From 75d9644d44ba998a32ed14c072e883a75145ab72 Mon Sep 17 00:00:00 2001 From: soryu Date: Fri, 16 Jan 2026 19:50:27 +0000 Subject: Add autopilot panel and retry system --- .../src/components/contracts/AutopilotPanel.tsx | 208 +++++++++++++++++++++ .../src/components/contracts/ContractDetail.tsx | 7 + makima/frontend/src/lib/api.ts | 114 +++++++++++ makima/frontend/tsconfig.tsbuildinfo | 2 +- 4 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 makima/frontend/src/components/contracts/AutopilotPanel.tsx (limited to 'makima/frontend') diff --git a/makima/frontend/src/components/contracts/AutopilotPanel.tsx b/makima/frontend/src/components/contracts/AutopilotPanel.tsx new file mode 100644 index 0000000..a8a8e2e --- /dev/null +++ b/makima/frontend/src/components/contracts/AutopilotPanel.tsx @@ -0,0 +1,208 @@ +import { useState, useCallback } from "react"; +import type { ContractWithRelations } from "../../lib/api"; +import { + getSupervisorStatus, + startSupervisor, + stopSupervisor, + resumeSupervisor, + type SupervisorStatus, +} from "../../lib/api"; + +interface AutopilotPanelProps { + contract: ContractWithRelations; + onUpdate: () => void; +} + +const statusConfig: Record< + SupervisorStatus["status"], + { label: string; color: string; bgColor: string } +> = { + not_configured: { + label: "Not Configured", + color: "text-[#555]", + bgColor: "bg-[#555]/10", + }, + pending: { + label: "Ready", + color: "text-yellow-400", + bgColor: "bg-yellow-400/10", + }, + starting: { + label: "Starting...", + color: "text-blue-400", + bgColor: "bg-blue-400/10", + }, + running: { + label: "Running", + color: "text-green-400", + bgColor: "bg-green-400/10", + }, + paused: { + label: "Paused", + color: "text-orange-400", + bgColor: "bg-orange-400/10", + }, + done: { + label: "Completed", + color: "text-blue-400", + bgColor: "bg-blue-400/10", + }, + failed: { + label: "Failed", + color: "text-red-400", + bgColor: "bg-red-400/10", + }, +}; + +export function AutopilotPanel({ contract, onUpdate }: AutopilotPanelProps) { + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + const supervisorStatus = getSupervisorStatus(contract); + const config = statusConfig[supervisorStatus.status]; + + const handleStart = useCallback(async () => { + if (!supervisorStatus.supervisorTaskId) return; + + setLoading(true); + setError(null); + + try { + await startSupervisor(supervisorStatus.supervisorTaskId); + onUpdate(); + } catch (e) { + setError(e instanceof Error ? e.message : "Failed to start autopilot"); + } finally { + setLoading(false); + } + }, [supervisorStatus.supervisorTaskId, onUpdate]); + + const handleStop = useCallback(async () => { + if (!supervisorStatus.supervisorTaskId) return; + + setLoading(true); + setError(null); + + try { + await stopSupervisor(supervisorStatus.supervisorTaskId); + onUpdate(); + } catch (e) { + setError(e instanceof Error ? e.message : "Failed to stop autopilot"); + } finally { + setLoading(false); + } + }, [supervisorStatus.supervisorTaskId, onUpdate]); + + const handleResume = useCallback(async () => { + setLoading(true); + setError(null); + + try { + await resumeSupervisor(contract.id, { resumeMode: "continue" }); + // After resuming, we need to start the task + if (supervisorStatus.supervisorTaskId) { + await startSupervisor(supervisorStatus.supervisorTaskId); + } + onUpdate(); + } catch (e) { + setError(e instanceof Error ? e.message : "Failed to resume autopilot"); + } finally { + setLoading(false); + } + }, [contract.id, supervisorStatus.supervisorTaskId, onUpdate]); + + // Don't show panel for task-type contracts (they don't have supervisors) + if (contract.contractType === "task") { + return null; + } + + return ( +
+
+

+ Autopilot Mode +

+
+ {config.label} +
+
+ +

+ {supervisorStatus.status === "not_configured" ? ( + "This contract does not have an autopilot supervisor configured." + ) : supervisorStatus.status === "running" ? ( + "Autopilot is actively working on this contract, spawning tasks and managing progress." + ) : supervisorStatus.status === "pending" ? ( + "Autopilot is ready to start. Click 'Enable' to begin autonomous work." + ) : supervisorStatus.status === "paused" ? ( + "Autopilot is paused. Click 'Resume' to continue work." + ) : supervisorStatus.status === "failed" ? ( + "Autopilot encountered an error. You can resume to retry." + ) : supervisorStatus.status === "done" ? ( + "Autopilot has completed its work on this contract." + ) : ( + "Autopilot is initializing..." + )} +

+ + {error && ( +
+ {error} +
+ )} + +
+ {supervisorStatus.canStart && ( + + )} + + {supervisorStatus.canResume && ( + + )} + + {supervisorStatus.canStop && ( + + )} +
+ + {/* Show running indicator when active */} + {supervisorStatus.status === "running" && ( +
+
+ + Autopilot is actively working + +
+ )} + + {supervisorStatus.status === "starting" && ( +
+
+ + Initializing autopilot... + +
+ )} +
+ ); +} diff --git a/makima/frontend/src/components/contracts/ContractDetail.tsx b/makima/frontend/src/components/contracts/ContractDetail.tsx index cf5f8f2..f93097a 100644 --- a/makima/frontend/src/components/contracts/ContractDetail.tsx +++ b/makima/frontend/src/components/contracts/ContractDetail.tsx @@ -18,6 +18,7 @@ import { PhaseHint } from "./PhaseHint"; import { RepositoryPanel } from "./RepositoryPanel"; import { ContractCliInput } from "./ContractCliInput"; import { PhaseDeliverablesPanel } from "./PhaseDeliverablesPanel"; +import { AutopilotPanel } from "./AutopilotPanel"; import { TaskTree } from "../mesh/TaskTree"; type Tab = "overview" | "repos" | "files" | "tasks"; @@ -225,6 +226,7 @@ export function ContractDetail({ onStatusChange={onStatusChange} onPhaseChange={onPhaseChange} onCreateFile={onCreateFileFromTemplate} + onRefresh={onRefresh} /> )} @@ -276,14 +278,19 @@ function OverviewTab({ onStatusChange, onPhaseChange, onCreateFile, + onRefresh, }: { contract: ContractWithRelations; onStatusChange: (status: ContractStatus) => void; onPhaseChange: (phase: ContractPhase) => void; onCreateFile?: (templateId: string, suggestedName: string) => void; + onRefresh: () => void; }) { return (
+ {/* Autopilot controls */} + + {/* Phase deliverables checklist */} { + return startTask(supervisorTaskId); +} + +/** + * Stop a contract's supervisor task (pause autopilot mode). + * This is a convenience wrapper around stopTask. + */ +export async function stopSupervisor(supervisorTaskId: string): Promise { + return stopTask(supervisorTaskId); +} + +/** Status of the supervisor/autopilot for a contract */ +export interface SupervisorStatus { + supervisorTaskId: string | null; + status: "not_configured" | "pending" | "starting" | "running" | "paused" | "done" | "failed"; + daemonId: string | null; + canStart: boolean; + canStop: boolean; + canResume: boolean; +} + +/** + * Get the supervisor status for a contract. + */ +export function getSupervisorStatus( + contract: ContractWithRelations +): SupervisorStatus { + const supervisorTaskId = contract.supervisorTaskId; + + if (!supervisorTaskId) { + return { + supervisorTaskId: null, + status: "not_configured", + daemonId: null, + canStart: false, + canStop: false, + canResume: false, + }; + } + + // Find the supervisor task in the contract's tasks + const supervisorTask = contract.tasks.find( + (t) => t.id === supervisorTaskId && t.isSupervisor + ); + + if (!supervisorTask) { + return { + supervisorTaskId, + status: "pending", + daemonId: null, + canStart: true, + canStop: false, + canResume: false, + }; + } + + // Map task status to supervisor status + let status: SupervisorStatus["status"]; + let canStart = false; + let canStop = false; + let canResume = false; + + switch (supervisorTask.status) { + case "pending": + status = "pending"; + canStart = true; + break; + case "initializing": + case "starting": + status = "starting"; + canStop = true; + break; + case "running": + status = "running"; + canStop = true; + break; + case "paused": + case "blocked": + status = "paused"; + canResume = true; + canStop = true; + break; + case "done": + case "merged": + status = "done"; + break; + case "failed": + status = "failed"; + canResume = true; + break; + default: + status = "pending"; + canStart = true; + } + + return { + supervisorTaskId, + status, + daemonId: null, // Task summary doesn't have daemon_id, would need full task + canStart, + canStop, + canResume, + }; +} diff --git a/makima/frontend/tsconfig.tsbuildinfo b/makima/frontend/tsconfig.tsbuildinfo index 33deafa..a3ef773 100644 --- a/makima/frontend/tsconfig.tsbuildinfo +++ b/makima/frontend/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"root":["./src/main.tsx","./src/vite-env.d.ts","./src/components/gridoverlay.tsx","./src/components/japanesehovertext.tsx","./src/components/logo.tsx","./src/components/masthead.tsx","./src/components/navstrip.tsx","./src/components/protectedroute.tsx","./src/components/rewritelink.tsx","./src/components/simplemarkdown.tsx","./src/components/supervisorquestionnotification.tsx","./src/components/charts/chartrenderer.tsx","./src/components/contracts/contractcliinput.tsx","./src/components/contracts/contractdetail.tsx","./src/components/contracts/contractlist.tsx","./src/components/contracts/phasebadge.tsx","./src/components/contracts/phasedeliverablespanel.tsx","./src/components/contracts/phasehint.tsx","./src/components/contracts/phaseprogressbar.tsx","./src/components/contracts/quickactionbuttons.tsx","./src/components/contracts/repositorypanel.tsx","./src/components/contracts/taskderivationpreview.tsx","./src/components/files/bodyrenderer.tsx","./src/components/files/cliinput.tsx","./src/components/files/conflictnotification.tsx","./src/components/files/elementcontextmenu.tsx","./src/components/files/filedetail.tsx","./src/components/files/filelist.tsx","./src/components/files/reposyncindicator.tsx","./src/components/files/updatenotification.tsx","./src/components/files/versionhistorydropdown.tsx","./src/components/history/checkpointcard.tsx","./src/components/history/checkpointlist.tsx","./src/components/history/conversationmessage.tsx","./src/components/history/conversationview.tsx","./src/components/history/historyfilters.tsx","./src/components/history/resumecontrols.tsx","./src/components/history/timelineeventcard.tsx","./src/components/history/timelinelist.tsx","./src/components/history/index.ts","./src/components/listen/contractpickermodal.tsx","./src/components/listen/controlpanel.tsx","./src/components/listen/speakerpanel.tsx","./src/components/listen/transcriptanalysispanel.tsx","./src/components/listen/transcriptpanel.tsx","./src/components/mesh/directoryinput.tsx","./src/components/mesh/inlinesubtaskeditor.tsx","./src/components/mesh/mergeconflictresolver.tsx","./src/components/mesh/overlaydiffviewer.tsx","./src/components/mesh/prpreview.tsx","./src/components/mesh/subtasktree.tsx","./src/components/mesh/taskdetail.tsx","./src/components/mesh/tasklist.tsx","./src/components/mesh/taskoutput.tsx","./src/components/mesh/tasktree.tsx","./src/components/mesh/unifiedmeshchatinput.tsx","./src/components/workflow/phasecolumn.tsx","./src/components/workflow/workflowboard.tsx","./src/components/workflow/workflowcontractcard.tsx","./src/contexts/authcontext.tsx","./src/contexts/supervisorquestionscontext.tsx","./src/hooks/usecontracts.ts","./src/hooks/usefilesubscription.ts","./src/hooks/usefiles.ts","./src/hooks/usemeshchathistory.ts","./src/hooks/usemicrophone.ts","./src/hooks/usetasksubscription.ts","./src/hooks/usetasks.ts","./src/hooks/usetextscramble.ts","./src/hooks/useversionhistory.ts","./src/hooks/usewebsocket.ts","./src/lib/api.ts","./src/lib/listenapi.ts","./src/lib/markdown.ts","./src/lib/supabase.ts","./src/routes/_index.tsx","./src/routes/contracts.tsx","./src/routes/files.tsx","./src/routes/history.tsx","./src/routes/listen.tsx","./src/routes/login.tsx","./src/routes/mesh.tsx","./src/routes/settings.tsx","./src/routes/workflow.tsx","./src/types/messages.ts"],"version":"5.9.3"} \ No newline at end of file +{"root":["./src/main.tsx","./src/vite-env.d.ts","./src/components/gridoverlay.tsx","./src/components/japanesehovertext.tsx","./src/components/logo.tsx","./src/components/masthead.tsx","./src/components/navstrip.tsx","./src/components/protectedroute.tsx","./src/components/rewritelink.tsx","./src/components/simplemarkdown.tsx","./src/components/supervisorquestionnotification.tsx","./src/components/charts/chartrenderer.tsx","./src/components/contracts/autopilotpanel.tsx","./src/components/contracts/contractcliinput.tsx","./src/components/contracts/contractdetail.tsx","./src/components/contracts/contractlist.tsx","./src/components/contracts/phasebadge.tsx","./src/components/contracts/phasedeliverablespanel.tsx","./src/components/contracts/phasehint.tsx","./src/components/contracts/phaseprogressbar.tsx","./src/components/contracts/quickactionbuttons.tsx","./src/components/contracts/repositorypanel.tsx","./src/components/contracts/taskderivationpreview.tsx","./src/components/files/bodyrenderer.tsx","./src/components/files/cliinput.tsx","./src/components/files/conflictnotification.tsx","./src/components/files/elementcontextmenu.tsx","./src/components/files/filedetail.tsx","./src/components/files/filelist.tsx","./src/components/files/reposyncindicator.tsx","./src/components/files/updatenotification.tsx","./src/components/files/versionhistorydropdown.tsx","./src/components/history/checkpointcard.tsx","./src/components/history/checkpointlist.tsx","./src/components/history/conversationmessage.tsx","./src/components/history/conversationview.tsx","./src/components/history/historyfilters.tsx","./src/components/history/resumecontrols.tsx","./src/components/history/timelineeventcard.tsx","./src/components/history/timelinelist.tsx","./src/components/history/index.ts","./src/components/listen/contractpickermodal.tsx","./src/components/listen/controlpanel.tsx","./src/components/listen/speakerpanel.tsx","./src/components/listen/transcriptanalysispanel.tsx","./src/components/listen/transcriptpanel.tsx","./src/components/mesh/directoryinput.tsx","./src/components/mesh/inlinesubtaskeditor.tsx","./src/components/mesh/mergeconflictresolver.tsx","./src/components/mesh/overlaydiffviewer.tsx","./src/components/mesh/prpreview.tsx","./src/components/mesh/subtasktree.tsx","./src/components/mesh/taskdetail.tsx","./src/components/mesh/tasklist.tsx","./src/components/mesh/taskoutput.tsx","./src/components/mesh/tasktree.tsx","./src/components/mesh/unifiedmeshchatinput.tsx","./src/components/workflow/phasecolumn.tsx","./src/components/workflow/workflowboard.tsx","./src/components/workflow/workflowcontractcard.tsx","./src/contexts/authcontext.tsx","./src/contexts/supervisorquestionscontext.tsx","./src/hooks/usecontracts.ts","./src/hooks/usefilesubscription.ts","./src/hooks/usefiles.ts","./src/hooks/usemeshchathistory.ts","./src/hooks/usemicrophone.ts","./src/hooks/usetasksubscription.ts","./src/hooks/usetasks.ts","./src/hooks/usetextscramble.ts","./src/hooks/useversionhistory.ts","./src/hooks/usewebsocket.ts","./src/lib/api.ts","./src/lib/listenapi.ts","./src/lib/markdown.ts","./src/lib/supabase.ts","./src/routes/_index.tsx","./src/routes/contracts.tsx","./src/routes/files.tsx","./src/routes/history.tsx","./src/routes/listen.tsx","./src/routes/login.tsx","./src/routes/mesh.tsx","./src/routes/settings.tsx","./src/routes/workflow.tsx","./src/types/messages.ts"],"version":"5.9.3"} \ No newline at end of file -- cgit v1.2.3