/**
 * PreToolUse handler - evaluates blocking rules for tool invocations.
 * Returns permissionDecision allow/deny with reason.
 */
export const preToolUseHandler = async (payload) => {
    const body = payload.body;
    const toolName = (body?.tool_name ?? body?.toolName ?? '');
    const toolInput = body?.tool_input;
    // Default: allow
    const allow = () => ({
        status: 200,
        body: {
            hookSpecificOutput: {
                hookEventName: 'PreToolUse',
                permissionDecision: 'allow',
                permissionDecisionReason: 'OK',
            },
        },
    });
    const deny = (reason) => ({
        status: 200,
        body: {
            hookSpecificOutput: {
                hookEventName: 'PreToolUse',
                permissionDecision: 'deny',
                permissionDecisionReason: reason,
            },
        },
    });
    // Skip non-write tools
    if (!['Write', 'Edit'].includes(toolName)) {
        return allow();
    }
    // Check file path for protected paths
    const filePath = (toolInput?.file_path ?? toolInput?.filePath ?? '');
    // Protect .specweave/config.json from full overwrites (Edit is fine, Write is not)
    if (filePath.endsWith('.specweave/config.json') && toolName === 'Write') {
        return deny('Cannot overwrite .specweave/config.json with Write — use Edit instead');
    }
    return allow();
};
//# sourceMappingURL=pre-tool-use.js.map