opencode
opencode copied to clipboard
Unrevert from subdirectory overwrites files in other directories with stale versions
Description
When running opencode from a subdirectory and clicking "undo revert", files in other directories are overwritten with stale versions (potentially weeks old).
Steps to Reproduce
- Create a project with multiple subdirectories:
mkdir -p /tmp/testproject/frontend /tmp/testproject/backend
cd /tmp/testproject
git init && git config user.email "[email protected]" && git config user.name "Test"
echo 'console.log("frontend")' > frontend/app.ts
echo 'println("backend ORIGINAL")' > backend/server.go
git add . && git commit -m "Initial"
- Run opencode from
backend/, make a change, then exit:
cd /tmp/testproject/backend
opencode
# Ask it to modify server.go, then exit
- Update backend externally (simulates time passing):
echo 'println("backend CURRENT")' > backend/server.go
git add . && git commit -m "Update backend"
- Run opencode from
frontend/, make a change, revert, then unrevert:
cd /tmp/testproject/frontend
opencode
# Ask it to modify app.ts
# Click "Revert" on the assistant's message
# Click "Undo Revert"
- Check if backend was corrupted:
cat /tmp/testproject/backend/server.go
# Shows "backend ORIGINAL" instead of "backend CURRENT"
Expected Behavior
Files in other directories should NOT be affected when running revert/unrevert from a subdirectory.
Actual Behavior
Files in other directories are overwritten with stale versions from the shared snapshot index.
Root Cause
- The snapshot index at
~/.local/share/opencode/snapshot/{project_id}/is shared across all sessions in a project -
git add .from a subdirectory only updates that subdirectory's entries in the index -
restore()usescheckout-index -awhich restores ALL files in the index, including stale entries from other directories -
diff()usescwd(Instance.worktree)showing diffs for unrelated directories
Environment
- OpenCode version: v1.1.13
- OS: Linux