/** * Adaptive Validation module for the CLEO Intelligence dimension. * * Extends the prediction layer with: * - Gate-level failure tracking: which verification gates fail most for which task types * - Adaptive focus suggestions: recommend which gates to pay attention to given task attributes * - Confidence scoring: compute and persist a 0-1 confidence score after task verification * - Prediction storage: persist quality predictions back to brain as observations so * subsequent sessions can learn from them * * All storage goes to existing brain tables (brain_observations, brain_learnings, * brain_patterns). No new tables required. * * @task T035 * @epic T029 * @module intelligence */ import type { TaskVerification, VerificationGate } from '@cleocode/contracts'; import type { DataAccessor } from '../store/data-accessor.js'; import type { BrainDataAccessor } from '../store/memory-accessor.js'; import type { ValidationPrediction } from './types.js'; /** * A gate-level focus recommendation produced by adaptive validation. */ export interface GateFocusRecommendation { /** The verification gate this recommendation applies to. */ gate: VerificationGate; /** * Priority level: high gates should be checked first; low gates are lower * risk for this task type and can be reviewed last. */ priority: 'high' | 'medium' | 'low'; /** Human-readable rationale for this priority level. */ rationale: string; /** * Estimated pass likelihood for this gate (0-1) based on historical * patterns and task metadata. Null when no historical data is available. */ estimatedPassLikelihood: number | null; } /** * Full adaptive validation suggestion set for a task. */ export interface AdaptiveValidationSuggestion { /** Task ID this suggestion applies to. */ taskId: string; /** Ordered gate recommendations (highest priority first). */ gateFocus: GateFocusRecommendation[]; /** Overall confidence that the task will pass all required gates. */ overallConfidence: number; /** * Actionable tips derived from gate focus analysis. * Includes failure-pattern mitigations where available. */ tips: string[]; } /** * Result of scoring and persisting a completed verification round. */ export interface VerificationConfidenceScore { /** Task ID. */ taskId: string; /** * Computed confidence score (0-1). * * Score derivation: * - Gates passed vs required gates: up to 0.6 * - Failure log length (fewer failures = higher confidence): up to 0.2 * - Round number (fewer rounds = higher confidence): up to 0.2 */ confidenceScore: number; /** Whether the overall verification passed. */ passed: boolean; /** IDs of gates that passed. */ gatesPassed: VerificationGate[]; /** IDs of gates that failed or are missing. */ gatesFailed: VerificationGate[]; /** Brain observation ID if the score was persisted (may be undefined on dry run). */ observationId?: string; /** Brain learning ID if a learning was extracted (may be undefined). */ learningId?: string; } /** * Parameters for storing a quality prediction as a brain observation. */ export interface StorePredictionOptions { /** Whether to skip persisting to brain (useful in tests). Default: false. */ dryRun?: boolean; /** Session ID to attach to the observation (optional). */ sessionId?: string; /** Project identifier to attach to the observation (optional). */ project?: string; } /** * Suggest which verification gates to focus on for a task, ordered by risk. * * Uses: * - Historical failure patterns from brain_patterns filtered by task type/labels * - Task characteristics (size, type, labels, priority) to weight gate risk * - Existing gate state from task.verification to skip already-passed gates * * @param taskId - The task to analyze * @param taskAccessor - DataAccessor for tasks.db * @param brainAccessor - BrainDataAccessor for brain.db * @returns Ordered gate focus recommendations and overall confidence */ export declare function suggestGateFocus(taskId: string, taskAccessor: DataAccessor, brainAccessor: BrainDataAccessor): Promise; /** * Compute a confidence score for a completed verification round and persist * it to brain.db as an observation and learning. * * Called after `cleo verify` gates are set. Stores: * - A `brain_observations` row (type: 'discovery') with score, gates, task metadata * - A `brain_learnings` row if the result is notable (high pass or high failure) * * @param taskId - The task that was verified * @param verification - The task's current verification state * @param taskAccessor - DataAccessor for tasks.db * @param brainAccessor - BrainDataAccessor for brain.db * @param options - Persistence and session options * @returns Computed confidence score with optional persisted observation/learning IDs */ export declare function scoreVerificationConfidence(taskId: string, verification: TaskVerification, taskAccessor: DataAccessor, brainAccessor: BrainDataAccessor, options?: StorePredictionOptions): Promise; /** * Store a validation prediction as a brain observation for future learning. * * Saves the full `ValidationPrediction` to brain_observations so that * accumulated predictions can later be analyzed to improve gate pass rates. * * @param prediction - The prediction to persist * @param brainAccessor - BrainDataAccessor for brain.db * @param options - Dry-run and session options * @returns The created brain observation ID (or undefined on dry run) */ export declare function storePrediction(prediction: ValidationPrediction, brainAccessor: BrainDataAccessor, options?: StorePredictionOptions): Promise; /** * Compute a prediction for a task and immediately persist it to brain. * * Convenience wrapper combining `predictValidationOutcome` and `storePrediction`. * * @param taskId - The task to predict and record * @param stage - The lifecycle stage being predicted * @param taskAccessor - DataAccessor for tasks.db * @param brainAccessor - BrainDataAccessor for brain.db * @param options - Dry-run and session options * @returns The prediction with optional stored observation ID */ export declare function predictAndStore(taskId: string, stage: string, taskAccessor: DataAccessor, brainAccessor: BrainDataAccessor, options?: StorePredictionOptions): Promise; //# sourceMappingURL=adaptive-validation.d.ts.map