The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
hooks: keep quotes that belong to a tool argument (#1094)
kyle-elliott-asymptoteb95de429ddfb
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.goindex 6f60fca4..90653673 100644--- a/cli/beacon-hooks/cmd/endpoint_events.go+++ b/cli/beacon-hooks/cmd/endpoint_events.go@@ -880,12 +880,18 @@ func firstNestedString(input map[string]interface{}, key string) string {return normalizeToolString(value)}+// normalizeToolString returns a tool argument as text. A value wrapped whole in one pair of double+// quotes ("npm test", "C:\tools\run.exe") loses that pair; quotes that belong to the value, as in+// echo "hi", stay. Nothing is unescaped: backslashes are what the shell or the path holds.func normalizeToolString(value interface{}) string {str := strings.TrimSpace(fmt.Sprint(value))if str == "" || str == "<nil>" {return ""}- return strings.Trim(strings.TrimSpace(str), `"`)+ if len(str) >= 2 && str[0] == '"' && str[len(str)-1] == '"' && !strings.Contains(str[1:len(str)-1], `"`) {+ return strings.TrimSpace(str[1 : len(str)-1])+ }+ return str}// fileOperation classifies what a tool did to the file it named.diff --git a/cli/beacon-hooks/cmd/tool_string_test.go b/cli/beacon-hooks/cmd/tool_string_test.gonew file mode 100644index 00000000..aaafa662--- /dev/null+++ b/cli/beacon-hooks/cmd/tool_string_test.go@@ -0,0 +1,22 @@+package cmd++import "testing"++// A command's own quotes are part of what it runs, and rules read them; only a value wrapped whole+// in one pair of quotes loses that pair, and backslashes are never unescaped.+func TestFirstToolStringKeepsQuotesThatBelongToTheValue(t *testing.T) {+ for raw, want := range map[string]string{+ `echo "hi"`: `echo "hi"`,+ `"a" b "c"`: `"a" b "c"`,+ `git commit -m "fix"`: `git commit -m "fix"`,+ `"npm test"`: `npm test`,+ `"C:\tools\bin\run.exe"`: `C:\tools\bin\run.exe`,+ `"C:\Users\me\a.go"`: `C:\Users\me\a.go`,+ `"$(\rm -rf ~ )"`: `$(\rm -rf ~ )`,+ `"`: `"`,+ } {+ if got := firstToolString(map[string]interface{}{"command": raw}, "command"); got != want {+ t.Errorf("firstToolString(%q) = %q, want %q", raw, got, want)+ }+ }+}