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 */}
-
-
-
-
- ⌘↵ to start · Each task is a new session · Use "Follow up" on a failed session to continue it
-
-
+ {/* Task input — context-aware */}
+ {(() => {
+ const st = activeSession?.status;
+
+ // Agent is actively working — lock input
+ if (st === "running" || st === "pending") {
+ return (
+
+
+
+
+ Agent is working — wait for it to finish, or stop it above.
+
+
+
+ );
+ }
+
+ // Session completed successfully — offer follow-up or new task
+ if (st === "done") {
+ return (
+
+ {showFollowUp ? (
+
+
+ Describe the next thing to build (continues from this session's context):
+
+
+
+ ⌘↵ to run · Esc to cancel · Starts a new session for this task
+
+
+ ) : (
+
+
+ ✓ Done — approve the changes above, or continue building.
+
+
+
+
+ )}
+
+ );
+ }
+
+ // No active session (or failed/stopped handled above) — new task input
+ if (!activeSession) {
+ return (
+
+
+
+
+ ⌘↵ to start · The agent works autonomously until done · You approve before anything is committed
+
+
+ );
+ }
+
+ return null;
+ })()}
);