@wrongstack/webui 0.296.3 → 0.296.4
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.
- package/dist/assets/{AgentRosterView-Bnfjs7SR.js → AgentRosterView-DTbg5NoZ.js} +1 -1
- package/dist/assets/{AnalyticsDashboard-Df_4y-Kx.js → AnalyticsDashboard-Xc8aG4ev.js} +1 -1
- package/dist/assets/{AudienceMemoryPanel-BCXl0qMA.js → AudienceMemoryPanel-C1mj_XOq.js} +1 -1
- package/dist/assets/{ChangesView-CngAYbT4.js → ChangesView-W_UTPolz.js} +1 -1
- package/dist/assets/{ChronicleDashboard-BTnRluuW.js → ChronicleDashboard-BivxCmdl.js} +1 -1
- package/dist/assets/{CodeEditor-Bb8Oyrho.js → CodeEditor-NAOGCzZS.js} +1 -1
- package/dist/assets/{CronJobsPanel-CUjKpoEA.js → CronJobsPanel-0virGKLS.js} +1 -1
- package/dist/assets/{DebugDashboard-CF9tnDg7.js → DebugDashboard-DYEVc0PA.js} +1 -1
- package/dist/assets/{DesignGalleryView-DDOG2RxE.js → DesignGalleryView-BSBDNBNf.js} +1 -1
- package/dist/assets/{GoalView-CAckYUC5.js → GoalView-C_wodXvj.js} +1 -1
- package/dist/assets/{KanbanView-BMzDV1-z.js → KanbanView-D7SKeieE.js} +1 -1
- package/dist/assets/{LazyMarkdown-CaNUh8CL.js → LazyMarkdown-Bt3iw3ZV.js} +1 -1
- package/dist/assets/{MailboxDetailView-DQUJsig8.js → MailboxDetailView-BaFQIyhC.js} +1 -1
- package/dist/assets/{MemoryManager-JTZWsb0i.js → MemoryManager-CWkdwf8F.js} +1 -1
- package/dist/assets/{ModelPicker-D5XBxW8U.js → ModelPicker-CJBOoZME.js} +1 -1
- package/dist/assets/{OfficeMapPanel-C6S89GWN.js → OfficeMapPanel-BopbmfGN.js} +1 -1
- package/dist/assets/{ProcessMonitor-DJaaQP3Q.js → ProcessMonitor-d_5Iwyo7.js} +1 -1
- package/dist/assets/{QueuePanel-DBQkV_Ka.js → QueuePanel-DlNF8CUn.js} +1 -1
- package/dist/assets/{RefreshDebugView-BL9PikWZ.js → RefreshDebugView-gPMro5jy.js} +1 -1
- package/dist/assets/{SageTabs-CPyvLW73.js → SageTabs-yP5fr4lP.js} +2 -2
- package/dist/assets/{SddHub-CLFzMwKX.js → SddHub-DjeM7IaL.js} +1 -1
- package/dist/assets/{SessionsDashboard-B1lpqE1X.js → SessionsDashboard-D7b7aEse.js} +1 -1
- package/dist/assets/SetupScreen-Dsek43zs.js +1 -0
- package/dist/assets/{SkillDetailView-CeA6lnQh.js → SkillDetailView-DxdqTQ5E.js} +1 -1
- package/dist/assets/{SpecsView-T1qjfodF.js → SpecsView-Bu8xHf5j.js} +1 -1
- package/dist/assets/{TechStackView-ByuNsOIe.js → TechStackView--7TPHg0R.js} +1 -1
- package/dist/assets/{TerminalPanel-yTWOVqll.js → TerminalPanel-gA6ThdVE.js} +1 -1
- package/dist/assets/{Toaster-D5WTIK_V.js → Toaster-DTJHnKyl.js} +1 -1
- package/dist/assets/{i18n-D-JnOQZX.js → i18n-C2VyJ0Kz.js} +2 -2
- package/dist/assets/index-3CuRO3-V.css +1 -0
- package/dist/assets/{index-WvJRbCoi.js → index-DSXHr5yP.js} +5 -5
- package/dist/assets/{progress-ring-DZ7API6e.js → progress-ring-BEsRLdjq.js} +1 -1
- package/dist/assets/settings-C5F2tQ7C.js +1 -0
- package/dist/assets/settings-Cdk8i_p6.js +1 -0
- package/dist/assets/settings-D6wFOw5n.js +1 -0
- package/dist/assets/settings-DCEOkxYE.js +1 -0
- package/dist/assets/settings-DEmKlLmn.js +1 -0
- package/dist/assets/settings-DsflqNn0.js +1 -0
- package/dist/assets/settings-skShEZ2B.js +1 -0
- package/dist/assets/{useWebSocket-DAm5zYOB.js → useWebSocket-Ba38Sknk.js} +1 -1
- package/dist/components/AgentOfficeDetails.d.ts.map +1 -1
- package/dist/components/AgentOfficeView.d.ts.map +1 -1
- package/dist/components/AgentRosterView.d.ts.map +1 -1
- package/dist/components/CodeMap.d.ts.map +1 -1
- package/dist/components/DeadCodeScanPanel/DeadCodeScanPanel.d.ts.map +1 -1
- package/dist/components/OfficeMapCanvas/CanvasPanels.d.ts.map +1 -1
- package/dist/components/OfficeMapCanvas.d.ts.map +1 -1
- package/dist/components/SetupScreen/ProviderKeyCard.d.ts.map +1 -1
- package/dist/components/SetupScreen.d.ts.map +1 -1
- package/dist/components/context-editor/ContextWindowEditor.d.ts.map +1 -1
- package/dist/index.html +8 -8
- package/dist/index.js +168 -137
- package/dist/index.js.map +3 -3
- package/package.json +7 -7
- package/dist/assets/SetupScreen-M95bQ1A6.js +0 -1
- package/dist/assets/index-B_lRId11.css +0 -1
- package/dist/assets/settings-BHVrMeiB.js +0 -1
- package/dist/assets/settings-BNkUdI3D.js +0 -1
- package/dist/assets/settings-ByapDpso.js +0 -1
- package/dist/assets/settings-DDjoc06u.js +0 -1
- package/dist/assets/settings-DgZ3cEL3.js +0 -1
- package/dist/assets/settings-iiGjrvpU.js +0 -1
- package/dist/assets/settings-oGMBWYjV.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$n as t,Ct as n,Dt as r,Fi as i,Gi as a,Ir as o,It as s,Kn as c,Kr as l,Li as u,Nt as d,On as f,Qr as p,Ri as m,Si as h,Sn as g,Tr as _,Ut as v,Xr as y,Yr as b,Zi as x,Zt as S,_ as C,_n as w,a as T,at as E,br as D,bt as ee,cn as te,da as O,en as k,et as ne,f as re,hn as A,i as ie,ii as ae,ki as oe,n as se,oa as ce,pn as le,r as ue,s as j,vi as M,vr as de,xa as fe,xn as pe}from"./vendor-9hC4n4Me.js";import{n as me}from"./ui-store-BI3LH2q8.js";import{t as he}from"./useWebSocket-DAm5zYOB.js";import{t as N}from"./ws-client-eyEv8wbm.js";import{t as P}from"./utils-DzRQUvln.js";import{M as ge}from"./stores-hEu6z1qz.js";import{a as _e,i as ve,n as ye,o as be,r as F,t as I}from"./dialog-BLr7olIX.js";import{t as L}from"./button-Bmh1yFe5.js";import{t as R}from"./input-BRS2rHSR.js";import{b as xe,f as Se,p as Ce}from"./index-WvJRbCoi.js";import{t as we}from"./roster-ws-CVCrt_ih.js";import{_ as Te,a as Ee,b as De,c as Oe,d as ke,f as Ae,g as z,h as je,i as B,l as V,m as H,n as Me,o as Ne,p as Pe,r as U,s as Fe,t as Ie,u as Le,v as Re,y as W}from"./shared-DYL4K3aB.js";var G=e(fe(),1),K=ne(),ze=212,Be=188;function Ve(e){return e.length>14?`${e.slice(0,11)}…`:e}function He(e,t=58){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function Ue(e){return e.type===`symbol`?[e.path,e.symbol?`#${e.symbol}`:``].filter(Boolean).join(``):e.path??e.command??e.symbol??e.role??e.type}function We(e){return e===`active`?`border-success/45 bg-success/10 text-success`:e===`stale`?`border-warning/45 bg-warning/10 text-warning`:e===`contradicted`?`border-destructive/45 bg-destructive/10 text-destructive`:e===`superseded`?`border-warning/35 bg-warning/5 text-warning`:`border-border bg-muted/55 text-muted-foreground`}function Ge({data:e}){let{entry:t,center:n}=e;return(0,K.jsxs)(`div`,{className:n?`border border-primary/70 bg-card px-3 py-2.5 text-card-foreground shadow-[0_0_0_1px_hsl(var(--primary)/0.2),0_0_24px_hsl(var(--primary)/0.12)]`:`border border-border/80 bg-card/95 px-3 py-2.5 text-card-foreground shadow-lg`,style:{width:ze},title:t.text,children:[(0,K.jsx)(j,{type:`target`,position:C.Top,className:`!border-background !bg-muted-foreground`}),(0,K.jsx)(j,{type:`source`,position:C.Bottom,className:`!border-background !bg-primary`}),(0,K.jsx)(j,{type:`source`,position:C.Right,className:`!border-background !bg-primary`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[9px] font-bold uppercase ${We(t.status)}`,children:t.status}),(0,K.jsx)(`span`,{className:`ml-auto truncate font-mono text-[9px] text-muted-foreground`,children:Ve(t.id)})]}),(0,K.jsx)(`p`,{className:`mt-2 line-clamp-2 text-[11px] leading-4 text-foreground/90`,children:He(t.text)}),(0,K.jsx)(`p`,{className:`mt-1 font-mono text-[9px] uppercase text-muted-foreground`,children:t.kind})]})}function Ke({data:e}){return(0,K.jsxs)(`div`,{className:`border border-info/40 bg-info/8 px-2.5 py-2 text-card-foreground shadow-lg`,style:{width:Be},title:e.label,children:[(0,K.jsx)(j,{type:`target`,position:C.Left,className:`!border-background !bg-info`}),(0,K.jsx)(`p`,{className:`font-mono text-[9px] font-bold uppercase text-info`,children:e.anchor.type}),(0,K.jsx)(`p`,{className:`mt-1 truncate font-mono text-[10px] text-foreground/85`,children:e.label})]})}var qe={memoryNode:Ge,anchorNode:Ke};function Je(e){return{id:e,revision:0,scope:`project`,kind:`fact`,status:`deleted`,text:`Memory is unavailable or has been removed.`,importance:0,confidence:0,freshness:0,tags:[],anchors:[],createdAt:``,updatedAt:``}}function Ye({nodes:e,edges:t,className:n}){return(0,K.jsx)(`div`,{className:P(`w-full`,n),children:(0,K.jsxs)(re,{nodes:e,edges:t,nodeTypes:qe,fitView:!0,fitViewOptions:{padding:.24,maxZoom:1.05},minZoom:.4,maxZoom:1.5,nodesConnectable:!1,elementsSelectable:!1,panOnScroll:!1,zoomOnScroll:!1,proOptions:{hideAttribution:!0},children:[(0,K.jsx)(ue,{variant:ie.Dots,gap:18,size:1,color:`hsl(var(--muted-foreground) / 0.18)`}),(0,K.jsx)(T,{showInteractive:!1,className:`!border-border !bg-card !shadow-lg`})]})})}function q({centerMemory:e,allMemories:t,graphEdges:n,loading:r=!1,error:i=null}){let[a,o]=(0,G.useState)(!1),s=`mem:${e.id}`,c=(0,G.useMemo)(()=>n.filter(e=>e.from===s&&e.to.startsWith(`mem:`)||e.to===s&&e.from.startsWith(`mem:`)).slice(0,24),[s,n]),{nodes:l,edges:u}=(0,G.useMemo)(()=>{let n=[],r=[],i=new Map(t.map(e=>[e.id,e]));n.push({id:e.id,type:`memoryNode`,position:{x:320-ze/2,y:120},data:{entry:e,center:!0}});let a=[...e.supersededBy?[{id:e.supersededBy,relation:`superseded by`}]:[],...(e.supersedes??[]).map(e=>({id:e,relation:`supersedes`})),...(e.contradicts??[]).map(e=>({id:e,relation:`contradicts`}))];for(let e of c){let t=(e.from===s?e.to:e.from).slice(4);a.some(n=>n.id===t&&n.relation===e.relation)||a.push({id:t,relation:e.relation,weight:e.weight,evidence:e.evidence})}let o=320-(a.length-1)*220/2;return a.forEach((t,a)=>{let s=i.get(t.id)??Je(t.id),c=t.relation===`superseded by`,l=c?0:280+Math.floor(a/3)*130,u=c?320-ze/2:o+a*220-ze/2;n.push({id:`memory:${t.id}:${a}`,type:`memoryNode`,position:{x:u,y:l},data:{entry:s,center:!1}});let d=t.relation===`contradicts`,f=c?`memory:${t.id}:${a}`:e.id,p=c?e.id:`memory:${t.id}:${a}`;r.push({id:`relation:${t.relation}:${t.id}:${a}`,source:f,target:p,type:`smoothstep`,animated:!d,label:t.weight===void 0?t.relation:`${t.relation} ${t.weight.toFixed(2)}`,data:{evidence:t.evidence??[]},style:{stroke:d?`hsl(var(--destructive))`:`hsl(var(--primary))`,strokeWidth:1.7,...d?{strokeDasharray:`5 4`}:{}},labelStyle:{fill:d?`hsl(var(--destructive))`:`hsl(var(--muted-foreground))`,fontSize:9,fontWeight:700},labelBgStyle:{fill:`hsl(var(--card))`,fillOpacity:.9}})}),e.anchors.forEach((t,i)=>{let a=`anchor:${i}`;n.push({id:a,type:`anchorNode`,position:{x:540,y:120+(i-(e.anchors.length-1)/2)*66},data:{anchor:t,label:Ue(t)}}),r.push({id:`anchor-edge:${i}`,source:e.id,target:a,type:`smoothstep`,style:{stroke:`hsl(var(--info))`,strokeWidth:1.3}})}),{nodes:n,edges:r}},[t,e,s,c]);return l.length<=1&&!r&&!i?null:(0,K.jsxs)(`section`,{className:`overflow-hidden border border-border/75 bg-background/35`,"aria-label":`Memory relationship graph`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:`Relationship map`}),l.length>1&&(0,K.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),className:`h-6 gap-1 px-2 text-[9px] font-bold uppercase tracking-[0.12em]`,"aria-label":`Open full screen graph`,children:[(0,K.jsx)(p,{className:`size-3`}),`Open full screen`]})]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r?`loading real graph…`:`${l.length} nodes · ${u.length} edges`})]}),i&&(0,K.jsx)(`p`,{className:`border-b border-destructive/25 bg-destructive/5 px-3 py-2 text-[10px] text-destructive`,children:i}),l.length>1&&(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[320px]`}),c.some(e=>e.evidence?.length)&&(0,K.jsx)(`div`,{className:`grid gap-1 border-t border-border/70 bg-card/35 px-3 py-2`,children:c.filter(e=>e.evidence?.length).slice(0,12).map(e=>{let t=(e.from===s?e.to:e.from).slice(4);return(0,K.jsxs)(`p`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:[(0,K.jsx)(`span`,{className:`text-info`,children:e.relation}),` `,Ve(t),` · why:`,` `,e.evidence?.join(`, `)]},e.id)})}),a&&(0,K.jsx)(I,{open:a,onOpenChange:o,children:(0,K.jsxs)(ye,{className:`flex max-h-[90dvh] max-w-[90vw] flex-col p-0`,showCloseButton:!1,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-4 py-3`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:[`Relationship map — `,e.id]}),(0,K.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>o(!1),className:`h-7 gap-1 px-2 text-[10px]`,children:`Close`})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 px-4 pb-4`,children:(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[65vh]`})})]})})]})}function Xe({memory:e,allMemories:t,relatedMemories:r,graphEdges:i,graphLoading:o,graphError:s,onClose:c,onOpenMemory:l,onEdit:u,onDelete:d,onTagSelect:f,onNotice:p}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/65 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,className:`md:hidden`,onClick:c,"aria-label":`Back to memory list`,children:(0,K.jsx)(ce,{className:`size-4`})}),(0,K.jsx)(`span`,{className:P(`text-[10px] font-bold uppercase tracking-[0.14em]`,je(e.kind)),children:U[e.kind]??e.kind}),(0,K.jsx)(V,{status:e.status}),(0,K.jsx)(`span`,{className:`border border-border/70 px-2 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 border border-primary/30 bg-primary/10 px-2 py-0.5 font-mono text-[9px] text-primary`,title:Pe(e.audience),children:[(0,K.jsx)(a,{className:`size-3`}),Pe(e.audience)]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,"aria-label":`Copy memory ID`,title:`Copy memory ID`,onClick:()=>{navigator.clipboard?.writeText(e.id),p(`Memory ID copied.`)},children:(0,K.jsx)(M,{className:`size-4`})}),(0,K.jsxs)(L,{variant:`outline`,size:`sm`,onClick:u,disabled:e.status===`deleted`,children:[(0,K.jsx)(w,{className:`size-3.5`}),` Edit`]}),(0,K.jsxs)(L,{variant:`destructive`,size:`sm`,onClick:d,disabled:e.status===`deleted`,children:[(0,K.jsx)(n,{className:`size-3.5`}),` Delete`]})]})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[(0,K.jsx)(Ze,{memory:e}),(0,K.jsx)(J,{memory:e}),e.tags.length>0&&(0,K.jsx)(Qe,{tags:e.tags,onTagSelect:f}),e.anchors.length>0&&(0,K.jsx)(Y,{anchors:e.anchors}),r.length>0&&(0,K.jsx)($e,{relatedMemories:r,allMemories:t,onOpenMemory:l}),(0,K.jsx)(q,{centerMemory:e,allMemories:t,graphEdges:i,loading:o,error:s}),(0,K.jsx)(X,{memory:e}),e.status===`deleted`&&(0,K.jsx)(et,{contextPolicy:e.contextPolicy})]})})]})}function Ze({memory:e}){return(0,K.jsxs)(`div`,{className:`relative overflow-hidden border border-border/75 bg-card/55 p-5 shadow-[inset_0_1px_0_hsl(var(--foreground)/0.04)]`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute -right-10 -top-10 size-36 bg-[radial-gradient(circle,hsl(var(--info)/0.13),transparent_68%)]`}),(0,K.jsx)(`p`,{className:`relative whitespace-pre-wrap text-sm leading-7 text-foreground md:text-[15px]`,children:e.text}),e.summary&&(0,K.jsx)(`p`,{className:`relative mt-4 border-l-2 border-info/50 pl-3 text-xs italic leading-5 text-muted-foreground`,children:e.summary}),(0,K.jsxs)(`div`,{className:`relative mt-5 flex flex-wrap items-center gap-2 border-t border-border/60 pt-3`,children:[(0,K.jsx)(`code`,{className:`min-w-0 break-all font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-[10px] text-muted-foreground`,children:[`revision `,e.revision]})]})]})}function J({memory:e}){return(0,K.jsx)(`div`,{className:`grid gap-px bg-border/60 sm:grid-cols-3`,children:[[`Importance`,e.importance,v],[`Confidence`,e.confidence,oe],[`Freshness`,e.freshness,te]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/60 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(n,{className:`size-3.5 text-info`}),(0,K.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.13em] text-muted-foreground`,children:e}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-xs font-bold tabular-nums`,children:[Math.round(t*100),`%`]})]}),(0,K.jsx)(`div`,{className:`mt-2 h-1 bg-muted`,children:(0,K.jsx)(`div`,{className:`h-full bg-info shadow-[0_0_8px_hsl(var(--info)/0.45)]`,style:{width:`${Math.round(t*100)}%`}})})]},e))})}function Qe({tags:e,onTagSelect:t}){return(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(r,{className:`size-3.5 text-info`}),` Tags`]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>t(e),className:`border border-info/25 bg-info/5 px-2 py-1 font-mono text-[10px] text-info hover:border-info/55 hover:bg-info/10`,children:[`#`,e]},e))})]})}function Y({anchors:e}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(l,{className:`size-3.5 text-info`}),` Anchors`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map((e,t)=>(0,K.jsxs)(`li`,{className:`flex min-w-0 items-start gap-3 px-3 py-2.5`,children:[(0,K.jsx)(`span`,{className:`mt-0.5 flex size-7 shrink-0 items-center justify-center border border-info/25 bg-info/5 text-info`,children:e.type===`command`?(0,K.jsx)(d,{className:`size-3.5`}):(0,K.jsx)(l,{className:`size-3.5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-[9px] font-bold uppercase text-muted-foreground`,children:e.type}),(0,K.jsxs)(`p`,{className:`mt-0.5 break-all font-mono text-[10px] leading-4 text-foreground/85`,children:[e.path??e.command??e.role??`—`,e.symbol?`#${e.symbol}`:``]})]}),(e.lineStart||e.lineEnd)&&(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`L`,e.lineStart??`?`,`–`,e.lineEnd??`?`]})]},`${e.type}:${e.path??e.command??e.symbol??e.role}:${t}`))})]})}function $e({relatedMemories:e,allMemories:t,onOpenMemory:n}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(D,{className:`size-3.5 text-info`}),` Memory relationships`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map(e=>{let r=t.find(t=>t.id===e.id);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&n(r.id),className:`group flex w-full min-w-0 items-center gap-3 px-3 py-2.5 text-left hover:bg-info/5 disabled:cursor-not-allowed disabled:opacity-55`,children:[(0,K.jsx)(`span`,{className:P(`w-24 shrink-0 text-[9px] font-bold uppercase`,e.relation===`Contradicts`?`text-destructive`:`text-info`),children:e.relation}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs`,children:r?z(r.text,95):`Referenced memory is unavailable`}),(0,K.jsx)(`code`,{className:`hidden max-w-32 truncate font-mono text-[9px] text-muted-foreground sm:block`,children:e.id}),r&&(0,K.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground group-hover:text-info`})]})},`${e.relation}:${e.id}`)})})]})}function X({memory:e}){return(0,K.jsx)(`section`,{className:`grid gap-px bg-border/60 sm:grid-cols-2 lg:grid-cols-4`,children:[[`Created`,H(e.createdAt),x],[`Updated`,H(e.updatedAt),te],[`Last accessed`,H(e.lastAccessedAt),f],[`Last verified`,H(e.lastVerifiedAt),v]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/50 p-3`,children:[(0,K.jsx)(n,{className:`size-3.5 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`mt-2 text-[9px] font-bold uppercase tracking-[0.12em] text-muted-foreground`,children:e}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] leading-4 text-foreground/85`,children:t})]},e))})}function et({contextPolicy:e}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 border border-border bg-muted/50 p-4 text-xs text-muted-foreground`,children:[(0,K.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-bold text-foreground`,children:`Deleted memory`}),(0,K.jsx)(`p`,{className:`mt-1 leading-5`,children:e===`never`?`This record is audit-only and carries an absolute ban: it can never enter LLM context.`:`The record is inactive and cannot be edited, but remains eligible as historical evidence when retrieval finds it relevant.`})]})]})}var Z={filePath:``,primaryMatches:[],symbolMatches:[],relatedMatches:[],totalCount:0,activeCount:0,supersededCount:0,reviewPendingCount:0};function tt(e){let{filePath:t,lineStart:n,lineEnd:r,limit:i=50,showSuperseded:a=!0,showDeleted:o=!1,autoFetch:s=!0,sendOptions:c}=e,l=c?JSON.stringify(c):``,[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(null),g=(0,G.useRef)(0),_=(0,G.useRef)(null),v=(0,G.useRef)(c);v.current=c;let y=(0,G.useCallback)(()=>{if(!t){d(null),h(null),p(!1);return}let e=++g.current;p(!0),h(null);let s=N();if(!s){h(`WebSocket client unavailable`),p(!1);return}_.current?.(),_.current=null;let c=t,l=s.on(`memory.sage.forFile`,t=>{if(e!==g.current)return;let n=t.payload.response;n&&n.filePath!==c||(t.payload.error?(h(t.payload.error),d(null)):(d(n??Z),h(null)),p(!1))});_.current=l;let u={filePath:t,limit:i,showSuperseded:a,showDeleted:o,...n===void 0?{}:{lineStart:n},...r===void 0?{}:{lineEnd:r}};try{s.findMemoriesForFile(u,v.current??void 0)}catch(t){l(),_.current===l&&(_.current=null),e===g.current&&(h(t instanceof Error?t.message:String(t)),p(!1))}},[t,n,r,i,a,o]);(0,G.useEffect)(()=>{if(s)return y(),()=>{g.current++,_.current?.(),_.current=null}},[s,y,l]);let b=(0,G.useCallback)(()=>{y()},[y]);return(0,G.useEffect)(()=>()=>{_.current?.(),_.current=null},[]),{data:u,loading:f,error:m,refetch:b}}function nt(e){return e>=.9?`bg-success/15 border-success/40`:e>=.7?`bg-info/15 border-info/40`:e>=.4?`bg-warning/10 border-warning/30`:`bg-muted/30 border-border/40`}function Q(e){switch(e){case`scope_file`:return`scope: file`;case`scope_symbol`:return`scope: symbol`;case`anchor_file`:return`anchor: file`;case`anchor_symbol`:return`anchor: symbol`;case`anchor_directory`:return`anchor: directory`;case`mention`:return`text mention`}}function rt({match:e,cursorBoosted:t,onShowMemory:n,onAcceptDeletion:r,onKeep:i,onUpdate:a,onMarkPermanent:o,onRecover:l,pendingAction:u}){let d=e.memory.status===`deleted`,f=e.memory.status===`superseded`,p=e.pendingReview,h=u!==void 0,g=t===!0;return(0,K.jsxs)(`article`,{className:P(`group relative rounded-md border px-3 py-2 text-sm transition-colors`,nt(e.matchStrength),g&&`ring-1 ring-primary/40 ring-offset-0`,d&&`opacity-70`),"data-match-via":e.matchedVia,"data-memory-id":e.memory.id,children:[(0,K.jsx)(`header`,{className:`flex items-start justify-between gap-2`,children:(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide`,children:[(0,K.jsx)(`span`,{className:P(`font-mono`,je(e.memory.kind)),children:U[e.memory.kind]??e.memory.kind}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:Q(e.matchedVia)}),g&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-primary/15 px-1 py-0.5 font-mono text-primary`,title:`Cursor line range matches this memory's anchor`,children:[(0,K.jsx)(A,{className:`size-2.5`}),` cursor`]}),p&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-warning/15 px-1 py-0.5 font-mono text-warning`,title:`Hygiene review: ${p.reason} (${p.ageDays}d old)`,children:[(0,K.jsx)(ee,{className:`size-2.5`}),` review`]}),d&&(0,K.jsx)(`span`,{className:`font-mono text-destructive`,children:`deleted`}),f&&!d&&(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:`superseded`})]}),(0,K.jsx)(`p`,{className:`mt-1 text-foreground/90`,children:z(e.memory.text,200)}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(V,{status:e.memory.status}),(0,K.jsxs)(`span`,{children:[`updated `,Re(e.memory.updatedAt)]})]})]})}),(0,K.jsxs)(`footer`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[d&&l&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>l(e.memory.id),className:`h-7 gap-1 border-primary/40 px-2 text-[11px] text-primary hover:bg-primary/10`,title:`Restore this memory to active status (PR #1: memory_recover)`,children:[(0,K.jsx)(te,{className:`size-3`}),` Recover`]}),f&&e.supersededByActiveId&&n&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>n(e.supersededByActiveId),className:`h-7 gap-1 px-2 text-[11px]`,title:`This version is superseded — jump to the active version`,children:[(0,K.jsx)(de,{className:`size-3`}),` Go to active`]}),p&&(0,K.jsxs)(K.Fragment,{children:[p.suggestedAction===`delete`&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`destructive`,disabled:h,onClick:()=>r?.(p.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Accept hygiene's deletion suggestion — memory will be forgotten`,children:[(0,K.jsx)(m,{className:`size-3`}),` Accept Deletion`]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>i?.(p.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Reject the suggestion — memory stays as-is and may be re-suggested later`,children:[(0,K.jsx)(E,{className:`size-3`}),` Keep`]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>a?.(e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Update the memory's content — versioning creates a new active record`,children:[(0,K.jsx)(s,{className:`size-3`}),` Update`]}),o&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>o(e.memory.id),className:`h-7 gap-1 border-warning/40 px-2 text-[11px] text-warning hover:bg-warning/10`,title:"Promote to `permanent` — hygiene will never surface this again",children:[(0,K.jsx)(A,{className:`size-3`}),` Mark as Permanent`]})]}),n&&!d&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`ghost`,disabled:h,onClick:()=>n(e.memory.id),className:`h-7 gap-1 px-2 text-[11px] text-muted-foreground hover:text-foreground`,title:`Open the full record in MemoryManager`,children:[(0,K.jsx)(b,{className:`size-3`}),` Show full`]}),u&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(c,{className:`size-3 animate-spin`}),` `,u]})]})]})}function it({icon:e,title:t,count:n,matches:r,cursorBoosted:i=!1,...a}){let o=Ce(r,10);return r.length===0?null:(0,K.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-1.5 px-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(e,{className:`size-3`}),(0,K.jsx)(`span`,{children:t}),(0,K.jsxs)(`span`,{className:`font-mono`,children:[`(`,n,`)`]}),i&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(A,{className:`size-2.5`}),` cursor boost`]})]}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:o.pageItems.map(e=>(0,K.jsx)(rt,{match:e,cursorBoosted:i&&(e.matchedVia===`anchor_symbol`||e.matchedVia===`scope_symbol`),pendingAction:a.pendingActionById.get(e.memory.id),...a},e.memory.id))}),(0,K.jsx)(Se,{page:o.page,pageSize:o.pageSize,totalItems:o.totalItems,onPageChange:o.setPage,compact:!0,itemLabel:`memories`})]})}function at({filePath:e,lineStart:t,lineEnd:n,open:r,onClose:i,onShowMemory:a,onAcceptDeletion:s,onKeep:c,onUpdate:l,onMarkPermanent:u,onRecover:d}){let[f,p]=(0,G.useState)(!1),[m,g]=(0,G.useState)(new Map),{data:_,loading:v,error:x,refetch:S}=tt({filePath:e,lineStart:t,lineEnd:n,showDeleted:f,autoFetch:r}),C=t!==void 0&&n!==void 0,w=(0,G.useCallback)(async(e,t,n)=>{if(n){g(n=>new Map(n).set(e,t));try{await n(e)}finally{g(t=>{let n=new Map(t);return n.delete(e),n})}}},[]);if((0,G.useEffect)(()=>{p(!1)},[e]),!r)return null;let T=_,E=T?.totalCount??0;return(0,K.jsxs)(`aside`,{className:`flex h-full min-h-0 w-full flex-col border-l border-border/70 bg-card/15`,"aria-label":`File memory drawer`,"data-file-path":e??``,children:[(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(o,{className:`size-3`}),(0,K.jsx)(`span`,{className:`truncate font-mono`,title:e??``,children:e??`(no file)`})]}),(0,K.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[E,` memories`]}),T&&T.reviewPendingCount>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono text-warning`,children:[(0,K.jsx)(ee,{className:`size-3`}),T.reviewPendingCount,` pending review`]}),T&&T.supersededCount>0&&(0,K.jsxs)(`span`,{className:`font-mono`,children:[T.supersededCount,` superseded`]})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,K.jsx)(L,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>S(),disabled:v||!e,className:`h-7 w-7 p-0`,"aria-label":`Refresh`,title:`Re-query for this file`,children:(0,K.jsx)(te,{className:P(`size-3.5`,v&&`animate-spin`)})}),(0,K.jsx)(L,{type:`button`,size:`sm`,variant:`ghost`,onClick:i,className:`h-7 w-7 p-0`,"aria-label":`Close drawer`,title:`Close memory drawer`,children:(0,K.jsx)(h,{className:`size-3.5`})})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/40 bg-background/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`size-3 accent-primary`,disabled:!e,"data-testid":`memory-drawer-show-deleted`}),f?(0,K.jsx)(b,{className:`size-3`}):(0,K.jsx)(y,{className:`size-3`}),(0,K.jsx)(`span`,{children:`Show recoverable (deleted)`})]}),C&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 font-mono text-[10px] text-primary`,children:[(0,K.jsx)(A,{className:`size-3`}),` lines `,t,`–`,n]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 py-3`,children:e?v&&!T?(0,K.jsx)(ot,{loading:!0,message:`Loading memories…`}):x?(0,K.jsx)(ot,{tone:`error`,message:`Error: ${x}`}):!T||E===0?(0,K.jsx)(ot,{message:`No memories attached to ${e} yet.`}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(it,{icon:A,title:`Cursor boost`,count:T.symbolMatches.length,cursorBoosted:C,matches:T.symbolMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))}),(0,K.jsx)(it,{icon:o,title:`File-scoped`,count:T.primaryMatches.length,matches:T.primaryMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))}),(0,K.jsx)(it,{icon:b,title:`Mentioned in`,count:T.relatedMatches.length,matches:T.relatedMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))})]}):(0,K.jsx)(ot,{message:`Open a file to see its memories.`})})]})}function ot({message:e,loading:t=!1,tone:n=`default`}){return(0,K.jsxs)(`div`,{className:P(`flex min-h-[120px] flex-col items-center justify-center gap-2 rounded-md border border-dashed border-border/60 px-4 py-6 text-center text-[11px]`,n===`error`?`text-destructive`:`text-muted-foreground`),children:[t&&(0,K.jsx)(c,{className:`size-4 animate-spin`}),(0,K.jsx)(`p`,{children:e})]})}function st({mode:e,draft:r,busy:i,error:a,onChange:o,onCancel:l,onSubmit:u}){let d=(0,G.useRef)(null),[f,p]=(0,G.useState)([]);(0,G.useEffect)(()=>{d.current?.focus();let e=new AbortController;return we(`agent-roster.list`,{},e.signal).then(e=>{let t=e.roles;Array.isArray(t)&&p(t.filter(e=>typeof e==`string`))}).catch(()=>void 0),()=>e.abort()},[]);let m=(e,t)=>{o({...r,[e]:t})},h=()=>{m(`anchors`,[...r.anchors,{type:`file`,path:``}])};return(0,K.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),u()},"aria-busy":i,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/70 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`flex size-8 items-center justify-center border border-info/35 bg-info/10 text-info`,children:e===`create`?(0,K.jsx)(s,{className:`size-4`}):(0,K.jsx)(w,{className:`size-4`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`truncate text-sm font-bold`,children:e===`create`?`Capture a memory`:`Edit memory`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e===`create`?`Add durable knowledge with retrieval metadata.`:`Update content without losing provenance.`})]})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,onClick:l,disabled:i,children:[(0,K.jsx)(E,{className:`size-3.5`}),` Cancel`]}),(0,K.jsxs)(L,{type:`submit`,size:`sm`,disabled:i||!r.text.trim(),children:[i?(0,K.jsx)(c,{className:`size-3.5 animate-spin`}):e===`create`?(0,K.jsx)(le,{className:`size-3.5`}):(0,K.jsx)(k,{className:`size-3.5`}),i?`Saving…`:e===`create`?`Create memory`:`Save changes`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-5`,children:[a&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 border border-destructive/40 bg-destructive/10 px-3 py-2.5 text-sm text-destructive`,children:[(0,K.jsx)(ee,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsx)(`span`,{children:a})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Knowledge`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Write the durable fact or decision in complete, searchable language.`})]}),(0,K.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground tabular-nums`,children:[r.text.length,` chars`]})]}),(0,K.jsx)(`label`,{htmlFor:`memory-text`,className:`sr-only`,children:`Memory content`}),(0,K.jsx)(`textarea`,{ref:d,id:`memory-text`,value:r.text,onChange:e=>m(`text`,e.target.value),rows:7,required:!0,placeholder:`Example: WebUI state is owned by Zustand stores; server messages update those stores through singleton WebSocket handlers.`,className:`min-h-36 w-full resize-y border border-input bg-background/75 px-3 py-3 text-sm leading-6 text-foreground shadow-inner placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-kind`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Kind`}),(0,K.jsx)(`select`,{id:`memory-kind`,value:r.kind,onChange:e=>m(`kind`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:B.map(e=>(0,K.jsx)(`option`,{value:e,children:U[e]},e))})]}),e===`create`?(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-scope`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Scope`}),(0,K.jsx)(`select`,{id:`memory-scope`,value:r.scope,onChange:e=>m(`scope`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:Ee.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}):(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-status`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Lifecycle status`}),(0,K.jsx)(`select`,{id:`memory-status`,value:r.status,onChange:e=>m(`status`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:Me.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}),(0,K.jsxs)(`div`,{className:P(`min-w-0`,e===`create`?`sm:col-span-2 lg:col-span-1`:``),children:[(0,K.jsx)(`label`,{htmlFor:`memory-tags`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Tags`}),(0,K.jsx)(R,{id:`memory-tags`,value:r.tags,onChange:e=>m(`tags`,e.target.value),placeholder:`architecture, webui, workflow`,className:`h-10 bg-background`})]})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,K.jsx)(Oe,{id:`memory-importance`,label:`Importance`,value:r.importance,onChange:e=>m(`importance`,e)}),(0,K.jsx)(Oe,{id:`memory-confidence`,label:`Confidence`,value:r.confidence,onChange:e=>m(`confidence`,e)}),(0,K.jsx)(Oe,{id:`memory-freshness`,label:`Freshness`,value:r.freshness,onChange:e=>m(`freshness`,e)})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Anchors`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Bind knowledge to files, symbols, packages, tests, Git paths, or commands.`})]}),(0,K.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:h,children:[(0,K.jsx)(le,{className:`size-3.5`}),` Add anchor`]})]}),r.anchors.length===0?(0,K.jsxs)(`button`,{type:`button`,onClick:h,className:`mt-4 flex w-full items-center justify-center gap-2 border border-dashed border-border px-4 py-7 text-xs text-muted-foreground transition-colors hover:border-info/50 hover:bg-info/5 hover:text-info`,children:[(0,K.jsx)(t,{className:`size-4`}),` No anchors yet — add one to improve retrieval precision`]}):(0,K.jsx)(`div`,{className:`mt-4 space-y-2`,children:r.anchors.map((e,t)=>(0,K.jsxs)(`div`,{className:`grid gap-2 border border-border/65 bg-background/40 p-2 sm:grid-cols-[9rem_minmax(0,1fr)_auto]`,children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-type-${t}`,children:[`Anchor `,t+1,` type`]}),(0,K.jsx)(`select`,{id:`anchor-type-${t}`,value:e.type,onChange:e=>{let n=e.target.value,i=n===`command`?{type:n,command:``}:n===`agent`?{type:n,role:``}:{type:n,path:``},a=r.anchors.map((e,n)=>n===t?i:e);m(`anchors`,a)},className:`h-10 border border-input bg-background px-2 text-xs`,children:Ie.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))}),(0,K.jsxs)(`div`,{className:P(`grid min-w-0 gap-2`,e.type===`symbol`&&`sm:grid-cols-[minmax(0,1fr)_11rem]`),children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-value-${t}`,children:[`Anchor `,t+1,` value`]}),(0,K.jsx)(R,{id:`anchor-value-${t}`,list:e.type===`agent`?`memory-agent-role-options`:void 0,value:Le(e),onChange:e=>{let n=r.anchors.map((n,r)=>r===t?De(n,e.target.value):n);m(`anchors`,n)},placeholder:e.type===`command`?`pnpm test --filter webui`:e.type===`agent`?`reviewer`:`packages/webui/src/App.tsx`,className:`h-10 min-w-0 bg-background font-mono text-xs`}),e.type===`symbol`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-symbol-${t}`,children:[`Anchor `,t+1,` symbol`]}),(0,K.jsx)(R,{id:`anchor-symbol-${t}`,value:e.symbol??``,onChange:e=>{let n=r.anchors.map((n,r)=>r===t?{...n,symbol:e.target.value}:n);m(`anchors`,n)},placeholder:`Symbol name`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove anchor ${t+1}`,onClick:()=>m(`anchors`,r.anchors.filter((e,n)=>n!==t)),children:(0,K.jsx)(n,{className:`size-4 text-destructive`})})]},`${e.type}:${t}`))}),(0,K.jsx)(`datalist`,{id:`memory-agent-role-options`,children:f.map(e=>(0,K.jsx)(`option`,{value:e},e))})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 border border-border/75 bg-card/45 p-4 sm:grid-cols-2`,children:[(0,K.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Relationships`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Reference exact memory IDs. Relationships are validated and graph edges are rebuilt by SAGE.`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-supersedes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Supersedes`}),(0,K.jsx)(R,{id:`memory-supersedes`,value:r.supersedes,onChange:e=>m(`supersedes`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-contradicts`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Contradicts`}),(0,K.jsx)(R,{id:`memory-contradicts`,value:r.contradicts,onChange:e=>m(`contradicts`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Audience (Optional)`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:`Target this memory to specific agent types. Leave empty for general project memory.`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-roles`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Roles`}),(0,K.jsx)(R,{id:`memory-audience-roles`,value:r.audienceRoles,onChange:e=>m(`audienceRoles`,e.target.value),placeholder:`reviewer, refactor-planner`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-task-types`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Task types`}),(0,K.jsx)(R,{id:`memory-audience-task-types`,value:r.audienceTaskTypes,onChange:e=>m(`audienceTaskTypes`,e.target.value),placeholder:`review, refactor, bugfix`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-modes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Modes`}),(0,K.jsx)(R,{id:`memory-audience-modes`,value:r.audienceModes,onChange:e=>m(`audienceModes`,e.target.value),placeholder:`teach, code-review`,className:`h-9 bg-background font-mono text-xs`})]})]})]})})]})}function ct({searchQuery:e,statusFilter:t,kindFilter:n,audienceOnly:i,tagFilter:o,hasFilters:s,allTags:c,stats:l,onSearchChange:d,onStatusFilterChange:f,onKindFilterChange:p,onToggleAudienceOnly:m,onTagFilterChange:h,onClearFilters:g}){let[v,y]=(0,G.useState)(!!o),b=v||!!o,x=c.length>0;return(0,K.jsxs)(`div`,{className:`shrink-0 space-y-2 overflow-hidden border-b border-border/70 bg-card/45 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(S,{className:`pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,K.jsx)(R,{"aria-label":`Search memories`,value:e,onChange:e=>d(e.target.value),placeholder:`Search content, IDs, tags, anchors…`,className:`h-10 min-w-0 bg-background pl-9 pr-8 text-xs`}),e&&(0,K.jsx)(`button`,{type:`button`,"aria-label":`Clear search`,onClick:()=>d(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground`,children:(0,K.jsx)(E,{className:`size-3.5`})})]}),(0,K.jsx)(L,{variant:i?`default`:`ghost`,size:`icon`,onClick:m,"aria-label":`Filter audience-scoped only`,title:`Show only audience-scoped memories`,className:`shrink-0`,children:(0,K.jsx)(a,{className:`size-4`})}),s&&(0,K.jsx)(L,{variant:`ghost`,size:`icon`,onClick:g,"aria-label":`Clear all filters`,title:`Clear all filters`,children:(0,K.jsx)(_,{className:`size-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-status-filter`,children:`Filter by status`}),(0,K.jsxs)(`select`,{id:`memory-status-filter`,value:t,onChange:e=>f(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All statuses`}),Ne.map(e=>(0,K.jsxs)(`option`,{value:e,children:[e,` · `,l?.byStatus[e]??0]},e))]}),(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-kind-filter`,children:`Filter by kind`}),(0,K.jsxs)(`select`,{id:`memory-kind-filter`,value:n,onChange:e=>p(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All kinds`}),B.map(e=>(0,K.jsxs)(`option`,{value:e,children:[U[e],` · `,l?.byKind[e]??0]},e))]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o||y(e=>!e)},"aria-expanded":b,"aria-controls":`memory-tags-panel`,disabled:!!o,className:P(`flex items-center gap-1.5 px-1 py-0.5 text-[10px] uppercase tracking-wide transition-colors`,b?`text-foreground`:`text-muted-foreground hover:text-foreground`,!!o&&`cursor-default`),title:o?`Active filter: ${o} (click the chip to clear)`:b?`Hide tag filters`:`Show tag filters (${c.length})`,children:[(0,K.jsx)(u,{className:P(`size-3 transition-transform`,!b&&`-rotate-90`)}),(0,K.jsx)(r,{className:`size-3`}),(0,K.jsx)(`span`,{className:`font-semibold`,children:`Tags`}),(0,K.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:c.length})]}),o&&(0,K.jsx)(`span`,{"aria-label":`Active tag filter: ${o}`,className:`border border-info/55 bg-info/10 px-1 font-mono text-[9px] uppercase text-info`,children:o})]}),x&&b&&(0,K.jsxs)(`fieldset`,{id:`memory-tags-panel`,className:`min-w-0 border-0 p-0`,children:[(0,K.jsx)(`legend`,{className:`sr-only`,children:`Popular tags`}),(0,K.jsx)(`div`,{className:`no-scrollbar flex gap-1.5 overflow-x-auto pb-0.5`,children:c.slice(0,18).map(([e,t])=>(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":o===e,onClick:()=>h(o===e?null:e),className:P(`flex shrink-0 items-center gap-1 border px-2 py-1 text-[10px] transition-colors`,o===e?`border-info/55 bg-info/10 text-info`:`border-border/70 bg-background/45 text-muted-foreground hover:border-info/35 hover:text-foreground`),children:[(0,K.jsx)(r,{className:`size-2.5`}),` `,e,(0,K.jsx)(`span`,{className:`font-mono opacity-60`,children:t})]},e))})]})]})}var lt=100;function ut({memoryListRef:e,memories:t,filteredMemories:n,selectedId:r,onSelectMemory:i,onOpenCreate:a,onClearFilters:o}){let s=n.length>lt,c=se({count:n.length,getScrollElement:()=>e.current,estimateSize:()=>100,overscan:8,enabled:s});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/60 px-3 py-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{children:[n.length,` of `,t.length,` memories`]}),(0,K.jsx)(`span`,{className:`font-mono uppercase`,children:`updated ↓`})]}),(0,K.jsx)(`section`,{ref:e,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"aria-label":`Memories`,children:n.length===0?(0,K.jsx)(dt,{hasMemories:t.length>0,onOpenCreate:a,onClearFilters:o}):s?(0,K.jsx)(`div`,{style:{height:`${c.getTotalSize()}px`,width:`100%`,position:`relative`},children:c.getVirtualItems().map(e=>{let t=n[e.index];return t?(0,K.jsx)(`div`,{"data-index":e.index,ref:c.measureElement,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`},children:(0,K.jsx)(ft,{memory:t,isSelected:r===t.id,onClick:()=>i(t.id)})},t.id):null})}):n.map(e=>(0,K.jsx)(ft,{memory:e,isSelected:r===e.id,onClick:()=>i(e.id)},e.id))})]})}function dt({hasMemories:e,onOpenCreate:t,onClearFilters:n}){return(0,K.jsxs)(`div`,{className:`flex min-h-64 flex-col items-center justify-center px-6 text-center`,children:[(0,K.jsx)(`span`,{className:`flex size-12 items-center justify-center border border-dashed border-border text-muted-foreground`,children:(0,K.jsx)(ae,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-sm font-bold`,children:e?`No matching memories`:`Build your memory graph`}),(0,K.jsx)(`p`,{className:`mt-1 max-w-xs text-xs leading-5 text-muted-foreground`,children:e?`Change the filters or clear the search query.`:`Capture durable facts, decisions, conventions, and file-bound notes for every agent.`}),(0,K.jsxs)(L,{className:`mt-4`,variant:`outline`,size:`sm`,onClick:e?n:t,children:[e?(0,K.jsx)(_,{className:`size-3.5`}):(0,K.jsx)(le,{className:`size-3.5`}),e?`Clear filters`:`Create first memory`]})]})}function ft({memory:e,isSelected:t,onClick:n}){return(0,K.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:P(`group relative block w-full border-b border-border/55 px-3 py-3 text-left transition-[background-color,border-color] hover:bg-info/5`,t&&`bg-info/8`),children:[t&&(0,K.jsx)(`span`,{className:`absolute inset-y-0 left-0 w-0.5 bg-info shadow-[0_0_10px_hsl(var(--info)/0.7)]`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:P(`truncate text-[10px] font-bold uppercase tracking-[0.1em]`,je(e.kind)),children:U[e.kind]??e.kind}),(0,K.jsx)(V,{status:e.status}),(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`r`,e.revision]})]}),(0,K.jsx)(`p`,{className:P(`mt-2 line-clamp-2 text-xs leading-5 text-foreground/90`,e.status===`deleted`&&`line-through opacity-60`),children:z(e.text)}),(0,K.jsxs)(`div`,{className:`mt-2 flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`border border-border/60 bg-background/50 px-1.5 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 border border-primary/30 bg-primary/10 px-1.5 py-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(a,{className:`size-2.5`}),(e.audience.roles??e.audience.taskTypes??e.audience.modes??[]).slice(0,1)[0]??`scoped`]}),e.tags.slice(0,2).map(e=>(0,K.jsxs)(`span`,{className:`max-w-24 truncate border border-border/60 px-1.5 py-0.5 font-mono text-[9px] text-muted-foreground`,children:[`#`,e]},e)),e.tags.length>2&&(0,K.jsxs)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:[`+`,e.tags.length-2]}),(0,K.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:Re(e.updatedAt)}),(0,K.jsx)(i,{className:`size-3 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-info`})]})]})}function pt({busyAction:e,deletingId:t,memories:r,onCancel:i,onConfirm:a,onOpenChange:o}){return(0,K.jsx)(I,{open:!!t,onOpenChange:o,children:(0,K.jsxs)(ye,{className:`max-w-md`,children:[(0,K.jsxs)(_e,{children:[(0,K.jsx)(`span`,{className:`mb-2 flex size-10 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(n,{className:`size-4`})}),(0,K.jsx)(be,{children:`Delete this memory?`}),(0,K.jsx)(F,{className:`leading-6`,children:`SAGE will mark the record deleted, remove graph edges, and clean references from related memories. The record remains in the audit trail but cannot be restored from this page.`})]}),(0,K.jsx)(`div`,{className:`border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:z(r.find(e=>e.id===t)?.text??``,180)}),(0,K.jsxs)(ve,{children:[(0,K.jsx)(L,{variant:`outline`,onClick:i,disabled:e===`delete`,children:`Cancel`}),(0,K.jsxs)(L,{variant:`destructive`,onClick:a,disabled:e===`delete`,children:[e===`delete`?(0,K.jsx)(c,{className:`size-4 animate-spin`}):(0,K.jsx)(n,{className:`size-4`}),e===`delete`?`Deleting…`:`Delete memory`]})]})]})})}function mt({onCapture:e}){return(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center p-8 text-center`,children:[(0,K.jsxs)(`div`,{className:`relative flex size-20 items-center justify-center border border-info/25 bg-info/5 text-info`,children:[(0,K.jsx)(a,{className:`size-8`}),(0,K.jsx)(`span`,{className:`absolute inset-2 border border-info/10`})]}),(0,K.jsx)(`h2`,{className:`mt-5 text-lg font-bold`,children:`Your project’s long-term context`}),(0,K.jsx)(`p`,{className:`mt-2 max-w-md text-sm leading-6 text-muted-foreground`,children:`Select a memory to inspect its metadata and relationship graph, or capture knowledge that future agents should retrieve automatically.`}),(0,K.jsxs)(`div`,{className:`mt-6 grid w-full max-w-lg gap-2 sm:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(m,{className:`mx-auto size-4 text-success`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Verified anchors`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(a,{className:`mx-auto size-4 text-info`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Typed relations`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(le,{className:`mx-auto size-4 text-warning`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Agent recall`})]})]}),(0,K.jsxs)(L,{onClick:e,children:[(0,K.jsx)(le,{className:`size-4`}),` Capture memory`]})]})}function ht(e,t){let n=t.searchQuery.trim().toLowerCase();return e.filter(e=>{if(t.statusFilter!==`all`&&e.status!==t.statusFilter||t.kindFilter!==`all`&&e.kind!==t.kindFilter||t.tagFilter&&!e.tags.includes(t.tagFilter)||t.audienceOnly&&!e.audience)return!1;if(!n)return!0;let r=e.anchors.map(e=>[e.path,e.symbol,e.command,e.role].filter(Boolean).join(` `)).join(` `),i=e.audience?[e.audience.roles?.join(` `)??``,e.audience.taskTypes?.join(` `)??``,e.audience.modes?.join(` `)??``].join(` `):``;return[e.id,e.text,e.summary??``,e.kind,e.scope,e.tags.join(` `),r,i].join(` `).toLowerCase().includes(n)})}function gt(e){let t=new Map;for(let n of e)for(let e of n.tags)t.set(e,(t.get(e)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))}function _t(e){if(!e)return[];let t=[];e.supersededBy&&t.push({relation:`Superseded by`,id:e.supersededBy});for(let n of e.supersedes??[])t.push({relation:`Supersedes`,id:n});for(let n of e.contradicts??[])t.push({relation:`Contradicts`,id:n});return t}function vt(){let{client:e,listSageMemoriesPage:t,rememberSage:n,updateSage:r,deleteSage:i,getSageGraph:o,recoverSage:s,resolveMemoryCandidate:c}=he(),l=ge(e=>e.wsConnected),u=me(e=>e.setCurrentView),d=xe(`memory`),[f,p]=(0,G.useState)([]),[h,_]=(0,G.useState)(null),[v,y]=(0,G.useState)(!0),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(null),[w,T]=(0,G.useState)(null),[E,D]=(0,G.useState)(null),[O,k]=(0,G.useState)(null),[ne,re]=(0,G.useState)([]),[A,ie]=(0,G.useState)([]),[ae,oe]=(0,G.useState)(null),[se,ue]=(0,G.useState)(!1),[j,M]=(0,G.useState)(!1),[de,fe]=(0,G.useState)(!1),[N,_e]=(0,G.useState)(Ae),[ve,ye]=(0,G.useState)(Ae),[be,F]=(0,G.useState)(null),[I,R]=(0,G.useState)(null),[Se,Ce]=(0,G.useState)(``),[we,Ee]=(0,G.useState)(`all`),[De,Oe]=(0,G.useState)(`all`),[z,je]=(0,G.useState)(!1),[B,V]=(0,G.useState)(null),[H,Me]=(0,G.useState)(!1),[Ne,Pe]=(0,G.useState)(null),[U,Ie]=(0,G.useState)(!1),[Le,Re]=(0,G.useState)(!1),[ze,Be]=(0,G.useState)({}),[Ve,He]=(0,G.useState)(!1),[Ue,We]=(0,G.useState)(null),[Ge,Ke]=(0,G.useState)(void 0),[qe,Je]=(0,G.useState)(void 0),Ye=(0,G.useRef)(!1),q=(0,G.useRef)(!0),Ze=(0,G.useRef)(0),J=(0,G.useRef)(0),Qe=(0,G.useRef)(null),Y=(0,G.useRef)(null),$e=(0,G.useMemo)(()=>JSON.stringify(N)!==JSON.stringify(ve),[ve,N]),X=(0,G.useMemo)(()=>f.find(e=>e.id===O)??null,[f,O]),et=(0,G.useCallback)(n=>{let r=n!==null,i=++Ze.current;Qe.current?.(),C(null),r?Re(!0):(x(!0),Ye.current||y(!0));let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Qe.current===c&&(Qe.current=null))};a=e.on(`memory.sage.listPage`,e=>{if(i!==Ze.current||!q.current){c();return}if(c(),e.payload.error)C(e.payload.error);else{let t=e.payload.memories??[];p(e=>r?[...e,...t]:t),Pe(e.payload.nextCursor??null),Ie(!!e.payload.nextCursor);let n=e.payload.statusCounts??{};Be(n);let i=Object.values(n).reduce((e,t)=>e+t,0);e.payload.stats?_(e.payload.stats):_(e=>({total:i,byStatus:n,byKind:e?.byKind??{},edges:e?.edges??0})),Ye.current=!0,r||k(e=>e&&t.some(t=>t.id===e)?e:null)}y(!1),x(!1),Re(!1)}),o=setTimeout(()=>{i!==Ze.current||!q.current||(c(),C(`The memory store did not respond. Check the WebSocket connection and try again.`),y(!1),x(!1),Re(!1))},2e4),Qe.current=c,t({limit:100,...H?{statuses:[`deleted`]}:{},...n?{cursor:n}:{}},{echoToChat:!1})},[e,t,H]),Z=(0,G.useCallback)(()=>{Pe(null),Ie(!1),et(null)},[et]),tt=(0,G.useCallback)(()=>{Le||!Ne||et(Ne)},[et,Le,Ne]);(0,G.useEffect)(()=>(q.current=!0,Z(),()=>{q.current=!1,Ze.current+=1,J.current+=1,Qe.current?.(),Y.current?.()}),[Z]),(0,G.useEffect)(()=>{if(re([]),ie([]),oe(null),!O){ue(!1);return}let t=O;ue(!0);let n=null,r=e.on(`memory.sage.graph`,e=>{e.payload.query===t&&(n!==null&&clearTimeout(n),re(e.payload.edges??[]),ie(e.payload.memories??[]),oe(e.payload.error??null),ue(!1))});return n=setTimeout(()=>{oe(`Relationship graph did not respond in time.`),ue(!1)},15e3),o(t,{maxDepth:1,limit:120},{echoToChat:!1}),()=>{n!==null&&clearTimeout(n),r()}},[e,o,O]);let nt=(0,G.useRef)(l);(0,G.useEffect)(()=>{l&&!nt.current&&Ye.current&&Z(),nt.current=l},[Z,l]),(0,G.useEffect)(()=>{if(!E)return;let e=setTimeout(()=>D(null),4e3);return()=>clearTimeout(e)},[E]);let Q=(0,G.useCallback)(()=>!$e||!j&&!de||window.confirm(`Discard the unsaved memory changes?`),[de,$e,j]),rt=(0,G.useCallback)(()=>{if(!Q())return;let e=Ae();_e(e),ye(e),fe(!0),M(!1),k(null),T(null)},[Q]),it=(0,G.useCallback)(e=>{Q()&&(k(e),fe(!1),M(!1),T(null))},[Q]),ot=(0,G.useCallback)(()=>{if(!X||X.status===`deleted`)return;let e=ke(X);_e(e),ye(e),M(!0),fe(!1),T(null)},[X]),lt=(0,G.useCallback)(()=>{Q()&&(M(!1),fe(!1),T(null))},[Q]),dt=(0,G.useCallback)((t,n,r)=>{if(!N.text.trim()){T(`Memory content is required.`);return}let i=++J.current;Y.current?.(),F(r),T(null),D(null);let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Y.current===c&&(Y.current=null))},l=e=>{if(i!==J.current||!q.current){c();return}if(c(),F(null),e.payload.error||!e.payload.memory){T(e.payload.error??`The server returned no memory record.`);return}let t=e.payload.memory;p(e=>{let n=e.filter(e=>e.id!==t.id);return[t,...n]}),k(t.id),fe(!1),M(!1),D(r===`create`?`Memory captured.`:`Memory updated.`),Z()};a=t===`memory.sage.remember`?e.on(`memory.sage.remember`,l):e.on(`memory.sage.update`,l),o=setTimeout(()=>{i!==J.current||!q.current||(c(),F(null),T(`${r===`create`?`Create`:`Save`} timed out. Your draft is still here.`))},2e4),Y.current=c,n()},[e,N.text,Z]),ft=(0,G.useCallback)(()=>{dt(`memory.sage.remember`,()=>n({text:N.text.trim(),kind:N.kind,scope:N.scope,tags:W(N.tags),importance:N.importance,confidence:N.confidence,freshness:N.freshness,anchors:Te(N.anchors),...W(N.audienceRoles).length||W(N.audienceTaskTypes).length||W(N.audienceModes).length?{audience:{roles:W(N.audienceRoles),taskTypes:W(N.audienceTaskTypes),modes:W(N.audienceModes)}}:{},supersedes:W(N.supersedes),contradicts:W(N.contradicts)},{echoToChat:!1}),`create`)},[N,n,dt]),vt=(0,G.useCallback)(()=>{X&&dt(`memory.sage.update`,()=>r(X.id,{text:N.text.trim(),kind:N.kind,status:N.status,tags:W(N.tags),importance:N.importance,confidence:N.confidence,freshness:N.freshness,anchors:Te(N.anchors),...W(N.audienceRoles).length||W(N.audienceTaskTypes).length||W(N.audienceModes).length?{audience:{roles:W(N.audienceRoles),taskTypes:W(N.audienceTaskTypes),modes:W(N.audienceModes)}}:{},supersedes:W(N.supersedes),contradicts:W(N.contradicts)},{echoToChat:!1}),`update`)},[N,dt,X,r]),yt=(0,G.useCallback)(()=>{if(!I)return;let t=++J.current;Y.current?.(),F(`delete`),T(null);let n=()=>{},r=null,a=!1,o=()=>{a||(a=!0,r!==null&&clearTimeout(r),n(),Y.current===o&&(Y.current=null))};n=e.on(`memory.sage.delete`,e=>{if(t!==J.current||!q.current){o();return}if(o(),F(null),!e.payload.success){T(e.payload.message||`Delete failed.`);return}R(null),k(null),M(!1),D(`Memory deleted and relationship edges cleaned up.`),Z()}),r=setTimeout(()=>{t!==J.current||!q.current||(o(),F(null),T(`Delete timed out. The memory may still exist; refresh to confirm.`))},2e4),Y.current=o,i(I,`Deleted from the WebUI Memory Manager.`)},[e,i,I,Z]),bt=(0,G.useMemo)(()=>ht(f,{searchQuery:Se,statusFilter:we,kindFilter:De,tagFilter:B,audienceOnly:z}),[z,De,f,Se,we,B]),xt=(0,G.useMemo)(()=>gt(f),[f]),St=(0,G.useMemo)(()=>_t(X),[X]),Ct=(0,G.useCallback)(()=>{Ce(``),Ee(`all`),Oe(`all`),je(!1),V(null)},[]),wt=!!(Se||we!==`all`||De!==`all`||B||z),Tt=de||!!X,$=Ve&&!!Ue;return v&&f.length===0?(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-busy":`true`,children:[(0,K.jsxs)(`div`,{className:`border-b border-border/70 bg-card/70 px-5 py-4`,children:[(0,K.jsx)(`div`,{className:`h-3 w-28 animate-pulse bg-muted`}),(0,K.jsx)(`div`,{className:`mt-3 h-7 w-56 animate-pulse bg-muted`})]}),(0,K.jsxs)(`div`,{className:`grid flex-1 gap-px bg-border/60 md:grid-cols-[minmax(300px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsx)(`div`,{className:`space-y-px bg-background p-4`,children:Array.from({length:7},(e,t)=>(0,K.jsx)(`div`,{className:`h-24 animate-pulse border border-border/60 bg-card/45`},t))}),(0,K.jsx)(`div`,{className:`hidden bg-background p-6 md:block`,children:(0,K.jsx)(`div`,{className:`h-full animate-pulse border border-border/60 bg-card/35`})})]}),(0,K.jsx)(`span`,{className:`sr-only`,role:`status`,children:`Loading SAGE content`})]}):S&&f.length===0?(0,K.jsx)(`div`,{className:`flex h-full min-h-0 items-center justify-center bg-background p-6`,children:(0,K.jsxs)(`div`,{className:`max-w-md border border-destructive/35 bg-card p-6 shadow-2xl`,children:[(0,K.jsx)(`span`,{className:`flex size-11 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(ee,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-lg font-bold`,children:`Memory store unavailable`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-muted-foreground`,children:S}),(0,K.jsxs)(`div`,{className:`mt-5 flex gap-2`,children:[(0,K.jsxs)(L,{onClick:Z,children:[(0,K.jsx)(te,{className:`size-4`}),` Retry`]}),(0,K.jsxs)(L,{variant:`outline`,onClick:()=>u(`chat`),children:[(0,K.jsx)(ce,{className:`size-4`}),` Back to chat`]})]})]})}):(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[(0,K.jsxs)(`header`,{className:`relative shrink-0 overflow-hidden border-b border-border/70 bg-card/72 px-4 py-3 backdrop-blur-xl sm:px-5`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 w-1/2 bg-[radial-gradient(circle_at_right,hsl(var(--info)/0.11),transparent_68%)]`}),(0,K.jsxs)(`div`,{className:`relative flex flex-wrap items-center gap-3`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,onClick:()=>u(`chat`),"aria-label":`Back to chat`,title:`Back to chat`,children:(0,K.jsx)(ce,{className:`size-4`})}),(0,K.jsx)(`span`,{className:`flex size-10 items-center justify-center border border-info/40 bg-info/10 text-info shadow-[0_0_20px_hsl(var(--info)/0.12)]`,children:(0,K.jsx)(a,{className:`size-5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`h1`,{className:`text-base font-bold sm:text-lg`,children:`SAGE`}),(0,K.jsx)(`span`,{className:`border border-success/35 bg-success/10 px-2 py-0.5 font-mono text-[9px] font-bold uppercase text-success`,children:`project knowledge`})]}),(0,K.jsx)(`p`,{className:`mt-0.5 max-w-2xl text-[10px] text-muted-foreground sm:text-xs`,children:`Inspect, connect, curate, and retire durable context used across agent sessions.`})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:P(`hidden items-center gap-1.5 border px-2 py-1 font-mono text-[9px] uppercase sm:flex`,l?`border-success/30 text-success`:`border-warning/30 text-warning`),children:[(0,K.jsx)(`span`,{className:`size-1.5 bg-current`}),` `,l?`live store`:`reconnecting`]}),(0,K.jsxs)(L,{variant:`outline`,size:`sm`,onClick:Z,disabled:b,"aria-label":`Refresh memories`,children:[(0,K.jsx)(te,{className:P(`size-3.5`,b&&`animate-spin`)}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),(0,K.jsxs)(L,{size:`sm`,onClick:rt,children:[(0,K.jsx)(le,{className:`size-3.5`}),` New memory`]})]})]})]}),(0,K.jsxs)(`div`,{className:`grid shrink-0 grid-cols-2 gap-px border-b border-border/70 bg-border/60 sm:grid-cols-4`,children:[(0,K.jsx)(Fe,{label:`Memories`,value:h?.total??f.length,hint:`${bt.length} visible`}),(0,K.jsx)(Fe,{label:`Active`,value:h?.byStatus.active??f.filter(e=>e.status===`active`).length,hint:`retrievable`,tone:`success`}),(0,K.jsx)(Fe,{label:`Needs review`,value:(h?.byStatus.stale??0)+(h?.byStatus.contradicted??0),hint:`stale + conflicts`,tone:`warning`}),(0,K.jsx)(`div`,{className:`hidden sm:block`,children:(0,K.jsx)(Fe,{label:`Graph edges`,value:h?.edges??0,hint:`${xt.length} tags`,tone:`info`})})]}),(()=>{let e=f.filter(e=>e.audience).length;if(e===0)return null;let t=new Set;for(let e of f)if(e.audience){for(let n of e.audience.roles??[])t.add(n);for(let n of e.audience.taskTypes??[])t.add(n);for(let n of e.audience.modes??[])t.add(n)}return(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/70 bg-primary/5 px-4 py-1.5`,children:[(0,K.jsx)(a,{className:`size-3.5 text-primary`}),(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-primary`,children:[e,` audience-scoped memory`,e===1?``:`ies`]}),t.size>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,[...t].sort().join(`, `),`)`]})]})})(),(E||S||w)&&(0,K.jsxs)(`div`,{className:`shrink-0 border-b border-border/70 px-4 py-2`,"aria-live":`polite`,children:[E&&(0,K.jsxs)(`div`,{role:`status`,className:`flex items-center gap-2 text-xs text-success`,children:[(0,K.jsx)(m,{className:`size-3.5`}),` `,E]}),S&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-warning`,children:[(0,K.jsx)(ee,{className:`size-3.5`}),` `,S,` Existing content remains available.`]}),w&&!j&&!de&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-destructive`,children:[(0,K.jsx)(ee,{className:`size-3.5`}),` `,w]})]}),(0,K.jsxs)(`div`,{className:`grid min-h-0 flex-1 md:grid-cols-[minmax(320px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsxs)(`section`,{className:P(`min-h-0 border-r border-border/70 bg-card/25`,Tt?`hidden md:flex md:flex-col`:`flex flex-col`),"aria-label":`Memory library`,children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-3 pt-1`,role:`tablist`,"aria-label":`Memory view`,children:[(0,K.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":!H,onClick:()=>{H&&Me(!1)},className:P(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,H?`border-transparent text-muted-foreground`:`border-primary text-foreground`),children:`Active`}),(0,K.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":H,onClick:()=>{H||Me(!0)},className:P(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,H?`border-primary text-foreground`:`border-transparent text-muted-foreground`),children:[`Deleted`,typeof ze.deleted==`number`?` (${ze.deleted})`:``]})]}),(0,K.jsx)(ct,{searchQuery:Se,statusFilter:we,kindFilter:De,audienceOnly:z,tagFilter:B,hasFilters:wt,allTags:xt,stats:h,onSearchChange:Ce,onStatusFilterChange:Ee,onKindFilterChange:Oe,onToggleAudienceOnly:()=>je(e=>!e),onTagFilterChange:V,onClearFilters:Ct}),(0,K.jsx)(ut,{memoryListRef:d,memories:f,filteredMemories:bt,selectedId:O,onSelectMemory:it,onOpenCreate:rt,onClearFilters:Ct}),U?(0,K.jsx)(`div`,{className:`shrink-0 border-t border-border/60 p-2`,children:(0,K.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:tt,disabled:Le,className:`h-7 w-full text-[11px]`,children:Le?`Loading…`:`Load more (${f.length} loaded)`})}):null]}),(0,K.jsxs)(`section`,{className:P(`min-h-0 bg-background`,Tt?`flex flex-col`:`hidden md:flex md:flex-col`),"aria-label":`Memory detail`,children:[f.some(e=>(e.anchors??[]).some(e=>e.type===`file`&&e.path))&&(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/60 bg-card/30 px-3 py-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:`File drawer`}),(0,K.jsxs)(`select`,{value:Ue??``,onChange:e=>{let t=e.target.value||null;We(t),t&&He(!0)},className:`min-w-0 max-w-[260px] flex-1 truncate rounded-sm border border-border/60 bg-background px-1.5 py-0.5 text-[10px] font-mono`,"aria-label":`File for memory drawer`,"data-testid":`memory-drawer-file-select`,children:[(0,K.jsx)(`option`,{value:``,children:`— select a file —`}),f.flatMap(e=>e.anchors??[]).filter(e=>e.type===`file`&&e.path).map((e,t)=>(0,K.jsx)(`option`,{value:e.path,title:e.path,children:e.path},`${e.path}-${t}`))]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:$?`default`:`outline`,onClick:()=>{Ue&&He(e=>!e)},disabled:!Ue,className:`h-7 shrink-0 gap-1 px-2 text-[11px]`,"aria-pressed":$,title:$?`Hide file memory drawer`:`Show file memory drawer`,children:[$?(0,K.jsx)(g,{className:`size-3`}):(0,K.jsx)(pe,{className:`size-3`}),$?`Hide`:`Show`,` drawer`]})]}),de?(0,K.jsx)(st,{mode:`create`,draft:N,busy:be===`create`,error:w,onChange:_e,onCancel:lt,onSubmit:ft}):X?j?(0,K.jsx)(st,{mode:`edit`,draft:N,busy:be===`update`,error:w,onChange:_e,onCancel:lt,onSubmit:vt}):$?(0,K.jsx)(at,{filePath:Ue,lineStart:Ge,lineEnd:qe,open:$,onClose:()=>He(!1),onShowMemory:e=>k(e),onAcceptDeletion:async(e,t)=>{c({candidateId:e,action:`accept`}),D(`Accepted hygiene review for ${t.slice(0,12)}… (candidate ${e.slice(0,12)}…).`),setTimeout(()=>{Z()},500)},onKeep:async(e,t)=>{c({candidateId:e,action:`reject`}),D(`Kept ${t.slice(0,12)}… (candidate ${e.slice(0,12)}… rejected).`)},onUpdate:e=>{k(e),ot()},onMarkPermanent:async e=>{F(`update`);try{await r(e,{persistence:`permanent`}),D(`Memory ${e.slice(0,12)}… promoted to permanent.`),await Z()}catch(e){T(e instanceof Error?e.message:String(e))}finally{F(null)}},onRecover:async e=>{s({id:e,reason:`recovered via file drawer`}),D(`Recovered ${e.slice(0,12)}…`),setTimeout(()=>{Z()},500)}}):(0,K.jsx)(Xe,{memory:X,allMemories:[...f,...A],relatedMemories:St,graphEdges:ne,graphLoading:se,graphError:ae,onClose:()=>k(null),onOpenMemory:it,onEdit:ot,onDelete:()=>R(X.id),onTagSelect:e=>{V(e),k(null)},onNotice:D}):(0,K.jsx)(mt,{onCapture:rt})]})]}),(0,K.jsx)(pt,{busyAction:be,deletingId:I,memories:f,onCancel:()=>R(null),onConfirm:yt,onOpenChange:e=>{!e&&be!==`delete`&&R(null)}})]})}export{vt as MemoryManager};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$n as t,Ct as n,Dt as r,Fi as i,Gi as a,Ir as o,It as s,Kn as c,Kr as l,Li as u,Nt as d,On as f,Qr as p,Ri as m,Si as h,Sn as g,Tr as _,Ut as v,Xr as y,Yr as b,Zi as x,Zt as S,_ as C,_n as w,a as T,at as E,br as D,bt as ee,cn as te,da as O,en as k,et as ne,f as re,hn as A,i as ie,ii as ae,ki as oe,n as se,oa as ce,pn as le,r as ue,s as j,vi as M,vr as de,xa as fe,xn as pe}from"./vendor-9hC4n4Me.js";import{n as me}from"./ui-store-BI3LH2q8.js";import{t as he}from"./useWebSocket-Ba38Sknk.js";import{t as N}from"./ws-client-eyEv8wbm.js";import{t as P}from"./utils-DzRQUvln.js";import{M as ge}from"./stores-hEu6z1qz.js";import{a as _e,i as ve,n as ye,o as be,r as F,t as I}from"./dialog-BLr7olIX.js";import{t as L}from"./button-Bmh1yFe5.js";import{t as R}from"./input-BRS2rHSR.js";import{b as xe,f as Se,p as Ce}from"./index-DSXHr5yP.js";import{t as we}from"./roster-ws-CVCrt_ih.js";import{_ as Te,a as Ee,b as De,c as Oe,d as ke,f as Ae,g as z,h as je,i as B,l as V,m as H,n as Me,o as Ne,p as Pe,r as U,s as Fe,t as Ie,u as Le,v as Re,y as W}from"./shared-DYL4K3aB.js";var G=e(fe(),1),K=ne(),ze=212,Be=188;function Ve(e){return e.length>14?`${e.slice(0,11)}…`:e}function He(e,t=58){let n=e.replace(/\s+/g,` `).trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function Ue(e){return e.type===`symbol`?[e.path,e.symbol?`#${e.symbol}`:``].filter(Boolean).join(``):e.path??e.command??e.symbol??e.role??e.type}function We(e){return e===`active`?`border-success/45 bg-success/10 text-success`:e===`stale`?`border-warning/45 bg-warning/10 text-warning`:e===`contradicted`?`border-destructive/45 bg-destructive/10 text-destructive`:e===`superseded`?`border-warning/35 bg-warning/5 text-warning`:`border-border bg-muted/55 text-muted-foreground`}function Ge({data:e}){let{entry:t,center:n}=e;return(0,K.jsxs)(`div`,{className:n?`border border-primary/70 bg-card px-3 py-2.5 text-card-foreground shadow-[0_0_0_1px_hsl(var(--primary)/0.2),0_0_24px_hsl(var(--primary)/0.12)]`:`border border-border/80 bg-card/95 px-3 py-2.5 text-card-foreground shadow-lg`,style:{width:ze},title:t.text,children:[(0,K.jsx)(j,{type:`target`,position:C.Top,className:`!border-background !bg-muted-foreground`}),(0,K.jsx)(j,{type:`source`,position:C.Bottom,className:`!border-background !bg-primary`}),(0,K.jsx)(j,{type:`source`,position:C.Right,className:`!border-background !bg-primary`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`border px-1.5 py-0.5 text-[9px] font-bold uppercase ${We(t.status)}`,children:t.status}),(0,K.jsx)(`span`,{className:`ml-auto truncate font-mono text-[9px] text-muted-foreground`,children:Ve(t.id)})]}),(0,K.jsx)(`p`,{className:`mt-2 line-clamp-2 text-[11px] leading-4 text-foreground/90`,children:He(t.text)}),(0,K.jsx)(`p`,{className:`mt-1 font-mono text-[9px] uppercase text-muted-foreground`,children:t.kind})]})}function Ke({data:e}){return(0,K.jsxs)(`div`,{className:`border border-info/40 bg-info/8 px-2.5 py-2 text-card-foreground shadow-lg`,style:{width:Be},title:e.label,children:[(0,K.jsx)(j,{type:`target`,position:C.Left,className:`!border-background !bg-info`}),(0,K.jsx)(`p`,{className:`font-mono text-[9px] font-bold uppercase text-info`,children:e.anchor.type}),(0,K.jsx)(`p`,{className:`mt-1 truncate font-mono text-[10px] text-foreground/85`,children:e.label})]})}var qe={memoryNode:Ge,anchorNode:Ke};function Je(e){return{id:e,revision:0,scope:`project`,kind:`fact`,status:`deleted`,text:`Memory is unavailable or has been removed.`,importance:0,confidence:0,freshness:0,tags:[],anchors:[],createdAt:``,updatedAt:``}}function Ye({nodes:e,edges:t,className:n}){return(0,K.jsx)(`div`,{className:P(`w-full`,n),children:(0,K.jsxs)(re,{nodes:e,edges:t,nodeTypes:qe,fitView:!0,fitViewOptions:{padding:.24,maxZoom:1.05},minZoom:.4,maxZoom:1.5,nodesConnectable:!1,elementsSelectable:!1,panOnScroll:!1,zoomOnScroll:!1,proOptions:{hideAttribution:!0},children:[(0,K.jsx)(ue,{variant:ie.Dots,gap:18,size:1,color:`hsl(var(--muted-foreground) / 0.18)`}),(0,K.jsx)(T,{showInteractive:!1,className:`!border-border !bg-card !shadow-lg`})]})})}function q({centerMemory:e,allMemories:t,graphEdges:n,loading:r=!1,error:i=null}){let[a,o]=(0,G.useState)(!1),s=`mem:${e.id}`,c=(0,G.useMemo)(()=>n.filter(e=>e.from===s&&e.to.startsWith(`mem:`)||e.to===s&&e.from.startsWith(`mem:`)).slice(0,24),[s,n]),{nodes:l,edges:u}=(0,G.useMemo)(()=>{let n=[],r=[],i=new Map(t.map(e=>[e.id,e]));n.push({id:e.id,type:`memoryNode`,position:{x:320-ze/2,y:120},data:{entry:e,center:!0}});let a=[...e.supersededBy?[{id:e.supersededBy,relation:`superseded by`}]:[],...(e.supersedes??[]).map(e=>({id:e,relation:`supersedes`})),...(e.contradicts??[]).map(e=>({id:e,relation:`contradicts`}))];for(let e of c){let t=(e.from===s?e.to:e.from).slice(4);a.some(n=>n.id===t&&n.relation===e.relation)||a.push({id:t,relation:e.relation,weight:e.weight,evidence:e.evidence})}let o=320-(a.length-1)*220/2;return a.forEach((t,a)=>{let s=i.get(t.id)??Je(t.id),c=t.relation===`superseded by`,l=c?0:280+Math.floor(a/3)*130,u=c?320-ze/2:o+a*220-ze/2;n.push({id:`memory:${t.id}:${a}`,type:`memoryNode`,position:{x:u,y:l},data:{entry:s,center:!1}});let d=t.relation===`contradicts`,f=c?`memory:${t.id}:${a}`:e.id,p=c?e.id:`memory:${t.id}:${a}`;r.push({id:`relation:${t.relation}:${t.id}:${a}`,source:f,target:p,type:`smoothstep`,animated:!d,label:t.weight===void 0?t.relation:`${t.relation} ${t.weight.toFixed(2)}`,data:{evidence:t.evidence??[]},style:{stroke:d?`hsl(var(--destructive))`:`hsl(var(--primary))`,strokeWidth:1.7,...d?{strokeDasharray:`5 4`}:{}},labelStyle:{fill:d?`hsl(var(--destructive))`:`hsl(var(--muted-foreground))`,fontSize:9,fontWeight:700},labelBgStyle:{fill:`hsl(var(--card))`,fillOpacity:.9}})}),e.anchors.forEach((t,i)=>{let a=`anchor:${i}`;n.push({id:a,type:`anchorNode`,position:{x:540,y:120+(i-(e.anchors.length-1)/2)*66},data:{anchor:t,label:Ue(t)}}),r.push({id:`anchor-edge:${i}`,source:e.id,target:a,type:`smoothstep`,style:{stroke:`hsl(var(--info))`,strokeWidth:1.3}})}),{nodes:n,edges:r}},[t,e,s,c]);return l.length<=1&&!r&&!i?null:(0,K.jsxs)(`section`,{className:`overflow-hidden border border-border/75 bg-background/35`,"aria-label":`Memory relationship graph`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:`Relationship map`}),l.length>1&&(0,K.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:()=>o(!0),className:`h-6 gap-1 px-2 text-[9px] font-bold uppercase tracking-[0.12em]`,"aria-label":`Open full screen graph`,children:[(0,K.jsx)(p,{className:`size-3`}),`Open full screen`]})]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r?`loading real graph…`:`${l.length} nodes · ${u.length} edges`})]}),i&&(0,K.jsx)(`p`,{className:`border-b border-destructive/25 bg-destructive/5 px-3 py-2 text-[10px] text-destructive`,children:i}),l.length>1&&(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[320px]`}),c.some(e=>e.evidence?.length)&&(0,K.jsx)(`div`,{className:`grid gap-1 border-t border-border/70 bg-card/35 px-3 py-2`,children:c.filter(e=>e.evidence?.length).slice(0,12).map(e=>{let t=(e.from===s?e.to:e.from).slice(4);return(0,K.jsxs)(`p`,{className:`truncate font-mono text-[9px] text-muted-foreground`,children:[(0,K.jsx)(`span`,{className:`text-info`,children:e.relation}),` `,Ve(t),` · why:`,` `,e.evidence?.join(`, `)]},e.id)})}),a&&(0,K.jsx)(I,{open:a,onOpenChange:o,children:(0,K.jsxs)(ye,{className:`flex max-h-[90dvh] max-w-[90vw] flex-col p-0`,showCloseButton:!1,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/70 bg-card/55 px-4 py-3`,children:[(0,K.jsxs)(`p`,{className:`text-[10px] font-bold uppercase tracking-[0.16em] text-muted-foreground`,children:[`Relationship map — `,e.id]}),(0,K.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>o(!1),className:`h-7 gap-1 px-2 text-[10px]`,children:`Close`})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 px-4 pb-4`,children:(0,K.jsx)(Ye,{nodes:l,edges:u,className:`h-[65vh]`})})]})})]})}function Xe({memory:e,allMemories:t,relatedMemories:r,graphEdges:i,graphLoading:o,graphError:s,onClose:c,onOpenMemory:l,onEdit:u,onDelete:d,onTagSelect:f,onNotice:p}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/65 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,className:`md:hidden`,onClick:c,"aria-label":`Back to memory list`,children:(0,K.jsx)(ce,{className:`size-4`})}),(0,K.jsx)(`span`,{className:P(`text-[10px] font-bold uppercase tracking-[0.14em]`,je(e.kind)),children:U[e.kind]??e.kind}),(0,K.jsx)(V,{status:e.status}),(0,K.jsx)(`span`,{className:`border border-border/70 px-2 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1 border border-primary/30 bg-primary/10 px-2 py-0.5 font-mono text-[9px] text-primary`,title:Pe(e.audience),children:[(0,K.jsx)(a,{className:`size-3`}),Pe(e.audience)]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,"aria-label":`Copy memory ID`,title:`Copy memory ID`,onClick:()=>{navigator.clipboard?.writeText(e.id),p(`Memory ID copied.`)},children:(0,K.jsx)(M,{className:`size-4`})}),(0,K.jsxs)(L,{variant:`outline`,size:`sm`,onClick:u,disabled:e.status===`deleted`,children:[(0,K.jsx)(w,{className:`size-3.5`}),` Edit`]}),(0,K.jsxs)(L,{variant:`destructive`,size:`sm`,onClick:d,disabled:e.status===`deleted`,children:[(0,K.jsx)(n,{className:`size-3.5`}),` Delete`]})]})]}),(0,K.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-5xl space-y-5`,children:[(0,K.jsx)(Ze,{memory:e}),(0,K.jsx)(J,{memory:e}),e.tags.length>0&&(0,K.jsx)(Qe,{tags:e.tags,onTagSelect:f}),e.anchors.length>0&&(0,K.jsx)(Y,{anchors:e.anchors}),r.length>0&&(0,K.jsx)($e,{relatedMemories:r,allMemories:t,onOpenMemory:l}),(0,K.jsx)(q,{centerMemory:e,allMemories:t,graphEdges:i,loading:o,error:s}),(0,K.jsx)(X,{memory:e}),e.status===`deleted`&&(0,K.jsx)(et,{contextPolicy:e.contextPolicy})]})})]})}function Ze({memory:e}){return(0,K.jsxs)(`div`,{className:`relative overflow-hidden border border-border/75 bg-card/55 p-5 shadow-[inset_0_1px_0_hsl(var(--foreground)/0.04)]`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute -right-10 -top-10 size-36 bg-[radial-gradient(circle,hsl(var(--info)/0.13),transparent_68%)]`}),(0,K.jsx)(`p`,{className:`relative whitespace-pre-wrap text-sm leading-7 text-foreground md:text-[15px]`,children:e.text}),e.summary&&(0,K.jsx)(`p`,{className:`relative mt-4 border-l-2 border-info/50 pl-3 text-xs italic leading-5 text-muted-foreground`,children:e.summary}),(0,K.jsxs)(`div`,{className:`relative mt-5 flex flex-wrap items-center gap-2 border-t border-border/60 pt-3`,children:[(0,K.jsx)(`code`,{className:`min-w-0 break-all font-mono text-[10px] text-muted-foreground`,children:e.id}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-[10px] text-muted-foreground`,children:[`revision `,e.revision]})]})]})}function J({memory:e}){return(0,K.jsx)(`div`,{className:`grid gap-px bg-border/60 sm:grid-cols-3`,children:[[`Importance`,e.importance,v],[`Confidence`,e.confidence,oe],[`Freshness`,e.freshness,te]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/60 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(n,{className:`size-3.5 text-info`}),(0,K.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.13em] text-muted-foreground`,children:e}),(0,K.jsxs)(`span`,{className:`ml-auto font-mono text-xs font-bold tabular-nums`,children:[Math.round(t*100),`%`]})]}),(0,K.jsx)(`div`,{className:`mt-2 h-1 bg-muted`,children:(0,K.jsx)(`div`,{className:`h-full bg-info shadow-[0_0_8px_hsl(var(--info)/0.45)]`,style:{width:`${Math.round(t*100)}%`}})})]},e))})}function Qe({tags:e,onTagSelect:t}){return(0,K.jsxs)(`section`,{children:[(0,K.jsxs)(`h3`,{className:`mb-2 flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(r,{className:`size-3.5 text-info`}),` Tags`]}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,K.jsxs)(`button`,{type:`button`,onClick:()=>t(e),className:`border border-info/25 bg-info/5 px-2 py-1 font-mono text-[10px] text-info hover:border-info/55 hover:bg-info/10`,children:[`#`,e]},e))})]})}function Y({anchors:e}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(l,{className:`size-3.5 text-info`}),` Anchors`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map((e,t)=>(0,K.jsxs)(`li`,{className:`flex min-w-0 items-start gap-3 px-3 py-2.5`,children:[(0,K.jsx)(`span`,{className:`mt-0.5 flex size-7 shrink-0 items-center justify-center border border-info/25 bg-info/5 text-info`,children:e.type===`command`?(0,K.jsx)(d,{className:`size-3.5`}):(0,K.jsx)(l,{className:`size-3.5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`text-[9px] font-bold uppercase text-muted-foreground`,children:e.type}),(0,K.jsxs)(`p`,{className:`mt-0.5 break-all font-mono text-[10px] leading-4 text-foreground/85`,children:[e.path??e.command??e.role??`—`,e.symbol?`#${e.symbol}`:``]})]}),(e.lineStart||e.lineEnd)&&(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`L`,e.lineStart??`?`,`–`,e.lineEnd??`?`]})]},`${e.type}:${e.path??e.command??e.symbol??e.role}:${t}`))})]})}function $e({relatedMemories:e,allMemories:t,onOpenMemory:n}){return(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/40`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border/65 px-3 py-2.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-2 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:[(0,K.jsx)(D,{className:`size-3.5 text-info`}),` Memory relationships`]}),(0,K.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.length})]}),(0,K.jsx)(`ul`,{className:`divide-y divide-border/55`,children:e.map(e=>{let r=t.find(t=>t.id===e.id);return(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&n(r.id),className:`group flex w-full min-w-0 items-center gap-3 px-3 py-2.5 text-left hover:bg-info/5 disabled:cursor-not-allowed disabled:opacity-55`,children:[(0,K.jsx)(`span`,{className:P(`w-24 shrink-0 text-[9px] font-bold uppercase`,e.relation===`Contradicts`?`text-destructive`:`text-info`),children:e.relation}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs`,children:r?z(r.text,95):`Referenced memory is unavailable`}),(0,K.jsx)(`code`,{className:`hidden max-w-32 truncate font-mono text-[9px] text-muted-foreground sm:block`,children:e.id}),r&&(0,K.jsx)(i,{className:`size-3.5 shrink-0 text-muted-foreground group-hover:text-info`})]})},`${e.relation}:${e.id}`)})})]})}function X({memory:e}){return(0,K.jsx)(`section`,{className:`grid gap-px bg-border/60 sm:grid-cols-2 lg:grid-cols-4`,children:[[`Created`,H(e.createdAt),x],[`Updated`,H(e.updatedAt),te],[`Last accessed`,H(e.lastAccessedAt),f],[`Last verified`,H(e.lastVerifiedAt),v]].map(([e,t,n])=>(0,K.jsxs)(`div`,{className:`bg-card/50 p-3`,children:[(0,K.jsx)(n,{className:`size-3.5 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`mt-2 text-[9px] font-bold uppercase tracking-[0.12em] text-muted-foreground`,children:e}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] leading-4 text-foreground/85`,children:t})]},e))})}function et({contextPolicy:e}){return(0,K.jsxs)(`div`,{className:`flex items-start gap-3 border border-border bg-muted/50 p-4 text-xs text-muted-foreground`,children:[(0,K.jsx)(O,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-bold text-foreground`,children:`Deleted memory`}),(0,K.jsx)(`p`,{className:`mt-1 leading-5`,children:e===`never`?`This record is audit-only and carries an absolute ban: it can never enter LLM context.`:`The record is inactive and cannot be edited, but remains eligible as historical evidence when retrieval finds it relevant.`})]})]})}var Z={filePath:``,primaryMatches:[],symbolMatches:[],relatedMatches:[],totalCount:0,activeCount:0,supersededCount:0,reviewPendingCount:0};function tt(e){let{filePath:t,lineStart:n,lineEnd:r,limit:i=50,showSuperseded:a=!0,showDeleted:o=!1,autoFetch:s=!0,sendOptions:c}=e,l=c?JSON.stringify(c):``,[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(null),g=(0,G.useRef)(0),_=(0,G.useRef)(null),v=(0,G.useRef)(c);v.current=c;let y=(0,G.useCallback)(()=>{if(!t){d(null),h(null),p(!1);return}let e=++g.current;p(!0),h(null);let s=N();if(!s){h(`WebSocket client unavailable`),p(!1);return}_.current?.(),_.current=null;let c=t,l=s.on(`memory.sage.forFile`,t=>{if(e!==g.current)return;let n=t.payload.response;n&&n.filePath!==c||(t.payload.error?(h(t.payload.error),d(null)):(d(n??Z),h(null)),p(!1))});_.current=l;let u={filePath:t,limit:i,showSuperseded:a,showDeleted:o,...n===void 0?{}:{lineStart:n},...r===void 0?{}:{lineEnd:r}};try{s.findMemoriesForFile(u,v.current??void 0)}catch(t){l(),_.current===l&&(_.current=null),e===g.current&&(h(t instanceof Error?t.message:String(t)),p(!1))}},[t,n,r,i,a,o]);(0,G.useEffect)(()=>{if(s)return y(),()=>{g.current++,_.current?.(),_.current=null}},[s,y,l]);let b=(0,G.useCallback)(()=>{y()},[y]);return(0,G.useEffect)(()=>()=>{_.current?.(),_.current=null},[]),{data:u,loading:f,error:m,refetch:b}}function nt(e){return e>=.9?`bg-success/15 border-success/40`:e>=.7?`bg-info/15 border-info/40`:e>=.4?`bg-warning/10 border-warning/30`:`bg-muted/30 border-border/40`}function Q(e){switch(e){case`scope_file`:return`scope: file`;case`scope_symbol`:return`scope: symbol`;case`anchor_file`:return`anchor: file`;case`anchor_symbol`:return`anchor: symbol`;case`anchor_directory`:return`anchor: directory`;case`mention`:return`text mention`}}function rt({match:e,cursorBoosted:t,onShowMemory:n,onAcceptDeletion:r,onKeep:i,onUpdate:a,onMarkPermanent:o,onRecover:l,pendingAction:u}){let d=e.memory.status===`deleted`,f=e.memory.status===`superseded`,p=e.pendingReview,h=u!==void 0,g=t===!0;return(0,K.jsxs)(`article`,{className:P(`group relative rounded-md border px-3 py-2 text-sm transition-colors`,nt(e.matchStrength),g&&`ring-1 ring-primary/40 ring-offset-0`,d&&`opacity-70`),"data-match-via":e.matchedVia,"data-memory-id":e.memory.id,children:[(0,K.jsx)(`header`,{className:`flex items-start justify-between gap-2`,children:(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide`,children:[(0,K.jsx)(`span`,{className:P(`font-mono`,je(e.memory.kind)),children:U[e.memory.kind]??e.memory.kind}),(0,K.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:Q(e.matchedVia)}),g&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-primary/15 px-1 py-0.5 font-mono text-primary`,title:`Cursor line range matches this memory's anchor`,children:[(0,K.jsx)(A,{className:`size-2.5`}),` cursor`]}),p&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 rounded-sm bg-warning/15 px-1 py-0.5 font-mono text-warning`,title:`Hygiene review: ${p.reason} (${p.ageDays}d old)`,children:[(0,K.jsx)(ee,{className:`size-2.5`}),` review`]}),d&&(0,K.jsx)(`span`,{className:`font-mono text-destructive`,children:`deleted`}),f&&!d&&(0,K.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:`superseded`})]}),(0,K.jsx)(`p`,{className:`mt-1 text-foreground/90`,children:z(e.memory.text,200)}),(0,K.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(V,{status:e.memory.status}),(0,K.jsxs)(`span`,{children:[`updated `,Re(e.memory.updatedAt)]})]})]})}),(0,K.jsxs)(`footer`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,children:[d&&l&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>l(e.memory.id),className:`h-7 gap-1 border-primary/40 px-2 text-[11px] text-primary hover:bg-primary/10`,title:`Restore this memory to active status (PR #1: memory_recover)`,children:[(0,K.jsx)(te,{className:`size-3`}),` Recover`]}),f&&e.supersededByActiveId&&n&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>n(e.supersededByActiveId),className:`h-7 gap-1 px-2 text-[11px]`,title:`This version is superseded — jump to the active version`,children:[(0,K.jsx)(de,{className:`size-3`}),` Go to active`]}),p&&(0,K.jsxs)(K.Fragment,{children:[p.suggestedAction===`delete`&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`destructive`,disabled:h,onClick:()=>r?.(p.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Accept hygiene's deletion suggestion — memory will be forgotten`,children:[(0,K.jsx)(m,{className:`size-3`}),` Accept Deletion`]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>i?.(p.candidateId,e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Reject the suggestion — memory stays as-is and may be re-suggested later`,children:[(0,K.jsx)(E,{className:`size-3`}),` Keep`]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>a?.(e.memory.id),className:`h-7 gap-1 px-2 text-[11px]`,title:`Update the memory's content — versioning creates a new active record`,children:[(0,K.jsx)(s,{className:`size-3`}),` Update`]}),o&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`outline`,disabled:h,onClick:()=>o(e.memory.id),className:`h-7 gap-1 border-warning/40 px-2 text-[11px] text-warning hover:bg-warning/10`,title:"Promote to `permanent` — hygiene will never surface this again",children:[(0,K.jsx)(A,{className:`size-3`}),` Mark as Permanent`]})]}),n&&!d&&(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:`ghost`,disabled:h,onClick:()=>n(e.memory.id),className:`h-7 gap-1 px-2 text-[11px] text-muted-foreground hover:text-foreground`,title:`Open the full record in MemoryManager`,children:[(0,K.jsx)(b,{className:`size-3`}),` Show full`]}),u&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,K.jsx)(c,{className:`size-3 animate-spin`}),` `,u]})]})]})}function it({icon:e,title:t,count:n,matches:r,cursorBoosted:i=!1,...a}){let o=Ce(r,10);return r.length===0?null:(0,K.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-1.5 px-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(e,{className:`size-3`}),(0,K.jsx)(`span`,{children:t}),(0,K.jsxs)(`span`,{className:`font-mono`,children:[`(`,n,`)`]}),i&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(A,{className:`size-2.5`}),` cursor boost`]})]}),(0,K.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:o.pageItems.map(e=>(0,K.jsx)(rt,{match:e,cursorBoosted:i&&(e.matchedVia===`anchor_symbol`||e.matchedVia===`scope_symbol`),pendingAction:a.pendingActionById.get(e.memory.id),...a},e.memory.id))}),(0,K.jsx)(Se,{page:o.page,pageSize:o.pageSize,totalItems:o.totalItems,onPageChange:o.setPage,compact:!0,itemLabel:`memories`})]})}function at({filePath:e,lineStart:t,lineEnd:n,open:r,onClose:i,onShowMemory:a,onAcceptDeletion:s,onKeep:c,onUpdate:l,onMarkPermanent:u,onRecover:d}){let[f,p]=(0,G.useState)(!1),[m,g]=(0,G.useState)(new Map),{data:_,loading:v,error:x,refetch:S}=tt({filePath:e,lineStart:t,lineEnd:n,showDeleted:f,autoFetch:r}),C=t!==void 0&&n!==void 0,w=(0,G.useCallback)(async(e,t,n)=>{if(n){g(n=>new Map(n).set(e,t));try{await n(e)}finally{g(t=>{let n=new Map(t);return n.delete(e),n})}}},[]);if((0,G.useEffect)(()=>{p(!1)},[e]),!r)return null;let T=_,E=T?.totalCount??0;return(0,K.jsxs)(`aside`,{className:`flex h-full min-h-0 w-full flex-col border-l border-border/70 bg-card/15`,"aria-label":`File memory drawer`,"data-file-path":e??``,children:[(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:[(0,K.jsx)(o,{className:`size-3`}),(0,K.jsx)(`span`,{className:`truncate font-mono`,title:e??``,children:e??`(no file)`})]}),(0,K.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`font-mono`,children:[E,` memories`]}),T&&T.reviewPendingCount>0&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 font-mono text-warning`,children:[(0,K.jsx)(ee,{className:`size-3`}),T.reviewPendingCount,` pending review`]}),T&&T.supersededCount>0&&(0,K.jsxs)(`span`,{className:`font-mono`,children:[T.supersededCount,` superseded`]})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,K.jsx)(L,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>S(),disabled:v||!e,className:`h-7 w-7 p-0`,"aria-label":`Refresh`,title:`Re-query for this file`,children:(0,K.jsx)(te,{className:P(`size-3.5`,v&&`animate-spin`)})}),(0,K.jsx)(L,{type:`button`,size:`sm`,variant:`ghost`,onClick:i,className:`h-7 w-7 p-0`,"aria-label":`Close drawer`,title:`Close memory drawer`,children:(0,K.jsx)(h,{className:`size-3.5`})})]})]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/40 bg-background/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:f,onChange:e=>p(e.target.checked),className:`size-3 accent-primary`,disabled:!e,"data-testid":`memory-drawer-show-deleted`}),f?(0,K.jsx)(b,{className:`size-3`}):(0,K.jsx)(y,{className:`size-3`}),(0,K.jsx)(`span`,{children:`Show recoverable (deleted)`})]}),C&&(0,K.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 font-mono text-[10px] text-primary`,children:[(0,K.jsx)(A,{className:`size-3`}),` lines `,t,`–`,n]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto px-3 py-3`,children:e?v&&!T?(0,K.jsx)(ot,{loading:!0,message:`Loading memories…`}):x?(0,K.jsx)(ot,{tone:`error`,message:`Error: ${x}`}):!T||E===0?(0,K.jsx)(ot,{message:`No memories attached to ${e} yet.`}):(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(it,{icon:A,title:`Cursor boost`,count:T.symbolMatches.length,cursorBoosted:C,matches:T.symbolMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))}),(0,K.jsx)(it,{icon:o,title:`File-scoped`,count:T.primaryMatches.length,matches:T.primaryMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))}),(0,K.jsx)(it,{icon:b,title:`Mentioned in`,count:T.relatedMatches.length,matches:T.relatedMatches,pendingActionById:m,onShowMemory:a,onAcceptDeletion:(e,t)=>w(t,`accepting…`,()=>s?.(e,t)),onKeep:(e,t)=>w(t,`keeping…`,()=>c?.(e,t)),onUpdate:e=>w(e,`updating…`,()=>l?.(e)),onMarkPermanent:e=>w(e,`marking…`,()=>u?.(e)),onRecover:e=>w(e,`recovering…`,()=>d?.(e))})]}):(0,K.jsx)(ot,{message:`Open a file to see its memories.`})})]})}function ot({message:e,loading:t=!1,tone:n=`default`}){return(0,K.jsxs)(`div`,{className:P(`flex min-h-[120px] flex-col items-center justify-center gap-2 rounded-md border border-dashed border-border/60 px-4 py-6 text-center text-[11px]`,n===`error`?`text-destructive`:`text-muted-foreground`),children:[t&&(0,K.jsx)(c,{className:`size-4 animate-spin`}),(0,K.jsx)(`p`,{children:e})]})}function st({mode:e,draft:r,busy:i,error:a,onChange:o,onCancel:l,onSubmit:u}){let d=(0,G.useRef)(null),[f,p]=(0,G.useState)([]);(0,G.useEffect)(()=>{d.current?.focus();let e=new AbortController;return we(`agent-roster.list`,{},e.signal).then(e=>{let t=e.roles;Array.isArray(t)&&p(t.filter(e=>typeof e==`string`))}).catch(()=>void 0),()=>e.abort()},[]);let m=(e,t)=>{o({...r,[e]:t})},h=()=>{m(`anchors`,[...r.anchors,{type:`file`,path:``}])};return(0,K.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),u()},"aria-busy":i,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-border/70 bg-card/70 px-4 py-3 backdrop-blur-xl`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`flex size-8 items-center justify-center border border-info/35 bg-info/10 text-info`,children:e===`create`?(0,K.jsx)(s,{className:`size-4`}):(0,K.jsx)(w,{className:`size-4`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`p`,{className:`truncate text-sm font-bold`,children:e===`create`?`Capture a memory`:`Edit memory`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:e===`create`?`Add durable knowledge with retrieval metadata.`:`Update content without losing provenance.`})]})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,onClick:l,disabled:i,children:[(0,K.jsx)(E,{className:`size-3.5`}),` Cancel`]}),(0,K.jsxs)(L,{type:`submit`,size:`sm`,disabled:i||!r.text.trim(),children:[i?(0,K.jsx)(c,{className:`size-3.5 animate-spin`}):e===`create`?(0,K.jsx)(le,{className:`size-3.5`}):(0,K.jsx)(k,{className:`size-3.5`}),i?`Saving…`:e===`create`?`Create memory`:`Save changes`]})]})]}),(0,K.jsx)(`div`,{className:`flex-1 overflow-y-auto overscroll-contain p-4 md:p-5`,children:(0,K.jsxs)(`div`,{className:`mx-auto max-w-4xl space-y-5`,children:[a&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 border border-destructive/40 bg-destructive/10 px-3 py-2.5 text-sm text-destructive`,children:[(0,K.jsx)(ee,{className:`mt-0.5 size-4 shrink-0`}),(0,K.jsx)(`span`,{children:a})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Knowledge`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Write the durable fact or decision in complete, searchable language.`})]}),(0,K.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground tabular-nums`,children:[r.text.length,` chars`]})]}),(0,K.jsx)(`label`,{htmlFor:`memory-text`,className:`sr-only`,children:`Memory content`}),(0,K.jsx)(`textarea`,{ref:d,id:`memory-text`,value:r.text,onChange:e=>m(`text`,e.target.value),rows:7,required:!0,placeholder:`Example: WebUI state is owned by Zustand stores; server messages update those stores through singleton WebSocket handlers.`,className:`min-h-36 w-full resize-y border border-input bg-background/75 px-3 py-3 text-sm leading-6 text-foreground shadow-inner placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-kind`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Kind`}),(0,K.jsx)(`select`,{id:`memory-kind`,value:r.kind,onChange:e=>m(`kind`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:B.map(e=>(0,K.jsx)(`option`,{value:e,children:U[e]},e))})]}),e===`create`?(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-scope`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Scope`}),(0,K.jsx)(`select`,{id:`memory-scope`,value:r.scope,onChange:e=>m(`scope`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:Ee.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}):(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsx)(`label`,{htmlFor:`memory-status`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Lifecycle status`}),(0,K.jsx)(`select`,{id:`memory-status`,value:r.status,onChange:e=>m(`status`,e.target.value),className:`h-10 w-full border border-input bg-background px-3 text-sm`,children:Me.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))})]}),(0,K.jsxs)(`div`,{className:P(`min-w-0`,e===`create`?`sm:col-span-2 lg:col-span-1`:``),children:[(0,K.jsx)(`label`,{htmlFor:`memory-tags`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Tags`}),(0,K.jsx)(R,{id:`memory-tags`,value:r.tags,onChange:e=>m(`tags`,e.target.value),placeholder:`architecture, webui, workflow`,className:`h-10 bg-background`})]})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,K.jsx)(Oe,{id:`memory-importance`,label:`Importance`,value:r.importance,onChange:e=>m(`importance`,e)}),(0,K.jsx)(Oe,{id:`memory-confidence`,label:`Confidence`,value:r.confidence,onChange:e=>m(`confidence`,e)}),(0,K.jsx)(Oe,{id:`memory-freshness`,label:`Freshness`,value:r.freshness,onChange:e=>m(`freshness`,e)})]}),(0,K.jsxs)(`section`,{className:`border border-border/75 bg-card/45 p-4`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Anchors`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Bind knowledge to files, symbols, packages, tests, Git paths, or commands.`})]}),(0,K.jsxs)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:h,children:[(0,K.jsx)(le,{className:`size-3.5`}),` Add anchor`]})]}),r.anchors.length===0?(0,K.jsxs)(`button`,{type:`button`,onClick:h,className:`mt-4 flex w-full items-center justify-center gap-2 border border-dashed border-border px-4 py-7 text-xs text-muted-foreground transition-colors hover:border-info/50 hover:bg-info/5 hover:text-info`,children:[(0,K.jsx)(t,{className:`size-4`}),` No anchors yet — add one to improve retrieval precision`]}):(0,K.jsx)(`div`,{className:`mt-4 space-y-2`,children:r.anchors.map((e,t)=>(0,K.jsxs)(`div`,{className:`grid gap-2 border border-border/65 bg-background/40 p-2 sm:grid-cols-[9rem_minmax(0,1fr)_auto]`,children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-type-${t}`,children:[`Anchor `,t+1,` type`]}),(0,K.jsx)(`select`,{id:`anchor-type-${t}`,value:e.type,onChange:e=>{let n=e.target.value,i=n===`command`?{type:n,command:``}:n===`agent`?{type:n,role:``}:{type:n,path:``},a=r.anchors.map((e,n)=>n===t?i:e);m(`anchors`,a)},className:`h-10 border border-input bg-background px-2 text-xs`,children:Ie.map(e=>(0,K.jsx)(`option`,{value:e,children:e},e))}),(0,K.jsxs)(`div`,{className:P(`grid min-w-0 gap-2`,e.type===`symbol`&&`sm:grid-cols-[minmax(0,1fr)_11rem]`),children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-value-${t}`,children:[`Anchor `,t+1,` value`]}),(0,K.jsx)(R,{id:`anchor-value-${t}`,list:e.type===`agent`?`memory-agent-role-options`:void 0,value:Le(e),onChange:e=>{let n=r.anchors.map((n,r)=>r===t?De(n,e.target.value):n);m(`anchors`,n)},placeholder:e.type===`command`?`pnpm test --filter webui`:e.type===`agent`?`reviewer`:`packages/webui/src/App.tsx`,className:`h-10 min-w-0 bg-background font-mono text-xs`}),e.type===`symbol`&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`sr-only`,htmlFor:`anchor-symbol-${t}`,children:[`Anchor `,t+1,` symbol`]}),(0,K.jsx)(R,{id:`anchor-symbol-${t}`,value:e.symbol??``,onChange:e=>{let n=r.anchors.map((n,r)=>r===t?{...n,symbol:e.target.value}:n);m(`anchors`,n)},placeholder:`Symbol name`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsx)(L,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`Remove anchor ${t+1}`,onClick:()=>m(`anchors`,r.anchors.filter((e,n)=>n!==t)),children:(0,K.jsx)(n,{className:`size-4 text-destructive`})})]},`${e.type}:${t}`))}),(0,K.jsx)(`datalist`,{id:`memory-agent-role-options`,children:f.map(e=>(0,K.jsx)(`option`,{value:e},e))})]}),(0,K.jsxs)(`section`,{className:`grid gap-3 border border-border/75 bg-card/45 p-4 sm:grid-cols-2`,children:[(0,K.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,K.jsx)(`h3`,{className:`text-xs font-bold uppercase tracking-[0.14em]`,children:`Relationships`}),(0,K.jsx)(`p`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`Reference exact memory IDs. Relationships are validated and graph edges are rebuilt by SAGE.`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-supersedes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Supersedes`}),(0,K.jsx)(R,{id:`memory-supersedes`,value:r.supersedes,onChange:e=>m(`supersedes`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-contradicts`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Contradicts`}),(0,K.jsx)(R,{id:`memory-contradicts`,value:r.contradicts,onChange:e=>m(`contradicts`,e.target.value),placeholder:`mem_id, mem_id`,className:`h-10 bg-background font-mono text-xs`})]})]}),(0,K.jsxs)(`section`,{className:`space-y-2`,children:[(0,K.jsx)(`h3`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Audience (Optional)`}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/70`,children:`Target this memory to specific agent types. Leave empty for general project memory.`}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-roles`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Roles`}),(0,K.jsx)(R,{id:`memory-audience-roles`,value:r.audienceRoles,onChange:e=>m(`audienceRoles`,e.target.value),placeholder:`reviewer, refactor-planner`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-task-types`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Task types`}),(0,K.jsx)(R,{id:`memory-audience-task-types`,value:r.audienceTaskTypes,onChange:e=>m(`audienceTaskTypes`,e.target.value),placeholder:`review, refactor, bugfix`,className:`h-9 bg-background font-mono text-xs`})]}),(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`label`,{htmlFor:`memory-audience-modes`,className:`mb-1.5 block text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Modes`}),(0,K.jsx)(R,{id:`memory-audience-modes`,value:r.audienceModes,onChange:e=>m(`audienceModes`,e.target.value),placeholder:`teach, code-review`,className:`h-9 bg-background font-mono text-xs`})]})]})]})})]})}function ct({searchQuery:e,statusFilter:t,kindFilter:n,audienceOnly:i,tagFilter:o,hasFilters:s,allTags:c,stats:l,onSearchChange:d,onStatusFilterChange:f,onKindFilterChange:p,onToggleAudienceOnly:m,onTagFilterChange:h,onClearFilters:g}){let[v,y]=(0,G.useState)(!!o),b=v||!!o,x=c.length>0;return(0,K.jsxs)(`div`,{className:`shrink-0 space-y-2 overflow-hidden border-b border-border/70 bg-card/45 p-3`,children:[(0,K.jsxs)(`div`,{className:`flex gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,K.jsx)(S,{className:`pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,K.jsx)(R,{"aria-label":`Search memories`,value:e,onChange:e=>d(e.target.value),placeholder:`Search content, IDs, tags, anchors…`,className:`h-10 min-w-0 bg-background pl-9 pr-8 text-xs`}),e&&(0,K.jsx)(`button`,{type:`button`,"aria-label":`Clear search`,onClick:()=>d(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground`,children:(0,K.jsx)(E,{className:`size-3.5`})})]}),(0,K.jsx)(L,{variant:i?`default`:`ghost`,size:`icon`,onClick:m,"aria-label":`Filter audience-scoped only`,title:`Show only audience-scoped memories`,className:`shrink-0`,children:(0,K.jsx)(a,{className:`size-4`})}),s&&(0,K.jsx)(L,{variant:`ghost`,size:`icon`,onClick:g,"aria-label":`Clear all filters`,title:`Clear all filters`,children:(0,K.jsx)(_,{className:`size-4`})})]}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-status-filter`,children:`Filter by status`}),(0,K.jsxs)(`select`,{id:`memory-status-filter`,value:t,onChange:e=>f(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All statuses`}),Ne.map(e=>(0,K.jsxs)(`option`,{value:e,children:[e,` · `,l?.byStatus[e]??0]},e))]}),(0,K.jsx)(`label`,{className:`sr-only`,htmlFor:`memory-kind-filter`,children:`Filter by kind`}),(0,K.jsxs)(`select`,{id:`memory-kind-filter`,value:n,onChange:e=>p(e.target.value),className:`h-9 min-w-0 border border-input bg-background px-2 text-xs`,children:[(0,K.jsx)(`option`,{value:`all`,children:`All kinds`}),B.map(e=>(0,K.jsxs)(`option`,{value:e,children:[U[e],` · `,l?.byKind[e]??0]},e))]})]}),x&&(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>{o||y(e=>!e)},"aria-expanded":b,"aria-controls":`memory-tags-panel`,disabled:!!o,className:P(`flex items-center gap-1.5 px-1 py-0.5 text-[10px] uppercase tracking-wide transition-colors`,b?`text-foreground`:`text-muted-foreground hover:text-foreground`,!!o&&`cursor-default`),title:o?`Active filter: ${o} (click the chip to clear)`:b?`Hide tag filters`:`Show tag filters (${c.length})`,children:[(0,K.jsx)(u,{className:P(`size-3 transition-transform`,!b&&`-rotate-90`)}),(0,K.jsx)(r,{className:`size-3`}),(0,K.jsx)(`span`,{className:`font-semibold`,children:`Tags`}),(0,K.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:c.length})]}),o&&(0,K.jsx)(`span`,{"aria-label":`Active tag filter: ${o}`,className:`border border-info/55 bg-info/10 px-1 font-mono text-[9px] uppercase text-info`,children:o})]}),x&&b&&(0,K.jsxs)(`fieldset`,{id:`memory-tags-panel`,className:`min-w-0 border-0 p-0`,children:[(0,K.jsx)(`legend`,{className:`sr-only`,children:`Popular tags`}),(0,K.jsx)(`div`,{className:`no-scrollbar flex gap-1.5 overflow-x-auto pb-0.5`,children:c.slice(0,18).map(([e,t])=>(0,K.jsxs)(`button`,{type:`button`,"aria-pressed":o===e,onClick:()=>h(o===e?null:e),className:P(`flex shrink-0 items-center gap-1 border px-2 py-1 text-[10px] transition-colors`,o===e?`border-info/55 bg-info/10 text-info`:`border-border/70 bg-background/45 text-muted-foreground hover:border-info/35 hover:text-foreground`),children:[(0,K.jsx)(r,{className:`size-2.5`}),` `,e,(0,K.jsx)(`span`,{className:`font-mono opacity-60`,children:t})]},e))})]})]})}var lt=100;function ut({memoryListRef:e,memories:t,filteredMemories:n,selectedId:r,onSelectMemory:i,onOpenCreate:a,onClearFilters:o}){let s=n.length>lt,c=se({count:n.length,getScrollElement:()=>e.current,estimateSize:()=>100,overscan:8,enabled:s});return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between border-b border-border/60 px-3 py-2 text-[10px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{children:[n.length,` of `,t.length,` memories`]}),(0,K.jsx)(`span`,{className:`font-mono uppercase`,children:`updated ↓`})]}),(0,K.jsx)(`section`,{ref:e,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"aria-label":`Memories`,children:n.length===0?(0,K.jsx)(dt,{hasMemories:t.length>0,onOpenCreate:a,onClearFilters:o}):s?(0,K.jsx)(`div`,{style:{height:`${c.getTotalSize()}px`,width:`100%`,position:`relative`},children:c.getVirtualItems().map(e=>{let t=n[e.index];return t?(0,K.jsx)(`div`,{"data-index":e.index,ref:c.measureElement,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`},children:(0,K.jsx)(ft,{memory:t,isSelected:r===t.id,onClick:()=>i(t.id)})},t.id):null})}):n.map(e=>(0,K.jsx)(ft,{memory:e,isSelected:r===e.id,onClick:()=>i(e.id)},e.id))})]})}function dt({hasMemories:e,onOpenCreate:t,onClearFilters:n}){return(0,K.jsxs)(`div`,{className:`flex min-h-64 flex-col items-center justify-center px-6 text-center`,children:[(0,K.jsx)(`span`,{className:`flex size-12 items-center justify-center border border-dashed border-border text-muted-foreground`,children:(0,K.jsx)(ae,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-sm font-bold`,children:e?`No matching memories`:`Build your memory graph`}),(0,K.jsx)(`p`,{className:`mt-1 max-w-xs text-xs leading-5 text-muted-foreground`,children:e?`Change the filters or clear the search query.`:`Capture durable facts, decisions, conventions, and file-bound notes for every agent.`}),(0,K.jsxs)(L,{className:`mt-4`,variant:`outline`,size:`sm`,onClick:e?n:t,children:[e?(0,K.jsx)(_,{className:`size-3.5`}):(0,K.jsx)(le,{className:`size-3.5`}),e?`Clear filters`:`Create first memory`]})]})}function ft({memory:e,isSelected:t,onClick:n}){return(0,K.jsxs)(`button`,{type:`button`,"aria-current":t?`true`:void 0,onClick:n,className:P(`group relative block w-full border-b border-border/55 px-3 py-3 text-left transition-[background-color,border-color] hover:bg-info/5`,t&&`bg-info/8`),children:[t&&(0,K.jsx)(`span`,{className:`absolute inset-y-0 left-0 w-0.5 bg-info shadow-[0_0_10px_hsl(var(--info)/0.7)]`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`span`,{className:P(`truncate text-[10px] font-bold uppercase tracking-[0.1em]`,je(e.kind)),children:U[e.kind]??e.kind}),(0,K.jsx)(V,{status:e.status}),(0,K.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-[9px] text-muted-foreground`,children:[`r`,e.revision]})]}),(0,K.jsx)(`p`,{className:P(`mt-2 line-clamp-2 text-xs leading-5 text-foreground/90`,e.status===`deleted`&&`line-through opacity-60`),children:z(e.text)}),(0,K.jsxs)(`div`,{className:`mt-2 flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`border border-border/60 bg-background/50 px-1.5 py-0.5 font-mono text-[9px] uppercase text-muted-foreground`,children:e.scope}),e.audience&&(0,K.jsxs)(`span`,{className:`flex items-center gap-0.5 border border-primary/30 bg-primary/10 px-1.5 py-0.5 font-mono text-[9px] text-primary`,children:[(0,K.jsx)(a,{className:`size-2.5`}),(e.audience.roles??e.audience.taskTypes??e.audience.modes??[]).slice(0,1)[0]??`scoped`]}),e.tags.slice(0,2).map(e=>(0,K.jsxs)(`span`,{className:`max-w-24 truncate border border-border/60 px-1.5 py-0.5 font-mono text-[9px] text-muted-foreground`,children:[`#`,e]},e)),e.tags.length>2&&(0,K.jsxs)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:[`+`,e.tags.length-2]}),(0,K.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:Re(e.updatedAt)}),(0,K.jsx)(i,{className:`size-3 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-info`})]})]})}function pt({busyAction:e,deletingId:t,memories:r,onCancel:i,onConfirm:a,onOpenChange:o}){return(0,K.jsx)(I,{open:!!t,onOpenChange:o,children:(0,K.jsxs)(ye,{className:`max-w-md`,children:[(0,K.jsxs)(_e,{children:[(0,K.jsx)(`span`,{className:`mb-2 flex size-10 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(n,{className:`size-4`})}),(0,K.jsx)(be,{children:`Delete this memory?`}),(0,K.jsx)(F,{className:`leading-6`,children:`SAGE will mark the record deleted, remove graph edges, and clean references from related memories. The record remains in the audit trail but cannot be restored from this page.`})]}),(0,K.jsx)(`div`,{className:`border border-border/70 bg-background/45 p-3 text-xs text-muted-foreground`,children:z(r.find(e=>e.id===t)?.text??``,180)}),(0,K.jsxs)(ve,{children:[(0,K.jsx)(L,{variant:`outline`,onClick:i,disabled:e===`delete`,children:`Cancel`}),(0,K.jsxs)(L,{variant:`destructive`,onClick:a,disabled:e===`delete`,children:[e===`delete`?(0,K.jsx)(c,{className:`size-4 animate-spin`}):(0,K.jsx)(n,{className:`size-4`}),e===`delete`?`Deleting…`:`Delete memory`]})]})]})})}function mt({onCapture:e}){return(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center p-8 text-center`,children:[(0,K.jsxs)(`div`,{className:`relative flex size-20 items-center justify-center border border-info/25 bg-info/5 text-info`,children:[(0,K.jsx)(a,{className:`size-8`}),(0,K.jsx)(`span`,{className:`absolute inset-2 border border-info/10`})]}),(0,K.jsx)(`h2`,{className:`mt-5 text-lg font-bold`,children:`Your project’s long-term context`}),(0,K.jsx)(`p`,{className:`mt-2 max-w-md text-sm leading-6 text-muted-foreground`,children:`Select a memory to inspect its metadata and relationship graph, or capture knowledge that future agents should retrieve automatically.`}),(0,K.jsxs)(`div`,{className:`mt-6 grid w-full max-w-lg gap-2 sm:grid-cols-3`,children:[(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(m,{className:`mx-auto size-4 text-success`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Verified anchors`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(a,{className:`mx-auto size-4 text-info`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Typed relations`})]}),(0,K.jsxs)(`div`,{className:`border border-border/70 bg-card/45 p-3`,children:[(0,K.jsx)(le,{className:`mx-auto size-4 text-warning`}),(0,K.jsx)(`p`,{className:`mt-2 text-[10px] font-bold uppercase`,children:`Agent recall`})]})]}),(0,K.jsxs)(L,{onClick:e,children:[(0,K.jsx)(le,{className:`size-4`}),` Capture memory`]})]})}function ht(e,t){let n=t.searchQuery.trim().toLowerCase();return e.filter(e=>{if(t.statusFilter!==`all`&&e.status!==t.statusFilter||t.kindFilter!==`all`&&e.kind!==t.kindFilter||t.tagFilter&&!e.tags.includes(t.tagFilter)||t.audienceOnly&&!e.audience)return!1;if(!n)return!0;let r=e.anchors.map(e=>[e.path,e.symbol,e.command,e.role].filter(Boolean).join(` `)).join(` `),i=e.audience?[e.audience.roles?.join(` `)??``,e.audience.taskTypes?.join(` `)??``,e.audience.modes?.join(` `)??``].join(` `):``;return[e.id,e.text,e.summary??``,e.kind,e.scope,e.tags.join(` `),r,i].join(` `).toLowerCase().includes(n)})}function gt(e){let t=new Map;for(let n of e)for(let e of n.tags)t.set(e,(t.get(e)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))}function _t(e){if(!e)return[];let t=[];e.supersededBy&&t.push({relation:`Superseded by`,id:e.supersededBy});for(let n of e.supersedes??[])t.push({relation:`Supersedes`,id:n});for(let n of e.contradicts??[])t.push({relation:`Contradicts`,id:n});return t}function vt(){let{client:e,listSageMemoriesPage:t,rememberSage:n,updateSage:r,deleteSage:i,getSageGraph:o,recoverSage:s,resolveMemoryCandidate:c}=he(),l=ge(e=>e.wsConnected),u=me(e=>e.setCurrentView),d=xe(`memory`),[f,p]=(0,G.useState)([]),[h,_]=(0,G.useState)(null),[v,y]=(0,G.useState)(!0),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(null),[w,T]=(0,G.useState)(null),[E,D]=(0,G.useState)(null),[O,k]=(0,G.useState)(null),[ne,re]=(0,G.useState)([]),[A,ie]=(0,G.useState)([]),[ae,oe]=(0,G.useState)(null),[se,ue]=(0,G.useState)(!1),[j,M]=(0,G.useState)(!1),[de,fe]=(0,G.useState)(!1),[N,_e]=(0,G.useState)(Ae),[ve,ye]=(0,G.useState)(Ae),[be,F]=(0,G.useState)(null),[I,R]=(0,G.useState)(null),[Se,Ce]=(0,G.useState)(``),[we,Ee]=(0,G.useState)(`all`),[De,Oe]=(0,G.useState)(`all`),[z,je]=(0,G.useState)(!1),[B,V]=(0,G.useState)(null),[H,Me]=(0,G.useState)(!1),[Ne,Pe]=(0,G.useState)(null),[U,Ie]=(0,G.useState)(!1),[Le,Re]=(0,G.useState)(!1),[ze,Be]=(0,G.useState)({}),[Ve,He]=(0,G.useState)(!1),[Ue,We]=(0,G.useState)(null),[Ge,Ke]=(0,G.useState)(void 0),[qe,Je]=(0,G.useState)(void 0),Ye=(0,G.useRef)(!1),q=(0,G.useRef)(!0),Ze=(0,G.useRef)(0),J=(0,G.useRef)(0),Qe=(0,G.useRef)(null),Y=(0,G.useRef)(null),$e=(0,G.useMemo)(()=>JSON.stringify(N)!==JSON.stringify(ve),[ve,N]),X=(0,G.useMemo)(()=>f.find(e=>e.id===O)??null,[f,O]),et=(0,G.useCallback)(n=>{let r=n!==null,i=++Ze.current;Qe.current?.(),C(null),r?Re(!0):(x(!0),Ye.current||y(!0));let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Qe.current===c&&(Qe.current=null))};a=e.on(`memory.sage.listPage`,e=>{if(i!==Ze.current||!q.current){c();return}if(c(),e.payload.error)C(e.payload.error);else{let t=e.payload.memories??[];p(e=>r?[...e,...t]:t),Pe(e.payload.nextCursor??null),Ie(!!e.payload.nextCursor);let n=e.payload.statusCounts??{};Be(n);let i=Object.values(n).reduce((e,t)=>e+t,0);e.payload.stats?_(e.payload.stats):_(e=>({total:i,byStatus:n,byKind:e?.byKind??{},edges:e?.edges??0})),Ye.current=!0,r||k(e=>e&&t.some(t=>t.id===e)?e:null)}y(!1),x(!1),Re(!1)}),o=setTimeout(()=>{i!==Ze.current||!q.current||(c(),C(`The memory store did not respond. Check the WebSocket connection and try again.`),y(!1),x(!1),Re(!1))},2e4),Qe.current=c,t({limit:100,...H?{statuses:[`deleted`]}:{},...n?{cursor:n}:{}},{echoToChat:!1})},[e,t,H]),Z=(0,G.useCallback)(()=>{Pe(null),Ie(!1),et(null)},[et]),tt=(0,G.useCallback)(()=>{Le||!Ne||et(Ne)},[et,Le,Ne]);(0,G.useEffect)(()=>(q.current=!0,Z(),()=>{q.current=!1,Ze.current+=1,J.current+=1,Qe.current?.(),Y.current?.()}),[Z]),(0,G.useEffect)(()=>{if(re([]),ie([]),oe(null),!O){ue(!1);return}let t=O;ue(!0);let n=null,r=e.on(`memory.sage.graph`,e=>{e.payload.query===t&&(n!==null&&clearTimeout(n),re(e.payload.edges??[]),ie(e.payload.memories??[]),oe(e.payload.error??null),ue(!1))});return n=setTimeout(()=>{oe(`Relationship graph did not respond in time.`),ue(!1)},15e3),o(t,{maxDepth:1,limit:120},{echoToChat:!1}),()=>{n!==null&&clearTimeout(n),r()}},[e,o,O]);let nt=(0,G.useRef)(l);(0,G.useEffect)(()=>{l&&!nt.current&&Ye.current&&Z(),nt.current=l},[Z,l]),(0,G.useEffect)(()=>{if(!E)return;let e=setTimeout(()=>D(null),4e3);return()=>clearTimeout(e)},[E]);let Q=(0,G.useCallback)(()=>!$e||!j&&!de||window.confirm(`Discard the unsaved memory changes?`),[de,$e,j]),rt=(0,G.useCallback)(()=>{if(!Q())return;let e=Ae();_e(e),ye(e),fe(!0),M(!1),k(null),T(null)},[Q]),it=(0,G.useCallback)(e=>{Q()&&(k(e),fe(!1),M(!1),T(null))},[Q]),ot=(0,G.useCallback)(()=>{if(!X||X.status===`deleted`)return;let e=ke(X);_e(e),ye(e),M(!0),fe(!1),T(null)},[X]),lt=(0,G.useCallback)(()=>{Q()&&(M(!1),fe(!1),T(null))},[Q]),dt=(0,G.useCallback)((t,n,r)=>{if(!N.text.trim()){T(`Memory content is required.`);return}let i=++J.current;Y.current?.(),F(r),T(null),D(null);let a=()=>{},o=null,s=!1,c=()=>{s||(s=!0,o!==null&&clearTimeout(o),a(),Y.current===c&&(Y.current=null))},l=e=>{if(i!==J.current||!q.current){c();return}if(c(),F(null),e.payload.error||!e.payload.memory){T(e.payload.error??`The server returned no memory record.`);return}let t=e.payload.memory;p(e=>{let n=e.filter(e=>e.id!==t.id);return[t,...n]}),k(t.id),fe(!1),M(!1),D(r===`create`?`Memory captured.`:`Memory updated.`),Z()};a=t===`memory.sage.remember`?e.on(`memory.sage.remember`,l):e.on(`memory.sage.update`,l),o=setTimeout(()=>{i!==J.current||!q.current||(c(),F(null),T(`${r===`create`?`Create`:`Save`} timed out. Your draft is still here.`))},2e4),Y.current=c,n()},[e,N.text,Z]),ft=(0,G.useCallback)(()=>{dt(`memory.sage.remember`,()=>n({text:N.text.trim(),kind:N.kind,scope:N.scope,tags:W(N.tags),importance:N.importance,confidence:N.confidence,freshness:N.freshness,anchors:Te(N.anchors),...W(N.audienceRoles).length||W(N.audienceTaskTypes).length||W(N.audienceModes).length?{audience:{roles:W(N.audienceRoles),taskTypes:W(N.audienceTaskTypes),modes:W(N.audienceModes)}}:{},supersedes:W(N.supersedes),contradicts:W(N.contradicts)},{echoToChat:!1}),`create`)},[N,n,dt]),vt=(0,G.useCallback)(()=>{X&&dt(`memory.sage.update`,()=>r(X.id,{text:N.text.trim(),kind:N.kind,status:N.status,tags:W(N.tags),importance:N.importance,confidence:N.confidence,freshness:N.freshness,anchors:Te(N.anchors),...W(N.audienceRoles).length||W(N.audienceTaskTypes).length||W(N.audienceModes).length?{audience:{roles:W(N.audienceRoles),taskTypes:W(N.audienceTaskTypes),modes:W(N.audienceModes)}}:{},supersedes:W(N.supersedes),contradicts:W(N.contradicts)},{echoToChat:!1}),`update`)},[N,dt,X,r]),yt=(0,G.useCallback)(()=>{if(!I)return;let t=++J.current;Y.current?.(),F(`delete`),T(null);let n=()=>{},r=null,a=!1,o=()=>{a||(a=!0,r!==null&&clearTimeout(r),n(),Y.current===o&&(Y.current=null))};n=e.on(`memory.sage.delete`,e=>{if(t!==J.current||!q.current){o();return}if(o(),F(null),!e.payload.success){T(e.payload.message||`Delete failed.`);return}R(null),k(null),M(!1),D(`Memory deleted and relationship edges cleaned up.`),Z()}),r=setTimeout(()=>{t!==J.current||!q.current||(o(),F(null),T(`Delete timed out. The memory may still exist; refresh to confirm.`))},2e4),Y.current=o,i(I,`Deleted from the WebUI Memory Manager.`)},[e,i,I,Z]),bt=(0,G.useMemo)(()=>ht(f,{searchQuery:Se,statusFilter:we,kindFilter:De,tagFilter:B,audienceOnly:z}),[z,De,f,Se,we,B]),xt=(0,G.useMemo)(()=>gt(f),[f]),St=(0,G.useMemo)(()=>_t(X),[X]),Ct=(0,G.useCallback)(()=>{Ce(``),Ee(`all`),Oe(`all`),je(!1),V(null)},[]),wt=!!(Se||we!==`all`||De!==`all`||B||z),Tt=de||!!X,$=Ve&&!!Ue;return v&&f.length===0?(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background`,"aria-busy":`true`,children:[(0,K.jsxs)(`div`,{className:`border-b border-border/70 bg-card/70 px-5 py-4`,children:[(0,K.jsx)(`div`,{className:`h-3 w-28 animate-pulse bg-muted`}),(0,K.jsx)(`div`,{className:`mt-3 h-7 w-56 animate-pulse bg-muted`})]}),(0,K.jsxs)(`div`,{className:`grid flex-1 gap-px bg-border/60 md:grid-cols-[minmax(300px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsx)(`div`,{className:`space-y-px bg-background p-4`,children:Array.from({length:7},(e,t)=>(0,K.jsx)(`div`,{className:`h-24 animate-pulse border border-border/60 bg-card/45`},t))}),(0,K.jsx)(`div`,{className:`hidden bg-background p-6 md:block`,children:(0,K.jsx)(`div`,{className:`h-full animate-pulse border border-border/60 bg-card/35`})})]}),(0,K.jsx)(`span`,{className:`sr-only`,role:`status`,children:`Loading SAGE content`})]}):S&&f.length===0?(0,K.jsx)(`div`,{className:`flex h-full min-h-0 items-center justify-center bg-background p-6`,children:(0,K.jsxs)(`div`,{className:`max-w-md border border-destructive/35 bg-card p-6 shadow-2xl`,children:[(0,K.jsx)(`span`,{className:`flex size-11 items-center justify-center border border-destructive/35 bg-destructive/10 text-destructive`,children:(0,K.jsx)(ee,{className:`size-5`})}),(0,K.jsx)(`h2`,{className:`mt-4 text-lg font-bold`,children:`Memory store unavailable`}),(0,K.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-muted-foreground`,children:S}),(0,K.jsxs)(`div`,{className:`mt-5 flex gap-2`,children:[(0,K.jsxs)(L,{onClick:Z,children:[(0,K.jsx)(te,{className:`size-4`}),` Retry`]}),(0,K.jsxs)(L,{variant:`outline`,onClick:()=>u(`chat`),children:[(0,K.jsx)(ce,{className:`size-4`}),` Back to chat`]})]})]})}):(0,K.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col overflow-hidden bg-background`,children:[(0,K.jsxs)(`header`,{className:`relative shrink-0 overflow-hidden border-b border-border/70 bg-card/72 px-4 py-3 backdrop-blur-xl sm:px-5`,children:[(0,K.jsx)(`div`,{className:`pointer-events-none absolute inset-y-0 right-0 w-1/2 bg-[radial-gradient(circle_at_right,hsl(var(--info)/0.11),transparent_68%)]`}),(0,K.jsxs)(`div`,{className:`relative flex flex-wrap items-center gap-3`,children:[(0,K.jsx)(L,{variant:`ghost`,size:`icon`,onClick:()=>u(`chat`),"aria-label":`Back to chat`,title:`Back to chat`,children:(0,K.jsx)(ce,{className:`size-4`})}),(0,K.jsx)(`span`,{className:`flex size-10 items-center justify-center border border-info/40 bg-info/10 text-info shadow-[0_0_20px_hsl(var(--info)/0.12)]`,children:(0,K.jsx)(a,{className:`size-5`})}),(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(`h1`,{className:`text-base font-bold sm:text-lg`,children:`SAGE`}),(0,K.jsx)(`span`,{className:`border border-success/35 bg-success/10 px-2 py-0.5 font-mono text-[9px] font-bold uppercase text-success`,children:`project knowledge`})]}),(0,K.jsx)(`p`,{className:`mt-0.5 max-w-2xl text-[10px] text-muted-foreground sm:text-xs`,children:`Inspect, connect, curate, and retire durable context used across agent sessions.`})]}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:P(`hidden items-center gap-1.5 border px-2 py-1 font-mono text-[9px] uppercase sm:flex`,l?`border-success/30 text-success`:`border-warning/30 text-warning`),children:[(0,K.jsx)(`span`,{className:`size-1.5 bg-current`}),` `,l?`live store`:`reconnecting`]}),(0,K.jsxs)(L,{variant:`outline`,size:`sm`,onClick:Z,disabled:b,"aria-label":`Refresh memories`,children:[(0,K.jsx)(te,{className:P(`size-3.5`,b&&`animate-spin`)}),(0,K.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]}),(0,K.jsxs)(L,{size:`sm`,onClick:rt,children:[(0,K.jsx)(le,{className:`size-3.5`}),` New memory`]})]})]})]}),(0,K.jsxs)(`div`,{className:`grid shrink-0 grid-cols-2 gap-px border-b border-border/70 bg-border/60 sm:grid-cols-4`,children:[(0,K.jsx)(Fe,{label:`Memories`,value:h?.total??f.length,hint:`${bt.length} visible`}),(0,K.jsx)(Fe,{label:`Active`,value:h?.byStatus.active??f.filter(e=>e.status===`active`).length,hint:`retrievable`,tone:`success`}),(0,K.jsx)(Fe,{label:`Needs review`,value:(h?.byStatus.stale??0)+(h?.byStatus.contradicted??0),hint:`stale + conflicts`,tone:`warning`}),(0,K.jsx)(`div`,{className:`hidden sm:block`,children:(0,K.jsx)(Fe,{label:`Graph edges`,value:h?.edges??0,hint:`${xt.length} tags`,tone:`info`})})]}),(()=>{let e=f.filter(e=>e.audience).length;if(e===0)return null;let t=new Set;for(let e of f)if(e.audience){for(let n of e.audience.roles??[])t.add(n);for(let n of e.audience.taskTypes??[])t.add(n);for(let n of e.audience.modes??[])t.add(n)}return(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/70 bg-primary/5 px-4 py-1.5`,children:[(0,K.jsx)(a,{className:`size-3.5 text-primary`}),(0,K.jsxs)(`span`,{className:`text-[11px] font-medium text-primary`,children:[e,` audience-scoped memory`,e===1?``:`ies`]}),t.size>0&&(0,K.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(`,[...t].sort().join(`, `),`)`]})]})})(),(E||S||w)&&(0,K.jsxs)(`div`,{className:`shrink-0 border-b border-border/70 px-4 py-2`,"aria-live":`polite`,children:[E&&(0,K.jsxs)(`div`,{role:`status`,className:`flex items-center gap-2 text-xs text-success`,children:[(0,K.jsx)(m,{className:`size-3.5`}),` `,E]}),S&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-warning`,children:[(0,K.jsx)(ee,{className:`size-3.5`}),` `,S,` Existing content remains available.`]}),w&&!j&&!de&&(0,K.jsxs)(`div`,{role:`alert`,className:`flex items-center gap-2 text-xs text-destructive`,children:[(0,K.jsx)(ee,{className:`size-3.5`}),` `,w]})]}),(0,K.jsxs)(`div`,{className:`grid min-h-0 flex-1 md:grid-cols-[minmax(320px,0.82fr)_minmax(0,1.35fr)]`,children:[(0,K.jsxs)(`section`,{className:P(`min-h-0 border-r border-border/70 bg-card/25`,Tt?`hidden md:flex md:flex-col`:`flex flex-col`),"aria-label":`Memory library`,children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-3 pt-1`,role:`tablist`,"aria-label":`Memory view`,children:[(0,K.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":!H,onClick:()=>{H&&Me(!1)},className:P(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,H?`border-transparent text-muted-foreground`:`border-primary text-foreground`),children:`Active`}),(0,K.jsxs)(L,{type:`button`,variant:`ghost`,size:`sm`,role:`tab`,"aria-selected":H,onClick:()=>{H||Me(!0)},className:P(`h-7 rounded-b-none border-b-2 px-3 text-[11px]`,H?`border-primary text-foreground`:`border-transparent text-muted-foreground`),children:[`Deleted`,typeof ze.deleted==`number`?` (${ze.deleted})`:``]})]}),(0,K.jsx)(ct,{searchQuery:Se,statusFilter:we,kindFilter:De,audienceOnly:z,tagFilter:B,hasFilters:wt,allTags:xt,stats:h,onSearchChange:Ce,onStatusFilterChange:Ee,onKindFilterChange:Oe,onToggleAudienceOnly:()=>je(e=>!e),onTagFilterChange:V,onClearFilters:Ct}),(0,K.jsx)(ut,{memoryListRef:d,memories:f,filteredMemories:bt,selectedId:O,onSelectMemory:it,onOpenCreate:rt,onClearFilters:Ct}),U?(0,K.jsx)(`div`,{className:`shrink-0 border-t border-border/60 p-2`,children:(0,K.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:tt,disabled:Le,className:`h-7 w-full text-[11px]`,children:Le?`Loading…`:`Load more (${f.length} loaded)`})}):null]}),(0,K.jsxs)(`section`,{className:P(`min-h-0 bg-background`,Tt?`flex flex-col`:`hidden md:flex md:flex-col`),"aria-label":`Memory detail`,children:[f.some(e=>(e.anchors??[]).some(e=>e.type===`file`&&e.path))&&(0,K.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border/60 bg-card/30 px-3 py-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:`File drawer`}),(0,K.jsxs)(`select`,{value:Ue??``,onChange:e=>{let t=e.target.value||null;We(t),t&&He(!0)},className:`min-w-0 max-w-[260px] flex-1 truncate rounded-sm border border-border/60 bg-background px-1.5 py-0.5 text-[10px] font-mono`,"aria-label":`File for memory drawer`,"data-testid":`memory-drawer-file-select`,children:[(0,K.jsx)(`option`,{value:``,children:`— select a file —`}),f.flatMap(e=>e.anchors??[]).filter(e=>e.type===`file`&&e.path).map((e,t)=>(0,K.jsx)(`option`,{value:e.path,title:e.path,children:e.path},`${e.path}-${t}`))]}),(0,K.jsxs)(L,{type:`button`,size:`sm`,variant:$?`default`:`outline`,onClick:()=>{Ue&&He(e=>!e)},disabled:!Ue,className:`h-7 shrink-0 gap-1 px-2 text-[11px]`,"aria-pressed":$,title:$?`Hide file memory drawer`:`Show file memory drawer`,children:[$?(0,K.jsx)(g,{className:`size-3`}):(0,K.jsx)(pe,{className:`size-3`}),$?`Hide`:`Show`,` drawer`]})]}),de?(0,K.jsx)(st,{mode:`create`,draft:N,busy:be===`create`,error:w,onChange:_e,onCancel:lt,onSubmit:ft}):X?j?(0,K.jsx)(st,{mode:`edit`,draft:N,busy:be===`update`,error:w,onChange:_e,onCancel:lt,onSubmit:vt}):$?(0,K.jsx)(at,{filePath:Ue,lineStart:Ge,lineEnd:qe,open:$,onClose:()=>He(!1),onShowMemory:e=>k(e),onAcceptDeletion:async(e,t)=>{c({candidateId:e,action:`accept`}),D(`Accepted hygiene review for ${t.slice(0,12)}… (candidate ${e.slice(0,12)}…).`),setTimeout(()=>{Z()},500)},onKeep:async(e,t)=>{c({candidateId:e,action:`reject`}),D(`Kept ${t.slice(0,12)}… (candidate ${e.slice(0,12)}… rejected).`)},onUpdate:e=>{k(e),ot()},onMarkPermanent:async e=>{F(`update`);try{await r(e,{persistence:`permanent`}),D(`Memory ${e.slice(0,12)}… promoted to permanent.`),await Z()}catch(e){T(e instanceof Error?e.message:String(e))}finally{F(null)}},onRecover:async e=>{s({id:e,reason:`recovered via file drawer`}),D(`Recovered ${e.slice(0,12)}…`),setTimeout(()=>{Z()},500)}}):(0,K.jsx)(Xe,{memory:X,allMemories:[...f,...A],relatedMemories:St,graphEdges:ne,graphLoading:se,graphError:ae,onClose:()=>k(null),onOpenMemory:it,onEdit:ot,onDelete:()=>R(X.id),onTagSelect:e=>{V(e),k(null)},onNotice:D}):(0,K.jsx)(mt,{onCapture:rt})]})]}),(0,K.jsx)(pt,{busyAction:be,deletingId:I,memories:f,onCancel:()=>R(null),onConfirm:yt,onOpenChange:e=>{!e&&be!==`delete`&&R(null)}})]})}export{vt as MemoryManager};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Li as t,Ri as n,at as r,et as i,ga as a,in as o,oi as s,xa as c}from"./vendor-9hC4n4Me.js";import"./i18n-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Li as t,Ri as n,at as r,et as i,ga as a,in as o,oi as s,xa as c}from"./vendor-9hC4n4Me.js";import"./i18n-C2VyJ0Kz.js";import{t as l}from"./useWebSocket-Ba38Sknk.js";import{t as u}from"./ws-client-eyEv8wbm.js";import{t as d}from"./utils-DzRQUvln.js";import{M as f}from"./stores-hEu6z1qz.js";var p=e(c(),1);function m(e){let t=f(e=>e.wsUrl),{listSavedProviders:n,listProviderModels:r}=l(),[i,a]=(0,p.useState)([]),[o,s]=(0,p.useState)({});return(0,p.useEffect)(()=>{let e=u(t),n=e.on(`providers.saved`,e=>{let t=e.payload;a((t.providers??[]).map(e=>e.id))}),r=e.on(`provider.models`,e=>{let t=e.payload;s(e=>({...e,[t.provider]:t.models??[]}))});return()=>{n(),r()}},[t]),(0,p.useEffect)(()=>{e&&n()},[e,n]),(0,p.useEffect)(()=>{if(e)for(let e of i)o[e]||r(e)},[e,i,o,r]),(0,p.useMemo)(()=>{let e=[];for(let t of i)for(let n of o[t]??[])n.outputModalities?.length&&!n.outputModalities.includes(`text`)||e.push({provider:t,model:n.id,label:n.name??n.id,description:n.description,contextWindow:n.contextWindow,outputModalities:n.outputModalities});return e},[i,o])}var h=i();function g({value:e,provider:i,candidates:c,placeholder:l,resetLabel:u,onPick:f,onReset:m,className:g}){let{t:_}=a(),[v,y]=(0,p.useState)(!1),[b,x]=(0,p.useState)(``),S=(0,p.useRef)(null);(0,p.useEffect)(()=>{if(!v)return;let e=e=>{S.current&&!S.current.contains(e.target)&&y(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[v]);let C=(0,p.useMemo)(()=>{let e=b.trim().toLowerCase();return(e?c.filter(t=>`${t.provider}/${t.model} ${t.label}`.toLowerCase().includes(e)):c).slice(0,60)},[c,b]);return(0,h.jsxs)(`div`,{ref:S,className:d(`relative`,g),children:[(0,h.jsxs)(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center gap-1.5 rounded-md border border-border bg-muted px-2 py-1.5 text-left text-xs transition-colors hover:border-primary/45 hover:bg-muted/80`,children:[(0,h.jsx)(s,{className:`h-3.5 w-3.5 shrink-0 text-primary`}),(0,h.jsx)(`span`,{className:d(`min-w-0 flex-1 truncate`,e?`text-foreground`:`text-muted-foreground`),children:e?i?`${i}/${e}`:e:l??_(`activity:model.runDefault`)}),(0,h.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),v&&(0,h.jsxs)(`div`,{className:`sdd-rise absolute z-50 mt-1 max-h-72 w-full min-w-[240px] overflow-hidden rounded-md border border-border/80 bg-popover shadow-xl`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b border-border/70 bg-muted/20 px-2 py-1.5`,children:[(0,h.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:_(`activity:model.filterPlaceholder`),className:`min-w-0 flex-1 bg-transparent text-xs outline-none placeholder:text-muted-foreground`}),b&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>x(``),className:`text-muted-foreground hover:text-foreground`,children:(0,h.jsx)(r,{className:`h-3 w-3`})})]}),(0,h.jsxs)(`div`,{className:`max-h-60 overflow-y-auto py-1`,children:[m&&(0,h.jsxs)(`button`,{type:`button`,onClick:()=>{m(),y(!1)},className:`flex w-full items-center gap-1.5 px-2 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:[(0,h.jsx)(o,{className:`h-3 w-3`}),` `,u??_(`activity:model.useRunDefault`)]}),C.map(t=>{let r=t.model===e&&(!i||t.provider===i);return(0,h.jsxs)(`button`,{type:`button`,onClick:()=>{f(t.model,t.provider),y(!1)},className:d(`flex w-full items-start gap-1.5 px-2 py-1.5 text-left text-xs transition-colors hover:bg-muted`,r?`bg-primary/8 text-primary`:`text-foreground`),children:[r?(0,h.jsx)(n,{className:`mt-0.5 h-3 w-3 shrink-0 text-primary`}):(0,h.jsx)(`span`,{className:`w-3 shrink-0`}),(0,h.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,h.jsx)(`span`,{className:`block truncate`,children:t.label}),t.description&&(0,h.jsx)(`span`,{className:`mt-0.5 block truncate text-[10px] text-muted-foreground`,children:t.description})]}),(0,h.jsx)(`span`,{className:`mt-0.5 shrink-0 font-mono text-[9px] text-muted-foreground`,children:t.provider})]},`${t.provider}/${t.model}`)}),C.length===0&&(0,h.jsx)(`div`,{className:`px-2 py-3 text-center text-[11px] text-muted-foreground`,children:c.length===0?_(`activity:model.loading`):_(`activity:model.noMatch`)})]})]})]})}export{m as n,g as t};
|