#[ allow( dead_code ) ]
#[ path = "../common/mod.rs" ]
mod common;
mod b01_default_continues;
mod b02_new_session;
mod b03_print_flag;
mod b04_continue_flag;
mod b05_mtime_selection;
mod b06_session_accumulation;
mod b07_agent_sessions;
mod b08_zero_byte_init;
mod b09_storage_path;
mod b10_entry_threading;
mod b11_auto_continue;
mod b12_agent_session_id_is_parent;
mod b13_subagent_directory_structure;
mod b14_agent_meta_json;
mod b15_agent_slug_field;
mod b16_tools_disable;
#[ must_use ]
#[ inline ]
pub fn claude_home() -> Option< std::path::PathBuf >
{
let home = std::env::var( "HOME" ).ok()?;
let claude = std::path::PathBuf::from( home ).join( ".claude" );
if claude.is_dir() { Some( claude ) } else { None }
}
#[ must_use ]
#[ inline ]
pub fn claude_projects_dir() -> Option< std::path::PathBuf >
{
let projects = claude_home()?.join( "projects" );
if projects.is_dir() { Some( projects ) } else { None }
}
#[ must_use ]
#[ inline ]
pub fn find_projects() -> Vec< std::path::PathBuf >
{
let Some( projects_dir ) = claude_projects_dir() else { return vec![] };
std::fs::read_dir( projects_dir )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e | e.file_type().map( | t | t.is_dir() ).unwrap_or( false ) )
.map( | e | e.path() )
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_sessions( project : &std::path::Path ) -> Vec< std::path::PathBuf >
{
std::fs::read_dir( project )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e |
{
let name = e.file_name();
let name = name.to_string_lossy();
name.ends_with( ".jsonl" )
&& !name.starts_with( "agent-" )
&& e.metadata().map( | m | m.len() > 0 ).unwrap_or( false )
})
.map( | e | e.path() )
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_all_jsonl( project : &std::path::Path ) -> Vec< std::path::PathBuf >
{
std::fs::read_dir( project )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e | e.file_name().to_string_lossy().ends_with( ".jsonl" ) )
.map( | e | e.path() )
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_agent_sessions( project : &std::path::Path ) -> Vec< std::path::PathBuf >
{
std::fs::read_dir( project )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e |
{
let name = e.file_name();
let name = name.to_string_lossy();
name.starts_with( "agent-" ) && name.ends_with( ".jsonl" )
})
.map( | e | e.path() )
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_claude_binary() -> Option< std::path::PathBuf >
{
let path_var = std::env::var( "PATH" ).ok()?;
for dir in path_var.split( ':' )
{
let candidate = std::path::PathBuf::from( dir ).join( "claude" );
if candidate.is_file() { return Some( candidate ); }
}
None
}
#[ must_use ]
#[ inline ]
pub fn stdout( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stdout ).into_owned()
}
#[ must_use ]
#[ inline ]
pub fn stderr( out : &std::process::Output ) -> String
{
String::from_utf8_lossy( &out.stderr ).into_owned()
}
#[ must_use ]
#[ inline ]
pub fn find_subagent_dirs( project : &std::path::Path ) -> Vec< ( String, std::path::PathBuf ) >
{
std::fs::read_dir( project )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e | e.file_type().map( | t | t.is_dir() ).unwrap_or( false ) )
.filter_map( | e |
{
let name = e.file_name().to_string_lossy().into_owned();
let subagents = e.path().join( "subagents" );
if subagents.is_dir() { Some( ( name, subagents ) ) } else { None }
})
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_meta_json_files( subagents_dir : &std::path::Path ) -> Vec< std::path::PathBuf >
{
std::fs::read_dir( subagents_dir )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e | e.file_name().to_string_lossy().ends_with( ".meta.json" ) )
.map( | e | e.path() )
.collect()
}
#[ must_use ]
#[ inline ]
pub fn find_subagent_sessions( subagents_dir : &std::path::Path ) -> Vec< std::path::PathBuf >
{
std::fs::read_dir( subagents_dir )
.ok()
.into_iter()
.flatten()
.filter_map( Result::ok )
.filter( | e |
{
let name = e.file_name();
let name = name.to_string_lossy();
name.starts_with( "agent-" )
&& name.ends_with( ".jsonl" )
&& e.metadata().map( | m | m.len() > 0 ).unwrap_or( false )
})
.map( | e | e.path() )
.collect()
}