import type { ValidationRule, ValidationContext } from '../interfaces'; import { ValidationSeverity } from '../interfaces'; /** * Configuration options for ReservedPrefixRule */ export interface ReservedPrefixOptions { /** * List of reserved prefixes that identifiers cannot use * Default: ['__ag_', '__safe_'] */ reservedPrefixes?: string[]; /** * List of allowed identifiers that can use reserved prefixes * (for internal/compiler use) * Default: ['__ag_main'] */ allowedIdentifiers?: string[]; /** * Custom error message */ message?: string; } /** * ReservedPrefixRule - Blocks identifiers starting with reserved prefixes * * This rule prevents user code from using internal runtime/compiler prefixes, * ensuring no collision with: * - `__ag_*` - AgentScript compiler/runtime internals * - `__safe_*` - Safe runtime wrappers * * **Purpose:** * - Protect internal implementation details from user access * - Prevent namespace pollution * - Ensure clear separation between user code and runtime * * **Example violations:** * ```javascript * const __ag_main = 42; // ❌ BLOCKED: __ag_ prefix reserved * const __safe_callTool = () => {}; // ❌ BLOCKED: __safe_ prefix reserved * function __ag_helper() {} // ❌ BLOCKED: __ag_ prefix reserved * ``` * * **Valid code:** * ```javascript * const main = 42; // ✅ OK * const safeTool = () => {}; // ✅ OK * function helper() {} // ✅ OK * ``` * * @example * ```typescript * const rule = new ReservedPrefixRule({ * reservedPrefixes: ['__ag_', '__safe_', '__internal_'], * }); * ``` */ export declare class ReservedPrefixRule implements ValidationRule { readonly name = "reserved-prefix"; readonly description = "Blocks identifiers starting with reserved prefixes"; readonly defaultSeverity = ValidationSeverity.ERROR; readonly enabledByDefault = true; private readonly reservedPrefixes; private readonly allowedIdentifiers; private readonly customMessage?; constructor(options?: ReservedPrefixOptions); validate(context: ValidationContext): void; /** * Check if an identifier starts with a reserved prefix */ private checkIdentifier; /** * Check destructuring patterns for reserved prefixes */ private checkPattern; /** * Check assignment targets for reserved prefixes * Security: Blocks runtime reassignment of protected identifiers * * @example * __safe_callTool = () => 'pwned'; // ❌ BLOCKED * __ag_counter = 0; // ❌ BLOCKED */ private checkAssignmentTarget; /** * Check member expression assignments for reserved prefixes * Security: Blocks assignment to properties with reserved prefixes * * @example * obj.__safe_callTool = malicious; // ❌ BLOCKED * obj['__safe_callTool'] = malicious; // ❌ BLOCKED * this.__ag_internal = 42; // ❌ BLOCKED */ private checkMemberAssignment; }