Skip to content

fix: persist worktree state across reload and polish desktop UX#95

Merged
amandal0903 merged 16 commits intomainfrom
monk
Apr 10, 2026
Merged

fix: persist worktree state across reload and polish desktop UX#95
amandal0903 merged 16 commits intomainfrom
monk

Conversation

@amandal0903
Copy link
Copy Markdown
Collaborator

Summary

  • Persist terminal ownership and editor working sets across window reload so switching worktrees preserves open editors and terminal assignments
  • Hide window on macOS X-button instead of closing, preserving all state (terminals, editors, positions) — dock click re-shows
  • Exclude .workstreams repos from SCM git detection so worktree sub-repos don't pollute the Source Control sidebar
  • Deduplicate worktree building by extracting shared _buildWorktreeEntries used by both addRepository and restoreState
  • Replace setTimeout with RunOnceScheduler for editor retry logic and guard expensive debug logging behind log level
  • Update landing page copy fix and CTA button styling

Persists the worktree path→editor working set mapping to
StorageScope.WORKSPACE so editor layouts survive window close/reopen.

- Add WORKING_SET_MAP_KEY storage key
- Add _persistWorkingSetMap() called after every switchTo() save
- Delete stale working set before creating a new snapshot (prevents
  unbounded accumulation across sessions)
- Restore map in restoreState() with id validation against
  editorGroupsService.getWorkingSets() to guard against storage drift
When removeWorktree() fires, delete the worktree's snapshot from both
editorGroupsService and _workingSetMap, then persist the updated map.
Prevents orphaned working set entries from accumulating after worktrees
are deleted.
On reload, restoreState() was calling switchTo() which ran the full
switch flow (applyWorkingSet('empty') → folder swap → restore), wiping
VS Code's own editor restoration. Fix by setting _activeWorktree
directly and only firing the event — no destructive editor ops.

Additionally, backgrounded worktree terminals were killed on reload
because forcePersist was never set and the ownership map was in-memory.
Now set forcePersist=true when backgrounding so pty processes survive,
and persist/restore the ownership map (keyed by persistentProcessId)
to workspace storage so terminals can be reclaimed after reconnect.
Seed _activeKey from the already-restored active worktree during
contribution init so the first worktree switch correctly claims
terminals. Remove the now-redundant _restoreOwnership call from
_onActiveWorktreeChanging and the duplicate fire during service
restoration. Fix deleteWorktreeModal test teardown to click cancel
buttons instead of removing DOM elements, ensuring DisposableStores
are properly disposed. Remove unused mcpStdioStateHandler test.
On macOS, clicking the red close button now hides the window instead of
destroying it, preserving all terminals, editors, and cursor positions.
Clicking the dock icon shows the hidden window. Cmd+Q still fully quits.
Also removes debug console.warn from hookNotificationServer.
…clean up styles

Extract shared _buildWorktreeEntries() to eliminate duplicated logic
between addRepository and restoreState. Merge _findGroupIndex and
_findTabIndex into single-pass _findGroupPosition. Move inline styles
to CSS and flatten nested try/catch in getRemoteUrl.
Prevents worktree repositories inside .workstreams/ from appearing in
the Source Control panel by filtering them in both directory traversal
and the openRepository catch-all path.
The previous filter was too aggressive — it blocked SCM for worktrees
opened as their own workspace. Now checks relative path from workspace
folder so the filter only applies to sub-repo discovery, not when the
workspace root itself is inside .workstreams/.
@amandal0903 amandal0903 merged commit 9c73a58 into main Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant