opencode-swarm 7.146.3 → 7.146.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.opencode/skills/swarm-pr-review/SKILL.md +27 -44
  2. package/.opencode/skills/swarm-pr-review/references/findings-persistence-contract.md +52 -12
  3. package/.opencode/skills/swarm-pr-review/references/lane-output-recoverability.md +6 -3
  4. package/.opencode/skills/swarm-pr-review/references/parser-dry-run.md +19 -1
  5. package/.opencode/skills/swarm-pr-review/references/verdict-settlement-contract.md +41 -0
  6. package/dist/background/candidate-contract.d.ts +21 -1
  7. package/dist/background/candidate-parser.d.ts +21 -1
  8. package/dist/background/pending-delegations.d.ts +8 -1
  9. package/dist/background/pr-review-collection-receipt.d.ts +70 -0
  10. package/dist/cli/{config-doctor-yd866pd5.js → config-doctor-578ebqhn.js} +2 -2
  11. package/dist/cli/{core-nc9a9g5m.js → core-2ne03a43.js} +1 -1
  12. package/dist/cli/{curation-policy-9vv7v5rf.js → curation-policy-g353f457.js} +4 -4
  13. package/dist/cli/{curator-llm-factory-ewffa8r1.js → curator-llm-factory-6hgn7p6n.js} +24 -24
  14. package/dist/cli/{curator-acp80hpc.js → curator-w52frg17.js} +24 -24
  15. package/dist/cli/{evidence-summary-service-8gw74j8g.js → evidence-summary-service-nj4p6a0d.js} +9 -9
  16. package/dist/cli/{gate-evidence-jj3zt2x1.js → gate-evidence-4vnjdh9y.js} +4 -4
  17. package/dist/cli/{guardrail-explain-50cp8k3r.js → guardrail-explain-rq01z1yz.js} +25 -25
  18. package/dist/cli/{guardrail-log-jazq10gt.js → guardrail-log-ratb651f.js} +3 -3
  19. package/dist/cli/{hive-promoter-qhrngsvb.js → hive-promoter-pbm9kee1.js} +24 -24
  20. package/dist/cli/{index-gayh8tmh.js → index-1mbdwy12.js} +1 -1
  21. package/dist/cli/{index-fypq68yn.js → index-3neh2mxk.js} +1 -1
  22. package/dist/cli/{index-4zevsvaa.js → index-5cbbtbvf.js} +3 -3
  23. package/dist/cli/{index-0a4s2803.js → index-6eycwm3v.js} +4 -4
  24. package/dist/cli/{index-1kq3x5q6.js → index-8py21zn6.js} +1 -1
  25. package/dist/cli/{index-262kyrk3.js → index-96zkay2e.js} +2 -2
  26. package/dist/cli/{index-bydybrke.js → index-bq4mvwht.js} +2 -2
  27. package/dist/cli/{index-n96nt4gb.js → index-brb64k96.js} +247 -102
  28. package/dist/cli/{index-3gagma8p.js → index-df8xj9hr.js} +1 -1
  29. package/dist/cli/{index-a7cnyp5e.js → index-dp5w9s5z.js} +5 -5
  30. package/dist/cli/{index-j2ckvbx7.js → index-f75qjtn5.js} +1 -1
  31. package/dist/cli/{index-pgsvn005.js → index-ffqdah8s.js} +5 -5
  32. package/dist/cli/{index-ypwwchs0.js → index-fp2d44f5.js} +1 -1
  33. package/dist/cli/{index-eybamsqg.js → index-g2r8nknz.js} +2 -2
  34. package/dist/cli/{index-cgcs823z.js → index-g335vrc7.js} +4 -4
  35. package/dist/cli/{index-7ph5pz77.js → index-gr3zfcsh.js} +2 -1
  36. package/dist/cli/{index-qjgg9qzs.js → index-hcb25p12.js} +1 -1
  37. package/dist/cli/{index-xz9w7sa9.js → index-hw1yghpg.js} +4 -4
  38. package/dist/cli/{index-gwt7ceh7.js → index-jgwhpza8.js} +2 -2
  39. package/dist/cli/{index-bxk21f2w.js → index-kjmcp9mf.js} +1 -1
  40. package/dist/cli/{index-923phxsp.js → index-kv2j4cnq.js} +6 -6
  41. package/dist/cli/{index-pc4423w8.js → index-p3k155dv.js} +1 -1
  42. package/dist/cli/{index-bxs4wkjf.js → index-rpy0bent.js} +177 -17
  43. package/dist/cli/{index-qqawmxe7.js → index-t798v5pq.js} +26 -26
  44. package/dist/cli/{index-463msy1e.js → index-tp5ytzzg.js} +1 -1
  45. package/dist/cli/{index-v2eevdbj.js → index-vdrwj7z0.js} +4 -4
  46. package/dist/cli/{index-yr1aabxa.js → index-wesj94x0.js} +3 -3
  47. package/dist/cli/{index-3377n9qp.js → index-xsxj4vbf.js} +1 -1
  48. package/dist/cli/index.js +24 -24
  49. package/dist/cli/{knowledge-escalator-7zpg79dx.js → knowledge-escalator-jbazxmk5.js} +9 -9
  50. package/dist/cli/{knowledge-events-8abttcnt.js → knowledge-events-jyqy3st8.js} +7 -7
  51. package/dist/cli/{knowledge-link-mgg482z6.js → knowledge-link-jkx8xjxp.js} +3 -3
  52. package/dist/cli/{knowledge-store-a5mzf986.js → knowledge-store-e2defagd.js} +4 -4
  53. package/dist/cli/{knowledge-validator-fn2myc73.js → knowledge-validator-pnmdsw2b.js} +6 -6
  54. package/dist/cli/{pending-delegations-591vme3d.js → pending-delegations-k2yqg1sj.js} +1 -1
  55. package/dist/cli/{runner-rcnpm510.js → runner-q7d22d1w.js} +4 -4
  56. package/dist/cli/{scan-cursor-4jv70zwb.js → scan-cursor-snx85enn.js} +5 -5
  57. package/dist/cli/{schema-jhz9hme9.js → schema-6rmxzg6g.js} +1 -1
  58. package/dist/cli/{scope-persistence-ykswenxj.js → scope-persistence-23cqafkx.js} +5 -5
  59. package/dist/cli/{skill-generator-k5pxb3w2.js → skill-generator-980zjk9q.js} +11 -11
  60. package/dist/cli/{worktree-collision-ownership-vt0jzmdt.js → worktree-collision-ownership-xj0bsg92.js} +1 -1
  61. package/dist/cli/{worktree-isolation-443q0pah.js → worktree-isolation-4d0nc04c.js} +24 -24
  62. package/dist/hooks/pr-workflow-gate.d.ts +58 -5
  63. package/dist/index.js +80 -77
  64. package/dist/tools/dispatch-lanes.d.ts +30 -8
  65. package/package.json +2 -1
@@ -4,7 +4,7 @@ import {
4
4
  PlanSchema,
5
5
  TaskStatusSchema,
6
6
  init_loader
7
- } from "./index-fypq68yn.js";
7
+ } from "./index-3neh2mxk.js";
8
8
  import {
9
9
  assertProjectRoot,
10
10
  withEvidenceLock
@@ -1,11 +1,11 @@
1
1
  // @bun
2
2
  import {
3
3
  loadPluginConfigWithMeta
4
- } from "./index-fypq68yn.js";
4
+ } from "./index-3neh2mxk.js";
5
5
  import {
6
6
  KnowledgeConfigSchema,
7
7
  init_schema
8
- } from "./index-7ph5pz77.js";
8
+ } from "./index-gr3zfcsh.js";
9
9
  import {
10
10
  validateSwarmPath
11
11
  } from "./index-w8pgjr75.js";
@@ -14,10 +14,10 @@ import {
14
14
  } from "./index-ae75rja9.js";
15
15
  import {
16
16
  resolveKnowledgeStoreDir
17
- } from "./index-j2ckvbx7.js";
17
+ } from "./index-f75qjtn5.js";
18
18
  import {
19
19
  atomicWriteFile
20
- } from "./index-1kq3x5q6.js";
20
+ } from "./index-8py21zn6.js";
21
21
  import {
22
22
  assertProjectRoot
23
23
  } from "./index-6q35swn2.js";
@@ -2693,7 +2693,7 @@ async function applyKnowledgeVerdictFeedback(directory, options) {
2693
2693
  }
2694
2694
  let bumps = 0;
2695
2695
  if (deltas.length > 0) {
2696
- const { bumpKnowledgeConfidenceBatch } = await import("./knowledge-store-a5mzf986.js");
2696
+ const { bumpKnowledgeConfidenceBatch } = await import("./knowledge-store-e2defagd.js");
2697
2697
  bumps = await bumpKnowledgeConfidenceBatch(directory, deltas, options?.floorOptions);
2698
2698
  }
2699
2699
  return {
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteFile
4
- } from "./index-1kq3x5q6.js";
4
+ } from "./index-8py21zn6.js";
5
5
  import {
6
6
  init_logger,
7
7
  warn
@@ -6,12 +6,12 @@ import {
6
6
  resolveSwarmKnowledgePath,
7
7
  transactKnowledge,
8
8
  wordBigrams
9
- } from "./index-923phxsp.js";
9
+ } from "./index-kv2j4cnq.js";
10
10
  import {
11
11
  queryHistoricalOutcomes,
12
12
  readKnowledgeEvents,
13
13
  recordKnowledgeEvent
14
- } from "./index-a7cnyp5e.js";
14
+ } from "./index-dp5w9s5z.js";
15
15
  import {
16
16
  init_knowledge_types,
17
17
  isActiveStatus
@@ -224,11 +224,11 @@ async function maybeQuarantineOnContradiction(directory, entryId, threshold, win
224
224
  alreadyInactive: true
225
225
  };
226
226
  }
227
- const { quarantineEntry } = await import("./knowledge-validator-fn2myc73.js");
227
+ const { quarantineEntry } = await import("./knowledge-validator-pnmdsw2b.js");
228
228
  let policyConfig;
229
229
  try {
230
- const { KnowledgeConfigSchema } = await import("./schema-jhz9hme9.js");
231
- const { loadPluginConfigWithMeta } = await import("./index-4zevsvaa.js");
230
+ const { KnowledgeConfigSchema } = await import("./schema-6rmxzg6g.js");
231
+ const { loadPluginConfigWithMeta } = await import("./index-5cbbtbvf.js");
232
232
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
233
233
  policyConfig = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
234
234
  } catch {
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  redactPath,
4
4
  redactShellCommand
5
- } from "./index-3377n9qp.js";
5
+ } from "./index-xsxj4vbf.js";
6
6
 
7
7
  // src/services/guardrail-log-service.ts
8
8
  import * as fs from "fs/promises";
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  readKnowledge,
4
4
  transactKnowledge
5
- } from "./index-923phxsp.js";
5
+ } from "./index-kv2j4cnq.js";
6
6
  import {
7
7
  init_git_executable,
8
8
  resolveGitExecutableAsync
9
9
  } from "./index-9e6fdz2h.js";
10
10
  import {
11
11
  resolveKnowledgeStoreDir
12
- } from "./index-j2ckvbx7.js";
12
+ } from "./index-f75qjtn5.js";
13
13
  import {
14
14
  init_knowledge_types,
15
15
  isActiveStatus
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  authorizeCuration
4
- } from "./index-463msy1e.js";
4
+ } from "./index-tp5ytzzg.js";
5
5
  import {
6
6
  findNearDuplicate,
7
7
  inferTags,
@@ -9,13 +9,13 @@ import {
9
9
  resolveSwarmKnowledgePath,
10
10
  resolveSwarmRejectedPath,
11
11
  transactKnowledge
12
- } from "./index-923phxsp.js";
12
+ } from "./index-kv2j4cnq.js";
13
13
  import {
14
14
  resolveKnowledgeStoreDir
15
- } from "./index-j2ckvbx7.js";
15
+ } from "./index-f75qjtn5.js";
16
16
  import {
17
17
  atomicWriteFile
18
- } from "./index-1kq3x5q6.js";
18
+ } from "./index-8py21zn6.js";
19
19
  import {
20
20
  require_proper_lockfile
21
21
  } from "./index-7g4c7s5r.js";
@@ -21,7 +21,7 @@ var package_default;
21
21
  var init_package = __esm(() => {
22
22
  package_default = {
23
23
  name: "opencode-swarm",
24
- version: "7.146.3",
24
+ version: "7.146.4",
25
25
  description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
26
26
  main: "dist/index.js",
27
27
  types: "dist/index.d.ts",
@@ -131,6 +131,7 @@ var init_package = __esm(() => {
131
131
  "check:events": "bun run scripts/check-event-contract.ts",
132
132
  "check:retention": "bun run scripts/check-retention-registry.ts",
133
133
  "check:test-file-cap": "bun run scripts/check-test-file-cap.ts",
134
+ "check:pending-fragment": "bun run scripts/check-pending-fragment.ts",
134
135
  "check:gate-portability": "bun run scripts/check-gate-portability.ts",
135
136
  "check:bare-spawn": "bun run scripts/check-bare-executable-spawn.ts",
136
137
  "check:memory-recall": "bun run scripts/memory-recall-regression.ts"
@@ -9,7 +9,7 @@ import {
9
9
  readEvaluationRun,
10
10
  saveEvaluationRun,
11
11
  saveTaskSetSnapshot
12
- } from "./index-pc4423w8.js";
12
+ } from "./index-p3k155dv.js";
13
13
  import {
14
14
  canonicalHash,
15
15
  computeCandidateInputContentHash,
@@ -42,8 +42,8 @@ var SWARM_TEMP_GRAMMARS = [
42
42
  token: "instance",
43
43
  quarantineEligible: true,
44
44
  parsesTarget: true,
45
- producers: ["src/hooks/pr-workflow-gate.ts:12961"],
46
- note: "pre/post-rename file-identity verification (assertOpened/ClosedSwarmFileIdentity, pr-workflow-gate.ts:11844-11889) is writer-specific and load-bearing"
45
+ producers: ["src/hooks/pr-workflow-gate.ts:13358"],
46
+ note: "pre/post-rename file-identity verification (assertOpened/ClosedSwarmFileIdentity, pr-workflow-gate.ts:13300-13356) is writer-specific and load-bearing"
47
47
  },
48
48
  {
49
49
  id: "target-suffix-tmp-num-num-json",
@@ -123,7 +123,7 @@ var SWARM_TEMP_GRAMMARS = [
123
123
  "src/tools/spec-write.ts:98",
124
124
  "src/sdd/effective-spec.ts:1149",
125
125
  "src/background/lane-output-store.ts:353",
126
- "src/background/pending-delegations.ts:905",
126
+ "src/background/pending-delegations.ts:922",
127
127
  "src/background/delegation-health.ts:300",
128
128
  "src/hooks/delegation-gate/worktree-provisioning-owner.ts:100",
129
129
  "src/tools/submit-phase-council-verdicts.ts:458",
@@ -171,7 +171,7 @@ var SWARM_TEMP_GRAMMARS = [
171
171
  quarantineEligible: true,
172
172
  parsesTarget: true,
173
173
  producers: [
174
- "src/tools/write-pr-review-artifact.ts:107",
174
+ "src/tools/write-pr-review-artifact.ts:135",
175
175
  "src/tools/write-pr-review-trigger-eval.ts:574"
176
176
  ],
177
177
  note: "bundled-skills writes outside .swarm (project skill roots) and keeps its own contained-directory logic (invariant 4 bundled-skill ownership)"
@@ -12,14 +12,14 @@ import {
12
12
  detectPosixWrites,
13
13
  detectWindowsWrites,
14
14
  resolveWriteTargets
15
- } from "./index-n96nt4gb.js";
15
+ } from "./index-brb64k96.js";
16
16
  import {
17
17
  checkFileAuthority,
18
18
  classifyFile,
19
19
  isInDeclaredScope,
20
20
  redactPath,
21
21
  redactShellCommand
22
- } from "./index-3377n9qp.js";
22
+ } from "./index-xsxj4vbf.js";
23
23
 
24
24
  // src/services/guardrail-explain-service.ts
25
25
  import path from "path";
@@ -92,7 +92,7 @@ var _internals = {
92
92
  symlinkSync: fs.symlinkSync
93
93
  },
94
94
  writeScopeToDisk: async (directory, taskId, files) => {
95
- const { writeScopeToDisk: realWrite } = await import("./scope-persistence-ykswenxj.js");
95
+ const { writeScopeToDisk: realWrite } = await import("./scope-persistence-23cqafkx.js");
96
96
  return realWrite(directory, taskId, files);
97
97
  },
98
98
  writeLaneProfileToDisk: async (_worktreePath, _laneIndex, _envOverrides) => {
@@ -6,10 +6,10 @@ import {
6
6
  } from "./index-ae75rja9.js";
7
7
  import {
8
8
  resolveKnowledgeStoreDir
9
- } from "./index-j2ckvbx7.js";
9
+ } from "./index-f75qjtn5.js";
10
10
  import {
11
11
  atomicWriteFile
12
- } from "./index-1kq3x5q6.js";
12
+ } from "./index-8py21zn6.js";
13
13
  import {
14
14
  init_knowledge_types,
15
15
  isActiveStatus
@@ -709,7 +709,7 @@ async function applyConfidenceFloorAction(directory, touched, options) {
709
709
  const {
710
710
  readAuthoritativeKnowledgeCounterRollups,
711
711
  effectiveRetrievalOutcomes
712
- } = await import("./knowledge-events-8abttcnt.js");
712
+ } = await import("./knowledge-events-jyqy3st8.js");
713
713
  const rollups = await readAuthoritativeKnowledgeCounterRollups(directory);
714
714
  const flagIds = new Set;
715
715
  for (const e of atFloor) {
@@ -776,11 +776,11 @@ async function applyConfidenceFloorAction(directory, touched, options) {
776
776
  });
777
777
  }
778
778
  if (action === "quarantine" && toQuarantine.length > 0) {
779
- const { quarantineEntry } = await import("./knowledge-validator-fn2myc73.js");
780
- const { KnowledgeConfigSchema } = await import("./schema-jhz9hme9.js");
779
+ const { quarantineEntry } = await import("./knowledge-validator-pnmdsw2b.js");
780
+ const { KnowledgeConfigSchema } = await import("./schema-6rmxzg6g.js");
781
781
  let config;
782
782
  try {
783
- const { loadPluginConfigWithMeta } = await import("./index-4zevsvaa.js");
783
+ const { loadPluginConfigWithMeta } = await import("./index-5cbbtbvf.js");
784
784
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
785
785
  config = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
786
786
  } catch {
@@ -9,7 +9,7 @@ import {
9
9
  } from "./index-y8552snf.js";
10
10
  import {
11
11
  atomicWriteFile
12
- } from "./index-1kq3x5q6.js";
12
+ } from "./index-8py21zn6.js";
13
13
  import {
14
14
  assertProjectRoot,
15
15
  withEvidenceLock
@@ -19,7 +19,7 @@ import {
19
19
 
20
20
  // src/background/pending-delegations.ts
21
21
  init_zod();
22
- import { createHash } from "crypto";
22
+ import { createHash as createHash2 } from "crypto";
23
23
  import * as fs2 from "fs";
24
24
  import * as path2 from "path";
25
25
  import { isDeepStrictEqual } from "util";
@@ -222,6 +222,104 @@ function collectDelegationLedgerHealth(directory, options) {
222
222
  }
223
223
  };
224
224
  }
225
+
226
+ // src/background/pr-review-collection-receipt.ts
227
+ init_zod();
228
+ import { createHash } from "crypto";
229
+ var PR_REVIEW_COLLECTION_RECEIPT_PREFIX = "[PR_REVIEW_COLLECTION_RECEIPT_V1] ";
230
+ var PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX = "[PR_REVIEW_COLLECTION_RECEIPT_SHED_V1] ";
231
+ var MAX_PR_REVIEW_COLLECTION_RECEIPT_CHARS = 64 * 1024;
232
+ var MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS = 1e4;
233
+ var PrReviewCollectionReceiptPayloadSchema = exports_external.object({
234
+ schemaVersion: exports_external.literal(1),
235
+ parentSessionId: exports_external.string().min(1).max(256),
236
+ batchId: exports_external.string().min(1).max(120),
237
+ laneId: exports_external.string().min(1).max(120),
238
+ mode: exports_external.enum(["swarm-pr-review:reviewer", "swarm-pr-review:critic"]),
239
+ workflowLane: exports_external.string().min(1).max(120),
240
+ outputDigest: exports_external.string().regex(/^[a-f0-9]{64}$/),
241
+ disposition: exports_external.enum(["accepted", "rejected"]),
242
+ reviewItemIds: exports_external.array(exports_external.string().min(1).max(160)).min(1).max(MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS)
243
+ }).strict().superRefine((payload, context) => {
244
+ if (new Set(payload.reviewItemIds).size !== payload.reviewItemIds.length) {
245
+ context.addIssue({
246
+ code: exports_external.ZodIssueCode.custom,
247
+ message: "review item IDs must be unique"
248
+ });
249
+ }
250
+ });
251
+ var PrReviewCollectionReceiptShedMarkerSchema = exports_external.object({
252
+ schemaVersion: exports_external.literal(1),
253
+ parentSessionId: exports_external.string().min(1).max(256),
254
+ batchId: exports_external.string().min(1).max(120),
255
+ laneId: exports_external.string().min(1).max(120),
256
+ mode: exports_external.enum(["swarm-pr-review:reviewer", "swarm-pr-review:critic"]),
257
+ workflowLane: exports_external.string().min(1).max(120),
258
+ outputDigest: exports_external.string().regex(/^[a-f0-9]{64}$/),
259
+ disposition: exports_external.enum(["accepted", "rejected"]),
260
+ reviewItemCount: exports_external.number().int().positive().max(MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS),
261
+ reviewItemDigest: exports_external.string().regex(/^[a-f0-9]{64}$/)
262
+ }).strict();
263
+ function reviewItemDigest(reviewItemIds) {
264
+ return createHash("sha256").update(JSON.stringify(reviewItemIds)).digest("hex");
265
+ }
266
+ function encodePrReviewCollectionReceiptShedMarker(payload) {
267
+ const marker = {
268
+ schemaVersion: 1,
269
+ parentSessionId: payload.parentSessionId,
270
+ batchId: payload.batchId,
271
+ laneId: payload.laneId,
272
+ mode: payload.mode,
273
+ workflowLane: payload.workflowLane,
274
+ outputDigest: payload.outputDigest,
275
+ disposition: payload.disposition,
276
+ reviewItemCount: payload.reviewItemIds.length,
277
+ reviewItemDigest: reviewItemDigest(payload.reviewItemIds)
278
+ };
279
+ return `${PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX}${JSON.stringify(marker)}`;
280
+ }
281
+ function parsePrReviewCollectionReceiptShedMarker(binding, result) {
282
+ if (!result.text)
283
+ return null;
284
+ const lines = result.text.split(/\r?\n/);
285
+ const markerLines = lines.filter((line) => line.startsWith(PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX));
286
+ const finalLine = lines.at(-1);
287
+ if (markerLines.length !== 1 || !finalLine?.startsWith(PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX) || finalLine.length > MAX_PR_REVIEW_COLLECTION_RECEIPT_CHARS) {
288
+ return null;
289
+ }
290
+ let decoded;
291
+ try {
292
+ decoded = JSON.parse(finalLine.slice(PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX.length));
293
+ } catch {
294
+ return null;
295
+ }
296
+ const parsed = PrReviewCollectionReceiptShedMarkerSchema.safeParse(decoded);
297
+ if (!parsed.success)
298
+ return null;
299
+ const marker = parsed.data;
300
+ return marker.parentSessionId === binding.parentSessionId && marker.batchId === (binding.batchId ?? binding.callID) && marker.laneId === (binding.laneId ?? binding.correlationId) && marker.mode === binding.mode && marker.workflowLane === binding.workflowLane && marker.outputDigest === result.digest ? marker : null;
301
+ }
302
+ function parsePrReviewCollectionReceiptFooter(binding, result) {
303
+ if (!result.text)
304
+ return null;
305
+ const lines = result.text.split(/\r?\n/);
306
+ const receiptLines = lines.filter((line) => line.startsWith(PR_REVIEW_COLLECTION_RECEIPT_PREFIX));
307
+ const finalLine = lines.at(-1);
308
+ if (receiptLines.length !== 1 || !finalLine?.startsWith(PR_REVIEW_COLLECTION_RECEIPT_PREFIX) || finalLine.length > MAX_PR_REVIEW_COLLECTION_RECEIPT_CHARS) {
309
+ return null;
310
+ }
311
+ let decoded;
312
+ try {
313
+ decoded = JSON.parse(finalLine.slice(PR_REVIEW_COLLECTION_RECEIPT_PREFIX.length));
314
+ } catch {
315
+ return null;
316
+ }
317
+ const parsed = PrReviewCollectionReceiptPayloadSchema.safeParse(decoded);
318
+ if (!parsed.success)
319
+ return null;
320
+ const payload = parsed.data;
321
+ return payload.parentSessionId === binding.parentSessionId && payload.batchId === (binding.batchId ?? binding.callID) && payload.laneId === (binding.laneId ?? binding.correlationId) && payload.mode === binding.mode && payload.workflowLane === binding.workflowLane && payload.outputDigest === result.digest ? payload : null;
322
+ }
225
323
  // src/background/pending-delegations.ts
226
324
  var BACKGROUND_DELEGATIONS_FILE = "background-delegations.jsonl";
227
325
  var BACKGROUND_DELEGATION_FALLBACK_DIR = "background-delegation-fallback";
@@ -237,6 +335,7 @@ var MAX_RECOVERY_FALLBACK_BYTES = 1024 * 1024;
237
335
  var DELEGATION_COMPACTION_LOW_WATER_BYTES = 256 * 1024;
238
336
  var DELEGATION_COMPACTION_HIGH_WATER_BYTES = 1024 * 1024;
239
337
  var MAX_CHECKPOINT_BYTES = 2 * 1024 * 1024;
338
+ var CHECKPOINT_SELECTION_RESERVE_BYTES = 64 * 1024;
240
339
  var MAX_CHECKPOINT_RECORDS = 2048;
241
340
  var TOMBSTONE_MIN_AGE_MS = 72 * 60 * 60 * 1000;
242
341
  var STORE_LOCK_AGENT = "background";
@@ -254,7 +353,8 @@ var WorkflowLaneRecoverySchema = exports_external.object({
254
353
  "parser-normalization",
255
354
  "parser-row-recovery",
256
355
  "truncated-preview-durable-artifact",
257
- "transcript-incomplete-terminal-candidate"
356
+ "transcript-incomplete-terminal-candidate",
357
+ "clean-attestation-salvaged"
258
358
  ]),
259
359
  reason: exports_external.string()
260
360
  }).strict();
@@ -653,7 +753,7 @@ function readDelegationCheckpoint(directory) {
653
753
  return { kind: "ok", checkpoint: parsed.data, bytes };
654
754
  }
655
755
  function sha256Hex(data) {
656
- return createHash("sha256").update(data).digest("hex");
756
+ return createHash2("sha256").update(data).digest("hex");
657
757
  }
658
758
  function checkpointPayloadChecksum(checkpoint) {
659
759
  return sha256Hex(JSON.stringify([
@@ -960,21 +1060,63 @@ function buildClosedSummary(record) {
960
1060
  delete summary.prompt;
961
1061
  delete summary.taskChangeContext;
962
1062
  if (summary.result) {
963
- summary.result = stripResultBody(summary.result);
1063
+ summary.result = stripResultBody(record, summary.result);
964
1064
  }
965
1065
  if (summary.terminalResult) {
966
1066
  summary.terminalResult = {
967
1067
  ...summary.terminalResult,
968
- result: stripResultBody(summary.terminalResult.result)
1068
+ result: dropResultBody(summary.terminalResult.result)
969
1069
  };
970
1070
  }
971
1071
  const parsed = RecordSchema.safeParse(summary);
972
1072
  return parsed.success ? parsed.data : null;
973
1073
  }
974
- function stripResultBody(result) {
1074
+ function stripResultBody(record, result) {
975
1075
  const { text: _text, error: _error, ...rest } = result;
1076
+ const receipt = parsePrReviewCollectionReceiptFooter(record, result);
1077
+ const shedMarker = receipt ? null : parsePrReviewCollectionReceiptShedMarker(record, result);
1078
+ const receiptText = receipt ? `${PR_REVIEW_COLLECTION_RECEIPT_PREFIX}${JSON.stringify(receipt)}` : shedMarker ? `${PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX}${JSON.stringify(shedMarker)}` : undefined;
1079
+ return receiptText ? { ...rest, text: receiptText, outputPreviewChars: receiptText.length } : rest;
1080
+ }
1081
+ function dropResultBody(result) {
1082
+ const {
1083
+ text: _text,
1084
+ error: _error,
1085
+ outputPreviewChars: _preview,
1086
+ ...rest
1087
+ } = result;
976
1088
  return rest;
977
1089
  }
1090
+ function dropRetainedPrReviewReceipt(record) {
1091
+ const compact = (result) => {
1092
+ const payload = parsePrReviewCollectionReceiptFooter(record, result);
1093
+ if (!payload) {
1094
+ const marker2 = parsePrReviewCollectionReceiptShedMarker(record, result);
1095
+ if (!marker2)
1096
+ return dropResultBody(result);
1097
+ const markerText = `${PR_REVIEW_COLLECTION_RECEIPT_SHED_PREFIX}${JSON.stringify(marker2)}`;
1098
+ const { text: _text2, error: _error2, ...rest2 } = result;
1099
+ return {
1100
+ ...rest2,
1101
+ text: markerText,
1102
+ outputPreviewChars: markerText.length
1103
+ };
1104
+ }
1105
+ const marker = encodePrReviewCollectionReceiptShedMarker(payload);
1106
+ const { text: _text, error: _error, ...rest } = result;
1107
+ return { ...rest, text: marker, outputPreviewChars: marker.length };
1108
+ };
1109
+ return {
1110
+ ...record,
1111
+ ...record.result ? { result: compact(record.result) } : {},
1112
+ ...record.terminalResult ? {
1113
+ terminalResult: {
1114
+ ...record.terminalResult,
1115
+ result: dropResultBody(record.terminalResult.result)
1116
+ }
1117
+ } : {}
1118
+ };
1119
+ }
978
1120
  function emptyAudit() {
979
1121
  return {
980
1122
  dispatchCount: 0,
@@ -1126,12 +1268,21 @@ function compactDelegationsLocked(directory, options) {
1126
1268
  payloadChecksum: "0".repeat(64)
1127
1269
  }), "utf-8");
1128
1270
  let used = baseOverhead;
1271
+ const selectionBudget = MAX_CHECKPOINT_BYTES - CHECKPOINT_SELECTION_RESERVE_BYTES;
1129
1272
  const keptClosed = [];
1130
1273
  let evicted = 0;
1131
1274
  for (const entry of closedCandidates) {
1132
- const cost = Buffer.byteLength(JSON.stringify(entry), "utf-8") + 1;
1133
- if (used + cost > MAX_CHECKPOINT_BYTES) {
1275
+ let retainedEntry = entry;
1276
+ let cost = Buffer.byteLength(JSON.stringify(retainedEntry), "utf-8") + 1;
1277
+ if (used + cost > selectionBudget) {
1134
1278
  if (now - entry.updatedAt < TOMBSTONE_MIN_AGE_MS) {
1279
+ retainedEntry = dropRetainedPrReviewReceipt(entry);
1280
+ cost = Buffer.byteLength(JSON.stringify(retainedEntry), "utf-8") + 1;
1281
+ if (used + cost <= selectionBudget) {
1282
+ used += cost;
1283
+ keptClosed.push(retainedEntry);
1284
+ continue;
1285
+ }
1135
1286
  recordLedgerUncertainty(directory, "checkpoint byte budget would evict a young closed summary; compaction skipped", "compaction");
1136
1287
  return {
1137
1288
  status: "skipped",
@@ -1142,7 +1293,7 @@ function compactDelegationsLocked(directory, options) {
1142
1293
  continue;
1143
1294
  }
1144
1295
  used += cost;
1145
- keptClosed.push(entry);
1296
+ keptClosed.push(retainedEntry);
1146
1297
  }
1147
1298
  const sequence = Math.max(load.manifest?.sequence ?? 0, load.checkpoint?.sequence ?? 0, 0) + 1;
1148
1299
  let healthLateTerminals = 0;
@@ -1155,7 +1306,7 @@ function compactDelegationsLocked(directory, options) {
1155
1306
  const previousClosedIds = new Set((load.checkpoint?.closed ?? []).map((entry) => entry.correlationId));
1156
1307
  const newlySummarized = keptClosed.filter((entry) => !previousClosedIds.has(entry.correlationId)).length;
1157
1308
  const audit = mergeCheckpointAudit(load.checkpoint?.audit ?? null, load.checkpoint, folded, healthLateTerminals, retiredLineCount, newlySummarized + evicted, now);
1158
- const checkpoint = {
1309
+ const checkpointCandidate = {
1159
1310
  schemaVersion: 1,
1160
1311
  sequence,
1161
1312
  writerId: WRITER_ID,
@@ -1166,8 +1317,17 @@ function compactDelegationsLocked(directory, options) {
1166
1317
  records: live,
1167
1318
  closed: keptClosed,
1168
1319
  audit,
1169
- payloadChecksum: ""
1320
+ payloadChecksum: "0".repeat(64)
1170
1321
  };
1322
+ const normalizedCheckpoint = CheckpointSchema.safeParse(checkpointCandidate);
1323
+ if (!normalizedCheckpoint.success) {
1324
+ recordLedgerUncertainty(directory, "generated checkpoint failed schema normalization; compaction skipped", "compaction");
1325
+ return {
1326
+ status: "skipped",
1327
+ reason: "generated checkpoint failed schema normalization"
1328
+ };
1329
+ }
1330
+ const checkpoint = normalizedCheckpoint.data;
1171
1331
  checkpoint.payloadChecksum = checkpointPayloadChecksum(checkpoint);
1172
1332
  const checkpointJson = `${JSON.stringify(checkpoint)}
1173
1333
  `;
@@ -1409,7 +1569,7 @@ function buildPromptSnapshot(text, maxChars) {
1409
1569
  text: bounded,
1410
1570
  chars: text.length,
1411
1571
  truncated,
1412
- digest: createHash("sha256").update(text).digest("hex")
1572
+ digest: createHash2("sha256").update(text).digest("hex")
1413
1573
  };
1414
1574
  }
1415
1575
  async function appendDelegationTransition(directory, correlationId, transition) {
@@ -1455,7 +1615,7 @@ function buildBackgroundCompletionEventId(input) {
1455
1615
  input.status,
1456
1616
  input.resultDigest
1457
1617
  ]);
1458
- return `bgc1:${createHash("sha256").update(canonical).digest("hex")}`;
1618
+ return `bgc1:${createHash2("sha256").update(canonical).digest("hex")}`;
1459
1619
  }
1460
1620
  function sameJson(left, right) {
1461
1621
  return JSON.stringify(left) === JSON.stringify(right);
@@ -1775,7 +1935,7 @@ async function claimDelegationIngestion(directory, correlationId, options) {
1775
1935
  }
1776
1936
  const disposition = current.status === "ingestion_error" || current.ingestion?.state === "claimed" ? "retry" : "claimed";
1777
1937
  const attempt = (current.ingestion?.attempt ?? 0) + 1;
1778
- const claimToken = createHash("sha256").update(JSON.stringify([correlationId, options.claimantId, attempt, now])).digest("hex");
1938
+ const claimToken = createHash2("sha256").update(JSON.stringify([correlationId, options.claimantId, attempt, now])).digest("hex");
1779
1939
  const next = {
1780
1940
  ...current,
1781
1941
  schemaVersion: 3,
@@ -2078,7 +2238,7 @@ async function sweepStaleDelegations(directory, timeoutMs, options = {}) {
2078
2238
  }
2079
2239
  }
2080
2240
  function fallbackRelativePath(correlationId) {
2081
- const digest = createHash("sha256").update(correlationId).digest("hex");
2241
+ const digest = createHash2("sha256").update(correlationId).digest("hex");
2082
2242
  return path2.join(BACKGROUND_DELEGATION_FALLBACK_DIR, `${digest}.json`);
2083
2243
  }
2084
2244
  function fallbackPath(directory, correlationId) {
@@ -2336,7 +2496,7 @@ function reservationStorePath(directory) {
2336
2496
  }
2337
2497
  function buildBackgroundCoderReservationId(input) {
2338
2498
  const ownerIdentity = input.planTaskId === null ? ["call", input.parentSessionId, input.callID] : ["task", input.parentSessionId, input.planTaskId];
2339
- return `bgcr1:${createHash("sha256").update(JSON.stringify(ownerIdentity)).digest("hex")}`;
2499
+ return `bgcr1:${createHash2("sha256").update(JSON.stringify(ownerIdentity)).digest("hex")}`;
2340
2500
  }
2341
2501
  function scanBackgroundCoderReservationsForAdmission(directory) {
2342
2502
  let absolutePath;
@@ -2664,4 +2824,4 @@ async function releaseBackgroundCoderReservation(directory, input) {
2664
2824
  }
2665
2825
  }
2666
2826
 
2667
- export { MAX_RECOVERY_LEDGER_BYTES, collectDelegationLedgerHealth, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation };
2827
+ export { MAX_RECOVERY_LEDGER_BYTES, collectDelegationLedgerHealth, MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation };