@agent-inspect/mcp-server 6.31.29 → 6.31.31

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.cjs CHANGED
@@ -7505,6 +7505,159 @@ function redactRunTreeForExport(tree, options) {
7505
7505
  return clone;
7506
7506
  }
7507
7507
 
7508
+ // packages/core/src/exporters/presentation-lifecycle.ts
7509
+ function stepIdOf2(event) {
7510
+ const value = event.attributes?.stepId;
7511
+ return typeof value === "string" && value.trim() !== "" ? value : void 0;
7512
+ }
7513
+ function attemptIdOf(event) {
7514
+ const direct = event.attributes?.attemptId;
7515
+ if (typeof direct === "string" && direct.trim() !== "") return direct;
7516
+ const meta = event.attributes?.metadata;
7517
+ if (meta && typeof meta === "object" && !Array.isArray(meta)) {
7518
+ const nested = meta.attemptId;
7519
+ if (typeof nested === "string" && nested.trim() !== "") return nested;
7520
+ }
7521
+ return void 0;
7522
+ }
7523
+ function lifecycleKey(event) {
7524
+ if (event.kind === "RUN") return `run:${event.runId}`;
7525
+ const stepId = stepIdOf2(event);
7526
+ if (stepId !== void 0) return `step:${stepId}`;
7527
+ return `event:${event.eventId}`;
7528
+ }
7529
+ function isTerminal(status) {
7530
+ return status === "ok" || status === "error";
7531
+ }
7532
+ function eventTime(event) {
7533
+ return typeof event.timestamp === "number" ? event.timestamp : 0;
7534
+ }
7535
+ function cloneNode(node) {
7536
+ return {
7537
+ event: {
7538
+ ...node.event,
7539
+ ...node.event.attributes !== void 0 ? { attributes: { ...node.event.attributes } } : {}
7540
+ },
7541
+ children: node.children.map(cloneNode),
7542
+ depth: node.depth
7543
+ };
7544
+ }
7545
+ function joinOnePair(start, terminal) {
7546
+ const childMap = /* @__PURE__ */ new Map();
7547
+ if (start) {
7548
+ for (const child of start.children) {
7549
+ childMap.set(child.event.eventId, child);
7550
+ }
7551
+ }
7552
+ for (const child of terminal.children) {
7553
+ childMap.set(child.event.eventId, child);
7554
+ }
7555
+ return {
7556
+ event: {
7557
+ ...terminal.event,
7558
+ name: start?.event.name ?? terminal.event.name,
7559
+ kind: start?.event.kind ?? terminal.event.kind,
7560
+ ...start && attemptIdOf(terminal.event) === void 0 && attemptIdOf(start.event) ? {
7561
+ attributes: {
7562
+ ...terminal.event.attributes,
7563
+ attemptId: attemptIdOf(start.event)
7564
+ }
7565
+ } : {}
7566
+ },
7567
+ children: presentSiblingNodes([...childMap.values()]),
7568
+ depth: terminal.depth
7569
+ };
7570
+ }
7571
+ function joinSiblingGroup(group) {
7572
+ if (group.length <= 1) return group;
7573
+ const terminals = group.filter((n) => isTerminal(n.event.status)).sort((a, b) => eventTime(a.event) - eventTime(b.event));
7574
+ const runnings = group.filter((n) => n.event.status === "running").sort((a, b) => eventTime(a.event) - eventTime(b.event));
7575
+ const others = group.filter(
7576
+ (n) => !isTerminal(n.event.status) && n.event.status !== "running"
7577
+ );
7578
+ const terminalStatuses = new Set(terminals.map((n) => n.event.status));
7579
+ if (terminalStatuses.size > 1) {
7580
+ return group;
7581
+ }
7582
+ if (terminals.length > 1 && terminals.every((t) => attemptIdOf(t.event) === void 0) && runnings.every((r) => attemptIdOf(r.event) === void 0)) {
7583
+ return group;
7584
+ }
7585
+ const usedRunning = /* @__PURE__ */ new Set();
7586
+ const out = [];
7587
+ for (const terminal of terminals) {
7588
+ const terminalAttempt = attemptIdOf(terminal.event);
7589
+ const terminalTs = eventTime(terminal.event);
7590
+ const candidate = runnings.find((r) => {
7591
+ if (usedRunning.has(r.event.eventId)) return false;
7592
+ if (eventTime(r.event) > terminalTs) return false;
7593
+ const runningAttempt = attemptIdOf(r.event);
7594
+ if (terminalAttempt !== void 0) {
7595
+ return runningAttempt === terminalAttempt;
7596
+ }
7597
+ if (runningAttempt !== void 0) {
7598
+ return true;
7599
+ }
7600
+ return true;
7601
+ });
7602
+ if (candidate) {
7603
+ usedRunning.add(candidate.event.eventId);
7604
+ out.push(joinOnePair(candidate, terminal));
7605
+ } else {
7606
+ out.push({
7607
+ ...terminal,
7608
+ children: presentSiblingNodes(terminal.children)
7609
+ });
7610
+ }
7611
+ }
7612
+ for (const running of runnings) {
7613
+ if (usedRunning.has(running.event.eventId)) continue;
7614
+ out.push({
7615
+ ...running,
7616
+ children: presentSiblingNodes(running.children)
7617
+ });
7618
+ }
7619
+ for (const other of others) {
7620
+ out.push({
7621
+ ...other,
7622
+ children: presentSiblingNodes(other.children)
7623
+ });
7624
+ }
7625
+ return out;
7626
+ }
7627
+ function presentSiblingNodes(nodes) {
7628
+ const prepared = nodes.map((n) => ({
7629
+ ...cloneNode(n),
7630
+ children: presentSiblingNodes(n.children)
7631
+ }));
7632
+ const order = [];
7633
+ const groups = /* @__PURE__ */ new Map();
7634
+ for (const node of prepared) {
7635
+ const key = lifecycleKey(node.event);
7636
+ if (!groups.has(key)) {
7637
+ groups.set(key, []);
7638
+ order.push(key);
7639
+ }
7640
+ groups.get(key).push(node);
7641
+ }
7642
+ const out = [];
7643
+ for (const key of order) {
7644
+ out.push(...joinSiblingGroup(groups.get(key)));
7645
+ }
7646
+ return out;
7647
+ }
7648
+ function presentLifecycleJoinedTree(tree) {
7649
+ return {
7650
+ ...tree,
7651
+ children: presentSiblingNodes(tree.children),
7652
+ metadata: {
7653
+ ...tree.metadata,
7654
+ confidenceBreakdown: { ...tree.metadata.confidenceBreakdown },
7655
+ kinds: { ...tree.metadata.kinds },
7656
+ ...tree.metadata.relationshipSummary !== void 0 ? { relationshipSummary: { ...tree.metadata.relationshipSummary } } : {}
7657
+ }
7658
+ };
7659
+ }
7660
+
7508
7661
  // packages/core/src/exporters/html-exporter.ts
7509
7662
  function renderTreeHtml(nodes, ulClass = "tree") {
7510
7663
  if (nodes.length === 0) return "";
@@ -7532,32 +7685,33 @@ function exportHtml(tree, options) {
7532
7685
  const includeErrors = options?.includeErrors ?? true;
7533
7686
  const maxLen = options?.maxAttributeLength ?? 500;
7534
7687
  const redacted = options?.redacted;
7535
- const titleName = escapeHtml(tree.name ?? tree.runId);
7688
+ const view = presentLifecycleJoinedTree(tree);
7689
+ const titleName = escapeHtml(view.name ?? view.runId);
7536
7690
  const summaryRows = [];
7537
7691
  summaryRows.push(
7538
- `<tr><th scope="row">runId</th><td><code>${escapeHtml(tree.runId)}</code></td></tr>`
7692
+ `<tr><th scope="row">runId</th><td><code>${escapeHtml(view.runId)}</code></td></tr>`
7539
7693
  );
7540
- if (tree.name !== void 0) {
7541
- summaryRows.push(`<tr><th scope="row">name</th><td>${escapeHtml(tree.name)}</td></tr>`);
7694
+ if (view.name !== void 0) {
7695
+ summaryRows.push(`<tr><th scope="row">name</th><td>${escapeHtml(view.name)}</td></tr>`);
7542
7696
  }
7543
7697
  summaryRows.push(
7544
- `<tr><th scope="row">status</th><td>${escapeHtml(String(tree.status ?? "unknown"))}</td></tr>`
7698
+ `<tr><th scope="row">status</th><td>${escapeHtml(String(view.status ?? "unknown"))}</td></tr>`
7545
7699
  );
7546
7700
  summaryRows.push(
7547
- `<tr><th scope="row">durationMs</th><td>${tree.durationMs !== void 0 ? escapeHtml(String(tree.durationMs)) : "\u2014"}</td></tr>`
7701
+ `<tr><th scope="row">durationMs</th><td>${view.durationMs !== void 0 ? escapeHtml(String(view.durationMs)) : "\u2014"}</td></tr>`
7548
7702
  );
7549
7703
  summaryRows.push(
7550
- `<tr><th scope="row">startedAt</th><td>${tree.startedAt !== void 0 ? escapeHtml(String(tree.startedAt)) : "\u2014"}</td></tr>`
7704
+ `<tr><th scope="row">startedAt</th><td>${view.startedAt !== void 0 ? escapeHtml(String(view.startedAt)) : "\u2014"}</td></tr>`
7551
7705
  );
7552
7706
  summaryRows.push(
7553
- `<tr><th scope="row">endedAt</th><td>${tree.endedAt !== void 0 ? escapeHtml(String(tree.endedAt)) : "\u2014"}</td></tr>`
7707
+ `<tr><th scope="row">endedAt</th><td>${view.endedAt !== void 0 ? escapeHtml(String(view.endedAt)) : "\u2014"}</td></tr>`
7554
7708
  );
7555
7709
  summaryRows.push(
7556
- `<tr><th scope="row">totalEvents</th><td>${escapeHtml(String(tree.metadata.totalEvents))}</td></tr>`
7710
+ `<tr><th scope="row">totalEvents</th><td>${escapeHtml(String(view.metadata.totalEvents))}</td></tr>`
7557
7711
  );
7558
7712
  let confidenceHtml = "";
7559
7713
  if (includeMetadata) {
7560
- const cb = tree.metadata.confidenceBreakdown;
7714
+ const cb = view.metadata.confidenceBreakdown;
7561
7715
  confidenceHtml += "<h3>Confidence breakdown</h3><table><thead><tr><th>bucket</th><th>count</th></tr></thead><tbody>";
7562
7716
  for (const k of Object.keys(cb).sort()) {
7563
7717
  const key = k;
@@ -7565,14 +7719,14 @@ function exportHtml(tree, options) {
7565
7719
  }
7566
7720
  confidenceHtml += "</tbody></table>";
7567
7721
  confidenceHtml += "<h3>Kind breakdown</h3><table><thead><tr><th>kind</th><th>count</th></tr></thead><tbody>";
7568
- for (const k of Object.keys(tree.metadata.kinds).sort()) {
7722
+ for (const k of Object.keys(view.metadata.kinds).sort()) {
7569
7723
  const key = k;
7570
- const c = tree.metadata.kinds[key];
7724
+ const c = view.metadata.kinds[key];
7571
7725
  if (c > 0) confidenceHtml += `<tr><td>${escapeHtml(key)}</td><td>${c}</td></tr>`;
7572
7726
  }
7573
7727
  confidenceHtml += "</tbody></table>";
7574
7728
  }
7575
- const flat = flattenTree(tree);
7729
+ const flat = flattenTree(view);
7576
7730
  const errors = flat.filter((n) => n.event.status === "error");
7577
7731
  let errorsHtml = "";
7578
7732
  if (includeErrors && errors.length > 0) {
@@ -7627,7 +7781,7 @@ footer{margin-top:2rem;font-size:0.85rem;color:#555}
7627
7781
  <header><h1>AgentInspect Run: ${titleName}</h1></header>
7628
7782
  <p class="note">Generated locally by AgentInspect.</p>
7629
7783
  ${includeMetadata ? `<section class="summary"><h2>Summary</h2><table>${summaryRows.join("")}</table>${confidenceHtml}</section>` : ""}
7630
- <section class="tree"><h2>Execution tree</h2>${tree.children.length > 0 ? renderTreeHtml(tree.children) : "<p>No steps recorded.</p>"}</section>
7784
+ <section class="tree"><h2>Execution tree</h2>${view.children.length > 0 ? renderTreeHtml(view.children) : "<p>No steps recorded.</p>"}</section>
7631
7785
  ${errorsHtml}
7632
7786
  ${attrsHtml}
7633
7787
  <footer>Generated locally by AgentInspect. Review for sensitive data before sharing.</footer>
@@ -7668,7 +7822,8 @@ function exportMarkdown(tree, options) {
7668
7822
  const includeErrors = options?.includeErrors ?? true;
7669
7823
  const maxLen = options?.maxAttributeLength ?? 500;
7670
7824
  const redacted = options?.redacted ?? true;
7671
- const titleName = tree.name ?? tree.runId;
7825
+ const view = presentLifecycleJoinedTree(tree);
7826
+ const titleName = view.name ?? view.runId;
7672
7827
  const lines = [];
7673
7828
  lines.push(`# AgentInspect Run: ${escapeMarkdown(titleName)}`);
7674
7829
  lines.push("");
@@ -7677,28 +7832,28 @@ function exportMarkdown(tree, options) {
7677
7832
  if (includeMetadata) {
7678
7833
  lines.push("## Summary");
7679
7834
  lines.push("");
7680
- lines.push(`- **runId**: ${escapeMarkdown(tree.runId)}`);
7681
- if (tree.name !== void 0) lines.push(`- **name**: ${escapeMarkdown(tree.name)}`);
7682
- lines.push(`- **status**: ${escapeMarkdown(String(tree.status ?? "unknown"))}`);
7835
+ lines.push(`- **runId**: ${escapeMarkdown(view.runId)}`);
7836
+ if (view.name !== void 0) lines.push(`- **name**: ${escapeMarkdown(view.name)}`);
7837
+ lines.push(`- **status**: ${escapeMarkdown(String(view.status ?? "unknown"))}`);
7683
7838
  lines.push(
7684
- `- **durationMs**: ${tree.durationMs !== void 0 ? escapeMarkdown(String(tree.durationMs)) : "-"}`
7839
+ `- **durationMs**: ${view.durationMs !== void 0 ? escapeMarkdown(String(view.durationMs)) : "-"}`
7685
7840
  );
7686
7841
  lines.push(
7687
- `- **startedAt**: ${tree.startedAt !== void 0 ? escapeMarkdown(String(tree.startedAt)) : "-"}`
7842
+ `- **startedAt**: ${view.startedAt !== void 0 ? escapeMarkdown(String(view.startedAt)) : "-"}`
7688
7843
  );
7689
7844
  lines.push(
7690
- `- **endedAt**: ${tree.endedAt !== void 0 ? escapeMarkdown(String(tree.endedAt)) : "-"}`
7845
+ `- **endedAt**: ${view.endedAt !== void 0 ? escapeMarkdown(String(view.endedAt)) : "-"}`
7691
7846
  );
7692
- lines.push(`- **totalEvents**: ${tree.metadata.totalEvents}`);
7847
+ lines.push(`- **totalEvents**: ${view.metadata.totalEvents}`);
7693
7848
  lines.push("");
7694
7849
  lines.push("### Confidence breakdown");
7695
7850
  lines.push("");
7696
7851
  lines.push("| bucket | count |");
7697
7852
  lines.push("| --- | --- |");
7698
- for (const k of Object.keys(tree.metadata.confidenceBreakdown).sort()) {
7853
+ for (const k of Object.keys(view.metadata.confidenceBreakdown).sort()) {
7699
7854
  const key = k;
7700
7855
  lines.push(
7701
- `| ${escapeMarkdown(key)} | ${tree.metadata.confidenceBreakdown[key]} |`
7856
+ `| ${escapeMarkdown(key)} | ${view.metadata.confidenceBreakdown[key]} |`
7702
7857
  );
7703
7858
  }
7704
7859
  lines.push("");
@@ -7706,9 +7861,9 @@ function exportMarkdown(tree, options) {
7706
7861
  lines.push("");
7707
7862
  lines.push("| kind | count |");
7708
7863
  lines.push("| --- | --- |");
7709
- for (const k of Object.keys(tree.metadata.kinds).sort()) {
7864
+ for (const k of Object.keys(view.metadata.kinds).sort()) {
7710
7865
  const key = k;
7711
- const c = tree.metadata.kinds[key];
7866
+ const c = view.metadata.kinds[key];
7712
7867
  if (c > 0) lines.push(`| ${escapeMarkdown(key)} | ${c} |`);
7713
7868
  }
7714
7869
  lines.push("");
@@ -7717,11 +7872,11 @@ function exportMarkdown(tree, options) {
7717
7872
  lines.push("");
7718
7873
  lines.push("```text");
7719
7874
  lines.push(
7720
- tree.children.length > 0 ? renderTreeAscii(tree.children) : "(no steps)"
7875
+ view.children.length > 0 ? renderTreeAscii(view.children) : "(no steps)"
7721
7876
  );
7722
7877
  lines.push("```");
7723
7878
  lines.push("");
7724
- const flat = flattenTree(tree);
7879
+ const flat = flattenTree(view);
7725
7880
  const errors = flat.filter((n) => n.event.status === "error");
7726
7881
  if (includeErrors && errors.length > 0) {
7727
7882
  lines.push("## Errors");