/** * Output repair contract — types for the bounded structured-output repair loop. * * Per AGENT_SOFTWARE_CONTRACT.md Layer 2: * raw LLM output → JSON extraction → schema validation → * schema invalid → build repair prompt → bounded retry → * still invalid → output_invalid + evidence pack * * Design principles: * - Evidence pack is always observable (schemaRef, provider, model, errors, attempts) * - Repair loop is bounded (max 1-2 attempts) * - Lineage fields are protected during repair * - Failure types are classified for telemetry routing */ export type OutputFailureKind = 'extraction_failed' | 'schema_invalid' | 'repair_exhausted'; export interface OutputValidationErrorEntry { readonly path: string; readonly expected: string; readonly actualPreview: string; } export interface OutputRepairAttempt { readonly schemaRef: string; readonly attempt: number; readonly rawOutputPreview: string; readonly validationErrors: readonly OutputValidationErrorEntry[]; readonly repairPromptVersion: string; readonly repaired: boolean; } export interface OutputEvidencePack { readonly schemaRef: string; readonly provider: string; readonly model: string; readonly promptContractVersion?: string; readonly rawOutputPreview: string; readonly validationErrors: readonly OutputValidationErrorEntry[]; readonly repairAttempts: readonly OutputRepairAttempt[]; readonly finalFailureReason: OutputFailureKind; /** PRI-621 RC3: complete JSON objects found in the answer (diagnostic). */ readonly extractionCandidateCount?: number; /** PRI-621 RC3: selected object matched none of the schema's required keys. */ readonly truncationSuspected?: true; /** * PRI-707: provider finish metadata, preserved only when the adapter's * response actually carried it — never fabricated. `truncated` is set * exclusively from finish_reason=length (definitive), unlike the * `truncationSuspected` heuristic which also fires for wrong-shape output. */ readonly stopReason?: string; readonly truncated?: true; /** Provider-reported output token count when usage was supplied. */ readonly outputTokens?: number; } export declare const REPAIR_PROMPT_VERSION = "2"; export declare const MAX_REPAIR_ATTEMPTS = 3; export declare function normalizeMaxRepairAttempts(raw: number | undefined, defaultVal: number): number; export declare function truncatePreview(text: string, maxLen?: number): string; export declare function safeStringifyPreview(value: unknown, maxLen?: number): string; export declare const LINEAGE_FIELDS: readonly ['taskId', 'sourcePainId', 'sourceTaskId', 'sourceRunIds', 'sourceArtifactId', 'sourceRefs']; export type LineageField = typeof LINEAGE_FIELDS[number]; export declare function isLineageField(key: string): key is LineageField; export declare function preserveLineageFields(original: Record, repaired: Record): Record; export declare function stripLineageFields(obj: Record): Record; export declare function formatValidationErrorEntry(path: string, message: string, value: unknown): OutputValidationErrorEntry; //# sourceMappingURL=output-repair-contract.d.ts.map