agent-inspect 6.9.0 → 6.10.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 +6 -0
- package/README.md +1 -1
- package/docs/BUNDLES.md +31 -9
- package/docs/CI-ARTIFACTS.md +10 -1
- package/docs/CLI.md +11 -2
- package/package.json +1 -1
- package/packages/cli/dist/{chunk-WQ5XMFH2.mjs → chunk-36IJ76LH.mjs} +1756 -149
- package/packages/cli/dist/chunk-36IJ76LH.mjs.map +1 -0
- package/packages/cli/dist/index.cjs +10370 -8774
- package/packages/cli/dist/index.cjs.map +1 -1
- package/packages/cli/dist/index.mjs +584 -712
- package/packages/cli/dist/index.mjs.map +1 -1
- package/packages/cli/dist/{src-C4EUHTER.mjs → src-YFN3Q3GP.mjs} +3 -3
- package/packages/cli/dist/{src-C4EUHTER.mjs.map → src-YFN3Q3GP.mjs.map} +1 -1
- package/packages/core/dist/advanced.cjs +1703 -12
- package/packages/core/dist/advanced.cjs.map +1 -1
- package/packages/core/dist/advanced.d.cts +334 -3
- package/packages/core/dist/advanced.d.ts +334 -3
- package/packages/core/dist/advanced.mjs +1163 -10
- package/packages/core/dist/advanced.mjs.map +1 -1
- package/packages/core/dist/chunk-F7STQ5JF.mjs +479 -0
- package/packages/core/dist/chunk-F7STQ5JF.mjs.map +1 -0
- package/packages/core/dist/diff.mjs +3 -477
- package/packages/core/dist/diff.mjs.map +1 -1
- package/packages/core/dist/reporters.cjs +25 -0
- package/packages/core/dist/reporters.cjs.map +1 -1
- package/packages/core/dist/reporters.d.cts +16 -2
- package/packages/core/dist/reporters.d.ts +16 -2
- package/packages/core/dist/reporters.mjs +24 -1
- package/packages/core/dist/reporters.mjs.map +1 -1
- package/packages/cli/dist/chunk-WQ5XMFH2.mjs.map +0 -1
|
@@ -2,10 +2,11 @@ import { runTraceChecks, createRunStatusRule, createToolUsageRule, createRunDura
|
|
|
2
2
|
export { MAX_TERMINAL_DEPTH, MAX_TERMINAL_NAME_LENGTH, TERMINAL_INDENT, TraceDirectory, createInspector, createInspectorRuntime, formatTerminalName, getCurrentContext, getCurrentCorrelationMetadata, getCurrentDepth, getCurrentRunId, getCurrentRunName, getCurrentStepId, getIndent, getParentStepId, getTraceDirFromContext, getTraceSafetyFromContext, hasActiveContext, isAgentInspectEnabled, isSilentContext, maybeInspectRun, printError, printFailedAt, printRunComplete, printRunStart, printStepComplete, printStepStart, renderErrorLine, renderRunSummary, renderStepLine, resolveTraceDir, runWithContext, runWithStepContext } from './chunk-ZWA5RWMV.mjs';
|
|
3
3
|
import { filterTraces, extractMetadata, buildRunSummary } from './chunk-KDDU2R5P.mjs';
|
|
4
4
|
export { buildRunSummary, buildRunTimeline, buildRunWhatSummary, buildTraceStats, extractMetadata, filterTraces, renderRunWhat, renderTimeline, renderTraceStats } from './chunk-KDDU2R5P.mjs';
|
|
5
|
-
import { parseObservationFilter, extractOutcomesFromTraceEvents, extractOutcomesFromPersistedEvents } from './chunk-VFO76UH3.mjs';
|
|
5
|
+
import { parseObservationFilter, extractOutcomesFromTraceEvents, summarizeObservedOutcomes, extractOutcomesFromPersistedEvents, renderObservedOutcomesHtml } from './chunk-VFO76UH3.mjs';
|
|
6
6
|
export { extractOutcomesFromPersistedEvents, extractOutcomesFromTraceEvents } from './chunk-VFO76UH3.mjs';
|
|
7
|
+
import { diffTraceEvents, renderRunDiff } from './chunk-F7STQ5JF.mjs';
|
|
7
8
|
import './chunk-BT7CATSD.mjs';
|
|
8
|
-
import { escapeHtml } from './chunk-CAWPF22J.mjs';
|
|
9
|
+
import { escapeHtml, flattenTree } from './chunk-CAWPF22J.mjs';
|
|
9
10
|
import { resolveRedactionProfile, readTraceEventsFromFile } from './chunk-ULCGIRTC.mjs';
|
|
10
11
|
export { DEFAULT_MAX_EVENT_BYTES, DEFAULT_MAX_METADATA_VALUE_LENGTH, DEFAULT_MAX_PREVIEW_LENGTH, getRunIdFromTraceFileName, initializeTraceFile, listTraceFiles, prepareMetadataForDisk, prepareTraceEventForDisk, readTraceEvents, readTraceFile, resolveRedactionProfile, resolveTraceSafetyOptions, serializeEvent, validateEvent, writeTraceEvent } from './chunk-ULCGIRTC.mjs';
|
|
11
12
|
import { Redactor } from './chunk-VU6O5QAH.mjs';
|
|
@@ -15,12 +16,13 @@ import './chunk-S4YWKV4G.mjs';
|
|
|
15
16
|
import './chunk-T5MASTIW.mjs';
|
|
16
17
|
import { parseDuration, isTraceEvent, getTraceFilePath } from './chunk-WRE4CNPF.mjs';
|
|
17
18
|
export { DEFAULT_TRACE_DIR_NAME, FALLBACK_TRACE_DIR, MAX_NAME_LENGTH, RUNS_DIR_NAME, createRunId, createStepId, ensureTraceDir, formatDuration, formatError, formatTimestamp, getDefaultTraceDir, getTraceFilePath, isStepStatus, isStepType, isTraceEvent, parseDuration, parseTraceJsonl, truncateName, unknownTraceFormatMessage, warn } from './chunk-WRE4CNPF.mjs';
|
|
18
|
-
import './chunk-P366CCL2.mjs';
|
|
19
|
+
import { persistedInspectEventsToTraceEvents } from './chunk-P366CCL2.mjs';
|
|
19
20
|
import './chunk-7TGZLWEE.mjs';
|
|
20
21
|
import { createReadStream } from 'fs';
|
|
21
22
|
import { createInterface } from 'readline';
|
|
22
23
|
import path from 'path';
|
|
23
|
-
import {
|
|
24
|
+
import { createHash } from 'crypto';
|
|
25
|
+
import { stat, readFile, access, readdir } from 'fs/promises';
|
|
24
26
|
import { pathToFileURL } from 'url';
|
|
25
27
|
|
|
26
28
|
// packages/core/src/explain.ts
|
|
@@ -1111,12 +1113,12 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1111
1113
|
handoffs.filter((edge) => edge.confidence === "explicit").map((edge) => edge.from)
|
|
1112
1114
|
);
|
|
1113
1115
|
const ordered = [...runs].sort(compareRuns);
|
|
1114
|
-
const
|
|
1116
|
+
const path9 = [];
|
|
1115
1117
|
const visited = /* @__PURE__ */ new Set();
|
|
1116
1118
|
const pushRun = (run, confidence, source) => {
|
|
1117
1119
|
if (visited.has(run.runId)) return;
|
|
1118
1120
|
visited.add(run.runId);
|
|
1119
|
-
|
|
1121
|
+
path9.push({
|
|
1120
1122
|
runId: run.runId,
|
|
1121
1123
|
name: run.name,
|
|
1122
1124
|
startedAt: run.startedAt,
|
|
@@ -1141,7 +1143,7 @@ function buildCriticalPath(runs, handoffs) {
|
|
|
1141
1143
|
const confidence = explicitTargets.has(run.runId) || explicitSources.has(run.runId) ? "explicit" : "correlated";
|
|
1142
1144
|
pushRun(run, confidence, confidence === "explicit" ? "manual" : "inferred");
|
|
1143
1145
|
}
|
|
1144
|
-
return
|
|
1146
|
+
return path9;
|
|
1145
1147
|
}
|
|
1146
1148
|
function metaRunIdMatches(run, token, runById) {
|
|
1147
1149
|
const meta = extractSessionWorkflowMetadata(run.metadata);
|
|
@@ -1451,13 +1453,13 @@ function assertBundlePathContained(outputDir, relativePath) {
|
|
|
1451
1453
|
}
|
|
1452
1454
|
return resolved;
|
|
1453
1455
|
}
|
|
1454
|
-
function normalizeBundleOutputPath(out) {
|
|
1456
|
+
function normalizeBundleOutputPath(out, options) {
|
|
1455
1457
|
const trimmed = out.trim();
|
|
1456
1458
|
if (trimmed === "") {
|
|
1457
1459
|
throw new Error("--out requires a non-empty path.");
|
|
1458
1460
|
}
|
|
1459
1461
|
const resolved = path.resolve(trimmed);
|
|
1460
|
-
if (resolved.toLowerCase().endsWith(".zip")) {
|
|
1462
|
+
if (options?.preserveZipExtension !== true && resolved.toLowerCase().endsWith(".zip")) {
|
|
1461
1463
|
return resolved.slice(0, -4);
|
|
1462
1464
|
}
|
|
1463
1465
|
return resolved;
|
|
@@ -1468,6 +1470,1157 @@ function defaultBundleOutputPath(runIds) {
|
|
|
1468
1470
|
return path.resolve(`agent-inspect-bundle-${label}-${stamp}`);
|
|
1469
1471
|
}
|
|
1470
1472
|
|
|
1473
|
+
// packages/core/src/evidence/types.ts
|
|
1474
|
+
var EVIDENCE_FORMAT_VERSION = "1.0";
|
|
1475
|
+
var EVIDENCE_ASSESSMENT_NOTE = "Best-effort local safety verification only; not a compliance certification.";
|
|
1476
|
+
var EVIDENCE_MANIFEST_FILENAME = "evidence.json";
|
|
1477
|
+
var SHA256_RE = /^[a-f0-9]{64}$/i;
|
|
1478
|
+
function sha256Hex(data) {
|
|
1479
|
+
const hash = createHash("sha256");
|
|
1480
|
+
if (typeof data === "string") {
|
|
1481
|
+
hash.update(data, "utf8");
|
|
1482
|
+
} else {
|
|
1483
|
+
hash.update(data);
|
|
1484
|
+
}
|
|
1485
|
+
return hash.digest("hex");
|
|
1486
|
+
}
|
|
1487
|
+
function isSha256Hex(value) {
|
|
1488
|
+
return SHA256_RE.test(value);
|
|
1489
|
+
}
|
|
1490
|
+
function sha256Equals(expected, actual) {
|
|
1491
|
+
if (!isSha256Hex(expected) || !isSha256Hex(actual)) {
|
|
1492
|
+
return false;
|
|
1493
|
+
}
|
|
1494
|
+
const a = expected.toLowerCase();
|
|
1495
|
+
const b = actual.toLowerCase();
|
|
1496
|
+
if (a.length !== b.length) return false;
|
|
1497
|
+
let mismatch = 0;
|
|
1498
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
1499
|
+
mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1500
|
+
}
|
|
1501
|
+
return mismatch === 0;
|
|
1502
|
+
}
|
|
1503
|
+
function assertEvidenceRelativePath(relativePath) {
|
|
1504
|
+
if (typeof relativePath !== "string" || relativePath.trim() === "") {
|
|
1505
|
+
throw new Error("Evidence file path must be a non-empty relative path.");
|
|
1506
|
+
}
|
|
1507
|
+
const trimmed = relativePath.trim().replaceAll("\\", "/");
|
|
1508
|
+
if (path.isAbsolute(trimmed) || trimmed.startsWith("/")) {
|
|
1509
|
+
throw new Error(`Evidence file path must be relative: ${relativePath}`);
|
|
1510
|
+
}
|
|
1511
|
+
const parts = trimmed.split("/").filter((part) => part !== "");
|
|
1512
|
+
if (parts.length === 0) {
|
|
1513
|
+
throw new Error(`Evidence file path must be relative: ${relativePath}`);
|
|
1514
|
+
}
|
|
1515
|
+
for (const part of parts) {
|
|
1516
|
+
if (part === "." || part === "..") {
|
|
1517
|
+
throw new Error(`Evidence file path must not contain "." or "..": ${relativePath}`);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
return parts.join("/");
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
// packages/core/src/evidence/manifest.ts
|
|
1524
|
+
function stable(value) {
|
|
1525
|
+
if (Array.isArray(value)) return value.map(stable);
|
|
1526
|
+
if (value === null || typeof value !== "object") return value;
|
|
1527
|
+
const record = value;
|
|
1528
|
+
return Object.fromEntries(
|
|
1529
|
+
Object.keys(record).sort((a, b) => a.localeCompare(b)).map((key) => [key, stable(record[key])])
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
function serializeEvidenceManifest(manifest) {
|
|
1533
|
+
return `${JSON.stringify(stable(manifest), null, 2)}
|
|
1534
|
+
`;
|
|
1535
|
+
}
|
|
1536
|
+
function inferEvidenceFileRole(relativePath) {
|
|
1537
|
+
const normalized = assertEvidenceRelativePath(relativePath);
|
|
1538
|
+
const base = normalized.includes("/") ? normalized.slice(normalized.lastIndexOf("/") + 1) : normalized;
|
|
1539
|
+
if (base === "evidence.html" || base === "trace.html" || base.endsWith(".html")) {
|
|
1540
|
+
return "report";
|
|
1541
|
+
}
|
|
1542
|
+
if (base === "trace.jsonl" || base.endsWith(".jsonl")) {
|
|
1543
|
+
return "redacted-trace";
|
|
1544
|
+
}
|
|
1545
|
+
if (base === "check-results.json") {
|
|
1546
|
+
return "checks";
|
|
1547
|
+
}
|
|
1548
|
+
if (base === "redaction-report.json") {
|
|
1549
|
+
return "redaction-report";
|
|
1550
|
+
}
|
|
1551
|
+
if (base === "summary.md") {
|
|
1552
|
+
return "summary";
|
|
1553
|
+
}
|
|
1554
|
+
return "other";
|
|
1555
|
+
}
|
|
1556
|
+
function buildEvidenceFileEntries(files) {
|
|
1557
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
1558
|
+
for (const file of files) {
|
|
1559
|
+
const relativePath = assertEvidenceRelativePath(file.path);
|
|
1560
|
+
if (relativePath === EVIDENCE_MANIFEST_FILENAME) {
|
|
1561
|
+
throw new Error(
|
|
1562
|
+
`Do not include ${EVIDENCE_MANIFEST_FILENAME} in packaged file hashes (self-hash is undefined).`
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
1565
|
+
if (byPath.has(relativePath)) {
|
|
1566
|
+
throw new Error(`Duplicate evidence file path: ${relativePath}`);
|
|
1567
|
+
}
|
|
1568
|
+
byPath.set(relativePath, {
|
|
1569
|
+
path: relativePath,
|
|
1570
|
+
sha256: sha256Hex(file.content),
|
|
1571
|
+
role: file.role ?? inferEvidenceFileRole(relativePath)
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
return [...byPath.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
1575
|
+
}
|
|
1576
|
+
function buildEvidenceManifest(parts) {
|
|
1577
|
+
const runIds = [...parts.runIds];
|
|
1578
|
+
if (runIds.length === 0) {
|
|
1579
|
+
throw new Error("Evidence manifest requires at least one run id.");
|
|
1580
|
+
}
|
|
1581
|
+
for (const item of parts.sourceHashes) {
|
|
1582
|
+
if (!runIds.includes(item.runId)) {
|
|
1583
|
+
throw new Error(`sourceHashes runId "${item.runId}" is not listed in source.runIds.`);
|
|
1584
|
+
}
|
|
1585
|
+
if (item.algorithm !== "sha256") {
|
|
1586
|
+
throw new Error(`Unsupported source hash algorithm: ${item.algorithm}`);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
const assessment = {
|
|
1590
|
+
status: parts.assessmentStatus,
|
|
1591
|
+
note: parts.note ?? EVIDENCE_ASSESSMENT_NOTE
|
|
1592
|
+
};
|
|
1593
|
+
if (parts.sourceStatus !== void 0) {
|
|
1594
|
+
assessment.sourceStatus = parts.sourceStatus;
|
|
1595
|
+
}
|
|
1596
|
+
return {
|
|
1597
|
+
evidenceFormatVersion: EVIDENCE_FORMAT_VERSION,
|
|
1598
|
+
generator: {
|
|
1599
|
+
name: parts.generatorName ?? "agent-inspect",
|
|
1600
|
+
version: parts.generatorVersion
|
|
1601
|
+
},
|
|
1602
|
+
createdAt: parts.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
1603
|
+
source: {
|
|
1604
|
+
runIds,
|
|
1605
|
+
traceSchemaVersions: [...parts.traceSchemaVersions].sort((a, b) => a.localeCompare(b)),
|
|
1606
|
+
sourceHashes: [...parts.sourceHashes].sort((a, b) => a.runId.localeCompare(b.runId))
|
|
1607
|
+
},
|
|
1608
|
+
policy: {
|
|
1609
|
+
redactionProfile: parts.redactionProfile,
|
|
1610
|
+
verificationPolicy: parts.verificationPolicy ?? parts.redactionProfile
|
|
1611
|
+
},
|
|
1612
|
+
assessment,
|
|
1613
|
+
files: buildEvidenceFileEntries(parts.files)
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
function validateEvidenceManifest(value) {
|
|
1617
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
1618
|
+
throw new Error("Evidence manifest must be a JSON object.");
|
|
1619
|
+
}
|
|
1620
|
+
const record = value;
|
|
1621
|
+
if (record.evidenceFormatVersion !== EVIDENCE_FORMAT_VERSION) {
|
|
1622
|
+
throw new Error(
|
|
1623
|
+
`Unsupported evidenceFormatVersion: ${String(record.evidenceFormatVersion)}`
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
const generator = record.generator;
|
|
1627
|
+
if (generator === null || typeof generator !== "object" || Array.isArray(generator) || typeof generator.name !== "string" || typeof generator.version !== "string") {
|
|
1628
|
+
throw new Error("Evidence manifest requires generator.name and generator.version.");
|
|
1629
|
+
}
|
|
1630
|
+
const source = record.source;
|
|
1631
|
+
if (source === null || typeof source !== "object" || Array.isArray(source)) {
|
|
1632
|
+
throw new Error("Evidence manifest requires source.");
|
|
1633
|
+
}
|
|
1634
|
+
const sourceRecord = source;
|
|
1635
|
+
if (!Array.isArray(sourceRecord.runIds) || sourceRecord.runIds.length === 0) {
|
|
1636
|
+
throw new Error("Evidence manifest source.runIds must be a non-empty array.");
|
|
1637
|
+
}
|
|
1638
|
+
if (!Array.isArray(sourceRecord.traceSchemaVersions)) {
|
|
1639
|
+
throw new Error("Evidence manifest source.traceSchemaVersions must be an array.");
|
|
1640
|
+
}
|
|
1641
|
+
if (!Array.isArray(sourceRecord.sourceHashes)) {
|
|
1642
|
+
throw new Error("Evidence manifest source.sourceHashes must be an array.");
|
|
1643
|
+
}
|
|
1644
|
+
const policy = record.policy;
|
|
1645
|
+
if (policy === null || typeof policy !== "object" || Array.isArray(policy)) {
|
|
1646
|
+
throw new Error("Evidence manifest requires policy.");
|
|
1647
|
+
}
|
|
1648
|
+
const assessment = record.assessment;
|
|
1649
|
+
if (assessment === null || typeof assessment !== "object" || Array.isArray(assessment) || typeof assessment.status !== "string") {
|
|
1650
|
+
throw new Error("Evidence manifest requires assessment.status.");
|
|
1651
|
+
}
|
|
1652
|
+
if (!Array.isArray(record.files) || record.files.length === 0) {
|
|
1653
|
+
throw new Error("Evidence manifest files must be a non-empty array.");
|
|
1654
|
+
}
|
|
1655
|
+
for (const file of record.files) {
|
|
1656
|
+
if (file === null || typeof file !== "object" || Array.isArray(file)) {
|
|
1657
|
+
throw new Error("Evidence manifest file entries must be objects.");
|
|
1658
|
+
}
|
|
1659
|
+
const entry = file;
|
|
1660
|
+
if (typeof entry.path !== "string") {
|
|
1661
|
+
throw new Error("Evidence file entry requires path.");
|
|
1662
|
+
}
|
|
1663
|
+
assertEvidenceRelativePath(entry.path);
|
|
1664
|
+
if (typeof entry.sha256 !== "string" || !/^[a-f0-9]{64}$/i.test(entry.sha256)) {
|
|
1665
|
+
throw new Error(`Evidence file entry requires sha256 hex for ${entry.path}.`);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
return value;
|
|
1669
|
+
}
|
|
1670
|
+
function parseEvidenceManifestJson(text) {
|
|
1671
|
+
let parsed;
|
|
1672
|
+
try {
|
|
1673
|
+
parsed = JSON.parse(text);
|
|
1674
|
+
} catch (error) {
|
|
1675
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1676
|
+
throw new Error(`Evidence manifest is not valid JSON: ${message}`);
|
|
1677
|
+
}
|
|
1678
|
+
return validateEvidenceManifest(parsed);
|
|
1679
|
+
}
|
|
1680
|
+
function collectTraceSchemaVersions(jsonl) {
|
|
1681
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1682
|
+
for (const line of jsonl.split(/\r?\n/)) {
|
|
1683
|
+
const trimmed = line.trim();
|
|
1684
|
+
if (trimmed === "") continue;
|
|
1685
|
+
try {
|
|
1686
|
+
const row = JSON.parse(trimmed);
|
|
1687
|
+
if (typeof row.schemaVersion === "string" && row.schemaVersion.trim() !== "") {
|
|
1688
|
+
versions.add(row.schemaVersion.trim());
|
|
1689
|
+
}
|
|
1690
|
+
} catch {
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return [...versions].sort((a, b) => a.localeCompare(b));
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// packages/core/src/evidence/views.ts
|
|
1697
|
+
function renderTreeHtml(nodes, ulClass = "tree") {
|
|
1698
|
+
if (nodes.length === 0) return "";
|
|
1699
|
+
const parts = [`<ul class="${ulClass}">`];
|
|
1700
|
+
for (const n of nodes) {
|
|
1701
|
+
const ev = n.event;
|
|
1702
|
+
const status = ev.status ?? "?";
|
|
1703
|
+
const dur = ev.durationMs !== void 0 && Number.isFinite(ev.durationMs) ? `${ev.durationMs}ms` : "-";
|
|
1704
|
+
const errClass = ev.status === "error" ? " is-error" : "";
|
|
1705
|
+
parts.push(`<li class="tree-node${errClass}">`);
|
|
1706
|
+
parts.push(
|
|
1707
|
+
`<span class="nm">${escapeHtml(ev.name)}</span> <span class="meta">[${escapeHtml(ev.kind)}] ${escapeHtml(status)} (${escapeHtml(dur)})</span>`
|
|
1708
|
+
);
|
|
1709
|
+
if (n.children.length > 0) {
|
|
1710
|
+
parts.push(renderTreeHtml(n.children, "tree nested"));
|
|
1711
|
+
}
|
|
1712
|
+
parts.push("</li>");
|
|
1713
|
+
}
|
|
1714
|
+
parts.push("</ul>");
|
|
1715
|
+
return parts.join("");
|
|
1716
|
+
}
|
|
1717
|
+
function buildEvidenceTreeViewHtml(trees) {
|
|
1718
|
+
if (trees.length === 0) {
|
|
1719
|
+
return `<p class="muted">No execution trees available.</p>`;
|
|
1720
|
+
}
|
|
1721
|
+
const parts = [];
|
|
1722
|
+
for (const tree of trees) {
|
|
1723
|
+
parts.push(`<article class="run-block">`);
|
|
1724
|
+
parts.push(`<h3><code>${escapeHtml(tree.runId)}</code></h3>`);
|
|
1725
|
+
if (tree.name) {
|
|
1726
|
+
parts.push(`<p class="muted">Name: ${escapeHtml(tree.name)}</p>`);
|
|
1727
|
+
}
|
|
1728
|
+
parts.push(
|
|
1729
|
+
`<p>Status: <strong>${escapeHtml(String(tree.status ?? "unknown"))}</strong>${tree.durationMs !== void 0 ? ` \xB7 ${escapeHtml(String(tree.durationMs))}ms` : ""}</p>`
|
|
1730
|
+
);
|
|
1731
|
+
parts.push(
|
|
1732
|
+
tree.children.length > 0 ? renderTreeHtml(tree.children) : `<p class="muted">No steps recorded.</p>`
|
|
1733
|
+
);
|
|
1734
|
+
parts.push(`</article>`);
|
|
1735
|
+
}
|
|
1736
|
+
return parts.join("\n");
|
|
1737
|
+
}
|
|
1738
|
+
function timelineRows(tree) {
|
|
1739
|
+
const flat = flattenTree(tree);
|
|
1740
|
+
const origin = tree.startedAt ?? flat.reduce((min, n) => {
|
|
1741
|
+
const t = n.event.timestamp;
|
|
1742
|
+
if (!Number.isFinite(t)) return min;
|
|
1743
|
+
return min === void 0 ? t : Math.min(min, t);
|
|
1744
|
+
}, void 0) ?? 0;
|
|
1745
|
+
return flat.filter((n) => n.event.kind !== "RUN").map((n) => {
|
|
1746
|
+
const started = Number.isFinite(n.event.timestamp) ? n.event.timestamp : origin;
|
|
1747
|
+
const durationMs = n.event.durationMs !== void 0 && Number.isFinite(n.event.durationMs) ? Math.max(0, n.event.durationMs) : 0;
|
|
1748
|
+
return {
|
|
1749
|
+
name: n.event.name,
|
|
1750
|
+
kind: n.event.kind,
|
|
1751
|
+
status: n.event.status ?? "?",
|
|
1752
|
+
offsetMs: Math.max(0, started - origin),
|
|
1753
|
+
durationMs,
|
|
1754
|
+
isError: n.event.status === "error"
|
|
1755
|
+
};
|
|
1756
|
+
}).sort((a, b) => a.offsetMs - b.offsetMs || a.name.localeCompare(b.name));
|
|
1757
|
+
}
|
|
1758
|
+
function buildEvidenceTimelineViewHtml(trees) {
|
|
1759
|
+
if (trees.length === 0) {
|
|
1760
|
+
return `<p class="muted">No timeline data available.</p>`;
|
|
1761
|
+
}
|
|
1762
|
+
const parts = [];
|
|
1763
|
+
for (const tree of trees) {
|
|
1764
|
+
const rows = timelineRows(tree);
|
|
1765
|
+
const maxEnd = rows.reduce(
|
|
1766
|
+
(max, row) => Math.max(max, row.offsetMs + Math.max(row.durationMs, 1)),
|
|
1767
|
+
1
|
|
1768
|
+
);
|
|
1769
|
+
parts.push(`<article class="run-block">`);
|
|
1770
|
+
parts.push(`<h3><code>${escapeHtml(tree.runId)}</code></h3>`);
|
|
1771
|
+
if (rows.length === 0) {
|
|
1772
|
+
parts.push(`<p class="muted">No step timings recorded.</p>`);
|
|
1773
|
+
} else {
|
|
1774
|
+
parts.push(`<div class="waterfall" role="list">`);
|
|
1775
|
+
for (const row of rows) {
|
|
1776
|
+
const left = row.offsetMs / maxEnd * 100;
|
|
1777
|
+
const width = Math.max(0.8, Math.max(row.durationMs, 1) / maxEnd * 100);
|
|
1778
|
+
const err = row.isError ? " is-error" : "";
|
|
1779
|
+
parts.push(
|
|
1780
|
+
`<div class="wf-row${err}" role="listitem"><div class="wf-label"><span class="nm">${escapeHtml(row.name)}</span> <span class="meta">[${escapeHtml(row.kind)}] ${escapeHtml(row.status)} \xB7 ${escapeHtml(String(row.durationMs))}ms @+${escapeHtml(String(row.offsetMs))}ms</span></div><div class="wf-track"><span class="wf-bar" style="left:${left.toFixed(2)}%;width:${width.toFixed(2)}%"></span></div></div>`
|
|
1781
|
+
);
|
|
1782
|
+
}
|
|
1783
|
+
parts.push(`</div>`);
|
|
1784
|
+
}
|
|
1785
|
+
parts.push(`</article>`);
|
|
1786
|
+
}
|
|
1787
|
+
return parts.join("\n");
|
|
1788
|
+
}
|
|
1789
|
+
function findNodeByEventId(nodes, eventId) {
|
|
1790
|
+
for (const node of nodes) {
|
|
1791
|
+
if (node.event.eventId === eventId) return node;
|
|
1792
|
+
const child = findNodeByEventId(node.children, eventId);
|
|
1793
|
+
if (child) return child;
|
|
1794
|
+
}
|
|
1795
|
+
return void 0;
|
|
1796
|
+
}
|
|
1797
|
+
function buildAncestorChain(tree, failure) {
|
|
1798
|
+
const chain = [failure];
|
|
1799
|
+
let parentId = failure.event.parentId;
|
|
1800
|
+
const guard = /* @__PURE__ */ new Set([failure.event.eventId]);
|
|
1801
|
+
while (parentId && !guard.has(parentId)) {
|
|
1802
|
+
guard.add(parentId);
|
|
1803
|
+
const parent = findNodeByEventId(tree.children, parentId);
|
|
1804
|
+
if (!parent) break;
|
|
1805
|
+
chain.unshift(parent);
|
|
1806
|
+
parentId = parent.event.parentId;
|
|
1807
|
+
}
|
|
1808
|
+
return chain;
|
|
1809
|
+
}
|
|
1810
|
+
function buildEvidenceCausalFailureViewHtml(trees) {
|
|
1811
|
+
if (trees.length === 0) {
|
|
1812
|
+
return `<p class="muted">No runs available for causal analysis.</p>`;
|
|
1813
|
+
}
|
|
1814
|
+
const parts = [];
|
|
1815
|
+
for (const tree of trees) {
|
|
1816
|
+
parts.push(`<article class="run-block">`);
|
|
1817
|
+
parts.push(`<h3><code>${escapeHtml(tree.runId)}</code></h3>`);
|
|
1818
|
+
const errors = flattenTree(tree).filter((n) => n.event.status === "error" || n.event.kind === "ERROR").sort((a, b) => a.event.timestamp - b.event.timestamp);
|
|
1819
|
+
if (errors.length === 0) {
|
|
1820
|
+
parts.push(
|
|
1821
|
+
`<p class="muted">No error-status events found. Run status: <strong>${escapeHtml(String(tree.status ?? "unknown"))}</strong>.</p>`
|
|
1822
|
+
);
|
|
1823
|
+
parts.push(`</article>`);
|
|
1824
|
+
continue;
|
|
1825
|
+
}
|
|
1826
|
+
const first = errors[0];
|
|
1827
|
+
const chain = buildAncestorChain(tree, first);
|
|
1828
|
+
parts.push(`<p>First error by timestamp:</p>`);
|
|
1829
|
+
parts.push(`<ol class="causal-chain">`);
|
|
1830
|
+
for (const node of chain) {
|
|
1831
|
+
const isTip = node.event.eventId === first.event.eventId;
|
|
1832
|
+
const msg = typeof node.event.attributes?.message === "string" ? node.event.attributes.message : typeof node.event.attributes?.error === "string" ? node.event.attributes.error : void 0;
|
|
1833
|
+
parts.push(
|
|
1834
|
+
`<li class="${isTip ? "causal-tip" : ""}"><span class="nm">${escapeHtml(node.event.name)}</span> <span class="meta">[${escapeHtml(node.event.kind)}] ${escapeHtml(node.event.status ?? "?")} \xB7 ${escapeHtml(node.event.eventId)}</span>${msg ? `<div class="causal-msg">${escapeHtml(msg.slice(0, 400))}</div>` : ""}</li>`
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
parts.push(`</ol>`);
|
|
1838
|
+
if (errors.length > 1) {
|
|
1839
|
+
parts.push(
|
|
1840
|
+
`<p class="muted">${escapeHtml(String(errors.length - 1))} additional error event(s) not shown in the primary chain.</p>`
|
|
1841
|
+
);
|
|
1842
|
+
}
|
|
1843
|
+
parts.push(`</article>`);
|
|
1844
|
+
}
|
|
1845
|
+
return parts.join("\n");
|
|
1846
|
+
}
|
|
1847
|
+
var EVIDENCE_VIEW_CSS = `
|
|
1848
|
+
ul.tree{list-style:none;padding-left:1rem;margin:.5rem 0}
|
|
1849
|
+
ul.tree.nested{padding-left:1.25rem;border-left:1px solid var(--line);margin:.25rem 0}
|
|
1850
|
+
.tree-node.is-error .nm,.wf-row.is-error .nm,.causal-tip .nm{color:var(--unsafe)}
|
|
1851
|
+
.waterfall{display:flex;flex-direction:column;gap:.45rem;max-width:52rem}
|
|
1852
|
+
.wf-row{display:grid;grid-template-columns:minmax(10rem,18rem) 1fr;gap:.6rem;align-items:center}
|
|
1853
|
+
.wf-track{position:relative;height:.7rem;background:#e8e8e4;border-radius:.25rem;overflow:hidden}
|
|
1854
|
+
.wf-bar{position:absolute;top:0;bottom:0;background:var(--accent);border-radius:.25rem}
|
|
1855
|
+
.wf-row.is-error .wf-bar{background:var(--unsafe)}
|
|
1856
|
+
.causal-chain{max-width:44rem}
|
|
1857
|
+
.causal-msg{margin:.25rem 0 0;color:var(--muted);font-size:.92rem}
|
|
1858
|
+
.run-block{margin:0 0 1.25rem;padding-bottom:1rem;border-bottom:1px solid var(--line)}
|
|
1859
|
+
.run-block:last-child{border-bottom:0}
|
|
1860
|
+
@media (max-width:720px){
|
|
1861
|
+
.wf-row{grid-template-columns:1fr}
|
|
1862
|
+
}
|
|
1863
|
+
`.trim();
|
|
1864
|
+
|
|
1865
|
+
// packages/core/src/evidence/html-shell.ts
|
|
1866
|
+
var EVIDENCE_HTML_FILENAME = "evidence.html";
|
|
1867
|
+
var EVIDENCE_HTML_NOTE = "Generated locally by AgentInspect. Share-checked evidence for review \u2014 not a compliance or security certification.";
|
|
1868
|
+
var EVIDENCE_VIEW_IDS = [
|
|
1869
|
+
"summary",
|
|
1870
|
+
"tree",
|
|
1871
|
+
"timeline",
|
|
1872
|
+
"causal",
|
|
1873
|
+
"tools-llm",
|
|
1874
|
+
"outcomes",
|
|
1875
|
+
"contracts",
|
|
1876
|
+
"circuit",
|
|
1877
|
+
"diff",
|
|
1878
|
+
"safety",
|
|
1879
|
+
"provenance"
|
|
1880
|
+
];
|
|
1881
|
+
function statusClass(status) {
|
|
1882
|
+
if (status === "SAFE") return "st-safe";
|
|
1883
|
+
if (status === "SAFE WITH WARNINGS") return "st-warn";
|
|
1884
|
+
if (status === "UNSAFE") return "st-unsafe";
|
|
1885
|
+
return "st-unknown";
|
|
1886
|
+
}
|
|
1887
|
+
function viewLabel(id) {
|
|
1888
|
+
switch (id) {
|
|
1889
|
+
case "summary":
|
|
1890
|
+
return "Summary";
|
|
1891
|
+
case "tree":
|
|
1892
|
+
return "Tree";
|
|
1893
|
+
case "timeline":
|
|
1894
|
+
return "Timeline";
|
|
1895
|
+
case "causal":
|
|
1896
|
+
return "Causal failure";
|
|
1897
|
+
case "tools-llm":
|
|
1898
|
+
return "Tools / LLM";
|
|
1899
|
+
case "outcomes":
|
|
1900
|
+
return "Outcomes";
|
|
1901
|
+
case "contracts":
|
|
1902
|
+
return "Contracts / checks";
|
|
1903
|
+
case "circuit":
|
|
1904
|
+
return "Circuit / guardrails";
|
|
1905
|
+
case "diff":
|
|
1906
|
+
return "Diff";
|
|
1907
|
+
case "safety":
|
|
1908
|
+
return "Safety / redaction";
|
|
1909
|
+
case "provenance":
|
|
1910
|
+
return "Provenance";
|
|
1911
|
+
default: {
|
|
1912
|
+
const _exhaustive = id;
|
|
1913
|
+
return _exhaustive;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
function encodeEmbeddedEvidenceJson(value) {
|
|
1918
|
+
return JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
1919
|
+
}
|
|
1920
|
+
function buildEmbeddedPayload(input) {
|
|
1921
|
+
return {
|
|
1922
|
+
evidenceFormatVersion: input.evidenceFormatVersion ?? "1.0",
|
|
1923
|
+
generator: {
|
|
1924
|
+
name: input.generatorName,
|
|
1925
|
+
version: input.generatorVersion
|
|
1926
|
+
},
|
|
1927
|
+
createdAt: input.createdAt,
|
|
1928
|
+
runIds: [...input.runIds],
|
|
1929
|
+
assessment: {
|
|
1930
|
+
status: input.assessmentStatus,
|
|
1931
|
+
...input.sourceStatus !== void 0 ? { sourceStatus: input.sourceStatus } : {}
|
|
1932
|
+
},
|
|
1933
|
+
policy: {
|
|
1934
|
+
redactionProfile: input.redactionProfile,
|
|
1935
|
+
verificationPolicy: input.verificationPolicy
|
|
1936
|
+
},
|
|
1937
|
+
checkSummary: input.checkSummary
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function buildEvidenceHtmlShell(input) {
|
|
1941
|
+
if (input.runIds.length === 0) {
|
|
1942
|
+
throw new Error("Evidence HTML shell requires at least one run id.");
|
|
1943
|
+
}
|
|
1944
|
+
const maxChars = input.maxEmbeddedJsonChars ?? 64 * 1024;
|
|
1945
|
+
let embedded = encodeEmbeddedEvidenceJson(buildEmbeddedPayload(input));
|
|
1946
|
+
if (embedded.length > maxChars) {
|
|
1947
|
+
embedded = encodeEmbeddedEvidenceJson({
|
|
1948
|
+
truncated: true,
|
|
1949
|
+
evidenceFormatVersion: input.evidenceFormatVersion ?? "1.0",
|
|
1950
|
+
runIds: [...input.runIds],
|
|
1951
|
+
assessment: { status: input.assessmentStatus },
|
|
1952
|
+
note: "Embedded payload truncated to bound; open evidence.json / trace files for full detail."
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
const title = escapeHtml(input.title ?? "AgentInspect evidence");
|
|
1956
|
+
const runList = input.runIds.map((id) => `<li><code>${escapeHtml(id)}</code></li>`).join("");
|
|
1957
|
+
const summaryBody = input.summaryText !== void 0 && input.summaryText.trim() !== "" ? `<pre class="summary-md">${escapeHtml(input.summaryText)}</pre>` : `<p class="muted">Open <code>summary.md</code> in this bundle for the full text summary.</p>`;
|
|
1958
|
+
const checkRows = input.checkSummary?.runs.map(
|
|
1959
|
+
(run) => `<tr><td><code>${escapeHtml(run.runId)}</code></td><td class="${statusClass(run.status)}">${escapeHtml(run.status)}</td><td>${run.errors}</td><td>${run.warnings}</td><td>${run.findings}</td></tr>`
|
|
1960
|
+
).join("") ?? "";
|
|
1961
|
+
const nav = EVIDENCE_VIEW_IDS.map(
|
|
1962
|
+
(id) => `<a class="nav-link" href="#view-${id}" data-view="${id}">${escapeHtml(viewLabel(id))}</a>`
|
|
1963
|
+
).join("\n");
|
|
1964
|
+
const stubPanels = EVIDENCE_VIEW_IDS.filter((id) => id !== "summary").map((id) => {
|
|
1965
|
+
const body = input.viewBodies?.[id];
|
|
1966
|
+
if (body !== void 0 && body.trim() !== "") {
|
|
1967
|
+
return ` <section id="view-${id}" class="panel" hidden>
|
|
1968
|
+
<h2>${escapeHtml(viewLabel(id))}</h2>
|
|
1969
|
+
${body}
|
|
1970
|
+
</section>`;
|
|
1971
|
+
}
|
|
1972
|
+
return ` <section id="view-${id}" class="panel" hidden>
|
|
1973
|
+
<h2>${escapeHtml(viewLabel(id))}</h2>
|
|
1974
|
+
<p class="muted">This view will be filled in a later AgentInspect 6.10 release. The shell is offline-ready.</p>
|
|
1975
|
+
</section>`;
|
|
1976
|
+
}).join("\n");
|
|
1977
|
+
return `<!doctype html>
|
|
1978
|
+
<html lang="en">
|
|
1979
|
+
<head>
|
|
1980
|
+
<meta charset="utf-8"/>
|
|
1981
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
1982
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'"/>
|
|
1983
|
+
<meta name="referrer" content="no-referrer"/>
|
|
1984
|
+
<title>${title}</title>
|
|
1985
|
+
<style>
|
|
1986
|
+
:root{--bg:#f7f7f5;--fg:#1a1a1a;--muted:#5c5c5c;--line:#d8d8d4;--accent:#0b5fff;--safe:#0a7a3e;--warn:#9a6700;--unsafe:#b42318;--unknown:#5c5c5c}
|
|
1987
|
+
*{box-sizing:border-box}
|
|
1988
|
+
body{margin:0;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,sans-serif;background:var(--bg);color:var(--fg);line-height:1.5}
|
|
1989
|
+
a{color:var(--accent)}
|
|
1990
|
+
header{padding:1.25rem 1.5rem;border-bottom:1px solid var(--line);background:#fff}
|
|
1991
|
+
header h1{margin:0 0 .35rem;font-size:1.35rem}
|
|
1992
|
+
.note{margin:0;color:var(--muted);font-size:.92rem;max-width:52rem}
|
|
1993
|
+
.layout{display:grid;grid-template-columns:14rem 1fr;min-height:70vh}
|
|
1994
|
+
nav{padding:1rem;border-right:1px solid var(--line);background:#fff}
|
|
1995
|
+
nav .nav-link{display:block;padding:.4rem .55rem;margin:0 0 .2rem;border-radius:.35rem;text-decoration:none;color:inherit}
|
|
1996
|
+
nav .nav-link:hover,nav .nav-link:focus{background:#eef3ff;outline:2px solid var(--accent);outline-offset:1px}
|
|
1997
|
+
main{padding:1.25rem 1.5rem}
|
|
1998
|
+
.panel[hidden]{display:none}
|
|
1999
|
+
.badge{display:inline-block;padding:.15rem .55rem;border-radius:.3rem;font-size:.85rem;font-weight:600}
|
|
2000
|
+
.st-safe{color:var(--safe)}.st-warn{color:var(--warn)}.st-unsafe{color:var(--unsafe)}.st-unknown{color:var(--unknown)}
|
|
2001
|
+
table{border-collapse:collapse;width:100%;max-width:48rem;background:#fff}
|
|
2002
|
+
th,td{border:1px solid var(--line);padding:.4rem .55rem;text-align:left;vertical-align:top}
|
|
2003
|
+
th{background:#f0f0ec}
|
|
2004
|
+
.summary-md,pre.data{white-space:pre-wrap;word-break:break-word;background:#fff;border:1px solid var(--line);padding:.75rem;max-width:52rem}
|
|
2005
|
+
.muted{color:var(--muted)}
|
|
2006
|
+
ul.runs{margin:.4rem 0 1rem;padding-left:1.2rem}
|
|
2007
|
+
@media print{
|
|
2008
|
+
nav{display:none}
|
|
2009
|
+
.layout{display:block}
|
|
2010
|
+
.panel[hidden]{display:block!important;page-break-before:always}
|
|
2011
|
+
header{border:0}
|
|
2012
|
+
}
|
|
2013
|
+
@media (max-width:720px){
|
|
2014
|
+
.layout{grid-template-columns:1fr}
|
|
2015
|
+
nav{border-right:0;border-bottom:1px solid var(--line);display:flex;flex-wrap:wrap;gap:.25rem}
|
|
2016
|
+
}
|
|
2017
|
+
${EVIDENCE_VIEW_CSS}
|
|
2018
|
+
</style>
|
|
2019
|
+
</head>
|
|
2020
|
+
<body>
|
|
2021
|
+
<header>
|
|
2022
|
+
<h1>${title}</h1>
|
|
2023
|
+
<p class="note">${escapeHtml(EVIDENCE_HTML_NOTE)}</p>
|
|
2024
|
+
</header>
|
|
2025
|
+
<div class="layout">
|
|
2026
|
+
<nav aria-label="Evidence views">
|
|
2027
|
+
${nav}
|
|
2028
|
+
</nav>
|
|
2029
|
+
<main id="main">
|
|
2030
|
+
<section id="view-summary" class="panel" tabindex="-1">
|
|
2031
|
+
<h2>Summary</h2>
|
|
2032
|
+
<p>Artifact status: <span class="badge ${statusClass(input.assessmentStatus)}">${escapeHtml(input.assessmentStatus)}</span>
|
|
2033
|
+
${input.sourceStatus !== void 0 ? ` \xB7 Source status: <span class="badge ${statusClass(input.sourceStatus)}">${escapeHtml(input.sourceStatus)}</span>` : ""}</p>
|
|
2034
|
+
<p>Profile: <code>${escapeHtml(input.redactionProfile)}</code> \xB7 Verification: <code>${escapeHtml(input.verificationPolicy)}</code></p>
|
|
2035
|
+
<p>Generator: <code>${escapeHtml(input.generatorName)}@${escapeHtml(input.generatorVersion)}</code>
|
|
2036
|
+
${input.createdAt ? ` \xB7 Created: <code>${escapeHtml(input.createdAt)}</code>` : ""}</p>
|
|
2037
|
+
<h3>Runs</h3>
|
|
2038
|
+
<ul class="runs">${runList}</ul>
|
|
2039
|
+
${checkRows ? `<h3>Check summary</h3>
|
|
2040
|
+
<table>
|
|
2041
|
+
<thead><tr><th>runId</th><th>artifact</th><th>errors</th><th>warnings</th><th>findings</th></tr></thead>
|
|
2042
|
+
<tbody>${checkRows}</tbody>
|
|
2043
|
+
</table>` : ""}
|
|
2044
|
+
<h3>Text summary</h3>
|
|
2045
|
+
${summaryBody}
|
|
2046
|
+
</section>
|
|
2047
|
+
${stubPanels}
|
|
2048
|
+
</main>
|
|
2049
|
+
</div>
|
|
2050
|
+
<script type="application/json" id="ai-evidence-data">${embedded}</script>
|
|
2051
|
+
<script>
|
|
2052
|
+
(function(){
|
|
2053
|
+
var links=document.querySelectorAll("nav .nav-link");
|
|
2054
|
+
var panels=document.querySelectorAll("main .panel");
|
|
2055
|
+
function show(id){
|
|
2056
|
+
for(var i=0;i<panels.length;i++){
|
|
2057
|
+
var p=panels[i];
|
|
2058
|
+
var on=p.id==="view-"+id;
|
|
2059
|
+
if(on){p.removeAttribute("hidden");}else{p.setAttribute("hidden","");}
|
|
2060
|
+
}
|
|
2061
|
+
for(var j=0;j<links.length;j++){
|
|
2062
|
+
var a=links[j];
|
|
2063
|
+
if(a.getAttribute("data-view")===id){a.setAttribute("aria-current","page");}
|
|
2064
|
+
else{a.removeAttribute("aria-current");}
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
for(var k=0;k<links.length;k++){
|
|
2068
|
+
links[k].addEventListener("click",function(ev){
|
|
2069
|
+
var id=ev.currentTarget.getAttribute("data-view");
|
|
2070
|
+
if(!id)return;
|
|
2071
|
+
ev.preventDefault();
|
|
2072
|
+
if(history.replaceState){history.replaceState(null,"","#view-"+id);}
|
|
2073
|
+
show(id);
|
|
2074
|
+
var panel=document.getElementById("view-"+id);
|
|
2075
|
+
if(panel)panel.focus();
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
var hash=(location.hash||"").replace(/^#view-/,"");
|
|
2079
|
+
var initial="summary";
|
|
2080
|
+
for(var n=0;n<links.length;n++){
|
|
2081
|
+
if(links[n].getAttribute("data-view")===hash){initial=hash;break;}
|
|
2082
|
+
}
|
|
2083
|
+
show(initial);
|
|
2084
|
+
})();
|
|
2085
|
+
</script>
|
|
2086
|
+
</body>
|
|
2087
|
+
</html>
|
|
2088
|
+
`;
|
|
2089
|
+
}
|
|
2090
|
+
function buildEvidenceHtmlShellFromManifest(manifest, extras) {
|
|
2091
|
+
return buildEvidenceHtmlShell({
|
|
2092
|
+
title: extras?.title,
|
|
2093
|
+
runIds: manifest.source.runIds,
|
|
2094
|
+
assessmentStatus: manifest.assessment.status,
|
|
2095
|
+
sourceStatus: manifest.assessment.sourceStatus,
|
|
2096
|
+
redactionProfile: manifest.policy.redactionProfile,
|
|
2097
|
+
verificationPolicy: manifest.policy.verificationPolicy,
|
|
2098
|
+
generatorName: manifest.generator.name,
|
|
2099
|
+
generatorVersion: manifest.generator.version,
|
|
2100
|
+
createdAt: manifest.createdAt,
|
|
2101
|
+
evidenceFormatVersion: manifest.evidenceFormatVersion,
|
|
2102
|
+
summaryText: extras?.summaryText,
|
|
2103
|
+
checkSummary: extras?.checkSummary,
|
|
2104
|
+
viewBodies: extras?.viewBodies
|
|
2105
|
+
});
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// packages/core/src/evidence/views-contract.ts
|
|
2109
|
+
function boundMessage(message, max = 200) {
|
|
2110
|
+
const trimmed = message.trim();
|
|
2111
|
+
if (trimmed.length <= max) return trimmed;
|
|
2112
|
+
return `${trimmed.slice(0, max)}\u2026`;
|
|
2113
|
+
}
|
|
2114
|
+
function buildEvidenceContractsViewHtml(input) {
|
|
2115
|
+
const rows = input.runs.map(
|
|
2116
|
+
(run) => `<tr><td><code>${escapeHtml(run.runId)}</code></td><td>${escapeHtml(run.status)}</td><td>${escapeHtml(run.sourceStatus ?? "\u2014")}</td><td>${run.errors}</td><td>${run.warnings}</td><td>${run.findings}</td></tr>`
|
|
2117
|
+
).join("");
|
|
2118
|
+
const findings = input.findingSummaries ?? [];
|
|
2119
|
+
const findingRows = findings.length === 0 ? `<p class="muted">No structured check findings recorded for the redacted artifact.</p>` : `<table>
|
|
2120
|
+
<thead><tr><th>runId</th><th>severity</th><th>rule</th><th>category</th><th>detector</th><th>message</th></tr></thead>
|
|
2121
|
+
<tbody>${findings.map(
|
|
2122
|
+
(f) => `<tr><td><code>${escapeHtml(f.runId)}</code></td><td>${escapeHtml(f.severity)}</td><td><code>${escapeHtml(f.ruleId)}</code></td><td>${escapeHtml(f.category ?? "\u2014")}</td><td>${escapeHtml(f.detector ?? "\u2014")}</td><td>${escapeHtml(boundMessage(f.message))}</td></tr>`
|
|
2123
|
+
).join("")}</tbody>
|
|
2124
|
+
</table>`;
|
|
2125
|
+
return `<p>Aggregate artifact status: <strong>${escapeHtml(input.aggregateStatus)}</strong></p>
|
|
2126
|
+
<table>
|
|
2127
|
+
<thead><tr><th>runId</th><th>artifact</th><th>source</th><th>errors</th><th>warnings</th><th>findings</th></tr></thead>
|
|
2128
|
+
<tbody>${rows}</tbody>
|
|
2129
|
+
</table>
|
|
2130
|
+
<h3>Finding summaries</h3>
|
|
2131
|
+
${findingRows}
|
|
2132
|
+
<p class="muted">TraceContract / check details are best-effort local results \u2014 not a compliance certification.</p>`;
|
|
2133
|
+
}
|
|
2134
|
+
function buildEvidenceOutcomesViewHtml(runs) {
|
|
2135
|
+
if (runs.length === 0) {
|
|
2136
|
+
return `<p class="muted">No runs available for outcome extraction.</p>`;
|
|
2137
|
+
}
|
|
2138
|
+
const parts = [];
|
|
2139
|
+
for (const run of runs) {
|
|
2140
|
+
const forRun = run.events.filter((event) => event.runId === run.runId);
|
|
2141
|
+
const summary = summarizeObservedOutcomes(extractOutcomesFromPersistedEvents(forRun));
|
|
2142
|
+
parts.push(`<article class="run-block">`);
|
|
2143
|
+
parts.push(`<h3><code>${escapeHtml(run.runId)}</code></h3>`);
|
|
2144
|
+
parts.push(renderObservedOutcomesHtml(summary));
|
|
2145
|
+
parts.push(`</article>`);
|
|
2146
|
+
}
|
|
2147
|
+
return parts.join("\n");
|
|
2148
|
+
}
|
|
2149
|
+
function buildEvidenceDiffViewHtml(parts) {
|
|
2150
|
+
if (parts === void 0 || parts.leftEvents.length === 0 || parts.rightEvents.length === 0) {
|
|
2151
|
+
return `<p class="muted">No baseline/candidate pair was supplied for this evidence bundle. Attach two runs (or a reporter baseline) to populate this view.</p>`;
|
|
2152
|
+
}
|
|
2153
|
+
try {
|
|
2154
|
+
const left = persistedInspectEventsToTraceEvents(
|
|
2155
|
+
parts.leftEvents.filter((e) => e.runId === parts.leftRunId)
|
|
2156
|
+
);
|
|
2157
|
+
const right = persistedInspectEventsToTraceEvents(
|
|
2158
|
+
parts.rightEvents.filter((e) => e.runId === parts.rightRunId)
|
|
2159
|
+
);
|
|
2160
|
+
if (left.length === 0 || right.length === 0) {
|
|
2161
|
+
return `<p class="muted">Could not normalize both runs for diff (missing v0.1-compatible events).</p>`;
|
|
2162
|
+
}
|
|
2163
|
+
const result = diffTraceEvents(left, right);
|
|
2164
|
+
const text = renderRunDiff(result, { color: false, verbose: false });
|
|
2165
|
+
return `<p>Comparing <code>${escapeHtml(parts.leftRunId)}</code> \u2192 <code>${escapeHtml(parts.rightRunId)}</code></p>
|
|
2166
|
+
<pre class="summary-md">${escapeHtml(text)}</pre>`;
|
|
2167
|
+
} catch (error) {
|
|
2168
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2169
|
+
return `<p class="muted">Diff unavailable: ${escapeHtml(message)}</p>`;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
// packages/core/src/evidence/views-safety.ts
|
|
2174
|
+
function buildEvidenceSafetyViewHtml(input) {
|
|
2175
|
+
const findingRows = (input.findingSummaries ?? []).length === 0 ? `<p class="muted">No safety findings on the redacted artifact.</p>` : `<table>
|
|
2176
|
+
<thead><tr><th>runId</th><th>severity</th><th>category</th><th>detector</th><th>action</th><th>message</th></tr></thead>
|
|
2177
|
+
<tbody>${(input.findingSummaries ?? []).map((f) => {
|
|
2178
|
+
const msg = f.message.length > 160 ? `${f.message.slice(0, 160)}\u2026` : f.message;
|
|
2179
|
+
return `<tr><td><code>${escapeHtml(f.runId)}</code></td><td>${escapeHtml(f.severity)}</td><td>${escapeHtml(f.category ?? "\u2014")}</td><td>${escapeHtml(f.detector ?? "\u2014")}</td><td>${escapeHtml(f.action ?? "\u2014")}</td><td>${escapeHtml(msg)}</td></tr>`;
|
|
2180
|
+
}).join("")}</tbody>
|
|
2181
|
+
</table>`;
|
|
2182
|
+
const redactionBlock = input.redaction === void 0 ? `<p class="muted">No redaction report attached.</p>` : `<p>Total redaction findings: <strong>${input.redaction.totalFindings}</strong></p>
|
|
2183
|
+
<ul>${input.redaction.runs.map(
|
|
2184
|
+
(run) => `<li><code>${escapeHtml(run.runId)}</code>: ${run.findings} finding(s); detectors: ${escapeHtml(run.detectors.join(", ") || "none")}</li>`
|
|
2185
|
+
).join("")}</ul>`;
|
|
2186
|
+
return `<p>Artifact status: <strong>${escapeHtml(String(input.artifactStatus))}</strong>
|
|
2187
|
+
${input.sourceStatus !== void 0 ? ` \xB7 Source status: <strong>${escapeHtml(String(input.sourceStatus))}</strong>` : ""}</p>
|
|
2188
|
+
<p>Redaction profile: <code>${escapeHtml(input.redactionProfile)}</code> \xB7 Verification: <code>${escapeHtml(input.verificationPolicy)}</code></p>
|
|
2189
|
+
<h3>Redaction</h3>
|
|
2190
|
+
${redactionBlock}
|
|
2191
|
+
<h3>Safety findings (artifact)</h3>
|
|
2192
|
+
${findingRows}
|
|
2193
|
+
<p class="muted">Best-effort local verification only \u2014 not a compliance certification. Gate sharing on artifact status.</p>`;
|
|
2194
|
+
}
|
|
2195
|
+
function buildEvidenceProvenanceViewHtml(input) {
|
|
2196
|
+
const hashes = input.sourceHashes.length === 0 ? `<p class="muted">No source hashes recorded.</p>` : `<table>
|
|
2197
|
+
<thead><tr><th>runId</th><th>algorithm</th><th>hash</th></tr></thead>
|
|
2198
|
+
<tbody>${input.sourceHashes.map(
|
|
2199
|
+
(h) => `<tr><td><code>${escapeHtml(h.runId)}</code></td><td>${escapeHtml(h.algorithm)}</td><td><code>${escapeHtml(h.hash)}</code></td></tr>`
|
|
2200
|
+
).join("")}</tbody>
|
|
2201
|
+
</table>`;
|
|
2202
|
+
const files = input.packagedFiles.length === 0 ? `<p class="muted">No packaged files listed.</p>` : `<ul>${input.packagedFiles.map(
|
|
2203
|
+
(f) => `<li><code>${escapeHtml(f.path)}</code>${f.role ? ` <span class="meta">(${escapeHtml(f.role)})</span>` : ""}</li>`
|
|
2204
|
+
).join("")}</ul>`;
|
|
2205
|
+
return `<p>Generator: <code>${escapeHtml(input.generatorName)}@${escapeHtml(input.generatorVersion)}</code>
|
|
2206
|
+
\xB7 Evidence format: <code>${escapeHtml(input.evidenceFormatVersion)}</code>
|
|
2207
|
+
${input.createdAt ? ` \xB7 Created: <code>${escapeHtml(input.createdAt)}</code>` : ""}</p>
|
|
2208
|
+
<p>Runs: ${input.runIds.map((id) => `<code>${escapeHtml(id)}</code>`).join(", ")}</p>
|
|
2209
|
+
<p>Trace schema versions: ${input.traceSchemaVersions.length > 0 ? input.traceSchemaVersions.map((v) => `<code>${escapeHtml(v)}</code>`).join(", ") : '<span class="muted">unknown</span>'}</p>
|
|
2210
|
+
<h3>Source hashes (pre-redaction input)</h3>
|
|
2211
|
+
${hashes}
|
|
2212
|
+
<h3>Packaged files</h3>
|
|
2213
|
+
${files}
|
|
2214
|
+
<p class="muted">${escapeHtml(input.note ?? "Reader/mapping losses are reported elsewhere when present; relationships are never invented without confidence policy.")}</p>`;
|
|
2215
|
+
}
|
|
2216
|
+
function buildEvidenceToolsLlmViewHtml(trees) {
|
|
2217
|
+
if (trees.length === 0) {
|
|
2218
|
+
return `<p class="muted">No runs available for tool/LLM metadata.</p>`;
|
|
2219
|
+
}
|
|
2220
|
+
const parts = [];
|
|
2221
|
+
for (const tree of trees) {
|
|
2222
|
+
const nodes = flattenTree(tree).filter(
|
|
2223
|
+
(n) => n.event.kind === "TOOL" || n.event.kind === "LLM" || n.event.kind === "AGENT"
|
|
2224
|
+
);
|
|
2225
|
+
parts.push(`<article class="run-block">`);
|
|
2226
|
+
parts.push(`<h3><code>${escapeHtml(tree.runId)}</code></h3>`);
|
|
2227
|
+
if (nodes.length === 0) {
|
|
2228
|
+
parts.push(`<p class="muted">No TOOL/LLM/AGENT events in this run.</p>`);
|
|
2229
|
+
} else {
|
|
2230
|
+
parts.push(`<table>
|
|
2231
|
+
<thead><tr><th>name</th><th>kind</th><th>status</th><th>durationMs</th></tr></thead>
|
|
2232
|
+
<tbody>${nodes.map((n) => {
|
|
2233
|
+
const dur = n.event.durationMs !== void 0 && Number.isFinite(n.event.durationMs) ? String(n.event.durationMs) : "\u2014";
|
|
2234
|
+
return `<tr><td>${escapeHtml(n.event.name)}</td><td>${escapeHtml(n.event.kind)}</td><td>${escapeHtml(n.event.status ?? "?")}</td><td>${escapeHtml(dur)}</td></tr>`;
|
|
2235
|
+
}).join("")}</tbody>
|
|
2236
|
+
</table>`);
|
|
2237
|
+
}
|
|
2238
|
+
parts.push(`</article>`);
|
|
2239
|
+
}
|
|
2240
|
+
return parts.join("\n");
|
|
2241
|
+
}
|
|
2242
|
+
function buildEvidenceCircuitViewHtml(parts) {
|
|
2243
|
+
const findings = parts?.findings ?? [];
|
|
2244
|
+
if (findings.length === 0) {
|
|
2245
|
+
return `<p class="muted">No circuit or guardrail findings were attached to this evidence bundle.</p>`;
|
|
2246
|
+
}
|
|
2247
|
+
return `<table>
|
|
2248
|
+
<thead><tr><th>runId</th><th>name</th><th>status</th><th>detail</th></tr></thead>
|
|
2249
|
+
<tbody>${findings.map(
|
|
2250
|
+
(f) => `<tr><td><code>${escapeHtml(f.runId)}</code></td><td>${escapeHtml(f.name)}</td><td>${escapeHtml(f.status)}</td><td>${escapeHtml(f.detail ?? "\u2014")}</td></tr>`
|
|
2251
|
+
).join("")}</tbody>
|
|
2252
|
+
</table>`;
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
// packages/core/src/evidence/zip.ts
|
|
2256
|
+
var CRC_TABLE = (() => {
|
|
2257
|
+
const table = new Uint32Array(256);
|
|
2258
|
+
for (let n = 0; n < 256; n += 1) {
|
|
2259
|
+
let c = n;
|
|
2260
|
+
for (let k = 0; k < 8; k += 1) {
|
|
2261
|
+
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
2262
|
+
}
|
|
2263
|
+
table[n] = c >>> 0;
|
|
2264
|
+
}
|
|
2265
|
+
return table;
|
|
2266
|
+
})();
|
|
2267
|
+
function crc32(data) {
|
|
2268
|
+
let crc = 4294967295;
|
|
2269
|
+
for (let i = 0; i < data.length; i += 1) {
|
|
2270
|
+
crc = CRC_TABLE[(crc ^ data[i]) & 255] ^ crc >>> 8;
|
|
2271
|
+
}
|
|
2272
|
+
return (crc ^ 4294967295) >>> 0;
|
|
2273
|
+
}
|
|
2274
|
+
function toBytes(content) {
|
|
2275
|
+
return typeof content === "string" ? Buffer.from(content, "utf8") : content;
|
|
2276
|
+
}
|
|
2277
|
+
function u16(value) {
|
|
2278
|
+
const buf = Buffer.alloc(2);
|
|
2279
|
+
buf.writeUInt16LE(value >>> 0, 0);
|
|
2280
|
+
return buf;
|
|
2281
|
+
}
|
|
2282
|
+
function u32(value) {
|
|
2283
|
+
const buf = Buffer.alloc(4);
|
|
2284
|
+
buf.writeUInt32LE(value >>> 0, 0);
|
|
2285
|
+
return buf;
|
|
2286
|
+
}
|
|
2287
|
+
function buildZipArchive(entries) {
|
|
2288
|
+
if (entries.length === 0) {
|
|
2289
|
+
throw new Error("ZIP archive requires at least one entry.");
|
|
2290
|
+
}
|
|
2291
|
+
const locals = [];
|
|
2292
|
+
const centrals = [];
|
|
2293
|
+
let offset = 0;
|
|
2294
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2295
|
+
for (const entry of entries) {
|
|
2296
|
+
const name = assertEvidenceRelativePath(entry.path);
|
|
2297
|
+
if (seen.has(name)) {
|
|
2298
|
+
throw new Error(`Duplicate ZIP entry path: ${name}`);
|
|
2299
|
+
}
|
|
2300
|
+
seen.add(name);
|
|
2301
|
+
const nameBytes = Buffer.from(name, "utf8");
|
|
2302
|
+
const data = toBytes(entry.content);
|
|
2303
|
+
const checksum = crc32(data);
|
|
2304
|
+
const size = data.byteLength;
|
|
2305
|
+
const local = Buffer.concat([
|
|
2306
|
+
u32(67324752),
|
|
2307
|
+
u16(20),
|
|
2308
|
+
// version needed
|
|
2309
|
+
u16(0),
|
|
2310
|
+
// flags
|
|
2311
|
+
u16(0),
|
|
2312
|
+
// method STORE
|
|
2313
|
+
u16(0),
|
|
2314
|
+
// time
|
|
2315
|
+
u16(0),
|
|
2316
|
+
// date
|
|
2317
|
+
u32(checksum),
|
|
2318
|
+
u32(size),
|
|
2319
|
+
u32(size),
|
|
2320
|
+
u16(nameBytes.length),
|
|
2321
|
+
u16(0),
|
|
2322
|
+
// extra length
|
|
2323
|
+
nameBytes,
|
|
2324
|
+
Buffer.from(data)
|
|
2325
|
+
]);
|
|
2326
|
+
const central = Buffer.concat([
|
|
2327
|
+
u32(33639248),
|
|
2328
|
+
u16(20),
|
|
2329
|
+
// version made by
|
|
2330
|
+
u16(20),
|
|
2331
|
+
// version needed
|
|
2332
|
+
u16(0),
|
|
2333
|
+
u16(0),
|
|
2334
|
+
u16(0),
|
|
2335
|
+
u16(0),
|
|
2336
|
+
u32(checksum),
|
|
2337
|
+
u32(size),
|
|
2338
|
+
u32(size),
|
|
2339
|
+
u16(nameBytes.length),
|
|
2340
|
+
u16(0),
|
|
2341
|
+
u16(0),
|
|
2342
|
+
u16(0),
|
|
2343
|
+
u16(0),
|
|
2344
|
+
u32(0),
|
|
2345
|
+
u32(offset),
|
|
2346
|
+
nameBytes
|
|
2347
|
+
]);
|
|
2348
|
+
locals.push(local);
|
|
2349
|
+
centrals.push(central);
|
|
2350
|
+
offset += local.length;
|
|
2351
|
+
}
|
|
2352
|
+
const centralDir = Buffer.concat(centrals);
|
|
2353
|
+
const end = Buffer.concat([
|
|
2354
|
+
u32(101010256),
|
|
2355
|
+
u16(0),
|
|
2356
|
+
u16(0),
|
|
2357
|
+
u16(entries.length),
|
|
2358
|
+
u16(entries.length),
|
|
2359
|
+
u32(centralDir.length),
|
|
2360
|
+
u32(offset),
|
|
2361
|
+
u16(0)
|
|
2362
|
+
]);
|
|
2363
|
+
return Buffer.concat([...locals, centralDir, end]);
|
|
2364
|
+
}
|
|
2365
|
+
async function listFilesRecursive(root) {
|
|
2366
|
+
const out = [];
|
|
2367
|
+
async function walk(dir) {
|
|
2368
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
2369
|
+
for (const entry of entries) {
|
|
2370
|
+
const abs = path.join(dir, entry.name);
|
|
2371
|
+
if (entry.isDirectory()) {
|
|
2372
|
+
await walk(abs);
|
|
2373
|
+
} else if (entry.isFile()) {
|
|
2374
|
+
const rel = path.relative(root, abs).split(path.sep).join("/");
|
|
2375
|
+
out.push(rel);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
await walk(root);
|
|
2380
|
+
return out.sort((a, b) => a.localeCompare(b));
|
|
2381
|
+
}
|
|
2382
|
+
async function verifyEvidenceDirectory(rootPath, options = {}) {
|
|
2383
|
+
const unexpectedMode = options.unexpectedFiles ?? "fail";
|
|
2384
|
+
const root = path.resolve(rootPath);
|
|
2385
|
+
const issues = [];
|
|
2386
|
+
let rootStat;
|
|
2387
|
+
try {
|
|
2388
|
+
rootStat = await stat(root);
|
|
2389
|
+
} catch (error) {
|
|
2390
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2391
|
+
return {
|
|
2392
|
+
ok: false,
|
|
2393
|
+
status: "fail",
|
|
2394
|
+
root,
|
|
2395
|
+
issues: [{ code: "io_error", severity: "error", message: `Cannot read path: ${message}` }],
|
|
2396
|
+
checkedFiles: 0
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
if (!rootStat.isDirectory()) {
|
|
2400
|
+
return {
|
|
2401
|
+
ok: false,
|
|
2402
|
+
status: "fail",
|
|
2403
|
+
root,
|
|
2404
|
+
issues: [
|
|
2405
|
+
{
|
|
2406
|
+
code: "io_error",
|
|
2407
|
+
severity: "error",
|
|
2408
|
+
message: "Evidence verify expects a directory containing evidence.json (unpack ZIP first)."
|
|
2409
|
+
}
|
|
2410
|
+
],
|
|
2411
|
+
checkedFiles: 0
|
|
2412
|
+
};
|
|
2413
|
+
}
|
|
2414
|
+
const manifestPath = path.join(root, EVIDENCE_MANIFEST_FILENAME);
|
|
2415
|
+
let manifestText;
|
|
2416
|
+
try {
|
|
2417
|
+
manifestText = await readFile(manifestPath, "utf-8");
|
|
2418
|
+
} catch {
|
|
2419
|
+
return {
|
|
2420
|
+
ok: false,
|
|
2421
|
+
status: "fail",
|
|
2422
|
+
root,
|
|
2423
|
+
issues: [
|
|
2424
|
+
{
|
|
2425
|
+
code: "manifest_missing",
|
|
2426
|
+
severity: "error",
|
|
2427
|
+
message: `Missing ${EVIDENCE_MANIFEST_FILENAME}`,
|
|
2428
|
+
path: EVIDENCE_MANIFEST_FILENAME
|
|
2429
|
+
}
|
|
2430
|
+
],
|
|
2431
|
+
checkedFiles: 0
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2434
|
+
let manifest;
|
|
2435
|
+
try {
|
|
2436
|
+
manifest = parseEvidenceManifestJson(manifestText);
|
|
2437
|
+
} catch (error) {
|
|
2438
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2439
|
+
return {
|
|
2440
|
+
ok: false,
|
|
2441
|
+
status: "fail",
|
|
2442
|
+
root,
|
|
2443
|
+
issues: [
|
|
2444
|
+
{
|
|
2445
|
+
code: "manifest_invalid",
|
|
2446
|
+
severity: "error",
|
|
2447
|
+
message,
|
|
2448
|
+
path: EVIDENCE_MANIFEST_FILENAME
|
|
2449
|
+
}
|
|
2450
|
+
],
|
|
2451
|
+
checkedFiles: 0
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
if (!manifest.assessment?.status) {
|
|
2455
|
+
issues.push({
|
|
2456
|
+
code: "assessment_missing",
|
|
2457
|
+
severity: "error",
|
|
2458
|
+
message: "Manifest assessment.status is required."
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
if (!manifest.generator?.name || !manifest.generator?.version) {
|
|
2462
|
+
issues.push({
|
|
2463
|
+
code: "provenance_missing",
|
|
2464
|
+
severity: "error",
|
|
2465
|
+
message: "Manifest generator.name and generator.version are required."
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
if (!manifest.source?.runIds?.length) {
|
|
2469
|
+
issues.push({
|
|
2470
|
+
code: "provenance_missing",
|
|
2471
|
+
severity: "error",
|
|
2472
|
+
message: "Manifest source.runIds must be non-empty."
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
const listed = /* @__PURE__ */ new Set();
|
|
2476
|
+
for (const file of manifest.files) {
|
|
2477
|
+
let rel;
|
|
2478
|
+
try {
|
|
2479
|
+
rel = assertEvidenceRelativePath(file.path);
|
|
2480
|
+
} catch (error) {
|
|
2481
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2482
|
+
issues.push({
|
|
2483
|
+
code: "path_unsafe",
|
|
2484
|
+
severity: "error",
|
|
2485
|
+
message,
|
|
2486
|
+
path: file.path
|
|
2487
|
+
});
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
if (rel === EVIDENCE_MANIFEST_FILENAME) {
|
|
2491
|
+
issues.push({
|
|
2492
|
+
code: "manifest_invalid",
|
|
2493
|
+
severity: "error",
|
|
2494
|
+
message: `${EVIDENCE_MANIFEST_FILENAME} must not list itself in files[].`,
|
|
2495
|
+
path: rel
|
|
2496
|
+
});
|
|
2497
|
+
continue;
|
|
2498
|
+
}
|
|
2499
|
+
listed.add(rel);
|
|
2500
|
+
const abs = path.join(root, ...rel.split("/"));
|
|
2501
|
+
let bytes;
|
|
2502
|
+
try {
|
|
2503
|
+
bytes = await readFile(abs);
|
|
2504
|
+
} catch {
|
|
2505
|
+
issues.push({
|
|
2506
|
+
code: "file_missing",
|
|
2507
|
+
severity: "error",
|
|
2508
|
+
message: `Listed file missing: ${rel}`,
|
|
2509
|
+
path: rel
|
|
2510
|
+
});
|
|
2511
|
+
continue;
|
|
2512
|
+
}
|
|
2513
|
+
const actual = sha256Hex(bytes);
|
|
2514
|
+
if (!sha256Equals(file.sha256, actual)) {
|
|
2515
|
+
issues.push({
|
|
2516
|
+
code: "hash_mismatch",
|
|
2517
|
+
severity: "error",
|
|
2518
|
+
message: `SHA-256 mismatch for ${rel}`,
|
|
2519
|
+
path: rel
|
|
2520
|
+
});
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
let onDisk = [];
|
|
2524
|
+
try {
|
|
2525
|
+
onDisk = await listFilesRecursive(root);
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2528
|
+
issues.push({ code: "io_error", severity: "error", message });
|
|
2529
|
+
}
|
|
2530
|
+
for (const rel of onDisk) {
|
|
2531
|
+
if (rel === EVIDENCE_MANIFEST_FILENAME) continue;
|
|
2532
|
+
if (listed.has(rel)) continue;
|
|
2533
|
+
if (unexpectedMode === "ignore") continue;
|
|
2534
|
+
issues.push({
|
|
2535
|
+
code: "file_unexpected",
|
|
2536
|
+
severity: unexpectedMode === "warn" ? "warning" : "error",
|
|
2537
|
+
message: `Unexpected file not listed in manifest: ${rel}`,
|
|
2538
|
+
path: rel
|
|
2539
|
+
});
|
|
2540
|
+
}
|
|
2541
|
+
const hasError = issues.some((issue) => issue.severity === "error");
|
|
2542
|
+
return {
|
|
2543
|
+
ok: !hasError,
|
|
2544
|
+
status: hasError ? "fail" : "pass",
|
|
2545
|
+
root,
|
|
2546
|
+
manifest,
|
|
2547
|
+
issues,
|
|
2548
|
+
checkedFiles: listed.size
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
// packages/core/src/evidence/ci.ts
|
|
2553
|
+
function asMap(value) {
|
|
2554
|
+
if (value instanceof Map) return new Map(value);
|
|
2555
|
+
return new Map(Object.entries(value));
|
|
2556
|
+
}
|
|
2557
|
+
function buildEvidenceCiPackage(input) {
|
|
2558
|
+
const sources = asMap(input.sourceContents);
|
|
2559
|
+
const sourceHashes = input.runIds.map((runId) => ({
|
|
2560
|
+
runId,
|
|
2561
|
+
algorithm: "sha256",
|
|
2562
|
+
hash: sha256Hex(sources.get(runId) ?? "")
|
|
2563
|
+
}));
|
|
2564
|
+
const schemaVersions = /* @__PURE__ */ new Set();
|
|
2565
|
+
for (const content of sources.values()) {
|
|
2566
|
+
for (const version of collectTraceSchemaVersions(content)) {
|
|
2567
|
+
schemaVersions.add(version);
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
for (const version of collectTraceSchemaVersions(input.redactedTraceJsonl)) {
|
|
2571
|
+
schemaVersions.add(version);
|
|
2572
|
+
}
|
|
2573
|
+
const createdAt = input.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
2574
|
+
const evidenceHtml = buildEvidenceHtmlShell({
|
|
2575
|
+
title: "AgentInspect evidence",
|
|
2576
|
+
runIds: input.runIds,
|
|
2577
|
+
assessmentStatus: input.assessmentStatus,
|
|
2578
|
+
sourceStatus: input.sourceStatus,
|
|
2579
|
+
redactionProfile: input.redactionProfile,
|
|
2580
|
+
verificationPolicy: input.redactionProfile,
|
|
2581
|
+
generatorName: "agent-inspect",
|
|
2582
|
+
generatorVersion: input.generatorVersion,
|
|
2583
|
+
createdAt,
|
|
2584
|
+
summaryText: input.summaryText,
|
|
2585
|
+
checkSummary: {
|
|
2586
|
+
aggregateStatus: input.assessmentStatus,
|
|
2587
|
+
runs: input.runIds.map((runId) => ({
|
|
2588
|
+
runId,
|
|
2589
|
+
status: input.assessmentStatus,
|
|
2590
|
+
sourceStatus: input.sourceStatus,
|
|
2591
|
+
errors: input.assessmentStatus === "UNSAFE" || input.assessmentStatus === "UNKNOWN" ? 1 : 0,
|
|
2592
|
+
warnings: input.assessmentStatus === "SAFE WITH WARNINGS" ? 1 : 0,
|
|
2593
|
+
findings: 0
|
|
2594
|
+
}))
|
|
2595
|
+
}
|
|
2596
|
+
});
|
|
2597
|
+
const packaged = [
|
|
2598
|
+
{ path: EVIDENCE_HTML_FILENAME, content: evidenceHtml },
|
|
2599
|
+
{ path: "check-results.json", content: input.checkResultsJson },
|
|
2600
|
+
{ path: "trace.jsonl", content: input.redactedTraceJsonl }
|
|
2601
|
+
];
|
|
2602
|
+
const manifest = buildEvidenceManifest({
|
|
2603
|
+
generatorVersion: input.generatorVersion,
|
|
2604
|
+
runIds: input.runIds,
|
|
2605
|
+
traceSchemaVersions: [...schemaVersions].sort((a, b) => a.localeCompare(b)),
|
|
2606
|
+
sourceHashes,
|
|
2607
|
+
redactionProfile: input.redactionProfile,
|
|
2608
|
+
verificationPolicy: input.redactionProfile,
|
|
2609
|
+
assessmentStatus: input.assessmentStatus,
|
|
2610
|
+
sourceStatus: input.sourceStatus,
|
|
2611
|
+
files: packaged,
|
|
2612
|
+
createdAt,
|
|
2613
|
+
note: EVIDENCE_ASSESSMENT_NOTE
|
|
2614
|
+
});
|
|
2615
|
+
return {
|
|
2616
|
+
"evidence.html": evidenceHtml,
|
|
2617
|
+
"evidence.json": serializeEvidenceManifest(manifest),
|
|
2618
|
+
"check-results.json": input.checkResultsJson,
|
|
2619
|
+
"trace.jsonl": input.redactedTraceJsonl,
|
|
2620
|
+
manifest
|
|
2621
|
+
};
|
|
2622
|
+
}
|
|
2623
|
+
|
|
1471
2624
|
// packages/core/src/suite/types.ts
|
|
1472
2625
|
var DEFAULT_SUITE_CONFIG_NAMES = [
|
|
1473
2626
|
"agent-inspect.suite.json",
|
|
@@ -3099,6 +4252,6 @@ function renderGateReport(result, options = {}) {
|
|
|
3099
4252
|
return renderGateSummaryMarkdown(result);
|
|
3100
4253
|
}
|
|
3101
4254
|
|
|
3102
|
-
export { COHORT_METRIC_IDS, DEFAULT_SUITE_ARTIFACTS_DIR, DEFAULT_SUITE_CONFIG_NAMES, SESSION_WORKFLOW_KEYS, SUITE_TEMPLATE_IDS, aggregateBundleSafeStatus, aggregateSessionCheckResults, analyzeCohort, assertBundlePathContained, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildLocalExplanation, buildPlaceholderArtifact, buildSessionIndex, bundleFailsOnSafety, bundleRunAssetRelativePath, compareCohortAggregates, defaultBundleOutputPath, defaultSuiteConfigTemplate, deriveSessionStatus, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, gateHasThresholds, getSuiteTemplate, groupSessionCohorts, isAgentInspectTrace, listSuiteTemplates, loadSessionRunRecords, loadSuiteConfig, loadTraceMetadataList, normalizeBundleOutputPath, normalizeSuiteConfig, parseCohortMetricList, parseDurationFilter, parseGateList, parseGateNumber, parseGroupBySpec, renderActivitySummaryHuman, renderCohortReport, renderCohortSummaryMarkdown, renderGateGithubStepSummary, renderGateJUnit, renderGateReport, renderGateSummaryMarkdown, renderSuiteReport, renderSuiteReportMarkdown, resolveBundleRunIds, resolveSuiteCaseTrace, resolveSuiteConfigPath, resolveSuiteTemplate, runGate, runSuite, sanitizeBundleRunId, searchTraces, sessionKeyForRun, toMetadataSafeStatus, traceMetasToSessionRunRecords, validateSuiteConfig };
|
|
4255
|
+
export { COHORT_METRIC_IDS, DEFAULT_SUITE_ARTIFACTS_DIR, DEFAULT_SUITE_CONFIG_NAMES, EVIDENCE_ASSESSMENT_NOTE, EVIDENCE_FORMAT_VERSION, EVIDENCE_HTML_FILENAME, EVIDENCE_MANIFEST_FILENAME, EVIDENCE_VIEW_CSS, EVIDENCE_VIEW_IDS, SESSION_WORKFLOW_KEYS, SUITE_TEMPLATE_IDS, aggregateBundleSafeStatus, aggregateSessionCheckResults, analyzeCohort, assertBundlePathContained, assertEvidenceRelativePath, buildActivitySummary, buildBundleMetadata, buildBundleSummaryMarkdown, buildEvidenceCausalFailureViewHtml, buildEvidenceCiPackage, buildEvidenceCircuitViewHtml, buildEvidenceContractsViewHtml, buildEvidenceDiffViewHtml, buildEvidenceFileEntries, buildEvidenceHtmlShell, buildEvidenceHtmlShellFromManifest, buildEvidenceManifest, buildEvidenceOutcomesViewHtml, buildEvidenceProvenanceViewHtml, buildEvidenceSafetyViewHtml, buildEvidenceTimelineViewHtml, buildEvidenceToolsLlmViewHtml, buildEvidenceTreeViewHtml, buildLocalExplanation, buildPlaceholderArtifact, buildSessionIndex, buildZipArchive, bundleFailsOnSafety, bundleRunAssetRelativePath, collectTraceSchemaVersions, compareCohortAggregates, defaultBundleOutputPath, defaultSuiteConfigTemplate, deriveSessionStatus, encodeEmbeddedEvidenceJson, enrichSessionRunRecord, enrichSessionSummary, extractSessionWorkflowMetadata, filterMetasBySessionScope, gateHasThresholds, getSuiteTemplate, groupSessionCohorts, inferEvidenceFileRole, isAgentInspectTrace, isSha256Hex, listSuiteTemplates, loadSessionRunRecords, loadSuiteConfig, loadTraceMetadataList, normalizeBundleOutputPath, normalizeSuiteConfig, parseCohortMetricList, parseDurationFilter, parseEvidenceManifestJson, parseGateList, parseGateNumber, parseGroupBySpec, renderActivitySummaryHuman, renderCohortReport, renderCohortSummaryMarkdown, renderGateGithubStepSummary, renderGateJUnit, renderGateReport, renderGateSummaryMarkdown, renderSuiteReport, renderSuiteReportMarkdown, resolveBundleRunIds, resolveSuiteCaseTrace, resolveSuiteConfigPath, resolveSuiteTemplate, runGate, runSuite, sanitizeBundleRunId, searchTraces, serializeEvidenceManifest, sessionKeyForRun, sha256Equals, sha256Hex, toMetadataSafeStatus, traceMetasToSessionRunRecords, validateEvidenceManifest, validateSuiteConfig, verifyEvidenceDirectory };
|
|
3103
4256
|
//# sourceMappingURL=advanced.mjs.map
|
|
3104
4257
|
//# sourceMappingURL=advanced.mjs.map
|