agent-inspect 6.31.29 → 6.31.30

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.
@@ -418,6 +418,96 @@ function redactRunTreeForExport(tree, options) {
418
418
  return clone;
419
419
  }
420
420
 
421
+ // packages/core/src/exporters/presentation-lifecycle.ts
422
+ function stepIdOf(event) {
423
+ const value = event.attributes?.stepId;
424
+ return typeof value === "string" && value.trim() !== "" ? value : void 0;
425
+ }
426
+ function lifecycleKey(event) {
427
+ if (event.kind === "RUN") return `run:${event.runId}`;
428
+ const stepId = stepIdOf(event);
429
+ if (stepId !== void 0) return `step:${stepId}`;
430
+ return `event:${event.eventId}`;
431
+ }
432
+ function isTerminal(status) {
433
+ return status === "ok" || status === "error";
434
+ }
435
+ function cloneNode(node) {
436
+ return {
437
+ event: {
438
+ ...node.event,
439
+ ...node.event.attributes !== void 0 ? { attributes: { ...node.event.attributes } } : {}
440
+ },
441
+ children: node.children.map(cloneNode),
442
+ depth: node.depth
443
+ };
444
+ }
445
+ function joinSiblingGroup(group) {
446
+ if (group.length <= 1) return group;
447
+ const terminals = group.filter((n) => isTerminal(n.event.status));
448
+ const runnings = group.filter((n) => n.event.status === "running");
449
+ const terminalStatuses = new Set(terminals.map((n) => n.event.status));
450
+ if (terminalStatuses.size > 1) {
451
+ return group;
452
+ }
453
+ if (terminals.length >= 1) {
454
+ const terminal = terminals[terminals.length - 1];
455
+ const start = runnings[0];
456
+ const childMap = /* @__PURE__ */ new Map();
457
+ for (const n of group) {
458
+ for (const child of n.children) {
459
+ childMap.set(child.event.eventId, child);
460
+ }
461
+ }
462
+ return [
463
+ {
464
+ event: {
465
+ ...terminal.event,
466
+ name: start?.event.name ?? terminal.event.name,
467
+ kind: start?.event.kind ?? terminal.event.kind,
468
+ ...start?.event.timestamp !== void 0 && terminal.event.durationMs === void 0 ? {} : {}
469
+ },
470
+ children: presentSiblingNodes([...childMap.values()]),
471
+ depth: terminal.depth
472
+ }
473
+ ];
474
+ }
475
+ return group;
476
+ }
477
+ function presentSiblingNodes(nodes) {
478
+ const prepared = nodes.map((n) => ({
479
+ ...cloneNode(n),
480
+ children: presentSiblingNodes(n.children)
481
+ }));
482
+ const order = [];
483
+ const groups = /* @__PURE__ */ new Map();
484
+ for (const node of prepared) {
485
+ const key = lifecycleKey(node.event);
486
+ if (!groups.has(key)) {
487
+ groups.set(key, []);
488
+ order.push(key);
489
+ }
490
+ groups.get(key).push(node);
491
+ }
492
+ const out = [];
493
+ for (const key of order) {
494
+ out.push(...joinSiblingGroup(groups.get(key)));
495
+ }
496
+ return out;
497
+ }
498
+ function presentLifecycleJoinedTree(tree) {
499
+ return {
500
+ ...tree,
501
+ children: presentSiblingNodes(tree.children),
502
+ metadata: {
503
+ ...tree.metadata,
504
+ confidenceBreakdown: { ...tree.metadata.confidenceBreakdown },
505
+ kinds: { ...tree.metadata.kinds },
506
+ ...tree.metadata.relationshipSummary !== void 0 ? { relationshipSummary: { ...tree.metadata.relationshipSummary } } : {}
507
+ }
508
+ };
509
+ }
510
+
421
511
  // packages/core/src/exporters/html-exporter.ts
422
512
  function renderTreeHtml(nodes, ulClass = "tree") {
423
513
  if (nodes.length === 0) return "";
@@ -445,32 +535,33 @@ function exportHtml(tree, options) {
445
535
  const includeErrors = options?.includeErrors ?? true;
446
536
  const maxLen = options?.maxAttributeLength ?? 500;
447
537
  const redacted = options?.redacted ?? true;
448
- const titleName = escapeHtml(tree.name ?? tree.runId);
538
+ const view = presentLifecycleJoinedTree(tree);
539
+ const titleName = escapeHtml(view.name ?? view.runId);
449
540
  const summaryRows = [];
450
541
  summaryRows.push(
451
- `<tr><th scope="row">runId</th><td><code>${escapeHtml(tree.runId)}</code></td></tr>`
542
+ `<tr><th scope="row">runId</th><td><code>${escapeHtml(view.runId)}</code></td></tr>`
452
543
  );
453
- if (tree.name !== void 0) {
454
- summaryRows.push(`<tr><th scope="row">name</th><td>${escapeHtml(tree.name)}</td></tr>`);
544
+ if (view.name !== void 0) {
545
+ summaryRows.push(`<tr><th scope="row">name</th><td>${escapeHtml(view.name)}</td></tr>`);
455
546
  }
456
547
  summaryRows.push(
457
- `<tr><th scope="row">status</th><td>${escapeHtml(String(tree.status ?? "unknown"))}</td></tr>`
548
+ `<tr><th scope="row">status</th><td>${escapeHtml(String(view.status ?? "unknown"))}</td></tr>`
458
549
  );
459
550
  summaryRows.push(
460
- `<tr><th scope="row">durationMs</th><td>${tree.durationMs !== void 0 ? escapeHtml(String(tree.durationMs)) : "\u2014"}</td></tr>`
551
+ `<tr><th scope="row">durationMs</th><td>${view.durationMs !== void 0 ? escapeHtml(String(view.durationMs)) : "\u2014"}</td></tr>`
461
552
  );
462
553
  summaryRows.push(
463
- `<tr><th scope="row">startedAt</th><td>${tree.startedAt !== void 0 ? escapeHtml(String(tree.startedAt)) : "\u2014"}</td></tr>`
554
+ `<tr><th scope="row">startedAt</th><td>${view.startedAt !== void 0 ? escapeHtml(String(view.startedAt)) : "\u2014"}</td></tr>`
464
555
  );
465
556
  summaryRows.push(
466
- `<tr><th scope="row">endedAt</th><td>${tree.endedAt !== void 0 ? escapeHtml(String(tree.endedAt)) : "\u2014"}</td></tr>`
557
+ `<tr><th scope="row">endedAt</th><td>${view.endedAt !== void 0 ? escapeHtml(String(view.endedAt)) : "\u2014"}</td></tr>`
467
558
  );
468
559
  summaryRows.push(
469
- `<tr><th scope="row">totalEvents</th><td>${escapeHtml(String(tree.metadata.totalEvents))}</td></tr>`
560
+ `<tr><th scope="row">totalEvents</th><td>${escapeHtml(String(view.metadata.totalEvents))}</td></tr>`
470
561
  );
471
562
  let confidenceHtml = "";
472
563
  if (includeMetadata) {
473
- const cb = tree.metadata.confidenceBreakdown;
564
+ const cb = view.metadata.confidenceBreakdown;
474
565
  confidenceHtml += "<h3>Confidence breakdown</h3><table><thead><tr><th>bucket</th><th>count</th></tr></thead><tbody>";
475
566
  for (const k of Object.keys(cb).sort()) {
476
567
  const key = k;
@@ -478,14 +569,14 @@ function exportHtml(tree, options) {
478
569
  }
479
570
  confidenceHtml += "</tbody></table>";
480
571
  confidenceHtml += "<h3>Kind breakdown</h3><table><thead><tr><th>kind</th><th>count</th></tr></thead><tbody>";
481
- for (const k of Object.keys(tree.metadata.kinds).sort()) {
572
+ for (const k of Object.keys(view.metadata.kinds).sort()) {
482
573
  const key = k;
483
- const c = tree.metadata.kinds[key];
574
+ const c = view.metadata.kinds[key];
484
575
  if (c > 0) confidenceHtml += `<tr><td>${escapeHtml(key)}</td><td>${c}</td></tr>`;
485
576
  }
486
577
  confidenceHtml += "</tbody></table>";
487
578
  }
488
- const flat = flattenTree(tree);
579
+ const flat = flattenTree(view);
489
580
  const errors = flat.filter((n) => n.event.status === "error");
490
581
  let errorsHtml = "";
491
582
  if (includeErrors && errors.length > 0) {
@@ -540,7 +631,7 @@ footer{margin-top:2rem;font-size:0.85rem;color:#555}
540
631
  <header><h1>AgentInspect Run: ${titleName}</h1></header>
541
632
  <p class="note">Generated locally by AgentInspect.</p>
542
633
  ${includeMetadata ? `<section class="summary"><h2>Summary</h2><table>${summaryRows.join("")}</table>${confidenceHtml}</section>` : ""}
543
- <section class="tree"><h2>Execution tree</h2>${tree.children.length > 0 ? renderTreeHtml(tree.children) : "<p>No steps recorded.</p>"}</section>
634
+ <section class="tree"><h2>Execution tree</h2>${view.children.length > 0 ? renderTreeHtml(view.children) : "<p>No steps recorded.</p>"}</section>
544
635
  ${errorsHtml}
545
636
  ${attrsHtml}
546
637
  <footer>Generated locally by AgentInspect. Review for sensitive data before sharing.</footer>
@@ -581,7 +672,8 @@ function exportMarkdown(tree, options) {
581
672
  const includeErrors = options?.includeErrors ?? true;
582
673
  const maxLen = options?.maxAttributeLength ?? 500;
583
674
  const redacted = options?.redacted ?? true;
584
- const titleName = tree.name ?? tree.runId;
675
+ const view = presentLifecycleJoinedTree(tree);
676
+ const titleName = view.name ?? view.runId;
585
677
  const lines = [];
586
678
  lines.push(`# AgentInspect Run: ${escapeMarkdown(titleName)}`);
587
679
  lines.push("");
@@ -590,28 +682,28 @@ function exportMarkdown(tree, options) {
590
682
  if (includeMetadata) {
591
683
  lines.push("## Summary");
592
684
  lines.push("");
593
- lines.push(`- **runId**: ${escapeMarkdown(tree.runId)}`);
594
- if (tree.name !== void 0) lines.push(`- **name**: ${escapeMarkdown(tree.name)}`);
595
- lines.push(`- **status**: ${escapeMarkdown(String(tree.status ?? "unknown"))}`);
685
+ lines.push(`- **runId**: ${escapeMarkdown(view.runId)}`);
686
+ if (view.name !== void 0) lines.push(`- **name**: ${escapeMarkdown(view.name)}`);
687
+ lines.push(`- **status**: ${escapeMarkdown(String(view.status ?? "unknown"))}`);
596
688
  lines.push(
597
- `- **durationMs**: ${tree.durationMs !== void 0 ? escapeMarkdown(String(tree.durationMs)) : "-"}`
689
+ `- **durationMs**: ${view.durationMs !== void 0 ? escapeMarkdown(String(view.durationMs)) : "-"}`
598
690
  );
599
691
  lines.push(
600
- `- **startedAt**: ${tree.startedAt !== void 0 ? escapeMarkdown(String(tree.startedAt)) : "-"}`
692
+ `- **startedAt**: ${view.startedAt !== void 0 ? escapeMarkdown(String(view.startedAt)) : "-"}`
601
693
  );
602
694
  lines.push(
603
- `- **endedAt**: ${tree.endedAt !== void 0 ? escapeMarkdown(String(tree.endedAt)) : "-"}`
695
+ `- **endedAt**: ${view.endedAt !== void 0 ? escapeMarkdown(String(view.endedAt)) : "-"}`
604
696
  );
605
- lines.push(`- **totalEvents**: ${tree.metadata.totalEvents}`);
697
+ lines.push(`- **totalEvents**: ${view.metadata.totalEvents}`);
606
698
  lines.push("");
607
699
  lines.push("### Confidence breakdown");
608
700
  lines.push("");
609
701
  lines.push("| bucket | count |");
610
702
  lines.push("| --- | --- |");
611
- for (const k of Object.keys(tree.metadata.confidenceBreakdown).sort()) {
703
+ for (const k of Object.keys(view.metadata.confidenceBreakdown).sort()) {
612
704
  const key = k;
613
705
  lines.push(
614
- `| ${escapeMarkdown(key)} | ${tree.metadata.confidenceBreakdown[key]} |`
706
+ `| ${escapeMarkdown(key)} | ${view.metadata.confidenceBreakdown[key]} |`
615
707
  );
616
708
  }
617
709
  lines.push("");
@@ -619,9 +711,9 @@ function exportMarkdown(tree, options) {
619
711
  lines.push("");
620
712
  lines.push("| kind | count |");
621
713
  lines.push("| --- | --- |");
622
- for (const k of Object.keys(tree.metadata.kinds).sort()) {
714
+ for (const k of Object.keys(view.metadata.kinds).sort()) {
623
715
  const key = k;
624
- const c = tree.metadata.kinds[key];
716
+ const c = view.metadata.kinds[key];
625
717
  if (c > 0) lines.push(`| ${escapeMarkdown(key)} | ${c} |`);
626
718
  }
627
719
  lines.push("");
@@ -630,11 +722,11 @@ function exportMarkdown(tree, options) {
630
722
  lines.push("");
631
723
  lines.push("```text");
632
724
  lines.push(
633
- tree.children.length > 0 ? renderTreeAscii(tree.children) : "(no steps)"
725
+ view.children.length > 0 ? renderTreeAscii(view.children) : "(no steps)"
634
726
  );
635
727
  lines.push("```");
636
728
  lines.push("");
637
- const flat = flattenTree(tree);
729
+ const flat = flattenTree(view);
638
730
  const errors = flat.filter((n) => n.event.status === "error");
639
731
  if (includeErrors && errors.length > 0) {
640
732
  lines.push("## Errors");