lastlight-core 0.26.0 → 0.28.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 (127) hide show
  1. package/config/default.yaml +302 -5
  2. package/dist/admin/docker.js.map +1 -1
  3. package/dist/admin/sessions.js.map +1 -1
  4. package/dist/admin/tail.js.map +1 -1
  5. package/dist/config/config.d.ts +18 -4
  6. package/dist/config/config.js +122 -9
  7. package/dist/config/config.js.map +1 -1
  8. package/dist/config/repo-config.js.map +1 -1
  9. package/dist/connectors/messaging/session-manager.js.map +1 -1
  10. package/dist/connectors/slack/connector.js.map +1 -1
  11. package/dist/cron/dependabot-discovery.js.map +1 -1
  12. package/dist/cron/review-discovery.js.map +1 -1
  13. package/dist/engine/agent-executor.d.ts +25 -1
  14. package/dist/engine/agent-executor.js +41 -1
  15. package/dist/engine/agent-executor.js.map +1 -1
  16. package/dist/engine/chat/chat-prompt.js.map +1 -1
  17. package/dist/engine/chat/chat-runner.js.map +1 -1
  18. package/dist/engine/dispatcher.js +17 -0
  19. package/dist/engine/dispatcher.js.map +1 -1
  20. package/dist/engine/event-shim.d.ts +18 -0
  21. package/dist/engine/event-shim.js +2 -0
  22. package/dist/engine/event-shim.js.map +1 -1
  23. package/dist/engine/executors/orchestrator.d.ts +92 -1
  24. package/dist/engine/executors/orchestrator.js +144 -46
  25. package/dist/engine/executors/orchestrator.js.map +1 -1
  26. package/dist/engine/executors/shared.js.map +1 -1
  27. package/dist/engine/fix-harvest.js.map +1 -1
  28. package/dist/engine/github/github.d.ts +59 -0
  29. package/dist/engine/github/github.js +72 -0
  30. package/dist/engine/github/github.js.map +1 -1
  31. package/dist/engine/github/installations.js.map +1 -1
  32. package/dist/engine/github/review-poster.d.ts +403 -9
  33. package/dist/engine/github/review-poster.js +619 -52
  34. package/dist/engine/github/review-poster.js.map +1 -1
  35. package/dist/engine/github/team-visibility.js.map +1 -1
  36. package/dist/engine/llm.js.map +1 -1
  37. package/dist/engine/pr-decisions.d.ts +85 -5
  38. package/dist/engine/pr-decisions.js +331 -5
  39. package/dist/engine/pr-decisions.js.map +1 -1
  40. package/dist/engine/pr-state.d.ts +82 -0
  41. package/dist/engine/pr-state.js +71 -1
  42. package/dist/engine/pr-state.js.map +1 -1
  43. package/dist/engine/review-spec.d.ts +264 -0
  44. package/dist/engine/review-spec.js +723 -0
  45. package/dist/engine/review-spec.js.map +1 -0
  46. package/dist/engine/router.js.map +1 -1
  47. package/dist/engine/screen/classifier.js.map +1 -1
  48. package/dist/engine/screen/screen.js.map +1 -1
  49. package/dist/evals-api.d.ts +3 -0
  50. package/dist/evals-api.js +20 -0
  51. package/dist/evals-api.js.map +1 -1
  52. package/dist/index.js +76 -11
  53. package/dist/index.js.map +1 -1
  54. package/dist/notify/digest-blocks.js.map +1 -1
  55. package/dist/notify/model.js.map +1 -1
  56. package/dist/notify/transports/github.js.map +1 -1
  57. package/dist/notify/transports/slack.js.map +1 -1
  58. package/dist/sandbox/artifact-backend.js.map +1 -1
  59. package/dist/sandbox/artifact-store.js.map +1 -1
  60. package/dist/sandbox/docker.d.ts +23 -4
  61. package/dist/sandbox/docker.js +1 -1
  62. package/dist/sandbox/docker.js.map +1 -1
  63. package/dist/sandbox/egress-allowlist.js.map +1 -1
  64. package/dist/sandbox/k8s/agent-context-registry.js.map +1 -1
  65. package/dist/sandbox/k8s/client.js.map +1 -1
  66. package/dist/sandbox/k8s/kubernetes-sandbox.js.map +1 -1
  67. package/dist/sandbox/k8s/resource-name.js.map +1 -1
  68. package/dist/sandbox/k8s/run-id.js.map +1 -1
  69. package/dist/sandbox/k8s/run-secrets.js.map +1 -1
  70. package/dist/sandbox/k8s/skill-bundle.js.map +1 -1
  71. package/dist/sandbox/k8s/workspace-provisioner.js +10 -2
  72. package/dist/sandbox/k8s/workspace-provisioner.js.map +1 -1
  73. package/dist/sandbox/sandbox.d.ts +20 -0
  74. package/dist/sandbox/sandbox.js +27 -6
  75. package/dist/sandbox/sandbox.js.map +1 -1
  76. package/dist/session-log.js.map +1 -1
  77. package/dist/state/approval-store.js.map +1 -1
  78. package/dist/state/build-assets.js.map +1 -1
  79. package/dist/state/cron-run-store.js.map +1 -1
  80. package/dist/state/data-migrate.d.ts +135 -0
  81. package/dist/state/data-migrate.js +309 -0
  82. package/dist/state/data-migrate.js.map +1 -0
  83. package/dist/state/db.d.ts +24 -3
  84. package/dist/state/db.js +41 -11
  85. package/dist/state/db.js.map +1 -1
  86. package/dist/state/execution-store.js.map +1 -1
  87. package/dist/state/feedback-store.js.map +1 -1
  88. package/dist/state/pg-client.d.ts +44 -0
  89. package/dist/state/pg-client.js +81 -0
  90. package/dist/state/pg-client.js.map +1 -0
  91. package/dist/state/schema/pg.d.ts +15 -15
  92. package/dist/state/schema/sqlite.d.ts +15 -15
  93. package/dist/state/state-cli.d.ts +8 -0
  94. package/dist/state/state-cli.js +247 -0
  95. package/dist/state/state-cli.js.map +1 -0
  96. package/dist/state/team-store.js.map +1 -1
  97. package/dist/state/user-store.js.map +1 -1
  98. package/dist/state/workflow-run-store.js.map +1 -1
  99. package/dist/telemetry/index.js.map +1 -1
  100. package/dist/workflows/handlers/fanout.d.ts +157 -0
  101. package/dist/workflows/handlers/fanout.js +663 -0
  102. package/dist/workflows/handlers/fanout.js.map +1 -0
  103. package/dist/workflows/handlers/post-review.d.ts +111 -10
  104. package/dist/workflows/handlers/post-review.js +531 -39
  105. package/dist/workflows/handlers/post-review.js.map +1 -1
  106. package/dist/workflows/runner.js +33 -0
  107. package/dist/workflows/runner.js.map +1 -1
  108. package/dist/workflows/simple.js.map +1 -1
  109. package/docker-compose.yml +50 -0
  110. package/package.json +22 -12
  111. package/sandbox.Dockerfile +54 -0
  112. package/skills/adjudicate-pass/SKILL.md +117 -0
  113. package/skills/code-review/SKILL.md +114 -15
  114. package/skills/pr-review/SKILL.md +113 -24
  115. package/skills/pr-review/references/findings-schema.md +38 -7
  116. package/skills/survey-pass/SKILL.md +148 -0
  117. package/workflows/pr-review.yaml +626 -0
  118. package/workflows/prompts/dependabot-pr-merge.md +22 -2
  119. package/workflows/prompts/review-adjudicate.md +340 -0
  120. package/workflows/prompts/review-falsify.md +167 -0
  121. package/workflows/prompts/review.md +80 -0
  122. package/workflows/prompts/survey-contract.md +121 -0
  123. package/workflows/prompts/survey-enforcement.md +137 -0
  124. package/workflows/prompts/survey-security.md +165 -0
  125. package/workflows/prompts/survey-spec.md +116 -0
  126. package/workflows/prompts/survey-state.md +151 -0
  127. package/workflows/prompts/survey-tests.md +99 -0
@@ -20,13 +20,85 @@ export type ReviewSide = "LEFT" | "RIGHT";
20
20
  /** One finding as written by the `pr-review` skill into findings.json. */
21
21
  export interface ReviewFinding {
22
22
  path: string;
23
- line: number;
23
+ /**
24
+ * ADVISORY since WP6a. The model is asked for it, but {@link resolveAnchor}
25
+ * derives the real value from {@link ReviewFinding.existingCode} and
26
+ * overwrites this when it succeeds. Optional because a finding whose excerpt
27
+ * resolves needs no line at all, and one whose excerpt does not resolve is
28
+ * demoted to the body — where a wrong number is worse than none.
29
+ */
30
+ line?: number;
24
31
  side?: ReviewSide;
25
32
  start_line?: number;
26
33
  severity?: string;
27
34
  title?: string;
28
35
  body?: string;
29
36
  suggestion?: string;
37
+ /**
38
+ * The verbatim excerpt the finding is about — the anchor of record.
39
+ *
40
+ * **Models quote code well and count lines badly.** `alibaba/open-code-review`
41
+ * names the failure "position drift" and lists it second of the three its
42
+ * architecture is built against; our own cost is worse than theirs, because
43
+ * `post-review` DEMOTES an off-diff line rather than correcting it, so a
44
+ * finding whose analysis is perfect and whose arithmetic is off by two pays
45
+ * the full price of a wrong answer. See {@link resolveAnchor}.
46
+ */
47
+ existingCode?: string;
48
+ /** The obligation family this came from — the key for the per-family threshold (WP6b). */
49
+ family?: string;
50
+ /** 0..1. Absent is NOT zero — see {@link tierFindings}. */
51
+ confidence?: number;
52
+ /**
53
+ * The survey hypothesis ids this finding was built from, as written by the
54
+ * `adjudicate` phase (`findings[].hypotheses[]`, the same field the
55
+ * conservation gate reads).
56
+ *
57
+ * **Optional, and an empty array is not the same as a clean one.** A finding
58
+ * with none is either the shipped reviewer's own — which was never
59
+ * hypothesis-derived — or one the adjudicator generated downstream of the
60
+ * surveys. Neither can be judged by its provenance, so both keep the
61
+ * confidence path. See {@link tierFindings}.
62
+ */
63
+ hypotheses?: string[];
64
+ /**
65
+ * An EXPLICIT destination, set by the `adjudicate` phase (and by
66
+ * `lastlight-facts findings --repair`, which records an unaccounted-for
67
+ * hypothesis at `internal`).
68
+ *
69
+ * Honoured in one direction only: `internal` and `body` are obeyed, `inline`
70
+ * is a request that still has to clear anchorability and the budget. A
71
+ * document may not grant itself a scarce inline slot — but it must always be
72
+ * able to say "record this, do not post it", or the conservation floor's
73
+ * repaired findings would be POSTED, which is the opposite of what recording
74
+ * them means.
75
+ */
76
+ tier?: "inline" | "body" | "internal";
77
+ }
78
+ /** A finding that has an anchor. Narrowed by {@link splitFindings}. */
79
+ export type AnchoredFinding = ReviewFinding & {
80
+ line: number;
81
+ };
82
+ /** One axis of the split verdict. `unknown` = not assessed, which is not a pass. */
83
+ export type AxisVerdict = "pass" | "fail" | "unknown";
84
+ /**
85
+ * The per-axis verdict — issue #271's fix 7.
86
+ *
87
+ * > *"A blended verdict lets the passing axis hide the failing one."*
88
+ *
89
+ * A change that is clean by every standards check but does not do what the
90
+ * issue asked is exactly the case a single `event` cannot express, and the
91
+ * production numbers say it is not hypothetical: 71% APPROVE, 58 of 59
92
+ * approvals carrying zero inline findings.
93
+ *
94
+ * `unknown` is a first-class value and deliberately does NOT block: it is the
95
+ * honest answer when a PR states no acceptance criteria, which is most of them.
96
+ * Treating "not assessed" as "failed" would stop the reviewer approving
97
+ * anything, which is a worse reviewer, not a stricter one.
98
+ */
99
+ export interface SplitVerdict {
100
+ spec?: AxisVerdict;
101
+ standards?: AxisVerdict;
30
102
  }
31
103
  /**
32
104
  * The findings document the agent writes. `pr_number` / `base_ref` /
@@ -38,6 +110,14 @@ export interface ReviewFindingsDoc {
38
110
  summary?: string;
39
111
  event?: ReviewEvent;
40
112
  findings?: ReviewFinding[];
113
+ /**
114
+ * Optional per-axis verdict. Absent ⇒ today's behaviour exactly, which is
115
+ * what makes the field safe to add before anything writes it.
116
+ *
117
+ * The `post-review` handler strips this unless `review.analysis.enabled`, so
118
+ * inertness is structural rather than a promise about what a prompt says.
119
+ */
120
+ verdict?: SplitVerdict;
41
121
  }
42
122
  /** An inline review comment in the shape GitHub's create-review API expects. */
43
123
  export interface InlineComment {
@@ -55,14 +135,122 @@ export interface BuiltReview {
55
135
  comments: InlineComment[];
56
136
  inlineCount: number;
57
137
  demotedCount: number;
138
+ /** Below the floor: recorded, never posted. Always 0 without an {@link AttentionBoundary}. */
139
+ internalCount: number;
140
+ /**
141
+ * The tiering this review was built from, present only when an
142
+ * {@link AttentionBoundary} was supplied.
143
+ *
144
+ * Returned rather than recomputed by the caller so that the review that gets
145
+ * POSTED and the disposition record that gets AUDITED are the same object.
146
+ * Two calls to a pure function on identical arguments cannot disagree today —
147
+ * but the audit trail claiming something the post did not do is precisely the
148
+ * failure the `internal` tier's auditability exists to rule out, and one edit
149
+ * to either branch is all it would take.
150
+ */
151
+ tiered?: TieredFindings;
152
+ }
153
+ /** One line of one hunk, with the line number it carries on each side. */
154
+ export interface DiffLine {
155
+ /** `+` added · `-` removed · ` ` context. */
156
+ prefix: "+" | "-" | " ";
157
+ /** The line's text, with the diff prefix character stripped. */
158
+ text: string;
159
+ /** Old-file line number, or `null` for an added line. */
160
+ left: number | null;
161
+ /** New-file line number, or `null` for a removed line. */
162
+ right: number | null;
163
+ }
164
+ /** One `@@` hunk. Lines within a hunk are contiguous; across hunks they are not. */
165
+ export interface DiffHunk {
166
+ lines: DiffLine[];
167
+ }
168
+ /** One file's worth of a unified diff, keyed by its NEW path. */
169
+ export interface DiffFile {
170
+ path: string;
171
+ hunks: DiffHunk[];
58
172
  }
59
173
  /**
60
- * Map a unified diff to `path -> Set<"SIDE:line">`. Added/`+` and context lines
174
+ * Parse a unified diff into per-file hunks, **keeping the line text**.
175
+ *
176
+ * `parseDiff` used to be the only parser and threw the text away, which made
177
+ * the WP6a anchor cascade structurally impossible: you cannot match an excerpt
178
+ * against a corpus of line numbers. This is the same single pass, retaining
179
+ * what it already read.
180
+ *
181
+ * A `+++ /dev/null` (a deletion) yields no file — there is no new-side path to
182
+ * anchor against — matching the old parser exactly.
183
+ */
184
+ export declare function parseDiffFiles(diff: string): DiffFile[];
185
+ /**
186
+ * The commentable set: `path -> Set<"SIDE:line">`. Added/`+` and context lines
61
187
  * are `RIGHT:<newLine>`; removed/`-` and context lines are `LEFT:<oldLine>` —
62
188
  * mirroring GitHub's three-dot PR diff anchoring. A finding may be commented
63
189
  * inline only when its `side:line` appears in this set.
64
190
  */
191
+ export declare function commentableOf(files: DiffFile[]): Map<string, Set<string>>;
192
+ /** Map a unified diff straight to its commentable set. */
65
193
  export declare function parseDiff(diff: string): Map<string, Set<string>>;
194
+ /** How an anchor was arrived at. `model` = the cascade declined and the model's own line stands. */
195
+ export type AnchorVia = "model" | "hunk" | "file" | "relocated";
196
+ /** A resolved anchor. `path` may differ from the finding's — that is step 3. */
197
+ export interface AnchorResolution {
198
+ path: string;
199
+ line: number;
200
+ side: ReviewSide;
201
+ start_line?: number;
202
+ via: AnchorVia;
203
+ }
204
+ /**
205
+ * Derive a finding's anchor from its verbatim `existingCode`, instead of
206
+ * trusting the line number the model counted.
207
+ *
208
+ * | # | Step | Model? |
209
+ * |---|---|---|
210
+ * | 1 | Match the excerpt against the file's own hunks — new side, then old side | no |
211
+ * | 2 | Scan the full head-side file content | no |
212
+ * | 3 | Relocate across files: a **unique** hit anywhere in the diff re-files the finding | no |
213
+ * | 4 | Ask a model to regenerate the excerpt and retry step 1 | yes |
214
+ * | 5 | Still unlocated — demote to the body, exactly as today | — |
215
+ *
216
+ * **Step 4 is deliberately NOT built**, and the reason is the same one that
217
+ * makes step 3 mandatory. `post-review` is a deterministic phase-type handler
218
+ * with no model binding, so step 4 is new machinery; and Open Code Review's
219
+ * source records what that machinery does when it fires — handed the *wrong
220
+ * file's* diff and a prompt demanding a code block back, the model answers with
221
+ * whatever token in that diff looks closest, overwriting the one piece of
222
+ * evidence that pointed at the real code. The comment then ends up **looking
223
+ * located while pointing at unrelated code**, which is strictly worse than the
224
+ * demotion it was trying to avoid. A declaration/implementation split is the
225
+ * normal shape of a finding from a contract delta, so that is not an exotic
226
+ * case for us. Step 3 covers it without a model; step 5 is the honest floor.
227
+ *
228
+ * Returns `null` when nothing resolved — the caller then leaves the model's own
229
+ * `line` alone and lets {@link splitFindings} demote it if it is off-diff.
230
+ */
231
+ export declare function resolveAnchor(f: ReviewFinding, files: DiffFile[], readHeadFile?: (path: string) => string | null): AnchorResolution | null;
232
+ /** What {@link anchorFindings} did, for the log line and the eval. */
233
+ export interface AnchorStats {
234
+ hunk: number;
235
+ file: number;
236
+ relocated: number;
237
+ /** Had an `existingCode` and still could not be placed. */
238
+ unresolved: number;
239
+ /** Carried no `existingCode` at all — the model's line stands unchecked. */
240
+ noExcerpt: number;
241
+ }
242
+ /**
243
+ * Run the cascade over every finding, returning NEW finding objects with the
244
+ * derived anchor written on. Pure: the only I/O is the injected `readHeadFile`.
245
+ *
246
+ * The anchor must be written back onto the finding before {@link splitFindings}
247
+ * sees it — that function partitions on `f.line`, so a resolution that is not
248
+ * persisted is a resolution that demotes anyway.
249
+ */
250
+ export declare function anchorFindings(findings: ReviewFinding[], files: DiffFile[], readHeadFile?: (path: string) => string | null): {
251
+ findings: ReviewFinding[];
252
+ stats: AnchorStats;
253
+ };
66
254
  /** True when a finding anchors onto a line that appears in the diff. */
67
255
  export declare function isAnchored(f: ReviewFinding, commentable: Map<string, Set<string>> | null): boolean;
68
256
  /**
@@ -72,27 +260,233 @@ export declare function isAnchored(f: ReviewFinding, commentable: Map<string, Se
72
260
  * review still posts and nothing is lost.
73
261
  */
74
262
  export declare function splitFindings(findings: ReviewFinding[], commentable: Map<string, Set<string>> | null): {
75
- inline: ReviewFinding[];
263
+ inline: AnchoredFinding[];
76
264
  demoted: ReviewFinding[];
77
265
  };
78
- /** The "Additional findings" section appended to the body for demoted findings. */
266
+ /**
267
+ * Why a finding is in the review body rather than inline. Three causes, and
268
+ * they must stay distinguishable: "Additional findings" meaning off-diff AND
269
+ * below-threshold AND overflowed-the-cap, under one heading, is a worse review
270
+ * to read than the one it replaced (§D11).
271
+ */
272
+ export type DemotionReason = "off-diff" | "below-threshold" | "overflow" | "adjudicated";
273
+ /** One demoted finding, carrying the reason it did not earn an inline comment. */
274
+ export interface DemotedFinding {
275
+ finding: ReviewFinding;
276
+ reason: DemotionReason;
277
+ }
278
+ /**
279
+ * Why a finding was recorded rather than posted. The same treatment
280
+ * {@link DemotionReason} gives the body tier, and for the same reason: three
281
+ * causes under one label is a record that cannot answer *"what did we know and
282
+ * not say, and why?"* — which is the only thing separating an attention
283
+ * boundary from v2's suppressor.
284
+ *
285
+ * - `adjudicated` — the document said `tier: "internal"` itself. That includes
286
+ * every hypothesis the conservation floor repaired, which carries no
287
+ * confidence at all.
288
+ * - `clean-discharge` — every supporting hypothesis is a clean QUOTE, so the
289
+ * finding is an ANTI-finding. See {@link tierFindings}.
290
+ * - `below-floor` — under {@link AttentionBoundary.internalFloor}.
291
+ * - `body-budget` — demoted to the body and then past
292
+ * {@link AttentionBoundary.maxBodyComments}. The only reason applied to a
293
+ * finding the boundary had already ROUTED somewhere visible, which is why it
294
+ * must stay its own token: folded into any of the other three it would read
295
+ * as a judgement about the finding's content, when it is a judgement about
296
+ * the reader's attention.
297
+ */
298
+ export type InternalReason = "adjudicated" | "clean-discharge" | "below-floor" | "body-budget";
299
+ /** One recorded-not-posted finding, carrying the reason it was withheld. */
300
+ export interface InternalFinding {
301
+ finding: ReviewFinding;
302
+ reason: InternalReason;
303
+ }
304
+ /**
305
+ * The attention budget. Absent ⇒ today's behaviour exactly: no cap, no
306
+ * thresholds, no `internal` tier — every finding is inline or body, decided by
307
+ * anchorability alone.
308
+ */
309
+ export interface AttentionBoundary {
310
+ /** Rank by confidence × severity; everything past this goes to the body, never away. */
311
+ maxInlineComments: number;
312
+ /** Per-obligation-family confidence bar for an INLINE comment. Below it: the body. */
313
+ thresholds: Record<string, number>;
314
+ /** Below this, recorded but not posted. See {@link TieredFindings.internal}. */
315
+ internalFloor: number;
316
+ /**
317
+ * Cap on the FINAL body list — applied last, after every other rule has
318
+ * routed findings there (including the inline overflow), because it governs
319
+ * what the "Additional findings" section may cost a reader, not how any
320
+ * single finding was judged.
321
+ *
322
+ * Unlike `maxInlineComments` this budget DOES filter: the excess is tiered
323
+ * `internal` with reason `body-budget` — recorded in the disposition, never
324
+ * posted. `null` or absent = unlimited, the legacy funnel; `0` = nothing
325
+ * tiers to body at all. Ranked by {@link rankOf} — the same severity ×
326
+ * confidence rank the inline budget spends, so an absent confidence ranks
327
+ * as 1.0 (severity order), never as low confidence. Shipped default is `5`
328
+ * (see `ReviewAnalysisConfig.maxBodyComments` in lastlight-shared for the
329
+ * measurements, and for why the measured-best `0` is not the shipped one);
330
+ * optional here so every existing constructor keeps today's behaviour.
331
+ */
332
+ maxBodyComments?: number | null;
333
+ }
334
+ /** The three destinations. Nothing is dropped; `internal` is recorded, not posted. */
335
+ export interface TieredFindings {
336
+ inline: AnchoredFinding[];
337
+ body: DemotedFinding[];
338
+ /**
339
+ * Below the floor: kept in `findings.json` with its reason, never posted.
340
+ *
341
+ * **This is an attention boundary, not v2's suppressor**, and the difference
342
+ * is that it is auditable — WP7's `review_findings` table is where it becomes
343
+ * queryable; until then the run's own findings document is the record.
344
+ */
345
+ internal: InternalFinding[];
346
+ }
347
+ /**
348
+ * A severity string no {@link SEVERITY_WEIGHT} entry matches — see `rankOf`.
349
+ *
350
+ * A PREDICATE, not a warning, because this module does no I/O: every function
351
+ * here is a pure transform, which is what lets the anchoring and tiering rules
352
+ * be exercised directly rather than through an eval. `post-review.ts` owns the
353
+ * logger and calls this.
354
+ *
355
+ * **Absence is deliberately NOT unknown.** The shipped reviewer writes no
356
+ * severity at all, and ranking that Important is the documented default above,
357
+ * not a drift. What this catches is a spelling from some other vocabulary —
358
+ * severity is written by prompts, in more than one schema, and nothing between
359
+ * them normalises it.
360
+ */
361
+ export declare function unknownSeverity(f: ReviewFinding): boolean;
362
+ /**
363
+ * Split findings across the three destinations.
364
+ *
365
+ * Order matters and each step is a different question: does this SAY anything
366
+ * (the clean-discharge rule) · is it worth a human's attention at all (the
367
+ * floor) · can it even be anchored (GitHub's constraint) · is it confident
368
+ * enough for an inline comment (the family threshold) · is there room (the
369
+ * budget) · and, last, may the body still grow (the body budget,
370
+ * {@link AttentionBoundary.maxBodyComments} — the one step that moves a
371
+ * finding OUT of the posted review, to `internal` with reason `body-budget`).
372
+ *
373
+ * **A missing `confidence` never demotes and never suppresses.** Both bars are
374
+ * `confidence !== undefined && confidence < bar`, so a finding that declines to
375
+ * self-score is treated as passing — the alternative silently deletes every
376
+ * finding from any prompt that has not been taught the field.
377
+ *
378
+ * ## The clean-discharge rule, and why it is not a confidence rule
379
+ *
380
+ * A survey discharges each obligation with QUOTE / ABSENT / PARTIAL / PROBE,
381
+ * and the row shape's own contract is *"on a clean QUOTE write
382
+ * `failureScenario: null`"*. So a row that is a `QUOTE` with an explicit null
383
+ * scenario is the pass saying **"I looked, I quote the line, and it is fine"**.
384
+ * A finding built ENTIRELY out of such rows is an anti-finding: it cannot match
385
+ * a gold defect by construction, and posting it spends a maintainer's attention
386
+ * on a report that nothing is wrong.
387
+ *
388
+ * **Measured on `prreview__skillspro-1587-r2`, three identical repeats**: of the
389
+ * 45 / 48 / 46 hypotheses, **23 / 25 / 23** are clean discharges under the rule
390
+ * this file implements — `QUOTE` with `failureScenario` PRESENT and explicitly
391
+ * `null` — and 17 / 14 / 7 findings trace entirely to them.
392
+ *
393
+ * The looser reading that counts a merely ABSENT key scores 23 / 25 / 30, and
394
+ * the seven-row gap is the whole reason the strict form is the one here. Under
395
+ * the pre-2026-08-23 obligation contract the field did not exist at all, and the
396
+ * `spec` pass's row shape has nowhere to record one, so 37 rows across the
397
+ * preserved minimal-contract runs are `QUOTE` with no key — silence that carries
398
+ * no information. Reading it as "clean" would demote 28 findings across 4 of 16
399
+ * of those instances on the strength of a field nobody asked for. Strictly, the
400
+ * count there is **0 of 16** and this rule is a verified no-op, which is what
401
+ * keeps the control arm single-variable. On the first repeat **all 17 were posted**
402
+ * — "Type contract: consolidateData correctly accepts…", "GOOGLE_CLIENT_ID
403
+ * constant imported and passed correctly". The confidence bars cannot catch
404
+ * them: confidence on those rows is uniformly ≥ 0.7 (median 0.95–1.00, minimum
405
+ * 0.75 across the whole document), so `internalFloor` and every family
406
+ * threshold pass them. That is the point — **an anti-finding is not an
407
+ * unconfident finding, it is a confident report of nothing**, and only its
408
+ * provenance says so.
409
+ *
410
+ * It is checked BEFORE the floor because it is the more specific answer to
411
+ * "why was this withheld?", not because the two disagree about the tier — they
412
+ * cannot; both are `internal`.
413
+ *
414
+ * `clean` is supplied by the caller (`post-review` reads the sibling
415
+ * `hypotheses/*.jsonl`), never read here: this module does no I/O. Absent or
416
+ * empty ⇒ the rule cannot fire, which is the inertness guarantee for every
417
+ * deployment and every arm that runs no evidence pipeline.
418
+ */
419
+ export declare function tierFindings(findings: ReviewFinding[], commentable: Map<string, Set<string>> | null, boundary: AttentionBoundary, clean?: ReadonlySet<string>): TieredFindings;
420
+ /**
421
+ * The flat "Additional findings" section — no reasons, one heading. Still the
422
+ * whole story when there is no attention boundary configured, and the shape the
423
+ * body-only retry uses (there every finding is demoted for the same reason).
424
+ */
79
425
  export declare function renderDemoted(list: ReviewFinding[]): string;
426
+ /**
427
+ * The "Additional findings" section, grouped by why each finding is here.
428
+ *
429
+ * Everything in it is still POSTED and still visible — demotion is not
430
+ * suppression. What it is not is an inline comment at the defect site, and the
431
+ * evidence says that difference is large ("Does AI Code Review Lead to Code
432
+ * Changes?", 22k+ real comments: concise, hunk-level, actionable findings are
433
+ * substantially likelier to cause a change).
434
+ */
435
+ export declare function renderDemotedGrouped(entries: DemotedFinding[]): string;
80
436
  /** Build the inline-comment objects GitHub's create-review API expects. */
81
- export declare function toInlineComments(list: ReviewFinding[]): InlineComment[];
437
+ export declare function toInlineComments(list: AnchoredFinding[]): InlineComment[];
438
+ /**
439
+ * The worse of the two axes, or `undefined` when neither was recorded.
440
+ *
441
+ * Ordering is `fail` > `unknown` > `pass`, and only `fail` is load-bearing —
442
+ * see {@link SplitVerdict} for why `unknown` must not block.
443
+ */
444
+ export declare function worstAxis(verdict: SplitVerdict | undefined): AxisVerdict | undefined;
82
445
  /**
83
446
  * Resolve the review event. An explicit `doc.event` wins; otherwise an empty
84
447
  * findings set is an `APPROVE` and anything else is a `COMMENT` (never an
85
448
  * automatic `REQUEST_CHANGES` — that stays an explicit, deliberate call).
449
+ *
450
+ * ## The split verdict's one effect
451
+ *
452
+ * A `fail` on EITHER axis stops the review being an `APPROVE`; it becomes a
453
+ * `COMMENT`. Nothing else changes: the event is never escalated to
454
+ * `REQUEST_CHANGES`, and among the non-APPROVE events an explicit `doc.event`
455
+ * still wins, so a fork choosing `REQUEST_CHANGES` over `COMMENT` keeps its
456
+ * choice.
457
+ *
458
+ * **Why the downgrade also applies to an EXPLICIT `APPROVE`**, which is the one
459
+ * judgement call in this function. The retired WP6 doc (git history; condensed
460
+ * in `docs/plans/deterministic-pr-levers.md` §"Adjudication and the attention
461
+ * boundary (WP6)") says `resolveEvent` "takes
462
+ * the worse of the two axes" while `event` "remains explicit-wins". Read
463
+ * strictly, those contradict: today's skill makes `event` a REQUIRED field, so
464
+ * an always-present explicit event would make the split verdict inert by
465
+ * construction — the passing axis would go on hiding the failing one, which is
466
+ * the entire defect #271 filed. So "explicit-wins" is read as governing the
467
+ * CHOICE OF EVENT, and the axis verdict as a FLOOR under it, exactly like the
468
+ * skill's existing "never APPROVE over an open human CHANGES_REQUESTED" rule.
469
+ * An agent that writes `event: APPROVE` beside `verdict.spec: "fail"` has
470
+ * contradicted itself, and the safe reading of a self-contradiction is the one
471
+ * that does not silently approve a change that does not do what was asked.
86
472
  */
87
473
  export declare function resolveEvent(doc: ReviewFindingsDoc): ReviewEvent;
88
474
  /**
89
475
  * Compose the full review payload. Pass `commentable = null` to force every
90
476
  * finding into the body (the diff-unavailable fallback).
91
477
  */
92
- export declare function buildReview(doc: ReviewFindingsDoc, commentable: Map<string, Set<string>> | null): BuiltReview;
478
+ export declare function buildReview(doc: ReviewFindingsDoc, commentable: Map<string, Set<string>> | null, boundary?: AttentionBoundary, clean?: ReadonlySet<string>): BuiltReview;
93
479
  /**
94
480
  * The body-only fallback: when the inline POST is rejected (e.g. a stale diff
95
- * yields a 422 on a comment line), re-render with ALL findings in the body so
96
- * the review still lands. Same event as the inline attempt.
481
+ * yields a 422 on a comment line), re-render with every POSTABLE finding in the
482
+ * body so the review still lands. Same event as the inline attempt.
483
+ *
484
+ * **Pass `tiered` whenever the boundary produced one.** Without it this
485
+ * re-reads `doc.findings` wholesale, which republishes the `internal` tier —
486
+ * the conservation floor's repaired hypotheses and the anti-findings alike — so
487
+ * "recorded, never posted" would hold on the happy path and quietly stop
488
+ * holding on the retry. That is a dark drop's mirror image: a publication
489
+ * nobody decided on, reached by a failure in an unrelated request. Omitted ⇒
490
+ * today's behaviour exactly, which is what every no-boundary caller gets.
97
491
  */
98
- export declare function buildBodyOnlyReview(doc: ReviewFindingsDoc): BuiltReview;
492
+ export declare function buildBodyOnlyReview(doc: ReviewFindingsDoc, tiered?: TieredFindings): BuiltReview;