ISSUE DESCRIPTION Respect backups for OpenCode and Crush generated files Review run…
- User
ISSUE DESCRIPTION
Respect backups for OpenCode and Crush generated files Review run finding.
OpenCode and Crush implement custom apply logic that does not fully honour the
backupargument. Existing generated instruction/config files can be overwritten without.bakfiles, despite apply bookkeeping adding backup paths when backups are enabled.Impact: user-owned
AGENTS.md,CRUSH.md, or.crush.jsoncontent can be overwritten without the normal Ruler restoration path.Evidence:
src/agents/OpenCodeAgent.tsomits the backup parameter for instructions writes.src/agents/CrushAgent.tswritesCRUSH.mdand.crush.jsondirectly.
Expected fix:
- Accept
backup = truein these agent implementations. - Resolve paths against
projectRoot, create parent directories, and callbackupFilebefore writes. - Add tests for backup enabled/disabled behaviour.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files. Let's first get a high-level view.
- Assistant
Let me explore the repository structure more carefully.
- Assistant
Let me explore the src directory structure to understand the codebase.
- Assistant
Let me look at the OpenCodeAgent and CrushAgent files, as well as the IAgent interface to understand the backup mechanism.
- Assistant
Let me look at the OpenCodeAgent and CrushAgent files.
- Assistant
Now let me look at CrushAgent.ts.
- Assistant
Now let me look at the AbstractAgent and other agents to understand how backup is handled.
- Assistant
Let me now look at the
FileSystemUtilsto understand thebackupFileandwriteGeneratedFilefunctions. - Assistant
Now let me look at a few other agents that already handle backup properly, to see the pattern they follow. Let me check
ClaudeAgentorCopilotAgentas they're commonly used. - Assistant
Good, I can see that neither
OpenCodeAgent.tsnorCrushAgent.tshave the backup functionality. Let me look atAgentsMdAgent.tsfor a reference implementation: - Assistant
Now let me look at an agent that handles MCP with backup, like AiderAgent:
- Assistant
Let me also look at how the backup is called in the apply-engine:
- Assistant
Let me look at how
applyRulerConfigis called in the apply engine and how the backup parameter flows: - Assistant
Let me see the context around that line.
- Assistant
Now let me check how the backup parameter is determined and how it flows:
- Assistant
Let me check the existing tests:
- Assistant
Let me look at the OpenCode agent test:
- Assistant
Let me check if there are any tests for Crush agent:
- Assistant
Let me check the CrushAgent test.
- Assistant
Now let me also check the OpenCodeAgent test:
- Assistant
Let me check the unit test for OpenCodeAgent:
- Assistant
Now let me check how the
applyRulerConfigis called in the apply-engine to understand the flow better: - Assistant
Now let me check the revert-engine to understand how backups are used during revert:
- Assistant
Now I have a good understanding of the codebase. Let me create a plan:
-
OpenCodeAgent.ts:
- Add
backup = trueparameter toapplyRulerConfigmethod signature - Import
backupFilefromFileSystemUtils - Call
backupFilebefore writing instructions and MCP config files
- Add
-
CrushAgent.ts:
- Add
backup = trueparameter toapplyRulerConfigmethod signature - Import
backupFilefromFileSystemUtils - Call
backupFilebefore writingCRUSH.mdand.crush.json
- Add
-
Tests: Add tests for backup enabled/disabled behavior in both agents
Let me start by implementing the fixes. First, let me modify OpenCodeAgent.ts:
-
- Assistant
Let me check the full file now to see what happened:
- Assistant
The edit removed the class declaration. Let me restore the file and redo it properly:
- Assistant
Let me open the file and make targeted edits:
- Assistant
Now let me make the targeted edits. First, add the import for backupFile:
- Assistant
There's a duplicate line. Let me restore and rewrite the whole file:
- Assistant
Let me write the entire file directly:
- Assistant
Now let me do the same for CrushAgent.ts:
- Assistant
Let me verify both files were written correctly:
- Assistant
Good, OpenCodeAgent looks correct. Now let me check CrushAgent:
- Assistant
Good, both files are updated correctly. Now let me verify the changes compile correctly and run existing tests:
- Assistant
Good, no TypeScript errors. Now let me run the existing tests:
- Assistant
Now let me run the CrushAgent tests:
- Assistant
All existing tests pass. Let me also run the integration test for OpenCode agent:
- Assistant
Now I need to add tests for backup enabled/disabled behavior. Let me run the full test suite to make sure nothing is broken first:
- Assistant
The only failing test is in
skills-propagation.test.tsand it's a pre-existing test failure unrelated to our changes. Let me verify that this failure existed before our changes: - Assistant
Good - the failure is pre-existing. Let me restore my changes:
- Assistant
Now I need to add tests for backup enabled/disabled behavior. Let me check the existing test structure:
- Assistant
Let me check the AgentBackupForwarding test:
- Assistant
Let me check the test harness:
- Assistant
Let me check if there are similar backup tests for other agents:
- Assistant
Let me look at a few backup test patterns from existing agents:
- Assistant
Let me see the full CopilotAgent test for backup tests:
- Assistant
Let me check if the CrushAgent test already has tests for backup enabled/disabled:
- Assistant
Let me check the existing CrushAgent test to see if there are already backup tests:
- Assistant
Let me check how AiderAgent handles backup tests:
- Assistant
Let me check the OpenCodeAgent test to see if I can add backup tests with mocked fs or if I need a new file:
- Assistant
I need to add backup tests. Let me create new test files with real fs for backup behavior. First, let me create a test file for OpenCodeAgent backup tests:
- Assistant
Let me look at the CrushAgent backup tests more closely:
- Assistant
The existing CrushAgent tests have backup and revert functionality tests, but they don't test the
backup = true/falseparameter inapplyRulerConfig. Let me add tests for that. Let me create a similar backup test file for CrushAgent: - Assistant
Now let me run the new test files to make sure they pass:
- Assistant
Now let me run the CrushAgent backup tests:
- Assistant
Now let me run the existing OpenCodeAgent and CrushAgent tests to make sure they still pass:
- Assistant
Let me also run the AgentBackupForwarding test to make sure I haven't broken anything:
- Assistant
Let me run a broader set of tests to make sure nothing is broken:
- Assistant
Let me run the full test suite (excluding the pre-existing failure) to make sure nothing is broken:
- Assistant
All tests pass except the pre-existing failure. Let me verify the changes I made:
- Assistant
Let me also check the new test files I created:
- Assistant
Let me review the changes to make sure they are correct:
- Assistant
Let me check the CrushAgent diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.