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 inspect the OpenCode/Crush implementations to apply the same pattern.
- Assistant
Following TDD: adding backup tests first, then updating the agent implementations.
- Assistant
Implementing backup support in both agents.
- Assistant
All targeted tests passed. Running Prettier and the full test suite.
- Assistant
Both agents now honor the
backupargument when writing generated files.Changes
OpenCodeAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Before writing
AGENTS.mdandopencode.json: resolve paths againstprojectRoot, ensure parent directories exist, callbackupFilewhenbackupis true, then write viawriteGeneratedFile
CrushAgent.ts- Same
backupparameter and write flow forCRUSH.mdand.crush.json - Paths are now resolved with
path.resolve(projectRoot, ...)(previously relative custom paths could be wrong)
Tests
- Unit:
OpenCodeAgent— backup enabled/disabled via mockedFileSystemUtils - Unit:
CrushAgent— backup enabled/disabled with real filesystem - Integration:
backup-option.test.ts—--no-backupfor both agents with existingAGENTS.md/opencode.jsonand /
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.