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.
Assistant
Now let's look at how apply-engine calls applyRulerConfig, and how AmazonQCliAgent does it (as another example with both instructions and mcp backups).
Assistant
Now let's check existing tests for OpenCode and Crush agents to understand test patterns.
Assistant
Now let's check how apply-engine calls agent.applyRulerConfig around line 490-510, and how backup paths are collected for gitignore (bookkeeping mentioned in issue).
Assistant
Good, that confirms the bookkeeping already adds
.bakpaths regardless of whether the agent actually creates them - hence the issue. Now let's fix both agent files.Assistant
No python3 available; use node instead, or use the edit/replace tool directly.
Assistant
I'll use the
open/replacespecial commands instead.Assistant
Oops, I accidentally deleted the
concatenatedRules: string,line. Let me fix.Assistant
Good, now fix. Now add backupFile calls before writes.
Assistant
OpenCodeAgent looks good now. Let's do the same for CrushAgent.
Assistant
Now let's edit imports and function signature, and add path resolving + mkdir + backup.
Assistant
Now edit the applyRulerConfig function body.
Assistant
Now add mkdir + backup before the mcp write at lines 123-125.
Assistant
Now let's build and run the existing tests for both agents.
Assistant
No type errors. Now run existing test suites.
Assistant
All existing tests pass. Now let's add new tests for backup enabled/disabled behavior for both agents. Let's check test file structure conventions used elsewhere (e.g., AmazonQCliAgent test for backup).
Assistant
All new tests pass. Now let's run the full test suite to ensure nothing else broke.
Assistant
Confirmed pre-existing failure unrelated to our changes. Restore stash.
Assistant
Good, pre-existing failure confirmed unrelated to our fix. Now let's double check lint passes.
Assistant
Good — that's a pre-existing condition affecting all test files, not something caused by our new file. Let's just lint the source files, which is what matters.
Assistant
Lint passes cleanly for the source files. Let's also run prettier check/format on new test file to keep style consistent.
Assistant
Now let's view the final diffs for review.
Assistant
This matches expectations from the issue. Let's run the full jest suite once more to confirm overall status (excluding the known pre-existing failure).
Assistant
Only the pre-existing unrelated failure remains. All other 1037 tests pass including my new ones.
Assistant
Let's go through the checklist explicitly and then submit.
Checklist review:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.