Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(desktop): live status, larger type, paged chat, code auto, fleets
Salman Qureshi21fbf4805478
diff --git a/apps/desktop/src/api/mercury.ts b/apps/desktop/src/api/mercury.tsindex 0f459582..c256b63d 100644--- a/apps/desktop/src/api/mercury.ts+++ b/apps/desktop/src/api/mercury.ts@@ -6,7 +6,7 @@import { http, ApiError } from "./client";import type {BotManifest, BotRunRecord, BotStatus, ChatMessage, ChatSettings, ChatThread, CodeStatus, HealthInfo,- McpServer, ModelsResponse, PairResponse, PluginItem, ReasoningChoice, Skill, DeviceSummary,+ McpServer, ModelsResponse, CodeMode, PairResponse, PluginItem, ReasoningChoice, Skill, DeviceSummary,} from "./types";export const health = {@@ -60,7 +60,7 @@ export const chat = {export const code = {status: () => http.get<CodeStatus>("/api/code/status"),- set: (state: "off" | "plan" | "execute") => http.post<{ state: string; active: boolean }>("/api/code/set", { state }),+ set: (state: CodeMode) => http.post<{ state: string; active: boolean }>("/api/code/set", { state }),};export const bots = {@@ -70,6 +70,7 @@ export const bots = {enable: (id: string) => http.post<{ ok: boolean }>(`/api/bots/${encodeURIComponent(id)}/enable`),disable: (id: string) => http.post<{ ok: boolean }>(`/api/bots/${encodeURIComponent(id)}/disable`),stop: (id: string) => http.post<{ ok: boolean }>(`/api/bots/${encodeURIComponent(id)}/stop`),+ avatarUrl: (id: string) => `/api/bots/${encodeURIComponent(id)}/avatar`,run: (id: string) => http.post<{ accepted: boolean }>(`/api/bots/${encodeURIComponent(id)}/run`, {}),};diff --git a/apps/desktop/src/api/stream.ts b/apps/desktop/src/api/stream.tsindex 4883360b..14d0f1f2 100644--- a/apps/desktop/src/api/stream.ts+++ b/apps/desktop/src/api/stream.ts@@ -46,7 +46,9 @@ export function openStream(path: string, handlers: StreamHandlers): StreamHandlelet res: Response;try {res = await fetch(apiUrl(path), {- headers: { Accept: "text/event-stream", "Cache-Control": "no-cache", ...authHeaders(), ...(lastEventId ? { "Last-Event-ID": lastEventId } : {}) },+ // No Cache-Control: it is not a CORS-safelisted header, and a runtime that+ // does not list it in Access-Control-Allow-Headers blocks the stream.+ headers: { Accept: "text/event-stream", ...authHeaders(), ...(lastEventId ? { "Last-Event-ID": lastEventId } : {}) },signal: controller.signal,});} catch {diff --git a/apps/desktop/src/api/types.ts b/apps/desktop/src/api/types.tsindex 3fc00af4..64829669 100644--- a/apps/desktop/src/api/types.ts+++ b/apps/desktop/src/api/types.ts@@ -29,6 +29,8 @@ export interface PairResponse {export interface ChatThread {id: string;title?: string;+ alias?: string;+ updatedAt?: string;messages: ChatMessage[];createdAt: string;}@@ -41,7 +43,9 @@ export interface ToolStep {export interface ChatMessage {id: string;- role: "user" | "assistant" | "system";+ role: "user" | "assistant" | "system" | "tool";+ /** "message" | "tool-call" | … — how the runtime stored this entry. */+ kind?: string;content: string;timestamp: string;steps?: ToolStep[];@@ -70,9 +74,11 @@ export interface ChatSettings {workspace: string;}+export type CodeMode = "off" | "auto" | "plan" | "execute";+export interface CodeStatus {available: boolean;- state: "off" | "plan" | "execute";+ state: CodeMode;active: boolean;statusText: string;}@@ -101,6 +107,7 @@ export interface BotStatus {fleetRole?: "lead" | "crew";parent?: string;crewWorking?: number;+ hasAvatar?: boolean;}export interface BotManifest {diff --git a/apps/desktop/src/components/BotAvatar.tsx b/apps/desktop/src/components/BotAvatar.tsxnew file mode 100644index 00000000..f44f4852--- /dev/null+++ b/apps/desktop/src/components/BotAvatar.tsx@@ -0,0 +1,90 @@+import { useEffect, useState } from "react";+import { apiUrl, authHeaders } from "~/api/client";+import * as api from "~/api/mercury";+import { cx } from "~/lib/cx";++/**+ * A bot's face. Uses the avatar the runtime stores (ADR-028) when there is+ * one; otherwise draws a face from the id: a shape (circle, squircle,+ * shield, hexagon) in a two-tone gradient with two eyes and a smile — the+ * same friendly line as the Mercury mark, so a fleet reads as one family.+ * Same id, same face, on every device. Not an emoji, not a photo.+ */++const cache = new Map<string, Promise<string | null>>();++function fetchAvatar(id: string): Promise<string | null> {+ let hit = cache.get(id);+ if (!hit) {+ hit = fetch(apiUrl(api.bots.avatarUrl(id)), { headers: authHeaders() })+ .then(async (res) => (res.ok ? URL.createObjectURL(await res.blob()) : null))+ .catch(() => null);+ cache.set(id, hit);+ }+ return hit;+}++export function BotAvatar({ id, name, hasAvatar, size = 32, dimmed, className }: { id: string; name: string; hasAvatar?: boolean; size?: number; dimmed?: boolean; className?: string }) {+ const [src, setSrc] = useState<string | null>(null);+ useEffect(() => {+ let live = true;+ if (hasAvatar) void fetchAvatar(id).then((url) => { if (live) setSrc(url); });+ else setSrc(null);+ return () => { live = false; };+ }, [id, hasAvatar]);++ const style = { width: size, height: size };+ if (src) {+ return <img src={src} alt={name} style={style} className={cx("shrink-0 rounded-[28%] object-cover", dimmed && "opacity-50 grayscale", className)} draggable={false} />;+ }+ return <GeneratedFace id={id} name={name} size={size} dimmed={dimmed} className={className} />;+}++function hash(s: string): number {+ let h = 2166136261;+ for (let i = 0; i < s.length; i++) {+ h ^= s.charCodeAt(i);+ h = Math.imul(h, 16777619);+ }+ return h >>> 0;+}++const SHAPES = [+ // circle+ "M50 4a46 46 0 1 1 0 92a46 46 0 1 1 0-92z",+ // squircle+ "M50 4c36 0 46 10 46 46s-10 46-46 46S4 86 4 50 14 4 50 4z",+ // shield / rounded triangle pointing down+ "M14 10h72c6 0 10 5 8 11L60 88c-4 8-16 8-20 0L6 21c-2-6 2-11 8-11z",+ // hexagon+ "M50 3l41 23v48L50 97 9 74V26z",+];++function GeneratedFace({ id, name, size, dimmed, className }: { id: string; name: string; size: number; dimmed?: boolean; className?: string }) {+ const h = hash(id);+ const hue = h % 360;+ const hue2 = (hue + 28 + ((h >> 9) % 40)) % 360;+ const shape = SHAPES[(h >> 3) % SHAPES.length];+ const eyeGap = 9 + ((h >> 12) % 5);+ const mouth = (h >> 16) % 3; // smile, grin, small smile+ const tri = shape === SHAPES[2];+ const eyeY = tri ? 36 : 44;+ const mouthY = tri ? 52 : 60;+ const gid = `g-${id}`;+ return (+ <svg viewBox="0 0 100 100" width={size} height={size} role="img" aria-label={name} className={cx("shrink-0", dimmed && "opacity-50 grayscale", className)}>+ <defs>+ <linearGradient id={gid} x1="0" y1="0" x2="1" y2="1">+ <stop offset="0" stopColor={`hsl(${hue} 70% 62%)`} />+ <stop offset="1" stopColor={`hsl(${hue2} 72% 44%)`} />+ </linearGradient>+ </defs>+ <path d={shape} fill={`url(#${gid})`} />+ <circle cx={50 - eyeGap} cy={eyeY} r="5.2" fill="#fff" />+ <circle cx={50 + eyeGap} cy={eyeY} r="5.2" fill="#fff" />+ {mouth === 0 && <path d={`M${40} ${mouthY} q10 9 20 0`} stroke="#fff" strokeWidth="4.5" strokeLinecap="round" fill="none" />}+ {mouth === 1 && <path d={`M${38} ${mouthY - 1} q12 13 24 0z`} fill="#fff" />}+ {mouth === 2 && <path d={`M${44} ${mouthY} q6 5 12 0`} stroke="#fff" strokeWidth="4.5" strokeLinecap="round" fill="none" />}+ </svg>+ );+}diff --git a/apps/desktop/src/styles/base.css b/apps/desktop/src/styles/base.cssindex a56005af..56b31442 100644--- a/apps/desktop/src/styles/base.css+++ b/apps/desktop/src/styles/base.css@@ -15,8 +15,8 @@ body {background: rgb(var(--bg));color: rgb(var(--ink));font-family: "Geist Variable", system-ui, -apple-system, sans-serif;- font-size: 14px;- line-height: 22px;+ font-size: 15px;+ line-height: 24px;-webkit-font-smoothing: antialiased;text-rendering: optimizeLegibility;font-feature-settings: "kern", "liga", "calt";@@ -48,8 +48,8 @@ input, textarea, pre, code, [data-selectable], .prose {button, input, textarea, a, [role="button"], [data-no-drag] { -webkit-app-region: no-drag; }/* ── Prose: the agent's answers ── */-.prose { font-size: 14.5px; line-height: 1.6; color: rgb(var(--ink)); }-.prose > * + * { margin-top: 0.75em; }+.prose { font-size: 16px; line-height: 1.7; color: rgb(var(--ink)); letter-spacing: -0.003em; }+.prose > * + * { margin-top: 0.85em; }.prose p { margin: 0; }.prose h1, .prose h2, .prose h3, .prose h4 { font-weight: 600; letter-spacing: -0.01em; color: rgb(var(--ink)); }.prose h1 { font-size: 1.35em; } .prose h2 { font-size: 1.2em; } .prose h3 { font-size: 1.08em; } .prose h4 { font-size: 1em; }@@ -59,10 +59,10 @@ button, input, textarea, a, [role="button"], [data-no-drag] { -webkit-app-region.prose a { color: rgb(var(--accent)); text-decoration: underline; text-decoration-color: rgb(var(--accent) / 0.4); text-underline-offset: 2px; }.prose strong { font-weight: 600; }.prose code { font-family: "Geist Mono Variable", ui-monospace, monospace; font-size: 0.9em; background: rgb(var(--ink) / 0.07); padding: 1px 5px; border-radius: 5px; }-.prose pre { background: rgb(var(--surface-2)); border: 1px solid rgb(var(--ink) / 0.08); border-radius: 10px; padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; }+.prose pre { background: rgb(var(--surface-2)); border: 1px solid rgb(var(--ink) / 0.08); border-radius: 10px; padding: 14px 16px; overflow-x: auto; font-size: 13.5px; line-height: 1.6; }.prose pre code { background: none; padding: 0; font-size: inherit; }.prose blockquote { border-left: 2px solid rgb(var(--ink) / 0.18); padding-left: 12px; color: rgb(var(--ink-2)); }-.prose table { border-collapse: collapse; width: 100%; font-size: 13px; }+.prose table { border-collapse: collapse; width: 100%; font-size: 14px; }.prose th, .prose td { border: 1px solid rgb(var(--ink) / 0.12); padding: 6px 10px; text-align: left; }.prose th { background: rgb(var(--ink) / 0.04); font-weight: 600; }.prose hr { border: 0; border-top: 1px solid rgb(var(--ink) / 0.12); }diff --git a/apps/desktop/src/views/bots/BotsView.tsx b/apps/desktop/src/views/bots/BotsView.tsxindex 485cb0de..1f09fc9a 100644--- a/apps/desktop/src/views/bots/BotsView.tsx+++ b/apps/desktop/src/views/bots/BotsView.tsx@@ -1,5 +1,5 @@-import { Play, Square, RefreshCw } from "lucide-react";-import { useEffect, useState } from "react";+import { ChevronDown, Play, RefreshCw, Square } from "lucide-react";+import { useEffect, useMemo, useState } from "react";import { cx } from "~/lib/cx";import * as api from "~/api/mercury";import type { BotManifest, BotRunRecord, BotStatus } from "~/api/types";@@ -11,53 +11,131 @@ import { Switch } from "~/components/ui/Switch";import { Badge, Empty, Mono, SectionTitle } from "~/components/ui/bits";import { StateOrb } from "~/components/indicators/StateOrb";import { Input } from "~/components/ui/Input";+import { BotAvatar } from "~/components/BotAvatar";++/**+ * Bots, organised the way they work: each fleet is a lead with its crew+ * underneath; bots without a fleet are listed on their own. Selecting a+ * lead shows the whole fleet; selecting a crew member shows that bot.+ */++interface Fleet {+ lead: BotStatus;+ crew: BotStatus[];+}++function organise(bots: BotStatus[]): { fleets: Fleet[]; solo: BotStatus[] } {+ const byId = new Map(bots.map((b) => [b.id, b]));+ const crewOf = new Map<string, BotStatus[]>();+ for (const b of bots) {+ if (b.fleetRole === "crew" && b.parent && byId.has(b.parent)) {+ const list = crewOf.get(b.parent) ?? [];+ list.push(b);+ crewOf.set(b.parent, list);+ }+ }+ const fleets: Fleet[] = [];+ const solo: BotStatus[] = [];+ for (const b of bots) {+ if (b.fleetRole === "crew" && b.parent && byId.has(b.parent)) continue;+ if (b.fleetRole === "lead" || crewOf.has(b.id)) fleets.push({ lead: b, crew: (crewOf.get(b.id) ?? []).sort((x, y) => x.name.localeCompare(y.name)) });+ else solo.push(b);+ }+ fleets.sort((a, b) => a.lead.name.localeCompare(b.lead.name));+ solo.sort((a, b) => a.name.localeCompare(b.name));+ return { fleets, solo };+}-/** Bots: the roster on the left with live state, one bot's detail on the right. */export function BotsView() {const bots = useBots((s) => s.bots);const available = useBots((s) => s.available);const activity = useBots((s) => s.activity);const [selected, setSelected] = useState<string | null>(null);+ const [collapsed, setCollapsed] = useState<Record<string, boolean>>({});+ const { fleets, solo } = useMemo(() => organise(bots), [bots]);useEffect(() => {- if (!selected && bots.length) setSelected(bots[0].id);- }, [bots, selected]);+ if (!selected && bots.length) setSelected(fleets[0]?.lead.id ?? solo[0]?.id ?? null);+ }, [bots, selected, fleets, solo]);if (!available) return <Empty title="Bots are not available on this runtime" body="Enable bots in the runtime's configuration to see them here." />;+ const selectedFleet = fleets.find((f) => f.lead.id === selected) ?? null;+ const selectedBot = bots.find((b) => b.id === selected) ?? null;+return (<div className="flex h-full min-h-0">- <aside className="flex w-[280px] shrink-0 flex-col border-r border-line bg-soft">- <header className="flex h-12 shrink-0 items-center justify-between px-4" data-tauri-drag-region>- <span className="text-sm font-medium text-ink">Bots</span>+ <aside className="flex w-[300px] shrink-0 flex-col border-r border-line bg-soft">+ <header className="flex h-[52px] shrink-0 items-center justify-between px-4" data-tauri-drag-region>+ <span className="text-base font-medium text-ink">Bots</span><Button variant="ghost" size="sm" icon onClick={() => void refreshBots()} aria-label="Refresh"><RefreshCw size={14} /></Button></header>- <div className="min-h-0 flex-1 overflow-y-auto px-2 pb-3">- {bots.length === 0 && <p className="px-2 text-xs text-ink4">No bots yet. Create one with `mercury bots create`.</p>}- {bots.map((b) => (- <button- key={b.id}- onClick={() => setSelected(b.id)}- className={cx("flex w-full items-center gap-3 rounded-md px-2.5 py-2 text-left", selected === b.id ? "bg-ink/[0.07]" : "hover:bg-ink/[0.05]")}- >- <StateOrb state={orbFor(b)} size={10} />- <span className="min-w-0 flex-1">- <span className="block truncate text-sm text-ink">{b.name}</span>- <span className="block truncate text-2xs text-ink3">{activity[b.id] ?? describe(b)}</span>- </span>- {b.needsYou && <Badge tone="amber">needs you</Badge>}- </button>- ))}+ <div className="min-h-0 flex-1 overflow-y-auto px-2 pb-4">+ {bots.length === 0 && <p className="px-2 text-sm text-ink4">No bots yet. Create one with `mercury bots create`.</p>}++ {fleets.map((f) => {+ const working = f.crew.filter((c) => c.state === "running").length + (f.lead.state === "running" ? 1 : 0);+ const isCollapsed = collapsed[f.lead.id] === true;+ return (+ <div key={f.lead.id} className="mb-3">+ <div className={cx("flex items-center rounded-lg", selected === f.lead.id ? "bg-ink/[0.07]" : "hover:bg-ink/[0.05]")}>+ <button onClick={() => setSelected(f.lead.id)} className="flex min-w-0 flex-1 items-center gap-3 px-2.5 py-2 text-left">+ <BotAvatar id={f.lead.id} name={f.lead.name} hasAvatar={f.lead.hasAvatar} size={36} dimmed={!f.lead.enabled} />+ <span className="min-w-0 flex-1">+ <span className="flex items-center gap-2">+ <span className="truncate text-sm font-medium text-ink">{f.lead.name}</span>+ {f.lead.needsYou && <span className="block h-1.5 w-1.5 shrink-0 rounded-full bg-amber" aria-label="needs you" />}+ </span>+ <span className="block truncate text-xs text-ink3">Fleet · {f.crew.length} crew{working ? ` · ${working} working` : ""}</span>+ </span>+ </button>+ <button onClick={() => setCollapsed((c) => ({ ...c, [f.lead.id]: !isCollapsed }))} className="mr-1.5 rounded p-1 text-ink4 hover:text-ink" aria-label={isCollapsed ? "Show crew" : "Hide crew"} aria-expanded={!isCollapsed}>+ <ChevronDown size={15} className={cx("transition-transform", isCollapsed && "-rotate-90")} />+ </button>+ </div>+ {!isCollapsed && (+ <div className="ml-[27px] border-l border-line pl-2">+ {f.crew.map((b) => (+ <BotRow key={b.id} bot={b} activity={activity[b.id]} active={selected === b.id} onClick={() => setSelected(b.id)} size={26} />+ ))}+ </div>+ )}+ </div>+ );+ })}++ {solo.length > 0 && (+ <>+ <div className="px-2.5 pb-1 pt-2 text-2xs font-medium uppercase tracking-wider text-ink4">On their own</div>+ {solo.map((b) => <BotRow key={b.id} bot={b} activity={activity[b.id]} active={selected === b.id} onClick={() => setSelected(b.id)} size={32} />)}+ </>+ )}</div></aside><section className="min-w-0 flex-1 overflow-y-auto">- {selected ? <BotDetail id={selected} status={bots.find((b) => b.id === selected) ?? null} /> : <Empty title="Pick a bot" />}+ {selectedFleet ? <FleetDetail fleet={selectedFleet} activity={activity} onSelect={setSelected} /> : selected ? <BotDetail id={selected} status={selectedBot} /> : <Empty title="Pick a bot" />}</section></div>);}+function BotRow({ bot, activity, active, onClick, size }: { bot: BotStatus; activity?: string; active: boolean; onClick: () => void; size: number }) {+ return (+ <button onClick={onClick} className={cx("flex w-full items-center gap-2.5 rounded-md px-2 py-1.5 text-left", active ? "bg-ink/[0.07]" : "hover:bg-ink/[0.05]")}>+ <span className="relative">+ <BotAvatar id={bot.id} name={bot.name} hasAvatar={bot.hasAvatar} size={size} dimmed={!bot.enabled} />+ <StateOrb state={orbFor(bot)} size={8} className="absolute -bottom-0.5 -right-0.5 rounded-full bg-soft p-[1.5px]" />+ </span>+ <span className="min-w-0 flex-1">+ <span className="block truncate text-sm text-ink">{bot.name}</span>+ <span className={cx("block truncate text-xs", bot.state === "running" ? "text-accent" : "text-ink3")}>{activity ?? describe(bot)}</span>+ </span>+ {bot.needsYou && <span className="block h-1.5 w-1.5 shrink-0 rounded-full bg-amber" aria-label="needs you" />}+ </button>+ );+}+function orbFor(b: BotStatus): AgentState {if (b.needsYou) return "needs-you";if (!b.enabled || b.state === "disabled") return "offline";@@ -67,19 +145,54 @@ function orbFor(b: BotStatus): AgentState {}function describe(b: BotStatus): string {- if (!b.enabled) return "disabled";- if (b.state === "running") return "working";- if (b.state === "queued") return "queued";- if (b.lastRunAt) return `last run ${ago(b.lastRunAt)}${b.lastRunState ? ` · ${b.lastRunState}` : ""}`;- return "idle";+ if (!b.enabled) return "Off";+ if (b.state === "running") return "Working";+ if (b.state === "queued") return "Queued";+ if (b.state === "paused") return "Paused";+ if (b.lastRunAt) return `Last ran ${ago(b.lastRunAt)}`;+ return "Idle";+}++function FleetDetail({ fleet, activity, onSelect }: { fleet: Fleet; activity: Record<string, string>; onSelect: (id: string) => void }) {+ const { lead, crew } = fleet;+ return (+ <div className="mx-auto flex max-w-[820px] flex-col gap-7 px-8 py-7">+ <BotHeader id={lead.id} status={lead} subtitle={`Fleet lead · ${crew.length} crew`} />+ <div className="flex flex-col gap-3">+ <SectionTitle>Crew</SectionTitle>+ <div className="grid grid-cols-2 gap-2.5 xl:grid-cols-3">+ {crew.map((b) => (+ <button key={b.id} onClick={() => onSelect(b.id)} className="flex items-center gap-3 rounded-lg border border-line bg-surface p-3 text-left hover:border-line-strong">+ <span className="relative">+ <BotAvatar id={b.id} name={b.name} hasAvatar={b.hasAvatar} size={36} dimmed={!b.enabled} />+ <StateOrb state={orbFor(b)} size={9} className="absolute -bottom-0.5 -right-0.5 rounded-full bg-surface p-[1.5px]" />+ </span>+ <span className="min-w-0 flex-1">+ <span className="block truncate text-sm font-medium text-ink">{b.name}</span>+ <span className={cx("block truncate text-xs", b.state === "running" ? "text-accent" : "text-ink3")}>{activity[b.id] ?? describe(b)}</span>+ </span>+ </button>+ ))}+ {crew.length === 0 && <p className="text-sm text-ink4">No crew yet.</p>}+ </div>+ </div>+ <BotBody id={lead.id} status={lead} />+ </div>+ );}function BotDetail({ id, status }: { id: string; status: BotStatus | null }) {+ return (+ <div className="mx-auto flex max-w-[820px] flex-col gap-7 px-8 py-7">+ <BotHeader id={id} status={status} />+ <BotBody id={id} status={status} />+ </div>+ );+}++function useBot(id: string, status: BotStatus | null) {const [bot, setBot] = useState<BotManifest | null>(null);const [journal, setJournal] = useState<BotRunRecord[]>([]);- const [message, setMessage] = useState("");- const [note, setNote] = useState<string | null>(null);-async function load() {try {const res = await api.bots.get(id);@@ -89,12 +202,47 @@ function BotDetail({ id, status }: { id: string; status: BotStatus | null }) {setBot(null);}}- useEffect(() => { void load(); setNote(null); }, [id, status?.state, status?.lastRunAt]);+ useEffect(() => { void load(); }, [id, status?.state, status?.lastRunAt, status?.enabled]);+ return { bot, journal, reload: load };+}+function BotHeader({ id, status, subtitle }: { id: string; status: BotStatus | null; subtitle?: string }) {+ const { bot, reload } = useBot(id, status);async function toggle(enabled: boolean) {try { await (enabled ? api.bots.enable(id) : api.bots.disable(id)); } catch { /* keep */ }- void refreshBots(); void load();+ void refreshBots(); void reload();}+ if (!bot) return <div className="h-16" />;+ return (+ <header className="flex items-start gap-4">+ <BotAvatar id={id} name={bot.name} hasAvatar={status?.hasAvatar} size={56} dimmed={!bot.enabled} />+ <div className="min-w-0 flex-1">+ <h1 className="text-xl font-medium tracking-tight text-ink">{bot.name}</h1>+ <p className="mt-0.5 text-sm text-ink3">{subtitle ?? bot.description ?? (bot.fleetRole === "crew" ? `Crew of ${bot.parent}` : "")}</p>+ <div className="mt-2 flex flex-wrap items-center gap-2">+ <Mono>{bot.id}</Mono>+ {bot.model?.model && <Badge>{bot.model.model}</Badge>}+ {bot.autonomy?.dailyTokenBudget && <Badge>{bot.autonomy.dailyTokenBudget.toLocaleString()} tokens/day</Badge>}+ {status?.needsYou && <Badge tone="amber">needs you</Badge>}+ </div>+ </div>+ <div className="flex items-center gap-2">+ <Switch id={`bot-${id}`} checked={bot.enabled} onCheckedChange={(v) => void toggle(v)} label={bot.enabled ? "On" : "Off"} />+ {status?.state === "running" ? (+ <Button size="sm" variant="outline" onClick={() => void api.bots.stop(id).then(refreshBots)}><Square size={13} /> Stop</Button>+ ) : (+ <Button size="sm" variant="outline" disabled={!bot.enabled} onClick={() => void api.bots.run(id).then(refreshBots)}><Play size={13} /> Run now</Button>+ )}+ </div>+ </header>+ );+}++function BotBody({ id, status }: { id: string; status: BotStatus | null }) {+ const { bot, journal } = useBot(id, status);+ const [message, setMessage] = useState("");+ const [note, setNote] = useState<string | null>(null);+ useEffect(() => { setNote(null); setMessage(""); }, [id]);async function send() {const text = message.trim();if (!text) return;@@ -106,49 +254,26 @@ function BotDetail({ id, status }: { id: string; status: BotStatus | null }) {setNote(err instanceof Error ? err.message : String(err));}}-- if (!bot) return <Empty title="Loading…" />;-+ if (!bot) return null;return (- <div className="mx-auto flex max-w-[760px] flex-col gap-6 px-6 py-5">- <header className="flex items-start gap-3">- <div className="min-w-0 flex-1">- <h1 className="text-xl font-medium tracking-tight text-ink">{bot.name}</h1>- {bot.description && <p className="mt-0.5 text-sm text-ink3">{bot.description}</p>}- <div className="mt-2 flex flex-wrap items-center gap-2">- <Mono>{bot.id}</Mono>- {bot.fleetRole && <Badge>{bot.fleetRole}</Badge>}- {bot.model?.model && <Badge>{bot.model.model}</Badge>}- {bot.autonomy?.dailyTokenBudget && <Badge>{bot.autonomy.dailyTokenBudget.toLocaleString()} tokens/day</Badge>}- </div>- </div>- <div className="flex items-center gap-2">- <Switch id={`bot-${id}`} checked={bot.enabled} onCheckedChange={(v) => void toggle(v)} label={bot.enabled ? "On" : "Off"} />- {status?.state === "running" ? (- <Button size="sm" variant="outline" onClick={() => void api.bots.stop(id).then(refreshBots)}><Square size={13} /> Stop</Button>- ) : (- <Button size="sm" variant="outline" disabled={!bot.enabled} onClick={() => void api.bots.run(id).then(refreshBots)}><Play size={13} /> Run now</Button>- )}- </div>- </header>-+ <><div className="flex flex-col gap-2">- <SectionTitle>Tell it something</SectionTitle>+ <SectionTitle>Tell {bot.fleetRole === "lead" ? "the fleet" : "it"} something</SectionTitle><div className="flex gap-2">- <Input value={message} onChange={(e) => setMessage(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") void send(); }} placeholder={`Message ${bot.name}…`} />- <Button variant="primary" onClick={() => void send()} disabled={!message.trim()}>Send</Button>+ <Input value={message} onChange={(e) => setMessage(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") void send(); }} placeholder={`Message ${bot.name}…`} className="h-10 text-base" />+ <Button variant="primary" size="lg" onClick={() => void send()} disabled={!message.trim()}>Send</Button></div>- {note && <p className="text-xs text-ink3">{note}</p>}+ {note && <p className="text-sm text-ink3">{note}</p>}</div>{bot.schedules && bot.schedules.length > 0 && (<div className="flex flex-col gap-2"><SectionTitle>Schedules</SectionTitle>{bot.schedules.map((s) => (- <div key={s.name} className="flex items-center gap-3 rounded-md border border-line bg-surface px-3 py-2 text-sm">+ <div key={s.name} className="flex items-center gap-3 rounded-lg border border-line bg-surface px-3.5 py-2.5 text-sm"><span className="text-ink">{s.name}</span><Mono>{s.cron}</Mono>- <span className="min-w-0 flex-1 truncate text-xs text-ink3">{s.prompt}</span>+ <span className="min-w-0 flex-1 truncate text-sm text-ink3">{s.prompt}</span></div>))}</div>@@ -156,18 +281,17 @@ function BotDetail({ id, status }: { id: string; status: BotStatus | null }) {<div className="flex flex-col gap-2"><SectionTitle>Recent runs</SectionTitle>- {journal.length === 0 && <p className="text-xs text-ink4">Nothing yet.</p>}- {journal.slice(0, 20).map((r) => (- <div key={r.runId} className="flex items-center gap-3 rounded-md border border-line bg-surface px-3 py-2 text-xs">+ {journal.length === 0 && <p className="text-sm text-ink4">Nothing yet.</p>}+ {journal.slice(0, 15).map((r) => (+ <div key={r.runId} className="flex items-center gap-3 rounded-lg border border-line bg-surface px-3.5 py-2.5 text-sm"><StateOrb state={r.state === "failed" ? "needs-you" : r.state === "running" ? "working" : "idle"} size={9} /><span className="w-24 shrink-0 text-ink2">{ago(r.startedAt)}</span>- <span className="w-16 shrink-0 text-ink3">{r.trigger}</span><span className="min-w-0 flex-1 truncate text-ink">{r.summary || r.error || r.state}</span><Mono>{Math.round(r.durationMs / 1000)}s · {(r.tokensIn + r.tokensOut).toLocaleString()} tok</Mono></div>))}</div>- </div>+ </>);}diff --git a/apps/desktop/src/views/chat/ChatView.tsx b/apps/desktop/src/views/chat/ChatView.tsxindex 9bce408b..ffcd5e46 100644--- a/apps/desktop/src/views/chat/ChatView.tsx+++ b/apps/desktop/src/views/chat/ChatView.tsx@@ -1,5 +1,5 @@import { PanelLeft, Plus } from "lucide-react";-import { useEffect, useRef } from "react";+import { useEffect, useLayoutEffect, useRef, useState } from "react";import { cx } from "~/lib/cx";import { useChat, useRuntimeState, useUi } from "~/app/store";import { answerPrompt, openThread } from "~/app/events";@@ -17,6 +17,8 @@ import { Composer } from "./Composer";* column, the composer at the bottom. The same component serves Code* mode with a different header.*/+const PAGE = 30;+export function ChatView({ mode, header }: { mode: "chat" | "code"; header?: React.ReactNode }) {const sidebar = useUi((s) => s.sidebar);const toggleSidebar = useUi((s) => s.toggleSidebar);@@ -30,6 +32,26 @@ export function ChatView({ mode, header }: { mode: "chat" | "code"; header?: Reaconst prompts = useRuntimeState((s) => s.prompts);const scroller = useRef<HTMLDivElement>(null);const stickToBottom = useRef(true);+ // Render only the newest PAGE messages; older ones come in a page at a+ // time when the reader scrolls near the top, keeping their place.+ const [visible, setVisible] = useState(PAGE);+ const prepend = useRef<{ height: number; top: number } | null>(null);+ useEffect(() => { setVisible(PAGE); stickToBottom.current = true; }, [activeId]);+ const shown = messages.length > visible ? messages.slice(messages.length - visible) : messages;+ const hiddenCount = messages.length - shown.length;+ useLayoutEffect(() => {+ const el = scroller.current;+ const p = prepend.current;+ if (!el || !p) return;+ el.scrollTop = p.top + (el.scrollHeight - p.height);+ prepend.current = null;+ }, [visible]);+ function loadEarlier() {+ const el = scroller.current;+ if (!el || hiddenCount <= 0) return;+ prepend.current = { height: el.scrollHeight, top: el.scrollTop };+ setVisible((v) => v + PAGE);+ }const title = threads.find((t) => t.id === activeId)?.title || (activeId ? "Untitled" : "New thread");const empty = !activeId && messages.length === 0 && !streaming;@@ -54,13 +76,13 @@ export function ChatView({ mode, header }: { mode: "chat" | "code"; header?: Rea{mode === "chat" && sidebar && <ThreadList />}<section className="flex min-w-0 flex-1 flex-col">- <header className="flex h-12 shrink-0 items-center gap-2 border-b border-line px-3" data-tauri-drag-region>+ <header className="flex h-[52px] shrink-0 items-center gap-2 border-b border-line px-3" data-tauri-drag-region>{mode === "chat" && (<Tooltip label={sidebar ? "Hide threads" : "Show threads"} shortcut="⌘B" side="bottom"><Button variant="ghost" size="sm" icon onClick={toggleSidebar} aria-label="Toggle threads"><PanelLeft size={16} /></Button></Tooltip>)}- <div className="min-w-0 flex-1 truncate text-sm font-medium text-ink">{header ?? title}</div>+ <div className="min-w-0 flex-1 truncate text-base font-medium text-ink">{header ?? title}</div><StateLabel state={agent} detail={step?.tool ? `${step.tool}${step.total ? ` ${step.current}/${step.total}` : ""}` : undefined} />{mode === "chat" && (<Tooltip label="New thread" shortcut="⌘N" side="bottom">@@ -71,21 +93,30 @@ export function ChatView({ mode, header }: { mode: "chat" | "code"; header?: Rea<divref={scroller}- onScroll={(e) => { const el = e.currentTarget; stickToBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80; }}+ onScroll={(e) => {+ const el = e.currentTarget;+ stickToBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;+ if (el.scrollTop < 160 && hiddenCount > 0 && !prepend.current) loadEarlier();+ }}className={cx("min-h-0 flex-1 overflow-y-auto", empty && "flex items-center justify-center")}>{empty ? (<EmptyPrompt mode={mode} />) : (- <div className="mx-auto flex w-full max-w-[760px] flex-col gap-6 px-6 py-6">+ <div className="mx-auto flex w-full max-w-[780px] flex-col gap-7 px-8 py-8">{loading && messages.length === 0 && <ThinkingDots label="Loading" />}- {messages.map((m) => <Message key={m.id} message={m} />)}+ {hiddenCount > 0 && (+ <button onClick={loadEarlier} className="self-center rounded-full border border-line px-3 py-1 text-xs text-ink3 hover:text-ink">+ {hiddenCount} earlier message{hiddenCount === 1 ? "" : "s"}+ </button>+ )}+ {shown.map((m) => <Message key={m.id} message={m} />)}{streaming && <StreamingMessage text={streaming} />}{!streaming && (agent === "thinking" || agent === "working") && (- <ThinkingDots label={agent === "working" && step?.tool ? `Running ${step.tool}` : "Thinking"} className="pl-9" />+ <ThinkingDots label={agent === "working" && step?.tool ? `Running ${step.tool}` : "Thinking"} className="pl-10" />)}{prompts.map((p) => (- <div key={p.id} className="pl-9">+ <div key={p.id} className="pl-10"><Approval prompt={p} onAnswer={(v) => answerPrompt(p, v)} /></div>))}@@ -102,8 +133,8 @@ export function ChatView({ mode, header }: { mode: "chat" | "code"; header?: Reafunction EmptyPrompt({ mode }: { mode: "chat" | "code" }) {return (<div className="flex flex-col items-center gap-2 px-6 pb-24 text-center">- <div className="text-xl font-medium tracking-tight text-ink">{mode === "code" ? "What should we build?" : "What's on your mind?"}</div>- <p className="max-w-[420px] text-sm text-ink3">+ <div className="text-2xl font-medium tracking-tight text-ink">{mode === "code" ? "What should we build?" : "What's on your mind?"}</div>+ <p className="max-w-[460px] text-base text-ink3">{mode === "code" ? "Mercury works in your workspace: reads, edits, runs, and asks before anything that can't be undone." : "Ask, delegate, or think out loud. Mercury remembers what matters."}</p></div>diff --git a/apps/desktop/src/views/chat/Composer.tsx b/apps/desktop/src/views/chat/Composer.tsxindex 43ed64a6..5e304a4b 100644--- a/apps/desktop/src/views/chat/Composer.tsx+++ b/apps/desktop/src/views/chat/Composer.tsx@@ -48,8 +48,8 @@ export function Composer({ mode }: { mode: "chat" | "code" }) {const busy = agent === "thinking" || agent === "streaming" || agent === "working";return (- <div className="shrink-0 px-6 pb-5 pt-2">- <div className="mx-auto w-full max-w-[760px]">+ <div className="shrink-0 px-8 pb-6 pt-2">+ <div className="mx-auto w-full max-w-[780px]">{error && <div className="mb-2 text-xs text-red">{error}</div>}<div className={cx("rounded-xl border border-line bg-surface shadow-sm transition-colors focus-within:border-line-strong")}><textarea@@ -62,7 +62,7 @@ export function Composer({ mode }: { mode: "chat" | "code" }) {placeholder={mode === "code" ? "Describe the change…" : "Message Mercury…"}rows={1}disabled={!connected}- className="block w-full resize-none bg-transparent px-4 pt-3.5 text-base leading-[22px] text-ink placeholder:text-ink4 disabled:opacity-60"+ className="block w-full resize-none bg-transparent px-4 pt-4 text-md leading-[26px] text-ink placeholder:text-ink4 disabled:opacity-60"aria-label="Message"/><div className="flex items-center gap-1 px-2 pb-2 pt-1">@@ -71,7 +71,7 @@ export function Composer({ mode }: { mode: "chat" | "code" }) {<div className="flex-1" />{busy && <span className="mr-1 text-2xs text-ink4">{agent === "streaming" ? "answering" : agent === "working" ? "working" : "thinking"}…</span>}<Tooltip label="Send" shortcut="↵" side="top">- <Button variant="primary" size="sm" icon onClick={() => void submit()} disabled={!text.trim() || !connected} loading={sending} aria-label="Send">+ <Button variant="primary" size="md" icon onClick={() => void submit()} disabled={!text.trim() || !connected} loading={sending} aria-label="Send"><ArrowUp size={16} strokeWidth={2.2} /></Button></Tooltip>@@ -104,7 +104,7 @@ function ModelPicker() {<Menuside="top"trigger={- <button className="flex h-7 items-center gap-1 rounded-md px-2 text-xs text-ink2 hover:bg-ink/[0.06] hover:text-ink" aria-label="Model">+ <button className="flex h-8 items-center gap-1 rounded-md px-2 text-sm text-ink2 hover:bg-ink/[0.06] hover:text-ink" aria-label="Model"><span className="max-w-[180px] truncate">{label}</span><ChevronDown size={12} className="text-ink4" /></button>@@ -137,7 +137,7 @@ function ModePicker() {<Menuside="top"trigger={- <button className={cx("flex h-7 items-center gap-1.5 rounded-md px-2 text-xs hover:bg-ink/[0.06]", allowAll ? "text-accent" : "text-amber")} aria-label="Approval mode">+ <button className={cx("flex h-8 items-center gap-1.5 rounded-md px-2 text-sm hover:bg-ink/[0.06]", allowAll ? "text-accent" : "text-amber")} aria-label="Approval mode">{allowAll ? <ShieldCheck size={13} /> : <Shield size={13} />}{settings ? (allowAll ? "Allow All" : "Ask Me") : "…"}</button>diff --git a/apps/desktop/src/views/chat/Message.test.ts b/apps/desktop/src/views/chat/Message.test.tsnew file mode 100644index 00000000..153c1f9c--- /dev/null+++ b/apps/desktop/src/views/chat/Message.test.ts@@ -0,0 +1,13 @@+import { describe, expect, it } from "vitest";+import { parseToolActivity } from "./Message";++describe("tool activity", () => {+ it("turns the runtime's stored tool summary into rows", () => {+ const rows = parseToolActivity("[Tool activity in my previous turn]\n- use_skill name=web-search → ok (42 lines)\n- web_search query=weather in Kashmir → ok (22 lines)\n- fetch_url url=https://x.example → error: timeout");+ expect(rows).toEqual([+ { tool: "use_skill", args: "name=web-search", status: "done", detail: "(42 lines)" },+ { tool: "web_search", args: "query=weather in Kashmir", status: "done", detail: "(22 lines)" },+ { tool: "fetch_url", args: "url=https://x.example", status: "error", detail: "error: timeout" },+ ]);+ });+});diff --git a/apps/desktop/src/views/chat/Message.tsx b/apps/desktop/src/views/chat/Message.tsxindex fbcc8e25..ca3c33a3 100644--- a/apps/desktop/src/views/chat/Message.tsx+++ b/apps/desktop/src/views/chat/Message.tsx@@ -1,35 +1,44 @@-import { memo } from "react";+import { ChevronRight, Wrench } from "lucide-react";+import { memo, useState } from "react";import type { ChatMessage } from "~/api/types";import { Mark } from "~/components/Logo";import { Markdown } from "~/components/Markdown";import { StreamCaret } from "~/components/indicators/Thinking";import { ActionResult } from "~/components/indicators/Activity";+import { cx } from "~/lib/cx";/**- * No bubbles. The user's turn reads like a heading; the agent's answer is- * prose beneath it, with the mark in the gutter. System notes are muted.+ * One entry in a conversation. Each kind the runtime stores gets its own+ * rendering:+ * - user a short heading-weight line, no bubble+ * - assistant prose (markdown) beside the mark+ * - tool-call a collapsed "used N tools" row; open it for each call+ * - system a muted note*/export const Message = memo(function Message({ message }: { message: ChatMessage }) {if (message.role === "user") {return (- <div className="pl-9">- <p className="whitespace-pre-wrap text-md font-medium leading-relaxed tracking-[-0.005em] text-ink" data-selectable>{message.content}</p>+ <div className="pl-10 pt-2">+ <p className="whitespace-pre-wrap text-lg font-medium leading-[1.55] tracking-[-0.01em] text-ink" data-selectable>{message.content}</p></div>);}+ if (message.kind === "tool-call" || message.role === "tool") {+ return <ToolActivity content={message.content} />;+ }if (message.role === "system") {return (- <div className="pl-9">- <p className="rounded-md border border-line bg-surface px-3 py-2 text-xs text-ink3" data-selectable>{message.content}</p>+ <div className="pl-10">+ <p className="rounded-md border border-line bg-surface px-3 py-2 text-sm text-ink3" data-selectable>{message.content}</p></div>);}return (- <div className="flex gap-3">- <span className="mt-[3px] flex h-6 w-6 shrink-0 items-center justify-center" aria-hidden="true"><Mark size={20} /></span>+ <div className="flex gap-4">+ <span className="mt-1 flex h-6 w-6 shrink-0 items-center justify-center" aria-hidden="true"><Mark size={22} /></span><div className="min-w-0 flex-1">{message.steps && message.steps.length > 0 && (- <div className="mb-2 flex flex-col gap-1">+ <div className="mb-3 flex flex-col gap-1">{message.steps.map((s, i) => <ActionResult key={i} tool={s.tool} status={s.status} detail={s.result} />)}</div>)}@@ -39,10 +48,60 @@ export const Message = memo(function Message({ message }: { message: ChatMessage);});+interface ToolLine {+ tool: string;+ args: string;+ status: "done" | "error";+ detail: string;+}++/** "[Tool activity …]\n- web_search query=… → ok (22 lines)" → structured rows. */+export function parseToolActivity(content: string): ToolLine[] {+ const lines: ToolLine[] = [];+ for (const raw of content.split(/\r?\n/)) {+ const line = raw.trim();+ if (!line.startsWith("- ")) continue;+ const body = line.slice(2);+ const arrow = body.lastIndexOf("→");+ const head = arrow === -1 ? body : body.slice(0, arrow).trim();+ const tail = arrow === -1 ? "" : body.slice(arrow + 1).trim();+ const space = head.indexOf(" ");+ const tool = space === -1 ? head : head.slice(0, space);+ const args = space === -1 ? "" : head.slice(space + 1);+ const failed = /^(error|failed|denied|blocked)/i.test(tail);+ lines.push({ tool, args, status: failed ? "error" : "done", detail: tail.replace(/^ok\s*/i, "") });+ }+ return lines;+}++function ToolActivity({ content }: { content: string }) {+ const [open, setOpen] = useState(false);+ const calls = parseToolActivity(content);+ if (calls.length === 0) return null;+ const names = [...new Set(calls.map((c) => c.tool))];+ const failed = calls.filter((c) => c.status === "error").length;+ return (+ <div className="pl-10">+ <button onClick={() => setOpen((o) => !o)} className="flex items-center gap-2 rounded-md py-1 text-sm text-ink3 hover:text-ink" aria-expanded={open}>+ <ChevronRight size={14} className={cx("transition-transform", open && "rotate-90")} aria-hidden="true" />+ <Wrench size={13} aria-hidden="true" />+ <span>Used {calls.length} tool{calls.length === 1 ? "" : "s"}</span>+ <span className="truncate font-mono text-xs text-ink4">{names.slice(0, 4).join(" · ")}{names.length > 4 ? " …" : ""}</span>+ {failed > 0 && <span className="text-xs text-red">{failed} failed</span>}+ </button>+ {open && (+ <div className="mt-1 flex flex-col gap-1 pl-5">+ {calls.map((c, i) => <ActionResult key={i} tool={c.tool} status={c.status} detail={[c.args, c.detail].filter(Boolean).join(" · ")} />)}+ </div>+ )}+ </div>+ );+}+export function StreamingMessage({ text }: { text: string }) {return (- <div className="flex gap-3">- <span className="mt-[3px] flex h-6 w-6 shrink-0 items-center justify-center" aria-hidden="true"><Mark size={20} /></span>+ <div className="flex gap-4">+ <span className="mt-1 flex h-6 w-6 shrink-0 items-center justify-center" aria-hidden="true"><Mark size={22} /></span><div className="min-w-0 flex-1"><Markdown text={text} /><StreamCaret />diff --git a/apps/desktop/src/views/chat/ThreadList.tsx b/apps/desktop/src/views/chat/ThreadList.tsxindex 2469d278..fbbb3096 100644--- a/apps/desktop/src/views/chat/ThreadList.tsx+++ b/apps/desktop/src/views/chat/ThreadList.tsx@@ -1,17 +1,43 @@-import { Trash2 } from "lucide-react";-import { useMemo } from "react";+import { Search, Trash2 } from "lucide-react";+import { useEffect, useMemo, useRef, useState } from "react";import { cx } from "~/lib/cx";import * as api from "~/api/mercury";import type { ChatThread } from "~/api/types";import { useChat } from "~/app/store";import { openThread, refreshThreads } from "~/app/events";-/** Threads, newest first, grouped by day. Quiet rows; the active one is marked, not coloured. */+const PAGE = 40;++/**+ * Threads, most recently active first, grouped by day. Renders a page at a+ * time and adds the next page as the list scrolls; a filter box searches+ * all of them by title.+ */export function ThreadList() {const threads = useChat((s) => s.threads);const activeId = useChat((s) => s.activeId);+ const [limit, setLimit] = useState(PAGE);+ const [query, setQuery] = useState("");+ const sentinel = useRef<HTMLDivElement>(null);++ const filtered = useMemo(() => {+ const q = query.trim().toLowerCase();+ const sorted = [...threads].sort((a, b) => stamp(b).localeCompare(stamp(a)));+ return q ? sorted.filter((t) => (t.title || t.alias || "").toLowerCase().includes(q)) : sorted;+ }, [threads, query]);+ const page = filtered.slice(0, limit);+ const groups = useMemo(() => groupByDay(page), [page]);- const groups = useMemo(() => groupByDay(threads), [threads]);+ useEffect(() => { setLimit(PAGE); }, [query]);+ useEffect(() => {+ const el = sentinel.current;+ if (!el) return;+ const io = new IntersectionObserver((entries) => {+ if (entries.some((e) => e.isIntersecting)) setLimit((l) => (l < filtered.length ? l + PAGE : l));+ }, { rootMargin: "200px" });+ io.observe(el);+ return () => io.disconnect();+ }, [filtered.length]);async function remove(t: ChatThread) {try {@@ -22,38 +48,46 @@ export function ThreadList() {}return (- <aside className="flex h-full w-[232px] shrink-0 flex-col border-r border-line bg-soft">- <div className="h-12 shrink-0" data-tauri-drag-region />+ <aside className="flex h-full w-[260px] shrink-0 flex-col border-r border-line bg-soft">+ <div className="flex h-[52px] shrink-0 items-center px-3" data-tauri-drag-region>+ <label className="flex h-8 w-full items-center gap-2 rounded-md border border-line bg-surface px-2.5 text-ink4 focus-within:border-line-strong">+ <Search size={14} aria-hidden="true" />+ <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Search threads" className="w-full bg-transparent text-sm text-ink placeholder:text-ink4" aria-label="Search threads" />+ </label>+ </div><div className="min-h-0 flex-1 overflow-y-auto px-2 pb-3">- {groups.length === 0 && <p className="px-2 pt-2 text-xs text-ink4">No threads yet.</p>}+ {filtered.length === 0 && <p className="px-2 pt-2 text-sm text-ink4">{query ? "No matching threads." : "No threads yet."}</p>}{groups.map(([day, list]) => (- <div key={day} className="mb-3">- <div className="px-2 pb-1 text-2xs font-medium uppercase tracking-wider text-ink4">{day}</div>+ <div key={day} className="mb-4">+ <div className="px-2.5 pb-1 text-2xs font-medium uppercase tracking-wider text-ink4">{day}</div>{list.map((t) => (<div key={t.id} className={cx("group flex items-center rounded-md", activeId === t.id ? "bg-ink/[0.07]" : "hover:bg-ink/[0.05]")}>- <button onClick={() => void openThread(t.id)} className="min-w-0 flex-1 truncate px-2.5 py-1.5 text-left text-sm text-ink2 group-hover:text-ink" title={t.title || "Untitled"}>- <span className={cx(activeId === t.id && "text-ink")}>{t.title || "Untitled"}</span>+ <button onClick={() => void openThread(t.id)} className="min-w-0 flex-1 truncate px-2.5 py-[7px] text-left text-sm" title={t.title || "Untitled"}>+ <span className={activeId === t.id ? "text-ink" : "text-ink2 group-hover:text-ink"}>{t.title || "Untitled"}</span></button><button onClick={() => void remove(t)} className="mr-1 hidden rounded p-1 text-ink4 hover:text-red group-hover:block" aria-label="Delete thread">- <Trash2 size={13} />+ <Trash2 size={14} /></button></div>))}</div>))}+ <div ref={sentinel} className="h-px" aria-hidden="true" /></div></aside>);}+function stamp(t: ChatThread): string {+ return t.updatedAt || t.createdAt || "";+}+function groupByDay(threads: ChatThread[]): Array<[string, ChatThread[]]> {- const sorted = [...threads].sort((a, b) => (b.createdAt || "").localeCompare(a.createdAt || ""));const out = new Map<string, ChatThread[]>();- const today = new Date();- for (const t of sorted) {- const d = new Date(t.createdAt);- const diff = Math.floor((startOfDay(today) - startOfDay(d)) / 86_400_000);- const key = Number.isNaN(diff) ? "Earlier" : diff === 0 ? "Today" : diff === 1 ? "Yesterday" : diff < 7 ? "This week" : "Earlier";+ const today = startOfDay(new Date());+ for (const t of threads) {+ const diff = Math.floor((today - startOfDay(new Date(stamp(t)))) / 86_400_000);+ const key = Number.isNaN(diff) ? "Earlier" : diff <= 0 ? "Today" : diff === 1 ? "Yesterday" : diff < 7 ? "Previous 7 days" : diff < 30 ? "Previous 30 days" : "Older";const list = out.get(key) ?? [];list.push(t);out.set(key, list);diff --git a/apps/desktop/src/views/code/CodeView.tsx b/apps/desktop/src/views/code/CodeView.tsxindex 643de653..e29534ef 100644--- a/apps/desktop/src/views/code/CodeView.tsx+++ b/apps/desktop/src/views/code/CodeView.tsx@@ -1,17 +1,29 @@import { useEffect, useState } from "react";import * as api from "~/api/mercury";-import type { ChatSettings, CodeStatus } from "~/api/types";+import type { ChatSettings, CodeMode, CodeStatus } from "~/api/types";import { Segmented, Mono } from "~/components/ui/bits";+import { Tooltip } from "~/components/ui/Tooltip";import { ChatView } from "~/views/chat/ChatView";/**- * Code: the same conversation, with the runtime in plan or execute mode- * against the workspace. The header carries the mode and the workspace;- * nothing else changes, which is the point.+ * Code: the same conversation with the runtime's programming mode on,+ * driven by /api/code/status and /api/code/set.+ * Off plain chat+ * Auto Mercury decides when a request is a coding task+ * Plan it plans and waits for you before changing anything+ * Execute it plans and carries out the plan*/+const MODES: Array<{ value: CodeMode; label: string; hint: string }> = [+ { value: "off", label: "Off", hint: "Plain chat" },+ { value: "auto", label: "Auto", hint: "Mercury decides when a request is a coding task" },+ { value: "plan", label: "Plan", hint: "Plans first and waits for you" },+ { value: "execute", label: "Execute", hint: "Plans and carries it out" },+];+export function CodeView() {const [status, setStatus] = useState<CodeStatus | null>(null);const [settings, setSettings] = useState<ChatSettings | null>(null);+ const [error, setError] = useState<string | null>(null);async function load() {try { setStatus(await api.code.status()); } catch { setStatus(null); }@@ -19,20 +31,24 @@ export function CodeView() {}useEffect(() => { void load(); }, []);- async function setMode(state: "off" | "plan" | "execute") {- try { await api.code.set(state); } catch { /* keep */ }+ async function setMode(state: CodeMode) {+ setError(null);+ try { await api.code.set(state); } catch (err) { setError(err instanceof Error ? err.message : String(err)); }void load();}+ const current = MODES.find((m) => m.value === (status?.state ?? "off"));const header = (<div className="flex items-center gap-3">- <Segmented- value={status?.state ?? "off"}- onChange={(v) => void setMode(v)}- options={[{ value: "off", label: "Off" }, { value: "plan", label: "Plan" }, { value: "execute", label: "Execute" }]}- />+ <Tooltip label={current?.hint ?? ""} side="bottom">+ <span>+ <Segmented<CodeMode> value={status?.state ?? "off"} onChange={(v) => void setMode(v)} options={MODES.map(({ value, label }) => ({ value, label }))} />+ </span>+ </Tooltip>+ {status?.statusText && <span className="truncate text-xs text-ink3">{status.statusText}</span>}{settings?.workspace && <Mono className="truncate">{settings.workspace}</Mono>}- {status && !status.available && <span className="text-xs text-ink4">Code mode is not available on this runtime.</span>}+ {status && !status.available && <span className="text-xs text-ink4">Not available on this runtime.</span>}+ {error && <span className="text-xs text-red">{error}</span>}</div>);diff --git a/apps/desktop/src/views/plugins/PluginsView.tsx b/apps/desktop/src/views/plugins/PluginsView.tsxindex 68ec82d2..08859fa0 100644--- a/apps/desktop/src/views/plugins/PluginsView.tsx+++ b/apps/desktop/src/views/plugins/PluginsView.tsx@@ -54,7 +54,7 @@ export function PluginsView() {return (<div className="flex h-full min-h-0 flex-col">- <header className="flex h-12 shrink-0 items-center gap-3 border-b border-line px-4" data-tauri-drag-region>+ <header className="flex h-[52px] shrink-0 items-center gap-3 border-b border-line px-4" data-tauri-drag-region><span className="text-sm font-medium text-ink">Plugins</span><Segmented value={tab} onChange={setTab} options={[{ value: "installed", label: `Installed ${installed.length}` }, { value: "catalog", label: `Catalog ${catalog.length}` }, { value: "mcp", label: `MCP ${servers.length}` }]} />{safeMode && <Badge tone="amber">safe mode</Badge>}diff --git a/apps/desktop/src/views/settings/SettingsView.tsx b/apps/desktop/src/views/settings/SettingsView.tsxindex 51007a8a..e2cb3605 100644--- a/apps/desktop/src/views/settings/SettingsView.tsx+++ b/apps/desktop/src/views/settings/SettingsView.tsx@@ -16,7 +16,7 @@ import { StateOrb } from "~/components/indicators/StateOrb";export function SettingsView({ connection, health, onSwitchConnection }: { connection: Connection; health: HealthInfo; onSwitchConnection: () => void }) {return (<div className="flex h-full min-h-0 flex-col">- <header className="flex h-12 shrink-0 items-center px-4" data-tauri-drag-region>+ <header className="flex h-[52px] shrink-0 items-center px-4" data-tauri-drag-region><span className="text-sm font-medium text-ink">Settings</span></header><div className="min-h-0 flex-1 overflow-y-auto">diff --git a/apps/desktop/src/views/skills/SkillsView.tsx b/apps/desktop/src/views/skills/SkillsView.tsxindex 396862a6..a7098689 100644--- a/apps/desktop/src/views/skills/SkillsView.tsx+++ b/apps/desktop/src/views/skills/SkillsView.tsx@@ -39,7 +39,7 @@ export function SkillsView() {return (<div className="flex h-full min-h-0 flex-col">- <header className="flex h-12 shrink-0 items-center gap-3 border-b border-line px-4" data-tauri-drag-region>+ <header className="flex h-[52px] shrink-0 items-center gap-3 border-b border-line px-4" data-tauri-drag-region><span className="text-sm font-medium text-ink">Skills</span><span className="text-xs text-ink3">{active} of {skills.length} active</span><div className="flex-1" />diff --git a/apps/desktop/tailwind.config.js b/apps/desktop/tailwind.config.jsindex 67623dfc..3b0402c8 100644--- a/apps/desktop/tailwind.config.js+++ b/apps/desktop/tailwind.config.js@@ -41,14 +41,16 @@ export default {},extend: {fontSize: {- "2xs": ["11px", "16px"],- xs: ["12px", "16px"],- sm: ["13px", "20px"],- base: ["14px", "22px"],- md: ["15px", "24px"],- lg: ["17px", "26px"],- xl: ["20px", "28px"],- "2xl": ["24px", "32px"],+ // Reading sizes for a desktop app viewed at arm's length: UI text 14,+ // body 15, answers 16 (see styles/base.css .prose).+ "2xs": ["12px", "16px"],+ xs: ["13px", "18px"],+ sm: ["14px", "20px"],+ base: ["15px", "24px"],+ md: ["16px", "26px"],+ lg: ["18px", "28px"],+ xl: ["22px", "30px"],+ "2xl": ["26px", "34px"],},keyframes: {"dot-pulse": { "0%, 80%, 100%": { opacity: "0.25" }, "40%": { opacity: "1" } },diff --git a/src/web/cors.ts b/src/web/cors.tsindex 150d87fd..2daf8751 100644--- a/src/web/cors.ts+++ b/src/web/cors.ts@@ -54,7 +54,7 @@ export function apiCors(extra: readonly string[] | undefined): MiddlewareHandlerreturn cors({origin: (origin) => (allowed.has(origin) ? origin : null),allowMethods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],- allowHeaders: ['Authorization', 'Content-Type', 'Accept', 'Last-Event-ID'],+ allowHeaders: ['Authorization', 'Content-Type', 'Accept', 'Last-Event-ID', 'Cache-Control'],exposeHeaders: ['Content-Type', 'Content-Disposition'],maxAge: 600,credentials: false,