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
@@ -11,23 +11,21 @@ import {
11
11
  type MaterialityVerdict,
12
12
  parseJudgeVerdict,
13
13
  } from "#compare/materiality";
14
- import {
15
- defaultEffortForRole,
16
- type Effort,
17
- type StepRole,
18
- } from "#model/catalog";
14
+ import { defaultEffortForRole, type Effort, isEffort } from "#model/catalog";
15
+ import type { ModelsConfig } from "#model/model-name";
19
16
  import {
20
17
  agentStepKey,
21
18
  buildResolvedRoutePlan,
19
+ claudeCliModel,
20
+ InvalidModelError,
22
21
  isMeasuredJudgeRoute,
23
22
  MATERIALITY_JUDGE_MODEL,
24
23
  MATERIALITY_STEP_KEY,
25
24
  type ResolvedModelRoute,
26
25
  type ResolvedRoutePlan,
27
- type RoutingConfig,
26
+ type ResolvedStepRoute,
28
27
  type RunnerBackend,
29
28
  resolveMaterialityJudgeRoute,
30
- spawnModelForClaudeCli,
31
29
  } from "#model/routing";
32
30
  import {
33
31
  composeAdjudicationPrompt,
@@ -140,14 +138,18 @@ import {
140
138
  recordDiversityHunterResult,
141
139
  } from "../diversity/pipeline-integration";
142
140
  import { writeJsonAtomically } from "../execution/atomic-write";
143
- import type {
144
- FailureCredential,
145
- TransportFailureCause,
141
+ import { claudeSessionTracePath } from "../execution/claude-session-trace";
142
+ import {
143
+ effortApplied,
144
+ type FailureCredential,
145
+ type TransportFailureCause,
146
146
  } from "../execution/contracts";
147
+ import type { FailureCause } from "../execution/failure-policy";
147
148
  // One predicate, owned beside the appends it recognizes. Already in this
148
149
  // module's graph through step-runner's value import of the harness, so it
149
150
  // adds no weight (the atomic-write WHY above is about a NEW dependency).
150
151
  import { isHarnessStderrAnnotation } from "../execution/harness";
152
+ import { ranRoute } from "../execution/model-fallback";
151
153
  import {
152
154
  DEFAULT_CANCELLATION_DEADLINE_MS,
153
155
  HARNESS_GRACE_MARGIN_MS,
@@ -294,9 +296,9 @@ export interface PipelineInput {
294
296
  // demotes the immaterial ones to advisory. ABSENT means no judge step and
295
297
  // findings exactly as before (the scout's rule); pipeline.json still
296
298
  // carries a `materiality` record (`enabled: false`, `status: "skipped"`).
297
- // No `model` seat on purpose: the judge is pinned to the model it was
298
- // measured on (MATERIALITY_JUDGE_MODEL), and neither `--model` nor a
299
- // frontmatter edit may move it.
299
+ // No `model` seat on purpose: the judge runs only on a model it was
300
+ // measured on (sonnet by default, opus through `models.judge`), and neither
301
+ // `--model`, `models.default` nor a frontmatter edit may move it.
300
302
  materiality?: { promptPath: string };
301
303
  // The PR title the materiality judge reads (S9): PrTarget.title in PR mode,
302
304
  // the reviewed head's commit subject in local mode. Author-controlled, so
@@ -352,9 +354,11 @@ export interface PipelineInput {
352
354
  // so callers that pass nothing see byte-identical step names, per_agent
353
355
  // keys, and parity semantics.
354
356
  spec?: ReviewSpec;
355
- // D2 PR3: Optional pre-resolved model route plan or config
357
+ // D2 PR3: Optional pre-resolved model route plan, or the role -> model
358
+ // lists to build one from (S1). Absent `models` falls back to the merged
359
+ // config's, as the routing config used to.
356
360
  routePlan?: ResolvedRoutePlan;
357
- routingConfig?: RoutingConfig;
361
+ models?: ModelsConfig;
358
362
  // Item 7: skip hunter (and scout) fan-out. A re-review whose restricted
359
363
  // delta is empty still classifies and verifies (C6); spawning hunters on
360
364
  // an empty patch would bill a first-review for nothing. Absent = run
@@ -1090,6 +1094,10 @@ interface StepMeta {
1090
1094
  // when the step carries no route (the legacy Claude-only shape), where the
1091
1095
  // backend is not recorded and guessing it would be fabrication.
1092
1096
  effort_applied?: boolean;
1097
+ // The OpenCode variant the step's backend was sent: its `models` entry's
1098
+ // effort (S7). Absent when none was sent (D1), and on every Claude step,
1099
+ // whose level is `effort` above.
1100
+ variant?: string;
1093
1101
  tools: string[];
1094
1102
  systemPromptPath: string;
1095
1103
  outPath: string;
@@ -1131,6 +1139,10 @@ interface StepMeta {
1131
1139
  attemptLogPath?: string;
1132
1140
  attemptEvidencePath?: string;
1133
1141
  settlementReceiptPath?: string;
1142
+ // Claude CLI session transcripts for every attempt whose copy exists,
1143
+ // relative to the run dir. Absent when none were copied, so a failed
1144
+ // capture names no file and a pipeline.json from before traces still parses.
1145
+ tracePaths?: string[];
1134
1146
  // D1-08 PR2 (§8): the step's normalized usage, attached by recordSettlement
1135
1147
  // — the single existing usage join site (D1-10c's own comment: a second
1136
1148
  // pass over `state.steps` "would be a parallel mechanism able to disagree
@@ -1148,8 +1160,26 @@ interface StepMeta {
1148
1160
  // not become a second, shorter copy of them. Redacted — a transport error
1149
1161
  // can carry a token — and capped.
1150
1162
  failure?: string;
1151
- // D2 PR3: route attached at step construction
1163
+ // D2 PR3: route attached at step construction. On a step whose role listed
1164
+ // several models (S4), overwritten when it settles with the route of the
1165
+ // model that ran, like `model` and `effort_applied`.
1152
1166
  route?: ResolvedModelRoute;
1167
+ // S4: every model the step tried, in order, with its own attempts, cause
1168
+ // and usage (models can bill differently, so only these keep each one's
1169
+ // billing). Absent on a step with one model.
1170
+ model_attempts?: Array<{
1171
+ model: string;
1172
+ route: ResolvedModelRoute;
1173
+ status: "ok" | "failed" | "skipped";
1174
+ attempts: number;
1175
+ // S7: the effort this model was asked to run at, and what its backend
1176
+ // was sent (as on the step itself).
1177
+ effort: Effort;
1178
+ effort_applied: boolean;
1179
+ variant?: string;
1180
+ cause?: FailureCause;
1181
+ usage_v2?: NormalizedUsage;
1182
+ }>;
1153
1183
  }
1154
1184
 
1155
1185
  // pipeline.json's `scout` key (§3.9). Written on EVERY run, including one
@@ -1548,8 +1578,7 @@ async function execute(
1548
1578
  // it is settled long before a survivor exists to tier.
1549
1579
  state.refuterConfigured = reviewSpec.agents.some((a) => a.role === "refuter");
1550
1580
 
1551
- const effectiveRoutingConfig =
1552
- input.routingConfig ?? input.config?.effective?.routing;
1581
+ const effectiveModels = input.models ?? input.config?.effective?.models;
1553
1582
 
1554
1583
  const frontmatterByKey = new Map<string, string | undefined>();
1555
1584
  for (const agent of reviewSpec.agents) {
@@ -1566,7 +1595,6 @@ async function execute(
1566
1595
  let diversityCtx = prepareDiversityExecution({
1567
1596
  reviewSpec,
1568
1597
  cliModel: input.model,
1569
- routingConfig: effectiveRoutingConfig,
1570
1598
  frontmatterModel: (agentKey) => frontmatterByKey.get(agentKey),
1571
1599
  target: input.diversityTarget,
1572
1600
  runtimeTarget: reviewSpec.multiModelDiversity?.enabled
@@ -1617,7 +1645,7 @@ async function execute(
1617
1645
  routePlan = buildResolvedRoutePlan({
1618
1646
  agents: diversityCtx.routeAgents,
1619
1647
  cliModel: input.model,
1620
- routingConfig: effectiveRoutingConfig,
1648
+ models: effectiveModels,
1621
1649
  frontmatterModel: (agentKey) => frontmatterByKey.get(agentKey),
1622
1650
  ...(input.summarizer === undefined
1623
1651
  ? {}
@@ -1650,9 +1678,13 @@ async function execute(
1650
1678
  : { materiality: true as const }),
1651
1679
  });
1652
1680
  } catch (error) {
1653
- // Spec: legacy Claude-only runs without operator routing keep today's
1654
- // direct model passthrough; D2 route dimensions are optional then.
1655
- if (effectiveRoutingConfig !== undefined) throw error;
1681
+ // Spec: legacy Claude-only runs without `models` keep today's direct
1682
+ // model passthrough (a raw Claude id the CLI resolves itself); D2 route
1683
+ // dimensions are optional then. A model written in the new form never
1684
+ // falls back: its error says how to write it.
1685
+ if (effectiveModels !== undefined || error instanceof InvalidModelError) {
1686
+ throw error;
1687
+ }
1656
1688
  routePlan = undefined;
1657
1689
  }
1658
1690
  }
@@ -1830,14 +1862,17 @@ async function execute(
1830
1862
  tools: agent.tools,
1831
1863
  mcpConfigPath: input.mcpConfigPath,
1832
1864
  model: resolveModel(input, hunter.model, agent.model, hunter.file),
1833
- effort: resolveEffort(agent.effort, "hunter"),
1865
+ ...stepEffortFields(
1866
+ routePlan,
1867
+ name,
1868
+ agent.effort,
1869
+ defaultEffortForRole("hunter"),
1870
+ ),
1834
1871
  cwd: input.worktree,
1835
1872
  outPath: path.join(stepsDir, `${name}.draft.json`),
1836
1873
  timeoutMs: stepTimeoutMs,
1837
1874
  maxAttempts: DEFAULT_STEP_MAX_ATTEMPTS,
1838
- ...(routeForStepKey(routePlan, name) === undefined
1839
- ? {}
1840
- : { route: routeForStepKey(routePlan, name) }),
1875
+ ...stepRouteFields(routePlan, name),
1841
1876
  parse: (finalText) => {
1842
1877
  const extracted = extractJsonObject(finalText);
1843
1878
  if (extracted === undefined) {
@@ -1896,7 +1931,13 @@ async function execute(
1896
1931
  agent.model,
1897
1932
  input.summarizer.promptPath,
1898
1933
  );
1899
- summarizerMeta.effort = resolveEffort(agent.effort, "summarizer");
1934
+ const summarizerEffort = stepEffortFields(
1935
+ routePlan,
1936
+ name,
1937
+ agent.effort,
1938
+ defaultEffortForRole("summarizer"),
1939
+ );
1940
+ summarizerMeta.effort = summarizerEffort.effort;
1900
1941
  summarizerMeta.tools = agent.tools;
1901
1942
  summarizerSpec = {
1902
1943
  name,
@@ -1905,12 +1946,10 @@ async function execute(
1905
1946
  tools: agent.tools,
1906
1947
  mcpConfigPath: input.mcpConfigPath,
1907
1948
  model: summarizerMeta.model,
1908
- effort: summarizerMeta.effort,
1949
+ ...summarizerEffort,
1909
1950
  cwd: input.worktree,
1910
1951
  outPath,
1911
- ...(routeForStepKey(routePlan, name) === undefined
1912
- ? {}
1913
- : { route: routeForStepKey(routePlan, name) }),
1952
+ ...stepRouteFields(routePlan, name),
1914
1953
  // The summary is a cosmetic barrier ahead of dedupe/refutation. It
1915
1954
  // must not inherit the 30-minute hunter watchdog or its retry budget.
1916
1955
  timeoutMs: 5 * 60 * 1000,
@@ -2473,7 +2512,12 @@ async function runRefuter(
2473
2512
  agent.model,
2474
2513
  options.agent.file,
2475
2514
  );
2476
- const effort = resolveEffort(agent.effort, "refuter");
2515
+ const effortFields = stepEffortFields(
2516
+ state.routePlan,
2517
+ agentStepKey(options.agent),
2518
+ agent.effort,
2519
+ defaultEffortForRole("refuter"),
2520
+ );
2477
2521
  // A finding's content is composed LONG after the run's nonce was committed
2478
2522
  // — the hunters wrote its `claim` and `proof_refs` from the patch — so it is
2479
2523
  // the one block `selectBoundaryNonce` could not be drawn against. Guarded
@@ -2516,7 +2560,7 @@ async function runRefuter(
2516
2560
  tools: agent.tools,
2517
2561
  mcpConfigPath: input.mcpConfigPath,
2518
2562
  model,
2519
- effort,
2563
+ ...effortFields,
2520
2564
  cwd: input.worktree,
2521
2565
  outPath: path.join(
2522
2566
  options.stepsDir,
@@ -2524,15 +2568,7 @@ async function runRefuter(
2524
2568
  ),
2525
2569
  timeoutMs: options.stepTimeoutMs,
2526
2570
  maxAttempts: DEFAULT_STEP_MAX_ATTEMPTS,
2527
- ...(routeForStepKey(state.routePlan, agentStepKey(options.agent)) ===
2528
- undefined
2529
- ? {}
2530
- : {
2531
- route: routeForStepKey(
2532
- state.routePlan,
2533
- agentStepKey(options.agent),
2534
- ),
2535
- }),
2571
+ ...stepRouteFields(state.routePlan, agentStepKey(options.agent)),
2536
2572
  parse: (finalText) => {
2537
2573
  const extracted = extractJsonObject(finalText);
2538
2574
  if (extracted === undefined) {
@@ -2707,7 +2743,12 @@ async function runVerify(
2707
2743
  // The verifier re-reads the REFUTER's prompt file, so a frontmatter `effort:`
2708
2744
  // there applies to it as well; `verifier` is only the fallback for a prompt
2709
2745
  // that omits the key.
2710
- const effort = resolveEffort(agent.effort, "verifier");
2746
+ const effortFields = stepEffortFields(
2747
+ state.routePlan,
2748
+ agentStepKey(options.agent),
2749
+ agent.effort,
2750
+ defaultEffortForRole("verifier"),
2751
+ );
2711
2752
  const forged: VerifySubject[] = [];
2712
2753
  const specs: Array<{
2713
2754
  subject: VerifySubject;
@@ -2729,7 +2770,7 @@ async function runVerify(
2729
2770
  tools: agent.tools,
2730
2771
  mcpConfigPath: input.mcpConfigPath,
2731
2772
  model,
2732
- effort,
2773
+ ...effortFields,
2733
2774
  cwd: input.worktree,
2734
2775
  outPath: path.join(dir, "result.json"),
2735
2776
  timeoutMs: options.stepTimeoutMs,
@@ -2738,15 +2779,7 @@ async function runVerify(
2738
2779
  // admitted route, as the refuter and adjudicator legs do. Left unset, a
2739
2780
  // routed run had no binding for these steps and every one failed
2740
2781
  // "No admitted binding for step route" before reaching a provider.
2741
- ...(routeForStepKey(state.routePlan, agentStepKey(options.agent)) ===
2742
- undefined
2743
- ? {}
2744
- : {
2745
- route: routeForStepKey(
2746
- state.routePlan,
2747
- agentStepKey(options.agent),
2748
- ),
2749
- }),
2782
+ ...stepRouteFields(state.routePlan, agentStepKey(options.agent)),
2750
2783
  parse: (finalText) => {
2751
2784
  const extracted = extractJsonObject(finalText);
2752
2785
  if (extracted === undefined) {
@@ -2906,7 +2939,12 @@ async function runAdjudicate(
2906
2939
  agent.model,
2907
2940
  options.agent.file,
2908
2941
  );
2909
- const effort = resolveEffort(agent.effort, "refuter");
2942
+ const effortFields = stepEffortFields(
2943
+ state.routePlan,
2944
+ agentStepKey(options.agent),
2945
+ agent.effort,
2946
+ defaultEffortForRole("refuter"),
2947
+ );
2910
2948
  const specs: Array<{
2911
2949
  index: number;
2912
2950
  subject: AdjudicationSubject;
@@ -2927,20 +2965,12 @@ async function runAdjudicate(
2927
2965
  tools: agent.tools,
2928
2966
  mcpConfigPath: input.mcpConfigPath,
2929
2967
  model,
2930
- effort,
2968
+ ...effortFields,
2931
2969
  cwd: input.worktree,
2932
2970
  outPath: path.join(dir, "result.json"),
2933
2971
  timeoutMs: options.stepTimeoutMs,
2934
2972
  maxAttempts: DEFAULT_STEP_MAX_ATTEMPTS,
2935
- ...(routeForStepKey(state.routePlan, agentStepKey(options.agent)) ===
2936
- undefined
2937
- ? {}
2938
- : {
2939
- route: routeForStepKey(
2940
- state.routePlan,
2941
- agentStepKey(options.agent),
2942
- ),
2943
- }),
2973
+ ...stepRouteFields(state.routePlan, agentStepKey(options.agent)),
2944
2974
  parse: parseAdjudicationResult,
2945
2975
  onRetry: (info) => emit(deps, { kind: "step-retry", ...info }),
2946
2976
  };
@@ -3143,7 +3173,13 @@ async function runScout(
3143
3173
  input.scout.promptPath,
3144
3174
  );
3145
3175
  record.model = meta.model;
3146
- meta.effort = resolveEffort(agent.effort, "scout");
3176
+ const scoutEffort = stepEffortFields(
3177
+ state.routePlan,
3178
+ name,
3179
+ agent.effort,
3180
+ defaultEffortForRole("scout"),
3181
+ );
3182
+ meta.effort = scoutEffort.effort;
3147
3183
  // FULL sha256, not the 12 chars the probe prints: the probe's artifact
3148
3184
  // stores the full digest too, so a pipeline.json and a scout-probe.json
3149
3185
  // naming the same prompt say the same string.
@@ -3157,14 +3193,12 @@ async function runScout(
3157
3193
  tools: meta.tools,
3158
3194
  mcpConfigPath: input.mcpConfigPath,
3159
3195
  model: meta.model,
3160
- effort: meta.effort,
3196
+ ...scoutEffort,
3161
3197
  cwd: input.worktree,
3162
3198
  outPath,
3163
3199
  timeoutMs: SCOUT_TIMEOUT_MS,
3164
3200
  maxAttempts: 1,
3165
- ...(routeForStepKey(state.routePlan, name) === undefined
3166
- ? {}
3167
- : { route: routeForStepKey(state.routePlan, name) }),
3201
+ ...stepRouteFields(state.routePlan, name),
3168
3202
  parse: (finalText) => {
3169
3203
  const extracted = extractJsonObject(finalText);
3170
3204
  if (extracted === undefined) {
@@ -3184,7 +3218,7 @@ async function runScout(
3184
3218
 
3185
3219
  if (spec.route !== undefined) {
3186
3220
  meta.route = spec.route;
3187
- meta.effort_applied = spec.route.backend === "claude-code";
3221
+ Object.assign(meta, routeEffortFields(spec.route));
3188
3222
  const routedModel = effectiveExecutionModel(spec);
3189
3223
  meta.model = routedModel;
3190
3224
  record.model = routedModel;
@@ -3205,6 +3239,8 @@ async function runScout(
3205
3239
  // BEFORE the verdict branches below, so every road that ends in `abandon`
3206
3240
  // still carries the attempt count and pointers of the session that ran.
3207
3241
  recordSettlement(meta, result, input.runDir);
3242
+ // The model that ran, when the scout fell back to another (S4).
3243
+ record.model = meta.model;
3208
3244
  state.usageTotal = sumUsage(state.usageTotal, result.usage);
3209
3245
  accumulateUsageV2(state, result);
3210
3246
  if (result.status !== "ok") return abandon();
@@ -3413,7 +3449,13 @@ async function runConsolidation(
3413
3449
  input.consolidate.promptPath,
3414
3450
  );
3415
3451
  record.model = meta.model;
3416
- meta.effort = agent.effort ?? DEFAULT_CONSOLIDATE_EFFORT;
3452
+ const consolidateEffort = stepEffortFields(
3453
+ state.routePlan,
3454
+ name,
3455
+ agent.effort,
3456
+ DEFAULT_CONSOLIDATE_EFFORT,
3457
+ );
3458
+ meta.effort = consolidateEffort.effort;
3417
3459
  record.prompt_sha256 = new Bun.CryptoHasher("sha256")
3418
3460
  .update(raw)
3419
3461
  .digest("hex");
@@ -3424,14 +3466,12 @@ async function runConsolidation(
3424
3466
  tools: meta.tools,
3425
3467
  mcpConfigPath: input.mcpConfigPath,
3426
3468
  model: meta.model,
3427
- effort: meta.effort,
3469
+ ...consolidateEffort,
3428
3470
  cwd: input.worktree,
3429
3471
  outPath,
3430
3472
  timeoutMs: CONSOLIDATE_TIMEOUT_MS,
3431
3473
  maxAttempts: CONSOLIDATE_MAX_ATTEMPTS,
3432
- ...(routeForStepKey(state.routePlan, name) === undefined
3433
- ? {}
3434
- : { route: routeForStepKey(state.routePlan, name) }),
3474
+ ...stepRouteFields(state.routePlan, name),
3435
3475
  parse: (finalText) => {
3436
3476
  const extracted = extractJsonObject(finalText);
3437
3477
  if (extracted === undefined) {
@@ -3451,7 +3491,7 @@ async function runConsolidation(
3451
3491
 
3452
3492
  if (spec.route !== undefined) {
3453
3493
  meta.route = spec.route;
3454
- meta.effort_applied = spec.route.backend === "claude-code";
3494
+ Object.assign(meta, routeEffortFields(spec.route));
3455
3495
  const routedModel = effectiveExecutionModel(spec);
3456
3496
  meta.model = routedModel;
3457
3497
  record.model = routedModel;
@@ -3469,6 +3509,8 @@ async function runConsolidation(
3469
3509
  // tokens.
3470
3510
  state.perAgent.consolidate = perAgentEntry(result);
3471
3511
  recordSettlement(meta, result, input.runDir);
3512
+ // The model that ran, when consolidation fell back to another (S4).
3513
+ record.model = meta.model;
3472
3514
  state.usageTotal = sumUsage(state.usageTotal, result.usage);
3473
3515
  accumulateUsageV2(state, result);
3474
3516
  if (result.status !== "ok") {
@@ -3614,12 +3656,14 @@ async function runMaterialityJudge(
3614
3656
  record.reason =
3615
3657
  route !== undefined ||
3616
3658
  resolveMaterialityJudgeRoute(
3617
- input.routingConfig ?? input.config?.effective?.routing,
3659
+ input.models ?? input.config?.effective?.models,
3618
3660
  ) === undefined
3619
3661
  ? "judge route is not the measured claude-code route"
3620
3662
  : "route plan carries no judge step";
3621
3663
  return;
3622
3664
  }
3665
+ // `models.judge` may pick opus: the record names the model that runs.
3666
+ record.model = route.modelSnapshot;
3623
3667
  }
3624
3668
  if (judge.length === 0) return;
3625
3669
 
@@ -3680,7 +3724,16 @@ async function runMaterialityJudge(
3680
3724
  input.prTitle !== undefined && input.prTitle.trim() !== ""
3681
3725
  ? input.prTitle
3682
3726
  : MATERIALITY_TITLE_FALLBACK;
3683
- const effort = defaultEffortForRole("other");
3727
+ // models.judge takes no effort (D3), so this is the role default; it goes
3728
+ // through stepEffortFields anyway so no step builds its effort another way.
3729
+ // `.effort` only: the judge's list is chosen whole (judgeModelChoice) and
3730
+ // its step carries no fallbacks to pair efforts with.
3731
+ const { effort } = stepEffortFields(
3732
+ state.routePlan,
3733
+ MATERIALITY_STEP_KEY,
3734
+ undefined,
3735
+ defaultEffortForRole("other"),
3736
+ );
3684
3737
  const specs: Array<{ id: string; spec: StepSpec; meta: StepMeta }> = [];
3685
3738
  // The owner's file as posting policy, or undefined when it holds nothing of
3686
3739
  // the owner's own: template text never reaches the judge (ownerPolicyText).
@@ -3725,9 +3778,10 @@ async function runMaterialityJudge(
3725
3778
  tools: [],
3726
3779
  mcpConfigPath,
3727
3780
  // PINNED, never `input.model` or the frontmatter: the measured judge is
3728
- // sonnet, and a judge on another model is a different, unmeasured judge
3729
- // deciding which blockers post.
3730
- model: MATERIALITY_JUDGE_MODEL,
3781
+ // sonnet or opus (`models.judge`, through the route), and a judge on
3782
+ // another model is a different, unmeasured judge deciding which
3783
+ // blockers post. A run with no route plan sends the measured default.
3784
+ model: route?.modelSnapshot ?? MATERIALITY_JUDGE_MODEL,
3731
3785
  effort,
3732
3786
  cwd: input.worktree,
3733
3787
  outPath: path.join(dir, "result.json"),
@@ -4065,8 +4119,12 @@ function hunterFailureOf(
4065
4119
  result: StepResult | undefined,
4066
4120
  ): HunterFailure {
4067
4121
  const cause = result?.failureCause;
4068
- const provider = spec.route?.provider.trim();
4069
- const model = spec.route?.modelSnapshot.trim();
4122
+ // The model that ran, when the role listed several (S4): the provider and
4123
+ // model to name are the ones that failed last, not the first one listed.
4124
+ const route =
4125
+ (result === undefined ? undefined : ranRoute(result)) ?? spec.route;
4126
+ const provider = route?.provider.trim();
4127
+ const model = route?.modelSnapshot.trim();
4070
4128
  const detail = failureDetailOf(result?.failureDetail);
4071
4129
  return {
4072
4130
  name: spec.name,
@@ -4297,14 +4355,56 @@ function resolveModel(
4297
4355
  return model;
4298
4356
  }
4299
4357
 
4300
- // Precedence: the prompt's frontmatter `effort:`, else the engine's per-role
4301
- // default. There is no third seat on purpose: nothing may fall through to the
4302
- // CLI's implicit default, which is what #299 removed.
4303
- function resolveEffort(
4358
+ // A step's effort AND each fallback's (S7), from the plan, as StepSpec fields.
4359
+ // One spread at every site that builds a step, beside stepRouteFields, so no
4360
+ // site can skip it or hand a fallback the first model's effort.
4361
+ //
4362
+ // Precedence, per model: its `models` entry's effort > the prompt's
4363
+ // frontmatter `effort:` > the role's default. There is no fourth seat on
4364
+ // purpose: nothing may fall through to the CLI's implicit default, which is
4365
+ // what #299 removed. `--model`, a spec model and a prompt alias carry no entry
4366
+ // effort (D4), so they keep frontmatter > role default.
4367
+ //
4368
+ // Only a Claude entry's effort lands in `effort`, the Claude scale the CLI's
4369
+ // `--effort` takes. An OpenCode entry's effort is a provider variant, already
4370
+ // on its route (`modelVariant`), and its step keeps the frontmatter or role
4371
+ // level as intent only, as before.
4372
+ //
4373
+ // `roleDefault` is a level, not a StepRole, because the consolidation pass has
4374
+ // its own default (DEFAULT_CONSOLIDATE_EFFORT) outside the role table.
4375
+ function stepEffortFields(
4376
+ routePlan: ResolvedRoutePlan | undefined,
4377
+ stepKey: string,
4304
4378
  frontmatterEffort: Effort | undefined,
4305
- role: StepRole,
4306
- ): Effort {
4307
- return frontmatterEffort ?? defaultEffortForRole(role);
4379
+ roleDefault: Effort,
4380
+ ): Pick<StepSpec, "effort" | "fallbackEfforts"> {
4381
+ const base = frontmatterEffort ?? roleDefault;
4382
+ const step = routePlan?.steps.find((s) => s.stepKey === stepKey);
4383
+ if (step === undefined) return { effort: base };
4384
+ return {
4385
+ effort: entryEffort(step, base),
4386
+ ...(step.fallbacks === undefined || step.fallbacks.length === 0
4387
+ ? {}
4388
+ : {
4389
+ fallbackEfforts: step.fallbacks.map((fallback) =>
4390
+ entryEffort(fallback, base),
4391
+ ),
4392
+ }),
4393
+ };
4394
+ }
4395
+
4396
+ function entryEffort(step: ResolvedStepRoute, base: Effort): Effort {
4397
+ if (step.route.backend !== "claude-code" || step.effort === undefined) {
4398
+ return base;
4399
+ }
4400
+ // parseModelList refused any other level, so this is an invariant, not a
4401
+ // reading: a level that reached here unvalidated must not run as another.
4402
+ if (!isEffort(step.effort)) {
4403
+ throw new Error(
4404
+ `${step.stepKey}: effort ${JSON.stringify(step.effort)} is not a Claude effort level`,
4405
+ );
4406
+ }
4407
+ return step.effort;
4308
4408
  }
4309
4409
 
4310
4410
  function perAgentEntry(result: StepResult): PerAgentUsage {
@@ -4377,17 +4477,42 @@ function routeForStepKey(
4377
4477
  return routePlan?.steps.find((step) => step.stepKey === stepKey)?.route;
4378
4478
  }
4379
4479
 
4480
+ // A step's route AND its fallbacks (S4), from the plan, as StepSpec fields.
4481
+ // One spread at every site that routes a step, so no site can hand a runner
4482
+ // the first model without the rest of the list.
4483
+ function stepRouteFields(
4484
+ routePlan: ResolvedRoutePlan | undefined,
4485
+ stepKey: string,
4486
+ ): Pick<StepSpec, "route" | "fallbackRoutes"> {
4487
+ const step = routePlan?.steps.find((s) => s.stepKey === stepKey);
4488
+ if (step === undefined) return {};
4489
+ return {
4490
+ route: step.route,
4491
+ ...(step.fallbacks === undefined || step.fallbacks.length === 0
4492
+ ? {}
4493
+ : { fallbackRoutes: step.fallbacks.map((fallback) => fallback.route) }),
4494
+ };
4495
+ }
4496
+
4497
+ // What a route's backend is sent: the Claude CLI's `--model`, or the
4498
+ // provider's model id.
4499
+ function routeExecutionModel(
4500
+ route: ResolvedModelRoute,
4501
+ fallback: string,
4502
+ ): string {
4503
+ if (route.backend === "claude-code") {
4504
+ return claudeCliModel(route);
4505
+ }
4506
+ return route.modelSnapshot || fallback;
4507
+ }
4508
+
4509
+ // What the step's backend is sent, recorded as the step's model in
4510
+ // pipeline.json: the route's model when there is a route, else the step's own.
4380
4511
  function effectiveExecutionModel(spec: StepSpec): string {
4381
4512
  if (spec.route === undefined) {
4382
4513
  return spec.model;
4383
4514
  }
4384
- if (spec.route.backend === "claude-code") {
4385
- return spawnModelForClaudeCli(spec.route, spec.model);
4386
- }
4387
- return (
4388
- (spec.route as { model?: string } | undefined)?.model ??
4389
- (spec.route.modelSnapshot || spec.model)
4390
- );
4515
+ return routeExecutionModel(spec.route, spec.model);
4391
4516
  }
4392
4517
 
4393
4518
  function stepMeta(spec: StepSpec): StepMeta {
@@ -4395,9 +4520,7 @@ function stepMeta(spec: StepSpec): StepMeta {
4395
4520
  name: spec.name,
4396
4521
  model: effectiveExecutionModel(spec),
4397
4522
  effort: spec.effort,
4398
- ...(spec.route === undefined
4399
- ? {}
4400
- : { effort_applied: spec.route.backend === "claude-code" }),
4523
+ ...(spec.route === undefined ? {} : routeEffortFields(spec.route)),
4401
4524
  tools: spec.tools,
4402
4525
  systemPromptPath: spec.systemPromptPath,
4403
4526
  outPath: spec.outPath,
@@ -4409,6 +4532,22 @@ function stepMeta(spec: StepSpec): StepMeta {
4409
4532
  };
4410
4533
  }
4411
4534
 
4535
+ // What pipeline.json says a route's backend was sent for effort (S7): whether
4536
+ // it applied one (effortApplied) and, on OpenCode, the variant it was sent.
4537
+ // `variant` is absent when none was sent, so a run with no entry effort
4538
+ // records what it always recorded.
4539
+ function routeEffortFields(route: ResolvedModelRoute): {
4540
+ effort_applied: boolean;
4541
+ variant?: string;
4542
+ } {
4543
+ return {
4544
+ effort_applied: effortApplied(route),
4545
+ ...(route.modelVariant === undefined
4546
+ ? {}
4547
+ : { variant: route.modelVariant }),
4548
+ };
4549
+ }
4550
+
4412
4551
  // D1-10c. Attaches one settled step's provenance from the SAME `StepResult`
4413
4552
  // the usage join already reads, at the SAME join site — a second pass over the
4414
4553
  // steps would be a parallel mechanism able to disagree with `per_agent`, and
@@ -4439,6 +4578,35 @@ function recordSettlement(
4439
4578
  if (result.reservations !== undefined && result.reservations.length > 0) {
4440
4579
  meta.reservations = result.reservations;
4441
4580
  }
4581
+ // S4: a step whose role listed several models records the one that ran,
4582
+ // over the first model stamped before the spawn, and every model it tried.
4583
+ // The backend and the effort can change with the model (S7: each runs at
4584
+ // its own), so `effort`, `effort_applied` and `variant` follow the model
4585
+ // that ran. A step with one model carries no `modelAttempts` and records
4586
+ // what it always recorded.
4587
+ if (result.modelAttempts !== undefined) {
4588
+ const firstEffort = meta.effort;
4589
+ const ran = result.modelAttempts.findLast(
4590
+ (entry) => entry.status !== "skipped",
4591
+ );
4592
+ if (ran !== undefined) {
4593
+ meta.route = ran.route;
4594
+ meta.model = routeExecutionModel(ran.route, meta.model);
4595
+ meta.effort = ran.effort ?? firstEffort;
4596
+ delete meta.variant;
4597
+ Object.assign(meta, routeEffortFields(ran.route));
4598
+ }
4599
+ meta.model_attempts = result.modelAttempts.map((entry) => ({
4600
+ model: routeExecutionModel(entry.route, meta.model),
4601
+ route: entry.route,
4602
+ status: entry.status,
4603
+ attempts: entry.attempts,
4604
+ effort: entry.effort ?? firstEffort,
4605
+ ...routeEffortFields(entry.route),
4606
+ ...(entry.cause === undefined ? {} : { cause: entry.cause }),
4607
+ ...(entry.usageV2 === undefined ? {} : { usage_v2: entry.usageV2 }),
4608
+ }));
4609
+ }
4442
4610
  meta.status = result.status;
4443
4611
  meta.attempts = result.attempts;
4444
4612
  // Cancellation before the first admitted attempt, and every preflight
@@ -4470,6 +4638,14 @@ function recordSettlement(
4470
4638
  runDir,
4471
4639
  settlementReceiptPath(meta.outPath, meta.name, result.attempts),
4472
4640
  );
4641
+ const tracePaths: string[] = [];
4642
+ for (let attempt = 1; attempt <= result.attempts; attempt++) {
4643
+ const absolute = claudeSessionTracePath(meta.outPath, meta.name, attempt);
4644
+ if (existsSync(absolute)) {
4645
+ tracePaths.push(path.relative(runDir, absolute));
4646
+ }
4647
+ }
4648
+ if (tracePaths.length > 0) meta.tracePaths = tracePaths;
4473
4649
  }
4474
4650
 
4475
4651
  // A step that reached a terminal verdict WITHOUT a StepResult: the spec never