fix(coding-agent): harden archived stats cleanup

This commit is contained in:
Sunil Srivatsa
2026-08-01 17:17:46 -04:00
parent f3a555ac78
commit 980ab4fd0a
9 changed files with 702 additions and 129 deletions
+10 -3
View File
@@ -181,10 +181,17 @@ export interface SessionData {
subSessions?: Record<string, SubSession>;
}
function sessionHeaderForExport(header: SessionHeader | null): SessionHeader | null {
if (!header) return null;
const exported = { ...header };
delete exported.previousSessionFiles;
return exported;
}
/** Snapshot the session (plus optional agent state) into the JSON shape the viewer renders. */
export function buildSessionData(sm: SessionManager, state?: AgentState): SessionData {
return {
header: sm.getHeader(),
header: sessionHeaderForExport(sm.getHeader()),
entries: sm.getEntries(),
leafId: sm.getLeafId(),
systemPrompt: state?.systemPrompt.join("\n\n"),
@@ -231,7 +238,7 @@ async function collectSubSessionsFromDir(
out[key] = {
agentId,
parent: parentKey,
header,
header: sessionHeaderForExport(header),
entries,
leafId: entries.length > 0 ? entries[entries.length - 1].id : null,
};
@@ -295,7 +302,7 @@ export async function exportFromFile(inputPath: string, options?: ExportOptions
}
const sessionData: SessionData = {
header: sm.getHeader(),
header: sessionHeaderForExport(sm.getHeader()),
entries: sm.getEntries(),
leafId: sm.getLeafId(),
};