mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-10 03:13:29 +08:00
feat: add ecc2 dashboard worktree cleanup control
This commit is contained in:
@@ -41,6 +41,7 @@ pub async fn run(db: StateStore, cfg: Config) -> Result<()> {
|
||||
(_, KeyCode::Char('n')) => dashboard.new_session(),
|
||||
(_, KeyCode::Char('s')) => dashboard.stop_selected().await,
|
||||
(_, KeyCode::Char('u')) => dashboard.resume_selected().await,
|
||||
(_, KeyCode::Char('x')) => dashboard.cleanup_selected_worktree().await,
|
||||
(_, KeyCode::Char('r')) => dashboard.refresh(),
|
||||
(_, KeyCode::Char('?')) => dashboard.toggle_help(),
|
||||
_ => {}
|
||||
|
||||
@@ -345,7 +345,7 @@ impl Dashboard {
|
||||
|
||||
fn render_status_bar(&self, frame: &mut Frame, area: Rect) {
|
||||
let text = format!(
|
||||
" [n]ew session [s]top [u]resume [r]efresh [Tab] switch pane [j/k] scroll [+/-] resize [{}] layout [?] help [q]uit ",
|
||||
" [n]ew session [s]top [u]resume [x]cleanup [r]efresh [Tab] switch pane [j/k] scroll [+/-] resize [{}] layout [?] help [q]uit ",
|
||||
self.layout_label()
|
||||
);
|
||||
let aggregate = self.aggregate_usage();
|
||||
@@ -387,6 +387,7 @@ impl Dashboard {
|
||||
" n New session",
|
||||
" s Stop selected session",
|
||||
" u Resume selected session",
|
||||
" x Cleanup selected worktree",
|
||||
" Tab Next pane",
|
||||
" S-Tab Previous pane",
|
||||
" j/↓ Scroll down",
|
||||
@@ -527,6 +528,23 @@ impl Dashboard {
|
||||
self.refresh();
|
||||
}
|
||||
|
||||
pub async fn cleanup_selected_worktree(&mut self) {
|
||||
let Some(session) = self.sessions.get(self.selected_session) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if session.worktree.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Err(error) = manager::cleanup_session_worktree(&self.db, &session.id).await {
|
||||
tracing::warn!("Failed to cleanup session {} worktree: {error}", session.id);
|
||||
return;
|
||||
}
|
||||
|
||||
self.refresh();
|
||||
}
|
||||
|
||||
pub fn refresh(&mut self) {
|
||||
self.sync_from_store();
|
||||
}
|
||||
@@ -1341,6 +1359,44 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cleanup_selected_worktree_clears_session_metadata() -> 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();
|
||||
let worktree_path = std::env::temp_dir().join(format!("ecc2-cleanup-{}", Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&worktree_path)?;
|
||||
|
||||
db.insert_session(&Session {
|
||||
id: "stopped-1".to_string(),
|
||||
task: "cleanup me".to_string(),
|
||||
agent_type: "claude".to_string(),
|
||||
state: SessionState::Stopped,
|
||||
pid: None,
|
||||
worktree: Some(WorktreeInfo {
|
||||
path: worktree_path.clone(),
|
||||
branch: "ecc/stopped-1".to_string(),
|
||||
base_branch: "main".to_string(),
|
||||
}),
|
||||
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.cleanup_selected_worktree().await;
|
||||
|
||||
let session = db
|
||||
.get_session("stopped-1")?
|
||||
.expect("session should exist after cleanup");
|
||||
assert!(session.worktree.is_none(), "worktree metadata should be cleared");
|
||||
|
||||
let _ = std::fs::remove_dir_all(worktree_path);
|
||||
let _ = std::fs::remove_file(db_path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grid_layout_renders_four_panes() {
|
||||
let mut dashboard = test_dashboard(vec![sample_session("grid-1", "claude", SessionState::Running, None, 1, 1)], 0);
|
||||
|
||||
Reference in New Issue
Block a user