Skip to content

Commit bfa5016

Browse files
committed
print exectuetion res in every invoke
1 parent ad34b23 commit bfa5016

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

crates/chat-cli/src/cli/chat/tools/fs_read.rs

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ impl FsRead {
154154
}
155155
}
156156

157+
queue!(
158+
updates,
159+
style::Print("\n"),
160+
style::Print(CONTINUATION_LINE),
161+
style::Print("\n")
162+
)?;
157163
super::queue_function_result(
158164
&format!(
159165
"Summary: {} operations processed, {} successful, {} failed",
@@ -242,6 +248,7 @@ impl FsImage {
242248
pub async fn invoke(&self, updates: &mut impl Write) -> Result<InvokeOutput> {
243249
let pre_processed_paths: Vec<String> = self.image_paths.iter().map(|path| pre_process(path)).collect();
244250
let valid_images = handle_images_from_paths(updates, &pre_processed_paths);
251+
super::queue_function_result(&format!("Successfully read image"), updates, false, false)?;
245252
Ok(InvokeOutput {
246253
output: OutputKind::Images(valid_images),
247254
})
@@ -250,9 +257,10 @@ impl FsImage {
250257
pub fn queue_description(&self, updates: &mut impl Write) -> Result<()> {
251258
queue!(
252259
updates,
253-
style::Print("Reading images: \n"),
260+
style::Print("Reading images: "),
254261
style::SetForegroundColor(Color::Green),
255262
style::Print(&self.image_paths.join("\n")),
263+
style::Print("\n"),
256264
style::ResetColor,
257265
)?;
258266
Ok(())
@@ -323,7 +331,7 @@ impl FsLine {
323331
}
324332
}
325333

326-
pub async fn invoke(&self, os: &Os, _updates: &mut impl Write) -> Result<InvokeOutput> {
334+
pub async fn invoke(&self, os: &Os, updates: &mut impl Write) -> Result<InvokeOutput> {
327335
let path = sanitize_path_tool_arg(os, &self.path);
328336
debug!(?path, "Reading");
329337
let file_bytes = os.fs.read(&path).await?;
@@ -362,6 +370,17 @@ time. You tried to read {byte_count} bytes. Try executing with fewer lines speci
362370
);
363371
}
364372

373+
super::queue_function_result(
374+
&format!(
375+
"Successfully read {} bytes from {}",
376+
file_contents.len(),
377+
&path.display()
378+
),
379+
updates,
380+
false,
381+
false,
382+
)?;
383+
365384
Ok(InvokeOutput {
366385
output: OutputKind::Text(file_contents),
367386
})
@@ -415,7 +434,6 @@ impl FsSearch {
415434
style::SetForegroundColor(Color::Green),
416435
style::Print(&self.pattern.to_lowercase()),
417436
style::ResetColor,
418-
style::Print("\n"),
419437
)?;
420438
Ok(())
421439
}
@@ -455,36 +473,17 @@ impl FsSearch {
455473
});
456474
}
457475
}
458-
let match_text = if total_matches == 1 {
459-
"1 match".to_string()
460-
} else {
461-
format!("{} matches", total_matches)
462-
};
463-
464-
let color = if total_matches == 0 {
465-
Color::Yellow
466-
} else {
467-
Color::Green
468-
};
469476

470-
let result = if total_matches == 0 {
471-
CROSS.yellow()
472-
} else {
473-
CHECKMARK.green()
474-
};
475-
476-
queue!(
477+
super::queue_function_result(
478+
&format!(
479+
"Found {} matches for pattern '{}' in {}",
480+
total_matches,
481+
pattern,
482+
&file_path.display()
483+
),
477484
updates,
478-
style::SetForegroundColor(Color::Yellow),
479-
style::ResetColor,
480-
style::Print(CONTINUATION_LINE),
481-
style::Print("\n"),
482-
style::Print(" "),
483-
style::Print(result),
484-
style::Print(" Found: "),
485-
style::SetForegroundColor(color),
486-
style::Print(match_text),
487-
style::ResetColor,
485+
false,
486+
false,
488487
)?;
489488

490489
Ok(InvokeOutput {
@@ -535,13 +534,13 @@ impl FsDirectory {
535534
)?)
536535
}
537536

538-
pub async fn invoke(&self, os: &Os, _updates: &mut impl Write) -> Result<InvokeOutput> {
537+
pub async fn invoke(&self, os: &Os, updates: &mut impl Write) -> Result<InvokeOutput> {
539538
let path = sanitize_path_tool_arg(os, &self.path);
540539
let max_depth = self.depth();
541540
debug!(?path, max_depth, "Reading directory at path with depth");
542541
let mut result = Vec::new();
543542
let mut dir_queue = VecDeque::new();
544-
dir_queue.push_back((path, 0));
543+
dir_queue.push_back((path.clone(), 0));
545544
while let Some((path, depth)) = dir_queue.pop_front() {
546545
if depth > max_depth {
547546
break;
@@ -619,6 +618,17 @@ impl FsDirectory {
619618
);
620619
}
621620

621+
super::queue_function_result(
622+
&format!(
623+
"Successfully read directory {} ({} entries)",
624+
&path.display(),
625+
file_count
626+
),
627+
updates,
628+
false,
629+
false,
630+
)?;
631+
622632
Ok(InvokeOutput {
623633
output: OutputKind::Text(result),
624634
})

0 commit comments

Comments
 (0)