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): short note labels and a hover card on the brain graphs

Salman Qureshifc07bbf78851
diff --git a/apps/desktop/src/views/brain/BrainGraph.tsx b/apps/desktop/src/views/brain/BrainGraph.tsx
index 7a6f0cee..cd3a3808 100644
--- a/apps/desktop/src/views/brain/BrainGraph.tsx
+++ b/apps/desktop/src/views/brain/BrainGraph.tsx
@@ -11,6 +11,7 @@ import { Tooltip } from "~/components/ui/Tooltip";
import { useTheme } from "~/app/theme";
import { cx } from "~/lib/cx";
import { ZoomPanel, zoomKeys } from "./ZoomPanel";
+import { shortLabel, useNoteHoverCard } from "./NoteHoverCard";
/**
* The brain as a living graph, Obsidian-style.
@@ -61,6 +62,7 @@ type Show = "all" | "people" | "memories";
export function BrainGraph({ visible, onSelect, selectedId }: { visible: boolean; onSelect: (node: { id: string; kind: SelectableKind } | null) => void; selectedId: string | null }) {
const host = useRef<HTMLDivElement>(null);
const graph = useRef<ForceGraph<GraphNode, GraphLink> | null>(null);
+ const hoverCard = useNoteHoverCard(graph, host);
const [data, setData] = useState<BrainGraphData | null>(null);
const [limit, setLimit] = useState(300);
const [show, setShow] = useState<Show>("all");
@@ -131,9 +133,12 @@ export function BrainGraph({ visible, onSelect, selectedId }: { visible: boolean
.nodePointerAreaPaint((node, color, ctx) => { ctx.fillStyle = color; ctx.beginPath(); ctx.arc(node.x ?? 0, node.y ?? 0, radius(node) + 4, 0, 2 * Math.PI); ctx.fill(); })
.onRenderFramePre(() => { labelsDrawn.current = []; })
.onZoom(({ k }) => setZoomPct(Math.round(k * 100)))
+ .onRenderFramePost(() => hoverCard.place())
.onNodeHover((node) => {
hover.current = node ?? null;
el.style.cursor = node ? "pointer" : "grab";
+ const memory = node?.kind === "memory" ? node : null;
+ hoverCard.hover(memory, memory ? { text: memory.label, label: memory.type } : null);
})
.onNodeClick((node) => {
if (node.kind === "hub") { g.centerAt(node.x, node.y, 500); g.zoom(Math.max(g.zoom(), 1.6), 500); return; }
@@ -237,6 +242,7 @@ export function BrainGraph({ visible, onSelect, selectedId }: { visible: boolean
return (
<div className="relative h-full w-full overflow-hidden">
<div ref={host} className="absolute inset-0" style={{ cursor: "grab" }} />
+ {hoverCard.card}
<div className="pointer-events-none absolute left-4 right-4 top-3 flex flex-wrap items-center gap-2">
<div className="pointer-events-auto"><Segmented value={show} onChange={setShow} options={[{ value: "all", label: "Everything" }, { value: "people", label: "People" }, { value: "memories", label: "Memories" }]} /></div>
@@ -370,7 +376,7 @@ export function BrainGraph({ visible, onSelect, selectedId }: { visible: boolean
const px = n.kind === "memory" ? 10.5 : n.kind === "hub" || n.kind === "you" ? 12.5 : 12;
const size = px / scale;
ctx.font = `${n.kind === "memory" ? 400 : 600} ${size}px "Geist Variable", system-ui, sans-serif`;
- const text = n.kind === "memory" ? truncate(n.label, 54) : n.label;
+ const text = n.kind === "memory" ? shortLabel(n.label) : n.label;
const w = ctx.measureText(text).width;
const ty = y + r + 2 / scale;
const free = lit || n.kind === "you" ? (labelsDrawn.current.push([x - w / 2, ty, w, size]), true) : claim(x - w / 2, ty, w, size);
@@ -462,10 +468,6 @@ function buildAdjacency(links: GraphLink[]): Map<string, Set<string>> {
return m;
}
-function truncate(s: string, n: number): string {
- return s.length > n ? `${s.slice(0, n - 1)}…` : s;
-}
-
// ── placement: random start, pins kept for the session ─────────────────────
function readPins(): Record<string, [number, number]> {
diff --git a/apps/desktop/src/views/brain/MindMap.tsx b/apps/desktop/src/views/brain/MindMap.tsx
index 5c4c44d8..ae1e92a8 100644
--- a/apps/desktop/src/views/brain/MindMap.tsx
+++ b/apps/desktop/src/views/brain/MindMap.tsx
@@ -12,6 +12,7 @@ import { Tooltip } from "~/components/ui/Tooltip";
import { useTheme } from "~/app/theme";
import { cx } from "~/lib/cx";
import { ZoomPanel, zoomKeys } from "./ZoomPanel";
+import { shortLabel, useNoteHoverCard } from "./NoteHoverCard";
/**
* Everything Mercury knows, as a mind map: You → themes → sub-themes →
@@ -149,6 +150,7 @@ type Mode = "map" | "outline";
export function MindMap({ visible, onSelect, selectedId }: { visible: boolean; onSelect: (node: { id: string; kind: "memory" } | null) => void; selectedId: string | null }) {
const host = useRef<HTMLDivElement>(null);
const graph = useRef<ForceGraph<MapNode, MapLink> | null>(null);
+ const hoverCard = useNoteHoverCard(graph, host);
const [data, setData] = useState<BrainMap | null>(null);
const [archive, setArchive] = useState(false);
const [showLinks, setShowLinks] = useState(false);
@@ -230,7 +232,12 @@ export function MindMap({ visible, onSelect, selectedId }: { visible: boolean; o
.onRenderFramePre(() => { labelsDrawn.current = []; })
.onRenderFramePost((ctx, scale) => drawRelated(ctx, scale))
.onZoom(({ k }) => setZoomPct(Math.round(k * 100)))
- .onNodeHover((n) => { hover.current = n ?? null; el.style.cursor = n ? "pointer" : "grab"; })
+ .onRenderFramePost(() => hoverCard.place())
+ .onNodeHover((n) => {
+ hover.current = n ?? null;
+ el.style.cursor = n ? "pointer" : "grab";
+ hoverCard.hover(n?.kind === "note" ? n : null, n?.kind === "note" ? { text: n.label, label: byId.current.get(n.theme)?.label, color: n.color } : null);
+ })
.onNodeClick((n) => {
if (n.kind === "note") { onSelectRef.current({ id: n.id, kind: "memory" }); return; }
if (n.kind === "you") { setFocus(null); g.zoomToFit(600, 60); return; }
@@ -335,6 +342,7 @@ export function MindMap({ visible, onSelect, selectedId }: { visible: boolean; o
return (
<div className="relative h-full w-full overflow-hidden">
<div ref={host} className={cx("absolute inset-0", mode !== "map" && "invisible")} style={{ cursor: "grab" }} />
+ {mode === "map" && hoverCard.card}
{mode === "outline" && data && <Outline data={data} selectedId={selectedId} onSelect={(id) => onSelect({ id, kind: "memory" })} find={find} />}
<div className="pointer-events-none absolute left-4 right-4 top-3 flex flex-wrap items-center gap-2">
@@ -441,7 +449,7 @@ export function MindMap({ visible, onSelect, selectedId }: { visible: boolean; o
}
ctx.globalAlpha = 1;
// Name the related notes of the one under the pointer.
- if (focusNote) for (const [b] of (related.current.get(focusNote.id) ?? []).slice(0, 6)) { const nb = byId.current.get(b); if (nb) noteLabel(nb, ctx, scale, true); }
+ if (focusNote) for (const [b] of (related.current.get(focusNote.id) ?? []).slice(0, 4)) { const nb = byId.current.get(b); if (nb) noteLabel(nb, ctx, scale, true); }
}
function claim(x: number, y: number, w: number, h: number): boolean {
@@ -454,7 +462,7 @@ export function MindMap({ visible, onSelect, selectedId }: { visible: boolean; o
const x = n.x ?? 0;
const y = n.y ?? 0;
const size = 10.5 / scale;
- const text = truncate(n.label, 64);
+ const text = shortLabel(n.label);
ctx.font = `400 ${size}px "Geist Variable", system-ui, sans-serif`;
const w = ctx.measureText(text).width;
// Outward along the node's ray, flipped on the left so it never reads upside down.
@@ -646,10 +654,6 @@ function radius(n: MapNode): number {
return 2.2 + Math.min(1.6, n.size * 1.6);
}
-function truncate(s: string, n: number): string {
- return s.length > n ? `${s.slice(0, n - 1)}…` : s;
-}
-
function readPins(): Record<string, [number, number]> {
try { return JSON.parse(sessionStorage.getItem(PINS_KEY) ?? "{}") as Record<string, [number, number]>; } catch { return {}; }
}
diff --git a/apps/desktop/src/views/brain/NoteHoverCard.test.ts b/apps/desktop/src/views/brain/NoteHoverCard.test.ts
new file mode 100644
index 00000000..d20020e8
--- /dev/null
+++ b/apps/desktop/src/views/brain/NoteHoverCard.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from "vitest";
+import { shortLabel } from "./NoteHoverCard";
+
+describe("note labels on the graph", () => {
+ it("leaves short notes alone and drops the full stop", () => {
+ expect(shortLabel("Married to Heer.")).toBe("Married to Heer");
+ });
+ it("ends at the first clause when it's short enough", () => {
+ expect(shortLabel("Lives in Srinagar, works on Mercury at Cosmic Stack every evening")).toBe("Lives in Srinagar…");
+ });
+ it("otherwise cuts at a whole word, never mid-word", () => {
+ const out = shortLabel("Prefers Mercury to communicate in Urdu and not switch languages without asking");
+ expect(out).toBe("Prefers Mercury to communicate…");
+ expect(out.length).toBeLessThanOrEqual(32);
+ });
+ it("cuts one very long word hard", () => {
+ expect(shortLabel("a".repeat(60))).toHaveLength(32);
+ });
+ it("doesn't end on dangling punctuation", () => {
+ expect(shortLabel("Uses Tauri for the desktop app (Rust shell) — React UI and more after that")).toBe("Uses Tauri for the desktop app…");
+ });
+});
diff --git a/apps/desktop/src/views/brain/NoteHoverCard.tsx b/apps/desktop/src/views/brain/NoteHoverCard.tsx
new file mode 100644
index 00000000..971a3552
--- /dev/null
+++ b/apps/desktop/src/views/brain/NoteHoverCard.tsx
@@ -0,0 +1,79 @@
+import { useLayoutEffect, useRef, useState, type RefObject } from "react";
+
+/**
+ * Long notes on a graph: the canvas shows a short label, and pausing on a
+ * note shows the whole thing in a card beside its dot (Obsidian's page
+ * preview, without the modifier key). Clicking still opens the side panel.
+ */
+
+/** A note's label for the canvas: its first clause or first few words, never cut mid-word. */
+export function shortLabel(text: string, max = 32): string {
+ const s = text.replace(/\s+/g, " ").trim().replace(/[.。]+$/, "");
+ if (s.length <= max) return s;
+ // A natural break early enough reads better than a cut ("…, and later…").
+ const clause = /^(.{12,}?)(?:[,;:]\s|\s[—–-]\s|\s\()/.exec(s);
+ if (clause && clause[1].length <= max - 1) return `${clause[1].trimEnd()}…`;
+ const cut = s.slice(0, max - 1);
+ const space = cut.lastIndexOf(" ");
+ const base = space >= max * 0.5 ? cut.slice(0, space) : cut;
+ return `${base.replace(/[\s,;:.(—–-]+$/, "")}…`;
+}
+
+export interface HoverNote {
+ text: string;
+ /** Theme or kind, shown above the text. */
+ label?: string;
+ color?: string;
+}
+
+interface Positioned { x?: number; y?: number }
+interface Projector { graph2ScreenCoords(x: number, y: number): { x: number; y: number } }
+
+const DELAY_MS = 280;
+
+/**
+ * Hover card state for a force-graph. Call `hover` from onNodeHover and
+ * `place` from onRenderFramePost (the dot can move); render `card`.
+ */
+export function useNoteHoverCard(graph: RefObject<Projector | null>, host: RefObject<HTMLElement | null>) {
+ const [note, setNote] = useState<HoverNote | null>(null);
+ const anchor = useRef<Positioned | null>(null);
+ const el = useRef<HTMLDivElement>(null);
+ const timer = useRef<number | undefined>(undefined);
+
+ function hover(node: Positioned | null, info: HoverNote | null) {
+ window.clearTimeout(timer.current);
+ if (!node || !info) { anchor.current = null; setNote(null); return; }
+ anchor.current = node;
+ timer.current = window.setTimeout(() => { if (anchor.current === node) setNote(info); }, DELAY_MS);
+ }
+
+ /** Beside the dot, flipped to the other side or nudged in at the edges. */
+ function place() {
+ const card = el.current, n = anchor.current, g = graph.current, box = host.current;
+ if (!card || !n || !g || !box) return;
+ const p = g.graph2ScreenCoords(n.x ?? 0, n.y ?? 0);
+ const W = box.clientWidth, H = box.clientHeight, w = card.offsetWidth, h = card.offsetHeight, gap = 16;
+ let left = p.x + gap;
+ if (left + w > W - 8) left = Math.max(8, p.x - gap - w);
+ const top = Math.min(Math.max(8, p.y - h / 2), Math.max(8, H - h - 8));
+ card.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
+ }
+
+ useLayoutEffect(place, [note]); // eslint-disable-line react-hooks/exhaustive-deps
+
+ const card = note ? (
+ <div ref={el} role="tooltip" className="pointer-events-none absolute left-0 top-0 z-20 w-max max-w-[300px] animate-fade-in rounded-xl border border-line bg-surface/95 px-3.5 py-3 shadow-xl backdrop-blur" style={{ transform: "translate(-9999px, 0)" }}>
+ {note.label && (
+ <div className="mb-1.5 flex items-center gap-1.5 text-2xs font-medium uppercase tracking-wider text-ink4">
+ {note.color && <span className="h-2 w-2 shrink-0 rounded-full" style={{ background: note.color }} />}
+ <span className="truncate">{note.label}</span>
+ </div>
+ )}
+ <p className="line-clamp-5 text-sm leading-relaxed text-ink">{note.text}</p>
+ <div className="mt-2 text-2xs text-ink4">Click to open</div>
+ </div>
+ ) : null;
+
+ return { hover, place, card };
+}
diff --git a/apps/desktop/src/views/brain/NoteWeb.tsx b/apps/desktop/src/views/brain/NoteWeb.tsx
index 0e24bfd4..d5bb4856 100644
--- a/apps/desktop/src/views/brain/NoteWeb.tsx
+++ b/apps/desktop/src/views/brain/NoteWeb.tsx
@@ -12,6 +12,7 @@ import { useTheme } from "~/app/theme";
import { cx } from "~/lib/cx";
import { LOOSE, themeColors } from "./MindMap";
import { ZoomPanel, zoomKeys } from "./ZoomPanel";
+import { shortLabel, useNoteHoverCard } from "./NoteHoverCard";
/**
* The mind map: Obsidian's graph view for the second brain. Every note is a dot,
@@ -119,6 +120,9 @@ export function NoteWeb({ visible, onSelect, selectedId }: { visible: boolean; o
selectedRef.current = selectedId;
const onSelectRef = useRef(onSelect);
onSelectRef.current = onSelect;
+ const themeNames = useRef(new Map<string, string>());
+ themeNames.current = new Map((data?.themes ?? []).map((t) => [t.id, t.label]));
+ const hoverCard = useNoteHoverCard(graph, host);
useEffect(() => { try { localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings)); } catch { /* per-device nicety only */ } }, [settings]);
const set = <K extends keyof WebSettings>(k: K, v: WebSettings[K]) => setSettings((s) => ({ ...s, [k]: v }));
@@ -168,7 +172,12 @@ export function NoteWeb({ visible, onSelect, selectedId }: { visible: boolean; o
.nodePointerAreaPaint((n, color, ctx) => { ctx.fillStyle = color; ctx.beginPath(); ctx.arc(n.x ?? 0, n.y ?? 0, radius(n) + 3, 0, 2 * Math.PI); ctx.fill(); })
.onRenderFramePre(() => { labelsDrawn.current = []; })
.onZoom(({ k }) => setZoomPct(Math.round(k * 100)))
- .onNodeHover((n) => { hover.current = n ?? null; el.style.cursor = n ? "pointer" : "grab"; })
+ .onRenderFramePost(() => hoverCard.place())
+ .onNodeHover((n) => {
+ hover.current = n ?? null;
+ el.style.cursor = n ? "pointer" : "grab";
+ hoverCard.hover(n ?? null, n ? { text: n.label, label: themeNames.current.get(n.theme), color: n.color } : null);
+ })
.onNodeClick((n) => { onSelectRef.current({ id: n.id, kind: "memory" }); })
.onBackgroundClick(() => onSelectRef.current(null))
.onNodeDragEnd((n) => { n.fx = n.x; n.fy = n.y; savePin(n); });
@@ -242,6 +251,7 @@ export function NoteWeb({ visible, onSelect, selectedId }: { visible: boolean; o
return (
<div className="relative h-full w-full overflow-hidden">
<div ref={host} className="absolute inset-0" style={{ cursor: "grab" }} />
+ {hoverCard.card}
<div className="pointer-events-none absolute left-4 right-4 top-3 flex flex-wrap items-center gap-2">
<div className="pointer-events-auto flex h-8 items-center gap-1.5 rounded-md border border-line bg-surface/85 px-2 backdrop-blur">
@@ -384,7 +394,7 @@ export function NoteWeb({ visible, onSelect, selectedId }: { visible: boolean; o
if (alpha > 0.02 && !dim) {
const size = 10.5 / scale;
ctx.font = `${lit ? 500 : 400} ${size}px "Geist Variable", system-ui, sans-serif`;
- const text = n.label.length > 48 ? `${n.label.slice(0, 47)}…` : n.label;
+ const text = shortLabel(n.label);
const w = ctx.measureText(text).width;
const ty = y + r + 2 / scale;
if (lit ? (labelsDrawn.current.push([x - w / 2, ty, w, size]), true) : claim(x - w / 2, ty, w, size)) {