nlm-memory 0.5.19 → 0.5.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,6 @@ Error generating stack: `+a.message+`
64
64
  * LICENSE.md file in the root directory of this source tree.
65
65
  *
66
66
  * @license MIT
67
- */function Ol(){return Ol=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ol.apply(this,arguments)}function Sd(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,a;for(a=0;a<r.length;a++)l=r[a],!(t.indexOf(l)>=0)&&(n[l]=e[l]);return n}function Zh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function qh(e,t){return e.button===0&&(!t||t==="_self")&&!Zh(e)}function La(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(l=>[n,l]):[[n,r]])},[]))}function em(e,t){let n=La(e);return t&&t.forEach((r,l)=>{n.has(l)||t.getAll(l).forEach(a=>{n.append(l,a)})}),n}const tm=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],nm=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],rm="6";try{window.__reactRouterVersion=rm}catch{}const lm=v.createContext({isTransitioning:!1}),sm="startTransition",Ko=Yd[sm];function am(e){let{basename:t,children:n,future:r,window:l}=e,a=v.useRef();a.current==null&&(a.current=ih({window:l,v5Compat:!0}));let i=a.current,[o,u]=v.useState({action:i.action,location:i.location}),{v7_startTransition:f}=r||{},h=v.useCallback(p=>{f&&Ko?Ko(()=>u(p)):u(p)},[u,f]);return v.useLayoutEffect(()=>i.listen(h),[i,h]),v.useEffect(()=>Yh(r),[r]),v.createElement(Gh,{basename:t,children:n,location:o.location,navigationType:o.action,navigator:i,future:r})}const im=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",om=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Pr=v.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:a,replace:i,state:o,target:u,to:f,preventScrollReset:h,viewTransition:p}=t,m=Sd(t,tm),{basename:N}=v.useContext(ct),g,w=!1;if(typeof f=="string"&&om.test(f)&&(g=f,im))try{let y=new URL(window.location.href),x=f.startsWith("//")?new URL(y.protocol+f):new URL(f),j=En(x.pathname,N);x.origin===y.origin&&j!=null?f=j+x.search+x.hash:w=!0}catch{}let S=Mh(f,{relative:l}),d=cm(f,{replace:i,state:o,target:u,preventScrollReset:h,relative:l,viewTransition:p});function c(y){r&&r(y),y.defaultPrevented||d(y)}return v.createElement("a",Ol({},m,{href:g||S,onClick:w||a?r:c,ref:n,target:u}))}),Ta=v.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:l=!1,className:a="",end:i=!1,style:o,to:u,viewTransition:f,children:h}=t,p=Sd(t,nm),m=ql(u,{relative:p.relative}),N=$t(),g=v.useContext(yd),{navigator:w,basename:S}=v.useContext(ct),d=g!=null&&dm(m)&&f===!0,c=w.encodeLocation?w.encodeLocation(m).pathname:m.pathname,y=N.pathname,x=g&&g.navigation&&g.navigation.location?g.navigation.location.pathname:null;l||(y=y.toLowerCase(),x=x?x.toLowerCase():null,c=c.toLowerCase()),x&&S&&(x=En(x,S)||x);const j=c!=="/"&&c.endsWith("/")?c.length-1:c.length;let k=y===c||!i&&y.startsWith(c)&&y.charAt(j)==="/",C=x!=null&&(x===c||!i&&x.startsWith(c)&&x.charAt(c.length)==="/"),_={isActive:k,isPending:C,isTransitioning:d},$=k?r:void 0,b;typeof a=="function"?b=a(_):b=[a,k?"active":null,C?"pending":null,d?"transitioning":null].filter(Boolean).join(" ");let L=typeof o=="function"?o(_):o;return v.createElement(Pr,Ol({},p,{"aria-current":$,className:b,ref:n,style:L,to:u,viewTransition:f}),typeof h=="function"?h(_):h)});var Ra;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Ra||(Ra={}));var Qo;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Qo||(Qo={}));function um(e){let t=v.useContext(Jl);return t||ee(!1),t}function cm(e,t){let{target:n,replace:r,state:l,preventScrollReset:a,relative:i,viewTransition:o}=t===void 0?{}:t,u=_r(),f=$t(),h=ql(e,{relative:i});return v.useCallback(p=>{if(qh(p,n)){p.preventDefault();let m=r!==void 0?r:Ml(f)===Ml(h);u(e,{replace:m,state:l,preventScrollReset:a,relative:i,viewTransition:o})}},[f,u,h,r,l,n,e,a,i,o])}function Cd(e){let t=v.useRef(La(e)),n=v.useRef(!1),r=$t(),l=v.useMemo(()=>em(r.search,n.current?null:t.current),[r.search]),a=_r(),i=v.useCallback((o,u)=>{const f=La(typeof o=="function"?o(l):o);n.current=!0,a("?"+f,u)},[a,l]);return[l,i]}function dm(e,t){t===void 0&&(t={});let n=v.useContext(lm);n==null&&ee(!1);let{basename:r}=um(Ra.useViewTransitionState),l=ql(e,{relative:t.relative});if(!n.isTransitioning)return!1;let a=En(n.currentLocation.pathname,r)||n.currentLocation.pathname,i=En(n.nextLocation.pathname,r)||n.nextLocation.pathname;return _a(l.pathname,i)!=null||_a(l.pathname,a)!=null}const fm=6*60*60*1e3,pm=30*1e3,hm=5*60*1e3,Yo="npm i -g nlm-memory@latest && nlm restart";function mm({collapsed:e}){const[t,n]=v.useState(null),[r,l]=v.useState(!1),[a,i]=v.useState(null),[o,u]=v.useState(!1),f=v.useRef(null),[h,p]=v.useState(()=>typeof window>"u"?null:window.localStorage.getItem("nlm.update.dismissed")??null);if(v.useEffect(()=>{let g=!1;async function w(){try{const c=await fetch("/api/update-status");if(!c.ok)return;const y=await c.json();g||n(y)}catch{}}w();const S=a!==null?pm:fm,d=window.setInterval(()=>void w(),S);return()=>{g=!0,window.clearInterval(d)}},[a]),v.useEffect(()=>{if(a===null){u(!1);return}if(t&&f.current&&t.current!==f.current){i(null),u(!1);return}const g=Date.now()-a,w=hm-g;if(w<=0){u(!0);return}const S=window.setTimeout(()=>u(!0),w);return()=>window.clearTimeout(S)},[a,t]),!t||!t.behind||!t.latest||h===t.latest)return null;async function m(){var g;try{await((g=navigator.clipboard)==null?void 0:g.writeText(Yo)),l(!0),window.setTimeout(()=>l(!1),1800),f.current=(t==null?void 0:t.current)??null,i(Date.now())}catch{l(!1)}}function N(){t!=null&&t.latest&&(window.localStorage.setItem("nlm.update.dismissed",t.latest),p(t.latest))}return e?s.jsx("button",{type:"button",className:"update-banner update-banner--collapsed",onClick:m,title:`Update available — ${t.current} → ${t.latest}. Click to copy install command.`,"aria-label":`Update ${t.latest} available — click to copy install command`,children:s.jsx("span",{className:"update-dot","aria-hidden":"true",children:"●"})}):s.jsxs("div",{className:"update-banner",role:"status","aria-live":"polite",children:[s.jsxs("div",{className:"update-banner-head",children:[s.jsxs("span",{className:"update-banner-version mono small",children:[t.current," → ",t.latest]}),s.jsx("button",{type:"button",className:"update-banner-dismiss",onClick:N,"aria-label":"Dismiss this update notice",title:"Hide until the next release",children:"×"})]}),s.jsx("p",{className:"update-banner-body small",children:"New version available on npm."}),s.jsx("div",{className:"update-banner-cmd mono small","aria-label":"Install command",children:Yo}),s.jsxs("div",{className:"update-banner-actions",children:[s.jsx("button",{type:"button",className:"update-banner-copy",onClick:m,children:r?"copied ✓":"copy command"}),s.jsx("a",{className:"update-banner-link small",href:`https://github.com/pbmagnet4/nlm-memory-ts/releases/tag/v${t.latest}`,target:"_blank",rel:"noopener noreferrer",children:"release notes"})]}),o?s.jsxs("p",{className:"update-banner-nudge small",role:"alert",children:["Daemon still on ",t.current,". The npm install swaps the binary on disk but the running daemon needs a kick — run ",s.jsx("code",{className:"mono",children:"nlm restart"}),"."]}):null]})}const Xo="nlm.sidenav.collapsed",vm=[{to:"/live",label:"Live",icon:ym()},{to:"/pulse",label:"Pulse",icon:xm()},{to:"/river",label:"River",icon:jm()},{to:"/thread",label:"Thread",icon:wm()},{to:"/search",label:"Search",icon:Nm()},{to:"/recall",label:"Recall",icon:km()},{to:"/settings",label:"Settings",icon:Sm()}];function gm(){const[e,t]=v.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Xo)==="1");return v.useEffect(()=>{document.body.style.setProperty("--sidenav-w",e?"52px":"180px"),window.localStorage.setItem(Xo,e?"1":"0")},[e]),s.jsxs("nav",{className:`sidenav${e?" collapsed":""}`,"aria-label":"Primary navigation",children:[s.jsxs("div",{className:"sidenav-header",children:[s.jsx("span",{className:"sidenav-wordmark",children:"NLM"}),s.jsx("button",{className:"sidenav-toggle","aria-label":"Toggle sidebar",onClick:()=>t(n=>!n),children:e?_m():Em()})]}),s.jsx("div",{className:"sidenav-items",children:vm.map(n=>s.jsxs(Ta,{to:n.to,className:({isActive:r})=>`sidenav-item${r?" active":""}`,"data-label":n.label,children:[s.jsx("span",{className:"item-icon",children:n.icon}),s.jsx("span",{className:"item-label",children:n.label})]},n.to))}),s.jsxs("div",{className:"sidenav-footer",children:[s.jsx(mm,{collapsed:e}),s.jsxs(Ta,{to:"/settings/data",className:"sidenav-item sidenav-data","data-label":"Data",children:[s.jsx("span",{className:"item-icon",children:Cm()}),s.jsx("span",{className:"item-label",children:"Data"})]})]})]})}function Gt(e,t=16){return s.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round",children:e})}function ym(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"12",cy:"12",r:"3"}),s.jsx("path",{d:"M19 12a7 7 0 00-14 0M22 12a10 10 0 00-20 0"})]}))}function xm(){return Gt(s.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"}))}function jm(){return Gt(s.jsx("path",{d:"M2 12c1.5-3 3-4.5 4.5-4.5S9 9 10.5 12s3 4.5 4.5 4.5S18 15 19.5 12 21 7.5 22 7.5"}))}function wm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),s.jsx("circle",{cx:"18",cy:"6",r:"3"}),s.jsx("circle",{cx:"6",cy:"18",r:"3"}),s.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]}))}function Nm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"11",cy:"11",r:"8"}),s.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}))}function km(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"13"}),s.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),s.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"9"})]}))}function Sm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),s.jsx("circle",{cx:"12",cy:"12",r:"3"})]}))}function Cm(){return s.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),s.jsx("path",{d:"M21 12c0 1.657-4.03 3-9 3S3 13.657 3 12"}),s.jsx("path",{d:"M3 5v14c0 1.657 4.03 3 9 3s9-1.343 9-3V5"})]})}function Em(){return s.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"15 18 9 12 15 6"})})}function _m(){return s.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"9 18 15 12 9 6"})})}async function Pm(e){const t=await fetch(e);if(!t.ok)throw new Error(`${e} → ${t.status}`);return t.json()}function er(e,t,n){const[r,l]=v.useState({data:n,error:null,lastUpdated:null,loading:!0});return v.useEffect(()=>{let a=!1;const i=async()=>{try{const u=await Pm(e);a||l({data:u,error:null,lastUpdated:Date.now(),loading:!1})}catch(u){a||l(f=>({...f,error:u instanceof Error?u.message:String(u),loading:!1}))}};i();const o=setInterval(i,t);return()=>{a=!0,clearInterval(o)}},[e,t]),r}function ol(e){if(!e)return"";const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Math.max(0,Math.floor((Date.now()-t)/1e3));if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const l=Math.floor(r/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function ie({w:e,h:t=12,radius:n=4,className:r}){const l={width:typeof e=="number"?`${e}px`:e??"100%",height:typeof t=="number"?`${t}px`:t,borderRadius:n};return s.jsx("span",{className:`skeleton${r?` ${r}`:""}`,style:l,"aria-hidden":"true"})}function Lm(){return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"kpi-row",children:[Array.from({length:4}).map((e,t)=>s.jsxs("div",{className:"kpi",children:[s.jsx(ie,{h:10,w:70}),s.jsx(ie,{h:28,w:90}),s.jsx(ie,{h:10,w:60})]},t)),s.jsx("div",{className:"kpi",children:s.jsx(ie,{h:56})})]}),s.jsx("div",{className:"pulse-grid",children:Array.from({length:4}).map((e,t)=>s.jsxs("section",{className:"card",children:[s.jsx("header",{className:"card-head",children:s.jsx(ie,{h:14,w:140})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"12px 0"},children:Array.from({length:5}).map((n,r)=>s.jsx(ie,{h:12,w:`${65+r*7%30}%`},r))})]},t))})]})}function Tm({rows:e=6}){return s.jsx("ul",{className:"session-list",children:Array.from({length:e}).map((t,n)=>s.jsxs("li",{className:"session-row session-row-detail",children:[s.jsx(ie,{h:18,w:56,radius:10}),s.jsxs("div",{className:"session-row-main",children:[s.jsx(ie,{h:13,w:`${50+n*11%35}%`}),s.jsx(ie,{h:11,w:`${30+n*13%50}%`})]}),s.jsx(ie,{h:10,w:48})]},n))})}function Rm({rows:e=8,cols:t=6}){return s.jsx("tbody",{children:Array.from({length:e}).map((n,r)=>s.jsx("tr",{children:Array.from({length:t}).map((l,a)=>s.jsx("td",{children:s.jsx(ie,{h:12,w:a===0?"70%":a===t-1?"60%":"50%"})},a))},r))})}function bm(){return s.jsxs("div",{className:"drawer-body",children:[s.jsx("dl",{className:"kv-list",children:Array.from({length:5}).map((e,t)=>s.jsxs("div",{style:{display:"contents"},children:[s.jsx("dt",{className:"kv-label",children:s.jsx(ie,{h:10,w:70})}),s.jsx("dd",{className:"kv-value",children:s.jsx(ie,{h:12,w:`${40+t*13%50}%`})})]},t))}),s.jsx("h4",{className:"drawer-section",children:s.jsx(ie,{h:12,w:100})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:4}).map((e,t)=>s.jsx(ie,{h:12,w:`${55+t*7%35}%`},t))})]})}const Mm=200;function Om({predecessorId:e,predecessorLabel:t,onClose:n,onMarked:r}){const[l,a]=v.useState(""),[i,o]=v.useState([]),[u,f]=v.useState(0),[h,p]=v.useState(null),[m,N]=v.useState(""),[g,w]=v.useState(!1),[S,d]=v.useState(null),c=v.useRef(null),y=v.useRef(null),x=v.useRef(null),j=v.useMemo(()=>`supersede-listbox-${Math.random().toString(36).slice(2,9)}`,[]);v.useEffect(()=>{var L;(L=c.current)==null||L.focus()},[]),v.useEffect(()=>{const L=x.current;if(!L)return;const I=P=>{if(P.key==="Escape"){P.preventDefault(),P.stopPropagation(),n();return}if(P.key!=="Tab")return;const R=Dm(L);if(R.length===0)return;const A=R[0],z=R[R.length-1],V=document.activeElement;P.shiftKey&&V===A?(P.preventDefault(),z.focus()):!P.shiftKey&&V===z&&(P.preventDefault(),A.focus())};return L.addEventListener("keydown",I),()=>L.removeEventListener("keydown",I)},[n]),v.useEffect(()=>{if(h)return;const L=l.trim();if(L.length===0){o([]);return}const I=setTimeout(async()=>{try{const P=await fetch(`/api/recall?q=${encodeURIComponent(L)}&mode=hybrid&limit=8`);if(!P.ok)throw new Error(`HTTP ${P.status}`);const A=(await P.json()).results.filter(z=>z.id!==e).map(z=>({id:z.id,label:z.label||"(unlabelled)",startedAt:z.startedAt??null,runtime:z.runtime??""}));o(A),f(0),d(null)}catch(P){d(P instanceof Error?P.message:String(P)),o([])}},Mm);return()=>clearTimeout(I)},[l,h,e]),v.useEffect(()=>{var L;h&&((L=y.current)==null||L.focus())},[h]);function k(L){if(i.length!==0){if(L.key==="ArrowDown")L.preventDefault(),f(I=>Math.min(I+1,i.length-1));else if(L.key==="ArrowUp")L.preventDefault(),f(I=>Math.max(I-1,0));else if(L.key==="Enter"){L.preventDefault();const I=i[u];I&&p(I)}}}const C=v.useCallback(L=>p(L),[]);function _(L,I){(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),C(I))}async function $(){if(!(!h||g)){w(!0),d(null);try{const L=await fetch(`/api/session/${encodeURIComponent(e)}/supersede`,{method:"POST",headers:{"content-type":"application/json","x-supersedence-source":"ui"},body:JSON.stringify({successor_id:h.id,...m.trim().length>0?{reason:m.trim()}:{}})});if(!L.ok){const I=await L.json().catch(()=>({}));throw new Error(I.error??`HTTP ${L.status}`)}r(h.id)}catch(L){d(L instanceof Error?L.message:String(L)),w(!1)}}}const b=v.useMemo(()=>t.length>60?`${t.slice(0,60)}…`:t,[t]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"palette-backdrop",onClick:n}),s.jsxs("div",{ref:x,className:"supersede-palette",role:"dialog","aria-modal":"true","aria-labelledby":"supersede-palette-title",children:[s.jsxs("header",{className:"palette-head",children:[s.jsx("span",{id:"supersede-palette-title",className:"palette-title",children:"Mark superseded"}),s.jsx("button",{type:"button",className:"drawer-close",onClick:n,"aria-label":"Close",children:"×"})]}),s.jsxs("div",{className:"palette-body",children:[s.jsxs("div",{className:"palette-context",children:[s.jsx("span",{className:"palette-context-label",children:"retiring"}),s.jsx("span",{className:"palette-context-value mono small",children:b}),s.jsx("span",{className:"palette-context-id mono small",children:e})]}),!h&&s.jsxs(s.Fragment,{children:[s.jsx("label",{className:"palette-field-label",htmlFor:"palette-search",children:"Successor — the session that replaces it"}),s.jsx("input",{id:"palette-search",ref:c,className:"palette-input mono",type:"text",role:"combobox","aria-expanded":i.length>0,"aria-controls":j,"aria-activedescendant":i.length>0?`${j}-${u}`:void 0,"aria-autocomplete":"list",placeholder:"search by label, decision, or entity",value:l,onChange:L=>a(L.target.value),onKeyDown:k,autoComplete:"off",spellCheck:!1}),s.jsxs("ul",{id:j,className:"palette-list",role:"listbox","aria-label":"Successor candidates",children:[i.length===0&&l.trim().length>0&&!S&&s.jsx("li",{className:"palette-empty muted small",role:"presentation",children:"no matches"}),i.map((L,I)=>s.jsxs("li",{id:`${j}-${I}`,role:"option",tabIndex:0,"aria-selected":I===u,className:`palette-row${I===u?" palette-row--hot":""}`,onMouseEnter:()=>f(I),onClick:()=>C(L),onKeyDown:P=>_(P,L),children:[s.jsx("span",{className:"palette-row-date mono small",children:L.startedAt?L.startedAt.slice(0,10):" - "}),s.jsx("span",{className:"palette-row-runtime mono small muted",children:L.runtime||"—"}),s.jsx("span",{className:"palette-row-label",children:L.label}),s.jsx("span",{className:"palette-row-id mono small muted",children:L.id})]},L.id))]})]}),h&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"palette-pick",children:[s.jsx("span",{className:"palette-context-label",children:"successor"}),s.jsx("span",{className:"palette-context-value mono small",children:h.label}),s.jsx("span",{className:"palette-context-id mono small",children:h.id}),s.jsx("button",{type:"button",className:"palette-undo",onClick:()=>p(null),disabled:g,children:"change"})]}),s.jsx("label",{className:"palette-field-label",htmlFor:"palette-reason",children:"Reason (optional)"}),s.jsx("input",{id:"palette-reason",ref:y,className:"palette-input mono",type:"text",placeholder:"why this supersedence — logged for audit",value:m,onChange:L=>N(L.target.value),onKeyDown:L=>{L.key==="Enter"&&$()},disabled:g,autoComplete:"off"})]}),S&&s.jsx("div",{className:"palette-error",children:S})]}),s.jsxs("footer",{className:"palette-foot",children:[s.jsx("span",{className:"palette-hint muted small",children:h?"Enter to confirm · Esc to cancel":"↑↓ to move · Enter to pick · Esc to cancel"}),s.jsx("button",{type:"button",className:"palette-confirm",disabled:!h||g,onClick:$,children:g?"marking…":"mark superseded"})]})]})]})}const $m='a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])';function Dm(e){return Array.from(e.querySelectorAll($m)).filter(n=>!n.hasAttribute("disabled")&&n.offsetParent!==null)}function Lr({sessionId:e,onClose:t,entityColor:n,onNavigate:r,prevSessionId:l,nextSessionId:a}){const[i,o]=v.useState(null),[u,f]=v.useState(null),[h,p]=v.useState(!1),[m,N]=v.useState(!1),[g,w]=v.useState(0),S=v.useRef(null);return v.useEffect(()=>{if(!h)return;const d=c=>{var y;(y=S.current)!=null&&y.contains(c.target)||p(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[h]),v.useEffect(()=>{N(!1),p(!1)},[e]),v.useEffect(()=>{o(null),f(null),fetch(`/api/session/${encodeURIComponent(e)}`).then(async d=>{if(!d.ok)throw new Error(`HTTP ${d.status}`);const c=await d.json();o({id:String(c.id??e),label:String(c.label??""),summary:String(c.summary??""),body:String(c.body??""),status:String(c.status??"closed"),startedAt:typeof c.startedAt=="string"?c.startedAt:null,endedAt:typeof c.endedAt=="string"?c.endedAt:null,durationMin:typeof c.durationMin=="number"?c.durationMin:null,runtime:String(c.runtime??""),entities:Array.isArray(c.entities)?c.entities:[],decisions:Array.isArray(c.decisions)?c.decisions:[],open:Array.isArray(c.open)?c.open:[],supersededBy:typeof c.supersededBy=="string"?c.supersededBy:null,supersedes:Array.isArray(c.supersedes)?c.supersedes:[]})}).catch(d=>f(d instanceof Error?d.message:String(d)))},[e,g]),v.useEffect(()=>{const d=c=>{if(!m){if(c.key==="Escape"){t();return}c.key==="ArrowLeft"&&l!=null&&r&&r(l),c.key==="ArrowRight"&&a!=null&&r&&r(a)}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[t,r,l,a,m]),s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"drawer-backdrop",onClick:t}),s.jsxs("aside",{className:"session-drawer",role:"dialog","aria-modal":"true",children:[s.jsxs("header",{className:"drawer-head",children:[n&&s.jsx("span",{className:"dot",style:{background:n}}),s.jsx("h3",{className:"drawer-title",children:(i==null?void 0:i.label)??e}),(l!=null||a!=null)&&r&&s.jsxs("div",{className:"drawer-nav",children:[s.jsx("button",{type:"button",className:"drawer-nav-btn",disabled:l==null,onClick:()=>l&&r(l),"aria-label":"Previous session",children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M15 18l-6-6 6-6"})})}),s.jsx("button",{type:"button",className:"drawer-nav-btn",disabled:a==null,onClick:()=>a&&r(a),"aria-label":"Next session",children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M9 18l6-6-6-6"})})})]}),s.jsxs("div",{className:"drawer-menu",ref:S,children:[s.jsx("button",{type:"button",className:"drawer-menu-trigger",onClick:()=>p(d=>!d),"aria-label":"Session actions","aria-haspopup":"menu","aria-expanded":h,disabled:!i,children:"⋯"}),h&&s.jsxs("ul",{className:"drawer-menu-list",role:"menu",children:[s.jsx("li",{role:"none",children:s.jsx("button",{type:"button",role:"menuitem",className:"drawer-menu-item",disabled:!i,onClick:()=>{p(!1),N(!0)},children:"Mark superseded by…"})}),s.jsx("li",{role:"none",children:s.jsx("button",{type:"button",role:"menuitem",className:"drawer-menu-item",onClick:()=>{var d;(d=navigator.clipboard)==null||d.writeText(e),p(!1)},children:"Copy session ID"})})]})]}),s.jsx("button",{type:"button",className:"drawer-close",onClick:t,"aria-label":"Close",children:"×"})]}),u&&s.jsx("div",{className:"muted error drawer-body",children:u}),!i&&!u&&s.jsx(bm,{}),i&&s.jsxs("div",{className:"drawer-body",children:[i.supersededBy&&s.jsxs("div",{className:"supersedence-banner supersedence-banner--superseded",children:[s.jsx("span",{className:"supersedence-label",children:"Superseded by"}),r?s.jsx("button",{type:"button",className:"supersedence-link",onClick:()=>r(i.supersededBy),children:i.supersededBy}):s.jsx("span",{className:"supersedence-id mono small",children:i.supersededBy})]}),i.supersedes.length>0&&s.jsxs("div",{className:"supersedence-banner supersedence-banner--supersedes",children:[s.jsx("span",{className:"supersedence-label",children:"Supersedes"}),s.jsx("span",{className:"supersedence-ids",children:i.supersedes.map(d=>r?s.jsx("button",{type:"button",className:"supersedence-link",onClick:()=>r(d),children:d},d):s.jsx("span",{className:"supersedence-id mono small",children:d},d))})]}),i.summary&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Summary"}),s.jsx("p",{className:"drawer-paragraph",children:i.summary})]}),i.decisions.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Decisions"}),s.jsx("ul",{className:"drawer-list",children:i.decisions.map((d,c)=>s.jsxs("li",{children:[s.jsx("span",{className:"live-tag","data-kind":"decision",children:"decision"})," ",d]},c))})]}),i.open.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Open questions"}),s.jsx("ul",{className:"drawer-list",children:i.open.map((d,c)=>s.jsxs("li",{children:[s.jsx("span",{className:"live-tag","data-kind":"open",children:"open"})," ",d]},c))})]}),i.entities.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Entities"}),s.jsx("div",{className:"entity-chips",children:i.entities.map(d=>s.jsx(Pr,{to:`/thread?entity=${encodeURIComponent(d)}`,className:"chip",onClick:t,children:d},d))})]}),s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Status"}),s.jsx("dd",{className:"kv-value",children:s.jsx("span",{className:`chip-inline status-${i.status}`,children:i.status})}),s.jsx("dt",{className:"kv-label",children:"Started"}),s.jsx("dd",{className:"kv-value mono small",children:i.startedAt??"—"}),s.jsx("dt",{className:"kv-label",children:"Duration"}),s.jsxs("dd",{className:"kv-value",children:[i.durationMin??"—"," min"]}),s.jsx("dt",{className:"kv-label",children:"Runtime"}),s.jsx("dd",{className:"kv-value mono small",children:i.runtime}),s.jsx("dt",{className:"kv-label",children:"Session ID"}),s.jsx("dd",{className:"kv-value mono small",children:i.id})]}),i.body&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Transcript excerpt"}),s.jsxs("pre",{className:"drawer-body-text",children:[i.body.slice(0,3e3),i.body.length>3e3?`
67
+ */function Ol(){return Ol=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ol.apply(this,arguments)}function Sd(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,a;for(a=0;a<r.length;a++)l=r[a],!(t.indexOf(l)>=0)&&(n[l]=e[l]);return n}function Zh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function qh(e,t){return e.button===0&&(!t||t==="_self")&&!Zh(e)}function La(e){return e===void 0&&(e=""),new URLSearchParams(typeof e=="string"||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map(l=>[n,l]):[[n,r]])},[]))}function em(e,t){let n=La(e);return t&&t.forEach((r,l)=>{n.has(l)||t.getAll(l).forEach(a=>{n.append(l,a)})}),n}const tm=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],nm=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],rm="6";try{window.__reactRouterVersion=rm}catch{}const lm=v.createContext({isTransitioning:!1}),sm="startTransition",Ko=Yd[sm];function am(e){let{basename:t,children:n,future:r,window:l}=e,a=v.useRef();a.current==null&&(a.current=ih({window:l,v5Compat:!0}));let i=a.current,[o,u]=v.useState({action:i.action,location:i.location}),{v7_startTransition:f}=r||{},h=v.useCallback(p=>{f&&Ko?Ko(()=>u(p)):u(p)},[u,f]);return v.useLayoutEffect(()=>i.listen(h),[i,h]),v.useEffect(()=>Yh(r),[r]),v.createElement(Gh,{basename:t,children:n,location:o.location,navigationType:o.action,navigator:i,future:r})}const im=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",om=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Pr=v.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:a,replace:i,state:o,target:u,to:f,preventScrollReset:h,viewTransition:p}=t,m=Sd(t,tm),{basename:N}=v.useContext(ct),g,w=!1;if(typeof f=="string"&&om.test(f)&&(g=f,im))try{let y=new URL(window.location.href),x=f.startsWith("//")?new URL(y.protocol+f):new URL(f),j=En(x.pathname,N);x.origin===y.origin&&j!=null?f=j+x.search+x.hash:w=!0}catch{}let S=Mh(f,{relative:l}),d=cm(f,{replace:i,state:o,target:u,preventScrollReset:h,relative:l,viewTransition:p});function c(y){r&&r(y),y.defaultPrevented||d(y)}return v.createElement("a",Ol({},m,{href:g||S,onClick:w||a?r:c,ref:n,target:u}))}),Ta=v.forwardRef(function(t,n){let{"aria-current":r="page",caseSensitive:l=!1,className:a="",end:i=!1,style:o,to:u,viewTransition:f,children:h}=t,p=Sd(t,nm),m=ql(u,{relative:p.relative}),N=$t(),g=v.useContext(yd),{navigator:w,basename:S}=v.useContext(ct),d=g!=null&&dm(m)&&f===!0,c=w.encodeLocation?w.encodeLocation(m).pathname:m.pathname,y=N.pathname,x=g&&g.navigation&&g.navigation.location?g.navigation.location.pathname:null;l||(y=y.toLowerCase(),x=x?x.toLowerCase():null,c=c.toLowerCase()),x&&S&&(x=En(x,S)||x);const j=c!=="/"&&c.endsWith("/")?c.length-1:c.length;let k=y===c||!i&&y.startsWith(c)&&y.charAt(j)==="/",C=x!=null&&(x===c||!i&&x.startsWith(c)&&x.charAt(c.length)==="/"),_={isActive:k,isPending:C,isTransitioning:d},$=k?r:void 0,b;typeof a=="function"?b=a(_):b=[a,k?"active":null,C?"pending":null,d?"transitioning":null].filter(Boolean).join(" ");let L=typeof o=="function"?o(_):o;return v.createElement(Pr,Ol({},p,{"aria-current":$,className:b,ref:n,style:L,to:u,viewTransition:f}),typeof h=="function"?h(_):h)});var Ra;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Ra||(Ra={}));var Qo;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Qo||(Qo={}));function um(e){let t=v.useContext(Jl);return t||ee(!1),t}function cm(e,t){let{target:n,replace:r,state:l,preventScrollReset:a,relative:i,viewTransition:o}=t===void 0?{}:t,u=_r(),f=$t(),h=ql(e,{relative:i});return v.useCallback(p=>{if(qh(p,n)){p.preventDefault();let m=r!==void 0?r:Ml(f)===Ml(h);u(e,{replace:m,state:l,preventScrollReset:a,relative:i,viewTransition:o})}},[f,u,h,r,l,n,e,a,i,o])}function Cd(e){let t=v.useRef(La(e)),n=v.useRef(!1),r=$t(),l=v.useMemo(()=>em(r.search,n.current?null:t.current),[r.search]),a=_r(),i=v.useCallback((o,u)=>{const f=La(typeof o=="function"?o(l):o);n.current=!0,a("?"+f,u)},[a,l]);return[l,i]}function dm(e,t){t===void 0&&(t={});let n=v.useContext(lm);n==null&&ee(!1);let{basename:r}=um(Ra.useViewTransitionState),l=ql(e,{relative:t.relative});if(!n.isTransitioning)return!1;let a=En(n.currentLocation.pathname,r)||n.currentLocation.pathname,i=En(n.nextLocation.pathname,r)||n.nextLocation.pathname;return _a(l.pathname,i)!=null||_a(l.pathname,a)!=null}const fm=6*60*60*1e3,pm=30*1e3,hm=5*60*1e3,Yo="nlm upgrade";function mm({collapsed:e}){const[t,n]=v.useState(null),[r,l]=v.useState(!1),[a,i]=v.useState(null),[o,u]=v.useState(!1),f=v.useRef(null),[h,p]=v.useState(()=>typeof window>"u"?null:window.localStorage.getItem("nlm.update.dismissed")??null);if(v.useEffect(()=>{let g=!1;async function w(){try{const c=await fetch("/api/update-status");if(!c.ok)return;const y=await c.json();g||n(y)}catch{}}w();const S=a!==null?pm:fm,d=window.setInterval(()=>void w(),S);return()=>{g=!0,window.clearInterval(d)}},[a]),v.useEffect(()=>{if(a===null){u(!1);return}if(t&&f.current&&t.current!==f.current){i(null),u(!1);return}const g=Date.now()-a,w=hm-g;if(w<=0){u(!0);return}const S=window.setTimeout(()=>u(!0),w);return()=>window.clearTimeout(S)},[a,t]),!t||!t.behind||!t.latest||h===t.latest)return null;async function m(){var g;try{await((g=navigator.clipboard)==null?void 0:g.writeText(Yo)),l(!0),window.setTimeout(()=>l(!1),1800),f.current=(t==null?void 0:t.current)??null,i(Date.now())}catch{l(!1)}}function N(){t!=null&&t.latest&&(window.localStorage.setItem("nlm.update.dismissed",t.latest),p(t.latest))}return e?s.jsx("button",{type:"button",className:"update-banner update-banner--collapsed",onClick:m,title:`Update available — ${t.current} → ${t.latest}. Click to copy install command.`,"aria-label":`Update ${t.latest} available — click to copy install command`,children:s.jsx("span",{className:"update-dot","aria-hidden":"true",children:"●"})}):s.jsxs("div",{className:"update-banner",role:"status","aria-live":"polite",children:[s.jsxs("div",{className:"update-banner-head",children:[s.jsxs("span",{className:"update-banner-version mono small",children:[t.current," → ",t.latest]}),s.jsx("button",{type:"button",className:"update-banner-dismiss",onClick:N,"aria-label":"Dismiss this update notice",title:"Hide until the next release",children:"×"})]}),s.jsx("p",{className:"update-banner-body small",children:"New version available on npm."}),s.jsx("div",{className:"update-banner-cmd mono small","aria-label":"Install command",children:Yo}),s.jsxs("div",{className:"update-banner-actions",children:[s.jsx("button",{type:"button",className:"update-banner-copy",onClick:m,children:r?"copied ✓":"copy command"}),s.jsx("a",{className:"update-banner-link small",href:`https://github.com/pbmagnet4/nlm-memory-ts/releases/tag/v${t.latest}`,target:"_blank",rel:"noopener noreferrer",children:"release notes"})]}),o?s.jsxs("p",{className:"update-banner-nudge small",role:"alert",children:["Daemon still on ",t.current,". The npm install swaps the binary on disk but the running daemon needs a kick — run ",s.jsx("code",{className:"mono",children:"nlm restart"}),"."]}):null]})}const Xo="nlm.sidenav.collapsed",vm=[{to:"/live",label:"Live",icon:ym()},{to:"/pulse",label:"Pulse",icon:xm()},{to:"/river",label:"River",icon:jm()},{to:"/thread",label:"Thread",icon:wm()},{to:"/search",label:"Search",icon:Nm()},{to:"/recall",label:"Recall",icon:km()},{to:"/settings",label:"Settings",icon:Sm()}];function gm(){const[e,t]=v.useState(()=>typeof window>"u"?!1:window.localStorage.getItem(Xo)==="1");return v.useEffect(()=>{document.body.style.setProperty("--sidenav-w",e?"52px":"180px"),window.localStorage.setItem(Xo,e?"1":"0")},[e]),s.jsxs("nav",{className:`sidenav${e?" collapsed":""}`,"aria-label":"Primary navigation",children:[s.jsxs("div",{className:"sidenav-header",children:[s.jsx("span",{className:"sidenav-wordmark",children:"NLM"}),s.jsx("button",{className:"sidenav-toggle","aria-label":"Toggle sidebar",onClick:()=>t(n=>!n),children:e?_m():Em()})]}),s.jsx("div",{className:"sidenav-items",children:vm.map(n=>s.jsxs(Ta,{to:n.to,className:({isActive:r})=>`sidenav-item${r?" active":""}`,"data-label":n.label,children:[s.jsx("span",{className:"item-icon",children:n.icon}),s.jsx("span",{className:"item-label",children:n.label})]},n.to))}),s.jsxs("div",{className:"sidenav-footer",children:[s.jsx(mm,{collapsed:e}),s.jsxs(Ta,{to:"/settings/data",className:"sidenav-item sidenav-data","data-label":"Data",children:[s.jsx("span",{className:"item-icon",children:Cm()}),s.jsx("span",{className:"item-label",children:"Data"})]})]})]})}function Gt(e,t=16){return s.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round",children:e})}function ym(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"12",cy:"12",r:"3"}),s.jsx("path",{d:"M19 12a7 7 0 00-14 0M22 12a10 10 0 00-20 0"})]}))}function xm(){return Gt(s.jsx("polyline",{points:"22 12 18 12 15 21 9 3 6 12 2 12"}))}function jm(){return Gt(s.jsx("path",{d:"M2 12c1.5-3 3-4.5 4.5-4.5S9 9 10.5 12s3 4.5 4.5 4.5S18 15 19.5 12 21 7.5 22 7.5"}))}function wm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),s.jsx("circle",{cx:"18",cy:"6",r:"3"}),s.jsx("circle",{cx:"6",cy:"18",r:"3"}),s.jsx("path",{d:"M18 9a9 9 0 01-9 9"})]}))}function Nm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("circle",{cx:"11",cy:"11",r:"8"}),s.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}))}function km(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"13"}),s.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),s.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"9"})]}))}function Sm(){return Gt(s.jsxs(s.Fragment,{children:[s.jsx("path",{d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),s.jsx("circle",{cx:"12",cy:"12",r:"3"})]}))}function Cm(){return s.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),s.jsx("path",{d:"M21 12c0 1.657-4.03 3-9 3S3 13.657 3 12"}),s.jsx("path",{d:"M3 5v14c0 1.657 4.03 3 9 3s9-1.343 9-3V5"})]})}function Em(){return s.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"15 18 9 12 15 6"})})}function _m(){return s.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"9 18 15 12 9 6"})})}async function Pm(e){const t=await fetch(e);if(!t.ok)throw new Error(`${e} → ${t.status}`);return t.json()}function er(e,t,n){const[r,l]=v.useState({data:n,error:null,lastUpdated:null,loading:!0});return v.useEffect(()=>{let a=!1;const i=async()=>{try{const u=await Pm(e);a||l({data:u,error:null,lastUpdated:Date.now(),loading:!1})}catch(u){a||l(f=>({...f,error:u instanceof Error?u.message:String(u),loading:!1}))}};i();const o=setInterval(i,t);return()=>{a=!0,clearInterval(o)}},[e,t]),r}function ol(e){if(!e)return"";const t=Date.parse(e);if(!Number.isFinite(t))return"";const n=Math.max(0,Math.floor((Date.now()-t)/1e3));if(n<60)return`${n}s ago`;const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const l=Math.floor(r/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function ie({w:e,h:t=12,radius:n=4,className:r}){const l={width:typeof e=="number"?`${e}px`:e??"100%",height:typeof t=="number"?`${t}px`:t,borderRadius:n};return s.jsx("span",{className:`skeleton${r?` ${r}`:""}`,style:l,"aria-hidden":"true"})}function Lm(){return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"kpi-row",children:[Array.from({length:4}).map((e,t)=>s.jsxs("div",{className:"kpi",children:[s.jsx(ie,{h:10,w:70}),s.jsx(ie,{h:28,w:90}),s.jsx(ie,{h:10,w:60})]},t)),s.jsx("div",{className:"kpi",children:s.jsx(ie,{h:56})})]}),s.jsx("div",{className:"pulse-grid",children:Array.from({length:4}).map((e,t)=>s.jsxs("section",{className:"card",children:[s.jsx("header",{className:"card-head",children:s.jsx(ie,{h:14,w:140})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"12px 0"},children:Array.from({length:5}).map((n,r)=>s.jsx(ie,{h:12,w:`${65+r*7%30}%`},r))})]},t))})]})}function Tm({rows:e=6}){return s.jsx("ul",{className:"session-list",children:Array.from({length:e}).map((t,n)=>s.jsxs("li",{className:"session-row session-row-detail",children:[s.jsx(ie,{h:18,w:56,radius:10}),s.jsxs("div",{className:"session-row-main",children:[s.jsx(ie,{h:13,w:`${50+n*11%35}%`}),s.jsx(ie,{h:11,w:`${30+n*13%50}%`})]}),s.jsx(ie,{h:10,w:48})]},n))})}function Rm({rows:e=8,cols:t=6}){return s.jsx("tbody",{children:Array.from({length:e}).map((n,r)=>s.jsx("tr",{children:Array.from({length:t}).map((l,a)=>s.jsx("td",{children:s.jsx(ie,{h:12,w:a===0?"70%":a===t-1?"60%":"50%"})},a))},r))})}function bm(){return s.jsxs("div",{className:"drawer-body",children:[s.jsx("dl",{className:"kv-list",children:Array.from({length:5}).map((e,t)=>s.jsxs("div",{style:{display:"contents"},children:[s.jsx("dt",{className:"kv-label",children:s.jsx(ie,{h:10,w:70})}),s.jsx("dd",{className:"kv-value",children:s.jsx(ie,{h:12,w:`${40+t*13%50}%`})})]},t))}),s.jsx("h4",{className:"drawer-section",children:s.jsx(ie,{h:12,w:100})}),s.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:4}).map((e,t)=>s.jsx(ie,{h:12,w:`${55+t*7%35}%`},t))})]})}const Mm=200;function Om({predecessorId:e,predecessorLabel:t,onClose:n,onMarked:r}){const[l,a]=v.useState(""),[i,o]=v.useState([]),[u,f]=v.useState(0),[h,p]=v.useState(null),[m,N]=v.useState(""),[g,w]=v.useState(!1),[S,d]=v.useState(null),c=v.useRef(null),y=v.useRef(null),x=v.useRef(null),j=v.useMemo(()=>`supersede-listbox-${Math.random().toString(36).slice(2,9)}`,[]);v.useEffect(()=>{var L;(L=c.current)==null||L.focus()},[]),v.useEffect(()=>{const L=x.current;if(!L)return;const I=P=>{if(P.key==="Escape"){P.preventDefault(),P.stopPropagation(),n();return}if(P.key!=="Tab")return;const R=Dm(L);if(R.length===0)return;const A=R[0],z=R[R.length-1],V=document.activeElement;P.shiftKey&&V===A?(P.preventDefault(),z.focus()):!P.shiftKey&&V===z&&(P.preventDefault(),A.focus())};return L.addEventListener("keydown",I),()=>L.removeEventListener("keydown",I)},[n]),v.useEffect(()=>{if(h)return;const L=l.trim();if(L.length===0){o([]);return}const I=setTimeout(async()=>{try{const P=await fetch(`/api/recall?q=${encodeURIComponent(L)}&mode=hybrid&limit=8`);if(!P.ok)throw new Error(`HTTP ${P.status}`);const A=(await P.json()).results.filter(z=>z.id!==e).map(z=>({id:z.id,label:z.label||"(unlabelled)",startedAt:z.startedAt??null,runtime:z.runtime??""}));o(A),f(0),d(null)}catch(P){d(P instanceof Error?P.message:String(P)),o([])}},Mm);return()=>clearTimeout(I)},[l,h,e]),v.useEffect(()=>{var L;h&&((L=y.current)==null||L.focus())},[h]);function k(L){if(i.length!==0){if(L.key==="ArrowDown")L.preventDefault(),f(I=>Math.min(I+1,i.length-1));else if(L.key==="ArrowUp")L.preventDefault(),f(I=>Math.max(I-1,0));else if(L.key==="Enter"){L.preventDefault();const I=i[u];I&&p(I)}}}const C=v.useCallback(L=>p(L),[]);function _(L,I){(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),C(I))}async function $(){if(!(!h||g)){w(!0),d(null);try{const L=await fetch(`/api/session/${encodeURIComponent(e)}/supersede`,{method:"POST",headers:{"content-type":"application/json","x-supersedence-source":"ui"},body:JSON.stringify({successor_id:h.id,...m.trim().length>0?{reason:m.trim()}:{}})});if(!L.ok){const I=await L.json().catch(()=>({}));throw new Error(I.error??`HTTP ${L.status}`)}r(h.id)}catch(L){d(L instanceof Error?L.message:String(L)),w(!1)}}}const b=v.useMemo(()=>t.length>60?`${t.slice(0,60)}…`:t,[t]);return s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"palette-backdrop",onClick:n}),s.jsxs("div",{ref:x,className:"supersede-palette",role:"dialog","aria-modal":"true","aria-labelledby":"supersede-palette-title",children:[s.jsxs("header",{className:"palette-head",children:[s.jsx("span",{id:"supersede-palette-title",className:"palette-title",children:"Mark superseded"}),s.jsx("button",{type:"button",className:"drawer-close",onClick:n,"aria-label":"Close",children:"×"})]}),s.jsxs("div",{className:"palette-body",children:[s.jsxs("div",{className:"palette-context",children:[s.jsx("span",{className:"palette-context-label",children:"retiring"}),s.jsx("span",{className:"palette-context-value mono small",children:b}),s.jsx("span",{className:"palette-context-id mono small",children:e})]}),!h&&s.jsxs(s.Fragment,{children:[s.jsx("label",{className:"palette-field-label",htmlFor:"palette-search",children:"Successor — the session that replaces it"}),s.jsx("input",{id:"palette-search",ref:c,className:"palette-input mono",type:"text",role:"combobox","aria-expanded":i.length>0,"aria-controls":j,"aria-activedescendant":i.length>0?`${j}-${u}`:void 0,"aria-autocomplete":"list",placeholder:"search by label, decision, or entity",value:l,onChange:L=>a(L.target.value),onKeyDown:k,autoComplete:"off",spellCheck:!1}),s.jsxs("ul",{id:j,className:"palette-list",role:"listbox","aria-label":"Successor candidates",children:[i.length===0&&l.trim().length>0&&!S&&s.jsx("li",{className:"palette-empty muted small",role:"presentation",children:"no matches"}),i.map((L,I)=>s.jsxs("li",{id:`${j}-${I}`,role:"option",tabIndex:0,"aria-selected":I===u,className:`palette-row${I===u?" palette-row--hot":""}`,onMouseEnter:()=>f(I),onClick:()=>C(L),onKeyDown:P=>_(P,L),children:[s.jsx("span",{className:"palette-row-date mono small",children:L.startedAt?L.startedAt.slice(0,10):" - "}),s.jsx("span",{className:"palette-row-runtime mono small muted",children:L.runtime||"—"}),s.jsx("span",{className:"palette-row-label",children:L.label}),s.jsx("span",{className:"palette-row-id mono small muted",children:L.id})]},L.id))]})]}),h&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"palette-pick",children:[s.jsx("span",{className:"palette-context-label",children:"successor"}),s.jsx("span",{className:"palette-context-value mono small",children:h.label}),s.jsx("span",{className:"palette-context-id mono small",children:h.id}),s.jsx("button",{type:"button",className:"palette-undo",onClick:()=>p(null),disabled:g,children:"change"})]}),s.jsx("label",{className:"palette-field-label",htmlFor:"palette-reason",children:"Reason (optional)"}),s.jsx("input",{id:"palette-reason",ref:y,className:"palette-input mono",type:"text",placeholder:"why this supersedence — logged for audit",value:m,onChange:L=>N(L.target.value),onKeyDown:L=>{L.key==="Enter"&&$()},disabled:g,autoComplete:"off"})]}),S&&s.jsx("div",{className:"palette-error",children:S})]}),s.jsxs("footer",{className:"palette-foot",children:[s.jsx("span",{className:"palette-hint muted small",children:h?"Enter to confirm · Esc to cancel":"↑↓ to move · Enter to pick · Esc to cancel"}),s.jsx("button",{type:"button",className:"palette-confirm",disabled:!h||g,onClick:$,children:g?"marking…":"mark superseded"})]})]})]})}const $m='a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])';function Dm(e){return Array.from(e.querySelectorAll($m)).filter(n=>!n.hasAttribute("disabled")&&n.offsetParent!==null)}function Lr({sessionId:e,onClose:t,entityColor:n,onNavigate:r,prevSessionId:l,nextSessionId:a}){const[i,o]=v.useState(null),[u,f]=v.useState(null),[h,p]=v.useState(!1),[m,N]=v.useState(!1),[g,w]=v.useState(0),S=v.useRef(null);return v.useEffect(()=>{if(!h)return;const d=c=>{var y;(y=S.current)!=null&&y.contains(c.target)||p(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[h]),v.useEffect(()=>{N(!1),p(!1)},[e]),v.useEffect(()=>{o(null),f(null),fetch(`/api/session/${encodeURIComponent(e)}`).then(async d=>{if(!d.ok)throw new Error(`HTTP ${d.status}`);const c=await d.json();o({id:String(c.id??e),label:String(c.label??""),summary:String(c.summary??""),body:String(c.body??""),status:String(c.status??"closed"),startedAt:typeof c.startedAt=="string"?c.startedAt:null,endedAt:typeof c.endedAt=="string"?c.endedAt:null,durationMin:typeof c.durationMin=="number"?c.durationMin:null,runtime:String(c.runtime??""),entities:Array.isArray(c.entities)?c.entities:[],decisions:Array.isArray(c.decisions)?c.decisions:[],open:Array.isArray(c.open)?c.open:[],supersededBy:typeof c.supersededBy=="string"?c.supersededBy:null,supersedes:Array.isArray(c.supersedes)?c.supersedes:[]})}).catch(d=>f(d instanceof Error?d.message:String(d)))},[e,g]),v.useEffect(()=>{const d=c=>{if(!m){if(c.key==="Escape"){t();return}c.key==="ArrowLeft"&&l!=null&&r&&r(l),c.key==="ArrowRight"&&a!=null&&r&&r(a)}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[t,r,l,a,m]),s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"drawer-backdrop",onClick:t}),s.jsxs("aside",{className:"session-drawer",role:"dialog","aria-modal":"true",children:[s.jsxs("header",{className:"drawer-head",children:[n&&s.jsx("span",{className:"dot",style:{background:n}}),s.jsx("h3",{className:"drawer-title",children:(i==null?void 0:i.label)??e}),(l!=null||a!=null)&&r&&s.jsxs("div",{className:"drawer-nav",children:[s.jsx("button",{type:"button",className:"drawer-nav-btn",disabled:l==null,onClick:()=>l&&r(l),"aria-label":"Previous session",children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M15 18l-6-6 6-6"})})}),s.jsx("button",{type:"button",className:"drawer-nav-btn",disabled:a==null,onClick:()=>a&&r(a),"aria-label":"Next session",children:s.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M9 18l6-6-6-6"})})})]}),s.jsxs("div",{className:"drawer-menu",ref:S,children:[s.jsx("button",{type:"button",className:"drawer-menu-trigger",onClick:()=>p(d=>!d),"aria-label":"Session actions","aria-haspopup":"menu","aria-expanded":h,disabled:!i,children:"⋯"}),h&&s.jsxs("ul",{className:"drawer-menu-list",role:"menu",children:[s.jsx("li",{role:"none",children:s.jsx("button",{type:"button",role:"menuitem",className:"drawer-menu-item",disabled:!i,onClick:()=>{p(!1),N(!0)},children:"Mark superseded by…"})}),s.jsx("li",{role:"none",children:s.jsx("button",{type:"button",role:"menuitem",className:"drawer-menu-item",onClick:()=>{var d;(d=navigator.clipboard)==null||d.writeText(e),p(!1)},children:"Copy session ID"})})]})]}),s.jsx("button",{type:"button",className:"drawer-close",onClick:t,"aria-label":"Close",children:"×"})]}),u&&s.jsx("div",{className:"muted error drawer-body",children:u}),!i&&!u&&s.jsx(bm,{}),i&&s.jsxs("div",{className:"drawer-body",children:[i.supersededBy&&s.jsxs("div",{className:"supersedence-banner supersedence-banner--superseded",children:[s.jsx("span",{className:"supersedence-label",children:"Superseded by"}),r?s.jsx("button",{type:"button",className:"supersedence-link",onClick:()=>r(i.supersededBy),children:i.supersededBy}):s.jsx("span",{className:"supersedence-id mono small",children:i.supersededBy})]}),i.supersedes.length>0&&s.jsxs("div",{className:"supersedence-banner supersedence-banner--supersedes",children:[s.jsx("span",{className:"supersedence-label",children:"Supersedes"}),s.jsx("span",{className:"supersedence-ids",children:i.supersedes.map(d=>r?s.jsx("button",{type:"button",className:"supersedence-link",onClick:()=>r(d),children:d},d):s.jsx("span",{className:"supersedence-id mono small",children:d},d))})]}),i.summary&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Summary"}),s.jsx("p",{className:"drawer-paragraph",children:i.summary})]}),i.decisions.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Decisions"}),s.jsx("ul",{className:"drawer-list",children:i.decisions.map((d,c)=>s.jsxs("li",{children:[s.jsx("span",{className:"live-tag","data-kind":"decision",children:"decision"})," ",d]},c))})]}),i.open.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Open questions"}),s.jsx("ul",{className:"drawer-list",children:i.open.map((d,c)=>s.jsxs("li",{children:[s.jsx("span",{className:"live-tag","data-kind":"open",children:"open"})," ",d]},c))})]}),i.entities.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Entities"}),s.jsx("div",{className:"entity-chips",children:i.entities.map(d=>s.jsx(Pr,{to:`/thread?entity=${encodeURIComponent(d)}`,className:"chip",onClick:t,children:d},d))})]}),s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Status"}),s.jsx("dd",{className:"kv-value",children:s.jsx("span",{className:`chip-inline status-${i.status}`,children:i.status})}),s.jsx("dt",{className:"kv-label",children:"Started"}),s.jsx("dd",{className:"kv-value mono small",children:i.startedAt??"—"}),s.jsx("dt",{className:"kv-label",children:"Duration"}),s.jsxs("dd",{className:"kv-value",children:[i.durationMin??"—"," min"]}),s.jsx("dt",{className:"kv-label",children:"Runtime"}),s.jsx("dd",{className:"kv-value mono small",children:i.runtime}),s.jsx("dt",{className:"kv-label",children:"Session ID"}),s.jsx("dd",{className:"kv-value mono small",children:i.id})]}),i.body&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"drawer-section",children:"Transcript excerpt"}),s.jsxs("pre",{className:"drawer-body-text",children:[i.body.slice(0,3e3),i.body.length>3e3?`
68
68
 
69
69
  […truncated]`:""]})]})]})]}),m&&i&&s.jsx(Om,{predecessorId:i.id,predecessorLabel:i.label||i.id,onClose:()=>N(!1),onMarked:d=>{N(!1),o(c=>c&&{...c,status:"superseded",supersededBy:d}),w(c=>c+1)}})]})}const tr=3e3,zm=tr*3;function Ps(e){const t=v.useRef(null),[n,r]=v.useState(new Set),l=e.join("|");return v.useEffect(()=>{if(e.length===0)return;if(t.current===null){t.current=new Set(e);return}const a=e.filter(o=>!t.current.has(o));for(const o of e)t.current.add(o);if(a.length===0)return;r(o=>new Set([...o,...a]));const i=setTimeout(()=>{r(o=>{const u=new Set(o);for(const f of a)u.delete(f);return u})},1200);return()=>clearTimeout(i)},[l]),n}function Im(){const e=er("/api/recall/recent?limit=50",tr,{entries:[]}),t=er("/api/live/recent-writes?limit=50",tr,{writes:[]}),n=er("/api/live/recent-markers?limit=50",tr,{markers:[]}),[r,l]=v.useState(null),a=e.data.entries.map(p=>`${p.ts}|${p.source}|${p.query??""}`),i=t.data.writes.map(p=>p.id),o=n.data.markers.map(p=>`${p.sessionId}|${p.kind}|${p.text}`),u=Ps(a),f=Ps(i),h=Ps(o);return s.jsxs("div",{className:"live-page",children:[s.jsx(Fm,{reads:e,writes:t,markers:n}),s.jsxs("div",{className:"live-board",children:[s.jsx(Ls,{title:"Reads",count:e.data.entries.length,loading:e.loading,emptyLabel:"no recent recall",children:e.data.entries.map((p,m)=>{const N=a[m];return s.jsxs("div",{className:`live-row${u.has(N)?" is-new":""}`,children:[s.jsx("span",{className:"live-tag",children:p.source}),s.jsx("span",{className:"label",children:p.query??"(no query)"}),s.jsxs("div",{className:"body",children:[p.mode," · ",p.nResults," hit",p.nResults===1?"":"s"]}),s.jsx("div",{className:"meta",children:ol(p.ts)})]},N)})}),s.jsx(Ls,{title:"Writes",count:t.data.writes.length,loading:t.loading,emptyLabel:"no recent writes",children:t.data.writes.map(p=>s.jsxs(Go,{fresh:f.has(p.id),onOpen:()=>l(p.id),children:[s.jsx("span",{className:"live-tag",children:p.runtime.split("/")[0]}),s.jsx("span",{className:"label",children:p.label}),s.jsx("div",{className:"body",children:p.summary}),s.jsxs("div",{className:"meta",children:[ol(p.createdAt)," · ",p.id]})]},p.id))}),s.jsx(Ls,{title:"Markers",count:n.data.markers.length,loading:n.loading,emptyLabel:"no recent markers",children:n.data.markers.map((p,m)=>{const N=o[m];return s.jsxs(Go,{fresh:h.has(N),onOpen:()=>l(p.sessionId),children:[s.jsx("span",{className:"live-tag","data-kind":p.kind,children:p.kind}),s.jsx("span",{className:"label",children:p.text}),s.jsx("div",{className:"body",children:p.label}),s.jsx("div",{className:"meta",children:ol(p.createdAt)})]},N)})})]}),r&&s.jsx(Lr,{sessionId:r,onClose:()=>l(null)})]})}function Fm({reads:e,writes:t,markers:n}){const r=[e,t,n],l=r.every(p=>p.loading),a=r.map(p=>p.lastUpdated).filter(p=>p!==null),i=a.length>0?Math.max(...a):null,o=r.some(p=>p.error!==null),u=i!==null&&Date.now()-i>zm;let f;l?f="connecting":u||o?f="reconnecting":f="live";const h=f==="connecting"?"Connecting…":f==="reconnecting"?"Reconnecting…":"Live";return s.jsxs("div",{className:"live-status",children:[s.jsx("span",{className:`live-status-dot live-status-${f}`,"aria-hidden":"true"}),s.jsx("span",{className:"live-status-label",children:h}),i!==null&&s.jsxs("span",{className:"muted small",children:["updated ",ol(new Date(i).toISOString())]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small mono",children:["polling every ",tr/1e3,"s"]})]})}function Ls({title:e,count:t,loading:n,emptyLabel:r,children:l}){const a=t===0;return s.jsxs("section",{className:"live-col",children:[s.jsxs("header",{className:"live-col-head",children:[s.jsx("span",{className:"live-col-title",children:e}),s.jsx("span",{className:"live-col-count",children:t})]}),s.jsx("div",{className:"live-col-body",children:a?s.jsx("div",{className:"live-empty",children:n?"loading…":r}):l})]})}function Go({fresh:e,onOpen:t,children:n}){return s.jsx("div",{className:`live-row clickable${e?" is-new":""}`,onClick:t,role:"button",tabIndex:0,onKeyDown:r=>{(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),t())},children:n})}function bn(e){const[t,n]=v.useState({data:null,loading:!0,error:null}),r=v.useRef(!1),l=v.useCallback(async()=>{try{const a=await fetch("/api/dataset");if(!a.ok)throw new Error(`HTTP ${a.status}`);const i=await a.json();r.current||n({data:i,loading:!1,error:null})}catch(a){if(!r.current){const i=a instanceof Error?a.message:String(a);n(o=>({data:o.data,loading:!1,error:i}))}}},[]);return v.useEffect(()=>(r.current=!1,l(),()=>{r.current=!0}),[e,l]),{...t,refetch:l}}function qe(e){if(!e)return"—";const t=Date.parse(e);if(!Number.isFinite(t))return"—";const n=Math.floor((Date.now()-t)/864e5);if(n<=0)return"today";if(n===1)return"1d";if(n<30)return`${n}d`;const r=Math.floor(n/30);return r<12?`${r}mo`:`${Math.floor(n/365)}y`}async function yn(e){const t=await fetch("/api/action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...e,runtime:e.runtime??"web-ui"})});if(!t.ok)throw new Error(`POST /api/action → ${t.status}`);return(await t.json()).id}function Ed({openId:e,defaultText:t,onPromoted:n}){const[r,l]=v.useState(!1),[a,i]=v.useState(!1),[o,u]=v.useState(t),f=async()=>{const h=o.trim();if(h){i(!0);try{await yn({kind:"promote_open",subject_type:"open_question",subject_id:e,payload:{resolution:h,original_text:t}}),await n(),l(!1)}catch{i(!1)}}};return r?s.jsxs("div",{className:"promote-editor",onClick:h=>h.stopPropagation(),children:[s.jsx("input",{className:"form-input form-input-inline promote-input",value:o,onChange:h=>u(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),f()),h.key==="Escape"&&(h.preventDefault(),l(!1))},disabled:a,autoFocus:!0}),s.jsx("button",{type:"button",className:"chip",onClick:()=>void f(),disabled:a||!o.trim(),children:"save"}),s.jsx("button",{type:"button",className:"chip",onClick:()=>l(!1),disabled:a,children:"cancel"})]}):s.jsx("button",{type:"button",className:"chip promote-chip",onClick:()=>{u(t),l(!0)},children:"→ decision"})}function Am(){const{data:e,loading:t,error:n,refetch:r}=bn(),[l,a]=v.useState("all"),[i,o]=v.useState("oldest"),[u,f]=v.useState(null),[h,p]=v.useState(null),m=v.useMemo(()=>e?[...l==="all"?e.alerts:e.alerts.filter(c=>c.severity===l)].sort((c,y)=>i==="oldest"?y.age_days-c.age_days:c.age_days-y.age_days):[],[e,l,i]),N=async d=>{await yn({kind:"dismiss",subject_type:"alert",subject_id:d}),await r()},g=async(d,c)=>{const y=new Date(Date.now()+c*864e5).toISOString();await yn({kind:"snooze",subject_type:"alert",subject_id:d,payload:{snoozed_until:y}}),await r()},w=v.useMemo(()=>e?[...e.sessions].sort((d,c)=>(c.started_at??"").localeCompare(d.started_at??"")).slice(0,20):[],[e]);if(t&&!e)return s.jsx(Lm,{});if(n&&!e)return s.jsx("div",{className:"page-pad",children:s.jsx("div",{className:"muted error",children:n})});if(!e)return null;const S=u?e.alerts.find(d=>d.id===u)??null:null;return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"kpi-row",children:[s.jsx(Yr,{label:"This week",value:e.metrics.this_week,hint:`${e.metrics.last_week} last week`}),s.jsx(Yr,{label:"Sessions",value:e.meta.sessions_total,hint:"total"}),s.jsx(Yr,{label:"Entities",value:e.meta.entities_total,hint:"catalogued"}),s.jsx(Yr,{label:"Decisions",value:e.metrics.closed_decisions,hint:"non-superseded"}),s.jsx(Wm,{values:e.metrics.sparkline})]}),s.jsxs("div",{className:"pulse-grid",children:[s.jsxs("section",{className:"card pulse-area-coherence",children:[s.jsx("header",{className:"card-head",children:s.jsx("h3",{children:"Coherence"})}),s.jsx(Vm,{metrics:e.metrics})]}),s.jsxs("section",{className:"card pulse-area-runtimes",children:[s.jsx("header",{className:"card-head",children:s.jsx("h3",{children:"Runtimes"})}),s.jsx(Hm,{runtimes:e.runtimes})]}),s.jsxs("section",{className:"card pulse-scroll-card pulse-area-recent",children:[s.jsx("header",{className:"card-head",children:s.jsx("h3",{children:"Recent sessions"})}),s.jsx("div",{className:"pulse-scroll-body",children:s.jsx("ul",{className:"session-list",children:w.map(d=>s.jsxs("li",{className:"session-row clickable",onClick:()=>p(d.id),role:"button",tabIndex:0,onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),p(d.id))},children:[s.jsx("span",{className:`chip-inline status-${d.status}`,children:d.status}),s.jsx("span",{className:"session-label",children:d.label}),s.jsxs("span",{className:"session-meta",children:[qe(d.started_at)," · ",d.entities.slice(0,3).join(", "),d.entities.length>3?` +${d.entities.length-3}`:""]})]},d.id))})})]}),s.jsxs("section",{className:"card pulse-scroll-card pulse-area-stale",children:[s.jsxs("header",{className:"card-head card-head-stack",children:[s.jsxs("div",{className:"card-head-row",children:[s.jsx("h3",{children:"Stale alerts"}),s.jsxs("span",{className:"muted small",children:[m.length,m.length!==e.alerts.length?` / ${e.alerts.length}`:""]})]}),s.jsxs("div",{className:"card-filters",children:[s.jsx("div",{className:"filter-group",role:"group","aria-label":"Severity",children:["all","high","medium"].map(d=>s.jsx("button",{type:"button",className:`chip${l===d?" active":""}`,"data-severity":d==="all"?void 0:d,onClick:()=>a(d),children:d},d))}),s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Sort",children:[s.jsx("button",{type:"button",className:`chip${i==="oldest"?" active":""}`,onClick:()=>o("oldest"),children:"oldest"}),s.jsx("button",{type:"button",className:`chip${i==="recent"?" active":""}`,onClick:()=>o("recent"),children:"recent"})]})]})]}),s.jsx("div",{className:"pulse-scroll-body",children:s.jsxs("ul",{className:"alert-list",children:[m.map(d=>s.jsxs("li",{className:"alert-row clickable",onClick:()=>f(d.id),role:"button",tabIndex:0,onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),f(d.id))},children:[s.jsx("span",{className:`chip-inline severity-${d.severity}`,children:d.severity}),s.jsx("span",{className:"alert-entity",children:d.entity}),s.jsx("span",{className:"alert-summary",children:d.summary}),s.jsxs("div",{className:"alert-actions",onClick:c=>c.stopPropagation(),children:[s.jsx("button",{type:"button",className:"chip",onClick:()=>void g(d.id,7),children:"snooze 7d"}),s.jsx("button",{type:"button",className:"chip",onClick:()=>void N(d.id),children:"dismiss"})]})]},d.id)),m.length===0&&s.jsx("li",{className:"muted alert-row-empty",children:e.alerts.length===0?"No stale alerts.":"No alerts match the current filters."})]})})]})]}),S&&s.jsx(Bm,{alert:S,entity:e.entities.find(d=>d.canonical===S.entity)??null,entityColor:e.entity_colors[S.entity]??"#666",sessions:e.sessions,onClose:()=>f(null),onDismiss:async()=>{await N(S.id),f(null)},onSnooze:async d=>{await g(S.id,d),f(null)},onPromoted:r}),h&&s.jsx(Lr,{sessionId:h,onClose:()=>p(null),entityColor:(()=>{const d=e.sessions.find(y=>y.id===h),c=d==null?void 0:d.entities[0];return c?e.entity_colors[c]:void 0})()})]})}const Um=[10,25,50];function Bm({alert:e,entity:t,entityColor:n,sessions:r,onClose:l,onDismiss:a,onSnooze:i,onPromoted:o}){const u=_r(),[f,h]=v.useState(10),[p,m]=v.useState(0),N=v.useMemo(()=>r.filter(x=>x.entities.includes(e.entity)).sort((x,j)=>(j.started_at??"").localeCompare(x.started_at??"")),[r,e.entity]);v.useEffect(()=>{m(0)},[e.id,f]);const g=Math.max(1,Math.ceil(N.length/f)),w=Math.min(p,g-1),S=w*f,d=N.slice(S,S+f),c=v.useMemo(()=>N.flatMap(x=>x.open_questions.map(j=>({id:j.id,text:j.text,sid:x.id,when:x.started_at}))),[N]),y=v.useMemo(()=>N.flatMap(x=>x.decisions.map(j=>({text:j,sid:x.id,when:x.started_at}))),[N]);return v.useEffect(()=>{const x=j=>{j.key==="Escape"&&l()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[l]),s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"drawer-backdrop",onClick:l}),s.jsxs("aside",{className:"session-drawer",role:"dialog","aria-modal":"true","aria-label":`Alert detail: ${e.entity}`,children:[s.jsxs("header",{className:"drawer-head",children:[s.jsx("span",{className:"dot lg",style:{background:n}}),s.jsx("h3",{className:"drawer-title",children:e.entity}),s.jsx("span",{className:`chip-inline severity-${e.severity}`,children:e.severity}),s.jsx("button",{type:"button",className:"drawer-close",onClick:l,"aria-label":"Close",children:"×"})]}),s.jsxs("div",{className:"drawer-body",children:[s.jsx("p",{className:"drawer-paragraph",children:e.summary}),s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Last touch"}),s.jsxs("dd",{className:"kv-value",children:[e.age_days," day",e.age_days===1?"":"s"," ago"]}),s.jsx("dt",{className:"kv-label",children:"Last session"}),s.jsx("dd",{className:"kv-value mono small",children:e.last_touch_at??"—"}),t&&s.jsxs(s.Fragment,{children:[s.jsx("dt",{className:"kv-label",children:"Entity type"}),s.jsx("dd",{className:"kv-value",children:t.type}),s.jsx("dt",{className:"kv-label",children:"Total sessions"}),s.jsx("dd",{className:"kv-value mono",children:t.session_count})]})]}),s.jsxs("div",{className:"drawer-actions",children:[s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>u(`/thread?entity=${encodeURIComponent(e.entity)}`),children:"Open thread"}),s.jsx("button",{type:"button",className:"btn",onClick:()=>void i(7),children:"Snooze 7d"}),s.jsx("button",{type:"button",className:"btn",onClick:()=>void i(30),children:"Snooze 30d"}),s.jsx("button",{type:"button",className:"btn btn-danger",onClick:()=>void a(),children:"Dismiss"})]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("h4",{className:"drawer-section",children:["Open questions (",c.length,")"]}),s.jsx("ul",{className:"drawer-list",children:c.slice(0,12).map((x,j)=>s.jsxs("li",{className:"marker-row-promotable",children:[s.jsx("span",{className:"live-tag","data-kind":"open",children:"open"}),s.jsx("span",{className:"marker-text",children:x.text}),s.jsx(Ed,{openId:x.id,defaultText:x.text,onPromoted:o}),s.jsx("span",{className:"muted small",children:qe(x.when)})]},`${x.id}-${j}`))}),c.length>12&&s.jsxs("p",{className:"muted small",children:["Showing first 12 of ",c.length,"."]})]}),y.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("h4",{className:"drawer-section",children:["Decisions (",y.length,")"]}),s.jsx("ul",{className:"drawer-list",children:y.slice(0,8).map((x,j)=>s.jsxs("li",{children:[s.jsx("span",{className:"live-tag","data-kind":"decision",children:"decision"}),s.jsx("span",{className:"marker-text",children:x.text}),s.jsx("span",{className:"muted small",children:qe(x.when)})]},`${x.sid}-${j}`))}),y.length>8&&s.jsxs("p",{className:"muted small",children:["Showing first 8 of ",y.length,"."]})]}),s.jsxs("h4",{className:"drawer-section",children:["Recent sessions (",N.length,")"]}),s.jsx("ul",{className:"session-list",children:d.map(x=>s.jsxs("li",{className:"session-row",children:[s.jsx("span",{className:`chip-inline status-${x.status}`,children:x.status}),s.jsxs("div",{className:"session-row-main",children:[s.jsx(Pr,{to:`/thread?entity=${encodeURIComponent(e.entity)}&session=${encodeURIComponent(x.id)}`,className:"session-label",children:x.label}),s.jsx("span",{className:"session-meta",children:x.summary})]}),s.jsx("span",{className:"muted small mono",children:qe(x.started_at)})]},x.id))}),N.length>0&&s.jsxs("div",{className:"pagination pagination-compact",children:[s.jsxs("div",{className:"page-size",children:[s.jsx("label",{className:"form-label",children:"Per page"}),s.jsx("select",{className:"form-input form-input-inline",value:f,onChange:x=>h(Number.parseInt(x.target.value,10)),children:Um.map(x=>s.jsx("option",{value:x,children:x},x))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[S+1,"–",Math.min(S+f,N.length)," of ",N.length]}),s.jsxs("div",{className:"page-nav",children:[s.jsx("button",{type:"button",className:"chip",disabled:w===0,onClick:()=>m(0),children:"«"}),s.jsx("button",{type:"button",className:"chip",disabled:w===0,onClick:()=>m(x=>Math.max(0,x-1)),children:"‹"}),s.jsxs("span",{className:"page-indicator mono",children:[w+1," / ",g]}),s.jsx("button",{type:"button",className:"chip",disabled:w>=g-1,onClick:()=>m(x=>Math.min(g-1,x+1)),children:"›"}),s.jsx("button",{type:"button",className:"chip",disabled:w>=g-1,onClick:()=>m(g-1),children:"»"})]})]})]})]})]})}function Yr({label:e,value:t,hint:n}){return s.jsxs("div",{className:"kpi",children:[s.jsx("span",{className:"kpi-label",children:e}),s.jsx("span",{className:"kpi-value",children:t.toLocaleString()}),n&&s.jsx("span",{className:"kpi-hint",children:n})]})}function Wm({values:e}){const t=Math.max(1,...e);return s.jsxs("div",{className:"kpi kpi-sparkline",children:[s.jsx("span",{className:"kpi-label",children:"Last 7 days"}),s.jsx("div",{className:"sparkline",children:e.map((n,r)=>s.jsx("span",{className:"spark-bar",style:{height:`${n/t*100}%`},title:`${n} sessions`},r))})]})}function Vm({metrics:e}){const t=e.healthy+e.sparse+e.stale,n=r=>t>0?r/t*100:0;return s.jsxs("div",{className:"bar-stack",children:[s.jsx(Ts,{tone:"active",label:"Healthy",value:e.healthy,pct:n(e.healthy)}),s.jsx(Ts,{tone:"warn",label:"Sparse",value:e.sparse,pct:n(e.sparse)}),s.jsx(Ts,{tone:"danger",label:"Stale",value:e.stale,pct:n(e.stale)})]})}function Hm({runtimes:e}){return e.length===0?s.jsx("div",{className:"muted small",style:{padding:"8px 12px"},children:"No runtime activity yet."}):s.jsx("ul",{className:"runtime-list",children:e.map(t=>s.jsxs("li",{className:"runtime-row",children:[s.jsx("span",{className:`runtime-dot runtime-${t.status}`,title:t.status}),s.jsx("span",{className:"runtime-name mono",children:t.name}),s.jsxs("span",{className:"runtime-counts muted small",children:[t.this_week,s.jsx("span",{className:"runtime-counts-sep",children:"·"}),s.jsxs("span",{className:"runtime-counts-prev",children:[t.last_week," prev"]})]}),s.jsx("span",{className:"muted small mono runtime-age",children:qe(t.last_session_at)})]},t.name))})}function Ts({tone:e,label:t,value:n,pct:r}){const l=Math.round(r);return s.jsxs("div",{className:"bar-item",children:[s.jsx("span",{className:"bar-label",children:t}),s.jsx("div",{className:"bar-track",title:`${n.toLocaleString()} entit${n===1?"y":"ies"} · ${l}% of total`,children:s.jsx("div",{className:`bar-fill tone-${e}`,style:{width:`${r}%`}})}),s.jsxs("span",{className:"bar-value mono",children:[n.toLocaleString(),s.jsxs("span",{className:"bar-pct muted small",children:[" · ",l,"%"]})]})]})}const _d="nlm.settings.views",xt={landing:"live",riverDensity:"comfortable",threadSort:"recent"};function es(){if(typeof window>"u")return xt;try{const e=window.localStorage.getItem(_d);return e?{...xt,...JSON.parse(e)}:xt}catch{return xt}}function Km(e){typeof window>"u"||window.localStorage.setItem(_d,JSON.stringify(e))}const Jo={"7d":7,"30d":30,"90d":90,all:null};function Qm(){const{data:e,loading:t,error:n}=bn(),[r,l]=v.useState("30d"),[a,i]=v.useState(null),[o,u]=v.useState(null),[f,h]=v.useState(null),p=_r(),[m]=v.useState(()=>es().riverDensity),N=v.useRef(null),g=v.useRef(null),[w,S]=v.useState(null),d=v.useMemo(()=>{if(!e)return null;const k=Jo[r],C=e.sessions.filter(z=>z.started_at!==null),_=Date.now(),$=k?C.filter(z=>(_-Date.parse(z.started_at))/864e5<=k):C,b=new Map,L=new Map,I=new Set;for(const z of $){const V=(z.started_at??"").slice(0,10);if(!V)continue;I.add(V);const M=z.status==="superseded";for(const D of z.entities)if(M){const F=L.get(D)??new Map;F.set(V,(F.get(V)??0)+1),L.set(D,F)}else{const F=b.get(D)??new Map;F.set(V,(F.get(V)??0)+1),b.set(D,F)}}for(const[z]of L)b.has(z)||b.set(z,new Map);const P=[...I].sort(),R=[...b.entries()].map(([z,V])=>({entity:z,total:[...V.values()].reduce((M,D)=>M+D,0),perDate:V,supersededPerDate:L.get(z)??new Map})).sort((z,V)=>V.total-z.total).slice(0,24),A=new Set($.filter(z=>z.started_at&&_-Date.parse(z.started_at)<864e5).flatMap(z=>z.entities));return{dates:P,laneRows:R,total:$.length,recentEntities:A}},[e,r]),c=(k,C)=>{if(!e)return;const _=e.sessions.filter($=>($.started_at??"").slice(0,10)===C&&$.entities.includes(k)).sort(($,b)=>(b.started_at??"").localeCompare($.started_at??""));if(_.length!==0){if(_.length===1){h(_[0].id);return}u({entity:k,date:C,sessions:_})}},y=k=>{if(!N.current)return;const C=N.current.getBoundingClientRect();g.current={startX:k.clientX,rect:C}},x=k=>{if(!g.current)return;const{startX:C,rect:_}=g.current,$=Math.min(C,k.clientX)-_.left,b=Math.max(C,k.clientX)-_.left;if(b-$<6){S(null);return}S({from:$,to:b})},j=()=>{if(!g.current||!w||!d){g.current=null,S(null);return}const k=N.current,C=k==null?void 0:k.querySelector(".river-lane-label"),_=(C==null?void 0:C.offsetWidth)??0,$=(k==null?void 0:k.offsetWidth)??0,L=Math.max(1,$-_)/d.dates.length,I=_+12,P=Math.max(0,Math.floor((w.from-I)/L)),R=Math.min(d.dates.length-1,Math.floor((w.to-I)/L));if(R<=P){g.current=null,S(null);return}const A=d.dates[P],z=d.dates[R];if(A&&z){const V=Math.max(1,Math.ceil((Date.parse(z)-Date.parse(A))/864e5));l(V<=7?"7d":V<=30?"30d":V<=90?"90d":"all")}g.current=null,S(null)};return t&&!e?s.jsxs("div",{className:"page-pad",children:[s.jsx("div",{className:"river-toolbar",children:s.jsx(ie,{h:22,w:80})}),s.jsx("div",{className:"card",style:{padding:12},children:Array.from({length:8}).map((k,C)=>s.jsxs("div",{className:"river-row",style:{marginBottom:3},children:[s.jsx(ie,{h:14,w:160}),s.jsx(ie,{h:20})]},C))})]}):n&&!e?s.jsx("div",{className:"page-pad",children:s.jsx("div",{className:"muted error",children:n})}):!e||!d?null:s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"river-toolbar",children:[s.jsx("span",{className:"page-title",children:"River"}),s.jsxs("span",{className:"muted small",children:[d.total," sessions · ",d.laneRows.length," lanes · ",d.dates.length," days"]}),s.jsx("span",{className:"header-spacer"}),Object.keys(Jo).map(k=>s.jsx("button",{type:"button",className:`ctrl-btn${k===r?" active":""}`,onClick:()=>l(k),children:k},k)),s.jsxs("div",{className:"river-legend","aria-label":"Activity scale",children:[s.jsx("span",{className:"muted small",children:"less"}),[0,1,2,3,4].map(k=>s.jsx("span",{className:`river-legend-cell tier-${k}`},k)),s.jsx("span",{className:"muted small",children:"more"})]})]}),s.jsxs("div",{className:`river-grid card river-density-${m}`,ref:N,onMouseDown:y,onMouseMove:x,onMouseUp:j,onMouseLeave:()=>{g.current=null,S(null),i(null)},style:{"--cells":d.dates.length},children:[w&&s.jsx("div",{className:"river-drag-rect",style:{left:`${w.from}px`,width:`${w.to-w.from}px`}}),s.jsxs("div",{className:"river-row river-row-dates",children:[s.jsx("div",{className:"river-lane-label river-lane-label--header","aria-hidden":"true"}),s.jsx("div",{className:"river-cells",children:(()=>{const k=d.dates.length,C=k<=60?1:k<=120?2:k<=250?7:14;return d.dates.map((_,$)=>{const L=["river-date-cell",_.slice(8,10)==="01"?"river-date-cell--month-start":""].filter(Boolean).join(" ");return s.jsx("div",{className:L,title:_,children:$%C===0?_.slice(5):""},_)})})()})]}),d.laneRows.map(({entity:k,perDate:C,supersededPerDate:_,total:$})=>{const b=d.recentEntities.has(k);return s.jsxs("div",{className:"river-row",children:[s.jsxs("button",{type:"button",className:"river-lane-label",onClick:()=>p(`/thread?entity=${encodeURIComponent(k)}`),children:[s.jsx("span",{className:`dot${b?" dot-pulse":""}`,style:{background:e.entity_colors[k]??"#666"}}),s.jsx("span",{className:"river-lane-name",children:k}),s.jsx("span",{className:"muted small",children:$})]}),s.jsx("div",{className:"river-cells",children:d.dates.map(L=>{const I=C.get(L)??0,P=_.get(L)??0,R=I>0||P>0,A=["river-cell",`tier-${Xm(I)}`,P>0?"has-corrections":""].filter(Boolean).join(" ");return s.jsx("div",{className:A,onMouseEnter:z=>i({entity:k,date:L,count:I,superseded:P,x:z.clientX,y:z.clientY}),onMouseLeave:()=>i(null),onClick:()=>R&&c(k,L),style:R?{cursor:"pointer"}:{}},L)})})]},k)})]}),d.laneRows.length===0&&s.jsx("div",{className:"muted",children:"No entities in this window."}),a&&(a.count>0||a.superseded>0)&&s.jsxs("div",{className:"river-hover",style:{left:a.x+12,top:a.y+12},children:[s.jsx("span",{className:"dot",style:{background:e.entity_colors[a.entity]??"#666"}}),s.jsx("span",{className:"river-hover-name",children:a.entity}),s.jsxs("span",{className:"muted small",children:[a.date,a.count>0&&` · ${a.count} session${a.count===1?"":"s"}`,a.superseded>0&&` · ${a.superseded} corrected`]})]}),o&&s.jsx(Ym,{state:o,entityColor:e.entity_colors[o.entity]??"#666",onClose:()=>u(null),onPick:k=>{u(null),h(k)},onOpenThread:()=>p(`/thread?entity=${encodeURIComponent(o.entity)}`)}),f&&(()=>{const k=o?o.sessions:[...e.sessions].filter(I=>I.started_at!==null).sort((I,P)=>(P.started_at??"").localeCompare(I.started_at??"")),C=k.findIndex(I=>I.id===f),_=C<k.length-1?k[C+1].id:null,$=C>0?k[C-1].id:null,b=e.sessions.find(I=>I.id===f),L=b==null?void 0:b.entities[0];return s.jsx(Lr,{sessionId:f,onClose:()=>h(null),onNavigate:h,prevSessionId:_,nextSessionId:$,entityColor:L?e.entity_colors[L]:void 0})})()]})}function Ym({state:e,entityColor:t,onClose:n,onPick:r,onOpenThread:l}){return v.useEffect(()=>{const a=i=>{i.key==="Escape"&&n()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[n]),s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"drawer-backdrop",onClick:n}),s.jsxs("aside",{className:"session-drawer",role:"dialog","aria-modal":"true","aria-label":`Sessions on ${e.date}`,children:[s.jsxs("header",{className:"drawer-head",children:[s.jsx("span",{className:"dot lg",style:{background:t}}),s.jsx("h3",{className:"drawer-title",children:e.entity}),s.jsx("span",{className:"muted small",children:e.date}),s.jsx("button",{type:"button",className:"drawer-close",onClick:n,"aria-label":"Close",children:"×"})]}),s.jsxs("div",{className:"drawer-body",children:[s.jsxs("p",{className:"muted small",children:[e.sessions.length," sessions on this day. Pick one to inspect."]}),s.jsx("div",{className:"drawer-actions",children:s.jsx("button",{type:"button",className:"btn btn-accent",onClick:l,children:"Open thread"})}),s.jsx("ul",{className:"session-list",children:e.sessions.map(a=>s.jsxs("li",{className:"session-row session-row-detail clickable",onClick:()=>r(a.id),role:"button",tabIndex:0,onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),r(a.id))},children:[s.jsx("span",{className:`chip-inline status-${a.status}`,children:a.status}),s.jsxs("div",{className:"session-row-main",children:[s.jsx("span",{className:"session-label",children:a.label}),s.jsx("span",{className:"session-meta",children:a.summary})]}),s.jsx("span",{className:"muted small mono",children:qe(a.started_at)})]},a.id))})]})]})]})}function Xm(e){return e===0?0:e===1?1:e<=3?2:e<=6?3:4}const Gm=[10,25,50,100];function Jm(e,t,n){const r=e.label.toLowerCase(),l=e.summary.toLowerCase(),a=e.decisions.join(" ").toLowerCase(),i=e.open.join(" ").toLowerCase(),o={label:0,entity:0,decision:0,open:0,summary:0};for(const m of t){r.includes(m)&&(o.label+=3);for(const N of e.entities){const g=N.toLowerCase();if(g===m){o.entity+=4;break}else if(g.includes(m)){o.entity+=2;break}}a.includes(m)&&(o.decision+=2),i.includes(m)&&(o.open+=2),l.includes(m)&&(o.summary+=1)}if(n&&(r.includes(n)||a.includes(n)||i.includes(n))){const m=Object.keys(o).reduce((N,g)=>o[N]>=o[g]?N:g);o[m]+=5}const u=Object.values(o).reduce((m,N)=>m+N,0),f=["label","entity","decision","open","summary"];let h="summary",p=-1;for(const m of f)o[m]>p&&(p=o[m],h=m);return{score:u,matchedField:h}}function Zm(e,t,n=60){const r=e.toLowerCase();let l=-1;for(const o of t){const u=r.indexOf(o);u!==-1&&(l===-1||u<l)&&(l=u)}if(l===-1)return e.slice(0,n*2);const a=Math.max(0,l-n),i=Math.min(e.length,l+n);return(a>0?"…":"")+e.slice(a,i)+(i<e.length?"…":"")}function qm(e,t){let n=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");for(const r of t)n=n.replace(new RegExp(r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"gi"),l=>`<mark>${l}</mark>`);return n}function ev(){const{data:e,loading:t,error:n}=bn(),[r,l]=Cd(),a=r.get("q")??"",[i,o]=v.useState(a),[u,f]=v.useState(r.get("entity")??""),[h,p]=v.useState("all"),[m,N]=v.useState("all"),[g,w]=v.useState("recent"),[S,d]=v.useState(25),[c,y]=v.useState(0),[x,j]=v.useState(r.get("session")),k=E=>{const U=new URLSearchParams(r);U.set("session",E),l(U),j(E)},C=()=>{const E=new URLSearchParams(r);E.delete("session"),l(E),j(null)};v.useEffect(()=>{const E=setTimeout(()=>{const U=new URLSearchParams(r);i?U.set("q",i):U.delete("q"),l(U)},200);return()=>clearTimeout(E)},[i]),v.useEffect(()=>{const E=new URLSearchParams(r);u?E.set("entity",u):E.delete("entity"),l(E)},[u]);const _=v.useMemo(()=>a.toLowerCase().split(/\s+/).filter(Boolean),[a]),$=_.join(" "),b=v.useMemo(()=>{if(!e)return[];const E=e.sessions.filter(W=>!(u&&!W.entities.includes(u)||h!=="all"&&W.runtime!==h||m!=="all"&&W.status!==m));if(_.length===0)return[...E].sort((le,xe)=>(xe.started_at??"").localeCompare(le.started_at??"")).map(le=>({session:le,score:0,matchedField:"summary"}));const U=E.map(W=>{const{score:le,matchedField:xe}=Jm(W,_,$);return{session:W,score:le,matchedField:xe}}).filter(W=>W.score>0);return g==="recent"?U.sort((W,le)=>(le.session.started_at??"").localeCompare(W.session.started_at??"")):U.sort((W,le)=>le.score-W.score),U},[e,_,$,u,h,m,g]);v.useEffect(()=>{y(0)},[b,h,m,u]);const L=Math.max(1,Math.ceil(b.length/S)),I=Math.min(c,L-1),P=I*S,R=b.slice(P,P+S),A=v.useMemo(()=>{if(!e)return[];const E=new Map;for(const U of e.sessions)E.set(U.runtime,(E.get(U.runtime)??0)+1);return[...E.entries()].sort((U,W)=>W[1]-U[1]).map(([U])=>U)},[e]),z=v.useMemo(()=>{const E=new Map;for(const{session:U}of b)for(const W of U.entities)E.set(W,(E.get(W)??0)+1);return[...E.entries()].sort((U,W)=>W[1]-U[1]).map(([U])=>U)},[b]),V=a!==""||u!==""||h!=="all"||m!=="all",M=()=>{o(""),f(""),p("all"),N("all"),w("recent");const E=new URLSearchParams;x&&E.set("session",x),l(E)},D=R.findIndex(E=>E.session.id===x),F=D<R.length-1?R[D+1].session.id:null,J=D>0?R[D-1].session.id:null;return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"search-header",children:[s.jsx("form",{onSubmit:E=>E.preventDefault(),className:"search-bar",children:s.jsxs("div",{className:"search-wrap",style:{flex:1},children:[s.jsx("input",{className:"search-input search-big",placeholder:"search sessions, decisions, open questions…",value:i,onChange:E=>o(E.target.value),autoFocus:!0}),i.length>0&&s.jsx("button",{type:"button",className:"search-clear",onClick:()=>o(""),"aria-label":"Clear search",children:s.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),s.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})}),s.jsxs("div",{className:"thread-filters",children:[A.length>1&&s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Agent filter",children:[s.jsx("button",{type:"button",className:`chip${h==="all"?" active":""}`,onClick:()=>p("all"),children:"all"}),A.map(E=>{const U=b.filter(W=>W.session.runtime===E).length;return s.jsxs("button",{type:"button",className:`chip${h===E?" active":""}`,onClick:()=>p(E),children:[E," · ",U]},E)})]}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Status filter",children:["all","active","idle","closed","superseded"].map(E=>{const U=E==="all"?b.length:b.filter(W=>W.session.status===E).length;return s.jsxs("button",{type:"button",className:`chip${m===E?" active":""}`,"data-status":E==="all"?void 0:E,onClick:()=>N(E),children:[E," · ",U]},E)})}),a!==""&&s.jsx("div",{className:"filter-group",role:"group","aria-label":"Sort order",children:["relevance","recent"].map(E=>s.jsx("button",{type:"button",className:`chip${g===E?" active":""}`,onClick:()=>w(E),children:E},E))}),z.length>0&&s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Entity filter",style:{flexWrap:"wrap"},children:[s.jsx("button",{type:"button",className:`chip${u===""?" active":""}`,onClick:()=>f(""),children:"all entities"}),z.slice(0,12).map(E=>s.jsx("button",{type:"button",className:`chip${u===E?" active":""}`,onClick:()=>f(u===E?"":E),children:E},E)),z.length>12&&s.jsxs("select",{className:"form-input form-input-inline",value:u,onChange:E=>f(E.target.value),children:[s.jsx("option",{value:"",children:"more entities…"}),z.slice(12).map(E=>s.jsx("option",{value:E,children:E},E))]})]})]})]}),t&&!e&&s.jsx("div",{className:"muted",children:"Loading…"}),n&&s.jsx("div",{className:"muted error",children:n}),!V&&s.jsx("p",{className:"muted small search-hint",children:"Showing recent sessions. Type to search across labels, decisions, open questions, and summaries."}),s.jsxs("div",{className:"muted small search-meta",children:[b.length," result",b.length===1?"":"s",V&&s.jsx("button",{type:"button",className:"link-button",style:{marginLeft:8},onClick:M,children:"clear filters"})]}),s.jsxs("ul",{className:"session-list",children:[R.map(({session:E,matchedField:U})=>{let W=E.summary;return _.length>0&&(U==="decision"?W=E.decisions.find(le=>_.some(xe=>le.toLowerCase().includes(xe)))??E.summary:U==="open"&&(W=E.open.find(le=>_.some(xe=>le.toLowerCase().includes(xe)))??E.summary)),s.jsxs("li",{className:`session-row session-row-detail clickable${x===E.id?" is-active":""}`,onClick:()=>k(E.id),children:[s.jsx("span",{className:`chip-inline status-${E.status}`,children:E.status}),s.jsxs("div",{className:"session-row-main",children:[s.jsx("span",{className:"session-label",children:E.label}),s.jsx("span",{className:"session-meta",children:E.entities.slice(0,4).map(le=>s.jsx("span",{className:"chip-inline",style:{marginRight:4},children:le},le))}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"live-tag","data-kind":U,children:U}),s.jsx("div",{className:"match-snippet",dangerouslySetInnerHTML:{__html:qm(Zm(W,_),_)}})]})]}),s.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:4},children:[s.jsx("span",{className:"muted small mono",children:qe(E.started_at)}),s.jsx("span",{className:"chip-inline",children:E.runtime})]})]},E.id)}),R.length===0&&e&&s.jsx("li",{className:"muted empty-row",children:b.length===0?"No sessions match the current filters.":"No sessions on this page."})]}),b.length>0&&s.jsxs("div",{className:"pagination",children:[s.jsxs("div",{className:"page-size",children:[s.jsx("label",{className:"form-label",children:"Per page"}),s.jsx("select",{className:"form-input form-input-inline",value:S,onChange:E=>d(Number.parseInt(E.target.value,10)),children:Gm.map(E=>s.jsx("option",{value:E,children:E},E))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[P+1,"–",Math.min(P+S,b.length)," of ",b.length]}),s.jsxs("div",{className:"page-nav",children:[s.jsx("button",{type:"button",className:"chip",disabled:I===0,onClick:()=>y(0),children:"« first"}),s.jsx("button",{type:"button",className:"chip",disabled:I===0,onClick:()=>y(E=>Math.max(0,E-1)),children:"‹ prev"}),s.jsxs("span",{className:"page-indicator mono",children:[I+1," / ",L]}),s.jsx("button",{type:"button",className:"chip",disabled:I>=L-1,onClick:()=>y(E=>Math.min(L-1,E+1)),children:"next ›"}),s.jsx("button",{type:"button",className:"chip",disabled:I>=L-1,onClick:()=>y(L-1),children:"last »"})]})]}),x&&s.jsx(Lr,{sessionId:x,onClose:C,onNavigate:k,prevSessionId:F,nextSessionId:J})]})}function tv(){const{data:e,loading:t,error:n,refetch:r}=bn(),[l,a]=Cd(),i=l.get("entity")??"",o=l.get("session"),[u,f]=v.useState(()=>es().threadSort),[h,p]=v.useState(!1),[m,N]=v.useState(!1),g=v.useMemo(()=>{if(!e||!i)return[];const x=e.sessions.filter(j=>j.entities.includes(i));return x.sort((j,k)=>{const C=j.started_at??"",_=k.started_at??"";return u==="recent"?_.localeCompare(C):C.localeCompare(_)}),x},[e,i,u]),w=i&&e?e.entity_colors[i]??"#666":"#666";v.useEffect(()=>{i&&e&&(document.title=`${i} — Thread`)},[i,e]);const S=x=>{const j=new URLSearchParams(l);j.set("session",x),a(j)},d=()=>{const x=new URLSearchParams(l);x.delete("session"),a(x)};if(t&&!e)return s.jsxs("div",{className:"page-pad",children:[s.jsx(ie,{h:22,w:220}),s.jsx("div",{style:{marginTop:16},children:s.jsx(Tm,{rows:8})})]});if(n&&!e)return s.jsx("div",{className:"page-pad",children:s.jsx("div",{className:"muted error",children:n})});if(!e)return null;if(!i)return s.jsx(sv,{data:e});const c=g.flatMap(x=>x.decisions.map(j=>({d:j,sid:x.id,when:x.started_at}))),y=g.flatMap(x=>x.open_questions.map(j=>({id:j.id,q:j.text,sid:x.id,when:x.started_at})));return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"thread-header",children:[s.jsx("span",{className:"dot lg",style:{background:w}}),s.jsx("h2",{className:"page-title",children:i}),s.jsxs("span",{className:"muted",children:[g.length," session",g.length===1?"":"s"]}),s.jsx("span",{className:"header-spacer"}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Sort order",children:["recent","oldest"].map(x=>s.jsx("button",{type:"button",className:`chip${u===x?" active":""}`,onClick:()=>f(x),children:x==="recent"?"recent first":"oldest first"},x))})]}),s.jsxs("div",{className:"thread-grid",children:[s.jsxs("section",{className:"card",children:[s.jsxs("header",{className:"card-head",children:[s.jsx("h3",{children:"Decisions"}),s.jsx("span",{className:"muted small",children:c.length})]}),s.jsxs("ul",{className:"marker-list",children:[(h?c:c.slice(0,30)).map((x,j)=>s.jsxs("li",{className:"marker-row",children:[s.jsx("span",{className:"live-tag","data-kind":"decision",children:"decision"}),s.jsx("span",{className:"marker-text",children:x.d}),s.jsx("button",{type:"button",className:"link-button",onClick:()=>S(x.sid),children:qe(x.when)})]},j)),c.length===0&&s.jsx("li",{className:"muted empty-row",children:"No decisions captured yet."}),c.length>30&&s.jsx("li",{style:{padding:"8px 14px"},children:s.jsx("button",{type:"button",className:"link-button",onClick:()=>p(x=>!x),children:h?"Show less":`Showing 30 of ${c.length} — show all`})})]})]}),s.jsxs("section",{className:"card",children:[s.jsxs("header",{className:"card-head",children:[s.jsx("h3",{children:"Open questions"}),s.jsx("span",{className:"muted small",children:y.length})]}),s.jsxs("ul",{className:"marker-list",children:[(m?y:y.slice(0,30)).map((x,j)=>s.jsxs("li",{className:"marker-row marker-row-promotable",children:[s.jsx("span",{className:"live-tag","data-kind":"open",children:"open"}),s.jsx("span",{className:"marker-text",children:x.q}),s.jsxs("div",{className:"marker-actions",children:[s.jsx(Ed,{openId:x.id,defaultText:x.q,onPromoted:r}),s.jsx("button",{type:"button",className:"link-button",onClick:()=>S(x.sid),children:qe(x.when)})]})]},`${x.id}-${j}`)),y.length===0&&s.jsx("li",{className:"muted empty-row",children:"No open questions captured yet."}),y.length>30&&s.jsx("li",{style:{padding:"8px 14px"},children:s.jsx("button",{type:"button",className:"link-button",onClick:()=>N(x=>!x),children:m?"Show less":`Showing 30 of ${y.length} — show all`})})]})]})]}),s.jsx(rv,{thread:g,entity:i,onOpenSession:S}),o&&(()=>{const x=g.findIndex(C=>C.id===o),j=x<g.length-1?g[x+1].id:null,k=x>0?g[x-1].id:null;return s.jsx(Lr,{sessionId:o,onClose:d,onNavigate:S,prevSessionId:j,nextSessionId:k,entityColor:w})})()]})}const nv=[10,25,50,100];function rv({thread:e,entity:t,onOpenSession:n}){const[r,l]=v.useState("all"),[a,i]=v.useState(""),[o,u]=v.useState("all"),[f,h]=v.useState("all"),[p,m]=v.useState(25),[N,g]=v.useState(0),w=v.useMemo(()=>{const j=new Map;for(const k of e)j.set(k.runtime,(j.get(k.runtime)??0)+1);return[...j.entries()].sort((k,C)=>C[1]-k[1]).map(([k])=>k)},[e]),S=v.useMemo(()=>{const j=a.toLowerCase().trim();return e.filter(k=>r!=="all"&&k.runtime!==r||o!=="all"&&k.status!==o||f==="decisions"&&k.decisions.length===0||f==="open"&&k.open_questions.length===0?!1:j?k.label.toLowerCase().includes(j)||k.summary.toLowerCase().includes(j)||k.decisions.some(C=>C.toLowerCase().includes(j))||k.open.some(C=>C.toLowerCase().includes(j)):!0)},[e,a,o,f,r]);v.useEffect(()=>{g(0)},[a,o,f,p,r]),v.useEffect(()=>{l("all")},[t]);const d=Math.max(1,Math.ceil(S.length/p)),c=Math.min(N,d-1),y=c*p,x=S.slice(y,y+p);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"thread-sessions-head",children:[s.jsx("h3",{className:"section-title thread-sessions-title",children:"Sessions"}),s.jsxs("div",{className:"search-wrap",children:[s.jsx("input",{className:"search-input",placeholder:"search label, summary, decisions, open…",value:a,onChange:j=>i(j.target.value),onKeyDown:j=>{j.key==="Escape"&&i("")}}),a&&s.jsx("button",{type:"button",className:"search-clear",onClick:()=>i(""),"aria-label":"Clear search",children:s.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),s.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),s.jsxs("div",{className:"thread-filters",children:[w.length>1&&s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Agent filter",children:[s.jsx("button",{type:"button",className:`chip${r==="all"?" active":""}`,onClick:()=>l("all"),children:"all"}),w.map(j=>{const k=e.filter(C=>C.runtime===j).length;return s.jsxs("button",{type:"button",className:`chip${r===j?" active":""}`,onClick:()=>l(j),children:[j," · ",k]},j)})]}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Status filter",children:["all","active","idle","closed","superseded"].map(j=>{const k=j==="all"?e.length:e.filter(C=>C.status===j).length;return s.jsxs("button",{type:"button",className:`chip${o===j?" active":""}`,"data-status":j==="all"?void 0:j,onClick:()=>u(j),children:[j," · ",k]},j)})}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Marker filter",children:["all","decisions","open"].map(j=>{const k=j==="decisions"?e.filter(C=>C.decisions.length>0).length:e.filter(C=>C.open_questions.length>0).length;return s.jsx("button",{type:"button",className:`chip${f===j?" active":""}`,"data-marker":j==="all"?void 0:j,onClick:()=>h(j),children:j==="all"?"all":`${j} · ${k}`},j)})}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[S.length," match",S.length===1?"":"es"]})]}),s.jsxs("ul",{className:"session-list",children:[x.map(j=>s.jsxs("li",{className:"session-row session-row-detail clickable",onClick:()=>n(j.id),children:[s.jsx("span",{className:`chip-inline status-${j.status}`,children:j.status}),s.jsxs("div",{className:"session-row-main",children:[s.jsx("span",{className:"session-label",children:j.label}),s.jsx("span",{className:"session-meta",children:j.summary})]}),s.jsx("span",{className:"muted small mono",children:qe(j.started_at)})]},j.id)),x.length===0&&s.jsx("li",{className:"muted empty-row",children:e.length===0?"No sessions yet.":"No sessions match the current filters."})]}),S.length>0&&s.jsxs("div",{className:"pagination",children:[s.jsxs("div",{className:"page-size",children:[s.jsx("label",{className:"form-label",children:"Per page"}),s.jsx("select",{className:"form-input form-input-inline",value:p,onChange:j=>m(Number.parseInt(j.target.value,10)),children:nv.map(j=>s.jsx("option",{value:j,children:j},j))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[y+1,"–",Math.min(y+p,S.length)," of ",S.length]}),s.jsxs("div",{className:"page-nav",children:[s.jsx("button",{type:"button",className:"chip",disabled:c===0,onClick:()=>g(0),children:"« first"}),s.jsx("button",{type:"button",className:"chip",disabled:c===0,onClick:()=>g(j=>Math.max(0,j-1)),children:"‹ prev"}),s.jsxs("span",{className:"page-indicator mono",children:[c+1," / ",d]}),s.jsx("button",{type:"button",className:"chip",disabled:c>=d-1,onClick:()=>g(j=>Math.min(d-1,j+1)),children:"next ›"}),s.jsx("button",{type:"button",className:"chip",disabled:c>=d-1,onClick:()=>g(d-1),children:"last »"})]})]})]})}const lv=[24,48,96];function sv({data:e}){const[t,n]=v.useState("all"),[r,l]=v.useState(""),[a,i]=v.useState("most-active"),[o,u]=v.useState(48),[f,h]=v.useState(0),p=v.useMemo(()=>{const c=new Map;for(const y of e.sessions)for(const x of y.entities){let j=c.get(x);j||(j=new Set,c.set(x,j)),j.add(y.runtime)}return c},[e.sessions]),m=v.useMemo(()=>[...e.runtimes].sort((c,y)=>y.sessions_total-c.sessions_total),[e.runtimes]),N=v.useMemo(()=>{const c=r.toLowerCase().trim(),y=c?e.entities.filter(j=>j.canonical.toLowerCase().includes(c)):[...e.entities],x=t==="all"?y:y.filter(j=>{var k;return((k=p.get(j.canonical))==null?void 0:k.has(t))??!1});return x.sort((j,k)=>a==="most-active"?k.session_count-j.session_count:a==="least-active"?j.session_count-k.session_count:a==="a-z"?j.canonical.localeCompare(k.canonical):k.canonical.localeCompare(j.canonical)),x},[e.entities,r,a,t,p]);v.useEffect(()=>{h(0)},[r,a,o,t]);const g=Math.max(1,Math.ceil(N.length/o)),w=Math.min(f,g-1),S=w*o,d=N.slice(S,S+o);return s.jsxs("div",{className:"page-pad",children:[s.jsx("h2",{className:"page-title",children:"Thread"}),s.jsx("p",{className:"muted",children:"Pick an entity to view its reasoning history."}),s.jsxs("div",{className:"thread-sessions-head",style:{marginTop:16},children:[s.jsxs("div",{className:"search-wrap",style:{maxWidth:320},children:[s.jsx("input",{className:"search-input",placeholder:"search entities…",value:r,onChange:c=>l(c.target.value),onKeyDown:c=>{c.key==="Escape"&&l("")}}),r&&s.jsx("button",{type:"button",className:"search-clear",onClick:()=>l(""),"aria-label":"Clear search",children:s.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[s.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),s.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),s.jsx("span",{className:"header-spacer"}),s.jsx("span",{className:"muted small",children:r?`${N.length} of ${e.entities.length} entities`:`${e.entities.length} entities`})]}),s.jsxs("div",{className:"thread-filters",children:[s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Agent filter",children:[s.jsx("button",{type:"button",className:`chip${t==="all"?" active":""}`,onClick:()=>n("all"),children:"all"}),m.map(c=>s.jsxs("button",{type:"button",className:`chip${t===c.name?" active":""}`,onClick:()=>n(c.name),children:[c.name," · ",c.sessions_total]},c.name))]}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Sort order",children:["most-active","least-active","a-z","z-a"].map(c=>s.jsx("button",{type:"button",className:`chip${a===c?" active":""}`,onClick:()=>i(c),children:c==="most-active"?"most active":c==="least-active"?"least active":c},c))})]}),s.jsxs("ul",{className:"entity-grid",children:[d.map(c=>s.jsx("li",{children:s.jsxs(Pr,{to:`/thread?entity=${encodeURIComponent(c.canonical)}`,className:"card card-lift entity-card",children:[s.jsx("span",{className:"dot",style:{background:e.entity_colors[c.canonical]??"#666"}}),s.jsx("span",{className:"entity-name",children:c.canonical}),s.jsx("span",{className:"muted small",children:c.session_count})]})},c.canonical)),d.length===0&&s.jsx("li",{style:{gridColumn:"1 / -1"},className:"muted empty-row",children:"No entities match."})]}),N.length>o&&s.jsxs("div",{className:"pagination",children:[s.jsxs("div",{className:"page-size",children:[s.jsx("label",{className:"form-label",children:"Per page"}),s.jsx("select",{className:"form-input form-input-inline",value:o,onChange:c=>u(Number.parseInt(c.target.value,10)),children:lv.map(c=>s.jsx("option",{value:c,children:c},c))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[S+1,"–",Math.min(S+o,N.length)," of ",N.length]}),s.jsxs("div",{className:"page-nav",children:[s.jsx("button",{type:"button",className:"chip",disabled:w===0,onClick:()=>h(0),children:"« first"}),s.jsx("button",{type:"button",className:"chip",disabled:w===0,onClick:()=>h(c=>Math.max(0,c-1)),children:"‹ prev"}),s.jsxs("span",{className:"page-indicator mono",children:[w+1," / ",g]}),s.jsx("button",{type:"button",className:"chip",disabled:w>=g-1,onClick:()=>h(c=>Math.min(g-1,c+1)),children:"next ›"}),s.jsx("button",{type:"button",className:"chip",disabled:w>=g-1,onClick:()=>h(g-1),children:"last »"})]})]})]})}const av={days:7,total:0,with_results:0,hit_rate:0,by_source:{},top_queries:[],log_present:!1},iv={days:7,total:0,with_results:0,hit_rate:0,by_source:{},top_subjects:[],top_predicates:[],log_present:!1},ov=[7,30,90];function uv(){const[e,t]=v.useState(7),n=er(`/api/recall/stats?days=${e}`,3e4,av),r=er(`/api/recall/facts/stats?days=${e}`,3e4,iv);return s.jsxs("div",{className:"page-pad",children:[s.jsxs("div",{className:"recall-head",children:[s.jsxs("p",{className:"muted small recall-note",children:["Hit rate measures whether recall returned something — not whether the agent used it. Watch ",s.jsx("strong",{children:"by source"})," for adoption and ",s.jsx("strong",{children:"hit rate"})," for whether the corpus covers what's being asked."]}),s.jsx("div",{className:"filter-group",role:"group","aria-label":"Time window",children:ov.map(l=>s.jsxs("button",{type:"button",className:`chip${e===l?" active":""}`,onClick:()=>t(l),children:[l,"d"]},l))})]}),s.jsx(Zo,{title:"Session recall",subtitle:"What the orchestrator pulls when answering questions about past work — the human-operator surface.",stats:n.data,error:n.error,topLabel:"Top queries",topRows:n.data.top_queries.map(l=>({label:l.query,count:l.count}))}),s.jsx(Zo,{title:"Fact recall",subtitle:"Structured facts agents pull mid-task — the orchestrator surface.",stats:r.data,error:r.error,topLabel:"Top subjects",topRows:r.data.top_subjects.map(l=>({label:l.subject,count:l.count})),extraLabel:"Top predicates",extraRows:r.data.top_predicates.map(l=>({label:l.predicate,count:l.count}))})]})}function Zo({title:e,subtitle:t,stats:n,error:r,topLabel:l,topRows:a,extraLabel:i,extraRows:o}){const u=n.total-n.with_results,f=Object.entries(n.by_source).map(([h,p])=>({label:h,count:p})).sort((h,p)=>p.count-h.count);return s.jsxs("section",{className:"recall-block",children:[s.jsxs("header",{className:"recall-block-head",children:[s.jsx("h2",{className:"page-title",children:e}),s.jsx("p",{className:"muted small",children:t})]}),r&&s.jsx("div",{className:"muted error small",children:r}),n.log_present?n.total===0?s.jsxs("div",{className:"card recall-empty muted",children:["No queries in the last ",n.days," days. The log exists but this window is empty."]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"kpi-row",children:[s.jsx(Xr,{label:"Queries",value:n.total,hint:`last ${n.days}d`}),s.jsx(Xr,{label:"Hit rate",value:`${Math.round(n.hit_rate*100)}%`,hint:`${n.with_results.toLocaleString()} returned ≥1`}),s.jsx(Xr,{label:"Zero-result",value:u,hint:u>0?"corpus gaps":"full coverage"}),s.jsx(Xr,{label:"Sources",value:f.length,hint:"distinct callers"})]}),s.jsxs("div",{className:"recall-cards",children:[s.jsx(Rs,{title:"By source",rows:f,emptyText:"No sources recorded."}),s.jsx(Rs,{title:l,rows:a,emptyText:"None recorded."}),i&&o&&s.jsx(Rs,{title:i,rows:o,emptyText:"None recorded."})]})]}):s.jsx("div",{className:"card recall-empty muted",children:"No query log on disk yet — nothing has called this recall surface."})]})}function Xr({label:e,value:t,hint:n}){return s.jsxs("div",{className:"kpi",children:[s.jsx("span",{className:"kpi-label",children:e}),s.jsx("span",{className:"kpi-value",children:typeof t=="number"?t.toLocaleString():t}),n&&s.jsx("span",{className:"kpi-hint",children:n})]})}function Rs({title:e,rows:t,emptyText:n}){const r=Math.max(1,...t.map(l=>l.count));return s.jsxs("section",{className:"card",children:[s.jsx("header",{className:"card-head",children:s.jsx("h3",{children:e})}),s.jsxs("div",{className:"bar-stack recall-bars",children:[t.length===0&&s.jsx("div",{className:"muted small recall-bars-empty",children:n}),t.map(l=>s.jsxs("div",{className:"bar-item",children:[s.jsx("span",{className:"bar-label recall-bar-label",title:l.label,children:l.label}),s.jsx("div",{className:"bar-track",children:s.jsx("div",{className:"bar-fill tone-active",style:{width:`${l.count/r*100}%`}})}),s.jsx("span",{className:"bar-value mono",children:l.count.toLocaleString()})]},l.label))]})]})}const cv=[{to:"/settings",label:"Overview"},{to:"/settings/sources",label:"Sources"},{to:"/settings/providers",label:"Providers"},{to:"/settings/classifier",label:"Classifier"},{to:"/settings/labels",label:"Labels"},{to:"/settings/data",label:"Data"},{to:"/settings/views",label:"Views"}];function Jt(){return s.jsx("div",{className:"subnav",children:cv.map(e=>s.jsx(Ta,{to:e.to,end:e.to==="/settings",className:({isActive:t})=>`subnav-link${t?" active":""}`,children:e.label},e.to))})}const dv=[{to:"/settings/sources",title:"Sources",body:()=>"Transcript origins the daemon scans. Add Claude Code, Hermes, pi.dev, custom JSONL directories, or webhook ingest."},{to:"/settings/providers",title:"Providers",body:()=>"LLM endpoints (DeepSeek, Ollama, OpenAI, Anthropic, OpenRouter, custom). Manage keys and test connections."},{to:"/settings/labels",title:"Labels",body:({entities:e})=>`${e} entities catalogued. Promote candidates and edit types.`},{to:"/settings/classifier",title:"Classifier",body:({classifierProvider:e})=>e?`Active provider: ${e}.`:"Classifier provider unknown."},{to:"/settings/data",title:"Data",body:({sessions:e})=>`${e} sessions in the canonical store. Inspect path and backup posture.`},{to:"/settings/views",title:"Views",body:()=>"Default landing page, density, sort, density tier."}];function fv(){const{data:e}=bn(),t={sessions:(e==null?void 0:e.meta.sessions_total)??0,entities:(e==null?void 0:e.meta.entities_total)??0,classifierProvider:null};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsx("div",{className:"settings-grid",children:dv.map(n=>s.jsxs(Pr,{to:n.to,className:"card card-lift settings-card",children:[s.jsx("h3",{className:"settings-card-title",children:n.title}),s.jsx("p",{className:"settings-card-body",children:n.body(t)})]},n.to))})]})}function pv(e){if(e<1024)return`${e} B`;const t=["KB","MB","GB"];let n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n.toFixed(n>=100?0:1)} ${t[r]}`}function hv(){var p;const[e,t]=v.useState(null),[n,r]=v.useState(null),[l,a]=v.useState(null),[i,o]=v.useState(!1),u=v.useRef(null),f=v.useCallback(async()=>{try{const m=await fetch("/api/data/stats");if(!m.ok)throw new Error(`HTTP ${m.status}`);t(await m.json()),r(null)}catch(m){r(m instanceof Error?m.message:String(m))}},[]);v.useEffect(()=>{f()},[f]);const h=async()=>{var N,g;const m=(g=(N=u.current)==null?void 0:N.files)==null?void 0:g[0];if(m&&confirm(`Restore from "${m.name}"? Your current database is archived (not deleted), and the new one takes effect after the daemon restarts.`)){o(!0),a(null);try{const w=new FormData;w.append("file",m);const d=await(await fetch("/api/data/restore",{method:"POST",body:w})).json();a(d),d.staged&&u.current&&(u.current.value="")}catch(w){a({error:w instanceof Error?w.message:String(w)})}finally{o(!1)}}};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsx("h2",{className:"page-title",children:"Data"}),!e&&!n&&s.jsx("div",{className:"muted",children:"Loading…"}),n&&s.jsx("div",{className:"muted error",children:n}),e&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"section-title",children:"Storage"}),s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Canonical SQLite"}),s.jsx("dd",{className:"kv-value mono",children:e.dbPath}),s.jsx("dt",{className:"kv-label",children:"On disk"}),s.jsxs("dd",{className:"kv-value mono",children:[pv(e.dbBytes),!e.dbPresent&&s.jsx("span",{className:"muted small",children:" · file missing"})]}),s.jsx("dt",{className:"kv-label",children:"Schema version"}),s.jsxs("dd",{className:"kv-value mono",children:[e.schemaVersion??"—",e.migrations.length>0&&s.jsxs("span",{className:"muted small",children:[" · ",e.migrations.length," migrations applied"]})]})]}),s.jsx("h3",{className:"section-title",children:"Tables"}),s.jsxs("table",{className:"data-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Table"}),s.jsx("th",{children:"Rows"})]})}),s.jsx("tbody",{children:e.tables.map(m=>s.jsxs("tr",{children:[s.jsx("td",{className:"mono small",children:m.name}),s.jsx("td",{className:"mono",children:m.rows.toLocaleString()})]},m.name))})]}),e.runtimes.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("h3",{className:"section-title",children:"Sessions by runtime"}),s.jsxs("table",{className:"data-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Runtime"}),s.jsx("th",{children:"Sessions"})]})}),s.jsx("tbody",{children:e.runtimes.map(m=>s.jsxs("tr",{children:[s.jsx("td",{className:"mono small",children:m.runtime}),s.jsx("td",{className:"mono",children:m.n.toLocaleString()})]},m.runtime))})]})]}),s.jsx("h3",{className:"section-title",children:"Backup"}),s.jsx("p",{className:"muted small",children:"Downloads a clean, defragmented snapshot of the canonical store. Safe to run while the daemon is ingesting."}),s.jsx("div",{className:"form-row",children:s.jsx("a",{className:"btn btn-accent",href:"/api/data/backup",download:!0,children:"Download backup"})}),s.jsx("h3",{className:"section-title",children:"Restore"}),s.jsxs("p",{className:"muted small",children:["Replace the canonical store with an ",s.jsx("code",{children:".sqlite"})," backup. The current database is archived alongside it (",s.jsx("code",{children:".pre-restore-<timestamp>"}),"), never deleted. Takes effect on the next daemon restart."]}),s.jsxs("div",{className:"form-row",children:[s.jsx("input",{ref:u,type:"file",accept:".sqlite,application/x-sqlite3",className:"file-input",disabled:i}),s.jsx("button",{type:"button",className:"btn",onClick:()=>void h(),disabled:i,children:i?"Validating…":"Restore from backup"})]}),(l==null?void 0:l.staged)&&s.jsx("div",{className:"card",style:{borderColor:"var(--accent)",padding:"0.75rem 1rem",marginTop:"0.75rem"},children:s.jsxs("p",{className:"small",style:{margin:0},children:["Backup validated and staged (",(p=l.sessions)==null?void 0:p.toLocaleString()," sessions, schema v",l.schemaVersion,").",s.jsx("strong",{children:" Restart the daemon"})," to apply it. Your current database will be archived automatically."]})}),(l==null?void 0:l.error)&&s.jsx("p",{className:"muted error small",children:l.error})]})]})}function mv(){const[e,t]=v.useState(()=>es()),[n,r]=v.useState(!1),l=v.useRef(!0);v.useEffect(()=>{if(l.current){l.current=!1;return}Km(e),r(!0);const i=setTimeout(()=>r(!1),1800);return()=>clearTimeout(i)},[e]);const a=e.landing===xt.landing&&e.riverDensity===xt.riverDensity&&e.threadSort===xt.threadSort;return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsxs("div",{className:"form-row",style:{justifyContent:"space-between"},children:[s.jsx("h2",{className:"page-title",style:{margin:0},children:"Views"}),n&&s.jsx("span",{className:"muted small",children:"Saved"})]}),s.jsxs("div",{className:"form-grid",children:[s.jsx(bs,{label:"Default landing",children:s.jsxs("select",{className:"form-input",value:e.landing,onChange:i=>t({...e,landing:i.target.value}),children:[s.jsx("option",{value:"live",children:"Live"}),s.jsx("option",{value:"pulse",children:"Pulse"}),s.jsx("option",{value:"river",children:"River"}),s.jsx("option",{value:"thread",children:"Thread"}),s.jsx("option",{value:"search",children:"Search"})]})}),s.jsx(bs,{label:"River density",children:s.jsxs("select",{className:"form-input",value:e.riverDensity,onChange:i=>t({...e,riverDensity:i.target.value}),children:[s.jsx("option",{value:"compact",children:"Compact"}),s.jsx("option",{value:"comfortable",children:"Comfortable"}),s.jsx("option",{value:"spacious",children:"Spacious"})]})}),s.jsx(bs,{label:"Thread sort",children:s.jsxs("select",{className:"form-input",value:e.threadSort,onChange:i=>t({...e,threadSort:i.target.value}),children:[s.jsx("option",{value:"recent",children:"Most recent first"}),s.jsx("option",{value:"oldest",children:"Oldest first"})]})})]}),s.jsx("div",{className:"form-row",children:s.jsx("button",{type:"button",className:"btn",onClick:()=>t(xt),disabled:a,children:"Reset to defaults"})}),s.jsx("p",{className:"muted small",children:"Preferences are stored per-device in localStorage. Landing applies on next load; River density and Thread sort apply when you open those pages."})]})}function bs({label:e,children:t}){return s.jsxs("label",{className:"form-field",children:[s.jsx("span",{className:"form-label",children:e}),t]})}const Ms=["candidate","project","tool","contact","service","concept"],vv=["all","active","snoozed","retired"],gv=[{value:"sessions-desc",label:"Sessions (high → low)"},{value:"sessions-asc",label:"Sessions (low → high)"},{value:"name-asc",label:"Name (A → Z)"},{value:"name-desc",label:"Name (Z → A)"},{value:"recent",label:"Most recently seen"},{value:"oldest",label:"Least recently seen"}],yv=[25,50,100,200];function xv(){const{data:e,loading:t,error:n,refetch:r}=bn(),[l,a]=v.useState(""),[i,o]=v.useState("all"),[u,f]=v.useState("all"),[h,p]=v.useState("sessions-desc"),[m,N]=v.useState(50),[g,w]=v.useState(0),[S,d]=v.useState(null),c=(e==null?void 0:e.entities)??[],y=v.useMemo(()=>{const P=new Set(Ms);for(const R of c)P.add(R.type);return["all",...[...P].sort()]},[c]),x=v.useMemo(()=>{const P=l.toLowerCase().trim(),A=[...c.filter(z=>i!=="all"&&z.type!==i||u!=="all"&&z.status!==u?!1:P?z.canonical.toLowerCase().includes(P)||z.type.toLowerCase().includes(P):!0)];return A.sort((z,V)=>{switch(h){case"sessions-desc":return V.session_count-z.session_count;case"sessions-asc":return z.session_count-V.session_count;case"name-asc":return z.canonical.localeCompare(V.canonical);case"name-desc":return V.canonical.localeCompare(z.canonical);case"recent":return(V.last_seen_session??"").localeCompare(z.last_seen_session??"");case"oldest":return(z.last_seen_session??"").localeCompare(V.last_seen_session??"")}}),A},[c,l,i,u,h]);v.useEffect(()=>{w(0)},[l,i,u,h,m]);const j=Math.max(1,Math.ceil(x.length/m)),k=Math.min(g,j-1),C=k*m,_=x.slice(C,C+m),$=async(P,R)=>{d(P);try{await R(),await r()}finally{d(null)}},b=(P,R)=>$(P,()=>yn({kind:"label_entity",subject_type:"entity",subject_id:P,payload:{new_type:R}}).then(()=>{})),L=P=>$(P,()=>yn({kind:"retire_entity",subject_type:"entity",subject_id:P}).then(()=>{})),I=P=>{const R=new Date(Date.now()+2592e6).toISOString();return $(P,()=>yn({kind:"snooze",subject_type:"entity",subject_id:P,payload:{snoozed_until:R}}).then(()=>{}))};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsxs("div",{className:"page-header",children:[s.jsx("h2",{className:"page-title",children:"Labels"}),s.jsx("input",{className:"search-input",placeholder:"search canonical or type…",value:l,onChange:P=>a(P.target.value)})]}),s.jsxs("div",{className:"thread-filters",children:[s.jsx("div",{className:"filter-group",role:"group","aria-label":"Status filter",children:vv.map(P=>s.jsx("button",{type:"button",className:`chip${u===P?" active":""}`,onClick:()=>f(P),children:P},P))}),s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Type filter",children:[s.jsx("label",{className:"form-label",children:"Type"}),s.jsx("select",{className:"form-input form-input-inline",value:i,onChange:P=>o(P.target.value),children:y.map(P=>s.jsx("option",{value:P,children:P},P))})]}),s.jsxs("div",{className:"filter-group",role:"group","aria-label":"Sort",children:[s.jsx("label",{className:"form-label",children:"Sort"}),s.jsx("select",{className:"form-input form-input-inline",value:h,onChange:P=>p(P.target.value),children:gv.map(P=>s.jsx("option",{value:P.value,children:P.label},P.value))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[x.length," match",x.length===1?"":"es"]})]}),n&&s.jsx("div",{className:"muted error",children:n}),s.jsxs("table",{className:"data-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Canonical"}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Status"}),s.jsx("th",{className:"right",children:"Sessions"}),s.jsx("th",{children:"Last seen"}),s.jsx("th",{children:"Actions"})]})}),t&&!e&&s.jsx(Rm,{rows:8,cols:6}),s.jsxs("tbody",{children:[_.map(P=>{const R=S===P.canonical;return s.jsxs("tr",{className:R?"row-busy":"",children:[s.jsxs("td",{className:"canonical",children:[s.jsx("span",{className:"dot",style:{background:(e==null?void 0:e.entity_colors[P.canonical])??"#666"}}),P.canonical]}),s.jsx("td",{children:s.jsx("select",{className:"form-input form-input-inline",value:Ms.includes(P.type)?P.type:"candidate",onChange:A=>void b(P.canonical,A.target.value),disabled:R,children:Ms.map(A=>s.jsx("option",{value:A,children:A},A))})}),s.jsx("td",{children:s.jsx("span",{className:`chip-inline status-${P.status}`,children:P.status})}),s.jsx("td",{className:"right mono",children:P.session_count}),s.jsx("td",{className:"mono small",children:P.last_seen_session??"—"}),s.jsxs("td",{className:"row-actions",children:[s.jsx("button",{type:"button",className:"chip",disabled:R,onClick:()=>void I(P.canonical),children:"snooze 30d"}),s.jsx("button",{type:"button",className:"chip",disabled:R,onClick:()=>void L(P.canonical),children:"retire"})]})]},P.canonical)}),_.length===0&&s.jsx("tr",{children:s.jsx("td",{colSpan:6,className:"muted small empty-row",children:c.length===0?"No entities yet.":"No entities match the current filters."})})]})]}),x.length>0&&s.jsxs("div",{className:"pagination",children:[s.jsxs("div",{className:"page-size",children:[s.jsx("label",{className:"form-label",children:"Per page"}),s.jsx("select",{className:"form-input form-input-inline",value:m,onChange:P=>N(Number.parseInt(P.target.value,10)),children:yv.map(P=>s.jsx("option",{value:P,children:P},P))})]}),s.jsx("span",{className:"header-spacer"}),s.jsxs("span",{className:"muted small",children:[C+1,"–",Math.min(C+m,x.length)," of ",x.length]}),s.jsxs("div",{className:"page-nav",children:[s.jsx("button",{type:"button",className:"chip",disabled:k===0,onClick:()=>w(0),children:"« first"}),s.jsx("button",{type:"button",className:"chip",disabled:k===0,onClick:()=>w(P=>Math.max(0,P-1)),children:"‹ prev"}),s.jsxs("span",{className:"page-indicator mono",children:[k+1," / ",j]}),s.jsx("button",{type:"button",className:"chip",disabled:k>=j-1,onClick:()=>w(P=>Math.min(j-1,P+1)),children:"next ›"}),s.jsx("button",{type:"button",className:"chip",disabled:k>=j-1,onClick:()=>w(j-1),children:"last »"})]})]}),s.jsx("p",{className:"muted small",children:"Changes are append-only actions; refresh re-applies the overlay over the persisted store."})]})}const jv=["claude-code","codex","hermes","pi","jsonl-generic","webhook"],wv=["deepseek","ollama","openai","anthropic","openrouter","openai-compatible"],nr={deepseek:"DeepSeek",ollama:"Ollama",openai:"OpenAI",anthropic:"Anthropic",openrouter:"OpenRouter","openai-compatible":"OpenAI-compatible"},Pd={"claude-code":"Claude Code",codex:"Codex",hermes:"Hermes",pi:"pi.dev","jsonl-generic":"Custom JSONL",webhook:"Webhook"},qo={"claude-code":{name:"Claude Code",runtimeLabel:"claude-code",pathOrUrl:"~/.claude/projects",parseConfig:{}},codex:{name:"Codex",runtimeLabel:"codex",pathOrUrl:"~/.codex/sessions",parseConfig:{}},hermes:{name:"Hermes",runtimeLabel:"hermes",pathOrUrl:"~/.hermes/sessions",parseConfig:{}},pi:{name:"pi.dev",runtimeLabel:"pi",pathOrUrl:"~/.pi/transcripts",parseConfig:{}},"jsonl-generic":{name:"",runtimeLabel:"",pathOrUrl:"",parseConfig:{idField:"session_id",textField:"text",startedAtField:"started_at",endedAtField:"ended_at"}},webhook:{name:"",runtimeLabel:"",pathOrUrl:null,parseConfig:{}}},eu={deepseek:{baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},ollama:{baseUrl:"http://localhost:11434",defaultModel:"phi4-mini:latest"},openai:{baseUrl:"https://api.openai.com/v1",defaultModel:"gpt-4o-mini"},anthropic:{baseUrl:"https://api.anthropic.com",defaultModel:"claude-haiku-4-5-20251001"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",defaultModel:"anthropic/claude-haiku-4-5"},"openai-compatible":{baseUrl:"",defaultModel:null}};async function Nv(){const e=await fetch("/api/sources");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).sources}async function Ld(){const e=await fetch("/api/providers");if(!e.ok)throw new Error(`HTTP ${e.status}`);return(await e.json()).providers}async function kv(e){const t=await fetch(`/api/providers/${e}/models`),n=await t.json();if(!t.ok||n.error)throw new Error(n.error??`HTTP ${t.status}`);return n.models??[]}async function Li(e){return await(await fetch(`/api/providers/${e}/test`,{method:"POST"})).json()}function Sv(){const[e,t]=v.useState(null),[n,r]=v.useState([]),[l,a]=v.useState([]),[i,o]=v.useState(null),[u,f]=v.useState(null),[h,p]=v.useState(""),[m,N]=v.useState(null),[g,w]=v.useState(null),[S,d]=v.useState(!1),[c,y]=v.useState(null),[x,j]=v.useState(null),k=v.useCallback(async()=>{try{const[R,A]=await Promise.all([fetch("/api/classifier/info").then(D=>D.json()),Ld()]);t(R),r(A);const z=A.find(D=>D.kind===R.provider&&D.enabled),V=A.find(D=>D.enabled)??A[0]??null,M=z??V;f(M?M.id:null),p(R.model),j(null)}catch(R){j(R instanceof Error?R.message:String(R))}},[]);v.useEffect(()=>{k()},[k]);const C=v.useMemo(()=>n.find(R=>R.id===u)??null,[n,u]);v.useEffect(()=>{if(!C){a([]);return}let R=!1;return o(null),a([]),kv(C.id).then(A=>{R||(a(A),(!h||!A.includes(h))&&p(C.defaultModel??A[0]??""))}).catch(A=>{R||o(A instanceof Error?A.message:String(A))}),()=>{R=!0}},[C==null?void 0:C.id]);const _=C?`${C.id}|${h}`:"",$=(m==null?void 0:m.ok)===!0&&g===_,L=(e&&C?C.kind!==e.provider||h!==e.model:!1)&&h.length>0&&!S&&$,I=async()=>{if(C){d(!0),N(null),w(null);try{const R=await Li(C.id);N(R),R.ok&&w(_)}catch(R){N({ok:!1,latencyMs:0,error:R instanceof Error?R.message:String(R)})}finally{d(!1)}}},P=async()=>{if(C){d(!0),y(null);try{const R=await fetch("/api/classifier",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:C.kind,model:h})}),A=await R.json();!R.ok||A.error?y(`Error: ${A.error??R.statusText}`):(y(`Active: ${A.provider} · ${A.model}`),await k())}catch(R){y(`Error: ${R instanceof Error?R.message:String(R)}`)}finally{d(!1)}}};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsx("h2",{className:"page-title",children:"Classifier"}),!e&&!x&&s.jsx("div",{className:"muted",children:"Loading…"}),x&&s.jsx("div",{className:"muted error",children:x}),e&&s.jsxs(s.Fragment,{children:[s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Active provider"}),s.jsx("dd",{className:"kv-value mono",children:e.provider}),s.jsx("dt",{className:"kv-label",children:"Active model"}),s.jsx("dd",{className:"kv-value mono",children:e.model})]}),s.jsx("h3",{className:"section-title",children:"Switch model"}),n.length===0?s.jsxs("p",{className:"muted small",children:["No providers configured. Add one on the ",s.jsx("a",{href:"/settings/providers",children:"Providers"})," page first."]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Provider"}),s.jsx("select",{className:"form-input form-input-inline",value:u??"",onChange:R=>{f(Number.parseInt(R.target.value,10)),N(null),w(null)},disabled:S,children:n.map(R=>s.jsxs("option",{value:R.id,disabled:!R.enabled,children:[R.name," (",nr[R.kind],")",R.enabled?"":" — disabled",R.kind!=="ollama"&&!R.hasApiKey?" — no key":""]},R.id))}),s.jsx("label",{className:"form-label",children:"Model"}),s.jsxs("select",{className:"form-input form-input-inline",value:h,onChange:R=>{p(R.target.value),w(null)},disabled:S||l.length===0,children:[l.map(R=>s.jsx("option",{value:R,children:R},R)),!l.includes(h)&&h&&s.jsx("option",{value:h,children:h})]}),s.jsx("button",{type:"button",className:"btn",onClick:()=>void I(),disabled:S||!C,children:S&&!m?"Testing…":"Test connection"}),s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>void P(),disabled:!L,title:$?void 0:"Run a successful test before saving",children:S&&(m!=null&&m.ok)?"Saving…":"Save"})]}),i&&s.jsxs("p",{className:"muted error small",children:["Model list failed: ",i]}),m&&s.jsx("p",{className:`small ${m.ok?"muted":"muted error"}`,children:m.ok?`Connection OK · ${m.modelCount??"?"} models · ${m.latencyMs}ms`:`Connection failed: ${m.error??"unknown"} (${m.latencyMs}ms)`}),c&&s.jsx("p",{className:"muted small",children:c}),s.jsx("p",{className:"muted small",children:"Save is gated on a passing connection test for the selected provider + model."})]}),s.jsx("h3",{className:"section-title",children:"Embedder"}),s.jsxs("dl",{className:"kv-list",children:[s.jsx("dt",{className:"kv-label",children:"Provider"}),s.jsx("dd",{className:"kv-value mono",children:e.embedder.provider}),s.jsx("dt",{className:"kv-label",children:"Model"}),s.jsx("dd",{className:"kv-value mono",children:e.embedder.model}),s.jsx("dt",{className:"kv-label",children:"Dimensions"}),s.jsx("dd",{className:"kv-value mono",children:e.embedder.dims})]}),s.jsx("p",{className:"muted small",children:"Embedder is fixed at build time. Recall vectors must match the index dims, so it isn't hot-swappable. DeepSeek has no embeddings endpoint; Ollama serves both classification (optional) and embedding (always)."})]})]})}function Cv(){const[e,t]=v.useState([]),[n,r]=v.useState(null),[l,a]=v.useState(!0),[i,o]=v.useState(!1),[u,f]=v.useState(null),h=v.useCallback(async()=>{a(!0);try{t(await Nv()),r(null)}catch(g){r(g instanceof Error?g.message:String(g))}finally{a(!1)}},[]);v.useEffect(()=>{h()},[h]);const p=async g=>{await fetch(`/api/sources/${g.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!g.enabled})}),await h()},m=async g=>{confirm(`Delete source "${g.name}"? This stops scanning but leaves ingested sessions in place.`)&&(await fetch(`/api/sources/${g.id}`,{method:"DELETE"}),await h())},N=async g=>{if(!confirm(`Regenerate token for "${g.name}"? Any client using the current token will stop working.`))return;const w=await fetch(`/api/sources/${g.id}/regenerate-token`,{method:"POST"}),S=await w.json();S.token?(f({name:g.name,token:S.token}),await h()):alert(`Failed: ${S.error??w.statusText}`)};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsxs("div",{className:"form-row",style:{justifyContent:"space-between"},children:[s.jsx("h2",{className:"page-title",style:{margin:0},children:"Sources"}),s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>o(!0),children:"Add source"})]}),u&&s.jsx(Ev,{name:u.name,token:u.token,onDismiss:()=>f(null)}),l&&e.length===0&&s.jsx("div",{className:"muted",children:"Loading…"}),n&&s.jsx("div",{className:"muted error",children:n}),e.length>0&&s.jsxs("table",{className:"data-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Kind"}),s.jsx("th",{children:"Runtime"}),s.jsx("th",{children:"Path / URL"}),s.jsx("th",{children:"Status"}),s.jsx("th",{})]})}),s.jsx("tbody",{children:e.map(g=>s.jsxs("tr",{children:[s.jsx("td",{className:"mono",children:g.name}),s.jsx("td",{children:Pd[g.kind]}),s.jsx("td",{className:"mono small",children:g.runtimeLabel}),s.jsx("td",{className:"mono small",children:g.pathOrUrl??(g.kind==="webhook"?"—":"")}),s.jsx("td",{children:s.jsx("span",{className:`chip-inline ${g.enabled?"status-active":"status-stale"}`,children:g.enabled?"enabled":"disabled"})}),s.jsx("td",{children:s.jsxs("div",{className:"form-row",style:{gap:"0.5rem"},children:[s.jsx("button",{type:"button",className:"btn small",onClick:()=>void p(g),children:g.enabled?"Disable":"Enable"}),g.kind==="webhook"&&s.jsx("button",{type:"button",className:"btn small",onClick:()=>void N(g),children:"Regenerate token"}),s.jsx("button",{type:"button",className:"btn small",onClick:()=>void m(g),children:"Delete"})]})})]},g.id))})]}),!l&&e.length===0&&s.jsx("p",{className:"muted small",children:'No sources yet. Click "Add source" to scan your first transcript directory.'}),i&&s.jsx(_v,{onClose:()=>o(!1),onCreated:g=>{o(!1),g.kind==="webhook"&&g.token&&f({name:g.name,token:g.token}),h()}})]})}function Ev({name:e,token:t,onDismiss:n}){return s.jsxs("div",{className:"card",style:{borderColor:"var(--accent)",padding:"1rem",marginTop:"1rem"},children:[s.jsxs("h3",{className:"section-title",style:{marginTop:0},children:['One-time token for "',e,'"']}),s.jsxs("p",{className:"muted small",children:["Copy this now. It's stored hashed on the daemon and won't be shown again. Send sessions with"," ",s.jsx("code",{children:"Authorization: Bearer <token>"})," to ",s.jsx("code",{children:"POST /api/ingest"}),"."]}),s.jsx("pre",{className:"mono",style:{padding:"0.5rem",overflow:"auto"},children:t}),s.jsxs("div",{className:"form-row",children:[s.jsx("button",{type:"button",className:"btn",onClick:()=>void navigator.clipboard.writeText(t),children:"Copy"}),s.jsx("button",{type:"button",className:"btn btn-accent",onClick:n,children:"I've stored it"})]})]})}function _v({onClose:e,onCreated:t}){const[n,r]=v.useState("claude-code"),l=qo[n],[a,i]=v.useState(l.name),[o,u]=v.useState(l.runtimeLabel),[f,h]=v.useState(l.pathOrUrl??""),[p,m]=v.useState({idField:"session_id",textField:"text",startedAtField:"started_at",endedAtField:"ended_at"}),[N,g]=v.useState(!1),[w,S]=v.useState(null);v.useEffect(()=>{const j=qo[n];i(j.name),u(j.runtimeLabel),h(j.pathOrUrl??""),S(null)},[n]);const d=n!=="webhook",c=n==="jsonl-generic",y=async()=>{g(!0),S(null);try{const j={kind:n,name:a,runtimeLabel:o};d&&(j.pathOrUrl=f),c&&(j.parseConfig=p);const k=await fetch("/api/sources",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)}),C=await k.json();if(!k.ok||C.error){S(C.error??k.statusText);return}t(C)}catch(j){S(j instanceof Error?j.message:String(j))}finally{g(!1)}},x=!N&&a.length>0&&o.length>0&&(!d||f.length>0);return s.jsxs("div",{className:"card",style:{padding:"1rem",marginTop:"1rem"},children:[s.jsx("h3",{className:"section-title",style:{marginTop:0},children:"Add source"}),s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Kind"}),s.jsx("select",{className:"form-input form-input-inline",value:n,onChange:j=>r(j.target.value),disabled:N,children:jv.map(j=>s.jsx("option",{value:j,children:Pd[j]},j))})]}),s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Name"}),s.jsx("input",{className:"form-input form-input-inline",value:a,onChange:j=>i(j.target.value),placeholder:c||n==="webhook"?"e.g. my-agent":"",disabled:N}),s.jsx("label",{className:"form-label",children:"Runtime label"}),s.jsx("input",{className:"form-input form-input-inline",value:o,onChange:j=>u(j.target.value),placeholder:"appears on Pulse Runtimes card",disabled:N})]}),d&&s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:n==="jsonl-generic"?"Directory":"Path"}),s.jsx("input",{className:"form-input form-input-inline",style:{minWidth:"32rem"},value:f,onChange:j=>h(j.target.value),placeholder:"absolute or ~/ path to JSONL directory",disabled:N})]}),c&&s.jsxs(s.Fragment,{children:[s.jsx("h4",{className:"section-title",style:{fontSize:"0.875rem"},children:"JSONL field mapping"}),s.jsx("p",{className:"muted small",children:"How to read your JSONL files. Each row should be one session. Use dot.notation for nested fields."}),["idField","textField","startedAtField","endedAtField"].map(j=>s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:j}),s.jsx("input",{className:"form-input form-input-inline",value:p[j],onChange:k=>m({...p,[j]:k.target.value}),disabled:N})]},j))]}),n==="webhook"&&s.jsxs("p",{className:"muted small",children:["A bearer token will be generated and shown ",s.jsx("strong",{children:"once"})," when you create this source. Use it to ",s.jsx("code",{children:"POST /api/ingest"})," from any agent or script."]}),w&&s.jsx("p",{className:"muted error small",children:w}),s.jsxs("div",{className:"form-row",children:[s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>void y(),disabled:!x,children:N?"Creating…":"Create"}),s.jsx("button",{type:"button",className:"btn",onClick:e,disabled:N,children:"Cancel"})]})]})}function Pv(){const[e,t]=v.useState([]),[n,r]=v.useState(null),[l,a]=v.useState(!0),[i,o]=v.useState(!1),[u,f]=v.useState({}),h=v.useCallback(async()=>{a(!0);try{t(await Ld()),r(null)}catch(g){r(g instanceof Error?g.message:String(g))}finally{a(!1)}},[]);v.useEffect(()=>{h()},[h]);const p=async g=>{await fetch(`/api/providers/${g.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!g.enabled})}),await h()},m=async g=>{confirm(`Delete provider "${g.name}"? The Classifier will fall back to another provider if this one was active.`)&&(await fetch(`/api/providers/${g.id}`,{method:"DELETE"}),await h())},N=async g=>{f(w=>({...w,[g.id]:"running"}));try{const w=await Li(g.id);f(S=>({...S,[g.id]:w}))}catch(w){f(S=>({...S,[g.id]:{ok:!1,latencyMs:0,error:w instanceof Error?w.message:String(w)}}))}};return s.jsxs("div",{className:"page-pad",children:[s.jsx(Jt,{}),s.jsxs("div",{className:"form-row",style:{justifyContent:"space-between"},children:[s.jsx("h2",{className:"page-title",style:{margin:0},children:"Providers"}),s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>o(!0),children:"Add provider"})]}),l&&e.length===0&&s.jsx("div",{className:"muted",children:"Loading…"}),n&&s.jsx("div",{className:"muted error",children:n}),e.length>0&&s.jsxs("table",{className:"data-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Kind"}),s.jsx("th",{children:"Base URL"}),s.jsx("th",{children:"Default model"}),s.jsx("th",{children:"API key"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Last test"}),s.jsx("th",{})]})}),s.jsx("tbody",{children:e.map(g=>{const w=u[g.id];return s.jsxs("tr",{children:[s.jsx("td",{className:"mono",children:g.name}),s.jsx("td",{children:nr[g.kind]}),s.jsx("td",{className:"mono small",children:g.baseUrl??"—"}),s.jsx("td",{className:"mono small",children:g.defaultModel??"—"}),s.jsx("td",{children:g.kind==="ollama"||g.kind==="openai-compatible"?s.jsx("span",{className:"muted small",children:g.hasApiKey?"set":"n/a"}):s.jsx("span",{className:`chip-inline ${g.hasApiKey?"status-active":"status-stale"}`,children:g.hasApiKey?"set":"missing"})}),s.jsx("td",{children:s.jsx("span",{className:`chip-inline ${g.enabled?"status-active":"status-stale"}`,children:g.enabled?"enabled":"disabled"})}),s.jsxs("td",{className:"small",children:[w==="running"&&s.jsx("span",{className:"muted",children:"testing…"}),w&&w!=="running"&&w.ok&&s.jsxs("span",{className:"muted",children:["OK · ",w.modelCount," models · ",w.latencyMs,"ms"]}),w&&w!=="running"&&!w.ok&&s.jsxs("span",{className:"muted error",children:["fail: ",w.error]})]}),s.jsx("td",{children:s.jsxs("div",{className:"form-row",style:{gap:"0.5rem"},children:[s.jsx("button",{type:"button",className:"btn small",onClick:()=>void N(g),children:"Test"}),s.jsx("button",{type:"button",className:"btn small",onClick:()=>void p(g),children:g.enabled?"Disable":"Enable"}),s.jsx("button",{type:"button",className:"btn small",onClick:()=>void m(g),children:"Delete"})]})})]},g.id)})})]}),!l&&e.length===0&&s.jsx("p",{className:"muted small",children:'No providers yet. Click "Add provider" to wire up DeepSeek, Ollama, or any OpenAI-compatible endpoint.'}),i&&s.jsx(Lv,{onClose:()=>o(!1),onCreated:()=>{o(!1),h()}})]})}function Lv({onClose:e,onCreated:t}){const[n,r]=v.useState("deepseek"),l=eu[n],[a,i]=v.useState(nr[n]),[o,u]=v.useState(l.baseUrl??""),[f,h]=v.useState(""),[p,m]=v.useState(l.defaultModel??""),[N,g]=v.useState(!1),[w,S]=v.useState(null),[d,c]=v.useState(null);v.useEffect(()=>{const k=eu[n];i(nr[n]),u(k.baseUrl??""),m(k.defaultModel??""),c(null),S(null)},[n]);const y=n!=="ollama"&&n!=="openai-compatible",x=async k=>{g(!0),S(null);try{const C={kind:n,name:a};o&&(C.baseUrl=o),f&&(C.apiKey=f),p&&(C.defaultModel=p);const _=await fetch("/api/providers",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(C)}),$=await _.json();if(!_.ok||$.error){S($.error??_.statusText);return}if(k){const b=await Li($.id);if(c(b),!b.ok)return}t()}catch(C){S(C instanceof Error?C.message:String(C))}finally{g(!1)}},j=!N&&a.length>0&&(!y||f.length>0);return s.jsxs("div",{className:"card",style:{padding:"1rem",marginTop:"1rem"},children:[s.jsx("h3",{className:"section-title",style:{marginTop:0},children:"Add provider"}),s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Kind"}),s.jsx("select",{className:"form-input form-input-inline",value:n,onChange:k=>r(k.target.value),disabled:N,children:wv.map(k=>s.jsx("option",{value:k,children:nr[k]},k))}),s.jsx("label",{className:"form-label",children:"Name"}),s.jsx("input",{className:"form-input form-input-inline",value:a,onChange:k=>i(k.target.value),placeholder:"Display name (must be unique)",disabled:N})]}),s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Base URL"}),s.jsx("input",{className:"form-input form-input-inline",style:{minWidth:"28rem"},value:o,onChange:k=>u(k.target.value),placeholder:n==="openai-compatible"?"https://your-endpoint/v1":"",disabled:N})]}),s.jsxs("div",{className:"form-row",children:[s.jsxs("label",{className:"form-label",children:["API key",y?"":" (optional)"]}),s.jsx("input",{type:"password",className:"form-input form-input-inline",style:{minWidth:"28rem"},value:f,onChange:k=>h(k.target.value),autoComplete:"off",disabled:N})]}),s.jsxs("div",{className:"form-row",children:[s.jsx("label",{className:"form-label",children:"Default model"}),s.jsx("input",{className:"form-input form-input-inline",value:p,onChange:k=>m(k.target.value),placeholder:"optional",disabled:N})]}),d&&!d.ok&&s.jsxs("p",{className:"muted error small",children:["Saved, but test failed: ",d.error," (",d.latencyMs,"ms). You can edit or delete from the list."]}),w&&s.jsx("p",{className:"muted error small",children:w}),s.jsxs("div",{className:"form-row",children:[s.jsx("button",{type:"button",className:"btn btn-accent",onClick:()=>void x(!0),disabled:!j,children:N?"Saving…":"Save & test"}),s.jsx("button",{type:"button",className:"btn",onClick:()=>void x(!1),disabled:!j,children:"Save without testing"}),s.jsx("button",{type:"button",className:"btn",onClick:e,disabled:N,children:"Cancel"})]})]})}function Tv({page:e}){return s.jsxs("div",{className:"stub-shell",children:[s.jsxs("span",{className:"stub-name",children:["/",e]}),s.jsx("p",{children:"not yet ported from the Astro UI."}),s.jsx("p",{className:"stub-hint",children:"Tracked in NocoDB #95 (Vite + React SPA port)."})]})}function Rv(){return s.jsxs("div",{className:"page-shell",children:[s.jsx(gm,{}),s.jsxs("div",{className:"page-main",children:[s.jsx(bv,{}),s.jsxs(Jh,{children:[s.jsx(ve,{path:"/",element:s.jsx(Xh,{to:`/${es().landing}`,replace:!0})}),s.jsx(ve,{path:"/live",element:s.jsx(Im,{})}),s.jsx(ve,{path:"/pulse",element:s.jsx(Am,{})}),s.jsx(ve,{path:"/river",element:s.jsx(Qm,{})}),s.jsx(ve,{path:"/thread",element:s.jsx(tv,{})}),s.jsx(ve,{path:"/search",element:s.jsx(ev,{})}),s.jsx(ve,{path:"/recall",element:s.jsx(uv,{})}),s.jsx(ve,{path:"/settings",element:s.jsx(fv,{})}),s.jsx(ve,{path:"/settings/sources",element:s.jsx(Cv,{})}),s.jsx(ve,{path:"/settings/providers",element:s.jsx(Pv,{})}),s.jsx(ve,{path:"/settings/labels",element:s.jsx(xv,{})}),s.jsx(ve,{path:"/settings/classifier",element:s.jsx(Sv,{})}),s.jsx(ve,{path:"/settings/data",element:s.jsx(hv,{})}),s.jsx(ve,{path:"/settings/views",element:s.jsx(mv,{})}),s.jsx(ve,{path:"*",element:s.jsx(Tv,{page:"not found"})})]})]})]})}function bv(){const{pathname:e}=$t(),t=e.replace(/^\//,"").replace(/\/+$/,"")||"live";return s.jsxs("header",{className:"app-header",children:[s.jsx("span",{className:"wordmark-page",children:t}),s.jsx("span",{className:"header-spacer"}),s.jsx("span",{className:"status-dot","aria-hidden":"true"}),s.jsx("span",{className:"header-info",children:"nlm-memory · :3940"})]})}const Td=document.getElementById("root");if(!Td)throw new Error("missing #root");hd(Td).render(s.jsx(du.StrictMode,{children:s.jsx(am,{basename:"/ui",children:s.jsx(Rv,{})})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>nlm memory</title>
7
- <script type="module" crossorigin src="/ui/assets/index-CmY9CBuo.js"></script>
7
+ <script type="module" crossorigin src="/ui/assets/index-BO0dvNHn.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/ui/assets/index-B7j5U42U.css">
9
9
  </head>
10
10
  <body>
@@ -1,9 +1,13 @@
1
1
  # nlm-memory pi.dev extension
2
2
 
3
- This directory is the pi.dev distribution surface for nlm-memory. Pi exposes
4
- hooks as a TypeScript extension API (`pi -e <path>`), not config-file hooks
5
- like Claude Code or Codex, so the install surface is a single bundled
6
- extension module.
3
+ This directory is the pi.dev distribution surface for nlm-memory. Pi loads
4
+ TypeScript extensions declared in `~/.pi/agent/settings.json`'s `packages`
5
+ array; pointing pi at this directory auto-discovers `index.js` and registers
6
+ the prompt-recall hook.
7
+
8
+ Pi's interactive UI strips `index.{ts,js}` from the load path, so this
9
+ extension surfaces in pi's `[Extensions]` list as `nlm` — matching the
10
+ naming convention used by `pi-mcp-adapter`, `whtnxt-tasks`, etc.
7
11
 
8
12
  ## Install
9
13
 
@@ -15,17 +19,17 @@ nlm connect pi
15
19
  ```
16
20
 
17
21
  That appends this directory's absolute path to `packages` in
18
- `~/.pi/agent/settings.json`. Pi auto-loads it on next start via the
19
- `pi.extensions` field declared in this package's `package.json` (which
20
- points at `scripts/nlm-extension.mjs`). No `-e` flag required at the
21
- prompt.
22
+ `~/.pi/agent/settings.json`. Pi auto-loads `index.js` on next start. No
23
+ `-e` flag required at the prompt.
22
24
 
23
- Reverse with `nlm disconnect pi`.
25
+ Reverse with `nlm disconnect pi`. The disconnect filter also strips the
26
+ legacy `plugin-pi` basename used by nlm-memory <= 0.5.19, so users
27
+ upgrading from that release get a clean migration.
24
28
 
25
29
  Manual fallback if you'd rather not edit settings.json:
26
30
 
27
31
  ```bash
28
- pi -e "$(npm root -g)/nlm-memory/plugin-pi/scripts/nlm-extension.mjs"
32
+ pi -e "$(npm root -g)/nlm-memory/nlm/index.js"
29
33
  ```
30
34
 
31
35
  ## What ships
@@ -45,8 +49,6 @@ pi -e "$(npm root -g)/nlm-memory/plugin-pi/scripts/nlm-extension.mjs"
45
49
  (`src/core/adapters/pi.ts`) already polls `~/.pi/agent/sessions/**/*.jsonl`
46
50
  and ingests completed sessions on its own schedule — what Claude's
47
51
  stop-hook does inline.
48
- - **No `nlm connect pi` wrapper yet.** Install is the manual `pi -e` line
49
- above.
50
52
 
51
53
  ## Modes
52
54
 
@@ -67,5 +69,5 @@ Same env vars as the Claude Code hook:
67
69
  npm run build:codex-plugin
68
70
  ```
69
71
 
70
- Bundles `src/hook/pi-extension.ts` to `plugin-pi/scripts/nlm-extension.mjs`
71
- via the same esbuild pipeline that builds the Claude Code hook scripts.
72
+ Bundles `src/hook/pi-extension.ts` to `nlm/index.js` via the same esbuild
73
+ pipeline that builds the Claude Code hook scripts.
@@ -4,9 +4,5 @@
4
4
  "private": true,
5
5
  "description": "pi.dev extension entry for nlm-memory prompt-recall hook.",
6
6
  "type": "module",
7
- "pi": {
8
- "extensions": [
9
- "scripts/nlm-extension.mjs"
10
- ]
11
- }
7
+ "main": "index.js"
12
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nlm-memory",
3
- "version": "0.5.19",
3
+ "version": "0.5.21",
4
4
  "description": "Local-first non-linear memory operating system for AI operators.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  "files": [
30
30
  "dist",
31
31
  "plugin",
32
- "plugin-pi",
32
+ "nlm",
33
33
  "assets",
34
34
  "LICENSE",
35
35
  "README.md"
@@ -44,12 +44,16 @@
44
44
  "build:ui": "vite build --config src/ui/vite.config.ts",
45
45
  "build:codex-plugin": "node scripts/build-codex-plugin.mjs",
46
46
  "build": "npm run build:server && npm run build:ui && npm run build:codex-plugin",
47
+ "prepare": "[ -d src ] && npm run build || true",
47
48
  "ui:dev": "vite --config src/ui/vite.config.ts",
48
49
  "test": "vitest run",
49
50
  "test:watch": "vitest",
50
51
  "test:unit": "vitest run tests/unit",
51
52
  "test:integration": "vitest run tests/integration",
52
- "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json"
53
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json",
54
+ "bench:longmemeval": "tsx scripts/longmemeval/run-harness.ts",
55
+ "bench:classifier": "tsx scripts/longmemeval/run-harness.ts --classifier",
56
+ "bench:compare": "tsx scripts/longmemeval/compare-classifiers.ts"
53
57
  },
54
58
  "dependencies": {
55
59
  "@clack/prompts": "^1.4.0",