crysk 0.0.0-stage → 0.3.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 (229) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +610 -2
  3. package/bin/pr-hero.js +166 -0
  4. package/config/models/anthropic.json +5 -0
  5. package/dist/SKILL-7e3725zn.md +496 -0
  6. package/dist/SKILL-7q35wcaz.md +66 -0
  7. package/dist/SKILL-9at22381.md +74 -0
  8. package/dist/SKILL-ex2hxxh3.md +134 -0
  9. package/dist/adjudicator-dtg2axnh.md +86 -0
  10. package/dist/admission-config.example-a9vqmmad.json +9 -0
  11. package/dist/ci-admission-camfbx2b.md +122 -0
  12. package/dist/cli.js +42292 -0
  13. package/dist/consolidate-ac0mnfyj.md +24 -0
  14. package/dist/deep-review-lifecycle-m698ybjp.md +362 -0
  15. package/dist/deep-review-logic-a6b1gczf.md +156 -0
  16. package/dist/deep-review-parity-0ec904db.md +120 -0
  17. package/dist/deep-review-reliability-qyakbjb9.md +125 -0
  18. package/dist/deep-review-resilience-3tz8y26e.md +118 -0
  19. package/dist/index.js +20190 -0
  20. package/dist/opencode-ci-7b0be64p.md +141 -0
  21. package/dist/review-refuter-j4e9gezy.md +71 -0
  22. package/dist/scout-yvp153q7.md +140 -0
  23. package/dist/summarizer-zca44nxa.md +18 -0
  24. package/dist/workflow-w1g9szna.yml +151 -0
  25. package/package.json +82 -4
  26. package/prompts/consolidate.md +24 -0
  27. package/prompts/default/PROVENANCE.md +18 -0
  28. package/prompts/default/deep-review-lifecycle.md +362 -0
  29. package/prompts/default/deep-review-logic.md +156 -0
  30. package/prompts/default/deep-review-parity.md +120 -0
  31. package/prompts/default/deep-review-reliability.md +125 -0
  32. package/prompts/default/deep-review-resilience.md +118 -0
  33. package/prompts/default/review-refuter.md +71 -0
  34. package/prompts/scout.md +140 -0
  35. package/prompts/summarizer.md +18 -0
  36. package/skills/crysk/SKILL.md +74 -0
  37. package/skills/crysk-ci-setup/SKILL.md +134 -0
  38. package/skills/crysk-ci-setup/assets/admission-config.example.json +9 -0
  39. package/skills/crysk-ci-setup/assets/workflow.yml +151 -0
  40. package/skills/crysk-ci-setup/references/ci-admission.md +122 -0
  41. package/skills/crysk-ci-setup/references/opencode-ci.md +141 -0
  42. package/skills/crysk-loop/SKILL.md +496 -0
  43. package/skills/crysk-loop/adjudicator.md +86 -0
  44. package/skills/crysk-pr/SKILL.md +66 -0
  45. package/src/agent-env.ts +1084 -0
  46. package/src/asset-manifest.ts +83 -0
  47. package/src/assets.d.ts +6 -0
  48. package/src/assets.ts +183 -0
  49. package/src/brand-paths.ts +155 -0
  50. package/src/brand.ts +255 -0
  51. package/src/ci/admission-ledger.ts +350 -0
  52. package/src/ci/classify-error.ts +73 -0
  53. package/src/ci/cli-record.ts +271 -0
  54. package/src/ci/force-comment.ts +39 -0
  55. package/src/ci/gates.ts +923 -0
  56. package/src/ci/outcome.ts +2181 -0
  57. package/src/ci/override.ts +187 -0
  58. package/src/ci/publish.ts +1639 -0
  59. package/src/ci/reporter.ts +626 -0
  60. package/src/ci/review-admission.ts +901 -0
  61. package/src/ci/review-levels.ts +310 -0
  62. package/src/ci/review-policy.ts +18 -0
  63. package/src/ci/review-risk.ts +184 -0
  64. package/src/ci/setup.ts +844 -0
  65. package/src/ci/trigger.ts +1353 -0
  66. package/src/cli.ts +348 -0
  67. package/src/commands/activity.ts +67 -0
  68. package/src/commands/ci-setup-questions.ts +397 -0
  69. package/src/commands/ci-setup.ts +381 -0
  70. package/src/commands/config.ts +99 -0
  71. package/src/commands/doctor.ts +108 -0
  72. package/src/commands/init.ts +139 -0
  73. package/src/commands/mcp.ts +10 -0
  74. package/src/commands/menu.ts +129 -0
  75. package/src/commands/post.ts +302 -0
  76. package/src/commands/skills.ts +83 -0
  77. package/src/commands/status.ts +173 -0
  78. package/src/commands/triage.ts +342 -0
  79. package/src/commands/uninstall.ts +37 -0
  80. package/src/commands/upgrade.ts +214 -0
  81. package/src/commands/usage.ts +98 -0
  82. package/src/compare/compare.ts +28 -0
  83. package/src/compare/floor-test.ts +471 -0
  84. package/src/compare/martian-adapter.ts +80 -0
  85. package/src/config/config.ts +267 -0
  86. package/src/corpus/corpus.ts +1094 -0
  87. package/src/corpus/preflight.ts +1789 -0
  88. package/src/diversity/accounting.ts +90 -0
  89. package/src/diversity/adjudication.ts +145 -0
  90. package/src/diversity/admission.ts +60 -0
  91. package/src/diversity/benchmark.ts +195 -0
  92. package/src/diversity/clustering.ts +285 -0
  93. package/src/diversity/errors.ts +7 -0
  94. package/src/diversity/identity.ts +285 -0
  95. package/src/diversity/index.ts +11 -0
  96. package/src/diversity/pipeline-integration.ts +448 -0
  97. package/src/diversity/projection.ts +57 -0
  98. package/src/diversity/self-contained.ts +68 -0
  99. package/src/diversity/target-validation.ts +179 -0
  100. package/src/doctor-migration.ts +209 -0
  101. package/src/doctor.ts +723 -0
  102. package/src/errors.ts +83 -0
  103. package/src/execution/admission.ts +75 -0
  104. package/src/execution/atomic-write.ts +35 -0
  105. package/src/execution/attempt-evidence.ts +415 -0
  106. package/src/execution/bucket-id.ts +136 -0
  107. package/src/execution/concurrency-limiter.ts +175 -0
  108. package/src/execution/contracts.ts +443 -0
  109. package/src/execution/failure-classification.ts +42 -0
  110. package/src/execution/failure-policy.ts +240 -0
  111. package/src/execution/harness.ts +2548 -0
  112. package/src/execution/settlement.ts +348 -0
  113. package/src/execution/spawned-process.ts +66 -0
  114. package/src/execution/spend-limiter.ts +424 -0
  115. package/src/execution/step-artifacts.ts +55 -0
  116. package/src/execution/usage-normalized.ts +469 -0
  117. package/src/git/git.ts +396 -0
  118. package/src/git/identity.ts +64 -0
  119. package/src/git/refs.ts +140 -0
  120. package/src/home-preflight.ts +443 -0
  121. package/src/home.ts +243 -0
  122. package/src/ignore-file.ts +336 -0
  123. package/src/ignore-read.ts +118 -0
  124. package/src/index.ts +34 -0
  125. package/src/legacy-launchd.ts +29 -0
  126. package/src/mcp/mcp.ts +150 -0
  127. package/src/mcp/preflight.ts +407 -0
  128. package/src/menu-context.ts +192 -0
  129. package/src/model/catalog.ts +251 -0
  130. package/src/model/exec-snapshots.ts +390 -0
  131. package/src/model/free-discovery.ts +302 -0
  132. package/src/model/provider-capabilities.ts +814 -0
  133. package/src/model/routing.ts +600 -0
  134. package/src/pr/admission.ts +847 -0
  135. package/src/pr/ci-admission-gate.ts +665 -0
  136. package/src/pr/ci-publish.ts +76 -0
  137. package/src/pr/discovery.ts +432 -0
  138. package/src/pr/inline.ts +507 -0
  139. package/src/pr/plan.ts +366 -0
  140. package/src/pr/posting.ts +115 -0
  141. package/src/pr/pr-status.ts +787 -0
  142. package/src/pr/pr.ts +3642 -0
  143. package/src/pr/preflight.ts +1031 -0
  144. package/src/pr/publish-outcome.ts +361 -0
  145. package/src/pr/range.ts +119 -0
  146. package/src/pr/reverts-preflight.ts +606 -0
  147. package/src/pr/reverts.ts +377 -0
  148. package/src/pr/review-pr.ts +927 -0
  149. package/src/pr/status.ts +154 -0
  150. package/src/pr/target.ts +388 -0
  151. package/src/pr/teardown.ts +437 -0
  152. package/src/pr/worktree-setup.ts +60 -0
  153. package/src/production-runtime.ts +1877 -0
  154. package/src/progress.ts +487 -0
  155. package/src/rereview/adjudicate.ts +89 -0
  156. package/src/rereview/classify.ts +362 -0
  157. package/src/rereview/identity.ts +211 -0
  158. package/src/rereview/plan.ts +308 -0
  159. package/src/rereview/prepare.ts +1025 -0
  160. package/src/rereview/state.ts +767 -0
  161. package/src/rereview/verify.ts +241 -0
  162. package/src/review/boundary.ts +105 -0
  163. package/src/review/consolidate.ts +246 -0
  164. package/src/review/dedupe.ts +368 -0
  165. package/src/review/drafts.ts +448 -0
  166. package/src/review/findings-conformance.ts +120 -0
  167. package/src/review/findings.ts +714 -0
  168. package/src/review/pipeline.ts +3977 -0
  169. package/src/review/preflight.ts +3575 -0
  170. package/src/review/prompt-set.ts +177 -0
  171. package/src/review/proof-refs.ts +187 -0
  172. package/src/review/report.ts +1821 -0
  173. package/src/review/review.ts +490 -0
  174. package/src/review/root-cause.ts +120 -0
  175. package/src/review/route-preflight.ts +289 -0
  176. package/src/review/run.ts +601 -0
  177. package/src/review/scout.ts +323 -0
  178. package/src/review/size-gate.ts +595 -0
  179. package/src/review/spec.ts +235 -0
  180. package/src/review/step-runner.ts +233 -0
  181. package/src/runner-authority.ts +596 -0
  182. package/src/security/binding-policy.ts +115 -0
  183. package/src/security/credential-broker.ts +773 -0
  184. package/src/security/evidence-redaction.ts +62 -0
  185. package/src/security/execution-authority.ts +27 -0
  186. package/src/security/redact.ts +71 -0
  187. package/src/security/workspace-read-broker.ts +466 -0
  188. package/src/server/client.ts +190 -0
  189. package/src/server/preflight.ts +217 -0
  190. package/src/server/server.ts +327 -0
  191. package/src/signal-handler.ts +50 -0
  192. package/src/store/activity.ts +413 -0
  193. package/src/store/backfill-preflight.ts +49 -0
  194. package/src/store/backfill.ts +141 -0
  195. package/src/store/gc-preflight.ts +206 -0
  196. package/src/store/gc.ts +424 -0
  197. package/src/store/metrics-preflight.ts +229 -0
  198. package/src/store/metrics.ts +236 -0
  199. package/src/store/preflight.ts +748 -0
  200. package/src/store/store.ts +693 -0
  201. package/src/system-tools.ts +355 -0
  202. package/src/transport-registry.ts +1124 -0
  203. package/src/transports/claude-code-cli.ts +1348 -0
  204. package/src/transports/opencode-admission.ts +515 -0
  205. package/src/transports/opencode-client.ts +3328 -0
  206. package/src/transports/opencode-evidence.ts +557 -0
  207. package/src/transports/opencode-mcp.ts +248 -0
  208. package/src/transports/opencode-sdk.ts +2294 -0
  209. package/src/transports/opencode-server.ts +535 -0
  210. package/src/triage/adjudication.ts +113 -0
  211. package/src/triage/reply.ts +125 -0
  212. package/src/triage/triage.ts +255 -0
  213. package/src/ui/activity.ts +173 -0
  214. package/src/ui/config-edit.ts +816 -0
  215. package/src/ui/config.ts +462 -0
  216. package/src/ui/menu.ts +1325 -0
  217. package/src/ui/plan.ts +1039 -0
  218. package/src/ui/primitives.ts +300 -0
  219. package/src/ui/progress.ts +298 -0
  220. package/src/ui/result.ts +552 -0
  221. package/src/ui/review-menu.ts +312 -0
  222. package/src/ui/select.ts +528 -0
  223. package/src/ui/tree.ts +178 -0
  224. package/src/uninstaller.ts +479 -0
  225. package/src/updater.ts +836 -0
  226. package/src/usage.ts +77 -0
  227. package/src/watch/preflight.ts +1389 -0
  228. package/src/watch/watch.ts +1235 -0
  229. package/src/wizard.ts +877 -0
@@ -0,0 +1,443 @@
1
+ import type { Effort } from "#model/catalog";
2
+ import type {
3
+ CredentialKind,
4
+ ExecutableAllowlistEntry,
5
+ ExecutableDenialCode,
6
+ ProviderCapabilityReport,
7
+ RunnerBackend,
8
+ VerifiedExecutable,
9
+ } from "#model/provider-capabilities";
10
+ import type { StepSpec } from "#review/step-runner";
11
+ import type { CredentialBroker } from "../security/credential-broker";
12
+ import type { WorkspaceDenialCode } from "../security/workspace-read-broker";
13
+ import type {
14
+ NormalizedTokens,
15
+ NormalizedUsage,
16
+ UsageBillingMode,
17
+ } from "./usage-normalized";
18
+
19
+ export type {
20
+ CredentialKind,
21
+ ExecutableAllowlistEntry,
22
+ ExecutableDenialCode,
23
+ ProviderCapabilityReport,
24
+ RunnerBackend,
25
+ VerifiedExecutable,
26
+ WorkspaceDenialCode,
27
+ };
28
+
29
+ export type DenialCode = WorkspaceDenialCode | ExecutableDenialCode;
30
+
31
+ export interface ResolvedModelRoute {
32
+ readonly backend: RunnerBackend;
33
+ readonly provider: string;
34
+ readonly gateway?: string;
35
+ readonly modelFamily: string;
36
+ readonly modelSnapshot: string;
37
+ readonly modelVariant?: string;
38
+ }
39
+
40
+ export interface IsolationProjection {
41
+ readonly credentialProjectionId: string;
42
+ readonly env: Readonly<Record<string, string>>;
43
+ readonly syntheticHome: string;
44
+ readonly syntheticConfigHome: string;
45
+ readonly syntheticTmp: string;
46
+ readonly verifiedBinaryPath: string;
47
+ }
48
+
49
+ export interface TransportRequest {
50
+ readonly sessionId: string;
51
+ readonly attempt: number;
52
+ readonly route: ResolvedModelRoute;
53
+ // The model string the provider CLI/SDK actually receives. For Claude Code
54
+ // direct routes this is the logical alias (sonnet|opus|haiku); configured
55
+ // routes use route.modelSnapshot instead.
56
+ readonly executionModel: string;
57
+ // The effort the engine asked for (StepSpec.effort), always present. Only
58
+ // the Claude Code transport can APPLY it (`--effort`); a backend that cannot
59
+ // still receives it so the evidence can record intent beside the fact that
60
+ // it was not applied.
61
+ readonly effort: Effort;
62
+ readonly systemPromptPath: string;
63
+ readonly systemPromptSha256: string;
64
+ readonly userPrompt: string;
65
+ readonly cwd: string;
66
+ readonly tools: readonly string[];
67
+ readonly mcpConfigPath?: string;
68
+ readonly isolation: IsolationProjection;
69
+ }
70
+
71
+ export interface ProviderTerminalProof {
72
+ readonly eventId: string;
73
+ readonly providerStatus: string;
74
+ readonly providerObservedAt: string;
75
+ readonly exitCode?: number;
76
+ readonly signal?: string;
77
+ }
78
+
79
+ export interface ProviderEventBase {
80
+ readonly sessionId: string;
81
+ readonly attempt: number;
82
+ readonly seq: number;
83
+ readonly observedAt: string;
84
+ }
85
+
86
+ export type ProviderEvent =
87
+ | (ProviderEventBase & { readonly type: "delta"; readonly text: string })
88
+ | (ProviderEventBase & {
89
+ readonly type: "usage";
90
+ readonly mode: "snapshot" | "delta";
91
+ readonly final: boolean;
92
+ // D1-08 PR2 (§8): a streamed usage UPDATE, not a full snapshot — only
93
+ // the leaves this event actually reports are present. cashCostUsd
94
+ // carries a per-event cost delta/snapshot alongside the token leaves;
95
+ // `applyUsageUpdate` (usage-normalized.ts) folds a sequence of these
96
+ // through the same snapshot/delta state machine as the tokens.
97
+ readonly usage: Partial<NormalizedTokens> & {
98
+ readonly cashCostUsd?: number;
99
+ };
100
+ })
101
+ | (ProviderEventBase & {
102
+ readonly type: "diagnostic";
103
+ readonly level: "info" | "warn" | "error";
104
+ readonly message: string;
105
+ })
106
+ | (ProviderEventBase & { readonly type: "heartbeat" })
107
+ | (ProviderEventBase & {
108
+ readonly type: "terminal";
109
+ readonly origin: "provider" | "transport" | "harness";
110
+ readonly proof?: ProviderTerminalProof;
111
+ readonly status: "completed" | "failed" | "cancelled";
112
+ readonly integrity: TransportOutcome["protocolIntegrity"];
113
+ });
114
+
115
+ export interface AsyncEventSink {
116
+ push(event: ProviderEvent): Promise<"accepted" | "closed">;
117
+ close(): void;
118
+ }
119
+
120
+ // #175 half 2, 2026-09-02. WHICH model(s) the provider actually ran, as the
121
+ // provider reported them — not as we asked for them.
122
+ //
123
+ // WHY this exists at all: the engine used to assert a model version up front,
124
+ // from a hardcoded alias -> snapshot mapping that nothing verified (see the
125
+ // #175 note atop model/catalog.ts). The Claude CLI has been reporting the
126
+ // truth in its `modelUsage` block the whole time and we discarded it.
127
+ //
128
+ // WHY it is a LIST and not "the model that ran": verified live 2026-09-02, a
129
+ // single `--model sonnet` invocation reported TWO models — the requested
130
+ // sonnet snapshot AND `claude-haiku-4-5-20251001`, which the CLI uses for its
131
+ // own internal work. Collapsing that to a scalar would be a new false
132
+ // provenance claim replacing the one #175 removed. Nothing may assume the
133
+ // requested model appears here, or that exactly one entry does.
134
+ //
135
+ // `model` is the exact snapshot the provider keyed the entry on;
136
+ // `canonicalModel` is the family it reported for that snapshot, absent when
137
+ // the provider did not say. Neither is derived, defaulted, or cross-checked
138
+ // against the route — a mismatch between what we asked for and what ran is a
139
+ // FACT to record, and reconciling it here would erase it.
140
+ export interface ObservedModel {
141
+ readonly model: string;
142
+ readonly canonicalModel?: string;
143
+ }
144
+
145
+ export interface DiagnosticEvidence {
146
+ readonly schema: string;
147
+ readonly status: "complete" | "incomplete" | "unavailable";
148
+ readonly redactedJson: string;
149
+ }
150
+
151
+ export interface TransportOutcome {
152
+ readonly diagnosticEvidence?: DiagnosticEvidence;
153
+ // A cause the transport holds as a typed fact, not as witness text. resolveFailureCause
154
+ // consults it before the witness classifier, so a fact the stderr witness could only
155
+ // spell keeps its own cause instead of the runtime's generic one.
156
+ readonly failureCause?: TransportFailureCause;
157
+ // One short line saying WHY the attempt failed, in the provider's own words, when the
158
+ // transport holds them as a fact (the Claude CLI's API-error envelope). It travels to
159
+ // the CLI record so the PR can name the real cause; the harness copies it from the final
160
+ // attempt's outcome. Absent on a success and when the transport has nothing to say.
161
+ readonly failureDetail?: string;
162
+ // The secret the failed attempt ran on, when the transport can tell: a CI run names it
163
+ // so the fix says WHICH secret to replace or top up. The per-token variables win over
164
+ // CLAUDE_CODE_OAUTH_TOKEN in the CLI (see credentialOf in the Claude transport).
165
+ readonly failureCredential?: FailureCredential;
166
+ readonly completion: "success" | "failed" | "cancelled";
167
+ readonly protocolIntegrity:
168
+ | "verified"
169
+ | "truncated"
170
+ | "malformed"
171
+ | "overflow"
172
+ | "unverified";
173
+ readonly terminalProof?: ProviderTerminalProof;
174
+ readonly finalText: string;
175
+ // D1-08 PR2 (§8): normalized disjoint usage leaves, not the legacy flat
176
+ // shape. `projectLegacyUsage` (usage-normalized.ts) is the ONLY bridge back
177
+ // to `SessionUsage`, applied at the `runPipeline` return boundary.
178
+ readonly usage: NormalizedUsage;
179
+ readonly stderrTail: string;
180
+ // #126: the transport's OWN diagnostics — counts and tallies that describe
181
+ // how the transport observed the attempt, not what the provider said.
182
+ // `stderrTail` is the classification witness and its declared meaning is
183
+ // "the provider's words"; finalText is already excluded from it for exactly
184
+ // that reason, and our own text is the same hazard from the other
185
+ // direction. Measured, not guessed: a `429` poll-timeout count classified
186
+ // `rate_limit` and a `503` one `network_transient` on the transport's own
187
+ // patterns, while the legacy classifier's unanchored `502|503|529` turned
188
+ // `1502` into a transient too — and the prose "poll round(s) timed out"
189
+ // matched the legacy `timed out` pattern at EVERY count, deterministically.
190
+ // This channel exists so those facts stay visible in the attempt log
191
+ // without any classifier being able to read them. Nothing may classify off
192
+ // it; every witness pattern lives on `stderrTail` alone.
193
+ readonly diagnosticsTail?: string;
194
+ // #214: how many provider tool-call parts this attempt observed.
195
+ // `undefined` — never a fabricated 0 — when the transport cannot observe
196
+ // tools, because 0 is the claim "we looked and the model issued none" and
197
+ // absence is the honest shape for "we were told nothing" (the same rule
198
+ // `observedModels` follows one field down). OpenCode stamps the count
199
+ // after a session actually ran, including 0. Claude Code derives it from
200
+ // the CLI result's `num_turns` (#299), as a lower bound that is exact on
201
+ // zero versus nonzero, and omits it when `num_turns` is not an integer >= 1.
202
+ readonly toolInvocations?: number;
203
+ // #175 half 2: the models the provider says it ran. `undefined` — never
204
+ // `[]` — when the provider reported nothing, because an empty list is the
205
+ // claim "we looked and nothing ran" and absence is the honest shape for
206
+ // "we were told nothing" (the same rule `normalizeUnavailableUsage` follows
207
+ // for tokens one field up).
208
+ //
209
+ // WHERE THIS STOPS, stated here so the next reader does not assume more
210
+ // wiring than exists: the ONLY consumer is the per-attempt log written by
211
+ // `writeAttemptLog` (harness.ts). It is deliberately NOT folded into
212
+ // `NormalizedUsage` — that is §8's numeric contract, summed field-by-field
213
+ // by `sumNormalizedUsage` into a run-level rollup, and a list of names
214
+ // needs union-with-dedup semantics that would have to be designed rather
215
+ // than assumed. It therefore does not reach `StepResult`, `per_agent`,
216
+ // `pipeline.json`, or the terminal report. Wiring it to provenance is a
217
+ // separate slice; parsing it and making it readable is this one.
218
+ readonly observedModels?: readonly ObservedModel[];
219
+ readonly timedOut?: boolean;
220
+ readonly exitCode?: number;
221
+ }
222
+
223
+ // The GitHub secrets a Claude review can run on (see TransportOutcome.failureCredential).
224
+ // The CI record mirrors this list in src/ci/outcome.ts, tied by `satisfies`.
225
+ export type FailureCredential =
226
+ | "ANTHROPIC_API_KEY"
227
+ | "ANTHROPIC_AUTH_TOKEN"
228
+ | "CLAUDE_CODE_OAUTH_TOKEN";
229
+
230
+ export type TransportFailureCause =
231
+ | "auth_invalid"
232
+ | "quota_exhausted"
233
+ | "rate_limit"
234
+ | "network_transient"
235
+ | "protocol_truncation"
236
+ | "protocol_mismatch"
237
+ | "protocol_overflow"
238
+ | "output_limit_exceeded"
239
+ | "context_window_exceeded"
240
+ | "safety_refusal"
241
+ | "provider_configuration_invalid"
242
+ | "model_unavailable"
243
+ | "missing_provider_record"
244
+ | "runtime_unavailable"
245
+ | "remote_abort_unconfirmed";
246
+
247
+ // Every TransportFailureCause as a runtime lookup. The `satisfies` clause fails tsc
248
+ // when a cause joins the union and is missing here, and when a key is not a cause.
249
+ const TRANSPORT_FAILURE_CAUSE_LOOKUP = {
250
+ auth_invalid: true,
251
+ quota_exhausted: true,
252
+ rate_limit: true,
253
+ network_transient: true,
254
+ protocol_truncation: true,
255
+ protocol_mismatch: true,
256
+ protocol_overflow: true,
257
+ output_limit_exceeded: true,
258
+ context_window_exceeded: true,
259
+ safety_refusal: true,
260
+ provider_configuration_invalid: true,
261
+ model_unavailable: true,
262
+ missing_provider_record: true,
263
+ runtime_unavailable: true,
264
+ remote_abort_unconfirmed: true,
265
+ } satisfies Record<TransportFailureCause, true>;
266
+
267
+ export function isTransportFailureCause(
268
+ value: unknown,
269
+ ): value is TransportFailureCause {
270
+ return (
271
+ typeof value === "string" &&
272
+ Object.hasOwn(TRANSPORT_FAILURE_CAUSE_LOOKUP, value)
273
+ );
274
+ }
275
+
276
+ // #150 (built on #149's server-lifetime OpenCode credential fix). Declares
277
+ // whether a `ProviderTransport` consumes `StepExecutionHarness.run`'s
278
+ // per-STEP credential projection — the one `credentialBroker.project()`
279
+ // materializes, writes to disk, and destroys once per attempt, and hands
280
+ // the transport as `TransportRequest.isolation` (harness.ts ~728-808).
281
+ //
282
+ // "per-step" (or the field left undeclared) means "yes, this transport
283
+ // reads `request.isolation.env`/`verifiedBinaryPath`, so keep projecting" —
284
+ // today's only behaviour, and the FAIL-SAFE default: a transport nobody
285
+ // updated to declare itself still gets protected credentials rather than
286
+ // silently running on whatever `buildChildEnv` passes through.
287
+ //
288
+ // "server-lifetime" means the transport's OWN process already owns
289
+ // credential protection for its whole run, independent of any one step
290
+ // (the OpenCode SDK transport's server, launched once and brokered by
291
+ // `OpenCodeAuthBroker`/`OpenCodeFreeBroker` per #149) — it never reads
292
+ // `isolation` at all. Declaring it lets the harness skip the per-step
293
+ // projection for that transport entirely: no broker call, no auth file
294
+ // written and destroyed for nothing, and no `missing_subscription_record`
295
+ // degrade warning for a projection that was never attempted (#150's
296
+ // finding: that projection had no consumer and its absence was mislabeled
297
+ // as an "operator-env-fallback", implying a degrade that never happened).
298
+ export type CredentialProjectionConsumption = "per-step" | "server-lifetime";
299
+
300
+ export interface ProviderTransport {
301
+ readonly backend: RunnerBackend;
302
+ readonly billingMode?: UsageBillingMode;
303
+ readonly admissionIdentity?: {
304
+ readonly executable: string;
305
+ readonly provider: string;
306
+ };
307
+ readonly cancellationSemantics?: "process-exit" | "provider-proof";
308
+ // #150: absent = "per-step" (fail-safe default, see
309
+ // `CredentialProjectionConsumption` above). A FUTURE transport that starts
310
+ // reading `isolation.env` must declare "per-step" explicitly or it would
311
+ // silently run unprotected the moment some OTHER transport's declaration
312
+ // taught the harness to skip.
313
+ readonly credentialProjection?: CredentialProjectionConsumption;
314
+ readonly defaultRoute?: ResolvedModelRoute;
315
+ capabilities(): Promise<ProviderCapabilityReport>;
316
+ execute(
317
+ request: TransportRequest,
318
+ context: {
319
+ readonly signal: AbortSignal;
320
+ readonly events: AsyncEventSink;
321
+ },
322
+ ): Promise<TransportOutcome>;
323
+ classifyFailure(outcome: TransportOutcome): TransportFailureCause | undefined;
324
+ }
325
+
326
+ export interface StepAdmissionGate {
327
+ admit(spec: StepSpec): Promise<void> | void;
328
+ }
329
+
330
+ export interface AuthEvent {
331
+ readonly kind: "workspace" | "executable";
332
+ readonly status: "approved" | "denied";
333
+ readonly reason?: string;
334
+ }
335
+
336
+ export type BillingMode = "subscription" | "metered";
337
+
338
+ export interface EnvironmentPolicy {
339
+ readonly syntheticHome: boolean;
340
+ readonly workspaceReadBroker: boolean;
341
+ }
342
+
343
+ export interface ToolPolicy {
344
+ readonly allowMapOnly: boolean;
345
+ readonly deniedTools: readonly string[];
346
+ }
347
+
348
+ export interface McpPolicy {
349
+ readonly codegraphOnly: boolean;
350
+ readonly verifiedConfigRequired: boolean;
351
+ }
352
+
353
+ export interface VerifiedExecutableStatus {
354
+ readonly resolved: boolean;
355
+ readonly absolutePath?: string;
356
+ readonly sha256?: string;
357
+ readonly reason?: string;
358
+ }
359
+
360
+ export interface AuthProjectionFacts {
361
+ readonly kind: CredentialKind;
362
+ readonly projectionReady: boolean;
363
+ readonly probe: "passed" | "failed" | "not_run";
364
+ }
365
+
366
+ export interface EnvironmentFacts {
367
+ readonly syntheticHome: boolean;
368
+ readonly enumeratedPassthrough: boolean;
369
+ }
370
+
371
+ export interface IsolationFacts {
372
+ readonly workspaceReadBroker: boolean;
373
+ readonly codegraphPolicy: boolean;
374
+ }
375
+
376
+ export interface ToolMcpFacts {
377
+ readonly allowMapEnforced: boolean;
378
+ readonly mcpIntegrityChecked: boolean;
379
+ }
380
+
381
+ export interface ProtocolFacts {
382
+ readonly terminalProof: boolean;
383
+ readonly boundedEvents: boolean;
384
+ readonly usageMode: "snapshot" | "delta" | "none";
385
+ }
386
+
387
+ export interface UsageFacts {
388
+ readonly normalized: boolean;
389
+ }
390
+
391
+ export interface ExactBindingCapabilityReport {
392
+ readonly routeKey: string;
393
+ readonly backend: RunnerBackend;
394
+ readonly sdk: { readonly available: boolean; readonly version?: string };
395
+ readonly binary: VerifiedExecutableStatus;
396
+ readonly auth: AuthProjectionFacts;
397
+ readonly environment: EnvironmentFacts;
398
+ readonly isolation: IsolationFacts;
399
+ readonly toolsMcp: ToolMcpFacts;
400
+ readonly protocol: ProtocolFacts;
401
+ readonly usage: UsageFacts;
402
+ readonly billing: {
403
+ readonly mode: BillingMode;
404
+ readonly pricingApplicability: "required" | "not_applicable";
405
+ readonly tokenPricingAvailable: boolean;
406
+ readonly cashCostAccountingValid: boolean;
407
+ };
408
+ }
409
+
410
+ export interface RuntimeBindingCredential {
411
+ readonly kind: CredentialKind;
412
+ readonly ref: string;
413
+ readonly broker?: CredentialBroker;
414
+ readonly bucketId: string;
415
+ }
416
+
417
+ export interface RuntimeBinding {
418
+ readonly key: string;
419
+ readonly route: ResolvedModelRoute;
420
+ readonly executable: VerifiedExecutable;
421
+ readonly credential: RuntimeBindingCredential;
422
+ readonly environment: EnvironmentPolicy;
423
+ readonly tools: ToolPolicy;
424
+ readonly mcp: McpPolicy;
425
+ readonly admissionIdentity?: {
426
+ readonly executable: string;
427
+ readonly provider: string;
428
+ };
429
+ readonly cancellationSemantics?: "process-exit" | "provider-proof";
430
+ readonly defaultRoute?: ResolvedModelRoute;
431
+ capabilities(): Promise<ExactBindingCapabilityReport>;
432
+ acquire(
433
+ isolation: IsolationProjection,
434
+ registry: {
435
+ get(backend: RunnerBackend): ProviderTransport;
436
+ },
437
+ ): Promise<TransportLease>;
438
+ }
439
+
440
+ export interface TransportLease {
441
+ readonly transport: ProviderTransport;
442
+ dispose(): Promise<void>;
443
+ }
@@ -0,0 +1,42 @@
1
+ // The legacy v1 session-failure classification vocabulary
2
+ // (transient|terminal|format), ported verbatim from deep-review's
3
+ // runner/session.ts.
4
+ //
5
+ // Split out of review/step-runner.ts (architecture guard C2):
6
+ // execution/failure-policy.ts's `resolveFailureCause` falls back to this
7
+ // classifier (step 4: for any outcome a transport's own `classifyFailure`
8
+ // and the parse check both miss), and review/step-runner.ts itself depends
9
+ // on execution/harness.ts for StepExecutionHarness — so failure-policy.ts
10
+ // importing this classifier FROM step-runner.ts closed a value-import
11
+ // cycle back through harness.ts. This file has no imports of its own — a
12
+ // true leaf both sides can depend on one-way.
13
+
14
+ export type FailureClass = "transient" | "terminal" | "format";
15
+
16
+ export function isTransientSessionFailure(result: {
17
+ stderrTail: string;
18
+ resultText: string;
19
+ }): boolean {
20
+ const witness = `${result.stderrTail}\n${result.resultText}`;
21
+ return /API Error|Connection closed|ECONNRESET|socket hang up|timed out|502|503|529|overloaded/i.test(
22
+ witness,
23
+ );
24
+ }
25
+
26
+ export function isTerminalSessionFailure(result: {
27
+ stderrTail: string;
28
+ resultText: string;
29
+ }): boolean {
30
+ const witness = `${result.stderrTail}\n${result.resultText}`;
31
+ return /Not logged in\s*[·.]\s*Please run \/login/i.test(witness);
32
+ }
33
+
34
+ export function classifyFailure(outcome: {
35
+ stderrTail: string;
36
+ resultText: string;
37
+ timedOut: boolean;
38
+ }): FailureClass {
39
+ if (outcome.timedOut) return "transient";
40
+ if (isTerminalSessionFailure(outcome)) return "terminal";
41
+ return isTransientSessionFailure(outcome) ? "transient" : "format";
42
+ }