/**
 * SQLite store for conduit.db — project-tier messaging and agent-ref database.
 *
 * Creates and manages .cleo/conduit.db using node:sqlite directly.
 * Applies the full conduit.db DDL (from spec §2.1) to bootstrap all
 * project-local messaging tables and the project_agent_refs override table.
 *
 * Architecture (ADR-037):
 *   conduit.db   — project-scoped (this module) — messaging, delivery, attachments,
 *                  project_agent_refs
 *   signaldock.db — global-scoped (T346) — agents, capabilities, cloud-sync tables
 *
 * CRUD accessors for project_agent_refs land in T353.
 * Cross-DB join accessor changes land in T355.
 * Migration executor from signaldock.db → conduit.db lands in T358.
 *
 * @task T344
 * @epic T310
 * @why ADR-037 splits single signaldock.db into project-tier conduit.db
 *      (this module) and global-tier signaldock.db (T346). This module owns
 *      the project-tier path helper, initializer, schema DDL, and health check.
 * @what Path helper, database initializer, schema applier, health check, and
 *       native DB accessor for project-local tables. No CRUD, no migrations.
 */
import type { DatabaseSync as _DatabaseSyncType } from 'node:sqlite';
import type { ProjectAgentRef } from '@cleocode/contracts';
type DatabaseSync = _DatabaseSyncType;
declare const DatabaseSync: new (path: import("fs").PathLike, options?: import("node:sqlite").DatabaseSyncOptions | undefined) => DatabaseSync;
/** Database file name within .cleo/ directory. */
export declare const CONDUIT_DB_FILENAME = "conduit.db";
/** Schema version for conduit.db — updated when DDL changes. */
export declare const CONDUIT_SCHEMA_VERSION = "2026.4.12";
/**
 * Returns the project-tier conduit.db path.
 *
 * Always resolves to `<projectRoot>/.cleo/conduit.db`. The caller is
 * responsible for supplying the absolute project root (e.g. via
 * `getProjectRoot()` from `../paths.js`).
 *
 * @task T344
 * @epic T310
 * @param projectRoot - Absolute path to the project root directory.
 * @returns Absolute path to `<projectRoot>/.cleo/conduit.db`.
 */
export declare function getConduitDbPath(projectRoot: string): string;
/**
 * Applies the conduit.db schema idempotently using CREATE TABLE IF NOT EXISTS.
 *
 * Exposed for the migration executor (T358) which needs to apply the schema
 * to a newly created conduit.db during the signaldock.db → conduit.db
 * migration. Also called internally by `ensureConduitDb` on every open.
 *
 * @task T344
 * @epic T310
 * @param db - An open node:sqlite DatabaseSync instance.
 */
export declare function applyConduitSchema(db: DatabaseSync): void;
/**
 * Opens or creates conduit.db for the given project root.
 *
 * On first call for a given projectRoot:
 *   1. Creates `<projectRoot>/.cleo/` directory if missing.
 *   2. Opens (or creates) the SQLite file.
 *   3. Sets WAL mode and enables foreign keys.
 *   4. Applies all DDL via `applyConduitSchema` (idempotent).
 *   5. Records `schema_version` in `_conduit_meta`.
 *   6. Records the initial migration in `_conduit_migrations`.
 *   7. Stores the open handle in the module singleton.
 *
 * On subsequent calls the existing singleton is returned immediately if the
 * resolved path matches; otherwise the previous handle is closed and a new
 * one is opened (test-isolation safety).
 *
 * Caller MUST call `closeConduitDb()` when done to release the handle.
 *
 * @task T344
 * @epic T310
 * @param projectRoot - Absolute path to the project root directory.
 * @returns Object with `action` (`'created'` | `'exists'`) and `path`.
 */
export declare function ensureConduitDb(projectRoot: string): {
    action: 'created' | 'exists';
    path: string;
};
/**
 * Returns the live node:sqlite DatabaseSync handle for conduit.db.
 *
 * Returns `null` if `ensureConduitDb` has not been called yet for this
 * process, or if `closeConduitDb` has been called since the last open.
 *
 * @task T344
 * @epic T310
 * @returns The open DatabaseSync instance, or `null` if not initialized.
 */
export declare function getConduitNativeDb(): DatabaseSync | null;
/**
 * Closes the conduit.db connection and resets the module singleton.
 *
 * Safe to call multiple times. No-op if the database is already closed.
 *
 * @task T344
 * @epic T310
 */
export declare function closeConduitDb(): void;
/**
 * Attaches an agent to the current project. If a row exists with enabled=0,
 * re-enables it (update attached_at timestamp). If a row exists with enabled=1,
 * no-op. Inserts a new row otherwise.
 *
 * @param db - conduit.db handle (from ensureConduitDb).
 * @param agentId - Global signaldock.db:agents.id (soft FK, not validated here).
 * @param opts - Optional role and capabilities override.
 * @task T353
 * @epic T310
 */
export declare function attachAgentToProject(db: DatabaseSync, agentId: string, opts?: {
    role?: string | null;
    capabilitiesOverride?: string | null;
}): void;
/**
 * Detaches an agent from the current project by setting enabled=0.
 * Does NOT delete the row (preserves attachment history for audit).
 *
 * @param db - conduit.db handle (from ensureConduitDb).
 * @param agentId - Agent ID to detach.
 * @task T353
 * @epic T310
 */
export declare function detachAgentFromProject(db: DatabaseSync, agentId: string): void;
/**
 * Lists project_agent_refs rows. By default returns only enabled=1 rows.
 * Pass enabledOnly=false to return all rows regardless of enabled state.
 *
 * @param db - conduit.db handle (from ensureConduitDb).
 * @param opts - Filter options. Defaults to `{ enabledOnly: true }`.
 * @returns Array of ProjectAgentRef rows ordered by attached_at DESC.
 * @task T353
 * @epic T310
 */
export declare function listProjectAgentRefs(db: DatabaseSync, opts?: {
    enabledOnly?: boolean;
}): ProjectAgentRef[];
/**
 * Returns a single project_agent_refs row by agentId, or null if not found.
 *
 * @param db - conduit.db handle (from ensureConduitDb).
 * @param agentId - Agent ID to look up.
 * @returns The ProjectAgentRef row, or null if the agent is not attached.
 * @task T353
 * @epic T310
 */
export declare function getProjectAgentRef(db: DatabaseSync, agentId: string): ProjectAgentRef | null;
/**
 * Updates the last_used_at timestamp for an agent to now.
 * No-op if the agent_id does not exist in project_agent_refs.
 *
 * @param db - conduit.db handle (from ensureConduitDb).
 * @param agentId - Agent ID to update.
 * @task T353
 * @epic T310
 */
export declare function updateProjectAgentLastUsed(db: DatabaseSync, agentId: string): void;
/**
 * Checks conduit.db health — table count, WAL mode, schema version, and
 * foreign keys status.
 *
 * Used by `cleo doctor` to verify conduit.db integrity. Does NOT require
 * `ensureConduitDb` to have been called; opens and closes the DB internally.
 *
 * @task T344
 * @epic T310
 * @param projectRoot - Absolute path to the project root directory.
 * @returns Health report object. `exists: false` when conduit.db is absent.
 */
export declare function checkConduitDbHealth(projectRoot: string): {
    exists: boolean;
    path: string;
    tableCount: number;
    walMode: boolean;
    schemaVersion: string | null;
    foreignKeysEnabled: boolean;
};
export {};
//# sourceMappingURL=conduit-sqlite.d.ts.map