import { useState } from 'react' import { Play, Square, Loader2, GitBranch, Clock } from 'lucide-react' import { useStartAgent, useStopAgent, useSettings, } from '../hooks/useProjects' import { useNextScheduledRun } from '../hooks/useSchedules' import { formatNextRun, formatEndTime } from '../lib/timeUtils' import { ScheduleModal } from './ScheduleModal' import type { AgentStatus } from '../lib/types' interface AgentControlProps { projectName: string status: AgentStatus } export function AgentControl({ projectName, status }: AgentControlProps) { const { data: settings } = useSettings() const yoloMode = settings?.yolo_mode ?? false // Concurrency: 1 = single agent, 2-5 = parallel const [concurrency, setConcurrency] = useState(3) const startAgent = useStartAgent(projectName) const stopAgent = useStopAgent(projectName) const { data: nextRun } = useNextScheduledRun(projectName) const [showScheduleModal, setShowScheduleModal] = useState(false) const isLoading = startAgent.isPending || stopAgent.isPending const isRunning = status === 'running' || status === 'paused' const isLoadingStatus = status === 'loading' // Status unknown, waiting for WebSocket const isParallel = concurrency > 1 const handleStart = () => startAgent.mutate({ yoloMode, parallelMode: isParallel, maxConcurrency: concurrency, // Always pass concurrency (1-5) testingAgentRatio: settings?.testing_agent_ratio, countTestingInConcurrency: settings?.count_testing_in_concurrency, }) const handleStop = () => stopAgent.mutate() // Simplified: either show Start (when stopped/crashed), Stop (when running/paused), or loading spinner const isStopped = status === 'stopped' || status === 'crashed' return ( <>
{/* Concurrency slider - visible when stopped */} {isStopped && (
setConcurrency(Number(e.target.value))} disabled={isLoading} className="w-16 h-2 accent-[var(--color-neo-primary)] cursor-pointer" title={`${concurrency} concurrent agent${concurrency > 1 ? 's' : ''}`} aria-label="Set number of concurrent agents" /> {concurrency}x
)} {/* Show concurrency indicator when running with multiple agents */} {isRunning && isParallel && (
{concurrency}x
)} {/* Schedule status display */} {nextRun?.is_currently_running && nextRun.next_end && (
Running until {formatEndTime(nextRun.next_end)}
)} {!nextRun?.is_currently_running && nextRun?.next_start && (
Next: {formatNextRun(nextRun.next_start)}
)} {/* Start/Stop button */} {isLoadingStatus ? ( ) : isStopped ? ( ) : ( )} {/* Clock button to open schedule modal */}
{/* Schedule Modal */} setShowScheduleModal(false)} /> ) }