crysk 0.0.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +611 -3
  3. package/bin/pr-hero.js +166 -0
  4. package/config/models/anthropic.json +5 -0
  5. package/dist/SKILL-7e3725zn.md +496 -0
  6. package/dist/SKILL-7q35wcaz.md +66 -0
  7. package/dist/SKILL-9at22381.md +74 -0
  8. package/dist/SKILL-ex2hxxh3.md +134 -0
  9. package/dist/SKILL-y8rv8msh.md +134 -0
  10. package/dist/SKILL-ygka1bs0.md +515 -0
  11. package/dist/adjudicator-dtg2axnh.md +86 -0
  12. package/dist/admission-config.example-a9vqmmad.json +9 -0
  13. package/dist/ci-admission-camfbx2b.md +122 -0
  14. package/dist/ci-admission-qk9r9taq.md +124 -0
  15. package/dist/cli.js +42501 -0
  16. package/dist/consolidate-ac0mnfyj.md +24 -0
  17. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  18. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  19. package/dist/deep-review-parity-0ec904db.md +120 -0
  20. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  21. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  22. package/dist/index.js +20190 -0
  23. package/dist/opencode-ci-7b0be64p.md +141 -0
  24. package/dist/review-refuter-j4e9gezy.md +71 -0
  25. package/dist/scout-yvp153q7.md +140 -0
  26. package/dist/summarizer-zca44nxa.md +18 -0
  27. package/dist/workflow-w1g9szna.yml +151 -0
  28. package/package.json +81 -4
  29. package/prompts/consolidate.md +24 -0
  30. package/prompts/default/PROVENANCE.md +18 -0
  31. package/prompts/default/deep-review-lifecycle.md +362 -0
  32. package/prompts/default/deep-review-logic.md +156 -0
  33. package/prompts/default/deep-review-parity.md +120 -0
  34. package/prompts/default/deep-review-reliability.md +125 -0
  35. package/prompts/default/deep-review-resilience.md +118 -0
  36. package/prompts/default/review-refuter.md +71 -0
  37. package/prompts/scout.md +140 -0
  38. package/prompts/summarizer.md +18 -0
  39. package/skills/crysk/SKILL.md +74 -0
  40. package/skills/crysk-ci-setup/SKILL.md +134 -0
  41. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  42. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  43. package/skills/crysk-ci-setup/references/ci-admission.md +124 -0
  44. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  45. package/skills/crysk-loop/SKILL.md +515 -0
  46. package/skills/crysk-loop/adjudicator.md +86 -0
  47. package/skills/crysk-pr/SKILL.md +66 -0
  48. package/src/agent-env.ts +1084 -0
  49. package/src/asset-manifest.ts +83 -0
  50. package/src/assets.d.ts +6 -0
  51. package/src/assets.ts +183 -0
  52. package/src/brand-paths.ts +155 -0
  53. package/src/brand.ts +255 -0
  54. package/src/ci/admission-ledger.ts +350 -0
  55. package/src/ci/classify-error.ts +73 -0
  56. package/src/ci/cli-record.ts +271 -0
  57. package/src/ci/force-comment.ts +39 -0
  58. package/src/ci/gates.ts +945 -0
  59. package/src/ci/outcome.ts +2181 -0
  60. package/src/ci/override.ts +187 -0
  61. package/src/ci/publish.ts +1639 -0
  62. package/src/ci/reporter.ts +626 -0
  63. package/src/ci/review-admission.ts +910 -0
  64. package/src/ci/review-levels.ts +310 -0
  65. package/src/ci/review-policy.ts +18 -0
  66. package/src/ci/review-risk.ts +184 -0
  67. package/src/ci/setup.ts +844 -0
  68. package/src/ci/trigger.ts +1353 -0
  69. package/src/cli.ts +348 -0
  70. package/src/commands/activity.ts +67 -0
  71. package/src/commands/ci-setup-questions.ts +397 -0
  72. package/src/commands/ci-setup.ts +381 -0
  73. package/src/commands/config.ts +99 -0
  74. package/src/commands/doctor.ts +108 -0
  75. package/src/commands/init.ts +139 -0
  76. package/src/commands/mcp.ts +10 -0
  77. package/src/commands/menu.ts +129 -0
  78. package/src/commands/post.ts +302 -0
  79. package/src/commands/skills.ts +83 -0
  80. package/src/commands/status.ts +173 -0
  81. package/src/commands/triage.ts +342 -0
  82. package/src/commands/uninstall.ts +37 -0
  83. package/src/commands/upgrade.ts +214 -0
  84. package/src/commands/usage.ts +98 -0
  85. package/src/compare/compare.ts +28 -0
  86. package/src/compare/floor-test.ts +471 -0
  87. package/src/compare/martian-adapter.ts +80 -0
  88. package/src/config/config.ts +267 -0
  89. package/src/corpus/corpus.ts +1094 -0
  90. package/src/corpus/preflight.ts +1789 -0
  91. package/src/diversity/accounting.ts +90 -0
  92. package/src/diversity/adjudication.ts +145 -0
  93. package/src/diversity/admission.ts +60 -0
  94. package/src/diversity/benchmark.ts +195 -0
  95. package/src/diversity/clustering.ts +285 -0
  96. package/src/diversity/errors.ts +7 -0
  97. package/src/diversity/identity.ts +285 -0
  98. package/src/diversity/index.ts +11 -0
  99. package/src/diversity/pipeline-integration.ts +448 -0
  100. package/src/diversity/projection.ts +57 -0
  101. package/src/diversity/self-contained.ts +68 -0
  102. package/src/diversity/target-validation.ts +179 -0
  103. package/src/doctor-migration.ts +209 -0
  104. package/src/doctor.ts +723 -0
  105. package/src/errors.ts +83 -0
  106. package/src/execution/admission.ts +75 -0
  107. package/src/execution/atomic-write.ts +35 -0
  108. package/src/execution/attempt-evidence.ts +415 -0
  109. package/src/execution/bucket-id.ts +136 -0
  110. package/src/execution/concurrency-limiter.ts +175 -0
  111. package/src/execution/contracts.ts +443 -0
  112. package/src/execution/failure-classification.ts +42 -0
  113. package/src/execution/failure-policy.ts +240 -0
  114. package/src/execution/harness.ts +2548 -0
  115. package/src/execution/settlement.ts +348 -0
  116. package/src/execution/spawned-process.ts +66 -0
  117. package/src/execution/spend-limiter.ts +424 -0
  118. package/src/execution/step-artifacts.ts +55 -0
  119. package/src/execution/usage-normalized.ts +469 -0
  120. package/src/git/git.ts +396 -0
  121. package/src/git/identity.ts +64 -0
  122. package/src/git/refs.ts +140 -0
  123. package/src/home-preflight.ts +443 -0
  124. package/src/home.ts +243 -0
  125. package/src/ignore-file.ts +336 -0
  126. package/src/ignore-read.ts +118 -0
  127. package/src/index.ts +34 -0
  128. package/src/legacy-launchd.ts +29 -0
  129. package/src/mcp/mcp.ts +150 -0
  130. package/src/mcp/preflight.ts +407 -0
  131. package/src/menu-context.ts +192 -0
  132. package/src/model/catalog.ts +251 -0
  133. package/src/model/exec-snapshots.ts +390 -0
  134. package/src/model/free-discovery.ts +302 -0
  135. package/src/model/provider-capabilities.ts +814 -0
  136. package/src/model/routing.ts +600 -0
  137. package/src/pr/admission.ts +984 -0
  138. package/src/pr/answered-findings.ts +169 -0
  139. package/src/pr/ci-admission-gate.ts +743 -0
  140. package/src/pr/ci-publish.ts +76 -0
  141. package/src/pr/discovery.ts +432 -0
  142. package/src/pr/inline.ts +507 -0
  143. package/src/pr/plan.ts +366 -0
  144. package/src/pr/posting.ts +115 -0
  145. package/src/pr/pr-status.ts +845 -0
  146. package/src/pr/pr.ts +3642 -0
  147. package/src/pr/preflight.ts +1031 -0
  148. package/src/pr/publish-outcome.ts +361 -0
  149. package/src/pr/range.ts +119 -0
  150. package/src/pr/reverts-preflight.ts +606 -0
  151. package/src/pr/reverts.ts +377 -0
  152. package/src/pr/review-pr.ts +927 -0
  153. package/src/pr/status.ts +154 -0
  154. package/src/pr/target.ts +388 -0
  155. package/src/pr/teardown.ts +437 -0
  156. package/src/pr/worktree-setup.ts +60 -0
  157. package/src/production-runtime.ts +1877 -0
  158. package/src/progress.ts +487 -0
  159. package/src/rereview/adjudicate.ts +89 -0
  160. package/src/rereview/classify.ts +362 -0
  161. package/src/rereview/identity.ts +211 -0
  162. package/src/rereview/plan.ts +308 -0
  163. package/src/rereview/prepare.ts +1025 -0
  164. package/src/rereview/state.ts +767 -0
  165. package/src/rereview/verify.ts +241 -0
  166. package/src/review/boundary.ts +105 -0
  167. package/src/review/consolidate.ts +246 -0
  168. package/src/review/dedupe.ts +368 -0
  169. package/src/review/drafts.ts +448 -0
  170. package/src/review/findings-conformance.ts +120 -0
  171. package/src/review/findings.ts +714 -0
  172. package/src/review/pipeline.ts +3977 -0
  173. package/src/review/preflight.ts +3575 -0
  174. package/src/review/prompt-set.ts +177 -0
  175. package/src/review/proof-refs.ts +187 -0
  176. package/src/review/report.ts +1821 -0
  177. package/src/review/review.ts +490 -0
  178. package/src/review/root-cause.ts +120 -0
  179. package/src/review/route-preflight.ts +289 -0
  180. package/src/review/run.ts +601 -0
  181. package/src/review/scout.ts +323 -0
  182. package/src/review/size-gate.ts +595 -0
  183. package/src/review/spec.ts +235 -0
  184. package/src/review/step-runner.ts +233 -0
  185. package/src/runner-authority.ts +596 -0
  186. package/src/security/binding-policy.ts +115 -0
  187. package/src/security/credential-broker.ts +773 -0
  188. package/src/security/evidence-redaction.ts +62 -0
  189. package/src/security/execution-authority.ts +27 -0
  190. package/src/security/redact.ts +71 -0
  191. package/src/security/workspace-read-broker.ts +466 -0
  192. package/src/server/client.ts +190 -0
  193. package/src/server/preflight.ts +217 -0
  194. package/src/server/server.ts +327 -0
  195. package/src/signal-handler.ts +50 -0
  196. package/src/store/activity.ts +413 -0
  197. package/src/store/backfill-preflight.ts +49 -0
  198. package/src/store/backfill.ts +141 -0
  199. package/src/store/gc-preflight.ts +206 -0
  200. package/src/store/gc.ts +424 -0
  201. package/src/store/metrics-preflight.ts +229 -0
  202. package/src/store/metrics.ts +236 -0
  203. package/src/store/preflight.ts +748 -0
  204. package/src/store/store.ts +693 -0
  205. package/src/system-tools.ts +355 -0
  206. package/src/transport-registry.ts +1124 -0
  207. package/src/transports/claude-code-cli.ts +1348 -0
  208. package/src/transports/opencode-admission.ts +515 -0
  209. package/src/transports/opencode-client.ts +3328 -0
  210. package/src/transports/opencode-evidence.ts +557 -0
  211. package/src/transports/opencode-mcp.ts +248 -0
  212. package/src/transports/opencode-sdk.ts +2294 -0
  213. package/src/transports/opencode-server.ts +535 -0
  214. package/src/triage/adjudication.ts +113 -0
  215. package/src/triage/reply.ts +125 -0
  216. package/src/triage/triage.ts +255 -0
  217. package/src/ui/activity.ts +173 -0
  218. package/src/ui/config-edit.ts +816 -0
  219. package/src/ui/config.ts +462 -0
  220. package/src/ui/menu.ts +1325 -0
  221. package/src/ui/plan.ts +1039 -0
  222. package/src/ui/primitives.ts +300 -0
  223. package/src/ui/progress.ts +298 -0
  224. package/src/ui/result.ts +552 -0
  225. package/src/ui/review-menu.ts +312 -0
  226. package/src/ui/select.ts +528 -0
  227. package/src/ui/tree.ts +178 -0
  228. package/src/uninstaller.ts +479 -0
  229. package/src/updater.ts +836 -0
  230. package/src/usage.ts +77 -0
  231. package/src/watch/preflight.ts +1389 -0
  232. package/src/watch/watch.ts +1235 -0
  233. package/src/wizard.ts +877 -0
@@ -0,0 +1,471 @@
1
+ // M6's PRIMARY instrument (ROADMAP-DOORDASH M6, `docs/scout-design.md` §3.11):
2
+ // the floor test. Deterministic, per-case, no statistics.
3
+ //
4
+ // The question is binary per case: *did this arm produce a refuter-corroborated
5
+ // finding at the site?* Nothing here scores quality, ranks arms, or computes a
6
+ // p-value — §3.11 states up front that 13 cases cannot rank two arms that both
7
+ // score well, and an instrument that pretended otherwise would be the third
8
+ // thing this milestone had to throw away (§3.10bis killed the second).
9
+ //
10
+ // PURE on purpose, the ../report.ts rule: no I/O, no clock, no git. The harness
11
+ // reads the run dirs and hands parsed objects in, so a scoring pass can be
12
+ // re-run from artifacts on disk months later and come out byte-identical.
13
+
14
+ import type { Finding, FindingsDocument } from "#review/findings";
15
+ import { DEFAULT_LINE_WINDOW, normalizePath } from "./compare";
16
+
17
+ // §3.11's two case types, and M6 must not blur them: a `miss` case reviews the
18
+ // PR where our engine missed a defect a production reviewer caught; a `corpus` case reviews
19
+ // the INTRODUCER, and `fix_pr` is provenance only.
20
+ export type FloorCaseType = "miss" | "corpus";
21
+
22
+ export interface FloorCase {
23
+ id: number;
24
+ pr: number;
25
+ path: string;
26
+ start_line: number;
27
+ end_line: number;
28
+ type: FloorCaseType;
29
+ fix_pr?: number;
30
+ what: string;
31
+ }
32
+
33
+ export class FloorCaseError extends Error {}
34
+
35
+ function must(condition: boolean, message: string): void {
36
+ if (!condition) throw new FloorCaseError(message);
37
+ }
38
+
39
+ // Loud, not tolerant, and deliberately unlike `parsePipelineMeta`: a malformed
40
+ // case list is not a degraded read to fall back from — it is an experiment
41
+ // about to spend ~$224 scoring the wrong sites. The fail-safe direction here is
42
+ // refusing to start.
43
+ export function parseFloorCases(raw: string): FloorCase[] {
44
+ let parsed: unknown;
45
+ try {
46
+ parsed = JSON.parse(raw);
47
+ } catch (error) {
48
+ throw new FloorCaseError(
49
+ `floor cases file is not valid JSON: ${(error as Error).message}`,
50
+ );
51
+ }
52
+ must(
53
+ typeof parsed === "object" && parsed !== null && !Array.isArray(parsed),
54
+ "floor cases file must be a JSON object",
55
+ );
56
+ const doc = parsed as Record<string, unknown>;
57
+ must(Array.isArray(doc.cases), "floor cases file must carry a `cases` array");
58
+ const cases = (doc.cases as unknown[]).map((entry, i) => {
59
+ must(
60
+ typeof entry === "object" && entry !== null,
61
+ `cases[${i}] must be an object`,
62
+ );
63
+ const c = entry as Record<string, unknown>;
64
+ const int = (key: string): number => {
65
+ const value = c[key];
66
+ must(
67
+ typeof value === "number" && Number.isInteger(value) && value > 0,
68
+ `cases[${i}].${key} must be a positive integer`,
69
+ );
70
+ return value as number;
71
+ };
72
+ const id = int("id");
73
+ const pr = int("pr");
74
+ const start = int("start_line");
75
+ const end = int("end_line");
76
+ must(
77
+ end >= start,
78
+ `cases[${i}].end_line (${end}) is before start_line (${start})`,
79
+ );
80
+ must(
81
+ typeof c.path === "string" && c.path.trim().length > 0,
82
+ `cases[${i}].path required`,
83
+ );
84
+ // A bare filename is the failure §2.4septies's 2026-08-18 note records:
85
+ // `normalizePath` refuses basename matching, so a short path scores as a
86
+ // miss by BOTH arms and reads as evidence about the scout. Cheap to check,
87
+ // and the check is the only thing standing between a display path and a
88
+ // silently unscorable case.
89
+ must(
90
+ (c.path as string).includes("/"),
91
+ `cases[${i}].path must be repo-relative, got a bare filename: ${c.path}`,
92
+ );
93
+ must(
94
+ c.type === "miss" || c.type === "corpus",
95
+ `cases[${i}].type must be "miss" or "corpus"`,
96
+ );
97
+ must(
98
+ typeof c.what === "string" && c.what.trim().length > 0,
99
+ `cases[${i}].what required`,
100
+ );
101
+ must(
102
+ c.type === "corpus"
103
+ ? typeof c.fix_pr === "number"
104
+ : c.fix_pr === undefined,
105
+ `cases[${i}]: a corpus case needs fix_pr, a miss case must not carry one`,
106
+ );
107
+ return {
108
+ id,
109
+ pr,
110
+ path: c.path as string,
111
+ start_line: start,
112
+ end_line: end,
113
+ type: c.type as FloorCaseType,
114
+ ...(c.fix_pr === undefined ? {} : { fix_pr: c.fix_pr as number }),
115
+ what: c.what as string,
116
+ };
117
+ });
118
+ const ids = new Set(cases.map((c) => c.id));
119
+ must(ids.size === cases.length, "floor case ids must be unique");
120
+ must(cases.length > 0, "floor cases file carries no cases");
121
+ return cases;
122
+ }
123
+
124
+ // `compare/compare.ts`'s window, reused rather than re-chosen: the PR comparison and
125
+ // this scorer must agree on what "the same place" means, or a finding can match in one
126
+ // and count as a miss in the other at the same line.
127
+ export { DEFAULT_LINE_WINDOW };
128
+
129
+ export type FloorArm = "scout" | "control";
130
+
131
+ // Which arm a run belongs to, read from the ARTIFACT and never from a
132
+ // directory name or a harness variable — pipeline.json's `scout.enabled` is
133
+ // the field M5 built for exactly this, written on every run including the ones
134
+ // with no scout at all.
135
+ //
136
+ // `null` means the artifact cannot say, which is not the same as "control": a
137
+ // run from before M5, or a corrupt plan, must be excluded from the read rather
138
+ // than silently counted as the arm it happens to resemble.
139
+ export function armOfRun(plan: unknown): FloorArm | null {
140
+ if (typeof plan !== "object" || plan === null || Array.isArray(plan)) {
141
+ return null;
142
+ }
143
+ const scout = (plan as Record<string, unknown>).scout;
144
+ if (typeof scout !== "object" || scout === null) return null;
145
+ const enabled = (scout as Record<string, unknown>).enabled;
146
+ if (typeof enabled !== "boolean") return null;
147
+ return enabled ? "scout" : "control";
148
+ }
149
+
150
+ export function diversityArmOfRun(
151
+ plan: unknown,
152
+ ): "diversity" | "control" | null {
153
+ if (typeof plan !== "object" || plan === null || Array.isArray(plan)) {
154
+ return null;
155
+ }
156
+ const diversity = (plan as Record<string, unknown>).multiModelDiversity;
157
+ if (typeof diversity !== "object" || diversity === null) return null;
158
+ const enabled = (diversity as Record<string, unknown>).enabled;
159
+ if (typeof enabled !== "boolean") return null;
160
+ return enabled ? "diversity" : "control";
161
+ }
162
+
163
+ // §3.6's exclusion rule, as a predicate: a scout-arm run whose scout FAILED is
164
+ // a control-arm run wearing a scout-arm flag. Counting it would dilute the arm
165
+ // with its own control, which is the exact way an A/B lies quietly. The harness
166
+ // re-runs these; the scorer refuses to score them.
167
+ export function scoutFailed(plan: unknown): boolean {
168
+ if (typeof plan !== "object" || plan === null) return false;
169
+ const scout = (plan as Record<string, unknown>).scout;
170
+ if (typeof scout !== "object" || scout === null) return false;
171
+ const record = scout as Record<string, unknown>;
172
+ return record.enabled === true && record.status !== "ok";
173
+ }
174
+
175
+ export interface FloorHit {
176
+ finding_id: string;
177
+ path: string;
178
+ line: number;
179
+ severity: string;
180
+ tier?: string;
181
+ refuter_verdict: string;
182
+ }
183
+
184
+ export interface CaseScore {
185
+ case_id: number;
186
+ pr: number;
187
+ type: FloorCaseType;
188
+ // THE GATE (§3.11): a refuter-CORROBORATED finding at the site.
189
+ hit: boolean;
190
+ // The diagnostic beside it: any finding at the site, whatever the refuter
191
+ // said. Reported separately and never folded into `hit`, because the gap
192
+ // between the two is a statement about the REFUTER, and an arm that finds
193
+ // the defect and then refutes it away has failed differently from an arm
194
+ // that never looked. M6 cannot attribute a result it cannot see.
195
+ found: boolean;
196
+ hits: FloorHit[];
197
+ }
198
+
199
+ function atSite(
200
+ finding: { path: string; line: number },
201
+ floorCase: FloorCase,
202
+ window: number,
203
+ ): boolean {
204
+ if (normalizePath(finding.path) !== normalizePath(floorCase.path))
205
+ return false;
206
+ return (
207
+ finding.line >= floorCase.start_line - window &&
208
+ finding.line <= floorCase.end_line + window
209
+ );
210
+ }
211
+
212
+ // Scores ONE run against the cases belonging to its PR.
213
+ //
214
+ // `debug.refuted` is deliberately NOT searched. A refuted finding is one the
215
+ // refuter positively disproved, and §3.11's gate says corroborated — counting
216
+ // a refuted finding as a floor hit would score the arm on what it SAID rather
217
+ // than on what survived scrutiny, which is the volume metric M0 already killed
218
+ // (§3.1). `debug.deduped` is likewise out: a merge loser's survivor is in
219
+ // `findings` and would double-count the same site.
220
+ export function scoreRun(
221
+ doc: Pick<FindingsDocument, "pr" | "findings">,
222
+ cases: FloorCase[],
223
+ opts: { lineWindow?: number } = {},
224
+ ): CaseScore[] {
225
+ const window = opts.lineWindow ?? DEFAULT_LINE_WINDOW;
226
+ const findings: Finding[] = Array.isArray(doc.findings) ? doc.findings : [];
227
+ return cases
228
+ .filter((c) => c.pr === doc.pr)
229
+ .map((floorCase) => {
230
+ const hits = findings
231
+ .filter((f) => atSite(f, floorCase, window))
232
+ .map((f) => ({
233
+ finding_id: f.id,
234
+ path: f.path,
235
+ line: f.line,
236
+ severity: f.severity,
237
+ ...(f.tier === undefined ? {} : { tier: f.tier }),
238
+ refuter_verdict: f.refuter_verdict,
239
+ }));
240
+ return {
241
+ case_id: floorCase.id,
242
+ pr: floorCase.pr,
243
+ type: floorCase.type,
244
+ hit: hits.some((h) => h.refuter_verdict === "corroborated"),
245
+ found: hits.length > 0,
246
+ hits,
247
+ };
248
+ });
249
+ }
250
+
251
+ export interface CaseTally {
252
+ case_id: number;
253
+ pr: number;
254
+ type: FloorCaseType;
255
+ // Replicates in which the gate fired, over replicates SCORED.
256
+ hit: number;
257
+ found: number;
258
+ replicates: number;
259
+ }
260
+
261
+ export interface ArmTally {
262
+ arm: FloorArm;
263
+ cases: CaseTally[];
264
+ // Cases hit in AT LEAST ONE replicate. §3.11's read is per case and binary;
265
+ // "at least one" is the recall-shaped reading, and `casesHitEvery` is stated
266
+ // beside it because §1.3 measured six of eight replicate pairs MOVING — a
267
+ // 1-of-2 and a 2-of-2 are different claims and the write-up must show both.
268
+ casesHitAny: number;
269
+ casesHitEvery: number;
270
+ casesFoundAny: number;
271
+ total: number;
272
+ }
273
+
274
+ export interface ScoredRun {
275
+ arm: FloorArm;
276
+ scores: CaseScore[];
277
+ }
278
+
279
+ // Aggregates scored runs into one row per case per arm.
280
+ //
281
+ // A case with ZERO scored replicates in an arm is kept with `replicates: 0`
282
+ // rather than dropped: a case nobody ran is not a case both arms missed, and
283
+ // silently omitting it would turn an incomplete session into a clean-looking
284
+ // result. It counts toward `total` and toward neither hit column.
285
+ export function tallyArm(
286
+ arm: FloorArm,
287
+ runs: ScoredRun[],
288
+ cases: FloorCase[],
289
+ ): ArmTally {
290
+ const mine = runs.filter((r) => r.arm === arm);
291
+ const tallies: CaseTally[] = cases.map((floorCase) => {
292
+ const scored = mine
293
+ .flatMap((r) => r.scores)
294
+ .filter((s) => s.case_id === floorCase.id);
295
+ return {
296
+ case_id: floorCase.id,
297
+ pr: floorCase.pr,
298
+ type: floorCase.type,
299
+ hit: scored.filter((s) => s.hit).length,
300
+ found: scored.filter((s) => s.found).length,
301
+ replicates: scored.length,
302
+ };
303
+ });
304
+ return {
305
+ arm,
306
+ cases: tallies,
307
+ casesHitAny: tallies.filter((t) => t.hit > 0).length,
308
+ casesHitEvery: tallies.filter(
309
+ (t) => t.replicates > 0 && t.hit === t.replicates,
310
+ ).length,
311
+ casesFoundAny: tallies.filter((t) => t.found > 0).length,
312
+ total: tallies.length,
313
+ };
314
+ }
315
+
316
+ // The floor test's whole output, as lines. A renderer, so it obeys the
317
+ // project's renderer rule: returns string[], never logs, and takes no styles
318
+ // because this table is written to a file and read in a diff, not painted.
319
+ export function renderFloorTable(
320
+ cases: FloorCase[],
321
+ scout: ArmTally,
322
+ control: ArmTally,
323
+ ): string[] {
324
+ const byId = new Map(cases.map((c) => [c.id, c]));
325
+ const cell = (t: CaseTally | undefined): string =>
326
+ t === undefined || t.replicates === 0
327
+ ? "not run"
328
+ : `${t.hit}/${t.replicates}${t.found > t.hit ? ` (found ${t.found})` : ""}`;
329
+ const scoutById = new Map(scout.cases.map((t) => [t.case_id, t]));
330
+ const controlById = new Map(control.cases.map((t) => [t.case_id, t]));
331
+ const lines = [
332
+ "| # | PR | type | control | scout | site |",
333
+ "|---|---|---|---|---|---|",
334
+ ];
335
+ for (const c of cases) {
336
+ const site = `${c.path}:${c.start_line}${
337
+ c.end_line === c.start_line ? "" : `-${c.end_line}`
338
+ }`;
339
+ lines.push(
340
+ `| ${c.id} | ${c.pr} | ${c.type} | ${cell(controlById.get(c.id))} | ` +
341
+ `${cell(scoutById.get(c.id))} | \`${site}\` |`,
342
+ );
343
+ }
344
+ lines.push("");
345
+ lines.push(
346
+ `control: ${control.casesHitAny}/${control.total} cases hit in at least one ` +
347
+ `replicate, ${control.casesHitEvery} in every replicate, ` +
348
+ `${control.casesFoundAny} found at the site before refutation`,
349
+ );
350
+ lines.push(
351
+ `scout: ${scout.casesHitAny}/${scout.total} cases hit in at least one ` +
352
+ `replicate, ${scout.casesHitEvery} in every replicate, ` +
353
+ `${scout.casesFoundAny} found at the site before refutation`,
354
+ );
355
+ // C10's blind spot, printed WITH the numbers rather than left to the prose:
356
+ // a table this compact is exactly the kind that gets screenshotted away from
357
+ // its caveat.
358
+ lines.push("");
359
+ lines.push(
360
+ "Neither arm's number can see a defect BOTH arms missed, and this table " +
361
+ "cannot rank two arms that both score well (§3.11). It can say `drop` " +
362
+ "loudly; it cannot distinguish `adopt` from `opt-in`.",
363
+ );
364
+ if (byId.size !== cases.length) lines.push("WARNING: duplicate case ids");
365
+ return lines;
366
+ }
367
+
368
+ // ---------------------------------------------------------------------------
369
+ // The clean pair (§3.11), which is NOT optional garnish.
370
+ //
371
+ // The floor test only looks at known-bad PRs, so nothing in it can see the
372
+ // failure a "bias, never filter" design is most likely to produce: hunters
373
+ // chasing spurious leads into junk findings on code where the control is
374
+ // quiet. M4's restraint gate measured the SCOUT's lead volume, not that
375
+ // downstream effect, and Tier 2's precision guard runs only on known-bad PRs,
376
+ // so neither instrument covers it either.
377
+ //
378
+ // §3.11's read is one number — *does the scout arm produce MORE findings than
379
+ // the control on a PR where the control produces few?* — and it is the one
380
+ // place this project sanctions a raw count, because the comparison is between
381
+ // arms on the same PR rather than an absolute claim about quality. C1's rule
382
+ // still applies to how it is READ, so the distinct-root-cause count is
383
+ // reported beside the raw one: one systemic defect reported at N call sites is
384
+ // one finding fanned out, and reading it as N is exactly how a correct review
385
+ // scores as a precision collapse.
386
+ // ---------------------------------------------------------------------------
387
+
388
+ export interface CleanRun {
389
+ arm: FloorArm;
390
+ pr: number;
391
+ findings: number;
392
+ // Findings the refuter corroborated — the ones that would actually reach a
393
+ // human as blocking.
394
+ corroborated: number;
395
+ // `debug.root_causes.distinct_root_causes` when the artifact carries it.
396
+ // Absent on runs that predate the clusterer, and absent is not zero.
397
+ rootCauses?: number;
398
+ }
399
+
400
+ export interface CleanArmStat {
401
+ runs: number;
402
+ findings: number[];
403
+ corroborated: number[];
404
+ rootCauses: Array<number | undefined>;
405
+ }
406
+
407
+ export interface CleanTally {
408
+ pr: number;
409
+ control: CleanArmStat;
410
+ scout: CleanArmStat;
411
+ }
412
+
413
+ function cleanArmStat(runs: CleanRun[]): CleanArmStat {
414
+ return {
415
+ runs: runs.length,
416
+ findings: runs.map((r) => r.findings),
417
+ corroborated: runs.map((r) => r.corroborated),
418
+ rootCauses: runs.map((r) => r.rootCauses),
419
+ };
420
+ }
421
+
422
+ export function tallyCleanPrs(runs: CleanRun[], prs: number[]): CleanTally[] {
423
+ return prs.map((pr) => {
424
+ const mine = runs.filter((r) => r.pr === pr);
425
+ return {
426
+ pr,
427
+ control: cleanArmStat(mine.filter((r) => r.arm === "control")),
428
+ scout: cleanArmStat(mine.filter((r) => r.arm === "scout")),
429
+ };
430
+ });
431
+ }
432
+
433
+ // Every replicate is listed, never averaged into one number. §1.3 measured six
434
+ // of eight same-head replicate pairs MOVING, with deltas as large as the whole
435
+ // effect the scout is expected to produce — so a mean over two runs would hide
436
+ // exactly the variance that decides whether any of this is readable.
437
+ function cleanCell(stat: CleanArmStat): string {
438
+ if (stat.runs === 0) return "not run";
439
+ return stat.findings
440
+ .map((n, i) => {
441
+ const corroborated = stat.corroborated[i] ?? 0;
442
+ const causes = stat.rootCauses[i];
443
+ return `${n} (${corroborated} corr${
444
+ causes === undefined
445
+ ? ""
446
+ : `, ${causes} cause${causes === 1 ? "" : "s"}`
447
+ })`;
448
+ })
449
+ .join(" · ");
450
+ }
451
+
452
+ export function renderCleanTable(tallies: CleanTally[]): string[] {
453
+ const lines = [
454
+ "| PR | control | scout |",
455
+ "|---|---|---|",
456
+ ...tallies.map(
457
+ (t) => `| ${t.pr} | ${cleanCell(t.control)} | ${cleanCell(t.scout)} |`,
458
+ ),
459
+ "",
460
+ "Findings per run, one entry per replicate, never averaged (§1.3: six of " +
461
+ "eight same-head replicate pairs MOVED, by as much as the whole effect " +
462
+ "the scout is expected to produce). `corr` is refuter-corroborated; " +
463
+ "`causes` is distinct root causes, because one systemic defect at N call " +
464
+ "sites is one finding fanned out (C1).",
465
+ "The question here is RELATIVE and between arms on the same PR: does the " +
466
+ "scout arm produce MORE than the control where the control is quiet? It " +
467
+ "is not a claim that these PRs are defect-free — their `prhero_only` " +
468
+ "rows were never triaged (§2.4).",
469
+ ];
470
+ return lines;
471
+ }
@@ -0,0 +1,80 @@
1
+ // Project a pr-hero findings.json onto Martian's offline candidate shape.
2
+ // Pure: no I/O, no judge, no precision/recall. The judge is theirs; this
3
+ // only makes our artifacts injectable. See docs/martian-bench.md.
4
+
5
+ import type { Finding } from "#review/findings";
6
+
7
+ export interface MartianGoldenComment {
8
+ comment: string;
9
+ severity: string;
10
+ category: string;
11
+ }
12
+
13
+ export interface MartianGoldenPr {
14
+ pr_title: string;
15
+ url: string;
16
+ comments: MartianGoldenComment[];
17
+ }
18
+
19
+ export interface MartianCandidate {
20
+ path: string;
21
+ line: number;
22
+ body: string;
23
+ }
24
+
25
+ export interface MartianReviewComment {
26
+ path: string;
27
+ line: number;
28
+ body: string;
29
+ }
30
+
31
+ export interface MartianReview {
32
+ tool: "pr-hero";
33
+ pr_url: string;
34
+ review_comments: MartianReviewComment[];
35
+ candidates: string[];
36
+ }
37
+
38
+ export function prNumberFromUrl(url: string): number {
39
+ const match = url.match(/\/pull\/(\d+)\/?$/);
40
+ if (match === null) {
41
+ throw new Error(`not a GitHub pull URL: ${url}`);
42
+ }
43
+ return Number(match[1]);
44
+ }
45
+
46
+ export function findingsToCandidates(findings: Finding[]): MartianCandidate[] {
47
+ return findings.map((finding) => ({
48
+ path: finding.path,
49
+ line: finding.line,
50
+ body: finding.claim,
51
+ }));
52
+ }
53
+
54
+ export function findingsToMartianReview(input: {
55
+ prUrl: string;
56
+ findings: Finding[];
57
+ }): MartianReview {
58
+ const mapped = findingsToCandidates(input.findings);
59
+ return {
60
+ tool: "pr-hero",
61
+ pr_url: input.prUrl,
62
+ review_comments: mapped.map((c) => ({
63
+ path: c.path,
64
+ line: c.line,
65
+ body: c.body,
66
+ })),
67
+ candidates: mapped.map((c) => c.body),
68
+ };
69
+ }
70
+
71
+ export function lookupGolden(
72
+ goldens: MartianGoldenPr[],
73
+ pr: number,
74
+ ): MartianGoldenPr {
75
+ const found = goldens.find((g) => prNumberFromUrl(g.url) === pr);
76
+ if (found === undefined) {
77
+ throw new Error(`no Martian golden for PR ${pr}`);
78
+ }
79
+ return found;
80
+ }