diff --git a/crates/goose-cli/src/cli.rs b/crates/goose-cli/src/cli.rs index 69d5763e3..c726ce37e 100644 --- a/crates/goose-cli/src/cli.rs +++ b/crates/goose-cli/src/cli.rs @@ -34,7 +34,7 @@ use crate::commands::schedule::{ handle_schedule_run_now, handle_schedule_services_status, handle_schedule_services_stop, handle_schedule_sessions, }; -use crate::commands::session::{handle_session_list, handle_session_remove}; +use crate::commands::session::{handle_session_list, handle_session_remove, handle_session_rename}; use crate::commands::skills::handle_skills_list; use crate::recipes::extract_from_cli::extract_recipe_info_from_cli; use crate::recipes::recipe::{explain_recipe, render_recipe_as_yaml}; @@ -610,6 +610,19 @@ enum SessionCommand { #[arg(short = 'o', long)] output: Option, }, + #[command(about = "Rename a session")] + Rename { + #[arg( + long = "session-id", + alias = "id", + value_name = "SESSION_ID", + help = "Session ID to rename (e.g., '20250921_143022'). If omitted, prompts interactively." + )] + session_id: Option, + + #[arg(short = 'n', long = "new-name", help = "New name for the session")] + new_name: String, + }, } #[cfg(feature = "scheduler")] @@ -1998,6 +2011,28 @@ async fn handle_session_subcommand(command: SessionCommand) -> Result<()> { }; crate::commands::session::handle_diagnostics(&session_id, output).await?; } + SessionCommand::Rename { + session_id, + new_name, + } => { + let session_manager = SessionManager::instance(); + let session_id = if let Some(id) = session_id { + id + } else { + match crate::commands::session::prompt_interactive_session_selection( + &session_manager, + ) + .await + { + Ok(id) => id, + Err(e) => { + eprintln!("Error: {}", e); + return Ok(()); + } + } + }; + handle_session_rename(session_id, new_name).await?; + } } Ok(()) } diff --git a/crates/goose-cli/src/commands/session.rs b/crates/goose-cli/src/commands/session.rs index acc22c363..e931483b8 100644 --- a/crates/goose-cli/src/commands/session.rs +++ b/crates/goose-cli/src/commands/session.rs @@ -153,6 +153,24 @@ pub async fn handle_session_remove( remove_sessions(&session_manager, matched_sessions).await } +pub async fn handle_session_rename(session_id: String, new_name: String) -> Result<()> { + let new_name = new_name.trim(); + if new_name.is_empty() { + anyhow::bail!("Session name cannot be empty"); + } + + let session_manager = SessionManager::instance(); + + session_manager + .update(&session_id) + .user_provided_name(new_name) + .apply() + .await?; + + println!("Session `{}` renamed to '{}'.", session_id, new_name); + Ok(()) +} + fn write_line_or_broken_pipe_ok(out: &mut W, line: &str) -> Result { match writeln!(out, "{line}") { Ok(()) => Ok(true), @@ -472,7 +490,7 @@ pub async fn prompt_interactive_session_selection( } // Build the selection prompt - let mut selector = select("Select a session to export:"); + let mut selector = select("Select a session"); // Map to display text let display_map: std::collections::HashMap = sessions @@ -497,13 +515,13 @@ pub async fn prompt_interactive_session_selection( // Add a cancel option let cancel_value = String::from("cancel"); - selector = selector.item(cancel_value, "Cancel", "Cancel export"); + selector = selector.item(cancel_value, "Cancel", ""); // Get user selection let selected_display_text: String = selector.interact()?; if selected_display_text == "cancel" { - return Err(anyhow::anyhow!("Export canceled")); + return Err(anyhow::anyhow!("No session selected")); } // Retrieve the selected session diff --git a/documentation/docs/guides/goose-cli-commands.md b/documentation/docs/guides/goose-cli-commands.md index 4d8c6f81c..92c3f8e6f 100644 --- a/documentation/docs/guides/goose-cli-commands.md +++ b/documentation/docs/guides/goose-cli-commands.md @@ -324,6 +324,24 @@ Session removal is permanent and cannot be undone. goose will show which session --- +#### session rename [options] +Rename a saved session. If no session ID is provided, goose will prompt you to select a session interactively. + +**Options:** +- **`--session-id `**: Rename a specific session by its session ID (e.g., `20251108_3`) +- **`-n, --new-name `**: The new name for the session (required) + +**Usage:** +```bash +# Rename a specific session by ID +goose session rename --session-id 20251108_3 --new-name my-project + +# Interactive selection (prompts you to choose a session) +goose session rename --new-name my-project +``` + +--- + #### session export [options] Export sessions in different formats for backup, sharing, migration, or documentation purposes. diff --git a/documentation/docs/guides/sessions/session-management.md b/documentation/docs/guides/sessions/session-management.md index af8fae24e..87a29f29d 100644 --- a/documentation/docs/guides/sessions/session-management.md +++ b/documentation/docs/guides/sessions/session-management.md @@ -107,6 +107,18 @@ In your first session, goose prompts you to [set up an LLM (Large Language Model goose session --name react-migration ``` + To rename an existing session, use the `session rename` subcommand: + + ```sh + goose session rename --session-id 20260213_9 --new-name my-new-name + ``` + + If you omit the session ID, goose will prompt you to select a session interactively: + + ```sh + goose session rename --new-name my-new-name + ``` + If you want to confirm the session name, run: ```sh