/** * ContractAwareSelfHealing — Runtime Contract Delta Injection * * **Evolution 4: Self-Healing Context** * * When a Zod validation error occurs (the LLM sent malformed * arguments), this module enriches the error response with * contract change context. If the tool's behavioral contract * has changed since the LLM was last calibrated, the error * message includes: * * 1. Which contract fields changed (from ContractDiff) * 2. What the previous contract looked like * 3. What the current contract requires * * This gives the LLM enough context to self-correct on the * next invocation instead of repeating the same mistake. * * **Integration**: Plugs into the existing `formatValidationError()` * pipeline via a wrapping function that checks for relevant * contract deltas and injects them into the XML error response. * * **Zero-overhead**: When no contract changes exist, the function * passes through to the original formatter with zero additional cost. * * @module */ import type { ContractDiffResult } from './ContractDiff.js'; /** * Configuration for contract-aware self-healing. */ export interface SelfHealingConfig { /** * Active contract diff results, keyed by tool name. * Populated at server startup by diffing current contracts * against the last known-good lockfile. */ readonly activeDeltas: ReadonlyMap; /** * Whether to inject deltas for all severity levels. * Default: only BREAKING and RISKY. */ readonly includeAllSeverities?: boolean; /** * Maximum number of deltas to inject per error. * Prevents context flooding from large diffs. * Default: 5. */ readonly maxDeltasPerError?: number; } /** * Result of self-healing injection. */ export interface SelfHealingResult { /** The original error XML */ readonly originalError: string; /** The enriched error XML with contract context */ readonly enrichedError: string; /** Whether any contract context was injected */ readonly injected: boolean; /** Number of deltas injected */ readonly deltaCount: number; /** Tool name */ readonly toolName: string; } /** * Enrich a validation error with contract change context. * * If the tool has relevant contract changes (from `SelfHealingConfig.activeDeltas`), * this function injects them into the error XML so the LLM can self-correct. * * @param originalError - The original XML error from `formatValidationError()` * @param toolName - The tool that failed validation * @param actionKey - The action that failed * @param config - Self-healing configuration with active deltas * @returns Enriched error string with contract context */ export declare function enrichValidationError(originalError: string, toolName: string, actionKey: string, config: SelfHealingConfig): SelfHealingResult; /** * Create a tool-scoped self-healing enhancer. * * This is the primary integration point: wraps a per-tool * error formatter with contract delta context. * * @param toolName - The tool name for delta lookup * @param config - Self-healing configuration * @returns A function that enriches error strings */ export declare function createToolEnhancer(toolName: string, config: SelfHealingConfig): (errorXml: string, actionKey: string) => string; //# sourceMappingURL=ContractAwareSelfHealing.d.ts.map