agent-inspect 4.1.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.
- package/CHANGELOG.md +18 -0
- package/docs/CLI.md +50 -6
- package/package.json +1 -1
- package/packages/cli/dist/{chunk-MT5G7JFO.mjs → chunk-BS5LSKZ3.mjs} +451 -14
- package/packages/cli/dist/chunk-BS5LSKZ3.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +2662 -1561
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +2118 -1510
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-DUGEOAZ7.mjs → src-YFMPWEIS.mjs} +3 -3
- package/packages/cli/dist/{src-DUGEOAZ7.mjs.map → src-YFMPWEIS.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +461 -11
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.d.cts +171 -1
- package/packages/core/dist/advanced.d.ts +171 -1
- package/packages/core/dist/advanced.mjs +450 -12
- package/packages/core/dist/advanced.mjs.map +1 -1
- package/packages/cli/dist/chunk-MT5G7JFO.mjs.map +0 -1
|
@@ -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) {
|
|
@@ -644,6 +645,252 @@ function sessionKeyForRun(meta, options) {
|
|
|
644
645
|
return void 0;
|
|
645
646
|
}
|
|
646
647
|
|
|
648
|
+
// packages/core/src/sessions/status.ts
|
|
649
|
+
var DEFAULT_STALE_THRESHOLD_MS = 864e5;
|
|
650
|
+
var EXPLICIT_STATUS_PRIORITY = {
|
|
651
|
+
error: 5,
|
|
652
|
+
waiting_input: 4,
|
|
653
|
+
idle: 3,
|
|
654
|
+
stale: 2,
|
|
655
|
+
completed: 1
|
|
656
|
+
};
|
|
657
|
+
var EXPLICIT_SESSION_STATUSES = /* @__PURE__ */ new Set([
|
|
658
|
+
"running",
|
|
659
|
+
"waiting_input",
|
|
660
|
+
"idle",
|
|
661
|
+
"completed",
|
|
662
|
+
"error",
|
|
663
|
+
"stale",
|
|
664
|
+
"unknown"
|
|
665
|
+
]);
|
|
666
|
+
function isExplicitSessionStatus(value) {
|
|
667
|
+
return typeof value === "string" && EXPLICIT_SESSION_STATUSES.has(value);
|
|
668
|
+
}
|
|
669
|
+
function activityMs(run) {
|
|
670
|
+
return run.endedAt ?? run.startedAt ?? 0;
|
|
671
|
+
}
|
|
672
|
+
function latestActivityMs(runs) {
|
|
673
|
+
let latest = 0;
|
|
674
|
+
for (const run of runs) {
|
|
675
|
+
const ms = activityMs(run);
|
|
676
|
+
if (ms > latest) latest = ms;
|
|
677
|
+
}
|
|
678
|
+
return latest;
|
|
679
|
+
}
|
|
680
|
+
function earliestStart(runs) {
|
|
681
|
+
let earliest;
|
|
682
|
+
for (const run of runs) {
|
|
683
|
+
if (run.startedAt === void 0) continue;
|
|
684
|
+
if (earliest === void 0 || run.startedAt < earliest) {
|
|
685
|
+
earliest = run.startedAt;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return earliest;
|
|
689
|
+
}
|
|
690
|
+
function latestEndWhenAllEnded(runs) {
|
|
691
|
+
if (runs.length === 0) return void 0;
|
|
692
|
+
let latest;
|
|
693
|
+
for (const run of runs) {
|
|
694
|
+
if (run.endedAt === void 0) return void 0;
|
|
695
|
+
if (latest === void 0 || run.endedAt > latest) latest = run.endedAt;
|
|
696
|
+
}
|
|
697
|
+
return latest;
|
|
698
|
+
}
|
|
699
|
+
function pickExplicitStatus(runs) {
|
|
700
|
+
let best;
|
|
701
|
+
let bestPriority = 0;
|
|
702
|
+
for (const run of runs) {
|
|
703
|
+
const raw = run.metadata?.sessionStatus;
|
|
704
|
+
if (!isExplicitSessionStatus(raw)) continue;
|
|
705
|
+
const priority = EXPLICIT_STATUS_PRIORITY[raw] ?? 0;
|
|
706
|
+
if (priority > bestPriority) {
|
|
707
|
+
bestPriority = priority;
|
|
708
|
+
best = raw;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return best;
|
|
712
|
+
}
|
|
713
|
+
function deriveLastError(runs) {
|
|
714
|
+
const errorRuns = runs.filter((run) => run.status === "error").sort((a, b) => activityMs(b) - activityMs(a));
|
|
715
|
+
const latest = errorRuns[0];
|
|
716
|
+
if (!latest) return void 0;
|
|
717
|
+
const meta = latest.metadata ?? {};
|
|
718
|
+
const message = typeof meta.errorMessage === "string" && meta.errorMessage.trim() !== "" ? meta.errorMessage.trim() : latest.name ?? latest.runId;
|
|
719
|
+
const code = typeof meta.errorCode === "string" && meta.errorCode.trim() !== "" ? meta.errorCode.trim() : void 0;
|
|
720
|
+
return { runId: latest.runId, message, code };
|
|
721
|
+
}
|
|
722
|
+
function deriveCheckSummary(runs) {
|
|
723
|
+
let pass = 0;
|
|
724
|
+
let fail = 0;
|
|
725
|
+
let warn2 = 0;
|
|
726
|
+
let found = false;
|
|
727
|
+
for (const run of runs) {
|
|
728
|
+
const summary = run.metadata?.checkSummary;
|
|
729
|
+
if (!summary || typeof summary !== "object") continue;
|
|
730
|
+
const record = summary;
|
|
731
|
+
if (typeof record.pass === "number") {
|
|
732
|
+
pass += record.pass;
|
|
733
|
+
found = true;
|
|
734
|
+
}
|
|
735
|
+
if (typeof record.fail === "number") {
|
|
736
|
+
fail += record.fail;
|
|
737
|
+
found = true;
|
|
738
|
+
}
|
|
739
|
+
if (typeof record.warn === "number") {
|
|
740
|
+
warn2 += record.warn;
|
|
741
|
+
found = true;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return found ? { pass, fail, warn: warn2 } : void 0;
|
|
745
|
+
}
|
|
746
|
+
function deriveObservationSummary(runs) {
|
|
747
|
+
for (const run of [...runs].sort((a, b) => activityMs(b) - activityMs(a))) {
|
|
748
|
+
const value = run.metadata?.observationSummary;
|
|
749
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
750
|
+
return value.trim();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
function deriveSessionStatus(runs, options = {}) {
|
|
756
|
+
if (runs.length === 0) return "unknown";
|
|
757
|
+
if (runs.some((run) => run.status === "running")) return "running";
|
|
758
|
+
const explicit = pickExplicitStatus(runs);
|
|
759
|
+
if (explicit && explicit !== "running") return explicit;
|
|
760
|
+
if (runs.some((run) => run.status === "error")) return "error";
|
|
761
|
+
if (runs.every((run) => run.status === "success")) return "completed";
|
|
762
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
763
|
+
const staleThresholdMs = options.staleThresholdMs ?? DEFAULT_STALE_THRESHOLD_MS;
|
|
764
|
+
const lastMs = latestActivityMs(runs);
|
|
765
|
+
if (lastMs > 0 && nowMs - lastMs > staleThresholdMs) return "stale";
|
|
766
|
+
return "unknown";
|
|
767
|
+
}
|
|
768
|
+
function enrichSessionSummary(summary, runs, options = {}) {
|
|
769
|
+
const sessionRuns = runs.filter((run) => summary.runIds.includes(run.runId)).sort((a, b) => a.runId.localeCompare(b.runId));
|
|
770
|
+
const startedAt = earliestStart(sessionRuns);
|
|
771
|
+
const endedAt = latestEndWhenAllEnded(sessionRuns);
|
|
772
|
+
const durationMs = startedAt !== void 0 && endedAt !== void 0 ? endedAt - startedAt : void 0;
|
|
773
|
+
let correlationId;
|
|
774
|
+
let jobId;
|
|
775
|
+
let workflowId;
|
|
776
|
+
for (const run of sessionRuns) {
|
|
777
|
+
const meta = extractSessionWorkflowMetadata(run.metadata);
|
|
778
|
+
if (!correlationId && meta?.correlationId) correlationId = meta.correlationId;
|
|
779
|
+
if (!jobId && meta?.jobId) jobId = meta.jobId;
|
|
780
|
+
if (!workflowId && meta?.workflowName) workflowId = meta.workflowName;
|
|
781
|
+
else if (!workflowId && meta?.workflowStep) workflowId = meta.workflowStep;
|
|
782
|
+
}
|
|
783
|
+
const lastMs = latestActivityMs(sessionRuns);
|
|
784
|
+
const lastActivity = lastMs > 0 ? new Date(lastMs).toISOString() : (/* @__PURE__ */ new Date(0)).toISOString();
|
|
785
|
+
const retryCount = summary.retries.filter(
|
|
786
|
+
(retry) => retry.retryOf !== void 0 || (retry.attempt ?? 0) > 1
|
|
787
|
+
).length;
|
|
788
|
+
return {
|
|
789
|
+
...summary,
|
|
790
|
+
status: deriveSessionStatus(sessionRuns, options),
|
|
791
|
+
startedAt,
|
|
792
|
+
endedAt,
|
|
793
|
+
durationMs,
|
|
794
|
+
correlationId,
|
|
795
|
+
jobId,
|
|
796
|
+
workflowId,
|
|
797
|
+
lastError: deriveLastError(sessionRuns),
|
|
798
|
+
lastActivity,
|
|
799
|
+
retryCount,
|
|
800
|
+
observationSummary: deriveObservationSummary(sessionRuns),
|
|
801
|
+
checkSummary: deriveCheckSummary(sessionRuns)
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// packages/core/src/sessions/activity.ts
|
|
806
|
+
function statusLine(session) {
|
|
807
|
+
const name = session.workflowId ?? session.correlationId ?? session.sessionId;
|
|
808
|
+
const status = session.status;
|
|
809
|
+
if (session.lastError) {
|
|
810
|
+
return `${name} session ${session.sessionId} failed at ${session.lastError.message}`;
|
|
811
|
+
}
|
|
812
|
+
if (session.observationSummary) {
|
|
813
|
+
return `${name} session ${session.sessionId} ${status} with observation warning`;
|
|
814
|
+
}
|
|
815
|
+
return `${name} session ${session.sessionId} ${status}`;
|
|
816
|
+
}
|
|
817
|
+
function parseSinceMs(since, nowMs) {
|
|
818
|
+
if (!since || since.trim() === "") return nowMs - 7 * 864e5;
|
|
819
|
+
const trimmed = since.trim().toLowerCase();
|
|
820
|
+
const match = /^(\d+)([smhd])$/.exec(trimmed);
|
|
821
|
+
if (!match) return nowMs - 7 * 864e5;
|
|
822
|
+
const amount = Number.parseInt(match[1], 10);
|
|
823
|
+
const unit = match[2];
|
|
824
|
+
const mult = unit === "s" ? 1e3 : unit === "m" ? 6e4 : unit === "h" ? 36e5 : 864e5;
|
|
825
|
+
return nowMs - amount * mult;
|
|
826
|
+
}
|
|
827
|
+
function isFailed(status) {
|
|
828
|
+
return status === "error";
|
|
829
|
+
}
|
|
830
|
+
function isStale(status) {
|
|
831
|
+
return status === "stale";
|
|
832
|
+
}
|
|
833
|
+
function guardrailWarnings(session) {
|
|
834
|
+
const summary = session.checkSummary;
|
|
835
|
+
if (!summary) return 0;
|
|
836
|
+
return summary.warn;
|
|
837
|
+
}
|
|
838
|
+
function buildActivitySummary(index, options = {}) {
|
|
839
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
840
|
+
const sinceMs = parseSinceMs(options.since, nowMs);
|
|
841
|
+
const sinceIso = new Date(sinceMs).toISOString();
|
|
842
|
+
const limit = Number.isInteger(options.limit) && options.limit > 0 ? options.limit : 20;
|
|
843
|
+
const inWindow = index.sessions.filter((session) => {
|
|
844
|
+
const activityMs2 = Date.parse(session.lastActivity);
|
|
845
|
+
return Number.isFinite(activityMs2) && activityMs2 >= sinceMs;
|
|
846
|
+
});
|
|
847
|
+
const entries = [...inWindow].sort((a, b) => Date.parse(b.lastActivity) - Date.parse(a.lastActivity)).slice(0, limit).map((session) => ({
|
|
848
|
+
sessionId: session.sessionId,
|
|
849
|
+
status: session.status,
|
|
850
|
+
summary: statusLine(session),
|
|
851
|
+
lastActivity: session.lastActivity,
|
|
852
|
+
runCount: session.runIds.length
|
|
853
|
+
}));
|
|
854
|
+
let failed = 0;
|
|
855
|
+
let stale = 0;
|
|
856
|
+
let guardrailWarningTotal = 0;
|
|
857
|
+
for (const session of inWindow) {
|
|
858
|
+
if (isFailed(session.status)) failed += 1;
|
|
859
|
+
if (isStale(session.status)) stale += 1;
|
|
860
|
+
guardrailWarningTotal += guardrailWarnings(session);
|
|
861
|
+
}
|
|
862
|
+
return {
|
|
863
|
+
since: sinceIso,
|
|
864
|
+
sessions: inWindow.length,
|
|
865
|
+
failed,
|
|
866
|
+
stale,
|
|
867
|
+
guardrailWarnings: guardrailWarningTotal,
|
|
868
|
+
entries
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function renderActivitySummaryHuman(summary) {
|
|
872
|
+
const lines = [];
|
|
873
|
+
const todayStart = /* @__PURE__ */ new Date();
|
|
874
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
875
|
+
const todayMs = todayStart.getTime();
|
|
876
|
+
const today = summary.entries.filter(
|
|
877
|
+
(entry) => Date.parse(entry.lastActivity) >= todayMs
|
|
878
|
+
);
|
|
879
|
+
if (today.length > 0) {
|
|
880
|
+
lines.push("Today");
|
|
881
|
+
for (const entry of today) {
|
|
882
|
+
lines.push(` ${entry.summary}`);
|
|
883
|
+
}
|
|
884
|
+
lines.push("");
|
|
885
|
+
}
|
|
886
|
+
lines.push(`Since ${summary.since}`);
|
|
887
|
+
lines.push(` ${summary.sessions} sessions`);
|
|
888
|
+
lines.push(` ${summary.failed} failed`);
|
|
889
|
+
lines.push(` ${summary.stale} stale`);
|
|
890
|
+
lines.push(` ${summary.guardrailWarnings} guardrail warnings`);
|
|
891
|
+
return lines.join("\n");
|
|
892
|
+
}
|
|
893
|
+
|
|
647
894
|
// packages/core/src/sessions/types.ts
|
|
648
895
|
var SESSION_WORKFLOW_KEYS = [
|
|
649
896
|
"sessionId",
|
|
@@ -1054,12 +1301,12 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1054
1301
|
handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
|
|
1055
1302
|
);
|
|
1056
1303
|
const ordered = [...runs].sort(compareRuns);
|
|
1057
|
-
const
|
|
1304
|
+
const path2 = [];
|
|
1058
1305
|
const visited = /* @__PURE__ */ new Set();
|
|
1059
1306
|
const pushRun = (run, confidence, source) => {
|
|
1060
1307
|
if (visited.has(run.runId)) return;
|
|
1061
1308
|
visited.add(run.runId);
|
|
1062
|
-
|
|
1309
|
+
path2.push({
|
|
1063
1310
|
runId: run.runId,
|
|
1064
1311
|
name: run.name,
|
|
1065
1312
|
startedAt: run.startedAt,
|
|
@@ -1084,7 +1331,7 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1084
1331
|
const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
|
|
1085
1332
|
pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
|
|
1086
1333
|
}
|
|
1087
|
-
return
|
|
1334
|
+
return path2;
|
|
1088
1335
|
}
|
|
1089
1336
|
function metaRunIdMatches(run, token, runById) {
|
|
1090
1337
|
const meta = extractSessionWorkflowMetadata(run.metadata);
|
|
@@ -1126,14 +1373,21 @@ function buildSessionIndex(inputRuns, options = {}) {
|
|
|
1126
1373
|
sessionId
|
|
1127
1374
|
});
|
|
1128
1375
|
}
|
|
1129
|
-
return
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1376
|
+
return enrichSessionSummary(
|
|
1377
|
+
{
|
|
1378
|
+
sessionId,
|
|
1379
|
+
runIds,
|
|
1380
|
+
groups,
|
|
1381
|
+
handoffs,
|
|
1382
|
+
retries,
|
|
1383
|
+
criticalPath
|
|
1384
|
+
},
|
|
1385
|
+
runs,
|
|
1386
|
+
{
|
|
1387
|
+
nowMs: options.nowMs,
|
|
1388
|
+
staleThresholdMs: options.staleThresholdMs
|
|
1389
|
+
}
|
|
1390
|
+
);
|
|
1137
1391
|
});
|
|
1138
1392
|
if (sessions.length === 0 && runs.length > 0) {
|
|
1139
1393
|
warnings.push({
|
|
@@ -1197,6 +1451,190 @@ async function isAgentInspectTrace(filePath) {
|
|
|
1197
1451
|
}
|
|
1198
1452
|
}
|
|
1199
1453
|
|
|
1200
|
-
|
|
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 };
|
|
1201
1639
|
//# sourceMappingURL=advanced.mjs.map
|
|
1202
1640
|
//# sourceMappingURL=advanced.mjs.map
|