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): plan card above the composer

Salman Qureshie654336540b2
diff --git a/apps/desktop/src/app/conversation.ts b/apps/desktop/src/app/conversation.ts
index ef832f3d..0ed9d60b 100644
--- a/apps/desktop/src/app/conversation.ts
+++ b/apps/desktop/src/app/conversation.ts
@@ -26,6 +26,9 @@ export interface ConversationState {
/** The stop button was pressed and the runtime hasn't confirmed yet. */
stopping: boolean;
setStopping(stopping: boolean): void;
+ /** The conversation's plan checklist (update_plan), if Mercury made one. */
+ plan: { steps: Array<{ label: string; status: "pending" | "active" | "done" }>; updatedAt: number } | null;
+ setPlan(plan: ConversationState["plan"]): void;
setLive(update: (live: ThoughtTrace) => ThoughtTrace): void;
clearLive(): void;
setActive(id: string | null): void;
@@ -55,9 +58,11 @@ function makeConversation(surface: Surface): ConversationStore {
live: null,
stopping: false,
setStopping: (stopping) => set({ stopping }),
+ plan: null,
+ setPlan: (plan) => set({ plan }),
setLive: (update) => set((s) => ({ live: update(s.live ?? { reasoning: "", steps: [], startedAt: Date.now() }) })),
clearLive: () => set({ live: null }),
- setActive: (activeId) => set({ activeId, prompts: [], step: null, agent: "idle", live: null, stopping: false }),
+ setActive: (activeId) => set({ activeId, prompts: [], step: null, agent: "idle", live: null, stopping: false, plan: null }),
setMessages: (messages) => set({ messages }),
addMessage: (message) => set((s) => ({ messages: [...s.messages, message] })),
appendStreaming: (text) => set((s) => ({ streaming: s.streaming + text })),
diff --git a/apps/desktop/src/app/events.ts b/apps/desktop/src/app/events.ts
index de236153..10c687cb 100644
--- a/apps/desktop/src/app/events.ts
+++ b/apps/desktop/src/app/events.ts
@@ -8,6 +8,7 @@
import { useEffect } from "react";
import { openStream } from "~/api/stream";
import * as api from "~/api/mercury";
+import { http } from "~/api/client";
import type { BotActivityEvent, ChatMessage, CodeMode, PendingPrompt } from "~/api/types";
import { useBots, useChat, useRuntimeState, type AgentState } from "./store";
import { conversations, useCodeSessions, type ConversationStore, type Surface } from "./conversation";
@@ -92,6 +93,11 @@ function handleEvent(store: ConversationStore, event: string, raw: string): void
conv.setAgent("thinking");
conv.setLive((l) => l);
break;
+ case "plan": {
+ const steps = Array.isArray(data.steps) ? (data.steps as Array<{ label: string; status: "pending" | "active" | "done" }>) : [];
+ if (steps.length) conv.setPlan({ steps, updatedAt: Number(data.updatedAt) || Date.now() });
+ break;
+ }
case "reasoning":
if (data.done === true) break;
if (typeof data.text === "string" && data.text) conv.setLive((l) => ({ ...l, reasoning: (l.reasoning + data.text).slice(-20_000) }));
@@ -205,6 +211,10 @@ export async function openThread(surface: Surface, id: string | null): Promise<v
return;
}
store.getState().setLoading(true);
+ // The plan Mercury was working through in this conversation, if any.
+ void http.get<{ plan: { steps: Array<{ label: string; status: "pending" | "active" | "done" }>; updatedAt: number } | null }>(`/api/chat/plan?sessionId=${encodeURIComponent(id)}`)
+ .then((r) => { if (store.getState().activeId === id && r.plan?.steps?.length) store.getState().setPlan(r.plan); })
+ .catch(() => { /* older Mercury: no plans */ });
try {
const thread = await api.chat.thread(id);
store.getState().setMessages(thread.messages ?? []);
diff --git a/apps/desktop/src/views/chat/Conversation.tsx b/apps/desktop/src/views/chat/Conversation.tsx
index 55f7d8d4..8fd7ebfd 100644
--- a/apps/desktop/src/views/chat/Conversation.tsx
+++ b/apps/desktop/src/views/chat/Conversation.tsx
@@ -1,4 +1,5 @@
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import { PlanCard } from "./PlanCard";
import { cx } from "~/lib/cx";
import { useConversation, useConversationStore } from "~/app/conversation";
import { answerPrompt } from "~/app/events";
@@ -99,6 +100,7 @@ export function Conversation({ header, empty, composer }: { header: ReactNode; e
)}
</div>
+ <PlanCard surface={composer.surface} />
<Composer {...composer} />
</section>
);
diff --git a/apps/desktop/src/views/chat/PlanCard.test.ts b/apps/desktop/src/views/chat/PlanCard.test.ts
new file mode 100644
index 00000000..c8c5a6ba
--- /dev/null
+++ b/apps/desktop/src/views/chat/PlanCard.test.ts
@@ -0,0 +1,14 @@
+import { describe, expect, it } from "vitest";
+import { shouldShowPlan } from "./PlanCard";
+
+const steps = (n: number) => Array.from({ length: n }, (_, i) => ({ label: `Step ${i + 1}`, status: "pending" as const }));
+
+describe("plan card", () => {
+ it("chat shows only real multi-step plans; code shows any plan", () => {
+ expect(shouldShowPlan("chat", steps(2))).toBe(false);
+ expect(shouldShowPlan("chat", steps(3))).toBe(true);
+ expect(shouldShowPlan("code", steps(1))).toBe(true);
+ expect(shouldShowPlan("code", [])).toBe(false);
+ expect(shouldShowPlan("chat", undefined)).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/views/chat/PlanCard.tsx b/apps/desktop/src/views/chat/PlanCard.tsx
new file mode 100644
index 00000000..c447154a
--- /dev/null
+++ b/apps/desktop/src/views/chat/PlanCard.tsx
@@ -0,0 +1,112 @@
+import { CheckCircle2, ChevronDown, ListChecks, X } from "lucide-react";
+import { useEffect, useState } from "react";
+import { useConversation, type Surface } from "~/app/conversation";
+import { cx } from "~/lib/cx";
+
+/**
+ * The plan Mercury is working through, pinned above the composer: done
+ * steps ticked, the current one half-filled, the rest open circles, like
+ * the terminal's checklist. Minimize it to one line (remembered per
+ * conversation); when every step is done it folds away and can be closed.
+ *
+ * Chat only shows real multi-step plans (three or more steps); Code shows
+ * any plan, since coding always works from one.
+ */
+
+type Step = { label: string; status: "pending" | "active" | "done" };
+
+const MIN_STEPS: Record<Surface, number> = { chat: 3, code: 1 };
+
+function readFlag(key: string): string | null {
+ try { return localStorage.getItem(key); } catch { return null; }
+}
+function writeFlag(key: string, value: string | null): void {
+ try { if (value === null) localStorage.removeItem(key); else localStorage.setItem(key, value); } catch { /* per-device nicety only */ }
+}
+
+export function shouldShowPlan(surface: Surface, steps: Step[] | undefined): boolean {
+ return !!steps && steps.length >= MIN_STEPS[surface];
+}
+
+export function PlanCard({ surface }: { surface: Surface }) {
+ const plan = useConversation((s) => s.plan);
+ const threadId = useConversation((s) => s.activeId);
+ const agent = useConversation((s) => s.agent);
+ const busy = agent === "thinking" || agent === "working" || agent === "streaming";
+ const minKey = `mercury.plan.min.${threadId ?? "new"}`;
+ const closedKey = `mercury.plan.closed.${threadId ?? "new"}`;
+ const [minimized, setMinimized] = useState(() => readFlag(minKey) === "1");
+ const [closedAt, setClosedAt] = useState(() => Number(readFlag(closedKey) ?? 0));
+ useEffect(() => { setMinimized(readFlag(minKey) === "1"); setClosedAt(Number(readFlag(closedKey) ?? 0)); }, [minKey, closedKey]);
+
+ const steps = plan?.steps ?? [];
+ const done = steps.filter((s) => s.status === "done").length;
+ const complete = steps.length > 0 && done === steps.length;
+ const active = steps.find((s) => s.status === "active") ?? (complete ? null : steps.find((s) => s.status === "pending") ?? null);
+
+ // A finished plan folds to one line by itself once the work stops.
+ useEffect(() => { if (complete && !busy) setMinimized(true); }, [complete, busy]);
+
+ if (!plan || !shouldShowPlan(surface, steps)) return null;
+ // Closed by you: stays closed until Mercury changes the plan.
+ if (closedAt && closedAt >= plan.updatedAt) return null;
+
+ const toggle = () => { const next = !minimized; setMinimized(next); writeFlag(minKey, next ? "1" : null); };
+ const close = () => { setClosedAt(plan.updatedAt); writeFlag(closedKey, String(plan.updatedAt)); };
+ const pct = Math.round((done / steps.length) * 100);
+
+ return (
+ <div className="shrink-0 px-8 pt-1">
+ <div className="mx-auto w-full max-w-[780px]">
+ <section className="overflow-hidden rounded-2xl border border-line bg-surface shadow-[0_1px_2px_rgb(0_0_0/0.04)]" aria-label="Plan">
+ <div className="flex items-center gap-3 px-4 py-2.5">
+ <button onClick={toggle} className="flex min-w-0 flex-1 items-center gap-3 text-left" aria-expanded={!minimized}>
+ {complete ? <CheckCircle2 size={16} className="shrink-0 text-accent" /> : <ListChecks size={16} className="shrink-0 text-ink3" />}
+ <span className="shrink-0 text-sm font-medium text-ink">{complete ? "Plan complete" : "Plan"}</span>
+ <span className="shrink-0 font-mono text-xs tabular-nums text-ink3">{done} of {steps.length}</span>
+ {minimized && active && <span className="min-w-0 truncate text-sm text-ink2">· {active.label}</span>}
+ <span className="ml-auto hidden h-1 w-24 shrink-0 overflow-hidden rounded-full bg-ink/[0.08] sm:block" aria-hidden="true">
+ <span className={cx("block h-full rounded-full transition-[width] duration-500", complete ? "bg-accent" : "bg-ink/60")} style={{ width: `${pct}%` }} />
+ </span>
+ <ChevronDown size={15} className={cx("shrink-0 text-ink4 transition-transform", !minimized && "rotate-180")} />
+ </button>
+ {complete && !busy && (
+ <button onClick={close} className="rounded-md p-1 text-ink4 hover:bg-ink/[0.06] hover:text-ink" aria-label="Close the plan"><X size={14} /></button>
+ )}
+ </div>
+ {!minimized && (
+ <ol className="flex max-h-56 flex-col gap-0.5 overflow-y-auto border-t border-line px-3 py-2">
+ {steps.map((s, i) => (
+ <li key={`${i}-${s.label}`} className="flex items-start gap-2.5 rounded-lg px-1.5 py-1.5">
+ <StepMark status={s.status} live={busy && s.status === "active"} />
+ <span className={cx("min-w-0 flex-1 text-sm leading-snug",
+ s.status === "done" && "text-ink3",
+ s.status === "active" && "font-medium text-ink",
+ s.status === "pending" && "text-ink2")}>{s.label}</span>
+ </li>
+ ))}
+ </ol>
+ )}
+ </section>
+ </div>
+ </div>
+ );
+}
+
+/** ✓ done · ◐ in progress · ○ not started. */
+function StepMark({ status, live }: { status: Step["status"]; live: boolean }) {
+ if (status === "done") return <CheckCircle2 size={16} className="mt-px shrink-0 text-accent" aria-label="Done" />;
+ if (status === "active") {
+ return (
+ <svg width="16" height="16" viewBox="0 0 16 16" className={cx("mt-px shrink-0 text-accent", live && "animate-pulse")} role="img" aria-label="In progress">
+ <circle cx="8" cy="8" r="6.25" fill="none" stroke="currentColor" strokeWidth="1.5" />
+ <path d="M8 1.75 A6.25 6.25 0 0 1 8 14.25 Z" fill="currentColor" />
+ </svg>
+ );
+ }
+ return (
+ <svg width="16" height="16" viewBox="0 0 16 16" className="mt-px shrink-0 text-ink4" role="img" aria-label="Not started">
+ <circle cx="8" cy="8" r="6.25" fill="none" stroke="currentColor" strokeWidth="1.5" />
+ </svg>
+ );
+}