opencode-swarm 7.133.0 → 7.134.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 (87) hide show
  1. package/.opencode/skills/codebase-review-swarm/SKILL.md +18 -2
  2. package/.opencode/skills/codebase-review-swarm/references/review-protocol-v8.2.md +18 -2
  3. package/.opencode/skills/swarm-implement/SKILL.md +17 -2
  4. package/dist/background/completion-observer.d.ts +17 -7
  5. package/dist/background/pending-delegations.d.ts +305 -30
  6. package/dist/background/pr-event-subscribers.d.ts +1 -1
  7. package/dist/cli/{config-doctor-8nbdwnn6.js → config-doctor-4avzz3rh.js} +3 -3
  8. package/dist/cli/{core-egwpry19.js → core-d6yd2jzv.js} +3 -3
  9. package/dist/cli/{curation-policy-gae3xm5d.js → curation-policy-8vkzjtwb.js} +7 -7
  10. package/dist/cli/{curator-e88bm4mg.js → curator-3vsvhwav.js} +31 -28
  11. package/dist/cli/{curator-drift-ea0p8nh1.js → curator-drift-9q6f85bm.js} +7 -7
  12. package/dist/cli/{curator-llm-factory-1a7esr69.js → curator-llm-factory-2qk8q4y9.js} +31 -28
  13. package/dist/cli/{dispatch-3mhgqj2x.js → dispatch-gxbeb2ps.js} +2 -2
  14. package/dist/cli/{evidence-summary-service-nhsmsap8.js → evidence-summary-service-mrzsjpg4.js} +13 -12
  15. package/dist/cli/{gate-evidence-cy2te3x8.js → gate-evidence-b5v1xvxp.js} +4 -4
  16. package/dist/cli/guardrail-explain-tw521x47.js +57 -0
  17. package/dist/cli/{guardrail-log-fjgyx76r.js → guardrail-log-e3jrwdw8.js} +5 -5
  18. package/dist/cli/{hive-promoter-2b04e0wh.js → hive-promoter-sdy5qjzn.js} +31 -28
  19. package/dist/cli/{index-66zght9d.js → index-0541h76w.js} +2 -2
  20. package/dist/cli/{index-g4mnf3p5.js → index-1j3682j8.js} +5 -5
  21. package/dist/cli/{index-mmvaf4t6.js → index-1v5mby7t.js} +25 -3
  22. package/dist/cli/{index-j5pnah1w.js → index-2j8f71c3.js} +12 -12
  23. package/dist/cli/{index-17zjp67y.js → index-2t1n9k7b.js} +4 -4
  24. package/dist/cli/{index-mwqfyjja.js → index-358f9h8p.js} +48406 -48697
  25. package/dist/cli/{index-hfpw5m0e.js → index-463k8mfr.js} +3 -3
  26. package/dist/cli/{index-2tn5h2zp.js → index-4p02dp92.js} +6 -6
  27. package/dist/cli/{index-7ftthvqt.js → index-6b69mp0r.js} +8 -8
  28. package/dist/cli/{index-bz08438z.js → index-8t9xpn1a.js} +7 -7
  29. package/dist/cli/{index-sp7tm8t7.js → index-9z1q181f.js} +1 -1
  30. package/dist/cli/index-b4z7s917.js +80 -0
  31. package/dist/cli/index-b8zgtz81.js +123 -0
  32. package/dist/cli/{index-tj2mkfb3.js → index-bq2848a3.js} +1 -1
  33. package/dist/cli/{index-kc1m6vpr.js → index-c0e3vhv9.js} +2 -2
  34. package/dist/cli/{index-q27bajqb.js → index-cfkvc5q9.js} +3 -3
  35. package/dist/cli/{index-7mkpsw6g.js → index-dd7ttx8x.js} +1 -1
  36. package/dist/cli/{index-r260ybay.js → index-k742ecbm.js} +178 -222
  37. package/dist/cli/{index-cpest8sa.js → index-kwm7hz18.js} +5 -5
  38. package/dist/cli/{index-0vd91yb8.js → index-m8ajf6wb.js} +3 -3
  39. package/dist/cli/{index-mhcge2ry.js → index-mz6sqtm9.js} +33 -30
  40. package/dist/cli/{index-74tptrss.js → index-p8hezdtz.js} +1 -1
  41. package/dist/cli/{index-sw82jvf2.js → index-pz49rx4y.js} +2 -2
  42. package/dist/cli/{index-3x761jqv.js → index-wk1h5ec2.js} +1 -1
  43. package/dist/cli/{index-wzb4dv5s.js → index-y2esw64s.js} +4 -4
  44. package/dist/cli/index-y3v1404y.js +1625 -0
  45. package/dist/cli/{index-wz36r0fk.js → index-zjw32rv9.js} +2 -2
  46. package/dist/cli/index.js +31 -28
  47. package/dist/cli/{knowledge-escalator-hzkw1ban.js → knowledge-escalator-v09w0jmg.js} +8 -8
  48. package/dist/cli/{knowledge-events-pbycdhqd.js → knowledge-events-qp19r2he.js} +6 -6
  49. package/dist/cli/{knowledge-link-4yd2z8ev.js → knowledge-link-nc4y2zkq.js} +5 -5
  50. package/dist/cli/{knowledge-store-45jawb2p.js → knowledge-store-n5pvv0s3.js} +6 -6
  51. package/dist/cli/{knowledge-validator-ge576f8n.js → knowledge-validator-qg31ycbb.js} +9 -9
  52. package/dist/cli/pending-delegations-v9e40hfk.js +96 -0
  53. package/dist/cli/{pr-subscriptions-zqbmctwz.js → pr-subscriptions-ztq40hrt.js} +7 -7
  54. package/dist/cli/{scan-cursor-kvw872be.js → scan-cursor-wtzfvkh2.js} +7 -7
  55. package/dist/cli/{schema-a2zm2m3r.js → schema-erk5bz43.js} +2 -2
  56. package/dist/cli/{scope-persistence-5qypzxxm.js → scope-persistence-hz3zmmsv.js} +5 -5
  57. package/dist/cli/{skill-generator-ch79hvxh.js → skill-generator-nxs65tq3.js} +10 -10
  58. package/dist/cli/worktree-collision-ownership-c4bdnjtx.js +221 -0
  59. package/dist/evaluation/contracts.d.ts +1 -1
  60. package/dist/evaluation/public-api.d.ts +1 -1
  61. package/dist/hooks/delegation-gate/worktree-collision-ownership.d.ts +28 -0
  62. package/dist/hooks/delegation-gate/worktree-isolation.d.ts +63 -1
  63. package/dist/hooks/delegation-gate/worktree-merge-status.d.ts +14 -0
  64. package/dist/hooks/delegation-gate/worktree-ownership-tag.d.ts +19 -0
  65. package/dist/hooks/delegation-gate/worktree-provisioning-owner.d.ts +30 -0
  66. package/dist/hooks/delegation-gate.d.ts +14 -5
  67. package/dist/hooks/guardrails/messages-transform.d.ts +10 -0
  68. package/dist/hooks/guardrails/stored-input-args.d.ts +6 -0
  69. package/dist/hooks/index.d.ts +1 -1
  70. package/dist/hooks/init-orphan-recovery.d.ts +17 -0
  71. package/dist/index.js +486 -479
  72. package/dist/memory/schema.d.ts +4 -4
  73. package/dist/prm/escalation.d.ts +1 -11
  74. package/dist/prm/index.d.ts +1 -0
  75. package/dist/prm/types.d.ts +0 -2
  76. package/dist/session/snapshot-writer.d.ts +3 -0
  77. package/dist/state.d.ts +54 -1
  78. package/dist/tools/dispatch-lanes.d.ts +1 -1
  79. package/dist/tools/epic-record-divergence.d.ts +5 -5
  80. package/dist/utils/advisory-queue.d.ts +60 -0
  81. package/dist/worktree/merge.d.ts +47 -1
  82. package/package.json +1 -1
  83. package/dist/cli/guardrail-explain-zgja2b9m.js +0 -54
  84. package/dist/cli/pending-delegations-kxy8mdqg.js +0 -75
  85. package/dist/cli/{index-9f71ye47.js → index-13xxjfhn.js} +3 -3
  86. package/dist/cli/{index-s80bsjkj.js → index-2ghkk9ve.js} +6 -6
  87. package/dist/cli/{index-76kvm9z5.js → index-5nybajn9.js} +3 -3
@@ -71,8 +71,16 @@ When the review target is a PR branch or commit range, complete this before any
71
71
  explorer or candidate-generation dispatch:
72
72
 
73
73
  1. Verify the working tree is clean with `git status --porcelain`. If
74
- uncommitted changes exist, stash them or abort the checkout to prevent data
75
- loss.
74
+ uncommitted changes exist, **you (the orchestrator)** must handle them
75
+ before any explorer/candidate dispatch — use `prepare_pr_workflow_checkout`
76
+ (the controller-owned path; it preserves every dirty path — including
77
+ untracked files when called with no `paths` argument — and returns a recovery
78
+ command), or a git worktree (see `running-tests` skill precedent). Note:
79
+ `git branch tmp/save-<topic>` only moves the HEAD ref — it does not record or
80
+ preserve uncommitted working-tree changes, so do not rely on it to save dirty
81
+ work. **Never delegate `git stash`, `git reset`, `git checkout -- .`,
82
+ or `git restore` to subagents** — these are worktree-global operations that
83
+ destroy sibling agents' in-flight work under parallel execution.
76
84
  2. Fetch and check out the PR head branch locally. Explorer agents read the
77
85
  working-tree filesystem (`Read`/`Glob`/`Grep`), not git history, so reviewing
78
86
  a PR while the base branch is checked out produces invalid candidates.
@@ -80,6 +88,14 @@ explorer or candidate-generation dispatch:
80
88
  packet and pass that range in every explorer/candidate-generation delegation
81
89
  so agents have revision context for targeted `git show` inspection.
82
90
 
91
+ **Subagent prohibition — must reach every subagent prompt:**
92
+ Include this line verbatim in every explorer/candidate-generation lane
93
+ or subagent dispatch prompt:
94
+ "You are a subagent sharing a worktree with sibling agents. You MUST
95
+ NOT run `git stash`, `git reset`, `git checkout -- .`, `git restore`,
96
+ or any other worktree-global destructive git command. These destroy
97
+ sibling agents' in-flight work without error."
98
+
83
99
  ## Async advisory lanes
84
100
 
85
101
  When selected-track inventory or candidate generation decomposes into independent read-only units, launch those units with `dispatch_lanes_async` when available. Record each returned `batch_id`, then continue architect-owned deterministic work that does not depend on lane output: update the coverage ledger shell, run safe local tools, prepare validation shards, and document unresolved coverage units. Do not mark coverage `REVIEWED`, promote candidates to findings, or write the final report from running lanes.
@@ -196,8 +196,16 @@ If the review target is a PR branch or commit range, complete this before Phase
196
196
  candidate-generation dispatch:
197
197
 
198
198
  1. Verify the working tree is clean with `git status --porcelain`. If
199
- uncommitted changes exist, stash them or abort the checkout to prevent data
200
- loss.
199
+ uncommitted changes exist, **you (the orchestrator)** must handle them
200
+ before any explorer/candidate dispatch — use `prepare_pr_workflow_checkout`
201
+ (the controller-owned path; it preserves every dirty path — including
202
+ untracked files when called with no `paths` argument — and returns a recovery
203
+ command), or a git worktree (see `running-tests` skill precedent). Note:
204
+ `git branch tmp/save-<topic>` only moves the HEAD ref — it does not record or
205
+ preserve uncommitted working-tree changes, so do not rely on it to save dirty
206
+ work. **Never delegate `git stash`, `git reset`, `git checkout -- .`,
207
+ or `git restore` to subagents** — these are worktree-global operations that
208
+ destroy sibling agents' in-flight work under parallel execution.
201
209
  2. Fetch and check out the PR head branch locally. Explorer agents read the
202
210
  working-tree filesystem (`Read`/`Glob`/`Grep`), not git history; without the
203
211
  checkout, they inspect the base branch and produce invalid candidates.
@@ -205,6 +213,14 @@ candidate-generation dispatch:
205
213
  commit range in every explorer/candidate-generation delegation so lanes can
206
214
  use `git show` for revision-specific inspection.
207
215
 
216
+ **Subagent prohibition — must reach every subagent prompt:**
217
+ Include this line verbatim in every explorer/candidate-generation
218
+ subagent dispatch prompt:
219
+ "You are a subagent sharing a worktree with sibling agents. You MUST
220
+ NOT run `git stash`, `git reset`, `git checkout -- .`, `git restore`,
221
+ or any other worktree-global destructive git command. These destroy
222
+ sibling agents' in-flight work without error."
223
+
208
224
  ### 0K — User review mode gate
209
225
 
210
226
  Stop and present the ten review choices unless the user’s original request already selected tracks and explicitly authorized continuing. If the user selects a focused review, do not run unrelated tracks; record omitted tracks in coverage notes.
@@ -75,8 +75,16 @@ When implementation or review-scoping work depends on explorer agents reading a
75
75
  PR branch or commit range, complete this before Phase 1 explorer dispatch:
76
76
 
77
77
  1. Verify the working tree is clean with `git status --porcelain`. If
78
- uncommitted changes exist, stash them or abort the checkout to prevent data
79
- loss.
78
+ uncommitted changes exist, **you (the orchestrator)** must handle them
79
+ before Phase 1 dispatch — use `prepare_pr_workflow_checkout` (the
80
+ controller-owned path; it preserves every dirty path — including untracked
81
+ files when called with no `paths` argument — and returns a recovery command),
82
+ or a git worktree (see `running-tests` skill precedent). Note: `git branch
83
+ tmp/save-<topic>` only moves the HEAD ref — it does not record or preserve
84
+ uncommitted working-tree changes, so do not rely on it to save dirty work.
85
+ **Never delegate `git stash`, `git reset`, `git checkout -- .`,
86
+ or `git restore` to subagents** — these are worktree-global operations that
87
+ destroy sibling agents' in-flight work under parallel execution.
80
88
  2. Fetch and check out the PR head branch locally. Explorer agents read files
81
89
  from the working tree (`Read`/`Glob`/`Grep`), not from git history, so a stale
82
90
  checkout makes them inspect the base branch.
@@ -90,6 +98,13 @@ Launch parallel subagents for disjoint investigation tasks such as repository
90
98
  mapping, locating existing patterns, finding tests/contracts, side-effect
91
99
  analysis, and dependency or migration checks. Keep the main context focused.
92
100
 
101
+ **Subagent prohibition — must reach every subagent prompt:**
102
+ Include this line verbatim in every subagent dispatch prompt:
103
+ "You are a subagent sharing a worktree with sibling agents. You MUST
104
+ NOT run `git stash`, `git reset`, `git checkout -- .`, `git restore`,
105
+ or any other worktree-global destructive git command. These destroy
106
+ sibling agents' in-flight work without error."
107
+
93
108
  ### Phase 2 - Plan
94
109
 
95
110
  Create a concrete implementation plan before editing for any non-trivial task.
@@ -1,22 +1,32 @@
1
1
  /**
2
- * Background subagent completion observer/ingester.
2
+ * Trusted background-subagent completion observer.
3
3
  *
4
- * Trusted synthetic background completions always settle the durable
5
- * background-delegation ledger. Correctness-critical Stage B completions then
6
- * pass through workspace freshness validation before gate evidence, receipts, or
7
- * task workflow state can advance.
4
+ * Terminal identity, coder settlement, workflow ingestion, and parent
5
+ * notification are separate durable transitions. Replaying the same synthetic
6
+ * event therefore resumes the first incomplete transition without re-running a
7
+ * completed one.
8
8
  */
9
- import type { ReviewerReceiptValidationOptions } from '../hooks/review-receipt-collector.js';
9
+ import { type BackgroundDelegationRecord, recordDelegationIngestionResult } from './pending-delegations.js';
10
10
  interface ObserverConfig {
11
11
  enabled: boolean;
12
12
  }
13
+ export interface PreparedBackgroundAdvisories {
14
+ preparationId: string;
15
+ eventIds: string[];
16
+ messages: string[];
17
+ }
13
18
  export declare function createBackgroundCompletionObserver(opts: {
14
19
  config: ObserverConfig;
15
20
  directory: string;
16
- reviewerReceiptOptions?: ReviewerReceiptValidationOptions;
21
+ onTerminalClaimed?: (record: BackgroundDelegationRecord) => void;
22
+ recordIngestionResult?: typeof recordDelegationIngestionResult;
23
+ reviewerReceiptOptions?: Record<string, unknown>;
17
24
  }): {
18
25
  event: (input: {
19
26
  event: unknown;
20
27
  }) => Promise<void>;
28
+ prepareAdvisories: (parentSessionId: string) => Promise<PreparedBackgroundAdvisories | null>;
29
+ ackObservedAdvisories: (parentSessionId: string, observedTexts: readonly string[]) => Promise<number>;
30
+ releaseAdvisories: (parentSessionId: string, prepared: PreparedBackgroundAdvisories) => Promise<boolean>;
21
31
  };
22
32
  export {};
@@ -23,9 +23,24 @@
23
23
  * `.swarm/` (Invariant 4).
24
24
  */
25
25
  export declare const BACKGROUND_DELEGATIONS_FILE = "background-delegations.jsonl";
26
- export type BackgroundDelegationStatus = 'pending' | 'running' | 'ingestion_error' | 'completed' | 'ingesting' | 'error' | 'cancelled' | 'stale' | 'consumed';
26
+ export declare const BACKGROUND_DELEGATION_FALLBACK_DIR = "background-delegation-fallback";
27
+ export declare const BACKGROUND_CODER_RESERVATIONS_FILE = "background-coder-reservations.json";
28
+ export declare const MAX_LIVE_BACKGROUND_FALLBACKS = 256;
29
+ export declare const MAX_LIVE_BACKGROUND_CODER_RESERVATIONS = 256;
30
+ export declare const MAX_BACKGROUND_OBSERVED_FILES = 5000;
31
+ export declare const MAX_BACKGROUND_ADVISORY_CHARS = 4000;
32
+ export type RecoveryOwnershipScanResult<T> = {
33
+ status: 'ok';
34
+ owners: T[];
35
+ } | {
36
+ status: 'uncertain';
37
+ reason: string;
38
+ };
39
+ /** An abandoned ingestion lease may be reclaimed after this bounded interval. */
40
+ export declare const BACKGROUND_INGESTION_LEASE_MS = 30000;
41
+ export type BackgroundDelegationStatus = 'pending' | 'running' | 'ingesting' | 'ingestion_error' | 'completed' | 'error' | 'cancelled' | 'stale' | 'consumed';
27
42
  export interface BackgroundDelegationRecord {
28
- schemaVersion: 1 | 2;
43
+ schemaVersion: 1 | 2 | 3;
29
44
  /** Subagent session id from the dispatch envelope — the correlation key. */
30
45
  correlationId: string;
31
46
  /** Structured jobId from dispatch metadata when available, else null. */
@@ -66,16 +81,22 @@ export interface BackgroundDelegationRecord {
66
81
  workspace?: BackgroundWorkspaceSnapshot;
67
82
  /** Immutable pre-coder provenance for doc-only gate classification. */
68
83
  taskChangeContext?: BackgroundTaskChangeContext;
84
+ /** Complete isolated-worktree recovery coordinates captured before handoff. */
85
+ worktree?: BackgroundWorktreeDescriptor;
86
+ /** Stable pre-launch background-coder capacity reservation. */
87
+ coderReservationId?: string;
69
88
  prompt?: BackgroundPromptSnapshot;
70
89
  generation?: number;
90
+ /** Immutable trusted terminal event. Established exactly once. */
91
+ terminalResult?: BackgroundTerminalResult;
92
+ /** Durable coder settlement state. Settled outcomes are never recomputed. */
93
+ coderSettlement?: BackgroundCoderSettlement;
94
+ /** Durable parent advisory keyed by terminalResult.eventId. */
95
+ advisoryInbox?: BackgroundAdvisoryInboxEntry;
96
+ /** CAS marker for exactly one active ingestion attempt. */
97
+ ingestion?: BackgroundDelegationIngestion;
71
98
  result?: BackgroundDelegationResult;
72
99
  completedAt?: number;
73
- /** Unique lease token for the process currently applying Stage-B side effects. */
74
- ingestionId?: string;
75
- /** Start time for bounded crash-recovery of an abandoned ingestion lease. */
76
- ingestionStartedAt?: number;
77
- /** Terminal result digest claimed by the ingester. */
78
- ingestionDigest?: string;
79
100
  }
80
101
  export interface BackgroundWorkspaceSnapshot {
81
102
  directory: string;
@@ -89,6 +110,19 @@ export interface BackgroundTaskChangeContext {
89
110
  declaredFiles: string[] | null;
90
111
  baseline: BackgroundWorkspaceSnapshot;
91
112
  }
113
+ export interface BackgroundWorktreeDescriptor {
114
+ callID: string;
115
+ parentSessionId: string;
116
+ taskId: string;
117
+ planTaskId: string | null;
118
+ worktreePath: string;
119
+ branchName: string;
120
+ worktreeId: string;
121
+ worktreeSessionId: string;
122
+ mergeStrategy: 'merge' | 'rebase' | 'cherry-pick';
123
+ laneIndex: number;
124
+ worktreeDir: string | null;
125
+ }
92
126
  export interface BackgroundPromptSnapshot {
93
127
  text: string;
94
128
  chars: number;
@@ -108,6 +142,71 @@ export interface BackgroundDelegationResult {
108
142
  transcriptIncomplete?: boolean;
109
143
  messageCount?: number;
110
144
  }
145
+ export interface BackgroundTerminalResult {
146
+ /** Stable identity derived from trusted correlation + immutable result metadata. */
147
+ eventId: string;
148
+ status: 'completed' | 'error' | 'cancelled';
149
+ recordedAt: number;
150
+ result: BackgroundDelegationResult;
151
+ }
152
+ export type BackgroundCoderSettlementState = 'pending' | 'settling' | 'settled' | 'preserved';
153
+ export interface BackgroundCoderSettlementProvenance {
154
+ correlationId: string;
155
+ parentSessionId: string;
156
+ callID: string;
157
+ planTaskId: string | null;
158
+ baseline: BackgroundWorkspaceSnapshot;
159
+ worktree: BackgroundWorktreeDescriptor | null;
160
+ }
161
+ export interface BackgroundCoderSettlementOutcome {
162
+ kind: 'shared-root' | 'standard-worktree';
163
+ result: 'ready' | 'merged' | 'unchanged' | 'partial' | 'failed';
164
+ reason?: string;
165
+ sourceHeadAfterCommit?: string | null;
166
+ targetHeadBeforeMerge?: string | null;
167
+ targetHeadAfterMerge?: string | null;
168
+ }
169
+ export interface BackgroundCoderSettlement {
170
+ state: BackgroundCoderSettlementState;
171
+ provenance: BackgroundCoderSettlementProvenance;
172
+ operationId?: string;
173
+ sourceHeadAfterCommit?: string | null;
174
+ targetHeadBeforeMerge?: string | null;
175
+ observedFiles: string[] | null;
176
+ outcome?: BackgroundCoderSettlementOutcome;
177
+ updatedAt: number;
178
+ }
179
+ export interface BackgroundAdvisoryPreparation {
180
+ id: string;
181
+ preparedAt: number;
182
+ leaseExpiresAt: number;
183
+ }
184
+ export interface BackgroundAdvisoryInboxEntry {
185
+ eventId: string;
186
+ parentSessionId: string;
187
+ state: 'pending' | 'delivered';
188
+ message: string;
189
+ createdAt: number;
190
+ preparation?: BackgroundAdvisoryPreparation;
191
+ deliveredAt?: number;
192
+ }
193
+ export interface BackgroundDelegationIngestion {
194
+ state: 'claimed' | 'retryable' | 'consumed';
195
+ attempt: number;
196
+ updatedAt: number;
197
+ claimToken: string;
198
+ leaseExpiresAt?: number;
199
+ }
200
+ export interface BackgroundCoderReservation {
201
+ reservationId: string;
202
+ parentSessionId: string;
203
+ planTaskId: string | null;
204
+ callID: string;
205
+ state: 'reserved' | 'bound';
206
+ correlationId: string | null;
207
+ createdAt: number;
208
+ updatedAt: number;
209
+ }
111
210
  /**
112
211
  * Read and fold the store to the latest snapshot per correlationId. Lock-free and
113
212
  * defensive: a missing file yields an empty list, and malformed/partial lines are skipped
@@ -118,6 +217,12 @@ export interface BackgroundDelegationResult {
118
217
  * concurrent background delegations, and the on-disk log is small).
119
218
  */
120
219
  export declare function readDelegations(directory: string): BackgroundDelegationRecord[];
220
+ /**
221
+ * Strict startup-recovery view of the primary ledger. Unlike the ordinary
222
+ * advisory reader, this never treats unreadable, oversized, or malformed owner
223
+ * data as absence: destructive orphan cleanup must fail closed on uncertainty.
224
+ */
225
+ export declare function scanDelegationsForRecovery(directory: string): RecoveryOwnershipScanResult<BackgroundDelegationRecord>;
121
226
  /** Returns the folded record for a correlationId, or null. Lock-free read. */
122
227
  export declare function findByCorrelationId(directory: string, correlationId: string): BackgroundDelegationRecord | null;
123
228
  export interface RecordPendingInput {
@@ -138,6 +243,8 @@ export interface RecordPendingInput {
138
243
  promptHash?: string;
139
244
  workspace?: BackgroundWorkspaceSnapshot;
140
245
  taskChangeContext?: BackgroundTaskChangeContext;
246
+ worktree?: BackgroundWorktreeDescriptor;
247
+ coderReservationId?: string;
141
248
  prompt?: BackgroundPromptSnapshot;
142
249
  generation?: number;
143
250
  }
@@ -157,38 +264,101 @@ export declare function appendDelegationTransition(directory: string, correlatio
157
264
  result?: BackgroundDelegationResult;
158
265
  completedAt?: number;
159
266
  }): Promise<BackgroundDelegationRecord | null>;
160
- /** An abandoned ingestion lease may be reclaimed after this bounded interval. */
161
- export declare const BACKGROUND_INGESTION_LEASE_MS = 30000;
162
- export type BackgroundIngestionClaim = {
163
- outcome: 'claimed';
267
+ export interface BuildBackgroundCompletionEventIdInput {
268
+ correlationId: string;
269
+ jobId: string | null;
270
+ status: BackgroundTerminalResult['status'];
271
+ resultDigest: string;
272
+ }
273
+ /** Build the stable inbox/terminal identity without timestamps or process state. */
274
+ export declare function buildBackgroundCompletionEventId(input: BuildBackgroundCompletionEventIdInput): string;
275
+ export type TerminalClaimDisposition = 'claimed' | 'resume_settlement' | 'retry_ingestion' | 'preserved' | 'consumed' | 'duplicate';
276
+ export interface TerminalClaim {
277
+ disposition: TerminalClaimDisposition;
164
278
  record: BackgroundDelegationRecord;
165
- ingestionId: string;
166
- } | {
167
- outcome: 'busy' | 'settled' | 'rejected' | 'missing';
168
- record: BackgroundDelegationRecord | null;
169
- };
279
+ }
170
280
  /**
171
- * Acquire the single durable right to apply Stage-B side effects.
281
+ * Establish an immutable trusted terminal event exactly once.
172
282
  *
173
- * The completed/ingestion_error -> ingesting transition is a compare-and-set
174
- * performed under the pending-delegation store lock. A stale ingesting lease
175
- * may be reclaimed after a crash; live duplicates observe `busy` and do no
176
- * work. Result digest equality keeps replay bound to the immutable completion.
283
+ * A different event for an already-claimed correlation is rejected. Replays of the
284
+ * same event receive an explicit resume/retry disposition from durable state.
177
285
  */
178
- export declare function claimDelegationIngestion(directory: string, correlationId: string, resultDigest: string, options?: {
286
+ export declare function claimTerminalResult(directory: string, correlationId: string, terminalResult: BackgroundTerminalResult): Promise<TerminalClaim | null>;
287
+ export interface ClaimCoderSettlementInput {
288
+ sourceHeadAfterCommit?: string | null;
289
+ targetHeadBeforeMerge?: string | null;
290
+ }
291
+ export interface CoderSettlementClaim {
292
+ disposition: 'claimed' | 'resume' | 'settled' | 'preserved';
293
+ record: BackgroundDelegationRecord;
294
+ }
295
+ /**
296
+ * Claim coder settlement under the ledger lock. A `settling` operation may resume only
297
+ * with its original operationId; completed or preserved outcomes are returned unchanged.
298
+ */
299
+ export declare function claimCoderSettlement(directory: string, correlationId: string, operationId: string, input?: ClaimCoderSettlementInput): Promise<CoderSettlementClaim | null>;
300
+ export declare function normalizeBackgroundObservedFiles(files: readonly string[]): string[] | null;
301
+ export interface UpdateCoderSettlementInput {
302
+ operationId: string;
303
+ state: 'settling' | 'settled' | 'preserved';
304
+ sourceHeadAfterCommit?: string | null;
305
+ targetHeadBeforeMerge?: string | null;
306
+ observedFiles?: string[] | null;
307
+ outcome?: BackgroundCoderSettlementOutcome;
308
+ }
309
+ /**
310
+ * Persist settlement progress or its terminal outcome. Once settled/preserved, every
311
+ * replay returns the original snapshot and ignores recomputation attempts.
312
+ */
313
+ export declare function updateCoderSettlement(directory: string, correlationId: string, input: UpdateCoderSettlementInput): Promise<BackgroundDelegationRecord | null>;
314
+ export type DelegationIngestionDisposition = 'claimed' | 'retry' | 'busy' | 'not_ready' | 'preserved' | 'consumed';
315
+ export interface DelegationIngestionClaim {
316
+ disposition: DelegationIngestionDisposition;
317
+ record: BackgroundDelegationRecord;
318
+ }
319
+ export interface ClaimDelegationIngestionOptions {
320
+ claimantId: string;
179
321
  now?: number;
180
322
  leaseMs?: number;
181
- }): Promise<BackgroundIngestionClaim>;
323
+ }
182
324
  /**
183
- * Settle only the ingestion lease held by `ingestionId`.
325
+ * Lease-backed CAS claim for ingestion.
184
326
  *
185
- * A consumed record is forward-only and returned idempotently; no late error
186
- * path can regress it to ingestion_error.
327
+ * An interrupted claimant cannot strand the record permanently: after the
328
+ * bounded lease expires, a replay may reclaim and retry the immutable settled
329
+ * input. A still-live claim remains busy and must never be reported as success.
187
330
  */
188
- export declare function settleDelegationIngestion(directory: string, correlationId: string, ingestionId: string, transition: {
189
- status: 'consumed' | 'ingestion_error';
190
- result?: BackgroundDelegationResult;
331
+ export declare function claimDelegationIngestion(directory: string, correlationId: string, options: ClaimDelegationIngestionOptions): Promise<DelegationIngestionClaim | null>;
332
+ /** Commit an ingestion claim to consumed or retryable ingestion_error. */
333
+ export declare function recordDelegationIngestionResult(directory: string, correlationId: string, claimToken: string, success: boolean, options?: {
334
+ now?: number;
191
335
  }): Promise<BackgroundDelegationRecord | null>;
336
+ export interface PutPendingBackgroundAdvisoryInput {
337
+ eventId: string;
338
+ parentSessionId: string;
339
+ message: string;
340
+ createdAt?: number;
341
+ }
342
+ /** Establish one immutable durable advisory for the terminal event. */
343
+ export declare function putPendingBackgroundAdvisory(directory: string, correlationId: string, input: PutPendingBackgroundAdvisoryInput): Promise<BackgroundAdvisoryInboxEntry | null>;
344
+ export interface PreparePendingBackgroundAdvisoriesOptions {
345
+ preparationId: string;
346
+ now?: number;
347
+ leaseMs?: number;
348
+ }
349
+ /**
350
+ * Lease pending entries for one synchronous message transform. Expired leases are
351
+ * reclaimable after restart; delivery is committed only when a later host
352
+ * transform reflects the injected text back as conversation history.
353
+ */
354
+ export declare function preparePendingBackgroundAdvisories(directory: string, parentSessionId: string, options: PreparePendingBackgroundAdvisoriesOptions): Promise<BackgroundAdvisoryInboxEntry[]>;
355
+ /**
356
+ * Commit delivery only after a later host transform reflects the exact advisory
357
+ * text back in conversation history. This is the first boundary at which the
358
+ * plugin can prove that a prior transform result escaped the process.
359
+ */
360
+ export declare function acknowledgeObservedBackgroundAdvisories(directory: string, parentSessionId: string, observedTexts: readonly string[]): Promise<number>;
361
+ export declare function releasePreparedBackgroundAdvisories(directory: string, parentSessionId: string, preparationId: string, eventIds: readonly string[]): Promise<boolean>;
192
362
  export declare function findByBatchId(directory: string, batchId: string, opts?: {
193
363
  parentSessionId?: string;
194
364
  }): BackgroundDelegationRecord[];
@@ -198,3 +368,108 @@ export declare function findOpenAsyncLaneBatches(directory: string): BackgroundD
198
368
  * Best-effort; returns the number swept (0 on lock timeout / error).
199
369
  */
200
370
  export declare function sweepStaleDelegations(directory: string, timeoutMs: number): Promise<number>;
371
+ export interface BackgroundDelegationFallbackArtifact {
372
+ schemaVersion: 1;
373
+ correlationId: string;
374
+ createdAt: number;
375
+ record: BackgroundDelegationRecord;
376
+ }
377
+ /** Read one exact fallback artifact with bounded post-rename visibility retries. */
378
+ export declare function readDelegationFallback(directory: string, correlationId: string): Promise<BackgroundDelegationFallbackArtifact | null>;
379
+ /**
380
+ * Enumerate valid live fallback owners for startup orphan recovery. Malformed files are
381
+ * ignored as data but still count toward the fail-closed capacity bound.
382
+ */
383
+ export declare function listDelegationFallbacks(directory: string): Promise<BackgroundDelegationFallbackArtifact[]>;
384
+ /**
385
+ * Strict startup-recovery view of fallback owners. Every candidate must be
386
+ * readable and schema-valid, and overflow is uncertainty rather than
387
+ * truncation, because omitted ownership could make cleanup destructive.
388
+ */
389
+ export declare function scanDelegationFallbacksForRecovery(directory: string): Promise<RecoveryOwnershipScanResult<BackgroundDelegationFallbackArtifact>>;
390
+ export interface WriteDelegationFallbackOptions {
391
+ /** Testable lower cap; callers cannot raise the production maximum. */
392
+ maxLive?: number;
393
+ }
394
+ /**
395
+ * Atomically persist a launched-but-unledgered delegation in an independent,
396
+ * per-correlation artifact. Capacity failure never removes another live artifact.
397
+ */
398
+ export declare function writeDelegationFallback(directory: string, input: RecordPendingInput, options?: WriteDelegationFallbackOptions): Promise<BackgroundDelegationFallbackArtifact | null>;
399
+ /** Idempotently remove one exact fallback after durable primary promotion. */
400
+ export declare function removeDelegationFallback(directory: string, correlationId: string): Promise<boolean>;
401
+ export interface CompletionDelegationLookup {
402
+ source: 'primary' | 'fallback';
403
+ record: BackgroundDelegationRecord;
404
+ fallback?: BackgroundDelegationFallbackArtifact;
405
+ }
406
+ /** Lookup used by terminal handling: primary ledger first, exact fallback second. */
407
+ export declare function findDelegationForCompletion(directory: string, correlationId: string): Promise<CompletionDelegationLookup | null>;
408
+ /**
409
+ * Promote one exact fallback into the append-only primary ledger, then remove it.
410
+ * A conflicting primary identity fails closed and leaves the fallback untouched.
411
+ */
412
+ export declare function promoteDelegationFallback(directory: string, correlationId: string): Promise<CompletionDelegationLookup | null>;
413
+ export declare function buildBackgroundCoderReservationId(input: {
414
+ parentSessionId: string;
415
+ planTaskId: string | null;
416
+ callID: string;
417
+ }): string;
418
+ export type BackgroundCoderReservationScanResult = {
419
+ status: 'ok';
420
+ reservations: BackgroundCoderReservation[];
421
+ } | {
422
+ status: 'uncertain';
423
+ reason: string;
424
+ };
425
+ /**
426
+ * Strict reservation read for admission. Corruption is uncertainty, never absence.
427
+ */
428
+ export declare function scanBackgroundCoderReservationsForAdmission(directory: string): BackgroundCoderReservationScanResult;
429
+ export interface ReserveBackgroundCoderSlotInput {
430
+ parentSessionId: string;
431
+ planTaskId: string | null;
432
+ callID: string;
433
+ maxConcurrent: number;
434
+ occupiedTaskIds?: readonly string[];
435
+ now?: number;
436
+ }
437
+ export type ReserveBackgroundCoderSlotResult = {
438
+ ok: true;
439
+ reservation: BackgroundCoderReservation;
440
+ activeCount: number;
441
+ } | {
442
+ ok: false;
443
+ reason: 'invalid' | 'duplicate_task' | 'duplicate_call' | 'capacity' | 'uncertain';
444
+ activeCount?: number;
445
+ detail?: string;
446
+ existing?: BackgroundCoderReservation;
447
+ };
448
+ /**
449
+ * Atomically reserve one parent-scoped background coder slot before launch.
450
+ * This has no workflow-state side effect.
451
+ */
452
+ export declare function reserveBackgroundCoderSlot(directory: string, input: ReserveBackgroundCoderSlotInput): Promise<ReserveBackgroundCoderSlotResult>;
453
+ export interface BindBackgroundCoderReservationInput {
454
+ reservationId: string;
455
+ parentSessionId: string;
456
+ planTaskId: string | null;
457
+ callID: string;
458
+ correlationId: string;
459
+ now?: number;
460
+ }
461
+ /** Bind the pre-launch owner to the exact trusted completion correlation. */
462
+ export declare function bindBackgroundCoderReservation(directory: string, input: BindBackgroundCoderReservationInput): Promise<BackgroundCoderReservation | null>;
463
+ export interface ReleaseBackgroundCoderReservationInput {
464
+ reservationId: string;
465
+ parentSessionId: string;
466
+ planTaskId: string | null;
467
+ callID: string;
468
+ correlationId: string | null;
469
+ reason: 'consumed' | 'recovered';
470
+ }
471
+ /**
472
+ * Release only an exact owner. `consumed` is independently proven from the strict
473
+ * primary ledger; `recovered` is reserved for a caller that completed recovery.
474
+ */
475
+ export declare function releaseBackgroundCoderReservation(directory: string, input: ReleaseBackgroundCoderReservationInput): Promise<boolean>;
@@ -97,7 +97,7 @@ declare function scheduleClearUnaddressed(directory: string, correlationId: stri
97
97
  /**
98
98
  * Format a structured advisory message for the given PR event type.
99
99
  * Returns null for unknown event types. The first token is always the
100
- * dedup token `[pr-monitor:<type>:<repo>#<n>]`.
100
+ * dedup token from buildPrEventToken.
101
101
  */
102
102
  declare function formatAdvisory(type: string, payload: PrEventPayload): string | null;
103
103
  export {};
@@ -12,13 +12,13 @@ import {
12
12
  shouldRunOnStartup,
13
13
  writeBackupArtifact,
14
14
  writeDoctorArtifact
15
- } from "./index-tj2mkfb3.js";
16
- import"./index-wzb4dv5s.js";
15
+ } from "./index-bq2848a3.js";
16
+ import"./index-y2esw64s.js";
17
17
  import"./index-bk5tah7q.js";
18
+ import"./index-bpmtbmy9.js";
18
19
  import"./index-z6xqpmqg.js";
19
20
  import"./index-zjygnfay.js";
20
21
  import"./index-zgwm4ryv.js";
21
- import"./index-bpmtbmy9.js";
22
22
  import"./index-a76rekgs.js";
23
23
  export {
24
24
  writeDoctorArtifact,
@@ -14,12 +14,12 @@ import {
14
14
  resolveWorktreeBaseDir,
15
15
  shortenWorktreePath,
16
16
  writeLaneProfileToDiskReal
17
- } from "./index-17zjp67y.js";
18
- import"./index-z6xqpmqg.js";
17
+ } from "./index-2t1n9k7b.js";
19
18
  import"./index-4rhhvd1a.js";
19
+ import"./index-z6xqpmqg.js";
20
20
  import"./index-zjygnfay.js";
21
- import"./index-zgwm4ryv.js";
22
21
  import"./index-qe3v54nb.js";
22
+ import"./index-zgwm4ryv.js";
23
23
  import"./index-a76rekgs.js";
24
24
  export {
25
25
  writeLaneProfileToDiskReal,
@@ -4,18 +4,18 @@ import {
4
4
  authorizeCuration,
5
5
  buildConfigFingerprintInput,
6
6
  readCohortConfigFingerprint
7
- } from "./index-wz36r0fk.js";
7
+ } from "./index-zjw32rv9.js";
8
8
  import"./index-rtry5xyf.js";
9
- import"./index-bz08438z.js";
9
+ import"./index-8t9xpn1a.js";
10
10
  import"./index-ae75rja9.js";
11
- import"./index-q27bajqb.js";
12
- import"./index-zgwm4ryv.js";
13
- import"./index-7mkpsw6g.js";
11
+ import"./index-cfkvc5q9.js";
12
+ import"./index-dd7ttx8x.js";
14
13
  import"./index-fsrp8wp3.js";
15
- import"./index-76kvm9z5.js";
16
- import"./index-q2rrv0cy.js";
14
+ import"./index-5nybajn9.js";
17
15
  import"./index-7g4c7s5r.js";
16
+ import"./index-q2rrv0cy.js";
18
17
  import"./index-qe3v54nb.js";
18
+ import"./index-zgwm4ryv.js";
19
19
  import"./index-a76rekgs.js";
20
20
  export {
21
21
  readCohortConfigFingerprint,