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
@@ -13,12 +13,12 @@ import {
13
13
  type CiReviewPolicyMode,
14
14
  } from "#ci/review-policy";
15
15
  import type { EffectiveConfig } from "#config/config";
16
- import type {
17
- ModelGateway,
18
- RouteMapping,
19
- RoutingConfig,
20
- RunnerBackend,
21
- } from "#model/routing";
16
+ import {
17
+ ModelNameError,
18
+ type ModelsConfig,
19
+ parseModelsConfig,
20
+ } from "#model/model-name";
21
+ import { judgeModelChoice } from "#model/routing";
22
22
  import { POST_MIN_SEVERITIES, type PostMinSeverity } from "#pr/post-floor";
23
23
  import type { SuspicionPrior } from "#review/prompt-set";
24
24
  import { type AgentSpec, isSafeSlug, type ReviewSpec } from "#review/spec";
@@ -36,7 +36,7 @@ import { REPO_DIR_NAME } from "../brand-paths";
36
36
  // imports only the ones it uses itself.
37
37
  import { CliError, CliUsageError, withUsageClass } from "../errors";
38
38
  import { DEFAULT_BASE_REF, listPaths } from "../git/refs";
39
- import { redactDiagnostic } from "../security/redact";
39
+ import { redactConfigValue } from "../security/redact";
40
40
  // review/size-gate.ts imports only a TYPE from here, so this is not a runtime
41
41
  // cycle — the type import is erased and size-gate has no load-time
42
42
  // dependency on this module.
@@ -512,7 +512,11 @@ Options:
512
512
  default 8; 0 pauses verification), and optional
513
513
  max_concurrent_steps (cap on steps in flight at once;
514
514
  a positive integer; unset = unlimited)
515
- --model <model> Override every agent's model
515
+ --model <model> Override every step's model but the materiality judge's:
516
+ claude:<name>-latest, claude:<full model name>,
517
+ opencode:<provider>/<model>, or a bare alias (sonnet,
518
+ opus, haiku, fable). A model only: per-role models and
519
+ their effort go in "models" in ~/.crysk/config.json
516
520
  --summary Enable the engine-owned PR summary (default)
517
521
  --no-summary Disable the engine-owned PR summary
518
522
  --scout review only: run the diff-only scout stage before the
@@ -1963,12 +1967,23 @@ export function assertBasenameOnly(file: string, index: number): void {
1963
1967
 
1964
1968
  export const AGENT_FILE_PATTERNS = ["deep-review-*.md", "review-*.md"];
1965
1969
 
1966
- // BIDIRECTIONAL on purpose, and this is the check that pays for itself. The
1967
- // default spec declares four agents and omits the lifecycle hunter, so
1968
- // running the 5-file clean set with that spec silently drops the one hunter
1969
- // the whole campaign is about — the run completes, the artifacts validate,
1970
- // the cost looks normal, and nothing downstream notices. So: every file the
1971
- // spec names must exist, AND every agent file present must be named.
1970
+ // BIDIRECTIONAL on purpose, and this is the check that pays for itself. A spec
1971
+ // that omits a file the dir carries silently drops that hunter — the run
1972
+ // completes, the artifacts validate, the cost looks normal, and nothing
1973
+ // downstream notices. So: every file the spec names must exist, AND every
1974
+ // agent file present must be named.
1975
+ //
1976
+ // The lifecycle hunter was retired from the default spec (2026-11-08: on the
1977
+ // benchmarks it added almost nothing the other hunters missed, for about 37%
1978
+ // of the cost and wall time). A custom set copied from an older default still
1979
+ // carries its file, so that one file gets the way out in its message.
1980
+ const RETIRED_AGENT_HINTS: Record<string, string> = {
1981
+ "deep-review-lifecycle.md":
1982
+ "; the lifecycle hunter was retired from the default spec: delete the " +
1983
+ "file, or keep the hunter with " +
1984
+ "CRYSK_EXTRA_HUNTERS=lifecycle:deep-review-lifecycle.md",
1985
+ };
1986
+
1972
1987
  export function agentsDirProblems(
1973
1988
  specFiles: string[],
1974
1989
  presentFiles: string[],
@@ -1987,7 +2002,7 @@ export function agentsDirProblems(
1987
2002
  if (!named.has(file)) {
1988
2003
  problems.push(
1989
2004
  `the dir has "${file}" but no agent in the spec references it ` +
1990
- "(it would never run)",
2005
+ `(it would never run)${RETIRED_AGENT_HINTS[file] ?? ""}`,
1991
2006
  );
1992
2007
  }
1993
2008
  }
@@ -2104,10 +2119,9 @@ function parseExtraHunters(read: BrandEnvValue | undefined): AgentSpec[] {
2104
2119
  });
2105
2120
  }
2106
2121
 
2107
- // Local mode's wiring: the four unconditional hunters, the conditional
2122
+ // Local mode's wiring: the three unconditional hunters, the conditional
2108
2123
  // parity hunter, and the refuter. Deliberately NOT defaultReviewSpec() — that
2109
- // one omits the lifecycle and logic hunters, and local mode targets the 6-file
2110
- // clean set. Hunter keys stay inside the findings-schema v1.1.0 Hunter/specialty
2124
+ // one omits the logic hunter, and local mode targets the 5-file clean set. Hunter keys stay inside the findings-schema v1.1.0 Hunter/specialty
2111
2125
  // set, which validateReviewSpec enforces.
2112
2126
  //
2113
2127
  // `env` is injectable (defaults to `process.env`) so PRHERO_EXTRA_HUNTERS can
@@ -2125,7 +2139,6 @@ export function localReviewSpec(
2125
2139
  role: "hunter",
2126
2140
  },
2127
2141
  { key: "resilience", file: "deep-review-resilience.md", role: "hunter" },
2128
- { key: "lifecycle", file: "deep-review-lifecycle.md", role: "hunter" },
2129
2142
  { key: "logic", file: "deep-review-logic.md", role: "hunter" },
2130
2143
  {
2131
2144
  key: "parity",
@@ -2175,7 +2188,11 @@ export const CONFIG_DIRECTION: Record<keyof LocalConfig, ConfigDirection> = {
2175
2188
  // exists. This row declares the key for the known-key set; the merge
2176
2189
  // descends into it rather than folding the object whole.
2177
2190
  summary: "capped",
2178
- routing: "person",
2191
+ // Which model runs each role and which Claude credential pays for it are the
2192
+ // operator's decisions: a committed file must not move them onto another
2193
+ // model or another bill. Both are PERSON_ONLY_KEYS, refused in a repo file.
2194
+ models: "person",
2195
+ credentials: "person",
2179
2196
  max_verification_steps: "capped",
2180
2197
  max_concurrent_steps: "capped",
2181
2198
  max_changed_lines: "capped",
@@ -2201,12 +2218,10 @@ export const CONFIG_DIRECTION: Record<keyof LocalConfig, ConfigDirection> = {
2201
2218
  };
2202
2219
 
2203
2220
  // The ONE nested key, so this is a second table and not a pattern. `enabled`
2204
- // takes the cap because it switches spend on; `model` cannot be capped even
2205
- // in principle — "narrower" is undefinable for a string, and a direction that
2206
- // cannot be computed is worse than no direction at all.
2221
+ // takes the cap because it switches spend on. `summary.model` is gone: the
2222
+ // summary model is the `summary` role under `models` (see parseSummaryConfig).
2207
2223
  export const SUMMARY_DIRECTION: Record<keyof SummaryConfig, ConfigDirection> = {
2208
2224
  enabled: "capped",
2209
- model: "person",
2210
2225
  };
2211
2226
 
2212
2227
  export interface LocalConfig {
@@ -2218,7 +2233,11 @@ export interface LocalConfig {
2218
2233
  agents_dir?: string;
2219
2234
  default_base?: string;
2220
2235
  summary?: SummaryConfig;
2221
- routing?: RoutingConfig;
2236
+ // Role -> model list (S1). A role not listed uses `default`, and with no
2237
+ // `default` the step keeps its prompt's model.
2238
+ models?: ModelsConfig;
2239
+ // Which Claude credential is used, in order (S5).
2240
+ credentials?: CredentialsConfig;
2222
2241
  // Item 7: unattended bound on the verify queue. Absent means
2223
2242
  // DEFAULT_MAX_VERIFICATION_STEPS. 0 is legal — every queued prior lands
2224
2243
  // `unconfirmed` (the pause switch, same shape as watch daily_cap).
@@ -2251,7 +2270,16 @@ export interface LocalConfig {
2251
2270
 
2252
2271
  export interface SummaryConfig {
2253
2272
  enabled?: boolean;
2254
- model?: string;
2273
+ }
2274
+
2275
+ // The Claude credentials a run may use, in the order they are tried (S5).
2276
+ // A closed vocabulary on purpose: this key is exempt from the credential
2277
+ // deny-list only because no value it admits can be a secret.
2278
+ export const CLAUDE_CREDENTIAL_KINDS = ["subscription", "api_key"] as const;
2279
+ export type ClaudeCredentialKind = (typeof CLAUDE_CREDENTIAL_KINDS)[number];
2280
+
2281
+ export interface CredentialsConfig {
2282
+ readonly claude?: readonly ClaudeCredentialKind[];
2255
2283
  }
2256
2284
 
2257
2285
  export interface SummarySettings {
@@ -2285,8 +2313,13 @@ export type ConfigLayer = Partial<LocalConfig>;
2285
2313
  // known key.
2286
2314
  const KNOWN_CONFIG_KEYS = new Set<string>(Object.keys(CONFIG_DIRECTION));
2287
2315
 
2316
+ // Keys a committed repo file may never set. Wider than "direction is person":
2317
+ // `agents_dir` and `post_min_severity` are person-direction keys a repo file
2318
+ // may still name. These two choose a model or a bill.
2319
+ const PERSON_ONLY_KEYS = new Set<string>(["models", "credentials"]);
2320
+
2288
2321
  const LOCAL_CONFIG_KEYS = new Set<string>(
2289
- Object.keys(CONFIG_DIRECTION).filter((key) => key !== "routing"),
2322
+ Object.keys(CONFIG_DIRECTION).filter((key) => !PERSON_ONLY_KEYS.has(key)),
2290
2323
  );
2291
2324
 
2292
2325
  const GLOBAL_CONFIG_KEYS = new Set<string>(
@@ -2319,19 +2352,21 @@ const GLOBAL_CONFIG_LABEL = "~/.crysk/config.json";
2319
2352
  // can still see was absent. The `?? []` locals below stay exactly as they
2320
2353
  // are: they feed the validators, and validating an absent key against the
2321
2354
  // empty array is what keeps every error string byte-identical.
2322
- // The repo layer's usage errors carry the repo-config class (T2d-1). It passes the
2323
- // classed routing parser for symmetry only: `routing` is not a repo key, so the file is
2324
- // rejected as a per-person key before any routing value is parsed. The person layer's
2325
- // errors carry no class (see parseGlobalConfig).
2355
+ // The repo layer's usage errors carry the repo-config class (T2d-1). The person
2356
+ // layer's errors carry no class (see parseGlobalConfig).
2326
2357
  // `label` is the file name an error should show: a repo still on the legacy
2327
2358
  // `.prhero/` passes `.prhero/config.json`, so the message names the file that
2328
2359
  // was actually read.
2360
+ // `warnings` collects what the file says that still works but is on its way
2361
+ // out (today: `summary.model: "haiku"`). Returned as data, never printed here:
2362
+ // this module is the pure half, and the shells decide where a warning goes.
2329
2363
  export function parseLocalConfig(
2330
2364
  raw: string,
2331
2365
  label: string = REPO_CONFIG_LABEL,
2366
+ warnings?: string[],
2332
2367
  ): ConfigLayer {
2333
2368
  return withUsageClass({ kind: "config-parse", source: "repo-config" }, () =>
2334
- parseConfigLayer(raw, label, LOCAL_CONFIG_KEYS, parseRoutingConfig, true),
2369
+ parseConfigLayer(raw, label, LOCAL_CONFIG_KEYS, true, warnings),
2335
2370
  );
2336
2371
  }
2337
2372
 
@@ -2341,22 +2376,28 @@ export function parseLocalConfig(
2341
2376
  // rejects the three that are, because no global answer to them could be
2342
2377
  // right: two are lists of paths inside one repository and the third selects a
2343
2378
  // commit range ahead of an autodetection that already works.
2344
- // Its routing object is parsed without the routing class. That class renders
2345
- // PRH-ROUTING-INVALID, whose text names CRYSK_ROUTING and `gh variable set`: the
2346
- // fix for the CI routing input, not for this personal file. The message is the same.
2347
2379
  export function parseGlobalConfig(
2348
2380
  raw: string,
2349
2381
  label: string = GLOBAL_CONFIG_LABEL,
2382
+ warnings?: string[],
2350
2383
  ): ConfigLayer {
2351
- return parseConfigLayer(
2352
- raw,
2353
- label,
2354
- GLOBAL_CONFIG_KEYS,
2355
- parseRoutingValue,
2356
- false,
2357
- );
2384
+ return parseConfigLayer(raw, label, GLOBAL_CONFIG_KEYS, false, warnings);
2358
2385
  }
2359
2386
 
2387
+ // S2's clean break: `routing` is not read alongside `models`, it is refused
2388
+ // with the one thing that fixes it. Checked BEFORE the unknown-key and the
2389
+ // per-person checks, so a repo file gets this message too and not "routing is
2390
+ // a per-person key", which would send the operator to move a dead key.
2391
+ export const REMOVED_ROUTING_MESSAGE =
2392
+ '`routing` is gone: set models per role, e.g. `"models": {"hunter.logic": ["claude:sonnet-latest"]}`';
2393
+
2394
+ // `summary.model` is gone too (L6 item 1), except for the one value `crysk
2395
+ // init` used to write, which is accepted with a warning (parseSummaryConfig).
2396
+ const SUMMARY_MODEL_EXAMPLE =
2397
+ '`"models": {"summary": ["claude:haiku-latest"]}`';
2398
+ const SUMMARY_MODEL_INIT_VALUE = "haiku";
2399
+ const SUMMARY_MODEL_CONVERTED = ["claude:haiku-latest"] as const;
2400
+
2360
2401
  // `??` is what makes an explicit `null` mean "absent" for the two arrays, and
2361
2402
  // the returned layer has to agree with it: `{"suspicion_priors": null}`
2362
2403
  // validates as the empty array, so it must not claim the layer spoke either.
@@ -2376,14 +2417,12 @@ function parseOptionalBoolean(
2376
2417
  return value;
2377
2418
  }
2378
2419
 
2379
- // `parseRouting` is the layer's routing parser: the classed one for the repo file, the
2380
- // unclassed one for the person file (see parseGlobalConfig for why it differs).
2381
2420
  function parseConfigLayer(
2382
2421
  raw: string,
2383
2422
  file: string,
2384
2423
  admitted: ReadonlySet<string>,
2385
- parseRouting: typeof parseRoutingConfig,
2386
2424
  isRepoFile: boolean,
2425
+ warnings: string[] | undefined,
2387
2426
  ): ConfigLayer {
2388
2427
  let parsed: unknown;
2389
2428
  try {
@@ -2398,8 +2437,11 @@ function parseConfigLayer(
2398
2437
  }
2399
2438
  const config = parsed as Record<string, unknown>;
2400
2439
  for (const key of Object.keys(config)) {
2440
+ if (key === "routing") {
2441
+ throw new CliUsageError(`${file}: ${REMOVED_ROUTING_MESSAGE}`);
2442
+ }
2401
2443
  if (!KNOWN_CONFIG_KEYS.has(key)) {
2402
- throw new CliUsageError(`${file} unknown key: ${redactDiagnostic(key)}`);
2444
+ throw new CliUsageError(`${file} unknown key: ${redactConfigValue(key)}`);
2403
2445
  }
2404
2446
  // Templated over the OFFENDING key, never a fixed example: one hardcoded
2405
2447
  // key name across three rejections sends two operators out of three
@@ -2451,8 +2493,39 @@ function parseConfigLayer(
2451
2493
  throw new CliUsageError(`suspicion_priors[${i}].reason required`);
2452
2494
  }
2453
2495
  }
2454
- const summary = parseSummaryConfig(config.summary, file);
2455
- const routing = parseRouting(config.routing, file);
2496
+ const summaryParse = parseSummaryConfig(config.summary, file);
2497
+ const summary = summaryParse?.summary;
2498
+ let models = parseModels(config.models, file);
2499
+ if (summaryParse?.initModel === true) {
2500
+ if (isRepoFile) {
2501
+ // L6 item 6: a repo file can no longer pick the summary model, and
2502
+ // `models` is person-only, so the init-written value is dropped. It was
2503
+ // the summarizer prompt's own model, so dropping it changes nothing.
2504
+ warnings?.push(
2505
+ `${file}: summary.model is gone and is ignored here: the summary model is set per person, under models.summary in your person config (~/.crysk/config.json). Delete summary.model from this file.`,
2506
+ );
2507
+ } else if (models?.summary !== undefined) {
2508
+ warnings?.push(
2509
+ `${file}: summary.model is gone and models.summary already sets the summary model. Delete summary.model.`,
2510
+ );
2511
+ } else {
2512
+ models = { ...models, summary: [...SUMMARY_MODEL_CONVERTED] };
2513
+ warnings?.push(
2514
+ `${file}: summary.model is gone; "haiku" is read as ${SUMMARY_MODEL_EXAMPLE}. Write that instead of summary.model.`,
2515
+ );
2516
+ }
2517
+ }
2518
+ // The judge's list is kept as written (the plan skips what it cannot
2519
+ // use), but a model it will never run on is said out loud here, once.
2520
+ if (models?.judge !== undefined) {
2521
+ const { model, dropped } = judgeModelChoice(models);
2522
+ if (dropped.length > 0) {
2523
+ warnings?.push(
2524
+ `${file}: models.judge skips ${dropped.join(", ")}: the materiality judge runs only on claude:sonnet-latest or claude:opus-latest${model === undefined ? ", so it stands down" : ""}.`,
2525
+ );
2526
+ }
2527
+ }
2528
+ const credentials = parseCredentialsConfig(config.credentials, file);
2456
2529
  const maxVerificationSteps = parseNonNegativeInteger(
2457
2530
  config.max_verification_steps,
2458
2531
  "max_verification_steps",
@@ -2536,7 +2609,8 @@ function parseConfigLayer(
2536
2609
  ...optionalString(config, "agents_dir", file),
2537
2610
  ...optionalString(config, "default_base", file),
2538
2611
  ...(summary === undefined ? {} : { summary }),
2539
- ...(routing === undefined ? {} : { routing }),
2612
+ ...(models === undefined ? {} : { models }),
2613
+ ...(credentials === undefined ? {} : { credentials }),
2540
2614
  ...(maxVerificationSteps === undefined
2541
2615
  ? {}
2542
2616
  : { max_verification_steps: maxVerificationSteps }),
@@ -2580,251 +2654,83 @@ function parseConfigLayer(
2580
2654
  };
2581
2655
  }
2582
2656
 
2583
- const CREDENTIAL_KEY_NAMES = new Set([
2584
- "apikey",
2585
- "api_key",
2586
- "token",
2587
- "secret",
2588
- "password",
2589
- "bearer",
2590
- "auth",
2591
- "credential",
2592
- "credentials",
2593
- ]);
2594
-
2595
- function checkNoCredentials(
2596
- obj: Record<string, unknown>,
2597
- path: string,
2598
- file: string,
2599
- ): void {
2600
- for (const key of Object.keys(obj)) {
2601
- const lower = key.toLowerCase();
2602
- if (
2603
- CREDENTIAL_KEY_NAMES.has(lower) ||
2604
- lower.includes("secret") ||
2605
- lower.includes("password") ||
2606
- lower.includes("token") ||
2607
- lower.includes("apikey") ||
2608
- lower.includes("api_key")
2609
- ) {
2610
- throw new CliUsageError(
2611
- `${file} ${path}: credentials are not permitted in routing config`,
2612
- );
2613
- }
2614
- const val = obj[key];
2615
- if (typeof val === "string") {
2616
- const redacted = redactDiagnostic(val);
2617
- if (redacted !== val) {
2618
- throw new CliUsageError(
2619
- `${file} ${path}: credentials are not permitted in routing config`,
2620
- );
2621
- }
2657
+ // The `models` object (S1, S3). Its rules live in model/model-name.ts; this
2658
+ // adds the file to every message, as every other key's error does.
2659
+ function parseModels(value: unknown, file: string): ModelsConfig | undefined {
2660
+ if (value === undefined) return undefined;
2661
+ try {
2662
+ return parseModelsConfig(value);
2663
+ } catch (error) {
2664
+ if (error instanceof ModelNameError) {
2665
+ throw new CliUsageError(`${file} ${error.message}`);
2622
2666
  }
2667
+ throw error;
2623
2668
  }
2624
2669
  }
2625
2670
 
2626
- const KNOWN_ROUTE_MAPPING_KEYS = new Set([
2627
- "logical",
2628
- "backend",
2629
- "provider",
2630
- "gateway",
2631
- "modelFamily",
2632
- "modelSnapshot",
2633
- "modelVariant",
2634
- "disabled",
2635
- "allowSpend",
2636
- ]);
2671
+ const CREDENTIALS_EXAMPLE =
2672
+ '`"credentials": {"claude": ["subscription", "api_key"]}`';
2637
2673
 
2638
- function parseRouteMapping(
2639
- m: unknown,
2640
- path: string,
2674
+ // `credentials` (S5): which Claude credential a run uses, in order. Parsed and
2675
+ // validated here; choosing a credential at run start is not this parser's job.
2676
+ //
2677
+ // WHY this key escapes the credential deny-list that used to guard `routing`:
2678
+ // it names KINDS of credential, never one. The values are a closed set, and
2679
+ // no message echoes a value, so a secret pasted here is refused unseen.
2680
+ function parseCredentialsConfig(
2681
+ value: unknown,
2641
2682
  file: string,
2642
- ): RouteMapping {
2643
- if (typeof m !== "object" || m === null || Array.isArray(m)) {
2644
- throw new CliUsageError(`${file} ${path} must be an object`);
2645
- }
2646
- const mapping = m as Record<string, unknown>;
2647
- checkNoCredentials(mapping, path, file);
2648
-
2649
- for (const key of Object.keys(mapping)) {
2650
- if (!KNOWN_ROUTE_MAPPING_KEYS.has(key)) {
2651
- throw new CliUsageError(
2652
- `${file} ${path} unknown key: ${redactDiagnostic(key)}`,
2653
- );
2654
- }
2683
+ ): CredentialsConfig | undefined {
2684
+ if (value === undefined) return undefined;
2685
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
2686
+ throw new CliUsageError(
2687
+ `${file} credentials must be an object, e.g. ${CREDENTIALS_EXAMPLE}`,
2688
+ );
2655
2689
  }
2656
-
2657
- if (mapping.logical !== undefined) {
2658
- if (
2659
- typeof mapping.logical !== "string" ||
2660
- mapping.logical.trim().length === 0
2661
- ) {
2690
+ const record = value as Record<string, unknown>;
2691
+ for (const key of Object.keys(record)) {
2692
+ if (key !== "claude") {
2662
2693
  throw new CliUsageError(
2663
- `${file} ${path}.logical must be a non-empty string`,
2694
+ `${file} credentials has an unknown key "${redactConfigValue(key)}": only claude is supported, e.g. ${CREDENTIALS_EXAMPLE}`,
2664
2695
  );
2665
2696
  }
2666
2697
  }
2667
-
2668
- if (
2669
- typeof mapping.backend !== "string" ||
2670
- (mapping.backend !== "claude-code" && mapping.backend !== "opencode")
2671
- ) {
2698
+ if (record.claude === undefined) return {};
2699
+ const list = record.claude;
2700
+ if (!Array.isArray(list) || list.length === 0) {
2672
2701
  throw new CliUsageError(
2673
- `${file} ${path}.backend must be claude-code|opencode`,
2702
+ `${file} credentials.claude must list subscription, api_key or both, in the order to try them`,
2674
2703
  );
2675
2704
  }
2676
-
2677
- if (
2678
- typeof mapping.provider !== "string" ||
2679
- mapping.provider.trim().length === 0
2680
- ) {
2681
- throw new CliUsageError(
2682
- `${file} ${path}.provider must be a non-empty string`,
2683
- );
2684
- }
2685
-
2686
- if (mapping.gateway !== undefined) {
2705
+ const seen = new Set<string>();
2706
+ for (const [i, entry] of list.entries()) {
2687
2707
  if (
2688
- typeof mapping.gateway !== "string" ||
2689
- (mapping.gateway !== "configured" &&
2690
- mapping.gateway !== "direct" &&
2691
- mapping.gateway !== "openrouter")
2708
+ typeof entry !== "string" ||
2709
+ !(CLAUDE_CREDENTIAL_KINDS as readonly string[]).includes(entry)
2692
2710
  ) {
2693
2711
  throw new CliUsageError(
2694
- `${file} ${path}.gateway must be configured|direct|openrouter`,
2712
+ `${file} credentials.claude[${i}] must be "subscription" or "api_key"`,
2695
2713
  );
2696
2714
  }
2697
- }
2698
-
2699
- if (
2700
- mapping.modelFamily !== undefined &&
2701
- typeof mapping.modelFamily !== "string"
2702
- ) {
2703
- throw new CliUsageError(`${file} ${path}.modelFamily must be a string`);
2704
- }
2705
- if (
2706
- mapping.modelSnapshot !== undefined &&
2707
- typeof mapping.modelSnapshot !== "string"
2708
- ) {
2709
- throw new CliUsageError(`${file} ${path}.modelSnapshot must be a string`);
2710
- }
2711
- if (
2712
- mapping.modelVariant !== undefined &&
2713
- typeof mapping.modelVariant !== "string"
2714
- ) {
2715
- throw new CliUsageError(`${file} ${path}.modelVariant must be a string`);
2716
- }
2717
- if (mapping.disabled !== undefined && typeof mapping.disabled !== "boolean") {
2718
- throw new CliUsageError(`${file} ${path}.disabled must be a boolean`);
2719
- }
2720
- if (
2721
- mapping.allowSpend !== undefined &&
2722
- typeof mapping.allowSpend !== "boolean"
2723
- ) {
2724
- throw new CliUsageError(`${file} ${path}.allowSpend must be a boolean`);
2725
- }
2726
-
2727
- return {
2728
- ...(mapping.logical ? { logical: mapping.logical as string } : {}),
2729
- backend: mapping.backend as RunnerBackend,
2730
- provider: mapping.provider as string,
2731
- ...(mapping.gateway ? { gateway: mapping.gateway as ModelGateway } : {}),
2732
- ...(mapping.modelFamily
2733
- ? { modelFamily: mapping.modelFamily as string }
2734
- : {}),
2735
- ...(mapping.modelSnapshot
2736
- ? { modelSnapshot: mapping.modelSnapshot as string }
2737
- : {}),
2738
- ...(mapping.modelVariant
2739
- ? { modelVariant: mapping.modelVariant as string }
2740
- : {}),
2741
- ...(mapping.disabled !== undefined
2742
- ? { disabled: mapping.disabled as boolean }
2743
- : {}),
2744
- ...(mapping.allowSpend !== undefined
2745
- ? { allowSpend: mapping.allowSpend as boolean }
2746
- : {}),
2747
- };
2748
- }
2749
-
2750
- // Every usage error of the routing object carries the routing class (T2d-1). The CI
2751
- // routing input (src/ci/setup.ts) keeps its own class and discards this one. The repo
2752
- // layer passes this parser too, but never reaches a routing value (see
2753
- // parseLocalConfig). The person layer calls parseRoutingValue directly, so its errors
2754
- // carry no class.
2755
- export function parseRoutingConfig(
2756
- value: unknown,
2757
- file: string,
2758
- ): RoutingConfig | undefined {
2759
- return withUsageClass({ kind: "config-parse", source: "routing" }, () =>
2760
- parseRoutingValue(value, file),
2761
- );
2762
- }
2763
-
2764
- function parseRoutingValue(
2765
- value: unknown,
2766
- file: string,
2767
- ): RoutingConfig | undefined {
2768
- if (value === undefined) return undefined;
2769
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
2770
- throw new CliUsageError(`${file} routing must be an object`);
2771
- }
2772
- const routing = value as Record<string, unknown>;
2773
- checkNoCredentials(routing, "routing", file);
2774
-
2775
- for (const key of Object.keys(routing)) {
2776
- if (key !== "mappings" && key !== "default" && key !== "disabled") {
2715
+ if (seen.has(entry)) {
2777
2716
  throw new CliUsageError(
2778
- `${file} routing unknown key: ${redactDiagnostic(key)}`,
2717
+ `${file} credentials.claude lists "${entry}" twice`,
2779
2718
  );
2780
2719
  }
2720
+ seen.add(entry);
2781
2721
  }
2782
-
2783
- let mappings: RouteMapping[] | Record<string, RouteMapping> | undefined;
2784
- if (routing.mappings !== undefined) {
2785
- if (Array.isArray(routing.mappings)) {
2786
- mappings = routing.mappings.map((m, i) =>
2787
- parseRouteMapping(m, `routing.mappings[${i}]`, file),
2788
- );
2789
- } else if (
2790
- typeof routing.mappings === "object" &&
2791
- routing.mappings !== null
2792
- ) {
2793
- const rec = routing.mappings as Record<string, unknown>;
2794
- const result: Record<string, RouteMapping> = {};
2795
- for (const [k, v] of Object.entries(rec)) {
2796
- result[k] = parseRouteMapping(v, `routing.mappings.${k}`, file);
2797
- }
2798
- mappings = result;
2799
- } else {
2800
- throw new CliUsageError(
2801
- `${file} routing.mappings must be an array or object`,
2802
- );
2803
- }
2804
- }
2805
-
2806
- let def: RouteMapping | undefined;
2807
- if (routing.default !== undefined) {
2808
- def = parseRouteMapping(routing.default, "routing.default", file);
2809
- }
2810
-
2811
- if (routing.disabled !== undefined && typeof routing.disabled !== "boolean") {
2812
- throw new CliUsageError(`${file} routing.disabled must be a boolean`);
2813
- }
2814
-
2815
- return {
2816
- ...(mappings ? { mappings } : {}),
2817
- ...(def ? { default: def } : {}),
2818
- ...(routing.disabled !== undefined
2819
- ? { disabled: routing.disabled as boolean }
2820
- : {}),
2821
- };
2722
+ return { claude: list as ClaudeCredentialKind[] };
2822
2723
  }
2823
2724
 
2725
+ // `initModel` is true when the file said `summary.model: "haiku"`, the value
2726
+ // `crysk init` wrote into every scaffolded repo file (L6 item 1): accepted with
2727
+ // a warning so those repos keep working, and turned into `models.summary` by
2728
+ // the caller where the layer may hold `models`. Any other value is refused with
2729
+ // the new form.
2824
2730
  function parseSummaryConfig(
2825
2731
  value: unknown,
2826
2732
  file: string,
2827
- ): SummaryConfig | undefined {
2733
+ ): { summary: SummaryConfig; initModel: boolean } | undefined {
2828
2734
  if (value === undefined) return undefined;
2829
2735
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
2830
2736
  throw new CliUsageError(`${file} summary must be an object`);
@@ -2838,15 +2744,14 @@ function parseSummaryConfig(
2838
2744
  if (config.enabled !== undefined && typeof config.enabled !== "boolean") {
2839
2745
  throw new CliUsageError(`${file} summary.enabled must be a boolean`);
2840
2746
  }
2841
- if (
2842
- config.model !== undefined &&
2843
- (typeof config.model !== "string" || config.model.trim().length === 0)
2844
- ) {
2845
- throw new CliUsageError(`${file} summary.model must be a non-empty string`);
2747
+ if (config.model !== undefined && config.model !== SUMMARY_MODEL_INIT_VALUE) {
2748
+ throw new CliUsageError(
2749
+ `${file} summary.model is gone: set the summary model per person, under models in your person config, e.g. ${SUMMARY_MODEL_EXAMPLE}`,
2750
+ );
2846
2751
  }
2847
2752
  return {
2848
- ...(config.enabled === undefined ? {} : { enabled: config.enabled }),
2849
- ...(config.model === undefined ? {} : { model: config.model as string }),
2753
+ summary: config.enabled === undefined ? {} : { enabled: config.enabled },
2754
+ initModel: config.model !== undefined,
2850
2755
  };
2851
2756
  }
2852
2757
 
@@ -2948,7 +2853,9 @@ export function resolveSummary(
2948
2853
  options: Pick<CliOptions, "summary" | "model">,
2949
2854
  config: Pick<ConfigLayer, "summary">,
2950
2855
  ): SummarySettings {
2951
- const model = options.model ?? config.summary?.model;
2856
+ // `--model` only: the configured summary model is `models.summary`, which
2857
+ // the route plan reads.
2858
+ const model = options.model;
2952
2859
  return {
2953
2860
  enabled: options.summary ?? config.summary?.enabled ?? true,
2954
2861
  ...(model === undefined ? {} : { model }),
@@ -3101,11 +3008,6 @@ export function mergeConfig(
3101
3008
  (layer) => layer.summary?.enabled,
3102
3009
  (a, b) => a && b,
3103
3010
  );
3104
- const summaryModel = foldKey(
3105
- layers,
3106
- SUMMARY_DIRECTION.model,
3107
- (layer) => layer.summary?.model,
3108
- );
3109
3011
  const maxSteps = foldKey(
3110
3012
  layers,
3111
3013
  CONFIG_DIRECTION.max_verification_steps,
@@ -3158,10 +3060,17 @@ export function mergeConfig(
3158
3060
  CONFIG_DIRECTION.post_min_severity,
3159
3061
  (layer) => layer.post_min_severity,
3160
3062
  );
3161
- const routing = foldKey(
3063
+ // Folded whole, not per role: the person layer is the only one that may
3064
+ // hold either, so there is never a second layer to merge roles from.
3065
+ const models = foldKey(
3066
+ layers,
3067
+ CONFIG_DIRECTION.models,
3068
+ (layer) => layer.models,
3069
+ );
3070
+ const credentials = foldKey(
3162
3071
  layers,
3163
- CONFIG_DIRECTION.routing,
3164
- (layer) => layer.routing,
3072
+ CONFIG_DIRECTION.credentials,
3073
+ (layer) => layer.credentials,
3165
3074
  );
3166
3075
  const ciReviewPolicy = foldKey(
3167
3076
  layers,
@@ -3209,7 +3118,6 @@ export function mergeConfig(
3209
3118
  ...(summaryEnabled.value === undefined
3210
3119
  ? {}
3211
3120
  : { enabled: summaryEnabled.value }),
3212
- ...(summaryModel.value === undefined ? {} : { model: summaryModel.value }),
3213
3121
  };
3214
3122
 
3215
3123
  const effective: LocalConfig = {
@@ -3224,10 +3132,11 @@ export function mergeConfig(
3224
3132
  ...(defaultBase.value === undefined
3225
3133
  ? {}
3226
3134
  : { default_base: defaultBase.value }),
3227
- ...(summaryEnabled.value === undefined && summaryModel.value === undefined
3135
+ ...(summaryEnabled.value === undefined ? {} : { summary }),
3136
+ ...(models.value === undefined ? {} : { models: models.value }),
3137
+ ...(credentials.value === undefined
3228
3138
  ? {}
3229
- : { summary }),
3230
- ...(routing.value === undefined ? {} : { routing: routing.value }),
3139
+ : { credentials: credentials.value }),
3231
3140
  ...(maxSteps.value === undefined
3232
3141
  ? {}
3233
3142
  : { max_verification_steps: maxSteps.value }),
@@ -3280,8 +3189,9 @@ export function mergeConfig(
3280
3189
  default_base: defaultBase.source,
3281
3190
  parity_trigger_paths: triggers.source,
3282
3191
  suspicion_priors: priors.source,
3283
- summary: { enabled: summaryEnabled.source, model: summaryModel.source },
3284
- routing: routing.source,
3192
+ summary: { enabled: summaryEnabled.source },
3193
+ models: models.source,
3194
+ credentials: credentials.source,
3285
3195
  max_verification_steps: maxSteps.source,
3286
3196
  max_concurrent_steps: maxConcurrentSteps.source,
3287
3197
  max_changed_lines: maxLines.source,
@@ -3342,7 +3252,6 @@ export interface InitTemplateInput {
3342
3252
  export interface InitTemplateOmissions {
3343
3253
  agentsDir: boolean;
3344
3254
  summaryEnabled: boolean;
3345
- summaryModel: boolean;
3346
3255
  // The same three facts as config-file key names, for init's log. Derived
3347
3256
  // here rather than rebuilt at the call site, because a scaffold that omits a
3348
3257
  // key and a log that does not mention it is worse than either alone: the
@@ -3371,15 +3280,12 @@ export function initTemplateOmissions(
3371
3280
  (input.global?.agents_dir !== undefined &&
3372
3281
  input.agentsDirFromFlag !== true);
3373
3282
  const summaryEnabled = input.global?.summary?.enabled !== undefined;
3374
- const summaryModel = input.global?.summary?.model !== undefined;
3375
3283
  return {
3376
3284
  agentsDir,
3377
3285
  summaryEnabled,
3378
- summaryModel,
3379
3286
  keys: [
3380
3287
  ...(agentsDir ? ["agents_dir"] : []),
3381
3288
  ...(summaryEnabled ? ["summary.enabled"] : []),
3382
- ...(summaryModel ? ["summary.model"] : []),
3383
3289
  ],
3384
3290
  };
3385
3291
  }
@@ -3394,16 +3300,17 @@ export function initTemplateOmissions(
3394
3300
  // required.
3395
3301
  export function initConfigTemplate(input: InitTemplateInput): string {
3396
3302
  const omit = initTemplateOmissions(input);
3303
+ // No `summary.model` any more: the summary model is a person setting
3304
+ // (`models.summary`), and a repo file that names it gets a warning.
3397
3305
  const summary: SummaryConfig = {
3398
3306
  ...(omit.summaryEnabled ? {} : { enabled: true }),
3399
- ...(omit.summaryModel ? {} : { model: DEFAULT_SUMMARY_MODEL }),
3400
3307
  };
3401
3308
  return `${JSON.stringify(
3402
3309
  {
3403
3310
  ...(omit.agentsDir ? {} : { agents_dir: input.agentsDir }),
3404
3311
  // Always written, whatever the global file says.
3405
3312
  default_base: input.defaultBase,
3406
- // Dropped WHOLE when both fields hoisted: `"summary": {}` parses fine
3313
+ // Dropped WHOLE when `enabled` hoisted: `"summary": {}` parses fine
3407
3314
  // and configures nothing, which is a line whose only effect is to make
3408
3315
  // the next reader wonder what it does.
3409
3316
  ...(Object.keys(summary).length === 0 ? {} : { summary }),