fix(discovery): correct subagent directory path structure

Subagents live at <session-uuid>/subagents/ (a sibling directory to
the session JSONL), not at <project-dir>/subagents/. Fix both
discover_agents_for_session and discover_all_agents to use the correct
path, and update integration tests accordingly.

Closes claudbg-33n0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
Elijah Voigt 2 months ago
parent 5bddec167b
commit 01afe4d804

@ -1,11 +1,11 @@
--- ---
# claudbg-33n0 # claudbg-33n0
title: Agent discovery looks in wrong subagents directory — sessions show 0 agents title: Agent discovery looks in wrong subagents directory — sessions show 0 agents
status: todo status: completed
type: bug type: bug
priority: high priority: high
created_at: 2026-03-30T04:43:21Z created_at: 2026-03-30T04:43:21Z
updated_at: 2026-03-30T04:43:21Z updated_at: 2026-03-30T05:01:30Z
--- ---
## Problem ## 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 198205), `discover_all_agents` (lines 211266), `collect_agents_in_dir` - `src/parser/discovery.rs``discover_agents_for_session` (lines 198205), `discover_all_agents` (lines 211266), `collect_agents_in_dir`
- `src/commands/agents.rs` — integration tests - `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

@ -529,10 +529,12 @@ mod tests {
.join(".claude") .join(".claude")
.join("projects") .join("projects")
.join("myproject"); .join("myproject");
let subagents = projects.join("subagents");
std::fs::create_dir_all(&subagents).unwrap();
let session_id = "bbbbcccc-dddd-eeee-ffff-000000000000"; 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")); let session_file = projects.join(format!("{session_id}.jsonl"));
std::fs::write( std::fs::write(
&session_file, &session_file,
@ -566,10 +568,12 @@ mod tests {
.join(".claude") .join(".claude")
.join("projects") .join("projects")
.join("myproject"); .join("myproject");
let subagents = projects.join("subagents");
std::fs::create_dir_all(&subagents).unwrap();
let session_id = "ccccdddd-eeee-ffff-0000-111122223333"; 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")); let session_file = projects.join(format!("{session_id}.jsonl"));
std::fs::write( std::fs::write(
&session_file, &session_file,

@ -193,14 +193,26 @@ pub fn discover_sessions() -> crate::error::Result<Vec<SessionRef>> {
/// Discover all sub-agent runs for a session given the session's JSONL file path. /// 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 /// The actual disk layout is:
/// `session_file`. /// ```text
/// <project-dir>/
/// <session-uuid>.jsonl
/// <session-uuid>/ ← directory named after the UUID (no extension)
/// subagents/
/// agent-<id>.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<Vec<AgentRef>> { pub fn discover_agents_for_session(session_file: &Path) -> crate::error::Result<Vec<AgentRef>> {
let parent = match session_file.parent() { let parent = match session_file.parent() {
Some(p) => p, Some(p) => p,
None => return Ok(vec![]), 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) collect_agents_in_dir(&subagents_dir, None)
} }
@ -249,15 +261,44 @@ pub fn discover_all_agents() -> crate::error::Result<Vec<AgentRef>> {
continue; continue;
} }
let subagents_dir = proj_path.join("subagents"); // Each project dir may contain zero or more <session-uuid>/ subdirectories.
match collect_agents_in_dir(&subagents_dir, None) { // Each of those may have a `subagents/` directory inside it.
Ok(mut found) => agents.append(&mut found), let session_dir_entries = match std::fs::read_dir(&proj_path) {
Ok(e) => e,
Err(err) => { Err(err) => {
eprintln!( eprintln!(
"claudbg: error collecting agents in {}: {}", "claudbg: could not read {}: {}",
subagents_dir.display(), proj_path.display(),
err 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
);
}
} }
} }
} }

Loading…
Cancel
Save