Skip to content

fix(hooks): use absolute path for teamai binary in hook commands#177

Merged
jeff-r2026 merged 3 commits into
Tencent:mainfrom
m0Nst3r873:worktree-fix-hook-absolute-path
Jul 10, 2026
Merged

fix(hooks): use absolute path for teamai binary in hook commands#177
jeff-r2026 merged 3 commits into
Tencent:mainfrom
m0Nst3r873:worktree-fix-hook-absolute-path

Conversation

@m0Nst3r873

@m0Nst3r873 m0Nst3r873 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Resolve the absolute path of the teamai binary at init/pull time and embed it in hook commands
  • Fix hook identification regexes to match both bare teamai and absolute paths
  • Prevents hook failures in GUI-launched AI tools (CodeBuddy/WorkBuddy) that lack a complete PATH

Root Cause

Hook commands are written as bash -lc "teamai hook-dispatch ..." which relies on teamai being in PATH. GUI-launched IDE processes (CodeBuddy, WorkBuddy) may not inherit the user's full login shell PATH, causing the hook to fail silently — no report, no sync, no debug.log update.

Fix

  1. resolveTeamaiBinPath() (new): looks for teamai in path.dirname(process.argv[0]) — this is the node binary directory where npm global install places the teamai symlink. Falls back to bare teamai if not found.

  2. getDispatchCommand(): accepts optional binPath parameter, defaults to 'teamai' for backward compatibility.

  3. builtinHookDefs(): calls resolveTeamaiBinPath() and passes the result to getDispatchCommand().

  4. Hook identification regexes: isTeamaiHookCommand and extractTeamaiSubcommand updated from /"teamai\s/ to /(?:^|\/|")teamai\s/ so reconcile correctly detects hooks with absolute paths (prevents duplicate injection).

Compatibility

  • Existing installs: next teamai init --force or teamai pull will automatically upgrade hook commands to use absolute paths via the normal reconcile flow
  • Golden tests: process.argv[0] is set to /nonexistent in beforeEach so resolveTeamaiBinPath falls back to 'teamai', keeping fixtures stable
  • WorkBuddy sandbox: if the sandbox restricts access to the resolved path, resolveTeamaiBinPath falls back to bare teamai (same behavior as before)

Test plan

  • npx tsc --noEmit passes
  • npx vitest run — no new failures (golden + hooks tests all pass)
  • On macOS: teamai init --http <url> --agent codebuddy --force, verify ~/.codebuddy/settings.json contains absolute path like /Users/xxx/.nvm/.../bin/teamai hook-dispatch ...
  • On macOS: open CodeBuddy IDE (not from terminal), start a session, verify debug.log shows report/sync activity
  • On Windows: same verification with WorkBuddy (if sandbox blocks the path, should gracefully fall back to bare teamai)

🤖 Generated with Claude Code

jaelgeng and others added 3 commits July 10, 2026 17:03
GUI-launched AI tools (CodeBuddy/WorkBuddy) may spawn hook subprocesses
without a complete PATH, causing `teamai hook-dispatch` to fail silently.

Resolve the absolute path of the teamai binary at init/pull time via
process.argv[0] (node binary dir, where npm places the teamai symlink)
and embed it in the hook command. Falls back to bare `teamai` when
resolution fails.

Also fix hook identification regexes (isTeamaiHookCommand,
extractTeamaiSubcommand) to match absolute paths so reconcile correctly
detects and replaces existing teamai hooks.

--story=1032029153857553

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t PATH

WorkBuddy uses a bundled Node and its hook subprocesses lack the user's
PATH, causing `teamai: command not found`. Instead of embedding absolute
paths in every hook command, write a thin wrapper script at
`~/.teamai/bin/teamai` (using WorkBuddy's bundled Node + the real entry
script), and prepend `~/.teamai/bin` to PATH in WorkBuddy hook commands.

This keeps all `teamai xxx` subcommands working (not just hook-dispatch)
and preserves the `teamai hook-dispatch ...` command format so existing
reconcile identification logic continues to match.

Also widen `isTeamaiHookCommand` regex to match WorkBuddy's PATH-prefixed
command format (`PATH="..." teamai hook-dispatch ...`).

Other tools (Claude Code, CodeBuddy, Cursor) are unchanged.

--story=1032029153857553

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The WorkBuddy PATH wrapper was only written by injectHooksToAllTools, but
init/pull/hooks-inject go through reconcileHooksToAllTools, which never
created it — so GUI-launched hooks still failed to resolve `teamai`.
CodeBuddy has the same limited-PATH problem but was left on bare `teamai`.

- reconcileHooksToAllTools now writes the wrapper when workbuddy/codebuddy
  are active (P0: init path was a no-op before)
- builtinHookDefs routes both workbuddy and codebuddy through the wrapper
  PATH-prepend command; wrapper node resolution now also probes CodeBuddy's
  bundled node (~/.codebuddy-server*/bin/stable-*/node)
- wrapper command uses the `$HOME` shell literal so golden fixtures stay
  byte-stable across machines
- fix bundled-node version pick to compare numerically, not lexically
- update codebuddy golden fixture, add workbuddy fixture + wrapper tests

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@m0Nst3r873 m0Nst3r873 force-pushed the worktree-fix-hook-absolute-path branch from 5c0fe32 to 2e1d306 Compare July 10, 2026 09:06
@jeff-r2026 jeff-r2026 merged commit 9361732 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