crysk 0.6.1 → 0.8.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 (179) hide show
  1. package/README.md +28 -22
  2. package/dist/SKILL-1q3658n0.md +74 -0
  3. package/dist/SKILL-25j4q9b8.md +143 -0
  4. package/dist/SKILL-32cmme3j.md +143 -0
  5. package/dist/SKILL-4747bhne.md +143 -0
  6. package/dist/SKILL-4jc3sv23.md +74 -0
  7. package/dist/SKILL-c0492rch.md +540 -0
  8. package/dist/SKILL-d1nzkhhr.md +74 -0
  9. package/dist/SKILL-f8p7kvx0.md +143 -0
  10. package/dist/SKILL-gxd45g38.md +553 -0
  11. package/dist/SKILL-rec41991.md +66 -0
  12. package/dist/SKILL-zze8zj5g.md +536 -0
  13. package/dist/adjudicator-eckqh14e.md +78 -0
  14. package/dist/ci-admission-qn797a6c.md +128 -0
  15. package/dist/cli.js +18608 -18523
  16. package/dist/consolidate-4xw1pkg7.md +24 -0
  17. package/dist/deep-review-logic-dgr112y1.md +196 -0
  18. package/dist/deep-review-logic-fck5z4xe.md +197 -0
  19. package/dist/deep-review-logic-h1fpamfh.md +192 -0
  20. package/dist/deep-review-logic-m4vk5683.md +196 -0
  21. package/dist/deep-review-logic-z63kmgmc.md +157 -0
  22. package/dist/deep-review-parity-7x7s5d81.md +148 -0
  23. package/dist/deep-review-parity-9wxmynsc.md +115 -0
  24. package/dist/deep-review-parity-bwwe7cx6.md +152 -0
  25. package/dist/deep-review-parity-e50pw3pk.md +117 -0
  26. package/dist/deep-review-parity-ennmm9m1.md +151 -0
  27. package/{prompts/default/deep-review-parity.md → dist/deep-review-parity-h7y6y2he.md} +14 -16
  28. package/dist/deep-review-parity-xg6wy69c.md +151 -0
  29. package/dist/deep-review-reliability-6h3c4gmw.md +125 -0
  30. package/dist/deep-review-reliability-dcjab69x.md +122 -0
  31. package/dist/deep-review-reliability-ec7b5pbk.md +159 -0
  32. package/dist/deep-review-reliability-hvasvmt9.md +153 -0
  33. package/dist/deep-review-reliability-mjnayxmt.md +158 -0
  34. package/dist/deep-review-reliability-mm7fnayf.md +124 -0
  35. package/dist/deep-review-reliability-xk4xvc2w.md +158 -0
  36. package/dist/deep-review-resilience-0esd5qeh.md +148 -0
  37. package/dist/deep-review-resilience-envgcmpy.md +115 -0
  38. package/dist/deep-review-resilience-fgx8ythf.md +151 -0
  39. package/dist/deep-review-resilience-mq5qa6ad.md +152 -0
  40. package/dist/deep-review-resilience-pwh1gawp.md +151 -0
  41. package/dist/deep-review-resilience-s9n21dkx.md +117 -0
  42. package/dist/deep-review-resilience-vz4qskea.md +119 -0
  43. package/dist/deep-review-security-1vwjdc9q.md +205 -0
  44. package/dist/deep-review-security-x1cc1z00.md +205 -0
  45. package/dist/index.js +590 -485
  46. package/dist/opencode-ci-jc8mf4wn.md +106 -0
  47. package/dist/opencode-ci-qrcv7a99.md +106 -0
  48. package/dist/opencode-ci-rdpcc7xc.md +106 -0
  49. package/dist/opencode-ci-yt0k74t0.md +106 -0
  50. package/dist/review-refuter-7qffwtzz.md +77 -0
  51. package/dist/verifier-tyh8r45v.md +40 -0
  52. package/dist/verifier-xf4xj701.md +40 -0
  53. package/dist/workflow-andv2dvm.yml +158 -0
  54. package/package.json +1 -1
  55. package/prompts/consolidate.md +1 -1
  56. package/prompts/default/PROVENANCE.md +6 -0
  57. package/prompts/default/deep-review-logic.md +56 -15
  58. package/prompts/default/deep-review-reliability.md +64 -30
  59. package/prompts/default/deep-review-resilience.md +71 -37
  60. package/prompts/default/deep-review-security.md +205 -0
  61. package/prompts/default/review-refuter.md +1 -1
  62. package/prompts/verifier.md +40 -0
  63. package/skills/crysk/SKILL.md +6 -6
  64. package/skills/crysk-ci-setup/SKILL.md +32 -33
  65. package/skills/crysk-ci-setup/assets/workflow.yml +5 -10
  66. package/skills/crysk-ci-setup/references/ci-admission.md +5 -5
  67. package/skills/crysk-ci-setup/references/opencode-ci.md +6 -6
  68. package/skills/crysk-loop/SKILL.md +37 -54
  69. package/skills/crysk-loop/adjudicator.md +10 -18
  70. package/skills/crysk-pr/SKILL.md +1 -1
  71. package/src/asset-manifest.ts +6 -6
  72. package/src/assets.ts +4 -4
  73. package/src/brand.ts +20 -30
  74. package/src/ci/gates.ts +155 -192
  75. package/src/ci/outcome.ts +4 -31
  76. package/src/ci/platform-limits.ts +135 -0
  77. package/src/ci/platform-report.ts +212 -126
  78. package/src/ci/platform.ts +28 -26
  79. package/src/ci/reporter.ts +25 -26
  80. package/src/ci/review-admission.ts +1 -2
  81. package/src/ci/review-levels.ts +12 -53
  82. package/src/ci/setup.ts +96 -66
  83. package/src/ci/trace-bundle.ts +11 -27
  84. package/src/ci/trace-transcripts.ts +4 -6
  85. package/src/ci/trigger.ts +3 -5
  86. package/src/cli.ts +6 -5
  87. package/src/commands/ci-setup-questions.ts +2 -55
  88. package/src/commands/ci-setup.ts +2 -26
  89. package/src/commands/triage.ts +131 -38
  90. package/src/commands/usage.ts +0 -1
  91. package/src/compare/compare.ts +3 -3
  92. package/src/compare/floor-test.ts +30 -201
  93. package/src/compare/hunter-exam.ts +631 -0
  94. package/src/config/config.ts +6 -30
  95. package/src/diversity/accounting.ts +0 -26
  96. package/src/diversity/benchmark.ts +1 -17
  97. package/src/diversity/identity.ts +0 -14
  98. package/src/diversity/pipeline-integration.ts +0 -29
  99. package/src/doctor.ts +3 -6
  100. package/src/execution/claude-session-trace.ts +7 -2
  101. package/src/execution/contracts.ts +15 -9
  102. package/src/execution/harness.ts +165 -187
  103. package/src/execution/spend-limiter.ts +39 -131
  104. package/src/execution/usage-facts.ts +397 -0
  105. package/src/execution/usage-normalized.ts +33 -86
  106. package/src/harness/materiality-judge.ts +0 -5
  107. package/src/harness/pipeline-plan.ts +0 -3
  108. package/src/harness/replay-rows.ts +0 -5
  109. package/src/harness/route-runner.ts +2 -2
  110. package/src/harness/single-step.ts +3 -9
  111. package/src/index.ts +1 -1
  112. package/src/mcp/preflight.ts +2 -2
  113. package/src/model/catalog.ts +1 -3
  114. package/src/model/free-discovery.ts +11 -78
  115. package/src/model/model-name.ts +16 -5
  116. package/src/model/profiles/claude.ts +1 -2
  117. package/src/model/profiles/openai.ts +1 -2
  118. package/src/model/profiles.ts +2 -3
  119. package/src/model/provider-capabilities.ts +16 -55
  120. package/src/model/routing.ts +39 -36
  121. package/src/pr/admission.ts +6 -6
  122. package/src/pr/answered-findings.ts +8 -4
  123. package/src/pr/ci-publish.ts +0 -2
  124. package/src/pr/discovery.ts +4 -25
  125. package/src/pr/plan.ts +40 -121
  126. package/src/pr/pr-status.ts +14 -2
  127. package/src/pr/pr.ts +1 -1
  128. package/src/pr/preflight.ts +44 -15
  129. package/src/pr/publish-outcome.ts +1 -19
  130. package/src/pr/review-pr.ts +15 -47
  131. package/src/pr/target.ts +76 -82
  132. package/src/production-runtime.ts +52 -114
  133. package/src/progress.ts +0 -54
  134. package/src/rereview/prepare.ts +4 -1
  135. package/src/rereview/state.ts +1 -1
  136. package/src/rereview/verify.ts +15 -9
  137. package/src/review/boundary.ts +5 -8
  138. package/src/review/drafts.ts +3 -3
  139. package/src/review/findings-conformance.ts +1 -1
  140. package/src/review/findings.ts +0 -4
  141. package/src/review/pipeline.ts +194 -407
  142. package/src/review/preflight.ts +175 -201
  143. package/src/review/prompt-set.ts +1 -2
  144. package/src/review/report.ts +2 -162
  145. package/src/review/review.ts +25 -74
  146. package/src/review/route-preflight.ts +19 -35
  147. package/src/review/run.ts +37 -73
  148. package/src/review/size-gate.ts +3 -3
  149. package/src/review/spec.ts +6 -11
  150. package/src/review/step-runner.ts +4 -4
  151. package/src/runner-authority.ts +10 -9
  152. package/src/security/credential-broker.ts +5 -6
  153. package/src/server/preflight.ts +0 -1
  154. package/src/server/server.ts +17 -6
  155. package/src/store/activity.ts +1 -2
  156. package/src/store/backfill-preflight.ts +0 -3
  157. package/src/store/backfill.ts +0 -1
  158. package/src/store/metrics-preflight.ts +4 -14
  159. package/src/store/metrics.ts +5 -5
  160. package/src/store/preflight.ts +0 -13
  161. package/src/store/store.ts +11 -12
  162. package/src/transport-registry.ts +6 -30
  163. package/src/transports/claude-code-cli.ts +149 -215
  164. package/src/transports/opencode-client.ts +4 -24
  165. package/src/transports/opencode-sdk.ts +17 -112
  166. package/src/triage/plain-reply.ts +37 -0
  167. package/src/ui/activity.ts +1 -6
  168. package/src/ui/config-edit.ts +14 -67
  169. package/src/ui/config.ts +3 -8
  170. package/src/ui/plan.ts +11 -198
  171. package/src/ui/progress.ts +3 -49
  172. package/src/ui/result.ts +18 -77
  173. package/src/ui/review-menu.ts +3 -12
  174. package/src/ui/select.ts +9 -79
  175. package/src/updater.ts +1 -1
  176. package/src/usage.ts +1 -7
  177. package/prompts/scout.md +0 -140
  178. package/src/ci/platform-estimate.ts +0 -111
  179. package/src/review/scout.ts +0 -323
@@ -1,323 +0,0 @@
1
- // The scout's PURE half — the diff-only pre-hunter stage (ROADMAP-DOORDASH M3,
2
- // `docs/scout-design.md` §3.7-§3.9). Engine source, never prompt-set text: the
3
- // contract string, the caps and the leads block are covered by the engine
4
- // version, not by the prompt-set fingerprint.
5
- //
6
- // WHY this module exists in M4, one milestone before the stage is wired into
7
- // review/pipeline.ts: so the scout-probe measures the SAME parsing, capping and
8
- // rendering the engine will ship in M5. A probe carrying its own parser and its
9
- // own caps would measure the probe's parser — and every number it produced
10
- // about the PROMPT would be confounded by a second implementation that no
11
- // production run ever executes.
12
-
13
- import { normalizePath } from "#compare/compare";
14
- import { wrapBlock } from "#review/boundary";
15
-
16
- // Prose §3.7 turned into the engine-owned output contract, beside
17
- // HUNTER/REFUTER/SUMMARY_OUTPUT_CONTRACT in review/pipeline.ts. This text is driver
18
- // source: it is covered by the engine version, NOT by the prompt-set
19
- // fingerprint.
20
- export const SCOUT_OUTPUT_CONTRACT = [
21
- "Your final message must be exactly one JSON object — no prose, no code",
22
- "fences — of the shape",
23
- '{"leads":[{"path":"...","line":123,"why":"one sentence"}]}. A lead',
24
- "carries nothing else: no severity, no evidence class, no proof refs, no",
25
- 'hop trail. If the diff hides no suspicious place, return {"leads":[]} —',
26
- "an empty array is a valid, expected result, not a failure.",
27
- ].join("\n");
28
-
29
- export interface ScoutLead {
30
- path: string;
31
- line: number;
32
- why: string;
33
- }
34
-
35
- // The scout gets the patch and the contract and NOTHING else — no priors, no
36
- // gotchas, no PR title or body (§3.8). Feeding it the same {{PRIORS}}/
37
- // {{GOTCHAS}} the hunters read would correlate its attention with theirs, and
38
- // the independence of its pass is the entire reason it can add coverage.
39
- // Byte-identical in shape to summarizerPrompt: patch, blank line, contract.
40
- //
41
- // The patch is the ONE attacker-controlled block this prompt carries and it is
42
- // the first thing the scout reads, so it is wrapped in C4's nonced boundary
43
- // tag (`docs/c4-preamble-design.md` §3.3): a diff that adds a line reading
44
- // `</patch>` cannot end its own block and speak as the engine. `nonce` is
45
- // REQUIRED rather than defaulted — a default would let a caller compose an
46
- // unwrapped prompt by omission, which is the whole failure this closes.
47
- export function scoutPrompt(patch: string, nonce: string): string {
48
- return [wrapBlock("patch", nonce, patch), "", SCOUT_OUTPUT_CONTRACT].join(
49
- "\n",
50
- );
51
- }
52
-
53
- export class ScoutValidationError extends Error {}
54
-
55
- function must(condition: boolean, message: string): void {
56
- if (!condition) throw new ScoutValidationError(message);
57
- }
58
-
59
- // Structural validation BEFORE anything reaches the driver — the same role
60
- // validateHunterDraft plays for a hunter's draft. A step whose final message
61
- // does not survive these checks is "not delivered".
62
- export function validateScoutLeads(candidate: unknown): ScoutLead[] {
63
- must(
64
- typeof candidate === "object" && candidate !== null,
65
- "scout output must be an object",
66
- );
67
- const d = candidate as Record<string, unknown>;
68
- // An ABSENT `leads` key is a failure, never an empty list: the contract makes
69
- // {"leads":[]} the way a scout says "nothing suspicious here", so a model
70
- // that omitted the key did not tell us it found nothing — it told us nothing.
71
- must(Array.isArray(d.leads), "scout output .leads must be an array");
72
- return (d.leads as unknown[]).map((entry, i) => {
73
- must(
74
- typeof entry === "object" && entry !== null,
75
- `scout leads[${i}] must be an object`,
76
- );
77
- const lead = entry as Record<string, unknown>;
78
- must(
79
- typeof lead.path === "string" && lead.path.length > 0,
80
- `scout leads[${i}].path required`,
81
- );
82
- must(
83
- typeof lead.path === "string" && lead.path.length <= 400,
84
- `scout leads[${i}].path must be at most 400 characters`,
85
- );
86
- // Git diff notation is not a path. A scout that writes `b/src/x.ts` copied
87
- // the `+++ b/...` header it was given — it is being literal, not wrong —
88
- // and the prompt's Coordinates section asks for the bare path. Stripping
89
- // the prefix HERE, at the one boundary every lead crosses, is what makes
90
- // that slip free: the caps' per-path grouping, the block the hunters read,
91
- // §3.10's hunk metric and §3.9's ±25 attribution then all see one spelling.
92
- // Left unstripped, a correct suspicion at the right line scores as a
93
- // coverage MISS and the M4 gate silently measures prompt formatting
94
- // instead of scouting. `compare/compare.ts`'s normalizePath is deliberately NOT
95
- // the place for this: it defines "the same path" for the PR
96
- // comparison rows, and widening it there would invent matches across
97
- // `packages/`.
98
- const leadPath = (lead.path as string).replace(/^[ab]\//, "");
99
- must(leadPath.length > 0, `scout leads[${i}].path required`);
100
- must(
101
- typeof lead.line === "number" &&
102
- Number.isInteger(lead.line) &&
103
- lead.line >= 1,
104
- `scout leads[${i}].line must be an integer >= 1`,
105
- );
106
- must(
107
- typeof lead.why === "string" && lead.why.length > 0,
108
- `scout leads[${i}].why required`,
109
- );
110
- // NO maximum on `why` here on purpose. The 240-char ceiling is a DRIVER cap
111
- // applied in capScoutLeads, not grounds to discard a whole step's output:
112
- // one over-long sentence would otherwise delete eleven good leads and the
113
- // paid spawn that produced them.
114
- //
115
- // Extra keys are IGNORED, never rejected — the return value is narrowed to
116
- // exactly {path, line, why}. A model that volunteers a `severity` has not
117
- // failed the contract; silently dropping the key is what keeps the scout
118
- // structurally incapable of producing a finding (§3.5 mechanism 3), and
119
- // rejecting it instead would trade that guarantee for a lost step.
120
- return {
121
- path: leadPath,
122
- line: lead.line as number,
123
- why: lead.why as string,
124
- };
125
- });
126
- }
127
-
128
- // The ceiling (§3.8). Hard, enforced by the driver, never by the prompt alone —
129
- // a prompt-only cap is a request, and the failure mode DashBench names is a
130
- // scout that leads on everything.
131
- export const MAX_LEADS = 12; // above this it is a filter of nothing
132
- export const MAX_LEADS_PER_PATH = 3; // stops one interesting file absorbing the whole budget
133
- export const MAX_WHY_CHARS = 240; // one sentence; a paragraph is a finding in disguise
134
- export const MAX_LEADS_BLOCK_CHARS = 3000; // bounded prompt growth per hunter, times every hunter
135
-
136
- // The verbatim block shape from §3.8. The header paragraph is the
137
- // anti-anchoring guard, and it is what keeps §3.4's "bias" from decaying into
138
- // "replace" in practice: without it a hunter reads a lead list as a work order
139
- // and stops scanning the rest of the diff.
140
- const LEADS_BLOCK_HEADER = [
141
- "Scout leads — UNVERIFIED suspicions from a diff-only pass that read no",
142
- "code. They are not findings, they carry no evidence, and confirming one",
143
- "still requires your own proof_refs. Their absence is not evidence of",
144
- "absence: your own scan of the whole diff is unchanged.",
145
- ].join("\n");
146
-
147
- // Empty leads render to the EMPTY STRING, not to a header with no bullets: the
148
- // block must be absent byte for byte when there is nothing to say. That is what
149
- // makes M6's control arm a control arm — a scout run that found nothing must
150
- // produce a hunter prompt identical to an unled run's.
151
- export function renderLeadsBlock(leads: ScoutLead[]): string {
152
- if (leads.length === 0) return "";
153
- const bullets = leads.map((l) => `- ${l.path}:${l.line} — ${l.why}`);
154
- return [LEADS_BLOCK_HEADER, "", ...bullets].join("\n");
155
- }
156
-
157
- export interface CappedLeads {
158
- leads: ScoutLead[];
159
- dropped: number;
160
- whyTruncated: number;
161
- }
162
-
163
- // Deterministic, INPUT ORDER, no re-ranking. Re-ranking would make the scout a
164
- // filter rather than a bias, and a filter's cost lands entirely in the blind
165
- // spot where neither M6 arm can see it: a lead ranked out is a place no hunter
166
- // was pointed at and no artifact records.
167
- //
168
- // A truncation that fires routinely is a PROMPT defect to fix, never a cap to
169
- // raise (§3.8) — which is why the probe reports raw and capped counts side by
170
- // side instead of only what survived.
171
- export function capScoutLeads(leads: ScoutLead[]): CappedLeads {
172
- let whyTruncated = 0;
173
- // (a) per-lead `why` truncation. Counted for every lead it fires on, even one
174
- // a later step drops — the count answers "is the prompt writing paragraphs?",
175
- // which is a property of the scout's output, not of what survived the caps.
176
- const truncated = leads.map((lead) => {
177
- if (lead.why.length <= MAX_WHY_CHARS) return lead;
178
- whyTruncated++;
179
- return { ...lead, why: lead.why.slice(0, MAX_WHY_CHARS) };
180
- });
181
-
182
- // (b) per-path: the first MAX_LEADS_PER_PATH per distinct path. Exact string
183
- // equality, no normalization — the scout is instructed to use the diff's own
184
- // path spelling (§3.7 Coordinates), so two spellings of one file are a prompt
185
- // failure to see, not a cap to paper over.
186
- const perPath = new Map<string, number>();
187
- const pathCapped: ScoutLead[] = [];
188
- for (const lead of truncated) {
189
- const seen = perPath.get(lead.path) ?? 0;
190
- if (seen >= MAX_LEADS_PER_PATH) continue;
191
- perPath.set(lead.path, seen + 1);
192
- pathCapped.push(lead);
193
- }
194
-
195
- // (c) total.
196
- const kept = pathCapped.slice(0, MAX_LEADS);
197
-
198
- // (d) block size, measured on the RENDERED block rather than on a sum of
199
- // field lengths — the header and the bullet punctuation are prompt bytes too.
200
- // Dropping from the END keeps input order meaningful: the leads that survive
201
- // are always a prefix of what the scout emitted.
202
- while (
203
- kept.length > 0 &&
204
- renderLeadsBlock(kept).length > MAX_LEADS_BLOCK_CHARS
205
- ) {
206
- kept.pop();
207
- }
208
-
209
- return { leads: kept, dropped: leads.length - kept.length, whyTruncated };
210
- }
211
-
212
- export interface HunkRange {
213
- path: string;
214
- start: number;
215
- end: number;
216
- }
217
-
218
- // Right-side (new-file) line ranges, one per hunk, in order of appearance.
219
- // Both captures matter here, unlike pr/inline.ts's anchor scan: `d` is what turns
220
- // a header into a RANGE, and `d === 0` is what marks a hunk with no right side.
221
- const HUNK_HEADER = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
222
- const TARGET_HEADER = /^\+\+\+ (.+)$/;
223
-
224
- // Parsed from the `+++ b/...` headers plus each `@@` header's right-side counts.
225
- //
226
- // WHY a header scan and not pr/inline.ts's splitDiffRecords: this metric needs the
227
- // hunk BOUNDARIES (a lead lands "inside hunk 3 of 7"), which the anchor-set
228
- // representation deliberately throws away. The cost is the one structural hole
229
- // splitDiffRecords closes for free — an ADDED body line whose own content
230
- // starts with `++` renders as `+++ ...` and reads exactly like a target header.
231
- // Guarded with state: a `+++` line only counts as a header when we are not
232
- // inside a hunk body, and a `diff --git` line resets that state.
233
- export function parseHunkRanges(patch: string): HunkRange[] {
234
- const ranges: HunkRange[] = [];
235
- let target: string | undefined;
236
- let inHunk = false;
237
- for (const line of patch.split("\n")) {
238
- if (line.startsWith("diff --git ")) {
239
- target = undefined;
240
- inHunk = false;
241
- continue;
242
- }
243
- const header = HUNK_HEADER.exec(line);
244
- if (header !== null) {
245
- inHunk = true;
246
- if (target === undefined) continue;
247
- const start = Number.parseInt(header[1] as string, 10);
248
- // An absent count means exactly one line (`@@ -1 +1 @@`), which is git's
249
- // own shorthand, not a malformed header.
250
- const count =
251
- header[2] === undefined ? 1 : Number.parseInt(header[2], 10);
252
- // A pure-deletion hunk (`+12,0`) has NO right-side line at all. Skipped
253
- // rather than recorded as an empty range: a lead cannot land on a line
254
- // that does not exist in the new file, so counting it as a hunk the scout
255
- // failed to cover would penalise the scout for the impossible.
256
- if (count === 0) continue;
257
- ranges.push({ path: target, start, end: start + count - 1 });
258
- continue;
259
- }
260
- if (inHunk) continue;
261
- const found = TARGET_HEADER.exec(line);
262
- if (found === null) continue;
263
- const raw = (found[1] as string).trim();
264
- // `+++ /dev/null` is a deleted file: it contributes no right-side hunk, and
265
- // leaving `target` undefined makes its `@@` headers fall through above.
266
- target = raw === "/dev/null" ? undefined : raw.replace(/^[ab]\//, "");
267
- }
268
- return ranges;
269
- }
270
-
271
- export interface HunkCoverage {
272
- hunks: number;
273
- hunksWithLead: number;
274
- coverage: number;
275
- unmatchedLeads: number;
276
- }
277
-
278
- // M4's RESTRAINT metric (§3.10 assertion 2). It measures SELECTIVITY — a
279
- // property of the scout — precisely because cleanliness is a property of a PR
280
- // we have not triaged: the six restraint PRs carry untriaged `prhero_only`
281
- // rows, so "this PR is clean" is not a claim this project owns, and a
282
- // precision number computed against it would be fiction.
283
- //
284
- // Stated as what it is: a PROXY. The failure mode DashBench names is not
285
- // "flagged a clean PR", it is filtering nothing — being loud everywhere — and
286
- // the fraction of changed hunks carrying a lead measures exactly that without
287
- // knowing a single defect count.
288
- //
289
- // `unmatchedLeads` is the diagnostic beside it: a lead inside no hunk at all is
290
- // either a miscounted line number (a prompt defect in the Coordinates section)
291
- // or a suspicion about unchanged code (out of contract). Both are worth seeing,
292
- // and neither is visible in the coverage fraction alone.
293
- export function hunkCoverage(patch: string, leads: ScoutLead[]): HunkCoverage {
294
- const hunks = parseHunkRanges(patch);
295
- const normalizedLeads = leads.map((l) => ({
296
- path: normalizePath(l.path),
297
- line: l.line,
298
- }));
299
- const matchedLeads = new Set<number>();
300
- let hunksWithLead = 0;
301
- for (const hunk of hunks) {
302
- const hunkPath = normalizePath(hunk.path);
303
- let carries = false;
304
- for (const [i, lead] of normalizedLeads.entries()) {
305
- if (lead.path !== hunkPath) continue;
306
- if (lead.line < hunk.start || lead.line > hunk.end) continue;
307
- // Both loops run to completion: a hunk is counted once no matter how many
308
- // leads land in it, and every lead that lands anywhere is marked so the
309
- // unmatched tally stays a per-LEAD number.
310
- matchedLeads.add(i);
311
- carries = true;
312
- }
313
- if (carries) hunksWithLead++;
314
- }
315
- return {
316
- hunks: hunks.length,
317
- hunksWithLead,
318
- // A patch with zero hunks is 0, never NaN — the restraint mean is averaged
319
- // over runs, and one NaN would poison the whole gate silently.
320
- coverage: hunks.length === 0 ? 0 : hunksWithLead / hunks.length,
321
- unmatchedLeads: leads.length - matchedLeads.size,
322
- };
323
- }