Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
feat(tui): a vertical tab rail, from the same layout the horizontal row uses (#230)
Abdurrahman Fakhrulc63f3359d15f
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 05460dda..27531eb9 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -4,11 +4,17 @@Newest first. `docs/PROGRESS.md` is the source of truth for *why* a change was made;this is the *what*, and it is what Settings → Account → About shows as “What's new”.+## 2026-11-02++**Added**++- `tui` a vertical tab rail, from the same layout the horizontal row uses+## 2026-11-01**Added**-- `tui` /tabs as a table, with real activity and no invented idle+- `tui` /tabs as a table, with real activity and no invented idle (#226)- `tui` mcp and context pane kinds, with an honest unknown (#225)- `tui` /terminal hands the real terminal to a shell or a one-shot command (#224)- `skills` add mso-agent-fleet for Orca + OpenCode fan-out (#217)@@ -1529,20 +1535,3 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh**Docs**- `security` disclose scorecard posture gaps--## 2026-08-29--**Fixed**--- `security` keep path sinks in validated branches-- `security` make root containment explicit-- `security` close follow-up CodeQL flows--**Docs**--- `comparison` use explicit SEO-friendly ratings--**Chores**--- `deps` hold incompatible toolchain majors-- `deps` migrate to lucide-react 1.33.0diff --git a/scripts/mso-agent-chrome.mjs b/scripts/mso-agent-chrome.mjsindex d705c967..0c720e55 100644--- a/scripts/mso-agent-chrome.mjs+++ b/scripts/mso-agent-chrome.mjs@@ -1,91 +1,99 @@import { cellWidth, clean, fitCells } from "./tui/cells.mjs";import { composerFooter } from "./mso-agent-layout.mjs";-/**- * Formats a single physical row containing session tabs and performs hit testing.- * Extracted layout model ensures tabRow and tabAtPoint stay in exact agreement.- */-function makeSegments(itemsList) {+function candidateSplits(kept, total, activeIdx) {+ const splits = [];+ for (let l = 0; l <= kept; l++) {+ const r = kept - l;+ if (activeIdx < 0 || activeIdx < l || r > total - 1 - activeIdx) splits.push(l);+ }+ const all = splits.length ? splits : Array.from({ length: kept + 1 }, (_, i) => i);+ return all.sort((a, b) => Math.abs(a - kept / 2) - Math.abs(b - kept / 2));+}++function makeSegments(itemsList, orientation = "horizontal", maxWidth = 80) {+ if (orientation === "vertical") {+ const contentWidth = Math.max(1, maxWidth - 1);+ return itemsList.map((it, row) => {+ if (!it) return null;+ return {+ type: it.type || "tab",+ id: it.id,+ row,+ start: 0,+ end: Math.min(it.width, contentWidth),+ styled: fitCells(it.styled || it.plainText || "", contentWidth, { pad: false }),+ plainText: it.plainText || it.text || "",+ text: it.text,+ isActive: Boolean(it.isActive),+ };+ }).filter(Boolean);+ }let col = 0;const segments = [];for (const it of itemsList) {if (!it) continue;- segments.push({ type: it.type || "tab", id: it.id, start: col, end: col + it.width, styled: it.styled });+ segments.push({ type: it.type || "tab", id: it.id, start: col, end: col + it.width, styled: it.styled, text: it.text });col += it.width + 2;}return segments;}-export function tabLayout(sessions, activeId = null, { colors = {}, width = 80 } = {}) {+/** @param {Array<any>} sessions @param {string|number|null} [activeId] @param {any} [options] */+export function tabLayout(sessions, activeId = null, { colors = {}, width = 80, rows = null, orientation = "horizontal" } = {}) {if (!Array.isArray(sessions) || sessions.length === 0) {return { segments: [], maxWidth: Math.max(1, Number(width) || 80) };}const maxWidth = Math.max(1, Number(width) || 80);const sep = " ";-- const cBold = colors?.bold || "";- const cBlue = colors?.blue || "";- const cDim = colors?.dim || "";- const cReset = colors?.reset || "";+ const cBold = colors?.bold || "", cBlue = colors?.blue || "", cDim = colors?.dim || "", cReset = colors?.reset || "";const items = sessions.map((s) => {const rawName = clean(s?.name || s?.agentSession?.name || "").replace(/^@/, "");const name = rawName || "agent";const id = String(s?.id || s?.agentSession?.id || "");const isActive = activeId != null && (String(activeId) === id || String(activeId).replace(/^@/, "") === name);- // State marker omitted: single glyph cannot honestly reflect activity without live background signals.const marker = isActive ? "● " : "";const plainText = `${marker}@${name}`;const styled = isActive ? `${cBold}${cBlue}${marker}@${name}${cReset}` : `${cDim}@${name}${cReset}`;return { id, name, isActive, plainText, styled, width: cellWidth(plainText) };});- const fullPlain = items.map((it) => it.plainText).join(sep);- if (cellWidth(fullPlain) <= maxWidth) {- return { segments: makeSegments(items), maxWidth };+ const activeIdx = items.findIndex((it) => it.isActive);++ if (orientation === "vertical") {+ const maxRows = rows != null ? Math.max(0, Number(rows)) : items.length;+ if (maxRows === 0) return { segments: [], maxWidth };+ if (items.length <= maxRows) return { segments: makeSegments(items, "vertical", maxWidth), maxWidth };+ const kept = Math.max(0, maxRows - 1);+ if (kept === 0) {+ const fallback = activeIdx >= 0 ? items[activeIdx] : items[0];+ return { segments: makeSegments([fallback], "vertical", maxWidth), maxWidth };+ }+ const dropped = items.length - kept;+ const markerText = `+${dropped}`;+ const marker = { type: "marker", text: markerText, styled: `${cDim}${markerText}${cReset}`, width: cellWidth(markerText) };+ const l = candidateSplits(kept, items.length, activeIdx)[0] ?? 0;+ const left = items.slice(0, l), right = items.slice(items.length - (kept - l));+ return { segments: makeSegments([...left, marker, ...right], "vertical", maxWidth), maxWidth };}- // Dropping from the middle keeps both endpoints visible while indicating hidden tabs.- const activeIdx = items.findIndex((it) => it.isActive);+ const fullPlain = items.map((it) => it.plainText).join(sep);+ if (cellWidth(fullPlain) <= maxWidth) return { segments: makeSegments(items, "horizontal", maxWidth), maxWidth };for (let dropped = 1; dropped < items.length; dropped++) {const kept = items.length - dropped;const markerText = `+${dropped}`;- const markerStyled = `${cDim}${markerText}${cReset}`;- const markerWidth = cellWidth(markerText);-- // Candidate splits between left and right items.- // When an active tab exists, prefer splits that preserve the active tab.- const candidateSplits = [];- for (let l = 0; l <= kept; l++) {- const r = kept - l;- const preservesActive = activeIdx < 0 || activeIdx < l || r > (items.length - 1 - activeIdx);- if (preservesActive) candidateSplits.push(l);- }- if (candidateSplits.length === 0) {- for (let l = 0; l <= kept; l++) candidateSplits.push(l);- }- candidateSplits.sort((a, b) => Math.abs(a - kept / 2) - Math.abs(b - kept / 2));-- for (const leftCount of candidateSplits) {- const rightCount = kept - leftCount;- const leftItems = items.slice(0, leftCount);- const rightItems = items.slice(items.length - rightCount);-- const candidatePlain = [- ...leftItems.map((it) => it.plainText),- markerText,- ...rightItems.map((it) => it.plainText),- ].filter(Boolean).join(sep);-+ const marker = { type: "marker", text: markerText, styled: `${cDim}${markerText}${cReset}`, width: cellWidth(markerText) };+ for (const leftCount of candidateSplits(kept, items.length, activeIdx)) {+ const leftItems = items.slice(0, leftCount), rightItems = items.slice(items.length - (kept - leftCount));+ const candidatePlain = [...leftItems.map((it) => it.plainText), markerText, ...rightItems.map((it) => it.plainText)].filter(Boolean).join(sep);if (cellWidth(candidatePlain) <= maxWidth) {- const marker = { type: "marker", text: markerText, styled: markerStyled, width: markerWidth };- return { segments: makeSegments([...leftItems, marker, ...rightItems]), maxWidth };+ return { segments: makeSegments([...leftItems, marker, ...rightItems], "horizontal", maxWidth), maxWidth };}}}- // Fallback for extremely constrained terminal widths: show single active or first tab truncated.const fallbackItem = activeIdx >= 0 ? items[activeIdx] : items[0];const truncatedStyled = fitCells(fallbackItem.styled, maxWidth, { pad: false });return {@@ -94,55 +102,61 @@ export function tabLayout(sessions, activeId = null, { colors = {}, width = 80 }};}-/**- * One physical row of session tabs. The active tab is undimmed and bulleted; when the tabs do not- * fit, the middle is dropped with a +N marker rather than wrapping, because a wrapped tab row- * breaks the reserved-row arithmetic the composer depends on.- *- * @param {Array<any>} sessions- * @param {string|number|null} [activeId]- * @param {{ colors?: any, width?: number }} [options]- * @returns {string}- */+/** @param {Array<any>} sessions @param {string|number|null} [activeId] @param {any} [options] */export function tabRow(sessions, activeId = null, options = {}) {const { segments } = tabLayout(sessions, activeId, options);return segments.map((s) => s.styled).join(" ");}-/**- * @param {Array<any>} sessions- * @param {string|number|null} [activeId]- * @param {any} [point]- * @param {any} [options]- * @returns {string|null}- */+// Side rail width: floor 18 preserves readable names; ceiling 26 avoids crowding transcript.+// Returns 0 below 100 columns so narrow terminals keep transcript space just as paneWidth does.+export function tabRailWidth(columns, { minColumns = 100 } = {}) {+ const cols = Number(columns) || 0;+ if (cols < minColumns) return 0;+ return Math.max(18, Math.min(26, Math.floor(cols * 0.18)));+}++/** @param {Array<any>} sessions @param {string|number|null} [activeId] @param {any} [options] */+export function tabRailLines(sessions, activeId = null, options = {}) {+ const { segments, maxWidth } = tabLayout(sessions, activeId, { ...options, orientation: "vertical" });+ const rows = Math.max(0, Number(options?.rows) || segments.length);+ const contentWidth = Math.max(1, maxWidth - 1);+ const colors = options?.colors || {};+ const cBold = colors.bold || "", cBlue = colors.blue || "", cDim = colors.dim || "", cReset = colors.reset || "";+ const borderChar = cDim ? `${cDim}│${cReset}` : "│";+ const lines = [];+ for (let r = 0; r < rows; r++) {+ const seg = segments.find((s) => s.row === r);+ if (!seg) {+ lines.push(" ".repeat(contentWidth) + borderChar);+ continue;+ }+ const plain = fitCells(seg.plainText || "", contentWidth, { pad: false });+ const pad = " ".repeat(Math.max(0, contentWidth - cellWidth(plain)));+ const styled = seg.isActive ? `${cBold}${cBlue}${plain}${cReset}` : (cDim ? `${cDim}${plain}${cReset}` : plain);+ lines.push(styled + pad + borderChar);+ }+ return lines;+}++/** @param {Array<any>} sessions @param {string|number|null} [activeId] @param {any} [point] @param {any} [options] */export function tabAtPoint(sessions, activeId = null, point = {}, options = {}) {- const opts = typeof point === "object" && point !== null ? point : options;+ const opts = typeof point === "object" && point !== null ? { ...options, ...point } : (options || {});const x = typeof point === "number" ? point : Number(opts?.x) || 0;const y = typeof opts?.y === "number" ? opts.y : 0;+ const orientation = opts?.orientation || "horizontal";+ const { segments } = tabLayout(sessions, activeId, opts);+ if (orientation === "vertical") {+ const hit = segments.find((s) => s.type === "tab" && s.row === y && x >= s.start && x < s.end);+ return hit ? hit.id : null;+ }const tabRowY = typeof opts?.tabRow === "number" ? opts.tabRow : (typeof opts?.row === "number" ? opts.row : 0);if (y !== tabRowY) return null;- const { segments } = tabLayout(sessions, activeId, opts);const hit = segments.find((s) => s.type === "tab" && x >= s.start && x < s.end);return hit ? hit.id : null;}-/**- * Builds the bottom chrome block: session tab row plus status footer line.- * Drops the footer first on short terminals (<= 8 rows), and drops both on tiny terminals (<= 6 rows)- * to prevent eating user input lines.- *- * @param {{- * session?: any,- * sessions?: Array<any>,- * activeId?: string|number|null,- * colors?: any,- * width?: number,- * rows?: number|null,- * footer?: any,- * }} [options]- * @returns {Array<string>}- */+/** @param {{ session?: any, sessions?: Array<any>, activeId?: string|number|null, colors?: any, width?: number, rows?: number|null, footer?: any }} [options] */export function chromeLines({session = null,sessions = /** @type {Array<any>} */ ([]),@@ -154,11 +168,8 @@ export function chromeLines({} = {}) {const termRows = rows != null ? Number(rows) : null;if (termRows !== null && termRows <= 6) return [];-const tab = tabRow(sessions, activeId, { colors, width });- if (termRows !== null && termRows <= 8) {- return tab ? [tab] : [];- }+ if (termRows !== null && termRows <= 8) return tab ? [tab] : [];let foot = "";if (footer != null) {@@ -166,51 +177,30 @@ export function chromeLines({} else if (session != null) {foot = String(composerFooter(session, colors, width) || "");}-return [tab, foot].filter((line) => typeof line === "string" && line.trim().length > 0).slice(0, 2);}-/**- * Resolves a target session from a /tabs switch query.- * Supports 1-based index, exact name, exact id, unique prefix name, and unique prefix id.- * Refuses ambiguous matches rather than guessing to avoid accidental state switching.- *- * @param {Array<any>} sessions- * @param {any} args- * @returns {any}- */+/** @param {Array<any>} sessions @param {any} args */export function tabsToSwitch(sessions, args) {if (!Array.isArray(sessions) || sessions.length === 0) return null;const raw = Array.isArray(args) ? args.join(" ").trim() : String(args ?? "").trim();if (!raw) return null;-if (/^\d+$/.test(raw)) {const idx = Number.parseInt(raw, 10);- if (idx >= 1 && idx <= sessions.length) {- return sessions[idx - 1] ?? null;- }- return null;+ return idx >= 1 && idx <= sessions.length ? sessions[idx - 1] ?? null : null;}-const query = raw.toLowerCase().replace(/^@/, "");- const getSessionName = (s) => clean(s?.name || s?.agentSession?.name || "").toLowerCase().replace(/^@/, "");- const getSessionId = (s) => String(s?.id || s?.agentSession?.id || "").toLowerCase();-- const exactNameMatches = sessions.filter((s) => getSessionName(s) === query);- if (exactNameMatches.length === 1) return exactNameMatches[0];- if (exactNameMatches.length > 1) return null;-- const exactIdMatches = sessions.filter((s) => getSessionId(s) === query);- if (exactIdMatches.length === 1) return exactIdMatches[0];- if (exactIdMatches.length > 1) return null;-- const prefixNameMatches = sessions.filter((s) => getSessionName(s).startsWith(query));- if (prefixNameMatches.length === 1) return prefixNameMatches[0];- if (prefixNameMatches.length > 1) return null;-- const prefixIdMatches = sessions.filter((s) => getSessionId(s).startsWith(query));- if (prefixIdMatches.length === 1) return prefixIdMatches[0];- if (prefixIdMatches.length > 1) return null;-+ const getName = (s) => clean(s?.name || s?.agentSession?.name || "").toLowerCase().replace(/^@/, "");+ const getId = (s) => String(s?.id || s?.agentSession?.id || "").toLowerCase();+ for (const match of [+ (s) => getName(s) === query,+ (s) => getId(s) === query,+ (s) => getName(s).startsWith(query),+ (s) => getId(s).startsWith(query),+ ]) {+ const hits = sessions.filter(match);+ if (hits.length === 1) return hits[0];+ if (hits.length > 1) return null;+ }return null;}diff --git a/scripts/mso-agent-screen-loop.mjs b/scripts/mso-agent-screen-loop.mjsindex fde97d27..9b23817e 100644--- a/scripts/mso-agent-screen-loop.mjs+++ b/scripts/mso-agent-screen-loop.mjs@@ -1,5 +1,5 @@import process from "node:process";-import { chromeLines, tabAtPoint } from "./mso-agent-chrome.mjs";+import { chromeLines, tabAtPoint, tabRailLines, tabRailWidth } from "./mso-agent-chrome.mjs";import { composerSeparator } from "./mso-agent-layout.mjs";import { disableMouse, enableMouse, handleMouse } from "./mso-agent-mouse.mjs";import { installInputHook } from "./mso-agent-input-hook.mjs";@@ -26,7 +26,9 @@ export { clampPromptRows, PROMPT_ROWS } from "./mso-agent-composer-ui.mjs";* colors?: any,* getSessions?: () => Array<any>,* onTabClick?: (sessionId: string) => void | Promise<void>,+ * composer?: any,* preamble?: (() => Array<string> | null) | null,+ * tabsLayout?: string | null,* }} options*/export function mountScreenLoop({@@ -39,6 +41,7 @@ export function mountScreenLoop({onTabClick,composer = null,preamble = null,+ tabsLayout = null,} = {}) {if (!enabled || !session) {return {@@ -49,7 +52,7 @@ export function mountScreenLoop({suspend() {},resume() {},follow() {},- geometry() { return { cols: 80, rows: 24, panel: [], viewRows: 0, tabRowY: 0, pWidth: 0, transWidth: 80, kind: null, promptRows: PROMPT_ROWS }; },+ geometry() { return { cols: 80, rows: 24, panel: [], viewRows: 0, tabRowY: 0, pWidth: 0, transWidth: 80, railWidth: 0, kind: null, promptRows: PROMPT_ROWS }; },setPromptRows() {},dispose() {},};@@ -90,27 +93,31 @@ export function mountScreenLoop({const geometry = (reservation = promptReservation) => {const cols = Math.max(20, Number(output.columns) || 80);const rows = Math.max(6, Number(output.rows) || 24);- const chrome = chromeLines({ session, sessions: getSessions(), activeId: session.agentSession?.id, colors, width: cols, rows: null });+ const isVertical = (tabsLayout || session?.tabsLayout || session?.tabLayout) === "vertical";+ const railWidth = isVertical ? tabRailWidth(cols) : 0;+ const chromeSessions = railWidth > 0 ? [] : getSessions();+ const chrome = chromeLines({ session, sessions: chromeSessions, activeId: session.agentSession?.id, colors, width: cols, rows: null });const separator = composerSeparator(session, colors, cols);const hasSep = typeof separator === "string" && separator.length > 0;// The separator belongs to the panel in this mode; the composer is told to draw none.const panel = [hasSep ? separator : "", ...chrome].filter((line) => line.length > 0);const viewRows = Math.max(0, rows - panel.length - reservation);- const tabRowY = viewRows + (hasSep ? 1 : 0);+ const tabRowY = railWidth > 0 ? -1 : viewRows + (hasSep ? 1 : 0);const kind = session?.paneKind && session.paneKind !== "off" ? session.paneKind : null;const pWidth = kind ? paneWidth(cols) : 0;- const transWidth = cols - pWidth;- return { cols, rows, panel, viewRows, tabRowY, pWidth, transWidth, kind, promptRows: reservation };+ const transWidth = cols - pWidth - railWidth;+ return { cols, rows, panel, viewRows, tabRowY, pWidth, transWidth, railWidth, kind, promptRows: reservation };};// Repaints from the top of the screen and leaves the cursor where the composer expects to start,// because the composer paints relative to the cursor and cannot be told where to begin.const paint = () => {if (output?.isTTY !== true) return;- const { panel, viewRows, pWidth, transWidth, kind } = geometry();+ const { panel, viewRows, pWidth, transWidth, railWidth, kind } = geometry();const body = renderViewport(viewport, { colors, width: transWidth, rows: viewRows });const side = pWidth > 0 ? paneLines({ kind, session, colors, width: pWidth, rows: viewRows }) : [];- const joined = pWidth > 0 ? body.map((line, i) => `${line}${side[i] || ""}`) : body;+ const rail = railWidth > 0 ? tabRailLines(getSessions(), session?.agentSession?.id, { colors, width: railWidth, rows: viewRows }) : [];+ const joined = body.map((line, i) => `${rail[i] || ""}${line}${side[i] || ""}`);const frame = [...joined, ...panel, ""];output.write("\x1b[H");painted = writeFrame(output, painted, frame);@@ -142,13 +149,14 @@ export function mountScreenLoop({return false;}if (event.kind === "click") {- const { cols, tabRowY } = geometry();- if (event.y === tabRowY) {- const targetId = tabAtPoint(getSessions(), session?.agentSession?.id, { x: event.x, y: event.y, width: cols, tabRow: tabRowY });- if (targetId && typeof onTabClick === "function") {- Promise.resolve(onTabClick(targetId)).then(paint).catch(() => {});- return true;- }+ const { cols, tabRowY, railWidth, viewRows } = geometry();+ const hitOpts = railWidth > 0+ ? { x: event.x, y: event.y, width: railWidth, rows: viewRows, orientation: "vertical" }+ : { x: event.x, y: event.y, width: cols, tabRow: tabRowY, orientation: "horizontal" };+ const targetId = tabAtPoint(getSessions(), session?.agentSession?.id, hitOpts);+ if (targetId && typeof onTabClick === "function") {+ Promise.resolve(onTabClick(targetId)).then(paint).catch(() => {});+ return true;}return true;}diff --git a/scripts/mso-agent-tabs-rail.mjs b/scripts/mso-agent-tabs-rail.mjsnew file mode 100644index 00000000..16a7d01d--- /dev/null+++ b/scripts/mso-agent-tabs-rail.mjs@@ -0,0 +1,27 @@+// Vertical tab rail layout, kept out of mso-agent-chrome.mjs so that file stays under the line+// ratchet. It is still the SAME layout source: the caller passes the same segment builder, so the+// painted rail and its hit test cannot drift.+import { candidateSplits, makeSegments } from "./mso-agent-chrome.mjs";++/**+ * Split items for a vertical rail of `maxRows` rows, dropping from the middle with a +N marker.+ * @param {Array<any>} items+ * @param {{ maxRows: number, maxWidth: number, activeIdx: number, dim: string, reset: string }} options+ */+export function verticalSegments(items, { maxRows, maxWidth, activeIdx, dim = "", reset = "" }) {+ if (maxRows === 0) return [];+ if (items.length <= maxRows) return makeSegments(items, "vertical", maxWidth);+ const kept = Math.max(0, maxRows - 1);+ if (kept === 0) {+ const fallback = activeIdx >= 0 ? items[activeIdx] : items[0];+ return makeSegments([fallback], "vertical", maxWidth);+ }+ const markerText = `+${items.length - kept}`;+ const marker = { type: "marker", text: markerText, styled: `${dim}${markerText}${reset}`, width: markerText.length };+ const left = candidateSplits(kept, items.length, activeIdx)[0] ?? 0;+ return makeSegments(+ [...items.slice(0, left), marker, ...items.slice(items.length - (kept - left))],+ "vertical",+ maxWidth,+ );+}diff --git a/scripts/mso-agent-tabs-vertical.test.ts b/scripts/mso-agent-tabs-vertical.test.tsnew file mode 100644index 00000000..fe729b13--- /dev/null+++ b/scripts/mso-agent-tabs-vertical.test.ts@@ -0,0 +1,181 @@+import { EventEmitter } from "node:events";+import { describe, expect, it, vi } from "vitest";+import { tabAtPoint, tabLayout, tabRailLines, tabRailWidth, tabRow } from "./mso-agent-chrome.mjs";+import { mountScreenLoop } from "./mso-agent-screen-loop.mjs";+import { cellWidth } from "./tui/cells.mjs";++class FakeOutput extends EventEmitter {+ isTTY = true;+ columns = 80;+ rows = 24;+ chunks: string[] = [];+ write(str: string) {+ this.chunks.push(String(str));+ return true;+ }+}++describe("MSO Agent TUI vertical tab rail", () => {+ const sessions = [+ { id: "s1", name: "alpha" },+ { id: "s2", name: "beta" },+ { id: "s3", name: "gamma" },+ ];++ it("tabLayout with orientation: vertical yields segments that tabAtPoint resolves correctly at every visible cell", () => {+ const { segments } = tabLayout(sessions, "s1", { orientation: "vertical", width: 20, rows: 10 });+ expect(segments).toHaveLength(3);++ for (const seg of segments) {+ if (seg.type === "tab") {+ for (let x = seg.start; x < seg.end; x++) {+ const hit = tabAtPoint(sessions, "s1", { x, y: seg.row, orientation: "vertical", width: 20, rows: 10 });+ expect(hit).toBe(seg.id);+ }+ }+ }++ const horiz = tabLayout(sessions, "s1", { orientation: "horizontal", width: 80 });+ for (const seg of horiz.segments) {+ if (seg.type === "tab") {+ for (let x = seg.start; x < seg.end; x++) {+ const hit = tabAtPoint(sessions, "s1", { x, y: 0, orientation: "horizontal", width: 80, tabRow: 0 });+ expect(hit).toBe(seg.id);+ }+ }+ }+ });++ it("a click on a rail cell switches to that session id", () => {+ const onTabClick = vi.fn();+ const output = new FakeOutput();+ output.columns = 120;+ output.rows = 30;+ const input = new EventEmitter();+ const session: any = { agentSession: { id: "s1", name: "alpha" }, history: [] };++ const loop = mountScreenLoop({+ enabled: true,+ session,+ output: output as never,+ input: input as never,+ getSessions: () => sessions,+ onTabClick,+ tabsLayout: "vertical",+ });++ const geom = loop.geometry();+ expect(geom.railWidth).toBeGreaterThan(0);++ // Beta tab is on row 1 (y=1). Left click at col 3, row 2 in SGR escape syntax is x=2, y=1+ input.emit("data", "\x1b[<0;3;2M");+ expect(onTabClick).toHaveBeenCalledWith("s2");++ loop.dispose();+ });++ it("a click on the rail gutter returns null", () => {+ // Column 19 is the border gutter when rail width is 20+ const gutterHit = tabAtPoint(sessions, "s1", { x: 19, y: 0, orientation: "vertical", width: 20, rows: 10 });+ expect(gutterHit).toBeNull();++ // Far beyond rail width returns null+ const outsideHit = tabAtPoint(sessions, "s1", { x: 25, y: 0, orientation: "vertical", width: 20, rows: 10 });+ expect(outsideHit).toBeNull();++ // In a running loop, a click on the rail border gutter does not trigger tab switch+ const onTabClick = vi.fn();+ const output = new FakeOutput();+ output.columns = 120;+ output.rows = 30;+ const input = new EventEmitter();+ const session: any = { agentSession: { id: "s1", name: "alpha" }, history: [] };++ const loop = mountScreenLoop({+ enabled: true,+ session,+ output: output as never,+ input: input as never,+ getSessions: () => sessions,+ onTabClick,+ tabsLayout: "vertical",+ });++ const geom = loop.geometry();+ // Click on border column x = railWidth - 1 (1-based: railWidth) on row y = 0 (1-based: 1)+ input.emit("data", `\x1b[<0;${geom.railWidth};1M`);+ expect(onTabClick).not.toHaveBeenCalled();++ loop.dispose();+ });++ it("the rail returns zero width below 100 columns", () => {+ // Guards transcript width from rail crowding on narrow terminals+ expect(tabRailWidth(79)).toBe(0);+ expect(tabRailWidth(80)).toBe(0);+ expect(tabRailWidth(99)).toBe(0);+ expect(tabRailWidth(100)).toBeGreaterThan(0);+ expect(tabRailWidth(120)).toBeGreaterThan(0);++ const narrowOut = new FakeOutput();+ narrowOut.columns = 80;+ const session: any = { agentSession: { id: "s1", name: "alpha" }, history: [] };+ const loopNarrow = mountScreenLoop({ enabled: true, session, output: narrowOut as never, tabsLayout: "vertical" });+ expect(loopNarrow.geometry().railWidth).toBe(0);+ loopNarrow.dispose();+ });++ it("overflow drops from the middle with +N and the rail stays within its width", () => {+ const manySessions = [+ { id: "s1", name: "alpha-orchestration-service" },+ { id: "s2", name: "beta-worker-pool-runner" },+ { id: "s3", name: "gamma-analytics-aggregator" },+ { id: "s4", name: "delta-subagent-dispatch" },+ { id: "s5", name: "epsilon-monitoring-probe" },+ ];++ const { segments } = tabLayout(manySessions, "s1", { orientation: "vertical", width: 20, rows: 3 });+ expect(segments).toHaveLength(3);+ expect(segments[0].id).toBe("s1");+ expect(segments[1].type).toBe("marker");+ expect(segments[1].text).toBe("+3");+ expect(segments[2].id).toBe("s5");++ const lines = tabRailLines(manySessions, "s1", { width: 20, rows: 3 });+ expect(lines).toHaveLength(3);+ for (const line of lines) {+ expect(cellWidth(line)).toBe(20);+ }++ // Clicking marker returns null+ expect(tabAtPoint(manySessions, "s1", { x: 1, y: 1, orientation: "vertical", width: 20, rows: 3 })).toBeNull();+ });++ it("horizontal output is unchanged when the option is absent", () => {+ const defaultLayout = tabLayout(sessions, "s1", { width: 80 });+ const explicitLayout = tabLayout(sessions, "s1", { width: 80, orientation: "horizontal" });+ expect(defaultLayout).toEqual(explicitLayout);++ const defaultRow = tabRow(sessions, "s1", { width: 80 });+ const explicitRow = tabRow(sessions, "s1", { width: 80, orientation: "horizontal" });+ expect(defaultRow).toBe(explicitRow);+ expect(defaultRow).toBe("● @alpha @beta @gamma");++ // Disabled loop with rail off writes nothing+ const outDisabled = new FakeOutput();+ const session: any = { agentSession: { id: "s1", name: "alpha" }, history: [] };+ const loopDisabled = mountScreenLoop({ enabled: false, session, output: outDisabled as never });+ loopDisabled.paint();+ expect(outDisabled.chunks).toHaveLength(0);+ loopDisabled.dispose();++ // Baseline horizontal frame is byte-identical whether tabsLayout is omitted or horizontal+ const out1 = new FakeOutput();+ const out2 = new FakeOutput();+ const loop1 = mountScreenLoop({ enabled: true, session, output: out1 as never, getSessions: () => sessions });+ const loop2 = mountScreenLoop({ enabled: true, session, output: out2 as never, getSessions: () => sessions, tabsLayout: "horizontal" });+ expect(out1.chunks).toEqual(out2.chunks);+ loop1.dispose();+ loop2.dispose();+ });+});