Respect backups for OpenCode and Crush generated files Review run finding. OpenCode and…
- User
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.
- Assistant
I'll review how backup handling works in other agents and what OpenCode/Crush currently do, then align their apply logic and add tests.
- Assistant
Implementing backup support in both agents and adding tests.
- Assistant
Updating tests to match the new backup behavior.
- Assistant
Removing the
readFilespy that's conflicting with Jest's module mocking. - Assistant
OpenCode and Crush now honor the
backupargument when writing generated files, matching the pattern used by other agents like RooCode and AugmentCode.Changes
OpenCodeAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Calls
backupFilebefore writingAGENTS.mdandopencode.jsonwhen backup is enabled - Uses
writeGeneratedFileinstead of rawfs.writeFile(handles parent directory creation)
CrushAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Resolves output paths with
path.resolve(projectRoot, …)for consistent relative-path handling - Calls
backupFilebefore writingCRUSH.mdand.crush.jsonwhen backup is enabled - Uses
writeGeneratedFilefor both outputs
Tests
OpenCodeAgent.test.ts— Updated to spy onbackupFile/; added integration tests for backup enabled/disabled. - Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.