

























@@ -4,10 +4,15 @@ import {
44normalizeLowercaseStringOrEmpty,
55normalizeOptionalLowercaseString,
66} from "../../shared/string-coerce.js";
7+import {
8+resolveTrajectoryFilePath,
9+resolveTrajectoryPointerFilePath,
10+} from "../../trajectory/paths.js";
711import {
812isCompactionCheckpointTranscriptFileName,
913isPrimarySessionTranscriptFileName,
1014isSessionArchiveArtifactName,
15+isTrajectorySessionArtifactName,
1116} from "./artifacts.js";
1217import { resolveSessionFilePath } from "./paths.js";
1318import type { SessionEntry } from "./types.js";
@@ -119,18 +124,39 @@ function resolveSessionTranscriptPathForEntry(params: {
119124}
120125}
121126122-function resolveReferencedSessionTranscriptPaths(params: {
127+function resolveSessionArtifactPathsForEntry(params: {
128+sessionsDir: string;
129+entry: SessionEntry;
130+}): string[] {
131+const transcriptPath = resolveSessionTranscriptPathForEntry(params);
132+if (!transcriptPath) {
133+return [];
134+}
135+const paths = [transcriptPath];
136+if (params.entry.sessionId) {
137+paths.push(resolveTrajectoryPointerFilePath(transcriptPath));
138+paths.push(
139+resolveTrajectoryFilePath({
140+env: {},
141+sessionFile: transcriptPath,
142+sessionId: params.entry.sessionId,
143+}),
144+);
145+}
146+return paths;
147+}
148+149+function resolveReferencedSessionArtifactPaths(params: {
123150sessionsDir: string;
124151store: Record<string, SessionEntry>;
125152}): Set<string> {
126153const referenced = new Set<string>();
127154const resolvedSessionsDir = canonicalizePathForComparison(params.sessionsDir);
128155for (const entry of Object.values(params.store)) {
129-const resolved = resolveSessionTranscriptPathForEntry({
156+for (const resolved of resolveSessionArtifactPathsForEntry({
130157sessionsDir: params.sessionsDir,
131158 entry,
132-});
133-if (resolved) {
159+})) {
134160referenced.add(canonicalizePathForComparison(resolved));
135161}
136162for (const checkpoint of entry.compactionCheckpoints ?? []) {
@@ -267,7 +293,7 @@ export async function enforceSessionDiskBudget(params: {
267293let removedEntries = 0;
268294let freedBytes = 0;
269295270-const referencedPaths = resolveReferencedSessionTranscriptPaths({
296+const referencedPaths = resolveReferencedSessionArtifactPaths({
271297 sessionsDir,
272298store: params.store,
273299});
@@ -277,6 +303,7 @@ export async function enforceSessionDiskBudget(params: {
277303isSessionArchiveArtifactName(file.name) ||
278304(isCompactionCheckpointTranscriptFileName(file.name) &&
279305!referencedPaths.has(file.canonicalPath)) ||
306+(isTrajectorySessionArtifactName(file.name) && !referencedPaths.has(file.canonicalPath)) ||
280307(isPrimarySessionTranscriptFileName(file.name) && !referencedPaths.has(file.canonicalPath)),
281308)
282309.toSorted((a, b) => a.mtimeMs - b.mtimeMs);
@@ -342,22 +369,20 @@ export async function enforceSessionDiskBudget(params: {
342369continue;
343370}
344371sessionIdRefCounts.delete(sessionId);
345-const transcriptPath = resolveSessionTranscriptPathForEntry({ sessionsDir, entry });
346-if (!transcriptPath) {
347-continue;
348-}
349-const deletedBytes = await removeFileForBudget({
350-filePath: transcriptPath,
351- dryRun,
352- fileSizesByPath,
353- simulatedRemovedPaths,
354-});
355-if (deletedBytes <= 0) {
356-continue;
372+for (const artifactPath of resolveSessionArtifactPathsForEntry({ sessionsDir, entry })) {
373+const deletedBytes = await removeFileForBudget({
374+filePath: artifactPath,
375+ dryRun,
376+ fileSizesByPath,
377+ simulatedRemovedPaths,
378+});
379+if (deletedBytes <= 0) {
380+continue;
381+}
382+total -= deletedBytes;
383+freedBytes += deletedBytes;
384+removedFiles += 1;
357385}
358-total -= deletedBytes;
359-freedBytes += deletedBytes;
360-removedFiles += 1;
361386}
362387}
363388此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。