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.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /ruler, current file: none) bash-$
Assistant
Let me start by exploring the repository structure to understand the codebase and then look at the specific files mentioned in the issue description.
Assistant
Let me explore the source directory structure and look at the specific files mentioned in the issue.
Assistant
Let me look at the relevant files mentioned in the issue description
Assistant
Let me use the bash terminal to read the files.
Assistant
Let me read them one at a time.
Assistant
Now let me read CrushAgent.ts
Assistant
Now let me look at the apply engine to understand the backup mechanism.
Assistant
Let me look at the IAgent interface and agent-utils to understand how agents are called.
Assistant
Let me look at the apply engine to understand how backup is passed and how other agents handle it.
Assistant
Let me look at the section of apply-engine.ts around line 450 where agent rules are applied.
Assistant
Let me look at how other agents handle the backup parameter, and the `backupFile
Assistant
Let me look at how other agents properly handle backup. Let's check a few examples.
Assistant
Let me look at AbstractAgent.ts and also look at how agents like ClaudeAgent.ts handle backup.
Assistant
Now let me look at FileSystemUtils.ts to understand the backup and write functions
Assistant
Now let me look at existing tests for these agents
Assistant
Let me look at existing test files for these agents.
Assistant
Now let me check the CrushAgent test and the backup-option test for patterns
Assistant
Let me also look at the backup-related tests and how other agents handle backup
Assistant
Let me also look at the harness and existing backup tests
Assistant
Now I have a thorough understanding of the codebase. Let me implement the fixes.
Issue Analysis:
OpenCodeAgent.ts-applyRulerConfigignores thebackupparameter (missing from signature) and writes files without creating backupsCrushAgent.ts- Same issue; also doesn't resolve paths againstprojectRootand doesn't create parent directories
Plan:
- Fix
OpenCodeAgent.ts: Addbackupparameter, importbackupFile, call it before writes - Fix
CrushAgent.ts: Addbackupparameter, importbackupFile, resolve paths againstprojectRoot, create parent dirs, callbackupFilebefore writes - Add tests for backup enabled/disabled behavior
Let's start with
Assistant
Now let me fix OpenCodeAgent.ts. I'll add the
backupparameter, importbackupFile, and call it before writes.Assistant
Now fix CrushAgent.ts with backup support, path resolution, and directory creation
Assistant
Let me verify the changes look correct
Assistant
Good. Now let me check CrushAgent.ts:
Assistant
Let me build to make sure there are no TypeScript errors
Assistant
Let me check how the OpenCodeAgent tests are set up to understand the mocking patterns
Assistant
Let me look at how AmpAgent tests handle backup to follow the same
Assistant
Let me also look at the integration test for OpenCodeAgent:
Assistant
Now let me add backup tests. First, let me update the OpenCodeAgent test
Assistant
Let me look at the JunieAgent test for inspiration on how to test backup with direct fs
Assistant
Let me see the full JunieAgent test setup
Assistant
Let me now add backup tests. First, let me update OpenCodeAgent.test.ts:
Assistant
Now let me add backup tests for CrushAgent:
Assistant
Let's run the tests to make sure everything works:
Assistant
All OpenCodeAgent tests pass. Now let's run CrushAgent tests:
Assistant
All tests pass. Let me also run broader tests to make sure nothing is broken:
Assistant
All 371 agent tests pass. Let me also run the integration tests and apply-engine tests
Assistant
Let me also run the broader backup-related tests
Assistant
Let me verify the final state of changes with git
Assistant
Let me see the full diff for a final review
Assistant
Let me run the broader test suite to make sure nothing is broken
Assistant
There's one pre-existing failing test in
skills-propagation.test.tsthat is unrelated to my changes. Let me confirm by checking if it fails on a clean checkout:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →