crysk 0.3.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +26 -17
  2. package/config/models/anthropic.json +1 -1
  3. package/dist/SKILL-dsnffnfp.md +140 -0
  4. package/dist/SKILL-gnrbph72.md +140 -0
  5. package/dist/SKILL-k4k0zn1w.md +143 -0
  6. package/dist/SKILL-kq0xejn3.md +553 -0
  7. package/dist/SKILL-qaqsbygw.md +66 -0
  8. package/dist/SKILL-vhb4c3vv.md +553 -0
  9. package/dist/SKILL-vws0aqb8.md +553 -0
  10. package/dist/SKILL-xpf6kmdw.md +74 -0
  11. package/dist/ci-admission-0ken6ehx.md +128 -0
  12. package/dist/ci-admission-t0f5qwth.md +128 -0
  13. package/dist/cli.js +3366 -1680
  14. package/dist/index.js +1884 -947
  15. package/dist/opencode-ci-ac5zksdn.md +106 -0
  16. package/dist/workflow-4pkyck01.yml +160 -0
  17. package/package.json +2 -2
  18. package/prompts/default/PROVENANCE.md +1 -0
  19. package/skills/crysk/SKILL.md +16 -16
  20. package/skills/crysk-ci-setup/SKILL.md +42 -39
  21. package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
  22. package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
  23. package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
  24. package/skills/crysk-loop/SKILL.md +20 -9
  25. package/skills/crysk-pr/SKILL.md +1 -1
  26. package/src/asset-manifest.ts +0 -4
  27. package/src/assets.ts +2 -2
  28. package/src/ci/admission-ledger.ts +4 -0
  29. package/src/ci/classify-error.ts +21 -24
  30. package/src/ci/cli-record.ts +53 -1
  31. package/src/ci/crysk-secrets.ts +409 -0
  32. package/src/ci/gates.ts +31 -42
  33. package/src/ci/outcome.ts +421 -330
  34. package/src/ci/platform-config.ts +127 -0
  35. package/src/ci/platform-report.ts +935 -0
  36. package/src/ci/platform-trace.ts +551 -0
  37. package/src/ci/platform.ts +465 -0
  38. package/src/ci/publish.ts +19 -6
  39. package/src/ci/reporter.ts +9 -7
  40. package/src/ci/review-admission.ts +8 -4
  41. package/src/ci/review-levels.ts +8 -7
  42. package/src/ci/run.ts +88 -0
  43. package/src/ci/setup.ts +547 -109
  44. package/src/ci/trace-bundle.ts +1282 -0
  45. package/src/ci/trace-transcripts.ts +415 -0
  46. package/src/ci/trigger.ts +176 -33
  47. package/src/cli.ts +11 -3
  48. package/src/commands/ci-setup-questions.ts +3 -3
  49. package/src/commands/ci-setup.ts +152 -6
  50. package/src/commands/config.ts +3 -0
  51. package/src/commands/doctor.ts +15 -6
  52. package/src/compare/loop.ts +9 -1
  53. package/src/compare/martian-adapter.ts +1 -1
  54. package/src/config/config.ts +16 -3
  55. package/src/diversity/clustering.ts +0 -1
  56. package/src/diversity/identity.ts +4 -5
  57. package/src/diversity/pipeline-integration.ts +1 -9
  58. package/src/doctor.ts +3 -3
  59. package/src/execution/attempt-evidence.ts +10 -5
  60. package/src/execution/claude-session-trace.ts +480 -0
  61. package/src/execution/contracts.ts +21 -4
  62. package/src/execution/harness.ts +105 -8
  63. package/src/execution/model-fallback.ts +239 -0
  64. package/src/execution/usage-normalized.ts +6 -4
  65. package/src/home-preflight.ts +1 -1
  66. package/src/index.ts +1 -1
  67. package/src/model/catalog.ts +13 -37
  68. package/src/model/free-discovery.ts +117 -8
  69. package/src/model/model-name.ts +404 -0
  70. package/src/model/provider-capabilities.ts +22 -7
  71. package/src/model/routing.ts +346 -467
  72. package/src/pr/admission.ts +71 -11
  73. package/src/pr/ci-admission-gate.ts +2 -1
  74. package/src/pr/finding-state-record.ts +58 -0
  75. package/src/pr/gate-record.ts +22 -0
  76. package/src/pr/inline.ts +3 -0
  77. package/src/pr/plan.ts +20 -4
  78. package/src/pr/posting.ts +4 -0
  79. package/src/pr/pr-status.ts +27 -7
  80. package/src/pr/pr.ts +39 -8
  81. package/src/pr/preflight.ts +44 -2
  82. package/src/pr/publish-outcome.ts +11 -3
  83. package/src/pr/review-pr.ts +20 -4
  84. package/src/pr/target.ts +12 -3
  85. package/src/production-runtime.ts +760 -331
  86. package/src/rereview/classify.ts +4 -0
  87. package/src/rereview/prepare.ts +47 -22
  88. package/src/rereview/state.ts +34 -8
  89. package/src/review/pipeline.ts +277 -101
  90. package/src/review/preflight.ts +201 -294
  91. package/src/review/report.ts +60 -40
  92. package/src/review/review.ts +20 -3
  93. package/src/review/route-preflight.ts +79 -11
  94. package/src/review/run.ts +28 -6
  95. package/src/review/scout.ts +1 -1
  96. package/src/review/spec.ts +3 -3
  97. package/src/review/step-runner.ts +70 -1
  98. package/src/runner-authority.ts +127 -9
  99. package/src/security/binding-policy.ts +1 -2
  100. package/src/security/claude-credential.ts +355 -0
  101. package/src/security/credential-broker.ts +56 -40
  102. package/src/security/evidence-redaction.ts +179 -4
  103. package/src/security/opencode-secret-manifest.ts +114 -0
  104. package/src/security/published-text.ts +161 -0
  105. package/src/security/redact.ts +45 -0
  106. package/src/system-tools.ts +48 -21
  107. package/src/transport-registry.ts +12 -2
  108. package/src/transports/claude-code-cli.ts +21 -2
  109. package/src/transports/opencode-sdk.ts +11 -9
  110. package/src/transports/opencode-server.ts +7 -10
  111. package/src/triage/triage.ts +2 -1
  112. package/src/ui/config-edit.ts +9 -20
  113. package/src/ui/config.ts +32 -27
  114. package/src/ui/plan.ts +76 -47
  115. package/src/updater.ts +10 -7
  116. package/prompts/default/deep-review-lifecycle.md +0 -362
@@ -8,7 +8,7 @@
8
8
  // a renderer that reached for `new Date()` would make that a lie).
9
9
 
10
10
  import { listPaths } from "#git/refs";
11
- import type { ResolvedModelRoute, ResolvedStepRoute } from "#model/routing";
11
+ import type { ResolvedRoutePlan, ResolvedStepRoute } from "#model/routing";
12
12
  import type { PostMinSeverity } from "#pr/post-floor";
13
13
  import {
14
14
  type CiMode,
@@ -42,6 +42,7 @@ import {
42
42
  LEGACY_BIN_NAME,
43
43
  matchMarkerPrefix,
44
44
  } from "../brand";
45
+ import { publishedText, redactSecrets } from "../security/published-text";
45
46
 
46
47
  export interface DiffStat {
47
48
  files: number;
@@ -961,7 +962,7 @@ function liveFindingLines(rereview: RereviewDelta | undefined): string[] {
961
962
  ? "⚠️ severity unavailable"
962
963
  : severityEmoji(row.sev);
963
964
  out.push(
964
- `- \`${row.status}\` ${badge} \`${loc}\` — ${liveClaimText(row.claim)} (${row.id})`,
965
+ `- \`${row.status}\` ${badge} ${code(loc)} — ${liveClaimText(row.claim)} (${row.id})`,
965
966
  );
966
967
  }
967
968
  out.push("");
@@ -1257,7 +1258,7 @@ function findingLocationLine(
1257
1258
  ): string {
1258
1259
  const loc = code(`${finding.path}:${finding.line}`);
1259
1260
  const linked =
1260
- linkLocation && webUrl !== undefined
1261
+ linkLocation && webUrl !== undefined && isLinkablePath(finding.path)
1261
1262
  ? `[${loc}](${blobUrl(webUrl, headSha, finding.path, `L${finding.line}`)})`
1262
1263
  : loc;
1263
1264
  // A POSITIVE type test, not `=== undefined`. Defence in depth: the draft and
@@ -1326,16 +1327,11 @@ function tierExplanationLines(finding: Finding): string[] {
1326
1327
 
1327
1328
  // The judge's reason is model text written about author-controlled input,
1328
1329
  // and it is posted. One line (a newline would end the list item and could
1329
- // start a forged header line), capped, with HTML comment delimiters broken so
1330
- // it can never open or close a marker the comment parsers read, and `@`
1331
- // defused so it cannot notify anyone.
1330
+ // start a forged header line) and capped; oneLine makes it safe to publish.
1332
1331
  const MATERIALITY_REASON_MAX = 280;
1333
1332
 
1334
1333
  function materialityReason(reason: string): string {
1335
- const flat = oneLine(reason)
1336
- .replaceAll("<!--", "<!‐‐")
1337
- .replaceAll("-->", "‐‐>")
1338
- .replaceAll("@", "@\u200b");
1334
+ const flat = oneLine(reason);
1339
1335
  return flat.length <= MATERIALITY_REASON_MAX
1340
1336
  ? flat
1341
1337
  : `${flat.slice(0, MATERIALITY_REASON_MAX - 1).trimEnd()}…`;
@@ -1351,7 +1347,7 @@ function promptToFixBlock(finding: Finding): string[] {
1351
1347
  "<details><summary>Prompt to fix with AI</summary>",
1352
1348
  "",
1353
1349
  "```",
1354
- `Fix this issue in ${finding.path} at line ${finding.line}:`,
1350
+ `Fix this issue in ${oneLine(finding.path)} at line ${finding.line}:`,
1355
1351
  "",
1356
1352
  oneLine(finding.claim),
1357
1353
  "```",
@@ -1520,7 +1516,7 @@ function renderRef(
1520
1516
  ): string {
1521
1517
  if (webUrl === undefined) return code(ref);
1522
1518
  const parsed = parseRefAnchor(ref);
1523
- if (parsed === null) return code(ref);
1519
+ if (parsed === null || !isLinkablePath(parsed.path)) return code(ref);
1524
1520
  const fragment =
1525
1521
  parsed.end === undefined
1526
1522
  ? `L${parsed.start}`
@@ -1559,6 +1555,27 @@ function parseRefAnchor(ref: string): {
1559
1555
  };
1560
1556
  }
1561
1557
 
1558
+ // A finding's path is whatever the model wrote; nothing checks that the file
1559
+ // exists. A span redacts it, but a link's href needs the original, so a path
1560
+ // carrying a secret gets no link.
1561
+ export function isLinkablePath(path: string): boolean {
1562
+ return redactSecrets(path) === path;
1563
+ }
1564
+
1565
+ // A path is author-controlled and lands in a Markdown link. `)` would end the
1566
+ // link and leave what follows as text, where `@name` is a real mention. Parens are
1567
+ // encoded by hand because encodeURIComponent leaves them. An unpaired surrogate
1568
+ // would make it throw, and a post that was paid for must not be lost to a path.
1569
+ function encodeBlobPath(path: string): string {
1570
+ return path
1571
+ .toWellFormed()
1572
+ .split("/")
1573
+ .map(encodeURIComponent)
1574
+ .join("/")
1575
+ .replaceAll("(", "%28")
1576
+ .replaceAll(")", "%29");
1577
+ }
1578
+
1562
1579
  // Exported for ui/result.ts, the second surface that links a finding to its
1563
1580
  // source. Deliberately SHARED rather than re-derived: the markdown report and
1564
1581
  // the terminal block must point a reader at the same bytes, and two copies of
@@ -1570,7 +1587,7 @@ export function blobUrl(
1570
1587
  path: string,
1571
1588
  fragment: string,
1572
1589
  ): string {
1573
- return `${webUrl}/blob/${sha}/${path}#${fragment}`;
1590
+ return `${webUrl}/blob/${sha}/${encodeBlobPath(path)}#${fragment}`;
1574
1591
  }
1575
1592
 
1576
1593
  function runLines(doc: FindingsDocument, meta: ReportMeta): string[] {
@@ -1809,9 +1826,12 @@ export function code(text: string): string {
1809
1826
  }
1810
1827
 
1811
1828
  // Claims arrive as free prose and sometimes carry newlines; a raw newline
1812
- // inside a list item silently ends the item.
1829
+ // inside a list item silently ends the item. Every piece of model text and every
1830
+ // span in this file passes through here, which makes this the one place it is
1831
+ // made safe to publish. The finding marker fingerprints the raw claim instead, so
1832
+ // a comment posted before this existed still matches its finding.
1813
1833
  function oneLine(text: string): string {
1814
- return text.replace(/\s+/g, " ").trim();
1834
+ return publishedText(text.replace(/\s+/g, " ").trim());
1815
1835
  }
1816
1836
 
1817
1837
  function usd(amount: number): string {
@@ -1844,40 +1864,40 @@ function round2(value: number): number {
1844
1864
  return Math.round(value * 100) / 100;
1845
1865
  }
1846
1866
 
1847
- export function formatModelRoute(
1848
- route: ResolvedModelRoute,
1849
- logicalIdentity?: string,
1850
- ): string {
1851
- const variant = route.modelVariant ? `#${route.modelVariant}` : "";
1852
- const modelName = route.modelSnapshot || route.modelFamily;
1853
- const target = `${route.provider}/${modelName}${variant}`;
1854
- const gateway = route.gateway ?? "direct";
1855
- const dims = `[${gateway}, ${route.backend}]`;
1856
- if (logicalIdentity && logicalIdentity !== target) {
1857
- return `${logicalIdentity} -> ${target} ${dims}`;
1858
- }
1859
- return `${target} ${dims}`;
1860
- }
1861
-
1862
- export function formatStepRoute(
1863
- step: ResolvedStepRoute,
1864
- rawLogical?: string,
1865
- ): string {
1866
- return formatModelRoute(step.route, rawLogical ?? step.logicalIdentity);
1867
+ // A step's route as the plan card shows it: the model name it resolved to,
1868
+ // which already says its backend (`claude:sonnet-latest`,
1869
+ // `opencode:openai/gpt-5`), and its `models` entry's effort when it sets one,
1870
+ // in the config row's form (`claude:opus-latest (effort max)`, S7). It
1871
+ // replaced `alias -> provider/model [gateway, backend]`, whose gateway no
1872
+ // longer exists.
1873
+ export function formatStepRoute(step: ResolvedStepRoute): string {
1874
+ return step.effort === undefined
1875
+ ? step.logicalIdentity
1876
+ : `${step.logicalIdentity} (effort ${step.effort})`;
1867
1877
  }
1868
1878
 
1869
1879
  // The envelope needs ONE model string. With no --model override each agent
1870
- // carries its own frontmatter model, so report what actually ran rather than
1871
- // inventing a single value: identical models collapse to one name, a mixed
1872
- // set is recorded as a mix instead of as a lie.
1880
+ // carries its own model, so report what actually ran rather than inventing a
1881
+ // single value: identical models collapse to one name, a mixed set is
1882
+ // recorded as a mix instead of as a lie. With a route plan, "what ran" is the
1883
+ // plan's model for the hunters and the refuter (`models` moves them off their
1884
+ // frontmatter); a zero-config plan names the same aliases the frontmatter does.
1873
1885
  export function envelopeModel(
1874
1886
  options: { model?: string },
1875
1887
  agentFiles: Map<string, { model?: string }>,
1888
+ routePlan?: ResolvedRoutePlan,
1876
1889
  ): string {
1877
1890
  if (options.model) return options.model;
1878
1891
  const models = new Set<string>();
1879
- for (const agent of agentFiles.values()) {
1880
- if (agent.model) models.add(agent.model);
1892
+ const agentSteps = (routePlan?.steps ?? []).filter(
1893
+ (step) => step.role === "hunter" || step.role === "refuter",
1894
+ );
1895
+ if (agentSteps.length > 0) {
1896
+ for (const step of agentSteps) models.add(step.route.modelSnapshot);
1897
+ } else {
1898
+ for (const agent of agentFiles.values()) {
1899
+ if (agent.model) models.add(agent.model);
1900
+ }
1881
1901
  }
1882
1902
  if (models.size === 0) return "unspecified";
1883
1903
  return [...models].sort().join("+");
@@ -24,6 +24,7 @@ import {
24
24
  } from "#git/git";
25
25
  import { engineIdentity } from "#git/identity";
26
26
  import { countFreeRouteSteps } from "#model/free-discovery";
27
+ import { planRoutes } from "#model/routing";
27
28
  import { reviewPr } from "#pr/review-pr";
28
29
  import type { Telemetry } from "#review/findings";
29
30
  import { type PipelineResult, runPipeline } from "#review/pipeline";
@@ -80,6 +81,7 @@ import { prheroLayout } from "../home-preflight";
80
81
  import { readLocalIgnoreRules } from "../ignore-read";
81
82
  import type { ProductionRuntime } from "../production-runtime";
82
83
  import { resolveRunnerAuthority } from "../runner-authority";
84
+ import { resolveRunClaudeCredential } from "../security/claude-credential";
83
85
 
84
86
  export async function review(options: CliOptions): Promise<number> {
85
87
  // PR mode is a different front half (gh-resolved range, detached worktree)
@@ -105,6 +107,12 @@ export async function review(options: CliOptions): Promise<number> {
105
107
  options,
106
108
  });
107
109
  options = { ...options, scout, post };
110
+ // S5: the Claude credential this run uses, chosen once, here, from
111
+ // `credentials.claude` and what is set. Every runner, binding and child below
112
+ // reads its env, which holds that one credential and no other.
113
+ const claudeRun = resolveRunClaudeCredential({
114
+ credentials: config.credentials,
115
+ });
108
116
 
109
117
  // 3 — the base ref, then the canonical refs and the range.
110
118
  const baseRef = await resolveBase(repoRoot, options, config);
@@ -242,14 +250,15 @@ export async function review(options: CliOptions): Promise<number> {
242
250
  true,
243
251
  );
244
252
  const productionRoute = await resolvePipelineRoute({
245
- routingConfigured: config.routing !== undefined,
253
+ modelsConfigured: config.models !== undefined,
246
254
  workspaceRoot: repoRoot,
247
255
  spec,
248
256
  options,
249
257
  agentFiles,
250
- routingConfig: config.routing,
258
+ models: config.models,
251
259
  summary,
252
260
  materialityEnabled: resolveMaterialityGate(config),
261
+ claudeRun: options.dryRun ? undefined : claudeRun,
253
262
  });
254
263
  const routePlan = productionRoute?.routePlan;
255
264
  const productionAdmission = productionRoute?.productionAdmission;
@@ -259,8 +268,12 @@ export async function review(options: CliOptions): Promise<number> {
259
268
  routePlan === undefined || productionAdmission === undefined
260
269
  ? undefined
261
270
  : await countFreeRouteSteps({
262
- steps: routePlan.steps,
271
+ steps: planRoutes(routePlan),
263
272
  probe: productionAdmission.freeModelProbe,
273
+ // The CRYSK_OPENCODE_* names admission bound each route's kind with,
274
+ // so the card counts free exactly the routes admission probed (U3).
275
+ openCodeSecretNames:
276
+ productionAdmission.authorityOptions.openCodeSecretNames,
264
277
  });
265
278
  // Named rather than inlined into renderPlan: the same context is what the
266
279
  // confirm menu's "Show details" renders, and building it twice would risk
@@ -311,6 +324,10 @@ export async function review(options: CliOptions): Promise<number> {
311
324
  // claude-code ProviderCapabilityReport path byte-compatible.
312
325
  const runnerAuthority = await resolveRunnerAuthority({
313
326
  workspaceRoot: repoRoot,
327
+ env: claudeRun.env,
328
+ ...(claudeRun.kind === undefined
329
+ ? {}
330
+ : { claudeCredential: claudeRun.kind }),
314
331
  });
315
332
  await enforceCapabilityGate({
316
333
  routePlan,
@@ -2,19 +2,22 @@
2
2
  // enforce executable and provider capability gates, and admit production
3
3
  // routes across Claude and OpenCode runners before confirming or spending tokens.
4
4
 
5
+ import type { ModelsConfig } from "#model/model-name";
5
6
  import {
6
7
  capabilityGateDecision,
7
8
  produceClaudeCapabilityReport,
8
9
  } from "#model/provider-capabilities";
9
10
  import {
10
11
  buildResolvedRoutePlan,
12
+ InvalidModelError,
13
+ planRoutes,
11
14
  type ResolvedRoutePlan,
12
- type RoutingConfig,
13
15
  } from "#model/routing";
14
16
  import { resolveEngineAssets } from "../assets";
15
17
  import { CliError } from "../errors";
16
18
  import type { RunnerBackend } from "../execution/contracts";
17
19
  import {
20
+ type OpenCodeCredentialRefusal,
18
21
  type ProductionAdmissionContext,
19
22
  prepareProductionAdmissionContext,
20
23
  probeBindingsReadiness,
@@ -24,6 +27,12 @@ import type {
24
27
  RunnerAuthorityOptions,
25
28
  RunnerAuthorityResolution,
26
29
  } from "../runner-authority";
30
+ import {
31
+ ClaudeCredentialRefusalError,
32
+ CredentialRefusalError,
33
+ claudeCredentialRefusal,
34
+ type RunClaudeCredential,
35
+ } from "../security/claude-credential";
27
36
  import {
28
37
  admitRoutePlan,
29
38
  createDefaultTransportRegistry,
@@ -111,7 +120,7 @@ export async function buildCliRoutePlan(params: {
111
120
  spec: ReviewSpec;
112
121
  options: CliOptions;
113
122
  agentFiles: Map<string, ParsedAgent>;
114
- routingConfig?: RoutingConfig;
123
+ models?: ModelsConfig;
115
124
  summary: SummarySettings;
116
125
  summarizerEnabled?: boolean;
117
126
  scoutEnabled?: boolean;
@@ -163,7 +172,7 @@ export async function buildCliRoutePlan(params: {
163
172
  return buildResolvedRoutePlan({
164
173
  agents: params.spec.agents,
165
174
  cliModel: params.options.model,
166
- routingConfig: params.routingConfig,
175
+ models: params.models,
167
176
  frontmatterModel: (agentKey) => params.agentFiles.get(agentKey)?.model,
168
177
  ...(summarizerEnabled
169
178
  ? {
@@ -196,11 +205,19 @@ export async function buildCliRoutePlan(params: {
196
205
  });
197
206
  }
198
207
 
199
- // Pre-confirm route resolution: legacy runs without operator routing may omit
200
- // route provenance when the plan cannot be built, but admission failures must
208
+ // Whether a plan that failed to build may fall back to the legacy no-plan
209
+ // path (a prompt or `--model` naming a raw Claude id the CLI resolves itself).
210
+ // Never when `models` is set, and never for a model written in the new form:
211
+ // both are the operator's words, and the error is how to fix them.
212
+ function planErrorIsFatal(error: unknown, modelsConfigured: boolean): boolean {
213
+ return modelsConfigured || error instanceof InvalidModelError;
214
+ }
215
+
216
+ // Pre-confirm route resolution: legacy runs without `models` may omit route
217
+ // provenance when the plan cannot be built, but admission failures must
201
218
  // always surface before confirm — never be swallowed into routePlan = undefined.
202
219
  export async function resolveRoutePlanAtConfirm(input: {
203
- routingConfigured: boolean;
220
+ modelsConfigured: boolean;
204
221
  buildRoutePlan: () => Promise<ResolvedRoutePlan>;
205
222
  registry?: TransportRegistry;
206
223
  }): Promise<ResolvedRoutePlan | undefined> {
@@ -210,13 +227,28 @@ export async function resolveRoutePlanAtConfirm(input: {
210
227
  try {
211
228
  routePlan = await input.buildRoutePlan();
212
229
  } catch (error) {
213
- if (input.routingConfigured) throw error;
230
+ if (planErrorIsFatal(error, input.modelsConfigured)) throw error;
214
231
  return undefined;
215
232
  }
216
233
  await admitRoutePlan(routePlan, registry);
217
234
  return routePlan;
218
235
  }
219
236
 
237
+ // The OpenCode refusal: a route the plan runs has no credential record in the run's
238
+ // OpenCode auth file (openCodeCredentialRefusal, production-runtime.ts). It is the
239
+ // failure the route's first step would hit (CRYSK-CRED-UNUSABLE), raised before any
240
+ // spend.
241
+ export class OpenCodeCredentialRefusalError extends CredentialRefusalError {
242
+ constructor(refusal: OpenCodeCredentialRefusal) {
243
+ super(
244
+ refusal.message,
245
+ { kind: "credential", failureClass: refusal.failureClass },
246
+ refusal.params,
247
+ `no credential record for OpenCode provider ${refusal.params.provider}; refused before any provider spend`,
248
+ );
249
+ }
250
+ }
251
+
220
252
  export interface ProductionRoutePlanResult {
221
253
  readonly routePlan: ResolvedRoutePlan;
222
254
  readonly productionAdmission: ProductionAdmissionContext;
@@ -225,29 +257,59 @@ export interface ProductionRoutePlanResult {
225
257
  // Production admission: discover per-backend executable authority, derive
226
258
  // D1-11 evidence from exact-binding probes, and admit with one shared registry.
227
259
  export async function resolveProductionRoutePlanAtConfirm(input: {
228
- routingConfigured: boolean;
260
+ modelsConfigured: boolean;
229
261
  workspaceRoot: string;
230
262
  buildRoutePlan: () => Promise<ResolvedRoutePlan>;
231
263
  authorityDeps?: ResolveRunnerAuthorityDeps;
232
264
  loadSdk?: () => Promise<OpenCodeSdkLike>;
233
265
  env?: RunnerAuthorityOptions["env"];
266
+ // S5: the Claude credential chosen at run start. Its env replaces `env` (it is the
267
+ // process environment with one Claude credential left), and a plan that needs
268
+ // Claude with no listed credential present is refused here, before admission.
269
+ claudeRun?: RunClaudeCredential;
270
+ // False on a dry run, which authenticates nothing: no OpenCode route is refused
271
+ // for a missing record (the Claude check is skipped by passing no claudeRun).
272
+ checkCredentials?: boolean;
234
273
  }): Promise<ProductionRoutePlanResult | undefined> {
274
+ const refuse = (planHasClaudeRoute: boolean): void => {
275
+ if (input.claudeRun === undefined) return;
276
+ const refusal = claudeCredentialRefusal(
277
+ input.claudeRun.selection,
278
+ planHasClaudeRoute,
279
+ );
280
+ if (refusal !== undefined) throw new ClaudeCredentialRefusalError(refusal);
281
+ };
235
282
  let routePlan: ResolvedRoutePlan;
236
283
  try {
237
284
  routePlan = await input.buildRoutePlan();
238
285
  } catch (error) {
239
- if (input.routingConfigured) throw error;
286
+ if (planErrorIsFatal(error, input.modelsConfigured)) throw error;
287
+ // The legacy no-plan path runs every step on the Claude CLI.
288
+ refuse(true);
240
289
  return undefined;
241
290
  }
291
+ refuse(
292
+ planRoutes(routePlan).some((step) => step.route.backend === "claude-code"),
293
+ );
242
294
 
295
+ const env = input.claudeRun?.env ?? input.env;
243
296
  const productionAdmission = await prepareProductionAdmissionContext({
244
297
  workspaceRoot: input.workspaceRoot,
245
298
  plan: routePlan,
246
299
  authorityDeps: input.authorityDeps,
247
300
  loadSdk: input.loadSdk,
248
- env: input.env,
301
+ ...(input.checkCredentials === false ? { checkCredentials: false } : {}),
302
+ ...(env === undefined ? {} : { env }),
303
+ ...(input.claudeRun?.kind === undefined
304
+ ? {}
305
+ : { claudeCredential: input.claudeRun.kind }),
249
306
  });
250
307
  if ("error" in productionAdmission) {
308
+ if (productionAdmission.credentialRefusal !== undefined) {
309
+ throw new OpenCodeCredentialRefusalError(
310
+ productionAdmission.credentialRefusal,
311
+ );
312
+ }
251
313
  throw new CliError(
252
314
  `production admission failed: ${productionAdmission.error}`,
253
315
  );
@@ -273,7 +335,13 @@ export async function enforceProviderCapabilityGate(input: {
273
335
  `execution authority unavailable: ${input.runnerAuthority.error}`,
274
336
  );
275
337
  }
276
- const capabilityReport = await produceClaudeCapabilityReport({});
338
+ // S5: the run env (one Claude credential, under the CLI's name), the same object
339
+ // the legacy runner hands its child, so the auth check sees the credential the
340
+ // run chose (a CRYSK_* secret included) and never one it stripped.
341
+ const runEnv = input.runnerAuthority?.runnerOptions?.childEnv;
342
+ const capabilityReport = await produceClaudeCapabilityReport(
343
+ runEnv === undefined ? {} : { env: { ...runEnv } },
344
+ );
277
345
  const capabilityGate = capabilityGateDecision(capabilityReport);
278
346
  if (!capabilityGate.ok) {
279
347
  throw new CliError(
package/src/review/run.ts CHANGED
@@ -21,7 +21,8 @@ import {
21
21
  loadEffectiveConfig,
22
22
  notionalCostInput,
23
23
  } from "#config/config";
24
- import type { ResolvedRoutePlan, RoutingConfig } from "#model/routing";
24
+ import type { ModelsConfig } from "#model/model-name";
25
+ import type { ResolvedRoutePlan } from "#model/routing";
25
26
  import type { CiMode } from "#pr/preflight";
26
27
  import {
27
28
  type FindingsDocument,
@@ -90,6 +91,7 @@ import {
90
91
  type ProductionRuntime,
91
92
  } from "../production-runtime";
92
93
  import type { RunnerAuthorityResolution } from "../runner-authority";
94
+ import type { RunClaudeCredential } from "../security/claude-credential";
93
95
 
94
96
  // The codegraph server, and ONLY the codegraph server. Written per run and
95
97
  // handed to every step together with the runner's --strict-mcp-config: an
@@ -129,12 +131,19 @@ export async function loadRunConfig(params: {
129
131
  home: string;
130
132
  configFlag: string | undefined;
131
133
  options: Pick<CliOptions, "summary" | "model" | "scout" | "post">;
134
+ // Where config warnings go. Defaults to stderr, beside every other
135
+ // `warning:` line a run prints.
136
+ warn?: (line: string) => void;
132
137
  }): Promise<LoadedRunConfig> {
133
138
  const loaded = await loadEffectiveConfig({
134
139
  root: params.root,
135
140
  home: params.home,
136
141
  configFlag: params.configFlag,
137
142
  });
143
+ const warn =
144
+ params.warn ??
145
+ ((line: string) => process.stderr.write(`warning: ${line}\n`));
146
+ for (const line of loaded.warnings) warn(line);
138
147
  const config = loaded.effective;
139
148
  const summary = resolveSummary(params.options, config);
140
149
  const scout = resolveScout(params.options, config);
@@ -360,7 +369,11 @@ export async function writeRunFindings(params: {
360
369
  pr: params.pr,
361
370
  base_sha: params.baseSha,
362
371
  head_sha: params.headSha,
363
- model: envelopeModel(params.options, params.agentFiles),
372
+ model: envelopeModel(
373
+ params.options,
374
+ params.agentFiles,
375
+ params.result.routePlan,
376
+ ),
364
377
  iteration: 0,
365
378
  prompt_set: params.promptSet,
366
379
  engine: params.engine,
@@ -487,27 +500,36 @@ export async function writeMcpConfig(
487
500
  // wraps — `resolveProductionRoute` reads as a near-duplicate of that name at
488
501
  // a glance, which is exactly the confusion a shared wrapper should not add.
489
502
  export async function resolvePipelineRoute(params: {
490
- routingConfigured: boolean;
503
+ modelsConfigured: boolean;
491
504
  workspaceRoot: string;
492
505
  spec: ReviewSpec;
493
506
  options: CliOptions;
494
507
  agentFiles: Map<string, ParsedAgent>;
495
- routingConfig: RoutingConfig | undefined;
508
+ models: ModelsConfig | undefined;
496
509
  summary: SummarySettings;
497
510
  summarizerEnabled?: boolean;
498
511
  scoutEnabled?: boolean;
499
512
  consolidateEnabled?: boolean;
500
513
  materialityEnabled?: boolean;
514
+ // S5: the run's Claude credential, chosen once at run start. Required (undefined
515
+ // spelled out) so tsc keeps every caller handing it over: dropping it would compile
516
+ // and silently admit on the process env. A dry run passes undefined: it
517
+ // authenticates nothing (like the capability gate it skips), so it is never
518
+ // refused for a credential and admits on the process env.
519
+ claudeRun: RunClaudeCredential | undefined;
501
520
  }): Promise<ProductionRoutePlanResult | undefined> {
502
521
  return resolveProductionRoutePlanAtConfirm({
503
- routingConfigured: params.routingConfigured,
522
+ modelsConfigured: params.modelsConfigured,
504
523
  workspaceRoot: params.workspaceRoot,
524
+ ...(params.claudeRun === undefined
525
+ ? { checkCredentials: false }
526
+ : { claudeRun: params.claudeRun }),
505
527
  buildRoutePlan: () =>
506
528
  buildCliRoutePlan({
507
529
  spec: params.spec,
508
530
  options: params.options,
509
531
  agentFiles: params.agentFiles,
510
- routingConfig: params.routingConfig,
532
+ models: params.models,
511
533
  summary: params.summary,
512
534
  summarizerEnabled: params.summarizerEnabled,
513
535
  scoutEnabled: params.scoutEnabled,
@@ -131,7 +131,7 @@ export function validateScoutLeads(candidate: unknown): ScoutLead[] {
131
131
  export const MAX_LEADS = 12; // above this it is a filter of nothing
132
132
  export const MAX_LEADS_PER_PATH = 3; // stops one interesting file absorbing the whole budget
133
133
  export const MAX_WHY_CHARS = 240; // one sentence; a paragraph is a finding in disguise
134
- export const MAX_LEADS_BLOCK_CHARS = 3000; // bounded prompt growth per hunter, x4 hunters
134
+ export const MAX_LEADS_BLOCK_CHARS = 3000; // bounded prompt growth per hunter, times every hunter
135
135
 
136
136
  // The verbatim block shape from §3.8. The header paragraph is the
137
137
  // anti-anchoring guard, and it is what keeps §3.4's "bias" from decaying into
@@ -4,7 +4,7 @@
4
4
  // EXACTLY the wiring the engine used to hard-code (prose Step 4), so a caller
5
5
  // that passes nothing gets byte-identical behavior.
6
6
 
7
- import { parseLogicalIdentity } from "#model/routing";
7
+ import { modelNameFromAlias } from "#model/model-name";
8
8
 
9
9
  const SAFE_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
10
10
 
@@ -149,7 +149,7 @@ export function validateReviewSpec(candidate: unknown): ReviewSpec {
149
149
  if (diversityEnabled && Array.isArray(a.models)) {
150
150
  for (const model of a.models as string[]) {
151
151
  try {
152
- parseLogicalIdentity(model);
152
+ modelNameFromAlias(model);
153
153
  } catch (error) {
154
154
  must(
155
155
  false,
@@ -165,7 +165,7 @@ export function validateReviewSpec(candidate: unknown): ReviewSpec {
165
165
  );
166
166
  if (a.model !== undefined) {
167
167
  try {
168
- parseLogicalIdentity(a.model as string);
168
+ modelNameFromAlias(a.model as string);
169
169
  } catch (error) {
170
170
  must(
171
171
  false,