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
import { T, selected, statusStyle, resultStyle } from "./theme.mjs";
import { border, cellWidth, clean, compose, fitCells, paneRow, paneWidths, visibleColumns, windowFor } from "./layout.mjs";
import { activeSection, columns, context, labelFor, SECTIONS } from "./model.mjs";
const statusGlyph=(s)=>s==="verified"?"✓":s==="default"?"●":s==="configured"?"◆":s==="missing"?"!":s==="error"?"×":"";
function headerLine(config,W){const ctx=context(config.stack),identity=[ctx.user,ctx.provider,ctx.connection].filter(Boolean).join(" / ")||"no connection selected";const left=" MSO Integrations";const plain=compose(left,identity,W);const split=plain.indexOf("Integrations");if(split<0)return plain;const before=plain.slice(0,5),after=plain.slice(5);return `${T.blueBg}${T.white}${T.bold}${before}${T.reset}${T.bold}${after.slice(0,12)}${T.reset}${T.muted}${after.slice(12)}${T.reset}`;}
function sectionLine(config,W,active){let plain=" SECTIONS ";for(const s of SECTIONS)plain+=` ${s.key}:${s.label} `;plain=fitCells(plain,W);let styled=plain;for(const s of SECTIONS){const token=` ${s.key}:${s.label} `;styled=styled.replace(token,s.id===active?`${T.blueBg}${T.white}${T.bold}${token}${T.reset}`:`${T.muted}${token}${T.reset}`);}return styled;}
function pathLine(config,W){const parts=["MSO",...config.stack.map((id,i)=>labelFor(config.snapshot,id,config.stack.slice(0,i)))];return `${T.muted}${fitCells(` PATH ${parts.join(" › ")}`,W)}${T.reset}`;}
function filterLine(config,W){const value=config.filterMode?`/${config.query||""}`:(config.query?`/${config.query}`:"/ to filter current column");return `${T.muted}${fitCells(` FILTER ${value}`,W)}${T.reset}`;}
function rowText(item,w){const branch=item?.kind==="branch"?"›":"·",glyph=statusGlyph(item?.status),badge=item?.badge?` ${item.badge}`:"";const prefix=` ${branch} ${glyph?glyph+" ":""}${clean(item?.label||"")}`;const right=badge?`[${badge.trim()}]`:"";return compose(prefix,right,w);}
function styleRow(item,text,isSelected,isActive){if(isSelected)return selected(text,isActive);if(item?.status)return statusStyle(item.status,text);return text;}
function grid(config,W,bodyRows){const all=columns(config.snapshot,config.stack),shown=visibleColumns(all,config.cols),widths=paneWidths(W,shown.length),current=shown.at(-1);const items=config.items??current?.items??[],cursor=Math.min(config.cursor??0,Math.max(0,items.length-1)),active=items[cursor]??null;const prepared=shown.map((col,i)=>{const isActive=i===shown.length-1,rows=isActive?items:col.items,selectedId=isActive?active?.id:col.selectedId,idx=Math.max(0,rows.findIndex((it)=>it.id===selectedId)),win=windowFor(rows,idx,Math.max(1,bodyRows));return{...col,isActive,rows,selectedId,win};});const lines=[`${T.border}${border(widths,"top")}${T.reset}`];const titles=prepared.map((p)=>` ${p.title}`);lines.push(`${T.border}│${T.reset}`+titles.map((x,i)=>`${T.bold}${fitCells(x,widths[i])}${T.reset}`).join(`${T.border}│${T.reset}`)+`${T.border}│${T.reset}`);lines.push(`${T.border}${border(widths,"mid")}${T.reset}`);for(let r=0;r<bodyRows;r++){const cells=prepared.map((p)=>{const it=p.rows[p.win.start+r];if(!it)return" ".repeat(widths[prepared.indexOf(p)]);const sel=it.id===p.selectedId,txt=rowText(it,widths[prepared.indexOf(p)]);return styleRow(it,txt,sel,p.isActive);});lines.push(`${T.border}│${T.reset}`+cells.map((x,i)=>{const pad=Math.max(0,widths[i]-cellWidth(x));return x+" ".repeat(pad);}).join(`${T.border}│${T.reset}`)+`${T.border}│${T.reset}`);}lines.push(`${T.border}${border(widths,"bottom")}${T.reset}`);return{lines,active};}
function inspector(config,active,W,rows){const activity=(config.activity||[]).filter(Boolean),preview=(active?.preview||[]).filter(Boolean),body=activity.length?activity:preview;const title=activity.length?"RESULT":"INSPECTOR";const lines=[`${T.border}┌${"─".repeat(Math.max(0,W-2))}┐${T.reset}`];const headline=active?`${active.label}${active.hint?` — ${active.hint}`:""}`:"No matching item";lines.push(`${T.border}│${T.reset}${T.bold}${fitCells(` ${title} ${headline}`,W-2)}${T.reset}${T.border}│${T.reset}`);for(let i=0;i<rows;i++){const raw=body[i]||"",styled=activity.length?resultStyle(fitCells(` ${raw}`,W-2)):`${T.muted}${fitCells(` ${raw}`,W-2)}${T.reset}`;lines.push(`${T.border}│${T.reset}${styled}${T.border}│${T.reset}`);}lines.push(`${T.border}└${"─".repeat(Math.max(0,W-2))}┘${T.reset}`);return lines;}
export function buildFrame(config,{cols=120,rows=30}={}){const W=Math.max(39,cols-1),H=Math.max(16,rows);config={...config,cols};const all=columns(config.snapshot,config.stack),current=all.at(-1),source=current?.items||[],q=clean(config.query||"").toLowerCase(),items=q?source.filter((x)=>`${x.id} ${x.label} ${x.hint||""} ${x.status||""}`.toLowerCase().includes(q)):source,cursor=Math.min(config.cursor??0,Math.max(0,items.length-1));const active=items[cursor]||null,section=activeSection(config.stack,active);const top=[headerLine(config,W),sectionLine(config,W,section),pathLine(config,W),filterLine(config,W)];const inspectorRows=H>=36?6:H>=28?4:H>=22?3:2;const footerRows=1,gridFixed=4,available=H-top.length-(inspectorRows+3)-footerRows,bodyRows=Math.max(2,available-gridFixed);const g=grid({...config,items,cursor},W,bodyRows),ins=inspector(config,g.active,W,inspectorRows);const footerText=cols>=132?" ↑↓ move ←→ columns Enter open/run / filter V verify R route S setup D default N new 1–4 sections ? help Ctrl-D quit":cols>=92?" ↑↓ move ←→ columns Enter open / filter V verify S setup 1–4 sections ? help Ctrl-D quit":cols>=68?" ↑↓ move ←→ open/back Enter run / filter ? help Ctrl-D quit":" ↑↓ move ←→ open/back Enter / filter Ctrl-D quit";const footer=`${T.muted}${fitCells(footerText,W)}${T.reset}`;const out=[...top,...g.lines,...ins,footer];while(out.length<H)out.push(" ".repeat(W));return{lines:out.slice(0,H),items,cursor,active:g.active};}
export function paint(output,lines){const E="\x1b",CUP=(r)=>`${E}[${r};1H`;output.write(`${E}[H${E}[2J${E}[?25l`+lines.map((line,i)=>`${CUP(i+1)}${line}${T.reset}`).join(""));}