/** * Read-only SQLite connection helpers for the Living Brain substrate adapters. * * Uses node:sqlite (Node.js built-in). * * Global databases (nexus.db, signaldock.db) are shared across all projects * and use module-level caches — their path is fixed per machine and never * changes between requests. * * Per-project databases (brain.db, tasks.db, conduit.db) are resolved from * the active {@link ProjectContext} passed by the caller. No cross-request * caching is performed: opening SQLite with `node:sqlite` is sub-millisecond, * and caching across different ProjectContexts is the precise bug this * module's Studio counterpart was rewritten to avoid. * * This file is a trimmed mirror of * `packages/studio/src/lib/server/db/connections.ts`, containing only the * getters required by the substrate adapters. * * ## E4-T5 transition (T11516 · SG-DB-SUBSTRATE-V2) * * This module now depends on `@cleocode/core` and delegates to * {@link openDualScopeDb} for new consolidated `cleo.db` access. The legacy * per-domain DB getters ({@link getNexusDb}, {@link getBrainDb}, etc.) still * open the old per-domain files via per-line-allowed raw opens because the * substrate adapters in this package still target those legacy table schemas. * The full exodus to the consolidated `cleo.db` schema happens in E6 (T11249), * at which point the per-line `// db-open-allowed` markers and the legacy * getters are removed. * * @task T969 * @task T11516 (E4-T5) */ import type { DatabaseSync as _DatabaseSyncType } from 'node:sqlite'; import type { ProjectContext } from './project-context.js'; /** * Re-export of the dual-scope `cleo.db` chokepoint. * * Callers that target the new consolidated schema (E4+) should use * `openDualScopeDb` directly rather than the legacy per-domain getters below. * * @see packages/core/src/store/dual-scope-db.ts */ export { openDualScopeDb } from '@cleocode/core/db'; type DatabaseSync = _DatabaseSyncType; declare const DatabaseSync: new (path: import("fs").PathLike, options?: import("node:sqlite").DatabaseSyncOptions | undefined) => DatabaseSync; /** * Minimal structural view of a `node:sqlite` prepared statement. * * `node:sqlite` returns rows as `Record[]` — a generic * shape that's not directly assignable to the row interfaces defined by each * substrate adapter. This type captures just the subset of `StatementSync` * used by the typed-row helper below. */ interface PreparedStatementLike { all(...params: unknown[]): unknown[]; } /** * Executes a prepared statement and returns rows typed as `T[]`. * * This helper consolidates the SQL-to-TypeScript boundary into a single, * auditable location. Each adapter specifies the expected row shape via the * type parameter; the unknown→T conversion happens exactly once per call * site rather than being scattered across every query site. * * Callers remain responsible for validating that the SQL projection matches * the declared type `T`. * * @param stmt - A prepared `node:sqlite` StatementSync. * @param params - Anonymous parameter bindings for the statement. * @returns Rows materialised as `T[]`. */ export declare function allTyped(stmt: PreparedStatementLike, ...params: unknown[]): T[]; /** * Returns a read-only connection to the global nexus.db. * Returns null when the file does not exist on disk. * * @remarks * Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045). * The raw open is per-line-allowed during the E4 → E6 transition; substrate * adapters still target legacy nexus.db table names. Full exodus in E6 (T11249). */ export declare function getNexusDb(): DatabaseSync | null; /** * Returns a read-only connection to the global signaldock.db. * Returns null when the file does not exist on disk. * * @remarks * Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045). * The raw open is per-line-allowed during the E4 → E6 transition; substrate * adapters still target legacy signaldock.db table names. Full exodus in E6 (T11249). */ export declare function getAgentRegistryDb(): DatabaseSync | null; /** * Opens a connection to brain.db for the given project context. * * Each call opens a fresh DatabaseSync against the path stored in `ctx`. * Returns null when brain.db does not exist for the project OR when the * file is detected as malformed (T10303). Reader-side malformation is * handled by returning null — recovery is owned by the writer side in * `@cleocode/core/store/memory-sqlite.ts:getBrainDb`, which runs the * `recoverMalformedBrainDb()` pipeline before the next process re-opens. * * @param ctx - The active project context. * * @remarks * Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045). * The raw open is per-line-allowed during the E4 → E6 transition; substrate * adapters still target legacy brain.db table names. Full exodus in E6 (T11249). */ export declare function getBrainDb(ctx: ProjectContext): DatabaseSync | null; /** * Opens a connection to tasks.db for the given project context. * * Each call opens a fresh DatabaseSync against the path stored in `ctx`. * Returns null when tasks.db does not exist for the project. * * @param ctx - The active project context. * * @remarks * Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045). * The raw open is per-line-allowed during the E4 → E6 transition; substrate * adapters still target legacy tasks.db table names. Full exodus in E6 (T11249). */ export declare function getTasksDb(ctx: ProjectContext): DatabaseSync | null; /** * Opens a connection to conduit.db for the given project context. * * conduit.db lives alongside brain.db in the project's `.cleo/` directory. * Its path is derived from the brain.db path since `ProjectContext` does not * carry a dedicated `conduitDbPath` field. * * Returns null when conduit.db does not exist for the project. * * @param ctx - The active project context. * * @remarks * Uses `applyPerfPragmas` from `@cleocode/core` (SSoT, T9045). * The raw open is per-line-allowed during the E4 → E6 transition; substrate * adapters still target legacy conduit.db table names. Full exodus in E6 (T11249). */ export declare function getConduitDb(ctx: ProjectContext): DatabaseSync | null; //# sourceMappingURL=db-connections.d.ts.map