Files
mnote/.codex/hooks/omx/pre-tool-use.mjs
T

38 lines
730 B
JavaScript
Raw Normal View History

2026-04-14 13:22:29 +08:00
#!/usr/bin/env node
import { readFileSync } from "node:fs";
function readStdin() {
try {
return JSON.parse(readFileSync(0, "utf8") || "{}");
} catch {
return {};
}
}
const payload = readStdin();
const command = JSON.stringify(payload).toLowerCase();
const blocked = [
"rm -rf /",
"mkfs",
"dd if=",
"shutdown",
"reboot",
"poweroff",
"git reset --hard",
];
if (blocked.some((token) => command.includes(token))) {
process.stdout.write(JSON.stringify({
decision: "block",
reason: "OMX safety hook blocked an obviously destructive command.",
}));
process.exit(0);
}
process.stdout.write(JSON.stringify({
continue: true,
hookSpecificOutput: {
hookEventName: "PreToolUse",
},
}));