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 other agents handle backups, then fix OpenCode and Crush to honor the
backupargument. - Assistant
Implementing backup support in both agents and adding tests, following the AmazonQCliAgent pattern.
- Assistant
Updating tests for both agents:
- Assistant
Fixing the broken CrushAgent test file.
- Assistant
Both agents now honor the
backupargument when writing generated files.Changes
OpenCodeAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Uses
ensureDirExists,backupFile, andwriteGeneratedFilefromFileSystemUtils - Backs up
AGENTS.mdbefore instructions write, andopencode.jsonbefore MCP write when backup is enabled
CrushAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Resolves
instructionsPathandmcpPathagainstprojectRootviapath.resolve - Creates parent directories with
ensureDirExists - Backs up
CRUSH.mdand.crush.jsonbefore writes when backup is enabled
Tests
OpenCodeAgent.test.ts— Refactored to mockFileSystemUtils(matching other agents) and 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.