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.

fix(sidebar): route the project-row switch through Canvas, not setActive

enes97a2f1abb227
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 27dc8739f..e1129a11c 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -8466,6 +8466,7 @@ export function Canvas() {
onReorder={reorderSession}
onRowContextMenu={onRowContextMenu}
onProjectContextMenu={onProjectContextMenu}
+ onSwitchProject={switchProject}
onAddToProject={addToProject}
onMouseEnter={openSessionsPeek}
onMouseLeave={closeSessionsPeekSoon}
diff --git a/src/renderer/components/SessionsSidebar.tsx b/src/renderer/components/SessionsSidebar.tsx
index bd552931f..b6e098220 100644
--- a/src/renderer/components/SessionsSidebar.tsx
+++ b/src/renderer/components/SessionsSidebar.tsx
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from 'react'
import {
buildSessionList,
isGroupCollapsed,
+ projectHeadClickAction,
projectSignalCounts,
type SessionNodeInput
} from '../lib/sessionList'
@@ -26,6 +27,11 @@ export interface SessionsSidebarProps {
onRowContextMenu(e: React.MouseEvent, projectId: string, id: string): void
/** Right-click on a project header: the project actions menu (switch/rename/folder/close). */
onProjectContextMenu(e: React.MouseEvent, projectId: string): void
+ /** Make a project active. MUST be Canvas's `switchProject`, never `useProjects.setActive`:
+ * a switch has to commit the live React Flow nodes back into the store and persist first,
+ * or the outgoing project's unsaved edits are dropped by the active-project reload and the
+ * new activeProjectId never reaches disk (the app reopens on the old project). */
+ onSwitchProject(projectId: string): void
onAddToProject(projectId: string): void
/** Move a node into a canvas group (groupId) or out to the top level (null). */
onMoveToGroup(projectId: string, nodeId: string, groupId: string | null): void
@@ -46,7 +52,6 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
// Closed projects are hidden from the tab bar; hide them from the sidebar too.
const projects = useMemo(() => allProjects.filter((p) => !p.closed), [allProjects])
const activeProjectId = useProjects((s) => s.activeProjectId)
- const setActiveProject = useProjects((s) => s.setActive)
const statusById = useAgentStatus((s) => s.byId)
const namingById = useSessionNaming((s) => s.byId)
// This sidebar's core api (a stable context read — the branch lookups run on the session's git).
@@ -276,9 +281,13 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
>
<div
className={`ss-group__head${dropClass(g.projectId, null)}`}
+ // One click, one action (projectHeadClickAction documents why it is never both):
+ // an inactive project switches — through Canvas, so the outgoing project's live
+ // nodes are committed and the new active id is persisted — and the active one
+ // toggles its own collapse, so the row keeps no dead zone.
onClick={() => {
- if (!g.isActive) setActiveProject(g.projectId)
- if (isCollapsed) toggleCollapse(g.projectId, isCollapsed)
+ if (projectHeadClickAction(g.isActive) === 'switch') props.onSwitchProject(g.projectId)
+ else toggleCollapse(g.projectId, isCollapsed)
}}
onContextMenu={(e) => props.onProjectContextMenu(e, g.projectId)}
title={drag?.projectId === g.projectId ? 'Drop here to remove from group' : undefined}
@@ -293,16 +302,22 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
}}
{...dropProps(g.projectId, null)}
>
- <span
+ {/* Collapse is now the chevron's job alone on an inactive row, so it has to be a
+ real target: a button with its own hit area and keyboard focus, not the bare
+ 9px glyph. It stops propagation so peeking into a project never switches. */}
+ <button
+ type="button"
className="ss-group__chev"
title={isCollapsed ? 'Expand' : 'Collapse'}
+ aria-label={isCollapsed ? `Expand ${g.projectName}` : `Collapse ${g.projectName}`}
+ aria-expanded={!isCollapsed}
onClick={(e) => {
e.stopPropagation()
toggleCollapse(g.projectId, isCollapsed)
}}
>
{isCollapsed ? '▶' : '▼'}
- </span>
+ </button>
<span className="ss-group__monogram" style={{ background: g.projectColor }}>
{(g.projectName.trim() || '?').charAt(0).toUpperCase()}
</span>
diff --git a/src/renderer/lib/sessionList.test.ts b/src/renderer/lib/sessionList.test.ts
index 92a0d467d..8d6e03346 100644
--- a/src/renderer/lib/sessionList.test.ts
+++ b/src/renderer/lib/sessionList.test.ts
@@ -3,6 +3,7 @@ import {
buildSessionList,
sessionStatusKind,
isGroupCollapsed,
+ projectHeadClickAction,
projectSignalCounts,
type ProjectInput
} from './sessionList'
@@ -49,6 +50,30 @@ describe('isGroupCollapsed', () => {
})
})
+describe('projectHeadClickAction', () => {
+ it('switches to an inactive project and toggles the active one (never both, never nothing)', () => {
+ expect(projectHeadClickAction(false)).toBe('switch')
+ // No dead zone: the active row still does what the whole header used to do.
+ expect(projectHeadClickAction(true)).toBe('toggle-collapse')
+ })
+
+ it('needs no collapse write on a switch: the target expands from the DEFAULT', () => {
+ // With autoCollapse ON the sidebar wipes every override on the activeProjectId change, so
+ // a toggle written by the click would be clobbered a tick later anyway — and is pointless,
+ // because the newly active project is expanded by the default rule.
+ expect(projectHeadClickAction(false)).toBe('switch')
+ expect(isGroupCollapsed({}, 'p2', true)).toBe(false)
+ })
+
+ it("with autoCollapse off, a switch leaves the target's explicit collapse choice alone", () => {
+ // Documented contract: "off = switches never touch the user's choices". The click writes no
+ // override, so a project the user collapsed by hand stays collapsed after switching to it.
+ const overrides = { p2: true }
+ expect(projectHeadClickAction(false)).toBe('switch')
+ expect(isGroupCollapsed(overrides, 'p2', true, false)).toBe(true)
+ })
+})
+
describe('buildSessionList', () => {
it('keeps store order (mirrors the tab bar) regardless of which project is active', () => {
const groups = buildSessionList(projects(), null, 'p2', {}, '')
diff --git a/src/renderer/lib/sessionList.ts b/src/renderer/lib/sessionList.ts
index 78f86b9e1..fb7f00b97 100644
--- a/src/renderer/lib/sessionList.ts
+++ b/src/renderer/lib/sessionList.ts
@@ -50,6 +50,30 @@ export function isGroupCollapsed(
return autoCollapse ? !isActive : false
}
+/** What a left-click on a project header in the sessions sidebar does. */
+export type ProjectHeadAction = 'switch' | 'toggle-collapse'
+
+/**
+ * A project header's click does exactly ONE of two things, and never both.
+ *
+ * - An INACTIVE project **switches** to that project and leaves `overrides` alone. Touching
+ * collapse here would be dead-or-wrong under both settings: with `sidebarAutoCollapse` ON
+ * the sidebar's own effect wipes every override on the `activeProjectId` change, so any
+ * toggle written here is clobbered a tick later (and unnecessary — the newly active project
+ * is expanded by default); with it OFF, writing one would discard the user's explicit
+ * choice, contradicting the documented "off = switches never touch the user's choices".
+ * - The ACTIVE project **toggles its own collapse** — the pre-existing behavior of the whole
+ * header, kept so the row has no dead zone. It sets a normal override, which is transient
+ * under auto-collapse (dropped at the next switch) and sticky without it, exactly like the
+ * chevron button.
+ *
+ * The chevron is the escape hatch either way: it toggles collapse on ANY row (it
+ * stops propagation), so an inactive project can be peeked into without switching.
+ */
+export function projectHeadClickAction(isActive: boolean): ProjectHeadAction {
+ return isActive ? 'toggle-collapse' : 'switch'
+}
+
/**
* Header badges for a project group: how many sessions need the user right now
* (waiting/blocked) and how many finished unseen. Mirrors the row glyph's precedence —
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 2db0dd6e6..79663bf01 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -6355,7 +6355,26 @@ body,
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
flex: 0 0 auto;
}
-.ss-group__chev { font-size: 9px; color: var(--muted); width: 10px; }
+/* The chevron is the ONLY collapse toggle on an inactive project row (the row itself switches),
+ so it is a real button with a clickable box around the 9px glyph, not the glyph alone. */
+.ss-group__chev {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex: 0 0 auto;
+ width: 18px;
+ height: 18px;
+ margin: -3px -2px -3px -3px;
+ padding: 0;
+ border: none;
+ border-radius: 4px;
+ background: transparent;
+ font-size: 9px;
+ line-height: 1;
+ color: var(--muted);
+ cursor: pointer;
+}
+.ss-group__chev:hover { background: rgba(var(--tint-rgb), 0.12); color: var(--text); }
.ss-group__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.ss-group__name { font-size: 12px; font-weight: 600; color: var(--text); }
.ss-group.is-active .ss-group__name { color: var(--accent); }