fix: initialize reset transcript files

This commit is contained in:
Tak Hoffman 2026-03-26 21:08:57 -05:00
parent 77d15841d7
commit 3e5d86384e
No known key found for this signature in database
2 changed files with 18 additions and 0 deletions

View File

@ -1111,6 +1111,7 @@ describe("gateway server sessions", () => {
expect(reset.payload?.entry.modelProvider).toBe("openai");
expect(reset.payload?.entry.model).toBe("gpt-test-a");
expect(reset.payload?.entry.contextTokens).toBeUndefined();
await expect(fs.stat(reset.payload?.entry.sessionFile as string)).resolves.toBeTruthy();
ws.close();
});

View File

@ -1,4 +1,7 @@
import { randomUUID } from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { CURRENT_SESSION_VERSION } from "@mariozechner/pi-coding-agent";
import { getAcpSessionManager } from "../acp/control-plane/manager.js";
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
import { clearBootstrapSnapshot } from "../agents/bootstrap-cache.js";
@ -387,6 +390,20 @@ export async function performGatewaySessionReset(params: {
agentId: target.agentId,
reason: "reset",
});
fs.mkdirSync(path.dirname(next.sessionFile as string), { recursive: true });
if (!fs.existsSync(next.sessionFile as string)) {
const header = {
type: "session",
version: CURRENT_SESSION_VERSION,
id: next.sessionId,
timestamp: new Date().toISOString(),
cwd: process.cwd(),
};
fs.writeFileSync(next.sessionFile as string, `${JSON.stringify(header)}\n`, {
encoding: "utf-8",
mode: 0o600,
});
}
if (hadExistingEntry) {
await emitSessionUnboundLifecycleEvent({
targetSessionKey: target.canonicalKey ?? params.key,