crysk 0.3.3 → 0.5.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 (116) hide show
  1. package/README.md +26 -17
  2. package/config/models/anthropic.json +1 -1
  3. package/dist/SKILL-dsnffnfp.md +140 -0
  4. package/dist/SKILL-gnrbph72.md +140 -0
  5. package/dist/SKILL-k4k0zn1w.md +143 -0
  6. package/dist/SKILL-kq0xejn3.md +553 -0
  7. package/dist/SKILL-qaqsbygw.md +66 -0
  8. package/dist/SKILL-vhb4c3vv.md +553 -0
  9. package/dist/SKILL-vws0aqb8.md +553 -0
  10. package/dist/SKILL-xpf6kmdw.md +74 -0
  11. package/dist/ci-admission-0ken6ehx.md +128 -0
  12. package/dist/ci-admission-t0f5qwth.md +128 -0
  13. package/dist/cli.js +3366 -1680
  14. package/dist/index.js +1884 -947
  15. package/dist/opencode-ci-ac5zksdn.md +106 -0
  16. package/dist/workflow-4pkyck01.yml +160 -0
  17. package/package.json +2 -2
  18. package/prompts/default/PROVENANCE.md +1 -0
  19. package/skills/crysk/SKILL.md +16 -16
  20. package/skills/crysk-ci-setup/SKILL.md +42 -39
  21. package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
  22. package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
  23. package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
  24. package/skills/crysk-loop/SKILL.md +20 -9
  25. package/skills/crysk-pr/SKILL.md +1 -1
  26. package/src/asset-manifest.ts +0 -4
  27. package/src/assets.ts +2 -2
  28. package/src/ci/admission-ledger.ts +4 -0
  29. package/src/ci/classify-error.ts +21 -24
  30. package/src/ci/cli-record.ts +53 -1
  31. package/src/ci/crysk-secrets.ts +409 -0
  32. package/src/ci/gates.ts +31 -42
  33. package/src/ci/outcome.ts +421 -330
  34. package/src/ci/platform-config.ts +127 -0
  35. package/src/ci/platform-report.ts +935 -0
  36. package/src/ci/platform-trace.ts +551 -0
  37. package/src/ci/platform.ts +465 -0
  38. package/src/ci/publish.ts +19 -6
  39. package/src/ci/reporter.ts +9 -7
  40. package/src/ci/review-admission.ts +8 -4
  41. package/src/ci/review-levels.ts +8 -7
  42. package/src/ci/run.ts +88 -0
  43. package/src/ci/setup.ts +547 -109
  44. package/src/ci/trace-bundle.ts +1282 -0
  45. package/src/ci/trace-transcripts.ts +415 -0
  46. package/src/ci/trigger.ts +176 -33
  47. package/src/cli.ts +11 -3
  48. package/src/commands/ci-setup-questions.ts +3 -3
  49. package/src/commands/ci-setup.ts +152 -6
  50. package/src/commands/config.ts +3 -0
  51. package/src/commands/doctor.ts +15 -6
  52. package/src/compare/loop.ts +9 -1
  53. package/src/compare/martian-adapter.ts +1 -1
  54. package/src/config/config.ts +16 -3
  55. package/src/diversity/clustering.ts +0 -1
  56. package/src/diversity/identity.ts +4 -5
  57. package/src/diversity/pipeline-integration.ts +1 -9
  58. package/src/doctor.ts +3 -3
  59. package/src/execution/attempt-evidence.ts +10 -5
  60. package/src/execution/claude-session-trace.ts +480 -0
  61. package/src/execution/contracts.ts +21 -4
  62. package/src/execution/harness.ts +105 -8
  63. package/src/execution/model-fallback.ts +239 -0
  64. package/src/execution/usage-normalized.ts +6 -4
  65. package/src/home-preflight.ts +1 -1
  66. package/src/index.ts +1 -1
  67. package/src/model/catalog.ts +13 -37
  68. package/src/model/free-discovery.ts +117 -8
  69. package/src/model/model-name.ts +404 -0
  70. package/src/model/provider-capabilities.ts +22 -7
  71. package/src/model/routing.ts +346 -467
  72. package/src/pr/admission.ts +71 -11
  73. package/src/pr/ci-admission-gate.ts +2 -1
  74. package/src/pr/finding-state-record.ts +58 -0
  75. package/src/pr/gate-record.ts +22 -0
  76. package/src/pr/inline.ts +3 -0
  77. package/src/pr/plan.ts +20 -4
  78. package/src/pr/posting.ts +4 -0
  79. package/src/pr/pr-status.ts +27 -7
  80. package/src/pr/pr.ts +39 -8
  81. package/src/pr/preflight.ts +44 -2
  82. package/src/pr/publish-outcome.ts +11 -3
  83. package/src/pr/review-pr.ts +20 -4
  84. package/src/pr/target.ts +12 -3
  85. package/src/production-runtime.ts +760 -331
  86. package/src/rereview/classify.ts +4 -0
  87. package/src/rereview/prepare.ts +47 -22
  88. package/src/rereview/state.ts +34 -8
  89. package/src/review/pipeline.ts +277 -101
  90. package/src/review/preflight.ts +201 -294
  91. package/src/review/report.ts +60 -40
  92. package/src/review/review.ts +20 -3
  93. package/src/review/route-preflight.ts +79 -11
  94. package/src/review/run.ts +28 -6
  95. package/src/review/scout.ts +1 -1
  96. package/src/review/spec.ts +3 -3
  97. package/src/review/step-runner.ts +70 -1
  98. package/src/runner-authority.ts +127 -9
  99. package/src/security/binding-policy.ts +1 -2
  100. package/src/security/claude-credential.ts +355 -0
  101. package/src/security/credential-broker.ts +56 -40
  102. package/src/security/evidence-redaction.ts +179 -4
  103. package/src/security/opencode-secret-manifest.ts +114 -0
  104. package/src/security/published-text.ts +161 -0
  105. package/src/security/redact.ts +45 -0
  106. package/src/system-tools.ts +48 -21
  107. package/src/transport-registry.ts +12 -2
  108. package/src/transports/claude-code-cli.ts +21 -2
  109. package/src/transports/opencode-sdk.ts +11 -9
  110. package/src/transports/opencode-server.ts +7 -10
  111. package/src/triage/triage.ts +2 -1
  112. package/src/ui/config-edit.ts +9 -20
  113. package/src/ui/config.ts +32 -27
  114. package/src/ui/plan.ts +76 -47
  115. package/src/updater.ts +10 -7
  116. package/prompts/default/deep-review-lifecycle.md +0 -362
@@ -38,6 +38,8 @@ import {
38
38
  type CommitStatusFact,
39
39
  clipStatusDescription,
40
40
  commitStatusRequest,
41
+ heldVerdictSha,
42
+ manualReviewHoldDescription,
41
43
  partialReviewAgainDescription,
42
44
  partialReviewDescription,
43
45
  prHtmlUrl,
@@ -46,6 +48,7 @@ import {
46
48
  import { publishFinalCommitStatus } from "#pr/status";
47
49
  import { log } from "#ui/primitives";
48
50
  import { canonicalStatusText, STATUS_CONTEXT } from "../brand";
51
+ import { CredentialRefusalError } from "../security/claude-credential";
49
52
 
50
53
  // ROADMAP Pillar 3 (GitHub Actions CI). The mechanical glue behind a gate
51
54
  // skip in CI mode: every DECISION (what to say, which marker, what the
@@ -178,6 +181,23 @@ export async function settleCiGateSkip(
178
181
  await settleCiAdmissionLedger(state, "gate-skipped", reason, options);
179
182
  }
180
183
 
184
+ // R003 (#494): a credential refusal at admission (CredentialRefusalError: no Claude
185
+ // credential, or an OpenCode route with no auth record) stops a CI run after the
186
+ // reservation and before any binding or provider call (the OpenCode refusal follows
187
+ // only the token-free free-model probe), so it spent nothing:
188
+ // its row settles as gate-skipped, like the budget gate it follows, with the
189
+ // refusal's own reason. Any other error is left for teardown, which settles it
190
+ // `failed`. The caller rethrows the error unchanged. The name predates the OpenCode
191
+ // refusal and is kept: an architecture test pins its call site.
192
+ export async function settleClaudeCredentialRefusal(
193
+ state: CiAdmissionLedgerState | null,
194
+ error: unknown,
195
+ options?: { spawnFn?: typeof Bun.spawn },
196
+ ): Promise<void> {
197
+ if (!(error instanceof CredentialRefusalError)) return;
198
+ await settleCiGateSkip(state, error.ledgerReason, options);
199
+ }
200
+
181
201
  export async function reserveCiAdmissionLedger(input: {
182
202
  operatorRoot: string;
183
203
  prNumber: number;
@@ -318,7 +338,7 @@ export interface AdmissionStatusInput {
318
338
  }
319
339
 
320
340
  export interface AdmissionStatusDecision {
321
- state: "success" | "failure";
341
+ state: "success" | "failure" | "pending";
322
342
  description: string;
323
343
  }
324
344
 
@@ -335,13 +355,21 @@ type CarriedReason = Exclude<AdmissionStatusReason, "same-head">;
335
355
 
336
356
  // Every rule that skips a review carries the last verdict the same way (budget-exhausted-carry S2): the
337
357
  // 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.
358
+ // one exception: that head's own status already exists. A capped rule holds a green (holdsForManualReview).
339
359
  function isCarriedReason(
340
360
  reason: AdmissionStatusReason,
341
361
  ): reason is CarriedReason {
342
362
  return reason !== "same-head";
343
363
  }
344
364
 
365
+ // ROADMAP Stage 2 #12: the rules that cap automatic reviews. Under them no later push is reviewed on its
366
+ // own, so carrying a green would let code no review read merge (measured: one PR merged green over 11
367
+ // unreviewed commits).
368
+ // The head waits for a manual review instead; a red still carries, since it already blocks.
369
+ function holdsForManualReview(reason: CarriedReason): boolean {
370
+ return reason === "max-attempts-exhausted" || reason === "manual-only-policy";
371
+ }
372
+
345
373
  // The readers below rewrite a legacy `pr-hero` lead into `crysk` first (canonicalStatusText), so the
346
374
  // patterns and the builders speak one spelling.
347
375
  const BLOCKING_COUNT = /^crysk: (\d+) blocking finding\(s\)/;
@@ -601,6 +629,12 @@ export function admissionSkipDecision(
601
629
  const verdict = newestCarriedVerdict(input.carried.statuses);
602
630
  if (verdict === undefined) return failClosed(label);
603
631
  if (verdict.state === "success") {
632
+ if (holdsForManualReview(input.reason)) {
633
+ return {
634
+ state: "pending",
635
+ description: manualReviewHoldDescription(label, input.carried.sha),
636
+ };
637
+ }
604
638
  // A carried unverified green stays unverified: chaining it never turns it into a green a review earned.
605
639
  const answeredCount = answeredCountIn(verdict.description ?? "");
606
640
  return {
@@ -638,6 +672,12 @@ export function admissionSkipDecision(
638
672
  answered.blocking > 0 &&
639
673
  answered.blocking >= blocking
640
674
  ) {
675
+ if (holdsForManualReview(input.reason)) {
676
+ return {
677
+ state: "pending",
678
+ description: manualReviewHoldDescription(label, input.carried.sha),
679
+ };
680
+ }
641
681
  return {
642
682
  state: "success",
643
683
  description: unverifiedFixesDescription(
@@ -676,6 +716,10 @@ const CARRY_WALK_CAP = 20;
676
716
  // missing from the list fails closed.
677
717
  // WHY a failed read ends the walk: a commit whose statuses did not read is not a commit with no verdict,
678
718
  // so skipping it would carry an older verdict across a read that never happened.
719
+ // WHY a hold redirects the walk (Stage 2 #12): a hold is no verdict, but it names the commit whose verdict
720
+ // it held. Under a used-up budget every push is held, so without the jump a PR with more commits since its
721
+ // last review than the cap would fail closed red although that review is still on the PR. The jump only
722
+ // ever moves to an older commit, so the walk ends, and the cap restarts from the commit it lands on.
679
723
  async function findCarriedVerdict(input: {
680
724
  operatorRoot: string;
681
725
  prNumber: number;
@@ -690,17 +734,33 @@ async function findCarriedVerdict(input: {
690
734
  if (shas === null) return null;
691
735
  const headIndex = shas.indexOf(input.headSha);
692
736
  if (headIndex < 0) return null;
693
- const earlier = shas.slice(0, headIndex).reverse().slice(0, CARRY_WALK_CAP);
694
- for (const sha of earlier) {
695
- const statuses = await input.readStatuses(input.operatorRoot, sha, {
696
- spawnFn: input.spawnFn,
697
- });
698
- if (statuses === null) return null;
699
- if (newestCarriedVerdict(statuses) !== undefined) {
700
- return { sha, statuses, older: earlier.slice(earlier.indexOf(sha) + 1) };
737
+ let end = headIndex;
738
+ walk: while (true) {
739
+ const earlier = shas.slice(0, end).reverse().slice(0, CARRY_WALK_CAP);
740
+ for (const sha of earlier) {
741
+ const statuses = await input.readStatuses(input.operatorRoot, sha, {
742
+ spawnFn: input.spawnFn,
743
+ });
744
+ if (statuses === null) return null;
745
+ if (newestCarriedVerdict(statuses) !== undefined) {
746
+ return {
747
+ sha,
748
+ statuses,
749
+ older: earlier.slice(earlier.indexOf(sha) + 1),
750
+ };
751
+ }
752
+ const newest = newestStatusInContext(statuses, COMMIT_STATUS_CONTEXT);
753
+ const held = newest === undefined ? null : heldVerdictSha(newest);
754
+ if (held !== null) {
755
+ const target = shas.findIndex((s) => s.startsWith(held));
756
+ if (target >= 0 && target < shas.indexOf(sha)) {
757
+ end = target + 1;
758
+ continue walk;
759
+ }
760
+ }
701
761
  }
762
+ return null;
702
763
  }
703
- return null;
704
764
  }
705
765
 
706
766
  // WHY the head's override holds: a human's `/pr-hero override` on this head is the decision for it. A
@@ -176,6 +176,7 @@ export async function evaluateCiAdmissionGate(input: {
176
176
  }
177
177
  const trustedActors = resolveCiTrustedActors({
178
178
  githubActor: process.env.GITHUB_ACTOR,
179
+ platformActor: process.env.CRYSK_PLATFORM_ACTOR,
179
180
  extra: config.ci_trusted_actors,
180
181
  });
181
182
  const allComments = [...reviewComments, ...issueComments];
@@ -387,7 +388,7 @@ export async function evaluateCiAdmissionGate(input: {
387
388
  advisoryCount: admissionVerdict.prior.advisory,
388
389
  });
389
390
  // S2: manual-required carries the last verdict like every other skip (publishCiSkip,
390
- // admissionSkipDecision); a carried red with every blocking finding answered turns green, unverified.
391
+ // admissionSkipDecision), except a green: Stage 2 #12 holds it pending for a manual review.
391
392
  const plan = planCiReviewManualRequired({
392
393
  prNumber,
393
394
  verdict: admissionVerdict,
@@ -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/plan.ts CHANGED
@@ -27,11 +27,12 @@ import {
27
27
  countFreeRouteSteps,
28
28
  type FreeRouteBilling,
29
29
  } from "#model/free-discovery";
30
- import type { ResolvedRoutePlan } from "#model/routing";
30
+ import { planRoutes, type ResolvedRoutePlan } from "#model/routing";
31
31
  import {
32
32
  type CiAdmissionLedgerState,
33
33
  publishCiSkip,
34
34
  settleCiGateSkip,
35
+ settleClaudeCredentialRefusal,
35
36
  } from "#pr/admission";
36
37
  import { ghRepoWebUrl } from "#pr/pr";
37
38
  import {
@@ -71,6 +72,7 @@ import {
71
72
  type RunnerAuthorityResolution,
72
73
  resolveRunnerAuthority,
73
74
  } from "../runner-authority";
75
+ import type { RunClaudeCredential } from "../security/claude-credential";
74
76
 
75
77
  export type PrPlanAndConfirmResult =
76
78
  | { exitCode: number }
@@ -128,6 +130,8 @@ export async function resolvePrPlanAndConfirm(params: {
128
130
  // run, pr-hero/local otherwise (resolveCiPosture). Passed down, never re-derived.
129
131
  statusContext: CommitStatusContext;
130
132
  ciBudgetCeiling: { budgetUsd: number | undefined };
133
+ // S5: the run's Claude credential, chosen once at run start (reviewPr).
134
+ claudeRun: RunClaudeCredential;
131
135
  ciAdmissionLedger: CiAdmissionLedgerState | null;
132
136
  skipDiscovery: boolean;
133
137
  hunterCount: number;
@@ -204,12 +208,12 @@ export async function resolvePrPlanAndConfirm(params: {
204
208
  }
205
209
  }
206
210
  const productionRoute = await resolvePipelineRoute({
207
- routingConfigured: params.config.routing !== undefined,
211
+ modelsConfigured: params.config.models !== undefined,
208
212
  workspaceRoot: params.worktreePath,
209
213
  spec: params.spec,
210
214
  options: params.options,
211
215
  agentFiles: params.agentFiles,
212
- routingConfig: params.config.routing,
216
+ models: params.config.models,
213
217
  summary: params.summary,
214
218
  summarizerEnabled: params.summary.enabled && !params.skipDiscovery,
215
219
  scoutEnabled: params.options.scout && !params.skipDiscovery,
@@ -218,6 +222,10 @@ export async function resolvePrPlanAndConfirm(params: {
218
222
  // re-review that hunts nothing new.
219
223
  materialityEnabled:
220
224
  resolveMaterialityGate(params.config) && !params.skipDiscovery,
225
+ claudeRun: params.claudeRun,
226
+ }).catch(async (error: unknown) => {
227
+ await settleClaudeCredentialRefusal(params.ciAdmissionLedger, error);
228
+ throw error;
221
229
  });
222
230
  const routePlan = productionRoute?.routePlan;
223
231
  const productionAdmission = productionRoute?.productionAdmission;
@@ -227,11 +235,19 @@ export async function resolvePrPlanAndConfirm(params: {
227
235
  routePlan === undefined || productionAdmission === undefined
228
236
  ? undefined
229
237
  : await countFreeRouteSteps({
230
- steps: routePlan.steps,
238
+ steps: planRoutes(routePlan),
231
239
  probe: productionAdmission.freeModelProbe,
240
+ // The CRYSK_OPENCODE_* names admission bound each route's kind with,
241
+ // so the card counts free exactly the routes admission probed (U3).
242
+ openCodeSecretNames:
243
+ productionAdmission.authorityOptions.openCodeSecretNames,
232
244
  });
233
245
  const runnerAuthority = await resolveRunnerAuthority({
234
246
  workspaceRoot: params.worktreePath,
247
+ env: params.claudeRun.env,
248
+ ...(params.claudeRun.kind === undefined
249
+ ? {}
250
+ : { claudeCredential: params.claudeRun.kind }),
235
251
  });
236
252
  await enforceCapabilityGate({
237
253
  routePlan,
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
 
@@ -828,7 +828,7 @@ export function settleRequestForCancellation(
828
828
  lock: HeldCommitStatusLock | null,
829
829
  ): { operatorRoot: string; sha: string; request: CommitStatusRequest } | null {
830
830
  if (lock === null) return null;
831
- // WHY PRH-CANCELLED and not "review did not finish": a signal is a cancel, and the
831
+ // WHY CRYSK-CANCELLED and not "review did not finish": a signal is a cancel, and the
832
832
  // action's cancel-settle step writes the same text when this settle does not land
833
833
  // first (src/ci/publish.ts runCancelSettle). Either writer leaves one coded status.
834
834
  return {
@@ -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,
@@ -331,7 +339,7 @@ export async function publishRunOutcome(
331
339
  findings: doc.findings,
332
340
  costUsdEst: result.usage.cost_usd_est,
333
341
  wallMs,
334
- model: envelopeModel(input.options, input.agentFiles),
342
+ model: envelopeModel(input.options, input.agentFiles, result.routePlan),
335
343
  webUrl,
336
344
  delta: posted?.delta,
337
345
  runDir: input.runDir,