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(board-log): clamp comment text (SSH arg-max silent loss, unbounded file growth)

enes098d1c1099aa
diff --git a/src/core/board-log.test.ts b/src/core/board-log.test.ts
index ba98d634d..24146b040 100644
--- a/src/core/board-log.test.ts
+++ b/src/core/board-log.test.ts
@@ -3,7 +3,7 @@ import fs from 'fs'
import os from 'os'
import path from 'path'
import type { BoardLogEntry } from '@shared/types'
-import { buildLine, parseLines, validEntry, BoardLogStore, type RemoteLogExec } from './board-log'
+import { buildLine, parseLines, validEntry, BoardLogStore, BOARD_LOG_TEXT_MAX, type RemoteLogExec } from './board-log'
const entry = (over: Partial<BoardLogEntry> = {}): BoardLogEntry => ({
id: 'e1',
@@ -23,6 +23,19 @@ describe('buildLine / parseLines / validEntry', () => {
expect(parseLines(line)).toEqual([e])
})
+ it('buildLine clamps over-long text to BOARD_LOG_TEXT_MAX chars + ellipsis, line stays valid JSON', () => {
+ const long = 'x'.repeat(BOARD_LOG_TEXT_MAX + 5000)
+ const line = buildLine(entry({ id: 'big', text: long }))
+ expect(line.endsWith('\n')).toBe(true)
+ const parsed = JSON.parse(line.slice(0, -1)) as BoardLogEntry // valid single-line JSON
+ expect(parsed.text).toHaveLength(BOARD_LOG_TEXT_MAX + 1) // cap chars + the '…'
+ expect(parsed.text!.endsWith('…')).toBe(true)
+ expect(parsed.text!.slice(0, -1)).toBe('x'.repeat(BOARD_LOG_TEXT_MAX))
+ // Text exactly at the cap is left untouched (no ellipsis).
+ const exact = 'y'.repeat(BOARD_LOG_TEXT_MAX)
+ expect((JSON.parse(buildLine(entry({ text: exact })).slice(0, -1)) as BoardLogEntry).text).toBe(exact)
+ })
+
it('parseLines is tolerant: skips a garbage line, keeps the valid one', () => {
const good = buildLine(entry({ id: 'ok' }))
const raw = 'not json\n' + '{"missing":"fields"}\n' + good
diff --git a/src/core/board-log.ts b/src/core/board-log.ts
index d9378fe32..aeefc8864 100644
--- a/src/core/board-log.ts
+++ b/src/core/board-log.ts
@@ -1,7 +1,10 @@
import fs from 'fs'
import path from 'path'
import { watch, type FSWatcher } from 'fs'
-import type { BoardLogEntry } from '@shared/types'
+import { BOARD_LOG_TEXT_MAX, type BoardLogEntry } from '@shared/types'
+
+// Re-exported so callers of this module (and its tests) can reach the cap alongside buildLine.
+export { BOARD_LOG_TEXT_MAX }
// Append-only board history. Each project's board log lives beside its nodes at
// `<cwd>/.nodeterm/board-log.jsonl`, one JSON entry per line, oldest-first on disk. Local
@@ -12,6 +15,14 @@ import type { BoardLogEntry } from '@shared/types'
const LOG_DIR = '.nodeterm'
const LOG_FILE = 'board-log.jsonl'
const DEFAULT_CAP = 500
+
+/** Clamp an entry's `text` to `BOARD_LOG_TEXT_MAX` chars (+ '…' when truncated). Returns the
+ * same entry when nothing changes, else a shallow copy with the shortened text. */
+export function clampEntryText(entry: BoardLogEntry): BoardLogEntry {
+ const { text } = entry
+ if (typeof text !== 'string' || text.length <= BOARD_LOG_TEXT_MAX) return entry
+ return { ...entry, text: text.slice(0, BOARD_LOG_TEXT_MAX) + '…' }
+}
// `all` still needs a finite tail count for the remote path; larger than any realistic log.
const ALL_LINES = 1_000_000_000
@@ -45,7 +56,7 @@ export function validEntry(x: unknown): x is BoardLogEntry {
/** One log line: single-line JSON + '\n'. Any newline in `text` is JSON-escaped, so the line
* never breaks the one-entry-per-line invariant. */
export function buildLine(entry: BoardLogEntry): string {
- return JSON.stringify(entry) + '\n'
+ return JSON.stringify(clampEntryText(entry)) + '\n'
}
/** Parse a raw log blob → entries, NEWEST-FIRST. Tolerant: lines that fail JSON.parse or the
diff --git a/src/renderer/state/boardLog.ts b/src/renderer/state/boardLog.ts
index 2a44a0bf3..e56e48329 100644
--- a/src/renderer/state/boardLog.ts
+++ b/src/renderer/state/boardLog.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand'
-import type { BoardLogEntry, NodeTerminalApi } from '@shared/types'
+import { BOARD_LOG_TEXT_MAX, type BoardLogEntry, type NodeTerminalApi } from '@shared/types'
import { loadIdentity } from './presence'
/**
@@ -69,13 +69,20 @@ export const useBoardLog = create<BoardLogState>((set, get) => ({
append: (api, projectId, input) => {
const id = loadIdentity()
const author = id ? { name: id.name, color: id.color } : ANON_AUTHOR
+ // Clamp identically to buildLine (src/core/board-log.ts) so the optimistic entry the user sees
+ // matches what lands on disk — an over-long paste would otherwise silently truncate on reload
+ // (and, over SSH, fail the append entirely and vanish).
+ const text =
+ input.text !== undefined && input.text.length > BOARD_LOG_TEXT_MAX
+ ? input.text.slice(0, BOARD_LOG_TEXT_MAX) + '…'
+ : input.text
const entry: BoardLogEntry = {
id: crypto.randomUUID(),
ts: Date.now(),
author,
kind: input.kind,
...(input.nodeId !== undefined ? { nodeId: input.nodeId } : {}),
- ...(input.text !== undefined ? { text: input.text } : {}),
+ ...(text !== undefined ? { text } : {}),
...(input.event !== undefined ? { event: input.event } : {})
}
// Optimistic newest-first insert.
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 76f961056..3e75daa1d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -246,6 +246,13 @@ export interface BoardLogEntry {
event?: BoardLogEvent
}
+/** Max chars kept for a comment's `text`. On an SSH project the whole JSON line becomes one
+ * shell arg (`printf '%s\n' '<line>'` over the ControlMaster); an unbounded paste blows past
+ * ARG_MAX → the append fails → the optimistic entry silently vanishes on reload. Locally it
+ * just bloats the append-only file. Shared so core (disk) and the renderer (optimistic UI)
+ * clamp identically. */
+export const BOARD_LOG_TEXT_MAX = 16_384
+
/** Read options for the board log: cap the newest N entries (default 500 in the store) or `all`. */
export interface BoardLogReadOpts {
cap?: number