opencode-swarm 7.162.0 → 7.163.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/background/pr-review-contract.d.ts +1 -24
  2. package/dist/cli/authorization-vstrh7ra.js +23 -0
  3. package/dist/cli/{coder-settlement-s8cskxk7.js → coder-settlement-g2g5kkv5.js} +10 -10
  4. package/dist/cli/{config-doctor-636h188h.js → config-doctor-p16xr78z.js} +2 -2
  5. package/dist/cli/{core-h3hsczyq.js → core-g088v0zt.js} +1 -1
  6. package/dist/cli/{curation-policy-ayq5kmnf.js → curation-policy-j12j2gvc.js} +6 -6
  7. package/dist/cli/{curator-p0dwpn2x.js → curator-3m8a8qsn.js} +33 -31
  8. package/dist/cli/curator-llm-factory-p00hks4v.js +69 -0
  9. package/dist/cli/{evidence-summary-service-hvbqyb4g.js → evidence-summary-service-4ghqakhx.js} +13 -13
  10. package/dist/cli/{gate-evidence-dhgmnsh0.js → gate-evidence-4v8apasx.js} +6 -6
  11. package/dist/cli/guardrail-explain-smqenqtm.js +70 -0
  12. package/dist/cli/{guardrail-log-qc7rfhv2.js → guardrail-log-mmh4b4k4.js} +7 -7
  13. package/dist/cli/{guardrail-reset-cxkf5h0x.js → guardrail-reset-zge5hg4p.js} +33 -31
  14. package/dist/cli/{hive-promoter-ppbrv8m1.js → hive-promoter-vxez5s7m.js} +33 -31
  15. package/dist/cli/{index-jw7z3gem.js → index-0103w5pf.js} +2 -2
  16. package/dist/cli/{index-fx3em0dr.js → index-2zgjcmmc.js} +139 -45
  17. package/dist/cli/{index-qw893zqp.js → index-3ab9tczn.js} +8 -8
  18. package/dist/cli/{index-q87ht62k.js → index-3b762978.js} +5 -2
  19. package/dist/cli/{index-5wq0dd30.js → index-3rjxbe1p.js} +2 -2
  20. package/dist/cli/{index-z4n60b0a.js → index-453tzvkg.js} +1 -1
  21. package/dist/cli/{index-pde4zn7j.js → index-4t68xs0p.js} +3 -3
  22. package/dist/cli/{index-sjkxrf06.js → index-4xggfhge.js} +4 -4
  23. package/dist/cli/{index-8vwe2qjh.js → index-5hgn302x.js} +9 -9
  24. package/dist/cli/{index-bdmg6yvj.js → index-7n9jznv0.js} +4 -4
  25. package/dist/cli/{index-2rhs7j4r.js → index-7wb2v7jg.js} +2152 -2622
  26. package/dist/cli/{index-kk9yk7an.js → index-8ada7ag7.js} +2 -2
  27. package/dist/cli/{index-nqbqkx4c.js → index-9crtmnqg.js} +1 -1
  28. package/dist/cli/{index-3gwkmq53.js → index-axx3t3k7.js} +2 -2
  29. package/dist/cli/{index-80pmq6q2.js → index-cqgpvx2d.js} +2 -2
  30. package/dist/cli/{index-vcv9m2q5.js → index-eqkdjfqa.js} +4 -4
  31. package/dist/cli/{index-77syzssw.js → index-f7t5fn4z.js} +4 -4
  32. package/dist/cli/{index-9wrmzsnk.js → index-fckfgptr.js} +1 -1
  33. package/dist/cli/{index-0h63swrc.js → index-g4bvsapf.js} +5 -5
  34. package/dist/cli/{index-ydbd41sv.js → index-hm239n1p.js} +1 -1
  35. package/dist/cli/{index-qn4w0gar.js → index-m4nhy4fp.js} +1 -1
  36. package/dist/cli/{index-2ze7yqm8.js → index-m7yt3xmk.js} +1 -1
  37. package/dist/cli/index-mmngnxev.js +883 -0
  38. package/dist/cli/{index-7z9gyts0.js → index-n2mhyect.js} +1 -1
  39. package/dist/cli/{index-db520vnn.js → index-n67vx5zw.js} +2 -2
  40. package/dist/cli/{index-25xvw7hq.js → index-nwa7ctyf.js} +35 -33
  41. package/dist/cli/{index-4wmpv2kn.js → index-ptsmms01.js} +6 -6
  42. package/dist/cli/{index-mfewnd7j.js → index-pykfqsk0.js} +5 -5
  43. package/dist/cli/{index-r7rn6e5f.js → index-qy2rm1f6.js} +6 -6
  44. package/dist/cli/{index-tnj464kq.js → index-rqh25ns3.js} +1 -1
  45. package/dist/cli/{index-tjaawnws.js → index-s8c6f9rr.js} +6 -4
  46. package/dist/cli/{index-vkaqrrsc.js → index-t4hs3qk6.js} +15 -644
  47. package/dist/cli/{index-1wapt173.js → index-w0yn4rmh.js} +3 -3
  48. package/dist/cli/{index-1mbwgw4p.js → index-w1mc7gcm.js} +2 -2
  49. package/dist/cli/index-w7ekntej.js +643 -0
  50. package/dist/cli/{index-acnwj4pc.js → index-xyhmt813.js} +1 -1
  51. package/dist/cli/{index-6w468bjy.js → index-zgz81a8x.js} +1 -1
  52. package/dist/cli/index.js +33 -31
  53. package/dist/cli/{knowledge-escalator-nyeg4ndw.js → knowledge-escalator-91d1n291.js} +12 -12
  54. package/dist/cli/{knowledge-events-z7smbnff.js → knowledge-events-xrd9es3p.js} +10 -10
  55. package/dist/cli/{knowledge-link-0byjmj0w.js → knowledge-link-vmdj5e5d.js} +5 -5
  56. package/dist/cli/{knowledge-store-p14t72y5.js → knowledge-store-2brg88cx.js} +6 -6
  57. package/dist/cli/{knowledge-validator-jg6zhx9s.js → knowledge-validator-s1v7kry2.js} +8 -8
  58. package/dist/cli/{pending-delegations-0111ywd2.js → pending-delegations-b341397j.js} +6 -5
  59. package/dist/cli/{pr-subscriptions-4e64sbwg.js → pr-subscriptions-2mkdt0ak.js} +5 -5
  60. package/dist/cli/{runner-rddddxmq.js → runner-3gw2njnx.js} +6 -6
  61. package/dist/cli/{scan-cursor-wjad4yd7.js → scan-cursor-jm7j3w1c.js} +7 -7
  62. package/dist/cli/{schema-9ebqj7mv.js → schema-6cpgnq4s.js} +1 -1
  63. package/dist/cli/{scope-persistence-j5hz4mnd.js → scope-persistence-q713ck5n.js} +9 -9
  64. package/dist/cli/{skill-generator-x6b05jz6.js → skill-generator-z9bs6vdt.js} +14 -14
  65. package/dist/cli/{telemetry-cmbjv240.js → telemetry-x4zggfd7.js} +1 -1
  66. package/dist/cli/{worktree-collision-ownership-g5n5xbqy.js → worktree-collision-ownership-drtv7jjp.js} +7 -6
  67. package/dist/cli/{worktree-isolation-ha70bwes.js → worktree-isolation-534h3c2f.js} +33 -31
  68. package/dist/council/council-observability.d.ts +42 -0
  69. package/dist/hooks/pr-workflow-gate.d.ts +20 -245
  70. package/dist/index.js +374 -374
  71. package/dist/observability/catalog.d.ts +8 -4
  72. package/dist/observability/ids.d.ts +1 -1
  73. package/dist/observability/legacy.d.ts +6 -4
  74. package/dist/observability/observe.d.ts +1 -1
  75. package/dist/{hooks/pr-review-reentry-authorization.d.ts → pr-review/authorization.d.ts} +32 -10
  76. package/dist/{hooks/pr-review-resilience-circuit.d.ts → pr-review/circuit.d.ts} +60 -3
  77. package/dist/pr-review/completion.d.ts +373 -0
  78. package/dist/pr-review/critic-routing.d.ts +37 -0
  79. package/dist/pr-review/guardrails.d.ts +67 -0
  80. package/dist/pr-review/legacy-transcript-adapter.d.ts +276 -0
  81. package/dist/pr-review/persistence.d.ts +107 -0
  82. package/dist/pr-review/reducer.d.ts +54 -0
  83. package/dist/pr-review/types.d.ts +225 -0
  84. package/dist/telemetry.d.ts +1 -1
  85. package/package.json +1 -1
  86. package/dist/cli/curator-llm-factory-g65xmh8f.js +0 -67
  87. package/dist/cli/guardrail-explain-s0dzn8c6.js +0 -68
  88. package/dist/cli/pr-review-reentry-authorization-b7ceja9y.js +0 -301
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * The event catalog (issue #2029).
3
3
  *
4
- * Exactly 56 entries, matching the `TelemetryEvent` union at
5
- * `src/telemetry.ts:15-131`. Thirty-eight predate the #2029 contract; the 39th is
4
+ * Exactly 59 entries, matching the `TelemetryEvent` union at
5
+ * `src/telemetry.ts:15-165`. Thirty-eight predate the #2029 contract; the 39th is
6
6
  * `agent_conflict_detected` (previously emitted through a force-cast past the
7
7
  * type system), the 40th is `close_archive_result` (issue #2030 — the
8
8
  * structured close/archive result event), the 41st is the bounded diagnostic
@@ -24,7 +24,11 @@
24
24
  * `pr_subscription_health` storage audit for the issue-#2042
25
25
  * `.swarm/pr-monitor/` subscription checkpoint store. The 52nd is
26
26
  * `delegation_cost_correction`, the 53rd is `delegation_cost_binding`, and the
27
- * 54th is `delegation_cost_join`. These late
27
+ * 54th is `delegation_cost_join`. The 57th is `council_attempt`, the 58th is
28
+ * `council_round_transition`, and the 59th is `council_attempt_unscoped`
29
+ * (issue #2046 item 9 — canonical council attempt / accepted-transition
30
+ * observations joined to the lifecycle correlation system via the
31
+ * server-derived `councilRoundId`). These late
28
32
  * additions are instances
29
33
  * of the defect class this contract exists to close: an event kind entering
30
34
  * the stream with no registration.
@@ -80,7 +84,7 @@ export interface CatalogEntry {
80
84
  /**
81
85
  * Whether an event of this kind must carry `trace.parentSpanId`.
82
86
  *
83
- * `false` for all 56 entries today, and that is a truthful statement about
87
+ * `false` for all 59 entries today, and that is a truthful statement about
84
88
  * the current system rather than a placeholder: no producer supplies a
85
89
  * parent span, so `createObservation` never sets one. Setting this to `true`
86
90
  * for a kind whose producer cannot supply a parent would make every
@@ -50,7 +50,7 @@ export declare function newEventId(): string;
50
50
  * Derive a correlated trace/span pair, consuming 24 bytes from the pool above.
51
51
  *
52
52
  * This exists for the hot path: `createObservation` runs on every `emit()`, and
53
- * src/telemetry.ts:315-317 documents that path as deliberately frugal.
53
+ * src/telemetry.ts:393-396 documents that path as deliberately frugal.
54
54
  */
55
55
  export declare function newTraceAndSpanId(): TraceAndSpanId;
56
56
  /**
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Two hard constraints govern every function here:
10
10
  * 1. **Never throw.** `emit()` documents a never-throw guarantee
11
- * (`src/telemetry.ts:266,294`) and `src/telemetry.test.ts:137-162`
11
+ * (`src/telemetry.ts:276,304`) and `src/telemetry.test.ts:137-162`
12
12
  * exercises circular objects, functions, `Symbol`s and `BigInt`s.
13
13
  * 2. **Never deep-traverse, clone, or serialize the payload.** Only
14
14
  * `Object.keys` (shallow) and own-key reads. See `LegacyProjectionSchema`
@@ -54,9 +54,11 @@ export declare function adaptLegacyTelemetryPayload(kind: string, data: unknown,
54
54
  * of the wrong type stays `undefined`. Only the mappings a producer actually
55
55
  * populates are implemented — `sessionId` to `hostSessionId`, `taskId`, `phase`
56
56
  * to `phaseId`, `laneId`, `batchId`, plus the canonical receipt payload keys
57
- * `knowledgeTraceId` and `knowledgeEntryId`. Unmapped IDs stay absent; inventing
58
- * an extraction for them would manufacture exactly the joins issue #2029 item 2
59
- * forbids.
57
+ * `knowledgeTraceId` and `knowledgeEntryId`, and the council round identity
58
+ * `councilRoundId` (producer: `src/council/council-observability.ts`, issue
59
+ * #2046 — the server-derived scope token, never a client-supplied label).
60
+ * Unmapped IDs stay absent; inventing an extraction for them would manufacture
61
+ * exactly the joins issue #2029 item 2 forbids.
60
62
  */
61
63
  export declare function extractWorkflowIds(data: unknown): WorkflowIds;
62
64
  /**
@@ -51,7 +51,7 @@ export declare function initObservability(input: InitObservabilityInput): void;
51
51
  * `BigInt` payload, not on an unknown kind, not on `null` or `undefined` data.
52
52
  * It never calls `JSON.stringify`, never clones, and never deep-traverses
53
53
  * `data` — `src/telemetry.test.ts:137-162` emits exactly those payloads and
54
- * asserts `emit()` does not throw, and `src/telemetry.ts:266` documents the
54
+ * asserts `emit()` does not throw, and `src/telemetry.ts:276` documents the
55
55
  * never-throw guarantee. If anything inside fails, a minimal valid event is
56
56
  * returned carrying `relationshipViolations: ['observation_build_failed']`.
57
57
  *
@@ -1,21 +1,29 @@
1
- import { z } from 'zod';
2
1
  /**
3
- * Correlated one-use reviewer re-entry authorization (issue #2383).
2
+ * PR-review authorization boundary (issues #2383, #2385).
3
+ *
4
+ * Correlated one-use reviewer re-entry authorization, moved behind the
5
+ * `src/pr-review/` boundary (issue #2385). This module replaces prompt-text
6
+ * inspection (`MODE: PR_REVIEW`) as the ONLY way a direct Task dispatch of
7
+ * `reviewer`/`test_engineer` may bypass the generic Stage-A task-workflow
8
+ * requirement. The PR workflow controller issues an authorization bound to
9
+ * the exact active session, workflow, run, base/head SHA, worktree revision
10
+ * digest, role, and gate generation; the Task delegation gate consumes it
11
+ * atomically, exactly once. Stale, cross-session, wrong-role, replayed,
12
+ * expired, or revision-drifted requests fail closed to the normal gating
13
+ * path.
4
14
  *
5
- * Replaces prompt-text inspection (`MODE: PR_REVIEW`) as the ONLY way a
6
- * direct Task dispatch of `reviewer`/`test_engineer` may bypass the generic
7
- * Stage-A task-workflow requirement. The PR workflow controller issues an
8
- * authorization bound to the exact active session, workflow, run, base/head
9
- * SHA, worktree revision digest, role, and gate generation; the Task
10
- * delegation gate consumes it atomically, exactly once. Stale, cross-session,
11
- * wrong-role, replayed, expired, or revision-drifted requests fail closed to
12
- * the normal gating path.
15
+ * Binding verification: the CURRENT gate binding (head/revision/generation)
16
+ * is supplied by the owning gate through a bound reader
17
+ * (`bindPrReviewReentryBindingReader`) the boundary must not import the
18
+ * orchestration gate back. The gate binds its
19
+ * `readPrReviewReentryBindingContext` at module init.
13
20
  *
14
21
  * Persistence: `.swarm/pr-review/reentry-authorizations/<session-stem>.json`,
15
22
  * guarded by a `proper-lockfile` lock (the same dependency the candidate
16
23
  * sidecar store uses). Bounded: at most MAX_ACTIVE_AUTHORIZATIONS unconsumed
17
24
  * authorizations per session; expired/unconsumed records are pruned on write.
18
25
  */
26
+ import { z } from 'zod';
19
27
  export type PrReviewReentryRole = 'reviewer' | 'test_engineer';
20
28
  export interface PrReviewReentryAuthorizationRecord {
21
29
  schemaVersion: 1;
@@ -32,6 +40,20 @@ export interface PrReviewReentryAuthorizationRecord {
32
40
  consumedAt?: string;
33
41
  consumedCallId?: string;
34
42
  }
43
+ /**
44
+ * The CURRENT active-workflow binding an authorization must match at issue
45
+ * AND at consume time. Supplied by the owning gate (which reads state through
46
+ * the persistence boundary) via `bindPrReviewReentryBindingReader`.
47
+ */
48
+ export interface PrReviewReentryBindingContext {
49
+ prHeadSha: string;
50
+ revisionDigest: string;
51
+ generation: number;
52
+ workflowInstanceId?: string;
53
+ runId?: string;
54
+ }
55
+ export type PrReviewReentryBindingReader = (directory: string, sessionID: string) => Promise<PrReviewReentryBindingContext | null>;
56
+ export declare function bindPrReviewReentryBindingReader(reader: PrReviewReentryBindingReader): void;
35
57
  declare const AuthorizationFileSchema: z.ZodObject<{
36
58
  schemaVersion: z.ZodLiteral<1>;
37
59
  sessionId: z.ZodString;
@@ -1,5 +1,6 @@
1
1
  /**
2
- * PR-review resilience circuit — typed, recoverable, versioned (issue #2382).
2
+ * PR-review resilience circuit — typed, recoverable, versioned (issues
3
+ * #2382, #2385).
3
4
  *
4
5
  * Pure state machine + typed-signal classification for the PR_REVIEW
5
6
  * resilience circuit. No I/O: the owning gate (`pr-workflow-gate.ts`) reads
@@ -17,9 +18,17 @@
17
18
  * waterline) or back to OPEN (new interval). Legacy unversioned records
18
19
  * migrate once to a nonblocking v2 CLOSED record with an evidence waterline;
19
20
  * malformed records fail open.
21
+ *
22
+ * Issue #2385 additionally makes this module the ONLY authority that may
23
+ * construct or transition circuit records: policy snapshot resolution, the
24
+ * re-enable reset, and the rolled-back-probe transition live here (previously
25
+ * inline record constructions in the gate). The parallel-rule guardrail
26
+ * (`src/pr-review/guardrails.ts`) enforces that no circuit record is built
27
+ * outside `src/pr-review/`.
20
28
  */
21
29
  import { z } from 'zod';
22
30
  import type { BackgroundDelegationRecord } from '../background/pending-delegations.js';
31
+ import { type PrReviewResilienceConfig } from '../config/schema.js';
23
32
  /** Bounded contributor ledger. Mirrors `MAX_WORKFLOW_BATCHES (128) × 6` base dimensions. */
24
33
  export declare const PR_REVIEW_CIRCUIT_CONTRIBUTOR_LIMIT = 768;
25
34
  export type PrReviewCircuitIgnoredReason = 'observer_deadline' | 'client_unavailable' | 'parser' | 'validation' | 'policy' | 'filesystem' | 'git' | 'cancellation' | 'stale_observation' | 'unknown';
@@ -67,6 +76,20 @@ export interface PrReviewCircuitLegacyRecord {
67
76
  }>;
68
77
  openedAt: string;
69
78
  }
79
+ /**
80
+ * The persisted circuit union: a v2 record or a legacy unversioned record
81
+ * awaiting migration.
82
+ */
83
+ export type PrReviewCircuitRecord = PrReviewCircuitLegacyRecord | PrReviewCircuitRecordV2;
84
+ export interface PrReviewResiliencePolicyRecord {
85
+ enabled: boolean;
86
+ canaryProbeMs: number;
87
+ statusProbeTimeoutMs: number;
88
+ correlatedFailureThreshold: number;
89
+ maxRetryAttemptsAfterInitial: number;
90
+ /** Issue #2382. Optional: policies persisted before the field existed parse unchanged. */
91
+ circuitOpenDurationMs?: number;
92
+ }
70
93
  export declare const PrReviewCircuitLegacyRecordSchema: z.ZodObject<{
71
94
  signature: z.ZodString;
72
95
  count: z.ZodNumber;
@@ -130,6 +153,12 @@ export declare const PrReviewCircuitRecordSchema: z.ZodUnion<readonly [z.ZodObje
130
153
  admittedAt: z.ZodString;
131
154
  }, z.core.$strict>>;
132
155
  }, z.core.$strict>]>;
156
+ /**
157
+ * The terminal delegation statuses the circuit consults. The single shared
158
+ * definition (issue #2385): the gate's settlement paths and this module read
159
+ * the same vocabulary.
160
+ */
161
+ export declare const CIRCUIT_TERMINAL_DELEGATION_STATUSES: ReadonlySet<string>;
133
162
  /**
134
163
  * Derive the typed circuit signal from a durable delegation record's LATEST
135
164
  * terminal state. Returns `null` for anything that is not a terminal failure
@@ -190,7 +219,7 @@ export interface PrReviewCircuitAdvanceInput {
190
219
  admission?: {
191
220
  batchId: string;
192
221
  laneId: string;
193
- };
222
+ } | undefined;
194
223
  /** Latest-record signals for every dispatch lane of the current workflow. */
195
224
  laneSignals: readonly PrReviewCircuitSignal[];
196
225
  /**
@@ -202,7 +231,7 @@ export interface PrReviewCircuitAdvanceInput {
202
231
  terminalStatus: string;
203
232
  signal: PrReviewCircuitSignal | null;
204
233
  terminalAtMs: number;
205
- };
234
+ } | undefined;
206
235
  }
207
236
  export type PrReviewCircuitAdvanceResult = {
208
237
  action: 'admit';
@@ -230,3 +259,31 @@ export type PrReviewCircuitAdvanceResult = {
230
259
  * gate passes an explicit waterlined record for migration / re-enable births).
231
260
  */
232
261
  export declare function advancePrReviewCircuit(current: PrReviewCircuitRecordV2 | null, input: PrReviewCircuitAdvanceInput): PrReviewCircuitAdvanceResult;
262
+ /**
263
+ * Resolve the effective resilience policy record from optional config. Every
264
+ * default comes from `DEFAULT_PR_REVIEW_RESILIENCE_CONFIG` (single source);
265
+ * a hardcoded literal here would drift from the config schema (issue #2385
266
+ * recurrence class G-2).
267
+ */
268
+ export declare function resolvePrReviewResiliencePolicy(policy?: PrReviewResilienceConfig): PrReviewResiliencePolicyRecord;
269
+ /**
270
+ * Issue #2382 re-enable semantics (issue #2385: moved behind the machine).
271
+ * Re-enabling resilience after a live disable starts from a fresh v2 CLOSED
272
+ * generation with an evidence waterline at `nowMs` — pre-disable evidence can
273
+ * never resurrect. Generation strictly increases.
274
+ */
275
+ export declare function resetPrReviewResilienceForReEnable(args: {
276
+ previousCircuit?: PrReviewCircuitRecord | null;
277
+ policy: PrReviewResiliencePolicyRecord;
278
+ nowMs: number;
279
+ }): PrReviewCircuitRecordV2;
280
+ /**
281
+ * Issue #2382 review (PRR-002) rolled-back-probe transition (issue #2385:
282
+ * moved behind the machine). A rolled-back HALF_OPEN probe can never produce
283
+ * a terminal record — the rollback's own precondition is that the batch has
284
+ * zero delegation records — so leaving the probe in place would wedge the
285
+ * circuit on probe_in_flight forever. End the probe lifecycle exactly the way
286
+ * an ignored outcome does: state stays OPEN with a restarted recovery
287
+ * cooldown, and no contributor, generation, or waterline changes.
288
+ */
289
+ export declare function rollbackPrReviewCircuitProbe(circuit: PrReviewCircuitRecordV2, nowMs: number, openDurationMs: number): PrReviewCircuitRecordV2;
@@ -0,0 +1,373 @@
1
+ /**
2
+ * PR-review completion / coverage-settlement authority (issues #2383, #2385).
3
+ *
4
+ * The six-dimension coverage reduction and terminal report eligibility
5
+ * machinery, moved out of `src/hooks/pr-workflow-gate.ts` behind the
6
+ * `src/pr-review/` boundary (issue #2385). This module owns:
7
+ *
8
+ * - the coverage-disclosure record vocabulary (v2 plural + legacy v1 singular),
9
+ * its Zod schemas, and the single legacy→v2 normalization read boundary;
10
+ * - the per-dimension attempt summary (`summarizePrReviewBaseDimensionAttempts`)
11
+ * and the terminal N-of-6 settlement derivation
12
+ * (`derivePrReviewDimensionSettlement`);
13
+ * - the disclosure admission / rollback / settled-assertion state machine
14
+ * (`admitPrReviewPartialBaseCoverage`,
15
+ * `rollbackPrReviewPartialBaseCoverageAdmission`,
16
+ * `assertPrReviewBaseCoverageSettled`);
17
+ * - the verdict eligibility matrix for terminal reports
18
+ * (`allowedPrReviewReportVerdicts`) and the read-only report projection
19
+ * (`readPrReviewTerminalCoverageForReport`).
20
+ *
21
+ * Binding contract (same precedent as `bindPrReviewReentryBindingReader` in
22
+ * `authorization.ts`): the boundary must never import the orchestration gate
23
+ * back. Gate-owned derivation helpers (`successfulObligationsFromExactBatch`,
24
+ * `recordsPassingBatchIntegrity`, `validatePrReviewDiscoveryLaneCompletion`,
25
+ * `validateExactStructuredReceiptCoverage`, `readBoundedSwarmRegularFile`,
26
+ * `createPrReviewGateContext`, `requireBoundState`,
27
+ * `readPrWorkflowGateStateFromDisk`) are supplied by the owning gate through
28
+ * `bindPrReviewCompletionHelpers`, bound once at gate module init.
29
+ *
30
+ * State typing: the moved functions read only the PR-review slice of
31
+ * `PrWorkflowGateState`, expressed as the local structural interface
32
+ * `PrReviewCompletionState`. The gate passes its full state, which satisfies
33
+ * the slice structurally. Durable reads/writes still go through
34
+ * `src/pr-review/persistence.ts` (the atomic persistence boundary) — this
35
+ * module never writes state outside `withSessionStateMutation` /
36
+ * `writeStateWhileLocked`.
37
+ */
38
+ import { z } from 'zod';
39
+ import { type LaneOutputArtifact } from '../background/lane-output-store.js';
40
+ import { type BackgroundDelegationRecord, type BackgroundDelegationResult, type BackgroundDelegationWorkflowLaneFailureClass } from '../background/pending-delegations.js';
41
+ import { type PrReviewBaseDimensionId, type PrReviewResultReceipt } from '../background/pr-review-contract.js';
42
+ /** Declared lane shape of a base dispatch, as the settlement reads it. */
43
+ export interface PrReviewCompletionLane {
44
+ laneId: string;
45
+ workflowLane: string;
46
+ ownedWorkflowLanes?: readonly string[];
47
+ }
48
+ /** Base dispatch batch, as the settlement reads it. */
49
+ export interface PrReviewCompletionBaseDispatchRecord {
50
+ batchId: string;
51
+ lanes: ReadonlyArray<PrReviewCompletionLane>;
52
+ validatedAt: string;
53
+ }
54
+ /**
55
+ * The PR-review slice of the owning gate's `PrWorkflowGateState`: exactly the
56
+ * fields the moved settlement machinery reads. The gate's full state type
57
+ * satisfies this structurally, so the gate passes its state without a
58
+ * projection step. `schemaVersion`/`revision`/`sessionID` mirror
59
+ * `PrWorkflowPersistedStateBase` in `persistence.ts` so the CAS write generic
60
+ * accepts the slice.
61
+ */
62
+ export interface PrReviewCompletionState {
63
+ schemaVersion: number;
64
+ revision: number;
65
+ sessionID: string;
66
+ workflowInstanceId?: string;
67
+ mode?: string;
68
+ prHeadSha?: string;
69
+ prReviewBaseSha?: string;
70
+ prReviewBaseDispatches?: PrReviewCompletionBaseDispatchRecord[];
71
+ prReviewContractRetryDimensions?: PrReviewBaseDimensionId[];
72
+ prReviewReservedRunId?: string;
73
+ prReviewArtifactRunId?: string;
74
+ prReviewArtifactBoundaries?: Array<'post_explorer' | 'post_reviewer' | 'post_critic'>;
75
+ prReviewDimensionCancellations?: Partial<Record<PrReviewBaseDimensionId, PrReviewDimensionCancellationRecord>>;
76
+ prReviewPartialBaseCoverage?: PrReviewPartialBaseCoverageRecord;
77
+ prReviewCoverageDisclosurePath?: string;
78
+ prReviewCoverageDisclosureDigest?: string;
79
+ }
80
+ /** The gate-context surface the settlement consumes (full ctx is gate-owned). */
81
+ export interface PrReviewCompletionGateContext {
82
+ readonly revisionDigest: string;
83
+ }
84
+ /** A batch-integrity-qualified record, as the settlement consumes it. */
85
+ export interface PrReviewCompletionQualifiedRecord {
86
+ record: BackgroundDelegationRecord;
87
+ expectedLane: PrReviewCompletionLane;
88
+ expectedWorkflowLane: string;
89
+ expectedOwnedLanes: string[];
90
+ }
91
+ /** Discovery-lane validation input, as the settlement supplies it. */
92
+ export interface PrReviewCompletionDiscoveryValidationInput {
93
+ record: BackgroundDelegationRecord;
94
+ result: BackgroundDelegationResult;
95
+ artifact: LaneOutputArtifact | null;
96
+ expected: {
97
+ mode: string;
98
+ workflowLane: string;
99
+ ownedWorkflowLanes?: readonly string[];
100
+ prHeadSha: string;
101
+ gitHead: string;
102
+ revisionDigest: string;
103
+ workflowInstanceId?: string;
104
+ workflowRevision?: number;
105
+ baseSha?: string;
106
+ reviewScope?: string;
107
+ checkWorkflowLane?: boolean;
108
+ };
109
+ }
110
+ /** Structured-receipt coverage verdict, as the settlement consumes it. */
111
+ export type PrReviewCompletionStructuredReceiptCoverage = {
112
+ status: 'absent';
113
+ } | {
114
+ status: 'accepted';
115
+ receipt: PrReviewResultReceipt;
116
+ } | {
117
+ status: 'rejected';
118
+ };
119
+ /**
120
+ * Gate-owned derivation helpers, bound by the owning gate at module init so
121
+ * this boundary never imports the gate back. Declared with method syntax on
122
+ * purpose: the gate's implementations accept/return its FULL state and result
123
+ * types, which are structural supersets of the slices below, and interface
124
+ * method parameters are checked bivariantly.
125
+ */
126
+ export interface PrReviewCompletionGateHelpers {
127
+ createPrReviewGateContext(directory: string, state: PrReviewCompletionState): Promise<PrReviewCompletionGateContext>;
128
+ requireBoundState(directory: string, sessionID: string, expectedMode: string): Promise<PrReviewCompletionState>;
129
+ readPrWorkflowGateStateFromDisk(directory: string, sessionID: string): Promise<PrReviewCompletionState | null>;
130
+ readBoundedSwarmRegularFile(directory: string, relativePath: string, maxBytes: number, label: string): Promise<string>;
131
+ successfulObligationsFromExactBatch(directory: string, state: PrReviewCompletionState, batchId: string, expectedLanes: ReadonlyArray<PrReviewCompletionLane>, expectedMode: string, validatedAt: string, checkWorkflowLane?: boolean, forbiddenSubagentSessionIds?: ReadonlySet<string>, expectedRevisionDigest?: string, diagnostics?: string[]): Set<string>;
132
+ recordsPassingBatchIntegrity(directory: string, state: PrReviewCompletionState, batchId: string, expectedLanes: ReadonlyArray<PrReviewCompletionLane>, expectedMode: string, validatedAt: string, checkWorkflowLane?: boolean, forbiddenSubagentSessionIds?: ReadonlySet<string>, diagnostics?: string[]): PrReviewCompletionQualifiedRecord[];
133
+ validatePrReviewDiscoveryLaneCompletion(input: PrReviewCompletionDiscoveryValidationInput): {
134
+ ok: boolean;
135
+ };
136
+ validateExactStructuredReceiptCoverage(input: PrReviewCompletionDiscoveryValidationInput): PrReviewCompletionStructuredReceiptCoverage;
137
+ }
138
+ export declare function bindPrReviewCompletionHelpers(helpers: PrReviewCompletionGateHelpers): void;
139
+ /**
140
+ * Normalized terminal state of one canonical base dimension (issue #2383).
141
+ * Every dimension ends in exactly one of these; completion requires every
142
+ * LAUNCHED lane to be terminal (COVERED/FAILED) or explicitly cancelled, with
143
+ * no in-flight lane and no late result creditable to the active generation.
144
+ */
145
+ export type PrReviewDimensionTerminalState = 'COVERED' | 'FAILED' | 'CANCELLED' | 'NOT_LAUNCHED';
146
+ /** Gate-derived per-dimension terminal evidence for an unresolved dimension. */
147
+ export interface PrReviewUnresolvedDimensionRecord {
148
+ dimension: PrReviewBaseDimensionId;
149
+ terminalState: 'FAILED' | 'CANCELLED' | 'NOT_LAUNCHED';
150
+ reasonKind: 'lane_failure' | 'cancelled' | 'not_launched';
151
+ failureClass?: BackgroundDelegationWorkflowLaneFailureClass;
152
+ terminalEventId?: string;
153
+ /** Contributing lane/batch identity, when available. */
154
+ batchId?: string;
155
+ laneId?: string;
156
+ /**
157
+ * Bounded safe detail derived from the failure-class vocabulary — never
158
+ * lane output, prompts, or secrets.
159
+ */
160
+ safeDetail?: string;
161
+ }
162
+ /** v2 terminal-settlement disclosure (issue #2383). The ONLY shape new writers emit. */
163
+ export interface PrReviewPartialBaseCoverageRecordV2 {
164
+ schemaVersion: 2;
165
+ runId: string;
166
+ prHeadSha: string;
167
+ revisionDigest: string;
168
+ unresolvedDimensions: PrReviewUnresolvedDimensionRecord[];
169
+ admittedAt: string;
170
+ }
171
+ /**
172
+ * Legacy v1 disclosure (pre-#2383): singular `missingDimension` with a typed
173
+ * terminal failure. Read-only — normalized to the v2 in-memory view at the
174
+ * single read boundary; never rewritten on disk.
175
+ */
176
+ export interface PrReviewPartialBaseCoverageRecordV1 {
177
+ runId: string;
178
+ prHeadSha: string;
179
+ revisionDigest: string;
180
+ missingDimension: PrReviewBaseDimensionId;
181
+ failureClass: BackgroundDelegationWorkflowLaneFailureClass;
182
+ terminalEventId: string;
183
+ admittedAt: string;
184
+ }
185
+ export type PrReviewPartialBaseCoverageRecord = PrReviewPartialBaseCoverageRecordV2 | PrReviewPartialBaseCoverageRecordV1;
186
+ /** Terminal report kind of an N-of-6 settlement (issue #2383). */
187
+ export type PrReviewTerminalCoverageKind = 'COMPLETE' | 'PARTIAL' | 'NO_COVERAGE';
188
+ /** Controller-declared terminal verdict for a PR_REVIEW completion (issue #2383). */
189
+ export declare const PR_REVIEW_REPORT_VERDICTS: readonly ["APPROVE", "REQUEST_CHANGES", "INCOMPLETE"];
190
+ export type PrReviewReportVerdict = (typeof PR_REVIEW_REPORT_VERDICTS)[number];
191
+ /**
192
+ * Verdicts a terminal report may carry by coverage kind (issue #2383):
193
+ * PARTIAL may only request changes or declare itself incomplete; NO_COVERAGE
194
+ * is a forced INCOMPLETE operational report. Neither may ever APPROVE or
195
+ * claim a full review.
196
+ */
197
+ export declare function allowedPrReviewReportVerdicts(kind: PrReviewTerminalCoverageKind): readonly PrReviewReportVerdict[];
198
+ export interface PrReviewTerminalCoverageSettlement {
199
+ kind: PrReviewTerminalCoverageKind;
200
+ coveredDimensions: PrReviewBaseDimensionId[];
201
+ unresolvedDimensions: PrReviewUnresolvedDimensionRecord[];
202
+ /** False while any dimension still has a live (in-flight) lane. */
203
+ allLaunchedTerminal: boolean;
204
+ }
205
+ /** Per-dimension explicit cancellation, written by armed recovery (issue #2383). */
206
+ export interface PrReviewDimensionCancellationRecord {
207
+ reason: string;
208
+ cancelledAt: string;
209
+ source: 'armed_recovery';
210
+ }
211
+ export declare const PrReviewPartialBaseCoverageRecordSchema: z.ZodUnion<readonly [z.ZodObject<{
212
+ schemaVersion: z.ZodLiteral<2>;
213
+ runId: z.ZodString;
214
+ prHeadSha: z.ZodString;
215
+ revisionDigest: z.ZodString;
216
+ unresolvedDimensions: z.ZodArray<z.ZodObject<{
217
+ dimension: z.ZodEnum<{
218
+ "intent-architecture": "intent-architecture";
219
+ "correctness-state": "correctness-state";
220
+ "tests-falsifiability": "tests-falsifiability";
221
+ "security-trust": "security-trust";
222
+ "reliability-performance": "reliability-performance";
223
+ "compatibility-delivery": "compatibility-delivery";
224
+ }>;
225
+ terminalState: z.ZodEnum<{
226
+ FAILED: "FAILED";
227
+ CANCELLED: "CANCELLED";
228
+ NOT_LAUNCHED: "NOT_LAUNCHED";
229
+ }>;
230
+ reasonKind: z.ZodEnum<{
231
+ cancelled: "cancelled";
232
+ lane_failure: "lane_failure";
233
+ not_launched: "not_launched";
234
+ }>;
235
+ failureClass: z.ZodOptional<z.ZodEnum<{
236
+ contract: "contract";
237
+ resource: "resource";
238
+ deadline: "deadline";
239
+ }>>;
240
+ terminalEventId: z.ZodOptional<z.ZodString>;
241
+ batchId: z.ZodOptional<z.ZodString>;
242
+ laneId: z.ZodOptional<z.ZodString>;
243
+ safeDetail: z.ZodOptional<z.ZodString>;
244
+ }, z.core.$strict>>;
245
+ admittedAt: z.ZodString;
246
+ }, z.core.$strict>, z.ZodObject<{
247
+ runId: z.ZodString;
248
+ prHeadSha: z.ZodString;
249
+ revisionDigest: z.ZodString;
250
+ missingDimension: z.ZodEnum<{
251
+ "intent-architecture": "intent-architecture";
252
+ "correctness-state": "correctness-state";
253
+ "tests-falsifiability": "tests-falsifiability";
254
+ "security-trust": "security-trust";
255
+ "reliability-performance": "reliability-performance";
256
+ "compatibility-delivery": "compatibility-delivery";
257
+ }>;
258
+ failureClass: z.ZodEnum<{
259
+ contract: "contract";
260
+ resource: "resource";
261
+ deadline: "deadline";
262
+ }>;
263
+ terminalEventId: z.ZodString;
264
+ admittedAt: z.ZodString;
265
+ }, z.core.$strict>]>;
266
+ export declare const PrReviewDimensionCancellationRecordSchema: z.ZodObject<{
267
+ reason: z.ZodString;
268
+ cancelledAt: z.ZodString;
269
+ source: z.ZodLiteral<"armed_recovery">;
270
+ }, z.core.$strict>;
271
+ /**
272
+ * Normalize any disclosure record to the v2 in-memory view. A legacy v1
273
+ * record maps to exactly one FAILED entry; the durable file is never
274
+ * rewritten (its digest stays bound to the original bytes).
275
+ */
276
+ export declare function normalizePrReviewPartialBaseCoverageRecord(record: PrReviewPartialBaseCoverageRecord): PrReviewPartialBaseCoverageRecordV2;
277
+ export interface PrReviewBaseDimensionAttempts {
278
+ /** Dimensions with a currently authoritative successful artifact. */
279
+ successful: Set<string>;
280
+ /** Dimensions with a currently in-flight or retryable recorded lane. */
281
+ inFlight: Set<string>;
282
+ /** Dimensions whose terminal record was a contract failure. */
283
+ contractFailed: Set<string>;
284
+ /** Dimensions that already consumed the dedicated contract retry channel. */
285
+ contractRetried: Set<string>;
286
+ /**
287
+ * The subset of `successful` supplied by a lane that owns that dimension
288
+ * alone. Used by the cumulative tier-L lane floor to decide when an earlier
289
+ * consolidated lane has been superseded and no longer spends lane budget.
290
+ */
291
+ dedicatedSuccessful: Set<string>;
292
+ /** Dimensions whose recorded lane ran to a terminal, non-successful end. */
293
+ terminallyFailed: Set<string>;
294
+ }
295
+ /**
296
+ * Per-dimension success/failure across every recorded base batch.
297
+ *
298
+ * The two halves deliberately use different evidence:
299
+ *
300
+ * - **successful** is revision-aware (`successfulObligationsFromExactBatch`
301
+ * compares each artifact's `revisionDigest` against the current worktree), so
302
+ * a stale artifact is correctly not a current source.
303
+ * - **terminallyFailed** is revision-INdependent on purpose.
304
+ * `recordsPassingBatchIntegrity` plus
305
+ * `hasRevisionIndependentDiscoverySemantics` use the artifact's recorded
306
+ * revision rather than the current worktree digest. If failure were
307
+ * derived from the revision-aware set instead, any working-tree edit would
308
+ * make all six dimensions read as "failed" at once and a caller could then
309
+ * consolidate the whole base wave into two lanes — re-opening the tier-L lane
310
+ * floor by a second route (issue #1968 BL-4).
311
+ */
312
+ export declare function summarizePrReviewBaseDimensionAttempts(directory: string, state: PrReviewCompletionState, revisionDigest: string): PrReviewBaseDimensionAttempts;
313
+ export declare function coverageDisclosureRelativePath(runId: string): string;
314
+ /**
315
+ * Derive the normalized terminal N-of-6 settlement (issue #2383).
316
+ *
317
+ * Pure over durable state: no mutation, no audit. Every dimension maps to
318
+ * exactly one view — COVERED, a terminal unresolved record (FAILED /
319
+ * CANCELLED / NOT_LAUNCHED), or a live (in-flight) dimension that blocks
320
+ * settlement. Coverage success is revision-aware (a stale artifact never
321
+ * counts on the current worktree), and a FAILED dimension carries the typed
322
+ * terminal-failure evidence plus its contributing lane/batch identity.
323
+ */
324
+ export declare function derivePrReviewDimensionSettlement(directory: string, state: PrReviewCompletionState, revisionDigest: string): PrReviewTerminalCoverageSettlement & {
325
+ liveDimensions: PrReviewBaseDimensionId[];
326
+ };
327
+ export declare function admitPrReviewPartialBaseCoverage(directory: string, sessionID: string, runId: string, unresolvedDimensions: readonly PrReviewBaseDimensionId[]): Promise<PrReviewCompletionState>;
328
+ /**
329
+ * Undo a newly admitted partial-base disclosure when the findings checkpoint
330
+ * cannot be completed. The compare-and-clear checks keep a stale writer from
331
+ * deleting a disclosure that another writer has already committed.
332
+ */
333
+ export declare function rollbackPrReviewPartialBaseCoverageAdmission(directory: string, sessionID: string, options: {
334
+ runId: string;
335
+ boundary: 'post_explorer' | 'post_reviewer' | 'post_critic';
336
+ relativePath: string;
337
+ digest: string;
338
+ }): Promise<boolean>;
339
+ /**
340
+ * Validate durable terminal N-of-6 coverage evidence (issue #2383).
341
+ *
342
+ * Returns the settlement: COMPLETE when all six dimensions are covered, or
343
+ * PARTIAL / NO_COVERAGE when an admitted, still-accurate disclosure exactly
344
+ * matches the currently derived terminal settlement. Throws while any
345
+ * unresolved dimension still has a live lane, or when the disclosure has been
346
+ * invalidated by later evidence (e.g. a late success landing on the same
347
+ * revision) — the disclosure is immutable, so such a run must re-settle or
348
+ * restart rather than silently re-crediting.
349
+ */
350
+ export declare function assertPrReviewBaseCoverageSettled(directory: string, sessionID: string, gateContext?: PrReviewCompletionGateContext): Promise<{
351
+ state: PrReviewCompletionState;
352
+ settlement: PrReviewTerminalCoverageSettlement & {
353
+ liveDimensions: PrReviewBaseDimensionId[];
354
+ };
355
+ }>;
356
+ /**
357
+ * Read-only terminal-coverage projection for the completion report surface
358
+ * (issue #2383). Pure derivation over the CURRENT state; returns null when no
359
+ * active PR_REVIEW gate exists. The completion tool reads this BEFORE the
360
+ * terminal clear so the response carries the truthful settlement summary.
361
+ */
362
+ export declare function readPrReviewTerminalCoverageForReport(directory: string, sessionID: string): Promise<{
363
+ kind: PrReviewTerminalCoverageKind;
364
+ coveredDimensions: PrReviewBaseDimensionId[];
365
+ unresolvedDimensions: Array<{
366
+ dimension: PrReviewBaseDimensionId;
367
+ terminal_state: PrReviewUnresolvedDimensionRecord['terminalState'];
368
+ reason_kind: PrReviewUnresolvedDimensionRecord['reasonKind'];
369
+ failure_class?: BackgroundDelegationWorkflowLaneFailureClass;
370
+ }>;
371
+ liveDimensions: PrReviewBaseDimensionId[];
372
+ allowedVerdicts: readonly PrReviewReportVerdict[];
373
+ } | null>;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * PR-review critic routing — the single severity/impact/tag predicate
3
+ * (issues #2383, #2385).
4
+ *
5
+ * Issue #2385 makes `src/pr-review/critic-routing.ts` the canonical home of
6
+ * the shared production critic-routing predicate. `src/background/
7
+ * pr-review-contract.ts` re-exports it (single definition, two import paths —
8
+ * no duplication). Every production consumer (critic inventory derivation,
9
+ * artifact-record validation, coverage admission, reducer transitions)
10
+ * imports THIS predicate; inline severity triples are forbidden and a
11
+ * centralization guard test enforces it.
12
+ */
13
+ import type { PrReviewRiskImpact, PrReviewRiskTag } from '../background/pr-review-contract.js';
14
+ export interface PrReviewCriticRoutingInput {
15
+ classification?: string;
16
+ severity?: string;
17
+ risk_impact?: PrReviewRiskImpact;
18
+ risk_tags?: readonly PrReviewRiskTag[];
19
+ }
20
+ /**
21
+ * THE shared production critic-routing predicate (issue #2383).
22
+ *
23
+ * Exactly one definition, imported by every production consumer (critic
24
+ * inventory derivation, artifact-record validation, coverage admission).
25
+ * Inline severity triples are forbidden — a parity/centralization guard test
26
+ * enforces it. Accepts only the normalized canonical shape:
27
+ *
28
+ * - non-CONFIRMED classifications are never critic-routed;
29
+ * - UNKNOWN/missing/invalid risk metadata routes to critic (fail-safe);
30
+ * - CRITICAL/HIGH always route to critic;
31
+ * - MEDIUM routes iff HIGH_IMPACT or at least one risk tag;
32
+ * - LOW/INFO/NONE follow the existing no-critic policy once metadata is known.
33
+ *
34
+ * Paths, dimensions, keywords, and prompt prose may suggest risk to the model
35
+ * but can never override this typed result.
36
+ */
37
+ export declare function prReviewFindingRequiresCritic(input: PrReviewCriticRoutingInput): boolean;