diff --git a/apps/fe/CLAUDE.md b/apps/fe/CLAUDE.md index 13574c8e..900d60f0 100644 --- a/apps/fe/CLAUDE.md +++ b/apps/fe/CLAUDE.md @@ -13,7 +13,7 @@ Web app (Next.js App Router + NEAR Connect). Owner: Ancung. Design comes from Na - Streams: chat, approve/decline and builder runs are POST + SSE, so `EventSource` can't be used; read the `fetch` body with `eventsource-parser` 4.1.3. - Forms: `react-hook-form` 7.91.0 + `zod` 4.6.7 + `@hookform/resolvers` 7.0.3 (validate as you type, as in the design). - Bottom drawers on phones (`ResponsiveDialog`, "Add a block", a Builder block's settings, the live view) share one roomy spacing (Ancung, 11 Nov, after Welcome). `DrawerContent`'s classes go on the outer popup while its children sit in an inner element with no gap, so the spacing between parts lives on a wrapper inside it (`ResponsiveDialog`) or as margins ("Add a block"); the side padding lives inside too, since that inner element clips, and padding on the outer popup cut the left edge of a title's first letter (Ancung, 11 Nov); a header there is left-aligned (the drawer centres it by default), except Welcome (`centered`). The sizes: 20 px sides, 20 px between parts, 8 px between a title and its text, 12 px between stacked buttons, and at least 24 px at the bottom (more with a home indicator). -- Toasts: `sonner` 2.0.8 (shadcn's). Theme: `next-themes` 0.4.6 (System, Light, Dark from the account menu). Mind replies: `react-markdown` 10.1.0 with `remark-gfm` 4.0.1 (tables, strikethrough, task lists, bare links; added 9 Nov when a reply's table showed as pipes). Wide tables scroll sideways inside the reply. Springs (Penny is ready, freeze, Builder drag): `motion` 14.10.0; everything else is CSS. Thinking indicators (Thinking... and every running step row, by kind of work: `orb` in `TOOLS` (`runs/data/tools.ts`, every tool's words in one list), read by `stepOrb`, reading searching, websites connecting, writing composing, acting working, time and sums solving, memory breathing, waiting for the owner listening): `thinking-orbs` 0.3.2 (MIT, no runtime dependencies; Axel's pick, 10 Nov): ``, a dotted canvas orb that follows the `dark` class, freezes with reduced motion and pauses off screen by itself. Only the free states and the 20 and 64 sizes (libraries.dev marks some as Pro). +- Toasts: `sonner` 2.0.8 (shadcn's). Theme: `next-themes` 0.4.6 (System, Light, Dark from the account menu). Mind replies: `react-markdown` 10.1.0 with `remark-gfm` 4.0.1 (tables, strikethrough, task lists, bare links; added 9 Nov when a reply's table showed as pipes). Wide tables scroll sideways inside the reply. Springs (Penny is ready, freeze, Builder drag): `motion` 14.10.0; everything else is CSS. Thinking indicators (Thinking... and every running step row, by kind of work: `orb` in `TOOLS` (`runs/data/tools.ts`, every tool's words in one list), read by `stepOrb`, reading searching, websites connecting, writing composing, acting working, time and sums solving, memory breathing, waiting for the owner listening): `thinking-orbs` 0.3.2 (MIT, no runtime dependencies; Axel's pick, 10 Nov): ``, a dotted canvas orb that follows the `dark` class, freezes with reduced motion and pauses off screen by itself. Only the free states and the 20 and 64 sizes (libraries.dev marks some as Pro). The composer's beam: `border-beam` 1.4.1 (MIT, the same maker; Ancung, 11 Nov), `size="line"` (a light travelling along the box's bottom edge), on only while the Mind replies (`active={busy}`), `mono` tinted to the brand lime in globals.css (`.composer-beam`: the library has no custom colour, so its own layers get `sepia saturate hue-rotate`, the bloom keeping its 6 px blur; the text is untouched). - Tests: `vitest` 5.1.0 (unit, `tests/*.test.ts`, config `vitest.config.mts`) with a 15 s test timeout (a few tests that import inside themselves timed out at 5 s on Windows beside the dev server), `@playwright/test` 1.65.0 (flows). - Motion: easing tokens are in `src/styles/globals.css` (`ease-out`, `ease-in-out`, `ease-drawer` utilities; Tailwind only emits them once used). Rules, durations and chat streaming: `design/CLAUDE.md` "Motion (v0.3)". shadcn components keep their own animation classes; set menus and popovers to grow from `--transform-origin` (Base UI provides it) and make exits faster than entries. - Scaffolded with `create-near-app` 10.0.0 (`--frontend next-app`). All versions in `package.json` are pinned exactly; do not upgrade during the hackathon. @@ -102,7 +102,7 @@ Chat (`/minds/[mindId]/chat` and `/chat/[threadId]`, `src/modules/chat`, design Live view (beside the chat, `src/modules/graph`, design C2 "What Penny is doing", #17), like Obsidian's graph view (Axel, via Ancung, 10 Nov): - `data/graph.ts` `buildGraph` (app bubbles follow engine/src/graph.ts: every app's tools, the track apps of #211 included, are one App bubble, hung off the skill that uses it, so it reads Mind, skill, app; named "Your Notion" beside the Notion skill, with its logo from `APPS`; Ancung, 11 Nov: the track apps showed twice and without a logo): the Mind in the centre, each equipped skill (not blocked ones), the tools, apps and wallet each skill reaches (`GET /skills` `tools` and `connections`), then anything the events touched; node ids are the engine's (`nodeIdFor`, docs/api-contract.md §4), so live events light the nodes the history built. `uses` counts calls, the last state is running, waiting (an approval), ok, error or denied (`policy_denied`, `wallet_frozen`). A meeting with a Meet link lights Google Meet too. Only live states pulse (`liveStates`): running for the run on screen, waiting for an approval still in `GET …/approvals`; history only sizes the bubbles (Ancung, 10 Nov: Meet and Wallet pulsed from an old, declined approval, which never gets a result event). Mastra's `updateWorkingMemory` is the Memory node. - Events: the last 7 days from `GET /minds/{id}/events?limit=2000`, plus `ChatRunProvider`'s run on screen; read again when a run ends. -- `components/MindGraph.tsx` draws on a canvas: `data/sim.ts` (every pair pushes apart, links pull like springs, a pull to the centre, cools down; the Mind stays in the centre), bubbles coloured by kind from the `node-*` tokens (read from CSS, again when the theme changes), the Mind's avatar in the centre, Gmail, Google Calendar and Google Meet with their own logos (`AppLogos`, serialised to images), labels under every bubble, drawn last with an outline in the background colour so lines and bubbles never hide them (tools quieter). The layout keeps room for the labels (stronger push, longer links; Ancung, 10 Nov: the first one was too tight): each bubble with its label is a box and overlapping boxes are pushed apart, bubbles keep off lines that aren't theirs, and a tool several skills share hangs off the first one only, a tree, so lines don't cross (`tests/graph.test.ts` checks a seven-skill Mind settles with no box on another and no bubble on a line). The built-in HelloNear guide isn't drawn; a job is named from its id ("wallet-watch" reads "Wallet watch"). While a tool works, dots travel along the links from the Mind and its bubble pulses (blue running, amber waiting); a result rings green, a failure or a blocked payment red. The reply on screen leaves a trail (Ancung, 10 Nov: a 1 s calendar call showed nothing): the links from the Mind to every node it used stay blue with slow dots while it streams, and stay softly lit for the last reply, with a ring on those bubbles. Pulses are timed from when this page saw the state change, not the event's server time, and only the run on screen pulses (history loading in after the first draw lit up the whole graph on open, Ancung, 10 Nov). From Obsidian's graph (Axel's screen recording, 10 Nov), keeping the colours that say what each node is and how it went: dragging keeps the layout warm so linked bubbles follow like rubber bands and sway back on release. Labels always show and hover doesn't glow (tried, then dropped with Ancung the same day). A torch follows the mouse instead: the parts of the lines near the cursor catch a lime light (`--focus`, a radial gradient over the lines within reach) that fades with distance. Hover dims nothing (Ancung, 10 Nov: dimming the rest felt odd), its label turns bold, and the cursor is a magnet anywhere on the canvas: every bubble within 120 screen px leans toward it, the nearer the stronger (up to a third of the way, at most 8 units, eased), and its lines follow (drawn only, the layout never sees it; none while dragging or with reduced motion; Ancung, 11 Nov); drag a bubble, drag the background (or Space + drag, or the middle button, even over a bubble) to pan; the wheel works like the Builder's canvas (Ancung, 11 Nov): scroll or two fingers pan, Shift + scroll pans sideways, Ctrl/Cmd + scroll or a trackpad pinch zooms around the pointer (the Builder's `wheelPixels`, `wheelPan`, `wheelZoomFactor`); with the graph focused, + and - zoom, 0 is 100%, 1 or F fits; a two-finger pinch on a touch screen zooms (around the point between the fingers; a second finger ends a bubble drag; Ancung, 10 Nov), Fit to frame it again. Clicking a node glides the camera to it and zooms in (Esc, X or a click on empty canvas lets go; Fit goes back), and a card under the graph says what it is (`describe`), how often it was used, and its latest five calls as the chat's step rows that open to show what went in and came back (`callsOf`; a skill shows the calls of the tools under it, the Mind all of them) (Axel, via Ancung, 10 Nov). Reduced motion keeps the colours without moving dots or rings. It stops drawing while off screen. The layout and the camera are kept per Mind across mounts (`KEPT` in `MindGraph.tsx`), so sending from New chat (which moves to the thread's URL and mounts a new page) doesn't replay the settling, and only new bubbles warm the layout up; a state change or a count doesn't (Ancung, 10 Nov: every event of a reply set it bouncing). The first graph of a Mind on a page is settled before it is drawn and framed at once (`settle`, no bounce or zoom out), and the layout remembers where every bubble sat (`Sim.seen`), so one that drops out for a moment while a chat page mounts comes back to its place without warming anything up (Ancung, 11 Nov: switching chats replayed the zoom out and the jiggle). The panel draws only the chat on screen's run: ChatScreen passes its `activeHere` (`LiveView` `active`), so after switching chats it no longer shows the other chat's reply, trail or steps. +- `components/MindGraph.tsx` draws on a canvas: `data/sim.ts` (every pair pushes apart, links pull like springs, a pull to the centre, cools down; the Mind stays in the centre), bubbles coloured by kind from the `node-*` tokens (read from CSS, again when the theme changes), the Mind's avatar in the centre, Gmail, Google Calendar and Google Meet with their own logos (`AppLogos`, serialised to images), labels under every bubble, drawn last with an outline in the background colour so lines and bubbles never hide them (tools quieter). The layout keeps room for the labels (stronger push, longer links; Ancung, 10 Nov: the first one was too tight): each bubble with its label is a box and overlapping boxes are pushed apart, bubbles keep off lines that aren't theirs, and a tool several skills share hangs off the first one only, a tree, so lines don't cross (`tests/graph.test.ts` checks a seven-skill Mind settles with no box on another and no bubble on a line). The built-in HelloNear guide isn't drawn; a job is named from its id ("wallet-watch" reads "Wallet watch"). While a tool works, dots travel along the links from the Mind and its bubble pulses (blue running, amber waiting); a result rings green, a failure or a blocked payment red. The reply on screen leaves a trail (Ancung, 10 Nov: a 1 s calendar call showed nothing): the links from the Mind to every node it used stay blue with slow dots while it streams, and stay softly lit for the last reply, with a ring on those bubbles. Pulses are timed from when this page saw the state change, not the event's server time, and only the run on screen pulses (history loading in after the first draw lit up the whole graph on open, Ancung, 10 Nov). From Obsidian's graph (Axel's screen recording, 10 Nov), keeping the colours that say what each node is and how it went: dragging keeps the layout warm so linked bubbles follow like rubber bands and sway back on release. Labels always show and hover doesn't glow (tried, then dropped with Ancung the same day). A torch follows the mouse instead: the parts of the lines near the cursor catch a lime light (`--focus`, a radial gradient over the lines within reach) that fades with distance. Hover dims nothing (Ancung, 10 Nov: dimming the rest felt odd), its label turns bold, and the cursor is a magnet anywhere on the canvas: every bubble within 120 screen px leans toward it, the nearer the stronger (up to a third of the way, at most 8 units, eased), and its lines follow (drawn only, the layout never sees it; none while dragging or with reduced motion; Ancung, 11 Nov); drag a bubble, drag the background (or Space + drag, or the middle button, even over a bubble) to pan; the wheel works like the Builder's canvas (Ancung, 11 Nov): scroll or two fingers pan, Shift + scroll pans sideways, Ctrl/Cmd + scroll or a trackpad pinch zooms around the pointer (the Builder's `wheelPixels`, `wheelPan`, `wheelZoomFactor`); with the graph focused, + and - zoom, 0 is 100%, 1 or F fits; a two-finger pinch on a touch screen zooms (around the point between the fingers; a second finger ends a bubble drag; Ancung, 10 Nov), Fit to frame it again. Clicking a node glides the camera to it and zooms in (Esc, X or a click on empty canvas lets go; Fit goes back), and a card under the graph says what it is (`describe`), how often it was used, and its latest five calls as the chat's step rows that open to show what went in and came back (`callsOf`; a skill shows the calls of the tools under it, the Mind all of them) (Axel, via Ancung, 10 Nov). Reduced motion keeps the colours without moving dots or rings. It stops drawing while off screen. The layout and the camera are kept per Mind across mounts (`KEPT` in `MindGraph.tsx`), and every chat page's graph comes in with a zoom out over its layout (from 1.35 times the frame's zoom to it, 700 ms, ease-out quart; Ancung, 11 Nov: on every chat, like stepping in; the layout stays put, so nothing jiggles), at once with reduced motion; a new page also puts the camera back on automatic framing. A layout to settle (the first graph, or three or more new bubbles) is settled by the draw loop in slices of at most 6 ms a frame (`SETTLE_BUDGET_MS`) and drawn once still: 35 bubbles took 23 to 58 ms in one go on a laptop (60 took 73 to 87), so a phone would freeze. The desktop panel's graph is only made on screens of 1280 px and up (`ChatScreen`, `wide`): below, the hidden panel still fetched and laid out the graph on every chat page; phones and tablets make it only when the drawer or sheet opens. A graph off screen draws nothing, so it settles and animates nothing either (a zoom or a click on a bubble used to stick, so every chat opened after it was zoomed into the Mind, Ancung, 11 Nov); the camera never frames the Mind alone, and while automatic it reframes, gliding, whenever the number of bubbles changes, so sending from New chat (which moves to the thread's URL and mounts a new page) doesn't replay the settling, and only new bubbles warm the layout up; a state change or a count doesn't (Ancung, 10 Nov: every event of a reply set it bouncing). The first graph of a Mind on a page is settled before it is drawn and framed at once (`settle`, no bounce or zoom out); so is a graph that grows by three or more bubbles at once (framed at once only while opening, when nothing but the Mind was there; later the camera glides there, and only if the owner hasn't moved it, since a snap during a reply read as the graph zooming by itself), since the first one often holds only the Mind before its skills and history arrive (they piled in and bounced, Ancung, 11 Nov: "too much jiggle"). One or two new bubbles only nudge it (0.25), and settling on its own uses more friction (0.74) than a drag does (0.86, so a released bubble still sways back), and the layout remembers where every bubble sat (`Sim.seen`), so one that drops out for a moment while a chat page mounts comes back to its place without warming anything up (Ancung, 11 Nov: switching chats replayed the zoom out and the jiggle). The panel draws only the chat on screen's run: ChatScreen passes its `activeHere` (`LiveView` `active`), so after switching chats it no longer shows the other chat's reply, trail or steps. - `components/LiveView.tsx`: the panel ("What {name} is doing", Live dot while streaming, the graph, the picked node, this reply's step rows, and "Waiting for you" from `GET …/approvals` linking to the chat that asked). Beside the chat from 1280 px (`xl`), 360 px wide, toggled with "Live view" in the chat header and remembered (`hellonear.chat.live`, read during render through `useLiveOpen` in `data/liveOpen.ts`, so moving between chats never flashes it open; Ancung, 10 Nov), opening and closing like the app's sidebar (the width slides 0 <-> 360 px, ease-in-out 200 ms, the panel fades; no slide on first paint); below 1280 px the same button opens it in a sheet. Phones have no chat header, so the Live view button sits in the phone's top bar on the chat (`MobileHeader`, opening the chat's drawer through `graph/data/liveDrawer.ts`; it floated over the messages until 11 Nov and hid words); on phones it opens as a drawer from the bottom (85% of the screen, swipe down to close; dragging on the graph moves the graph, not the drawer), on tablets as a sheet from the right (Ancung, 10 Nov). - Not checked in a browser yet. diff --git a/apps/fe/bun.lock b/apps/fe/bun.lock index d475efc0..26253ca5 100644 --- a/apps/fe/bun.lock +++ b/apps/fe/bun.lock @@ -10,6 +10,7 @@ "@hot-labs/near-connect": "0.12.0", "@tanstack/react-query": "5.106.1", "@xyflow/react": "12.12.1", + "border-beam": "1.4.1", "class-variance-authority": "0.7.1", "cn": "0.5.2", "eventsource-parser": "4.1.3", @@ -524,6 +525,8 @@ "bip39-light": ["bip39-light@1.0.7", "", { "dependencies": { "create-hash": "^1.1.0", "pbkdf2": "^3.0.9" } }, "sha512-WDTmLRQUsiioBdTs9BmSEmkJza+8xfJmptsNJjxnoq3EydSa/ZBXT6rm66KoT3PJIRYMnhSKNR7S9YL1l7R40Q=="], + "border-beam": ["border-beam@1.4.1", "", { "peerDependencies": { "react": ">=18.0.0", "react-dom": ">=18.0.0" } }, "sha512-YyugmKjrhkg1PBC1ZKX7JvFo/zYzha6NXOq24VWrnvBYmDRvGCgFS9oxZoKJ+oS9Kn436l1etYGlAdGiWK+3ag=="], + "borsh": ["borsh@2.0.0", "", {}, "sha512-kc9+BgR3zz9+cjbwM8ODoUB4fs3X3I5A/HtX7LZKxCLaMrEeDFoBpnhZY//DTS1VZBSs6S5v46RZRbZjRFspEg=="], "brace-expansion": ["brace-expansion@1.1.21", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-9zeA+KLZNNzglF2TPKRQEDyx6Yby7daAkuy8MiPzpXPsYDWi/DRM8jmwUDxokQjYqBpv5DgPiwD4h4ZZSy1Ujw=="], diff --git a/apps/fe/package.json b/apps/fe/package.json index 24f41963..4766b796 100644 --- a/apps/fe/package.json +++ b/apps/fe/package.json @@ -19,6 +19,7 @@ "@hot-labs/near-connect": "0.12.0", "@tanstack/react-query": "5.106.1", "@xyflow/react": "12.12.1", + "border-beam": "1.4.1", "class-variance-authority": "0.7.1", "cn": "0.5.2", "eventsource-parser": "4.1.3", diff --git a/apps/fe/src/modules/chat/components/ChatScreen.tsx b/apps/fe/src/modules/chat/components/ChatScreen.tsx index 2d23af71..2a5ffb4e 100644 --- a/apps/fe/src/modules/chat/components/ChatScreen.tsx +++ b/apps/fe/src/modules/chat/components/ChatScreen.tsx @@ -25,6 +25,7 @@ import { dayLabel } from "@/modules/chat/data/thread" import { Shown, TurnView } from "@/modules/chat/components/TurnView" import { FirstChat, Centered, ThreadSkeleton } from "@/modules/chat/components/ChatStates" import { onLiveDrawer } from "@/modules/graph/data/liveDrawer" +import { useMediaQuery } from "@/hooks/useMediaQuery" /** * Chat (design 4 · Chat, C1): the thread, what each run did, and the composer. `threadId` null @@ -51,6 +52,7 @@ export function ChatScreen({ mindId, threadId }: { mindId: string; threadId: str // The live view (C2, #17): beside the chat from 1280 px, remembered per device; a sheet below that. const liveOpen = useLiveOpen() + const wide = useMediaQuery(MEDIA.xl, false) const [liveSheet, setLiveSheet] = useState(false) // Phones get it as a drawer from the bottom (Ancung, 10 Nov), tablets as a sheet from the right. const [liveDrawer, setLiveDrawer] = useState(false) @@ -371,7 +373,11 @@ export function ChatScreen({ mindId, threadId }: { mindId: string; threadId: str liveOpen ? "opacity-100 delay-50" : "opacity-0" )} > - + {/* Only made on screens wide enough to show it (1280 px): below that the panel is hidden, + and it still fetched the history, laid out the graph and readied its entrance on + every chat page (Ancung, 11 Nov: no animating what a phone doesn't show). Phones and + tablets make it only when the drawer or sheet opens. */} + {wide && } diff --git a/apps/fe/src/modules/chat/components/Composer.tsx b/apps/fe/src/modules/chat/components/Composer.tsx index 9565423d..acf5b872 100644 --- a/apps/fe/src/modules/chat/components/Composer.tsx +++ b/apps/fe/src/modules/chat/components/Composer.tsx @@ -6,6 +6,8 @@ import { Spinner } from "@/components/elements/Spinner" import { Button } from "@/components/ui/button" import { readPref, writePref } from "@/lib/storage" import { MEDIA, matches } from "@/lib/media" +import { BorderBeam } from "border-beam" +import { useTheme } from "next-themes" /** * The message box (C1.1). Enter sends, Shift+Enter adds a line. While the Mind replies, the send @@ -60,6 +62,7 @@ export function Composer({ } const message = value.trim() const canSend = !busy && !locked && message.length > 0 + const { resolvedTheme } = useTheme() function send() { if (!canSend) return @@ -82,7 +85,10 @@ export function Composer({ }} className="flex w-full flex-col gap-2" > -
+ {/* A beam travels along the box's bottom edge only while the Mind replies (Ancung, 11 Nov), + like "Thinking...": off otherwise, so nothing moves while the owner types. */} + +
@@ -108,6 +114,7 @@ export function Composer({ )}
+

{note}

) diff --git a/apps/fe/src/modules/graph/components/MindGraph.tsx b/apps/fe/src/modules/graph/components/MindGraph.tsx index 77c66c31..0b7459f2 100644 --- a/apps/fe/src/modules/graph/components/MindGraph.tsx +++ b/apps/fe/src/modules/graph/components/MindGraph.tsx @@ -6,7 +6,7 @@ import { setFlag } from "@/modules/onboarding/data/progress" import { wheelPan, wheelPixels, wheelZoomFactor } from "@/modules/builder/hooks/useCanvasView" import { APPS } from "@/modules/connections/data/apps" import type { GraphLink, GraphNode } from "@/modules/graph/data/graph" -import { settle, stepSim, syncSim, type Sim } from "@/modules/graph/data/sim" +import { stepSim, syncSim, type Sim } from "@/modules/graph/data/sim" import { MEDIA } from "@/lib/media" import { clampZoom, framing, toWorld as worldAt, zoomAround } from "@/modules/graph/data/camera" import { readColors, FILL } from "@/modules/graph/data/colors" @@ -39,6 +39,11 @@ const KEPT = new Map()) - const view = useRef(KEPT.get(mindId)?.view ?? { x: 0, y: 0, k: 1, auto: true }) + // The camera kept from the last chat, but always back on automatic framing: a zoom or a click on + // a bubble (which zooms to it) used to stick, so every chat opened after it was zoomed into the + // Mind (Ancung, 11 Nov). The layout itself is kept, so nothing replays. + const view = useRef({ ...(KEPT.get(mindId)?.view ?? { x: 0, y: 0, k: 1 }), auto: true }) // The node the camera is gliding to after a click (Axel, via Ancung, 10 Nov: zoom to it). const focus = useRef(null) const lastSelected = useRef(null) - // Frame the layout at once on the next draw, instead of easing toward it. + // Frame the layout at once on the next draw, instead of easing toward it. A page that finds a + // kept layout frames it at once too, without a glide. const snap = useRef(false) // Fit was pressed: glide to the frame until there. const fitting = useRef(false) + // How many bubbles the camera last framed, so a change reframes it. + const framedCount = useRef(0) + // A layout to settle before it is drawn, a slice each frame (see SETTLE_BUDGET_MS). + const pendingSettle = useRef(false) + // The entrance zoom out: null when none, -1 waiting for the first frame, else when it started. + // Every chat page plays it over the kept layout (Ancung, 11 Nov: like stepping into the chat); + // the layout itself stays put, so nothing jiggles. + const entering = useRef(KEPT.has(mindId) ? -1 : null) + // No layout kept for this Mind yet: its first real frame on this page gets the entrance, even if + // the very first graph held only the Mind. + const fresh = useRef(!KEPT.has(mindId)) const hover = useRef(null) // How far each bubble leans toward the cursor right now (drawn only), and whether one is dragged. const magnet = useRef(new Map()) @@ -89,12 +109,28 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect, } lastSelected.current = selected const first = sim.current === null + const before = sim.current?.bodies.size ?? 0 sim.current = syncSim(sim.current, nodes, links, mind) // The first graph of this Mind on this page shows settled and framed at once: no bounce, no - // zoom out (Ancung, 11 Nov). Later, only bubbles that are really new nudge it. - if (first && nodes.length > 1) { - settle(sim.current, new Map(nodes.map((n) => [n.id, n.kind]))) - snap.current = true + // zoom out (Ancung, 11 Nov). So does a graph that grows by several bubbles at once: the first + // one often holds only the Mind, before its skills and history arrive, and they then piled in + // and bounced into place (Ancung, 11 Nov: "too much jiggle"). One or two new ones only nudge it. + const grew = sim.current.bodies.size - before + if ((first && nodes.length > 1) || grew >= 3) { + // Settled in slices by the draw loop (SETTLE_BUDGET_MS a frame), not here at once: 35 + // bubbles took 23 to 58 ms on a laptop, so a phone would freeze for a few hundred. A graph + // that isn't on screen doesn't draw, so it doesn't settle either. + pendingSettle.current = true + // Frame it at once only while the graph is opening (nothing but the Mind before). Later, the + // camera glides to the new frame, and only if the owner hasn't moved it: snapping during a + // reply read as the graph zooming by itself (Ancung, 11 Nov). + // The very first graph of this Mind on the page comes in with a zoom out (ENTER_MS); a page + // that finds the layout kept, or one still opening, frames at once. + if (fresh.current) { + fresh.current = false + entering.current = -1 + } else if (before <= 1 && entering.current === null) snap.current = true + else fitting.current = true } const now = performance.now() for (const n of nodes) { @@ -193,6 +229,28 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect, } const to = framing({ x0, y0, x1, y1 }, size) const v = view.current + // The Mind alone is no frame: zooming to it is what stuck when a chat page opened before the + // other bubbles were back (Ancung, 11 Nov). Wait for them, keeping a pending snap. + if (bodies.length <= 1) return + // The entrance (Ancung, 11 Nov): start a little zoomed in on the frame's middle and ease out + // to it, fast at first and slowing at the end. Reduced motion frames at once. + if (entering.current !== null && !still.matches) { + const now = performance.now() + if (entering.current < 0) entering.current = now + const p = Math.min(1, (now - entering.current) / ENTER_MS) + const e = 1 - (1 - p) ** 4 + const from = ENTER_ZOOM + (1 - ENTER_ZOOM) * e + // Scaling the frame about the panel's middle keeps the same spot in the middle. + v.k = to.k * from + v.x = to.x * from + v.y = to.y * from + if (p >= 1) entering.current = null + return + } + if (entering.current !== null) { + entering.current = null + snap.current = true + } if (snap.current) { snap.current = false v.k = to.k @@ -227,8 +285,26 @@ export function MindGraph({ mindId, nodes, links, avatarSrc, selected, onSelect, const s = sim.current if (!s) return const kinds = new Map(data.current.nodes.map((n) => [n.id, n.kind])) + if (pendingSettle.current) { + const until = now + SETTLE_BUDGET_MS + let warm = true + while (warm && performance.now() < until) warm = stepSim(s, kinds) + // Not still yet: nothing drawn this frame, the rest next frame. Then it appears settled. + if (warm) { + ctx.setTransform(1, 0, 0, 1, 0, 0) + ctx.clearRect(0, 0, cv.width, cv.height) + return + } + pendingSettle.current = false + } const moving = stepSim(s, kinds) - if (view.current.auto && (moving || snap.current || fitting.current || now < 1500)) fit() + // While the camera is automatic, a change in how many bubbles there are reframes it (gliding), + // so bubbles that come back one or two at a time are never left outside it. + if (view.current.auto && s.bodies.size !== framedCount.current && s.bodies.size > 1) { + framedCount.current = s.bodies.size + fitting.current = true + } + if (view.current.auto && (moving || snap.current || fitting.current || entering.current !== null || now < 1500)) fit() // Glide to the picked node and zoom in a little; a jump with reduced motion. const f = focus.current ? s.bodies.get(focus.current) : null if (f) { diff --git a/apps/fe/src/modules/graph/data/sim.ts b/apps/fe/src/modules/graph/data/sim.ts index 9d1d0229..eb20a127 100644 --- a/apps/fe/src/modules/graph/data/sim.ts +++ b/apps/fe/src/modules/graph/data/sim.ts @@ -64,7 +64,9 @@ export function syncSim(prev: Sim | null, nodes: GraphNode[], links: GraphLink[] // reply set it bouncing again). const seen = new Map(prev?.seen) for (const b of prev?.bodies.values() ?? []) seen.set(b.id, { x: b.x, y: b.y }) - return { bodies, links, alpha: !prev ? 1 : added ? Math.max(prev.alpha, 0.5) : prev.alpha, seen } + // A bubble or two joining only nudges it (0.25, was 0.5: Ancung, 11 Nov, the entrance read as + // too much jiggle); many at once are settled before drawing (MindGraph). + return { bodies, links, alpha: !prev ? 1 : added ? Math.max(prev.alpha, 0.25) : prev.alpha, seen } } /** Run the layout until it is still (or `max` ticks), so a first graph shows settled, without the bounce. */ @@ -77,6 +79,8 @@ export function stepSim(sim: Sim, kinds: Map): boolean { if (sim.alpha < 0.004) return false const list = [...sim.bodies.values()] const a = sim.alpha + // The Mind is always pinned; another pinned bubble is one being dragged. + const friction = list.filter((b) => b.pinned).length > 1 ? 0.86 : 0.74 // Every pair pushes apart, more when close. for (let i = 0; i < list.length; i++) { for (let j = i + 1; j < list.length; j++) { @@ -128,9 +132,10 @@ export function stepSim(sim: Sim, kinds: Map): boolean { // A pull to the centre, and friction. b.vx -= b.x * 0.0025 * a b.vy -= b.y * 0.0025 * a - // A little less friction than a dead stop, so a pulled bubble sways back (Obsidian). - b.vx *= 0.86 - b.vy *= 0.86 + // While a bubble is dragged, a little less friction than a dead stop, so it sways back on + // release (Obsidian). Settling on its own, more, so it comes to rest without bouncing. + b.vx *= friction + b.vy *= friction b.x += b.vx b.y += b.vy } diff --git a/apps/fe/src/styles/globals.css b/apps/fe/src/styles/globals.css index 0f3ae482..5169ec5b 100644 --- a/apps/fe/src/styles/globals.css +++ b/apps/fe/src/styles/globals.css @@ -400,3 +400,14 @@ display: none; } } + +/* The composer's beam (border-beam, Composer.tsx) has no colour of its own to set: its "mono" light + is tinted to the brand lime here, on the beam's own layers only so the text keeps its colour. + The bloom keeps the 6 px blur the library gives it (Ancung, 11 Nov). */ +.composer-beam::before, +.composer-beam::after { + filter: sepia(1) saturate(6) hue-rotate(28deg) brightness(1.08); +} +.composer-beam [data-beam-bloom] { + filter: blur(6px) sepia(1) saturate(6) hue-rotate(28deg) brightness(1.08); +}