/** * ContractDiff — Behavioral Contract Diffing Engine * * Computes the semantic difference between two snapshots of a * `ToolContract`. Unlike naive JSON diffing, this engine understands * the behavioral semantics of each field and classifies changes by * severity: * * - **BREAKING**: The behavioral surface changed in a way that will * cause an LLM that was previously calibrated to this tool to * fail or hallucinate. Examples: egress schema fields removed, * system rules changed, affordance topology altered. * * - **RISKY**: The behavioral surface changed in a way that might * affect LLM behavior but won't cause immediate failure. Examples: * cognitive guardrails loosened, middleware chain changed. * * - **SAFE**: The change is additive and won't affect existing * LLM behavior. Examples: new action added, description improved. * * - **COSMETIC**: No behavioral impact. Examples: description * rewording with identical semantics. * * Pure-function module: no state, no side effects. * * @module */ import type { ToolContract } from './ToolContract.js'; /** Severity classification for a contract change */ export type DeltaSeverity = 'BREAKING' | 'RISKY' | 'SAFE' | 'COSMETIC'; /** * A single atomic change in a tool contract. * * Designed to be human-readable, machine-diffable, and injectable * into LLM correction prompts (Self-Healing Context). */ export interface ContractDelta { /** Which part of the contract changed */ readonly category: DeltaCategory; /** Specific field or sub-path that changed */ readonly field: string; /** Severity classification */ readonly severity: DeltaSeverity; /** Human-readable description of the change */ readonly description: string; /** Previous value (serialized) */ readonly before: string | null; /** New value (serialized) */ readonly after: string | null; } /** * Broad category of what changed in the contract. * Maps to the major sections of `ToolContract`. */ export type DeltaCategory = 'surface' | 'surface.action' | 'behavior.egress' | 'behavior.rules' | 'behavior.guardrails' | 'behavior.middleware' | 'behavior.stateSync' | 'behavior.affordances' | 'tokenEconomics' | 'entitlements'; /** * Result of a full contract diff operation. */ export interface ContractDiffResult { /** Tool name */ readonly toolName: string; /** All detected deltas, sorted by severity */ readonly deltas: readonly ContractDelta[]; /** Highest severity found */ readonly maxSeverity: DeltaSeverity; /** Whether the overall behavior digest changed */ readonly digestChanged: boolean; /** Whether the contract is backwards-compatible */ readonly isBackwardsCompatible: boolean; } /** * Compute the semantic diff between two snapshots of a tool contract. * * @param before - Previous contract snapshot * @param after - Current contract snapshot * @returns Classified, sorted list of deltas */ export declare function diffContracts(before: ToolContract, after: ToolContract): ContractDiffResult; /** * Format a diff result as a human-readable report. * * Designed for both terminal output and injection into * LLM correction prompts (Self-Healing Context). */ export declare function formatDiffReport(result: ContractDiffResult): string; /** * Format deltas as XML for injection into LLM correction prompts. * Compatible with ValidationErrorFormatter's XML format. */ export declare function formatDeltasAsXml(deltas: readonly ContractDelta[]): string; //# sourceMappingURL=ContractDiff.d.ts.map