agent-inspect 1.1.0 → 1.2.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.
@@ -4,13 +4,12 @@ import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { Command, Option } from 'commander';
6
6
  import { unlink, stat, mkdir, writeFile, appendFile, readdir, readFile, open } from 'fs/promises';
7
- import crypto from 'crypto';
8
- import { nanoid } from 'nanoid';
7
+ import crypto, { webcrypto } from 'crypto';
9
8
  import os from 'os';
10
9
  import { AsyncLocalStorage } from 'async_hooks';
11
10
  import { createInterface } from 'readline';
12
- import chalk2 from 'chalk';
13
- import { stdin, stdout } from 'process';
11
+ import process2, { stdin, stdout } from 'process';
12
+ import tty from 'tty';
14
13
 
15
14
  // packages/core/src/types.ts
16
15
  var STEP_TYPES = [
@@ -50,6 +49,86 @@ function isTraceEvent(value) {
50
49
  return false;
51
50
  }
52
51
  }
52
+
53
+ // packages/core/src/logs/tree-builder.ts
54
+ function inc(map, key) {
55
+ map[key] = (map[key] ?? 0) + 1;
56
+ }
57
+ function computeRunStatus(events) {
58
+ let hasRunning = false;
59
+ for (const e of events) {
60
+ if (e.status === "error") return "error";
61
+ if (e.status === "running") hasRunning = true;
62
+ }
63
+ if (hasRunning) return "running";
64
+ return "ok";
65
+ }
66
+ var TreeBuilder = class {
67
+ constructor(options) {
68
+ void options?.config;
69
+ }
70
+ build(events) {
71
+ const byRun = /* @__PURE__ */ new Map();
72
+ for (const e of events) {
73
+ if (!byRun.has(e.runId)) byRun.set(e.runId, []);
74
+ byRun.get(e.runId).push(e);
75
+ }
76
+ const out = [];
77
+ for (const [runId, runEvents] of byRun.entries()) {
78
+ const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
79
+ const nodes = /* @__PURE__ */ new Map();
80
+ for (const e of sorted) {
81
+ nodes.set(e.eventId, { event: e, children: [], depth: 0 });
82
+ }
83
+ const roots = [];
84
+ for (const node of nodes.values()) {
85
+ const parentId = node.event.parentId;
86
+ if (parentId && nodes.has(parentId)) {
87
+ nodes.get(parentId).children.push(node);
88
+ } else {
89
+ roots.push(node);
90
+ }
91
+ }
92
+ const assignDepth = (n, depth) => {
93
+ n.depth = depth;
94
+ for (const c of n.children) assignDepth(c, depth + 1);
95
+ };
96
+ for (const r of roots) assignDepth(r, 0);
97
+ const confidenceBreakdown = {
98
+ explicit: 0,
99
+ correlated: 0,
100
+ heuristic: 0,
101
+ unknown: 0
102
+ };
103
+ const kinds = {};
104
+ for (const e of sorted) {
105
+ inc(confidenceBreakdown, e.confidence);
106
+ kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
107
+ }
108
+ const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
109
+ const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
110
+ const status = computeRunStatus(sorted);
111
+ const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
112
+ const name = sorted.find((e) => e.kind === "RUN")?.name;
113
+ out.push({
114
+ runId,
115
+ name,
116
+ status,
117
+ startedAt,
118
+ endedAt: status === "running" ? void 0 : endedAt,
119
+ durationMs,
120
+ children: roots,
121
+ metadata: {
122
+ totalEvents: sorted.length,
123
+ confidenceBreakdown,
124
+ kinds
125
+ }
126
+ });
127
+ }
128
+ out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
129
+ return out;
130
+ }
131
+ };
53
132
  function isRecord2(v) {
54
133
  return typeof v === "object" && v !== null && !Array.isArray(v);
55
134
  }
@@ -456,6 +535,36 @@ var Redactor = class {
456
535
  return value;
457
536
  }
458
537
  };
538
+
539
+ // node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js
540
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
541
+
542
+ // node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/index.js
543
+ var POOL_SIZE_MULTIPLIER = 128;
544
+ var pool;
545
+ var poolOffset;
546
+ function fillPool(bytes) {
547
+ if (bytes < 0 || bytes > 1024) throw new RangeError("Wrong ID size");
548
+ if (!pool || pool.length < bytes) {
549
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
550
+ webcrypto.getRandomValues(pool);
551
+ poolOffset = 0;
552
+ } else if (poolOffset + bytes > pool.length) {
553
+ webcrypto.getRandomValues(pool);
554
+ poolOffset = 0;
555
+ }
556
+ poolOffset += bytes;
557
+ }
558
+ function nanoid(size = 21) {
559
+ fillPool(size |= 0);
560
+ let id = "";
561
+ for (let i = poolOffset - size; i < poolOffset; i++) {
562
+ id += urlAlphabet[pool[i] & 63];
563
+ }
564
+ return id;
565
+ }
566
+
567
+ // packages/core/src/logs/normalizer.ts
459
568
  function isFiniteNumber(v) {
460
569
  return typeof v === "number" && Number.isFinite(v);
461
570
  }
@@ -636,86 +745,6 @@ var EventNormalizer = class {
636
745
  }
637
746
  };
638
747
 
639
- // packages/core/src/logs/tree-builder.ts
640
- function inc(map, key) {
641
- map[key] = (map[key] ?? 0) + 1;
642
- }
643
- function computeRunStatus(events) {
644
- let hasRunning = false;
645
- for (const e of events) {
646
- if (e.status === "error") return "error";
647
- if (e.status === "running") hasRunning = true;
648
- }
649
- if (hasRunning) return "running";
650
- return "ok";
651
- }
652
- var TreeBuilder = class {
653
- constructor(options) {
654
- void options?.config;
655
- }
656
- build(events) {
657
- const byRun = /* @__PURE__ */ new Map();
658
- for (const e of events) {
659
- if (!byRun.has(e.runId)) byRun.set(e.runId, []);
660
- byRun.get(e.runId).push(e);
661
- }
662
- const out = [];
663
- for (const [runId, runEvents] of byRun.entries()) {
664
- const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
665
- const nodes = /* @__PURE__ */ new Map();
666
- for (const e of sorted) {
667
- nodes.set(e.eventId, { event: e, children: [], depth: 0 });
668
- }
669
- const roots = [];
670
- for (const node of nodes.values()) {
671
- const parentId = node.event.parentId;
672
- if (parentId && nodes.has(parentId)) {
673
- nodes.get(parentId).children.push(node);
674
- } else {
675
- roots.push(node);
676
- }
677
- }
678
- const assignDepth = (n, depth) => {
679
- n.depth = depth;
680
- for (const c of n.children) assignDepth(c, depth + 1);
681
- };
682
- for (const r of roots) assignDepth(r, 0);
683
- const confidenceBreakdown = {
684
- explicit: 0,
685
- correlated: 0,
686
- heuristic: 0,
687
- unknown: 0
688
- };
689
- const kinds = {};
690
- for (const e of sorted) {
691
- inc(confidenceBreakdown, e.confidence);
692
- kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
693
- }
694
- const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
695
- const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
696
- const status = computeRunStatus(sorted);
697
- const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
698
- const name = sorted.find((e) => e.kind === "RUN")?.name;
699
- out.push({
700
- runId,
701
- name,
702
- status,
703
- startedAt,
704
- endedAt: status === "running" ? void 0 : endedAt,
705
- durationMs,
706
- children: roots,
707
- metadata: {
708
- totalEvents: sorted.length,
709
- confidenceBreakdown,
710
- kinds
711
- }
712
- });
713
- }
714
- out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
715
- return out;
716
- }
717
- };
718
-
719
748
  // packages/core/src/logs/tree-renderer.ts
720
749
  function truncate(v, max) {
721
750
  if (v.length <= max) return v;
@@ -2386,6 +2415,498 @@ function diffRuns(left, right, options) {
2386
2415
  };
2387
2416
  return { summary, differences };
2388
2417
  }
2418
+
2419
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
2420
+ var ANSI_BACKGROUND_OFFSET = 10;
2421
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
2422
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
2423
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
2424
+ var styles = {
2425
+ modifier: {
2426
+ reset: [0, 0],
2427
+ // 21 isn't widely supported and 22 does the same thing
2428
+ bold: [1, 22],
2429
+ dim: [2, 22],
2430
+ italic: [3, 23],
2431
+ underline: [4, 24],
2432
+ overline: [53, 55],
2433
+ inverse: [7, 27],
2434
+ hidden: [8, 28],
2435
+ strikethrough: [9, 29]
2436
+ },
2437
+ color: {
2438
+ black: [30, 39],
2439
+ red: [31, 39],
2440
+ green: [32, 39],
2441
+ yellow: [33, 39],
2442
+ blue: [34, 39],
2443
+ magenta: [35, 39],
2444
+ cyan: [36, 39],
2445
+ white: [37, 39],
2446
+ // Bright color
2447
+ blackBright: [90, 39],
2448
+ gray: [90, 39],
2449
+ // Alias of `blackBright`
2450
+ grey: [90, 39],
2451
+ // Alias of `blackBright`
2452
+ redBright: [91, 39],
2453
+ greenBright: [92, 39],
2454
+ yellowBright: [93, 39],
2455
+ blueBright: [94, 39],
2456
+ magentaBright: [95, 39],
2457
+ cyanBright: [96, 39],
2458
+ whiteBright: [97, 39]
2459
+ },
2460
+ bgColor: {
2461
+ bgBlack: [40, 49],
2462
+ bgRed: [41, 49],
2463
+ bgGreen: [42, 49],
2464
+ bgYellow: [43, 49],
2465
+ bgBlue: [44, 49],
2466
+ bgMagenta: [45, 49],
2467
+ bgCyan: [46, 49],
2468
+ bgWhite: [47, 49],
2469
+ // Bright color
2470
+ bgBlackBright: [100, 49],
2471
+ bgGray: [100, 49],
2472
+ // Alias of `bgBlackBright`
2473
+ bgGrey: [100, 49],
2474
+ // Alias of `bgBlackBright`
2475
+ bgRedBright: [101, 49],
2476
+ bgGreenBright: [102, 49],
2477
+ bgYellowBright: [103, 49],
2478
+ bgBlueBright: [104, 49],
2479
+ bgMagentaBright: [105, 49],
2480
+ bgCyanBright: [106, 49],
2481
+ bgWhiteBright: [107, 49]
2482
+ }
2483
+ };
2484
+ Object.keys(styles.modifier);
2485
+ var foregroundColorNames = Object.keys(styles.color);
2486
+ var backgroundColorNames = Object.keys(styles.bgColor);
2487
+ [...foregroundColorNames, ...backgroundColorNames];
2488
+ function assembleStyles() {
2489
+ const codes = /* @__PURE__ */ new Map();
2490
+ for (const [groupName, group] of Object.entries(styles)) {
2491
+ for (const [styleName, style] of Object.entries(group)) {
2492
+ styles[styleName] = {
2493
+ open: `\x1B[${style[0]}m`,
2494
+ close: `\x1B[${style[1]}m`
2495
+ };
2496
+ group[styleName] = styles[styleName];
2497
+ codes.set(style[0], style[1]);
2498
+ }
2499
+ Object.defineProperty(styles, groupName, {
2500
+ value: group,
2501
+ enumerable: false
2502
+ });
2503
+ }
2504
+ Object.defineProperty(styles, "codes", {
2505
+ value: codes,
2506
+ enumerable: false
2507
+ });
2508
+ styles.color.close = "\x1B[39m";
2509
+ styles.bgColor.close = "\x1B[49m";
2510
+ styles.color.ansi = wrapAnsi16();
2511
+ styles.color.ansi256 = wrapAnsi256();
2512
+ styles.color.ansi16m = wrapAnsi16m();
2513
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
2514
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
2515
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
2516
+ Object.defineProperties(styles, {
2517
+ rgbToAnsi256: {
2518
+ value(red, green, blue) {
2519
+ if (red === green && green === blue) {
2520
+ if (red < 8) {
2521
+ return 16;
2522
+ }
2523
+ if (red > 248) {
2524
+ return 231;
2525
+ }
2526
+ return Math.round((red - 8) / 247 * 24) + 232;
2527
+ }
2528
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
2529
+ },
2530
+ enumerable: false
2531
+ },
2532
+ hexToRgb: {
2533
+ value(hex) {
2534
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
2535
+ if (!matches) {
2536
+ return [0, 0, 0];
2537
+ }
2538
+ let [colorString] = matches;
2539
+ if (colorString.length === 3) {
2540
+ colorString = [...colorString].map((character) => character + character).join("");
2541
+ }
2542
+ const integer = Number.parseInt(colorString, 16);
2543
+ return [
2544
+ /* eslint-disable no-bitwise */
2545
+ integer >> 16 & 255,
2546
+ integer >> 8 & 255,
2547
+ integer & 255
2548
+ /* eslint-enable no-bitwise */
2549
+ ];
2550
+ },
2551
+ enumerable: false
2552
+ },
2553
+ hexToAnsi256: {
2554
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
2555
+ enumerable: false
2556
+ },
2557
+ ansi256ToAnsi: {
2558
+ value(code) {
2559
+ if (code < 8) {
2560
+ return 30 + code;
2561
+ }
2562
+ if (code < 16) {
2563
+ return 90 + (code - 8);
2564
+ }
2565
+ let red;
2566
+ let green;
2567
+ let blue;
2568
+ if (code >= 232) {
2569
+ red = ((code - 232) * 10 + 8) / 255;
2570
+ green = red;
2571
+ blue = red;
2572
+ } else {
2573
+ code -= 16;
2574
+ const remainder = code % 36;
2575
+ red = Math.floor(code / 36) / 5;
2576
+ green = Math.floor(remainder / 6) / 5;
2577
+ blue = remainder % 6 / 5;
2578
+ }
2579
+ const value = Math.max(red, green, blue) * 2;
2580
+ if (value === 0) {
2581
+ return 30;
2582
+ }
2583
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
2584
+ if (value === 2) {
2585
+ result += 60;
2586
+ }
2587
+ return result;
2588
+ },
2589
+ enumerable: false
2590
+ },
2591
+ rgbToAnsi: {
2592
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
2593
+ enumerable: false
2594
+ },
2595
+ hexToAnsi: {
2596
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
2597
+ enumerable: false
2598
+ }
2599
+ });
2600
+ return styles;
2601
+ }
2602
+ var ansiStyles = assembleStyles();
2603
+ var ansi_styles_default = ansiStyles;
2604
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
2605
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
2606
+ const position = argv.indexOf(prefix + flag);
2607
+ const terminatorPosition = argv.indexOf("--");
2608
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
2609
+ }
2610
+ var { env } = process2;
2611
+ var flagForceColor;
2612
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
2613
+ flagForceColor = 0;
2614
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
2615
+ flagForceColor = 1;
2616
+ }
2617
+ function envForceColor() {
2618
+ if ("FORCE_COLOR" in env) {
2619
+ if (env.FORCE_COLOR === "true") {
2620
+ return 1;
2621
+ }
2622
+ if (env.FORCE_COLOR === "false") {
2623
+ return 0;
2624
+ }
2625
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
2626
+ }
2627
+ }
2628
+ function translateLevel(level) {
2629
+ if (level === 0) {
2630
+ return false;
2631
+ }
2632
+ return {
2633
+ level,
2634
+ hasBasic: true,
2635
+ has256: level >= 2,
2636
+ has16m: level >= 3
2637
+ };
2638
+ }
2639
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
2640
+ const noFlagForceColor = envForceColor();
2641
+ if (noFlagForceColor !== void 0) {
2642
+ flagForceColor = noFlagForceColor;
2643
+ }
2644
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
2645
+ if (forceColor === 0) {
2646
+ return 0;
2647
+ }
2648
+ if (sniffFlags) {
2649
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
2650
+ return 3;
2651
+ }
2652
+ if (hasFlag("color=256")) {
2653
+ return 2;
2654
+ }
2655
+ }
2656
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
2657
+ return 1;
2658
+ }
2659
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
2660
+ return 0;
2661
+ }
2662
+ const min = forceColor || 0;
2663
+ if (env.TERM === "dumb") {
2664
+ return min;
2665
+ }
2666
+ if (process2.platform === "win32") {
2667
+ const osRelease = os.release().split(".");
2668
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
2669
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
2670
+ }
2671
+ return 1;
2672
+ }
2673
+ if ("CI" in env) {
2674
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
2675
+ return 3;
2676
+ }
2677
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
2678
+ return 1;
2679
+ }
2680
+ return min;
2681
+ }
2682
+ if ("TEAMCITY_VERSION" in env) {
2683
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
2684
+ }
2685
+ if (env.COLORTERM === "truecolor") {
2686
+ return 3;
2687
+ }
2688
+ if (env.TERM === "xterm-kitty") {
2689
+ return 3;
2690
+ }
2691
+ if (env.TERM === "xterm-ghostty") {
2692
+ return 3;
2693
+ }
2694
+ if (env.TERM === "wezterm") {
2695
+ return 3;
2696
+ }
2697
+ if ("TERM_PROGRAM" in env) {
2698
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
2699
+ switch (env.TERM_PROGRAM) {
2700
+ case "iTerm.app": {
2701
+ return version >= 3 ? 3 : 2;
2702
+ }
2703
+ case "Apple_Terminal": {
2704
+ return 2;
2705
+ }
2706
+ }
2707
+ }
2708
+ if (/-256(color)?$/i.test(env.TERM)) {
2709
+ return 2;
2710
+ }
2711
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
2712
+ return 1;
2713
+ }
2714
+ if ("COLORTERM" in env) {
2715
+ return 1;
2716
+ }
2717
+ return min;
2718
+ }
2719
+ function createSupportsColor(stream, options = {}) {
2720
+ const level = _supportsColor(stream, {
2721
+ streamIsTTY: stream && stream.isTTY,
2722
+ ...options
2723
+ });
2724
+ return translateLevel(level);
2725
+ }
2726
+ var supportsColor = {
2727
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
2728
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
2729
+ };
2730
+ var supports_color_default = supportsColor;
2731
+
2732
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
2733
+ function stringReplaceAll(string, substring, replacer) {
2734
+ let index = string.indexOf(substring);
2735
+ if (index === -1) {
2736
+ return string;
2737
+ }
2738
+ const substringLength = substring.length;
2739
+ let endIndex = 0;
2740
+ let returnValue = "";
2741
+ do {
2742
+ returnValue += string.slice(endIndex, index) + substring + replacer;
2743
+ endIndex = index + substringLength;
2744
+ index = string.indexOf(substring, endIndex);
2745
+ } while (index !== -1);
2746
+ returnValue += string.slice(endIndex);
2747
+ return returnValue;
2748
+ }
2749
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2750
+ let endIndex = 0;
2751
+ let returnValue = "";
2752
+ do {
2753
+ const gotCR = string[index - 1] === "\r";
2754
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
2755
+ endIndex = index + 1;
2756
+ index = string.indexOf("\n", endIndex);
2757
+ } while (index !== -1);
2758
+ returnValue += string.slice(endIndex);
2759
+ return returnValue;
2760
+ }
2761
+
2762
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
2763
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
2764
+ var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
2765
+ var STYLER = /* @__PURE__ */ Symbol("STYLER");
2766
+ var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
2767
+ var levelMapping = [
2768
+ "ansi",
2769
+ "ansi",
2770
+ "ansi256",
2771
+ "ansi16m"
2772
+ ];
2773
+ var styles2 = /* @__PURE__ */ Object.create(null);
2774
+ var applyOptions = (object, options = {}) => {
2775
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2776
+ throw new Error("The `level` option should be an integer from 0 to 3");
2777
+ }
2778
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
2779
+ object.level = options.level === void 0 ? colorLevel : options.level;
2780
+ };
2781
+ var chalkFactory = (options) => {
2782
+ const chalk2 = (...strings) => strings.join(" ");
2783
+ applyOptions(chalk2, options);
2784
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
2785
+ return chalk2;
2786
+ };
2787
+ function createChalk(options) {
2788
+ return chalkFactory(options);
2789
+ }
2790
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2791
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2792
+ styles2[styleName] = {
2793
+ get() {
2794
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2795
+ Object.defineProperty(this, styleName, { value: builder });
2796
+ return builder;
2797
+ }
2798
+ };
2799
+ }
2800
+ styles2.visible = {
2801
+ get() {
2802
+ const builder = createBuilder(this, this[STYLER], true);
2803
+ Object.defineProperty(this, "visible", { value: builder });
2804
+ return builder;
2805
+ }
2806
+ };
2807
+ var getModelAnsi = (model, level, type, ...arguments_) => {
2808
+ if (model === "rgb") {
2809
+ if (level === "ansi16m") {
2810
+ return ansi_styles_default[type].ansi16m(...arguments_);
2811
+ }
2812
+ if (level === "ansi256") {
2813
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
2814
+ }
2815
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
2816
+ }
2817
+ if (model === "hex") {
2818
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
2819
+ }
2820
+ return ansi_styles_default[type][model](...arguments_);
2821
+ };
2822
+ var usedModels = ["rgb", "hex", "ansi256"];
2823
+ for (const model of usedModels) {
2824
+ styles2[model] = {
2825
+ get() {
2826
+ const { level } = this;
2827
+ return function(...arguments_) {
2828
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2829
+ return createBuilder(this, styler, this[IS_EMPTY]);
2830
+ };
2831
+ }
2832
+ };
2833
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2834
+ styles2[bgModel] = {
2835
+ get() {
2836
+ const { level } = this;
2837
+ return function(...arguments_) {
2838
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2839
+ return createBuilder(this, styler, this[IS_EMPTY]);
2840
+ };
2841
+ }
2842
+ };
2843
+ }
2844
+ var proto = Object.defineProperties(() => {
2845
+ }, {
2846
+ ...styles2,
2847
+ level: {
2848
+ enumerable: true,
2849
+ get() {
2850
+ return this[GENERATOR].level;
2851
+ },
2852
+ set(level) {
2853
+ this[GENERATOR].level = level;
2854
+ }
2855
+ }
2856
+ });
2857
+ var createStyler = (open2, close, parent) => {
2858
+ let openAll;
2859
+ let closeAll;
2860
+ if (parent === void 0) {
2861
+ openAll = open2;
2862
+ closeAll = close;
2863
+ } else {
2864
+ openAll = parent.openAll + open2;
2865
+ closeAll = close + parent.closeAll;
2866
+ }
2867
+ return {
2868
+ open: open2,
2869
+ close,
2870
+ openAll,
2871
+ closeAll,
2872
+ parent
2873
+ };
2874
+ };
2875
+ var createBuilder = (self, _styler, _isEmpty) => {
2876
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2877
+ Object.setPrototypeOf(builder, proto);
2878
+ builder[GENERATOR] = self;
2879
+ builder[STYLER] = _styler;
2880
+ builder[IS_EMPTY] = _isEmpty;
2881
+ return builder;
2882
+ };
2883
+ var applyStyle = (self, string) => {
2884
+ if (self.level <= 0 || !string) {
2885
+ return self[IS_EMPTY] ? "" : string;
2886
+ }
2887
+ let styler = self[STYLER];
2888
+ if (styler === void 0) {
2889
+ return string;
2890
+ }
2891
+ const { openAll, closeAll } = styler;
2892
+ if (string.includes("\x1B")) {
2893
+ while (styler !== void 0) {
2894
+ string = stringReplaceAll(string, styler.close, styler.open);
2895
+ styler = styler.parent;
2896
+ }
2897
+ }
2898
+ const lfIndex = string.indexOf("\n");
2899
+ if (lfIndex !== -1) {
2900
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
2901
+ }
2902
+ return openAll + string + closeAll;
2903
+ };
2904
+ Object.defineProperties(createChalk.prototype, styles2);
2905
+ var chalk = createChalk();
2906
+ createChalk({ level: stderrColor ? stderrColor.level : 0 });
2907
+ var source_default = chalk;
2908
+
2909
+ // packages/core/src/diff/renderer.ts
2389
2910
  function formatPath(path7) {
2390
2911
  if (path7 === void 0 || path7.path.length === 0) {
2391
2912
  return "(run)";
@@ -2466,6 +2987,8 @@ function diffTraceEvents(leftEvents, rightEvents, options) {
2466
2987
  const right = manualTraceEventsToComparableRun(rightEvents);
2467
2988
  return diffRuns(left, right, options);
2468
2989
  }
2990
+
2991
+ // packages/core/src/terminal.ts
2469
2992
  var TERMINAL_INDENT = " ";
2470
2993
  var MAX_TERMINAL_NAME_LENGTH = 80;
2471
2994
  var MAX_TERMINAL_DEPTH = 10;
@@ -2491,24 +3014,24 @@ function formatTerminalName(name) {
2491
3014
  return truncateName(name, MAX_TERMINAL_NAME_LENGTH);
2492
3015
  }
2493
3016
  function getStatusIcon(status) {
2494
- if (status === "success") return chalk2.green("\u2714");
2495
- if (status === "error") return chalk2.red("\u2716");
2496
- return chalk2.yellow("\u23F3");
3017
+ if (status === "success") return source_default.green("\u2714");
3018
+ if (status === "error") return source_default.red("\u2716");
3019
+ return source_default.yellow("\u23F3");
2497
3020
  }
2498
3021
  function renderStepLine(name, durationMs, status, depth) {
2499
3022
  try {
2500
3023
  const nm = formatTerminalName(name);
2501
3024
  const ind = getIndent(depth ?? 0);
2502
3025
  if (status === "running" && durationMs === void 0) {
2503
- return `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3026
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2504
3027
  }
2505
3028
  const hasDur = durationMs !== void 0 && Number.isFinite(durationMs);
2506
3029
  const dur = hasDur ? formatDuration2(durationMs) : void 0;
2507
3030
  if (status === "running") {
2508
- return dur !== void 0 ? `${ind}${chalk2.yellow("\u23F3")} ${nm} (${dur})` : `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3031
+ return dur !== void 0 ? `${ind}${source_default.yellow("\u23F3")} ${nm} (${dur})` : `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2509
3032
  }
2510
3033
  if (!hasDur || dur === void 0) {
2511
- return `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3034
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2512
3035
  }
2513
3036
  if (status === "success") {
2514
3037
  return `${ind}${getStatusIcon("success")} ${nm} (${dur})`;