owlrunkit 0.18.4 → 0.19.1

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +109 -4
  3. package/docs/architecture/OWLCODA_RUNKIT_0190_CONSOLIDATED_DAILY_USE_PRODUCT_DECISION_20260812.md +100 -0
  4. package/docs/architecture/OWLCODA_RUNKIT_0191_PROFILE_RECONCILE_PATCH_PRODUCT_DECISION_20260813.md +30 -0
  5. package/docs/architecture/OWLCODA_RUN_KIT_CONTRACT_V0_2.md +57 -0
  6. package/integrations/codex/skills/owlcoda-runkit/SKILL.md +28 -4
  7. package/integrations/codex/skills/owlcoda-runkit/assets/templates/config.json +3 -3
  8. package/integrations/codex/skills/owlcoda-runkit/references/contract-v0.2.md +57 -0
  9. package/package.json +1 -1
  10. package/packages/attest/README.md +9 -5
  11. package/packages/attest/consumer-surface-v2.json +263 -0
  12. package/packages/attest/distribution-manifest-v1.json +14 -1
  13. package/packages/attest/schemas/quick-verification-receipt-v3.schema.json +244 -0
  14. package/packages/attest/schemas/workspace-snapshot-v2.schema.json +114 -0
  15. package/packages/attest/src/dependency-environment.mjs +128 -0
  16. package/packages/attest/src/index.mjs +1 -0
  17. package/packages/attest/src/quick-receipt-contract.mjs +202 -9
  18. package/packages/attest/src/quick.mjs +45 -4
  19. package/packages/attest/src/workspace-snapshot.mjs +133 -6
  20. package/registry-release-policy-v1.json +5 -5
  21. package/sbom.spdx.json +5 -5
  22. package/scripts/runkit-contract/core-contract.mjs +21 -1
  23. package/scripts/runkit-contract/efficiency-metrics.mjs +559 -0
  24. package/scripts/runkit-contract/evidence-store.mjs +130 -0
  25. package/scripts/runkit-contract/onboarding-bootstrap.mjs +685 -0
  26. package/scripts/runkit-contract/onboarding-doctor.mjs +2 -1
  27. package/scripts/runkit-contract/outcome-presentation.mjs +171 -0
  28. package/scripts/runkit-contract/profile-onboarding.mjs +74 -35
  29. package/scripts/runkit-contract/project-cli-resolver.mjs +26 -5
  30. package/scripts/runkit-contract/quick-evidence-reuse.mjs +590 -0
  31. package/scripts/runkit-contract/quick-isolation.mjs +314 -0
  32. package/scripts/runkit-contract/quick-metrics.mjs +51 -3
  33. package/scripts/runkit-contract/quick-receipt.mjs +31 -1
  34. package/scripts/runkit-contract/quick-verify.mjs +216 -25
  35. package/scripts/runkit-contract/quick-workspace-snapshot.mjs +1 -0
  36. package/scripts/runkit-contract/runkit-bootstrap.mjs +1 -0
  37. package/scripts/runkit-contract/runkit-cli.mjs +330 -18
  38. package/scripts/runkit-contract/runtime-transition.mjs +478 -0
  39. package/scripts/runkit-contract/schemas/efficiency-event-v1.schema.json +56 -0
  40. package/scripts/runkit-contract/schemas/efficiency-metrics-v1.schema.json +220 -0
  41. package/scripts/runkit-contract/schemas/external-runtime-report-v1.schema.json +125 -0
  42. package/scripts/runkit-contract/schemas/onboarding-bootstrap-plan-v1.schema.json +168 -0
  43. package/scripts/runkit-contract/schemas/onboarding-bootstrap-receipt-v1.schema.json +130 -0
  44. package/scripts/runkit-contract/schemas/outcome-summary-v1.schema.json +83 -0
  45. package/scripts/runkit-contract/schemas/quick-evidence-reuse-plan-v1.schema.json +59 -0
  46. package/scripts/runkit-contract/schemas/quick-evidence-reuse-receipt-v1.schema.json +79 -0
  47. package/scripts/runkit-contract/schemas/runtime-transition-receipt-v1.schema.json +185 -0
  48. package/scripts/runkit-contract/schemas/team-project-event-v4.schema.json +142 -0
  49. package/scripts/runkit-contract/team-project.mjs +704 -16
  50. package/scripts/runkit-contract/verification-envelope.mjs +15 -18
@@ -0,0 +1,590 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { createHash, randomUUID } from "node:crypto";
3
+ import {
4
+ existsSync,
5
+ lstatSync,
6
+ mkdirSync,
7
+ readFileSync,
8
+ realpathSync,
9
+ renameSync,
10
+ writeFileSync,
11
+ } from "node:fs";
12
+ import path from "node:path";
13
+
14
+ import {
15
+ decodeUtf8Strict,
16
+ hasExactKeys,
17
+ parseJsonStrict,
18
+ readFileBytesBounded,
19
+ sha256Bytes,
20
+ sha256Canonical,
21
+ } from "../../packages/attest/src/formal.mjs";
22
+ import {
23
+ quickSnapshotFingerprintValid,
24
+ validQuickReceiptShape,
25
+ } from "../../packages/attest/src/quick-receipt-contract.mjs";
26
+ import { attestQuickReceiptDetails } from "./quick-attest.mjs";
27
+ import { runQuickVerification } from "./quick-verify.mjs";
28
+ import { captureWorkspaceSnapshot } from "./quick-workspace-snapshot.mjs";
29
+
30
+ const REUSE_ROOT = ".owlcoda/runkit/quick/reuse";
31
+ const MAX_GIT_BLOB_BYTES = 512 * 1024 * 1024;
32
+ const ALLOWED_BASE_ATTESTATION_ISSUES = new Set([
33
+ "anchor_absent",
34
+ "receipt_source_mismatch",
35
+ "signature_absent",
36
+ ]);
37
+ const NON_DECISIONAL_DELTA_ATTESTATION_ISSUES = new Set([
38
+ "anchor_absent",
39
+ "signature_absent",
40
+ ]);
41
+
42
+ function compareCodeUnits(left, right) {
43
+ if (left < right) return -1;
44
+ if (left > right) return 1;
45
+ return 0;
46
+ }
47
+
48
+ function git(root, args, options = {}) {
49
+ return execFileSync("git", args, {
50
+ cwd: root,
51
+ encoding: options.encoding,
52
+ maxBuffer: options.maxBuffer ?? 64 * 1024 * 1024,
53
+ stdio: ["ignore", "pipe", "pipe"],
54
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
55
+ });
56
+ }
57
+
58
+ function withinRoot(root, candidate) {
59
+ const relative = path.relative(root, candidate);
60
+ return relative !== ""
61
+ && relative !== ".."
62
+ && !relative.startsWith(`..${path.sep}`)
63
+ && !path.isAbsolute(relative);
64
+ }
65
+
66
+ function safeLiteralPath(value) {
67
+ if (typeof value !== "string" || value.length === 0 || path.isAbsolute(value)) return false;
68
+ if (value.includes("\\") || /[\0\r\n\t]/u.test(value)) return false;
69
+ const segments = value.split("/");
70
+ return segments.every(segment => segment.length > 0 && segment !== "." && segment !== "..")
71
+ && value !== ".owlcoda/runkit"
72
+ && !value.startsWith(".owlcoda/runkit/");
73
+ }
74
+
75
+ function safeQuickArtifactPath(value) {
76
+ if (typeof value !== "string" || value.length === 0 || path.isAbsolute(value)) return false;
77
+ if (value.includes("\\") || /[\0\r\n\t]/u.test(value)) return false;
78
+ const segments = value.split("/");
79
+ return segments.every(segment => segment.length > 0 && segment !== "." && segment !== "..")
80
+ && value.startsWith(".owlcoda/runkit/quick/");
81
+ }
82
+
83
+ function selectedPaths(values, label) {
84
+ if (!Array.isArray(values) || values.length === 0 || values.some(value => !safeLiteralPath(value))) {
85
+ throw new Error(`${label} must contain safe literal workspace-relative paths.`);
86
+ }
87
+ const selected = [...new Set(values)].sort(compareCodeUnits);
88
+ if (selected.length !== values.length) throw new Error(`${label} must not contain duplicates.`);
89
+ return selected;
90
+ }
91
+
92
+ function readBaseReceipt(root, requestedPath) {
93
+ const absolute = path.resolve(root, requestedPath);
94
+ if (!withinRoot(root, absolute)) throw new Error("Base Quick receipt must remain inside the workspace.");
95
+ const { bytes } = readFileBytesBounded(absolute);
96
+ const receipt = parseJsonStrict(decodeUtf8Strict(bytes));
97
+ if (
98
+ !validQuickReceiptShape(receipt)
99
+ || !quickSnapshotFingerprintValid(receipt.workspaceBefore)
100
+ || !quickSnapshotFingerprintValid(receipt.workspaceAfter)
101
+ ) {
102
+ throw new Error("Base Quick receipt does not satisfy a supported strict contract.");
103
+ }
104
+ const receiptWorkspace = realpathSync(
105
+ receipt.schemaVersion === "OwlCodaQuickVerificationReceiptV3"
106
+ ? receipt.sourceWorkspaceRoot
107
+ : receipt.exactCommand.cwd,
108
+ );
109
+ if (receiptWorkspace !== root) throw new Error("Base Quick receipt belongs to another workspace.");
110
+ if (
111
+ receipt.mutationDecision !== "source_unchanged"
112
+ || receipt.exitResult.exitCode !== 0
113
+ || receipt.exitResult.signal !== null
114
+ ) {
115
+ throw new Error("Base Quick receipt must record a passed, source-unchanged command.");
116
+ }
117
+ const attested = attestQuickReceiptDetails({ receiptPath: absolute, workspaceRoot: root });
118
+ const disallowed = attested.attestation.issueCodes.filter(
119
+ issue => !ALLOWED_BASE_ATTESTATION_ISSUES.has(issue),
120
+ );
121
+ if (disallowed.length > 0) {
122
+ throw new Error(`Base Quick receipt evidence is not reusable: ${disallowed.join(",")}`);
123
+ }
124
+ return {
125
+ absolute,
126
+ bytes,
127
+ receipt,
128
+ receiptSha256: sha256Bytes(bytes),
129
+ attestationIssueCodes: attested.attestation.issueCodes,
130
+ };
131
+ }
132
+
133
+ function committedChangedPaths(root, beforeHead, afterHead) {
134
+ if (beforeHead === afterHead) return [];
135
+ if (beforeHead === null || afterHead === null) {
136
+ throw new Error("Quick evidence reuse requires committed Git identities on both candidates.");
137
+ }
138
+ return git(root, [
139
+ "diff",
140
+ "--name-only",
141
+ "--no-renames",
142
+ "-z",
143
+ beforeHead,
144
+ afterHead,
145
+ "--",
146
+ ])
147
+ .toString("utf8")
148
+ .split("\0")
149
+ .filter(Boolean);
150
+ }
151
+
152
+ function treeEntry(root, headCommit, relativePath) {
153
+ if (headCommit === null) return null;
154
+ const raw = git(root, ["ls-tree", "-z", "--full-tree", headCommit, "--", relativePath]);
155
+ const records = raw.toString("utf8").split("\0").filter(Boolean);
156
+ const record = records.find(value => value.slice(value.indexOf("\t") + 1) === relativePath);
157
+ if (record === undefined) return null;
158
+ const separator = record.indexOf("\t");
159
+ const [mode, type, objectId] = record.slice(0, separator).split(" ");
160
+ if (mode === "160000" || type === "commit") return `gitlink:${objectId}`;
161
+ if (type !== "blob") throw new Error(`Unsupported Git tree entry for reuse: ${relativePath}`);
162
+ const bytes = git(root, ["cat-file", "blob", objectId], {
163
+ encoding: null,
164
+ maxBuffer: MAX_GIT_BLOB_BYTES,
165
+ });
166
+ const hash = createHash("sha256")
167
+ .update(mode === "120000" ? Buffer.concat([Buffer.from("symlink:"), bytes]) : bytes)
168
+ .digest("hex");
169
+ return `sha256:${hash}`;
170
+ }
171
+
172
+ function candidateIdentity(root, snapshot, relativePath) {
173
+ const overlay = snapshot.dirtyOverlay.find(entry => entry.path === relativePath);
174
+ if (overlay !== undefined) return overlay.state === "deleted" ? null : overlay.sha256;
175
+ const submodule = snapshot.submodules.find(entry => entry.path === relativePath);
176
+ if (submodule !== undefined) return `gitlink:${submodule.commit}`;
177
+ return treeEntry(root, snapshot.headCommit, relativePath);
178
+ }
179
+
180
+ function ignoredBindingMap(snapshot) {
181
+ return new Map((snapshot.ignoredPathBindings ?? []).map(entry => [
182
+ entry.path,
183
+ `${entry.state}:${entry.sha256 ?? "missing"}`,
184
+ ]));
185
+ }
186
+
187
+ function currentDelta({ root, baseSnapshot, currentSnapshot }) {
188
+ if (baseSnapshot.repositoryIdentity !== currentSnapshot.repositoryIdentity) {
189
+ throw new Error("Base receipt repository identity differs from the current workspace.");
190
+ }
191
+ const possible = new Set([
192
+ ...committedChangedPaths(root, baseSnapshot.headCommit, currentSnapshot.headCommit),
193
+ ...baseSnapshot.dirtyOverlay.map(entry => entry.path),
194
+ ...currentSnapshot.dirtyOverlay.map(entry => entry.path),
195
+ ...baseSnapshot.submodules.map(entry => entry.path),
196
+ ...currentSnapshot.submodules.map(entry => entry.path),
197
+ ]);
198
+ const baseIgnored = ignoredBindingMap(baseSnapshot);
199
+ const currentIgnored = ignoredBindingMap(currentSnapshot);
200
+ for (const ignoredPath of new Set([...baseIgnored.keys(), ...currentIgnored.keys()])) {
201
+ if (baseIgnored.get(ignoredPath) !== currentIgnored.get(ignoredPath)) possible.add(ignoredPath);
202
+ }
203
+ return [...possible]
204
+ .filter(relativePath => {
205
+ if (baseIgnored.has(relativePath) || currentIgnored.has(relativePath)) {
206
+ return baseIgnored.get(relativePath) !== currentIgnored.get(relativePath);
207
+ }
208
+ return candidateIdentity(root, baseSnapshot, relativePath)
209
+ !== candidateIdentity(root, currentSnapshot, relativePath);
210
+ })
211
+ .sort(compareCodeUnits);
212
+ }
213
+
214
+ function captureStableCurrent(root, baseSnapshot) {
215
+ const ignoredPaths = (baseSnapshot.ignoredPathBindings ?? []).map(entry => entry.path);
216
+ const first = captureWorkspaceSnapshot(root, { ignoredPaths });
217
+ const second = captureWorkspaceSnapshot(root, { ignoredPaths });
218
+ if (first.sourceFingerprint !== second.sourceFingerprint) {
219
+ throw new Error("Current workspace changed while planning Quick evidence reuse.");
220
+ }
221
+ return first;
222
+ }
223
+
224
+ function blockedResult(error) {
225
+ return {
226
+ status: "quick_evidence_reuse_input_invalid",
227
+ exitCode: 3,
228
+ ready: false,
229
+ issues: [error instanceof Error ? error.message : String(error)],
230
+ actualDeltaPaths: [],
231
+ outOfScopePaths: [],
232
+ unusedAllowedPaths: [],
233
+ reuseReceiptPath: null,
234
+ authorizationGranted: false,
235
+ };
236
+ }
237
+
238
+ function withBaseReceipt(result, receipt) {
239
+ Object.defineProperty(result, "_baseReceipt", {
240
+ value: receipt,
241
+ enumerable: false,
242
+ });
243
+ return result;
244
+ }
245
+
246
+ export function planQuickEvidenceReuse({ workspaceRoot, baseReceiptPath, allowedPaths }) {
247
+ try {
248
+ const root = realpathSync(workspaceRoot);
249
+ const gitRoot = realpathSync(git(root, ["rev-parse", "--show-toplevel"], { encoding: "utf8" }).trim());
250
+ if (gitRoot !== root) throw new Error("Quick evidence reuse requires the exact Git worktree root.");
251
+ const allowed = selectedPaths(allowedPaths, "Allowed delta paths");
252
+ const base = readBaseReceipt(root, baseReceiptPath);
253
+ const current = captureStableCurrent(root, base.receipt.workspaceAfter);
254
+ const actualDeltaPaths = currentDelta({
255
+ root,
256
+ baseSnapshot: base.receipt.workspaceAfter,
257
+ currentSnapshot: current,
258
+ });
259
+ const allowedSet = new Set(allowed);
260
+ const actualSet = new Set(actualDeltaPaths);
261
+ const outOfScopePaths = actualDeltaPaths.filter(value => !allowedSet.has(value));
262
+ const unusedAllowedPaths = allowed.filter(value => !actualSet.has(value));
263
+ const common = {
264
+ schemaVersion: "OwlCodaQuickEvidenceReusePlanV1",
265
+ baseReceipt: {
266
+ receiptId: base.receipt.receiptId,
267
+ path: path.relative(root, base.absolute).split(path.sep).join("/"),
268
+ sha256: base.receiptSha256,
269
+ sourceFingerprint: base.receipt.workspaceAfter.sourceFingerprint,
270
+ attestationIssueCodes: base.attestationIssueCodes,
271
+ },
272
+ allowedPaths: allowed,
273
+ actualDeltaPaths,
274
+ outOfScopePaths,
275
+ unusedAllowedPaths,
276
+ currentSourceFingerprint: current.sourceFingerprint,
277
+ authorizationGranted: false,
278
+ };
279
+ if (outOfScopePaths.length > 0) {
280
+ return withBaseReceipt({
281
+ ...common,
282
+ status: "quick_evidence_reuse_blocked",
283
+ exitCode: 2,
284
+ ready: false,
285
+ issues: ["Current candidate includes delta paths outside the explicit allowance."],
286
+ }, base.receipt);
287
+ }
288
+ if (actualDeltaPaths.length === 0) {
289
+ return withBaseReceipt({
290
+ ...common,
291
+ status: "quick_evidence_reuse_not_needed",
292
+ exitCode: 0,
293
+ ready: false,
294
+ issues: [],
295
+ }, base.receipt);
296
+ }
297
+ return withBaseReceipt({
298
+ ...common,
299
+ status: "quick_evidence_reuse_ready",
300
+ exitCode: 0,
301
+ ready: true,
302
+ issues: [],
303
+ }, base.receipt);
304
+ } catch (error) {
305
+ return blockedResult(error);
306
+ }
307
+ }
308
+
309
+ function ensureReuseDirectory(root) {
310
+ let current = root;
311
+ for (const segment of REUSE_ROOT.split("/")) {
312
+ current = path.join(current, segment);
313
+ if (!existsSync(current)) {
314
+ try {
315
+ mkdirSync(current);
316
+ } catch (error) {
317
+ if (error?.code !== "EEXIST") throw error;
318
+ }
319
+ }
320
+ const stat = lstatSync(current);
321
+ if (stat.isSymbolicLink() || !stat.isDirectory() || !withinRoot(root, realpathSync(current))) {
322
+ throw new Error("Quick evidence reuse store must be a real in-workspace directory.");
323
+ }
324
+ }
325
+ return current;
326
+ }
327
+
328
+ function persistReuseReceipt(root, body) {
329
+ const receipt = { ...body, receiptSha256: sha256Canonical(body) };
330
+ const directory = ensureReuseDirectory(root);
331
+ const receiptPath = path.join(directory, `${body.reuseId}.json`);
332
+ const temporary = `${receiptPath}.tmp-${process.pid}-${randomUUID()}`;
333
+ writeFileSync(temporary, `${JSON.stringify(receipt, null, 2)}\n`, { flag: "wx", mode: 0o600 });
334
+ renameSync(temporary, receiptPath);
335
+ return { receipt, receiptPath };
336
+ }
337
+
338
+ function validReuseReceiptShape(receipt) {
339
+ return hasExactKeys(receipt, [
340
+ "schemaVersion",
341
+ "reuseId",
342
+ "baseReceipt",
343
+ "delta",
344
+ "decision",
345
+ "reasonCodes",
346
+ "proven",
347
+ "notProven",
348
+ "createdAt",
349
+ "authorizationGranted",
350
+ "receiptSha256",
351
+ ])
352
+ && receipt.schemaVersion === "OwlCodaQuickEvidenceReuseReceiptV1"
353
+ && /^[A-Za-z0-9._-]+$/u.test(receipt.reuseId)
354
+ && receipt.authorizationGranted === false
355
+ && ["accepted", "rejected"].includes(receipt.decision)
356
+ && Array.isArray(receipt.reasonCodes)
357
+ && Array.isArray(receipt.proven)
358
+ && receipt.proven.length >= 2
359
+ && Array.isArray(receipt.notProven)
360
+ && receipt.notProven.length >= 2
361
+ && typeof receipt.createdAt === "string"
362
+ && Number.isFinite(Date.parse(receipt.createdAt))
363
+ && hasExactKeys(receipt.baseReceipt, [
364
+ "receiptId", "path", "sha256", "sourceFingerprint", "attestationIssueCodes",
365
+ ])
366
+ && safeQuickArtifactPath(receipt.baseReceipt.path)
367
+ && typeof receipt.baseReceipt.receiptId === "string"
368
+ && Array.isArray(receipt.baseReceipt.attestationIssueCodes)
369
+ && hasExactKeys(receipt.delta, [
370
+ "allowedPaths",
371
+ "actualPaths",
372
+ "unusedAllowedPaths",
373
+ "currentSourceFingerprint",
374
+ "receiptId",
375
+ "receiptPath",
376
+ "receiptSha256",
377
+ "command",
378
+ ])
379
+ && safeQuickArtifactPath(receipt.delta.receiptPath)
380
+ && Array.isArray(receipt.delta.allowedPaths)
381
+ && Array.isArray(receipt.delta.actualPaths)
382
+ && Array.isArray(receipt.delta.unusedAllowedPaths)
383
+ && hasExactKeys(receipt.delta.command, ["executable", "argv"])
384
+ && typeof receipt.delta.command.executable === "string"
385
+ && Array.isArray(receipt.delta.command.argv)
386
+ && receipt.delta.command.argv.every(value => typeof value === "string")
387
+ && /^sha256:[a-f0-9]{64}$/u.test(receipt.receiptSha256)
388
+ && /^sha256:[a-f0-9]{64}$/u.test(receipt.baseReceipt.sha256)
389
+ && /^sha256:[a-f0-9]{64}$/u.test(receipt.baseReceipt.sourceFingerprint)
390
+ && /^sha256:[a-f0-9]{64}$/u.test(receipt.delta.receiptSha256)
391
+ && /^sha256:[a-f0-9]{64}$/u.test(receipt.delta.currentSourceFingerprint);
392
+ }
393
+
394
+ export function verifyQuickEvidenceReuseReceipt({ workspaceRoot, receiptPath }) {
395
+ const issues = [];
396
+ try {
397
+ const root = realpathSync(workspaceRoot);
398
+ const absolute = path.resolve(root, receiptPath);
399
+ if (!withinRoot(root, absolute)) throw new Error("Reuse receipt escapes the workspace.");
400
+ const { bytes } = readFileBytesBounded(absolute);
401
+ const receipt = parseJsonStrict(decodeUtf8Strict(bytes));
402
+ if (!validReuseReceiptShape(receipt)) throw new Error("Reuse receipt shape is invalid.");
403
+ const { receiptSha256, ...body } = receipt;
404
+ if (sha256Canonical(body) !== receiptSha256) issues.push("reuse_receipt_hash_mismatch");
405
+
406
+ const basePath = path.resolve(root, receipt.baseReceipt.path);
407
+ const baseBytes = readFileBytesBounded(basePath).bytes;
408
+ const base = parseJsonStrict(decodeUtf8Strict(baseBytes));
409
+ if (
410
+ sha256Bytes(baseBytes) !== receipt.baseReceipt.sha256
411
+ || !validQuickReceiptShape(base)
412
+ || base.receiptId !== receipt.baseReceipt.receiptId
413
+ || base.workspaceAfter.sourceFingerprint !== receipt.baseReceipt.sourceFingerprint
414
+ ) {
415
+ issues.push("reuse_base_receipt_mismatch");
416
+ }
417
+
418
+ const deltaPath = path.resolve(root, receipt.delta.receiptPath);
419
+ const deltaBytes = readFileBytesBounded(deltaPath).bytes;
420
+ const delta = parseJsonStrict(decodeUtf8Strict(deltaBytes));
421
+ if (
422
+ sha256Bytes(deltaBytes) !== receipt.delta.receiptSha256
423
+ || !validQuickReceiptShape(delta)
424
+ || delta.receiptId !== receipt.delta.receiptId
425
+ || delta.workspaceAfter.sourceFingerprint !== receipt.delta.currentSourceFingerprint
426
+ || delta.exactCommand.executable !== receipt.delta.command.executable
427
+ || JSON.stringify(delta.exactCommand.argv) !== JSON.stringify(receipt.delta.command.argv)
428
+ ) {
429
+ issues.push("reuse_delta_receipt_mismatch");
430
+ }
431
+ const deltaAttestation = attestQuickReceiptDetails({
432
+ receiptPath: deltaPath,
433
+ workspaceRoot: root,
434
+ });
435
+ if (deltaAttestation.attestation.decision !== "GO") {
436
+ issues.push("reuse_delta_attestation_failed");
437
+ issues.push(...deltaAttestation.attestation.issueCodes.filter(
438
+ issue => !NON_DECISIONAL_DELTA_ATTESTATION_ISSUES.has(issue),
439
+ ));
440
+ }
441
+
442
+ if (receipt.decision === "accepted") {
443
+ if (
444
+ receipt.reasonCodes.length !== 0
445
+ || delta.mutationDecision !== "source_unchanged"
446
+ || delta.exitResult.exitCode !== 0
447
+ || delta.exitResult.signal !== null
448
+ ) {
449
+ issues.push("reuse_accepted_delta_not_passed");
450
+ }
451
+ const plan = planQuickEvidenceReuse({
452
+ workspaceRoot: root,
453
+ baseReceiptPath: receipt.baseReceipt.path,
454
+ allowedPaths: receipt.delta.allowedPaths,
455
+ });
456
+ if (
457
+ plan.status !== "quick_evidence_reuse_ready"
458
+ || plan.currentSourceFingerprint !== receipt.delta.currentSourceFingerprint
459
+ || JSON.stringify(plan.actualDeltaPaths) !== JSON.stringify(receipt.delta.actualPaths)
460
+ || JSON.stringify(plan.unusedAllowedPaths) !== JSON.stringify(receipt.delta.unusedAllowedPaths)
461
+ ) {
462
+ issues.push("reuse_current_candidate_mismatch");
463
+ }
464
+ }
465
+ return {
466
+ status: issues.length === 0 ? "quick_evidence_reuse_receipt_valid" : "quick_evidence_reuse_receipt_invalid",
467
+ exitCode: issues.length === 0 && receipt.decision === "accepted" ? 0 : 1,
468
+ decision: issues.length === 0 && receipt.decision === "accepted" ? "GO" : "NO_GO",
469
+ issueCodes: [...new Set(issues)].sort(),
470
+ receiptPath: absolute,
471
+ receiptSha256: sha256Bytes(bytes),
472
+ authorizationGranted: false,
473
+ };
474
+ } catch (error) {
475
+ return {
476
+ status: "quick_evidence_reuse_receipt_invalid",
477
+ exitCode: 1,
478
+ decision: "NO_GO",
479
+ issueCodes: ["reuse_receipt_unreadable_or_invalid"],
480
+ issues: [error instanceof Error ? error.message : String(error)],
481
+ authorizationGranted: false,
482
+ };
483
+ }
484
+ }
485
+
486
+ export async function runQuickEvidenceReuse({
487
+ workspaceRoot,
488
+ baseReceiptPath,
489
+ allowedPaths,
490
+ commandArgv,
491
+ stdinFile,
492
+ apply = false,
493
+ }) {
494
+ const plan = planQuickEvidenceReuse({ workspaceRoot, baseReceiptPath, allowedPaths });
495
+ const { _baseReceipt: baseReceipt, ...publicPlan } = plan;
496
+ if (!plan.ready || apply !== true) {
497
+ return { ...publicPlan, reuseReceiptPath: null };
498
+ }
499
+ if (!Array.isArray(commandArgv) || commandArgv.length === 0) {
500
+ return blockedResult(new Error("An exact delta command is required after --."));
501
+ }
502
+ const root = realpathSync(workspaceRoot);
503
+ const baseIgnoredPaths = (baseReceipt.workspaceAfter.ignoredPathBindings ?? [])
504
+ .map(entry => entry.path);
505
+ const baseDependencyRoot = baseReceipt.executionIsolation?.dependencyEnvironment?.root;
506
+ const isolate = baseReceipt.executionIsolation !== null
507
+ && baseReceipt.executionIsolation !== undefined;
508
+ const delta = await runQuickVerification({
509
+ workspaceRoot: root,
510
+ commandArgv,
511
+ stdinFile,
512
+ isolate,
513
+ dependencyRoot: baseDependencyRoot,
514
+ ignoredPaths: baseIgnoredPaths,
515
+ });
516
+ if (delta.receiptPath === null || delta.receiptPath === undefined) {
517
+ return {
518
+ ...publicPlan,
519
+ status: "quick_evidence_reuse_blocked",
520
+ exitCode: delta.exitCode,
521
+ ready: false,
522
+ issues: delta.issues,
523
+ reuseReceiptPath: null,
524
+ };
525
+ }
526
+ const deltaBytes = readFileSync(delta.receiptPath);
527
+ const deltaReceipt = JSON.parse(deltaBytes.toString("utf8"));
528
+ const accepted = delta.status === "quick_verification_passed"
529
+ && deltaReceipt.workspaceBefore.sourceFingerprint === plan.currentSourceFingerprint
530
+ && deltaReceipt.workspaceAfter.sourceFingerprint === plan.currentSourceFingerprint;
531
+ const reasonCodes = accepted
532
+ ? []
533
+ : delta.status === "quick_verification_failed"
534
+ ? ["delta_verification_command_failed"]
535
+ : ["delta_candidate_or_environment_mutated"];
536
+ const reuseId = `reuse-${Date.now()}-${randomUUID()}`;
537
+ const body = {
538
+ schemaVersion: "OwlCodaQuickEvidenceReuseReceiptV1",
539
+ reuseId,
540
+ baseReceipt: publicPlan.baseReceipt,
541
+ delta: {
542
+ allowedPaths: publicPlan.allowedPaths,
543
+ actualPaths: publicPlan.actualDeltaPaths,
544
+ unusedAllowedPaths: publicPlan.unusedAllowedPaths,
545
+ currentSourceFingerprint: plan.currentSourceFingerprint,
546
+ receiptId: deltaReceipt.receiptId,
547
+ receiptPath: path.relative(root, delta.receiptPath).split(path.sep).join("/"),
548
+ receiptSha256: sha256Bytes(deltaBytes),
549
+ command: {
550
+ executable: deltaReceipt.exactCommand.executable,
551
+ argv: deltaReceipt.exactCommand.argv,
552
+ },
553
+ },
554
+ decision: accepted ? "accepted" : "rejected",
555
+ reasonCodes,
556
+ proven: [
557
+ "The base Quick receipt is strict, passed, source-unchanged, and material-readable.",
558
+ "Every current candidate delta is an explicitly allowed literal path.",
559
+ ...(accepted ? ["The exact delta verification command passed without candidate drift."] : []),
560
+ ],
561
+ notProven: [
562
+ "Formal, UX, deployment, production, and business acceptance are not proven.",
563
+ "No Git, release, deployment, production, or business authority is granted.",
564
+ ],
565
+ createdAt: new Date().toISOString(),
566
+ authorizationGranted: false,
567
+ };
568
+ const persisted = persistReuseReceipt(root, body);
569
+ const verification = verifyQuickEvidenceReuseReceipt({
570
+ workspaceRoot: root,
571
+ receiptPath: persisted.receiptPath,
572
+ });
573
+ if (accepted && verification.decision !== "GO") {
574
+ throw new Error(`Persisted Quick evidence reuse receipt failed verification: ${verification.issueCodes.join(",")}`);
575
+ }
576
+ return {
577
+ ...publicPlan,
578
+ status: accepted ? "quick_evidence_reuse_accepted" : "quick_evidence_reuse_rejected",
579
+ exitCode: accepted ? 0 : 1,
580
+ decision: persisted.receipt.decision,
581
+ reasonCodes,
582
+ deltaReceiptPath: delta.receiptPath,
583
+ reuseReceiptPath: persisted.receiptPath,
584
+ reuseReceiptSha256: persisted.receipt.receiptSha256,
585
+ outputSummary: delta.outputSummary,
586
+ evidenceStorage: delta.evidenceStorage,
587
+ verification,
588
+ authorizationGranted: false,
589
+ };
590
+ }