Fix: Preserve user content when generating rules#6
Open
MS-Jahan wants to merge 1 commit into
Open
Conversation
Problem:
- The rules generation function (generate_rules) was overwriting existing
files completely, destroying user customizations in .windsurfrules,
AGENTS.md, copilot-instructions.md, and other rule files.
Solution:
- Modified write_rule() to use section markers for content management
- Markers: <!-- BEGIN CODEGENOME MCP INTEGRATION --> and <!-- END -->
- New behavior:
* New files: Create with markers wrapping CodeGenome content
* Existing files without section: Append CodeGenome section with markers
* Existing files with section: Replace only the CodeGenome section,
preserving all user content before and after
Benefits:
- Users can add custom rules above/below CodeGenome section
- CodeGenome updates won't destroy customizations
- Non-destructive updates - safe to run multiple times
- Backup created if file is unreadable
Tests:
- Added test_rules_append.py with comprehensive test coverage
- Manual verification confirms all scenarios work correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Preserve user content when generating rules
Problem
The
codegenome rulescommand was destructively overwriting existing files, causing loss of user customizations:.windsurfrules: Users' Windsurf IDE rules replaced completelyAGENTS.md: Important agent instructions lost.github/copilot-instructions.md: Custom Copilot settings overwritten.cursor/rules/codegenome-knowledge-graph.mdc: Cursor rules resetThis made the
rulescommand unsafe to run more than once and prevented users from adding their own customizations alongside CodeGenome instructions.Solution
Modified
write_rule()insrc/codegenome/rules.pyto use section markers for non-destructive content management:Behavior
Example
Before (destructive):
# My Custom Rules User content hereRunning
codegenome ruleswould replace everything with CodeGenome content.After (non-destructive):
User content preserved! Running the command again only updates the CodeGenome section.
Benefits
✓ Safe to run multiple times - updates don't destroy customizations
✓ Users can add custom rules - above or below CodeGenome section
✓ Backwards compatible - works with existing files
✓ Automatic backup - creates
.backupif file is unreadableTesting
Added comprehensive test suite in
tests/test_rules_append.py:All tests pass ✓
Files Changed
src/codegenome/rules.py- Modifiedwrite_rule()function (42 lines added)tests/test_rules_append.py- New test suite (134 lines)Migration
No migration needed. Existing generated files will work as-is. Next time users run
codegenome rules, it will append the section with markers instead of overwriting.