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,480 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, open, unlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
EXPRESSION_VALUE,
|
|
6
|
+
isNonSecretValue,
|
|
7
|
+
isSecretName,
|
|
8
|
+
nameParts,
|
|
9
|
+
redactEvidenceText,
|
|
10
|
+
redactSecretShapes,
|
|
11
|
+
} from "../security/evidence-redaction";
|
|
12
|
+
import type { TransportRequest } from "./contracts";
|
|
13
|
+
|
|
14
|
+
export const CLAUDE_TRACE_MISSES = [
|
|
15
|
+
"session file missing",
|
|
16
|
+
"more than one session file",
|
|
17
|
+
"session trace write failed",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export type ClaudeTraceMiss = (typeof CLAUDE_TRACE_MISSES)[number];
|
|
21
|
+
|
|
22
|
+
// The transport names the CLI's session; the harness owns the run-dir path.
|
|
23
|
+
// The request object is the only value both already hold, so the id crosses
|
|
24
|
+
// without a new field on TransportRequest or TransportOutcome.
|
|
25
|
+
const retained = new WeakMap<TransportRequest, string>();
|
|
26
|
+
|
|
27
|
+
export function claudeSessionTracePath(
|
|
28
|
+
outPath: string,
|
|
29
|
+
stepName: string,
|
|
30
|
+
attempt: number,
|
|
31
|
+
): string {
|
|
32
|
+
return path.join(
|
|
33
|
+
path.dirname(outPath),
|
|
34
|
+
`trace.${stepName}.attempt${attempt}.jsonl`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function claudeTraceCaptureAnnotation(reason: ClaudeTraceMiss): string {
|
|
39
|
+
return `[pr-hero] claude session trace was not copied (${reason})`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A fresh id for the CLI's `--session-id`, which requires a UUID. The engine
|
|
43
|
+
// picks it instead of reading the CLI's result: an attempt that times out, is
|
|
44
|
+
// killed or is cancelled prints no result, yet its session file is written as
|
|
45
|
+
// the conversation goes, and failed attempts are the transcripts that matter
|
|
46
|
+
// most.
|
|
47
|
+
export function newClaudeSessionId(): string {
|
|
48
|
+
return crypto.randomUUID();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Called once the child is spawned, so an attempt that never started a CLI
|
|
52
|
+
// (prompt integrity denied, execve refused) has no transcript to look for.
|
|
53
|
+
export function retainClaudeSession(
|
|
54
|
+
request: TransportRequest,
|
|
55
|
+
sessionId: string,
|
|
56
|
+
): void {
|
|
57
|
+
retained.set(request, sessionId);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function findSessionFile(
|
|
61
|
+
configHome: string,
|
|
62
|
+
sessionId: string,
|
|
63
|
+
): Promise<string | ClaudeTraceMiss> {
|
|
64
|
+
const projects = path.join(configHome, "projects");
|
|
65
|
+
if (!existsSync(projects)) return "session file missing";
|
|
66
|
+
const matches: string[] = [];
|
|
67
|
+
const glob = new Bun.Glob(`**/${sessionId}.jsonl`);
|
|
68
|
+
for await (const relative of glob.scan({ cwd: projects, onlyFiles: true })) {
|
|
69
|
+
matches.push(path.join(projects, relative));
|
|
70
|
+
if (matches.length > 1) return "more than one session file";
|
|
71
|
+
}
|
|
72
|
+
const only = matches[0];
|
|
73
|
+
return only === undefined ? "session file missing" : only;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Copies one attempt's session JSONL into the run dir, whatever way the
|
|
77
|
+
// attempt ended. Undefined means no Claude CLI process was spawned, or the
|
|
78
|
+
// copy landed. A miss string is a warning: the caller must not fail the
|
|
79
|
+
// attempt.
|
|
80
|
+
export async function copyRetainedClaudeSession(
|
|
81
|
+
request: TransportRequest,
|
|
82
|
+
dest: string,
|
|
83
|
+
): Promise<ClaudeTraceMiss | undefined> {
|
|
84
|
+
const noted = retained.get(request);
|
|
85
|
+
if (noted === undefined) {
|
|
86
|
+
await dropStaleTrace(dest);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const source = await findSessionFile(
|
|
91
|
+
request.isolation.syntheticConfigHome,
|
|
92
|
+
noted,
|
|
93
|
+
);
|
|
94
|
+
if (
|
|
95
|
+
source === "session file missing" ||
|
|
96
|
+
source === "more than one session file"
|
|
97
|
+
) {
|
|
98
|
+
await dropStaleTrace(dest);
|
|
99
|
+
return source;
|
|
100
|
+
}
|
|
101
|
+
await copySessionJsonl(source, dest);
|
|
102
|
+
return undefined;
|
|
103
|
+
} catch {
|
|
104
|
+
await dropStaleTrace(dest);
|
|
105
|
+
return "session trace write failed";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// A session file can be any size (a 61 MB one took about 526 MB to redact
|
|
110
|
+
// whole), and several hunters copy at once. So the copy streams: one line at
|
|
111
|
+
// a time, a line over MAX_LINE_BYTES becomes the omitted marker without being
|
|
112
|
+
// held, and the copy stops at MAX_COPY_BYTES with the truncated marker.
|
|
113
|
+
const MAX_LINE_BYTES = 4 * 1024 * 1024;
|
|
114
|
+
const MAX_COPY_BYTES = 64 * 1024 * 1024;
|
|
115
|
+
const OMITTED_LINE = JSON.stringify({ crysk: "session line omitted" });
|
|
116
|
+
const TRUNCATED_LINE = `${JSON.stringify({ crysk: "session truncated" })}\n`;
|
|
117
|
+
const NEWLINE = 0x0a;
|
|
118
|
+
|
|
119
|
+
async function copySessionJsonl(source: string, dest: string): Promise<void> {
|
|
120
|
+
await mkdir(path.dirname(dest), { recursive: true });
|
|
121
|
+
const out = await open(dest, "w");
|
|
122
|
+
const reader = Bun.file(source).stream().getReader();
|
|
123
|
+
const encoder = new TextEncoder();
|
|
124
|
+
const decoder = new TextDecoder();
|
|
125
|
+
const truncatedBytes = encoder.encode(TRUNCATED_LINE).byteLength;
|
|
126
|
+
let written = 0;
|
|
127
|
+
let pending: Uint8Array[] = [];
|
|
128
|
+
let pendingBytes = 0;
|
|
129
|
+
let overLimit = false;
|
|
130
|
+
|
|
131
|
+
// False once the cap is reached: the truncated marker is written instead.
|
|
132
|
+
const emit = async (line: string, newline: boolean): Promise<boolean> => {
|
|
133
|
+
const bytes = encoder.encode(newline ? `${line}\n` : line);
|
|
134
|
+
if (written + bytes.byteLength + truncatedBytes > MAX_COPY_BYTES) {
|
|
135
|
+
await out.write(TRUNCATED_LINE);
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
await out.write(bytes);
|
|
139
|
+
written += bytes.byteLength;
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
const finishLine = (): string => {
|
|
143
|
+
const line = overLimit
|
|
144
|
+
? OMITTED_LINE
|
|
145
|
+
: redactSessionLine(decoder.decode(Buffer.concat(pending)));
|
|
146
|
+
pending = [];
|
|
147
|
+
pendingBytes = 0;
|
|
148
|
+
overLimit = false;
|
|
149
|
+
return line;
|
|
150
|
+
};
|
|
151
|
+
const hold = (bytes: Uint8Array): void => {
|
|
152
|
+
if (overLimit || bytes.byteLength === 0) return;
|
|
153
|
+
if (pendingBytes + bytes.byteLength > MAX_LINE_BYTES) {
|
|
154
|
+
overLimit = true;
|
|
155
|
+
pending = [];
|
|
156
|
+
pendingBytes = 0;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
pending.push(bytes);
|
|
160
|
+
pendingBytes += bytes.byteLength;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
for (;;) {
|
|
165
|
+
const { done, value } = await reader.read();
|
|
166
|
+
if (done) break;
|
|
167
|
+
let start = 0;
|
|
168
|
+
for (
|
|
169
|
+
let at = value.indexOf(NEWLINE);
|
|
170
|
+
at !== -1;
|
|
171
|
+
at = value.indexOf(NEWLINE, start)
|
|
172
|
+
) {
|
|
173
|
+
hold(value.subarray(start, at));
|
|
174
|
+
start = at + 1;
|
|
175
|
+
if (!(await emit(finishLine(), true))) return;
|
|
176
|
+
}
|
|
177
|
+
hold(value.subarray(start));
|
|
178
|
+
}
|
|
179
|
+
if (pendingBytes > 0 || overLimit) await emit(finishLine(), false);
|
|
180
|
+
} finally {
|
|
181
|
+
await reader.cancel().catch(() => undefined);
|
|
182
|
+
await out.close();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The key rule of redactEvidence, kept whole: a match loses its value
|
|
187
|
+
// whatever its type.
|
|
188
|
+
const SESSION_SECRET_KEY =
|
|
189
|
+
/authorization|cookie|password|secret|api.?key|access.?token|refresh.?token|^token$|^key$/i;
|
|
190
|
+
// Wider names for the session copy only. A config file a hunter Reads holds
|
|
191
|
+
// `apiToken`, `github_token`, `private_key`, `session`; OpenCode captures and
|
|
192
|
+
// code windows keep the narrower shared rule. `sessionId` (the CLI's own UUID
|
|
193
|
+
// on every line) and `author` are not credentials.
|
|
194
|
+
const SESSION_SECRET_WORDS = new Set([
|
|
195
|
+
"auth",
|
|
196
|
+
"oauth",
|
|
197
|
+
"cookie",
|
|
198
|
+
"cookies",
|
|
199
|
+
"credential",
|
|
200
|
+
"credentials",
|
|
201
|
+
]);
|
|
202
|
+
function isSessionSecretName(name: string): boolean {
|
|
203
|
+
if (isSecretName(name)) return true;
|
|
204
|
+
const parts = nameParts(name);
|
|
205
|
+
return (
|
|
206
|
+
parts.some((part) => SESSION_SECRET_WORDS.has(part)) ||
|
|
207
|
+
parts.at(-1) === "session"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const MAX_DEPTH = 12;
|
|
211
|
+
const MAX_NODES = 20_000;
|
|
212
|
+
|
|
213
|
+
function redactSessionLine(line: string): string {
|
|
214
|
+
if (line.length === 0) return line;
|
|
215
|
+
try {
|
|
216
|
+
return JSON.stringify(
|
|
217
|
+
redactSessionValue(JSON.parse(line), 0, { nodes: 0 }),
|
|
218
|
+
);
|
|
219
|
+
} catch {
|
|
220
|
+
return OMITTED_LINE;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// One JSON object per line. A line that cannot be redacted is omitted, not copied raw.
|
|
225
|
+
export function redactSessionJsonl(text: string): string {
|
|
226
|
+
const trailingNewline = text.endsWith("\n");
|
|
227
|
+
const lines = text.split("\n");
|
|
228
|
+
if (trailingNewline) lines.pop();
|
|
229
|
+
return (
|
|
230
|
+
lines.map(redactSessionLine).join("\n") + (trailingNewline ? "\n" : "")
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function redactSessionValue(
|
|
235
|
+
value: unknown,
|
|
236
|
+
depth: number,
|
|
237
|
+
budget: { nodes: number },
|
|
238
|
+
): unknown {
|
|
239
|
+
if (++budget.nodes > MAX_NODES || depth > MAX_DEPTH) {
|
|
240
|
+
throw new Error("session redaction limit");
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "string")
|
|
243
|
+
return redactSessionString(value, depth, budget);
|
|
244
|
+
if (Array.isArray(value)) {
|
|
245
|
+
return value.map((item) => redactSessionValue(item, depth + 1, budget));
|
|
246
|
+
}
|
|
247
|
+
if (isPlainObject(value)) {
|
|
248
|
+
const out: Record<string, unknown> = {};
|
|
249
|
+
for (const [key, item] of Object.entries(value)) {
|
|
250
|
+
if (SESSION_SECRET_KEY.test(key)) out[key] = "[REDACTED]";
|
|
251
|
+
else if (isSessionSecretName(key))
|
|
252
|
+
out[key] = redactStrings(item, depth + 1, budget);
|
|
253
|
+
else out[key] = redactSessionValue(item, depth + 1, budget);
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
return redactScalar(value);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Under a credential name every string goes; numbers, booleans and null stay,
|
|
261
|
+
// so a count is never mistaken for a secret.
|
|
262
|
+
function redactStrings(
|
|
263
|
+
value: unknown,
|
|
264
|
+
depth: number,
|
|
265
|
+
budget: { nodes: number },
|
|
266
|
+
): unknown {
|
|
267
|
+
if (++budget.nodes > MAX_NODES || depth > MAX_DEPTH) {
|
|
268
|
+
throw new Error("session redaction limit");
|
|
269
|
+
}
|
|
270
|
+
if (typeof value === "string") return "[REDACTED]";
|
|
271
|
+
if (Array.isArray(value)) {
|
|
272
|
+
return value.map((item) => redactStrings(item, depth + 1, budget));
|
|
273
|
+
}
|
|
274
|
+
if (isPlainObject(value)) {
|
|
275
|
+
const out: Record<string, unknown> = {};
|
|
276
|
+
for (const [key, item] of Object.entries(value)) {
|
|
277
|
+
out[key] = redactStrings(item, depth + 1, budget);
|
|
278
|
+
}
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
return redactScalar(value);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
285
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
const proto = Object.getPrototypeOf(value);
|
|
289
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
290
|
+
throw new Error("non-JSON session value");
|
|
291
|
+
}
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function redactScalar(value: unknown): unknown {
|
|
296
|
+
if (
|
|
297
|
+
value === null ||
|
|
298
|
+
typeof value === "boolean" ||
|
|
299
|
+
typeof value === "number"
|
|
300
|
+
) {
|
|
301
|
+
return value;
|
|
302
|
+
}
|
|
303
|
+
throw new Error("non-JSON session value");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// The trace's copy of redactDiagnostic (src/security/redact.ts), which stays
|
|
307
|
+
// as it is because config validation relies on it. Its key shapes are kept,
|
|
308
|
+
// except that `sk-` must start a word, as in redactEvidenceText: `crysk-loop`
|
|
309
|
+
// is a path, not a key. Its keyword rule read a workflow file as credentials
|
|
310
|
+
// (`id-token: write`, `github-token: ${{ github.token }}`, "an id-token so
|
|
311
|
+
// the run"), so the trace's rule differs in four ways: a value never sits on
|
|
312
|
+
// the next line (a YAML value there is redactSecretShapes' job), an expression
|
|
313
|
+
// is read whole, a value that cannot be a secret is kept (isNonSecretValue),
|
|
314
|
+
// and after only a space a token or API key value must look like a key.
|
|
315
|
+
const TRACE_KEY_SHAPES: readonly RegExp[] = [
|
|
316
|
+
/(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{8,}/g,
|
|
317
|
+
// Known key bodies need no word boundary, so a key glued to an encoded or
|
|
318
|
+
// escaped prefix (`%3D`, `%22`, `\t`) is still caught; `crysk-loop` is not.
|
|
319
|
+
/sk-(?:ant|proj|or|svcacct|admin)-[A-Za-z0-9_-]{8,}/g,
|
|
320
|
+
/sk-[A-Za-z0-9]{32,}/g,
|
|
321
|
+
/gh[pousr]_[A-Za-z0-9_]{20,}/g,
|
|
322
|
+
/Bearer\s+\S+/gi,
|
|
323
|
+
/AIza[0-9A-Za-z_-]{35}/g,
|
|
324
|
+
/gsk_[A-Za-z0-9]{20,}/g,
|
|
325
|
+
/xai-[A-Za-z0-9]{20,}/g,
|
|
326
|
+
];
|
|
327
|
+
const TRACE_KEYWORD_VALUE = new RegExp(
|
|
328
|
+
String.raw`(api[_-]?key|token|password)([ \t"':=]+)(${EXPRESSION_VALUE}|\S+)`,
|
|
329
|
+
"gi",
|
|
330
|
+
);
|
|
331
|
+
// redactDiagnostic's prose words, still the rule after `password` and a space:
|
|
332
|
+
// "the password swordfish was wrong" hides swordfish.
|
|
333
|
+
const PROSE_AFTER_PASSWORD = new Set([
|
|
334
|
+
"is",
|
|
335
|
+
"was",
|
|
336
|
+
"are",
|
|
337
|
+
"were",
|
|
338
|
+
"has",
|
|
339
|
+
"have",
|
|
340
|
+
"had",
|
|
341
|
+
"will",
|
|
342
|
+
"would",
|
|
343
|
+
"can",
|
|
344
|
+
"could",
|
|
345
|
+
"must",
|
|
346
|
+
"should",
|
|
347
|
+
"not",
|
|
348
|
+
"no",
|
|
349
|
+
"in",
|
|
350
|
+
"on",
|
|
351
|
+
"at",
|
|
352
|
+
"of",
|
|
353
|
+
"or",
|
|
354
|
+
"and",
|
|
355
|
+
"to",
|
|
356
|
+
"for",
|
|
357
|
+
"from",
|
|
358
|
+
"with",
|
|
359
|
+
"expired",
|
|
360
|
+
"invalid",
|
|
361
|
+
"rejected",
|
|
362
|
+
"revoked",
|
|
363
|
+
"missing",
|
|
364
|
+
"required",
|
|
365
|
+
"provided",
|
|
366
|
+
"found",
|
|
367
|
+
"refused",
|
|
368
|
+
"denied",
|
|
369
|
+
]);
|
|
370
|
+
const SENTENCE_END = /[.,;:!?)\]"']+$/;
|
|
371
|
+
|
|
372
|
+
// A token or key written after only a space: a digit, or 16 characters or
|
|
373
|
+
// more in both cases. Prose words ("so", "the", "comes", "—") are neither.
|
|
374
|
+
function looksLikeKeyValue(word: string): boolean {
|
|
375
|
+
return (
|
|
376
|
+
/\d/.test(word) ||
|
|
377
|
+
(/^[A-Za-z0-9_+/=.-]{16,}$/.test(word) &&
|
|
378
|
+
/[a-z]/.test(word) &&
|
|
379
|
+
/[A-Z]/.test(word))
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function redactTraceDiagnostic(text: string): string {
|
|
384
|
+
let redacted = text;
|
|
385
|
+
for (const shape of TRACE_KEY_SHAPES) {
|
|
386
|
+
redacted = redacted.replace(shape, "[REDACTED]");
|
|
387
|
+
}
|
|
388
|
+
return redacted.replace(
|
|
389
|
+
TRACE_KEYWORD_VALUE,
|
|
390
|
+
(match: string, keyword: string, separator: string, value: string) => {
|
|
391
|
+
// Already hidden by an earlier rule: `[REDACTED]`, `[REDACTED HEADER]`.
|
|
392
|
+
if (value.startsWith("[REDACTED")) return match;
|
|
393
|
+
const bare = value.replace(SENTENCE_END, "");
|
|
394
|
+
const hidden = `${keyword}${separator}[REDACTED]`;
|
|
395
|
+
if (!/^[ \t]+$/.test(separator)) {
|
|
396
|
+
return isNonSecretValue(bare, keyword) ? match : hidden;
|
|
397
|
+
}
|
|
398
|
+
if (/^password$/i.test(keyword)) {
|
|
399
|
+
return PROSE_AFTER_PASSWORD.has(bare.toLowerCase()) ? match : hidden;
|
|
400
|
+
}
|
|
401
|
+
return looksLikeKeyValue(value) ? hidden : match;
|
|
402
|
+
},
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// A string that holds JSON (a config file a hunter Read) is redacted twice
|
|
407
|
+
// over: the quote-safe text patterns run on the raw string first, where a key
|
|
408
|
+
// still sits next to its value, then the parse redacts every key and string
|
|
409
|
+
// value. Text patterns that can eat a quote run only on strings that are not
|
|
410
|
+
// JSON, so the parse is never broken by a regex. If the parse fails anyway,
|
|
411
|
+
// the string goes through every text pattern instead.
|
|
412
|
+
function redactSessionString(
|
|
413
|
+
value: string,
|
|
414
|
+
depth: number,
|
|
415
|
+
budget: { nodes: number },
|
|
416
|
+
): string {
|
|
417
|
+
const trimmed = value.trim();
|
|
418
|
+
const wrapped =
|
|
419
|
+
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
|
|
420
|
+
(trimmed.startsWith("[") && trimmed.endsWith("]"));
|
|
421
|
+
if (wrapped) {
|
|
422
|
+
try {
|
|
423
|
+
const inner = JSON.parse(
|
|
424
|
+
redactSecretShapes(trimmed, isSessionSecretName, true),
|
|
425
|
+
) as unknown;
|
|
426
|
+
if (typeof inner === "object" && inner !== null) {
|
|
427
|
+
return JSON.stringify(redactSessionValue(inner, depth + 1, budget));
|
|
428
|
+
}
|
|
429
|
+
} catch {
|
|
430
|
+
// Text that only looks like JSON. The text patterns run on it below.
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return redactTraceDiagnostic(
|
|
434
|
+
redactEvidenceText(redactSecretShapes(value, isSessionSecretName, true)),
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// The session copy's string rules, for text that leaves the runner in a review
|
|
439
|
+
// trace (src/ci/trace-bundle.ts): prompts, outputs, tool arguments and results.
|
|
440
|
+
export function redactSessionText(value: string): string {
|
|
441
|
+
return redactSessionString(value, 0, { nodes: 0 });
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// The session copy's key rules over a whole parsed document, with no node cap:
|
|
445
|
+
// an OpenCode capture holds thousands of records, and redactEvidence, which
|
|
446
|
+
// wrote it, kept values under names such as `apiToken` (its key rule is the
|
|
447
|
+
// narrow shared one). Strings under a credential-like name go, numbers stay,
|
|
448
|
+
// and every other string takes redactSessionText. A branch deeper than the
|
|
449
|
+
// bound is replaced whole, never copied raw.
|
|
450
|
+
export function redactSessionDocument(value: unknown, depth = 0): unknown {
|
|
451
|
+
if (depth > DOCUMENT_MAX_DEPTH) return "[REDACTED]";
|
|
452
|
+
if (typeof value === "string") return redactSessionText(value);
|
|
453
|
+
if (Array.isArray(value)) {
|
|
454
|
+
return value.map((item) => redactSessionDocument(item, depth + 1));
|
|
455
|
+
}
|
|
456
|
+
if (typeof value === "object" && value !== null) {
|
|
457
|
+
const out: Record<string, unknown> = {};
|
|
458
|
+
for (const [key, item] of Object.entries(value)) {
|
|
459
|
+
if (SESSION_SECRET_KEY.test(key)) out[key] = "[REDACTED]";
|
|
460
|
+
else if (isSessionSecretName(key)) out[key] = credentialValue(item);
|
|
461
|
+
else out[key] = redactSessionDocument(item, depth + 1);
|
|
462
|
+
}
|
|
463
|
+
return out;
|
|
464
|
+
}
|
|
465
|
+
return typeof value === "number" || typeof value === "boolean" ? value : null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const DOCUMENT_MAX_DEPTH = 64;
|
|
469
|
+
|
|
470
|
+
function credentialValue(value: unknown): unknown {
|
|
471
|
+
try {
|
|
472
|
+
return redactStrings(value, 0, { nodes: 0 });
|
|
473
|
+
} catch {
|
|
474
|
+
return "[REDACTED]";
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
async function dropStaleTrace(dest: string): Promise<void> {
|
|
479
|
+
await unlink(dest).catch(() => undefined);
|
|
480
|
+
}
|
|
@@ -28,15 +28,32 @@ export type {
|
|
|
28
28
|
|
|
29
29
|
export type DenialCode = WorkspaceDenialCode | ExecutableDenialCode;
|
|
30
30
|
|
|
31
|
+
// Which backend runs a step, and what it is sent. `modelSnapshot` is the wire
|
|
32
|
+
// model (the Claude CLI's `--model`, OpenCode's model id) and the name
|
|
33
|
+
// pipeline.json has always recorded. There is no gateway any more: a model
|
|
34
|
+
// name says its backend (odd/tasks/role-model-routing.md S3).
|
|
31
35
|
export interface ResolvedModelRoute {
|
|
32
36
|
readonly backend: RunnerBackend;
|
|
33
37
|
readonly provider: string;
|
|
34
|
-
readonly gateway?: string;
|
|
35
38
|
readonly modelFamily: string;
|
|
36
39
|
readonly modelSnapshot: string;
|
|
37
40
|
readonly modelVariant?: string;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
// Whether a route's backend is sent an effort (S7), the ONE answer every
|
|
44
|
+
// report's `effort_applied` reads. The Claude CLI always gets `--effort`.
|
|
45
|
+
// OpenCode gets one only as the model variant a `models` entry's effort sets;
|
|
46
|
+
// with no entry effort it is sent no variant (D1) and runs at the provider's
|
|
47
|
+
// default, so nothing the engine asked for was applied. "Applied" means passed
|
|
48
|
+
// to the backend: the Claude CLI clamps a level the model lacks and reports
|
|
49
|
+
// nothing back.
|
|
50
|
+
export function effortApplied(route: ResolvedModelRoute): boolean {
|
|
51
|
+
return (
|
|
52
|
+
route.backend === "claude-code" ||
|
|
53
|
+
(route.backend === "opencode" && route.modelVariant !== undefined)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
export interface IsolationProjection {
|
|
41
58
|
readonly credentialProjectionId: string;
|
|
42
59
|
readonly env: Readonly<Record<string, string>>;
|
|
@@ -50,9 +67,9 @@ export interface TransportRequest {
|
|
|
50
67
|
readonly sessionId: string;
|
|
51
68
|
readonly attempt: number;
|
|
52
69
|
readonly route: ResolvedModelRoute;
|
|
53
|
-
// The model string the
|
|
54
|
-
//
|
|
55
|
-
//
|
|
70
|
+
// The model string the step asked for (StepSpec.model), kept for evidence.
|
|
71
|
+
// What a provider receives is the route's: `route.modelSnapshot` is the
|
|
72
|
+
// Claude CLI's `--model` (claudeCliModel) and OpenCode's model id.
|
|
56
73
|
readonly executionModel: string;
|
|
57
74
|
// The effort the engine asked for (StepSpec.effort), always present. Only
|
|
58
75
|
// the Claude Code transport can APPLY it (`--effort`); a backend that cannot
|