feat: auto-migrate hooks to dispatch format on first session after update#20
Merged
Conversation
…request !188) Squash merge branch 'fix/sync-wiki-path-from-github' into 'master' Sync from GitHub main (PR #15 merged): 1. skills/teamai-wiki/SKILL.md - wiki path scope-aware 2. package.json - bin path and repo url format
Show user and project scope storage paths (e.g. ~/.teamai/, $PWD/.teamai/) before the scope selection prompt so users know where data will be stored. Closes #7
Resolves #6. Instead of spawning N separate `teamai <subcommand>` processes per Claude Code hook event, introduce a unified `teamai hook-dispatch <event>` command that reads STDIN once and fans out to all handlers internally. Key changes: - New dispatcher core (hook-dispatch.ts) with routing, isolation via Promise.allSettled, per-handler timeout, and output merging - Handler registry (hook-handlers.ts) wrapping existing subcommand logic - hooks.ts now emits 9 merged dispatch entries instead of 13 individual ones - Legacy hooks are auto-cleaned on next `teamai hooks inject` - Backward compatible: standalone subcommands (pull, track, etc.) unchanged Performance: lightweight events (prompt-submit) drop from ~1040ms to ~220ms by eliminating redundant Node.js cold starts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…format The E2E test file still expected the old 13-hook format. Updated to match the new 9-entry dispatch format (1 per event+matcher instead of N per event). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…date When the CLI is updated but settings.json still has old individual hook entries (teamai pull, teamai track, etc.), the pull handler now detects this on session start and reinjects hooks in the new dispatch format. This happens automatically on the first session after `teamai update`: 1. Old hooks fire (backward compat) → pull handler runs in NEW binary 2. Detects settings.json lacks 'hook-dispatch' → calls injectHooksToAllTools() 3. Next session: dispatch format active, full performance benefit Detection is lightweight (~1ms): read settings.json, check if 'hook-dispatch' substring exists. Only triggers reinject when old format is detected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
teamai updateinstalls a new CLI version, hooks in settings.json still have the old individual formathook-dispatch— if not, it reinjects hooks in the new dispatch formatteamai hooks injectafter updatingWhy not reinject in
doUpdate()directly?The running Node.js process has the OLD version's code loaded in memory. Calling
injectHooksToAllTools()in the same process would use the oldgetClaudeHooks()definitions — it can never produce the new format. The correct time is the next session start, when a fresh process loads the new binary.Test plan
teamai pull→ hooks auto-migrated to dispatch format🤖 Generated with Claude Code