feat(copilot): cross-platform PreToolUse hook via rtk hook (VS Code + Copilot CLI + Windows)#605
Conversation
Add .github/copilot-instructions.md so GitHub Copilot CLI sessions automatically receive rtk usage instructions at startup. Includes: - Explicit 'always prefix with rtk' directive with before/after examples - Meta-commands reference (rtk gain, rtk discover, rtk proxy) - Installation verification step - Name-collision warning (reachingforthejack/rtk vs rtk-ai/rtk) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
Add GitHub Copilot CLI hook integration using the deny-with-suggestion pattern (Copilot CLI hooks cannot rewrite commands, only deny them): - .github/hooks/rtk-rewrite.json: preToolUse hook config - hooks/copilot-rtk-rewrite.sh: script that calls 'rtk rewrite' and denies raw commands with reason 'Token savings: use rtk X instead' - hooks/copilot-rtk-awareness.md: integration docs (mirrors rtk-awareness.md) - README.md: GitHub Copilot CLI section under Auto-Rewrite Hook Copilot CLI reads .github/hooks/*.json automatically — no rtk init needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
Show Copilot CLI integration status in `rtk init --show` output, alongside existing Claude Code and OpenCode checks: ✅ Copilot CLI: hook + instructions configured (repo-scoped, automatic)⚠️ Copilot CLI: hook config found but script missing or not executable ⚪ Copilot CLI: not configured Also adds const COPILOT_HOOK_SCRIPT and test_copilot_hook_has_guards to verify guard ordering mirrors the Claude Code hook convention. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
22 tests covering: - Intercepted commands (git, cargo, grep, gh) → deny with rtk suggestion - Pass-through: already-rtk, heredoc, unknown commands, non-bash tools, empty input - Output format: valid JSON, permissionDecision=deny, backtick-quoted rtk command in reason Mirrors the structure of hooks/test-rtk-rewrite.sh for the Claude Code hook. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
|
You should have to do windows support too, also his maybe works on vscode copilot integration. I'm planning to add many extensions to the VS Code chat integration. |
|
Also rewrite script should be automated. Maybe adding rust code should fix that |
Replace hooks/copilot-rtk-rewrite.sh with rtk hook — a native Rust binary that handles PreToolUse hooks for both VS Code Copilot Chat and Copilot CLI. - VS Code Copilot Chat: returns updatedInput (transparent rewrite, no denial) - GitHub Copilot CLI: returns permissionDecision: deny with suggestion (CLI ignores updatedInput today — tracked in copilot-cli#2013) - Windows: works natively, no bash or jq dependency Changes: - src/hook_cmd.rs: new subcommand, detects format via toolName vs tool_name - .github/hooks/rtk-rewrite.json: fix key casing (PreToolUse), point to rtk hook - hooks/copilot-rtk-rewrite.sh: deleted (replaced by rtk hook binary) - hooks/test-copilot-rtk-rewrite.sh: rewritten to test rtk hook binary - src/init.rs: remove COPILOT_HOOK_SCRIPT constant and bash script checks - hooks/copilot-rtk-awareness.md: add VS Code row, document both paths - README.md: rename section, add VS Code Copilot Chat, Windows note - CHANGELOG.md: update unreleased entry Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: jeziellopes <jeziellopes@gmail.com>
|
@vrdons Great suggestions — this PR has been expanded to implement exactly what you described. Rust binary instead of bash script ✅ VS Code Copilot Chat support ✅
When Copilot CLI adds The old bash hook also had wrong key casing ( |
Closes #593
What this adds
Cross-platform
PreToolUsehook for GitHub Copilot (VS Code Copilot Chat + Copilot CLI) viartk hook— a native Rust binary. No bash scripts, nojq, works on Windows natively.How it works
rtk hookreadsPreToolUseJSON from stdin, detects the agent format, responds appropriately:VS Code Copilot Chat (
updatedInput— transparent rewrite):GitHub Copilot CLI (deny-with-suggestion — CLI ignores
updatedInputtoday, copilot-cli#2013):When Copilot CLI adds
updatedInputsupport, onlyrtk hookneeds a one-line change.Also fixed
The old
.github/hooks/rtk-rewrite.jsonhad wrong key names (preToolUse→PreToolUse,bash/timeoutSec→command/timeout) that prevented it from loading in VS Code.Measured gains (validated Copilot CLI session)
rtk cargo testrtk cargo clippy --all-targetsrtk git diff HEAD~1rtk gh pr listFiles
src/hook_cmd.rsrtk hooksubcommand (13 unit tests).github/hooks/rtk-rewrite.jsonrtk hookhooks/copilot-rtk-rewrite.shrtk hookhooks/test-copilot-rtk-rewrite.shrtk hookhooks/copilot-rtk-awareness.mdsrc/init.rsREADME.mdCHANGELOG.mdTesting