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 update both agents. First,
OpenCodeAgent.ts: - Assistant
Now
CrushAgent.ts: - Assistant
Now update the OpenCode unit tests. Since they mock
fs/promises, I'll mockbackupFilethere too: - Assistant
Now add backup tests to the Crush suite (real fs, so we assert actual
.bakfiles): - Assistant
All 30 tests pass. Now run the wider related suites plus lint/typecheck to check for regressions:
- Assistant
Confirmed pre-existing — it fails on the clean tree too (env sets
XDG_CONFIG_HOME). Now typecheck and lint: - Assistant
All done. Summary of the fix:
src/agents/OpenCodeAgent.tsapplyRulerConfignow acceptsbackup = true(matching theIAgentsignature).- Calls
backupFile(instructionsPath)before writingAGENTS.mdandbackupFile(mcpPath)before writingopencode.jsonwhen backups are enabled.
src/agents/CrushAgent.tsapplyRulerConfignow acceptsbackup = true.- Instructions/MCP paths are now resolved against
projectRootwithpath.resolve(previously relative custom paths resolved against cwd). - Parent directories are created with
fs.mkdir(..., { recursive: true })before writes. backupFileis called before writingCRUSH.mdand when backups are enabled.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.