mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(navigation): show Assistant sessions in the sidebar and repo switcher (#368)
This commit is contained in:
1 parent
a1b7f58aae
commit
e80016cc22
11 files changed
+69
-26
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
SessionNavStatus,
|
||||
} from '@/components/navigation/RepoSessionNav'
|
||||
import { getActiveRepoId, isCurrentSessionItem, isRepoReady } from '@/components/navigation/sidebar-session-tree'
|
||||
import { getRepoPath } from '@/lib/navigation'
|
||||
|
||||
function SessionSearchInput({
|
||||
hasActiveSearch,
|
||||
@@ -78,7 +79,7 @@ function SessionSearchResults({ repos, search }: { repos: Repo[]; search: string
|
||||
isWorktree={group.repo.isWorktree}
|
||||
isOpen
|
||||
isCurrent={group.repo.id === getActiveRepoId(location.pathname)}
|
||||
onOpenRepo={() => navigate(`/repos/${group.repo.id}`)}
|
||||
onOpenRepo={() => navigate(getRepoPath(group.repo.id))}
|
||||
actions={<NewSessionButton repo={group.repo} onOpenSession={navigate} />}
|
||||
>
|
||||
{group.items.map((item) => (
|
||||
@@ -121,7 +122,7 @@ export function DesktopSessionTree() {
|
||||
repos={repos}
|
||||
activeRepoId={getActiveRepoId(location.pathname)}
|
||||
isVisible
|
||||
onOpenRepo={(repoId) => navigate(`/repos/${repoId}`)}
|
||||
onOpenRepo={(repoId) => navigate(getRepoPath(repoId))}
|
||||
onSelectSession={navigate}
|
||||
renderActions={(repo) => <NewSessionButton repo={repo} onOpenSession={navigate} />}
|
||||
/>
|
||||
|
||||
@@ -243,7 +243,7 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('does not show assistant as a repo option', async () => {
|
||||
it('shows assistant as the first repo option', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: ASSISTANT_REPO_ID,
|
||||
@@ -276,7 +276,8 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByText('Assistant')).not.toBeInTheDocument()
|
||||
const repoNames = screen.getAllByText(/^(Assistant|repo1)$/).map((node) => node.textContent)
|
||||
expect(repoNames).toEqual(['Assistant', 'repo1'])
|
||||
})
|
||||
|
||||
it('navigates on repo click and closes sheet', async () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Plus } from 'lucide-react'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { getAssistantPath } from '@/lib/navigation'
|
||||
import { getAssistantPath, getRepoPath } from '@/lib/navigation'
|
||||
import { NewSessionButton, RepoSessionNavList, SearchClearButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { getActiveRepoId } from '@/components/navigation/sidebar-session-tree'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
@@ -58,7 +58,7 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
return
|
||||
}
|
||||
|
||||
navigateAndClose(`/repos/${id}`, { replace: true })
|
||||
navigateAndClose(getRepoPath(id), { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useForms, usePermissions } from '@/contexts/EventContext'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useSidebarRepoGroups } from '@/hooks/useSidebarRepoGroups'
|
||||
import { cn, formatShortRelativeTime, getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
|
||||
import { getSessionPath } from '@/lib/navigation'
|
||||
import { getRepoPath, getSessionPath } from '@/lib/navigation'
|
||||
import {
|
||||
isCurrentSessionItem,
|
||||
isRepoReady,
|
||||
@@ -200,7 +200,7 @@ function RepoSessionList({ repo, onSelectSession }: RepoSessionListProps) {
|
||||
/>
|
||||
))}
|
||||
{hasMore && (
|
||||
<SessionNavLink onClick={() => onSelectSession(`/repos/${repo.id}`)}>All sessions</SessionNavLink>
|
||||
<SessionNavLink onClick={() => onSelectSession(getRepoPath(repo.id))}>All sessions</SessionNavLink>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -44,10 +44,14 @@ describe('getActiveRepoId', () => {
|
||||
expect(getActiveRepoId('/repos/3/sessions/abc')).toBe(3)
|
||||
})
|
||||
|
||||
it('returns null outside a repo and on assistant routes', () => {
|
||||
it('returns null outside a repo', () => {
|
||||
expect(getActiveRepoId('/')).toBeNull()
|
||||
expect(getActiveRepoId('/assistant')).toBeNull()
|
||||
expect(getActiveRepoId('/repos/1/assistant')).toBeNull()
|
||||
})
|
||||
|
||||
it('returns the assistant repo id on assistant routes', () => {
|
||||
expect(getActiveRepoId('/assistant')).toBe(0)
|
||||
expect(getActiveRepoId('/repos/1/assistant')).toBe(0)
|
||||
expect(getActiveRepoId('/repos/0/sessions/abc')).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -76,14 +80,14 @@ describe('isRepoReady', () => {
|
||||
})
|
||||
|
||||
describe('selectNavigableRepos', () => {
|
||||
it('excludes the assistant repo but keeps repos that are not ready', () => {
|
||||
it('pins the assistant repo first and keeps repos that are not ready', () => {
|
||||
const repos = [
|
||||
createRepo({ id: 0, fullPath: '/assistant' }),
|
||||
createRepo({ id: 1, fullPath: '/repos/a' }),
|
||||
createRepo({ id: 1, fullPath: '/repos/a', lastAccessedAt: 20 }),
|
||||
createRepo({ id: 2, fullPath: '/repos/b', cloneStatus: 'cloning' }),
|
||||
createRepo({ id: 0, fullPath: '/assistant', lastAccessedAt: 10 }),
|
||||
]
|
||||
|
||||
expect(selectNavigableRepos(repos).map((repo) => repo.id)).toEqual([1, 2])
|
||||
expect(selectNavigableRepos(repos).map((repo) => repo.id)).toEqual([0, 1, 2])
|
||||
})
|
||||
|
||||
it('sorts by last access, newest first, with never-accessed repos last', () => {
|
||||
@@ -173,6 +177,17 @@ describe('buildSidebarRepoGroups', () => {
|
||||
expect(item.path).toBe('/repos/3/sessions/w1')
|
||||
})
|
||||
|
||||
it('labels assistant sessions and links them in assistant mode', () => {
|
||||
const assistant = createRepo({ id: 0, fullPath: '/assistant', localPath: 'assistant' })
|
||||
const sessions = [createSession('s1', atStartOfDay(1000), '/assistant')]
|
||||
|
||||
const [group] = buildSidebarRepoGroups({ repos: [assistant], sessions, pinnedKeys: new Set(), now: NOW })
|
||||
|
||||
expect(group.label).toBe('Assistant')
|
||||
expect(group.items[0].path).toBe('/repos/0/sessions/s1?assistant=1')
|
||||
expect(isCurrentSessionItem(group.items[0], '/repos/0/sessions/s1')).toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to repo.branch when currentBranch is absent', () => {
|
||||
const repo = createRepo({ id: 4, fullPath: '/repos/d', branch: 'main' })
|
||||
const sessions = [createSession('d1', atStartOfDay(1000), '/repos/d')]
|
||||
|
||||
@@ -31,7 +31,7 @@ export function isCurrentSessionItem(item: SidebarSessionItem, pathname: string)
|
||||
}
|
||||
|
||||
export function getActiveRepoId(pathname: string): number | null {
|
||||
if (isAssistantPath(pathname)) return null
|
||||
if (isAssistantPath(pathname)) return ASSISTANT_REPO_ID
|
||||
return parseRepoRoute(pathname).repoId
|
||||
}
|
||||
|
||||
@@ -40,9 +40,10 @@ export function isRepoReady(repo: Repo): boolean {
|
||||
}
|
||||
|
||||
export function selectNavigableRepos(repos: Repo[]): Repo[] {
|
||||
return repos
|
||||
.filter((repo) => repo.id !== ASSISTANT_REPO_ID)
|
||||
.sort((a, b) => (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0))
|
||||
const isAssistant = (repo: Repo) => Number(repo.id === ASSISTANT_REPO_ID)
|
||||
return [...repos].sort(
|
||||
(a, b) => isAssistant(b) - isAssistant(a) || (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0),
|
||||
)
|
||||
}
|
||||
|
||||
export function buildSidebarRepoGroups(input: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { getSessionListPath, getSwipeBackTarget, getAssistantPath, getAssistantSessionListPath, isAssistantPath, getPathWithReturnTo, getReturnToPath, getSessionPath, parseRepoRoute } from './navigation';
|
||||
import { getSessionListPath, getSwipeBackTarget, getAssistantPath, getAssistantSessionListPath, isAssistantPath, getPathWithReturnTo, getReturnToPath, getRepoPath, getSessionPath, parseRepoRoute } from './navigation';
|
||||
|
||||
describe('getAssistantPath', () => {
|
||||
it('returns /assistant', () => {
|
||||
@@ -65,6 +65,18 @@ describe('getSessionPath', () => {
|
||||
expect(getSessionPath(5, 'ses_1')).toBe('/repos/5/sessions/ses_1');
|
||||
expect(getSessionPath('5', 'ses_1')).toBe('/repos/5/sessions/ses_1');
|
||||
});
|
||||
|
||||
it('marks assistant repo sessions with the assistant param', () => {
|
||||
expect(getSessionPath(0, 'ses_1')).toBe('/repos/0/sessions/ses_1?assistant=1');
|
||||
expect(getSessionPath('0', 'ses_1')).toBe('/repos/0/sessions/ses_1?assistant=1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRepoPath', () => {
|
||||
it('routes the assistant repo to the assistant page and others to their repo page', () => {
|
||||
expect(getRepoPath(0)).toBe('/assistant');
|
||||
expect(getRepoPath(5)).toBe('/repos/5');
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseRepoRoute', () => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils';
|
||||
|
||||
export function getAssistantPath(): string {
|
||||
return '/assistant';
|
||||
}
|
||||
@@ -10,8 +12,17 @@ export function isAssistantPath(pathname: string): boolean {
|
||||
return pathname === '/assistant' || /^\/repos\/[^/]+\/assistant$/.test(pathname);
|
||||
}
|
||||
|
||||
function isAssistantRepo(repoId: number | string): boolean {
|
||||
return String(repoId) === String(ASSISTANT_REPO_ID);
|
||||
}
|
||||
|
||||
export function getRepoPath(repoId: number | string): string {
|
||||
return isAssistantRepo(repoId) ? getAssistantPath() : `/repos/${repoId}`;
|
||||
}
|
||||
|
||||
export function getSessionPath(repoId: number | string, sessionId: string): string {
|
||||
return `/repos/${repoId}/sessions/${sessionId}`;
|
||||
const suffix = isAssistantRepo(repoId) ? '?assistant=1' : '';
|
||||
return `/repos/${repoId}/sessions/${sessionId}${suffix}`;
|
||||
}
|
||||
|
||||
export function parseRepoRoute(pathname: string): { repoId: number | null; section: string | null; sessionId: string | null } {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { useCreateSession } from "@/hooks/useOpenCode"
|
||||
import { useDialogParam } from "@/hooks/useDialogParam"
|
||||
import { useSidebarAction } from "@/hooks/useSidebarAction"
|
||||
import { useSSE } from "@/hooks/useSSE"
|
||||
import { getSessionPath } from "@/lib/navigation"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Header } from "@/components/ui/header"
|
||||
import { SessionList } from "@/components/session/SessionList"
|
||||
@@ -35,7 +36,7 @@ export function AssistantRedirect() {
|
||||
useSSE(assistantDirectory)
|
||||
|
||||
const createSessionMutation = useCreateSession(assistantDirectory, (session) => {
|
||||
navigate(`/repos/${repoId}/sessions/${session.id}?assistant=1`)
|
||||
navigate(getSessionPath(repoId, session.id))
|
||||
})
|
||||
|
||||
const handleCreateSession = async () => {
|
||||
@@ -72,7 +73,7 @@ export function AssistantRedirect() {
|
||||
) : (
|
||||
<SessionList
|
||||
directory={assistantDirectory}
|
||||
onSelectSession={(sessionId) => navigate(`/repos/${repoId}/sessions/${sessionId}?assistant=1`)}
|
||||
onSelectSession={(sessionId) => navigate(getSessionPath(repoId, sessionId))}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -20,8 +20,7 @@ import { useSidebarAction } from '@/hooks/useSidebarAction'
|
||||
|
||||
import type { ScheduleJobWithRepo, ScheduleRunWithContext } from '@/api/schedules'
|
||||
import { Combobox } from '@/components/ui/combobox'
|
||||
import { isAssistantRepoId } from '@/lib/schedules/schedule-target'
|
||||
import { getAssistantPath } from '@/lib/navigation'
|
||||
import { getRepoPath } from '@/lib/navigation'
|
||||
|
||||
type StatusFilter = 'all' | 'enabled' | 'disabled'
|
||||
type ScheduleModeFilter = 'all' | 'cron' | 'interval'
|
||||
@@ -284,7 +283,7 @@ export function GlobalSchedules() {
|
||||
const handleNavigateToRepo = (repoPath: string) => {
|
||||
const repoId = jobs.find((j) => j.repoPath === repoPath)?.repoId
|
||||
if (repoId === undefined) return
|
||||
navigate(isAssistantRepoId(repoId) ? getAssistantPath() : `/repos/${repoId}`)
|
||||
navigate(getRepoPath(repoId))
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
@@ -135,11 +135,13 @@ function getPathBaseName(filePath: string): string {
|
||||
}
|
||||
|
||||
export function getRepoDisplayName(repo: {
|
||||
id?: number
|
||||
name?: string | null
|
||||
repoUrl?: string | null
|
||||
localPath?: string | null
|
||||
sourcePath?: string | null
|
||||
}): string {
|
||||
if (repo.id === ASSISTANT_REPO_ID) return ASSISTANT_REPO_NAME
|
||||
if (repo.name && repo.name.trim()) return repo.name.trim()
|
||||
const fromLocalPath = repo.localPath ? getPathBaseName(repo.localPath) : ''
|
||||
if (repo.repoUrl) return getRepoNameFromUrl(repo.repoUrl) || fromLocalPath || 'Repository'
|
||||
|
||||
Reference in new issue
Block a user