fix(electrobun): preserve conversation history when resuming session (don't clearSession on resume)
This commit is contained in:
parent
78d77080cc
commit
1afbe66fd7
1 changed files with 28 additions and 11 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue