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.
@@ -4,13 +4,12 @@ import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { Command, Option } from 'commander';
6
6
  import { unlink, stat, mkdir, writeFile, appendFile, readdir, readFile, open } from 'fs/promises';
7
- import crypto from 'crypto';
8
- import { nanoid } from 'nanoid';
7
+ import crypto, { webcrypto } from 'crypto';
9
8
  import os from 'os';
10
9
  import { AsyncLocalStorage } from 'async_hooks';
11
10
  import { createInterface } from 'readline';
12
- import chalk2 from 'chalk';
13
- import { stdin, stdout } from 'process';
11
+ import process2, { stdin, stdout } from 'process';
12
+ import tty from 'tty';
14
13
 
15
14
  // packages/core/src/types.ts
16
15
  var STEP_TYPES = [
@@ -50,6 +49,86 @@ function isTraceEvent(value) {
50
49
  return false;
51
50
  }
52
51
  }
52
+
53
+ // packages/core/src/logs/tree-builder.ts
54
+ function inc(map, key) {
55
+ map[key] = (map[key] ?? 0) + 1;
56
+ }
57
+ function computeRunStatus(events) {
58
+ let hasRunning = false;
59
+ for (const e of events) {
60
+ if (e.status === "error") return "error";
61
+ if (e.status === "running") hasRunning = true;
62
+ }
63
+ if (hasRunning) return "running";
64
+ return "ok";
65
+ }
66
+ var TreeBuilder = class {
67
+ constructor(options) {
68
+ void options?.config;
69
+ }
70
+ build(events) {
71
+ const byRun = /* @__PURE__ */ new Map();
72
+ for (const e of events) {
73
+ if (!byRun.has(e.runId)) byRun.set(e.runId, []);
74
+ byRun.get(e.runId).push(e);
75
+ }
76
+ const out = [];
77
+ for (const [runId, runEvents] of byRun.entries()) {
78
+ const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
79
+ const nodes = /* @__PURE__ */ new Map();
80
+ for (const e of sorted) {
81
+ nodes.set(e.eventId, { event: e, children: [], depth: 0 });
82
+ }
83
+ const roots = [];
84
+ for (const node of nodes.values()) {
85
+ const parentId = node.event.parentId;
86
+ if (parentId && nodes.has(parentId)) {
87
+ nodes.get(parentId).children.push(node);
88
+ } else {
89
+ roots.push(node);
90
+ }
91
+ }
92
+ const assignDepth = (n, depth) => {
93
+ n.depth = depth;
94
+ for (const c of n.children) assignDepth(c, depth + 1);
95
+ };
96
+ for (const r of roots) assignDepth(r, 0);
97
+ const confidenceBreakdown = {
98
+ explicit: 0,
99
+ correlated: 0,
100
+ heuristic: 0,
101
+ unknown: 0
102
+ };
103
+ const kinds = {};
104
+ for (const e of sorted) {
105
+ inc(confidenceBreakdown, e.confidence);
106
+ kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
107
+ }
108
+ const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
109
+ const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
110
+ const status = computeRunStatus(sorted);
111
+ const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
112
+ const name = sorted.find((e) => e.kind === "RUN")?.name;
113
+ out.push({
114
+ runId,
115
+ name,
116
+ status,
117
+ startedAt,
118
+ endedAt: status === "running" ? void 0 : endedAt,
119
+ durationMs,
120
+ children: roots,
121
+ metadata: {
122
+ totalEvents: sorted.length,
123
+ confidenceBreakdown,
124
+ kinds
125
+ }
126
+ });
127
+ }
128
+ out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
129
+ return out;
130
+ }
131
+ };
53
132
  function isRecord2(v) {
54
133
  return typeof v === "object" && v !== null && !Array.isArray(v);
55
134
  }
@@ -456,6 +535,36 @@ var Redactor = class {
456
535
  return value;
457
536
  }
458
537
  };
538
+
539
+ // node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js
540
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
541
+
542
+ // node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/index.js
543
+ var POOL_SIZE_MULTIPLIER = 128;
544
+ var pool;
545
+ var poolOffset;
546
+ function fillPool(bytes) {
547
+ if (bytes < 0 || bytes > 1024) throw new RangeError("Wrong ID size");
548
+ if (!pool || pool.length < bytes) {
549
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
550
+ webcrypto.getRandomValues(pool);
551
+ poolOffset = 0;
552
+ } else if (poolOffset + bytes > pool.length) {
553
+ webcrypto.getRandomValues(pool);
554
+ poolOffset = 0;
555
+ }
556
+ poolOffset += bytes;
557
+ }
558
+ function nanoid(size = 21) {
559
+ fillPool(size |= 0);
560
+ let id = "";
561
+ for (let i = poolOffset - size; i < poolOffset; i++) {
562
+ id += urlAlphabet[pool[i] & 63];
563
+ }
564
+ return id;
565
+ }
566
+
567
+ // packages/core/src/logs/normalizer.ts
459
568
  function isFiniteNumber(v) {
460
569
  return typeof v === "number" && Number.isFinite(v);
461
570
  }
@@ -636,86 +745,6 @@ var EventNormalizer = class {
636
745
  }
637
746
  };
638
747
 
639
- // packages/core/src/logs/tree-builder.ts
640
- function inc(map, key) {
641
- map[key] = (map[key] ?? 0) + 1;
642
- }
643
- function computeRunStatus(events) {
644
- let hasRunning = false;
645
- for (const e of events) {
646
- if (e.status === "error") return "error";
647
- if (e.status === "running") hasRunning = true;
648
- }
649
- if (hasRunning) return "running";
650
- return "ok";
651
- }
652
- var TreeBuilder = class {
653
- constructor(options) {
654
- void options?.config;
655
- }
656
- build(events) {
657
- const byRun = /* @__PURE__ */ new Map();
658
- for (const e of events) {
659
- if (!byRun.has(e.runId)) byRun.set(e.runId, []);
660
- byRun.get(e.runId).push(e);
661
- }
662
- const out = [];
663
- for (const [runId, runEvents] of byRun.entries()) {
664
- const sorted = [...runEvents].sort((a, b) => a.timestamp - b.timestamp);
665
- const nodes = /* @__PURE__ */ new Map();
666
- for (const e of sorted) {
667
- nodes.set(e.eventId, { event: e, children: [], depth: 0 });
668
- }
669
- const roots = [];
670
- for (const node of nodes.values()) {
671
- const parentId = node.event.parentId;
672
- if (parentId && nodes.has(parentId)) {
673
- nodes.get(parentId).children.push(node);
674
- } else {
675
- roots.push(node);
676
- }
677
- }
678
- const assignDepth = (n, depth) => {
679
- n.depth = depth;
680
- for (const c of n.children) assignDepth(c, depth + 1);
681
- };
682
- for (const r of roots) assignDepth(r, 0);
683
- const confidenceBreakdown = {
684
- explicit: 0,
685
- correlated: 0,
686
- heuristic: 0,
687
- unknown: 0
688
- };
689
- const kinds = {};
690
- for (const e of sorted) {
691
- inc(confidenceBreakdown, e.confidence);
692
- kinds[e.kind] = (kinds[e.kind] ?? 0) + 1;
693
- }
694
- const startedAt = sorted.length > 0 ? sorted[0].timestamp : void 0;
695
- const endedAt = sorted.length > 0 ? sorted[sorted.length - 1].timestamp : void 0;
696
- const status = computeRunStatus(sorted);
697
- const durationMs = startedAt !== void 0 && endedAt !== void 0 && Number.isFinite(startedAt) && Number.isFinite(endedAt) && endedAt >= startedAt && status !== "running" ? endedAt - startedAt : void 0;
698
- const name = sorted.find((e) => e.kind === "RUN")?.name;
699
- out.push({
700
- runId,
701
- name,
702
- status,
703
- startedAt,
704
- endedAt: status === "running" ? void 0 : endedAt,
705
- durationMs,
706
- children: roots,
707
- metadata: {
708
- totalEvents: sorted.length,
709
- confidenceBreakdown,
710
- kinds
711
- }
712
- });
713
- }
714
- out.sort((a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0));
715
- return out;
716
- }
717
- };
718
-
719
748
  // packages/core/src/logs/tree-renderer.ts
720
749
  function truncate(v, max) {
721
750
  if (v.length <= max) return v;
@@ -1166,89 +1195,6 @@ function warn(message, error) {
1166
1195
  }
1167
1196
  console.warn(`${base}: ${formatError(error).message}`);
1168
1197
  }
1169
- var storage = new AsyncLocalStorage();
1170
- function toPublicContext(ctx) {
1171
- return {
1172
- runId: ctx.runId,
1173
- runName: ctx.runName,
1174
- traceDir: ctx.traceDir,
1175
- silent: ctx.silent,
1176
- metadata: ctx.metadata
1177
- };
1178
- }
1179
- function invoke(fn) {
1180
- return new Promise((resolve, reject) => {
1181
- try {
1182
- Promise.resolve(fn()).then(resolve, reject);
1183
- } catch (e) {
1184
- reject(e);
1185
- }
1186
- });
1187
- }
1188
- function getCurrentContext() {
1189
- try {
1190
- const s = storage.getStore();
1191
- if (!s) return void 0;
1192
- return toPublicContext(s);
1193
- } catch {
1194
- return void 0;
1195
- }
1196
- }
1197
- function getCurrentStepId() {
1198
- try {
1199
- return storage.getStore()?.currentStepId;
1200
- } catch {
1201
- return void 0;
1202
- }
1203
- }
1204
- function getParentStepId() {
1205
- return getCurrentStepId();
1206
- }
1207
- function getCurrentDepth() {
1208
- try {
1209
- const d = storage.getStore()?.currentDepth;
1210
- return typeof d === "number" && Number.isFinite(d) ? d : 0;
1211
- } catch {
1212
- return 0;
1213
- }
1214
- }
1215
- function isSilentContext() {
1216
- try {
1217
- const s = storage.getStore();
1218
- return s ? s.silent : false;
1219
- } catch {
1220
- return false;
1221
- }
1222
- }
1223
- function runWithStepContext(stepId, fn) {
1224
- let parent;
1225
- try {
1226
- parent = storage.getStore();
1227
- } catch {
1228
- parent = void 0;
1229
- }
1230
- if (!parent) {
1231
- return invoke(fn);
1232
- }
1233
- const derived = {
1234
- runId: parent.runId,
1235
- runName: parent.runName,
1236
- traceDir: parent.traceDir,
1237
- silent: parent.silent,
1238
- metadata: parent.metadata,
1239
- currentStepId: stepId,
1240
- currentDepth: parent.currentDepth + 1
1241
- };
1242
- return new Promise((resolve, reject) => {
1243
- storage.run(derived, () => {
1244
- try {
1245
- Promise.resolve(fn()).then(resolve, reject);
1246
- } catch (e) {
1247
- reject(e);
1248
- }
1249
- });
1250
- });
1251
- }
1252
1198
  function isRecord6(value) {
1253
1199
  return typeof value === "object" && value !== null && !Array.isArray(value);
1254
1200
  }
@@ -1311,12 +1257,20 @@ function serializeEvent(event) {
1311
1257
  return "";
1312
1258
  }
1313
1259
  }
1260
+ function ensureEventWithinBounds(event) {
1261
+ const line = serializeEvent(event);
1262
+ if (line === "") return event;
1263
+ const bytes = Buffer.byteLength(line, "utf8");
1264
+ if (bytes <= DEFAULT_MAX_EVENT_BYTES) return event;
1265
+ return prepareTraceEventForDisk(event, resolveTraceSafetyOptions());
1266
+ }
1314
1267
  async function writeTraceEvent(event, traceDir) {
1315
- if (!validateEvent(event)) {
1268
+ const bounded = ensureEventWithinBounds(event);
1269
+ if (!validateEvent(bounded)) {
1316
1270
  warn("Skipped invalid trace event (validation failed)");
1317
1271
  return;
1318
1272
  }
1319
- const line = serializeEvent(event);
1273
+ const line = serializeEvent(bounded);
1320
1274
  if (line === "") {
1321
1275
  warn("Skipped trace event (serialization failed)");
1322
1276
  return;
@@ -1383,6 +1337,297 @@ async function readTraceEvents(runId, traceDir) {
1383
1337
  }
1384
1338
  return out;
1385
1339
  }
1340
+
1341
+ // packages/core/src/trace-event-safety.ts
1342
+ var DEFAULT_MAX_METADATA_VALUE_LENGTH = 2e3;
1343
+ var DEFAULT_MAX_PREVIEW_LENGTH = 500;
1344
+ var DEFAULT_MAX_EVENT_BYTES = 65536;
1345
+ function isRecord7(value) {
1346
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1347
+ }
1348
+ function isPreviewKey(key) {
1349
+ return key.toLowerCase().includes("preview");
1350
+ }
1351
+ function truncateString(value, maxLen) {
1352
+ if (maxLen <= 0) return "\u2026";
1353
+ if (value.length <= maxLen) return value;
1354
+ return `${value.slice(0, maxLen)}\u2026`;
1355
+ }
1356
+ function byteLength(text) {
1357
+ return Buffer.byteLength(text, "utf8");
1358
+ }
1359
+ function resolveTraceSafetyOptions(options) {
1360
+ let redactEnabled = true;
1361
+ let redactionRules;
1362
+ {
1363
+ redactEnabled = true;
1364
+ }
1365
+ return {
1366
+ redactEnabled,
1367
+ redactionRules,
1368
+ maxMetadataValueLength: "undefined" === "number" && Number.isFinite(options.maxMetadataValueLength) && options.maxMetadataValueLength >= 0 ? Math.floor(options.maxMetadataValueLength) : DEFAULT_MAX_METADATA_VALUE_LENGTH,
1369
+ maxPreviewLength: "undefined" === "number" && Number.isFinite(options.maxPreviewLength) && options.maxPreviewLength >= 0 ? Math.floor(options.maxPreviewLength) : DEFAULT_MAX_PREVIEW_LENGTH,
1370
+ maxEventBytes: "undefined" === "number" && Number.isFinite(options.maxEventBytes) && options.maxEventBytes > 0 ? Math.floor(options.maxEventBytes) : DEFAULT_MAX_EVENT_BYTES
1371
+ };
1372
+ }
1373
+ function boundMetadataValue(key, value, opts, seen, depth) {
1374
+ if (depth > 32) return "[MaxDepth]";
1375
+ if (value === null || typeof value !== "object") {
1376
+ if (typeof value === "string") {
1377
+ const max = isPreviewKey(key) ? opts.maxPreviewLength : opts.maxMetadataValueLength;
1378
+ return truncateString(value, max);
1379
+ }
1380
+ return value;
1381
+ }
1382
+ if (seen.has(value)) return "[Circular]";
1383
+ seen.add(value);
1384
+ if (Array.isArray(value)) {
1385
+ const maxItems = 50;
1386
+ const out2 = value.slice(0, maxItems).map(
1387
+ (item, index) => boundMetadataValue(String(index), item, opts, seen, depth + 1)
1388
+ );
1389
+ if (value.length > maxItems) {
1390
+ out2.push(`\u2026(+${value.length - maxItems} more)`);
1391
+ }
1392
+ return out2;
1393
+ }
1394
+ const record = value;
1395
+ const out = {};
1396
+ for (const [k, v] of Object.entries(record)) {
1397
+ out[k] = boundMetadataValue(k, v, opts, seen, depth + 1);
1398
+ }
1399
+ return out;
1400
+ }
1401
+ function redactMetadata(metadata, opts) {
1402
+ if (!opts.redactEnabled) return { ...metadata };
1403
+ const redactor = new Redactor({ rules: opts.redactionRules });
1404
+ return redactor.redactRecord(metadata);
1405
+ }
1406
+ function prepareMetadataForDisk(metadata, opts) {
1407
+ try {
1408
+ const redacted = redactMetadata(metadata, opts);
1409
+ const seen = /* @__PURE__ */ new WeakSet();
1410
+ const bounded = boundMetadataValue(
1411
+ "metadata",
1412
+ redacted,
1413
+ opts,
1414
+ seen,
1415
+ 0
1416
+ );
1417
+ return isRecord7(bounded) ? bounded : {};
1418
+ } catch {
1419
+ return { truncated: true, reason: "metadataPreparationFailed" };
1420
+ }
1421
+ }
1422
+ function truncateErrorStack(event, maxLen) {
1423
+ if (event.event !== "run_completed" && event.event !== "step_completed") {
1424
+ return event;
1425
+ }
1426
+ if (!event.error?.stack || typeof event.error.stack !== "string") {
1427
+ return event;
1428
+ }
1429
+ return {
1430
+ ...event,
1431
+ error: {
1432
+ ...event.error,
1433
+ stack: truncateString(event.error.stack, maxLen)
1434
+ }
1435
+ };
1436
+ }
1437
+ function replaceMetadataWithTruncationMarker(event, originalApproxBytes) {
1438
+ const marker = {
1439
+ truncated: true,
1440
+ reason: "maxEventBytes",
1441
+ originalApproxBytes
1442
+ };
1443
+ if (event.event === "run_started") {
1444
+ return { ...event, metadata: marker };
1445
+ }
1446
+ if (event.event === "step_started") {
1447
+ return { ...event, metadata: marker };
1448
+ }
1449
+ return event;
1450
+ }
1451
+ function shrinkMetadataLimits(opts, factor) {
1452
+ return {
1453
+ ...opts,
1454
+ maxMetadataValueLength: Math.max(32, Math.floor(opts.maxMetadataValueLength * factor)),
1455
+ maxPreviewLength: Math.max(16, Math.floor(opts.maxPreviewLength * factor))
1456
+ };
1457
+ }
1458
+ function applyMetadataToEvent(event, metadata) {
1459
+ if (event.event === "run_started") {
1460
+ return { ...event, metadata };
1461
+ }
1462
+ if (event.event === "step_started") {
1463
+ return { ...event, metadata };
1464
+ }
1465
+ return event;
1466
+ }
1467
+ function eventHasMetadata(event) {
1468
+ return (event.event === "run_started" || event.event === "step_started") && event.metadata !== void 0;
1469
+ }
1470
+ function getEventMetadata(event) {
1471
+ if (event.event === "run_started" || event.event === "step_started") {
1472
+ return event.metadata;
1473
+ }
1474
+ return void 0;
1475
+ }
1476
+ function prepareTraceEventForDisk(event, opts) {
1477
+ try {
1478
+ let working = { ...event };
1479
+ const rawMetadata = getEventMetadata(working);
1480
+ if (rawMetadata !== void 0) {
1481
+ const safe = prepareMetadataForDisk(rawMetadata, opts);
1482
+ working = applyMetadataToEvent(working, safe);
1483
+ }
1484
+ let serialized = serializeEvent(working);
1485
+ if (serialized === "") {
1486
+ return working;
1487
+ }
1488
+ let bytes = byteLength(serialized);
1489
+ if (bytes <= opts.maxEventBytes) {
1490
+ return working;
1491
+ }
1492
+ if (rawMetadata !== void 0) {
1493
+ for (const factor of [0.5, 0.25, 0.1]) {
1494
+ const tighter = shrinkMetadataLimits(opts, factor);
1495
+ const shrunk = prepareMetadataForDisk(rawMetadata, tighter);
1496
+ working = applyMetadataToEvent(working, shrunk);
1497
+ serialized = serializeEvent(working);
1498
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1499
+ return working;
1500
+ }
1501
+ }
1502
+ working = replaceMetadataWithTruncationMarker(working, bytes);
1503
+ serialized = serializeEvent(working);
1504
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1505
+ return working;
1506
+ }
1507
+ }
1508
+ working = truncateErrorStack(working, Math.min(opts.maxMetadataValueLength, 500));
1509
+ serialized = serializeEvent(working);
1510
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1511
+ return working;
1512
+ }
1513
+ if (eventHasMetadata(working)) {
1514
+ working = replaceMetadataWithTruncationMarker(working, bytes);
1515
+ serialized = serializeEvent(working);
1516
+ if (serialized !== "" && byteLength(serialized) <= opts.maxEventBytes) {
1517
+ return working;
1518
+ }
1519
+ if (working.event === "run_started") {
1520
+ const { metadata: _meta, ...rest } = working;
1521
+ working = rest;
1522
+ } else if (working.event === "step_started") {
1523
+ const { metadata: _meta, ...rest } = working;
1524
+ working = rest;
1525
+ }
1526
+ }
1527
+ return working;
1528
+ } catch {
1529
+ if (event.event === "run_started" || event.event === "step_started") {
1530
+ return applyMetadataToEvent(event, {
1531
+ truncated: true,
1532
+ reason: "prepareTraceEventFailed"
1533
+ });
1534
+ }
1535
+ return event;
1536
+ }
1537
+ }
1538
+
1539
+ // packages/core/src/context.ts
1540
+ var storage = new AsyncLocalStorage();
1541
+ function toPublicContext(ctx) {
1542
+ return {
1543
+ runId: ctx.runId,
1544
+ runName: ctx.runName,
1545
+ traceDir: ctx.traceDir,
1546
+ silent: ctx.silent,
1547
+ metadata: ctx.metadata
1548
+ };
1549
+ }
1550
+ function invoke(fn) {
1551
+ return new Promise((resolve, reject) => {
1552
+ try {
1553
+ Promise.resolve(fn()).then(resolve, reject);
1554
+ } catch (e) {
1555
+ reject(e);
1556
+ }
1557
+ });
1558
+ }
1559
+ function getCurrentContext() {
1560
+ try {
1561
+ const s = storage.getStore();
1562
+ if (!s) return void 0;
1563
+ return toPublicContext(s);
1564
+ } catch {
1565
+ return void 0;
1566
+ }
1567
+ }
1568
+ function getCurrentStepId() {
1569
+ try {
1570
+ return storage.getStore()?.currentStepId;
1571
+ } catch {
1572
+ return void 0;
1573
+ }
1574
+ }
1575
+ function getParentStepId() {
1576
+ return getCurrentStepId();
1577
+ }
1578
+ function getCurrentDepth() {
1579
+ try {
1580
+ const d = storage.getStore()?.currentDepth;
1581
+ return typeof d === "number" && Number.isFinite(d) ? d : 0;
1582
+ } catch {
1583
+ return 0;
1584
+ }
1585
+ }
1586
+ function isSilentContext() {
1587
+ try {
1588
+ const s = storage.getStore();
1589
+ return s ? s.silent : false;
1590
+ } catch {
1591
+ return false;
1592
+ }
1593
+ }
1594
+ function getTraceSafetyFromContext() {
1595
+ try {
1596
+ return storage.getStore()?.traceSafety;
1597
+ } catch {
1598
+ return void 0;
1599
+ }
1600
+ }
1601
+ function runWithStepContext(stepId, fn) {
1602
+ let parent;
1603
+ try {
1604
+ parent = storage.getStore();
1605
+ } catch {
1606
+ parent = void 0;
1607
+ }
1608
+ if (!parent) {
1609
+ return invoke(fn);
1610
+ }
1611
+ const derived = {
1612
+ runId: parent.runId,
1613
+ runName: parent.runName,
1614
+ traceDir: parent.traceDir,
1615
+ silent: parent.silent,
1616
+ metadata: parent.metadata,
1617
+ traceSafety: parent.traceSafety,
1618
+ currentStepId: stepId,
1619
+ currentDepth: parent.currentDepth + 1
1620
+ };
1621
+ return new Promise((resolve, reject) => {
1622
+ storage.run(derived, () => {
1623
+ try {
1624
+ Promise.resolve(fn()).then(resolve, reject);
1625
+ } catch (e) {
1626
+ reject(e);
1627
+ }
1628
+ });
1629
+ });
1630
+ }
1386
1631
  function resolveTraceDir(options = {}) {
1387
1632
  if (typeof options.dir === "string" && options.dir.trim() !== "") {
1388
1633
  return options.dir.trim();
@@ -1647,7 +1892,7 @@ var KNOWN_EVENTS = /* @__PURE__ */ new Set([
1647
1892
  "step_started",
1648
1893
  "step_completed"
1649
1894
  ]);
1650
- function isRecord7(value) {
1895
+ function isRecord8(value) {
1651
1896
  return typeof value === "object" && value !== null && !Array.isArray(value);
1652
1897
  }
1653
1898
  function safeParse(line) {
@@ -1669,7 +1914,7 @@ async function isAgentInspectTrace(filePath) {
1669
1914
  if (trimmed === "") continue;
1670
1915
  const parsed = safeParse(trimmed);
1671
1916
  if (!parsed) continue;
1672
- if (!isRecord7(parsed)) continue;
1917
+ if (!isRecord8(parsed)) continue;
1673
1918
  checked += 1;
1674
1919
  if (isTraceEvent(parsed)) return true;
1675
1920
  const ev = parsed.event;
@@ -2170,6 +2415,498 @@ function diffRuns(left, right, options) {
2170
2415
  };
2171
2416
  return { summary, differences };
2172
2417
  }
2418
+
2419
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
2420
+ var ANSI_BACKGROUND_OFFSET = 10;
2421
+ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
2422
+ var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
2423
+ var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
2424
+ var styles = {
2425
+ modifier: {
2426
+ reset: [0, 0],
2427
+ // 21 isn't widely supported and 22 does the same thing
2428
+ bold: [1, 22],
2429
+ dim: [2, 22],
2430
+ italic: [3, 23],
2431
+ underline: [4, 24],
2432
+ overline: [53, 55],
2433
+ inverse: [7, 27],
2434
+ hidden: [8, 28],
2435
+ strikethrough: [9, 29]
2436
+ },
2437
+ color: {
2438
+ black: [30, 39],
2439
+ red: [31, 39],
2440
+ green: [32, 39],
2441
+ yellow: [33, 39],
2442
+ blue: [34, 39],
2443
+ magenta: [35, 39],
2444
+ cyan: [36, 39],
2445
+ white: [37, 39],
2446
+ // Bright color
2447
+ blackBright: [90, 39],
2448
+ gray: [90, 39],
2449
+ // Alias of `blackBright`
2450
+ grey: [90, 39],
2451
+ // Alias of `blackBright`
2452
+ redBright: [91, 39],
2453
+ greenBright: [92, 39],
2454
+ yellowBright: [93, 39],
2455
+ blueBright: [94, 39],
2456
+ magentaBright: [95, 39],
2457
+ cyanBright: [96, 39],
2458
+ whiteBright: [97, 39]
2459
+ },
2460
+ bgColor: {
2461
+ bgBlack: [40, 49],
2462
+ bgRed: [41, 49],
2463
+ bgGreen: [42, 49],
2464
+ bgYellow: [43, 49],
2465
+ bgBlue: [44, 49],
2466
+ bgMagenta: [45, 49],
2467
+ bgCyan: [46, 49],
2468
+ bgWhite: [47, 49],
2469
+ // Bright color
2470
+ bgBlackBright: [100, 49],
2471
+ bgGray: [100, 49],
2472
+ // Alias of `bgBlackBright`
2473
+ bgGrey: [100, 49],
2474
+ // Alias of `bgBlackBright`
2475
+ bgRedBright: [101, 49],
2476
+ bgGreenBright: [102, 49],
2477
+ bgYellowBright: [103, 49],
2478
+ bgBlueBright: [104, 49],
2479
+ bgMagentaBright: [105, 49],
2480
+ bgCyanBright: [106, 49],
2481
+ bgWhiteBright: [107, 49]
2482
+ }
2483
+ };
2484
+ Object.keys(styles.modifier);
2485
+ var foregroundColorNames = Object.keys(styles.color);
2486
+ var backgroundColorNames = Object.keys(styles.bgColor);
2487
+ [...foregroundColorNames, ...backgroundColorNames];
2488
+ function assembleStyles() {
2489
+ const codes = /* @__PURE__ */ new Map();
2490
+ for (const [groupName, group] of Object.entries(styles)) {
2491
+ for (const [styleName, style] of Object.entries(group)) {
2492
+ styles[styleName] = {
2493
+ open: `\x1B[${style[0]}m`,
2494
+ close: `\x1B[${style[1]}m`
2495
+ };
2496
+ group[styleName] = styles[styleName];
2497
+ codes.set(style[0], style[1]);
2498
+ }
2499
+ Object.defineProperty(styles, groupName, {
2500
+ value: group,
2501
+ enumerable: false
2502
+ });
2503
+ }
2504
+ Object.defineProperty(styles, "codes", {
2505
+ value: codes,
2506
+ enumerable: false
2507
+ });
2508
+ styles.color.close = "\x1B[39m";
2509
+ styles.bgColor.close = "\x1B[49m";
2510
+ styles.color.ansi = wrapAnsi16();
2511
+ styles.color.ansi256 = wrapAnsi256();
2512
+ styles.color.ansi16m = wrapAnsi16m();
2513
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
2514
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
2515
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
2516
+ Object.defineProperties(styles, {
2517
+ rgbToAnsi256: {
2518
+ value(red, green, blue) {
2519
+ if (red === green && green === blue) {
2520
+ if (red < 8) {
2521
+ return 16;
2522
+ }
2523
+ if (red > 248) {
2524
+ return 231;
2525
+ }
2526
+ return Math.round((red - 8) / 247 * 24) + 232;
2527
+ }
2528
+ return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
2529
+ },
2530
+ enumerable: false
2531
+ },
2532
+ hexToRgb: {
2533
+ value(hex) {
2534
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
2535
+ if (!matches) {
2536
+ return [0, 0, 0];
2537
+ }
2538
+ let [colorString] = matches;
2539
+ if (colorString.length === 3) {
2540
+ colorString = [...colorString].map((character) => character + character).join("");
2541
+ }
2542
+ const integer = Number.parseInt(colorString, 16);
2543
+ return [
2544
+ /* eslint-disable no-bitwise */
2545
+ integer >> 16 & 255,
2546
+ integer >> 8 & 255,
2547
+ integer & 255
2548
+ /* eslint-enable no-bitwise */
2549
+ ];
2550
+ },
2551
+ enumerable: false
2552
+ },
2553
+ hexToAnsi256: {
2554
+ value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
2555
+ enumerable: false
2556
+ },
2557
+ ansi256ToAnsi: {
2558
+ value(code) {
2559
+ if (code < 8) {
2560
+ return 30 + code;
2561
+ }
2562
+ if (code < 16) {
2563
+ return 90 + (code - 8);
2564
+ }
2565
+ let red;
2566
+ let green;
2567
+ let blue;
2568
+ if (code >= 232) {
2569
+ red = ((code - 232) * 10 + 8) / 255;
2570
+ green = red;
2571
+ blue = red;
2572
+ } else {
2573
+ code -= 16;
2574
+ const remainder = code % 36;
2575
+ red = Math.floor(code / 36) / 5;
2576
+ green = Math.floor(remainder / 6) / 5;
2577
+ blue = remainder % 6 / 5;
2578
+ }
2579
+ const value = Math.max(red, green, blue) * 2;
2580
+ if (value === 0) {
2581
+ return 30;
2582
+ }
2583
+ let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
2584
+ if (value === 2) {
2585
+ result += 60;
2586
+ }
2587
+ return result;
2588
+ },
2589
+ enumerable: false
2590
+ },
2591
+ rgbToAnsi: {
2592
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
2593
+ enumerable: false
2594
+ },
2595
+ hexToAnsi: {
2596
+ value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
2597
+ enumerable: false
2598
+ }
2599
+ });
2600
+ return styles;
2601
+ }
2602
+ var ansiStyles = assembleStyles();
2603
+ var ansi_styles_default = ansiStyles;
2604
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
2605
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
2606
+ const position = argv.indexOf(prefix + flag);
2607
+ const terminatorPosition = argv.indexOf("--");
2608
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
2609
+ }
2610
+ var { env } = process2;
2611
+ var flagForceColor;
2612
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
2613
+ flagForceColor = 0;
2614
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
2615
+ flagForceColor = 1;
2616
+ }
2617
+ function envForceColor() {
2618
+ if ("FORCE_COLOR" in env) {
2619
+ if (env.FORCE_COLOR === "true") {
2620
+ return 1;
2621
+ }
2622
+ if (env.FORCE_COLOR === "false") {
2623
+ return 0;
2624
+ }
2625
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
2626
+ }
2627
+ }
2628
+ function translateLevel(level) {
2629
+ if (level === 0) {
2630
+ return false;
2631
+ }
2632
+ return {
2633
+ level,
2634
+ hasBasic: true,
2635
+ has256: level >= 2,
2636
+ has16m: level >= 3
2637
+ };
2638
+ }
2639
+ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
2640
+ const noFlagForceColor = envForceColor();
2641
+ if (noFlagForceColor !== void 0) {
2642
+ flagForceColor = noFlagForceColor;
2643
+ }
2644
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
2645
+ if (forceColor === 0) {
2646
+ return 0;
2647
+ }
2648
+ if (sniffFlags) {
2649
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
2650
+ return 3;
2651
+ }
2652
+ if (hasFlag("color=256")) {
2653
+ return 2;
2654
+ }
2655
+ }
2656
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) {
2657
+ return 1;
2658
+ }
2659
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
2660
+ return 0;
2661
+ }
2662
+ const min = forceColor || 0;
2663
+ if (env.TERM === "dumb") {
2664
+ return min;
2665
+ }
2666
+ if (process2.platform === "win32") {
2667
+ const osRelease = os.release().split(".");
2668
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
2669
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
2670
+ }
2671
+ return 1;
2672
+ }
2673
+ if ("CI" in env) {
2674
+ if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
2675
+ return 3;
2676
+ }
2677
+ if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
2678
+ return 1;
2679
+ }
2680
+ return min;
2681
+ }
2682
+ if ("TEAMCITY_VERSION" in env) {
2683
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
2684
+ }
2685
+ if (env.COLORTERM === "truecolor") {
2686
+ return 3;
2687
+ }
2688
+ if (env.TERM === "xterm-kitty") {
2689
+ return 3;
2690
+ }
2691
+ if (env.TERM === "xterm-ghostty") {
2692
+ return 3;
2693
+ }
2694
+ if (env.TERM === "wezterm") {
2695
+ return 3;
2696
+ }
2697
+ if ("TERM_PROGRAM" in env) {
2698
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
2699
+ switch (env.TERM_PROGRAM) {
2700
+ case "iTerm.app": {
2701
+ return version >= 3 ? 3 : 2;
2702
+ }
2703
+ case "Apple_Terminal": {
2704
+ return 2;
2705
+ }
2706
+ }
2707
+ }
2708
+ if (/-256(color)?$/i.test(env.TERM)) {
2709
+ return 2;
2710
+ }
2711
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
2712
+ return 1;
2713
+ }
2714
+ if ("COLORTERM" in env) {
2715
+ return 1;
2716
+ }
2717
+ return min;
2718
+ }
2719
+ function createSupportsColor(stream, options = {}) {
2720
+ const level = _supportsColor(stream, {
2721
+ streamIsTTY: stream && stream.isTTY,
2722
+ ...options
2723
+ });
2724
+ return translateLevel(level);
2725
+ }
2726
+ var supportsColor = {
2727
+ stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
2728
+ stderr: createSupportsColor({ isTTY: tty.isatty(2) })
2729
+ };
2730
+ var supports_color_default = supportsColor;
2731
+
2732
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
2733
+ function stringReplaceAll(string, substring, replacer) {
2734
+ let index = string.indexOf(substring);
2735
+ if (index === -1) {
2736
+ return string;
2737
+ }
2738
+ const substringLength = substring.length;
2739
+ let endIndex = 0;
2740
+ let returnValue = "";
2741
+ do {
2742
+ returnValue += string.slice(endIndex, index) + substring + replacer;
2743
+ endIndex = index + substringLength;
2744
+ index = string.indexOf(substring, endIndex);
2745
+ } while (index !== -1);
2746
+ returnValue += string.slice(endIndex);
2747
+ return returnValue;
2748
+ }
2749
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
2750
+ let endIndex = 0;
2751
+ let returnValue = "";
2752
+ do {
2753
+ const gotCR = string[index - 1] === "\r";
2754
+ returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
2755
+ endIndex = index + 1;
2756
+ index = string.indexOf("\n", endIndex);
2757
+ } while (index !== -1);
2758
+ returnValue += string.slice(endIndex);
2759
+ return returnValue;
2760
+ }
2761
+
2762
+ // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
2763
+ var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
2764
+ var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
2765
+ var STYLER = /* @__PURE__ */ Symbol("STYLER");
2766
+ var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
2767
+ var levelMapping = [
2768
+ "ansi",
2769
+ "ansi",
2770
+ "ansi256",
2771
+ "ansi16m"
2772
+ ];
2773
+ var styles2 = /* @__PURE__ */ Object.create(null);
2774
+ var applyOptions = (object, options = {}) => {
2775
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
2776
+ throw new Error("The `level` option should be an integer from 0 to 3");
2777
+ }
2778
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
2779
+ object.level = options.level === void 0 ? colorLevel : options.level;
2780
+ };
2781
+ var chalkFactory = (options) => {
2782
+ const chalk2 = (...strings) => strings.join(" ");
2783
+ applyOptions(chalk2, options);
2784
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
2785
+ return chalk2;
2786
+ };
2787
+ function createChalk(options) {
2788
+ return chalkFactory(options);
2789
+ }
2790
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
2791
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
2792
+ styles2[styleName] = {
2793
+ get() {
2794
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
2795
+ Object.defineProperty(this, styleName, { value: builder });
2796
+ return builder;
2797
+ }
2798
+ };
2799
+ }
2800
+ styles2.visible = {
2801
+ get() {
2802
+ const builder = createBuilder(this, this[STYLER], true);
2803
+ Object.defineProperty(this, "visible", { value: builder });
2804
+ return builder;
2805
+ }
2806
+ };
2807
+ var getModelAnsi = (model, level, type, ...arguments_) => {
2808
+ if (model === "rgb") {
2809
+ if (level === "ansi16m") {
2810
+ return ansi_styles_default[type].ansi16m(...arguments_);
2811
+ }
2812
+ if (level === "ansi256") {
2813
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
2814
+ }
2815
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
2816
+ }
2817
+ if (model === "hex") {
2818
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
2819
+ }
2820
+ return ansi_styles_default[type][model](...arguments_);
2821
+ };
2822
+ var usedModels = ["rgb", "hex", "ansi256"];
2823
+ for (const model of usedModels) {
2824
+ styles2[model] = {
2825
+ get() {
2826
+ const { level } = this;
2827
+ return function(...arguments_) {
2828
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
2829
+ return createBuilder(this, styler, this[IS_EMPTY]);
2830
+ };
2831
+ }
2832
+ };
2833
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
2834
+ styles2[bgModel] = {
2835
+ get() {
2836
+ const { level } = this;
2837
+ return function(...arguments_) {
2838
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
2839
+ return createBuilder(this, styler, this[IS_EMPTY]);
2840
+ };
2841
+ }
2842
+ };
2843
+ }
2844
+ var proto = Object.defineProperties(() => {
2845
+ }, {
2846
+ ...styles2,
2847
+ level: {
2848
+ enumerable: true,
2849
+ get() {
2850
+ return this[GENERATOR].level;
2851
+ },
2852
+ set(level) {
2853
+ this[GENERATOR].level = level;
2854
+ }
2855
+ }
2856
+ });
2857
+ var createStyler = (open2, close, parent) => {
2858
+ let openAll;
2859
+ let closeAll;
2860
+ if (parent === void 0) {
2861
+ openAll = open2;
2862
+ closeAll = close;
2863
+ } else {
2864
+ openAll = parent.openAll + open2;
2865
+ closeAll = close + parent.closeAll;
2866
+ }
2867
+ return {
2868
+ open: open2,
2869
+ close,
2870
+ openAll,
2871
+ closeAll,
2872
+ parent
2873
+ };
2874
+ };
2875
+ var createBuilder = (self, _styler, _isEmpty) => {
2876
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
2877
+ Object.setPrototypeOf(builder, proto);
2878
+ builder[GENERATOR] = self;
2879
+ builder[STYLER] = _styler;
2880
+ builder[IS_EMPTY] = _isEmpty;
2881
+ return builder;
2882
+ };
2883
+ var applyStyle = (self, string) => {
2884
+ if (self.level <= 0 || !string) {
2885
+ return self[IS_EMPTY] ? "" : string;
2886
+ }
2887
+ let styler = self[STYLER];
2888
+ if (styler === void 0) {
2889
+ return string;
2890
+ }
2891
+ const { openAll, closeAll } = styler;
2892
+ if (string.includes("\x1B")) {
2893
+ while (styler !== void 0) {
2894
+ string = stringReplaceAll(string, styler.close, styler.open);
2895
+ styler = styler.parent;
2896
+ }
2897
+ }
2898
+ const lfIndex = string.indexOf("\n");
2899
+ if (lfIndex !== -1) {
2900
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
2901
+ }
2902
+ return openAll + string + closeAll;
2903
+ };
2904
+ Object.defineProperties(createChalk.prototype, styles2);
2905
+ var chalk = createChalk();
2906
+ createChalk({ level: stderrColor ? stderrColor.level : 0 });
2907
+ var source_default = chalk;
2908
+
2909
+ // packages/core/src/diff/renderer.ts
2173
2910
  function formatPath(path7) {
2174
2911
  if (path7 === void 0 || path7.path.length === 0) {
2175
2912
  return "(run)";
@@ -2250,6 +2987,8 @@ function diffTraceEvents(leftEvents, rightEvents, options) {
2250
2987
  const right = manualTraceEventsToComparableRun(rightEvents);
2251
2988
  return diffRuns(left, right, options);
2252
2989
  }
2990
+
2991
+ // packages/core/src/terminal.ts
2253
2992
  var TERMINAL_INDENT = " ";
2254
2993
  var MAX_TERMINAL_NAME_LENGTH = 80;
2255
2994
  var MAX_TERMINAL_DEPTH = 10;
@@ -2275,24 +3014,24 @@ function formatTerminalName(name) {
2275
3014
  return truncateName(name, MAX_TERMINAL_NAME_LENGTH);
2276
3015
  }
2277
3016
  function getStatusIcon(status) {
2278
- if (status === "success") return chalk2.green("\u2714");
2279
- if (status === "error") return chalk2.red("\u2716");
2280
- return chalk2.yellow("\u23F3");
3017
+ if (status === "success") return source_default.green("\u2714");
3018
+ if (status === "error") return source_default.red("\u2716");
3019
+ return source_default.yellow("\u23F3");
2281
3020
  }
2282
3021
  function renderStepLine(name, durationMs, status, depth) {
2283
3022
  try {
2284
3023
  const nm = formatTerminalName(name);
2285
3024
  const ind = getIndent(depth ?? 0);
2286
3025
  if (status === "running" && durationMs === void 0) {
2287
- return `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3026
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2288
3027
  }
2289
3028
  const hasDur = durationMs !== void 0 && Number.isFinite(durationMs);
2290
3029
  const dur = hasDur ? formatDuration2(durationMs) : void 0;
2291
3030
  if (status === "running") {
2292
- return dur !== void 0 ? `${ind}${chalk2.yellow("\u23F3")} ${nm} (${dur})` : `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3031
+ return dur !== void 0 ? `${ind}${source_default.yellow("\u23F3")} ${nm} (${dur})` : `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2293
3032
  }
2294
3033
  if (!hasDur || dur === void 0) {
2295
- return `${ind}${chalk2.yellow("\u23F3")} ${nm}`;
3034
+ return `${ind}${source_default.yellow("\u23F3")} ${nm}`;
2296
3035
  }
2297
3036
  if (status === "success") {
2298
3037
  return `${ind}${getStatusIcon("success")} ${nm} (${dur})`;
@@ -2369,6 +3108,7 @@ async function stepImpl(name, fn, options) {
2369
3108
  const parentId = getParentStepId();
2370
3109
  const stepType = options?.type ?? "logic";
2371
3110
  const metadata = options?.metadata;
3111
+ const traceSafety = getTraceSafetyFromContext();
2372
3112
  const startTime = Date.now();
2373
3113
  await safeInstrumentation("writeTraceEvent(step_started)", async () => {
2374
3114
  const started = {
@@ -2383,7 +3123,8 @@ async function stepImpl(name, fn, options) {
2383
3123
  startTime,
2384
3124
  ...metadata !== void 0 ? { metadata } : {}
2385
3125
  };
2386
- await writeTraceEvent(started, context.traceDir);
3126
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(started, traceSafety) : started;
3127
+ await writeTraceEvent(safe, context.traceDir);
2387
3128
  });
2388
3129
  await safeInstrumentation("printStepStart", () => {
2389
3130
  printStepStart(stepName, renderDepth);
@@ -2409,7 +3150,8 @@ async function stepImpl(name, fn, options) {
2409
3150
  durationMs: durationMs2,
2410
3151
  error: formatted
2411
3152
  };
2412
- await writeTraceEvent(completed, context.traceDir);
3153
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(completed, traceSafety) : completed;
3154
+ await writeTraceEvent(safe, context.traceDir);
2413
3155
  });
2414
3156
  await safeInstrumentation("printStepComplete(error)", () => {
2415
3157
  printStepComplete(stepName, durationMs2, "error", renderDepth);
@@ -2435,7 +3177,8 @@ async function stepImpl(name, fn, options) {
2435
3177
  endTime,
2436
3178
  durationMs
2437
3179
  };
2438
- await writeTraceEvent(completed, context.traceDir);
3180
+ const safe = traceSafety !== void 0 ? prepareTraceEventForDisk(completed, traceSafety) : completed;
3181
+ await writeTraceEvent(safe, context.traceDir);
2439
3182
  });
2440
3183
  await safeInstrumentation("printStepComplete(success)", () => {
2441
3184
  printStepComplete(stepName, durationMs, "success", renderDepth);