Add native hook review and cleanup - #183
Conversation
Reviewer's GuideAdds a native hook review/removal workflow spanning Claude Code, Codex, Droid, Hermes, and Qwen, with surgical config editing, stale-hook doctor diagnostics, CLI/help integration, documentation, and a Claude hook reconciliation fix. Sequence diagram for native hook review and surgical removalsequenceDiagram
participant User
participant CLI as dotagents
participant Collector as collectNativeHooks
participant Config as Native hook configs
participant Writer as removeNativeHookEntries
User->>CLI: dotagents hook list [query]
CLI->>Collector: collectNativeHooks(home, cfg, selected)
Collector->>Config: Read Claude, Codex, Droid, Hermes, Qwen configs
Config-->>Collector: Hook registrations
Collector-->>CLI: Managed and stale entries
CLI-->>User: printNativeHooks(entries, unsupported)
User->>CLI: dotagents hook remove --dry-run query
CLI->>Collector: collectNativeHooks(home, cfg, selected)
Collector-->>CLI: Matching registrations
CLI-->>User: Preview removals
User->>CLI: dotagents hook remove query
CLI->>Writer: removeNativeHookEntries(matches)
Writer->>Config: Rewrite only matching registrations
Config-->>Writer: Updated native configs
Writer-->>CLI: Changed file count
CLI-->>User: Removal summary
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cmd/dotagents/hook_cli.go" line_range="463-470" />
<code_context>
+var hookScriptPathPattern = regexp.MustCompile(`(?:~|\$\{HOME-\}|\$HOME|/)[^'"[:space:];]+\.(?:sh|py|cmd|ts)`)
+
+func missingHookTarget(command string, home string) string {
+ paths := hookScriptPathPattern.FindAllString(command, -1)
+ if len(paths) == 0 {
+ return ""
+ }
+ seen := make(map[string]bool)
+ for _, path := range paths {
+ path = strings.ReplaceAll(path, "${HOME-}", home)
+ path = strings.ReplaceAll(path, "$HOME", home)
+ path = expandPath(path, home)
+ if seen[path] {
+ continue
+ }
+ seen[path] = true
+ if _, err := os.Stat(path); err == nil || !os.IsNotExist(err) {
+ return ""
+ }
+ }
+ for path := range seen {
+ return path
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** `missingHookTarget` returns an empty result as soon as any extracted script path exists, so a command containing both an existing target and a missing target is reported as non-stale even though one of its script targets is missing.
**Triggers:** When a native hook command references multiple `.sh`, `.py`, `.cmd`, or `.ts` paths and at least one exists.
**Suggested fix:** Check every extracted path and return a missing target if any path does not exist; only return empty when all extracted targets exist.
```suggestion
if _, err := os.Stat(path); err == nil || !os.IsNotExist(err) {
continue
}
return path
}
return ""
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and the new remove command permanently rewrites native hook configuration and can disable matching command registrations, including ones selected by a broad query; reverting the code will not restore those removed entries. The impact is bounded and manually repairable from configuration backups or by re-registering the hooks, but it is not undone by reverting the PR.
Blocking findings: cmd/dotagents/hook_cli.go:470
Native hook review and cleanup
Adds a
dotagents hookcommand group so native hook registrations can be inventoried and removed the same way skills and MCP servers already are. Motivated by leftover Orca and cmux hooks that stayed registered in harness configs after those tools were dropped.What's new
dotagents hook list [--agents ...] [query]inventories native hook registrations across harnesses, marks canonical entries as managed, and flags registrations whose script targets are missing as stale.dotagents hook remove [--dry-run] [--agents ...] <query>previews then removes matching registrations surgically, preserving unrelated hooks.dotagents doctornow reports stale native hooks.dotagents syncreconciles the remaining canonical hooks afterward.Coverage
Claude Code, Codex, Droid, Hermes, and Qwen hook formats are handled, each with tests. Hermes toolset entries (for example
orca-status) are left untouched since they are not hooks.Docs
README and
docs/troubleshooting.mddocument the review/remove flow and the "removed tool left stale native hooks" recovery path.Verification
go test ./...,go build ./..., andgo vet ./cmd/dotagentspass.dotagents hook list orcaanddotagents hook list cmuxboth report0 native hook registration(s).Summary by Sourcery
Add native hook inventory and cleanup workflows while improving hook health checks and Claude Code synchronization.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: