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
@@ -18,7 +18,9 @@ import type {
18
18
  TransportFailureCause,
19
19
  } from "../execution/contracts";
20
20
  import type { FailureClass } from "../execution/failure-classification";
21
+ import type { FailureCause } from "../execution/failure-policy";
21
22
  import { StepExecutionHarness } from "../execution/harness";
23
+ import { runWithFallback } from "../execution/model-fallback";
22
24
  import type { SpendReservation } from "../execution/spend-limiter";
23
25
  import type { NormalizedUsage } from "../execution/usage-normalized";
24
26
  import type { CredentialBroker } from "../security/credential-broker";
@@ -61,6 +63,20 @@ export interface StepSpec {
61
63
  backend?: "claude-code" | "opencode";
62
64
  models?: string[];
63
65
  route?: ResolvedModelRoute;
66
+ // The routes tried after `route`, in order, when the provider fails it
67
+ // (S4; the plan's `fallbacks`, the runner side is model-fallback.ts).
68
+ // Absent when the step's role names one model.
69
+ fallbackRoutes?: readonly ResolvedModelRoute[];
70
+ // The effort each of `fallbackRoutes` runs at, in the same order (S7): its
71
+ // `models` entry's effort, else the prompt's frontmatter, else the role's
72
+ // default (the pipeline's stepEffortFields). Absent with no fallbacks. A
73
+ // step built without it runs every fallback at `effort`.
74
+ fallbackEfforts?: readonly Effort[];
75
+ // How many attempts earlier models of this same step already used. The
76
+ // harness numbers this run's attempts after them, so every model's attempt
77
+ // logs, receipts and evidence keep their own files instead of overwriting
78
+ // the first model's. Absent means 0.
79
+ attemptOffset?: number;
64
80
  // Frozen route fingerprint from the admitted plan. Required for routed
65
81
  // production execution via createProductionRuntime.
66
82
  routeKey?: string;
@@ -108,15 +124,54 @@ export interface StepResult {
108
124
  // resolved one (a transport cause, never a harness cause). Absent on success,
109
125
  // and on a failure with no transport cause. The CLI record names it per hunter.
110
126
  failureCause?: TransportFailureCause;
127
+ // The cause the step's final failed attempt ended on, harness causes
128
+ // included: `failureCause` above keeps transport causes only, so a timeout
129
+ // (`watchdog_timeout`) or a bad answer (`format_violation`) was invisible to
130
+ // anything reading the result. The fallback reads this one. Absent on
131
+ // success, on cancellation, and when no cause was resolved. An attempt
132
+ // refused by a fenced spend bucket never reached the provider and has no
133
+ // cause, so after one this is the cause of the attempt before it.
134
+ finalCause?: FailureCause;
135
+ // The final attempt was refused by a fenced spend bucket (an earlier
136
+ // attempt on it left a cost nobody knows), before the transport was called.
137
+ // That attempt is counted in `attempts` but wrote no log or receipt. Read
138
+ // only by the fallback (model-fallback.ts); never recorded.
139
+ spendFenced?: true;
111
140
  // The final failed attempt's one-line explanation (TransportOutcome.failureDetail),
112
141
  // when the transport gave one. Absent on success.
113
142
  failureDetail?: string;
114
143
  // The secret the final failed attempt ran on (TransportOutcome.failureCredential).
115
144
  failureCredential?: FailureCredential;
145
+ // Each model the step tried, in order, when its role listed more than one
146
+ // (S4). The last entry not `skipped` is the model that ran. Absent on a
147
+ // step with one model, which records exactly what it recorded before.
148
+ modelAttempts?: ModelAttempt[];
116
149
  stderrTail: string;
117
150
  resultText: string;
118
151
  }
119
152
 
153
+ // One model of a step's list, as it ended. Usage is kept per model because
154
+ // models can bill differently (a subscription model, then a metered one):
155
+ // the step's total sums them, and only these entries keep each one's billing.
156
+ export interface ModelAttempt {
157
+ route: ResolvedModelRoute;
158
+ // `skipped`: never reached its provider. Either an earlier model on the
159
+ // same credential was refused its login (cause `auth_invalid`), or it was
160
+ // stopped before any request: its spend bucket was fenced, or it failed
161
+ // before its first attempt (no cause).
162
+ status: "ok" | "failed" | "skipped";
163
+ // Attempts that reached the provider: 0 for a skipped model.
164
+ attempts: number;
165
+ // The effort this model was asked to run at (S7; StepSpec.effort or its
166
+ // entry in `fallbackEfforts`), skipped models included. Optional only so a
167
+ // runner that predates it still type-checks; runWithFallback always sets it.
168
+ effort?: Effort;
169
+ // Why it failed, or `auth_invalid` for a model skipped after a refused
170
+ // login. Absent on `ok`, and on a model skipped for any other reason.
171
+ cause?: FailureCause;
172
+ usageV2?: NormalizedUsage;
173
+ }
174
+
120
175
  export interface StepRunner {
121
176
  run(step: StepSpec): Promise<StepResult>;
122
177
  }
@@ -211,8 +266,10 @@ export interface ClaudeCodeRunnerOptions {
211
266
 
212
267
  export class ClaudeCodeRunner implements StepRunner {
213
268
  private readonly harness: StepExecutionHarness;
269
+ private readonly signal?: AbortSignal;
214
270
 
215
271
  constructor(options: ClaudeCodeRunnerOptions = {}) {
272
+ this.signal = options.signal;
216
273
  this.harness = new StepExecutionHarness({
217
274
  workspaceRoot: options.workspaceRoot,
218
275
  executableAllowlist: options.executableAllowlist,
@@ -227,7 +284,19 @@ export class ClaudeCodeRunner implements StepRunner {
227
284
  });
228
285
  }
229
286
 
287
+ // A caller that builds its own plan (runPipeline with `models`, as the lab
288
+ // does) can hand this runner a step with fallbacks (S4). It runs them in
289
+ // order like the production runner does. Every Claude model here runs on
290
+ // the one Claude credential this runner holds; a model on another backend
291
+ // has no transport here, fails before any spawn with no cause, and so ends
292
+ // the step, recorded in its `modelAttempts`.
230
293
  async run(step: StepSpec): Promise<StepResult> {
231
- return this.harness.run(step);
294
+ return runWithFallback({
295
+ step,
296
+ runOn: (single) => this.harness.run(single),
297
+ credentialOf: (route) =>
298
+ route.backend === "claude-code" ? "claude-code" : undefined,
299
+ cancelled: () => this.signal?.aborted === true,
300
+ });
232
301
  }
233
302
  }
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readFile, realpath } from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { chooseOpenCodeSecret } from "#ci/crysk-secrets";
4
5
  import type {
5
6
  ClaudeBinaryResolutionDeps,
6
7
  ExecutableAllowlistEntry,
@@ -9,7 +10,8 @@ import {
9
10
  resolveClaudeCanonicalBinary,
10
11
  verifyExecutableBinding,
11
12
  } from "#model/provider-capabilities";
12
- import type { ResolvedRoutePlan } from "#model/routing";
13
+ import { planRoutes, type ResolvedRoutePlan } from "#model/routing";
14
+ import type { ClaudeCredentialKind } from "#review/preflight";
13
15
  import type { CredentialKind, RunnerBackend } from "./execution/contracts";
14
16
  // #161: the SAME predicate the Claude CLI transport files usage on
15
17
  // (`claudeCliCostBasis` -> `envBillsMetered`) is the one `credentialKindForRoute`
@@ -34,8 +36,33 @@ export interface RunnerAuthorityOptions {
34
36
  // `credentialKindForRoute` reads to decide a claude-code route's credential
35
37
  // kind, so it has to be able to carry ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN,
36
38
  // not just PATH.
39
+ //
40
+ // S5: in a review run this is the RUN env (security/claude-credential.ts): the
41
+ // process environment with every Claude credential removed but the one chosen at
42
+ // run start. It is also what the harness hands the child (`childEnv`), so the
43
+ // binding's kind and the child's credential are read from the same object.
37
44
  readonly env?: Readonly<Record<string, string | undefined>>;
45
+ // S5: the Claude credential chosen at run start. `api_key` attaches no Keychain
46
+ // broker: a broker would project the subscription and strip the key the run chose.
47
+ // Absent (tests, probes, doctor) keeps the pre-S5 decision below.
48
+ readonly claudeCredential?: ClaudeCredentialKind;
49
+ // U3 (S8, L12): the CRYSK_OPENCODE_* secret names the CI setup step built the
50
+ // OpenCode auth file from, read once per run from its manifest
51
+ // (security/opencode-secret-manifest.ts). An OpenCode route's kind follows them
52
+ // (credentialKindForRoute). Absent (no manifest: the old opencode-auth input, a
53
+ // local store, tests) keeps the provider literal.
54
+ readonly openCodeSecretNames?: readonly string[];
55
+ // `credentialBrokers.opencode` is ONE broker for every OpenCode route: a test
56
+ // seam, and what admission seeds when the plan names exactly one OpenCode
57
+ // credential. It cannot serve a plan with several (U4), so routes there take
58
+ // theirs from `openCodeBrokerFor`.
38
59
  readonly credentialBrokers?: Partial<Record<RunnerBackend, CredentialBroker>>;
60
+ // U4 (S9, L12): the broker for one OpenCode credential (kind + provider), per
61
+ // route. Admission builds one pool per run (createOpenCodeBrokerPool) so the
62
+ // bindings, the free-verdict upgrade and the server each route launches all
63
+ // hold the same instance for the same credential. Absent: a fresh
64
+ // `openCodeCredentialBrokerForKind` per binding, as before.
65
+ readonly openCodeBrokerFor?: OpenCodeBrokerFor;
39
66
  /** Independent executable authority — never derived from the candidate binary. */
40
67
  readonly executableAllowlists?: Partial<
41
68
  Record<RunnerBackend, readonly ExecutableAllowlistEntry[]>
@@ -47,6 +74,8 @@ export interface ResolvedRunnerOptions {
47
74
  readonly workspaceRoot: string;
48
75
  readonly executableAllowlist: readonly ExecutableAllowlistEntry[];
49
76
  readonly credentialBroker?: CredentialBroker;
77
+ // S5: the run env, when the caller gave one, for the legacy runner's harness.
78
+ readonly childEnv?: Readonly<Record<string, string | undefined>>;
50
79
  }
51
80
 
52
81
  export type RunnerAuthorityResolution =
@@ -220,7 +249,9 @@ function planUsesBackend(
220
249
  backend: RunnerBackend,
221
250
  ): boolean {
222
251
  const seen = new Set<RunnerBackend>();
223
- for (const step of plan.steps) {
252
+ // Fallbacks included (S4): an OpenCode model listed only as a fallback still
253
+ // needs its executable resolved before the run.
254
+ for (const step of planRoutes(plan)) {
224
255
  if (!seen.has(step.route.backend)) {
225
256
  seen.add(step.route.backend);
226
257
  if (step.route.backend === backend) {
@@ -359,15 +390,35 @@ export async function withClaudeDiscoveryAllowlist(
359
390
  // (claude-code-cli.ts) by construction. #279 is the one path where that
360
391
  // equality breaks.
361
392
  //
393
+ // S5 (2026-11-06): in a review run both inputs already follow the credential chosen at
394
+ // run start (security/claude-credential.ts). `env` is the run env, holding only that
395
+ // credential, and `hasBroker` is false when the API key was chosen
396
+ // (`RunnerAuthorityOptions.claudeCredential`), so this predicate answers metered
397
+ // exactly when the run uses the API key and needs no knowledge of the order itself.
398
+ // One side effect on #279: with the subscription chosen, the run env carries no key,
399
+ // so a degraded projection runs on no credential and fails, instead of quietly
400
+ // switching to a key mid-run.
401
+ //
362
402
  // Both arguments default to the "nothing is known" case (`env: {}`,
363
403
  // `hasBroker: false`) so a caller that omits them — every existing call site
364
404
  // that never threaded either through, and every test that does not care
365
405
  // about this dimension — keeps today's answer: subscription.
406
+ //
407
+ // U3 (S8, L12, 2026-11-06): `openCodeSecretNames` lifts the provider-keyed limit
408
+ // above for an auth file the CI setup step built from CRYSK_OPENCODE_* secrets.
409
+ // The names (never the store) say which secret built the provider's record, and
410
+ // chooseOpenCodeSecret, the same rule the setup step chose with, turns them into
411
+ // the kind: `_OAUTH` (openai only, subscription first) is the ChatGPT OAuth kind,
412
+ // `_API_KEY` is a metered API token, so `openai` on an API key now binds metered
413
+ // instead of being refused. Still pure: the caller read the names. Absent or
414
+ // silent names keep the provider literal, which the old `opencode-auth` input and
415
+ // a local store still get.
366
416
  export function credentialKindForRoute(
367
417
  backend: RunnerBackend,
368
418
  provider: string,
369
419
  env: Readonly<Record<string, string | undefined>> = {},
370
420
  hasBroker = false,
421
+ openCodeSecretNames?: readonly string[],
371
422
  ): CredentialKind {
372
423
  if (backend === "claude-code") {
373
424
  return !hasBroker && envBillsMetered(env)
@@ -375,6 +426,12 @@ export function credentialKindForRoute(
375
426
  : "claude_subscription_oauth";
376
427
  }
377
428
  if (backend === "opencode") {
429
+ const choice =
430
+ openCodeSecretNames === undefined
431
+ ? undefined
432
+ : chooseOpenCodeSecret(provider, openCodeSecretNames);
433
+ if (choice?.kind === "api_key") return "provider_api_token";
434
+ if (choice?.kind === "oauth") return "opencode_chatgpt_oauth";
378
435
  return provider === OPENCODE_OAUTH_PROVIDER
379
436
  ? "opencode_chatgpt_oauth"
380
437
  : "provider_api_token";
@@ -432,6 +489,51 @@ export function openCodeCredentialBrokerForKind(
432
489
  return new OpenCodeAuthBroker();
433
490
  }
434
491
 
492
+ // U4 (S9, L12): the broker for one OpenCode credential, keyed by its kind and
493
+ // provider. A pool memoises it per credential so every route on that credential
494
+ // shares ONE instance (#149's "one broker, never two diverging in silence", now
495
+ // scoped per credential instead of per plan) while routes on different
496
+ // credentials never share one: each broker projects only its own provider's
497
+ // record, so no server is ever handed another credential's.
498
+ export type OpenCodeBrokerFor = (
499
+ kind: CredentialKind,
500
+ provider: string,
501
+ ) => CredentialBroker;
502
+
503
+ export function createOpenCodeBrokerPool(
504
+ make: OpenCodeBrokerFor = openCodeCredentialBrokerForKind,
505
+ ): OpenCodeBrokerFor {
506
+ const brokers = new Map<string, CredentialBroker>();
507
+ return (kind, provider) => {
508
+ // JSON, not a joined string: no separator can make two pairs collide.
509
+ const key = JSON.stringify([kind, provider]);
510
+ let broker = brokers.get(key);
511
+ if (broker === undefined) {
512
+ broker = make(kind, provider);
513
+ brokers.set(key, broker);
514
+ }
515
+ return broker;
516
+ };
517
+ }
518
+
519
+ // The broker an OpenCode route of this credential runs on: the caller's single
520
+ // injected broker first (tests, and admission's seed for a one-credential plan),
521
+ // then the run's pool, then a fresh default.
522
+ export function openCodeBrokerForRoute(
523
+ options: Pick<
524
+ RunnerAuthorityOptions,
525
+ "credentialBrokers" | "openCodeBrokerFor"
526
+ >,
527
+ kind: CredentialKind,
528
+ provider: string,
529
+ ): CredentialBroker {
530
+ return (
531
+ options.credentialBrokers?.opencode ??
532
+ options.openCodeBrokerFor?.(kind, provider) ??
533
+ openCodeCredentialBrokerForKind(kind, provider)
534
+ );
535
+ }
536
+
435
537
  export function openCodeCredentialBroker(provider: string): CredentialBroker {
436
538
  return openCodeCredentialBrokerForKind(
437
539
  credentialKindForRoute("opencode", provider),
@@ -469,8 +571,15 @@ export async function resolveBindingAuthority(
469
571
  // around: see the WHY block on `credentialKindForRoute` above for the
470
572
  // full reasoning, including the one known exception where a broker is
471
573
  // present but its projection degrades (#279).
574
+ //
575
+ // S5: an API key chosen at run start attaches no broker at all, on any host. The
576
+ // run env then carries ANTHROPIC_API_KEY and nothing else, so the kind below is
577
+ // metered by the same predicate, and the child spends the key the run chose.
472
578
  const broker =
473
- options.credentialBrokers?.["claude-code"] ?? claudeCredentialBroker();
579
+ options.claudeCredential === "api_key"
580
+ ? undefined
581
+ : (options.credentialBrokers?.["claude-code"] ??
582
+ claudeCredentialBroker());
474
583
  // Falls back to `process.env` exactly like the opencode PATH lookup a few
475
584
  // lines below (`resolveOpenCodeCanonicalBinary`'s
476
585
  // `lookup.env?.PATH ?? process.env.PATH`) — nothing in the real CLI
@@ -531,7 +640,13 @@ export async function resolveBindingAuthority(
531
640
  if ("error" in verified) {
532
641
  return { error: verified.error };
533
642
  }
534
- const credentialKind = credentialKindForRoute(backend, provider);
643
+ const credentialKind = credentialKindForRoute(
644
+ backend,
645
+ provider,
646
+ {},
647
+ false,
648
+ options.openCodeSecretNames,
649
+ );
535
650
  return {
536
651
  binding: {
537
652
  backend,
@@ -547,11 +662,13 @@ export async function resolveBindingAuthority(
547
662
  // subscription's quota and a metered token's quota into one bucket
548
663
  // and make both wrong.
549
664
  credentialRef: `opencode-auth:${provider}`,
550
- credentialBroker:
551
- options.credentialBrokers?.opencode ??
552
- // #182: the kind above, not a second derivation — deriving again
553
- // here is how the broker and the kind drift apart unobserved.
554
- openCodeCredentialBrokerForKind(credentialKind, provider),
665
+ // #182: the kind above, not a second derivation — deriving again
666
+ // here is how the broker and the kind drift apart unobserved.
667
+ credentialBroker: openCodeBrokerForRoute(
668
+ options,
669
+ credentialKind,
670
+ provider,
671
+ ),
555
672
  bucketId: "opencode",
556
673
  },
557
674
  };
@@ -591,6 +708,7 @@ export async function resolveRunnerAuthority(
591
708
  ...(binding.credentialBroker
592
709
  ? { credentialBroker: binding.credentialBroker }
593
710
  : {}),
711
+ ...(options.env === undefined ? {} : { childEnv: options.env }),
594
712
  },
595
713
  };
596
714
  }
@@ -24,8 +24,7 @@ export function routesMatch(
24
24
  a.provider === b.provider &&
25
25
  a.modelFamily === b.modelFamily &&
26
26
  a.modelSnapshot === b.modelSnapshot &&
27
- a.modelVariant === b.modelVariant &&
28
- (a.gateway ?? "") === (b.gateway ?? "")
27
+ a.modelVariant === b.modelVariant
29
28
  );
30
29
  }
31
30