Add session rename command to CLI (#12236)

Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
Co-authored-by: Lifei Zhou <lifei@squareup.com>
This commit is contained in:
Lucas Alvares Gomes
2026-09-28 02:42:33 +00:00
committed by GitHub
parent fdfa2d43b2
commit 91e92ea25c
4 changed files with 87 additions and 4 deletions
+36 -1
View File
@@ -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<PathBuf>,
},
#[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<String>,
#[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(())
}
+21 -3
View File
@@ -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<W: Write>(out: &mut W, line: &str) -> Result<bool> {
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<String, Session> = 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
@@ -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 <session_id>`**: Rename a specific session by its session ID (e.g., `20251108_3`)
- **`-n, --new-name <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.
@@ -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