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
@@ -0,0 +1,409 @@
1
+ // The CRYSK_* secrets intake (odd/tasks/role-model-routing.md, S8/S9, L12-L13).
2
+ //
3
+ // The workflow names each Crysk secret explicitly and hands them to the action as
4
+ // one `crysk-secrets` input of `NAME=value` lines:
5
+ //
6
+ // crysk-secrets: |
7
+ // CRYSK_CLAUDE_OAUTH_TOKEN=${{ secrets.CRYSK_CLAUDE_OAUTH_TOKEN }}
8
+ // CRYSK_OPENCODE_DEEPSEEK_API_KEY=${{ secrets.CRYSK_OPENCODE_DEEPSEEK_API_KEY }}
9
+ //
10
+ // WHY explicit names and never `toJSON(secrets)` (L13): the action, and whatever
11
+ // it installs, must never receive the customer's other secrets. A secret the
12
+ // repository does not have arrives as an empty value, which counts as absent.
13
+ //
14
+ // This module is the grammar and nothing else: pure, builtins only (Buffer is a
15
+ // global), so the trigger, which runs before `bun install`, can import it later.
16
+ // It never prints. Every message it returns names a secret or a line number,
17
+ // never a value, and `masks` lists every value the caller must `::add-mask::`
18
+ // before it writes anything else.
19
+ //
20
+ // The names (S8):
21
+ // CRYSK_CLAUDE_OAUTH_TOKEN Claude Code subscription (`claude setup-token`)
22
+ // CRYSK_CLAUDE_API_KEY Claude Code on an Anthropic API key
23
+ // CRYSK_OPENCODE_<P>_API_KEY an OpenCode provider's API key
24
+ // CRYSK_OPENCODE_<P>_OAUTH base64 of that provider's `opencode auth login` record
25
+ // <P> is the Models.dev provider id uppercased with `-` and `.` as `_`
26
+ // (opencodeSecretToken). CRYSK_CLAUDE_(OAUTH_TOKEN|API_KEY)_<NAME> is reserved
27
+ // for several Claude accounts (S6, out of scope) and ignored with a notice.
28
+
29
+ export type ClaudeCredentialKind = "subscription" | "api_key";
30
+
31
+ // The `opencode auth login` record of an OAuth provider. Only `type` is checked:
32
+ // the rest is the provider's own shape (access, refresh, expires, ...), carried
33
+ // whole into the OpenCode auth file (U3, setup.ts), so the child can refresh it.
34
+ export interface OpenCodeOAuthRecord {
35
+ readonly type: "oauth";
36
+ readonly [field: string]: unknown;
37
+ }
38
+
39
+ export interface OpenCodeProviderSecrets {
40
+ apiKey?: string;
41
+ oauth?: OpenCodeOAuthRecord;
42
+ }
43
+
44
+ export interface CryskSecrets {
45
+ // Keyed by the S5 credential kinds, so `credentials.claude` reads it directly.
46
+ readonly claude: { subscription?: string; api_key?: string };
47
+ // Keyed by <P>, the normalized provider token. Look a plan provider up with
48
+ // opencodeSecretsFor, which normalizes the provider: a secret name is never
49
+ // reversed into a provider id (`WAFER_AI` could be `wafer.ai` or `wafer-ai`).
50
+ readonly opencode: ReadonlyMap<string, OpenCodeProviderSecrets>;
51
+ }
52
+
53
+ // The names the engine read before S8. Recorded by presence only, for the clean
54
+ // break (U5), which names the new secret for each.
55
+ export const LEGACY_SECRET_NAMES = [
56
+ "CLAUDE_CODE_OAUTH_TOKEN",
57
+ "ANTHROPIC_API_KEY",
58
+ "OPENCODE_AUTH_JSON",
59
+ ] as const;
60
+ export type LegacySecretName = (typeof LEGACY_SECRET_NAMES)[number];
61
+
62
+ // The CRYSK_* secret to set in place of each old name (U5), for the messages that
63
+ // name it. OPENCODE_AUTH_JSON held the whole store; its replacement is one secret
64
+ // per provider, and an `_OAUTH` record is read only for openai (U3).
65
+ export const LEGACY_SECRET_REPLACEMENT: Readonly<
66
+ Record<LegacySecretName, string>
67
+ > = {
68
+ CLAUDE_CODE_OAUTH_TOKEN: "CRYSK_CLAUDE_OAUTH_TOKEN",
69
+ ANTHROPIC_API_KEY: "CRYSK_CLAUDE_API_KEY",
70
+ OPENCODE_AUTH_JSON:
71
+ "one CRYSK_OPENCODE_<PROVIDER>_API_KEY per provider (CRYSK_OPENCODE_OPENAI_OAUTH for an OpenAI subscription)",
72
+ };
73
+
74
+ export interface CryskSecretsParse {
75
+ readonly secrets: CryskSecrets;
76
+ // The kept names, sorted. Names only: they are already in the workflow file.
77
+ readonly names: readonly string[];
78
+ // The old names that arrived with a value, in LEGACY_SECRET_NAMES order.
79
+ readonly legacy: readonly LegacySecretName[];
80
+ // Every value to mask, in input order, without repeats.
81
+ readonly masks: readonly string[];
82
+ // Ignored names, for a `::notice::`. Names or line numbers only.
83
+ readonly notices: readonly string[];
84
+ // Non-empty means the input is refused. Names or line numbers only.
85
+ readonly problems: readonly string[];
86
+ }
87
+
88
+ const CLAUDE_NAMES: Readonly<Record<string, ClaudeCredentialKind>> = {
89
+ CRYSK_CLAUDE_OAUTH_TOKEN: "subscription",
90
+ CRYSK_CLAUDE_API_KEY: "api_key",
91
+ };
92
+ const CLAUDE_RESERVED_RE = /^CRYSK_CLAUDE_(?:OAUTH_TOKEN|API_KEY)_[A-Z0-9_]+$/;
93
+ // <P> is exactly the image of opencodeSecretToken: one or more [A-Z0-9] runs
94
+ // joined by single underscores. The provider runs up to the fixed suffix, so a
95
+ // provider whose own name ends in `_API` still parses (FOO_API + _API_KEY).
96
+ const OPENCODE_RE =
97
+ /^CRYSK_OPENCODE_([A-Z0-9]+(?:_[A-Z0-9]+)*)_(API_KEY|OAUTH)$/;
98
+ // A line is NAME=value when it starts with an identifier and an `=`; the value
99
+ // runs from the FIRST `=`, so base64 padding survives.
100
+ const LINE_RE = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/;
101
+ // Names printed back are only these: a CRYSK_ name or an old name. Anything else
102
+ // may be the tail of a value split across lines (a base64 wrapped at 76
103
+ // characters can look like `QQ==`), so it is reported by line number only.
104
+ const CRYSK_NAME_RE = /^CRYSK_[A-Z0-9_]+$/;
105
+ // Standard base64, padded: what `base64 -w0` and the platform write.
106
+ const BASE64_RE = /^[A-Za-z0-9+/]+={0,2}$/;
107
+ // No credential is this short, and masking one would blank common text such as
108
+ // a lone `=` across the whole job log.
109
+ const MIN_MASK_LENGTH = 4;
110
+ // <P>'s source: a Models.dev style provider id. Dots are accepted (`wafer.ai`)
111
+ // and become `_` like dashes, as S8 says; `_` itself stays `_`.
112
+ const PROVIDER_ID_RE = /^[A-Za-z0-9]+(?:[._-][A-Za-z0-9]+)*$/;
113
+
114
+ // The platform stub forwards OpenCode API keys through dynamic slots,
115
+ // `CRYSK_OPENCODE_<TOKEN>_API_KEY=<secret>` with the token from a dispatch input
116
+ // (platform L97-L98). An unused slot renders exactly as this line (empty token,
117
+ // empty value; verified on GitHub, run 42544917469 on cryskai/crysk-sandbox).
118
+ const EMPTY_OPENCODE_SLOT_NAME = "CRYSK_OPENCODE__API_KEY";
119
+ const EMPTY_OPENCODE_SLOT_LINE = `${EMPTY_OPENCODE_SLOT_NAME}=`;
120
+
121
+ // How many OpenCode provider slots a workflow carries, so the most OpenCode
122
+ // providers one review's models may name. The scaffolded workflow (E-f F4, D2)
123
+ // has this many slot lines, driven by vars.CRYSK_OPENCODE_PROVIDERS, and
124
+ // `crysk ci init` refuses models that name more. The platform's stub has the
125
+ // same count (its MAX_OPENCODE_PROVIDERS).
126
+ export const MAX_OPENCODE_PROVIDER_SLOTS = 5;
127
+
128
+ // E-f F5: action.yml empties the Claude variables in every step, but an OpenCode
129
+ // secret's name is per provider, so a job-level CRYSK_OPENCODE_* variable cannot be
130
+ // emptied there and reaches every process the step starts. The trigger and the run
131
+ // step name such a variable in a warning, never its value. Empty ones carry nothing.
132
+ const OPENCODE_ENV_NAME_RE = /^CRYSK_OPENCODE_[A-Z0-9_]+$/;
133
+
134
+ export function inheritedOpenCodeSecretNames(
135
+ env: Readonly<Record<string, string | undefined>>,
136
+ ): string[] {
137
+ return Object.keys(env)
138
+ .filter(
139
+ (name) => OPENCODE_ENV_NAME_RE.test(name) && (env[name] ?? "") !== "",
140
+ )
141
+ .sort();
142
+ }
143
+
144
+ export function inheritedOpenCodeSecretWarning(name: string): string {
145
+ return `${name} is set in this step's environment, so every process the step starts can read it: pass it only in the crysk-secrets input, and remove it from the workflow's env.`;
146
+ }
147
+
148
+ const SPLIT_HINT =
149
+ "(a value split across lines? encode _OAUTH secrets with base64 -w0)";
150
+
151
+ // A plan provider id to the <P> of its secret names, or undefined when no secret
152
+ // name can carry it (empty, a leading, trailing or doubled separator, or any
153
+ // other character). Two ids that differ only in `-`, `.` or `_` share a token;
154
+ // Models.dev has no such pair today.
155
+ export function opencodeSecretToken(providerId: string): string | undefined {
156
+ if (!PROVIDER_ID_RE.test(providerId)) return undefined;
157
+ return providerId.toUpperCase().replace(/[.-]/g, "_");
158
+ }
159
+
160
+ export function opencodeSecretsFor(
161
+ secrets: CryskSecrets,
162
+ providerId: string,
163
+ ): OpenCodeProviderSecrets | undefined {
164
+ const token = opencodeSecretToken(providerId);
165
+ return token === undefined ? undefined : secrets.opencode.get(token);
166
+ }
167
+
168
+ // U3 (L12 decision 5): an `_OAUTH` secret is read for this provider only, the
169
+ // one whose subscription record the engine projects (OPENCODE_OAUTH_PROVIDER in
170
+ // security/credential-broker.ts, not imported so this module stays builtins-only;
171
+ // a test pins the two equal). Another provider's OAuth record has no broker yet.
172
+ export const OPENCODE_OAUTH_SECRET_PROVIDER = "openai";
173
+
174
+ export type OpenCodeSecretChoice =
175
+ | {
176
+ readonly kind: "oauth" | "api_key";
177
+ // The secret whose value builds the provider's auth record.
178
+ readonly secret: string;
179
+ // A secret of the same provider that is set but not used.
180
+ readonly unused?: string;
181
+ readonly problem?: undefined;
182
+ }
183
+ | { readonly problem: string; readonly kind?: undefined };
184
+
185
+ // Which CRYSK_* secret serves an OpenCode provider, from the secret NAMES alone,
186
+ // so the setup step that writes the auth record and credentialKindForRoute, which
187
+ // binds the kind, read one rule and cannot disagree. Undefined when no secret
188
+ // serves it. The subscription comes first (L12 decision 4), like the Claude
189
+ // order's default. The provider is normalized with opencodeSecretToken; a secret
190
+ // name is never reversed into a provider.
191
+ // outcome.ts matches this refusal to give it its own fix (the provider's
192
+ // _API_KEY); test/ci/publish.test.ts runs this function's text through it.
193
+ const UNSUPPORTED_OAUTH_TEXT = `is an OpenCode subscription record, which Crysk reads only for ${OPENCODE_OAUTH_SECRET_PROVIDER} for now`;
194
+ export function chooseOpenCodeSecret(
195
+ providerId: string,
196
+ names: readonly string[],
197
+ ): OpenCodeSecretChoice | undefined {
198
+ const token = opencodeSecretToken(providerId);
199
+ if (token === undefined) return undefined;
200
+ const apiKey = `CRYSK_OPENCODE_${token}_API_KEY`;
201
+ const oauth = `CRYSK_OPENCODE_${token}_OAUTH`;
202
+ const hasApiKey = names.includes(apiKey);
203
+ if (names.includes(oauth)) {
204
+ if (providerId !== OPENCODE_OAUTH_SECRET_PROVIDER) {
205
+ return {
206
+ problem: `${oauth} ${UNSUPPORTED_OAUTH_TEXT}; set ${apiKey} instead`,
207
+ };
208
+ }
209
+ return hasApiKey
210
+ ? { kind: "oauth", secret: oauth, unused: apiKey }
211
+ : { kind: "oauth", secret: oauth };
212
+ }
213
+ return hasApiKey ? { kind: "api_key", secret: apiKey } : undefined;
214
+ }
215
+
216
+ // Whether the input carries any Crysk credential, for the trigger's no-credential
217
+ // check (U5). A refused value counts: the setup step names what is wrong with it
218
+ // (credential/malformed_payload), which says more than "no credential". An old
219
+ // name never counts, and an empty value is absent.
220
+ export function cryskSecretsCarryCredential(parse: CryskSecretsParse): boolean {
221
+ const presence = cryskSecretsPresence(parse);
222
+ return (
223
+ presence.claude.length > 0 ||
224
+ presence.opencodeProviders.length > 0 ||
225
+ parse.problems.length > 0
226
+ );
227
+ }
228
+
229
+ // What the setup step may tell later steps: names and kinds, never a value.
230
+ export function cryskSecretsPresence(parse: CryskSecretsParse): {
231
+ names: string[];
232
+ claude: ClaudeCredentialKind[];
233
+ opencodeProviders: string[];
234
+ } {
235
+ const claude = (["subscription", "api_key"] as const).filter(
236
+ (kind) => parse.secrets.claude[kind] !== undefined,
237
+ );
238
+ return {
239
+ names: [...parse.names],
240
+ claude,
241
+ opencodeProviders: [...parse.secrets.opencode.keys()].sort(),
242
+ };
243
+ }
244
+
245
+ type OAuthDecode =
246
+ | { ok: true; record: OpenCodeOAuthRecord; leaves: string[] }
247
+ | { ok: false; problem: string };
248
+
249
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
250
+ return typeof value === "object" && value !== null && !Array.isArray(value);
251
+ }
252
+
253
+ // Every string inside the record but its top-level `type`: GitHub registered the
254
+ // base64 text as the secret, never the tokens inside it, so these masks are the
255
+ // only thing that hides a decoded access or refresh token.
256
+ function stringLeaves(value: unknown, out: string[], skipType: boolean): void {
257
+ if (typeof value === "string") {
258
+ out.push(value);
259
+ } else if (Array.isArray(value)) {
260
+ for (const item of value) stringLeaves(item, out, false);
261
+ } else if (isPlainObject(value)) {
262
+ for (const [key, item] of Object.entries(value)) {
263
+ if (skipType && key === "type") continue;
264
+ stringLeaves(item, out, false);
265
+ }
266
+ }
267
+ }
268
+
269
+ function decodeOAuth(name: string, value: string): OAuthDecode {
270
+ // Buffer.from(x, "base64") skips characters outside the alphabet without a
271
+ // word, so the alphabet and the padded length are checked first.
272
+ if (!BASE64_RE.test(value) || value.length % 4 !== 0) {
273
+ return {
274
+ ok: false,
275
+ problem: `${name} is not base64 (encode the OpenCode auth record with base64 -w0)`,
276
+ };
277
+ }
278
+ let parsed: unknown;
279
+ try {
280
+ parsed = JSON.parse(Buffer.from(value, "base64").toString("utf8"));
281
+ } catch {
282
+ parsed = undefined;
283
+ }
284
+ if (!isPlainObject(parsed)) {
285
+ return { ok: false, problem: `${name} does not decode to a JSON object` };
286
+ }
287
+ if (parsed.type !== "oauth") {
288
+ return {
289
+ ok: false,
290
+ problem: `${name} is not an OpenCode OAuth record (its type is not "oauth")`,
291
+ };
292
+ }
293
+ const leaves: string[] = [];
294
+ stringLeaves(parsed, leaves, true);
295
+ return { ok: true, record: parsed as OpenCodeOAuthRecord, leaves };
296
+ }
297
+
298
+ export function parseCryskSecrets(raw: string): CryskSecretsParse {
299
+ const claude: { subscription?: string; api_key?: string } = {};
300
+ const opencode = new Map<string, OpenCodeProviderSecrets>();
301
+ const names = new Set<string>();
302
+ const legacy = new Set<LegacySecretName>();
303
+ const masks: string[] = [];
304
+ const notices: string[] = [];
305
+ const problems: string[] = [];
306
+ const seen = new Set<string>();
307
+
308
+ const mask = (text: string) => {
309
+ if (text.length >= MIN_MASK_LENGTH && !masks.includes(text)) {
310
+ masks.push(text);
311
+ }
312
+ };
313
+
314
+ const lines = raw.split("\n");
315
+ for (const [index, rawLine] of lines.entries()) {
316
+ const line = rawLine.trim();
317
+ if (line === "") continue;
318
+ // An unused platform slot: skipped silently, never present. Only this exact
319
+ // line; a value under the empty token is refused below.
320
+ if (line === EMPTY_OPENCODE_SLOT_LINE) continue;
321
+ const lineNo = index + 1;
322
+ const match = LINE_RE.exec(line);
323
+ if (match === null) {
324
+ mask(line);
325
+ problems.push(
326
+ `line ${lineNo} of the crysk-secrets input is not NAME=value ${SPLIT_HINT}`,
327
+ );
328
+ continue;
329
+ }
330
+ const name = match[1] as string;
331
+ const value = (match[2] as string).trim();
332
+ const printable =
333
+ CRYSK_NAME_RE.test(name) ||
334
+ (LEGACY_SECRET_NAMES as readonly string[]).includes(name);
335
+
336
+ if (!printable) {
337
+ mask(line);
338
+ if (value !== "") mask(value);
339
+ notices.push(
340
+ `line ${lineNo} of the crysk-secrets input is not a Crysk credential; it is ignored.`,
341
+ );
342
+ continue;
343
+ }
344
+ // Empty counts as absent: a secret the repository does not have arrives as
345
+ // `NAME=` from `${{ secrets.NAME }}`.
346
+ if (value === "") continue;
347
+ mask(value);
348
+ if (name === EMPTY_OPENCODE_SLOT_NAME) {
349
+ problems.push(
350
+ `${name} has a value but no provider: an unused OpenCode slot must be empty`,
351
+ );
352
+ continue;
353
+ }
354
+
355
+ if ((LEGACY_SECRET_NAMES as readonly string[]).includes(name)) {
356
+ legacy.add(name as LegacySecretName);
357
+ continue;
358
+ }
359
+ if (CLAUDE_RESERVED_RE.test(name)) {
360
+ notices.push(
361
+ `${name} is reserved for several Claude accounts, which Crysk does not read yet; it is ignored.`,
362
+ );
363
+ continue;
364
+ }
365
+
366
+ const claudeKind = CLAUDE_NAMES[name];
367
+ const opencodeMatch = OPENCODE_RE.exec(name);
368
+ if (claudeKind === undefined && opencodeMatch === null) {
369
+ notices.push(`${name} is not a Crysk credential name; it is ignored.`);
370
+ continue;
371
+ }
372
+ if (seen.has(name)) {
373
+ problems.push(`${name} is given more than once`);
374
+ continue;
375
+ }
376
+ seen.add(name);
377
+
378
+ if (claudeKind !== undefined) {
379
+ claude[claudeKind] = value;
380
+ names.add(name);
381
+ continue;
382
+ }
383
+ const token = (opencodeMatch as RegExpExecArray)[1] as string;
384
+ const kind = (opencodeMatch as RegExpExecArray)[2];
385
+ const entry: OpenCodeProviderSecrets = opencode.get(token) ?? {};
386
+ if (kind === "API_KEY") {
387
+ entry.apiKey = value;
388
+ } else {
389
+ const decoded = decodeOAuth(name, value);
390
+ if (!decoded.ok) {
391
+ problems.push(decoded.problem);
392
+ continue;
393
+ }
394
+ for (const leaf of decoded.leaves) mask(leaf);
395
+ entry.oauth = decoded.record;
396
+ }
397
+ opencode.set(token, entry);
398
+ names.add(name);
399
+ }
400
+
401
+ return {
402
+ secrets: { claude, opencode },
403
+ names: [...names].sort(),
404
+ legacy: LEGACY_SECRET_NAMES.filter((name) => legacy.has(name)),
405
+ masks,
406
+ notices,
407
+ problems,
408
+ };
409
+ }
package/src/ci/gates.ts CHANGED
@@ -65,7 +65,7 @@ import type { CiMode } from "#pr/preflight";
65
65
  import type { Finding, FindingsDocument } from "#review/findings";
66
66
  import type { PrCommentDelta } from "#review/report";
67
67
  import type { SizeGateVerdict } from "#review/size-gate";
68
- import { MARKER_OPEN } from "../brand";
68
+ import { commandHint, MARKER_OPEN } from "../brand";
69
69
  import { CliUsageError } from "../errors";
70
70
  import { envBillsMetered } from "../execution/usage-normalized";
71
71
  import { ciForceReviewHintLine } from "./force-comment";
@@ -83,6 +83,7 @@ import {
83
83
  } from "./review-admission";
84
84
  import type { CiReviewPolicyMode } from "./review-policy";
85
85
  import type { DeltaRiskAssessment } from "./review-risk";
86
+ import { OVERRIDE_COMMAND } from "./trigger";
86
87
 
87
88
  function usd(amount: number): string {
88
89
  return `$${amount.toFixed(2)}`;
@@ -329,44 +330,30 @@ export type CiBillingMode = "subscription" | "metered";
329
330
  // ANTHROPIC_AUTH_TOKEN joined the signal in the same move. It was never
330
331
  // excluded by a decision — the doctrine below never mentions it — and
331
332
  // `ENV_PASSTHROUGH` (harness.ts) projects it into the child immediately beside
332
- // ANTHROPIC_API_KEY as the same per-token credential class, so the rule stated
333
- // two paragraphs down ("the mere PRESENCE of a key keeps the ceiling") already
334
- // covered it. Nil-delta for the shipped action: action.yml binds only
335
- // ANTHROPIC_API_KEY and CLAUDE_CODE_OAUTH_TOKEN, so no generated workflow can
336
- // newly acquire a ceiling from it.
333
+ // ANTHROPIC_API_KEY as the same per-token credential class, so the presence rule
334
+ // that stood below (retired by S5) already covered it. It cannot reach a run's
335
+ // ceiling any more: the action takes Claude credentials only from the CRYSK_CLAUDE_*
336
+ // secrets in its crysk-secrets input (S8, U5) and empties the CLI's own variables,
337
+ // and the run env (claudeRunEnv) removes ANTHROPIC_AUTH_TOKEN whatever its source.
337
338
  //
338
- // Which credential bills when BOTH CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY are
339
- // present was settled by observation after this rule was written: CLI 2.1.312 prints
340
- // "claude.ai connectors are disabled because ANTHROPIC_API_KEY or another auth source is
341
- // set and takes precedence over your claude.ai login", and on this repo's CI with both
342
- // secrets bound every request used the API key (see credentialOf in
343
- // transports/claude-code-cli.ts). The rule below still does not depend on that answer,
344
- // and the gap it describes was real when it was written:
345
- // action.yml:111-112 binds both into the child env unconditionally,
346
- // test/harness/env-projection.test.ts:48-56 deliberately asserts both survive
347
- // the projection with no precedence between them, and `defaultClaudeAuthProbe`
348
- // (model/provider-capabilities.ts:402-405) ORs them into a single boolean. Whichever
349
- // one the Claude CLI itself prefers wins, and that fact is recorded nowhere in
350
- // this codebase.
339
+ // S5 (2026-11-06) retired the rule that stood here: "the mere PRESENCE of a key keeps
340
+ // the ceiling", written while nobody chose which credential billed when both were set
341
+ // (the CLI preferred the key, observed on CLI 2.1.312). Now the run chooses: the first
342
+ // credential in `credentials.claude` (default subscription, then api_key) that is
343
+ // present, once at run start (security/claude-credential.ts). The env this function
344
+ // receives is that run's env, which holds the chosen Claude credential and no other,
345
+ // so `metered` here means the run uses the API key, and a repo holding both secrets
346
+ // with the default order runs on the subscription with no ceiling. A caller that
347
+ // passes the raw process env instead gets the old presence answer.
351
348
  //
352
- // This rule does not need that answer, because the two errors are not
353
- // symmetric. Guess "unlimited" wrongly and a real invoice arrives that nobody
354
- // authorized. Guess "ceiling" wrongly and one review is skipped, which the
355
- // operator clears with a single line of YAML (`budget-usd: 0`). So the mere
356
- // PRESENCE of a key keeps the ceiling: we cannot rule out that it bills.
357
- // README.md:38-45 already states the user-facing half of the same rule —
358
- // sourcing ANTHROPIC_API_KEY into the shell "is what moves a run from quota to
359
- // invoice".
360
- //
361
- // Trimming is load-bearing. 2026-09-02, #177 corrects the overstatement this
362
- // paragraph used to carry ("without the trim, no route would ever resolve as
363
- // a subscription in Actions"): action.yml:111 binds the input UNCONDITIONALLY
364
- // and GitHub renders an unset input as the empty string, so every
365
- // subscription-route CI run carries `ANTHROPIC_API_KEY=""` — and `""` is
366
- // already falsy, so that case never needed the trim. What the trim catches is
367
- // a WHITESPACE-ONLY value, which is truthy and would otherwise impose a
368
- // ceiling on a subscription route. `test/ci/gates.test.ts` asserts both cases
369
- // separately, and only the whitespace ones flip when the trim is removed.
349
+ // Trimming is load-bearing. An empty value never needed it: `""` is already
350
+ // falsy, and it is what the action binds the CLI's Claude variables to and how
351
+ // GitHub renders a secret the repository does not have. What the trim catches is
352
+ // a WHITESPACE-ONLY value, which is truthy and would otherwise impose a ceiling
353
+ // on a subscription route, for a caller that passes a raw env (the run env never
354
+ // holds one: claudeCredentialPresence trims the same way and drops it).
355
+ // `test/ci/gates.test.ts` asserts both cases separately, and only the
356
+ // whitespace ones flip when the trim is removed.
370
357
  //
371
358
  // This is deliberately NOT `model/provider-capabilities.ts`'s
372
359
  // `CLAUDE_CAPABILITY_STATICS.billingMode`, and the two must not be "unified"
@@ -697,8 +684,8 @@ function buildCoverageSkipComment(
697
684
 
698
685
  // budget-exhausted-carry S10: the comment a PR gets once no automatic review is left. It says so, explains
699
686
  // it by the repository's own rules, says what the gate does with the next pushes, and how to ask for more.
700
- // WHY no "override" here: an exhausted budget carries the last verdict (S2), and answered findings unlock a
701
- // carried red (S3), so nothing in this situation needs a human to unlock the gate.
687
+ // Stage 2 #12: no review reads those pushes, so the gate holds a green instead of carrying it, and the
688
+ // override is how a human merges a head no review verified.
702
689
  function buildManualRequiredComment(data: ManualRequiredSummary): string {
703
690
  const manualOnly = data.admissionReason === "manual-only-policy";
704
691
  const rules = [
@@ -724,9 +711,11 @@ function buildManualRequiredComment(data: ManualRequiredSummary): string {
724
711
  "",
725
712
  ...rules,
726
713
  "",
727
- "What the gate does with the next pushes: it keeps the last review's verdict. A red verdict turns " +
728
- "green, marked unverified, once every blocking finding has a reply from someone with write access: " +
729
- "`applied`, or a `dismissed` the CI adjudicator upheld. Reply before you push: the gate reads the " +
714
+ "What the gate does with the next pushes: no review reads them, so it never turns green on its own. " +
715
+ "A red verdict stays red while a blocking finding is unanswered. A green verdict, or a red one whose " +
716
+ "blocking findings all have a reply from someone with write access (`applied`, or a `dismissed` the " +
717
+ "CI adjudicator upheld), waits as `pending` until a review verifies the head or " +
718
+ `${commandHint(OVERRIDE_COMMAND)} merges it unverified. Reply before you push: the gate reads the ` +
730
719
  "replies when the push arrives.",
731
720
  "",
732
721
  "The existing review comment still describes the last head Crysk reviewed.",