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): /tabs as a table, with real activity and no invented idle (#226)

Abdurrahman Fakhrul7fa96877f884
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 949b2eeb..05460dda 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -8,6 +8,7 @@ this is the *what*, and it is what Settings → Account → About shows as “Wh
**Added**
+- `tui` /tabs as a table, with real activity and no invented idle
- `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)
diff --git a/scripts/mso-agent-chrome.mjs b/scripts/mso-agent-chrome.mjs
index 60207d67..d705c967 100644
--- a/scripts/mso-agent-chrome.mjs
+++ b/scripts/mso-agent-chrome.mjs
@@ -33,6 +33,7 @@ export function tabLayout(sessions, activeId = null, { colors = {}, width = 80 }
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}`;
diff --git a/scripts/mso-agent-cmd-session.mjs b/scripts/mso-agent-cmd-session.mjs
index d3133cc4..9f46163e 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 { sessionTable } from "./mso-agent-session-list.mjs";
import { cyclePane, paneKinds } from "./mso-agent-pane.mjs";
import { createPrinter } from "./mso-agent-print.mjs";
@@ -45,18 +46,13 @@ export async function handleTabs(ctx, args = []) {
const { print } = createPrinter(ctx);
const rows = visibleSessionRows(await listCliSessions(20));
if (!args.length) {
- if (!rows.length) {
- print("No active sessions.");
- return "handled";
- }
- print(`${colors.bold || ""}Sessions${colors.reset || ""}`);
- rows.forEach((row, idx) => {
- const isCurrent = String(row.id) === String(session?.agentSession?.id);
- const mark = isCurrent ? `${colors.blue || ""}${colors.bold || ""}●${colors.reset || ""}` : " ";
- const name = `@${row.name || "agent"}`;
- const title = row.title || "MSO Agent session";
- print(` ${mark} ${idx + 1}. ${name} · ${title}${isCurrent ? " (current)" : ""}`);
+ const width = Number(ctx.width || process.stdout.columns) || 80;
+ const lines = sessionTable(rows, {
+ colors,
+ width,
+ activeId: session?.agentSession?.id,
});
+ for (const line of lines) print(line);
return "handled";
}
const target = tabsToSwitch(rows, args);
diff --git a/scripts/mso-agent-session-list.mjs b/scripts/mso-agent-session-list.mjs
new file mode 100644
index 00000000..192fd5ae
--- /dev/null
+++ b/scripts/mso-agent-session-list.mjs
@@ -0,0 +1,170 @@
+import { cellWidth, clean } from "./tui/cells.mjs";
+import { formatSessionModified } from "./mso-agent-sessions.mjs";
+
+// Interactive turns (LLM calls, tool runs) typically complete within 60 seconds.
+// An update timestamp within 60 seconds indicates active execution.
+// Past 60 seconds without updates, the session is considered idle.
+export const ACTIVITY_THRESHOLD_MS = 60_000;
+
+/**
+ * @param {any} row
+ * @param {number} [now]
+ * @returns {{ state: string, label: string }}
+ */
+export function stateOf(row, now = Date.now()) {
+ if (!row || typeof row !== "object") {
+ return { state: "unknown", label: "no activity data" };
+ }
+
+ // Explicit failure or error status takes precedence.
+ if (row.error || ["error", "errored", "failed"].includes(String(row.status || ""))) {
+ return { state: "errored", label: "errored" };
+ }
+
+ // Explicit waiting or prompt-ready state.
+ if (["waiting", "waiting for input"].includes(String(row.status || ""))) {
+ return { state: "waiting", label: "waiting for input" };
+ }
+
+ // Explicit running or busy status flag.
+ if (["working", "busy", "running"].includes(String(row.status || ""))) {
+ return { state: "working", label: "working" };
+ }
+
+ if (row.status === "idle") {
+ return { state: "idle", label: "idle" };
+ }
+
+ // In the absence of an explicit status flag, derive state from the last recorded update.
+ const rawTime = row.updatedAt || row.createdAt;
+ const at = Date.parse(String(rawTime || ""));
+ if (!Number.isFinite(at)) {
+ return { state: "unknown", label: "no activity data" };
+ }
+
+ // Clock skew tolerance: future timestamps are treated as current activity.
+ const diff = Math.max(0, Number(now) - at);
+ if (diff <= ACTIVITY_THRESHOLD_MS) {
+ return { state: "working", label: "working" };
+ }
+ return { state: "idle", label: "idle" };
+}
+
+function stateColor(state, colors = {}) {
+ if (state === "working") return colors.green || "";
+ if (state === "waiting") return colors.yellow || "";
+ if (state === "errored") return colors.red || colors.err || "";
+ if (state === "idle") return colors.dim || "";
+ return colors.dim || "";
+}
+
+function formatCell(text, width) {
+ const cleaned = clean(text);
+ if (width <= 0) return { visible: "", pad: "" };
+ let out = "";
+ let used = 0;
+ for (const ch of cleaned) {
+ const w = cellWidth(ch);
+ if (used + w > width) break;
+ out += ch;
+ used += w;
+ }
+ if (used < cellWidth(cleaned) && width > 0) {
+ while (out && cellWidth(out) > Math.max(0, width - 1)) {
+ out = Array.from(out).slice(0, -1).join("");
+ }
+ out += "…";
+ used = cellWidth(out);
+ }
+ const pad = " ".repeat(Math.max(0, width - used));
+ return { visible: out, pad };
+}
+
+function isSessionActive(row, activeId) {
+ if (activeId == null) return false;
+ const id = String(row?.id || row?.agentSession?.id || "");
+ const name = clean(row?.name || row?.agentSession?.name || "").replace(/^@/, "");
+ return String(activeId) === id || String(activeId).replace(/^@/, "") === name;
+}
+
+/**
+ * @param {Array<any>} rows
+ * @param {{
+ * colors?: Record<string, string>,
+ * width?: number,
+ * activeId?: string | number | null,
+ * now?: number,
+ * }} [options]
+ * @returns {Array<string>}
+ */
+export function sessionTable(rows, { colors = {}, width = 80, activeId = null, now = Date.now() } = {}) {
+ if (!Array.isArray(rows) || rows.length === 0) {
+ return ["No active sessions."];
+ }
+
+ const maxW = Math.max(20, Number(width) || 80);
+ const sep = " ";
+ const sepW = 2;
+ const totalGaps = sepW * 3;
+ const available = Math.max(4, maxW - totalGaps);
+
+ // Allocate column widths proportionally while guaranteeing exact fit within width.
+ const actW = Math.max(6, Math.min(12, Math.floor(available * 0.18)));
+ const stateW = Math.max(8, Math.min(18, Math.floor(available * 0.26)));
+ const nameW = Math.max(8, Math.min(16, Math.floor(available * 0.26)));
+ const titleW = Math.max(4, available - nameW - stateW - actW);
+
+ const cBold = colors?.bold || "";
+ const cBlue = colors?.blue || "";
+ const cDim = colors?.dim || "";
+ const cReset = colors?.reset || "";
+
+ const hName = formatCell(" NAME", nameW);
+ const hTitle = formatCell("TITLE", titleW);
+ const hState = formatCell("STATE", stateW);
+ const hAct = formatCell("ACTIVITY", actW);
+
+ const headerLine = cBold
+ ? `${cBold}${hName.visible}${cReset}${hName.pad}${sep}${cBold}${hTitle.visible}${cReset}${hTitle.pad}${sep}${cBold}${hState.visible}${cReset}${hState.pad}${sep}${cBold}${hAct.visible}${cReset}${hAct.pad}`
+ : `${hName.visible}${hName.pad}${sep}${hTitle.visible}${hTitle.pad}${sep}${hState.visible}${hState.pad}${sep}${hAct.visible}${hAct.pad}`;
+
+ const lines = [headerLine];
+
+ rows.forEach((row, idx) => {
+ const isCurrent = isSessionActive(row, activeId);
+ const mark = isCurrent ? "●" : " ";
+ const rawName = clean(row?.name || "agent").replace(/^@/, "");
+ const nameText = `${mark} ${idx + 1}. @${rawName}`;
+ const titleText = clean(row?.title || "MSO Agent session");
+
+ const stateInfo = stateOf(row, now);
+ // "recently" is the shared helper's word for a missing timestamp, which reads as a claim that
+ // something happened. In an activity column that is exactly the claim we must not make.
+ const stamp = row?.updatedAt || row?.createdAt;
+ const actText = stamp ? formatSessionModified(stamp, now) : "unknown";
+
+ const cellName = formatCell(nameText, nameW);
+ const cellTitle = formatCell(titleText, titleW);
+ const cellState = formatCell(stateInfo.label, stateW);
+ const cellAct = formatCell(actText, actW);
+
+ const sc = stateColor(stateInfo.state, colors);
+
+ const nameStyled = isCurrent && cBold
+ ? `${cBold}${cBlue}${cellName.visible}${cReset}${cellName.pad}`
+ : `${cellName.visible}${cellName.pad}`;
+ const titleStyled = isCurrent && cBold
+ ? `${cBold}${cellTitle.visible}${cReset}${cellTitle.pad}`
+ : `${cellTitle.visible}${cellTitle.pad}`;
+ const stateStyled = sc && cReset
+ ? `${sc}${cellState.visible}${cReset}${cellState.pad}`
+ : `${cellState.visible}${cellState.pad}`;
+ const actStyled = cDim && cReset
+ ? `${cDim}${cellAct.visible}${cReset}${cellAct.pad}`
+ : `${cellAct.visible}${cellAct.pad}`;
+
+ lines.push(`${nameStyled}${sep}${titleStyled}${sep}${stateStyled}${sep}${actStyled}`);
+ });
+
+ return lines;
+}
diff --git a/scripts/mso-agent-session-list.test.ts b/scripts/mso-agent-session-list.test.ts
new file mode 100644
index 00000000..c418cb09
--- /dev/null
+++ b/scripts/mso-agent-session-list.test.ts
@@ -0,0 +1,116 @@
+import { describe, expect, it } from "vitest";
+import { cellWidth, stripAnsi } from "./tui/cells.mjs";
+import {
+ ACTIVITY_THRESHOLD_MS,
+ sessionTable,
+ stateOf,
+} from "./mso-agent-session-list.mjs";
+
+describe("MSO Agent session list table and state derivation", () => {
+ it("renders three rows plus a header within width for three sessions", () => {
+ const sessions = [
+ { id: "s1", name: "eli", title: "First session", updatedAt: new Date().toISOString() },
+ { id: "s2", name: "olive", title: "Second worker", updatedAt: new Date().toISOString() },
+ { id: "s3", name: "milo", title: "Review auditor", updatedAt: new Date().toISOString() },
+ ];
+ const width = 80;
+ const lines = sessionTable(sessions, { width, activeId: "s1" });
+
+ // Expect 1 header line plus 3 session rows.
+ expect(lines).toHaveLength(4);
+ for (const line of lines) {
+ expect(cellWidth(line)).toBeLessThanOrEqual(width);
+ }
+ });
+
+ it("marks the active session once and only once", () => {
+ const sessions = [
+ { id: "s1", name: "eli", title: "First session" },
+ { id: "s2", name: "olive", title: "Second worker" },
+ { id: "s3", name: "milo", title: "Review auditor" },
+ ];
+ const lines = sessionTable(sessions, { activeId: "s2" });
+
+ // Header must not contain the active indicator bullet.
+ expect(lines[0]).not.toContain("●");
+
+ // Exactly one session line contains the active bullet indicator.
+ const markedLines = lines.slice(1).filter((l) => l.includes("●"));
+ expect(markedLines).toHaveLength(1);
+ expect(markedLines[0]).toContain("@olive");
+
+ // The other session lines must not contain the bullet.
+ expect(lines[1]).not.toContain("●");
+ expect(lines[3]).not.toContain("●");
+ });
+
+ it("evaluates boundary conditions for state derivation around threshold", () => {
+ const now = 1_700_000_000_000;
+
+ // Row exactly at the threshold: 60,000 ms elapsed.
+ const exactThresholdRow = {
+ id: "exact",
+ updatedAt: new Date(now - ACTIVITY_THRESHOLD_MS).toISOString(),
+ };
+ const exactState = stateOf(exactThresholdRow, now);
+ expect(exactState.state).toBe("working");
+ expect(exactState.label).toBe("working");
+
+ // Row just past the threshold: 60,001 ms elapsed.
+ const pastThresholdRow = {
+ id: "past",
+ updatedAt: new Date(now - ACTIVITY_THRESHOLD_MS - 1).toISOString(),
+ };
+ const pastState = stateOf(pastThresholdRow, now);
+ expect(pastState.state).toBe("idle");
+ expect(pastState.label).toBe("idle");
+ });
+
+ it("renders documented fallback text for missing or unknown state and never green idle", () => {
+ const now = 1_700_000_000_000;
+ const missingStateRow = { id: "s-unknown", name: "ghost", title: "No timestamp" };
+
+ const state = stateOf(missingStateRow, now);
+ expect(state.state).toBe("unknown");
+ expect(state.label).toBe("no activity data");
+
+ const colors = {
+ green: "\x1b[32m",
+ dim: "\x1b[2m",
+ reset: "\x1b[0m",
+ bold: "\x1b[1m",
+ };
+ const lines = sessionTable([missingStateRow], { colors, width: 80, now });
+ expect(lines).toHaveLength(2);
+
+ const dataRow = lines[1];
+ expect(dataRow).toContain("no activity data");
+ expect(dataRow).not.toContain("idle");
+ // Ensure green is never applied to the fallback text.
+ expect(dataRow).not.toContain(`${colors.green}no activity data`);
+ expect(dataRow).not.toContain(`${colors.green}idle`);
+ });
+
+ it("emits no ANSI escape codes when no colors are passed", () => {
+ const sessions = [
+ { id: "s1", name: "eli", title: "First session", updatedAt: new Date().toISOString() },
+ { id: "s2", name: "olive", title: "Second session", updatedAt: new Date().toISOString() },
+ ];
+ const lines = sessionTable(sessions, { activeId: "s1", width: 80 });
+
+ for (const line of lines) {
+ expect(line).toBe(stripAnsi(line));
+ expect(line).not.toMatch(/\x1b\[/);
+ }
+ });
+
+ it("renders a single clear line when session list is empty", () => {
+ const emptyLines = sessionTable([]);
+ expect(emptyLines).toHaveLength(1);
+ expect(emptyLines[0]).toBe("No active sessions.");
+
+ const nullLines = sessionTable(null as unknown as []);
+ expect(nullLines).toHaveLength(1);
+ expect(nullLines[0]).toBe("No active sessions.");
+ });
+});