Repository: block/goose
File: crates/goose/src/agents/agent.rs (Rust)

Code before:
                            success: true,
                            error: None,
                        },
                        Err(e) => {
                            let error_msg = e.to_string();
                            warn!("Failed to load extension {}: {}", name, error_msg);
                            ExtensionLoadResult {
                                name,
                                success: false,
                                error: Some(error_msg),
                            }
                        }
                    }
                }
            })
            .collect::<Vec<_>>();

        futures::future::join_all(extension_futures).await
    }

    pub async fn add_extension(
        &self,
        extension: ExtensionConfig,
        session_id: Option<&str>,
    ) -> ExtensionResult<()> {
        self.add_extension_internal(extension, None, session_id)
            .await
    }

    pub async fn add_extension_with_working_dir(
        &self,
        extension: ExtensionConfig,
        working_dir: Option<std::path::PathBuf>,
        session_id: Option<&str>,
    ) -> ExtensionResult<()> {
        self.add_extension_internal(extension, working_dir, session_id)
            .await
    }

    async fn add_extension_internal(
        &self,
        extension: ExtensionConfig,
        working_dir: Option<std::path::PathBuf>,
        session_id: Option<&str>,
    ) -> ExtensionResult<()> {
        match &extension {
            ExtensionConfig::Frontend {
                tools,
                instructions,
                ..
            } => {

Review comment (suggestion):
session_id should not be optional here. add_extension_with_working_dir and add_extension_internal are the same right now

this should all just be one thing - add extension with a session id. that session has your working dir.

Code after:
                let agent_ref = self.clone();
                let session_id_clone = session_id.clone();

                async move {
                    let name = config_clone.name().to_string();

                    if agent_ref
                        .extension_manager
                        .is_extension_enabled(&name)
                        .await
                    {
                        tracing::debug!("Extension {} already loaded, skipping", name);
                        return ExtensionLoadResult {
                            name,
                            success: true,
                            error: None,
                        };
                    }

                    match agent_ref
                        .add_extension(config_clone, &session_id_clone)
                        .await
                    {
                        Ok(_) => ExtensionLoadResult {
                            name,
                            success: true,
                            error: None,
                        },
                        Err(e) => {
                            let error_msg = e.to_string();
                            warn!("Failed to load extension {}: {}", name, error_msg);
                            ExtensionLoadResult {
                                name,
                                success: false,
                                error: Some(error_msg),
                            }
                        }
                    }
                }
            })
            .collect::<Vec<_>>();

        futures::future::join_all(extension_futures).await
    }

    pub async fn add_extension(
        &self,
        extension: ExtensionConfig,
        session_id: &str,
    ) -> ExtensionResult<()> {
        let session = self