Skip to content

feat(clients): register ZCode during setup - #1564

Merged
morluto merged 4 commits into
morluto:mainfrom
IvenKooLab:feat/zcode-client
Oct 12, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
IvenKooLab:feat/zcode-client

Conversation

@IvenKooLab

Copy link
Copy Markdown
Contributor

Summary

Registers ZCode (Z.ai's coding-agent CLI) as a supported client during npx rea-agents setup, following the same pattern as the merged Qwen Code registration (#1415). After this change, ZCode users can install REA with one command: setup writes the rea MCP server into the user-level ~/.zcode/cli/config.json and installs the REA skill into ~/.zcode/skills.

Problem and expected behavior

ZCode is not among the clients setup recognizes, so its users must hand-edit a nested JSON structure that no other client uses. Expected behavior: after setup, mcp.servers.rea exists in ~/.zcode/cli/config.json and the REA skill is installed under ~/.zcode/skills; uninstall removes exactly the rea entry and the installed skill directory.

ZCode's configuration dialect (verified against a live install):

  • MCP servers live in the nested mcp.servers table of the user-level config; entries carry command, args, and env (stdio, no transport discriminator).
  • Personal skills are discovered from ~/.zcode/skills, not the shared skills root.

Change and scope

  • SupportedClients: zcode definition — config path ~/.zcode/cli/config.json, marker ~/.zcode/cli, skill path ~/.zcode/skills, format zcode.
  • ClientConfigurationDocument:
    • mcp servers key for zcode (shared with opencode).
    • A zcode branch in parseClientConfiguration that returns the nested table with serversPath: ["mcp", "servers"].
    • withClientServers now treats a missing outer table as empty. This also fixes the same latent crash for a fresh opencode document (the other format using the mcp key), where a missing outer table previously threw during write.
  • docs/installation.md: ZCode row in the supported-clients table plus a short configuration note.
  • Skill install/uninstall plans are already data-driven from the definition's skillPath, so no SetupPlan/Uninstall changes are needed.
  • Intentionally out of scope: non-stdio transports and ZCode-specific skill variants.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application-layer setup client registration (SupportedClients, ClientConfigurationDocument).
  • CLI and MCP/tool-catalog contract: none (no tools added or changed).
  • Provider, bridge, target-format, or platform compatibility: adds the zcode client configuration format (nested mcp.servers JSON).
  • Evidence, artifact, provenance, or reconstruction contract: not applicable.
  • Process execution, authorization, cleanup, or containment impact: uninstall removes only the rea entry and the installed skill directory.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none authored; generated catalogs stay CI-owned.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/filesystem/zcodeClientConfiguration.test.ts (6 cases) — config path resolution, upsert preserving unrelated settings, fresh/empty documents (missing outer mcp table), and uninstall removing only the rea entry. clientLifecycle.test.ts expected-client list now includes zcode.
  • Base reproduction or other evidence: not applicable (feature).
  • User-visible CLI/MCP output (if applicable): setup and uninstall now list "ZCode" as a client label.
  • Remaining proof gaps: the full boundary suite was not run on a Unix host locally; two pre-existing symlink tests in clientLifecycle.test.ts fail on this Windows machine because Node cannot create symlinks without Developer Mode, reproduced identically on stock main.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm ci — clean install (Node v22.23.2, npm 10.9.8; .nvmrc pins 24.18.0, so CI covers the pinned toolchain)
  • npx vitest run tests/boundary/filesystem/zcodeClientConfiguration.test.ts — 6/6 passed
  • npx tsc -p tsconfig.json --noEmit — clean
  • npm run check:fast — typecheck + lint green (also passed as the pre-push hook)
  • npm run verify:test-discovery — all 733 test files discovered exactly once
  • npx vitest run tests/boundary/filesystem/clientLifecycle.test.ts — 41/43 passed; the 2 failures are the pre-existing Windows symlink cases described above (identical on main)

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; config I/O is covered by filesystem boundary tests.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: setup writes only the rea entry into ~/.zcode/cli/config.json (preserving all unrelated settings) and installs the skill under ~/.zcode/skills; no network access or process execution added.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above. (No open issue for ZCode support found; same-pattern precedent discussion in feat(clients): register Qwen Code during setup #1415.)
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output. (New client label in the setup client list only.)
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

- SupportedClients: zcode definition (~/.zcode/cli/config.json, format
  zcode, personal skills at ~/.zcode/skills)
- ClientConfigurationDocument: zcode dialect reads/writes the nested
  mcp.servers table; withClientServers now tolerates a missing outer
  table for fresh documents
- docs: add ZCode to the supported-clients table with configuration notes
- tests: zcodeClientConfiguration.test.ts (path resolution, nested
  upsert, fresh/empty configs, uninstall)

Verified: tsc --noEmit clean; vitest run
tests/boundary/filesystem/zcodeClientConfiguration.test.ts 6/6.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: ZCode (Apache-2.0) setup works. Setup, doctor and uninstall passed in a fake home, and the changed tests passed on Node 22, 24 and 26. The paths match the ZCode docs, with one heads-up about ~/.agents/mcp.json.

Results

Tested on Linux. The PR is c1b9b2315. Main is 6d8f95e38.

Check Result
Config path, mcp.servers key and skill folder against the ZCode MCP docs and skill docs match
Changed tests (49), Node 22.23.1, 24.18.0, 26.11.1 49 of 49 on each
npm run build, npm run docs:check (Node 24) exit 0, exit 0
Fresh home: setup, doctor, setup again, uninstall all work. The second setup changes nothing. Uninstall removes the entry and the skill
Existing config with an enable: false server, ui and model keys all kept after setup and after uninstall
Bad JSON, or mcp set to a list refused, nothing written
Merge with main clean. It conflicts with #1572 in three files and with #1573 in docs/installation.md

Heads-up from the ZCode docs: if any server comes from a .zcode file, ZCode skips ~/.agents/mcp.json in that scope. Setup creates ~/.zcode/cli/config.json. A user who keeps servers only in ~/.agents/mcp.json would lose them. Setup left that file untouched. This comes from the docs, as I did not run ZCode.

Also, this PR does not update the client list in the bundled skill or the website FAQ.

Not run

  • ZCode (Apache-2.0) itself is not installed, so I did not check that it loads the entry or the skill.
  • I did not check whether ZCode moves its config when ZCODE_HOME is set. Setup ignores that variable, and the ZCode docs do not list it.
  • I did not run Windows or macOS, lint, verify:package or the full suite.

Thanks, IvenKooLab, for the nested mcp.servers handling and the clear tests.

Cases I ran and what they showed
Case Result
Fresh home creates ~/.zcode/cli/config.json and ~/.zcode/skills/reverse-engineer-anything; doctor says aligned
// comment in config.json setup keeps the comment. ZCode reads this file with plain JSON.parse in its source, so ZCode cannot read a commented file anyway
Empty file setup fills it in
Only ~/.agents/mcp.json has a server that file is byte-identical after setup
ZCODE_HOME=$H/zhome setup still writes ~/.zcode/cli/config.json. ZCode source mentions ZCODE_HOME for other paths. I did not find it moving the config
OpenCode: no mcp key, empty folder, empty file, mcp.servers already there same file on main and on this PR, no crash. The PR says a fresh OpenCode file used to crash. I could not make that happen on main

Uninstall leaves {"mcp":{"servers":{}}} and a .rea.backup file. I saw the same leftovers for Qwen Code in an earlier test, so this is not new.

Commands
git --git-dir=$HOME/code/rea-mirror/rea.git fetch -q origin
git archive <sha> | tar -x -C <dir>
npm run build && npm run docs:check
node scripts/run-development-tests.mjs focused \
  tests/boundary/filesystem/zcodeClientConfiguration.test.ts \
  tests/boundary/filesystem/clientLifecycle.test.ts
env -i PATH="$NODE24/bin:/usr/bin:/bin" HOME="$FAKE" TMPDIR="$FAKE/tmp" \
  XDG_CONFIG_HOME="$FAKE/.config" XDG_DATA_HOME="$FAKE/.local/share" \
  XDG_CACHE_HOME="$FAKE/.cache" XDG_STATE_HOME="$FAKE/.local/state" \
  npm_config_cache="$FAKE/.npm" timeout 60 \
  node scripts/rea.mjs setup --client zcode --yes --format json

I ran a dry run first. setup without --yes exits 1 and writes nothing.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: c1b9b2315 / 6d8f95e38 (main when I started; the PR's own base is 2d426c924). I also merge-checked against main 603d04ee3: clean.
  • Other: I did not run a fresh npm ci, because the disk was nearly full. I reused a node_modules from another tree with the same package-lock.json (blob 4b668f798).

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Reviewed this change and found two integration gaps:

  1. [P2] Preserve effective fallback servers before writing the first native registration. The definition at src/application/SupportedClients.ts:489–492 writes REA into ~/.zcode/cli/config.json. ZCode's official load rules say that any native server suppresses the entire same-scope ~/.agents/mcp.json fallback, with no merging. Users currently loading unrelated fallback servers, with no native servers, lose access to those servers after setup writes REA. Please preserve the effective fallback registrations or explicitly handle this transition in the setup plan/preflight before writing, with regression coverage.

  2. [P2] Recognize ZCode's native disabled flag during registration inspection. The new dialect uses generic status parsing, which checks enabled and disabled, while ZCode uses enable: false. I reproduced this at the PR head: writing mcp.servers.rea with the expected command/args plus enable: false, then calling readClientRegistrationStatuses, returns state: "aligned" although ZCode considers the server disabled. Please model that flag at the ZCode boundary and add a status regression. Explicit setup reconfiguration can repair the entry; the defect is incorrect status reporting.

Validation: all six new filesystem tests and 43 shared client-lifecycle tests pass on macOS with Node 24.18.0 and npm 11.16.0. An additional disabled-state reproduction fails as described. The native path and nested dialect match official documentation; ZCode itself was not executed.

Review follow-up (morluto#1564), two integration gaps:

- ZCode reads the user-scope ~/.agents/mcp.json fallback only while the
  native .zcode config defines no servers at all, with no merging. Setup
  now copies the fallback's mcpServers entries into the native table when
  writing the first native server, so registrations that only live in
  the fallback keep loading; the fallback file is left untouched. A
  malformed fallback fails setup closed (configure and preflight)
  instead of being silently suppressed.
- ZCode disables a server with "enable": false on its entry, which the
  generic status parsing (disabled/enabled) did not recognize: doctor
  reported such a registration as aligned although ZCode never starts
  it. The ZCode dialect now treats enable: false as disabled (state
  stale) and setup rewrites the entry on rerun.

Docs describe both behaviors; the bundled REA skill's supported client
list includes zcode.

Verified: tsc --noEmit clean; vitest run
tests/boundary/filesystem/zcodeClientConfiguration.test.ts 10/10;
npm run check:fast green; npm run verify:test-discovery 733 files.
@IvenKooLab

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review — both gaps are real and confirmed against the ZCode docs, and both are fixed in 8657bf2.

1. Fallback suppression. Setup now preserves the effective fallback registrations: when it writes REA into an empty native table (mcp.servers absent or empty), it copies the user-scope ~/.agents/mcp.json mcpServers entries into the native table alongside REA and leaves the fallback file untouched, so servers that only lived in the fallback keep loading. When the native table already has servers, setup does not read the fallback (nothing effective is lost). A malformed fallback now fails setup closed — in configureClientConfiguration and in the setup preflight (inspectClientConfiguration reports invalid with a repair remediation) — instead of being silently suppressed. Covered by three new regression tests: migration with verbatim entry preservation (including env), no merging into an existing native table, and fail-closed on a malformed fallback.

2. enable: false status. Confirmed and reproduced the same way. The registration schema now carries enable, and the ZCode dialect treats enable: false as disabled: doctor reports state: "stale" with the standard refresh remediation, and rerunning setup repairs the entry (the desired entry has no enable field, so the value comparison rewrites it). Covered by a regression test asserting both the stale report and the return to aligned after setup.

Docs describe both behaviors in docs/installation.md, and the bundled REA skill's supported-client list now includes zcode (also covering the list gap CassieFox23 noted).

Validation: tsc --noEmit clean, npm run check:fast green, npm run verify:test-discovery 733 files discovered once, zcodeClientConfiguration.test.ts 10/10. The shared suites still show 4 pre-existing Windows-environment failures (2 symlink cases in clientLifecycle, 2 command-resolution cases in clientRegistrationStatus); all four reproduce identically on stock main, as noted in the PR description.

@dandgabr dandgabr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consolidated review

  • P2 — Reject non-regular ZCode fallback files before reading. readZcodeFallbackServers reads ~/.agents/mcp.json directly with readFile (src/application/SetupClientConfiguration.ts:335-349). During setup or preflight for the first native registration, a FIFO at that path can block the operation indefinitely; this read also bypasses the regular-file/path admission used for client configuration files. Please use the existing safe regular-file admission and transaction-path checks for the fallback before parsing or copying its entries. The previously reported fallback-preservation and enable: false findings are resolved at this head; no other actionable findings were confirmed.

Resolve the fallback through the client-config transaction path and the
regular-file admission before parsing it, so a FIFO or other non-regular
file at ~/.agents/mcp.json fails setup closed instead of blocking the
read indefinitely. Directory and FIFO fallback cases are covered in
tests, and the preflight remediation names unreadable fallbacks too.
@IvenKooLab

Copy link
Copy Markdown
Contributor Author

Thanks — fixed in a443d33.

readZcodeFallbackServers now admits the fallback like any other client configuration source: the path resolves through resolveClientConfigTransactionPath (the same symlink policy as the native config), and the content is read via the existing regular-file admission, so a FIFO at ~/.agents/mcp.json is rejected by the non-blocking open + stat check instead of hanging the read, and any other non-regular or unreadable fallback fails setup and preflight closed. The preflight remediation now names unreadable fallbacks alongside malformed ones.

Tests: a directory at the fallback path (cross-platform) and a mkfifo fallback rejected without blocking (POSIX-only, mirroring the existing FIFO tests). Validation: zcodeClientConfiguration.test.ts 12/12, clientLifecycle.test.ts 43/43, tsc --noEmit clean, prettier --check clean.

@morluto
morluto merged commit 51d6c87 into morluto:main Oct 12, 2026
30 checks passed
@morluto

morluto commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thanks @IvenKooLab for adding ZCode support! The nested MCP configuration and personal skill registration make setup much easier for ZCode users. I also appreciate your work on the follow-up fixes and regression coverage. Great work!

@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added enhancement New feature or request area: cli CLI adapter and one-shot commands labels Oct 14, 2026
@morluto morluto added the area: setup Setup, packaging, upgrade, install, Doctor, and client registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants