crysk 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +28 -22
  2. package/dist/SKILL-1q3658n0.md +74 -0
  3. package/dist/SKILL-25j4q9b8.md +143 -0
  4. package/dist/SKILL-32cmme3j.md +143 -0
  5. package/dist/SKILL-4747bhne.md +143 -0
  6. package/dist/SKILL-4jc3sv23.md +74 -0
  7. package/dist/SKILL-c0492rch.md +540 -0
  8. package/dist/SKILL-d1nzkhhr.md +74 -0
  9. package/dist/SKILL-f8p7kvx0.md +143 -0
  10. package/dist/SKILL-gxd45g38.md +553 -0
  11. package/dist/SKILL-rec41991.md +66 -0
  12. package/dist/SKILL-zze8zj5g.md +536 -0
  13. package/dist/adjudicator-eckqh14e.md +78 -0
  14. package/dist/ci-admission-qn797a6c.md +128 -0
  15. package/dist/cli.js +18608 -18523
  16. package/dist/consolidate-4xw1pkg7.md +24 -0
  17. package/dist/deep-review-logic-dgr112y1.md +196 -0
  18. package/dist/deep-review-logic-fck5z4xe.md +197 -0
  19. package/dist/deep-review-logic-h1fpamfh.md +192 -0
  20. package/dist/deep-review-logic-m4vk5683.md +196 -0
  21. package/dist/deep-review-logic-z63kmgmc.md +157 -0
  22. package/dist/deep-review-parity-7x7s5d81.md +148 -0
  23. package/dist/deep-review-parity-9wxmynsc.md +115 -0
  24. package/dist/deep-review-parity-bwwe7cx6.md +152 -0
  25. package/dist/deep-review-parity-e50pw3pk.md +117 -0
  26. package/dist/deep-review-parity-ennmm9m1.md +151 -0
  27. package/{prompts/default/deep-review-parity.md → dist/deep-review-parity-h7y6y2he.md} +14 -16
  28. package/dist/deep-review-parity-xg6wy69c.md +151 -0
  29. package/dist/deep-review-reliability-6h3c4gmw.md +125 -0
  30. package/dist/deep-review-reliability-dcjab69x.md +122 -0
  31. package/dist/deep-review-reliability-ec7b5pbk.md +159 -0
  32. package/dist/deep-review-reliability-hvasvmt9.md +153 -0
  33. package/dist/deep-review-reliability-mjnayxmt.md +158 -0
  34. package/dist/deep-review-reliability-mm7fnayf.md +124 -0
  35. package/dist/deep-review-reliability-xk4xvc2w.md +158 -0
  36. package/dist/deep-review-resilience-0esd5qeh.md +148 -0
  37. package/dist/deep-review-resilience-envgcmpy.md +115 -0
  38. package/dist/deep-review-resilience-fgx8ythf.md +151 -0
  39. package/dist/deep-review-resilience-mq5qa6ad.md +152 -0
  40. package/dist/deep-review-resilience-pwh1gawp.md +151 -0
  41. package/dist/deep-review-resilience-s9n21dkx.md +117 -0
  42. package/dist/deep-review-resilience-vz4qskea.md +119 -0
  43. package/dist/deep-review-security-1vwjdc9q.md +205 -0
  44. package/dist/deep-review-security-x1cc1z00.md +205 -0
  45. package/dist/index.js +590 -485
  46. package/dist/opencode-ci-jc8mf4wn.md +106 -0
  47. package/dist/opencode-ci-qrcv7a99.md +106 -0
  48. package/dist/opencode-ci-rdpcc7xc.md +106 -0
  49. package/dist/opencode-ci-yt0k74t0.md +106 -0
  50. package/dist/review-refuter-7qffwtzz.md +77 -0
  51. package/dist/verifier-tyh8r45v.md +40 -0
  52. package/dist/verifier-xf4xj701.md +40 -0
  53. package/dist/workflow-andv2dvm.yml +158 -0
  54. package/package.json +1 -1
  55. package/prompts/consolidate.md +1 -1
  56. package/prompts/default/PROVENANCE.md +6 -0
  57. package/prompts/default/deep-review-logic.md +56 -15
  58. package/prompts/default/deep-review-reliability.md +64 -30
  59. package/prompts/default/deep-review-resilience.md +71 -37
  60. package/prompts/default/deep-review-security.md +205 -0
  61. package/prompts/default/review-refuter.md +1 -1
  62. package/prompts/verifier.md +40 -0
  63. package/skills/crysk/SKILL.md +6 -6
  64. package/skills/crysk-ci-setup/SKILL.md +32 -33
  65. package/skills/crysk-ci-setup/assets/workflow.yml +5 -10
  66. package/skills/crysk-ci-setup/references/ci-admission.md +5 -5
  67. package/skills/crysk-ci-setup/references/opencode-ci.md +6 -6
  68. package/skills/crysk-loop/SKILL.md +37 -54
  69. package/skills/crysk-loop/adjudicator.md +10 -18
  70. package/skills/crysk-pr/SKILL.md +1 -1
  71. package/src/asset-manifest.ts +6 -6
  72. package/src/assets.ts +4 -4
  73. package/src/brand.ts +20 -30
  74. package/src/ci/gates.ts +155 -192
  75. package/src/ci/outcome.ts +4 -31
  76. package/src/ci/platform-limits.ts +135 -0
  77. package/src/ci/platform-report.ts +212 -126
  78. package/src/ci/platform.ts +28 -26
  79. package/src/ci/reporter.ts +25 -26
  80. package/src/ci/review-admission.ts +1 -2
  81. package/src/ci/review-levels.ts +12 -53
  82. package/src/ci/setup.ts +96 -66
  83. package/src/ci/trace-bundle.ts +11 -27
  84. package/src/ci/trace-transcripts.ts +4 -6
  85. package/src/ci/trigger.ts +3 -5
  86. package/src/cli.ts +6 -5
  87. package/src/commands/ci-setup-questions.ts +2 -55
  88. package/src/commands/ci-setup.ts +2 -26
  89. package/src/commands/triage.ts +131 -38
  90. package/src/commands/usage.ts +0 -1
  91. package/src/compare/compare.ts +3 -3
  92. package/src/compare/floor-test.ts +30 -201
  93. package/src/compare/hunter-exam.ts +631 -0
  94. package/src/config/config.ts +6 -30
  95. package/src/diversity/accounting.ts +0 -26
  96. package/src/diversity/benchmark.ts +1 -17
  97. package/src/diversity/identity.ts +0 -14
  98. package/src/diversity/pipeline-integration.ts +0 -29
  99. package/src/doctor.ts +3 -6
  100. package/src/execution/claude-session-trace.ts +7 -2
  101. package/src/execution/contracts.ts +15 -9
  102. package/src/execution/harness.ts +165 -187
  103. package/src/execution/spend-limiter.ts +39 -131
  104. package/src/execution/usage-facts.ts +397 -0
  105. package/src/execution/usage-normalized.ts +33 -86
  106. package/src/harness/materiality-judge.ts +0 -5
  107. package/src/harness/pipeline-plan.ts +0 -3
  108. package/src/harness/replay-rows.ts +0 -5
  109. package/src/harness/route-runner.ts +2 -2
  110. package/src/harness/single-step.ts +3 -9
  111. package/src/index.ts +1 -1
  112. package/src/mcp/preflight.ts +2 -2
  113. package/src/model/catalog.ts +1 -3
  114. package/src/model/free-discovery.ts +11 -78
  115. package/src/model/model-name.ts +16 -5
  116. package/src/model/profiles/claude.ts +1 -2
  117. package/src/model/profiles/openai.ts +1 -2
  118. package/src/model/profiles.ts +2 -3
  119. package/src/model/provider-capabilities.ts +16 -55
  120. package/src/model/routing.ts +39 -36
  121. package/src/pr/admission.ts +6 -6
  122. package/src/pr/answered-findings.ts +8 -4
  123. package/src/pr/ci-publish.ts +0 -2
  124. package/src/pr/discovery.ts +4 -25
  125. package/src/pr/plan.ts +40 -121
  126. package/src/pr/pr-status.ts +14 -2
  127. package/src/pr/pr.ts +1 -1
  128. package/src/pr/preflight.ts +44 -15
  129. package/src/pr/publish-outcome.ts +1 -19
  130. package/src/pr/review-pr.ts +15 -47
  131. package/src/pr/target.ts +76 -82
  132. package/src/production-runtime.ts +52 -114
  133. package/src/progress.ts +0 -54
  134. package/src/rereview/prepare.ts +4 -1
  135. package/src/rereview/state.ts +1 -1
  136. package/src/rereview/verify.ts +15 -9
  137. package/src/review/boundary.ts +5 -8
  138. package/src/review/drafts.ts +3 -3
  139. package/src/review/findings-conformance.ts +1 -1
  140. package/src/review/findings.ts +0 -4
  141. package/src/review/pipeline.ts +194 -407
  142. package/src/review/preflight.ts +175 -201
  143. package/src/review/prompt-set.ts +1 -2
  144. package/src/review/report.ts +2 -162
  145. package/src/review/review.ts +25 -74
  146. package/src/review/route-preflight.ts +19 -35
  147. package/src/review/run.ts +37 -73
  148. package/src/review/size-gate.ts +3 -3
  149. package/src/review/spec.ts +6 -11
  150. package/src/review/step-runner.ts +4 -4
  151. package/src/runner-authority.ts +10 -9
  152. package/src/security/credential-broker.ts +5 -6
  153. package/src/server/preflight.ts +0 -1
  154. package/src/server/server.ts +17 -6
  155. package/src/store/activity.ts +1 -2
  156. package/src/store/backfill-preflight.ts +0 -3
  157. package/src/store/backfill.ts +0 -1
  158. package/src/store/metrics-preflight.ts +4 -14
  159. package/src/store/metrics.ts +5 -5
  160. package/src/store/preflight.ts +0 -13
  161. package/src/store/store.ts +11 -12
  162. package/src/transport-registry.ts +6 -30
  163. package/src/transports/claude-code-cli.ts +149 -215
  164. package/src/transports/opencode-client.ts +4 -24
  165. package/src/transports/opencode-sdk.ts +17 -112
  166. package/src/triage/plain-reply.ts +37 -0
  167. package/src/ui/activity.ts +1 -6
  168. package/src/ui/config-edit.ts +14 -67
  169. package/src/ui/config.ts +3 -8
  170. package/src/ui/plan.ts +11 -198
  171. package/src/ui/progress.ts +3 -49
  172. package/src/ui/result.ts +18 -77
  173. package/src/ui/review-menu.ts +3 -12
  174. package/src/ui/select.ts +9 -79
  175. package/src/updater.ts +1 -1
  176. package/src/usage.ts +1 -7
  177. package/prompts/scout.md +0 -140
  178. package/src/ci/platform-estimate.ts +0 -111
  179. package/src/review/scout.ts +0 -323
@@ -93,21 +93,16 @@ import {
93
93
  resolveMaxConcurrentSteps,
94
94
  resolveSharedPrefix,
95
95
  } from "#review/preflight";
96
- import { code, estimateCost } from "#review/report";
96
+ import { code } from "#review/report";
97
97
  import {
98
98
  claudeAuthorityRequired,
99
99
  isBundledAgentsDir,
100
100
  pipelineConsolidateInput,
101
101
  pipelineMaterialityInput,
102
- pipelineScoutInput,
103
102
  pipelineSummarizerInput,
103
+ pipelineVerifierInput,
104
104
  } from "#review/route-preflight";
105
- import {
106
- fullReviewHunterCount,
107
- prepareRunnerForRoute,
108
- resolveParityFires,
109
- validateGotchas,
110
- } from "#review/run";
105
+ import { prepareRunnerForRoute, validateGotchas } from "#review/run";
111
106
  import { sizeGateConfigFor, sizeGateLine } from "#review/size-gate";
112
107
  import { registerActiveRun, unregisterActiveRun } from "#store/activity";
113
108
  import {
@@ -116,7 +111,7 @@ import {
116
111
  CI_ADJUDICATOR_LOGIN,
117
112
  trustedAdjudicator,
118
113
  } from "#triage/adjudication";
119
- import { dryRunHunterCount, reviewingLine } from "#ui/plan";
114
+ import { reviewingLine } from "#ui/plan";
120
115
  import { log, styleEnabled, terminalWidth } from "#ui/primitives";
121
116
  import { applySizeGate, startProgressRenderer } from "#ui/progress";
122
117
  import { parsePrFiles } from "#watch/preflight";
@@ -361,7 +356,8 @@ export async function reviewPr(
361
356
  throw error;
362
357
  }
363
358
  const {
364
- ciBudgetCeiling,
359
+ ciBillingMode,
360
+ ciRoleBilling,
365
361
  ciSizeLimits,
366
362
  agents,
367
363
  spec,
@@ -428,15 +424,6 @@ export async function reviewPr(
428
424
  // dry run that says SKIP for a PR the real per-file run happily accepts
429
425
  // reads as a broken tool, not a conservative estimate.
430
426
  if (options.dryRun) {
431
- const hunterCount = dryRunHunterCount(spec, config);
432
- const estimate = estimateCost(
433
- target.ghDiffStat,
434
- hunterCount,
435
- summary.enabled,
436
- options.scout,
437
- 0,
438
- true,
439
- );
440
427
  const dryRunGateConfig = sizeGateConfigFor(
441
428
  sizeGateOverrides,
442
429
  config,
@@ -467,8 +454,6 @@ export async function reviewPr(
467
454
  summary,
468
455
  loaded,
469
456
  isCi,
470
- hunterCount,
471
- estimate,
472
457
  dryRunGateConfig,
473
458
  perFile,
474
459
  });
@@ -594,7 +579,6 @@ export async function reviewPr(
594
579
  adjudicationQueue,
595
580
  phaseB,
596
581
  diffStat,
597
- prDiffStat,
598
582
  sizeGate,
599
583
  } = discovery;
600
584
 
@@ -703,23 +687,13 @@ export async function reviewPr(
703
687
 
704
688
  // 7 — the plan and the paid gate, exactly like local mode but with the
705
689
  // real numstat replacing GitHub's counters.
706
- const parityFires = resolveParityFires(
707
- effectiveDiff.patch,
708
- config.parity_trigger_paths,
709
- );
710
690
  const activeHunters = discoveryHunters({
711
691
  skipDiscovery,
712
692
  agents: spec.agents,
713
- parityFires,
714
693
  });
715
694
  const hunterCount = activeHunters.length;
716
- const fullHunterCount = fullReviewHunterCount(
717
- spec.agents,
718
- anchorPatch,
719
- config.parity_trigger_paths,
720
- );
721
695
  // See resolvePrPlanAndConfirm (src/pr/plan.ts) for the full rationale —
722
- // the CI budget gate, route/capability resolution, the plan card, the
696
+ // route/capability resolution, the plan card, the
723
697
  // interactive confirm, and the "committed to spending" commit-status
724
698
  // hold that follows a successful one.
725
699
  const planResult = await resolvePrPlanAndConfirm({
@@ -734,7 +708,6 @@ export async function reviewPr(
734
708
  diffFromSha,
735
709
  diffPath,
736
710
  diffStat,
737
- prDiffStat,
738
711
  droppedPaths: effectiveDiff.droppedPaths,
739
712
  sizeGate,
740
713
  sizeGateConfirmed,
@@ -749,13 +722,11 @@ export async function reviewPr(
749
722
  isCi,
750
723
  ciMode,
751
724
  statusContext,
752
- ciBudgetCeiling,
725
+ ciBillingMode,
726
+ ciRoleBilling,
753
727
  claudeRun,
754
728
  ciAdmissionLedger,
755
729
  skipDiscovery,
756
- hunterCount,
757
- fullHunterCount,
758
- parityFires,
759
730
  verifyQueue,
760
731
  prepared,
761
732
  });
@@ -766,9 +737,7 @@ export async function reviewPr(
766
737
  productionAdmission,
767
738
  runnerAuthority,
768
739
  maxVerificationSteps,
769
- estimate,
770
740
  statusTargetUrl,
771
- freeRoute,
772
741
  } = planResult;
773
742
 
774
743
  let result: PipelineResult | undefined;
@@ -808,7 +777,7 @@ export async function reviewPr(
808
777
  // into a group nothing ever closes.
809
778
  let started = 0;
810
779
  await withCiWorkflowGroup(isCi, "crysk review", log, async () => {
811
- log(reviewingLine(hunterCount, summary, options));
780
+ log(reviewingLine(hunterCount, summary));
812
781
  // runnerAuthority resolved before confirm with the exact-binding gate.
813
782
  // A plan with no claude-code route never starts the Claude CLI.
814
783
  if (
@@ -886,15 +855,12 @@ export async function reviewPr(
886
855
  mcpConfigPath,
887
856
  hopBudget: options.hopBudget,
888
857
  ...(options.model ? { model: options.model } : {}),
889
- parityTriggerPaths: config.parity_trigger_paths,
858
+ parityTriggerPaths: [],
890
859
  suspicionPriors: config.suspicion_priors,
891
860
  modelProfile: profile,
892
861
  ...(skipDiscovery
893
862
  ? {}
894
863
  : pipelineSummarizerInput(summary, { profile })),
895
- ...(skipDiscovery
896
- ? {}
897
- : pipelineScoutInput(options, { profile })),
898
864
  ...(skipDiscovery ? {} : pipelineConsolidateInput({ profile })),
899
865
  // Gated on skipDiscovery like consolidation: an empty-delta
900
866
  // re-review posts no new findings, so there is nothing to judge.
@@ -902,6 +868,7 @@ export async function reviewPr(
902
868
  ? {}
903
869
  : pipelineMaterialityInput(config, { profile })),
904
870
  prTitle: target.title,
871
+ prDescription: target.body,
905
872
  ...(resolveSharedPrefix(options) ? { sharedPrefix: true } : {}),
906
873
  // NOT gated on skipDiscovery: an empty-delta re-review still
907
874
  // classifies and verifies against this config, and a run whose
@@ -915,6 +882,9 @@ export async function reviewPr(
915
882
  ...(skipDiscovery ? { skipDiscovery: true } : {}),
916
883
  ...(rereview === undefined ? {} : { rereview }),
917
884
  ...(verifyQueue.length > 0 ? { verifyQueue } : {}),
885
+ // Unconditional: an overlap candidate can queue a verify step
886
+ // with an empty verifyQueue.
887
+ ...pipelineVerifierInput({ profile }),
918
888
  ...(overlapCandidates.length > 0 ? { overlapCandidates } : {}),
919
889
  ...(adjudicationQueue.length > 0 ? { adjudicationQueue } : {}),
920
890
  maxVerificationSteps,
@@ -977,8 +947,6 @@ export async function reviewPr(
977
947
  isCi,
978
948
  ciMode,
979
949
  postMinSeverity: config.post_min_severity,
980
- estimate,
981
- freeRoute,
982
950
  ciAdmissionLedger,
983
951
  onPosted: (outcome) => {
984
952
  posted = outcome;
package/src/pr/target.ts CHANGED
@@ -19,17 +19,17 @@
19
19
  import { existsSync } from "node:fs";
20
20
  import os from "node:os";
21
21
  import {
22
- budgetDisabledWarningMessage,
23
- budgetUnlimitedNoticeMessage,
22
+ type CiBillingMode,
24
23
  type CiSizeLimits,
25
24
  deriveCiBillingMode,
26
- resolveCiBudgetCeiling,
25
+ type ModelRoleBilling,
27
26
  resolveCiSizeLimits,
28
27
  sizeGateUnlimitedNoticeMessage,
29
28
  } from "#ci/gates";
30
29
  import { formatWorkflowCommand } from "#ci/reporter";
31
- import { openCodeRoutesBillMetered } from "#ci/setup";
30
+ import { modelRoleBilling, openCodeRoutesBillMetered } from "#ci/setup";
32
31
  import { resolveRepoRoot } from "#git/git";
32
+ import { planRoutes, type ResolvedRoutePlan } from "#model/routing";
33
33
  import { ghCurrentBranchPr, ghPrView } from "#pr/pr";
34
34
  import {
35
35
  type PrTarget,
@@ -44,9 +44,9 @@ import {
44
44
  type CliOptions,
45
45
  isCiEnvironment,
46
46
  type NumstatFile,
47
+ resolveMaterialityGate,
47
48
  } from "#review/preflight";
48
49
  import type { ParsedAgent, PromptSetIdentity } from "#review/prompt-set";
49
- import type { estimateCost } from "#review/report";
50
50
  import { buildCliRoutePlan, isBundledAgentsDir } from "#review/route-preflight";
51
51
  import {
52
52
  type LoadedRunConfig,
@@ -113,16 +113,14 @@ export async function resolvePrRunOptions(
113
113
  // yet at this point, and a `.crysk/config.json` committed by the PR author
114
114
  // must stay unread (O-8). Same loader as local mode, so the two modes
115
115
  // cannot drift on precedence.
116
- const { loaded, config, summary, scout, post, profile } = await loadRunConfig(
117
- {
118
- root: operatorRoot,
119
- home,
120
- configFlag: options.config,
121
- options,
122
- },
123
- );
116
+ const { loaded, config, summary, post, profile } = await loadRunConfig({
117
+ root: operatorRoot,
118
+ home,
119
+ configFlag: options.config,
120
+ options,
121
+ });
124
122
  // ROADMAP Pillar 3 (GitHub Actions CI). isCi folds in HERE, alongside
125
- // scout/post, so `options.yes` carries the headless bypass (spec 2.1:
123
+ // post, so `options.yes` carries the headless bypass (spec 2.1:
126
124
  // "MUST run headlessly ... equivalent to --yes") through every downstream
127
125
  // read of `options.yes` in one move — the confirm gate, the in-flight
128
126
  // TOCTOU check (`if (options.yes) return 0` is the correct CI answer to a
@@ -137,7 +135,7 @@ export async function resolvePrRunOptions(
137
135
  prNumber,
138
136
  home,
139
137
  isCi,
140
- options: { ...options, scout, post, yes: options.yes || isCi },
138
+ options: { ...options, post, yes: options.yes || isCi },
141
139
  loaded,
142
140
  config,
143
141
  summary,
@@ -146,7 +144,13 @@ export async function resolvePrRunOptions(
146
144
  }
147
145
 
148
146
  export interface ResolvedPrPromptSet {
149
- ciBudgetCeiling: ReturnType<typeof resolveCiBudgetCeiling>;
147
+ // How the run bills (the engine's own answer: the platform cannot see it).
148
+ // The CI limits gate reads it (src/pr/plan.ts); the size limits resolve from it.
149
+ ciBillingMode: CiBillingMode;
150
+ // Which of the run's model roles bill an API key, for the limits gate's
151
+ // comparison of a mixed setup (S17). Undefined when the routes could not be
152
+ // resolved here: the gate then compares the whole estimate.
153
+ ciRoleBilling: ModelRoleBilling | undefined;
150
154
  ciSizeLimits: CiSizeLimits | undefined;
151
155
  agents: AgentsDirResolution;
152
156
  spec: ReviewSpec;
@@ -156,30 +160,33 @@ export interface ResolvedPrPromptSet {
156
160
  gotchasPath: string | undefined;
157
161
  }
158
162
 
159
- // The OpenCode providers of every route the run resolves, fallbacks included,
160
- // from the same plan builder the run confirms with (buildCliRoutePlan), so each
161
- // source routing reads counts the way routing reads it. Undefined when the plan
162
- // cannot be built here; the run itself surfaces that error at confirm.
163
- async function openCodeRouteProviders(
163
+ // The run's route plan, fallbacks included, from the same plan builder the run
164
+ // confirms with (buildCliRoutePlan), so each source routing reads counts the way
165
+ // routing reads it. Undefined when the plan cannot be built here; the run itself
166
+ // surfaces that error at confirm.
167
+ async function resolveRoutePlanForBilling(
164
168
  input: Parameters<typeof buildCliRoutePlan>[0],
165
- ): Promise<string[] | undefined> {
166
- let plan: Awaited<ReturnType<typeof buildCliRoutePlan>>;
169
+ ): Promise<ResolvedRoutePlan | undefined> {
167
170
  try {
168
- plan = await buildCliRoutePlan(input);
171
+ return await buildCliRoutePlan(input);
169
172
  } catch {
170
173
  return undefined;
171
174
  }
175
+ }
176
+
177
+ // The OpenCode providers of every route of the plan, fallbacks included.
178
+ function openCodeRouteProviders(
179
+ plan: ResolvedRoutePlan | undefined,
180
+ ): string[] | undefined {
181
+ if (plan === undefined) return undefined;
172
182
  const providers = new Set<string>();
173
- for (const step of plan.steps) {
174
- for (const route of [step, ...(step.fallbacks ?? [])]) {
175
- if (route.route.backend === "opencode")
176
- providers.add(route.route.provider);
177
- }
183
+ for (const route of planRoutes(plan)) {
184
+ if (route.route.backend === "opencode") providers.add(route.route.provider);
178
185
  }
179
186
  return [...providers].sort();
180
187
  }
181
188
 
182
- // Step 1's second half: the CI budget ceiling (+ its notices), then the
189
+ // Step 1's second half: how the run bills, then the
183
190
  // prompt set resolution and the gotchas PATH (never the validation itself —
184
191
  // see this module's header). Runs after the caller's own
185
192
  // `readLocalIgnoreRules(operatorRoot)` read, before its own
@@ -215,35 +222,41 @@ export async function resolvePrPromptSetAndBudget(params: {
215
222
  // invoices nothing for a run whose models do not bill per token. Not
216
223
  // envBillsMetered either: that predicate stamps Claude usage and must stay
217
224
  // Anthropic-env-only.
218
- const billingMode = deriveCiBillingMode(
219
- params.claudeRun?.env ?? process.env,
220
- {
221
- openCodeBillsMetered: openCodeRoutesBillMetered({
222
- providers: await openCodeRouteProviders({
223
- spec,
224
- options: params.options,
225
- agentFiles,
226
- bundledAgents: isBundledAgentsDir(agents),
227
- models: params.config.models,
228
- summary: params.summary,
229
- profile: params.profile,
230
- }),
231
- authFilePresent: existsSync(resolveOpenCodeAuthPath()),
232
- openCodeSecretNames: readOpenCodeSecretNames(),
233
- }),
234
- },
235
- );
236
- // Issue #156: resolve the ceiling ONCE, here, and use this same value at
237
- // the budget gate far below (src/pr/review-pr.ts's plan/confirm stage).
238
- // Resolving twice invites the announcement and the gate drifting apart.
239
- // Deliberately NOT folded back into `options.budgetUsd` — the metered
240
- // default is a CI-gate policy, and leaking a 10 that the operator never
241
- // typed into every other read of `options.budgetUsd` would make it look
242
- // configured.
243
- const ciBudgetCeiling = resolveCiBudgetCeiling({
244
- configured: params.options.budgetUsd,
245
- billingMode,
225
+ const routePlan = await resolveRoutePlanForBilling({
226
+ spec,
227
+ options: params.options,
228
+ agentFiles,
229
+ bundledAgents: isBundledAgentsDir(agents),
230
+ models: params.config.models,
231
+ summary: params.summary,
232
+ profile: params.profile,
233
+ // The judge step joins the run when the gate is on (plan.ts), so the plan
234
+ // that decides how the run bills must have it too (#551 R002). On, whatever
235
+ // a re-review later skips: counting a judge that may not run is the
236
+ // conservative side.
237
+ materialityEnabled: resolveMaterialityGate(params.config),
238
+ });
239
+ const claudeEnv = params.claudeRun?.env ?? process.env;
240
+ const authFilePresent = existsSync(resolveOpenCodeAuthPath());
241
+ const openCodeSecretNames = readOpenCodeSecretNames();
242
+ const billingMode = deriveCiBillingMode(claudeEnv, {
243
+ openCodeBillsMetered: openCodeRoutesBillMetered({
244
+ providers: openCodeRouteProviders(routePlan),
245
+ authFilePresent,
246
+ openCodeSecretNames,
247
+ }),
246
248
  });
249
+ // The same routes, per model role: the platform prices each role and the
250
+ // limits gate compares the ones billed on an API key (S17).
251
+ const ciRoleBilling = modelRoleBilling({
252
+ plan: routePlan,
253
+ agents: spec.agents,
254
+ claudeEnv,
255
+ authFilePresent,
256
+ openCodeSecretNames,
257
+ });
258
+ // Resolved ONCE, here: the size limits below and the platform limits gate
259
+ // far below (src/pr/plan.ts's plan/confirm stage) read this same value.
247
260
  // The size gate's half of the same route policy (ci/gates.ts,
248
261
  // resolveCiSizeLimits). CI only: a local or watcher run keeps reading the
249
262
  // flags and the repo config exactly as before.
@@ -254,25 +267,9 @@ export async function resolvePrPromptSetAndBudget(params: {
254
267
  billingMode,
255
268
  })
256
269
  : undefined;
257
- // Spec 3.1: a silent disable is indistinguishable from a passing gate, so
258
- // an EXPLICIT `--budget-usd <= 0` warns even though it never skips a run.
259
- // Emitted here (once, as soon as isCi/budgetUsd are both known) rather
260
- // than beside the budget-gate check far below, which only runs at all when
261
- // there IS an estimate to compare against. The subscription notice rides
262
- // the same reasoning and the same placement, one register quieter: a
263
- // resolved no-ceiling is not an operator mistake, but it is still a gate
264
- // that did not run, and this repo does not ship those silently.
270
+ // A gate that did not run is still announced: the size gate's notice for a
271
+ // route where its limits resolved to off.
265
272
  if (params.isCi) {
266
- const disabledWarning = budgetDisabledWarningMessage(
267
- ciBudgetCeiling.budgetUsd,
268
- );
269
- if (disabledWarning !== null) {
270
- log(formatWorkflowCommand("warning", disabledWarning));
271
- }
272
- const unlimitedNotice = budgetUnlimitedNoticeMessage(ciBudgetCeiling);
273
- if (unlimitedNotice !== null) {
274
- log(formatWorkflowCommand("notice", unlimitedNotice));
275
- }
276
273
  if (ciSizeLimits !== undefined) {
277
274
  const sizeNotice = sizeGateUnlimitedNoticeMessage(ciSizeLimits);
278
275
  if (sizeNotice !== null) {
@@ -295,7 +292,8 @@ export async function resolvePrPromptSetAndBudget(params: {
295
292
  }
296
293
  const gotchasPath = instructions.path;
297
294
  return {
298
- ciBudgetCeiling,
295
+ ciBillingMode: billingMode,
296
+ ciRoleBilling,
299
297
  ciSizeLimits,
300
298
  agents,
301
299
  spec,
@@ -381,7 +379,7 @@ export async function resolvePrTargetRecord(params: {
381
379
 
382
380
  // Step 3's second half: the free dry-run exit's size-gate verdict, plan
383
381
  // card, and closing lines. Relocated out of reviewPr()'s `if (options.dryRun)`
384
- // block; the FIRST half of that block (hunterCount/estimate/dryRunGateConfig,
382
+ // block; the FIRST half of that block (dryRunGateConfig,
385
383
  // then the `resolvePrDryRunNumstat` call just above) stays inline in
386
384
  // reviewPr(), unchanged. This half picks up right after `perFile` is known
387
385
  // and returns the dry run's exit code (always 0).
@@ -400,8 +398,6 @@ export function renderPrDryRunPlan(params: {
400
398
  summary: LoadedRunConfig["summary"];
401
399
  loaded: LoadedRunConfig["loaded"];
402
400
  isCi: boolean;
403
- hunterCount: number;
404
- estimate: ReturnType<typeof estimateCost>;
405
401
  dryRunGateConfig: SizeGateConfig;
406
402
  perFile: NumstatFile[] | null;
407
403
  }): number {
@@ -441,8 +437,6 @@ export function renderPrDryRunPlan(params: {
441
437
  spec: params.spec,
442
438
  config: params.config,
443
439
  summary: params.summary,
444
- estimate: params.estimate,
445
- hunterCount: params.hunterCount,
446
440
  sizeGate: estimated,
447
441
  sizeGateNote,
448
442
  droppedPaths: [],