altimate-receipts 0.6.1 → 0.7.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.
@@ -20,7 +20,7 @@ import {
20
20
  redactReceipt,
21
21
  rewritesHistory,
22
22
  touchedPaths
23
- } from "./chunk-DBQWQVZZ.js";
23
+ } from "./chunk-ZORGM2DA.js";
24
24
 
25
25
  // src/receipt/canonical.ts
26
26
  function canonicalize(value) {
@@ -149,9 +149,141 @@ function envelopePae(env) {
149
149
  return pae(env.payloadType, raw);
150
150
  }
151
151
 
152
- // src/trace/diffScope.ts
152
+ // src/trace/commitMatch.ts
153
153
  import { spawnSync as spawnSync2 } from "child_process";
154
154
 
155
+ // src/trace/gitCommand.ts
156
+ var WRAPPERS = /* @__PURE__ */ new Set(["command", "exec", "nohup", "time", "env"]);
157
+ var GIT_VALUE_FLAGS = /* @__PURE__ */ new Set(["-C", "-c", "--git-dir", "--work-tree", "--exec-path"]);
158
+ function gitInvocations(command) {
159
+ const blanked = command.replace(/\\["']/g, " ").replace(/'[^']*'/g, " ").replace(/"[^"]*"/g, " ");
160
+ const out = [];
161
+ for (const simple of blanked.split(/(?:&&|\|\||[;|\n])/)) {
162
+ const tokens = simple.trim().split(/\s+/).filter(Boolean);
163
+ let i = 0;
164
+ while (i < tokens.length && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[i]) || WRAPPERS.has(tokens[i]))) {
165
+ i++;
166
+ }
167
+ if (tokens[i] !== "git") {
168
+ continue;
169
+ }
170
+ i++;
171
+ while (i < tokens.length && tokens[i].startsWith("-")) {
172
+ const flag = tokens[i];
173
+ i++;
174
+ if (GIT_VALUE_FLAGS.has(flag)) {
175
+ i++;
176
+ }
177
+ }
178
+ const sub = tokens[i];
179
+ if (sub) {
180
+ out.push({ sub, rest: tokens.slice(i + 1) });
181
+ }
182
+ }
183
+ return out;
184
+ }
185
+
186
+ // src/trace/commitMatch.ts
187
+ var SHA_CAP = 200;
188
+ function branchShas(base2, cwd) {
189
+ if (!base2) {
190
+ return [];
191
+ }
192
+ const r = spawnSync2("git", ["log", `--max-count=${SHA_CAP}`, "--format=%H", `${base2}..HEAD`], {
193
+ encoding: "utf8",
194
+ cwd
195
+ });
196
+ if (r.status !== 0) {
197
+ return [];
198
+ }
199
+ return r.stdout.split("\n").filter((s) => /^[0-9a-f]{40}$/.test(s));
200
+ }
201
+ var HEX_RUN = /\b[0-9a-f]{7,40}\b/g;
202
+ function commandOf2(input) {
203
+ if (typeof input === "string") {
204
+ const t = input.trim();
205
+ if (t.startsWith("{")) {
206
+ try {
207
+ return commandOf2(JSON.parse(t));
208
+ } catch {
209
+ return input;
210
+ }
211
+ }
212
+ return input;
213
+ }
214
+ if (input && typeof input === "object") {
215
+ const o = input;
216
+ for (const key of ["command", "cmd"]) {
217
+ const v = o[key];
218
+ if (typeof v === "string") {
219
+ return v;
220
+ }
221
+ if (Array.isArray(v)) {
222
+ return v.filter((t) => typeof t === "string").join(" ");
223
+ }
224
+ }
225
+ }
226
+ return "";
227
+ }
228
+ function isGitWrite(command) {
229
+ return gitInvocations(command).some((g) => g.sub === "commit" || g.sub === "push");
230
+ }
231
+ function authoredBranch(spans, shas) {
232
+ if (shas.length === 0) {
233
+ return false;
234
+ }
235
+ for (const s of spans) {
236
+ if (s.kind !== "tool" || typeof s.output !== "string") {
237
+ continue;
238
+ }
239
+ if (!isGitWrite(commandOf2(s.input))) {
240
+ continue;
241
+ }
242
+ for (const token of s.output.match(HEX_RUN) ?? []) {
243
+ if (shas.some((full) => full.startsWith(token))) {
244
+ return true;
245
+ }
246
+ }
247
+ }
248
+ return false;
249
+ }
250
+ function shaWindow(spans, shas) {
251
+ if (shas.length === 0) {
252
+ return null;
253
+ }
254
+ let firstOwn = -1;
255
+ let lastOwn = -1;
256
+ let lastForeignBeforeOwn = -1;
257
+ spans.forEach((s, i) => {
258
+ if (s.kind !== "tool" || typeof s.output !== "string") {
259
+ return;
260
+ }
261
+ if (!isGitWrite(commandOf2(s.input))) {
262
+ return;
263
+ }
264
+ const tokens = s.output.match(HEX_RUN) ?? [];
265
+ if (tokens.length === 0) {
266
+ return;
267
+ }
268
+ const own = tokens.some((t) => shas.some((full) => full.startsWith(t)));
269
+ if (own) {
270
+ if (firstOwn === -1) {
271
+ firstOwn = i;
272
+ }
273
+ lastOwn = i;
274
+ } else if (firstOwn === -1) {
275
+ lastForeignBeforeOwn = i;
276
+ }
277
+ });
278
+ if (lastOwn === -1) {
279
+ return null;
280
+ }
281
+ return { start: lastForeignBeforeOwn + 1, end: lastOwn };
282
+ }
283
+
284
+ // src/trace/diffScope.ts
285
+ import { spawnSync as spawnSync3 } from "child_process";
286
+
155
287
  // src/findings/surface.ts
156
288
  var OPERATOR_KINDS = /* @__PURE__ */ new Set([
157
289
  "loop",
@@ -198,7 +330,7 @@ function regenerableReceiptRm(title) {
198
330
 
199
331
  // src/trace/diffScope.ts
200
332
  function git(args, cwd) {
201
- const r = spawnSync2("git", args, { encoding: "utf8", cwd });
333
+ const r = spawnSync3("git", args, { encoding: "utf8", cwd });
202
334
  return r.status === 0 ? r.stdout : null;
203
335
  }
204
336
  var RECEIPTS_DIR_RE = /(?:^|\/)\.receipts\//;
@@ -312,17 +444,20 @@ function keepUnderDiff(f, files, commandFor, locusFor) {
312
444
  }
313
445
  return f.filePath ? inDiff(f.filePath, files) : false;
314
446
  }
315
- function diffEffort(derived, files) {
447
+ function diffEffort(derived, files, window) {
316
448
  const editedGens = /* @__PURE__ */ new Set();
317
- for (const s of derived.spans) {
449
+ derived.spans.forEach((s, i) => {
318
450
  if (s.kind !== "tool" || !s.parentSpanId || !isEditTool(s.name)) {
319
- continue;
451
+ return;
452
+ }
453
+ if (window && (i < window.start || i > window.end)) {
454
+ return;
320
455
  }
321
456
  const fp = filePathOf(s.input);
322
457
  if (fp && inDiff(fp, files)) {
323
458
  editedGens.add(s.parentSpanId);
324
459
  }
325
- }
460
+ });
326
461
  let cost = 0;
327
462
  let tokens = 0;
328
463
  for (const s of derived.spans) {
@@ -340,6 +475,10 @@ function narrowEffort(sliceDerived, files) {
340
475
  const eff = diffEffort(sliceDerived, files);
341
476
  return eff.turns > 0 ? eff : null;
342
477
  }
478
+ function windowedEffort(derived, files, window) {
479
+ const eff = diffEffort(derived, files, window);
480
+ return eff.turns > 0 ? eff : null;
481
+ }
343
482
  function applyDiffScope(derived, findings, files, projectPath) {
344
483
  const spanCmd = /* @__PURE__ */ new Map();
345
484
  const spanCwd = /* @__PURE__ */ new Map();
@@ -463,7 +602,13 @@ async function rederiveFromTranscript(path, opts = {}) {
463
602
  findings = scoped.findings;
464
603
  if (scope.branch) {
465
604
  const slice = sliceByBranch(loaded, scope.branch);
466
- const eff = narrowEffort(slice ? deriveSpans(slice) : null, scope.files);
605
+ let eff = narrowEffort(slice ? deriveSpans(slice) : null, scope.files);
606
+ if (!eff && scope.shas?.length) {
607
+ const win = shaWindow(derived.spans, scope.shas);
608
+ if (win) {
609
+ eff = windowedEffort(derived, scope.files, win);
610
+ }
611
+ }
467
612
  if (eff) {
468
613
  derived = {
469
614
  ...derived,
@@ -490,7 +635,17 @@ async function compareToTranscript(committed, transcriptPath, opts = {}) {
490
635
  if (!fresh) {
491
636
  return { rederived: false, matches: false };
492
637
  }
493
- return { rederived: true, matches: canonicalize(committed) === canonicalize(fresh) };
638
+ const strip = (r) => {
639
+ if (!r.predicate.prEffort) {
640
+ return r;
641
+ }
642
+ const { prEffort: _x, ...rest } = r.predicate;
643
+ return { ...r, predicate: rest };
644
+ };
645
+ return {
646
+ rederived: true,
647
+ matches: canonicalize(strip(committed)) === canonicalize(strip(fresh))
648
+ };
494
649
  }
495
650
 
496
651
  // src/report/checks.ts
@@ -583,6 +738,7 @@ function categorize(findings) {
583
738
  }
584
739
 
585
740
  export {
741
+ gitInvocations,
586
742
  canonicalize,
587
743
  CHECK_CATALOG,
588
744
  checkForId,
@@ -593,15 +749,19 @@ export {
593
749
  pae,
594
750
  toDsseEnvelope,
595
751
  envelopePae,
752
+ branchShas,
753
+ authoredBranch,
754
+ shaWindow,
596
755
  findingSurface,
597
756
  destructiveOutsideRepo,
598
757
  changedFiles,
599
758
  inDiff,
600
759
  narrowEffort,
760
+ windowedEffort,
601
761
  applyDiffScope,
602
762
  branchesIn,
603
763
  sliceByBranch,
604
764
  rederiveFromTranscript,
605
765
  compareToTranscript
606
766
  };
607
- //# sourceMappingURL=chunk-54J2FEKI.js.map
767
+ //# sourceMappingURL=chunk-FTKMO26V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/receipt/canonical.ts","../src/share/clipboard.ts","../src/share/markdown.ts","../src/sign/envelope.ts","../src/trace/commitMatch.ts","../src/trace/gitCommand.ts","../src/trace/diffScope.ts","../src/findings/surface.ts","../src/trace/slice.ts","../src/sign/rederive.ts","../src/report/checks.ts"],"sourcesContent":["/**\n * Canonical JSON (RFC 8785-style): object keys sorted lexicographically, minimal\n * whitespace, arrays in order. Used now for deterministic hashing/equality and\n * reused verbatim as M4's DSSE signing payload, so a Receipt and its signature\n * always agree on the exact bytes.\n *\n * Scope note: this is a pragmatic subset — all numbers in a Receipt are integers\n * or values we round before emitting, so JSON.stringify's number formatting is\n * already stable. We do not implement RFC 8785's full number canonicalization.\n */\nexport function canonicalize(value: unknown): string {\n return serialize(value);\n}\n\nfunction serialize(value: unknown): string {\n if (value === null || typeof value === \"number\" || typeof value === \"boolean\") {\n return JSON.stringify(value);\n }\n if (typeof value === \"string\") {\n return JSON.stringify(value);\n }\n if (Array.isArray(value)) {\n return `[${value.map(serialize).join(\",\")}]`;\n }\n if (typeof value === \"object\") {\n const obj = value as Record<string, unknown>;\n const keys = Object.keys(obj)\n .filter((k) => obj[k] !== undefined)\n .sort();\n const body = keys.map((k) => `${JSON.stringify(k)}:${serialize(obj[k])}`).join(\",\");\n return `{${body}}`;\n }\n // undefined / function / symbol — not valid Receipt content\n return \"null\";\n}\n","import { spawnSync } from \"node:child_process\";\n\ninterface ClipboardTool {\n cmd: string;\n args: string[];\n}\n\n/** OS clipboard tools, by platform, in preference order. */\nfunction candidates(): ClipboardTool[] {\n if (process.platform === \"darwin\") {\n return [{ cmd: \"pbcopy\", args: [] }];\n }\n if (process.platform === \"win32\") {\n return [{ cmd: \"clip\", args: [] }];\n }\n // linux / other: Wayland first, then X11\n return [\n { cmd: \"wl-copy\", args: [] },\n { cmd: \"xclip\", args: [\"-selection\", \"clipboard\"] },\n { cmd: \"xsel\", args: [\"--clipboard\", \"--input\"] },\n ];\n}\n\n/**\n * Best-effort copy to the OS clipboard. Returns true on success, false if no tool\n * is available or the copy failed — the caller prints a note and still exits 0.\n * No npm dependency; shells out to the platform tool.\n */\nexport function copyToClipboard(text: string): boolean {\n for (const { cmd, args } of candidates()) {\n try {\n const res = spawnSync(cmd, args, { input: text, stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n if (!res.error && res.status === 0) {\n return true;\n }\n } catch {\n // try the next tool\n }\n }\n return false;\n}\n","import type { FindingSet, Severity } from \"../findings/findings.js\";\nimport { type GradeLetter, gradeLetter } from \"../findings/grade.js\";\nimport type { DerivedSummary } from \"../findings/spans.js\";\nimport { deriveEvidence } from \"../receipt/build.js\";\nimport type { Session, SessionSummary } from \"../trace/types.js\";\nimport { redact } from \"./redact.js\";\n\nconst VERDICT: Record<GradeLetter, string> = {\n F: \"DO NOT MERGE WITHOUT REVIEW\",\n C: \"NEEDS A CLOSE REVIEW\",\n B: \"MINOR THINGS TO CHECK\",\n A: \"LOOKS CLEAN\",\n};\n\nconst ICON: Record<Severity, string> = {\n critical: \"⛔\",\n high: \"⚠️\",\n medium: \"🔍\",\n low: \"·\",\n};\n\nconst base = (p: string): string => p.split(\"/\").pop() ?? p;\n\n/**\n * A redacted, paste-ready Markdown summary of a session — the `--share` artifact.\n * Pure function of the derived data; all user-text is passed through `redact()`.\n */\nexport function renderShareMarkdown(args: {\n summary: SessionSummary;\n session: Session;\n derived: DerivedSummary;\n findings: FindingSet;\n}): string {\n const { summary, session, derived, findings } = args;\n const { main, minor } = findings;\n const g = gradeLetter(main);\n const ev = deriveEvidence(session, derived);\n\n const counts =\n ([\"critical\", \"high\", \"medium\"] as const)\n .map((s) => {\n const n = main.filter((f) => f.severity === s).length;\n return n ? `${n} ${s}` : null;\n })\n .filter(Boolean)\n .join(\" · \") || \"no findings\";\n\n const title = redact(summary.title || \"untitled session\");\n const out: string[] = [];\n out.push(`## 🧾 Receipt — ${title} · Grade ${g}`);\n out.push(\"\");\n out.push(`**${VERDICT[g]}** · ${counts} · _${summary.source}_`);\n out.push(\"\");\n\n if (main.length) {\n out.push(\"### Findings\");\n const order: Record<Severity, number> = { critical: 0, high: 1, medium: 2, low: 3 };\n const sorted = [...main].sort(\n (a, b) => order[a.severity] - order[b.severity] || b.score - a.score,\n );\n for (const f of sorted.slice(0, 12)) {\n const tag = f.impactLabel ? ` — ${redact(f.impactLabel)}` : \"\";\n const loc = f.filePath ? ` (\\`${redact(base(f.filePath))}\\`)` : \"\";\n out.push(`- ${ICON[f.severity]} **${redact(f.title)}**${tag}${loc}`);\n }\n if (minor.length) {\n out.push(`- _+${minor.length} minor (collapsed)_`);\n }\n out.push(\"\");\n }\n\n out.push(\"### Evidence\");\n out.push(\n `${ev.filesChanged} files · ${ev.edits} edits · ${ev.commands} commands · ` +\n `${ev.testsRan ? \"tests ran ✓\" : \"no test run detected\"} · ` +\n `${ev.destructiveOps} destructive ops`,\n );\n out.push(\"\");\n out.push(\"_Verified by Receipts · deterministic · 0 model calls · evidence, not judgement_\");\n return `${out.join(\"\\n\")}\\n`;\n}\n","import type { Receipt } from \"../receipt/build.js\";\nimport { canonicalize } from \"../receipt/canonical.js\";\n\n/** in-toto payloads ride in DSSE with this type. */\nexport const DSSE_PAYLOAD_TYPE = \"application/vnd.in-toto+json\";\n\nexport interface DsseSignature {\n sig: string;\n keyid?: string;\n}\n\nexport interface DsseEnvelope {\n payloadType: string;\n /** base64 of the canonical Receipt JSON */\n payload: string;\n signatures: DsseSignature[];\n}\n\n/**\n * DSSE Pre-Authentication Encoding (PAE) — the exact bytes a signer signs:\n * \"DSSEv1\" SP len(payloadType) SP payloadType SP len(payload) SP payload\n * Lengths count UTF-8 bytes; `payload` here is the raw (un-base64) payload.\n */\nexport function pae(payloadType: string, payload: string): Buffer {\n const typeBytes = Buffer.from(payloadType, \"utf8\");\n const bodyBytes = Buffer.from(payload, \"utf8\");\n const header = `DSSEv1 ${typeBytes.length} ${payloadType} ${bodyBytes.length} `;\n return Buffer.concat([Buffer.from(header, \"utf8\"), bodyBytes]);\n}\n\n/**\n * Wrap a Receipt as an UNSIGNED DSSE envelope. The payload is the canonical\n * Receipt JSON (so signature and content always agree on the exact bytes). The\n * signature array is filled by the signer (the GitHub Action), not here.\n */\nexport function toDsseEnvelope(receipt: Receipt): DsseEnvelope {\n const canonical = canonicalize(receipt);\n return {\n payloadType: DSSE_PAYLOAD_TYPE,\n payload: Buffer.from(canonical, \"utf8\").toString(\"base64\"),\n signatures: [],\n };\n}\n\n/** The PAE bytes for an envelope (what a verifier checks the signature against). */\nexport function envelopePae(env: DsseEnvelope): Buffer {\n const raw = Buffer.from(env.payload, \"base64\").toString(\"utf8\");\n return pae(env.payloadType, raw);\n}\n","import { spawnSync } from \"node:child_process\";\nimport type { DerivedSpan } from \"../findings/spans.js\";\nimport { gitInvocations } from \"./gitCommand.js\";\n\n/**\n * Commit-SHA attribution (SPEC-0069 / M70). When any agent runs `git commit` or\n * `git push`, the captured output carries the commit SHA (\"[feat-x 5f8a31d] msg\",\n * \"abc1234..def5678 feat-x -> feat-x\"). Matching those SHAs against the branch's\n * `git log` gives an exact, agent-agnostic session↔branch binding — no branch\n * tags, no edit spans, nothing new recorded. Prior art: aider stamps commits,\n * git-ai/Entire attach notes; we read the binding the transcript already holds.\n */\n\n/** Max branch commits to match against — far beyond any sane PR; newest first. */\nconst SHA_CAP = 200;\n\n/** Full SHAs of the commits unique to this branch (newest first), or [] when\n * unknowable (no base / no commits / no git). */\nexport function branchShas(base?: string, cwd?: string): string[] {\n if (!base) {\n return [];\n }\n const r = spawnSync(\"git\", [\"log\", `--max-count=${SHA_CAP}`, \"--format=%H\", `${base}..HEAD`], {\n encoding: \"utf8\",\n cwd,\n });\n if (r.status !== 0) {\n return [];\n }\n return r.stdout.split(\"\\n\").filter((s) => /^[0-9a-f]{40}$/.test(s));\n}\n\nconst HEX_RUN = /\\b[0-9a-f]{7,40}\\b/g;\n\n/** The command string of a tool span, across agent input shapes: Claude's\n * `{command}` object, Codex's raw arguments JSON string (`'{\"cmd\":\"…\"}'`, string\n * or argv array inside). Raw inputs per R5. */\nfunction commandOf(input: unknown): string {\n if (typeof input === \"string\") {\n const t = input.trim();\n if (t.startsWith(\"{\")) {\n try {\n return commandOf(JSON.parse(t));\n } catch {\n return input;\n }\n }\n return input;\n }\n if (input && typeof input === \"object\") {\n const o = input as Record<string, unknown>;\n for (const key of [\"command\", \"cmd\"]) {\n const v = o[key];\n if (typeof v === \"string\") {\n return v;\n }\n if (Array.isArray(v)) {\n return v.filter((t) => typeof t === \"string\").join(\" \");\n }\n }\n }\n return \"\";\n}\n\n/**\n * Is this command a real `git commit`/`git push` invocation? Tokenized via the\n * shared M67-discipline matcher — an orchestrating session running\n * `codex exec \"...then git push...\"` (the SHA-bearing instruction-in-a-string\n * case, observed live) never counts as the author of its child agent's commits.\n */\nexport function isGitWrite(command: string): boolean {\n return gitInvocations(command).some((g) => g.sub === \"commit\" || g.sub === \"push\");\n}\n\n/**\n * Did this session author any of the branch's commits? True iff a hex run (≥7\n * chars) in the OUTPUT of a `git commit`/`git push` command span prefixes one of\n * the branch's full SHAs. Output-only: a SHA pasted into a command's input isn't\n * authorship. Deterministic string scan; zero git calls.\n */\nexport function authoredBranch(spans: readonly DerivedSpan[], shas: readonly string[]): boolean {\n if (shas.length === 0) {\n return false;\n }\n for (const s of spans) {\n if (s.kind !== \"tool\" || typeof s.output !== \"string\") {\n continue;\n }\n if (!isGitWrite(commandOf(s.input))) {\n continue;\n }\n for (const token of s.output.match(HEX_RUN) ?? []) {\n if (shas.some((full) => full.startsWith(token))) {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * The branch's commit WINDOW inside a session (SPEC-0072 R1): span indices from\n * just after the last FOREIGN commit anchor preceding the branch's first own\n * anchor, through the last own anchor. Own anchor = a `git commit`/`git push`\n * span whose OUTPUT contains one of the branch's SHAs (same output-only\n * discipline as `authoredBranch`); foreign anchor = such a span whose output\n * carries hex runs but none of ours — the previous sibling branch's commit in a\n * multi-PR session. Null when the session authored none of the branch's commits.\n * Pure span scan ⇒ re-derivable at verify from the transcript + recorded SHAs.\n */\nexport function shaWindow(\n spans: readonly DerivedSpan[],\n shas: readonly string[],\n): { start: number; end: number } | null {\n if (shas.length === 0) {\n return null;\n }\n let firstOwn = -1;\n let lastOwn = -1;\n let lastForeignBeforeOwn = -1;\n spans.forEach((s, i) => {\n if (s.kind !== \"tool\" || typeof s.output !== \"string\") {\n return;\n }\n if (!isGitWrite(commandOf(s.input))) {\n return;\n }\n const tokens = s.output.match(HEX_RUN) ?? [];\n if (tokens.length === 0) {\n return;\n }\n const own = tokens.some((t) => shas.some((full) => full.startsWith(t)));\n if (own) {\n if (firstOwn === -1) {\n firstOwn = i;\n }\n lastOwn = i;\n } else if (firstOwn === -1) {\n lastForeignBeforeOwn = i;\n }\n });\n if (lastOwn === -1) {\n return null;\n }\n return { start: lastForeignBeforeOwn + 1, end: lastOwn };\n}\n","/**\n * Shared git-invocation tokenizer (extracted in SPEC-0069 — the M67 push matcher\n * and the M70 authorship matcher need identical discipline). Quoted text is\n * blanked first, so `git push` inside a prompt string (`codex exec \"...git\n * push...\"`, `echo \"git push\"`, commit-message text) never reads as a git call;\n * then each `&&`/`||`/`;`/`|`-separated simple command must START with `git`\n * (after env assignments / benign wrappers and git's global flags).\n */\n\n/** Shell wrappers that may legitimately precede `git` in a simple command. */\nconst WRAPPERS = new Set([\"command\", \"exec\", \"nohup\", \"time\", \"env\"]);\n/** Global git flags between `git` and the subcommand that consume a value. */\nconst GIT_VALUE_FLAGS = new Set([\"-C\", \"-c\", \"--git-dir\", \"--work-tree\", \"--exec-path\"]);\n\nexport interface GitInvocation {\n /** the git subcommand: \"push\", \"commit\", \"log\", … */\n sub: string;\n /** tokens after the subcommand (flags + positionals) */\n rest: string[];\n}\n\n/** Every real `git <sub> …` invocation in a (possibly compound) shell command. */\nexport function gitInvocations(command: string): GitInvocation[] {\n const blanked = command\n .replace(/\\\\[\"']/g, \" \")\n .replace(/'[^']*'/g, \" \")\n .replace(/\"[^\"]*\"/g, \" \");\n const out: GitInvocation[] = [];\n for (const simple of blanked.split(/(?:&&|\\|\\||[;|\\n])/)) {\n const tokens = simple.trim().split(/\\s+/).filter(Boolean);\n let i = 0;\n while (\n i < tokens.length &&\n (/^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[i]) || WRAPPERS.has(tokens[i]))\n ) {\n i++;\n }\n if (tokens[i] !== \"git\") {\n continue;\n }\n i++;\n while (i < tokens.length && tokens[i].startsWith(\"-\")) {\n const flag = tokens[i];\n i++;\n if (GIT_VALUE_FLAGS.has(flag)) {\n i++;\n }\n }\n const sub = tokens[i];\n if (sub) {\n out.push({ sub, rest: tokens.slice(i + 1) });\n }\n }\n return out;\n}\n","import { spawnSync } from \"node:child_process\";\nimport { estimateCost } from \"../findings/cost.js\";\nimport type { Finding, FindingSet } from \"../findings/findings.js\";\nimport {\n cwdAtFirstGit,\n destroysGitData,\n isNoVerify,\n parseGitInvocations,\n rewritesHistory,\n touchedPaths,\n} from \"../findings/gitParse.js\";\nimport { type DerivedSummary, destructiveMatch } from \"../findings/spans.js\";\nimport { destructiveOutsideRepo, regenerableReceiptRm } from \"../findings/surface.js\";\nimport { commandOf, filePathOf, isEditTool } from \"../findings/toolRoles.js\";\n\n/**\n * Diff-scoping for `receipts pr` (SPEC-0013). The PR's changed-file set is read from\n * git at produce time and recorded in `predicate.scope.files`; every scoping decision\n * below is a pure function of that file list (+ the repo-root-free destructive\n * heuristic), so a verifier reproduces the exact scoped receipt from the recorded\n * `files` alone — no git at verify time. That's what keeps L1 re-derivation intact.\n */\n\nfunction git(args: string[], cwd?: string): string | null {\n const r = spawnSync(\"git\", args, { encoding: \"utf8\", cwd });\n return r.status === 0 ? r.stdout : null;\n}\n\nexport interface DiffResult {\n /** the ref the diff was taken against */\n base: string;\n /** changed files, sorted, repo-relative */\n files: string[];\n repoRoot: string;\n}\n\n/** Receipts' own bookkeeping dir. A receipt must NOT scope over `.receipts/` — else\n * committing the receipt changes the diff, which re-scopes the next receipt: an endless\n * regeneration loop in the pre-push hook. Excluded from the diff scope here AND in the\n * Action's scope-honesty check (action/verified-by.mjs) so the two stay consistent. */\nexport const RECEIPTS_DIR_RE = /(?:^|\\/)\\.receipts\\//;\n\n/**\n * The PR's changed files via `git diff --name-only <base>...HEAD`, sorted, with the\n * `.receipts/` bookkeeping dir excluded (see RECEIPTS_DIR_RE). `base` defaults to the\n * default branch (origin/HEAD → main). Returns null when no repo, base, or non-empty\n * diff is resolvable (caller falls back honestly).\n */\nexport function changedFiles(\n baseOverride?: string,\n opts?: { includeWorkingTree?: boolean },\n): DiffResult | null {\n const root = git([\"rev-parse\", \"--show-toplevel\"])?.trim();\n if (!root) {\n return null;\n }\n let base = baseOverride;\n if (!base) {\n const sym = git([\"symbolic-ref\", \"refs/remotes/origin/HEAD\"], root)?.trim();\n if (sym) {\n base = sym.replace(\"refs/remotes/\", \"\");\n } else if (git([\"rev-parse\", \"--verify\", \"--quiet\", \"origin/main\"], root) !== null) {\n // origin/HEAD is only set by clone/`remote set-head`; without it, prefer the\n // remote's main over a possibly-stale local main so the diff isn't inflated\n // by upstream commits the user hasn't pulled.\n base = \"origin/main\";\n } else {\n base = \"main\";\n }\n }\n let out = git([\"diff\", \"--name-only\", `${base}...HEAD`], root);\n if (out === null && !baseOverride) {\n // base may be unfetched (e.g. origin/main absent locally) — try local main.\n out = git([\"diff\", \"--name-only\", \"main...HEAD\"], root);\n if (out !== null) {\n base = \"main\";\n }\n }\n // An agent pre-push hook fires BEFORE a compound `git commit … && git push` runs,\n // so the in-flight commit's files aren't in base...HEAD yet — union the working\n // tree (staged + unstaged + untracked) when the caller says a commit is pending.\n const pending = opts?.includeWorkingTree ? workingTreeFiles(root) : [];\n if (out === null && pending.length === 0) {\n return null;\n }\n const files = [...new Set([...(out ?? \"\").split(\"\\n\").map((s) => s.trim()), ...pending])]\n .filter(Boolean)\n .filter((f) => !RECEIPTS_DIR_RE.test(f)) // a receipt never scopes over .receipts/\n .sort();\n if (files.length === 0) {\n return null; // nothing to scope to (or a receipts-only diff) → caller falls back\n }\n return { base, files, repoRoot: root };\n}\n\n/** Staged + unstaged + untracked paths from `git status --porcelain -z`\n * (repo-relative; rename/copy entries contribute the destination path only). */\nfunction workingTreeFiles(root: string): string[] {\n const out = git([\"status\", \"--porcelain\", \"-z\", \"--untracked-files=all\"], root);\n if (!out) {\n return [];\n }\n const toks = out.split(\"\\0\");\n const files: string[] = [];\n for (let i = 0; i < toks.length; i++) {\n const t = toks[i];\n if (!t || t.length < 4 || t[2] !== \" \") {\n continue;\n }\n files.push(t.slice(3));\n if (t[0] === \"R\" || t[0] === \"C\") {\n i++; // -z rename/copy: the next NUL-separated token is the source path\n }\n }\n return files;\n}\n\n/** Does a finding's file path belong to the changed-file set? Matches exact, path\n * suffix, or basename (a PR's diff is small; basename collisions are unlikely and\n * fail toward surfacing). */\nexport function inDiff(filePath: string, files: readonly string[]): boolean {\n const base = filePath.split(\"/\").pop();\n for (const d of files) {\n if (d === filePath || d.endsWith(`/${filePath}`) || filePath.endsWith(`/${d}`)) {\n return true;\n }\n if (base && d.split(\"/\").pop() === base) {\n return true;\n }\n }\n return false;\n}\n\n// Integrity findings that are about the *act*, not a path — kept regardless of the\n// diff (a `curl | sh`, a fabricated tool call, a `--no-verify` are merge-relevant\n// even though they name no changed file). `force-push` is NOT here: it's a git op\n// scoped by its touched paths below (it touches none ⇒ session hygiene, not a merge\n// risk for this change).\n// Path-free integrity findings kept regardless of the diff — a `curl|sh` or a\n// fabricated/malformed tool call is a session-integrity problem no matter which files\n// changed. `hook-bypass` is NOT here: it's scoped below (a `push --no-verify` only skips\n// pre-push hooks ⇒ session hygiene, not a merge risk for this diff).\nconst PROCESS_PREFIXES = [\"pipe-sh\", \"tool-fabricated\", \"tool-malformed-args\"];\nconst isProcessFinding = (id: string): boolean =>\n PROCESS_PREFIXES.some((p) => id === p || id.startsWith(`${p}-`));\nconst isDestructive = (id: string): boolean => id.startsWith(\"destructive-\");\nconst isGitProcess = (id: string): boolean =>\n id.startsWith(\"force-push\") || id.startsWith(\"destructive-git\");\n\n/** True when the **destructive** git op in this command touches a diff file. Only the\n * destructive / history-rewriting invocation is judged — a benign sibling clause in the\n * same compound command (e.g. `git add <diff-file> && git reset --hard <ref>`) must NOT\n * make the unrelated reset look diff-relevant. Ref/history/worktree-wide ops\n * (`reset --hard <branch>`, `push -f`, `branch -D`) have no touched path ⇒ false ⇒\n * session hygiene, not a merge risk for this change. */\n/** True when every `--no-verify` in this command is on a `push` (no `commit --no-verify`).\n * A `push --no-verify` skips only the pre-push hooks (no committed content changes), so it\n * is session hygiene, not a merge risk for this diff. A `commit --no-verify` skipped the\n * pre-commit checks on committed content ⇒ NOT push-only ⇒ kept. */\nfunction hookBypassIsPushOnly(command: string): boolean {\n const noVerify = parseGitInvocations(command).filter(isNoVerify);\n return noVerify.length > 0 && noVerify.every((inv) => inv.subcommand === \"push\");\n}\n\nfunction gitTouchesDiff(command: string, files: readonly string[]): boolean {\n for (const inv of parseGitInvocations(command)) {\n if (!destroysGitData(inv) && !rewritesHistory(inv)) {\n continue; // a `git add`/`commit`/`checkout <branch>` clause is not the destructive op\n }\n if (touchedPaths(inv).some((p) => inDiff(p, files))) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Keep a finding under a diff scope:\n * - path-free integrity findings (hook-bypass, pipe-sh, fabricated/malformed) — always,\n * - a git process/destructive op only when its touched paths fall in the diff\n * (`reset --hard <branch>`/`push -f` touch nothing ⇒ dropped to the session card),\n * - a non-git destructive whose target is a repo path (not a `$TMP`/`.receipts` scratch),\n * - any other finding about a changed file.\n * Pure function of the finding + the recorded file list (+ the finding's own command,\n * itself re-derived from the transcript) ⇒ reproducible at verify.\n */\nexport function keepUnderDiff(\n f: Pick<Finding, \"id\" | \"title\"> & { filePath?: string; evidenceSpanId?: string },\n files: readonly string[],\n commandFor?: (f: Pick<Finding, \"id\" | \"evidenceSpanId\">) => string | undefined,\n locusFor?: (f: Pick<Finding, \"id\" | \"evidenceSpanId\">) => \"here\" | \"elsewhere\" | undefined,\n): boolean {\n // Cross-repo bleed (SPEC-0069 addendum, observed live): a session that also ran\n // `git commit --no-verify` in ANOTHER repo (`cd /other && git commit --no-verify`)\n // must not flag THIS repo's diff receipt. The locus is resolved by the caller from\n // transcript data only (span cwd + cd tracking), so the drop re-derives with no\n // git at verify time; \"elsewhere\" includes unresolvable-cd uncertainty (under-claim).\n if (locusFor?.(f) === \"elsewhere\") {\n return false;\n }\n if (isProcessFinding(f.id)) {\n return true;\n }\n // hook-bypass: a `push --no-verify` skips only pre-push hooks (no code change) ⇒ session\n // hygiene, dropped from the diff; a `commit --no-verify` (or an unresolvable command) is\n // kept — it may have skipped pre-commit checks on the committed change.\n if (f.id === \"hook-bypass\" || f.id.startsWith(\"hook-bypass-\")) {\n const cmd = commandFor?.(f);\n return cmd ? !hookBypassIsPushOnly(cmd) : true;\n }\n // git ref/history surgery is a merge risk only if it touched a changed file.\n if (isGitProcess(f.id)) {\n const cmd = commandFor?.(f);\n return cmd ? gitTouchesDiff(cmd, files) : false;\n }\n if (isDestructive(f.id)) {\n // scratch (`/tmp`) and the tool's own regenerable `.receipts/*.json` are both\n // out-of-scope for \"did this change do damage?\" — drop either from the diff.\n if (destructiveOutsideRepo(f.title) || regenerableReceiptRm(f.title)) {\n return false;\n }\n // a git destructive (`git reset --hard <branch>`, `git rm`) only counts when it hit\n // the diff; a non-git filesystem removal (`rm -rf src/old`) keeps the repo-path\n // behaviour. The command comes from the span resolver, falling back to the title's\n // clause (`Destructive op: <cmd>`), so this holds even without a resolver.\n const cmd =\n commandFor?.(f) ?? f.title.replace(/^Destructive op:\\s*/i, \"\").replace(/\\s*×\\d+\\s*$/, \"\");\n if (/(^|[\\s;&|])git\\s/.test(cmd)) {\n return gitTouchesDiff(cmd, files);\n }\n return true;\n }\n return f.filePath ? inDiff(f.filePath, files) : false;\n}\n\nexport interface ScopedData {\n derived: DerivedSummary;\n findings: FindingSet;\n}\n\n/**\n * Cost/tokens of just the generation turns that edited a file in the diff — \"what\n * producing *this change* cost\", versus the whole-session total. Each edit tool span\n * links to the assistant turn that emitted it via `parentSpanId`; we collect those\n * generations and sum their recorded/estimated cost + tokens. Pure function of\n * `derived.spans` (re-derived from the transcript) + `files` ⇒ reproducible at verify.\n *\n * Honest bound: a turn that edited a diff file *and* others is counted whole, and the\n * turn's cost includes its shared context overhead — so this is an upper estimate of the\n * diff's marginal cost, not a precise split. It is always ≤ the session total and, in a\n * session that produced several PRs, far below it.\n */\nexport function diffEffort(\n derived: DerivedSummary,\n files: readonly string[],\n window?: { start: number; end: number },\n): { cost: number; tokens: number; turns: number } {\n const editedGens = new Set<string>();\n derived.spans.forEach((s, i) => {\n if (s.kind !== \"tool\" || !s.parentSpanId || !isEditTool(s.name)) {\n return;\n }\n if (window && (i < window.start || i > window.end)) {\n return;\n }\n const fp = filePathOf(s.input);\n if (fp && inDiff(fp, files)) {\n editedGens.add(s.parentSpanId);\n }\n });\n let cost = 0;\n let tokens = 0;\n for (const s of derived.spans) {\n if (s.kind === \"generation\" && editedGens.has(s.spanId)) {\n // recorded cost when present, else estimate from the turn's tokens + model (the\n // generation span's name is the model id) — the same basis as the session total.\n cost += s.cost || estimateCost(s.tokens, s.name);\n tokens += s.tokens?.total ?? 0;\n }\n }\n return { cost, tokens, turns: editedGens.size };\n}\n\n/**\n * Branch-narrowed effort (SPEC-0068 R4): in a session that produced several PRs, the\n * whole-session `diffEffort` counts every turn that ever touched a hot file (cli.ts,\n * README) — observed 26× inflation on a marathon session. When the session carries the\n * receipt branch's turns, the honest bound is branch turns ∩ diff-file edits. Returns\n * null when there is no slice or the slice has zero diff-file-editing turns (e.g.\n * Bash-only writes) — callers then keep the whole-session bound and must NOT record\n * `scope.branch`, so the receipt always states how its effort was computed. Shared by\n * produce (`receipts pr`) and verify (rederive) so the bytes match (L1).\n */\nexport function narrowEffort(\n sliceDerived: DerivedSummary | null,\n files: readonly string[],\n): { cost: number; tokens: number; turns: number } | null {\n if (!sliceDerived) {\n return null;\n }\n const eff = diffEffort(sliceDerived, files);\n return eff.turns > 0 ? eff : null;\n}\n\n/**\n * SHA-window narrowed effort (SPEC-0072 R1): for sessions WITHOUT branch tags\n * (codex), bound the turns-that-edited-these-files count to the branch's own\n * commit window. Without this, sibling PRs of one marathon session that touch a\n * shared file each inherit the file's whole edit history (observed: two\n * corpus-loop PRs each claiming the same ~93 turns / ~$10). Null when the window\n * has no diff-file-editing turns — callers keep the wider bound, honestly.\n */\nexport function windowedEffort(\n derived: DerivedSummary,\n files: readonly string[],\n window: { start: number; end: number },\n): { cost: number; tokens: number; turns: number } | null {\n const eff = diffEffort(derived, files, window);\n return eff.turns > 0 ? eff : null;\n}\n\n/**\n * Apply a diff scope to derived evidence + findings. Scopes the risk-relevant\n * evidence (`filesChanged`, `destructiveOps`) to the change and computes the diff's own\n * cost (`diffCostUsd`/`diffTokens`/`diffTurns`); leaves whole-session effort metrics\n * (`edits`/`commands`/`reads`/total tokens/cost) intact for the footer. Deterministic;\n * uses only `files` so re-derivation reproduces it from `predicate.scope.files`.\n */\nexport function applyDiffScope(\n derived: DerivedSummary,\n findings: FindingSet,\n files: readonly string[],\n projectPath?: string,\n): ScopedData {\n // evidenceSpanId → the span's command/cwd, so a git process/destructive finding can\n // be attributed to the diff by its touched paths and its repo. Built from\n // `derived.spans` (re-derived from the transcript) so the scope stays a pure\n // function of (derived, findings, files, projectPath) — all transcript-derived.\n const spanCmd = new Map<string, string>();\n const spanCwd = new Map<string, string>();\n for (const s of derived.spans) {\n if (s.spanId) {\n spanCmd.set(s.spanId, commandOf(s.input));\n if (s.cwd) {\n spanCwd.set(s.spanId, s.cwd);\n }\n }\n }\n const cmdOf = (f: Pick<Finding, \"evidenceSpanId\">): string | undefined =>\n f.evidenceSpanId ? spanCmd.get(f.evidenceSpanId) : undefined;\n // Did this finding's command actually run in the session's own project?\n // `cwdAtFirstGit` tracks `cd` clauses inside compounds; outside or uncertain ⇒\n // \"elsewhere\" (another repo's process risk — drop from the diff receipt).\n const locusOf = (f: Pick<Finding, \"evidenceSpanId\">): \"here\" | \"elsewhere\" | undefined => {\n if (!projectPath || !f.evidenceSpanId) {\n return undefined;\n }\n const base = spanCwd.get(f.evidenceSpanId);\n const state = cwdAtFirstGit(spanCmd.get(f.evidenceSpanId) ?? \"\", base);\n if (state.kind === \"unknown\") {\n return \"elsewhere\";\n }\n const at = state.kind === \"known\" ? state.path : base;\n if (!at) {\n return undefined;\n }\n return at === projectPath || at.startsWith(`${projectPath}/`) ? \"here\" : \"elsewhere\";\n };\n const keep = (f: Finding): boolean => keepUnderDiff(f, files, cmdOf, locusOf);\n const scopedFindings: FindingSet = {\n main: findings.main.filter(keep),\n minor: findings.minor.filter(keep),\n };\n const filesChanged = derived.filesChanged.filter((fc) => inDiff(fc.path, files));\n const destructiveCount = derived.spans\n .filter((s) => s.destructive)\n .filter((s) => {\n const cmd = commandOf(s.input);\n const clause = destructiveMatch(cmd) ?? cmd;\n if (destructiveOutsideRepo(clause) || regenerableReceiptRm(clause)) {\n return false;\n }\n // git ref/history surgery that touched no changed file isn't this diff's damage.\n if (/(^|[\\s;&|])git\\s/.test(cmd)) {\n return gitTouchesDiff(cmd, files);\n }\n return true;\n }).length;\n const eff = diffEffort(derived, files);\n return {\n derived: {\n ...derived,\n filesChanged,\n destructiveCount,\n diffCostUsd: eff.cost,\n diffTokens: eff.tokens,\n diffTurns: eff.turns,\n },\n findings: scopedFindings,\n };\n}\n","/**\n * Which surface a finding belongs to. The **merge gate** (the PR comment) is about\n * the *merged artifact* — what a reviewer must check before merging. The **operator**\n * view (the `receipts` card and `receipts trends`) is about *how the agent worked* —\n * efficiency, cost, loops, retries. One source of truth, shared by the PR-comment\n * renderer and its standalone Action mirror.\n */\n\n/** Kinds that describe agent behaviour/efficiency, not the merged change. */\nconst OPERATOR_KINDS = new Set([\n \"loop\",\n \"bottleneck\",\n \"cost-concentration\",\n \"cache-opportunity\",\n \"model-downgrade\",\n]);\n\nexport type Surface = \"merge\" | \"operator\";\n\nexport function findingSurface(id: string): Surface {\n // `errcluster-<tool>` (\"X failed N× before succeeding\") is an efficiency signal.\n if (OPERATOR_KINDS.has(id) || id.startsWith(\"errcluster-\")) {\n return \"operator\";\n }\n return \"merge\";\n}\n\n/**\n * True when a destructive finding's target is a **scratch path** (a `$VAR`, `/tmp`,\n * `/var/folders`, or `~`), so it can't be a merge risk and shouldn't gate the PR.\n * Parsed from the finding title's clause (the `destructiveMatch` output, e.g.\n * `Destructive op: rm -rf \"$TMP\"`). Conservative: only returns true when **every**\n * `rm`/`rmdir` operand is clearly non-repo — `rm -rf ./src`, `rm -rf build`,\n * `git reset --hard`, `DROP TABLE` are all kept (return false).\n */\nexport function destructiveOutsideRepo(title: string): boolean {\n const clause = title.replace(/^Destructive op:\\s*/i, \"\").replace(/\\s*×\\d+\\s*$/, \"\");\n // Only filesystem removals carry a path target we can judge; git/SQL/infra\n // destructives act on the repo or an external system → never \"outside repo\".\n const m = clause.match(/^\\s*(rm|rmdir)\\b(.*)$/i);\n if (!m) {\n return false;\n }\n const operands = m[2].split(/\\s+/).filter((t) => t && !t.startsWith(\"-\"));\n if (operands.length === 0) {\n return false;\n }\n const scratch = (t: string): boolean => {\n const p = t.replace(/^[\"']|[\"']$/g, \"\");\n return (\n /\\$/.test(p) ||\n p.startsWith(\"/tmp\") ||\n p.startsWith(\"/var/folders\") ||\n p.startsWith(\"/private/var/folders\") ||\n p.startsWith(\"~\")\n );\n };\n return operands.every(scratch);\n}\n\n/**\n * True when a destructive finding deletes only the tool's **own regenerable Receipt\n * artifact** (`rm .receipts/<branch>.json`), e.g. when regenerating it against a\n * corrected base. Like {@link destructiveOutsideRepo} this is a scope-layer carve-out:\n * a `.receipts/*.json` is inside the repo but is rewritten by `receipts pr`, so it\n * isn't a merge risk in the change under review. Conservative: only `rm`/`rmdir` whose\n * **every** operand is a `.receipts/<name>.json` file — a mixed command\n * (`rm .receipts/x.json src/app.ts`) or the whole dir (`rm -rf .receipts`) returns\n * false and keeps flagging.\n */\nexport function regenerableReceiptRm(title: string): boolean {\n const clause = title.replace(/^Destructive op:\\s*/i, \"\").replace(/\\s*×\\d+\\s*$/, \"\");\n const m = clause.match(/^\\s*(rm|rmdir)\\b(.*)$/i);\n if (!m) {\n return false;\n }\n const operands = m[2].split(/\\s+/).filter((t) => t && !t.startsWith(\"-\"));\n if (operands.length === 0) {\n return false;\n }\n // a flat `.receipts/<name>.json` file (receipts are one-per-branch, not nested) —\n // the dir itself (`.receipts`, `.receipts/`) has no `.json` operand, so it's kept.\n const receiptJson = (t: string): boolean =>\n /(?:^|\\/)\\.receipts\\/[^/]+\\.json$/.test(t.replace(/^[\"']|[\"']$/g, \"\"));\n return operands.every(receiptJson);\n}\n","import type { Session, SessionMessage } from \"./types.js\";\n\n/** The distinct branches that appear across a session's messages, in first-seen order. */\nexport function branchesIn(session: Session): string[] {\n const seen: string[] = [];\n for (const m of session.messages) {\n if (m.gitBranch && !seen.includes(m.gitBranch)) {\n seen.push(m.gitBranch);\n }\n }\n return seen;\n}\n\n/**\n * Assign every message an effective branch: its own `gitBranch`, else the nearest\n * preceding tagged branch (carry-forward); leading untagged messages take the\n * first branch that appears. Deterministic.\n */\nfunction effectiveBranches(messages: SessionMessage[]): (string | undefined)[] {\n const firstTagged = messages.find((m) => m.gitBranch)?.gitBranch;\n let current = firstTagged;\n return messages.map((m) => {\n if (m.gitBranch) {\n current = m.gitBranch;\n }\n return current;\n });\n}\n\n/**\n * Slice a session down to the messages belonging to `branch` (non-contiguous\n * visits included), recomputing the per-session `digestSource` over the slice so\n * the Receipt's subject digest is scoped to this branch's work. Deterministic.\n *\n * Returns null when the branch isn't present in the session at all.\n */\nexport function sliceByBranch(session: Session, branch: string): Session | null {\n if (!branchesIn(session).includes(branch)) {\n return null;\n }\n const eff = effectiveBranches(session.messages);\n const messages = session.messages.filter((_, i) => eff[i] === branch);\n if (messages.length === 0) {\n return null;\n }\n const timestamps = messages\n .map((m) => m.timestamp)\n .filter((t): t is number => typeof t === \"number\");\n const startedAt = timestamps.length ? Math.min(...timestamps) : session.startedAt;\n const endedAt = timestamps.length ? Math.max(...timestamps) : session.endedAt;\n\n return {\n ...session,\n id: `${session.id}#${branch}`,\n gitBranch: branch,\n startedAt,\n endedAt,\n messages,\n // Scope the subject digest to this branch's slice (reproducible by re-slicing).\n digestSource: JSON.stringify({ id: session.id, branch, messages }),\n };\n}\n","import { deriveFindings } from \"../findings/findings.js\";\nimport { deriveSpans } from \"../findings/spans.js\";\nimport { type Receipt, type ReceiptScope, buildReceipt } from \"../receipt/build.js\";\nimport { canonicalize } from \"../receipt/canonical.js\";\nimport { redactReceipt } from \"../share/redact.js\";\nimport { shaWindow } from \"../trace/commitMatch.js\";\nimport { applyDiffScope, narrowEffort, windowedEffort } from \"../trace/diffScope.js\";\nimport { loadById } from \"../trace/load.js\";\nimport { agentIds } from \"../trace/registry.js\";\nimport { sliceByBranch } from \"../trace/slice.js\";\nimport type { AgentSource } from \"../trace/types.js\";\n\n/**\n * The agent that produced a receipt, read from its subject prefix (`<source>/<id>`,\n * set in buildReceipt). Re-derivation must load the transcript through the SAME\n * adapter the receipt was built with, or the bytes can't match (e.g. a `codex/…`\n * receipt re-derived through the Claude adapter yields empty evidence). Returns\n * undefined for an unknown prefix so the caller keeps its default.\n */\nexport function sourceFromReceipt(receipt: Receipt): AgentSource | undefined {\n const prefix = receipt.subject?.[0]?.name?.split(\"/\")[0];\n return agentIds().find((id) => id === prefix);\n}\n\nexport interface RederiveOptions {\n /** agent that produced the transcript (default: claude-code) */\n source?: AgentSource;\n /** scope to one branch's turns before deriving */\n branch?: string;\n /** the committed receipt's recorded scope — re-applied so the re-derivation\n * matches a scoped receipt byte-for-byte (SPEC-0013 L1). Its `files`/`branch`\n * come from the receipt, so no git is needed at verify time. */\n scope?: ReceiptScope;\n /** apply secret redaction (to compare against a redacted committed Receipt) */\n redact?: boolean;\n}\n\n/**\n * Re-run the deterministic engine on a transcript file to reproduce its Receipt.\n * Because the pipeline is deterministic, a verifier with the transcript gets the\n * exact same Receipt — that's what proves a committed Receipt is faithful and not\n * fabricated (SPEC-0009 Part B, L1). When the committed receipt was scoped\n * (SPEC-0013), the same recorded scope is re-applied so the bytes still match.\n */\nexport async function rederiveFromTranscript(\n path: string,\n opts: RederiveOptions = {},\n): Promise<Receipt | null> {\n const loaded = await loadById(opts.source ?? \"claude-code\", path);\n if (!loaded) {\n return null;\n }\n // Resolve scope: the recorded `predicate.scope` takes precedence; fall back to a\n // bare `--branch` for pre-SPEC-0013 (branch-only) receipts.\n const scope = opts.scope;\n const branch = scope?.kind === \"branch\" ? scope.branch : opts.branch;\n const session = branch ? (sliceByBranch(loaded, branch) ?? loaded) : loaded;\n\n let derived = deriveSpans(session);\n let findings = deriveFindings(derived);\n if (scope?.kind === \"diff\" && scope.files) {\n const scoped = applyDiffScope(derived, findings, scope.files, session.projectPath);\n derived = scoped.derived;\n findings = scoped.findings;\n if (scope.branch) {\n // SPEC-0068 R4: the receipt declares branch-narrowed effort — recompute it the\n // same way (branch turns ∩ diff-file edits) so the byte-compare holds.\n const slice = sliceByBranch(loaded, scope.branch);\n let eff = narrowEffort(slice ? deriveSpans(slice) : null, scope.files);\n if (!eff && scope.shas?.length) {\n // SPEC-0072 R2: a tagless session declared a SHA-anchored commit window —\n // reproduce it from the transcript + the recorded anchors.\n const win = shaWindow(derived.spans, scope.shas);\n if (win) {\n eff = windowedEffort(derived, scope.files, win);\n }\n }\n if (eff) {\n derived = {\n ...derived,\n diffCostUsd: eff.cost,\n diffTokens: eff.tokens,\n diffTurns: eff.turns,\n };\n }\n }\n }\n\n const receipt = await buildReceipt(session, derived, findings, { scope });\n return opts.redact ? redactReceipt(receipt) : receipt;\n}\n\nexport interface RederiveCompare {\n /** the re-derivation produced a Receipt at all */\n rederived: boolean;\n /** the committed Receipt byte-equals the re-derivation (faithful, not fabricated) */\n matches: boolean;\n}\n\n/**\n * Compare a committed Receipt against a fresh re-derivation from its transcript.\n * `matches` true ⇒ the Receipt is the deterministic function of that transcript.\n */\nexport async function compareToTranscript(\n committed: Receipt,\n transcriptPath: string,\n opts: RederiveOptions = {},\n): Promise<RederiveCompare> {\n // Re-apply the committed receipt's own recorded scope so a scoped receipt\n // re-derives byte-for-byte (the basis is in the receipt, so no git is needed).\n const fresh = await rederiveFromTranscript(transcriptPath, {\n redact: true,\n ...opts,\n // Re-derive through the adapter the receipt names (its subject prefix), so a\n // codex/cursor receipt isn't re-run through the Claude adapter. An explicit\n // opts.source still wins.\n source: opts.source ?? sourceFromReceipt(committed),\n scope: committed.predicate.scope,\n });\n if (!fresh) {\n return { rederived: false, matches: false };\n }\n // SPEC-0072 R4: `prEffort` accumulates PRIOR receipts — by construction not a\n // function of this transcript, so it is exempt from the byte-compare. It stays\n // tamper-evident through the envelope/attestation digest.\n const strip = (r: Receipt): Receipt => {\n if (!r.predicate.prEffort) {\n return r;\n }\n const { prEffort: _x, ...rest } = r.predicate;\n return { ...r, predicate: rest as Receipt[\"predicate\"] };\n };\n return {\n rederived: true,\n matches: canonicalize(strip(committed)) === canonicalize(strip(fresh)),\n };\n}\n","/**\n * The catalog of merge-surface checks the engine runs on every diff. The PR comment\n * lists it so a reviewer sees *what was mechanically scanned for* — the cleared checks\n * are the trust surface (\"a deterministic auditor looked for these and found nothing\"),\n * the flagged ones point at the Findings above. This is a render-time partition of the\n * existing finding ids — it adds no detector and makes no judgement: \"cleared\" means\n * **no detector fired on this diff**, never \"this code is good\" (SPEC-0000 R2).\n *\n * Keep this in lock-step with the detectors: every merge-surface finding id prefix MUST\n * map to a category here (the `categorize` self-check throws in dev if one doesn't), so\n * the catalog never silently under-claims or claims a check that doesn't run.\n */\n\nexport interface Check {\n key: string;\n icon: string;\n label: string;\n /** matches the finding-id prefixes this category covers */\n prefixes: string[];\n}\n\n/** Ordered by review priority. Operator/efficiency findings (loop, errcluster, …) are\n * deliberately absent — they live on the `receipts` card, not the merge gate. */\nexport const CHECK_CATALOG: readonly Check[] = [\n {\n key: \"destructive\",\n icon: \"🛡️\",\n label: \"destructive ops\",\n prefixes: [\"destructive\", \"file-shrink\"],\n },\n {\n key: \"git-history\",\n icon: \"🌿\",\n label: \"git-history safety\",\n prefixes: [\"force-push\", \"history-rewrite\"],\n },\n { key: \"secrets\", icon: \"🔑\", label: \"secret leaks\", prefixes: [\"secret\"] },\n { key: \"cicd\", icon: \"⚙️\", label: \"CI/CD tampering\", prefixes: [\"ci-cd-touch\"] },\n { key: \"lockfile\", icon: \"📦\", label: \"lockfile integrity\", prefixes: [\"lockfile-edit\"] },\n {\n key: \"tests\",\n icon: \"🧪\",\n label: \"test integrity\",\n prefixes: [\n \"fake-green\",\n \"test-focus\",\n \"test-skipped\",\n \"test-trivialised\",\n \"grader-edit\",\n \"eval-override\",\n ],\n },\n {\n key: \"weakening\",\n icon: \"🔓\",\n label: \"config/safety weakening\",\n prefixes: [\"config-weaken\", \"hook-bypass\", \"pipe-sh\"],\n },\n {\n key: \"blind-edits\",\n icon: \"👁️\",\n label: \"blind / unverified edits\",\n prefixes: [\"blind-edit\", \"unverified-change\", \"edit-reversion\"],\n },\n { key: \"injection\", icon: \"💉\", label: \"prompt-injection\", prefixes: [\"prompt-injection\"] },\n { key: \"trojan\", icon: \"🕵️\", label: \"hidden unicode\", prefixes: [\"trojan-source\"] },\n {\n key: \"duplication\",\n icon: \"📋\",\n label: \"duplicated code\",\n prefixes: [\"dup-file\", \"duplicated-code\"],\n },\n { key: \"swallowed\", icon: \"🤫\", label: \"swallowed errors\", prefixes: [\"error-swallowed\"] },\n { key: \"stubbed\", icon: \"🚧\", label: \"stubbed implementation\", prefixes: [\"impl-stubbed\"] },\n { key: \"malformed\", icon: \"🧱\", label: \"malformed artifacts\", prefixes: [\"malformed-artifact\"] },\n { key: \"truncated\", icon: \"✂️\", label: \"truncated turns\", prefixes: [\"truncated-turn\"] },\n {\n key: \"promises\",\n icon: \"🤝\",\n label: \"unfulfilled claims\",\n prefixes: [\"claimed-commit-none\", \"unfulfilled-promise\"],\n },\n {\n key: \"tool-calls\",\n icon: \"🧬\",\n label: \"tool-call integrity\",\n prefixes: [\"tool-fabricated\", \"tool-malformed-args\"],\n },\n] as const;\n\n/** A finding id matches a category if it equals or `<prefix>-`-starts one of its prefixes. */\nfunction matches(id: string, check: Check): boolean {\n return check.prefixes.some((p) => id === p || id.startsWith(`${p}-`));\n}\n\n/** The catalog check a finding id belongs to (for cross-receipt rollups), or undefined. */\nexport function checkForId(id: string): Check | undefined {\n return CHECK_CATALOG.find((c) => matches(id, c));\n}\n\nexport type CheckSeverity = \"critical\" | \"high\" | \"medium\" | \"low\";\nconst SEV_RANK: Record<CheckSeverity, number> = { critical: 0, high: 1, medium: 2, low: 3 };\n\nexport interface FlaggedCheck {\n check: Check;\n count: number;\n /** worst severity among the findings that matched this category */\n severity: CheckSeverity;\n}\n\nexport interface CategorizedChecks {\n /** categories with ≥1 merge finding on this diff, each with count + worst severity */\n flagged: FlaggedCheck[];\n /** categories that ran and found nothing — the trust surface */\n cleared: Check[];\n /** total categories in the catalog */\n total: number;\n}\n\n/**\n * Partition the catalog against a set of (merge-surface) findings. A category is\n * `flagged` when ≥1 finding matches it (carrying the count + worst severity), else\n * `cleared`. The order of {@link CHECK_CATALOG} is preserved in both lists.\n */\nexport function categorize(\n findings: readonly { id: string; severity?: CheckSeverity }[],\n): CategorizedChecks {\n const flagged: FlaggedCheck[] = [];\n const cleared: Check[] = [];\n for (const check of CHECK_CATALOG) {\n const hits = findings.filter((f) => matches(f.id, check));\n if (hits.length > 0) {\n const severity = hits\n .map((f) => f.severity ?? \"high\")\n .sort((a, b) => SEV_RANK[a] - SEV_RANK[b])[0];\n flagged.push({ check, count: hits.length, severity });\n } else {\n cleared.push(check);\n }\n }\n return { flagged, cleared, total: CHECK_CATALOG.length };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAUO,SAAS,aAAa,OAAwB;AACnD,SAAO,UAAU,KAAK;AACxB;AAEA,SAAS,UAAU,OAAwB;AACzC,MAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,WAAW;AAC7E,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,UAAU,KAAK;AAAA,EAC7B;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,IAAI,MAAM,IAAI,SAAS,EAAE,KAAK,GAAG,CAAC;AAAA,EAC3C;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,MAAM;AACZ,UAAM,OAAO,OAAO,KAAK,GAAG,EACzB,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,MAAS,EAClC,KAAK;AACR,UAAM,OAAO,KAAK,IAAI,CAAC,MAAM,GAAG,KAAK,UAAU,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,GAAG;AAClF,WAAO,IAAI,IAAI;AAAA,EACjB;AAEA,SAAO;AACT;;;AClCA,SAAS,iBAAiB;AAQ1B,SAAS,aAA8B;AACrC,MAAI,QAAQ,aAAa,UAAU;AACjC,WAAO,CAAC,EAAE,KAAK,UAAU,MAAM,CAAC,EAAE,CAAC;AAAA,EACrC;AACA,MAAI,QAAQ,aAAa,SAAS;AAChC,WAAO,CAAC,EAAE,KAAK,QAAQ,MAAM,CAAC,EAAE,CAAC;AAAA,EACnC;AAEA,SAAO;AAAA,IACL,EAAE,KAAK,WAAW,MAAM,CAAC,EAAE;AAAA,IAC3B,EAAE,KAAK,SAAS,MA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,mBAAmB,UAAU,CAAC,gBAAgB,EAAE;AAAA,EACvF;AAAA,IACE,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU,CAAC,uBAAuB,qBAAqB;AAAA,EACzD;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU,CAAC,mBAAmB,qBAAqB;AAAA,EACrD;AACF;AAGA,SAAS,QAAQ,IAAY,OAAuB;AAClD,SAAO,MAAM,SAAS,KAAK,CAAC,MAAM,OAAO,KAAK,GAAG,WAAW,GAAG,CAAC,GAAG,CAAC;AACtE;AAGO,SAAS,WAAW,IAA+B;AACxD,SAAO,cAAc,KAAK,CAAC,MAAM,QAAQ,IAAI,CAAC,CAAC;AACjD;AAGA,IAAM,WAA0C,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,EAAE;AAuBnF,SAAS,WACd,UACmB;AACnB,QAAM,UAA0B,CAAC;AACjC,QAAM,UAAmB,CAAC;AAC1B,aAAW,SAAS,eAAe;AACjC,UAAM,OAAO,SAAS,OAAO,CAAC,MAAM,QAAQ,EAAE,IAAI,KAAK,CAAC;AACxD,QAAI,KAAK,SAAS,GAAG;AACnB,YAAM,WAAW,KACd,IAAI,CAAC,MAAM,EAAE,YAAY,MAAM,EAC/B,KAAK,CAAC,GAAG,MAAM,SAAS,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC;AAC9C,cAAQ,KAAK,EAAE,OAAO,OAAO,KAAK,QAAQ,SAAS,CAAC;AAAA,IACtD,OAAO;AACL,cAAQ,KAAK,KAAK;AAAA,IACpB;AAAA,EACF;AACA,SAAO,EAAE,SAAS,SAAS,OAAO,cAAc,OAAO;AACzD;","names":["spawnSync","base","spawnSync","commandOf","spawnSync","spawnSync","base"]}
@@ -7,7 +7,7 @@ import {
7
7
  loadSession,
8
8
  selectSummary,
9
9
  upsertSection
10
- } from "./chunk-DBQWQVZZ.js";
10
+ } from "./chunk-ZORGM2DA.js";
11
11
 
12
12
  // src/report/sessions.ts
13
13
  async function deriveTargets(opts) {
@@ -259,4 +259,4 @@ export {
259
259
  renderTrends,
260
260
  upsertTrendsSection
261
261
  };
262
- //# sourceMappingURL=chunk-543NGQTN.js.map
262
+ //# sourceMappingURL=chunk-MSPULJEI.js.map
@@ -612,10 +612,20 @@ var PRICES = [
612
612
  { match: /opus/i, price: { input: 15, output: 75, cacheRead: 1.5, cacheWrite: 18.75 } },
613
613
  { match: /sonnet/i, price: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 } },
614
614
  { match: /haiku/i, price: { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25 } },
615
- // OpenAI
615
+ // OpenAI — rates from the live pricing page (2026-06; cached input = 10% of
616
+ // input, prompt caching has no write surcharge). Field-calibrated after a codex
617
+ // gpt-5.5 marathon receipt priced 1B cache-read tokens 2.5× high (core-internal #146).
616
618
  {
617
619
  match: /gpt-?5.*mini|o4-?mini/i,
618
- price: { input: 0.75, output: 4.5, cacheRead: 0.19, cacheWrite: 0.75 }
620
+ price: { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 }
621
+ },
622
+ {
623
+ match: /gpt-?5\.\d+-?codex/i,
624
+ price: { input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 }
625
+ },
626
+ {
627
+ match: /gpt-?5\.[5-9]/i,
628
+ price: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 0 }
619
629
  },
620
630
  {
621
631
  match: /gpt-?5|gpt-?4\.1|gpt-?4o/i,
@@ -4720,4 +4730,4 @@ export {
4720
4730
  redact,
4721
4731
  redactReceipt
4722
4732
  };
4723
- //# sourceMappingURL=chunk-DBQWQVZZ.js.map
4733
+ //# sourceMappingURL=chunk-ZORGM2DA.js.map