import Database from 'better-sqlite3';
export { CREATE_TABLES_SQL } from './workspace-schema.js';
export interface WorkspaceConfig {
    id: number;
    type: 'hq' | 'workspace';
    workspace_name: string;
    has_pmo: boolean;
    active_theme_id: string | null;
    created_at: string;
}
export interface Repository {
    name: string;
    path: string;
    type: 'main' | 'dependency';
    source_url?: string;
    action?: 'clone' | 'move' | 'link';
    added_at: string;
}
export type AgentType = 'persistent' | 'ephemeral';
export type AgentStatus = 'active' | 'cleaned';
export type MountMode = 'worktree' | 'clone';
export interface Agent {
    name: string;
    type: AgentType;
    status: AgentStatus;
    base_name: string | null;
    theme_id: string | null;
    worktree_path: string | null;
    mount_mode: MountMode;
    created_at: string;
    cleaned_at: string | null;
}
export interface AgentTheme {
    id: string;
    name: string;
    display_name: string;
    description: string | null;
    builtin: boolean;
    created_at: string;
}
export interface AgentThemeName {
    theme_id: string;
    name: string;
}
export interface AgentWorktree {
    agent_name: string;
    repo_name: string;
    worktree_path: string;
    branch: string;
    created_at: string;
    last_commit_hash?: string;
    commits_ahead: number;
    is_clean: boolean;
    last_checked?: string;
}
/**
 * Get the database path for a workspace
 */
export declare function getDatabasePath(workspacePath: string): string;
/**
 * Get the config path for a workspace
 */
export declare function getConfigPath(workspacePath: string): string;
/**
 * Open workspace database connection
 */
export declare function openWorkspaceDatabase(workspacePath: string): Database.Database;
/**
 * Create and initialize workspace database
 */
export declare function createWorkspaceDatabase(workspacePath: string, type: 'hq' | 'workspace', workspaceName: string, hasPMO?: boolean): Database.Database;
/**
 * Get workspace configuration
 */
export declare function getWorkspaceConfig(workspacePath: string): WorkspaceConfig | null;
/**
 * Get the active theme for a workspace
 * Auto-detects theme from existing agents if not explicitly set
 */
export declare function getActiveTheme(workspacePath: string): AgentTheme | null;
/**
 * Set the active theme for a workspace
 */
export declare function setActiveTheme(workspacePath: string, themeId: string | null): void;
/**
 * Add repositories to database
 */
export declare function addRepositoriesToDatabase(workspacePath: string, repos: {
    name: string;
    path: string;
    source_url?: string;
    action?: 'clone' | 'move' | 'link';
}[]): void;
/**
 * Add agents to database (case-insensitive uniqueness)
 */
export declare function addAgentsToDatabase(workspacePath: string, agentNames: string[], themeId?: string, mountMode?: MountMode): void;
/**
 * Add an ephemeral agent to the database.
 * Throws on name collision — use tryAddEphemeralAgentToDatabase for
 * concurrency-safe insertion with conflict detection.
 */
export declare function addEphemeralAgentToDatabase(workspacePath: string, agentName: string, baseName: string, themeId?: string, mountMode?: MountMode): Agent;
/**
 * Try to add an ephemeral agent to the database.
 * Returns the Agent on success, or null if the name already exists
 * (SQLITE_CONSTRAINT_PRIMARYKEY). This is concurrency-safe: parallel
 * processes that generate the same name will not crash — the loser
 * simply gets null and can retry with a different name.
 */
export declare function tryAddEphemeralAgentToDatabase(workspacePath: string, agentName: string, baseName: string, themeId?: string, mountMode?: MountMode): Agent | null;
/**
 * Get all ephemeral agent names from the database
 */
export declare function getEphemeralAgentNames(workspacePath: string): Set<string>;
/**
 * Remove an ephemeral agent from the database
 */
export declare function removeEphemeralAgent(workspacePath: string, agentName: string): void;
/**
 * Get all agents in workspace
 */
export declare function getWorkspaceAgents(workspacePath: string, includeCleanedUp?: boolean): Agent[];
/**
 * Get an agent by directory path.
 * Looks up agent where the given absolute path is inside the agent's worktree.
 * Returns null if no matching agent found.
 */
export declare function getAgentByPath(workspacePath: string, absolutePath: string): Agent | null;
/**
 * Mark an agent as cleaned up (keeps the record for history)
 */
export declare function markAgentCleaned(workspacePath: string, agentName: string): void;
/**
 * Sync agents in database with what exists on disk.
 * Marks agents as 'cleaned' if their directory no longer exists.
 * Returns list of agents that were cleaned up.
 */
export declare function syncAgentsWithDisk(workspacePath: string): string[];
export interface DiscoverResult {
    discovered: {
        name: string;
        type: AgentType;
        path: string;
    }[];
    cleaned: string[];
}
/**
 * Discover agents on disk that aren't in the database and register them.
 * Also cleans up agents in DB whose directories no longer exist.
 * Returns both discovered and cleaned agents.
 */
export declare function discoverAgentsOnDisk(workspacePath: string): DiscoverResult;
/**
 * Get all repositories in workspace
 */
export declare function getWorkspaceRepositories(workspacePath: string): Repository[];
/**
 * Get worktrees for a specific agent
 */
export declare function getAgentWorktrees(workspacePath: string, agentName: string): AgentWorktree[];
/**
 * Find agent worktrees matching a branch pattern (case-insensitive LIKE).
 */
export declare function findWorktreesByBranch(workspacePath: string, branchPattern: string): AgentWorktree[];
/**
 * Get agent worktrees for a specific repository.
 */
export declare function getWorktreesForRepo(workspacePath: string, repoName: string): Array<{
    agent_name: string;
    is_clean: number;
    commits_ahead: number;
    branch: string;
}>;
/**
 * Upsert a workspace setting (key-value pair).
 */
export declare function upsertWorkspaceSetting(db: Database.Database, key: string, value: string): void;
/**
 * Remove agents from database
 */
export declare function removeAgentsFromDatabase(workspacePath: string, agentNames: string[]): void;
/**
 * Check if PMO tables exist and get basic stats.
 * Used by pmo init to detect existing PMO before storage layer is available.
 */
export declare function checkPMOExists(dbPath: string): {
    exists: boolean;
    projectCount: number;
    ticketCount: number;
};
/**
 * Get a PMO setting from the pmo_settings table.
 * Used for bootstrapping queries before storage layer is available.
 */
export declare function getPMOSetting(dbPath: string, key: string): string | null;
/**
 * Drop PMO tables from the database.
 * Used during PMO reinitialization.
 */
export declare function dropPMOTables(dbPath: string, tables: string[]): void;
/**
 * Get all themes
 */
export declare function getThemes(workspacePath: string): AgentTheme[];
/**
 * Get a theme by ID
 */
export declare function getTheme(workspacePath: string, themeId: string): AgentTheme | null;
/**
 * Create a new theme
 */
export declare function createTheme(workspacePath: string, theme: {
    id: string;
    name: string;
    displayName: string;
    description?: string;
    builtin?: boolean;
}): AgentTheme;
/**
 * Delete a theme (cannot delete builtin themes)
 */
export declare function deleteTheme(workspacePath: string, themeId: string): boolean;
/**
 * Get names for a theme
 */
export declare function getThemeNames(workspacePath: string, themeId: string): AgentThemeName[];
/**
 * Get available names for a theme.
 * A name is available if:
 * 1. No staff agent exists in the database with that name (case-insensitive), OR
 * 2. The agent exists but its worktree directory is missing (manually deleted)
 */
export declare function getAvailableThemeNames(workspacePath: string, themeId: string): string[];
/**
 * Add names to a theme (case-insensitive uniqueness)
 */
export declare function addThemeNames(workspacePath: string, themeId: string, names: string[]): void;
export interface MediaItem {
    name: string;
    path: string;
    source_path: string | null;
    media_type: 'video' | 'audio';
    duration_seconds: number | null;
    resolution: string | null;
    frame_count: number;
    has_transcript: boolean;
    frame_interval: number;
    status: 'pending' | 'processing' | 'ready' | 'error';
    error_message: string | null;
    added_at: string;
    processed_at: string | null;
}
/**
 * Add a media item to the database
 */
export declare function addMediaItemToDatabase(workspacePath: string, item: {
    name: string;
    path: string;
    source_path?: string;
    media_type: 'video' | 'audio';
    frame_interval?: number;
}): void;
/**
 * Update media item after preprocessing
 */
export declare function updateMediaItemStatus(workspacePath: string, name: string, updates: {
    status: 'pending' | 'processing' | 'ready' | 'error';
    duration_seconds?: number;
    resolution?: string;
    frame_count?: number;
    has_transcript?: boolean;
    error_message?: string;
}): void;
/**
 * Get all media items in workspace
 */
export declare function getWorkspaceMediaItems(workspacePath: string): MediaItem[];
/**
 * Get a single media item by name
 */
export declare function getMediaItem(workspacePath: string, name: string): MediaItem | null;
/**
 * Remove a media item from the database
 */
export declare function removeMediaItemFromDatabase(workspacePath: string, name: string): void;
