@ai-setting/roy-agent-core 1.4.12 → 1.4.13

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 (57) hide show
  1. package/dist/index.d.ts +7825 -0
  2. package/dist/index.js +13073 -19300
  3. package/dist/shared/chunk-0q6s9wm6.js +249 -0
  4. package/dist/shared/chunk-1aakcfp1.js +15 -0
  5. package/dist/shared/chunk-1d4rwms4.js +25 -0
  6. package/dist/shared/chunk-1pf5mfgd.js +82 -0
  7. package/dist/shared/chunk-1qwabsm0.js +154 -0
  8. package/dist/shared/chunk-25x2pdtp.js +107 -0
  9. package/dist/shared/chunk-2b5kbhx3.js +366 -0
  10. package/dist/shared/chunk-91bas8w5.js +20 -0
  11. package/dist/shared/chunk-9qzt1v1p.js +10 -0
  12. package/dist/shared/chunk-a9qmy3sc.js +296 -0
  13. package/dist/shared/chunk-g6j5n3gv.js +549 -0
  14. package/dist/shared/chunk-hs7tbmje.js +24 -0
  15. package/dist/shared/chunk-mf5xqbdh.js +14 -0
  16. package/dist/shared/chunk-q9j99fsm.js +368 -0
  17. package/dist/{env/workflow/engine/index.js → shared/chunk-rncy3rtd.js} +330 -1581
  18. package/dist/shared/chunk-t1rh6jtm.js +205 -0
  19. package/dist/{env/task/hooks/index.js → shared/chunk-wbkh7wat.js} +3 -18
  20. package/dist/shared/chunk-yqmx37vm.js +10 -0
  21. package/dist/shared/chunk-ze20rksg.js +102 -0
  22. package/package.json +7 -7
  23. package/dist/config/index.js +0 -1670
  24. package/dist/env/agent/index.js +0 -3035
  25. package/dist/env/commands/index.js +0 -1685
  26. package/dist/env/debug/formatters/index.js +0 -639
  27. package/dist/env/debug/index.js +0 -2300
  28. package/dist/env/hook/index.js +0 -273
  29. package/dist/env/index.js +0 -12591
  30. package/dist/env/llm/index.js +0 -2736
  31. package/dist/env/log-trace/index.js +0 -1779
  32. package/dist/env/mcp/index.js +0 -2173
  33. package/dist/env/mcp/tool/index.js +0 -1149
  34. package/dist/env/memory/built-in/index.js +0 -225
  35. package/dist/env/memory/index.js +0 -2171
  36. package/dist/env/memory/plugin/index.js +0 -1263
  37. package/dist/env/prompt/index.js +0 -2107
  38. package/dist/env/session/index.js +0 -3594
  39. package/dist/env/session/storage/index.js +0 -2049
  40. package/dist/env/skill/index.js +0 -1635
  41. package/dist/env/skill/tool/index.js +0 -114
  42. package/dist/env/task/delegate/index.js +0 -1844
  43. package/dist/env/task/index.js +0 -3578
  44. package/dist/env/task/plugins/index.js +0 -1626
  45. package/dist/env/task/storage/index.js +0 -1464
  46. package/dist/env/task/tools/index.js +0 -344
  47. package/dist/env/task/tools/operation/index.js +0 -270
  48. package/dist/env/tool/built-in/index.js +0 -1151
  49. package/dist/env/tool/index.js +0 -2284
  50. package/dist/env/workflow/decorators/index.js +0 -449
  51. package/dist/env/workflow/index.js +0 -6214
  52. package/dist/env/workflow/nodes/index.js +0 -650
  53. package/dist/env/workflow/service/index.js +0 -262
  54. package/dist/env/workflow/storage/index.js +0 -1236
  55. package/dist/env/workflow/tools/index.js +0 -1081
  56. package/dist/env/workflow/types/index.js +0 -479
  57. package/dist/env/workflow/utils/index.js +0 -1631
@@ -1,639 +0,0 @@
1
- // @bun
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- function __accessProp(key) {
7
- return this[key];
8
- }
9
- var __toCommonJS = (from) => {
10
- var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
- if (entry)
12
- return entry;
13
- entry = __defProp({}, "__esModule", { value: true });
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (var key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(entry, key))
17
- __defProp(entry, key, {
18
- get: __accessProp.bind(from, key),
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- __moduleCache.set(from, entry);
23
- return entry;
24
- };
25
- var __moduleCache;
26
- var __returnValue = (v) => v;
27
- function __exportSetter(name, newValue) {
28
- this[name] = __returnValue.bind(null, newValue);
29
- }
30
- var __export = (target, all) => {
31
- for (var name in all)
32
- __defProp(target, name, {
33
- get: all[name],
34
- enumerable: true,
35
- configurable: true,
36
- set: __exportSetter.bind(all, name)
37
- });
38
- };
39
- var __legacyDecorateClassTS = function(decorators, target, key, desc) {
40
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
42
- r = Reflect.decorate(decorators, target, key, desc);
43
- else
44
- for (var i = decorators.length - 1;i >= 0; i--)
45
- if (d = decorators[i])
46
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- };
49
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
50
- var __require = import.meta.require;
51
-
52
- // packages/core/src/env/debug/formatters/trace-formatter.ts
53
- class TraceFormatter {
54
- formatEntry(entry, options = {}) {
55
- const { pretty = false } = options;
56
- const actionSymbol = entry.action === "enter" ? ">>>" : entry.action === "error" ? "!!!" : "<<<";
57
- let output = `${actionSymbol} ${entry.function} ${entry.action}`;
58
- if (entry.action === "enter" && entry.params) {
59
- output += `
60
- ` + this.formatData(entry.params, options);
61
- } else if (entry.action === "quit") {
62
- if (entry.durationMs !== undefined) {
63
- output += ` (${entry.durationMs}ms)`;
64
- }
65
- if (entry.result) {
66
- output += `
67
- ` + this.formatData(entry.result, options);
68
- }
69
- } else if (entry.action === "error" && entry.error) {
70
- output += `: ${entry.error}`;
71
- }
72
- if (pretty) {
73
- output = this.indentMultilineContent(output);
74
- }
75
- return output;
76
- }
77
- indentMultilineContent(text, indent = " ") {
78
- const lines = text.split(`
79
- `);
80
- if (lines.length <= 1)
81
- return text;
82
- return lines.map((line, i) => i === 0 ? line : `${indent}${line}`).join(`
83
- `);
84
- }
85
- formatEntries(entries, options = {}) {
86
- if (entries.length === 0) {
87
- return "No trace entries";
88
- }
89
- const formatted = entries.map((entry) => this.formatEntry(entry, options));
90
- if (options.pretty) {
91
- return formatted.join(`
92
- ` + "-".repeat(80) + `
93
- `);
94
- }
95
- return formatted.join(`
96
- `);
97
- }
98
- formatData(data, options = {}) {
99
- const { pretty = false, maxDepth = 10 } = options;
100
- if (pretty) {
101
- return this.formatPretty(data, 0, maxDepth);
102
- }
103
- return JSON.stringify(data);
104
- }
105
- formatPretty(data, indent = 0, maxDepth) {
106
- const baseIndent = " ".repeat(indent);
107
- const nextIndent = " ".repeat(indent + 1);
108
- if (data === null || data === undefined) {
109
- return String(data);
110
- }
111
- if (typeof data === "string") {
112
- if (data.includes(`
113
- `)) {
114
- return data.split(`
115
- `).map((line, i) => i === 0 ? line : `${nextIndent}${line}`).join(`
116
- `);
117
- }
118
- return data;
119
- }
120
- if (typeof data === "number" || typeof data === "boolean") {
121
- return String(data);
122
- }
123
- if (Array.isArray(data)) {
124
- if (data.length === 0)
125
- return "[]";
126
- const items = data.map((item) => {
127
- const formatted = this.formatPretty(item, indent + 1, maxDepth);
128
- return formatted.split(`
129
- `).map((line) => ` ${line}`).join(`
130
- `);
131
- });
132
- return `[
133
- ` + items.join(`,
134
- `) + `
135
- ` + baseIndent + "]";
136
- }
137
- if (typeof data === "object") {
138
- const obj = data;
139
- const keys = Object.keys(obj);
140
- if (keys.length === 0)
141
- return "{}";
142
- if (indent >= maxDepth) {
143
- return "{...}";
144
- }
145
- const entries = keys.map((key) => {
146
- const value = obj[key];
147
- let formatted;
148
- if (typeof value === "object" && value !== null) {
149
- formatted = this.formatPretty(value, indent + 1, maxDepth);
150
- } else if (typeof value === "string" && value.includes(`
151
- `)) {
152
- formatted = value.split(`
153
- `).map((line, i) => i === 0 ? line : `${nextIndent}${line}`).join(`
154
- `);
155
- } else {
156
- formatted = JSON.stringify(value);
157
- }
158
- return ` ${key}: ` + formatted.split(`
159
- `).map((line, i) => i === 0 ? line : nextIndent + line).join(`
160
- `);
161
- });
162
- return `{
163
- ` + entries.join(`,
164
- `) + `
165
- ` + baseIndent + "}";
166
- }
167
- return JSON.stringify(data);
168
- }
169
- toJSON(entries) {
170
- return JSON.stringify(entries, null, 2);
171
- }
172
- toSummary(entries) {
173
- if (entries.length === 0) {
174
- return "No trace entries";
175
- }
176
- const functions = new Set(entries.map((e) => e.function));
177
- const actions = entries.reduce((acc, e) => {
178
- acc[e.action] = (acc[e.action] || 0) + 1;
179
- return acc;
180
- }, {});
181
- let summary = `Trace Summary (${entries.length} entries)
182
- `;
183
- summary += `Functions: ${[...functions].join(", ")}
184
- `;
185
- summary += `Actions: ${Object.entries(actions).map(([k, v]) => `${k}=${v}`).join(", ")}`;
186
- return summary;
187
- }
188
- }
189
- // packages/core/src/env/debug/formatters/tree-formatter.ts
190
- var Colors = {
191
- reset: "\x1B[0m",
192
- bold: "\x1B[1m",
193
- dim: "\x1B[2m",
194
- red: "\x1B[31m",
195
- green: "\x1B[32m",
196
- yellow: "\x1B[33m",
197
- cyan: "\x1B[36m",
198
- white: "\x1B[37m"
199
- };
200
- function color(text, colorCode) {
201
- return `${colorCode}${text}${Colors.reset}`;
202
- }
203
- var CHARS = {
204
- VERTICAL: "\u2502",
205
- VERTICAL_CONNECTOR: "\u251C\u2500\u2500",
206
- LAST_CONNECTOR: "\u2514\u2500\u2500",
207
- SPACE: " ",
208
- BAR: "\u2588",
209
- EMPTY: "\u2591",
210
- DASH: "\u2500"
211
- };
212
-
213
- class TreeFormatter {
214
- options;
215
- constructor(options = {}) {
216
- this.options = {
217
- showPercent: true,
218
- showTimeBar: false,
219
- barWidth: 10,
220
- ...options
221
- };
222
- }
223
- colorByPercent(percent) {
224
- if (percent >= 80)
225
- return Colors.red;
226
- if (percent >= 50)
227
- return Colors.yellow;
228
- if (percent >= 20)
229
- return Colors.cyan;
230
- return Colors.dim;
231
- }
232
- formatTree(node) {
233
- const lines = [];
234
- const totalDuration = node.durationMs || 0;
235
- const percentBase = node.children.reduce((sum, c) => sum + (c.durationMs || 0), 0) || totalDuration;
236
- lines.push(this.formatNode(node, totalDuration, percentBase, "", true, true));
237
- this.formatChildren(node.children, "", lines, totalDuration, percentBase);
238
- return lines.join(`
239
- `);
240
- }
241
- formatNode(node, totalDuration, percentBase, prefix, isLast, isRoot) {
242
- const connector = isRoot ? "" : isLast ? CHARS.LAST_CONNECTOR : CHARS.VERTICAL_CONNECTOR;
243
- const prefixStr = isRoot ? "" : prefix;
244
- let line = `${prefixStr}${connector} ${node.function}`;
245
- if (node.durationMs !== undefined) {
246
- line += color(` (${this.formatDuration(node.durationMs)})`, Colors.dim);
247
- }
248
- if (this.options.showPercent && percentBase > 0 && node.durationMs !== undefined && node.function !== "(root)" && !isRoot) {
249
- const percent = Math.round(node.durationMs / percentBase * 100);
250
- const percentStr = ` [${percent}%]`;
251
- line += color(percentStr, this.colorByPercent(percent));
252
- }
253
- if (this.options.showTimeBar && node.durationMs !== undefined && totalDuration > 0 && !isRoot) {
254
- line += " " + this.renderTimeBar(node.durationMs, totalDuration);
255
- }
256
- return isRoot ? color(line, Colors.bold) : line;
257
- }
258
- formatChildren(children, prefix, lines, totalDuration, percentBase) {
259
- children.forEach((child, index) => {
260
- const isLast = index === children.length - 1;
261
- const newPrefix = prefix + (isLast ? " " : `${CHARS.VERTICAL} `);
262
- lines.push(this.formatNode(child, totalDuration, percentBase, prefix, isLast, false));
263
- if (child.children.length > 0) {
264
- this.formatChildren(child.children, newPrefix, lines, totalDuration, percentBase);
265
- }
266
- });
267
- }
268
- renderTimeBar(duration, total) {
269
- const width = this.options.barWidth || 10;
270
- const filledWidth = Math.round(duration / total * width);
271
- const emptyWidth = width - filledWidth;
272
- const bar = CHARS.BAR.repeat(filledWidth) + CHARS.EMPTY.repeat(emptyWidth);
273
- return color(`[${bar}]`, Colors.dim);
274
- }
275
- formatDuration(ms) {
276
- if (ms < 1000) {
277
- return `${ms}ms`;
278
- } else if (ms < 60000) {
279
- return `${(ms / 1000).toFixed(2)}s`;
280
- } else if (ms < 3600000) {
281
- const mins = Math.floor(ms / 60000);
282
- const secs = Math.round(ms % 60000 / 1000);
283
- return `${mins}m ${secs}s`;
284
- } else {
285
- const hours = Math.floor(ms / 3600000);
286
- const mins = Math.floor(ms % 3600000 / 60000);
287
- return `${hours}h ${mins}m`;
288
- }
289
- }
290
- formatTrees(trees) {
291
- if (trees.length === 0) {
292
- return "No trace trees";
293
- }
294
- return trees.map((tree) => this.formatTree(tree)).join(`
295
-
296
- `);
297
- }
298
- toJSON(trees) {
299
- return JSON.stringify(trees, null, 2);
300
- }
301
- formatSummary(node) {
302
- const rows = [];
303
- const total = node.durationMs || 0;
304
- const childrenTotal = node.children.reduce((sum, c) => sum + (c.durationMs || 0), 0);
305
- const percentBase = total > 0 ? total : childrenTotal;
306
- const collect = (n, depth) => {
307
- if (n.durationMs !== undefined) {
308
- rows.push({
309
- func: n.function,
310
- duration: n.durationMs,
311
- percent: percentBase > 0 ? Math.round(n.durationMs / percentBase * 100) : 0,
312
- depth
313
- });
314
- }
315
- n.children.forEach((child) => collect(child, depth + 1));
316
- };
317
- collect(node, 0);
318
- rows.sort((a, b) => b.duration - a.duration);
319
- const lines = [];
320
- lines.push(color(`
321
- === Duration Summary ===`, Colors.bold));
322
- lines.push(color(`(sorted by time consumption)
323
- `, Colors.dim));
324
- lines.push(color(` ${"\u2500".repeat(65)}`, Colors.dim));
325
- lines.push(color(` ${"FUNCTION".padEnd(35)} ${"TIME".padEnd(12)} %`, Colors.dim));
326
- lines.push(color(` ${"\u2500".repeat(65)}`, Colors.dim));
327
- for (const row of rows) {
328
- const indent = " ".repeat(row.depth);
329
- const funcDisplay = row.depth > 0 ? "\u2514\u2500 ".repeat(row.depth) + row.func : row.func;
330
- const percentStr = String(row.percent).padStart(3) + "%";
331
- const percentColor = row.percent >= 50 ? Colors.red : row.percent >= 20 ? Colors.yellow : Colors.dim;
332
- lines.push(` ${indent}${funcDisplay.substring(0, 35).padEnd(35)}${this.formatDuration(row.duration).padEnd(12)} ${color(percentStr, percentColor)}`);
333
- }
334
- return lines.join(`
335
- `);
336
- }
337
- formatTimeline(node) {
338
- const lines = [];
339
- const totalDuration = node.durationMs || 0;
340
- lines.push(color(`
341
- === Timeline: ${node.function} ===`, Colors.bold));
342
- lines.push(color(`Total: ${this.formatDuration(totalDuration)}
343
- `, Colors.dim));
344
- const timeline = this.buildTimeline(node, totalDuration, 0, 0);
345
- lines.push(...timeline);
346
- return lines.join(`
347
- `);
348
- }
349
- buildTimeline(node, totalDuration, absoluteOffset, depth) {
350
- const lines = [];
351
- const width = 40;
352
- const startPos = Math.round(absoluteOffset / totalDuration * width);
353
- const durationWidth = node.durationMs !== undefined ? Math.max(2, Math.round(node.durationMs / totalDuration * width)) : 2;
354
- const bar = " ".repeat(Math.max(0, startPos)) + CHARS.BAR.repeat(durationWidth);
355
- const indent = " ".repeat(depth);
356
- const funcName = node.function.length > 25 ? "..." + node.function.slice(-22) : node.function;
357
- const time = node.durationMs !== undefined ? this.formatDuration(node.durationMs) : "-";
358
- const percent = node.durationMs !== undefined ? ` [${Math.round(node.durationMs / totalDuration * 100)}%]` : "";
359
- lines.push(`${indent}${funcName.padEnd(25)} ${bar} ${color(time + percent, Colors.dim)}`);
360
- let childOffset = absoluteOffset;
361
- for (const child of node.children) {
362
- lines.push(...this.buildTimeline(child, totalDuration, childOffset, depth + 1));
363
- childOffset += child.durationMs || 0;
364
- }
365
- return lines;
366
- }
367
- }
368
- // packages/core/src/env/debug/formatters/repl-formatter.ts
369
- class ReplFormatter {
370
- context = {};
371
- history = [];
372
- getWelcomeMessage() {
373
- return `========================================
374
- Debug REPL - Interactive Debugger
375
- ========================================
376
-
377
- Commands:
378
- list [limit] - List trace IDs
379
- trace [options] - Show trace details
380
- tree [options] - Show call tree
381
- help - Show this help
382
- exit - Exit REPL
383
-
384
- Examples:
385
- list 10
386
- trace --func llm.invoke
387
- tree --trace trace-001
388
-
389
- ========================================
390
- `;
391
- }
392
- formatPrompt(context) {
393
- const ctx = { ...this.context, ...context };
394
- let prompt = "debug";
395
- if (ctx.traceId) {
396
- prompt += `:${ctx.traceId}`;
397
- } else if (ctx.function) {
398
- prompt += `:${ctx.function}`;
399
- }
400
- return `${prompt}> `;
401
- }
402
- getHelpText() {
403
- return `
404
- Available Commands:
405
- ==================
406
- list [n] - List recent trace IDs (default: 10)
407
- trace [options] - Show trace details
408
- --func <name> - Filter by function name
409
- --trace <id> - Show specific trace
410
- --pretty - Pretty print output
411
- --limit <n> - Limit results
412
- tree [options] - Show call tree
413
- --func <name> - Show tree for function
414
- --trace <id> - Show tree for trace
415
- clear - Clear screen
416
- help - Show this help
417
- exit - Exit REPL
418
- `;
419
- }
420
- formatCommandResult(command, data) {
421
- switch (command) {
422
- case "list":
423
- return this.formatListResult(data);
424
- case "trace":
425
- return this.formatTraceResult(data);
426
- case "tree":
427
- return this.formatTreeResult(data);
428
- default:
429
- return `Unknown command: ${command}`;
430
- }
431
- }
432
- formatListResult(data) {
433
- const { traceIds, count } = data;
434
- if (traceIds.length === 0) {
435
- return "No traces found.";
436
- }
437
- let output = `
438
- `;
439
- output += ` TraceId First Time Count
440
- `;
441
- output += " " + "-".repeat(70) + `
442
- `;
443
- for (const trace of traceIds) {
444
- const time = trace.firstTime.replace("T", " ").substring(0, 19);
445
- output += ` ${trace.traceId.padEnd(18)} ${time.padEnd(22)} ${trace.count}
446
- `;
447
- }
448
- output += `
449
- Total: ${count} traces
450
- `;
451
- return output;
452
- }
453
- formatTraceResult(entries) {
454
- if (entries.length === 0) {
455
- return "No traces found.";
456
- }
457
- let output = "";
458
- let currentTraceId = null;
459
- for (const entry of entries) {
460
- if (entry.traceId !== currentTraceId) {
461
- currentTraceId = entry.traceId;
462
- output += `
463
- === Trace: ${entry.traceId} ===
464
-
465
- `;
466
- }
467
- if (entry.action === "enter") {
468
- output += `>>> ${entry.function} enter:`;
469
- if (entry.params) {
470
- output += `
471
- ` + this.formatJsonCompact(entry.params);
472
- }
473
- output += `
474
- `;
475
- } else if (entry.action === "quit") {
476
- output += `<<< ${entry.function} quit`;
477
- if (entry.durationMs !== undefined) {
478
- output += ` (${entry.durationMs}ms)`;
479
- }
480
- if (entry.result) {
481
- output += `:
482
- ` + this.formatJsonCompact(entry.result);
483
- }
484
- output += `
485
- `;
486
- } else if (entry.action === "error") {
487
- output += `!!! ${entry.function} error: ${entry.error}
488
- `;
489
- }
490
- }
491
- return output;
492
- }
493
- formatTreeResult(trees) {
494
- if (trees.length === 0) {
495
- return "No trees found.";
496
- }
497
- let output = "";
498
- for (const tree of trees) {
499
- output += this.formatTreeNode(tree, "");
500
- }
501
- return output;
502
- }
503
- formatTreeNode(node, prefix) {
504
- const duration = node.durationMs !== undefined ? ` (${node.durationMs}ms)` : "";
505
- let output = `${prefix}${node.function}${duration}
506
- `;
507
- const childPrefix = prefix + " ";
508
- for (let i = 0;i < node.children.length; i++) {
509
- const isLast = i === node.children.length - 1;
510
- const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
511
- output += this.formatTreeNode(node.children[i], childPrefix + connector);
512
- }
513
- return output;
514
- }
515
- formatJsonCompact(data, indent = 2) {
516
- const spaces = " ".repeat(indent);
517
- if (data === null || data === undefined) {
518
- return `${spaces}null
519
- `;
520
- }
521
- if (typeof data === "string") {
522
- if (data.length > 200) {
523
- return `${spaces}"${data.substring(0, 200)}..."
524
- `;
525
- }
526
- return `${spaces}"${data}"
527
- `;
528
- }
529
- if (typeof data === "number" || typeof data === "boolean") {
530
- return `${spaces}${data}
531
- `;
532
- }
533
- if (Array.isArray(data)) {
534
- if (data.length === 0)
535
- return `${spaces}[]
536
- `;
537
- let output = `${spaces}[
538
- `;
539
- for (const item of data) {
540
- output += this.formatJsonCompact(item, indent + 1);
541
- }
542
- output += `${spaces}]
543
- `;
544
- return output;
545
- }
546
- if (typeof data === "object") {
547
- const entries = Object.entries(data);
548
- if (entries.length === 0)
549
- return `${spaces}{}
550
- `;
551
- let output = `${spaces}{
552
- `;
553
- for (const [key, val] of entries) {
554
- output += `${spaces} ${key}: ${JSON.stringify(val).substring(0, 50)}`;
555
- if (JSON.stringify(val).length > 50) {
556
- output += "...";
557
- }
558
- output += `
559
- `;
560
- }
561
- output += `${spaces}}
562
- `;
563
- return output;
564
- }
565
- return `${spaces}${String(data)}
566
- `;
567
- }
568
- parseCommand(input) {
569
- const trimmed = input.trim();
570
- if (!trimmed) {
571
- return { command: "help", args: {} };
572
- }
573
- if (["exit", "quit", "q"].includes(trimmed.toLowerCase())) {
574
- return { command: "exit", args: {} };
575
- }
576
- if (trimmed.toLowerCase() === "clear") {
577
- return { command: "clear", args: {} };
578
- }
579
- if (["help", "?", "h"].includes(trimmed.toLowerCase())) {
580
- return { command: "help", args: {} };
581
- }
582
- const parts = trimmed.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
583
- if (parts.length === 0) {
584
- return { command: "help", args: {} };
585
- }
586
- const command = parts[0]?.toLowerCase() ?? "";
587
- const args = {};
588
- for (let i = 1;i < parts.length; i++) {
589
- const part = parts[i];
590
- if (part.startsWith("--")) {
591
- const key = part.substring(2);
592
- const next = parts[i + 1];
593
- if (next && !next.startsWith("--")) {
594
- args[key] = next;
595
- i++;
596
- } else {
597
- args[key] = "true";
598
- }
599
- } else if (part.startsWith("-")) {
600
- const key = part.substring(1);
601
- const next = parts[i + 1];
602
- if (next && !next.startsWith("-")) {
603
- args[key] = next;
604
- i++;
605
- } else {
606
- args[key] = "true";
607
- }
608
- } else {
609
- if (command === "list" && !args.limit) {
610
- args.limit = part;
611
- } else if (command === "trace" && !args.func) {
612
- args.func = part;
613
- } else if (command === "tree" && !args.func) {
614
- args.func = part;
615
- }
616
- }
617
- }
618
- return { command, args };
619
- }
620
- setContext(context) {
621
- this.context = { ...this.context, ...context };
622
- }
623
- getContext() {
624
- return { ...this.context };
625
- }
626
- addToHistory(command) {
627
- if (command.trim() && this.history[this.history.length - 1] !== command) {
628
- this.history.push(command);
629
- }
630
- }
631
- getHistory() {
632
- return [...this.history];
633
- }
634
- }
635
- export {
636
- TreeFormatter,
637
- TraceFormatter,
638
- ReplFormatter
639
- };