Repository navigation
fix(hooks): keep ZCode replies free of login shell output - #1316
Conversation
|
No findings in the specified diff. The PR description includes sufficient testing: a build followed by a representative E2E run exercising the generated ZCode process hook and real CLI. No additional provider × agent coverage is required. Review was read-only; I did not run, build, or install anything from the PR. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@nateEc Thanks. The ZCode half of the #1221 item works, and so does the doctor probe. We built this head and its base 2401d047 and ran a login profile that prints a banner. The base's ZCode hook reply is broken and this head's is clean JSON. Doctor passed a banner-printing -lc entry on the base and fails it here. hooks inject rewrites -lc to -c and is idempotent. The new e2e and doctor tests fail on the base and pass here.
[P1 blocking] In user scope the new command needs a wrapper that nothing writes for ZCode. It is the same gap as #1317. The POSIX command now runs PATH="$HOME/.teamai/bin:$PATH" … bash -c … without a login shell. ensureTeamaiWrapper() runs only for WorkBuddy, CodeBuddy and the project-scope git hook, so a user-scope ZCode install has no ~/.teamai/bin/teamai. If teamai is only on the login PATH (an nvm install, for example), the hook exits 127 with no reply, where the base still finds it through -l. Doctor's probe still passes, because it never resolves teamai. We reproduced this with dsh on #1317. Here it is the same command shape with ZCode modelled, since ZCode isn't installed on our side. Writing the wrapper for every tool whose command uses it would fix both PRs at once.
Not blocking:
[P2 non-blocking]Dropping-lalso drops the login-profile environment for every ZCode POSIX hook, team hooks included. A hook that relied on a variable from the profile changes. One sentence in the body would cover it.[P3 nit]Two assertions got looser:hooks-skill-retire.test.ts:75andzcode.test.ts:182.[P3 nit]The e2e PATH includes the Node bin directory, which can hold a globalteamai. The test could then pass without the wrapper.
- Run POSIX ZCode process hooks with bash -c so profile banners cannot corrupt the JSON reply; prepend TeamAI's managed wrapper directory for built-ins so GUI sessions still find the dispatcher. - Make doctor's reply probe compare the entire byte stream rather than accepting a JSON substring inside otherwise invalid output. - Keep Windows launchers, timeout overrides and command-tail ownership intact; retain old fixtures as upgrade inputs and update current output. - Verify 575 hook/ZCode regression tests (one Windows-only skip), static checks, build, and a generated process entry executing the real CLI with a noisy-login-shell fixture and a restricted PATH. Refs Tencent#1221.
- 在 ZCode 和 DSH 的 POSIX hook 安装入口生成 teamai wrapper,不再依赖项目 Git hook 的副作用。 - 新增只有系统 PATH 的用户范围用例,通过真实调度事件验证包装器实际执行;项目用例继续验证登录横幅不会污染 JSON。 - 对齐主分支 ZCode 的 HOME 配置位置;28 个相关单测、2 个真实 CLI 用例及构建、类型检查和 lint 通过。
278a234 to
86de830
Compare
|
Addressed the review follow-up at
The PR description contains the updated verification record. Ready for another review. |
|
No findings in the specified diff. The PR description documents sufficient testing: a build followed by representative real-CLI E2E runs covering clean JSON output and user-scope wrapper creation. Additional provider × agent coverage is not required. The earlier review reported no findings, so none require resolution. Review was read-only; I did not run, build, or install anything from the PR. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@nateEc Thanks, approving at 86de830. The user-scope wrapper is fixed: the new test delivers user-scope context without a login PATH… passes here (2/2) and fails on main with bash: teamai: command not found. With the built CLI, the session-start reply is invalid JSON on the base and valid JSON on this head. The compatibility note in the body covers the earlier login-profile env point. Build, tsc, lint and the related unit files pass.
- [P2 non-blocking] The
nonLoginWrapperhunk insrc/builtin-hooks.tsis the same text in #1317. On this PR alone, the dsh command still runsbash -lcwithout the PATH prefix, so the dsh wrapper is written but nothing references it until #1317 lands, and the commit message reads as if dsh were fixed too. Whichever PR lands first owns the hunk, and the other should drop it on rebase. - [P3 nit] The user-scope e2e has dsh branches that never run because
TOOLis fixed to'zcode'.hooks-skill-retire.test.ts:75andzcode.test.ts:182are still looser than before.
Not checked: a live ZCode session (not installed here), and doctor's probe catching a real banner end to end. The unit test covers the probe.
The CI review reports no findings. We agree that nothing blocks. It did not mention the shared hunk above. All CI jobs pass.
* fix(hooks): keep ZCode replies free of login shell output - Run POSIX ZCode process hooks with bash -c so profile banners cannot corrupt the JSON reply; prepend TeamAI's managed wrapper directory for built-ins so GUI sessions still find the dispatcher. - Make doctor's reply probe compare the entire byte stream rather than accepting a JSON substring inside otherwise invalid output. - Keep Windows launchers, timeout overrides and command-tail ownership intact; retain old fixtures as upgrade inputs and update current output. - Verify 575 hook/ZCode regression tests (one Windows-only skip), static checks, build, and a generated process entry executing the real CLI with a noisy-login-shell fixture and a restricted PATH. Refs Tencent#1221. * fix(hooks): 为用户范围的非登录 hook 生成启动包装器 - 在 ZCode 和 DSH 的 POSIX hook 安装入口生成 teamai wrapper,不再依赖项目 Git hook 的副作用。 - 新增只有系统 PATH 的用户范围用例,通过真实调度事件验证包装器实际执行;项目用例继续验证登录横幅不会污染 JSON。 - 对齐主分支 ZCode 的 HOME 配置位置;28 个相关单测、2 个真实 CLI 用例及构建、类型检查和 lint 通过。
Summary
A ZCode process hook used
bash -lc, so a login profile printing a banner produced invalid JSON on stdout and prevented session context delivery. Doctor accepted the reply as a substring and incorrectly passed that broken runner.Use a non-login POSIX runner, resolve built-ins through TeamAI's managed PATH wrapper, and require the doctor's probe reply to match the complete byte stream.
Type of Change
Test Plan
npx tsc --noEmit,npm run lint, andgit diff --check.npx vitest run hooks zcode project-hook-rules windows-test-list: 575 passed, one Windows-only skip. A noisy launcher previously made the new doctor regression fail.npm run build, thennpx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/zcode-clean-stdout.test.ts: one passed. A compiled-CLI self-mode init generates the process entry, then that entry runs the real dispatcher under a restricted PATH and a fake shell which prints on login startup; the complete reply parses as JSON and contains the project's rule.Additional integration validation with all five fixes applied together to
origin/main(2401d04): build, type checking and lint passed; the five affected E2E files passed all 19 tests.npx vitest run --maxWorkers=4finished with 12,232 passed, 36 skipped and two existing baseline failures. Both failures aresubmodule-checkout.test.tscases preserving empty old.claude/settings.local.json/.codex/hooks.json:git config --get hook.teamai-post-checkout.commandfails. Both were independently reproduced on a clean, unchanged2401d04checkout usingnpx vitest run src/__tests__/submodule-checkout.test.ts -t 'preserves an empty old'; no tests were skipped or weakened to hide them.The PR's native Windows CI job (paths, hook rendering and hook shells) also passed at the submitted head.
Related Issues
Refs #1221. This PR addresses only the finding described above and does not close the umbrella issue.
Notes for Reviewers
The Windows Node launcher, explicit timeouts and verbatim command-tail matching are preserved. The old Skill-retirement input fixture remains unchanged; its expected current ZCode output now includes the runner upgrade. The E2E executes the generated process entry with a fixture host; it does not claim a live ZCode/model session.
Follow-up verification (2026-10-25)
teamai: command not foundbefore the fix./usr/bin:/bin; its dashboard SessionStart proves the dispatcher executed. The project fixture verifies clean JSON without login banner output, using main's HOME ZCode config location.Updated head:
86de83075370a8e69b7355f8f9d0a69c6148a355. Rebased onto main6ebb31ce.