Render tool output as terminal text
This commit is contained in:
18
src/agent.rs
18
src/agent.rs
@@ -1472,7 +1472,7 @@ fn split_tool_results(result: &str) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn bounded_tool_text(text: &str, limit: usize) -> 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 {
|
if output.chars().count() > limit {
|
||||||
output = output
|
output = output
|
||||||
.chars()
|
.chars()
|
||||||
@@ -1489,7 +1489,12 @@ pub(crate) fn tool_parameters(call: &ToolCall) -> String {
|
|||||||
.find_map(|name| string(call, name).map(|value| (name, value)))
|
.find_map(|name| string(call, name).map(|value| (name, value)))
|
||||||
.map_or_else(
|
.map_or_else(
|
||||||
|| bounded_tool_text(&Value::Object(call.arguments.clone()).to_string(), 240),
|
|| 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"));
|
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]
|
#[test]
|
||||||
fn denial_and_stop_cancel_commands_awaiting_approval() {
|
fn denial_and_stop_cancel_commands_awaiting_approval() {
|
||||||
let directory = std::env::temp_dir().join(format!(
|
let directory = std::env::temp_dir().join(format!(
|
||||||
|
|||||||
@@ -141,6 +141,11 @@ impl App {
|
|||||||
})
|
})
|
||||||
.padding(0)
|
.padding(0)
|
||||||
.size(14)
|
.size(14)
|
||||||
|
.font(if message.tool {
|
||||||
|
iced::Font::MONOSPACE
|
||||||
|
} else {
|
||||||
|
iced::Font::DEFAULT
|
||||||
|
})
|
||||||
.style(selectable_text_style),
|
.style(selectable_text_style),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -503,7 +508,7 @@ fn tool_cards(cards: Vec<crate::agent::ToolCard>) -> Element<'static, Message> {
|
|||||||
.spacing(5);
|
.spacing(5);
|
||||||
if let Some(result) = card.result {
|
if let Some(result) = card.result {
|
||||||
let bounded = crate::agent::bounded_tool_text(&result, 1_200);
|
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));
|
rows = rows.push(container(content).padding(10).width(Length::Fill));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user