Skip to content

armgit / mso

Public Imported from GitHub
0

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.

feat(tui): mcp and context pane kinds, with an honest unknown (#225)

Abdurrahman Fakhrul139e63c5f293
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 82d36c31..fa9d58b9 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` /terminal hands the real terminal to a shell or a one-shot command
+- `tui` mcp and context pane kinds, with an honest unknown
+- `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)
- `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)
diff --git a/scripts/mso-agent-pane-context.mjs b/scripts/mso-agent-pane-context.mjs
new file mode 100644
index 00000000..635e3506
--- /dev/null
+++ b/scripts/mso-agent-pane-context.mjs
@@ -0,0 +1,112 @@
+import { contextStatus, statusParts } from "./mso-agent-status.mjs";
+
+function compactTokens(value) {
+ const n = Number(value || 0);
+ if (!Number.isFinite(n) || n <= 0) return "0";
+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}m`;
+ if (n >= 1_000) return `${(n / 1_000).toFixed(n >= 10_000 ? 0 : 1)}k`;
+ return String(Math.round(n));
+}
+
+// Renders context usage bar when window limit is known; returns null when unknown
+// so the caller can display a question mark instead of an invented percentage.
+export function renderProportionBar(percent, width = 12) {
+ if (percent == null || !Number.isFinite(percent)) return null;
+ const p = Math.max(0, Math.min(100, Math.round(percent)));
+ const barWidth = Math.max(4, Number(width) || 12);
+ const filled = Math.max(0, Math.min(barWidth, Math.round((p / 100) * barWidth)));
+ const unfilled = barWidth - filled;
+ return `[${"█".repeat(filled)}${"░".repeat(unfilled)}] ${p}%`;
+}
+
+function resolveMcpServers(mcpServers, session) {
+ if (Array.isArray(mcpServers)) return mcpServers;
+ if (Array.isArray(session?.mcpServers)) return session.mcpServers;
+ if (Array.isArray(session?.state?.mcpServers)) return session.state.mcpServers;
+ if (Array.isArray(session?.mcp)) return session.mcp;
+ if (Array.isArray(session?.state?.mcp)) return session.state.mcp;
+ return [];
+}
+
+// MCP pane renders one row per server with name and tool count, dimmed when down.
+export function formatMcpContent({ session, mcpServers }) {
+ const servers = resolveMcpServers(mcpServers, session);
+ if (!servers.length) {
+ return { title: "MCP", emptyText: "no MCP servers", rows: [] };
+ }
+ const rows = servers.map((server) => {
+ const name = String(server?.name || server?.id || "server");
+ const count = typeof server?.toolCount === "number"
+ ? server.toolCount
+ : (Array.isArray(server?.tools)
+ ? server.tools.length
+ : (typeof server?.tools === "number" ? server.tools : 0));
+ const isDown = Boolean(
+ server?.error ||
+ server?.isError ||
+ server?.connected === false ||
+ server?.status === "disconnected" ||
+ server?.status === "error" ||
+ server?.status === "errored" ||
+ server?.state === "disconnected" ||
+ server?.state === "error"
+ );
+ const countLabel = count === 1 ? "1 tool" : `${count} tools`;
+ // Dimming alone is not enough: with a bare palette the line looked identical to a connected
+ // server, so a user reading the pane could not tell a broken MCP server from a healthy one.
+ return {
+ text: isDown ? `${name} (offline)` : `${name} (${countLabel})`,
+ tone: isDown ? "dim" : "normal",
+ };
+ });
+ return { title: "MCP", emptyText: null, rows };
+}
+
+// Context pane shows active provider/model, token usage, turns, and proportion bar.
+export function formatContextContent({ session }) {
+ // Call statusParts to reuse the established status calculations.
+ statusParts(session);
+ const cfg = session?.state?.config || {};
+ const provider = String(cfg.provider || "none");
+ const model = String(cfg.model || "none");
+ const history = Array.isArray(session?.history)
+ ? session.history
+ : (Array.isArray(session?.agentSession?.history) ? session.agentSession.history : []);
+ const ctx = contextStatus(history, session?.state?.modelMeta);
+ // history is the durable transcript, but a session that has run turns carries the provider's own
+ // accounting in usage. Prefer the larger of the two: showing ~0 tokens next to a live model that
+ // just billed 47k is the kind of number that teaches the user to distrust the pane.
+ const reported = Number(session?.usage?.totalTokens ?? session?.usage?.promptTokens ?? 0) || 0;
+ if (reported > ctx.used) ctx.used = reported;
+ const turns = history.filter((row) => row?.role === "user").length || Number(session?.usage?.apiCalls || 0);
+
+ const rows = [];
+ rows.push({ text: `${provider}/${model}`, tone: "header" });
+
+ if (ctx.limit) {
+ rows.push({
+ text: `tokens: ~${compactTokens(ctx.used)} / ${compactTokens(ctx.limit)}`,
+ tone: "normal",
+ });
+ const bar = renderProportionBar(ctx.percent, 12);
+ rows.push({ text: `bar: ${bar}`, tone: "normal" });
+ } else {
+ // Window limit is unknown; render ? without inventing a percentage.
+ rows.push({ text: `tokens: ~${compactTokens(ctx.used)} / ?`, tone: "normal" });
+ rows.push({ text: "bar: ?", tone: "dim" });
+ }
+
+ rows.push({ text: `turns: ${turns}`, tone: "normal" });
+
+ // If system tokens are explicitly recorded, show breakdown without guessing.
+ if (typeof session?.systemTokens === "number") {
+ rows.push({
+ text: `system: ~${compactTokens(session.systemTokens)} · history: ~${compactTokens(ctx.used)}`,
+ tone: "dim",
+ });
+ } else {
+ rows.push({ text: `history: ~${compactTokens(ctx.used)} stored`, tone: "dim" });
+ }
+
+ return { title: "Context", emptyText: null, rows };
+}
diff --git a/scripts/mso-agent-pane-kinds.test.ts b/scripts/mso-agent-pane-kinds.test.ts
new file mode 100644
index 00000000..6f7d3911
--- /dev/null
+++ b/scripts/mso-agent-pane-kinds.test.ts
@@ -0,0 +1,154 @@
+import { describe, expect, it } from "vitest";
+import { cellWidth, stripAnsi } from "./tui/cells.mjs";
+import { cyclePane, paneKinds, paneLines } from "./mso-agent-pane.mjs";
+
+describe("mso-agent-pane-kinds", () => {
+ it("paneKinds() includes all five and cyclePane walks every one and wraps", () => {
+ const kinds = paneKinds();
+ expect(kinds).toContain("todos");
+ expect(kinds).toContain("diff");
+ expect(kinds).toContain("files");
+ expect(kinds).toContain("mcp");
+ expect(kinds).toContain("context");
+ expect(kinds).toEqual(["todos", "diff", "files", "mcp", "context", "off"]);
+
+ expect(cyclePane("todos")).toBe("diff");
+ expect(cyclePane("diff")).toBe("files");
+ expect(cyclePane("files")).toBe("mcp");
+ expect(cyclePane("mcp")).toBe("context");
+ expect(cyclePane("context")).toBe("off");
+ expect(cyclePane("off")).toBe("todos");
+ expect(cyclePane("unknown")).toBe("todos");
+ });
+
+ it("mcp with two connected servers renders one line each with the tool counts, exactly rows lines total, no line wider than width", () => {
+ const mcpServers = [
+ { name: "github", toolCount: 12 },
+ { name: "filesystem", tools: 4 },
+ ];
+ const width = 42;
+ const rows = 10;
+ const lines = paneLines({
+ kind: "mcp",
+ mcpServers,
+ width,
+ rows,
+ });
+ expect(lines.length).toBe(rows);
+ for (const line of lines) {
+ expect(cellWidth(line)).toBe(width);
+ }
+ const text = lines.map((l) => stripAnsi(l)).join("\n");
+ expect(text).toContain("github (12 tools)");
+ expect(text).toContain("filesystem (4 tools)");
+ });
+
+ it("mcp with none renders the empty-state line, not blank rows above the border", () => {
+ const lines = paneLines({
+ kind: "mcp",
+ mcpServers: [],
+ width: 40,
+ rows: 8,
+ });
+ expect(lines.length).toBe(8);
+ for (const line of lines) {
+ expect(cellWidth(line)).toBe(40);
+ }
+ const text = lines.map((l) => stripAnsi(l)).join("\n");
+ expect(text).toContain("(no MCP servers)");
+ });
+
+ it("context with a known window renders the proportion bar and the token count; with an unknown window renders ? and no invented percentage", () => {
+ const sessionWithWindow = {
+ state: {
+ config: { provider: "anthropic", model: "claude-3-5-sonnet" },
+ modelMeta: { context: 100_000 },
+ },
+ history: [
+ { role: "user", text: "hello".repeat(200) },
+ ],
+ };
+
+ const linesKnown = paneLines({
+ kind: "context",
+ session: sessionWithWindow,
+ width: 42,
+ rows: 10,
+ });
+ expect(linesKnown.length).toBe(10);
+ const textKnown = linesKnown.map((l) => stripAnsi(l)).join("\n");
+ expect(textKnown).toMatch(/tokens:\s*~\d+/);
+ expect(textKnown).toContain("100k");
+ expect(textKnown).toMatch(/bar:\s*\[[█░]+\]\s*\d+%/);
+
+ const sessionWithoutWindow = {
+ state: {
+ config: { provider: "custom", model: "unknown-model" },
+ modelMeta: null,
+ },
+ history: [
+ { role: "user", text: "hello".repeat(200) },
+ ],
+ };
+
+ const linesUnknown = paneLines({
+ kind: "context",
+ session: sessionWithoutWindow,
+ width: 42,
+ rows: 10,
+ });
+ expect(linesUnknown.length).toBe(10);
+ const textUnknown = linesUnknown.map((l) => stripAnsi(l)).join("\n");
+ expect(textUnknown).toContain("tokens: ~");
+ expect(textUnknown).toContain("/ ?");
+ expect(textUnknown).toContain("bar: ?");
+ expect(textUnknown).not.toContain("%");
+ });
+
+ it("context on a fresh session with no usage does not throw and still renders exactly rows lines", () => {
+ const freshSessions = [
+ {},
+ { state: null, history: [] },
+ { state: {}, history: [] },
+ null,
+ ];
+
+ for (const session of freshSessions) {
+ for (const r of [1, 2, 3, 4, 8, 20]) {
+ let lines: string[] = [];
+ expect(() => {
+ lines = paneLines({
+ kind: "context",
+ session,
+ width: 40,
+ rows: r,
+ });
+ }).not.toThrow();
+ expect(lines.length).toBe(r);
+ for (const line of lines) {
+ expect(cellWidth(line)).toBe(40);
+ }
+ }
+ }
+ });
+
+ it("a CJK character in a server name does not push the line past width", () => {
+ const cjkServers = [
+ { name: "データベース管理サーバー日本語テスト", toolCount: 8 },
+ { name: "API連携", toolCount: 1 },
+ ];
+
+ for (const w of [30, 35, 42, 50]) {
+ const lines = paneLines({
+ kind: "mcp",
+ mcpServers: cjkServers,
+ width: w,
+ rows: 8,
+ });
+ expect(lines.length).toBe(8);
+ for (const line of lines) {
+ expect(cellWidth(line)).toBe(w);
+ }
+ }
+ });
+});
diff --git a/scripts/mso-agent-pane.mjs b/scripts/mso-agent-pane.mjs
index 55095646..559920a2 100644
--- a/scripts/mso-agent-pane.mjs
+++ b/scripts/mso-agent-pane.mjs
@@ -1,8 +1,9 @@
import { border, paneRow } from "./tui/cells.mjs";
import { latestTodos } from "./mso-agent-todos.mjs";
import { parseEditResult } from "./mso-agent-edit-diff.mjs";
+import { formatContextContent, formatMcpContent } from "./mso-agent-pane-context.mjs";
-const KINDS = ["todos", "diff", "files", "off"];
+const KINDS = ["todos", "diff", "files", "mcp", "context", "off"];
export function paneKinds() {
return [...KINDS];
@@ -70,7 +71,7 @@ function resolveFiles(files, session) {
return list;
}
-function formatKindContent({ kind, session, todos, lastDiff, files }) {
+function formatKindContent({ kind, session, todos, lastDiff, files, mcpServers }) {
if (kind === "todos") {
const state = resolveTodos(todos, session);
const items = Array.isArray(state?.items) ? state.items : [];
@@ -106,6 +107,14 @@ function formatKindContent({ kind, session, todos, lastDiff, files }) {
return { title: "Changed files", emptyText: null, rows: fileList.map((f) => ({ text: f, tone: "normal" })) };
}
+ if (kind === "mcp") {
+ return formatMcpContent({ session, mcpServers });
+ }
+
+ if (kind === "context") {
+ return formatContextContent({ session });
+ }
+
return { title: "Pane off", emptyText: "pane is off", rows: [] };
}
@@ -127,6 +136,7 @@ function styleTone(line, tone, { colors, cDim, cCyan, cErr, cBlue, cBold }) {
* todos?: any,
* lastDiff?: any,
* files?: any,
+ * mcpServers?: any,
* colors?: any,
* width?: number,
* rows?: number,
@@ -138,6 +148,7 @@ export function paneLines({
todos = null,
lastDiff = null,
files = null,
+ mcpServers = null,
colors = {},
width = 40,
rows = 24,
@@ -157,7 +168,14 @@ export function paneLines({
cBlue: hasColors ? (colors.blue || "") : "",
};
- const { title, emptyText, rows: contentRows } = formatKindContent({ kind, session, todos, lastDiff, files });
+ const { title, emptyText, rows: contentRows } = formatKindContent({
+ kind,
+ session,
+ todos,
+ lastDiff,
+ files,
+ mcpServers,
+ });
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");
diff --git a/scripts/mso-agent-pane.test.ts b/scripts/mso-agent-pane.test.ts
index 8fe3d44d..d5d595b6 100644
--- a/scripts/mso-agent-pane.test.ts
+++ b/scripts/mso-agent-pane.test.ts
@@ -7,10 +7,10 @@ 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(kinds).toEqual(["todos", "diff", "files", "mcp", "context", "off"]);
expect(cyclePane("todos")).toBe("diff");
expect(cyclePane("diff")).toBe("files");
- expect(cyclePane("files")).toBe("off");
+ expect(cyclePane("files")).toBe("mcp");
expect(cyclePane("off")).toBe("todos");
expect(cyclePane("unknown")).toBe("todos");
});