Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ vi.mock('@/lib/telemetry', () => ({ track: vi.fn() }))
vi.mock('sonner', () => ({ toast: { success: vi.fn(), dismiss: vi.fn(), error: vi.fn() } }))

let persisted: GlobalSettings
let presentation: 'tiles' | 'switch'
const settingsSet = vi.fn(async (updates: Partial<GlobalSettings>) => {
persisted = { ...persisted, ...updates }
return persisted
})

function Section(): React.JSX.Element | null {
const settings = useAppStore((state) => state.settings)
return settings ? <AgentDefaultSurfaceSection settings={settings} /> : null
return settings ? (
<AgentDefaultSurfaceSection settings={settings} presentation={presentation} />
) : null
}

function renderSection(settings: Partial<GlobalSettings>): void {
Expand All @@ -33,6 +36,7 @@ function renderSection(settings: Partial<GlobalSettings>): void {
}

beforeEach(() => {
presentation = 'tiles'
useAppStore.setState(useAppStore.getInitialState(), true)
settingsSet.mockClear()
vi.mocked(track).mockClear()
Expand All @@ -46,6 +50,26 @@ beforeEach(() => {
afterEach(cleanup)

describe('Open agents as', () => {
it('reuses the default write from the Chat UI button and retains per-agent choices', async () => {
presentation = 'switch'
renderSection({ agentDefaultSurface: 'terminal', nativeChatProviders: { claude: false } })
const control = screen.getByRole('button', { name: 'Turn on' })
expect(screen.getByText('Chat UI is off')).toBeTruthy()
expect(screen.getByText('New agents will launch as CLI by default.')).toBeTruthy()
fireEvent.click(control)
await waitFor(() => expect(screen.getByRole('button', { name: 'Turn off' })).toBeTruthy())
expect(settingsSet).toHaveBeenCalledExactlyOnceWith({ agentDefaultSurface: 'chat' })
expect(persisted.nativeChatProviders).toEqual({ claude: false })
expect(screen.getByText('Chat UI is on')).toBeTruthy()
expect(toast.success).toHaveBeenCalledExactlyOnceWith(
'Agents now open as chats',
expect.objectContaining({
description: 'Claude stays in the terminal, as you set.',
action: expect.objectContaining({ label: 'Set all to Chat' })
})
)
})

it('sets only the default, names agents set to the other surface, and Set all makes them follow', async () => {
renderSection({
agentDefaultSurface: 'terminal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {
} from '../feature-tips/feature-tip-telemetry'
import { ChatSurfacePreview, TerminalSurfacePreview } from './AgentDefaultSurfacePreviews'
import { AGENT_DEFAULT_SURFACE_SECTION_ID, AGENTS_INSTALLED_SECTION_ID } from './agents-search'
import { Card, CardContent } from '../ui/card'
import { SettingsRow } from './SettingsFormControls'
import { Button } from '../ui/button'
import {
agentsKeepingOwnSurface,
followAgentDefaultSurface,
Expand Down Expand Up @@ -164,9 +167,11 @@ function SurfaceTile({

/** This computer's default surface; agents set on their own Installed row keep their choice. */
export function AgentDefaultSurfaceSection({
settings
settings,
presentation = 'tiles'
}: {
settings: GlobalSettings
presentation?: 'tiles' | 'switch'
}): JSX.Element {
const name = useId()
const notify = useKeptSurfaceNotice()
Expand Down Expand Up @@ -199,6 +204,45 @@ export function AgentDefaultSurfaceSection({
list?.scrollIntoView({ behavior: motionSafeScrollBehavior(), block: 'start' })
list?.focus({ preventScroll: true })
}
if (presentation === 'switch') {
return (
<Card>
<CardContent>
<SettingsRow
label={
<span className="text-lg font-semibold">
{surface === 'chat'
? translate('settings.chat.launch.on', 'Chat UI is on')
: translate('settings.chat.launch.off', 'Chat UI is off')}
</span>
}
description={
surface === 'chat'
? translate(
'settings.chat.launch.chatDescription',
'New agents will launch in chat mode by default.'
)
: translate(
'settings.chat.launch.cliDescription',
'New agents will launch as CLI by default.'
)
}
control={
<Button
variant={surface === 'chat' ? 'outline' : 'default'}
disabled={pending}
onClick={() => choose(surface === 'chat' ? 'terminal' : 'chat')}
>
{surface === 'chat'
? translate('settings.chat.launch.turnOff', 'Turn off')
: translate('settings.chat.launch.turnOn', 'Turn on')}
</Button>
}
/>
</CardContent>
</Card>
)
}
return (
<section id={AGENT_DEFAULT_SURFACE_SECTION_ID} className="@container scroll-mt-8">
<h3 className="text-lg font-semibold tracking-tight">{title}</h3>
Expand Down
72 changes: 72 additions & 0 deletions src/renderer/src/components/settings/ChatAgentLaunchSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import type { GlobalSettings } from '../../../../shared/global-settings-types'
import { useEffect } from 'react'
import { LOCAL_EXECUTION_HOST_ID } from '../../../../shared/execution-host'
import { AgentIcon, getAgentCatalog } from '@/lib/agent-catalog'
import { chatProviderAgents, useHostStructuredAgentsVersion } from '@/lib/chat-provider-agents'
import { readChatProgram, resolveChatProgramContext } from '@/lib/host-chat-program'
import { useChatProgramFacts } from '@/lib/host-chat-program-acquisition'
import { useAppStore } from '@/store'
import { readNativeDetectedAgents } from '@/store/slices/local-detected-agent-store-state'
import { Card, CardContent } from '../ui/card'
import { AgentOpensAsControl } from './AgentChatChoiceControls'
import { buildAgentOpensAs } from './native-chat-provider-choice'
import { SettingsSubsectionHeader } from './SettingsFormControls'
import { getChatLaunchEntriesByKey } from './chat-launch-search'

const WORKSPACE = { kind: 'floating' } as const

export function ChatAgentLaunchSettings({
settings,
updateSettings
}: {
settings: GlobalSettings
updateSettings: (updates: Partial<GlobalSettings>) => void | Promise<void>
}): React.JSX.Element {
useHostStructuredAgentsVersion()
useChatProgramFacts(WORKSPACE)
useEffect(() => {
void useAppStore.getState().ensureNativeDetectedAgents()
}, [])
const detected = useAppStore(readNativeDetectedAgents)
const chatOnlyKey = useAppStore((state) => {
const context = resolveChatProgramContext(state, WORKSPACE)
return chatProviderAgents(LOCAL_EXECUTION_HOST_ID, undefined)
.filter(
(agent) =>
!detected?.includes(agent) &&
readChatProgram(state, agent, context, detected) === 'available'
)
.join(' ')
})
const chatOnly = new Set(chatOnlyKey.split(' '))
const entry = getChatLaunchEntriesByKey().agents
return (
<section className="space-y-3">
<SettingsSubsectionHeader title={entry.title} description={entry.description} />
<Card size="list">
<CardContent>
<div className="divide-y divide-border">
{getAgentCatalog().map((agent) => {
const opensAs = buildAgentOpensAs({
agent: agent.id,
cliDetected: detected === null ? null : detected.includes(agent.id),
chatProgramHere: chatOnly.has(agent.id),
settings,
updateSettings
})
return opensAs ? (
<div key={agent.id} className="flex items-center justify-between gap-4 py-3">
<div className="flex min-w-0 items-center gap-3">
<AgentIcon agent={agent.id} size={16} />
<span className="text-sm font-medium">{agent.label}</span>
</div>
<AgentOpensAsControl label={agent.label} opensAs={opensAs} />
</div>
) : null
})}
</div>
</CardContent>
</Card>
</section>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineFixture } from '../../component-fixtures/component-fixture'
import { useAppStore } from '@/store'
import { ChatSettingsSection } from './ChatSettingsSection'
import { ActiveSettingsSectionProvider } from './SettingsSection'

function ChatSettingsPreview(): React.JSX.Element | null {
const settings = useAppStore((state) => state.settings)
const updateSettings = useAppStore((state) => state.updateSettings)
return settings ? (
<ActiveSettingsSectionProvider value="chat">
<ChatSettingsSection
settings={settings}
updateSettings={updateSettings}
writeSourceControlAiSettings={async () => {}}
searchEntries={[]}
showDesktopOnlySettings
isMounted
/>
</ActiveSettingsSectionProvider>
) : null
}

export const desktop = defineFixture({ width: 820, render: () => <ChatSettingsPreview /> })
export const narrow = defineFixture({ width: 390, render: () => <ChatSettingsPreview /> })
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { useRef, useState } from 'react'
import { cleanup, render, screen, waitFor } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { getDefaultSettings } from '../../../../shared/constants'
import { buildSettingsNavigationMetadata } from '@/hooks/useSettingsNavigationMetadata'
import { ChatSettingsSection } from './ChatSettingsSection'
Expand All @@ -15,12 +15,14 @@ import type { SettingsStoreModel } from './use-settings-store-model'
import type { SettingsInteractionController } from './use-settings-interaction-controller'
import type { SettingsNavigationModel } from './use-settings-navigation-model'
import type { SettingsTerminalModel } from './use-settings-terminal-model'
import { useAppStore } from '@/store'

vi.mock('@/lib/host-chat-program-acquisition', () => ({ useChatProgramFacts: () => {} }))
vi.mock('../../store', () => ({
useAppStore: (selector: (value: { settingsSearchQuery: string }) => unknown) =>
selector({ settingsSearchQuery: '' })
}))
beforeEach(() => {
useAppStore.setState(useAppStore.getInitialState(), true)
useAppStore.setState({ ensureNativeDetectedAgents: vi.fn(async () => []) })
})

afterEach(() => {
cleanup()
vi.restoreAllMocks()
Expand Down
Loading
Loading