fix: list and open sessions across project directories

Sessions outside the server's launch directory were invisible and returned
404 on open, leaving the model picker empty. List without the SDK's
process-cwd filter and normalize working directories at the API boundary and
when reading stored session data, tolerating separator/normalization
differences (including Windows backslash vs forward slash). Requires Pi
coding agent SDK 0.78.0 or newer.
This commit is contained in:
Federico Jaramillo Martinez
2026-06-13 11:40:47 +02:00
parent 38cf334c40
commit c0d12222a2
14 changed files with 2342 additions and 2261 deletions
+4 -2
View File
@@ -3,6 +3,7 @@ import { constants } from "node:fs";
import { access, copyFile, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
import { basename, dirname, join } from "node:path";
import { homedir } from "node:os";
import { canonicalizeStoredCwd } from "../workingDirectory.js";
export interface ArchiveSessionInput {
sessionId: string;
@@ -148,7 +149,7 @@ export class SessionArchiveStore {
function archiveRecordFromInput(session: ArchiveSessionInput, archive: { archivedAt: string; originalPath: string; archivePath: string }): ArchivedSessionRecord {
return {
sessionId: session.sessionId,
cwd: session.cwd,
cwd: canonicalizeStoredCwd(session.cwd),
archivedAt: archive.archivedAt,
originalPath: archive.originalPath,
archivePath: archive.archivePath,
@@ -211,6 +212,7 @@ function parseArchivedSessionRecord(value: unknown): ArchivedSessionRecord {
const cwd = value["cwd"];
const archivedAt = value["archivedAt"];
if (typeof sessionId !== "string" || typeof cwd !== "string" || typeof archivedAt !== "string") throw new Error("Invalid archived session record");
const canonicalCwd = canonicalizeStoredCwd(cwd);
const originalPath = optionalString(value, "originalPath");
const archivePath = optionalString(value, "archivePath");
const created = optionalString(value, "created");
@@ -221,7 +223,7 @@ function parseArchivedSessionRecord(value: unknown): ArchivedSessionRecord {
const parentSessionPath = optionalString(value, "parentSessionPath");
return {
sessionId,
cwd,
cwd: canonicalCwd,
archivedAt,
...(originalPath === undefined ? {} : { originalPath }),
...(archivePath === undefined ? {} : { archivePath }),