cocheck 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +17 -3
  2. package/dist/agent-transcripts.js +15 -12
  3. package/dist/attribution/evidence.js +2 -1
  4. package/dist/attribution/reconstruct.js +19 -0
  5. package/dist/attribution/tag.js +3 -3
  6. package/dist/build-info.json +1 -1
  7. package/dist/cli.js +31 -11
  8. package/dist/connector/export-view.js +1 -1
  9. package/dist/coverage.js +5 -3
  10. package/dist/credit-guard.js +59 -54
  11. package/dist/harness-cmd/create.js +76 -0
  12. package/dist/harness-cmd/index.js +19 -0
  13. package/dist/harness-cmd/record.js +327 -0
  14. package/dist/harness-cmd/scrub.js +25 -0
  15. package/dist/harness-cmd/test.js +318 -0
  16. package/dist/harnesses/README.md +5 -0
  17. package/dist/harnesses/claude/cocheck-harness.json +344 -0
  18. package/dist/harnesses/codex/cocheck-harness.json +212 -0
  19. package/dist/harnesses/copilot/cocheck-harness.json +296 -0
  20. package/dist/{copilot-helpers.js → helper-linker.js} +43 -32
  21. package/dist/hook-adapter.js +287 -63
  22. package/dist/hook-cli.js +73 -36
  23. package/dist/hook-journal.js +40 -12
  24. package/dist/hosts/claude.js +23 -159
  25. package/dist/hosts/codex.js +41 -81
  26. package/dist/hosts/compile.js +275 -0
  27. package/dist/hosts/copilot.js +7 -162
  28. package/dist/hosts/extras.js +55 -0
  29. package/dist/hosts/harnesses.js +66 -0
  30. package/dist/hosts/index.js +176 -8
  31. package/dist/hosts/install-block.js +332 -0
  32. package/dist/hosts/manifest.js +372 -0
  33. package/dist/hosts/shared.js +21 -0
  34. package/dist/hosts/tool-classes.js +6 -0
  35. package/dist/hosts/types.js +1 -0
  36. package/dist/install.js +69 -22
  37. package/dist/ledger.js +11 -0
  38. package/dist/normalize.js +33 -9
  39. package/dist/open-pick.js +5 -3
  40. package/dist/patch-secrets.js +11 -11
  41. package/dist/review-server.js +2 -2
  42. package/dist/timeline/attribution.js +2 -2
  43. package/dist/timeline/describe.js +20 -17
  44. package/dist/timeline/load.js +2 -2
  45. package/dist/timeline/rail/assets/review.js +1 -1
  46. package/dist/timeline/rail/model.js +8 -8
  47. package/dist/timeline/read-signal.js +4 -4
  48. package/dist/timeline/render/view-v1.js +2 -13
  49. package/dist/timeline/runs.js +9 -9
  50. package/dist/timeline/timeline.js +8 -8
  51. package/dist/timeline/write-signal.js +4 -3
  52. package/package.json +2 -2
  53. package/public-kit/harness/GUIDE.md +81 -0
  54. package/public-kit/harness/README.md +10 -0
  55. package/public-kit/harness/cases/claude/shell-writes-file.json +120 -0
  56. package/public-kit/harness/cases/codex/apply-patch-writes-files.json +177 -0
  57. package/public-kit/harness/cases/codex/helper-writes-file.json +160 -0
  58. package/public-kit/harness/cases/codex/shell-writes-and-fails.json +110 -0
  59. package/public-kit/harness/cases/copilot/camel-case-patch-and-failure.json +126 -0
  60. package/public-kit/harness/cases/copilot/helper-writes-file.json +209 -0
  61. package/public-kit/harness/cases/copilot/vscode-helper-writes-file.json +236 -0
  62. package/public-kit/harness/examples/toyagent/cases/write-notes.json +142 -0
  63. package/public-kit/harness/examples/toyagent/cocheck-harness.json +47 -0
  64. package/public-kit/harness/examples/toyagent/recordings/payloads.jsonl +8 -0
  65. package/public-kit/harness/harnesses/antigravity/README.md +32 -0
  66. package/public-kit/harness/harnesses/antigravity/cases/failed-edit.json +99 -0
  67. package/public-kit/harness/harnesses/antigravity/cases/helper-writes-file.json +270 -0
  68. package/public-kit/harness/harnesses/antigravity/cases/shell-ok-fail-and-denied.json +211 -0
  69. package/public-kit/harness/harnesses/antigravity/cases/write-then-edit.json +191 -0
  70. package/public-kit/harness/harnesses/antigravity/cocheck-harness.json +62 -0
  71. package/public-kit/harness/harnesses/antigravity/recordings/payloads.jsonl +63 -0
  72. package/public-kit/harness/harnesses/cursor/README.md +40 -0
  73. package/public-kit/harness/harnesses/cursor/cases/editor-write-edit-shell-helper.json +359 -0
  74. package/public-kit/harness/harnesses/cursor/cases/read-then-write-one-call-id.json +159 -0
  75. package/public-kit/harness/harnesses/cursor/cocheck-harness.json +67 -0
  76. package/public-kit/harness/harnesses/cursor/recordings/payloads.jsonl +28 -0
  77. package/public-kit/harness/scaffold/README.md +42 -0
  78. package/public-kit/harness/scaffold/cocheck-harness.json +72 -0
  79. package/public-kit/harness/scaffold/recordings/.gitkeep +0 -0
  80. package/public-kit/harness/spec/v1.md +286 -0
  81. package/scripts/hook-launch.sh +1 -1
@@ -0,0 +1,19 @@
1
+ // `cocheck harness <sub>`: the commands for a person adding an agent harness. Each subcommand is its own module.
2
+ import { runHarnessTest } from "./test.js";
3
+ export const HARNESS_USAGE = `usage:
4
+ cocheck harness create <key> [--dir <path>]
5
+ cocheck harness record <key> --manifest <path> --out <dir> [--timeout <seconds>] [-- <harness command...>]
6
+ cocheck harness record --stop <scratch>
7
+ cocheck harness test --cases <dir> [--manifest <path>]`;
8
+ /** Runs one `cocheck harness` command (the words after `harness`); resolves to the exit code. */
9
+ export async function runHarnessCommand(args, io) {
10
+ const [sub, ...rest] = args;
11
+ if (sub === "create")
12
+ return (await import("./create.js")).runHarnessCreate(rest, io);
13
+ if (sub === "record")
14
+ return (await import("./record.js")).runHarnessRecord(rest, io);
15
+ if (sub === "test")
16
+ return runHarnessTest(rest, io);
17
+ io.err(sub === undefined ? HARNESS_USAGE : `unknown harness command ${JSON.stringify(sub)}\n${HARNESS_USAGE}`);
18
+ return sub === undefined ? 2 : 1;
19
+ }
@@ -0,0 +1,327 @@
1
+ // `cocheck harness record <key> --manifest <path> --out <dir> [-- <harness command...>]`: records the raw hook calls a harness makes, for a manifest to be written from.
2
+ //
3
+ // Safety invariant:
4
+ // - It writes only under <out> and its own scratch folder. The manifest's install path is resolved against the scratch folder only (a scratch HOME, and a scratch
5
+ // folder for each environment variable the path names), and a path that lands outside the scratch folder is refused. The person's real config files are never written.
6
+ // - It signals only the process it spawned, by that process's handle (timeout, interrupt), never by name or by a recorded pid.
7
+ // - It removes nothing recursively except its own scratch folder at the end, and only one that carries its marker file.
8
+ // - On an interrupt it stops its child, writes what was recorded so far to <out>, and removes its scratch folder.
9
+ // Every file written to <out> is scrubbed (emails, the home path); a token-shaped string left over fails the run and nothing is written.
10
+ import { spawn } from "node:child_process";
11
+ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
12
+ import { homedir, tmpdir } from "node:os";
13
+ import path from "node:path";
14
+ import { platform } from "../platform/index.js";
15
+ import { INSTALL_OWN, MANIFEST_FILE, validateManifest } from "../hosts/manifest.js";
16
+ import { jsonHookEditor, validateInstallBlock } from "../hosts/install-block.js";
17
+ import { findTokenShapes, scrubText } from "./scrub.js";
18
+ export const RECORD_USAGE = "usage: cocheck harness record <key> --manifest <path> --out <dir> [--timeout <seconds>] [-- <harness command...>]\n cocheck harness record --stop <scratch>";
19
+ const SCRATCH_PREFIX = "cocheck-record-";
20
+ export const MARKER = ".cocheck-record-scratch";
21
+ const DEFAULT_TIMEOUT_S = 600;
22
+ // The logging hook: one line per call. Its arguments are the payload file, the payload path of the event name ("-" when the command names it), then what the harness passed.
23
+ const LOG_HOOK = `import { appendFileSync } from "node:fs";
24
+ const [file, evPath, ...rest] = process.argv.slice(2);
25
+ let input = "";
26
+ process.stdin.setEncoding("utf8");
27
+ process.stdin.on("data", (c) => (input += c));
28
+ process.stdin.on("end", () => {
29
+ let event = "";
30
+ const i = rest.indexOf("--event");
31
+ if (i >= 0) event = rest[i + 1] ?? "";
32
+ else if (evPath !== "-") {
33
+ try {
34
+ let v = JSON.parse(input);
35
+ for (const part of evPath.split(/[.\\[\\]]+/).filter(Boolean)) v = v?.[/^\\d+$/.test(part) ? Number(part) : part];
36
+ if (typeof v === "string") event = v;
37
+ } catch {}
38
+ }
39
+ appendFileSync(file, JSON.stringify({ event, argv: rest, stdin: input, ts: Date.now() / 1000 }) + "\\n");
40
+ });
41
+ `;
42
+ /** The `{...}` tokens of a path template at its top level (a token inside a fallback is not one). */
43
+ function topTokens(template) {
44
+ const out = [];
45
+ for (let i = 0; i < template.length; i++) {
46
+ if (template[i] !== "{")
47
+ continue;
48
+ let depth = 1;
49
+ let j = i + 1;
50
+ for (; j < template.length && depth > 0; j++)
51
+ depth += template[j] === "{" ? 1 : template[j] === "}" ? -1 : 0;
52
+ out.push(template.slice(i + 1, j - 1));
53
+ i = j - 1;
54
+ }
55
+ return out;
56
+ }
57
+ const within = (parent, child) => child === parent || child.startsWith(parent + path.sep);
58
+ const shq = (s) => `'${s.replace(/'/g, `'\\''`)}'`;
59
+ const real = (p) => {
60
+ let cur = path.resolve(p);
61
+ const rest = [];
62
+ while (!existsSync(cur) && path.dirname(cur) !== cur) {
63
+ rest.unshift(path.basename(cur));
64
+ cur = path.dirname(cur);
65
+ }
66
+ return path.join(realpathSync(cur), ...rest);
67
+ };
68
+ /** Resolves where the harness's hook config goes inside `scratch` and the environment that makes the harness read it from there. */
69
+ function scratchConfig(m, scratch) {
70
+ const install = m.install;
71
+ if (install === undefined || install.editorExtra !== undefined)
72
+ throw new Error("the manifest has no JSON install block, so record cannot set up the hooks. Add an install block, or log the harness's hook calls by hand.");
73
+ const home = path.join(scratch, "home");
74
+ const env = {};
75
+ const tokens = topTokens(install.path);
76
+ for (const t of tokens)
77
+ if (t.startsWith("env:")) {
78
+ const name = (t.slice(4).split("|")[0] ?? "").trim();
79
+ env[name] = path.join(scratch, "env", name);
80
+ }
81
+ if (tokens.includes("home"))
82
+ env.HOME = home;
83
+ // A workspace-scoped config ({project}) goes in the scratch work folder, where the harness command runs.
84
+ const project = path.join(scratch, "work");
85
+ const block = validateInstallBlock(Object.fromEntries(Object.entries(install).filter(([k]) => !INSTALL_OWN.includes(k))), "install");
86
+ const file = jsonHookEditor(block).configFile(env, home, project);
87
+ if (!within(real(scratch), real(file)))
88
+ throw new Error(`the manifest's install path resolves outside the scratch folder (${file}); refusing to write it`);
89
+ return { file, env, home };
90
+ }
91
+ function writeSetup(m, scratch, payloads) {
92
+ const { file, env, home } = scratchConfig(m, scratch);
93
+ const block = validateInstallBlock(Object.fromEntries(Object.entries(m.install).filter(([k]) => !INSTALL_OWN.includes(k))), "install");
94
+ const hookScript = path.join(scratch, "log-hook.mjs");
95
+ writeFileSync(hookScript, LOG_HOOK);
96
+ const evPath = "payload" in m.eventFrom ? m.eventFrom.payload : "-";
97
+ const base = `${JSON.stringify(process.execPath)} ${JSON.stringify(hookScript)} ${JSON.stringify(payloads)} ${JSON.stringify(evPath)}`;
98
+ const plat = platform();
99
+ const shim = { ...plat, hookCommand: { ...plat.hookCommand, build: () => base } };
100
+ const text = jsonHookEditor(block).addHooks("", file, {}, shim);
101
+ mkdirSync(path.dirname(file), { recursive: true });
102
+ mkdirSync(home, { recursive: true });
103
+ writeFileSync(file, text);
104
+ return { env, configFile: file };
105
+ }
106
+ /** Scrubs the recorded lines into <out>/payloads.jsonl and removes the scratch folder. Returns the line count, or a failure message. */
107
+ function finish(scratch, out, realHome) {
108
+ const marker = path.join(scratch, MARKER);
109
+ const payloads = path.join(scratch, "payloads.jsonl");
110
+ let failure;
111
+ let lines = 0;
112
+ try {
113
+ if (existsSync(payloads)) {
114
+ const homes = [realHome, real(realHome), homedir(), real(homedir())];
115
+ const clean = scrubText(readFileSync(payloads, "utf8"), homes);
116
+ const shapes = findTokenShapes(clean);
117
+ if (shapes.length > 0)
118
+ failure = `token-shaped string left after scrubbing (${shapes.join(", ")}); nothing was written to ${out}`;
119
+ else {
120
+ lines = clean.split("\n").filter(Boolean).length;
121
+ const dst = path.join(out, "payloads.jsonl");
122
+ if (existsSync(dst))
123
+ failure = `${dst} already exists; nothing was written`;
124
+ else if (lines > 0) {
125
+ mkdirSync(out, { recursive: true });
126
+ writeFileSync(dst, clean);
127
+ }
128
+ }
129
+ }
130
+ }
131
+ finally {
132
+ // Only a folder this command made: a real folder (not a link) that carries the marker.
133
+ if (existsSync(marker) && lstatSync(scratch).isDirectory() && !lstatSync(scratch).isSymbolicLink() && path.basename(scratch).startsWith(SCRATCH_PREFIX))
134
+ rmSync(scratch, { recursive: true, force: true });
135
+ }
136
+ return failure === undefined ? { lines } : { lines: 0, failure };
137
+ }
138
+ export async function recordRun(o) {
139
+ const messages = [];
140
+ const res = (exitCode, extra = {}) => ({ exitCode, lines: 0, messages, ...extra });
141
+ const cwd = o.cwd ?? process.cwd();
142
+ const realHome = o.realHome ?? homedir();
143
+ let m;
144
+ try {
145
+ const manifestPath = path.resolve(cwd, o.manifest);
146
+ m = validateManifest(JSON.parse(readFileSync(manifestPath, "utf8")), path.basename(path.dirname(manifestPath)) + "/" + MANIFEST_FILE, { outsider: true });
147
+ }
148
+ catch (error) {
149
+ messages.push(`cannot use the manifest ${o.manifest}: ${error instanceof Error ? error.message : String(error)}`);
150
+ return res(1);
151
+ }
152
+ if (m.key !== o.key) {
153
+ messages.push(`the manifest's key is ${JSON.stringify(m.key)}, not ${JSON.stringify(o.key)}`);
154
+ return res(1);
155
+ }
156
+ const out = path.resolve(cwd, o.out);
157
+ if (existsSync(path.join(out, "payloads.jsonl"))) {
158
+ messages.push(`${path.join(out, "payloads.jsonl")} already exists; pick a new --out folder. Nothing was written.`);
159
+ return res(1);
160
+ }
161
+ const baseEnv = o.env ?? process.env;
162
+ // `out` may not sit inside the folder of the harness's real config.
163
+ try {
164
+ const realCfg = jsonHookEditor(validateInstallBlock(Object.fromEntries(Object.entries(m.install ?? {}).filter(([k]) => !INSTALL_OWN.includes(k))), "install")).configFile(baseEnv, realHome, cwd);
165
+ if (within(real(path.dirname(realCfg)), real(out))) {
166
+ messages.push(`refusing to write inside ${path.dirname(realCfg)}, the folder of the harness's own config: ${out}`);
167
+ return res(1);
168
+ }
169
+ }
170
+ catch {
171
+ // no JSON install block, or an unset required variable: scratchConfig reports it below
172
+ }
173
+ const root = o.tmpRoot ?? tmpdir();
174
+ mkdirSync(root, { recursive: true });
175
+ const scratch = real(mkdtempSync(path.join(root, SCRATCH_PREFIX)));
176
+ writeFileSync(path.join(scratch, MARKER), JSON.stringify({ schema: "cocheck-record-scratch/1", key: o.key, out }) + "\n");
177
+ if (within(scratch, real(out))) {
178
+ finish(scratch, out, realHome);
179
+ messages.push("--out may not be inside the scratch folder");
180
+ return res(1);
181
+ }
182
+ const work = path.join(scratch, "work");
183
+ const payloads = path.join(scratch, "payloads.jsonl");
184
+ let setup;
185
+ try {
186
+ mkdirSync(work);
187
+ writeFileSync(payloads, "");
188
+ setup = writeSetup(m, scratch, payloads);
189
+ }
190
+ catch (error) {
191
+ finish(scratch, out, realHome);
192
+ messages.push(error instanceof Error ? error.message : String(error));
193
+ return res(1);
194
+ }
195
+ const env = { ...baseEnv, ...setup.env };
196
+ if (o.command === undefined || o.command.length === 0) {
197
+ messages.push(`Scratch folder: ${scratch}\nHook config written for the harness (scratch only): ${setup.configFile}\nIn the shell you will run the harness from:\n` +
198
+ `${Object.entries(setup.env).map(([k, v]) => ` export ${k}=${shq(v)}`).join("\n")}${Object.keys(setup.env).length ? "\n" : ""} cd ${shq(work)}\n` +
199
+ `Run your harness there, then finish with:\n cocheck harness record --stop ${shq(scratch)}`);
200
+ return res(0, { scratch });
201
+ }
202
+ // The harness command runs in the scratch work folder; only this child, by its handle, is ever signalled.
203
+ const timeoutMs = (o.timeoutSeconds ?? DEFAULT_TIMEOUT_S) * 1000;
204
+ const child = spawn(o.command[0], o.command.slice(1), { cwd: work, env, stdio: ["ignore", "pipe", "pipe"] });
205
+ let stderrTail = "";
206
+ child.stdout?.on("data", () => { });
207
+ child.stderr?.on("data", (c) => (stderrTail = (stderrTail + c).slice(-500)));
208
+ let timedOut = false;
209
+ let interrupted = false;
210
+ const stop = () => {
211
+ if (child.exitCode === null && child.signalCode === null) {
212
+ child.kill("SIGTERM");
213
+ setTimeout(() => {
214
+ if (child.exitCode === null && child.signalCode === null)
215
+ child.kill("SIGKILL");
216
+ }, 3000).unref();
217
+ }
218
+ };
219
+ const timer = setTimeout(() => {
220
+ timedOut = true;
221
+ stop();
222
+ }, timeoutMs);
223
+ const onAbort = () => {
224
+ interrupted = true;
225
+ stop();
226
+ };
227
+ if (o.signal?.aborted)
228
+ onAbort();
229
+ o.signal?.addEventListener("abort", onAbort);
230
+ const status = await new Promise((resolve) => {
231
+ child.on("error", (error) => resolve({ code: null, error }));
232
+ child.on("close", (code) => resolve({ code }));
233
+ });
234
+ clearTimeout(timer);
235
+ o.signal?.removeEventListener("abort", onAbort);
236
+ const fin = finish(scratch, out, realHome);
237
+ if (fin.failure !== undefined) {
238
+ messages.push(fin.failure);
239
+ return res(1, { interrupted });
240
+ }
241
+ if (status.error)
242
+ messages.push(`could not start the harness command: ${status.error.message}`);
243
+ else if (interrupted)
244
+ messages.push("interrupted: the harness command was stopped");
245
+ else if (timedOut)
246
+ messages.push(`the harness command was stopped after ${o.timeoutSeconds ?? DEFAULT_TIMEOUT_S} seconds`);
247
+ else if (status.code !== 0)
248
+ messages.push(`the harness command exited with ${status.code}: ${stderrTail.trim()}`);
249
+ if (fin.lines === 0)
250
+ messages.push("no hook call was recorded; the harness did not run the hooks. Check that it reads the hook config the manifest's install path names.");
251
+ else
252
+ messages.push(`Recorded ${fin.lines} hook call${fin.lines === 1 ? "" : "s"} to ${path.join(out, "payloads.jsonl")}`);
253
+ const ok = !status.error && !interrupted && !timedOut && status.code === 0 && fin.lines > 0;
254
+ return res(interrupted ? 130 : ok ? 0 : 1, { lines: fin.lines, interrupted });
255
+ }
256
+ /** `record --stop <scratch>`: finishes a hand-run recording. Only a folder this command made (its marker names the output) is read and removed. */
257
+ export function recordStop(scratch, opts = {}) {
258
+ const messages = [];
259
+ const dir = path.resolve(opts.cwd ?? process.cwd(), scratch);
260
+ let out;
261
+ try {
262
+ if (lstatSync(dir).isSymbolicLink() || !path.basename(dir).startsWith(SCRATCH_PREFIX))
263
+ throw new Error("not a record scratch folder");
264
+ const marker = JSON.parse(readFileSync(path.join(dir, MARKER), "utf8"));
265
+ if (typeof marker.out !== "string")
266
+ throw new Error("marker unreadable");
267
+ out = marker.out;
268
+ }
269
+ catch {
270
+ messages.push(`${scratch} is not a scratch folder made by cocheck harness record; nothing was changed`);
271
+ return { exitCode: 1, lines: 0, messages };
272
+ }
273
+ const fin = finish(dir, out, opts.realHome ?? homedir());
274
+ if (fin.failure !== undefined) {
275
+ messages.push(fin.failure);
276
+ return { exitCode: 1, lines: 0, messages };
277
+ }
278
+ messages.push(fin.lines === 0 ? "no hook call was recorded; nothing was written" : `Recorded ${fin.lines} hook call${fin.lines === 1 ? "" : "s"} to ${path.join(out, "payloads.jsonl")}`);
279
+ return { exitCode: fin.lines === 0 ? 1 : 0, lines: fin.lines, messages };
280
+ }
281
+ export async function runHarnessRecord(argv, io) {
282
+ const dd = argv.indexOf("--");
283
+ const head = dd < 0 ? argv : argv.slice(0, dd);
284
+ const command = dd < 0 ? undefined : argv.slice(dd + 1);
285
+ const fail = (m) => (io.err(m), 2);
286
+ let key;
287
+ let manifest;
288
+ let out;
289
+ let stopDir;
290
+ let timeout;
291
+ for (let i = 0; i < head.length; i++) {
292
+ const a = head[i];
293
+ const val = () => head[++i];
294
+ if (a === "--manifest")
295
+ manifest = val();
296
+ else if (a === "--out")
297
+ out = val();
298
+ else if (a === "--stop")
299
+ stopDir = val();
300
+ else if (a === "--timeout") {
301
+ const t = Number(val());
302
+ if (!(t > 0))
303
+ return fail("--timeout needs a number of seconds");
304
+ timeout = t;
305
+ }
306
+ else if (a.startsWith("--"))
307
+ return fail(`unknown option ${a}`);
308
+ else if (key === undefined)
309
+ key = a;
310
+ else
311
+ return fail(RECORD_USAGE);
312
+ }
313
+ if (stopDir !== undefined) {
314
+ if (key !== undefined || manifest !== undefined || out !== undefined || command !== undefined)
315
+ return fail(RECORD_USAGE);
316
+ const r = recordStop(stopDir, { cwd: io.cwd });
317
+ for (const line of r.messages)
318
+ (r.exitCode === 0 ? io.out : io.err)(line);
319
+ return r.exitCode;
320
+ }
321
+ if (key === undefined || manifest === undefined || out === undefined || (command !== undefined && command.length === 0))
322
+ return fail(RECORD_USAGE);
323
+ const r = await recordRun({ key, manifest, out, command, timeoutSeconds: timeout, env: io.env, signal: io.signal, cwd: io.cwd });
324
+ for (const line of r.messages)
325
+ (r.exitCode === 0 ? io.out : io.err)(line);
326
+ return r.exitCode;
327
+ }
@@ -0,0 +1,25 @@
1
+ import path from "node:path";
2
+ // The scrub a recording goes through before it leaves a scratch folder: emails and the home path are replaced, and a token-shaped string left over fails the run.
3
+ // Shared by `cocheck harness record` and scripts/probe-host.ts.
4
+ // What a recorded home path becomes: the same text on every machine.
5
+ const HOME_PLACEHOLDER = path.posix.join("/", "Users", "<user>");
6
+ const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+/g;
7
+ const TOKEN_SHAPES = [
8
+ ["sk- key", /sk-[A-Za-z0-9_-]{16,}/],
9
+ ["ghp_ token", /ghp_[A-Za-z0-9]{16,}/],
10
+ ["gho_ token", /gho_[A-Za-z0-9]{16,}/],
11
+ ["JWT", /eyJ[A-Za-z0-9_-]{8,}/],
12
+ ["Bearer value", /Bearer\s+[A-Za-z0-9._~+/=-]{8,}/],
13
+ ["private key header", /-----BEGIN [A-Z ]*PRIVATE KEY-----/],
14
+ ];
15
+ /** Replaces emails and the home path (as given and as its realpath, longest first). */
16
+ export function scrubText(text, homes) {
17
+ let out = text;
18
+ for (const h of [...new Set(homes)].filter((x) => x.length > 1).sort((a, b) => b.length - a.length))
19
+ out = out.split(h).join(HOME_PLACEHOLDER);
20
+ return out.replace(EMAIL, "user@example.com");
21
+ }
22
+ /** Names of the token shapes found in text. */
23
+ export function findTokenShapes(text) {
24
+ return TOKEN_SHAPES.filter(([, re]) => re.test(text)).map(([name]) => name);
25
+ }