From 2edcd6ae027f31b53e8f2b0d63e430e50b5a9430 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Thu, 9 Oct 2025 12:42:43 -0700 Subject: [PATCH] feat: background agents --- core/index.d.ts | 2 +- .../components/BackgroundMode/AgentsList.tsx | 166 ++++++++++++++++++ .../BackgroundMode/BackgroundModeView.tsx | 55 ++++++ gui/src/components/ModeSelect/ModeIcon.tsx | 3 + gui/src/components/ModeSelect/ModeSelect.tsx | 28 ++- gui/src/pages/gui/Chat.tsx | 25 ++- 6 files changed, 275 insertions(+), 4 deletions(-) create mode 100644 gui/src/components/BackgroundMode/AgentsList.tsx create mode 100644 gui/src/components/BackgroundMode/BackgroundModeView.tsx diff --git a/core/index.d.ts b/core/index.d.ts index fb59d97bd..56e65d3f2 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -462,7 +462,7 @@ export interface PromptLog { completion: string; } -export type MessageModes = "chat" | "agent" | "plan"; +export type MessageModes = "chat" | "agent" | "plan" | "background"; export type ToolStatus = | "generating" // Tool call arguments are being streamed from the LLM diff --git a/gui/src/components/BackgroundMode/AgentsList.tsx b/gui/src/components/BackgroundMode/AgentsList.tsx new file mode 100644 index 000000000..dad28dbe5 --- /dev/null +++ b/gui/src/components/BackgroundMode/AgentsList.tsx @@ -0,0 +1,166 @@ +import { Loader2 } from "lucide-react"; +import { useContext, useEffect, useState } from "react"; +import { useAuth } from "../../context/Auth"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; + +interface Agent { + id: string; + name: string | null; + status: string; + repoUrl: string; + createdAt: string; + metadata?: { + github_repo?: string; + }; +} + +export function AgentsList() { + const { session } = useAuth(); + const ideMessenger = useContext(IdeMessengerContext); + const [agents, setAgents] = useState([]); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + async function fetchAgents() { + if (!session) { + setAgents([]); + setIsLoading(false); + return; + } + + try { + setIsLoading(true); + // Request agent list from IDE + const result = await ideMessenger.request("listBackgroundAgents", {}); + + if (result && Array.isArray(result)) { + setAgents(result); + setError(null); + } else { + setAgents([]); + } + } catch (err: any) { + console.error("Failed to fetch agents:", err); + setError(err.message || "Failed to load agents"); + setAgents([]); + } finally { + setIsLoading(false); + } + } + + void fetchAgents(); + + // Poll for updates every 10 seconds + const interval = setInterval(() => { + void fetchAgents(); + }, 10000); + + return () => clearInterval(interval); + }, [session, ideMessenger]); + + if (isLoading) { + return ( +
+ +
+ ); + } + + if (error) { + return ( +
+ Error loading agents: {error} +
+ ); + } + + if (agents.length === 0) { + return ( +
+ No background agents yet. Submit a message above to create one. +
+ ); + } + + return ( +
+
+ Recent Agents +
+
+ {agents.map((agent) => ( +
{ + // Open agent detail in browser + const agentUrl = `https://app.continue.dev/agents/${agent.id}`; + ideMessenger.post("openUrl", agentUrl); + }} + > +
+
+
+ {agent.name || "Unnamed Agent"} +
+
+ {agent.metadata?.github_repo || agent.repoUrl} +
+
+
+ +
+
+
+ {formatRelativeTime(agent.createdAt)} +
+
+ ))} +
+
+ ); +} + +function AgentStatusBadge({ status }: { status: string }) { + const statusColors: Record = { + running: "bg-green-100 text-green-800", + pending: "bg-yellow-100 text-yellow-800", + creating: "bg-blue-100 text-blue-800", + failure: "bg-red-100 text-red-800", + suspended: "bg-gray-100 text-gray-800", + }; + + const color = statusColors[status] || "bg-gray-100 text-gray-800"; + + return ( + + {status} + + ); +} + +function formatRelativeTime(dateString: string): string { + try { + const date = new Date(dateString); + const now = new Date(); + const diffMs = now.getTime() - date.getTime(); + const diffMins = Math.floor(diffMs / 60000); + const diffHours = Math.floor(diffMs / 3600000); + const diffDays = Math.floor(diffMs / 86400000); + + if (diffMins < 1) { + return "just now"; + } else if (diffMins < 60) { + return `${diffMins}m ago`; + } else if (diffHours < 24) { + return `${diffHours}h ago`; + } else { + return `${diffDays}d ago`; + } + } catch { + return dateString; + } +} diff --git a/gui/src/components/BackgroundMode/BackgroundModeView.tsx b/gui/src/components/BackgroundMode/BackgroundModeView.tsx new file mode 100644 index 000000000..0c3d68aa8 --- /dev/null +++ b/gui/src/components/BackgroundMode/BackgroundModeView.tsx @@ -0,0 +1,55 @@ +import { RocketLaunchIcon } from "@heroicons/react/24/outline"; +import { useCallback, useState } from "react"; +import { useAuth } from "../../context/Auth"; +import { AgentsList } from "./AgentsList"; + +interface BackgroundModeViewProps { + onCreateAgent: (prompt: string) => void; +} + +export function BackgroundModeView({ onCreateAgent }: BackgroundModeViewProps) { + const { session, login } = useAuth(); + const [isLoggingIn, setIsLoggingIn] = useState(false); + + const handleSignIn = useCallback(async () => { + setIsLoggingIn(true); + try { + await login(false); + } catch (error) { + console.error("Login failed:", error); + } finally { + setIsLoggingIn(false); + } + }, [login]); + + if (!session) { + return ( +
+ +
+

Background Agents

+

+ Trigger long-running background agents that work on your codebase + autonomously. Sign in to Continue to get started. +

+ +
+
+ ); + } + + return ( +
+
+ Agents you trigger will run in the background and appear below. +
+ +
+ ); +} diff --git a/gui/src/components/ModeSelect/ModeIcon.tsx b/gui/src/components/ModeSelect/ModeIcon.tsx index 92dfc1723..074185886 100644 --- a/gui/src/components/ModeSelect/ModeIcon.tsx +++ b/gui/src/components/ModeSelect/ModeIcon.tsx @@ -1,5 +1,6 @@ import { ChatBubbleLeftIcon, + RocketLaunchIcon, SparklesIcon, SwatchIcon, } from "@heroicons/react/24/outline"; @@ -21,5 +22,7 @@ export function ModeIcon({ return ; case "chat": return ; + case "background": + return ; } } diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index 88a549012..19904d8d3 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -39,6 +39,8 @@ export function ModeSelect() { dispatch(setMode("plan")); } else if (mode === "plan") { dispatch(setMode("agent")); + } else if (mode === "agent") { + dispatch(setMode("background")); } else { dispatch(setMode("chat")); } @@ -96,7 +98,13 @@ export function ModeSelect() { > - {mode === "chat" ? "Chat" : mode === "agent" ? "Agent" : "Plan"} + {mode === "chat" + ? "Chat" + : mode === "agent" + ? "Agent" + : mode === "background" + ? "Background" + : "Plan"} + +
+ + Background + + + +
+ +
+
{`${metaKeyLabel} . for next mode`}
diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 61fc0a859..0d7f1a71b 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -44,6 +44,7 @@ import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; import { ToolCallDiv } from "./ToolCallDiv"; import { useStore } from "react-redux"; +import { BackgroundModeView } from "../../components/BackgroundMode/BackgroundModeView"; import { CliInstallBanner } from "../../components/CliInstallBanner"; import { FatalErrorIndicator } from "../../components/config/FatalErrorNotice"; import InlineErrorMessage from "../../components/mainInput/InlineErrorMessage"; @@ -125,6 +126,7 @@ export function Chat() { const hasDismissedExploreDialog = useAppSelector( (state) => state.ui.hasDismissedExploreDialog, ); + const mode = useAppSelector((state) => state.session.mode); const jetbrains = useMemo(() => { return isJetBrains(); }, []); @@ -169,6 +171,17 @@ export function Chat() { const codeToEditSnapshot = stateSnapshot.editModeState.codeToEdit; const selectedModelByRole = stateSnapshot.config.config.selectedModelByRole; + const currentMode = stateSnapshot.session.mode; + + // Handle background mode specially + if (currentMode === "background" && !isCurrentlyInEdit) { + // Background mode triggers agent creation instead of chat + ideMessenger.post("createBackgroundAgent", { editorState }); + if (editorToClearOnSend) { + editorToClearOnSend.commands.clearContent(); + } + return; + } // Cancel all pending tool calls latestPendingToolCalls.forEach((toolCallState) => { @@ -457,8 +470,16 @@ export function Chat() { {!hasDismissedExploreDialog && } - {history.length === 0 && ( - + {mode === "background" ? ( + { + ideMessenger.post("createBackgroundAgent", { prompt }); + }} + /> + ) : ( + history.length === 0 && ( + + ) )}