From 48cd166dff4cbdccbc70c1516a366ff961335bca Mon Sep 17 00:00:00 2001 From: Ryan Wyler Date: Tue, 25 Aug 2026 20:01:55 -0700 Subject: [PATCH] fix(snapshot): scope restore and diff to the session directory The snapshot index is shared across a whole project (git worktree), but a snapshot taken from a subdirectory only updates that subdirectory's entries via `add()` (scoped with `cwd: state.directory`). `restore()` used `checkout-index -a -f`, which writes every entry in the shared index across the entire worktree - so reverting/unreverting a session started in a subdirectory could overwrite a sibling directory's current file with a stale index blob, silently destroying unrelated edits. `diff()` had the matching scope gap: it ran `-- .` from `cwd: state.worktree`, reporting changes for unrelated directories. Scope both to the session directory: - restore() lists the snapshot's files under the session-directory prefix (`ls-tree -r`) and checks out only those, instead of `checkout-index -a`. - diff() runs from `cwd: state.directory` so `-- .` is relative to the session directory, consistent with add()/patch()/diffFull(). --- packages/opencode/src/snapshot/index.ts | 44 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/packages/opencode/src/snapshot/index.ts b/packages/opencode/src/snapshot/index.ts index 4da9bc3ca864..9c883855058a 100644 --- a/packages/opencode/src/snapshot/index.ts +++ b/packages/opencode/src/snapshot/index.ts @@ -382,24 +382,43 @@ const layer: Layer.Layer