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): encode card ids in the status-chip signature

review589576869488
diff --git a/src/renderer/lib/kanbanStatusChips.test.ts b/src/renderer/lib/kanbanStatusChips.test.ts
index 93c048431..ff6112585 100644
--- a/src/renderer/lib/kanbanStatusChips.test.ts
+++ b/src/renderer/lib/kanbanStatusChips.test.ts
@@ -67,6 +67,23 @@ describe('statusChipSig — a derived signature, never the whole byId map', () =
expect([...facts.unread].sort()).toEqual(['b', 'c'])
})
+ it('a card id carrying the separators cannot forge another card\'s facts', () => {
+ // Node ids come from a git-shared, hand-editable project file.
+ const hostile: StatusChipCard[] = [
+ { id: 'x|victim', kind: 'terminal' },
+ { id: 'y:rnu|z', kind: 'terminal' },
+ { id: 'victim', kind: 'terminal' },
+ { id: 'z', kind: 'terminal' }
+ ]
+ const facts = parseStatusChipSig(statusChipSig({
+ 'x|victim': st({ unread: true }),
+ 'y:rnu|z': st({ state: 'working' })
+ }, hostile))
+ expect([...facts.unread]).toEqual(['x|victim'])
+ expect([...facts.running]).toEqual(['y:rnu|z'])
+ expect(facts.needs.size).toBe(0)
+ })
+
it('a dropped agent is not "running" even if its last state said so', () => {
const facts = parseStatusChipSig(statusChipSig({ a: st({ state: 'working', dropped: true }) }, cards))
expect(facts.running.size).toBe(0)
@@ -74,7 +91,10 @@ describe('statusChipSig — a derived signature, never the whole byId map', () =
})
describe('matchesStatusChips', () => {
- const facts = parseStatusChipSig('a:r..|b:.nu|')
+ const facts = parseStatusChipSig(statusChipSig(
+ { a: st({ state: 'working' }), b: st({ state: 'waiting', unread: true }) },
+ [{ id: 'a', kind: 'terminal' }, { id: 'b', kind: 'terminal' }]
+ ))
it('no active chip matches everything', () => {
expect(matchesStatusChips(facts, 'zzz', [])).toBe(true)
diff --git a/src/renderer/lib/kanbanStatusChips.ts b/src/renderer/lib/kanbanStatusChips.ts
index 91dfc6b0c..d21e994a0 100644
--- a/src/renderer/lib/kanbanStatusChips.ts
+++ b/src/renderer/lib/kanbanStatusChips.ts
@@ -47,12 +47,15 @@ export interface StatusChipCard {
kind: string
}
-/** One entry per card with at least one chip fact: `id:` + `r|.` `n|.` `u|.` + `|`. */
+/** One `[id, flags]` entry per card with at least one chip fact (`r|.` `n|.` `u|.`), written with
+ * `JSON.stringify` — node ids come from a git-shared, hand-editable project file, and an id joined
+ * raw with a separator (`x|victim`) used to split into a forged entry for another card. `''` when
+ * no card has a fact. */
export function statusChipSig(
byId: Readonly<Record<string, AgentNodeStatus | undefined>>,
cards: readonly StatusChipCard[]
): string {
- let sig = ''
+ const entries: Array<[string, string]> = []
for (const card of cards) {
const status = byId[card.id]
if (!status) continue
@@ -61,9 +64,9 @@ export function statusChipSig(
const n = badge === 'needs'
const u = !!status.unread
if (!r && !n && !u) continue
- sig += `${card.id}:${r ? 'r' : '.'}${n ? 'n' : '.'}${u ? 'u' : '.'}|`
+ entries.push([card.id, `${r ? 'r' : '.'}${n ? 'n' : '.'}${u ? 'u' : '.'}`])
}
- return sig
+ return entries.length ? JSON.stringify(entries) : ''
}
export interface StatusChipFacts {
@@ -74,11 +77,17 @@ export interface StatusChipFacts {
export function parseStatusChipSig(sig: string): StatusChipFacts {
const facts: StatusChipFacts = { running: new Set(), needs: new Set(), unread: new Set() }
- for (const entry of sig.split('|')) {
- const colon = entry.lastIndexOf(':')
- if (colon <= 0) continue
- const id = entry.slice(0, colon)
- const flags = entry.slice(colon + 1)
+ if (!sig) return facts
+ let entries: unknown
+ try {
+ entries = JSON.parse(sig)
+ } catch {
+ return facts
+ }
+ if (!Array.isArray(entries)) return facts
+ for (const entry of entries) {
+ if (!Array.isArray(entry) || typeof entry[0] !== 'string' || typeof entry[1] !== 'string') continue
+ const [id, flags] = entry as [string, string]
if (flags[0] === 'r') facts.running.add(id)
if (flags[1] === 'n') facts.needs.add(id)
if (flags[2] === 'u') facts.unread.add(id)