fix: use target session entry for export

This commit is contained in:
Tak Hoffman
2026-04-10 20:17:00 -05:00
parent 343541217a
commit a2dbc1b63c
2 changed files with 29 additions and 7 deletions

View File

@@ -164,4 +164,28 @@ describe("buildExportSessionReply", () => {
storePath: "/tmp/custom-store/sessions.json",
});
});
it("uses the target store entry even when the wrapper sessionEntry is missing", async () => {
const { buildExportSessionReply } = await import("./commands-export-session.js");
hoisted.loadSessionStoreMock.mockReturnValue({
"agent:target:session": {
sessionId: "session-from-store",
updatedAt: 2,
},
});
const reply = await buildExportSessionReply({
...makeParams(),
sessionEntry: undefined,
});
expect(reply.text).toContain("✅ Session exported!");
expect(hoisted.resolveCommandsSystemPromptBundleMock).toHaveBeenCalledWith(
expect.objectContaining({
sessionEntry: expect.objectContaining({
sessionId: "session-from-store",
}),
}),
);
});
});

View File

@@ -114,12 +114,7 @@ function parseExportArgs(commandBodyNormalized: string): { outputPath?: string }
export async function buildExportSessionReply(params: HandleCommandsParams): Promise<ReplyPayload> {
const args = parseExportArgs(params.command.commandBodyNormalized);
// 1. Resolve session file
const sessionEntry = params.sessionEntry;
if (!sessionEntry?.sessionId) {
return { text: "❌ No active session found." };
}
// 1. Resolve target session entry and session file from the canonical target store.
const targetAgentId = resolveAgentIdFromSessionKey(params.sessionKey) || params.agentId;
const storePath = params.storePath ?? resolveDefaultSessionStorePath(targetAgentId);
const store = loadSessionStore(storePath, { skipCache: true });
@@ -152,7 +147,10 @@ export async function buildExportSessionReply(params: HandleCommandsParams): Pro
const leafId = sessionManager.getLeafId();
// 3. Build full system prompt
const { systemPrompt, tools } = await resolveCommandsSystemPromptBundle(params);
const { systemPrompt, tools } = await resolveCommandsSystemPromptBundle({
...params,
sessionEntry: entry as HandleCommandsParams["sessionEntry"],
});
// 4. Prepare session data
const sessionData: SessionData = {