@delta-infra/cli 1.0.59 → 1.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/checksums.txt CHANGED
@@ -1,5 +1,5 @@
1
- f517a9a699de046528ec0f044e09793a26acc2ec4b644d26bb8176327275445d delta-cli-darwin-amd64.tar.gz
2
- 5eaadcca6694e34d03be041e64201ce2646a44861ea11ad797b777131e9337c6 delta-cli-darwin-arm64.tar.gz
3
- 286c1a112868234964e2d34a79a46067077a88a55e6fb2cf072f5fd84b742f09 delta-cli-linux-amd64.tar.gz
4
- 7f2808fd84f1f8479290146f78ea4066eddc4bfbe801c2f70c33b672af90f67e delta-cli-linux-arm64.tar.gz
5
- c50411fe98ff2739a7f1ca2f571eef63956bc82f283cd23171c162d213897cf0 delta-cli-windows-amd64.zip
1
+ 3770b173894f9548536df67e995e346bdfd819ea784f6c517a758e95ddeab70d delta-cli-darwin-amd64.tar.gz
2
+ 5a5f78039dd015d719840cf10da059778f0bed8c934e64f5678b7c7157eb5715 delta-cli-darwin-arm64.tar.gz
3
+ 71ca0548c7eecac71683c969165f050aea10800a7994facb81241a88c80477b5 delta-cli-linux-amd64.tar.gz
4
+ 5f3b5920f6ddf23a4cbd60b2fd57b804def6f8e9c287ea418f8f299ceb1f41ba delta-cli-linux-arm64.tar.gz
5
+ 8769479c00c62fc560d96e75e762f5aa7431c570f7c866972dfcf829530c0dc2 delta-cli-windows-amd64.zip
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delta-infra/cli",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "description": "Delta Sandbox CLI",
5
5
  "bin": {
6
6
  "delta-cli": "scripts/run.js"
@@ -41,7 +41,7 @@ metadata:
41
41
  ```bash
42
42
  delta-cli sandbox run-bg <id> --command "<命令>" --timeout <秒> --wait
43
43
  ```
44
- CLI 在内部每 5 秒轮询一次 `logs`,直到 `finished=true` 或超时,然后一次性返回 `{execution_id, running, finished, exit_code, content}`。返回的 `execution_id` 可在后续用于 `sandbox logs` / `cancel`。适合只关心最终结果、不需要查看中间进度的场景。
44
+ CLI 在内部每 5 秒轮询一次 `logs`,直到 `finished=true` 或超时(`--timeout` 同时充当服务端命令超时和客户端轮询 deadline,默认 300s),然后一次性返回 `CommandResult` 信封:`{execution_id, sandbox_id, finished, exit_code, stderr_tail, stderr_size, log_file, result_summary, hints, error}`。**stdout 不直接暴露**——命令的 stdout 在 `finished=true` 时被写入沙箱内的 `log_file`,需要读全文时用 `sandbox read <id> --path <log_file>`;默认开启的 `--summary` 会自动 reverse-scan stdout 末尾 JSON 并填入 `data.result_summary`,常用场景无需手动读 `log_file`。返回的 `execution_id` 可在后续用于 `sandbox logs` / `cancel`。适合只关心最终结果、不需要查看中间进度的场景。
45
45
 
46
46
  **手动轮询(需要查看中间进度时)**:
47
47
  如果不加 `--wait` 或需要查看实时输出,用 `sandbox logs <id> --execution-id <exec_id>` 手动轮询:
@@ -49,7 +49,7 @@ metadata:
49
49
  - `finished=true` + `exit_code!=0` → 失败
50
50
  - `running=true` → 仍运行
51
51
 
52
- **故障诊断**:连续 3 次 `running=true` 且 `content`/`cursor` 无变化且距离提交超过 60 秒 → 用 `sandbox status <id>` 检查 sandbox 是否存活。
52
+ **故障诊断**:连续 3 次 `running=true` 且 `stderr_tail`/`cursor` 无变化且距离提交超过 60 秒 → 用 `sandbox status <id>` 检查 sandbox 是否存活。注意:`cursor` 字段无 `omitempty`,永远会出现在响应中(即使为 0);`stderr_tail` 默认只保留 **最后 200 字节** stderr 片段(CLI 硬编码 `tailString(s, 200)`,按字节截取;ASCII 文本等同于 200 字符,多字节 UTF-8 可能被截断),`cursor=0` 通常意味着服务端从 provider 还没读到任何 stderr 行。
53
53
 
54
54
  - 后台任务成功后仍需按规则 2/3 销毁 sandbox。
55
55
 
@@ -27,7 +27,7 @@
27
27
  |------|------|
28
28
  | `sandbox run <id> --command "..." [--timeout N] [--summary/--no-summary] [--artifacts]` | 同步运行命令;默认 `--summary` 开启,返回 JSON 中 `summary` 字段已含 stdout 末尾 JSON 提取结果;`--artifacts` 附带 workspace 产物清单 |
29
29
  | `sandbox run-bg <id> --command "..." [--timeout N] [--wait] [--summary/--no-summary] [--artifacts]` | 后台运行命令;不加 `--wait` 立即返回 `{execution_id, sandbox_id}`;加 `--wait` 等待完成返回含 `summary` 的完整结果 |
30
- | `sandbox logs <id> --execution-id <eid> [--tail N --grep <pattern> --context N --max-bytes N]` | 获取后台命令日志;默认返回 `stderr_size + stderr_tail`(避免上下文爆炸);可用 `--tail/--grep` 过滤 |
30
+ | `sandbox logs <id> --execution-id <eid> [--tail N --grep <pattern> --context N --max-bytes N]` | 获取后台命令日志;**默认返回 `stderr_tail`(CLI 硬编码 `tailString(s, 200)` 截取最后 200 字节,ASCII 等同 200 字符)+ `stderr_size` + `cursor`**,避免上下文爆炸;可用 `--tail/--grep` 过滤;**`cursor` 字段无 `omitempty`,0 也常驻响应**;**stdout 不通过此接口暴露**,需在 `finished=true` 后读 `log_file`。 |
31
31
  | `sandbox cancel <id> --execution-id <eid>` | 中断正在运行的后台命令 |
32
32
 
33
33
  ## 文件操作
@@ -29,6 +29,8 @@ CLI 内部每 5 秒轮询一次,`finished=true` 时返回,结果中包含 `e
29
29
 
30
30
  > `--wait` 默认带 `--summary`,返回的 JSON `data.result_summary` 字段已包含 stdout 末尾结构化 JSON 的提取结果。常用场景无需再调 `sandbox read` 二次解析 log_file。
31
31
 
32
+ > ⚠️ **返回类型不对称**:`finished=true` 时返回 `CommandResult` 信封(含 `execution_id, sandbox_id, finished, exit_code, stderr_tail, stderr_size, log_file, result_summary, hints, error`);若轮询 deadline 到了仍未 `finished=true`(即 `--timeout` 超时),CLI 会返回 `CommandLogsResult` 信封(**字段集合不同**:含 `cursor, running, finished, exit_code, stderr_tail, stderr_size, log_file?` 但**没有 `result_summary` / `hints` / `sandbox_id`**)。调用方解析 `run-bg --wait` 返回时应兼容两种 schema。从 `execution_id` 是否存在可粗略区分,更准确的信号是 `result_summary` 字段是否存在。
33
+
32
34
  ### 方式二:手动轮询(需要看实时输出时)
33
35
 
34
36
  ```bash
@@ -38,7 +40,7 @@ delta-cli sandbox run-bg <id> --command "<命令>" --timeout 7200
38
40
 
39
41
  # 2. 手动轮询进度(可用 --tail N / --grep <pattern> 过滤大输出)
40
42
  delta-cli sandbox logs <id> --execution-id <exec_id>
41
- # ↑ 返回 {content, cursor, running, finished, exit_code}
43
+ # ↑ 返回 {sandbox_id, execution_id, stderr_tail, stderr_size, cursor, running, finished, exit_code, log_file?}
42
44
 
43
45
  # 3. 完成后销毁
44
46
  delta-cli sandbox kill <id>
@@ -49,25 +51,42 @@ delta-cli sandbox kill <id>
49
51
  `sandbox logs` 返回的数据结构为:
50
52
 
51
53
  ```json
52
- {"ok":true,"data":{"content":"...","cursor":5,"running":false,"finished":true,"exit_code":0}}
54
+ {"ok":true,"data":{"sandbox_id":"...","execution_id":"...","stderr_tail":"...","stderr_size":1234,"cursor":5,"running":false,"finished":true,"exit_code":0,"log_file":"/tmp/delta-result-...json"}}
53
55
  ```
54
56
 
55
57
  字段说明:
56
- - `content` — 命令的标准输出
57
- - `cursor` — 输出行数计数器
58
+ - `sandbox_id` / `execution_id` — 与请求一致
59
+ - `stderr_tail` — CLI 默认保留的 **最后 200 字节** stderr 片段(CLI 硬编码 `tailString(s, 200)` 按字节截取;ASCII 等同 200 字符,多字节 UTF-8 可能被截断),避免上下文爆炸。不传任何 range flag 时,CLI 会把原始 `stderr` 字段清空,只暴露 `stderr_tail` 和 `stderr_size`
60
+ - `stderr_size` — 原始 stderr 字节数(CLI 端计算)
61
+ - `cursor` — 服务端 stderr 行计数器;**该字段无 `omitempty`,永远出现在响应中**(即使为 0 也露)。`cursor=0` 通常意味着服务端从 provider 还没读到任何 stderr 行
58
62
  - `running` — 命令是否仍在运行
59
63
  - `finished` — 命令是否已完成(`finished = not running`)
60
- - `exit_code` — 退出码(完成后才有值,运行中为 null)
64
+ - `exit_code` — 退出码(完成后才有值,运行中字段省略)
65
+ - `log_file` — 仅 `finished=true` 时出现,是 run envelope 日志文件路径(含完整 stdout + stderr + exit_code + finished + command + error),需读它用 `delta-cli sandbox read <id> --path <log_file>`
66
+
67
+ **stdout 路径说明**:`sandbox logs` **永远不直接返回 stdout**——stdout 在命令结束时被写入沙箱内的 `log_file`,必须用 `sandbox read` 读。CLI `run-bg --wait` 完成后默认开启 `--summary`,会自动 reverse-scan stdout 末尾 JSON 填入 `data.result_summary`,常用场景无需手动读 `log_file`。
68
+
69
+ 要用 `--tail/--grep/--context/--max-bytes` 自定义切片:传任意一个 flag 时,CLI 会把过滤后的 stderr 写回 `stderr` 字段并更新 `stderr_size`;不传则保持 `stderr=""` + `stderr_tail` 末尾 200 字节预览。
70
+
71
+ ```bash
72
+ # 看最后 50 行 stderr
73
+ delta-cli sandbox logs <id> --execution-id <eid> --tail 50
74
+ # 过滤 ERROR/warning 行
75
+ delta-cli sandbox logs <id> --execution-id <eid> --grep "ERROR|warning" --context 2
76
+ # 兜底限流 32KB
77
+ delta-cli sandbox logs <id> --execution-id <eid> --max-bytes 32768
78
+ ```
61
79
 
62
80
  判断任务状态的规则(按优先顺序):
63
81
 
64
82
  1. **`finished=true` + `exit_code=0`** → 正常完成,可以读取结果并销毁 sandbox
65
83
  2. **`finished=true` + `exit_code≠0`** → 命令执行失败,查看 stderr/error 信息
66
84
  3. **`running=true`** → 任务仍在运行,继续等待(建议每 15-30 秒查询一次)
67
- 4. **连续 3 次 `running=true` 且 `content`/`cursor` 无变化且距离提交超过 60 秒** → 任务可能挂起或无输出,用 `sandbox status <id>` 检查 sandbox 是否存活
85
+ 4. **连续 3 次 `running=true` 且 `stderr_tail`/`cursor` 无变化且距离提交超过 60 秒** → 任务可能挂起或无输出,用 `sandbox status <id>` 检查 sandbox 是否存活
68
86
  5. **`sandbox status` 返回正常但 logs 仍然无变化** → 用 `sandbox run <id> --command "ps aux | grep <进程名>" --timeout 15` 在容器内检查命令是否还在运行
69
87
 
70
88
  **注意**:
71
89
  - `sandbox logs` 只应配合 `sandbox run-bg` 使用;同步 `sandbox run` 的结果直接返回,不能也不应该调用 `logs`。
72
- - `sandbox run-bg` 的 `--timeout` 传给服务端作为命令超时,HTTP 请求本身会快速返回;命令若超时会以非零退出码结束。
90
+ - `sandbox run-bg` 不加 `--wait` 时,HTTP 请求本身会快速返回 `{execution_id, sandbox_id}`;命令若超时会以非零退出码结束,需后续通过 `logs` 拿 `exit_code`。
91
+ - `sandbox run-bg --wait` 模式下,`--timeout` **同时**充当服务端命令执行超时和客户端轮询 deadline(默认 300s);轮询间隔固定 5 秒;初始 `/run-background` POST 有独立的 60s HTTP timeout。
73
92
  - 后台命令可跨 tool call 轮次查询:保存 `sandbox_id` 和 `execution_id`,后续轮次通过 `sandbox status` / `sandbox logs` 获取结果。