import type { ValidationRule, ValidationContext } from '../interfaces'; import { ValidationSeverity } from '../interfaces'; /** * Configuration options for NoCallTargetAssignmentRule */ /** * Error types for NoCallTargetAssignmentRule */ export type NoCallTargetAssignmentErrorType = 'assignment' | 'declaration' | 'function-declaration' | 'function-expression' | 'class-declaration' | 'destructuring' | 'destructuring-rest' | 'parameter' | 'catch-parameter' | 'import'; export interface NoCallTargetAssignmentOptions { /** * List of protected call targets that cannot be assigned or shadowed * Default: ['callTool'] */ protectedTargets?: string[]; /** * Custom error message */ message?: string; } /** * NoCallTargetAssignmentRule - Blocks assignment and shadowing of protected call targets * * This rule prevents user code from: * - Reassigning protected identifiers like `callTool` * - Shadowing protected identifiers via declarations * - Destructuring to shadow protected identifiers * * **Purpose:** * - Protect the integrity of core API functions * - Prevent users from overriding tool call behavior * - Ensure sandbox security by preserving call targets * * **Example violations:** * ```javascript * callTool = () => 'pwned'; // ❌ BLOCKED: Assignment to protected target * const callTool = () => {}; // ❌ BLOCKED: Declaration shadows protected target * const { callTool } = obj; // ❌ BLOCKED: Destructuring shadows protected target * function callTool() {} // ❌ BLOCKED: Function declaration shadows * ``` * * **Valid code:** * ```javascript * await callTool('test', {}); // ✅ OK: Using callTool * const result = await callTool('x', {}); // ✅ OK: Using return value * ``` * * @example * ```typescript * const rule = new NoCallTargetAssignmentRule({ * protectedTargets: ['callTool', 'myCustomAPI'], * }); * ``` */ export declare class NoCallTargetAssignmentRule implements ValidationRule { readonly name = "no-call-target-assignment"; readonly description = "Blocks assignment and shadowing of protected call targets"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = true; private readonly protectedTargets; private readonly customMessage?; constructor(options?: NoCallTargetAssignmentOptions); validate(context: ValidationContext): void; /** * Check object pattern for protected identifiers */ private checkObjectPattern; /** * Check array pattern for protected identifiers */ private checkArrayPattern; /** * Check function parameters for protected identifiers */ private checkParameters; /** * Report a validation error */ private reportError; }