Skip to content

feat(local-agent): install/uninstall session hooks via sync + ack (#238) - #265

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:feature/agent-hooks-238
Jul 30, 2026
Merged

feat(local-agent): install/uninstall session hooks via sync + ack (#238)#265
jeff-r2026 merged 1 commit into
Tencent:mainfrom
m0Nst3r873:feature/agent-hooks-238

Conversation

@m0Nst3r873

@m0Nst3r873 m0Nst3r873 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #238

Summary

Implements the clawpro install_hook_rule / uninstall_hook_rule sync commands (issue #238) so a backend can remotely install and uninstall a session hook in the current reporting tool's settings, keyed by slug, reporting the result over the existing ack channel. These two types were previously silently skipped (handle_type === 'hook'); this turns that skip path into real handlers on the same sync → processCommands → executeCommand → ackCommand rails.

⚠️ Stacked on #249. This branch builds on #249 (uninstall_teamai), which is not yet merged. Until #249 lands, this PR's diff includes its commit 3b89fee as well as this feature's commit. Merge #249 first; this PR's own change is the single commit feat(local-agent): install/uninstall session hooks via sync + ack (#238). Once #249 merges I'll rebase so only that commit remains.

Behavior (locked constraints from #238)

  • Current tool only — writes to context.tool's settings; never batch-injects other tools.
  • Supported toolsclaude / codex / workbuddy / codebuddy (+ internal variants). Cursor and OpenClaw-family tools are rejected → acked failed (unsupported tool).
  • Event whitelistSessionStart / UserPromptSubmit / PreToolUse / PostToolUse / Stop; anything else → 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 removed first). Missing-slug uninstall is idempotent success.

Isolation & teardown

  • Dedicated [teamai:agent-hook:<slug>] description marker, distinct from built-in ([teamai] ) and team ([teamai:hook:) markers, so team full-reconcile treats agent hooks as untouched and never deletes them. The claude removeAll teardown branch is extended to recognize the agent-hook marker so teamai uninstall sweeps residue even without the manifest.
  • Tracked 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 have no description field, so codex hooks are matched by command and the manifest is authoritative for their teardown.
  • Teardown covers all three paths with no residue: uninstall_hook_rule, teamai source remove, 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).

Test plan

  • npx tsc --noEmit clean · npx vitest run 1858 passed · npm run build success.
  • Unit tests: install/replace/remove for claude & codex, validation failures, cursor rejection, marker isolation (team reconcile leaves agent hooks; removeAll sweeps them), codex command-change reinstall, kill switch.
  • Real-CLI e2e (mock HTTP endpoint, 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 updated bilingually (docs/usage-guide.md + .zh-CN.md).

🤖 Generated with Claude Code

…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
m0Nst3r873 force-pushed the feature/agent-hooks-238 branch from 7ca3a4c to 44567f6 Compare July 30, 2026 12:08
@jeff-r2026
jeff-r2026 merged commit 901055e into Tencent:main Jul 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(http): support install_hooks / uninstall_hooks sync commands

2 participants