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(),
};
@@ -223,6 +223,7 @@ function collectShareRegexSecretValues(o: SecretObfuscator, data: SessionData):
if (!header) return;
add(header.title);
add(header.cwd);
for (const previousSessionFile of header.previousSessionFiles ?? []) add(previousSessionFile);
};
addHeader(data.header);
@@ -246,6 +247,9 @@ function redactShareHeader(
...header,
title: header.title === undefined ? undefined : o.obfuscate(header.title, sharedRegexSecretValues),
cwd: o.obfuscate(header.cwd, sharedRegexSecretValues),
previousSessionFiles: header.previousSessionFiles?.map(previousSessionFile =>
o.obfuscate(previousSessionFile, sharedRegexSecretValues),
),
};
}