Skip to content

chore: upgrade#1789

Open
shunkakinoki wants to merge 1 commit into
mainfrom
chore/upgrade
Open

chore: upgrade#1789
shunkakinoki wants to merge 1 commit into
mainfrom
chore/upgrade

Conversation

@shunkakinoki
Copy link
Copy Markdown
Owner

@shunkakinoki shunkakinoki commented May 15, 2026

Automated upgrade

@shunkakinoki shunkakinoki enabled auto-merge (squash) May 15, 2026 13:38
@indent
Copy link
Copy Markdown
Contributor

indent Bot commented May 15, 2026

PR Summary

Automated re-sync of config/{claude,codex}/hooks/rtk-rewrite.sh from upstream rtk-ai/rtk via scripts/sync-rtk-rewrite.sh. Upstream narrowed the hook's scope to Claude Code's PreToolUse:Bash only, so this PR drops the multi-platform input parsing and Copilot-shaped output that #1788 had added locally one PR ago, without updating the downstream Copilot wiring or test specs.

  • Input parsing collapses from 7 fallback selectors (.tool.input, .tool_input, .toolArgs object/string, .toolInput, .command) to just .tool_input.command // empty.
  • ORIGINAL_INPUT simplified to read .tool_input directly (no more string→fromjson coercion or {} fallback).
  • Removes the IS_COPILOT_INPUT branch and the {permissionDecision, modifiedArgs} output shape; the script now always emits the Claude-Code hookSpecificOutput envelope.
  • Header docstring narrowed from "Claude/Codex/Copilot PreToolUse shell commands" to "Claude Code PreToolUse:Bash".
  • Claude and Codex copies remain byte-identical (preserves the spec/sync_rtk_rewrite_spec.sh invariant).

Issues

2 potential issues found:

  • shell-check CI is red because the sync didn't update the Copilot tests landed in feat: add Copilot and Codex hook parity #1788spec/rtk_rewrite_spec.sh:113-128 and spec/codex_rtk_rewrite_spec.sh:67-81 still assert that .modifiedArgs.command is populated for {toolName, toolArgs} payloads, but the rewritten hook no longer emits modifiedArgs, producing 4 failures in shell-test. Update or delete those specs as part of this PR (paired with the Copilot wiring decision in the other issue) so the required check goes green. → Autofix
  • Copilot's RTK rewrite hook is silently broken after this sync — config/copilot/default.nix still installs config/codex/hooks/rtk-rewrite.sh as ~/.copilot/hooks/rtk-rewrite.sh and config/copilot/config.json still calls it, but the new script only reads .tool_input.command so Copilot's {toolName, toolArgs} payload yields an empty CMD and no-ops. Either restore the Copilot input/output branches in the codex copy, or remove the Copilot wiring under config/copilot/ and the Copilot test cases together so the sync stays self-consistent. → Autofix

CI Checks

Same 4 shellspec failures as on the previous SHA — shell-test is red because the Copilot modifiedArgs cases added in #1788 still exist in the specs but the rewritten hook no longer emits that output. The docker/nix/e2e failures from the previous push appear to have cleared after the rebase onto fresher main; the only remaining blocker is the Copilot regression already flagged in this PR's issues.

Failing shell-check / shell-test→ Autofix
  • 4 shellspec failures, identical to the pre-rebase run: spec/rtk_rewrite_spec.sh:113,121 and spec/codex_rtk_rewrite_spec.sh:67,75 — the rewrites Copilot {object,string} toolArgs with modifiedArgs output cases. The hook no longer emits .modifiedArgs.command, so jq -r '.modifiedArgs.command' returns empty and the output should include 'rtk' assertion fails. Tied to the 'Copilot's RTK rewrite hook is silently broken' issue — same root cause, same fix paths.

⚡ Autofix All

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9abcf681-73ef-4721-a544-9a3a30486968

📥 Commits

Reviewing files that changed from the base of the PR and between 9194093 and 3c9319a.

📒 Files selected for processing (2)
  • config/claude/hooks/rtk-rewrite.sh
  • config/codex/hooks/rtk-rewrite.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/claude/hooks/rtk-rewrite.sh
  • config/codex/hooks/rtk-rewrite.sh

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Standardized how tool inputs are interpreted and unified rewrite output formatting across pre-tool hooks for more consistent behavior.
    • Clarified prompting flow: certain rewrites now trigger an explicit "ask for clarification" path, while others are returned as allowed with an explanatory reason.
    • Removed special-case branching for a previously supported tool-specific input shape, simplifying overall handling.

Walkthrough

Two RTK auto-rewrite hook scripts (config/claude/hooks/rtk-rewrite.sh and config/codex/hooks/rtk-rewrite.sh) are refactored to extract the command only from .tool_input.command, remove historical fallback parsing, construct ORIGINAL_INPUT from .tool_input, update .command with the rewrite result, and unify output branching to depend solely on EXIT_CODE.

Changes

RTK Hook Unified Input/Output Refactoring

Layer / File(s) Summary
Hook identification and scope clarification
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Header comments updated to identify the scripts as the RTK auto-rewrite hook for "Claude Code PreToolUse:Bash".
Command input extraction simplification
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Both hooks now extract CMD via a single jq lookup of .tool_input.command, removing multi-path fallback logic for other input shapes.
Unified output payload and branching
config/claude/hooks/rtk-rewrite.sh, config/codex/hooks/rtk-rewrite.sh
Rewritten payloads now set ORIGINAL_INPUT from .tool_input, overwrite only the command field with the rewritten value, and choose output format based solely on EXIT_CODE, removing prior Copilot-specific branching and alternate permissionDecision/modifiedArgs structures.

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels: dependencies

"I nibbled old fallbacks down to none,
One jq hop, two hooks, and now it's done.
Commands flow tidy, outputs aligned—
A rabbit's small refactor, neat and kind. 🐇"

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'chore: upgrade' is vague and generic, failing to convey meaningful information about the specific changes made to the RTK rewrite hooks. Replace with a more descriptive title that captures the main changes, such as 'chore: simplify RTK rewrite hooks to use tool_input.command only' or similar.
Description check ❓ Inconclusive The description 'Automated upgrade' is extremely vague and generic, providing no meaningful information about what was changed or why. Provide a more detailed description explaining the changes to the RTK rewrite hooks, such as simplifications to command extraction and payload construction.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/upgrade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the rtk-rewrite.sh hooks for Claude and Codex to focus on Claude Code PreToolUse:Bash. The changes significantly simplify the command extraction and input processing logic by removing support for multiple input formats (such as .toolArgs and .tool.input) and eliminating GitHub Copilot-specific output structures. Feedback highlights that these changes introduce regressions, including data loss for metadata in certain input structures and broken compatibility with GitHub Copilot integrations.

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and read with a matching IFS. This is safer than splitting by spaces with cut, especially when data fields might contain spaces.
  2. Maintain consistency with established patterns for writing scripts that are extracted from Nix expressions, even if it involves suppressing linter warnings like ShellCheck SC2024.

) | 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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Restricting ORIGINAL_INPUT to only the .tool_input object leads to data loss for other supported input structures. Previously, the script ensured that all original fields (such as timeout or other metadata) were preserved regardless of the input format.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of the IS_COPILOT_INPUT check and the specific modifiedArgs output format breaks compatibility with GitHub Copilot. Copilot requires this specific JSON structure to accept and execute the rewritten command; without it, the rewrite functionality will be ignored by the Copilot client.

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. To robustly parse command output in shell scripts, use a unique delimiter (e.g., tab) in the format string and read with a matching IFS. This is safer than splitting by spaces with cut, especially when data fields might contain spaces.
  2. Maintain consistency with established patterns for writing scripts that are extracted from Nix expressions, even if it involves suppressing linter warnings like ShellCheck SC2024.

) | 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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Restricting ORIGINAL_INPUT to only the .tool_input object leads to data loss for other supported input structures. Previously, the script ensured that all original fields (such as timeout or other metadata) were preserved regardless of the input format.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of the IS_COPILOT_INPUT check and the specific modifiedArgs output format breaks compatibility with GitHub Copilot. Copilot requires this specific JSON structure to accept and execute the rewritten command; without it, the rewrite functionality will be ignored by the Copilot client.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="config/claude/hooks/rtk-rewrite.sh">

<violation number="1" location="config/claude/hooks/rtk-rewrite.sh:35">
P1: Parsing only `.tool_input.command` breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.</violation>

<violation number="2" location="config/claude/hooks/rtk-rewrite.sh:85">
P1: Removing the Copilot output path breaks integrations that expect `modifiedArgs` responses instead of Claude `hookSpecificOutput`.</violation>
</file>

<file name="config/codex/hooks/rtk-rewrite.sh">

<violation number="1" location="config/codex/hooks/rtk-rewrite.sh:35">
P1: This now only reads `.tool_input.command`, so valid non-`tool_input` payloads are skipped and never rewritten.</violation>

<violation number="2" location="config/codex/hooks/rtk-rewrite.sh:85">
P1: Removing the Copilot output branch changes the response contract and drops `modifiedArgs`, breaking codex/copilot-style hook consumers.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Removing the Copilot output path breaks integrations that expect modifiedArgs responses instead of Claude hookSpecificOutput.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/claude/hooks/rtk-rewrite.sh, line 85:

<comment>Removing the Copilot output path breaks integrations that expect `modifiedArgs` responses instead of Claude `hookSpecificOutput`.</comment>

<file context>
@@ -86,37 +78,11 @@ esac
-      }'
-  fi
-elif [ "$EXIT_CODE" -eq 3 ]; then
+if [ "$EXIT_CODE" -eq 3 ]; then
   # Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
   jq -n \
</file context>

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Parsing only .tool_input.command breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/claude/hooks/rtk-rewrite.sh, line 35:

<comment>Parsing only `.tool_input.command` breaks non-Claude payload formats that this hook currently supports, causing command rewrite checks to be skipped.</comment>

<file context>
@@ -32,15 +32,7 @@ fi
-  // .command
-  // empty
-')
+CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
 
 if [ -z "$CMD" ]; then
</file context>
Suggested change
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
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
')

}'
fi
elif [ "$EXIT_CODE" -eq 3 ]; then
if [ "$EXIT_CODE" -eq 3 ]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Removing the Copilot output branch changes the response contract and drops modifiedArgs, breaking codex/copilot-style hook consumers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/codex/hooks/rtk-rewrite.sh, line 85:

<comment>Removing the Copilot output branch changes the response contract and drops `modifiedArgs`, breaking codex/copilot-style hook consumers.</comment>

<file context>
@@ -86,37 +78,11 @@ esac
-      }'
-  fi
-elif [ "$EXIT_CODE" -eq 3 ]; then
+if [ "$EXIT_CODE" -eq 3 ]; then
   # Ask: rewrite the command, omit permissionDecision so Claude Code prompts.
   jq -n \
</file context>

// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This now only reads .tool_input.command, so valid non-tool_input payloads are skipped and never rewritten.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/codex/hooks/rtk-rewrite.sh, line 35:

<comment>This now only reads `.tool_input.command`, so valid non-`tool_input` payloads are skipped and never rewritten.</comment>

<file context>
@@ -32,15 +32,7 @@ fi
-  // .command
-  // empty
-')
+CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
 
 if [ -z "$CMD" ]; then
</file context>
Suggested change
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
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
')

@shunkakinoki shunkakinoki force-pushed the chore/upgrade branch 2 times, most recently from 417c0f7 to 9194093 Compare May 16, 2026 05:57
// .command
// empty
')
CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 (config/copilot/default.nix sets home.file.".copilot/hooks/rtk-rewrite.sh".source = ../codex/hooks/rtk-rewrite.sh, and config/copilot/config.json calls $HOME/.copilot/hooks/rtk-rewrite.sh in its preToolUse array). Copilot CLI sends {"toolName":"shell","toolArgs":{"command":"..."}} (or a stringified JSON variant), but with this PR CMD=$(echo "$INPUT" | jq -r '.tool_input.command // empty') returns empty for those payloads, so the hook falls through the empty-command guard and never rewrites — no error, just a silent no-op for every Copilot Bash invocation. The IS_COPILOT_INPUT/modifiedArgs output branch removed at line 85 below compounds the issue: even if CMD were extracted, Copilot expects modifiedArgs, not Claude's hookSpecificOutput. This regresses the Copilot parity work from #1788. Either re-introduce both branches here (and in the Claude copy, to keep spec/sync_rtk_rewrite_spec.sh's byte-identical invariant) — possibly with a comment to prevent the next scripts/sync-rtk-rewrite.sh run from clobbering it again — or remove the Copilot wiring (config/copilot/config.json entry + config/copilot/default.nix symlink) and the corresponding Copilot specs together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant