From 5b8e933904a2bce9c4eb0b147ee3145462d37059 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Tue, 21 Apr 2026 23:14:22 -0700 Subject: [PATCH] feat(tab-bar): add quick-launch CLI buttons (#933) Introduce a dedicated detected-agents store slice that replaces the module-scoped detect-agents-cached cache, with a shared useDetectedAgents hook driving AgentsPane, composer, and the new QuickLaunchButton in TabBar. Extracts launchAgentInNewTab helper to share the startup-command path used by the tab bar's + button. --- .../src/components/settings/AgentsPane.tsx | 40 ++---- .../components/tab-bar/QuickLaunchButton.tsx | 131 ++++++++++++++++++ .../src/components/tab-bar/TabBar.tsx | 6 + src/renderer/src/hooks/useComposerState.ts | 16 ++- src/renderer/src/hooks/useDetectedAgents.ts | 38 +++++ src/renderer/src/lib/detect-agents-cached.ts | 25 ---- .../src/lib/launch-agent-in-new-tab.ts | 84 +++++++++++ .../src/lib/launch-work-item-direct.ts | 3 +- src/renderer/src/store/index.ts | 4 +- .../src/store/slices/detected-agents.ts | 83 +++++++++++ .../slices/store-session-cascades.test.ts | 4 +- .../src/store/slices/store-test-helpers.ts | 4 +- src/renderer/src/store/slices/tabs.test.ts | 4 +- src/renderer/src/store/types.ts | 4 +- 14 files changed, 382 insertions(+), 64 deletions(-) create mode 100644 src/renderer/src/components/tab-bar/QuickLaunchButton.tsx create mode 100644 src/renderer/src/hooks/useDetectedAgents.ts delete mode 100644 src/renderer/src/lib/detect-agents-cached.ts create mode 100644 src/renderer/src/lib/launch-agent-in-new-tab.ts create mode 100644 src/renderer/src/store/slices/detected-agents.ts diff --git a/src/renderer/src/components/settings/AgentsPane.tsx b/src/renderer/src/components/settings/AgentsPane.tsx index 15b1301cb..980f713a5 100644 --- a/src/renderer/src/components/settings/AgentsPane.tsx +++ b/src/renderer/src/components/settings/AgentsPane.tsx @@ -1,7 +1,8 @@ -import { useCallback, useEffect, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { Check, ChevronDown, ExternalLink, RefreshCw, Terminal } from 'lucide-react' import type { GlobalSettings, TuiAgent } from '../../../../shared/types' import { AGENT_CATALOG, AgentIcon } from '@/lib/agent-catalog' +import { useDetectedAgents } from '@/hooks/useDetectedAgents' import { Button } from '../ui/button' import { Input } from '../ui/input' import { cn } from '@/lib/utils' @@ -204,30 +205,17 @@ function AgentRow({ } export function AgentsPane({ settings, updateSettings }: AgentsPaneProps): React.JSX.Element { - const [detectedIds, setDetectedIds] = useState | null>(null) - const [isRefreshing, setIsRefreshing] = useState(false) - - useEffect(() => { - void window.api.preflight.detectAgents().then((ids) => { - setDetectedIds(new Set(ids)) - }) - }, []) - - const handleRefresh = useCallback(async (): Promise => { - // Why: refresh re-spawns the user's login shell to re-capture PATH - // (preflight:refreshAgents on the main side). This handles the - // "installed a new CLI, Orca doesn't see it yet" case without a restart. - if (isRefreshing) { - return - } - setIsRefreshing(true) - try { - const result = await window.api.preflight.refreshAgents() - setDetectedIds(new Set(result.agents)) - } finally { - setIsRefreshing(false) - } - }, [isRefreshing]) + const { detectedIds: detectedList, isRefreshing, refresh } = useDetectedAgents() + // Why: refresh re-spawns the user's login shell to re-capture PATH + // (preflight:refreshAgents on the main side). This handles the + // "installed a new CLI, Orca doesn't see it yet" case without a restart. + const handleRefresh = (): void => { + void refresh() + } + const detectedIds = useMemo | null>( + () => (detectedList ? new Set(detectedList) : null), + [detectedList] + ) const defaultAgent = settings.defaultTuiAgent const cmdOverrides = settings.agentCmdOverrides ?? {} @@ -338,7 +326,7 @@ export function AgentsPane({ settings, updateSettings }: AgentsPaneProps): React