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
package/src/ci/gates.ts CHANGED
@@ -1,14 +1,13 @@
1
- // Bounded unattended spend (ROADMAP Pillar 3, GitHub Actions CI): the two
2
- // gates that must clear BEFORE a CI run spawns a single agent, and the pure
1
+ // Bounded unattended spend (ROADMAP Pillar 3, GitHub Actions CI): the gates
2
+ // that must clear BEFORE a CI run spawns a single agent, and the pure
3
3
  // CI-mode skip payloads those gates produce when they don't.
4
4
  //
5
5
  // Phase 3 additions (this module's scope now covers the whole CI-mode
6
- // policy layer, not just the two spend gates): `planCiSizeSkip`/
7
- // `planCiBudgetSkip` are the ONE call reviewPr's shell makes per gate —
6
+ // policy layer, not just the spend gates): `planCiSizeSkip`/
7
+ // `planCiLimitsSkip` are the ONE call reviewPr's shell makes per gate —
8
8
  // comment + marker + step-summary markdown + $GITHUB_OUTPUT, all from the
9
- // same numbers, so the shell has no decision left to make beyond "post it /
10
- // write it". `budgetDisabledWarningMessage` covers spec 3.1's disabled-
11
- // ceiling `::warning::` requirement. The exit-code contract (spec 2.1) lives
9
+ // same inputs, so the shell has no decision left to make beyond "post it /
10
+ // write it". The exit-code contract (spec 2.1) lives
12
11
  // in src/review/exit-code.ts, shared by every mode.
13
12
  //
14
13
  // This module does NOT reimplement the size gate — that gate (deterministic
@@ -20,8 +19,8 @@
20
19
  // there is nobody to prompt AND the run must still exit 0 with a courteous
21
20
  // PR notice (assistant posture — see proposal.md's Invariants). So this
22
21
  // module adds exactly that CI-mode handling on top of an already-computed
23
- // `SizeGateVerdict`, plus the budget gate's own threshold check (there is no
24
- // pre-existing budget gate to reuse).
22
+ // `SizeGateVerdict`, plus the platform limits rule (the engine computes no
23
+ // dollar figure; see `evaluatePlatformLimits`).
25
24
  //
26
25
  // Purity (project rule 1): every function here is a total function of its
27
26
  // arguments. No file I/O, no `process.env` sniffing, no `log()`, no network,
@@ -67,6 +66,7 @@ import { commandHint, MARKER_OPEN } from "../brand";
67
66
  import { CliUsageError } from "../errors";
68
67
  import { envBillsMetered } from "../execution/usage-normalized";
69
68
  import { ciForceReviewHintLine } from "./force-comment";
69
+ import type { PlatformLimitHit, PlatformLimits } from "./platform-limits";
70
70
  import {
71
71
  type CiOutputs,
72
72
  type CiSummaryData,
@@ -83,56 +83,104 @@ import type { CiReviewPolicyMode } from "./review-policy";
83
83
  import type { DeltaRiskAssessment } from "./review-risk";
84
84
  import { OVERRIDE_COMMAND } from "./trigger";
85
85
 
86
- function usd(amount: number): string {
87
- return `$${amount.toFixed(2)}`;
88
- }
89
-
90
86
  // ---------------------------------------------------------------------------
91
- // Budget gate — spec.md 3.1: "If estimated cost exceeds --budget-usd ...".
92
- // The one comparison this module owns outright (no pre-existing gate to
93
- // reuse, unlike size).
87
+ // Platform limits — platform-owned-cost L55. The platform owns the dollar
88
+ // limits (settings, defaults, the month's spend) and sends them with its
89
+ // estimate at the token exchange, nothing when the review was forced. The
90
+ // engine keeps ONE comparison, because only it knows whether the run bills an
91
+ // API key: skip when the run does and either the month's limit is used up, or
92
+ // the platform's estimate is over the per-review limit or over what is left of
93
+ // the month.
94
94
  // ---------------------------------------------------------------------------
95
95
 
96
- export interface BudgetGateVerdict {
97
- allowed: boolean;
98
- // Present only when `allowed` is false — mirrors SizeGateVerdict's own
99
- // discriminated shape (size-gate.ts) in spirit, kept optional-on-a-flat-
100
- // object here per the task's own stated signature rather than a second
101
- // discriminated union for a single string field.
102
- reason?: string;
96
+ export type PlatformLimitsVerdict =
97
+ | { allowed: true }
98
+ | {
99
+ allowed: false;
100
+ hit: PlatformLimitHit;
101
+ // Set when the comparison used the API share of the estimate (S17), not
102
+ // the whole of it; the skip notice says so.
103
+ apiShare?: true;
104
+ };
105
+
106
+ // Which model roles the run bills on an API key (true) and which it does not
107
+ // (false), resolved once from the run's routes (`modelRoleBilling`, ci/setup.ts).
108
+ export type ModelRoleBilling = ReadonlyMap<string, boolean>;
109
+
110
+ // The part of the estimate that runs on an API key (S17): the platform's split
111
+ // summed over the roles the run bills on one, plus every key the run cannot map
112
+ // to one of its roles (an unknown role may bill, so it counts). Undefined means
113
+ // there is no usable split, and the whole estimate is compared: no split sent
114
+ // or the run's routes unresolved (a run whose roles bill no API key never gets
115
+ // here: evaluatePlatformLimits lets it run).
116
+ // Rounded to the platform's 6 decimals so a sum of its parts sits on a limit
117
+ // instead of a hair over it.
118
+ function apiShareUsd(
119
+ limits: PlatformLimits,
120
+ roleBilling: ModelRoleBilling | undefined,
121
+ ): number | undefined {
122
+ const split = limits.estimateByRoleUsd;
123
+ if (split === undefined || roleBilling === undefined) return undefined;
124
+ if (!hasApiBilledRole(roleBilling)) return undefined;
125
+ let share = 0;
126
+ for (const [role, usd] of Object.entries(split)) {
127
+ if (roleBilling.get(role) !== false) share += usd;
128
+ }
129
+ return Math.round(share * 1e6) / 1e6;
130
+ }
131
+
132
+ // True when at least one resolved role bills an API key.
133
+ function hasApiBilledRole(roleBilling: ModelRoleBilling): boolean {
134
+ return [...roleBilling.values()].some(Boolean);
103
135
  }
104
136
 
105
- // Inclusive boundary: a cost exactly AT the ceiling is allowed, matching
137
+ // Inclusive boundary: an estimate exactly AT a limit passes, matching
106
138
  // size-gate.ts's own `>` (not `>=`) comparison against its limits.
107
139
  //
108
- // A non-positive ceiling DISABLES the gate. That is not this module's
109
- // invention — size-gate.ts:20 already settled it for the sibling knobs
110
- // ("<= 0 disables the limit. Both knobs, independently."), and all three
111
- // ship side by side in one action.yml feeding one preflight, so `budget-usd:
112
- // 0` has to mean what `max-changed-lines: 0` means. The external convention
113
- // does cut the other way (a $0 spend cap elsewhere often means "spend
114
- // nothing"), which is why it is written down here rather than assumed.
140
+ // No estimate and a month with money left: the review runs. That is a stated
141
+ // limit of the design (a model the platform cannot price is not capped per
142
+ // review), not an oversight; the platform's own month ledger still counts the
143
+ // run once it reports.
115
144
  //
116
- // What settles it is that the failure modes are not symmetric. Read as "no
117
- // ceiling" when the operator meant "spend nothing", being wrong costs one
118
- // visible review, still bounded by the size gate running independently. Read
119
- // as "always skip" when the operator meant "no ceiling", being wrong makes
120
- // pr-hero go dark on every PR while each run still exits 0 green — the same
121
- // shape as a lint gate that checks nothing and passes, which this repo has
122
- // already paid for once (docs/research/scout-design.md:344). A disable is only safe
123
- // when it is loud, so the CI shell warns on a disabled ceiling.
124
- export function evaluateBudgetGate(
125
- estimatedCostUsd: number,
126
- budgetUsd: number,
127
- ): BudgetGateVerdict {
128
- if (budgetUsd <= 0) return { allowed: true };
129
- if (estimatedCostUsd <= budgetUsd) return { allowed: true };
130
- return {
131
- allowed: false,
132
- reason:
133
- `estimated cost ${usd(estimatedCostUsd)} exceeds the ` +
134
- `${usd(budgetUsd)} budget ceiling`,
135
- };
145
+ // A subscription or free route is never skipped: its runs draw on quota, and
146
+ // only API spend counts toward the limits (L54, "counts": "api_only"). In a run
147
+ // whose roles bill differently, the estimate compared is the API share when the
148
+ // platform split it per role (S17); without the split it is the whole estimate,
149
+ // the conservative side.
150
+ export function evaluatePlatformLimits(input: {
151
+ billingMode: CiBillingMode;
152
+ limits: PlatformLimits | undefined;
153
+ roleBilling?: ModelRoleBilling;
154
+ }): PlatformLimitsVerdict {
155
+ const { limits } = input;
156
+ if (input.billingMode !== "metered" || limits === undefined) {
157
+ return { allowed: true };
158
+ }
159
+ // Metered by the Claude env alone (an API key present) while no resolved role
160
+ // routes to it: the run bills no API spend, so it is never skipped (#551 R001).
161
+ // No role map (routes unresolved) keeps the conservative whole-estimate path.
162
+ if (
163
+ input.roleBilling !== undefined &&
164
+ input.roleBilling.size > 0 &&
165
+ !hasApiBilledRole(input.roleBilling)
166
+ ) {
167
+ return { allowed: true };
168
+ }
169
+ const { reviewUsd, monthLeftUsd, estimateUsd } = limits;
170
+ if (monthLeftUsd !== undefined && monthLeftUsd <= 0) {
171
+ return { allowed: false, hit: "month-used-up" };
172
+ }
173
+ if (estimateUsd === undefined) return { allowed: true };
174
+ const share = apiShareUsd(limits, input.roleBilling);
175
+ const compared = share ?? estimateUsd;
176
+ const basis = share === undefined ? {} : { apiShare: true as const };
177
+ if (reviewUsd !== undefined && compared > reviewUsd) {
178
+ return { allowed: false, hit: "review-limit", ...basis };
179
+ }
180
+ if (monthLeftUsd !== undefined && compared > monthLeftUsd) {
181
+ return { allowed: false, hit: "month-left", ...basis };
182
+ }
183
+ return { allowed: true };
136
184
  }
137
185
 
138
186
  // ---------------------------------------------------------------------------
@@ -214,27 +262,35 @@ function buildSizeSkipComment(
214
262
  return `${lines.join("\n")}\n`;
215
263
  }
216
264
 
217
- // What a platform repository can do about a budget skip (cryskai/platform#12):
218
- // it has no `budget-usd` input to raise, and what a review costs is the model
219
- // setup chosen in the dashboard.
220
- const PLATFORM_BUDGET_SKIP_HINT =
221
- "To change what reviews cost, change the model setup in the Crysk dashboard.";
265
+ // What a platform repository can do about a limits skip: the limits are
266
+ // dashboard settings (Review > Limits), not workflow inputs.
267
+ const LIMIT_SKIP_REASON: Record<PlatformLimitHit, string> = {
268
+ "month-used-up":
269
+ "⚠️ This organization's monthly review limit is used up for this calendar month.",
270
+ "review-limit":
271
+ "⚠️ The estimated cost of this review is over the per-review limit.",
272
+ "month-left":
273
+ "⚠️ The estimated cost of this review is more than what is left of this organization's monthly limit.",
274
+ };
275
+
276
+ // A mixed setup is compared on the part of the estimate that runs on an API
277
+ // key; the notice says so, because the estimate the reader may know is larger.
278
+ const API_SHARE_LINE =
279
+ "Only the part of the estimate that runs on an API key (its API share) " +
280
+ "was compared with the limit.";
222
281
 
223
282
  function buildBudgetSkipComment(data: SkipBudgetSummary): string {
224
- const platformConnected = data.platformConnected === true;
225
283
  const lines = [
226
284
  SKIP_BUDGET_COMMENT_MARKER,
227
285
  "## Crysk review skipped",
228
286
  "",
229
- `⚠️ The estimated review cost (${usd(data.estimatedCostUsd)}) exceeds ` +
230
- `the configured CI budget ceiling (${usd(data.budgetUsd)}).`,
287
+ LIMIT_SKIP_REASON[data.limit],
288
+ ...(data.apiShare === true ? ["", API_SHARE_LINE] : []),
231
289
  "",
232
- platformConnected
233
- ? PLATFORM_BUDGET_SKIP_HINT
234
- : "Crysk did not run to stay within the configured `--budget-usd` " +
235
- "ceiling.",
290
+ "Crysk did not run to stay within the limits set in the Crysk dashboard " +
291
+ "(Review > Limits). Raise the limit there to review later pushes.",
236
292
  "",
237
- ciForceReviewHintLine(data.prNumber, platformConnected),
293
+ ciForceReviewHintLine(data.prNumber, true),
238
294
  ];
239
295
  return `${lines.join("\n")}\n`;
240
296
  }
@@ -280,62 +336,34 @@ export function ciSizeGateSkip(input: CiSizeGateSkipInput): CiGateSkip | null {
280
336
  };
281
337
  }
282
338
 
283
- export interface CiBudgetGateSkipInput {
339
+ export interface CiLimitsGateSkipInput {
284
340
  isCi: boolean;
285
- estimatedCostUsd: number;
286
- budgetUsd: number;
341
+ billingMode: CiBillingMode;
342
+ limits: PlatformLimits | undefined;
343
+ // The run's roles that bill an API key, for the estimate split (S17).
344
+ roleBilling?: ModelRoleBilling;
287
345
  prNumber: number;
288
- // The run came through the Crysk platform (CRYSK_PLATFORM_CONNECTED): the
289
- // skip names only what applies to a platform repository.
290
- platformConnected?: boolean;
291
346
  }
292
347
 
293
- export function ciBudgetGateSkip(
294
- input: CiBudgetGateSkipInput,
348
+ export function ciLimitsGateSkip(
349
+ input: CiLimitsGateSkipInput,
295
350
  ): CiGateSkip | null {
296
- const verdict = evaluateBudgetGate(input.estimatedCostUsd, input.budgetUsd);
297
- if (!input.isCi || verdict.allowed) return null;
351
+ if (!input.isCi) return null;
352
+ const verdict = evaluatePlatformLimits(input);
353
+ if (verdict.allowed) return null;
298
354
  const summary: SkipBudgetSummary = {
299
355
  kind: "skipped-budget",
300
356
  prNumber: input.prNumber,
301
- estimatedCostUsd: input.estimatedCostUsd,
302
- budgetUsd: input.budgetUsd,
303
- ...(input.platformConnected === true ? { platformConnected: true } : {}),
357
+ limit: verdict.hit,
358
+ ...(verdict.apiShare === true ? { apiShare: true as const } : {}),
304
359
  };
305
360
  return { comment: buildBudgetSkipComment(summary), summary };
306
361
  }
307
362
 
308
363
  // ---------------------------------------------------------------------------
309
- // Disabled-ceiling warning — spec 3.1: "Because a silent disable is
310
- // indistinguishable from a passing gate, the CI shell MUST emit a
311
- // `::warning::` workflow command noting that the budget ceiling is
312
- // disabled." Only for an EXPLICIT <= 0 — `undefined` (the flag was never
313
- // given) means no ceiling was ever configured, so there is nothing to warn
314
- // about disabling. The shell wraps this message with
315
- // `formatWorkflowCommand("warning", ...)` (ci/reporter.ts); this module only
316
- // decides whether to and builds the text, never the annotation syntax.
317
- // ---------------------------------------------------------------------------
318
-
319
- export function budgetDisabledWarningMessage(
320
- budgetUsd: number | undefined,
321
- ): string | null {
322
- if (budgetUsd === undefined || budgetUsd > 0) return null;
323
- return (
324
- "budget-usd ceiling is disabled (<= 0 was configured); estimated cost " +
325
- "is unconstrained for this CI run. The size gate is resolved " +
326
- "separately."
327
- );
328
- }
329
-
330
- // ---------------------------------------------------------------------------
331
- // Route-aware ceiling resolution (issue #156). The budget gate compares
332
- // `estimate.high` — a TOKEN-derived figure — against a real-dollar ceiling.
333
- // On a Claude subscription route the real cash cost of a run is $0.00, so the
334
- // shipped $10 default refused to do work over an overrun that cannot happen,
335
- // and a skipped review is indistinguishable from a clean one to anyone
336
- // reading the checks (this module's own doctrine, ~110-115; ci/setup.ts:50-63).
337
- // So: no ceiling by default on a subscription route, the default ceiling on a
338
- // metered one, and an explicit operator value honoured verbatim on either.
364
+ // How the run bills (issue #156). The size gate's route-aware limits and the
365
+ // platform limits gate both read it: a subscription route has no per-token
366
+ // invoice, so the platform's dollar limits never skip it.
339
367
  // ---------------------------------------------------------------------------
340
368
 
341
369
  export type CiBillingMode = "subscription" | "metered";
@@ -425,64 +453,6 @@ export function deriveCiBillingMode(
425
453
  : "subscription";
426
454
  }
427
455
 
428
- export const CI_DEFAULT_METERED_BUDGET_USD = 10;
429
-
430
- export interface CiBudgetCeiling {
431
- // `undefined` means NO ceiling — the gate does not run at all. Distinct from
432
- // a `0` ceiling, which reaches `evaluateBudgetGate` and is allowed there by
433
- // the `<= 0` convention; the two arrive by different routes and the shell
434
- // announces them with different messages.
435
- budgetUsd: number | undefined;
436
- source: "operator" | "default-metered" | "unlimited-subscription";
437
- }
438
-
439
- // Total over the four cases. `source` exists so the caller can tell the two
440
- // no-ceiling outcomes apart without re-deriving why.
441
- //
442
- // An explicitly configured value is honoured verbatim on ANY route — that is
443
- // how an operator imposes a ceiling on a subscription (`budget-usd: 5`) or
444
- // removes one on a metered route (`budget-usd: 0`, which still reaches
445
- // `budgetDisabledWarningMessage`). The `configured !== undefined` test is what
446
- // keeps 0 and negatives on the operator branch: falling back to a truthiness
447
- // check would swallow the explicit disable and silently reimpose the $10 the
448
- // operator just removed.
449
- export function resolveCiBudgetCeiling(input: {
450
- configured: number | undefined;
451
- billingMode: CiBillingMode;
452
- }): CiBudgetCeiling {
453
- if (input.configured !== undefined) {
454
- return { budgetUsd: input.configured, source: "operator" };
455
- }
456
- if (input.billingMode === "metered") {
457
- return {
458
- budgetUsd: CI_DEFAULT_METERED_BUDGET_USD,
459
- source: "default-metered",
460
- };
461
- }
462
- return { budgetUsd: undefined, source: "unlimited-subscription" };
463
- }
464
-
465
- // The loudness half. `unlimited-subscription` produces no ceiling and would
466
- // otherwise be silent, which is the exact shape this module already refuses
467
- // for the `<= 0` case: a disable is only safe when it is loud.
468
- //
469
- // Kept SEPARATE from `budgetDisabledWarningMessage`, and separate in register
470
- // too — a NOTE, not a warning. The operator chose nothing wrong here; they
471
- // configured nothing and the policy resolved. Merging the two would tell
472
- // someone who never set `budget-usd` that they disabled something.
473
- export function budgetUnlimitedNoticeMessage(
474
- ceiling: CiBudgetCeiling,
475
- ): string | null {
476
- if (ceiling.source !== "unlimited-subscription") return null;
477
- return (
478
- "no budget-usd ceiling was applied: this route has no per-token invoice " +
479
- "credential (a Claude subscription or a free route), so a run draws on " +
480
- "quota rather than a per-token invoice and the estimated cost is not a " +
481
- "dollar figure to gate on. The size gate resolves from the route separately. " +
482
- "Set `budget-usd: <n>` to impose a ceiling anyway."
483
- );
484
- }
485
-
486
456
  // ---------------------------------------------------------------------------
487
457
  // Route-aware size limits — the size gate's half of the #156 policy above.
488
458
  // The size gate is a COST and predictability gate (review/size-gate.ts's own
@@ -566,7 +536,7 @@ export function sizeGateUnlimitedNoticeMessage(
566
536
 
567
537
  // ---------------------------------------------------------------------------
568
538
  // CI skip plan — the ONE call reviewPr's shell makes per gate. Composes
569
- // ciSizeGateSkip/ciBudgetGateSkip's {comment, summary} with renderStepSummary
539
+ // ciSizeGateSkip/ciLimitsGateSkip's {comment, summary} with renderStepSummary
570
540
  // (ci/reporter.ts) and the $GITHUB_OUTPUT contract into everything the shell
571
541
  // needs to publish, so the shell's own job is pure mechanical glue: post
572
542
  // `comment` under `markerPrefix` if `--post`, append `summaryMarkdown` if
@@ -587,11 +557,7 @@ export interface CiGateSkipPlan {
587
557
  }
588
558
 
589
559
  // Spec 1.1's $GITHUB_OUTPUT contract for a skip: no review ran, so every
590
- // finding count is 0 and there is no run dir. `estimatedCostUsd` is 0 for a
591
- // size skip (the gate fires before any cost estimate exists) and the
592
- // estimate that tripped the ceiling for a budget skip — the same number the
593
- // comment and summary already show (this module's own "same numbers"
594
- // doctrine, see the module header).
560
+ // finding count is 0 and there is no run dir.
595
561
  export function ciGateSkipOutputs(
596
562
  status:
597
563
  | "skipped-size"
@@ -599,14 +565,12 @@ export function ciGateSkipOutputs(
599
565
  | "skipped-coverage"
600
566
  | "skipped-excluded"
601
567
  | "manual-required",
602
- estimatedCostUsd: number,
603
568
  ): CiOutputs {
604
569
  return {
605
570
  status,
606
571
  findings_count: 0,
607
572
  blocking_count: 0,
608
573
  advisory_count: 0,
609
- cost_usd_est: estimatedCostUsd,
610
574
  run_dir: "",
611
575
  };
612
576
  }
@@ -620,7 +584,7 @@ export function planCiSizeSkip(
620
584
  comment: skip.comment,
621
585
  markerPrefix: SKIP_SIZE_COMMENT_MARKER,
622
586
  summaryMarkdown: renderStepSummary(skip.summary, input.ciMode),
623
- outputs: ciGateSkipOutputs("skipped-size", 0),
587
+ outputs: ciGateSkipOutputs("skipped-size"),
624
588
  };
625
589
  }
626
590
 
@@ -645,25 +609,25 @@ export function planCiExcludedSkip(input: {
645
609
  },
646
610
  input.ciMode,
647
611
  ),
648
- outputs: ciGateSkipOutputs("skipped-excluded", 0),
612
+ outputs: ciGateSkipOutputs("skipped-excluded"),
649
613
  };
650
614
  }
651
615
 
652
- export function planCiBudgetSkip(
653
- input: CiBudgetGateSkipInput & { force: boolean; ciMode: CiMode },
616
+ export function planCiLimitsSkip(
617
+ input: CiLimitsGateSkipInput & { force: boolean; ciMode: CiMode },
654
618
  ): CiGateSkipPlan | null {
655
619
  // CI `--force` is the `/crysk review` comment. It answers "run this one
656
- // anyway" for every CI skip, including the spend ceiling. Outside that
657
- // explicit comment the ceiling still holds. Local `--force` never reaches
658
- // here: the caller only invokes this plan when `isCi` is set.
620
+ // anyway" for every CI skip, including the platform limits. The platform
621
+ // also omits the limits for a forced dispatch. Local `--force` never
622
+ // reaches here: the caller only invokes this plan when `isCi` is set.
659
623
  if (input.force) return null;
660
- const skip = ciBudgetGateSkip(input);
624
+ const skip = ciLimitsGateSkip(input);
661
625
  if (skip === null) return null;
662
626
  return {
663
627
  comment: skip.comment,
664
628
  markerPrefix: SKIP_BUDGET_COMMENT_MARKER,
665
629
  summaryMarkdown: renderStepSummary(skip.summary, input.ciMode),
666
- outputs: ciGateSkipOutputs("skipped-budget", input.estimatedCostUsd),
630
+ outputs: ciGateSkipOutputs("skipped-budget"),
667
631
  };
668
632
  }
669
633
 
@@ -743,10 +707,12 @@ function buildManualRequiredComment(
743
707
  "",
744
708
  "What the gate does with the next pushes: no review reads them, so it never turns green on its own. " +
745
709
  "A red verdict stays red while a blocking finding is unanswered. A green verdict, or a red one whose " +
746
- "blocking findings all have a reply from someone with write access (`applied`, or a `dismissed` the " +
747
- "CI adjudicator upheld), waits as `pending` until a review verifies the head or " +
748
- `${commandHint(OVERRIDE_COMMAND)} merges it unverified. Reply before you push: the gate reads the ` +
749
- "replies when the push arrives.",
710
+ "blocking findings all have a reply from someone with write access, waits as `pending` until a review " +
711
+ "verifies the head or " +
712
+ `${commandHint(OVERRIDE_COMMAND)} merges it unverified. A reply counts when it is posted in the ` +
713
+ "finding's thread and starts with `applied` (a plain comment is enough), or when it is a `dismissed` " +
714
+ "the CI adjudicator upheld (`crysk triage reply`). Reply before you push: the gate reads the replies " +
715
+ "when the push arrives.",
750
716
  "",
751
717
  "The existing review comment still describes the last head Crysk reviewed.",
752
718
  "",
@@ -833,7 +799,7 @@ export function planCiReviewSkip(input: {
833
799
  ),
834
800
  markerPrefix: SKIP_COVERAGE_COMMENT_MARKER,
835
801
  summaryMarkdown: renderStepSummary(summary, input.ciMode),
836
- outputs: ciGateSkipOutputs("skipped-coverage", 0),
802
+ outputs: ciGateSkipOutputs("skipped-coverage"),
837
803
  };
838
804
  }
839
805
 
@@ -866,7 +832,7 @@ export function planCiReviewManualRequired(input: {
866
832
  ),
867
833
  markerPrefix: MANUAL_REQUIRED_COMMENT_MARKER,
868
834
  summaryMarkdown: renderStepSummary(summary, input.ciMode),
869
- outputs: ciGateSkipOutputs("manual-required", 0),
835
+ outputs: ciGateSkipOutputs("manual-required"),
870
836
  };
871
837
  }
872
838
 
@@ -889,7 +855,6 @@ export function planCiReview(input: {
889
855
  prNumber: number;
890
856
  headSha: string;
891
857
  findings: readonly Finding[];
892
- costUsdEst: number;
893
858
  wallMs: number;
894
859
  model: string;
895
860
  repoWebUrl?: string;
@@ -905,7 +870,6 @@ export function planCiReview(input: {
905
870
  prNumber: input.prNumber,
906
871
  headSha: input.headSha,
907
872
  findings: input.findings,
908
- costUsdEst: input.costUsdEst,
909
873
  wallMs: input.wallMs,
910
874
  model: input.model,
911
875
  ...(input.repoWebUrl === undefined ? {} : { repoWebUrl: input.repoWebUrl }),
@@ -918,7 +882,6 @@ export function planCiReview(input: {
918
882
  findings_count: input.findings.length,
919
883
  blocking_count: blockingCount,
920
884
  advisory_count: input.findings.length - blockingCount,
921
- cost_usd_est: input.costUsdEst,
922
885
  run_dir: input.runDir,
923
886
  },
924
887
  };
@@ -951,7 +914,7 @@ export function shouldWriteCiOutputs(
951
914
 
952
915
  // Spec 2.1: step-summary writing is additionally gated on the tri-state
953
916
  // `--step-summary`/`--no-step-summary` flag (`stepSummary`), unset meaning
954
- // the shell's own default of on — mirroring `summary`/`scout`'s own
917
+ // the shell's own default of on — mirroring `summary`'s own
955
918
  // unset-means-default convention (preflight.ts's CliOptions).
956
919
  export function shouldWriteStepSummary(
957
920
  isCi: boolean,
package/src/ci/outcome.ts CHANGED
@@ -1191,10 +1191,6 @@ const ENGINE_DEFECT_ISSUE =
1191
1191
  'gh issue create -R cryskai/crysk --title "CRYSK-ENGINE-DEFECT {detail}" --body "{runUrl}"';
1192
1192
  const RERUN_FAILED = "$ gh run rerun {runId} --failed";
1193
1193
  const REVIEW_AGAIN = '$ gh pr comment {pr} --body "/crysk review"';
1194
- // A workflow set up before the rename filters only `/pr-hero`, and the
1195
- // floating action tag still delivers this text to it.
1196
- const LEGACY_REVIEW_NOTE =
1197
- "On a workflow set up before the rename, comment `/pr-hero review` instead.";
1198
1194
  // The OpenCode secrets (S8): one per provider, <PROVIDER> being the provider id
1199
1195
  // uppercased with `-` and `.` as `_` (opencodeSecretToken in crysk-secrets.ts,
1200
1196
  // which this module cannot import: see the builtins-only guard).
@@ -1390,11 +1386,7 @@ function single(
1390
1386
 
1391
1387
  const PROVIDER_LIMITED: CatalogVariant = {
1392
1388
  why: "the provider has throttled this account or key, so an immediate retry would fail the same way",
1393
- fixes: [
1394
- "Wait, or raise the quota, then ask for a new review:",
1395
- REVIEW_AGAIN,
1396
- LEGACY_REVIEW_NOTE,
1397
- ],
1389
+ fixes: ["Wait, or raise the quota, then ask for a new review:", REVIEW_AGAIN],
1398
1390
  annotationFix: `wait for the limit to reset or raise the quota, then comment ${commandHint("/crysk review", "")} on the PR`,
1399
1391
  };
1400
1392
 
@@ -1535,7 +1527,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1535
1527
  "Or run on the subscription: set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order).",
1536
1528
  "Then ask for a new review:",
1537
1529
  REVIEW_AGAIN,
1538
- LEGACY_REVIEW_NOTE,
1539
1530
  ],
1540
1531
  annotationFix:
1541
1532
  "create a new key and run `gh secret set {secret}`, or set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order)",
@@ -1546,7 +1537,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1546
1537
  "$ claude setup-token && gh secret set {secret}",
1547
1538
  "Then ask for a new review:",
1548
1539
  REVIEW_AGAIN,
1549
- LEGACY_REVIEW_NOTE,
1550
1540
  ],
1551
1541
  annotationFix:
1552
1542
  "log in again with `claude setup-token` and set `{secret}` (`gh secret set {secret}`)",
@@ -1560,7 +1550,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1560
1550
  "$ gh secret set {secret}",
1561
1551
  "Then ask for a new review:",
1562
1552
  REVIEW_AGAIN,
1563
- LEGACY_REVIEW_NOTE,
1564
1553
  ],
1565
1554
  annotationFix:
1566
1555
  "create a new key with the provider and run `gh secret set {secret}`",
@@ -1575,7 +1564,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1575
1564
  "$ gh secret set CRYSK_OPENCODE_OPENAI_API_KEY",
1576
1565
  "Then ask for a new review:",
1577
1566
  REVIEW_AGAIN,
1578
- LEGACY_REVIEW_NOTE,
1579
1567
  ],
1580
1568
  annotationFix:
1581
1569
  "log in again with `opencode auth login`, choose ChatGPT and set {secret} from its record, or set CRYSK_OPENCODE_OPENAI_API_KEY and stop passing {secret} to bill per token",
@@ -1590,7 +1578,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1590
1578
  OPENCODE_API_KEY_SECRET,
1591
1579
  "Then ask for a new review:",
1592
1580
  REVIEW_AGAIN,
1593
- LEGACY_REVIEW_NOTE,
1594
1581
  ],
1595
1582
  annotationFix:
1596
1583
  "replace the credential in {secret} with a new one, then run `gh secret set {secret}`",
@@ -1866,7 +1853,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1866
1853
  "Add credit to the Anthropic account behind the API key (Claude Console → Plans & Billing), or run on the subscription: set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order).",
1867
1854
  "Then ask for a new review:",
1868
1855
  REVIEW_AGAIN,
1869
- LEGACY_REVIEW_NOTE,
1870
1856
  ],
1871
1857
  annotationFix:
1872
1858
  "add credit to the Anthropic account behind the API key (Claude Console → Plans & Billing), or set CRYSK_CLAUDE_OAUTH_TOKEN and put subscription first in `credentials.claude` (the default order)",
@@ -1879,7 +1865,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1879
1865
  fixes: [
1880
1866
  "Re-run after the limit resets (the reset time is in the sentence above):",
1881
1867
  REVIEW_AGAIN,
1882
- LEGACY_REVIEW_NOTE,
1883
1868
  "Or bill per token: set CRYSK_CLAUDE_API_KEY and put api_key first in `credentials.claude` (the default order uses the subscription while it is set):",
1884
1869
  "$ gh secret set CRYSK_CLAUDE_API_KEY",
1885
1870
  ],
@@ -1894,7 +1879,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1894
1879
  fixes: [
1895
1880
  "Wait for the limit to reset, or add credit or raise the quota on the provider account behind the key, then ask for a new review:",
1896
1881
  REVIEW_AGAIN,
1897
- LEGACY_REVIEW_NOTE,
1898
1882
  "Or set a key from an account that has quota:",
1899
1883
  "$ gh secret set {secret}",
1900
1884
  ],
@@ -1907,7 +1891,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1907
1891
  fixes: [
1908
1892
  "Re-run after the limit resets:",
1909
1893
  REVIEW_AGAIN,
1910
- LEGACY_REVIEW_NOTE,
1911
1894
  OPENAI_API_KEY_INSTEAD,
1912
1895
  "$ gh secret set CRYSK_OPENCODE_OPENAI_API_KEY",
1913
1896
  ],
@@ -1932,12 +1915,7 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1932
1915
  what: "the request was refused",
1933
1916
  variants: single(
1934
1917
  PROVIDER_REFUSED_WHY,
1935
- [
1936
- "Ask for a new review once:",
1937
- REVIEW_AGAIN,
1938
- LEGACY_REVIEW_NOTE,
1939
- "If it repeats, report it.",
1940
- ],
1918
+ ["Ask for a new review once:", REVIEW_AGAIN, "If it repeats, report it."],
1941
1919
  "ask for a new review once, and report it if the provider refuses again",
1942
1920
  ),
1943
1921
  },
@@ -1976,7 +1954,6 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
1976
1954
  fixes: [
1977
1955
  "Lower `max-changed-lines` in the workflow's `with:` block (or `max_changed_lines` in the repo config), or exclude paths in `.cryskignore` (`.prheroignore` in a repo set up before the rename), then ask for a new review:",
1978
1956
  REVIEW_AGAIN,
1979
- LEGACY_REVIEW_NOTE,
1980
1957
  ],
1981
1958
  annotationFix:
1982
1959
  "lower `max-changed-lines` (or `max_changed_lines` in the repo config) or exclude paths in `.cryskignore` (`.prheroignore` before the rename)",
@@ -2009,12 +1986,8 @@ export const ERROR_CATALOG: Readonly<Record<ErrorCode, CatalogEntry>> = {
2009
1986
  what: "The review was cancelled or superseded by a newer push",
2010
1987
  variants: single(
2011
1988
  "a newer run replaces this one, so this result would describe an outdated head",
2012
- [
2013
- "Ask for a review of the current head:",
2014
- REVIEW_AGAIN,
2015
- LEGACY_REVIEW_NOTE,
2016
- ],
2017
- 'ask for a review of the current head with `gh pr comment {pr} --body "/crysk review"` (or "/pr-hero review" on a workflow set up before the rename)',
1989
+ ["Ask for a review of the current head:", REVIEW_AGAIN],
1990
+ 'ask for a review of the current head with `gh pr comment {pr} --body "/crysk review"`',
2018
1991
  ),
2019
1992
  },
2020
1993
  };