claude_cli: show the command/path of each claude tool call

This commit is contained in:
hermes committed 2026-10-16 20:36:47 +00:00
1 parent 785effef11
commit 15b037ceca
3 files changed
+41 -9

No files matched your search

+38 -7
View File
@@ -94,6 +94,26 @@ fn prompt(msgs: &[Message], resumed: bool) -> String {
s + "\nCurrent request:\n" + &msgs[last].text()
}
/// `Bash: cargo test`, `Edit: src/a.rs`; other tools show their input, shortened.
fn tool_line(b: &Value) -> String {
let name = b["name"].as_str().unwrap_or("tool");
let i = &b["input"];
let d = [
"command",
"file_path",
"notebook_path",
"pattern",
"url",
"query",
"description",
]
.iter()
.find_map(|k| i[*k].as_str().map(String::from))
.unwrap_or_else(|| i.to_string());
let d: String = d.chars().take(300).collect();
format!("{name}: {d}")
}
fn usage(u: &Value) -> Usage {
let n = |k: &str| u[k].as_u64().unwrap_or(0);
Usage {
@@ -185,16 +205,17 @@ impl Provider for ClaudeCli {
}
_ => {}
},
// claude runs its tools itself; show them, don't hand them to hx
Some("content_block_start")
if e["content_block"]["type"] == "tool_use" =>
{
let n = e["content_block"]["name"].as_str().unwrap_or("tool");
_ => {}
}
}
// complete tool calls (the stream events only carry partial JSON)
Some("assistant") => {
for b in v["message"]["content"].as_array().into_iter().flatten() {
if b["type"] == "tool_use" {
let _ = tx.send(Ok(StreamEvent::TextDelta {
text: format!("\n[claude tool: {n}]\n"),
text: format!("\n[claude {}]\n", tool_line(b)),
}));
}
_ => {}
}
}
Some("result") => {
@@ -250,6 +271,16 @@ impl Provider for ClaudeCli {
mod tests {
use super::*;
#[test]
fn tool_line_shows_what_runs() {
let b = json!({"name": "Bash", "input": {"command": "cargo test", "description": "run"}});
assert_eq!(tool_line(&b), "Bash: cargo test");
let b = json!({"name": "Edit", "input": {"file_path": "a.rs", "old_string": "x"}});
assert_eq!(tool_line(&b), "Edit: a.rs");
let b = json!({"name": "X", "input": {"a": 1}});
assert_eq!(tool_line(&b), "X: {\"a\":1}");
}
#[test]
fn prompt_replays_history_only_on_fresh_session() {
let m = vec![