deepminer-cli 0.1.27 → 0.1.30
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 +20 -93
- package/bin/dm-cli-darwin-amd64 +0 -0
- package/bin/dm-cli-darwin-arm64 +0 -0
- package/bin/dm-cli-linux-amd64 +0 -0
- package/bin/dm-cli-windows-amd64.exe +0 -0
- package/package.json +1 -1
- package/scripts/_dm-cli +2 -20
- package/scripts/install-completion.js +6 -0
package/README.md
CHANGED
|
@@ -5,11 +5,8 @@ DeepMiner 系统的命令行工具,用于管理认证、配置和 AI 会话。
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
7
|
- **跨平台支持**: macOS、Linux、Windows
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- **空间管理**: 查看和切换工作空间
|
|
11
|
-
- **配置管理**: API 端点配置
|
|
12
|
-
- **安全存储**: Token 以受限权限存储在本地
|
|
8
|
+
- **AccessKey 鉴权**: 通过 AccessKey 进行 API 认证
|
|
9
|
+
- **配置管理**: API 端点和 AccessKey 配置
|
|
13
10
|
- **AI 会话**: 启动/继续/停止 AI 助手会话,支持自定义消息、文件附件、会话追问和 claw_param 参数
|
|
14
11
|
- **JSON 输出**: 所有命令支持 `--json` 结构化输出,适合 AI agent 和脚本调用
|
|
15
12
|
- **错误提示**: 错误响应包含 `hint` 字段,提供可操作的修复建议
|
|
@@ -36,52 +33,24 @@ go build -o dm-cli .
|
|
|
36
33
|
|
|
37
34
|
## 快速开始
|
|
38
35
|
|
|
39
|
-
**方式一:使用 AccessKey(推荐,无需登录)**
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
# 1. 初始化配置(带 AccessKey,无需后续登录和选择空间)
|
|
43
|
-
dm-cli config init --endpoint https://dm-dev.xmingai.com --accesskey <your_access_key>
|
|
44
|
-
|
|
45
|
-
# 2. 直接使用
|
|
46
|
-
dm-cli agent start-thread --message "你好"
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
**方式二:使用用户名密码登录**
|
|
50
|
-
|
|
51
36
|
```bash
|
|
52
37
|
# 1. 初始化配置
|
|
53
|
-
dm-cli config init --endpoint https://dm-dev.xmingai.com
|
|
54
|
-
|
|
55
|
-
# 2. 登录(返回空间列表)
|
|
56
|
-
dm-cli auth login --username user@example.com --password xxx
|
|
57
|
-
|
|
58
|
-
# 3. 选择空间
|
|
59
|
-
dm-cli auth switch <space_id>
|
|
60
|
-
|
|
61
|
-
# 4. 查看状态
|
|
62
|
-
dm-cli auth status
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**通用操作**
|
|
38
|
+
dm-cli config init --endpoint https://dm-dev.xmingai.com --accesskey <your_access_key>
|
|
66
39
|
|
|
67
|
-
|
|
68
|
-
# 启动 AI 会话(返回 agent_run_id、thread_id)
|
|
40
|
+
# 2. 启动 AI 会话(返回 agent_run_id、thread_id)
|
|
69
41
|
dm-cli agent start-thread --message "你好"
|
|
70
42
|
|
|
71
|
-
# 带文件附件发送
|
|
43
|
+
# 3. 带文件附件发送
|
|
72
44
|
dm-cli agent start-thread --message "请分析这个报告" --file ./report.ppt
|
|
73
45
|
|
|
74
|
-
# 在已有会话中继续追问
|
|
46
|
+
# 4. 在已有会话中继续追问
|
|
75
47
|
dm-cli agent start-thread --message "继续聊" --thread-id <thread_id>
|
|
76
48
|
|
|
77
|
-
# 停止正在运行的 Agent
|
|
49
|
+
# 5. 停止正在运行的 Agent
|
|
78
50
|
dm-cli agent stop --agent-run-id <agent_run_id>
|
|
79
51
|
|
|
80
|
-
# 查看用户打开的 agent
|
|
52
|
+
# 6. 查看用户打开的 agent
|
|
81
53
|
dm-cli agent user-open
|
|
82
|
-
|
|
83
|
-
# 登出(仅用户名密码模式)
|
|
84
|
-
dm-cli auth logout
|
|
85
54
|
```
|
|
86
55
|
|
|
87
56
|
### JSON 模式(适合 AI agent / 脚本)
|
|
@@ -90,7 +59,7 @@ dm-cli auth logout
|
|
|
90
59
|
|
|
91
60
|
```bash
|
|
92
61
|
dm-cli auth status --json
|
|
93
|
-
# {"ok": true, "data": {"
|
|
62
|
+
# {"ok": true, "data": {"auth_mode": "accesskey", "access_key": "..."}}
|
|
94
63
|
|
|
95
64
|
dm-cli agent start-thread --message "分析" --file ./data.xlsx --json
|
|
96
65
|
# {"ok": true, "data": {"agent_run_id": "...", "thread_id": "...", ...}}
|
|
@@ -102,17 +71,14 @@ dm-cli agent start-thread --message "分析" --file ./data.xlsx --json
|
|
|
102
71
|
|
|
103
72
|
```bash
|
|
104
73
|
dm-cli config init --endpoint <url> # 初始化配置(设置 API 端点)
|
|
105
|
-
dm-cli config init --endpoint <url> --accesskey <key> # 初始化配置并设置 AccessKey
|
|
74
|
+
dm-cli config init --endpoint <url> --accesskey <key> # 初始化配置并设置 AccessKey
|
|
106
75
|
dm-cli config show # 显示当前配置
|
|
107
76
|
```
|
|
108
77
|
|
|
109
78
|
### 认证
|
|
110
79
|
|
|
111
80
|
```bash
|
|
112
|
-
dm-cli auth
|
|
113
|
-
dm-cli auth switch <space_id> # 切换工作空间
|
|
114
|
-
dm-cli auth status # 显示登录状态
|
|
115
|
-
dm-cli auth logout # 退出登录
|
|
81
|
+
dm-cli auth status # 显示鉴权状态
|
|
116
82
|
```
|
|
117
83
|
|
|
118
84
|
### AI 会话
|
|
@@ -193,7 +159,7 @@ dm-cli --help # 显示帮助信息
|
|
|
193
159
|
|
|
194
160
|
错误(含修复建议):
|
|
195
161
|
```json
|
|
196
|
-
{"ok": false, "error": {"type": "auth", "message": "
|
|
162
|
+
{"ok": false, "error": {"type": "auth", "message": "未配置 AccessKey", "hint": "运行 'dm-cli config init --endpoint <url> --accesskey <key>' 配置"}}
|
|
197
163
|
```
|
|
198
164
|
|
|
199
165
|
`hint` 字段提供可操作的修复建议,AI agent 可直接据此自动恢复。
|
|
@@ -202,16 +168,6 @@ dm-cli --help # 显示帮助信息
|
|
|
202
168
|
|
|
203
169
|
使用 `--dry-run` 预览请求而不实际执行,适合调试和 AI agent 安全验证:
|
|
204
170
|
|
|
205
|
-
```bash
|
|
206
|
-
dm-cli --dry-run auth login --username user --password pass
|
|
207
|
-
# [DRY RUN] POST https://api.example.com/api/auth/authentication/login
|
|
208
|
-
# Headers:
|
|
209
|
-
# Content-Type: application/json
|
|
210
|
-
# Body:
|
|
211
|
-
# {"username": "user", "password": "pass"}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
JSON 模式:
|
|
215
171
|
```bash
|
|
216
172
|
dm-cli --dry-run --json agent start-thread --message "你好"
|
|
217
173
|
```
|
|
@@ -219,7 +175,7 @@ dm-cli --dry-run --json agent start-thread --message "你好"
|
|
|
219
175
|
{"ok": true, "dry_run": true, "data": {"method": "POST", "url": "...", "headers": {...}, "body": {...}}}
|
|
220
176
|
```
|
|
221
177
|
|
|
222
|
-
只读命令(`config show`、`auth status`、`version`、`schema`)和纯本地操作(`config init
|
|
178
|
+
只读命令(`config show`、`auth status`、`version`、`schema`)和纯本地操作(`config init`)不受 `--dry-run` 影响,正常执行。
|
|
223
179
|
|
|
224
180
|
## 文件说明
|
|
225
181
|
|
|
@@ -227,43 +183,22 @@ dm-cli --dry-run --json agent start-thread --message "你好"
|
|
|
227
183
|
|
|
228
184
|
```json
|
|
229
185
|
{
|
|
230
|
-
"api_endpoint": "https://dm-dev.xmingai.com/api"
|
|
231
|
-
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### Token 文件:`~/.dm-cli/token.json` (权限 0600)
|
|
235
|
-
|
|
236
|
-
```json
|
|
237
|
-
{
|
|
238
|
-
"access_token": "eyJ...",
|
|
239
|
-
"refresh_token": "ey...",
|
|
240
|
-
"expires_at": 1716239022,
|
|
241
|
-
"user_id": "user_123",
|
|
242
|
-
"email": "user@example.com",
|
|
243
|
-
"current_space": "space_id"
|
|
186
|
+
"api_endpoint": "https://dm-dev.xmingai.com/api",
|
|
187
|
+
"access_key": "your_access_key"
|
|
244
188
|
}
|
|
245
189
|
```
|
|
246
190
|
|
|
247
|
-
## Token 管理工作原理
|
|
248
|
-
|
|
249
|
-
1. **认证**: 使用 `--username`/`--password` 凭证获得 `access_token` (JWT) 和 `refresh_token`
|
|
250
|
-
2. **空间选择**: 登录返回可用空间列表,使用 `auth switch` 选择
|
|
251
|
-
3. **存储**: Token 和元数据保存在 `~/.dm-cli/token.json`
|
|
252
|
-
4. **自动刷新**: API 调用前自动检查 Token 是否过期,过期则刷新
|
|
253
|
-
5. **401 处理**: 服务器拒绝 Token 时自动尝试刷新并重试
|
|
254
|
-
|
|
255
191
|
## 项目结构
|
|
256
192
|
|
|
257
193
|
```
|
|
258
194
|
dm-cli/
|
|
259
195
|
├── cmd/ # 命令定义
|
|
260
196
|
│ ├── root.go # 根命令
|
|
261
|
-
│ ├── auth/ #
|
|
197
|
+
│ ├── auth/ # 鉴权状态命令
|
|
262
198
|
│ ├── config/ # 配置命令
|
|
263
199
|
│ ├── agent/ # AI 命令
|
|
264
200
|
│ └── schema/ # Schema 输出命令
|
|
265
201
|
├── internal/
|
|
266
|
-
│ ├── auth/ # 认证模块
|
|
267
202
|
│ ├── client/ # HTTP 客户端
|
|
268
203
|
│ ├── config/ # 配置管理
|
|
269
204
|
│ ├── cmdutil/ # 命令工具
|
|
@@ -286,15 +221,9 @@ dm-cli/
|
|
|
286
221
|
go build -o dm-cli .
|
|
287
222
|
|
|
288
223
|
# 初始化配置
|
|
289
|
-
./dm-cli config init --endpoint https://dm-dev.xmingai.com
|
|
290
|
-
|
|
291
|
-
# 登录
|
|
292
|
-
./dm-cli auth login --username user@example.com --password xxx
|
|
293
|
-
|
|
294
|
-
# 选择空间
|
|
295
|
-
./dm-cli auth switch <space_id>
|
|
224
|
+
./dm-cli config init --endpoint https://dm-dev.xmingai.com --accesskey <your_access_key>
|
|
296
225
|
|
|
297
|
-
#
|
|
226
|
+
# 查看鉴权状态
|
|
298
227
|
./dm-cli auth status
|
|
299
228
|
```
|
|
300
229
|
|
|
@@ -313,10 +242,8 @@ make build-all
|
|
|
313
242
|
|
|
314
243
|
## 安全考虑
|
|
315
244
|
|
|
316
|
-
-
|
|
317
|
-
-
|
|
318
|
-
- Token 过期时自动刷新
|
|
319
|
-
- Refresh Token 过期后需要重新登录
|
|
245
|
+
- 配置文件存储在 `~/.dm-cli/` 目录,权限为 0600
|
|
246
|
+
- AccessKey 以明文存储在配置文件中,请确保文件权限安全
|
|
320
247
|
|
|
321
248
|
## zsh 补全
|
|
322
249
|
|
package/bin/dm-cli-darwin-amd64
CHANGED
|
Binary file
|
package/bin/dm-cli-darwin-arm64
CHANGED
|
Binary file
|
package/bin/dm-cli-linux-amd64
CHANGED
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/scripts/_dm-cli
CHANGED
|
@@ -81,32 +81,14 @@ _dm_cli_auth() {
|
|
|
81
81
|
case "$state" in
|
|
82
82
|
subcommand)
|
|
83
83
|
local -a subcommands=(
|
|
84
|
-
'
|
|
85
|
-
'logout:退出登录'
|
|
86
|
-
'status:显示登录状态'
|
|
87
|
-
'switch:切换空间'
|
|
84
|
+
'status:显示鉴权状态'
|
|
88
85
|
)
|
|
89
86
|
_describe -t subcommands 'subcommand' subcommands
|
|
90
87
|
;;
|
|
91
88
|
args)
|
|
92
89
|
case "${line[1]}" in
|
|
93
|
-
|
|
90
|
+
status)
|
|
94
91
|
_arguments \
|
|
95
|
-
'--username=[用户名]:username' \
|
|
96
|
-
'--password=[密码]:password' \
|
|
97
|
-
'--json[以 JSON 格式输出]' \
|
|
98
|
-
'--dry-run[预览请求]' \
|
|
99
|
-
'--help[显示帮助]'
|
|
100
|
-
;;
|
|
101
|
-
logout|status)
|
|
102
|
-
_arguments \
|
|
103
|
-
'--json[以 JSON 格式输出]' \
|
|
104
|
-
'--dry-run[预览请求]' \
|
|
105
|
-
'--help[显示帮助]'
|
|
106
|
-
;;
|
|
107
|
-
switch)
|
|
108
|
-
_arguments \
|
|
109
|
-
'1:space_id' \
|
|
110
92
|
'--json[以 JSON 格式输出]' \
|
|
111
93
|
'--dry-run[预览请求]' \
|
|
112
94
|
'--help[显示帮助]'
|
|
@@ -26,6 +26,12 @@ try {
|
|
|
26
26
|
if (fs.existsSync(sourceFile)) {
|
|
27
27
|
fs.copyFileSync(sourceFile, completionFile);
|
|
28
28
|
fs.chmodSync(completionFile, 0o644);
|
|
29
|
+
|
|
30
|
+
// Clear zsh completion cache so new completions take effect
|
|
31
|
+
const zcompdumpFiles = fs.readdirSync(homeDir).filter(f => f.startsWith('.zcompdump'));
|
|
32
|
+
for (const f of zcompdumpFiles) {
|
|
33
|
+
try { fs.unlinkSync(path.join(homeDir, f)); } catch (_) {}
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
// Add fpath to .zshrc if not already there
|