import Database from 'better-sqlite3';
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;
}
export declare const CREATE_TABLES_SQL = "\n-- Core workspace metadata\nCREATE TABLE IF NOT EXISTS workspace (\n  id INTEGER PRIMARY KEY CHECK (id = 1),\n  type TEXT NOT NULL CHECK (type IN ('hq', 'workspace')),\n  workspace_name TEXT NOT NULL,\n  has_pmo BOOLEAN DEFAULT FALSE,\n  active_theme_id TEXT,\n  created_at TEXT NOT NULL,\n  FOREIGN KEY (active_theme_id) REFERENCES agent_themes(id) ON DELETE SET NULL\n);\n\n-- Repository management\nCREATE TABLE IF NOT EXISTS repositories (\n  name TEXT PRIMARY KEY,\n  path TEXT NOT NULL,\n  type TEXT DEFAULT 'main' CHECK (type IN ('main', 'dependency')),\n  source_url TEXT,\n  action TEXT CHECK (action IN ('clone', 'move', 'link')),\n  added_at TEXT NOT NULL\n);\n\n-- Agent naming themes (optional)\nCREATE TABLE IF NOT EXISTS agent_themes (\n  id TEXT PRIMARY KEY,\n  name TEXT NOT NULL UNIQUE,\n  display_name TEXT NOT NULL,\n  description TEXT,\n  builtin BOOLEAN DEFAULT FALSE,\n  created_at TEXT NOT NULL\n);\n\n-- Names available within each theme\nCREATE TABLE IF NOT EXISTS agent_theme_names (\n  theme_id TEXT NOT NULL,\n  name TEXT NOT NULL,\n  PRIMARY KEY (theme_id, name),\n  FOREIGN KEY (theme_id) REFERENCES agent_themes(id) ON DELETE CASCADE\n);\n\n-- Agent instances in workspace\nCREATE TABLE IF NOT EXISTS agents (\n  name TEXT PRIMARY KEY,\n  type TEXT NOT NULL DEFAULT 'persistent' CHECK (type IN ('persistent', 'ephemeral')),\n  status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'cleaned')),\n  base_name TEXT,\n  theme_id TEXT,\n  worktree_path TEXT,\n  mount_mode TEXT NOT NULL DEFAULT 'worktree' CHECK (mount_mode IN ('worktree', 'clone')),\n  created_at TEXT NOT NULL,\n  cleaned_at TEXT,\n  FOREIGN KEY (theme_id) REFERENCES agent_themes(id) ON DELETE SET NULL\n);\n\n-- Agent-owned worktrees\nCREATE TABLE IF NOT EXISTS agent_worktrees (\n  agent_name TEXT NOT NULL,\n  repo_name TEXT NOT NULL,\n  worktree_path TEXT NOT NULL,\n  branch TEXT NOT NULL,\n  created_at TEXT NOT NULL,\n  last_commit_hash TEXT,\n  commits_ahead INTEGER NOT NULL DEFAULT 0,\n  is_clean INTEGER NOT NULL DEFAULT 1,\n  last_checked TEXT,\n  PRIMARY KEY (agent_name, repo_name),\n  FOREIGN KEY (agent_name) REFERENCES agents(name) ON DELETE CASCADE,\n  FOREIGN KEY (repo_name) REFERENCES repositories(name) ON DELETE CASCADE\n);\n\n-- Workspace-level settings (key-value store)\nCREATE TABLE IF NOT EXISTS workspace_settings (\n  key TEXT PRIMARY KEY,\n  value TEXT NOT NULL\n);\n\n-- =============================================================================\n-- Indexes\n-- =============================================================================\n\nCREATE INDEX IF NOT EXISTS idx_worktrees_agent ON agent_worktrees(agent_name);\nCREATE INDEX IF NOT EXISTS idx_worktrees_repo ON agent_worktrees(repo_name);\nCREATE INDEX IF NOT EXISTS idx_theme_names_theme ON agent_theme_names(theme_id);\nCREATE INDEX IF NOT EXISTS idx_agents_theme ON agents(theme_id);\n";
/**
 * 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;
