/** * SQLite store via drizzle-orm/node-sqlite + node:sqlite (DatabaseSync). * * ## E6-L1 — thin-facade migration (T11521) * * `getDb()` and `getNativeTasksDb()` are now thin facades that delegate the * database open to {@link openDualScopeDb}('project', cwd) — the canonical * dual-scope chokepoint introduced by E3/E4 (T11512/T11517). This ensures: * * - Every tasks.db open flows through the single pragma SSoT (ADR-068/069). * - The worktree-isolation guard (T9806) fires consistently on all opens. * - DB Open Guard Gate 3 (`scripts/lint-no-direct-db-open.mjs`) stays green. * * The legacy tables (`tasks`, `sessions`, `schema_meta`, …) are still created * by `runMigrations` (drizzle-tasks folder) inside the shared `cleo.db` file * during the E3→E6 transition period, co-existing with the new `tasks_tasks` * prefix tables from the consolidated schema. E6-L7/L8 will remove them. * * @epic T4454 * @task T4817 - node:sqlite engine migration (ADR-006, ADR-010) * @task T4810 - Data loss prevention guards * @task T11521 - E6-L1: route getDb through openDualScopeDb (SG-DB-SUBSTRATE-V2) */ import type { NodeSQLiteDatabase } from 'drizzle-orm/node-sqlite'; export { type DatabaseSync, openNativeDatabase } from './sqlite-native.js'; import type { DatabaseSync } from './sqlite-native.js'; import * as schema from './tasks-schema.js'; /** Schema version for newly created databases. Single source of truth. */ export declare const SQLITE_SCHEMA_VERSION = "2.0.0"; /** * Get the path to the SQLite database file that {@link getDb} opens. * * ## E6-L1 (T11521) * * After the dual-scope migration, `getDb()` opens the consolidated project * `cleo.db` via {@link openDualScopeDb}. This function therefore returns the * dual-scope `cleo.db` path so that callers checking for the file `getDb()` * created (existence / backup / health probes) point at the correct file. */ export declare function getDbPath(cwd?: string): string; /** * See the doc block above {@link countBackupTasks} for the full T5188/T11662 * rationale. Exported (rather than module-private) ONLY so the T11662 concurrency * regression test can drive ≥4 racing invocations against a single `cleo.db` and * assert exactly one restore occurs under the shared first-open lock. Production * code MUST reach this solely via {@link getDb}. * * @param nativeDb - The freshly-opened consolidated handle (its `tasks_tasks` is * probed for emptiness; closed before the file is overwritten on the restore path). * @param dbPath - Absolute path to the consolidated project `cleo.db`. * @param cwd - Working directory used to resolve the `.cleo/backups/sqlite/` dir. * @internal * @task T5188 * @task T11662 */ export declare function autoRecoverFromBackup(nativeDb: DatabaseSync, dbPath: string, cwd: string | undefined): Promise; /** * Open (or return cached) the drizzle tasks-schema handle for the project scope. * * ## E6-L1 façade (T11521) * * Delegates the physical DB open to {@link openDualScopeDb}('project', cwd) — * the canonical dual-scope chokepoint. The returned `NodeSQLiteDatabase` wraps * the same `DatabaseSync` handle as the consolidated `cleo.db` but is typed * against the legacy `tasks-schema` (table name `tasks`, etc.) so all existing * callers compile without change. * * The legacy drizzle-tasks migrations are still applied to this handle during * the E3→E6 transition, creating the `tasks` table family inside `cleo.db` * alongside the new `tasks_tasks` tables. E6-L7/L8 will remove them. * * Uses a promise guard so concurrent callers wait for the same * initialization to complete (migrations are async). */ export declare function getDb(cwd?: string): Promise>; /** * Resolve the absolute path to the drizzle-tasks migrations folder inside * @cleocode/core, using ESM-native module resolution (T1177). * * Delegates to {@link resolveCorePackageMigrationsFolder} which handles * bundled dist/, workspace dev, and global-install layouts uniformly via * `import.meta.resolve()` + `createRequire().resolve()` fallback. */ export declare function resolveMigrationsFolder(): string; /** * Check whether a table exists in the SQLite database. */ /** Re-export isSqliteBusy for external consumers. */ export { isSqliteBusy } from './migration-manager.js'; /** * Close the database connection and release resources. * * ## E6-L1 (T11521) * * Resets the dual-scope cache via {@link _resetDualScopeDbCache} so the next * `getDb()` call re-initialises cleanly rather than receiving a stale cached * handle whose `DatabaseSync` is already closed (which would produce * "database is not open" errors in migration-manager). * * Without the cache eviction, `openDualScopeDb` would return the stale entry * for the same (scope, cwd) key — its `DatabaseSync` already closed by * `_nativeDb.close()` below — causing downstream "database is not open" errors * in `runMigrations → tableExists` for the very next `getDb()` caller. */ export declare function closeDb(): void; /** * Reset database singleton state without saving. * Used during migrations when database file is deleted and recreated. * Safe to call multiple times. * * ## E6-L1 (T11521) * * Also resets the dual-scope cache via {@link _resetDualScopeDbCache} so the * next `getDb()` opens a fresh handle rather than reusing a stale one. * Mirrors the cache-eviction logic in {@link closeDb}. * * E6-L4 (T11524): scoped to `'project'` so it does not close the shared GLOBAL * `cleo.db` handle (nexus/signaldock/skills) — see {@link closeDb}. */ export declare function resetDbState(): void; /** * Get the schema version from the database. */ export declare function getSchemaVersion(cwd?: string): Promise; /** * Check if the database file exists. * * ## E6-L1 (T11521) * * After the dual-scope migration, `getDb()` opens `cleo.db` via * {@link openDualScopeDb} — not the legacy `tasks.db`. This function now * checks for `cleo.db` so that callers (e.g. `migration-sqlite.ts`) correctly * detect the E6 database and skip re-migration. * * {@link getDbPath} still returns the legacy `tasks.db` path for backward-compat * callers that specifically need that file (e.g. backup path construction). */ export declare function dbExists(cwd?: string): boolean; /** * Get the underlying node:sqlite DatabaseSync instance. * Useful for direct PRAGMA calls or raw SQL operations. * Returns null if the database hasn't been initialized. */ export declare function getNativeDb(): DatabaseSync | null; /** * Get the underlying node:sqlite DatabaseSync instance for tasks.db. * * ## E6-L1 façade (T11521) * * Thin facade delegating to {@link getNativeDb}. After the chokepoint * migration the native handle originates from {@link openDualScopeDb} — * callers receive the same `DatabaseSync` from `cleo.db`. */ export declare function getNativeTasksDb(): DatabaseSync | null; export type { NodeSQLiteDatabase }; /** * Re-export schema for external use. */ export { schema }; /** * Close ALL database singletons (tasks.db, brain.db, nexus.db). * * Must be called before deleting temp directories on Windows, where * SQLite holds exclusive file handles on .db, .db-wal, and .db-shm files. * Safe to call even if some databases were never opened. * * @task T5508 */ export declare function closeAllDatabases(): Promise; //# sourceMappingURL=sqlite.d.ts.map