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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(kanban): pure board transforms + tests
enesea3ab507d6b5
diff --git a/src/renderer/lib/kanban.test.ts b/src/renderer/lib/kanban.test.tsnew file mode 100644index 000000000..b7da27e22--- /dev/null+++ b/src/renderer/lib/kanban.test.ts@@ -0,0 +1,95 @@+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+} 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' }+ ],+ 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 }+ ]+})++describe('defaultKanban', () => {+ it('makes To Do / In Progress / Done with unique ids and no cards', () => {+ 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([])+ })+})++describe('columns', () => {+ it('addColumn appends with the given title/color; 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()))+ })+ it('renameColumn / recolorColumn touch only the target', () => {+ const k = recolorColumn(renameColumn(board(), 'b', 'WIP'), 'b', '#fff')+ expect(k.columns[1]).toMatchObject({ id: 'b', title: 'WIP', color: '#fff' })+ 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())+ })+ 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()+ expect(deleteColumn(board(), 'nope')).toEqual(board())+ })+})++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())+ })+ 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('deleteCard removes it', () => {+ expect(deleteCard(board(), 'c2').cards.map((c) => c.id)).toEqual(['c1', 'c3'])+ })+ 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('moveCard reorders within a column', () => {+ const k = moveCard(board(), 'c3', 'a', 'c1')+ expect(cardsInColumn(k, 'a').map((c) => c.id)).toEqual(['c3', 'c1'])+ })+ 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())+ })+})diff --git a/src/renderer/lib/kanban.ts b/src/renderer/lib/kanban.tsnew file mode 100644index 000000000..e88e0d186--- /dev/null+++ b/src/renderer/lib/kanban.ts@@ -0,0 +1,113 @@+import type { KanbanCard, 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.++const kid = (prefix: string): string => `${prefix}-${Math.random().toString(36).slice(2, 10)}`++/** Default board for a project whose file has no `kanban` yet. NOT written to disk+ * until the first user edit (the spec's lazy-default rule). */+export function defaultKanban(): ProjectKanban {+ return {+ columns: [+ { id: kid('kcol'), title: 'To Do', color: NODE_COLORS[0] },+ { id: kid('kcol'), title: 'In Progress', color: NODE_COLORS[2] },+ { id: kid('kcol'), title: 'Done', color: NODE_COLORS[1] }+ ],+ cards: []+ }+}++/** 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]+}++export function addColumn(k: ProjectKanban, title: string, color: string): ProjectKanban {+ return { ...k, columns: [...k.columns, { id: kid('kcol'), title, color }] }+}++export function renameColumn(k: ProjectKanban, columnId: string, title: string): ProjectKanban {+ return { ...k, columns: k.columns.map((c) => (c.id === columnId ? { ...c, title } : c)) }+}++export function recolorColumn(k: ProjectKanban, columnId: string, color: string): ProjectKanban {+ return { ...k, columns: k.columns.map((c) => (c.id === columnId ? { ...c, color } : c)) }+}++/** Moves a column before `beforeId` (null = to the end). */+export function moveColumn(k: ProjectKanban, columnId: string, beforeId: string | null): ProjectKanban {+ if (columnId === beforeId) return k+ const dragged = k.columns.find((c) => c.id === columnId)+ if (!dragged) return k+ const without = k.columns.filter((c) => c.id !== columnId)+ const idx = beforeId ? without.findIndex((c) => c.id === beforeId) : -1+ const at = idx === -1 ? without.length : idx+ 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 {+ 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))+ }+}++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 }] }+}++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+ })+ }+}++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(+ k: ProjectKanban,+ cardId: string,+ toColumnId: string,+ beforeCardId: 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)+ : 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)] }+}