crysk 0.7.0 → 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 (133) hide show
  1. package/README.md +27 -23
  2. package/dist/SKILL-1q3658n0.md +74 -0
  3. package/dist/SKILL-25j4q9b8.md +143 -0
  4. package/dist/SKILL-4747bhne.md +143 -0
  5. package/dist/SKILL-4jc3sv23.md +74 -0
  6. package/dist/SKILL-c0492rch.md +540 -0
  7. package/dist/SKILL-d1nzkhhr.md +74 -0
  8. package/dist/SKILL-f8p7kvx0.md +143 -0
  9. package/dist/SKILL-gxd45g38.md +553 -0
  10. package/dist/SKILL-rec41991.md +66 -0
  11. package/dist/SKILL-zze8zj5g.md +536 -0
  12. package/dist/cli.js +24658 -24654
  13. package/dist/index.js +492 -463
  14. package/dist/opencode-ci-qrcv7a99.md +106 -0
  15. package/dist/opencode-ci-rdpcc7xc.md +106 -0
  16. package/dist/opencode-ci-yt0k74t0.md +106 -0
  17. package/dist/workflow-andv2dvm.yml +158 -0
  18. package/package.json +1 -1
  19. package/prompts/default/PROVENANCE.md +1 -0
  20. package/skills/crysk/SKILL.md +6 -6
  21. package/skills/crysk-ci-setup/SKILL.md +32 -33
  22. package/skills/crysk-ci-setup/assets/workflow.yml +5 -10
  23. package/skills/crysk-ci-setup/references/ci-admission.md +5 -5
  24. package/skills/crysk-ci-setup/references/opencode-ci.md +6 -6
  25. package/skills/crysk-loop/SKILL.md +37 -54
  26. package/skills/crysk-pr/SKILL.md +1 -1
  27. package/src/asset-manifest.ts +0 -6
  28. package/src/assets.ts +1 -4
  29. package/src/brand.ts +20 -30
  30. package/src/ci/gates.ts +155 -201
  31. package/src/ci/outcome.ts +4 -31
  32. package/src/ci/platform-limits.ts +135 -0
  33. package/src/ci/platform-report.ts +212 -126
  34. package/src/ci/platform.ts +28 -26
  35. package/src/ci/reporter.ts +25 -26
  36. package/src/ci/review-admission.ts +1 -2
  37. package/src/ci/review-levels.ts +12 -53
  38. package/src/ci/setup.ts +96 -66
  39. package/src/ci/trace-bundle.ts +11 -27
  40. package/src/ci/trace-transcripts.ts +4 -6
  41. package/src/ci/trigger.ts +3 -5
  42. package/src/cli.ts +6 -5
  43. package/src/commands/ci-setup-questions.ts +2 -55
  44. package/src/commands/ci-setup.ts +2 -26
  45. package/src/commands/triage.ts +131 -38
  46. package/src/commands/usage.ts +0 -1
  47. package/src/compare/compare.ts +3 -3
  48. package/src/compare/floor-test.ts +30 -201
  49. package/src/config/config.ts +6 -30
  50. package/src/diversity/accounting.ts +0 -26
  51. package/src/diversity/benchmark.ts +1 -17
  52. package/src/diversity/identity.ts +0 -14
  53. package/src/diversity/pipeline-integration.ts +0 -29
  54. package/src/doctor.ts +3 -6
  55. package/src/execution/claude-session-trace.ts +7 -2
  56. package/src/execution/contracts.ts +15 -9
  57. package/src/execution/harness.ts +165 -187
  58. package/src/execution/spend-limiter.ts +39 -131
  59. package/src/execution/usage-facts.ts +397 -0
  60. package/src/execution/usage-normalized.ts +33 -86
  61. package/src/harness/materiality-judge.ts +0 -5
  62. package/src/harness/pipeline-plan.ts +0 -3
  63. package/src/harness/replay-rows.ts +0 -5
  64. package/src/harness/route-runner.ts +2 -2
  65. package/src/harness/single-step.ts +3 -9
  66. package/src/index.ts +1 -1
  67. package/src/mcp/preflight.ts +2 -2
  68. package/src/model/catalog.ts +1 -3
  69. package/src/model/free-discovery.ts +11 -78
  70. package/src/model/model-name.ts +14 -4
  71. package/src/model/profiles/claude.ts +1 -2
  72. package/src/model/profiles/openai.ts +1 -2
  73. package/src/model/profiles.ts +1 -2
  74. package/src/model/provider-capabilities.ts +16 -55
  75. package/src/model/routing.ts +39 -36
  76. package/src/pr/admission.ts +6 -6
  77. package/src/pr/answered-findings.ts +8 -4
  78. package/src/pr/ci-publish.ts +0 -2
  79. package/src/pr/discovery.ts +4 -25
  80. package/src/pr/plan.ts +40 -121
  81. package/src/pr/pr-status.ts +14 -2
  82. package/src/pr/preflight.ts +15 -12
  83. package/src/pr/publish-outcome.ts +1 -19
  84. package/src/pr/review-pr.ts +10 -47
  85. package/src/pr/target.ts +76 -82
  86. package/src/production-runtime.ts +52 -114
  87. package/src/progress.ts +0 -54
  88. package/src/rereview/prepare.ts +4 -1
  89. package/src/rereview/state.ts +1 -1
  90. package/src/review/boundary.ts +4 -8
  91. package/src/review/drafts.ts +3 -3
  92. package/src/review/findings-conformance.ts +1 -1
  93. package/src/review/findings.ts +0 -4
  94. package/src/review/pipeline.ts +57 -395
  95. package/src/review/preflight.ts +162 -201
  96. package/src/review/prompt-set.ts +0 -2
  97. package/src/review/report.ts +2 -162
  98. package/src/review/review.ts +16 -65
  99. package/src/review/route-preflight.ts +3 -35
  100. package/src/review/run.ts +37 -73
  101. package/src/review/size-gate.ts +3 -3
  102. package/src/review/spec.ts +6 -11
  103. package/src/review/step-runner.ts +4 -4
  104. package/src/runner-authority.ts +10 -9
  105. package/src/security/credential-broker.ts +5 -6
  106. package/src/server/preflight.ts +0 -1
  107. package/src/server/server.ts +17 -6
  108. package/src/store/activity.ts +1 -2
  109. package/src/store/backfill-preflight.ts +0 -3
  110. package/src/store/backfill.ts +0 -1
  111. package/src/store/metrics-preflight.ts +4 -14
  112. package/src/store/metrics.ts +5 -5
  113. package/src/store/preflight.ts +0 -13
  114. package/src/store/store.ts +11 -12
  115. package/src/transport-registry.ts +6 -30
  116. package/src/transports/claude-code-cli.ts +149 -215
  117. package/src/transports/opencode-client.ts +4 -24
  118. package/src/transports/opencode-sdk.ts +17 -112
  119. package/src/triage/plain-reply.ts +37 -0
  120. package/src/ui/activity.ts +1 -6
  121. package/src/ui/config-edit.ts +14 -67
  122. package/src/ui/config.ts +3 -8
  123. package/src/ui/plan.ts +11 -198
  124. package/src/ui/progress.ts +3 -49
  125. package/src/ui/result.ts +18 -77
  126. package/src/ui/review-menu.ts +3 -12
  127. package/src/ui/select.ts +9 -79
  128. package/src/updater.ts +1 -1
  129. package/src/usage.ts +1 -7
  130. package/prompts/default/deep-review-parity.md +0 -152
  131. package/prompts/scout.md +0 -140
  132. package/src/ci/platform-estimate.ts +0 -111
  133. package/src/review/scout.ts +0 -323
@@ -21,7 +21,7 @@
21
21
  // for the emoji mapping, blob-link builder, compact duration format, and
22
22
  // the re-review delta's data shape — the same severity glyph and blob URL a
23
23
  // reader sees on the PR comment must be the one this job summary shows.
24
- // `deltaLine`/`usd`/`code`/`severityRank` stay PRIVATE in report.ts, so this
24
+ // `deltaLine`/`code`/`severityRank` stay PRIVATE in report.ts, so this
25
25
  // module writes small local equivalents rather than exporting report.ts
26
26
  // internals for a single extra caller.
27
27
 
@@ -44,6 +44,7 @@ import {
44
44
  } from "#review/report";
45
45
  import { log } from "#ui/primitives";
46
46
  import { publishedText } from "../security/published-text";
47
+ import type { PlatformLimitHit } from "./platform-limits";
47
48
 
48
49
  // ---------------------------------------------------------------------------
49
50
  // Workflow commands (`::group::`, `::endgroup::`, `::notice::`, `::warning::`,
@@ -134,7 +135,6 @@ interface CiReviewSummary {
134
135
  prNumber: number;
135
136
  headSha: string;
136
137
  findings: readonly Finding[];
137
- costUsdEst: number;
138
138
  wallMs: number;
139
139
  model: string;
140
140
  // Cosmetic and optional, same contract as renderPrComment's repoWebUrl
@@ -158,10 +158,12 @@ interface CiSkipSizeSummary {
158
158
  interface CiSkipBudgetSummary {
159
159
  kind: "skipped-budget";
160
160
  prNumber: number;
161
- estimatedCostUsd: number;
162
- budgetUsd: number;
163
- // A platform repository has no `--budget-usd` to raise (cryskai/platform#12).
164
- platformConnected?: true;
161
+ // Which platform limit was hit. The limits live in the Crysk dashboard
162
+ // (Review > Limits); the summary names the limit, never a dollar figure.
163
+ limit: PlatformLimitHit;
164
+ // The estimate compared was the API share of a mixed setup, not the whole
165
+ // estimate (S17).
166
+ apiShare?: true;
165
167
  }
166
168
 
167
169
  interface CiSkipExcludedSummary {
@@ -309,10 +311,6 @@ function formatDeltaLine(delta: PrCommentDelta): string {
309
311
  return `${since}: ${delta.resolved} resolved · ${delta.new} new · ${delta.persist} persist`;
310
312
  }
311
313
 
312
- function usd(amount: number): string {
313
- return `$${amount.toFixed(2)}`;
314
- }
315
-
316
314
  // A size limit <= 0 means that knob is off (review/size-gate.ts). Printed as
317
315
  // a number it reads "limit 0", a limit every diff exceeds, and a subscription
318
316
  // route now turns a knob off by default (resolveCiSizeLimits), so the other
@@ -340,20 +338,28 @@ function skipSizeLines(data: CiSkipSizeSummary): string[] {
340
338
  ];
341
339
  }
342
340
 
341
+ const SKIP_BUDGET_REASON: Record<PlatformLimitHit, string> = {
342
+ "month-used-up": "the organization's monthly review limit is used up.",
343
+ "review-limit": "the estimated cost is over the per-review limit.",
344
+ "month-left":
345
+ "the estimated cost is more than what is left of the monthly limit.",
346
+ };
347
+
343
348
  function skipBudgetLines(data: CiSkipBudgetSummary): string[] {
344
349
  return [
345
350
  `### ⚠️ Crysk Review Skipped — PR #${data.prNumber}`,
346
351
  "",
347
- "**Reason:** the estimated cost exceeds the configured budget ceiling.",
352
+ `**Reason:** ${SKIP_BUDGET_REASON[data.limit]}`,
353
+ ...(data.apiShare === true
354
+ ? [
355
+ "",
356
+ "Only the part of the estimate that runs on an API key (its API " +
357
+ "share) was compared with the limit.",
358
+ ]
359
+ : []),
348
360
  "",
349
- "| Metric | Value |",
350
- "| --- | --- |",
351
- `| Estimated cost | ${usd(data.estimatedCostUsd)} (budget ${usd(data.budgetUsd)}) |`,
352
- "",
353
- data.platformConnected === true
354
- ? "To change what reviews cost, change the model setup in the Crysk dashboard."
355
- : "Crysk did not run to stay within the configured `--budget-usd` " +
356
- "ceiling.",
361
+ "Crysk did not run to stay within the limits set in the Crysk dashboard " +
362
+ "(Review > Limits).",
357
363
  ];
358
364
  }
359
365
 
@@ -466,7 +472,6 @@ function reviewedLines(data: CiReviewSummary): string[] {
466
472
  "| --- | --- |",
467
473
  `| Findings | ${data.findings.length} (${blocking.length} blocking · ` +
468
474
  `${advisory.length} advisory) |`,
469
- `| Estimated cost | ${usd(data.costUsdEst)} |`,
470
475
  `| Duration | ${formatElapsed(data.wallMs)} |`,
471
476
  `| Model | ${data.model} |`,
472
477
  "",
@@ -525,10 +530,6 @@ export interface CiOutputs {
525
530
  findings_count: number;
526
531
  blocking_count: number;
527
532
  advisory_count: number;
528
- // Spec 1.1: "cost-usd-est: ... (float string, e.g. `"2.45"`)" — formatted
529
- // to 2 decimals here so every consumer of $GITHUB_OUTPUT reads the same
530
- // fixed-precision string the action.yml output contract promises.
531
- cost_usd_est: number;
532
533
  run_dir: string;
533
534
  }
534
535
 
@@ -541,7 +542,6 @@ export function formatCiOutputs(outputs: CiOutputs): string {
541
542
  `findings_count=${outputs.findings_count}`,
542
543
  `blocking_count=${outputs.blocking_count}`,
543
544
  `advisory_count=${outputs.advisory_count}`,
544
- `cost_usd_est=${outputs.cost_usd_est.toFixed(2)}`,
545
545
  `run_dir=${outputs.run_dir}`,
546
546
  ];
547
547
  return `${lines.join("\n")}\n`;
@@ -633,7 +633,6 @@ export async function reportFatalCiError(
633
633
  findings_count: 0,
634
634
  blocking_count: 0,
635
635
  advisory_count: 0,
636
- cost_usd_est: 0,
637
636
  run_dir: "",
638
637
  }).catch(() => {});
639
638
  }
@@ -17,7 +17,6 @@ import type { LocalConfig } from "#review/preflight";
17
17
  import {
18
18
  findMarker,
19
19
  isCommand,
20
- legacyCommand,
21
20
  MARKER_BRAND_PATTERN,
22
21
  MARKER_OPEN,
23
22
  matchMarkerPrefix,
@@ -801,7 +800,7 @@ export function ciReviewSkipDetail(
801
800
  case "stopped":
802
801
  // A status description has little room, so it names the one spelling
803
802
  // every workflow accepts during the rename.
804
- return `a maintainer stopped automatic reviews; ${legacyCommand(REVIEW_COMMAND)} reviews this head`;
803
+ return `a maintainer stopped automatic reviews; ${REVIEW_COMMAND} reviews this head`;
805
804
  }
806
805
  }
807
806
 
@@ -1,5 +1,5 @@
1
1
  // The choices `setup --ci` asks for, as data: the re-review level presets, the
2
- // gate mode, the spend ceiling, and the advanced keys. Pure, so every choice
2
+ // gate mode, and the advanced keys. Pure, so every choice
3
3
  // and every line of the summary is testable offline; the prompts live in the
4
4
  // command shell (src/commands/ci-setup.ts).
5
5
  //
@@ -10,7 +10,6 @@
10
10
 
11
11
  import type { PostMinSeverity } from "#pr/post-floor";
12
12
  import { DEFAULT_SIZE_GATE } from "#review/size-gate";
13
- import { CI_DEFAULT_METERED_BUDGET_USD } from "./gates";
14
13
  import {
15
14
  DEFAULT_CI_ADVISORY_WEIGHT,
16
15
  DEFAULT_CI_BLOCKING_WEIGHT,
@@ -91,8 +90,6 @@ export function isReviewLevel(value: string): value is ReviewLevel {
91
90
  return (REVIEW_LEVEL_ORDER as readonly string[]).includes(value);
92
91
  }
93
92
 
94
- export type Billing = "subscription" | "api";
95
-
96
93
  export interface AdvancedChoices {
97
94
  ci_blocking_weight?: number;
98
95
  ci_advisory_weight?: number;
@@ -106,14 +103,9 @@ export interface AdvancedChoices {
106
103
  export interface CiSetupChoices {
107
104
  level: ReviewLevel;
108
105
  mode: "gate" | "advisory";
109
- // Undefined: nobody said how the review is paid, so no ceiling is written
110
- // and the action resolves it from the route's billing mode.
111
- billing?: Billing;
112
- // Only with billing "api"; undefined there means the metered default.
113
- budgetUsd?: number;
114
- // Always written. Unlike the budget, a size threshold matters on any route:
115
- // left unset, a subscription route resolves to NO limit, so a huge PR would
116
- // run a review nobody asked for. 0 is the explicit, chosen "no limit".
106
+ // Always written: a size threshold matters on any route. Left unset, a
107
+ // subscription route resolves to NO limit, so a huge PR would run a review
108
+ // nobody asked for. 0 is the explicit, chosen "no limit".
117
109
  maxChangedLines: number;
118
110
  advanced: AdvancedChoices;
119
111
  // True when no human or agent chose: the summary must say so.
@@ -121,13 +113,12 @@ export interface CiSetupChoices {
121
113
  // Which groups someone chose this run. A chosen group overrides the file; an
122
114
  // unchosen one only fills a group the file does not have yet, so re-running
123
115
  // setup (say `--force` to refresh an old workflow) never resets tuned keys.
124
- // `mode` and `billing` guard the workflow the same way: on a --force refresh
125
- // an unchosen one keeps what the old workflow said.
116
+ // `mode` guards the workflow the same way: on a --force refresh an unchosen
117
+ // one keeps what the old workflow said.
126
118
  chosen: {
127
119
  level: boolean;
128
120
  maxChangedLines: boolean;
129
121
  mode: boolean;
130
- billing: boolean;
131
122
  };
132
123
  }
133
124
 
@@ -137,7 +128,6 @@ export interface CurrentSettings {
137
128
  config: Record<string, unknown>;
138
129
  workflow: {
139
130
  mode?: "gate" | "advisory";
140
- budgetUsd?: string;
141
131
  maxChangedLines?: string;
142
132
  maxChangedFiles?: string;
143
133
  };
@@ -168,13 +158,14 @@ export function presetMatching(
168
158
  return "custom";
169
159
  }
170
160
 
171
- // The two inputs setup writes into the workflow, read back from an existing one.
161
+ // The inputs setup writes into the workflow, read back from an existing one.
172
162
  export function parseWorkflowChoices(
173
163
  text: string,
174
164
  ): CurrentSettings["workflow"] {
175
165
  // One input per line, quoted or not, with an optional trailing comment. A
176
- // number must be a whole number (sizes) or a plain decimal (budget): a value
177
- // like `1.2.3` reads as absent rather than becoming NaN in the new file.
166
+ // number must be a whole number: a value like `1.2` reads as absent rather
167
+ // than becoming NaN in the new file. Inputs setup no longer writes (the
168
+ // retired `budget-usd`) are not read, so a re-run drops them.
178
169
  const input = (name: string, value: string): string | undefined =>
179
170
  new RegExp(`^\\s+${name}:\\s*["']?(${value})["']?\\s*(?:#.*)?$`, "m").exec(
180
171
  text,
@@ -183,12 +174,10 @@ export function parseWorkflowChoices(
183
174
  | "gate"
184
175
  | "advisory"
185
176
  | undefined;
186
- const budgetUsd = input("budget-usd", "-?\\d+(?:\\.\\d+)?");
187
177
  const maxChangedLines = input("max-changed-lines", "\\d+");
188
178
  const maxChangedFiles = input("max-changed-files", "\\d+");
189
179
  return {
190
180
  ...(mode === undefined ? {} : { mode }),
191
- ...(budgetUsd === undefined ? {} : { budgetUsd }),
192
181
  ...(maxChangedLines === undefined ? {} : { maxChangedLines }),
193
182
  ...(maxChangedFiles === undefined ? {} : { maxChangedFiles }),
194
183
  };
@@ -204,30 +193,10 @@ export function defaultChoices(): CiSetupChoices {
204
193
  maxChangedLines: DEFAULT_MAX_CHANGED_LINES,
205
194
  advanced: {},
206
195
  defaulted: true,
207
- chosen: {
208
- level: false,
209
- maxChangedLines: false,
210
- mode: false,
211
- billing: false,
212
- },
196
+ chosen: { level: false, maxChangedLines: false, mode: false },
213
197
  };
214
198
  }
215
199
 
216
- // The `budget-usd` workflow input for these choices, or undefined to write none.
217
- // A subscription writes none. CI bills as metered only when the run's chosen
218
- // Claude credential is the API key (S5: the first of `credentials.claude` that is
219
- // present, default subscription then api_key; gates.ts, CiBillingMode), so a
220
- // subscription run already gets no ceiling. An explicit 0 would print the
221
- // disabled-ceiling warning on every run and, worse, stay an operator override if
222
- // the run later moves to an API key, defeating the default ceiling a metered run
223
- // brings back.
224
- export function budgetInput(choices: CiSetupChoices): string | undefined {
225
- if (choices.billing === "api") {
226
- return String(choices.budgetUsd ?? CI_DEFAULT_METERED_BUDGET_USD);
227
- }
228
- return undefined;
229
- }
230
-
231
200
  // How the choices land in .crysk/config.json. `set` overrides; each group in
232
201
  // `fillIfAbsent` is written only when the file has none of its keys, and kept
233
202
  // whole otherwise, so a tuned policy is never half-replaced by a preset.
@@ -284,10 +253,9 @@ export function renderChoicesSummary(
284
253
  ...(effective as AdvancedChoices),
285
254
  ...choices.advanced,
286
255
  };
287
- const budget = budgetInput(choices);
288
256
  const lines = [
289
257
  choices.defaulted
290
- ? "Review settings (defaults: nobody chose them; pass --level, --ci-mode and --billing, or run setup --ci in a terminal, to choose):"
258
+ ? "Review settings (defaults: nobody chose them; pass --level and --ci-mode, or run setup --ci in a terminal, to choose):"
291
259
  : "Review settings:",
292
260
  ...(levelKept.length > 0
293
261
  ? [
@@ -299,15 +267,6 @@ export function renderChoicesSummary(
299
267
  ` verification up to ${c.max_verification_steps} prior findings checked per re-review`,
300
268
  ]),
301
269
  ` gate ${choices.mode === "gate" ? "gate: blocking findings turn the crysk check red" : "advisory: the crysk check stays green"}`,
302
- ` budget ${
303
- budget === undefined
304
- ? choices.billing === "subscription"
305
- ? `not set: no ceiling while the review runs on CRYSK_CLAUDE_OAUTH_TOKEN and no OpenCode model (a subscription spends quota, not dollars); CRYSK_CLAUDE_API_KEY chosen in its place, or an OpenCode model with its CRYSK_OPENCODE_* secret, brings back the $${CI_DEFAULT_METERED_BUDGET_USD} ceiling`
306
- : `not set: resolved from how the review is paid (no ceiling on a subscription, $${CI_DEFAULT_METERED_BUDGET_USD} on an API key)`
307
- : Number(budget) <= 0
308
- ? `none (budget-usd: ${budget}; 0 or less disables the ceiling)`
309
- : `$${budget} per review (budget-usd)`
310
- }`,
311
270
  ` score weights blocking ${a.ci_blocking_weight ?? DEFAULT_CI_BLOCKING_WEIGHT}, advisory ${a.ci_advisory_weight ?? DEFAULT_CI_ADVISORY_WEIGHT}`,
312
271
  ` observe only ${a.ci_admission_observe_only === true ? "yes: skip decisions are logged, every push is reviewed" : "no"}`,
313
272
  ` trusted actors ${a.ci_trusted_actors && a.ci_trusted_actors.length > 0 ? a.ci_trusted_actors.join(", ") : "none beyond the workflow actor"}`,
package/src/ci/setup.ts CHANGED
@@ -76,6 +76,11 @@ import {
76
76
  parseModelsConfig,
77
77
  } from "#model/model-name";
78
78
  import { MODEL_PROFILES, profileModels } from "#model/profiles";
79
+ import {
80
+ agentModelRole,
81
+ agentStepKey,
82
+ type ResolvedRoutePlan,
83
+ } from "#model/routing";
79
84
  import { parseGlobalConfig, parseLocalConfig } from "#review/preflight";
80
85
  import { commandForms } from "../brand";
81
86
  import {
@@ -114,43 +119,19 @@ export const LEGACY_CI_WORKFLOW_RELATIVE_PATH = LEGACY_WORKFLOW_RELATIVE_PATH;
114
119
  // PR that changes it.
115
120
  export interface CiWorkflowTemplateOptions {
116
121
  actionRef?: string;
117
- // Repo-local override for the action's own `budget-usd` default. Omitted
118
- // means "say nothing and inherit the action's default", which is what every
119
- // scaffolded repo gets: raising a stranger's spend ceiling from a template
120
- // they did not choose is not ours to do.
121
- //
122
- // Since issue #156 that inherited default is a POLICY, not a number:
123
- // action.yml's `budget-usd` default is empty, and the CLI resolves the
124
- // ceiling from the route's billing mode (ci/gates.ts's
125
- // `resolveCiBudgetCeiling`) — no ceiling on a Claude subscription, a default
126
- // ceiling on a metered ANTHROPIC_API_KEY route. Inheriting is therefore
127
- // strictly better than it was: a scaffolded repo now gets a ceiling exactly
128
- // when a ceiling means something.
122
+ // Repo-local override for the action's own `max-changed-lines` default.
123
+ // Omitted means "say nothing and inherit the route-derived limit" (none on a
124
+ // subscription, 4000 on a metered key; resolveCiSizeLimits), which every
125
+ // scaffolded repo gets and decides for itself.
129
126
  //
130
- // NOTHING sets this today, this repo included — see OWN_CI_WORKFLOW_OPTIONS
131
- // for why the one override that existed went away. The knob stays because a
132
- // repo that genuinely wants a fixed ceiling on a subscription route needs a
133
- // way to say so, and that is the only thing an explicit value now means.
134
- budgetUsd?: string;
135
- // Repo-local override for the action's own `max-changed-lines` default, and
136
- // omitted for the same reason as `budgetUsd`: a scaffolded repo inherits
137
- // the route-derived limit (none on a subscription, 4000 on a metered key;
138
- // resolveCiSizeLimits) and decides for itself. THIS repo raises it because its
139
- // own slices routinely land near the line — D1-10c was skipped at 1023,
140
- // twenty-three lines over, and a skipped review is indistinguishable from a
141
- // clean one to anyone reading the checks.
127
+ // THIS repo raises it because its own slices routinely land near the line:
128
+ // D1-10c was skipped at 1023, twenty-three lines over, and a skipped review is
129
+ // indistinguishable from a clean one to anyone reading the checks.
142
130
  //
143
131
  // Raising it costs little and risks little HERE. It is a COST gate, never a
144
132
  // quality one — the size<->quality question is unmeasured in this project
145
133
  // (`scripts/scope-probe.ts`), so this number is not a claim that pr-hero
146
134
  // reviews a 1500-line diff as well as a 300-line one.
147
- //
148
- // Since issue #156 it is also the ONLY gate bounding a self-review's scope
149
- // here, which is what the number has to be read against: this comment used
150
- // to lean on `budget-usd` as "the real spend ceiling, which still refuses
151
- // the work outright". On this repo's subscription route it never was — it
152
- // gated `estimate.high`, a token-derived figure, against $0.00 of real
153
- // cash.
154
135
  maxChangedLines?: string;
155
136
  // The files half of the size gate, emitted right after the lines input.
156
137
  maxChangedFiles?: string;
@@ -189,17 +170,7 @@ export const DEFAULT_CI_ACTION_REF = "cryskai/crysk@v0";
189
170
  // leave the committed workflow and the tests disagreeing about what "ours"
190
171
  // means. Nothing a scaffolded repo receives passes through here.
191
172
  //
192
- // `budgetUsd` is "0": the explicit, loud DISABLE, not a ceiling. History:
193
- // it used to be "15.00", because a self-review's diff grows against the base
194
- // every time a finding is answered, so an iterating PR walked toward the
195
- // ceiling exactly when the check mattered most. Issue #156 dropped it on the
196
- // promise that the route's billing mode would apply no ceiling on this repo's
197
- // Claude subscription. That promise did not hold here: the route resolved as
198
- // metered, and #326 (and earlier PRs) skipped at the $10 metered default on
199
- // an `estimate.high` that is not this route's cash cost. A subscription has
200
- // no dollar cost to cap, so this repo opts out explicitly; fixing the
201
- // billing-mode resolution itself is a separate issue. `maxChangedLines`
202
- // stays: that gate is real on any route.
173
+ // `maxChangedLines` stays: that gate is real on any route.
203
174
  //
204
175
  // `cryskSecrets` names the Claude pair (U5): the action stops a run that passes the
205
176
  // removed inputs, so this repo's own review passes CRYSK_* secrets. The repository
@@ -207,7 +178,6 @@ export const DEFAULT_CI_ACTION_REF = "cryskai/crysk@v0";
207
178
  export const OWN_CI_WORKFLOW_OPTIONS: CiWorkflowTemplateOptions = {
208
179
  actionRef: "./",
209
180
  maxChangedLines: "5000",
210
- budgetUsd: "0",
211
181
  mode: "gate",
212
182
  forceEngineFromPr: true,
213
183
  cryskSecrets: ["CRYSK_CLAUDE_OAUTH_TOKEN", "CRYSK_CLAUDE_API_KEY"],
@@ -294,12 +264,6 @@ export function generateCiWorkflowTemplate(
294
264
  ): string {
295
265
  const actionRef = options.actionRef ?? DEFAULT_CI_ACTION_REF;
296
266
  const pinEngine = options.forceEngineFromPr === true;
297
- const budgetLine =
298
- options.budgetUsd === undefined
299
- ? ""
300
- : `\n budget-usd: ${options.budgetUsd}`;
301
- // Emitted before `budget-usd` to mirror action.yml's own declaration order,
302
- // so the generated file reads in the same sequence as the inputs it sets.
303
267
  const sizeGateLine =
304
268
  options.maxChangedLines === undefined
305
269
  ? ""
@@ -405,24 +369,19 @@ export function generateCiWorkflowTemplate(
405
369
 
406
370
  `
407
371
  : "";
408
- // One clause per command and per name, new name first: an Actions expression
409
- // has no regex, so the legacy /pr-hero forms are listed beside /crysk ones.
372
+ // One clause per command form: an Actions expression has no regex.
410
373
  const commandBodies = [
411
374
  REVIEW_COMMAND,
412
375
  RECHECK_COMMAND,
413
376
  OVERRIDE_COMMAND,
414
377
  ].flatMap(commandForms);
415
- const newNamesFirst = [
416
- ...commandBodies.filter((c) => c.startsWith("/crysk")),
417
- ...commandBodies.filter((c) => !c.startsWith("/crysk")),
418
- ];
419
- const ifCommentClauses = newNamesFirst
378
+ const ifCommentClauses = commandBodies
420
379
  .map(
421
380
  (c) =>
422
381
  `(github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '${c}'))`,
423
382
  )
424
383
  .join(" ||\n ");
425
- const groupCommentClauses = newNamesFirst
384
+ const groupCommentClauses = commandBodies
426
385
  .map(
427
386
  (c) =>
428
387
  `(startsWith(github.event.comment.body, '${c}') && contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))`,
@@ -451,8 +410,7 @@ export function generateCiWorkflowTemplate(
451
410
  # no cost, and records who did it. A comment that is exactly
452
411
  # \`/crysk recheck\` reviews the head and asks the CI adjudicator to rule on
453
412
  # pending dismissals of blocking findings. The action parses the comment and
454
- # refuses a commenter without write access. The older \`/pr-hero ...\` forms
455
- # of these commands still work for one version.
413
+ # refuses a commenter without write access.
456
414
  name: Crysk Review
457
415
 
458
416
  on:
@@ -491,8 +449,7 @@ jobs:
491
449
  # fork's head.
492
450
  #
493
451
  # A comment starts the job only when it BEGINS with \`/crysk review\`,
494
- # \`/crysk recheck\` or \`/crysk override\` (or the older \`/pr-hero\` forms
495
- # of the three). The action then requires an exact match after
452
+ # \`/crysk recheck\` or \`/crysk override\`. The action then requires an exact match after
496
453
  # trimming, so a near-miss such as "/crysk review please" starts a job the
497
454
  # action ends without reviewing or overriding.
498
455
  if: >-
@@ -512,7 +469,7 @@ jobs:
512
469
  #
513
470
  # GitHub keeps one PENDING run per group, and a newer run replaces it. So
514
471
  # a comment enters the pull request's group only when it starts with
515
- # /crysk review, /crysk recheck or /crysk override (or the older /pr-hero forms), and GitHub associates its author
472
+ # /crysk review, /crysk recheck or /crysk override, and GitHub associates its author
516
473
  # with the repository as OWNER, MEMBER or COLLABORATOR; every other comment
517
474
  # gets its own group. Without that, anyone who can comment could replace a
518
475
  # maintainer's queued review with a run the action then refuses. The job
@@ -562,7 +519,7 @@ ${gateStep} - name: Checkout${checkoutGate}
562
519
  uses: ${actionRef}
563
520
  with:
564
521
  github-token: \${{ secrets.GITHUB_TOKEN }}
565
- ${credentialWithLines(options)}${sizeGateLine}${filesGateLine}${budgetLine}${modeLine}
522
+ ${credentialWithLines(options)}${sizeGateLine}${filesGateLine}${modeLine}
566
523
  `;
567
524
  }
568
525
 
@@ -573,7 +530,7 @@ export interface RunCiSetupOptions {
573
530
  // What the person chose in setup --ci; absent keeps the template's defaults.
574
531
  template?: Pick<
575
532
  CiWorkflowTemplateOptions,
576
- "mode" | "budgetUsd" | "maxChangedLines" | "maxChangedFiles"
533
+ "mode" | "maxChangedLines" | "maxChangedFiles"
577
534
  >;
578
535
  }
579
536
 
@@ -894,10 +851,10 @@ export function openCodeProvidersOfPerson(person: {
894
851
  // resolved routes, any step or fallback, binds an API key, by the same rule the
895
852
  // run binds it with (credentialKindForRoute over the secret manifest's names, the
896
853
  // provider literal without one). `providers` comes from the run's own route plan,
897
- // so every source routing reads counts (`models`, `--model`, `--scout-model`, a
854
+ // so every source routing reads counts (`models`, `--model`, a
898
855
  // spec model, a prompt's frontmatter, the engine's defaults). Undefined means the
899
856
  // routes could not be resolved here: the auth file decides, the old rule, which
900
- // keeps the ceiling. The file alone is not enough otherwise: it also exists for a
857
+ // keeps the route metered. The file alone is not enough otherwise: it also exists for a
901
858
  // ChatGPT subscription, after an earlier run on a runner whose HOME persists, or
902
859
  // from a local `opencode auth login`. And no file means no credential for a
903
860
  // per-token route, as before: a free `opencode/*` model stays unmetered.
@@ -920,6 +877,79 @@ export function openCodeRoutesBillMetered(input: {
920
877
  );
921
878
  }
922
879
 
880
+ // The key modelRoleBilling records a plan step under when no `models` key covers
881
+ // it. Not a role name the platform sends, so it never adds to the API share.
882
+ const UNMAPPED_STEP = "(unmapped step)";
883
+
884
+ // Which of the run's model roles bill an API key (S17), keyed like the engine's
885
+ // `models` config (`hunter.<specialty>`, `refuter`, `summary`, `consolidate`,
886
+ // `judge`). A role is the route its step resolved to, so what `models.default`
887
+ // covers is already in it. A role bills an API key when any route it can take,
888
+ // a fallback included, does: a Claude route when the run's chosen Claude
889
+ // credential is an API key, an OpenCode route by the rule the run binds it
890
+ // with (openCodeRoutesBillMetered). The platform prices each role and the
891
+ // limits gate sums the ones that bill here, because only the engine knows how a
892
+ // run is billed. Undefined when the plan could not be built: the gate then
893
+ // compares the whole estimate.
894
+ export function modelRoleBilling(input: {
895
+ plan: ResolvedRoutePlan | undefined;
896
+ agents: readonly {
897
+ readonly key: string;
898
+ readonly role: string;
899
+ readonly specialty?: string;
900
+ }[];
901
+ // The run's chosen Claude credential env (claudeRun.env).
902
+ claudeEnv: Readonly<Record<string, string | undefined>>;
903
+ authFilePresent: boolean;
904
+ openCodeSecretNames: readonly string[] | undefined;
905
+ }): ReadonlyMap<string, boolean> | undefined {
906
+ if (input.plan === undefined) return undefined;
907
+ const routeBills = (route: { backend: string; provider: string }) =>
908
+ route.backend === "claude-code"
909
+ ? credentialKindForRoute(
910
+ "claude-code",
911
+ route.provider,
912
+ input.claudeEnv,
913
+ ) === "provider_api_token"
914
+ : openCodeRoutesBillMetered({
915
+ providers: [route.provider],
916
+ authFilePresent: input.authFilePresent,
917
+ openCodeSecretNames: input.openCodeSecretNames,
918
+ });
919
+ const billing = new Map<string, boolean>();
920
+ const add = (
921
+ role: string,
922
+ routes: readonly { backend: string; provider: string }[],
923
+ ) => {
924
+ billing.set(role, (billing.get(role) ?? false) || routes.some(routeBills));
925
+ };
926
+ for (const step of input.plan.steps) {
927
+ const routes = [step, ...(step.fallbacks ?? [])].map((s) => s.route);
928
+ // A step no `models` key covers still spends: recorded under a key the
929
+ // platform never sends, so an API-billed one keeps the run API-billed (the
930
+ // gate's no-API-role shortcut cannot fire) without adding to the share.
931
+ add(stepModelRole(step.stepKey, input.agents) ?? UNMAPPED_STEP, routes);
932
+ }
933
+ // The materiality judge is counted only when it is in the plan (the gate on,
934
+ // its `materiality` step above): an idle judge bills nothing, and counting its
935
+ // Claude route would mark a run whose roles are all on a subscription as
936
+ // API-billed through an unused Claude key (#551 R001). A `judge` key the
937
+ // platform still sends then has no role here and counts as API.
938
+ return billing;
939
+ }
940
+
941
+ // The `models` key a plan step reads, or undefined for a step no key covers.
942
+ function stepModelRole(
943
+ stepKey: string,
944
+ agents: readonly { key: string; role: string; specialty?: string }[],
945
+ ): string | undefined {
946
+ if (stepKey === "summarizer") return "summary";
947
+ if (stepKey === "consolidate") return "consolidate";
948
+ if (stepKey === "materiality") return "judge";
949
+ const agent = agents.find((a) => agentStepKey(a) === stepKey);
950
+ return agent === undefined ? undefined : agentModelRole(agent);
951
+ }
952
+
923
953
  interface OpenCodeAuthAssembly {
924
954
  // provider id -> its auth.json record.
925
955
  readonly records: Record<string, Record<string, unknown>>;
@@ -8,8 +8,8 @@
8
8
  // - a root span `invoke_workflow crysk.review` for the run;
9
9
  // - a child `invoke_agent <step>` per pipeline step;
10
10
  // - under it a `chat <model>` per attempt, carrying the model, provider, token
11
- // usage (inclusive of cache and reasoning, as the conventions count it) and
12
- // cost, so a backend sees each model call once;
11
+ // usage (inclusive of cache and reasoning, as the conventions count it),
12
+ // so a backend sees each model call once;
13
13
  // - under that an `execute_tool <tool>` per tool call the model made.
14
14
  // Engine facts ride as `crysk.*` attributes with snake_case keys. Every leaf of
15
15
  // each pipeline.json step lands on its step span (crysk.step.*), every leaf of
@@ -41,7 +41,7 @@ import {
41
41
  redactSessionDocument,
42
42
  redactSessionText,
43
43
  } from "../execution/claude-session-trace";
44
- import { metadataOnlyFinding } from "./platform-report";
44
+ import { metadataOnlyFinding, stepRole } from "./platform-report";
45
45
  import {
46
46
  type ChatMessage,
47
47
  type Conversation,
@@ -482,8 +482,8 @@ function sumKnown(...values: unknown[]): number | undefined {
482
482
  }
483
483
 
484
484
  // The engine's usage leaves are disjoint; the conventions count input with its
485
- // cache and output with its reasoning. List cost follows the report step's
486
- // rule: a subscription's notional cost, a metered run's cash cost.
485
+ // cache and output with its reasoning. No price is attached: the platform
486
+ // prices the run from the usage facts.
487
487
  function writeUsage(attrs: Attributes, usage: Record<string, unknown>): void {
488
488
  const tokens = isRecord(usage.tokens) ? usage.tokens : {};
489
489
  attrs.number(
@@ -511,29 +511,9 @@ function writeUsage(attrs: Attributes, usage: Record<string, unknown>): void {
511
511
  tokens.inputCacheWrite,
512
512
  );
513
513
  attrs.number("gen_ai.usage.reasoning.output_tokens", tokens.outputReasoning);
514
- const listCost =
515
- usage.billingMode === "subscription"
516
- ? num(usage.notionalCostUsd)
517
- : usage.billingMode === "metered"
518
- ? num(usage.cashCostUsd)
519
- : undefined;
520
- attrs.number("gen_ai.usage.cost", listCost);
521
514
  attrs.flatten("crysk.usage", usage);
522
515
  }
523
516
 
524
- function stepRole(pipeline: unknown, name: string): string {
525
- const plan =
526
- isRecord(pipeline) && isRecord(pipeline.route_plan)
527
- ? pipeline.route_plan
528
- : undefined;
529
- const planned = Array.isArray(plan?.steps)
530
- ? plan.steps.filter(isRecord).find((step) => step.stepKey === name)
531
- : undefined;
532
- const role = str(planned?.role);
533
- if (role !== undefined) return role;
534
- return name.split(/[-.]/)[0] ?? name;
535
- }
536
-
537
517
  function pipelineSteps(pipeline: unknown): Record<string, unknown>[] {
538
518
  return isRecord(pipeline) && Array.isArray(pipeline.steps)
539
519
  ? pipeline.steps.filter(isRecord)
@@ -922,7 +902,12 @@ function build(
922
902
  attrs.text("gen_ai.operation.name", "invoke_agent");
923
903
  attrs.text("gen_ai.agent.name", step.name);
924
904
  attrs.text("crysk.step.role", stepRole(run.pipeline, step.name));
925
- if (meta !== undefined) attrs.flatten("crysk.step", meta);
905
+ if (meta !== undefined) {
906
+ // `usage_facts` (one tuple per model request) travels in the run report to the
907
+ // platform; flattened here it would be hundreds of attributes per attempt.
908
+ const { usage_facts: _usageFacts, ...stepAttrs } = meta;
909
+ attrs.flatten("crysk.step", stepAttrs);
910
+ }
926
911
  attrs.text("crysk.step.name", step.name);
927
912
  attrs.text("crysk.model.effort", str(meta?.effort));
928
913
  const status = str(meta?.status);
@@ -1098,7 +1083,6 @@ function writeTurnUsage(attrs: Attributes, turn: Turn): void {
1098
1083
  turn.cacheWriteTokens,
1099
1084
  );
1100
1085
  attrs.number("gen_ai.usage.reasoning.output_tokens", turn.reasoningTokens);
1101
- attrs.number("gen_ai.usage.cost", turn.costUsd);
1102
1086
  }
1103
1087
 
1104
1088
  function toolSpan(