@hasna/hooks 0.12.19 → 0.12.21
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 +129 -3
- package/bin/hooks/scratch-lifecycle.js +501 -0
- package/bin/hooks-mcp.js +5199 -3025
- package/bin/index.js +6207 -3610
- package/bin/native-safety-worker.cjs +1 -1
- package/bin/serve.js +15 -1
- package/dist/index.js +5534 -3359
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-check.d.ts +4 -0
- package/dist/lib/hook-env.d.ts +3 -2
- package/dist/lib/run.d.ts +9 -0
- package/dist/serve.d.ts +1 -1
- package/hooks/hook-scratch-lifecycle/README.md +88 -0
- package/hooks/hook-scratch-lifecycle/manifest.json +10 -0
- package/hooks/hook-scratch-lifecycle/package.json +11 -0
- package/hooks/hook-scratch-lifecycle/src/hook.ts +194 -0
- package/hooks/hook-scratch-lifecycle/src/lifecycle.ts +218 -0
- package/package.json +8 -2
- package/scripts/validate-bundled-hooks.ts +12 -0
- package/scripts/validate-package.ts +46 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { copyFile, mkdtemp, mkdir, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { chmod, copyFile, mkdtemp, mkdir, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { validatePackedBundledHooks } from "./validate-bundled-hooks";
|
|
6
6
|
|
|
@@ -281,6 +281,49 @@ async function validatePackedNativeSafety(packageDir: string, smokeDir: string):
|
|
|
281
281
|
} finally { await writeFile(worker, bytes); }
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* HO-00087: a harness starts `hooks run <hook>` and `hooks-mcp` in the project
|
|
286
|
+
* it works on. Executed through their own shebang, as a harness does, the packed
|
|
287
|
+
* bins must not run that project's bunfig.toml preload or read its .env, and a
|
|
288
|
+
* hook they start must not either.
|
|
289
|
+
*/
|
|
290
|
+
async function validatePackedEntryIsolation(options: {
|
|
291
|
+
binIndex: string;
|
|
292
|
+
binMcp: string;
|
|
293
|
+
workspace: string;
|
|
294
|
+
env: NodeJS.ProcessEnv;
|
|
295
|
+
failClosedEnv: NodeJS.ProcessEnv;
|
|
296
|
+
}): Promise<void> {
|
|
297
|
+
const { binIndex, binMcp, workspace, env, failClosedEnv } = options;
|
|
298
|
+
const project = join(workspace, "hostile-project");
|
|
299
|
+
const marker = join(workspace, "hostile-preload-ran");
|
|
300
|
+
await mkdir(project);
|
|
301
|
+
await writeFile(join(project, "preload.ts"), `require("node:fs").appendFileSync(${JSON.stringify(marker)}, process.argv[1] + "\\n");\n`);
|
|
302
|
+
await writeFile(join(project, "bunfig.toml"), `preload = ["./preload.ts"]\n`);
|
|
303
|
+
// Without the shebang's --no-env-file this opt-in would turn the fail-closed runs below into local-mode runs.
|
|
304
|
+
await writeFile(join(project, ".env"), "HASNA_HOOKS_LOCAL=1\n");
|
|
305
|
+
// npm makes bin targets executable on install; the extracted tarball keeps the packed mode.
|
|
306
|
+
for (const bin of [binIndex, binMcp]) await chmod(bin, 0o755);
|
|
307
|
+
|
|
308
|
+
// Positive control: plain bun in that directory does run the preload.
|
|
309
|
+
const control = spawnSync("bun", [binIndex, "--version"], { cwd: project, env, encoding: "utf8", timeout: 20000 });
|
|
310
|
+
if (control.status !== 0 || !existsSync(marker)) throw new Error(`hostile-project control did not run its preload (exit ${control.status})`);
|
|
311
|
+
await rm(marker);
|
|
312
|
+
|
|
313
|
+
const input = JSON.stringify({ hook_event_name: "PreToolUse", tool_name: "Bash", tool_input: { command: "echo smoke" } });
|
|
314
|
+
const ran = spawnSync(binIndex, ["run", "gitguard"], { cwd: project, env, encoding: "utf8", input, timeout: 20000 });
|
|
315
|
+
if (ran.status !== 0 || !/decision/.test(ran.stdout)) throw new Error(`packed CLI run through its shebang failed (exit ${ran.status}): ${ran.stderr.slice(0, 300)}`);
|
|
316
|
+
for (const [label, bin, args] of [["packed CLI `hooks categories`", binIndex, ["categories"]], ["packed hooks-mcp", binMcp, []]] as Array<[string, string, string[]]>) {
|
|
317
|
+
const refused = spawnSync(bin, args, { cwd: project, env: failClosedEnv, encoding: "utf8", input: "", timeout: 20000 });
|
|
318
|
+
if (refused.status === 0) throw new Error(`${label} read the project's .env opt-in (exit 0 with nothing configured)`);
|
|
319
|
+
// Only the fail-closed refusal text proves the bin started through its shebang at all.
|
|
320
|
+
if (!/HASNA_HOOKS_LOCAL=1/.test(refused.stderr) || !/hasna\.credentials\.hooks\.api-key/.test(refused.stderr)) {
|
|
321
|
+
throw new Error(`${label} did not start through its shebang and reach the fail-closed refusal (exit ${refused.status}): ${refused.stderr.slice(0, 300)}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (existsSync(marker)) throw new Error(`a packed bin or its hook ran the project's bunfig.toml preload: ${(await readFile(marker, "utf8")).trim()}`);
|
|
325
|
+
}
|
|
326
|
+
|
|
284
327
|
async function validateExtractedSmoke(pkg: PackageJson): Promise<void> {
|
|
285
328
|
const tempRoot = join(root, "temp");
|
|
286
329
|
await mkdir(tempRoot, { recursive: true });
|
|
@@ -426,6 +469,8 @@ async function validateExtractedSmoke(pkg: PackageJson): Promise<void> {
|
|
|
426
469
|
});
|
|
427
470
|
if (runRes.status !== 0) throw new Error(`packed bundled-hook run failed (exit ${runRes.status}): ${runRes.stderr}`);
|
|
428
471
|
if (!/decision/.test(runRes.stdout)) throw new Error(`packed bundled-hook run produced no hook decision: ${runRes.stdout.slice(0, 200)}`);
|
|
472
|
+
|
|
473
|
+
await validatePackedEntryIsolation({ binIndex, binMcp, workspace, env, failClosedEnv: fcEnv });
|
|
429
474
|
} finally {
|
|
430
475
|
await rm(workspace, { force: true, recursive: true });
|
|
431
476
|
}
|