deepminer-cli 0.1.15

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 XMingAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # DeepMiner CLI
2
+
3
+ DeepMiner 系统的命令行工具,用于管理认证、配置和 AI 会话。
4
+
5
+ ## 功能特性
6
+
7
+ - ✅ **跨平台支持**: macOS、Linux、Windows
8
+ - ✅ **用户认证**: 用户名/密码登录,支持 JWT Token
9
+ - ✅ **自动 Token 管理**: Token 过期时自动刷新(本地 JWT 解析,无需 API 调用)
10
+ - ✅ **空间管理**: 选择和切换工作空间
11
+ - ✅ **配置管理**: 简单的 API 端点配置
12
+ - ✅ **安全存储**: Token 以受限权限存储在本地
13
+
14
+ ## 快速安装
15
+
16
+ ### 方式一:使用 npm(推荐)
17
+
18
+ 详见 [QUICK_START_FOR_USERS.md](./QUICK_START_FOR_USERS.md)
19
+
20
+ ```bash
21
+ npm install -g deepMiner-cli
22
+ dm-cli --version
23
+ ```
24
+
25
+ ### 方式二:从源码编译
26
+
27
+ ```bash
28
+ git clone https://code.mlamp.cn/dm/packages.git
29
+ cd dm-cli
30
+ go build -o dm-cli .
31
+ ```
32
+
33
+ ## 快速开始
34
+
35
+ ```bash
36
+ # 1. 初始化配置
37
+ dm-cli config init
38
+
39
+ # 2. 登录
40
+ dm-cli auth login
41
+
42
+ # 3. 查看状态
43
+ dm-cli auth status
44
+
45
+ # 4. 切换空间
46
+ dm-cli auth switch
47
+
48
+ # 5. 登出
49
+ dm-cli auth logout
50
+ ```
51
+
52
+ ## 命令列表
53
+
54
+ ### 配置
55
+
56
+ ```bash
57
+ dm-cli config init # 初始化配置(设置 API 端点)
58
+ dm-cli config show # 显示当前配置
59
+ ```
60
+
61
+ ### 认证
62
+
63
+ ```bash
64
+ dm-cli auth login # 登录到 DM 系统
65
+ dm-cli auth logout # 退出登录
66
+ dm-cli auth status # 显示登录状态
67
+ dm-cli auth switch # 切换工作空间
68
+ ```
69
+
70
+ ### 其他
71
+
72
+ ```bash
73
+ dm-cli --version # 显示版本号
74
+ dm-cli --help # 显示帮助信息
75
+ ```
76
+
77
+ ## 文件说明
78
+
79
+ ### 配置文件:`~/.dm-cli/config.json`
80
+
81
+ ```json
82
+ {
83
+ "api_endpoint": "https://dm-dev.xmingai.com/api"
84
+ }
85
+ ```
86
+
87
+ ### Token 文件:`~/.dm-cli/token.json` (权限 0600)
88
+
89
+ ```json
90
+ {
91
+ "access_token": "eyJ...",
92
+ "refresh_token": "ey...",
93
+ "expires_at": 1716239022,
94
+ "user_id": "user_123",
95
+ "email": "user@example.com",
96
+ "current_space": "space_id"
97
+ }
98
+ ```
99
+
100
+ ## Token 管理工作原理
101
+
102
+ 1. **认证**: 用户输入凭证,获得 `access_token` (JWT) 和 `refresh_token`
103
+ 2. **空间选择**: 获取可用空间,用户选择一个
104
+ 3. **存储**: Token 和元数据保存在 `~/.dm-cli/token.json`
105
+ 4. **自动刷新**: API 调用前自动检查 Token 是否过期,过期则刷新
106
+ 5. **401 处理**: 服务器拒绝 Token 时自动尝试刷新并重试
107
+
108
+ ## 项目结构
109
+
110
+ ```
111
+ dm-cli/
112
+ ├── cmd/ # 命令定义
113
+ │ ├── root.go # 根命令
114
+ │ ├── auth/ # 认证命令
115
+ │ ├── config/ # 配置命令
116
+ │ └── agent/ # AI 命令
117
+ ├── internal/
118
+ │ ├── auth/ # 认证模块
119
+ │ ├── client/ # HTTP 客户端
120
+ │ ├── config/ # 配置管理
121
+ │ ├── cmdutil/ # 命令工具
122
+ │ ├── output/ # 输出处理
123
+ │ └── validate/ # 输入验证
124
+ ├── main.go # 入口点
125
+ ├── go.mod # 依赖定义
126
+ └── Makefile # 构建脚本
127
+ ```
128
+
129
+ ## 开发
130
+
131
+ ### 本地编译和测试
132
+
133
+ ```bash
134
+ # 编译
135
+ go build -o dm-cli .
136
+
137
+ # 初始化配置
138
+ ./dm-cli config init
139
+
140
+ # 登录
141
+ ./dm-cli auth login
142
+
143
+ # 查看状态
144
+ ./dm-cli auth status
145
+ ```
146
+
147
+ ### 跨平台编译
148
+
149
+ ```bash
150
+ make build-all
151
+ # 输出: dm-cli-linux-amd64, dm-cli-darwin-amd64, dm-cli-darwin-arm64, dm-cli-windows-amd64.exe
152
+ ```
153
+
154
+ ## 文档
155
+
156
+ - [快速开始(用户)](./QUICK_START_FOR_USERS.md) - 普通用户安装指南
157
+ - [详细安装](./INSTALL.md) - 安装和常见问题
158
+ - [发布指南](./NPM_RELEASE.md) - 项目维护者发布新版本
159
+
160
+ ## 安全考虑
161
+
162
+ - Token 存储在 `~/.dm-cli/` 目录,权限为 0600
163
+ - 密码输入不显示在终端
164
+ - JWT Token 本地解析,只读取 exp 声明(不验证签名)
165
+ - Token 过期时自动刷新
166
+ - Refresh Token 过期后需要重新登录
167
+
168
+ ## 许可证
169
+
170
+ MIT
Binary file
Binary file
Binary file
Binary file
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "deepminer-cli",
3
+ "version": "0.1.15",
4
+ "description": "DeepMiner CLI - Command-line tool for DM system with cross-platform support, JWT authentication, and workspace management",
5
+ "keywords": [
6
+ "deepminer",
7
+ "dm",
8
+ "cli",
9
+ "command-line",
10
+ "authentication",
11
+ "jwt",
12
+ "api-client"
13
+ ],
14
+ "homepage": "https://www.npmjs.com/package/deepMiner-cli",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/xmingai/deepMiner-cli.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://code.mlamp.cn/dm/packages/-/issues"
21
+ },
22
+ "license": "MIT",
23
+ "author": "XMingAI",
24
+ "bin": {
25
+ "dm-cli": "scripts/run.js"
26
+ },
27
+ "files": [
28
+ "bin/dm-cli-darwin-amd64",
29
+ "bin/dm-cli-darwin-arm64",
30
+ "bin/dm-cli-linux-amd64",
31
+ "bin/dm-cli-windows-amd64.exe",
32
+ "scripts/run.js",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "make build-all",
38
+ "test": "go test ./..."
39
+ },
40
+ "engines": {
41
+ "node": ">=14.0.0"
42
+ },
43
+ "preferGlobal": true
44
+ }
package/scripts/run.js ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn, execSync } = require('child_process');
4
+ const path = require('path');
5
+ const os = require('os');
6
+ const fs = require('fs');
7
+
8
+ const platform = os.platform();
9
+ const arch = os.arch();
10
+
11
+ // Map node's platform/arch to standard names
12
+ const PLATFORM_MAP = {
13
+ 'darwin': 'darwin',
14
+ 'linux': 'linux',
15
+ 'win32': 'windows'
16
+ };
17
+
18
+ const ARCH_MAP = {
19
+ 'x64': 'amd64',
20
+ 'arm64': 'arm64'
21
+ };
22
+
23
+ const stdPlatform = PLATFORM_MAP[platform];
24
+ const stdArch = ARCH_MAP[arch];
25
+
26
+ if (!stdPlatform || !stdArch) {
27
+ console.error(`❌ Unsupported platform: ${platform}/${arch}`);
28
+ process.exit(1);
29
+ }
30
+
31
+ const isWindows = platform === 'win32';
32
+ const binaryName = `dm-cli-${stdPlatform}-${stdArch}${isWindows ? '.exe' : ''}`;
33
+ const binaryPath = path.join(__dirname, '..', 'bin', binaryName);
34
+
35
+ // Ensure symlink exists on first run (for global installs)
36
+ try {
37
+ const npmPrefix = execSync('npm config get prefix', { encoding: 'utf-8', stdio: 'pipe' }).trim();
38
+ const npmBinDir = path.join(npmPrefix, 'bin');
39
+ const npmBinPath = path.join(npmBinDir, 'dm-cli');
40
+ const thisFile = __filename;
41
+
42
+ if (!fs.existsSync(npmBinPath) && platform !== 'win32') {
43
+ try {
44
+ execSync(`ln -sf "${thisFile}" "${npmBinPath}"`, { stdio: 'ignore' });
45
+ } catch (e) {
46
+ // Silent fail
47
+ }
48
+ }
49
+ } catch (e) {
50
+ // Silent fail
51
+ }
52
+
53
+ // Spawn the binary and forward all arguments
54
+ const child = spawn(binaryPath, process.argv.slice(2), {
55
+ stdio: 'inherit',
56
+ windowsHide: true
57
+ });
58
+
59
+ child.on('error', (err) => {
60
+ if (err.code === 'ENOENT') {
61
+ console.error(`❌ Binary not found: ${binaryPath}`);
62
+ } else {
63
+ console.error(`❌ Error: ${err.message}`);
64
+ }
65
+ process.exit(1);
66
+ });
67
+
68
+ process.on('SIGINT', () => {
69
+ child.kill('SIGINT');
70
+ });
71
+
72
+ process.on('SIGTERM', () => {
73
+ child.kill('SIGTERM');
74
+ });
75
+
76
+ child.on('exit', (code) => {
77
+ process.exit(code);
78
+ });