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.
@@ -4734,12 +4734,12 @@ function buildCriticalPath(runs, handoffs) {
4734
4734
  handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
4735
4735
  );
4736
4736
  const ordered = [...runs].sort(compareRuns);
4737
- const path5 = [];
4737
+ const path6 = [];
4738
4738
  const visited = /* @__PURE__ */ new Set();
4739
4739
  const pushRun = (run, confidence, source) => {
4740
4740
  if (visited.has(run.runId)) return;
4741
4741
  visited.add(run.runId);
4742
- path5.push({
4742
+ path6.push({
4743
4743
  runId: run.runId,
4744
4744
  name: run.name,
4745
4745
  startedAt: run.startedAt,
@@ -4764,7 +4764,7 @@ function buildCriticalPath(runs, handoffs) {
4764
4764
  const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
4765
4765
  pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
4766
4766
  }
4767
- return path5;
4767
+ return path6;
4768
4768
  }
4769
4769
  function metaRunIdMatches(run, token, runById) {
4770
4770
  const meta = extractSessionWorkflowMetadata(run.metadata);
@@ -4884,6 +4884,190 @@ async function isAgentInspectTrace(filePath) {
4884
4884
  }
4885
4885
  }
4886
4886
 
4887
+ // packages/core/src/bundle/resolve.ts
4888
+ function parseSinceCutoff(since) {
4889
+ const trimmed = since.trim();
4890
+ if (trimmed === "") {
4891
+ throw new Error("--since requires a non-empty duration (e.g. 24h, 7d).");
4892
+ }
4893
+ return Date.now() - parseDuration(trimmed);
4894
+ }
4895
+ function runActivityMs(run) {
4896
+ if (run.startedAt !== void 0 && Number.isFinite(run.startedAt)) return run.startedAt;
4897
+ if (run.endedAt !== void 0 && Number.isFinite(run.endedAt)) return run.endedAt;
4898
+ return void 0;
4899
+ }
4900
+ function runsInSinceWindow(runs, since) {
4901
+ const cutoff = parseSinceCutoff(since);
4902
+ const ids = [];
4903
+ for (const run of runs) {
4904
+ const activity = runActivityMs(run);
4905
+ if (activity !== void 0 && activity >= cutoff) {
4906
+ ids.push(run.runId);
4907
+ }
4908
+ }
4909
+ return ids.sort((a, b) => a.localeCompare(b));
4910
+ }
4911
+ function findSession(index, sessionId) {
4912
+ return index.sessions.find((session) => session.sessionId === sessionId);
4913
+ }
4914
+ function resolveBundleRunIds(index, runs, options) {
4915
+ const runId = options.runId?.trim();
4916
+ const sessionId = options.sessionId?.trim();
4917
+ const since = options.since?.trim();
4918
+ const modes = [runId ? 1 : 0, sessionId ? 1 : 0, since ? 1 : 0].reduce((a, b) => a + b, 0);
4919
+ if (modes === 0) {
4920
+ throw new Error(
4921
+ "bundle requires a run id, --session <sessionId>, or --since <duration>."
4922
+ );
4923
+ }
4924
+ if (modes > 1) {
4925
+ throw new Error(
4926
+ "bundle accepts only one target: a run id, --session, or --since (not combined)."
4927
+ );
4928
+ }
4929
+ if (runId) {
4930
+ const known = runs.some((run) => run.runId === runId);
4931
+ if (!known) {
4932
+ throw new Error(`Run "${runId}" was not found in the trace directory.`);
4933
+ }
4934
+ return { runIds: [runId] };
4935
+ }
4936
+ if (sessionId) {
4937
+ const session = findSession(index, sessionId);
4938
+ if (!session) {
4939
+ throw new Error(`Session "${sessionId}" was not found.`);
4940
+ }
4941
+ if (session.runIds.length === 0) {
4942
+ throw new Error(`Session "${sessionId}" has no runs to bundle.`);
4943
+ }
4944
+ return {
4945
+ runIds: [...session.runIds].sort((a, b) => a.localeCompare(b)),
4946
+ sessionId
4947
+ };
4948
+ }
4949
+ const runIds = runsInSinceWindow(runs, since);
4950
+ if (runIds.length === 0) {
4951
+ throw new Error(`No runs matched --since ${since}.`);
4952
+ }
4953
+ return { runIds, since };
4954
+ }
4955
+
4956
+ // packages/core/src/bundle/safety-status.ts
4957
+ function aggregateBundleSafeStatus(statuses) {
4958
+ if (statuses.length === 0) return "UNKNOWN";
4959
+ if (statuses.some((status) => status === "UNSAFE")) return "UNSAFE";
4960
+ if (statuses.some((status) => status === "UNKNOWN")) return "UNKNOWN";
4961
+ if (statuses.some((status) => status === "SAFE WITH WARNINGS")) return "SAFE WITH WARNINGS";
4962
+ return "SAFE";
4963
+ }
4964
+ function toMetadataSafeStatus(status) {
4965
+ if (status === "SAFE WITH WARNINGS") return "SAFE_WITH_WARNINGS";
4966
+ return status;
4967
+ }
4968
+ function bundleFailsOnSafety(status, allowUnsafe) {
4969
+ if (allowUnsafe) return false;
4970
+ return status === "UNSAFE" || status === "UNKNOWN";
4971
+ }
4972
+
4973
+ // packages/core/src/bundle/manifest.ts
4974
+ var BUNDLE_NOTE = "Generated locally by AgentInspect. Bundles are derived copies for review \u2014 not compliance or security certification. Review before sharing.";
4975
+ var PLACEHOLDER_NOTE = "No eval or performance artifacts were requested for this bundle.";
4976
+ function buildBundleMetadata(parts) {
4977
+ const aggregate = aggregateBundleSafeStatus(
4978
+ parts.checks.runs.map((run) => run.status)
4979
+ );
4980
+ return {
4981
+ createdAt: parts.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
4982
+ agentInspectVersion: parts.agentInspectVersion,
4983
+ redactionProfile: parts.profile,
4984
+ sourceTraceCount: parts.resolve.runIds.length,
4985
+ runIds: [...parts.resolve.runIds],
4986
+ safeStatus: toMetadataSafeStatus(aggregate),
4987
+ files: [...parts.files].sort((a, b) => a.localeCompare(b)),
4988
+ note: BUNDLE_NOTE,
4989
+ ...parts.resolve.sessionId !== void 0 ? { sessionId: parts.resolve.sessionId } : {},
4990
+ ...parts.resolve.since !== void 0 ? { since: parts.resolve.since } : {}
4991
+ };
4992
+ }
4993
+ function buildPlaceholderArtifact() {
4994
+ return {
4995
+ status: "not_requested",
4996
+ note: PLACEHOLDER_NOTE
4997
+ };
4998
+ }
4999
+
5000
+ // packages/core/src/bundle/summary.ts
5001
+ function markdownTable(rows) {
5002
+ const lines = ["| Field | Value |", "| --- | --- |"];
5003
+ for (const [key, value] of rows) {
5004
+ lines.push(`| ${key} | ${value ?? "unknown"} |`);
5005
+ }
5006
+ return lines.join("\n");
5007
+ }
5008
+ function buildBundleSummaryMarkdown(parts) {
5009
+ const { metadata, checks, redaction } = parts;
5010
+ const lines = [
5011
+ "# AgentInspect trace bundle",
5012
+ "",
5013
+ metadata.note,
5014
+ "",
5015
+ "## Overview",
5016
+ "",
5017
+ markdownTable([
5018
+ ["Created", metadata.createdAt],
5019
+ ["AgentInspect", metadata.agentInspectVersion],
5020
+ ["Redaction profile", metadata.redactionProfile],
5021
+ ["Safe status", metadata.safeStatus],
5022
+ ["Source traces", metadata.sourceTraceCount],
5023
+ ["Runs", metadata.runIds.join(", ")],
5024
+ ...metadata.sessionId ? [["Session", metadata.sessionId]] : [],
5025
+ ...metadata.since ? [["Since", metadata.since]] : []
5026
+ ]),
5027
+ "",
5028
+ "## Safety checks",
5029
+ "",
5030
+ `Aggregate: **${checks.aggregateStatus}**`,
5031
+ ""
5032
+ ];
5033
+ for (const run of checks.runs) {
5034
+ lines.push(
5035
+ `- \`${run.runId}\`: ${run.status} (${run.findings} finding(s), ${run.errors} error(s), ${run.warnings} warning(s))`
5036
+ );
5037
+ }
5038
+ lines.push("", "## Redaction", "", `Total findings: ${redaction.totalFindings}`, "");
5039
+ for (const run of redaction.runs) {
5040
+ const detectors = run.detectors.length > 0 ? run.detectors.join(", ") : "none";
5041
+ lines.push(`- \`${run.runId}\`: ${run.findings} finding(s); detectors: ${detectors}`);
5042
+ }
5043
+ lines.push(
5044
+ "",
5045
+ "## Files",
5046
+ "",
5047
+ ...metadata.files.map((file) => `- \`${file}\``),
5048
+ "",
5049
+ "_Review every generated artifact before sharing outside your team._",
5050
+ ""
5051
+ );
5052
+ return lines.join("\n");
5053
+ }
5054
+ function normalizeBundleOutputPath(out) {
5055
+ const trimmed = out.trim();
5056
+ if (trimmed === "") {
5057
+ throw new Error("--out requires a non-empty path.");
5058
+ }
5059
+ const resolved = path__default.default.resolve(trimmed);
5060
+ if (resolved.toLowerCase().endsWith(".zip")) {
5061
+ return resolved.slice(0, -4);
5062
+ }
5063
+ return resolved;
5064
+ }
5065
+ function defaultBundleOutputPath(runIds) {
5066
+ const label = runIds.length === 1 ? runIds[0] : `multi-${runIds.length}`;
5067
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
5068
+ return path__default.default.resolve(`agent-inspect-bundle-${label}-${stamp}`);
5069
+ }
5070
+
4887
5071
  // packages/core/src/inspect-run.ts
4888
5072
  function normalizeRunName(name) {
4889
5073
  if (typeof name !== "string" || name.trim() === "") {
@@ -5026,18 +5210,24 @@ exports.RUNS_DIR_NAME = RUNS_DIR_NAME;
5026
5210
  exports.SESSION_WORKFLOW_KEYS = SESSION_WORKFLOW_KEYS;
5027
5211
  exports.TERMINAL_INDENT = TERMINAL_INDENT;
5028
5212
  exports.TraceDirectory = TraceDirectory;
5213
+ exports.aggregateBundleSafeStatus = aggregateBundleSafeStatus;
5029
5214
  exports.aggregateSessionCheckResults = aggregateSessionCheckResults;
5030
5215
  exports.buildActivitySummary = buildActivitySummary;
5216
+ exports.buildBundleMetadata = buildBundleMetadata;
5217
+ exports.buildBundleSummaryMarkdown = buildBundleSummaryMarkdown;
5031
5218
  exports.buildLocalExplanation = buildLocalExplanation;
5219
+ exports.buildPlaceholderArtifact = buildPlaceholderArtifact;
5032
5220
  exports.buildRunSummary = buildRunSummary;
5033
5221
  exports.buildRunTimeline = buildRunTimeline;
5034
5222
  exports.buildRunWhatSummary = buildRunWhatSummary;
5035
5223
  exports.buildSessionIndex = buildSessionIndex;
5036
5224
  exports.buildTraceStats = buildTraceStats;
5225
+ exports.bundleFailsOnSafety = bundleFailsOnSafety;
5037
5226
  exports.createInspector = createInspector;
5038
5227
  exports.createInspectorRuntime = createInspectorRuntime;
5039
5228
  exports.createRunId = createRunId;
5040
5229
  exports.createStepId = createStepId;
5230
+ exports.defaultBundleOutputPath = defaultBundleOutputPath;
5041
5231
  exports.deriveSessionStatus = deriveSessionStatus;
5042
5232
  exports.enrichSessionRunRecord = enrichSessionRunRecord;
5043
5233
  exports.enrichSessionSummary = enrichSessionSummary;
@@ -5076,6 +5266,7 @@ exports.listTraceFiles = listTraceFiles;
5076
5266
  exports.loadSessionRunRecords = loadSessionRunRecords;
5077
5267
  exports.loadTraceMetadataList = loadTraceMetadataList;
5078
5268
  exports.maybeInspectRun = maybeInspectRun;
5269
+ exports.normalizeBundleOutputPath = normalizeBundleOutputPath;
5079
5270
  exports.parseDuration = parseDuration;
5080
5271
  exports.parseDurationFilter = parseDurationFilter;
5081
5272
  exports.parseTraceJsonl = parseTraceJsonl;
@@ -5096,6 +5287,7 @@ exports.renderRunWhat = renderRunWhat;
5096
5287
  exports.renderStepLine = renderStepLine;
5097
5288
  exports.renderTimeline = renderTimeline;
5098
5289
  exports.renderTraceStats = renderTraceStats;
5290
+ exports.resolveBundleRunIds = resolveBundleRunIds;
5099
5291
  exports.resolveRedactionProfile = resolveRedactionProfile;
5100
5292
  exports.resolveTraceDir = resolveTraceDir;
5101
5293
  exports.resolveTraceSafetyOptions = resolveTraceSafetyOptions;
@@ -5104,6 +5296,7 @@ exports.runWithStepContext = runWithStepContext;
5104
5296
  exports.searchTraces = searchTraces;
5105
5297
  exports.serializeEvent = serializeEvent;
5106
5298
  exports.sessionKeyForRun = sessionKeyForRun;
5299
+ exports.toMetadataSafeStatus = toMetadataSafeStatus;
5107
5300
  exports.traceMetasToSessionRunRecords = traceMetasToSessionRunRecords;
5108
5301
  exports.truncateName = truncateName;
5109
5302
  exports.unknownTraceFormatMessage = unknownTraceFormatMessage;