"use strict";exports.id=4925,exports.ids=[4925],exports.modules={83513:(e,t,s)=>{s.d(t,{Ho:()=>r,Ns:()=>i,Y1:()=>E,ZP:()=>n,_7:()=>o,py:()=>l,tK:()=>a});let a=["claude","codex","gemini","vibe-local","opencode"];function o(e){return a.includes(e)}let r=128,i=2097152;function n(e){return"number"==typeof e&&Number.isInteger(e)&&e>=r&&e<=i}let E=/^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$/;function l(e){return"function"==typeof e.supportsImage&&!0===e.supportsImage()}},94925:(e,t,s)=>{s.r(t),s.d(t,{closeDbInstance:()=>a.b,getDbInstance:()=>a.n});var a=s(67702)},67702:(e,t,s)=>{s.d(t,{b:()=>d,n:()=>_});var a=s(85890),o=s.n(a),r=s(55315),i=s.n(r),n=s(48215),E=s(98838);let l=null;function _(){if(!l){let e=(0,E.dU)().CM_DB_PATH,t=s(92048),a=i().dirname(e);t.existsSync(a)||t.mkdirSync(a,{recursive:!0,mode:448}),(l=new(o())(e)).pragma("foreign_keys = ON"),(0,n.xt)(l)}return l}function d(){l&&(l.close(),l=null)}},48215:(e,t,s)=>{s.d(t,{xt:()=>l});var a=s(55315),o=s.n(a),r=s(89168);let i=[{version:1,name:"initial-schema",up:e=>{(0,r.qZ)(e)},down:e=>{e.exec("DROP TABLE IF EXISTS session_states;"),e.exec("DROP TABLE IF EXISTS chat_messages;"),e.exec("DROP TABLE IF EXISTS worktrees;")}},{version:2,name:"add-multi-repo-and-memo-support",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN repository_path TEXT;
        ALTER TABLE worktrees ADD COLUMN repository_name TEXT;
        ALTER TABLE worktrees ADD COLUMN memo TEXT;
        ALTER TABLE worktrees ADD COLUMN last_user_message TEXT;
        ALTER TABLE worktrees ADD COLUMN last_user_message_at INTEGER;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_worktrees_repository
        ON worktrees(repository_path);
      `);let t=e.prepare("SELECT id, path FROM worktrees").all(),s=e.prepare(`
        UPDATE worktrees
        SET repository_path = ?,
            repository_name = ?
        WHERE id = ?
      `);for(let e of t){let t=n(e.path),a=o().basename(t);s.run(t,a,e.id)}let a=e.prepare(`
        UPDATE worktrees
        SET last_user_message = ?,
            last_user_message_at = ?
        WHERE id = ?
      `);for(let s of t){let t=e.prepare(`
          SELECT content, timestamp
          FROM chat_messages
          WHERE worktree_id = ? AND role = 'user'
          ORDER BY timestamp DESC
          LIMIT 1
        `).get(s.id);if(t){let e=t.content.substring(0,200);a.run(e,t.timestamp,s.id)}}},down:e=>{e.exec(`
        -- Create backup table
        CREATE TABLE worktrees_backup AS
        SELECT id, name, path, last_message_summary, updated_at
        FROM worktrees;

        -- Drop original table
        DROP TABLE worktrees;

        -- Recreate original table
        CREATE TABLE worktrees (
          id TEXT PRIMARY KEY,
          name TEXT NOT NULL,
          path TEXT NOT NULL UNIQUE,
          last_message_summary TEXT,
          updated_at INTEGER
        );

        -- Restore data
        INSERT INTO worktrees (id, name, path, last_message_summary, updated_at)
        SELECT id, name, path, last_message_summary, updated_at
        FROM worktrees_backup;

        -- Drop backup table
        DROP TABLE worktrees_backup;

        -- Drop index
        DROP INDEX IF EXISTS idx_worktrees_repository;
      `)}},{version:3,name:"fix-worktree-repository-paths",up:e=>{let t=e.prepare("SELECT id, path FROM worktrees").all(),s=e.prepare(`
        UPDATE worktrees
        SET repository_path = ?,
            repository_name = ?
        WHERE id = ?
      `);for(let e of t){let t=n(e.path),a=o().basename(t);s.run(t,a,e.id)}},down:()=>{console.log("No rollback needed for repository path fix")}},{version:4,name:"add-favorite-field",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN favorite INTEGER DEFAULT 0;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_worktrees_favorite
        ON worktrees(favorite DESC, updated_at DESC);
      `)},down:e=>{e.exec(`
        -- Drop the index first
        DROP INDEX IF EXISTS idx_worktrees_favorite;

        -- Note: In production, you'd need to recreate the table without the favorite column
        -- This is a simplified down migration
      `)}},{version:5,name:"add-status-field",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN status TEXT DEFAULT NULL;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_worktrees_status
        ON worktrees(status);
      `)},down:e=>{e.exec(`
        DROP INDEX IF EXISTS idx_worktrees_status;
      `)}},{version:6,name:"add-link-field",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN link TEXT DEFAULT NULL;
      `)},down:()=>{console.log("No rollback needed for link field")}},{version:7,name:"add-cli-tool-id",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN cli_tool_id TEXT DEFAULT 'claude';
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_worktrees_cli_tool
        ON worktrees(cli_tool_id);
      `),e.exec(`
        UPDATE worktrees SET cli_tool_id = 'claude' WHERE cli_tool_id IS NULL;
      `)},down:e=>{e.exec(`
        DROP INDEX IF EXISTS idx_worktrees_cli_tool;
      `),console.log("No full rollback for cli_tool_id column (SQLite limitation)")}},{version:8,name:"change-role-claude-to-assistant",up:e=>{e.exec(`
        CREATE TABLE chat_messages_new (
          id TEXT PRIMARY KEY,
          worktree_id TEXT NOT NULL,
          role TEXT NOT NULL CHECK (role IN ('user', 'assistant')),
          content TEXT NOT NULL,
          summary TEXT,
          timestamp INTEGER NOT NULL,
          log_file_name TEXT,
          request_id TEXT,
          message_type TEXT DEFAULT 'normal',
          prompt_data TEXT,
          cli_tool_id TEXT DEFAULT 'claude',
          FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
        );
      `),e.exec(`
        INSERT INTO chat_messages_new
        SELECT
          id,
          worktree_id,
          CASE WHEN role = 'claude' THEN 'assistant' ELSE role END as role,
          content,
          summary,
          timestamp,
          log_file_name,
          request_id,
          message_type,
          prompt_data,
          cli_tool_id
        FROM chat_messages;
      `),e.exec("DROP TABLE chat_messages;"),e.exec("ALTER TABLE chat_messages_new RENAME TO chat_messages;"),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_chat_messages_worktree
        ON chat_messages(worktree_id);
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_chat_messages_timestamp
        ON chat_messages(timestamp);
      `),console.log('✓ Changed role constraint from "claude" to "assistant"'),console.log('✓ Updated existing messages with role="claude" to role="assistant"')},down:e=>{e.exec(`
        CREATE TABLE chat_messages_new (
          id TEXT PRIMARY KEY,
          worktree_id TEXT NOT NULL,
          role TEXT NOT NULL CHECK (role IN ('user', 'claude')),
          content TEXT NOT NULL,
          summary TEXT,
          timestamp INTEGER NOT NULL,
          log_file_name TEXT,
          request_id TEXT,
          message_type TEXT DEFAULT 'normal',
          prompt_data TEXT,
          cli_tool_id TEXT DEFAULT 'claude',
          FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
        );
      `),e.exec(`
        INSERT INTO chat_messages_new
        SELECT
          id,
          worktree_id,
          CASE WHEN role = 'assistant' THEN 'claude' ELSE role END as role,
          content,
          summary,
          timestamp,
          log_file_name,
          request_id,
          message_type,
          prompt_data,
          cli_tool_id
        FROM chat_messages;
      `),e.exec("DROP TABLE chat_messages;"),e.exec("ALTER TABLE chat_messages_new RENAME TO chat_messages;"),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_chat_messages_worktree
        ON chat_messages(worktree_id);
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_chat_messages_timestamp
        ON chat_messages(timestamp);
      `),console.log('✓ Rolled back: Changed role constraint from "assistant" to "claude"')}},{version:9,name:"add-in-progress-message-id-to-session-states",up:e=>{e.exec(`
        ALTER TABLE session_states ADD COLUMN in_progress_message_id TEXT DEFAULT NULL;
      `),console.log("✓ Added in_progress_message_id column to session_states table")},down:()=>{console.log("No full rollback for in_progress_message_id column (SQLite limitation)")}},{version:10,name:"add-worktree-memos-table",up:e=>{e.exec(`
        CREATE TABLE worktree_memos (
          id TEXT PRIMARY KEY,
          worktree_id TEXT NOT NULL,
          title TEXT NOT NULL DEFAULT 'Memo',
          content TEXT NOT NULL DEFAULT '',
          position INTEGER NOT NULL DEFAULT 0,
          created_at INTEGER NOT NULL,
          updated_at INTEGER NOT NULL,

          FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE,
          UNIQUE(worktree_id, position)
        );
      `),e.exec(`
        CREATE INDEX idx_worktree_memos_worktree
          ON worktree_memos(worktree_id, position);
      `);let{randomUUID:t}=s(84770),a=e.prepare(`
        SELECT id, memo FROM worktrees WHERE memo IS NOT NULL AND memo != ''
      `).all(),o=e.prepare(`
        INSERT INTO worktree_memos (id, worktree_id, title, content, position, created_at, updated_at)
        VALUES (?, ?, 'Memo', ?, 0, ?, ?)
      `),r=Date.now();for(let e of a)o.run(t(),e.id,e.memo,r,r);console.log(`✓ Created worktree_memos table`),console.log(`✓ Migrated ${a.length} existing memos to new table`)},down:e=>{e.exec("DROP TABLE IF EXISTS worktree_memos"),console.log("✓ Dropped worktree_memos table")}},{version:11,name:"add-viewed-tracking",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN last_viewed_at TEXT;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_chat_messages_assistant_latest
        ON chat_messages(worktree_id, role, timestamp DESC);
      `),console.log("✓ Added last_viewed_at column to worktrees table"),console.log("✓ Created index for assistant message queries")},down:e=>{e.exec("DROP INDEX IF EXISTS idx_chat_messages_assistant_latest"),console.log("✓ Dropped idx_chat_messages_assistant_latest index")}},{version:12,name:"add-external-apps-table",up:e=>{e.exec(`
        CREATE TABLE IF NOT EXISTS external_apps (
          id TEXT PRIMARY KEY,

          -- Basic info
          name TEXT NOT NULL UNIQUE,
          display_name TEXT NOT NULL,
          description TEXT,

          -- Routing config
          path_prefix TEXT NOT NULL UNIQUE,
          target_port INTEGER NOT NULL,
          target_host TEXT DEFAULT 'localhost',

          -- App type
          app_type TEXT NOT NULL CHECK(app_type IN ('sveltekit', 'streamlit', 'nextjs', 'other')),

          -- WebSocket config
          websocket_enabled INTEGER DEFAULT 0,
          websocket_path_pattern TEXT,

          -- Status
          enabled INTEGER DEFAULT 1,

          -- Metadata
          created_at INTEGER NOT NULL,
          updated_at INTEGER NOT NULL
        );
      `),e.exec(`
        CREATE INDEX idx_external_apps_path_prefix ON external_apps(path_prefix);
      `),e.exec(`
        CREATE INDEX idx_external_apps_enabled ON external_apps(enabled);
      `),console.log("✓ Created external_apps table"),console.log("✓ Created indexes for external_apps")},down:e=>{e.exec("DROP INDEX IF EXISTS idx_external_apps_enabled"),e.exec("DROP INDEX IF EXISTS idx_external_apps_path_prefix"),e.exec("DROP TABLE IF EXISTS external_apps"),console.log("✓ Dropped external_apps table and indexes")}},{version:13,name:"rename-worktree-memo-to-description",up:e=>{e.exec(`
        ALTER TABLE worktrees RENAME COLUMN memo TO description;
      `),console.log("✓ Renamed worktrees.memo column to description")},down:e=>{e.exec(`
        ALTER TABLE worktrees RENAME COLUMN description TO memo;
      `),console.log("✓ Rolled back: Renamed worktrees.description column back to memo")}},{version:14,name:"add-repositories-and-clone-jobs-tables",up:e=>{e.exec(`
        CREATE TABLE IF NOT EXISTS repositories (
          id TEXT PRIMARY KEY,
          name TEXT NOT NULL,
          path TEXT NOT NULL UNIQUE,
          enabled INTEGER NOT NULL DEFAULT 1,
          clone_url TEXT,
          normalized_clone_url TEXT,
          clone_source TEXT CHECK(clone_source IN ('local', 'https', 'ssh')) DEFAULT 'local',
          is_env_managed INTEGER NOT NULL DEFAULT 0,
          created_at INTEGER NOT NULL,
          updated_at INTEGER NOT NULL
        );
      `),e.exec(`
        CREATE UNIQUE INDEX IF NOT EXISTS idx_repositories_normalized_clone_url
        ON repositories(normalized_clone_url)
        WHERE normalized_clone_url IS NOT NULL;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_repositories_path
        ON repositories(path);
      `),e.exec(`
        CREATE TABLE IF NOT EXISTS clone_jobs (
          id TEXT PRIMARY KEY,
          clone_url TEXT NOT NULL,
          normalized_clone_url TEXT NOT NULL,
          target_path TEXT NOT NULL,
          repository_id TEXT,
          status TEXT NOT NULL CHECK(status IN ('pending', 'running', 'completed', 'failed', 'cancelled')) DEFAULT 'pending',
          pid INTEGER,
          progress INTEGER NOT NULL DEFAULT 0,
          error_category TEXT,
          error_code TEXT,
          error_message TEXT,
          started_at INTEGER,
          completed_at INTEGER,
          created_at INTEGER NOT NULL,

          FOREIGN KEY (repository_id) REFERENCES repositories(id) ON DELETE SET NULL
        );
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_clone_jobs_status
        ON clone_jobs(status);
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_clone_jobs_normalized_clone_url
        ON clone_jobs(normalized_clone_url);
      `),console.log("✓ Created repositories table"),console.log("✓ Created clone_jobs table"),console.log("✓ Created indexes for repositories and clone_jobs")},down:e=>{e.exec("DROP INDEX IF EXISTS idx_clone_jobs_normalized_clone_url"),e.exec("DROP INDEX IF EXISTS idx_clone_jobs_status"),e.exec("DROP TABLE IF EXISTS clone_jobs"),e.exec("DROP INDEX IF EXISTS idx_repositories_path"),e.exec("DROP INDEX IF EXISTS idx_repositories_normalized_clone_url"),e.exec("DROP TABLE IF EXISTS repositories"),console.log("✓ Dropped repositories and clone_jobs tables")}},{version:15,name:"add-initial-branch-column",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN initial_branch TEXT;
      `),console.log("✓ Added initial_branch column to worktrees table")},down:e=>{e.exec(`
        -- 1. Create backup table without initial_branch
        CREATE TABLE worktrees_backup AS
        SELECT id, name, path, repository_path, repository_name, description,
               last_user_message, last_user_message_at, last_message_summary,
               favorite, status, link, cli_tool_id, updated_at, last_viewed_at
        FROM worktrees;

        -- 2. Drop original table
        DROP TABLE worktrees;

        -- 3. Recreate table without initial_branch
        CREATE TABLE worktrees (
          id TEXT PRIMARY KEY,
          name TEXT NOT NULL,
          path TEXT NOT NULL UNIQUE,
          repository_path TEXT,
          repository_name TEXT,
          description TEXT,
          last_user_message TEXT,
          last_user_message_at INTEGER,
          last_message_summary TEXT,
          favorite INTEGER DEFAULT 0,
          status TEXT DEFAULT NULL,
          link TEXT DEFAULT NULL,
          cli_tool_id TEXT DEFAULT 'claude',
          updated_at INTEGER,
          last_viewed_at TEXT
        );

        -- 4. Restore data
        INSERT INTO worktrees (id, name, path, repository_path, repository_name,
               description, last_user_message, last_user_message_at, last_message_summary,
               favorite, status, link, cli_tool_id, updated_at, last_viewed_at)
        SELECT id, name, path, repository_path, repository_name,
               description, last_user_message, last_user_message_at, last_message_summary,
               favorite, status, link, cli_tool_id, updated_at, last_viewed_at
        FROM worktrees_backup;

        -- 5. Drop backup
        DROP TABLE worktrees_backup;

        -- 6. Recreate indexes
        CREATE INDEX IF NOT EXISTS idx_worktrees_updated_at
        ON worktrees(updated_at DESC);

        CREATE INDEX IF NOT EXISTS idx_worktrees_repository
        ON worktrees(repository_path);

        CREATE INDEX IF NOT EXISTS idx_worktrees_favorite
        ON worktrees(favorite DESC, updated_at DESC);

        CREATE INDEX IF NOT EXISTS idx_worktrees_status
        ON worktrees(status);

        CREATE INDEX IF NOT EXISTS idx_worktrees_cli_tool
        ON worktrees(cli_tool_id);
      `),console.log("✓ Removed initial_branch column from worktrees table")}},{version:16,name:"add-issue-no-to-external-apps",up:e=>{e.exec(`
        ALTER TABLE external_apps ADD COLUMN issue_no INTEGER;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_external_apps_issue_no ON external_apps(issue_no);
      `),console.log("✓ Added issue_no column to external_apps table"),console.log("✓ Created index idx_external_apps_issue_no")},down:e=>{e.exec(`
        -- 1. Create backup table without issue_no
        CREATE TABLE external_apps_backup AS
        SELECT id, name, display_name, description, path_prefix, target_port,
               target_host, app_type, websocket_enabled, websocket_path_pattern,
               enabled, created_at, updated_at
        FROM external_apps;

        -- 2. Drop original table (this also drops indexes)
        DROP TABLE external_apps;

        -- 3. Recreate table without issue_no
        CREATE TABLE external_apps (
          id TEXT PRIMARY KEY,
          name TEXT NOT NULL UNIQUE,
          display_name TEXT NOT NULL,
          description TEXT,
          path_prefix TEXT NOT NULL UNIQUE,
          target_port INTEGER NOT NULL,
          target_host TEXT DEFAULT 'localhost',
          app_type TEXT NOT NULL CHECK(app_type IN ('sveltekit', 'streamlit', 'nextjs', 'other')),
          websocket_enabled INTEGER DEFAULT 0,
          websocket_path_pattern TEXT,
          enabled INTEGER DEFAULT 1,
          created_at INTEGER NOT NULL,
          updated_at INTEGER NOT NULL
        );

        -- 4. Restore data
        INSERT INTO external_apps (id, name, display_name, description, path_prefix,
               target_port, target_host, app_type, websocket_enabled, websocket_path_pattern,
               enabled, created_at, updated_at)
        SELECT id, name, display_name, description, path_prefix,
               target_port, target_host, app_type, websocket_enabled, websocket_path_pattern,
               enabled, created_at, updated_at
        FROM external_apps_backup;

        -- 5. Drop backup
        DROP TABLE external_apps_backup;

        -- 6. Recreate original indexes
        CREATE INDEX idx_external_apps_path_prefix ON external_apps(path_prefix);
        CREATE INDEX idx_external_apps_enabled ON external_apps(enabled);
      `),console.log("✓ Removed issue_no column from external_apps table")}},{version:17,name:"add-scheduled-executions-and-execution-logs",up:e=>{e.exec(`
        DELETE FROM chat_messages WHERE worktree_id NOT IN (SELECT id FROM worktrees);
      `),e.exec(`
        DELETE FROM session_states WHERE worktree_id NOT IN (SELECT id FROM worktrees);
      `),e.exec(`
        DELETE FROM worktree_memos WHERE worktree_id NOT IN (SELECT id FROM worktrees);
      `),e.exec(`
        UPDATE clone_jobs SET repository_id = NULL
          WHERE repository_id IS NOT NULL AND repository_id NOT IN (SELECT id FROM repositories);
      `),e.exec(`
        CREATE TABLE scheduled_executions (
          id TEXT PRIMARY KEY,
          worktree_id TEXT NOT NULL,
          cli_tool_id TEXT DEFAULT 'claude',
          name TEXT NOT NULL,
          message TEXT NOT NULL,
          cron_expression TEXT,
          enabled INTEGER DEFAULT 1,
          last_executed_at INTEGER,
          next_execute_at INTEGER,
          created_at INTEGER NOT NULL,
          updated_at INTEGER NOT NULL,
          UNIQUE(worktree_id, name),
          FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
        );
      `),e.exec(`
        CREATE INDEX idx_scheduled_executions_worktree
          ON scheduled_executions(worktree_id);
      `),e.exec(`
        CREATE INDEX idx_scheduled_executions_enabled
          ON scheduled_executions(enabled);
      `),e.exec(`
        CREATE TABLE execution_logs (
          id TEXT PRIMARY KEY,
          schedule_id TEXT NOT NULL,
          worktree_id TEXT NOT NULL,
          message TEXT NOT NULL,
          result TEXT,
          exit_code INTEGER,
          status TEXT DEFAULT 'running' CHECK(status IN ('running', 'completed', 'failed', 'timeout', 'cancelled')),
          started_at INTEGER NOT NULL,
          completed_at INTEGER,
          created_at INTEGER NOT NULL,
          FOREIGN KEY (schedule_id) REFERENCES scheduled_executions(id) ON DELETE CASCADE,
          FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
        );
      `),e.exec(`
        CREATE INDEX idx_execution_logs_schedule
          ON execution_logs(schedule_id);
      `),e.exec(`
        CREATE INDEX idx_execution_logs_worktree
          ON execution_logs(worktree_id);
      `),e.exec(`
        CREATE INDEX idx_execution_logs_status
          ON execution_logs(status);
      `),console.log("✓ Cleaned up orphan records"),console.log("✓ Created scheduled_executions table"),console.log("✓ Created execution_logs table"),console.log("✓ Created indexes for schedule tables")},down:e=>{e.exec("DROP INDEX IF EXISTS idx_execution_logs_status"),e.exec("DROP INDEX IF EXISTS idx_execution_logs_worktree"),e.exec("DROP INDEX IF EXISTS idx_execution_logs_schedule"),e.exec("DROP TABLE IF EXISTS execution_logs"),e.exec("DROP INDEX IF EXISTS idx_scheduled_executions_enabled"),e.exec("DROP INDEX IF EXISTS idx_scheduled_executions_worktree"),e.exec("DROP TABLE IF EXISTS scheduled_executions"),console.log("✓ Dropped scheduled_executions and execution_logs tables")}},{version:18,name:"add-selected-agents-column",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN selected_agents TEXT;
      `),e.exec(`
        UPDATE worktrees SET selected_agents =
          CASE
            WHEN cli_tool_id NOT IN ('claude', 'codex')
            THEN json_array(cli_tool_id, 'claude')
            ELSE '["claude","codex"]'
          END;
      `),console.log("✓ Added selected_agents column to worktrees table"),console.log("✓ Initialized selected_agents based on cli_tool_id")},down:()=>{console.log("No rollback for selected_agents column (SQLite limitation)")}},{version:19,name:"add-vibe-local-model-column",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN vibe_local_model TEXT DEFAULT NULL;
      `),console.log("✓ Added vibe_local_model column to worktrees table")},down:()=>{console.log("No rollback for vibe_local_model column (SQLite limitation)")}},{version:20,name:"add-vibe-local-context-window-column",up:e=>{e.exec(`
        ALTER TABLE worktrees ADD COLUMN vibe_local_context_window INTEGER DEFAULT NULL;
      `),console.log("✓ Added vibe_local_context_window column to worktrees table")},down:()=>{console.log("No rollback for vibe_local_context_window column (SQLite limitation)")}},{version:21,name:"add-scheduled-executions-worktree-enabled-index",up:e=>{e.exec(`
        CREATE INDEX IF NOT EXISTS idx_scheduled_executions_worktree_enabled
          ON scheduled_executions(worktree_id, enabled);
      `),console.log("✓ Created composite index idx_scheduled_executions_worktree_enabled")},down:e=>{e.exec("DROP INDEX IF EXISTS idx_scheduled_executions_worktree_enabled"),console.log("✓ Dropped idx_scheduled_executions_worktree_enabled index")}},{version:22,name:"add-archived-column-to-chat-messages",up:e=>{e.exec(`
        ALTER TABLE chat_messages ADD COLUMN archived INTEGER DEFAULT 0;
      `),e.exec(`
        UPDATE chat_messages SET archived = 0 WHERE archived IS NULL;
      `),e.exec(`
        CREATE INDEX IF NOT EXISTS idx_messages_archived
          ON chat_messages(worktree_id, archived, timestamp DESC);
      `),console.log("✓ Added archived column to chat_messages table"),console.log("✓ Created composite index idx_messages_archived")},down:()=>{console.log("No rollback for archived column (SQLite limitation)")}}];function n(e){let t=s(92048),a=e;for(;a!==o().dirname(a);){let e=o().join(a,".git");if(t.existsSync(e)){let s=t.statSync(e);if(s.isDirectory())return a;if(s.isFile()){let s=t.readFileSync(e,"utf-8").trim().match(/^gitdir:\s*(.+)$/);if(s)return s[1].split("/.git/")[0]}}a=o().dirname(a)}return e}function E(e){try{let t=e.prepare("SELECT MAX(version) as version FROM schema_version").get();return t?.version??0}catch{return 0}}function l(e){!function(e){e.exec(`
    CREATE TABLE IF NOT EXISTS schema_version (
      version INTEGER PRIMARY KEY,
      name TEXT NOT NULL,
      applied_at INTEGER NOT NULL
    );
  `)}(e);let t=E(e);console.log(`Current schema version: ${t}`);let s=i.filter(e=>e.version>t);if(0===s.length){console.log("✓ Schema is up to date");return}for(let t of(console.log(`Found ${s.length} pending migration(s)`),s)){console.log(`Applying migration ${t.version}: ${t.name}...`);try{e.transaction(()=>{t.up(e),e.prepare(`
          INSERT INTO schema_version (version, name, applied_at)
          VALUES (?, ?, ?)
        `).run(t.version,t.name,Date.now())})(),console.log(`✓ Migration ${t.version} applied successfully`)}catch(s){let e=s instanceof Error?s.message:String(s);throw console.error(`✗ Migration ${t.version} failed:`,e),Error(`Migration ${t.version} (${t.name}) failed: ${e}`)}}console.log(`✓ All migrations completed. Current version: ${E(e)}`)}},89168:(e,t,s)=>{function a(e){e.exec(`
    CREATE TABLE IF NOT EXISTS worktrees (
      id TEXT PRIMARY KEY,
      name TEXT NOT NULL,
      path TEXT NOT NULL UNIQUE,
      last_message_summary TEXT,
      updated_at INTEGER
    );
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_worktrees_updated_at
    ON worktrees(updated_at DESC);
  `),e.exec(`
    CREATE TABLE IF NOT EXISTS chat_messages (
      id TEXT PRIMARY KEY,
      worktree_id TEXT NOT NULL,
      role TEXT NOT NULL CHECK(role IN ('user', 'assistant')),
      content TEXT NOT NULL,
      summary TEXT,
      timestamp INTEGER NOT NULL,
      log_file_name TEXT,
      request_id TEXT,
      message_type TEXT DEFAULT 'normal',
      prompt_data TEXT,
      cli_tool_id TEXT DEFAULT 'claude',
      archived INTEGER DEFAULT 0,

      FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
    );
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_messages_worktree_time
    ON chat_messages(worktree_id, timestamp DESC);
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_messages_request_id
    ON chat_messages(request_id);
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_messages_type
    ON chat_messages(message_type, worktree_id);
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_messages_cli_tool
    ON chat_messages(worktree_id, cli_tool_id, timestamp DESC);
  `),e.exec(`
    CREATE INDEX IF NOT EXISTS idx_messages_archived
    ON chat_messages(worktree_id, archived, timestamp DESC);
  `),e.exec(`
    CREATE TABLE IF NOT EXISTS session_states (
      worktree_id TEXT NOT NULL,
      cli_tool_id TEXT NOT NULL DEFAULT 'claude',
      last_captured_line INTEGER DEFAULT 0,

      PRIMARY KEY (worktree_id, cli_tool_id),
      FOREIGN KEY (worktree_id) REFERENCES worktrees(id) ON DELETE CASCADE
    );
  `)}s.d(t,{Mf:()=>H,Aq:()=>m,dD:()=>K,tn:()=>l,HE:()=>T,_e:()=>j,ls:()=>c,GZ:()=>p,DF:()=>b,j8:()=>B,pM:()=>y,Q7:()=>F,vX:()=>d,ZI:()=>Y,Db:()=>G,S$:()=>N,_U:()=>_,ER:()=>g,zl:()=>M,gU:()=>I,Pv:()=>v,Xv:()=>R,qZ:()=>a,GP:()=>w,Ek:()=>f,VW:()=>h,R3:()=>x,OK:()=>u,Of:()=>S,Nr:()=>$,GA:()=>L,ey:()=>X,IH:()=>P,Nf:()=>k,Yg:()=>U,dl:()=>C,xr:()=>O,y:()=>D,ly:()=>A});var o=s(55483),r=s(84770);let i=(0,s(43895).h)("chat-db"),n="AND archived = 0";function E(e){return{id:e.id,worktreeId:e.worktree_id,role:e.role,content:e.content,summary:e.summary||void 0,timestamp:new Date(e.timestamp),logFileName:e.log_file_name||void 0,requestId:e.request_id||void 0,messageType:e.message_type||"normal",promptData:e.prompt_data?JSON.parse(e.prompt_data):void 0,cliToolId:e.cli_tool_id??"claude",archived:1===e.archived}}function l(e,t){let s=(0,r.randomUUID)();return e.prepare(`
    INSERT INTO chat_messages
    (id, worktree_id, role, content, summary, timestamp, log_file_name, request_id, message_type, prompt_data, cli_tool_id)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  `).run(s,t.worktreeId,t.role,t.content,t.summary||null,t.timestamp.getTime(),t.logFileName||null,t.requestId||null,t.messageType||"normal",t.promptData?JSON.stringify(t.promptData):null,t.cliToolId||"claude"),function(e,t,s){e.prepare(`
    UPDATE worktrees
    SET updated_at = ?
    WHERE id = ?
  `).run(s.getTime(),t)}(e,t.worktreeId,t.timestamp),"user"===t.role&&u(e,t.worktreeId,t.content,t.timestamp),{id:s,...t,archived:!1}}function _(e,t,s={}){let{before:a,limit:o=50,cliToolId:r,includeArchived:i=!1}=s,l=`
    SELECT id, worktree_id, role, content, summary, timestamp, log_file_name, request_id, message_type, prompt_data, cli_tool_id, archived
    FROM chat_messages
    WHERE worktree_id = ? AND (? IS NULL OR timestamp < ?)
  `,_=[t,a?.getTime()||null,a?.getTime()||null];return i||(l+=` ${n}`),r&&(l+=" AND cli_tool_id = ?",_.push(r)),l+=" ORDER BY timestamp DESC LIMIT ?",_.push(o),e.prepare(l).all(..._).map(E)}function d(e,t){let s=e.prepare(`
    SELECT id, worktree_id, role, content, summary, timestamp, log_file_name, request_id, message_type, prompt_data, cli_tool_id, archived
    FROM chat_messages
    WHERE worktree_id = ? AND role = 'user' ${n}
    ORDER BY timestamp DESC
    LIMIT 1
  `).get(t);return s?E(s):null}function T(e,t){let s=e.prepare(`
    UPDATE chat_messages
    SET archived = 1
    WHERE worktree_id = ? ${n}
  `).run(t);return i.info("archived-all-messages",{worktreeId:t,count:s.changes}),s.changes}function c(e,t){return e.prepare(`
    DELETE FROM chat_messages
    WHERE id = ?
  `).run(t).changes>0}function p(e,t,s){let a=e.prepare(`
    UPDATE chat_messages
    SET archived = 1
    WHERE worktree_id = ? AND cli_tool_id = ? ${n}
  `).run(t,s);return i.info("archived-messages-by-cli-tool",{worktreeId:t,cliTool:s,count:a.changes}),a.changes}function u(e,t,s,a){let o=e.prepare(`
    UPDATE worktrees
    SET last_user_message = ?,
        last_user_message_at = ?
    WHERE id = ?
  `),r=s.substring(0,200);o.run(r,a.getTime(),t)}function m(e,t){e.prepare(`
    UPDATE worktrees
    SET last_user_message = NULL,
        last_user_message_at = NULL
    WHERE id = ?
  `).run(t)}function N(e,t){let s=e.prepare(`
    SELECT id, worktree_id, role, content, summary, timestamp, log_file_name, request_id, message_type, prompt_data, cli_tool_id, archived
    FROM chat_messages
    WHERE id = ?
  `).get(t);return s?E(s):null}function L(e,t,s){e.prepare(`
    UPDATE chat_messages
    SET prompt_data = ?
    WHERE id = ?
  `).run(JSON.stringify(s),t)}function w(e,t,s){let a=e.prepare(`
    SELECT id, prompt_data
    FROM chat_messages
    WHERE worktree_id = ?
      AND cli_tool_id = ?
      AND message_type = 'prompt'
      AND json_extract(prompt_data, '$.status') = 'pending'
      ${n}
    ORDER BY timestamp DESC
  `).all(t,s);if(0===a.length)return 0;let o=e.prepare(`
    UPDATE chat_messages
    SET prompt_data = ?
    WHERE id = ?
  `),r=0;for(let e of a)try{let t=JSON.parse(e.prompt_data);t.status="answered",t.answer="(answered via terminal)",t.answeredAt=new Date().toISOString(),o.run(JSON.stringify(t),e.id),r++}catch{}return r}function R(e,t){let s=`
    SELECT
      w.id, w.name, w.path, w.repository_path, w.repository_name, w.description,
      w.last_user_message, w.last_user_message_at, w.last_message_summary,
      w.updated_at, w.favorite, w.status, w.link, w.cli_tool_id, w.last_viewed_at,
      w.selected_agents, w.vibe_local_model, w.vibe_local_context_window,
      (SELECT MAX(timestamp) FROM chat_messages
       WHERE worktree_id = w.id AND role = 'assistant' ${n}) as last_assistant_message_at
    FROM worktrees w
  `,a=[];t&&(s+=" WHERE w.repository_path = ?",a.push(t)),s+=" ORDER BY w.updated_at DESC NULLS LAST";let r=e.prepare(s).all(...a),i=function(e,t){if(0===t.length)return new Map;let s=t.map(()=>"?").join(","),a=e.prepare(`
    WITH ranked_messages AS (
      SELECT
        worktree_id,
        cli_tool_id,
        content,
        ROW_NUMBER() OVER (
          PARTITION BY worktree_id, cli_tool_id
          ORDER BY timestamp DESC
        ) as rn
      FROM chat_messages
      WHERE worktree_id IN (${s})
        AND role = 'user'
        ${n}
    )
    SELECT worktree_id, cli_tool_id, content
    FROM ranked_messages
    WHERE rn = 1
  `).all(...t),o=new Map;for(let e of t)o.set(e,{});for(let e of a){let t=o.get(e.worktree_id)||{};t[e.cli_tool_id]=e.content.substring(0,50),o.set(e.worktree_id,t)}return o}(e,r.map(e=>e.id));return r.map(e=>{let t=i.get(e.id)||{};return{id:e.id,name:e.name,path:e.path,repositoryPath:e.repository_path||"",repositoryName:e.repository_name||"",description:e.description||void 0,lastUserMessage:e.last_user_message||void 0,lastUserMessageAt:e.last_user_message_at?new Date(e.last_user_message_at):void 0,lastMessageSummary:e.last_message_summary||void 0,lastMessagesByCli:t,updatedAt:e.updated_at?new Date(e.updated_at):void 0,lastViewedAt:e.last_viewed_at?new Date(e.last_viewed_at):void 0,lastAssistantMessageAt:e.last_assistant_message_at?new Date(e.last_assistant_message_at):void 0,favorite:1===e.favorite,status:e.status||null,link:e.link||void 0,cliToolId:e.cli_tool_id??"claude",selectedAgents:(0,o.e7)(e.selected_agents),vibeLocalModel:e.vibe_local_model??null,vibeLocalContextWindow:e.vibe_local_context_window??null}})}function g(e){return e.prepare(`
    SELECT
      repository_path as path,
      repository_name as name,
      COUNT(*) as worktree_count
    FROM worktrees
    WHERE repository_path IS NOT NULL
    GROUP BY repository_path, repository_name
    ORDER BY repository_name ASC
  `).all().map(e=>({path:e.path,name:e.name,worktreeCount:e.worktree_count}))}function I(e,t){let s=e.prepare(`
    SELECT
      w.id, w.name, w.path, w.repository_path, w.repository_name, w.description,
      w.last_user_message, w.last_user_message_at, w.last_message_summary,
      w.updated_at, w.favorite, w.status, w.link, w.cli_tool_id, w.last_viewed_at,
      w.selected_agents, w.vibe_local_model, w.vibe_local_context_window,
      (SELECT MAX(timestamp) FROM chat_messages
       WHERE worktree_id = w.id AND role = 'assistant' ${n}) as last_assistant_message_at
    FROM worktrees w
    WHERE w.id = ?
  `).get(t);return s?{id:s.id,name:s.name,path:s.path,repositoryPath:s.repository_path||"",repositoryName:s.repository_name||"",description:s.description||void 0,lastUserMessage:s.last_user_message||void 0,lastUserMessageAt:s.last_user_message_at?new Date(s.last_user_message_at):void 0,lastMessageSummary:s.last_message_summary||void 0,updatedAt:s.updated_at?new Date(s.updated_at):void 0,lastViewedAt:s.last_viewed_at?new Date(s.last_viewed_at):void 0,lastAssistantMessageAt:s.last_assistant_message_at?new Date(s.last_assistant_message_at):void 0,favorite:1===s.favorite,status:s.status||null,link:s.link||void 0,cliToolId:s.cli_tool_id??"claude",selectedAgents:(0,o.e7)(s.selected_agents),vibeLocalModel:s.vibe_local_model??null,vibeLocalContextWindow:s.vibe_local_context_window??null}:null}function A(e,t){e.prepare("DELETE FROM worktrees WHERE path = ? AND id != ?").run(t.path,t.id),e.prepare(`
    INSERT INTO worktrees (
      id, name, path, repository_path, repository_name, description,
      last_user_message, last_user_message_at, last_message_summary, updated_at, cli_tool_id
    )
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    ON CONFLICT(id) DO UPDATE SET
      name = excluded.name,
      path = excluded.path,
      repository_path = excluded.repository_path,
      repository_name = excluded.repository_name,
      description = COALESCE(excluded.description, worktrees.description),
      last_user_message = COALESCE(excluded.last_user_message, worktrees.last_user_message),
      last_user_message_at = COALESCE(excluded.last_user_message_at, worktrees.last_user_message_at),
      last_message_summary = COALESCE(excluded.last_message_summary, worktrees.last_message_summary),
      updated_at = COALESCE(excluded.updated_at, worktrees.updated_at),
      cli_tool_id = COALESCE(excluded.cli_tool_id, worktrees.cli_tool_id)
  `).run(t.id,t.name,t.path,t.repositoryPath||null,t.repositoryName||null,t.description||null,t.lastUserMessage||null,t.lastUserMessageAt?.getTime()||null,t.lastMessageSummary||null,t.updatedAt?.getTime()||null,t.cliToolId||"claude")}function O(e,t,s){e.prepare(`
    UPDATE worktrees
    SET description = ?
    WHERE id = ?
  `).run(s||null,t)}function D(e,t,s){e.prepare(`
    UPDATE worktrees
    SET link = ?
    WHERE id = ?
  `).run(s||null,t)}function S(e,t,s){e.prepare(`
    UPDATE worktrees
    SET last_viewed_at = ?
    WHERE id = ?
  `).run(s.toISOString(),t)}function x(e,t,s){e.prepare(`
    UPDATE worktrees
    SET favorite = ?
    WHERE id = ?
  `).run(s?1:0,t)}function k(e,t,s){e.prepare(`
    UPDATE worktrees
    SET status = ?
    WHERE id = ?
  `).run(s,t)}function h(e,t,s){e.prepare(`
    UPDATE worktrees
    SET cli_tool_id = ?
    WHERE id = ?
  `).run(s,t)}function X(e,t,s){e.prepare(`
    UPDATE worktrees
    SET selected_agents = ?
    WHERE id = ?
  `).run(JSON.stringify(s),t)}function C(e,t,s){e.prepare(`
    UPDATE worktrees
    SET vibe_local_model = ?
    WHERE id = ?
  `).run(s,t)}function U(e,t,s){e.prepare(`
    UPDATE worktrees
    SET vibe_local_context_window = ?
    WHERE id = ?
  `).run(s,t)}function f(e,t,s){e.prepare(`
    UPDATE worktrees
    SET initial_branch = ?
    WHERE id = ?
  `).run(s,t)}function F(e,t){let s=e.prepare(`
    SELECT initial_branch
    FROM worktrees
    WHERE id = ?
  `).get(t);return s?.initial_branch??null}function v(e,t){return e.prepare(`
    SELECT id FROM worktrees WHERE repository_path = ?
  `).all(t).map(e=>e.id)}function b(e,t){return{deletedCount:e.prepare(`
    DELETE FROM worktrees WHERE repository_path = ?
  `).run(t).changes}}function y(e,t){if(0===t.length)return{deletedCount:0};let s=t.map(()=>"?").join(",");return{deletedCount:e.prepare(`
    DELETE FROM worktrees WHERE id IN (${s})
  `).run(...t).changes}}function M(e,t,s="claude"){let a=e.prepare(`
    SELECT worktree_id, cli_tool_id, last_captured_line, in_progress_message_id
    FROM session_states
    WHERE worktree_id = ? AND cli_tool_id = ?
  `).get(t,s);return a?{worktreeId:a.worktree_id,cliToolId:a.cli_tool_id,lastCapturedLine:a.last_captured_line,inProgressMessageId:a.in_progress_message_id||null}:null}function P(e,t,s,a){e.prepare(`
    INSERT INTO session_states (worktree_id, cli_tool_id, last_captured_line)
    VALUES (?, ?, ?)
    ON CONFLICT(worktree_id, cli_tool_id) DO UPDATE SET
      last_captured_line = excluded.last_captured_line
  `).run(t,s,a)}function H(e,t,s){!function(e,t,s,a){e.prepare(`
    INSERT INTO session_states (worktree_id, cli_tool_id, last_captured_line, in_progress_message_id)
    VALUES (?, ?, 0, ?)
    ON CONFLICT(worktree_id, cli_tool_id) DO UPDATE SET
      in_progress_message_id = excluded.in_progress_message_id
  `).run(t,s,null)}(e,t,s,0)}function B(e,t,s){s?e.prepare(`
      DELETE FROM session_states
      WHERE worktree_id = ? AND cli_tool_id = ?
    `).run(t,s):e.prepare(`
      DELETE FROM session_states
      WHERE worktree_id = ?
    `).run(t)}function W(e){return{id:e.id,worktreeId:e.worktree_id,title:e.title,content:e.content,position:e.position,createdAt:new Date(e.created_at),updatedAt:new Date(e.updated_at)}}function G(e,t){return e.prepare(`
    SELECT id, worktree_id, title, content, position, created_at, updated_at
    FROM worktree_memos
    WHERE worktree_id = ?
    ORDER BY position ASC
  `).all(t).map(W)}function Y(e,t){let s=e.prepare(`
    SELECT id, worktree_id, title, content, position, created_at, updated_at
    FROM worktree_memos
    WHERE id = ?
  `).get(t);return s?W(s):null}function K(e,t,s){let a=(0,r.randomUUID)(),o=Date.now(),i=s.title??"Memo",n=s.content??"";return e.prepare(`
    INSERT INTO worktree_memos (id, worktree_id, title, content, position, created_at, updated_at)
    VALUES (?, ?, ?, ?, ?, ?, ?)
  `).run(a,t,i,n,s.position,o,o),{id:a,worktreeId:t,title:i,content:n,position:s.position,createdAt:new Date(o),updatedAt:new Date(o)}}function $(e,t,s){let a=Date.now(),o=["updated_at = ?"],r=[a];void 0!==s.title&&(o.push("title = ?"),r.push(s.title)),void 0!==s.content&&(o.push("content = ?"),r.push(s.content)),r.push(t),e.prepare(`
    UPDATE worktree_memos
    SET ${o.join(", ")}
    WHERE id = ?
  `).run(...r)}function j(e,t){e.prepare(`
    DELETE FROM worktree_memos
    WHERE id = ?
  `).run(t)}},55483:(e,t,s)=>{s.d(t,{KE:()=>n,e7:()=>i});var a=s(83513);let o=["claude","codex","gemini"];function r(e){return e.length<2||e.length>4?{valid:!1,error:"Must be 2-4 elements"}:e.every(e=>"string"==typeof e&&a.tK.includes(e))?new Set(e).size!==e.length?{valid:!1,error:"Duplicate tool IDs not allowed"}:{valid:!0,value:e}:{valid:!1,error:"Invalid CLI tool ID"}}function i(e){if(!e)return o;try{let t=JSON.parse(e);if(!Array.isArray(t))return o;let s=r(t);if(!s.valid)return o;return s.value}catch{return o}}function n(e){return!Array.isArray(e)||e.length<2||e.length>4?{valid:!1,error:"selected_agents must be an array of 2-4 elements"}:r(e)}}};