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.
30 lines
784 B
TypeScript
30 lines
784 B
TypeScript
/**
|
|
* Protected Paths Hook
|
|
*
|
|
* Blocks write and edit operations to protected paths.
|
|
* Useful for preventing accidental modifications to sensitive files.
|
|
*/
|
|
import type { HookAPI } from "@oh-my-pi/pi-coding-agent";
|
|
|
|
export default function (pi: HookAPI) {
|
|
const protectedPaths = [".env", ".git/", "node_modules/"];
|
|
|
|
pi.on("tool_call", async (event, ctx) => {
|
|
if (event.toolName !== "write" && event.toolName !== "edit") {
|
|
return undefined;
|
|
}
|
|
|
|
const path = event.input.path as string;
|
|
const isProtected = protectedPaths.some(p => path.includes(p));
|
|
|
|
if (isProtected) {
|
|
if (ctx.hasUI) {
|
|
ctx.ui.notify(`Blocked write to protected path: ${path}`, "warning");
|
|
}
|
|
return { block: true, reason: `Path "${path}" is protected` };
|
|
}
|
|
|
|
return undefined;
|
|
});
|
|
}
|