Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[bug]Windows codebuddy ide hook失效

Closed
#1,446 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
git, node.js, typescript
Domain
cli, tooling

Research direction

Start with src/builtin-hooks.ts, especially the CodeBuddy rendering near line 297, and compare it with the explicit shell invocation near line 222. Confirm how the CLI and IDE hook runners interpret commands on Windows, then trace the hook reconciliation paths named in the report. Done means hooks execute in both products without cmd parse errors or swallowed failures.

Written by the indexing model from the issue text.

Description

bug help wanted

问题描述

Windows 下 teamai 会往 ~/.codebuddy/settings.json 注入 codebuddy hook。在 CodeBuddy IDE 1.106.1 中没有一条真正执行,而且是静默失败:IDE 每个生命周期事件都会打印 Executing hook command,看上去 hook 在跑,实际什么都没做。

预期:注入的 hook 正常执行,hook-dispatch 收到 stdin 的 JSON,会话上下文被送达。

实际存在两种失败形态:

  1. 6 条 dispatch hook 被渲染成
    PATH="$HOME/.teamai/bin:$PATH" teamai hook-dispatch <event> --tool codebuddy 2>/dev/null || true。
    在 cmd.exe 下 PATH=... 不是赋值而是命令名,shell 直接报
    The system cannot find the path specified.;而 || true 把退出码洗成 0,
    于是 hook-dispatch 从未被调用,也没有任何报错留在日志里。

  2. 3 条项目门禁 hook 被渲染成 if [ "$PWD" = '...' ] || case ... esac; then (python3 ...); fi,
    这根本不是 cmd 语法:Hook exited with non-blocking error code 1: 此时不应有 "$PWD"。

结论: hook 实际生效 0 条,且 teamai doctor 和 IDE 都不会提示异常。

复现步骤

  1. Windows 11 环境,安装 CodeBuddy IDE 1.106.1,teamai 0.28.0(npm 全局安装)。
  2. 执行 teamai hooks inject(teamai pull / teamai init 同样可复现,凡是走到 reconcileHooks 的路径都是)。
  3. 查看 ~/.codebuddy/settings.json:6 条是 POSIX 包装形式,3 条是 $PWD 门禁。
  4. 在 CodeBuddy IDE 里开一个对话,随便发一句(会触发 SessionStart、UserPromptSubmit、PostToolUse)。
  5. 打开日志
    %APPDATA%\CodeBuddy CN\logs\<时间戳>\window<N>\exthost\Tencent-Cloud.coding-copilot\腾讯云代码助手.log。

现象:每个事件都有 Executing hook command,但包装类条目的 Hook exited 从不出现;门禁类条目则以 cmd.exe 解析错误退出。

环境

  • OS:Windows 11(build 26200)
  • Node.js:v20.15.1
  • teamai:0.28.0(npm i -g teamai-cli)
  • 仓库托管:TGit
  • AI 工具:CodeBuddy IDE 1.106.1(VS Code 1.106 fork),未安装 CodeBuddy Code CLI
  • Shell:cmd.exe(ComSpec=C:\Windows\system32\cmd.exe),机器上装有 Git for Windows 2.50.0

日志

IDE hook 执行日志
# 门禁条目:被当成 cmd 解析,卡在 POSIX 判断上
55006  [HookExecutor] Executing hook command: if [ "$PWD" = 'C:\Users\<user>\CodeBuddy\teamai-new-version-test' ] || ...
55025  [HookExecutor] Hook exited with non-blocking error code 1: 此时不应有 "$PWD"。
55026  [HookExecutor] Hook exited with non-blocking error code 1: 此时不应有 "$PWD"。

# 包装条目:只有 Executing,没有 Hook exited(退出码被洗成 0)
57199  [HookExecutor] Executing hook command: PATH="$HOME/.teamai/bin:$PATH" teamai hook-dispatch post-tool-use --tool codebuddy 2>/dev/null || true
57232  [HookExecutor] Executing hook command: PATH="$HOME/.teamai/bin:$PATH" teamai hook-dispatch post-tool-use --tool codebuddy 2>/dev/null || true

在 IDE 之外用同一个 shell 手工复现同一条命令:

> cmd.exe /c 'PATH="C:\Users\<user>\.teamai\bin:$PATH" teamai hook-dispatch post-tool-use --tool codebuddy 2>/dev/null || true'
The system cannot find the path specified.
exit code: 0        <-- 被 `|| true` 吞掉了

根因分析

#989(a7aee948,随 0.27.0 发布)把 CodeBuddy 在 Windows 下的渲染从 cmd 改成 POSIX。它的提交说明写明了前提:

CodeBuddy runs a hook's command string through Git Bash on Windows — it dropped PowerShell/CMD for hooks in 2.52.4 and forces Git Bash since 2.55.1

这个前提只对 CodeBuddy Code(CLI) 成立,对 CodeBuddy IDE 不成立。IDE 是独立产品、独立版本线(1.106.x)、独立的 hook 执行器。IDE 扩展里的执行方式是:

spawn(command, [], { stdio: ['pipe','pipe','pipe'], shell: true, env, cwd, detached })

shell: true 且不指定 shell 时,Node 会退化到 process.env.ComSpec,也就是 cmd.exe。IDE 的扩展包里 CODEBUDDY_CODE_GIT_BASH_PATH、CODEBUDDY_CODE_SHELL、MSYSTEM、Git Bash 出现次数均为 0,说明这条路径上压根没有 Git Bash 解析逻辑。

由此形成一个零和 bug:codebuddy 这一个 tool id 同时覆盖了两个 shell 相反的产品。

teamai 版本 codebuddy 的渲染结果 CodeBuddy CLI(Git Bash) CodeBuddy IDE(cmd.exe)
≤ 0.26.0 set "PATH=…;%PATH%" && teamai … 2>nul || exit /b 0 坏(留下 nul 文件、PATH 未生效、exit 2 会阻塞提问) 正常
≥ 0.27.0 PATH="$HOME/…" teamai … 2>/dev/null || true 正常 坏(静默空转)

0.28.0 中相关渲染点:

  • src/builtin-hooks.ts:297 —— codebuddy 走的是裸 POSIX 字符串
  • src/builtin-hooks.ts:222 —— WorkBuddy 走的是 ${shell} -lc "…",即显式解析出 shell 再调用

注意 :222 那种形状在 cmd.exe 下同样成立:cmd 可以用绝对路径启动 bash.exe,所以显式调用 shell 的写法在两个 runner 下都能跑。而 codebuddy 分支选择了裸字符串,把“用哪个 shell”交给了 runner 自己决定。

Dominant language
TypeScript
Stars
5.6k
Forks
471
Avg merge
20h 16m
Merged PRs (30d)
399

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Tencent/teamai-cli

All issues in Tencent/teamai-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.