feat(servers): bring linked-server sessions to parity with local

Add a read-only Source Control panel for linked servers backed by the OpenCode VCS API, broadcast remote events to every client, include recent linked-server sessions in Activity with per-server sidebar indicators, and enable the session picker, tool shortcuts, mobile activity, remote Skills panel and remote permission prompt titles.
This commit is contained in:
Chris Scott committed 2026-10-18 21:46:14 -04:00
1 parent 9ec2ed5903
commit 7874afdab9
38 files changed
+1506 -279

No files matched your search

@@ -6,6 +6,7 @@ import { LinkedServersNav } from './LinkedServersNav'
const mocks = vi.hoisted(() => ({
useOpenCodeServers: vi.fn(),
useOpenCodeServerStatuses: vi.fn(),
useServerActivityState: vi.fn(),
}))
vi.mock('@/hooks/useOpenCodeServers', () => ({
@@ -13,6 +14,10 @@ vi.mock('@/hooks/useOpenCodeServers', () => ({
useOpenCodeServerStatuses: mocks.useOpenCodeServerStatuses,
}))
vi.mock('@/hooks/useActiveWork', () => ({
useServerActivityState: mocks.useServerActivityState,
}))
const kitchen = {
id: 'srv_kitchen',
name: 'Kitchen',
@@ -46,6 +51,7 @@ describe('LinkedServersNav', () => {
beforeEach(() => {
vi.clearAllMocks()
mocks.useOpenCodeServers.mockReturnValue({ servers: [], isLoading: false })
mocks.useServerActivityState.mockReturnValue(null)
mocks.useOpenCodeServerStatuses.mockReturnValue({
statuses: [],
statusById: { srv_kitchen: { serverId: 'srv_kitchen', connected: true, version: null, error: null } },
@@ -117,4 +123,32 @@ describe('LinkedServersNav', () => {
expect(onNavigate).toHaveBeenCalledWith('/servers/srv_kitchen')
})
it('shows the activity indicator only for the server with an active session', () => {
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen, office], isLoading: false })
mocks.useServerActivityState.mockImplementation((serverId: string) =>
serverId === 'srv_kitchen' ? 'needs-input' : null,
)
renderNav()
expect(mocks.useServerActivityState).toHaveBeenCalledWith('srv_kitchen')
expect(mocks.useServerActivityState).toHaveBeenCalledWith('srv_office')
expect(screen.getByRole('img', { name: 'Session needs input' })).toBeInTheDocument()
expect(screen.queryByRole('img', { name: 'Sessions running' })).not.toBeInTheDocument()
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
})
it('shows the running indicator in the sheet variant', () => {
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
mocks.useServerActivityState.mockReturnValue('running')
render(
<MemoryRouter>
<LinkedServersNav variant="sheet" />
</MemoryRouter>,
)
expect(screen.getByRole('img', { name: 'Sessions running' })).toBeInTheDocument()
})
})
@@ -1,6 +1,9 @@
import { Link, useLocation } from 'react-router-dom'
import { Server } from 'lucide-react'
import type { OpenCodeServer } from '@opencode-manager/shared/schemas'
import { useOpenCodeServers, useOpenCodeServerStatuses } from '@/hooks/useOpenCodeServers'
import { useServerActivityState } from '@/hooks/useActiveWork'
import { ActivityStateIndicator } from '@/components/activity/ActivityStateIndicator'
import { SidebarSection } from '@/components/ui/sidebar'
import { getServerPath } from '@/lib/navigation'
import { cn } from '@/lib/utils'
@@ -31,6 +34,52 @@ function ServerConnectionDot({ connected }: { connected: boolean }) {
)
}
interface LinkedServerRowProps {
server: OpenCodeServer
variant: 'sidebar' | 'sheet'
path: string
active: boolean
connected: boolean
onNavigate?: (path: string) => void
}
function LinkedServerRow({ server, variant, path, active, connected, onNavigate }: LinkedServerRowProps) {
const activity = useServerActivityState(server.id)
const className = cn(
'flex items-center gap-3 rounded-md p-2.5 text-sm transition-colors duration-150',
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
variant === 'sheet' && 'mx-2 p-2 text-left',
)
const content = (
<>
<Server className="h-5 w-5 shrink-0" />
<span className="min-w-0 flex-1 truncate">{server.name}</span>
<ActivityStateIndicator state={activity} />
<ServerConnectionDot connected={connected} />
</>
)
if (onNavigate) {
return (
<button
type="button"
onClick={() => onNavigate(path)}
aria-current={active ? 'page' : undefined}
className={className}
>
{content}
</button>
)
}
return (
<Link to={path} className={className}>
{content}
</Link>
)
}
export function LinkedServersNav({ variant = 'sidebar', onNavigate }: LinkedServersNavProps) {
const location = useLocation()
const { servers, isLoading } = useOpenCodeServers()
@@ -71,40 +120,17 @@ export function LinkedServersNav({ variant = 'sidebar', onNavigate }: LinkedServ
const rows = enabledServers.map((server) => {
const path = getServerPath(server.id)
const active = isActiveServerPath(location.pathname, path)
const connected = statusById[server.id]?.connected ?? false
const className = cn(
'flex items-center gap-3 rounded-md p-2.5 text-sm transition-colors duration-150',
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
variant === 'sheet' && 'mx-2 p-2 text-left',
)
const content = (
<>
<Server className="h-5 w-5 shrink-0" />
<span className="min-w-0 flex-1 truncate">{server.name}</span>
<ServerConnectionDot connected={connected} />
</>
)
if (onNavigate) {
return (
<button
key={server.id}
type="button"
onClick={() => onNavigate(path)}
aria-current={active ? 'page' : undefined}
className={className}
>
{content}
</button>
)
}
return (
<Link key={server.id} to={path} className={className}>
{content}
</Link>
<LinkedServerRow
key={server.id}
server={server}
variant={variant}
path={path}
active={isActiveServerPath(location.pathname, path)}
connected={statusById[server.id]?.connected ?? false}
onNavigate={onNavigate}
/>
)
})
@@ -416,14 +416,14 @@ describe('MoreDrawer', () => {
expect(screen.getByText('Settings')).toBeInTheDocument()
expect(screen.getByText('Logout')).toBeInTheDocument()
expect(screen.getByText('Terminal')).toBeInTheDocument()
expect(screen.getByRole('heading', { name: 'Activity' })).toBeInTheDocument()
expect(screen.getByText('Repos')).toBeInTheDocument()
expect(screen.queryByText('Files')).not.toBeInTheDocument()
expect(screen.queryByText('Source Control')).not.toBeInTheDocument()
expect(screen.getByText('Source Control')).toBeInTheDocument()
expect(screen.queryByText('Preview')).not.toBeInTheDocument()
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
expect(screen.queryByText('Reset Permissions')).not.toBeInTheDocument()
expect(screen.queryByText('Repos')).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Assistant' })).not.toBeInTheDocument()
expect(screen.queryByRole('heading', { name: 'Activity' })).not.toBeInTheDocument()
})
it('shows unread reports and marks them all read', () => {
@@ -14,7 +14,7 @@ import { useMarkAllScheduleRunsViewed, useUnreadScheduleRuns } from '@/hooks/use
import { buildMoreItems, buildNavModel, isManagerOnlyNavItem, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
import { useSwipeBack } from '@/hooks/useMobile'
import { cn, getRepoDisplayName } from '@/lib/utils'
import { getPathWithReturnTo, isAssistantPath } from '@/lib/navigation'
import { getPathWithReturnTo, isAssistantPath, parseServerSessionRoute } from '@/lib/navigation'
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
import { isLocalOpenCodeServer, useRouteOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
@@ -77,6 +77,7 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
const { logout } = useAuth()
const { data: health } = useServerHealth()
const isSessionDetail = isSessionDetailPath(location.pathname)
const isRemoteSessionDetail = parseServerSessionRoute(location.pathname) !== null
const isAssistantRoute = isAssistantPath(location.pathname)
const isAssistantSession = isSessionDetail && searchParams.get('assistant') === '1'
const isRemoteRoute = !isLocalOpenCodeServer(useRouteOpenCodeServerId())
@@ -205,11 +206,11 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
/>
</div>
)}
{isOpen && !isRemoteRoute && (
{isOpen && (
<CompactActivityList onNavigate={(path) => navigate(path)} />
)}
<MenuSection>
{isSessionDetail && !isRemoteRoute && (
{(isSessionDetail || isRemoteSessionDetail) && (
<MenuRow icon={FolderGit2} label="Repos" onClick={() => openMobileSheet('repos')} trailing />
)}
{assistantCta?.to && (
@@ -52,6 +52,7 @@ vi.mock('@/hooks/useActiveWork', () => ({
useActiveWork: activityMocks.useActiveWork,
useActivityWindowMinutes: activityMocks.useActivityWindowMinutes,
useRepoActivityState: () => null,
useServerActivityState: () => null,
}))
vi.mock('@/api/repos')
@@ -27,6 +27,11 @@ vi.mock('@/components/file-browser/FileBrowser', () => ({
vi.mock('@/components/source-control', () => ({
SourceControlContent: () => <div>source-control-tool</div>,
}))
vi.mock('@/components/source-control/RemoteSourceControlContent', () => ({
RemoteSourceControlContent: ({ serverId, directory }: { serverId: string; directory: string }) => (
<div>remote-source-control-tool {serverId} {directory}</div>
),
}))
vi.mock('@/components/terminal/TerminalPanel', () => ({
TerminalWorkspace: () => <div>terminal-tool</div>,
}))
@@ -360,12 +365,43 @@ describe('ToolSidePanel', () => {
within(rail)
.getAllByRole('button')
.map((button) => button.getAttribute('aria-label') ?? button.textContent?.trim()),
).toEqual(['Activity', 'MCP', 'Skills', 'Terminal'])
).toEqual(['Activity', 'MCP', 'Skills', 'Source Control', 'Terminal'])
await user.click(screen.getByRole('button', { name: 'MCP' }))
expect(await screen.findByText('mcp-tool')).toBeInTheDocument()
})
it('opens the remote source control panel for a linked-server session', async () => {
const user = userEvent.setup()
render(
<MemoryRouter initialEntries={['/servers/srv_kitchen/sessions/ses_remote']}>
<RemoteHarness />
</MemoryRouter>,
)
await user.click(screen.getByRole('button', { name: 'Source Control' }))
expect(
await screen.findByText('remote-source-control-tool srv_kitchen /home/me/app'),
).toBeInTheDocument()
expect(search().get('panel')).toBe('sourceControl')
expect(screen.queryByText('source-control-tool')).not.toBeInTheDocument()
})
it('opens the skills panel for a linked-server session', async () => {
const user = userEvent.setup()
render(
<MemoryRouter initialEntries={['/servers/srv_kitchen/sessions/ses_remote']}>
<RemoteHarness />
</MemoryRouter>,
)
await user.click(screen.getByRole('button', { name: 'Skills' }))
expect(await screen.findByText('skills-tool')).toBeInTheDocument()
expect(search().get('panel')).toBe('skills')
})
it('opens the Activity panel with rows and the window label when clicked', async () => {
const user = userEvent.setup()
setActivityGroups([createActivityItem('other', 'Other Session', 2, 'Beta')])
@@ -4,6 +4,7 @@ import { X } from 'lucide-react'
import { useLocation, useNavigate } from 'react-router-dom'
import { FileBrowser } from '@/components/file-browser/FileBrowser'
import { SourceControlContent } from '@/components/source-control'
import { RemoteSourceControlContent } from '@/components/source-control/RemoteSourceControlContent'
import { TerminalWorkspace } from '@/components/terminal/TerminalPanel'
import {
ChangesWalkthroughCancel,
@@ -38,7 +39,7 @@ const PANEL_WIDTH_CLASSES: Partial<Record<PanelTool, string>> = {
activity: 'w-80',
}
const REMOTE_TOOL_KEYS: ReadonlySet<string> = new Set(['activity', 'mcp', 'skills', 'terminal'])
const REMOTE_TOOL_KEYS: ReadonlySet<string> = new Set(['activity', 'mcp', 'skills', 'source-control', 'terminal'])
function ActivityWindowLabel() {
const minutes = useActivityWindowMinutes()
@@ -163,7 +164,8 @@ export function ToolSidePanel({
const { activeTool, toggleTool, closePanel } = panel
const location = useLocation()
const openNavItem = useOpenNavItem()
const isRemoteRoute = !isLocalOpenCodeServer(useRouteOpenCodeServerId())
const routeServerId = useRouteOpenCodeServerId()
const isRemoteRoute = !isLocalOpenCodeServer(routeServerId)
const railRef = useRef<HTMLElement>(null)
const previousActiveToolRef = useRef(activeTool)
@@ -212,25 +214,34 @@ export function ToolSidePanel({
? <TerminalWorkspace target={terminalWorkspaceTarget} directory={terminalDirectory ?? directory} isOpen />
: null
}
if (tool === 'skills') {
return sessionId ? (
<RepoSkillsContent
open
repoId={repoId}
sessionId={sessionId}
directory={repoDirectory}
onSkillLoaded={onSkillLoaded}
onDone={closePanel}
/>
) : (
<RepoSkillsContent open repoId={repoId} onDone={closePanel} />
)
}
if (tool === 'sourceControl') {
if (isRemoteRoute) {
return repoDirectory
? <RemoteSourceControlContent serverId={routeServerId} directory={repoDirectory} compact />
: null
}
return repoId === undefined
? null
: <SourceControlContent repoId={repoId} isOpen currentBranch={currentBranch} compact />
}
if (repoId === undefined) return null
switch (tool) {
case 'sourceControl':
return <SourceControlContent repoId={repoId} isOpen currentBranch={currentBranch} compact />
case 'actions':
return <RepoActionsContent repoId={repoId} directory={directory} open />
case 'skills':
return sessionId ? (
<RepoSkillsContent
open
repoId={repoId}
sessionId={sessionId}
directory={repoDirectory}
onSkillLoaded={onSkillLoaded}
onDone={closePanel}
/>
) : (
<RepoSkillsContent open repoId={repoId} onDone={closePanel} />
)
case 'schedules':
return <RepoSchedulesContent repoId={repoId} embedded />
}
@@ -64,7 +64,15 @@ describe('buildMoreItems', () => {
it('returns only the server tools a linked server can serve for /servers/:id/sessions/:sid', () => {
const items = buildMoreItems('/servers/srv_kitchen/sessions/abc')
expect(items.map((item) => item.key)).toEqual(['home', 'mcp', 'skills', 'terminal', 'settings', 'logout'])
expect(items.map((item) => item.key)).toEqual([
'home',
'mcp',
'skills',
'source-control',
'terminal',
'settings',
'logout',
])
})
it('omits the Actions item for an Assistant session', () => {
@@ -174,6 +182,7 @@ describe('buildToolItems', () => {
'activity',
'mcp',
'skills',
'source-control',
'terminal',
])
})
@@ -58,7 +58,6 @@ const NON_TOOL_ITEM_KEYS = new Set(['home', 'settings', 'logout'])
const MANAGER_ONLY_ITEM_KEYS: ReadonlySet<string> = new Set([
'files',
'source-control',
'preview',
'walkthrough',
'actions',
@@ -92,6 +91,7 @@ function buildRouteNavModel(pathname: string): NavModel {
items: [
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },
{ key: 'terminal', label: 'Terminal', icon: SquareTerminal, dialog: 'terminal' },
...baseItems,
],