Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(session): runtime session dimension on tabs (no persisted change)

enesf6ccf4c42e38
diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsx
index 8765cbaee..8c471a54d 100644
--- a/src/renderer/components/TabBar.tsx
+++ b/src/renderer/components/TabBar.tsx
@@ -5,6 +5,7 @@ import { useAgentStatus } from '../state/agentStatus'
import { useSettings } from '../state/settings'
import { accountsForProject, systemAccountDisplay } from '../state/workspace'
import { useSystemAccount } from '../state/systemAccount'
+import { sessionCount, useProjectSession } from '../session/session'
import {
ALL_PERMISSION_MODES,
PERMISSION_MODE_LABELS,
@@ -27,6 +28,22 @@ interface TabBarProps {
onSetDefaultPermissionMode: (id: string, mode: AgentPermissionMode | undefined) => void
}
+/**
+ * The runtime session dimension of a tab (which core the project lives on). Rendered ONLY when
+ * more than one session exists — `sessionCount()` is 1 for a solo user today, so this never
+ * mounts and the solo tab bar is pixel-identical. Its own component because
+ * `useProjectSession` is a hook and the tabs render in a `.map()`. Nothing here is persisted:
+ * the project → session binding is resolved at runtime by `sessionForProject`.
+ */
+function TabSessionLabel({ projectId }: { projectId: string }) {
+ const session = useProjectSession(projectId)
+ return (
+ <span className="tab__session" title={`Session: ${session.label} (${session.status})`}>
+ {session.label}
+ </span>
+ )
+}
+
/**
* Top tab bar — one tab per project. Click to switch, "+" to add. The active tab
* exposes a caret menu (Rename / Set folder / Delete). The menu is rendered in a body
@@ -72,6 +89,12 @@ export function TabBar({
const systemEmail = useSystemAccount((s) => s.email)
const systemLabel = systemAccountDisplay(systemLabelSetting, systemEmail)
+ // Session labels appear only once a second session exists (4c: remote tabs). For a solo user
+ // this is always false, so the tab strip renders exactly as before. Plain call, not a
+ // subscription: sessions are registered at boot (and, in 4c, on connect — which re-renders
+ // through its own state), so no store is needed here.
+ const multiSession = sessionCount() > 1
+
const menuProject = projects.find((p) => p.id === menuId)
// Accounts eligible as the caret-menu project's default: local accounts for a local project, this
// host's accounts for an SSH project (pending logins always excluded).
@@ -196,6 +219,8 @@ export function TabBar({
<span className="tab__name">{p.name}</span>
)}
+ {multiSession && <TabSessionLabel projectId={p.id} />}
+
{unreadCount > 0 && (
<span className="tab__badge" title={`${unreadCount} unread`}>
{unreadCount}
diff --git a/src/renderer/session/session.test.ts b/src/renderer/session/session.test.ts
index 0f72401d0..72dc2c1ab 100644
--- a/src/renderer/session/session.test.ts
+++ b/src/renderer/session/session.test.ts
@@ -5,6 +5,8 @@ import {
getActiveSession,
setActiveSession,
activeSessionApi,
+ sessionForProject,
+ sessionCount,
resetSessionsForTest,
} from './session'
import type { NodeTerminalApi } from '@shared/types'
@@ -87,3 +89,20 @@ describe('createSession', () => {
expect(() => getSessionStores('nope')).toThrow()
})
})
+
+describe('sessionForProject (runtime tab → session resolver, never persisted)', () => {
+ it('sessionForProject returns the active (local) session for any project today', () => {
+ const s = createSession('local', fakeApi, 'This Mac')
+ setActiveSession(s.id)
+ expect(sessionForProject('any-project-id')).toBe(s)
+ expect(sessionCount()).toBe(1)
+ })
+
+ it('sessionCount counts registered sessions', () => {
+ expect(sessionCount()).toBe(0)
+ createSession('local', fakeApi, 'This Mac')
+ expect(sessionCount()).toBe(1)
+ createSession('relay', { marker: 'relay' } as unknown as NodeTerminalApi, "Ayşe's Mac")
+ expect(sessionCount()).toBe(2)
+ })
+})
diff --git a/src/renderer/session/session.ts b/src/renderer/session/session.ts
index 685c6e317..8f47b3441 100644
--- a/src/renderer/session/session.ts
+++ b/src/renderer/session/session.ts
@@ -91,6 +91,27 @@ export function activeSessionApi(): NodeTerminalApi {
return getActiveSession().api
}
+/** How many sessions are registered. `1` for a solo user today — UI affordances that only make
+ * sense with multiple cores (the tab session label) gate on `> 1` so the solo UI is unchanged. */
+export function sessionCount(): number {
+ return SESSIONS.size
+}
+
+/** Which session a project belongs to. Runtime-only — NEVER persisted (workspace.json /
+ * project.json are shared across machines; a session id is meaningless off this machine — see
+ * the toWorkspace tripwire in state/projects.test.ts). Today every project is on the local
+ * session; 4c returns the tab's bound session (local | relay | server). */
+export function sessionForProject(_projectId: string): WorkspaceSession {
+ return getActiveSession()
+}
+
+/** Hook wrapper over `sessionForProject` for components. Subscribes via `useSession()` so a
+ * provider change re-renders the consumer; the resolver itself is runtime, not persisted. */
+export function useProjectSession(projectId: string): WorkspaceSession {
+ useSession() // subscribe to provider changes; resolver is runtime, not persisted
+ return sessionForProject(projectId)
+}
+
export const SessionContext = createContext<WorkspaceSession | null>(null)
export function useSession(): WorkspaceSession {
diff --git a/src/renderer/state/projects.test.ts b/src/renderer/state/projects.test.ts
index fd3d4ed44..9b80c1075 100644
--- a/src/renderer/state/projects.test.ts
+++ b/src/renderer/state/projects.test.ts
@@ -44,6 +44,20 @@ describe('openFolderProject', () => {
})
})
+describe('toWorkspace', () => {
+ // Tripwire for Stage 4a: a project's session binding is RUNTIME-ONLY (resolved by
+ // src/renderer/session/session.ts `sessionForProject`). The persisted workspace shape must
+ // never gain a session field — workspace.json / project.json are shared across machines and a
+ // session id is meaningless anywhere but the machine that minted it. If this fails, someone
+ // started persisting the session dimension; that is a design change, not a bug fix.
+ it('toWorkspace does not persist any session dimension', () => {
+ useProjects.getState().addProject('my-app', '/Users/me/dev/my-app')
+ const ws = useProjects.getState().toWorkspace()
+ const json = JSON.stringify(ws)
+ expect(json).not.toMatch(/"session/i)
+ })
+})
+
describe('setDinoHighScore', () => {
it('raises the project record and never lowers it', () => {
const p = useProjects.getState().addProject('game', '/tmp/game')