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
fix(tui): an approval prompt must leave the alternate screen, or it is erased before it is read (#213)
Abdurrahman Fakhrulcbe0af970e95
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 738d74b1..042907a9 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -8,21 +8,14 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh**Added**+- `ci` three security scanners that actually run, and lanes that fail closed (#210)- `tui` the panel is the default, and the banner lives in the transcript (#209)-**Fixed**--- `docs` regenerate the changelog after the date rolled over--**Docs**--- `contributing` how to run the CI work locally before opening a PR-- `gates` the green full run, and the parallel-run trap-## 2026-10-31**Added**+- `tui` a suspended panel really leaves the alternate screen, so an approval is readable- `tui` install the print sink the last change forgot, and migrate the modules that still print (#206)- `tui` a suspended panel really leaves the alternate screen, so an approval is readable (#205)- `tui` mid-turn writes go into the panel, and prompts suspend it instead of fighting it (#204)diff --git a/scripts/mso-agent-input-hook.mjs b/scripts/mso-agent-input-hook.mjsindex 881346f3..df2a3396 100644--- a/scripts/mso-agent-input-hook.mjs+++ b/scripts/mso-agent-input-hook.mjs@@ -6,7 +6,8 @@ import { parseMouseChunk } from "./mso-agent-mouse.mjs";// nothing else, so the screen loop stays under the line ratchet.export function installInputHook({ input, onKey, onMouse }) {const originalEmit = input.emit;- if (typeof originalEmit !== "function") return { dispose() {} };+ if (typeof originalEmit !== "function") return { dispose() {}, setEnabled() {} };+ let enabled = true;const consumeMouse = (payload) => {const events = parseMouseChunk(payload);@@ -16,6 +17,9 @@ export function installInputHook({ input, onKey, onMouse }) {};input.emit = function patchedEmit(event, ...args) {+ // A suspension hands the terminal to a line oriented prompt, so the panel must stop consuming+ // keys and mouse sequences until it comes back, or the prompt would silently lose them.+ if (!enabled) return Reflect.apply(originalEmit, this, [event, ...args]);if (event === "data" && args[0]) {const chunk = typeof args[0] === "string" ? args[0] : (args[0] instanceof Buffer ? args[0].toString("utf8") : "");if (chunk.includes("\x1b[<")) {@@ -37,6 +41,7 @@ export function installInputHook({ input, onKey, onMouse }) {};return {+ setEnabled(next) { enabled = next; },dispose() {input.emit = originalEmit;},diff --git a/scripts/mso-agent-panel-suspend.mjs b/scripts/mso-agent-panel-suspend.mjsnew file mode 100644index 00000000..2d42690f--- /dev/null+++ b/scripts/mso-agent-panel-suspend.mjs@@ -0,0 +1,53 @@+import { disableMouse, enableMouse } from "./mso-agent-mouse.mjs";+import { enterScreen, leaveScreen } from "./mso-agent-altscreen.mjs";++/**+ * A line oriented prompt needs the terminal to itself, so the panel LEAVES the alternate screen for+ * the duration. Detaching the sink alone is not enough: the prompt would be painted into the+ * alternate buffer, where the next repaint overwrites it, so the user would answer a question that+ * vanished before they could read it. Leaving gives the prompt the normal screen and its own+ * scrollback, and resume re-enters and repaints.+ *+ * Building an in-panel input mode instead would mean a second implementation of the composer's key+ * handling, which is the ceiling this deliberately accepts.+ *+ * @param {{+ * session: any,+ * output: any,+ * hook?: { setEnabled?: (on: boolean) => void } | null,+ * onRepaint: () => void,+ * onReset: () => void,+ * }} options+ */+export function createPanelSuspension({ session, output, hook = null, onRepaint, onReset }) {+ let savedSink = null;+ let suspended = false;++ const suspend = () => {+ if (suspended) return;+ suspended = true;+ if (session?.streamSink) {+ savedSink = session.streamSink;+ delete session.streamSink;+ }+ hook?.setEnabled?.(false);+ disableMouse(output);+ leaveScreen(output);+ };++ const resume = () => {+ if (!suspended) return;+ suspended = false;+ enterScreen(output);+ enableMouse(output);+ hook?.setEnabled?.(true);+ if (savedSink) {+ session.streamSink = savedSink;+ savedSink = null;+ }+ onReset();+ onRepaint();+ };++ return { suspend, resume, isSuspended: () => suspended };+}diff --git a/scripts/mso-agent-panel-suspend.test.ts b/scripts/mso-agent-panel-suspend.test.tsnew file mode 100644index 00000000..90b8e680--- /dev/null+++ b/scripts/mso-agent-panel-suspend.test.ts@@ -0,0 +1,134 @@+import { EventEmitter } from "node:events";+import { describe, expect, it } from "vitest";+import { ENTER_SEQUENCE, LEAVE_SEQUENCE, enterScreen } from "./mso-agent-altscreen.mjs";+import { MOUSE_OFF, MOUSE_ON, enableMouse } from "./mso-agent-mouse.mjs";+import { createPanelSuspension } from "./mso-agent-panel-suspend.mjs";++function fakeOutput() {+ const chunks: string[] = [];+ const output = new EventEmitter();+ Object.assign(output, {+ columns: 80,+ rows: 24,+ isTTY: true,+ write(value: string) {+ chunks.push(String(value));+ return true;+ },+ });+ return { output, chunks, all: () => chunks.join("") };+}++describe("panel suspension owns the terminal while a prompt runs", () => {+ it("leaves the alternate screen, or the prompt would be painted where the panel overwrites it", () => {+ const { output, all } = fakeOutput();+ const session: any = { streamSink: { write() {} } };+ enterScreen(output);++ const suspension = createPanelSuspension({ session, output, onRepaint() {}, onReset() {} });+ suspension.suspend();++ expect(all()).toContain(LEAVE_SEQUENCE);+ expect(session.streamSink).toBeUndefined();+ });++ it("turns mouse reporting off and the input hook off for the duration", () => {+ const { output, all } = fakeOutput();+ const session: any = { streamSink: { write() {} } };+ const toggles: boolean[] = [];+ enterScreen(output);+ // Mouse is idempotent, so it only writes the off sequence if it was on: enable it first, which+ // is also what the screen loop does when the panel opens.+ enableMouse(output);++ const suspension = createPanelSuspension({+ session,+ output,+ hook: { setEnabled: (on: boolean) => toggles.push(on) },+ onRepaint() {},+ onReset() {},+ });++ suspension.suspend();+ expect(toggles).toEqual([false]);+ expect(all()).toContain(MOUSE_OFF);++ suspension.resume();+ expect(toggles).toEqual([false, true]);+ expect(all()).toContain(MOUSE_ON);+ });++ it("re-enters, restores the sink and repaints exactly once on resume", () => {+ const { output, all } = fakeOutput();+ const sink = { write() {} };+ const session: any = { streamSink: sink };+ let repaints = 0;+ let resets = 0;+ enterScreen(output);++ const suspension = createPanelSuspension({+ session,+ output,+ onRepaint: () => { repaints += 1; },+ onReset: () => { resets += 1; },+ });++ suspension.suspend();+ suspension.resume();++ expect(session.streamSink).toBe(sink);+ expect(repaints).toBe(1);+ expect(resets).toBe(1);+ expect(all().split(ENTER_SEQUENCE).length - 1).toBe(2);+ });++ it("is idempotent in both directions, because a prompt can be nested in a retry", () => {+ const { output, all } = fakeOutput();+ const session: any = { streamSink: { write() {} } };+ let repaints = 0;+ enterScreen(output);++ const suspension = createPanelSuspension({+ session,+ output,+ onRepaint: () => { repaints += 1; },+ onReset() {},+ });++ suspension.suspend();+ suspension.suspend();+ expect(all().split(LEAVE_SEQUENCE).length - 1).toBe(1);++ suspension.resume();+ suspension.resume();+ expect(repaints).toBe(1);+ expect(suspension.isSuspended()).toBe(false);+ });++ it("resume without a suspend does nothing at all", () => {+ const { output, chunks } = fakeOutput();+ const session: any = { streamSink: { write() {} } };+ let repaints = 0;++ const suspension = createPanelSuspension({+ session,+ output,+ onRepaint: () => { repaints += 1; },+ onReset() {},+ });++ suspension.resume();+ expect(chunks).toEqual([]);+ expect(repaints).toBe(0);+ });++ it("survives a session with no sink and no hook, because both are optional in tests", () => {+ const { output, all } = fakeOutput();+ enterScreen(output);+ const suspension = createPanelSuspension({ session: {}, output, onRepaint() {}, onReset() {} });++ expect(() => { suspension.suspend(); suspension.resume(); }).not.toThrow();+ expect(all()).toContain(LEAVE_SEQUENCE);+ expect(all()).toContain(ENTER_SEQUENCE);+ });+});diff --git a/scripts/mso-agent-screen-loop.mjs b/scripts/mso-agent-screen-loop.mjsindex 41c92d5f..d72e4018 100644--- a/scripts/mso-agent-screen-loop.mjs+++ b/scripts/mso-agent-screen-loop.mjs@@ -3,6 +3,7 @@ import { chromeLines, tabAtPoint } 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";+import { createPanelSuspension } from "./mso-agent-panel-suspend.mjs";import { writeFrame } from "./mso-agent-screen.mjs";import { transcriptLines } from "./mso-agent-transcript.mjs";import { appendStream, commitStream, createViewport, handleViewportKey, resetFollow, setLines } from "./mso-agent-viewport.mjs";@@ -66,7 +67,6 @@ export function mountScreenLoop({const viewport = createViewport({ rows: output.rows || 24 });let painted = [];let promptReservation = PROMPT_ROWS;- let savedSink = null;const setPromptRows = (rows) => {// When the composer reports its painted row count, clamp it so the panel never jumps on erase@@ -153,22 +153,6 @@ export function mountScreenLoop({return false;};- // A line oriented prompt needs the terminal to itself, so the sink is detached for the duration- // and the panel repaints afterwards. Building an in-panel input mode would mean a second- // implementation of the composer's key handling.- const suspend = () => {- if (!session.streamSink) return;- savedSink = session.streamSink;- delete session.streamSink;- };- const resume = () => {- if (savedSink) {- session.streamSink = savedSink;- savedSink = null;- }- paint();- };-const hook = installInputHook({input,onKey: (key) => {@@ -179,6 +163,12 @@ export function mountScreenLoop({onMouse: (event) => dispatchMouse(event),});+ const panelSuspend = createPanelSuspension({+ session, output, hook, onRepaint: paint, onReset: () => { painted = []; },+ });+ const suspend = panelSuspend.suspend;+ const resume = panelSuspend.resume;+setLines(viewport, withPreamble(preamble?.() ?? null, transcriptLines(session, { colors, width: geometry().transWidth })));paint();