import type { DatabaseAdapter } from '../db-manager.js'; import { type CaseTargetRef } from './target-ref.js'; import type { CaseCorrectionRequiresReconfirmResult } from './types.js'; export type CaseCorrectionErrorCode = 'case.precompile_gap' | 'case.correction_requires_reconfirm' | 'case.correction_active_conflict' | 'case.correction_not_found' | 'case.correction_reverted' | 'case.correction_inactive' | 'case.correction_already_superseded' | 'case.supersede_target_mismatch' | 'case.reconfirm_token_invalid' | 'case.reconfirm_token_replayed' | 'case.terminal_status' | 'case.lock_held'; export interface ApplyCorrectionInput { case_id: string; target_kind: 'case_field' | 'membership' | 'wiki_section'; target_ref: CaseTargetRef; field_name?: 'status' | 'status_reason' | 'primary_actors' | 'blockers' | 'confidence'; old_value_json?: string | null; reconfirm_token?: string | null; session_id?: string | null; new_value_json: string; reason: string; confirmed: true; confirmed_by: string; confirmation_summary: string; now?: string; } export type CorrectionApplyResult = { kind: 'applied'; correction_id: string; case_id: string; target_ref_json: string; canonical_hash_hex: string; } | CaseCorrectionRequiresReconfirmResult | { kind: 'precompile_gap'; code: 'case.precompile_gap'; case_id: string; } | { kind: 'rejected'; code: CaseCorrectionErrorCode; message: string; case_id: string; }; export interface RevertCorrectionInput { correction_id: string; confirmed: true; confirmed_by: string; confirmation_summary: string; now?: string; } export type CorrectionRevertResult = { kind: 'reverted'; correction_id: string; case_id: string; } | { kind: 'precompile_gap'; code: 'case.precompile_gap'; case_id: string; } | { kind: 'rejected'; code: CaseCorrectionErrorCode; message: string; correction_id?: string; }; export interface SupersedeCorrectionInput { old_correction_id: string; new_value_json: string; reason: string; confirmed: true; confirmed_by: string; confirmation_summary: string; /** * The current value the user saw in the drawer when they chose to * supersede. When provided and it disagrees with the live value, the * helper returns `case.correction_requires_reconfirm`. Omit to skip * CAS — in that case the caller trusts the active correction as the * sole source of truth. */ expected_current_value_json?: string | null; reconfirm_token?: string | null; session_id?: string | null; now?: string; } export type CorrectionSupersedeResult = { kind: 'superseded'; old_correction_id: string; new_correction_id: string; case_id: string; target_ref_json: string; canonical_hash_hex: string; } | CaseCorrectionRequiresReconfirmResult | { kind: 'precompile_gap'; code: 'case.precompile_gap'; case_id: string; } | { kind: 'rejected'; code: CaseCorrectionErrorCode; message: string; correction_id?: string; case_id?: string; }; export interface ReconfirmTokenPayload { v: 1; kid: string; nonce: string; case_id: string; target_kind: ApplyCorrectionInput['target_kind']; target_ref_hash_hex: string; current_value_hash_hex: string; proposed_value_hash_hex: string; confirmed_by: string; session_id: string | null; expires_at: string; } export interface ReconfirmTokenEnvelope { kid: string; payload: ReconfirmTokenPayload; signature_hex: string; } export interface InsertCaseCorrectionLockInput { correction_id?: string; case_id: string; target_kind: ApplyCorrectionInput['target_kind']; target_ref: CaseTargetRef; field_name?: ApplyCorrectionInput['field_name'] | null; old_value_json: string | null; new_value_json: string; reason: string; applied_by: string; applied_at: string; is_lock_active?: 0 | 1; superseded_by?: string | null; } export interface InsertCaseCorrectionLockResult { correction_id: string; case_id: string; target_kind: ApplyCorrectionInput['target_kind']; target_ref_json: string; target_ref_hash: Uint8Array; canonical_hash_hex: string; applied_at: string; is_lock_active: 0 | 1; } export declare function insertCaseCorrectionLock(adapter: DatabaseAdapter, input: InsertCaseCorrectionLockInput): InsertCaseCorrectionLockResult; export declare function applyCorrection(adapter: DatabaseAdapter, input: ApplyCorrectionInput): CorrectionApplyResult; export declare function revertCorrection(adapter: DatabaseAdapter, input: RevertCorrectionInput): CorrectionRevertResult; /** * supersedeCorrection — Phase 2b. Unblocked by spec amendment-8 (2026-04-18) * which added `superseded_by` to the mutable-column set in §5.4. * * Semantics: user changes their mind on an active correction. Inside a single * transaction: * 1. Read OLD row; reject if not found / reverted / already superseded / inactive. * 2. INSERT new correction row referencing the same (case_id, target_kind, * target_ref_hash) with new_value_json and is_lock_active=1. * 3. UPDATE OLD row: superseded_by = new.correction_id, is_lock_active = 0. * 4. Emit case.correction_superseded memory_event. * * Per spec §5.4 invariant (amendment-8), the three mutable columns are * is_lock_active + reverted_at + superseded_by. superseded_by is written * ONLY inside this transition. */ export declare function supersedeCorrection(adapter: DatabaseAdapter, input: SupersedeCorrectionInput): CorrectionSupersedeResult; //# sourceMappingURL=corrections.d.ts.map