Skip to content

fix(hooks): keep ZCode replies free of login shell output - #1316

Merged
SaulMoro merged 2 commits into
Tencent:mainfrom
nateEc:fix/1221-zcode-clean-stdout
Oct 24, 2026
Merged

SaulMoro merged 2 commits into
Tencent:mainfrom
nateEc:fix/1221-zcode-clean-stdout

Conversation

@nateEc

@nateEc nateEc commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change that fixes an issue)

Test Plan

  • npx tsc --noEmit, npm run lint, and git 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, then npx 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=4 finished with 12,232 passed, 36 skipped and two existing baseline failures. Both failures are submodule-checkout.test.ts cases preserving empty old .claude/settings.local.json / .codex/hooks.json: git config --get hook.teamai-post-checkout.command fails. Both were independently reproduced on a clean, unchanged 2401d04 checkout using npx 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)

  • Fixed the user-scope wrapper gap: POSIX ZCode/DSH injection now creates the absolute Node/CLI wrapper without relying on a project Git hook. The new user-scope regression reproduced teamai: command not found before the fix.
  • Built-CLI E2E: 2 passed. The user-scope hook runs with PATH restricted to /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.
  • 28 related unit tests, build, type checking and lint passed. Live ZCode and Windows were not run.
  • Compatibility note: POSIX hooks now run without login profiles. Team hook commands that relied on login-profile environment variables must provide those variables explicitly.

Updated head: 86de83075370a8e69b7355f8f9d0a69c6148a355. Rebased onto main 6ebb31ce.

@github-actions

Copy link
Copy Markdown

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 SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -l also 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:75 and zcode.test.ts:182.
  • [P3 nit] The e2e PATH includes the Node bin directory, which can hold a global teamai. 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 通过。
@nateEc
nateEc force-pushed the fix/1221-zcode-clean-stdout branch from 278a234 to 86de830 Compare October 24, 2026 17:21
@nateEc

nateEc commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up at 86de83075370a8e69b7355f8f9d0a69c6148a355 on current main.

  • Fixed the user-scope wrapper gap: POSIX ZCode/DSH injection now creates the absolute Node/CLI wrapper without relying on a project Git hook. The new user-scope regression reproduced teamai: command not found before the fix.
  • Built-CLI E2E: 2 passed. The user-scope hook runs with PATH restricted to /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.
  • 28 related unit tests, build, type checking and lint passed. Live ZCode and Windows were not run.
  • Compatibility note: POSIX hooks now run without login profiles. Team hook commands that relied on login-profile environment variables must provide those variables explicitly.

The PR description contains the updated verification record. Ready for another review.

@github-actions

Copy link
Copy Markdown

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 SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nonLoginWrapper hunk in src/builtin-hooks.ts is the same text in #1317. On this PR alone, the dsh command still runs bash -lc without 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 TOOL is fixed to 'zcode'. hooks-skill-retire.test.ts:75 and zcode.test.ts:182 are 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.

@SaulMoro
SaulMoro merged commit c69996b into Tencent:main Oct 24, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
* 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 通过。
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.

3 participants