agent-inspect 4.2.0 → 4.3.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.
@@ -643,4 +643,96 @@ declare function isAgentInspectTrace(filePath: string): Promise<boolean>;
643
643
  */
644
644
  declare function parseDuration(duration: string): number;
645
645
 
646
- export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
646
+ /** Aggregate verify-safe status for a bundle. */
647
+ type BundleSafeStatus = "SAFE" | "SAFE WITH WARNINGS" | "UNSAFE" | "UNKNOWN";
648
+ /** Metadata-safe status (underscore form). */
649
+ type BundleSafeStatusMetadata = "SAFE" | "SAFE_WITH_WARNINGS" | "UNSAFE" | "UNKNOWN";
650
+ type BundleRedactionProfile = "local" | "share" | "strict";
651
+ interface BundleMetadata {
652
+ createdAt: string;
653
+ agentInspectVersion: string;
654
+ redactionProfile: BundleRedactionProfile;
655
+ sourceTraceCount: number;
656
+ runIds: string[];
657
+ safeStatus: BundleSafeStatusMetadata;
658
+ files: string[];
659
+ note: string;
660
+ sessionId?: string;
661
+ since?: string;
662
+ }
663
+ interface BundleRedactionReportRun {
664
+ runId: string;
665
+ findings: number;
666
+ detectors: string[];
667
+ }
668
+ interface BundleRedactionReport {
669
+ profile: BundleRedactionProfile;
670
+ totalFindings: number;
671
+ runs: BundleRedactionReportRun[];
672
+ }
673
+ interface BundleCheckRunResult {
674
+ runId: string;
675
+ status: BundleSafeStatus;
676
+ errors: number;
677
+ warnings: number;
678
+ findings: number;
679
+ }
680
+ interface BundleCheckResults {
681
+ aggregateStatus: BundleSafeStatus;
682
+ runs: BundleCheckRunResult[];
683
+ }
684
+ interface BundleResolveOptions {
685
+ runId?: string;
686
+ sessionId?: string;
687
+ since?: string;
688
+ }
689
+ interface BundleResolveResult {
690
+ runIds: string[];
691
+ sessionId?: string;
692
+ since?: string;
693
+ }
694
+ interface BundlePlaceholderArtifact {
695
+ status: "not_requested";
696
+ note: string;
697
+ }
698
+
699
+ /**
700
+ * Resolves which run ids belong in a bundle.
701
+ *
702
+ * @throws when target mode is missing, ambiguous, or yields zero runs.
703
+ */
704
+ declare function resolveBundleRunIds(index: SessionIndex, runs: readonly SessionRunRecord[], options: BundleResolveOptions): BundleResolveResult;
705
+
706
+ declare function buildBundleMetadata(parts: {
707
+ agentInspectVersion: string;
708
+ profile: BundleRedactionProfile;
709
+ resolve: BundleResolveResult;
710
+ checks: BundleCheckResults;
711
+ files: string[];
712
+ createdAt?: string;
713
+ }): BundleMetadata;
714
+ declare function buildPlaceholderArtifact(): BundlePlaceholderArtifact;
715
+
716
+ /**
717
+ * Builds a human-readable bundle summary for `summary.md`.
718
+ */
719
+ declare function buildBundleSummaryMarkdown(parts: {
720
+ metadata: BundleMetadata;
721
+ checks: BundleCheckResults;
722
+ redaction: BundleRedactionReport;
723
+ }): string;
724
+
725
+ declare function aggregateBundleSafeStatus(statuses: readonly BundleSafeStatus[]): BundleSafeStatus;
726
+ declare function toMetadataSafeStatus(status: BundleSafeStatus): BundleSafeStatusMetadata;
727
+ declare function bundleFailsOnSafety(status: BundleSafeStatus, allowUnsafe: boolean): boolean;
728
+
729
+ /**
730
+ * Normalizes bundle output path. Strips a `.zip` suffix (folder-first MVP).
731
+ */
732
+ declare function normalizeBundleOutputPath(out: string): string;
733
+ /**
734
+ * Default bundle directory when --out is omitted.
735
+ */
736
+ declare function defaultBundleOutputPath(runIds: readonly string[]): string;
737
+
738
+ export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type BundleCheckResults, type BundleCheckRunResult, type BundleMetadata, type BundlePlaceholderArtifact, type BundleRedactionProfile, type BundleRedactionReport, type BundleRedactionReportRun, type BundleResolveOptions, type BundleResolveResult, type BundleSafeStatus, type BundleSafeStatusMetadata, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateBundleSafeStatus, aggregateSessionCheckResults, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, bundleFailsOnSafety, createRunId, createStepId, defaultBundleOutputPath, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, normalizeBundleOutputPath, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveBundleRunIds, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, toMetadataSafeStatus, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
@@ -643,4 +643,96 @@ declare function isAgentInspectTrace(filePath: string): Promise<boolean>;
643
643
  */
644
644
  declare function parseDuration(duration: string): number;
645
645
 
646
- export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, createRunId, createStepId, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
646
+ /** Aggregate verify-safe status for a bundle. */
647
+ type BundleSafeStatus = "SAFE" | "SAFE WITH WARNINGS" | "UNSAFE" | "UNKNOWN";
648
+ /** Metadata-safe status (underscore form). */
649
+ type BundleSafeStatusMetadata = "SAFE" | "SAFE_WITH_WARNINGS" | "UNSAFE" | "UNKNOWN";
650
+ type BundleRedactionProfile = "local" | "share" | "strict";
651
+ interface BundleMetadata {
652
+ createdAt: string;
653
+ agentInspectVersion: string;
654
+ redactionProfile: BundleRedactionProfile;
655
+ sourceTraceCount: number;
656
+ runIds: string[];
657
+ safeStatus: BundleSafeStatusMetadata;
658
+ files: string[];
659
+ note: string;
660
+ sessionId?: string;
661
+ since?: string;
662
+ }
663
+ interface BundleRedactionReportRun {
664
+ runId: string;
665
+ findings: number;
666
+ detectors: string[];
667
+ }
668
+ interface BundleRedactionReport {
669
+ profile: BundleRedactionProfile;
670
+ totalFindings: number;
671
+ runs: BundleRedactionReportRun[];
672
+ }
673
+ interface BundleCheckRunResult {
674
+ runId: string;
675
+ status: BundleSafeStatus;
676
+ errors: number;
677
+ warnings: number;
678
+ findings: number;
679
+ }
680
+ interface BundleCheckResults {
681
+ aggregateStatus: BundleSafeStatus;
682
+ runs: BundleCheckRunResult[];
683
+ }
684
+ interface BundleResolveOptions {
685
+ runId?: string;
686
+ sessionId?: string;
687
+ since?: string;
688
+ }
689
+ interface BundleResolveResult {
690
+ runIds: string[];
691
+ sessionId?: string;
692
+ since?: string;
693
+ }
694
+ interface BundlePlaceholderArtifact {
695
+ status: "not_requested";
696
+ note: string;
697
+ }
698
+
699
+ /**
700
+ * Resolves which run ids belong in a bundle.
701
+ *
702
+ * @throws when target mode is missing, ambiguous, or yields zero runs.
703
+ */
704
+ declare function resolveBundleRunIds(index: SessionIndex, runs: readonly SessionRunRecord[], options: BundleResolveOptions): BundleResolveResult;
705
+
706
+ declare function buildBundleMetadata(parts: {
707
+ agentInspectVersion: string;
708
+ profile: BundleRedactionProfile;
709
+ resolve: BundleResolveResult;
710
+ checks: BundleCheckResults;
711
+ files: string[];
712
+ createdAt?: string;
713
+ }): BundleMetadata;
714
+ declare function buildPlaceholderArtifact(): BundlePlaceholderArtifact;
715
+
716
+ /**
717
+ * Builds a human-readable bundle summary for `summary.md`.
718
+ */
719
+ declare function buildBundleSummaryMarkdown(parts: {
720
+ metadata: BundleMetadata;
721
+ checks: BundleCheckResults;
722
+ redaction: BundleRedactionReport;
723
+ }): string;
724
+
725
+ declare function aggregateBundleSafeStatus(statuses: readonly BundleSafeStatus[]): BundleSafeStatus;
726
+ declare function toMetadataSafeStatus(status: BundleSafeStatus): BundleSafeStatusMetadata;
727
+ declare function bundleFailsOnSafety(status: BundleSafeStatus, allowUnsafe: boolean): boolean;
728
+
729
+ /**
730
+ * Normalizes bundle output path. Strips a `.zip` suffix (folder-first MVP).
731
+ */
732
+ declare function normalizeBundleOutputPath(out: string): string;
733
+ /**
734
+ * Default bundle directory when --out is omitted.
735
+ */
736
+ declare function defaultBundleOutputPath(runIds: readonly string[]): string;
737
+
738
+ export { type ActivityEntry, type ActivitySummary, type BuildActivitySummaryOptions, type BuildSessionIndexOptions, type BundleCheckResults, type BundleCheckRunResult, type BundleMetadata, type BundlePlaceholderArtifact, type BundleRedactionProfile, type BundleRedactionReport, type BundleRedactionReportRun, type BundleResolveOptions, type BundleResolveResult, type BundleSafeStatus, type BundleSafeStatusMetadata, type CriticalPathStep, DEFAULT_TRACE_DIR_NAME, type DurationStats, type EnrichSessionSummaryOptions, ErrorInfo, type ExplainFact, type ExplainInference, type ExplainMode, type ExplainOptions, type ExplainResult, FALLBACK_TRACE_DIR, type GroupSessionCohortsOptions, type HandoffEdge, InspectRunTree, MAX_NAME_LENGTH, MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, type ParseTraceJsonlOptions, type ParseTraceJsonlResult, type ParsedDurationFilter, RUNS_DIR_NAME, RedactionProfile, type RenderTimelineOptions, type RenderWhatOptions, type ResolvedRedactionProfile, type RetryLink, RunStatus, RunSummary, type RunTimeline, type RunWhatSummary, SESSION_WORKFLOW_KEYS, type SessionCheckSummary, type SessionCohort, type SessionCohortKind, type SessionConfidence, type SessionEdgeSource, type SessionGroup, type SessionIndex, type SessionLastError, type SessionRunRecord, type SessionScopeOptions, type SessionScopeResult, type SessionStatus, type SessionSummary, type SessionWarning, type SessionWorkflowKey, type SessionWorkflowMetadata, StepStatus, StepType, TERMINAL_INDENT, type TimelineEntry, type TimelineFocus, type TimelineOptions, TraceCorrelationMetadata, TraceDirectory, type TraceDirectoryOptions, TraceEvent, type TraceFilterOptions, type TraceJsonlFormat, TraceMetadata, TraceMetadataStatus, type TraceSearchOptions, type TraceSearchResult, type TraceSessionCheckResult, type TraceStats, type TraceStatsOptions, type TraceStatsRankedRun, type TraceStatsRankedStep, aggregateBundleSafeStatus, aggregateSessionCheckResults, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildSessionIndex, buildTraceStats, bundleFailsOnSafety, createRunId, createStepId, defaultBundleOutputPath, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, ensureTraceDir, extractMetadata, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, formatDuration, formatError, formatTerminalName, formatTimestamp, getDefaultTraceDir, getIndent, getRunIdFromTraceFileName, getTraceFilePath, groupSessionCohorts, initializeTraceFile, isAgentInspectTrace, listTraceFiles, loadSessionRunRecords, loadTraceMetadataList, normalizeBundleOutputPath, parseDuration, parseDurationFilter, parseTraceJsonl, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, readTraceEvents, readTraceFile, renderActivitySummaryHuman, renderErrorLine, renderRunSummary, renderRunWhat, renderStepLine, renderTimeline, renderTraceStats, resolveBundleRunIds, resolveRedactionProfile, resolveTraceDir, searchTraces, serializeEvent, sessionKeyForRun, toMetadataSafeStatus, traceMetasToSessionRunRecords, truncateName, unknownTraceFormatMessage, validateEvent, warn, writeTraceEvent };
@@ -14,6 +14,7 @@ import './chunk-IZBJAZGF.mjs';
14
14
  import './chunk-7TGZLWEE.mjs';
15
15
  import { createReadStream } from 'fs';
16
16
  import { createInterface } from 'readline';
17
+ import path from 'path';
17
18
 
18
19
  // packages/core/src/trace-filter.ts
19
20
  function toLower(s) {
@@ -1300,12 +1301,12 @@ function buildCriticalPath(runs, handoffs) {
1300
1301
  handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
1301
1302
  );
1302
1303
  const ordered = [...runs].sort(compareRuns);
1303
- const path = [];
1304
+ const path2 = [];
1304
1305
  const visited = /* @__PURE__ */ new Set();
1305
1306
  const pushRun = (run, confidence, source) => {
1306
1307
  if (visited.has(run.runId)) return;
1307
1308
  visited.add(run.runId);
1308
- path.push({
1309
+ path2.push({
1309
1310
  runId: run.runId,
1310
1311
  name: run.name,
1311
1312
  startedAt: run.startedAt,
@@ -1330,7 +1331,7 @@ function buildCriticalPath(runs, handoffs) {
1330
1331
  const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
1331
1332
  pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
1332
1333
  }
1333
- return path;
1334
+ return path2;
1334
1335
  }
1335
1336
  function metaRunIdMatches(run, token, runById) {
1336
1337
  const meta = extractSessionWorkflowMetadata(run.metadata);
@@ -1450,6 +1451,190 @@ async function isAgentInspectTrace(filePath) {
1450
1451
  }
1451
1452
  }
1452
1453
 
1453
- export { SESSION_WORKFLOW_KEYS, aggregateSessionCheckResults, buildActivitySummary, buildLocalExplanation, buildSessionIndex, buildTraceStats, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, groupSessionCohorts, isAgentInspectTrace, loadSessionRunRecords, loadTraceMetadataList, parseDurationFilter, renderActivitySummaryHuman, renderTraceStats, searchTraces, sessionKeyForRun, traceMetasToSessionRunRecords };
1454
+ // packages/core/src/bundle/resolve.ts
1455
+ function parseSinceCutoff(since) {
1456
+ const trimmed = since.trim();
1457
+ if (trimmed === "") {
1458
+ throw new Error("--since requires a non-empty duration (e.g. 24h, 7d).");
1459
+ }
1460
+ return Date.now() - parseDuration(trimmed);
1461
+ }
1462
+ function runActivityMs(run) {
1463
+ if (run.startedAt !== void 0 && Number.isFinite(run.startedAt)) return run.startedAt;
1464
+ if (run.endedAt !== void 0 && Number.isFinite(run.endedAt)) return run.endedAt;
1465
+ return void 0;
1466
+ }
1467
+ function runsInSinceWindow(runs, since) {
1468
+ const cutoff = parseSinceCutoff(since);
1469
+ const ids = [];
1470
+ for (const run of runs) {
1471
+ const activity = runActivityMs(run);
1472
+ if (activity !== void 0 && activity >= cutoff) {
1473
+ ids.push(run.runId);
1474
+ }
1475
+ }
1476
+ return ids.sort((a, b) => a.localeCompare(b));
1477
+ }
1478
+ function findSession(index, sessionId) {
1479
+ return index.sessions.find((session) => session.sessionId === sessionId);
1480
+ }
1481
+ function resolveBundleRunIds(index, runs, options) {
1482
+ const runId = options.runId?.trim();
1483
+ const sessionId = options.sessionId?.trim();
1484
+ const since = options.since?.trim();
1485
+ const modes = [runId ? 1 : 0, sessionId ? 1 : 0, since ? 1 : 0].reduce((a, b) => a + b, 0);
1486
+ if (modes === 0) {
1487
+ throw new Error(
1488
+ "bundle requires a run id, --session <sessionId>, or --since <duration>."
1489
+ );
1490
+ }
1491
+ if (modes > 1) {
1492
+ throw new Error(
1493
+ "bundle accepts only one target: a run id, --session, or --since (not combined)."
1494
+ );
1495
+ }
1496
+ if (runId) {
1497
+ const known = runs.some((run) => run.runId === runId);
1498
+ if (!known) {
1499
+ throw new Error(`Run "${runId}" was not found in the trace directory.`);
1500
+ }
1501
+ return { runIds: [runId] };
1502
+ }
1503
+ if (sessionId) {
1504
+ const session = findSession(index, sessionId);
1505
+ if (!session) {
1506
+ throw new Error(`Session "${sessionId}" was not found.`);
1507
+ }
1508
+ if (session.runIds.length === 0) {
1509
+ throw new Error(`Session "${sessionId}" has no runs to bundle.`);
1510
+ }
1511
+ return {
1512
+ runIds: [...session.runIds].sort((a, b) => a.localeCompare(b)),
1513
+ sessionId
1514
+ };
1515
+ }
1516
+ const runIds = runsInSinceWindow(runs, since);
1517
+ if (runIds.length === 0) {
1518
+ throw new Error(`No runs matched --since ${since}.`);
1519
+ }
1520
+ return { runIds, since };
1521
+ }
1522
+
1523
+ // packages/core/src/bundle/safety-status.ts
1524
+ function aggregateBundleSafeStatus(statuses) {
1525
+ if (statuses.length === 0) return "UNKNOWN";
1526
+ if (statuses.some((status) => status === "UNSAFE")) return "UNSAFE";
1527
+ if (statuses.some((status) => status === "UNKNOWN")) return "UNKNOWN";
1528
+ if (statuses.some((status) => status === "SAFE WITH WARNINGS")) return "SAFE WITH WARNINGS";
1529
+ return "SAFE";
1530
+ }
1531
+ function toMetadataSafeStatus(status) {
1532
+ if (status === "SAFE WITH WARNINGS") return "SAFE_WITH_WARNINGS";
1533
+ return status;
1534
+ }
1535
+ function bundleFailsOnSafety(status, allowUnsafe) {
1536
+ if (allowUnsafe) return false;
1537
+ return status === "UNSAFE" || status === "UNKNOWN";
1538
+ }
1539
+
1540
+ // packages/core/src/bundle/manifest.ts
1541
+ var BUNDLE_NOTE = "Generated locally by AgentInspect. Bundles are derived copies for review \u2014 not compliance or security certification. Review before sharing.";
1542
+ var PLACEHOLDER_NOTE = "No eval or performance artifacts were requested for this bundle.";
1543
+ function buildBundleMetadata(parts) {
1544
+ const aggregate = aggregateBundleSafeStatus(
1545
+ parts.checks.runs.map((run) => run.status)
1546
+ );
1547
+ return {
1548
+ createdAt: parts.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
1549
+ agentInspectVersion: parts.agentInspectVersion,
1550
+ redactionProfile: parts.profile,
1551
+ sourceTraceCount: parts.resolve.runIds.length,
1552
+ runIds: [...parts.resolve.runIds],
1553
+ safeStatus: toMetadataSafeStatus(aggregate),
1554
+ files: [...parts.files].sort((a, b) => a.localeCompare(b)),
1555
+ note: BUNDLE_NOTE,
1556
+ ...parts.resolve.sessionId !== void 0 ? { sessionId: parts.resolve.sessionId } : {},
1557
+ ...parts.resolve.since !== void 0 ? { since: parts.resolve.since } : {}
1558
+ };
1559
+ }
1560
+ function buildPlaceholderArtifact() {
1561
+ return {
1562
+ status: "not_requested",
1563
+ note: PLACEHOLDER_NOTE
1564
+ };
1565
+ }
1566
+
1567
+ // packages/core/src/bundle/summary.ts
1568
+ function markdownTable(rows) {
1569
+ const lines = ["| Field | Value |", "| --- | --- |"];
1570
+ for (const [key, value] of rows) {
1571
+ lines.push(`| ${key} | ${value ?? "unknown"} |`);
1572
+ }
1573
+ return lines.join("\n");
1574
+ }
1575
+ function buildBundleSummaryMarkdown(parts) {
1576
+ const { metadata, checks, redaction } = parts;
1577
+ const lines = [
1578
+ "# AgentInspect trace bundle",
1579
+ "",
1580
+ metadata.note,
1581
+ "",
1582
+ "## Overview",
1583
+ "",
1584
+ markdownTable([
1585
+ ["Created", metadata.createdAt],
1586
+ ["AgentInspect", metadata.agentInspectVersion],
1587
+ ["Redaction profile", metadata.redactionProfile],
1588
+ ["Safe status", metadata.safeStatus],
1589
+ ["Source traces", metadata.sourceTraceCount],
1590
+ ["Runs", metadata.runIds.join(", ")],
1591
+ ...metadata.sessionId ? [["Session", metadata.sessionId]] : [],
1592
+ ...metadata.since ? [["Since", metadata.since]] : []
1593
+ ]),
1594
+ "",
1595
+ "## Safety checks",
1596
+ "",
1597
+ `Aggregate: **${checks.aggregateStatus}**`,
1598
+ ""
1599
+ ];
1600
+ for (const run of checks.runs) {
1601
+ lines.push(
1602
+ `- \`${run.runId}\`: ${run.status} (${run.findings} finding(s), ${run.errors} error(s), ${run.warnings} warning(s))`
1603
+ );
1604
+ }
1605
+ lines.push("", "## Redaction", "", `Total findings: ${redaction.totalFindings}`, "");
1606
+ for (const run of redaction.runs) {
1607
+ const detectors = run.detectors.length > 0 ? run.detectors.join(", ") : "none";
1608
+ lines.push(`- \`${run.runId}\`: ${run.findings} finding(s); detectors: ${detectors}`);
1609
+ }
1610
+ lines.push(
1611
+ "",
1612
+ "## Files",
1613
+ "",
1614
+ ...metadata.files.map((file) => `- \`${file}\``),
1615
+ "",
1616
+ "_Review every generated artifact before sharing outside your team._",
1617
+ ""
1618
+ );
1619
+ return lines.join("\n");
1620
+ }
1621
+ function normalizeBundleOutputPath(out) {
1622
+ const trimmed = out.trim();
1623
+ if (trimmed === "") {
1624
+ throw new Error("--out requires a non-empty path.");
1625
+ }
1626
+ const resolved = path.resolve(trimmed);
1627
+ if (resolved.toLowerCase().endsWith(".zip")) {
1628
+ return resolved.slice(0, -4);
1629
+ }
1630
+ return resolved;
1631
+ }
1632
+ function defaultBundleOutputPath(runIds) {
1633
+ const label = runIds.length === 1 ? runIds[0] : `multi-${runIds.length}`;
1634
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
1635
+ return path.resolve(`agent-inspect-bundle-${label}-${stamp}`);
1636
+ }
1637
+
1638
+ export { SESSION_WORKFLOW_KEYS, aggregateBundleSafeStatus, aggregateSessionCheckResults, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildSessionIndex, buildTraceStats, bundleFailsOnSafety, defaultBundleOutputPath, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, filterTraces, groupSessionCohorts, isAgentInspectTrace, loadSessionRunRecords, loadTraceMetadataList, normalizeBundleOutputPath, parseDurationFilter, renderActivitySummaryHuman, renderTraceStats, resolveBundleRunIds, searchTraces, sessionKeyForRun, toMetadataSafeStatus, traceMetasToSessionRunRecords };
1454
1639
  //# sourceMappingURL=advanced.mjs.map
1455
1640
  //# sourceMappingURL=advanced.mjs.map