vestige/apps/dashboard/build/_app/immutable/nodes/8.BmBiit5q.js
Sam Valladares 4c2016596c feat(graph): FSRS memory-state colour mode + legend overlay
Closes Agent 1's audit gap #4: FSRS memory state (Active / Dormant /
Silent / Unavailable) was computed server-side per query but never
rendered in the 3D graph. Spheres always tinted by node type.

The new colour mode adds a second channel that users can toggle
between at runtime — Type (default, existing behaviour) and State
(new). The toggle is a radio-pair pill in the graph page's top-right
control bar next to the node-count selector + Dream button.

Buckets + palette:
- Active    ≥ 70%  emerald #10b981  easily retrievable
- Dormant  40-70%  amber   #f59e0b  retrievable with effort
- Silent   10-40%  violet  #8b5cf6  difficult, needs cues
- Unavail.  < 10%  slate   #6b7280  needs reinforcement

Thresholds match `execute_system_status` at the backend so the graph
colour bands line up exactly with what the Stats page reports in its
stateDistribution block. Using retention as the proxy for the full
accessibility formula (retention × 0.5 + retrieval × 0.3 + storage ×
0.2) is an approximation — retention is the dominant 0.5 weight and
it is the only FSRS channel the current GraphNode DTO carries. Swap
to the full formula in a future release if the DTO grows.

Implementation:
- `apps/dashboard/src/lib/graph/nodes.ts` — new `MemoryState` type,
  `getMemoryState(retention)`, `MEMORY_STATE_COLORS`,
  `MEMORY_STATE_DESCRIPTIONS`, `ColorMode`, `getNodeColor(node, mode)`.
- `NodeManager.colorMode` field (default `'type'`). `createNodeMeshes`
  now calls `getNodeColor(node, this.colorMode)` so newly-added nodes
  during the session follow the toggled mode.
- New `NodeManager.setColorMode(mode)` mutates every live mesh's
  material + glow sprite colour in place. Idempotent; cheap. Does NOT
  touch opacity/emissive-intensity so the v2.0.5 suppression dimming
  layer keeps working unchanged.
- New `MemoryStateLegend.svelte` floating overlay in the bottom-right
  when state mode is active (hidden in type mode so the legend doesn't
  compete with the node-type palette).
- `Graph3D.svelte` accepts a new `colorMode` prop (default `'type'`)
  and runs a `$effect` that calls `setColorMode` on every toggle.
- Dashboard rebuild picks up the new component + wiring.

Tests: 171 vitest, svelte-check 581 files / 0 errors. No backend
changes; this is pure dashboard code.
2026-04-19 20:45:08 -05:00

4 lines
6.9 KiB
JavaScript

import"../chunks/Bzak7iHL.js";import{o as Be}from"../chunks/DWVWfZUn.js";import{p as Qe,s as b,c as Ye,t as D,g as e,a as ze,d as t,e as o,h as x,r as a}from"../chunks/VE8Jor13.js";import{d as Ge,a as n,s as v}from"../chunks/DHnEMX8z.js";import{i as ue}from"../chunks/JkhlGLjU.js";import{e as ee,i as xe}from"../chunks/ByItJEsC.js";import{a as g,f}from"../chunks/7UNxJI5L.js";import{r as _e}from"../chunks/Cu3VmnGp.js";import{s as He}from"../chunks/BR2EHpd7.js";import{s as ge}from"../chunks/ussr1V5_.js";import{b as fe}from"../chunks/BRHZEveZ.js";import{b as Ie}from"../chunks/B5Pq2mnD.js";import{a as u}from"../chunks/DcQGRi49.js";import{N as Je}from"../chunks/BNytumrp.js";var Ke=f('<div class="h-24 glass-subtle rounded-xl animate-pulse"></div>'),Ue=f('<div class="grid gap-3"></div>'),Ve=f('<span class="text-xs px-1.5 py-0.5 bg-white/[0.04] rounded text-muted"> </span>'),We=f('<div class="mt-4 pt-4 border-t border-synapse/10 space-y-3"><p class="text-sm text-text whitespace-pre-wrap"> </p> <div class="grid grid-cols-3 gap-3 text-xs text-dim"><div> </div> <div> </div> <div> </div></div> <div class="flex gap-2"><span role="button" tabindex="0" class="px-3 py-1.5 bg-recall/20 text-recall text-xs rounded-lg hover:bg-recall/30 cursor-pointer select-none">Promote</span> <span role="button" tabindex="0" class="px-3 py-1.5 bg-decay/20 text-decay text-xs rounded-lg hover:bg-decay/30 cursor-pointer select-none">Demote</span> <span role="button" tabindex="0" title="Top-down inhibition (Anderson 2025). Compounds. Reversible for 24h." class="px-3 py-1.5 bg-purple-500/20 text-purple-400 text-xs rounded-lg hover:bg-purple-500/30 cursor-pointer select-none">Suppress</span> <span role="button" tabindex="0" class="px-3 py-1.5 bg-decay/10 text-decay/60 text-xs rounded-lg hover:bg-decay/20 ml-auto cursor-pointer select-none">Delete</span></div></div>'),Xe=f('<button><div class="flex items-start justify-between gap-4"><div class="flex-1 min-w-0"><div class="flex items-center gap-2 mb-2"><span class="w-2 h-2 rounded-full"></span> <span class="text-xs text-dim"> </span> <!></div> <p class="text-sm text-text leading-relaxed line-clamp-2"> </p></div> <div class="flex flex-col items-end gap-1 flex-shrink-0"><div class="w-12 h-1.5 bg-deep rounded-full overflow-hidden"><div class="h-full rounded-full"></div></div> <span class="text-xs text-muted"> </span></div></div> <!></button>'),Ze=f('<div class="grid gap-3"></div>'),et=f(`<div class="p-6 max-w-6xl mx-auto space-y-6"><div class="flex items-center justify-between"><h1 class="text-xl text-bright font-semibold">Memories</h1> <span class="text-dim text-sm"> </span></div> <div class="flex gap-3 flex-wrap"><input type="text" placeholder="Search memories..." class="flex-1 min-w-64 px-4 py-2.5 bg-white/[0.03] border border-synapse/10 rounded-xl text-text text-sm
placeholder:text-muted focus:outline-none focus:border-synapse/40 focus:ring-1 focus:ring-synapse/20 transition backdrop-blur-sm"/> <select class="px-3 py-2.5 bg-white/[0.03] border border-synapse/10 rounded-xl text-dim text-sm focus:outline-none backdrop-blur-sm"><option>All types</option><option>Fact</option><option>Concept</option><option>Event</option><option>Person</option><option>Place</option><option>Note</option><option>Pattern</option><option>Decision</option></select> <div class="flex items-center gap-2 text-xs text-dim"><span>Min retention:</span> <input type="range" min="0" max="1" step="0.1" class="w-24 accent-synapse"/> <span> </span></div></div> <!></div>`);function _t(me,be){Qe(be,!0);let k=b(Ye([])),P=b(""),S=b(""),he="",h=b(0),A=b(!0),T=b(null),te;Be(()=>m());async function m(){x(A,!0);try{const i={};e(P)&&(i.q=e(P)),e(S)&&(i.node_type=e(S)),e(h)>0&&(i.min_retention=String(e(h)));const c=await u.memories.list(i);x(k,c.memories,!0)}catch{x(k,[],!0)}finally{x(A,!1)}}function ye(){clearTimeout(te),te=setTimeout(m,300)}function we(i){return i>.7?"#10b981":i>.4?"#f59e0b":"#ef4444"}var C=et(),F=o(C),ae=t(o(F),2),ke=o(ae);a(ae),a(F);var M=t(F,2),$=o(M);_e($);var y=t($,2),R=o(y);R.value=R.__value="";var N=t(R);N.value=N.__value="fact";var O=t(N);O.value=O.__value="concept";var j=t(O);j.value=j.__value="event";var L=t(j);L.value=L.__value="person";var q=t(L);q.value=q.__value="place";var B=t(q);B.value=B.__value="note";var Q=t(B);Q.value=Q.__value="pattern";var se=t(Q);se.value=se.__value="decision",a(y);var oe=t(y,2),E=t(o(oe),2);_e(E);var ie=t(E,2),Pe=o(ie);a(ie),a(oe),a(M);var Se=t(M,2);{var Te=i=>{var c=Ue();ee(c,20,()=>Array(8),xe,(w,s)=>{var _=Ke();g(w,_)}),a(c),g(i,c)},$e=i=>{var c=Ze();ee(c,21,()=>e(k),w=>w.id,(w,s)=>{var _=Xe(),Y=o(_),z=o(Y),G=o(z),re=o(G),H=t(re,2),Ee=o(H,!0);a(H);var De=t(H,2);ee(De,17,()=>e(s).tags.slice(0,3),xe,(p,d)=>{var l=Ve(),J=o(l,!0);a(l),D(()=>v(J,e(d))),g(p,l)}),a(G);var ne=t(G,2),Ae=o(ne,!0);a(ne),a(z);var pe=t(z,2),I=o(pe),Ce=o(I);a(I);var de=t(I,2),Fe=o(de);a(de),a(pe),a(Y);var Me=t(Y,2);{var Re=p=>{var d=We(),l=o(d),J=o(l,!0);a(l);var K=t(l,2),U=o(K),Ne=o(U);a(U);var V=t(U,2),Oe=o(V);a(V);var le=t(V,2),je=o(le);a(le),a(K);var ve=t(K,2),W=o(ve),X=t(W,2),Z=t(X,2),ce=t(Z,2);a(ve),a(d),D((r,Le,qe)=>{v(J,e(s).content),v(Ne,`Storage: ${r??""}%`),v(Oe,`Retrieval: ${Le??""}%`),v(je,`Created: ${qe??""}`)},[()=>(e(s).storageStrength*100).toFixed(1),()=>(e(s).retrievalStrength*100).toFixed(1),()=>new Date(e(s).createdAt).toLocaleDateString()]),n("click",W,r=>{r.stopPropagation(),u.memories.promote(e(s).id)}),n("keydown",W,r=>{r.key==="Enter"&&(r.stopPropagation(),u.memories.promote(e(s).id))}),n("click",X,r=>{r.stopPropagation(),u.memories.demote(e(s).id)}),n("keydown",X,r=>{r.key==="Enter"&&(r.stopPropagation(),u.memories.demote(e(s).id))}),n("click",Z,async r=>{r.stopPropagation(),await u.memories.suppress(e(s).id,"dashboard trigger")}),n("keydown",Z,async r=>{r.key==="Enter"&&(r.stopPropagation(),await u.memories.suppress(e(s).id,"dashboard trigger"))}),n("click",ce,async r=>{r.stopPropagation(),await u.memories.delete(e(s).id),m()}),n("keydown",ce,async r=>{r.key==="Enter"&&(r.stopPropagation(),await u.memories.delete(e(s).id),m())}),g(p,d)};ue(Me,p=>{var d;((d=e(T))==null?void 0:d.id)===e(s).id&&p(Re)})}a(_),D((p,d)=>{var l;He(_,1,`text-left p-4 glass-subtle rounded-xl hover:bg-white/[0.04]
transition-all duration-200 group
${((l=e(T))==null?void 0:l.id)===e(s).id?"!border-synapse/40 glow-synapse":""}`),ge(re,`background: ${(Je[e(s).nodeType]||"#8B95A5")??""}`),v(Ee,e(s).nodeType),v(Ae,e(s).content),ge(Ce,`width: ${e(s).retentionStrength*100}%; background: ${p??""}`),v(Fe,`${d??""}%`)},[()=>we(e(s).retentionStrength),()=>(e(s).retentionStrength*100).toFixed(0)]),n("click",_,()=>{var p;return x(T,((p=e(T))==null?void 0:p.id)===e(s).id?null:e(s),!0)}),g(w,_)}),a(c),g(i,c)};ue(Se,i=>{e(A)?i(Te):i($e,!1)})}a(C),D(i=>{v(ke,`${e(k).length??""} results`),v(Pe,`${i??""}%`)},[()=>(e(h)*100).toFixed(0)]),n("input",$,ye),fe($,()=>e(P),i=>x(P,i)),n("change",y,m),Ie(y,()=>e(S),i=>x(S,i)),n("change",E,m),fe(E,()=>e(h),i=>x(h,i)),g(me,C),ze()}Ge(["input","change","click","keydown"]);export{_t as component};