/** * Cross-database cleanup hooks for brain.db → tasks.db soft FK enforcement. * * SQLite does not support foreign key constraints across database connections. * This module provides application-layer guards that maintain referential * integrity between brain.db and tasks.db after destructive operations. * * Implements the recommendations from T030 audit (XFKB-001 through XFKB-005). * * @task T033 * @epic T029 */ /** * Clean up brain.db references after a task is deleted from tasks.db. * * Handles: * - XFKB-001/002: Nullify brain_decisions.context_epic_id / context_task_id * - XFKB-003: Delete brain_memory_links rows where task_id matches * - XFKB-005: Delete brain_page_nodes with id='task:' and cascade brain_page_edges * * This is a best-effort cleanup — brain.db is a cognitive store and minor * staleness is preferable to failing task deletions due to brain.db errors. * * @remarks * Best-effort: failures in brain.db cleanup do not propagate to the caller. * A background reconciliation pass can clean up any residual stale refs. * * @param taskId - The ID of the task being deleted from tasks.db * @param cwd - Optional working directory * * @example * ```ts * await cleanupBrainRefsOnTaskDelete('T042'); * ``` */ export declare function cleanupBrainRefsOnTaskDelete(taskId: string, cwd?: string): Promise; /** * Clean up brain.db references after a session is deleted from tasks.db. * * Handles: * - XFKB-004: Nullify brain_observations.source_session_id where it matches * * @remarks * Best-effort: failures do not propagate. brain.db may not be initialised. * * @param sessionId - The ID of the session being deleted from tasks.db * @param cwd - Optional working directory * * @example * ```ts * await cleanupBrainRefsOnSessionDelete('ses_20260321_abc'); * ``` */ export declare function cleanupBrainRefsOnSessionDelete(sessionId: string, cwd?: string): Promise; /** * Verify a task ID exists in tasks.db before writing a cross-DB reference to brain.db. * Returns true if the task exists, false otherwise. * * Provides write-guard for XFKB-001/002/003 on brain.db insert. * * @remarks * Used as a write-guard before inserting cross-DB references into brain.db. * * @param taskId - Task ID to verify * @param tasksDb - The tasks.db drizzle instance * @returns True if the task exists in tasks.db * * @example * ```ts * if (await taskExistsInTasksDb('T042', db)) { /* safe to reference *\/ } * ``` */ export declare function taskExistsInTasksDb(taskId: string, tasksDb: Awaited>): Promise; /** * Verify a session ID exists in tasks.db before writing a cross-DB reference to brain.db. * Returns true if the session exists, false otherwise. * * Provides write-guard for XFKB-004 on brain.db insert. * * @remarks * Used as a write-guard before inserting cross-DB references into brain.db. * * @param sessionId - Session ID to verify * @param tasksDb - The tasks.db drizzle instance * @returns True if the session exists in tasks.db * * @example * ```ts * if (await sessionExistsInTasksDb('ses_abc', db)) { /* safe to reference *\/ } * ``` */ /** * Reconcile orphaned cross-DB references in brain.db. * * Scans brain.db for references to tasks/sessions that no longer exist in * tasks.db and cleans them up: * - brain_decisions with stale context_task_id or context_epic_id → nullify * - brain_observations with stale source_session_id → nullify * - brain_memory_links with stale task_id → delete row * * This is the background reconciliation pass mentioned in the module doc. * Safe to run at any frequency — idempotent. * * @param cwd - Optional working directory * @returns Counts of orphaned references cleaned up */ export declare function reconcileOrphanedRefs(cwd?: string): Promise<{ decisionsFixed: number; observationsFixed: number; linksRemoved: number; }>; export declare function sessionExistsInTasksDb(sessionId: string, tasksDb: Awaited>): Promise; /** * Verify an agent exists in the global Agent Registry before creating cross-DB references. * Returns true if the agent_id exists in the global cleo.db agent_registry_agents table. * * Provides write-guard for agent_instances and agent_error_log in tasks.db * that reference agents whose identity lives in the global Agent Registry. * * @param agentId - Agent slug (e.g. 'cleo-db-lead') to verify * @param cwd - Optional working directory * @returns True if the agent exists in the global Agent Registry * * @task T238 */ export declare function agentExistsInAgentRegistryDb(agentId: string, cwd?: string): Promise; //# sourceMappingURL=cross-db-cleanup.d.ts.map