Sessions: fix sessions_list transcriptPath path resolution

This commit is contained in:
Vignesh Natarajan
2026-02-28 14:42:14 -08:00
parent f57b4669e1
commit c58d2aa99e
5 changed files with 59 additions and 7 deletions

View File

@@ -39,13 +39,15 @@ export type SessionFilePathOptions = {
sessionsDir?: string;
};
const MULTI_STORE_PATH_SENTINEL = "(multiple)";
export function resolveSessionFilePathOptions(params: {
agentId?: string;
storePath?: string;
}): SessionFilePathOptions | undefined {
const agentId = params.agentId?.trim();
const storePath = params.storePath?.trim();
if (storePath) {
if (storePath && storePath !== MULTI_STORE_PATH_SENTINEL) {
const sessionsDir = path.dirname(path.resolve(storePath));
return agentId ? { sessionsDir, agentId } : { sessionsDir };
}

View File

@@ -13,6 +13,7 @@ import {
import type { SessionConfig } from "../types.base.js";
import {
resolveSessionFilePath,
resolveSessionFilePathOptions,
resolveSessionTranscriptPathInDir,
validateSessionId,
} from "./paths.js";
@@ -68,6 +69,13 @@ describe("session path safety", () => {
expect(resolved).toBe(path.resolve(sessionsDir, "sess-1.jsonl"));
});
it("ignores multi-store sentinel paths when deriving session file options", () => {
expect(resolveSessionFilePathOptions({ agentId: "worker", storePath: "(multiple)" })).toEqual({
agentId: "worker",
});
expect(resolveSessionFilePathOptions({ storePath: "(multiple)" })).toBeUndefined();
});
it("accepts symlink-alias session paths that resolve under the sessions dir", () => {
if (process.platform === "win32") {
return;