From 15b037ceca39ee4c179ad227b4f006c121faf0ea Mon Sep 17 00:00:00 2001 From: hermes Date: Fri, 16 Oct 2026 20:36:47 +0000 Subject: [PATCH 1/2] claude_cli: show the command/path of each claude tool call --- crates/hx-ai/src/claude_cli.rs | 45 ++++++++++++++++++++++++++++------ tests/claude_cli_e2e.sh | 2 +- tests/fake_claude.py | 3 ++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/crates/hx-ai/src/claude_cli.rs b/crates/hx-ai/src/claude_cli.rs index 3efa994..f9683d5 100644 --- a/crates/hx-ai/src/claude_cli.rs +++ b/crates/hx-ai/src/claude_cli.rs @@ -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![ diff --git a/tests/claude_cli_e2e.sh b/tests/claude_cli_e2e.sh index e858e1b..45fe500 100644 --- a/tests/claude_cli_e2e.sh +++ b/tests/claude_cli_e2e.sh @@ -10,6 +10,6 @@ chmod +x "$root/tests/fake_claude.py" cd "$tmp/repo" export HOME="$tmp/home" HX_CLAUDE_BIN="$root/tests/fake_claude.py" FAKE_CLAUDE_LOG="$tmp/argv" "$root/target/debug/hx" -p "hi" -s "$tmp/s.jsonl" > "$tmp/out" 2> "$tmp/err" || { echo "FAIL run"; cat "$tmp/err"; exit 1; } -grep -q "approve: allow" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; } +grep -q "claude Bash: echo hi-from-tool" "$tmp/out" && grep -q "approve: allow" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; } grep -q '"--permission-prompt-tool"' "$tmp/argv" && grep -q '"--mcp-config"' "$tmp/argv" && grep -q '"stream-json"' "$tmp/argv" || { echo "FAIL argv"; cat "$tmp/argv"; exit 1; } echo "claude cli e2e ok" diff --git a/tests/fake_claude.py b/tests/fake_claude.py index 6c78459..d36f780 100755 --- a/tests/fake_claude.py +++ b/tests/fake_claude.py @@ -20,7 +20,8 @@ if "--permission-prompt-tool" in sys.argv: # act like claude: ask hx whether `r reply = "approve: " + json.loads(lines[1]["result"]["content"][0]["text"])["behavior"] out({"type": "system", "subtype": "init", "session_id": "S1"}) ev = lambda e: out({"type": "stream_event", "session_id": "S1", "event": e}) -ev({"type": "content_block_start", "content_block": {"type": "tool_use", "name": "Read"}}) +out({"type": "assistant", "session_id": "S1", "message": {"content": [ + {"type": "tool_use", "name": "Bash", "input": {"command": "echo hi-from-tool"}}]}}) ev({"type": "content_block_delta", "delta": {"type": "text_delta", "text": reply + " "}}) ev({"type": "content_block_delta", "delta": {"type": "text_delta", "text": "from claude"}}) out({"type": "result", "session_id": "S1", "is_error": False, "result": "hello from claude", -- 2.54.1 From acdb4fcf0dfd5c347265f2f54cd0585a8068fe9b Mon Sep 17 00:00:00 2001 From: hermes Date: Fri, 16 Oct 2026 20:37:11 +0000 Subject: [PATCH 2/2] clippy --- crates/hx-ai/src/claude_cli.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/hx-ai/src/claude_cli.rs b/crates/hx-ai/src/claude_cli.rs index f9683d5..a455959 100644 --- a/crates/hx-ai/src/claude_cli.rs +++ b/crates/hx-ai/src/claude_cli.rs @@ -190,8 +190,8 @@ impl Provider for ClaudeCli { match v["type"].as_str() { Some("stream_event") => { let e = &v["event"]; - match e["type"].as_str() { - Some("content_block_delta") => match e["delta"]["type"].as_str() { + if e["type"] == "content_block_delta" { + match e["delta"]["type"].as_str() { Some("text_delta") => { let t = e["delta"]["text"].as_str().unwrap_or_default(); text += t; @@ -204,8 +204,7 @@ impl Provider for ClaudeCli { tx.send(Ok(StreamEvent::ThinkingDelta { text: t.into() })); } _ => {} - }, - _ => {} + } } } // complete tool calls (the stream events only carry partial JSON) -- 2.54.1