mirror of
https://github.com/aaif-goose/goose.git
synced 2026-07-03 14:10:03 +02:00
Use the working dir from the session (#7285)
This commit is contained in:
@@ -21,6 +21,8 @@ use rmcp::{
|
||||
const WORKING_DIR_HEADER: &str = "agent-working-dir";
|
||||
const SESSION_ID_HEADER: &str = "agent-session-id";
|
||||
|
||||
pub const WORKING_DIR_PLACEHOLDER: &str = "{{WORKING_DIR}}";
|
||||
|
||||
fn extract_working_dir_from_meta(meta: &Meta) -> Option<PathBuf> {
|
||||
meta.0
|
||||
.get(WORKING_DIR_HEADER)
|
||||
@@ -242,8 +244,6 @@ pub struct DeveloperServer {
|
||||
impl ServerHandler for DeveloperServer {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
// Get base instructions and working directory
|
||||
let cwd = std::env::current_dir().expect("should have a current working dir");
|
||||
let os = std::env::consts::OS;
|
||||
let in_container = Self::is_definitely_container();
|
||||
|
||||
@@ -268,7 +268,7 @@ impl ServerHandler for DeveloperServer {
|
||||
{container_info}
|
||||
"#,
|
||||
os=os,
|
||||
cwd=cwd.to_string_lossy(),
|
||||
cwd=WORKING_DIR_PLACEHOLDER,
|
||||
container_info=if in_container { "container: true" } else { "" },
|
||||
},
|
||||
_ => {
|
||||
@@ -295,7 +295,7 @@ impl ServerHandler for DeveloperServer {
|
||||
{container_info}
|
||||
"#,
|
||||
os=os,
|
||||
cwd=cwd.to_string_lossy(),
|
||||
cwd=WORKING_DIR_PLACEHOLDER,
|
||||
shell=shell_info,
|
||||
container_info=if in_container { "container: true" } else { "" },
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ pub mod tutorial;
|
||||
pub use autovisualiser::AutoVisualiserRouter;
|
||||
pub use computercontroller::ComputerControllerServer;
|
||||
pub use developer::rmcp_developer::DeveloperServer;
|
||||
pub use developer::rmcp_developer::WORKING_DIR_PLACEHOLDER;
|
||||
pub use memory::MemoryServer;
|
||||
pub use tutorial::TutorialServer;
|
||||
|
||||
|
||||
@@ -1728,7 +1728,15 @@ impl Agent {
|
||||
) -> Result<Recipe> {
|
||||
tracing::info!("Starting recipe creation with {} messages", messages.len());
|
||||
|
||||
let extensions_info = self.extension_manager.get_extensions_info().await;
|
||||
let session = self
|
||||
.config
|
||||
.session_manager
|
||||
.get_session(session_id, false)
|
||||
.await?;
|
||||
let extensions_info = self
|
||||
.extension_manager
|
||||
.get_extensions_info(&session.working_dir)
|
||||
.await;
|
||||
tracing::debug!("Retrieved {} extensions info", extensions_info.len());
|
||||
let (extension_count, tool_count) = self
|
||||
.extension_manager
|
||||
|
||||
@@ -791,17 +791,17 @@ impl ExtensionManager {
|
||||
}
|
||||
|
||||
/// Get extensions info for building the system prompt
|
||||
pub async fn get_extensions_info(&self) -> Vec<ExtensionInfo> {
|
||||
pub async fn get_extensions_info(&self, working_dir: &std::path::Path) -> Vec<ExtensionInfo> {
|
||||
let working_dir_str = working_dir.to_string_lossy();
|
||||
self.extensions
|
||||
.lock()
|
||||
.await
|
||||
.iter()
|
||||
.map(|(name, ext)| {
|
||||
ExtensionInfo::new(
|
||||
name,
|
||||
ext.get_instructions().unwrap_or_default().as_str(),
|
||||
ext.supports_resources(),
|
||||
)
|
||||
let instructions = ext.get_instructions().unwrap_or_default();
|
||||
let instructions =
|
||||
instructions.replace(goose_mcp::WORKING_DIR_PLACEHOLDER, &working_dir_str);
|
||||
ExtensionInfo::new(name, &instructions, ext.supports_resources())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -164,7 +164,10 @@ impl Agent {
|
||||
tools.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
|
||||
// Prepare system prompt
|
||||
let extensions_info = self.extension_manager.get_extensions_info().await;
|
||||
let extensions_info = self
|
||||
.extension_manager
|
||||
.get_extensions_info(working_dir)
|
||||
.await;
|
||||
let (extension_count, tool_count) = self
|
||||
.extension_manager
|
||||
.get_extension_and_tool_counts(session_id)
|
||||
|
||||
@@ -120,7 +120,10 @@ impl ProviderTester {
|
||||
.await
|
||||
.expect("get_prefixed_tools failed");
|
||||
|
||||
let info = self.extension_manager.get_extensions_info().await;
|
||||
let info = self
|
||||
.extension_manager
|
||||
.get_extensions_info(std::path::Path::new("."))
|
||||
.await;
|
||||
let system = PromptManager::new()
|
||||
.builder()
|
||||
.with_extensions(info.into_iter())
|
||||
|
||||
Reference in New Issue
Block a user