Skip to content

feat(agents): add ZCode (Z.ai) agent adapter - #157

Open
Geerdan1995 wants to merge 1 commit into
nexu-io:mainfrom
Geerdan1995:zcode-agent
Open

Geerdan1995 wants to merge 1 commit into
nexu-io:mainfrom
Geerdan1995:zcode-agent

Conversation

@Geerdan1995

Copy link
Copy Markdown

What

Adds a ZCode agent adapter (Z.ai's coding agent CLI, open-sourced last week at zai-org/ZCode) — the "hook up a new coding-agent CLI" bucket from CONTRIBUTING (~an entry + argv + parser, plus one Windows-specific delivery fix in invoke.ts).

ZCode's headless shape is zcode --json -p "<prompt>": one yolo-permissioned turn, printing a single JSON document ({sessionId, response, usage}) on close — no ndjson stream, no stdin prompt sentinel.

Changes

  • detect.ts — zcode entry (protocol argv, ZCODE_BIN override). No --model flag exists in the CLI yet, so only the synthetic DEFAULT_MODEL is offered (the CLI's configured default model wins).
  • argv.ts — --json -p flags; parser extracts response / sessionId / usage.totalTokens from the closing JSON document.
  • invoke.ts — two integration details:
    1. The prompt is delivered via --attach <temp-file> instead of -p <text>: multi-line prompts cannot survive Windows argv — npm's .cmd shims (and the existing shell: true spawn) re-parse the command line at newlines, so the 4KB skill prompt arrives truncated and -p errors with "argument missing". zcode --attach is the CLI's native file-input path.
    2. zcode joins openclaw in skipping the per-line stdout loop (whole-document parse on close).

Verification

End-to-end on Windows 11, zcode 0.16.9 running GLM-5.3 via a Z.AI coding plan:

  • detection: available: true via the npm-shim path
  • a full article-magazine conversion through the app produces a complete 12.6KB standalone HTML document (<!DOCTYPE html> … </html>)
  • temp prompt files are cleaned up on close/abort

中文摘要:接入 ZCode(Z.ai 刚开源的 Agent CLI)。无头形态是 zcode --json -p 单轮执行 + 关流时输出单个 JSON 文档。Windows 上多行提示词过 cmd.exe 会被截断,所以提示词经 --attach 临时文件投递(CLI 原生能力),解析器从整份 JSON 中提取 response/usage。已在 GLM-5.3 Coding Plan 上端到端验证杂志模板真实生成。

Related: #156 (community desktop packaging — same author).

- detect.ts: zcode entry (protocol argv, ZCODE_BIN override)
- argv.ts: --json -p flags + single-JSON-document parser (response/usage)
- invoke.ts: deliver the prompt via --attach temp file — multi-line
  prompts cannot survive Windows cmd.exe argv (npm .cmd shims re-parse
  at newlines), and zcode -p takes no stdin sentinel. Skips the per-line
  stdout loop like openclaw (whole-document parse on close).

Verified end-to-end on Windows: zcode 0.16.9 via GLM-5.3 coding plan
generates a full magazine-article HTML through the app.
@lefarcen
lefarcen requested a review from mrcfps September 21, 2026 10:31
@lefarcen lefarcen added size/S Small change: 20-99 changed lines risk/medium Medium risk change type/feature Feature or new user-facing capability labels Sep 21, 2026
@lefarcen

Copy link
Copy Markdown

Heads-up: #139 is also open for ZCode support. Both PRs change next/src/lib/agents/argv.ts, detect.ts, and invoke.ts, but they take different transport approaches: this PR uses the one-shot CLI JSON path, while #139 implements ZCode's app-server protocol discussed in #138. Sharing the overlap so the authors and maintainers can compare the assumptions before choosing what lands.

@mrcfps mrcfps 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.

@Geerdan1995 thanks for this tidy adapter — the Windows --attach workaround is a thoughtful catch.

Verified the three-file change against ZCode's current CLI (--json / -p / --attach, one closing JSON document with response / sessionId). Detection, argv, whole-document parse-on-close, and temp-file cleanup on the success and abort paths all line up with the stated headless shape, and the special-case in invoke.ts leaves the other argv agents alone.

Nice work shipping a real end-to-end path on Windows 11. 🙌

🔁 Powered by Looper · runner=reviewer · agent=omp · An autonomous AI dev team for your GitHub repos.

@lefarcen lefarcen added the needs-product-review Feature PR awaiting product sign-off before merge (see roadmap) label Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-product-review Feature PR awaiting product sign-off before merge (see roadmap) risk/medium Medium risk change size/S Small change: 20-99 changed lines type/feature Feature or new user-facing capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants