Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions crates/goose-cli/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ pub async fn classify_planner_response(
}
}

fn generate_extension_name(extension_command: &str) -> String {
let cmd_name: String = extension_command
.split([' ', '/'])
.next_back()
.unwrap_or("")
.chars()
.filter(|c| c.is_alphanumeric())
.collect();

let prefix: String = cmd_name.chars().take(16).collect();

let random_suffix: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();

let name = format!("{}_{}", prefix, random_suffix);
Comment on lines +147 to +155
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cmd_name is empty (which occurs when the input contains only non-alphanumeric characters), prefix will be empty. This leads to name being just _{random_suffix}, which starts with an underscore. The subsequent alphabetic check on line 157 will then prepend 'g', resulting in names like g_abc12345. This creates inconsistent naming where empty prefixes get 'g_' but valid prefixes don't. Consider handling the empty cmd_name case explicitly before formatting the name.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, what? that's exactly how it is supposed to work


if name.chars().next().is_none_or(|c| !c.is_alphabetic()) {
format!("g{}", name)
} else {
name
}
}

impl CliSession {
#[allow(clippy::too_many_arguments)]
pub async fn new(
Expand Down Expand Up @@ -194,11 +220,7 @@ impl CliSession {
}

let cmd = parts.remove(0).to_string();
let name: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let name = generate_extension_name(&extension_command);

let config = ExtensionConfig::Stdio {
name,
Expand Down Expand Up @@ -229,11 +251,7 @@ impl CliSession {
/// # Arguments
/// * `extension_url` - URL of the server
pub async fn add_remote_extension(&mut self, extension_url: String) -> Result<()> {
let name: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let name = generate_extension_name(&extension_url);

let config = ExtensionConfig::Sse {
name,
Expand Down Expand Up @@ -263,11 +281,7 @@ impl CliSession {
/// # Arguments
/// * `extension_url` - URL of the server
pub async fn add_streamable_http_extension(&mut self, extension_url: String) -> Result<()> {
let name: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let name = generate_extension_name(&extension_url);

let config = ExtensionConfig::StreamableHttp {
name,
Expand Down