0.6 rust重构01
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#!/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",
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user