@cygnuxlabs/tracekit 1.5.2 → 1.5.3

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
@@ -140,7 +140,8 @@ and streams (`messages.stream()`, `streamText`) work as without Tracekit. Offlin
140
140
  keep the run's `runId` and `runToken` with the framework's saved state and re-attach:
141
141
  `new RunHandle(new Client(), { run_id, run_token })`; close that client when you are done with it
142
142
  (`run.client.close()`), or re-attach every run through one shared client. `process.exit()` skips all of this: close
143
- first.
143
+ first. The [offline Vercel AI resume example](examples/v2_vercel_ai_resume.mjs) saves the run and messages, prints
144
+ the approval command, and resumes in a second process.
144
145
  - **The LLM gateway.** Point the provider at it with the run in a header, e.g. OpenAI Agents
145
146
  `setDefaultOpenAIClient(new OpenAI({ baseURL, apiKey: <gateway token>, defaultHeaders: { "X-Tracekit-Run":
146
147
  `${run.runId}.${run.runToken}` } }))`, Vercel AI `createOpenAI({ baseURL, apiKey, headers })`. Register the run as
@@ -1,7 +1,7 @@
1
1
  export { MAX_ENTRIES, MAX_ENTRY, MAX_TOTAL, Unusable, readZip } from "./zip.js";
2
2
  export { StrictJSONError, canonicalize, strictParse, strictParseBytes } from "./jcs.js";
3
3
  /** The bundle format version this verifier implements: a bundle needing a later one is UNVERIFIABLE. */
4
- export declare const VERSION = "1.5.2";
4
+ export declare const VERSION = "1.5.3";
5
5
  export declare const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
6
6
  /** The integrity of a trust config that can't be used: nothing in the bundle was checked. */
7
7
  export declare const TRUST_UNUSABLE = "UNVERIFIABLE (the trust file can't be used)";
@@ -25,7 +25,7 @@ import { BadZipFile, MAX_ENTRY, Unusable, readZip } from "./zip.js";
25
25
  export { MAX_ENTRIES, MAX_ENTRY, MAX_TOTAL, Unusable, readZip } from "./zip.js";
26
26
  export { StrictJSONError, canonicalize, strictParse, strictParseBytes } from "./jcs.js";
27
27
  /** The bundle format version this verifier implements: a bundle needing a later one is UNVERIFIABLE. */
28
- export const VERSION = "1.5.2";
28
+ export const VERSION = "1.5.3";
29
29
  /** The browser verifier of the latest release (docs/RELEASING.md). */
30
30
  const PAGE = "https://cygnux-labs.github.io/Tracekit/verify/";
31
31
  export const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
@@ -78,15 +78,25 @@ export class Report {
78
78
  }
79
79
  }
80
80
  const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
81
- /** The manifest check's detail: on a failure, the files that differ from the manifest (the first 5) and how. */
82
- function manifestDetail(listed, hashes, bad) {
81
+ /** The files a bundle may hold besides its manifest (format-v2.md §9): no code, no trust config; a misnamed run part or
82
+ * policy snapshot fails a line of its own (run parts, policy snapshot). */
83
+ const FILES = new RegExp("^(runs/[0-9a-f]{32}(\\.part-[0-9]+)?\\.jsonl|keys/records\\.jsonl|proofs/records\\.json"
84
+ + "|checkpoints/(registry-)?[0-9]+\\.note|rekor/[0-9]+\\.json|tsa/[0-9]+\\.tsr|policies/.+"
85
+ + "|registry/(run-set\\.json|records\\.jsonl))$");
86
+ /** The manifest check's detail: on a failure, the files that differ from the manifest (the first 5) and how, and the
87
+ * files no bundle holds (the first 5). */
88
+ function manifestDetail(listed, hashes, bad, other) {
83
89
  if (!isObj(listed))
84
90
  return "the manifest lists no files";
85
- if (bad.length === 0)
91
+ if (!bad.length && !other.length)
86
92
  return "every file is listed with its SHA-256 and nothing else is in the bundle";
87
- const how = bad.slice(0, 5).map((n) => `${n} (${Object.hasOwn(listed, n) && hashes.has(n) ? "changed"
88
- : Object.hasOwn(listed, n) ? "missing" : "not listed"})`);
89
- return "files differ from the manifest: " + how.join(", ") + (bad.length > 5 ? ` and ${bad.length - 5} more` : "");
93
+ const more = (names) => names.length > 5 ? ` and ${names.length - 5} more` : "", out = [];
94
+ if (bad.length)
95
+ out.push("files differ from the manifest: " + bad.slice(0, 5).map((n) => `${n} (${Object.hasOwn(listed, n)
96
+ && hashes.has(n) ? "changed" : Object.hasOwn(listed, n) ? "missing" : "not listed"})`).join(", ") + more(bad));
97
+ if (other.length)
98
+ out.push("files no bundle holds: " + other.slice(0, 5).join(", ") + more(other));
99
+ return out.join("; ");
90
100
  }
91
101
  /** A check's detail: what it found when it passed, else how many problems in what (its lines say which), so a failed
92
102
  * line never reads as a pass. */
@@ -336,7 +346,8 @@ async function check(rep, manifest, files, trust, floats) {
336
346
  hashes.set(n, await sha256hex(b));
337
347
  const bad = isObj(listed) ? [...new Set([...Object.keys(listed), ...hashes.keys()])]
338
348
  .filter((n) => !(Object.hasOwn(listed, n) && hashes.get(n) === listed[n])).sort() : [];
339
- rep.check("manifest", isObj(listed) && bad.length === 0, manifestDetail(listed, hashes, bad));
349
+ const other = [...hashes.keys()].filter((n) => !FILES.test(n)).sort();
350
+ rep.check("manifest", isObj(listed) && !bad.length && !other.length, manifestDetail(listed, hashes, bad, other));
340
351
  // the checkpoint: the only thing the records' trust hangs on
341
352
  const proofs = json("proofs/records.json");
342
353
  const name = at(proofs, "checkpoint");
@@ -436,7 +447,9 @@ async function check(rep, manifest, files, trust, floats) {
436
447
  const runSet = files.has("registry/run-set.json");
437
448
  const runs = new Map(), problems = [], chain = [], outside = [];
438
449
  const layout = [], seen = new Set();
450
+ let unchecked = 0;
439
451
  for (const [name, parts] of names) {
452
+ const marks = problems.length + chain.length;
440
453
  const pieces = parts.map(jsonl), records = pieces.flat(), whole = parts.length === 1 && parts[0] === name;
441
454
  runs.set(name, records);
442
455
  extend(layout, parted(name, parts, pieces));
@@ -448,15 +461,24 @@ async function check(rep, manifest, files, trust, floats) {
448
461
  if (seen.has(key))
449
462
  chain.push(`run ${repr(cut(runId, 200))} of tenant ${repr(cut(tenant, 64))} again in ${name}`);
450
463
  seen.add(key);
464
+ const named = await runName(tenant, runId); // §9: a run's file is named by its tenant and run_id
465
+ if (named !== name)
466
+ chain.push(`run ${repr(cut(runId, 200))} of tenant ${repr(cut(tenant, 64))} in ${name}: its file is ${named}`);
451
467
  }
452
468
  for (const [i, r] of records.entries()) {
453
- await checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), problems);
454
- const e = r.event, prev = i ? records[i - 1] : null;
469
+ if (problems.length + chain.length - marks >= RUN_PROBLEMS) {
470
+ unchecked += records.length - i;
471
+ chain.push(`run ${repr(cut(str(get(head, "run_id")), 200))}: ${records.length - i} record(s) from run_seq ${i} on `
472
+ + `not checked, after ${RUN_PROBLEMS} problems in the run`);
473
+ break;
474
+ }
475
+ const e = at(r, "event"), prev = i ? records[i - 1] : null; // its link to the one before first: it costs nothing
455
476
  if (!same(get(e, "run_seq"), i) || !same(get(e, "run_prev_hash"), prev ? at(prev, "hash") : ZERO_HASH)
456
477
  || !same([get(e, "tenant"), get(e, "run_id")], [get(head, "tenant"), get(head, "run_id")])
457
478
  || prev && (num(at(e, "seq")) <= num(at(at(prev, "event"), "seq")) || get(prev.event, "type") === "run.final"))
458
479
  chain.push(`run ${repr(cut(str(get(head, "run_id")), 200))} run_seq ${i} (seq ${repr(get(e, "seq"))}) does not `
459
480
  + "continue the run");
481
+ await checkRecord(r, keysAt(num(at(e, "seq"))), problems);
460
482
  }
461
483
  if (!(await included(records[0]) && await included(records.at(-1))))
462
484
  outside.push(`run ${repr(cut(str(get(head, "run_id")), 200))}` + (!whole && await included(records[0])
@@ -467,9 +489,9 @@ async function check(rep, manifest, files, trust, floats) {
467
489
  rep.unsupport("tracekit why findings");
468
490
  else if (runs.size !== 1 && !runSet && !aboutOne(runs))
469
491
  throw new ValueError("a v2 bundle holds exactly one run, one run with its findings and replay runs, or a run-set");
470
- let retired = [], provenTo = -1, regCosigs = [];
492
+ let retired = [], provenTo = -1, regCosigs = [], pointed = [];
471
493
  if (runSet) {
472
- [retired, provenTo, regCosigs] = await checkRunSet(rep, json("registry/run-set.json"), jsonl, file, trust, witnesses, origin, size, runs, included, (r, p) => checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), p), floats);
494
+ [retired, provenTo, regCosigs, pointed] = await checkRunSet(rep, json("registry/run-set.json"), jsonl, file, trust, witnesses, origin, size, runs, included, (r, p) => checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), p), floats);
473
495
  const keyed = new Set(keyRecords.map((r) => `${at(at(r, "event"), "seq")} ${at(r, "hash")}`));
474
496
  extend(keyProblems, retired.filter(([seq, h]) => !keyed.has(`${seq} ${h}`))
475
497
  .map(([seq]) => `seq ${seq}: key.retire withheld (the registry log has it)`));
@@ -492,7 +514,8 @@ async function check(rep, manifest, files, trust, floats) {
492
514
  if (inParts.length)
493
515
  rep.check("run parts", !layout.length, found(layout, `${inParts.length} run(s) in ${inParts.reduce((a, b) => a + b, 0)} `
494
516
  + "parts, each part continuing the one before it", `the parts of ${inParts.length} run(s)`), layout);
495
- rep.check("signatures", !problems.length, found(problems, `${every.length} record(s), keys valid at their position`, `${every.length} record(s)`), problems);
517
+ rep.check("signatures", !problems.length, found(problems, `${every.length - unchecked} record(s), keys valid at their `
518
+ + "position", `${every.length - unchecked} record(s)`), problems);
496
519
  const only = runs.size === 1 ? [...runs.values()][0][0].event : null;
497
520
  rep.check("run chain", !chain.length, found(chain, only ? `run ${repr(cut(str(get(only, "run_id")), 200))} of tenant `
498
521
  + `${repr(get(only, "tenant"))}, contiguous from run_seq 0` : `${runs.size} run(s), each contiguous from run_seq 0`, `the chain of ${runs.size} run(s)`), chain);
@@ -644,7 +667,6 @@ async function check(rep, manifest, files, trust, floats) {
644
667
  if (glass.length)
645
668
  rep.check("break-glass approvals", false, `${glass.length} approval(s) answered under the break-glass role`, glass.map((e) => `seq ${e.seq}: ${str(at(e.data, "decision"))} ${str(get(e.data, "approval_id"))} by `
646
669
  + `${cut(text(at(e.data, "approver")), 256)}: ${repr(cut(str(get(e.data, "reason")), 200))}`).slice(0, 20), true);
647
- const pointed = runSet ? jsonl("registry/records.jsonl") : []; // the records a run-set's leaves name
648
670
  checkExt(rep, [...new Map([...keyRecords, ...pointed, ...every].map((r) => [at(at(r, "event"), "seq"), r.event]))
649
671
  .values()], get(manifest, "verifier_version"));
650
672
  }
@@ -700,6 +722,8 @@ function checkOpenshellPolicy(rep, events) {
700
722
  const EXT_CHECKS = new Map([["amended", checkAmended],
701
723
  ["openshell.policy", checkOpenshellPolicy]]);
702
724
  const MAX_UNREAD = 20; // `not interpreted` lines, one per ext name; the rest on one line
725
+ /** A run's problems past which its later records go unchecked: forged records cost a verifier little. */
726
+ const RUN_PROBLEMS = 20;
703
727
  /** The ext names an event carries: its `ext` field's keys, and an `ext` record's name. */
704
728
  const extNames = (e) => [...Object.keys(isObj(get(e, "ext")) ? e.ext : {}),
705
729
  ...get(e, "type") === "ext" ? [at(at(e, "data"), "name")] : []];
@@ -1130,8 +1154,8 @@ export async function verifyRecord(r, keys, algs) {
1130
1154
  return await verifyV2(r.alg, key, bytes(message), sig) ? null : "bad signature";
1131
1155
  }
1132
1156
  /** §7: the run-set line (COMPLETE or INCOMPLETE) and the log tail line. Returns the (seq, hash) of every key.retire the
1133
- * range points to, the highest seq it points to when it starts at registry size 0 (else -1), and the pinned
1134
- * cosignatures of each registry note. */
1157
+ * range points to, the highest seq it points to when it starts at registry size 0 (else -1), the pinned cosignatures of
1158
+ * each registry note, and the records of registry/records.jsonl it checked, each the one its leaf points to. */
1135
1159
  async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size, runs, included, checkRecord, floats) {
1136
1160
  const problems = [], tsalt = b64decode(at(rs, "tenant_salt"));
1137
1161
  const lo = at(rs, "from"), hi = at(rs, "to"), regOrigin = await registryOrigin(origin, tsalt);
@@ -1141,7 +1165,7 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
1141
1165
  const span = `registry ${bound("from", lo)}..${bound("to", hi)}`;
1142
1166
  if (![lo, hi].every((n) => Number.isSafeInteger(n)) || floats.get(rs)?.has("from") || floats.get(rs)?.has("to")) {
1143
1167
  rep.check("run-set", false, `INCOMPLETE, ${span}`, ["the registry range is not two integers"]);
1144
- return [[], -1, []];
1168
+ return [[], -1, [], []];
1145
1169
  }
1146
1170
  // the registry notes are signed by the record log's own pinned key, under the registry origin
1147
1171
  const vkeys = [];
@@ -1172,14 +1196,18 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
1172
1196
  }
1173
1197
  if (problems.length || !(0 <= lo && lo <= hi) || hi === 0) {
1174
1198
  rep.check("run-set", false, `INCOMPLETE, ${span}`, problems.length ? problems : [`bad registry range ${lo}..${hi}`]);
1175
- return [[], -1, regCosigs];
1199
+ return [[], -1, regCosigs, []];
1176
1200
  }
1177
1201
  if (0 < lo && lo < hi && !await verifyConsistency(lo, hi, roots.get(lo), roots.get(hi), list(at(rs, "consistency")).map(b64decode)))
1178
1202
  problems.push(`registry checkpoint ${lo} is not a prefix of ${hi}`);
1203
+ else if (!(0 < lo && lo < hi) && !same(at(rs, "consistency"), [])) // a range from 0, or empty, has no consistency proof
1204
+ problems.push(`a consistency proof for registry ${lo}..${hi}, which has none`);
1179
1205
  const leaves = list(at(rs, "leaves"));
1180
- const pointed = new Map(jsonl("registry/records.jsonl").map((r) => [at(at(r, "event"), "seq"), r]));
1206
+ const lines = jsonl("registry/records.jsonl"), pointed = [];
1181
1207
  if (leaves.length !== hi - lo)
1182
1208
  problems.push(`${hi - lo} leaves in ${lo}..${hi}, ${leaves.length} in the bundle: a leaf is missing`);
1209
+ if (lines.length !== leaves.length) // §9: the record each leaf points to, in leaf order, and nothing else
1210
+ problems.push(`${lines.length} record(s) in registry/records.jsonl for ${leaves.length} leaves: one per leaf, in leaf order`);
1183
1211
  const registered = new Map(), finals = new Map(), retired = [], targets = new Set();
1184
1212
  const gaps = new Map();
1185
1213
  let closed = null, tenant = null, top = -1;
@@ -1190,15 +1218,16 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
1190
1218
  continue;
1191
1219
  }
1192
1220
  const { type, runHash: rh, logId, seq, hash } = parseLeaf(leaf);
1193
- const r = pointed.get(seq) ?? null, e = r && truthy(r) ? at(r, "event") : r;
1194
- if (r === null || at(r, "hash") !== hash || at(e, "type") !== type || at(e, "log_id") !== logId || !await included(r)
1221
+ top = Math.max(top, seq); // the registry note proves the leaf, whatever record the bundle has for it
1222
+ const r = j < lines.length ? lines[j] : null, e = r && truthy(r) ? at(r, "event") : r;
1223
+ if (r === null || !same(at(e, "seq"), seq) || at(r, "hash") !== hash || at(e, "type") !== type || at(e, "log_id") !== logId || !await included(r)
1195
1224
  || !equal(await runHash(tsalt, text(at(e, "run_id"))), rh)
1196
1225
  || !SIGNER_LEAVES.includes(type) && tenant !== null && !same(tenant, at(e, "tenant"))) {
1197
1226
  problems.push(`leaf ${i} points to a missing or different record (seq ${seq})`);
1198
1227
  continue;
1199
1228
  }
1200
1229
  await checkRecord(r, problems);
1201
- top = Math.max(top, seq);
1230
+ pointed.push(r);
1202
1231
  if (type === "run.registered" || type === "run.final")
1203
1232
  targets.add(await runName(at(e, "tenant"), e.run_id));
1204
1233
  if (type === "run.registered") {
@@ -1242,7 +1271,7 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
1242
1271
  rep.check("tenant-level gaps", false, `${[...gaps.values()].reduce((a, b) => a + b, 0)} in the range: ${counted}`, [], true);
1243
1272
  rep.check("log tail", truthy(closed), truthy(closed) ? `none: log.closed at seq ${str(closed.seq)} is the last record`
1244
1273
  : `records after tree size ${size} are unproven (no log.closed in the range)`, [], true);
1245
- return [retired, lo === 0 ? top : -1, regCosigs];
1274
+ return [retired, lo === 0 ? top : -1, regCosigs, pointed];
1246
1275
  }
1247
1276
  /** A run's part: the run's file name, the part's number (tracekit/bundle_v2.py PART). */
1248
1277
  const PART = /^(runs\/.+)\.part-([0-9]+)\.jsonl$/;
@@ -125,7 +125,7 @@ export async function readZip(data) {
125
125
  need(start, e.csize);
126
126
  const body = data.subarray(start, start + e.csize);
127
127
  const cap = Math.min(MAX_ENTRY, MAX_TOTAL - total);
128
- const limit = Math.min(e.usize, cap + 1);
128
+ const limit = Math.min(e.usize + 1, cap + 1); // a byte past the stated size: a stream that holds more doesn't match
129
129
  let out;
130
130
  if (e.method === 0)
131
131
  out = body.subarray(0, limit);
package/dist/verify.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-6+Xm0MJoXjjSMX5iSnqKkEjeXQadLU2RxbMTNRcZVRw='; style-src 'sha256-41aEPfNKIK0vxFn3JTgv68G+SOVBoDbHT4QPLHGL360='; worker-src blob:; connect-src 'none'">
6
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'sha256-pHODtIZ5E17dkYUp0gizDKpAgL3yIMpkg9pQvaEFTaw='; style-src 'sha256-41aEPfNKIK0vxFn3JTgv68G+SOVBoDbHT4QPLHGL360='; worker-src blob:; connect-src 'none'">
7
7
  <title>tracekit verify</title>
8
8
  <style>
9
9
  :root {
@@ -1120,7 +1120,7 @@ async function readZip(data) {
1120
1120
  need(start, e.csize);
1121
1121
  const body = data.subarray(start, start + e.csize);
1122
1122
  const cap = Math.min(MAX_ENTRY, MAX_TOTAL - total);
1123
- const limit = Math.min(e.usize, cap + 1);
1123
+ const limit = Math.min(e.usize + 1, cap + 1); // a byte past the stated size: a stream that holds more doesn't match
1124
1124
  let out;
1125
1125
  if (e.method === 0)
1126
1126
  out = body.subarray(0, limit);
@@ -1175,7 +1175,7 @@ const { BadZipFile: BadZipFile, MAX_ENTRY: MAX_ENTRY, Unusable: Unusable, readZi
1175
1175
 
1176
1176
 
1177
1177
  /** The bundle format version this verifier implements: a bundle needing a later one is UNVERIFIABLE. */
1178
- const VERSION = "1.5.2";
1178
+ const VERSION = "1.5.3";
1179
1179
  /** The browser verifier of the latest release (docs/RELEASING.md). */
1180
1180
  const PAGE = "https://cygnux-labs.github.io/Tracekit/verify/";
1181
1181
  const EXIT_OK = 0, EXIT_FAIL = 1, EXIT_BAD = 2, EXIT_WARN = 3;
@@ -1228,15 +1228,25 @@ class Report {
1228
1228
  }
1229
1229
  }
1230
1230
  const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1231
- /** The manifest check's detail: on a failure, the files that differ from the manifest (the first 5) and how. */
1232
- function manifestDetail(listed, hashes, bad) {
1231
+ /** The files a bundle may hold besides its manifest (format-v2.md §9): no code, no trust config; a misnamed run part or
1232
+ * policy snapshot fails a line of its own (run parts, policy snapshot). */
1233
+ const FILES = new RegExp("^(runs/[0-9a-f]{32}(\\.part-[0-9]+)?\\.jsonl|keys/records\\.jsonl|proofs/records\\.json"
1234
+ + "|checkpoints/(registry-)?[0-9]+\\.note|rekor/[0-9]+\\.json|tsa/[0-9]+\\.tsr|policies/.+"
1235
+ + "|registry/(run-set\\.json|records\\.jsonl))$");
1236
+ /** The manifest check's detail: on a failure, the files that differ from the manifest (the first 5) and how, and the
1237
+ * files no bundle holds (the first 5). */
1238
+ function manifestDetail(listed, hashes, bad, other) {
1233
1239
  if (!isObj(listed))
1234
1240
  return "the manifest lists no files";
1235
- if (bad.length === 0)
1241
+ if (!bad.length && !other.length)
1236
1242
  return "every file is listed with its SHA-256 and nothing else is in the bundle";
1237
- const how = bad.slice(0, 5).map((n) => `${n} (${Object.hasOwn(listed, n) && hashes.has(n) ? "changed"
1238
- : Object.hasOwn(listed, n) ? "missing" : "not listed"})`);
1239
- return "files differ from the manifest: " + how.join(", ") + (bad.length > 5 ? ` and ${bad.length - 5} more` : "");
1243
+ const more = (names) => names.length > 5 ? ` and ${names.length - 5} more` : "", out = [];
1244
+ if (bad.length)
1245
+ out.push("files differ from the manifest: " + bad.slice(0, 5).map((n) => `${n} (${Object.hasOwn(listed, n)
1246
+ && hashes.has(n) ? "changed" : Object.hasOwn(listed, n) ? "missing" : "not listed"})`).join(", ") + more(bad));
1247
+ if (other.length)
1248
+ out.push("files no bundle holds: " + other.slice(0, 5).join(", ") + more(other));
1249
+ return out.join("; ");
1240
1250
  }
1241
1251
  /** A check's detail: what it found when it passed, else how many problems in what (its lines say which), so a failed
1242
1252
  * line never reads as a pass. */
@@ -1486,7 +1496,8 @@ async function check(rep, manifest, files, trust, floats) {
1486
1496
  hashes.set(n, await sha256hex(b));
1487
1497
  const bad = isObj(listed) ? [...new Set([...Object.keys(listed), ...hashes.keys()])]
1488
1498
  .filter((n) => !(Object.hasOwn(listed, n) && hashes.get(n) === listed[n])).sort() : [];
1489
- rep.check("manifest", isObj(listed) && bad.length === 0, manifestDetail(listed, hashes, bad));
1499
+ const other = [...hashes.keys()].filter((n) => !FILES.test(n)).sort();
1500
+ rep.check("manifest", isObj(listed) && !bad.length && !other.length, manifestDetail(listed, hashes, bad, other));
1490
1501
  // the checkpoint: the only thing the records' trust hangs on
1491
1502
  const proofs = json("proofs/records.json");
1492
1503
  const name = at(proofs, "checkpoint");
@@ -1586,7 +1597,9 @@ async function check(rep, manifest, files, trust, floats) {
1586
1597
  const runSet = files.has("registry/run-set.json");
1587
1598
  const runs = new Map(), problems = [], chain = [], outside = [];
1588
1599
  const layout = [], seen = new Set();
1600
+ let unchecked = 0;
1589
1601
  for (const [name, parts] of names) {
1602
+ const marks = problems.length + chain.length;
1590
1603
  const pieces = parts.map(jsonl), records = pieces.flat(), whole = parts.length === 1 && parts[0] === name;
1591
1604
  runs.set(name, records);
1592
1605
  extend(layout, parted(name, parts, pieces));
@@ -1598,15 +1611,24 @@ async function check(rep, manifest, files, trust, floats) {
1598
1611
  if (seen.has(key))
1599
1612
  chain.push(`run ${repr(cut(runId, 200))} of tenant ${repr(cut(tenant, 64))} again in ${name}`);
1600
1613
  seen.add(key);
1614
+ const named = await runName(tenant, runId); // §9: a run's file is named by its tenant and run_id
1615
+ if (named !== name)
1616
+ chain.push(`run ${repr(cut(runId, 200))} of tenant ${repr(cut(tenant, 64))} in ${name}: its file is ${named}`);
1601
1617
  }
1602
1618
  for (const [i, r] of records.entries()) {
1603
- await checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), problems);
1604
- const e = r.event, prev = i ? records[i - 1] : null;
1619
+ if (problems.length + chain.length - marks >= RUN_PROBLEMS) {
1620
+ unchecked += records.length - i;
1621
+ chain.push(`run ${repr(cut(str(get(head, "run_id")), 200))}: ${records.length - i} record(s) from run_seq ${i} on `
1622
+ + `not checked, after ${RUN_PROBLEMS} problems in the run`);
1623
+ break;
1624
+ }
1625
+ const e = at(r, "event"), prev = i ? records[i - 1] : null; // its link to the one before first: it costs nothing
1605
1626
  if (!same(get(e, "run_seq"), i) || !same(get(e, "run_prev_hash"), prev ? at(prev, "hash") : ZERO_HASH)
1606
1627
  || !same([get(e, "tenant"), get(e, "run_id")], [get(head, "tenant"), get(head, "run_id")])
1607
1628
  || prev && (num(at(e, "seq")) <= num(at(at(prev, "event"), "seq")) || get(prev.event, "type") === "run.final"))
1608
1629
  chain.push(`run ${repr(cut(str(get(head, "run_id")), 200))} run_seq ${i} (seq ${repr(get(e, "seq"))}) does not `
1609
1630
  + "continue the run");
1631
+ await checkRecord(r, keysAt(num(at(e, "seq"))), problems);
1610
1632
  }
1611
1633
  if (!(await included(records[0]) && await included(records.at(-1))))
1612
1634
  outside.push(`run ${repr(cut(str(get(head, "run_id")), 200))}` + (!whole && await included(records[0])
@@ -1617,9 +1639,9 @@ async function check(rep, manifest, files, trust, floats) {
1617
1639
  rep.unsupport("tracekit why findings");
1618
1640
  else if (runs.size !== 1 && !runSet && !aboutOne(runs))
1619
1641
  throw new ValueError("a v2 bundle holds exactly one run, one run with its findings and replay runs, or a run-set");
1620
- let retired = [], provenTo = -1, regCosigs = [];
1642
+ let retired = [], provenTo = -1, regCosigs = [], pointed = [];
1621
1643
  if (runSet) {
1622
- [retired, provenTo, regCosigs] = await checkRunSet(rep, json("registry/run-set.json"), jsonl, file, trust, witnesses, origin, size, runs, included, (r, p) => checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), p), floats);
1644
+ [retired, provenTo, regCosigs, pointed] = await checkRunSet(rep, json("registry/run-set.json"), jsonl, file, trust, witnesses, origin, size, runs, included, (r, p) => checkRecord(r, keysAt(num(at(at(r, "event"), "seq"))), p), floats);
1623
1645
  const keyed = new Set(keyRecords.map((r) => `${at(at(r, "event"), "seq")} ${at(r, "hash")}`));
1624
1646
  extend(keyProblems, retired.filter(([seq, h]) => !keyed.has(`${seq} ${h}`))
1625
1647
  .map(([seq]) => `seq ${seq}: key.retire withheld (the registry log has it)`));
@@ -1642,7 +1664,8 @@ async function check(rep, manifest, files, trust, floats) {
1642
1664
  if (inParts.length)
1643
1665
  rep.check("run parts", !layout.length, found(layout, `${inParts.length} run(s) in ${inParts.reduce((a, b) => a + b, 0)} `
1644
1666
  + "parts, each part continuing the one before it", `the parts of ${inParts.length} run(s)`), layout);
1645
- rep.check("signatures", !problems.length, found(problems, `${every.length} record(s), keys valid at their position`, `${every.length} record(s)`), problems);
1667
+ rep.check("signatures", !problems.length, found(problems, `${every.length - unchecked} record(s), keys valid at their `
1668
+ + "position", `${every.length - unchecked} record(s)`), problems);
1646
1669
  const only = runs.size === 1 ? [...runs.values()][0][0].event : null;
1647
1670
  rep.check("run chain", !chain.length, found(chain, only ? `run ${repr(cut(str(get(only, "run_id")), 200))} of tenant `
1648
1671
  + `${repr(get(only, "tenant"))}, contiguous from run_seq 0` : `${runs.size} run(s), each contiguous from run_seq 0`, `the chain of ${runs.size} run(s)`), chain);
@@ -1794,7 +1817,6 @@ async function check(rep, manifest, files, trust, floats) {
1794
1817
  if (glass.length)
1795
1818
  rep.check("break-glass approvals", false, `${glass.length} approval(s) answered under the break-glass role`, glass.map((e) => `seq ${e.seq}: ${str(at(e.data, "decision"))} ${str(get(e.data, "approval_id"))} by `
1796
1819
  + `${cut(text(at(e.data, "approver")), 256)}: ${repr(cut(str(get(e.data, "reason")), 200))}`).slice(0, 20), true);
1797
- const pointed = runSet ? jsonl("registry/records.jsonl") : []; // the records a run-set's leaves name
1798
1820
  checkExt(rep, [...new Map([...keyRecords, ...pointed, ...every].map((r) => [at(at(r, "event"), "seq"), r.event]))
1799
1821
  .values()], get(manifest, "verifier_version"));
1800
1822
  }
@@ -1850,6 +1872,8 @@ function checkOpenshellPolicy(rep, events) {
1850
1872
  const EXT_CHECKS = new Map([["amended", checkAmended],
1851
1873
  ["openshell.policy", checkOpenshellPolicy]]);
1852
1874
  const MAX_UNREAD = 20; // `not interpreted` lines, one per ext name; the rest on one line
1875
+ /** A run's problems past which its later records go unchecked: forged records cost a verifier little. */
1876
+ const RUN_PROBLEMS = 20;
1853
1877
  /** The ext names an event carries: its `ext` field's keys, and an `ext` record's name. */
1854
1878
  const extNames = (e) => [...Object.keys(isObj(get(e, "ext")) ? e.ext : {}),
1855
1879
  ...get(e, "type") === "ext" ? [at(at(e, "data"), "name")] : []];
@@ -2280,8 +2304,8 @@ async function verifyRecord(r, keys, algs) {
2280
2304
  return await verifyV2(r.alg, key, bytes(message), sig) ? null : "bad signature";
2281
2305
  }
2282
2306
  /** §7: the run-set line (COMPLETE or INCOMPLETE) and the log tail line. Returns the (seq, hash) of every key.retire the
2283
- * range points to, the highest seq it points to when it starts at registry size 0 (else -1), and the pinned
2284
- * cosignatures of each registry note. */
2307
+ * range points to, the highest seq it points to when it starts at registry size 0 (else -1), the pinned cosignatures of
2308
+ * each registry note, and the records of registry/records.jsonl it checked, each the one its leaf points to. */
2285
2309
  async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size, runs, included, checkRecord, floats) {
2286
2310
  const problems = [], tsalt = b64decode(at(rs, "tenant_salt"));
2287
2311
  const lo = at(rs, "from"), hi = at(rs, "to"), regOrigin = await registryOrigin(origin, tsalt);
@@ -2291,7 +2315,7 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
2291
2315
  const span = `registry ${bound("from", lo)}..${bound("to", hi)}`;
2292
2316
  if (![lo, hi].every((n) => Number.isSafeInteger(n)) || floats.get(rs)?.has("from") || floats.get(rs)?.has("to")) {
2293
2317
  rep.check("run-set", false, `INCOMPLETE, ${span}`, ["the registry range is not two integers"]);
2294
- return [[], -1, []];
2318
+ return [[], -1, [], []];
2295
2319
  }
2296
2320
  // the registry notes are signed by the record log's own pinned key, under the registry origin
2297
2321
  const vkeys = [];
@@ -2322,14 +2346,18 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
2322
2346
  }
2323
2347
  if (problems.length || !(0 <= lo && lo <= hi) || hi === 0) {
2324
2348
  rep.check("run-set", false, `INCOMPLETE, ${span}`, problems.length ? problems : [`bad registry range ${lo}..${hi}`]);
2325
- return [[], -1, regCosigs];
2349
+ return [[], -1, regCosigs, []];
2326
2350
  }
2327
2351
  if (0 < lo && lo < hi && !await verifyConsistency(lo, hi, roots.get(lo), roots.get(hi), list(at(rs, "consistency")).map(b64decode)))
2328
2352
  problems.push(`registry checkpoint ${lo} is not a prefix of ${hi}`);
2353
+ else if (!(0 < lo && lo < hi) && !same(at(rs, "consistency"), [])) // a range from 0, or empty, has no consistency proof
2354
+ problems.push(`a consistency proof for registry ${lo}..${hi}, which has none`);
2329
2355
  const leaves = list(at(rs, "leaves"));
2330
- const pointed = new Map(jsonl("registry/records.jsonl").map((r) => [at(at(r, "event"), "seq"), r]));
2356
+ const lines = jsonl("registry/records.jsonl"), pointed = [];
2331
2357
  if (leaves.length !== hi - lo)
2332
2358
  problems.push(`${hi - lo} leaves in ${lo}..${hi}, ${leaves.length} in the bundle: a leaf is missing`);
2359
+ if (lines.length !== leaves.length) // §9: the record each leaf points to, in leaf order, and nothing else
2360
+ problems.push(`${lines.length} record(s) in registry/records.jsonl for ${leaves.length} leaves: one per leaf, in leaf order`);
2333
2361
  const registered = new Map(), finals = new Map(), retired = [], targets = new Set();
2334
2362
  const gaps = new Map();
2335
2363
  let closed = null, tenant = null, top = -1;
@@ -2340,15 +2368,16 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
2340
2368
  continue;
2341
2369
  }
2342
2370
  const { type, runHash: rh, logId, seq, hash } = parseLeaf(leaf);
2343
- const r = pointed.get(seq) ?? null, e = r && truthy(r) ? at(r, "event") : r;
2344
- if (r === null || at(r, "hash") !== hash || at(e, "type") !== type || at(e, "log_id") !== logId || !await included(r)
2371
+ top = Math.max(top, seq); // the registry note proves the leaf, whatever record the bundle has for it
2372
+ const r = j < lines.length ? lines[j] : null, e = r && truthy(r) ? at(r, "event") : r;
2373
+ if (r === null || !same(at(e, "seq"), seq) || at(r, "hash") !== hash || at(e, "type") !== type || at(e, "log_id") !== logId || !await included(r)
2345
2374
  || !equal(await runHash(tsalt, text(at(e, "run_id"))), rh)
2346
2375
  || !SIGNER_LEAVES.includes(type) && tenant !== null && !same(tenant, at(e, "tenant"))) {
2347
2376
  problems.push(`leaf ${i} points to a missing or different record (seq ${seq})`);
2348
2377
  continue;
2349
2378
  }
2350
2379
  await checkRecord(r, problems);
2351
- top = Math.max(top, seq);
2380
+ pointed.push(r);
2352
2381
  if (type === "run.registered" || type === "run.final")
2353
2382
  targets.add(await runName(at(e, "tenant"), e.run_id));
2354
2383
  if (type === "run.registered") {
@@ -2392,7 +2421,7 @@ async function checkRunSet(rep, rs, jsonl, file, trust, witnesses, origin, size,
2392
2421
  rep.check("tenant-level gaps", false, `${[...gaps.values()].reduce((a, b) => a + b, 0)} in the range: ${counted}`, [], true);
2393
2422
  rep.check("log tail", truthy(closed), truthy(closed) ? `none: log.closed at seq ${str(closed.seq)} is the last record`
2394
2423
  : `records after tree size ${size} are unproven (no log.closed in the range)`, [], true);
2395
- return [retired, lo === 0 ? top : -1, regCosigs];
2424
+ return [retired, lo === 0 ? top : -1, regCosigs, pointed];
2396
2425
  }
2397
2426
  /** A run's part: the run's file name, the part's number (tracekit/bundle_v2.py PART). */
2398
2427
  const PART = /^(runs\/.+)\.part-([0-9]+)\.jsonl$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cygnuxlabs/tracekit",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Tracekit for TypeScript/JavaScript agents: a native client of the Tracekit signer: policy-gated tool calls and signed evidence, no runtime dependencies.",
5
5
  "keywords": ["ai-agents", "agent-security", "audit-log", "tamper-evident", "guardrails", "mcp", "openai-agents",
6
6
  "vercel-ai", "claude-agent-sdk", "observability", "provenance", "llm"],
@@ -27,10 +27,10 @@
27
27
  "test": "npm run build && node --test test/*.test.mjs"
28
28
  },
29
29
  "optionalDependencies": {
30
- "@cygnuxlabs/tracekit-signer-darwin-arm64": "1.5.2",
31
- "@cygnuxlabs/tracekit-signer-linux-x64-gnu": "1.5.2",
32
- "@cygnuxlabs/tracekit-signer-linux-arm64-gnu": "1.5.2",
33
- "@cygnuxlabs/tracekit-signer-win32-x64": "1.5.2"
30
+ "@cygnuxlabs/tracekit-signer-darwin-arm64": "1.5.3",
31
+ "@cygnuxlabs/tracekit-signer-linux-x64-gnu": "1.5.3",
32
+ "@cygnuxlabs/tracekit-signer-linux-arm64-gnu": "1.5.3",
33
+ "@cygnuxlabs/tracekit-signer-win32-x64": "1.5.3"
34
34
  },
35
35
  "peerDependencies": { "@openai/agents": ">=0.20.0", "ai": ">=7.0.0", "@anthropic-ai/claude-agent-sdk": ">=0.3.0" },
36
36
  "peerDependenciesMeta": {