fix: scope session list to current working directory

Sessions are stored in a single flat ~/.gsd/sessions/ directory, so
/resume shows sessions from all projects regardless of which folder
you're in.

Use per-cwd subdirectories under ~/.gsd/sessions/ with the same
path encoding the upstream SDK uses (--path-segments--), so /resume
only lists sessions from the current working directory.
This commit is contained in:
vp275 2026-03-11 21:39:02 +05:30
parent f72a86b773
commit f307923db2

View file

@ -6,6 +6,7 @@ import {
createAgentSession,
InteractiveMode,
} from '@mariozechner/pi-coding-agent'
import { join } from 'path'
import { agentDir, sessionsDir, authFilePath } from './app-paths.js'
import { buildResourceLoader, initResources } from './resource-loader.js'
import { loadStoredEnvKeys, runWizardIfNeeded } from './wizard.js'
@ -53,7 +54,12 @@ if (!settingsManager.getCollapseChangelog()) {
settingsManager.setCollapseChangelog(true)
}
const sessionManager = SessionManager.create(process.cwd(), sessionsDir)
// Per-directory session storage — same encoding as the upstream SDK so that
// /resume only shows sessions from the current working directory.
const cwd = process.cwd()
const safePath = `--${cwd.replace(/^[/\\]/, '').replace(/[/\\:]/g, '-')}--`
const projectSessionsDir = join(sessionsDir, safePath)
const sessionManager = SessionManager.create(cwd, projectSessionsDir)
initResources(agentDir)
const resourceLoader = buildResourceLoader(agentDir)