diff --git a/crates/goose/src/agents/execute_commands.rs b/crates/goose/src/agents/execute_commands.rs index da675944e..8914643df 100644 --- a/crates/goose/src/agents/execute_commands.rs +++ b/crates/goose/src/agents/execute_commands.rs @@ -634,7 +634,6 @@ mod tests { .iter() .any(|command| command.name == "status")); } - #[tokio::test] async fn invalid_rendered_recipe_schema_returns_assistant_response() { let agent = Agent::new(); @@ -673,4 +672,25 @@ mod tests { .contains("Recipe /invalid-rendered-schema is not valid")); assert!(agent.final_output_tool.lock().await.is_none()); } + #[tokio::test] + async fn doctor_refuses_without_enabling_developer() { + let agent = Agent::new(); + + let response = agent + .execute_command("/doctor", "doctor-disabled-legacy-test") + .await + .expect("doctor command should succeed") + .expect("doctor command should return a message"); + + assert_eq!( + response.as_concat_text(), + crate::doctor::DEVELOPER_EXTENSION_REQUIRED_MESSAGE + ); + assert!( + !agent + .extension_manager + .is_extension_enabled(crate::agents::platform_extensions::developer::EXTENSION_NAME) + .await + ); + } } diff --git a/crates/goose/src/agents/state_machine/tests/mod.rs b/crates/goose/src/agents/state_machine/tests/mod.rs index 6f00f2c2f..9f81b5be2 100644 --- a/crates/goose/src/agents/state_machine/tests/mod.rs +++ b/crates/goose/src/agents/state_machine/tests/mod.rs @@ -110,6 +110,36 @@ async fn bang_shell_requests_the_shell_tool() -> Result<()> { Ok(()) } +#[tokio::test] +async fn doctor_refuses_without_developer_before_inference() -> Result<()> { + let (pipeline, api) = test_pipeline().await?; + let agent = crate::execution::manager::AgentManager::instance() + .await? + .get_or_create_agent(pipeline.session_id.clone()) + .await?; + agent + .extension_manager + .remove_extension(crate::agents::platform_extensions::developer::EXTENSION_NAME) + .await?; + + let result = pipeline.run(["/doctor"]).await?; + + result.assert_message( + -1, + Agent, + crate::doctor::DEVELOPER_EXTENSION_REQUIRED_MESSAGE, + ); + assert_eq!(api.call_count(), 0); + assert!( + !agent + .extension_manager + .is_extension_enabled(crate::agents::platform_extensions::developer::EXTENSION_NAME) + .await + ); + + Ok(()) +} + #[tokio::test] async fn max_turns_counts_inference_calls_and_injects_budget() -> Result<()> { let (pipeline, api) = test_pipeline().await?; diff --git a/crates/goose/src/doctor.rs b/crates/goose/src/doctor.rs index 7f794634d..caeff0950 100644 --- a/crates/goose/src/doctor.rs +++ b/crates/goose/src/doctor.rs @@ -11,13 +11,21 @@ use crate::session::{ }; use goose_providers::errors::ProviderError; +pub(crate) const DEVELOPER_EXTENSION_REQUIRED_MESSAGE: &str = "**Goose Doctor**\n\n\ +`/doctor` requires the Developer extension, but it is disabled for this session.\n\n\ +Enable it for this session and run `/doctor` again:\n\ +- CLI: `/builtin developer`\n\ +- Desktop: select **Developer** in the session extension selector."; + pub async fn run(agent: &crate::agents::Agent, session_id: &str) -> anyhow::Result { + if let Some(message) = require_developer_extension(agent).await { + return Ok(message); + } + if let Some(msg) = ensure_working_provider(agent, session_id).await? { return Ok(msg); } - ensure_developer_extension(agent, session_id).await; - let info = SystemInfo::collect(); let extensions = agent.list_extensions().await; @@ -56,6 +64,24 @@ pub async fn run(agent: &crate::agents::Agent, session_id: &str) -> anyhow::Resu Ok(Message::user().with_text(prompt)) } +async fn require_developer_extension(agent: &crate::agents::Agent) -> Option { + let has_developer = agent + .extension_manager + .get_extension_configs() + .await + .iter() + .any(is_developer_platform_config); + + (!has_developer).then(|| Message::assistant().with_text(DEVELOPER_EXTENSION_REQUIRED_MESSAGE)) +} + +fn is_developer_platform_config(config: &ExtensionConfig) -> bool { + matches!( + config, + ExtensionConfig::Builtin { .. } | ExtensionConfig::Platform { .. } + ) && config.key() == developer::EXTENSION_NAME +} + async fn ensure_working_provider( agent: &crate::agents::Agent, session_id: &str, @@ -115,26 +141,6 @@ async fn ensure_working_provider( )))) } -async fn ensure_developer_extension(agent: &crate::agents::Agent, session_id: &str) { - if agent - .extension_manager - .is_extension_enabled(developer::EXTENSION_NAME) - .await - { - return; - } - let config = ExtensionConfig::Platform { - name: developer::EXTENSION_NAME.to_string(), - description: "Write and edit files, and execute shell commands".to_string(), - display_name: Some("Developer".to_string()), - bundled: None, - available_tools: vec![], - }; - if let Err(e) = agent.add_extension(config, session_id).await { - tracing::warn!("Doctor: failed to load developer extension: {}", e); - } -} - async fn save_and_set( agent: &crate::agents::Agent, session_id: &str, @@ -272,3 +278,43 @@ fn describe_error(e: &ProviderError) -> String { other => format!("{}", other), } } + +#[cfg(test)] +mod tests { + use super::*; + + #[tokio::test] + async fn developer_requirement_accepts_enabled_extension() { + let agent = crate::agents::Agent::new(); + agent + .extension_manager + .add_extension( + ExtensionConfig::Platform { + name: developer::EXTENSION_NAME.to_string(), + description: "Developer tools".to_string(), + display_name: Some("Developer".to_string()), + bundled: None, + available_tools: vec![], + }, + None, + None, + Some("doctor-enabled-test"), + ) + .await + .expect("developer extension should load"); + + assert!(require_developer_extension(&agent).await.is_none()); + } + + #[test] + fn custom_extension_named_developer_does_not_satisfy_requirement() { + let config = ExtensionConfig::stdio( + developer::EXTENSION_NAME, + "custom-developer", + "Unrelated custom extension", + 30_u64, + ); + + assert!(!is_developer_platform_config(&config)); + } +}