// Example mod: answer permission prompts with a team policy. // // hooks.onPermissionRequest fires ONLY where Command Code was about to ask you. Deny rules, // plan mode, and dont-ask have already run, so a mod can never undo them. Return 'allow' or // 'deny' to answer for the person, or undefined to let them decide. A prompt a safety check // forced (isSafetyPrompt: a sensitive file, a risky command) can be denied but never allowed: // an 'allow' there is ignored and you are asked as usual. import type {ModApi} from '@commandcode/harness'; // Anything that can chain or redirect a second command goes to the person: without this, // `git status && npm publish` would pass as a safe `git status`. const SHELL_CONTROL = /[;&|`<>\n]|\$\(/; // Anchored at both ends, so the whole command must be one of these. const SAFE_SHELL = [ /^git (status|diff|log)( .*)?$/, /^pnpm (test|lint|typecheck)( .*)?$/, ]; export default function (cmd: ModApi): void { cmd.hooks({ onPermissionRequest: ({toolName, input}) => { if (toolName !== 'shell_command') return undefined; const command = typeof input.command === 'string' ? input.command : ''; if (/\bcurl\b.*\|\s*(ba)?sh\b/.test(command)) return 'deny'; if (SHELL_CONTROL.test(command)) return undefined; if (SAFE_SHELL.some(pattern => pattern.test(command))) return 'allow'; return undefined; }, }); }