crysk 0.3.2 → 0.4.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 (66) hide show
  1. package/README.md +52 -32
  2. package/dist/SKILL-12as0f3q.md +74 -0
  3. package/dist/SKILL-2h445snn.md +140 -0
  4. package/dist/SKILL-6vy283pt.md +140 -0
  5. package/dist/SKILL-dsnffnfp.md +140 -0
  6. package/dist/SKILL-ebn0fqaq.md +140 -0
  7. package/dist/SKILL-gnrbph72.md +140 -0
  8. package/dist/SKILL-kq0xejn3.md +553 -0
  9. package/dist/SKILL-qaqsbygw.md +66 -0
  10. package/dist/SKILL-vws0aqb8.md +553 -0
  11. package/dist/ci-admission-a6d0wk1c.md +128 -0
  12. package/dist/ci-admission-t0f5qwth.md +128 -0
  13. package/dist/cli.js +14567 -14177
  14. package/dist/index.js +270 -56
  15. package/dist/review-refuter-btpgnkcd.md +77 -0
  16. package/package.json +2 -2
  17. package/prompts/default/PROVENANCE.md +1 -0
  18. package/prompts/default/review-refuter.md +6 -0
  19. package/skills/crysk/SKILL.md +3 -3
  20. package/skills/crysk-ci-setup/SKILL.md +4 -4
  21. package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
  22. package/skills/crysk-loop/SKILL.md +19 -8
  23. package/skills/crysk-pr/SKILL.md +1 -1
  24. package/src/assets.ts +2 -2
  25. package/src/ci/gates.ts +9 -6
  26. package/src/ci/outcome.ts +4 -4
  27. package/src/ci/platform-config.ts +127 -0
  28. package/src/ci/platform-report.ts +702 -0
  29. package/src/ci/platform.ts +449 -0
  30. package/src/ci/reporter.ts +9 -7
  31. package/src/ci/review-admission.ts +8 -4
  32. package/src/ci/setup.ts +112 -9
  33. package/src/commands/ci-setup.ts +21 -18
  34. package/src/commands/init.ts +21 -12
  35. package/src/compare/loop.ts +9 -1
  36. package/src/compare/martian-adapter.ts +1 -1
  37. package/src/doctor.ts +48 -29
  38. package/src/index.ts +1 -1
  39. package/src/menu-context.ts +1 -1
  40. package/src/pr/admission.ts +53 -11
  41. package/src/pr/ci-admission-gate.ts +2 -1
  42. package/src/pr/finding-state-record.ts +58 -0
  43. package/src/pr/gate-record.ts +22 -0
  44. package/src/pr/inline.ts +3 -0
  45. package/src/pr/posting.ts +4 -0
  46. package/src/pr/pr-status.ts +27 -7
  47. package/src/pr/pr.ts +39 -8
  48. package/src/pr/preflight.ts +43 -1
  49. package/src/pr/publish-outcome.ts +10 -2
  50. package/src/pr/review-pr.ts +5 -3
  51. package/src/pr/target.ts +16 -3
  52. package/src/rereview/classify.ts +4 -0
  53. package/src/rereview/prepare.ts +47 -22
  54. package/src/rereview/state.ts +34 -8
  55. package/src/review/boundary.ts +2 -1
  56. package/src/review/materiality-gate.ts +25 -1
  57. package/src/review/pipeline.ts +60 -15
  58. package/src/review/preflight.ts +132 -28
  59. package/src/review/prompt-set.ts +12 -8
  60. package/src/review/report.ts +34 -14
  61. package/src/review/review.ts +14 -5
  62. package/src/review/run.ts +54 -18
  63. package/src/security/published-text.ts +161 -0
  64. package/src/triage/triage.ts +2 -1
  65. package/src/updater.ts +1 -1
  66. package/src/wizard.ts +35 -9
@@ -0,0 +1,58 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const FINDING_STATE_FILE = "finding-state.json";
5
+
6
+ // Which findings stay open after this run, under the ids that last across runs (R###). findings.json
7
+ // cannot say: it holds only this run's findings, renumbered each run, and a finding missing from it
8
+ // may simply not have been looked at. Only ids and statuses: nothing here can quote the customer's
9
+ // code, so it may leave the runner in metadata-only mode too.
10
+ export interface FindingStateRecord {
11
+ open: { id: string; status: string; tier: string }[];
12
+ // This run's finding id -> its stable id.
13
+ fresh: Record<string, string>;
14
+ // The stable ids this run verified gone. Absence never means resolved.
15
+ resolved: string[];
16
+ // The stable ids a stronger finding replaced this run, under a new id. Not fixed, so not resolved.
17
+ superseded: string[];
18
+ // Rows the state block's size cap left out, whose state is therefore unknown.
19
+ dropped: number;
20
+ }
21
+
22
+ export function buildFindingStateRecord(input: {
23
+ rows: readonly { id: string; status: string; tier: string }[];
24
+ freshFindingIds: readonly string[];
25
+ freshIds: readonly (string | undefined)[];
26
+ resolvedIds: readonly string[];
27
+ supersededIds: readonly string[];
28
+ dropped: number;
29
+ }): FindingStateRecord {
30
+ const fresh: Record<string, string> = {};
31
+ input.freshFindingIds.forEach((findingId, index) => {
32
+ const stable = input.freshIds[index];
33
+ if (stable !== undefined) fresh[findingId] = stable;
34
+ });
35
+ return {
36
+ open: input.rows.map(({ id, status, tier }) => ({ id, status, tier })),
37
+ fresh,
38
+ resolved: [...input.resolvedIds],
39
+ superseded: [...input.supersededIds],
40
+ dropped: input.dropped,
41
+ };
42
+ }
43
+
44
+ // The report to the platform runs as another process, so it reads this file. A failure to write only
45
+ // costs the platform this detail; it must not change the review's result.
46
+ export function writeFindingStateRecord(
47
+ runDir: string,
48
+ record: FindingStateRecord,
49
+ ): void {
50
+ try {
51
+ writeFileSync(
52
+ path.join(runDir, FINDING_STATE_FILE),
53
+ `${JSON.stringify(record)}\n`,
54
+ );
55
+ } catch {
56
+ // see above
57
+ }
58
+ }
@@ -0,0 +1,22 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ export const GATE_RECORD_FILE = "gate.json";
5
+
6
+ // The count the `crysk` status is decided on: this run's blocking findings plus earlier ones still
7
+ // open. findings.json holds only this run's, so a same-head re-review there reads zero while the
8
+ // status stays red. The report to the platform runs as another process, so it reads this file. A
9
+ // failure to write only costs the platform the number; it must not change the review's result.
10
+ export function writeGateRecord(
11
+ runDir: string,
12
+ unresolvedBlocking: number,
13
+ ): void {
14
+ try {
15
+ writeFileSync(
16
+ path.join(runDir, GATE_RECORD_FILE),
17
+ `${JSON.stringify({ unresolved_blocking: unresolvedBlocking })}\n`,
18
+ );
19
+ } catch {
20
+ // see above
21
+ }
22
+ }
package/src/pr/inline.ts CHANGED
@@ -14,6 +14,7 @@
14
14
  import type { PrHeroFindingRef } from "#compare/compare";
15
15
  import { extractAnchor } from "#review/root-cause";
16
16
  import { diffRecordPath, splitDiffRecords } from "#review/size-gate";
17
+ import type { FindingStateRecord } from "./finding-state-record";
17
18
  import { claimFingerprint, type ParsedFindingMarker } from "./preflight";
18
19
 
19
20
  // The comparison ref plus the proof_refs posting needs to re-anchor an
@@ -447,6 +448,8 @@ export function buildPostPlan(input: {
447
448
  // ---------------------------------------------------------------------------
448
449
 
449
450
  export interface InlinePostOutcome {
451
+ // Absent when this post wrote no state block, so nothing can be said about findings across runs.
452
+ findingState?: FindingStateRecord;
450
453
  reviewOutcome: "posted" | "demoted";
451
454
  reviewFindingCount: number;
452
455
  // Always [] this slice (issues #16/#17): findings no longer POST as
package/src/pr/posting.ts CHANGED
@@ -21,6 +21,7 @@ import type { CiMode } from "#pr/preflight";
21
21
  import type { RereviewProvenance } from "#rereview/prepare";
22
22
  import type { FindingsDocument } from "#review/findings";
23
23
  import { log } from "#ui/primitives";
24
+ import { writeFindingStateRecord } from "./finding-state-record";
24
25
 
25
26
  export interface PostingStageResult {
26
27
  posted: InlinePostOutcome | null;
@@ -91,6 +92,9 @@ export async function postFindingsIfEnabled(input: {
91
92
  if (posted) {
92
93
  input.onDelivered?.();
93
94
  await writePostReceipt(input.runDir, input.pr, input.headSha, posted);
95
+ if (posted.findingState !== undefined) {
96
+ writeFindingStateRecord(input.runDir, posted.findingState);
97
+ }
94
98
  log(
95
99
  `posted: review ${posted.reviewOutcome} (${posted.reviewFindingCount} ` +
96
100
  `finding(s)), ${posted.outsideDiffCount} outside diff, ` +
@@ -24,6 +24,7 @@ import {
24
24
  findMarkedCommentId,
25
25
  IN_FLIGHT_TTL_MS,
26
26
  isInFlightCommitStatus,
27
+ isManualReviewHold,
27
28
  latestStatusInContext,
28
29
  type ParsedFindingMarker,
29
30
  parseFindingMarker,
@@ -573,6 +574,17 @@ function decideNext(
573
574
  (a) => a.finding.blocking && a.finding.live_on_head,
574
575
  );
575
576
  if (gate.state === "pending") {
577
+ // Stage 2 #12: a capped rule (the budget used up, or manual_only) held the head instead of carrying a
578
+ // green no review saw. No run will review it on its own, so waiting is wrong, and so is a routine
579
+ // forced review: a human decides between verifying the head and merging it unverified.
580
+ if (
581
+ isManualReviewHold({ state: gate.state, description: gate.description })
582
+ ) {
583
+ return {
584
+ next_action: "override-or-fix",
585
+ reason: `The gate holds this head for a manual review: the automatic review budget is used up, or the review policy is manual (ci_review_policy is manual_only), so no review read it and none will on its own. Comment ${commandHint(REVIEW_COMMAND, "")} to verify it, or ${commandHint(OVERRIDE_COMMAND, "")} to merge it unverified.`,
586
+ };
587
+ }
576
588
  if (gate.pending_in_flight) {
577
589
  return {
578
590
  next_action: "wait",
@@ -600,11 +612,21 @@ function decideNext(
600
612
  };
601
613
  }
602
614
  if (gate.state === "success") {
615
+ // PR #472/#475: a finding that lives only in the summary (outside the diff) has no thread, so nothing
616
+ // can be owed on it, but a done that does not name it let the loop merge without reading it. Every
617
+ // done below carries this note.
618
+ const summaryOnly = analyzed.filter(
619
+ (a) => a.finding.comment_id === null,
620
+ ).length;
621
+ const summaryNote =
622
+ summaryOnly === 0
623
+ ? ""
624
+ : ` ${summaryOnly} finding(s) live only in the summary comment (outside the diff, no thread to reply in); read them there before merging.`;
603
625
  // An override is a human's unlock of the head, so it stays done whatever the findings say.
604
626
  if (gate.override.active) {
605
627
  return {
606
628
  next_action: "done",
607
- reason: `The gate is green through an override by @${gate.override.by ?? "an unknown login"}; nothing is owed on this head.`,
629
+ reason: `The gate is green through an override by @${gate.override.by ?? "an unknown login"}; nothing is owed on this head.${summaryNote}`,
608
630
  };
609
631
  }
610
632
  // A partial review of this head (some reviewers failed) is not a finished review, and the
@@ -635,7 +657,7 @@ function decideNext(
635
657
  ) {
636
658
  return {
637
659
  next_action: "done",
638
- reason: `The gate is green on answered findings no review verified (${gate.description}); the PR is ready to merge, or comment ${commandHint(REVIEW_COMMAND, "")} for another review.`,
660
+ reason: `The gate is green on answered findings no review verified (${gate.description}); the PR is ready to merge, or comment ${commandHint(REVIEW_COMMAND, "")} for another review.${summaryNote}`,
639
661
  };
640
662
  }
641
663
  // #317: no review ran, so the reason must not read as a review that passed.
@@ -644,14 +666,12 @@ function decideNext(
644
666
  ) {
645
667
  return {
646
668
  next_action: "done",
647
- reason:
648
- "Every changed file on this head is excluded from review, so there was nothing to review; nothing is owed.",
669
+ reason: `Every changed file on this head is excluded from review, so there was nothing to review; nothing is owed.${summaryNote}`,
649
670
  };
650
671
  }
651
672
  return {
652
673
  next_action: "done",
653
- reason:
654
- "The review on this head passed the gate, and every finding on this head has a reply.",
674
+ reason: `The review on this head passed the gate, and every finding on this head has a reply.${summaryNote}`,
655
675
  };
656
676
  }
657
677
  // failure: the blocking findings on this head decide between triage, fix, and override.
@@ -719,7 +739,7 @@ function decideNext(
719
739
  next_action: "fix",
720
740
  reason:
721
741
  open === 0 && unseen === 0
722
- ? "Every live blocking finding is answered and a review rule skipped this head; push the fix. If a rule skips that push too, the gate reads the replies on it and can turn green, marked unverified; otherwise the review verifies it."
742
+ ? "Every live blocking finding is answered and a review rule skipped this head; push the fix. If a rule skips that push too, the gate reads the replies on it and can turn green, marked unverified, or, under a used-up budget or manual_only, hold the head for a manual review; otherwise the review verifies it."
723
743
  : `A live blocking finding is tagged applied, but ${open + unseen} blocking finding(s) are still open (deferred, misclassified, a dismissal not upheld, a reply at another head, or one this read cannot see), so replies alone will not unlock the carried red; push the fix, and answer or fix the rest.`,
724
744
  };
725
745
  }
package/src/pr/pr.ts CHANGED
@@ -74,6 +74,7 @@ import {
74
74
  WORKFLOW_FILE_NAME,
75
75
  } from "../brand";
76
76
  import { CliError } from "../errors";
77
+ import { buildFindingStateRecord } from "./finding-state-record";
77
78
  import {
78
79
  buildPostPlan,
79
80
  computeDroppedFindingIds,
@@ -1310,7 +1311,7 @@ const PR_ISSUE_COMMENTS_QUERY =
1310
1311
  "repository(owner:$repoOwner,name:$repoName){pullRequest(number:$number){" +
1311
1312
  "comments(first:100,after:$cursor){" +
1312
1313
  "pageInfo{endCursor hasNextPage}" +
1313
- "nodes{databaseId body createdAt updatedAt author{login}}}}}}";
1314
+ "nodes{databaseId body createdAt updatedAt author{login __typename}}}}}}";
1314
1315
 
1315
1316
  const PR_REVIEW_COMMENTS_QUERY =
1316
1317
  "query($repoOwner:String!,$repoName:String!,$number:Int!,$cursor:String){" +
@@ -1609,7 +1610,7 @@ function issueCommentsFromNodes(nodes: unknown[]): {
1609
1610
  if (id === null) continue;
1610
1611
  comments.push({
1611
1612
  id,
1612
- user: graphqlLogin(record.author),
1613
+ user: graphqlReviewLogin(record.author),
1613
1614
  body: typeof record.body === "string" ? record.body : "",
1614
1615
  ...(typeof record.createdAt === "string"
1615
1616
  ? { created_at: record.createdAt }
@@ -3133,31 +3134,48 @@ export async function postInlineFindings(input: {
3133
3134
  // WHY one merge function for both writes: the S1 re-merge reruns it with a
3134
3135
  // PATCH-sized budget and the SAME inputs, so the kept ids and hw cannot
3135
3136
  // drift between the POST and the PATCH.
3137
+ // WHY a first review writes the block too: an outside-diff finding has no
3138
+ // comment of its own, so the block is its only machine-readable copy. A
3139
+ // first review without one left `crysk status` blind to those findings
3140
+ // (PR #472: four advisories, status read none).
3141
+ // WHY not every post without framing (PR #475 R001): over another head's
3142
+ // summary, a block holding only this run's findings would replace the
3143
+ // marker recovery the next review relies on, so still-open findings of
3144
+ // older heads would stop being priors. Such a post writes the block only
3145
+ // as a same-head re-post, which carries the previous rows. A re-review
3146
+ // whose prior summary vanished has its framing dropped and stays
3147
+ // state-less: that framing names threads that no longer exist.
3148
+ const stateFramed =
3149
+ framing !== undefined ||
3150
+ (input.rereview === undefined &&
3151
+ (existingSummaryId === null || previousState?.headSha === doc.head_sha));
3136
3152
  const mergeStateWithBudget = (
3137
3153
  stateBudget: number,
3138
3154
  ): MergedState | undefined =>
3139
- framing === undefined
3155
+ !stateFramed
3140
3156
  ? undefined
3141
3157
  : mergeStateFindings({
3142
3158
  headSha: doc.head_sha,
3143
3159
  reviews: postedReviewCount,
3144
- live: framing.live,
3160
+ live: framing?.live ?? [],
3145
3161
  previous: previousState,
3146
3162
  previousHead: previousState?.headSha ?? null,
3147
3163
  retiredIds: [
3148
- ...(framing.resolved_ids ?? []),
3149
- ...(framing.worsened ?? []).map((w) => w.priorId),
3164
+ ...(framing?.resolved_ids ?? []),
3165
+ ...(framing?.worsened ?? []).map((w) => w.priorId),
3150
3166
  ],
3151
3167
  // The priors this run's gate count released through a materiality
3152
3168
  // demotion, recorded on the rereview block by the pipeline, so the
3153
3169
  // state the next run reads agrees with this run's count.
3154
- ...(input.rereview?.materiality_released_ids === undefined
3170
+ ...(framing?.materiality_released_ids === undefined
3155
3171
  ? {}
3156
- : { releasedIds: input.rereview.materiality_released_ids }),
3172
+ : { releasedIds: framing.materiality_released_ids }),
3157
3173
  fresh: freshFindings,
3158
3174
  stateBudget,
3159
3175
  });
3160
3176
  const merged = mergeStateWithBudget(stateBlockBudget(referenceBody.length));
3177
+ // What was finally written, for the record the platform reads: a re-merge below may drop rows.
3178
+ let writtenState = merged;
3161
3179
 
3162
3180
  const renderWithState = (
3163
3181
  delta: PrCommentDelta,
@@ -3361,6 +3379,7 @@ export async function postInlineFindings(input: {
3361
3379
  stateBlockBudget(bodyWithoutState.length),
3362
3380
  );
3363
3381
  patchBody = renderPatch(reMerged, 0);
3382
+ writtenState = reMerged;
3364
3383
  }
3365
3384
  if (patchBody.length > GITHUB_ISSUE_COMMENT_MAX) {
3366
3385
  process.stdout.write(
@@ -3515,6 +3534,18 @@ export async function postInlineFindings(input: {
3515
3534
  commentUrls: commentUrlByFindingId,
3516
3535
  movedHeadSha,
3517
3536
  ...(closingCommentId === undefined ? {} : { closingCommentId }),
3537
+ ...(writtenState === undefined
3538
+ ? {}
3539
+ : {
3540
+ findingState: buildFindingStateRecord({
3541
+ rows: writtenState.rows,
3542
+ freshFindingIds: postedDoc.findings.map((f) => f.id),
3543
+ freshIds: writtenState.freshIds,
3544
+ resolvedIds: framing?.resolved_ids ?? [],
3545
+ supersededIds: (framing?.worsened ?? []).map((w) => w.priorId),
3546
+ dropped: writtenState.dropped,
3547
+ }),
3548
+ }),
3518
3549
  };
3519
3550
  }
3520
3551
 
@@ -1007,10 +1007,51 @@ export function latestStatusInContext(
1007
1007
  return latest;
1008
1008
  }
1009
1009
 
1010
+ // The pending a gate skip writes when a rule that caps automatic reviews (the budget is used up, or the
1011
+ // policy is manual_only) would otherwise carry a green no review saw (ROADMAP Stage 2 #12). It holds the
1012
+ // head until a human asks for a review or an override. `label` is the rule (ciReviewSkipLabel); `sha` is
1013
+ // the commit whose verdict it held, so the next skip's walk can jump there (heldVerdictSha).
1014
+ export function manualReviewHoldDescription(
1015
+ label: string,
1016
+ sha: string,
1017
+ ): string {
1018
+ return clipStatusDescription(
1019
+ `${STATUS_CONTEXT}: waiting for a manual review (${label}); carried from ${sha.slice(0, 7)} — /pr-hero review or /pr-hero override`,
1020
+ );
1021
+ }
1022
+
1023
+ const MANUAL_REVIEW_HOLD = /^crysk: waiting for a manual review \(/;
1024
+ const HELD_VERDICT =
1025
+ /^crysk: waiting for a manual review \((.+)\); carried from ([0-9a-f]{7}) — /;
1026
+
1027
+ // Whether a pending status is the gate's hold, not a running review. No run holds it, so no in-flight
1028
+ // reader may wait on it: it lasts until a human acts, not until a run ends.
1029
+ export function isManualReviewHold(
1030
+ status: Pick<CommitStatusFact, "state" | "description">,
1031
+ ): boolean {
1032
+ return (
1033
+ status.state === "pending" &&
1034
+ MANUAL_REVIEW_HOLD.test(status.description ?? "")
1035
+ );
1036
+ }
1037
+
1038
+ // The short sha a hold names, or null. WHY the text is rebuilt: the builder above is the only authority on
1039
+ // a hold's exact text, so a description that only resembles one never redirects the carry's walk.
1040
+ export function heldVerdictSha(
1041
+ status: Pick<CommitStatusFact, "state" | "description">,
1042
+ ): string | null {
1043
+ if (!isManualReviewHold(status)) return null;
1044
+ const description = status.description ?? "";
1045
+ const match = HELD_VERDICT.exec(description);
1046
+ if (match === null) return null;
1047
+ const [, label, sha] = match as unknown as [string, string, string];
1048
+ return manualReviewHoldDescription(label, sha) === description ? sha : null;
1049
+ }
1050
+
1010
1051
  // Latest status for our context, by created_at — GitHub's list is usually
1011
1052
  // newest-first, but the watcher must not depend on that. A pending older
1012
1053
  // than the TTL is NOT in-flight: the process likely died, and the next tick
1013
- // must be allowed to launch.
1054
+ // must be allowed to launch. A manual-review hold is never in flight.
1014
1055
  // In-flight in ANY of the given contexts: each context's own latest status is
1015
1056
  // judged, so a fresh pending on one never hides behind a settled one on another.
1016
1057
  // The default reads the gate alone, which is a `--ci` run's yield. A non-CI run
@@ -1024,6 +1065,7 @@ export function isInFlightCommitStatus(
1024
1065
  return contexts.some((context) => {
1025
1066
  const latest = latestStatusInContext(statuses, context);
1026
1067
  if (latest === null || latest.state !== "pending") return false;
1068
+ if (isManualReviewHold(latest)) return false;
1027
1069
  const createdMs = Date.parse(latest.created_at);
1028
1070
  if (Number.isNaN(createdMs)) return false;
1029
1071
  return nowMs - createdMs < ttlMs;
@@ -105,7 +105,9 @@ export interface PublishRunOutcomeInput {
105
105
  // (settleCommitStatusAndLedger) reads this count in reviewPr()'s finally,
106
106
  // and a throw later in this tail must not leave it unknown. The count is the
107
107
  // gate's UNRESOLVED blocking count (rereview/state.ts), not this run's survivors.
108
- onBlockingCount: (count: number) => void;
108
+ // `conclusive` is false for a zero the gate itself ignores (commitStatusCompletion),
109
+ // because a reviewer that never ran or failed might have been the one to block.
110
+ onBlockingCount: (count: number, conclusive: boolean) => void;
109
111
  // Test-only seam (default: the real postFindingsIfEnabled). The posting stage
110
112
  // reaches gh with no offline seam of its own, so the suite passes a fake that
111
113
  // rejects or resolves, the way it drives the throw and the delivery point.
@@ -153,7 +155,13 @@ export async function publishRunOutcome(
153
155
  doc.findings,
154
156
  result.gatePriors ?? [],
155
157
  );
156
- input.onBlockingCount(blockingCount);
158
+ input.onBlockingCount(
159
+ blockingCount,
160
+ blockingCount > 0 ||
161
+ (result.sessionFailed !== true &&
162
+ result.noReviewerRan !== true &&
163
+ (result.hunterFailures?.length ?? 0) === 0),
164
+ );
157
165
  const reportPath = await writeRunReport({
158
166
  runDir: input.runDir,
159
167
  doc,
@@ -92,7 +92,7 @@ import {
92
92
  resolveMaxConcurrentSteps,
93
93
  resolveSharedPrefix,
94
94
  } from "#review/preflight";
95
- import { estimateCost } from "#review/report";
95
+ import { code, estimateCost } from "#review/report";
96
96
  import {
97
97
  pipelineConsolidateInput,
98
98
  pipelineMaterialityInput,
@@ -121,6 +121,7 @@ import { acquirePidLock } from "../home";
121
121
  import { worktreeLockPath } from "../home-preflight";
122
122
  import { readLocalIgnoreRules } from "../ignore-read";
123
123
  import type { ProductionRuntime } from "../production-runtime";
124
+ import { writeGateRecord } from "./gate-record";
124
125
 
125
126
  // The CLI's record for a pipeline whose every hunter failed (cli.json,
126
127
  // odd/tasks/agent-first-ci.md, T2c). reviewPr writes it right after the pipeline's
@@ -228,7 +229,7 @@ export async function postAdjudicationReplies(input: {
228
229
  });
229
230
  const evidence =
230
231
  entry.evidence.length > 0
231
- ? `\n\nEvidence:\n${entry.evidence.map((e) => `- \`${e}\``).join("\n")}`
232
+ ? `\n\nEvidence:\n${entry.evidence.map((e) => `- ${code(e)}`).join("\n")}`
232
233
  : "";
233
234
  const body = `${marker}\n\n${ADJUDICATION_BADGES[entry.verdict]}${evidence}`;
234
235
  let commentId: number | undefined;
@@ -916,8 +917,9 @@ export async function reviewPr(
916
917
  onPosted: (outcome) => {
917
918
  posted = outcome;
918
919
  },
919
- onBlockingCount: (count) => {
920
+ onBlockingCount: (count, conclusive) => {
920
921
  blockingCount = count;
922
+ if (conclusive) writeGateRecord(runDir, count);
921
923
  },
922
924
  });
923
925
  // T5b: the verdicts are posted only after the review itself published.
package/src/pr/target.ts CHANGED
@@ -49,8 +49,10 @@ import type { estimateCost } from "#review/report";
49
49
  import {
50
50
  type LoadedRunConfig,
51
51
  loadRunConfig,
52
- resolveGotchasPath,
52
+ NO_INSTRUCTIONS_NOTICE,
53
53
  resolvePromptSet,
54
+ resolveReviewInstructions,
55
+ shadowedGotchasNotice,
54
56
  } from "#review/run";
55
57
  import type { SizeGateConfig } from "#review/size-gate";
56
58
  import type { ReviewSpec } from "#review/spec";
@@ -142,7 +144,8 @@ export interface ResolvedPrPromptSet {
142
144
  spec: ReviewSpec;
143
145
  agentFiles: Map<string, ParsedAgent>;
144
146
  promptSet: PromptSetIdentity;
145
- gotchasPath: string;
147
+ // Undefined when the repo has no REVIEW.md or gotchas file (S3).
148
+ gotchasPath: string | undefined;
146
149
  }
147
150
 
148
151
  // Step 1's second half: the CI budget ceiling (+ its notices), then the
@@ -216,10 +219,20 @@ export async function resolvePrPromptSetAndBudget(params: {
216
219
  params.options,
217
220
  params.loaded,
218
221
  );
219
- const gotchasPath = resolveGotchasPath(
222
+ const instructions = resolveReviewInstructions(
220
223
  params.options.gotchas,
221
224
  params.operatorRoot,
222
225
  );
226
+ const notice =
227
+ instructions.shadowed !== undefined
228
+ ? shadowedGotchasNotice(instructions.shadowed)
229
+ : instructions.path === undefined
230
+ ? NO_INSTRUCTIONS_NOTICE
231
+ : undefined;
232
+ if (notice !== undefined) {
233
+ log(params.isCi ? formatWorkflowCommand("notice", notice) : notice);
234
+ }
235
+ const gotchasPath = instructions.path;
223
236
  return {
224
237
  ciBudgetCeiling,
225
238
  ciSizeLimits,
@@ -107,6 +107,10 @@ export interface PriorRecord {
107
107
  channel: FindingChannel;
108
108
  locs: readonly string[];
109
109
  claim: string;
110
+ // The fingerprint of the claim as first written, which is what the posted
111
+ // marker carries. `claim` here may be its published form, so hashing it would
112
+ // not match. Absent when the prior has no claim to fingerprint.
113
+ c?: string;
110
114
  triage: PriorTriage | null;
111
115
  // Case B rule 7b: any new reply on the prior thread, including tags
112
116
  // other than a newly-applied `applied` (that one is rule 7).
@@ -4,7 +4,7 @@
4
4
  // The case machine itself stays in rereview/plan.ts.
5
5
 
6
6
  import { normalizePath } from "#compare/compare";
7
- import { claimFingerprint } from "#pr/preflight";
7
+ import { claimFingerprint, parseFindingMarker } from "#pr/preflight";
8
8
  import type { Severity } from "#review/findings";
9
9
  import { parseFindingCommentBadge } from "#review/report";
10
10
  import {
@@ -617,20 +617,20 @@ export function priorsFromStateFindings(
617
617
  channel: finding.channel,
618
618
  locs: finding.locs,
619
619
  claim: finding.claim,
620
+ c: finding.c,
620
621
  triage: null,
621
622
  newThreadReply: false,
622
623
  }));
623
624
  }
624
625
 
625
626
  // #206's fix: the fallback that runs whenever the previous summary's
626
- // `pr-hero-state` block cannot supply priors — missing, unparseable, or (the
627
- // ROUTINE case, not a rare one: a FIRST review never writes a state block at
628
- // all, see `postInlineFindings`'s `framing === undefined` branch in
629
- // src/pr/pr.ts) simply absent because this is the PR's second review. It
630
- // used to hardcode `sev: "WARNING"` / `tier: "advisory"` / `claim: ""` for
631
- // EVERY prior here — silently downgrading a live BLOCKER to a warning on
632
- // every second review of every PR, and collapsing every claim-less row onto
633
- // `claimFingerprint("")`'s shared constant.
627
+ // `pr-hero-state` block cannot supply priors — missing or unparseable. Before
628
+ // 2026-11-04 a FIRST review never wrote a state block, so this was the
629
+ // routine path of every second review; summaries posted before then still
630
+ // reach it. It used to hardcode `sev: "WARNING"` / `tier: "advisory"` /
631
+ // `claim: ""` for EVERY prior here — silently downgrading a live BLOCKER to a
632
+ // warning on every second review of every PR, and collapsing every claim-less
633
+ // row onto `claimFingerprint("")`'s shared constant.
634
634
  //
635
635
  // `body` is the posted comment's raw text (the marker line alone carries no
636
636
  // sev/tier/claim — `findingMarker` signs only the claim's fingerprint, never
@@ -651,6 +651,7 @@ export function priorsFromPostedMarkers(
651
651
  ): PriorRecord[] {
652
652
  return posted.map((item, i) => {
653
653
  const recovered = parseFindingCommentBadge(item.body);
654
+ const c = recovered === null ? undefined : parseFindingMarker(item.body)?.c;
654
655
  return {
655
656
  id: `R${String(i + 1).padStart(3, "0")}`,
656
657
  sev: recovered?.sev ?? SEVERITY_UNRECOVERABLE,
@@ -658,6 +659,7 @@ export function priorsFromPostedMarkers(
658
659
  channel: item.channel,
659
660
  locs: [`${item.path}:${item.line}`],
660
661
  claim: recovered?.claim ?? "",
662
+ ...(c === undefined ? {} : { c }),
661
663
  triage: null,
662
664
  newThreadReply: false,
663
665
  };
@@ -750,13 +752,18 @@ export interface PostedForPrior {
750
752
  // triage tag or a thread left open; an over-match puts a "✅ RESOLVED ·
751
753
  // verified gone" reply on a still-live finding.
752
754
  export function bindPriorsToPosted<T extends PostedForPrior>(
753
- priors: readonly { id: string; locs: readonly string[]; claim: string }[],
755
+ priors: readonly {
756
+ id: string;
757
+ locs: readonly string[];
758
+ claim: string;
759
+ c?: string;
760
+ }[],
754
761
  posted: readonly T[],
755
762
  window: number = IDENTITY_LINE_WINDOW,
756
763
  ): Map<string, T> {
757
764
  interface Pair {
758
765
  priorId: string;
759
- claim: string;
766
+ fingerprint: string | undefined;
760
767
  row: T;
761
768
  distance: number;
762
769
  }
@@ -767,7 +774,12 @@ export function bindPriorsToPosted<T extends PostedForPrior>(
767
774
  for (const row of posted) {
768
775
  const distance = anchorDistance(identity, row, window);
769
776
  if (distance === null) continue;
770
- pairs.push({ priorId: prior.id, claim: prior.claim, row, distance });
777
+ pairs.push({
778
+ priorId: prior.id,
779
+ fingerprint: priorFingerprint(prior),
780
+ row,
781
+ distance,
782
+ });
771
783
  }
772
784
  }
773
785
 
@@ -804,7 +816,7 @@ export function bindPriorsToPosted<T extends PostedForPrior>(
804
816
  let changed = false;
805
817
  const proposals: Pair[] = [];
806
818
  for (const [priorId, group] of byPrior) {
807
- const winner = resolvePriorTie(group, group[0]?.claim ?? "");
819
+ const winner = resolvePriorTie(group, group[0]?.fingerprint);
808
820
  if (winner === undefined) {
809
821
  disqualified.add(priorId);
810
822
  changed = true;
@@ -869,16 +881,25 @@ function anchorDistance(
869
881
  return best;
870
882
  }
871
883
 
884
+ // What a prior's marker should carry. No claim, no fingerprint:
885
+ // `claimFingerprint("")` is a real constant hash (`e3b0c44298fc`) that every
886
+ // empty-claim prior shares, so consulting it would hand a whole tied set to
887
+ // whichever row came first. A stored `c` wins because the stored claim may be
888
+ // its published form, which the posted marker never hashed.
889
+ function priorFingerprint(prior: {
890
+ claim: string;
891
+ c?: string;
892
+ }): string | undefined {
893
+ if (prior.claim.trim().length === 0) return undefined;
894
+ return prior.c ?? claimFingerprint(prior.claim);
895
+ }
896
+
872
897
  function resolvePriorTie<T extends PostedForPrior>(
873
898
  tied: readonly { row: T; distance: number }[],
874
- claim: string,
899
+ fingerprint: string | undefined,
875
900
  ): T | undefined {
876
901
  if (tied.length === 1) return tied[0]?.row;
877
- // No claim, no tie-break: `claimFingerprint("")` is a real constant hash
878
- // (`e3b0c44298fc`) that every empty-claim prior shares, so consulting it
879
- // here would hand the whole tied set to whichever row came first.
880
- if (claim.trim().length === 0) return undefined;
881
- const fingerprint = claimFingerprint(claim);
902
+ if (fingerprint === undefined) return undefined;
882
903
  const matching = tied.filter((c) => c.row.marker.c === fingerprint);
883
904
  return matching.length === 1 ? matching[0]?.row : undefined;
884
905
  }
@@ -890,13 +911,17 @@ function resolvePriorTie<T extends PostedForPrior>(
890
911
  // claim-less prior shares), and anything short of exactly one match leaves the
891
912
  // comment to nobody.
892
913
  function resolveRowTie<T extends PostedForPrior>(
893
- contenders: readonly { priorId: string; claim: string; row: T }[],
914
+ contenders: readonly {
915
+ priorId: string;
916
+ fingerprint: string | undefined;
917
+ row: T;
918
+ }[],
894
919
  ): { priorId: string; row: T } | undefined {
895
920
  if (contenders.length === 1) return contenders[0];
896
921
  const matching = contenders.filter(
897
922
  (contender) =>
898
- contender.claim.trim().length > 0 &&
899
- contender.row.marker.c === claimFingerprint(contender.claim),
923
+ contender.fingerprint !== undefined &&
924
+ contender.row.marker.c === contender.fingerprint,
900
925
  );
901
926
  return matching.length === 1 ? matching[0] : undefined;
902
927
  }