crysk 0.4.0 → 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.
- 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/gates.ts +22 -36
- package/src/ci/outcome.ts +421 -330
- package/src/ci/platform-config.ts +2 -2
- package/src/ci/platform-report.ts +274 -41
- package/src/ci/platform-trace.ts +551 -0
- package/src/ci/platform.ts +28 -12
- package/src/ci/publish.ts +19 -6
- package/src/ci/review-levels.ts +8 -7
- package/src/ci/run.ts +88 -0
- package/src/ci/setup.ts +453 -118
- package/src/ci/trace-bundle.ts +1282 -0
- package/src/ci/trace-transcripts.ts +415 -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/plan.ts +20 -4
- package/src/pr/preflight.ts +1 -1
- package/src/pr/publish-outcome.ts +1 -1
- package/src/pr/review-pr.ts +15 -1
- package/src/pr/target.ts +12 -3
- 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 +26 -26
- package/src/review/review.ts +20 -3
- package/src/review/route-preflight.ts +79 -11
- package/src/review/run.ts +28 -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 +76 -47
- package/src/updater.ts +10 -7
- package/prompts/default/deep-review-lifecycle.md +0 -362
|
@@ -386,51 +386,66 @@ export class OpenCodeAuthBroker implements CredentialBroker {
|
|
|
386
386
|
);
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
} catch {
|
|
393
|
-
throw new CredentialProjectionError("source_read_failed");
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
let parsed: unknown;
|
|
397
|
-
try {
|
|
398
|
-
parsed = JSON.parse(raw);
|
|
399
|
-
} catch {
|
|
400
|
-
throw new CredentialProjectionError("malformed_payload");
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (typeof parsed !== "object" || parsed === null) {
|
|
404
|
-
throw new CredentialProjectionError("malformed_payload");
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const record = (parsed as Record<string, unknown>).openai;
|
|
408
|
-
if (typeof record !== "object" || record === null) {
|
|
409
|
-
throw new CredentialProjectionError("missing_subscription_record");
|
|
410
|
-
}
|
|
411
|
-
// This kind promises ChatGPT OAuth specifically. An `openai` entry holding
|
|
412
|
-
// a pay-as-you-go API key is a different credential on different billing,
|
|
413
|
-
// and projecting it here would make the capability report's
|
|
414
|
-
// `billing.mode: "subscription"` a lie rather than a claim.
|
|
415
|
-
//
|
|
416
|
-
// #133 note: this lock is also what makes credentialKindForRoute's
|
|
417
|
-
// provider-keyed decision safe. That function does NOT read the store, so
|
|
418
|
-
// an `openai` entry holding an API key still resolves to this OAuth kind —
|
|
419
|
-
// and lands here, refused, rather than being silently routed metered. A
|
|
420
|
-
// bounded, stated limit, not a bug: the failure is loud and the fix is to
|
|
421
|
-
// name that provider differently in the routing config.
|
|
422
|
-
if ((record as Record<string, unknown>).type !== "oauth") {
|
|
423
|
-
throw new CredentialProjectionError("missing_subscription_record");
|
|
389
|
+
const lookup = await lookupOpenCodeOAuthRecord(this.readerFn);
|
|
390
|
+
if (!lookup.ok) {
|
|
391
|
+
throw new CredentialProjectionError(lookup.failureClass);
|
|
424
392
|
}
|
|
425
393
|
|
|
426
394
|
return buildOpenCodeProjection(
|
|
427
395
|
input.kind,
|
|
428
396
|
OPENCODE_OAUTH_PROVIDER,
|
|
429
|
-
record
|
|
397
|
+
lookup.record,
|
|
430
398
|
);
|
|
431
399
|
}
|
|
432
400
|
}
|
|
433
401
|
|
|
402
|
+
// The read+parse+validate sequence for the `openai` ChatGPT OAuth record, the
|
|
403
|
+
// OAuth broker's own (above) and admission's credential check
|
|
404
|
+
// (openCodeCredentialRefusal, production-runtime.ts). One copy, so admission
|
|
405
|
+
// asks exactly what the broker will ask when the route runs.
|
|
406
|
+
export async function lookupOpenCodeOAuthRecord(
|
|
407
|
+
readerFn: () => Promise<string>,
|
|
408
|
+
): Promise<OpenCodeRecordLookup> {
|
|
409
|
+
let raw: string;
|
|
410
|
+
try {
|
|
411
|
+
raw = await readerFn();
|
|
412
|
+
} catch {
|
|
413
|
+
return { ok: false, failureClass: "source_read_failed" };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
let parsed: unknown;
|
|
417
|
+
try {
|
|
418
|
+
parsed = JSON.parse(raw);
|
|
419
|
+
} catch {
|
|
420
|
+
return { ok: false, failureClass: "malformed_payload" };
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
424
|
+
return { ok: false, failureClass: "malformed_payload" };
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const record = (parsed as Record<string, unknown>).openai;
|
|
428
|
+
if (typeof record !== "object" || record === null) {
|
|
429
|
+
return { ok: false, failureClass: "missing_subscription_record" };
|
|
430
|
+
}
|
|
431
|
+
// This kind promises ChatGPT OAuth specifically. An `openai` entry holding
|
|
432
|
+
// a pay-as-you-go API key is a different credential on different billing,
|
|
433
|
+
// and projecting it here would make the capability report's
|
|
434
|
+
// `billing.mode: "subscription"` a lie rather than a claim.
|
|
435
|
+
//
|
|
436
|
+
// #133 note: this lock is also what makes credentialKindForRoute's
|
|
437
|
+
// provider-keyed decision safe. That function does NOT read the store, so
|
|
438
|
+
// an `openai` entry holding an API key still resolves to this OAuth kind —
|
|
439
|
+
// and lands here, refused, rather than being silently routed metered. A
|
|
440
|
+
// bounded, stated limit, not a bug: the failure is loud and the fix is to
|
|
441
|
+
// name that provider differently in the model name (`opencode:<provider>/...`).
|
|
442
|
+
if ((record as Record<string, unknown>).type !== "oauth") {
|
|
443
|
+
return { ok: false, failureClass: "missing_subscription_record" };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return { ok: true, record: record as OpenCodeProviderRecord };
|
|
447
|
+
}
|
|
448
|
+
|
|
434
449
|
// ONE builder for both OpenCode brokers. A third copy of the create+lstat+hash
|
|
435
450
|
// sequence is exactly the drift `openCodeProjectionLayout` already exists to
|
|
436
451
|
// prevent (pr-hero F001 on PR #80: two hand-maintained path lists, three
|
|
@@ -526,7 +541,7 @@ function buildOpenCodeProjection(
|
|
|
526
541
|
// traversal, a prototype key, or anything requiring escaping.
|
|
527
542
|
const OPENCODE_PROVIDER_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
528
543
|
|
|
529
|
-
type
|
|
544
|
+
export type OpenCodeRecordLookup =
|
|
530
545
|
| { readonly ok: true; readonly record: OpenCodeProviderRecord }
|
|
531
546
|
| {
|
|
532
547
|
readonly ok: false;
|
|
@@ -541,11 +556,12 @@ type OpenCodeApiRecordLookup =
|
|
|
541
556
|
// hash sequence: a third hand-maintained copy is exactly the drift that
|
|
542
557
|
// comment warns about, and here it would additionally let the two callers'
|
|
543
558
|
// validation silently diverge (e.g. one broker accepting a record shape the
|
|
544
|
-
// other refuses).
|
|
545
|
-
|
|
559
|
+
// other refuses). Admission's credential check (openCodeCredentialRefusal,
|
|
560
|
+
// production-runtime.ts) is the third caller, for the same reason.
|
|
561
|
+
export async function lookupOpenCodeApiRecord(
|
|
546
562
|
readerFn: () => Promise<string>,
|
|
547
563
|
provider: string,
|
|
548
|
-
): Promise<
|
|
564
|
+
): Promise<OpenCodeRecordLookup> {
|
|
549
565
|
let raw: string;
|
|
550
566
|
try {
|
|
551
567
|
raw = await readerFn();
|
|
@@ -1,8 +1,184 @@
|
|
|
1
1
|
const MAX_BYTES = 4 * 1024 * 1024;
|
|
2
|
+
const REDACTED = "[REDACTED]";
|
|
2
3
|
const SECRET =
|
|
3
4
|
/authorization|cookie|password|secret|api.?key|access.?token|refresh.?token|^token$|^key$/i;
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
// The words of an identifier, lower-cased. camelCase, snake_case, kebab-case
|
|
7
|
+
// and dotted names split the same way: `AWS_SECRET_ACCESS_KEY` and
|
|
8
|
+
// `awsSecretAccessKey` both give aws, secret, access, key.
|
|
9
|
+
export function nameParts(name: string): string[] {
|
|
10
|
+
return name
|
|
11
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
12
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.split(/[^a-z0-9]+/)
|
|
15
|
+
.filter((part) => part.length > 0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const SECRET_WORDS = new Set([
|
|
19
|
+
"secret",
|
|
20
|
+
"secrets",
|
|
21
|
+
"password",
|
|
22
|
+
"passwords",
|
|
23
|
+
"passwd",
|
|
24
|
+
"passphrase",
|
|
25
|
+
"apikey",
|
|
26
|
+
"apitoken",
|
|
27
|
+
"accesskey",
|
|
28
|
+
"accesstoken",
|
|
29
|
+
"authtoken",
|
|
30
|
+
"privatekey",
|
|
31
|
+
"secretkey",
|
|
32
|
+
"clientsecret",
|
|
33
|
+
"refreshtoken",
|
|
34
|
+
]);
|
|
35
|
+
const KEY_QUALIFIERS = new Set([
|
|
36
|
+
"api",
|
|
37
|
+
"access",
|
|
38
|
+
"private",
|
|
39
|
+
"secret",
|
|
40
|
+
"client",
|
|
41
|
+
"signing",
|
|
42
|
+
"encryption",
|
|
43
|
+
"master",
|
|
44
|
+
"session",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
// Whether a name says its value is a credential: it holds a secret or password
|
|
48
|
+
// word anywhere, or it ends in `token` or in a qualified `key` (api, access,
|
|
49
|
+
// private...). Counts and descriptors survive: `max_tokens`, `token_type`,
|
|
50
|
+
// `tokenCount` and `apiKeySource` are not credentials.
|
|
51
|
+
export function isSecretName(name: string): boolean {
|
|
52
|
+
const parts = nameParts(name);
|
|
53
|
+
const last = parts.at(-1);
|
|
54
|
+
if (last === undefined) return false;
|
|
55
|
+
if (parts.some((part) => SECRET_WORDS.has(part))) return true;
|
|
56
|
+
if (last === "token") return true;
|
|
57
|
+
const qualifier = parts.at(-2);
|
|
58
|
+
return (
|
|
59
|
+
last === "key" && qualifier !== undefined && KEY_QUALIFIERS.has(qualifier)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Values that cannot be a credential, whatever name they are assigned to: a
|
|
64
|
+
// GitHub Actions expression, a permission or `secrets:` word, a YAML block
|
|
65
|
+
// scalar indicator, a placeholder, an environment reference, a boolean, or a
|
|
66
|
+
// small number. A workflow file a hunter reads is full of them
|
|
67
|
+
// (`id-token: write`, `API_KEY=${{ secrets.API_KEY }}`). The whole value must
|
|
68
|
+
// match, so `write-abc123` or `xxxabc123` is still a value to hide. A number
|
|
69
|
+
// stays hidden under a password name, and past five digits under any name,
|
|
70
|
+
// since a PIN or a numeric key is a secret.
|
|
71
|
+
const NON_SECRET_VALUES: readonly RegExp[] = [
|
|
72
|
+
/^\$\{\{(?:(?!\}\})[^\r\n])*\}\}$/,
|
|
73
|
+
/^(?:read|write|none|read-all|write-all|inherit)$/,
|
|
74
|
+
/^[|>][+-]?[1-9]?$/,
|
|
75
|
+
/^<[^<>\r\n]*>$/,
|
|
76
|
+
/^(?:x{3,}|X{3,}|\*{3,}|changeme|\[REDACTED\])$/,
|
|
77
|
+
/^\$[A-Z_][A-Z0-9_]*$/,
|
|
78
|
+
/^\$\{[A-Z_][A-Z0-9_]*\}$/,
|
|
79
|
+
/^(?:process\.env|Bun\.env|import\.meta\.env)\.[A-Za-z_]\w*$/,
|
|
80
|
+
/^(?:true|false)$/i,
|
|
81
|
+
];
|
|
82
|
+
const PASSWORD_WORDS = new Set(["password", "passwd", "passphrase", "pin"]);
|
|
83
|
+
|
|
84
|
+
export function isNonSecretValue(value: string, name = ""): boolean {
|
|
85
|
+
const bare = value.replace(/^\\*(["'])(.*)\\*\1$/, "$2");
|
|
86
|
+
if (bare === "" || NON_SECRET_VALUES.some((shape) => shape.test(bare))) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return (
|
|
90
|
+
/^\d{1,5}$/.test(bare) &&
|
|
91
|
+
!nameParts(name).some((part) => PASSWORD_WORDS.has(part))
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A GitHub Actions expression is one value even though it holds spaces, so
|
|
96
|
+
// `token: ${{ github.token }}` is read whole and kept, not cut at `${{`.
|
|
97
|
+
// Its body never holds another `${{` and is at most 512 characters, so a line
|
|
98
|
+
// of unclosed `token=${{ ` is scanned once, not to its end from every start.
|
|
99
|
+
export const EXPRESSION_VALUE = String.raw`\$\{\{(?:[^$}\r\n]|\$(?!\{\{)|\}(?!\})){0,512}\}\}(?=[\s,;&"'\\]|$)`;
|
|
100
|
+
// A YAML `:` value may sit below its key, past up to three blank or comment
|
|
101
|
+
// lines, unless that line is a key of its own: a `secrets:` section's first
|
|
102
|
+
// entry is not its value, and a comment is never one. The key must end its
|
|
103
|
+
// line, so each line is crossed from at most the three keys above it.
|
|
104
|
+
const YAML_VALUE_BELOW = String.raw`:(?:[ \t]*\r?\n(?:[ \t]*(?:#[^\r\n]*)?\r?\n){0,3}(?![ \t]*[\w.-]+[ \t]*:(?:\s|$))[ \t]*(?!#)|[ \t]*)`;
|
|
105
|
+
|
|
106
|
+
// Every pattern below stops at quotes and backslashes, so it can run on JSON
|
|
107
|
+
// text without breaking the parse that follows. Each one starts only where a
|
|
108
|
+
// run begins (lookbehind, not \b), so a long run of word characters is
|
|
109
|
+
// scanned once, not once per character.
|
|
110
|
+
// A block cut before its END line runs to the last base64 character. The run
|
|
111
|
+
// also takes the gutter of a line-numbered Read (` 2→` or ` 2\t`,
|
|
112
|
+
// raw or JSON-escaped): digits and whitespace are already base64 run
|
|
113
|
+
// characters, so only the arrow and the escaped tab are added.
|
|
114
|
+
const PEM_PRIVATE_KEY =
|
|
115
|
+
/-----BEGIN[A-Z0-9 ]*PRIVATE KEY[A-Z ]*-----(?:[\s\S]*?-----END[A-Z0-9 ]*PRIVATE KEY[A-Z ]*-----|(?:[A-Za-z0-9+/=\s\u2192]|\\[nrt])*)/g;
|
|
116
|
+
// `scheme://user:password@`, for every scheme: postgres, mysql, mongodb+srv,
|
|
117
|
+
// redis, amqp. The user goes too, since it is often a key id.
|
|
118
|
+
const URL_CREDENTIALS =
|
|
119
|
+
/(?<![a-z0-9+.-])([a-z][a-z0-9+.-]*:\/\/)[^\s/@:'"<>\\]*:[^\s/@'"<>\\]+@/gi;
|
|
120
|
+
const AWS_ACCESS_KEY_ID = /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g;
|
|
121
|
+
const STRIPE_KEY = /\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{10,}/g;
|
|
122
|
+
const JWT =
|
|
123
|
+
/(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{4,}\.eyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g;
|
|
124
|
+
// `"name": "value"`, `name = 'value'` and `{\"name\":\"value\"}`: the value
|
|
125
|
+
// is quoted, so code such as `token_count = usage.total` keeps reading.
|
|
126
|
+
const QUOTED_ASSIGNMENT =
|
|
127
|
+
/(?<![\w.-])([\w.-]+)(\\*["']?\s*[=:]\s*\\*["'])([^"'\\\r\n]+)/g;
|
|
128
|
+
// `NAME=value` and `name: value` in env, ini and YAML files, for UPPER_SNAKE,
|
|
129
|
+
// snake_case and kebab-case names. camelCase is left to the quoted form unless
|
|
130
|
+
// the caller asks for it, so `privateKey = loadKey()` in a code window reads as
|
|
131
|
+
// before; the session copy asks, since a YAML file spells `privateKey: abc`.
|
|
132
|
+
// An `=` value stays on its line, so an empty `TOKEN=` never takes the next
|
|
133
|
+
// variable. A `:` value may sit below its key (YAML_VALUE_BELOW).
|
|
134
|
+
const UNQUOTED_ASSIGNMENT = new RegExp(
|
|
135
|
+
String.raw`(?<![\w.-])([A-Za-z][\w-]*)([ \t]*(?:=[ \t]*|${YAML_VALUE_BELOW}))(${EXPRESSION_VALUE}|[^\s,;&"'\\]+)`,
|
|
136
|
+
"g",
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The credential shapes that need no surrounding context, plus assignments to
|
|
141
|
+
* a name `isSecret` accepts. Safe on JSON text: it never removes a quote.
|
|
142
|
+
*/
|
|
143
|
+
export function redactSecretShapes(
|
|
144
|
+
value: string,
|
|
145
|
+
isSecret: (name: string) => boolean = isSecretName,
|
|
146
|
+
unquotedCamelCase = false,
|
|
147
|
+
): string {
|
|
5
148
|
return value
|
|
149
|
+
.replace(PEM_PRIVATE_KEY, REDACTED)
|
|
150
|
+
.replace(URL_CREDENTIALS, `$1${REDACTED}@`)
|
|
151
|
+
.replace(AWS_ACCESS_KEY_ID, REDACTED)
|
|
152
|
+
.replace(STRIPE_KEY, REDACTED)
|
|
153
|
+
.replace(JWT, REDACTED)
|
|
154
|
+
.replace(
|
|
155
|
+
QUOTED_ASSIGNMENT,
|
|
156
|
+
(match, name: string, separator: string, value: string) =>
|
|
157
|
+
isSecret(name) && !isNonSecretValue(value, name)
|
|
158
|
+
? `${name}${separator}${REDACTED}`
|
|
159
|
+
: match,
|
|
160
|
+
)
|
|
161
|
+
.replace(
|
|
162
|
+
UNQUOTED_ASSIGNMENT,
|
|
163
|
+
(match, name: string, separator: string, value: string) =>
|
|
164
|
+
(unquotedCamelCase || !/[a-z][A-Z]/.test(name)) &&
|
|
165
|
+
isSecret(name) &&
|
|
166
|
+
!isNonSecretValue(value, name)
|
|
167
|
+
? `${name}${separator}${REDACTED}`
|
|
168
|
+
: match,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// A credential keyword, its separator, and the value: on the same line after
|
|
173
|
+
// `=`, and after `:` also below the key (YAML_VALUE_BELOW), so a camelCase
|
|
174
|
+
// `apiKey:` the unquoted rule leaves alone still loses a value on a later line.
|
|
175
|
+
const LEGACY_KEYWORD_VALUE = new RegExp(
|
|
176
|
+
String.raw`((?:api[_-]?key|access[_-]?token|refresh[_-]?token|token|password|secret)[ \t]*(?:=[ \t]*|${YAML_VALUE_BELOW}))(${EXPRESSION_VALUE}|[^\s,;&]+)`,
|
|
177
|
+
"gi",
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
export function redactEvidenceText(value: string): string {
|
|
181
|
+
return redactSecretShapes(value)
|
|
6
182
|
.replace(
|
|
7
183
|
/\b(?:authorization|proxy-authorization|cookie|set-cookie)\s*:[^\r\n]*/gi,
|
|
8
184
|
"[REDACTED HEADER]",
|
|
@@ -23,9 +199,8 @@ export function redactEvidenceText(value: string): string {
|
|
|
23
199
|
/\b(?:sk-[\w-]+|gh[pousr]_[\w]+|github_pat_[\w]+|Bearer\s+[^\s,;]+)/gi,
|
|
24
200
|
"[REDACTED]",
|
|
25
201
|
)
|
|
26
|
-
.replace(
|
|
27
|
-
|
|
28
|
-
"$1[REDACTED]",
|
|
202
|
+
.replace(LEGACY_KEYWORD_VALUE, (match, keyword: string, value: string) =>
|
|
203
|
+
isNonSecretValue(value, keyword) ? match : `${keyword}[REDACTED]`,
|
|
29
204
|
);
|
|
30
205
|
}
|
|
31
206
|
/** JSON-only bounded traversal: never call getters, custom iterators or toJSON. */
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// The manifest the CI setup step leaves beside the OpenCode auth file it builds
|
|
2
|
+
// from CRYSK_OPENCODE_* secrets (odd/tasks/role-model-routing.md S8/S9, L12
|
|
3
|
+
// "Building auth.json", unit U3).
|
|
4
|
+
//
|
|
5
|
+
// WHY a file: the secrets reach the setup step only (L13), and the run step
|
|
6
|
+
// never sees them or the setup step's outputs, yet the run must bind each
|
|
7
|
+
// OpenCode route to the kind of credential the auth file actually holds. An
|
|
8
|
+
// openai record built from `CRYSK_OPENCODE_OPENAI_API_KEY` is a metered API
|
|
9
|
+
// token, not the ChatGPT subscription the provider literal assumes. The setup
|
|
10
|
+
// step writes, next to auth.json, WHICH secret built each provider's record;
|
|
11
|
+
// the run reads the names back and hands them to credentialKindForRoute
|
|
12
|
+
// (runner-authority.ts), which applies the same chooseOpenCodeSecret rule the
|
|
13
|
+
// setup step used. Names and kinds only, never a value.
|
|
14
|
+
//
|
|
15
|
+
// No manifest (the old `opencode-auth` input, a local `opencode auth login`
|
|
16
|
+
// store) means the provider literal decides, exactly as before U3. A manifest
|
|
17
|
+
// that does not parse is treated as absent: the literal then stands and a
|
|
18
|
+
// mismatched record is refused loudly at projection, never billed silently.
|
|
19
|
+
|
|
20
|
+
import { readFileSync } from "node:fs";
|
|
21
|
+
import { homedir } from "node:os";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
import { resolveOpenCodeAuthPath } from "./credential-broker";
|
|
24
|
+
|
|
25
|
+
export const OPENCODE_SECRET_MANIFEST_FILE = "crysk-credentials.json";
|
|
26
|
+
|
|
27
|
+
const SOURCE = "crysk-secrets";
|
|
28
|
+
const SECRET_NAME_RE =
|
|
29
|
+
/^CRYSK_OPENCODE_[A-Z0-9]+(?:_[A-Z0-9]+)*_(?:API_KEY|OAUTH)$/;
|
|
30
|
+
|
|
31
|
+
export interface OpenCodeSecretManifestEntry {
|
|
32
|
+
// The provider id as the model name writes it, which keys auth.json.
|
|
33
|
+
readonly provider: string;
|
|
34
|
+
// The secret whose value built the record.
|
|
35
|
+
readonly secret: string;
|
|
36
|
+
readonly kind: "oauth" | "api_key";
|
|
37
|
+
// The provider's other secret, set but not used (the subscription came first).
|
|
38
|
+
readonly unused?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function openCodeSecretManifestPath(authPath: string): string {
|
|
42
|
+
return path.join(path.dirname(authPath), OPENCODE_SECRET_MANIFEST_FILE);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function serializeOpenCodeSecretManifest(
|
|
46
|
+
entries: readonly OpenCodeSecretManifestEntry[],
|
|
47
|
+
): string {
|
|
48
|
+
const providers: Record<string, Record<string, string>> = {};
|
|
49
|
+
for (const entry of [...entries].sort((a, b) =>
|
|
50
|
+
a.provider.localeCompare(b.provider),
|
|
51
|
+
)) {
|
|
52
|
+
providers[entry.provider] = {
|
|
53
|
+
secret: entry.secret,
|
|
54
|
+
kind: entry.kind,
|
|
55
|
+
...(entry.unused === undefined ? {} : { unused: entry.unused }),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return `${JSON.stringify({ v: 1, source: SOURCE, providers }, null, 2)}\n`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
62
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Every secret name the manifest records, sorted, or undefined when the text is
|
|
66
|
+
// not a manifest this version wrote.
|
|
67
|
+
export function openCodeSecretNamesFromManifest(
|
|
68
|
+
text: string,
|
|
69
|
+
): readonly string[] | undefined {
|
|
70
|
+
let parsed: unknown;
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(text);
|
|
73
|
+
} catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (!isRecord(parsed) || parsed.v !== 1 || parsed.source !== SOURCE) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (!isRecord(parsed.providers)) return undefined;
|
|
80
|
+
const names = new Set<string>();
|
|
81
|
+
for (const entry of Object.values(parsed.providers)) {
|
|
82
|
+
if (!isRecord(entry)) return undefined;
|
|
83
|
+
if (entry.kind !== "oauth" && entry.kind !== "api_key") return undefined;
|
|
84
|
+
const recorded =
|
|
85
|
+
entry.unused === undefined
|
|
86
|
+
? [entry.secret]
|
|
87
|
+
: [entry.secret, entry.unused];
|
|
88
|
+
for (const name of recorded) {
|
|
89
|
+
if (typeof name !== "string" || !SECRET_NAME_RE.test(name)) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
names.add(name);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return [...names].sort();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The names the manifest beside the auth file this env resolves to records, or
|
|
99
|
+
// undefined when there is none. Read once per run, at admission.
|
|
100
|
+
export function readOpenCodeSecretNames(
|
|
101
|
+
env: Readonly<Record<string, string | undefined>> = process.env,
|
|
102
|
+
homeDir: string = homedir(),
|
|
103
|
+
): readonly string[] | undefined {
|
|
104
|
+
let text: string;
|
|
105
|
+
try {
|
|
106
|
+
text = readFileSync(
|
|
107
|
+
openCodeSecretManifestPath(resolveOpenCodeAuthPath(env, homeDir)),
|
|
108
|
+
"utf8",
|
|
109
|
+
);
|
|
110
|
+
} catch {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
return openCodeSecretNamesFromManifest(text);
|
|
114
|
+
}
|
package/src/security/redact.ts
CHANGED
|
@@ -8,6 +8,12 @@ const REDACTION_PATTERNS: readonly RegExp[] = [
|
|
|
8
8
|
/sk-[A-Za-z0-9_-]{8,}/g,
|
|
9
9
|
/gh[pousr]_[A-Za-z0-9_]{20,}/g,
|
|
10
10
|
/Bearer\s+\S+/gi,
|
|
11
|
+
// Google API keys: `AIza` and 35 characters.
|
|
12
|
+
/AIza[0-9A-Za-z_-]{35}/g,
|
|
13
|
+
// Groq (`gsk_`) and xAI (`xai-`) keys. The minimum length keeps model and
|
|
14
|
+
// provider names that share the prefix (`xai-grok-4`) readable.
|
|
15
|
+
/gsk_[A-Za-z0-9]{20,}/g,
|
|
16
|
+
/xai-[A-Za-z0-9]{20,}/g,
|
|
11
17
|
];
|
|
12
18
|
|
|
13
19
|
// A keyword followed by a value: `token: abc`, `api_key="abc"`, `password hunter2`. When
|
|
@@ -69,3 +75,42 @@ export function redactDiagnostic(text: string): string {
|
|
|
69
75
|
: REDACTED,
|
|
70
76
|
);
|
|
71
77
|
}
|
|
78
|
+
|
|
79
|
+
// Plain hex and base64 are NOT in REDACTION_PATTERNS: error output and logs
|
|
80
|
+
// carry commit SHAs and digests, and redacting them would hide the evidence.
|
|
81
|
+
// They are refused only where a whole config value is validated (a model name,
|
|
82
|
+
// an effort, a config key), which never holds a SHA or a digest.
|
|
83
|
+
//
|
|
84
|
+
// Hex: 32 characters or more, the shortest common key length (MD5-sized).
|
|
85
|
+
const WHOLE_HEX = /^[0-9a-fA-F]{32,}$/;
|
|
86
|
+
// Base64: 40 characters or more of the standard alphabet plus `_`, padding
|
|
87
|
+
// allowed, with upper case, lower case and a digit. `-` and `.` are left out
|
|
88
|
+
// on purpose: model ids are hyphenated or dotted words
|
|
89
|
+
// (`Llama-4-Maverick-17B-128E-Instruct-FP8`), keys are not.
|
|
90
|
+
const WHOLE_BASE64 = /^[A-Za-z0-9+/_]{40,}={0,2}$/;
|
|
91
|
+
|
|
92
|
+
function isLongBase64(value: string): boolean {
|
|
93
|
+
return (
|
|
94
|
+
WHOLE_BASE64.test(value) &&
|
|
95
|
+
/[A-Z]/.test(value) &&
|
|
96
|
+
/[a-z]/.test(value) &&
|
|
97
|
+
/[0-9]/.test(value)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Whether a whole config value looks like a credential: a key shape that
|
|
102
|
+
// redactDiagnostic knows, or a long plain hex or base64 value.
|
|
103
|
+
export function looksLikeCredential(value: string): boolean {
|
|
104
|
+
return (
|
|
105
|
+
redactDiagnostic(value) !== value ||
|
|
106
|
+
WHOLE_HEX.test(value) ||
|
|
107
|
+
isLongBase64(value)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// A config value for a message: `[REDACTED]` when the whole value looks like a
|
|
112
|
+
// credential, otherwise redactDiagnostic's output.
|
|
113
|
+
export function redactConfigValue(value: string): string {
|
|
114
|
+
if (WHOLE_HEX.test(value) || isLongBase64(value)) return REDACTED;
|
|
115
|
+
return redactDiagnostic(value);
|
|
116
|
+
}
|
package/src/system-tools.ts
CHANGED
|
@@ -6,6 +6,10 @@ import {
|
|
|
6
6
|
LEGACY_WORKFLOW_RELATIVE_PATH,
|
|
7
7
|
WORKFLOW_RELATIVE_PATH,
|
|
8
8
|
} from "./brand-paths";
|
|
9
|
+
import {
|
|
10
|
+
claudeCredentialPresence,
|
|
11
|
+
defaultClaudeLoginPresent,
|
|
12
|
+
} from "./security/claude-credential";
|
|
9
13
|
import { resolveOpenCodeAuthPath } from "./security/credential-broker";
|
|
10
14
|
|
|
11
15
|
export type SystemTool = "git" | "claude" | "gh" | "codegraph";
|
|
@@ -28,6 +32,10 @@ export interface CheckSystemToolsOptions {
|
|
|
28
32
|
exists?: (path: string) => boolean;
|
|
29
33
|
env?: Record<string, string | undefined>;
|
|
30
34
|
home?: string;
|
|
35
|
+
// Injectable so the Keychain half of the Claude login check is testable off macOS.
|
|
36
|
+
platform?: NodeJS.Platform;
|
|
37
|
+
// Whether the Keychain item exists; tests inject it so none asks the real Keychain.
|
|
38
|
+
keychainProbe?: () => boolean;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export interface InstallSystemToolOptions {
|
|
@@ -103,6 +111,7 @@ export async function checkSystemTools(
|
|
|
103
111
|
const exists = options.exists ?? existsSync;
|
|
104
112
|
const env = options.env ?? process.env;
|
|
105
113
|
const home = options.home ?? os.homedir();
|
|
114
|
+
const platform = options.platform ?? process.platform;
|
|
106
115
|
|
|
107
116
|
// 1. git
|
|
108
117
|
const gitBin = await which("git");
|
|
@@ -134,26 +143,33 @@ export async function checkSystemTools(
|
|
|
134
143
|
const res = await exec([claudeBin, "--version"]);
|
|
135
144
|
const version = res.stdout.trim().replace(/^claude-code\//, "");
|
|
136
145
|
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
// The rule a run applies (U2, security/claude-credential.ts): a Claude
|
|
147
|
+
// credential variable (CRYSK_CLAUDE_* first, then the CLI's own names), or
|
|
148
|
+
// the machine's own login. `~/.claude.json` and `~/.claude/session.json` do
|
|
149
|
+
// not count: every Claude user has the first, API-key users included. The
|
|
150
|
+
// login half is defaultClaudeLoginPresent itself, over the injected `exists`,
|
|
151
|
+
// `home`, `platform` and `keychainProbe`: the CLI's OAuth store, or on macOS
|
|
152
|
+
// the Keychain item (R001, #494), so the doctor says what the run will choose.
|
|
153
|
+
const loginPresent = defaultClaudeLoginPresent(
|
|
154
|
+
{ HOME: home },
|
|
155
|
+
{
|
|
156
|
+
platform,
|
|
157
|
+
existsFn: exists,
|
|
158
|
+
...(options.keychainProbe === undefined
|
|
159
|
+
? {}
|
|
160
|
+
: { keychainProbe: options.keychainProbe }),
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
const presence = claudeCredentialPresence(env, loginPresent);
|
|
164
|
+
const authOk =
|
|
165
|
+
presence.subscription !== undefined || presence.api_key !== undefined;
|
|
150
166
|
claudeStatus = {
|
|
151
167
|
installed: true,
|
|
152
168
|
version: version.length > 0 ? version : undefined,
|
|
153
169
|
authOk,
|
|
154
170
|
hint: authOk
|
|
155
171
|
? undefined
|
|
156
|
-
: "Run 'claude' in your terminal to
|
|
172
|
+
: "Run 'claude' in your terminal to log in, or set CRYSK_CLAUDE_OAUTH_TOKEN (from 'claude setup-token') or CRYSK_CLAUDE_API_KEY",
|
|
157
173
|
};
|
|
158
174
|
}
|
|
159
175
|
|
|
@@ -273,8 +289,9 @@ export async function installSystemTool(
|
|
|
273
289
|
// can happen in — see spec.md §4.1's two scenarios:
|
|
274
290
|
// - Inside GitHub Actions: are the required secrets present? Presence
|
|
275
291
|
// only, NEVER a value, a prefix, or a length — see CLAUDE.md's "Never
|
|
276
|
-
// leak secrets into generated output" rule. Review auth is
|
|
277
|
-
//
|
|
292
|
+
// leak secrets into generated output" rule. Review auth is a Claude
|
|
293
|
+
// credential by U2's rule (CRYSK_CLAUDE_* first) OR the OpenCode auth
|
|
294
|
+
// file at resolveOpenCodeAuthPath().
|
|
278
295
|
// - In a local repo: is a pr-hero workflow configured at all?
|
|
279
296
|
// Deliberately does NOT verify the workflow file is git-committed (spec's
|
|
280
297
|
// "present and committed" local scenario) — that needs a git call, and the
|
|
@@ -304,27 +321,37 @@ export function checkCiConfiguration(
|
|
|
304
321
|
if (options.isCi) {
|
|
305
322
|
const exists = options.exists ?? existsSync;
|
|
306
323
|
const hasGithubToken = Boolean(env.GITHUB_TOKEN?.trim());
|
|
324
|
+
// U2's rule, the one a run chooses by: CRYSK_CLAUDE_* first (what the action's
|
|
325
|
+
// crysk-secrets input carries, U5), then the CLI's names; a whitespace-only value
|
|
326
|
+
// is absent and ANTHROPIC_AUTH_TOKEN never counts. No login: a hosted runner has none.
|
|
327
|
+
const presence = claudeCredentialPresence(env, false);
|
|
307
328
|
const hasClaudeAuth =
|
|
308
|
-
|
|
309
|
-
Boolean(env.CLAUDE_CODE_OAUTH_TOKEN?.trim());
|
|
329
|
+
presence.subscription !== undefined || presence.api_key !== undefined;
|
|
310
330
|
const hasOpenCodeAuth = exists(resolveOpenCodeAuthPath(env));
|
|
311
331
|
const hasReviewAuth = hasClaudeAuth || hasOpenCodeAuth;
|
|
312
332
|
|
|
313
333
|
const missing: string[] = [];
|
|
314
334
|
if (!hasGithubToken) missing.push("GITHUB_TOKEN");
|
|
315
|
-
if (!hasReviewAuth)
|
|
335
|
+
if (!hasReviewAuth) {
|
|
336
|
+
missing.push("CRYSK_CLAUDE_OAUTH_TOKEN (or CRYSK_CLAUDE_API_KEY)");
|
|
337
|
+
}
|
|
316
338
|
|
|
317
339
|
if (missing.length === 0) {
|
|
318
340
|
return {
|
|
319
341
|
configured: true,
|
|
320
342
|
message:
|
|
321
|
-
"Required CI secrets are present (GITHUB_TOKEN,
|
|
343
|
+
"Required CI secrets are present (GITHUB_TOKEN, a CRYSK_CLAUDE_* credential or OpenCode auth)",
|
|
322
344
|
};
|
|
323
345
|
}
|
|
324
346
|
return {
|
|
325
347
|
configured: false,
|
|
326
348
|
message: `Missing required CI secret(s): ${missing.join(", ")}`,
|
|
327
|
-
hint:
|
|
349
|
+
hint:
|
|
350
|
+
"Set the missing secret(s) as repository secrets (`claude setup-token`, then " +
|
|
351
|
+
"`gh secret set CRYSK_CLAUDE_OAUTH_TOKEN`) and pass each in the Crysk action's " +
|
|
352
|
+
// Spliced so the GitHub expression is not read as a template placeholder.
|
|
353
|
+
"`crysk-secrets` input as a `NAME=$" +
|
|
354
|
+
"{{ secrets.NAME }}` line — never echo their values.",
|
|
328
355
|
};
|
|
329
356
|
}
|
|
330
357
|
|
|
@@ -3,7 +3,11 @@ import os from "node:os";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { capabilityGateDecision } from "#model/provider-capabilities";
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
planRoutes,
|
|
8
|
+
type ResolvedRoutePlan,
|
|
9
|
+
type ResolvedStepRoute,
|
|
10
|
+
} from "#model/routing";
|
|
7
11
|
import { type AssetMode, detectAssetMode } from "./assets";
|
|
8
12
|
// Route-keyed transport factory/cache: one ProviderTransport instance per
|
|
9
13
|
// `${backend}:${routeFingerprint}`. `release()` drops a lease; teardown order
|
|
@@ -492,6 +496,10 @@ export interface TransportFactoryOptions {
|
|
|
492
496
|
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
493
497
|
// #149: the credential broker the authority resolved for the opencode
|
|
494
498
|
// backend. The server runs under its projection for the servers whole life.
|
|
499
|
+
// U4: on the registry it is only the default, set when the plan runs on one
|
|
500
|
+
// OpenCode credential; each binding passes its own on get() (acquire), and
|
|
501
|
+
// `{ ...defaultOptions, ...options }` lets that one win, so a plan on several
|
|
502
|
+
// credentials gives each route's server its own broker.
|
|
495
503
|
readonly credentialBroker?: CredentialBroker;
|
|
496
504
|
// #133: the KIND that broker was resolved for. Travels beside it and is
|
|
497
505
|
// only ever meaningful as a pair — see openCodeLaunchServerFor.
|
|
@@ -971,7 +979,9 @@ export async function admitRoutePlan(
|
|
|
971
979
|
const reports = new Map<RunnerBackend, ProviderCapabilityReport>();
|
|
972
980
|
const mode = options.mode ?? "production";
|
|
973
981
|
|
|
974
|
-
|
|
982
|
+
// Every route the plan may run, fallbacks included (S4): a fallback on a
|
|
983
|
+
// backend that is not admissible fails here, before anything spends.
|
|
984
|
+
for (const step of planRoutes(plan)) {
|
|
975
985
|
const backend = step.route.backend;
|
|
976
986
|
|
|
977
987
|
if (!registry.has(backend)) {
|