Repository navigation
fix(hooks): stop Copilot from silently deciding permission on unconfigured commands - #3212
Conversation
|
Nice catch on the dual-hook-invocation — that's a real bug and the fix (plus the upgrade test) is clean. One thing worth double-checking before merge, since it interacts with #3179 (still open): once
So both platforms report Did the live validation on 1.0.75 happen to include a Windows run? If the PascalCase |
|
No windows machine on my side to check that part unfortunately 😕 |
e1abc95 to
d1cc6ba
Compare
…AskRewrite handle_vscode (rtk hook copilot's PascalCase path, shared by VS Code Copilot Chat and Copilot CLI's Claude-compat entry) always set permissionDecision to "allow" or "ask", diverging from process_claude_payload which only asserts "allow" for an explicit user-configured Allow rule and stays silent otherwise. Asserting "ask" is what caused #3037: Copilot CLI 1.0.66+ treats it as authoritative and forces a blocking dialog with no "remember" option on every rewritten command. 84aa4d6/0df6929 patched the wrong path (the camelCase native handler, which never had this problem) with an auto-allow heuristic gated on an `explicit` flag, instead of fixing handle_vscode itself. Replace both with the same rule Claude's own hook and Droid's hook already use: never assert a decision for AskRewrite, regardless of whether the verdict was Default or an explicit Ask rule. This removes the Copilot-specific heuristic (and the now-unused `explicit` field) in favor of one behavior shared across all hosts. Also extracts vscode_response_from_decision as a pure, testable function (mirroring copilot_cli_response_from_decision), closing a prior gap where handle_vscode's decision output had no direct unit test coverage.
…ok config rtk init --copilot registered both a PascalCase PreToolUse entry and a camelCase preToolUse entry in the same rtk-rewrite.json, on the assumption that VS Code Copilot Chat needs the former and Copilot CLI needs the latter. Live testing showed Copilot CLI treats PreToolUse/preToolUse as two independent, sequentially-run hooks — a redundant second `rtk hook copilot` process spawn per tool call, chaining the first hook's rewrite into the second's input (confirmed via raw stdin capture, and confirmed independent of declaration order in the file). Also confirmed Copilot CLI honors the PascalCase-only schema perfectly well on its own, receiving the same tool_name/tool_input.command shape either way — so the camelCase entry buys nothing for Copilot CLI, while adding process overhead and an extra, harder-to-reason-about execution path. Drop the camelCase preToolUse entry, keeping the single PascalCase PreToolUse entry shared by both hosts. Existing installs are not upgraded automatically — re-running `rtk init --copilot` / `rtk init --global --copilot` overwrites the old dual-schema file with the new one (write_if_changed overwrites unconditionally on content diff), verified by test_copilot_init_upgrades_old_dual_schema_install and test_copilot_global_install_upgrades_old_dual_schema_install, which seed the old dual-schema content and assert it gets replaced.
detect_format only matched tool_name values "runTerminalCommand", "Bash", and "bash" for the VsCode hook format. Live payload capture from a real VS Code Copilot Chat session (agent mode, GitHub.copilot-chat) showed it actually sends "run_in_terminal" — none of the previously recognized values — so detect_format fell through to PassThrough and the hook never fired at all for VS Code Copilot Chat: no rewrite, no permissionDecision, nothing. Add "run_in_terminal" to the recognized tool_name set. Verified against the real captured payload end-to-end: a compound "cd <dir> && git status --short --branch" command now correctly rewrites only the git segment to "rtk git status --short --branch", leaving "cd" untouched, with no permissionDecision asserted (consistent with the Default-verdict behavior fixed in 042aeaf).
…ot generated The doc comments described the camelCase toolName/toolArgs schema as "GitHub Copilot CLI"'s format, which was accurate when rtk init --copilot registered it. Now that only the PascalCase schema is generated, this path is reachable only via not-yet-upgraded installs' leftover registration, or hosts that use this schema under a different toolName value on their own (JetBrains/ IntelliJ's Copilot plugin sends "run_in_terminal", tracked in #2443/#3093). Note both call sites accordingly so the code isn't mistaken for dead weight.
…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.
d1cc6ba to
2cb3908
Compare
|
So this will fix RTK to work on Windows? |
It depends what's your exact problem with RTK on Windows but it should help for sure |
What problems does this fix and when can we expect it to be released? |
pszymkowiak
left a comment
There was a problem hiding this comment.
LGTM — this fixes the root cause in handle_vscode cleanly instead of extending the previous workaround, and the removed dual-hook registration + run_in_terminal detection gap are both real fixes found through solid live testing.
Re: my earlier question about Windows and the camelCase hook removal — confirmed and closed by @romain-cureau's live test on Windows 11 / Copilot CLI 1.0.73: #3179 (comment). The PascalCase PreToolUse path fires and its updatedInput is honored end-to-end on Windows, so dropping the camelCase entry here doesn't regress Windows behavior.
CI green across the board (including windows-latest and benchmark). Approving.
Summary
Fixes the root cause of #3037 properly, instead of the workaround
84aa4d6/0df6929shipped, and closes two related gaps found while validating it live against real Copilot CLI (1.0.75) and VS Code Copilot Chat.permissionDecisionparity —handle_vscode(rtk hook copilot's PascalCase path, shared by VS Code Copilot Chat and Copilot CLI's Claude-compat entry) always assertedpermissionDecision: "allow"or"ask". Asserting"ask"is exactly what#3037reported: Copilot CLI 1.0.66+ treats it as authoritative and forces a distinct, memory-less "Hook permission request" dialog on every call.84aa4d6/0df6929patched the camelCase native path instead (which never had this problem) with an auto-allow heuristic — the actual bug inhandle_vscodewas never touched. Nowrtk hook copilotonly ever assertspermissionDecision: allowfor an explicit, user-configured Allow rule — exactly the same rule Claude Code's own hook (process_claude_payload) and Factory Droid's hook already use. Everything else omits the field, per GitHub's own docs ("empty output uses default behavior" — hook silence is a supported, intentional no-op, not a workaround), letting Copilot's native trust-on-first-use dialog (which does have a working "don't ask again" option) take over.rtk init --copilotregistered both a PascalCasePreToolUseand a camelCasepreToolUseentry in the same file. Live testing (raw stdin capture, both hook-order and key-order reversed) showed Copilot CLI treats them as two independent, sequentially-run hooks regardless of declaration order — camelCase always runs first and does the real rewrite, PascalCase always runs second on the already-rewritten command and just defers. A redundant process spawn with no behavioral benefit, since Copilot CLI honors the PascalCase-only schema perfectly well on its own. Dropped the camelCase entry; existing installs upgrade on the nextrtk init --copilot/rtk init --global --copilotre-run (write_if_changedoverwrites unconditionally on content diff — verified with dedicated upgrade tests, not just fresh-install tests).detect_formatonly recognizedtool_namevalues"runTerminalCommand"/"Bash"/"bash". A real captured payload from VS Code Copilot Chat showed it actually sends"run_in_terminal"— unrecognized, so the hook fell through toPassThroughand never fired at all for VS Code Copilot Chat (no rewrite, no decision, nothing). Added"run_in_terminal"to the recognized set. Fixes[Bug] rtk hook copilotdoes not trigger for VS Code Copilot Chat —"run_in_terminal"not recognized indetect_format()#1425Live validation
All three changes were validated against the real, currently-released binaries and both real hosts (not just unit tests):
developHEAD (23d1e89) fresh as the true "before" baseline (an initially-used stale local install turned out to predate both84aa4d6and0df6929entirely).tool_name/tool_input.command) payload shape when only that key is registered — not just a VS-Code-relayed artifact.#3037bug live:developHEAD's literalpermissionDecision: "ask"produces a distinct "Hook permission request" / "RTK auto-rewrite" dialog with no remember option, repeating on every call.cd <dir> && git status --short --branchcommand tocd <dir> && rtk git status --short --branch, with no forcedpermissionDecision.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --all(2498 tests, all green)vscode_response_from_decisiondecision matrix (allow/ask/deny/defer), dual-schema-upgrade tests (project + global scoped),run_in_terminalformat detectioncopilotCLI 1.0.75 and VS Code Copilot Chat, described above🤖 Generated with Claude Code