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
Let me look at how other agents handle the backup parameter.
- Assistant
Now let me check how the apply engine invokes these agents with the backup flag.
- Assistant
Now I'll implement the fixes. First
OpenCodeAgent.ts: - Assistant
Now
CrushAgent.ts: - Assistant
Now
CrushAgent.test.ts(real fs): - Assistant
backupFileusesfsfrom'fs', not'fs/promises', so the mock doesn't cover it. I'll mock the utility directly in the OpenCode test: - Assistant
Both pass. Now check for regressions — build and the broader test suite:
- Assistant
Pre-existing failure confirmed (environment-dependent
HOME). Now the OpenCode integration tests and lint: - Assistant
Lint only targets
src/(which passed). Checking prettier formatting on the changed files: - Assistant
Done. Both agents now honour the
backupargument thatapply-engine.ts:503already passes.Changes
src/agents/OpenCodeAgent.ts- Added
backup = trueparameter toapplyRulerConfig. - Calls
backupFile()before writing the instructions file (AGENTS.md) and the MCP config (opencode.json) when backups are enabled.
src/agents/CrushAgent.ts- Added
backup = trueparameter toapplyRulerConfig. - Instructions and MCP paths are now resolved against
projectRootviapath.resolve(previously relative overrides were resolved against the process cwd). - Creates parent directories with
fs.mkdir({ recursive: true })and calls before writing and .
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.