Skip to content

Commit 73189cc

Browse files
fix: Improve fs_read display (#634)
1 parent de8168b commit 73189cc

File tree

4 files changed

+65
-16
lines changed

4 files changed

+65
-16
lines changed

crates/q_cli/src/cli/chat/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,18 @@ Hi, I'm <g>Amazon Q</g>. I can answer questions about your workspace and tooling
487487
queue!(self.output, cursor::MoveToNextLine(1))?;
488488
queue!(self.output, style::SetAttribute(Attribute::NormalIntensity))?;
489489
tool.show_readable_intention(self.output)?;
490+
queue!(self.output, style::Print("\n"))?;
490491
queue!(self.output, cursor::MoveToNextLine(1))?;
491492
}
492493
queue!(self.output, style::Print("─".repeat(terminal_width)))?;
493-
execute!(self.output, style::Print("\n"))?;
494+
queue!(self.output, style::Print("\n"))?;
494495
execute!(
495496
self.output,
496-
style::Print(
497-
"Press `c` to consent to running these tools, or anything else to continue your conversation.\n\n"
498-
),
497+
style::Print("Enter "),
498+
style::SetForegroundColor(Color::Green),
499+
style::Print("y"),
500+
style::ResetColor,
501+
style::Print(" to consent to running these tools, or anything else to continue your conversation.\n\n")
499502
)?;
500503
}
501504

@@ -510,7 +513,7 @@ Hi, I'm <g>Amazon Q</g>. I can answer questions about your workspace and tooling
510513
match user_input.trim() {
511514
"exit" | "quit" => Ok(None),
512515
// Tool execution.
513-
c if c == "c" && !queued_tools.is_empty() => {
516+
c if c.to_lowercase() == "y" && !queued_tools.is_empty() => {
514517
// Execute the requested tools.
515518
let mut tool_results = vec![];
516519
for tool in queued_tools.drain(..) {
@@ -761,7 +764,7 @@ mod tests {
761764
initial_input: None,
762765
input_source: InputSource::new_mock(vec![
763766
"create a new file".to_string(),
764-
"c".to_string(),
767+
"y".to_string(),
765768
"exit".to_string(),
766769
]),
767770
is_interactive: true,

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

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ impl FsRead {
5454
let is_file = ctx.fs().symlink_metadata(&self.path).await?.is_file();
5555

5656
if is_file {
57-
let relative_path = relative_path(ctx.env().current_dir()?, &path);
57+
// TODO(bskiser): improve pathing display
58+
// let relative_path = relative_path(ctx.env().current_dir()?, &path);
59+
let relative_path = &path;
5860
if let Some((start, Some(end))) = self.read_range()? {
5961
// TODO: file size limit?
6062
// TODO: don't read entire file in memory
@@ -166,7 +168,14 @@ impl FsRead {
166168
let is_file = self.ty.expect("Tool needs to have been validated");
167169

168170
if is_file {
169-
queue!(updates, style::Print(format!("Reading file: {}, ", self.path)))?;
171+
queue!(
172+
updates,
173+
style::Print("Reading file: "),
174+
style::SetForegroundColor(Color::Green),
175+
style::Print(&self.path),
176+
style::ResetColor,
177+
style::Print(", "),
178+
)?;
170179

171180
let read_range = self.read_range.as_ref();
172181
let start = read_range.and_then(|r| r.first());
@@ -175,20 +184,45 @@ impl FsRead {
175184
match (start, end) {
176185
(Some(start), Some(end)) => Ok(queue!(
177186
updates,
178-
style::Print(format!("from line {} to {}\n", start, end))
187+
style::Print("from line "),
188+
style::SetForegroundColor(Color::Green),
189+
style::Print(start),
190+
style::ResetColor,
191+
style::Print(" to "),
192+
style::SetForegroundColor(Color::Green),
193+
style::Print(end),
194+
style::ResetColor,
179195
)?),
180196
(Some(start), None) => {
181-
let input = if *start > 0 {
182-
format!("from line {} to end of file\n", start)
197+
if *start > 0 {
198+
Ok(queue!(
199+
updates,
200+
style::Print("from line "),
201+
style::SetForegroundColor(Color::Green),
202+
style::Print(start),
203+
style::ResetColor,
204+
style::Print(" to end of file"),
205+
)?)
183206
} else {
184-
format!("{} line from the end of file to end of file", start)
185-
};
186-
Ok(queue!(updates, style::Print(input))?)
207+
Ok(queue!(
208+
updates,
209+
style::SetForegroundColor(Color::Green),
210+
style::Print(start),
211+
style::ResetColor,
212+
style::Print(" line from the end of file to end of file"),
213+
)?)
214+
}
187215
},
188-
_ => Ok(queue!(updates, style::Print("all lines"))?),
216+
_ => Ok(queue!(updates, style::Print("all lines".to_string()))?),
189217
}
190218
} else {
191-
queue!(updates, style::Print(format!("Reading directory: {}, ", self.path)))?;
219+
queue!(
220+
updates,
221+
style::Print("Reading directory: "),
222+
style::SetForegroundColor(Color::Green),
223+
style::Print(&self.path),
224+
style::ResetColor
225+
)?;
192226

193227
let depth = if let Some(ref depth) = self.read_range {
194228
*depth.first().unwrap_or(&0)

crates/q_cli/tests/chat_response_stubs/fs_read.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,15 @@
2121
"read_range": [1, 10]
2222
}
2323
}
24+
],
25+
[
26+
{
27+
"tool_use_id": "2",
28+
"name": "fs_read",
29+
"args": {
30+
"path": "Cargo.toml",
31+
"read_range": [5]
32+
}
33+
}
2434
]
2535
]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]

0 commit comments

Comments
 (0)