import type { SessionEntry, SessionManager } from "@caupulican/pi-agent-core/node"; import type { LearningDecision } from "../autonomy/contracts.ts"; import { type SessionSnapshotPayload } from "../session-snapshot.ts"; import type { DurableChangeLayer, DurableChangeProposal } from "./learning-gate.ts"; import type { ReflectionWrite } from "./reflection-engine.ts"; /** * Audit + rollback metadata for durable learning changes. Every reflection-sourced write that the * learning policy applies (or converts to a proposal) leaves one of these records in the session * log, so `/autonomy diagnostics` can explain what changed, why, and how to undo it — and * `rollbackLearningWrite` can execute the inverse operation. */ export type LearningRollbackKind = "memory_remove" | "memory_restore" | "memory_add" | "okf_remove" | "okf_organize" | "archive_skill"; export interface LearningRollbackPlan { kind: LearningRollbackKind; /** Text currently present because of the change (to remove/replace), or the skill name to archive. */ target?: string; /** Original text to restore (memory_restore/memory_add). */ previous?: string; /** Compare-and-delete guard for a structured record created by this exact audited write. */ expectedDigest?: string; /** Organization rollback only: false when the OKF record predated this hot-memory move. */ removeOkf?: boolean; instructions: string; } export type LearningAuditAction = "apply" | "apply_failed" | "propose" | "rollback"; /** reasonCode for an "apply_failed" audit — distinct from the gate's own reasonCode (e.g. * "eligible_auto_apply") so the record is honest about WHERE it stopped: the gate approved the * write, but the write tool refused it after the fact. */ export declare const APPLY_WRITE_REFUSED_REASON_CODE = "apply_write_refused"; export interface LearningAuditRecord { id: string; proposalId: string; layer: DurableChangeLayer; action: LearningAuditAction; summary: string; reasonCode: string; decision: LearningDecision; rollback?: LearningRollbackPlan; /** For action "rollback": the audit id of the applied change this record undoes. */ rollbackOf?: string; createdAt: string; } export declare function proposalFromReflectionWrite(write: ReflectionWrite, proposalId: string): DurableChangeProposal; /** * Contradiction count a reflection write carries against existing durable knowledge. A * `memory_replace`/`memory_remove` is only emitted when the reflection engine CONFRONTS an existing * fact (it supersedes or deletes it) — that supersession is the gate's contradiction signal, so such * a write must route through approval rather than silently overwriting prior memory. A `memory_add` * or `promote_skill` is purely additive and contradicts nothing. */ export declare function contradictionsForReflectionWrite(write: ReflectionWrite): number; export declare function rollbackPlanForReflectionWrite(write: ReflectionWrite): LearningRollbackPlan; export declare function isLearningAuditRecord(value: unknown): value is LearningAuditRecord; export declare function cloneLearningAuditRecordForStorage(record: LearningAuditRecord): LearningAuditRecord; export declare const LEARNING_AUDIT_CUSTOM_TYPE = "learning_audit"; export type LearningAuditSnapshotPayload = SessionSnapshotPayload<"record", LearningAuditRecord>; export declare function appendLearningAuditSnapshot(sessionManager: Pick, record: LearningAuditRecord): string; export declare function getLearningAuditSnapshots(entries: readonly SessionEntry[]): LearningAuditRecord[]; //# sourceMappingURL=learning-audit.d.ts.map