fix(coding-agent): handle missing session cwd

This commit is contained in:
Mario Zechner
2026-04-05 21:24:15 +02:00
parent 127547f2b3
commit 080af6fc06
6 changed files with 259 additions and 12 deletions

View File

@@ -1270,12 +1270,13 @@ export class SessionManager {
* Open a specific session file.
* @param path Path to session file
* @param sessionDir Optional session directory for /new or /branch. If omitted, derives from file's parent.
* @param cwdOverride Optional cwd override instead of the session header cwd.
*/
static open(path: string, sessionDir?: string): SessionManager {
static open(path: string, sessionDir?: string, cwdOverride?: string): SessionManager {
// Extract cwd from session header if possible, otherwise use process.cwd()
const entries = loadEntriesFromFile(path);
const header = entries.find((e) => e.type === "session") as SessionHeader | undefined;
const cwd = header?.cwd ?? process.cwd();
const cwd = cwdOverride ?? header?.cwd ?? process.cwd();
// If no sessionDir provided, derive from file's parent directory
const dir = sessionDir ?? resolve(path, "..");
return new SessionManager(cwd, dir, path, true);