crysk 0.3.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -17
- package/config/models/anthropic.json +1 -1
- package/dist/SKILL-dsnffnfp.md +140 -0
- package/dist/SKILL-gnrbph72.md +140 -0
- package/dist/SKILL-k4k0zn1w.md +143 -0
- package/dist/SKILL-kq0xejn3.md +553 -0
- package/dist/SKILL-qaqsbygw.md +66 -0
- package/dist/SKILL-vhb4c3vv.md +553 -0
- package/dist/SKILL-vws0aqb8.md +553 -0
- package/dist/SKILL-xpf6kmdw.md +74 -0
- package/dist/ci-admission-0ken6ehx.md +128 -0
- package/dist/ci-admission-t0f5qwth.md +128 -0
- package/dist/cli.js +3366 -1680
- package/dist/index.js +1884 -947
- package/dist/opencode-ci-ac5zksdn.md +106 -0
- package/dist/workflow-4pkyck01.yml +160 -0
- package/package.json +2 -2
- package/prompts/default/PROVENANCE.md +1 -0
- package/skills/crysk/SKILL.md +16 -16
- package/skills/crysk-ci-setup/SKILL.md +42 -39
- package/skills/crysk-ci-setup/assets/workflow.yml +31 -22
- package/skills/crysk-ci-setup/references/ci-admission.md +2 -2
- package/skills/crysk-ci-setup/references/opencode-ci.md +53 -88
- package/skills/crysk-loop/SKILL.md +20 -9
- package/skills/crysk-pr/SKILL.md +1 -1
- package/src/asset-manifest.ts +0 -4
- package/src/assets.ts +2 -2
- 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 +31 -42
- package/src/ci/outcome.ts +421 -330
- package/src/ci/platform-config.ts +127 -0
- package/src/ci/platform-report.ts +935 -0
- package/src/ci/platform-trace.ts +551 -0
- package/src/ci/platform.ts +465 -0
- package/src/ci/publish.ts +19 -6
- package/src/ci/reporter.ts +9 -7
- package/src/ci/review-admission.ts +8 -4
- package/src/ci/review-levels.ts +8 -7
- package/src/ci/run.ts +88 -0
- package/src/ci/setup.ts +547 -109
- 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/compare/loop.ts +9 -1
- package/src/compare/martian-adapter.ts +1 -1
- 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 +71 -11
- package/src/pr/ci-admission-gate.ts +2 -1
- package/src/pr/finding-state-record.ts +58 -0
- package/src/pr/gate-record.ts +22 -0
- package/src/pr/inline.ts +3 -0
- package/src/pr/plan.ts +20 -4
- package/src/pr/posting.ts +4 -0
- package/src/pr/pr-status.ts +27 -7
- package/src/pr/pr.ts +39 -8
- package/src/pr/preflight.ts +44 -2
- package/src/pr/publish-outcome.ts +11 -3
- package/src/pr/review-pr.ts +20 -4
- package/src/pr/target.ts +12 -3
- package/src/production-runtime.ts +760 -331
- package/src/rereview/classify.ts +4 -0
- package/src/rereview/prepare.ts +47 -22
- package/src/rereview/state.ts +34 -8
- package/src/review/pipeline.ts +277 -101
- package/src/review/preflight.ts +201 -294
- package/src/review/report.ts +60 -40
- 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/published-text.ts +161 -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/triage/triage.ts +2 -1
- 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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Text a model wrote about author-controlled input, on its way to a public
|
|
2
|
+
// surface: PR comments, the step summary, the state block. A pull request can
|
|
3
|
+
// steer what the model says, so GitHub must not act on any of it.
|
|
4
|
+
//
|
|
5
|
+
// WHY shapes and not the keyword rules of redact.ts: those are for error
|
|
6
|
+
// messages, where `password hunter2` is a leak. A finding is ABOUT code, so
|
|
7
|
+
// "the password field" and `const TOKEN = getToken()` have to survive it.
|
|
8
|
+
//
|
|
9
|
+
// WHY every repeat that can start at many positions has a bound: this runs on
|
|
10
|
+
// whatever the model printed, and one long word must not stall publication.
|
|
11
|
+
//
|
|
12
|
+
// What each defusal does was checked against GitHub's own renderer
|
|
13
|
+
// (`gh api markdown --mode gfm`), not assumed.
|
|
14
|
+
|
|
15
|
+
const REDACTED = "[REDACTED]";
|
|
16
|
+
const ZERO_WIDTH_SPACE = "\u200b";
|
|
17
|
+
|
|
18
|
+
// `(?<![A-Za-z0-9])` instead of `\b`: `\b` does not fire after `_`, and
|
|
19
|
+
// `_ghp_..._` is a token in Markdown emphasis.
|
|
20
|
+
const SECRET_SHAPES: readonly RegExp[] = [
|
|
21
|
+
/(?<![A-Za-z0-9])gh[pousr]_[A-Za-z0-9_]{20,}/g,
|
|
22
|
+
/(?<![A-Za-z0-9])github_pat_[A-Za-z0-9_]{20,}/g,
|
|
23
|
+
/(?<![A-Za-z0-9])glpat-[A-Za-z0-9_-]{20,}/g,
|
|
24
|
+
/(?<![A-Za-z0-9])(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
|
|
25
|
+
// The prefixed form and the older unbroken form. A bare `sk-` plus hyphens is
|
|
26
|
+
// what a CSS class looks like.
|
|
27
|
+
/(?<![A-Za-z0-9])sk-(?:ant|proj|svcacct|admin)-[A-Za-z0-9_-]{16,}/g,
|
|
28
|
+
/(?<![A-Za-z0-9])sk-[A-Za-z0-9]{32,}/g,
|
|
29
|
+
/(?<![A-Za-z0-9])[sr]k_(?:live|test)_[A-Za-z0-9]{16,}/g,
|
|
30
|
+
/(?<![A-Za-z0-9])xox[abeoprs]-[A-Za-z0-9-]{10,}/g,
|
|
31
|
+
/(?<![A-Za-z0-9])AIza[A-Za-z0-9_-]{35}/g,
|
|
32
|
+
/(?<![A-Za-z0-9])npm_[A-Za-z0-9]{36}\b/g,
|
|
33
|
+
/(?<![A-Za-z0-9])eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}/g,
|
|
34
|
+
// A digit is required: `Bearer verifyAccessTokenSignature` names a function.
|
|
35
|
+
/(?<![A-Za-z0-9])Bearer\s+(?=[A-Za-z0-9._~+/=-]{0,512}\d)[A-Za-z0-9._~+/=-]{20,}/gi,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
// `user:password@`, or a long user-only token. `git@` is a username, and `$`,
|
|
39
|
+
// `{` and `<` mean a placeholder (`redis://:${REDIS_PASSWORD}@cache`).
|
|
40
|
+
const URL_CREDENTIALS =
|
|
41
|
+
/(?<![A-Za-z0-9+.-])([a-z][a-z0-9+.-]{0,30}:\/\/)(?:[^\s/?#${<]{0,256}:[^\s/?#${<]{1,256}|[^\s/?#${<:@]{20,256})@/gi;
|
|
42
|
+
|
|
43
|
+
// A secret name followed by a value. The name alone decides nothing, because code
|
|
44
|
+
// is full of these: `TOKEN=getToken`, `API_KEY = "x-api-key"`, `SECRET: Uint8Array`.
|
|
45
|
+
// So isSecretValue reads the value.
|
|
46
|
+
const SECRET_ASSIGNMENT =
|
|
47
|
+
/(?<![A-Za-z0-9_-])(["']?)((?:[A-Za-z0-9_-]{0,40}[_-])?(?:password|passwd|secret|token|api[_-]?key|private[_-]?key|credentials?)(?:[_-][A-Za-z0-9_-]{0,40})?)\1(\s*[=:](?![=:])\s*)("[^"\n]{1,256}"|'[^'\n]{1,256}'|[^\s"',;]{1,256})/gi;
|
|
48
|
+
|
|
49
|
+
// A digit is the signal: a literal with one is rarely a word or an identifier. A
|
|
50
|
+
// password holds no such promise, so a password name also takes letters alone,
|
|
51
|
+
// unless the value only repeats the word (`PASSWORD = "password"`). This leaves
|
|
52
|
+
// letter-only values of other names, such as `API_KEY=hunter`: nothing tells them
|
|
53
|
+
// from `API_KEY=config`.
|
|
54
|
+
function isSecretValue(name: string, separator: string, raw: string): boolean {
|
|
55
|
+
const quoted = raw.startsWith('"') || raw.startsWith("'");
|
|
56
|
+
const value = quoted ? raw.slice(1, -1) : raw;
|
|
57
|
+
if (value.length < 6 || /^[\d_,.]+$/.test(value) || value.includes("$")) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// `config/credentials:100-120` is a file and a line range, nothing else.
|
|
61
|
+
if (separator === ":" && /^\d+-\d+$/.test(value)) return false;
|
|
62
|
+
const colon = separator.includes(":");
|
|
63
|
+
if (!quoted) {
|
|
64
|
+
// Spaces around `=` are source code, and a bracket or a dot is an expression.
|
|
65
|
+
if (!colon && separator !== "=") return false;
|
|
66
|
+
if (/[.()[\]{}<>]/.test(value)) return false;
|
|
67
|
+
// A type annotation: `SECRET: Uint8Array`.
|
|
68
|
+
if (colon && /^[A-Z][a-z]/.test(value)) return false;
|
|
69
|
+
}
|
|
70
|
+
if (/\d/.test(value)) return true;
|
|
71
|
+
if (!/pass(?:word|wd)$/i.test(name) || /pass(?:word|wd)/i.test(value)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// `password: string` is a type. An upper-case name is a config key.
|
|
75
|
+
return quoted || !colon || name === name.toUpperCase();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const PEM_BEGIN = /-----BEGIN [A-Z0-9 ]{0,40}PRIVATE KEY(?: BLOCK)?-----/g;
|
|
79
|
+
const PEM_END = /-----END [A-Z0-9 ]{0,40}PRIVATE KEY(?: BLOCK)?-----/g;
|
|
80
|
+
const PEM_BODY = /(?:\s*[A-Za-z0-9+/=]{16,})*/y;
|
|
81
|
+
|
|
82
|
+
// Up to the closing line, or, when that was cut off, across the base64 lines:
|
|
83
|
+
// half a private key is still a private key, and the sentence after it is not
|
|
84
|
+
// part of the key. A loop and not one regex, so many openers with no closer stay
|
|
85
|
+
// linear.
|
|
86
|
+
function redactPrivateKeys(text: string): string {
|
|
87
|
+
if (!text.includes("PRIVATE KEY")) return text;
|
|
88
|
+
let out = "";
|
|
89
|
+
let from = 0;
|
|
90
|
+
let noMoreEnds = false;
|
|
91
|
+
PEM_BEGIN.lastIndex = 0;
|
|
92
|
+
for (;;) {
|
|
93
|
+
const begin = PEM_BEGIN.exec(text);
|
|
94
|
+
if (begin === null) break;
|
|
95
|
+
let to = PEM_BEGIN.lastIndex;
|
|
96
|
+
let closed = false;
|
|
97
|
+
if (!noMoreEnds) {
|
|
98
|
+
PEM_END.lastIndex = to;
|
|
99
|
+
closed = PEM_END.test(text);
|
|
100
|
+
if (closed) to = PEM_END.lastIndex;
|
|
101
|
+
else noMoreEnds = true;
|
|
102
|
+
}
|
|
103
|
+
if (!closed) {
|
|
104
|
+
PEM_BODY.lastIndex = to;
|
|
105
|
+
PEM_BODY.test(text);
|
|
106
|
+
to = PEM_BODY.lastIndex;
|
|
107
|
+
}
|
|
108
|
+
out += text.slice(from, begin.index) + REDACTED;
|
|
109
|
+
from = to;
|
|
110
|
+
PEM_BEGIN.lastIndex = to;
|
|
111
|
+
}
|
|
112
|
+
return out + text.slice(from);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function redactSecrets(text: string): string {
|
|
116
|
+
let out = redactPrivateKeys(text);
|
|
117
|
+
for (const shape of SECRET_SHAPES) out = out.replace(shape, REDACTED);
|
|
118
|
+
return out
|
|
119
|
+
.replace(URL_CREDENTIALS, `$1${REDACTED}@`)
|
|
120
|
+
.replace(
|
|
121
|
+
SECRET_ASSIGNMENT,
|
|
122
|
+
(
|
|
123
|
+
match: string,
|
|
124
|
+
quote: string,
|
|
125
|
+
name: string,
|
|
126
|
+
separator: string,
|
|
127
|
+
raw: string,
|
|
128
|
+
) =>
|
|
129
|
+
isSecretValue(name, separator, raw)
|
|
130
|
+
? `${quote}${name}${quote}${separator}${REDACTED}`
|
|
131
|
+
: match,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// A secret was removed from this text, so the words around it are not all the
|
|
136
|
+
// words the model wrote. A guard reading it for safety content must not treat it
|
|
137
|
+
// as complete.
|
|
138
|
+
export function wasRedacted(text: string): boolean {
|
|
139
|
+
return text.includes(REDACTED);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// A zero-width space reads the same and stops GitHub from parsing a mention, an
|
|
143
|
+
// image or a tag out of the text. Breaking `<` also means no model text can spell
|
|
144
|
+
// a marker the comment parsers read. `@` after a letter, digit or `/` is left
|
|
145
|
+
// alone because GitHub does not read it as a mention, and emails, URLs and
|
|
146
|
+
// `src/@types` stay copyable. `&` is broken because `@octocat` IS a mention.
|
|
147
|
+
//
|
|
148
|
+
// Idempotent, because a posted claim is read back from its comment and rendered
|
|
149
|
+
// again.
|
|
150
|
+
function defuseMarkup(text: string): string {
|
|
151
|
+
return text
|
|
152
|
+
.replace(/(?<![A-Za-z0-9/])@(?!\u200b)/g, `@${ZERO_WIDTH_SPACE}`)
|
|
153
|
+
.replace(/&(?=#|commat)/gi, `&${ZERO_WIDTH_SPACE}`)
|
|
154
|
+
.replaceAll("![", `!${ZERO_WIDTH_SPACE}[`)
|
|
155
|
+
.replace(/<(?=[a-zA-Z/!?])/g, `<${ZERO_WIDTH_SPACE}`)
|
|
156
|
+
.replaceAll("-->", `--${ZERO_WIDTH_SPACE}>`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function publishedText(text: string): string {
|
|
160
|
+
return defuseMarkup(redactSecrets(text));
|
|
161
|
+
}
|
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)) {
|
|
@@ -2,9 +2,13 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { lstatSync, readFileSync } from "node:fs";
|
|
3
3
|
import { isEffort } from "#model/catalog";
|
|
4
4
|
import { CLAUDE_CAPABILITY_STATICS } from "#model/provider-capabilities";
|
|
5
|
-
import {
|
|
5
|
+
import { claudeCliModel } from "#model/routing";
|
|
6
6
|
import type { BucketScope } from "../execution/bucket-id";
|
|
7
7
|
import { deriveBucketId } from "../execution/bucket-id";
|
|
8
|
+
import {
|
|
9
|
+
newClaudeSessionId,
|
|
10
|
+
retainClaudeSession,
|
|
11
|
+
} from "../execution/claude-session-trace";
|
|
8
12
|
import type {
|
|
9
13
|
FailureCredential,
|
|
10
14
|
ObservedModel,
|
|
@@ -745,7 +749,7 @@ export class ClaudeCodeCliTransport implements ProviderTransport {
|
|
|
745
749
|
"--permission-mode",
|
|
746
750
|
"bypassPermissions",
|
|
747
751
|
"--model",
|
|
748
|
-
|
|
752
|
+
claudeCliModel(request.route),
|
|
749
753
|
"--effort",
|
|
750
754
|
request.effort,
|
|
751
755
|
// Moves the per-machine sections (cwd, env info, git status) out of the
|
|
@@ -758,6 +762,13 @@ export class ClaudeCodeCliTransport implements ProviderTransport {
|
|
|
758
762
|
"--exclude-dynamic-system-prompt-sections",
|
|
759
763
|
);
|
|
760
764
|
|
|
765
|
+
// The engine names the session so its transcript can be found however
|
|
766
|
+
// the attempt ends, including a timeout, a kill or a cancel that leaves no
|
|
767
|
+
// result to read the id from. `-p` never resumes, so a fresh id per spawn
|
|
768
|
+
// cannot collide.
|
|
769
|
+
const claudeSessionId = newClaudeSessionId();
|
|
770
|
+
args.push("--session-id", claudeSessionId);
|
|
771
|
+
|
|
761
772
|
const start = performance.now();
|
|
762
773
|
|
|
763
774
|
// §6.3: hash/mode/symlink verification happens immediately before spawn;
|
|
@@ -821,6 +832,7 @@ export class ClaudeCodeCliTransport implements ProviderTransport {
|
|
|
821
832
|
}
|
|
822
833
|
|
|
823
834
|
ACTIVE_CHILD_PROCS.add(proc);
|
|
835
|
+
retainClaudeSession(request, claudeSessionId);
|
|
824
836
|
|
|
825
837
|
let cascadePromise: Promise<CascadeResult> | undefined;
|
|
826
838
|
let provenPgid: number | undefined;
|
|
@@ -969,6 +981,10 @@ export class ClaudeCodeCliTransport implements ProviderTransport {
|
|
|
969
981
|
...(escalatedToKill ? { signal: "SIGKILL" } : {}),
|
|
970
982
|
};
|
|
971
983
|
|
|
984
|
+
// The result's `session_id` is not read for the transcript: the id passed
|
|
985
|
+
// as `--session-id` is the one retained at spawn, and it wins if the two
|
|
986
|
+
// ever differ, because only it exists on every way an attempt ends.
|
|
987
|
+
//
|
|
972
988
|
// The CLI exits 0 when the API rejected the request, with the provider's message in
|
|
973
989
|
// `result`. That message is not the agent's answer: it fails the attempt with its
|
|
974
990
|
// typed cause, is never handed to the draft parser (which would spend a format retry
|
|
@@ -1292,6 +1308,9 @@ function oneLine(words: string, room: number): string {
|
|
|
1292
1308
|
|
|
1293
1309
|
// The secret the child ran on. The per-token variables (the list envBillsMetered reads) win
|
|
1294
1310
|
// over CLAUDE_CODE_OAUTH_TOKEN, and a whitespace-only value is no credential (the same trim).
|
|
1311
|
+
// Since S5 a review run's child holds exactly one of them (the credential chosen at run
|
|
1312
|
+
// start, security/claude-credential.ts), so the precedence below only decides for callers
|
|
1313
|
+
// that build their own env.
|
|
1295
1314
|
//
|
|
1296
1315
|
// The precedence is observed, not assumed. With CLI 2.1.312 and both an API key and an
|
|
1297
1316
|
// OAuth login present, the CLI prints "claude.ai connectors are disabled because
|
|
@@ -1131,14 +1131,16 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
1131
1131
|
});
|
|
1132
1132
|
});
|
|
1133
1133
|
|
|
1134
|
-
// `request.effort` is deliberately NOT forwarded.
|
|
1135
|
-
// CLI
|
|
1136
|
-
// per-model reasoning variants, whose
|
|
1137
|
-
//
|
|
1138
|
-
//
|
|
1139
|
-
//
|
|
1140
|
-
//
|
|
1141
|
-
//
|
|
1134
|
+
// `request.effort` is deliberately NOT forwarded. It is on the Claude
|
|
1135
|
+
// Code CLI's scale (`claude --effort`, #299); OpenCode's equivalent is
|
|
1136
|
+
// per-model reasoning variants, whose names differ by provider, so
|
|
1137
|
+
// mapping one onto the other here would invent a meaning. A variant
|
|
1138
|
+
// reaches OpenCode only when a `models` entry names one as its `effort`
|
|
1139
|
+
// (S7): it is the route's `modelVariant`, sent with the model by the
|
|
1140
|
+
// client (transport-registry.ts), and admission has checked it against
|
|
1141
|
+
// the model's variants. Without one, no variant is sent (D1), the
|
|
1142
|
+
// request plan records the level as intent with `effortApplied: false`
|
|
1143
|
+
// (attempt-evidence.ts), and pipeline.json says `effort_applied: false`.
|
|
1142
1144
|
createPromise = this.client.createSession({
|
|
1143
1145
|
correlation: { sessionId: request.sessionId, attempt: request.attempt },
|
|
1144
1146
|
signal: operation.signal,
|
|
@@ -2245,7 +2247,7 @@ export class OpenCodeSdkTransport implements ProviderTransport {
|
|
|
2245
2247
|
// true is the provider asking for another attempt; that is the transient
|
|
2246
2248
|
// budget, never the format one.
|
|
2247
2249
|
// A refusal whose slot reports HTTP 404 names a model the provider does not
|
|
2248
|
-
// serve: no retry can make it exist, and
|
|
2250
|
+
// serve: no retry can make it exist, and CRYSK-MODEL-UNAVAILABLE says so with
|
|
2249
2251
|
// the provider's name. Only the status slot decides, never the message.
|
|
2250
2252
|
if (
|
|
2251
2253
|
witness.includes(MARKER_PROVIDER_REFUSAL) &&
|
|
@@ -455,16 +455,13 @@ export async function launchProjectedOpenCodeServer(
|
|
|
455
455
|
// route by runner-authority.ts's credentialKindForRoute, and this server
|
|
456
456
|
// is handed the one its binding resolved.
|
|
457
457
|
//
|
|
458
|
-
//
|
|
459
|
-
//
|
|
460
|
-
//
|
|
461
|
-
//
|
|
462
|
-
//
|
|
463
|
-
//
|
|
464
|
-
//
|
|
465
|
-
// prices those routes, this becomes reachable and needs a server per
|
|
466
|
-
// credential; until then it must fail LOUD, which it does — a broker
|
|
467
|
-
// handed the wrong kind refuses it by name.
|
|
458
|
+
// U4 (S9): this server serves ONE route (the registry caches one
|
|
459
|
+
// transport, so one client and one server, per route fingerprint), and
|
|
460
|
+
// its broker is that route's own, forwarded by FrozenRuntimeBinding.
|
|
461
|
+
// acquire(). A plan naming several providers, or a free model beside a
|
|
462
|
+
// metered one, therefore gets one server per route, each projected with
|
|
463
|
+
// only its credential's record; a broker handed the wrong kind still
|
|
464
|
+
// refuses it by name.
|
|
468
465
|
sessionId: "opencode-server",
|
|
469
466
|
credentialRef: "opencode-auth",
|
|
470
467
|
kind: credentialKind,
|
package/src/triage/triage.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// sides agree on.
|
|
11
11
|
//
|
|
12
12
|
import { MARKER_OPEN, matchMarkerPrefix } from "../brand";
|
|
13
|
+
import { publishedText } from "../security/published-text";
|
|
13
14
|
|
|
14
15
|
// Disjoint from PR_COMMENT_MARKER_PREFIX and PR_FINDING_MARKER_PREFIX on
|
|
15
16
|
// purpose, same reasoning as their own disjointness (pr/preflight.ts): a
|
|
@@ -129,7 +130,7 @@ export function renderTriageReplyBody(
|
|
|
129
130
|
reasoning: string,
|
|
130
131
|
): string {
|
|
131
132
|
const head = `${triageMarker(fields)}\n\n${triageBadge(fields)}`;
|
|
132
|
-
const prose = reasoning.trim();
|
|
133
|
+
const prose = publishedText(reasoning.trim());
|
|
133
134
|
return prose.length === 0 ? `${head}\n` : `${head}\n\n${prose}\n`;
|
|
134
135
|
}
|
|
135
136
|
|