@agent-inspect/mcp-server 6.14.2 → 6.15.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.
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { runReadOnlyMcpServer } from './chunk-7AL325ZU.mjs';
1
+ import { runReadOnlyMcpServer } from './chunk-JASWIBAT.mjs';
2
2
  import { readFileSync } from 'fs';
3
3
  import path from 'path';
4
4
  import { fileURLToPath } from 'url';
package/dist/index.cjs CHANGED
@@ -2578,6 +2578,59 @@ function diffRuns(left, right, options) {
2578
2578
  return table;
2579
2579
  })();
2580
2580
 
2581
+ // packages/core/src/diagnostics/programmatic.ts
2582
+ var PROGRAMMATIC_DIAGNOSTIC_SPECS = Object.freeze({
2583
+ AI_TRACE_INPUT_INVALID: {
2584
+ code: "AI_TRACE_INPUT_INVALID",
2585
+ summary: 'Expected { type: "file", path }, { type: "directory", path }, { type: "string", content }, { type: "buffer", content }, or { type: "stdin" }.',
2586
+ remediation: "For a file path, use openTraceFile(path).",
2587
+ relatedCodes: ["invalid_input"]
2588
+ },
2589
+ AI_TRACE_FORMAT_UNSUPPORTED: {
2590
+ code: "AI_TRACE_FORMAT_UNSUPPORTED",
2591
+ summary: "No trace reader could detect the input format.",
2592
+ remediation: "Pass an AgentInspect JSONL file via openTraceFile, or set options.format to a registered reader.",
2593
+ relatedCodes: ["unsupported_format"]
2594
+ },
2595
+ AI_TRACE_FORMAT_AMBIGUOUS: {
2596
+ code: "AI_TRACE_FORMAT_AMBIGUOUS",
2597
+ summary: "Multiple trace readers matched the input with equal confidence.",
2598
+ remediation: "Set options.format explicitly to disambiguate the reader.",
2599
+ relatedCodes: ["ambiguous_format"]
2600
+ },
2601
+ AI_TRACE_FACTS_INPUT_NOT_NORMALIZED: {
2602
+ code: "AI_TRACE_FACTS_INPUT_NOT_NORMALIZED",
2603
+ summary: "TraceFacts requires TraceReadResult or PersistedInspectEvent[].",
2604
+ remediation: "Use openTraceFile() to normalize a JSONL trace first."
2605
+ },
2606
+ AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED: {
2607
+ code: "AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED",
2608
+ summary: "Multiple runs are available; select a run before executing checks.",
2609
+ remediation: "Pass options.runId or TraceCheckInput.selectedRun.",
2610
+ relatedCodes: ["AI_CHECK_RUN_SELECTION_REQUIRED"]
2611
+ },
2612
+ AI_TRACE_RELATIONSHIP_SELF_PARENT: {
2613
+ code: "AI_TRACE_RELATIONSHIP_SELF_PARENT",
2614
+ summary: "A parentId equals its own event/step id.",
2615
+ remediation: "Reject at capture (AI_LANGGRAPH_SELF_PARENT_REJECTED) or drop via logical projection; do not invent replacement parents.",
2616
+ relatedCodes: [
2617
+ "AI_LANGGRAPH_SELF_PARENT_REJECTED",
2618
+ "AI_LOGICAL_SELF_PARENT_REMOVED"
2619
+ ]
2620
+ },
2621
+ AI_TRACE_RELATIONSHIP_CYCLE: {
2622
+ code: "AI_TRACE_RELATIONSHIP_CYCLE",
2623
+ summary: "Trace contains a parentId cycle.",
2624
+ remediation: "Use visibility-first tree linking for legacy fixtures; prefer acyclic capture for new adapter output.",
2625
+ relatedCodes: ["structure.cycle"]
2626
+ }
2627
+ });
2628
+ function formatProgrammaticDiagnostic(code, detail) {
2629
+ const spec = PROGRAMMATIC_DIAGNOSTIC_SPECS[code];
2630
+ const summary = detail?.trim() ? detail.trim() : spec.summary;
2631
+ return `${code}: ${summary} Remediation: ${spec.remediation}`;
2632
+ }
2633
+
2581
2634
  // packages/core/src/safety/sensitive-key.ts
2582
2635
  function normalizeSensitiveKey(value) {
2583
2636
  return value.toLowerCase().replace(/[^a-z0-9_]/g, "");
@@ -2843,7 +2896,10 @@ function projectLogicalEvents(events) {
2843
2896
  if (originalParentId === event.eventId) {
2844
2897
  diagnostics.push({
2845
2898
  code: "AI_LOGICAL_SELF_PARENT_REMOVED",
2846
- message: `Removed self-parent edge on ${event.eventId}.`,
2899
+ message: formatProgrammaticDiagnostic(
2900
+ "AI_TRACE_RELATIONSHIP_SELF_PARENT",
2901
+ `Removed self-parent edge on ${event.eventId}.`
2902
+ ),
2847
2903
  eventIds: [event.eventId]
2848
2904
  });
2849
2905
  const { parentId: _drop, ...rest } = event;
@@ -2875,7 +2931,10 @@ function projectLogicalEvents(events) {
2875
2931
  if (nextParent === event.eventId) {
2876
2932
  diagnostics.push({
2877
2933
  code: "AI_LOGICAL_SELF_PARENT_REMOVED",
2878
- message: `Removed self-parent edge on ${event.eventId} (was ${originalParentId}).`,
2934
+ message: formatProgrammaticDiagnostic(
2935
+ "AI_TRACE_RELATIONSHIP_SELF_PARENT",
2936
+ `Removed self-parent edge on ${event.eventId} (was ${originalParentId}).`
2937
+ ),
2879
2938
  eventIds: [event.eventId]
2880
2939
  });
2881
2940
  const { parentId: _drop, ...rest } = event;
@@ -2961,7 +3020,45 @@ function summarizeSemanticParity(events) {
2961
3020
  diagnostics: projection.diagnostics
2962
3021
  };
2963
3022
  }
2964
- function buildTraceFacts(events) {
3023
+ var TRACE_FACTS_INPUT_NOT_NORMALIZED = formatProgrammaticDiagnostic(
3024
+ "AI_TRACE_FACTS_INPUT_NOT_NORMALIZED"
3025
+ );
3026
+ function isTraceReadResult(input) {
3027
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
3028
+ return false;
3029
+ }
3030
+ const record = input;
3031
+ return Array.isArray(record.events) && Array.isArray(record.runs) && typeof record.format === "string" && Array.isArray(record.warnings);
3032
+ }
3033
+ function looksLikeRawV01TraceEvents(input) {
3034
+ if (!Array.isArray(input) || input.length === 0) return false;
3035
+ const first = input[0];
3036
+ if (typeof first !== "object" || first === null) return false;
3037
+ const row = first;
3038
+ return typeof row.event === "string" && (row.schemaVersion === "0.1" || row.eventId === void 0);
3039
+ }
3040
+ function isPersistedInspectEventArray(input) {
3041
+ if (!Array.isArray(input)) return false;
3042
+ if (input.length === 0) return true;
3043
+ const first = input[0];
3044
+ if (typeof first !== "object" || first === null) return false;
3045
+ const row = first;
3046
+ return typeof row.eventId === "string" && (row.schemaVersion === "0.2" || row.schemaVersion === "1.0" || row.schemaVersion === "0.1") && typeof row.event !== "string";
3047
+ }
3048
+ function resolveTraceFactsEvents(input) {
3049
+ if (isTraceReadResult(input)) {
3050
+ return input.events;
3051
+ }
3052
+ if (looksLikeRawV01TraceEvents(input)) {
3053
+ throw new TypeError(TRACE_FACTS_INPUT_NOT_NORMALIZED);
3054
+ }
3055
+ if (isPersistedInspectEventArray(input)) {
3056
+ return input;
3057
+ }
3058
+ throw new TypeError(TRACE_FACTS_INPUT_NOT_NORMALIZED);
3059
+ }
3060
+ function buildTraceFacts(input) {
3061
+ const events = resolveTraceFactsEvents(input);
2965
3062
  const projection = projectLogicalEvents(events);
2966
3063
  const toolsByName = /* @__PURE__ */ new Map();
2967
3064
  const llmEvents = [];
@@ -3163,7 +3260,13 @@ function resolveSelectedRun(input, runId) {
3163
3260
  if (input.read.runs.length === 0) {
3164
3261
  return {
3165
3262
  diagnostics: [
3166
- diagnostic("AI_CHECK_RUN_SELECTION_REQUIRED", "No runs are available for checks.")
3263
+ diagnostic(
3264
+ "AI_CHECK_RUN_SELECTION_REQUIRED",
3265
+ formatProgrammaticDiagnostic(
3266
+ "AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED",
3267
+ "No runs are available for checks."
3268
+ )
3269
+ )
3167
3270
  ]
3168
3271
  };
3169
3272
  }
@@ -3171,7 +3274,7 @@ function resolveSelectedRun(input, runId) {
3171
3274
  diagnostics: [
3172
3275
  diagnostic(
3173
3276
  "AI_CHECK_RUN_SELECTION_REQUIRED",
3174
- "Multiple runs are available; select a run before executing checks."
3277
+ formatProgrammaticDiagnostic("AI_TRACE_CONTRACT_RUN_SELECTION_REQUIRED")
3175
3278
  )
3176
3279
  ]
3177
3280
  };
@@ -4317,6 +4420,38 @@ var TraceReadError = class extends Error {
4317
4420
  this.warnings = warnings;
4318
4421
  }
4319
4422
  };
4423
+ var TRACE_INPUT_INVALID_MESSAGE = formatProgrammaticDiagnostic(
4424
+ "AI_TRACE_INPUT_INVALID"
4425
+ );
4426
+ function isTraceInput(input) {
4427
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
4428
+ return false;
4429
+ }
4430
+ const record = input;
4431
+ switch (record.type) {
4432
+ case "file":
4433
+ case "directory":
4434
+ return typeof record.path === "string";
4435
+ case "string":
4436
+ return typeof record.content === "string";
4437
+ case "buffer":
4438
+ return Buffer.isBuffer(record.content);
4439
+ case "stdin":
4440
+ return true;
4441
+ default:
4442
+ return false;
4443
+ }
4444
+ }
4445
+ function assertTraceInput(input) {
4446
+ if (isTraceInput(input)) return;
4447
+ throw new TraceReadError("invalid_input", TRACE_INPUT_INVALID_MESSAGE, [
4448
+ {
4449
+ code: "AI_TRACE_INPUT_INVALID",
4450
+ message: TRACE_INPUT_INVALID_MESSAGE,
4451
+ severity: "error"
4452
+ }
4453
+ ]);
4454
+ }
4320
4455
  function normalizeCandidate(reader, candidate) {
4321
4456
  const confidence = Number.isFinite(candidate.confidence) ? Math.max(0, Math.min(1, candidate.confidence)) : 0;
4322
4457
  return {
@@ -5671,6 +5806,7 @@ var DEFAULT_TRACE_READERS = [
5671
5806
  otlpJsonReader
5672
5807
  ];
5673
5808
  async function detectTraceFormat(input, options = {}) {
5809
+ assertTraceInput(input);
5674
5810
  const readers = options.readers ?? DEFAULT_TRACE_READERS;
5675
5811
  if (options.format !== void 0) {
5676
5812
  const reader = findReaderByFormat(options.format, readers);
@@ -5767,19 +5903,20 @@ async function detectTraceFormat(input, options = {}) {
5767
5903
  };
5768
5904
  }
5769
5905
  async function readTrace(input, options = {}) {
5906
+ assertTraceInput(input);
5770
5907
  const readers = options.readers ?? DEFAULT_TRACE_READERS;
5771
5908
  const detection = await detectTraceFormat(input, options);
5772
5909
  if (detection.status === "unsupported" || detection.format === void 0) {
5773
5910
  throw new TraceReadError(
5774
5911
  "unsupported_format",
5775
- "No trace reader could detect the input format.",
5912
+ formatProgrammaticDiagnostic("AI_TRACE_FORMAT_UNSUPPORTED"),
5776
5913
  detection.warnings
5777
5914
  );
5778
5915
  }
5779
5916
  if (detection.status === "ambiguous") {
5780
5917
  throw new TraceReadError(
5781
5918
  "ambiguous_format",
5782
- "Multiple trace readers matched the input with equal confidence.",
5919
+ formatProgrammaticDiagnostic("AI_TRACE_FORMAT_AMBIGUOUS"),
5783
5920
  detection.warnings
5784
5921
  );
5785
5922
  }
@@ -5787,7 +5924,10 @@ async function readTrace(input, options = {}) {
5787
5924
  if (!reader) {
5788
5925
  throw new TraceReadError(
5789
5926
  "unsupported_format",
5790
- `No trace reader is registered for format "${detection.format}".`,
5927
+ formatProgrammaticDiagnostic(
5928
+ "AI_TRACE_FORMAT_UNSUPPORTED",
5929
+ `No trace reader is registered for format "${detection.format}".`
5930
+ ),
5791
5931
  detection.warnings
5792
5932
  );
5793
5933
  }