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.

refactor: move pane input, visible capture and two renderer helpers out of live links

reviewe75900253780
diff --git a/src/core/watch-link/capture-route.realtmux.test.ts b/src/core/capture-route.realtmux.test.ts
similarity index 99%
rename from src/core/watch-link/capture-route.realtmux.test.ts
rename to src/core/capture-route.realtmux.test.ts
index 94c0744cf..d36be03b2 100644
--- a/src/core/watch-link/capture-route.realtmux.test.ts
+++ b/src/core/capture-route.realtmux.test.ts
@@ -19,7 +19,7 @@ import {
unavailableCapture,
type VisibleCapture
} from './capture-route'
-import { makeTmuxTmpdir } from '../tmux-test-socket'
+import { makeTmuxTmpdir } from './tmux-test-socket'
const SOCKET = `nt-wlcap-${process.pid}`
const HAS_TMUX = (() => {
diff --git a/src/core/watch-link/capture-route.test.ts b/src/core/capture-route.test.ts
similarity index 100%
rename from src/core/watch-link/capture-route.test.ts
rename to src/core/capture-route.test.ts
diff --git a/src/core/watch-link/capture-route.ts b/src/core/capture-route.ts
similarity index 100%
rename from src/core/watch-link/capture-route.ts
rename to src/core/capture-route.ts
diff --git a/src/core/watch-link/pane-input.realtmux.test.ts b/src/core/pane-input.realtmux.test.ts
similarity index 98%
rename from src/core/watch-link/pane-input.realtmux.test.ts
rename to src/core/pane-input.realtmux.test.ts
index ca9894a60..ea53febf9 100644
--- a/src/core/watch-link/pane-input.realtmux.test.ts
+++ b/src/core/pane-input.realtmux.test.ts
@@ -24,9 +24,9 @@ import { execFileSync, spawn, spawnSync, type ChildProcess } from 'child_process
import fs from 'fs'
import path from 'path'
import { controlInputPlan, remoteControlInputPlan, type ControlInputChunk } from './pane-input'
-import { runPasteDelivery } from '../tmux-naming'
-import { RMT_TMUX_SOCKET } from '../remote-ssh/control-master'
-import { makeTmuxTmpdir } from '../tmux-test-socket'
+import { runPasteDelivery } from './tmux-naming'
+import { RMT_TMUX_SOCKET } from './remote-ssh/control-master'
+import { makeTmuxTmpdir } from './tmux-test-socket'
const SOCKET = `nt-ctl-test-${process.pid}`
const CONN = { host: 'h.example.com', user: 'deploy', port: 2222, identityFile: '/k/id' }
diff --git a/src/core/watch-link/pane-input.test.ts b/src/core/pane-input.test.ts
similarity index 98%
rename from src/core/watch-link/pane-input.test.ts
rename to src/core/pane-input.test.ts
index 62c153284..6bc0498e2 100644
--- a/src/core/watch-link/pane-input.test.ts
+++ b/src/core/pane-input.test.ts
@@ -13,8 +13,8 @@ import {
remoteKeysArgs,
remotePasteArgs
} from './pane-input'
-import { RMT_TMUX_SOCKET } from '../remote-ssh/control-master'
-import { remoteTmuxPathPrologue } from '../../shared/ssh'
+import { RMT_TMUX_SOCKET } from './remote-ssh/control-master'
+import { remoteTmuxPathPrologue } from '../shared/ssh'
const CONN = { host: 'h.example.com', user: 'deploy', port: 2222, identityFile: '/k/id' }
const CM = '/cm/p1'
diff --git a/src/core/watch-link/pane-input.ts b/src/core/pane-input.ts
similarity index 98%
rename from src/core/watch-link/pane-input.ts
rename to src/core/pane-input.ts
index d4919600c..61953e14d 100644
--- a/src/core/watch-link/pane-input.ts
+++ b/src/core/pane-input.ts
@@ -73,17 +73,17 @@
// Read from tmux's source (window.c `window_pane_key`), not measured: `send-keys` honours a window's
// `synchronize-panes` (the keys are copied to its other panes) and silently drops input to a pane
// disabled with `select-pane -d` while still exiting 0. nodeterm's conf sets neither.
-import type { SshConnection } from '../../shared/ssh'
-import { posixQuote } from '../../shared/ssh'
-import { sanitizePasteText } from '../paste-injection'
+import type { SshConnection } from '../shared/ssh'
+import { posixQuote } from '../shared/ssh'
+import { sanitizePasteText } from './paste-injection'
import {
assertPasteBuffer,
exactPaneTarget,
localTmuxDeleteBufferArgs,
pasteBufferName,
type PasteDelivery
-} from '../tmux-naming'
-import { RMT_TMUX_SOCKET, childArgs, remoteDeleteBufferArgs, tmuxCmd } from '../remote-ssh/control-master'
+} from './tmux-naming'
+import { RMT_TMUX_SOCKET, childArgs, remoteDeleteBufferArgs, tmuxCmd } from './remote-ssh/control-master'
/** One unit of a controller's input. `keys` are typed byte for byte; `paste` is text tmux frames
* per the pane's own bracketed-paste state. */
diff --git a/src/core/pty-manager.capture-visible.test.ts b/src/core/pty-manager.capture-visible.test.ts
index 1a19a437a..18eecde5b 100644
--- a/src/core/pty-manager.capture-visible.test.ts
+++ b/src/core/pty-manager.capture-visible.test.ts
@@ -1,13 +1,13 @@
// `PtyManager.captureVisible` — a live link's keyframe: WHICH binary is asked with WHICH argv, and
// the failure contract. The argv's meaning (exact target, visible rows only, the cursor line from the
-// same invocation) is proven against a real tmux in `watch-link/capture-route.realtmux.test.ts` and
+// same invocation) is proven against a real tmux in `capture-route.realtmux.test.ts` and
// through a real /bin/sh in `remote-ssh/capture-visible.realsh.test.ts`; this file pins dispatch.
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { initPlatform, resetPlatformForTests } from './platform'
import { fakePlatform } from './platform-fake'
import { TMUX_SOCKET, sessionName } from './tmux-naming'
import { RMT_TMUX_SOCKET } from './remote-ssh/control-master'
-import { VISIBLE_CAPTURE_FORMAT, unavailableCapture } from './watch-link/capture-route'
+import { VISIBLE_CAPTURE_FORMAT, unavailableCapture } from './capture-route'
/** Every `runAsync` in pty-manager lands here. `answer` decides what each call resolves to. */
const calls: Array<{ file: string; args: string[] }> = []
diff --git a/src/core/pty-manager.control-input.test.ts b/src/core/pty-manager.control-input.test.ts
index 4182ffb92..89cc2b0a3 100644
--- a/src/core/pty-manager.control-input.test.ts
+++ b/src/core/pty-manager.control-input.test.ts
@@ -2,7 +2,7 @@
// input: WHICH route a session gets, WHICH binary is asked with WHICH argv and WHICH stdin, the
// per-session order, and the never-rejects contract. What the plans MEAN on a real tmux (bytes
// exact, the prefix inert, a mode cancelled first, the exact session only) is
-// `watch-link/pane-input.realtmux.test.ts`; this file pins dispatch, in the style of
+// `pane-input.realtmux.test.ts`; this file pins dispatch, in the style of
// `pty-manager.capture-visible.test.ts`. It is its own file because the runner here must carry
// STDIN (`runWithStdin` reads the child off execFile's promise, as Node's own promisified execFile
// provides it), which the capture-visible harness has no reason to fake.
@@ -10,7 +10,7 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { initPlatform, resetPlatformForTests } from './platform'
import { fakePlatform } from './platform-fake'
import { TMUX_SOCKET, sessionName } from './tmux-naming'
-import { PANE_INPUT_DEADLINE_MS, keysCommandText, remoteKeysArgs } from './watch-link/pane-input'
+import { PANE_INPUT_DEADLINE_MS, keysCommandText, remoteKeysArgs } from './pane-input'
import { INPUT_DELIVERY_TIMEOUT_MS } from './watch-link/link-host'
import { DEFAULT_SETTINGS } from '../shared/types'
import { DaReplyGate } from './da-reply-gate'
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.ts
index 1c850222c..3abb0000d 100644
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@ -99,14 +99,14 @@ import {
unavailableCapture,
visibleCaptureRoute,
type VisibleCapture
-} from './watch-link/capture-route'
+} from './capture-route'
import {
PANE_INPUT_DEADLINE_MS,
controlInputPlan,
remoteControlInputPlan,
type ControlInputChunk,
type WatcherInputRoute
-} from './watch-link/pane-input'
+} from './pane-input'
import type { ControlSupport } from '../shared/watch-link-types'
import { sanitizePasteText } from './paste-injection'
import {
@@ -6009,7 +6009,7 @@ export class PtyManager {
* A live link's keyframe: the VISIBLE screen of a session, with the cursor read in the same tmux
* invocation — never history. The keyframe's `altScreen` is the caller's, from the join (a
* tmux-backed client paints on the alternate screen; see `VisibleCapture`). Which backends get
- * one, the exact target and the parse are `watch-link/capture-route.ts`. The session host
+ * one, the exact target and the parse are `capture-route.ts`. The session host
* (scrollback only), a direct Windows pane and a plain shell get `unavailableCapture()`, as does
* any failure — a dead ControlMaster, tmux's own "can't find session" for an exact-target miss.
*/
@@ -6053,7 +6053,7 @@ export class PtyManager {
}
/**
- * How a live-link controller's input reaches this session's PANE (watch-link/pane-input.ts).
+ * How a live-link controller's input reaches this session's PANE (pane-input.ts).
*
* Never through a tmux CLIENT: a byte written into a client's pty is that client's KEYBOARD, so
* the prefix would reach tmux (`C-b s` opens the session chooser) — and a watcher's own client is
diff --git a/src/core/remote-ssh/capture-visible.realsh.test.ts b/src/core/remote-ssh/capture-visible.realsh.test.ts
index 9d352a9d9..d3ceba0ef 100644
--- a/src/core/remote-ssh/capture-visible.realsh.test.ts
+++ b/src/core/remote-ssh/capture-visible.realsh.test.ts
@@ -13,7 +13,7 @@ import { execFileSync } from 'child_process'
import fs from 'fs'
import path from 'path'
import { remoteCaptureVisibleArgs, RMT_TMUX_SOCKET } from './control-master'
-import { VISIBLE_CAPTURE_FORMAT, parseVisibleCapture } from '../watch-link/capture-route'
+import { VISIBLE_CAPTURE_FORMAT, parseVisibleCapture } from '../capture-route'
import { testTmpDir } from '../test-tmp'
import { makeTmuxTmpdir } from '../tmux-test-socket'
diff --git a/src/core/remote-ssh/control-master.test.ts b/src/core/remote-ssh/control-master.test.ts
index 28689dea1..898f86efb 100644
--- a/src/core/remote-ssh/control-master.test.ts
+++ b/src/core/remote-ssh/control-master.test.ts
@@ -38,7 +38,7 @@ import {
remoteScpPath
} from './control-master'
import { remoteTmuxPathPrologue } from '../../shared/ssh'
-import { VISIBLE_CAPTURE_FORMAT } from '../watch-link/capture-route'
+import { VISIBLE_CAPTURE_FORMAT } from '../capture-route'
/** The PATH-append prologue every remote tmux line now starts with (issue #449). */
const TP = remoteTmuxPathPrologue()
diff --git a/src/core/remote-ssh/control-master.ts b/src/core/remote-ssh/control-master.ts
index 6d5f41e4e..f02224035 100644
--- a/src/core/remote-ssh/control-master.ts
+++ b/src/core/remote-ssh/control-master.ts
@@ -22,7 +22,7 @@ import { sanitizePasteText } from '../paste-injection'
import { typedInputScript } from '../typed-input'
import { canControlCanvas } from '../../shared/agents/config'
import { COMBINED_PANE_MARKER, PANE_OWNER_FMT, PS_FOREGROUND_FLAGS } from '../agents/pane-owner'
-import { VISIBLE_CAPTURE_FORMAT, capturePaneTarget } from '../watch-link/capture-route'
+import { VISIBLE_CAPTURE_FORMAT, capturePaneTarget } from '../capture-route'
import { WATCHER_CLIENT_FLAGS, WINDOW_SIZE_FORMAT } from '../watch-link/watcher-client'
// Dependency-free (no node-pty): safe to import from these pure builders.
@@ -58,7 +58,7 @@ export const LEGACY_RMT_TMUX_SOCKET = 'nodeterm-rmt'
* `command not found` on any host whose ssh exec-channel PATH misses the install dir — most
* visibly macOS with Homebrew's tmux in `/opt/homebrew/bin`. The prologue is one assignment, so
* the command's own exit code (what `probeSaysAbsent` and every caller reads) is unchanged.
- * Exported for the live link's pane-input builders (`watch-link/pane-input.ts`), which build their
+ * Exported for the live link's pane-input builders (`pane-input.ts`), which build their
* remote commands beside their local twins rather than here.
*/
export function tmuxCmd(body: string): string {
@@ -580,7 +580,7 @@ export function remoteCapturePaneArgs(conn: SshConnection, controlPath: string,
/**
* The VISIBLE screen of a remote session, with SGR, and nothing above it — a live link's keyframe
* must never carry history, and `remoteCapturePaneArgs` always adds `-S`. The cursor line rides the
- * SAME tmux invocation (see `watch-link/capture-route.ts` for why, and for the measured exact-target
+ * SAME tmux invocation (see `capture-route.ts` for why, and for the measured exact-target
* spelling). Every piece that the REMOTE shell would otherwise read is single-quoted: tmux's `;`
* separator (bare, it would end the tmux command and run `display-message` as a shell command), the
* `=name:` target and the `#{…}` format. Proven under a real /bin/sh in capture-visible.realsh.test.ts.
diff --git a/src/core/watch-link/control-input.test.ts b/src/core/watch-link/control-input.test.ts
index 9aaa4fa2b..e9d655087 100644
--- a/src/core/watch-link/control-input.test.ts
+++ b/src/core/watch-link/control-input.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import type { ControlInputChunk } from './pane-input'
+import type { ControlInputChunk } from '../pane-input'
import {
PASTE_END,
PASTE_MAX,
diff --git a/src/core/watch-link/control-input.ts b/src/core/watch-link/control-input.ts
index 13e57c422..3ef813910 100644
--- a/src/core/watch-link/control-input.ts
+++ b/src/core/watch-link/control-input.ts
@@ -30,7 +30,7 @@
// newline a command run in the shell. A dropped input that ENDS in a start-marker prefix keeps that
// prefix, marked dropped: completed by the next input it opens a paste that is discarded whole;
// not completed, it is dropped (never typed, never drained).
-import type { ControlInputChunk } from './pane-input'
+import type { ControlInputChunk } from '../pane-input'
export const PASTE_START = '\x1b[200~'
export const PASTE_END = '\x1b[201~'
diff --git a/src/core/watch-link/link-host.test.ts b/src/core/watch-link/link-host.test.ts
index f3546330c..ffbd13e70 100644
--- a/src/core/watch-link/link-host.test.ts
+++ b/src/core/watch-link/link-host.test.ts
@@ -55,11 +55,11 @@ import {
type WatchPty
} from './link-host'
import type { HostTokenResult } from './api'
-import { unavailableCapture, type VisibleCapture } from './capture-route'
+import { unavailableCapture, type VisibleCapture } from '../capture-route'
import { hashControlPassword, verifyControlPassword, type ControlPasswordHash } from './password'
import type { WatchLinkControlRecord, WatchLinkRecord } from './store'
import type { UiSink } from '../ui-sink-registry'
-import type { ControlInputChunk, WatcherInputRoute } from './pane-input'
+import type { ControlInputChunk, WatcherInputRoute } from '../pane-input'
import { PASTE_END, PASTE_START, TYPING_WINDOW_MS } from './control-input'
import type { HistoryRead } from './history'
import type { ChatMessage } from '../../shared/types'
diff --git a/src/core/watch-link/link-host.ts b/src/core/watch-link/link-host.ts
index 0e9053e47..ea7c641c4 100644
--- a/src/core/watch-link/link-host.ts
+++ b/src/core/watch-link/link-host.ts
@@ -168,9 +168,9 @@ import {
type WatchMeta
} from '../../shared/watch-link/protocol'
import type { HostTokenResult } from './api'
-import { unavailableCapture, type VisibleCapture } from './capture-route'
+import { unavailableCapture, type VisibleCapture } from '../capture-route'
import { createInputSplitter, createTypingTracker, type InputSplitter } from './control-input'
-import { PANE_INPUT_DEADLINE_MS, WATCHER_INPUT_ROUTES, type ControlInputChunk, type WatcherInputRoute } from './pane-input'
+import { PANE_INPUT_DEADLINE_MS, WATCHER_INPUT_ROUTES, type ControlInputChunk, type WatcherInputRoute } from '../pane-input'
import { isTerminalReport } from '../terminal-reports'
import { createStreamFilter, type StreamFilter } from './stream-filter'
import { historyPageFrom, type HistoryRead } from './history'
diff --git a/src/core/watch-link/watcher-client.ts b/src/core/watch-link/watcher-client.ts
index b815c654e..0dadb6e64 100644
--- a/src/core/watch-link/watcher-client.ts
+++ b/src/core/watch-link/watcher-client.ts
@@ -29,7 +29,7 @@
//
// Client flags (`-f`) need tmux 3.2. Locally the version is probed (`supportsWatcherClient`) and an
// older or unreadable one refuses the watcher; over SSH the remote tmux rejects the flags itself.
-import { capturePaneTarget } from './capture-route'
+import { capturePaneTarget } from '../capture-route'
export const WATCHER_CLIENT_FLAGS = 'ignore-size,read-only'
diff --git a/src/main/remote/host-service.ts b/src/main/remote/host-service.ts
index 2035e210a..50aa03139 100644
--- a/src/main/remote/host-service.ts
+++ b/src/main/remote/host-service.ts
@@ -58,7 +58,7 @@ import { parseRelayKeys } from '../../core/relay-keys'
import { parseRelayLaunch, type RelayLaunchRequest } from '../../core/relay-launch'
import { browseHostDirectory, isWithinRootsFor, type BrowseFs } from '../../core/remote/host-fs-rpc'
import { stripAnsi } from '../../core/transcript-reader'
-import type { VisibleCapture } from '../../core/watch-link/capture-route'
+import type { VisibleCapture } from '../../core/capture-route'
import { resumeRepaintText } from '../../shared/capture-paint'
// Default relay endpoint; `NODETERM_RELAY_URL` overrides it (mirrors license.ts's API_BASE /
diff --git a/src/renderer/components/LiveChatDrawer.tsx b/src/renderer/components/LiveChatDrawer.tsx
index 180283ce2..f6ebe22fa 100644
--- a/src/renderer/components/LiveChatDrawer.tsx
+++ b/src/renderer/components/LiveChatDrawer.tsx
@@ -7,7 +7,8 @@ import { isTopDialog, nextDialogId, popDialog, pushDialog } from './dialog-stack
import { ControlHold, ControlSection, hasChat, kickViewer, type ControlHoldKind } from './LiveLinkControls'
import { IconClose, IconPin } from './icons'
import { CHAT_NOT_SENT_MESSAGE, kickNote, ROLE_NAME, statusLine, viewerName, waitingViewers } from '../lib/liveLink'
-import { chatClock, chatNameColor, nearBottom, newMessagesLabel } from '../lib/liveChatLook'
+import { chatClock, chatNameColor, nearBottom } from '../lib/liveChatLook'
+import { newMessagesLabel } from '../lib/chatLabels'
import { chatLinkOptionLabels, inLiveChatDrawer, LIVE_CHAT_DRAWER_ATTR, pickChatLink } from '../lib/liveChatPin'
import { useLinkThread, useWatchLinks } from '../state/watchLinks'
diff --git a/src/renderer/components/LiveLinkChip.test.tsx b/src/renderer/components/LiveLinkChip.test.tsx
index 902501a9d..a7c281585 100644
--- a/src/renderer/components/LiveLinkChip.test.tsx
+++ b/src/renderer/components/LiveLinkChip.test.tsx
@@ -4,7 +4,8 @@ import { createRoot, type Root } from 'react-dom/client'
import { renderToStaticMarkup } from 'react-dom/server'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { WatchChatMessage, WatchLinkView } from '@shared/watch-link-types'
-import { LiveLinkChip, projectSessionSource, showsLiveLinks } from './LiveLinkChip'
+import { LiveLinkChip, showsLiveLinks } from './LiveLinkChip'
+import { projectSessionSource } from '../lib/projectSessionSource'
import { useWatchLinks } from '../state/watchLinks'
import { useBoardLog } from '../state/boardLog'
import { useProjects } from '../state/projects'
diff --git a/src/renderer/components/LiveLinkChip.tsx b/src/renderer/components/LiveLinkChip.tsx
index db50851b4..c9bce4947 100644
--- a/src/renderer/components/LiveLinkChip.tsx
+++ b/src/renderer/components/LiveLinkChip.tsx
@@ -1,6 +1,6 @@
import { memo, useCallback, useEffect, useState } from 'react'
import { chipView } from '../lib/liveLink'
-import { sessionForProject, type SessionSource } from '../session/session'
+import type { SessionSource } from '../session/session'
import { EMPTY_LINKS, liveChipSig, useWatchLinks } from '../state/watchLinks'
import { LiveLinkPopover, type PopoverAnchor } from './LiveLinkPopover'
@@ -15,20 +15,6 @@ export function showsLiveLinks(source: SessionSource | null): boolean {
return source === 'local'
}
-/**
- * The source of the session a project's surfaces are viewed through — for the surfaces that know a
- * project id but sit outside that project's `SessionProvider` (the boards, the sessions sidebar).
- * Null when no session resolves (a registry with no session at all, e.g. a unit test), which
- * `showsLiveLinks` reads as "do not show".
- */
-export function projectSessionSource(projectId: string): SessionSource | null {
- try {
- return sessionForProject(projectId).source
- } catch {
- return null
- }
-}
-
/**
* "This terminal is being broadcast." ONE component on the canvas node header, the kanban card, the
* card modal header and the sessions sidebar row, so one session seen four times speaks with one
diff --git a/src/renderer/components/SessionsSidebar.tsx b/src/renderer/components/SessionsSidebar.tsx
index 65518ac7c..200db978b 100644
--- a/src/renderer/components/SessionsSidebar.tsx
+++ b/src/renderer/components/SessionsSidebar.tsx
@@ -21,7 +21,7 @@ import {
} from '../lib/sessionList'
import { sidebarEmptyState, sidebarFilterKeyAction } from '../lib/sidebarFilter'
import { SessionRow } from './SessionRow'
-import { projectSessionSource } from './LiveLinkChip'
+import { projectSessionSource } from '../lib/projectSessionSource'
import { ProjectGlyph } from './ProjectGlyph'
import { ClosedHistorySection } from './ClosedHistorySection'
import { IconBellFilled, IconCircleCheck, IconClose, IconPin } from './icons'
diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsx
index 4aa0a07f6..e0ca269b6 100644
--- a/src/renderer/components/kanban/CardModal.tsx
+++ b/src/renderer/components/kanban/CardModal.tsx
@@ -26,7 +26,8 @@ import { normalizeNodeIcon, type NodeIcon } from '@shared/node-icon'
import { ContextMeter } from '../ContextMeter'
import { isRemoteSessionNode } from '@shared/worktree'
import { AccountChip, useAccountChip } from '../AccountChip'
-import { LiveLinkChip, projectSessionSource } from '../LiveLinkChip'
+import { LiveLinkChip } from '../LiveLinkChip'
+import { projectSessionSource } from '../../lib/projectSessionSource'
import { useWatchLinks } from '../../state/watchLinks'
import { liveLinkUnavailable } from '../../lib/liveLinkEntry'
import { isBrowserRuntime } from '@renderer/bridge/runtime'
diff --git a/src/renderer/components/kanban/GlobalKanbanView.tsx b/src/renderer/components/kanban/GlobalKanbanView.tsx
index 4c3bd1d0e..261311913 100644
--- a/src/renderer/components/kanban/GlobalKanbanView.tsx
+++ b/src/renderer/components/kanban/GlobalKanbanView.tsx
@@ -12,7 +12,7 @@ import {
} from '../../lib/kanban'
import { KanbanColumn, type KanbanLane } from './KanbanColumn'
import { SessionCard } from './SessionCard'
-import { projectSessionSource } from '../LiveLinkChip'
+import { projectSessionSource } from '../../lib/projectSessionSource'
import { toKanbanSessionState } from '../../canvas/toKanbanSessionState'
import { createAgentNode, createBrowserNode, createStickyNode, createTerminalNode, flowToNodeStates, resolveNewNodeAccount } from '../../state/workspace'
import { markCanvasCovered } from '../../lib/canvasCovered'
diff --git a/src/renderer/components/kanban/KanbanView.tsx b/src/renderer/components/kanban/KanbanView.tsx
index 2a3b31be7..ab178dbe6 100644
--- a/src/renderer/components/kanban/KanbanView.tsx
+++ b/src/renderer/components/kanban/KanbanView.tsx
@@ -31,7 +31,7 @@ import { labelSwatch } from '../../lib/kanbanLabelColors'
import { CardModal } from './CardModal'
import { KanbanColumn, type KanbanLane } from './KanbanColumn'
import { SessionCard } from './SessionCard'
-import { projectSessionSource } from '../LiveLinkChip'
+import { projectSessionSource } from '../../lib/projectSessionSource'
import { GitHubIssueCard } from './GitHubIssueCard'
import { GitHubPullCard } from './GitHubPullCard'
import { kanbanSource, sourceVisible } from '../../lib/kanbanSources'
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index 8013bd4a6..529e32426 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -59,7 +59,7 @@ import { fileLinkDialect } from '../../terminal/file-link-dialect'
import { hostPlatformFor } from '../../terminal/host-platform'
import { sshFs } from '../../terminal/ssh-fs'
import { cardFileLinkRoute } from '../../lib/cardFileLinks'
-import { projectSessionSource } from '../LiveLinkChip'
+import { projectSessionSource } from '../../lib/projectSessionSource'
import type { LocalFileTarget } from './LocalFilePreviewModal'
import type { FsApi } from '@shared/types'
import { urlLinkMenuItems } from '../../terminal/link-menu'
diff --git a/src/renderer/components/settings/sections/LiveLinksSection.tsx b/src/renderer/components/settings/sections/LiveLinksSection.tsx
index d639f7924..5e5321922 100644
--- a/src/renderer/components/settings/sections/LiveLinksSection.tsx
+++ b/src/renderer/components/settings/sections/LiveLinksSection.tsx
@@ -5,7 +5,8 @@ import { Button } from '@renderer/ui/Button'
import { CopyButton } from '@renderer/ui/CopyButton'
import { isBrowserRuntime } from '@renderer/bridge/runtime'
import { ConfirmDialog } from '../../ConfirmDialog'
-import { projectSessionSource, showsLiveLinks } from '../../LiveLinkChip'
+import { showsLiveLinks } from '../../LiveLinkChip'
+import { projectSessionSource } from '../../../lib/projectSessionSource'
import { useEntitlement } from '../../../state/entitlement'
import { useProjects } from '../../../state/projects'
import { useWatchLinks } from '../../../state/watchLinks'
diff --git a/src/renderer/lib/chatLabels.test.ts b/src/renderer/lib/chatLabels.test.ts
new file mode 100644
index 000000000..f1c76b936
--- /dev/null
+++ b/src/renderer/lib/chatLabels.test.ts
@@ -0,0 +1,10 @@
+import { describe, expect, it } from 'vitest'
+import { newMessagesLabel } from './chatLabels'
+
+describe('newMessagesLabel', () => {
+ it('the pill label', () => {
+ expect(newMessagesLabel(1)).toBe('1 new message')
+ expect(newMessagesLabel(4)).toBe('4 new messages')
+ expect(newMessagesLabel(140)).toBe('99+ new messages')
+ })
+})
diff --git a/src/renderer/lib/chatLabels.ts b/src/renderer/lib/chatLabels.ts
new file mode 100644
index 000000000..38ccd1a78
--- /dev/null
+++ b/src/renderer/lib/chatLabels.ts
@@ -0,0 +1,4 @@
+/** The "N new messages ↓" pill a chat thread shows while the reader is scrolled up. */
+export function newMessagesLabel(n: number): string {
+ return n === 1 ? '1 new message' : `${n > 99 ? '99+' : n} new messages`
+}
diff --git a/src/renderer/lib/liveChatLook.test.ts b/src/renderer/lib/liveChatLook.test.ts
index fd980bcd6..a6338d8e0 100644
--- a/src/renderer/lib/liveChatLook.test.ts
+++ b/src/renderer/lib/liveChatLook.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
-import { chatClock, chatNameColor, nearBottom, NEAR_BOTTOM_PX, newMessagesLabel, VIEWER_NAME_COLORS } from './liveChatLook'
+import { chatClock, chatNameColor, nearBottom, NEAR_BOTTOM_PX, VIEWER_NAME_COLORS } from './liveChatLook'
describe('the viewer page\'s chat look, copied (nodeterm-web src/lib/watch-viewer/chat-panel.ts)', () => {
it('the same name gets the same colour as on the viewer page (FNV-1a over UTF-16 units)', () => {
@@ -21,12 +21,6 @@ describe('the viewer page\'s chat look, copied (nodeterm-web src/lib/watch-viewe
expect(nearBottom({ scrollTop: 567, clientHeight: 400, scrollHeight: 1000 })).toBe(false)
})
- it('the pill label', () => {
- expect(newMessagesLabel(1)).toBe('1 new message')
- expect(newMessagesLabel(4)).toBe('4 new messages')
- expect(newMessagesLabel(140)).toBe('99+ new messages')
- })
-
it('chatClock: a time the page cannot read is nothing', () => {
expect(chatClock(Number.NaN)).toBe('')
expect(chatClock('1' as unknown as number)).toBe('')
diff --git a/src/renderer/lib/liveChatLook.ts b/src/renderer/lib/liveChatLook.ts
index b3de8b9cd..d51d860bc 100644
--- a/src/renderer/lib/liveChatLook.ts
+++ b/src/renderer/lib/liveChatLook.ts
@@ -44,7 +44,3 @@ export function chatClock(at: unknown, locale?: string): string {
if (typeof at !== 'number' || !Number.isFinite(at)) return ''
return new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: '2-digit' }).format(at)
}
-
-export function newMessagesLabel(n: number): string {
- return n === 1 ? '1 new message' : `${n > 99 ? '99+' : n} new messages`
-}
diff --git a/src/renderer/lib/projectSessionSource.test.ts b/src/renderer/lib/projectSessionSource.test.ts
new file mode 100644
index 000000000..0698b62e5
--- /dev/null
+++ b/src/renderer/lib/projectSessionSource.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it, vi } from 'vitest'
+
+vi.mock('../session/session', () => ({
+ sessionForProject: (id: string) => {
+ if (id === 'p-none') throw new Error('no session')
+ return { source: id === 'p-relay' ? 'relay' : 'local' }
+ }
+}))
+
+import { projectSessionSource } from './projectSessionSource'
+
+describe('projectSessionSource', () => {
+ it('a project resolves through its session', () => {
+ expect(projectSessionSource('p-local')).toBe('local')
+ expect(projectSessionSource('p-relay')).toBe('relay')
+ })
+
+ it('no session resolves to null, never a throw', () => {
+ expect(projectSessionSource('p-none')).toBeNull()
+ })
+})
diff --git a/src/renderer/lib/projectSessionSource.ts b/src/renderer/lib/projectSessionSource.ts
new file mode 100644
index 000000000..1eb68130a
--- /dev/null
+++ b/src/renderer/lib/projectSessionSource.ts
@@ -0,0 +1,14 @@
+import { sessionForProject, type SessionSource } from '../session/session'
+
+/**
+ * The source of the session a project's surfaces are viewed through — for the surfaces that know a
+ * project id but sit outside that project's `SessionProvider` (the boards, the sessions sidebar).
+ * Null when no session resolves (a registry with no session at all, e.g. a unit test).
+ */
+export function projectSessionSource(projectId: string): SessionSource | null {
+ try {
+ return sessionForProject(projectId).source
+ } catch {
+ return null
+ }
+}
diff --git a/src/renderer/nodes/ChatPanel.tsx b/src/renderer/nodes/ChatPanel.tsx
index b1e16928d..abb40f057 100644
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@ -36,7 +36,7 @@ import {
import { E_UNSUPPORTED } from '@shared/rpc'
import { GROK_AMBIGUOUS_SESSION_MESSAGE, isGrokAmbiguousSessionError } from '@shared/chat-page'
import { Spinner } from '../components/Spinner'
-import { newMessagesLabel } from '../lib/liveChatLook'
+import { newMessagesLabel } from '../lib/chatLabels'
import {
CHAT_LIVE_RELOAD_MIN_MS,
CHAT_OPTIMISTIC_WORKING_MS,