diff --git a/app/[workspace]/project/[projectId]/build/page.tsx b/app/[workspace]/project/[projectId]/build/page.tsx index 4115426..f1c20b9 100644 --- a/app/[workspace]/project/[projectId]/build/page.tsx +++ b/app/[workspace]/project/[projectId]/build/page.tsx @@ -285,15 +285,26 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName if (el) el.scrollTop = el.scrollHeight; }, []); - // Load session list + // Load session list — auto-select the most recent active or last session useEffect(() => { if (!appName) return; setLoadingSessions(true); fetch(`/api/projects/${projectId}/agent/sessions`) .then(r => r.json()) - .then(d => { setSessions(d.sessions ?? []); setLoadingSessions(false); }) + .then(d => { + const list: AgentSession[] = d.sessions ?? []; + setSessions(list); + setLoadingSessions(false); + // Auto-select: prefer running/pending, then the most recent + if (list.length > 0 && !activeSessionId) { + const live = list.find(s => s.status === "running" || s.status === "pending"); + const pick = live ?? list[0]; + setActiveSessionId(pick.id); + setActiveSession(pick); + } + }) .catch(() => setLoadingSessions(false)); - }, [projectId, appName]); + }, [projectId, appName]); // eslint-disable-line react-hooks/exhaustive-deps // Adaptive polling — 500ms while running, 5s when idle useEffect(() => { @@ -619,38 +630,123 @@ function AgentMode({ projectId, appName, appPath }: { projectId: string; appName )} - {/* Task input */} -
-
-