Skip to content

feat: auto-migrate hooks to dispatch format on first session after update#20

Merged
jeff-r2026 merged 6 commits into
masterfrom
feat/auto-migrate-hooks
May 26, 2026
Merged

feat: auto-migrate hooks to dispatch format on first session after update#20
jeff-r2026 merged 6 commits into
masterfrom
feat/auto-migrate-hooks

Conversation

@jeff-r2026
Copy link
Copy Markdown
Collaborator

Summary

  • After teamai update installs a new CLI version, hooks in settings.json still have the old individual format
  • This adds automatic detection + migration: on the first session start after update, the pull handler checks if settings.json contains hook-dispatch — if not, it reinjects hooks in the new dispatch format
  • Detection is ~1ms (substring check), reinject only triggers once per version upgrade
  • Users no longer need to manually run teamai hooks inject after updating

Why 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 old getClaudeHooks() 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

  • TypeScript compiles (0 errors)
  • 53 test files, 975 tests pass
  • Build succeeds
  • E2E verified: old format settings.json → teamai pull → hooks auto-migrated to dispatch format

🤖 Generated with Claude Code

jeff-r2026 and others added 6 commits May 19, 2026 12:38
…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>
@jeff-r2026 jeff-r2026 merged commit 3c41535 into master May 26, 2026
7 checks passed
@jeff-r2026 jeff-r2026 deleted the feat/auto-migrate-hooks branch May 26, 2026 12:09
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.

1 participant