Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat(desktop): Mercury Code start screen in the terminal-agent style

Salman Qureshiae5558df41a8
diff --git a/apps/desktop/src/app/health.ts b/apps/desktop/src/app/health.ts
new file mode 100644
index 00000000..1834dee2
--- /dev/null
+++ b/apps/desktop/src/app/health.ts
@@ -0,0 +1,12 @@
+import { create } from "zustand";
+import type { HealthInfo } from "~/api/types";
+
+/** The connected runtime's /api/health, set once the connection is up. */
+export const useHealthStore = create<{ health: HealthInfo | null; set(h: HealthInfo | null): void }>((set) => ({
+ health: null,
+ set: (health) => set({ health }),
+}));
+
+export function useHealth(): HealthInfo | null {
+ return useHealthStore((s) => s.health);
+}
diff --git a/apps/desktop/src/layout/Workspace.tsx b/apps/desktop/src/layout/Workspace.tsx
index 7114915e..7c46ed3f 100644
--- a/apps/desktop/src/layout/Workspace.tsx
+++ b/apps/desktop/src/layout/Workspace.tsx
@@ -3,6 +3,7 @@ import { useUi, type View } from "~/app/store";
import { useRuntimeEvents, refreshBots, refreshThreads } from "~/app/events";
import { usePulsePolling } from "~/app/pulse";
import { useVoiceFeed } from "~/app/voice";
+import { useHealthStore } from "~/app/health";
import { registerBuiltinStatusItems } from "~/extensions/builtin-status";
import type { Connection } from "~/shell/connections";
import type { HealthInfo } from "~/api/types";
@@ -30,6 +31,8 @@ export function Workspace({ connection, health, onSwitchConnection }: { connecti
usePulsePolling(connection.id);
useVoiceFeed(connection.id);
+ useEffect(() => { useHealthStore.getState().set(health); }, [health]);
+
useEffect(() => {
void refreshThreads();
void refreshBots();
diff --git a/apps/desktop/src/views/chat/Composer.tsx b/apps/desktop/src/views/chat/Composer.tsx
index 4fb37eaf..47284cb0 100644
--- a/apps/desktop/src/views/chat/Composer.tsx
+++ b/apps/desktop/src/views/chat/Composer.tsx
@@ -38,9 +38,17 @@ export interface ComposerProps {
extra?: React.ReactNode;
/** Block sending with this reason (e.g. no folder chosen). */
blockedReason?: string;
+ /** Terminal look (Mercury Code): monospace, a ">" prompt. */
+ mono?: boolean;
+ /** Text to place in the box (e.g. a clicked suggestion). */
+ draft?: string | null;
+ onDraftConsumed?: () => void;
+ /** Shift+Tab cycles the mode; the chip shows it. */
+ onCycleMode?: () => void;
+ modeLabel?: string;
}
-export function Composer({ surface, placeholder, code, extra, blockedReason }: ComposerProps) {
+export function Composer({ surface, placeholder, code, extra, blockedReason, mono, draft, onDraftConsumed, onCycleMode, modeLabel }: ComposerProps) {
const [text, setText] = useState("");
const [files, setFiles] = useState<Pending[]>([]);
const [dragging, setDragging] = useState(false);
@@ -51,6 +59,13 @@ export function Composer({ surface, placeholder, code, extra, blockedReason }: C
const agent = useConversation((s) => s.agent);
const connected = useRuntimeState((s) => s.connected);
+ useEffect(() => {
+ if (draft == null) return;
+ setText(draft);
+ onDraftConsumed?.();
+ requestAnimationFrame(() => { const el = ref.current; if (el) { el.focus(); el.setSelectionRange(el.value.length, el.value.length); } });
+ }, [draft, onDraftConsumed]);
+
// Fit the box to its text. Re-measured when the text changes AND when the
// box's width changes or it becomes visible (a hidden view measures 0 and a
// narrower layout wraps more lines), so text never runs under the controls.
@@ -157,6 +172,8 @@ export function Composer({ surface, placeholder, code, extra, blockedReason }: C
))}
</div>
)}
+ <div className="flex">
+ {mono && <span aria-hidden="true" className="pointer-events-none select-none pl-5 pt-4 font-mono text-md leading-[26px] text-accent">&gt;</span>}
<textarea
ref={ref}
value={text}
@@ -165,13 +182,15 @@ export function Composer({ surface, placeholder, code, extra, blockedReason }: C
onKeyDown={(e) => {
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault(); void submit(); }
if (e.key === "Escape" && text) { e.preventDefault(); setText(""); }
+ if (e.key === "Tab" && e.shiftKey && onCycleMode) { e.preventDefault(); onCycleMode(); }
}}
placeholder={!connected ? "Waiting for Mercury…" : blockedReason ?? placeholder}
rows={1}
disabled={!connected}
- className="block max-h-[240px] w-full resize-none overflow-y-auto bg-transparent px-5 pb-1 pt-4 text-md leading-[26px] text-ink caret-accent placeholder:truncate placeholder:text-ink4"
+ className={cx("block max-h-[240px] w-full resize-none overflow-y-auto bg-transparent pb-1 pt-4 text-md leading-[26px] text-ink caret-accent placeholder:truncate placeholder:text-ink4", mono ? "pl-3 pr-5 font-mono text-[14.5px]" : "px-5")}
aria-label="Message"
/>
+ </div>
<div className="flex flex-wrap items-center gap-1 px-3 pb-3 pt-1.5">
<Tooltip label="Attach images or PDFs" side="top">
<Button variant="ghost" size="md" icon onClick={() => picker.current?.click()} disabled={!connected || files.length >= MAX_FILES} aria-label="Attach">
@@ -180,6 +199,13 @@ export function Composer({ surface, placeholder, code, extra, blockedReason }: C
</Tooltip>
<input ref={picker} type="file" accept="image/*,application/pdf" multiple hidden onChange={(e) => { if (e.target.files) void addFiles(e.target.files); e.target.value = ""; }} />
{extra}
+ {modeLabel && (
+ <Tooltip label="Switch mode" shortcut="⇧⇥" side="top">
+ <button onClick={onCycleMode} className="flex h-8 items-center gap-1.5 rounded-md px-2 font-mono text-sm text-cyan hover:bg-ink/[0.06]" aria-label="Switch mode">
+ <span className="text-ink4">mode</span> {modeLabel}
+ </button>
+ </Tooltip>
+ )}
<ModelPicker />
{surface === "chat" && <ModePicker />}
<div className="flex-1" />
diff --git a/apps/desktop/src/views/code/CodeHome.tsx b/apps/desktop/src/views/code/CodeHome.tsx
new file mode 100644
index 00000000..68914abc
--- /dev/null
+++ b/apps/desktop/src/views/code/CodeHome.tsx
@@ -0,0 +1,116 @@
+import { Check, FolderOpen, GitBranch } from "lucide-react";
+import type { ChatThread } from "~/api/types";
+import { PixelWordmark } from "~/components/PixelWordmark";
+import { shortPath } from "./CodeView";
+import { cx } from "~/lib/cx";
+
+/**
+ * The Mercury Code start screen, in the shape of the terminal coding agents
+ * (Claude Code's welcome box, OpenCode's centred wordmark): monospace, the
+ * pixel wordmark, a bordered welcome card with the working directory,
+ * numbered first steps that tick themselves off, recent sessions in this
+ * folder, and only shortcuts that actually work.
+ */
+export function CodeHome({ folder, branch, version, model, mode, recent, onPickFolder, onOpenSession, onSuggest }: {
+ folder: string | null;
+ branch: string;
+ version: string;
+ model: string;
+ mode: string;
+ recent: ChatThread[];
+ onPickFolder: () => void;
+ onOpenSession: (id: string) => void;
+ onSuggest: (text: string) => void;
+}) {
+ const steps = [
+ { done: Boolean(folder), text: folder ? <>Working in <span className="text-ink">{shortPath(folder)}</span></> : <><button onClick={onPickFolder} className="text-accent underline-offset-2 hover:underline">Open a project folder</button> to work in</> },
+ { done: false, text: <>Ask for a change, a fix, a review, or an explanation of the code</> },
+ { done: false, text: <>Be specific: name files, paste the error, say what "done" looks like</> },
+ { done: false, text: <>Press <Key>shift+tab</Key> to switch mode: <span className="text-ink">auto</span> builds in one go, <span className="text-ink">plan</span> waits for your go-ahead</> },
+ ];
+ const suggestions = [
+ "explain how this project is structured",
+ "find and fix the failing tests",
+ "review my uncommitted changes",
+ ];
+
+ return (
+ <div className="flex w-full max-w-[760px] flex-col gap-6 px-8 pb-16 font-mono text-[13.5px] leading-relaxed text-ink2">
+ <div className="flex flex-col items-center gap-2">
+ <PixelWordmark cell={8} />
+ <div className="text-xs text-ink4">v{version || "?"}{model ? ` · ${model}` : ""} · {mode}</div>
+ </div>
+
+ <div className="rounded-xl border border-accent/40 px-5 py-4">
+ <div className="text-ink"><span className="text-accent">✻</span> Welcome to <span className="font-semibold">Mercury Code</span></div>
+ <div className="mt-3 text-ink3">Mercury reads, edits, runs and checks its work in your project, and asks before anything that can't be undone.</div>
+ <div className="mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 text-ink3">
+ <span className="flex items-center gap-1.5"><FolderOpen size={13} />cwd: {folder ? <span className="text-ink">{shortPath(folder)}</span> : <button onClick={onPickFolder} className="text-accent hover:underline">not set</button>}</span>
+ {branch && <span className="flex items-center gap-1.5"><GitBranch size={13} />{branch}</span>}
+ </div>
+ </div>
+
+ <div>
+ <div className="mb-2 text-ink">Tips for getting started:</div>
+ <ol className="flex flex-col gap-1.5">
+ {steps.map((s, i) => (
+ <li key={i} className="flex gap-3">
+ <span className={cx("w-5 shrink-0 text-right", s.done ? "text-accent" : "text-ink4")}>{s.done ? <Check size={14} className="ml-auto mt-[3px]" /> : `${i + 1}.`}</span>
+ <span className={cx(s.done && "text-ink3")}>{s.text}</span>
+ </li>
+ ))}
+ </ol>
+ </div>
+
+ {folder && (
+ <div>
+ <div className="mb-2 text-ink">Try:</div>
+ <div className="flex flex-col gap-1">
+ {suggestions.map((t) => (
+ <button key={t} onClick={() => onSuggest(t)} className="w-fit text-left text-ink3 hover:text-ink">
+ <span className="text-ink4">&gt;</span> {t}
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {recent.length > 0 && (
+ <div>
+ <div className="mb-2 text-ink">Recent sessions{folder ? " in this folder" : ""}:</div>
+ <div className="flex flex-col gap-1">
+ {recent.slice(0, 4).map((t) => (
+ <button key={t.id} onClick={() => onOpenSession(t.id)} className="flex w-full items-center gap-3 text-left text-ink3 hover:text-ink">
+ <span className="text-ink4">↻</span>
+ <span className="min-w-0 flex-1 truncate">{(t.title || "Untitled").replace(/^Code · /, "")}</span>
+ <span className="shrink-0 text-xs text-ink4">{ago(t.updatedAt || t.createdAt)}</span>
+ </button>
+ ))}
+ </div>
+ </div>
+ )}
+
+ <div className="flex flex-wrap gap-x-5 gap-y-1 text-xs text-ink4">
+ <span><Key>enter</Key> send</span>
+ <span><Key>shift+enter</Key> new line</span>
+ <span><Key>shift+tab</Key> mode</span>
+ <span><Key>⌘n</Key> new session</span>
+ <span><Key>esc</Key> clear</span>
+ </div>
+ </div>
+ );
+}
+
+function Key({ children }: { children: React.ReactNode }) {
+ return <kbd className="rounded border border-line px-1 py-px text-[11.5px] text-ink3">{children}</kbd>;
+}
+
+function ago(iso: string): string {
+ const ms = Date.now() - new Date(iso).getTime();
+ if (!Number.isFinite(ms)) return "";
+ const m = Math.round(ms / 60_000);
+ if (m < 60) return `${Math.max(1, m)}m ago`;
+ const h = Math.round(m / 60);
+ if (h < 48) return `${h}h ago`;
+ return `${Math.round(h / 24)}d ago`;
+}
diff --git a/apps/desktop/src/views/code/CodeView.tsx b/apps/desktop/src/views/code/CodeView.tsx
index 8307d8dd..97756654 100644
--- a/apps/desktop/src/views/code/CodeView.tsx
+++ b/apps/desktop/src/views/code/CodeView.tsx
@@ -7,8 +7,9 @@ import { conversations, ConversationContext, useCodeSessions } from "~/app/conve
import { openThread, type CodeTurn } from "~/app/events";
import { Button } from "~/components/ui/Button";
import { Tooltip } from "~/components/ui/Tooltip";
-import { Segmented } from "~/components/ui/bits";
-import { PixelWordmark } from "~/components/PixelWordmark";
+import { CodeHome } from "./CodeHome";
+import { useRuntimeState } from "~/app/store";
+import { useHealth } from "~/app/health";
import { ThreadList } from "~/views/chat/ThreadList";
import { Conversation } from "~/views/chat/Conversation";
import { useConnections } from "~/shell/connections";
@@ -44,6 +45,10 @@ export function CodeView() {
const [pendingFolder, setPendingFolder] = useState<string | null>(null);
const [picking, setPicking] = useState(false);
const [branch, setBranch] = useState<string>("");
+ const [draft, setDraft] = useState<string | null>(null);
+ const model = useRuntimeState((s) => s.model);
+ const health = useHealth();
+ const cycleMode = () => setMode((m) => MODES[(MODES.findIndex((x) => x.value === m) + 1) % MODES.length].value);
useEffect(() => { if (connection) loadSessions(`${connection.id}@${connection.baseUrl}`); }, [connection?.id, connection?.baseUrl, loadSessions]);
@@ -103,26 +108,25 @@ export function CodeView() {
</button>
{branch && <span className="flex items-center gap-1 font-mono text-xs text-ink3"><GitBranch size={13} />{branch}</span>}
<div className="flex-1" />
- <Tooltip label={MODES.find((m) => m.value === mode)?.hint ?? ""} side="bottom">
- <span><Segmented<Mode> value={mode} onChange={setMode} options={MODES.map(({ value, label }) => ({ value, label }))} /></span>
- </Tooltip>
<Tooltip label={panelOpen ? "Hide project" : "Show project"} side="bottom">
<Button variant="ghost" size="sm" icon onClick={() => setPanelOpen((o) => !o)} aria-label="Toggle project panel"><PanelRight size={16} /></Button>
</Tooltip>
</>
}
empty={
- <div className="flex flex-col items-center gap-5 px-6 pb-24 text-center">
- <PixelWordmark />
- <p className="max-w-[480px] text-base text-ink3">
- {folder
- ? <>Working in <span className="font-mono text-ink2">{shortPath(folder)}</span>. Describe what to build or fix; Mercury reads, edits, runs and checks its work.</>
- : "Open a project folder to start. Mercury works inside it: reads, edits, runs, and asks before anything that can't be undone."}
- </p>
- {!folder && <Button variant="primary" size="lg" onClick={() => setPicking(true)}><FolderOpen size={16} /> Open a folder</Button>}
- </div>
+ <CodeHome
+ folder={folder}
+ branch={branch}
+ version={health?.version ?? ""}
+ model={model}
+ mode={mode}
+ recent={codeThreads.filter((t) => !folder || folderOf(t.id) === folder).sort((a, b) => (b.updatedAt || b.createdAt).localeCompare(a.updatedAt || a.createdAt))}
+ onPickFolder={() => setPicking(true)}
+ onOpenSession={(id) => void openThread("code", id)}
+ onSuggest={(t) => setDraft(t)}
+ />
}
- composer={{ surface: "code", placeholder: "Describe the change…", code: turn, blockedReason: folder ? undefined : "Open a project folder first" }}
+ composer={{ surface: "code", placeholder: 'Try "fix the failing test in src/…"', code: turn, blockedReason: folder ? undefined : "Open a project folder first", mono: true, draft, onDraftConsumed: () => setDraft(null), onCycleMode: cycleMode, modeLabel: mode }}
/>
{panelOpen && folder && <ProjectPanel folder={folder} />}