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"./DrKWWDpL.js";import{n as e,t}from"./DsQIgu-4.js";import{t as n}from"./DYP3EJMY.js";import{t as r}from"./DTkg6Mnx.js";import"./bG-fsHMS.js";import"./ImGf_A8f.js";import"./BFyEzYu52.js";import"./X_DUeLZp2.js";n(),e();var i=r(`maintenance`),a=500;async function o(e,n){let r=n?.dryRun??!1,o=n?.maxDeletePerRun??a,s={},c=0,l=0,{getBrainDb:u,getBrainNativeDb:d}=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 u(e);let f=d();if(!f)return{deleted:0,wouldDelete:0,dryRun:r,byTable:{}};let p=[{table:`brain_decisions`,dateCol:`created_at`},{table:`brain_patterns`,dateCol:`extracted_at`},{table:`brain_learnings`,dateCol:`created_at`},{table:`brain_observations`,dateCol:`created_at`}];for(let{table:e,dateCol:t}of p)try{let n=f.prepare(`SELECT COUNT(*) AS cnt
           FROM ${e}
           WHERE prune_candidate = 1
             AND COALESCE(quality_score, 0.5) < 0.2
             AND COALESCE(citation_count, 0) = 0
             AND julianday('now') - julianday(${t}) > 30`).all()[0]?.cnt??0;l+=n,s[e]=n}catch{s[e]=0}if(r)return i.info(`[prune-sweep] dry-run: would delete ${l} entries across 4 tables (cap=${o})`),{deleted:0,wouldDelete:l,dryRun:r,byTable:s};let m=o,h={};for(let{table:e,dateCol:t}of p){if(m<=0){h[e]=0;continue}try{let n=Math.min(s[e]??0,m);if(n<=0){h[e]=0;continue}let r=f.prepare(`DELETE FROM ${e}
           WHERE id IN (
             SELECT id FROM ${e}
             WHERE prune_candidate = 1
               AND COALESCE(quality_score, 0.5) < 0.2
               AND COALESCE(citation_count, 0) = 0
               AND julianday('now') - julianday(${t}) > 30
             LIMIT ?
           )`).run(n).changes??0;h[e]=r,c+=r,m-=r}catch{h[e]=0}}return i.info(`[prune-sweep] step-9f: deleted ${c} entries (would-qualify=${l}, cap=${o})`),{deleted:c,wouldDelete:l,dryRun:r,byTable:h}}export{o as t};