refactor(session): centralize transcript path option resolution

This commit is contained in:
Peter Steinberger
2026-02-22 12:00:54 +01:00
parent 37f12eb7ee
commit b77e53da67
5 changed files with 58 additions and 14 deletions

View File

@@ -8,6 +8,7 @@ import { hasNonzeroUsage } from "../../agents/usage.js";
import {
resolveAgentIdFromSessionKey,
resolveSessionFilePath,
resolveSessionFilePathOptions,
resolveSessionTranscriptPath,
type SessionEntry,
updateSessionStore,
@@ -324,7 +325,11 @@ export async function runReplyAgent(params: {
defaultRuntime.error(buildLogMessage(nextSessionId));
if (cleanupTranscripts && prevSessionId) {
const transcriptCandidates = new Set<string>();
const resolved = resolveSessionFilePath(prevSessionId, prevEntry, { agentId });
const resolved = resolveSessionFilePath(
prevSessionId,
prevEntry,
resolveSessionFilePathOptions({ agentId, storePath }),
);
if (resolved) {
transcriptCandidates.add(resolved);
}

View File

@@ -6,6 +6,7 @@ import { SessionManager } from "@mariozechner/pi-coding-agent";
import {
resolveDefaultSessionStorePath,
resolveSessionFilePath,
resolveSessionFilePathOptions,
} from "../../config/sessions/paths.js";
import { loadSessionStore } from "../../config/sessions/store.js";
import type { SessionEntry } from "../../config/sessions/types.js";
@@ -126,10 +127,11 @@ export async function buildExportSessionReply(params: HandleCommandsParams): Pro
let sessionFile: string;
try {
sessionFile = resolveSessionFilePath(entry.sessionId, entry, {
agentId: params.agentId,
sessionsDir: path.dirname(storePath),
});
sessionFile = resolveSessionFilePath(
entry.sessionId,
entry,
resolveSessionFilePathOptions({ agentId: params.agentId, storePath }),
);
} catch (err) {
return {
text: `❌ Failed to resolve session file: ${err instanceof Error ? err.message : String(err)}`,