const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./BlapV1mo.js","./bG-fsHMS.js","./DrKWWDpL.js","./DsQIgu-4.js","./DTkg6Mnx.js","./DYP3EJMY.js","./DeO5NWhN.js","./DgZn9uJn.js","./CbGRcr-D.js","./CudpqN6Z.js","./CX8DOZuw2.js","./DOqzs8kl2.js","./DIQmuJJZ.js","./D7w7HllH.js","./DB5ifLM-.js","./CxlOpib82.js","./Czb-RtcG.js","./C0nwgWmB.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();async function r(e){let{getBrainDb:n,getBrainNativeDb:r}=await t(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__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);await n(e);let i=r();if(i)try{i.prepare(`CREATE TABLE IF NOT EXISTS brain_usage_log (
          id         INTEGER PRIMARY KEY AUTOINCREMENT,
          entry_id   TEXT    NOT NULL,
          task_id    TEXT,
          used       INTEGER NOT NULL DEFAULT 0,
          outcome    TEXT    NOT NULL DEFAULT 'unknown',
          created_at TEXT    NOT NULL DEFAULT (datetime('now'))
        )`).run(),i.prepare(`CREATE INDEX IF NOT EXISTS idx_brain_usage_log_entry_id
         ON brain_usage_log(entry_id)`).run(),i.prepare(`CREATE INDEX IF NOT EXISTS idx_brain_usage_log_task_id
         ON brain_usage_log(task_id)`).run()}catch{}}async function i(e){let{getBrainDb:n,getBrainNativeDb:r}=await t(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__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);await n(e);let i=r();if(i)for(let e of[`brain_decisions`,`brain_patterns`,`brain_learnings`,`brain_observations`])try{i.prepare(`ALTER TABLE ${e} ADD COLUMN prune_candidate INTEGER DEFAULT 0`).run()}catch{}}function a(e){return e.startsWith(`D-`)||/^D\d/.test(e)?`brain_decisions`:e.startsWith(`P-`)||/^P\d/.test(e)?`brain_patterns`:e.startsWith(`L-`)||/^L\d/.test(e)?`brain_learnings`:e.startsWith(`O-`)||e.startsWith(`CM-`)||/^O/.test(e)?`brain_observations`:null}function o(e,t,n,r,i){if(e)try{e.prepare(`UPDATE ${t}
         SET quality_score = MAX(0.0, MIN(1.0, COALESCE(quality_score, 0.5) + ?)),
             updated_at    = ?
         WHERE id = ?`).run(r,i,n)}catch{}}async function s(e){await r(e),await i(e);let{getBrainDb:s,getBrainNativeDb:c}=await t(async()=>{let{getBrainDb:e,getBrainNativeDb:t}=await import(`./BlapV1mo.js`);return{getBrainDb:e,getBrainNativeDb:t}},__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);await s(e);let l=c(),u=new Date().toISOString();if(!l)return{boosted:0,penalized:0,flaggedForPruning:0,ranAt:u};let d=u.replace(`T`,` `).slice(0,19),f=0,p=0,m=[];try{m=n(l.prepare(`SELECT entry_id, outcome, SUM(used) AS used_count
         FROM brain_usage_log
         WHERE outcome IN ('success', 'failure')
         GROUP BY entry_id, outcome`))}catch{m=[]}for(let e of m){let t=a(e.entry_id);t&&(e.outcome===`success`&&e.used_count>0?(o(l,t,e.entry_id,.05,d),f++):e.outcome===`failure`&&e.used_count>0&&(o(l,t,e.entry_id,-.05,d),p++))}let h=new Date(Date.now()-720*60*60*1e3).toISOString().replace(`T`,` `).slice(0,19),g=0;for(let{table:e,dateCol:t}of[{table:`brain_decisions`,dateCol:`created_at`},{table:`brain_patterns`,dateCol:`extracted_at`},{table:`brain_learnings`,dateCol:`created_at`},{table:`brain_observations`,dateCol:`created_at`}])try{let n=l.prepare(`UPDATE ${e}
           SET prune_candidate = 1
           WHERE COALESCE(citation_count, 0) = 0
             AND ${t} < ?`).run(h);g+=n.changes??0}catch{}return{boosted:f,penalized:p,flaggedForPruning:g,ranAt:u}}export{s as t};