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.

fix(alfa): restore mobile text selection and copy

xdproject0012fd173645cb8
diff --git a/frontend/slices/appshell/components/alfa-thread.tsx b/frontend/slices/appshell/components/alfa-thread.tsx
index ccb70ad2..5fa0f8f0 100644
--- a/frontend/slices/appshell/components/alfa-thread.tsx
+++ b/frontend/slices/appshell/components/alfa-thread.tsx
@@ -10,6 +10,7 @@ import { openWindow } from "../lib/store";
import { ChatComposer } from "./chat-composer";
import { ApprovalCard } from "./approval-card";
import type { ToolCard } from "./message-bubble";
+import { CopyButton } from "./copy-button";
import { resolveAlfaApproval, useAlfaApprovalCount } from "../lib/alfa-approvals";
import { useAlfaProjectContext } from "../lib/alfa-work-context";
@@ -22,6 +23,11 @@ import { useAlfaProjectContext } from "../lib/alfa-work-context";
// happened in different apps a divider names the new one, so a long task Alfa
// carried from Files to Terminal to the Browser reads as one story instead of
// three disconnected chats.
+function legacyMessageTime(id: string): number | undefined {
+ const match = /^m(\d+)-/.exec(id);
+ return match ? Number(match[1]) : undefined;
+}
+
export function AlfaThread({ ctx, placeholder }: { ctx: AlfaContext; placeholder?: string }) {
const messages = useAlfaMessages();
const busy = useAlfaBusy();
@@ -83,8 +89,20 @@ export function AlfaThread({ ctx, placeholder }: { ctx: AlfaContext; placeholder
// Only when the app actually changes between consecutive turns.
const prev = i > 0 ? messages[i - 1].appId : undefined;
const crossed = m.appId && m.appId !== prev;
+ const createdAt = m.createdAt || legacyMessageTime(m.id);
+ const dateLabel = createdAt ? new Date(createdAt).toLocaleDateString(undefined, { weekday: "long", day: "numeric", month: "long", year: "numeric" }) : null;
+ const previousCreatedAt = i > 0 ? (messages[i - 1].createdAt || legacyMessageTime(messages[i - 1].id)) : undefined;
+ const newDay = Boolean(dateLabel && (!previousCreatedAt || new Date(createdAt!).toLocaleDateString() !== new Date(previousCreatedAt).toLocaleDateString()));
+ const time = createdAt ? new Date(createdAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false }) : null;
return (
<div key={m.id} className="contents">
+ {newDay ? (
+ <div className="flex items-center gap-1.5 py-1 text-[10px] text-muted-foreground">
+ <span className="h-px flex-1 bg-border" />
+ <span>{dateLabel}</span>
+ <span className="h-px flex-1 bg-border" />
+ </div>
+ ) : null}
{crossed ? (
<div className="flex items-center gap-1.5 py-0.5 text-[10px] text-muted-foreground">
<span className="h-px flex-1 bg-border" />
@@ -102,15 +120,24 @@ export function AlfaThread({ ctx, placeholder }: { ctx: AlfaContext; placeholder
onResolve={resolveAlfaApproval}
/>
) : (
- <div
- className={cn(
- "max-w-[92%] whitespace-pre-wrap rounded-lg px-2.5 py-1.5 text-xs leading-relaxed",
- m.role === "user"
- ? "self-end bg-primary text-primary-foreground"
- : "self-start bg-secondary text-secondary-foreground",
- )}
- >
- {m.text || "…"}
+ <div className={cn("max-w-[92%]", m.role === "user" ? "self-end" : "self-start")}>
+ <div
+ onContextMenu={(e) => e.stopPropagation()}
+ className={cn(
+ "select-text [user-select:text] [-webkit-user-select:text] [-webkit-touch-callout:default] min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere] rounded-lg px-2.5 py-1.5 text-xs leading-relaxed",
+ m.role === "user"
+ ? "bg-primary text-primary-foreground"
+ : "bg-secondary text-secondary-foreground",
+ )}
+ >
+ {m.text || "…"}
+ </div>
+ {m.text ? (
+ <div className={cn("mt-0.5 flex items-center gap-1.5", m.role === "user" ? "justify-end" : "justify-start")}>
+ {time ? <span className="flex h-8 items-center [@media(pointer:coarse)]:h-11 text-[10px] leading-none text-muted-foreground">{time}</span> : null}
+ <CopyButton value={m.text} label="message" />
+ </div>
+ ) : null}
</div>
)}
</div>
diff --git a/frontend/slices/appshell/components/message-bubble.tsx b/frontend/slices/appshell/components/message-bubble.tsx
index b13d7eab..2175a809 100644
--- a/frontend/slices/appshell/components/message-bubble.tsx
+++ b/frontend/slices/appshell/components/message-bubble.tsx
@@ -3,6 +3,7 @@
import { Sparkles, User } from "lucide-react";
import { cn } from "@/lib/utils";
import { mdToHtml } from "../features/widgets/components/md";
+import { CopyButton } from "./copy-button";
export type ChatRole = "user" | "assistant" | "tool";
@@ -21,6 +22,7 @@ export type ToolCard = {
export type ChatMessage = {
id: string;
+ createdAt?: number;
role: ChatRole;
text?: string;
/** Present only on `role: "tool"` rows. */
@@ -30,14 +32,22 @@ export type ChatMessage = {
// One chat row: user messages align right (primary bubble), assistant messages
// align left with a Sparkles avatar. Tool rows are routed to ApprovalCard by the
// chat panel, so this only renders user/assistant. All colour via theme tokens.
+function legacyMessageTime(id: string): number | undefined {
+ const match = /^m(\d+)-/.exec(id);
+ return match ? Number(match[1]) : undefined;
+}
+
export function MessageBubble({ message, ios }: { message: ChatMessage; ios?: boolean }) {
+ const createdAt = message.createdAt || legacyMessageTime(message.id);
+ const time = createdAt ? new Date(createdAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false }) : null;
const isUser = message.role === "user";
return (
- <div
- className={cn(
- "flex w-full items-start gap-2.5",
- isUser ? "flex-row-reverse" : "flex-row",
- )}
+ <div className="contents">
+ <div
+ className={cn(
+ "flex w-full min-w-0 items-start gap-2.5",
+ isUser ? "flex-row-reverse" : "flex-row",
+ )}
>
{/* iMessage shows no per-bubble avatar in the thread — keep it off on iOS. */}
{!ios && (
@@ -52,41 +62,50 @@ export function MessageBubble({ message, ios }: { message: ChatMessage; ios?: bo
{isUser ? <User className="size-3.5" /> : <Sparkles className="size-3.5" />}
</span>
)}
- <div
- className={cn(
- "whitespace-pre-wrap",
- // iOS = iMessage silhouette: 19px bubble with the tail at the BOTTOM
- // corner (points down at the sender); received bubble = systemFill gray.
- ios
- ? cn(
- "max-w-[74%] rounded-[19px] px-[13px] py-2 text-[15px] leading-[1.35]",
- isUser ? "rounded-br-[6px] bg-primary text-primary-foreground" : "rounded-bl-[6px] bg-[var(--fill2)] text-foreground",
- )
- : cn(
- "max-w-[82%] rounded-2xl px-3.5 py-2 text-sm leading-relaxed",
- isUser ? "rounded-tr-sm bg-primary text-primary-foreground" : "rounded-tl-sm bg-muted text-foreground",
- ),
- )}
- >
- {!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 className={cn("min-w-0", ios ? "max-w-[74%]" : "max-w-[82%]")}>
+ <div
+ className={cn(
+ "select-text [user-select:text] [-webkit-user-select:text] [-webkit-touch-callout:default] min-w-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]",
+ // iOS = iMessage silhouette: 19px bubble with the tail at the BOTTOM
+ // corner (points down at the sender); received bubble = systemFill gray.
+ ios
+ ? cn(
+ "rounded-[19px] px-[13px] py-2 text-[15px] leading-[1.35]",
+ isUser ? "rounded-br-[6px] bg-primary text-primary-foreground" : "rounded-bl-[6px] bg-[var(--fill2)] text-foreground",
+ )
+ : cn(
+ "rounded-2xl px-3.5 py-2 text-sm leading-relaxed",
+ isUser ? "rounded-tr-sm bg-primary text-primary-foreground" : "rounded-tl-sm bg-muted text-foreground",
+ ),
+ )}
+ >
+ {!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 min-w-0 whitespace-normal [overflow-wrap:anywhere] [&_code]:font-mono [&_pre]:break-words [&_pre]:whitespace-pre-wrap [&_pre]:[overflow-wrap:anywhere] [&_strong]:font-semibold"
+ dangerouslySetInnerHTML={{ __html: mdToHtml(message.text) }}
+ />
+ )}
+ </div>
+ {message.text ? (
+ <div className={cn("mt-0.5 flex", isUser ? "justify-end" : "justify-start")}>
+ {time ? <span className="flex h-8 items-center [@media(pointer:coarse)]:h-11 text-[10px] leading-none text-muted-foreground">{time}</span> : null}
+ <CopyButton value={message.text} label="message" />
+ </div>
+ ) : null}
+ </div>
</div>
</div>
);
diff --git a/frontend/slices/appshell/components/shells/context-menu-host.test.ts b/frontend/slices/appshell/components/shells/context-menu-host.test.ts
index 6e70e5be..ba363e18 100644
--- a/frontend/slices/appshell/components/shells/context-menu-host.test.ts
+++ b/frontend/slices/appshell/components/shells/context-menu-host.test.ts
@@ -44,6 +44,14 @@ describe("ContextMenuHost", () => {
expect(host).toMatch(/\},\s*\[shell, surface\],\s*\);/);
});
+ it("leaves descendants marked for native context menus untouched before collecting zones or registry items", () => {
+ const guard = host.indexOf("if (nativeContextMenu || !target) return;");
+ expect(guard).toBeGreaterThan(-1);
+ expect(host).toContain('e.nativeEvent.composedPath().some((node) =>');
+ expect(guard).toBeLessThan(host.indexOf("collectZones(target, base)"));
+ expect(guard).toBeLessThan(host.indexOf("getContextMenuItems(base)"));
+ });
+
// onClose was only the loudest of the three props. `pos` and `items` were still
// rebuilt inline every render (`pos={menu ? { x: menu.x, y: menu.y } : null}`,
// `items={menu?.items ?? []}`); harmless only because ContextMenu's destructive
diff --git a/frontend/slices/appshell/components/shells/context-menu-host.tsx b/frontend/slices/appshell/components/shells/context-menu-host.tsx
index 7bdc917b..c71e3243 100644
--- a/frontend/slices/appshell/components/shells/context-menu-host.tsx
+++ b/frontend/slices/appshell/components/shells/context-menu-host.tsx
@@ -42,8 +42,15 @@ export function ContextMenuHost({ children }: { children: ReactNode }) {
const onContextMenu = useCallback(
(e: React.MouseEvent) => {
if (e.defaultPrevented) return; // a descendant / legacy handler already claimed it
- const target = e.target as Element;
- const closest = (sel: string) => !!(target.closest && target.closest(sel));
+ const target = e.target as Element | null;
+ const closest = (sel: string) => !!(target?.closest && target.closest(sel));
+ const nativeContextMenu =
+ closest("[data-native-context-menu]") ||
+ e.nativeEvent.composedPath().some((node) =>
+ !!(node && typeof (node as Element).matches === "function" && (node as Element).matches("[data-native-context-menu]")),
+ );
+ if (nativeContextMenu || !target) return;
+
const base = { shell, surface, x: e.clientX, y: e.clientY };
const { groups, sealed } = collectZones(target, base);
diff --git a/frontend/slices/appshell/features/inspector/components/alfa-sheet.tsx b/frontend/slices/appshell/features/inspector/components/alfa-sheet.tsx
index 5fba8940..8858e7ca 100644
--- a/frontend/slices/appshell/features/inspector/components/alfa-sheet.tsx
+++ b/frontend/slices/appshell/features/inspector/components/alfa-sheet.tsx
@@ -79,7 +79,7 @@ export function AlfaSheet() {
</div>
</div>
) : null}
- <div className="min-h-0 flex-1">
+ <div data-native-context-menu className="min-h-0 flex-1">
<AlfaThread
ctx={{
appId: appId ?? undefined,
diff --git a/frontend/slices/appshell/lib/alfa.ts b/frontend/slices/appshell/lib/alfa.ts
index 0b300ff3..203e2da5 100644
--- a/frontend/slices/appshell/lib/alfa.ts
+++ b/frontend/slices/appshell/lib/alfa.ts
@@ -26,6 +26,8 @@ export type AlfaRole = "user" | "assistant" | "tool";
export type AlfaMessage = {
id: string;
+ /** Local creation time of this display message. */
+ createdAt: number;
role: AlfaRole;
text?: string;
/** Which app this turn happened in — the cross-feature trail. */
diff --git a/frontend/slices/assistant/components/chat-panel.tsx b/frontend/slices/assistant/components/chat-panel.tsx
index 624f8095..7d41057d 100644
--- a/frontend/slices/assistant/components/chat-panel.tsx
+++ b/frontend/slices/assistant/components/chat-panel.tsx
@@ -42,6 +42,11 @@ const SUGGESTED = ["Show system stats", "List ~/projects", "Create notes.txt in
let seq = 0;
const nextId = () => `m${Date.now()}-${seq++}`;
+function legacyMessageTime(id: string): number | undefined {
+ const match = /^m(\d+)-/.exec(id);
+ return match ? Number(match[1]) : undefined;
+}
+
export type ChatHandle = {
runSteps: (auto: Automation, agent?: Agent) => void;
stop: () => void;
@@ -103,7 +108,7 @@ export function ChatPanel({
// Stable UI seam for the tool binding: push/patch tool cards + await approval.
const pushCard = useCallback((id: string, card: ToolCard) => {
- setMessages((prev) => [...prev, { id, role: "tool", tool: card }]);
+ setMessages((prev) => [...prev, { id, createdAt: Date.now(), role: "tool", tool: card }]);
}, [setMessages]);
const updateCard = useCallback((id: string, patch: Partial<ToolCard>) => {
setMessages((prev) => prev.map((m) => (m.id === id && m.tool ? { ...m, tool: { ...m.tool, ...patch } } : m)));
@@ -139,10 +144,11 @@ export function ChatPanel({
const a = activeAgent();
// `appId` tags the turn with the app it came from — that tag is the whole
// cross-feature trail the sheet renders ("in Camoufox", "in Files").
+ const createdAt = Date.now();
setMessages((prev) => [
...prev,
- { id: nextId(), role: "user", text, appId: fromAppId },
- { id: nextId(), role: "assistant", text: "", appId: fromAppId },
+ { id: nextId(), createdAt, role: "user", text, appId: fromAppId },
+ { id: nextId(), createdAt, role: "assistant", text: "", appId: fromAppId },
]);
historyRef.current.push({ role: "user", text });
@@ -172,7 +178,7 @@ export function ChatPanel({
onDelta: (c) => appendToLastAssistant((t) => t + c),
// After each tool card, open a fresh assistant bubble so the next
// turn's text streams BELOW the card rather than into an earlier one.
- onTool: () => setMessages((prev) => [...prev, { id: nextId(), role: "assistant", text: "" }]),
+ onTool: () => setMessages((prev) => [...prev, { id: nextId(), createdAt: Date.now(), role: "assistant", text: "" }]),
},
8,
// The persona belongs HERE, rebuilt every turn, not smuggled into history
@@ -241,14 +247,36 @@ export function ChatPanel({
</div>
) : (
<ScrollArea className="flex-1">
- <div className={cn("flex flex-col p-4", ios ? "gap-1.5" : "gap-4")}>
- {messages.map((m) =>
- m.role === "tool" ? (
- <ApprovalCard key={m.id} message={m} onResolve={resolve} />
- ) : (
- <MessageBubble key={m.id} message={m} ios={ios} />
- ),
- )}
+ <div
+ data-native-context-menu
+ onContextMenu={(e) => e.stopPropagation()}
+ className={cn("flex flex-col p-4", ios ? "gap-1.5" : "gap-4")}
+ >
+ {messages.map((m, i) => {
+ const currentTime = m.createdAt || legacyMessageTime(m.id);
+ const previousTime = i > 0 ? (messages[i - 1].createdAt || legacyMessageTime(messages[i - 1].id)) : undefined;
+ const showDateSeparator = Boolean(
+ currentTime &&
+ (!previousTime ||
+ new Date(currentTime).toLocaleDateString() !== new Date(previousTime).toLocaleDateString()),
+ );
+ return (
+ <div key={m.id} className="contents">
+ {showDateSeparator ? (
+ <div className="flex items-center gap-1.5 py-1 text-[10px] text-muted-foreground">
+ <span className="h-px flex-1 bg-border" />
+ <span>{new Date(currentTime!).toLocaleDateString(undefined, { weekday: "long", day: "numeric", month: "long", year: "numeric" })}</span>
+ <span className="h-px flex-1 bg-border" />
+ </div>
+ ) : null}
+ {m.role === "tool" ? (
+ <ApprovalCard message={m} onResolve={resolve} />
+ ) : (
+ <MessageBubble message={m} ios={ios} />
+ )}
+ </div>
+ );
+ })}
<div ref={bottomRef} />
</div>
</ScrollArea>