feat(servers): switch the sidebar listing between local and linked servers

The Servers section becomes a Local/server switcher shared by the desktop sidebar, collapsed rail and mobile repo sheet. Selecting a linked server lists its projects and sessions with the same navigation as local repos, and a remote project page mirrors the local repo page.
This commit is contained in:
Chris Scott committed 2026-10-19 10:16:32 -04:00
1 parent cb9b7645e6
commit 36b8c1b200
29 files changed
+2080 -201

No files matched your search

+11
View File
@@ -290,6 +290,17 @@ export function serverActivityFromIndex(
return running ? 'running' : null
}
/**
* A linked server project's activity from a prebuilt server index, keyed by server and directory.
*/
export function projectActivityFromIndex(
serverId: string,
directory: string,
index: ReadonlyMap<string, 'needs-input' | 'running'>,
): 'needs-input' | 'running' | null {
return index.get(serverIndexKey(serverId, directory)) ?? null
}
/**
* The repo's activity from a prebuilt index, checking each of its own paths and the directories of
* the worktrees it owns. Needs-input outranks running.
+29 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { getSessionListPath, getSwipeBackTarget, getAssistantPath, getAssistantSessionListPath, isAssistantPath, getPathWithReturnTo, getReturnToPath, getRepoPath, getServerPath, getServerSessionPath, getSessionPath, parseRepoRoute, parseServerSessionRoute } from './navigation';
import { getSessionListPath, getSwipeBackTarget, getAssistantPath, getAssistantSessionListPath, isAssistantPath, getPathWithReturnTo, getReturnToPath, getRepoPath, getServerPath, getServerProjectPath, getServerSessionPath, getSessionPath, parseRepoRoute, parseServerProjectRoute, parseServerSessionRoute } from './navigation';
describe('getAssistantPath', () => {
it('returns /assistant', () => {
@@ -141,6 +141,28 @@ describe('parseRepoRoute', () => {
});
});
describe('linked server project paths', () => {
it('builds a project path with encoded server id and directory', () => {
expect(getServerProjectPath('srv_kitchen', '/home/me/app')).toBe(
'/servers/srv_kitchen/projects?directory=%2Fhome%2Fme%2Fapp'
);
expect(getServerProjectPath('srv a/b', '/srv/my app')).toBe(
'/servers/srv%20a%2Fb/projects?directory=%2Fsrv%2Fmy%20app'
);
});
it('parses the server id and decoded directory from a project route', () => {
expect(
parseServerProjectRoute('/servers/srv_kitchen/projects', '?directory=%2Fhome%2Fme%2Fapp')
).toEqual({ serverId: 'srv_kitchen', directory: '/home/me/app' });
});
it('returns null without a directory or for other routes', () => {
expect(parseServerProjectRoute('/servers/srv_kitchen/projects', '')).toBeNull();
expect(parseServerProjectRoute('/servers/srv_kitchen', '?directory=%2Fhome%2Fme')).toBeNull();
});
});
describe('parseServerSessionRoute', () => {
it('parses a linked-server session route', () => {
expect(parseServerSessionRoute('/servers/srv_kitchen/sessions/ses_1')).toEqual({
@@ -217,6 +239,12 @@ describe('getSwipeBackTarget', () => {
it('returns root for a server page', () => {
expect(getSwipeBackTarget('/servers/srv_kitchen', '')).toBe('/');
});
it('returns the server page for a remote project page', () => {
expect(
getSwipeBackTarget('/servers/srv_kitchen/projects', '?directory=%2Fhome%2Fme%2Fapp')
).toBe('/servers/srv_kitchen');
});
});
describe('repo route', () => {
+20
View File
@@ -36,6 +36,21 @@ export function getServerSessionPath(serverId: string, sessionId: string): strin
return buildServerSessionPath(serverId, sessionId);
}
export function getServerProjectPath(serverId: string, directory: string): string {
return `/servers/${encodeURIComponent(serverId)}/projects?directory=${encodeURIComponent(directory)}`;
}
export function parseServerProjectRoute(
pathname: string,
search: string,
): { serverId: string; directory: string } | null {
const match = /^\/servers\/([^/]+)\/projects$/.exec(pathname);
if (!match) return null;
const directory = new URLSearchParams(search).get('directory');
if (!directory) return null;
return { serverId: decodeURIComponent(match[1]), directory };
}
export function parseServerSessionRoute(pathname: string): { serverId: string; sessionId: string } | null {
const match = /^\/servers\/([^/]+)\/sessions\/([^/]+)$/.exec(pathname);
if (!match) return null;
@@ -90,6 +105,11 @@ export function getReturnToPath(search: string, fallback: string): string {
}
export function getSwipeBackTarget(pathname: string, search = ''): string | null {
const serverProject = parseServerProjectRoute(pathname, search);
if (serverProject) {
return getServerPath(serverProject.serverId);
}
const serverSession = parseServerSessionRoute(pathname);
if (serverSession) {
return getServerPath(serverSession.serverId);