agent-inspect 6.14.2 → 6.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -6
  2. package/README.md +2 -2
  3. package/docs/API.md +19 -3
  4. package/package.json +2 -2
  5. package/packages/cli/dist/{chunk-AACUXCHT.mjs → chunk-LFSBMUCD.mjs} +115 -10
  6. package/packages/cli/dist/chunk-LFSBMUCD.mjs.map +1 -0
  7. package/packages/cli/dist/index.cjs +126 -10
  8. package/packages/cli/dist/index.cjs.map +1 -1
  9. package/packages/cli/dist/index.mjs +4 -4
  10. package/packages/cli/dist/index.mjs.map +1 -1
  11. package/packages/cli/dist/{src-ABTS4GO4.mjs → src-5J2HPOJ3.mjs} +3 -3
  12. package/packages/cli/dist/{src-ABTS4GO4.mjs.map → src-5J2HPOJ3.mjs.map} +1 -1
  13. package/packages/core/dist/advanced.cjs +114 -7
  14. package/packages/core/dist/advanced.cjs.map +1 -1
  15. package/packages/core/dist/advanced.d.cts +2 -2
  16. package/packages/core/dist/advanced.d.ts +2 -2
  17. package/packages/core/dist/advanced.mjs +3 -2
  18. package/packages/core/dist/advanced.mjs.map +1 -1
  19. package/packages/core/dist/checks.cjs +115 -6
  20. package/packages/core/dist/checks.cjs.map +1 -1
  21. package/packages/core/dist/checks.d.cts +16 -6
  22. package/packages/core/dist/checks.d.ts +16 -6
  23. package/packages/core/dist/checks.mjs +2 -1
  24. package/packages/core/dist/chunk-FWK3Q3OJ.mjs +56 -0
  25. package/packages/core/dist/chunk-FWK3Q3OJ.mjs.map +1 -0
  26. package/packages/core/dist/{chunk-5N2OBM7S.mjs → chunk-HT54OLPE.mjs} +53 -6
  27. package/packages/core/dist/chunk-HT54OLPE.mjs.map +1 -0
  28. package/packages/core/dist/{chunk-BHMXLDLK.mjs → chunk-NF4ZHNTC.mjs} +63 -9
  29. package/packages/core/dist/chunk-NF4ZHNTC.mjs.map +1 -0
  30. package/packages/core/dist/index-B259NKkH.d.cts +102 -0
  31. package/packages/core/dist/index-B9ZGvUVL.d.ts +102 -0
  32. package/packages/core/dist/{index-D9HBequ_.d.ts → index-BsCcOKxy.d.ts} +1 -1
  33. package/packages/core/dist/{index-BY6XZ5aG.d.cts → index-Xk9X-yjY.d.cts} +1 -1
  34. package/packages/core/dist/readers.cjs +108 -3
  35. package/packages/core/dist/readers.cjs.map +1 -1
  36. package/packages/core/dist/readers.d.cts +27 -78
  37. package/packages/core/dist/readers.d.ts +27 -78
  38. package/packages/core/dist/readers.mjs +2 -1
  39. package/packages/cli/dist/chunk-AACUXCHT.mjs.map +0 -1
  40. package/packages/core/dist/chunk-5N2OBM7S.mjs.map +0 -1
  41. package/packages/core/dist/chunk-BHMXLDLK.mjs.map +0 -1
@@ -0,0 +1,102 @@
1
+ import { a as InspectRunTree } from './inspect-event-DRthdZlf.js';
2
+ import { P as PersistedInspectEvent } from './persisted-inspect-event-BVucFVrP.js';
3
+
4
+ type TraceInput = {
5
+ type: "file";
6
+ path: string;
7
+ } | {
8
+ type: "directory";
9
+ path: string;
10
+ } | {
11
+ type: "string";
12
+ content: string;
13
+ } | {
14
+ type: "buffer";
15
+ content: Buffer;
16
+ } | {
17
+ type: "stdin";
18
+ };
19
+ type TraceReadWarningSeverity = "info" | "warning" | "error";
20
+ interface TraceReadWarning {
21
+ code: string;
22
+ message: string;
23
+ severity?: TraceReadWarningSeverity;
24
+ sourceFile?: string;
25
+ line?: number;
26
+ field?: string;
27
+ }
28
+ interface TraceReadResult {
29
+ format: string;
30
+ events: PersistedInspectEvent[];
31
+ runs: InspectRunTree[];
32
+ warnings: TraceReadWarning[];
33
+ unsupportedFields: string[];
34
+ sourceFiles: string[];
35
+ }
36
+ interface TraceFormatCandidate {
37
+ format: string;
38
+ confidence: number;
39
+ readerName?: string;
40
+ description?: string;
41
+ warnings?: TraceReadWarning[];
42
+ }
43
+ type TraceFormatDetectionStatus = "detected" | "ambiguous" | "unsupported";
44
+ interface TraceFormatDetectionResult {
45
+ status: TraceFormatDetectionStatus;
46
+ format?: string;
47
+ candidates: TraceFormatCandidate[];
48
+ warnings: TraceReadWarning[];
49
+ }
50
+ interface TraceReaderDetectOptions {
51
+ format?: string;
52
+ }
53
+ interface TraceReaderReadOptions {
54
+ format?: string;
55
+ }
56
+ interface TraceReader {
57
+ readonly format: string;
58
+ readonly name?: string;
59
+ detect(input: TraceInput, options?: TraceReaderDetectOptions): TraceFormatCandidate | undefined | Promise<TraceFormatCandidate | undefined>;
60
+ read(input: TraceInput, options?: TraceReaderReadOptions): TraceReadResult | Promise<TraceReadResult>;
61
+ }
62
+ interface TraceReadOptions {
63
+ format?: string;
64
+ readers?: readonly TraceReader[];
65
+ }
66
+ type TraceReadErrorCode = "unsupported_format" | "ambiguous_format" | "reader_failed" | "invalid_input";
67
+ declare class TraceReadError extends Error {
68
+ readonly code: TraceReadErrorCode;
69
+ readonly warnings: TraceReadWarning[];
70
+ constructor(code: TraceReadErrorCode, message: string, warnings?: TraceReadWarning[]);
71
+ }
72
+ /**
73
+ * Runtime guard for structured TraceInput. Never throws WeakMap key errors for bare strings.
74
+ */
75
+ declare function assertTraceInput(input: unknown): asserts input is TraceInput;
76
+ declare const openInferenceJsonReader: TraceReader;
77
+ declare const otlpJsonReader: TraceReader;
78
+ declare const agentInspectJsonlReader: TraceReader;
79
+ declare const DEFAULT_TRACE_READERS: readonly TraceReader[];
80
+ declare function detectTraceFormat(input: TraceInput, options?: TraceReadOptions): Promise<TraceFormatDetectionResult>;
81
+ declare function readTrace(input: TraceInput, options?: TraceReadOptions): Promise<TraceReadResult>;
82
+ declare function openTrace(input: TraceInput, options?: TraceReadOptions): Promise<TraceReadResult>;
83
+ /**
84
+ * Open a single local trace file. Prefer this over passing a bare path string to `openTrace`.
85
+ *
86
+ * @experimental Additive convenience over `openTrace({ type: "file", path })`.
87
+ */
88
+ declare function openTraceFile(filePath: string, options?: TraceReadOptions): Promise<TraceReadResult>;
89
+ /**
90
+ * Open all `*.jsonl` files in a local directory (sorted, concatenated).
91
+ *
92
+ * @experimental Additive convenience over `openTrace({ type: "directory", path })`.
93
+ */
94
+ declare function openTraceDirectory(dirPath: string, options?: TraceReadOptions): Promise<TraceReadResult>;
95
+ /**
96
+ * Open an in-memory JSONL / supported text payload.
97
+ *
98
+ * @experimental Additive convenience over `openTrace({ type: "string", content })`.
99
+ */
100
+ declare function openTraceText(content: string, options?: TraceReadOptions): Promise<TraceReadResult>;
101
+
102
+ export { DEFAULT_TRACE_READERS as D, type TraceReadResult as T, type TraceReadWarning as a, type TraceFormatCandidate as b, type TraceFormatDetectionResult as c, type TraceFormatDetectionStatus as d, type TraceInput as e, TraceReadError as f, type TraceReadErrorCode as g, type TraceReadOptions as h, type TraceReadWarningSeverity as i, type TraceReader as j, type TraceReaderDetectOptions as k, type TraceReaderReadOptions as l, agentInspectJsonlReader as m, assertTraceInput as n, detectTraceFormat as o, openInferenceJsonReader as p, openTrace as q, openTraceDirectory as r, openTraceFile as s, openTraceText as t, otlpJsonReader as u, readTrace as v };
@@ -1,4 +1,4 @@
1
- import { TraceReadResult, TraceReadWarning } from './readers.js';
1
+ import { T as TraceReadResult, a as TraceReadWarning } from './index-B9ZGvUVL.js';
2
2
  import { a as InspectRunTree, b as InspectNode, A as AttributionConfidence } from './inspect-event-DRthdZlf.js';
3
3
  import { P as PersistedInspectEvent } from './persisted-inspect-event-BVucFVrP.js';
4
4
  import { O as ObservedOutcomeStatus } from './types-B562HgN_.js';
@@ -1,4 +1,4 @@
1
- import { TraceReadResult, TraceReadWarning } from './readers.cjs';
1
+ import { T as TraceReadResult, a as TraceReadWarning } from './index-B259NKkH.cjs';
2
2
  import { a as InspectRunTree, b as InspectNode, A as AttributionConfidence } from './inspect-event-DRthdZlf.cjs';
3
3
  import { P as PersistedInspectEvent } from './persisted-inspect-event-CVZWZldL.cjs';
4
4
  import { O as ObservedOutcomeStatus } from './types-B562HgN_.cjs';
@@ -1181,6 +1181,59 @@ function persistedInspectEventsToRunTrees(events, options) {
1181
1181
  return new TreeBuilder().build(inspectEvents);
1182
1182
  }
1183
1183
 
1184
+ // packages/core/src/diagnostics/programmatic.ts
1185
+ var PROGRAMMATIC_DIAGNOSTIC_SPECS = Object.freeze({
1186
+ AI_TRACE_INPUT_INVALID: {
1187
+ code: "AI_TRACE_INPUT_INVALID",
1188
+ summary: 'Expected { type: "file", path }, { type: "directory", path }, { type: "string", content }, { type: "buffer", content }, or { type: "stdin" }.',
1189
+ remediation: "For a file path, use openTraceFile(path).",
1190
+ relatedCodes: ["invalid_input"]
1191
+ },
1192
+ AI_TRACE_FORMAT_UNSUPPORTED: {
1193
+ code: "AI_TRACE_FORMAT_UNSUPPORTED",
1194
+ summary: "No trace reader could detect the input format.",
1195
+ remediation: "Pass an AgentInspect JSONL file via openTraceFile, or set options.format to a registered reader.",
1196
+ relatedCodes: ["unsupported_format"]
1197
+ },
1198
+ AI_TRACE_FORMAT_AMBIGUOUS: {
1199
+ code: "AI_TRACE_FORMAT_AMBIGUOUS",
1200
+ summary: "Multiple trace readers matched the input with equal confidence.",
1201
+ remediation: "Set options.format explicitly to disambiguate the reader.",
1202
+ relatedCodes: ["ambiguous_format"]
1203
+ },
1204
+ AI_TRACE_FACTS_INPUT_NOT_NORMALIZED: {
1205
+ code: "AI_TRACE_FACTS_INPUT_NOT_NORMALIZED",
1206
+ summary: "TraceFacts requires TraceReadResult or PersistedInspectEvent[].",
1207
+ remediation: "Use openTraceFile() to normalize a JSONL trace first."
1208
+ },
1209
+ AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED: {
1210
+ code: "AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED",
1211
+ summary: "Multiple runs are available; select a run before executing checks.",
1212
+ remediation: "Pass options.runId or TraceCheckInput.selectedRun.",
1213
+ relatedCodes: ["AI_CHECK_RUN_SELECTION_REQUIRED"]
1214
+ },
1215
+ AI_TRACE_RELATIONSHIP_SELF_PARENT: {
1216
+ code: "AI_TRACE_RELATIONSHIP_SELF_PARENT",
1217
+ summary: "A parentId equals its own event/step id.",
1218
+ remediation: "Reject at capture (AI_LANGGRAPH_SELF_PARENT_REJECTED) or drop via logical projection; do not invent replacement parents.",
1219
+ relatedCodes: [
1220
+ "AI_LANGGRAPH_SELF_PARENT_REJECTED",
1221
+ "AI_LOGICAL_SELF_PARENT_REMOVED"
1222
+ ]
1223
+ },
1224
+ AI_TRACE_RELATIONSHIP_CYCLE: {
1225
+ code: "AI_TRACE_RELATIONSHIP_CYCLE",
1226
+ summary: "Trace contains a parentId cycle.",
1227
+ remediation: "Use visibility-first tree linking for legacy fixtures; prefer acyclic capture for new adapter output.",
1228
+ relatedCodes: ["structure.cycle"]
1229
+ }
1230
+ });
1231
+ function formatProgrammaticDiagnostic(code, detail) {
1232
+ const spec = PROGRAMMATIC_DIAGNOSTIC_SPECS[code];
1233
+ const summary = detail?.trim() ? detail.trim() : spec.summary;
1234
+ return `${code}: ${summary} Remediation: ${spec.remediation}`;
1235
+ }
1236
+
1184
1237
  // packages/core/src/readers/index.ts
1185
1238
  var DEFAULT_MAX_TRACE_INPUT_BYTES = 10 * 1024 * 1024;
1186
1239
  var MIN_DETECTION_CONFIDENCE = 0.5;
@@ -1255,6 +1308,38 @@ var TraceReadError = class extends Error {
1255
1308
  this.warnings = warnings;
1256
1309
  }
1257
1310
  };
1311
+ var TRACE_INPUT_INVALID_MESSAGE = formatProgrammaticDiagnostic(
1312
+ "AI_TRACE_INPUT_INVALID"
1313
+ );
1314
+ function isTraceInput(input) {
1315
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
1316
+ return false;
1317
+ }
1318
+ const record = input;
1319
+ switch (record.type) {
1320
+ case "file":
1321
+ case "directory":
1322
+ return typeof record.path === "string";
1323
+ case "string":
1324
+ return typeof record.content === "string";
1325
+ case "buffer":
1326
+ return Buffer.isBuffer(record.content);
1327
+ case "stdin":
1328
+ return true;
1329
+ default:
1330
+ return false;
1331
+ }
1332
+ }
1333
+ function assertTraceInput(input) {
1334
+ if (isTraceInput(input)) return;
1335
+ throw new TraceReadError("invalid_input", TRACE_INPUT_INVALID_MESSAGE, [
1336
+ {
1337
+ code: "AI_TRACE_INPUT_INVALID",
1338
+ message: TRACE_INPUT_INVALID_MESSAGE,
1339
+ severity: "error"
1340
+ }
1341
+ ]);
1342
+ }
1258
1343
  function normalizeCandidate(reader, candidate) {
1259
1344
  const confidence = Number.isFinite(candidate.confidence) ? Math.max(0, Math.min(1, candidate.confidence)) : 0;
1260
1345
  return {
@@ -2609,6 +2694,7 @@ var DEFAULT_TRACE_READERS = [
2609
2694
  otlpJsonReader
2610
2695
  ];
2611
2696
  async function detectTraceFormat(input, options = {}) {
2697
+ assertTraceInput(input);
2612
2698
  const readers = options.readers ?? DEFAULT_TRACE_READERS;
2613
2699
  if (options.format !== void 0) {
2614
2700
  const reader = findReaderByFormat(options.format, readers);
@@ -2705,19 +2791,20 @@ async function detectTraceFormat(input, options = {}) {
2705
2791
  };
2706
2792
  }
2707
2793
  async function readTrace(input, options = {}) {
2794
+ assertTraceInput(input);
2708
2795
  const readers = options.readers ?? DEFAULT_TRACE_READERS;
2709
2796
  const detection = await detectTraceFormat(input, options);
2710
2797
  if (detection.status === "unsupported" || detection.format === void 0) {
2711
2798
  throw new TraceReadError(
2712
2799
  "unsupported_format",
2713
- "No trace reader could detect the input format.",
2800
+ formatProgrammaticDiagnostic("AI_TRACE_FORMAT_UNSUPPORTED"),
2714
2801
  detection.warnings
2715
2802
  );
2716
2803
  }
2717
2804
  if (detection.status === "ambiguous") {
2718
2805
  throw new TraceReadError(
2719
2806
  "ambiguous_format",
2720
- "Multiple trace readers matched the input with equal confidence.",
2807
+ formatProgrammaticDiagnostic("AI_TRACE_FORMAT_AMBIGUOUS"),
2721
2808
  detection.warnings
2722
2809
  );
2723
2810
  }
@@ -2725,7 +2812,10 @@ async function readTrace(input, options = {}) {
2725
2812
  if (!reader) {
2726
2813
  throw new TraceReadError(
2727
2814
  "unsupported_format",
2728
- `No trace reader is registered for format "${detection.format}".`,
2815
+ formatProgrammaticDiagnostic(
2816
+ "AI_TRACE_FORMAT_UNSUPPORTED",
2817
+ `No trace reader is registered for format "${detection.format}".`
2818
+ ),
2729
2819
  detection.warnings
2730
2820
  );
2731
2821
  }
@@ -2754,13 +2844,28 @@ async function readTrace(input, options = {}) {
2754
2844
  function openTrace(input, options = {}) {
2755
2845
  return readTrace(input, options);
2756
2846
  }
2847
+ function openTraceFile(filePath, options = {}) {
2848
+ return openTrace({ type: "file", path: filePath }, options);
2849
+ }
2850
+ function openTraceDirectory(dirPath, options = {}) {
2851
+ return openTrace({ type: "directory", path: dirPath }, options);
2852
+ }
2853
+ function openTraceText(content, options = {}) {
2854
+ return openTrace({ type: "string", content }, options);
2855
+ }
2757
2856
 
2758
2857
  exports.DEFAULT_TRACE_READERS = DEFAULT_TRACE_READERS;
2858
+ exports.PROGRAMMATIC_DIAGNOSTIC_SPECS = PROGRAMMATIC_DIAGNOSTIC_SPECS;
2759
2859
  exports.TraceReadError = TraceReadError;
2760
2860
  exports.agentInspectJsonlReader = agentInspectJsonlReader;
2861
+ exports.assertTraceInput = assertTraceInput;
2761
2862
  exports.detectTraceFormat = detectTraceFormat;
2863
+ exports.formatProgrammaticDiagnostic = formatProgrammaticDiagnostic;
2762
2864
  exports.openInferenceJsonReader = openInferenceJsonReader;
2763
2865
  exports.openTrace = openTrace;
2866
+ exports.openTraceDirectory = openTraceDirectory;
2867
+ exports.openTraceFile = openTraceFile;
2868
+ exports.openTraceText = openTraceText;
2764
2869
  exports.otlpJsonReader = otlpJsonReader;
2765
2870
  exports.readTrace = readTrace;
2766
2871
  //# sourceMappingURL=readers.cjs.map