tools: Send stale file notifications only once (#34026)

Previously, we sent notifications repeatedly until the agent read a
file, which was often inefficient. With this change, we now send a
notification only once (unless the files are modified again, in which
case we'll send another notification).

Release Notes:

- N/A
This commit is contained in:
Oleksiy Syvokon 2025-07-07 22:30:01 +03:00 committed by GitHub
parent e0c860c42a
commit d549993c73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 117 additions and 19 deletions

View file

@ -53,15 +53,21 @@ impl Tool for ProjectNotificationsTool {
cx: &mut App,
) -> ToolResult {
let mut stale_files = String::new();
let mut notified_buffers = Vec::new();
let action_log = action_log.read(cx);
for stale_file in action_log.stale_buffers(cx) {
for stale_file in action_log.read(cx).unnotified_stale_buffers(cx) {
if let Some(file) = stale_file.read(cx).file() {
writeln!(&mut stale_files, "- {}", file.path().display()).ok();
notified_buffers.push(stale_file.clone());
}
}
if !notified_buffers.is_empty() {
action_log.update(cx, |log, cx| {
log.mark_buffers_as_notified(notified_buffers, cx);
});
}
let response = if stale_files.is_empty() {
"No new notifications".to_string()
} else {
@ -155,11 +161,11 @@ mod tests {
// Run the tool again
let result = cx.update(|cx| {
tool.run(
tool.clone().run(
tool_input.clone(),
request.clone(),
project.clone(),
action_log,
action_log.clone(),
model.clone(),
None,
cx,
@ -179,6 +185,31 @@ mod tests {
expected_content,
"Tool should return the stale buffer notification"
);
// Run the tool once more without any changes - should get no new notifications
let result = cx.update(|cx| {
tool.run(
tool_input.clone(),
request.clone(),
project.clone(),
action_log,
model.clone(),
None,
cx,
)
});
let response = result.output.await.unwrap();
let response_text = match &response.content {
ToolResultContent::Text(text) => text.clone(),
_ => panic!("Expected text response"),
};
assert_eq!(
response_text.as_str(),
"No new notifications",
"Tool should return 'No new notifications' when running again without changes"
);
}
fn init_test(cx: &mut TestAppContext) {