crysk 0.3.0 → 0.3.2

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 (71) hide show
  1. package/README.md +11 -5
  2. package/dist/SKILL-6j27707y.md +140 -0
  3. package/dist/SKILL-816621e5.md +74 -0
  4. package/dist/SKILL-bnh7nrjz.md +74 -0
  5. package/dist/SKILL-fv8x6hhx.md +140 -0
  6. package/dist/SKILL-nv32jpc5.md +74 -0
  7. package/dist/SKILL-qnfc8yp3.md +539 -0
  8. package/dist/SKILL-xr56f0b6.md +140 -0
  9. package/dist/SKILL-y8rv8msh.md +134 -0
  10. package/dist/SKILL-ygka1bs0.md +515 -0
  11. package/dist/SKILL-yz6wk92g.md +542 -0
  12. package/dist/ci-admission-09k2ba89.md +126 -0
  13. package/dist/ci-admission-f19qh39t.md +128 -0
  14. package/dist/ci-admission-qk9r9taq.md +124 -0
  15. package/dist/ci-admission-tcqsj7b2.md +126 -0
  16. package/dist/cli.js +2463 -1573
  17. package/dist/index.js +1464 -911
  18. package/dist/materiality-f1qwnvg1.md +27 -0
  19. package/package.json +4 -3
  20. package/prompts/materiality.md +27 -0
  21. package/skills/crysk/SKILL.md +2 -2
  22. package/skills/crysk-ci-setup/SKILL.md +13 -7
  23. package/skills/crysk-ci-setup/references/ci-admission.md +8 -2
  24. package/skills/crysk-loop/SKILL.md +62 -16
  25. package/src/asset-manifest.ts +2 -0
  26. package/src/assets.ts +4 -1
  27. package/src/brand.ts +11 -9
  28. package/src/ci/cli-record.ts +1 -1
  29. package/src/ci/gates.ts +59 -6
  30. package/src/ci/outcome.ts +2 -1
  31. package/src/ci/override.ts +11 -10
  32. package/src/ci/publish.ts +44 -103
  33. package/src/ci/reporter.ts +36 -7
  34. package/src/ci/review-admission.ts +11 -2
  35. package/src/ci/review-levels.ts +21 -0
  36. package/src/ci/setup.ts +1 -2
  37. package/src/commands/post.ts +17 -0
  38. package/src/compare/loop.ts +356 -0
  39. package/src/compare/materiality.ts +266 -0
  40. package/src/compare/noise.ts +166 -0
  41. package/src/diversity/projection.ts +3 -0
  42. package/src/index.ts +1 -1
  43. package/src/model/routing.ts +62 -0
  44. package/src/pr/admission.ts +191 -42
  45. package/src/pr/answered-findings.ts +169 -0
  46. package/src/pr/ci-admission-gate.ts +80 -2
  47. package/src/pr/discovery.ts +17 -5
  48. package/src/pr/inline.ts +15 -1
  49. package/src/pr/plan.ts +5 -0
  50. package/src/pr/post-floor.ts +30 -0
  51. package/src/pr/posting.ts +4 -0
  52. package/src/pr/pr-status.ts +73 -1
  53. package/src/pr/pr.ts +50 -34
  54. package/src/pr/preflight.ts +2 -2
  55. package/src/pr/publish-outcome.ts +4 -0
  56. package/src/pr/review-pr.ts +65 -26
  57. package/src/pr/teardown.ts +1 -1
  58. package/src/rereview/prepare.ts +16 -0
  59. package/src/rereview/state.ts +206 -25
  60. package/src/review/boundary.ts +4 -1
  61. package/src/review/dedupe.ts +48 -4
  62. package/src/review/findings.ts +47 -1
  63. package/src/review/materiality-gate.ts +134 -0
  64. package/src/review/pipeline.ts +521 -41
  65. package/src/review/preflight.ts +69 -0
  66. package/src/review/report.ts +73 -10
  67. package/src/review/review.ts +16 -0
  68. package/src/review/route-preflight.ts +29 -1
  69. package/src/review/run.ts +2 -0
  70. package/src/ui/config.ts +8 -0
  71. package/src/updater.ts +1 -1
@@ -0,0 +1,166 @@
1
+ // The noise baseline's pure half (Stage 2 noise yardstick, step 2).
2
+ //
3
+ // The materiality judge (src/compare/materiality.ts), once it has passed its
4
+ // exam, labels every finding the engine posted on a real PR. The baseline is
5
+ // the share labelled `immaterial`, overall and broken down by severity, tier,
6
+ // hunter, repo and triage tag. The impure half (store read, PR titles, judge
7
+ // spawns) is scripts/noise-baseline.ts.
8
+
9
+ import type { MaterialityLabel } from "#compare/materiality";
10
+
11
+ // One finding as the store holds it, one row per run it appeared in.
12
+ export interface PostedFindingRow {
13
+ repo: string;
14
+ pr: number;
15
+ runId: number;
16
+ findingId: string;
17
+ dedupeKey: string;
18
+ claim: string;
19
+ severity: string;
20
+ tier: string;
21
+ hunter: string;
22
+ triageTag: string | null;
23
+ }
24
+
25
+ // One finding per PR. A re-review re-posts the same defect at a new head;
26
+ // counting it per head would weigh long PRs more than short ones.
27
+ export interface NoiseItem {
28
+ key: string;
29
+ repo: string;
30
+ pr: number;
31
+ claim: string;
32
+ severity: string;
33
+ tier: string;
34
+ hunter: string;
35
+ triageTag: string | null;
36
+ }
37
+
38
+ export function itemKey(repo: string, pr: number, dedupeKey: string): string {
39
+ return `${repo}#${pr}#${dedupeKey}`;
40
+ }
41
+
42
+ // Keeps the first run's copy of each (repo, pr, dedupe key): what the PR
43
+ // author saw first. A triage tag from any copy is kept, the newest winning,
44
+ // because a finding is usually answered on a later head than it was posted.
45
+ export function dedupePostedFindings(rows: PostedFindingRow[]): NoiseItem[] {
46
+ const ordered = [...rows].sort((a, b) => a.runId - b.runId);
47
+ const items = new Map<string, NoiseItem>();
48
+ for (const row of ordered) {
49
+ const key = itemKey(row.repo, row.pr, row.dedupeKey);
50
+ const existing = items.get(key);
51
+ if (existing === undefined) {
52
+ items.set(key, {
53
+ key,
54
+ repo: row.repo,
55
+ pr: row.pr,
56
+ claim: row.claim,
57
+ severity: row.severity,
58
+ tier: row.tier,
59
+ hunter: row.hunter,
60
+ triageTag: row.triageTag,
61
+ });
62
+ } else if (row.triageTag !== null) {
63
+ existing.triageTag = row.triageTag;
64
+ }
65
+ }
66
+ return [...items.values()];
67
+ }
68
+
69
+ export interface NoiseRow {
70
+ group: string;
71
+ judged: number;
72
+ immaterial: number;
73
+ failed: number;
74
+ // immaterial / (judged - failed); null when nothing was labelled.
75
+ noise: number | null;
76
+ }
77
+
78
+ export type NoiseDimension = "severity" | "tier" | "hunter" | "repo" | "triage";
79
+
80
+ export interface NoiseReport {
81
+ overall: NoiseRow;
82
+ by: Record<NoiseDimension, NoiseRow[]>;
83
+ }
84
+
85
+ function groupOf(item: NoiseItem, dimension: NoiseDimension): string {
86
+ switch (dimension) {
87
+ case "severity":
88
+ return item.severity;
89
+ case "tier":
90
+ return item.tier;
91
+ case "hunter":
92
+ return item.hunter;
93
+ case "repo":
94
+ return item.repo;
95
+ case "triage":
96
+ return item.triageTag ?? "(no reply)";
97
+ }
98
+ }
99
+
100
+ function tally(
101
+ group: string,
102
+ items: NoiseItem[],
103
+ labels: Map<string, MaterialityLabel | null>,
104
+ ): NoiseRow {
105
+ let judged = 0;
106
+ let immaterial = 0;
107
+ let failed = 0;
108
+ for (const item of items) {
109
+ if (!labels.has(item.key)) continue;
110
+ judged += 1;
111
+ const label = labels.get(item.key);
112
+ if (label === null) failed += 1;
113
+ else if (label === "immaterial") immaterial += 1;
114
+ }
115
+ const labelled = judged - failed;
116
+ return {
117
+ group,
118
+ judged,
119
+ immaterial,
120
+ failed,
121
+ noise: labelled === 0 ? null : immaterial / labelled,
122
+ };
123
+ }
124
+
125
+ // Failed spawns are left out of the rate, not counted as material or noise:
126
+ // they say nothing about the finding. Their count is reported beside it.
127
+ export function noiseReport(
128
+ items: NoiseItem[],
129
+ labels: Map<string, MaterialityLabel | null>,
130
+ ): NoiseReport {
131
+ const dimensions: NoiseDimension[] = [
132
+ "severity",
133
+ "tier",
134
+ "hunter",
135
+ "repo",
136
+ "triage",
137
+ ];
138
+ const by = {} as Record<NoiseDimension, NoiseRow[]>;
139
+ for (const dimension of dimensions) {
140
+ const groups = new Map<string, NoiseItem[]>();
141
+ for (const item of items) {
142
+ const group = groupOf(item, dimension);
143
+ const list = groups.get(group) ?? [];
144
+ list.push(item);
145
+ groups.set(group, list);
146
+ }
147
+ by[dimension] = [...groups.entries()]
148
+ .map(([group, list]) => tally(group, list, labels))
149
+ .sort((a, b) => b.judged - a.judged || a.group.localeCompare(b.group));
150
+ }
151
+ return { overall: tally("all", items, labels), by };
152
+ }
153
+
154
+ function pct(rate: number | null): string {
155
+ return rate === null ? "n/a" : `${(rate * 100).toFixed(1)}%`;
156
+ }
157
+
158
+ export function renderNoiseReport(report: NoiseReport): string[] {
159
+ const line = (row: NoiseRow) =>
160
+ ` ${row.group.padEnd(34)} ${pct(row.noise).padStart(6)} (${row.immaterial}/${row.judged - row.failed}${row.failed > 0 ? `, ${row.failed} failed` : ""})`;
161
+ const out = ["noise = share judged immaterial", line(report.overall)];
162
+ for (const [dimension, rows] of Object.entries(report.by)) {
163
+ out.push("", `by ${dimension}:`, ...rows.map(line));
164
+ }
165
+ return out;
166
+ }
@@ -35,6 +35,9 @@ export function projectAdjudicationToFindings(
35
35
  severity: canonical.severity,
36
36
  evidence_class: canonical.evidenceClass,
37
37
  refuter_verdict: refuterVerdict,
38
+ causal_disposition: canonical.causalDisposition,
39
+ claim: canonical.claim,
40
+ path: canonical.path,
38
41
  }),
39
42
  hops_used: canonical.hopsUsed,
40
43
  hop_trail: canonical.hopTrail,
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Public API surface; the deep-review lab consumes exactly these exports.
3
3
 
4
4
  export const ENGINE_NAME = "pr-hero";
5
- export const ENGINE_VERSION = "0.3.0";
5
+ export const ENGINE_VERSION = "0.3.2";
6
6
 
7
7
  // errors and git/refs used to reach this surface only through re-exports in
8
8
  // review/preflight.ts; they are exported directly now that those re-exports
@@ -517,6 +517,63 @@ export interface BuildRoutePlanInput {
517
517
  frontmatterModel?: string;
518
518
  defaultModel?: string;
519
519
  };
520
+ // The materiality judge (odd/tasks/materiality-gate.md S14). Present only
521
+ // when the gate is enabled, so a run with the gate off keeps its plan's step
522
+ // keys and fingerprint byte for byte.
523
+ readonly materiality?: true;
524
+ }
525
+
526
+ // The step key the materiality judge runs under in every route plan.
527
+ export const MATERIALITY_STEP_KEY = "materiality";
528
+
529
+ // The judge was measured on Claude sonnet and opus through the Claude Code CLI
530
+ // (same bundled prompt, same bar; both passed, lab bench/METRICS.md
531
+ // 2026-11-01); sonnet was chosen because it costs half for a difference within
532
+ // one run's noise. A judge on any other model or transport is a different,
533
+ // unmeasured judge. So the model
534
+ // is pinned (never `--model`, never the routing default model) and the route is
535
+ // returned only when it lands on the claude-code backend.
536
+ export const MATERIALITY_JUDGE_MODEL = "sonnet";
537
+
538
+ // The judge's route, or undefined when it would not run the measured judge:
539
+ // the routing config sends sonnet to another backend, or cannot resolve it at
540
+ // all (a disabled route, an unmapped snapshot). Never throws: the gate is
541
+ // optional and fails open toward blocking, so a route it cannot use must make
542
+ // the stage stand down, never kill the run. Omitting a non-claude route from
543
+ // the plan also keeps route admission from gating the run on a step that will
544
+ // never spawn.
545
+ export function resolveMaterialityJudgeRoute(
546
+ routingConfig: RoutingConfig | undefined,
547
+ ): ResolvedStepRoute | undefined {
548
+ let step: ResolvedStepRoute;
549
+ try {
550
+ step = resolveStepRoute({
551
+ stepKey: MATERIALITY_STEP_KEY,
552
+ role: "other",
553
+ specModel: MATERIALITY_JUDGE_MODEL,
554
+ routingConfig,
555
+ });
556
+ } catch {
557
+ return undefined;
558
+ }
559
+ return isMeasuredJudgeRoute(step.route) ? step : undefined;
560
+ }
561
+
562
+ // The route the judge was measured on: the Claude Code CLI talking straight to
563
+ // Anthropic. Through any other gateway, spawnModelForClaudeCli passes the
564
+ // mapping's modelSnapshot verbatim as --model, so a claude-code route over
565
+ // openrouter or a configured gateway can run an arbitrary model — a different,
566
+ // unmeasured judge that the pinned prompt hash cannot detect.
567
+ export function isMeasuredJudgeRoute(route: {
568
+ backend: string;
569
+ provider: string;
570
+ gateway?: string;
571
+ }): boolean {
572
+ return (
573
+ route.backend === "claude-code" &&
574
+ route.provider === "anthropic" &&
575
+ (route.gateway === undefined || route.gateway === "direct")
576
+ );
520
577
  }
521
578
 
522
579
  export function buildResolvedRoutePlan(
@@ -571,6 +628,11 @@ export function buildResolvedRoutePlan(
571
628
  }),
572
629
  );
573
630
  }
631
+ if (input.materiality) {
632
+ // No `cliModel` on purpose: `--model sonnet` must not move the judge.
633
+ const judge = resolveMaterialityJudgeRoute(input.routingConfig);
634
+ if (judge !== undefined) stepRoutes.push(judge);
635
+ }
574
636
  return createResolvedRoutePlan(stepRoutes);
575
637
  }
576
638
 
@@ -22,6 +22,7 @@ import {
22
22
  formatWorkflowCommand,
23
23
  } from "#ci/reporter";
24
24
  import { type CiReviewPolicy, ciReviewSkipLabel } from "#ci/review-admission";
25
+ import type { AnsweredFindings } from "#pr/answered-findings";
25
26
  import {
26
27
  fetchCommitStatuses,
27
28
  fetchCommitStatusList,
@@ -282,8 +283,15 @@ export async function recordCiAdmissionGateSkip(input: {
282
283
  // WHY fail closed: no verdict within the cap, a failed read, a head missing from the PR's commits (a
283
284
  // force-push, or a list cut short by GitHub's cap), or no reviewed head writes failure, so a trivial push
284
285
  // cannot pass the gate without a verdict behind it.
285
- // WHY manual-required is always failure: its code was never reviewed, so carrying a green verdict over it
286
- // would be a bypass. Same-head writes nothing, because that head's own status already exists.
286
+ // WHY an exhausted budget and a manual-only policy carry too (budget-exhausted-carry S2, the owner's
287
+ // decision of 2026-10-30, replacing the fixed failure S4 first wrote): every review rule is respected the
288
+ // same way. The once-per-pr, threshold and stop skips already carried a green over an unreviewed push, so a
289
+ // fixed failure here only turned the agent's last fix-up push red and made a human override routine.
290
+ // Same-head writes nothing, because that head's own status already exists.
291
+ // WHY answered findings may turn a carried blocking red green (S3): with no review left, the fixes cannot
292
+ // be verified. A write-access `applied` reply, or a dismissal the CI adjudicator upheld, on every blocking
293
+ // finding of the reviewed head is the most the gate can know, and the green it writes says so
294
+ // (unverifiedFixesDescription), so it never reads as a green a review earned.
287
295
  export type AdmissionStatusReason =
288
296
  | "same-head"
289
297
  | "once-per-pr"
@@ -303,6 +311,10 @@ export interface AdmissionStatusInput {
303
311
  // failure's description does not name a count. Every text isReviewVerdictStatus admits names one, so this
304
312
  // is unreachable through the walk today; it stays because ci-admission-gate.ts still supplies it.
305
313
  priorBlocking: number;
314
+ // Reads the reviewed head's answered blocking findings (pr/answered-findings.ts). Called only when the
315
+ // carried verdict is a blocking red, so every other skip makes no extra API call. Absent means never read.
316
+ // `verdictAt` is when the carried verdict was written (its status's created_at), or null when unknown.
317
+ readAnswered?: (verdictAt: string | null) => Promise<AnsweredFindings | null>;
306
318
  }
307
319
 
308
320
  export interface AdmissionStatusDecision {
@@ -314,23 +326,20 @@ export interface AdmissionStatusDecision {
314
326
  export interface CarriedVerdict {
315
327
  sha: string;
316
328
  statuses: readonly CommitStatusFact[];
329
+ // The PR's commits older than `sha`, newest first, within the walk's cap: where a chained carry's review
330
+ // verdict is looked up (reviewVerdictTime). Absent means none to look at.
331
+ older?: readonly string[];
317
332
  }
318
333
 
319
- type CarriedReason =
320
- | "once-per-pr"
321
- | "below-threshold"
322
- | "low-risk-delta"
323
- | "stopped";
334
+ type CarriedReason = Exclude<AdmissionStatusReason, "same-head">;
324
335
 
336
+ // Every rule that skips a review carries the last verdict the same way (budget-exhausted-carry S2): the
337
+ // rule is respected, so no review runs, and the head reads what the last review decided. Same-head is the
338
+ // one exception: that head's own status already exists.
325
339
  function isCarriedReason(
326
340
  reason: AdmissionStatusReason,
327
341
  ): reason is CarriedReason {
328
- return (
329
- reason === "once-per-pr" ||
330
- reason === "below-threshold" ||
331
- reason === "low-risk-delta" ||
332
- reason === "stopped"
333
- );
342
+ return reason !== "same-head";
334
343
  }
335
344
 
336
345
  // The readers below rewrite a legacy `pr-hero` lead into `crysk` first (canonicalStatusText), so the
@@ -366,6 +375,28 @@ export function carriedBlockingDescription(count: number, sha: string): string {
366
375
  );
367
376
  }
368
377
 
378
+ // The text a skip writes when a carried blocking red has every blocking finding answered and no review is
379
+ // left to verify the fixes (S3, S6). It names the rule that skipped, so a reader sees why nothing verified it.
380
+ // WHY "answered finding(s)" and not "blocking finding(s)": BLOCKING_COUNT reads that prefix as a red count.
381
+ export function unverifiedFixesDescription(
382
+ count: number,
383
+ label: string,
384
+ sha: string,
385
+ ): string {
386
+ return clipStatusDescription(
387
+ `${STATUS_CONTEXT}: ${count} answered finding(s), fixes unverified (${label}); ${CARRIED_FROM}${sha.slice(0, 7)}`,
388
+ );
389
+ }
390
+
391
+ const ANSWERED_COUNT = /^crysk: (\d+) answered finding\(s\), fixes unverified/;
392
+
393
+ function answeredCountIn(description: string): number | null {
394
+ const match = ANSWERED_COUNT.exec(canonicalStatusText(description));
395
+ if (match === null) return null;
396
+ const count = Number(match[1]);
397
+ return count > 0 ? count : null;
398
+ }
399
+
369
400
  // The text a skip writes when it inherits a finished review's partial verdict (some hunters failed).
370
401
  export function carriedPartialDescription(
371
402
  failed: number,
@@ -384,6 +415,8 @@ const CARRY_REASONS: readonly CarriedReason[] = [
384
415
  "below-threshold",
385
416
  "low-risk-delta",
386
417
  "stopped",
418
+ "max-attempts-exhausted",
419
+ "manual-only-policy",
387
420
  ];
388
421
 
389
422
  function finishedSuccessMatches(rawDescription: string): boolean {
@@ -429,6 +462,21 @@ function carriedSuccessMatches(rawDescription: string): boolean {
429
462
  );
430
463
  }
431
464
 
465
+ function unverifiedFixesMatches(rawDescription: string): boolean {
466
+ const description = canonicalStatusText(rawDescription);
467
+ const sha = carriedSha(description);
468
+ const count = answeredCountIn(description);
469
+ return (
470
+ sha !== null &&
471
+ count !== null &&
472
+ CARRY_REASONS.some(
473
+ (reason) =>
474
+ unverifiedFixesDescription(count, ciReviewSkipLabel(reason), sha) ===
475
+ description,
476
+ )
477
+ );
478
+ }
479
+
432
480
  function carriedBlockingMatches(rawDescription: string): boolean {
433
481
  const description = canonicalStatusText(rawDescription);
434
482
  const sha = carriedSha(description);
@@ -499,7 +547,9 @@ export function isReviewVerdictStatus(
499
547
  if (typeof description !== "string") return false;
500
548
  if (status.state === "success") {
501
549
  return (
502
- finishedSuccessMatches(description) || carriedSuccessMatches(description)
550
+ finishedSuccessMatches(description) ||
551
+ carriedSuccessMatches(description) ||
552
+ unverifiedFixesMatches(description)
503
553
  );
504
554
  }
505
555
  if (status.state === "failure") {
@@ -522,6 +572,10 @@ function newestCarriedVerdict(statuses: readonly CommitStatusFact[]) {
522
572
  );
523
573
  }
524
574
 
575
+ export const NOTHING_TO_REVIEW_DESCRIPTION = clipStatusDescription(
576
+ `${STATUS_CONTEXT}: nothing to review — every changed file is excluded`,
577
+ );
578
+
525
579
  function failClosed(label: string): AdmissionStatusDecision {
526
580
  return {
527
581
  state: "failure",
@@ -534,39 +588,27 @@ function failClosed(label: string): AdmissionStatusDecision {
534
588
  // What the gate's skip writes on the new head, or null for no write. `carried` is the verdict the skip
535
589
  // inherits (findCarriedVerdict), or null when none was read or found. A reason that never carries reads none.
536
590
  export function admissionSkipDecision(
537
- input: AdmissionStatusInput & { carried: CarriedVerdict | null },
591
+ input: AdmissionStatusInput & {
592
+ carried: CarriedVerdict | null;
593
+ // The blocking findings of the reviewed head and how many are still open (answeredBlockingFindings),
594
+ // read only when the carried verdict is a blocking red. Null when unread or failed closed.
595
+ answered?: AnsweredFindings | null;
596
+ },
538
597
  ): AdmissionStatusDecision | null {
539
- switch (input.reason) {
540
- case "same-head":
541
- return null;
542
- case "max-attempts-exhausted":
543
- return {
544
- state: "failure",
545
- description: clipStatusDescription(
546
- `${STATUS_CONTEXT}: review budget for this PR is used up — /pr-hero review reviews this head`,
547
- ),
548
- };
549
- case "manual-only-policy":
550
- return {
551
- state: "failure",
552
- description: clipStatusDescription(
553
- `${STATUS_CONTEXT}: review needs a manual trigger (ci_review_policy is manual_only) — /pr-hero review reviews this head`,
554
- ),
555
- };
556
- case "once-per-pr":
557
- case "below-threshold":
558
- case "low-risk-delta":
559
- case "stopped":
560
- break;
561
- }
598
+ if (input.reason === "same-head") return null;
562
599
  const label = ciReviewSkipLabel(input.reason);
563
600
  if (input.carried === null) return failClosed(label);
564
601
  const verdict = newestCarriedVerdict(input.carried.statuses);
565
602
  if (verdict === undefined) return failClosed(label);
566
603
  if (verdict.state === "success") {
604
+ // A carried unverified green stays unverified: chaining it never turns it into a green a review earned.
605
+ const answeredCount = answeredCountIn(verdict.description ?? "");
567
606
  return {
568
607
  state: "success",
569
- description: carriedSuccessDescription(label, input.carried.sha),
608
+ description:
609
+ answeredCount === null
610
+ ? carriedSuccessDescription(label, input.carried.sha)
611
+ : unverifiedFixesDescription(answeredCount, label, input.carried.sha),
570
612
  };
571
613
  }
572
614
  // S5: a partial verdict is red, and it is never read as a blocking count (it has none). Taking the
@@ -587,12 +629,42 @@ export function admissionSkipDecision(
587
629
  blockingCountIn(verdict.description) ??
588
630
  (input.priorBlocking > 0 ? input.priorBlocking : null);
589
631
  if (blocking === null) return failClosed(label);
632
+ // S3, S5: every blocking finding answered unlocks the red, and the read must see at least as many
633
+ // blocking findings as the red counts; fewer means some live where this read cannot see them.
634
+ const answered = input.answered ?? null;
635
+ if (
636
+ answered !== null &&
637
+ answered.open === 0 &&
638
+ answered.blocking > 0 &&
639
+ answered.blocking >= blocking
640
+ ) {
641
+ return {
642
+ state: "success",
643
+ description: unverifiedFixesDescription(
644
+ answered.blocking,
645
+ label,
646
+ input.carried.sha,
647
+ ),
648
+ };
649
+ }
590
650
  return {
591
651
  state: "failure",
592
652
  description: carriedBlockingDescription(blocking, input.carried.sha),
593
653
  };
594
654
  }
595
655
 
656
+ // The carried verdict's blocking count when it is a blocking red (not a partial), else null. The gate reads
657
+ // the answered findings only then, so a carried green or a partial red makes no extra API call.
658
+ export function carriedBlockingCount(
659
+ carried: CarriedVerdict | null,
660
+ ): number | null {
661
+ if (carried === null) return null;
662
+ const verdict = newestCarriedVerdict(carried.statuses);
663
+ if (verdict === undefined || verdict.state !== "failure") return null;
664
+ if (partialCountsIn(verdict.description) !== null) return null;
665
+ return blockingCountIn(verdict.description);
666
+ }
667
+
596
668
  // The most earlier commits the carry reads for a verdict. A push on top of a longer run of commits with
597
669
  // no verdict fails closed rather than walking the whole PR.
598
670
  const CARRY_WALK_CAP = 20;
@@ -624,7 +696,9 @@ async function findCarriedVerdict(input: {
624
696
  spawnFn: input.spawnFn,
625
697
  });
626
698
  if (statuses === null) return null;
627
- if (newestCarriedVerdict(statuses) !== undefined) return { sha, statuses };
699
+ if (newestCarriedVerdict(statuses) !== undefined) {
700
+ return { sha, statuses, older: earlier.slice(earlier.indexOf(sha) + 1) };
701
+ }
628
702
  }
629
703
  return null;
630
704
  }
@@ -664,6 +738,53 @@ async function overrideStandsOnHead(input: {
664
738
  return newest !== undefined && isOverrideStatus(newest);
665
739
  }
666
740
 
741
+ // When the review behind the carried verdict wrote its own verdict, or null when none reads: the stale-reply
742
+ // cutoff (answered-findings.ts isStaleReply). WHY the review's own verdict, not the carried one: a chained
743
+ // skip carries a status a skip wrote later, and a reply made between the review and that skip answers the
744
+ // review; cutting at the skip's time would drop it. The walk goes on down the PR's own commits from the
745
+ // carried one, the carry's source (never the summary's head, which a comment can name), and stops at the
746
+ // first commit with a review's own verdict. A failed read, or none within the cap, is null: fail closed.
747
+ async function reviewVerdictTime(input: {
748
+ operatorRoot: string;
749
+ carried: CarriedVerdict | null;
750
+ spawnFn?: typeof Bun.spawn;
751
+ readStatuses: typeof fetchCommitStatusList;
752
+ }): Promise<string | null> {
753
+ if (input.carried === null) return null;
754
+ const ownIn = (statuses: readonly CommitStatusFact[]) =>
755
+ newestStatusInContext(
756
+ statuses.filter((status) => finishedVerdict(status)),
757
+ COMMIT_STATUS_CONTEXT,
758
+ );
759
+ const first = ownIn(input.carried.statuses);
760
+ if (first !== undefined) return first.created_at ?? null;
761
+ for (const sha of input.carried.older ?? []) {
762
+ const statuses = await input.readStatuses(input.operatorRoot, sha, {
763
+ spawnFn: input.spawnFn,
764
+ });
765
+ if (statuses === null) return null;
766
+ const own = ownIn(statuses);
767
+ if (own !== undefined) return own.created_at ?? null;
768
+ }
769
+ return null;
770
+ }
771
+
772
+ // A verdict a review wrote itself: never a carried, skipped, or override text.
773
+ function finishedVerdict(
774
+ status: Pick<CommitStatusFact, "state" | "description">,
775
+ ): boolean {
776
+ const description = status.description;
777
+ if (typeof description !== "string") return false;
778
+ if (status.state === "success") return finishedSuccessMatches(description);
779
+ if (status.state === "failure") {
780
+ return (
781
+ finishedBlockingMatches(description) ||
782
+ finishedPartialMatches(description)
783
+ );
784
+ }
785
+ return false;
786
+ }
787
+
667
788
  // The status a gate-mode skip writes, or null for none. A size or budget skip is a fixed failure.
668
789
  // An admission skip or manual-required is decided by admissionSkipDecision; the carry's walk runs only
669
790
  // when the verdict carries forward, so same-head and manual-required make no read.
@@ -679,6 +800,12 @@ async function gateSkipDecision(
679
800
  },
680
801
  skip: CliRecord["skip"],
681
802
  ): Promise<AdmissionStatusDecision | null> {
803
+ // #317: nothing reviewable changed. A finished no-op, so the head reads
804
+ // green; the text is no review verdict (isReviewVerdictStatus), so a later
805
+ // skip's carry walks past it to the last real review.
806
+ if (skip === "excluded") {
807
+ return { state: "success", description: NOTHING_TO_REVIEW_DESCRIPTION };
808
+ }
682
809
  if (skip === "size" || skip === "budget") {
683
810
  const request = skipCommitStatusRequest({
684
811
  kind: skip,
@@ -703,7 +830,27 @@ async function gateSkipDecision(
703
830
  readStatuses: input.readStatuses ?? fetchCommitStatusList,
704
831
  })
705
832
  : null;
706
- return admissionSkipDecision({ ...input.admission, carried });
833
+ // S3: a carried blocking red asks whether every blocking finding was answered. A read that throws fails
834
+ // closed: the red stays.
835
+ let answered: AnsweredFindings | null = null;
836
+ if (
837
+ carriedBlockingCount(carried) !== null &&
838
+ input.admission.readAnswered !== undefined
839
+ ) {
840
+ try {
841
+ answered = await input.admission.readAnswered(
842
+ await reviewVerdictTime({
843
+ operatorRoot: input.operatorRoot,
844
+ carried,
845
+ spawnFn: input.spawnFn,
846
+ readStatuses: input.readStatuses ?? fetchCommitStatusList,
847
+ }),
848
+ );
849
+ } catch {
850
+ answered = null;
851
+ }
852
+ }
853
+ return admissionSkipDecision({ ...input.admission, carried, answered });
707
854
  }
708
855
 
709
856
  // The skip kind a plan stands for, read from the status its outputs carry. The
@@ -719,6 +866,8 @@ function cliSkipKindOf(plan: CiGateSkipPlan): CliRecord["skip"] {
719
866
  return "coverage";
720
867
  case "manual-required":
721
868
  return "manual-required";
869
+ case "skipped-excluded":
870
+ return "excluded";
722
871
  default:
723
872
  return undefined;
724
873
  }
@@ -755,7 +904,7 @@ export async function publishCiSkip(input: {
755
904
  // The record names the skip kind only. The plan carries no head, so none is
756
905
  // written: the publisher takes the head from the trigger's record.
757
906
  const skip = cliSkipKindOf(input.plan);
758
- if (input.post) {
907
+ if (input.post && input.plan.postsComment !== false) {
759
908
  // Repost, never edit in place: an edited notice is invisible on GitHub,
760
909
  // so a later push that was skipped again looked like nothing happened.
761
910
  // See repostMarkedPrComment's WHY. A repost that throws is the notice's own