crysk 0.4.0 → 0.5.1
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.
- package/README.md +26 -17
- package/config/models/anthropic.json +1 -1
- package/dist/SKILL-k4k0zn1w.md +143 -0
- package/dist/SKILL-vhb4c3vv.md +553 -0
- package/dist/SKILL-xpf6kmdw.md +74 -0
- package/dist/ci-admission-0ken6ehx.md +128 -0
- package/dist/cli.js +3056 -1623
- package/dist/index.js +1744 -938
- package/dist/opencode-ci-ac5zksdn.md +106 -0
- package/dist/workflow-4pkyck01.yml +160 -0
- package/package.json +1 -1
- package/prompts/default/PROVENANCE.md +1 -0
- package/skills/crysk/SKILL.md +16 -16
- package/skills/crysk-ci-setup/SKILL.md +41 -38
- package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
- package/skills/crysk-ci-setup/references/ci-admission.md +1 -1
- package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
- package/skills/crysk-loop/SKILL.md +1 -1
- package/src/asset-manifest.ts +0 -4
- package/src/assets.ts +1 -1
- package/src/ci/admission-ledger.ts +4 -0
- package/src/ci/classify-error.ts +21 -24
- package/src/ci/cli-record.ts +53 -1
- package/src/ci/crysk-secrets.ts +409 -0
- package/src/ci/force-comment.ts +14 -1
- package/src/ci/gates.ts +86 -57
- package/src/ci/outcome.ts +421 -330
- package/src/ci/platform-config.ts +2 -2
- package/src/ci/platform-estimate.ts +111 -0
- package/src/ci/platform-report.ts +274 -41
- package/src/ci/platform-trace.ts +581 -0
- package/src/ci/platform.ts +58 -12
- package/src/ci/publish.ts +19 -6
- package/src/ci/reporter.ts +14 -4
- package/src/ci/review-levels.ts +8 -7
- package/src/ci/run.ts +88 -0
- package/src/ci/setup.ts +485 -118
- package/src/ci/trace-bundle.ts +1486 -0
- package/src/ci/trace-transcripts.ts +480 -0
- package/src/ci/trigger.ts +176 -33
- package/src/cli.ts +11 -3
- package/src/commands/ci-setup-questions.ts +3 -3
- package/src/commands/ci-setup.ts +152 -6
- package/src/commands/config.ts +3 -0
- package/src/commands/doctor.ts +15 -6
- package/src/config/config.ts +16 -3
- package/src/diversity/clustering.ts +0 -1
- package/src/diversity/identity.ts +4 -5
- package/src/diversity/pipeline-integration.ts +1 -9
- package/src/doctor.ts +3 -3
- package/src/execution/attempt-evidence.ts +10 -5
- package/src/execution/claude-session-trace.ts +480 -0
- package/src/execution/contracts.ts +21 -4
- package/src/execution/harness.ts +105 -8
- package/src/execution/model-fallback.ts +239 -0
- package/src/execution/usage-normalized.ts +6 -4
- package/src/home-preflight.ts +1 -1
- package/src/index.ts +1 -1
- package/src/model/catalog.ts +13 -37
- package/src/model/free-discovery.ts +117 -8
- package/src/model/model-name.ts +404 -0
- package/src/model/provider-capabilities.ts +22 -7
- package/src/model/routing.ts +346 -467
- package/src/pr/admission.ts +18 -0
- package/src/pr/ci-admission-gate.ts +2 -0
- package/src/pr/discovery.ts +18 -0
- package/src/pr/plan.ts +55 -5
- package/src/pr/preflight.ts +1 -1
- package/src/pr/publish-outcome.ts +1 -1
- package/src/pr/review-pr.ts +26 -1
- package/src/pr/target.ts +63 -11
- package/src/production-runtime.ts +760 -331
- package/src/review/pipeline.ts +277 -101
- package/src/review/preflight.ts +201 -294
- package/src/review/report.ts +30 -26
- package/src/review/review.ts +20 -3
- package/src/review/route-preflight.ts +79 -11
- package/src/review/run.ts +44 -6
- package/src/review/scout.ts +1 -1
- package/src/review/spec.ts +3 -3
- package/src/review/step-runner.ts +70 -1
- package/src/runner-authority.ts +127 -9
- package/src/security/binding-policy.ts +1 -2
- package/src/security/claude-credential.ts +355 -0
- package/src/security/credential-broker.ts +56 -40
- package/src/security/evidence-redaction.ts +179 -4
- package/src/security/opencode-secret-manifest.ts +114 -0
- package/src/security/redact.ts +45 -0
- package/src/system-tools.ts +48 -21
- package/src/transport-registry.ts +12 -2
- package/src/transports/claude-code-cli.ts +21 -2
- package/src/transports/opencode-sdk.ts +11 -9
- package/src/transports/opencode-server.ts +7 -10
- package/src/ui/config-edit.ts +9 -20
- package/src/ui/config.ts +32 -27
- package/src/ui/plan.ts +84 -50
- package/src/updater.ts +10 -7
- package/prompts/default/deep-review-lifecycle.md +0 -362
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { credentialKindForRoute } from "../runner-authority";
|
|
2
2
|
|
|
3
3
|
// #182: live free-model discovery. OpenCode free models (backend `opencode`,
|
|
4
4
|
// provider `opencode`, e.g. `muse-spark-1.3-contributor-free`) authenticate
|
|
@@ -147,7 +147,10 @@ function headerMatches(
|
|
|
147
147
|
);
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
// The JSON block `models <provider> --verbose` prints under the model's
|
|
151
|
+
// header: the whole `Model` record (cost, status, variants, ...), parsed, or
|
|
152
|
+
// undefined when the header is absent or the block does not parse.
|
|
153
|
+
function parseModelBlock(
|
|
151
154
|
stdout: string,
|
|
152
155
|
provider: string,
|
|
153
156
|
model: string,
|
|
@@ -206,7 +209,7 @@ export async function isFreeModel(input: IsFreeModelInput): Promise<boolean> {
|
|
|
206
209
|
return false;
|
|
207
210
|
}
|
|
208
211
|
if (result.exitCode !== 0) return false;
|
|
209
|
-
const parsed =
|
|
212
|
+
const parsed = parseModelBlock(result.stdout, input.provider, input.model);
|
|
210
213
|
if (typeof parsed !== "object" || parsed === null) return false;
|
|
211
214
|
const record = parsed as Record<string, unknown>;
|
|
212
215
|
if (record.status !== "active") return false;
|
|
@@ -265,10 +268,12 @@ export function createFreeModelProbe(options: {
|
|
|
265
268
|
// free verdict covers. Reads only the verdicts admission already decided, so
|
|
266
269
|
// it never spawns — `probe` is the memoised instance admission returned, and a
|
|
267
270
|
// pair admission never probed would spawn here, which is why the gate below
|
|
268
|
-
// is the same one admission applies
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
//
|
|
271
|
+
// is the same one admission applies (openCodeFreeVerdicts in
|
|
272
|
+
// production-runtime.ts): credentialKindForRoute over the run's CRYSK_OPENCODE_*
|
|
273
|
+
// names (U3), so only a route whose kind is an API token can be free. An OAuth
|
|
274
|
+
// route (`openai` on its `_OAUTH` record, or on no names at all) never probes,
|
|
275
|
+
// and a claude-code step has no free kind at all. A missing probe, or a
|
|
276
|
+
// throwing one, counts as not free: an unknown price is never presented as free.
|
|
272
277
|
export interface FreeRouteBilling {
|
|
273
278
|
readonly free: number;
|
|
274
279
|
readonly total: number;
|
|
@@ -283,6 +288,9 @@ export async function countFreeRouteSteps(input: {
|
|
|
283
288
|
};
|
|
284
289
|
}[];
|
|
285
290
|
readonly probe: FreeModelProbe | undefined;
|
|
291
|
+
// The names admission read from the setup step's manifest
|
|
292
|
+
// (productionAdmission.authorityOptions.openCodeSecretNames); absent outside CI.
|
|
293
|
+
readonly openCodeSecretNames?: readonly string[];
|
|
286
294
|
}): Promise<FreeRouteBilling> {
|
|
287
295
|
const total = input.steps.length;
|
|
288
296
|
if (input.probe === undefined) return { free: 0, total };
|
|
@@ -290,7 +298,14 @@ export async function countFreeRouteSteps(input: {
|
|
|
290
298
|
const verdicts = await Promise.all(
|
|
291
299
|
input.steps.map(async ({ route }) => {
|
|
292
300
|
if (route.backend !== "opencode") return false;
|
|
293
|
-
|
|
301
|
+
const kind = credentialKindForRoute(
|
|
302
|
+
"opencode",
|
|
303
|
+
route.provider,
|
|
304
|
+
{},
|
|
305
|
+
false,
|
|
306
|
+
input.openCodeSecretNames,
|
|
307
|
+
);
|
|
308
|
+
if (kind !== "provider_api_token") return false;
|
|
294
309
|
try {
|
|
295
310
|
return await probe(route.provider, route.modelSnapshot);
|
|
296
311
|
} catch {
|
|
@@ -300,3 +315,97 @@ export async function countFreeRouteSteps(input: {
|
|
|
300
315
|
);
|
|
301
316
|
return { free: verdicts.filter((free) => free).length, total };
|
|
302
317
|
}
|
|
318
|
+
|
|
319
|
+
// S7 (E-g, E2; odd/tasks/role-model-routing.md L34): the variants OpenCode
|
|
320
|
+
// lists for a model, read from the SAME `models <provider> --verbose
|
|
321
|
+
// --refresh` listing the free check reads. OpenCode prints each model's whole
|
|
322
|
+
// `Model` record there (`JSON.stringify(model)` in its `models` command), and
|
|
323
|
+
// that record carries `variants`, keyed by name (SDK v2 `Model.variants`).
|
|
324
|
+
//
|
|
325
|
+
// WHY admission needs it: OpenCode accepts a variant the model does not have
|
|
326
|
+
// without an error, records it as given and runs at the model's default level
|
|
327
|
+
// (the L34 probe, OpenCode 1.19.5). A typo in a `models` entry's `effort`
|
|
328
|
+
// would bill the default and say nothing, so an effort is checked here before
|
|
329
|
+
// the run starts.
|
|
330
|
+
//
|
|
331
|
+
// listed the model is in the listing; `variants` may be empty, which
|
|
332
|
+
// means it has none to choose from;
|
|
333
|
+
// unavailable the listing could not be read (spawn error, timeout, non-zero
|
|
334
|
+
// exit, which includes OpenCode's "Provider not found"), or the
|
|
335
|
+
// model is not in it. `reason` says which, for the refusal.
|
|
336
|
+
export type ModelVariantsListing =
|
|
337
|
+
| { readonly kind: "listed"; readonly variants: readonly string[] }
|
|
338
|
+
| { readonly kind: "unavailable"; readonly reason: string };
|
|
339
|
+
|
|
340
|
+
export type ModelVariantsProbe = (
|
|
341
|
+
provider: string,
|
|
342
|
+
model: string,
|
|
343
|
+
) => Promise<ModelVariantsListing>;
|
|
344
|
+
|
|
345
|
+
// Never throws: every failure is `unavailable`, which admission refuses.
|
|
346
|
+
export function createModelVariantsProbe(options: {
|
|
347
|
+
readonly binaryPath: string;
|
|
348
|
+
readonly run?: IsFreeModelInput["run"];
|
|
349
|
+
readonly timeoutMs?: number;
|
|
350
|
+
}): ModelVariantsProbe {
|
|
351
|
+
// One listing per provider, however many of its models carry an effort.
|
|
352
|
+
const listings = new Map<
|
|
353
|
+
string,
|
|
354
|
+
Promise<FreeModelDiscoveryRunResult | string>
|
|
355
|
+
>();
|
|
356
|
+
const listingOf = (
|
|
357
|
+
provider: string,
|
|
358
|
+
): Promise<FreeModelDiscoveryRunResult | string> => {
|
|
359
|
+
const cached = listings.get(provider);
|
|
360
|
+
if (cached !== undefined) return cached;
|
|
361
|
+
const command = `opencode models ${provider}`;
|
|
362
|
+
const listing = (async () => {
|
|
363
|
+
if (!options.binaryPath.startsWith("/")) {
|
|
364
|
+
return `${command} could not run: no absolute OpenCode binary path`;
|
|
365
|
+
}
|
|
366
|
+
const run =
|
|
367
|
+
options.run ?? ((argv) => defaultRun(argv, options.timeoutMs));
|
|
368
|
+
try {
|
|
369
|
+
const result = await run([
|
|
370
|
+
options.binaryPath,
|
|
371
|
+
"models",
|
|
372
|
+
provider,
|
|
373
|
+
"--verbose",
|
|
374
|
+
"--refresh",
|
|
375
|
+
]);
|
|
376
|
+
return result.exitCode === 0
|
|
377
|
+
? result
|
|
378
|
+
: `${command} exited ${result.exitCode}`;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
381
|
+
// defaultRun's timeout names the free probe it was written for.
|
|
382
|
+
return /timed out/.test(detail)
|
|
383
|
+
? `${command} timed out`
|
|
384
|
+
: `${command} failed: ${detail}`;
|
|
385
|
+
}
|
|
386
|
+
})();
|
|
387
|
+
listings.set(provider, listing);
|
|
388
|
+
return listing;
|
|
389
|
+
};
|
|
390
|
+
return async (provider, model) => {
|
|
391
|
+
const listing = await listingOf(provider);
|
|
392
|
+
if (typeof listing === "string") {
|
|
393
|
+
return { kind: "unavailable", reason: listing };
|
|
394
|
+
}
|
|
395
|
+
const block = parseModelBlock(listing.stdout, provider, model);
|
|
396
|
+
if (typeof block !== "object" || block === null) {
|
|
397
|
+
return {
|
|
398
|
+
kind: "unavailable",
|
|
399
|
+
reason: `${provider}/${model} is not in opencode models ${provider}`,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
const variants = (block as Record<string, unknown>).variants;
|
|
403
|
+
return {
|
|
404
|
+
kind: "listed",
|
|
405
|
+
variants:
|
|
406
|
+
typeof variants === "object" && variants !== null
|
|
407
|
+
? Object.keys(variants)
|
|
408
|
+
: [],
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
}
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// The model names an operator writes, and the roles they are assigned to
|
|
2
|
+
// (odd/tasks/role-model-routing.md S1, S3).
|
|
3
|
+
//
|
|
4
|
+
// WHY a model name carries its backend in a prefix: the old routing keyed every
|
|
5
|
+
// assignment by a Claude alias (`sonnet`), so "which step" and "which model"
|
|
6
|
+
// were the same word, and a hunter could not get a model of its own. A name is
|
|
7
|
+
// now self-describing — `claude:<name>` runs on the Claude Code CLI,
|
|
8
|
+
// `opencode:<provider>/<model>` on OpenCode — and the role it is assigned to
|
|
9
|
+
// (`hunter.logic`, `summary`) is a separate key. How hard the model works is
|
|
10
|
+
// not part of its name: it is a list entry's `effort` (S7, below).
|
|
11
|
+
//
|
|
12
|
+
// WHY `-latest` and not the bare alias: Juanma, on "sonnet-latest": "explicito
|
|
13
|
+
// seria mas claro definitivamente". The Claude Code CLI aliases point to the
|
|
14
|
+
// newest version and move over time; a full `claude-*` id pins one
|
|
15
|
+
// (https://code.claude.com/docs/en/model-config: "Aliases point to the
|
|
16
|
+
// recommended version for your provider and update over time. To pin to a
|
|
17
|
+
// specific version, use the full model name"). A bare `claude:sonnet` is
|
|
18
|
+
// refused rather than guessed, so nobody reads it as a pin.
|
|
19
|
+
//
|
|
20
|
+
// Prompt frontmatter, the lab's PipelineInput.model and diversity models keep
|
|
21
|
+
// their bare aliases (`sonnet`): they are internal inputs, and
|
|
22
|
+
// `modelNameFromAlias` is the one place they become a model name.
|
|
23
|
+
|
|
24
|
+
import type { RunnerBackend } from "../execution/contracts";
|
|
25
|
+
import { looksLikeCredential, redactConfigValue } from "../security/redact";
|
|
26
|
+
import {
|
|
27
|
+
EFFORT_LEVELS,
|
|
28
|
+
isEffort,
|
|
29
|
+
isModelAlias,
|
|
30
|
+
type ModelAlias,
|
|
31
|
+
} from "./catalog";
|
|
32
|
+
|
|
33
|
+
export class ModelNameError extends Error {}
|
|
34
|
+
|
|
35
|
+
export interface ModelName {
|
|
36
|
+
// The name as written, e.g. `claude:sonnet-latest`.
|
|
37
|
+
readonly raw: string;
|
|
38
|
+
readonly backend: RunnerBackend;
|
|
39
|
+
readonly provider: string;
|
|
40
|
+
// What reaches the backend: the CLI alias (`sonnet`) or pinned id for
|
|
41
|
+
// Claude, the provider's model id for OpenCode.
|
|
42
|
+
readonly model: string;
|
|
43
|
+
// Set for the `-latest` names only.
|
|
44
|
+
readonly alias?: ModelAlias;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const CLAUDE_PREFIX = "claude:";
|
|
48
|
+
const OPENCODE_PREFIX = "opencode:";
|
|
49
|
+
const LATEST_SUFFIX = "-latest";
|
|
50
|
+
|
|
51
|
+
// A pinned Claude id: `claude-` and then lowercase letters, digits, dots and
|
|
52
|
+
// dashes (`claude-sonnet-5-5`, `claude-sonnet-4.5-20250929`).
|
|
53
|
+
const CLAUDE_ID_RE = /^claude-[a-z0-9.-]+$/;
|
|
54
|
+
// `provider/model`. The provider runs to the first slash; the model may hold
|
|
55
|
+
// more slashes, because some OpenCode providers (openrouter) name models as
|
|
56
|
+
// `vendor/model`.
|
|
57
|
+
const OPENCODE_RE =
|
|
58
|
+
/^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9._-]+(?:\/[a-zA-Z0-9._-]+)*)$/;
|
|
59
|
+
// An OpenCode variant name, which is what an OpenCode entry's effort becomes:
|
|
60
|
+
// provider-specific (Anthropic `high`/`max`, OpenAI `none`..`xhigh`, Google
|
|
61
|
+
// `low`/`high`, per https://opencode.ai/docs/models/ "Variants"), so the engine
|
|
62
|
+
// keeps no table of them and checks the shape only. The characters the removed
|
|
63
|
+
// `#variant` suffix allowed, with a length cap.
|
|
64
|
+
const OPENCODE_EFFORT_RE = /^[a-zA-Z0-9._-]{1,64}$/;
|
|
65
|
+
|
|
66
|
+
const CLAUDE_FORMS =
|
|
67
|
+
"claude:sonnet-latest, claude:opus-latest, claude:haiku-latest, claude:fable-latest or a full claude-* model name";
|
|
68
|
+
const OPENCODE_FORM = "opencode:<provider>/<model>";
|
|
69
|
+
|
|
70
|
+
// Every message quotes the name through redactConfigValue: a config value is
|
|
71
|
+
// echoed back to a terminal and a CI log, and a pasted key must not be.
|
|
72
|
+
function quoted(raw: string): string {
|
|
73
|
+
return `"${redactConfigValue(raw)}"`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A model name looks like a credential when the whole name does, any of its
|
|
77
|
+
// `:`/`/` segments does, or the text after any `:` or `/` does:
|
|
78
|
+
// `opencode:deepseek/<key>` parses as an OpenCode name, so a whole-value check
|
|
79
|
+
// alone would let it through, and a base64 key can itself contain `/`.
|
|
80
|
+
function nameLooksLikeCredential(raw: string): boolean {
|
|
81
|
+
const parts = raw.split(/[:/]/);
|
|
82
|
+
for (const [i, ch] of [...raw].entries()) {
|
|
83
|
+
if (ch === ":" || ch === "/") parts.push(raw.slice(i + 1));
|
|
84
|
+
}
|
|
85
|
+
return looksLikeCredential(raw) || parts.some(looksLikeCredential);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function parseClaudeName(raw: string, name: string): ModelName {
|
|
89
|
+
if (name.endsWith(LATEST_SUFFIX)) {
|
|
90
|
+
const alias = name.slice(0, -LATEST_SUFFIX.length);
|
|
91
|
+
if (isModelAlias(alias)) {
|
|
92
|
+
return {
|
|
93
|
+
raw,
|
|
94
|
+
backend: "claude-code",
|
|
95
|
+
provider: "anthropic",
|
|
96
|
+
model: alias,
|
|
97
|
+
alias,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (isModelAlias(name)) {
|
|
102
|
+
throw new ModelNameError(
|
|
103
|
+
`${quoted(raw)} is not a model name: write "claude:${name}-latest" for the newest ${name}, or a full name such as "claude-${name}-5-5" to pin a version`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (CLAUDE_ID_RE.test(name) && !name.endsWith("-")) {
|
|
107
|
+
return { raw, backend: "claude-code", provider: "anthropic", model: name };
|
|
108
|
+
}
|
|
109
|
+
throw new ModelNameError(
|
|
110
|
+
`${quoted(raw)} is not a Claude model name: use ${CLAUDE_FORMS}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parseOpenCodeName(raw: string, name: string): ModelName {
|
|
115
|
+
const match = name.match(OPENCODE_RE);
|
|
116
|
+
if (match === null) {
|
|
117
|
+
throw new ModelNameError(
|
|
118
|
+
`${quoted(raw)} is not an OpenCode model name: use ${OPENCODE_FORM}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const [, provider, model] = match;
|
|
122
|
+
return { raw, backend: "opencode", provider, model };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The removed `#variant` suffix (S7: "the old `#variant` suffix goes away so
|
|
126
|
+
// there is one concept"). Refused wherever a model is written (`models`,
|
|
127
|
+
// `--model`, the CI `model` input, a spec's model), and when the name before
|
|
128
|
+
// the `#` is a valid one the message is the entry to write instead.
|
|
129
|
+
function refuseVariantSuffix(raw: string): void {
|
|
130
|
+
const at = raw.indexOf("#");
|
|
131
|
+
if (at < 0) return;
|
|
132
|
+
const base = raw.slice(0, at);
|
|
133
|
+
const effort = raw.slice(at + 1);
|
|
134
|
+
if (!OPENCODE_EFFORT_RE.test(effort)) return;
|
|
135
|
+
try {
|
|
136
|
+
parseModelName(base);
|
|
137
|
+
} catch {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
throw new ModelNameError(
|
|
141
|
+
`${quoted(raw)}: the #variant suffix is gone: write {"model": ${JSON.stringify(base)}, "effort": ${JSON.stringify(effort)}} in models`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// A model name as an operator wrote it in `models`, `--model` or the CI input.
|
|
146
|
+
export function parseModelName(raw: string): ModelName {
|
|
147
|
+
if (typeof raw !== "string") {
|
|
148
|
+
throw new ModelNameError("a model name must be a string");
|
|
149
|
+
}
|
|
150
|
+
// The deny-list the old `routing` parser applied to its values, kept for
|
|
151
|
+
// the values that replaced them: the OpenCode grammar admits the characters
|
|
152
|
+
// of most API keys, so a key pasted as a model would otherwise parse.
|
|
153
|
+
if (nameLooksLikeCredential(raw)) {
|
|
154
|
+
throw new ModelNameError(
|
|
155
|
+
"a model name looks like a credential, and credentials are not permitted in models",
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
refuseVariantSuffix(raw);
|
|
159
|
+
if (raw.startsWith(CLAUDE_PREFIX)) {
|
|
160
|
+
return parseClaudeName(raw, raw.slice(CLAUDE_PREFIX.length));
|
|
161
|
+
}
|
|
162
|
+
if (raw.startsWith(OPENCODE_PREFIX)) {
|
|
163
|
+
return parseOpenCodeName(raw, raw.slice(OPENCODE_PREFIX.length));
|
|
164
|
+
}
|
|
165
|
+
if (isModelAlias(raw)) {
|
|
166
|
+
throw new ModelNameError(
|
|
167
|
+
`${quoted(raw)} is not a model name: write "claude:${raw}-latest"`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
throw new ModelNameError(
|
|
171
|
+
`${quoted(raw)} is not a model name: a model is "claude:<name>" or "${OPENCODE_FORM}"`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// THE one conversion point for internal inputs (prompt frontmatter, the lab's
|
|
176
|
+
// PipelineInput.model, diversity models): a bare alias means its `-latest`
|
|
177
|
+
// name, which is what the CLI ran for it before this change. Anything else must
|
|
178
|
+
// already be a full model name.
|
|
179
|
+
export function modelNameFromAlias(value: string): ModelName {
|
|
180
|
+
const trimmed = value.trim();
|
|
181
|
+
if (isModelAlias(trimmed)) {
|
|
182
|
+
return parseModelName(`${CLAUDE_PREFIX}${trimmed}${LATEST_SUFFIX}`);
|
|
183
|
+
}
|
|
184
|
+
return parseModelName(trimmed);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The roles a model can be assigned to (S1). `refuter` covers the verifier and
|
|
188
|
+
// the adjudicator too: the three judge one finding against the code, and the
|
|
189
|
+
// verifier and adjudicator run the refuter's prompt family. `judge` is the
|
|
190
|
+
// materiality judge. Hunters are open: `hunter.<key>` for any hunter key the
|
|
191
|
+
// review spec declares, checked against the spec when the plan is built.
|
|
192
|
+
export const FIXED_MODEL_ROLES = [
|
|
193
|
+
"default",
|
|
194
|
+
"consolidate",
|
|
195
|
+
"scout",
|
|
196
|
+
"judge",
|
|
197
|
+
"refuter",
|
|
198
|
+
"summary",
|
|
199
|
+
] as const;
|
|
200
|
+
export type FixedModelRole = (typeof FIXED_MODEL_ROLES)[number];
|
|
201
|
+
|
|
202
|
+
const HUNTER_ROLE_PREFIX = "hunter.";
|
|
203
|
+
// The same slug validateReviewSpec requires of an agent key.
|
|
204
|
+
const HUNTER_KEY_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
205
|
+
|
|
206
|
+
export function hunterRole(key: string): string {
|
|
207
|
+
return `${HUNTER_ROLE_PREFIX}${key}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function isModelRole(value: string): boolean {
|
|
211
|
+
if ((FIXED_MODEL_ROLES as readonly string[]).includes(value)) return true;
|
|
212
|
+
if (!value.startsWith(HUNTER_ROLE_PREFIX)) return false;
|
|
213
|
+
const key = value.slice(HUNTER_ROLE_PREFIX.length);
|
|
214
|
+
return key.length <= 64 && HUNTER_KEY_RE.test(key);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// At most three per role (L6 item 7): a fallback chain longer than that is a
|
|
218
|
+
// bill nobody planned, and the next model is tried only on provider failures.
|
|
219
|
+
export const MAX_MODELS_PER_ROLE = 3;
|
|
220
|
+
|
|
221
|
+
// A `models` list entry as written (S7): a model name, or the name with how
|
|
222
|
+
// hard it works, `{"model": "claude:opus-latest", "effort": "max"}`. Kept as
|
|
223
|
+
// written, so a config read and written back is unchanged; readers go through
|
|
224
|
+
// modelEntry, so a string and an object with no effort read the same.
|
|
225
|
+
export type ModelListEntry =
|
|
226
|
+
| string
|
|
227
|
+
| { readonly model: string; readonly effort?: string };
|
|
228
|
+
|
|
229
|
+
// An entry as every reader sees it.
|
|
230
|
+
export interface ModelEntry {
|
|
231
|
+
readonly name: string;
|
|
232
|
+
readonly effort?: string;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function modelEntry(entry: ModelListEntry): ModelEntry {
|
|
236
|
+
if (typeof entry === "string") return { name: entry };
|
|
237
|
+
return entry.effort === undefined
|
|
238
|
+
? { name: entry.model }
|
|
239
|
+
: { name: entry.model, effort: entry.effort };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const ENTRY_KEYS = ["model", "effort"];
|
|
243
|
+
const ENTRY_FORM = '{"model": "<name>", "effort": "<level>"}';
|
|
244
|
+
// `--effort ultracode` is not a level: on the Claude Code CLI it also turns on
|
|
245
|
+
// workflow orchestration and runs at xhigh
|
|
246
|
+
// (https://code.claude.com/docs/en/model-config "Adjust effort level"). A review
|
|
247
|
+
// step is one bounded turn, so it is refused by name rather than with the list.
|
|
248
|
+
const ULTRACODE = "ultracode";
|
|
249
|
+
|
|
250
|
+
function levelList(): string {
|
|
251
|
+
return `${EFFORT_LEVELS.slice(0, -1).join(", ")} or ${EFFORT_LEVELS.at(-1)}`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The effort an entry sets, checked against the backend its model runs on.
|
|
255
|
+
// Claude: the CLI's `--effort` vocabulary, closed. OpenCode: a variant name,
|
|
256
|
+
// open (OPENCODE_EFFORT_RE), and run through the same credential check as a
|
|
257
|
+
// model name, because its grammar admits the characters of most API keys.
|
|
258
|
+
function checkEffort(effort: unknown, name: ModelName, at: string): string {
|
|
259
|
+
if (typeof effort !== "string") {
|
|
260
|
+
throw new ModelNameError(`${at}: effort must be a string`);
|
|
261
|
+
}
|
|
262
|
+
if (looksLikeCredential(effort)) {
|
|
263
|
+
throw new ModelNameError(
|
|
264
|
+
`${at}: the effort looks like a credential, and credentials are not permitted in models`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
if (name.backend === "claude-code") {
|
|
268
|
+
if (effort === ULTRACODE) {
|
|
269
|
+
throw new ModelNameError(
|
|
270
|
+
`${at}: effort "${ULTRACODE}" is not an effort level: on the Claude Code CLI it also turns on workflow orchestration. Write "xhigh" for its effort level`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
if (!isEffort(effort)) {
|
|
274
|
+
throw new ModelNameError(
|
|
275
|
+
`${at}: effort ${quoted(effort)} is not a Claude effort level: use ${levelList()}`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
return effort;
|
|
279
|
+
}
|
|
280
|
+
if (!OPENCODE_EFFORT_RE.test(effort)) {
|
|
281
|
+
throw new ModelNameError(
|
|
282
|
+
`${at}: effort ${quoted(effort)} is not an OpenCode variant name: use letters, digits, ".", "_" and "-", at most 64 characters`,
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
return effort;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function parseModelEntry(
|
|
289
|
+
value: unknown,
|
|
290
|
+
at: string,
|
|
291
|
+
effortAllowed: string | undefined,
|
|
292
|
+
): ModelListEntry {
|
|
293
|
+
if (typeof value === "string") {
|
|
294
|
+
try {
|
|
295
|
+
parseModelName(value);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
throw new ModelNameError(`${at}: ${(error as Error).message}`);
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
302
|
+
throw new ModelNameError(`${at} must be a model name or ${ENTRY_FORM}`);
|
|
303
|
+
}
|
|
304
|
+
const record = value as Record<string, unknown>;
|
|
305
|
+
for (const key of Object.keys(record)) {
|
|
306
|
+
if (!ENTRY_KEYS.includes(key)) {
|
|
307
|
+
throw new ModelNameError(
|
|
308
|
+
`${at} has an unknown key ${quoted(key)}: an entry takes model and effort`,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (record.model === undefined) {
|
|
313
|
+
throw new ModelNameError(`${at} needs a "model"`);
|
|
314
|
+
}
|
|
315
|
+
let name: ModelName;
|
|
316
|
+
try {
|
|
317
|
+
name = parseModelName(record.model as string);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
throw new ModelNameError(`${at}: ${(error as Error).message}`);
|
|
320
|
+
}
|
|
321
|
+
if (record.effort === undefined) return { model: name.raw };
|
|
322
|
+
if (effortAllowed !== undefined) {
|
|
323
|
+
throw new ModelNameError(`${at} sets an effort: ${effortAllowed}`);
|
|
324
|
+
}
|
|
325
|
+
return { model: name.raw, effort: checkEffort(record.effort, name, at) };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// One role's list: non-empty, no repeats, at most three, every entry valid.
|
|
329
|
+
// Kept as the operator wrote it, so a config round-trips unchanged. A model
|
|
330
|
+
// named twice is refused even with two efforts (D2): the second would run only
|
|
331
|
+
// when the first fails, and a provider failure does not depend on effort.
|
|
332
|
+
export function parseModelList(
|
|
333
|
+
value: unknown,
|
|
334
|
+
where: string,
|
|
335
|
+
// Why this list takes no effort, when it takes none (`models.judge`).
|
|
336
|
+
noEffortReason?: string,
|
|
337
|
+
): ModelListEntry[] {
|
|
338
|
+
if (!Array.isArray(value)) {
|
|
339
|
+
throw new ModelNameError(`${where} must be a list of models`);
|
|
340
|
+
}
|
|
341
|
+
if (value.length === 0) {
|
|
342
|
+
throw new ModelNameError(`${where} must list at least one model`);
|
|
343
|
+
}
|
|
344
|
+
if (value.length > MAX_MODELS_PER_ROLE) {
|
|
345
|
+
throw new ModelNameError(
|
|
346
|
+
`${where} lists ${value.length} models: at most ${MAX_MODELS_PER_ROLE} are allowed`,
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const seen = new Set<string>();
|
|
350
|
+
const result: ModelListEntry[] = [];
|
|
351
|
+
for (const [i, value_] of value.entries()) {
|
|
352
|
+
const entry = parseModelEntry(value_, `${where}[${i}]`, noEffortReason);
|
|
353
|
+
const { name } = modelEntry(entry);
|
|
354
|
+
if (seen.has(name)) {
|
|
355
|
+
throw new ModelNameError(`${where} lists ${quoted(name)} twice`);
|
|
356
|
+
}
|
|
357
|
+
seen.add(name);
|
|
358
|
+
result.push(entry);
|
|
359
|
+
}
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export type ModelsConfig = Readonly<Record<string, readonly ModelListEntry[]>>;
|
|
364
|
+
|
|
365
|
+
// D3: the judge was measured on its prompt's own effort; a different one is
|
|
366
|
+
// a different, unmeasured judge (see MEASURED_JUDGE_MODELS in routing.ts).
|
|
367
|
+
const JUDGE_NO_EFFORT =
|
|
368
|
+
"the materiality judge runs at the effort it was measured at, so models.judge takes model names only";
|
|
369
|
+
|
|
370
|
+
const ROLE_LIST =
|
|
371
|
+
"default, hunter.<key>, consolidate, scout, judge, refuter, summary";
|
|
372
|
+
|
|
373
|
+
export function parseModelsConfig(value: unknown): ModelsConfig {
|
|
374
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
375
|
+
throw new ModelNameError(
|
|
376
|
+
"models must be an object from role to a list of models",
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
const result: Record<string, ModelListEntry[]> = {};
|
|
380
|
+
for (const [role, list] of Object.entries(value)) {
|
|
381
|
+
if (!isModelRole(role)) {
|
|
382
|
+
throw new ModelNameError(
|
|
383
|
+
`models has an unknown role ${quoted(role)}: roles are ${ROLE_LIST}`,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
result[role] = parseModelList(
|
|
387
|
+
list,
|
|
388
|
+
`models.${role}`,
|
|
389
|
+
role === "judge" ? JUDGE_NO_EFFORT : undefined,
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Whether any configured model runs on OpenCode, so the OpenCode SDK must be
|
|
396
|
+
// installed. Replaces the old routing check, read by `crysk doctor`,
|
|
397
|
+
// `crysk upgrade --reconcile` and the platform connect step: without it an
|
|
398
|
+
// OpenCode user would silently lose the SDK install.
|
|
399
|
+
export function modelsNeedOpenCode(models: ModelsConfig | undefined): boolean {
|
|
400
|
+
if (models === undefined) return false;
|
|
401
|
+
return Object.values(models).some((list) =>
|
|
402
|
+
list.some((entry) => modelEntry(entry).name.startsWith(OPENCODE_PREFIX)),
|
|
403
|
+
);
|
|
404
|
+
}
|
|
@@ -461,7 +461,9 @@ export function claudeCredentialProjectionReady(
|
|
|
461
461
|
// — pr-hero found its own gate refusing exactly that machine class) and the
|
|
462
462
|
// Linux-style ~/.claude/.credentials.json. The default probe never spawns
|
|
463
463
|
// claude; the keychain query is metadata-only (no -w), proven non-interactive.
|
|
464
|
-
|
|
464
|
+
// Exported for the run's login probe (security/claude-credential.ts), which asks
|
|
465
|
+
// the same question: is there a Keychain item the broker could project.
|
|
466
|
+
export function defaultKeychainCredentialPresent(): boolean {
|
|
465
467
|
return (
|
|
466
468
|
Bun.spawnSync([
|
|
467
469
|
"/usr/bin/security",
|
|
@@ -472,16 +474,29 @@ function defaultKeychainCredentialPresent(): boolean {
|
|
|
472
474
|
);
|
|
473
475
|
}
|
|
474
476
|
|
|
475
|
-
// The on-disk Claude
|
|
477
|
+
// The on-disk Claude login the default probe accepts, relative to HOME: the
|
|
478
|
+
// CLI's OAuth store. `~/.claude.json` and `~/.claude/session.json` are not a
|
|
479
|
+
// credential (U2: every Claude user has the first, API-key users included).
|
|
476
480
|
// Exported because src/ci/trigger.ts must reach the same verdict before
|
|
477
481
|
// `bun install` and so keeps its own copy (it may import only builtins); a
|
|
478
482
|
// drift test in test/ci/trigger.test.ts pins that copy to this list.
|
|
479
483
|
export const CLAUDE_SESSION_FILES: readonly string[] = [
|
|
480
|
-
".claude.json",
|
|
481
|
-
path.join(".claude", "session.json"),
|
|
482
484
|
path.join(".claude", ".credentials.json"),
|
|
483
485
|
];
|
|
484
486
|
|
|
487
|
+
// U2's rule, claudeCredentialPresence in src/security/claude-credential.ts: a
|
|
488
|
+
// subscription from CRYSK_CLAUDE_OAUTH_TOKEN, CLAUDE_CODE_OAUTH_TOKEN or a login, an
|
|
489
|
+
// API key from CRYSK_CLAUDE_API_KEY or ANTHROPIC_API_KEY, each trimmed; never
|
|
490
|
+
// ANTHROPIC_AUTH_TOKEN. A copy, because that module imports this one and a value
|
|
491
|
+
// import back would be a cycle (test/architecture/cycles.test.ts); a test in
|
|
492
|
+
// test/model/provider-capabilities.test.ts pins the two equal.
|
|
493
|
+
const CLAUDE_CREDENTIAL_ENV: readonly string[] = [
|
|
494
|
+
"CRYSK_CLAUDE_OAUTH_TOKEN",
|
|
495
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
496
|
+
"CRYSK_CLAUDE_API_KEY",
|
|
497
|
+
"ANTHROPIC_API_KEY",
|
|
498
|
+
];
|
|
499
|
+
|
|
485
500
|
function defaultClaudeAuthProbe(
|
|
486
501
|
env: Record<string, string | undefined>,
|
|
487
502
|
home: string,
|
|
@@ -489,9 +504,9 @@ function defaultClaudeAuthProbe(
|
|
|
489
504
|
platform: NodeJS.Platform,
|
|
490
505
|
keychainProbe: () => boolean,
|
|
491
506
|
): "passed" | "failed" {
|
|
492
|
-
const hasToken =
|
|
493
|
-
Boolean(env
|
|
494
|
-
|
|
507
|
+
const hasToken = CLAUDE_CREDENTIAL_ENV.some((name) =>
|
|
508
|
+
Boolean(env[name]?.trim()),
|
|
509
|
+
);
|
|
495
510
|
if (hasToken) return "passed";
|
|
496
511
|
const hasSessionFile = CLAUDE_SESSION_FILES.some((file) =>
|
|
497
512
|
exists(path.join(home, file)),
|