Repository navigation
feat: add first-class ZCode support - #462
Conversation
- register ZCode as a built-in target: skills deploy to ~/.zcode/skills, subagents (Claude-style Markdown) to ~/.zcode/agents/, and the built-in teamai-recall subagent rides the generic agents deployment - add a 'zcode' hook format: ZCode nests Claude-shaped hooks under hooks.events and gates them on hooks.enabled (config-file hooks are disabled by default, so the writer forces it on) - write process-type hook entries (bash -lc <dispatch> as an argv vector): a shell-string command would resolve through the host shell, which on Windows can land on the WSL bash.exe instead of Git Bash - omit the matcher for wildcard groups: ZCode matchers are case-sensitive regexes and '*' is an invalid pattern that never matches - user-scope MCP deploys to ~/.agents/mcp.json (Claude mcpServers shape — the file ZCode's own MCP settings page reads); project scope is not wired (ZCode stores workspace MCP under the different 'mcp.servers' key) - exclude ZCode from co-author reconciliation: it exposes no documented attribution setting - rules are not synced: ZCode has no user-level rules dir convention Validation: 6/6 zcode tests + affected suites (agents/agent-format/coauthor) all green, typecheck, build, and an end-to-end 'hooks inject' run against a sandbox HOME (unrelated config keys preserved, runner forced enabled, second run byte-identical). Hooks test files show identical pass/fail counts before and after the change on Windows.
jeff-r2026
left a comment
There was a problem hiding this comment.
Locally reproduced two issues on 8b6c870 using the built CLI and an isolated HOME. npm run build and the existing ZCode test suite (6/6) pass. Details and reproduction steps are attached inline.
| // same strategy as the Codex format. | ||
| const isManaged = (entry: ZcodeHookMatcher): boolean => { | ||
| const cmd = zcodeEntryCommand(entry); | ||
| return TEAMAI_COMMAND_MARKERS.some((marker) => cmd.includes(marker)) || priorTeamCommands.has(cmd); |
There was a problem hiding this comment.
[P1] Match managed team hooks using the same command representation as the manifest
priorTeamCommands contains the original HookDef.command, but zcodeEntryCommand() returns hook.args.join(' '), which includes the added -lc prefix and >/dev/null 2>&1 || true suffix. Ordinary team commands therefore never match the manifest and are treated as user-owned entries. Every injection appends another copy, and removal leaves all those copies behind while deleting their manifest records.
Reproduced with the built CLI in an isolated HOME: configure ZCode and a hooks/hooks.yaml entry with event: SessionStart and command: sh /absolute/path/audit.sh (the script appends a line to a temporary file). Run hooks inject twice, then hooks remove. The team-entry counts are 1 → 2 → 2, despite removal reporting success. Executing the two remaining entries using their exact stored command/args appends two lines. This verifies that the retained commands remain executable; it does not depend on running the ZCode app. Repeated syncs multiply side effects, and removing a team hook does not revoke it.
Please normalize the stored command and manifest command consistently for reconciliation and managed-hook detection, and cover reinjection plus removal with a custom team command.
There was a problem hiding this comment.
Additional end-to-end verification: this also affects teamai uninstall --force, not only hooks remove. In an isolated HOME with one custom SessionStart hook (sh /absolute/path/audit.sh), full uninstall reported success and removed the team skill, team agent, managed MCP server, and the entire .teamai directory. The custom hook remained in .zcode/cli/config.json; invoking its stored command/args after uninstall still appended a line to the audit file. Its ownership manifest had already been deleted. Targeted uninstall --agent zcode --force with Claude remaining also left the custom hook behind. Personal skills, agents, MCP entries, and plugin keys were preserved in the full-uninstall fixture.
| const cfg: ZcodeHooksJson = (await readJson<ZcodeHooksJson>(expanded)) ?? {}; | ||
| if (!cfg.hooks) cfg.hooks = {}; | ||
| // Config-file hooks are disabled by default in ZCode; entries we write would | ||
| // never fire unless the runner is explicitly enabled. |
There was a problem hiding this comment.
[P2] Persist changes to hooks.enabled even when event entries are unchanged
Setting cfg.hooks.enabled = true does not set changed; the write below only happens when an event array differs. Once the entries are stable, an existing hooks.enabled: false remains false on disk after reinjection, contrary to the documented behavior.
Locally reproduced with the built CLI: inject hooks, reach a stable configuration, edit only hooks.enabled to false, then run hooks inject again. The CLI reports success, but the file still contains false, leaving the config-file hooks disabled. Please include the enabled-field change in the dirty check and add a regression test for reinjecting an otherwise up-to-date disabled configuration.
| const cfg: ZcodeHooksJson = (await readJson<ZcodeHooksJson>(expanded)) ?? {}; | ||
| if (!cfg.hooks) cfg.hooks = {}; | ||
| // Config-file hooks are disabled by default in ZCode; entries we write would | ||
| // never fire unless the runner is explicitly enabled. |
There was a problem hiding this comment.
[P1] Preserve the hook runner state during removal
This unconditional assignment also runs with opts.removeAll: true. When removal changes the event arrays, the write persists hooks.enabled: true, turning on hooks that the user explicitly disabled. This affects retained user-owned hooks even after the managed-command matching issue is fixed.
Reproduced on 8b6c870 with the built CLI and an isolated HOME: start with a personal SessionStart hook, run hooks inject, explicitly set hooks.enabled to false, and run uninstall --force. The command reports success and deletes .teamai, but the surviving ZCode config now has hooks.enabled: true and still contains the personal hook. The same false → true transition occurs with uninstall --agent zcode --force while Claude remains installed. Combined with the separately reported team-hook ownership bug, removal also re-enables the orphaned team commands.
Please only force the runner on when installing hooks; removal should preserve its existing enabled/disabled state. Add a regression test starting with installed entries and hooks.enabled: false, then removing them.
There was a problem hiding this comment.
Re-reviewed and reproduced on the latest head, 343a5d8. This P1 is still present at src/hooks.ts:548–550: the enabled-state assignment remains unconditional with respect to opts.removeAll.
Actual built-CLI reproduction in an isolated HOME:
- Keep a personal SessionStart hook in the ZCode config and run
hooks inject. - Set only
hooks.enabledto false. - Run
uninstall --force. - Inspect the remaining config: the personal hook is preserved, but
hooks.enabledis true..teamaihas been deleted and the CLI reports success.
Repeated with uninstall --agent zcode --force while Claude remains installed: same false → true transition. Removal needs to preserve the existing runner state, e.g. gate the enabling branch on !opts.removeAll, with a disabled-state removal regression test.
The other fixes are verified for fresh installs: two injections now keep exactly one custom team hook, removal/full uninstall leave zero custom team hooks, and reinjection correctly persists the enabled flip. Build, TypeScript checking, and the ZCode/team-hooks/uninstall suites (52 tests) pass. The remaining removal-state issue prevents LGTM.
Review findings on Tencent#462 (both locally reproduced by jeff-r2026): - team hooks were appended on every injection and left behind on removal: zcodeEntryCommand() joined the full argv while the manifest stored the raw HookDef.command, so managed-entry detection never matched. The shell payload is now stored verbatim (args[1] === def.command) and the payload accessor returns it as-is — one command representation across entry, manifest, and desired set. - flipping hooks.enabled to true was not tracked as a change, so an otherwise up-to-date config with enabled: false stayed disabled after reinjection. The flip now participates in the dirty check. Regression tests cover both: custom team-command reinjection/removal via the manifest, and re-enabling a hand-disabled but otherwise stable config.
|
Thanks for the thorough review and the precise reproduction steps, @jeff-r2026 — both findings were real. Fixed in 343a5d8: P1 (team-hook command mismatch). Root cause exactly as diagnosed: the manifest stored the raw P2 ( Regression tests added to
Typecheck, build, and the full zcode suite pass on the rebased branch. One residual limitation worth documenting: because ZCode parses hook stdout as strict JSON, queued stdout hints (e.g. the packages-changed notice) cannot be injected into ZCode sessions until teamai learns to emit ZCode's output schema — happy to add that in a follow-up if you want it. |
The enabled-state normalization introduced for the P2 finding ran on the removal path too, so uninstall/remove flipped a user-disabled hooks.enabled back to true while stripping the managed entries — re-enabling surviving personal hooks against the user's explicit choice. Gate the enabling branch on !opts.removeAll so removal preserves the existing runner state, with a regression test: install, hand-disable hooks.enabled, removeAll — entries stripped, enabled stays false.
|
Thanks for the fast re-review — agreed, and fixed in cf00e98.
Regression test added: install → hand-disable Suite now 9/9; typecheck and build clean on the rebase base. |
Review findings on Tencent#462 (both locally reproduced by jeff-r2026): - team hooks were appended on every injection and left behind on removal: zcodeEntryCommand() joined the full argv while the manifest stored the raw HookDef.command, so managed-entry detection never matched. The shell payload is now stored verbatim (args[1] === def.command) and the payload accessor returns it as-is — one command representation across entry, manifest, and desired set. - flipping hooks.enabled to true was not tracked as a change, so an otherwise up-to-date config with enabled: false stayed disabled after reinjection. The flip now participates in the dirty check. Regression tests cover both: custom team-command reinjection/removal via the manifest, and re-enabling a hand-disabled but otherwise stable config.
feat: add first-class ZCode support
Summary
~/.zcode/skills/, subagents (Claude-style Markdown) →~/.zcode/agents/, user-scope MCP →~/.agents/mcp.json, hooks →~/.zcode/cli/config.jsonzcodehook format: ZCode nests Claude-shaped hooks underhooks.eventsand gates them onhooks.enabled(config-file hooks are disabled by default, so the writer forces it on)process-type hook entries (bash -lc <dispatch>as an argv vector) and omit wildcard matchers (ZCode matchers are case-sensitive regexes;*is an invalid pattern that never matches)Closes #461.
Why
ZCode was not discoverable as a tool id, so TeamAI could not deploy resources to it nor inject session hooks (no auto pull). Conventions verified against the ZCode desktop app (Windows): user skills live in
~/.zcode/skills(central~/.agents/skillsalso read — covered by the existingagentsentry), user subagents in~/.zcode/agents/*.md(edited by the desktop Subagents page), user MCP in~/.agents/mcp.json(mcpServersshape, read by the desktop MCP page), and hooks in the shared~/.zcode/cli/config.json.Validation
npx vitest run src/__tests__/zcode.test.ts(6/6 passed)npm run typecheck,npm run buildteamai hooks injectagainst a sandbox HOME: unrelated config keys (plugin state) preserved, runner forced enabled, second run byte-identicalBoundary
mcp.serverskey inside.zcode/config.json, which the Claude writer cannot emit)Type of Change
Test Plan
npx tsc --noEmitpassesnpx vitest runpasses (new zcode suite + affected suites green; pre-existing Windows-only failures unchanged, verified against a clean checkout)Related Issues
Closes #461
Notes for Reviewers
~/.zcode/cli/config.jsonis shared with ZCode's own state (plugins etc.) —reconcileZcodeFormatmerges the document and only ever toucheshooks.enabled+hooks.events.<Event>.bashfrom PATH; on Windows a host whose PATH resolves the WSLbash.exefirst would no-op — the same exposure as the existingbash -lcClaude commands, called out in the docs.