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
fix(kanban): rankBetween never returns the reserved smallest key
review34b4fc430dcf
diff --git a/src/shared/kanban-rank.test.ts b/src/shared/kanban-rank.test.tsindex b5ad4fef0..3e70ad068 100644--- a/src/shared/kanban-rank.test.ts+++ b/src/shared/kanban-rank.test.ts@@ -78,6 +78,30 @@ describe('ranksBetween', () => {})})+describe('the bottom of the key space', () => {+ // The smallest integer part is reserved (nothing may sort before it, so nothing may BE it); the+ // smallest integer a key may carry is one above it.+ const reserved = 'A' + '0'.repeat(26)+ const lowestInteger = 'A' + '0'.repeat(25) + '1'++ it('the reserved integer itself is never a key', () => {+ expect(isValidRank(reserved)).toBe(false)+ })++ it('there is always a valid key before the lowest integer, and before that one', () => {+ expect(isValidRank(lowestInteger)).toBe(true)+ let k = lowestInteger+ for (let i = 0; i < 50; i++) {+ const below = rankBetween(null, k)+ expect(isValidRank(below), below).toBe(true)+ expect(below < k).toBe(true)+ k = below+ }+ expect(ranksBetween(null, lowestInteger, 5).every((key) => isValidRank(key) && key < lowestInteger))+ .toBe(true)+ })+})+describe('isValidRank', () => {it('accepts what rankBetween mints', () => {expect(isValidRank(rankBetween(null, null))).toBe(true)diff --git a/src/shared/kanban-rank.ts b/src/shared/kanban-rank.tsindex 1bcc8ba3e..be84801d3 100644--- a/src/shared/kanban-rank.ts+++ b/src/shared/kanban-rank.ts@@ -25,7 +25,9 @@const DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'const ZERO = DIGITS[0]const LAST = DIGITS[DIGITS.length - 1]-/** The smallest integer part. Reserved: nothing may sort before it, so nothing may be it. */+/** The smallest integer part. Reserved: nothing may sort before it, so nothing may BE it — but a+ * key may carry it with a fraction (`A00…0V`), which sorts after it: that is the room below the+ * lowest plain integer, and without it `rankBetween(null, 'A00…01')` had no valid answer. */const SMALLEST_INTEGER = `A${ZERO.repeat(26)}`/** Longer than any key a board will ever mint; beyond it a "rank" is garbage, not a position. */export const RANK_MAX_LENGTH = 256@@ -51,7 +53,7 @@ export function isValidRank(x: unknown): x is string {for (const c of x) if (digitValue(c) === -1) return falseconst n = integerDigits(x[0])if (n < 0 || x.length < n + 1) return false- if (x.slice(0, n + 1) === SMALLEST_INTEGER) return false+ if (x === SMALLEST_INTEGER) return falsereturn !x.slice(n + 1).endsWith(ZERO)}@@ -118,7 +120,8 @@ export function rankBetween(a: string | null, b: string | null): string {if (ib < b) return ibconst down = stepInteger(ib, -1)if (down === null) throw new Error('rank space exhausted below')- return down+ // Stepping down onto the reserved integer: the key goes just under `b` with a fraction.+ return down === SMALLEST_INTEGER ? down + midpoint('', null) : down}if (b === null) {const ia = integerPart(a)