rl-rockcli 0.0.6 → 0.0.8

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 (74) hide show
  1. package/index.js +51 -20
  2. package/package.json +2 -2
  3. package/commands/log/core/constants.js +0 -237
  4. package/commands/log/core/display.js +0 -370
  5. package/commands/log/core/search.js +0 -330
  6. package/commands/log/core/tail.js +0 -216
  7. package/commands/log/core/utils.js +0 -424
  8. package/commands/log.js +0 -298
  9. package/commands/sandbox/core/log-bridge.js +0 -119
  10. package/commands/sandbox/core/replay/analyzer.js +0 -311
  11. package/commands/sandbox/core/replay/batch-orchestrator.js +0 -536
  12. package/commands/sandbox/core/replay/batch-task.js +0 -369
  13. package/commands/sandbox/core/replay/concurrent-display.js +0 -70
  14. package/commands/sandbox/core/replay/concurrent-orchestrator.js +0 -170
  15. package/commands/sandbox/core/replay/data-source.js +0 -86
  16. package/commands/sandbox/core/replay/display.js +0 -231
  17. package/commands/sandbox/core/replay/executor.js +0 -634
  18. package/commands/sandbox/core/replay/history-fetcher.js +0 -124
  19. package/commands/sandbox/core/replay/index.js +0 -338
  20. package/commands/sandbox/core/replay/loghouse-data-source.js +0 -177
  21. package/commands/sandbox/core/replay/pid-mapping.js +0 -26
  22. package/commands/sandbox/core/replay/request.js +0 -109
  23. package/commands/sandbox/core/replay/worker.js +0 -166
  24. package/commands/sandbox/core/session.js +0 -346
  25. package/commands/sandbox/log-bridge.js +0 -2
  26. package/commands/sandbox/ray.js +0 -2
  27. package/commands/sandbox/replay/analyzer.js +0 -311
  28. package/commands/sandbox/replay/batch-orchestrator.js +0 -536
  29. package/commands/sandbox/replay/batch-task.js +0 -369
  30. package/commands/sandbox/replay/concurrent-display.js +0 -70
  31. package/commands/sandbox/replay/concurrent-orchestrator.js +0 -170
  32. package/commands/sandbox/replay/display.js +0 -231
  33. package/commands/sandbox/replay/executor.js +0 -634
  34. package/commands/sandbox/replay/history-fetcher.js +0 -118
  35. package/commands/sandbox/replay/index.js +0 -338
  36. package/commands/sandbox/replay/pid-mapping.js +0 -26
  37. package/commands/sandbox/replay/request.js +0 -109
  38. package/commands/sandbox/replay/worker.js +0 -166
  39. package/commands/sandbox/replay.js +0 -2
  40. package/commands/sandbox/session.js +0 -2
  41. package/commands/sandbox-original.js +0 -1393
  42. package/commands/sandbox.js +0 -499
  43. package/help/help.json +0 -1071
  44. package/help/middleware.js +0 -71
  45. package/help/renderer.js +0 -800
  46. package/lib/plugin-context.js +0 -40
  47. package/sdks/sandbox/core/client.js +0 -845
  48. package/sdks/sandbox/core/config.js +0 -70
  49. package/sdks/sandbox/core/types.js +0 -74
  50. package/sdks/sandbox/httpLogger.js +0 -251
  51. package/sdks/sandbox/index.js +0 -9
  52. package/utils/asciiArt.js +0 -138
  53. package/utils/bun-compat.js +0 -59
  54. package/utils/ciPipelines.js +0 -138
  55. package/utils/cli.js +0 -17
  56. package/utils/command-router.js +0 -79
  57. package/utils/configManager.js +0 -503
  58. package/utils/dependency-resolver.js +0 -135
  59. package/utils/eagleeye_traceid.js +0 -151
  60. package/utils/envDetector.js +0 -78
  61. package/utils/execution_logger.js +0 -415
  62. package/utils/featureManager.js +0 -68
  63. package/utils/firstTimeTip.js +0 -44
  64. package/utils/hook-manager.js +0 -125
  65. package/utils/http-logger.js +0 -264
  66. package/utils/i18n.js +0 -139
  67. package/utils/image-progress.js +0 -159
  68. package/utils/logger.js +0 -154
  69. package/utils/plugin-loader.js +0 -124
  70. package/utils/plugin-manager.js +0 -348
  71. package/utils/ray_cli_wrapper.js +0 -746
  72. package/utils/sandbox-client.js +0 -419
  73. package/utils/terminal.js +0 -32
  74. package/utils/tips.js +0 -106
@@ -1,499 +0,0 @@
1
- const { SandboxClient, SandboxConfig } = require('../utils/sandbox-client');
2
- const fs = require('fs-extra');
3
- const path = require('path');
4
- const logger = require('../utils/logger');
5
- const { routeSandboxCommand, showDeprecatedWarning } = require('../utils/command-router');
6
- const { handleSandboxLogSearch, handleSandboxLogTail } = require('./sandbox/log-bridge');
7
- const { gracefulExit } = require('../utils/execution_logger');
8
- const configManager = require('../utils/configManager');
9
- const { printNextStep, TIPS } = require('../utils/tips');
10
-
11
- const isOpenSource = process.env.ROCKCLI_MODE === 'opensource';
12
- const DEFAULT_OPEN_SOURCE_BASE_URL = 'http://127.0.0.1:8080';
13
- const DEFAULT_OPEN_SOURCE_IMAGE = 'python:3.11';
14
-
15
- // Import existing sandbox.js handlers
16
- const sandboxOriginal = require('./sandbox-original');
17
-
18
- /**
19
- * 读取配置文件中的 sandbox 配置
20
- * @param {Object} argv - Command line arguments
21
- * @returns {Object} - Sandbox config with proper priority for all parameters
22
- */
23
- function readSandboxConfig(argv = {}) {
24
- const config = configManager.readConfig();
25
- const sandboxConfig = config?.sandbox || {};
26
- const envBaseUrl = process.env.ROCKCLI_BASE_URL;
27
-
28
- const baseUrl =
29
- argv.baseUrl ||
30
- envBaseUrl ||
31
- sandboxConfig.base_url ||
32
- (isOpenSource ? DEFAULT_OPEN_SOURCE_BASE_URL : 'http://127.0.0.1:8080');
33
-
34
- // Get default image from internal config or use open source default
35
- let defaultImage;
36
- if (isOpenSource) {
37
- defaultImage = DEFAULT_OPEN_SOURCE_IMAGE;
38
- } else {
39
- const { getInternalSandboxConfig } = require('../sdks/sandbox/core/config');
40
- const internalDefaults = getInternalSandboxConfig();
41
- defaultImage = internalDefaults.image;
42
- }
43
-
44
- return {
45
- base_url: baseUrl,
46
- image: defaultImage,
47
- api_key: configManager.getApiKeyWithPriority(argv),
48
- cluster: configManager.getClusterWithPriority(argv),
49
- user_id: configManager.getUserIdWithPriority(argv),
50
- experiment_id: configManager.getExperimentIdWithPriority(argv),
51
- };
52
- }
53
-
54
- // Sandbox command module for yargs - NEW FORMAT
55
- const sandboxExports = module.exports = {
56
- command: 'sandbox [id] [command]',
57
- describe: 'Sandbox instance management',
58
- builder: (yargs) => {
59
- return yargs
60
- .positional('id', {
61
- describe: 'Sandbox ID (for operations on existing sandbox)',
62
- type: 'string',
63
- })
64
- .positional('command', {
65
- describe: 'Sandbox command to perform',
66
- type: 'string',
67
- })
68
- .strict(false) // Allow unknown options (they will be passed to subcommands like log search)
69
- .option('api-key', {
70
- describe: 'API key for authentication',
71
- type: 'string',
72
- group: 'Command Options:'
73
- })
74
- .option('base-url', {
75
- describe: 'Base URL for sandbox service',
76
- type: 'string',
77
- group: 'Command Options:'
78
- })
79
- .option('image', {
80
- describe: 'Docker image to use',
81
- type: 'string',
82
- group: 'Command Options:'
83
- })
84
- .option('memory', {
85
- describe: 'Memory limit',
86
- type: 'string',
87
- default: '8g',
88
- group: 'Command Options:'
89
- })
90
- .option('cpus', {
91
- describe: 'CPU limit',
92
- type: 'number',
93
- default: 2.0,
94
- group: 'Command Options:'
95
- })
96
- .option('timeout', {
97
- describe: 'Startup timeout in seconds',
98
- type: 'number',
99
- default: 120,
100
- group: 'Command Options:'
101
- })
102
- .option('auto-clear', {
103
- describe: 'Auto clear time in seconds',
104
- type: 'number',
105
- default: 300,
106
- group: 'Command Options:'
107
- })
108
- .option('cluster', {
109
- alias: 'c',
110
- describe: 'Cluster ID (sets X-Cluster header)',
111
- type: 'string',
112
- group: 'Command Options:'
113
- })
114
- .option('experiment-id', {
115
- describe: 'Experiment ID (sets X-Experiment-Id header)',
116
- type: 'string',
117
- group: 'Command Options:'
118
- })
119
- .option('user-id', {
120
- describe: 'User ID (sets X-User-Id header)',
121
- type: 'string',
122
- group: 'Command Options:'
123
- })
124
- .option('extra-header', {
125
- alias: 'H',
126
- type: 'array',
127
- description: 'Extra HTTP headers in format "Key=value". Can be used multiple times.',
128
- group: 'Command Options:',
129
- coerce: (headers) => {
130
- const result = {};
131
- if (headers) {
132
- headers.forEach(header => {
133
- if (header.includes('=')) {
134
- const [key, value] = header.split('=', 2);
135
- result[key.trim()] = value.trim();
136
- } else {
137
- logger.warn(`Invalid header format: ${header}. Expected format: 'Key=Value'`);
138
- }
139
- });
140
- }
141
- return result;
142
- }
143
- })
144
- .option('wait-for-alive', {
145
- describe: 'Wait for sandbox to be alive before returning',
146
- type: 'boolean',
147
- default: false,
148
- group: 'Command Options:'
149
- })
150
- .option('n', {
151
- alias: 'lines',
152
- describe: 'Number of recent log lines to display (default: 10)',
153
- type: 'number',
154
- default: 10,
155
- group: 'Log Options:'
156
- })
157
- .option('f', {
158
- alias: 'follow',
159
- describe: 'Follow mode: continuously monitor logs (like tail -f)',
160
- type: 'boolean',
161
- default: false,
162
- group: 'Log Options:'
163
- })
164
- .option('sleep-interval', {
165
- alias: 'i',
166
- describe: 'Refresh interval in seconds for follow mode (default: 5)',
167
- type: 'number',
168
- default: 5,
169
- group: 'Log Options:'
170
- })
171
- .option('q', {
172
- alias: 'quiet',
173
- describe: 'Quiet mode: hide internal fields (timestamp, time_iso8601, etc.)',
174
- type: 'boolean',
175
- default: false,
176
- group: 'Log Options:'
177
- })
178
- .option('keyword', {
179
- alias: 'k',
180
- describe: 'Filter logs by keyword',
181
- type: 'string',
182
- group: 'Log Options:'
183
- })
184
- .option('log-file', {
185
- describe: 'Filter by log file name',
186
- type: 'string',
187
- group: 'Log Options:'
188
- })
189
- .option('debug', {
190
- describe: 'Enable debug mode to display SQL query',
191
- type: 'boolean',
192
- default: false,
193
- group: 'Log Options:'
194
- })
195
- .option('raw', {
196
- describe: 'Display raw output (flatten to single line)',
197
- type: 'boolean',
198
- default: false,
199
- group: 'Log Options:'
200
- })
201
- .option('multilines', {
202
- describe: 'Display multi-line logs with separators',
203
- type: 'boolean',
204
- default: false,
205
- group: 'Log Options:'
206
- })
207
- .option('highlight', {
208
- describe: 'Enable keyword highlighting (default: true)',
209
- type: 'boolean',
210
- default: true,
211
- group: 'Log Options:'
212
- })
213
- .example([
214
- ['$0 sandbox start --image python:3.11', 'Start a new sandbox'],
215
- ['$0 sandbox <id> status', 'Get sandbox status'],
216
- ['$0 sandbox <id> attach', 'Attach to sandbox (interactive REPL)'],
217
- ['$0 sandbox <id> exec -- ls -la', 'Execute command in sandbox'],
218
- ]);
219
- },
220
- handler: async (argv) => {
221
- try {
222
- // Rebuild argv._ from process.argv to preserve all original arguments
223
- // This is needed because yargs parses positional parameters separately
224
- const rawArgs = process.argv.slice(2);
225
-
226
- // Filter out options (args starting with -) from argv._
227
- // This is needed because global options like -vvv should not be treated as positional args
228
- argv._ = rawArgs.filter(arg => !arg.startsWith('-'));
229
-
230
- const commandType = routeSandboxCommand(argv);
231
-
232
- if (commandType === 'help') {
233
- const { renderHelp } = require('../help/renderer');
234
- console.log(renderHelp(['sandbox']));
235
- gracefulExit(0);
236
- return;
237
- }
238
-
239
- if (commandType === 'sandbox-start') {
240
- // Handle start command
241
- await sandboxOriginal.handler({
242
- ...argv,
243
- action: 'start'
244
- });
245
- return;
246
- }
247
-
248
- if (commandType === 'sandbox-id-first') {
249
- // Handle <id> <command> format
250
- const id = argv.id;
251
- if (!id) {
252
- console.error('Error: Sandbox ID is required');
253
- gracefulExit(1);
254
- return;
255
- }
256
-
257
- const command = argv.command;
258
- if (!command) {
259
- console.error('Error: Command is required');
260
- gracefulExit(1);
261
- return;
262
- }
263
-
264
- // Route to appropriate handler
265
- await handleIdFirstCommand(id, command, argv);
266
- return;
267
- }
268
-
269
- if (commandType === 'sandbox-session') {
270
- // Handle session commands (deprecated)
271
- showDeprecatedWarning('sandbox session', 'sandbox <id> exec --session <action>');
272
-
273
- // Use original handler for now
274
- await sandboxOriginal.handler(argv);
275
- return;
276
- }
277
-
278
- // Default: use original handler
279
- await sandboxOriginal.handler(argv);
280
-
281
- } catch (error) {
282
- if (error.response && error.response.status === 401) {
283
- logger.error('Authentication failed: Invalid or missing API key');
284
- console.error('\n💡 Please configure your API key:');
285
- console.error(' Option 1: export ROCK_API_KEY=<your-key>');
286
- console.error(' Option 2: Use --api-key flag: rc sandbox --id <id> --api-key <your-key>\n');
287
- } else {
288
- logger.error(`Sandbox action failed: ${error.message}`);
289
- }
290
- gracefulExit(1);
291
- }
292
- },
293
- };
294
-
295
- /**
296
- * Handle <id> <command> format
297
- * @param {string} id - Sandbox ID
298
- * @param {string} command - Command to execute
299
- * @param {Object} argv - Command line arguments
300
- */
301
- async function handleIdFirstCommand(id, command, argv) {
302
- // Set sandboxId in argv
303
- argv.sandboxId = id;
304
- argv.id = id;
305
-
306
- switch (command) {
307
- case 'status':
308
- await sandboxOriginal.handler({
309
- ...argv,
310
- action: 'status',
311
- sandboxId: id
312
- });
313
- break;
314
-
315
- case 'stop':
316
- await sandboxOriginal.handler({
317
- ...argv,
318
- action: 'stop',
319
- sandboxId: id
320
- });
321
- break;
322
-
323
- case 'attach':
324
- // Route to attach command
325
- const { handler: attachHandler } = require('./attach');
326
- await attachHandler({
327
- ...argv,
328
- sandboxId: id
329
- });
330
- break;
331
-
332
- case 'exec':
333
- case 'execute':
334
- // Extract command arguments from process.argv
335
- // This is needed because yargs parses options like -l separately
336
- const execRawArgs = process.argv.slice(2); // Skip 'node' and script path
337
- const execSandboxIndex = execRawArgs.indexOf('sandbox');
338
- const execIndex = execRawArgs.indexOf('exec');
339
-
340
- if (execIndex !== -1) {
341
- // Get all arguments after 'exec'
342
- const execArgs = execRawArgs.slice(execIndex + 1);
343
-
344
- // Parse --session parameter from exec args
345
- let sessionName = null;
346
- let commandArgs = [];
347
-
348
- for (let i = 0; i < execArgs.length; i++) {
349
- if (execArgs[i] === '--session' && i + 1 < execArgs.length) {
350
- sessionName = execArgs[i + 1];
351
- i++; // Skip session value
352
- } else if (execArgs[i] && !execArgs[i].startsWith('-')) {
353
- commandArgs.push(execArgs[i]);
354
- }
355
- }
356
-
357
- const command = commandArgs.join(' ');
358
-
359
- if (sessionName) {
360
- // Auto-create session before running command
361
- const sessionHandler = require('./sandbox/session');
362
-
363
- // Try to create session (ignore errors - session may already exist or sandbox may not be running)
364
- await sessionHandler.handler({
365
- ...argv,
366
- subaction: 'create',
367
- sandboxId: id,
368
- session: sessionName,
369
- envEnable: true,
370
- }).catch(() => {
371
- // Ignore errors from create
372
- });
373
-
374
- // Run command in session
375
- await sessionHandler.handler({
376
- ...argv,
377
- subaction: 'run',
378
- sandboxId: id,
379
- session: sessionName,
380
- command: command,
381
- });
382
- } else {
383
- await sandboxOriginal.handler({
384
- ...argv,
385
- action: 'execute',
386
- sandboxId: id,
387
- command: command || undefined
388
- });
389
- }
390
- } else {
391
- await sandboxOriginal.handler({
392
- ...argv,
393
- action: 'execute',
394
- sandboxId: id
395
- });
396
- }
397
- break;
398
-
399
- case 'upload':
400
- await sandboxOriginal.handler({
401
- ...argv,
402
- action: 'upload',
403
- sandboxId: id
404
- });
405
- break;
406
-
407
- case 'download':
408
- await sandboxOriginal.handler({
409
- ...argv,
410
- action: 'download',
411
- sandboxId: id
412
- });
413
- break;
414
-
415
- case 'history':
416
- // History is the same as log history
417
- const { handleLogHistory } = require('./log/history');
418
- await handleLogHistory({
419
- ...argv,
420
- sandboxId: id
421
- });
422
- break;
423
-
424
- case 'log':
425
- // Log operations require additional handling
426
- const logSubcommand = argv._[argv._.indexOf('log') + 1];
427
-
428
- // Extract additional arguments from process.argv (beyond yargs parsing)
429
- const rawArgs = process.argv.slice(2);
430
- const sandboxIndex = rawArgs.indexOf('sandbox');
431
-
432
- // Find the log file name (first non-option argument after 'log' or after 'tail')
433
- let logFile = null;
434
- let foundLog = false;
435
- let foundTail = false;
436
-
437
- for (let i = sandboxIndex + 1; i < rawArgs.length; i++) {
438
- const arg = rawArgs[i];
439
-
440
- if (arg === 'log') {
441
- foundLog = true;
442
- continue;
443
- }
444
-
445
- if (foundLog && arg === 'tail') {
446
- foundTail = true;
447
- continue;
448
- }
449
-
450
- if (foundTail && !arg.startsWith('-')) {
451
- logFile = arg;
452
- break;
453
- }
454
- }
455
-
456
- if (logFile) {
457
- argv.logFile = logFile;
458
- }
459
-
460
- if (logSubcommand === 'search') {
461
- await handleSandboxLogSearch({
462
- ...argv,
463
- sandboxId: id
464
- });
465
- } else if (logSubcommand === 'tail') {
466
- await handleSandboxLogTail({
467
- ...argv,
468
- sandboxId: id
469
- });
470
- } else {
471
- console.error(`错误:缺少 log 子命令\n`);
472
- console.error(`可用的子命令:`);
473
- console.error(` search - 搜索日志`);
474
- console.error(` tail - 实时监控日志\n`);
475
- console.error(`使用示例:`);
476
- console.error(` rockcli sandbox ${id} log search -k "error"`);
477
- console.error(` rockcli sandbox ${id} log tail -f\n`);
478
- console.error(`查看帮助:`);
479
- console.error(` rockcli sandbox --help`);
480
- gracefulExit(1);
481
- }
482
- break;
483
-
484
- default:
485
- console.error(`Unknown command: ${command}`);
486
- gracefulExit(1);
487
- }
488
- }
489
-
490
- // Export internal functions for testing
491
- sandboxExports.readSandboxConfig = readSandboxConfig;
492
-
493
- // Re-export functions from backup module for backward compatibility
494
- if (sandboxOriginal.getRemoteFileList) {
495
- sandboxExports.getRemoteFileList = sandboxOriginal.getRemoteFileList;
496
- }
497
- if (sandboxOriginal.validateAuth) {
498
- sandboxExports.validateAuth = sandboxOriginal.validateAuth;
499
- }