diff --git a/frontend/package.json b/frontend/package.json index 18f4b01c..4da6b232 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,6 +21,7 @@ "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-label": "^2.1.7", + "@radix-ui/react-popover": "^1.1.15", "@radix-ui/react-select": "^2.2.6", "@radix-ui/react-slider": "^1.3.6", "@radix-ui/react-slot": "^1.2.3", diff --git a/frontend/src/components/message/PromptInput.command.test.tsx b/frontend/src/components/message/PromptInput.command.test.tsx index 428b7fc1..340cabe6 100644 --- a/frontend/src/components/message/PromptInput.command.test.tsx +++ b/frontend/src/components/message/PromptInput.command.test.tsx @@ -215,17 +215,18 @@ describe('PromptInput command submission', () => { expect(screen.queryByText('The selected model has no variants')).not.toBeInTheDocument() }) - it('opens the model picker through the imperative handle while the session is active', async () => { + it('opens the config surface in the model view through the imperative handle while the session is active', async () => { const ref = createRef() await renderCommandInput({ promptRef: ref, isSessionActive: true }) - expect(screen.queryByText('Select model')).not.toBeInTheDocument() + expect(screen.queryByRole('heading', { name: 'Model' })).not.toBeInTheDocument() act(() => { ref.current?.openModelPicker() }) - expect(await screen.findByText('Select model')).toBeInTheDocument() + expect(await screen.findByRole('heading', { name: 'Model' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: /More models/ })).toBeInTheDocument() }) it('resets bash mode through the imperative clearPrompt', async () => { diff --git a/frontend/src/components/message/PromptInput.composer.test.tsx b/frontend/src/components/message/PromptInput.composer.test.tsx index e2703543..06c38654 100644 --- a/frontend/src/components/message/PromptInput.composer.test.tsx +++ b/frontend/src/components/message/PromptInput.composer.test.tsx @@ -130,17 +130,16 @@ describe('PromptInput composer layout', () => { }) const trigger = await screen.findByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5, context 42% used/ }) - const usage = screen.getByTestId('composer-config-context-usage') + const meter = screen.getByTestId('context-usage-meter') - expect(trigger).toContainElement(usage) - expect(usage).toHaveTextContent('42%') - expect(usage).toHaveClass('text-success') + expect(trigger).toContainElement(meter) expect(screen.getByTestId('context-usage-meter-fill')).toHaveStyle({ width: '42%' }) + expect(screen.getByTestId('context-usage-meter-fill')).toHaveClass('bg-success') }) it.each([ - [100000, 'text-warning', '50%'], - [176000, 'text-destructive', '88%'], + [100000, 'bg-warning', 'context 50% used'], + [176000, 'bg-destructive', 'context 88% used'], ])('tints the usage from %i total tokens', async (totalTokens, tone, label) => { await renderPromptInput({ transcript: { @@ -148,9 +147,8 @@ describe('PromptInput composer layout', () => { }, }) - const usage = await screen.findByTestId('composer-config-context-usage') - expect(usage).toHaveClass(tone) - expect(usage).toHaveTextContent(label) + expect(await screen.findByRole('button', { name: new RegExp(`^Session config: .*${label}`) })).toBeInTheDocument() + expect(screen.getByTestId('context-usage-meter-fill')).toHaveClass(tone) }) it('caps the meter at full width when usage exceeds the context window', async () => { @@ -160,7 +158,7 @@ describe('PromptInput composer layout', () => { }, }) - await screen.findByTestId('composer-config-context-usage') + await screen.findByRole('button', { name: /^Session config: .*context 130% used/ }) expect(screen.getByTestId('context-usage-meter-fill')).toHaveStyle({ width: '100%' }) }) @@ -172,7 +170,7 @@ describe('PromptInput composer layout', () => { }, }) - expect(await screen.findByTestId('composer-config-context-usage')).toHaveTextContent('12k') + expect(await screen.findByRole('button', { name: /^Session config: .*context 12k tokens used/ })).toBeInTheDocument() expect(screen.getByTestId('context-usage-meter-fill')).toHaveStyle({ width: '0%' }) }) @@ -187,15 +185,13 @@ describe('PromptInput composer layout', () => { }, }) - const usage = await screen.findByTestId('composer-config-context-usage') - expect(usage).toHaveTextContent('42%') + expect(await screen.findByRole('button', { name: /^Session config: .*context 42% used/ })).toBeInTheDocument() }) it('hides the usage without context data', async () => { await renderPromptInput() expect(await screen.findByRole('button', { name: /^Session config: .*Claude Sonnet 4\.5/ })).toBeInTheDocument() - expect(screen.queryByTestId('composer-config-context-usage')).not.toBeInTheDocument() expect(screen.queryByTestId('context-usage-meter')).not.toBeInTheDocument() }) }) diff --git a/frontend/src/components/message/PromptInput.config.test.tsx b/frontend/src/components/message/PromptInput.config.test.tsx index 26a8a4e5..84918bdf 100644 --- a/frontend/src/components/message/PromptInput.config.test.tsx +++ b/frontend/src/components/message/PromptInput.config.test.tsx @@ -1,8 +1,8 @@ import { createRef } from 'react' import { describe, expect, it, vi } from 'vitest' -import { act, fireEvent, screen, waitFor } from '@testing-library/react' +import { act, fireEvent, screen, waitFor, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' -import type { SessionGoalRead } from '@opencode-manager/shared/opencode' +import type { SessionGoalRead, SessionMessageAssistant } from '@opencode-manager/shared/opencode' import type { SessionPermissionModeState, SessionSandboxState } from '@opencode-manager/shared/schemas' import type { PromptInputHandle } from './PromptInput' import { createCommandActionsMock } from '@/test/test-utils' @@ -56,6 +56,18 @@ function withSandbox(overrides: Partial = {}): SessionSandb return { ...baseSandboxState, ...overrides } } +function assistantUsageMessage(tokens: SessionMessageAssistant['tokens']): SessionMessageAssistant { + return { + id: 'msg_assistant', + type: 'assistant', + agent: 'build', + model: { providerID: 'anthropic', id: 'claude-sonnet-4-5' }, + content: [{ type: 'text', text: 'A reply' }], + time: { created: 1, completed: 2 }, + tokens, + } +} + async function renderConfig(mobile: boolean, fixture: ConfigFixture = {}) { const user = userEvent.setup() const { permission, sandbox, ...rest } = fixture @@ -86,15 +98,50 @@ describe.each([ const trigger = await configTrigger() expect(trigger).not.toHaveAttribute('data-active') + expect(trigger).toHaveClass('shrink-0', 'p-0') if (mobile) { expect(trigger).not.toHaveClass('bg-highlight') - expect(trigger).toHaveClass('size-11', 'p-0') + expect(trigger).toHaveClass('size-11') + } else { + expect(trigger).toHaveClass('size-9') } await openConfig(user) expect(await screen.findByRole('menuitemcheckbox', { name: /Accept all permissions/ })).toHaveAttribute('aria-checked', 'false') }) + it('summarises agent, model, variant and context inside the trigger', async () => { + await renderConfig(mobile, { + agents: [makeAgent({ id: 'build', mode: 'primary' })], + models: [ + { + id: 'claude-sonnet-4-5', + providerID: 'anthropic', + name: 'Claude Sonnet 4.5', + variants: ['high', 'low'], + }, + ], + modelState: { variant: { 'anthropic/claude-sonnet-4-5': 'high' } }, + transcript: { + messages: [assistantUsageMessage({ input: 80000, output: 4000, reasoning: 0, cache: { read: 0, write: 0 } })], + }, + }) + + const trigger = await configTrigger() + + expect(trigger).toHaveAccessibleName(/^Session config: Build, Claude Sonnet 4\.5, high variant, context 42% used/) + expect(within(trigger).getByText('Build')).toBeInTheDocument() + expect(within(trigger).getByText('· Claude Sonnet 4.5')).toBeInTheDocument() + expect(within(trigger).getByText('High')).toBeInTheDocument() + expect(within(trigger).getByText('42%')).toBeInTheDocument() + expect(within(trigger).getByTestId('context-usage-meter')).toBeInTheDocument() + if (mobile) { + expect(trigger).not.toHaveClass('@min-[86rem]/composer:absolute') + } else { + expect(trigger).toHaveClass('@min-[86rem]/composer:absolute', '@min-[86rem]/composer:h-10') + } + }) + it.each([ ['permissions accept everything', { permission: { mode: 'auto' } }], ['commands are sandboxed', { sandbox: { sandboxed: true } }], @@ -265,19 +312,20 @@ describe.each([ expect(click).toHaveBeenCalledTimes(1) }) - it('switches the agent radio and sends with the selected agent', async () => { + it('switches the agent from the agent view and sends with the selected agent', async () => { const { user, fetchFake } = await renderConfig(mobile, { agents: [makeAgent({ id: 'build', mode: 'primary' }), makeAgent({ id: 'plan', mode: 'primary' })], }) await openConfig(user) + await user.click(await screen.findByRole('menuitem', { name: /Change agent: Build/ })) + const build = await screen.findByRole('menuitemradio', { name: /Build/ }) const plan = screen.getByRole('menuitemradio', { name: /Plan/ }) expect(build).toHaveAttribute('aria-checked', 'true') await user.click(plan) - expect(plan).toHaveAttribute('aria-checked', 'true') - expect(build).toHaveAttribute('aria-checked', 'false') + expect(await screen.findByRole('menuitem', { name: /Change agent: Plan/ })).toBeInTheDocument() await user.keyboard('{Escape}') fireEvent.change(promptTextarea(), { target: { value: 'hello' } }) @@ -290,13 +338,35 @@ describe.each([ ) }) - it('opens the model picker from the model action', async () => { + it('opens the model view in the config surface from the model action', async () => { const { user } = await renderConfig(mobile) await openConfig(user) await user.click(await screen.findByRole('menuitem', { name: /Change model/ })) - expect(await screen.findByRole('dialog', { name: 'Select model' })).toBeInTheDocument() + expect(await screen.findByRole('heading', { name: 'Model' })).toBeInTheDocument() + expect(screen.getByRole('button', { name: /More models/ })).toBeInTheDocument() + expect(screen.queryByRole('menuitem', { name: /Change agent/ })).not.toBeInTheDocument() + }) + + it('selects a model from the model view and returns to the main view', async () => { + const { user, fetchFake } = await renderConfig(mobile, { + models: [ + { id: 'claude-sonnet-4-5', providerID: 'anthropic', name: 'Claude Sonnet 4.5' }, + { id: 'claude-opus-5', providerID: 'anthropic', name: 'Claude Opus 5' }, + ], + }) + await openConfig(user) + + await user.click(await screen.findByRole('menuitem', { name: /Change model/ })) + await user.click(await screen.findByRole('button', { name: /Claude Opus 5/ })) + + expect(await screen.findByRole('menuitem', { name: /Change model: Claude Opus 5/ })).toBeInTheDocument() + await waitFor(() => + expect(fetchFake.lastRequest('POST', '/api/providers/model-state')?.body).toMatchObject({ + recent: { providerID: 'anthropic', modelID: 'claude-opus-5' }, + }), + ) }) it('omits the variant section when the model has no variants', async () => { diff --git a/frontend/src/components/message/SessionConfigMenu.tsx b/frontend/src/components/message/SessionConfigMenu.tsx index 9753f0dc..52a1c1d4 100644 --- a/frontend/src/components/message/SessionConfigMenu.tsx +++ b/frontend/src/components/message/SessionConfigMenu.tsx @@ -1,5 +1,5 @@ -import { Fragment, memo, useState, type ReactNode } from 'react' -import { Box, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react' +import { memo, useEffect, useState, type CSSProperties, type ReactNode } from 'react' +import { Box, Check, ChevronLeft, ChevronRight, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react' import type { AgentInfo } from '@opencode-manager/shared/opencode' import { useAgents, useSession } from '@/hooks/useOpenCode' import { useContextUsage } from '@/hooks/useContextUsage' @@ -19,23 +19,12 @@ import { formatContextUsage, } from '@/lib/contextUsage' import { cn } from '@/lib/utils' -import { - DropdownMenu, - DropdownMenuCheckboxItem, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuRadioGroup, - DropdownMenuRadioItem, - DropdownMenuSeparator, - DropdownMenuTrigger, -} from '@/components/ui/dropdown-menu' +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { BottomSheet, BottomSheetContent, BottomSheetHeader } from '@/components/ui/bottom-sheet' import { getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button' import { ContextUsageMeter } from '@/components/session/ContextUsageMeter' -import { ModelQuickSelect } from '@/components/model/ModelQuickSelect' +import { ModelPicker } from '@/components/model/ModelPicker' import { SessionSandboxResourcesDialog } from './SessionSandboxResourcesDialog' -import { ToolMenuItemContent } from './ToolMenuItemContent' interface SessionConfigMenuProps { sessionID: string @@ -56,37 +45,113 @@ interface SessionConfigMenuProps { onAttachFile: () => void } -interface SessionConfigEntryBase { - key: string - title: string - detail?: string - disabled?: boolean - icon?: ReactNode - className?: string -} - -type SessionConfigEntry = - | (SessionConfigEntryBase & { kind: 'radio'; checked: boolean; onSelect: () => void }) - | (SessionConfigEntryBase & { kind: 'checkbox'; checked: boolean; onSelect: () => void }) - | (SessionConfigEntryBase & { kind: 'action'; onSelect: () => void }) - -interface SessionConfigSection { - key: string - label: string - entries: SessionConfigEntry[] -} - type SelectableAgent = Pick +type SessionMenuView = 'main' | 'agent' | 'model' + +type SessionMenuItemRole = 'menuitem' | 'menuitemradio' | 'menuitemcheckbox' + +const BACK_BUTTON_CLASS = + 'flex shrink-0 items-center justify-center rounded-full border border-border bg-muted text-foreground/80 hover:bg-accent' + +const backButtonClassName = (mobile: boolean) => cn(BACK_BUTTON_CLASS, mobile ? 'h-11 w-11' : 'h-9 w-9') + const capitalize = (value: string) => value.charAt(0).toUpperCase() + value.slice(1).toLowerCase() const findAgent = (agents: SelectableAgent[], agentId: string): SelectableAgent | undefined => agents.find((agent) => agent.id.toLowerCase() === agentId.toLowerCase()) -const EMPTY_ICON =