agent-inspect 1.0.3 → 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);
@@ -1176,89 +1206,6 @@ function warn(message, error) {
1176
1206
  }
1177
1207
  console.warn(`${base}: ${formatError(error).message}`);
1178
1208
  }
1179
- var storage = new async_hooks.AsyncLocalStorage();
1180
- function toPublicContext(ctx) {
1181
- return {
1182
- runId: ctx.runId,
1183
- runName: ctx.runName,
1184
- traceDir: ctx.traceDir,
1185
- silent: ctx.silent,
1186
- metadata: ctx.metadata
1187
- };
1188
- }
1189
- function invoke(fn) {
1190
- return new Promise((resolve, reject) => {
1191
- try {
1192
- Promise.resolve(fn()).then(resolve, reject);
1193
- } catch (e) {
1194
- reject(e);
1195
- }
1196
- });
1197
- }
1198
- function getCurrentContext() {
1199
- try {
1200
- const s = storage.getStore();
1201
- if (!s) return void 0;
1202
- return toPublicContext(s);
1203
- } catch {
1204
- return void 0;
1205
- }
1206
- }
1207
- function getCurrentStepId() {
1208
- try {
1209
- return storage.getStore()?.currentStepId;
1210
- } catch {
1211
- return void 0;
1212
- }
1213
- }
1214
- function getParentStepId() {
1215
- return getCurrentStepId();
1216
- }
1217
- function getCurrentDepth() {
1218
- try {
1219
- const d = storage.getStore()?.currentDepth;
1220
- return typeof d === "number" && Number.isFinite(d) ? d : 0;
1221
- } catch {
1222
- return 0;
1223
- }
1224
- }
1225
- function isSilentContext() {
1226
- try {
1227
- const s = storage.getStore();
1228
- return s ? s.silent : false;
1229
- } catch {
1230
- return false;
1231
- }
1232
- }
1233
- function runWithStepContext(stepId, fn) {
1234
- let parent;
1235
- try {
1236
- parent = storage.getStore();
1237
- } catch {
1238
- parent = void 0;
1239
- }
1240
- if (!parent) {
1241
- return invoke(fn);
1242
- }
1243
- const derived = {
1244
- runId: parent.runId,
1245
- runName: parent.runName,
1246
- traceDir: parent.traceDir,
1247
- silent: parent.silent,
1248
- metadata: parent.metadata,
1249
- currentStepId: stepId,
1250
- currentDepth: parent.currentDepth + 1
1251
- };
1252
- return new Promise((resolve, reject) => {
1253
- storage.run(derived, () => {
1254
- try {
1255
- Promise.resolve(fn()).then(resolve, reject);
1256
- } catch (e) {
1257
- reject(e);
1258
- }
1259
- });
1260
- });
1261
- }
1262
1209
  function isRecord6(value) {
1263
1210
  return typeof value === "object" && value !== null && !Array.isArray(value);
1264
1211
  }
@@ -1321,12 +1268,20 @@ function serializeEvent(event) {
1321
1268
  return "";
1322
1269
  }
1323
1270
  }
1271
+ function ensureEventWithinBounds(event) {
1272
+ const line = serializeEvent(event);
1273
+ if (line === "") return event;
1274
+ const bytes = Buffer.byteLength(line, "utf8");
1275
+ if (bytes <= DEFAULT_MAX_EVENT_BYTES) return event;
1276
+ return prepareTraceEventForDisk(event, resolveTraceSafetyOptions());
1277
+ }
1324
1278
  async function writeTraceEvent(event, traceDir) {
1325
- if (!validateEvent(event)) {
1279
+ const bounded = ensureEventWithinBounds(event);
1280
+ if (!validateEvent(bounded)) {
1326
1281
  warn("Skipped invalid trace event (validation failed)");
1327
1282
  return;
1328
1283
  }
1329
- const line = serializeEvent(event);
1284
+ const line = serializeEvent(bounded);
1330
1285
  if (line === "") {
1331
1286
  warn("Skipped trace event (serialization failed)");
1332
1287
  return;
@@ -1393,6 +1348,297 @@ async function readTraceEvents(runId, traceDir) {
1393
1348
  }
1394
1349
  return out;
1395
1350
  }
1351
+
1352
+ // packages/core/src/trace-event-safety.ts
1353
+ var DEFAULT_MAX_METADATA_VALUE_LENGTH = 2e3;
1354
+ var DEFAULT_MAX_PREVIEW_LENGTH = 500;
1355
+ var DEFAULT_MAX_EVENT_BYTES = 65536;
1356
+ function isRecord7(value) {
1357
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1358
+ }
1359
+ function isPreviewKey(key) {
1360
+ return key.toLowerCase().includes("preview");
1361
+ }
1362
+ function truncateString(value, maxLen) {
1363
+ if (maxLen <= 0) return "\u2026";
1364
+ if (value.length <= maxLen) return value;
1365
+ return `${value.slice(0, maxLen)}\u2026`;
1366
+ }
1367
+ function byteLength(text) {
1368
+ return Buffer.byteLength(text, "utf8");
1369
+ }
1370
+ function resolveTraceSafetyOptions(options) {
1371
+ let redactEnabled = true;
1372
+ let redactionRules;
1373
+ {
1374
+ redactEnabled = true;
1375
+ }
1376
+ return {
1377
+ redactEnabled,
1378
+ redactionRules,
1379
+ maxMetadataValueLength: "undefined" === "number" && Number.isFinite(options.maxMetadataValueLength) && options.maxMetadataValueLength >= 0 ? Math.floor(options.maxMetadataValueLength) : DEFAULT_MAX_METADATA_VALUE_LENGTH,
1380
+ maxPreviewLength: "undefined" === "number" && Number.isFinite(options.maxPreviewLength) && options.maxPreviewLength >= 0 ? Math.floor(options.maxPreviewLength) : DEFAULT_MAX_PREVIEW_LENGTH,
1381
+ maxEventBytes: "undefined" === "number" && Number.isFinite(options.maxEventBytes) && options.maxEventBytes > 0 ? Math.floor(options.maxEventBytes) : DEFAULT_MAX_EVENT_BYTES
1382
+ };
1383
+ }
1384
+ function boundMetadataValue(key, value, opts, seen, depth) {
1385
+ if (depth > 32) return "[MaxDepth]";
1386
+ if (value === null || typeof value !== "object") {
1387
+ if (typeof value === "string") {
1388
+ const max = isPreviewKey(key) ? opts.maxPreviewLength : opts.maxMetadataValueLength;
1389
+ return truncateString(value, max);
1390
+ }
1391
+ return value;
1392
+ }
1393
+ if (seen.has(value)) return "[Circular]";
1394
+ seen.add(value);
1395
+ if (Array.isArray(value)) {
1396
+ const maxItems = 50;
1397
+ const out2 = value.slice(0, maxItems).map(
1398
+ (item, index) => boundMetadataValue(String(index), item, opts, seen, depth + 1)
1399
+ );
1400
+ if (value.length > maxItems) {
1401
+ out2.push(`\u2026(+${value.length - maxItems} more)`);
1402
+ }
1403
+ return out2;
1404
+ }
1405
+ const record = value;
1406
+ const out = {};
1407
+ for (const [k, v] of Object.entries(record)) {
1408
+ out[k] = boundMetadataValue(k, v, opts, seen, depth + 1);
1409
+ }
1410
+ return out;
1411
+ }
1412
+ function redactMetadata(metadata, opts) {
1413
+ if (!opts.redactEnabled) return { ...metadata };
1414
+ const redactor = new Redactor({ rules: opts.redactionRules });
1415
+ return redactor.redactRecord(metadata);
1416
+ }
1417
+ function prepareMetadataForDisk(metadata, opts) {
1418
+ try {
1419
+ const redacted = redactMetadata(metadata, opts);
1420
+ const seen = /* @__PURE__ */ new WeakSet();
1421
+ const bounded = boundMetadataValue(
1422
+ "metadata",
1423
+ redacted,
1424
+ opts,
1425
+ seen,
1426
+ 0
1427
+ );
1428
+ return isRecord7(bounded) ? bounded : {};
1429
+ } catch {
1430
+ return { truncated: true, reason: "metadataPreparationFailed" };
1431
+ }
1432
+ }
1433
+ function truncateErrorStack(event, maxLen) {
1434
+ if (event.event !== "run_completed" && event.event !== "step_completed") {
1435
+ return event;
1436
+ }
1437
+ if (!event.error?.stack || typeof event.error.stack !== "string") {
1438
+ return event;
1439
+ }
1440
+ return {
1441
+ ...event,
1442
+ error: {
1443
+ ...event.error,
1444
+ stack: truncateString(event.error.stack, maxLen)
1445
+ }
1446
+ };
1447
+ }
1448
+ function replaceMetadataWithTruncationMarker(event, originalApproxBytes) {
1449
+ const marker = {
1450
+ truncated: true,
1451
+ reason: "maxEventBytes",
1452
+ originalApproxBytes
1453
+ };
1454
+ if (event.event === "run_started") {
1455
+ return { ...event, metadata: marker };
1456
+ }
1457
+ if (event.event === "step_started") {
1458
+ return { ...event, metadata: marker };
1459
+ }
1460
+ return event;
1461
+ }
1462
+ function shrinkMetadataLimits(opts, factor) {
1463
+ return {
1464
+ ...opts,
1465
+ maxMetadataValueLength: Math.max(32, Math.floor(opts.maxMetadataValueLength * factor)),
1466
+ maxPreviewLength: Math.max(16, Math.floor(opts.maxPreviewLength * factor))
1467
+ };
1468
+ }
1469
+ function applyMetadataToEvent(event, metadata) {
1470
+ if (event.event === "run_started") {
1471
+ return { ...event, metadata };
1472
+ }
1473
+ if (event.event === "step_started") {
1474
+ return { ...event, metadata };
1475
+ }
1476
+ return event;
1477
+ }
1478
+ function eventHasMetadata(event) {
1479
+ return (event.event === "run_started" || event.event === "step_started") && event.metadata !== void 0;
1480
+ }
1481
+ function getEventMetadata(event) {
1482
+ if (event.event === "run_started" || event.event === "step_started") {
1483
+ return event.metadata;
1484
+ }
1485
+ return void 0;
1486
+ }
1487
+ function prepareTraceEventForDisk(event, opts) {
1488
+ try {
1489
+ let working = { ...event };
1490
+ const rawMetadata = getEventMetadata(working);
1491
+ if (rawMetadata !== void 0) {
1492
+ const safe = prepareMetadataForDisk(rawMetadata, opts);
1493
+ working = applyMetadataToEvent(working, safe);
1494
+ }
1495
+ let serialized = serializeEvent(working);
1496
+ if (serialized === "") {
1497
+ return working;
1498
+ }
1499
+ let bytes = byteLength(serialized);
1500
+ if (bytes <= opts.maxEventBytes) {
1501
+ return working;
1502
+ }
1503
+ if (rawMetadata !== void 0) {
1504
+ for (const factor of [0.5, 0.25, 0.1]) {
1505
+ const tighter = shrinkMetadataLimits(opts, factor);
1506
+ const shrunk = prepareMetadataForDisk(rawMetadata, tighter);
1507
+ working = applyMetadataToEvent(working, shrunk);
1508
+ serialized = serializeEvent(working);
1509
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1510
+ return working;
1511
+ }
1512
+ }
1513
+ working = replaceMetadataWithTruncationMarker(working, bytes);
1514
+ serialized = serializeEvent(working);
1515
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1516
+ return working;
1517
+ }
1518
+ }
1519
+ working = truncateErrorStack(working, Math.min(opts.maxMetadataValueLength, 500));
1520
+ serialized = serializeEvent(working);
1521
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1522
+ return working;
1523
+ }
1524
+ if (eventHasMetadata(working)) {
1525
+ working = replaceMetadataWithTruncationMarker(working, bytes);
1526
+ serialized = serializeEvent(working);
1527
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1528
+ return working;
1529
+ }
1530
+ if (working.event === "run_started") {
1531
+ const { metadata: _meta, ...rest } = working;
1532
+ working = rest;
1533
+ } else if (working.event === "step_started") {
1534
+ const { metadata: _meta, ...rest } = working;
1535
+ working = rest;
1536
+ }
1537
+ }
1538
+ return working;
1539
+ } catch {
1540
+ if (event.event === "run_started" || event.event === "step_started") {
1541
+ return applyMetadataToEvent(event, {
1542
+ truncated: true,
1543
+ reason: "prepareTraceEventFailed"
1544
+ });
1545
+ }
1546
+ return event;
1547
+ }
1548
+ }
1549
+
1550
+ // packages/core/src/context.ts
1551
+ var storage = new async_hooks.AsyncLocalStorage();
1552
+ function toPublicContext(ctx) {
1553
+ return {
1554
+ runId: ctx.runId,
1555
+ runName: ctx.runName,
1556
+ traceDir: ctx.traceDir,
1557
+ silent: ctx.silent,
1558
+ metadata: ctx.metadata
1559
+ };
1560
+ }
1561
+ function invoke(fn) {
1562
+ return new Promise((resolve, reject) => {
1563
+ try {
1564
+ Promise.resolve(fn()).then(resolve, reject);
1565
+ } catch (e) {
1566
+ reject(e);
1567
+ }
1568
+ });
1569
+ }
1570
+ function getCurrentContext() {
1571
+ try {
1572
+ const s = storage.getStore();
1573
+ if (!s) return void 0;
1574
+ return toPublicContext(s);
1575
+ } catch {
1576
+ return void 0;
1577
+ }
1578
+ }
1579
+ function getCurrentStepId() {
1580
+ try {
1581
+ return storage.getStore()?.currentStepId;
1582
+ } catch {
1583
+ return void 0;
1584
+ }
1585
+ }
1586
+ function getParentStepId() {
1587
+ return getCurrentStepId();
1588
+ }
1589
+ function getCurrentDepth() {
1590
+ try {
1591
+ const d = storage.getStore()?.currentDepth;
1592
+ return typeof d === "number" && Number.isFinite(d) ? d : 0;
1593
+ } catch {
1594
+ return 0;
1595
+ }
1596
+ }
1597
+ function isSilentContext() {
1598
+ try {
1599
+ const s = storage.getStore();
1600
+ return s ? s.silent : false;
1601
+ } catch {
1602
+ return false;
1603
+ }
1604
+ }
1605
+ function getTraceSafetyFromContext() {
1606
+ try {
1607
+ return storage.getStore()?.traceSafety;
1608
+ } catch {
1609
+ return void 0;
1610
+ }
1611
+ }
1612
+ function runWithStepContext(stepId, fn) {
1613
+ let parent;
1614
+ try {
1615
+ parent = storage.getStore();
1616
+ } catch {
1617
+ parent = void 0;
1618
+ }
1619
+ if (!parent) {
1620
+ return invoke(fn);
1621
+ }
1622
+ const derived = {
1623
+ runId: parent.runId,
1624
+ runName: parent.runName,
1625
+ traceDir: parent.traceDir,
1626
+ silent: parent.silent,
1627
+ metadata: parent.metadata,
1628
+ traceSafety: parent.traceSafety,
1629
+ currentStepId: stepId,
1630
+ currentDepth: parent.currentDepth + 1
1631
+ };
1632
+ return new Promise((resolve, reject) => {
1633
+ storage.run(derived, () => {
1634
+ try {
1635
+ Promise.resolve(fn()).then(resolve, reject);
1636
+ } catch (e) {
1637
+ reject(e);
1638
+ }
1639
+ });
1640
+ });
1641
+ }
1396
1642
  function resolveTraceDir(options = {}) {
1397
1643
  if (typeof options.dir === "string" && options.dir.trim() !== "") {
1398
1644
  return options.dir.trim();
@@ -1657,7 +1903,7 @@ var KNOWN_EVENTS = /* @__PURE__ */ new Set([
1657
1903
  "step_started",
1658
1904
  "step_completed"
1659
1905
  ]);
1660
- function isRecord7(value) {
1906
+ function isRecord8(value) {
1661
1907
  return typeof value === "object" && value !== null && !Array.isArray(value);
1662
1908
  }
1663
1909
  function safeParse(line) {
@@ -1679,7 +1925,7 @@ async function isAgentInspectTrace(filePath) {
1679
1925
  if (trimmed === "") continue;
1680
1926
  const parsed = safeParse(trimmed);
1681
1927
  if (!parsed) continue;
1682
- if (!isRecord7(parsed)) continue;
1928
+ if (!isRecord8(parsed)) continue;
1683
1929
  checked += 1;
1684
1930
  if (isTraceEvent(parsed)) return true;
1685
1931
  const ev = parsed.event;
@@ -2180,6 +2426,498 @@ function diffRuns(left, right, options) {
2180
2426
  };
2181
2427
  return { summary, differences };
2182
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
2183
2921
  function formatPath(path7) {
2184
2922
  if (path7 === void 0 || path7.path.length === 0) {
2185
2923
  return "(run)";
@@ -2260,6 +2998,8 @@ function diffTraceEvents(leftEvents, rightEvents, options) {
2260
2998
  const right = manualTraceEventsToComparableRun(rightEvents);
2261
2999
  return diffRuns(left, right, options);
2262
3000
  }
3001
+
3002
+ // packages/core/src/terminal.ts
2263
3003
  var TERMINAL_INDENT = " ";
2264
3004
  var MAX_TERMINAL_NAME_LENGTH = 80;
2265
3005
  var MAX_TERMINAL_DEPTH = 10;
@@ -2285,24 +3025,24 @@ function formatTerminalName(name) {
2285
3025
  return truncateName(name, MAX_TERMINAL_NAME_LENGTH);
2286
3026
  }
2287
3027
  function getStatusIcon(status) {
2288
- if (status === "success") return chalk2__default.default.green("\u2714");
2289
- if (status === "error") return chalk2__default.default.red("\u2716");
2290
- 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");
2291
3031
  }
2292
3032
  function renderStepLine(name, durationMs, status, depth) {
2293
3033
  try {
2294
3034
  const nm = formatTerminalName(name);
2295
3035
  const ind = getIndent(depth ?? 0);
2296
3036
  if (status === "running" && durationMs === void 0) {
2297
- return `${ind}${chalk2__default.default.yellow("\u23F3")} ${nm}`;
3037
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2298
3038
  }
2299
3039
  const hasDur = durationMs !== void 0 && Number.isFinite(durationMs);
2300
3040
  const dur = hasDur ? formatDuration2(durationMs) : void 0;
2301
3041
  if (status === "running") {
2302
- 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}`;
2303
3043
  }
2304
3044
  if (!hasDur || dur === void 0) {
2305
- return `${ind}${chalk2__default.default.yellow("\u23F3")} ${nm}`;
3045
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2306
3046
  }
2307
3047
  if (status === "success") {
2308
3048
  return `${ind}${getStatusIcon("success")} ${nm} (${dur})`;
@@ -2379,6 +3119,7 @@ async function stepImpl(name, fn, options) {
2379
3119
  const parentId = getParentStepId();
2380
3120
  const stepType = options?.type ?? "logic";
2381
3121
  const metadata = options?.metadata;
3122
+ const traceSafety = getTraceSafetyFromContext();
2382
3123
  const startTime = Date.now();
2383
3124
  await safeInstrumentation("writeTraceEvent(step_started)", async () => {
2384
3125
  const started = {
@@ -2393,7 +3134,8 @@ async function stepImpl(name, fn, options) {
2393
3134
  startTime,
2394
3135
  ...metadata !== void 0 ? { metadata } : {}
2395
3136
  };
2396
- await writeTraceEvent(started, context.traceDir);
3137
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(started, traceSafety) : started;
3138
+ await writeTraceEvent(safe, context.traceDir);
2397
3139
  });
2398
3140
  await safeInstrumentation("printStepStart", () => {
2399
3141
  printStepStart(stepName, renderDepth);
@@ -2419,7 +3161,8 @@ async function stepImpl(name, fn, options) {
2419
3161
  durationMs: durationMs2,
2420
3162
  error: formatted
2421
3163
  };
2422
- await writeTraceEvent(completed, context.traceDir);
3164
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(completed, traceSafety) : completed;
3165
+ await writeTraceEvent(safe, context.traceDir);
2423
3166
  });
2424
3167
  await safeInstrumentation("printStepComplete(error)", () => {
2425
3168
  printStepComplete(stepName, durationMs2, "error", renderDepth);
@@ -2445,7 +3188,8 @@ async function stepImpl(name, fn, options) {
2445
3188
  endTime,
2446
3189
  durationMs
2447
3190
  };
2448
- await writeTraceEvent(completed, context.traceDir);
3191
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(completed, traceSafety) : completed;
3192
+ await writeTraceEvent(safe, context.traceDir);
2449
3193
  });
2450
3194
  await safeInstrumentation("printStepComplete(success)", () => {
2451
3195
  printStepComplete(stepName, durationMs, "success", renderDepth);
@@ -3351,7 +4095,7 @@ function stableSortNewestFirst(a, b) {
3351
4095
  }
3352
4096
  async function confirmDeletion(count) {
3353
4097
  const { createInterface: createInterface2 } = await import('readline/promises');
3354
- const rl = createInterface2({ input: process$1.stdin, output: process$1.stdout });
4098
+ const rl = createInterface2({ input: process2.stdin, output: process2.stdout });
3355
4099
  try {
3356
4100
  const answer = await rl.question(
3357
4101
  `Delete ${count} AgentInspect trace file(s)? Type "yes" to continue: `
@@ -3444,7 +4188,7 @@ async function clean(options = {}) {
3444
4188
  return;
3445
4189
  }
3446
4190
  if (options.yes !== true) {
3447
- if (process$1.stdin.isTTY !== true) {
4191
+ if (process2.stdin.isTTY !== true) {
3448
4192
  console.error(
3449
4193
  "Refusing to delete without --yes in a non-interactive terminal."
3450
4194
  );
@@ -3854,7 +4598,7 @@ function sleep(ms) {
3854
4598
  }
3855
4599
  async function* readStdinLines() {
3856
4600
  const { createInterface: createInterface2 } = await import('readline');
3857
- const rl = createInterface2({ input: process$1.stdin, crlfDelay: Infinity });
4601
+ const rl = createInterface2({ input: process2.stdin, crlfDelay: Infinity });
3858
4602
  try {
3859
4603
  for await (const line of rl) {
3860
4604
  yield line;