Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76d6508f9e |
No files matched your search
@@ -83,24 +83,28 @@ ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
|
||||
UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd')
|
||||
|
||||
if [ "$EXIT_CODE" -eq 3 ]; then
|
||||
# Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
|
||||
# Ask/Default: rewrite the command, include permissionDecision "ask"
|
||||
# so Claude Code prompts the user for confirmation.
|
||||
# In bypassPermissions mode this is ignored (command still rewrites correctly).
|
||||
jq -n \
|
||||
--argjson updated "$UPDATED_INPUT" \
|
||||
'{
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PreToolUse",
|
||||
"permissionDecision": "ask",
|
||||
"permissionDecisionReason": "RTK: no explicit allow rule",
|
||||
"updatedInput": $updated
|
||||
}
|
||||
}'
|
||||
else
|
||||
# Allow: output the rewrite instruction in Claude Code hook format.
|
||||
# Allow (explicit rule matched): rewrite without permissionDecision.
|
||||
# Omitting permissionDecision = allow by default, AND works correctly
|
||||
# in bypassPermissions mode (updatedInput is not discarded). Fixes #893.
|
||||
jq -n \
|
||||
--argjson updated "$UPDATED_INPUT" \
|
||||
'{
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PreToolUse",
|
||||
"permissionDecision": "allow",
|
||||
"permissionDecisionReason": "RTK auto-rewrite",
|
||||
"updatedInput": $updated
|
||||
}
|
||||
}'
|
||||
|
||||
+18
-14
@@ -119,21 +119,25 @@ fn handle_vscode(cmd: &str) -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Allow (explicit rule matched): auto-allow the rewritten command.
|
||||
// Ask/Default (no allow rule matched): rewrite but let the host tool prompt.
|
||||
let decision = match verdict {
|
||||
PermissionVerdict::Allow => "allow",
|
||||
_ => "ask",
|
||||
// Allow (explicit rule matched): omit permissionDecision so updatedInput
|
||||
// works in bypassPermissions mode (#893). Omitting = allow by default.
|
||||
// Ask/Default: include permissionDecision "ask" to prompt the user.
|
||||
let output = match verdict {
|
||||
PermissionVerdict::Allow => json!({
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": PRE_TOOL_USE_KEY,
|
||||
"updatedInput": { "command": rewritten }
|
||||
}
|
||||
}),
|
||||
_ => json!({
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": PRE_TOOL_USE_KEY,
|
||||
"permissionDecision": "ask",
|
||||
"permissionDecisionReason": "RTK: no explicit allow rule",
|
||||
"updatedInput": { "command": rewritten }
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
let output = json!({
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": PRE_TOOL_USE_KEY,
|
||||
"permissionDecision": decision,
|
||||
"permissionDecisionReason": "RTK auto-rewrite",
|
||||
"updatedInput": { "command": rewritten }
|
||||
}
|
||||
});
|
||||
println!("{output}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user