MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / handle_session_command

Function handle_session_command

crates/opencode-cli/src/main.rs:2957–3051  ·  view source on GitHub ↗
(action: SessionCommands)

Source from the content-addressed store, hash-verified

2955}
2956
2957async fn handle_session_command(action: SessionCommands) -> anyhow::Result<()> {
2958 let db = Database::new()
2959 .await
2960 .map_err(|e| anyhow::anyhow!("Failed to open session database: {}", e))?;
2961 let session_repo = SessionRepository::new(db.pool().clone());
2962 let message_repo = MessageRepository::new(db.pool().clone());
2963
2964 match action {
2965 SessionCommands::List {
2966 max_count,
2967 format,
2968 project,
2969 } => {
2970 let limit = max_count.unwrap_or(50).max(1);
2971 let sessions = session_repo
2972 .list(project.as_deref(), limit)
2973 .await
2974 .map_err(|e| anyhow::anyhow!("Failed to list sessions: {}", e))?;
2975
2976 if sessions.is_empty() {
2977 return Ok(());
2978 }
2979
2980 match format {
2981 SessionListFormat::Json => {
2982 let rows: Vec<_> = sessions
2983 .into_iter()
2984 .filter(|s| s.parent_id.is_none())
2985 .map(|s| {
2986 serde_json::json!({
2987 "id": s.id,
2988 "title": s.title,
2989 "updated": s.time.updated,
2990 "created": s.time.created,
2991 "projectId": s.project_id,
2992 "directory": s.directory
2993 })
2994 })
2995 .collect();
2996 println!("{}", serde_json::to_string_pretty(&rows)?);
2997 }
2998 SessionListFormat::Table => {
2999 println!("Session ID Title Updated");
3000 println!(
3001 "-----------------------------------------------------------------------"
3002 );
3003 for session in sessions.into_iter().filter(|s| s.parent_id.is_none()) {
3004 println!(
3005 "{:<30} {:<25} {}",
3006 session.id,
3007 truncate_text(&session.title, 25),
3008 session.time.updated
3009 );
3010 }
3011 }
3012 }
3013 }
3014 SessionCommands::Show { session_id } => {

Callers 1

mainFunction · 0.85

Calls 10

newFunction · 0.85
poolMethod · 0.80
is_emptyMethod · 0.80
list_for_sessionMethod · 0.80
delete_for_sessionMethod · 0.80
cloneMethod · 0.45
listMethod · 0.45
filterMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected