Skip to content

fix(hooks): remove --stdin routing split that bypassed handler registry#179

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
m0Nst3r873:worktree-fix-hook-dispatch-stdin-split
Jul 10, 2026
Merged

fix(hooks): remove --stdin routing split that bypassed handler registry#179
jeff-r2026 merged 2 commits into
Tencent:mainfrom
m0Nst3r873:worktree-fix-hook-dispatch-stdin-split

Conversation

@m0Nst3r873

Copy link
Copy Markdown
Contributor

Summary

  • Remove --stdin flag from getDispatchCommand — restores v0.17.2 backward-compatible hook command format
  • Remove --stdin routing fork in index.ts — all hook-dispatch calls now go through hookDispatchCli's unified handler registry
  • Register local-agent HTTP report/sync (incl. workspace binding prompts) as a new handler in the registry
  • Keep --stdin as a no-op option declaration for forward compat with hooks already written to disk

Root Cause

PR #152 introduced a --stdin flag that split hook-dispatch into two mutually exclusive paths:

  • --stdin present → local-agent.ts hookDispatch() (only does HTTP report/sync)
  • --stdin absent → hookDispatchCli() (full handler registry: pull, update, contribute-check, mr-hint, etc.)

Simultaneously, getDispatchCommand was changed to emit --stdin in all hook commands. This means after upgrade, every hook goes through the local-agent path and silently drops all existing handlers: updateHandler, contributeCheckHandler, mrHintHandler, pullHandler, dashboardReportHandler, trackHandler, todowriteHintHandler.

Additionally, downgrading to v0.17.2 after upgrade causes --stdin to be rejected as an unknown option → all hooks fail silently (swallowed by 2>/dev/null || true).

Fix

  1. builtin-hooks.tsgetDispatchCommand no longer emits --stdin
  2. index.ts — unified code path: always calls hookDispatchCli
  3. hook-handlers.ts — new localAgentHandler registered on all 4 events
  4. local-agent.ts — exports reportAndSyncFromHook adapter for the handler

Compatibility

Scenario Before this fix After this fix
Upgrade (new CLI, new hooks) contribute-check/mr-hint/update all lost All handlers fire correctly
Downgrade to v0.17.2 --stdin unknown option → silent failure Hook format matches v0.17.2 exactly
Existing hooks with --stdin on disk N/A --stdin accepted as no-op, still works

Test plan

  • npx tsc --noEmit — no new type errors
  • npx vitest run — hooks-golden (4), hooks (40), hook-handlers (12), contribute-check (33), mr-hint (13) all pass
  • npm run build — clean build
  • Manual: teamai init --force, verify settings.json hooks do NOT contain --stdin
  • Manual: teamai pull on a machine with old --stdin hooks, verify reconcile upgrades them cleanly

🤖 Generated with Claude Code

jaelgeng and others added 2 commits July 10, 2026 15:50
The --stdin flag on hook-dispatch was used to route calls to
local-agent.ts instead of hookDispatchCli, silently dropping all
existing handlers (pull, update, contribute-check, mr-hint,
dashboard-report, track, todowrite-hint). Additionally, for init --http
users both statusReportHandler and localAgentHandler hit the same
/api/local-agent/report + /sync endpoints, causing double requests and
double command consumption on session-start and prompt-submit.

Fix:
- Remove --stdin from getDispatchCommand (restores v0.17.2 compat)
- Remove --stdin routing fork in index.ts (all calls go through
  hookDispatchCli's unified handler registry)
- Register local-agent report/sync as a new handler in the registry
  so HTTP reporting and workspace binding prompts still work
- Remove statusReportSessionHandler and statusReportMessageHandler
  from the registry (replaced by localAgentHandler to avoid double
  report/sync)
- Delete dead code: hookDispatch(), readStdin(), hookEventName() in
  local-agent.ts, and the two dead handler definitions + constant in
  hook-handlers.ts
- Keep --stdin as a no-op option for forward compat with hooks
  already written to disk
- Add regression test asserting exactly one HTTP reporter per event

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
status-report.ts has no import chain after removing its handlers from
the registry. Its HTTP report/sync/ack functionality is fully covered
by local-agent.ts. Each CLI version ships as a self-contained bundle
so removal has no cross-version compatibility impact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@m0Nst3r873 m0Nst3r873 force-pushed the worktree-fix-hook-dispatch-stdin-split branch from e0dd30d to dd44c18 Compare July 10, 2026 07:51
@jeff-r2026 jeff-r2026 merged commit 830abcf into Tencent:main Jul 10, 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.

2 participants