ISSUE DESCRIPTION Respect backups for OpenCode and Crush generated files Review run…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- Assistant
I’ll inspect the agent implementations, shared backup utilities, and nearby tests to understand the expected apply conventions before making changes.
- Assistant
The issue is visible in both implementations: neither receives the interface’s backup argument, OpenCode writes instructions without backup, and Crush also lacks path normalization/directory creation. I’ll now compare the shared helper and representative agents/tests so the fix matches established semantics (including whether config files are backed up only when actually written).
- Assistant
The interface confirms
backupis the fifth parameter and defaults should be enabled. Existing integration-style forwarding tests cover similar AGENTS.md agents but not these two. I’ll inspectbackupFile, exact implementations that resolve custom paths and create directories, and the complete relevant test cases to avoid conflicting mock assumptions. - Assistant
Crush tests use the real filesystem, while OpenCode mocks
fs/promises; importing the shared helper will still be compatible because it uses Node’s promises object, but default backup calls add filesystem operations that mocked tests may observe indirectly. The intended source change is straightforward: importbackupFile, resolve both paths, ensure each parent exists before use/write, and back up immediately before each actual write. I’ll verify helper behavior and OpenCode test mocks before editing. - Assistant
OpenCode’s unit tests only assert writes and will continue to pass because
backupFilecatches missing-file errors; however, their generic mocked errors have noENOENTcode, so I need to confirm whether the helper suppresses all access failures or only missing files. - Assistant
I’ll implement backups for every file that is actually overwritten. Backups remain opt-out via the fifth argument, and
backupFilepreserves the first.bakacross repeated applies. Both configured paths will be resolved relative toprojectRoot; nested parents will be created before writes. - Assistant
Python is unavailable, so no files changed. I’ll apply the same targeted transformations with Node, then format and inspect the diff.
- Assistant
The source now follows the expected semantics. I’ll run both agent suites and the backup forwarding/apply tests, then build and lint. This should expose any mock interaction, path, or type issues.
- Assistant
Targeted tests, build, and lint pass. Because existing tests do not directly assert these two agents’ enabled/disabled backup behavior, I’ll perform a temporary end-to-end filesystem reproduction against the built agents: pre-create all three affected files, apply once with defaults and once with
backup=false, including nested relative custom paths, and assert backup contents/directory creation. - Assistant
The direct reproduction confirms all three vulnerable file types preserve original content when backups are enabled and produce no
.bakwhen disabled; relative nested custom paths are also resolved and created correctly. I’ll run the complete test suite and formatting check, then review the final diff/status before submission. - Assistant
The full suite completed with 1 unrelated environment-sensitive failure out of 1,034 tests: a skills cleanup test expects a permission error, but the process runs as root and the operation succeeds. All 139 other suites—including OpenCode, Crush, backup, revert, MCP custom paths, and e2e apply—passed. Since the chained command stopped before formatting/status checks, I’ll run those separately and confirm only the intended files changed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.