feat(local-agent): install/uninstall session hooks via sync + ack (#238) - #265
Merged
Merged
Conversation
…ncent#238) Implement the clawpro install_hook_rule / uninstall_hook_rule sync commands so a backend can remotely manage a session hook in the current reporting tool's settings, keyed by slug, reporting the result over the existing ack channel. Delivery, ack, and retry semantics are reused unchanged; these two types were previously silently skipped (handle_type === 'hook'). Behavior: - Current tool only — writes to context.tool's settings (never batch-injects). - Supported tools: claude / codex / workbuddy / codebuddy (+ internal variants). Cursor and OpenClaw-family tools are rejected (acked failed, unsupported tool). - Event whitelist: SessionStart / UserPromptSubmit / PreToolUse / PostToolUse / Stop. Anything else is acked failed (unsupported event). - Default timeout 10s when omitted; explicit backend timeout honored. - Idempotent: re-installing a slug replaces rather than duplicates, including same-tool event/command changes (prior entry is removed first). Missing-slug uninstall is idempotent success. Isolation: agent hooks use a dedicated [teamai:agent-hook:<slug>] description marker, distinct from built-in ([teamai] ) and team ([teamai:hook:) markers, so team full-reconcile treats them as untouched and never deletes them. The claude removeAll teardown branch is extended to also recognize the agent-hook marker, so `teamai uninstall` sweeps residue even without the manifest. Tracking: agent hooks are recorded in a separate ~/.teamai/local-agent/ agent-hooks.json (atomic writes), kept apart from the team managed-hooks.json so a team pull can never treat them as stale. Codex settings carry no description field, so codex hooks are matched by command and the manifest is the authoritative record for their teardown. Teardown covers all three paths with no residue: uninstall_hook_rule, `teamai source remove` (removeAllAgentHooks), and `teamai uninstall`. Trust model matches uninstall_teamai: an agent hook is a backend-supplied command the tool auto-runs on its events, so TEAMAI_DISABLE_REMOTE_CMD=1 also rejects install_hook_rule / uninstall_hook_rule (acked failed). Docs updated in both languages. Unit tests cover install/replace/remove for claude & codex, validation failures, cursor rejection, marker isolation, teardown sweep, codex command-change reinstall, and the kill switch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
m0Nst3r873
force-pushed
the
feature/agent-hooks-238
branch
from
July 30, 2026 12:08
7ca3a4c to
44567f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #238
Summary
Implements the clawpro
install_hook_rule/uninstall_hook_rulesync commands (issue #238) so a backend can remotely install and uninstall a session hook in the current reporting tool's settings, keyed byslug, reporting the result over the existingackchannel. These two types were previously silently skipped (handle_type === 'hook'); this turns that skip path into real handlers on the samesync → processCommands → executeCommand → ackCommandrails.Behavior (locked constraints from #238)
context.tool's settings; never batch-injects other tools.claude/codex/workbuddy/codebuddy(+ internal variants). Cursor and OpenClaw-family tools are rejected → ackedfailed(unsupported tool).SessionStart/UserPromptSubmit/PreToolUse/PostToolUse/Stop; anything else → ackedfailed(unsupported event).timeouthonored.slugreplaces rather than duplicates, including same-tool event/command changes (prior entry removed first). Missing-slug uninstall is idempotent success.Isolation & teardown
[teamai:agent-hook:<slug>]description marker, distinct from built-in ([teamai]) and team ([teamai:hook:) markers, so team full-reconcile treats agent hooks asuntouchedand never deletes them. The clauderemoveAllteardown branch is extended to recognize the agent-hook marker soteamai uninstallsweeps residue even without the manifest.~/.teamai/local-agent/agent-hooks.json(atomic writes), kept apart from the teammanaged-hooks.jsonso a team pull can never treat them as stale. Codex settings have no description field, so codex hooks are matched by command and the manifest is authoritative for their teardown.uninstall_hook_rule,teamai source remove, andteamai uninstall.Trust model
Matches
uninstall_teamai: an agent hook is a backend-supplied command the tool auto-runs on its events, soTEAMAI_DISABLE_REMOTE_CMD=1also rejectsinstall_hook_rule/uninstall_hook_rule(ackedfailed).Test plan
npx tsc --noEmitclean ·npx vitest run1858 passed ·npm run buildsuccess.removeAllsweeps them), codex command-change reinstall, kill switch.teamai hook-dispatch session-start): 17/17 — claude install/uninstall (marker, manifest, explicit timeout), codex install (command-matched, no description, default 10s), validation failures, cursor rejection, kill-switch rejects + writes nothing.docs/usage-guide.md+.zh-CN.md).🤖 Generated with Claude Code