agent-inspect 6.31.22 → 6.31.23

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 (46) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/packages/cli/dist/{chunk-EMWA5EKU.mjs → chunk-P27XTK5U.mjs} +62 -20
  5. package/packages/cli/dist/chunk-P27XTK5U.mjs.map +1 -0
  6. package/packages/cli/dist/index.cjs +97 -49
  7. package/packages/cli/dist/index.cjs.map +1 -1
  8. package/packages/cli/dist/index.mjs +38 -34
  9. package/packages/cli/dist/index.mjs.map +1 -1
  10. package/packages/cli/dist/{src-VZHGOLTO.mjs → src-EWZYLDST.mjs} +3 -3
  11. package/packages/cli/dist/{src-VZHGOLTO.mjs.map → src-EWZYLDST.mjs.map} +1 -1
  12. package/packages/core/dist/advanced.cjs +38 -10
  13. package/packages/core/dist/advanced.cjs.map +1 -1
  14. package/packages/core/dist/advanced.mjs +6 -6
  15. package/packages/core/dist/checks.cjs +36 -11
  16. package/packages/core/dist/checks.cjs.map +1 -1
  17. package/packages/core/dist/checks.mjs +2 -2
  18. package/packages/core/dist/{chunk-RBXD7BNX.mjs → chunk-77PUPLPG.mjs} +14 -8
  19. package/packages/core/dist/chunk-77PUPLPG.mjs.map +1 -0
  20. package/packages/core/dist/{chunk-GCZUWY47.mjs → chunk-AN5MOADW.mjs} +31 -9
  21. package/packages/core/dist/chunk-AN5MOADW.mjs.map +1 -0
  22. package/packages/core/dist/{chunk-ZOF6ON65.mjs → chunk-IMCM42W6.mjs} +15 -9
  23. package/packages/core/dist/chunk-IMCM42W6.mjs.map +1 -0
  24. package/packages/core/dist/{chunk-S4NU55LU.mjs → chunk-J2ST4VCX.mjs} +3 -3
  25. package/packages/core/dist/{chunk-S4NU55LU.mjs.map → chunk-J2ST4VCX.mjs.map} +1 -1
  26. package/packages/core/dist/{chunk-UPGBMRL4.mjs → chunk-JJSL346L.mjs} +12 -3
  27. package/packages/core/dist/chunk-JJSL346L.mjs.map +1 -0
  28. package/packages/core/dist/exporters.cjs +38 -31
  29. package/packages/core/dist/exporters.cjs.map +1 -1
  30. package/packages/core/dist/exporters.mjs +35 -31
  31. package/packages/core/dist/exporters.mjs.map +1 -1
  32. package/packages/core/dist/logs.cjs +14 -5
  33. package/packages/core/dist/logs.cjs.map +1 -1
  34. package/packages/core/dist/logs.mjs +3 -3
  35. package/packages/core/dist/persisted.cjs +185 -163
  36. package/packages/core/dist/persisted.cjs.map +1 -1
  37. package/packages/core/dist/persisted.mjs +9 -6
  38. package/packages/core/dist/persisted.mjs.map +1 -1
  39. package/packages/core/dist/readers.cjs +189 -161
  40. package/packages/core/dist/readers.cjs.map +1 -1
  41. package/packages/core/dist/readers.mjs +4 -4
  42. package/packages/cli/dist/chunk-EMWA5EKU.mjs.map +0 -1
  43. package/packages/core/dist/chunk-GCZUWY47.mjs.map +0 -1
  44. package/packages/core/dist/chunk-RBXD7BNX.mjs.map +0 -1
  45. package/packages/core/dist/chunk-UPGBMRL4.mjs.map +0 -1
  46. package/packages/core/dist/chunk-ZOF6ON65.mjs.map +0 -1
@@ -168,6 +168,176 @@ function extractCorrelationMetadata(record) {
168
168
  return found ? out : void 0;
169
169
  }
170
170
 
171
+ // packages/core/src/checks/canonical-equality.ts
172
+ var DEFAULT_MAX_DEPTH = 8;
173
+ var DEFAULT_MAX_BYTES = 16384;
174
+ function sortKeysDeep(input, depth, maxDepth) {
175
+ if (depth > maxDepth) {
176
+ throw new Error("AI_CHECK_CANONICAL_DEPTH_EXCEEDED");
177
+ }
178
+ if (input === null || typeof input !== "object") return input;
179
+ if (Array.isArray(input)) {
180
+ return input.map((item) => sortKeysDeep(item, depth + 1, maxDepth));
181
+ }
182
+ const record = input;
183
+ const out = {};
184
+ for (const key of Object.keys(record).sort()) {
185
+ out[key] = sortKeysDeep(record[key], depth + 1, maxDepth);
186
+ }
187
+ return out;
188
+ }
189
+ function encodeCanonicalStructured(value, limits) {
190
+ const maxDepth = DEFAULT_MAX_DEPTH;
191
+ const maxBytes = DEFAULT_MAX_BYTES;
192
+ try {
193
+ const sorted = sortKeysDeep(value, 0, maxDepth);
194
+ const encoded = JSON.stringify(sorted);
195
+ if (encoded === void 0) {
196
+ return {
197
+ ok: false,
198
+ reason: "Value is not JSON-serializable for canonical comparison.",
199
+ code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
200
+ };
201
+ }
202
+ if (Buffer.byteLength(encoded, "utf8") > maxBytes) {
203
+ return {
204
+ ok: false,
205
+ reason: "Canonical structured value exceeds bounded size limit.",
206
+ code: "AI_CHECK_CANONICAL_SIZE_EXCEEDED"
207
+ };
208
+ }
209
+ return { ok: true, value: encoded };
210
+ } catch (error) {
211
+ const message = error instanceof Error ? error.message : String(error);
212
+ if (message === "AI_CHECK_CANONICAL_DEPTH_EXCEEDED") {
213
+ return {
214
+ ok: false,
215
+ reason: "Canonical structured value exceeds bounded depth limit.",
216
+ code: "AI_CHECK_CANONICAL_DEPTH_EXCEEDED"
217
+ };
218
+ }
219
+ return {
220
+ ok: false,
221
+ reason: "Canonical structured encoding failed.",
222
+ code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
223
+ };
224
+ }
225
+ }
226
+
227
+ // packages/core/src/persisted/delivery-identity.ts
228
+ var DELIVERY_CONFLICT_ATTR = "agent_inspect.delivery_conflict";
229
+ var DELIVERY_EVENT_BASE_ATTR = "agent_inspect.delivery_event_base";
230
+ var MAX_DELIVERY_BASE_LEN = 500;
231
+ function stripReaderDeliveryDiscriminator(eventId, attributes) {
232
+ if (!eventId) return eventId;
233
+ const rawBase = attributes?.[DELIVERY_EVENT_BASE_ATTR];
234
+ if (typeof rawBase !== "string" || rawBase.trim() === "") return eventId;
235
+ const base = rawBase.trim().slice(0, MAX_DELIVERY_BASE_LEN);
236
+ if (eventId === base) return base;
237
+ const prefix = `${base}:`;
238
+ if (!eventId.startsWith(prefix)) return eventId;
239
+ const suffix = eventId.slice(prefix.length);
240
+ if (/^\d+$/.test(suffix)) return base;
241
+ return eventId;
242
+ }
243
+ function deliveryEventBaseFromIndexedId(eventId) {
244
+ if (!/:\d+$/.test(eventId)) return void 0;
245
+ const base = eventId.replace(/:\d+$/, "");
246
+ return base.length > 0 ? base.slice(0, MAX_DELIVERY_BASE_LEN) : void 0;
247
+ }
248
+ function canonicalDigest(value) {
249
+ if (value === void 0) return null;
250
+ const encoded = encodeCanonicalStructured(value);
251
+ return encoded.ok ? encoded.value : `unencodable:${encoded.code}`;
252
+ }
253
+ function capturedContentDigest(attributes) {
254
+ if (!attributes || typeof attributes !== "object") {
255
+ return { args: null, result: null };
256
+ }
257
+ const nested = attributes.metadata && typeof attributes.metadata === "object" ? attributes.metadata : void 0;
258
+ const args = attributes.arguments ?? attributes.args ?? attributes.input ?? nested?.arguments ?? nested?.args ?? nested?.input;
259
+ const result = attributes.result ?? attributes.output ?? attributes.response ?? nested?.result ?? nested?.output ?? nested?.response;
260
+ return {
261
+ args: args === void 0 ? null : canonicalDigest(args),
262
+ result: result === void 0 ? null : canonicalDigest(result)
263
+ };
264
+ }
265
+ function timeKey(fields) {
266
+ if (typeof fields.startedAt === "string" && fields.startedAt.trim() !== "") {
267
+ return fields.startedAt;
268
+ }
269
+ if (typeof fields.timestamp === "string" && fields.timestamp.trim() !== "") {
270
+ return fields.timestamp;
271
+ }
272
+ if (typeof fields.timestamp === "number" && Number.isFinite(fields.timestamp)) {
273
+ return String(fields.timestamp);
274
+ }
275
+ return null;
276
+ }
277
+ function deliverySemanticFingerprint(fields) {
278
+ const content = capturedContentDigest(fields.attributes);
279
+ return JSON.stringify({
280
+ stableEventId: stripReaderDeliveryDiscriminator(fields.eventId, fields.attributes),
281
+ runId: fields.runId,
282
+ kind: fields.kind,
283
+ name: fields.name,
284
+ status: fields.status ?? null,
285
+ parentId: fields.parentId ?? null,
286
+ sourceType: fields.sourceType ?? null,
287
+ time: timeKey(fields),
288
+ operationId: fields.operationId ?? null,
289
+ attemptId: fields.attemptId ?? null,
290
+ attemptNumber: fields.attemptNumber ?? null,
291
+ retryOf: fields.retryOf ?? null,
292
+ argsDigest: content.args,
293
+ resultDigest: content.result
294
+ });
295
+ }
296
+ function identityFieldsFromAttributes(attributes) {
297
+ if (!attributes || typeof attributes !== "object") {
298
+ return {
299
+ operationId: null,
300
+ attemptId: null,
301
+ attemptNumber: null,
302
+ retryOf: null
303
+ };
304
+ }
305
+ const nested = attributes.metadata && typeof attributes.metadata === "object" && !Array.isArray(attributes.metadata) ? attributes.metadata : void 0;
306
+ const pickString = (key) => {
307
+ const direct = attributes[key];
308
+ if (typeof direct === "string" && direct.trim() !== "") return direct.trim();
309
+ const nestedValue = nested?.[key];
310
+ if (typeof nestedValue === "string" && nestedValue.trim() !== "") {
311
+ return nestedValue.trim();
312
+ }
313
+ return null;
314
+ };
315
+ const pickNumber = () => {
316
+ const direct = attributes.attemptNumber ?? attributes.attempt;
317
+ if (typeof direct === "number" && Number.isFinite(direct)) return direct;
318
+ const nestedValue = nested?.attemptNumber ?? nested?.attempt;
319
+ if (typeof nestedValue === "number" && Number.isFinite(nestedValue)) {
320
+ return nestedValue;
321
+ }
322
+ return null;
323
+ };
324
+ return {
325
+ operationId: pickString("operationId"),
326
+ attemptId: pickString("attemptId"),
327
+ retryOf: pickString("retryOf"),
328
+ attemptNumber: pickNumber()
329
+ };
330
+ }
331
+ function stampDeliveryConflict(event) {
332
+ return {
333
+ ...event,
334
+ attributes: {
335
+ ...event.attributes ?? {},
336
+ [DELIVERY_CONFLICT_ATTR]: true
337
+ }
338
+ };
339
+ }
340
+
171
341
  // packages/core/src/persisted/token-usage.ts
172
342
  function isRecord2(value) {
173
343
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -283,6 +453,11 @@ function compactAttributes(entries) {
283
453
  }
284
454
  return Object.keys(out).length > 0 ? out : void 0;
285
455
  }
456
+ function stampDeliveryEventBase(eventId, attributes) {
457
+ const base = deliveryEventBaseFromIndexedId(eventId);
458
+ if (!base) return attributes;
459
+ return { ...attributes ?? {}, [DELIVERY_EVENT_BASE_ATTR]: base };
460
+ }
286
461
  function traceEventToPersistedInspectEvent(event, options) {
287
462
  const eventIndex = options?.eventIndex ?? 0;
288
463
  const eventId = createPersistedEventId(event, eventIndex);
@@ -312,7 +487,7 @@ function traceEventToPersistedInspectEvent(event, options) {
312
487
  startedAt: tsStart.iso,
313
488
  confidence: "explicit",
314
489
  source,
315
- attributes
490
+ attributes: stampDeliveryEventBase(eventId, attributes)
316
491
  };
317
492
  }
318
493
  case "run_completed": {
@@ -335,7 +510,7 @@ function traceEventToPersistedInspectEvent(event, options) {
335
510
  durationMs: event.durationMs,
336
511
  confidence: "explicit",
337
512
  source,
338
- attributes,
513
+ attributes: stampDeliveryEventBase(eventId, attributes),
339
514
  error
340
515
  };
341
516
  }
@@ -360,7 +535,7 @@ function traceEventToPersistedInspectEvent(event, options) {
360
535
  startedAt: tsStart.iso,
361
536
  confidence: "explicit",
362
537
  source,
363
- attributes
538
+ attributes: stampDeliveryEventBase(eventId, attributes)
364
539
  };
365
540
  if (event.parentId !== void 0) {
366
541
  out.parentId = event.parentId;
@@ -391,7 +566,7 @@ function traceEventToPersistedInspectEvent(event, options) {
391
566
  durationMs: event.durationMs,
392
567
  confidence: "explicit",
393
568
  source,
394
- attributes,
569
+ attributes: stampDeliveryEventBase(eventId, attributes),
395
570
  error
396
571
  };
397
572
  }
@@ -418,7 +593,7 @@ function traceEventToPersistedInspectEvent(event, options) {
418
593
  timestamp: tsMain.iso,
419
594
  confidence: "explicit",
420
595
  source,
421
- attributes
596
+ attributes: stampDeliveryEventBase(eventId, attributes)
422
597
  };
423
598
  if (event.parentId !== void 0) {
424
599
  out.parentId = event.parentId;
@@ -527,19 +702,22 @@ function mapErrorFromAttributes(event) {
527
702
  }
528
703
  function inspectEventToPersistedInspectEvent(event, options) {
529
704
  const eventIndex = options?.eventIndex ?? 0;
530
- const eventId = typeof event.eventId === "string" && event.eventId.length > 0 ? event.eventId : createFallbackEventId(event, eventIndex);
705
+ const mintedFallback = !(typeof event.eventId === "string" && event.eventId.length > 0);
706
+ const eventId = mintedFallback ? createFallbackEventId(event, eventIndex) : event.eventId;
531
707
  const ts = toIsoTimestamp2(event.timestamp);
532
708
  const { persistedSource, originalSourceType } = mapInspectSourceToPersisted(
533
709
  event.source,
534
710
  options
535
711
  );
536
712
  const attrsBase = event.attributes !== void 0 ? { ...event.attributes } : {};
713
+ const deliveryBase = mintedFallback ? deliveryEventBaseFromIndexedId(eventId) : void 0;
537
714
  const attributes = compactAttributes2({
538
715
  ...attrsBase,
539
716
  sourceFile: event.source.file,
540
717
  sourceLine: event.source.line,
541
718
  originalSourceType,
542
- invalidTimestamp: ts.invalidTimestamp ? true : void 0
719
+ invalidTimestamp: ts.invalidTimestamp ? true : void 0,
720
+ ...deliveryBase !== void 0 ? { [DELIVERY_EVENT_BASE_ATTR]: deliveryBase } : {}
543
721
  });
544
722
  const tokenUsage = mapTokenUsageFromAttributes(event.attributes);
545
723
  const error = mapErrorFromAttributes(event);
@@ -1390,162 +1568,6 @@ function projectLogicalEvents(events) {
1390
1568
  };
1391
1569
  }
1392
1570
 
1393
- // packages/core/src/checks/canonical-equality.ts
1394
- var DEFAULT_MAX_DEPTH = 8;
1395
- var DEFAULT_MAX_BYTES = 16384;
1396
- function sortKeysDeep(input, depth, maxDepth) {
1397
- if (depth > maxDepth) {
1398
- throw new Error("AI_CHECK_CANONICAL_DEPTH_EXCEEDED");
1399
- }
1400
- if (input === null || typeof input !== "object") return input;
1401
- if (Array.isArray(input)) {
1402
- return input.map((item) => sortKeysDeep(item, depth + 1, maxDepth));
1403
- }
1404
- const record = input;
1405
- const out = {};
1406
- for (const key of Object.keys(record).sort()) {
1407
- out[key] = sortKeysDeep(record[key], depth + 1, maxDepth);
1408
- }
1409
- return out;
1410
- }
1411
- function encodeCanonicalStructured(value, limits) {
1412
- const maxDepth = DEFAULT_MAX_DEPTH;
1413
- const maxBytes = DEFAULT_MAX_BYTES;
1414
- try {
1415
- const sorted = sortKeysDeep(value, 0, maxDepth);
1416
- const encoded = JSON.stringify(sorted);
1417
- if (encoded === void 0) {
1418
- return {
1419
- ok: false,
1420
- reason: "Value is not JSON-serializable for canonical comparison.",
1421
- code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
1422
- };
1423
- }
1424
- if (Buffer.byteLength(encoded, "utf8") > maxBytes) {
1425
- return {
1426
- ok: false,
1427
- reason: "Canonical structured value exceeds bounded size limit.",
1428
- code: "AI_CHECK_CANONICAL_SIZE_EXCEEDED"
1429
- };
1430
- }
1431
- return { ok: true, value: encoded };
1432
- } catch (error) {
1433
- const message = error instanceof Error ? error.message : String(error);
1434
- if (message === "AI_CHECK_CANONICAL_DEPTH_EXCEEDED") {
1435
- return {
1436
- ok: false,
1437
- reason: "Canonical structured value exceeds bounded depth limit.",
1438
- code: "AI_CHECK_CANONICAL_DEPTH_EXCEEDED"
1439
- };
1440
- }
1441
- return {
1442
- ok: false,
1443
- reason: "Canonical structured encoding failed.",
1444
- code: "AI_CHECK_CANONICAL_UNSERIALIZABLE"
1445
- };
1446
- }
1447
- }
1448
-
1449
- // packages/core/src/persisted/delivery-identity.ts
1450
- var DELIVERY_CONFLICT_ATTR = "agent_inspect.delivery_conflict";
1451
- var SYNTHETIC_DELIVERY_ID = /^(?:manual|inspect):[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:[A-Za-z0-9_-]+:\d+$/;
1452
- function stripReaderDeliveryDiscriminator(eventId) {
1453
- if (!SYNTHETIC_DELIVERY_ID.test(eventId)) return eventId;
1454
- return eventId.replace(/:\d+$/, "");
1455
- }
1456
- function canonicalDigest(value) {
1457
- if (value === void 0) return null;
1458
- const encoded = encodeCanonicalStructured(value);
1459
- return encoded.ok ? encoded.value : `unencodable:${encoded.code}`;
1460
- }
1461
- function capturedContentDigest(attributes) {
1462
- if (!attributes || typeof attributes !== "object") {
1463
- return { args: null, result: null };
1464
- }
1465
- const nested = attributes.metadata && typeof attributes.metadata === "object" ? attributes.metadata : void 0;
1466
- const args = attributes.arguments ?? attributes.args ?? attributes.input ?? nested?.arguments ?? nested?.args ?? nested?.input;
1467
- const result = attributes.result ?? attributes.output ?? attributes.response ?? nested?.result ?? nested?.output ?? nested?.response;
1468
- return {
1469
- args: args === void 0 ? null : canonicalDigest(args),
1470
- result: result === void 0 ? null : canonicalDigest(result)
1471
- };
1472
- }
1473
- function timeKey(fields) {
1474
- if (typeof fields.startedAt === "string" && fields.startedAt.trim() !== "") {
1475
- return fields.startedAt;
1476
- }
1477
- if (typeof fields.timestamp === "string" && fields.timestamp.trim() !== "") {
1478
- return fields.timestamp;
1479
- }
1480
- if (typeof fields.timestamp === "number" && Number.isFinite(fields.timestamp)) {
1481
- return String(fields.timestamp);
1482
- }
1483
- return null;
1484
- }
1485
- function deliverySemanticFingerprint(fields) {
1486
- const content = capturedContentDigest(fields.attributes);
1487
- return JSON.stringify({
1488
- stableEventId: stripReaderDeliveryDiscriminator(fields.eventId),
1489
- runId: fields.runId,
1490
- kind: fields.kind,
1491
- name: fields.name,
1492
- status: fields.status ?? null,
1493
- parentId: fields.parentId ?? null,
1494
- sourceType: fields.sourceType ?? null,
1495
- time: timeKey(fields),
1496
- operationId: fields.operationId ?? null,
1497
- attemptId: fields.attemptId ?? null,
1498
- attemptNumber: fields.attemptNumber ?? null,
1499
- retryOf: fields.retryOf ?? null,
1500
- argsDigest: content.args,
1501
- resultDigest: content.result
1502
- });
1503
- }
1504
- function identityFieldsFromAttributes(attributes) {
1505
- if (!attributes || typeof attributes !== "object") {
1506
- return {
1507
- operationId: null,
1508
- attemptId: null,
1509
- attemptNumber: null,
1510
- retryOf: null
1511
- };
1512
- }
1513
- const nested = attributes.metadata && typeof attributes.metadata === "object" && !Array.isArray(attributes.metadata) ? attributes.metadata : void 0;
1514
- const pickString = (key) => {
1515
- const direct = attributes[key];
1516
- if (typeof direct === "string" && direct.trim() !== "") return direct.trim();
1517
- const nestedValue = nested?.[key];
1518
- if (typeof nestedValue === "string" && nestedValue.trim() !== "") {
1519
- return nestedValue.trim();
1520
- }
1521
- return null;
1522
- };
1523
- const pickNumber = () => {
1524
- const direct = attributes.attemptNumber ?? attributes.attempt;
1525
- if (typeof direct === "number" && Number.isFinite(direct)) return direct;
1526
- const nestedValue = nested?.attemptNumber ?? nested?.attempt;
1527
- if (typeof nestedValue === "number" && Number.isFinite(nestedValue)) {
1528
- return nestedValue;
1529
- }
1530
- return null;
1531
- };
1532
- return {
1533
- operationId: pickString("operationId"),
1534
- attemptId: pickString("attemptId"),
1535
- retryOf: pickString("retryOf"),
1536
- attemptNumber: pickNumber()
1537
- };
1538
- }
1539
- function stampDeliveryConflict(event) {
1540
- return {
1541
- ...event,
1542
- attributes: {
1543
- ...event.attributes ?? {},
1544
- [DELIVERY_CONFLICT_ATTR]: true
1545
- }
1546
- };
1547
- }
1548
-
1549
1571
  // packages/core/src/logs/tree-builder.ts
1550
1572
  function inc(map, key) {
1551
1573
  map[key] = (map[key] ?? 0) + 1;