Skip to content

Commit 86a4d6d

Browse files
committed
fix(guard): parse Claude fallback approval answers
Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
1 parent dbe4806 commit 86a4d6d

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/codex_plugin_scanner/guard/cli/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,7 +2155,9 @@ def _claude_guard_approval_answer(payload: dict[str, object]) -> str | None:
21552155
if isinstance(response, dict):
21562156
answers = response.get("answers")
21572157
if isinstance(answers, dict):
2158-
answer_text = " ".join(str(answer) for answer in answers.values() if str(answer).strip())
2158+
joined_answers = " ".join(str(answer) for answer in answers.values() if str(answer).strip())
2159+
if joined_answers:
2160+
answer_text = joined_answers
21592161
if answer_text is None:
21602162
for key in ("answer", "selected_answer", "selected", "choice", "value", "label"):
21612163
value = response.get(key)

tests/test_guard_runtime.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,6 +4468,30 @@ def test_guard_hook_claude_ask_user_question_without_answer_does_not_persist_blo
44684468
assert policies == []
44694469

44704470

4471+
def test_guard_hook_claude_ask_user_question_empty_answers_uses_explicit_fallback_answer():
4472+
payload = {
4473+
"hook_event_name": "PostToolUse",
4474+
"tool_name": "AskUserQuestion",
4475+
"tool_response": {
4476+
"questions": [
4477+
{
4478+
"header": "HOL Guard",
4479+
"question": "HOL Guard intercepted this sensitive action. What should Claude do?",
4480+
"options": [
4481+
{"label": "Allow once"},
4482+
{"label": "Allow during this session"},
4483+
{"label": "Keep blocked"},
4484+
],
4485+
}
4486+
],
4487+
"answers": {},
4488+
"selected_answer": "Allow once",
4489+
},
4490+
}
4491+
4492+
assert guard_commands_module._claude_guard_approval_answer(payload) == "allow"
4493+
4494+
44714495
def test_guard_hook_claude_alias_reuses_native_approval_policy_with_canonical_harness(tmp_path, capsys, monkeypatch):
44724496
home_dir = tmp_path / "home"
44734497
workspace_dir = tmp_path / "workspace"

0 commit comments

Comments
 (0)