7.1 KiB
v0.1 AgentRun CLI 规格
AgentRun CLI 是 v0.1 的受控人工操作和验收入口。它必须遵循 UniDesk cli-spec 原则:默认 JSON 输出、禁止空输出伪成功、禁止长阻塞、日志可见、配置显式校验,并优先通过 agentrun-mgr RESTful API 完成跨服务操作。
在系统中的职责划分
- 创建 run、查询 run、提交 command、查询 command、分页读取 events。
- 手动启动 runner,本地 process 或 Kubernetes Job 均必须快速返回 job/process identity 和 logPath。
- 查询 backend capability 和 manager health。
- 为综合联调提供 CLI 交互面;不得替代 RESTful API 合同测试。
- 不直连 Postgres,不读取 provider Secret 值,不把 debug/mock 路径伪装成正式验收。
CLI 入口
v0.1 固定规划入口:
scripts/agentrun-cli.ts
scripts/src/*.ts
CLI 官方 TypeScript 入口固定为 scripts/agentrun-cli.ts。在 G14 非交互 SSH route、CI task 和人工验收命令中,推荐使用仓库内 launcher:
./scripts/agentrun ...
该 launcher 只负责定位 bun(优先 BUN_BIN、其次 PATH、$HOME/.bun/bin/bun 和 G14 默认 /root/.bun/bin/bun),然后转入同一个 scripts/agentrun-cli.ts。它不实现第二套路由、不读取额外配置、不绕过 TypeScript CLI。bun scripts/agentrun-cli.ts ... 仍可在 PATH 已包含 Bun 的交互 shell 中使用;node、tsx 或其他 wrapper 只能作为本地开发辅助,不能成为 v0.1 综合联调的权威入口。
入口文件只负责参数解析和路由,具体实现拆到 scripts/src/。CLI 命令默认输出 JSON;任何命令无 stdout 都是失败。单次 CLI 调用必须在 60 秒内返回,长时间模型 turn 通过 status/events 后续命令观察。
初始命令族
./scripts/agentrun runs create --json-file <run.json>
./scripts/agentrun runs show <runId>
./scripts/agentrun runs events <runId> --after-seq <n> --limit <n>
./scripts/agentrun commands create <runId> --type turn --json-file <payload.json>
./scripts/agentrun commands show <commandId> --run-id <runId>
./scripts/agentrun runner start --run-id <runId> --backend <backendProfile>
./scripts/agentrun runner job --run-id <runId> --command-id <commandId>
./scripts/agentrun runner job --dry-run --run-id <runId> --command-id <commandId> --image <image>
./scripts/agentrun secrets codex render --dry-run [--profile codex|deepseek] [--codex-home <dir>]
./scripts/agentrun backends list
./scripts/agentrun server start|status
具体参数可以在实现时按代码结构微调,但行为必须保持:
- 创建类命令返回
runId、commandId、status 和下一步 poll command。 runner start返回 attemptId、job/process identity、logPath 和后续 status/events 命令。- 查询类命令返回当前 state、terminal_status、failureKind、event cursor 或 logPath。
events默认分页且有界,必须支持afterSeq和limit。server logs返回有界日志摘要,并指向完整日志文件或 Kubernetes pod identity。secrets codex render --dry-run返回 Codex stdio profile Secret 创建计划、输入文件 bytes/hash、SecretRef、manifest 摘要和 apply 命令形状;--profile codex默认 Secret name 为agentrun-v01-provider-codex,--profile deepseek默认 Secret name 为agentrun-v01-provider-deepseek;它不得输出 Secret value 或执行 Kubernetes 写操作。backends list必须显示codex与deepseekprofile 的 backendKind、protocol、transport、command、requiredSecretKeys 和状态;不得因为deepseek尚未配置 Secret 就隐藏 capability。
配置与 Secret 边界
- CLI 配置必须显式校验;部署关键值不得静默 fallback。
- CLI 调用 manager REST API;不得直接连 Postgres 或读 Kubernetes Secret value。
- CLI 可以显示 SecretRef 名称、key、credential source 和 readiness,但不得显示 Secret value、Codex
auth.json、Codexconfig.toml、DSN password、token 或 URL credential。 - Debug 子命令可以用于开发,但综合联调和测试规格不得用 debug 子命令作为通过证据。
测试规格
T1 CLI run 生命周期
阅读 AGENTS.md、本文和 spec-v01-validation.md,然后用 ./scripts/agentrun 创建 run、提交 turn command、启动 runner、轮询 command 和 events 直到 terminal_status。确认每个命令输出非空 JSON,60 秒内返回,并给出下一步可执行命令或 logPath。若直接执行 bun scripts/agentrun-cli.ts,必须先证明当前 shell 的 PATH 能找到 Bun;G14 route 默认以 ./scripts/agentrun 为准。
T2 CLI 错误可见性
阅读本文,然后用非法 backendProfile、缺失 SecretRef 和无效 runId 分别调用正式 CLI。确认每次失败都有 JSON 输出、failureKind、message、trace correlation 和 logPath 或诊断入口;不得空输出或只输出布尔值。
T3 CLI 日志可见性
阅读本文,然后启动一个会失败的 runner,并通过 CLI 返回的 logPath 或 pod identity 读取实际日志。确认日志包含足够定位失败原因的信息、异常 trace 或错误分类,同时没有 Secret value。
T4 CLI 与 RESTful 一致性
阅读本文和 spec-v01-agentrun-mgr.md,然后对同一个 run 分别使用 CLI 和 RESTful API 查询 run、command、events 和 terminal_status。确认 CLI 不维护独立状态,两种交互面观察结果一致。
T5 Backend profile CLI 切换
阅读本文、spec-v01-backend-codex.md 和 spec-v01-validation.md,然后用正式 CLI 分别创建 backendProfile=codex 与 backendProfile=deepseek 的 run,按 codex -> deepseek -> codex 顺序执行真实 runner。确认 CLI 输出非空 JSON,backend_status 显示正确 profile/backendKind/protocol,缺失 deepseek SecretRef 时返回 secret-unavailable,不会 fallback 到 codex。
规格的实现情况
| 规格项 | 状态 | 说明 |
|---|---|---|
| AgentRun CLI 规格 | 已定义 | 本文为 v0.1 CLI 权威。 |
scripts/agentrun-cli.ts |
已实现 | 已提供 run/command/event/backend/server 基础命令和 JSON envelope;scripts/agentrun 是同一入口的 Bun 定位 launcher。 |
| CLI 调 manager REST | 已实现 | CLI 通过 ManagerClient 调 manager REST;自测试可用内存 manager,综合联调必须指向真实 agentrun-v01 manager。 |
| runner start/job | 已实现 | runner start 可执行 host process runner;runner job --dry-run 可渲染 Kubernetes Job JSON;runner job 正式路径通过 manager REST 创建 Kubernetes Job 并快速返回 job identity、SecretRef、retention 和轮询命令。 |
| CLI 测试规格 | 已定义/已验证主闭环 | 综合联调见 spec-v01-validation.md;每次发布仍按手动交互验收复跑。 |
deepseek profile CLI |
已实现/已通过主闭环 | secrets codex render --profile deepseek、backends list、runner start --backend、runner job 和 JSON 错误可见性已实现;真实 CLI/RESTful 联调已通过 codex -> deepseek -> codex 切换主闭环。 |