Feat/mobile session actions (#206)

* feat: improve mobile session actions

* feat(frontend): improve mobile session actions

Replace inline file search in MoreDrawer with FileBrowserSheet for
mention-file interactions. Add activePromptFileBasePath state to track
workspace context, normalize file paths on selection, and improve
command sorting with relevance ranking (exact > prefix > partial match).

* refactor(frontend): remove dead state and deduplicate event reconciliation

Remove unused activePromptDirectory from uiStateStore and its writers in
SessionDetail and PromptInput. Consolidate duplicated permission and
question reconciliation helpers in EventContext behind a generic
session-scoped helper.

---------

Co-authored-by: Chris Scott <>
This commit is contained in:
Chris ScottandChris Scott authored and GitHub committed 2026-04-28 16:20:54 -04:00
1 parent 389120559f
commit 04400c91cc
17 files changed
+709 -132

No files matched your search

@@ -1,15 +1,27 @@
import { render, screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { beforeEach, describe, it, expect, vi } from 'vitest'
import { MemoryRouter, useNavigate } from 'react-router-dom'
import { MoreDrawer } from './MoreDrawer'
import { useAuth } from '@/hooks/useAuth'
import { useServerHealth } from '@/hooks/useServerHealth'
import { useCommands } from '@/hooks/useCommands'
import { useUIState } from '@/stores/uiStateStore'
vi.mock('@/hooks/useAuth')
vi.mock('@/hooks/useServerHealth')
vi.mock('@/hooks/useCommands')
vi.mock('@/hooks/useMemoryPluginStatus', () => ({
useMemoryPluginStatus: () => ({ memoryPluginEnabled: false }),
}))
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
FileBrowserSheet: ({ isOpen, basePath, onFileSelect }: { isOpen: boolean; basePath: string; onFileSelect: (file: { path: string }) => void }) => (
isOpen ? (
<div data-testid="mention-file-browser" data-base-path={basePath}>
<button type="button" onClick={() => onFileSelect({ path: 'repo/src/App.tsx' })}>App.tsx</button>
</div>
) : null
),
}))
vi.mock('react-router-dom', async () => {
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom')
return {
@@ -64,6 +76,24 @@ describe('MoreDrawer', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(useNavigate).mockReturnValue(vi.fn())
vi.mocked(useCommands).mockReturnValue({
commands: [],
loading: false,
error: null,
filterCommands: vi.fn().mockReturnValue([
{
name: 'help',
description: 'Show help',
template: '',
agent: '',
model: '',
hints: [],
},
]),
})
useUIState.getState().clearPendingPromptCommand()
useUIState.getState().clearPendingPromptFile()
useUIState.getState().setActivePromptFileBasePath(null)
})
it('renders Settings and Logout menu items', () => {
@@ -74,7 +104,6 @@ describe('MoreDrawer', () => {
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('OpenCode')).toBeInTheDocument()
expect(screen.getByText('Settings')).toBeInTheDocument()
expect(screen.getByText('Logout')).toBeInTheDocument()
})
@@ -131,8 +160,7 @@ describe('MoreDrawer', () => {
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('OpenCode v1.4.11')).toBeInTheDocument()
expect(screen.getByText('Manager v0.9.16')).toBeInTheDocument()
expect(screen.getByText('v1.4.11 · Manager v0.9.16')).toBeInTheDocument()
})
it('shows unhealthy server status when server is unhealthy', () => {
@@ -143,7 +171,7 @@ describe('MoreDrawer', () => {
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('OpenCode v1.4.11')).toBeInTheDocument()
expect(screen.getByText('v1.4.11')).toBeInTheDocument()
})
it('shows fallback text when version is not available', () => {
@@ -154,7 +182,42 @@ describe('MoreDrawer', () => {
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('OpenCode')).toBeInTheDocument()
expect(screen.queryByText('OpenCode')).not.toBeInTheDocument()
})
it('shows session commands and selects a command', () => {
mockAuth()
mockServerHealth()
const handleClose = vi.fn()
render(
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter initialEntries={['/repos/1/sessions/session-1']}>{children}</MemoryRouter> },
)
fireEvent.click(screen.getByText('Commands'))
expect(screen.queryByText('/help')).not.toBeInTheDocument()
fireEvent.click(screen.getByText('help'))
expect(useUIState.getState().pendingPromptCommand?.command.name).toBe('help')
expect(handleClose).toHaveBeenCalled()
})
it('opens file browser and selects a file mention', () => {
mockAuth()
mockServerHealth()
const handleClose = vi.fn()
useUIState.getState().setActivePromptFileBasePath('repo')
render(
<MoreDrawer isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter initialEntries={['/repos/1/sessions/session-1']}>{children}</MemoryRouter> },
)
fireEvent.click(screen.getByText('Mention File'))
expect(screen.getByTestId('mention-file-browser')).toHaveAttribute('data-base-path', 'repo')
fireEvent.click(screen.getByText('App.tsx'))
expect(useUIState.getState().pendingPromptFile?.path).toBe('src/App.tsx')
expect(handleClose).toHaveBeenCalled()
})
})
+109 -11
View File
@@ -1,9 +1,18 @@
import { useNavigate, useLocation } from 'react-router-dom'
import { useState } from 'react'
import { ChevronDown, ChevronRight, Command as CommandIcon, FileText, X } from 'lucide-react'
import { useAuth } from '@/hooks/useAuth'
import { useServerHealth } from '@/hooks/useServerHealth'
import { useMemoryPluginStatus } from '@/hooks/useMemoryPluginStatus'
import { SideDrawer, SideDrawerHeader, SideDrawerContent } from '@/components/ui/side-drawer'
import { useCommands } from '@/hooks/useCommands'
import { useUIState } from '@/stores/uiStateStore'
import { OPENCODE_API_ENDPOINT } from '@/config'
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
import { buildMoreItems } from './moreDrawerItems'
import type { components } from '@/api/opencode-types'
type CommandType = components['schemas']['Command']
interface MoreDrawerProps {
isOpen: boolean
@@ -13,9 +22,16 @@ interface MoreDrawerProps {
export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
const navigate = useNavigate()
const location = useLocation()
const [commandsOpen, setCommandsOpen] = useState(false)
const [mentionFileBrowserOpen, setMentionFileBrowserOpen] = useState(false)
const { logout } = useAuth()
const { data: health } = useServerHealth()
const { memoryPluginEnabled } = useMemoryPluginStatus()
const isSessionDetail = /^\/repos\/\d+\/sessions\/[^/]+$/.test(location.pathname)
const { filterCommands } = useCommands(isSessionDetail ? OPENCODE_API_ENDPOINT : null)
const activePromptFileBasePath = useUIState((state) => state.activePromptFileBasePath)
const selectPromptCommand = useUIState((state) => state.selectPromptCommand)
const selectPromptFile = useUIState((state) => state.selectPromptFile)
const handleSettingsClick = () => {
const newParams = new URLSearchParams(location.search)
@@ -44,23 +60,99 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
}
}
const handleCommandClick = (command: CommandType) => {
selectPromptCommand(command)
onClose()
}
const getPromptFilePath = (path: string) => {
if (!activePromptFileBasePath) return path
const normalizedPath = path.replace(/^\.\//, '')
const normalizedBasePath = activePromptFileBasePath.replace(/^\.\//, '').replace(/\/+$/, '')
const basePrefix = `${normalizedBasePath}/`
return normalizedPath.startsWith(basePrefix)
? normalizedPath.slice(basePrefix.length)
: normalizedPath
}
const handleFileClick = (path: string) => {
selectPromptFile(getPromptFilePath(path))
setMentionFileBrowserOpen(false)
onClose()
}
const items = buildMoreItems(location.pathname, { memoryPluginEnabled })
const commands = filterCommands('')
const opencodeVersion = health?.opencodeVersion
const managerVersion = health?.opencodeManagerVersion
const versionLabel = [
opencodeVersion ? `v${opencodeVersion}` : null,
managerVersion ? `Manager v${managerVersion}` : null,
].filter(Boolean).join(' · ')
return (
<SideDrawer isOpen={isOpen} onClose={onClose} side="right" ariaLabel="More">
<SideDrawerHeader
title={opencodeVersion ? `OpenCode v${opencodeVersion}` : 'OpenCode'}
onClose={onClose}
meta={
managerVersion ? (
<div className="text-xs text-muted-foreground">Manager v{managerVersion}</div>
) : null
}
/>
<SideDrawer isOpen={isOpen} onClose={onClose} side="right" ariaLabel="More" widthClass="w-screen sm:w-[min(90vw,420px)]">
<div className="flex flex-shrink-0 items-center justify-between gap-3 border-b border-border bg-background px-4 py-1.5">
{versionLabel && (
<span className="truncate text-xs leading-tight text-muted-foreground">{versionLabel}</span>
)}
<button
type="button"
onClick={onClose}
className="shrink-0 rounded-sm p-2 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
aria-label="Close"
>
<X className="h-5 w-5" />
</button>
</div>
<SideDrawerContent className="flex flex-col gap-1">
{isSessionDetail && (
<div className="flex flex-col gap-1">
<button
type="button"
onClick={() => setCommandsOpen((open) => !open)}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
aria-expanded={commandsOpen}
>
<CommandIcon className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">Commands</span>
{commandsOpen ? (
<ChevronDown className="w-4 h-4 text-muted-foreground" />
) : (
<ChevronRight className="w-4 h-4 text-muted-foreground" />
)}
</button>
{commandsOpen && (
<div className="-mx-4 max-h-64 overflow-y-auto border-y border-border bg-muted/30 p-1 sm:mx-0 sm:rounded-lg sm:border">
{commands.map((command) => (
<button
key={command.name}
type="button"
onClick={() => handleCommandClick(command)}
className="flex w-full min-w-0 items-start gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-accent"
>
<span className="font-mono text-sm font-medium text-blue-600 dark:text-blue-400">{command.name}</span>
{command.description && (
<span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">{command.description}</span>
)}
</button>
))}
</div>
)}
<button
type="button"
onClick={() => setMentionFileBrowserOpen(true)}
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
>
<FileText className="w-5 h-5 text-muted-foreground" />
<span className="font-medium text-foreground flex-1">Mention File</span>
<ChevronRight className="w-4 h-4 text-muted-foreground" />
</button>
</div>
)}
{items.map((item) => (
<button
key={item.key}
@@ -81,6 +173,12 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
</button>
))}
</SideDrawerContent>
<FileBrowserSheet
isOpen={mentionFileBrowserOpen}
onClose={() => setMentionFileBrowserOpen(false)}
basePath={activePromptFileBasePath ?? ''}
onFileSelect={(file) => handleFileClick(file.path)}
/>
</SideDrawer>
)
}
@@ -164,4 +164,46 @@ describe('RepoQuickSwitchSheet', () => {
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/assistant')
expect(handleClose).toHaveBeenCalled()
})
it('navigates from assistant to repo detail when clicking active repo', async () => {
vi.mocked(listRepos).mockResolvedValue([
{
id: 1,
repoUrl: 'https://github.com/test/repo1.git',
localPath: '/path/to/repo1',
sourcePath: null,
currentBranch: 'main',
isLocal: false,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
])
const handleClose = vi.fn()
render(
<QueryClientProvider client={new QueryClient()}>
<MemoryRouter initialEntries={['/repos/1/assistant?mobileTab=repos']}>
<Routes>
<Route
path="*"
element={
<>
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
<LocationSpy />
</>
}
/>
</Routes>
</MemoryRouter>
</QueryClientProvider>,
)
await waitFor(() => {
expect(screen.getByText('repo1')).toBeInTheDocument()
})
fireEvent.click(screen.getByText('repo1'))
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1')
expect(handleClose).not.toHaveBeenCalled()
})
})
@@ -39,14 +39,20 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
}, [repos, searchQuery])
const handleClick = (id: number) => {
if (id === activeRepoId) {
const pendingAction = new URLSearchParams(location.search).get('mobileTabAction')
if (pendingAction === 'assistant') {
navigate(`/repos/${id}/assistant`)
onClose()
return
}
const pendingAction = new URLSearchParams(location.search).get('mobileTabAction')
if (pendingAction === 'assistant') {
navigate(`/repos/${id}/assistant`)
const isAssistantRoute = location.pathname === `/repos/${id}/assistant`
if (id === activeRepoId) {
if (isAssistantRoute) {
navigate(`/repos/${id}`, { replace: true })
return
}
onClose()
return
}