Pi 0.85.1 and Claude Code 2.1.289 (Agent SDK 0.3.289), 34 cases against a scripted local model in a loopback-only network namespace. MATRIX.md has the command, outcome, model-visible message and fail-closed column per case, and one rely-on line per case. Evidence under evidence/. Co-Authored-By: Claude Opus 5.5 <[email protected]>
42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
// Row S0 case 6: a Claude Agent SDK PreToolUse callback hook on `Write`.
|
|
// HOOK_MODE: deny (control), throw, hang. Uses the pinned Claude Code binary
|
|
// (CLAUDE_BIN) and the SDK at SDK_ENTRY. Prints every SDK message as JSON.
|
|
import { appendFileSync } from "node:fs";
|
|
|
|
const { query } = await import(process.env.SDK_ENTRY);
|
|
const mode = process.env.HOOK_MODE ?? "deny";
|
|
const note = (s) => appendFileSync(process.env.GATE_LOG, `${new Date().toISOString()} ${s}\n`);
|
|
|
|
async function gate(input) {
|
|
note(`invoked tool=${input.tool_name} mode=${mode}`);
|
|
if (mode === "throw") throw new Error("PROBE-GATE crashed (SDK callback throw)");
|
|
if (mode === "hang") return new Promise(() => {});
|
|
return { hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: "PROBE-GATE: write is denied by policy (SDK callback)" } };
|
|
}
|
|
|
|
const matcher = { matcher: "Write", hooks: [gate] };
|
|
if (process.env.HOOK_TIMEOUT) matcher.timeout = Number(process.env.HOOK_TIMEOUT);
|
|
|
|
try {
|
|
for await (const m of query({
|
|
prompt: "probe",
|
|
options: {
|
|
pathToClaudeCodeExecutable: process.env.CLAUDE_BIN,
|
|
cwd: process.cwd(),
|
|
env: { ...process.env },
|
|
model: "claude-sonnet-4-5",
|
|
tools: ["Read", "Write", "Bash"],
|
|
allowedTools: ["Read", "Write", "Bash"],
|
|
settingSources: [],
|
|
hooks: { PreToolUse: [matcher] },
|
|
stderr: (d) => process.stderr.write(d),
|
|
},
|
|
})) {
|
|
console.log(JSON.stringify(m));
|
|
}
|
|
console.log(JSON.stringify({ sdk_probe: "query-ended" }));
|
|
} catch (e) {
|
|
console.log(JSON.stringify({ sdk_probe: "query-threw", error: String(e?.message ?? e) }));
|
|
process.exitCode = 1;
|
|
}
|