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): tell you and Mercury apart in conversations

Salman Qureshi4a414f5f98bb
diff --git a/apps/desktop/src/app/profile.ts b/apps/desktop/src/app/profile.ts
new file mode 100644
index 00000000..b73d2e58
--- /dev/null
+++ b/apps/desktop/src/app/profile.ts
@@ -0,0 +1,78 @@
+/* Your profile on this device: a display name, an optional photo, and the
+ seed your generated avatar is drawn from. The seed is random the first
+ time and then kept, so your face stays the same until you shuffle it. */
+
+import { create } from "zustand";
+
+interface ProfileState {
+ /** Overrides the owner name from the runtime config; "" means use that. */
+ name: string;
+ /** A small square photo as a data URL, or null for the generated avatar. */
+ image: string | null;
+ seed: string;
+ setName(name: string): void;
+ setImage(image: string | null): void;
+ shuffle(): void;
+ setSeed(seed: string): void;
+}
+
+const KEY = "mercury.profile.v1";
+
+export function randomSeed(): string {
+ try { return crypto.randomUUID(); } catch { return `${Date.now()}-${Math.random()}`; }
+}
+
+function read(): Pick<ProfileState, "name" | "image" | "seed"> {
+ try {
+ const raw = localStorage.getItem(KEY);
+ if (raw) {
+ const v = JSON.parse(raw) as Partial<ProfileState>;
+ if (typeof v.seed === "string" && v.seed) return { name: typeof v.name === "string" ? v.name : "", image: typeof v.image === "string" ? v.image : null, seed: v.seed };
+ }
+ } catch { /* fall through to a new profile */ }
+ return { name: "", image: null, seed: randomSeed() };
+}
+
+function write(s: Pick<ProfileState, "name" | "image" | "seed">) {
+ try { localStorage.setItem(KEY, JSON.stringify({ name: s.name, image: s.image, seed: s.seed })); } catch { /* storage full or blocked: keep it in memory */ }
+}
+
+export const useProfile = create<ProfileState>((set, get) => {
+ const initial = read();
+ write(initial);
+ const update = (patch: Partial<Pick<ProfileState, "name" | "image" | "seed">>) => {
+ set(patch);
+ const s = get();
+ write({ name: s.name, image: s.image, seed: s.seed });
+ };
+ return {
+ ...initial,
+ setName: (name) => update({ name: name.trim() }),
+ setImage: (image) => update({ image }),
+ shuffle: () => update({ seed: randomSeed() }),
+ setSeed: (seed) => update({ seed }),
+ };
+});
+
+/** Shrink a picked photo to a 192px centre-cropped square JPEG data URL. */
+export async function photoToDataUrl(file: File, size = 192): Promise<string> {
+ const url = URL.createObjectURL(file);
+ try {
+ const img = await new Promise<HTMLImageElement>((resolve, reject) => {
+ const i = new Image();
+ i.onload = () => resolve(i);
+ i.onerror = () => reject(new Error("That file isn't an image Mercury can read."));
+ i.src = url;
+ });
+ const side = Math.min(img.naturalWidth, img.naturalHeight);
+ const canvas = document.createElement("canvas");
+ canvas.width = size;
+ canvas.height = size;
+ const ctx = canvas.getContext("2d");
+ if (!ctx) throw new Error("Couldn't process the photo.");
+ ctx.drawImage(img, (img.naturalWidth - side) / 2, (img.naturalHeight - side) / 2, side, side, 0, 0, size, size);
+ return canvas.toDataURL("image/jpeg", 0.88);
+ } finally {
+ URL.revokeObjectURL(url);
+ }
+}
diff --git a/apps/desktop/src/components/UserAvatar.tsx b/apps/desktop/src/components/UserAvatar.tsx
new file mode 100644
index 00000000..a9cf4005
--- /dev/null
+++ b/apps/desktop/src/components/UserAvatar.tsx
@@ -0,0 +1,76 @@
+import { useId } from "react";
+import { useProfile } from "~/app/profile";
+import { usePulse } from "~/app/pulse";
+import { cx } from "~/lib/cx";
+
+/**
+ * Your face in the app: the photo you chose, or a soft "marble" drawn from
+ * your profile seed: three blurred colour shapes on a bright base. Same
+ * seed, same avatar. Different in kind from bot faces (no eyes, no smile),
+ * so you never read as one of the bots.
+ */
+export function UserAvatar({ size = 28, className }: { size?: number; className?: string }) {
+ const image = useProfile((s) => s.image);
+ const seed = useProfile((s) => s.seed);
+ const name = useDisplayName();
+ if (image) {
+ return <img src={image} alt={name} style={{ width: size, height: size }} className={cx("shrink-0 rounded-full object-cover", className)} draggable={false} />;
+ }
+ return <Marble seed={seed} size={size} label={name} className={className} />;
+}
+
+/** The name to show for you: your own override, else the runtime's owner name, else "You". */
+export function useDisplayName(): string {
+ const override = useProfile((s) => s.name);
+ const owner = usePulse((s) => s.owner);
+ return override || owner || "You";
+}
+
+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;
+}
+
+/** Palettes of three or four colours that sit well together, bright in light and dark. */
+const PALETTES = [
+ ["#FF6B6B", "#FFD166", "#06D6A0", "#118AB2"],
+ ["#7F5AF0", "#2CB67D", "#FFB86B", "#F25F4C"],
+ ["#F72585", "#7209B7", "#4CC9F0", "#FFBE0B"],
+ ["#00BBF9", "#00F5D4", "#FEE440", "#F15BB5"],
+ ["#FB5607", "#FFBE0B", "#3A86FF", "#8338EC"],
+ ["#43AA8B", "#F9C74F", "#F3722C", "#577590"],
+ ["#EF476F", "#FFD6A5", "#9BF6FF", "#5E60CE"],
+ ["#2EC4B6", "#FF9F1C", "#E71D36", "#CBF3F0"],
+];
+
+export function Marble({ seed, size = 28, label, className }: { seed: string; size?: number; label?: string; className?: string }) {
+ const uid = useId().replace(/:/g, "");
+ const h = hash(seed);
+ const palette = PALETTES[h % PALETTES.length];
+ // Three different colours from the palette, in an order set by the seed.
+ const i = (h >>> 3) % 4;
+ const j = (i + 1 + ((h >>> 6) % 3)) % 4;
+ const k = [0, 1, 2, 3].filter((x) => x !== i && x !== j)[(h >>> 10) % 2];
+ const base = palette[i];
+ const a = palette[j];
+ const b = palette[k];
+ const rot = (k: number) => ((h >>> k) % 360);
+ const off = (k: number) => (((h >>> k) % 40) - 20);
+ return (
+ <svg width={size} height={size} viewBox="0 0 80 80" role="img" aria-label={label} className={cx("shrink-0 rounded-full", className)}>
+ <defs>
+ <mask id={`m-${uid}`} maskUnits="userSpaceOnUse" x="0" y="0" width="80" height="80"><circle cx="40" cy="40" r="40" fill="#fff" /></mask>
+ <filter id={`f-${uid}`} x="-50%" y="-50%" width="200%" height="200%" filterUnits="userSpaceOnUse"><feGaussianBlur stdDeviation="7" /></filter>
+ </defs>
+ <g mask={`url(#m-${uid})`}>
+ <rect width="80" height="80" fill={base} />
+ <path filter={`url(#f-${uid})`} d="M32.4 -7.4L58.7 45.2 -4.8 64.3z" fill={a} transform={`translate(${off(2)} ${off(5)}) rotate(${rot(9)} 40 40) scale(1.2)`} />
+ <path filter={`url(#f-${uid})`} style={{ mixBlendMode: "overlay" }} d="M22.2 0c4.4 15.6 12.8 26.2 25.2 31.9 12.4 5.7 26.3 4.6 41.7-3.2L80 80H0z" fill={b} transform={`translate(${off(4)} ${off(8)}) rotate(${rot(14)} 40 40) scale(1.2)`} />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/desktop/src/views/chat/Message.tsx b/apps/desktop/src/views/chat/Message.tsx
index 807d0102..db7642d8 100644
--- a/apps/desktop/src/views/chat/Message.tsx
+++ b/apps/desktop/src/views/chat/Message.tsx
@@ -8,12 +8,14 @@ import { ActionResult } from "~/components/indicators/Activity";
import { Attachments } from "~/components/Attachments";
import { ThoughtProcess } from "~/components/ThoughtProcess";
import { cx } from "~/lib/cx";
+import { UserAvatar, useDisplayName } from "~/components/UserAvatar";
+import { usePulse } from "~/app/pulse";
/**
* 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
+ * - user your avatar and name, then a heading-weight line, no bubble
+ * - assistant the mark and Mercury's name, then prose (markdown)
* - tool-call a collapsed "used N tools" row; open it for each call
* - system a muted note
*/
@@ -23,10 +25,14 @@ export const Message = memo(function Message({ message }: { message: ChatMessage
// "(Attached: a.png)" is the runtime's text for a files-only turn; the files say it better.
const text = files.length > 0 && /^\(Attached: .*\)$/.test(message.content.trim()) ? "" : message.content;
return (
- <div className="group flex flex-col gap-3 pl-10 pt-2">
- {files.length > 0 && <Attachments items={files} />}
- {text && <p className="whitespace-pre-wrap text-lg font-medium leading-[1.55] tracking-[-0.01em] text-ink" data-selectable>{text}</p>}
- <MessageMeta timestamp={message.timestamp} />
+ <div className="group flex gap-4 pt-2">
+ <span className="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center" aria-hidden="true"><UserAvatar size={24} /></span>
+ <div className="flex min-w-0 flex-1 flex-col gap-2">
+ <Speaker who="you" />
+ {files.length > 0 && <Attachments items={files} />}
+ {text && <p className="whitespace-pre-wrap text-lg font-medium leading-[1.55] tracking-[-0.01em] text-ink" data-selectable>{text}</p>}
+ <MessageMeta timestamp={message.timestamp} />
+ </div>
</div>
);
}
@@ -42,8 +48,9 @@ export const Message = memo(function Message({ message }: { message: ChatMessage
}
return (
<div className="group 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>
+ <span className="mt-0.5 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">
+ <Speaker who="mercury" />
{message.trace && <ThoughtProcess trace={message.trace} />}
{message.steps && message.steps.length > 0 && (
<div className="mb-3 flex flex-col gap-1">
@@ -57,6 +64,17 @@ export const Message = memo(function Message({ message }: { message: ChatMessage
);
});
+/** Who is speaking: a small name line beside the avatar, so turns never blur together. */
+function Speaker({ who }: { who: "you" | "mercury" }) {
+ const you = useDisplayName();
+ const agent = usePulse((s) => s.agentName);
+ return (
+ <div className={cx("flex h-6 items-center text-sm font-semibold", who === "you" ? "text-ink2" : "mb-1.5 text-ink")}>
+ {who === "you" ? you : agent || "Mercury"}
+ </div>
+ );
+}
+
/** Time and copy, shown on hover so the conversation stays quiet. */
function MessageMeta({ timestamp, copy }: { timestamp: string; copy?: string }) {
const [copied, setCopied] = useState(false);
@@ -140,8 +158,9 @@ function ToolActivity({ content }: { content: string }) {
export function StreamingMessage({ text, live }: { text: string; live: ThoughtTrace | null }) {
return (
<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>
+ <span className="mt-0.5 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">
+ <Speaker who="mercury" />
{live && <ThoughtProcess trace={live} live={!text} />}
{text && <><Markdown text={text} streaming /><StreamCaret /></>}
</div>
diff --git a/apps/desktop/src/views/settings/Profile.tsx b/apps/desktop/src/views/settings/Profile.tsx
new file mode 100644
index 00000000..4831fb9d
--- /dev/null
+++ b/apps/desktop/src/views/settings/Profile.tsx
@@ -0,0 +1,82 @@
+import { ImageUp, Shuffle, Trash2 } from "lucide-react";
+import { useRef, useState } from "react";
+import { photoToDataUrl, randomSeed, useProfile } from "~/app/profile";
+import { cx } from "~/lib/cx";
+import { usePulse } from "~/app/pulse";
+import { Button } from "~/components/ui/Button";
+import { Input } from "~/components/ui/Input";
+import { Marble, UserAvatar } from "~/components/UserAvatar";
+
+/**
+ * How you appear in conversations on this device: a photo, or a generated
+ * avatar you can shuffle until you like it, and the name beside it.
+ */
+export function Profile() {
+ const name = useProfile((s) => s.name);
+ const image = useProfile((s) => s.image);
+ const setName = useProfile((s) => s.setName);
+ const setImage = useProfile((s) => s.setImage);
+ const shuffle = useProfile((s) => s.shuffle);
+ const owner = usePulse((s) => s.owner);
+ const [draft, setDraft] = useState(name);
+ const [error, setError] = useState<string | null>(null);
+ const file = useRef<HTMLInputElement>(null);
+
+ async function pick(f: File | undefined) {
+ if (!f) return;
+ setError(null);
+ try { setImage(await photoToDataUrl(f)); } catch (e) { setError(e instanceof Error ? e.message : String(e)); }
+ }
+
+ return (
+ <section className="flex flex-col gap-4">
+ <div className="flex items-center gap-5 rounded-xl border border-line bg-surface p-5">
+ <UserAvatar size={84} />
+ <div className="flex min-w-0 flex-1 flex-col gap-3">
+ <div className="text-sm text-ink3">{image ? "Your photo shows next to your messages." : "Generated for you. Shuffle until you like it, or use a photo."}</div>
+ <div className="flex flex-wrap gap-2">
+ <Button size="sm" variant="outline" onClick={() => file.current?.click()}><ImageUp size={14} /> {image ? "Change photo" : "Upload photo"}</Button>
+ {image
+ ? <Button size="sm" variant="ghost" onClick={() => setImage(null)}><Trash2 size={14} /> Use generated avatar</Button>
+ : <Button size="sm" variant="ghost" onClick={shuffle}><Shuffle size={14} /> Shuffle</Button>}
+ </div>
+ {error && <p className="text-sm text-red">{error}</p>}
+ <input ref={file} type="file" accept="image/*" className="hidden" onChange={(e) => { void pick(e.target.files?.[0]); e.target.value = ""; }} />
+ </div>
+ </div>
+
+ {!image && <ShufflePreview />}
+
+ <form
+ className="flex items-end gap-3 rounded-xl border border-line bg-surface p-5"
+ onSubmit={(e) => { e.preventDefault(); setName(draft); }}
+ >
+ <label className="flex min-w-0 flex-1 flex-col gap-1.5">
+ <span className="text-base text-ink">Display name</span>
+ <span className="text-xs text-ink3">Shown above your messages. Leave empty to use {owner ? `"${owner}" from Mercury's config` : "\"You\""}.</span>
+ <Input value={draft} onChange={(e) => setDraft(e.target.value)} placeholder={owner || "You"} />
+ </label>
+ <Button type="submit" variant="primary" disabled={draft.trim() === name}>Save</Button>
+ </form>
+ </section>
+ );
+}
+
+/** Eight alternatives to pick from; "More" draws a fresh set. */
+function ShufflePreview() {
+ const seed = useProfile((s) => s.seed);
+ const setSeed = useProfile((s) => s.setSeed);
+ const [options, setOptions] = useState(() => Array.from({ length: 8 }, randomSeed));
+ return (
+ <div className="flex flex-wrap items-center gap-3 rounded-xl border border-line bg-surface px-5 py-4">
+ <span className="mr-1 text-sm text-ink3">Or pick one</span>
+ {options.map((o) => (
+ <button key={o} onClick={() => setSeed(o)} aria-pressed={o === seed}
+ className={cx("rounded-full transition-transform hover:scale-110 focus-visible:ring-2 focus-visible:ring-accent/70", o === seed && "ring-2 ring-accent/80 ring-offset-2 ring-offset-surface")} aria-label="Use this avatar">
+ <Marble seed={o} size={36} />
+ </button>
+ ))}
+ <Button size="sm" variant="ghost" onClick={() => setOptions(Array.from({ length: 8 }, randomSeed))}><Shuffle size={14} /> More</Button>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/views/settings/SettingsView.tsx b/apps/desktop/src/views/settings/SettingsView.tsx
index c0fb5bde..6b63cd4a 100644
--- a/apps/desktop/src/views/settings/SettingsView.tsx
+++ b/apps/desktop/src/views/settings/SettingsView.tsx
@@ -1,4 +1,4 @@
-import { Activity, Info, PanelBottom, Palette, Power, Server, Smartphone } from "lucide-react";
+import { Activity, Info, PanelBottom, Palette, Power, Server, Smartphone, UserRound } from "lucide-react";
import { useEffect, useState } from "react";
import { cx } from "~/lib/cx";
import * as api from "~/api/mercury";
@@ -13,15 +13,17 @@ import { Dialog } from "~/components/ui/Dialog";
import { AddRemote } from "~/shell/AddRemote";
import { StateOrb } from "~/components/indicators/StateOrb";
import { Analytics } from "./Analytics";
+import { Profile } from "./Profile";
import { isVisible, orderedIds, useContributions, type ContributionArea } from "~/extensions/registry";
/**
* Settings: a section list on the left, one section on the right. Most-used
* first (Appearance), plain labels, every control explains itself in one line.
*/
-type Section = "appearance" | "statusbar" | "analytics" | "connections" | "devices" | "startup" | "about";
+type Section = "profile" | "appearance" | "statusbar" | "analytics" | "connections" | "devices" | "startup" | "about";
const SECTIONS: Array<{ id: Section; label: string; icon: typeof Palette }> = [
+ { id: "profile", label: "Profile", icon: UserRound },
{ id: "appearance", label: "Appearance", icon: Palette },
{ id: "statusbar", label: "Status bar", icon: PanelBottom },
{ id: "analytics", label: "Analytics", icon: Activity },
@@ -52,6 +54,7 @@ export function SettingsView({ connection, health, onSwitchConnection }: { conne
<div className="min-h-0 flex-1 overflow-y-auto">
<div className={cx("mx-auto flex flex-col gap-6 px-8 py-8", section === "analytics" ? "max-w-[960px]" : "max-w-[680px]")}>
<h1 className="text-xl font-semibold tracking-tight text-ink">{SECTIONS.find((s) => s.id === section)?.label}</h1>
+ {section === "profile" && <Profile />}
{section === "appearance" && <Appearance />}
{section === "statusbar" && <StatusBarSettings />}
{section === "analytics" && <Analytics />}