From 1afbe66fd7850a1acd64738c75fb23ca39e1227e Mon Sep 17 00:00:00 2001 From: Hibryda Date: Fri, 27 Mar 2026 03:59:22 +0100 Subject: [PATCH] fix(electrobun): preserve conversation history when resuming session (don't clearSession on resume) --- .../src/mainview/agent-store.svelte.ts | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/ui-electrobun/src/mainview/agent-store.svelte.ts b/ui-electrobun/src/mainview/agent-store.svelte.ts index 9764fb8..092c945 100644 --- a/ui-electrobun/src/mainview/agent-store.svelte.ts +++ b/ui-electrobun/src/mainview/agent-store.svelte.ts @@ -546,9 +546,6 @@ async function _startAgentInner( prompt: string, options: StartOptions, ): Promise<{ ok: boolean; error?: string }> { - // If there's an existing done/error session for this project, clear it first - clearSession(projectId); - // Check for pending resume (user selected a session in the picker) const pending = pendingResumes.get(projectId); if (pending) { @@ -559,6 +556,13 @@ async function _startAgentInner( } } + const isResume = options.resumeMode === 'continue' || options.resumeMode === 'resume'; + + // If resuming, keep existing session messages; if new, clear old session + if (!isResume) { + clearSession(projectId); + } + const sessionId = `${projectId}-${Date.now()}`; // Read settings defaults if not explicitly provided (Fix #5) @@ -587,25 +591,38 @@ async function _startAgentInner( } } catch { /* use provided or defaults */ } - // Create reactive session state + // Create reactive session state — carry forward messages if resuming + const existingSessionId = projectSessionMap.get(projectId); + const existingMessages = (isResume && existingSessionId && sessions[existingSessionId]) + ? [...sessions[existingSessionId].messages] + : []; + + // Add the new user prompt to messages + const newUserMsg = { + id: `${sessionId}-user-0`, + seqId: nextSeqId(sessionId), + role: 'user' as const, + content: prompt, + timestamp: Date.now(), + }; + sessions[sessionId] = { sessionId, projectId, provider, status: 'running', - messages: [{ - id: `${sessionId}-user-0`, - seqId: nextSeqId(sessionId), - role: 'user', - content: prompt, - timestamp: Date.now(), - }], + messages: [...existingMessages, newUserMsg], costUsd: 0, inputTokens: 0, outputTokens: 0, model: defaultModel ?? 'claude-opus-4-5', }; + // Clean up the old session entry if resuming (we moved messages to the new one) + if (isResume && existingSessionId && existingSessionId !== sessionId) { + delete sessions[existingSessionId]; + } + projectSessionMap.set(projectId, sessionId); bump(); // Force re-render — new session created resetStallTimer(sessionId, projectId);