From 627ad7d9a561acd82105e477fb2bd3ee230d3e6a Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 1 Feb 2026 13:43:47 -0700 Subject: [PATCH] fix: extract denied commands from correct JSON path (Issue #143) The permission_denials array from Claude CLI has commands nested under tool_input.command, not directly as .command: Before: jq '[.permission_denials[].command]' After: jq '[.permission_denials[].tool_input.command]' This fixes the "Permission denied for N command(s)" message to actually display the denied commands instead of showing empty/unknown. Also updated test fixture to match real Claude CLI output structure. --- lib/response_analyzer.sh | 3 ++- tests/unit/test_json_parsing.bats | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/response_analyzer.sh b/lib/response_analyzer.sh index 7e90eb0..ffb2579 100644 --- a/lib/response_analyzer.sh +++ b/lib/response_analyzer.sh @@ -189,9 +189,10 @@ parse_json_response() { fi # Extract denied commands for logging/display + # Note: Commands are nested under tool_input.command in the permission_denials array local denied_commands_json="[]" if [[ $permission_denial_count -gt 0 ]]; then - denied_commands_json=$(jq -r '[.permission_denials[].command // empty]' "$output_file" 2>/dev/null || echo "[]") + denied_commands_json=$(jq -r '[.permission_denials[].tool_input.command // empty]' "$output_file" 2>/dev/null || echo "[]") fi # Normalize values diff --git a/tests/unit/test_json_parsing.bats b/tests/unit/test_json_parsing.bats index 6d71cd2..c94b77a 100644 --- a/tests/unit/test_json_parsing.bats +++ b/tests/unit/test_json_parsing.bats @@ -982,12 +982,13 @@ EOF @test "parse_json_response extracts denied_commands list" { local output_file="$LOG_DIR/test_output.log" + # Use real Claude CLI output structure with tool_input.command cat > "$output_file" << 'EOF' { "result": "Permission denied for npm install", "sessionId": "session-extract-cmds", "permission_denials": [ - {"tool": "Bash", "command": "npm install express", "reason": "Not allowed"} + {"tool_name": "Bash", "tool_use_id": "toolu_123", "tool_input": {"command": "npm install express"}} ] } EOF @@ -998,7 +999,7 @@ EOF local result_file="$RALPH_DIR/.json_parse_result" [[ -f "$result_file" ]] - # Should extract the denied commands + # Should extract the denied commands from tool_input.command local denied_cmds=$(jq -r '.denied_commands[0]' "$result_file") [[ "$denied_cmds" == *"npm install"* ]] }