Repository navigation
fix(hook): detect Copilot CLI shell tool on Windows (adopt upstream #3179) - #63
Conversation
…ites Copilot CLI 1.0.66+ treats a missing permissionDecision field as "always prompt", forcing a permission dialog on every RTK-rewritten command. For simple (non-compound) commands, emit permissionDecision: "allow" so Copilot auto-accepts the rewrite. Compound commands (containing newlines, background &, subshells, or pipes) still omit the field, preserving the security guarantee that hidden dangerous segments trigger a manual prompt. Uses split_for_permissions() to detect compound commands — if the command decomposes into more than one segment, it's not safe to auto-allow. Closes rtk-ai#3037 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Change AskRewrite(String) to AskRewrite { rewritten, explicit } so the
Copilot path only auto-allows when the user didn't explicitly configure
"ask" for a command. Addresses KuSh's review feedback on rtk-ai#3149.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ecision fix(hooks): emit permissionDecision allow for simple Copilot CLI rewrites
Copilot CLI names its shell tool "powershell" on Windows, so detect_format
only ever matched "bash" and fell through to PassThrough. The native
CopilotCli branch — the one returning modifiedArgs without a permissionDecision
— was therefore unreachable on Windows, leaving only the Claude-compat
PreToolUse entry to answer, which emits "ask" and prompts on every command.
Verified against a live Copilot CLI 1.0.73 session on Windows 11: the payload
delivered is {"toolName":"powershell","toolArgs":"{\"command\":\"...\"}"} —
toolArgs is already the JSON-encoded string RTK expects, only toolName differed.
Refs rtk-ai#3178
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Pre-merge review round (Standards + Spec + security-guardian, parallel sub-agents)Standards — no hard violations. Spec (issue #59) — all requirements verified met: powershell reaches Security — no new escalation path. The tool name only selects payload shape; the command still flows through the same Outcome: no changes required; merging as-is. Quality gate re-confirmed on this branch: fmt clean, clippy zero warnings, 2538 unit tests + integration suites all passing. |
Adopts upstream rtk-ai/rtk#3179 by @romain-cureau. Closes #59.
What
detect_formatinsrc/hooks/hook_cmd.rsonly matchedtoolName == "bash"in the camelCase Copilot CLI branch. Copilot CLI names its shell toolpowershellon Windows, so every Windows Copilot payload fell through toPassThroughand the nativeCopilotClibranch was unreachable. The fix broadens the match to"bash" | "powershell"and addstest_detect_copilot_cli_powershell.Commits
673ad19fix(hook): detect Copilot CLI shell tool on Windows9637b25)No amendments needed — the upstream commit includes the test and covers the fix completely.
Cherry-pick fidelity: content byte-identical to upstream; only hunk offsets shifted (+1/+3 lines) because today's sync merged the rtk-ai#3149 fix into the same file above it. Verified with
diff <(git show pr-3179 --format=) <(git show HEAD --format=)— onlyindex/@@lines differ.Repro
Payload from the upstream PR's live capture (Copilot CLI 1.0.73 / Windows 11), piped to
rtk hook copilot.Before (develop @
3c77b72):After (this branch):
The rtk-ai#3037 dependency — decided
Issue #59 required an explicit decision on upstream rtk-ai#3037 (the "residual prompt" caveat: rtk-ai#3179 alone would reach the native path but still emit no
permissionDecision, so the Claude-compatPreToolUseentry kept prompting). Resolved: no residual gap. Upstream rtk-ai#3037 is a closed issue, fixed by rtk-ai#3149 (permissionDecision: allowfor simple Copilot CLI rewrites), and rtk-ai#3149 landed in our tree via today's sync (84aa4d6, merged in3c77b72). The repro-after shows the full outcome:modifiedArgswithpermissionDecision: allow— no prompt for simple commands.Deliberately not fixed
run_in_terminal— upstream fix(copilot): support IDE terminal hooks rtk-ai/rtk#3093, fix(hook): support copilot ide terminal tool rtk-ai/rtk#2574, fix(hook): detect JetBrains run_in_terminal in Copilot hook rtk-ai/rtk#2684, fix(hooks): recognize run_in_terminal for VS Code Copilot Chat rtk-ai/rtk#1800): different dispatch arm (snake_casetool_namebranch), separate cluster, not touched.askfrom the AskRewrite path — intended behavior per fix(hooks): emit permissionDecision allow for simple Copilot CLI rewrites rtk-ai/rtk#3149/0df6929, not a gap.Upstream sweep (
gh search prs --repo rtk-ai/rtk --state open "copilot", plus "copilot powershell") found no competing fix for this branch; treated as "probably none", not proof.Quality gate
Fork CI never runs; local gate is the merge gate. Windows ARM64, x64 host toolchain:
🤖 Generated with Claude Code