1 hour ago · Tech · hide · 0 comments

♠ Problem statement: block destructive shell commands issued by pi without resorting to grepping shell source with regular expressions. My first guard was a direct port of an older hook in Claude Code: const BLOCKED_COMMANDS: ReadonlyArray<{ pattern: RegExp; reason: string }> = [ { pattern: /terraform\s+apply/, reason: "terraform apply is blocked - use terraform plan first" }, { pattern: /terraform\s+destroy/, reason: "terraform destroy is blocked for safety" }, { pattern: /git\s+reset\s+.*--hard/, reason: "git reset --hard is blocked - discards changes irreversibly" }, ]; const blocked = BLOCKED_COMMANDS.find(({ pattern }) => pattern.test(command)); This matched harmless strings such as echo 'terraform destroy', while shell quoting, wrappers, substitutions, and reordered options kept opening holes. Regexes aren’t robust in this context. Enter ASTs! Shell source could leverage a shell parser. I switched the extension to the Bash grammar from tree-sitter-bash, loaded through the WASM…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.