






















@@ -1,7 +1,7 @@
11import { randomUUID } from "node:crypto";
22import fs from "node:fs";
33import path from "node:path";
4-import { CURRENT_SESSION_VERSION, SessionManager } from "@mariozechner/pi-coding-agent";
4+import { CURRENT_SESSION_VERSION } from "@mariozechner/pi-coding-agent";
55import { resolveAgentRuntimeMetadata } from "../../agents/agent-runtime-metadata.js";
66import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../agents/agent-scope.js";
77import {
@@ -66,6 +66,7 @@ import {
6666} from "../protocol/index.js";
6767import { resolveSessionKeyForRun } from "../server-session-key.js";
6868import {
69+forkCompactionCheckpointTranscriptAsync,
6970getSessionCompactionCheckpoint,
7071listSessionCompactionCheckpoints,
7172} from "../session-compaction-checkpoints.js";
@@ -1089,26 +1090,11 @@ export const sessionsHandlers: GatewayRequestHandlers = {
10891090);
10901091return;
10911092}
1092-if (!fs.existsSync(checkpoint.preCompaction.sessionFile)) {
1093-respond(
1094-false,
1095-undefined,
1096-errorShape(ErrorCodes.UNAVAILABLE, "checkpoint snapshot transcript is missing"),
1097-);
1098-return;
1099-}
1100-1101-const snapshotSession = SessionManager.open(
1102-checkpoint.preCompaction.sessionFile,
1103-path.dirname(checkpoint.preCompaction.sessionFile),
1104-);
1105-const branchedSession = SessionManager.forkFrom(
1106-checkpoint.preCompaction.sessionFile,
1107-snapshotSession.getCwd(),
1108-path.dirname(checkpoint.preCompaction.sessionFile),
1109-);
1110-const branchedSessionFile = branchedSession.getSessionFile();
1111-if (!branchedSessionFile) {
1093+const branchedSession = await forkCompactionCheckpointTranscriptAsync({
1094+sourceFile: checkpoint.preCompaction.sessionFile,
1095+sessionDir: path.dirname(checkpoint.preCompaction.sessionFile),
1096+});
1097+if (!branchedSession?.sessionFile) {
11121098respond(
11131099false,
11141100undefined,
@@ -1120,8 +1106,8 @@ export const sessionsHandlers: GatewayRequestHandlers = {
11201106const label = entry.label?.trim() ? `${entry.label.trim()} (checkpoint)` : "Checkpoint branch";
11211107const nextEntry = cloneCheckpointSessionEntry({
11221108currentEntry: entry,
1123-nextSessionId: branchedSession.getSessionId(),
1124-nextSessionFile: branchedSessionFile,
1109+nextSessionId: branchedSession.sessionId,
1110+nextSessionFile: branchedSession.sessionFile,
11251111 label,
11261112parentSessionKey: canonicalKey,
11271113totalTokens: checkpoint.tokensBefore,
@@ -1203,15 +1189,6 @@ export const sessionsHandlers: GatewayRequestHandlers = {
12031189);
12041190return;
12051191}
1206-if (!fs.existsSync(checkpoint.preCompaction.sessionFile)) {
1207-respond(
1208-false,
1209-undefined,
1210-errorShape(ErrorCodes.UNAVAILABLE, "checkpoint snapshot transcript is missing"),
1211-);
1212-return;
1213-}
1214-12151192const interruptResult = await interruptSessionRunIfActive({
12161193 req,
12171194 context,
@@ -1226,17 +1203,11 @@ export const sessionsHandlers: GatewayRequestHandlers = {
12261203return;
12271204}
122812051229-const snapshotSession = SessionManager.open(
1230-checkpoint.preCompaction.sessionFile,
1231-path.dirname(checkpoint.preCompaction.sessionFile),
1232-);
1233-const restoredSession = SessionManager.forkFrom(
1234-checkpoint.preCompaction.sessionFile,
1235-snapshotSession.getCwd(),
1236-path.dirname(checkpoint.preCompaction.sessionFile),
1237-);
1238-const restoredSessionFile = restoredSession.getSessionFile();
1239-if (!restoredSessionFile) {
1206+const restoredSession = await forkCompactionCheckpointTranscriptAsync({
1207+sourceFile: checkpoint.preCompaction.sessionFile,
1208+sessionDir: path.dirname(checkpoint.preCompaction.sessionFile),
1209+});
1210+if (!restoredSession?.sessionFile) {
12401211respond(
12411212false,
12421213undefined,
@@ -1246,8 +1217,8 @@ export const sessionsHandlers: GatewayRequestHandlers = {
12461217}
12471218const nextEntry = cloneCheckpointSessionEntry({
12481219currentEntry: entry,
1249-nextSessionId: restoredSession.getSessionId(),
1250-nextSessionFile: restoredSessionFile,
1220+nextSessionId: restoredSession.sessionId,
1221+nextSessionFile: restoredSession.sessionFile,
12511222totalTokens: checkpoint.tokensBefore,
12521223preserveCompactionCheckpoints: true,
12531224});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。