Render tool output as terminal text

This commit is contained in:
Georg Bauer
2026-07-27 22:07:21 +02:00
parent a7f26ccb71
commit d371d9d659
2 changed files with 22 additions and 3 deletions

View File

@@ -1472,7 +1472,7 @@ fn split_tool_results(result: &str) -> Vec<String> {
}
pub(crate) fn bounded_tool_text(text: &str, limit: usize) -> String {
let mut output = text.replace('\n', " ");
let mut output = text.to_owned();
if output.chars().count() > limit {
output = output
.chars()
@@ -1489,7 +1489,12 @@ pub(crate) fn tool_parameters(call: &ToolCall) -> String {
.find_map(|name| string(call, name).map(|value| (name, value)))
.map_or_else(
|| bounded_tool_text(&Value::Object(call.arguments.clone()).to_string(), 240),
|(name, value)| format!("{name}: {}", bounded_tool_text(value, 240)),
|(name, value)| {
format!(
"{name}: {}",
bounded_tool_text(&value.replace('\n', " "), 240)
)
},
)
}
@@ -1947,6 +1952,15 @@ mod tests {
assert!(!SHELL_ENV_ALLOWLIST.contains(&"SSH_AUTH_SOCK"));
}
#[test]
fn tool_output_keeps_terminal_lines_but_parameter_summaries_do_not() {
assert_eq!(bounded_tool_text("one\ntwo", 20), "one\ntwo");
assert_eq!(
tool_parameters(&call("bash", [("command", "one\ntwo")])),
"command: one two"
);
}
#[test]
fn denial_and_stop_cancel_commands_awaiting_approval() {
let directory = std::env::temp_dir().join(format!(

View File

@@ -141,6 +141,11 @@ impl App {
})
.padding(0)
.size(14)
.font(if message.tool {
iced::Font::MONOSPACE
} else {
iced::Font::DEFAULT
})
.style(selectable_text_style),
);
} else {
@@ -503,7 +508,7 @@ fn tool_cards(cards: Vec<crate::agent::ToolCard>) -> Element<'static, Message> {
.spacing(5);
if let Some(result) = card.result {
let bounded = crate::agent::bounded_tool_text(&result, 1_200);
content = content.push(text(bounded).size(12));
content = content.push(text(bounded).font(iced::Font::MONOSPACE).size(12));
}
rows = rows.push(container(content).padding(10).width(Length::Fill));
}