@delta-infra/cli 1.0.60 → 1.0.62

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
- 6e1755be96023a2743f835392ae64d5125f0fa320b97379fadf853d9ac719cc2 delta-cli-darwin-amd64.tar.gz
2
- 900e441253711cf1e924399abf0b7da65aa188e4c1972c41670eba91dcb7cb8d delta-cli-darwin-arm64.tar.gz
3
- 159a24364c0f89b89107f7c6b5ec8c3d71c7b742dd3d212c38da75ee6c41159c delta-cli-linux-amd64.tar.gz
4
- cedba82d3ff425eed52829f912ceccb6b7ade27611d452eff7d430ee9e884a4c delta-cli-linux-arm64.tar.gz
5
- 1c5d4d2a76de78356d11b150b3ddc3a67c22a0deb5f5cb8dd338f107beb7cef9 delta-cli-windows-amd64.zip
1
+ ee97f4fbd2e96e637186b16a2fe07e7f5efcee6e7d80b2f37be33169cd614ca8 delta-cli-darwin-amd64.tar.gz
2
+ cd5b445908a986529fc6eeb0c26552858ee9b0faed7eee863086033e027d44f7 delta-cli-darwin-arm64.tar.gz
3
+ e2cef122d91f28b14f24c1cb505033314a874bfabb2baf3942bad9a65c112ab0 delta-cli-linux-amd64.tar.gz
4
+ a63071b004394a3a5e2ed8c94da089655a334065d0e9507ecd4fc1e108130056 delta-cli-linux-arm64.tar.gz
5
+ 5f9fc12e6af6ace5071ede349b526c1ce2b2e736355fe194262cc35977a43165 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.60",
3
+ "version": "1.0.62",
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`/`stdout_tail`/`cursor` 无变化且距离提交超过 60 秒 → 用 `sandbox status <id>` 检查 sandbox 是否存活。注意:`cursor` 字段无 `omitempty`,永远会出现在响应中(即使为 0);`stderr_tail` 默认只保留 **最后 200 字节** stderr 片段,`stdout_tail` 默认保留 **最后 800 字节** stdout 片段(CLI 硬编码 `tailString(s, n)`,按字节截取;ASCII 文本等同于 n 字符,多字节 UTF-8 可能被截断),`cursor=0` 通常意味着服务端从 provider 还没读到任何 stderr 行。
53
53
 
54
54
  - 后台任务成功后仍需按规则 2/3 销毁 sandbox。
55
55
 
@@ -142,7 +142,7 @@ required_outputs:
142
142
  | **命令执行** | |
143
143
  | 同步运行命令(≤60s) | `sandbox run <id> --command "..." [--timeout <秒>] [--summary/--no-summary] [--artifacts]` |
144
144
  | 后台运行命令(>60s) | `sandbox run-bg <id> --command "..." [--timeout <秒>] [--wait] [--summary/--no-summary] [--artifacts]` |
145
- | 查看后台日志 | `sandbox logs <id> --execution-id <exec_id> [--tail N --grep <pattern> --context N --max-bytes N]` |
145
+ | 查看后台日志 | `sandbox logs <id> --execution-id <exec_id> [--tail N --grep <pattern> --context N]` |
146
146
  | 中断后台命令 | `sandbox cancel <id> --execution-id <exec_id>` |
147
147
  | **文件操作** | |
148
148
  | 读取文件 | `sandbox read <id> --path <path> [--output <本地路径> --tail N --grep <pattern> --offset N --limit N --context N --max-bytes N --parse-json]` |
@@ -187,7 +187,7 @@ required_outputs:
187
187
  - Go:`go run /workspace/main.go`
188
188
  - Shell:`bash /workspace/run.sh`
189
189
  - **长任务(预计 > 60 秒,如下载模型、训练、编译、大规模数据处理)**:`delta-cli sandbox run-bg <id> --command "<命令>" --timeout <秒> [--log-file <路径>]` 提交后台任务,获得 `execution_id` 后通过以下命令轮询:
190
- - `delta-cli sandbox logs <id> --execution-id <execution_id>` — 返回 `cursor`、`running`、`finished`、`exit_code`、`log_file`(完成后)。当 `finished=true` 时认为完成,完整输出需读取 `log_file`。
190
+ - `delta-cli sandbox logs <id> --execution-id <execution_id>` — 返回 `stdout_tail`(末尾 800 字节)、`stderr_tail`(末尾 200 字节)、`stdout_size`、`stderr_size`、`cursor`、`running`、`finished`、`exit_code`、`log_file`(完成后)。当 `finished=true` 时认为完成,完整输出需读取 `log_file`。
191
191
  禁止对长任务使用同步 `sandbox run`
192
192
 
193
193
  **推荐实践**:让 sandbox 脚本在 `stdout` 末尾打印一个独立的结构化 JSON 对象(例如 `{"status":"ok", ...}`),CLI 的 `--summary` 默认会自动反向扫描 stdout 末尾 JSON 提取为 `data.result_summary` 字段。这样即使 `stdout` 前面是大量训练/下载日志,skill 也无需让大模型去“读整段日志再摘要”。
@@ -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]` | 获取后台命令日志;**默认返回 `stdout_tail`(末尾 800 字节)+ `stderr_tail`(末尾 200 字节)+ `stderr_size` + `cursor`**,总计约 1KB,避免上下文爆炸;`--tail N` 同时作用于 stdout 和 stderr(各取尾 N 行);`--grep <pattern>` 同时过滤 stdout 和 stderr(正则);`--context N` 提供 grep 匹配行前后 N 行上下文(同时用于 stdout 和 stderr);**`cursor` 字段无 `omitempty`,0 也常驻响应**。 |
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":"...","stdout_tail":"...","stderr_tail":"...","stdout_size":1234,"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
+ - `stdout_tail` — CLI 默认保留的 **最后 800 字节** stdout 片段,避免上下文爆炸
60
+ - `stderr_tail` — CLI 默认保留的 **最后 200 字节** stderr 片段(CLI 硬编码 `tailString(s, n)` 按字节截取;ASCII 等同 n 字符,多字节 UTF-8 可能被截断),避免上下文爆炸。不传任何 range flag 时,CLI 会把原始 `stdout`/`stderr` 字段清空,只暴露 `stdout_tail`/`stderr_tail` 和 `stdout_size`/`stderr_size`
61
+ - `stdout_size` — 原始 stdout 字节数(CLI 端计算)
62
+ - `stderr_size` — 原始 stderr 字节数(CLI 端计算)
63
+ - `cursor` — 服务端 stderr 行计数器;**该字段无 `omitempty`,永远出现在响应中**(即使为 0)。`cursor=0` 通常意味着服务端从 provider 还没读到任何 stderr 行
58
64
  - `running` — 命令是否仍在运行
59
65
  - `finished` — 命令是否已完成(`finished = not running`)
60
- - `exit_code` — 退出码(完成后才有值,运行中为 null)
66
+ - `exit_code` — 退出码(完成后才有值,运行中字段省略)
67
+ - `log_file` — 仅 `finished=true` 时出现,是 run envelope 日志文件路径(含完整 stdout + stderr + exit_code + finished + command + error),需读它用 `delta-cli sandbox read <id> --path <log_file>`
68
+
69
+ **stdout 路径说明**:`sandbox logs` 默认返回 stdout 末尾 800 字节(`stdout_tail`)提供实时中间进度预览,完整 stdout 仍在命令结束时被写入沙箱内的 `log_file`,需全文时用 `sandbox read` 读。CLI `run-bg --wait` 完成后默认开启 `--summary`,会自动 reverse-scan stdout 末尾 JSON 填入 `data.result_summary`,常用场景无需手动读 `log_file`。
70
+
71
+ 要用 `--tail/--grep/--context` 自定义切片:传任意一个 flag 时,CLI 会把过滤后的 stdout 和 stderr 分别写回 `stdout`/`stderr` 字段并更新 `stdout_size`/`stderr_size`;不传则保持 `stdout=""` + `stdout_tail` 末尾 800 字节预览 + `stderr=""` + `stderr_tail` 末尾 200 字节预览(总计约 1KB)。
72
+
73
+ ```bash
74
+ # 看最后 50 行 stdout 和 stderr
75
+ delta-cli sandbox logs <id> --execution-id <eid> --tail 50
76
+ # 过滤 ERROR/warning 行(同时作用于 stdout 和 stderr)
77
+ delta-cli sandbox logs <id> --execution-id <eid> --grep "ERROR|warning" --context 2
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` 获取结果。