feat: load hints in nested subdirs (#7772)

This commit is contained in:
Alex Hancock
2026-03-11 10:06:22 -04:00
committed by GitHub
parent cb4d99d303
commit 8869098de6
6 changed files with 299 additions and 11 deletions
+18
View File
@@ -509,6 +509,11 @@ impl Agent {
});
tracing::Span::current().record("input", tracing::field::display(&input_summary));
self.prompt_manager
.lock()
.await
.record_tool_arguments(&tool_call.arguments, &session.working_dir);
if tool_call.name == PLATFORM_MANAGE_SCHEDULE_TOOL_NAME {
let arguments = tool_call
.arguments
@@ -1572,6 +1577,19 @@ impl Agent {
(tools, toolshim_tools, system_prompt) =
self.prepare_tools_and_prompt(&session_config.id, &session.working_dir).await?;
}
{
let has_new_hints = self
.prompt_manager
.lock()
.await
.load_subdirectory_hints(&working_dir);
if has_new_hints && !tools_updated {
(tools, toolshim_tools, system_prompt) =
self.prepare_tools_and_prompt(&session_config.id, &session.working_dir).await?;
}
}
let mut exit_chat = false;
if no_tools_called {
if let Some(final_output_tool) = self.final_output_tool.lock().await.as_ref() {
+23 -10
View File
@@ -7,7 +7,7 @@ use serde_json::Value;
use std::collections::HashMap;
use crate::agents::extension::ExtensionInfo;
use crate::hints::load_hints::{load_hint_files, AGENTS_MD_FILENAME, GOOSE_HINTS_FILENAME};
use crate::hints::{get_context_filenames, load_hint_files, SubdirectoryHintTracker};
use crate::{
config::{Config, GooseMode},
prompt_template,
@@ -22,6 +22,7 @@ pub struct PromptManager {
system_prompt_override: Option<String>,
system_prompt_extras: IndexMap<String, String>,
current_date_timestamp: String,
subdirectory_hint_tracker: SubdirectoryHintTracker,
}
impl Default for PromptManager {
@@ -88,15 +89,7 @@ impl<'a> SystemPromptBuilder<'a, PromptManager> {
}
pub fn with_hints(mut self, working_dir: &Path) -> Self {
let config = Config::global();
let hints_filenames = config
.get_param::<Vec<String>>("CONTEXT_FILE_NAMES")
.unwrap_or_else(|_| {
vec![
GOOSE_HINTS_FILENAME.to_string(),
AGENTS_MD_FILENAME.to_string(),
]
});
let hints_filenames = get_context_filenames();
let ignore_patterns = {
let builder = ignore::gitignore::GitignoreBuilder::new(working_dir);
builder.build().unwrap_or_else(|_| {
@@ -210,6 +203,7 @@ impl PromptManager {
// Use the fixed current date time so that prompt cache can be used.
// Filtering to an hour to balance user time accuracy and multi session prompt cache hits.
current_date_timestamp: Utc::now().format("%Y-%m-%d %H:00").to_string(),
subdirectory_hint_tracker: SubdirectoryHintTracker::new(),
}
}
@@ -219,6 +213,7 @@ impl PromptManager {
system_prompt_override: None,
system_prompt_extras: IndexMap::new(),
current_date_timestamp: dt.format("%Y-%m-%d %H:%M:%S").to_string(),
subdirectory_hint_tracker: SubdirectoryHintTracker::new(),
}
}
@@ -228,6 +223,24 @@ impl PromptManager {
self.system_prompt_extras.insert(key, instruction);
}
pub fn record_tool_arguments(
&mut self,
arguments: &Option<serde_json::Map<String, serde_json::Value>>,
working_dir: &Path,
) {
self.subdirectory_hint_tracker
.record_tool_arguments(arguments, working_dir);
}
pub fn load_subdirectory_hints(&mut self, working_dir: &Path) -> bool {
let new_hints = self.subdirectory_hint_tracker.load_new_hints(working_dir);
let has_new = !new_hints.is_empty();
for (key, content) in new_hints {
self.system_prompt_extras.insert(key, content);
}
has_new
}
/// Override the system prompt with custom text
pub fn set_system_prompt_override(&mut self, template: String) {
self.system_prompt_override = Some(template);