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 and inspect OpenCode and Crush apply logic to align them with the expected behavior.
- Assistant
Implementing backup support in both agents and adding tests.
- Assistant
Updating tests: refactoring OpenCodeAgent tests to use the real filesystem and adding backup coverage.
- Assistant
All targeted tests passed. Running lint and the full test suite.
- Assistant
Both agents now honor the
backupargument when writing generated files.OpenCodeAgent.ts- Added
backup = trueparameter toapplyRulerConfig - Before writing
AGENTS.mdandopencode.json: ensure parent dirs exist, callbackupFilewhen enabled, then write viawriteGeneratedFile
CrushAgent.ts- Added
backup = trueparameter - Resolved
CRUSH.mdand.crush.jsonpaths withpath.resolve(projectRoot, ...) - Same backup/ensure-dir/write flow for both files
Tests
OpenCodeAgent.test.ts: Switched from mockedfsto real filesystem tests; added backup enabled/disabled casesCrushAgent.test.ts: Added backup enabled/disabled cases in the existing backup/revert section
All 29 OpenCode/Crush agent tests pass. The two failures in the full suite (
handlers.test.ts,skills-propagation.test.ts) are unrelated to this change. - Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.