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.
This commit is contained in:
parent
2e6026aced
commit
627ad7d9a5
2 changed files with 5 additions and 3 deletions
|
|
@ -189,9 +189,10 @@ parse_json_response() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract denied commands for logging/display
|
# Extract denied commands for logging/display
|
||||||
|
# Note: Commands are nested under tool_input.command in the permission_denials array
|
||||||
local denied_commands_json="[]"
|
local denied_commands_json="[]"
|
||||||
if [[ $permission_denial_count -gt 0 ]]; then
|
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
|
fi
|
||||||
|
|
||||||
# Normalize values
|
# Normalize values
|
||||||
|
|
|
||||||
|
|
@ -982,12 +982,13 @@ EOF
|
||||||
@test "parse_json_response extracts denied_commands list" {
|
@test "parse_json_response extracts denied_commands list" {
|
||||||
local output_file="$LOG_DIR/test_output.log"
|
local output_file="$LOG_DIR/test_output.log"
|
||||||
|
|
||||||
|
# Use real Claude CLI output structure with tool_input.command
|
||||||
cat > "$output_file" << 'EOF'
|
cat > "$output_file" << 'EOF'
|
||||||
{
|
{
|
||||||
"result": "Permission denied for npm install",
|
"result": "Permission denied for npm install",
|
||||||
"sessionId": "session-extract-cmds",
|
"sessionId": "session-extract-cmds",
|
||||||
"permission_denials": [
|
"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
|
EOF
|
||||||
|
|
@ -998,7 +999,7 @@ EOF
|
||||||
local result_file="$RALPH_DIR/.json_parse_result"
|
local result_file="$RALPH_DIR/.json_parse_result"
|
||||||
[[ -f "$result_file" ]]
|
[[ -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")
|
local denied_cmds=$(jq -r '.denied_commands[0]' "$result_file")
|
||||||
[[ "$denied_cmds" == *"npm install"* ]]
|
[[ "$denied_cmds" == *"npm install"* ]]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue