rl-rockcli 0.0.13 → 0.0.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/commands/attach/ink-repl/InkREPL.js +19 -0
- package/commands/attach/ink-repl/builtinCommands.js +29 -86
- package/commands/attach/opentui-repl/App.tsx +15 -1
- package/commands/attach/opentui-repl/builtinCommands.ts +12 -0
- package/commands/attach/repl.js +1 -1
- package/commands/sandbox.js +29 -14
- package/help/renderer.js +55 -41
- package/index.js +0 -2
- package/package.json +1 -1
- package/utils/plugin-manager.js +78 -0
- 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/utils/plugin-manager.js
CHANGED
|
@@ -17,6 +17,12 @@ class PluginManager {
|
|
|
17
17
|
this._resolver = new DependencyResolver();
|
|
18
18
|
this._loadedPlugins = [];
|
|
19
19
|
this._registeredCommands = [];
|
|
20
|
+
this._registeredAttachCommands = [];
|
|
21
|
+
this._builtInAttachCommands = [
|
|
22
|
+
'status', 'sessions', 'tail', 'upload', 'download',
|
|
23
|
+
'stop', 'clear', 'stats', 'copy', 'about', 'retry', 'theme',
|
|
24
|
+
'cleanup-history', 'help', 'docs', 'bug', 'close', 'exit', 'quit', 'resume'
|
|
25
|
+
];
|
|
20
26
|
this._currentPluginMetadata = null;
|
|
21
27
|
}
|
|
22
28
|
|
|
@@ -309,6 +315,36 @@ class PluginManager {
|
|
|
309
315
|
* @param {number} code - 退出码
|
|
310
316
|
*/
|
|
311
317
|
gracefulExit,
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 注册 attach 内置命令
|
|
321
|
+
* @param {Object} commandDef - 命令定义
|
|
322
|
+
* @param {string} commandDef.name - 命令名称(不含 / 前缀)
|
|
323
|
+
* @param {string} commandDef.description - 命令描述
|
|
324
|
+
* @param {Function} commandDef.handler - 命令处理函数 (ctx, args) => Promise<{output, exitCode}>
|
|
325
|
+
*/
|
|
326
|
+
registerAttachCommand: (commandDef) => {
|
|
327
|
+
// 检查是否覆盖内置命令
|
|
328
|
+
if (this._builtInAttachCommands.includes(commandDef.name)) {
|
|
329
|
+
throw new Error(
|
|
330
|
+
`Cannot override built-in attach command: ${commandDef.name}`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// 检查命令冲突
|
|
335
|
+
if (this._isAttachCommandRegistered(commandDef.name)) {
|
|
336
|
+
throw new Error(
|
|
337
|
+
`Attach command "${commandDef.name}" is already registered`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
this._registeredAttachCommands.push({
|
|
342
|
+
...commandDef,
|
|
343
|
+
pluginName
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
logger.debug(`Attach command registered by plugin ${pluginName}: /${commandDef.name}`);
|
|
347
|
+
},
|
|
312
348
|
};
|
|
313
349
|
}
|
|
314
350
|
|
|
@@ -328,6 +364,22 @@ class PluginManager {
|
|
|
328
364
|
return [...this._registeredCommands];
|
|
329
365
|
}
|
|
330
366
|
|
|
367
|
+
/**
|
|
368
|
+
* 检查 attach 命令是否已注册
|
|
369
|
+
* @private
|
|
370
|
+
*/
|
|
371
|
+
_isAttachCommandRegistered(name) {
|
|
372
|
+
return this._registeredAttachCommands.some(cmd => cmd.name === name);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 获取所有插件注册的 attach 命令
|
|
377
|
+
* @returns {Array<Object>}
|
|
378
|
+
*/
|
|
379
|
+
getRegisteredAttachCommands() {
|
|
380
|
+
return [...this._registeredAttachCommands];
|
|
381
|
+
}
|
|
382
|
+
|
|
331
383
|
/**
|
|
332
384
|
* 获取所有已加载的插件信息
|
|
333
385
|
* @returns {Array<Object>}
|
|
@@ -345,4 +397,30 @@ class PluginManager {
|
|
|
345
397
|
}
|
|
346
398
|
}
|
|
347
399
|
|
|
400
|
+
/**
|
|
401
|
+
* 单例实例
|
|
402
|
+
* @type {PluginManager|null}
|
|
403
|
+
* @private
|
|
404
|
+
*/
|
|
405
|
+
PluginManager._instance = null;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* 获取 PluginManager 单例实例
|
|
409
|
+
* @returns {PluginManager}
|
|
410
|
+
*/
|
|
411
|
+
PluginManager.getInstance = function() {
|
|
412
|
+
if (!PluginManager._instance) {
|
|
413
|
+
throw new Error('PluginManager not initialized. Call setInstance() first.');
|
|
414
|
+
}
|
|
415
|
+
return PluginManager._instance;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 设置 PluginManager 单例实例
|
|
420
|
+
* @param {PluginManager} instance
|
|
421
|
+
*/
|
|
422
|
+
PluginManager.setInstance = function(instance) {
|
|
423
|
+
PluginManager._instance = instance;
|
|
424
|
+
};
|
|
425
|
+
|
|
348
426
|
module.exports = PluginManager;
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
// 日志显示字段配置
|
|
2
|
-
const DISPLAY_FIELDS = [
|
|
3
|
-
'timestamp',
|
|
4
|
-
'time',
|
|
5
|
-
'time_iso8601',
|
|
6
|
-
'ms',
|
|
7
|
-
'level',
|
|
8
|
-
'sandbox_id',
|
|
9
|
-
'trace_id',
|
|
10
|
-
'sent_http_request_id',
|
|
11
|
-
'request_id',
|
|
12
|
-
'callId',
|
|
13
|
-
'logger',
|
|
14
|
-
'thread',
|
|
15
|
-
'field',
|
|
16
|
-
'method',
|
|
17
|
-
'class',
|
|
18
|
-
'request_method',
|
|
19
|
-
'url',
|
|
20
|
-
'request_uri',
|
|
21
|
-
'host',
|
|
22
|
-
'status',
|
|
23
|
-
'status_code',
|
|
24
|
-
'process_time',
|
|
25
|
-
'request_time_usec',
|
|
26
|
-
'request_length',
|
|
27
|
-
'body_bytes_sent',
|
|
28
|
-
'upstream_response_tim',
|
|
29
|
-
'message',
|
|
30
|
-
'request',
|
|
31
|
-
"headers",
|
|
32
|
-
"http_Authorization",
|
|
33
|
-
"http_x_cluster",
|
|
34
|
-
"http_user_id",
|
|
35
|
-
"http_x_experiment_id",
|
|
36
|
-
"http_user_agent",
|
|
37
|
-
'request_body',
|
|
38
|
-
'response',
|
|
39
|
-
'filename',
|
|
40
|
-
'lineno',
|
|
41
|
-
'site',
|
|
42
|
-
'exc_info',
|
|
43
|
-
'exception',
|
|
44
|
-
'command_id',
|
|
45
|
-
'event',
|
|
46
|
-
'content',
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
// 字段颜色映射(ANSI 颜色代码)
|
|
50
|
-
// 1. 内置字段(@ 开头):灰色 - 系统元数据,通常不需要关注
|
|
51
|
-
// 2. 一般情况不需要关注的字段:灰色 - 辅助信息,低价值
|
|
52
|
-
// 3. 普通字段:青色 - 常规字段,有一定价值
|
|
53
|
-
// 4. 重点字段:粗体青色 - 核心标识,最重要的字段
|
|
54
|
-
const FIELD_COLOR_MAP = {
|
|
55
|
-
// 1. 内置字段(@ 开头)- 灰色
|
|
56
|
-
'@timestamp': '\x1b[0;90m',
|
|
57
|
-
'@source': '\x1b[0;90m',
|
|
58
|
-
'@app_group': '\x1b[0;90m',
|
|
59
|
-
'@hostname': '\x1b[0;90m',
|
|
60
|
-
'@filename': '\x1b[0;90m',
|
|
61
|
-
'@packId': '\x1b[0;90m',
|
|
62
|
-
'@logGroupOrder': '\x1b[0;90m',
|
|
63
|
-
'@topic': '\x1b[0;90m',
|
|
64
|
-
'@app_stage': '\x1b[0;90m',
|
|
65
|
-
'@site': '\x1b[0;90m',
|
|
66
|
-
|
|
67
|
-
// 2. 一般情况不需要关注的字段 - 灰色
|
|
68
|
-
'ms': '\x1b[0;90m',
|
|
69
|
-
'logger': '\x1b[0;90m',
|
|
70
|
-
'lineno': '\x1b[0;90m',
|
|
71
|
-
'site': '\x1b[0;90m',
|
|
72
|
-
'command_id': '\x1b[0;90m',
|
|
73
|
-
'sent_http_request_id': '\x1b[0;90m',
|
|
74
|
-
|
|
75
|
-
// 3. 普通字段 - 青色
|
|
76
|
-
'method': '\x1b[0;36m',
|
|
77
|
-
'request_method': '\x1b[0;36m',
|
|
78
|
-
'field': '\x1b[0;36m',
|
|
79
|
-
'url': '\x1b[0;36m',
|
|
80
|
-
'request_uri': '\x1b[0;36m',
|
|
81
|
-
'status_code': '\x1b[0;36m',
|
|
82
|
-
'process_time': '\x1b[0;36m',
|
|
83
|
-
'request': '\x1b[0;36m',
|
|
84
|
-
'request_body': '\x1b[0;36m',
|
|
85
|
-
'response': '\x1b[0;36m',
|
|
86
|
-
'filename': '\x1b[0;36m',
|
|
87
|
-
'event': '\x1b[0;36m',
|
|
88
|
-
'content': '\x1b[0;36m',
|
|
89
|
-
'sandbox_id': '\x1b[0;36m',
|
|
90
|
-
'trace_id': '\x1b[0;36m',
|
|
91
|
-
|
|
92
|
-
// 4. 重点字段 - 粗体青色
|
|
93
|
-
'timestamp': '\x1b[1;36m',
|
|
94
|
-
'time': '\x1b[1;36m',
|
|
95
|
-
'time_iso8601': '\x1b[1;36m',
|
|
96
|
-
'level': '\x1b[1;36m',
|
|
97
|
-
'message': '\x1b[1;36m',
|
|
98
|
-
'exc_info': '\x1b[1;31m', // 异常信息 - 红色粗体
|
|
99
|
-
'exception': '\x1b[1;31m', // 异常 - 红色粗体
|
|
100
|
-
'error': '\x1b[1;31m', // 错误 - 红色粗体
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// 默认字段颜色
|
|
104
|
-
const DEFAULT_FIELD_COLOR = '\x1b[0;90m';
|
|
105
|
-
|
|
106
|
-
// 字段黑名单(格式化模式下不显示)
|
|
107
|
-
const BLACKLIST_FIELDS = [
|
|
108
|
-
'sent_http_X_App_Id',
|
|
109
|
-
'scheme',
|
|
110
|
-
'remote_user',
|
|
111
|
-
'http_x_opensearch_rem',
|
|
112
|
-
'http_x_opensearch_sec',
|
|
113
|
-
'sent_http_Application',
|
|
114
|
-
'http_Content_Md5',
|
|
115
|
-
'http_date',
|
|
116
|
-
'sent_http_X_App_Name',
|
|
117
|
-
'http_Authorization',
|
|
118
|
-
'http_x_opensearch_non',
|
|
119
|
-
'sent_http_X_Aliyun_Us',
|
|
120
|
-
'sent_http_X_AppGroup_',
|
|
121
|
-
'upstream_response_tim',
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
// 需要截断的字段
|
|
125
|
-
const TRUNCATE_FIELDS = ['message', 'content', 'event'];
|
|
126
|
-
|
|
127
|
-
// Group by field mapping
|
|
128
|
-
const GROUP_BY_FIELDS = {
|
|
129
|
-
'file': '@filename',
|
|
130
|
-
'ip': '@source',
|
|
131
|
-
'app': '@app_group',
|
|
132
|
-
'hostname': '@hostname',
|
|
133
|
-
'cluster': '_cluster',
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// Group by field display labels
|
|
137
|
-
const GROUP_BY_LABELS = {
|
|
138
|
-
'@filename': 'File',
|
|
139
|
-
'@source': 'IP',
|
|
140
|
-
'@app_group': 'App',
|
|
141
|
-
'@hostname': 'Machine',
|
|
142
|
-
'_cluster': 'Cluster',
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// ANSI 颜色代码
|
|
146
|
-
const ANSI_COLORS = {
|
|
147
|
-
RESET: '\x1b[0m',
|
|
148
|
-
BOLD: '\x1b[1m',
|
|
149
|
-
CYAN: '\x1b[36m',
|
|
150
|
-
YELLOW: '\x1b[33m',
|
|
151
|
-
GREEN: '\x1b[32m',
|
|
152
|
-
MAGENTA: '\x1b[35m',
|
|
153
|
-
BLUE: '\x1b[34m',
|
|
154
|
-
RED: '\x1b[31m',
|
|
155
|
-
GRAY: '\x1b[90m',
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
// 查询时间范围(分钟)
|
|
159
|
-
const TIME_RANGES = [15, 60, 180, 720, 1800, 43200];
|
|
160
|
-
|
|
161
|
-
// 分页大小
|
|
162
|
-
const PAGE_SIZE = 1000;
|
|
163
|
-
|
|
164
|
-
// 日志文件名
|
|
165
|
-
// 注意:内网专有日志路径已移到 config/internal_log_config.json
|
|
166
|
-
const LOG_FILES = {
|
|
167
|
-
// 保留空对象,由具体命令从配置文件加载
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// 字段补全列表(用于 -f 参数的自动补全)
|
|
172
|
-
const FIELD_COMPLETION_LIST = [
|
|
173
|
-
// 系统内置字段(@ 开头)
|
|
174
|
-
'@filename',
|
|
175
|
-
'@source',
|
|
176
|
-
'@app_group',
|
|
177
|
-
'@hostname',
|
|
178
|
-
'@timestamp',
|
|
179
|
-
'@packId',
|
|
180
|
-
'@logGroupOrder',
|
|
181
|
-
'@topic',
|
|
182
|
-
'@app_stage',
|
|
183
|
-
'@site',
|
|
184
|
-
|
|
185
|
-
// 常规字段
|
|
186
|
-
'status',
|
|
187
|
-
'status_code',
|
|
188
|
-
'level',
|
|
189
|
-
'message',
|
|
190
|
-
'method',
|
|
191
|
-
'request_method',
|
|
192
|
-
'url',
|
|
193
|
-
'request_uri',
|
|
194
|
-
'host',
|
|
195
|
-
'sandbox_id',
|
|
196
|
-
'trace_id',
|
|
197
|
-
'thread',
|
|
198
|
-
'logger',
|
|
199
|
-
'field',
|
|
200
|
-
'process_time',
|
|
201
|
-
'request_time_usec',
|
|
202
|
-
'request_length',
|
|
203
|
-
'body_bytes_sent',
|
|
204
|
-
'request',
|
|
205
|
-
'headers',
|
|
206
|
-
'http_Authorization',
|
|
207
|
-
'http_x_cluster',
|
|
208
|
-
'http_user_id',
|
|
209
|
-
'http_x_experiment_id',
|
|
210
|
-
'http_user_agent',
|
|
211
|
-
'request_body',
|
|
212
|
-
'response',
|
|
213
|
-
'filename',
|
|
214
|
-
'lineno',
|
|
215
|
-
'site',
|
|
216
|
-
'exc_info',
|
|
217
|
-
'exception',
|
|
218
|
-
'command_id',
|
|
219
|
-
'event',
|
|
220
|
-
'content',
|
|
221
|
-
'error',
|
|
222
|
-
];
|
|
223
|
-
|
|
224
|
-
module.exports = {
|
|
225
|
-
DISPLAY_FIELDS,
|
|
226
|
-
FIELD_COLOR_MAP,
|
|
227
|
-
DEFAULT_FIELD_COLOR,
|
|
228
|
-
BLACKLIST_FIELDS,
|
|
229
|
-
TRUNCATE_FIELDS,
|
|
230
|
-
GROUP_BY_FIELDS,
|
|
231
|
-
GROUP_BY_LABELS,
|
|
232
|
-
ANSI_COLORS,
|
|
233
|
-
TIME_RANGES,
|
|
234
|
-
PAGE_SIZE,
|
|
235
|
-
LOG_FILES,
|
|
236
|
-
FIELD_COMPLETION_LIST,
|
|
237
|
-
};
|