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 right-hand side pane for todos, the last diff and changed files (#198)
Abdurrahman Fakhrul358646cd67d3
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex ee217024..ef443caf 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -8,7 +8,8 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh**Added**-- `tui` mouse wheel scrolling and tab clicks, only inside the alternate screen+- `tui` a right-hand side pane for todos, the last diff and changed files+- `tui` mouse wheel scrolling and tab clicks, only inside the alternate screen (#197)- `tui` a transcript viewport with a scrollbar, so the alternate screen has a reason (#193)- `tui` an alternate screen behind a flag, with teardown on every exit path (#192)- `tui` a tab row and a footer that stay put, painted through the frame writer (#191)diff --git a/docs/TUI-RENDERER-PLAN.md b/docs/TUI-RENDERER-PLAN.mdindex 15212a3a..bffcdbfd 100644--- a/docs/TUI-RENDERER-PLAN.md+++ b/docs/TUI-RENDERER-PLAN.md@@ -595,7 +595,7 @@ those two, and mouse/scrollbar/splits are additive after M5.| M5 | Alternate screen behind a flag, with teardown | DONE | PR #192; default off; teardown on exit, signals, execve, spawnSync || M6 | Transcript viewport and scrollbar | DONE | PR #193; 2000-line cap, follow mode, PgUp/PgDn/Ctrl+G/End, entrypoint 218 to 196 lines || M7 | Mouse | DONE | SGR 1000/1006 extended mode, wheel scrolls viewport, tab clicks switch session |-| M8 | Split panes, then flip the alt screen default | NOT STARTED | needs M6 and M7 |+| M8 | Split panes, then flip the alt screen default | IN PROGRESS | panel landed, default flip NOT done |Adjacent work that landed while this plan was being executed, and belongs to the same goal:`feat/agent-jobs-view` (#183, `/jobs` for background subagents) and `feat/tui-keybinds` (#182,diff --git a/scripts/mso-agent-cmd-session.mjs b/scripts/mso-agent-cmd-session.mjsindex ea7d264d..9a95846f 100644--- a/scripts/mso-agent-cmd-session.mjs+++ b/scripts/mso-agent-cmd-session.mjs@@ -12,6 +12,7 @@ import { clearTodos, formatTodoBlock, latestTodos } from "./mso-agent-todos.mjs"import { handleKeybindCommand } from "./mso-agent-keybinds.mjs";import { visibleSessionRows } from "./mso-agent-sessions.mjs";import { tabsToSwitch } from "./mso-agent-chrome.mjs";+import { cyclePane, paneKinds } from "./mso-agent-pane.mjs";export async function handleTodos(ctx, args = []) {const { C: colors = C } = ctx;@@ -64,10 +65,33 @@ export async function handleTabs(ctx, args = []) {return "refresh";}+export async function handlePane(ctx, args = []) {+ const { session, C: colors = C } = ctx;+ const kinds = paneKinds();+ if (!args.length) {+ const current = session?.paneKind || "off";+ const next = cyclePane(current);+ if (session) session.paneKind = next;+ console.log(`${colors.c || ""}side pane: ${next}${colors.reset || ""}`);+ return "handled";+ }+ const requested = String(args[0]).toLowerCase();+ if (kinds.includes(requested)) {+ if (session) session.paneKind = requested;+ console.log(`${colors.c || ""}side pane: ${requested}${colors.reset || ""}`);+ return "handled";+ }+ console.log(`usage: /pane [todos|diff|files|off] (current: ${session?.paneKind || "off"})`);+ return "handled";+}+export async function handleSessionCommand(ctx, cmd, args) {if (cmd === "/todos") {return handleTodos(ctx, args);}+ if (cmd === "/pane") {+ return handlePane(ctx, args);+ }if (cmd === "/keybind" || cmd === "/keybinds") {return handleKeybindCommand(ctx, args);}diff --git a/scripts/mso-agent-help.mjs b/scripts/mso-agent-help.mjsindex cfe4e667..833ca7f0 100644--- a/scripts/mso-agent-help.mjs+++ b/scripts/mso-agent-help.mjs@@ -14,6 +14,7 @@ export const HELP_LINES = [" /context alias for /status"," /diff [ref] [--full] show diff viewer panel for artifact write action"," /todos [--all] show session checklist from todo_write",+ " /pane [kind] cycle or set side pane (todos, diff, files, off)"," /keybind [sub] view keybindings (sub: reset, conflicts)"," /compact force context compaction and archive history"," /statusbar [on|off] toggle compact dynamic status line",diff --git a/scripts/mso-agent-pane.mjs b/scripts/mso-agent-pane.mjsnew file mode 100644index 00000000..55095646--- /dev/null+++ b/scripts/mso-agent-pane.mjs@@ -0,0 +1,193 @@+import { border, paneRow } from "./tui/cells.mjs";+import { latestTodos } from "./mso-agent-todos.mjs";+import { parseEditResult } from "./mso-agent-edit-diff.mjs";++const KINDS = ["todos", "diff", "files", "off"];++export function paneKinds() {+ return [...KINDS];+}++export function cyclePane(kind) {+ const idx = KINDS.indexOf(kind);+ return idx === -1 ? KINDS[0] : KINDS[(idx + 1) % KINDS.length];+}++// Side pane width: floor 30 preserves readability; ceiling 50 avoids crowding+// the transcript; fraction 0.35 reserves roughly two thirds for the transcript.+export function paneWidth(columns, { minColumns = 100 } = {}) {+ const cols = Number(columns) || 0;+ if (cols < minColumns) return 0;+ return Math.max(30, Math.min(50, Math.floor(cols * 0.35)));+}++function resolveTodos(todos, session) {+ if (todos != null) return todos;+ if (session?.todos != null) return session.todos;+ return latestTodos();+}++function resolveDiff(lastDiff, session) {+ if (lastDiff != null) return lastDiff;+ if (session?.lastDiff != null) return session.lastDiff;+ const history = Array.isArray(session?.history) ? session.history : (session?.agentSession?.history || []);+ for (let i = history.length - 1; i >= 0; i -= 1) {+ const row = history[i];+ if (!row || typeof row !== "object") continue;+ const results = Array.isArray(row.results) ? row.results : (row.result != null || row.content != null ? [row] : []);+ for (const res of results) {+ const parsed = parseEditResult(res?.content ?? res);+ if (parsed) return parsed;+ }+ }+ return null;+}++function resolveFiles(files, session) {+ if (Array.isArray(files) && files.length > 0) return files;+ if (Array.isArray(session?.changedFiles) && session.changedFiles.length > 0) return session.changedFiles;+ const history = Array.isArray(session?.history) ? session.history : (session?.agentSession?.history || []);+ const seen = new Set(), list = [];+ for (const row of history) {+ if (!row || typeof row !== "object") continue;+ if (Array.isArray(row.toolUses)) {+ for (const call of row.toolUses) {+ if (["fs_edit", "fs_write", "fs_replace"].includes(String(call?.name || "")) && call?.input?.path) {+ const p = String(call.input.path);+ if (!seen.has(p)) { seen.add(p); list.push(p); }+ }+ }+ }+ const results = Array.isArray(row.results) ? row.results : (row.result != null || row.content != null ? [row] : []);+ for (const res of results) {+ const parsed = parseEditResult(res?.content ?? res);+ if (parsed?.path && !seen.has(String(parsed.path))) {+ seen.add(String(parsed.path));+ list.push(String(parsed.path));+ }+ }+ }+ return list;+}++function formatKindContent({ kind, session, todos, lastDiff, files }) {+ if (kind === "todos") {+ const state = resolveTodos(todos, session);+ const items = Array.isArray(state?.items) ? state.items : [];+ if (!items.length && !state?.summary) return { title: "Todos", emptyText: "no todos in this session", rows: [] };+ const rows = items.map((it) => ({+ text: it.status === "completed" ? `[x] ${it.content}` : it.status === "in_progress" ? `[~] ${it.activeForm || it.content}` : `[ ] ${it.content}`,+ tone: it.status === "completed" ? "dim" : it.status === "in_progress" ? "active" : "normal",+ }));+ if (state?.summary && typeof state.summary.count === "number" && typeof state.summary.completed === "number") {+ rows.push({ text: `${state.summary.completed}/${state.summary.count} done`, tone: "dim" });+ }+ return { title: "Todos", emptyText: null, rows };+ }++ if (kind === "diff") {+ const diffObj = resolveDiff(lastDiff, session);+ if (!diffObj || typeof diffObj.diff !== "string") return { title: "Last edit diff", emptyText: "no edits in this session", rows: [] };+ const raw = diffObj.diff.replace(/\r/g, "");+ const diffLines = raw.endsWith("\n") ? raw.slice(0, -1).split("\n") : (raw ? raw.split("\n") : []);+ if (!diffLines.length) return { title: "Last edit diff", emptyText: "no edits in this session", rows: [] };+ const base = (diffObj.path ? diffObj.path.split(/[/\\]/).filter(Boolean).pop() : null) || "file";+ const rows = [{ text: `edit ${base}`, tone: "header" }];+ for (const dl of diffLines) {+ const tone = dl.startsWith("+") ? "add" : dl.startsWith("-") ? "del" : dl.startsWith("@@") ? "hunk" : "normal";+ rows.push({ text: dl, tone });+ }+ return { title: "Last edit diff", emptyText: null, rows };+ }++ if (kind === "files") {+ const fileList = resolveFiles(files, session);+ if (!fileList.length) return { title: "Changed files", emptyText: "no changed files", rows: [] };+ return { title: "Changed files", emptyText: null, rows: fileList.map((f) => ({ text: f, tone: "normal" })) };+ }++ return { title: "Pane off", emptyText: "pane is off", rows: [] };+}++function styleTone(line, tone, { colors, cDim, cCyan, cErr, cBlue, cBold }) {+ if (!colors || Object.keys(colors).length === 0) return line;+ const reset = colors.reset || "";+ if (tone === "dim" && cDim) return `${cDim}${line}${reset}`;+ if ((tone === "active" || tone === "add") && cCyan) return `${cCyan}${line}${reset}`;+ if (tone === "del" && cErr) return `${cErr}${line}${reset}`;+ if (tone === "hunk" && cBlue) return `${cBlue}${line}${reset}`;+ if (tone === "header" && cBold) return `${cBold}${line}${reset}`;+ return line;+}++/**+ * @param {{+ * kind?: string,+ * session?: any,+ * todos?: any,+ * lastDiff?: any,+ * files?: any,+ * colors?: any,+ * width?: number,+ * rows?: number,+ * }} [options]+ */+export function paneLines({+ kind = "todos",+ session = null,+ todos = null,+ lastDiff = null,+ files = null,+ colors = {},+ width = 40,+ rows = 24,+} = {}) {+ const r = Math.max(0, Number(rows) || 0), w = Math.max(0, Number(width) || 0);+ if (r === 0 || w === 0) return [];+ if (w <= 2) return Array.from({ length: r }, () => (w === 1 ? "│" : "││"));++ const widths = [w - 2], hasColors = Boolean(colors && Object.keys(colors).length > 0);+ const palette = {+ colors,+ cDim: hasColors ? (colors.dim || "") : "",+ cReset: hasColors ? (colors.reset || "") : "",+ cBold: hasColors ? (colors.bold || "") : "",+ cCyan: hasColors ? (colors.cyan || colors.c || "") : "",+ cErr: hasColors ? (colors.err || "") : "",+ cBlue: hasColors ? (colors.blue || "") : "",+ };++ const { title, emptyText, rows: contentRows } = formatKindContent({ kind, session, todos, lastDiff, files });+ const topBorder = palette.cDim ? `${palette.cDim}${border(widths, "top")}${palette.cReset}` : border(widths, "top");+ const midBorder = palette.cDim ? `${palette.cDim}${border(widths, "mid")}${palette.cReset}` : border(widths, "mid");+ const botBorder = palette.cDim ? `${palette.cDim}${border(widths, "bottom")}${palette.cReset}` : border(widths, "bottom");+ const titleRow = palette.cBold ? `${palette.cBold}${paneRow([title], widths)}${palette.cReset}` : paneRow([title], widths);++ if (r === 1) return [titleRow];+ if (r === 2) return [topBorder, botBorder];+ if (r === 3) return [topBorder, titleRow, botBorder];+ if (r === 4) {+ const row = emptyText+ ? styleTone(paneRow([`(${emptyText})`], widths), "dim", palette)+ : (contentRows[0] ? styleTone(paneRow([contentRows[0].text], widths), contentRows[0].tone, palette) : paneRow([""], widths));+ return [topBorder, titleRow, row, botBorder];+ }++ const bodySlots = r - 4, out = [topBorder, titleRow, midBorder];+ if (emptyText) {+ const line = paneRow([`(${emptyText})`], widths);+ out.push(palette.cDim ? `${palette.cDim}${line}${palette.cReset}` : line);+ for (let i = 1; i < bodySlots; i += 1) out.push(paneRow([""], widths));+ } else {+ for (let i = 0; i < bodySlots; i += 1) {+ if (i < contentRows.length) {+ const item = contentRows[i];+ out.push(styleTone(paneRow([item.text], widths), item.tone, palette));+ } else {+ out.push(paneRow([""], widths));+ }+ }+ }+ out.push(botBorder);+ return out;+}diff --git a/scripts/mso-agent-pane.test.ts b/scripts/mso-agent-pane.test.tsnew file mode 100644index 00000000..8fe3d44d--- /dev/null+++ b/scripts/mso-agent-pane.test.ts@@ -0,0 +1,172 @@+import { describe, expect, it } from "vitest";+import { cellWidth, stripAnsi } from "./tui/cells.mjs";+import { cyclePane, paneKinds, paneLines, paneWidth } from "./mso-agent-pane.mjs";+import { mountScreenLoop } from "./mso-agent-screen-loop.mjs";+import { handleSessionCommand } from "./mso-agent-cmd-session.mjs";++describe("mso-agent-pane", () => {+ it("cyclePane wraps through every kind and handles unknown fallback", () => {+ const kinds = paneKinds();+ expect(kinds).toEqual(["todos", "diff", "files", "off"]);+ expect(cyclePane("todos")).toBe("diff");+ expect(cyclePane("diff")).toBe("files");+ expect(cyclePane("files")).toBe("off");+ expect(cyclePane("off")).toBe("todos");+ expect(cyclePane("unknown")).toBe("todos");+ });++ it("paneWidth returns 0 below the minimum and a sane value above it", () => {+ expect(paneWidth(60)).toBe(0);+ expect(paneWidth(80)).toBe(0);+ expect(paneWidth(99)).toBe(0);+ expect(paneWidth(100)).toBe(35);+ expect(paneWidth(120)).toBe(42);+ expect(paneWidth(160)).toBe(50);+ expect(paneWidth(200)).toBe(50);+ });++ it("each kind renders exactly rows lines and no line exceeds width, including CJK at boundary", () => {+ const sampleData = {+ todos: { items: [{ content: "テスト内容の日本語テキスト境界確認", status: "in_progress" }] },+ lastDiff: { path: "src/日本語.ts", diff: "--- a\n+++ b\n@@ -1 +1 @@\n-旧コード\n+新コード境界値確認\n" },+ files: ["src/日本語ファイル名テスト.ts", "lib/main.mjs"],+ };++ for (const kind of paneKinds()) {+ for (const w of [30, 42, 50]) {+ for (const r of [1, 2, 3, 4, 10, 20]) {+ const lines = paneLines({+ kind,+ todos: sampleData.todos,+ lastDiff: sampleData.lastDiff,+ files: sampleData.files,+ width: w,+ rows: r,+ });+ expect(lines.length).toBe(r);+ for (const line of lines) {+ expect(cellWidth(line)).toBeLessThanOrEqual(w);+ expect(cellWidth(line)).toBe(w);+ }+ }+ }+ }+ });++ it("verifies CJK character right at cell boundary never exceeds width", () => {+ // Width 12 has inner cell width 10. Placing a 2-cell CJK character across boundary.+ const trickyLines = paneLines({+ kind: "files",+ files: ["123456789日本語テスト"],+ width: 12,+ rows: 6,+ });+ expect(trickyLines.length).toBe(6);+ for (const line of trickyLines) {+ expect(cellWidth(line)).toBe(12);+ }+ });++ it("an empty kind shows the nothing here line instead of blank", () => {+ const todosEmpty = paneLines({ kind: "todos", todos: { items: [] }, width: 35, rows: 8 });+ const todosText = todosEmpty.map((l) => stripAnsi(l)).join("\n");+ expect(todosText).toContain("no todos in this session");++ const diffEmpty = paneLines({ kind: "diff", lastDiff: null, width: 35, rows: 8 });+ const diffText = diffEmpty.map((l) => stripAnsi(l)).join("\n");+ expect(diffText).toContain("no edits in this session");++ const filesEmpty = paneLines({ kind: "files", files: [], width: 35, rows: 8 });+ const filesText = filesEmpty.map((l) => stripAnsi(l)).join("\n");+ expect(filesText).toContain("no changed files");++ const offEmpty = paneLines({ kind: "off", width: 35, rows: 8 });+ const offText = offEmpty.map((l) => stripAnsi(l)).join("\n");+ expect(offText).toContain("pane is off");+ });++ it("no ANSI when no palette is passed", () => {+ const kinds = paneKinds();+ for (const kind of kinds) {+ const lines = paneLines({+ kind,+ width: 40,+ rows: 8,+ colors: {},+ todos: { items: [{ content: "clean", status: "completed" }] },+ });+ for (const line of lines) {+ expect(line.includes("\x1b")).toBe(false);+ expect(stripAnsi(line)).toBe(line);+ }+ }+ });++ it("with the loop disabled, zero writes", () => {+ const writes: string[] = [];+ const fakeStdout = {+ isTTY: true,+ columns: 120,+ rows: 24,+ write(chunk: string) {+ writes.push(chunk);+ },+ on() {},+ off() {},+ };+ const fakeStdin = {+ emit() { return true; },+ };++ const session = {+ history: [{ role: "user", text: "hello" }],+ paneKind: "todos",+ };++ const loop = mountScreenLoop({+ session,+ enabled: false,+ output: fakeStdout as any,+ input: fakeStdin as any,+ });++ expect(loop.active).toBe(false);+ expect(writes.length).toBe(0);++ loop.paint();+ expect(writes.length).toBe(0);++ loop.sync();+ expect(writes.length).toBe(0);++ loop.dispose();+ expect(writes.length).toBe(0);+ });++ it("dispatches /pane to cycle kinds and set specific kind", async () => {+ const session: any = { paneKind: "off" };+ const logs: string[] = [];+ const origLog = console.log;+ console.log = (msg: string) => { logs.push(msg); };++ try {+ const ctx = { session, C: {} };+ // Cycle from off to todos+ const r1 = await handleSessionCommand(ctx, "/pane", []);+ expect(r1).toBe("handled");+ expect(session.paneKind).toBe("todos");++ // Set specific kind+ const r2 = await handleSessionCommand(ctx, "/pane", ["diff"]);+ expect(r2).toBe("handled");+ expect(session.paneKind).toBe("diff");++ // Invalid kind shows usage+ const r3 = await handleSessionCommand(ctx, "/pane", ["invalid"]);+ expect(r3).toBe("handled");+ expect(logs[logs.length - 1]).toContain("usage: /pane");+ } finally {+ console.log = origLog;+ }+ });+});diff --git a/scripts/mso-agent-screen-loop.mjs b/scripts/mso-agent-screen-loop.mjsindex 64613b72..16a783d6 100644--- a/scripts/mso-agent-screen-loop.mjs+++ b/scripts/mso-agent-screen-loop.mjs@@ -13,6 +13,7 @@ import {setLines,} from "./mso-agent-viewport.mjs";import { renderViewport } from "./mso-agent-viewport-render.mjs";+import { paneLines, paneWidth } from "./mso-agent-pane.mjs";// Rows kept below the panel for the composer prompt. The composer paints its own rows and cannot// report them back, so the panel reserves a fixed block instead of guessing per repaint.@@ -83,16 +84,21 @@ export function mountScreenLoop({const panel = [hasSep ? separator : "", ...chrome].filter((line) => line.length > 0);const viewRows = Math.max(0, rows - panel.length - PROMPT_ROWS);const tabRowY = viewRows + (hasSep ? 1 : 0);- return { cols, rows, panel, viewRows, tabRowY };+ 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 };};// 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 { cols, panel, viewRows } = geometry();- const body = renderViewport(viewport, { colors, width: cols, rows: viewRows });- const frame = [...body, ...panel, ""];+ const { panel, viewRows, pWidth, transWidth, 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 frame = [...joined, ...panel, ""];output.write("\x1b[H");painted = writeFrame(output, painted, frame);output.write(`\x1b[${frame.length};1H`);@@ -100,7 +106,7 @@ export function mountScreenLoop({const sync = () => {commitStream(viewport);- setLines(viewport, transcriptLines(session, { colors, width: output.columns || 80 }));+ setLines(viewport, transcriptLines(session, { colors, width: geometry().transWidth }));paint();};@@ -115,7 +121,7 @@ export function mountScreenLoop({const onResize = () => {viewport.rows = output.rows || 24;- paint();+ sync();};output.on?.("resize", onResize);@@ -176,7 +182,7 @@ export function mountScreenLoop({};}- setLines(viewport, transcriptLines(session, { colors, width: output.columns || 80 }));+ setLines(viewport, transcriptLines(session, { colors, width: geometry().transWidth }));paint();return {