Skip to content

Commit 1db4762

Browse files
committed
Fix: core agentic bug fixes before release
1 parent 650f5c0 commit 1db4762

File tree

5 files changed

+102
-29
lines changed

5 files changed

+102
-29
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::io::{
1515
use std::process::ExitCode;
1616
use std::sync::Arc;
1717
use std::sync::atomic::AtomicBool;
18+
use std::time::Duration;
1819

1920
use conversation_state::ConversationState;
2021
use crossterm::style::{
@@ -430,15 +431,21 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
430431
None => break, // Data was incomplete
431432
},
432433
}
434+
435+
// TODO: We should buffer output based on how much we have to parse, not as a constant
436+
// Do not remove unless you are nabochay :)
437+
std::thread::sleep(Duration::from_millis(8));
433438
}
434439

435440
// Set spinner after showing all of the assistant text content so far.
436441
if let (Some(name), true) = (&tool_name_being_recvd, self.is_interactive) {
437-
execute!(self.output, style::Print("\n"))?;
438-
self.spinner = Some(Spinner::new(
439-
Spinners::Dots,
440-
format!("Creating tool {}...", name.clone().green()),
441-
));
442+
queue!(
443+
self.output,
444+
style::SetForegroundColor(Color::Blue),
445+
style::Print(format!("\n{name}: ")),
446+
style::SetForegroundColor(Color::Reset),
447+
)?;
448+
self.spinner = Some(Spinner::new(Spinners::Dots, "Thinking...".to_string()));
442449
}
443450

444451
if ended {
@@ -676,11 +683,11 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
676683
let tool_start = std::time::Instant::now();
677684
queue!(
678685
self.output,
679-
style::Print("\n"),
680-
style::Print("▔".repeat(terminal_width)),
681-
style::Print("\nExecuting "),
686+
style::Print("\n\nExecuting "),
682687
style::SetForegroundColor(Color::Cyan),
683-
style::Print(format!("{}...\n\n", tool.1.display_name())),
688+
style::Print(format!("{}...\n", tool.1.display_name())),
689+
style::SetForegroundColor(Color::DarkGrey),
690+
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
684691
style::SetForegroundColor(Color::Reset),
685692
)?;
686693
should_terminate.store(false, std::sync::atomic::Ordering::SeqCst);
@@ -711,7 +718,7 @@ Hi, I'm <g>Amazon Q</g>. Ask me anything.
711718
style::SetForegroundColor(Color::Green),
712719
style::Print(format!("🟢 Completed in {}s", tool_time)),
713720
style::SetForegroundColor(Color::Reset),
714-
style::Print("\n\n"),
721+
style::Print("\n"),
715722
)?;
716723
if let Some(builder) = corresponding_builder {
717724
builder.is_success = Some(true);

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use serde::Deserialize;
1919

2020
use super::{
2121
InvokeOutput,
22+
MAX_TOOL_RESPONSE_SIZE,
2223
OutputKind,
2324
};
2425

@@ -38,15 +39,15 @@ impl ExecuteBash {
3839
style::Print("\n"),
3940
)?;
4041

41-
let (stdin, stdout, stderr) = match self.interactive {
42-
Some(true) => (Stdio::inherit(), Stdio::inherit(), Stdio::inherit()),
43-
_ => (Stdio::piped(), Stdio::piped(), Stdio::piped()),
42+
let (stdout, stderr) = match self.interactive {
43+
Some(true) => (Stdio::inherit(), Stdio::inherit()),
44+
_ => (Stdio::piped(), Stdio::piped()),
4445
};
4546

4647
let output = tokio::process::Command::new("bash")
4748
.arg("-c")
4849
.arg(&self.command)
49-
.stdin(stdin)
50+
.stdin(Stdio::inherit())
5051
.stdout(stdout)
5152
.stderr(stderr)
5253
.spawn()
@@ -62,12 +63,34 @@ impl ExecuteBash {
6263
execute!(updates, style::Print(&stdout))?;
6364
}
6465

66+
let stdout = format!(
67+
"{}{}",
68+
&stdout[0..stdout.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
69+
if stdout.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
70+
" ... truncated"
71+
} else {
72+
""
73+
}
74+
);
75+
76+
let stderr = format!(
77+
"{}{}",
78+
&stderr[0..stderr.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
79+
if stderr.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
80+
" ... truncated"
81+
} else {
82+
""
83+
}
84+
);
85+
86+
let output = serde_json::json!({
87+
"exit_status": status,
88+
"stdout": stdout,
89+
"stderr": stderr,
90+
});
91+
6592
Ok(InvokeOutput {
66-
output: OutputKind::Json(serde_json::json!({
67-
"exit_status": status,
68-
"stdout": stdout,
69-
"stderr": stderr,
70-
})),
93+
output: OutputKind::Json(output),
7194
})
7295
}
7396

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use tracing::warn;
1919

2020
use super::{
2121
InvokeOutput,
22+
MAX_TOOL_RESPONSE_SIZE,
2223
OutputKind,
2324
format_path,
2425
sanitize_path_tool_arg,
@@ -78,22 +79,31 @@ impl FsRead {
7879
.take(end - start + 1)
7980
.collect::<Vec<_>>()
8081
.join("\n");
81-
queue!(
82-
updates,
83-
style::SetForegroundColor(Color::Green),
84-
style::Print("Reading:\n"),
85-
style::ResetColor,
86-
style::Print("\n"),
87-
)?;
8882

8983
let formatted = stylize_output_if_able(ctx, &path, file_contents.as_str(), Some(start + 1), None);
9084
queue!(updates, style::Print(formatted), style::ResetColor, style::Print("\n"))?;
85+
86+
// TODO: We copy and paste this below so the control flow needs work in this tool
87+
let byte_count = file_contents.len();
88+
if byte_count > MAX_TOOL_RESPONSE_SIZE {
89+
bail!(
90+
"This tool only supports reading {MAX_TOOL_RESPONSE_SIZE} bytes at a time. You tried to read {byte_count} bytes. Try executing with fewer lines specified."
91+
);
92+
}
93+
9194
return Ok(InvokeOutput {
9295
output: OutputKind::Text(file_contents),
9396
});
9497
}
9598

9699
let file = ctx.fs().read_to_string(&path).await?;
100+
let byte_count = file.len();
101+
if byte_count > MAX_TOOL_RESPONSE_SIZE {
102+
bail!(
103+
"This tool only supports reading up to {MAX_TOOL_RESPONSE_SIZE} bytes at a time. You tried to read {byte_count} bytes. Try executing with fewer lines specified."
104+
);
105+
}
106+
97107
let file_text = stylize_output_if_able(ctx, path, file.as_str(), None, None);
98108
queue!(
99109
updates,
@@ -157,8 +167,17 @@ impl FsRead {
157167
}
158168
}
159169
}
170+
171+
let result = result.join("\n");
172+
let byte_count = result.len();
173+
if byte_count > MAX_TOOL_RESPONSE_SIZE {
174+
bail!(
175+
"This tool only supports reading up to {MAX_TOOL_RESPONSE_SIZE} bytes at a time. You tried to read {byte_count} bytes. Try executing with fewer lines specified."
176+
);
177+
}
178+
160179
Ok(InvokeOutput {
161-
output: OutputKind::Text(result.join("\n")),
180+
output: OutputKind::Text(result),
162181
})
163182
}
164183
}
@@ -243,6 +262,7 @@ impl FsRead {
243262
}
244263

245264
let is_file = ctx.fs().symlink_metadata(&path).await?.is_file();
265+
246266
self.ty = Some(is_file);
247267

248268
Ok(())

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ use use_aws::UseAws;
4444

4545
use super::parser::ToolUse;
4646

47+
pub const MAX_TOOL_RESPONSE_SIZE: usize = 30720;
48+
4749
static SYNTAX_SET: LazyLock<SyntaxSet> = LazyLock::new(SyntaxSet::load_defaults_newlines);
4850
static THEME_SET: LazyLock<ThemeSet> = LazyLock::new(ThemeSet::load_defaults);
4951

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use serde::Deserialize;
2020

2121
use super::{
2222
InvokeOutput,
23+
MAX_TOOL_RESPONSE_SIZE,
2324
OutputKind,
2425
};
2526

@@ -66,16 +67,36 @@ impl UseAws {
6667
let stdout = output.stdout.to_str_lossy();
6768
let stderr = output.stderr.to_str_lossy();
6869

70+
let stdout = format!(
71+
"{}{}",
72+
&stdout[0..stdout.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
73+
if stdout.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
74+
" ... truncated"
75+
} else {
76+
""
77+
}
78+
);
79+
80+
let stderr = format!(
81+
"{}{}",
82+
&stderr[0..stderr.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
83+
if stderr.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
84+
" ... truncated"
85+
} else {
86+
""
87+
}
88+
);
89+
6990
if status.eq("0") {
7091
Ok(InvokeOutput {
7192
output: OutputKind::Json(serde_json::json!({
7293
"exit_status": status,
7394
"stdout": stdout,
74-
"stderr": stderr
95+
"stderr": stderr.clone()
7596
})),
7697
})
7798
} else {
78-
Err(eyre::eyre!(stderr.to_string()))
99+
Err(eyre::eyre!(stderr))
79100
}
80101
}
81102

0 commit comments

Comments
 (0)