rl-rockcli 0.0.2 → 0.0.3

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.
Files changed (75) hide show
  1. package/README.md +400 -0
  2. package/index.js +51 -21
  3. package/package.json +1 -1
  4. package/commands/log/core/constants.js +0 -237
  5. package/commands/log/core/display.js +0 -370
  6. package/commands/log/core/search.js +0 -330
  7. package/commands/log/core/tail.js +0 -216
  8. package/commands/log/core/utils.js +0 -424
  9. package/commands/log.js +0 -298
  10. package/commands/sandbox/core/log-bridge.js +0 -119
  11. package/commands/sandbox/core/replay/analyzer.js +0 -311
  12. package/commands/sandbox/core/replay/batch-orchestrator.js +0 -536
  13. package/commands/sandbox/core/replay/batch-task.js +0 -369
  14. package/commands/sandbox/core/replay/concurrent-display.js +0 -70
  15. package/commands/sandbox/core/replay/concurrent-orchestrator.js +0 -170
  16. package/commands/sandbox/core/replay/data-source.js +0 -86
  17. package/commands/sandbox/core/replay/display.js +0 -231
  18. package/commands/sandbox/core/replay/executor.js +0 -634
  19. package/commands/sandbox/core/replay/history-fetcher.js +0 -124
  20. package/commands/sandbox/core/replay/index.js +0 -338
  21. package/commands/sandbox/core/replay/loghouse-data-source.js +0 -177
  22. package/commands/sandbox/core/replay/pid-mapping.js +0 -26
  23. package/commands/sandbox/core/replay/request.js +0 -109
  24. package/commands/sandbox/core/replay/worker.js +0 -166
  25. package/commands/sandbox/core/session.js +0 -346
  26. package/commands/sandbox/log-bridge.js +0 -2
  27. package/commands/sandbox/ray.js +0 -2
  28. package/commands/sandbox/replay/analyzer.js +0 -311
  29. package/commands/sandbox/replay/batch-orchestrator.js +0 -536
  30. package/commands/sandbox/replay/batch-task.js +0 -369
  31. package/commands/sandbox/replay/concurrent-display.js +0 -70
  32. package/commands/sandbox/replay/concurrent-orchestrator.js +0 -170
  33. package/commands/sandbox/replay/display.js +0 -231
  34. package/commands/sandbox/replay/executor.js +0 -634
  35. package/commands/sandbox/replay/history-fetcher.js +0 -118
  36. package/commands/sandbox/replay/index.js +0 -338
  37. package/commands/sandbox/replay/pid-mapping.js +0 -26
  38. package/commands/sandbox/replay/request.js +0 -109
  39. package/commands/sandbox/replay/worker.js +0 -166
  40. package/commands/sandbox/replay.js +0 -2
  41. package/commands/sandbox/session.js +0 -2
  42. package/commands/sandbox-original.js +0 -1393
  43. package/commands/sandbox.js +0 -499
  44. package/help/help.json +0 -1071
  45. package/help/middleware.js +0 -71
  46. package/help/renderer.js +0 -800
  47. package/lib/plugin-context.js +0 -40
  48. package/sdks/sandbox/core/client.js +0 -845
  49. package/sdks/sandbox/core/config.js +0 -70
  50. package/sdks/sandbox/core/types.js +0 -74
  51. package/sdks/sandbox/httpLogger.js +0 -251
  52. package/sdks/sandbox/index.js +0 -9
  53. package/utils/asciiArt.js +0 -138
  54. package/utils/bun-compat.js +0 -59
  55. package/utils/ciPipelines.js +0 -138
  56. package/utils/cli.js +0 -17
  57. package/utils/command-router.js +0 -79
  58. package/utils/configManager.js +0 -503
  59. package/utils/dependency-resolver.js +0 -135
  60. package/utils/eagleeye_traceid.js +0 -151
  61. package/utils/envDetector.js +0 -78
  62. package/utils/execution_logger.js +0 -415
  63. package/utils/featureManager.js +0 -68
  64. package/utils/firstTimeTip.js +0 -44
  65. package/utils/hook-manager.js +0 -125
  66. package/utils/http-logger.js +0 -264
  67. package/utils/i18n.js +0 -139
  68. package/utils/image-progress.js +0 -159
  69. package/utils/logger.js +0 -154
  70. package/utils/plugin-loader.js +0 -124
  71. package/utils/plugin-manager.js +0 -348
  72. package/utils/ray_cli_wrapper.js +0 -746
  73. package/utils/sandbox-client.js +0 -419
  74. package/utils/terminal.js +0 -32
  75. package/utils/tips.js +0 -106
package/commands/log.js DELETED
@@ -1,298 +0,0 @@
1
- const logger = require('../utils/logger');
2
- const { handleLogSearch } = require('./log/core/search');
3
- const { handleLogTail } = require('./log/core/tail');
4
- const { FIELD_COMPLETION_LIST } = require('./log/core/constants');
5
- const { gracefulExit } = require('../utils/execution_logger');
6
-
7
- // 条件引用:内网专有功能(开源版不存在)
8
- let handleLogTrace, handleLogHistory;
9
- try {
10
- handleLogTrace = require('./log/internal/trace').handleLogTrace;
11
- handleLogHistory = require('./log/internal/history').handleLogHistory;
12
- } catch (e) {
13
- // 开源版:无 trace 和 history 功能
14
- handleLogTrace = null;
15
- handleLogHistory = null;
16
- }
17
-
18
- const isOpenSource = process.env.ROCKCLI_MODE === 'opensource';
19
- const CORE_ACTIONS = ['search', 'tail'];
20
- const ALL_ACTIONS = ['search', 'tail', 'trace', 'history'];
21
- const ACTIONS = isOpenSource ? CORE_ACTIONS : ALL_ACTIONS;
22
-
23
- // Log command module for yargs
24
- module.exports = {
25
- command: 'log <action> [sandboxId]',
26
- describe: isOpenSource ? 'Log operations (search, tail)' : 'Log operations (search, tail, trace, history)',
27
- builder: (yargs) => {
28
- return yargs
29
- .positional('action', {
30
- describe: 'Log action to perform',
31
- type: 'string',
32
- choices: ACTIONS,
33
- })
34
- .positional('sandboxId', {
35
- describe: 'Sandbox ID (equivalent to --sandbox-id)',
36
- type: 'string',
37
- })
38
- .option('keyword', {
39
- alias: 'k',
40
- describe: 'Search keyword',
41
- type: 'string',
42
- group: 'Command Options:'
43
- })
44
- .option('field', {
45
- alias: 'f',
46
- describe: 'Search by field name and value (format: field=value or field!=value for negation, can be specified multiple times)',
47
- type: 'array',
48
- group: 'Command Options:',
49
- completion: (current, argv) => {
50
- // 返回所有字段列表作为补全建议
51
- return FIELD_COMPLETION_LIST;
52
- }
53
- })
54
- .option('query', {
55
- alias: 'q',
56
- describe: 'Direct query_string content (overrides --keyword and --field)',
57
- type: 'string',
58
- group: 'Command Options:'
59
- })
60
- .option('sandbox-id', {
61
- describe: 'Filter by sandbox ID (searches both sandbox_id field and @filename)',
62
- type: 'string',
63
- group: 'Command Options:'
64
- })
65
- .option('log-file', {
66
- describe: 'Specify log file name (used with --sandbox-id, e.g., command.log)',
67
- type: 'string',
68
- group: 'Command Options:'
69
- })
70
- .option('start-time', {
71
- alias: 's',
72
- describe: 'Start time (supports timestamps, relative time like "15m", "1h", "2d", or ISO date)',
73
- type: 'string',
74
- group: 'Command Options:'
75
- })
76
- .option('end-time', {
77
- alias: 'e',
78
- describe: 'End time (supports same formats as start-time, defaults to current time)',
79
- type: 'string',
80
- group: 'Command Options:'
81
- })
82
- .option('minutes', {
83
- alias: 'm',
84
- describe: 'Search logs from last N minutes (overrides start-time and end-time)',
85
- type: 'number',
86
- default: 15,
87
- group: 'Command Options:'
88
- })
89
- .option('limit', {
90
- alias: 'l',
91
- describe: 'Limit number of results returned',
92
- type: 'number',
93
- default: 100,
94
- group: 'Command Options:'
95
- })
96
- .option('offset', {
97
- alias: 'o',
98
- describe: 'Number of logs to skip before returning results (default: 0)',
99
- type: 'number',
100
- default: 0,
101
- group: 'Command Options:'
102
- })
103
- .option('raw', {
104
- describe: 'Display raw output (flatten to single line, use \\n for newlines)',
105
- type: 'boolean',
106
- default: false,
107
- group: 'Command Options:'
108
- })
109
- .option('log-format', {
110
- describe: 'Output format (logfmt, json, or columns)',
111
- type: 'string',
112
- default: 'logfmt',
113
- group: 'Command Options:'
114
- })
115
- .option('columns', {
116
- describe: 'Filter fields to display (comma-separated, e.g., message,time). Works with all formats.',
117
- type: 'string',
118
- group: 'Command Options:'
119
- })
120
- .option('multilines', {
121
- describe: 'Remove escape characters and display multi-line logs with separators',
122
- type: 'boolean',
123
- default: false,
124
- group: 'Command Options:'
125
- })
126
- .option('truncate', {
127
- describe: 'Truncate long field values (default: 2048 for message/content/event, 0 to disable)',
128
- type: 'number',
129
- default: 2048,
130
- group: 'Command Options:'
131
- })
132
- .option('count', {
133
- describe: 'Only display the count of matching logs',
134
- type: 'boolean',
135
- default: false,
136
- group: 'Command Options:'
137
- })
138
- .option('highlight', {
139
- describe: 'Enable field name color highlighting (default: true)',
140
- type: 'boolean',
141
- default: true,
142
- group: 'Command Options:'
143
- })
144
- .option('debug', {
145
- describe: 'Enable debug mode to display SQL query',
146
- type: 'boolean',
147
- default: false,
148
- group: 'Command Options:'
149
- })
150
- .option('after-context', {
151
- alias: 'A',
152
- describe: 'Show n lines after each match (requires --sandbox-id, --log-file, and -k)',
153
- type: 'number',
154
- group: 'Command Options:'
155
- })
156
- .option('before-context', {
157
- alias: 'B',
158
- describe: 'Show n lines before each match (requires --sandbox-id, --log-file, and -k)',
159
- type: 'number',
160
- group: 'Command Options:'
161
- })
162
- .option('context', {
163
- alias: 'C',
164
- describe: 'Show n lines before and after each match (requires --sandbox-id, --log-file, and -k)',
165
- type: 'number',
166
- group: 'Command Options:'
167
- })
168
- .option('group-by', {
169
- describe: 'Group logs by specified fields (comma-separated, e.g., file,ip,app,hostname,cluster). Available: file(@filename), ip(@source), app(@app_group), hostname(@hostname), cluster(_cluster)',
170
- type: 'array',
171
- group: 'Command Options:'
172
- })
173
- .option('cluster', {
174
- alias: 'c',
175
- describe: 'Filter by cluster name (e.g., zb-a, zb-b, nt-c, etc.)',
176
- type: 'string',
177
- group: 'Command Options:'
178
- })
179
- .option('interval', {
180
- alias: 'i',
181
- describe: 'Scan interval in seconds for tail mode (default: 5)',
182
- type: 'number',
183
- default: 5,
184
- group: 'Command Options:'
185
- })
186
- .option('n', {
187
- describe: 'Number of recent log lines to display initially in tail mode (default: 10)',
188
- type: 'number',
189
- default: 10,
190
- group: 'Command Options:'
191
- });
192
-
193
- // 内网专有选项
194
- if (!isOpenSource) {
195
- yargs
196
- .option('key', {
197
- describe: 'Key to filter sandboxes (for trace command)',
198
- type: 'string',
199
- group: 'Command Options:'
200
- })
201
- .option('user-id', {
202
- describe: 'User ID to filter sandboxes (for trace command)',
203
- type: 'string',
204
- group: 'Command Options:'
205
- })
206
- .option('top', {
207
- describe: 'Number of logs to display in trace mode (default: 100)',
208
- type: 'number',
209
- default: 100,
210
- group: 'Command Options:'
211
- })
212
- .option('full', {
213
- describe: 'Show all logs (for history command)',
214
- type: 'boolean',
215
- default: false,
216
- })
217
- .option('uris', {
218
- describe: 'Filter logs by URI patterns (comma-separated or multiple --uris). Use ! prefix to exclude (e.g., !get_status)',
219
- type: 'array',
220
- })
221
- .option('dump', {
222
- describe: 'Export sandbox history as JSON format for replay',
223
- type: 'boolean',
224
- default: false,
225
- });
226
- }
227
-
228
- return yargs
229
- .example(isOpenSource ? [
230
- ['$0 log search -k "error" -m 15', 'Search logs for "error" in last 15 minutes'],
231
- ['$0 log tail -k "error"', 'Tail logs in real-time'],
232
- ] : [
233
- ['$0 log search -k "error" -m 15', 'Search logs for "error" in last 15 minutes'],
234
- ['$0 log tail -k "error"', 'Tail logs in real-time'],
235
- ['$0 log trace --key "test-key"', 'Trace sandboxes with key'],
236
- ['$0 log history c55e3674e4e94709859550257c998b27', 'Display sandbox execution history'],
237
- ['$0 log history c55e3674e4e94709859550257c998b27 --dump', 'Export sandbox history as JSON'],
238
- ])
239
- .check((argv) => {
240
- if (argv.action === 'trace') {
241
- if (!argv.key && !argv.userId) {
242
- throw new Error('For trace command, at least one of --key or --user-id must be specified');
243
- }
244
- return true;
245
- }
246
-
247
- if (argv.action === 'history') {
248
- if (!argv.sandboxId && !argv['sandbox-id']) {
249
- throw new Error('For history command, sandbox ID is required');
250
- }
251
- return true;
252
- }
253
-
254
- if (!argv.keyword && !argv.field && !argv.query && !argv.sandboxId) {
255
- throw new Error('At least one of --keyword, --field, --query, or --sandbox-id must be specified');
256
- }
257
- if (!argv.minutes && !argv.startTime && !argv.endTime) {
258
- throw new Error('At least one of --minutes, --start-time, or --end-time must be specified');
259
- }
260
-
261
- if (argv.afterContext !== undefined || argv.beforeContext !== undefined || argv.context !== undefined) {
262
- const hasSandboxId = !!argv.sandboxId || !!argv['sandbox-id'];
263
- const hasLogFile = !!argv.logFile || !!argv['log-file'];
264
- const hasKeyword = !!argv.keyword;
265
-
266
- if (!hasSandboxId || !hasLogFile || !hasKeyword) {
267
- throw new Error('Context options (-A, -B, -C) require --sandbox-id, --log-file, and -k to be specified');
268
- }
269
- }
270
- return true;
271
- });
272
- },
273
- handler: async (argv) => {
274
- if (isOpenSource && !CORE_ACTIONS.includes(argv.action)) {
275
- logger.error(`Action ${argv.action} is not available in open source mode`);
276
- gracefulExit(1);
277
- return;
278
- }
279
-
280
- switch (argv.action) {
281
- case 'search':
282
- await handleLogSearch(argv);
283
- break;
284
- case 'tail':
285
- await handleLogTail(argv);
286
- break;
287
- case 'trace':
288
- await handleLogTrace(argv);
289
- break;
290
- case 'history':
291
- await handleLogHistory(argv);
292
- break;
293
- default:
294
- logger.error(`Unknown log action: ${argv.action}`);
295
- gracefulExit(1);
296
- }
297
- },
298
- };
@@ -1,119 +0,0 @@
1
- /**
2
- * Log Bridge Module
3
- * Bridges sandbox log commands to loghouse plugin commands
4
- */
5
-
6
- // 动态加载 loghouse 插件的处理器
7
- function getLogHandlers() {
8
- const { handleLogSearch } = require('../../../plugins/loghouse/commands/search');
9
- const { handleLogTail } = require('../../../plugins/loghouse/commands/tail');
10
- return { handleLogSearch, handleLogTail };
11
- }
12
-
13
- /**
14
- * Handle sandbox log search command
15
- * Equivalent to: log search --sandbox-id <id> [options]
16
- */
17
- async function handleSandboxLogSearch(argv) {
18
- const sandboxId = argv.sandboxId || argv.id;
19
-
20
- if (!sandboxId) {
21
- throw new Error('Sandbox ID is required');
22
- }
23
-
24
- const { handleLogSearch } = getLogHandlers();
25
-
26
- // Transform argv to match log search format
27
- const logSearchArgs = {
28
- ...argv,
29
- sandboxId: sandboxId,
30
- minutes: argv.minutes || 15, // Default to 15 minutes
31
- };
32
-
33
- // Call log search handler
34
- return handleLogSearch(logSearchArgs);
35
- }
36
-
37
- /**
38
- * Handle sandbox log tail command
39
- * Equivalent to: log tail --sandbox-id <id> [options]
40
- */
41
- async function handleSandboxLogTail(argv) {
42
- const sandboxId = argv.sandboxId || argv.id;
43
-
44
- if (!sandboxId) {
45
- throw new Error('Sandbox ID is required');
46
- }
47
-
48
- const { handleLogSearch, handleLogTail } = getLogHandlers();
49
-
50
- // Support Linux tail-style parameters
51
- // -f or --follow: follow mode (continuously monitor logs)
52
- // -n or --lines: number of recent lines to display
53
- // -s or --sleep-interval: refresh interval in seconds (only for follow mode)
54
- // -q or --quiet: hide internal fields (timestamp, time_iso8601, etc.)
55
- const followMode = argv.f || argv.follow;
56
- const quietMode = argv.q || argv.quiet;
57
- const lines = argv.n || argv.lines;
58
- const sleepInterval = argv.s || argv['sleep-interval'];
59
-
60
- // Default columns for tail mode (hide internal fields)
61
- const DEFAULT_TAIL_COLUMNS = [
62
- 'level',
63
- 'sandbox_id',
64
- 'trace_id',
65
- 'logger',
66
- 'method',
67
- 'message',
68
- 'request',
69
- 'response',
70
- 'content',
71
- 'event',
72
- 'exception'
73
- ];
74
-
75
- // Determine which columns to display
76
- let columns = argv.columns;
77
- if (!columns) {
78
- // In quiet mode or by default, use filtered columns
79
- if (quietMode) {
80
- // Quiet mode: hide most metadata, only show essential fields
81
- columns = DEFAULT_TAIL_COLUMNS.join(',');
82
- } else {
83
- // Default: use the standard log display (all fields except @ fields)
84
- columns = undefined;
85
- }
86
- }
87
-
88
- if (!followMode) {
89
- // Without -f flag, just show recent logs and exit (like Linux tail)
90
- // Use log search to get recent logs
91
- const logSearchArgs = {
92
- ...argv,
93
- sandboxId: sandboxId,
94
- minutes: 60, // Search last 60 minutes
95
- limit: lines || 10, // Use -n or default 10 lines
96
- columns: columns,
97
- };
98
-
99
- // Call log search handler
100
- return handleLogSearch(logSearchArgs);
101
- }
102
-
103
- // Transform argv to match log tail format
104
- const logTailArgs = {
105
- ...argv,
106
- sandboxId: sandboxId,
107
- n: lines || argv.n, // Support both -n and --lines
108
- interval: followMode ? (sleepInterval || argv.interval || 5) : undefined, // Only set interval in follow mode
109
- columns: columns,
110
- };
111
-
112
- // Call log tail handler
113
- return handleLogTail(logTailArgs);
114
- }
115
-
116
- module.exports = {
117
- handleSandboxLogSearch,
118
- handleSandboxLogTail,
119
- };