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(kanban): one unsafe-display set, column colour repair, tolerant label toggle, dead-card diff (D7, D12)

reviewb80b0fa6123f
diff --git a/src/renderer/lib/kanban.test.ts b/src/renderer/lib/kanban.test.ts
index 80fe94fc5..2c39b24c4 100644
--- a/src/renderer/lib/kanban.test.ts
+++ b/src/renderer/lib/kanban.test.ts
@@ -260,6 +260,15 @@ describe('board labels', () => {
expect(boardLabels(k)[1]).toMatchObject({ id: idB, name: 'B', color: 'green' })
})
+ // D7: a hand-edited file can carry a non-list `labels`; the toggle reads it as none instead of
+ // throwing (`.includes` of a string or an object) out of a click handler.
+ it('toggleCardLabel treats a non-list labels field as no labels', () => {
+ const k = { columns: [], assignments: [], meta: [{ nodeId: 'n1', labels: 'bug' as never, priority: 'high' as const }] }
+ expect(toggleCardLabel(k, 'n1', 'l1').meta).toEqual([{ nodeId: 'n1', priority: 'high', labels: ['l1'] }])
+ const obj = { columns: [], assignments: [], meta: [{ nodeId: 'n1', labels: { 0: 'x' } as never }] }
+ expect(toggleCardLabel(obj, 'n1', 'l1').meta).toEqual([{ nodeId: 'n1', labels: ['l1'] }])
+ })
+
it('toggleCardLabel adds then removes; labelsForCard resolves in palette order and drops dangling', () => {
let k = createLabel(board(), 'A', 'blue').k
const a = boardLabels(k)[0].id
diff --git a/src/shared/canvas-content.test.ts b/src/shared/canvas-content.test.ts
index 3411b28f4..be2e0b7f4 100644
--- a/src/shared/canvas-content.test.ts
+++ b/src/shared/canvas-content.test.ts
@@ -238,18 +238,44 @@ describe('diffContent', () => {
// outside edit that REMOVED the block (a checkout from before the board was first edited) turns
// every replica's board back into that default, instead of casting nothing and leaving each
// client's old board in place over a file that no longer has one.
- it('a removed board diffs to the lazy default', () => {
+ it('a removed board diffs to the lazy default: every item list, not only columns and cards', () => {
const prev: CanvasContent = {
nodes: [node('a')],
bridges: [],
ropes: [],
- kanban: { columns: [{ id: 'k1', title: 'T', color: '#000' }], assignments: [{ nodeId: 'a', columnId: 'k1' }] }
+ kanban: {
+ columns: [{ id: 'k1', title: 'T', color: '#000' }],
+ assignments: [{ nodeId: 'a', columnId: 'k1' }],
+ meta: [{ nodeId: 'a', priority: 'high', labels: ['l1'] }],
+ labels: [{ id: 'l1', name: 'Bug', color: 'red' }],
+ views: [{ id: 'v1', name: 'Mine', query: {} } as never]
+ }
}
const next: CanvasContent = { nodes: [node('a')], bridges: [], ropes: [] }
const replayed = diffContent(prev, next, 'p').reduce((c, m) => applyCanvasOp(c, m, 'p'), prev)
- expect(replayed.kanban?.columns).toEqual(defaultKanbanFor('p').columns)
+ const fresh = defaultKanbanFor('p')
+ expect(replayed.kanban?.columns).toEqual(fresh.columns)
expect(replayed.kanban?.assignments).toEqual([])
+ expect(replayed.kanban?.meta ?? []).toEqual([])
+ expect(replayed.kanban?.labels ?? []).toEqual([])
+ expect(replayed.kanban?.views ?? []).toEqual([])
// …and a project that never had a board still casts nothing for it.
expect(diffContent(next, { ...next }, 'p')).toEqual([])
})
+
+ // D12: the placement of a card whose node is gone on BOTH sides (a dead card the file still
+ // carried) is removed when the outside edit drops it; before, `prev ∪ next` node ids were the only
+ // live set, so every replica kept it.
+ it('drops a dead card placement and its meta when the edit drops them', () => {
+ const board = (withCard: boolean): ProjectKanban => ({
+ ...defaultKanbanFor('p'),
+ assignments: withCard ? [{ nodeId: 'gone', columnId: defaultKanbanFor('p').columns[0].id }] : [],
+ ...(withCard ? { meta: [{ nodeId: 'gone', priority: 'low' as const }] } : {})
+ })
+ const prev: CanvasContent = { nodes: [node('a')], bridges: [], ropes: [], kanban: board(true) }
+ const next: CanvasContent = { nodes: [node('a')], bridges: [], ropes: [], kanban: board(false) }
+ const ops = diffContent(prev, next, 'p')
+ expect(ops).toContainEqual({ op: 'kb-card-remove', nodeId: 'gone' })
+ expect(ops).toContainEqual({ op: 'kb-meta-remove', nodeId: 'gone' })
+ })
})
diff --git a/src/shared/canvas-content.ts b/src/shared/canvas-content.ts
index 88662c924..70375f48f 100644
--- a/src/shared/canvas-content.ts
+++ b/src/shared/canvas-content.ts
@@ -10,7 +10,7 @@ import {
isWellFormedMutation
} from './canvas-mutations'
import { defaultKanbanFor } from './kanban-default-board'
-import { applyKanbanOp, diffKanbanOps, isKanbanOp, sanitizeKanbanOp } from './kanban-ops'
+import { applyKanbanOp, boardNodeIds, diffKanbanOps, isKanbanOp, sanitizeKanbanOp } from './kanban-ops'
import type { BridgeLink, CanvasMutation, CanvasNodeState, Project, ProjectKanban } from './types'
/**
@@ -57,7 +57,9 @@ export function contentOf(p: Pick<Project, 'nodes' | 'bridges' | 'ropes' | 'kanb
* header for why a reducer must not re-apply a transport limit). A malformed op is a no-op.
*/
export function applyCanvasOp(c: CanvasContent, m: CanvasMutation, projectId: string): CanvasContent {
- if (!isWellFormedMutation(m)) return c
+ if (!m || typeof m !== 'object') return c
+ // A board op is sanitized ONCE: `sanitizeKanbanOp` is its whole shape verdict (what
+ // `isWellFormedMutation` would have asked for it), and its result is the op applied.
if (isKanbanOp(m)) {
const op = sanitizeKanbanOp(m)
if (!op) return c
@@ -65,6 +67,7 @@ export function applyCanvasOp(c: CanvasContent, m: CanvasMutation, projectId: st
const after = applyKanbanOp(c.kanban, op, projectId)
return sameBoard(before, after) ? c : { ...c, kanban: after }
}
+ if (!isWellFormedMutation(m)) return c
if (isEdgeMutation(m)) {
const s = applyEdgeMutationToScene({ bridges: c.bridges, ropes: c.ropes }, m)
return s.bridges === c.bridges && s.ropes === c.ropes ? c : { ...c, bridges: s.bridges, ropes: s.ropes }
@@ -76,9 +79,10 @@ export function applyCanvasOp(c: CanvasContent, m: CanvasMutation, projectId: st
/**
* The ops that turn `prev` into `next`, for an OUTSIDE edit (a git pull, a hand edit) that the
* authority must publish to every client as if someone had cast it. Every removal in it is real:
- * the board part is diffed with EVERY node id of both sides as live, so a card whose node is gone
- * from the new file has its removal cast — unlike a client's publisher, which must not cast the
- * lazy prune of a card whose node op may simply not have arrived yet.
+ * the board part is diffed with EVERY node id of both sides as live — the nodes, and every node a
+ * card of the old board names — so a card whose node is gone from the new file has its removal cast,
+ * a dead card the file carried included, unlike a client's publisher, which must not cast the lazy
+ * prune of a card whose node op may simply not have arrived yet.
*
* A `next` with no board while `prev` had one diffs to the LAZY DEFAULT, not to nothing: a file with
* no `kanban` block renders as the default board on every client, so an outside edit that removed
@@ -95,7 +99,7 @@ export function diffContent(prev: CanvasContent, next: CanvasContent, projectId:
{ nodes: prev.nodes, bridges: prev.bridges, ropes: prev.ropes },
{ nodes: next.nodes, bridges: next.bridges, ropes: next.ropes }
)
- const all = new Set([...prev.nodes, ...next.nodes].map((n) => n.id))
+ const all = new Set([...[...prev.nodes, ...next.nodes].map((n) => n.id), ...boardNodeIds(prev.kanban)])
const nextBoard = next.kanban ?? (prev.kanban ? defaultKanbanFor(projectId) : undefined)
const board = diffKanbanOps(prev.kanban, nextBoard, projectId, all)
const nodeAdds = scene.filter((m) => m.op === 'upsert')
diff --git a/src/shared/kanban-labels.ts b/src/shared/kanban-labels.ts
index 5831f6d07..6a5949c37 100644
--- a/src/shared/kanban-labels.ts
+++ b/src/shared/kanban-labels.ts
@@ -193,10 +193,10 @@ export function reorderLabels(k: ProjectKanban, id: string, beforeId: string | n
/** Toggle a label on a card (add if absent, remove if present). Preserves the card's other meta. */
export function toggleCardLabel(k: ProjectKanban, nodeId: string, labelId: string): ProjectKanban {
const cur = cardMeta(k, nodeId)
- const has = (cur?.labels ?? []).includes(labelId)
- const labels = has
- ? (cur?.labels ?? []).filter((x) => x !== labelId)
- : [...(cur?.labels ?? []), labelId]
+ // A hand-edited file can hold a non-list here: read it as no labels, never `.includes` of a string
+ // or an object thrown out of a click handler.
+ const held = Array.isArray(cur?.labels) ? cur.labels.filter((x): x is string => typeof x === 'string') : []
+ const labels = held.includes(labelId) ? held.filter((x) => x !== labelId) : [...held, labelId]
return withCardMeta(k, nodeId, {
assignees: cur?.assignees,
dueAt: cur?.dueAt,
diff --git a/src/shared/kanban-ops.test.ts b/src/shared/kanban-ops.test.ts
index cfddb1d96..ce584bed1 100644
--- a/src/shared/kanban-ops.test.ts
+++ b/src/shared/kanban-ops.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect } from 'vitest'
import { applyKanbanOp, diffKanbanOps, sanitizeKanbanOp, kanbanOpKey, isKanbanDeletion } from './kanban-ops'
-import { defaultKanbanFor } from './kanban-default-board'
+import { DEFAULT_BOARD_COLUMNS, defaultKanbanFor } from './kanban-default-board'
+import { UNSAFE_DISPLAY_CHARS } from './presence'
import { columnOrder } from './kanban-order'
import { isValidRank, rankBetween } from './kanban-rank'
import type { KanbanOp, ProjectKanban } from './types'
@@ -52,9 +53,27 @@ describe('sanitizeKanbanOp', () => {
expect(sanitizeKanbanOp({ op: 'kb-meta', meta: { nodeId: 'n1', assignees: [{ name: 'Ada\u202egnihsihp', color: '#f00' }, { name: '\u0007', color: '#0f0' }] } }))
.toEqual({ op: 'kb-meta', meta: { nodeId: 'n1', assignees: [{ name: 'Adagnihsihp', color: '#f00' }] } })
})
- it('ids stay refuse-only: a control character in an id is not repaired', () => {
+ // An id is an ADDRESS, never displayed: a malformed one (not a string, empty, past the ref bound) is
+ // refused whole, and any other string is carried byte for byte. Stripping a character would address
+ // a different item; refusing it would stop that item (and any order op listing it) ever syncing.
+ it('ids are never repaired: a malformed id is refused, any other string is carried as is', () => {
expect(sanitizeKanbanOp({ op: 'kb-column-remove', id: 'x'.repeat(129) })).toBeNull()
expect(sanitizeKanbanOp({ op: 'kb-card', assignment: { nodeId: '', columnId: 'c1' } })).toBeNull()
+ expect(sanitizeKanbanOp({ op: 'kb-column-remove', id: 'a\u0007\u202eb' })).toEqual({ op: 'kb-column-remove', id: 'a\u0007\u202eb' })
+ })
+ // D7: ONE unsafe-display set, shared with presence names: the zero-width marks and the BOM too.
+ it('strips zero-width marks and the BOM from a display name, like a presence name', () => {
+ expect(sanitizeKanbanOp({ op: 'kb-label', label: { id: 'l1', name: '\ufeffB\u200bu\u200fg', color: 'red' } }))
+ .toEqual({ op: 'kb-label', label: { id: 'l1', name: 'Bug', color: 'red' } })
+ expect(UNSAFE_DISPLAY_CHARS.source).toContain('\\u200b-\\u200f')
+ })
+ // D7: a column's colour is repaired, not a reason to refuse the column (like a label's).
+ it('a column with a missing or invalid colour keeps its place with the default colour', () => {
+ const expected = { op: 'kb-column', column: { id: 'c1', title: 'T', color: DEFAULT_BOARD_COLUMNS[0].color } }
+ expect(sanitizeKanbanOp({ op: 'kb-column', column: { id: 'c1', title: 'T' } })).toEqual(expected)
+ expect(sanitizeKanbanOp({ op: 'kb-column', column: { id: 'c1', title: 'T', color: 7 } })).toEqual(expected)
+ expect(sanitizeKanbanOp({ op: 'kb-column', column: { id: 'c1', title: 'T', color: '#f\u0000' } })).toEqual(expected)
+ expect(sanitizeKanbanOp({ op: 'kb-column', column: { id: 'c1', title: 'T', color: 'x'.repeat(65) } })).toEqual(expected)
})
it('drops an invalid rank rather than the whole op', () => {
expect(sanitizeKanbanOp({ op: 'kb-card', assignment: { nodeId: 'n1', columnId: 'c1', rank: '!!' } }))
diff --git a/src/shared/kanban-ops.ts b/src/shared/kanban-ops.ts
index a6a626ac9..6db66772b 100644
--- a/src/shared/kanban-ops.ts
+++ b/src/shared/kanban-ops.ts
@@ -9,16 +9,21 @@ import { defaultKanbanFor } from './kanban-default-board'
import { boardLabels, KANBAN_LABEL_COLORS, metaList } from './kanban-labels'
import { isValidRank } from './kanban-rank'
import { sanitizeViews } from './kanban-views'
-import { capCodePoints } from './presence'
+import { SYSTEM_NODE_COLORS } from './node-colors'
+import { capCodePoints, UNSAFE_DISPLAY_CHARS } from './presence'
import type {
KanbanAssignment, KanbanCardMeta, KanbanColumn, KanbanColumnCategory, KanbanLabel,
KanbanLabelColor, KanbanOp, KanbanPriority, KanbanSavedView, ProjectKanban
} from './types'
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/
-/** What a display name must never carry: C0/C1 controls (they break a name out of its one-line chip)
- * and the bidi overrides / isolates (they make a name DISPLAY as something it is not). */
-const UNSAFE_DISPLAY = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g
+/** What a display name must never carry: C0/C1 controls (they break a name out of its one-line chip),
+ * the bidi overrides / isolates and the zero-width marks and BOM (they make a name DISPLAY as
+ * something it is not). ONE set, shared with presence names (@shared/presence). */
+const UNSAFE_DISPLAY = UNSAFE_DISPLAY_CHARS
+/** A column whose colour is missing or unusable keeps its place in this colour (the default board's
+ * first column), exactly as a label with a colour off its palette becomes `default`. */
+const DEFAULT_COLUMN_COLOR = SYSTEM_NODE_COLORS[0]
const TITLE_MAX = 200
const COLOR_MAX = 64
const NAME_MAX = 100
@@ -39,6 +44,9 @@ const text = (x: unknown, max: number): string | null =>
* characters are removed, the rest trimmed, then cut to `max` CODE POINTS (never splitting an astral
* character in half) and trimmed again. Only what is empty once repaired is refused (`null`). Ids
* are never passed through here — an id is an address, and a repaired one addresses the wrong thing.
+ * Nor are they refused for their characters: ids are never displayed, and refusing one would stop
+ * that item, and every order op listing it, ever syncing. Only a malformed id (`isRefId`: not a
+ * string, empty, or past the ref bound) is refused.
*/
function displayText(x: unknown, max: number): string | null {
if (typeof x !== 'string') return null
@@ -53,9 +61,8 @@ const idList = (x: unknown): string[] | null => {
function column(x: unknown): KanbanColumn | null {
if (!isObj(x) || !isRefId(x.id)) return null
const title = displayText(x.title, TITLE_MAX)
- const color = text(x.color, COLOR_MAX)
- if (title === null || color === null) return null
- const out: KanbanColumn = { id: x.id, title, color }
+ if (title === null) return null
+ const out: KanbanColumn = { id: x.id, title, color: text(x.color, COLOR_MAX) ?? DEFAULT_COLUMN_COLOR }
if (CATEGORIES.includes(x.category as KanbanColumnCategory)) out.category = x.category as KanbanColumnCategory
return out
}
@@ -106,9 +113,10 @@ export function isKanbanOp(m: { op?: unknown }): boolean {
return typeof m.op === 'string' && m.op.startsWith('kb-')
}
-/** The sanitized op, or null to REFUSE it. Refusals are whole-op (a bad id addresses the wrong
- * thing); repairable fields are repaired or dropped — colour, rank, priority, dueAt, category, and
- * the display text (label name, column title, assignee name: see `displayText`). */
+/** The sanitized op, or null to REFUSE it. Refusals are whole-op (a malformed id addresses the wrong
+ * thing); repairable fields are repaired or dropped — colour (a column's to the default colour, a
+ * label's to `default`), rank, priority, dueAt, category, and the display text (label name, column
+ * title, assignee name: see `displayText`). */
export function sanitizeKanbanOp(m: unknown): KanbanOp | null {
if (!isObj(m)) return null
switch (m.op) {
@@ -178,6 +186,12 @@ const metaOf = (b: ProjectKanban): KanbanCardMeta[] => metaList(b).filter(isEntr
const labelsOf = (b: ProjectKanban): KanbanLabel[] => boardLabels(b)
const viewsOf = (b: ProjectKanban): KanbanSavedView[] =>
Array.isArray(b.views) ? b.views.filter(isEntry('id')) as KanbanSavedView[] : []
+/** Every node id a board's cards and card metadata name, read tolerantly. */
+export function boardNodeIds(b: ProjectKanban | undefined): string[] {
+ if (!b) return []
+ return [...assignmentsOf(b).map((a) => a.nodeId), ...metaOf(b).map((x) => x.nodeId)]
+}
+
/** A card's label ids, whatever a malformed file put there. */
const cardLabelIds = (x: KanbanCardMeta): string[] =>
Array.isArray(x.labels) ? x.labels.filter((l): l is string => typeof l === 'string') : []
diff --git a/src/shared/presence.ts b/src/shared/presence.ts
index aa1253d6f..a980b8a83 100644
--- a/src/shared/presence.ts
+++ b/src/shared/presence.ts
@@ -160,7 +160,10 @@ export function capCodePoints(text: string, max: number): string {
* CJK and emoji are untouched.
*/
// eslint-disable-next-line no-control-regex
-const UNSAFE_NAME_CHARS = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g
+export const UNSAFE_DISPLAY_CHARS = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g
+/** The name this file has always used for it. ONE set: the board's display text strips the same
+ * characters (@shared/kanban-ops `displayText`). Global, so use it with `replace`, never `test`. */
+const UNSAFE_NAME_CHARS = UNSAFE_DISPLAY_CHARS
/** Cap a name at NAME_MAX_LEN code points, after stripping the characters that could spoof or
* break the rendering of another peer's name (UNSAFE_NAME_CHARS). Trim runs again AFTER the cut,