crysk 0.5.1 → 0.6.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.
- package/README.md +2 -1
- package/package.json +3 -2
- package/skills/crysk-ci-setup/assets/workflow.yml +3 -0
- package/src/asset-manifest.ts +11 -0
- package/src/assets.ts +1 -1
- package/src/ci/credential-refresh.ts +524 -0
- package/src/ci/crysk-secrets.ts +20 -6
- package/src/ci/outcome.ts +165 -15
- package/src/ci/platform.ts +155 -7
- package/src/ci/setup.ts +64 -6
- package/src/ci/trigger.ts +20 -4
- package/src/commands/ci-setup.ts +12 -3
- package/src/commands/doctor.ts +25 -23
- package/src/diversity/identity.ts +11 -1
- package/src/diversity/pipeline-integration.ts +19 -6
- package/src/doctor.ts +133 -4
- package/src/execution/contracts.ts +15 -3
- package/src/harness/materiality-judge.ts +153 -0
- package/src/harness/pipeline-plan.ts +133 -0
- package/src/harness/replay-rows.ts +172 -0
- package/src/harness/route-runner.ts +288 -0
- package/src/harness/single-step.ts +153 -0
- package/src/index.ts +1 -1
- package/src/model/catalog.ts +10 -7
- package/src/model/model-name.ts +14 -0
- package/src/model/profiles/claude.ts +34 -0
- package/src/model/profiles/openai.ts +44 -0
- package/src/model/profiles.ts +213 -0
- package/src/model/routing.ts +155 -50
- package/src/pr/plan.ts +6 -1
- package/src/pr/review-pr.ts +32 -6
- package/src/pr/target.ts +16 -7
- package/src/production-runtime.ts +100 -13
- package/src/review/pipeline.ts +193 -58
- package/src/review/preflight.ts +91 -9
- package/src/review/prompt-set.ts +68 -0
- package/src/review/review.ts +21 -11
- package/src/review/route-preflight.ts +117 -67
- package/src/review/run.ts +34 -4
- package/src/security/credential-broker.ts +21 -9
- package/src/security/oauth-providers.ts +101 -0
- package/src/transport-registry.ts +33 -0
- package/src/transports/opencode-sdk.ts +33 -1
- package/src/ui/config-edit.ts +9 -0
- package/src/ui/config.ts +1 -0
- package/src/ui/menu.ts +9 -2
- package/src/updater.ts +21 -13
- package/src/wizard.ts +23 -0
package/src/review/run.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
notionalCostInput,
|
|
23
23
|
} from "#config/config";
|
|
24
24
|
import type { ModelsConfig } from "#model/model-name";
|
|
25
|
+
import { type ModelProfile, resolveProfile } from "#model/profiles";
|
|
25
26
|
import type { ResolvedRoutePlan } from "#model/routing";
|
|
26
27
|
import type { CiMode } from "#pr/preflight";
|
|
27
28
|
import {
|
|
@@ -117,6 +118,10 @@ export interface LoadedRunConfig {
|
|
|
117
118
|
summary: SummarySettings;
|
|
118
119
|
scout: boolean;
|
|
119
120
|
post: boolean;
|
|
121
|
+
// The run's model profile, resolved once here from `config.profile`
|
|
122
|
+
// (openai-profile S3). Every route, prompt and pipeline input of the run
|
|
123
|
+
// reads this one value.
|
|
124
|
+
profile: ModelProfile;
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
// Config load + the three per-run resolvers read right after it: identical
|
|
@@ -148,7 +153,8 @@ export async function loadRunConfig(params: {
|
|
|
148
153
|
const summary = resolveSummary(params.options, config);
|
|
149
154
|
const scout = resolveScout(params.options, config);
|
|
150
155
|
const post = resolvePost(params.options, config);
|
|
151
|
-
|
|
156
|
+
const profile = resolveProfile(config.profile);
|
|
157
|
+
return { loaded, config, summary, scout, post, profile };
|
|
152
158
|
}
|
|
153
159
|
|
|
154
160
|
// Shared range guard. Both orchestrators check the same thing right after
|
|
@@ -450,8 +456,14 @@ export interface ResolvedPromptSet {
|
|
|
450
456
|
export async function resolvePromptSet(
|
|
451
457
|
options: Pick<CliOptions, "agents">,
|
|
452
458
|
loaded: EffectiveConfig,
|
|
459
|
+
// The run's profile (openai-profile S3), whose prompt set the agents come
|
|
460
|
+
// from (model-profiles S4). Required, so no caller reads the fallback's set
|
|
461
|
+
// by forgetting it; tests may add `promptSets`.
|
|
462
|
+
prompts: NonNullable<Parameters<typeof resolveAgentsDir>[3]> & {
|
|
463
|
+
profile: ModelProfile;
|
|
464
|
+
},
|
|
453
465
|
): Promise<ResolvedPromptSet> {
|
|
454
|
-
const agents = resolveAgentsDir(options, loaded);
|
|
466
|
+
const agents = resolveAgentsDir(options, loaded, undefined, prompts);
|
|
455
467
|
const spec = validateReviewSpec(localReviewSpec());
|
|
456
468
|
spec.agents.forEach((agent, i) => {
|
|
457
469
|
assertBasenameOnly(agent.file, i);
|
|
@@ -487,8 +499,10 @@ export async function resolvePromptSet(
|
|
|
487
499
|
spec.agents.map((a) => agentFilePath(agents, a.file)),
|
|
488
500
|
// A bundled set has no directory basename to be named after. "default"
|
|
489
501
|
// is what dev and npm derive from prompts/default, so the same prompt
|
|
490
|
-
// set names itself identically in all three runtimes.
|
|
491
|
-
|
|
502
|
+
// set names itself identically in all three runtimes. A profile's prompt
|
|
503
|
+
// set merged over it (model-profiles S4) is named after that set, the way
|
|
504
|
+
// a person's set is named after its directory.
|
|
505
|
+
agents.promptSet ?? (agents.kind === "bundled" ? "default" : undefined),
|
|
492
506
|
);
|
|
493
507
|
return { agents, spec, agentFiles, promptSet };
|
|
494
508
|
}
|
|
@@ -509,6 +523,16 @@ export async function writeMcpConfig(
|
|
|
509
523
|
);
|
|
510
524
|
}
|
|
511
525
|
|
|
526
|
+
// Whether the person chose the routing (openai-profile S5): `models` or a
|
|
527
|
+
// `profile`. Either one makes a route plan that fails to build fatal, rather
|
|
528
|
+
// than a fallback to the no-plan run, which runs the fallback profile's
|
|
529
|
+
// models: a person who chose a profile must never get another one silently.
|
|
530
|
+
export function routingConfigured(
|
|
531
|
+
config: Pick<LocalConfig, "models" | "profile">,
|
|
532
|
+
): boolean {
|
|
533
|
+
return config.models !== undefined || config.profile !== undefined;
|
|
534
|
+
}
|
|
535
|
+
|
|
512
536
|
// Production route resolution: identical in both orchestrators except the
|
|
513
537
|
// workspace root and (reviewPr()'s skipped-discovery re-review only) the
|
|
514
538
|
// summarizer/scout enable overrides. Named distinctly from
|
|
@@ -521,7 +545,11 @@ export async function resolvePipelineRoute(params: {
|
|
|
521
545
|
spec: ReviewSpec;
|
|
522
546
|
options: CliOptions;
|
|
523
547
|
agentFiles: Map<string, ParsedAgent>;
|
|
548
|
+
// isBundledAgentsDir (#review/route-preflight) of the run's agents.
|
|
549
|
+
bundledAgents: boolean;
|
|
524
550
|
models: ModelsConfig | undefined;
|
|
551
|
+
// The run's profile, resolved once from the config (openai-profile S3).
|
|
552
|
+
profile: ModelProfile;
|
|
525
553
|
summary: SummarySettings;
|
|
526
554
|
summarizerEnabled?: boolean;
|
|
527
555
|
scoutEnabled?: boolean;
|
|
@@ -545,7 +573,9 @@ export async function resolvePipelineRoute(params: {
|
|
|
545
573
|
spec: params.spec,
|
|
546
574
|
options: params.options,
|
|
547
575
|
agentFiles: params.agentFiles,
|
|
576
|
+
bundledAgents: params.bundledAgents,
|
|
548
577
|
models: params.models,
|
|
578
|
+
profile: params.profile,
|
|
549
579
|
summary: params.summary,
|
|
550
580
|
summarizerEnabled: params.summarizerEnabled,
|
|
551
581
|
scoutEnabled: params.scoutEnabled,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { homedir, tmpdir } from "node:os";
|
|
17
17
|
import path from "node:path";
|
|
18
18
|
import type { CredentialKind } from "#model/provider-capabilities";
|
|
19
|
+
import { recordExpiresAt, reviewCopyOfRecord } from "./oauth-providers";
|
|
19
20
|
|
|
20
21
|
export type CredentialProjectionFile = {
|
|
21
22
|
readonly path: string;
|
|
@@ -76,7 +77,11 @@ export type CredentialProjectionFailureClass =
|
|
|
76
77
|
// whatever provider keys happen to be ambient. It falls into the
|
|
77
78
|
// fail-closed branch there, and must stay there.
|
|
78
79
|
| "missing_provider_record"
|
|
79
|
-
| "projection_layout_invalid"
|
|
80
|
+
| "projection_layout_invalid"
|
|
81
|
+
// A subscription login whose access token has expired (the broker) or expires
|
|
82
|
+
// within the review (admission, REVIEW_EXPIRY_MARGIN_MS). A review never renews
|
|
83
|
+
// a rotating provider's login itself (oauth-providers.ts).
|
|
84
|
+
| "subscription_expiring";
|
|
80
85
|
|
|
81
86
|
export class CredentialProjectionError extends Error {
|
|
82
87
|
readonly failureClass: CredentialProjectionFailureClass;
|
|
@@ -390,11 +395,18 @@ export class OpenCodeAuthBroker implements CredentialBroker {
|
|
|
390
395
|
if (!lookup.ok) {
|
|
391
396
|
throw new CredentialProjectionError(lookup.failureClass);
|
|
392
397
|
}
|
|
398
|
+
// Admission refuses a login that would expire during the review; this is the
|
|
399
|
+
// last word for a step that starts after it already has, so the child never
|
|
400
|
+
// tries to renew it with the emptied refresh token.
|
|
401
|
+
const expiresAt = recordExpiresAt(lookup.record);
|
|
402
|
+
if (expiresAt !== undefined && expiresAt <= Date.now()) {
|
|
403
|
+
throw new CredentialProjectionError("subscription_expiring");
|
|
404
|
+
}
|
|
393
405
|
|
|
394
406
|
return buildOpenCodeProjection(
|
|
395
407
|
input.kind,
|
|
396
408
|
OPENCODE_OAUTH_PROVIDER,
|
|
397
|
-
lookup.record,
|
|
409
|
+
reviewCopyOfRecord(OPENCODE_OAUTH_PROVIDER, lookup.record),
|
|
398
410
|
);
|
|
399
411
|
}
|
|
400
412
|
}
|
|
@@ -469,13 +481,13 @@ function buildOpenCodeProjection(
|
|
|
469
481
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
470
482
|
}
|
|
471
483
|
|
|
472
|
-
// The record travels
|
|
473
|
-
//
|
|
474
|
-
//
|
|
475
|
-
//
|
|
476
|
-
//
|
|
477
|
-
// the
|
|
478
|
-
//
|
|
484
|
+
// The record travels in the store's own shape, which is what OpenCode reads;
|
|
485
|
+
// reconstructing a subset here would be a second, silently drifting schema. The
|
|
486
|
+
// one change is made before this call, by the OAuth broker: a rotating
|
|
487
|
+
// provider's refresh token is emptied (reviewCopyOfRecord, oauth-providers.ts),
|
|
488
|
+
// because this copy is deleted after the run and a token renewed into it would
|
|
489
|
+
// spend the stored chain for nothing. The login is renewed by the Crysk
|
|
490
|
+
// platform's refresher, never by a review.
|
|
479
491
|
const payload = `${JSON.stringify({ [provider]: record }, null, 2)}\n`;
|
|
480
492
|
writeFileSync(layout.authFile, payload, { mode: 0o600 });
|
|
481
493
|
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// OAuth subscription providers, one descriptor each (cryskai/platform
|
|
2
|
+
// odd/tasks/openai-oauth.md, "Provider-generic"). Behavior that differs by
|
|
3
|
+
// provider is read from here, never branched on a provider name, so a provider
|
|
4
|
+
// that behaves like OpenAI is one more entry. The Crysk platform keeps the same
|
|
5
|
+
// table in packages/core/src/oauth-providers.ts.
|
|
6
|
+
//
|
|
7
|
+
// WHY no imports: the steps that run before `bun install` (the trigger, the
|
|
8
|
+
// connect step) may read it, and they are limited to runtime builtins.
|
|
9
|
+
|
|
10
|
+
export interface OAuthProviderDescriptor {
|
|
11
|
+
// The OpenCode provider id, the key of its record in auth.json.
|
|
12
|
+
readonly id: string;
|
|
13
|
+
// Whether the provider issues a new refresh token on every refresh and refuses
|
|
14
|
+
// the old one afterwards (OpenAI answers `refresh_token_reused`). A review never
|
|
15
|
+
// holds such a provider's refresh token: renewing it inside a run would spend
|
|
16
|
+
// the stored chain and throw the new token away with the run's copy.
|
|
17
|
+
readonly rotatesRefreshToken: boolean;
|
|
18
|
+
// How the runner-side refresher renews the login (src/ci/credential-refresh.ts):
|
|
19
|
+
// an RFC 6749 `grant_type=refresh_token` POST, form-encoded, to `tokenUrl` with
|
|
20
|
+
// `client_id` and any `extraParams`.
|
|
21
|
+
readonly refresh: {
|
|
22
|
+
readonly tokenUrl: string;
|
|
23
|
+
readonly clientId: string;
|
|
24
|
+
readonly extraParams?: Readonly<Record<string, string>>;
|
|
25
|
+
};
|
|
26
|
+
// The provider error codes that mean the login is gone and the person must log
|
|
27
|
+
// in again. Read from the token endpoint's error body (a string `error`, an
|
|
28
|
+
// `error.code`, or a top-level `code`). Any other error is not permanent.
|
|
29
|
+
readonly permanentErrors: readonly string[];
|
|
30
|
+
// Where the record's account id comes from, or undefined when the provider has
|
|
31
|
+
// none. The id is read from the JWT claims of the token response's `tokens`,
|
|
32
|
+
// in order, trying each claim path in order; when none answers, the stored
|
|
33
|
+
// record's `recordField` is kept.
|
|
34
|
+
readonly accountId?: {
|
|
35
|
+
readonly recordField: string;
|
|
36
|
+
readonly tokens: readonly string[];
|
|
37
|
+
readonly claims: readonly (readonly (string | number)[])[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// OpenAI's values are OpenCode's (v1.18.30,
|
|
42
|
+
// packages/opencode/src/plugin/openai/codex.ts: CLIENT_ID, refreshAccessToken,
|
|
43
|
+
// extractAccountIdFromClaims), so the refresher renews the login exactly as
|
|
44
|
+
// OpenCode itself would. The error codes are Codex's permanent refresh failures
|
|
45
|
+
// plus the standard OAuth `invalid_grant`.
|
|
46
|
+
export const OAUTH_PROVIDERS: readonly OAuthProviderDescriptor[] = [
|
|
47
|
+
{
|
|
48
|
+
id: "openai",
|
|
49
|
+
rotatesRefreshToken: true,
|
|
50
|
+
refresh: {
|
|
51
|
+
tokenUrl: "https://auth.openai.com/oauth/token",
|
|
52
|
+
clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
53
|
+
},
|
|
54
|
+
permanentErrors: [
|
|
55
|
+
"refresh_token_reused",
|
|
56
|
+
"refresh_token_expired",
|
|
57
|
+
"refresh_token_invalidated",
|
|
58
|
+
"invalid_grant",
|
|
59
|
+
],
|
|
60
|
+
accountId: {
|
|
61
|
+
recordField: "accountId",
|
|
62
|
+
tokens: ["id_token", "access_token"],
|
|
63
|
+
claims: [
|
|
64
|
+
["chatgpt_account_id"],
|
|
65
|
+
["https://api.openai.com/auth", "chatgpt_account_id"],
|
|
66
|
+
["organizations", 0, "id"],
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
export function oauthProvider(id: string): OAuthProviderDescriptor | undefined {
|
|
73
|
+
return OAUTH_PROVIDERS.find((provider) => provider.id === id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// A review refuses to start on a login whose access token expires within this
|
|
77
|
+
// margin. The longest review observed takes about 25 minutes; OpenAI's tokens
|
|
78
|
+
// live 240 hours, and the platform renews them at 80% of that.
|
|
79
|
+
export const REVIEW_EXPIRY_MARGIN_MS = 2 * 60 * 60 * 1000;
|
|
80
|
+
|
|
81
|
+
// The record's own expiry, in milliseconds since the epoch, or undefined when it
|
|
82
|
+
// states none. OpenCode's OAuth record keeps it as `expires`.
|
|
83
|
+
export function recordExpiresAt(record: unknown): number | undefined {
|
|
84
|
+
if (typeof record !== "object" || record === null) return undefined;
|
|
85
|
+
const expires = (record as Record<string, unknown>).expires;
|
|
86
|
+
return typeof expires === "number" && Number.isFinite(expires)
|
|
87
|
+
? expires
|
|
88
|
+
: undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// The copy of a record a review may hold: for a rotating provider, every field
|
|
92
|
+
// but the refresh token, emptied. OpenCode's schema accepts "" and reads it only
|
|
93
|
+
// once the access token has expired, and then fails instead of rotating.
|
|
94
|
+
export function reviewCopyOfRecord<T extends object>(
|
|
95
|
+
providerId: string,
|
|
96
|
+
record: T,
|
|
97
|
+
): T {
|
|
98
|
+
if (oauthProvider(providerId)?.rotatesRefreshToken !== true) return record;
|
|
99
|
+
if (!("refresh" in record)) return record;
|
|
100
|
+
return { ...record, refresh: "" };
|
|
101
|
+
}
|
|
@@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { opencodeSecretName } from "#ci/crysk-secrets";
|
|
5
6
|
import { capabilityGateDecision } from "#model/provider-capabilities";
|
|
6
7
|
import {
|
|
7
8
|
planRoutes,
|
|
@@ -15,6 +16,7 @@ import { type AssetMode, detectAssetMode } from "./assets";
|
|
|
15
16
|
// step timeout and calls destroy on credential projection after transport returns).
|
|
16
17
|
import type {
|
|
17
18
|
CredentialKind,
|
|
19
|
+
OpenCodeFailureCredential,
|
|
18
20
|
ProviderCapabilityReport,
|
|
19
21
|
ProviderTransport,
|
|
20
22
|
ResolvedModelRoute,
|
|
@@ -544,6 +546,27 @@ export interface CreateTransportRegistryOptions
|
|
|
544
546
|
readonly mode?: "production" | "conformance";
|
|
545
547
|
}
|
|
546
548
|
|
|
549
|
+
// S7: the CRYSK_OPENCODE_* secret an OpenCode route runs on, as a failed attempt names
|
|
550
|
+
// it. The kind decides the name the way chooseOpenCodeSecret decided the kind: the
|
|
551
|
+
// ChatGPT OAuth kind is the `_OAUTH` record, a metered token the `_API_KEY`. A free
|
|
552
|
+
// route runs on no secret, and an unknown kind or provider names none rather than guess.
|
|
553
|
+
export function openCodeFailureCredential(
|
|
554
|
+
provider: string | undefined,
|
|
555
|
+
kind: CredentialKind | undefined,
|
|
556
|
+
): OpenCodeFailureCredential | undefined {
|
|
557
|
+
if (provider === undefined) return undefined;
|
|
558
|
+
const secretKind =
|
|
559
|
+
kind === "opencode_chatgpt_oauth"
|
|
560
|
+
? "oauth"
|
|
561
|
+
: kind === "provider_api_token"
|
|
562
|
+
? "api_key"
|
|
563
|
+
: undefined;
|
|
564
|
+
if (secretKind === undefined) return undefined;
|
|
565
|
+
return opencodeSecretName(provider, secretKind) as
|
|
566
|
+
| OpenCodeFailureCredential
|
|
567
|
+
| undefined;
|
|
568
|
+
}
|
|
569
|
+
|
|
547
570
|
export class DefaultTransportRegistry implements TransportRegistry {
|
|
548
571
|
private readonly factories = new Map<
|
|
549
572
|
RunnerBackend,
|
|
@@ -672,6 +695,14 @@ export class DefaultTransportRegistry implements TransportRegistry {
|
|
|
672
695
|
provider: route?.provider ?? "opencode",
|
|
673
696
|
};
|
|
674
697
|
const defaultRoute: ResolvedModelRoute | undefined = route;
|
|
698
|
+
// S7: the secret this route runs on, from the same kind the billing mode reads,
|
|
699
|
+
// computed above both construction branches for the same reason.
|
|
700
|
+
const failureCredential = openCodeFailureCredential(
|
|
701
|
+
route?.provider,
|
|
702
|
+
merged.credentialKind,
|
|
703
|
+
);
|
|
704
|
+
const credentialOption =
|
|
705
|
+
failureCredential === undefined ? {} : { failureCredential };
|
|
675
706
|
|
|
676
707
|
if (merged.openCodeClient) {
|
|
677
708
|
return new OpenCodeSdkTransport({
|
|
@@ -679,6 +710,7 @@ export class DefaultTransportRegistry implements TransportRegistry {
|
|
|
679
710
|
billingMode: usageBillingMode,
|
|
680
711
|
admissionIdentity,
|
|
681
712
|
defaultRoute,
|
|
713
|
+
...credentialOption,
|
|
682
714
|
});
|
|
683
715
|
}
|
|
684
716
|
|
|
@@ -745,6 +777,7 @@ export class DefaultTransportRegistry implements TransportRegistry {
|
|
|
745
777
|
billingMode: usageBillingMode,
|
|
746
778
|
admissionIdentity,
|
|
747
779
|
defaultRoute,
|
|
780
|
+
...credentialOption,
|
|
748
781
|
});
|
|
749
782
|
});
|
|
750
783
|
}
|
|
@@ -2,6 +2,7 @@ import type { BucketScope } from "../execution/bucket-id";
|
|
|
2
2
|
import { deriveBucketId } from "../execution/bucket-id";
|
|
3
3
|
import type {
|
|
4
4
|
AsyncEventSink,
|
|
5
|
+
OpenCodeFailureCredential,
|
|
5
6
|
ProviderCapabilityReport,
|
|
6
7
|
ProviderEvent,
|
|
7
8
|
ProviderEventBase,
|
|
@@ -409,6 +410,12 @@ export interface OpenCodeSdkTransportOptions {
|
|
|
409
410
|
readonly provider: string;
|
|
410
411
|
};
|
|
411
412
|
readonly defaultRoute?: ResolvedModelRoute;
|
|
413
|
+
// S7: the CRYSK_OPENCODE_* secret this transport's route runs on, named by the
|
|
414
|
+
// registry factory from the route's provider and credential kind (the transport
|
|
415
|
+
// holds neither credential nor kind). Stamped on every failed outcome as
|
|
416
|
+
// `failureCredential`, so a CI fix names the secret to replace or top up. Absent
|
|
417
|
+
// for a free route, an unknown kind, or a provider no secret name can carry.
|
|
418
|
+
readonly failureCredential?: OpenCodeFailureCredential;
|
|
412
419
|
}
|
|
413
420
|
|
|
414
421
|
const MARKER_ABORT_UNCONFIRMED =
|
|
@@ -708,6 +715,9 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
708
715
|
// attempted.
|
|
709
716
|
readonly credentialProjection = "server-lifetime" as const;
|
|
710
717
|
readonly defaultRoute?: ResolvedModelRoute;
|
|
718
|
+
// Public and readonly for the same reason as usageBillingMode below: the factory
|
|
719
|
+
// derives it, and reading it is how a test observes that derivation.
|
|
720
|
+
readonly failureCredential?: OpenCodeFailureCredential;
|
|
711
721
|
private readonly client: OpenCodeClientLike;
|
|
712
722
|
private readonly stallDeadlineMs: number;
|
|
713
723
|
private readonly abortConfirmMs: number;
|
|
@@ -739,6 +749,7 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
739
749
|
};
|
|
740
750
|
this.cancellationSemantics = "provider-proof";
|
|
741
751
|
this.defaultRoute = options.defaultRoute;
|
|
752
|
+
this.failureCredential = options.failureCredential;
|
|
742
753
|
this.client = options.client;
|
|
743
754
|
this.stallDeadlineMs = options.stallDeadlineMs ?? DEFAULT_STALL_DEADLINE_MS;
|
|
744
755
|
this.abortConfirmMs = options.abortConfirmMs ?? SDK_ABORT_CONFIRM_MS;
|
|
@@ -878,7 +889,9 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
878
889
|
request: TransportRequest,
|
|
879
890
|
context: { readonly signal: AbortSignal; readonly events: AsyncEventSink },
|
|
880
891
|
): Promise<TransportOutcome> {
|
|
881
|
-
const outcome =
|
|
892
|
+
const outcome = this.withFailureCredential(
|
|
893
|
+
await this.executeAttempt(request, context),
|
|
894
|
+
);
|
|
882
895
|
try {
|
|
883
896
|
const diagnosticEvidence = this.client.takeEvidence?.(
|
|
884
897
|
request.sessionId,
|
|
@@ -890,6 +903,15 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
890
903
|
}
|
|
891
904
|
}
|
|
892
905
|
|
|
906
|
+
// The secret only on a failed attempt, like the Claude transport: it is what the fix
|
|
907
|
+
// names, and a success or a cancellation has nothing to fix.
|
|
908
|
+
private withFailureCredential(outcome: TransportOutcome): TransportOutcome {
|
|
909
|
+
return outcome.completion === "failed" &&
|
|
910
|
+
this.failureCredential !== undefined
|
|
911
|
+
? { ...outcome, failureCredential: this.failureCredential }
|
|
912
|
+
: outcome;
|
|
913
|
+
}
|
|
914
|
+
|
|
893
915
|
private async executeAttempt(
|
|
894
916
|
request: TransportRequest,
|
|
895
917
|
context: { readonly signal: AbortSignal; readonly events: AsyncEventSink },
|
|
@@ -2255,6 +2277,16 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
2255
2277
|
) {
|
|
2256
2278
|
return "model_unavailable";
|
|
2257
2279
|
}
|
|
2280
|
+
// S7, same slot rule: a 401 is the provider refusing the credential, whatever its
|
|
2281
|
+
// words (OpenAI's "Incorrect API key provided" matches none of the auth patterns
|
|
2282
|
+
// above). auth_invalid is terminal like runtime_unavailable, so the retry policy is
|
|
2283
|
+
// unchanged; the cause lets the PR name the secret to replace (CRYSK-CRED-REJECTED).
|
|
2284
|
+
if (
|
|
2285
|
+
witness.includes(MARKER_PROVIDER_REFUSAL) &&
|
|
2286
|
+
providerRefusalStatus(witness) === "401"
|
|
2287
|
+
) {
|
|
2288
|
+
return "auth_invalid";
|
|
2289
|
+
}
|
|
2258
2290
|
if (witness.includes(MARKER_PROVIDER_REFUSAL)) {
|
|
2259
2291
|
return providerRefusalRetries(witness) === true
|
|
2260
2292
|
? "network_transient"
|
package/src/ui/config-edit.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { profileIdProblem } from "#model/profiles";
|
|
4
5
|
import {
|
|
5
6
|
mergeConfig,
|
|
6
7
|
parseGlobalConfig,
|
|
7
8
|
parseLocalConfig,
|
|
8
9
|
} from "#review/preflight";
|
|
9
10
|
import { resolveHomeDir, resolveRepoDir } from "../brand-paths";
|
|
11
|
+
import { redactConfigValue } from "../security/redact";
|
|
10
12
|
import { bold, box, cyan, dim, sanitizeText, yellow } from "./primitives";
|
|
11
13
|
import type { KeyReader } from "./select";
|
|
12
14
|
|
|
@@ -628,6 +630,13 @@ export async function setConfigValue(input: {
|
|
|
628
630
|
// Gone (L6 item 1): writing it would plant the very key the parser now
|
|
629
631
|
// refuses. Say where the summary model lives instead.
|
|
630
632
|
throw new Error(SUMMARY_MODEL_GONE);
|
|
633
|
+
} else if (input.key === "profile") {
|
|
634
|
+
const value = input.value.trim();
|
|
635
|
+
const problem = profileIdProblem(value);
|
|
636
|
+
if (problem !== undefined) {
|
|
637
|
+
throw new Error(`${problem} (got "${redactConfigValue(value)}")`);
|
|
638
|
+
}
|
|
639
|
+
currentPerson.profile = value;
|
|
631
640
|
} else if (input.key === "agents_dir") {
|
|
632
641
|
currentPerson.agents_dir = input.value.trim();
|
|
633
642
|
} else if (input.key === "scout") {
|
package/src/ui/config.ts
CHANGED
|
@@ -168,6 +168,7 @@ export function configRows(
|
|
|
168
168
|
),
|
|
169
169
|
models: modelsCell(effective.models, sources.models),
|
|
170
170
|
credentials: credentialsCell(effective.credentials, sources.credentials),
|
|
171
|
+
profile: cell(effective.profile, sources.profile),
|
|
171
172
|
max_verification_steps: cell(
|
|
172
173
|
effective.max_verification_steps?.toString(),
|
|
173
174
|
sources.max_verification_steps,
|
package/src/ui/menu.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { DEFAULT_SIZE_GATE } from "#review/size-gate";
|
|
|
6
6
|
import { listActiveRuns } from "#store/activity";
|
|
7
7
|
import { DEFAULT_DAILY_CAP } from "#watch/preflight";
|
|
8
8
|
import { resolveHomeDir, resolveRepoDir } from "../brand-paths";
|
|
9
|
-
import { runDoctor } from "../doctor";
|
|
9
|
+
import { loadDoctorRouting, runDoctor } from "../doctor";
|
|
10
10
|
import {
|
|
11
11
|
getMenuOptions,
|
|
12
12
|
type MenuItem,
|
|
@@ -157,7 +157,14 @@ export async function gatherMenuStatus(
|
|
|
157
157
|
|
|
158
158
|
let doctorStatus: MenuStatusInfo["doctorStatus"];
|
|
159
159
|
try {
|
|
160
|
-
|
|
160
|
+
// The person's profile decides whether the Claude CLI is required
|
|
161
|
+
// (openai-profile S6), as `crysk doctor` reads it.
|
|
162
|
+
const routing = await loadDoctorRouting({ home, repoRoot: cwd });
|
|
163
|
+
const report = await runDoctor({
|
|
164
|
+
home,
|
|
165
|
+
cwd,
|
|
166
|
+
claudeRequired: routing.claudeRequired,
|
|
167
|
+
});
|
|
161
168
|
doctorStatus = report.overall;
|
|
162
169
|
} catch {
|
|
163
170
|
// Ignore
|
package/src/updater.ts
CHANGED
|
@@ -24,9 +24,10 @@ import { type AssetMode, resolveEngineAssets, selfInvocation } from "./assets";
|
|
|
24
24
|
import { BIN_NAME, LEGACY_BIN_NAME } from "./brand";
|
|
25
25
|
import { LEGACY_HOME_DIR_NAME, resolveHomeDir } from "./brand-paths";
|
|
26
26
|
import { loadGlobalConfigLayer } from "./config/config";
|
|
27
|
-
import { runDoctor } from "./doctor";
|
|
27
|
+
import { loadDoctorRouting, runDoctor } from "./doctor";
|
|
28
28
|
import { prheroLayout } from "./home-preflight";
|
|
29
|
-
import { type ModelsConfig,
|
|
29
|
+
import { type ModelsConfig, routingNeedsOpenCode } from "./model/model-name";
|
|
30
|
+
import { resolveProfile } from "./model/profiles";
|
|
30
31
|
import {
|
|
31
32
|
readInstalledOpenCodeSdkVersion,
|
|
32
33
|
SUPPORTED_OPENCODE_SDK_VERSION,
|
|
@@ -54,7 +55,7 @@ export function detectInstallMethod(
|
|
|
54
55
|
): InstallMethod {
|
|
55
56
|
const home = options.home ?? os.homedir();
|
|
56
57
|
const execPath = options.execPath ?? process.execPath;
|
|
57
|
-
const version = options.version ?? "0.
|
|
58
|
+
const version = options.version ?? "0.6.0";
|
|
58
59
|
const exists = options.exists ?? existsSync;
|
|
59
60
|
|
|
60
61
|
const isSource =
|
|
@@ -656,14 +657,15 @@ export function spawnOpenCodeSdkInstaller(
|
|
|
656
657
|
});
|
|
657
658
|
}
|
|
658
659
|
|
|
659
|
-
// The person file's `models`, the only layer that may hold them.
|
|
660
|
-
// file that no longer parses (a removed `routing` key) throws here,
|
|
661
|
-
// reconcile step records that message instead of crashing.
|
|
662
|
-
async function readReconcileModels(
|
|
663
|
-
|
|
664
|
-
|
|
660
|
+
// The person file's `models` and `profile`, the only layer that may hold them.
|
|
661
|
+
// A person file that no longer parses (a removed `routing` key) throws here,
|
|
662
|
+
// and the reconcile step records that message instead of crashing.
|
|
663
|
+
async function readReconcileModels(home: string): Promise<{
|
|
664
|
+
models: ModelsConfig | undefined;
|
|
665
|
+
profile: string | undefined;
|
|
666
|
+
}> {
|
|
665
667
|
const loaded = await loadGlobalConfigLayer(home);
|
|
666
|
-
return loaded.layer?.models;
|
|
668
|
+
return { models: loaded.layer?.models, profile: loaded.layer?.profile };
|
|
667
669
|
}
|
|
668
670
|
|
|
669
671
|
async function ensureOpenCodeSdkInstalled(options: {
|
|
@@ -673,8 +675,8 @@ async function ensureOpenCodeSdkInstalled(options: {
|
|
|
673
675
|
which?: (bin: string) => string | null;
|
|
674
676
|
spawnInstaller?: (argv: readonly string[]) => Promise<OpenCodeSdkSpawnResult>;
|
|
675
677
|
}): Promise<void> {
|
|
676
|
-
const models = await readReconcileModels(options.home);
|
|
677
|
-
if (!
|
|
678
|
+
const { models, profile } = await readReconcileModels(options.home);
|
|
679
|
+
if (!routingNeedsOpenCode(models, resolveProfile(profile))) return;
|
|
678
680
|
// Install and the version check share this home. The no-arg reader uses
|
|
679
681
|
// os.homedir(), which is a different tree whenever reconcile was given one.
|
|
680
682
|
const nodeModulesDir = prheroLayout(options.home).nodeModulesDir;
|
|
@@ -823,7 +825,13 @@ export async function reconcileUpgrade(
|
|
|
823
825
|
}
|
|
824
826
|
} else {
|
|
825
827
|
try {
|
|
826
|
-
|
|
828
|
+
// The person's profile decides whether the Claude CLI is required
|
|
829
|
+
// (openai-profile S6), as `crysk doctor` reads it.
|
|
830
|
+
const routing = await loadDoctorRouting({ home });
|
|
831
|
+
const doc = await runDoctor({
|
|
832
|
+
home,
|
|
833
|
+
claudeRequired: routing.claudeRequired,
|
|
834
|
+
});
|
|
827
835
|
if (doc.overall === "blocking") {
|
|
828
836
|
errors.push("Doctor check found blocking issues");
|
|
829
837
|
}
|
package/src/wizard.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import type { ModelsConfig } from "#model/model-name";
|
|
5
|
+
import type { ModelProfile } from "#model/profiles";
|
|
4
6
|
import {
|
|
5
7
|
GOTCHAS_PLACEHOLDER_MARKER,
|
|
6
8
|
initConfigTemplate,
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
} from "./agent-env";
|
|
17
19
|
import { resolveEngineAssets, selfInvocation } from "./assets";
|
|
18
20
|
import { REPO_DIR_NAME, resolveHomeDir, resolveRepoDir } from "./brand-paths";
|
|
21
|
+
import { loadDoctorRouting } from "./doctor";
|
|
19
22
|
import type {
|
|
20
23
|
ExactBindingCapabilityReport,
|
|
21
24
|
RunnerBackend,
|
|
@@ -341,6 +344,22 @@ function authProjectionDetail(
|
|
|
341
344
|
return ` (auth projection: ${ready ? "ready" : "unavailable"})`;
|
|
342
345
|
}
|
|
343
346
|
|
|
347
|
+
// The routing the wizard's binding probe resolves, read like `crysk doctor`
|
|
348
|
+
// reads it. A config that fails to load keeps the fallback profile with
|
|
349
|
+
// Claude required, which is what the probe did before profiles existed.
|
|
350
|
+
async function wizardDoctorRouting(home: string): Promise<{
|
|
351
|
+
claudeRequired: boolean;
|
|
352
|
+
models?: ModelsConfig;
|
|
353
|
+
profile: ModelProfile;
|
|
354
|
+
}> {
|
|
355
|
+
const routing = await loadDoctorRouting({ home });
|
|
356
|
+
return {
|
|
357
|
+
claudeRequired: routing.claudeRequired,
|
|
358
|
+
...(routing.models === undefined ? {} : { models: routing.models }),
|
|
359
|
+
profile: routing.profile,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
344
363
|
export const WIZARD_STEPS: readonly WizardStepDescriptor[] = [
|
|
345
364
|
// Step 1: System tools
|
|
346
365
|
{
|
|
@@ -372,6 +391,10 @@ export const WIZARD_STEPS: readonly WizardStepDescriptor[] = [
|
|
|
372
391
|
? await deps.probeExactBinding()
|
|
373
392
|
: await collectDoctorExactBindingReports({
|
|
374
393
|
workspaceRoot,
|
|
394
|
+
// What the person's config routes, as `crysk doctor` probes it
|
|
395
|
+
// (openai-profile S6): a profile with no Claude step is not
|
|
396
|
+
// probed on a Claude binding it never opens.
|
|
397
|
+
...(await wizardDoctorRouting(deps.home ?? os.homedir())),
|
|
375
398
|
authorityDeps: {
|
|
376
399
|
existsFn: deps.exists ?? deps.checkToolsOptions?.exists,
|
|
377
400
|
},
|