export const DEFAULT_BASH_INTERCEPTOR_RULES = [
    { pattern: "^\\s*(cat|head|tail|less|more)\\s+", tool: "read", message: "Use the read tool instead of shell commands to inspect file contents." },
    { pattern: "^\\s*(grep|rg|ripgrep|ag|ack)\\s+", tool: "search", message: "Use the search tool instead of shell grep commands." },
    { pattern: "^\\s*(find|fd|locate)\\s+.*(-name|-iname|-type|--type|-glob)", tool: "find", message: "Use the find tool instead of shell find/fd/locate commands." },
    { pattern: "^\\s*sed\\s+(-i|--in-place)", tool: "edit", message: "Use the edit tool instead of in-place sed." },
    { pattern: "^\\s*perl\\s+.*-[pn]?i", tool: "edit", message: "Use the edit tool instead of in-place perl." },
    { pattern: "^\\s*awk\\s+.*-i\\s+inplace", tool: "edit", message: "Use the edit tool instead of in-place awk." },
    { pattern: "^\\s*(echo|printf|cat\\s*<<)\\s+(?:[^\"'>]|\"[^\"]*\"|'[^']*')*(?<!\\|)>{1,2}\\|?\\s*[$\\w./~\"'-]", tool: "write", message: "Use the write tool instead of shell redirection to write files." },
];
export function checkBashInterception(command, availableTools, rules = DEFAULT_BASH_INTERCEPTOR_RULES) {
    for (const rule of rules) {
        if (!availableTools.includes(rule.tool))
            continue;
        let matcher;
        try {
            matcher = new RegExp(rule.pattern, rule.flags);
        }
        catch (error) {
            throw new Error(`Invalid bash interceptor rule for ${rule.tool}: ${error instanceof Error ? error.message : String(error)}`);
        }
        if (matcher.test(command.trim())) {
            return `Blocked: ${rule.message}\n\nOriginal command: ${command}`;
        }
    }
    return undefined;
}
export function checkBashInterceptionCandidates(candidates, availableTools, rules = DEFAULT_BASH_INTERCEPTOR_RULES) {
    const seen = new Set();
    for (const candidate of candidates) {
        const command = candidate?.trim();
        if (!command || seen.has(command))
            continue;
        seen.add(command);
        const blocked = checkBashInterception(command, availableTools, rules);
        if (blocked)
            throw new Error(blocked);
    }
}
//# sourceMappingURL=bash-interceptor.js.map