38 lines
730 B
JavaScript
38 lines
730 B
JavaScript
#!/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",
|
|
},
|
|
}));
|