779ca4872b
- Removed Prettier configuration files (.prettierignore and .prettierrc) and migrated formatting to Biome. - Updated Biome configuration from version 2.3.11 to 2.3.12 and changed arrowParentheses rule from 'always' to 'asNeeded'. - Pinned @biomejs/biome dependency to exact version 2.3.12 in package.json and bun.lock. - Applied consistent arrow function formatting across 489 files by removing unnecessary parentheses around single parameters. - Removed blank lines after comment blocks and reorganized imports for consistency across the codebase.
34 lines
995 B
TypeScript
34 lines
995 B
TypeScript
/**
|
|
* Permission Gate Hook
|
|
*
|
|
* Prompts for confirmation before running potentially dangerous bash commands.
|
|
* Patterns checked: rm -rf, sudo, chmod/chown 777
|
|
*/
|
|
import type { HookAPI } from "@oh-my-pi/pi-coding-agent";
|
|
|
|
export default function (pi: HookAPI) {
|
|
const dangerousPatterns = [/\brm\s+(-rf?|--recursive)/i, /\bsudo\b/i, /\b(chmod|chown)\b.*777/i];
|
|
|
|
pi.on("tool_call", async (event, ctx) => {
|
|
if (event.toolName !== "bash") return undefined;
|
|
|
|
const command = event.input.command as string;
|
|
const isDangerous = dangerousPatterns.some(p => p.test(command));
|
|
|
|
if (isDangerous) {
|
|
if (!ctx.hasUI) {
|
|
// In non-interactive mode, block by default
|
|
return { block: true, reason: "Dangerous command blocked (no UI for confirmation)" };
|
|
}
|
|
|
|
const choice = await ctx.ui.select(`⚠️ Dangerous command:\n\n ${command}\n\nAllow?`, ["Yes", "No"]);
|
|
|
|
if (choice !== "Yes") {
|
|
return { block: true, reason: "Blocked by user" };
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
});
|
|
}
|