import { useState } from "react"; import { NEW_ENTITY_ID } from "../../lib/constants"; import type { SectionId } from "@shared/types"; import { Kanban, ListChecks, Target, } from "@phosphor-icons/react"; import { ConnectorEditor } from "../../components/connectors"; import { KanbanBoard } from "../../components/dashboard"; import { TwoPaneLayout } from "../../components/TwoPaneLayout"; import { RunCenter } from "../../components/runs"; import { ActivityList, ApprovalInspector, ApprovalList, BudgetSummary, CostList, PendingReviewList, TaskCreator, TaskInspector, TaskQueue, } from "../../components/execution"; import { PolicyList } from "../../components/execution/PolicyList"; import { IncidentList } from "../../components/execution/IncidentList"; import { GoalCreator, GoalEditor, GoalList, } from "../../components/organization"; import { ActionButton, ListFrame, ListRow, Modal, Panel, StatusPill } from "../../components/ui"; import { unwrap } from "../../lib/desktop"; import { useAppStore } from "../../state/store"; import { useSectionContext } from "../../hooks/useSectionContext"; import { useAppActions } from "../../hooks/useAppActions"; interface ExecutionSectionsProps { section: SectionId; } // Policy: blocked tasks need an operator unblock via secret_access approval; // everything else routes through CEO strategy review. function buildTaskEscalation(task: { status: string; title: string; }): { type: "secret_access" | "approve_ceo_strategy"; payloadSummary: string; impactSummary: string; } { if (task.status === "blocked") { return { type: "secret_access", payloadSummary: `Blocker: ${task.title} — needs operator assistance`, impactSummary: "Agent is blocked and needs operator input (credentials, access, or decision).", }; } return { type: "approve_ceo_strategy", payloadSummary: `Review needed: ${task.title}`, impactSummary: "No automated reviewer available. Operator review required.", }; } export function ExecutionSections({ section }: ExecutionSectionsProps) { const { snapshot, currentCompany, tasks, runs, pendingApprovals, companyAgents, companyGoals, companyProjects, companyWorkspaces, companyCosts, companyDocuments, filteredActivity, selectedTask, selectedConnector, selectedApproval, selectedGoal, } = useSectionContext(); const { refresh, startRun, cancelRun, openPathWithFeedback } = useAppActions(); const selectedRunId = useAppStore((s) => s.selectedRunId); const setSelectedRunId = useAppStore((s) => s.setSelectedRunId); const selectedTaskId = useAppStore((s) => s.selectedTaskId); const setSelectedTaskId = useAppStore((s) => s.setSelectedTaskId); const setSelectedConnectorId = useAppStore((s) => s.setSelectedConnectorId); const setSelectedApprovalId = useAppStore((s) => s.setSelectedApprovalId); const selectedGoalId = useAppStore((s) => s.selectedGoalId); const setSelectedGoalId = useAppStore((s) => s.setSelectedGoalId); const taskViewMode = useAppStore((s) => s.taskViewMode); const setTaskViewMode = useAppStore((s) => s.setTaskViewMode); const setSection = useAppStore((s) => s.setSection); const setConsoleOpen = useAppStore((s) => s.setConsoleOpen); const setSelectedCommunicationEntityId = useAppStore((s) => s.setSelectedCommunicationEntityId); const [costsTab, setCostsTab] = useState<"costs" | "policies" | "incidents">("costs"); if (!snapshot || !currentCompany) return null; return ( <> {section === "runs" ? ( { setSelectedRunId(runId); }} onOpenLogPath={async (path: string) => { await openPathWithFeedback(path); }} onCancelRun={cancelRun} onOpenConsole={(runId: string) => { setSelectedRunId(runId); setConsoleOpen(true); }} /> ) : null} {section === "connectors" && selectedConnector ? (
{snapshot.connectors.map((connector) => ( setSelectedConnectorId(connector.id)} className={`cursor-pointer transition-colors duration-100 ${ selectedConnector.id === connector.id ? "bg-accent" : "hover:bg-muted" }`} >
{connector.label}
{connector.command}
))}
) : null} {section === "tasks" ? ( <> setSelectedGoalId(NEW_ENTITY_ID)} />}> setSelectedGoalId(null)}> { setSelectedGoalId(null); await refresh(); }} /> setSelectedGoalId(null)}> {selectedGoal ? ( { setSelectedGoalId(null); await refresh(); }} onDeleted={async () => { setSelectedGoalId(null); await refresh(); }} /> ) : null}
setSelectedTaskId(NEW_ENTITY_ID)} /> } > {taskViewMode === "kanban" ? ( ) : ( )}
setSelectedTaskId(null)}> { setSelectedTaskId(null); await refresh(); }} /> setSelectedTaskId(null)} width="720px"> {selectedTask ? ( run.taskId === selectedTask.id)} agents={companyAgents} goals={companyGoals} projects={companyProjects} workspaces={companyWorkspaces} companyId={currentCompany.id} comments={(snapshot.comments ?? []).filter((comment) => comment.taskId === selectedTask.id)} onRefresh={refresh} onRun={startRun} onCancelRun={cancelRun} onCreateApproval={async () => { const escalation = buildTaskEscalation(selectedTask); const approvalId = unwrap(await window.agentCompany.requestApproval({ companyId: currentCompany.id, relatedTaskId: selectedTask.id, requestedByAgentId: selectedTask.assigneeAgentId, ...escalation, })); setSelectedApprovalId(approvalId); await refresh(); }} onOpenDiscussion={(taskId) => { setSelectedTaskId(null); setSection("communication"); setSelectedCommunicationEntityId(taskId); }} onDeleted={async () => { setSelectedTaskId(null); await refresh(); }} /> ) : null} ) : null} {section === "approvals" ? ( <> setSelectedApprovalId(null)}> {selectedApproval ? ( { unwrap(await window.agentCompany.decideApproval({ companyId: currentCompany.id, approvalId: selectedApproval.id, state, decisionNote: note ?? `${state} from desktop control surface.` })); await refresh(); }} onDeleted={async () => { setSelectedApprovalId(null); await refresh(); }} /> ) : null} ) : null} {section === "costs" ? (
{(["costs", "policies", "incidents"] as const).map((tab) => ( ))}
{costsTab === "costs" ? ( } secondary={ } /> ) : costsTab === "policies" ? ( ({ id: a.id, name: a.name }))} projects={companyProjects.map((p) => ({ id: p.id, name: p.name }))} /> ) : ( ({ id: a.id, name: a.name }))} projects={companyProjects.map((p) => ({ id: p.id, name: p.name }))} /> )}
) : null} {section === "activity" ? ( ) : null} ); }