Repository navigation
fix(hook): detect Copilot CLI shell tool on Windows - #3179
Conversation
fix(hook): detect Copilot CLI shell tool on Windows (adopt upstream rtk-ai#3179)
There was a problem hiding this comment.
Hi @romain-cureau, thanks for your contribution, LGTM apart from one minor nitpick!
|
Thanks for tracking this down — since you've got Copilot CLI running on Windows already, could you help confirm something that affects whether this stays needed long-term? Right now Question: on your Windows setup, was the other hook ( Asking because #3212 removes the camelCase registration entirely in favor of the PascalCase one — if that one already works standalone on Windows, this fix's code path becomes legacy-only once #3212 lands and someone re-runs |
…owershell GitHub's hooks reference normalizes bash/powershell to tool_name "Bash" for PascalCase PreToolUse payloads, so the schema rtk init --copilot now exclusively registers already handles Copilot CLI on Windows via the existing "Bash" match. Document that the camelCase toolName "powershell" case (#3178/#3179) is transition-only, and add a regression test making the Windows-coverage reasoning explicit.
9637b25 to
7ab299c
Compare
|
@KuSh nitpick addressed — @pszymkowiak — yes, and I tested it rather than inferring it. The PascalCase hook was already firing and being honored on Windows, in parallel with the ignored camelCase one. Two pieces of evidence, both from Copilot CLI 1.0.73 on Windows 11. 1. It receives the call. Both entries fire for the same tool call; the payloads differ exactly as you describe: // camelCase preToolUse — toolName is the real Windows tool
{"sessionId":"...","cwd":"C:\\Windows\\System32",
"toolName":"powershell","toolArgs":"{\"command\":\"rtk gain\",...}"}
// PascalCase PreToolUse — same session, remapped to "Bash"
{"hook_event_name":"PreToolUse","session_id":"...","cwd":"C:\\Windows\\System32",
"tool_name":"Bash","tool_input":{"command":"git status --short"}}2. Its // hook sees: echo PROBE_INPUT_5521
// hook returns: {"hookSpecificOutput":{...,"permissionDecision":"allow",
// "updatedInput":{"command":"echo REWRITE_APPLIED_9137"}}}Session output was Correction to my own issue text: I wrote in #3178 that the unreachable native path "explains the Windows limitation documented in the README" and cross-posted that on #2424. That was wrong for Copilot CLI and I've retracted it there — the rewrite does happen on Windows, via the Claude-compat entry. Whatever #2424 is hitting is something else. Sorry for the noise. So yes: once #3212 lands and users re-run Test plan status unchanged and worth restating: |
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]>
7ab299c to
10ca886
Compare
|
Retracting my earlier "test plan not run" caveat — I installed a Rust toolchain and ran the CI commands locally. Pushed as
The 16 failures are all in # origin/develop, not a line of this PR applied
$ cargo test --bin rtk core::stream
test result: FAILED. 18 passed; 16 failed; ...
# this branch
$ cargo test --bin rtk core::stream
test result: FAILED. 18 passed; 16 failed; ...Identical, so The security-lint job's Environment: rustc 1.97.1, stable-x86_64-pc-windows-msvc, Windows 11. |
…owershell Contributor testing on Windows 11 with Copilot CLI 1.0.73 (#3179) confirmed Copilot CLI remaps its native bash/powershell shell tool to tool_name: "Bash" under the PascalCase PreToolUse schema, and that its updatedInput is honored end-to-end there. Since rtk init --copilot now only registers that schema, Windows already works standalone through it — the camelCase toolName "powershell" case (#3178/#3179) becomes legacy-only, relevant solely to un-upgraded installs. Document that on both HookFormat variants. Also fixes a HookDecision::AskRewrite struct-pattern leftover in copilot_ide_response_from_decision (added by #3093, merged into develop after this branch's own struct-to-tuple AskRewrite refactor), surfaced as a compile error by rebasing onto develop to pick up #3179.
Summary
detect_formatmatched the native Copilot CLI payload only ontoolName == "bash". Copilot CLI names its shell toolpowershellon Windows, so the payload fell through toPassThroughand theHookFormat::CopilotClibranch was unreachable there.PreToolUseentry answers, viaHookFormat::VsCode, which emitspermissionDecision: "ask"— a permission prompt on every rewritten command (see rtk hook copilot emits permissionDecision "ask", forcing a permission prompt on every command in Copilot CLI >= 1.0.66 #3037), and one the allowlist cannot suppress since onlyallow/denyshort-circuit Copilot's permission flow.Fixes #3178.
Test plan
cargo fmt --all -- --check✅ ·cargo clippy --all-targets✅ (no warnings) ·cargo test --all—hooks::subset 396/396 green, newtest_detect_copilot_cli_powershellpassesRun locally on rustc 1.97.1 / stable-x86_64-pc-windows-msvc.
fmtcaught a width overflow in my own patch, fixed in10ca886.cargo test --allreports 16 failures, all incore::stream::tests(program not found— they spawn Unix binaries); verified identical on unmodifiedorigin/develop, so pre-existing on Windows and unrelated. Details in the comments below.Manual verification against a live Copilot CLI session
Captured with a logging hook wired to the camelCase
preToolUseentry, Copilot CLI 1.0.73 / Windows 11, RTK 0.43.0 (official release asset):{"sessionId":"c1b3f427-...","timestamp":1784807355614,"cwd":"C:\\Windows\\System32", "toolName":"powershell","toolArgs":"{\"command\":\"rtk gain\",\"description\":\"...\"}"}toolArgsis already the JSON-encoded string RTK expects — onlytoolNamediffered. And with the shipped binary:Note
This is complementary to #3037, not a replacement. With this fix the native path is reached on Windows and returns
modifiedArgswithout apermissionDecision, but thePreToolUseentry thatrtk initalso writes still answersaskfor the same tool call. Unless #3037 lands as well (or the generated hook file stops declaring both entries), Windows users keep getting a prompt on every command.