diff --git a/.beans/claudbg-33n0--agent-discovery-looks-in-wrong-subagents-directory.md b/.beans/claudbg-33n0--agent-discovery-looks-in-wrong-subagents-directory.md index cbaa9ac..2711979 100644 --- a/.beans/claudbg-33n0--agent-discovery-looks-in-wrong-subagents-directory.md +++ b/.beans/claudbg-33n0--agent-discovery-looks-in-wrong-subagents-directory.md @@ -1,11 +1,11 @@ --- # claudbg-33n0 title: Agent discovery looks in wrong subagents directory — sessions show 0 agents -status: todo +status: completed type: bug priority: high created_at: 2026-03-30T04:43:21Z -updated_at: 2026-03-30T04:43:21Z +updated_at: 2026-03-30T05:01:30Z --- ## Problem @@ -61,3 +61,9 @@ The existing unit tests in `src/commands/agents.rs` (`dump_with_real_agent_retur - `src/parser/discovery.rs` — `discover_agents_for_session` (lines 198–205), `discover_all_agents` (lines 211–266), `collect_agents_in_dir` - `src/commands/agents.rs` — integration tests + +## Summary of Changes + +- Fixed in to use to derive the sibling directory +- Fixed to iterate UUID subdirectories inside each project dir and call on each +- Updated tests in (, ) to create agent files at the correct path structure diff --git a/src/commands/agents.rs b/src/commands/agents.rs index 08f6239..bc456da 100644 --- a/src/commands/agents.rs +++ b/src/commands/agents.rs @@ -529,10 +529,12 @@ mod tests { .join(".claude") .join("projects") .join("myproject"); - let subagents = projects.join("subagents"); - std::fs::create_dir_all(&subagents).unwrap(); let session_id = "bbbbcccc-dddd-eeee-ffff-000000000000"; + // subagents live inside a directory named after the session UUID + let subagents = projects.join(session_id).join("subagents"); + std::fs::create_dir_all(&subagents).unwrap(); + let session_file = projects.join(format!("{session_id}.jsonl")); std::fs::write( &session_file, @@ -566,10 +568,12 @@ mod tests { .join(".claude") .join("projects") .join("myproject"); - let subagents = projects.join("subagents"); - std::fs::create_dir_all(&subagents).unwrap(); let session_id = "ccccdddd-eeee-ffff-0000-111122223333"; + // subagents live inside a directory named after the session UUID + let subagents = projects.join(session_id).join("subagents"); + std::fs::create_dir_all(&subagents).unwrap(); + let session_file = projects.join(format!("{session_id}.jsonl")); std::fs::write( &session_file, diff --git a/src/parser/discovery.rs b/src/parser/discovery.rs index ada1d34..5dad6a6 100644 --- a/src/parser/discovery.rs +++ b/src/parser/discovery.rs @@ -193,14 +193,26 @@ pub fn discover_sessions() -> crate::error::Result> { /// Discover all sub-agent runs for a session given the session's JSONL file path. /// -/// Looks for `subagents/agent-*.jsonl` files in the same directory as -/// `session_file`. +/// The actual disk layout is: +/// ```text +/// / +/// .jsonl +/// / ← directory named after the UUID (no extension) +/// subagents/ +/// agent-.jsonl +/// ``` +/// So we derive the sibling directory from the file stem and look inside it. pub fn discover_agents_for_session(session_file: &Path) -> crate::error::Result> { let parent = match session_file.parent() { Some(p) => p, None => return Ok(vec![]), }; - let subagents_dir = parent.join("subagents"); + let stem = match session_file.file_stem() { + Some(s) => s, + None => return Ok(vec![]), + }; + let session_dir = parent.join(stem); + let subagents_dir = session_dir.join("subagents"); collect_agents_in_dir(&subagents_dir, None) } @@ -249,15 +261,44 @@ pub fn discover_all_agents() -> crate::error::Result> { continue; } - let subagents_dir = proj_path.join("subagents"); - match collect_agents_in_dir(&subagents_dir, None) { - Ok(mut found) => agents.append(&mut found), + // Each project dir may contain zero or more / subdirectories. + // Each of those may have a `subagents/` directory inside it. + let session_dir_entries = match std::fs::read_dir(&proj_path) { + Ok(e) => e, Err(err) => { eprintln!( - "claudbg: error collecting agents in {}: {}", - subagents_dir.display(), + "claudbg: could not read {}: {}", + proj_path.display(), err ); + continue; + } + }; + + for session_dir_entry in session_dir_entries { + let session_dir_entry = match session_dir_entry { + Ok(e) => e, + Err(err) => { + eprintln!("claudbg: error reading session dir entry: {err}"); + continue; + } + }; + + let session_dir_path = session_dir_entry.path(); + if !session_dir_path.is_dir() { + continue; + } + + let subagents_dir = session_dir_path.join("subagents"); + match collect_agents_in_dir(&subagents_dir, None) { + Ok(mut found) => agents.append(&mut found), + Err(err) => { + eprintln!( + "claudbg: error collecting agents in {}: {}", + subagents_dir.display(), + err + ); + } } } }