diff --git a/chat/public/builder.js b/chat/public/builder.js index b0e6417..510ae6c 100644 --- a/chat/public/builder.js +++ b/chat/public/builder.js @@ -323,14 +323,25 @@ async function redoMessage(msg, session) { // Case 1: Proceed with Build - undo first, then rebuild with plan content if (isProceedWithBuild) { - // First, send undo to revert any file changes - try { - await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, { - method: 'POST', - }); - setStatus('Undo complete, rebuilding...'); - } catch (err) { - console.warn('Undo failed, continuing with redo:', err.message); + // Check if this is the first opencode message (nothing to undo yet) + const messageIndex = session.messages.findIndex(m => m.id === msg.id); + const hasPreviousOpencodeMessages = session.messages + .slice(0, messageIndex) + .some(m => m.cli === 'opencode'); + + // Only undo if there are previous opencode messages + if (hasPreviousOpencodeMessages) { + try { + await api(`/api/sessions/${session.id}/messages/${msg.id}/undo`, { + method: 'POST', + }); + setStatus('Undo complete, rebuilding...'); + } catch (err) { + console.warn('Undo failed, continuing with redo:', err.message); + } + } else { + console.log('First build message - skipping undo, proceeding directly to rebuild'); + setStatus('Starting build...'); } // Get the plan content - either stored on the message or try to extract from content