import"../chunks/Bzak7iHL.js";import{o as Ce,a as Le}from"../chunks/CNjeV5xa.js";import{p as _e,f as we,g as e,a as Te,u as P,e as r,r as s,d as o,t as S,h as w,s as j,c as xe,n as he}from"../chunks/CvjSAYrz.js";import{d as Ae,s as g,a as z}from"../chunks/FzvEaXMa.js";import{i as G}from"../chunks/ciN1mm2W.js";import{e as oe,i as ke}from"../chunks/DTnG8poT.js";import{c as Re,a as v,f as m}from"../chunks/BsvCUYx-.js";import{s as ne,r as Fe}from"../chunks/CNfQDikv.js";import{b as Ne}from"../chunks/CVpUe0w3.js";import{s as pe}from"../chunks/DPl3NjBv.js";import{s as re}from"../chunks/Bhad70Ss.js";import{N as Ie}from"../chunks/DzfRjky4.js";function Me(n){return n>=.92?"near-identical":n>=.8?"strong":"weak"}function ge(n){const i=Me(n);return i==="near-identical"?"var(--color-decay)":i==="strong"?"var(--color-warning)":"#fde047"}function Ze(n){const i=Me(n);return i==="near-identical"?"Near-identical":i==="strong"?"Strong match":"Weak match"}function Ee(n){return n>.7?"#10b981":n>.4?"#f59e0b":"#ef4444"}function Oe(n){if(!n||n.length===0)return null;let i=n[0],d=Number.isFinite(i.retention)?i.retention:-1/0;for(let u=1;ud&&(i=b,d=_)}return i}function Pe(n,i){return n.filter(d=>d.similarity>=i)}function be(n){return n.map(i=>i.id).slice().sort().join("|")}function Be(n,i=80){if(!n)return"";const d=n.trim().replace(/\s+/g," ");return d.length<=i?d:d.slice(0,i)+"…"}function ye(n){if(!n||typeof n!="string")return"";const i=new Date(n);return Number.isNaN(i.getTime())?"":i.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function He(n,i=4){return Array.isArray(n)?n.slice(0,i):[]}var Ke=m('WINNER'),Ue=m(' '),We=m('
'),je=m('

'),ze=m('
');function Ge(n,i){_e(i,!0);let d=j(!1);const u=P(()=>Oe(i.memories)),b=P(()=>e(u)?i.memories.filter(x=>x.id!==e(u).id).map(x=>x.id):[]);function _(){i.onMerge&&e(u)&&i.onMerge(e(u).id,e(b))}var k=Re(),V=we(k);{var le=x=>{var X=ze(),B=r(X),Y=r(B),h=r(Y),C=r(h),ee=r(C);s(C);var H=o(C,2),de=r(H,!0);s(H);var K=o(H,2),q=r(K);s(K),s(h);var L=o(h,2),U=r(L);s(L),s(Y);var W=o(Y,2),ce=r(W);s(W),s(B);var R=o(B,2);oe(R,21,()=>i.memories,T=>T.id,(T,c)=>{var M=je(),N=r(M),I=o(N,2),t=r(I),a=r(t),l=r(a,!0);s(a);var p=o(a,2);{var Z=y=>{var A=Ke();v(y,A)};G(p,y=>{e(c).id===e(u).id&&y(Z)})}var D=o(p,2);oe(D,17,()=>He(e(c).tags,4),ke,(y,A)=>{var O=Ue(),me=r(O,!0);s(O),S(()=>g(me,e(A))),v(y,O)}),s(t);var f=o(t,2),E=r(f,!0);s(f);var ae=o(f,2);{var Q=y=>{var A=We(),O=r(A,!0);s(A),S(me=>g(O,me),[()=>ye(e(c).createdAt)]),v(y,A)},ve=P(()=>ye(e(c).createdAt));G(ae,y=>{e(ve)&&y(Q)})}s(I);var se=o(I,2),$=r(se),De=r($);s($);var fe=o($,2),Se=r(fe);s(fe),s(se),s(M),S((y,A,O)=>{pe(M,1,`group flex items-start gap-3 rounded-xl border border-synapse/5 bg-white/[0.02] p-3 transition-all duration-200 hover:border-synapse/20 hover:bg-white/[0.04] ${e(c).id===e(u).id?"ring-1 ring-recall/30":""}`),re(N,`background: ${(Ie[e(c).nodeType]||"#8B95A5")??""}`),ne(N,"title",e(c).nodeType),g(l,e(c).nodeType),pe(f,1,`text-sm text-text leading-relaxed ${e(d)?"whitespace-pre-wrap":""}`),g(E,y),re(De,`width: ${e(c).retention*100}%; background: ${A??""}`),g(Se,`${O??""}%`)},[()=>e(d)?e(c).content:Be(e(c).content),()=>Ee(e(c).retention),()=>(e(c).retention*100).toFixed(0)]),v(T,M)}),s(R);var te=o(R,2),J=r(te),F=o(J,2),ue=r(F,!0);s(F);var ie=o(F,2);s(te),s(X),S((T,c,M,N,I,t,a,l)=>{re(C,`color: ${T??""}`),g(ee,`${c??""}%`),g(de,M),g(q,`· ${i.memories.length??""} memories`),ne(L,"aria-valuenow",N),re(U,`width: ${I??""}%; background: ${t??""}; box-shadow: 0 0 12px ${a??""}66`),pe(W,1,`flex-shrink-0 rounded-full border px-3 py-1 text-xs font-medium ${i.suggestedAction==="merge"?"border-recall/40 bg-recall/10 text-recall":"border-dream-glow/40 bg-dream/10 text-dream-glow"}`),g(ce,`Suggested: ${i.suggestedAction==="merge"?"Merge":"Review"}`),ne(J,"title",`Merge all into highest-retention memory (${l??""}%)`),ne(F,"aria-expanded",e(d)),g(ue,e(d)?"Collapse":"Review")},[()=>ge(i.similarity),()=>(i.similarity*100).toFixed(1),()=>Ze(i.similarity),()=>Math.round(i.similarity*100),()=>(i.similarity*100).toFixed(1),()=>ge(i.similarity),()=>ge(i.similarity),()=>(e(u).retention*100).toFixed(0)]),z("click",J,_),z("click",F,()=>w(d,!e(d))),z("click",ie,function(...T){var c;(c=i.onDismiss)==null||c.apply(this,T)}),v(x,X)};G(V,x=>{i.memories.length>0&&e(u)&&x(le)})}v(n,k),Te()}Ae(["click"]);var Ve=m(' Detecting…',1),Xe=m(' Error',1),Ye=m(' ',1),qe=m(`
Couldn't detect duplicates
`),Je=m('
'),Qe=m('
'),$e=m('
·
No duplicates found above threshold.
Memory is clean.
'),et=m('
'),tt=m('
'),it=m('
'),at=m(`

Memory Hygiene — Duplicate Detection

Cosine-similarity clustering over embeddings. Merges reinforce the winner's FSRS state; losers inherit into the merged node. Dismissed clusters are hidden for this session only.

`);function ft(n,i){_e(i,!0);let d=j(.8),u=j(xe([])),b=j(xe(new Set)),_=j(!0),k=j(null),V;async function le(t){return await new Promise(l=>setTimeout(l,450)),{clusters:Pe([{similarity:.96,suggestedAction:"merge",memories:[{id:"m-001",content:"BUG FIX: Harmony parser dropped `final` channel tokens when tool call followed. Root cause: 5-layer fallback missed the final channel marker when channel switched mid-stream. Solution: added final-channel detector before tool-call pop. Files: src/parser/harmony.rs",nodeType:"fact",tags:["bug-fix","aimo3","parser"],retention:.91,createdAt:"2026-04-12T14:22:00Z"},{id:"m-002",content:"Fixed Harmony parser final-channel bug — 5-layer fallback was missing the final channel marker when a tool call followed. Added detector before tool pop.",nodeType:"fact",tags:["bug-fix","aimo3"],retention:.64,createdAt:"2026-04-13T09:15:00Z"},{id:"m-003",content:"Harmony parser: final channel dropped on tool-call. Patched the fallback stack.",nodeType:"note",tags:["parser"],retention:.38,createdAt:"2026-04-14T11:02:00Z"}]},{similarity:.88,suggestedAction:"merge",memories:[{id:"m-004",content:"DECISION: Use vLLM prefix caching at 0.35 gpu_memory_utilization for AIMO3 submissions. Alternatives considered: sglang (slower cold start), TensorRT-LLM (deployment friction).",nodeType:"decision",tags:["vllm","aimo3","inference"],retention:.84,createdAt:"2026-04-05T18:44:00Z"},{id:"m-005",content:"Chose vLLM with prefix caching (0.35 mem util) over sglang and TensorRT-LLM for AIMO3 inference.",nodeType:"decision",tags:["vllm","aimo3"],retention:.72,createdAt:"2026-04-06T10:30:00Z"}]},{similarity:.83,suggestedAction:"review",memories:[{id:"m-006",content:"Sam prefers to ship one change per Kaggle submission — stacking changes destroyed signal at AIMO3 (30/50 regression from 12 stacked variables).",nodeType:"pattern",tags:["kaggle","methodology","aimo3"],retention:.88,createdAt:"2026-04-04T22:10:00Z"},{id:"m-007",content:"One-variable-at-a-time rule: never stack multiple changes per submission. Paper 2603.27844 proves +/-2 points is noise.",nodeType:"pattern",tags:["kaggle","methodology"],retention:.67,createdAt:"2026-04-08T16:20:00Z"},{id:"m-008",content:"Lesson: stacking 12 changes at AIMO3 cost a submission. Always isolate variables.",nodeType:"note",tags:["methodology"],retention:.42,createdAt:"2026-04-15T08:55:00Z"}]},{similarity:.78,suggestedAction:"review",memories:[{id:"m-009",content:"Dimensional Illusion performance: 7-minute flow poi set, LED config Parthenos overcook preset, tempo 128 BPM.",nodeType:"event",tags:["dimensional-illusion","poi","performance"],retention:.76,createdAt:"2026-03-28T19:45:00Z"},{id:"m-010",content:"Dimensional Illusion set: 7 min, Parthenos LED overcook, 128 BPM.",nodeType:"event",tags:["dimensional-illusion","poi"],retention:.51,createdAt:"2026-04-02T12:12:00Z"}]},{similarity:.76,suggestedAction:"review",memories:[{id:"m-011",content:"Vestige v2.0.7 shipped active forgetting via Anderson 2025 top-down inhibition + Davis Rac1 cascade. Suppress compounds, reversible 24h.",nodeType:"fact",tags:["vestige","release","active-forgetting"],retention:.93,createdAt:"2026-04-17T03:22:00Z"},{id:"m-012",content:"Active Forgetting feature: compounds on each suppress, 24h reversible labile window, violet implosion animation in graph view.",nodeType:"concept",tags:["vestige","active-forgetting"],retention:.81,createdAt:"2026-04-18T09:07:00Z"}]}],t)}}async function x(){w(_,!0),w(k,null);try{const t=await le(e(d));w(u,t.clusters,!0);const a=new Set(e(u).map(p=>be(p.memories))),l=new Set;for(const p of e(b))a.has(p)&&l.add(p);w(b,l,!0)}catch(t){w(k,t instanceof Error?t.message:"Failed to detect duplicates",!0),w(u,[],!0)}finally{w(_,!1)}}function X(){clearTimeout(V),V=setTimeout(x,250)}function B(t){const a=new Set(e(b));a.add(t),w(b,a,!0)}function Y(t,a,l){console.log("Merge cluster",t,{winnerId:a,loserIds:l}),B(t)}const h=P(()=>e(u).map(t=>({c:t,key:be(t.memories)})).filter(({key:t})=>!e(b).has(t))),C=P(()=>e(h).reduce((t,{c:a})=>t+a.memories.length,0)),ee=50,H=P(()=>e(h).length>ee),de=P(()=>e(H)?e(h).slice(0,ee):e(h));Ce(()=>x()),Le(()=>clearTimeout(V));var K=at(),q=o(r(K),2),L=r(q),U=o(r(L),2);Fe(U);var W=o(U,2),ce=r(W);s(W),s(L);var R=o(L,2),te=r(R);{var J=t=>{var a=Ve();he(2),v(t,a)},F=t=>{var a=Xe();he(2),v(t,a)},ue=t=>{var a=Ye(),l=o(we(a),2),p=r(l);s(l),S(()=>g(p,`${e(h).length??""} ${e(h).length===1?"cluster":"clusters"}, ${e(C)??""} potential duplicate${e(C)===1?"":"s"}`)),v(t,a)};G(te,t=>{e(_)?t(J):e(k)?t(F,1):t(ue,!1)})}s(R);var ie=o(R,2);s(q);var T=o(q,2);{var c=t=>{var a=qe(),l=o(r(a),2),p=r(l,!0);s(l);var Z=o(l,2);s(a),S(()=>g(p,e(k))),z("click",Z,x),v(t,a)},M=t=>{var a=Qe();oe(a,20,()=>Array(3),ke,(l,p)=>{var Z=Je();v(l,Z)}),s(a),v(t,a)},N=t=>{var a=$e();v(t,a)},I=t=>{var a=it(),l=r(a);{var p=D=>{var f=et(),E=r(f);s(f),S(()=>g(E,`Showing first 50 of ${e(h).length??""} clusters. Raise the threshold to narrow results.`)),v(D,f)};G(l,D=>{e(H)&&D(p)})}var Z=o(l,2);oe(Z,17,()=>e(de),({c:D,key:f})=>f,(D,f)=>{let E=()=>e(f).c,ae=()=>e(f).key;var Q=tt(),ve=r(Q);Ge(ve,{get similarity(){return E().similarity},get memories(){return E().memories},get suggestedAction(){return E().suggestedAction},onDismiss:()=>B(ae()),onMerge:(se,$)=>Y(ae(),se,$)}),s(Q),v(D,Q)}),s(a),v(t,a)};G(T,t=>{e(k)?t(c):e(_)?t(M,1):e(h).length===0?t(N,2):t(I,!1)})}s(K),S(t=>{g(ce,`${t??""}%`),ie.disabled=e(_)},[()=>(e(d)*100).toFixed(0)]),z("input",U,X),Ne(U,()=>e(d),t=>w(d,t)),z("click",ie,x),v(n,K),Te()}Ae(["input","click"]);export{ft as component};