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(pwa,chat): notch clearance, a doubled iOS inset, and an assistant that was lying
Rahman7c998cd12c30
diff --git a/app/api/config/route.ts b/app/api/config/route.tsindex 648ec8de..1cb7905c 100644--- a/app/api/config/route.ts+++ b/app/api/config/route.ts@@ -53,6 +53,13 @@ export async function GET() {return NextResponse.json({provider,+ // Whether the ACTIVE provider path can carry function calls at all. The+ // ChatGPT Codex OAuth backend cannot — app/api/assistant/route.ts takes a+ // chat-only branch for it and drops `tools` entirely. Until this existed the+ // UI advertised "22 tools" and "Alfa acts on your real VPS" on that provider+ // while the model correctly answered that it had none, which reads as the+ // assistant being broken rather than the provider being chat-only.+ toolsSupported: provider !== "openai-codex",model: cfg.model || defaultModelFor(provider),hasApiKey: key.length > 0,apiKeyMasked: stored ? mask(stored) : "",diff --git a/app/globals.css b/app/globals.cssindex 2b80e89b..bc3a5d21 100644--- a/app/globals.css+++ b/app/globals.css@@ -459,8 +459,21 @@ body {installed PWA (display-mode: standalone), so the browser tab / desktopPhoneFrame preview stays visually unchanged while the real app clears the bar. */[data-shell="ios"] { --sai-top: max(env(safe-area-inset-top, 0px), 2.75rem); }-@media (display-mode: standalone) {- [data-shell="android"] { --sai-top: max(env(safe-area-inset-top, 0px), 1.5rem); }+/* Android floors BOTH insets, in every display mode.+ It used to floor only --sai-top, only at 1.5rem (24px), and only inside+ `display-mode: standalone`. Three problems on a real phone, all reported from+ one: 24px is a 2019 status bar — a punch-hole or curved-corner device needs+ ~36px, so the home grid and the top of every app sat UNDER the cutout; the+ standalone gate meant an installed-to-home-screen PWA that Chrome does not+ report as standalone got no floor at all; and --sai-bottom had no floor, so on+ gesture navigation the 48px nav row sat beneath the system gesture bar and its+ Back/Home/Recents could not be tapped.+ max() throughout, so a device that reports a LARGER inset still wins and nothing+ is capped. The desktop PhoneFrame preview gains 36px of top chrome, which is the+ honest thing for a preview of a device that has a status bar. */+[data-shell="android"] {+ --sai-top: max(env(safe-area-inset-top, 0px), 2.25rem);+ --sai-bottom: max(env(safe-area-inset-bottom, 0px), 1rem);}/* OS reduced-motion: collapse durations to ~instant. 1ms (not 0) so animationendstill fires — the window close/minimize finalize on that event. Scoped narrowlydiff --git a/frontend/slices/appshell/components/message-bubble.tsx b/frontend/slices/appshell/components/message-bubble.tsxindex 32bb7a45..b13d7eab 100644--- a/frontend/slices/appshell/components/message-bubble.tsx+++ b/frontend/slices/appshell/components/message-bubble.tsx@@ -2,6 +2,7 @@import { Sparkles, User } from "lucide-react";import { cn } from "@/lib/utils";+import { mdToHtml } from "../features/widgets/components/md";export type ChatRole = "user" | "assistant" | "tool";@@ -67,7 +68,25 @@ export function MessageBubble({ message, ios }: { message: ChatMessage; ios?: bo),)}>- {message.text || <span className="text-muted-foreground">…</span>}+ {!message.text ? (+ <span className="text-muted-foreground">…</span>+ ) : isUser ? (+ message.text+ ) : (+ // Assistant text is MARKDOWN. The model emits **bold**, `code`, bullets+ // and fenced blocks on nearly every turn, and rendering it literally is+ // why the thread read as unfinished — a wall of asterisks and backticks.+ // mdToHtml escapes first and emits a fixed tag set (see md.test.ts),+ // which is what makes dangerouslySetInnerHTML defensible on text that is+ // model output, i.e. untrusted.+ // USER text stays literal on purpose: someone typing ** means **.+ // whitespace-normal because mdToHtml already turned newlines into <br/>;+ // leaving the parent's pre-wrap on would double every line break.+ <span+ className="block whitespace-normal [&_code]:font-mono [&_pre]:whitespace-pre [&_strong]:font-semibold"+ dangerouslySetInnerHTML={{ __html: mdToHtml(message.text) }}+ />+ )}</div></div>);diff --git a/frontend/slices/appshell/components/mobile-shell.tsx b/frontend/slices/appshell/components/mobile-shell.tsxindex dc607ad7..93c3cf04 100644--- a/frontend/slices/appshell/components/mobile-shell.tsx+++ b/frontend/slices/appshell/components/mobile-shell.tsx@@ -239,13 +239,18 @@ export function MobileShell() {</div></header>{/* The home-indicator overlays the content edge-to-edge (real-iOS), so- raise --sai-bottom INSIDE the app pane to include its 34px zone —- every app already pads with var(--sai-bottom), so bumping the var- clears the pill centrally without double-padding anyone. */}+ --sai-bottom INSIDE the app pane must clear its 34px band — every app+ already pads with var(--sai-bottom), so setting the var here clears the+ pill centrally without double-padding anyone.+ max(), NOT env() + 34px. On a notched iPhone env(safe-area-inset-bottom)+ is ALREADY the 34px home-indicator zone, and our pill is drawn INSIDE+ that same physical band — adding them reserved 68px and pushed every+ app's bottom row visibly up the screen. On a device that reports 0 the+ floor still applies, so nothing regresses where the sum used to be right. */}<mainonScrollCapture={(e) => setAppScrolled((e.target as HTMLElement).scrollTop > 4)}className="relative min-h-0 flex-1 overflow-auto [container-type:inline-size]"- style={{ "--sai-bottom": "calc(env(safe-area-inset-bottom, 0px) + 34px)" } as React.CSSProperties}+ style={{ "--sai-bottom": "max(env(safe-area-inset-bottom, 0px), 34px)" } as React.CSSProperties}><WindowContent app={top.app} payload={top.payload} /></main>diff --git a/frontend/slices/appshell/features/widgets/components/md.test.ts b/frontend/slices/appshell/features/widgets/components/md.test.tsindex 2d651c41..c4a0a2ae 100644--- a/frontend/slices/appshell/features/widgets/components/md.test.ts+++ b/frontend/slices/appshell/features/widgets/components/md.test.ts@@ -19,3 +19,32 @@ describe("mdToHtml", () => {expect(out).toContain(""onmouseover"); // it stays escaped INSIDE the value});});++describe("fenced code blocks", () => {+ it("renders a fence as <pre><code>, not as literal backticks", () => {+ const out = mdToHtml("run this:\n```sh\nls -la ~\n```");+ expect(out).toContain("<pre");+ expect(out).toContain("ls -la ~");+ expect(out).not.toContain("```");+ });++ it("does NOT apply inline markdown inside a fence", () => {+ // `rm -rf **` inside a code block used to render as bold nothing, which is+ // both wrong and dangerous-looking in a VPS assistant.+ const out = mdToHtml("```\nrm -rf ** and `x`\n```");+ expect(out).not.toContain("<strong>");+ expect(out).toContain("rm -rf ** and `x`");+ });++ it("escapes inside a fence — it is model output, i.e. untrusted", () => {+ const out = mdToHtml("```\n<img src=x onerror=alert(1)>\n```");+ expect(out).not.toContain("<img");+ expect(out).toContain("<img");+ });++ it("still renders inline code and bold OUTSIDE a fence", () => {+ const out = mdToHtml("**bold** and `code`\n```\nraw\n```");+ expect(out).toContain("<strong>bold</strong>");+ expect(out).toContain("<code");+ });+});diff --git a/frontend/slices/appshell/features/widgets/components/md.ts b/frontend/slices/appshell/features/widgets/components/md.tsindex 7573b19b..8cfbf483 100644--- a/frontend/slices/appshell/features/widgets/components/md.ts+++ b/frontend/slices/appshell/features/widgets/components/md.ts@@ -1,15 +1,33 @@-// Minimal, SAFE markdown → HTML for the Markdown widget. Escape FIRST (including-// the double-quote, so a link URL can't break out of href="…" and inject an-// event-handler attribute), THEN apply a fixed set of transforms. Links are-// restricted to http(s) — no javascript:/data:. The output is rendered via-// dangerouslySetInnerHTML, so the escaping here is load-bearing (see md.test.ts).-// ponytail: headings/bold/italic/code/links/bullets — no tables/nested lists.+// Minimal, SAFE markdown → HTML. Escape FIRST (including the double-quote, so a+// link URL can't break out of href="…" and inject an event-handler attribute),+// THEN apply a fixed set of transforms. Links are restricted to http(s) — no+// javascript:/data:. The output is rendered via dangerouslySetInnerHTML, so the+// escaping here is load-bearing (see md.test.ts).+//+// Used by the Markdown widget AND by the Alfa chat bubble, which is why fenced+// code blocks exist: an assistant reporting command output emits them on almost+// every turn, and rendering them literally is what made the thread look unfinished.+// ponytail: headings/bold/italic/code/fences/links/bullets — no tables, no nested+// lists. Add one only when something actually needs it.++const esc = (s: string) =>+ s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);++// A placeholder that cannot appear in real text and survives the escape pass+// untouched (it contains none of & < > ").+const MARK = "\u0000F";+export function mdToHtml(src: string): string {- return src- .replace(/&/g, "&")- .replace(/</g, "<")- .replace(/>/g, ">")- .replace(/"/g, """)+ // Fenced blocks are lifted out BEFORE anything else and restored last. The+ // inline passes below would otherwise eat the ** and ` inside a shell snippet —+ // `rm -rf **` in a code block would have rendered as bold nothing.+ const fences: string[] = [];+ const body = src.replace(/```[a-zA-Z0-9_-]*\r?\n?([\s\S]*?)```/g, (_m, code: string) => {+ fences.push(esc(code.replace(/\n$/, "")));+ return `${MARK}${fences.length - 1}${MARK}`;+ });++ return esc(body).replace(/^### (.+)$/gm, '<div class="text-sm font-semibold">$1</div>').replace(/^## (.+)$/gm, '<div class="text-base font-bold">$1</div>').replace(/^# (.+)$/gm, '<div class="text-lg font-bold">$1</div>')@@ -18,5 +36,8 @@ export function mdToHtml(src: string): string {.replace(/\*([^*\n]+)\*/g, "<em>$1</em>").replace(/`([^`\n]+)`/g, '<code class="rounded bg-black/20 px-1">$1</code>').replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer" class="underline">$1</a>')- .replace(/\n/g, "<br/>");+ .replace(/\n/g, "<br/>")+ .replace(new RegExp(`${MARK}(\\d+)${MARK}`, "g"), (_m, i: string) =>+ `<pre class="my-1.5 overflow-x-auto rounded-md bg-black/25 p-2 text-[0.92em] leading-snug"><code>${fences[Number(i)]}</code></pre>`,+ );}diff --git a/frontend/slices/assistant/components/agent-switcher.tsx b/frontend/slices/assistant/components/agent-switcher.tsxindex 43497aba..109389ca 100644--- a/frontend/slices/assistant/components/agent-switcher.tsx+++ b/frontend/slices/assistant/components/agent-switcher.tsx@@ -9,6 +9,7 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";import type { AIStore } from "../lib/store";+import { useToolsSupported } from "../lib/use-tools-supported";import { OS_TOOLS } from "../lib/tools";import { GlyphTile } from "./agent-avatar";@@ -16,14 +17,19 @@ import { GlyphTile } from "./agent-avatar";// persona the system context for the next reply; "New agent" opens the editor.export function AgentSwitcher({ store, onNew }: { store: AIStore; onNew: () => void }) {const a = store.activeAgent;+ const toolsSupported = useToolsSupported();return (<DropdownMenu><DropdownMenuTrigger className="flex items-center gap-2 rounded-lg p-1 pr-2 outline-none hover:bg-accent [@media(pointer:coarse)]:min-h-[44px] [@media(pointer:coarse)]:min-w-[44px]"><GlyphTile glyph={a.glyph} color={a.color} size={30} /><div className="text-left leading-tight"><div className="text-[13px] font-semibold">{a.name}</div>+ {/* OS_TOOLS.length is what the CATALOG holds, which is not what the model+ receives: a chat-only provider gets none of them. Printing the catalog+ size unconditionally is how the header came to say "22 tools" next to an+ assistant that correctly reported having zero. */}<div className="text-[10px] text-muted-foreground">- {OS_TOOLS.length} tools+ {toolsSupported ? `${OS_TOOLS.length} tools` : "chat only"}</div></div><ChevronDown className="size-3.5 text-muted-foreground" />diff --git a/frontend/slices/assistant/components/chat-panel.tsx b/frontend/slices/assistant/components/chat-panel.tsxindex a45fddce..8100a3c5 100644--- a/frontend/slices/assistant/components/chat-panel.tsx+++ b/frontend/slices/assistant/components/chat-panel.tsx@@ -12,6 +12,7 @@ import {import { ScrollArea } from "@/components/ui/scroll-area";import { cn } from "@/lib/utils";import { errText } from "./error-text";+import { useToolsSupported } from "../lib/use-tools-supported";import {registerAlfaRunner,updateAlfa,@@ -68,6 +69,7 @@ export function ChatPanel({}) {const api = useOsApi();const ios = useActiveShell().id === "ios";+ const toolsSupported = useToolsSupported();// The display list lives in the SHARED Alfa store, not in this component. That// is what makes the per-app Alfa sheet show this very conversation instead of a// second, disconnected one — and it is less memory, not more: one array for@@ -226,12 +228,22 @@ export function ChatPanel({<divclassName={cn("px-3 py-1 text-center text-[11px] font-medium",- api.mode === "live" ? "bg-destructive/10 text-destructive" : "bg-muted text-muted-foreground",+ !toolsSupported+ ? "bg-amber-500/10 text-amber-600 dark:text-amber-400"+ : api.mode === "live"+ ? "bg-destructive/10 text-destructive"+ : "bg-muted text-muted-foreground",)}>- {api.mode === "live"- ? "● LIVE — Alfa acts on your real VPS; every change needs your approval"- : "MOCK — actions are simulated (switch to Live in Settings → Server)"}+ {/* Three states, not two. `api.mode` only says which DATA source the tools+ would hit — it says nothing about whether the model can call one, and on+ a chat-only provider the old two-state banner promised a VPS the+ assistant could not touch. */}+ {!toolsSupported+ ? "CHAT ONLY — this provider cannot call tools. Switch provider in Settings → AI to let Alfa act."+ : api.mode === "live"+ ? "● LIVE — Alfa acts on your real VPS; every change needs your approval"+ : "MOCK — actions are simulated (switch to Live in Settings → Server)"}</div>{messages.length === 0 ? (<div className="flex-1 overflow-y-auto">diff --git a/frontend/slices/assistant/lib/use-tools-supported.ts b/frontend/slices/assistant/lib/use-tools-supported.tsnew file mode 100644index 00000000..6cd5fb6f--- /dev/null+++ b/frontend/slices/assistant/lib/use-tools-supported.ts@@ -0,0 +1,47 @@+"use client";++import { useEffect, useState } from "react";+import { IS_DEMO } from "@/lib/demo";++// Can the ACTIVE provider actually call tools?+//+// Not a cosmetic question. app/api/assistant/route.ts takes a chat-only branch for+// the ChatGPT Codex OAuth backend and drops the `tools` array entirely, so on that+// provider every tool the UI advertises is unreachable. Before this, the header+// claimed "22 tools" and the banner claimed "Alfa acts on your real VPS" while the+// model answered, correctly, that it had none — which reads as a broken assistant+// rather than a chat-only provider.+//+// Optimistic default: true. A provider that CAN use tools is the common case, and+// flashing a "chat only" warning for one frame on every open would be its own lie.+// The GET is cached at module scope because several surfaces ask (chat panel+// banner, agent switcher badge) and the answer changes only when the owner picks a+// different provider in Settings.++let cached: Promise<boolean> | null = null;++function fetchSupported(): Promise<boolean> {+ cached ??= fetch("/api/config", { cache: "no-store" })+ .then((r) => (r.ok ? r.json() : null))+ .then((c: { toolsSupported?: boolean } | null) => c?.toolsSupported !== false)+ .catch(() => true); // unreachable config is not evidence of a chat-only provider+ return cached;+}++/** Call after changing the provider so the next read re-asks. */+export function invalidateToolsSupported(): void {+ cached = null;+}++export function useToolsSupported(): boolean {+ const [supported, setSupported] = useState(true);+ useEffect(() => {+ if (IS_DEMO) return; // demo makes no /api calls; its tools are simulated anyway+ let alive = true;+ void fetchSupported().then((v) => alive && setSupported(v));+ return () => {+ alive = false;+ };+ }, []);+ return supported;+}