@kb-labs/shared-cli-ui 1.0.0

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/dist/index.js ADDED
@@ -0,0 +1,2516 @@
1
+ import path from 'path';
2
+ import { promises } from 'fs';
3
+
4
+ // src/colors.ts
5
+ var CSI = "\x1B[";
6
+ var RESET = "\x1B[0m";
7
+ var createColor = (...codes) => (text) => `${CSI}${codes.join(";")}m${text}${RESET}`;
8
+ var accentBlue = "38;5;39";
9
+ var accentViolet = "38;5;99";
10
+ var accentTeal = "38;5;51";
11
+ var accentIndigo = "38;5;63";
12
+ var neutral = 37;
13
+ var neutralMuted = 90;
14
+ var colors = {
15
+ // Semantic colors
16
+ success: createColor(32),
17
+ error: createColor(31),
18
+ warning: createColor(33),
19
+ info: createColor(36),
20
+ // Accent palette (reused across CLI)
21
+ primary: createColor(accentBlue),
22
+ accent: createColor(accentViolet),
23
+ highlight: createColor(accentTeal),
24
+ secondary: createColor(accentIndigo),
25
+ emphasis: createColor("38;5;117"),
26
+ muted: createColor(neutralMuted),
27
+ foreground: createColor(neutral),
28
+ // Formatting helpers
29
+ dim: createColor(2),
30
+ bold: createColor(1),
31
+ underline: createColor(4),
32
+ inverse: createColor(7)
33
+ };
34
+ var symbolCharacters = {
35
+ success: "OK",
36
+ error: "ERR",
37
+ warning: "WARN",
38
+ info: "\u2139",
39
+ bullet: "\u2022",
40
+ clock: "TIME",
41
+ folder: "DIR",
42
+ package: "\u203A",
43
+ pointer: "\u203A",
44
+ section: "\u2502"
45
+ };
46
+ var symbols = {
47
+ success: colors.success(symbolCharacters.success),
48
+ error: colors.error(symbolCharacters.error),
49
+ warning: colors.warning(symbolCharacters.warning),
50
+ info: colors.info(symbolCharacters.info),
51
+ bullet: colors.muted(symbolCharacters.bullet),
52
+ clock: colors.info(symbolCharacters.clock),
53
+ folder: colors.primary(symbolCharacters.folder),
54
+ package: colors.accent(symbolCharacters.package),
55
+ pointer: colors.primary(symbolCharacters.pointer),
56
+ section: colors.primary(symbolCharacters.section)
57
+ };
58
+ var isTruthyEnv = (value) => {
59
+ if (!value) {
60
+ return false;
61
+ }
62
+ const normalized = value.trim().toLowerCase();
63
+ return normalized !== "" && normalized !== "0" && normalized !== "false" && normalized !== "off";
64
+ };
65
+ var supportsColor = (() => {
66
+ if (typeof process === "undefined") {
67
+ return false;
68
+ }
69
+ const forceColor = process.env.FORCE_COLOR;
70
+ if (isTruthyEnv(process.env.NO_COLOR)) {
71
+ return false;
72
+ }
73
+ if (isTruthyEnv(forceColor)) {
74
+ return true;
75
+ }
76
+ if (!process.stdout) {
77
+ return false;
78
+ }
79
+ if (process.stdout.isTTY === false) {
80
+ return false;
81
+ }
82
+ return true;
83
+ })();
84
+ var passthrough = (fn) => (text) => supportsColor ? fn(text) : text;
85
+ var safeColors = {
86
+ success: passthrough(colors.success),
87
+ error: passthrough(colors.error),
88
+ warning: passthrough(colors.warning),
89
+ info: passthrough(colors.info),
90
+ accent: passthrough(colors.accent),
91
+ primary: passthrough(colors.primary),
92
+ highlight: passthrough(colors.highlight),
93
+ secondary: passthrough(colors.secondary),
94
+ emphasis: passthrough(colors.emphasis),
95
+ foreground: passthrough(colors.foreground),
96
+ muted: passthrough(colors.muted),
97
+ dim: passthrough(colors.dim),
98
+ bold: passthrough(colors.bold),
99
+ underline: passthrough(colors.underline),
100
+ inverse: passthrough(colors.inverse)
101
+ };
102
+ var safeSymbols = {
103
+ success: supportsColor ? symbols.success : "\u2713",
104
+ error: supportsColor ? symbols.error : "\u2717",
105
+ warning: supportsColor ? symbols.warning : "\u26A0",
106
+ info: supportsColor ? symbols.info : "\u2192",
107
+ bullet: supportsColor ? symbols.bullet : "\u2022",
108
+ clock: supportsColor ? symbols.clock : "time",
109
+ folder: supportsColor ? symbols.folder : "dir",
110
+ package: supportsColor ? symbols.package : "\u203A",
111
+ pointer: supportsColor ? symbols.pointer : ">",
112
+ section: supportsColor ? symbols.section : "|",
113
+ // Box-drawing characters for modern side border
114
+ separator: "\u2500",
115
+ // Horizontal line
116
+ border: "\u2502",
117
+ // Vertical line
118
+ topLeft: "\u250C",
119
+ // Top-left corner
120
+ topRight: "\u2510",
121
+ // Top-right corner
122
+ bottomLeft: "\u2514",
123
+ // Bottom-left corner
124
+ bottomRight: "\u2518",
125
+ // Bottom-right corner
126
+ leftT: "\u251C",
127
+ // Left T-junction
128
+ rightT: "\u2524"
129
+ // Right T-junction
130
+ };
131
+
132
+ // src/loader.ts
133
+ var SPINNER_CHARS = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
134
+ var Loader = class {
135
+ isActive = false;
136
+ options;
137
+ frameIndex = 0;
138
+ intervalId;
139
+ currentText;
140
+ // ← Реактивная переменная для текста
141
+ constructor(options = {}) {
142
+ this.options = {
143
+ text: "Loading...",
144
+ spinner: true,
145
+ jsonMode: false,
146
+ ...options
147
+ };
148
+ this.currentText = this.options.text ?? "Loading...";
149
+ }
150
+ start() {
151
+ if (this.options.jsonMode || this.isActive) {
152
+ return;
153
+ }
154
+ this.isActive = true;
155
+ if (this.options.spinner && !this.options.jsonMode) {
156
+ this.intervalId = setInterval(() => {
157
+ if (!this.isActive) {
158
+ this.clearInterval();
159
+ return;
160
+ }
161
+ const char = SPINNER_CHARS[this.frameIndex % SPINNER_CHARS.length];
162
+ process.stdout.write(`\r${char} ${this.currentText}`);
163
+ this.frameIndex++;
164
+ }, 200);
165
+ }
166
+ }
167
+ update(options) {
168
+ this.options = { ...this.options, ...options };
169
+ if (!this.isActive || this.options.jsonMode) {
170
+ return;
171
+ }
172
+ if (options.text !== void 0) {
173
+ this.currentText = options.text;
174
+ }
175
+ if (!this.intervalId) {
176
+ if (this.options.spinner) {
177
+ const text = this.options.text ?? "Loading...";
178
+ console.log(`${safeSymbols.info} ${text}`);
179
+ } else if (this.options.total !== void 0) {
180
+ this.updateProgress();
181
+ }
182
+ }
183
+ }
184
+ stop() {
185
+ this.isActive = false;
186
+ this.clearInterval();
187
+ }
188
+ succeed(message) {
189
+ this.stop();
190
+ if (!this.options.jsonMode && message) {
191
+ process.stdout.write(`\r\x1B[K${safeSymbols.success} ${message}
192
+ `);
193
+ }
194
+ }
195
+ fail(message) {
196
+ this.stop();
197
+ if (!this.options.jsonMode && message) {
198
+ process.stdout.write(`\r\x1B[K${safeSymbols.error} ${message}
199
+ `);
200
+ }
201
+ }
202
+ clearInterval() {
203
+ if (this.intervalId) {
204
+ clearInterval(this.intervalId);
205
+ this.intervalId = void 0;
206
+ }
207
+ }
208
+ updateProgress() {
209
+ if (this.options.total === void 0 || this.options.current === void 0) {
210
+ return;
211
+ }
212
+ const current = this.options.current;
213
+ const total = this.options.total;
214
+ const percentage = Math.round(current / total * 100);
215
+ const barLength = 20;
216
+ const filledLength = Math.round(current / total * barLength);
217
+ const bar = "\u2588".repeat(filledLength) + "\u2591".repeat(barLength - filledLength);
218
+ const text = this.options.text || "Progress";
219
+ process.stdout.write(`\r${safeColors.info("\u2192")} ${text}... ${bar} ${percentage}% (${current}/${total})`);
220
+ }
221
+ };
222
+ function createSpinner(text, jsonMode = false) {
223
+ return new Loader({ text, spinner: true, jsonMode });
224
+ }
225
+ function createProgressBar(text, total, jsonMode = false) {
226
+ return new Loader({ text, spinner: false, total, current: 0, jsonMode });
227
+ }
228
+ function showLoading(text, jsonMode = false) {
229
+ if (!jsonMode) {
230
+ console.log(`${safeColors.info("\u2192")} ${text}...`);
231
+ }
232
+ }
233
+ function showSuccess(text, jsonMode = false) {
234
+ if (!jsonMode) {
235
+ console.log(`${safeSymbols.success} ${text}`);
236
+ }
237
+ }
238
+ function showError(text, jsonMode = false) {
239
+ if (!jsonMode) {
240
+ console.log(`${safeSymbols.error} ${text}`);
241
+ }
242
+ }
243
+ function useLoader(text, options) {
244
+ return new Loader({ text, ...options });
245
+ }
246
+
247
+ // src/format.ts
248
+ var ANSI_PATTERN = /\u001B\[[0-9;]*m/g;
249
+ function stripAnsi(input) {
250
+ return input.replace(ANSI_PATTERN, "");
251
+ }
252
+ function hasAnsi(input) {
253
+ return /\u001B\[[0-9;]*m/.test(input);
254
+ }
255
+ function visibleLength(input) {
256
+ return stripAnsi(input).length;
257
+ }
258
+ function box(title, content = [], maxWidth) {
259
+ const lines = content.length > 0 ? content : [""];
260
+ const titleWidth = visibleLength(title);
261
+ const terminalWidth = typeof process !== "undefined" && process.stdout?.columns ? process.stdout.columns : 80;
262
+ const effectiveMaxWidth = maxWidth ?? Math.min(terminalWidth - 4, 120);
263
+ const bodyWidth = Math.min(
264
+ effectiveMaxWidth,
265
+ Math.max(titleWidth, ...lines.map((line) => visibleLength(line)))
266
+ );
267
+ const wrappedLines = [];
268
+ for (const line of lines) {
269
+ const lineLength = visibleLength(line);
270
+ if (lineLength <= bodyWidth) {
271
+ wrappedLines.push(line);
272
+ } else {
273
+ const words = line.split(/(\s+)/);
274
+ let currentLine = "";
275
+ for (const word of words) {
276
+ const testLine = currentLine + word;
277
+ if (visibleLength(testLine) <= bodyWidth) {
278
+ currentLine = testLine;
279
+ } else {
280
+ if (currentLine) {
281
+ wrappedLines.push(currentLine.trimEnd());
282
+ }
283
+ if (visibleLength(word) > bodyWidth) {
284
+ wrappedLines.push(truncate(word, bodyWidth));
285
+ currentLine = "";
286
+ } else {
287
+ currentLine = word;
288
+ }
289
+ }
290
+ }
291
+ if (currentLine) {
292
+ wrappedLines.push(currentLine.trimEnd());
293
+ }
294
+ }
295
+ }
296
+ const topBorder = `\u250C${"\u2500".repeat(bodyWidth + 2)}\u2510`;
297
+ const titleLine = `\u2502 ${safeColors.bold(title)}${" ".repeat(Math.max(0, bodyWidth - titleWidth))} \u2502`;
298
+ const bodyLines = wrappedLines.map((line) => {
299
+ const padding = Math.max(0, bodyWidth - visibleLength(line));
300
+ return `\u2502 ${line}${" ".repeat(padding)} \u2502`;
301
+ });
302
+ const bottomBorder = `\u2514${"\u2500".repeat(bodyWidth + 2)}\u2518`;
303
+ return [topBorder, titleLine, ...bodyLines, bottomBorder].join("\n");
304
+ }
305
+ function indent(lines, level = 1) {
306
+ const prefix = " ".repeat(level);
307
+ return lines.map((line) => `${prefix}${line}`);
308
+ }
309
+ function section(header, content) {
310
+ return [
311
+ "",
312
+ safeColors.bold(header),
313
+ ...indent(content)
314
+ ];
315
+ }
316
+ function table(rows, headers) {
317
+ if (rows.length === 0) {
318
+ return [];
319
+ }
320
+ const allRows = headers ? [headers, ...rows] : rows;
321
+ if (allRows.length === 0) {
322
+ return [];
323
+ }
324
+ const columnWidths = allRows[0].map(
325
+ (_, colIndex) => Math.max(...allRows.map((row) => String(row[colIndex] || "").length))
326
+ );
327
+ return allRows.map((row) => {
328
+ return row.map(
329
+ (cell, colIndex) => String(cell || "").padEnd(columnWidths[colIndex] || 0)
330
+ ).join(" ");
331
+ });
332
+ }
333
+ function keyValue(pairs, options = {}) {
334
+ const { padKeys = true } = options;
335
+ return safeKeyValue(pairs, { pad: padKeys });
336
+ }
337
+ function bulletList(items) {
338
+ return items.map((item) => `${safeSymbols.bullet} ${item}`);
339
+ }
340
+ function safeKeyValue(pairs, options = {}) {
341
+ const { indent: indent2 = 0, pad: pad3 = true, valueColor } = options;
342
+ const keys = Object.keys(pairs);
343
+ if (keys.length === 0) {
344
+ return [];
345
+ }
346
+ const indentStr = " ".repeat(indent2);
347
+ const maxKeyLength = pad3 ? Math.max(...keys.map((key) => indent2 + stripAnsi(key).length)) : 0;
348
+ return keys.map((key) => {
349
+ const rawKey = key;
350
+ const rawValue = String(pairs[key] ?? "");
351
+ const keyLength = indent2 + stripAnsi(rawKey).length;
352
+ const padding = pad3 ? Math.max(0, maxKeyLength - keyLength) : 0;
353
+ const formattedKey = `${indentStr}${rawKey}${" ".repeat(padding)}`;
354
+ const computedValue = valueColor ? valueColor(rawValue, key) : rawValue;
355
+ const valueText = hasAnsi(computedValue) ? computedValue : safeColors.muted(computedValue);
356
+ return `${safeColors.bold(formattedKey)}: ${valueText}`;
357
+ });
358
+ }
359
+ var pad2 = (value) => value.toString().padStart(2, "0");
360
+ var toDate = (value) => value instanceof Date ? new Date(value.getTime()) : new Date(value);
361
+ var isValidDate = (date) => Number.isFinite(date.getTime());
362
+ function getOffsetMinutes(date, timeZone) {
363
+ if (!timeZone) {
364
+ return -date.getTimezoneOffset();
365
+ }
366
+ const dtf = new Intl.DateTimeFormat("en-US", {
367
+ timeZone,
368
+ hour12: false,
369
+ year: "numeric",
370
+ month: "2-digit",
371
+ day: "2-digit",
372
+ hour: "2-digit",
373
+ minute: "2-digit",
374
+ second: "2-digit"
375
+ });
376
+ const parts = dtf.formatToParts(date);
377
+ const lookup = Object.fromEntries(
378
+ parts.filter((part) => part.type !== "literal").map((part) => [part.type, Number(part.value)])
379
+ );
380
+ const year = lookup.year ?? date.getUTCFullYear();
381
+ const month = (lookup.month ?? date.getUTCMonth() + 1) - 1;
382
+ const day = lookup.day ?? date.getUTCDate();
383
+ const hour = lookup.hour ?? date.getUTCHours();
384
+ const minute = lookup.minute ?? date.getUTCMinutes();
385
+ const second = lookup.second ?? date.getUTCSeconds();
386
+ const asUTC = Date.UTC(year, month, day, hour, minute, second);
387
+ return Math.round((asUTC - date.getTime()) / 6e4);
388
+ }
389
+ function formatOffset(offsetMinutes) {
390
+ const sign = offsetMinutes >= 0 ? "+" : "-";
391
+ const absMinutes = Math.abs(offsetMinutes);
392
+ const hours = Math.floor(absMinutes / 60);
393
+ const minutes = absMinutes % 60;
394
+ return `${sign}${pad2(hours)}:${pad2(minutes)}`;
395
+ }
396
+ function getDateParts(date, timeZone) {
397
+ if (!timeZone) {
398
+ return {
399
+ year: date.getFullYear(),
400
+ month: date.getMonth() + 1,
401
+ day: date.getDate(),
402
+ hour: date.getHours(),
403
+ minute: date.getMinutes(),
404
+ second: date.getSeconds()
405
+ };
406
+ }
407
+ const dtf = new Intl.DateTimeFormat("en-US", {
408
+ timeZone,
409
+ hour12: false,
410
+ year: "numeric",
411
+ month: "2-digit",
412
+ day: "2-digit",
413
+ hour: "2-digit",
414
+ minute: "2-digit",
415
+ second: "2-digit"
416
+ });
417
+ const parts = dtf.formatToParts(date);
418
+ const lookup = Object.fromEntries(
419
+ parts.filter((part) => part.type !== "literal").map((part) => [part.type, Number(part.value)])
420
+ );
421
+ return {
422
+ year: lookup.year ?? date.getUTCFullYear(),
423
+ month: lookup.month ?? date.getUTCMonth() + 1,
424
+ day: lookup.day ?? date.getUTCDate(),
425
+ hour: lookup.hour ?? date.getUTCHours(),
426
+ minute: lookup.minute ?? date.getUTCMinutes(),
427
+ second: lookup.second ?? date.getUTCSeconds()
428
+ };
429
+ }
430
+ function headline(text) {
431
+ return safeColors.primary(safeColors.bold(text));
432
+ }
433
+ function accentLabel(text) {
434
+ return safeColors.accent(safeColors.bold(text));
435
+ }
436
+ function muted(text) {
437
+ return safeColors.muted(text);
438
+ }
439
+ function formatSize(bytes) {
440
+ const units = ["B", "KB", "MB", "GB"];
441
+ let size = bytes;
442
+ let unitIndex = 0;
443
+ while (size >= 1024 && unitIndex < units.length - 1) {
444
+ size /= 1024;
445
+ unitIndex++;
446
+ }
447
+ return `${size.toFixed(unitIndex === 0 ? 0 : 1)} ${units[unitIndex]}`;
448
+ }
449
+ function formatRelativeTime(timestamp) {
450
+ const now = /* @__PURE__ */ new Date();
451
+ const time = toDate(timestamp);
452
+ if (!isValidDate(time)) {
453
+ return "Invalid date";
454
+ }
455
+ const diffMs = now.getTime() - time.getTime();
456
+ const seconds = Math.floor(diffMs / 1e3);
457
+ const minutes = Math.floor(seconds / 60);
458
+ const hours = Math.floor(minutes / 60);
459
+ const days = Math.floor(hours / 24);
460
+ if (days > 0) {
461
+ return `${days} day${days > 1 ? "s" : ""} ago`;
462
+ } else if (hours > 0) {
463
+ return `${hours} hour${hours > 1 ? "s" : ""} ago`;
464
+ } else if (minutes > 0) {
465
+ return `${minutes} minute${minutes > 1 ? "s" : ""} ago`;
466
+ } else {
467
+ return `${seconds} second${seconds > 1 ? "s" : ""} ago`;
468
+ }
469
+ }
470
+ function formatTimestamp(timestamp, options = {}) {
471
+ const {
472
+ mode = "local",
473
+ timeZone,
474
+ includeSeconds = false,
475
+ includeMilliseconds = true,
476
+ includeOffset = true
477
+ } = options;
478
+ const date = toDate(timestamp);
479
+ if (!isValidDate(date)) {
480
+ return "Invalid date";
481
+ }
482
+ const offsetMinutes = includeOffset ? getOffsetMinutes(date, timeZone) : null;
483
+ const offsetSuffix = includeOffset && offsetMinutes !== null ? ` (${formatOffset(offsetMinutes)})` : "";
484
+ if (mode === "iso") {
485
+ const isoRaw = date.toISOString();
486
+ const iso = includeMilliseconds ? isoRaw : isoRaw.replace(/\.\d{3}Z$/, "Z");
487
+ return `${iso}${offsetSuffix}`;
488
+ }
489
+ const { year, month, day, hour, minute, second } = getDateParts(date, timeZone);
490
+ const base = [
491
+ `${year}-${pad2(month)}-${pad2(day)}`,
492
+ `${pad2(hour)}:${pad2(minute)}${includeSeconds ? `:${pad2(second)}` : ""}`
493
+ ].join(" ");
494
+ return `${base}${offsetSuffix}`;
495
+ }
496
+ function truncate(text, maxLength) {
497
+ if (text.length <= maxLength) {
498
+ return text;
499
+ }
500
+ return text.substring(0, maxLength - 3) + "...";
501
+ }
502
+ function pad(text, width, align = "left") {
503
+ if (text.length >= width) {
504
+ return text;
505
+ }
506
+ const padding = width - text.length;
507
+ switch (align) {
508
+ case "right":
509
+ return " ".repeat(padding) + text;
510
+ case "center":
511
+ const leftPad = Math.floor(padding / 2);
512
+ const rightPad = padding - leftPad;
513
+ return " ".repeat(leftPad) + text + " ".repeat(rightPad);
514
+ default:
515
+ return text + " ".repeat(padding);
516
+ }
517
+ }
518
+
519
+ // src/command-output.ts
520
+ function formatTiming(ms) {
521
+ if (ms < 1e3) {
522
+ return `${ms}ms`;
523
+ } else if (ms < 6e4) {
524
+ return `${(ms / 1e3).toFixed(1)}s`;
525
+ } else {
526
+ const minutes = Math.floor(ms / 6e4);
527
+ const seconds = (ms % 6e4 / 1e3).toFixed(1);
528
+ return `${minutes}m ${seconds}s`;
529
+ }
530
+ }
531
+ function formatTimingBreakdown(timings) {
532
+ const lines = [];
533
+ const sortedEntries = Object.entries(timings).filter(([key]) => key !== "total").sort(([, a], [, b]) => b - a);
534
+ for (const [name, ms] of sortedEntries) {
535
+ const formattedName = name.charAt(0).toUpperCase() + name.slice(1);
536
+ lines.push(`${formattedName}: ${formatTiming(ms)}`);
537
+ }
538
+ if (timings.total !== void 0) {
539
+ lines.push(`Total: ${formatTiming(timings.total)}`);
540
+ }
541
+ return lines;
542
+ }
543
+ function formatCommandOutput(result) {
544
+ const sections = [];
545
+ const summaryLines = keyValue(result.summary);
546
+ sections.push(...summaryLines);
547
+ if (result.timing !== void 0) {
548
+ sections.push("");
549
+ if (typeof result.timing === "number") {
550
+ sections.push(`Time: ${formatTiming(result.timing)}`);
551
+ } else {
552
+ const timingLines = formatTimingBreakdown(result.timing);
553
+ sections.push(...timingLines);
554
+ }
555
+ }
556
+ if (result.warnings && result.warnings.length > 0) {
557
+ sections.push("");
558
+ sections.push(safeColors.warning("Warnings:"));
559
+ result.warnings.forEach(
560
+ (warning) => sections.push(` ${safeColors.dim("\u2022")} ${warning}`)
561
+ );
562
+ }
563
+ if (result.errors && result.errors.length > 0) {
564
+ sections.push("");
565
+ sections.push(safeColors.error("Errors:"));
566
+ result.errors.forEach(
567
+ (error) => sections.push(` ${safeColors.dim("\u2022")} ${error}`)
568
+ );
569
+ }
570
+ if (result.diagnostics && result.diagnostics.length > 0) {
571
+ sections.push("");
572
+ sections.push(safeColors.info("Diagnostics:"));
573
+ result.diagnostics.forEach(
574
+ (diagnostic) => sections.push(` ${safeColors.dim("\u2022")} ${diagnostic}`)
575
+ );
576
+ }
577
+ if (result.suggestions && result.suggestions.length > 0) {
578
+ sections.push("");
579
+ sections.push(safeColors.info("Suggestions:"));
580
+ result.suggestions.forEach(
581
+ (suggestion) => sections.push(` ${safeColors.dim("\u2022")} ${suggestion}`)
582
+ );
583
+ }
584
+ return box(result.title, sections);
585
+ }
586
+ function createSimpleResult(title, summary, timing) {
587
+ return {
588
+ title,
589
+ summary,
590
+ timing
591
+ };
592
+ }
593
+ function createDetailedResult(title, summary, options = {}) {
594
+ return {
595
+ title,
596
+ summary,
597
+ ...options
598
+ };
599
+ }
600
+
601
+ // src/timing-tracker.ts
602
+ var TimingTracker = class {
603
+ start;
604
+ checkpoints = {};
605
+ constructor() {
606
+ this.start = Date.now();
607
+ }
608
+ /**
609
+ * Record a timing checkpoint
610
+ */
611
+ checkpoint(name) {
612
+ this.checkpoints[name] = Date.now() - this.start;
613
+ }
614
+ /**
615
+ * Get total elapsed time in milliseconds
616
+ */
617
+ total() {
618
+ return Date.now() - this.start;
619
+ }
620
+ /**
621
+ * Get timing breakdown including total
622
+ */
623
+ breakdown() {
624
+ return { ...this.checkpoints, total: this.total() };
625
+ }
626
+ /**
627
+ * Get timing breakdown without total
628
+ */
629
+ checkpointsOnly() {
630
+ return { ...this.checkpoints };
631
+ }
632
+ /**
633
+ * Reset the timer
634
+ */
635
+ reset() {
636
+ this.start = Date.now();
637
+ this.checkpoints = {};
638
+ }
639
+ /**
640
+ * Get elapsed time since last checkpoint or start
641
+ */
642
+ sinceLastCheckpoint() {
643
+ const lastCheckpointTime = Math.max(...Object.values(this.checkpoints), 0);
644
+ return Date.now() - this.start - lastCheckpointTime;
645
+ }
646
+ /**
647
+ * Get elapsed time since a specific checkpoint
648
+ */
649
+ sinceCheckpoint(checkpointName) {
650
+ const checkpointTime = this.checkpoints[checkpointName];
651
+ if (checkpointTime === void 0) {
652
+ return null;
653
+ }
654
+ return Date.now() - this.start - checkpointTime;
655
+ }
656
+ };
657
+
658
+ // src/command-suggestions.ts
659
+ function createCommandRegistry(commands) {
660
+ const commandSet = new Set(commands);
661
+ const groups = /* @__PURE__ */ new Map();
662
+ for (const cmd of commands) {
663
+ const [group, ...rest] = cmd.split(":");
664
+ if (group && rest.length > 0) {
665
+ if (!groups.has(group)) {
666
+ groups.set(group, /* @__PURE__ */ new Set());
667
+ }
668
+ groups.get(group).add(rest.join(":"));
669
+ }
670
+ }
671
+ return {
672
+ commands: commandSet,
673
+ groups
674
+ };
675
+ }
676
+ function isCommandAvailable(command, registry) {
677
+ if (command.startsWith("kb ")) {
678
+ const parts = command.split(" ");
679
+ if (parts.length >= 3 && parts[1] && parts[2]) {
680
+ const group = parts[1];
681
+ const subcommand = parts[2];
682
+ const fullCommand = `${group}:${subcommand}`;
683
+ return registry.commands.has(fullCommand);
684
+ }
685
+ }
686
+ return registry.commands.has(command);
687
+ }
688
+ function validateSuggestions(suggestions, registry) {
689
+ return suggestions.map((suggestion) => ({
690
+ ...suggestion,
691
+ available: isCommandAvailable(suggestion.command, registry)
692
+ })).filter((suggestion) => suggestion.available);
693
+ }
694
+ function generateDevlinkSuggestions(warningCodes, context, registry) {
695
+ const suggestions = [];
696
+ if (warningCodes.has("LOCK_MISMATCH")) {
697
+ suggestions.push({
698
+ id: "SYNC_LOCK",
699
+ command: "kb devlink apply",
700
+ args: ["--yes"],
701
+ description: "Apply changes to sync manifests",
702
+ impact: "safe",
703
+ when: "LOCK_MISMATCH"
704
+ });
705
+ }
706
+ if (warningCodes.has("BACKUP_MISSING")) {
707
+ suggestions.push({
708
+ id: "CREATE_BACKUP",
709
+ command: "kb devlink freeze",
710
+ args: ["--replace"],
711
+ description: "Create a fresh backup",
712
+ impact: "safe",
713
+ when: "BACKUP_MISSING"
714
+ });
715
+ }
716
+ if (warningCodes.has("STALE_LOCK")) {
717
+ suggestions.push({
718
+ id: "REFRESH_LOCK",
719
+ command: "kb devlink freeze",
720
+ args: ["--pin=caret"],
721
+ description: "Refresh lock file",
722
+ impact: "safe",
723
+ when: "STALE_LOCK"
724
+ });
725
+ }
726
+ if (warningCodes.has("STALE_YALC_ARTIFACTS")) {
727
+ suggestions.push({
728
+ id: "CLEAN_YALC",
729
+ command: "kb devlink clean",
730
+ args: [],
731
+ description: "Remove yalc artifacts",
732
+ impact: "safe",
733
+ when: "STALE_YALC_ARTIFACTS"
734
+ });
735
+ }
736
+ if (warningCodes.has("PROTOCOL_CONFLICTS")) {
737
+ suggestions.push({
738
+ id: "FIX_PROTOCOLS",
739
+ command: "kb devlink clean",
740
+ args: ["--hard"],
741
+ description: "Reset all protocols and reapply",
742
+ impact: "disruptive",
743
+ when: "PROTOCOL_CONFLICTS"
744
+ });
745
+ }
746
+ if (context.undo?.available) {
747
+ suggestions.push({
748
+ id: "UNDO_LAST",
749
+ command: "kb devlink undo",
750
+ args: [],
751
+ description: "Revert last operation",
752
+ impact: "safe",
753
+ when: "BACKUP_AVAILABLE"
754
+ });
755
+ }
756
+ return validateSuggestions(suggestions, registry);
757
+ }
758
+ function generateQuickActions(hasWarnings, registry, group = "devlink") {
759
+ if (!hasWarnings) {
760
+ return [];
761
+ }
762
+ const quickActions = [
763
+ {
764
+ id: "QUICK_CLEAN",
765
+ command: `kb ${group} clean`,
766
+ args: [],
767
+ description: "Clean artifacts",
768
+ impact: "safe",
769
+ when: "QUICK_ACTIONS"
770
+ },
771
+ {
772
+ id: "QUICK_PLAN",
773
+ command: `kb ${group} plan`,
774
+ args: [],
775
+ description: "Create plan",
776
+ impact: "safe",
777
+ when: "QUICK_ACTIONS"
778
+ },
779
+ {
780
+ id: "QUICK_APPLY",
781
+ command: `kb ${group} apply`,
782
+ args: [],
783
+ description: "Apply changes",
784
+ impact: "safe",
785
+ when: "QUICK_ACTIONS"
786
+ }
787
+ ];
788
+ return validateSuggestions(quickActions, registry);
789
+ }
790
+
791
+ // src/command-discovery.ts
792
+ var StaticCommandDiscovery = class {
793
+ constructor(commands) {
794
+ this.commands = commands;
795
+ }
796
+ async getAvailableCommands() {
797
+ return [...this.commands];
798
+ }
799
+ async getCommandInfo(commandId) {
800
+ if (!this.commands.includes(commandId)) {
801
+ return null;
802
+ }
803
+ const [group, name] = commandId.split(":");
804
+ return {
805
+ id: commandId,
806
+ group: group || "unknown",
807
+ name: name || commandId,
808
+ description: `Execute ${commandId}`,
809
+ available: true
810
+ };
811
+ }
812
+ async isCommandAvailable(commandId) {
813
+ return this.commands.includes(commandId);
814
+ }
815
+ };
816
+ function createCommandDiscovery(commands) {
817
+ return new StaticCommandDiscovery(commands);
818
+ }
819
+
820
+ // src/manifest-parser.ts
821
+ function extractCommandIds(manifest) {
822
+ return manifest.map((cmd) => cmd.id);
823
+ }
824
+ function extractCommandGroups(manifest) {
825
+ const groups = /* @__PURE__ */ new Set();
826
+ manifest.forEach((cmd) => groups.add(cmd.group));
827
+ return Array.from(groups);
828
+ }
829
+ function findCommandsByGroup(manifest, group) {
830
+ return manifest.filter((cmd) => cmd.group === group);
831
+ }
832
+ function findCommandById(manifest, id) {
833
+ return manifest.find((cmd) => cmd.id === id);
834
+ }
835
+ function getCommandInfo(manifest, commandId) {
836
+ const cmd = findCommandById(manifest, commandId);
837
+ if (!cmd) {
838
+ return null;
839
+ }
840
+ const [group, name] = commandId.split(":");
841
+ return {
842
+ id: commandId,
843
+ group: group || "unknown",
844
+ name: name || commandId,
845
+ description: cmd.describe,
846
+ available: true
847
+ };
848
+ }
849
+ function generateGroupSuggestions(manifest, group, _warningCodes, _context) {
850
+ const groupCommands = findCommandsByGroup(manifest, group);
851
+ const suggestions = [];
852
+ for (const cmd of groupCommands) {
853
+ suggestions.push({
854
+ id: `${cmd.group.toUpperCase()}_${cmd.id.split(":")[1]?.toUpperCase() || "UNKNOWN"}`,
855
+ command: `kb ${cmd.group} ${cmd.id.split(":")[1] || ""}`,
856
+ args: [],
857
+ description: cmd.describe,
858
+ impact: "safe",
859
+ when: "GENERAL",
860
+ available: true
861
+ });
862
+ if (cmd.id.includes("init")) {
863
+ suggestions.push({
864
+ id: `${cmd.group.toUpperCase()}_INIT_FORCE`,
865
+ command: `kb ${cmd.group} ${cmd.id.split(":")[1] || ""}`,
866
+ args: ["--force"],
867
+ description: `${cmd.describe} (force)`,
868
+ impact: "disruptive",
869
+ when: "INIT_FAILED",
870
+ available: true
871
+ });
872
+ }
873
+ if (cmd.id.includes("clean") || cmd.id.includes("reset")) {
874
+ suggestions.push({
875
+ id: `${cmd.group.toUpperCase()}_CLEAN_HARD`,
876
+ command: `kb ${cmd.group} ${cmd.id.split(":")[1] || ""}`,
877
+ args: ["--hard"],
878
+ description: `${cmd.describe} (hard)`,
879
+ impact: "disruptive",
880
+ when: "CLEAN_NEEDED",
881
+ available: true
882
+ });
883
+ }
884
+ }
885
+ return suggestions;
886
+ }
887
+
888
+ // src/multi-cli-suggestions.ts
889
+ var MultiCLISuggestions = class {
890
+ packages = /* @__PURE__ */ new Map();
891
+ globalRegistry = null;
892
+ /**
893
+ * Register a CLI package
894
+ */
895
+ registerPackage(pkg) {
896
+ this.packages.set(pkg.name, pkg);
897
+ this.globalRegistry = null;
898
+ }
899
+ /**
900
+ * Get or create global command registry
901
+ */
902
+ getGlobalRegistry() {
903
+ if (this.globalRegistry) {
904
+ return this.globalRegistry;
905
+ }
906
+ const allCommands = [];
907
+ for (const pkg of this.packages.values()) {
908
+ allCommands.push(...extractCommandIds(pkg.commands));
909
+ }
910
+ this.globalRegistry = createCommandRegistry(allCommands);
911
+ return this.globalRegistry;
912
+ }
913
+ /**
914
+ * Generate suggestions for a specific group
915
+ */
916
+ generateGroupSuggestions(group, context) {
917
+ const suggestions = [];
918
+ const registry = this.getGlobalRegistry();
919
+ const groupPackages = Array.from(this.packages.values()).filter((pkg) => pkg.group === group).sort((a, b) => b.priority - a.priority);
920
+ for (const pkg of groupPackages) {
921
+ const groupSuggestions = generateGroupSuggestions(
922
+ pkg.commands,
923
+ group,
924
+ context.warningCodes);
925
+ for (const suggestion of groupSuggestions) {
926
+ if (registry.commands.has(suggestion.command.replace("kb ", "").replace(" ", ":"))) {
927
+ suggestions.push({
928
+ id: suggestion.id,
929
+ command: suggestion.command,
930
+ args: suggestion.args,
931
+ description: suggestion.description,
932
+ impact: suggestion.impact,
933
+ when: suggestion.when,
934
+ available: true
935
+ });
936
+ }
937
+ }
938
+ }
939
+ return suggestions;
940
+ }
941
+ /**
942
+ * Generate all suggestions across all packages
943
+ */
944
+ generateAllSuggestions(context) {
945
+ const suggestions = [];
946
+ const registry = this.getGlobalRegistry();
947
+ if (this.packages.has("devlink")) {
948
+ const devlinkSuggestions = generateDevlinkSuggestions(
949
+ context.warningCodes,
950
+ { undo: context.undo },
951
+ registry
952
+ );
953
+ suggestions.push(...devlinkSuggestions);
954
+ }
955
+ const groups = /* @__PURE__ */ new Set();
956
+ for (const pkg of this.packages.values()) {
957
+ groups.add(pkg.group);
958
+ }
959
+ for (const group of groups) {
960
+ if (group !== "devlink") {
961
+ const groupSuggestions = this.generateGroupSuggestions(group, context);
962
+ suggestions.push(...groupSuggestions);
963
+ }
964
+ }
965
+ return suggestions;
966
+ }
967
+ /**
968
+ * Get available commands for a group
969
+ */
970
+ getAvailableCommands(group) {
971
+ const groupPackages = Array.from(this.packages.values()).filter((pkg) => pkg.group === group);
972
+ const commands = [];
973
+ for (const pkg of groupPackages) {
974
+ commands.push(...extractCommandIds(pkg.commands));
975
+ }
976
+ return commands;
977
+ }
978
+ /**
979
+ * Get all registered packages
980
+ */
981
+ getPackages() {
982
+ return Array.from(this.packages.values());
983
+ }
984
+ };
985
+
986
+ // src/dynamic-command-discovery.ts
987
+ var DynamicCommandDiscovery = class {
988
+ constructor(manifestLoader, packageNames) {
989
+ this.manifestLoader = manifestLoader;
990
+ this.packageNames = packageNames;
991
+ }
992
+ manifestCache = /* @__PURE__ */ new Map();
993
+ commandCache = /* @__PURE__ */ new Map();
994
+ async getAvailableCommands() {
995
+ const allCommands = [];
996
+ for (const packageName of this.packageNames) {
997
+ try {
998
+ const manifest = await this.loadManifest(packageName);
999
+ const commands = manifest.map((cmd) => cmd.id);
1000
+ allCommands.push(...commands);
1001
+ } catch (error) {
1002
+ console.warn(`Failed to load manifest for ${packageName}:`, error);
1003
+ }
1004
+ }
1005
+ return allCommands;
1006
+ }
1007
+ async getCommandInfo(commandId) {
1008
+ if (this.commandCache.has(commandId)) {
1009
+ return this.commandCache.get(commandId);
1010
+ }
1011
+ for (const packageName of this.packageNames) {
1012
+ try {
1013
+ const manifest = await this.loadManifest(packageName);
1014
+ const command = manifest.find((cmd) => cmd.id === commandId);
1015
+ if (command) {
1016
+ const [group, name] = commandId.split(":");
1017
+ const info = {
1018
+ id: commandId,
1019
+ group: group || "unknown",
1020
+ name: name || commandId,
1021
+ description: command.describe || `Execute ${commandId}`,
1022
+ available: true
1023
+ };
1024
+ this.commandCache.set(commandId, info);
1025
+ return info;
1026
+ }
1027
+ } catch (error) {
1028
+ console.warn(`Failed to load manifest for ${packageName}:`, error);
1029
+ }
1030
+ }
1031
+ return null;
1032
+ }
1033
+ async isCommandAvailable(commandId) {
1034
+ const info = await this.getCommandInfo(commandId);
1035
+ return info !== null;
1036
+ }
1037
+ async loadManifest(packageName) {
1038
+ if (this.manifestCache.has(packageName)) {
1039
+ return this.manifestCache.get(packageName);
1040
+ }
1041
+ const manifest = await this.manifestLoader.loadManifest(packageName);
1042
+ this.manifestCache.set(packageName, manifest);
1043
+ return manifest;
1044
+ }
1045
+ };
1046
+ function createKBLabsCommandDiscovery() {
1047
+ const manifestLoader = {
1048
+ async loadManifest(packageName) {
1049
+ try {
1050
+ const possiblePaths = [
1051
+ `@kb-labs/${packageName}/cli.manifest.js`,
1052
+ `@kb-labs/${packageName}/dist/cli.manifest.js`,
1053
+ `@kb-labs/${packageName}/src/cli.manifest.js`
1054
+ ];
1055
+ for (const path2 of possiblePaths) {
1056
+ try {
1057
+ const manifest = await import(path2);
1058
+ if (manifest.commands && Array.isArray(manifest.commands)) {
1059
+ return manifest.commands;
1060
+ }
1061
+ } catch {
1062
+ continue;
1063
+ }
1064
+ }
1065
+ throw new Error(`No manifest found for ${packageName}`);
1066
+ } catch (error) {
1067
+ console.warn(`Failed to load manifest for ${packageName}:`, error);
1068
+ return [];
1069
+ }
1070
+ }
1071
+ };
1072
+ const packageNames = [
1073
+ "devlink-core",
1074
+ "mind-cli",
1075
+ "tox-cli",
1076
+ "core-cli"
1077
+ ];
1078
+ return new DynamicCommandDiscovery(manifestLoader, packageNames);
1079
+ }
1080
+ function displayArtifacts(artifacts, options = {}) {
1081
+ const {
1082
+ showSize = true,
1083
+ showTime = true,
1084
+ showDescription = false,
1085
+ maxItems = 10,
1086
+ title = "Generated Artifacts",
1087
+ groupBy = "none"
1088
+ } = options;
1089
+ if (artifacts.length === 0) {
1090
+ return [];
1091
+ }
1092
+ let sortedArtifacts = artifacts;
1093
+ if (groupBy === "time") {
1094
+ sortedArtifacts = [...artifacts].sort(
1095
+ (a, b) => (b.modified?.getTime() ?? 0) - (a.modified?.getTime() ?? 0)
1096
+ );
1097
+ } else if (groupBy === "type") {
1098
+ sortedArtifacts = [...artifacts].sort((a, b) => a.name.localeCompare(b.name));
1099
+ } else {
1100
+ sortedArtifacts = [...artifacts].sort(
1101
+ (a, b) => (b.modified?.getTime() ?? 0) - (a.modified?.getTime() ?? 0)
1102
+ );
1103
+ }
1104
+ sortedArtifacts = sortedArtifacts.slice(0, maxItems);
1105
+ const lines = [];
1106
+ if (title) {
1107
+ lines.push(safeColors.bold(title));
1108
+ }
1109
+ if (groupBy === "type") {
1110
+ const grouped = sortedArtifacts.reduce((acc, artifact) => {
1111
+ const type = artifact.name.split(" ")[0] || "Other";
1112
+ if (!acc[type]) {
1113
+ acc[type] = [];
1114
+ }
1115
+ acc[type].push(artifact);
1116
+ return acc;
1117
+ }, {});
1118
+ Object.entries(grouped).forEach(([type, items], index) => {
1119
+ if (index > 0 || title) {
1120
+ lines.push("");
1121
+ }
1122
+ lines.push(...safeKeyValue({ [type]: "" }, { pad: false }));
1123
+ items.forEach((artifact, artifactIndex) => {
1124
+ if (artifactIndex > 0) {
1125
+ lines.push("");
1126
+ }
1127
+ lines.push(...formatArtifactLines(artifact, {
1128
+ showSize,
1129
+ showTime,
1130
+ showDescription,
1131
+ indent: 2
1132
+ }));
1133
+ });
1134
+ });
1135
+ return lines;
1136
+ }
1137
+ sortedArtifacts.forEach((artifact, index) => {
1138
+ if (index > 0) {
1139
+ lines.push("");
1140
+ }
1141
+ lines.push(...formatArtifactLines(artifact, {
1142
+ showSize,
1143
+ showTime,
1144
+ showDescription,
1145
+ indent: 0
1146
+ }));
1147
+ });
1148
+ return lines;
1149
+ }
1150
+ function formatArtifactLines(artifact, options) {
1151
+ const { showSize, showTime, showDescription, indent: indent2 } = options;
1152
+ const relativePath = path.relative(process.cwd(), artifact.path);
1153
+ const lines = [];
1154
+ lines.push(
1155
+ ...safeKeyValue({ [artifact.name]: relativePath }, { pad: false, indent: indent2 })
1156
+ );
1157
+ if (showSize && artifact.size) {
1158
+ lines.push(
1159
+ ...safeKeyValue({ Size: formatSize(artifact.size) }, { pad: false, indent: indent2 + 2 })
1160
+ );
1161
+ }
1162
+ if (showTime && artifact.modified) {
1163
+ lines.push(
1164
+ ...safeKeyValue({ Updated: formatRelativeTime(artifact.modified) }, { pad: false, indent: indent2 + 2 })
1165
+ );
1166
+ }
1167
+ if (showDescription && artifact.description) {
1168
+ lines.push(
1169
+ ...safeKeyValue({ Note: artifact.description }, { pad: false, indent: indent2 + 2 })
1170
+ );
1171
+ }
1172
+ return lines;
1173
+ }
1174
+ function displaySingleArtifact(artifact, title) {
1175
+ const relativePath = path.relative(process.cwd(), artifact.path);
1176
+ const lines = [];
1177
+ if (title) {
1178
+ lines.push("");
1179
+ lines.push(safeColors.bold(title));
1180
+ }
1181
+ lines.push(` ${safeColors.bold(artifact.name)}: ${safeColors.info(relativePath)}`);
1182
+ if (artifact.size) {
1183
+ lines.push(` Size: ${formatSize(artifact.size)}`);
1184
+ }
1185
+ if (artifact.modified) {
1186
+ lines.push(` Modified: ${formatRelativeTime(artifact.modified)}`);
1187
+ }
1188
+ if (artifact.description) {
1189
+ lines.push(` Description: ${artifact.description}`);
1190
+ }
1191
+ return lines;
1192
+ }
1193
+ function displayArtifactsCompact(artifacts, options = {}) {
1194
+ const {
1195
+ maxItems = 5,
1196
+ showSize = true,
1197
+ sortByTime = true,
1198
+ showTime = true,
1199
+ title = "Artifacts"
1200
+ } = options;
1201
+ if (artifacts.length === 0) {
1202
+ return [];
1203
+ }
1204
+ const sortedArtifacts = (sortByTime ? [...artifacts].sort((a, b) => (b.modified?.getTime() ?? 0) - (a.modified?.getTime() ?? 0)) : artifacts.slice()).slice(0, maxItems);
1205
+ const lines = [];
1206
+ lines.push(safeColors.bold(title));
1207
+ sortedArtifacts.forEach((artifact, index) => {
1208
+ if (index > 0) {
1209
+ lines.push("");
1210
+ }
1211
+ lines.push(
1212
+ ...formatArtifactLines(artifact, {
1213
+ showSize,
1214
+ showTime,
1215
+ showDescription: false,
1216
+ indent: 0
1217
+ })
1218
+ );
1219
+ });
1220
+ return lines;
1221
+ }
1222
+ async function discoverArtifacts(baseDir, patterns) {
1223
+ const artifacts = [];
1224
+ for (const artifact of patterns) {
1225
+ const artifactPath = path.join(baseDir, artifact.pattern);
1226
+ try {
1227
+ await promises.access(artifactPath);
1228
+ const stats = await promises.stat(artifactPath);
1229
+ artifacts.push({
1230
+ name: artifact.name,
1231
+ path: artifactPath,
1232
+ size: stats.size,
1233
+ modified: stats.mtime,
1234
+ description: artifact.description || ""
1235
+ });
1236
+ } catch {
1237
+ }
1238
+ }
1239
+ return artifacts;
1240
+ }
1241
+
1242
+ // src/table.ts
1243
+ function visualWidth(str) {
1244
+ const ansiRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
1245
+ const cleanStr = str.replace(ansiRegex, "");
1246
+ const emojiRegex = /[\u{1F300}-\u{1F9FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]|[\u{1F900}-\u{1F9FF}]|[\u{1FA00}-\u{1FA6F}]|[\u{1FA70}-\u{1FAFF}]|[\u{2190}-\u{21FF}]|[\u{2300}-\u{23FF}]|[\u{24C2}-\u{1F251}]|[\u{2B50}-\u{2B55}]|[\u{3030}-\u{303D}]|[\u{3297}-\u{3299}]|[\u{1F000}-\u{1F02F}]|[\u{1F0A0}-\u{1F0FF}]|[\u{1F100}-\u{1F1FF}]|[\u{1F200}-\u{1F2FF}]|[\u{1F300}-\u{1F5FF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]|[\u{1F700}-\u{1F7FF}]|[\u{1F800}-\u{1F8FF}]|[\u{1F900}-\u{1F9FF}]|[\u{1FA00}-\u{1FA6F}]|[\u{1FA70}-\u{1FAFF}]|[\u{23F0}-\u{23FF}]|[\u{25A0}-\u{25FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{FE00}-\u{FE0F}]|[\u{1F1E6}-\u{1F1FF}]|[\u{1F3FB}-\u{1F3FF}]|[\u{1F9B0}-\u{1F9B3}]|[\u{20E3}]|[\u{FE0F}]/gu;
1247
+ const emojiMatches = cleanStr.match(emojiRegex);
1248
+ const emojiCount = emojiMatches ? emojiMatches.length : 0;
1249
+ return cleanStr.length - emojiCount + emojiCount * 2;
1250
+ }
1251
+ function padVisual(str, width, padChar = " ") {
1252
+ const vWidth = visualWidth(str);
1253
+ const padding = Math.max(0, width - vWidth);
1254
+ return str + padChar.repeat(padding);
1255
+ }
1256
+ function formatTable(columns, rows, options = {}) {
1257
+ const { header = true, separator = "\u2500", padding = 1 } = options;
1258
+ const widths = columns.map((col, idx) => {
1259
+ if (col.width !== void 0) {
1260
+ return col.width;
1261
+ }
1262
+ let maxWidth = visualWidth(col.header);
1263
+ for (const row of rows) {
1264
+ if (row[idx]) {
1265
+ maxWidth = Math.max(maxWidth, visualWidth(String(row[idx])));
1266
+ }
1267
+ }
1268
+ return maxWidth;
1269
+ });
1270
+ const lines = [];
1271
+ if (header) {
1272
+ const headerCells = columns.map((col, idx) => {
1273
+ const cell = col.header;
1274
+ const width = widths[idx];
1275
+ return padVisual(cell, width);
1276
+ });
1277
+ lines.push(headerCells.join(" ".repeat(padding)));
1278
+ if (separator) {
1279
+ const separatorLine = widths.map((w) => separator.repeat(w)).join(" ".repeat(padding));
1280
+ lines.push(separatorLine);
1281
+ }
1282
+ }
1283
+ for (const row of rows) {
1284
+ const cells = columns.map((col, idx) => {
1285
+ const cell = row[idx] !== void 0 ? String(row[idx]) : "";
1286
+ const align = col.align || "left";
1287
+ const width = widths[idx];
1288
+ if (align === "right") {
1289
+ const vWidth = visualWidth(cell);
1290
+ const padding2 = Math.max(0, width - vWidth);
1291
+ return " ".repeat(padding2) + cell;
1292
+ } else if (align === "center") {
1293
+ const vWidth = visualWidth(cell);
1294
+ const padding2 = Math.max(0, width - vWidth);
1295
+ const leftPad = Math.floor(padding2 / 2);
1296
+ const rightPad = padding2 - leftPad;
1297
+ return " ".repeat(leftPad) + cell + " ".repeat(rightPad);
1298
+ } else {
1299
+ return padVisual(cell, width);
1300
+ }
1301
+ });
1302
+ lines.push(cells.join(" ".repeat(padding)));
1303
+ }
1304
+ return lines;
1305
+ }
1306
+ function formatKeyValueTable(data, options = {}) {
1307
+ const keys = Object.keys(data);
1308
+ if (keys.length === 0) {
1309
+ return [];
1310
+ }
1311
+ const keyWidth = options.keyWidth || Math.max(...keys.map((k) => visualWidth(k)), 0);
1312
+ const valueWidth = options.valueWidth || Math.max(...Object.values(data).map((v) => visualWidth(String(v))), 0);
1313
+ return keys.map((key) => {
1314
+ const value = String(data[key]);
1315
+ return `${padVisual(key, keyWidth)} ${padVisual(value, valueWidth)}`;
1316
+ });
1317
+ }
1318
+
1319
+ // src/debug/formatters/ai.ts
1320
+ function formatDebugEntryAI(entry) {
1321
+ return JSON.stringify(entry, null, 2);
1322
+ }
1323
+ function formatDebugEntriesAI(entries) {
1324
+ return JSON.stringify(entries, null, 2);
1325
+ }
1326
+ function shouldUseAIFormat(format, jsonMode) {
1327
+ if (jsonMode) {
1328
+ return true;
1329
+ }
1330
+ return format === "ai";
1331
+ }
1332
+
1333
+ // src/debug/formatters/human.ts
1334
+ function formatTimestamp2(timestamp) {
1335
+ const date = new Date(timestamp);
1336
+ return date.toISOString();
1337
+ }
1338
+ function formatDuration(duration) {
1339
+ if (duration < 1e3) {
1340
+ return `${duration}ms`;
1341
+ }
1342
+ return `${(duration / 1e3).toFixed(2)}s`;
1343
+ }
1344
+ function formatDebugEntryHuman(entry, options = {}) {
1345
+ const parts = [];
1346
+ if (options.showTimestamp) {
1347
+ parts.push(safeColors.dim(formatTimestamp2(entry.timestamp)));
1348
+ }
1349
+ parts.push(safeColors.bold(`[${entry.namespace}]`));
1350
+ parts.push(entry.message);
1351
+ if (options.showDuration && typeof entry.duration === "number") {
1352
+ parts.push(safeColors.dim(`(${formatDuration(entry.duration)})`));
1353
+ }
1354
+ if (entry.level === "error") {
1355
+ parts.push(safeColors.error(safeSymbols.error));
1356
+ } else if (entry.level === "warn") {
1357
+ parts.push(safeColors.warning(safeSymbols.warning));
1358
+ }
1359
+ return parts.join(" ");
1360
+ }
1361
+ function formatDebugEntriesHuman(entries, options = {}) {
1362
+ if (entries.length === 0) {
1363
+ return "";
1364
+ }
1365
+ const sorted = [...entries].sort((a, b) => a.timestamp - b.timestamp);
1366
+ const lines = [];
1367
+ if (options.groupBy === "namespace") {
1368
+ const namespaces = /* @__PURE__ */ new Map();
1369
+ for (const entry of sorted) {
1370
+ if (!namespaces.has(entry.namespace)) {
1371
+ namespaces.set(entry.namespace, []);
1372
+ }
1373
+ namespaces.get(entry.namespace).push(entry);
1374
+ }
1375
+ for (const [namespace, namespaceEntries] of namespaces) {
1376
+ lines.push(safeColors.bold(namespace));
1377
+ for (const entry of namespaceEntries) {
1378
+ lines.push(` ${formatDebugEntryHuman(entry, options)}`);
1379
+ }
1380
+ lines.push("");
1381
+ }
1382
+ return lines.join("\n").trimEnd();
1383
+ }
1384
+ if (options.groupBy === "group") {
1385
+ const groups = /* @__PURE__ */ new Map();
1386
+ for (const entry of sorted) {
1387
+ const groupName = entry.group ?? "default";
1388
+ if (!groups.has(groupName)) {
1389
+ groups.set(groupName, []);
1390
+ }
1391
+ groups.get(groupName).push(entry);
1392
+ }
1393
+ for (const [groupName, groupEntries] of groups) {
1394
+ lines.push(safeColors.bold(groupName));
1395
+ for (const entry of groupEntries) {
1396
+ lines.push(` ${formatDebugEntryHuman(entry, options)}`);
1397
+ }
1398
+ lines.push("");
1399
+ }
1400
+ return lines.join("\n").trimEnd();
1401
+ }
1402
+ for (const entry of sorted) {
1403
+ lines.push(formatDebugEntryHuman(entry, options));
1404
+ }
1405
+ return lines.join("\n");
1406
+ }
1407
+
1408
+ // src/debug/utilities.ts
1409
+ function toRegex(pattern) {
1410
+ if (!pattern.includes("*")) {
1411
+ return new RegExp(`^${pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "i");
1412
+ }
1413
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
1414
+ return new RegExp(`^${escaped}$`, "i");
1415
+ }
1416
+ function filterByNamespace(entries, pattern) {
1417
+ const matcher = typeof pattern === "string" ? toRegex(pattern) : pattern;
1418
+ return entries.filter((entry) => matcher.test(entry.namespace));
1419
+ }
1420
+ function filterByLevel(entries, level) {
1421
+ const allowed = Array.isArray(level) ? new Set(level) : /* @__PURE__ */ new Set([level]);
1422
+ return entries.filter((entry) => allowed.has(entry.level));
1423
+ }
1424
+ function filterByTimeRange(entries, from, to) {
1425
+ return entries.filter((entry) => {
1426
+ if (from !== void 0 && entry.timestamp < from) {
1427
+ return false;
1428
+ }
1429
+ if (to !== void 0 && entry.timestamp > to) {
1430
+ return false;
1431
+ }
1432
+ return true;
1433
+ });
1434
+ }
1435
+ function searchInLogs(entries, query) {
1436
+ const lowered = query.toLowerCase();
1437
+ return entries.filter((entry) => {
1438
+ if (entry.message.toLowerCase().includes(lowered)) {
1439
+ return true;
1440
+ }
1441
+ if (entry.namespace.toLowerCase().includes(lowered)) {
1442
+ return true;
1443
+ }
1444
+ if (entry.meta) {
1445
+ const metaString = JSON.stringify(entry.meta).toLowerCase();
1446
+ if (metaString.includes(lowered)) {
1447
+ return true;
1448
+ }
1449
+ }
1450
+ return false;
1451
+ });
1452
+ }
1453
+ function filterDebugEntries(entries, options) {
1454
+ let filtered = [...entries];
1455
+ if (options.namespace) {
1456
+ filtered = filterByNamespace(filtered, options.namespace);
1457
+ }
1458
+ if (options.level) {
1459
+ filtered = filterByLevel(filtered, options.level);
1460
+ }
1461
+ if (options.timeRange) {
1462
+ filtered = filterByTimeRange(filtered, options.timeRange.from, options.timeRange.to);
1463
+ }
1464
+ if (options.search) {
1465
+ filtered = searchInLogs(filtered, options.search);
1466
+ }
1467
+ if (options.traceId) {
1468
+ filtered = filtered.filter((entry) => entry.traceId === options.traceId);
1469
+ }
1470
+ return filtered;
1471
+ }
1472
+ function groupByNamespace(entries) {
1473
+ const map = /* @__PURE__ */ new Map();
1474
+ for (const entry of entries) {
1475
+ if (!map.has(entry.namespace)) {
1476
+ map.set(entry.namespace, []);
1477
+ }
1478
+ map.get(entry.namespace).push(entry);
1479
+ }
1480
+ return map;
1481
+ }
1482
+ function groupByGroup(entries) {
1483
+ const map = /* @__PURE__ */ new Map();
1484
+ for (const entry of entries) {
1485
+ const group = entry.group ?? "default";
1486
+ if (!map.has(group)) {
1487
+ map.set(group, []);
1488
+ }
1489
+ map.get(group).push(entry);
1490
+ }
1491
+ return map;
1492
+ }
1493
+ function createDebugTree(entries) {
1494
+ if (entries.length === 0) {
1495
+ return null;
1496
+ }
1497
+ const sorted = [...entries].sort((a, b) => a.timestamp - b.timestamp);
1498
+ const nodes = /* @__PURE__ */ new Map();
1499
+ let root = null;
1500
+ function ensureNode(entry) {
1501
+ if (entry.spanId && nodes.has(entry.spanId)) {
1502
+ return nodes.get(entry.spanId);
1503
+ }
1504
+ const node = { entry, children: [], depth: 0 };
1505
+ if (entry.spanId) {
1506
+ nodes.set(entry.spanId, node);
1507
+ }
1508
+ return node;
1509
+ }
1510
+ for (const entry of sorted) {
1511
+ const node = ensureNode(entry);
1512
+ if (entry.parentSpanId && nodes.has(entry.parentSpanId)) {
1513
+ const parent = nodes.get(entry.parentSpanId);
1514
+ node.depth = parent.depth + 1;
1515
+ parent.children.push(node);
1516
+ } else if (root === null) {
1517
+ root = node;
1518
+ } else {
1519
+ node.depth = root.depth + 1;
1520
+ root.children.push(node);
1521
+ }
1522
+ }
1523
+ return root;
1524
+ }
1525
+ function exportToJSON(entries, options = {}) {
1526
+ const filtered = options.filter ? filterDebugEntries(entries, options.filter) : entries;
1527
+ if (options.includeMeta === false) {
1528
+ return JSON.stringify(
1529
+ filtered.map(({ meta, ...rest }) => rest),
1530
+ null,
1531
+ 2
1532
+ );
1533
+ }
1534
+ return JSON.stringify(filtered, null, 2);
1535
+ }
1536
+ function exportToChromeFormat(entries, options = {}) {
1537
+ const filtered = options.filter ? filterDebugEntries(entries, options.filter) : entries;
1538
+ const traceEvents = filtered.map((entry) => ({
1539
+ name: entry.message,
1540
+ cat: entry.namespace,
1541
+ ph: entry.level === "error" ? "E" : entry.level === "warn" ? "W" : "X",
1542
+ ts: entry.timestamp * 1e3,
1543
+ dur: (entry.duration ?? 0) * 1e3,
1544
+ pid: 1,
1545
+ tid: entry.spanId ?? entry.namespace,
1546
+ args: entry.meta ?? {}
1547
+ }));
1548
+ return JSON.stringify({ traceEvents }, null, 2);
1549
+ }
1550
+ function exportToPlainText(entries, options = {}) {
1551
+ const filtered = options.filter ? filterDebugEntries(entries, options.filter) : entries;
1552
+ return formatDebugEntriesHuman(filtered, { groupBy: "namespace", showTimestamp: true, showDuration: true });
1553
+ }
1554
+ function exportDebugEntries(entries, options) {
1555
+ const format = options.format ?? "json";
1556
+ switch (format) {
1557
+ case "chrome":
1558
+ return exportToChromeFormat(entries, options);
1559
+ case "text":
1560
+ return exportToPlainText(entries, options);
1561
+ case "json":
1562
+ default:
1563
+ return exportToJSON(entries, options);
1564
+ }
1565
+ }
1566
+ function describeEntriesHuman(entries, options = {}) {
1567
+ const filtered = filterDebugEntries(entries, options);
1568
+ return formatDebugEntriesHuman(filtered, { showTimestamp: true, showDuration: true, groupBy: "namespace" });
1569
+ }
1570
+ function describeEntriesAI(entries, options = {}) {
1571
+ const filtered = filterDebugEntries(entries, options);
1572
+ return formatDebugEntriesAI(filtered);
1573
+ }
1574
+ function describeEntriesTimeline(entries, options = {}) {
1575
+ const filtered = filterDebugEntries(entries, options);
1576
+ return formatTimelineWithSummary(filtered);
1577
+ }
1578
+
1579
+ // src/debug/formatters/timeline.ts
1580
+ function formatDuration2(duration) {
1581
+ if (duration < 1e3) {
1582
+ return `${duration}ms`;
1583
+ }
1584
+ return `${(duration / 1e3).toFixed(2)}s`;
1585
+ }
1586
+ function formatTimelineNode(node, isLast, prefix = "", maxDepth) {
1587
+ const lines = [];
1588
+ const connector = isLast ? "\u2514\u2500" : "\u251C\u2500";
1589
+ const parts = [];
1590
+ parts.push(safeColors.bold(`[${node.entry.namespace}]`));
1591
+ parts.push(node.entry.message);
1592
+ if (typeof node.entry.duration === "number") {
1593
+ parts.push(safeColors.dim(`(${formatDuration2(node.entry.duration)})`));
1594
+ }
1595
+ if (node.entry.level === "error") {
1596
+ parts.push(safeColors.error(safeSymbols.error));
1597
+ } else if (node.entry.level === "warn") {
1598
+ parts.push(safeColors.warning(safeSymbols.warning));
1599
+ }
1600
+ lines.push(`${prefix}${connector} ${parts.join(" ")}`.trimEnd());
1601
+ if (maxDepth !== void 0 && node.depth + 1 >= maxDepth) {
1602
+ return lines;
1603
+ }
1604
+ const childPrefix = prefix + (isLast ? " " : "\u2502 ");
1605
+ for (let index = 0; index < node.children.length; index++) {
1606
+ const child = node.children[index];
1607
+ if (!child) {
1608
+ continue;
1609
+ }
1610
+ const childIsLast = index === node.children.length - 1;
1611
+ lines.push(...formatTimelineNode(child, childIsLast, childPrefix, maxDepth));
1612
+ }
1613
+ return lines;
1614
+ }
1615
+ function formatTimeline(entries) {
1616
+ if (entries.length === 0) {
1617
+ return "";
1618
+ }
1619
+ const tree = createDebugTree(entries);
1620
+ if (!tree) {
1621
+ return "";
1622
+ }
1623
+ return formatTimelineNode(tree, true).join("\n");
1624
+ }
1625
+ function formatTimelineWithSummary(entries) {
1626
+ const timeline = formatTimeline(entries);
1627
+ if (timeline.length === 0) {
1628
+ return "";
1629
+ }
1630
+ const totalDuration = entries.reduce((acc, entry) => acc + (entry.duration ?? 0), 0);
1631
+ const errorCount = entries.filter((entry) => entry.level === "error").length;
1632
+ const warnCount = entries.filter((entry) => entry.level === "warn").length;
1633
+ const summaryParts = [];
1634
+ if (totalDuration > 0) {
1635
+ summaryParts.push(`Total: ${formatDuration2(totalDuration)}`);
1636
+ }
1637
+ if (errorCount > 0) {
1638
+ summaryParts.push(safeColors.error(`${errorCount} errors`));
1639
+ }
1640
+ if (warnCount > 0) {
1641
+ summaryParts.push(safeColors.warning(`${warnCount} warnings`));
1642
+ }
1643
+ if (summaryParts.length === 0) {
1644
+ return timeline;
1645
+ }
1646
+ return `${timeline}
1647
+
1648
+ ${safeColors.bold("Summary:")} ${summaryParts.join(", ")}`;
1649
+ }
1650
+
1651
+ // src/debug/components/output.ts
1652
+ function formatDebugOutput(entry, options = {}) {
1653
+ if (shouldUseAIFormat(options.format)) {
1654
+ return formatDebugEntryAI(entry);
1655
+ }
1656
+ return formatDebugEntryHuman(entry, options);
1657
+ }
1658
+ function formatDebugOutputs(entries, options = {}) {
1659
+ if (shouldUseAIFormat(options.format)) {
1660
+ return formatDebugEntriesAI(entries);
1661
+ }
1662
+ if (options.useTimeline) {
1663
+ return formatTimelineWithSummary(entries);
1664
+ }
1665
+ return formatDebugEntriesHuman(entries, options);
1666
+ }
1667
+ var DebugSection = class {
1668
+ entries = [];
1669
+ title;
1670
+ options;
1671
+ constructor(title, options = {}) {
1672
+ this.title = title;
1673
+ this.options = options;
1674
+ }
1675
+ add(entry) {
1676
+ this.entries.push(entry);
1677
+ }
1678
+ addAll(entries) {
1679
+ this.entries.push(...entries);
1680
+ }
1681
+ clear() {
1682
+ this.entries.length = 0;
1683
+ }
1684
+ format() {
1685
+ if (this.entries.length === 0) {
1686
+ return "";
1687
+ }
1688
+ const content = formatDebugOutputs(this.entries, this.options);
1689
+ if (!content) {
1690
+ return "";
1691
+ }
1692
+ if (shouldUseAIFormat(this.options.format)) {
1693
+ return content;
1694
+ }
1695
+ return box(this.title, content.split("\n"));
1696
+ }
1697
+ get count() {
1698
+ return this.entries.length;
1699
+ }
1700
+ };
1701
+ var DebugOutput = class {
1702
+ sections = /* @__PURE__ */ new Map();
1703
+ globalEntries = [];
1704
+ options;
1705
+ constructor(options = {}) {
1706
+ this.options = options;
1707
+ }
1708
+ add(entry) {
1709
+ this.globalEntries.push(entry);
1710
+ }
1711
+ addToSection(sectionName, entry) {
1712
+ if (!this.sections.has(sectionName)) {
1713
+ this.sections.set(sectionName, new DebugSection(sectionName, this.options));
1714
+ }
1715
+ this.sections.get(sectionName).add(entry);
1716
+ }
1717
+ getSection(sectionName) {
1718
+ if (!this.sections.has(sectionName)) {
1719
+ this.sections.set(sectionName, new DebugSection(sectionName, this.options));
1720
+ }
1721
+ return this.sections.get(sectionName);
1722
+ }
1723
+ format() {
1724
+ const parts = [];
1725
+ if (this.globalEntries.length > 0) {
1726
+ const formatted = formatDebugOutputs(this.globalEntries, this.options);
1727
+ if (formatted) {
1728
+ parts.push(formatted);
1729
+ }
1730
+ }
1731
+ for (const [, section2] of this.sections) {
1732
+ const formatted = section2.format();
1733
+ if (formatted) {
1734
+ parts.push(formatted);
1735
+ }
1736
+ }
1737
+ return parts.join("\n\n");
1738
+ }
1739
+ clear() {
1740
+ this.globalEntries.length = 0;
1741
+ this.sections.clear();
1742
+ }
1743
+ get totalCount() {
1744
+ let count = this.globalEntries.length;
1745
+ for (const section2 of this.sections.values()) {
1746
+ count += section2.count;
1747
+ }
1748
+ return count;
1749
+ }
1750
+ };
1751
+
1752
+ // src/debug/components/tree.ts
1753
+ var DebugTree = class {
1754
+ tree = null;
1755
+ options;
1756
+ constructor(entries, options = {}) {
1757
+ this.options = options;
1758
+ this.tree = createDebugTree(entries);
1759
+ }
1760
+ update(entries) {
1761
+ this.tree = createDebugTree(entries);
1762
+ }
1763
+ format() {
1764
+ if (!this.tree) {
1765
+ return "";
1766
+ }
1767
+ const lines = formatTimelineNode(this.tree, true, "", this.options.maxDepth);
1768
+ if (this.options.showSummary) {
1769
+ const summary = this.getSummary();
1770
+ if (summary) {
1771
+ lines.push("", summary);
1772
+ }
1773
+ }
1774
+ return lines.join("\n");
1775
+ }
1776
+ getSummary() {
1777
+ if (!this.tree) {
1778
+ return "";
1779
+ }
1780
+ const stats = this.collectStats(this.tree);
1781
+ const parts = [];
1782
+ if (stats.totalDuration > 0) {
1783
+ parts.push(`total ${stats.totalDuration}ms`);
1784
+ }
1785
+ if (stats.errorCount > 0) {
1786
+ parts.push(`${stats.errorCount} errors`);
1787
+ }
1788
+ if (stats.warnCount > 0) {
1789
+ parts.push(`${stats.warnCount} warnings`);
1790
+ }
1791
+ parts.push(`${stats.nodeCount} nodes`);
1792
+ return `Summary: ${parts.join(", ")}`;
1793
+ }
1794
+ collectStats(node) {
1795
+ let totalDuration = node.entry.duration ?? 0;
1796
+ let errorCount = node.entry.level === "error" ? 1 : 0;
1797
+ let warnCount = node.entry.level === "warn" ? 1 : 0;
1798
+ let nodeCount = 1;
1799
+ for (const child of node.children) {
1800
+ const childStats = this.collectStats(child);
1801
+ totalDuration += childStats.totalDuration;
1802
+ errorCount += childStats.errorCount;
1803
+ warnCount += childStats.warnCount;
1804
+ nodeCount += childStats.nodeCount;
1805
+ }
1806
+ return { totalDuration, errorCount, warnCount, nodeCount };
1807
+ }
1808
+ get root() {
1809
+ return this.tree;
1810
+ }
1811
+ };
1812
+
1813
+ // src/debug/components/trace.ts
1814
+ var DebugTrace = class {
1815
+ entries = [];
1816
+ options;
1817
+ constructor(entries = [], options = {}) {
1818
+ this.entries.push(...entries);
1819
+ this.options = options;
1820
+ }
1821
+ add(entry) {
1822
+ this.entries.push(entry);
1823
+ }
1824
+ addAll(entries) {
1825
+ this.entries.push(...entries);
1826
+ }
1827
+ clear() {
1828
+ this.entries.length = 0;
1829
+ }
1830
+ format() {
1831
+ if (this.entries.length === 0) {
1832
+ return "";
1833
+ }
1834
+ const sorted = [...this.entries].sort((a, b) => a.timestamp - b.timestamp);
1835
+ if (this.options.groupByPlugin) {
1836
+ return this.formatGrouped(sorted);
1837
+ }
1838
+ return formatTimelineWithSummary(sorted);
1839
+ }
1840
+ formatGrouped(entries) {
1841
+ const groups = /* @__PURE__ */ new Map();
1842
+ for (const entry of entries) {
1843
+ const plugin = entry.namespace.split(":")[0] ?? entry.namespace;
1844
+ if (!groups.has(plugin)) {
1845
+ groups.set(plugin, []);
1846
+ }
1847
+ groups.get(plugin).push(entry);
1848
+ }
1849
+ const parts = [];
1850
+ for (const [plugin, pluginEntries] of groups) {
1851
+ const tree = new DebugTree(pluginEntries, {
1852
+ showSummary: this.options.showSummary,
1853
+ maxDepth: this.options.maxDepth
1854
+ });
1855
+ const formatted = tree.format();
1856
+ if (formatted) {
1857
+ parts.push(`[${plugin}]`, formatted);
1858
+ }
1859
+ }
1860
+ return parts.join("\n\n");
1861
+ }
1862
+ getStats() {
1863
+ const plugins = /* @__PURE__ */ new Set();
1864
+ let totalDuration = 0;
1865
+ let errorCount = 0;
1866
+ let warnCount = 0;
1867
+ for (const entry of this.entries) {
1868
+ const plugin = entry.namespace.split(":")[0] ?? entry.namespace;
1869
+ plugins.add(plugin);
1870
+ totalDuration += entry.duration ?? 0;
1871
+ if (entry.level === "error") {
1872
+ errorCount += 1;
1873
+ } else if (entry.level === "warn") {
1874
+ warnCount += 1;
1875
+ }
1876
+ }
1877
+ return {
1878
+ totalEntries: this.entries.length,
1879
+ plugins: Array.from(plugins),
1880
+ totalDuration,
1881
+ errorCount,
1882
+ warnCount
1883
+ };
1884
+ }
1885
+ };
1886
+
1887
+ // src/command-runner.ts
1888
+ function createCommandRunner(options) {
1889
+ return async (ctx, argv, flags) => {
1890
+ const tracker = new TimingTracker();
1891
+ const jsonMode = flags.json === true;
1892
+ const quietMode = flags.quiet === true;
1893
+ let runScope = null;
1894
+ if (options.analytics !== void 0) {
1895
+ try {
1896
+ const analyticsModule = await import('@kb-labs/analytics-sdk-node');
1897
+ if (analyticsModule.runScope) {
1898
+ runScope = analyticsModule.runScope;
1899
+ }
1900
+ } catch {
1901
+ runScope = null;
1902
+ }
1903
+ }
1904
+ const execute = async () => {
1905
+ tracker.checkpoint("start");
1906
+ try {
1907
+ const result2 = await options.execute(ctx, flags, tracker);
1908
+ tracker.checkpoint("complete");
1909
+ formatSuccessOutput(ctx, options.title, result2, tracker.total(), {
1910
+ jsonMode,
1911
+ quietMode
1912
+ });
1913
+ return 0;
1914
+ } catch (error) {
1915
+ tracker.checkpoint("error");
1916
+ const message = error instanceof Error ? error.message : String(error);
1917
+ formatErrorOutput(ctx, message, tracker.total(), {
1918
+ jsonMode,
1919
+ quietMode
1920
+ });
1921
+ return 1;
1922
+ }
1923
+ };
1924
+ if (!runScope || !options.analytics) {
1925
+ return execute();
1926
+ }
1927
+ const totalStart = Date.now();
1928
+ const result = await runScope(
1929
+ {
1930
+ actor: options.analytics.actor,
1931
+ ctx: { workspace: ctx.cwd }
1932
+ },
1933
+ async (emit) => {
1934
+ await emit({
1935
+ type: options.analytics.started,
1936
+ payload: options.analytics.getPayload?.(flags) ?? {}
1937
+ });
1938
+ let exitCode = 0;
1939
+ try {
1940
+ exitCode = await execute();
1941
+ await emit({
1942
+ type: options.analytics.finished,
1943
+ payload: {
1944
+ ...options.analytics.getPayload?.(flags) ?? {},
1945
+ durationMs: Date.now() - totalStart,
1946
+ result: exitCode === 0 ? "success" : "error"
1947
+ }
1948
+ });
1949
+ } catch (error) {
1950
+ await emit({
1951
+ type: options.analytics.finished,
1952
+ payload: {
1953
+ ...options.analytics.getPayload?.(flags) ?? {},
1954
+ durationMs: Date.now() - totalStart,
1955
+ result: "error",
1956
+ error: error instanceof Error ? error.message : String(error)
1957
+ }
1958
+ });
1959
+ throw error;
1960
+ }
1961
+ return exitCode;
1962
+ }
1963
+ );
1964
+ return result;
1965
+ };
1966
+ }
1967
+ function formatSuccessOutput(ctx, title, result, durationMs, flags) {
1968
+ if (flags.jsonMode) {
1969
+ const payload = {
1970
+ ok: true,
1971
+ summary: result.summary,
1972
+ timing: result.timing ?? durationMs,
1973
+ diagnostics: result.diagnostics,
1974
+ warnings: result.warnings,
1975
+ errors: result.errors
1976
+ };
1977
+ if (result.artifacts) {
1978
+ payload.artifacts = result.artifacts;
1979
+ }
1980
+ if (result.data) {
1981
+ Object.assign(payload, result.data);
1982
+ }
1983
+ ctx.presenter.json(payload);
1984
+ return;
1985
+ }
1986
+ if (flags.quietMode) {
1987
+ return;
1988
+ }
1989
+ const statusEntry = extractStatusEntry(result.summary);
1990
+ const summaryForDisplay = statusEntry ? { ...result.summary } : result.summary;
1991
+ if (statusEntry) {
1992
+ delete summaryForDisplay[statusEntry.key];
1993
+ }
1994
+ const lines = [];
1995
+ const summaryLines = keyValue(summaryForDisplay);
1996
+ if (summaryLines.length > 0) {
1997
+ lines.push(...summaryLines);
1998
+ }
1999
+ if (result.artifacts && result.artifacts.length > 0) {
2000
+ if (lines.length > 0) {
2001
+ lines.push("");
2002
+ }
2003
+ lines.push(...displayArtifacts(result.artifacts, result.artifactsOptions));
2004
+ }
2005
+ const timing = result.timing ?? durationMs;
2006
+ if (typeof timing !== "number") {
2007
+ const entries = Object.entries(timing);
2008
+ if (entries.length > 0) {
2009
+ if (lines.length > 0) {
2010
+ lines.push("");
2011
+ }
2012
+ lines.push(safeColors.bold("Timing"));
2013
+ for (const [label, value] of entries) {
2014
+ lines.push(...safeKeyValue({ [label]: formatTiming(value) }, { indent: 2, pad: false }));
2015
+ }
2016
+ }
2017
+ }
2018
+ if (result.diagnostics && result.diagnostics.length > 0) {
2019
+ if (lines.length > 0) {
2020
+ lines.push("");
2021
+ }
2022
+ lines.push(safeColors.bold("Diagnostics"));
2023
+ result.diagnostics.forEach((item) => lines.push(safeColors.muted(`- ${item}`)));
2024
+ }
2025
+ if (result.warnings && result.warnings.length > 0) {
2026
+ if (lines.length > 0) {
2027
+ lines.push("");
2028
+ }
2029
+ lines.push(safeColors.bold("Warnings"));
2030
+ result.warnings.forEach((item) => lines.push(safeColors.muted(`- ${item}`)));
2031
+ }
2032
+ if (result.errors && result.errors.length > 0) {
2033
+ if (lines.length > 0) {
2034
+ lines.push("");
2035
+ }
2036
+ lines.push(safeColors.bold("Errors"));
2037
+ result.errors.forEach((item) => lines.push(safeColors.muted(`- ${item}`)));
2038
+ }
2039
+ if (lines.length > 0) {
2040
+ lines.push("");
2041
+ }
2042
+ lines.push(formatStatusLine(statusEntry?.value, durationMs));
2043
+ ctx.presenter.write(box(title, lines));
2044
+ }
2045
+ function formatErrorOutput(ctx, errorMessage, durationMs, flags) {
2046
+ if (flags.jsonMode) {
2047
+ ctx.presenter.json({
2048
+ ok: false,
2049
+ error: errorMessage,
2050
+ timing: durationMs
2051
+ });
2052
+ return;
2053
+ }
2054
+ if (flags.quietMode) {
2055
+ return;
2056
+ }
2057
+ ctx.presenter.error(errorMessage);
2058
+ }
2059
+ function extractStatusEntry(summary) {
2060
+ for (const [key, value] of Object.entries(summary)) {
2061
+ if (typeof value === "string" && key.toLowerCase().includes("status")) {
2062
+ return { key, value };
2063
+ }
2064
+ }
2065
+ return null;
2066
+ }
2067
+ function formatStatusLine(statusValue, durationMs) {
2068
+ const rawStatus = statusValue ?? "Done";
2069
+ const normalized = rawStatus.toLowerCase();
2070
+ let symbol = safeSymbols.success;
2071
+ let colorize = safeColors.success;
2072
+ if (normalized.includes("error") || normalized.includes("fail")) {
2073
+ symbol = safeSymbols.error;
2074
+ colorize = safeColors.error;
2075
+ } else if (normalized.includes("partial") || normalized.includes("warn")) {
2076
+ symbol = safeSymbols.warning;
2077
+ colorize = safeColors.warning;
2078
+ }
2079
+ const statusText = hasAnsi(rawStatus) ? rawStatus : colorize(rawStatus);
2080
+ return `${symbol} ${statusText} \xB7 ${safeColors.muted(formatTiming(durationMs))}`;
2081
+ }
2082
+
2083
+ // src/utils/flags.ts
2084
+ function defineFlags(schema) {
2085
+ return {
2086
+ schema,
2087
+ type: {},
2088
+ parse: (input) => parseFlagsFromInput(input, schema)
2089
+ };
2090
+ }
2091
+ function parseFlagsFromInput(input, schema) {
2092
+ const result = {};
2093
+ const rawInput = input;
2094
+ for (const [key, spec] of Object.entries(schema)) {
2095
+ const value = rawInput?.[key];
2096
+ if (value === void 0) {
2097
+ if ("default" in spec) {
2098
+ result[key] = spec.default;
2099
+ }
2100
+ continue;
2101
+ }
2102
+ switch (spec.type) {
2103
+ case "boolean":
2104
+ result[key] = parseBoolean(value, key);
2105
+ break;
2106
+ case "string":
2107
+ result[key] = parseString(value, key);
2108
+ if (spec.validate && result[key] !== void 0) {
2109
+ spec.validate(result[key]);
2110
+ }
2111
+ break;
2112
+ case "number":
2113
+ result[key] = parseNumber(value, key);
2114
+ if (spec.validate && result[key] !== void 0) {
2115
+ spec.validate(result[key]);
2116
+ }
2117
+ break;
2118
+ }
2119
+ }
2120
+ return result;
2121
+ }
2122
+ function parseBoolean(value, flagName) {
2123
+ if (typeof value === "boolean") {
2124
+ return value;
2125
+ }
2126
+ if (typeof value === "string") {
2127
+ const lower = value.toLowerCase();
2128
+ if (lower === "true" || lower === "1" || lower === "yes") {
2129
+ return true;
2130
+ }
2131
+ if (lower === "false" || lower === "0" || lower === "no") {
2132
+ return false;
2133
+ }
2134
+ }
2135
+ throw new Error(
2136
+ `Flag "${flagName}" must be boolean, got ${typeof value}. Use true/false or 1/0 or yes/no.`
2137
+ );
2138
+ }
2139
+ function parseString(value, flagName) {
2140
+ if (typeof value === "string") {
2141
+ return value;
2142
+ }
2143
+ if (typeof value === "number") {
2144
+ return String(value);
2145
+ }
2146
+ throw new Error(
2147
+ `Flag "${flagName}" must be string, got ${typeof value}.`
2148
+ );
2149
+ }
2150
+ function parseNumber(value, flagName) {
2151
+ if (typeof value === "number") {
2152
+ if (!Number.isFinite(value)) {
2153
+ throw new Error(`Flag "${flagName}" must be finite number, got ${value}.`);
2154
+ }
2155
+ return value;
2156
+ }
2157
+ if (typeof value === "string") {
2158
+ const trimmed = value.trim();
2159
+ const parsed = Number(trimmed);
2160
+ if (!Number.isFinite(parsed)) {
2161
+ throw new Error(
2162
+ `Flag "${flagName}" must be number, got invalid string "${value}".`
2163
+ );
2164
+ }
2165
+ return parsed;
2166
+ }
2167
+ throw new Error(
2168
+ `Flag "${flagName}" must be number, got ${typeof value}.`
2169
+ );
2170
+ }
2171
+ function parseNumberFlag(value) {
2172
+ if (typeof value === "number") {
2173
+ return Number.isFinite(value) ? value : void 0;
2174
+ }
2175
+ if (typeof value === "string") {
2176
+ const trimmed = value.trim();
2177
+ if (trimmed.length === 0) {
2178
+ return void 0;
2179
+ }
2180
+ const parsed = Number(trimmed);
2181
+ return Number.isFinite(parsed) ? parsed : void 0;
2182
+ }
2183
+ return void 0;
2184
+ }
2185
+ function mergeFlags(input) {
2186
+ if (!input.flags || typeof input.flags !== "object") {
2187
+ return input;
2188
+ }
2189
+ return { ...input, ...input.flags };
2190
+ }
2191
+
2192
+ // src/utils/env.ts
2193
+ function defineEnv(schema) {
2194
+ return {
2195
+ schema,
2196
+ type: {},
2197
+ parse: (runtime) => parseEnvFromRuntime(runtime, schema)
2198
+ };
2199
+ }
2200
+ function parseEnvFromRuntime(runtime, schema) {
2201
+ const result = {};
2202
+ for (const [key, spec] of Object.entries(schema)) {
2203
+ const rawValue = runtime.env(key);
2204
+ if (rawValue === void 0) {
2205
+ if ("default" in spec) {
2206
+ result[key] = spec.default;
2207
+ }
2208
+ continue;
2209
+ }
2210
+ result[key] = parseEnvValue(rawValue, key, spec);
2211
+ }
2212
+ return result;
2213
+ }
2214
+ function parseEnvValue(value, key, spec) {
2215
+ if (value === void 0) {
2216
+ return void 0;
2217
+ }
2218
+ switch (spec.type) {
2219
+ case "boolean":
2220
+ return parseBoolean(value, key);
2221
+ case "string":
2222
+ const strValue = parseString(value, key);
2223
+ if (spec.validate) {
2224
+ spec.validate(strValue);
2225
+ }
2226
+ return strValue;
2227
+ case "number":
2228
+ const numValue = parseNumber(value, key);
2229
+ if (spec.validate) {
2230
+ spec.validate(numValue);
2231
+ }
2232
+ return numValue;
2233
+ default:
2234
+ return value;
2235
+ }
2236
+ }
2237
+
2238
+ // src/utils/context.ts
2239
+ function getContextCwd(input) {
2240
+ if (input && typeof input.cwd === "string" && input.cwd.length > 0) {
2241
+ return input.cwd;
2242
+ }
2243
+ return process.cwd();
2244
+ }
2245
+
2246
+ // src/utils/path.ts
2247
+ function toPosixPath(input) {
2248
+ return input.replace(/\\/g, "/");
2249
+ }
2250
+
2251
+ // src/modern-format.ts
2252
+ function sideBorderBox(options) {
2253
+ const { title, sections, footer, status, timing } = options;
2254
+ const lines = [];
2255
+ const titleLine = `${safeSymbols.topLeft}${safeSymbols.separator.repeat(2)} ${safeColors.primary(safeColors.bold(title))}`;
2256
+ lines.push(titleLine);
2257
+ lines.push(safeSymbols.border);
2258
+ for (let i = 0; i < sections.length; i++) {
2259
+ const section2 = sections[i];
2260
+ if (!section2) {
2261
+ continue;
2262
+ }
2263
+ if (section2.header) {
2264
+ lines.push(`${safeSymbols.border} ${safeColors.bold(section2.header)}`);
2265
+ }
2266
+ for (const item of section2.items) {
2267
+ lines.push(`${safeSymbols.border} ${item}`);
2268
+ }
2269
+ if (i < sections.length - 1) {
2270
+ lines.push(safeSymbols.border);
2271
+ }
2272
+ }
2273
+ if (footer || status || timing !== void 0) {
2274
+ lines.push(safeSymbols.border);
2275
+ const footerParts = [];
2276
+ if (footer) {
2277
+ footerParts.push(footer);
2278
+ } else if (status) {
2279
+ const statusSymbol = getStatusSymbol(status);
2280
+ const statusText = getStatusText(status);
2281
+ const statusColor = getStatusColor(status);
2282
+ footerParts.push(statusColor(`${statusSymbol} ${statusText}`));
2283
+ }
2284
+ if (timing !== void 0) {
2285
+ footerParts.push(formatTiming2(timing));
2286
+ }
2287
+ const footerLine = `${safeSymbols.bottomLeft}${safeSymbols.separator.repeat(2)} ${footerParts.join(" / ")}`;
2288
+ lines.push(footerLine);
2289
+ }
2290
+ return lines.join("\n");
2291
+ }
2292
+ function sectionHeader(text) {
2293
+ return safeColors.bold(text);
2294
+ }
2295
+ function metricsList(metrics) {
2296
+ const entries = Object.entries(metrics);
2297
+ if (entries.length === 0) {
2298
+ return [];
2299
+ }
2300
+ const maxKeyLength = Math.max(
2301
+ ...entries.map(([key]) => stripAnsi(key).length)
2302
+ );
2303
+ return entries.map(([key, value]) => {
2304
+ const keyLength = stripAnsi(key).length;
2305
+ const padding = " ".repeat(maxKeyLength - keyLength + 2);
2306
+ const formattedKey = safeColors.bold(key);
2307
+ const formattedValue = safeColors.muted(String(value));
2308
+ return `${formattedKey}:${padding}${formattedValue}`;
2309
+ });
2310
+ }
2311
+ var bulletList2 = bulletList;
2312
+ var formatTiming2 = formatTiming;
2313
+ function statusLine(status, timing) {
2314
+ const symbol = getStatusSymbol(status);
2315
+ const text = getStatusText(status);
2316
+ const color = getStatusColor(status);
2317
+ const parts = [color(`${symbol} ${text}`)];
2318
+ if (timing !== void 0) {
2319
+ parts.push(formatTiming2(timing));
2320
+ }
2321
+ return parts.join(" / ");
2322
+ }
2323
+ function getStatusSymbol(status) {
2324
+ switch (status) {
2325
+ case "success":
2326
+ return safeSymbols.success;
2327
+ case "error":
2328
+ return safeSymbols.error;
2329
+ case "warning":
2330
+ return safeSymbols.warning;
2331
+ case "info":
2332
+ return safeSymbols.info;
2333
+ }
2334
+ }
2335
+ function getStatusText(status) {
2336
+ switch (status) {
2337
+ case "success":
2338
+ return "Success";
2339
+ case "error":
2340
+ return "Failed";
2341
+ case "warning":
2342
+ return "Warning";
2343
+ case "info":
2344
+ return "Info";
2345
+ }
2346
+ }
2347
+ function getStatusColor(status) {
2348
+ switch (status) {
2349
+ case "success":
2350
+ return safeColors.success;
2351
+ case "error":
2352
+ return safeColors.error;
2353
+ case "warning":
2354
+ return safeColors.warning;
2355
+ case "info":
2356
+ return safeColors.info;
2357
+ }
2358
+ }
2359
+ function formatCommandHelp(options) {
2360
+ const { title, description, longDescription, examples, flags, aliases } = options;
2361
+ const sections = [];
2362
+ if (description) {
2363
+ sections.push({
2364
+ header: "Description",
2365
+ items: [description]
2366
+ });
2367
+ }
2368
+ if (longDescription) {
2369
+ sections.push({
2370
+ header: "Details",
2371
+ items: [longDescription]
2372
+ });
2373
+ }
2374
+ if (aliases && aliases.length > 0) {
2375
+ sections.push({
2376
+ header: "Aliases",
2377
+ items: aliases.map((a) => safeColors.muted(a))
2378
+ });
2379
+ }
2380
+ if (flags && flags.length > 0) {
2381
+ const flagItems = flags.map((flag) => {
2382
+ const label = flag.alias ? `--${flag.name}, -${flag.alias}` : `--${flag.name}`;
2383
+ const required = flag.required ? safeColors.warning(" (required)") : "";
2384
+ const desc = flag.description ? safeColors.muted(` \u2014 ${flag.description}`) : "";
2385
+ return `${safeColors.bold(label)}${required}${desc}`;
2386
+ });
2387
+ sections.push({
2388
+ header: "Flags",
2389
+ items: flagItems
2390
+ });
2391
+ }
2392
+ if (examples && examples.length > 0) {
2393
+ sections.push({
2394
+ header: "Examples",
2395
+ items: examples.map((ex) => safeColors.muted(` ${ex}`))
2396
+ });
2397
+ }
2398
+ return sideBorderBox({
2399
+ title,
2400
+ sections,
2401
+ status: "info"
2402
+ });
2403
+ }
2404
+
2405
+ // src/command-result.ts
2406
+ function formatCommandResult(params) {
2407
+ const {
2408
+ title,
2409
+ summary,
2410
+ details = [],
2411
+ warnings = [],
2412
+ errors = [],
2413
+ timing,
2414
+ status,
2415
+ jsonData
2416
+ } = params;
2417
+ const sections = [];
2418
+ if (summary && Object.keys(summary).length > 0) {
2419
+ sections.push({
2420
+ header: "Summary",
2421
+ items: metricsList(summary)
2422
+ });
2423
+ }
2424
+ for (const detail of details) {
2425
+ sections.push({
2426
+ header: detail.section,
2427
+ items: detail.items
2428
+ });
2429
+ }
2430
+ if (warnings.length > 0) {
2431
+ sections.push({
2432
+ header: "\u26A0 Warnings",
2433
+ items: bulletList2(warnings)
2434
+ });
2435
+ }
2436
+ if (errors.length > 0) {
2437
+ sections.push({
2438
+ header: "\u2717 Errors",
2439
+ items: bulletList2(errors)
2440
+ });
2441
+ }
2442
+ const human = sideBorderBox({
2443
+ title,
2444
+ sections,
2445
+ status,
2446
+ timing
2447
+ });
2448
+ const json = {
2449
+ ok: status === "success",
2450
+ status,
2451
+ ...summary && { summary },
2452
+ ...details.length > 0 && {
2453
+ details: details.reduce((acc, d) => {
2454
+ acc[d.section] = d.items;
2455
+ return acc;
2456
+ }, {})
2457
+ },
2458
+ ...warnings.length > 0 && { warnings },
2459
+ ...errors.length > 0 && { errors },
2460
+ ...timing !== void 0 && { timingMs: timing },
2461
+ ...jsonData && { data: jsonData }
2462
+ };
2463
+ return {
2464
+ ok: status === "success",
2465
+ status,
2466
+ human,
2467
+ json
2468
+ };
2469
+ }
2470
+ function successResult(title, data) {
2471
+ return formatCommandResult({
2472
+ title,
2473
+ summary: data?.summary,
2474
+ details: data?.details,
2475
+ timing: data?.timing,
2476
+ status: "success",
2477
+ jsonData: data?.json
2478
+ });
2479
+ }
2480
+ function errorResult(title, error, options) {
2481
+ const errorMessage = error instanceof Error ? error.message : error;
2482
+ const errorStack = error instanceof Error ? error.stack : void 0;
2483
+ return formatCommandResult({
2484
+ title,
2485
+ errors: [errorMessage],
2486
+ details: options?.suggestions ? [{ section: "Suggestions", items: bulletList2(options.suggestions) }] : [],
2487
+ timing: options?.timing,
2488
+ status: "error",
2489
+ jsonData: {
2490
+ error: errorMessage,
2491
+ ...errorStack && { stack: errorStack }
2492
+ }
2493
+ });
2494
+ }
2495
+ function warningResult(title, warnings, options) {
2496
+ return formatCommandResult({
2497
+ title,
2498
+ warnings,
2499
+ summary: options?.summary,
2500
+ timing: options?.timing,
2501
+ status: "warning"
2502
+ });
2503
+ }
2504
+ function infoResult(title, data) {
2505
+ return formatCommandResult({
2506
+ title,
2507
+ summary: data?.summary,
2508
+ details: data?.details,
2509
+ timing: data?.timing,
2510
+ status: "info"
2511
+ });
2512
+ }
2513
+
2514
+ export { DebugOutput, DebugSection, DebugTrace, DebugTree, DynamicCommandDiscovery, Loader, MultiCLISuggestions, StaticCommandDiscovery, TimingTracker, accentLabel, box, bulletList, colors, createCommandDiscovery, createCommandRegistry, createCommandRunner, createDebugTree, createDetailedResult, createKBLabsCommandDiscovery, createProgressBar, createSimpleResult, createSpinner, defineEnv, defineFlags, describeEntriesAI, describeEntriesHuman, describeEntriesTimeline, discoverArtifacts, displayArtifacts, displayArtifactsCompact, displaySingleArtifact, errorResult, exportDebugEntries, exportToChromeFormat, exportToJSON, exportToPlainText, extractCommandGroups, extractCommandIds, filterByLevel, filterByNamespace, filterByTimeRange, filterDebugEntries, findCommandById, findCommandsByGroup, formatCommandHelp, formatCommandOutput, formatCommandResult, formatDebugEntriesAI, formatDebugEntriesHuman, formatDebugEntryAI, formatDebugEntryHuman, formatDebugOutput, formatDebugOutputs, formatKeyValueTable, formatRelativeTime, formatSize, formatTable, formatTimeline, formatTimelineNode, formatTimelineWithSummary, formatTimestamp, formatTiming, formatTimingBreakdown, generateDevlinkSuggestions, generateGroupSuggestions, generateQuickActions, getCommandInfo, getContextCwd, groupByGroup, groupByNamespace, hasAnsi, headline, indent, infoResult, isCommandAvailable, keyValue, mergeFlags, metricsList, muted, pad, parseBoolean, parseEnvFromRuntime, parseFlagsFromInput, parseNumber, parseNumberFlag, parseString, safeColors, safeKeyValue, safeSymbols, searchInLogs, section, sectionHeader, shouldUseAIFormat, showError, showLoading, showSuccess, sideBorderBox, statusLine, stripAnsi, successResult, supportsColor, symbols, table, toPosixPath, truncate, useLoader, validateSuggestions, warningResult };
2515
+ //# sourceMappingURL=index.js.map
2516
+ //# sourceMappingURL=index.js.map