diff --git a/src/auto-reply/reply/commands-export-session.test.ts b/src/auto-reply/reply/commands-export-session.test.ts index 6d49a786b8f..8ac3e5c3755 100644 --- a/src/auto-reply/reply/commands-export-session.test.ts +++ b/src/auto-reply/reply/commands-export-session.test.ts @@ -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", + }), + }), + ); + }); }); diff --git a/src/auto-reply/reply/commands-export-session.ts b/src/auto-reply/reply/commands-export-session.ts index 433004ad3f7..3209f716df7 100644 --- a/src/auto-reply/reply/commands-export-session.ts +++ b/src/auto-reply/reply/commands-export-session.ts @@ -114,12 +114,7 @@ function parseExportArgs(commandBodyNormalized: string): { outputPath?: string } export async function buildExportSessionReply(params: HandleCommandsParams): Promise { 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 = {