From b8e9ca2028f9b8ec4a6edb48b760ff61d5d999e5 Mon Sep 17 00:00:00 2001 From: CJACK Date: Sun, 5 Apr 2026 18:33:15 +0800 Subject: [PATCH] refactor: stop stripping _raw and _xml fields from tool call inputs to preserve raw parameter data --- internal/util/toolcalls_parse.go | 4 ---- internal/util/toolcalls_test.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/util/toolcalls_parse.go b/internal/util/toolcalls_parse.go index d010697..6127592 100644 --- a/internal/util/toolcalls_parse.go +++ b/internal/util/toolcalls_parse.go @@ -158,10 +158,6 @@ func filterToolCallsDetailed(parsed []ParsedToolCall, availableToolNames []strin } if tc.Input == nil { tc.Input = map[string]any{} - } else { - // Remove known hallucinated fields often generated by models trying to bridge XML and JSON - delete(tc.Input, "_raw") - delete(tc.Input, "_xml") } out = append(out, tc) } diff --git a/internal/util/toolcalls_test.go b/internal/util/toolcalls_test.go index f131544..da78666 100644 --- a/internal/util/toolcalls_test.go +++ b/internal/util/toolcalls_test.go @@ -176,6 +176,24 @@ func TestParseToolCallsSupportsCanonicalXMLParametersJSON(t *testing.T) { } } +func TestParseToolCallsPreservesRawMalformedXMLParameters(t *testing.T) { + text := `execute_commandcd /root && git status` + calls := ParseToolCalls(text, []string{"execute_command"}) + if len(calls) != 1 { + t.Fatalf("expected 1 call, got %#v", calls) + } + if calls[0].Name != "execute_command" { + t.Fatalf("expected tool name execute_command, got %q", calls[0].Name) + } + raw, ok := calls[0].Input["_raw"].(string) + if !ok { + t.Fatalf("expected raw argument tracking, got %#v", calls[0].Input) + } + if raw != "cd /root && git status" { + t.Fatalf("expected raw arguments to be preserved, got %q", raw) + } +} + func TestParseToolCallsSupportsXMLParametersJSONWithAmpersandCommand(t *testing.T) { text := `execute_command{"command":"sshpass -p 'xxx' ssh -o StrictHostKeyChecking=no -p 1111 root@111.111.111.111 'cd /root && git clone https://github.com/ericc-ch/copilot-api.git'","cwd":null,"timeout":null}` calls := ParseToolCalls(text, []string{"execute_command"})