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
Now I'll implement the fixes.
- Assistant
Now CrushAgent:
- Assistant
Now add tests. First to CrushAgent.test.ts:
- Assistant
All pass. Verify the apply engine passes the backup flag through, then run the full unit suite and lint/typecheck:
- Assistant
The failure is in
handlers.test.ts(XDG config path), unrelated to my change. Confirm it's pre-existing: - Assistant
Confirmed pre-existing — that test fails on the clean checkout too (it assumes the home config dir resolves to
/root/.config, but this environment resolves to/workspace/.config). Unrelated to this fix.Summary
src/agents/OpenCodeAgent.tsapplyRulerConfignow acceptsbackup = trueas its fifth parameter (matchingIAgent).- Calls
backupFile()on the instructions path (AGENTS.md) and MCP config path (opencode.json) before each write when backups are enabled.
src/agents/CrushAgent.tsapplyRulerConfignow acceptsbackup = true.- Instruction and MCP paths are now resolved against
projectRootvia (previously used raw config values / pre-joined defaults).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.