Milestone 3.3: Overview #9

Open
opened 2026-07-24 03:22:36 +00:00 by david · 0 comments
Owner

Overview

Implement back-switching behavior to auto-restore previous session when returning to main repo.

Acceptance Criteria

  • Track previous sessions in memory during pi process lifetime using worktreeSessionMap (Map<string, string>)
  • When switching TO a worktree: store current session file mapped to that worktree path
  • When switching TO the main repo: auto-restore the previous session if tracked
  • If no previous session tracked for main repo: stay in current session and track it

Implementation

const worktreeSessionMap = new Map<string, string>(); // worktree path -> session file
let mainRepoSessionFile: string | undefined;

// When switching TO a worktree:
worktreeSessionMap.set(targetPath, ctx.sessionManager.getSessionFile());

// When switching TO the main repo (detected by checking if target is the original cwd):
if (mainRepoSessionFile) {
  await ctx.switchSession(mainRepoSessionFile);
} else {
  // No previous session tracked — stay in current session
  mainRepoSessionFile = ctx.sessionManager.getSessionFile();
}

Validation

  • Start a session, switch to a worktree (create new session), then switch back to main — verify pi returns to the original session
  • Verify that the worktreeSessionMap is cleared on pi restart (stateless tools)
# Overview Implement back-switching behavior to auto-restore previous session when returning to main repo. ## Acceptance Criteria - [ ] Track previous sessions in memory during pi process lifetime using `worktreeSessionMap` (Map<string, string>) - [ ] When switching TO a worktree: store current session file mapped to that worktree path - [ ] When switching TO the main repo: auto-restore the previous session if tracked - [ ] If no previous session tracked for main repo: stay in current session and track it ## Implementation ```typescript const worktreeSessionMap = new Map<string, string>(); // worktree path -> session file let mainRepoSessionFile: string | undefined; // When switching TO a worktree: worktreeSessionMap.set(targetPath, ctx.sessionManager.getSessionFile()); // When switching TO the main repo (detected by checking if target is the original cwd): if (mainRepoSessionFile) { await ctx.switchSession(mainRepoSessionFile); } else { // No previous session tracked — stay in current session mainRepoSessionFile = ctx.sessionManager.getSessionFile(); } ``` ## Validation - Start a session, switch to a worktree (create new session), then switch back to main — verify pi returns to the original session - Verify that the `worktreeSessionMap` is cleared on pi restart (stateless tools)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: david/pi-worktrees#9
No description provided.