From 4f2b8b31833dc9c3ae24e7e94c0823625b5fad4e Mon Sep 17 00:00:00 2001 From: Hibryda Date: Sun, 8 Mar 2026 19:37:17 +0100 Subject: [PATCH] refactor(ctx): remove dead code from ctx integration --- ctx | 2 - v2/src-tauri/src/ctx.rs | 49 ++----------------- v2/src-tauri/src/lib.rs | 6 --- v2/src/lib/adapters/ctx-bridge.ts | 11 ----- .../lib/components/Context/ContextPane.svelte | 2 +- .../components/Workspace/ContextTab.svelte | 15 ------ 6 files changed, 4 insertions(+), 81 deletions(-) delete mode 100644 v2/src/lib/components/Workspace/ContextTab.svelte diff --git a/ctx b/ctx index 6422ae9..bb2995b 100755 --- a/ctx +++ b/ctx @@ -8,9 +8,7 @@ Usage: ctx [args] import sqlite3 import sys -import os import json -from datetime import datetime, timezone from pathlib import Path DB_PATH = Path.home() / ".claude-context" / "context.db" diff --git a/v2/src-tauri/src/ctx.rs b/v2/src-tauri/src/ctx.rs index 1f07fc1..5149ebf 100644 --- a/v2/src-tauri/src/ctx.rs +++ b/v2/src-tauri/src/ctx.rs @@ -5,14 +5,6 @@ use rusqlite::{Connection, params}; use serde::Serialize; use std::sync::Mutex; -#[derive(Debug, Clone, Serialize)] -pub struct CtxProject { - pub name: String, - pub description: String, - pub work_dir: Option, - pub created_at: String, -} - #[derive(Debug, Clone, Serialize)] pub struct CtxEntry { pub project: String, @@ -142,14 +134,11 @@ impl CtxDb { } /// Register a project in the ctx database (creates if not exists). + /// Opens a brief read-write connection; the main self.conn stays read-only. pub fn register_project(&self, name: &str, description: &str, work_dir: Option<&str>) -> Result<(), String> { let db_path = Self::db_path(); - if !db_path.exists() { - return Err("ctx database not found".to_string()); - } - let conn = Connection::open(&db_path) - .map_err(|e| format!("Failed to open database: {e}"))?; + .map_err(|e| format!("ctx database not found: {e}"))?; conn.execute( "INSERT OR IGNORE INTO sessions (name, description, work_dir) VALUES (?1, ?2, ?3)", @@ -159,30 +148,6 @@ impl CtxDb { Ok(()) } - pub fn list_projects(&self) -> Result, String> { - let lock = self.conn.lock().unwrap(); - let conn = lock.as_ref().ok_or("ctx database not found")?; - - let mut stmt = conn - .prepare("SELECT name, description, work_dir, created_at FROM sessions ORDER BY name") - .map_err(|e| format!("ctx query failed: {e}"))?; - - let projects = stmt - .query_map([], |row| { - Ok(CtxProject { - name: row.get(0)?, - description: row.get(1)?, - work_dir: row.get(2)?, - created_at: row.get(3)?, - }) - }) - .map_err(|e| format!("ctx query failed: {e}"))? - .collect::, _>>() - .map_err(|e| format!("ctx row read failed: {e}"))?; - - Ok(projects) - } - pub fn get_context(&self, project: &str) -> Result, String> { let lock = self.conn.lock().unwrap(); let conn = lock.as_ref().ok_or("ctx database not found")?; @@ -268,7 +233,7 @@ impl CtxDb { project: row.get(0)?, key: row.get(1)?, value: row.get(2)?, - updated_at: String::new(), + updated_at: String::new(), // FTS5 virtual table doesn't store updated_at }) }) .map_err(|e| format!("ctx search failed: {e}"))? @@ -295,14 +260,6 @@ mod tests { let _db = CtxDb::new(); } - #[test] - fn test_list_projects_missing_db_returns_error() { - let db = make_missing_db(); - let result = db.list_projects(); - assert!(result.is_err()); - assert_eq!(result.unwrap_err(), "ctx database not found"); - } - #[test] fn test_get_context_missing_db_returns_error() { let db = make_missing_db(); diff --git a/v2/src-tauri/src/lib.rs b/v2/src-tauri/src/lib.rs index 239e017..239114f 100644 --- a/v2/src-tauri/src/lib.rs +++ b/v2/src-tauri/src/lib.rs @@ -192,11 +192,6 @@ fn ctx_register_project(state: State<'_, AppState>, name: String, description: S state.ctx_db.register_project(&name, &description, work_dir.as_deref()) } -#[tauri::command] -fn ctx_list_projects(state: State<'_, AppState>) -> Result, String> { - state.ctx_db.list_projects() -} - #[tauri::command] fn ctx_get_context(state: State<'_, AppState>, project: String) -> Result, String> { state.ctx_db.get_context(&project) @@ -551,7 +546,6 @@ pub fn run() { ssh_session_delete, ctx_init_db, ctx_register_project, - ctx_list_projects, ctx_get_context, ctx_get_shared, ctx_get_summaries, diff --git a/v2/src/lib/adapters/ctx-bridge.ts b/v2/src/lib/adapters/ctx-bridge.ts index 66e2212..4956282 100644 --- a/v2/src/lib/adapters/ctx-bridge.ts +++ b/v2/src/lib/adapters/ctx-bridge.ts @@ -1,12 +1,5 @@ import { invoke } from '@tauri-apps/api/core'; -export interface CtxProject { - name: string; - description: string; - work_dir: string | null; - created_at: string; -} - export interface CtxEntry { project: string; key: string; @@ -28,10 +21,6 @@ export async function ctxRegisterProject(name: string, description: string, work return invoke('ctx_register_project', { name, description, workDir: workDir ?? null }); } -export async function ctxListProjects(): Promise { - return invoke('ctx_list_projects'); -} - export async function ctxGetContext(project: string): Promise { return invoke('ctx_get_context', { project }); } diff --git a/v2/src/lib/components/Context/ContextPane.svelte b/v2/src/lib/components/Context/ContextPane.svelte index 9679ada..d7d2834 100644 --- a/v2/src/lib/components/Context/ContextPane.svelte +++ b/v2/src/lib/components/Context/ContextPane.svelte @@ -46,7 +46,7 @@ dbMissing = false; } catch (e) { error = `${e}`; - dbMissing = error.includes('not found'); + dbMissing = error.includes('not found'); // Coupled to Rust error text "ctx database not found" } finally { loading = false; } diff --git a/v2/src/lib/components/Workspace/ContextTab.svelte b/v2/src/lib/components/Workspace/ContextTab.svelte deleted file mode 100644 index e9970f1..0000000 --- a/v2/src/lib/components/Workspace/ContextTab.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - -
- {}} /> -
- -