Skip to content

fix(hook): detect Copilot CLI shell tool on Windows (adopt upstream #3179) - #63

Merged
kylehgc merged 5 commits into
developfrom
fix/copilot-cli-powershell-tool
Jul 25, 2026
Merged

kylehgc merged 5 commits into
developfrom
fix/copilot-cli-powershell-tool

Conversation

@kylehgc

@kylehgc kylehgc commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Adopts upstream rtk-ai/rtk#3179 by @romain-cureau. Closes #59.

What

detect_format in src/hooks/hook_cmd.rs only matched toolName == "bash" in the camelCase Copilot CLI branch. Copilot CLI names its shell tool powershell on Windows, so every Windows Copilot payload fell through to PassThrough and the native CopilotCli branch was unreachable. The fix broadens the match to "bash" | "powershell" and adds test_detect_copilot_cli_powershell.

Commits

Commit Author Kind
673ad19 fix(hook): detect Copilot CLI shell tool on Windows Romain Cureau (cherry-picked from upstream 9637b25) Adoption

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=) — only index/@@ 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):

--- powershell toolName (Windows Copilot CLI payload) ---
exit=0 (empty output above = PassThrough = bug reproduced)
--- bash toolName (control, should respond) ---
{"permissionDecisionReason":"RTK auto-rewrite","modifiedArgs":{"command":"rtk git status"},"permissionDecision":"allow"}
exit=0

After (this branch):

--- powershell toolName (Windows Copilot CLI payload) ---
{"permissionDecisionReason":"RTK auto-rewrite","modifiedArgs":{"command":"rtk git status"},"permissionDecision":"allow"}
exit=0
--- bash toolName (control, unchanged) ---
{"permissionDecisionReason":"RTK auto-rewrite","modifiedArgs":{"command":"rtk git status"},"permissionDecision":"allow"}
exit=0
--- non-shell toolName (must stay PassThrough) ---
exit=0 (empty above = still PassThrough, no regression)

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-compat PreToolUse entry kept prompting). Resolved: no residual gap. Upstream rtk-ai#3037 is a closed issue, fixed by rtk-ai#3149 (permissionDecision: allow for simple Copilot CLI rewrites), and rtk-ai#3149 landed in our tree via today's sync (84aa4d6, merged in 3c77b72). The repro-after shows the full outcome: modifiedArgs with permissionDecision: allow — no prompt for simple commands.

Deliberately not fixed

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:

cargo fmt --all      → clean
cargo clippy --all-targets → zero warnings
cargo test --all     → 2538 passed; 0 failed; 8 ignored (unit) + integration suites all ok
new test hooks::hook_cmd::tests::test_detect_copilot_cli_powershell ... ok

🤖 Generated with Claude Code

guyoron1 and others added 5 commits July 22, 2026 15:37
…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]>
@kylehgc

kylehgc commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

Pre-merge review round (Standards + Spec + security-guardian, parallel sub-agents)

Standards — no hard violations. matches! broadening mirrors the sibling snake_case arm; test follows the inline-fixture convention. One judgement call: test_detect_copilot_cli_powershell hand-rolls its payload instead of parameterizing the existing copilot_cli_input helper. Deliberately not taken — it would break byte-fidelity with upstream 9637b25 for a two-line test refactor; revisit if a third shell name (pwsh) ever appears.

Spec (issue #59) — all requirements verified met: powershell reaches HookFormat::CopilotCli; snake_case arm untouched; authorship preserved (Romain Cureau, no amendments needed); upstream's test present verbatim; no scope creep (diff is exactly upstream rtk-ai#3179). The required explicit rtk-ai#3037 decision is stated in the PR body (no residual gap — rtk-ai#3149 already merged via the 2026-07-25 sync). Nit: the cherry-picked test comment's "prompts on every command" claim is partially stale in fork context post-rtk-ai#3149; left verbatim to preserve upstream fidelity.

Security — no new escalation path. The tool name only selects payload shape; the command still flows through the same decide_hook_action → permissions::check_command_for → contains_unattestable_construct gate, and no tool-name-conditional branch or quoting exists downstream. The permissionDecision: allow fast path stays gated on split_for_permissions(cmd).len() <= 1, and every PowerShell multi-command construct (;, |, &&, &, (, `, $() is already a boundary or defer in the lexer. One pre-existing divergence flagged for follow-up (not introduced here, not exploitable): contains_substitution treats \ as a bash escape and skips the next byte, so a Windows path like C:\tmp\$(x) can slip the substitution check — it still cannot auto-allow because ( splits the command into >1 segment.

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.

@kylehgc
kylehgc merged commit 949ed6d into develop Jul 25, 2026
@kylehgc
kylehgc deleted the fix/copilot-cli-powershell-tool branch July 25, 2026 20:15
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.

Adopt upstream #3179: hook - detect Copilot CLI powershell tool so Windows Copilot traffic hits the hook

4 participants