Skip to content

[建议 / Feature] 支持非交互式 / 可脚本化的单轮执行模式(对标 codex exec / claude -p) #29

Open

Description

@15195999826

提交前确认 · Pre-submission checklist

  • 我已搜索过现有 issue,确认这不是重复提议 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

问题类别 · Category

其他 / 不确定 · Other / Not sure

涉及的 Agent 框架 · Agent framework

多个 / 通用 · Multiple / General

使用场景 · Use case

在 CI / 脚本 / 自动化里想把 ZCode 当成一个可被 shell 调用的"单次任务执行器":从命令行参数或 stdin 读入一段 prompt,跑完即退出,把结果输出到 stdout。
现在 ZCode 主要是桌面 / 交互式会话,没法被 Makefile、git hook、CI 流水线、shell pipeline 这种"非交互"场景直接调用——这些场景里没有 TTY、也不能让人盯着等输入。

具体例子:

  • zcode exec "把 src 下所有 TODO 注释列出来" —— 跑完打印结果就退
  • cat changed.diff | zcode exec "review 这段 diff,只输出 pass/fail" —— 塞进 pre-commit / CI gate
  • zcode exec --json "生成这周的 changelog" —— 输出 JSON 给后续脚本消费

建议方案 · Proposal

增加一个非交互、单轮、脚本可调用的执行模式(对标 codex exec / claude -p)。期望形态:

  • 从命令行参数或 stdin 读取 prompt;
  • 执行完一次性退出,不进入交互 REPL;
  • 结果写到 stdout(建议支持 --output-format json 之类选项,便于脚本解析);
  • 可配置 --model、--cwd / --cd、超时、权限模式等。

说明:这和 #8(Linux 版本和 ZCode Agent CLI)、#26(支持远程编程吗?)方向相关但不重复——那两个 issue 主要诉求是「出一个交互式 CLI / 远程接入能力」(Linux / SSH / REPL 场景);本 issue 聚焦的是「非交互、单轮、可脚本化」这个更窄但很常用的子能力(CI / 自动化 / shell pipeline)。两者可以独立评估、也可以一起规划,但场景不同,单独跟踪更清晰。

预期价值 · Expected value

  • 打通 CI / 自动化场景:pre-commit review、PR 自动检查、批量代码处理、定时任务(与 [建议 / Feature] 增加「定时任务 / 自动化调度」能力(Scheduled Tasks) #27 协同)都能用 ZCode 跑。
  • 让 ZCode 能作为 Unix pipeline 里的一环(stdin 进、stdout 出),复用现有工具链。
  • 降低从 Codex / Claude Code 迁移用户的迁移成本——他们已有大量依赖 codex exec / claude -p 的脚本和流水线。
  • 解锁"无人值守"工作流(无 TTY 的服务器、容器、CI runner),这是纯交互式 CLI 覆盖不到的场景。

你认为的优先级 · Your perceived priority

高 · High

你使用的 ZCode 版本 / 环境 · ZCode version / environment

3.1.2 / Windows 11

补充材料 · Additional context

参考实现:

  • Codex:codex exec "<prompt>"(非交互,可 --json)
  • Claude Code:claude -p "<prompt>"(print 模式,非交互)

Activity

  1. github-actions commented on Jun 21, 2026

    @github-actions

    👋 感谢你的反馈,我们已经收到。

    • 维护者会在 3 个工作日内 给出首次响应。
    • 状态保持为 status: 待评估,你可以随时补充信息。
    • 信息不全时我们会打上 needs: 更多信息 标签并 @ 你。

    👋 Thanks — we've received your issue.

    • A maintainer will respond within 3 business days.
    • Status stays at status: 待评估 (Triage); feel free to add context.
    • If we need more details, we'll add needs: 更多信息 and ping you.
  2. vtsixthai commented on Jul 6, 2026

    @vtsixthai

    +1 — strong support for this. Did a read-only pass over 3.2.5 and it turns out most of the machinery for a single-shot mode already ships in the bundle; what's missing is just a user-facing -p-style entrypoint. Hoping this evidence makes the issue easier to triage.

    What already exists under the hood (from app.asar, ZCode 3.2.5):

    • A real CLI exists: apps/zcode-cli/packages/cli/dist/zcode.cjs, launched via a shebang wrapper (#!/bin/sh … exec "$runtime_root/node" …).
    • It already runs as a JSON-RPC-over-stdio service: app-server --stdio (controlled via ZCODE_AGENT_SERVER_ARGS_JSON / ZCODE_AGENT_SERVER_CWD, spawned under ELECTRON_RUN_AS_NODE=1).
    • Full ACP-style session methods are reachable from that interface: session/create, session/send, session/subscribe, session/steer, session/events, session/read, session/list, plus turn.*/part.*/message.* event streams.
    • @agentclientprotocol/sdk is bundled, so the same protocol shape used to drive claude -p / codex exec is viable here.

    So zcode -p "<prompt>" is essentially: session/create → session/send → drain until turn.completed → print the final assistant part(s) to stdout → exit.

    Proposed entrypoint shape (stacking on the list already in the issue):

    zcode -p "<prompt>"            # equivalent to claude -p / codex exec
    zcode -p --json "<prompt>"     # NDJSON event stream for scripting
    zcode -p --model <ref> --cwd <path> --permission-mode <acceptEdits|plan|default>
    echo "<diff>" | zcode -p "review, reply pass/fail only"
    

    Semantics worth pinning: --json streams the raw event stream (turn.*/part.*); plain mode (default) emits only final assistant text on stdout with progress/diagnostics on stderr to keep stdout clean — matches claude -p.

    Rabbit holes worth flagging up front:

    1. MCP process lifecycle — a non-interactive session/create has to tear down MCP servers cleanly on exit or single-shot scripts will leak processes. There are already two open bugs on exactly this (MCP server 进程在重连/重启时未回收旧实例 and 同一 workspace 重复 session/create 导致 MCP 进程泄漏); a headless CLI would hit the same path on every run. Suggest agent-level cleanup after turn.completed, or an explicit --no-mcp.
    2. Auth / credentials — a headless CI runner has no desktop OAuth. Needs ZCODE_* env-var / API-key auth (GLM Coding Plan already has an API-key mechanism; expose it).
    3. Permission mode — for unattended runs the default must be non-interactive (either auto-deny tool calls, or a --permission-mode à la acceptEdits/bypassPermissions like Claude Code). Popping an interactive confirm with no TTY would just hang.
    4. Steering/queue relationship — session/steer currently returns {kind:"unsupported", message:"ZCode Protocol steering is not wired yet."} (see [建议 / Feature] Enter=排队 / queue, Ctrl+Enter=引导 / steer (对齐 Codex 行为) #95). Doesn't block -p`, but worth noting it's the same family of "expose existing internals via the protocol".
    5. Output determinism — for CI gates (pass/fail) the exit-code contract matters (e.g. non-zero = review failed, 0 = passed). Suggest not overloading exit codes for anything else.

    Why this is high-leverage: it's not a greenfield feature — it's wiring a thin command layer on top of the existing zcode.cjs that maps to session/create+session/send+drain, plus a defined stdout/stderr/exit-code contract. ACP + the stdio JSON-RPC server already do the heavy lifting.

    Happy to attach a PoC patch or a worked transcript. Watching this one. 🙌

  3. panda920 commented on Aug 17, 2026

    @panda920
    Collaborator

    📌 已把重复反馈合并到这条

    以下 issue 反映的是同一个问题,已合并到这里统一跟进:#8、#26、#215、#270

    共同根因:ZCode 目前只能通过桌面端交互使用。社区需要一个可被 shell/CI/git hook 调用的非交互执行入口,以及一个可独立安装、TUI 可用的 CLI 发行版(桌面端内置的 zcode.cjs 缺 @zcode/tui 包)。

    独立反馈人数:5

    优先级已从 P2 调整为 P1。

    后续进展只会更新在这条 issue 下,被合并的几条已关闭并打上 duplicate。如果你认为其中某条其实是另一个问题,在那条下面回复,我们会重新拆出来。


    📌 Duplicate reports consolidated here

    The following issues describe the same problem and are now tracked here: #8, #26, #215, #270

    Shared root cause: ZCode can only be driven interactively from the desktop app today. The community needs a non-interactive entry point callable from shell / CI / git hooks, plus a standalone CLI distribution with a working TUI (the bundled zcode.cjs is missing the @zcode/tui package).

    Distinct reporters: 5

    Priority raised from P2 to P1.

    Updates will only be posted on this issue; the merged ones are closed and labelled duplicate. If you think one of them is actually a different problem, reply there and we'll split it back out.

  4. added
    priority: P1
    and removed
    priority: P2
    on Aug 17, 2026
  5. demouo commented on Sep 4, 2026

    @demouo

    您好!非常需要zcode cli 蛮多服务器是无桌面的 glm-5.3还是在zcode上用更加丝滑,感谢

  6. Tr0jAnV1rU4 commented on Sep 6, 2026

    @Tr0jAnV1rU4

    希望推进该想法,真的很需要CLI工具

  7. fely-zhao commented on Sep 7, 2026

    @fely-zhao

    +1非常需要cli....现在都是通过wsl开发,且在wsl中统一管理所有agent...虽然目前版本远程开发已经可以了,但是不怎么方便。。

  8. liubaicai commented on Sep 8, 2026

    @liubaicai

    we need chinese...对不起走错台了,we need cli

  9. Hyacinth-YX commented on Sep 8, 2026

    @Hyacinth-YX

    we need cli 👍

  10. ahxinin commented on Sep 8, 2026

    @ahxinin

    i need cli

  11. mahan002 commented on Sep 9, 2026

    @mahan002

    非常需要cli

  12. LetterTree commented on Sep 10, 2026

    @LetterTree

    need CLI!

  13. beiyanpiki commented on Sep 10, 2026

    @beiyanpiki

    不止cli, 最好能同时将tui适配一下

  14. JamesbbBriz commented on Sep 10, 2026

    @JamesbbBriz

    非常需要

  15. agent-labs1998 commented on Sep 12, 2026

    @agent-labs1998

    +1,非常期待并强烈支持 ZCode CLI / TUI 及非交互单轮执行模式(对标 codex exec / claude -p)的落地!

    结合我们日常的真实开发工作流,补充几个为什么我们非 CLI / TUI 不可的核心场景与痛点:

    1. 无桌面环境(Headless / Remote Linux Server / WSL)的刚性需求:

      • 我们的开发与调试环境大量部署在 Remote Linux 服务器和 WSL 中,服务器环境完全没有 GUI 桌面。
      • 虽然目前的版本支持了远程能力,但由于缺乏完善的命令行/终端交互,需要在 VSCode 与桌面客户端之间频繁来回切换上下文,且无法及时接收终端内的实时反馈,大幅降低了开发效率。
    2. 嵌入现有工具链与脚本自动化(CI/CD Gate & Git Hooks):

      • Pre-commit / PR 自动 Review:期望能在 Git Hook 或 CI 中直接通过脚本(如 cat changed.diff | zcode exec "review 这段 diff,只输出 pass/fail")进行静默 Review,并根据返回结果决定是否阻断提交。
      • 单次任务自动化:在 CI/CD 流水线中批量处理代码(自动生成注释、格式化修剪、提取 Changelog 等),这需要 ZCode 能够作为无 TTY 阻塞的单次任务执行器,执行完毕后直接退出并返回标准的 exit code 以及 --output-format json 输出。
    3. Unix Pipeline 数据流与 Agent 工具链链式调用:

      • 在 Linux/Mac 环境下,大部分自动化脚本依赖 stdin/stdout 进行数据流传递。如果只提供 GUI 交互,自动化流程就会被迫中断,必须依赖人工手动复制粘贴上下文。
    4. 补全桌面版内置 CLI 缺陷(如缺少 @zcode/tui 包):

      • 希望官方在规划 CLI 时,能同步提供独立的 CLI 发行版,并修复桌面版自带 zcode.cjs 缺少 @zcode/tui 导致终端 UI 无法正常拉起的问题。

    总结:
    ZCode 的模型能力和 Agent 表现非常出色,但只有具备了独立的 CLI / TUI 及非交互脚本化模式,它才能从“桌面辅助工具”真正升级为“研发流程基础设施”。感谢社区维护者的倾听与跟进,希望能尽快看到 CLI 发行版的落地!

  16. Martian101 commented on Sep 13, 2026

    @Martian101

    非常需要,做基于tmux的多agent协同,通过cli还是很方便的

  17. longbow1998 commented on Sep 14, 2026

    @longbow1998

    需要cli

  18. ryaningli commented on Sep 29, 2026

    @ryaningli

    期待cli、tui

  19. maxweight commented on Oct 6, 2026

    @maxweight

    we need cli😭

  20. misa527528 commented on Oct 8, 2026

    @misa527528

    很需要 cli,期待早日推出,感恩

  21. zm112211mz commented on Oct 27, 2026

    @zm112211mz

    补充:独立 CLI(node-bundle 0.17.0 / Desktop 3.16.3)headless 链路排查——三处断点与复现

    环境:macOS (Apple Silicon)、ZCode.app 3.16.3、内置 CLI zcode.cjs 0.17.0(node-bundle artifact)。

    目标场景:在本 issue 的目标(shell/CI/git hook 可调用的非交互入口)下,让 zcode -p 复用桌面端已登录的 bigmodel 套餐(含闲时免费额度)跑 headless 任务。

    TL;DR:-p 在独立运行时存在三处相互叠加的断点,导致账户供应商永远无法进入注册表,最终表现为 Error: Select a model before sending a message;login 命令报 OAuth 错误也是同一根因。三处均已定位到具体函数。


    断点 1(即 #51 已报告的打包缺陷):CLI 相对自身目录定位内置 Provider 配置失败

    resolveBundledZCodeBuiltinProviderConfig 依次查找 <glm>/provider/zcode-builtin.json 与 <glm>/../../../../../config/provider/zcode-builtin.json,与 App 实际布局 Resources/config/provider/zcode-builtin.json 不符。可用环境变量绕过(prepareCliProviderRuntimeEnv 的 pass-through 分支):

    export ZCODE_BUILTIN_PROVIDER_CONFIG_FILE="$HOME/.zcode/v2/runtime/provider/darwin-aarch64/3.16.3/endpoint-*/zcode-builtin.json"
    export ZCODE_PERSONAL_PROVIDER_CONFIG_FILE="$HOME/.zcode/v2/provider_config.json"

    绕过后 -p 可进入模型选择阶段。

    断点 2(核心):独立模式账户源 bootstrap 必然为空

    • AccountProviderService 为纯内存实现,无持久化,每次启动经 njn → ejn 重新解析;
    • 首次 resolve 传入的 configuredProviders 为空 → ejn 走已有配置分支 → 返回空列表 → 之后永远为空(bootstrap 悖论);
    • login 路径(ejn 无入参分支)读取内置配置的 config.providers 字段,但现行配置格式(revision 33)中账户供应商实际声明在 config.providerConfigRules.providerRules(access.type === "zhipu-account" 条目,含 account:bigmodel-start-plan、account:bigmodel-offpeak-idle-plan 等 10 个),config.providers 字段不存在 → t.providers.entries() 抛 TypeError → 被 onDidRefreshError 静默吞掉;
    • 结果:xet({configuredDefault, registry}) 遍历 registry.providers 为空 → source:"none" → Select a model before sending a message。

    断点 3:OAuth JWT 无法通过 V4 请求签名

    • 签名 key 解析(D1r)只接受两类格式:payload 含 api_key 字段的 JWT,或 id.secret 形式的 API Key;
    • 共享凭据 ~/.zcode/v2/credentials.json 的 oauth:bigmodel:access_token payload 仅含 user_id / user_key / customer_id 等,无 api_key → ClientRequestSigningV4Error: Client signing requires an API Key or Project Access Token.;
    • 桌面端不受影响:账户供应商由宿主进程注入,请求凭证走服务端项目密钥(凭据文件中的 project-key-location 条目仅含 organizationId/projectId/apiKeyId 元数据,密钥本体不在本地);
    • 旁证:在 personal 配置 providerConfigRules.providerRules[0].config.access.apiKey 填入任意值,即可让 bigmodel-api 模板供应商进入注册表并自动选中模型(说明注册/选择链路本身是通的),仅在签名层被拒。

    复现步骤

    export ZCODE_BUILTIN_PROVIDER_CONFIG_FILE="$HOME/.zcode/v2/runtime/provider/darwin-aarch64/3.16.3/endpoint-*/zcode-builtin.json"
    export ZCODE_PERSONAL_PROVIDER_CONFIG_FILE="$HOME/.zcode/v2/provider_config.json"
    node /Applications/ZCode.app/Contents/Resources/glm/zcode.cjs -p "hi"
    # → Error: Select a model before sending a message (traceId: 84dc8338-afba-41d3-ab5a-45223a80019a)
    
    node /Applications/ZCode.app/Contents/Resources/glm/zcode.cjs login bigmodel
    # → OAuth 报错(断点 2 同根因)

    影响:未创建 Coding Plan API Key 的套餐用户(含仅使用闲时免费额度的用户)完全无法使用 headless CLI;独立 CLI 的登录复用在此版本不可用。

    修复建议:

    1. ejn 的 bootstrap/login 分支回退解析 config.providerConfigRules.providerRules 中 access.type === "zhipu-account" 的条目(数据已存在于配置中,仅字段路径不匹配);
    2. CLI 配置定位路径与 App 实际布局对齐,并按 [Bug] ZCode 3.1.6 (macOS, Apple Silicon) unusable via every entry point: desktop EPIPE + blank renderer; CLI missing @zcode/tui; CLI login "OAuth response is not valid JSON" (model & plan are fine) #51 随包分发 @zcode/tui;
    3. doctor 增加 standalone 账户源自检项,使被吞掉的 onDidRefreshError 对用户可见;
    4. 期望行为:独立 CLI 复用共享登录态(credentials.json 可由机器派生密钥解密,已验证可行)。
  22. SeveNOlogy7 commented on Nov 2, 2026

    @SeveNOlogy7

    交叉引用(#855 / #51 的打包层定位)+ 一组对照数据:清掉断点 1 之后 -p 能跑,但没有走套餐 provider

    按你给的 env 旁路,我在 Windows 上复现了断点 1,同时得到一个与断点 2 / 3 直接相关的对照数据点 —— 结论不否定你的分析,但可以把「打包层」和「账户层」分得更干净。

    1. 断点 1 在 Windows 侧完全一致

    Desktop 3.17.1 / 内置 CLI 0.17.1(node-bundle,sea: no)。zcode.cjs 里等价代码:

    const dir = dirname(realpathSync(resolve(entrypoint)));        // ...\ZCode\resources\glm
    const candidates = [
      join(dir, 'provider', 'zcode-builtin.json'),
      resolve(dir, '../../../../../config/provider/zcode-builtin.json')
    ];

    而 App 实际把配置发布在 resources\config\provider\zcode-builtin.json(rev 43,260,787 B)—— 只差 1 层,代码却往上找了 5 层。完整的 A/B 报错原文与三种改法我补在 #855 了。

    你给的旁路确认可用;补充一点:两个变量必须成对设置,只设一个会直接抛

    ZCode Built-in 与 Personal Provider Config 路径必须同时提供
    

    2. 对照数据:-p 跑通了,但落到的是 api-key provider

    $ zcode -p hi
    Hi! What would you like to work on?
    

    同一时刻日志(~/.zcode/cli/log/zcode-YYYY-MM-DD.jsonl):

    ttft.model.request_started   providerId=opencode-go-chat  modelId=deepseek-v4.1-flash
    model.sdk.stream.completed   providerKind=openai-compatible
    

    原因在 personal 配置里:

    "defaultModelSelection": { "providerId": "opencode-go-chat", "modelId": "deepseek-v4.1-flash" },
    "providerOrder": ["8794af26-…", "opencode-go-chat", "opencode-go-messages", "opencode-zen-chat"]

    providerOrder 里没有任何 account:* —— 所以 -p 只会选中 api-key provider。

    更准确的表述是:

    personal providerRules / providerOrder 里有没有可用的非账户 provider -p 表现
    有(本机:4 条 api-key,默认指向 opencode-go-chat) 能跑,但不消耗套餐,也不会报 Select a model
    没有(推测是你的环境) 注册表为空 → Select a model before sending a message

    这还解释了一个容易误判的现象:有套餐的用户在 -p 下可能悄悄用掉另一个 provider 的额度,看起来"套餐可用",实际根本没走套餐。

    3. 你的断点 2 细节被证实

    rev 43 的 config 只有 providerConfigRules / modelConfigRules,确实没有 config.providers;而 zcode_protocol.provider_registry.ready 的 accountRevision 里 10 条 zhipu-account 全部是 entitled:false:

    {providerId:"account:zai-individual-coding-plan", access:{type:"zhipu-account", entitled:false}} × 10
    

    4. 一个供继续验证的反差

    同一台机器上,同一个 bundled CLI 的交互式会话日志里能看到账户 provider 的成功请求:

    model.sdk.stream.completed  providerId=account:bigmodel-individual-coding-plan
                                modelId=GLM-5.3-Flash   providerKind=anthropic
    

    也就是说账户源并非在整个 CLI 里都不可用,差异更像是出现在 -p 的引导 / 模型选择阶段(ejn 的首轮 resolve),而不是账户源本身。如果这一点成立,修复面会比"账户源完全不可用"小不少。

    5. 建议的判别命令

    # 1) personal 配置里有没有可用的非账户 provider(不要贴 apiKey)
    jq '{defaultModelSelection, providerOrder,
         rules: [.config.providerConfigRules.providerRules[] | {providerId, type: .config.access.type}]}' \
       ~/.zcode/v2/provider_config.json
    
    # 2) 跑一次 -p 后确认实际使用的 provider
    grep -o 'ttft.model.request_started.\{0,200\}' ~/.zcode/cli/log/zcode-$(date +%F).jsonl | tail -1
    • 第 2 步显示 opencode-* / 其它 api-key provider → 与本机一致,需要把 defaultModelSelection 指向账户 provider 才能验证断点 3(签名层);
    • 第 2 步显示 account:* → 说明断点 2 在 0.17.1 已部分改善。

    6. 小结

    这里其实是两处独立修复,互不替代:

    1. 打包层([Bug] CLI 非 SEA 运行时无法定位 zcode-builtin.json:login 在 OAuth 授权完成后才报「无法定位 CLI ZCode Built-in Provider Config」 #855 / [Bug] ZCode 3.1.6 (macOS, Apple Silicon) unusable via every entry point: desktop EPIPE + blank renderer; CLI missing @zcode/tui; CLI login "OAuth response is not valid JSON" (model & plan are fine) #51):路径错位 + @zcode/tui 未随包分发;
    2. 账户层(本条断点 2):providerConfigRules.providerRules 的数据源与 ejn bootstrap 分支。

    前者修好之前,用户会先撞一次墙(无法定位 … / Cannot find package '@zcode/tui'),所以两条 issue 的症状很容易混在一起。

  23. SeveNOlogy7 commented on Nov 2, 2026

    @SeveNOlogy7

    补充一条受控实验:Windows 0.17.1 上独立 -p 的失败点是「签名层」(断点 3),不是「模型选择」(断点 2)—— 并更正我上一条里的一处推断

    1. 受控实验

    方法:把 ~/.zcode/v2/provider_config.json 的 defaultModelSelection 临时指向账户 provider,跑一次 -p,然后立刻按备份还原(sha256 校验一致)。这样能把「模型选择」和「认证/签名」两段分开。

    "defaultModelSelection": {
      "providerId": "account:bigmodel-individual-coding-plan",
      "modelId": "GLM-5.3-Flash",
      "options": { "reasoningLevel": "max" }
    }
    $ zcode -p hi
    (stdout 为空)
    APICallError [AI_APICallError]: Unauthorized

    日志(~/.zcode/cli/log/…jsonl)里的完整链条,baseURL = open.bigmodel.cn:

    ttft.model.request_started            providerId=account:bigmodel-individual-coding-plan  modelId=GLM-5.3-Flash
    model.client_signing.handshake_failed  errorKind=handshake-business  businessCode=1000  providerId=account:bigmodel-individual-coding-plan
    model.client_signing.unsigned_sent     providerId=account:bigmodel-individual-coding-plan
    model.request.failed                   status=401 "Provider authentication failed."  providerKind=anthropic
    turn.failed                            code=provider_not_configured  errorPhase=stream  statusCode=401
    

    读法:

    • 断点 2 未复现 —— provider 被正确选中,没有出现 Select a model before sending a message;
    • 断点 3 复现 —— 签名握手失败(handshake-business / businessCode=1000)→ CLI 改为无签名发送 → 401。

    所以在这台机器上,账户 provider 的注册 / 选择是通的,卡住的是「用 OAuth 凭据生成 V4 签名」这一步 —— 与你的断点 3 描述一致。

    2. 更正:上一条里「交互式会话能成功」的推断

    上一条我写「交互式会话日志里能看到账户 provider 的成功请求」,依据是同一份 CLI 日志里带 account:bigmodel-individual-coding-plan 的 model.sdk.stream.completed。

    查了 session 库后确认:那些记录来自一个长期并发的会话(同一个 id 从 10/31 持续到 11/02,工作目录是另一个项目,21 次请求、带 22 次工具调用),不是一次受控的独立 CLI 调用 —— 它很可能来自桌面宿主(按你的说法,宿主会注入凭据)。

    因此那条推断撤回:目前唯一受控的独立 CLI 数据点,是上面这次签名失败。抱歉造成误导。

    3. 对定位的意义

    断点 Windows / CLI 0.17.1 实测 备注
    1 打包路径 复现 见 #855;env 旁路可绕(两个变量必须成对设置)
    2 注册表 bootstrap 为空 未复现 personal providerRules 里已存在 account:* 条目时不会为空 → 与你的「已有配置即走另一分支」推测一致
    3 OAuth 凭据无法生成 V4 签名 复现 handshake-business 1000 → 无签名发送 → 401 provider_not_configured

    结论:#855 修好之后,套餐用户的 -p 仍会卡在断点 3;而断点 2 更像是一个「配置为空 + 首轮 resolve」的边界条件,值得单独确认。

    如果需要,我可以把这次实验的完整日志链(含时间戳、traceId,已去除个人路径)整理后贴上来。

  24. SeveNOlogy7 commented on Nov 6, 2026

    @SeveNOlogy7

    更正上一条:断点 3 不是签名协议问题,而是「用哪个凭据去签」—— project access token 可以通过 V4 签名

    上一条我写「断点 3 复现:签名握手失败」。继续做 A/B 后需要更正:签名协议本身是通的,结果取决于 standalone CLI 选用的凭据来源。

    复现(Windows / CLI 0.17.1)

    zcode -p hi,defaultModelSelection = account:bigmodel-individual-coding-plan / GLM-5.3-Flash:

    model.client_signing.handshake_failed  errorKind=handshake-business  businessCode=1000
    model.client_signing.unsigned_sent     reason=handshake_failed
    model.request.failed                   status=401  "Provider authentication failed."
    

    握手响应体(只读探针,HTTP 200 但业务码非 200):

    POST https://open.bigmodel.cn/api/paas/c1f3a7e2/v2/client
    {"code":1000,"msg":"身份验证失败","success":false}
    

    实际送出的凭据形状:field=apiKey apiKeyId.len=32 secret.len=16 secret.dots=0

    换到 OAuth 来源后

    createStandaloneProviderRuntimeHeadersPort.refreshBeforeModelRequest 里有两条分支:

    // auth-source === "manual"
    R = await credentialStore.load(W5e({ providerId, accountIdentity }));        // 手工 key
    
    // 否则(存在登录 token)
    F = await i.resolveMaterial({ family, accessToken, accountIdentity, ... });  // project access token
    R = F.token; D = F.apiKeyId;

    把分支强制到 oauth 后(只改诊断副本,不改安装包):

    field=accessToken  apiKeyId.len=32  secret.len=463  secret.dots=2
    POST .../v2/client  →  {"code":200,"msg":"操作成功","data":{"privateCipher":"…"}}
    

    签名成功,请求到达模型端,返回的是配额而不是 401:

    [1310][您已达到每周/每月使用上限,您的限额将在 2026-11-07 23:50:10 重置。]
    

    对断点 3 的修正

    凭据 handshakeField 握手结果
    manual coding-plan API key(id.secret) apiKey code 1000 身份验证失败
    OAuth → project access token(HS256 JWT,token_use:"project_access") accessToken code 200 操作成功

    所以在这台机器上 断点 3 不成立 —— 用 project access token 时 V4 签名是通的。真正卡住的是:auth-source=manual 时,standalone CLI 会拿 coding-plan API key 当签名凭据,而签名服务不接受它;失败后按 failOpenEligible 降级为无签名发送,才得到 401。

    给维护者的两个问题

    1. auth-source=manual 时用 coding-plan API key 做 V4 握手,是设计如此,还是应该改用别的凭据?
    2. 如果 manual key 不适用于签名,refreshBeforeModelRequest 是否应在降级成 unsigned 之前回退到 oauth(现在会直接 401)?

    不贴凭据的判别命令:

    # 键名是明文、值是加密的,可安全查看
    jq -r 'keys[] | select(test("account-provider:.*:(auth-source|api-key)$"))' ~/.zcode/v2/credentials.json
  25. gzhanlei commented on Nov 17, 2026

    @gzhanlei

    补一个刚实测过的真实用例(CoDelphi Radar skill),支持这个提案,并补充一个重要场景维度:「单发直调」不只是 CI 场景,也是 skill 协议里"宿主代为执行模型任务"的基础设施。

    背景

    CoDelphi 的开源 radar skill(分析一个 Git 仓库生成产品功能 HTML 报告)已经按"宿主原生模式"设计:skill 先确定性切出 65 个自包含工单(源码嵌在 prompt 里、禁用工具、纯补全、一发一分区),期望宿主把每个工单单轮直调给当前模型。这个形态天然适配 zcode exec:stdin/参数进 prompt → stdout 出 JSON。

    实测数据(Sure 仓库,65 分区)

    执行路径 每分区消耗 每分区时延 并行度
    现状:会话内子代理执行工单 120–170 万 token 5–10 分钟 受会话并发限制(~3)
    同一工单 HTTP 直调一发 41.4k token 19 秒 N 进程全并行

    (token 差 ~30 倍:agent 路径 90% 消耗在把工单分段 Read 进上下文的工具循环里。直调路径产出的结果通过了同一套证据校验:47 条 evidence 路径全部合法、字段名契约完全符合。)

    对提案的补充诉求

    1. 除 --output-format json 外,希望文档化多开并发的限流行为(并发 N 个 zcode exec 进程时的队列/退避语义)——skill 需要按此校准并行度;
    2. zcode exec + skill 协议组合后,ZCode 用户可以获得与 claude -p / codex exec 同级的自动化能力,这一档(订阅账号、无裸 API key 的 headless 子命令)正是当前市面主流宿主的标配形态。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: P1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions