rl-rockcli 0.0.2 → 0.0.4
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 +400 -0
- package/index.js +51 -21
- package/package.json +3 -2
- package/commands/log/core/constants.js +0 -237
- package/commands/log/core/display.js +0 -370
- package/commands/log/core/search.js +0 -330
- package/commands/log/core/tail.js +0 -216
- package/commands/log/core/utils.js +0 -424
- package/commands/log.js +0 -298
- package/commands/sandbox/core/log-bridge.js +0 -119
- package/commands/sandbox/core/replay/analyzer.js +0 -311
- package/commands/sandbox/core/replay/batch-orchestrator.js +0 -536
- package/commands/sandbox/core/replay/batch-task.js +0 -369
- package/commands/sandbox/core/replay/concurrent-display.js +0 -70
- package/commands/sandbox/core/replay/concurrent-orchestrator.js +0 -170
- package/commands/sandbox/core/replay/data-source.js +0 -86
- package/commands/sandbox/core/replay/display.js +0 -231
- package/commands/sandbox/core/replay/executor.js +0 -634
- package/commands/sandbox/core/replay/history-fetcher.js +0 -124
- package/commands/sandbox/core/replay/index.js +0 -338
- package/commands/sandbox/core/replay/loghouse-data-source.js +0 -177
- package/commands/sandbox/core/replay/pid-mapping.js +0 -26
- package/commands/sandbox/core/replay/request.js +0 -109
- package/commands/sandbox/core/replay/worker.js +0 -166
- package/commands/sandbox/core/session.js +0 -346
- package/commands/sandbox/log-bridge.js +0 -2
- package/commands/sandbox/ray.js +0 -2
- package/commands/sandbox/replay/analyzer.js +0 -311
- package/commands/sandbox/replay/batch-orchestrator.js +0 -536
- package/commands/sandbox/replay/batch-task.js +0 -369
- package/commands/sandbox/replay/concurrent-display.js +0 -70
- package/commands/sandbox/replay/concurrent-orchestrator.js +0 -170
- package/commands/sandbox/replay/display.js +0 -231
- package/commands/sandbox/replay/executor.js +0 -634
- package/commands/sandbox/replay/history-fetcher.js +0 -118
- package/commands/sandbox/replay/index.js +0 -338
- package/commands/sandbox/replay/pid-mapping.js +0 -26
- package/commands/sandbox/replay/request.js +0 -109
- package/commands/sandbox/replay/worker.js +0 -166
- package/commands/sandbox/replay.js +0 -2
- package/commands/sandbox/session.js +0 -2
- package/commands/sandbox-original.js +0 -1393
- package/commands/sandbox.js +0 -499
- package/help/help.json +0 -1071
- package/help/middleware.js +0 -71
- package/help/renderer.js +0 -800
- package/lib/plugin-context.js +0 -40
- package/sdks/sandbox/core/client.js +0 -845
- package/sdks/sandbox/core/config.js +0 -70
- package/sdks/sandbox/core/types.js +0 -74
- package/sdks/sandbox/httpLogger.js +0 -251
- package/sdks/sandbox/index.js +0 -9
- package/utils/asciiArt.js +0 -138
- package/utils/bun-compat.js +0 -59
- package/utils/ciPipelines.js +0 -138
- package/utils/cli.js +0 -17
- package/utils/command-router.js +0 -79
- package/utils/configManager.js +0 -503
- package/utils/dependency-resolver.js +0 -135
- package/utils/eagleeye_traceid.js +0 -151
- package/utils/envDetector.js +0 -78
- package/utils/execution_logger.js +0 -415
- package/utils/featureManager.js +0 -68
- package/utils/firstTimeTip.js +0 -44
- package/utils/hook-manager.js +0 -125
- package/utils/http-logger.js +0 -264
- package/utils/i18n.js +0 -139
- package/utils/image-progress.js +0 -159
- package/utils/logger.js +0 -154
- package/utils/plugin-loader.js +0 -124
- package/utils/plugin-manager.js +0 -348
- package/utils/ray_cli_wrapper.js +0 -746
- package/utils/sandbox-client.js +0 -419
- package/utils/terminal.js +0 -32
- package/utils/tips.js +0 -106
package/README.md
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# ROCK CLI (rockcli)
|
|
2
|
+
|
|
3
|
+
ROCK CLI 是一个开源的命令行工具,用于管理和操作沙箱环境以及查询日志数据。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **日志查询** - 搜索和实时查看日志数据
|
|
8
|
+
- **沙箱管理** - 启动、停止、执行、上传/下载文件、交互式 REPL
|
|
9
|
+
- **会话管理** - 持久化执行环境,支持环境变量继承
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# 使用 npm 安装
|
|
15
|
+
npm install -g rl-rockcli
|
|
16
|
+
|
|
17
|
+
# 或使用 yarn 安装
|
|
18
|
+
yarn global add rl-rockcli
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 使用方法
|
|
22
|
+
|
|
23
|
+
### 基本语法
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
rockcli <command> [options]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 全局选项
|
|
30
|
+
|
|
31
|
+
- `--verbose, -v` - 启用详细日志输出
|
|
32
|
+
- `--config` - 配置文件路径(默认:~/.rock/settings.json)
|
|
33
|
+
- `--base-url` - 服务器地址(覆盖配置文件)
|
|
34
|
+
- `--api-key` - API 密钥(覆盖配置文件)
|
|
35
|
+
|
|
36
|
+
## 命令详解
|
|
37
|
+
|
|
38
|
+
### 日志查询 (log)
|
|
39
|
+
|
|
40
|
+
日志查询功能支持两种模式:
|
|
41
|
+
- **search**:查询指定时间范围内的日志
|
|
42
|
+
- **tail**:实时滚动查看日志,每 5 秒自动刷新
|
|
43
|
+
|
|
44
|
+
#### 命令
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 搜索日志
|
|
48
|
+
rockcli log search [options]
|
|
49
|
+
|
|
50
|
+
# 实时滚动查看日志
|
|
51
|
+
rockcli log tail [options]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### 选项说明
|
|
55
|
+
|
|
56
|
+
##### 查询条件参数
|
|
57
|
+
|
|
58
|
+
- `[sandboxId]` - 位置参数,指定沙箱 ID
|
|
59
|
+
- `--sandbox-id` - 按沙箱 ID 过滤
|
|
60
|
+
- `-k, --keyword` - 搜索关键词
|
|
61
|
+
- `-f, --field` - 按字段名和值搜索(格式:`field=value`,可多次指定)
|
|
62
|
+
- `--log-file` - 指定日志文件名(需配合 --sandbox-id 使用)
|
|
63
|
+
|
|
64
|
+
##### 时间范围参数(仅 search 支持)
|
|
65
|
+
|
|
66
|
+
- `-m, --minutes` - 搜索最近 N 分钟的日志(默认:15)
|
|
67
|
+
- `-s, --start-time` - 开始时间
|
|
68
|
+
- `-e, --end-time` - 结束时间
|
|
69
|
+
|
|
70
|
+
##### 结果控制参数
|
|
71
|
+
|
|
72
|
+
- `-l, --limit` - 限制返回结果数量(默认:100)
|
|
73
|
+
- `-o, --offset` - 跳过前 N 条日志(默认:0,仅 search 支持)
|
|
74
|
+
|
|
75
|
+
##### 输出格式参数
|
|
76
|
+
|
|
77
|
+
- `--raw` - 显示原始输出(默认:false)
|
|
78
|
+
- `--log-format` - 输出格式:`logfmt`(默认)、`json`、`columns`
|
|
79
|
+
- `--columns` - 过滤显示的字段(逗号分隔)
|
|
80
|
+
- `--multilines` - 允许多行展示(默认:false)
|
|
81
|
+
- `--truncate` - 截断长字段值(默认:2048 字符)
|
|
82
|
+
|
|
83
|
+
##### 特殊功能参数
|
|
84
|
+
|
|
85
|
+
- `--count` - 仅显示匹配的日志条数(仅 search 支持)
|
|
86
|
+
- `--debug` - 启用调试模式,输出执行的查询语句
|
|
87
|
+
- `-i, --interval` - 扫描间隔(秒),默认:5(仅 tail 支持)
|
|
88
|
+
- `-n` - 首次显示的最近日志条数,默认:10(仅 tail 支持)
|
|
89
|
+
|
|
90
|
+
#### 示例
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# 搜索最近 15 分钟的日志
|
|
94
|
+
rockcli log search -k "error"
|
|
95
|
+
|
|
96
|
+
# 搜索最近 30 分钟的日志
|
|
97
|
+
rockcli log search -k "error" -m 30
|
|
98
|
+
|
|
99
|
+
# 使用位置参数指定沙箱 ID
|
|
100
|
+
rockcli log search abc123
|
|
101
|
+
|
|
102
|
+
# 限制返回结果数量(返回 50 条)
|
|
103
|
+
rockcli log search -k "error" -l 50
|
|
104
|
+
|
|
105
|
+
# 按字段名精确搜索
|
|
106
|
+
rockcli log search -f "level=ERROR" -m 15
|
|
107
|
+
|
|
108
|
+
# 实时滚动查看日志(默认 5 秒间隔)
|
|
109
|
+
rockcli log tail -k "error"
|
|
110
|
+
|
|
111
|
+
# 自定义扫描间隔为 10 秒
|
|
112
|
+
rockcli log tail -k "error" -i 10
|
|
113
|
+
|
|
114
|
+
# 显示最近 20 条日志,然后实时更新
|
|
115
|
+
rockcli log tail -k "error" -n 20
|
|
116
|
+
|
|
117
|
+
# 监控特定沙箱的日志
|
|
118
|
+
rockcli log tail --sandbox-id abc123
|
|
119
|
+
|
|
120
|
+
# 使用 JSON 格式输出
|
|
121
|
+
rockcli log search -k "error" --log-format json
|
|
122
|
+
|
|
123
|
+
# 只统计日志条数,不显示内容
|
|
124
|
+
rockcli log search -k "error" -m 15 --count
|
|
125
|
+
|
|
126
|
+
# 使用原始输出格式
|
|
127
|
+
rockcli log search -k "error" --raw
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 沙箱管理 (sandbox)
|
|
131
|
+
|
|
132
|
+
#### 基本语法
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
rockcli sandbox [action] [options]
|
|
136
|
+
rockcli sandbox [sandboxId] [action] [options]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### 可用操作
|
|
140
|
+
|
|
141
|
+
**基本操作:**
|
|
142
|
+
- **start** - 启动一个新的 sandbox 实例
|
|
143
|
+
- **stop** - 停止指定的 sandbox 实例
|
|
144
|
+
- **execute** - 在 sandbox 中执行命令(别名:exec)
|
|
145
|
+
- **status** - 查看 sandbox 的运行状态
|
|
146
|
+
- **upload** - 上传文件或文件夹到 sandbox
|
|
147
|
+
- **download** - 从 sandbox 下载文件
|
|
148
|
+
- **write-file** - 在 sandbox 中写入文件
|
|
149
|
+
- **read-file** - 从 sandbox 读取文件
|
|
150
|
+
- **attach** - 进入交互式 REPL 模式
|
|
151
|
+
|
|
152
|
+
**Session 管理(子命令):**
|
|
153
|
+
- **session create** - 创建 session
|
|
154
|
+
- **session run** - 在 session 中执行命令
|
|
155
|
+
- **session close** - 关闭 session
|
|
156
|
+
|
|
157
|
+
#### 新语法格式(推荐)
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# ID 在前,action 在后(更符合直觉)
|
|
161
|
+
rockcli sandbox start
|
|
162
|
+
rockcli sandbox <sandbox-id> stop
|
|
163
|
+
rockcli sandbox <sandbox-id> status
|
|
164
|
+
rockcli sandbox <sandbox-id> attach
|
|
165
|
+
|
|
166
|
+
# 执行命令(使用 -- 分隔符)
|
|
167
|
+
rockcli sandbox <sandbox-id> exec -- ls -la
|
|
168
|
+
rockcli sandbox <sandbox-id> exec -- python script.py
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### 基本命令示例
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# 启动一个新的 sandbox 实例
|
|
175
|
+
rockcli sandbox start --image python:3.11 --memory 8g --cpus 2.0
|
|
176
|
+
|
|
177
|
+
# 停止指定的 sandbox 实例
|
|
178
|
+
rockcli sandbox <sandbox-id> stop
|
|
179
|
+
|
|
180
|
+
# 在 sandbox 中执行命令(支持 -- 分隔符)
|
|
181
|
+
rockcli sandbox <sandbox-id> exec -- ls -la
|
|
182
|
+
rockcli sandbox <sandbox-id> exec --command "ls -la"
|
|
183
|
+
|
|
184
|
+
# 查看 sandbox 的运行状态
|
|
185
|
+
rockcli sandbox <sandbox-id> status
|
|
186
|
+
|
|
187
|
+
# 上传单个文件到 sandbox
|
|
188
|
+
rockcli sandbox <sandbox-id> upload --file local.txt --target-path /tmp/remote.txt
|
|
189
|
+
|
|
190
|
+
# 上传文件夹到 sandbox(仅一级文件)
|
|
191
|
+
rockcli sandbox <sandbox-id> upload --dir ./src --target-path /app/src
|
|
192
|
+
|
|
193
|
+
# 递归上传文件夹(保持目录结构)
|
|
194
|
+
rockcli sandbox <sandbox-id> upload --dir ./project --target-path /app -r
|
|
195
|
+
|
|
196
|
+
# 从 sandbox 下载文件
|
|
197
|
+
rockcli sandbox <sandbox-id> download --file /tmp/remote.txt
|
|
198
|
+
|
|
199
|
+
# 在 sandbox 中写入文件
|
|
200
|
+
rockcli sandbox <sandbox-id> write-file --content "Hello World" --target-path /tmp/hello.txt
|
|
201
|
+
|
|
202
|
+
# 从 sandbox 读取文件
|
|
203
|
+
rockcli sandbox <sandbox-id> read-file --file /tmp/hello.txt --start-line 1 --end-line 10
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Session 管理示例
|
|
207
|
+
|
|
208
|
+
**session create - 创建 session**
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
# 创建默认 session
|
|
212
|
+
rockcli sandbox <sandbox-id> session create
|
|
213
|
+
|
|
214
|
+
# 创建自定义名称的 session
|
|
215
|
+
rockcli sandbox <sandbox-id> session create --session my-session
|
|
216
|
+
|
|
217
|
+
# 创建带启动脚本的 session
|
|
218
|
+
rockcli sandbox <sandbox-id> session create --startup-source "/root/.bashrc,/app/env.sh"
|
|
219
|
+
|
|
220
|
+
# 创建带环境变量的 session
|
|
221
|
+
rockcli sandbox <sandbox-id> session create --env '{"PATH":"/usr/local/bin:/usr/bin","ENV":"production"}'
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**session run - 在 session 中执行命令**
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# 使用 -- 分隔符执行命令(推荐)
|
|
228
|
+
rockcli sandbox <sandbox-id> session run -- ls -la
|
|
229
|
+
rockcli sandbox <sandbox-id> session run -- python script.py --arg1 value1
|
|
230
|
+
|
|
231
|
+
# 使用 --command 参数
|
|
232
|
+
rockcli sandbox <sandbox-id> session run --command "ls -la"
|
|
233
|
+
|
|
234
|
+
# 在自定义 session 中执行
|
|
235
|
+
rockcli sandbox <sandbox-id> session run --session my-session -- ls -la
|
|
236
|
+
|
|
237
|
+
# 设置超时时间(30秒)
|
|
238
|
+
rockcli sandbox <sandbox-id> session run --timeout 30 -- python long_task.py
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**session close - 关闭 session**
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# 关闭默认 session
|
|
245
|
+
rockcli sandbox <sandbox-id> session close
|
|
246
|
+
|
|
247
|
+
# 关闭自定义名称的 session
|
|
248
|
+
rockcli sandbox <sandbox-id> session close --session my-session
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 交互式 REPL 模式
|
|
252
|
+
|
|
253
|
+
使用 `attach` 命令进入交互式模式:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# 进入交互式 REPL
|
|
257
|
+
rockcli sandbox <sandbox-id> attach
|
|
258
|
+
|
|
259
|
+
# 或使用旧语法
|
|
260
|
+
rockcli attach <sandbox-id>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
REPL 模式支持:
|
|
264
|
+
- 持久 session(export、cd 等命令状态保持)
|
|
265
|
+
- 命令历史(上下键浏览)
|
|
266
|
+
- Tab 补全
|
|
267
|
+
- 内置命令(以 `/` 开头):
|
|
268
|
+
- `/log` - 搜索日志
|
|
269
|
+
- `/upload` / `/download` - 文件传输
|
|
270
|
+
- `/status` - 查看状态
|
|
271
|
+
- `/help` - 帮助
|
|
272
|
+
- `/exit` - 退出
|
|
273
|
+
- `/close` - 关闭 session 并退出
|
|
274
|
+
|
|
275
|
+
## 配置文件
|
|
276
|
+
|
|
277
|
+
默认配置文件路径:`~/.rock/settings.json`
|
|
278
|
+
|
|
279
|
+
配置文件格式(JSON):
|
|
280
|
+
|
|
281
|
+
```json
|
|
282
|
+
{
|
|
283
|
+
"sandbox": {
|
|
284
|
+
"base_url": "http://localhost:8080",
|
|
285
|
+
"api_key": "your-api-key"
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## 环境变量
|
|
291
|
+
|
|
292
|
+
支持通过环境变量设置认证信息:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
# 设置 API Key
|
|
296
|
+
export ROCK_API_KEY=your-api-key
|
|
297
|
+
|
|
298
|
+
# 设置服务器地址
|
|
299
|
+
export ROCKCLI_BASE_URL=http://localhost:8080
|
|
300
|
+
|
|
301
|
+
# 或使用 ROCK_BASE_URL(兼容)
|
|
302
|
+
export ROCK_BASE_URL=http://localhost:8080
|
|
303
|
+
|
|
304
|
+
# 使用环境变量运行命令
|
|
305
|
+
rockcli sandbox <sandbox-id> status
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
优先级:命令行参数 > 环境变量 > 配置文件
|
|
309
|
+
|
|
310
|
+
## 配置管理 (config)
|
|
311
|
+
|
|
312
|
+
配置管理命令用于设置和查看本地配置参数。
|
|
313
|
+
|
|
314
|
+
### 基本语法
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
rockcli config [options]
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 选项说明
|
|
321
|
+
|
|
322
|
+
- `--api-key <key>` - 设置 API 密钥
|
|
323
|
+
- `--base-url <url>` - 设置服务器基础 URL
|
|
324
|
+
- `--list` - 显示当前配置(脱敏敏感值)
|
|
325
|
+
|
|
326
|
+
### 示例
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# 设置 API Key 和服务器地址
|
|
330
|
+
rockcli config --api-key xxx --base-url http://localhost:8080
|
|
331
|
+
|
|
332
|
+
# 显示当前配置
|
|
333
|
+
rockcli config --list
|
|
334
|
+
|
|
335
|
+
# 仅设置 API Key,其他值保持不变
|
|
336
|
+
rockcli config --api-key xxx
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## 开发指南
|
|
340
|
+
|
|
341
|
+
### 项目结构
|
|
342
|
+
|
|
343
|
+
```
|
|
344
|
+
opensource/
|
|
345
|
+
├── bin/
|
|
346
|
+
│ └── rockcli.js # CLI 主入口
|
|
347
|
+
└── package.json # 包配置
|
|
348
|
+
|
|
349
|
+
(引用上层目录的共享代码)
|
|
350
|
+
├── commands/ # 命令模块
|
|
351
|
+
├── sdks/ # SDK 客户端
|
|
352
|
+
└── utils/ # 工具类
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### 本地开发
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
# 克隆项目
|
|
359
|
+
git clone <repository-url>
|
|
360
|
+
|
|
361
|
+
# 安装依赖
|
|
362
|
+
npm install
|
|
363
|
+
|
|
364
|
+
# 本地链接
|
|
365
|
+
npm link
|
|
366
|
+
|
|
367
|
+
# 测试命令
|
|
368
|
+
rockcli --help
|
|
369
|
+
rockcli sandbox --help
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## 相关资源
|
|
373
|
+
|
|
374
|
+
- GitHub: https://github.com/your-org/rock-cli
|
|
375
|
+
- 文档: https://rock-cli.example.com/docs
|
|
376
|
+
- 问题反馈: https://github.com/your-org/rock-cli/issues
|
|
377
|
+
|
|
378
|
+
## 许可证
|
|
379
|
+
|
|
380
|
+
MIT License
|
|
381
|
+
|
|
382
|
+
Copyright (c) 2026 ROCK CLI Contributors
|
|
383
|
+
|
|
384
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
385
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
386
|
+
in the Software without restriction, including without limitation the rights
|
|
387
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
388
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
389
|
+
furnished to do so, subject to the following conditions:
|
|
390
|
+
|
|
391
|
+
The above copyright notice and this permission notice shall be included in all
|
|
392
|
+
copies or substantial portions of the Software.
|
|
393
|
+
|
|
394
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
395
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
396
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
397
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
398
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
399
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
400
|
+
SOFTWARE.
|
package/index.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* rl-rockcli - Open Source ROCK CLI Entry Point
|
|
5
|
+
*
|
|
6
|
+
* 这是开源版本的入口文件,它会:
|
|
7
|
+
* 1. 设置 ROCKCLI_MODE=opensource 环境变量
|
|
8
|
+
* 2. **只引用 Core 命令**(不引用 Internal)
|
|
9
|
+
* 3. 过滤掉内网专有功能
|
|
10
|
+
*/
|
|
7
11
|
|
|
8
|
-
//
|
|
12
|
+
// 强制设置开源模式(在任何 require 之前)
|
|
9
13
|
process.env.ROCKCLI_MODE = 'opensource';
|
|
10
14
|
|
|
15
|
+
// 开源版默认配置
|
|
16
|
+
if (!process.env.ROCKCLI_BASE_URL) {
|
|
17
|
+
process.env.ROCKCLI_BASE_URL = 'http://127.0.0.1:8080'; // 本地开发环境
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
const yargs = require('yargs/yargs');
|
|
12
21
|
const { hideBin } = require('yargs/helpers');
|
|
13
|
-
const logCommand = require('./commands/log');
|
|
14
|
-
const sandboxCommand = require('./commands/sandbox');
|
|
15
22
|
|
|
23
|
+
// ⚠️ 关键:只引用 Core 命令,不引用 Internal
|
|
24
|
+
// 这确保打包时不会包含内网代码
|
|
25
|
+
const logCommand = require('../commands/log'); // 已支持 ROCKCLI_MODE 过滤
|
|
26
|
+
const sandboxCommand = require('../commands/sandbox'); // 已支持 ROCKCLI_MODE 过滤
|
|
27
|
+
|
|
28
|
+
// ASCII Art Logo
|
|
16
29
|
const LOGO = `
|
|
17
30
|
██████╗ ██████╗ ██████╗██╗ ██╗ ██████╗██╗ ██╗
|
|
18
31
|
██╔══██╗██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██║ ██║
|
|
@@ -20,19 +33,36 @@ const LOGO = `
|
|
|
20
33
|
██╔══██╗██║ ██║██║ ██╔═██╗ ██║ ██║ ██║
|
|
21
34
|
██║ ██║╚██████╔╝╚██████╗██║ ██╗╚██████╗███████╗██║
|
|
22
35
|
╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝╚══════╝╚═╝
|
|
23
|
-
Open Source
|
|
24
36
|
`;
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
function run() {
|
|
39
|
+
const cli = yargs(hideBin(process.argv));
|
|
40
|
+
|
|
41
|
+
cli
|
|
42
|
+
.scriptName('rockcli')
|
|
43
|
+
.usage(LOGO + '\n\nUsage: $0 <command> [options]')
|
|
44
|
+
.command(logCommand)
|
|
45
|
+
.command(sandboxCommand)
|
|
46
|
+
.demandCommand(1, '请提供一个有效的命令。使用 --help 查看可用命令。')
|
|
47
|
+
.strict()
|
|
48
|
+
.alias('h', 'help')
|
|
49
|
+
.alias('v', 'version')
|
|
50
|
+
.version(require('./package.json').version)
|
|
51
|
+
.help()
|
|
52
|
+
.epilogue(`
|
|
53
|
+
环境变量:
|
|
54
|
+
ROCKCLI_API_KEY - API 密钥(用于认证)
|
|
55
|
+
ROCKCLI_BASE_URL - 沙箱服务地址(默认: http://127.0.0.1:8080)
|
|
56
|
+
ROCKCLI_LOG_LEVEL - 日志级别(debug/info/warn/error)
|
|
57
|
+
|
|
58
|
+
文档: https://github.com/rock-cli/rockcli
|
|
59
|
+
`);
|
|
60
|
+
|
|
61
|
+
if (typeof cli.terminalWidth === 'function') {
|
|
62
|
+
cli.wrap(cli.terminalWidth());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
cli.parse();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
run();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rl-rockcli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Open-source ROCK CLI - Sandbox and Log management tool",
|
|
5
5
|
"bin": {
|
|
6
6
|
"rockcli": "./index.js"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"sdks/",
|
|
14
14
|
"help/",
|
|
15
15
|
"lib/",
|
|
16
|
+
"README.md",
|
|
16
17
|
"package.json"
|
|
17
18
|
],
|
|
18
19
|
"scripts": {
|
|
@@ -45,4 +46,4 @@
|
|
|
45
46
|
"registry": "https://registry.npmjs.org",
|
|
46
47
|
"access": "public"
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
|
+
}
|