feat(frontend): add mobile composer tools menu and base branch select

This commit is contained in:
Chris Scott committed 2026-10-04 00:05:53 -04:00
1 parent fac23b1f1a
commit 4a2e695ec2
21 files changed
+819 -158

No files matched your search

@@ -0,0 +1,128 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { ComposerToolsMenu } from './ComposerToolsMenu'
import { useSessionPermissionMode, useSetSessionPermissionMode } from '@/hooks/useSessionPermissionMode'
import type { SessionPermissionModeState } from '@opencode-manager/shared/schemas'
vi.mock('@/hooks/useSessionPermissionMode')
const baseState: SessionPermissionModeState = {
sessionId: 'ses_1',
rootSessionId: 'ses_1',
mode: 'ask',
lockedReason: null,
}
function mockPermissionMode(state: Partial<SessionPermissionModeState> = {}, mutate = vi.fn()) {
vi.mocked(useSessionPermissionMode).mockReturnValue({
data: { ...baseState, ...state },
isError: false,
} as ReturnType<typeof useSessionPermissionMode>)
vi.mocked(useSetSessionPermissionMode).mockReturnValue({
mutate,
isPending: false,
} as unknown as ReturnType<typeof useSetSessionPermissionMode>)
return mutate
}
function renderMenu(overrides: Partial<React.ComponentProps<typeof ComposerToolsMenu>> = {}) {
const props = {
sessionID: 'ses_1',
directory: '/repo',
goalArmed: false,
goalDisabled: false,
goalLabel: 'Goal mode: the next message becomes the objective',
onToggleGoal: vi.fn(),
onAttachFile: vi.fn(),
...overrides,
}
render(<ComposerToolsMenu {...props} />)
return props
}
describe('ComposerToolsMenu', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('does not highlight the trigger when no tool is active', () => {
mockPermissionMode()
renderMenu()
expect(screen.getByRole('button', { name: 'Composer options' })).not.toHaveClass('bg-highlight')
})
it('highlights the trigger while permissions accept everything', () => {
mockPermissionMode({ mode: 'auto' })
renderMenu()
expect(screen.getByRole('button', { name: 'Composer options' })).toHaveClass('bg-highlight')
})
it('highlights the trigger while goal mode is armed', () => {
mockPermissionMode()
renderMenu({ goalArmed: true })
expect(screen.getByRole('button', { name: 'Composer options' })).toHaveClass('bg-highlight')
})
it('switches permissions to accept everything', async () => {
const user = userEvent.setup()
const mutate = mockPermissionMode()
renderMenu()
await user.click(screen.getByRole('button', { name: 'Composer options' }))
const item = await screen.findByRole('menuitemcheckbox', { name: /Accept all permissions/ })
expect(item).toHaveAttribute('aria-checked', 'false')
await user.click(item)
expect(mutate).toHaveBeenCalledWith({ directory: '/repo', mode: 'auto' })
})
it('shows why permissions cannot be changed', async () => {
const user = userEvent.setup()
mockPermissionMode({ lockedReason: 'child' })
renderMenu()
await user.click(screen.getByRole('button', { name: 'Composer options' }))
const item = await screen.findByRole('menuitemcheckbox', { name: /Accept all permissions/ })
expect(item).toHaveAttribute('aria-disabled', 'true')
expect(item).toHaveTextContent('Inherited from parent session')
})
it('toggles goal mode', async () => {
const user = userEvent.setup()
mockPermissionMode()
const props = renderMenu()
await user.click(screen.getByRole('button', { name: 'Composer options' }))
await user.click(await screen.findByRole('menuitemcheckbox', { name: /Goal mode/ }))
expect(props.onToggleGoal).toHaveBeenCalledTimes(1)
})
it('shows why goal mode is unavailable', async () => {
const user = userEvent.setup()
mockPermissionMode()
renderMenu({ goalDisabled: true, goalLabel: 'A goal is already active for this session' })
await user.click(screen.getByRole('button', { name: 'Composer options' }))
const item = await screen.findByRole('menuitemcheckbox', { name: /Goal mode/ })
expect(item).toHaveAttribute('aria-disabled', 'true')
expect(item).toHaveTextContent('A goal is already active for this session')
})
it('opens the file picker', async () => {
const user = userEvent.setup()
mockPermissionMode()
const props = renderMenu()
await user.click(screen.getByRole('button', { name: 'Composer options' }))
await user.click(await screen.findByRole('menuitem', { name: 'Attach image or PDF' }))
expect(props.onAttachFile).toHaveBeenCalledTimes(1)
})
})
@@ -0,0 +1,85 @@
import type { ReactNode } from 'react'
import { Paperclip, Plus, Shield, ShieldCheck, Target } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { getIconToggleButtonClassName } from '@/components/ui/icon-toggle-button'
import { usePermissionModeToggle } from '@/hooks/usePermissionModeToggle'
interface ComposerToolsMenuProps {
sessionID: string
directory: string
goalArmed: boolean
goalDisabled: boolean
goalLabel: string
onToggleGoal: () => void
onAttachFile: () => void
}
export function ComposerToolsMenu({
sessionID,
directory,
goalArmed,
goalDisabled,
goalLabel,
onToggleGoal,
onAttachFile,
}: ComposerToolsMenuProps) {
const permission = usePermissionModeToggle(sessionID, directory)
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
type="button"
aria-label="Composer options"
title="Composer options"
className={getIconToggleButtonClassName(permission.isAuto || goalArmed)}
>
<Plus className="w-5 h-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent side="top" align="end" collisionPadding={8} className="w-64">
<DropdownMenuCheckboxItem
checked={permission.isAuto}
disabled={permission.disabled}
onCheckedChange={permission.toggle}
>
<ToolMenuItemContent
icon={permission.isAuto ? <ShieldCheck className="h-4 w-4" /> : <Shield className="h-4 w-4" />}
title="Accept all permissions"
detail={permission.disabled ? permission.label : undefined}
/>
</DropdownMenuCheckboxItem>
<DropdownMenuCheckboxItem checked={goalArmed} disabled={goalDisabled} onCheckedChange={onToggleGoal}>
<ToolMenuItemContent
icon={<Target className="h-4 w-4" />}
title="Goal mode"
detail={goalDisabled ? goalLabel : undefined}
/>
</DropdownMenuCheckboxItem>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={onAttachFile} className="pl-8">
<ToolMenuItemContent icon={<Paperclip className="h-4 w-4" />} title="Attach image or PDF" />
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
function ToolMenuItemContent({ icon, title, detail }: { icon: ReactNode; title: string; detail?: string }) {
return (
<span className="flex items-start gap-2">
<span className="mt-0.5 shrink-0">{icon}</span>
<span className="flex min-w-0 flex-col">
<span>{title}</span>
{detail ? <span className="text-xs text-muted-foreground">{detail}</span> : null}
</span>
</span>
)
}
@@ -102,7 +102,19 @@ vi.mock('@/components/model/ModelQuickSelect', () => ({
}))
vi.mock('@/components/session/PermissionModeToggle', () => ({
PermissionModeToggle: () => null,
PermissionModeToggle: () => <div data-testid="permission-mode-toggle" />,
}))
vi.mock('./ComposerToolsMenu', () => ({
ComposerToolsMenu: ({ goalDisabled, goalLabel, onToggleGoal }: {
goalDisabled: boolean
goalLabel: string
onToggleGoal: () => void
}) => (
<button type="button" data-testid="composer-tools-menu" title={goalLabel} disabled={goalDisabled} onClick={onToggleGoal}>
Composer options
</button>
),
}))
vi.mock('@/components/ui/session-status-indicator', () => ({
@@ -318,6 +330,54 @@ describe('PromptInput goal mode', () => {
expect(button).toBeDisabled()
})
it('keeps permission and goal toggles inline on desktop', async () => {
stubMatchMedia(true)
renderComponent()
expect(await screen.findByRole('button', { name: GOAL_BUTTON })).toBeInTheDocument()
expect(screen.getByTestId('permission-mode-toggle')).toBeInTheDocument()
expect(screen.queryByTestId('composer-tools-menu')).not.toBeInTheDocument()
})
it('moves permission and goal toggles into the composer options menu on mobile', async () => {
stubMatchMedia(true)
mocks.useMobile.mockReturnValue(true)
renderComponent()
const menu = await screen.findByTestId('composer-tools-menu')
expect(menu).toHaveAttribute('title', GOAL_BUTTON)
expect(screen.queryByRole('button', { name: GOAL_BUTTON })).not.toBeInTheDocument()
expect(screen.queryByTestId('permission-mode-toggle')).not.toBeInTheDocument()
})
it('starts a goal armed from the mobile composer options menu', async () => {
stubMatchMedia(true)
mocks.useMobile.mockReturnValue(true)
renderComponent()
const input = await screen.findByPlaceholderText('Send a message...')
fireEvent.change(input, { target: { value: 'Ship the feature' } })
fireEvent.click(screen.getByTestId('composer-tools-menu'))
fireEvent.click(screen.getByTitle('Send'))
await waitFor(() => expect(mocks.startGoal).toHaveBeenCalledWith({
sessionId: 'test-session',
directory: '/test',
objective: 'Ship the feature',
}))
})
it('passes the goal lock reason to the mobile composer options menu', async () => {
stubMatchMedia(true)
mocks.useMobile.mockReturnValue(true)
mocks.useSessionGoal.mockReturnValue({ data: { status: 'active' } })
renderComponent()
const menu = await screen.findByTestId('composer-tools-menu')
expect(menu).toHaveAttribute('title', OPEN_GOAL_BUTTON)
expect(menu).toBeDisabled()
})
it('disables goal mode with a reason for child sessions', async () => {
stubMatchMedia(true)
mocks.useSessionPermissionMode.mockReturnValue({
@@ -104,6 +104,10 @@ vi.mock('@/components/session/PermissionModeToggle', () => ({
PermissionModeToggle: () => null,
}))
vi.mock('./ComposerToolsMenu', () => ({
ComposerToolsMenu: () => null,
}))
vi.mock('@/hooks/useSessionGoals', () => ({
useSessionGoal: () => ({ data: undefined }),
useStartSessionGoal: () => ({ mutateAsync: vi.fn(), isPending: false }),
+36 -31
View File
@@ -29,6 +29,7 @@ import { ModelQuickSelect } from '@/components/model/ModelQuickSelect'
import { AgentQuickSelect } from '@/components/agent/AgentQuickSelect'
import { VoiceStatusOverlay, type VoiceStatusOverlayState } from './VoiceStatusOverlay'
import { PermissionModeToggle } from '@/components/session/PermissionModeToggle'
import { ComposerToolsMenu } from './ComposerToolsMenu'
import { useSessionGoal, useStartSessionGoal } from '@/hooks/useSessionGoals'
import { useSessionPermissionMode } from '@/hooks/useSessionPermissionMode'
import { detectMentionTrigger, parsePromptToInput, getFilename, filterAgentsByQuery } from '@/lib/promptParser'
@@ -201,6 +202,10 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
clearSubmittedPrompt(pending.prompt, pending.files, pending.images)
}, [isStreamingResponse, clearSubmittedPrompt])
const openFilePicker = useCallback(() => {
fileInputRef.current?.click()
}, [])
useImperativeHandle(ref, () => ({
setPromptValue: (value: string) => {
setPrompt(value)
@@ -219,13 +224,11 @@ export const PromptInput = memo(forwardRef<PromptInputHandle, PromptInputProps>(
}
textareaRef.current?.focus()
},
triggerFileUpload: () => {
fileInputRef.current?.click()
},
triggerFileUpload: openFilePicker,
openModelPicker: () => {
setIsModelPickerOpen(true)
}
}), [imageAttachments, clearSTT, isRecording, abortRecording, resetVoiceGestureState])
}), [imageAttachments, clearSTT, isRecording, abortRecording, resetVoiceGestureState, openFilePicker])
const sessionAgent = useSessionAgent(sessionID, directory)
const currentMode = localMode ?? sessionAgent.agent
const setStoredAgent = useSessionAgentStore((s) => s.setAgent)
@@ -1187,16 +1190,8 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
: isGoalArmed
? 'Goal mode armed: the next message becomes the objective'
: 'Goal mode: the next message becomes the objective'
const goalModeButton = directory ? (
<IconToggleButton
active={isGoalArmed}
label={goalButtonLabel}
disabled={lockedReason !== null || hasOpenGoal || isBashMode || startGoal.isPending}
onClick={() => setIsGoalArmed((value) => !value)}
>
<Target className="w-5 h-5" />
</IconToggleButton>
) : null
const isGoalModeDisabled = lockedReason !== null || hasOpenGoal || isBashMode || startGoal.isPending
const toggleGoalArmed = () => setIsGoalArmed((value) => !value)
const voiceFeedbackState: VoiceStatusOverlayState | null = isTogglingRecording
? 'starting'
: isProcessing
@@ -1320,16 +1315,6 @@ if (isIOS && isSecureContext && navigator.clipboard && navigator.clipboard.read)
return (
<div className={`relative backdrop-blur-md bg-background opacity-95 border border-border dark:border-border/30 rounded-xl p-2 md:p-3 mb-4 md:mb-1 w-full transition-all ${hasPendingPermissionForSession ? 'border-highlight/50 ring-1 ring-highlight/30' : ''}`}>
{showStopButton && (
<button
onClick={handleStop}
className="absolute bottom-full right-0 mb-2 md:hidden z-50 p-3 rounded-xl transition-all duration-200 active:scale-95 hover:scale-105 bg-destructive hover:bg-destructive/90 text-destructive-foreground border border-destructive/60 shadow-lg shadow-destructive/30"
title="Stop"
>
<SquareFill className="w-5 h-5" />
</button>
)}
<textarea
ref={textareaRef}
value={prompt}
@@ -1396,8 +1381,6 @@ return (
open={isModelPickerOpen}
onOpenChange={setIsModelPickerOpen}
/>
{directory && <PermissionModeToggle sessionID={sessionID} directory={directory} />}
{goalModeButton}
</>
) : (
<>
@@ -1407,8 +1390,19 @@ return (
onAgentChange={handleAgentChange}
isBashMode={isBashMode}
/>
{directory && <PermissionModeToggle sessionID={sessionID} directory={directory} />}
{goalModeButton}
{directory && !isMobile && (
<>
<PermissionModeToggle sessionID={sessionID} directory={directory} />
<IconToggleButton
active={isGoalArmed}
label={goalButtonLabel}
disabled={isGoalModeDisabled}
onClick={toggleGoalArmed}
>
<Target className="w-5 h-5" />
</IconToggleButton>
</>
)}
{isSessionActive && (
<div className="px-2.5 py-1.5 md:px-3 md:py-2 rounded-lg text-xs md:text-sm font-medium text-muted-foreground max-w-[120px] md:max-w-[180px]">
<SessionStatusIndicator sessionID={sessionID} showLabel />
@@ -1421,11 +1415,11 @@ return (
>
{!isSessionActive && !hideSecondaryButtons && (
<button
className="px-2.5 py-0.5 md:px-3 min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto max-w-[110px] md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
className="px-2.5 py-0.5 md:px-3 min-h-[36px] min-w-0 rounded-lg text-xs md:text-sm font-medium border bg-muted border-border text-muted-foreground hover:bg-muted-foreground/10 hover:border-foreground/30 transition-colors cursor-pointer flex-1 md:flex-initial md:w-auto md:max-w-[220px] dark:border-border/30 flex flex-col items-start justify-center overflow-hidden"
>
<span className="truncate w-full text-left">{displayModelName || 'Select model'}</span>
{hasVariants && currentVariant && (
<span className="text-[10px] text-highlight truncate w-full text-center capitalize">{currentVariant}</span>
<span className="text-[10px] text-highlight truncate w-full text-left capitalize">{currentVariant}</span>
)}
</button>
)}
@@ -1461,12 +1455,23 @@ return (
/>
<button
type="button"
onClick={() => fileInputRef.current?.click()}
onClick={openFilePicker}
className="hidden md:block p-2 rounded-lg bg-muted hover:bg-muted-foreground/20 text-muted-foreground hover:text-foreground transition-all duration-200 active:scale-95 hover:scale-105 shadow-md border border-border"
title="Upload image or PDF"
>
<Upload className="w-5 h-5" />
</button>
{isMobile && directory && (
<ComposerToolsMenu
sessionID={sessionID}
directory={directory}
goalArmed={isGoalArmed}
goalDisabled={isGoalModeDisabled}
goalLabel={goalButtonLabel}
onToggleGoal={toggleGoalArmed}
onAttachFile={openFilePicker}
/>
)}
{sttEnabled && sttSupported && (
renderVoiceButton('desktop')
)}