@delta-infra/cli 1.0.89 → 1.0.90

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/README.md CHANGED
@@ -141,9 +141,9 @@ delta-cli config init \
141
141
  --base-url http://your-server/api/v1 \
142
142
  --token your-token
143
143
 
144
- # 通过环境变量
144
+ # 通过环境变量(API Key 或 Token 二选一)
145
145
  export DELTA_INFRA_BASE_URL=http://your-server/api/v1
146
- export DELTA_INFRA_TOKEN=your-token
146
+ export DELTA_INFRA_API_KEY=your-api-key # 或 DELTA_INFRA_TOKEN
147
147
  delta-cli config init
148
148
  ```
149
149
 
@@ -151,16 +151,26 @@ delta-cli config init
151
151
 
152
152
  ### 2. 认证
153
153
 
154
- 使用 Bearer Token:
154
+ 支持 **API Key** 与 **Bearer Token** 两种凭据(API Key 优先)。
155
+
156
+ **获取 API Key**:登录 Delta Infra **Web 控制台**,在 **API Keys** 页面生成一个 Key。
155
157
 
156
158
  ```bash
159
+ # API Key(推荐)
160
+ delta-cli auth login --apikey <your-api-key>
161
+
157
162
  # Token
158
163
  delta-cli auth login --token <your-token>
159
164
 
165
+ # 交互式登录(可直接粘贴 Key/Token,CLI 会自动识别格式)
166
+ delta-cli auth login
167
+
160
168
  # 查看认证状态
161
169
  delta-cli auth status
162
170
  ```
163
171
 
172
+ 也可以通过环境变量指定:`DELTA_INFRA_API_KEY=<key>` / `DELTA_INFRA_TOKEN=<token>`。
173
+
164
174
  ### 3. Sandbox 生命周期
165
175
 
166
176
  ```bash
@@ -201,7 +211,8 @@ delta-cli sandbox kill <sandbox_id>
201
211
  | `delta-cli config init` | 初始化配置文件 |
202
212
  | `delta-cli config show` | 查看当前配置(敏感字段已脱敏) |
203
213
  | `delta-cli config set <key> <value>` | 修改配置项 |
204
- | `delta-cli auth login` | 交互式登录 |
214
+ | `delta-cli auth login` | 交互式登录(自动识别 API Key / Token) |
215
+ | `delta-cli auth login --apikey <key>` | API Key 认证(推荐) |
205
216
  | `delta-cli auth login --token <token>` | Token 认证 |
206
217
  | `delta-cli auth status` | 查看认证状态 |
207
218
  | `delta-cli upgrade` | 升级 CLI 和 AI Skills 到最新版本 |
package/checksums.txt CHANGED
@@ -1,5 +1,5 @@
1
- 7d508465cf9cd3e646b5c6b40f7455e87d19d50220549ba99fc2cba8446e4620 delta-cli-darwin-amd64.tar.gz
2
- c37f4cd4dff81a202a2f9902ba44385a4f5d8117270ea07d2fa929c9a42fbbfb delta-cli-darwin-arm64.tar.gz
3
- e8d891e90578a487e225621d682435b003fbfb681544f152dddd69eb76fcc95d delta-cli-linux-amd64.tar.gz
4
- debd0241feb4a02c2a46054767f826a35d7abcd22f804bc134ec2df0ab5b85cd delta-cli-linux-arm64.tar.gz
5
- c5274e69364a89293062b886e7cfb41934259c442180531d76c66855de18d16f delta-cli-windows-amd64.zip
1
+ 79a7cf6a8f997f1aa1fa66c4d3a2f8a342d5e709684dab4be487dfa4f0bf8e97 delta-cli-darwin-amd64.tar.gz
2
+ 9883f3b2441349160389e32d32ef6a4c7b627f6277962da2cede032126530520 delta-cli-darwin-arm64.tar.gz
3
+ cb0945d795f00e4ddb33bcb7cd0ea55ca847b1a7dd9698f7d45d6e38ff9ee20c delta-cli-linux-amd64.tar.gz
4
+ 1bcc9be8107bd1785296cdb3060292576d6b5529de812445363b15347ef04aee delta-cli-linux-arm64.tar.gz
5
+ b0b68d07995291b55a781c2ef30c333e67d838ad9b4fd7fe49c2fbab8ddac6cd 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.89",
3
+ "version": "1.0.90",
4
4
  "description": "Delta Infra CLI for sandbox compute and science tools.",
5
5
  "bin": {
6
6
  "delta-cli": "scripts/run.js"
@@ -15,6 +15,7 @@ const CONFIG_DIR = path.join(osHomedir(), ".delta-infra");
15
15
  const CONFIG_VERSION = 1;
16
16
  const DEFAULT_BASE_URL = "https://delta-infra-nacos-test.yangtzeailab.com/sandbox/api/v1";
17
17
  const DEFAULT_SCIENCE_BASE_URL = "http://8.141.101.94:8080/science_tool";
18
+ const DASHBOARD_API_KEYS_URL = "https://delta-infra-dashboard-test.yangtzeailab.com/dashboard/api-keys";
18
19
  const isWindows = process.platform === "win32";
19
20
 
20
21
  const PLATFORM_PATHS = {
@@ -137,12 +138,14 @@ const messages = {
137
138
  step3Fail: "配置初始化失败。运行以下命令重试: delta-cli config init",
138
139
  step4: "身份认证",
139
140
  step4Confirm: "是否进行身份认证?",
141
+ step4GuideTitle:"还未配置 API Key",
142
+ step4Guide: "请先在网页端生成一个 API Key:\n %s\n打开后复制生成的 Key,粘贴到下方提示处。",
140
143
  step4Skip: "跳过身份认证。后续运行 delta-cli auth login 完成",
141
144
  step4Done: "认证完成",
142
145
  step4Fail: "认证失败。运行以下命令重试: delta-cli auth login",
143
146
  done: "安装完成!\n现在可以让你的 AI 工具使用 delta-cli 管理 Delta Sandbox 资源或调用 Science 工具。",
144
147
  cancelled: "安装已取消",
145
- nonTtyHint: "要完成配置,请在终端中运行:\n delta-cli config init\n delta-cli auth login",
148
+ nonTtyHint: "要完成配置,请在终端中运行:\n delta-cli config init\n delta-cli auth login\n若还没有 API Key,请先在网页端生成:\n " + "https://delta-infra-dashboard-test.yangtzeailab.com/dashboard/api-keys",
146
149
  uninstallConfirm: "将移除全局包、AI Skills 和配置文件。是否继续?",
147
150
  uninstallCancelled: "卸载已取消",
148
151
  uninstallDone: "卸载完成",
@@ -171,12 +174,14 @@ const messages = {
171
174
  step3Fail: "Failed to init config. Run manually: delta-cli config init",
172
175
  step4: "Authorization",
173
176
  step4Confirm: "Would you like to authenticate now?",
177
+ step4GuideTitle:"No API key configured yet",
178
+ step4Guide: "Please generate an API key on the web dashboard first:\n %s\nCopy the key and paste it when prompted.",
174
179
  step4Skip: "Skipped. Run delta-cli auth login to authorize later",
175
180
  step4Done: "Authorization complete",
176
181
  step4Fail: "Failed to authorize. Run delta-cli auth login to retry",
177
182
  done: "You are all set!\nYour AI tool can now use delta-cli to manage Delta Sandbox resources or invoke Science tools.",
178
183
  cancelled: "Installation cancelled",
179
- nonTtyHint: "To complete setup, run interactively:\n delta-cli config init\n delta-cli auth login",
184
+ nonTtyHint: "To complete setup, run interactively:\n delta-cli config init\n delta-cli auth login\nIf you don't have an API key yet, generate one first:\n " + "https://delta-infra-dashboard-test.yangtzeailab.com/dashboard/api-keys",
180
185
  uninstallConfirm: "This will remove the global package, AI Skills and config. Continue?",
181
186
  uninstallCancelled: "Uninstall cancelled",
182
187
  uninstallDone: "Uninstall complete",
@@ -561,6 +566,11 @@ async function stepAuthLogin(msg) {
561
566
  }
562
567
 
563
568
  p.log.step(msg.step4);
569
+ const existingConfig = getExistingConfig();
570
+ if (!existingConfig || (!existingConfig.token && !existingConfig.apikey)) {
571
+ p.log.warn(msg.step4GuideTitle);
572
+ p.log.info(fmt(msg.step4Guide, DASHBOARD_API_KEYS_URL));
573
+ }
564
574
  try {
565
575
  run(deltaCli, ["auth", "login"]);
566
576
  p.log.success(msg.step4Done);
@@ -47,10 +47,10 @@ metadata:
47
47
  ```bash
48
48
  delta-cli sandbox run-bg <id> --command "<命令>" --timeout <秒> --wait
49
49
  ```
50
- CLI 通过 SSE 实时流(`/logs/stream`)跟随输出,把原始 SSE 帧(`data: {...}`)**逐帧透传到 stdout**(curl -N 风格),帧类型见 JSON 的 `type` 字段:`init`(含 `execution_id`)/ `stdout` / `stderr` / `error` / `complete`。收到 `complete` 即命令结束。**CLI 会在 complete 帧里补全字段**:服务端给 `exit_code`/`execution_id`/`error`,CLI 注入流内累计的 `stdout`/`stderr`、兜底恢复的 `log_file`、以及检测到的末尾 JSON `result_summary`(stdout 末尾 50 行内有合法 JSON 对象时)。命令成败看 `complete` 帧里的 `exit_code`;**命令非零退出或报错时,CLI 追加一个 `error.type: command_failed` 信封并以非零码退出(进程退出码 8)**,信封 `message` 已附 stderr 尾部,便于 `&&` 链与按 `error.type` 分支、快速扫读失败原因;`type:"error"` 帧的 `message` 也会 best-effort 附上已流出的 stderr 尾部;成功则不追加信封。若在 `--timeout`(默认 300s,同时充当服务端命令超时和客户端等待 deadline)内未收到 `complete`,CLI 会在已透传的帧后**追加一个 `finished=false` 的快照信封**(`CommandLogsResult`),表示命令仍运行。完整 stdout 在 `finished` 后被写入沙箱内的 `log_file`(默认 `/workspace/{user_id}/{sandbox_id}/{execution_id}/delta-result-{execution_id}.json`,以服务端返回的 `log_file` 字段为准),需要读全文时用 `sandbox read <id> --path <log_file>`(末尾 JSON 摘要已在 complete 帧里,通常无需再读)。**`--summary`/`--artifacts` 富化(含 hints)仅在旧服务器回退路径生效**(服务端无 `/logs/stream` 端点时 CLI 自动回退到 5s 轮询并输出 `CommandResult` 信封)。`execution_id` 可用于后续 `sandbox logs` / `cancel`。
50
+ CLI 通过 SSE 实时流(`/logs/stream`)跟随输出,把原始 SSE 帧(`data: {...}`)**逐帧透传到 stdout**(curl -N 风格),帧类型见 JSON 的 `type` 字段:`init`(含 `execution_id`)/ `stdout` / `stderr` / `error` / `complete`。收到 `complete` 即命令结束。**CLI 会在 complete 帧里补全字段**:服务端给 `exit_code`/`execution_id`/`error`,CLI 注入流内累计的 `stdout`/`stderr`、兜底恢复的 `log_file`、以及检测到的末尾 JSON `result_summary`(stdout 末尾 50 行内有合法 JSON 对象时)。命令成败看 `complete` 帧里的 `exit_code`;**命令非零退出或报错时,CLI 追加一个 `error.type: command_failed` 信封并以非零码退出(进程退出码 8)**,信封 `message` 已附 stderr 尾部,便于 `&&` 链与按 `error.type` 分支、快速扫读失败原因;`type:"error"` 帧的 `message` 也会 best-effort 附上已流出的 stderr 尾部;成功则不追加信封。若在 `--timeout`(默认 300s,同时充当服务端命令超时和客户端等待 deadline)内未收到 `complete`,CLI 会在已透传的帧后**追加一个 `finished=false` 的快照信封**(`CommandLogsResult`),表示命令仍运行。完整 stdout 在 `finished` 后被写入沙箱内的 `log_file`(默认 `/workspace/{user_id}/sandbox_logs/delta-result-{sandbox_id}-{execution_id}.json`,以服务端返回的 `log_file` 字段为准),需要读全文时用 `sandbox read <id> --path <log_file>`(末尾 JSON 摘要已在 complete 帧里,通常无需再读)。**`--summary`/`--artifacts` 富化(含 hints)仅在旧服务器回退路径生效**(服务端无 `/logs/stream` 端点时 CLI 自动回退到 5s 轮询并输出 `CommandResult` 信封)。`execution_id` 可用于后续 `sandbox logs` / `cancel`。
51
51
 
52
52
  **实时跟随 / 手动轮询(需要查看中间进度时)**:
53
- `sandbox logs <id> --execution-id <exec_id> --stream` 实时跟随(SSE):原始 `data:` 帧逐帧透传到 stdout,直到 `complete` 事件,无末尾信封。`sandbox logs <id> --execution-id <exec_id>`(不加 `--stream`)返回快照信封:
53
+ `sandbox logs <id> --execution-id <exec_id> --stream` 实时跟随(SSE):原始 `data:` 帧逐帧透传到 stdout,直到 `complete` 事件,无末尾信封(`--stream` 必须传 `--execution-id`)。`sandbox logs <id> --execution-id <exec_id>`(不加 `--stream`)返回快照信封;`--execution-id` 可省略——省略时仅按 sandbox 查询,服务端因 sandbox_id / execution_id 未同时传递而自动走 ES(Elasticsearch)查询:
54
54
  - `finished=true` + `exit_code=0` → 完成
55
55
  - `finished=true` + `exit_code!=0` → 失败
56
56
  - `running=true` → 仍运行
@@ -152,7 +152,7 @@ required_outputs:
152
152
  | **命令执行** | |
153
153
  | 同步运行命令(≤60s) | `sandbox run <id> --command "..." [--timeout <秒>] [--summary/--no-summary] [--artifacts]` |
154
154
  | 后台运行命令(>60s) | `sandbox run-bg <id> --command "..." [--timeout <秒>] [--wait] [--summary/--no-summary] [--artifacts]` |
155
- | 查看后台日志 | `sandbox logs <id> --execution-id <exec_id> [--tail N --grep <pattern> --context N] [--stream]` |
155
+ | 查看后台日志 | `sandbox logs <id> [--execution-id <exec_id>] [--tail N --grep <pattern> --context N] [--stream]`(`--execution-id` 可选;省略时按 sandbox 从 ES 查询,仅 `--stream` 必须传)|
156
156
  | 中断后台命令 | `sandbox cancel <id> --execution-id <exec_id>` |
157
157
  | **文件操作** | |
158
158
  | 读取文件 | `sandbox read <id> --path <path> [--output <本地路径> --tail N --grep <pattern> --offset N --limit N --context N --max-bytes N --parse-json]` |
@@ -192,14 +192,14 @@ required_outputs:
192
192
  - 支持嵌套目录,空目录也会被创建。
193
193
  - **写后验证(可选)**:`sandbox stat <id> --path <path>` 确认文件存在且 size 符合预期即可。**不要**用 `sandbox ls` + `sandbox read` 把刚写入的文件读回宿主再逐字对比;无异常时不需要读回。
194
194
  4. **运行命令**:
195
- - **短任务(预计 ≤ 60 秒)**:`delta-cli sandbox run <id> --command "<命令>" --timeout <秒>` 同步执行,命令的 stdout/stderr 通过 SSE **以原始 `data:` 帧逐帧透传到 stdout**(无末尾信封),`exit_code` / `log_file` / `execution_id` 从 `complete` 帧读取。完整 `stdout` 在完成后写入 run envelope 日志文件(`log_file` 字段),需要读全文或提取末尾 JSON 时用 `sandbox read`,**不要**再调用 `sandbox logs`。可通过 `--log-file <路径>` 自定义 run envelope 日志文件路径;默认值为 `/workspace/{user_id}/{sandbox_id}/{execution_id}/delta-result-{execution_id}.json`(以服务端返回的 `log_file` 字段为准)。脚本经 `sandbox write` 落盘后位于 working-directory,运行命令需用完整路径 `<working-directory>/<文件名>`(先 `sandbox working-directory <id>` 查询)。根据镜像中的运行时构造命令,常见示例(`<wd>` 为 working-directory):
195
+ - **短任务(预计 ≤ 60 秒)**:`delta-cli sandbox run <id> --command "<命令>" --timeout <秒>` 同步执行,命令的 stdout/stderr 通过 SSE **以原始 `data:` 帧逐帧透传到 stdout**(无末尾信封),`exit_code` / `log_file` / `execution_id` 从 `complete` 帧读取。完整 `stdout` 在完成后写入 run envelope 日志文件(`log_file` 字段),需要读全文或提取末尾 JSON 时用 `sandbox read`,**不要**再调用 `sandbox logs`。可通过 `--log-file <路径>` 自定义 run envelope 日志文件路径;默认值为 `/workspace/{user_id}/sandbox_logs/delta-result-{sandbox_id}-{execution_id}.json`(以服务端返回的 `log_file` 字段为准)。脚本经 `sandbox write` 落盘后位于 working-directory,运行命令需用完整路径 `<working-directory>/<文件名>`(先 `sandbox working-directory <id>` 查询)。根据镜像中的运行时构造命令,常见示例(`<wd>` 为 working-directory):
196
196
  - Python:`python <wd>/train.py`
197
197
  - Node.js:`node <wd>/app.js`
198
198
  - Go:`go run <wd>/main.go`
199
199
  - Shell:`bash <wd>/run.sh`
200
200
  - **长任务(预计 > 60 秒,如下载模型、训练、编译、大规模数据处理)**:`delta-cli sandbox run-bg <id> --command "<命令>" --timeout <秒> [--log-file <路径>]` 提交后台任务,获得 `execution_id` 后通过以下命令查询:
201
- - `delta-cli sandbox logs <id> --execution-id <execution_id> --stream` — SSE 实时跟随,原始 `data:` 帧逐帧透传到 stdout,直到 `complete` 事件(含 `exit_code`/`log_file`),无末尾信封。
202
- - `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`。
201
+ - `delta-cli sandbox logs <id> --execution-id <execution_id> --stream` — SSE 实时跟随,原始 `data:` 帧逐帧透传到 stdout,直到 `complete` 事件(含 `exit_code`/`log_file`),无末尾信封(`--stream` 必须传 `--execution-id`)。
202
+ - `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`。`--execution-id` 可省略:省略时仅按 sandbox 查询,服务端因 sandbox_id / execution_id 未同时传递而自动走 ES 查询。
203
203
  禁止对长任务使用同步 `sandbox run`
204
204
 
205
205
  **推荐实践**:让 sandbox 脚本在 `stdout` 末尾打印一个独立的结构化 JSON 对象(例如 `{"status":"ok", ...}`)。SSE 路径下 CLI 会检测该末尾 JSON 并直接在 `complete` 帧里带出 `result_summary`,**任务结束后直接复用 complete 帧的 `result_summary` 写入 result.json**,无需再 `sandbox read` log_file 反向扫描。仅当 complete 帧缺失 `result_summary`(末尾无合法 JSON)时,才用 `sandbox read <id> --path <log_file>` 读取并按步骤 5 反向扫描提取,避免让大模型“读整段日志再摘要”。
@@ -40,11 +40,12 @@ delta-cli sandbox run-bg <id> --command "<命令>" --timeout 7200
40
40
 
41
41
  # 2a. 实时跟随(SSE,推荐):
42
42
  delta-cli sandbox logs <id> --execution-id <exec_id> --stream
43
- # ↑ 原始 data: 帧逐帧透传到 stdout,直到 complete 事件,无末尾信封
43
+ # ↑ 原始 data: 帧逐帧透传到 stdout,直到 complete 事件,无末尾信封(--stream 必须传 --execution-id)
44
44
 
45
45
  # 2b. 手动轮询快照(可用 --tail N / --grep <pattern> 过滤大输出)
46
46
  delta-cli sandbox logs <id> --execution-id <exec_id>
47
47
  # ↑ 返回 {sandbox_id, execution_id, stderr_tail, stderr_size, cursor, running, finished, exit_code, log_file?}
48
+ # --execution-id 可省略:省略时仅按 sandbox 查询,服务端因 sandbox_id/execution_id 未同时传递而自动走 ES
48
49
 
49
50
  # 3. 完成后销毁
50
51
  delta-cli sandbox kill <id>
@@ -55,11 +56,11 @@ delta-cli sandbox kill <id>
55
56
  `sandbox logs` 返回的数据结构为:
56
57
 
57
58
  ```json
58
- {"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":"/workspace/{user_id}/{sandbox_id}/{execution_id}/delta-result-{execution_id}.json"}}
59
+ {"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":"/workspace/{user_id}/sandbox_logs/delta-result-{sandbox_id}-{execution_id}.json"}}
59
60
  ```
60
61
 
61
62
  字段说明:
62
- - `sandbox_id` / `execution_id` — 与请求一致
63
+ - `sandbox_id` / `execution_id` — 与请求一致;省略 `--execution-id` 时走 ES 按 sandbox 查询,该字段为空
63
64
  - `stdout_tail` — CLI 默认保留的 **最后 800 字节** stdout 片段,避免上下文爆炸
64
65
  - `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`
65
66
  - `stdout_size` — 原始 stdout 字节数(CLI 端计算)