mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat: add assistant mode, SSE streaming, and OpenCode server integration (#214)
This commit is contained in:
1 parent
3cc24288a6
commit
c3d6549f01
133 files changed
+7284
-6293
No files matched your search
@@ -5,12 +5,10 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { DesktopSidebar } from './DesktopSidebar'
|
||||
import * as useDesktopModule from '@/hooks/useDesktop'
|
||||
import * as useSidebarCollapsedModule from '@/hooks/useSidebarCollapsed'
|
||||
import * as useMemoryPluginStatusModule from '@/hooks/useMemoryPluginStatus'
|
||||
import * as useAuthModule from '@/hooks/useAuth'
|
||||
|
||||
vi.mock('@/hooks/useDesktop')
|
||||
vi.mock('@/hooks/useSidebarCollapsed')
|
||||
vi.mock('@/hooks/useMemoryPluginStatus')
|
||||
vi.mock('@/hooks/useAuth')
|
||||
|
||||
function LocationDisplay() {
|
||||
@@ -44,7 +42,6 @@ describe('DesktopSidebar', () => {
|
||||
it('returns null when user is not authenticated', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: false,
|
||||
isLoading: false,
|
||||
@@ -63,7 +60,6 @@ describe('DesktopSidebar', () => {
|
||||
it('returns null when auth state is loading', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: true,
|
||||
@@ -82,7 +78,6 @@ describe('DesktopSidebar', () => {
|
||||
it('returns null when not desktop', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -101,7 +96,6 @@ describe('DesktopSidebar', () => {
|
||||
it('renders primary CTA for root path', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -117,7 +111,6 @@ describe('DesktopSidebar', () => {
|
||||
it('renders primary CTAs for repo detail', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -133,7 +126,6 @@ describe('DesktopSidebar', () => {
|
||||
it('renders primary CTAs for session detail', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -149,7 +141,6 @@ describe('DesktopSidebar', () => {
|
||||
it('renders primary CTA for schedules routes', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -166,7 +157,6 @@ describe('DesktopSidebar', () => {
|
||||
const dispatchEventSpy = vi.spyOn(window, 'dispatchEvent')
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -188,7 +178,6 @@ describe('DesktopSidebar', () => {
|
||||
it('opens dialog items by updating the dialog query param', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
@@ -211,7 +200,6 @@ describe('DesktopSidebar', () => {
|
||||
it('opens settings by updating settings query params', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useState } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useDesktop } from '@/hooks/useDesktop'
|
||||
import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed'
|
||||
import { useMemoryPluginStatus } from '@/hooks/useMemoryPluginStatus'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
|
||||
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
|
||||
@@ -19,7 +18,6 @@ export function DesktopSidebar() {
|
||||
const navigate = useNavigate()
|
||||
const [collapsed, toggle] = useSidebarCollapsed()
|
||||
const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false)
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus()
|
||||
const { isAuthenticated, isLoading, logout } = useAuth()
|
||||
|
||||
const isDesktop = useDesktop()
|
||||
@@ -32,7 +30,7 @@ export function DesktopSidebar() {
|
||||
return null
|
||||
}
|
||||
|
||||
const { primary, items } = buildNavModel(location.pathname, { memoryPluginEnabled })
|
||||
const { primary, items } = buildNavModel(location.pathname)
|
||||
|
||||
const handlePrimaryClick = (item: NavPrimaryCta) => {
|
||||
if (item.to) {
|
||||
|
||||
@@ -238,20 +238,4 @@ describe('MobileTabBar', () => {
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders tab bar on Memories path /repos/:id/memories', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/repos/1/memories']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Files')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
expect(screen.getByText('Schedules')).toBeInTheDocument()
|
||||
expect(screen.getByText('More')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -48,7 +48,6 @@ function getMobileTabRouteState(pathname: string): MobileTabRouteState {
|
||||
|
||||
switch (repoSection) {
|
||||
case undefined:
|
||||
case 'memories':
|
||||
case 'assistant':
|
||||
return { mode: 'global', isInsideRepo: true, repoId }
|
||||
case 'schedules':
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { beforeEach, describe, it, expect, vi } from 'vitest'
|
||||
import { MemoryRouter, useNavigate } from 'react-router-dom'
|
||||
import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { MoreDrawer } from './MoreDrawer'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { useCommands } from '@/hooks/useCommands'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { getRepo } from '@/api/repos'
|
||||
|
||||
vi.mock('@/hooks/useAuth')
|
||||
vi.mock('@/hooks/useServerHealth')
|
||||
vi.mock('@/hooks/useCommands')
|
||||
vi.mock('@/hooks/useMemoryPluginStatus', () => ({
|
||||
useMemoryPluginStatus: () => ({ memoryPluginEnabled: false }),
|
||||
vi.mock('@/api/repos', () => ({
|
||||
getRepo: vi.fn(),
|
||||
}))
|
||||
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
|
||||
FileBrowserSheet: ({ isOpen, basePath, onFileSelect }: { isOpen: boolean; basePath: string; onFileSelect: (file: { path: string }) => void }) => (
|
||||
@@ -72,6 +74,32 @@ const mockServerHealth = (health?: Partial<ReturnType<typeof useServerHealth>['d
|
||||
})
|
||||
}
|
||||
|
||||
const createQueryClient = () => new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const renderMoreDrawer = ({
|
||||
initialEntry = '/',
|
||||
routePath = '*',
|
||||
onClose = vi.fn(),
|
||||
}: {
|
||||
initialEntry?: string
|
||||
routePath?: string
|
||||
onClose?: () => void
|
||||
} = {}) => render(
|
||||
<QueryClientProvider client={createQueryClient()}>
|
||||
<MemoryRouter initialEntries={[initialEntry]}>
|
||||
<Routes>
|
||||
<Route path={routePath} element={<MoreDrawer isOpen onClose={onClose} />} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
describe('MoreDrawer', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -94,16 +122,22 @@ describe('MoreDrawer', () => {
|
||||
useUIState.getState().clearPendingPromptCommand()
|
||||
useUIState.getState().clearPendingPromptFile()
|
||||
useUIState.getState().setActivePromptFileBasePath(null)
|
||||
vi.mocked(getRepo).mockResolvedValue({
|
||||
id: 1,
|
||||
localPath: 'wrong-repo',
|
||||
fullPath: '/workspace/repos/wrong-repo',
|
||||
branch: 'main',
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
})
|
||||
})
|
||||
|
||||
it('renders Settings and Logout menu items', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument()
|
||||
expect(screen.getByText('Logout')).toBeInTheDocument()
|
||||
})
|
||||
@@ -112,10 +146,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
expect(screen.queryByText('Theme')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Light')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Dark')).not.toBeInTheDocument()
|
||||
@@ -128,10 +159,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
fireEvent.click(screen.getByText('Settings'))
|
||||
expect(navigateMock).toHaveBeenCalledWith(
|
||||
{ search: 'settings=open&tab=account' },
|
||||
@@ -144,10 +172,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth(logoutMock)
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
fireEvent.click(screen.getByText('Logout'))
|
||||
expect(logoutMock).toHaveBeenCalled()
|
||||
})
|
||||
@@ -156,10 +181,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth({ opencodeVersion: '1.4.11', opencodeManagerVersion: '0.9.16' })
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
expect(screen.getByText('v1.4.11 · Manager v0.9.16')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -167,10 +189,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth({ opencode: 'unhealthy' as const, opencodeVersion: '1.4.11' })
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
expect(screen.getByText('v1.4.11')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -178,10 +197,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth({ opencodeVersion: null, opencodeManagerVersion: null })
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ onClose: handleClose })
|
||||
expect(screen.queryByText('OpenCode')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -189,10 +205,7 @@ describe('MoreDrawer', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<MoreDrawer isOpen onClose={handleClose} />,
|
||||
{ wrapper: ({ children }) => <MemoryRouter initialEntries={['/repos/1/sessions/session-1']}>{children}</MemoryRouter> },
|
||||
)
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
|
||||
|
||||
fireEvent.click(screen.getByText('Commands'))
|
||||
expect(screen.queryByText('/help')).not.toBeInTheDocument()
|
||||
@@ -207,10 +220,7 @@ describe('MoreDrawer', () => {
|
||||
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> },
|
||||
)
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
|
||||
|
||||
fireEvent.click(screen.getByText('Mention File'))
|
||||
expect(screen.getByTestId('mention-file-browser')).toHaveAttribute('data-base-path', 'repo')
|
||||
@@ -220,4 +230,14 @@ describe('MoreDrawer', () => {
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows Assistant instead of the source repo on assistant routes', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/assistant', routePath: '/repos/:id/assistant', onClose: handleClose })
|
||||
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
expect(screen.queryByText('wrong-repo')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
})
|
||||
@@ -1,15 +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 { useNavigate, useLocation, useParams } from 'react-router-dom'
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import { ChevronDown, ChevronRight, Command as CommandIcon, FileText, X, GitBranch } from 'lucide-react'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { useMemoryPluginStatus } from '@/hooks/useMemoryPluginStatus'
|
||||
import { useCommands } from '@/hooks/useCommands'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getRepo } from '@/api/repos'
|
||||
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 { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
|
||||
type CommandType = components['schemas']['Command']
|
||||
@@ -22,17 +25,40 @@ interface MoreDrawerProps {
|
||||
export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const repoId = id ? Number(id) : null
|
||||
const [commandsOpen, setCommandsOpen] = useState(false)
|
||||
const [mentionFileBrowserOpen, setMentionFileBrowserOpen] = useState(false)
|
||||
const swipeRef = useRef<HTMLDivElement>(null)
|
||||
const { bind } = useSwipeBack(onClose, { enabled: true, suspendsRouteSwipe: false })
|
||||
const { logout } = useAuth()
|
||||
const { data: health } = useServerHealth()
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus()
|
||||
const isSessionDetail = /^\/repos\/\d+\/sessions\/[^/]+$/.test(location.pathname)
|
||||
const isAssistantRoute = /^\/repos\/\d+\/assistant$/.test(location.pathname)
|
||||
const isAssistantSession = isSessionDetail && new URLSearchParams(location.search).get('assistant') === '1'
|
||||
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)
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && swipeRef.current) {
|
||||
const cleanup = bind(swipeRef.current)
|
||||
return cleanup
|
||||
}
|
||||
}, [isOpen, bind])
|
||||
|
||||
const { data: repo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => repoId ? getRepo(repoId) : null,
|
||||
enabled: !!repoId,
|
||||
})
|
||||
|
||||
const currentBranch = repo?.currentBranch || repo?.branch
|
||||
const repoDisplayName = isAssistantRoute || isAssistantSession
|
||||
? 'Assistant'
|
||||
: repo ? getRepoDisplayName(repo.repoUrl, repo.localPath, repo.sourcePath) : null
|
||||
|
||||
const handleSettingsClick = () => {
|
||||
const newParams = new URLSearchParams(location.search)
|
||||
newParams.delete('mobileTab')
|
||||
@@ -83,7 +109,7 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
onClose()
|
||||
}
|
||||
|
||||
const items = buildMoreItems(location.pathname, { memoryPluginEnabled })
|
||||
const items = buildMoreItems(location.pathname)
|
||||
const commands = filterCommands('')
|
||||
|
||||
const opencodeVersion = health?.opencodeVersion
|
||||
@@ -95,18 +121,34 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
|
||||
return (
|
||||
<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>
|
||||
<div ref={swipeRef} className="flex flex-col flex-shrink-0 border-b border-border bg-background px-4 py-1.5">
|
||||
<div className="flex items-center justify-between gap-3 mb-2">
|
||||
{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>
|
||||
{(repoDisplayName || currentBranch) && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
{repoDisplayName && (
|
||||
<span className="font-medium text-orange-600 dark:text-orange-400">{repoDisplayName}</span>
|
||||
)}
|
||||
|
||||
{currentBranch && (
|
||||
<>
|
||||
<GitBranch className="h-3.5 w-3.5" />
|
||||
<span>{currentBranch}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<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 && (
|
||||
|
||||
@@ -3,9 +3,11 @@ import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { BottomSheet, BottomSheetHeader, BottomSheetContent } from '@/components/ui/bottom-sheet'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import { FolderGit2, Check } from 'lucide-react'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Check, Plus } from 'lucide-react'
|
||||
|
||||
interface RepoQuickSwitchSheetProps {
|
||||
isOpen: boolean
|
||||
@@ -16,6 +18,7 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
|
||||
const activeRepoId = useMemo(() => {
|
||||
const match = location.pathname.match(/^\/repos\/(\d+)/)
|
||||
@@ -69,17 +72,29 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
}
|
||||
|
||||
return (
|
||||
<BottomSheet isOpen={isOpen} onClose={onClose} heightClass="h-[70dvh]" ariaLabel="Switch repo">
|
||||
<BottomSheetHeader>
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Search projects..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
autoFocus
|
||||
className="flex-shrink-0"
|
||||
/>
|
||||
</BottomSheetHeader>
|
||||
<>
|
||||
<BottomSheet isOpen={isOpen} onClose={onClose} heightClass="h-[70dvh]" ariaLabel="Switch repo">
|
||||
<BottomSheetHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Search projects..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
autoFocus
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
onClick={() => setAddRepoOpen(true)}
|
||||
className="flex-shrink-0"
|
||||
>
|
||||
<Plus className="h-4 w-4" /> Repo
|
||||
<span className="sr-only">Add repository</span>
|
||||
</Button>
|
||||
</div>
|
||||
</BottomSheetHeader>
|
||||
<BottomSheetContent className="flex flex-col gap-2 overflow-y-auto pt-2">
|
||||
{isLoading ? (
|
||||
<div className="flex flex-col gap-2">
|
||||
@@ -129,6 +144,8 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
</div>
|
||||
)}
|
||||
</BottomSheetContent>
|
||||
</BottomSheet>
|
||||
</BottomSheet>
|
||||
<AddRepoDialog open={addRepoOpen} onOpenChange={setAddRepoOpen} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -11,80 +11,52 @@ describe('buildMoreItems', () => {
|
||||
expect(items[3].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns repo-specific items with memory when plugin enabled for /repos/:id', () => {
|
||||
const items = buildMoreItems('/repos/42', { memoryPluginEnabled: true })
|
||||
expect(items).toHaveLength(9)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[0].dialog).toBe('files')
|
||||
expect(items[1].key).toBe('memory')
|
||||
expect(items[1].to).toBe('/repos/42/memories')
|
||||
expect(items[2].key).toBe('mcp')
|
||||
expect(items[2].dialog).toBe('mcp')
|
||||
expect(items[3].key).toBe('skills')
|
||||
expect(items[3].dialog).toBe('skills')
|
||||
expect(items[4].key).toBe('reset-permissions')
|
||||
expect(items[4].dialog).toBe('resetPermissions')
|
||||
expect(items[4].danger).toBe(true)
|
||||
expect(items[5].key).toBe('schedules')
|
||||
expect(items[5].to).toBe('/repos/42/schedules')
|
||||
expect(items[6].key).toBe('source-control')
|
||||
expect(items[6].dialog).toBe('sourceControl')
|
||||
expect(items[7].key).toBe('settings')
|
||||
expect(items[8].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('omits memory item for /repos/:id when plugin disabled', () => {
|
||||
it('returns repo-specific items for /repos/:id', () => {
|
||||
const items = buildMoreItems('/repos/42')
|
||||
expect(items).toHaveLength(8)
|
||||
expect(items.some((item) => item.key === 'memory')).toBe(false)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[0].dialog).toBe('files')
|
||||
expect(items[1].key).toBe('mcp')
|
||||
expect(items[1].dialog).toBe('mcp')
|
||||
expect(items[2].key).toBe('skills')
|
||||
expect(items[2].dialog).toBe('skills')
|
||||
expect(items[3].key).toBe('reset-permissions')
|
||||
expect(items[3].dialog).toBe('resetPermissions')
|
||||
expect(items[3].danger).toBe(true)
|
||||
expect(items[4].key).toBe('schedules')
|
||||
expect(items[4].to).toBe('/repos/42/schedules')
|
||||
expect(items[5].key).toBe('source-control')
|
||||
expect(items[5].dialog).toBe('sourceControl')
|
||||
expect(items[6].key).toBe('settings')
|
||||
expect(items[7].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns session-specific items with memory when plugin enabled for /repos/:id/sessions/:sid', () => {
|
||||
const items = buildMoreItems('/repos/42/sessions/abc', { memoryPluginEnabled: true })
|
||||
expect(items).toHaveLength(9)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[1].key).toBe('memory')
|
||||
expect(items[2].key).toBe('mcp')
|
||||
expect(items[3].key).toBe('skills')
|
||||
expect(items[4].key).toBe('lsp')
|
||||
expect(items[4].dialog).toBe('lsp')
|
||||
expect(items[5].key).toBe('reset-permissions')
|
||||
expect(items[6].key).toBe('source-control')
|
||||
expect(items[7].key).toBe('settings')
|
||||
expect(items[8].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('omits memory item for /repos/:id/sessions/:sid when plugin disabled', () => {
|
||||
it('returns session-specific items for /repos/:id/sessions/:sid', () => {
|
||||
const items = buildMoreItems('/repos/42/sessions/abc')
|
||||
expect(items).toHaveLength(8)
|
||||
expect(items.some((item) => item.key === 'memory')).toBe(false)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[1].key).toBe('mcp')
|
||||
expect(items[2].key).toBe('skills')
|
||||
expect(items[3].key).toBe('lsp')
|
||||
expect(items[3].dialog).toBe('lsp')
|
||||
expect(items[4].key).toBe('reset-permissions')
|
||||
expect(items[5].key).toBe('source-control')
|
||||
expect(items[6].key).toBe('settings')
|
||||
expect(items[7].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns assistant workspace items for /repos/:id/assistant', () => {
|
||||
const items = buildMoreItems('/repos/42/assistant', { memoryPluginEnabled: true })
|
||||
expect(items).toHaveLength(9)
|
||||
const items = buildMoreItems('/repos/42/assistant')
|
||||
expect(items).toHaveLength(8)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[0].dialog).toBe('files')
|
||||
expect(items[1].key).toBe('memory')
|
||||
expect(items[1].to).toBe('/repos/42/memories')
|
||||
expect(items[2].key).toBe('mcp')
|
||||
expect(items[3].key).toBe('skills')
|
||||
expect(items[4].key).toBe('reset-permissions')
|
||||
expect(items[5].key).toBe('schedules')
|
||||
expect(items[6].key).toBe('source-control')
|
||||
expect(items[7].key).toBe('settings')
|
||||
expect(items[8].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns only Settings + Logout for /repos/:id/memories', () => {
|
||||
const items = buildMoreItems('/repos/42/memories')
|
||||
expect(items).toHaveLength(2)
|
||||
expect(items[0].key).toBe('settings')
|
||||
expect(items[1].key).toBe('logout')
|
||||
expect(items[1].key).toBe('mcp')
|
||||
expect(items[2].key).toBe('skills')
|
||||
expect(items[3].key).toBe('reset-permissions')
|
||||
expect(items[4].key).toBe('schedules')
|
||||
expect(items[5].key).toBe('source-control')
|
||||
expect(items[6].key).toBe('settings')
|
||||
expect(items[7].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns only Settings + Logout for /schedules', () => {
|
||||
@@ -166,13 +138,6 @@ describe('buildNavModel', () => {
|
||||
expect(model2.primary[1].to).toBe('/repos/5/assistant')
|
||||
})
|
||||
|
||||
it('returns empty primary for memories routes', () => {
|
||||
const model = buildNavModel('/repos/5/memories')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/repos/5/assistant')
|
||||
})
|
||||
|
||||
it('returns assistant primary for unknown routes', () => {
|
||||
const model = buildNavModel('/unknown/path')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
@@ -181,8 +146,8 @@ describe('buildNavModel', () => {
|
||||
})
|
||||
|
||||
it('preserves backwards compatibility with buildMoreItems', () => {
|
||||
const model = buildNavModel('/repos/42', { memoryPluginEnabled: true })
|
||||
const items = buildMoreItems('/repos/42', { memoryPluginEnabled: true })
|
||||
const model = buildNavModel('/repos/42')
|
||||
const items = buildMoreItems('/repos/42')
|
||||
expect(model.items).toEqual(items)
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { Brain, Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus } from 'lucide-react'
|
||||
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus } from 'lucide-react'
|
||||
|
||||
export interface MoreDrawerItem {
|
||||
key: string
|
||||
@@ -24,12 +24,6 @@ export interface NavModel {
|
||||
items: MoreDrawerItem[]
|
||||
}
|
||||
|
||||
export interface BuildMoreItemsOptions {
|
||||
memoryPluginEnabled?: boolean
|
||||
}
|
||||
|
||||
export type BuildNavOptions = BuildMoreItemsOptions
|
||||
|
||||
function getAssistantNavItem(pathname: string, variant: NavPrimaryCta['variant'] = 'secondary'): NavPrimaryCta {
|
||||
const repoMatch = /^\/repos\/(\d+)/.exec(pathname)
|
||||
|
||||
@@ -49,8 +43,7 @@ function getBaseItems(): MoreDrawerItem[] {
|
||||
]
|
||||
}
|
||||
|
||||
export function buildNavModel(pathname: string, options: BuildNavOptions = {}): NavModel {
|
||||
const { memoryPluginEnabled = false } = options
|
||||
export function buildNavModel(pathname: string): NavModel {
|
||||
const baseItems = getBaseItems()
|
||||
|
||||
const repoDetailMatch = /^\/repos\/(\d+)$/.exec(pathname)
|
||||
@@ -58,9 +51,6 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}):
|
||||
const id = repoDetailMatch[1]
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
|
||||
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
|
||||
{ key: 'reset-permissions', label: 'Reset Permissions', icon: ShieldOff, dialog: 'resetPermissions', danger: true },
|
||||
@@ -83,9 +73,6 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}):
|
||||
const id = sessionDetailMatch[1]
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
|
||||
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
|
||||
{ key: 'lsp', label: 'LSP', icon: Code2, dialog: 'lsp' },
|
||||
@@ -108,9 +95,6 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}):
|
||||
const id = assistantMatch[1]
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
|
||||
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
|
||||
{ key: 'reset-permissions', label: 'Reset Permissions', icon: ShieldOff, dialog: 'resetPermissions', danger: true },
|
||||
@@ -152,15 +136,6 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}):
|
||||
}
|
||||
}
|
||||
|
||||
if (/^\/repos\/\d+\/memories$/.test(pathname)) {
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname),
|
||||
@@ -169,6 +144,6 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}):
|
||||
}
|
||||
}
|
||||
|
||||
export function buildMoreItems(pathname: string, options: BuildMoreItemsOptions = {}): MoreDrawerItem[] {
|
||||
return buildNavModel(pathname, options).items
|
||||
export function buildMoreItems(pathname: string): MoreDrawerItem[] {
|
||||
return buildNavModel(pathname).items
|
||||
}
|
||||
Reference in new issue
Block a user