diff --git a/.beans/claudbg-0yk4--tui-session-message-count-always-shows-0.md b/.beans/claudbg-0yk4--tui-session-message-count-always-shows-0.md index 5555738..9b9e425 100644 --- a/.beans/claudbg-0yk4--tui-session-message-count-always-shows-0.md +++ b/.beans/claudbg-0yk4--tui-session-message-count-always-shows-0.md @@ -1,10 +1,15 @@ --- # claudbg-0yk4 title: 'TUI: session message count always shows 0' -status: todo +status: completed type: bug +priority: normal created_at: 2026-03-31T23:45:03Z -updated_at: 2026-03-31T23:45:03Z +updated_at: 2026-04-01T05:49:51Z --- In the TUI session list, the message count column always shows 0. The message count is not being populated from the database or computed correctly for the TUI. + +## Summary of Changes + +In `src/tui/run.rs`: after building the session list from disk discovery, open the DB and query `session_id, COALESCE(project_path, ''), message_count` from the sessions table. Use `tokio::task::block_in_place` to run the async DB query from the synchronous TUI startup. Populate `msg_count` on each `SessionListItem` from the DB result. diff --git a/.beans/claudbg-zniv--tui-some-sessions-show-no-project-path-in-session.md b/.beans/claudbg-zniv--tui-some-sessions-show-no-project-path-in-session.md index 23e1c12..3a27842 100644 --- a/.beans/claudbg-zniv--tui-some-sessions-show-no-project-path-in-session.md +++ b/.beans/claudbg-zniv--tui-some-sessions-show-no-project-path-in-session.md @@ -1,12 +1,17 @@ --- # claudbg-zniv title: 'TUI: some sessions show no project path in session list' -status: todo +status: completed type: bug +priority: normal created_at: 2026-03-31T23:44:55Z -updated_at: 2026-03-31T23:44:55Z +updated_at: 2026-04-01T05:49:51Z blocking: - claudbg-9627 --- In the TUI session list, some sessions do not display a project path. Likely related to the same root cause as the CLI bug (claudbg-9627). + +## Summary of Changes + +Implemented together with claudbg-0yk4 in `src/tui/run.rs`. When `sr.project_path` from disk discovery is empty (cwd not present in first JSONL line), fall back to the `project_path` stored in the DB sessions table (which is populated during `claudbg index` sync by scanning all JSONL entries). diff --git a/src/tui/run.rs b/src/tui/run.rs index e16b978..70dc542 100644 --- a/src/tui/run.rs +++ b/src/tui/run.rs @@ -9,6 +9,7 @@ //! 4. Tears down the terminal (disable raw mode, leave alternate screen) via //! an RAII guard, so cleanup happens even if an error is returned. +use std::collections::HashMap; use std::io::{self, Stdout}; use std::time::Duration; @@ -222,6 +223,52 @@ pub fn run_tui() -> Result<()> { }) .collect(); + // Enrich session list with data from the DB cache (message counts and + // fallback project paths for sessions whose JSONL first line has no cwd). + // Best-effort: silently skip if the DB is missing or unreadable. + let db_enrichment: HashMap = tokio::task::block_in_place(|| { + tokio::runtime::Handle::current().block_on(async { + let db_path = crate::db::connection::default_db_path(); + let db = match crate::db::connection::open_db(&db_path, false).await { + Ok(d) => d, + Err(_) => return HashMap::new(), + }; + let conn = match db.connect() { + Ok(c) => c, + Err(_) => return HashMap::new(), + }; + let mut rows = match conn + .query( + "SELECT session_id, COALESCE(project_path, ''), message_count FROM sessions", + (), + ) + .await + { + Ok(r) => r, + Err(_) => return HashMap::new(), + }; + let mut map: HashMap = HashMap::new(); + while let Ok(Some(row)) = rows.next().await { + let sid: String = match row.get(0) { + Ok(v) => v, + Err(_) => continue, + }; + let project: String = row.get(1).unwrap_or_default(); + let count: i64 = row.get(2).unwrap_or(0); + map.insert(sid, (project, count as usize)); + } + map + }) + }); + for item in &mut state.sessions { + if let Some((db_project, db_count)) = db_enrichment.get(&item.full_id) { + if item.project.is_empty() && !db_project.is_empty() { + item.project = db_project.clone(); + } + item.msg_count = *db_count; + } + } + loop { // Load transcript data lazily when entering a transcript screen. maybe_load_transcript(&mut state);