import type { SqliteDatabase } from '../sqlite/sqlite-driver.js'; import { ZodError } from 'zod'; import { EVOLUTION_DEFAULT_DELTA_MIN, type EvolutionEvaluation, type EvolutionProposal, type EvolutionProposalInput, type EvolutionTargetKind, type EvolutionVerdict } from './evolution-types.js'; /** * EvolutionService — Darwin-style ratchet enforcement. * * Hard rules enforced at THIS layer (not just the Zod schema) so * the ratchet cannot be bypassed by a malformed input: * * exactly one optimization dimension per round. * Code: EVOLUTION_MULTI_OBJECT, EVOLUTION_MULTI_DIMENSION. * Code: EVOLUTION_SELF_SCORE. * score_delta < score_delta_min (default 1.0). * Code: EVOLUTION_DELTA_BELOW_THRESHOLD. * author_id and skeptic_id. * author_id and evaluator_id. * * The service is intentionally narrow: createProposal / score / * markVerdict / list / get. The actual scoring agents * (IndependentEvaluatorRunner, RegressionSkepticRunner) live in * separate files so the author reasoning is NEVER imported into * the evaluator's process boundary. */ export type EvolutionIntegrityErrorCode = 'EVOLUTION_MULTI_OBJECT' | 'EVOLUTION_MULTI_DIMENSION' | 'EVOLUTION_SELF_SCORE' | 'EVOLUTION_DELTA_BELOW_THRESHOLD' | 'EVOLUTION_MISSING_USER_CONFIRMATION' | 'EVOLUTION_BELOW_RUBRIC'; export declare class EvolutionIntegrityError extends Error { readonly code: EvolutionIntegrityErrorCode; readonly findings: ReadonlyArray<{ path: string; message: string; }>; constructor(code: EvolutionIntegrityErrorCode, message: string, findings?: ReadonlyArray<{ path: string; message: string; }>); } export declare class EvolutionService { private readonly db; constructor(db: SqliteDatabase); /** * single dimension) BEFORE writing the row. * * The proposal id is auto-generated (`eval-`); callers supply * the proposal content only. The proposal's `verdict` is set to * `needs-user-decision` until the score + skeptic step lands. * * Throws: * - ZodError if the input fails schema validation. * - EvolutionIntegrityError(EVOLUTION_MULTI_OBJECT) if * single_object !== true. * - EvolutionIntegrityError(EVOLUTION_MULTI_DIMENSION) if * single_optimization_dimension !== true. */ createProposal(input: EvolutionProposalInput): EvolutionProposal; /** * threshold: cannot mark `keep` when `score_delta < * score_delta_min`). * * Returns the FINAL evaluation row with verdict derived from the * evaluator + skeptic results: * - `verdict = 'revert'` if the skeptic returned a blocker. * - `verdict = 'revert'` if the score delta is below threshold. * - `verdict = 'needs-user-decision'` otherwise; the CLI * (`peaks evolution evaluate`) surfaces this to the user for * a `keep` / `revert` choice. * * Throws: * - EvolutionIntegrityError(EVOLUTION_SELF_SCORE) if * evaluator_id === proposal.author_id. * - EvolutionIntegrityError(EVOLUTION_DELTA_BELOW_THRESHOLD) if * a `verdict = 'keep'` is requested and the delta is below * the proposal's `score_delta_min`. */ score(proposalId: string, args: { evaluator_id: string; skeptic_id: string; evaluator_result: import('./evolution-types.js').IndependentEvaluatorResult; skeptic_result: import('./evolution-types.js').RegressionSkepticResult; brief_pointer?: string; user_confirmation_pointer?: string; }): EvolutionEvaluation; /** * Mark a verdict explicitly (after the user has confirmed via * natural-language or a pick). Enforces: * score_delta_min. * * Throws: * - EvolutionIntegrityError(EVOLUTION_DELTA_BELOW_THRESHOLD) * when `verdict = 'keep'` and the delta is below threshold. * - EvolutionIntegrityError(EVOLUTION_MISSING_USER_CONFIRMATION) * when `verdict = 'keep'` and no user_confirmation_pointer * is supplied. */ markVerdict(proposalId: string, verdict: EvolutionVerdict, userConfirmationPointer?: string): EvolutionEvaluation | undefined; /** Revert a proposal (universal recovery). Always allowed. */ revert(proposalId: string, userConfirmationPointer?: string): EvolutionEvaluation | undefined; /** Read an evolution evaluation by id. */ read(proposalId: string): EvolutionEvaluation | undefined; /** List evaluations for a given target. */ listByTarget(opts: { target_kind: EvolutionTargetKind; target_release_id: string; verdict?: EvolutionVerdict; }): EvolutionEvaluation[]; /** * Status snapshot for `peaks evolution status`. Returns counts of * evaluations by verdict for the given target, plus the latest * evaluation id (if any). */ status(target: { target_kind: EvolutionTargetKind; target_release_id: string; }): { target_kind: EvolutionTargetKind; target_release_id: string; total: number; byVerdict: Record; latest: EvolutionEvaluation | undefined; }; } /** * Convenience: re-export the Zod error guard. */ export declare function isZodError(err: unknown): err is ZodError; /** * Convenience: get the default `score_delta_min` from the spec. */ export { EVOLUTION_DEFAULT_DELTA_MIN };