fix(cli): restore source file when reverting a move across folders
Summary
Fixes #9741. When the agent moved a file between folders during a task, clicking Revert would delete the file from its new location without restoring the original — resulting in data loss.
Root cause: patch() in snapshot/index.ts computed the file list via git diff --cached --name-only without --no-renames. Git's default rename detection collapsed a move (A/foo → B/foo) into a single destination entry, so the source path never entered the revert list.
Fix: Pass --no-renames, matching diffFull()'s behavior. Both source and destination now appear, so revert deletes the new location and restores the original.
Changes
- One-line fix in
patch()to add--no-renames - Regression tests in
test/kilocode/snapshot-revert-move.test.tscovering folder-to-folder moves and in-folder renames - Docs update in
checkpoints.mdandwhats-new.md(the limitation note now documents expected behavior; kept in case there are edge cases we haven't surfaced) - Changeset
Code Review Summary
Status: No Issues Found | Recommendation: Merge
Incremental Review Note
A large upstream merge landed on this branch since the previous review (b92677a). The PR-specific files were re-examined in full:
packages/opencode/src/snapshot/index.ts— The core fix (--no-renamesflag at line 426) is intact after the upstream restructuring. Thekilocode_change-marked diff command now reads:["diff", "--cached", "--no-ext-diff", "--no-renames", "--name-only", hash, "--", "."]. Fix confirmed present.packages/opencode/test/kilocode/snapshot-revert-move.test.ts— Simplified from 3 tests to 1 (adapted to thetestEffect/it.instanceframework introduced by the upstream merge). The primary regression case (cross-folder move) is still covered. The multi-step move and in-folder rename cases were dropped as part of test harness migration — not a concern..changeset/revert-file-moves.md— Unchanged.
Files Reviewed (3 files)
.changeset/revert-file-moves.mdpackages/opencode/src/snapshot/index.tspackages/opencode/test/kilocode/snapshot-revert-move.test.ts
Reviewed by claude-4.6-sonnet-20260217 · 674,187 tokens
Review guidance: REVIEW.md from base branch main
To stay organized pull requests are automatically closed after 30 days of inactivity. If the pull request is still relevant please reopen it or create a fresh new one.
@lambertjosh do you want to go ahead with this? Did you test it and is it ready to merge?