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 and Crush implementations.
- Assistant
Implementing backup support in both agents and adding tests. Starting with the agent implementations.
- Assistant
Updating tests to cover backup behavior.
- Assistant
All tests passed. Formatting changed files and checking lints.
- Assistant
Both agents now honor the
backupparameter, consistent with agents likeAmazonQCliAgentandRooCodeAgent.Changes
OpenCodeAgent.ts- Added
backup = truetoapplyRulerConfig - Before writing
AGENTS.mdandopencode.json: resolve paths, ensure parent dirs exist, callbackupFilewhen enabled, thenwriteGeneratedFile
CrushAgent.ts- Same
backuphandling forCRUSH.mdand.crush.json - Paths are now resolved with
path.resolve(projectRoot, ...)(matching OpenCode)
Tests
OpenCodeAgent.test.ts— verifiesbackupFileis called for both outputs whenbackup=true, and skipped whenbackup=falseCrushAgent.test.ts— integration tests that existing files get.bakcopies when backup is enabled, and no backups are created when disabledThis restores the normal Ruler revert path: user-owned
AGENTS.md,CRUSH.md, and.crush.jsoncontent is preserved in.bakfiles before overwrite. - Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.