const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./D3qVY-Cc2.js","./Cx_-1PHK2.js","./DrKWWDpL.js","./2PQNgpBd.js","./DsanjglN.js","./CbGRcr-D.js","./DgZn9uJn.js","./CudpqN6Z.js","./DYP3EJMY.js","./DTkg6Mnx.js","./CX8DOZuw2.js","./DsQIgu-4.js","./DOqzs8kl2.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./CxlOpib82.js","./DeO5NWhN.js","./Czb-RtcG.js","./C0nwgWmB.js","./B_DA9RKE2.js","./BlapV1mo.js","./bG-fsHMS.js","./D-eE9s2f.js","./CWxOfblT.js","./DlZwu-Y7.js"])))=>i.map(i=>d[i]);
import{n as e,t}from"./DsQIgu-4.js";import{t as n}from"./CvFbqtf9.js";e();var r=.05,i=14;async function a(e){if(e.length===0)return{strengthened:0,skipped:0};let{getNexusNativeDb:n}=await t(async()=>{let{getNexusNativeDb:e}=await import(`./D3qVY-Cc2.js`);return{getNexusNativeDb:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),import.meta.url),i=n();if(!i)return{strengthened:0,skipped:0};try{i.prepare(`SELECT relation_id FROM nexus_relation_weights LIMIT 1`).get()}catch{return{strengthened:0,skipped:0}}let a=new Date().toISOString().replace(`T`,` `).slice(0,19),o=0,s=0,c=i.prepare(`
    INSERT INTO nexus_relation_weights (relation_id, weight, last_accessed_at, co_accessed_count)
    SELECT id, MIN(1.0, ${r}), ?, 1
      FROM nexus_relations
     WHERE source_id = ? AND target_id = ?
    ON CONFLICT(relation_id) DO UPDATE SET
      weight            = MIN(1.0, nexus_relation_weights.weight + ${r}),
      co_accessed_count = nexus_relation_weights.co_accessed_count + 1,
      last_accessed_at  = excluded.last_accessed_at
  `);for(let t of e)try{let e=c.run(a,t.sourceId,t.targetId);(typeof e.changes==`number`?e.changes:0)>0?o++:s++}catch{s++}return{strengthened:o,skipped:s}}async function o(){let{getNexusNativeDb:e}=await t(async()=>{let{getNexusNativeDb:e}=await import(`./D3qVY-Cc2.js`);return{getNexusNativeDb:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),import.meta.url),n=e();if(!n)return{updated:0,halfLifeDays:i,decayPerDay:1-.5**(1/i)};let r=Number.parseFloat({}.CLEO_PLASTICITY_HALFLIFE_DAYS??String(i));if(!Number.isFinite(r)||r<=0)return{updated:0,halfLifeDays:i,decayPerDay:1-.5**(1/i)};let a=1-.5**(1/r);try{n.prepare(`SELECT weight, last_accessed_at FROM nexus_relation_weights LIMIT 1`).get()}catch{return{updated:0,halfLifeDays:r,decayPerDay:a}}let o=n.prepare(`
    UPDATE nexus_relation_weights
    SET weight = MAX(0.0, weight * EXP(LN(0.5) * (julianday('now') - julianday(last_accessed_at)) / ?))
    WHERE last_accessed_at IS NOT NULL AND weight > 0.001
  `);try{let e=o.run(r);return{updated:typeof e.changes==`number`?e.changes:0,halfLifeDays:r,decayPerDay:a}}catch{return{updated:0,halfLifeDays:r,decayPerDay:a}}}function s(e){let t=e.trim();if(t.startsWith(`[`))try{let e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}return t.split(`,`).map(e=>e.trim()).filter(Boolean)}async function c(e,r=30){let{getBrainDb:i,getBrainNativeDb:a}=await t(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__vite__mapDeps([21,22,2,11,9,8,17,6,5,7,10,12,13,14,15,16,18,19,23,24,25]),import.meta.url);await i(e);let o=a();if(!o)return[];try{o.prepare(`SELECT 1 FROM brain_retrieval_log LIMIT 1`).get()}catch{return[]}let c=new Date(Date.now()-r*24*60*60*1e3).toISOString().replace(`T`,` `).slice(0,19),l=[];try{l=n(o.prepare(`SELECT entry_ids FROM brain_retrieval_log WHERE created_at >= ? LIMIT 1000`),c)}catch{return[]}let u=new Set,d=[];for(let e of l){let t=s(e.entry_ids);if(!(t.length<2))for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let r=t[e],i=t[n];if(!r||!i)continue;let a=`${r}|${i}`,o=`${i}|${r}`;u.has(a)||(u.add(a),d.push({sourceId:r,targetId:i})),u.has(o)||(u.add(o),d.push({sourceId:i,targetId:r}))}}return d}export{o as applyPlasticityDecay,c as extractNexusPairsFromRetrievalLog,a as strengthenNexusCoAccess};