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.
- Assistant
I’ll first inspect the agent implementations, shared backup utilities, and nearby tests to understand existing conventions and reproduce the omission. Then I’ll patch only production code, run the relevant existing tests (without modifying tests), and review the diff for path and backup edge cases.
- Assistant
The defect is visible in both implementations: neither method accepts the interface’s backup argument, OpenCode writes instructions without backup, and Crush directly writes both files without path resolution, parent creation, or backup. I’ll now inspect
IAgent,backupFile, representative compliant agents, package scripts, and existing OpenCode/Crush tests so the fix matches repository semantics (especially whether configs are backed up before merge and whether absent files produce backups). - Assistant
Since ripgrep is unavailable, I’ll use
grep. The interface confirms the fifth optional parameter. I need the exact backup utility contract and tests’ direct invocation patterns before editing, particularly because backing up a merged config must happen before the write but can happen after reading it. - Assistant
The prior output was truncated by the broad examples, but it confirms the standard sequence: resolve against
projectRoot, ensure parent, conditionallybackupFile, then write. I’ll isolate the utility and target tests now, and also inspect RooCode’s MCP branch because it most closely mirrors these multi-file agents. - Assistant
The utility preserves the first
.bakand silently skips nonexistent sources, so calling it unconditionally when backup is enabled is safe. I’ll update both signatures withbackup = true; importbackupFile; resolve all configured paths againstprojectRoot; recursively create each parent directory before its write; and invoke backup immediately before each actual write. For Crush,.crush.jsonwill only be backed up when the existing logic actually emits that file. - Assistant
Python is not installed, so no source changes occurred. I’ll apply the same deterministic replacements with Node (available through the project), fail fast if any expected source fragment is missing, then format and inspect the diff.
- Assistant
The patch now matches the requested behavior. I’ll run the two agent unit suites and TypeScript build first. These tests cover existing path precedence, MCP merge/transform behavior, real filesystem writes, and revert compatibility; the build catches signature/import issues.
- Assistant
Existing suites and compilation pass, but they do not explicitly assert the newly reported enabled/disabled behavior. To reproduce and verify the issue end-to-end without adding repository tests, I’ll run a temporary Node script against the freshly built agents. It will seed user-owned instruction/config files for both agents, assert default backups preserve originals, assert
backup=falsecreates no.bak, and use nested relative custom paths to validate project-root resolution and directory creation. - Assistant
The temporary reproduction passes for all four enabled/disabled cases, including relative nested paths, and left only the two intended source changes. I’ll now run the broader backup CLI suite and OpenCode integration suite to verify the apply engine forwards the flag correctly, plus lint and formatting checks. If those pass, I’ll inspect the final diff and repository status before submission.
- Assistant
All relevant unit, integration, CLI backup, build, lint, and formatting checks pass. Edge-case review: absolute overrides remain absolute under
path.resolve; relative overrides are anchored toprojectRoot; recursive parent creation supports nested paths; absent files do not create spurious backups; preexisting.bakfiles remain intact viabackupFile; config backups occur only when a config write occurs; andfalsesuppresses both instruction and config backups. I’ll perform the final whitespace/status review now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.