@delta-infra/cli 1.0.83 → 1.0.84
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 +429 -429
- package/checksums.txt +5 -5
- package/package.json +1 -1
- package/scripts/install-wizard.js +625 -625
- package/scripts/install.js +417 -417
- package/scripts/run.js +65 -65
- package/skills/delta-sandbox/SKILL.md +356 -356
- package/skills/delta-sandbox/agents/openai.yaml +4 -4
- package/skills/delta-sandbox/references/commands.md +56 -56
- package/skills/delta-sandbox/references/lifecycle.md +92 -92
- package/skills/delta-sandbox/references/recipes.md +133 -133
- package/skills/delta-science/SKILL.md +140 -136
- package/skills/delta-science/agents/openai.yaml +4 -4
- package/skills/delta-science/references/antbo.md +100 -100
- package/skills/delta-science/references/cli-contract.md +53 -53
- package/skills/delta-science/references/delta-bo.md +89 -89
- package/skills/delta-science/references/gsasii.md +116 -116
- package/skills/delta-science/references/lammps.md +66 -66
- package/skills/delta-science/references/ldm-bo.md +129 -129
- package/skills/delta-science/references/ldm.md +73 -73
- package/skills/delta-science/references/pubchem.md +126 -126
- package/skills/delta-science/references/pymatgen.md +68 -68
- package/skills/delta-science/references/rdkit.md +138 -138
- package/skills/delta-science/references/routing-index.md +36 -36
- package/skills/delta-science/references/strbo.md +87 -87
- package/skills/delta-science/references/synbo.md +198 -198
- package/skills/delta-science/references/workflows.md +61 -61
- package/skills/delta-shared/SKILL.md +95 -95
- package/skills/delta-shared/agents/openai.yaml +4 -4
- package/skills/manifest.json +19 -19
package/README.md
CHANGED
|
@@ -1,429 +1,429 @@
|
|
|
1
|
-
# delta-cli
|
|
2
|
-
|
|
3
|
-
Delta Infra 的命令行工具,用于管理 Delta Sandbox GPU/CPU 计算任务和调用 Science 工具。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
### 方式一:npx 一键安装(推荐)
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npx @delta-infra/cli@latest install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
该命令会依次完成:
|
|
14
|
-
1. **全局安装** `@delta-infra/cli`(含 Go 二进制)
|
|
15
|
-
2. **选择 AI 工具平台**(可多选):通用 Agent 目录 `~/.agents/skills/`(Codex/Cursor/OpenCode)、Claude Code `~/.claude/skills/`、OpenCode 原生 `~/.config/opencode/skills/`、Cursor `~/.cursor/skills/`、Memento-S 开发模式 `~/memento_s/skills/`
|
|
16
|
-
3. **安装 AI Skills** 到所选平台的 skills 目录
|
|
17
|
-
4. **初始化配置** `delta-cli config init`(交互式,非 TTY 跳过)
|
|
18
|
-
5. **身份认证** `delta-cli auth login`(交互式,非 TTY 跳过)
|
|
19
|
-
|
|
20
|
-
AI Agent 也可以直接使用以下指令完成安装:
|
|
21
|
-
|
|
22
|
-
> 帮我安装 delta-cli:https://github.com/yzailab/delta-infra-cli
|
|
23
|
-
|
|
24
|
-
### 卸载
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npx @delta-infra/cli@latest uninstall
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
清理全局包、所有已知平台的 AI Skills 和配置文件。
|
|
31
|
-
|
|
32
|
-
### 升级
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# 升级 CLI + AI Skills
|
|
36
|
-
delta-cli upgrade
|
|
37
|
-
|
|
38
|
-
# 只检查是否有更新(不执行升级)
|
|
39
|
-
delta-cli upgrade --check
|
|
40
|
-
|
|
41
|
-
# 只升级 CLI 二进制
|
|
42
|
-
delta-cli upgrade --cli-only
|
|
43
|
-
|
|
44
|
-
# 只升级 AI Skills
|
|
45
|
-
delta-cli upgrade --skills-only
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
升级 CLI 时会通过 `npm install -g @delta-infra/cli@latest` 拉取最新版本;升级 Skills 时会通过 `npx skills add` 重新安装 AI Skills。
|
|
49
|
-
|
|
50
|
-
### 方式二:直接下载 Binary
|
|
51
|
-
|
|
52
|
-
从 [GitHub Releases](https://github.com/yzailab/delta-infra-cli/releases) 下载对应平台的压缩包(以下使用 `latest` 指向最新版):
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
# macOS (Apple Silicon)
|
|
56
|
-
curl -L -o delta-cli.tar.gz https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-darwin-arm64.tar.gz
|
|
57
|
-
tar -xzf delta-cli.tar.gz
|
|
58
|
-
sudo mv delta-cli-darwin-arm64 /usr/local/bin/delta-cli
|
|
59
|
-
rm delta-cli.tar.gz
|
|
60
|
-
|
|
61
|
-
# Linux (AMD64)
|
|
62
|
-
curl -L -o delta-cli.tar.gz https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-linux-amd64.tar.gz
|
|
63
|
-
tar -xzf delta-cli.tar.gz
|
|
64
|
-
chmod +x delta-cli-linux-amd64
|
|
65
|
-
sudo mv delta-cli-linux-amd64 /usr/local/bin/delta-cli
|
|
66
|
-
rm delta-cli.tar.gz
|
|
67
|
-
|
|
68
|
-
# Windows (AMD64,PowerShell)
|
|
69
|
-
Invoke-WebRequest -Uri https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-windows-amd64.zip -OutFile delta-cli.zip
|
|
70
|
-
Expand-Archive -Path delta-cli.zip -DestinationPath . -Force
|
|
71
|
-
Move-Item -Path delta-cli-windows-amd64.exe -Destination delta-cli.exe
|
|
72
|
-
Remove-Item -Path delta-cli.zip
|
|
73
|
-
# 将 delta-cli.exe 放到 PATH 中的目录
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 方式三:一键安装脚本(国内用户推荐)
|
|
77
|
-
|
|
78
|
-
安装脚本会自动尝试国内 npm 镜像(npmmirror),失败后再回退到 npm 官方源:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
# Linux / macOS
|
|
82
|
-
curl -L https://raw.githubusercontent.com/yzailab/delta-infra-cli/main/install.sh | bash
|
|
83
|
-
|
|
84
|
-
# Windows (PowerShell)
|
|
85
|
-
Invoke-RestMethod -Uri https://raw.githubusercontent.com/yzailab/delta-infra-cli/main/install.ps1 | Invoke-Expression
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### 方式四:npm
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
npm install -g @delta-infra/cli
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
`postinstall` 会按以下顺序尝试下载当前平台的二进制:
|
|
95
|
-
|
|
96
|
-
1. `DELTA_CLI_MIRROR` 环境变量(如果设置)
|
|
97
|
-
2. 国内加速镜像 `https://gh-proxy.com/https://github.com/...`
|
|
98
|
-
3. GitHub 源站 `https://github.com/yzailab/delta-infra-cli/releases/download/...`
|
|
99
|
-
|
|
100
|
-
如果安装时下载失败,可以:
|
|
101
|
-
|
|
102
|
-
- 直接运行一次 `delta-cli`,它会自动重新尝试下载。
|
|
103
|
-
- 或者在安装前设置本地压缩包路径:
|
|
104
|
-
|
|
105
|
-
```bash
|
|
106
|
-
DELTA_CLI_ARCHIVE=/path/to/delta-cli-linux-amd64.tar.gz npm install -g @delta-infra/cli
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
常用环境变量:
|
|
110
|
-
|
|
111
|
-
| 变量 | 说明 |
|
|
112
|
-
|------|------|
|
|
113
|
-
| `DELTA_CLI_MIRROR` | 下载镜像,例如 `https://gh-proxy.com/https://github.com`。只接受 HTTPS 且需在白名单内。 |
|
|
114
|
-
| `DELTA_CLI_MIRROR_ALLOWLIST` | 额外允许的主机列表,逗号分隔。 |
|
|
115
|
-
| `DELTA_CLI_ARCHIVE` | 指向预先下载好的 `.tar.gz` / `.zip` 本地路径,跳过网络下载。 |
|
|
116
|
-
| `DELTA_CLI_SKIP_POSTINSTALL` | 设置为 `1` 跳过安装时的二进制下载,之后由 `delta-cli` 运行时兜底。 |
|
|
117
|
-
| `DELTA_CLI_FATAL_ON_ERROR` | 安装失败时退出码非 0(默认警告,用于调试)。 |
|
|
118
|
-
| `DELTA_CLI_DOWNLOAD_TIMEOUT` | 单个下载源最大等待时间(毫秒,默认 120000)。 |
|
|
119
|
-
|
|
120
|
-
### 方式五:Go Install
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
go install github.com/delta-infra/delta-infra-cli/cmd/delta-cli@latest
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## 快速开始
|
|
127
|
-
|
|
128
|
-
### 1. 初始化配置
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
delta-cli config init
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
执行时会交互式提示输入服务端地址(默认:`https://delta-infra-nacos-test.yangtzeailab.com/sandbox/api/v1`)以及 Bearer Token(可选,也可后续用 `auth login` 配置)。
|
|
135
|
-
|
|
136
|
-
非交互式环境(如 CI)会直接使用默认值,也可以通过 flag 或环境变量一次性指定:
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
# 通过 flag
|
|
140
|
-
delta-cli config init \
|
|
141
|
-
--base-url http://your-server/api/v1 \
|
|
142
|
-
--token your-token
|
|
143
|
-
|
|
144
|
-
# 通过环境变量
|
|
145
|
-
export DELTA_INFRA_BASE_URL=http://your-server/api/v1
|
|
146
|
-
export DELTA_INFRA_TOKEN=your-token
|
|
147
|
-
delta-cli config init
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
配置文件保存在 `~/.delta-infra/config.json`(权限 0600)。
|
|
151
|
-
|
|
152
|
-
### 2. 认证
|
|
153
|
-
|
|
154
|
-
使用 Bearer Token:
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
# Token
|
|
158
|
-
delta-cli auth login --token <your-token>
|
|
159
|
-
|
|
160
|
-
# 查看认证状态
|
|
161
|
-
delta-cli auth status
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### 3. Sandbox 生命周期
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
# 创建带 GPU 的 sandbox(--max-life 默认 30 分钟,长任务请调高)
|
|
168
|
-
delta-cli sandbox create \
|
|
169
|
-
--image image.yangtzeailab.com/opensandbox/pytorch-cuda13:latest \
|
|
170
|
-
--cpu 4 --memory 16Gi --gpu 1 \
|
|
171
|
-
--max-life 120
|
|
172
|
-
|
|
173
|
-
# 运行命令(短任务同步执行,长任务用 run-bg 替代 run)
|
|
174
|
-
delta-cli sandbox run <sandbox_id> \
|
|
175
|
-
--command "<命令>" \
|
|
176
|
-
--timeout 3600
|
|
177
|
-
|
|
178
|
-
# v1.0.55+ 默认带 --summary,返回 JSON 中 data.result_summary 字段已含 stdout 末尾 JSON 提取结果
|
|
179
|
-
# 无需再手动读取 log_file 做二次解析(除非使用了 --no-summary)
|
|
180
|
-
delta-cli sandbox run <sandbox_id> --command "echo '{\"status\":\"ok\",\"result\":\"done\"}'" --timeout 60
|
|
181
|
-
|
|
182
|
-
# 读取结果文件
|
|
183
|
-
delta-cli sandbox read <sandbox_id> --path /workspace/result.json
|
|
184
|
-
|
|
185
|
-
# 销毁 sandbox
|
|
186
|
-
delta-cli sandbox kill <sandbox_id>
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## 命令列表
|
|
190
|
-
|
|
191
|
-
### 全局命令
|
|
192
|
-
|
|
193
|
-
| 命令 | 说明 |
|
|
194
|
-
|------|------|
|
|
195
|
-
| `delta-cli config init` | 初始化配置文件 |
|
|
196
|
-
| `delta-cli config show` | 查看当前配置(敏感字段已脱敏) |
|
|
197
|
-
| `delta-cli config set <key> <value>` | 修改配置项 |
|
|
198
|
-
| `delta-cli auth login` | 交互式登录 |
|
|
199
|
-
| `delta-cli auth login --token <token>` | Token 认证 |
|
|
200
|
-
| `delta-cli auth status` | 查看认证状态 |
|
|
201
|
-
| `delta-cli upgrade` | 升级 CLI 和 AI Skills 到最新版本 |
|
|
202
|
-
| `delta-cli upgrade --check` | 检查是否有可用更新 |
|
|
203
|
-
| `delta-cli upgrade --cli-only` | 只升级 CLI 二进制 |
|
|
204
|
-
| `delta-cli upgrade --skills-only` | 只升级 AI Skills |
|
|
205
|
-
| `delta-cli --version` | 显示版本 |
|
|
206
|
-
|
|
207
|
-
### Sandbox 命令
|
|
208
|
-
|
|
209
|
-
> **提示**:`sandbox list`(列沙箱实例)与 `sandbox ls <id>`(列目录)不同,注意区分。
|
|
210
|
-
|
|
211
|
-
| 命令 | 说明 |
|
|
212
|
-
|------|------|
|
|
213
|
-
| `delta-cli sandbox list` | 列出当前用户的 sandbox 实例 |
|
|
214
|
-
| `delta-cli sandbox providers` | 查看可用计算后端 |
|
|
215
|
-
| `delta-cli sandbox images` | 查看可用镜像列表 |
|
|
216
|
-
| `delta-cli sandbox recommend --cpu N --memory XGi` | 获取资源配置推荐 |
|
|
217
|
-
| `delta-cli sandbox create --image <img>` | 创建 sandbox 容器 |
|
|
218
|
-
| `delta-cli sandbox connect <id>` | 连接 sandbox |
|
|
219
|
-
| `delta-cli sandbox status <id>` | 查看 sandbox 状态 |
|
|
220
|
-
| `delta-cli sandbox finish <id>` | 保存结果并销毁 |
|
|
221
|
-
| `delta-cli sandbox kill <id>` | 销毁 sandbox |
|
|
222
|
-
| `delta-cli sandbox run <id> --command "..." [--timeout <秒>] [--summary/--no-summary] [--artifacts]` | 同步运行命令;默认带 `--summary`,返回 JSON 中 `summary` 字段已含 stdout 末尾 JSON 提取结果;`--artifacts` 附带 workspace 产物清单 |
|
|
223
|
-
| `delta-cli sandbox run-bg <id> --command "..." [--timeout <秒>] [--wait] [--summary/--no-summary] [--artifacts]` | 后台运行命令;不加 `--wait` 立即返回 `{execution_id, sandbox_id}`;加 `--wait` 等待完成返回含 `summary` 的完整结果 |
|
|
224
|
-
| `delta-cli sandbox logs <id> --execution-id <eid> [--tail N --grep <pattern> --context N --max-bytes N]` | 查看后台日志;默认返回 `stderr_size + stderr_tail`(避免上下文爆炸);可用 `--tail/--grep` 过滤 |
|
|
225
|
-
| `delta-cli sandbox cancel <id> --execution-id <eid>` | 中断后台命令 |
|
|
226
|
-
| `delta-cli sandbox read <id> --path <path> [--output <本地路径>] [--tail N] [--grep <pattern>] [--offset N] [--limit N] [--context N] [--max-bytes N] [--parse-json]` | 读取容器内文件;`--output <path>` 保存到本地;`--tail/--grep` 过滤;非 UTF-8 文件 CLI 自动走 base64 fallback |
|
|
227
|
-
| `delta-cli sandbox pull <id> --source <沙箱路径> --target <本地路径> [--recursive] [--pattern <glob>]` | 从沙箱拉取文件/目录到本地(mirror of `upload`,flag 方向相反:source=远程,target=本地);单文件或递归目录;CLI 端 + 服务端双向 sha1 完整性校验 |
|
|
228
|
-
| `delta-cli sandbox write <id> --path <path> --source <本地路径>` | 写入文件 |
|
|
229
|
-
| `delta-cli sandbox write-multiple <id> --entry <远程路径>=<本地路径>` | 批量写入 |
|
|
230
|
-
| `delta-cli sandbox ls <id> --path <path>` | 列出目录 |
|
|
231
|
-
| `delta-cli sandbox stat <id> --path <path>` | 文件元数据 |
|
|
232
|
-
| `delta-cli sandbox mv <id> --entry <src=dest>` | 移动/重命名 |
|
|
233
|
-
| `delta-cli sandbox replace <id> --path <path> --old <文本> --new <文本>` | 替换内容 |
|
|
234
|
-
| `delta-cli sandbox chmod <id> --path <path> --mode <八进制>` | 修改权限 |
|
|
235
|
-
| `delta-cli sandbox rm <id> --path <path>` | 删除文件 |
|
|
236
|
-
| `delta-cli sandbox rmdir <id> --path <路径>` | 递归删除目录 |
|
|
237
|
-
| `delta-cli sandbox mkdir <id> --path <路径>` | 创建目录 |
|
|
238
|
-
| `delta-cli sandbox search <id> --path <根目录> --pattern <glob>` | 搜索文件 |
|
|
239
|
-
| `delta-cli sandbox upload <id> --source <本地目录> --target <沙箱路径>` | 上传目录(tar.gz + 自动解压) |
|
|
240
|
-
|
|
241
|
-
### Science 工具
|
|
242
|
-
|
|
243
|
-
> 默认 Science Server 为 `http://8.141.101.94:8080/science_tool`。可通过
|
|
244
|
-
> `delta-cli config set science_base_url <url>` 或环境变量
|
|
245
|
-
> `DELTA_INFRA_SCIENCE_BASE_URL` 覆盖。
|
|
246
|
-
|
|
247
|
-
| 命令 | 说明 |
|
|
248
|
-
|------|------|
|
|
249
|
-
| `delta-cli science list` | 列出所有已启用的 science 工具 |
|
|
250
|
-
| `delta-cli science get <tool_name>` | 查看指定工具的详情 |
|
|
251
|
-
| `delta-cli science invoke --tool <tool_name> --endpoint <endpoint_name> [--data '{"key":"value"}'] [--params '{"key":"value"}']` | 调用工具端点 |
|
|
252
|
-
| `delta-cli science endpoints list <tool_name>` | 列出指定工具的所有端点 |
|
|
253
|
-
|
|
254
|
-
`tools.name` 和 `tool_endpoints.name` 是 Science 工具调用的唯一权威名称。
|
|
255
|
-
`science list` 与 `science endpoints list` 原样展示服务端数据库中的启用项,
|
|
256
|
-
`science invoke` 原样传递 `--tool` 和 `--endpoint`,不执行别名映射或旧名称兼容。
|
|
257
|
-
|
|
258
|
-
## 输出格式
|
|
259
|
-
|
|
260
|
-
所有命令返回统一的 JSON envelope:
|
|
261
|
-
|
|
262
|
-
```json
|
|
263
|
-
// 成功
|
|
264
|
-
{"ok":true,"data":{"id":"sb-xxx","status":"running"}}
|
|
265
|
-
|
|
266
|
-
// 错误
|
|
267
|
-
{"ok":false,"error":{"type":"auth","message":"not authenticated","hint":"run 'delta-cli auth login'"}}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
错误类型及退出码:
|
|
271
|
-
|
|
272
|
-
| Type | Exit Code | 场景 |
|
|
273
|
-
|------|-----------|------|
|
|
274
|
-
| validation | 2 | 参数错误 |
|
|
275
|
-
| auth | 3 | 未认证 |
|
|
276
|
-
| permission | 4 | 权限不足 |
|
|
277
|
-
| not_found | 5 | 资源不存在 |
|
|
278
|
-
| network | 6 | 网络错误 |
|
|
279
|
-
| api | 7 | 服务端错误 |
|
|
280
|
-
| internal | 10 | 客户端内部错误 |
|
|
281
|
-
|
|
282
|
-
## AI Agent Skills
|
|
283
|
-
|
|
284
|
-
delta-cli 内置 AI Agent 操作手册(Skills),帮助 Claude Code 等 AI 助手正确使用 CLI:
|
|
285
|
-
|
|
286
|
-
```bash
|
|
287
|
-
# 安装仓库中的全部 Skills
|
|
288
|
-
npx skills add delta-infra/delta-infra-cli -y -g
|
|
289
|
-
|
|
290
|
-
# 只安装统一 Science Skill
|
|
291
|
-
npx skills add delta-infra/delta-infra-cli -s delta-science
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
Skill 文件位于 `skills/` 目录:
|
|
295
|
-
- `delta-shared/` — 全局通用规则(认证、配置、错误处理)
|
|
296
|
-
- `delta-sandbox/` — Sandbox 操作指南(生命周期、命令路由)
|
|
297
|
-
- `delta-science/` — 唯一 Science 入口,包含统一 Delta CLI wrapper、跨工具工作流和
|
|
298
|
-
PubChem、RDKit、pymatgen、GSAS-II、LAMMPS、Delta-BO、LDM-BO、SynBO、AntBO
|
|
299
|
-
的按需 reference
|
|
300
|
-
|
|
301
|
-
Memento 等宿主只需要选择 `delta-science`。Skill 根据自然语言科研目标选择 tool 和
|
|
302
|
-
operation,并且只加载当前工具对应的 reference,避免大量独立 Skill 给规划器增加
|
|
303
|
-
负担。升级时会自动移除旧版独立 Science Skill。
|
|
304
|
-
|
|
305
|
-
### 添加 Science tool 或 operation
|
|
306
|
-
|
|
307
|
-
工具目录由 Science Server 数据库维护。新增工具时配置 `tools` 记录及对应的
|
|
308
|
-
`tool_endpoints` 记录;停用时设置 `status=false`。CLI 无需同步任何静态表或重新增加
|
|
309
|
-
命令。若需要让 AI 根据自然语言自动选择新工具并安全组装请求,再更新
|
|
310
|
-
`skills/delta-science/references/<tool>.md` 和路由文档;数据库中的 name 与 reference
|
|
311
|
-
必须完全一致。
|
|
312
|
-
|
|
313
|
-
## 开发
|
|
314
|
-
|
|
315
|
-
```bash
|
|
316
|
-
# 本地构建
|
|
317
|
-
make build
|
|
318
|
-
|
|
319
|
-
# 运行测试
|
|
320
|
-
make test
|
|
321
|
-
|
|
322
|
-
# 代码检查
|
|
323
|
-
make lint
|
|
324
|
-
|
|
325
|
-
# 跨平台编译(生成各平台二进制文件到 bin/)
|
|
326
|
-
make release
|
|
327
|
-
|
|
328
|
-
# 源码安装到系统 PATH(默认 /usr/local/bin;macOS / Linux)
|
|
329
|
-
make install
|
|
330
|
-
|
|
331
|
-
# 自定义安装前缀
|
|
332
|
-
make PREFIX=$HOME/.local install
|
|
333
|
-
|
|
334
|
-
# Windows 源码安装(二选一)
|
|
335
|
-
# 方式 A:直接用 go install 安装到 GOPATH/bin
|
|
336
|
-
go install github.com/delta-infra/delta-infra-cli/cmd/delta-cli@latest
|
|
337
|
-
|
|
338
|
-
# 方式 B:在仓库根目录运行 PowerShell 脚本,构建并添加到用户 PATH
|
|
339
|
-
# .\install-from-source.ps1
|
|
340
|
-
# .\install-from-source.ps1 -InstallDir "$env:USERPROFILE\bin"
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
### 日常开发流程
|
|
344
|
-
|
|
345
|
-
修改 `skills/` 或编译 `delta-cli` 后,需要同步到 Memento-S 项目才能生效:
|
|
346
|
-
|
|
347
|
-
```bash
|
|
348
|
-
# 1. 通过安装向导同步完整 Skill 集合
|
|
349
|
-
node scripts/install-wizard.js
|
|
350
|
-
|
|
351
|
-
# 2. 用 Docker 编译 Windows 版本(本地无 Go toolchain 时)
|
|
352
|
-
docker run --rm -v "$(pwd):/src" -w /src \
|
|
353
|
-
-e GOPROXY=https://goproxy.cn,direct \
|
|
354
|
-
golang:1.23 \
|
|
355
|
-
sh -c 'go build -buildvcs=false \
|
|
356
|
-
-ldflags "-X github.com/delta-infra/delta-infra-cli/internal/build.Version=$(git describe --tags --always --dirty 2>/dev/null || echo dev)" \
|
|
357
|
-
-o bin/delta-cli-windows-amd64.exe ./cmd/delta-cli'
|
|
358
|
-
|
|
359
|
-
# 3. 将 delta-cli 放到 Memento-S 的 node_modules/.bin(替换旧版本)
|
|
360
|
-
cp bin/delta-cli-windows-amd64.exe \
|
|
361
|
-
<memento-s>/electron_rebuild/node_modules/.bin/delta-cli
|
|
362
|
-
|
|
363
|
-
# 4. 重启 Memento-S sidecar 使新 binary 生效
|
|
364
|
-
# 在 Electron 界面中重新加载,或手动重启 sidecar 进程
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
> **注意**:`delta-cli` 替换后,如果 `~/.delta-infra/config.json` 中已配置 token,则
|
|
368
|
-
> Sandbox 和 Science Skills 可直接使用;否则需要先用 `auth login` 配置。
|
|
369
|
-
|
|
370
|
-
## 构建与发布
|
|
371
|
-
|
|
372
|
-
### 本地构建
|
|
373
|
-
|
|
374
|
-
```bash
|
|
375
|
-
# 本地构建
|
|
376
|
-
make build
|
|
377
|
-
|
|
378
|
-
# 运行测试
|
|
379
|
-
make test
|
|
380
|
-
|
|
381
|
-
# 代码检查
|
|
382
|
-
make lint
|
|
383
|
-
|
|
384
|
-
# 跨平台编译(生成各平台二进制文件到 bin/)
|
|
385
|
-
make release
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
> `make release` 仅生成各平台二进制文件(如 `bin/delta-cli-linux-amd64`),不会自动打包。打包与发布请使用下文的 `release.sh`。
|
|
389
|
-
|
|
390
|
-
### 一键发布(维护者)
|
|
391
|
-
|
|
392
|
-
项目根目录下的 `release.sh` 脚本负责完整发布流程:
|
|
393
|
-
|
|
394
|
-
```bash
|
|
395
|
-
export GH_TOKEN=<your-github-pat>
|
|
396
|
-
export NPM_TOKEN=<your-npm-token>
|
|
397
|
-
./release.sh v1.0.80
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
脚本执行步骤:
|
|
401
|
-
1. 更新 `package.json` 版本号。
|
|
402
|
-
2. 使用 Docker + `make release` 交叉编译 5 个平台二进制文件。
|
|
403
|
-
3. 在 `bin/` 目录生成 `.tar.gz` / `.zip` 归档。
|
|
404
|
-
4. 通过 `.ci/publish-github-release.js` 创建 GitHub Release 并上传资产。
|
|
405
|
-
5. 同步 npm 脚本、README 与全部 Skills 到公开仓库 `yzailab/delta-infra-cli`。
|
|
406
|
-
6. 执行 `npm publish --access public` 发布 `@delta-infra/cli`。
|
|
407
|
-
|
|
408
|
-
需要提前安装 `gh` CLI、Node.js/npm,并配置 `GH_TOKEN` 与 `NPM_TOKEN`。CI 流程可参考 `.gitlab-ci.yml`。
|
|
409
|
-
|
|
410
|
-
### npm 镜像
|
|
411
|
-
|
|
412
|
-
如果 GitHub 下载较慢,安装 npm 包时可设置镜像:
|
|
413
|
-
|
|
414
|
-
```bash
|
|
415
|
-
DELTA_CLI_MIRROR="https://gh-proxy.com/https://github.com" npm install -g @delta-infra/cli
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
## 技术栈
|
|
419
|
-
|
|
420
|
-
- **语言**: Go 1.23+
|
|
421
|
-
- **CLI 框架**: [Cobra](https://github.com/spf13/cobra)
|
|
422
|
-
- **配置**: JSON 文件(`~/.delta-infra/config.json`,权限 0600)
|
|
423
|
-
- **输出**: JSON envelope(AI-agent 友好,可脚本化)
|
|
424
|
-
- **发布**: GitHub Release(tar.gz/zip) + npm wrapper
|
|
425
|
-
- **架构**: 扁平静态命令树,Factory 依赖注入,惰性初始化
|
|
426
|
-
|
|
427
|
-
## License
|
|
428
|
-
|
|
429
|
-
MIT
|
|
1
|
+
# delta-cli
|
|
2
|
+
|
|
3
|
+
Delta Infra 的命令行工具,用于管理 Delta Sandbox GPU/CPU 计算任务和调用 Science 工具。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
### 方式一:npx 一键安装(推荐)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @delta-infra/cli@latest install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
该命令会依次完成:
|
|
14
|
+
1. **全局安装** `@delta-infra/cli`(含 Go 二进制)
|
|
15
|
+
2. **选择 AI 工具平台**(可多选):通用 Agent 目录 `~/.agents/skills/`(Codex/Cursor/OpenCode)、Claude Code `~/.claude/skills/`、OpenCode 原生 `~/.config/opencode/skills/`、Cursor `~/.cursor/skills/`、Memento-S 开发模式 `~/memento_s/skills/`
|
|
16
|
+
3. **安装 AI Skills** 到所选平台的 skills 目录
|
|
17
|
+
4. **初始化配置** `delta-cli config init`(交互式,非 TTY 跳过)
|
|
18
|
+
5. **身份认证** `delta-cli auth login`(交互式,非 TTY 跳过)
|
|
19
|
+
|
|
20
|
+
AI Agent 也可以直接使用以下指令完成安装:
|
|
21
|
+
|
|
22
|
+
> 帮我安装 delta-cli:https://github.com/yzailab/delta-infra-cli
|
|
23
|
+
|
|
24
|
+
### 卸载
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx @delta-infra/cli@latest uninstall
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
清理全局包、所有已知平台的 AI Skills 和配置文件。
|
|
31
|
+
|
|
32
|
+
### 升级
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 升级 CLI + AI Skills
|
|
36
|
+
delta-cli upgrade
|
|
37
|
+
|
|
38
|
+
# 只检查是否有更新(不执行升级)
|
|
39
|
+
delta-cli upgrade --check
|
|
40
|
+
|
|
41
|
+
# 只升级 CLI 二进制
|
|
42
|
+
delta-cli upgrade --cli-only
|
|
43
|
+
|
|
44
|
+
# 只升级 AI Skills
|
|
45
|
+
delta-cli upgrade --skills-only
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
升级 CLI 时会通过 `npm install -g @delta-infra/cli@latest` 拉取最新版本;升级 Skills 时会通过 `npx skills add` 重新安装 AI Skills。
|
|
49
|
+
|
|
50
|
+
### 方式二:直接下载 Binary
|
|
51
|
+
|
|
52
|
+
从 [GitHub Releases](https://github.com/yzailab/delta-infra-cli/releases) 下载对应平台的压缩包(以下使用 `latest` 指向最新版):
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# macOS (Apple Silicon)
|
|
56
|
+
curl -L -o delta-cli.tar.gz https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-darwin-arm64.tar.gz
|
|
57
|
+
tar -xzf delta-cli.tar.gz
|
|
58
|
+
sudo mv delta-cli-darwin-arm64 /usr/local/bin/delta-cli
|
|
59
|
+
rm delta-cli.tar.gz
|
|
60
|
+
|
|
61
|
+
# Linux (AMD64)
|
|
62
|
+
curl -L -o delta-cli.tar.gz https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-linux-amd64.tar.gz
|
|
63
|
+
tar -xzf delta-cli.tar.gz
|
|
64
|
+
chmod +x delta-cli-linux-amd64
|
|
65
|
+
sudo mv delta-cli-linux-amd64 /usr/local/bin/delta-cli
|
|
66
|
+
rm delta-cli.tar.gz
|
|
67
|
+
|
|
68
|
+
# Windows (AMD64,PowerShell)
|
|
69
|
+
Invoke-WebRequest -Uri https://github.com/yzailab/delta-infra-cli/releases/latest/download/delta-cli-windows-amd64.zip -OutFile delta-cli.zip
|
|
70
|
+
Expand-Archive -Path delta-cli.zip -DestinationPath . -Force
|
|
71
|
+
Move-Item -Path delta-cli-windows-amd64.exe -Destination delta-cli.exe
|
|
72
|
+
Remove-Item -Path delta-cli.zip
|
|
73
|
+
# 将 delta-cli.exe 放到 PATH 中的目录
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 方式三:一键安装脚本(国内用户推荐)
|
|
77
|
+
|
|
78
|
+
安装脚本会自动尝试国内 npm 镜像(npmmirror),失败后再回退到 npm 官方源:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Linux / macOS
|
|
82
|
+
curl -L https://raw.githubusercontent.com/yzailab/delta-infra-cli/main/install.sh | bash
|
|
83
|
+
|
|
84
|
+
# Windows (PowerShell)
|
|
85
|
+
Invoke-RestMethod -Uri https://raw.githubusercontent.com/yzailab/delta-infra-cli/main/install.ps1 | Invoke-Expression
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 方式四:npm
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npm install -g @delta-infra/cli
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`postinstall` 会按以下顺序尝试下载当前平台的二进制:
|
|
95
|
+
|
|
96
|
+
1. `DELTA_CLI_MIRROR` 环境变量(如果设置)
|
|
97
|
+
2. 国内加速镜像 `https://gh-proxy.com/https://github.com/...`
|
|
98
|
+
3. GitHub 源站 `https://github.com/yzailab/delta-infra-cli/releases/download/...`
|
|
99
|
+
|
|
100
|
+
如果安装时下载失败,可以:
|
|
101
|
+
|
|
102
|
+
- 直接运行一次 `delta-cli`,它会自动重新尝试下载。
|
|
103
|
+
- 或者在安装前设置本地压缩包路径:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
DELTA_CLI_ARCHIVE=/path/to/delta-cli-linux-amd64.tar.gz npm install -g @delta-infra/cli
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
常用环境变量:
|
|
110
|
+
|
|
111
|
+
| 变量 | 说明 |
|
|
112
|
+
|------|------|
|
|
113
|
+
| `DELTA_CLI_MIRROR` | 下载镜像,例如 `https://gh-proxy.com/https://github.com`。只接受 HTTPS 且需在白名单内。 |
|
|
114
|
+
| `DELTA_CLI_MIRROR_ALLOWLIST` | 额外允许的主机列表,逗号分隔。 |
|
|
115
|
+
| `DELTA_CLI_ARCHIVE` | 指向预先下载好的 `.tar.gz` / `.zip` 本地路径,跳过网络下载。 |
|
|
116
|
+
| `DELTA_CLI_SKIP_POSTINSTALL` | 设置为 `1` 跳过安装时的二进制下载,之后由 `delta-cli` 运行时兜底。 |
|
|
117
|
+
| `DELTA_CLI_FATAL_ON_ERROR` | 安装失败时退出码非 0(默认警告,用于调试)。 |
|
|
118
|
+
| `DELTA_CLI_DOWNLOAD_TIMEOUT` | 单个下载源最大等待时间(毫秒,默认 120000)。 |
|
|
119
|
+
|
|
120
|
+
### 方式五:Go Install
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
go install github.com/delta-infra/delta-infra-cli/cmd/delta-cli@latest
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 快速开始
|
|
127
|
+
|
|
128
|
+
### 1. 初始化配置
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
delta-cli config init
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
执行时会交互式提示输入服务端地址(默认:`https://delta-infra-nacos-test.yangtzeailab.com/sandbox/api/v1`)以及 Bearer Token(可选,也可后续用 `auth login` 配置)。
|
|
135
|
+
|
|
136
|
+
非交互式环境(如 CI)会直接使用默认值,也可以通过 flag 或环境变量一次性指定:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# 通过 flag
|
|
140
|
+
delta-cli config init \
|
|
141
|
+
--base-url http://your-server/api/v1 \
|
|
142
|
+
--token your-token
|
|
143
|
+
|
|
144
|
+
# 通过环境变量
|
|
145
|
+
export DELTA_INFRA_BASE_URL=http://your-server/api/v1
|
|
146
|
+
export DELTA_INFRA_TOKEN=your-token
|
|
147
|
+
delta-cli config init
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
配置文件保存在 `~/.delta-infra/config.json`(权限 0600)。
|
|
151
|
+
|
|
152
|
+
### 2. 认证
|
|
153
|
+
|
|
154
|
+
使用 Bearer Token:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Token
|
|
158
|
+
delta-cli auth login --token <your-token>
|
|
159
|
+
|
|
160
|
+
# 查看认证状态
|
|
161
|
+
delta-cli auth status
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 3. Sandbox 生命周期
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# 创建带 GPU 的 sandbox(--max-life 默认 30 分钟,长任务请调高)
|
|
168
|
+
delta-cli sandbox create \
|
|
169
|
+
--image image.yangtzeailab.com/opensandbox/pytorch-cuda13:latest \
|
|
170
|
+
--cpu 4 --memory 16Gi --gpu 1 \
|
|
171
|
+
--max-life 120
|
|
172
|
+
|
|
173
|
+
# 运行命令(短任务同步执行,长任务用 run-bg 替代 run)
|
|
174
|
+
delta-cli sandbox run <sandbox_id> \
|
|
175
|
+
--command "<命令>" \
|
|
176
|
+
--timeout 3600
|
|
177
|
+
|
|
178
|
+
# v1.0.55+ 默认带 --summary,返回 JSON 中 data.result_summary 字段已含 stdout 末尾 JSON 提取结果
|
|
179
|
+
# 无需再手动读取 log_file 做二次解析(除非使用了 --no-summary)
|
|
180
|
+
delta-cli sandbox run <sandbox_id> --command "echo '{\"status\":\"ok\",\"result\":\"done\"}'" --timeout 60
|
|
181
|
+
|
|
182
|
+
# 读取结果文件
|
|
183
|
+
delta-cli sandbox read <sandbox_id> --path /workspace/result.json
|
|
184
|
+
|
|
185
|
+
# 销毁 sandbox
|
|
186
|
+
delta-cli sandbox kill <sandbox_id>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## 命令列表
|
|
190
|
+
|
|
191
|
+
### 全局命令
|
|
192
|
+
|
|
193
|
+
| 命令 | 说明 |
|
|
194
|
+
|------|------|
|
|
195
|
+
| `delta-cli config init` | 初始化配置文件 |
|
|
196
|
+
| `delta-cli config show` | 查看当前配置(敏感字段已脱敏) |
|
|
197
|
+
| `delta-cli config set <key> <value>` | 修改配置项 |
|
|
198
|
+
| `delta-cli auth login` | 交互式登录 |
|
|
199
|
+
| `delta-cli auth login --token <token>` | Token 认证 |
|
|
200
|
+
| `delta-cli auth status` | 查看认证状态 |
|
|
201
|
+
| `delta-cli upgrade` | 升级 CLI 和 AI Skills 到最新版本 |
|
|
202
|
+
| `delta-cli upgrade --check` | 检查是否有可用更新 |
|
|
203
|
+
| `delta-cli upgrade --cli-only` | 只升级 CLI 二进制 |
|
|
204
|
+
| `delta-cli upgrade --skills-only` | 只升级 AI Skills |
|
|
205
|
+
| `delta-cli --version` | 显示版本 |
|
|
206
|
+
|
|
207
|
+
### Sandbox 命令
|
|
208
|
+
|
|
209
|
+
> **提示**:`sandbox list`(列沙箱实例)与 `sandbox ls <id>`(列目录)不同,注意区分。
|
|
210
|
+
|
|
211
|
+
| 命令 | 说明 |
|
|
212
|
+
|------|------|
|
|
213
|
+
| `delta-cli sandbox list` | 列出当前用户的 sandbox 实例 |
|
|
214
|
+
| `delta-cli sandbox providers` | 查看可用计算后端 |
|
|
215
|
+
| `delta-cli sandbox images` | 查看可用镜像列表 |
|
|
216
|
+
| `delta-cli sandbox recommend --cpu N --memory XGi` | 获取资源配置推荐 |
|
|
217
|
+
| `delta-cli sandbox create --image <img>` | 创建 sandbox 容器 |
|
|
218
|
+
| `delta-cli sandbox connect <id>` | 连接 sandbox |
|
|
219
|
+
| `delta-cli sandbox status <id>` | 查看 sandbox 状态 |
|
|
220
|
+
| `delta-cli sandbox finish <id>` | 保存结果并销毁 |
|
|
221
|
+
| `delta-cli sandbox kill <id>` | 销毁 sandbox |
|
|
222
|
+
| `delta-cli sandbox run <id> --command "..." [--timeout <秒>] [--summary/--no-summary] [--artifacts]` | 同步运行命令;默认带 `--summary`,返回 JSON 中 `summary` 字段已含 stdout 末尾 JSON 提取结果;`--artifacts` 附带 workspace 产物清单 |
|
|
223
|
+
| `delta-cli sandbox run-bg <id> --command "..." [--timeout <秒>] [--wait] [--summary/--no-summary] [--artifacts]` | 后台运行命令;不加 `--wait` 立即返回 `{execution_id, sandbox_id}`;加 `--wait` 等待完成返回含 `summary` 的完整结果 |
|
|
224
|
+
| `delta-cli sandbox logs <id> --execution-id <eid> [--tail N --grep <pattern> --context N --max-bytes N]` | 查看后台日志;默认返回 `stderr_size + stderr_tail`(避免上下文爆炸);可用 `--tail/--grep` 过滤 |
|
|
225
|
+
| `delta-cli sandbox cancel <id> --execution-id <eid>` | 中断后台命令 |
|
|
226
|
+
| `delta-cli sandbox read <id> --path <path> [--output <本地路径>] [--tail N] [--grep <pattern>] [--offset N] [--limit N] [--context N] [--max-bytes N] [--parse-json]` | 读取容器内文件;`--output <path>` 保存到本地;`--tail/--grep` 过滤;非 UTF-8 文件 CLI 自动走 base64 fallback |
|
|
227
|
+
| `delta-cli sandbox pull <id> --source <沙箱路径> --target <本地路径> [--recursive] [--pattern <glob>]` | 从沙箱拉取文件/目录到本地(mirror of `upload`,flag 方向相反:source=远程,target=本地);单文件或递归目录;CLI 端 + 服务端双向 sha1 完整性校验 |
|
|
228
|
+
| `delta-cli sandbox write <id> --path <path> --source <本地路径>` | 写入文件 |
|
|
229
|
+
| `delta-cli sandbox write-multiple <id> --entry <远程路径>=<本地路径>` | 批量写入 |
|
|
230
|
+
| `delta-cli sandbox ls <id> --path <path>` | 列出目录 |
|
|
231
|
+
| `delta-cli sandbox stat <id> --path <path>` | 文件元数据 |
|
|
232
|
+
| `delta-cli sandbox mv <id> --entry <src=dest>` | 移动/重命名 |
|
|
233
|
+
| `delta-cli sandbox replace <id> --path <path> --old <文本> --new <文本>` | 替换内容 |
|
|
234
|
+
| `delta-cli sandbox chmod <id> --path <path> --mode <八进制>` | 修改权限 |
|
|
235
|
+
| `delta-cli sandbox rm <id> --path <path>` | 删除文件 |
|
|
236
|
+
| `delta-cli sandbox rmdir <id> --path <路径>` | 递归删除目录 |
|
|
237
|
+
| `delta-cli sandbox mkdir <id> --path <路径>` | 创建目录 |
|
|
238
|
+
| `delta-cli sandbox search <id> --path <根目录> --pattern <glob>` | 搜索文件 |
|
|
239
|
+
| `delta-cli sandbox upload <id> --source <本地目录> --target <沙箱路径>` | 上传目录(tar.gz + 自动解压) |
|
|
240
|
+
|
|
241
|
+
### Science 工具
|
|
242
|
+
|
|
243
|
+
> 默认 Science Server 为 `http://8.141.101.94:8080/science_tool`。可通过
|
|
244
|
+
> `delta-cli config set science_base_url <url>` 或环境变量
|
|
245
|
+
> `DELTA_INFRA_SCIENCE_BASE_URL` 覆盖。
|
|
246
|
+
|
|
247
|
+
| 命令 | 说明 |
|
|
248
|
+
|------|------|
|
|
249
|
+
| `delta-cli science list` | 列出所有已启用的 science 工具 |
|
|
250
|
+
| `delta-cli science get <tool_name>` | 查看指定工具的详情 |
|
|
251
|
+
| `delta-cli science invoke --tool <tool_name> --endpoint <endpoint_name> [--data '{"key":"value"}'] [--params '{"key":"value"}']` | 调用工具端点 |
|
|
252
|
+
| `delta-cli science endpoints list <tool_name>` | 列出指定工具的所有端点 |
|
|
253
|
+
|
|
254
|
+
`tools.name` 和 `tool_endpoints.name` 是 Science 工具调用的唯一权威名称。
|
|
255
|
+
`science list` 与 `science endpoints list` 原样展示服务端数据库中的启用项,
|
|
256
|
+
`science invoke` 原样传递 `--tool` 和 `--endpoint`,不执行别名映射或旧名称兼容。
|
|
257
|
+
|
|
258
|
+
## 输出格式
|
|
259
|
+
|
|
260
|
+
所有命令返回统一的 JSON envelope:
|
|
261
|
+
|
|
262
|
+
```json
|
|
263
|
+
// 成功
|
|
264
|
+
{"ok":true,"data":{"id":"sb-xxx","status":"running"}}
|
|
265
|
+
|
|
266
|
+
// 错误
|
|
267
|
+
{"ok":false,"error":{"type":"auth","message":"not authenticated","hint":"run 'delta-cli auth login'"}}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
错误类型及退出码:
|
|
271
|
+
|
|
272
|
+
| Type | Exit Code | 场景 |
|
|
273
|
+
|------|-----------|------|
|
|
274
|
+
| validation | 2 | 参数错误 |
|
|
275
|
+
| auth | 3 | 未认证 |
|
|
276
|
+
| permission | 4 | 权限不足 |
|
|
277
|
+
| not_found | 5 | 资源不存在 |
|
|
278
|
+
| network | 6 | 网络错误 |
|
|
279
|
+
| api | 7 | 服务端错误 |
|
|
280
|
+
| internal | 10 | 客户端内部错误 |
|
|
281
|
+
|
|
282
|
+
## AI Agent Skills
|
|
283
|
+
|
|
284
|
+
delta-cli 内置 AI Agent 操作手册(Skills),帮助 Claude Code 等 AI 助手正确使用 CLI:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
# 安装仓库中的全部 Skills
|
|
288
|
+
npx skills add delta-infra/delta-infra-cli -y -g
|
|
289
|
+
|
|
290
|
+
# 只安装统一 Science Skill
|
|
291
|
+
npx skills add delta-infra/delta-infra-cli -s delta-science
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Skill 文件位于 `skills/` 目录:
|
|
295
|
+
- `delta-shared/` — 全局通用规则(认证、配置、错误处理)
|
|
296
|
+
- `delta-sandbox/` — Sandbox 操作指南(生命周期、命令路由)
|
|
297
|
+
- `delta-science/` — 唯一 Science 入口,包含统一 Delta CLI wrapper、跨工具工作流和
|
|
298
|
+
PubChem、RDKit、pymatgen、GSAS-II、LAMMPS、Delta-BO、LDM-BO、SynBO、AntBO
|
|
299
|
+
的按需 reference
|
|
300
|
+
|
|
301
|
+
Memento 等宿主只需要选择 `delta-science`。Skill 根据自然语言科研目标选择 tool 和
|
|
302
|
+
operation,并且只加载当前工具对应的 reference,避免大量独立 Skill 给规划器增加
|
|
303
|
+
负担。升级时会自动移除旧版独立 Science Skill。
|
|
304
|
+
|
|
305
|
+
### 添加 Science tool 或 operation
|
|
306
|
+
|
|
307
|
+
工具目录由 Science Server 数据库维护。新增工具时配置 `tools` 记录及对应的
|
|
308
|
+
`tool_endpoints` 记录;停用时设置 `status=false`。CLI 无需同步任何静态表或重新增加
|
|
309
|
+
命令。若需要让 AI 根据自然语言自动选择新工具并安全组装请求,再更新
|
|
310
|
+
`skills/delta-science/references/<tool>.md` 和路由文档;数据库中的 name 与 reference
|
|
311
|
+
必须完全一致。
|
|
312
|
+
|
|
313
|
+
## 开发
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
# 本地构建
|
|
317
|
+
make build
|
|
318
|
+
|
|
319
|
+
# 运行测试
|
|
320
|
+
make test
|
|
321
|
+
|
|
322
|
+
# 代码检查
|
|
323
|
+
make lint
|
|
324
|
+
|
|
325
|
+
# 跨平台编译(生成各平台二进制文件到 bin/)
|
|
326
|
+
make release
|
|
327
|
+
|
|
328
|
+
# 源码安装到系统 PATH(默认 /usr/local/bin;macOS / Linux)
|
|
329
|
+
make install
|
|
330
|
+
|
|
331
|
+
# 自定义安装前缀
|
|
332
|
+
make PREFIX=$HOME/.local install
|
|
333
|
+
|
|
334
|
+
# Windows 源码安装(二选一)
|
|
335
|
+
# 方式 A:直接用 go install 安装到 GOPATH/bin
|
|
336
|
+
go install github.com/delta-infra/delta-infra-cli/cmd/delta-cli@latest
|
|
337
|
+
|
|
338
|
+
# 方式 B:在仓库根目录运行 PowerShell 脚本,构建并添加到用户 PATH
|
|
339
|
+
# .\install-from-source.ps1
|
|
340
|
+
# .\install-from-source.ps1 -InstallDir "$env:USERPROFILE\bin"
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### 日常开发流程
|
|
344
|
+
|
|
345
|
+
修改 `skills/` 或编译 `delta-cli` 后,需要同步到 Memento-S 项目才能生效:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
# 1. 通过安装向导同步完整 Skill 集合
|
|
349
|
+
node scripts/install-wizard.js
|
|
350
|
+
|
|
351
|
+
# 2. 用 Docker 编译 Windows 版本(本地无 Go toolchain 时)
|
|
352
|
+
docker run --rm -v "$(pwd):/src" -w /src \
|
|
353
|
+
-e GOPROXY=https://goproxy.cn,direct \
|
|
354
|
+
golang:1.23 \
|
|
355
|
+
sh -c 'go build -buildvcs=false \
|
|
356
|
+
-ldflags "-X github.com/delta-infra/delta-infra-cli/internal/build.Version=$(git describe --tags --always --dirty 2>/dev/null || echo dev)" \
|
|
357
|
+
-o bin/delta-cli-windows-amd64.exe ./cmd/delta-cli'
|
|
358
|
+
|
|
359
|
+
# 3. 将 delta-cli 放到 Memento-S 的 node_modules/.bin(替换旧版本)
|
|
360
|
+
cp bin/delta-cli-windows-amd64.exe \
|
|
361
|
+
<memento-s>/electron_rebuild/node_modules/.bin/delta-cli
|
|
362
|
+
|
|
363
|
+
# 4. 重启 Memento-S sidecar 使新 binary 生效
|
|
364
|
+
# 在 Electron 界面中重新加载,或手动重启 sidecar 进程
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
> **注意**:`delta-cli` 替换后,如果 `~/.delta-infra/config.json` 中已配置 token,则
|
|
368
|
+
> Sandbox 和 Science Skills 可直接使用;否则需要先用 `auth login` 配置。
|
|
369
|
+
|
|
370
|
+
## 构建与发布
|
|
371
|
+
|
|
372
|
+
### 本地构建
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# 本地构建
|
|
376
|
+
make build
|
|
377
|
+
|
|
378
|
+
# 运行测试
|
|
379
|
+
make test
|
|
380
|
+
|
|
381
|
+
# 代码检查
|
|
382
|
+
make lint
|
|
383
|
+
|
|
384
|
+
# 跨平台编译(生成各平台二进制文件到 bin/)
|
|
385
|
+
make release
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
> `make release` 仅生成各平台二进制文件(如 `bin/delta-cli-linux-amd64`),不会自动打包。打包与发布请使用下文的 `release.sh`。
|
|
389
|
+
|
|
390
|
+
### 一键发布(维护者)
|
|
391
|
+
|
|
392
|
+
项目根目录下的 `release.sh` 脚本负责完整发布流程:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
export GH_TOKEN=<your-github-pat>
|
|
396
|
+
export NPM_TOKEN=<your-npm-token>
|
|
397
|
+
./release.sh v1.0.80
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
脚本执行步骤:
|
|
401
|
+
1. 更新 `package.json` 版本号。
|
|
402
|
+
2. 使用 Docker + `make release` 交叉编译 5 个平台二进制文件。
|
|
403
|
+
3. 在 `bin/` 目录生成 `.tar.gz` / `.zip` 归档。
|
|
404
|
+
4. 通过 `.ci/publish-github-release.js` 创建 GitHub Release 并上传资产。
|
|
405
|
+
5. 同步 npm 脚本、README 与全部 Skills 到公开仓库 `yzailab/delta-infra-cli`。
|
|
406
|
+
6. 执行 `npm publish --access public` 发布 `@delta-infra/cli`。
|
|
407
|
+
|
|
408
|
+
需要提前安装 `gh` CLI、Node.js/npm,并配置 `GH_TOKEN` 与 `NPM_TOKEN`。CI 流程可参考 `.gitlab-ci.yml`。
|
|
409
|
+
|
|
410
|
+
### npm 镜像
|
|
411
|
+
|
|
412
|
+
如果 GitHub 下载较慢,安装 npm 包时可设置镜像:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
DELTA_CLI_MIRROR="https://gh-proxy.com/https://github.com" npm install -g @delta-infra/cli
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 技术栈
|
|
419
|
+
|
|
420
|
+
- **语言**: Go 1.23+
|
|
421
|
+
- **CLI 框架**: [Cobra](https://github.com/spf13/cobra)
|
|
422
|
+
- **配置**: JSON 文件(`~/.delta-infra/config.json`,权限 0600)
|
|
423
|
+
- **输出**: JSON envelope(AI-agent 友好,可脚本化)
|
|
424
|
+
- **发布**: GitHub Release(tar.gz/zip) + npm wrapper
|
|
425
|
+
- **架构**: 扁平静态命令树,Factory 依赖注入,惰性初始化
|
|
426
|
+
|
|
427
|
+
## License
|
|
428
|
+
|
|
429
|
+
MIT
|