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(kanban): session-assignment model replaces text cards (types, serialization, transforms)

enesf4eff7afd5c0
diff --git a/src/core/workspace-files.test.ts b/src/core/workspace-files.test.ts
index 63013ab04..15ed7844b 100644
--- a/src/core/workspace-files.test.ts
+++ b/src/core/workspace-files.test.ts
@@ -251,7 +251,7 @@ describe('kanban board persistence', () => {
{ id: 'kcol-a', title: 'To Do', color: '#0a84ff' },
{ id: 'kcol-b', title: 'Done', color: '#32d74b' }
],
- cards: [{ id: 'kcard-1', columnId: 'kcol-a', title: 'ship it', description: '**md**', createdAt: 1752800000000 }]
+ assignments: [{ nodeId: 'term-abc', columnId: 'kcol-a' }]
}
it('rides the project file round-trip', () => {
const f = projectToFile(project({ kanban: board }), 1, '2026-07-18T00:00:00.000Z')
@@ -271,11 +271,13 @@ describe('kanban board persistence', () => {
const { files } = splitWorkspace(ws, () => 1, '2026-01-01T00:00:00.000Z')
expect(files.get('/a/b')?.kanban).toEqual(board)
})
- it('a malformed kanban shape from a hand-edited file is dropped, not carried', () => {
+ it('a malformed or v1-shaped kanban from a hand-edited file is dropped, not carried', () => {
const f = projectToFile(project(), 1, '2026-07-18T00:00:00.000Z')
const evil1 = { ...f, kanban: {} } as unknown as ProjectFileV1
- const evil2 = { ...f, kanban: { columns: 42, cards: [] } } as unknown as ProjectFileV1
+ const evil2 = { ...f, kanban: { columns: 42, assignments: [] } } as unknown as ProjectFileV1
+ const v1shape = { ...f, kanban: { columns: [], cards: [] } } as unknown as ProjectFileV1
expect('kanban' in fileToProject(evil1, {})).toBe(false)
expect('kanban' in fileToProject(evil2, {})).toBe(false)
+ expect('kanban' in fileToProject(v1shape, {})).toBe(false)
})
})
diff --git a/src/core/workspace-files.ts b/src/core/workspace-files.ts
index b2d2b553b..9c11bbcc2 100644
--- a/src/core/workspace-files.ts
+++ b/src/core/workspace-files.ts
@@ -142,7 +142,7 @@ export function fileToProject(
...(f.defaultAccountId ? { defaultAccountId: f.defaultAccountId } : {}),
...(f.defaultPermissionMode ? { defaultPermissionMode: f.defaultPermissionMode } : {}),
...(f.dinoHighScore ? { dinoHighScore: f.dinoHighScore } : {}),
- ...(f.kanban && Array.isArray(f.kanban.columns) && Array.isArray(f.kanban.cards)
+ ...(f.kanban && Array.isArray(f.kanban.columns) && Array.isArray(f.kanban.assignments)
? { kanban: f.kanban }
: {}),
...(base.cwd ? { cwd: base.cwd } : {}),
diff --git a/src/renderer/lib/kanban.test.ts b/src/renderer/lib/kanban.test.ts
index b7da27e22..17ef18a1f 100644
--- a/src/renderer/lib/kanban.test.ts
+++ b/src/renderer/lib/kanban.test.ts
@@ -1,38 +1,36 @@
import { describe, it, expect } from 'vitest'
import type { ProjectKanban } from '@shared/types'
import {
- addCard, addColumn, cardsInColumn, defaultKanban, deleteCard, deleteColumn,
- moveCard, moveColumn, nextColumnColor, recolorColumn, renameColumn, updateCard
+ addColumn, assignNode, assignedTo, defaultKanban, deleteColumn, moveColumn,
+ nextColumnColor, pruneAssignments, recolorColumn, renameColumn, unassigned
} from './kanban'
const board = (): ProjectKanban => ({
columns: [
{ id: 'a', title: 'To Do', color: '#0a84ff' },
- { id: 'b', title: 'Doing', color: '#ffd60a' },
- { id: 'c', title: 'Done', color: '#32d74b' }
+ { id: 'b', title: 'Doing', color: '#ffd60a' }
],
- cards: [
- { id: 'c1', columnId: 'a', title: 'one', createdAt: 1 },
- { id: 'c2', columnId: 'b', title: 'two', createdAt: 2 },
- { id: 'c3', columnId: 'a', title: 'three', createdAt: 3 }
+ assignments: [
+ { nodeId: 'n1', columnId: 'a' },
+ { nodeId: 'n2', columnId: 'b' },
+ { nodeId: 'n3', columnId: 'a' }
]
})
describe('defaultKanban', () => {
- it('makes To Do / In Progress / Done with unique ids and no cards', () => {
+ it('makes To Do / In Progress / Done with unique ids and no assignments', () => {
const k = defaultKanban()
expect(k.columns.map((c) => c.title)).toEqual(['To Do', 'In Progress', 'Done'])
expect(new Set(k.columns.map((c) => c.id)).size).toBe(3)
- expect(k.cards).toEqual([])
+ expect(k.assignments).toEqual([])
})
})
describe('columns', () => {
- it('addColumn appends with the given title/color; nextColumnColor cycles the palette', () => {
+ it('addColumn appends; nextColumnColor cycles the palette', () => {
const k = addColumn(board(), 'Review', nextColumnColor(board()))
- expect(k.columns).toHaveLength(4)
- expect(k.columns[3].title).toBe('Review')
- expect(k.columns[3].color).toBe(nextColumnColor(board()))
+ expect(k.columns).toHaveLength(3)
+ expect(k.columns[2].title).toBe('Review')
})
it('renameColumn / recolorColumn touch only the target', () => {
const k = recolorColumn(renameColumn(board(), 'b', 'WIP'), 'b', '#fff')
@@ -40,56 +38,53 @@ describe('columns', () => {
expect(k.columns[0]).toEqual(board().columns[0])
})
it('moveColumn before a target and to the end (null)', () => {
- expect(moveColumn(board(), 'c', 'a').columns.map((c) => c.id)).toEqual(['c', 'a', 'b'])
- expect(moveColumn(board(), 'a', null).columns.map((c) => c.id)).toEqual(['b', 'c', 'a'])
- expect(moveColumn(board(), 'a', 'a')).toEqual(board())
+ expect(moveColumn(board(), 'b', 'a').columns.map((c) => c.id)).toEqual(['b', 'a'])
+ expect(moveColumn(board(), 'a', null).columns.map((c) => c.id)).toEqual(['b', 'a'])
})
- it('deleteColumn migrates cards to the first remaining column, keeps array order', () => {
- const k = deleteColumn(board(), 'a')!
- expect(k.columns.map((c) => c.id)).toEqual(['b', 'c'])
- expect(k.cards.map((c) => [c.id, c.columnId])).toEqual([['c1', 'b'], ['c2', 'b'], ['c3', 'b']])
- })
- it('deleteColumn refuses the last column (null); unknown id is a no-op', () => {
- const one: ProjectKanban = { columns: [{ id: 'x', title: 't', color: '#fff' }], cards: [] }
- expect(deleteColumn(one, 'x')).toBeNull()
+ it('deleteColumn drops the column AND its assignments (cards return to Ungrouped); unknown id no-op', () => {
+ const k = deleteColumn(board(), 'a')
+ expect(k.columns.map((c) => c.id)).toEqual(['b'])
+ expect(k.assignments).toEqual([{ nodeId: 'n2', columnId: 'b' }])
expect(deleteColumn(board(), 'nope')).toEqual(board())
})
+ it('deleting every user column is allowed (Ungrouped always remains)', () => {
+ const k = deleteColumn(deleteColumn(board(), 'a'), 'b')
+ expect(k.columns).toEqual([])
+ expect(k.assignments).toEqual([])
+ })
})
-describe('cards', () => {
- it('cardsInColumn returns that column in array order', () => {
- expect(cardsInColumn(board(), 'a').map((c) => c.id)).toEqual(['c1', 'c3'])
- })
- it('addCard appends to the end of the column; unknown column is a no-op', () => {
- const k = addCard(board(), 'a', 'four', 4)
- expect(cardsInColumn(k, 'a').map((c) => c.title)).toEqual(['one', 'three', 'four'])
- expect(k.cards[3].createdAt).toBe(4)
- expect(addCard(board(), 'nope', 'x', 1)).toEqual(board())
+describe('assignments', () => {
+ it('assignedTo returns a column in array order; unassigned follows sessionIds order', () => {
+ expect(assignedTo(board(), 'a')).toEqual(['n1', 'n3'])
+ expect(unassigned(board(), ['n4', 'n1', 'n5'])).toEqual(['n4', 'n5'])
})
- it('updateCard patches title/description and drops an emptied description', () => {
- const k = updateCard(board(), 'c1', { title: 'ONE', description: 'body' })
- expect(k.cards[0]).toMatchObject({ title: 'ONE', description: 'body' })
- const k2 = updateCard(k, 'c1', { description: undefined })
- expect('description' in k2.cards[0]).toBe(false)
+ it('a dangling assignment (missing column) counts as unassigned', () => {
+ const k: ProjectKanban = { ...board(), assignments: [{ nodeId: 'n1', columnId: 'gone' }] }
+ expect(unassigned(k, ['n1', 'n2'])).toEqual(['n1', 'n2'])
+ expect(assignedTo(k, 'a')).toEqual([])
})
- it('deleteCard removes it', () => {
- expect(deleteCard(board(), 'c2').cards.map((c) => c.id)).toEqual(['c1', 'c3'])
+ it('assignNode into a column at the end (null) and before a target', () => {
+ const atEnd = assignNode(board(), 'n9', 'b', null)
+ expect(assignedTo(atEnd, 'b')).toEqual(['n2', 'n9'])
+ const before = assignNode(board(), 'n2', 'a', 'n3')
+ expect(assignedTo(before, 'a')).toEqual(['n1', 'n2', 'n3'])
+ expect(assignedTo(before, 'b')).toEqual([])
})
- it('moveCard across columns to the end (null) and before a target card', () => {
- const toEnd = moveCard(board(), 'c1', 'b', null)
- expect(cardsInColumn(toEnd, 'b').map((c) => c.id)).toEqual(['c2', 'c1'])
- const before = moveCard(board(), 'c2', 'a', 'c3')
- expect(cardsInColumn(before, 'a').map((c) => c.id)).toEqual(['c1', 'c2', 'c3'])
- expect(cardsInColumn(before, 'b')).toEqual([])
+ it('assignNode with columnId null removes the assignment (back to Ungrouped)', () => {
+ const k = assignNode(board(), 'n1', null, null)
+ expect(k.assignments.map((a) => a.nodeId)).toEqual(['n2', 'n3'])
})
- it('moveCard reorders within a column', () => {
- const k = moveCard(board(), 'c3', 'a', 'c1')
- expect(cardsInColumn(k, 'a').map((c) => c.id)).toEqual(['c3', 'c1'])
+ it('assignNode: beforeNode in a different column ⇒ end; unknown column ⇒ no-op; self-before ⇒ no-op', () => {
+ const k = assignNode(board(), 'n1', 'b', 'n3')
+ expect(assignedTo(k, 'b')).toEqual(['n2', 'n1'])
+ expect(assignNode(board(), 'n1', 'nope', null)).toEqual(board())
+ expect(assignNode(board(), 'n1', 'a', 'n1')).toEqual(board())
})
- it('moveCard: beforeCard in a DIFFERENT column ⇒ lands at the end; unknown ids are no-ops', () => {
- const k = moveCard(board(), 'c1', 'b', 'c3') // c3 is in column a, target is b
- expect(cardsInColumn(k, 'b').map((c) => c.id)).toEqual(['c2', 'c1'])
- expect(moveCard(board(), 'nope', 'a', null)).toEqual(board())
- expect(moveCard(board(), 'c1', 'nope', null)).toEqual(board())
+ it('pruneAssignments drops dead nodes, returns the same object when nothing changes', () => {
+ const k = pruneAssignments(board(), ['n1', 'n3'])
+ expect(k.assignments.map((a) => a.nodeId)).toEqual(['n1', 'n3'])
+ const same = board()
+ expect(pruneAssignments(same, ['n1', 'n2', 'n3'])).toBe(same)
})
})
diff --git a/src/renderer/lib/kanban.ts b/src/renderer/lib/kanban.ts
index e88e0d186..f6c3fb253 100644
--- a/src/renderer/lib/kanban.ts
+++ b/src/renderer/lib/kanban.ts
@@ -1,9 +1,11 @@
-import type { KanbanCard, ProjectKanban } from '@shared/types'
+import type { KanbanAssignment, ProjectKanban } from '@shared/types'
import { NODE_COLORS } from '../state/workspace'
// Pure kanban board transforms — the ONLY place board structure changes. The UI computes
// the next board here and hands it whole to setProjectKanban (no second live source).
// Every function returns a new board; unknown ids are no-ops returning the input.
+// Cards are the project's SESSION NODES — the board stores only column assignments; a
+// session with no (or dangling) assignment sits in the virtual Ungrouped column.
const kid = (prefix: string): string => `${prefix}-${Math.random().toString(36).slice(2, 10)}`
@@ -16,15 +18,10 @@ export function defaultKanban(): ProjectKanban {
{ id: kid('kcol'), title: 'In Progress', color: NODE_COLORS[2] },
{ id: kid('kcol'), title: 'Done', color: NODE_COLORS[1] }
],
- cards: []
+ assignments: []
}
}
-/** A column's cards in board order (order = relative position in the cards array). */
-export function cardsInColumn(k: ProjectKanban, columnId: string): KanbanCard[] {
- return k.cards.filter((c) => c.columnId === columnId)
-}
-
/** Color for the next added column — cycles the node palette. */
export function nextColumnColor(k: ProjectKanban): string {
return NODE_COLORS[k.columns.length % NODE_COLORS.length]
@@ -53,61 +50,63 @@ export function moveColumn(k: ProjectKanban, columnId: string, beforeId: string
return { ...k, columns: [...without.slice(0, at), dragged, ...without.slice(at)] }
}
-/** Deletes a column, migrating its cards to the first remaining column. Returns null
- * when this is the last column — the board always keeps ≥ 1 column. */
-export function deleteColumn(k: ProjectKanban, columnId: string): ProjectKanban | null {
+/** Deletes a user column; its assigned sessions return to Ungrouped (assignments drop).
+ * Non-destructive by design — sessions are untouched, so no confirm dialog and no
+ * last-column rule (the virtual Ungrouped column always remains). */
+export function deleteColumn(k: ProjectKanban, columnId: string): ProjectKanban {
if (!k.columns.some((c) => c.id === columnId)) return k
- if (k.columns.length <= 1) return null
- const columns = k.columns.filter((c) => c.id !== columnId)
- const target = columns[0].id
return {
- columns,
- cards: k.cards.map((c) => (c.columnId === columnId ? { ...c, columnId: target } : c))
+ columns: k.columns.filter((c) => c.id !== columnId),
+ assignments: k.assignments.filter((a) => a.columnId !== columnId)
}
}
-export function addCard(k: ProjectKanban, columnId: string, title: string, createdAt: number): ProjectKanban {
- if (!k.columns.some((c) => c.id === columnId)) return k
- return { ...k, cards: [...k.cards, { id: kid('kcard'), columnId, title, createdAt }] }
+/** Node ids assigned to `columnId`, in board order. */
+export function assignedTo(k: ProjectKanban, columnId: string): string[] {
+ return k.assignments.filter((a) => a.columnId === columnId).map((a) => a.nodeId)
}
-export function updateCard(
- k: ProjectKanban,
- cardId: string,
- patch: { title?: string; description?: string }
-): ProjectKanban {
- return {
- ...k,
- cards: k.cards.map((c) => {
- if (c.id !== cardId) return c
- const next = { ...c, ...patch }
- if (!next.description) delete next.description // emptied body: drop the key, keep the file clean
- return next
- })
- }
+/** Ids from `sessionIds` with no live assignment — never assigned, or assigned to a column
+ * that no longer exists (e.g. a git merge kept the assignment but lost the column). Order
+ * follows `sessionIds` (= canvas order). */
+export function unassigned(k: ProjectKanban, sessionIds: string[]): string[] {
+ const cols = new Set(k.columns.map((c) => c.id))
+ const assigned = new Set(
+ k.assignments.filter((a) => cols.has(a.columnId)).map((a) => a.nodeId)
+ )
+ return sessionIds.filter((id) => !assigned.has(id))
}
-export function deleteCard(k: ProjectKanban, cardId: string): ProjectKanban {
- return { ...k, cards: k.cards.filter((c) => c.id !== cardId) }
-}
-
-/** Moves a card into `toColumnId`, before `beforeCardId` (null — or a card that is not
- * in the target column — = end of that column). */
-export function moveCard(
+/** Assigns/moves a session card. `columnId` null = back to Ungrouped (assignment removed;
+ * Ungrouped order is canvas order, so `beforeNodeId` is ignored there). Inserts before
+ * `beforeNodeId`'s assignment when that assignment is in the target column, else at the
+ * end. Unknown target column is a no-op. */
+export function assignNode(
k: ProjectKanban,
- cardId: string,
- toColumnId: string,
- beforeCardId: string | null
+ nodeId: string,
+ columnId: string | null,
+ beforeNodeId: string | null
): ProjectKanban {
- if (cardId === beforeCardId) return k
- const card = k.cards.find((c) => c.id === cardId)
- if (!card || !k.columns.some((c) => c.id === toColumnId)) return k
- const moved = { ...card, columnId: toColumnId }
- const without = k.cards.filter((c) => c.id !== cardId)
- const before = beforeCardId
- ? without.find((c) => c.id === beforeCardId && c.columnId === toColumnId)
+ if (nodeId === beforeNodeId) return k
+ if (columnId === null) {
+ if (!k.assignments.some((a) => a.nodeId === nodeId)) return k
+ return { ...k, assignments: k.assignments.filter((a) => a.nodeId !== nodeId) }
+ }
+ if (!k.columns.some((c) => c.id === columnId)) return k
+ const moved: KanbanAssignment = { nodeId, columnId }
+ const without = k.assignments.filter((a) => a.nodeId !== nodeId)
+ const before = beforeNodeId
+ ? without.find((a) => a.nodeId === beforeNodeId && a.columnId === columnId)
: undefined
const idx = before ? without.indexOf(before) : -1
const at = idx === -1 ? without.length : idx
- return { ...k, cards: [...without.slice(0, at), moved, ...without.slice(at)] }
+ return { ...k, assignments: [...without.slice(0, at), moved, ...without.slice(at)] }
+}
+
+/** Drops assignments of nodes that no longer exist. Returns the SAME object when nothing
+ * changed, so callers can cheaply skip a no-op persist. */
+export function pruneAssignments(k: ProjectKanban, liveIds: string[]): ProjectKanban {
+ const live = new Set(liveIds)
+ const assignments = k.assignments.filter((a) => live.has(a.nodeId))
+ return assignments.length === k.assignments.length ? k : { ...k, assignments }
}
diff --git a/src/renderer/state/projects.kanban.test.ts b/src/renderer/state/projects.kanban.test.ts
index 770766c80..462076acd 100644
--- a/src/renderer/state/projects.kanban.test.ts
+++ b/src/renderer/state/projects.kanban.test.ts
@@ -8,7 +8,7 @@ describe('setProjectKanban', () => {
activeProjectId: 'p1',
projects: [{ id: 'p1', name: 'x', color: '#fff', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [] }]
})
- const board = { columns: [{ id: 'c1', title: 'To Do', color: '#0a84ff' }], cards: [] }
+ const board = { columns: [{ id: 'c1', title: 'To Do', color: '#0a84ff' }], assignments: [] }
useProjects.getState().setProjectKanban('p1', board)
expect(useProjects.getState().getProject('p1')?.kanban).toEqual(board)
expect(useProjects.getState().toWorkspace().projects[0].kanban).toEqual(board)
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 1f7b9c671..3cf5d03ce 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -193,23 +193,21 @@ export interface KanbanColumn {
color: string
}
-/** One kanban card. Lives in exactly one column; order within a column is the relative
- * order of that column's cards in ProjectKanban.cards (no explicit order field). */
-export interface KanbanCard {
- id: string
+/** Assignment of one session node to a board column. A session with no assignment sits
+ * in the virtual Ungrouped column (never persisted). Order within a column = relative
+ * order in ProjectKanban.assignments. */
+export interface KanbanAssignment {
+ nodeId: string
columnId: string
- title: string
- /** Optional markdown body (rendered sanitized). */
- description?: string
- createdAt: number
}
/** Per-project kanban board (docs/superpowers/specs/2026-07-18-kanban-view-design.md).
* Absent = never edited: the renderer shows a default 3-column board and writes
- * nothing until the first change. */
+ * nothing until the first change. Cards are the project's session nodes — the board
+ * stores only their column assignments. */
export interface ProjectKanban {
columns: KanbanColumn[]
- cards: KanbanCard[]
+ assignments: KanbanAssignment[]
}
/** A project is one canvas/page: its own nodes, viewport, and default working dir. */