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(sessions): show canvas groups in sidebar + drag a session in/out of a group

enes73df6ec0efe4
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 3339ed8a4..fedfc520b 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -106,6 +106,7 @@ import {
flowToNodeStates,
groupSelectedNodes,
nodeStatesToFlow,
+ reparentNode,
ungroupNodes,
type CanvasNode
} from '../state/workspace'
@@ -427,15 +428,19 @@ export function Canvas() {
const liveActiveNodes = useMemo<SessionNodeInput[]>(
() =>
nodes
- .filter((n) => (n.type ?? 'terminal') === 'terminal')
+ .filter((n) => {
+ const k = n.type ?? 'terminal'
+ return k === 'terminal' || k === 'group'
+ })
.map((n) => ({
id: n.id,
- kind: 'terminal' as const,
+ kind: (n.type ?? 'terminal') as SessionNodeInput['kind'],
title: n.data.title ?? n.id,
color: n.data.color ?? '#888',
agentId: n.data.agentId,
cwd: n.data.cwd,
- ssh: n.data.ssh
+ ssh: n.data.ssh,
+ parentId: n.parentId
})),
[nodes]
)
@@ -1872,6 +1877,20 @@ export function Canvas() {
[activeProjectId, addTerminal, switchProject]
)
+ // Sidebar drag-to-group: reparent a session into a canvas group (groupId) or out (null).
+ const moveSessionToGroup = useCallback(
+ (projectId: string, nodeId: string, groupId: string | null) => {
+ if (projectId === activeProjectId) {
+ setNodes((ns) => reparentNode(ns, nodeId, groupId))
+ markDirty()
+ } else {
+ useProjects.getState().moveNodeToGroup(projectId, nodeId, groupId)
+ void writeDisk()
+ }
+ },
+ [activeProjectId, setNodes, markDirty, writeDisk]
+ )
+
const onRowContextMenu = useCallback(
(e: React.MouseEvent, projectId: string, id: string) => {
e.preventDefault()
@@ -2398,6 +2417,7 @@ export function Canvas() {
onCloseSession={closeSession}
onRenameSession={renameSession}
onAiNameSession={aiNameSession}
+ onMoveToGroup={moveSessionToGroup}
onRowContextMenu={onRowContextMenu}
onAddToProject={addToProject}
onMouseEnter={openSessionsPeek}
diff --git a/src/renderer/components/SessionRow.tsx b/src/renderer/components/SessionRow.tsx
index 6f26ffbe3..c59b46eef 100644
--- a/src/renderer/components/SessionRow.tsx
+++ b/src/renderer/components/SessionRow.tsx
@@ -10,6 +10,8 @@ export interface SessionRowProps {
onRename(title: string): void
onAiName(): void | Promise<void>
onContextMenu(e: React.MouseEvent): void
+ onDragStart(): void
+ onDragEnd(): void
}
function ctxColor(pct: number): string {
@@ -30,7 +32,9 @@ export function SessionRow({
onClose,
onRename,
onAiName,
- onContextMenu
+ onContextMenu,
+ onDragStart,
+ onDragEnd
}: SessionRowProps): JSX.Element {
const [editing, setEditing] = useState(false)
const [draft, setDraft] = useState(row.title)
@@ -52,7 +56,19 @@ export function SessionRow({
}
return (
- <div className="ss-row" onClick={onClick} onContextMenu={onContextMenu}>
+ <div
+ className="ss-row"
+ draggable={!editing}
+ onClick={onClick}
+ onContextMenu={onContextMenu}
+ onDragStart={(e) => {
+ e.dataTransfer.effectAllowed = 'move'
+ // Some browsers require data to be set for a drag to start.
+ e.dataTransfer.setData('text/plain', row.id)
+ onDragStart()
+ }}
+ onDragEnd={onDragEnd}
+ >
<span className={`ss-dot ss-dot--${row.statusKind}`} title={row.stateLabel} />
<div className="ss-row__body">
<div className="ss-row__titleline">
diff --git a/src/renderer/components/SessionsSidebar.tsx b/src/renderer/components/SessionsSidebar.tsx
index 786aa596d..049bcbbe1 100644
--- a/src/renderer/components/SessionsSidebar.tsx
+++ b/src/renderer/components/SessionsSidebar.tsx
@@ -38,6 +38,8 @@ export interface SessionsSidebarProps {
onAiNameSession(projectId: string, id: string, cwd?: string): void | Promise<void>
onRowContextMenu(e: React.MouseEvent, projectId: string, id: 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
onMouseEnter?(): void
onMouseLeave?(): void
}
@@ -51,6 +53,9 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
const [filter, setFilter] = useState('')
const [overrides, setOverrides] = useState<Record<string, boolean>>(loadOverrides)
const [branches, setBranches] = useState<Record<string, string>>({})
+ // Drag-to-group: the session being dragged, and the current drop target for highlighting.
+ const [drag, setDrag] = useState<{ projectId: string; nodeId: string } | null>(null)
+ const [dropKey, setDropKey] = useState<string | null>(null)
// Look up the current git branch for each project cwd (best-effort, cached).
useEffect(() => {
@@ -76,7 +81,9 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
[projects, liveActiveNodes, activeProjectId, statusById, filter]
)
- const total = groups.reduce((n, g) => n + g.sessions.length, 0)
+ const projectCount = (g: (typeof groups)[number]): number =>
+ g.groups.reduce((n, b) => n + b.sessions.length, 0) + g.ungrouped.length
+ const total = groups.reduce((n, g) => n + projectCount(g), 0)
const toggleCollapse = (id: string, currentlyCollapsed: boolean): void => {
setOverrides((prev) => {
@@ -90,6 +97,49 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
})
}
+ // Drop-target wiring shared by the project header (ungroup) and group sub-headers (add).
+ // Only reacts while dragging a session that belongs to the same project.
+ const dropTargetKey = (projectId: string, groupId: string | null): string =>
+ `${projectId}:${groupId ?? 'ungrouped'}`
+ const dropProps = (projectId: string, groupId: string | null): React.HTMLAttributes<HTMLDivElement> => {
+ const key = dropTargetKey(projectId, groupId)
+ const active = !!drag && drag.projectId === projectId
+ return {
+ onDragOver: (e) => {
+ if (!active) return
+ e.preventDefault()
+ if (dropKey !== key) setDropKey(key)
+ },
+ onDragLeave: () => setDropKey((k) => (k === key ? null : k)),
+ onDrop: (e) => {
+ if (!drag || drag.projectId !== projectId) return
+ e.preventDefault()
+ props.onMoveToGroup(projectId, drag.nodeId, groupId)
+ setDrag(null)
+ setDropKey(null)
+ }
+ }
+ }
+ const dropClass = (projectId: string, groupId: string | null): string =>
+ dropKey === dropTargetKey(projectId, groupId) ? ' is-drop-target' : ''
+
+ const renderRow = (projectId: string, row: (typeof groups)[number]['ungrouped'][number]): JSX.Element => (
+ <SessionRow
+ key={row.id}
+ row={row}
+ onClick={() => props.onFocusNode(row.id)}
+ onClose={() => props.onCloseSession(projectId, row.id)}
+ onRename={(title) => props.onRenameSession(projectId, row.id, title)}
+ onAiName={() => props.onAiNameSession(projectId, row.id, row.cwd)}
+ onContextMenu={(e) => props.onRowContextMenu(e, projectId, row.id)}
+ onDragStart={() => setDrag({ projectId, nodeId: row.id })}
+ onDragEnd={() => {
+ setDrag(null)
+ setDropKey(null)
+ }}
+ />
+ )
+
if (!open) return null
return (
@@ -129,14 +179,19 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
const isCollapsed = isGroupCollapsed(overrides, g.projectId, g.isActive)
return (
<div key={g.projectId} className={`ss-group${g.isActive ? ' is-active' : ''}`}>
- <div className="ss-group__head" onClick={() => toggleCollapse(g.projectId, isCollapsed)}>
+ <div
+ className={`ss-group__head${dropClass(g.projectId, null)}`}
+ onClick={() => toggleCollapse(g.projectId, isCollapsed)}
+ title={drag?.projectId === g.projectId ? 'Drop here to remove from group' : undefined}
+ {...dropProps(g.projectId, null)}
+ >
<span className="ss-group__chev">{isCollapsed ? '▶' : '▼'}</span>
<span className="ss-group__dot" style={{ background: g.projectColor }} />
<span className="ss-group__name">{g.projectName}</span>
{branches[g.projectId] && (
<span className="ss-group__branch">⎇ {branches[g.projectId]}</span>
)}
- <span className="ss-group__count">{g.sessions.length}</span>
+ <span className="ss-group__count">{projectCount(g)}</span>
<button
className="ss-group__add"
title="New terminal in this project"
@@ -148,22 +203,40 @@ export function SessionsSidebar(props: SessionsSidebarProps): JSX.Element | null
+
</button>
</div>
- {!isCollapsed &&
- (g.sessions.length === 0 ? (
- <div className="ss-group__empty">No sessions</div>
- ) : (
- g.sessions.map((row) => (
- <SessionRow
- key={row.id}
- row={row}
- onClick={() => props.onFocusNode(row.id)}
- onClose={() => props.onCloseSession(g.projectId, row.id)}
- onRename={(title) => props.onRenameSession(g.projectId, row.id, title)}
- onAiName={() => props.onAiNameSession(g.projectId, row.id, row.cwd)}
- onContextMenu={(e) => props.onRowContextMenu(e, g.projectId, row.id)}
- />
- ))
- ))}
+ {!isCollapsed && (
+ <>
+ {g.groups.map((bucket) => (
+ <div key={bucket.id} className="ss-subgroup">
+ <div
+ className={`ss-subgroup__head${dropClass(g.projectId, bucket.id)}`}
+ {...dropProps(g.projectId, bucket.id)}
+ >
+ <span className="ss-subgroup__dot" style={{ background: bucket.color }} />
+ <span className="ss-subgroup__name">{bucket.title}</span>
+ <span className="ss-group__count">{bucket.sessions.length}</span>
+ </div>
+ {bucket.sessions.length === 0 ? (
+ <div className="ss-group__empty">Drop a session here</div>
+ ) : (
+ bucket.sessions.map((row) => renderRow(g.projectId, row))
+ )}
+ </div>
+ ))}
+ {g.ungrouped.length === 0 && g.groups.length === 0 ? (
+ <div className="ss-group__empty">No sessions</div>
+ ) : (
+ <div
+ className={`ss-ungrouped${dropClass(g.projectId, null)}`}
+ {...dropProps(g.projectId, null)}
+ >
+ {g.groups.length > 0 && g.ungrouped.length > 0 && (
+ <div className="ss-ungrouped__label">Ungrouped</div>
+ )}
+ {g.ungrouped.map((row) => renderRow(g.projectId, row))}
+ </div>
+ )}
+ </>
+ )}
</div>
)
})}
diff --git a/src/renderer/lib/sessionList.test.ts b/src/renderer/lib/sessionList.test.ts
index 6aec1d55e..06cd46ab6 100644
--- a/src/renderer/lib/sessionList.test.ts
+++ b/src/renderer/lib/sessionList.test.ts
@@ -47,10 +47,10 @@ describe('buildSessionList', () => {
it('keeps only terminal/agent nodes and flags agents', () => {
const groups = buildSessionList(projects(), null, 'p1', {}, '')
const p2 = groups.find((g) => g.projectId === 'p2')!
- expect(p2.sessions.map((s) => s.id)).toEqual(['t2']) // sticky + editor dropped
+ expect(p2.ungrouped.map((s) => s.id)).toEqual(['t2']) // sticky + editor dropped
const p1 = groups.find((g) => g.projectId === 'p1')!
- expect(p1.sessions.find((s) => s.id === 'a1')!.isAgent).toBe(true)
- expect(p1.sessions.find((s) => s.id === 't1')!.isAgent).toBe(false)
+ expect(p1.ungrouped.find((s) => s.id === 'a1')!.isAgent).toBe(true)
+ expect(p1.ungrouped.find((s) => s.id === 't1')!.isAgent).toBe(false)
})
it('attaches status and unread from the status map', () => {
@@ -58,7 +58,7 @@ describe('buildSessionList', () => {
a1: { unread: true, state: 'working', agentId: 'claude', session: 'fix bug', sessionId: 'sess-1' }
}
const groups = buildSessionList(projects(), null, 'p1', status, '')
- const a1 = groups[0].sessions.find((s) => s.id === 'a1')!
+ const a1 = groups[0].ungrouped.find((s) => s.id === 'a1')!
expect(a1.statusKind).toBe('working')
expect(a1.unread).toBe(true)
expect(a1.session).toBe('fix bug')
@@ -70,16 +70,59 @@ describe('buildSessionList', () => {
const live = [node('t1', { title: 'renamed live' })]
const groups = buildSessionList(projects(), live, 'p1', {}, '')
const p1 = groups.find((g) => g.projectId === 'p1')!
- expect(p1.sessions.map((s) => s.title)).toEqual(['renamed live'])
+ expect(p1.ungrouped.map((s) => s.title)).toEqual(['renamed live'])
})
- it('filters by title and session name, hiding empty groups only when filtering', () => {
+ it('nests sessions under their canvas group and separates ungrouped ones', () => {
+ const proj: ProjectInput[] = [
+ {
+ id: 'p1',
+ name: 'Alpha',
+ color: '#111',
+ nodes: [
+ node('g1', { kind: 'group', title: 'Frontend', color: '#abc' }),
+ node('t1', { parentId: 'g1' }),
+ node('t2', { parentId: 'g1' }),
+ node('t3'), // ungrouped
+ node('t4', { parentId: 'missing' }) // dangling parent → ungrouped
+ ]
+ }
+ ]
+ const [p1] = buildSessionList(proj, null, 'p1', {}, '')
+ expect(p1.groups).toHaveLength(1)
+ expect(p1.groups[0]).toMatchObject({ id: 'g1', title: 'Frontend', color: '#abc' })
+ expect(p1.groups[0].sessions.map((s) => s.id)).toEqual(['t1', 't2'])
+ expect(p1.ungrouped.map((s) => s.id)).toEqual(['t3', 't4'])
+ })
+
+ it('keeps empty groups without a filter and hides them when filtering', () => {
+ const proj: ProjectInput[] = [
+ {
+ id: 'p1',
+ name: 'Alpha',
+ color: '#111',
+ nodes: [
+ node('g1', { kind: 'group', title: 'Empty', color: '#abc' }),
+ node('g2', { kind: 'group', title: 'Has match', color: '#def' }),
+ node('t1', { title: 'special', parentId: 'g2' })
+ ]
+ }
+ ]
+ const unfiltered = buildSessionList(proj, null, 'p1', {}, '')
+ expect(unfiltered[0].groups.map((b) => b.id)).toEqual(['g1', 'g2']) // empty g1 kept
+
+ const filtered = buildSessionList(proj, null, 'p1', {}, 'spec')
+ expect(filtered[0].groups.map((b) => b.id)).toEqual(['g2']) // empty g1 dropped
+ expect(filtered[0].groups[0].sessions.map((s) => s.id)).toEqual(['t1'])
+ })
+
+ it('filters by title and session name, hiding empty projects only when filtering', () => {
const status: Record<string, AgentNodeStatus> = { a1: { unread: false, session: 'special' } }
const filtered = buildSessionList(projects(), null, 'p1', status, 'spec')
expect(filtered.map((g) => g.projectId)).toEqual(['p1'])
- expect(filtered[0].sessions.map((s) => s.id)).toEqual(['a1'])
+ expect(filtered[0].ungrouped.map((s) => s.id)).toEqual(['a1'])
const unfiltered = buildSessionList(projects(), null, 'p1', {}, '')
- expect(unfiltered.length).toBe(2) // empty groups kept when no filter
+ expect(unfiltered.length).toBe(2) // both projects kept when no filter
})
})
diff --git a/src/renderer/lib/sessionList.ts b/src/renderer/lib/sessionList.ts
index 5dc367b3b..9c030f9b3 100644
--- a/src/renderer/lib/sessionList.ts
+++ b/src/renderer/lib/sessionList.ts
@@ -12,6 +12,8 @@ export interface SessionNodeInput {
agentId?: AgentId
cwd?: string
ssh?: SshConnection
+ /** Parent group node id when this node lives inside a canvas group frame. */
+ parentId?: string
}
export interface ProjectInput {
@@ -76,13 +78,24 @@ export interface SessionRowVM {
usesContext: boolean
}
+/** A canvas group frame and the sessions nested inside it. */
+export interface GroupBucket {
+ id: string
+ title: string
+ color: string
+ sessions: SessionRowVM[]
+}
+
export interface SessionGroup {
projectId: string
projectName: string
projectColor: string
cwd?: string
isActive: boolean
- sessions: SessionRowVM[]
+ /** Canvas group frames in this project, each with its member sessions. */
+ groups: GroupBucket[]
+ /** Sessions not inside any canvas group. */
+ ungrouped: SessionRowVM[]
}
function toRow(n: SessionNodeInput, status: AgentNodeStatus | undefined): SessionRowVM {
@@ -118,26 +131,45 @@ export function buildSessionList(
filter: string
): SessionGroup[] {
const needle = filter.trim().toLowerCase()
+ const keep = (r: SessionRowVM): boolean => !needle || matches(r, needle)
+
const groups: SessionGroup[] = projects.map((p) => {
const isActive = p.id === activeProjectId
const source = isActive && liveActiveNodes ? liveActiveNodes : p.nodes
- let sessions = source
- .filter((n) => n.kind === 'terminal')
+ const groupNodes = source.filter((n) => n.kind === 'group')
+ const groupIds = new Set(groupNodes.map((n) => n.id))
+ const terminals = source.filter((n) => n.kind === 'terminal')
+
+ const buckets: GroupBucket[] = groupNodes.map((gn) => ({
+ id: gn.id,
+ title: gn.title,
+ color: gn.color,
+ sessions: terminals
+ .filter((n) => n.parentId === gn.id)
+ .map((n) => toRow(n, statusById[n.id]))
+ .filter(keep)
+ }))
+
+ const ungrouped = terminals
+ .filter((n) => !n.parentId || !groupIds.has(n.parentId))
.map((n) => toRow(n, statusById[n.id]))
- if (needle) sessions = sessions.filter((r) => matches(r, needle))
+ .filter(keep)
+
return {
projectId: p.id,
projectName: p.name,
projectColor: p.color,
cwd: p.cwd,
isActive,
- sessions
+ // When filtering, hide groups whose sessions all filtered out; otherwise keep empty
+ // groups so they remain visible drop targets.
+ groups: needle ? buckets.filter((b) => b.sessions.length > 0) : buckets,
+ ungrouped
}
})
- const ordered = [
- ...groups.filter((g) => g.isActive),
- ...groups.filter((g) => !g.isActive)
- ]
- return needle ? ordered.filter((g) => g.sessions.length > 0) : ordered
+ const ordered = [...groups.filter((g) => g.isActive), ...groups.filter((g) => !g.isActive)]
+ return needle
+ ? ordered.filter((g) => g.groups.length > 0 || g.ungrouped.length > 0)
+ : ordered
}
diff --git a/src/renderer/state/projects.sessions.test.ts b/src/renderer/state/projects.sessions.test.ts
index 84af64e1c..52b9b20fe 100644
--- a/src/renderer/state/projects.sessions.test.ts
+++ b/src/renderer/state/projects.sessions.test.ts
@@ -45,3 +45,67 @@ describe('projects store node mutations', () => {
expect(nodes[1].position).not.toEqual(nodes[0].position)
})
})
+
+describe('moveNodeToGroup', () => {
+ const group = (id: string, x: number, y: number): CanvasNodeState => ({
+ id,
+ kind: 'group',
+ position: { x, y },
+ size: { width: 400, height: 300 },
+ title: id,
+ color: '#fff',
+ group: null
+ })
+ const at = (id: string, x: number, y: number, parentId?: string): CanvasNodeState => ({
+ ...mkNode(id),
+ position: { x, y },
+ ...(parentId ? { parentId } : {})
+ })
+
+ beforeEach(() => {
+ useProjects.setState({
+ projects: [
+ {
+ id: 'p1',
+ name: 'P1',
+ color: '#111',
+ viewport: { x: 0, y: 0, zoom: 1 },
+ nodes: [group('g1', 50, 50), at('n1', 200, 150)]
+ }
+ ],
+ activeProjectId: 'p1'
+ })
+ })
+
+ it('adds a node to a group with a group-relative position', () => {
+ useProjects.getState().moveNodeToGroup('p1', 'n1', 'g1')
+ const n1 = useProjects.getState().getProject('p1')!.nodes.find((n) => n.id === 'n1')!
+ expect(n1.parentId).toBe('g1')
+ expect(n1.position).toEqual({ x: 150, y: 100 })
+ })
+
+ it('removes a node from its group, restoring the absolute position', () => {
+ useProjects.setState({
+ projects: [
+ {
+ id: 'p1',
+ name: 'P1',
+ color: '#111',
+ viewport: { x: 0, y: 0, zoom: 1 },
+ nodes: [group('g1', 50, 50), at('n1', 10, 10, 'g1')]
+ }
+ ],
+ activeProjectId: 'p1'
+ })
+ useProjects.getState().moveNodeToGroup('p1', 'n1', null)
+ const n1 = useProjects.getState().getProject('p1')!.nodes.find((n) => n.id === 'n1')!
+ expect(n1.parentId).toBeUndefined()
+ expect(n1.position).toEqual({ x: 60, y: 60 })
+ })
+
+ it('is a no-op when the node is missing', () => {
+ const before = useProjects.getState().getProject('p1')!.nodes
+ useProjects.getState().moveNodeToGroup('p1', 'nope', 'g1')
+ expect(useProjects.getState().getProject('p1')!.nodes).toBe(before)
+ })
+})
diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.ts
index 53e69a262..4836ea34d 100644
--- a/src/renderer/state/projects.ts
+++ b/src/renderer/state/projects.ts
@@ -24,6 +24,9 @@ interface ProjectsState {
removeNode(projectId: string, nodeId: string): void
/** Duplicates a node within a project (fresh id, offset position). */
duplicateNode(projectId: string, nodeId: string): void
+ /** Moves a node into a group frame (groupId) or out to the top level (null), keeping its
+ * on-canvas position fixed by converting absolute/relative coordinates. */
+ moveNodeToGroup(projectId: string, nodeId: string, groupId: string | null): void
/** Removes a project; returns the id that should become active (never deletes the last one). */
deleteProject(id: string): string
@@ -121,6 +124,34 @@ export const useProjects = create<ProjectsState>((set, get) => ({
}))
},
+ moveNodeToGroup(projectId, nodeId, groupId) {
+ set((s) => ({
+ projects: mapProjectNodes(s.projects, projectId, (nodes) => {
+ const node = nodes.find((n) => n.id === nodeId)
+ if (!node || node.kind === 'group') return nodes
+ if ((node.parentId ?? null) === groupId) return nodes
+ const oldParent = node.parentId ? nodes.find((n) => n.id === node.parentId) : undefined
+ const abs = {
+ x: node.position.x + (oldParent?.position.x ?? 0),
+ y: node.position.y + (oldParent?.position.y ?? 0)
+ }
+ let next: CanvasNodeState
+ if (groupId === null) {
+ next = { ...node, parentId: undefined, position: abs }
+ } else {
+ const group = nodes.find((n) => n.id === groupId)
+ if (!group || group.kind !== 'group') return nodes
+ next = {
+ ...node,
+ parentId: group.id,
+ position: { x: abs.x - group.position.x, y: abs.y - group.position.y }
+ }
+ }
+ return nodes.map((n) => (n.id === nodeId ? next : n))
+ })
+ }))
+ },
+
deleteProject(id) {
const { projects, activeProjectId } = get()
const index = projects.findIndex((p) => p.id === id)
diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.ts
index 638038db1..3185a7146 100644
--- a/src/renderer/state/workspace.test.ts
+++ b/src/renderer/state/workspace.test.ts
@@ -1,7 +1,65 @@
import { describe, it, expect } from 'vitest'
-import { flowToNodeStates, nodeStatesToFlow } from './workspace'
+import { flowToNodeStates, nodeStatesToFlow, reparentNode } from './workspace'
import type { CanvasNode } from './workspace'
+const term = (id: string, pos: { x: number; y: number }, parentId?: string): CanvasNode =>
+ ({
+ id,
+ type: 'terminal',
+ position: pos,
+ width: 320,
+ height: 240,
+ data: { title: id, color: '#888', group: null },
+ ...(parentId ? { parentId, extent: 'parent' as const } : {})
+ }) as unknown as CanvasNode
+
+const grp = (id: string, pos: { x: number; y: number }): CanvasNode =>
+ ({
+ id,
+ type: 'group',
+ position: pos,
+ width: 400,
+ height: 300,
+ data: { title: id, color: '#fff', group: null }
+ }) as unknown as CanvasNode
+
+describe('reparentNode', () => {
+ it('adds a top-level node to a group with a group-relative position', () => {
+ const nodes = [term('t1', { x: 200, y: 150 }), grp('g1', { x: 50, y: 50 })]
+ const out = reparentNode(nodes, 't1', 'g1')
+ const t1 = out.find((n) => n.id === 't1')!
+ expect(t1.parentId).toBe('g1')
+ expect(t1.extent).toBe('parent')
+ expect(t1.position).toEqual({ x: 150, y: 100 })
+ })
+
+ it('removes a node from its group, restoring the absolute position', () => {
+ const nodes = [grp('g1', { x: 50, y: 50 }), term('t1', { x: 10, y: 10 }, 'g1')]
+ const out = reparentNode(nodes, 't1', null)
+ const t1 = out.find((n) => n.id === 't1')!
+ expect(t1.parentId).toBeUndefined()
+ expect(t1.extent).toBeUndefined()
+ expect(t1.position).toEqual({ x: 60, y: 60 })
+ })
+
+ it('orders group nodes before their children', () => {
+ const nodes = [term('t1', { x: 200, y: 150 }), grp('g1', { x: 50, y: 50 })]
+ const out = reparentNode(nodes, 't1', 'g1')
+ expect(out.findIndex((n) => n.id === 'g1')).toBeLessThan(out.findIndex((n) => n.id === 't1'))
+ })
+
+ it('is a no-op when the node is already in the target group', () => {
+ const nodes = [grp('g1', { x: 50, y: 50 }), term('t1', { x: 10, y: 10 }, 'g1')]
+ expect(reparentNode(nodes, 't1', 'g1')).toBe(nodes)
+ })
+
+ it('is a no-op when the node is missing or the target is not a group', () => {
+ const nodes = [grp('g1', { x: 50, y: 50 }), term('t1', { x: 10, y: 10 })]
+ expect(reparentNode(nodes, 'nope', 'g1')).toBe(nodes)
+ expect(reparentNode(nodes, 't1', 't1')).toBe(nodes) // target is a terminal, not a group
+ })
+})
+
describe('group worktree serialization', () => {
it('round-trips data.worktree on a group node', () => {
const group = {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 744b26b36..50e35e513 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -425,6 +425,46 @@ export function ungroupNodes(nodes: CanvasNode[], groupId: string): CanvasNode[]
)
}
+/**
+ * Moves a node into an existing group frame (`groupId` set) or out to the top level
+ * (`groupId` null), keeping its on-canvas position fixed by converting between absolute and
+ * group-relative coordinates (one level of nesting). Returns a new array with group nodes kept
+ * before their children (React Flow requires parents first). No-op when the node is missing or
+ * is itself a group, when it already has the requested parent, or when `groupId` is not a group.
+ */
+export function reparentNode(
+ nodes: CanvasNode[],
+ nodeId: string,
+ groupId: string | null
+): CanvasNode[] {
+ const node = nodes.find((n) => n.id === nodeId)
+ if (!node || node.type === 'group') return nodes
+ if ((node.parentId ?? null) === groupId) return nodes
+
+ const oldParent = node.parentId ? nodes.find((n) => n.id === node.parentId) : undefined
+ const abs = {
+ x: node.position.x + (oldParent?.position.x ?? 0),
+ y: node.position.y + (oldParent?.position.y ?? 0)
+ }
+
+ let updated: CanvasNode
+ if (groupId === null) {
+ updated = { ...node, parentId: undefined, extent: undefined, position: abs }
+ } else {
+ const group = nodes.find((n) => n.id === groupId)
+ if (!group || group.type !== 'group') return nodes
+ updated = {
+ ...node,
+ parentId: group.id,
+ extent: 'parent' as const,
+ position: { x: abs.x - group.position.x, y: abs.y - group.position.y }
+ }
+ }
+
+ const next = nodes.map((n) => (n.id === nodeId ? updated : n))
+ return [...next.filter((n) => n.type === 'group'), ...next.filter((n) => n.type !== 'group')]
+}
+
/** Converts persisted node states into live React Flow nodes (parents first). */
/**
* Apply a single canvas mutation to a list of node states (renderer mirror of
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index f7ab724bb..b5dddc8e1 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4015,6 +4015,18 @@ body,
.ss-group__add:hover { opacity: 1 !important; color: var(--accent); }
.ss-group__empty { padding: 4px 8px 6px 22px; font-size: 11px; color: rgba(180, 180, 185, 0.6); }
+/* Canvas-group sub-section inside a project */
+.ss-subgroup { margin: 2px 0 2px 10px; }
+.ss-subgroup__head { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; border: 1px solid transparent; }
+.ss-subgroup__dot { width: 7px; height: 7px; border-radius: 2px; flex: 0 0 auto; }
+.ss-subgroup__name { font-size: 11.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.ss-ungrouped { margin-top: 2px; border: 1px solid transparent; border-radius: 6px; }
+.ss-ungrouped__label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.04em; color: rgba(180, 180, 185, 0.6); padding: 4px 6px 2px 8px; }
+/* Drop-target highlight while dragging a session onto a group / project header */
+.is-drop-target { border-color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 14%, transparent); }
+.ss-row[draggable='true'] { cursor: grab; }
+.ss-row[draggable='true']:active { cursor: grabbing; }
+
.sessions-icon-cluster { position: absolute; top: 54px; left: 14px; z-index: 11; }
.sessions-icon-cluster button { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; background: rgba(40, 40, 42, 0.92); border: 1px solid var(--border); border-radius: 9px; color: var(--text); cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
.sessions-icon-cluster button:hover { background: var(--panel-header); }