import { CoordinatorSidebar } from "./CoordinatorSidebar"; import { isWaitingToStart } from "../lib/agent-queue-wait"; import { useCoordinatorWorkspaceEnabled } from "@/hooks/useCoordinatorWorkspaceEnabled"; import { Inbox, ListChecks, CircleCheck, Target, LayoutDashboard, DollarSign, History, Search, SquarePen, Network, Boxes, Repeat, Layers, GitBranch, Package, Settings, FolderOpen, Unplug, MessagesSquare, MessageCircle, GanttChartSquare, LayoutGrid, Users, Compass, } from "lucide-react"; import { useState, type ReactNode } from "react"; import { useQuery } from "@tanstack/react-query"; import { SidebarSection } from "./SidebarSection"; import { SidebarNavItem } from "./SidebarNavItem"; import { SidebarAgents } from "./SidebarAgents"; import { SidebarProjects } from "./SidebarProjects"; import { SidebarStarredProjects } from "./SidebarStarredProjects"; import { useAgentChatEnabled } from "@/hooks/useAgentChatEnabled"; import { useAgentChatNavigation } from "@/hooks/useAgentChatNavigation"; import { useResponsibilitiesEnabled } from "@/hooks/useResponsibilitiesEnabled"; import { SidebarRecentTasks } from "./SidebarRecentTasks"; import { useDialogActions } from "../context/DialogContext"; import { useCompany } from "../context/CompanyContext"; import { heartbeatsApi } from "../api/heartbeats"; import { instanceSettingsApi } from "../api/instanceSettings"; import { queryKeys } from "../lib/queryKeys"; import { useAttentionBadge } from "../hooks/useAttentionViews"; import { useInboxBadge } from "../hooks/useInboxBadge"; import { useStreamlinedUiEnabled } from "../hooks/useStreamlinedUiEnabled"; import { usePublishSharedQueryData, useSharedPollingQuery } from "../hooks/useSharedPolling"; import { cn } from "../lib/utils"; import { PluginSlotOutlet } from "@/plugins/slots"; import { PluginLauncherOutlet } from "@/plugins/launchers"; import { SidebarCompanyMenu } from "./SidebarCompanyMenu"; import { primarySidebarStyles } from "./primary-sidebar-styles"; export function Sidebar({ children }: { children?: ReactNode }) { const { enabled } = useCoordinatorWorkspaceEnabled(); return enabled ? {children} : {children}; } function ClassicSidebar({ children }: { children?: ReactNode }) { const { openNewIssue } = useDialogActions(); const { enabled: agentChatEnabled } = useAgentChatEnabled(); const chatNavigation = useAgentChatNavigation(); const unreadChatCount = chatNavigation.chats.data?.filter(chat => chat.isUnreadForMe).length ?? 0; // Every labeled section is collapsible (session-scoped, default open) — // one policy across static nav groups and the data-driven sections. const [workOpen, setWorkOpen] = useState(true); const [organizationOpen, setOrganizationOpen] = useState(true); const { selectedCompanyId, selectedCompany } = useCompany(); const { enabled: streamlinedUiEnabled } = useStreamlinedUiEnabled(); const inboxBadge = useInboxBadge(selectedCompanyId); const { data: experimentalSettings } = useQuery({ queryKey: queryKeys.instance.experimentalSettings, queryFn: () => instanceSettingsApi.getExperimental(), }); const liveRunsQueryKey = queryKeys.liveRuns(selectedCompanyId!); const sharedLiveRuns = useSharedPollingQuery({ companyId: selectedCompanyId, resourceKey: "live-runs", queryKey: liveRunsQueryKey, enabled: !!selectedCompanyId, // Event-sourced via LiveUpdatesProvider (GitHub issue 9627) + reconnect reconcile — no // interval poll needed. Polling here also re-armed React Query's timer on // every live-event cache write, a major source of steady-state churn. refetchInterval: false, leaderOnly: true, }); const { data: liveRuns, dataUpdatedAt: liveRunsUpdatedAt } = useQuery({ queryKey: liveRunsQueryKey, queryFn: () => heartbeatsApi.liveRunsForCompany(selectedCompanyId!), enabled: sharedLiveRuns.enabled, refetchInterval: sharedLiveRuns.refetchInterval, }); usePublishSharedQueryData(sharedLiveRuns, liveRuns, liveRunsUpdatedAt); const liveRunCount = (liveRuns ?? []).filter((run) => !isWaitingToStart(run)).length; const liveIssueIds = new Set( (liveRuns ?? []).flatMap((run) => run.issueId ? [run.issueId] : []), ); const chatRail = agentChatEnabled && streamlinedUiEnabled; // The merged Tasks page only exists in the streamlined shell, so the legacy // shell keeps its Inbox row even with the flag on. const combinedInboxTasks = streamlinedUiEnabled && experimentalSettings?.enableCombinedInboxTasks === true; const showWorkspacesLink = experimentalSettings?.enableIsolatedWorkspaces === true; const showStatusCards = experimentalSettings?.enableStatusCards === true; const goalsLinkPending = experimentalSettings === undefined; const showGoalsLink = experimentalSettings?.enableGoalsSidebarLink === true; // Decisions (attention home) is an experimental surface (PAP-13481): the nav // item is hidden entirely until the flag is enabled (same no-flash pattern as // showWorkspacesLink — it defaults hidden, so no placeholder is needed). const showDecisions = experimentalSettings?.enableDecisions === true; // The shared "For you" badge (PAP-749 Rule 5): same query as the Decisions // page and the coordinator navigation, with no midnight reset. const { count: attentionCount } = useAttentionBadge(selectedCompanyId, { enabled: showDecisions, refetchInterval: 60_000, }); const showCases = experimentalSettings?.enableCases === true; // Conference Room Chat flag (PAP-136/PAP-137): the Conference Room nav item // is a new surface, hidden entirely while the flag is off (same no-flash // pattern as showWorkspacesLink above). const conferenceRoomChatEnabled = experimentalSettings?.enableConferenceRoomChat === true; // Responsibilities (experimental) is home: it leads the primary group with // Chat, Tasks and Inbox directly beneath it, and Dashboard moves down into // Work. Hidden until the flag is known (no-flash, same as above). const { enabled: responsibilitiesHome } = useResponsibilitiesEnabled(); const chatItem = ; // Combined Inbox + Task List: Inbox is a view inside Tasks, so the // unread/failed-run badge rides on Tasks. const tasksItem = combinedInboxTasks ? ( 0 ? "danger" : "default"} alert={inboxBadge.failedRuns > 0} /> ) : ( ); const inboxItem = !combinedInboxTasks ? ( 0 ? "danger" : "default"} alert={inboxBadge.failedRuns > 0} /> ) : null; // The classic dashboard. With Responsibilities as home that page takes the "Dashboard" name and this row is not shown. const dashboardItem = ; const pluginContext = { companyId: selectedCompanyId, companyPrefix: selectedCompany?.issuePrefix ?? null, }; return ( ); }