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