fix(hooks): accept raw control characters in payloads

This commit is contained in:
Bortlesboat authored and Dr. Dominik Jain committed 2026-07-26 18:47:18 +02:00
1 parent 31aef83786
commit 026b007bb8
3 files changed
+16 -1

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ Status of the `main` branch. Changes prior to the next official version change w
- Add `serena-hooks --client=grok`, including Grok-native PreToolUse allow/deny output.
- PreToolUse remind hook: coerce non-string shell command values instead of failing, and recognize
`target_file`/`targetFile` file-path keys (shared payload parsing, applies to all hook clients).
- Fix hook input parsing for clients that emit raw control characters in JSON string values #1743.
# v1.6.1 (2026-07-21)
+1 -1
View File
@@ -31,7 +31,7 @@ class HookClient(Enum):
class Hook(ABC):
def __init__(self, client: HookClient):
raw = sys.stdin.read()
input_data = json.loads(raw)
input_data = json.loads(raw, strict=False)
self._input_data = input_data
self._client = client
+14
View File
@@ -992,6 +992,20 @@ class TestHookCli:
output = json.loads(result.output)
assert output["hookSpecificOutput"]["permissionDecision"] == "deny"
def test_remind_command_accepts_raw_control_characters_in_tool_input(self, tmp_path: Path):
"""CodeBuddy freeform tool input may contain unescaped control characters."""
stdin_json = (
'{"hook_event_name":"PreToolUse","session_id":"cli-codebuddy-raw-input",'
'"tool_name":"Edit","tool_input":"*** Begin Patch\n*** Add File: /tmp/x.txt\n+hi\n",'
'"permission_mode":"default"}'
)
runner = CliRunner()
with patch("serena.hooks.serena_home_dir", str(tmp_path)):
result = runner.invoke(hook_commands, ["remind", "--client", "codebuddy"], input=stdin_json)
assert result.exit_code == 0
assert result.output == ""
def test_remind_command_grok_emits_native_deny(self, tmp_path: Path):
"""The documented Grok remind CLI emits Grok-native deny JSON."""
runner = CliRunner()