#!/usr/bin/env node
import {a}from'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as o from'fs';import*as c from'path';import l from'chalk';import b from'ora';function D(t){let a=t.match(/^(\d+)(d|h|m)$/);if(!a)return null;let[,e,s]=a,n=parseInt(e,10);switch(s){case "d":return n*24*60*60*1e3;case "h":return n*60*60*1e3;case "m":return n*60*1e3;default:return null}}function m(t,a){let e=[];if(!o.existsSync(t))return e;let s=o.readdirSync(t,{withFileTypes:true});for(let n of s){let f=c.join(t,n.name);if(n.isDirectory())e.push(...m(f,a));else if(n.isFile())try{let u=o.statSync(f),r=Date.now()-u.mtimeMs;if(r>a){let d=Math.floor(r/864e5);e.push({path:f,age:`${d}d`});}}catch{}}return e}async function v(t){let a$1=process.env.HOME||process.env.USERPROFILE||"~",e=c.join(a$1,".paradigm"),s=b();if(!o.existsSync(e)){console.log(l.yellow(`
No ~/.paradigm/ directory found.
`));return}let n=t.olderThan||"90d",f=D(n);f||(console.log(l.red(`
Invalid duration: ${n}`)),console.log(l.gray(`Use format: 90d, 30d, 7d, 24h, etc.
`)),process.exit(1)),console.log(l.blue(`
Global Brain Rotation
`)),console.log(l.gray(`  Scanning ~/.paradigm/ for files older than ${n}...
`)),s.start("Scanning...");let u=["wisdom","lore","history","cache"],r=[];for(let i of u){let g=c.join(e,i),y=m(g,f);r.push(...y);}if(s.stop(),r.length===0){console.log(l.green(`  No files older than ${n} found.
`));return}console.log(l.gray(`  Found ${r.length} files older than ${n}:
`));for(let i of r.slice(0,20)){let g=c.relative(e,i.path);console.log(l.gray(`    ${i.age} old - ${g}`));}if(r.length>20&&console.log(l.gray(`    ... and ${r.length-20} more`)),t.dryRun){console.log(l.yellow(`
  Dry run - no files deleted.
`)),a.command("global-clean").info("Dry run completed",{count:r.length,olderThan:n});return}s.start(`Deleting ${r.length} files...`);let d=0;for(let i of r)try{o.unlinkSync(i.path),d++;}catch{}s.succeed(`Deleted ${d} files older than ${n}`);for(let i of u){let g=c.join(e,i);p(g);}console.log(""),a.command("global-clean").success("Global brain rotation completed",{deleted:d,olderThan:n});}function p(t){if(!o.existsSync(t))return;let a=o.readdirSync(t);for(let e of a){let s=c.join(t,e);o.statSync(s).isDirectory()&&p(s);}if(o.readdirSync(t).length===0)try{o.rmdirSync(t);}catch{}}export{v as globalCleanCommand};