agent-inspect 1.4.0 → 1.6.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +34 -6
  3. package/docs/ADAPTERS.md +6 -0
  4. package/docs/API.md +132 -9
  5. package/docs/ARCHITECTURE.md +4 -0
  6. package/docs/CLI.md +98 -5
  7. package/docs/DIFF.md +8 -0
  8. package/docs/EXPORTS.md +13 -0
  9. package/docs/GETTING-STARTED.md +19 -1
  10. package/docs/KNOWN-ISSUES.md +8 -1
  11. package/docs/LIMITATIONS.md +13 -2
  12. package/docs/LOGS.md +22 -0
  13. package/docs/SCHEMA.md +19 -7
  14. package/docs/SCREENSHOTS.md +190 -9
  15. package/package.json +71 -1
  16. package/packages/cli/dist/index.cjs +7121 -3986
  17. package/packages/cli/dist/index.cjs.map +1 -1
  18. package/packages/cli/dist/index.mjs +7122 -3987
  19. package/packages/cli/dist/index.mjs.map +1 -1
  20. package/packages/core/dist/advanced.cjs +2258 -0
  21. package/packages/core/dist/advanced.cjs.map +1 -0
  22. package/packages/core/dist/advanced.d.cts +254 -0
  23. package/packages/core/dist/advanced.d.ts +254 -0
  24. package/packages/core/dist/advanced.mjs +11 -0
  25. package/packages/core/dist/advanced.mjs.map +1 -0
  26. package/packages/core/dist/chunk-57S5D6HR.mjs +655 -0
  27. package/packages/core/dist/chunk-57S5D6HR.mjs.map +1 -0
  28. package/packages/core/dist/chunk-6QSLZCBJ.mjs +743 -0
  29. package/packages/core/dist/chunk-6QSLZCBJ.mjs.map +1 -0
  30. package/packages/core/dist/chunk-6SZPTECC.mjs +342 -0
  31. package/packages/core/dist/chunk-6SZPTECC.mjs.map +1 -0
  32. package/packages/core/dist/chunk-74XZ6N7Q.mjs +409 -0
  33. package/packages/core/dist/chunk-74XZ6N7Q.mjs.map +1 -0
  34. package/packages/core/dist/chunk-7TGZLWEE.mjs +35 -0
  35. package/packages/core/dist/chunk-7TGZLWEE.mjs.map +1 -0
  36. package/packages/core/dist/chunk-BT7CATSD.mjs +497 -0
  37. package/packages/core/dist/chunk-BT7CATSD.mjs.map +1 -0
  38. package/packages/core/dist/chunk-E5F2LQCX.mjs +83 -0
  39. package/packages/core/dist/chunk-E5F2LQCX.mjs.map +1 -0
  40. package/packages/core/dist/chunk-EDTQHZPM.mjs +88 -0
  41. package/packages/core/dist/chunk-EDTQHZPM.mjs.map +1 -0
  42. package/packages/core/dist/chunk-HR7G62IE.mjs +785 -0
  43. package/packages/core/dist/chunk-HR7G62IE.mjs.map +1 -0
  44. package/packages/core/dist/chunk-HY7H3CQM.mjs +127 -0
  45. package/packages/core/dist/chunk-HY7H3CQM.mjs.map +1 -0
  46. package/packages/core/dist/chunk-S4YWKV4G.mjs +48 -0
  47. package/packages/core/dist/chunk-S4YWKV4G.mjs.map +1 -0
  48. package/packages/core/dist/chunk-TFLPUZ56.mjs +1571 -0
  49. package/packages/core/dist/chunk-TFLPUZ56.mjs.map +1 -0
  50. package/packages/core/dist/chunk-TZISEVLQ.mjs +390 -0
  51. package/packages/core/dist/chunk-TZISEVLQ.mjs.map +1 -0
  52. package/packages/core/dist/chunk-U2BGPESY.mjs +150 -0
  53. package/packages/core/dist/chunk-U2BGPESY.mjs.map +1 -0
  54. package/packages/core/dist/chunk-VTIB5MDK.mjs +304 -0
  55. package/packages/core/dist/chunk-VTIB5MDK.mjs.map +1 -0
  56. package/packages/core/dist/chunk-VU6O5QAH.mjs +99 -0
  57. package/packages/core/dist/chunk-VU6O5QAH.mjs.map +1 -0
  58. package/packages/core/dist/chunk-Y56BPA3B.mjs +990 -0
  59. package/packages/core/dist/chunk-Y56BPA3B.mjs.map +1 -0
  60. package/packages/core/dist/chunk-YWAOOXLR.mjs +475 -0
  61. package/packages/core/dist/chunk-YWAOOXLR.mjs.map +1 -0
  62. package/packages/core/dist/diff.cjs +993 -0
  63. package/packages/core/dist/diff.cjs.map +1 -0
  64. package/packages/core/dist/diff.d.cts +82 -0
  65. package/packages/core/dist/diff.d.ts +82 -0
  66. package/packages/core/dist/diff.mjs +5 -0
  67. package/packages/core/dist/diff.mjs.map +1 -0
  68. package/packages/core/dist/exporters.cjs +1228 -0
  69. package/packages/core/dist/exporters.cjs.map +1 -0
  70. package/packages/core/dist/exporters.d.cts +114 -0
  71. package/packages/core/dist/exporters.d.ts +114 -0
  72. package/packages/core/dist/exporters.mjs +6 -0
  73. package/packages/core/dist/exporters.mjs.map +1 -0
  74. package/packages/core/dist/index.cjs +5542 -2218
  75. package/packages/core/dist/index.cjs.map +1 -1
  76. package/packages/core/dist/index.d.cts +113 -908
  77. package/packages/core/dist/index.d.ts +113 -908
  78. package/packages/core/dist/index.mjs +1048 -5403
  79. package/packages/core/dist/index.mjs.map +1 -1
  80. package/packages/core/dist/inspect-event-Des4JDHo.d.cts +41 -0
  81. package/packages/core/dist/inspect-event-Des4JDHo.d.ts +41 -0
  82. package/packages/core/dist/log-config-BnH8Ykcb.d.cts +33 -0
  83. package/packages/core/dist/log-config-C1GcJPIM.d.ts +33 -0
  84. package/packages/core/dist/logs.cjs +1007 -0
  85. package/packages/core/dist/logs.cjs.map +1 -0
  86. package/packages/core/dist/logs.d.cts +138 -0
  87. package/packages/core/dist/logs.d.ts +138 -0
  88. package/packages/core/dist/logs.mjs +6 -0
  89. package/packages/core/dist/logs.mjs.map +1 -0
  90. package/packages/core/dist/persisted-inspect-event-0kaRADsp.d.cts +56 -0
  91. package/packages/core/dist/persisted-inspect-event-DiFto0K2.d.ts +56 -0
  92. package/packages/core/dist/persisted.cjs +1055 -0
  93. package/packages/core/dist/persisted.cjs.map +1 -0
  94. package/packages/core/dist/persisted.d.cts +111 -0
  95. package/packages/core/dist/persisted.d.ts +111 -0
  96. package/packages/core/dist/persisted.mjs +7 -0
  97. package/packages/core/dist/persisted.mjs.map +1 -0
  98. package/packages/core/dist/readers.cjs +2590 -0
  99. package/packages/core/dist/readers.cjs.map +1 -0
  100. package/packages/core/dist/readers.d.cts +80 -0
  101. package/packages/core/dist/readers.d.ts +80 -0
  102. package/packages/core/dist/readers.mjs +9 -0
  103. package/packages/core/dist/readers.mjs.map +1 -0
  104. package/packages/core/dist/types-DB8jB6Jg.d.cts +232 -0
  105. package/packages/core/dist/types-tSix7tfv.d.ts +232 -0
  106. package/packages/core/dist/writers.cjs +997 -0
  107. package/packages/core/dist/writers.cjs.map +1 -0
  108. package/packages/core/dist/writers.d.cts +62 -0
  109. package/packages/core/dist/writers.d.ts +62 -0
  110. package/packages/core/dist/writers.mjs +9 -0
  111. package/packages/core/dist/writers.mjs.map +1 -0
@@ -0,0 +1,993 @@
1
+ 'use strict';
2
+
3
+ var process = require('process');
4
+ var os = require('os');
5
+ var tty = require('tty');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var process__default = /*#__PURE__*/_interopDefault(process);
10
+ var os__default = /*#__PURE__*/_interopDefault(os);
11
+ var tty__default = /*#__PURE__*/_interopDefault(tty);
12
+
13
+ // packages/core/src/diff/comparable.ts
14
+ function extractOutputPreview(meta) {
15
+ if (meta === void 0) return void 0;
16
+ if ("outputPreview" in meta) return meta.outputPreview;
17
+ if ("resultPreview" in meta) return meta.resultPreview;
18
+ return void 0;
19
+ }
20
+ function mapStepStatus(s) {
21
+ if (s === void 0) return "running";
22
+ return s;
23
+ }
24
+ function manualTraceEventsToComparableRun(events) {
25
+ const started = events.find((e) => e.event === "run_started");
26
+ if (!started || started.event !== "run_started") {
27
+ throw new Error("Invalid trace: missing run_started");
28
+ }
29
+ const rs = started;
30
+ const runId = rs.runId;
31
+ const completedAll = events.filter((e) => e.event === "run_completed");
32
+ const lastCompleted = completedAll[completedAll.length - 1];
33
+ let runStatus;
34
+ if (lastCompleted === void 0) runStatus = "running";
35
+ else runStatus = lastCompleted.status;
36
+ const durationMs = lastCompleted !== void 0 && Number.isFinite(lastCompleted.durationMs) ? lastCompleted.durationMs : void 0;
37
+ const steps = /* @__PURE__ */ new Map();
38
+ let order = 0;
39
+ for (const e of events) {
40
+ if (e.event !== "step_started") continue;
41
+ const s = e;
42
+ const meta = s.metadata ? { ...s.metadata } : void 0;
43
+ steps.set(s.stepId, {
44
+ id: s.stepId,
45
+ parentId: s.parentId,
46
+ name: s.name,
47
+ type: s.type,
48
+ order: order++,
49
+ timestamp: s.timestamp,
50
+ metadata: meta
51
+ });
52
+ }
53
+ for (const e of events) {
54
+ if (e.event !== "step_completed") continue;
55
+ const acc = steps.get(e.stepId);
56
+ if (!acc) continue;
57
+ acc.status = e.status;
58
+ acc.durationMs = e.durationMs;
59
+ if (e.error?.message) acc.errorMsg = e.error.message;
60
+ const extra = e;
61
+ if (extra.metadata !== void 0 && typeof extra.metadata === "object") {
62
+ acc.metadata = { ...acc.metadata ?? {}, ...extra.metadata };
63
+ }
64
+ }
65
+ const nodes = /* @__PURE__ */ new Map();
66
+ for (const acc of steps.values()) {
67
+ let meta = acc.metadata ? { ...acc.metadata } : void 0;
68
+ if (acc.parentId !== void 0 && !steps.has(acc.parentId)) {
69
+ meta = { ...meta ?? {}, agent_inspect_diff_parent_missing: true };
70
+ }
71
+ const outputPreview = extractOutputPreview(meta);
72
+ const sc = {
73
+ id: acc.id,
74
+ name: acc.name,
75
+ type: acc.type,
76
+ status: mapStepStatus(acc.status),
77
+ durationMs: acc.durationMs,
78
+ error: acc.errorMsg,
79
+ metadata: meta && Object.keys(meta).length > 0 ? meta : void 0,
80
+ outputPreview,
81
+ children: []
82
+ };
83
+ nodes.set(acc.id, sc);
84
+ }
85
+ const roots = [];
86
+ const sortByOrder = (a, b) => {
87
+ const oa = steps.get(a.id)?.order ?? 0;
88
+ const ob = steps.get(b.id)?.order ?? 0;
89
+ return oa - ob;
90
+ };
91
+ for (const acc of steps.values()) {
92
+ const node = nodes.get(acc.id);
93
+ if (acc.parentId !== void 0 && nodes.has(acc.parentId)) {
94
+ nodes.get(acc.parentId).children.push(node);
95
+ } else {
96
+ roots.push(node);
97
+ }
98
+ }
99
+ roots.sort(sortByOrder);
100
+ for (const n of nodes.values()) {
101
+ n.children.sort(sortByOrder);
102
+ }
103
+ return {
104
+ runId,
105
+ name: rs.name,
106
+ status: runStatus,
107
+ durationMs,
108
+ steps: roots
109
+ };
110
+ }
111
+
112
+ // packages/core/src/exporters/helpers.ts
113
+ function sortKeysDeep(input) {
114
+ if (input === null || typeof input !== "object") return input;
115
+ if (Array.isArray(input)) return input.map(sortKeysDeep);
116
+ const o = input;
117
+ const out = {};
118
+ for (const k of Object.keys(o).sort()) {
119
+ out[k] = sortKeysDeep(o[k]);
120
+ }
121
+ return out;
122
+ }
123
+ function stableJson(value, pretty) {
124
+ const sorted = sortKeysDeep(value);
125
+ return JSON.stringify(sorted);
126
+ }
127
+
128
+ // packages/core/src/diff/engine.ts
129
+ var DEFAULT_THRESHOLD_MS = 0;
130
+ function pathSeg(step, index) {
131
+ return { index, name: step.name, stepId: step.id };
132
+ }
133
+ function buildPath(segments) {
134
+ return { path: [...segments] };
135
+ }
136
+ function pairSteps(left, right) {
137
+ const usedRight = /* @__PURE__ */ new Set();
138
+ const pairs = [];
139
+ for (let i = 0; i < left.length; i++) {
140
+ const L = left[i];
141
+ let R = right.find((r) => !usedRight.has(r.id) && r.id === L.id);
142
+ if (R === void 0 && i < right.length && !usedRight.has(right[i].id)) {
143
+ const cand = right[i];
144
+ if (cand.name === L.name && (cand.type ?? "") === (L.type ?? "")) {
145
+ R = cand;
146
+ }
147
+ }
148
+ if (R === void 0) {
149
+ R = right.find(
150
+ (r) => !usedRight.has(r.id) && r.name === L.name && (r.type ?? "") === (L.type ?? "")
151
+ );
152
+ }
153
+ if (R !== void 0) {
154
+ usedRight.add(R.id);
155
+ pairs.push([L, R]);
156
+ } else {
157
+ pairs.push([L, void 0]);
158
+ }
159
+ }
160
+ for (const R of right) {
161
+ if (!usedRight.has(R.id)) {
162
+ pairs.push([void 0, R]);
163
+ }
164
+ }
165
+ return pairs;
166
+ }
167
+ function compareLeafSteps(L, R, segments, opts, out) {
168
+ const path = buildPath(segments);
169
+ if (L.name !== R.name) {
170
+ out.push({
171
+ kind: "structure",
172
+ severity: "warning",
173
+ message: "Step name differs",
174
+ path,
175
+ left: L.name,
176
+ right: R.name
177
+ });
178
+ }
179
+ if ((L.type ?? "") !== (R.type ?? "")) {
180
+ out.push({
181
+ kind: "step-type",
182
+ severity: "warning",
183
+ message: "Step type differs",
184
+ path,
185
+ left: L.type,
186
+ right: R.type
187
+ });
188
+ }
189
+ if ((L.status ?? "") !== (R.status ?? "")) {
190
+ out.push({
191
+ kind: "step-status",
192
+ severity: "warning",
193
+ message: "Step status differs",
194
+ path,
195
+ left: L.status,
196
+ right: R.status
197
+ });
198
+ }
199
+ const le = L.error ?? "";
200
+ const re = R.error ?? "";
201
+ if (le !== re) {
202
+ out.push({
203
+ kind: "error",
204
+ severity: "error",
205
+ message: "Step error message differs",
206
+ path,
207
+ left: le || void 0,
208
+ right: re || void 0
209
+ });
210
+ }
211
+ if (!opts.ignoreDuration) {
212
+ const ld = L.durationMs;
213
+ const rd = R.durationMs;
214
+ const th = opts.durationThresholdMs;
215
+ let differs = false;
216
+ if (ld === void 0 && rd === void 0) differs = false;
217
+ else if (ld === void 0 || rd === void 0) differs = true;
218
+ else differs = Math.abs(ld - rd) > th;
219
+ if (differs) {
220
+ out.push({
221
+ kind: "duration",
222
+ severity: "info",
223
+ message: "Step duration differs",
224
+ path,
225
+ left: ld,
226
+ right: rd
227
+ });
228
+ }
229
+ }
230
+ const lm = stableJson(L.metadata ?? {});
231
+ const rm = stableJson(R.metadata ?? {});
232
+ if (lm !== rm) {
233
+ out.push({
234
+ kind: "metadata",
235
+ severity: "info",
236
+ message: "Step metadata differs",
237
+ path,
238
+ left: L.metadata,
239
+ right: R.metadata
240
+ });
241
+ }
242
+ const lo = stableJson(L.outputPreview ?? null);
243
+ const ro = stableJson(R.outputPreview ?? null);
244
+ if (lo !== ro) {
245
+ out.push({
246
+ kind: "output",
247
+ severity: "info",
248
+ message: "Output preview differs",
249
+ path,
250
+ left: L.outputPreview,
251
+ right: R.outputPreview
252
+ });
253
+ }
254
+ }
255
+ function compareRecursive(L, R, segments, opts, out) {
256
+ compareLeafSteps(L, R, segments, opts, out);
257
+ const pairs = pairSteps(L.children, R.children);
258
+ let ci = 0;
259
+ for (const [lch, rch] of pairs) {
260
+ if (lch !== void 0 && rch !== void 0) {
261
+ compareRecursive(lch, rch, [...segments, pathSeg(lch, ci)], opts, out);
262
+ } else if (lch !== void 0) {
263
+ out.push({
264
+ kind: "step-removed",
265
+ severity: "warning",
266
+ message: `Step only in left run: ${lch.name}`,
267
+ path: buildPath([...segments, pathSeg(lch, ci)]),
268
+ left: lch.id,
269
+ right: void 0
270
+ });
271
+ } else if (rch !== void 0) {
272
+ out.push({
273
+ kind: "step-added",
274
+ severity: "warning",
275
+ message: `Step only in right run: ${rch.name}`,
276
+ path: buildPath([...segments, pathSeg(rch, ci)]),
277
+ left: void 0,
278
+ right: rch.id
279
+ });
280
+ }
281
+ ci += 1;
282
+ }
283
+ }
284
+ function mergeDiffDefaults(options) {
285
+ return {
286
+ ignoreDuration: options?.ignoreDuration ?? false,
287
+ durationThresholdMs: options?.durationThresholdMs !== void 0 ? options.durationThresholdMs : DEFAULT_THRESHOLD_MS,
288
+ focus: options?.focus ?? "all",
289
+ check: options?.check ?? "all"
290
+ };
291
+ }
292
+ function kindMatchesFilter(kind, merged) {
293
+ const { focus, check } = merged;
294
+ if (check !== "all") {
295
+ if (check === "structure") {
296
+ if (!["step-added", "step-removed", "structure", "step-type"].includes(kind)) return false;
297
+ } else if (check === "outputs") {
298
+ if (!["metadata", "output"].includes(kind)) return false;
299
+ } else if (check === "errors") {
300
+ if (!["run-status", "step-status", "error"].includes(kind)) return false;
301
+ } else if (check === "timing") {
302
+ if (kind !== "duration") return false;
303
+ }
304
+ }
305
+ if (focus !== "all") {
306
+ if (focus === "errors") {
307
+ if (!["run-status", "step-status", "error"].includes(kind)) return false;
308
+ } else if (focus === "structure") {
309
+ if (!["step-added", "step-removed", "structure", "step-type"].includes(kind)) return false;
310
+ } else if (focus === "outputs") {
311
+ if (!["metadata", "output"].includes(kind)) return false;
312
+ }
313
+ }
314
+ return true;
315
+ }
316
+ function diffRuns(left, right, options) {
317
+ const merged = mergeDiffDefaults(options);
318
+ const opts = {
319
+ ignoreDuration: merged.ignoreDuration,
320
+ durationThresholdMs: merged.durationThresholdMs
321
+ };
322
+ const raw = [];
323
+ if ((left.status ?? "") !== (right.status ?? "")) {
324
+ raw.push({
325
+ kind: "run-status",
326
+ severity: "warning",
327
+ message: "Run completion status differs",
328
+ left: left.status,
329
+ right: right.status
330
+ });
331
+ }
332
+ if (!merged.ignoreDuration) {
333
+ const ld = left.durationMs;
334
+ const rd = right.durationMs;
335
+ const th = merged.durationThresholdMs;
336
+ let differs = false;
337
+ if (ld === void 0 && rd === void 0) differs = false;
338
+ else if (ld === void 0 || rd === void 0) differs = true;
339
+ else differs = Math.abs(ld - rd) > th;
340
+ if (differs) {
341
+ raw.push({
342
+ kind: "duration",
343
+ severity: "info",
344
+ message: "Run duration differs",
345
+ left: ld,
346
+ right: rd
347
+ });
348
+ }
349
+ }
350
+ const pairs = pairSteps(left.steps, right.steps);
351
+ let idx = 0;
352
+ for (const [ls, rs] of pairs) {
353
+ if (ls !== void 0 && rs !== void 0) {
354
+ compareRecursive(ls, rs, [pathSeg(ls, idx)], opts, raw);
355
+ idx += 1;
356
+ } else if (ls !== void 0) {
357
+ raw.push({
358
+ kind: "step-removed",
359
+ severity: "warning",
360
+ message: `Step only in left run: ${ls.name}`,
361
+ path: buildPath([pathSeg(ls, idx)]),
362
+ left: ls.id,
363
+ right: void 0
364
+ });
365
+ idx += 1;
366
+ } else if (rs !== void 0) {
367
+ raw.push({
368
+ kind: "step-added",
369
+ severity: "warning",
370
+ message: `Step only in right run: ${rs.name}`,
371
+ path: buildPath([pathSeg(rs, idx)]),
372
+ left: void 0,
373
+ right: rs.id
374
+ });
375
+ idx += 1;
376
+ }
377
+ }
378
+ const differences = raw.filter((d) => kindMatchesFilter(d.kind, merged));
379
+ let errors = 0;
380
+ let warnings = 0;
381
+ let info = 0;
382
+ for (const d of differences) {
383
+ if (d.severity === "error") errors += 1;
384
+ else if (d.severity === "warning") warnings += 1;
385
+ else info += 1;
386
+ }
387
+ const firstVisible = differences[0];
388
+ const firstDivergence = firstVisible !== void 0 ? {
389
+ kind: "first-divergence",
390
+ severity: firstVisible.severity,
391
+ message: `First divergence: ${firstVisible.message}`,
392
+ path: firstVisible.path,
393
+ left: firstVisible.left,
394
+ right: firstVisible.right
395
+ } : void 0;
396
+ const summary = {
397
+ leftRunId: left.runId,
398
+ rightRunId: right.runId,
399
+ totalDifferences: differences.length,
400
+ errors,
401
+ warnings,
402
+ info,
403
+ firstDivergence
404
+ };
405
+ return { summary, differences };
406
+ }
407
+
408
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
409
+ var ANSI_BACKGROUND_OFFSET = 10;
410
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
411
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
412
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
413
+ var styles = {
414
+ modifier: {
415
+ reset: [0, 0],
416
+ // 21 isn't widely supported and 22 does the same thing
417
+ bold: [1, 22],
418
+ dim: [2, 22],
419
+ italic: [3, 23],
420
+ underline: [4, 24],
421
+ overline: [53, 55],
422
+ inverse: [7, 27],
423
+ hidden: [8, 28],
424
+ strikethrough: [9, 29]
425
+ },
426
+ color: {
427
+ black: [30, 39],
428
+ red: [31, 39],
429
+ green: [32, 39],
430
+ yellow: [33, 39],
431
+ blue: [34, 39],
432
+ magenta: [35, 39],
433
+ cyan: [36, 39],
434
+ white: [37, 39],
435
+ // Bright color
436
+ blackBright: [90, 39],
437
+ gray: [90, 39],
438
+ // Alias of `blackBright`
439
+ grey: [90, 39],
440
+ // Alias of `blackBright`
441
+ redBright: [91, 39],
442
+ greenBright: [92, 39],
443
+ yellowBright: [93, 39],
444
+ blueBright: [94, 39],
445
+ magentaBright: [95, 39],
446
+ cyanBright: [96, 39],
447
+ whiteBright: [97, 39]
448
+ },
449
+ bgColor: {
450
+ bgBlack: [40, 49],
451
+ bgRed: [41, 49],
452
+ bgGreen: [42, 49],
453
+ bgYellow: [43, 49],
454
+ bgBlue: [44, 49],
455
+ bgMagenta: [45, 49],
456
+ bgCyan: [46, 49],
457
+ bgWhite: [47, 49],
458
+ // Bright color
459
+ bgBlackBright: [100, 49],
460
+ bgGray: [100, 49],
461
+ // Alias of `bgBlackBright`
462
+ bgGrey: [100, 49],
463
+ // Alias of `bgBlackBright`
464
+ bgRedBright: [101, 49],
465
+ bgGreenBright: [102, 49],
466
+ bgYellowBright: [103, 49],
467
+ bgBlueBright: [104, 49],
468
+ bgMagentaBright: [105, 49],
469
+ bgCyanBright: [106, 49],
470
+ bgWhiteBright: [107, 49]
471
+ }
472
+ };
473
+ Object.keys(styles.modifier);
474
+ var foregroundColorNames = Object.keys(styles.color);
475
+ var backgroundColorNames = Object.keys(styles.bgColor);
476
+ [...foregroundColorNames, ...backgroundColorNames];
477
+ function assembleStyles() {
478
+ const codes = /* @__PURE__ */ new Map();
479
+ for (const [groupName, group] of Object.entries(styles)) {
480
+ for (const [styleName, style] of Object.entries(group)) {
481
+ styles[styleName] = {
482
+ open: `\x1B[${style[0]}m`,
483
+ close: `\x1B[${style[1]}m`
484
+ };
485
+ group[styleName] = styles[styleName];
486
+ codes.set(style[0], style[1]);
487
+ }
488
+ Object.defineProperty(styles, groupName, {
489
+ value: group,
490
+ enumerable: false
491
+ });
492
+ }
493
+ Object.defineProperty(styles, "codes", {
494
+ value: codes,
495
+ enumerable: false
496
+ });
497
+ styles.color.close = "\x1B[39m";
498
+ styles.bgColor.close = "\x1B[49m";
499
+ styles.color.ansi = wrapAnsi16();
500
+ styles.color.ansi256 = wrapAnsi256();
501
+ styles.color.ansi16m = wrapAnsi16m();
502
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
503
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
504
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
505
+ Object.defineProperties(styles, {
506
+ rgbToAnsi256: {
507
+ value(red, green, blue) {
508
+ if (red === green && green === blue) {
509
+ if (red < 8) {
510
+ return 16;
511
+ }
512
+ if (red > 248) {
513
+ return 231;
514
+ }
515
+ return Math.round((red - 8) / 247 * 24) + 232;
516
+ }
517
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
518
+ },
519
+ enumerable: false
520
+ },
521
+ hexToRgb: {
522
+ value(hex) {
523
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
524
+ if (!matches) {
525
+ return [0, 0, 0];
526
+ }
527
+ let [colorString] = matches;
528
+ if (colorString.length === 3) {
529
+ colorString = [...colorString].map((character) => character + character).join("");
530
+ }
531
+ const integer = Number.parseInt(colorString, 16);
532
+ return [
533
+ /* eslint-disable no-bitwise */
534
+ integer >> 16 & 255,
535
+ integer >> 8 & 255,
536
+ integer & 255
537
+ /* eslint-enable no-bitwise */
538
+ ];
539
+ },
540
+ enumerable: false
541
+ },
542
+ hexToAnsi256: {
543
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
544
+ enumerable: false
545
+ },
546
+ ansi256ToAnsi: {
547
+ value(code) {
548
+ if (code < 8) {
549
+ return 30 + code;
550
+ }
551
+ if (code < 16) {
552
+ return 90 + (code - 8);
553
+ }
554
+ let red;
555
+ let green;
556
+ let blue;
557
+ if (code >= 232) {
558
+ red = ((code - 232) * 10 + 8) / 255;
559
+ green = red;
560
+ blue = red;
561
+ } else {
562
+ code -= 16;
563
+ const remainder = code % 36;
564
+ red = Math.floor(code / 36) / 5;
565
+ green = Math.floor(remainder / 6) / 5;
566
+ blue = remainder % 6 / 5;
567
+ }
568
+ const value = Math.max(red, green, blue) * 2;
569
+ if (value === 0) {
570
+ return 30;
571
+ }
572
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
573
+ if (value === 2) {
574
+ result += 60;
575
+ }
576
+ return result;
577
+ },
578
+ enumerable: false
579
+ },
580
+ rgbToAnsi: {
581
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
582
+ enumerable: false
583
+ },
584
+ hexToAnsi: {
585
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
586
+ enumerable: false
587
+ }
588
+ });
589
+ return styles;
590
+ }
591
+ var ansiStyles = assembleStyles();
592
+ var ansi_styles_default = ansiStyles;
593
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process__default.default.argv) {
594
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
595
+ const position = argv.indexOf(prefix + flag);
596
+ const terminatorPosition = argv.indexOf("--");
597
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
598
+ }
599
+ var { env } = process__default.default;
600
+ var flagForceColor;
601
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
602
+ flagForceColor = 0;
603
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
604
+ flagForceColor = 1;
605
+ }
606
+ function envForceColor() {
607
+ if ("FORCE_COLOR" in env) {
608
+ if (env.FORCE_COLOR === "true") {
609
+ return 1;
610
+ }
611
+ if (env.FORCE_COLOR === "false") {
612
+ return 0;
613
+ }
614
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
615
+ }
616
+ }
617
+ function translateLevel(level) {
618
+ if (level === 0) {
619
+ return false;
620
+ }
621
+ return {
622
+ level,
623
+ hasBasic: true,
624
+ has256: level >= 2,
625
+ has16m: level >= 3
626
+ };
627
+ }
628
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
629
+ const noFlagForceColor = envForceColor();
630
+ if (noFlagForceColor !== void 0) {
631
+ flagForceColor = noFlagForceColor;
632
+ }
633
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
634
+ if (forceColor === 0) {
635
+ return 0;
636
+ }
637
+ if (sniffFlags) {
638
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
639
+ return 3;
640
+ }
641
+ if (hasFlag("color=256")) {
642
+ return 2;
643
+ }
644
+ }
645
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
646
+ return 1;
647
+ }
648
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
649
+ return 0;
650
+ }
651
+ const min = forceColor || 0;
652
+ if (env.TERM === "dumb") {
653
+ return min;
654
+ }
655
+ if (process__default.default.platform === "win32") {
656
+ const osRelease = os__default.default.release().split(".");
657
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
658
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
659
+ }
660
+ return 1;
661
+ }
662
+ if ("CI" in env) {
663
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
664
+ return 3;
665
+ }
666
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
667
+ return 1;
668
+ }
669
+ return min;
670
+ }
671
+ if ("TEAMCITY_VERSION" in env) {
672
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
673
+ }
674
+ if (env.COLORTERM === "truecolor") {
675
+ return 3;
676
+ }
677
+ if (env.TERM === "xterm-kitty") {
678
+ return 3;
679
+ }
680
+ if (env.TERM === "xterm-ghostty") {
681
+ return 3;
682
+ }
683
+ if (env.TERM === "wezterm") {
684
+ return 3;
685
+ }
686
+ if ("TERM_PROGRAM" in env) {
687
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
688
+ switch (env.TERM_PROGRAM) {
689
+ case "iTerm.app": {
690
+ return version >= 3 ? 3 : 2;
691
+ }
692
+ case "Apple_Terminal": {
693
+ return 2;
694
+ }
695
+ }
696
+ }
697
+ if (/-256(color)?$/i.test(env.TERM)) {
698
+ return 2;
699
+ }
700
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
701
+ return 1;
702
+ }
703
+ if ("COLORTERM" in env) {
704
+ return 1;
705
+ }
706
+ return min;
707
+ }
708
+ function createSupportsColor(stream, options = {}) {
709
+ const level = _supportsColor(stream, {
710
+ streamIsTTY: stream && stream.isTTY,
711
+ ...options
712
+ });
713
+ return translateLevel(level);
714
+ }
715
+ var supportsColor = {
716
+ stdout: createSupportsColor({ isTTY: tty__default.default.isatty(1) }),
717
+ stderr: createSupportsColor({ isTTY: tty__default.default.isatty(2) })
718
+ };
719
+ var supports_color_default = supportsColor;
720
+
721
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
722
+ function stringReplaceAll(string, substring, replacer) {
723
+ let index = string.indexOf(substring);
724
+ if (index === -1) {
725
+ return string;
726
+ }
727
+ const substringLength = substring.length;
728
+ let endIndex = 0;
729
+ let returnValue = "";
730
+ do {
731
+ returnValue += string.slice(endIndex, index) + substring + replacer;
732
+ endIndex = index + substringLength;
733
+ index = string.indexOf(substring, endIndex);
734
+ } while (index !== -1);
735
+ returnValue += string.slice(endIndex);
736
+ return returnValue;
737
+ }
738
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
739
+ let endIndex = 0;
740
+ let returnValue = "";
741
+ do {
742
+ const gotCR = string[index - 1] === "\r";
743
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
744
+ endIndex = index + 1;
745
+ index = string.indexOf("\n", endIndex);
746
+ } while (index !== -1);
747
+ returnValue += string.slice(endIndex);
748
+ return returnValue;
749
+ }
750
+
751
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
752
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
753
+ var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
754
+ var STYLER = /* @__PURE__ */ Symbol("STYLER");
755
+ var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
756
+ var levelMapping = [
757
+ "ansi",
758
+ "ansi",
759
+ "ansi256",
760
+ "ansi16m"
761
+ ];
762
+ var styles2 = /* @__PURE__ */ Object.create(null);
763
+ var applyOptions = (object, options = {}) => {
764
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
765
+ throw new Error("The `level` option should be an integer from 0 to 3");
766
+ }
767
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
768
+ object.level = options.level === void 0 ? colorLevel : options.level;
769
+ };
770
+ var chalkFactory = (options) => {
771
+ const chalk2 = (...strings) => strings.join(" ");
772
+ applyOptions(chalk2, options);
773
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
774
+ return chalk2;
775
+ };
776
+ function createChalk(options) {
777
+ return chalkFactory(options);
778
+ }
779
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
780
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
781
+ styles2[styleName] = {
782
+ get() {
783
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
784
+ Object.defineProperty(this, styleName, { value: builder });
785
+ return builder;
786
+ }
787
+ };
788
+ }
789
+ styles2.visible = {
790
+ get() {
791
+ const builder = createBuilder(this, this[STYLER], true);
792
+ Object.defineProperty(this, "visible", { value: builder });
793
+ return builder;
794
+ }
795
+ };
796
+ var getModelAnsi = (model, level, type, ...arguments_) => {
797
+ if (model === "rgb") {
798
+ if (level === "ansi16m") {
799
+ return ansi_styles_default[type].ansi16m(...arguments_);
800
+ }
801
+ if (level === "ansi256") {
802
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
803
+ }
804
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
805
+ }
806
+ if (model === "hex") {
807
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
808
+ }
809
+ return ansi_styles_default[type][model](...arguments_);
810
+ };
811
+ var usedModels = ["rgb", "hex", "ansi256"];
812
+ for (const model of usedModels) {
813
+ styles2[model] = {
814
+ get() {
815
+ const { level } = this;
816
+ return function(...arguments_) {
817
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
818
+ return createBuilder(this, styler, this[IS_EMPTY]);
819
+ };
820
+ }
821
+ };
822
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
823
+ styles2[bgModel] = {
824
+ get() {
825
+ const { level } = this;
826
+ return function(...arguments_) {
827
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
828
+ return createBuilder(this, styler, this[IS_EMPTY]);
829
+ };
830
+ }
831
+ };
832
+ }
833
+ var proto = Object.defineProperties(() => {
834
+ }, {
835
+ ...styles2,
836
+ level: {
837
+ enumerable: true,
838
+ get() {
839
+ return this[GENERATOR].level;
840
+ },
841
+ set(level) {
842
+ this[GENERATOR].level = level;
843
+ }
844
+ }
845
+ });
846
+ var createStyler = (open, close, parent) => {
847
+ let openAll;
848
+ let closeAll;
849
+ if (parent === void 0) {
850
+ openAll = open;
851
+ closeAll = close;
852
+ } else {
853
+ openAll = parent.openAll + open;
854
+ closeAll = close + parent.closeAll;
855
+ }
856
+ return {
857
+ open,
858
+ close,
859
+ openAll,
860
+ closeAll,
861
+ parent
862
+ };
863
+ };
864
+ var createBuilder = (self, _styler, _isEmpty) => {
865
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
866
+ Object.setPrototypeOf(builder, proto);
867
+ builder[GENERATOR] = self;
868
+ builder[STYLER] = _styler;
869
+ builder[IS_EMPTY] = _isEmpty;
870
+ return builder;
871
+ };
872
+ var applyStyle = (self, string) => {
873
+ if (self.level <= 0 || !string) {
874
+ return self[IS_EMPTY] ? "" : string;
875
+ }
876
+ let styler = self[STYLER];
877
+ if (styler === void 0) {
878
+ return string;
879
+ }
880
+ const { openAll, closeAll } = styler;
881
+ if (string.includes("\x1B")) {
882
+ while (styler !== void 0) {
883
+ string = stringReplaceAll(string, styler.close, styler.open);
884
+ styler = styler.parent;
885
+ }
886
+ }
887
+ const lfIndex = string.indexOf("\n");
888
+ if (lfIndex !== -1) {
889
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
890
+ }
891
+ return openAll + string + closeAll;
892
+ };
893
+ Object.defineProperties(createChalk.prototype, styles2);
894
+ var chalk = createChalk();
895
+ createChalk({ level: stderrColor ? stderrColor.level : 0 });
896
+ var source_default = chalk;
897
+
898
+ // packages/core/src/diff/renderer.ts
899
+ function formatPath(path) {
900
+ if (path === void 0 || path.path.length === 0) {
901
+ return "(run)";
902
+ }
903
+ return path.path.map((s) => s.name).join(" > ");
904
+ }
905
+ function formatValue(v, verbose) {
906
+ if (v === void 0) return "(undefined)";
907
+ if (typeof v === "string") return v;
908
+ if (typeof v === "number" || typeof v === "boolean") return String(v);
909
+ const s = JSON.stringify(v);
910
+ if (verbose || s.length <= 120) return s;
911
+ return `${s.slice(0, 117)}...`;
912
+ }
913
+ function renderRunDiff(result, options) {
914
+ const json = options?.json === true;
915
+ const verbose = options?.verbose === true;
916
+ const color = options?.color === true;
917
+ if (json) {
918
+ return JSON.stringify(result, null, 2);
919
+ }
920
+ const sev = (s, level) => {
921
+ if (!color) return s;
922
+ if (level === "error") return source_default.red(s);
923
+ if (level === "warning") return source_default.yellow(s);
924
+ return source_default.gray(s);
925
+ };
926
+ const lines = [];
927
+ const { summary } = result;
928
+ lines.push("Run diff");
929
+ lines.push(`Left: ${summary.leftRunId}`);
930
+ lines.push(`Right: ${summary.rightRunId}`);
931
+ lines.push("");
932
+ lines.push("Summary:");
933
+ lines.push(` Differences: ${summary.totalDifferences}`);
934
+ lines.push(` Errors: ${summary.errors}`);
935
+ lines.push(` Warnings: ${summary.warnings}`);
936
+ lines.push(` Info: ${summary.info}`);
937
+ lines.push("");
938
+ const fd = summary.firstDivergence;
939
+ const firstKind = result.differences[0]?.kind;
940
+ if (fd !== void 0) {
941
+ lines.push("First divergence:");
942
+ const where = formatPath(fd.path);
943
+ const displayKind = firstKind ?? fd.kind;
944
+ lines.push(` ${displayKind} at ${where}`);
945
+ if (fd.left !== void 0 || fd.right !== void 0) {
946
+ lines.push(` left: ${formatValue(fd.left, verbose)}`);
947
+ lines.push(` right: ${formatValue(fd.right, verbose)}`);
948
+ }
949
+ lines.push("");
950
+ }
951
+ lines.push("Differences:");
952
+ if (result.differences.length === 0) {
953
+ lines.push(" (none)");
954
+ return lines.join("\n");
955
+ }
956
+ const showSides = (kind) => verbose || [
957
+ "run-status",
958
+ "step-status",
959
+ "error",
960
+ "duration",
961
+ "step-type",
962
+ "structure",
963
+ "step-added",
964
+ "step-removed"
965
+ ].includes(kind);
966
+ for (const d of result.differences) {
967
+ const tag = sev(`[${d.severity}]`, d.severity);
968
+ const pathStr = d.path !== void 0 ? ` ${formatPath(d.path)}` : "";
969
+ lines.push(` ${tag} ${d.kind}${pathStr}`);
970
+ lines.push(` ${d.message}`);
971
+ if (d.left !== void 0 || d.right !== void 0) {
972
+ if (showSides(d.kind)) {
973
+ lines.push(` left: ${formatValue(d.left, verbose)}`);
974
+ lines.push(` right: ${formatValue(d.right, verbose)}`);
975
+ }
976
+ }
977
+ }
978
+ return lines.join("\n");
979
+ }
980
+
981
+ // packages/core/src/diff/index.ts
982
+ function diffTraceEvents(leftEvents, rightEvents, options) {
983
+ const left = manualTraceEventsToComparableRun(leftEvents);
984
+ const right = manualTraceEventsToComparableRun(rightEvents);
985
+ return diffRuns(left, right, options);
986
+ }
987
+
988
+ exports.diffRuns = diffRuns;
989
+ exports.diffTraceEvents = diffTraceEvents;
990
+ exports.manualTraceEventsToComparableRun = manualTraceEventsToComparableRun;
991
+ exports.renderRunDiff = renderRunDiff;
992
+ //# sourceMappingURL=diff.cjs.map
993
+ //# sourceMappingURL=diff.cjs.map