refactor(ctx): remove dead code from ctx integration

This commit is contained in:
Hibryda 2026-03-08 19:37:17 +01:00
parent f50811cfdb
commit 4f2b8b3183
6 changed files with 4 additions and 81 deletions

2
ctx
View file

@ -8,9 +8,7 @@ Usage: ctx <command> [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"

View file

@ -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<String>,
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<Vec<CtxProject>, 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::<Result<Vec<_>, _>>()
.map_err(|e| format!("ctx row read failed: {e}"))?;
Ok(projects)
}
pub fn get_context(&self, project: &str) -> Result<Vec<CtxEntry>, 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();

View file

@ -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<Vec<ctx::CtxProject>, String> {
state.ctx_db.list_projects()
}
#[tauri::command]
fn ctx_get_context(state: State<'_, AppState>, project: String) -> Result<Vec<ctx::CtxEntry>, 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,

View file

@ -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<CtxProject[]> {
return invoke('ctx_list_projects');
}
export async function ctxGetContext(project: string): Promise<CtxEntry[]> {
return invoke('ctx_get_context', { project });
}

View file

@ -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;
}

View file

@ -1,15 +0,0 @@
<script lang="ts">
import ContextPane from '../Context/ContextPane.svelte';
</script>
<div class="context-tab">
<ContextPane onExit={() => {}} />
</div>
<style>
.context-tab {
height: 100%;
overflow: hidden;
min-width: 22em;
}
</style>