#!/usr/bin/env node
import {d}from'./chunk-WS2N27RX.js';import'./chunk-5TAVYPOV.js';import o from'chalk';async function L(r){let A=process.cwd(),u=await d(A,{symbol:r.symbol,tag:r.tag,author:r.author,hasAssessment:true});if(u.length===0){r.json?console.log(JSON.stringify({totalAssessed:0,message:"No assessed entries found"},null,2)):(console.log(o.gray(`
  No assessed lore entries found.
`)),console.log(o.gray("  Use `paradigm lore assess <id> <correct|partial|incorrect>` to assess entries.\n")));return}let F=u.filter(e=>e.confidence!=null),c=u.length,f=F.length,l={correct:0,partial:0,incorrect:0},h=0,$=0,b=0;for(let e of u){let n=e.assessment.verdict;l[n]++;let t=n==="correct"?1:n==="partial"?.5:0;h+=t,e.confidence!=null&&($+=e.confidence,b+=Math.abs(t-e.confidence));}let y=h/c,m=f>0?$/f:null,s=f>0?1-b/f:null,i;if(r.groupBy&&c>0){let e=new Map;for(let n of u){let t=[];r.groupBy==="symbol"?t=n.symbols_touched||[]:r.groupBy==="tag"?t=n.tags||[]:r.groupBy==="type"&&(t=[n.type||"agent-session"]);for(let a of t)e.has(a)||e.set(a,[]),e.get(a).push(n);}i=Array.from(e.entries()).map(([n,t])=>{let a=t.filter(d=>d.confidence!=null),v={correct:0,partial:0,incorrect:0},C=0,B=0,S=0;for(let d of t){let p=d.assessment.verdict;v[p]++;let k=p==="correct"?1:p==="partial"?.5:0;C+=k,d.confidence!=null&&(B+=d.confidence,S+=Math.abs(k-d.confidence));}return {key:n,total:t.length,accuracyRate:C/t.length,avgConfidence:a.length>0?B/a.length:null,calibrationScore:a.length>0?1-S/a.length:null,verdictBreakdown:v}}).sort((n,t)=>t.total-n.total);}if(r.json){console.log(JSON.stringify({totalAssessed:c,totalWithConfidence:f,accuracyRate:Math.round(y*1e3)/1e3,avgConfidence:m!=null?Math.round(m*1e3)/1e3:null,calibrationScore:s!=null?Math.round(s*1e3)/1e3:null,verdictBreakdown:l,...i?{groups:i}:{}},null,2));return}let w=c<5?o.gray(`  (Low sample: N=${c}. Stats may not be representative.)`):c<15?o.gray(`  (Moderate sample: N=${c}. Trends are directional.)`):"";console.log(o.magenta(`
  Calibration Report (${c} assessed entries)
`)),w&&console.log(w+`
`);let g=c;console.log(o.white("  Verdicts:")),console.log(`    ${o.green("correct")}:   ${l.correct}/${g} (${(l.correct/g*100).toFixed(0)}%)`),console.log(`    ${o.yellow("partial")}:   ${l.partial}/${g} (${(l.partial/g*100).toFixed(0)}%)`),console.log(`    ${o.red("incorrect")}: ${l.incorrect}/${g} (${(l.incorrect/g*100).toFixed(0)}%)`),console.log(),console.log(o.white("  Scores:"));let M=y>=.8?o.green:y>=.5?o.yellow:o.red;if(console.log(`    Accuracy rate:    ${M(y.toFixed(3))}`),m!=null&&console.log(`    Avg confidence:   ${m.toFixed(3)}`),s!=null){let e=s>=.9?o.green:s>=.7?o.yellow:o.red;console.log(`    Calibration:      ${e(s.toFixed(3))} (1.0 = perfect)`);}if(console.log(),i&&i.length>0){console.log(o.white(`  By ${r.groupBy}:`));for(let e of i.slice(0,15)){let n=e.accuracyRate>=.8?o.green:e.accuracyRate>=.5?o.yellow:o.red,t=e.calibrationScore!=null?` cal:${e.calibrationScore.toFixed(2)}`:"";console.log(`    ${o.cyan(e.key.padEnd(25))} ${n(`acc:${e.accuracyRate.toFixed(2)}`)}${t}  (${e.verdictBreakdown.correct}/${e.verdictBreakdown.partial}/${e.verdictBreakdown.incorrect}) N=${e.total}`);}console.log();}}export{L as loreCalibrationCommand};