mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
- Add setEditorText() and getEditorText() to HookUIContext for prompt generator pattern - custom() now accepts async factories for fire-and-forget work - Add CancellableLoader component to tui package - Add BorderedLoader component for hooks with cancel UI - Export HookAPI, HookContext, HookFactory from main package - Update all examples to import from packages instead of relative paths - Update hooks.md and custom-tools.md documentation fixes #350
30 lines
791 B
TypeScript
30 lines
791 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 "@mariozechner/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;
|
|
});
|
|
}
|