-
Notifications
You must be signed in to change notification settings - Fork 0
chore: upgrade #1789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
chore: upgrade #1789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||
| # rtk-hook-version: 3 | ||||||||||||||||||||||
| # RTK auto-rewrite hook for Claude/Codex/Copilot PreToolUse shell commands. | ||||||||||||||||||||||
| # RTK auto-rewrite hook for Claude Code PreToolUse:Bash | ||||||||||||||||||||||
| # Transparently rewrites raw commands to their RTK equivalents. | ||||||||||||||||||||||
| # Uses `rtk rewrite` as single source of truth — no duplicate mapping logic here. | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
|
|
@@ -32,15 +32,7 @@ fi | |||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| INPUT=$(cat) | ||||||||||||||||||||||
| CMD=$(echo "$INPUT" | jq -r ' | ||||||||||||||||||||||
| .tool.input.command | ||||||||||||||||||||||
| // .tool_input.command | ||||||||||||||||||||||
| // (.toolArgs | if type == "object" then .command else empty end) | ||||||||||||||||||||||
| // (.toolArgs | if type == "string" then (fromjson? | .command) else empty end) | ||||||||||||||||||||||
| // .toolInput.command | ||||||||||||||||||||||
| // .command | ||||||||||||||||||||||
| // empty | ||||||||||||||||||||||
| ') | ||||||||||||||||||||||
| CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Parsing only Prompt for AI agents
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [ -z "$CMD" ]; then | ||||||||||||||||||||||
| _rtk_audit_log "skip:empty" "-" | ||||||||||||||||||||||
|
|
@@ -86,37 +78,11 @@ esac | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| _rtk_audit_log "rewrite" "$CMD" "$REWRITTEN" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Build the updated tool input with all original fields preserved, only command changed. | ||||||||||||||||||||||
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c ' | ||||||||||||||||||||||
| ( | ||||||||||||||||||||||
| .tool_input | ||||||||||||||||||||||
| // .tool.input | ||||||||||||||||||||||
| // .toolArgs | ||||||||||||||||||||||
| // .toolInput | ||||||||||||||||||||||
| // {} | ||||||||||||||||||||||
| ) | if type == "string" then (fromjson? // {}) else . end | ||||||||||||||||||||||
| ') | ||||||||||||||||||||||
| # Build the updated tool_input with all original fields preserved, only command changed. | ||||||||||||||||||||||
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input') | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd') | ||||||||||||||||||||||
| IS_COPILOT_INPUT=$(echo "$INPUT" | jq -r 'has("toolName") and has("toolArgs")') | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [ "$IS_COPILOT_INPUT" = "true" ]; then | ||||||||||||||||||||||
| if [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson modified "$UPDATED_INPUT" \ | ||||||||||||||||||||||
| '{ | ||||||||||||||||||||||
| "permissionDecision": "ask", | ||||||||||||||||||||||
| "modifiedArgs": $modified | ||||||||||||||||||||||
| }' | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson modified "$UPDATED_INPUT" \ | ||||||||||||||||||||||
| '{ | ||||||||||||||||||||||
| "permissionDecision": "allow", | ||||||||||||||||||||||
| "permissionDecisionReason": "RTK auto-rewrite", | ||||||||||||||||||||||
| "modifiedArgs": $modified | ||||||||||||||||||||||
| }' | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| elif [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
| if [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Removing the Copilot output path breaks integrations that expect Prompt for AI agents |
||||||||||||||||||||||
| # Ask: rewrite the command, omit permissionDecision so Claude Code prompts. | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson updated "$UPDATED_INPUT" \ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||
| # rtk-hook-version: 3 | ||||||||||||||||||||||
| # RTK auto-rewrite hook for Claude/Codex/Copilot PreToolUse shell commands. | ||||||||||||||||||||||
| # RTK auto-rewrite hook for Claude Code PreToolUse:Bash | ||||||||||||||||||||||
| # Transparently rewrites raw commands to their RTK equivalents. | ||||||||||||||||||||||
| # Uses `rtk rewrite` as single source of truth — no duplicate mapping logic here. | ||||||||||||||||||||||
| # | ||||||||||||||||||||||
|
|
@@ -32,15 +32,7 @@ fi | |||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| INPUT=$(cat) | ||||||||||||||||||||||
| CMD=$(echo "$INPUT" | jq -r ' | ||||||||||||||||||||||
| .tool.input.command | ||||||||||||||||||||||
| // .tool_input.command | ||||||||||||||||||||||
| // (.toolArgs | if type == "object" then .command else empty end) | ||||||||||||||||||||||
| // (.toolArgs | if type == "string" then (fromjson? | .command) else empty end) | ||||||||||||||||||||||
| // .toolInput.command | ||||||||||||||||||||||
| // .command | ||||||||||||||||||||||
| // empty | ||||||||||||||||||||||
| ') | ||||||||||||||||||||||
| CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This simplified command extraction logic removes support for multiple input formats used by GitHub Copilot and other integrations (e.g., .toolArgs, .tool.input, and stringified JSON in toolArgs). This regression will cause the hook to skip rewrites for these platforms and will break existing tests in spec/codex_rtk_rewrite_spec.sh (lines 67-81). To maintain robustness and consistency, ensure the logic follows established patterns for Nix-extracted scripts and uses unique delimiters with read and IFS for any command output parsing. References
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This now only reads Prompt for AI agents
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot integration is silently broken by this sync. This Codex copy is also what gets installed as Copilot's hook ( |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [ -z "$CMD" ]; then | ||||||||||||||||||||||
| _rtk_audit_log "skip:empty" "-" | ||||||||||||||||||||||
|
|
@@ -86,37 +78,11 @@ esac | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| _rtk_audit_log "rewrite" "$CMD" "$REWRITTEN" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Build the updated tool input with all original fields preserved, only command changed. | ||||||||||||||||||||||
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c ' | ||||||||||||||||||||||
| ( | ||||||||||||||||||||||
| .tool_input | ||||||||||||||||||||||
| // .tool.input | ||||||||||||||||||||||
| // .toolArgs | ||||||||||||||||||||||
| // .toolInput | ||||||||||||||||||||||
| // {} | ||||||||||||||||||||||
| ) | if type == "string" then (fromjson? // {}) else . end | ||||||||||||||||||||||
| ') | ||||||||||||||||||||||
| # Build the updated tool_input with all original fields preserved, only command changed. | ||||||||||||||||||||||
| ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input') | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd') | ||||||||||||||||||||||
| IS_COPILOT_INPUT=$(echo "$INPUT" | jq -r 'has("toolName") and has("toolArgs")') | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [ "$IS_COPILOT_INPUT" = "true" ]; then | ||||||||||||||||||||||
| if [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson modified "$UPDATED_INPUT" \ | ||||||||||||||||||||||
| '{ | ||||||||||||||||||||||
| "permissionDecision": "ask", | ||||||||||||||||||||||
| "modifiedArgs": $modified | ||||||||||||||||||||||
| }' | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson modified "$UPDATED_INPUT" \ | ||||||||||||||||||||||
| '{ | ||||||||||||||||||||||
| "permissionDecision": "allow", | ||||||||||||||||||||||
| "permissionDecisionReason": "RTK auto-rewrite", | ||||||||||||||||||||||
| "modifiedArgs": $modified | ||||||||||||||||||||||
| }' | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| elif [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
| if [ "$EXIT_CODE" -eq 3 ]; then | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Removing the Copilot output branch changes the response contract and drops Prompt for AI agents |
||||||||||||||||||||||
| # Ask: rewrite the command, omit permissionDecision so Claude Code prompts. | ||||||||||||||||||||||
| jq -n \ | ||||||||||||||||||||||
| --argjson updated "$UPDATED_INPUT" \ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simplified command extraction logic removes support for multiple input formats used by GitHub Copilot and other integrations (e.g., .toolArgs, .tool.input, and stringified JSON in toolArgs). This regression will cause the hook to skip rewrites for these platforms and will break existing tests in spec/rtk_rewrite_spec.sh (lines 113-128). To maintain robustness and consistency, ensure the logic follows established patterns for Nix-extracted scripts and uses unique delimiters with read and IFS for any command output parsing.
References