/** * Polyglot AST Invariant Engine * * Deterministic backward-compatibility & invariant validator that checks AST * diffs between original code and LLM mutations before changes are written to disk. * * Rules are implemented for TypeScript/JavaScript, Python, Go and Rust: * - INV-001: Export / Public Symbol Deletion or Rename * - INV-002: Mandatory / Non-Default Parameter Addition * - INV-003: Mandatory Interface / Trait / Model Property Addition * - INV-004: Incompatible Return Type Alteration * * Any other language has no contract extractor: the result says so through * `supported: false` instead of reporting an empty diff as "compatible". */ import type { SymbolLang } from './schema.js'; export type InvariantRuleId = 'INV-001' | 'INV-002' | 'INV-003' | 'INV-004'; export interface InvariantViolation { ruleId: InvariantRuleId; symbolName: string; lang: SymbolLang; message: string; severity: 'CRITICAL' | 'WARNING'; details?: { addedParameter?: string | undefined; addedProperty?: string | undefined; expectedModifier?: string | undefined; originalSignature?: string | undefined; modifiedSignature?: string | undefined; } | undefined; } export interface InvariantEvaluationResult { valid: boolean; violations: InvariantViolation[]; /** Language the rules were evaluated as. */ lang: SymbolLang; /** * False when no contract extractor exists for `lang` (or its grammar failed * to load). `valid: true` then means "nothing was checked", not "compatible". */ supported: boolean; stats: { originalSymbols: number; modifiedSymbols: number; durationMs: number; }; } interface ParameterContract { name: string; isOptional: boolean; hasDefault: boolean; isRest: boolean; type?: string | undefined; } interface FunctionContract { name: string; isExported: boolean; params: ParameterContract[]; returnType?: string | undefined; } interface InterfacePropertyContract { name: string; isOptional: boolean; hasDefault?: boolean | undefined; type?: string | undefined; } interface InterfaceContract { name: string; isExported: boolean; properties: InterfacePropertyContract[]; methods: Array<{ name: string; isOptional: boolean; params: ParameterContract[]; returnType?: string | undefined; }>; } export interface ModuleContract { lang: SymbolLang; exports: Set; /** * Keyed by SCOPED name (`Class.method`, `Receiver.Method`, `Type.fn`): a * bare-name key let `impl A { fn new }` overwrite `impl B { fn new }`, so the * rules compared unrelated functions and missed the real change. */ functions: Map; interfaces: Map; /** False when this language has no extractor or its grammar did not load. */ supported: boolean; } /** * Universal AST Invariant Engine for deterministic backward compatibility validation. */ export declare class PolyglotInvariantEngine { /** * Evaluate whether a code mutation respects backward compatibility invariants. */ evaluate(opts: { originalCode: string; modifiedCode: string; lang?: SymbolLang | undefined; filePath?: string | undefined; }): Promise; /** * Extract high-level contract signatures from source code. */ extractContract(code: string, lang: SymbolLang): Promise; /** * TypeScript & JavaScript extraction via TS Compiler API. */ private extractTsContract; /** * Polyglot extraction (Python, Go, Rust) via Tree-sitter WASM. */ private extractTreeSitterContract; } /** Singleton instance ready for use across WrongStack */ export declare const polyglotInvariantEngine: PolyglotInvariantEngine; export {}; //# sourceMappingURL=ast-invariant-engine.d.ts.map