Skip to content

feat: restore the last-open session when switching workspaces - #416

Merged
agegr merged 3 commits into
agegr:mainfrom
isWittHere:feature/workspace-session-memory
Aug 8, 2026
Merged

feat: restore the last-open session when switching workspaces#416
agegr merged 3 commits into
agegr:mainfrom
isWittHere:feature/workspace-session-memory

Conversation

@isWittHere

Copy link
Copy Markdown
Contributor

Feat: restore the last-open session when switching workspaces

切换工作区后回到先前所处的session而不是始终切换到新会话页面。

Switching to a workspace previously landed on a blank new-session page,
and the session open there last had to be re-picked by hand. This PR
remembers each workspace's last-open session and restores it on switch.

Behavior

  • Session selected in a workspace → remembered under the resolved
    project root (all worktrees of one repo share a slot).
  • Switch to another workspace → the remembered session is restored
    after a brief welcome-transition; no memory → default welcome page.
  • Remembered session deleted or drifted to another workspace
    memory cleared silently, welcome page stays.
  • Rapid switching → a token guard drops stale async restores.

Implementation

  • lib/workspace-memory.ts — pure localStorage helpers
    (getLastOpenSession / setLastOpenSession / clearLastOpen /
    workspaceKeyOf), storage injectable for tests.
  • components/AppShell.tsx — record on session select; new
    restoreWorkspaceContext called from handleCwdChange's cross-project
    branch restores the session via the live session list.

Testing

  • node --test lib/workspace-memory.test.mjs — 11/11 pass
  • node_modules/.bin/tsc --noEmit — clean
  • npm run lint — clean

isWittHere and others added 3 commits August 8, 2026 01:03
Switching to a workspace previously landed on a blank new-session page and
the session open there last had to be re-picked by hand. Record the
selected session per workspace (resolved project root, sharing one slot
across worktrees) in localStorage, and on a cross-project cwd change
look it up against the live session list to restore it.

A deleted or drifted session clears the memory and keeps the welcome
page; a failed list fetch keeps the memory for a later retry. A token
guard drops stale async restores after a rapid switch sequence.
…e-memory

# Conflicts:
#	components/AppShell.tsx
@agegr
agegr merged commit c8692e4 into agegr:main Aug 8, 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.

2 participants