#!/usr/bin/env node
import {d}from'./chunk-7YTAA6XA.js';import'./chunk-XHJ27CER.js';import n from'chalk';async function w(c){let y=process.cwd(),h=parseInt(c.limit||"20",10),i=await d(y,{limit:h});if(i.length===0){c.json?console.log(JSON.stringify({entries:[],byDate:{},hotSymbols:[],authors:[]},null,2)):console.log(n.gray(`
No lore entries found.
`));return}let r=new Map;for(let o of i){let t=o.timestamp.slice(0,10);r.has(t)||r.set(t,[]),r.get(t).push(o);}let a=new Map;for(let o of i)for(let t of o.symbols_touched||[])a.set(t,(a.get(t)||0)+1);let g=Array.from(a.entries()).sort(([,o],[,t])=>t-o).slice(0,10).map(([o,t])=>({symbol:o,count:t})),l=new Map;for(let o of i){let t=o.author,e=l.get(t);e?(e.count++,o.agent&&(e.hasAgent=true),o.timestamp>e.lastActive&&(e.lastActive=o.timestamp)):l.set(t,{count:1,hasAgent:o.agent!=null,lastActive:o.timestamp});}if(c.json){let o={};for(let[t,e]of r)o[t]=e.map(s=>({id:s.id,type:s.type||"note",title:s.title,author:s.author,symbols:s.symbols_touched||[]}));console.log(JSON.stringify({total:i.length,byDate:o,hotSymbols:g,authors:Array.from(l.entries()).map(([t,e])=>({id:t,hasAgent:e.hasAgent,entries:e.count,lastActive:e.lastActive}))},null,2));return}let f={"agent-session":n.hex("#818cf8"),"human-note":n.hex("#34d399"),decision:n.hex("#fbbf24"),review:n.hex("#c084fc"),incident:n.hex("#f87171"),milestone:n.hex("#60a5fa")};console.log(n.magenta(`
  Lore Timeline (${i.length} entries)
`));for(let[o,t]of r){console.log(n.white.bold(`  ${o}`)+n.gray(` (${t.length} entries)`));for(let e of t){let s=e.type||"note",u=f[s]||n.white,d=e.timestamp.slice(11,16),p=e.agent?"\u{1F916}":"\u{1F464}";console.log(`    ${n.gray(d)} ${u(s.padEnd(14))} ${n.white(e.title)}`),console.log(`           ${p} ${n.gray(e.author)}  ${(e.symbols_touched||[]).slice(0,4).map(b=>n.cyan(b)).join(" ")}`);}console.log();}if(g.length>0){console.log(n.white("  Hot Symbols:"));for(let{symbol:o,count:t}of g.slice(0,5)){let e="\u2588".repeat(Math.min(t,20));console.log(`    ${n.cyan(o.padEnd(25))} ${n.gray(e)} ${t}`);}console.log();}if(l.size>0){console.log(n.white("  Active Authors:"));for(let[o,t]of l){let e=t.hasAgent?"\u{1F916}":"\u{1F464}";console.log(`    ${e} ${n.white(o)} - ${t.count} entries`);}console.log();}}export{w as loreTimelineCommand};