fix(hook): preserve existing Copilot instructions#1513
Conversation
📊 Automated PR Analysis
SummaryThis PR fixes the Copilot instructions installation to preserve existing user-authored content in Review Checklist
Linked issues: #1512 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
Drive by comment, but I think the more idiomatic way to manage this would be to create a .github/instructions/rtk.instruction.md. Avoids messing with the users existing instructions, and reduces the risk of clobbering the RTK instructions if the user runs /init to regenerate their copilot-instructions. |
|
Thanks @kiljacken, appreciate the drive-by — and you're right, .github/instructions/rtk.instructions.md is the more idiomatic home for this. It avoids touching the user's main copilot-instructions.md entirely, survives a Copilot /init regen, and uninstall becomes a single rm. Cleaner all around. That said, I'd still like to merge this PR first as the immediate fix for #1512 — users hitting the clobber bug today need the v2 marker path, and the migration logic added here is what we'd reuse to clean up marker blocks when we move to the separate-file approach in a follow-up "v3". One thing I'd love your input on before committing to the move: do you know how well .github/instructions/*.instructions.md is supported outside VS Code Copilot (JetBrains, Visual Studio, Copilot CLI)? If it's broadly supported, v3 is a no-brainer. If it's VS Code-only, we may want to keep copilot-instructions.md as a fallback. Either way, happy to open a follow-up issue and update accordingly. Thanks again for the suggestion! |
|
@season179 @kiljacken placing the instructions in |
|
@xxradzip Might need to add markdown frontmatter with files it should apply to: ---
applyTo: "**"
---
Rest of the instruction goes here... |
# Conflicts: # src/hooks/init.rs
Summary
.github/copilot-instructions.mdcontent when installing Copilot support.<!-- rtk-instructions v2 -->markers so future installs update idempotently.Fixes #1512
Root Cause
run_copilot()usedwrite_if_changed()for.github/copilot-instructions.md. When the file already existed with user-authored Copilot rules, any content mismatch caused RTK to atomically replace thewhole file with RTK instructions.
Test plan
rtk cargo +1.92.0 test patch_copilot_instructionsrtk cargo fmt --all -- --checkrtk git diff --checkinit --copilottwice preserved existing Copilot rules and produced one RTK marker blockNotes
Full
rtk cargo +1.92.0 testwas attempted and reached the suite, but failed in unrelated existing areas: curl truncation expectations, tracking DB creation in this sandbox, and a global uninstall testtouching
/Users/season/.config/opencode/plugins/rtk.ts. The new Copilot tests passed.