mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-13 21:33:32 +08:00
feat: add ecc2 dashboard session deletion controls
This commit is contained in:
@@ -107,6 +107,28 @@ pub async fn cleanup_session_worktree(db: &StateStore, id: &str) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_session(db: &StateStore, id: &str) -> Result<()> {
|
||||||
|
let session = resolve_session(db, id)?;
|
||||||
|
|
||||||
|
if matches!(
|
||||||
|
session.state,
|
||||||
|
SessionState::Pending | SessionState::Running | SessionState::Idle
|
||||||
|
) {
|
||||||
|
anyhow::bail!(
|
||||||
|
"Cannot delete active session {} while it is {}",
|
||||||
|
session.id,
|
||||||
|
session.state
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(worktree) = session.worktree.as_ref() {
|
||||||
|
let _ = crate::worktree::remove(&worktree.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.delete_session(&session.id)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn agent_program(agent_type: &str) -> Result<PathBuf> {
|
fn agent_program(agent_type: &str) -> Result<PathBuf> {
|
||||||
match agent_type {
|
match agent_type {
|
||||||
"claude" => Ok(PathBuf::from("claude")),
|
"claude" => Ok(PathBuf::from("claude")),
|
||||||
@@ -721,6 +743,45 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "current_thread")]
|
||||||
|
async fn delete_session_removes_inactive_session_and_worktree() -> Result<()> {
|
||||||
|
let tempdir = TestDir::new("manager-delete-session")?;
|
||||||
|
let repo_root = tempdir.path().join("repo");
|
||||||
|
init_git_repo(&repo_root)?;
|
||||||
|
|
||||||
|
let cfg = build_config(tempdir.path());
|
||||||
|
let db = StateStore::open(&cfg.db_path)?;
|
||||||
|
let (fake_claude, _) = write_fake_claude(tempdir.path())?;
|
||||||
|
|
||||||
|
let session_id = create_session_in_dir(
|
||||||
|
&db,
|
||||||
|
&cfg,
|
||||||
|
"delete later",
|
||||||
|
"claude",
|
||||||
|
true,
|
||||||
|
&repo_root,
|
||||||
|
&fake_claude,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
stop_session_with_options(&db, &session_id, false).await?;
|
||||||
|
let stopped = db
|
||||||
|
.get_session(&session_id)?
|
||||||
|
.context("stopped session should exist")?;
|
||||||
|
let worktree_path = stopped
|
||||||
|
.worktree
|
||||||
|
.clone()
|
||||||
|
.context("stopped session worktree missing")?
|
||||||
|
.path;
|
||||||
|
|
||||||
|
delete_session(&db, &session_id).await?;
|
||||||
|
|
||||||
|
assert!(db.get_session(&session_id)?.is_none(), "session should be deleted");
|
||||||
|
assert!(!worktree_path.exists(), "worktree path should be removed");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_status_supports_latest_alias() -> Result<()> {
|
fn get_status_supports_latest_alias() -> Result<()> {
|
||||||
let tempdir = TestDir::new("manager-latest-status")?;
|
let tempdir = TestDir::new("manager-latest-status")?;
|
||||||
|
|||||||
@@ -302,6 +302,32 @@ impl StateStore {
|
|||||||
.find(|session| session.id == id || session.id.starts_with(id)))
|
.find(|session| session.id == id || session.id.starts_with(id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_session(&self, session_id: &str) -> Result<()> {
|
||||||
|
self.conn.execute(
|
||||||
|
"DELETE FROM session_output WHERE session_id = ?1",
|
||||||
|
rusqlite::params![session_id],
|
||||||
|
)?;
|
||||||
|
self.conn.execute(
|
||||||
|
"DELETE FROM tool_log WHERE session_id = ?1",
|
||||||
|
rusqlite::params![session_id],
|
||||||
|
)?;
|
||||||
|
self.conn.execute(
|
||||||
|
"DELETE FROM messages WHERE from_session = ?1 OR to_session = ?1",
|
||||||
|
rusqlite::params![session_id],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let deleted = self.conn.execute(
|
||||||
|
"DELETE FROM sessions WHERE id = ?1",
|
||||||
|
rusqlite::params![session_id],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
if deleted == 0 {
|
||||||
|
anyhow::bail!("Session not found: {session_id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn send_message(&self, from: &str, to: &str, content: &str, msg_type: &str) -> Result<()> {
|
pub fn send_message(&self, from: &str, to: &str, content: &str, msg_type: &str) -> Result<()> {
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
"INSERT INTO messages (from_session, to_session, content, msg_type, timestamp)
|
"INSERT INTO messages (from_session, to_session, content, msg_type, timestamp)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ pub async fn run(db: StateStore, cfg: Config) -> Result<()> {
|
|||||||
(_, KeyCode::Char('s')) => dashboard.stop_selected().await,
|
(_, KeyCode::Char('s')) => dashboard.stop_selected().await,
|
||||||
(_, KeyCode::Char('u')) => dashboard.resume_selected().await,
|
(_, KeyCode::Char('u')) => dashboard.resume_selected().await,
|
||||||
(_, KeyCode::Char('x')) => dashboard.cleanup_selected_worktree().await,
|
(_, KeyCode::Char('x')) => dashboard.cleanup_selected_worktree().await,
|
||||||
|
(_, KeyCode::Char('d')) => dashboard.delete_selected_session().await,
|
||||||
(_, KeyCode::Char('r')) => dashboard.refresh(),
|
(_, KeyCode::Char('r')) => dashboard.refresh(),
|
||||||
(_, KeyCode::Char('?')) => dashboard.toggle_help(),
|
(_, KeyCode::Char('?')) => dashboard.toggle_help(),
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ impl Dashboard {
|
|||||||
|
|
||||||
fn render_status_bar(&self, frame: &mut Frame, area: Rect) {
|
fn render_status_bar(&self, frame: &mut Frame, area: Rect) {
|
||||||
let text = format!(
|
let text = format!(
|
||||||
" [n]ew session [s]top [u]resume [x]cleanup [r]efresh [Tab] switch pane [j/k] scroll [+/-] resize [{}] layout [?] help [q]uit ",
|
" [n]ew session [s]top [u]resume [x]cleanup [d]elete [r]efresh [Tab] switch pane [j/k] scroll [+/-] resize [{}] layout [?] help [q]uit ",
|
||||||
self.layout_label()
|
self.layout_label()
|
||||||
);
|
);
|
||||||
let aggregate = self.aggregate_usage();
|
let aggregate = self.aggregate_usage();
|
||||||
@@ -392,6 +392,7 @@ impl Dashboard {
|
|||||||
" s Stop selected session",
|
" s Stop selected session",
|
||||||
" u Resume selected session",
|
" u Resume selected session",
|
||||||
" x Cleanup selected worktree",
|
" x Cleanup selected worktree",
|
||||||
|
" d Delete selected inactive session",
|
||||||
" Tab Next pane",
|
" Tab Next pane",
|
||||||
" S-Tab Previous pane",
|
" S-Tab Previous pane",
|
||||||
" j/↓ Scroll down",
|
" j/↓ Scroll down",
|
||||||
@@ -575,6 +576,19 @@ impl Dashboard {
|
|||||||
self.refresh();
|
self.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_selected_session(&mut self) {
|
||||||
|
let Some(session) = self.sessions.get(self.selected_session) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(error) = manager::delete_session(&self.db, &session.id).await {
|
||||||
|
tracing::warn!("Failed to delete session {}: {error}", session.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn refresh(&mut self) {
|
pub fn refresh(&mut self) {
|
||||||
self.sync_from_store();
|
self.sync_from_store();
|
||||||
}
|
}
|
||||||
@@ -1503,6 +1517,34 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn delete_selected_session_removes_inactive_session() -> Result<()> {
|
||||||
|
let db_path = std::env::temp_dir().join(format!("ecc2-dashboard-{}.db", Uuid::new_v4()));
|
||||||
|
let db = StateStore::open(&db_path)?;
|
||||||
|
let now = Utc::now();
|
||||||
|
|
||||||
|
db.insert_session(&Session {
|
||||||
|
id: "done-1".to_string(),
|
||||||
|
task: "delete me".to_string(),
|
||||||
|
agent_type: "claude".to_string(),
|
||||||
|
state: SessionState::Completed,
|
||||||
|
pid: None,
|
||||||
|
worktree: None,
|
||||||
|
created_at: now,
|
||||||
|
updated_at: now,
|
||||||
|
metrics: SessionMetrics::default(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let dashboard_store = StateStore::open(&db_path)?;
|
||||||
|
let mut dashboard = Dashboard::new(dashboard_store, Config::default());
|
||||||
|
dashboard.delete_selected_session().await;
|
||||||
|
|
||||||
|
assert!(db.get_session("done-1")?.is_none(), "session should be deleted");
|
||||||
|
|
||||||
|
let _ = std::fs::remove_file(db_path);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn grid_layout_renders_four_panes() {
|
fn grid_layout_renders_four_panes() {
|
||||||
let mut dashboard = test_dashboard(vec![sample_session("grid-1", "claude", SessionState::Running, None, 1, 1)], 0);
|
let mut dashboard = test_dashboard(vec![sample_session("grid-1", "claude", SessionState::Running, None, 1, 1)], 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user