agentcert 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -42,8 +42,15 @@ npx agentcert push --evidence .agentcert/latest/agentcert-evidence.json
42
42
  ```
43
43
 
44
44
  Add `--push` to `agentcert run` to run locally and upload the resulting bundle
45
- in one command. Project API keys can create runs, record events, and upload
46
- evidence, but cannot approve their own runtime actions.
45
+ in one command. By default, both commands also upload local files referenced by
46
+ the bundle. Reads are confined to `--artifact-root` (the current directory by
47
+ default), path and symlink escapes are rejected, and uploads are capped at 25
48
+ files, 10 MiB per file, and 50 MiB total. Skipped references are reported in
49
+ the CLI and hosted run timeline. Companion uploads are restricted to
50
+ PNG/JPEG/WebP, JSON/JSONL, HTML, PDF, and ZIP; other extensions are skipped
51
+ before they are read. Pass `--no-artifacts` to upload only the JSON bundle.
52
+ Project API keys can create runs, record events, and upload evidence, but
53
+ cannot approve their own runtime actions.
47
54
 
48
55
  Review/export helpers:
49
56
 
@@ -4,21 +4,24 @@ export async function validateEvidenceArtifacts(input, artifactRoot) {
4
4
  if (!input || typeof input !== "object" || Array.isArray(input)) {
5
5
  return { checked: 0, missing: [] };
6
6
  }
7
- const paths = collectArtifactPaths(input, artifactRoot);
8
- const uniquePaths = dedupeArtifactPathEntries(paths).filter((entry) => !looksLikeUrl(entry.path));
7
+ const uniquePaths = collectEvidenceArtifactPaths(input, artifactRoot)
8
+ .filter((entry) => !isRemoteArtifactPath(entry.sourcePath));
9
9
  const missing = [];
10
10
  for (const entry of uniquePaths) {
11
- const fullPath = isAbsolute(entry.path) ? entry.path : resolve(entry.root, entry.path);
11
+ const fullPath = isAbsolute(entry.sourcePath) ? entry.sourcePath : resolve(entry.root, entry.sourcePath);
12
12
  try {
13
13
  await access(fullPath);
14
14
  }
15
15
  catch {
16
- missing.push(entry.path);
16
+ missing.push(entry.sourcePath);
17
17
  }
18
18
  }
19
19
  return { checked: uniquePaths.length, missing };
20
20
  }
21
- function collectArtifactPaths(bundle, artifactRoot) {
21
+ export function collectEvidenceArtifactPaths(input, artifactRoot) {
22
+ if (!input || typeof input !== "object" || Array.isArray(input))
23
+ return [];
24
+ const bundle = input;
22
25
  const paths = [];
23
26
  const productRoots = productArtifactRoots(bundle, artifactRoot);
24
27
  collectStringValues(bundle.artifacts, paths, artifactRoot);
@@ -27,20 +30,25 @@ function collectArtifactPaths(bundle, artifactRoot) {
27
30
  if (result && typeof result === "object" && !Array.isArray(result)) {
28
31
  const resultRecord = result;
29
32
  collectStringValues(resultRecord.artifacts, paths, artifactRoot);
33
+ const product = typeof resultRecord.product === "string" ? resultRecord.product : undefined;
34
+ collectEvidencePaths(resultRecord.evidence, paths, product ? (productRoots.get(product) ?? artifactRoot) : artifactRoot);
30
35
  }
31
36
  }
32
- const evidence = Array.isArray(bundle.evidence) ? bundle.evidence : [];
37
+ collectEvidencePaths(bundle.evidence, paths, artifactRoot, productRoots);
38
+ return dedupeArtifactPathEntries(paths);
39
+ }
40
+ function collectEvidencePaths(input, paths, root, productRoots) {
41
+ const evidence = Array.isArray(input) ? input : [];
33
42
  for (const item of evidence) {
34
43
  if (item && typeof item === "object" && !Array.isArray(item)) {
35
44
  const itemRecord = item;
36
45
  const artifactPath = itemRecord.artifactPath;
37
46
  if (typeof artifactPath === "string" && artifactPath.length > 0) {
38
47
  const source = typeof itemRecord.source === "string" ? itemRecord.source : undefined;
39
- paths.push({ path: artifactPath, root: source ? (productRoots.get(source) ?? artifactRoot) : artifactRoot });
48
+ paths.push({ sourcePath: artifactPath, root: source && productRoots ? (productRoots.get(source) ?? root) : root });
40
49
  }
41
50
  }
42
51
  }
43
- return paths;
44
52
  }
45
53
  function productArtifactRoots(bundle, artifactRoot) {
46
54
  const roots = new Map();
@@ -71,7 +79,7 @@ function collectStringValues(input, paths, root) {
71
79
  }
72
80
  for (const value of Object.values(input)) {
73
81
  if (typeof value === "string" && value.length > 0) {
74
- paths.push({ path: value, root });
82
+ paths.push({ sourcePath: value, root });
75
83
  }
76
84
  }
77
85
  }
@@ -79,7 +87,7 @@ function dedupeArtifactPathEntries(entries) {
79
87
  const seen = new Set();
80
88
  const deduped = [];
81
89
  for (const entry of entries) {
82
- const key = `${entry.root}\0${entry.path}`;
90
+ const key = `${entry.root}\0${entry.sourcePath}`;
83
91
  if (seen.has(key))
84
92
  continue;
85
93
  seen.add(key);
@@ -87,6 +95,6 @@ function dedupeArtifactPathEntries(entries) {
87
95
  }
88
96
  return deduped;
89
97
  }
90
- function looksLikeUrl(value) {
98
+ export function isRemoteArtifactPath(value) {
91
99
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
92
100
  }
package/dist/cli.js CHANGED
@@ -5,6 +5,7 @@ import { createInterface } from "node:readline/promises";
5
5
  import { validateEvidenceArtifacts } from "./artifact-validation.js";
6
6
  import { renderAgentCertBadge } from "./badge.js";
7
7
  import { buildEvidenceBundle } from "./bundle.js";
8
+ import { collectCompanionArtifacts, MAX_REPORTED_COMPANION_ARTIFACT_SKIPS } from "./companion-artifacts.js";
8
9
  import { recordsFromAgentCertResult, evaluateFailureClassifier, renderCorpusSummary, summarizeCorpus, writeReviewedFailureDataset, } from "./corpus.js";
9
10
  import { openCorpusStore, parseCorpusStoreKind } from "./corpus-store.js";
10
11
  import { pushEvidenceToControlPlane, verifyControlPlaneConnection } from "./control-plane.js";
@@ -521,7 +522,7 @@ else {
521
522
  agentcert monitor build --corpus .agentcert/corpus/corpus.jsonl --out .agentcert/latest/monitor.json --subject my-agent
522
523
  agentcert monitor build --store sqlite --sqlite .agentcert/corpus/agentcert.sqlite --out .agentcert/latest/monitor.json --subject my-agent
523
524
  agentcert run --profile public-demo
524
- agentcert push --evidence .agentcert/latest/agentcert-evidence.json --server https://agentcert.example.com --project <project-id>
525
+ agentcert push --evidence .agentcert/latest/agentcert-evidence.json --server https://agentcert.example.com --project <project-id> [--artifact-root .] [--no-artifacts]
525
526
  agentcert run --tripwire .tripwire/latest/tripwire-result.json --push
526
527
  agentcert run --mcpbench .mcpbench/latest/results.json --tripwire .tripwire/latest/tripwire-result.json --onegent .onegent/procurement/audit-packet.json --out .agentcert/latest --corpus .agentcert/corpus/corpus.jsonl --monitor-out .agentcert/latest/monitor.json --reviewed-dataset-out .agentcert/latest/reviewed-failure-dataset.jsonl
527
528
  agentcert release-gate --config agentcert.config.json --strict
@@ -551,6 +552,9 @@ async function pushHostedEvidence(bundle, bytes, fileName) {
551
552
  projectId: readFlag("--project"),
552
553
  apiKey: readFlag("--api-key"),
553
554
  });
555
+ const companions = readBoolFlag("--no-artifacts")
556
+ ? undefined
557
+ : await collectCompanionArtifacts(bundle, resolve(readFlag("--artifact-root") ?? process.cwd()));
554
558
  const result = await pushEvidenceToControlPlane({
555
559
  baseUrl: connection.server,
556
560
  projectId: connection.projectId,
@@ -559,8 +563,19 @@ async function pushHostedEvidence(bundle, bytes, fileName) {
559
563
  evidenceBytes: bytes,
560
564
  fileName,
561
565
  externalId: readFlag("--external-id"),
566
+ companionArtifacts: companions?.artifacts,
567
+ skippedCompanionArtifacts: companions?.skipped,
562
568
  });
563
569
  process.stdout.write(`Hosted run: ${result.runId}\nHosted evidence: ${result.evidenceId}\n`);
570
+ if (companions) {
571
+ process.stdout.write(`Hosted companion artifacts: ${result.artifactsUploaded} uploaded, ${result.artifactsSkipped} skipped, ${result.artifactBytesUploaded} bytes.\n`);
572
+ for (const skipped of companions.skipped.slice(0, MAX_REPORTED_COMPANION_ARTIFACT_SKIPS)) {
573
+ process.stderr.write(`Skipped companion artifact ${skipped.sourcePath}: ${skipped.reason}${skipped.detail ? ` (${skipped.detail})` : ""}.\n`);
574
+ }
575
+ if (companions.skipped.length > MAX_REPORTED_COMPANION_ARTIFACT_SKIPS) {
576
+ process.stderr.write(`${companions.skipped.length - MAX_REPORTED_COMPANION_ARTIFACT_SKIPS} additional skipped artifacts omitted.\n`);
577
+ }
578
+ }
564
579
  }
565
580
  async function promptValue(label) {
566
581
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
@@ -0,0 +1,170 @@
1
+ import { lstat, open, realpath, stat } from "node:fs/promises";
2
+ import { basename, extname, isAbsolute, relative, resolve, sep } from "node:path";
3
+ import { collectEvidenceArtifactPaths, isRemoteArtifactPath, } from "./artifact-validation.js";
4
+ export const DEFAULT_COMPANION_ARTIFACT_LIMITS = {
5
+ maxFiles: 25,
6
+ maxFileBytes: 10 * 1024 * 1024,
7
+ maxTotalBytes: 50 * 1024 * 1024,
8
+ };
9
+ export const MAX_REPORTED_COMPANION_ARTIFACT_SKIPS = 50;
10
+ export async function collectCompanionArtifacts(bundle, artifactRoot, limits = DEFAULT_COMPANION_ARTIFACT_LIMITS) {
11
+ validateLimits(limits);
12
+ const root = await realpath(resolve(artifactRoot));
13
+ const artifacts = [];
14
+ const skipped = [];
15
+ const uploadedRealPaths = new Set();
16
+ let totalBytes = 0;
17
+ for (const entry of collectEvidenceArtifactPaths(bundle, root)) {
18
+ if (isRemoteArtifactPath(entry.sourcePath)) {
19
+ skipped.push(skip(entry, "remote_url"));
20
+ continue;
21
+ }
22
+ const descriptor = describeArtifact(entry.sourcePath);
23
+ if (!descriptor) {
24
+ skipped.push(skip(entry, "unsupported_type", "accepted formats: PNG, JPEG, WebP, JSON, JSONL, HTML, PDF, ZIP"));
25
+ continue;
26
+ }
27
+ if (artifacts.length >= limits.maxFiles) {
28
+ skipped.push(skip(entry, "file_limit", `maximum ${limits.maxFiles} files`));
29
+ continue;
30
+ }
31
+ const candidate = isAbsolute(entry.sourcePath)
32
+ ? resolve(entry.sourcePath)
33
+ : resolve(entry.root, entry.sourcePath);
34
+ if (!isWithinRoot(root, candidate)) {
35
+ skipped.push(skip(entry, "outside_artifact_root"));
36
+ continue;
37
+ }
38
+ let candidateInfo;
39
+ try {
40
+ candidateInfo = await lstat(candidate);
41
+ }
42
+ catch (error) {
43
+ skipped.push(skip(entry, errorCode(error) === "ENOENT" ? "missing" : "unreadable", errorMessage(error)));
44
+ continue;
45
+ }
46
+ if (candidateInfo.isSymbolicLink()) {
47
+ skipped.push(skip(entry, "symlink"));
48
+ continue;
49
+ }
50
+ let resolvedPath;
51
+ try {
52
+ resolvedPath = await realpath(candidate);
53
+ }
54
+ catch (error) {
55
+ skipped.push(skip(entry, errorCode(error) === "ENOENT" ? "missing" : "unreadable", errorMessage(error)));
56
+ continue;
57
+ }
58
+ if (!isWithinRoot(root, resolvedPath)) {
59
+ skipped.push(skip(entry, "outside_artifact_root"));
60
+ continue;
61
+ }
62
+ if (uploadedRealPaths.has(resolvedPath))
63
+ continue;
64
+ let fileInfo;
65
+ try {
66
+ fileInfo = await stat(resolvedPath);
67
+ }
68
+ catch (error) {
69
+ skipped.push(skip(entry, errorCode(error) === "ENOENT" ? "missing" : "unreadable", errorMessage(error)));
70
+ continue;
71
+ }
72
+ if (!fileInfo.isFile()) {
73
+ skipped.push(skip(entry, "not_file"));
74
+ continue;
75
+ }
76
+ if (fileInfo.size > limits.maxFileBytes) {
77
+ skipped.push(skip(entry, "file_too_large", `${fileInfo.size} bytes exceeds ${limits.maxFileBytes}`));
78
+ continue;
79
+ }
80
+ if (totalBytes + fileInfo.size > limits.maxTotalBytes) {
81
+ skipped.push(skip(entry, "total_size_limit", `maximum ${limits.maxTotalBytes} bytes`));
82
+ continue;
83
+ }
84
+ const remainingBytes = limits.maxTotalBytes - totalBytes;
85
+ let readResult;
86
+ try {
87
+ readResult = await readBounded(resolvedPath, Math.min(limits.maxFileBytes, remainingBytes));
88
+ }
89
+ catch (error) {
90
+ skipped.push(skip(entry, "unreadable", errorMessage(error)));
91
+ continue;
92
+ }
93
+ if (readResult.exceeded) {
94
+ const reason = remainingBytes < limits.maxFileBytes ? "total_size_limit" : "file_too_large";
95
+ skipped.push(skip(entry, reason));
96
+ continue;
97
+ }
98
+ artifacts.push({
99
+ sourcePath: normalizeSourcePath(entry.sourcePath),
100
+ fileName: basename(resolvedPath),
101
+ kind: descriptor.kind,
102
+ contentType: descriptor.contentType,
103
+ bytes: readResult.bytes,
104
+ });
105
+ uploadedRealPaths.add(resolvedPath);
106
+ totalBytes += readResult.bytes.byteLength;
107
+ }
108
+ return { artifacts, skipped, totalBytes, limits: { ...limits } };
109
+ }
110
+ function validateLimits(limits) {
111
+ for (const [name, value] of Object.entries(limits)) {
112
+ if (!Number.isSafeInteger(value) || value <= 0)
113
+ throw new Error(`${name} must be a positive integer.`);
114
+ }
115
+ }
116
+ function isWithinRoot(root, candidate) {
117
+ const pathFromRoot = relative(root, candidate);
118
+ return pathFromRoot === "" || (!pathFromRoot.startsWith(`..${sep}`) && pathFromRoot !== ".." && !isAbsolute(pathFromRoot));
119
+ }
120
+ async function readBounded(path, maxBytes) {
121
+ const handle = await open(path, "r");
122
+ const chunks = [];
123
+ let total = 0;
124
+ try {
125
+ while (total <= maxBytes) {
126
+ const capacity = Math.min(64 * 1024, maxBytes + 1 - total);
127
+ const chunk = Buffer.allocUnsafe(capacity);
128
+ const { bytesRead } = await handle.read(chunk, 0, capacity, null);
129
+ if (bytesRead === 0)
130
+ return { bytes: Buffer.concat(chunks, total), exceeded: false };
131
+ chunks.push(chunk.subarray(0, bytesRead));
132
+ total += bytesRead;
133
+ }
134
+ return { bytes: new Uint8Array(), exceeded: true };
135
+ }
136
+ finally {
137
+ await handle.close();
138
+ }
139
+ }
140
+ function describeArtifact(path) {
141
+ const lower = path.toLowerCase();
142
+ const extension = extname(lower);
143
+ if ([".png", ".jpg", ".jpeg", ".webp"].includes(extension)) {
144
+ const imageType = extension === ".jpg" ? "jpeg" : extension.slice(1);
145
+ return { kind: "screenshot", contentType: `image/${imageType}` };
146
+ }
147
+ if (extension === ".zip")
148
+ return { kind: "trace", contentType: "application/zip" };
149
+ if ([".html", ".htm"].includes(extension))
150
+ return { kind: "dom", contentType: "text/html; charset=utf-8" };
151
+ if (extension === ".json")
152
+ return { kind: lower.includes("trace") ? "trace" : lower.includes("dom") ? "dom" : "json", contentType: "application/json" };
153
+ if (extension === ".jsonl")
154
+ return { kind: lower.includes("trace") ? "trace" : "json", contentType: "application/x-ndjson" };
155
+ if (extension === ".pdf")
156
+ return { kind: "report", contentType: "application/pdf" };
157
+ return undefined;
158
+ }
159
+ function normalizeSourcePath(path) {
160
+ return path.replace(/\\/g, "/").slice(0, 1024);
161
+ }
162
+ function skip(entry, reason, detail) {
163
+ return { sourcePath: normalizeSourcePath(entry.sourcePath), reason, ...(detail ? { detail } : {}) };
164
+ }
165
+ function errorCode(error) {
166
+ return error && typeof error === "object" && "code" in error ? String(error.code) : undefined;
167
+ }
168
+ function errorMessage(error) {
169
+ return error instanceof Error ? error.message : String(error);
170
+ }
@@ -1,3 +1,4 @@
1
+ import { MAX_REPORTED_COMPANION_ARTIFACT_SKIPS, } from "./companion-artifacts.js";
1
2
  export class ControlPlaneRequestError extends Error {
2
3
  status;
3
4
  constructor(message, status) {
@@ -85,6 +86,47 @@ export async function pushEvidenceToControlPlane(options) {
85
86
  headers: { ...headers, "content-type": "application/json" },
86
87
  body: new Uint8Array(options.evidenceBytes).buffer,
87
88
  });
89
+ const companionArtifacts = options.companionArtifacts ?? [];
90
+ const skippedArtifacts = options.skippedCompanionArtifacts ?? [];
91
+ let artifactBytesUploaded = 0;
92
+ for (const artifact of companionArtifacts) {
93
+ const artifactQuery = new URLSearchParams({
94
+ fileName: artifact.fileName,
95
+ kind: artifact.kind,
96
+ schemaVersion: options.bundle.schemaVersion,
97
+ runId: run.id,
98
+ sourcePath: artifact.sourcePath,
99
+ });
100
+ await requestJson(request, `${projectUrl}/evidence?${artifactQuery}`, {
101
+ method: "POST",
102
+ headers: { ...headers, "content-type": artifact.contentType },
103
+ body: new Uint8Array(artifact.bytes).buffer,
104
+ });
105
+ artifactBytesUploaded += artifact.bytes.byteLength;
106
+ }
107
+ if (companionArtifacts.length > 0 || skippedArtifacts.length > 0) {
108
+ await requestJson(request, `${projectUrl}/runs/${encodeURIComponent(run.id)}/events`, {
109
+ method: "POST",
110
+ headers: { ...headers, "content-type": "application/json" },
111
+ body: JSON.stringify({
112
+ events: [{
113
+ sequence: 1,
114
+ type: "agentcert.companion_artifacts.processed",
115
+ actor: "agentcert-cli",
116
+ occurredAt: options.bundle.generatedAt,
117
+ payload: {
118
+ uploadedCount: companionArtifacts.length,
119
+ skippedCount: skippedArtifacts.length,
120
+ uploadedBytes: artifactBytesUploaded,
121
+ skipped: skippedArtifacts
122
+ .slice(0, MAX_REPORTED_COMPANION_ARTIFACT_SKIPS)
123
+ .map(({ sourcePath, reason }) => ({ sourcePath, reason })),
124
+ skippedDetailsTruncated: skippedArtifacts.length > MAX_REPORTED_COMPANION_ARTIFACT_SKIPS,
125
+ },
126
+ }],
127
+ }),
128
+ });
129
+ }
88
130
  const firstDivergence = options.bundle.evidence.find((item) => item.severity === "critical" || item.severity === "high")?.message;
89
131
  await requestJson(request, `${projectUrl}/runs/${encodeURIComponent(run.id)}/complete`, {
90
132
  method: "POST",
@@ -98,10 +140,20 @@ export async function pushEvidenceToControlPlane(options) {
98
140
  metadata: {
99
141
  evidenceId: evidence.id,
100
142
  evidenceSchemaVersion: options.bundle.schemaVersion,
143
+ companionArtifactsUploaded: companionArtifacts.length,
144
+ companionArtifactsSkipped: skippedArtifacts.length,
145
+ companionArtifactBytesUploaded: artifactBytesUploaded,
101
146
  },
102
147
  }),
103
148
  });
104
- return { runId: run.id, evidenceId: evidence.id, externalId };
149
+ return {
150
+ runId: run.id,
151
+ evidenceId: evidence.id,
152
+ externalId,
153
+ artifactsUploaded: companionArtifacts.length,
154
+ artifactsSkipped: skippedArtifacts.length,
155
+ artifactBytesUploaded,
156
+ };
105
157
  }
106
158
  function hostedRunKind(bundle) {
107
159
  const products = new Set(bundle.summary.products);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentcert",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Assurance release gates, runtime evidence, and regression CI for AI agents.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",