#!/usr/bin/env node
import {a as a$1}from'./chunk-LKAT7IAK.js';import'./chunk-XHJ27CER.js';import*as a from'fs';import*as d from'path';import*as y from'os';import n from'chalk';import*as f from'js-yaml';var b=d.join(y.homedir(),".paradigm","notebooks"),m=".paradigm/notebooks",$="nb-",k=".yaml";async function x(e={}){let s=process.cwd(),c=a$1.command("notebook-list").start("Listing notebook entries",{cwd:s}),t=e.agent||"all",r=u(s,t==="all"?void 0:t);if(e.json){console.log(JSON.stringify({count:r.length,entries:r.map(w)},null,2)),c.success(`Found ${r.length} entries`);return}if(console.log(n.blue(`
\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510`)),console.log(n.blue("\u2502")+n.white.bold("  paradigm notebook list                           ")+n.blue("\u2502")),console.log(n.blue("\u2502")+n.gray(`  Agent: ${t}`.padEnd(50))+n.blue("\u2502")),console.log(n.blue(`\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
`)),r.length===0){console.log(n.yellow("  No notebook entries found.")),console.log(n.gray(`  Add entries via paradigm_notebook_add or paradigm_notebook_promote.
`)),c.success("No entries found");return}for(let o of r){let i=o.concepts.join(", ")||n.gray("none"),l=o.appliedCount>0?n.green(`${o.appliedCount}x applied`):n.gray("unused");console.log(`  ${n.white.bold(o.id)}`),console.log(`    ${n.gray(o.context.slice(0,80))}`),console.log(`    Concepts: ${i}  |  ${l}  |  Confidence: ${(o.confidence*100).toFixed(0)}%`),console.log("");}c.success(`Listed ${r.length} entries`);}async function N(e,s={}){let c=process.cwd(),t=a$1.command("notebook-show").start(`Showing notebook ${e}`,{cwd:c}),o=u(c,s.agent).find(i=>i.id===e);if(!o){s.json?console.log(JSON.stringify({error:`Entry "${e}" not found`})):console.log(n.red(`
  Entry "${e}" not found.
`)),t.error(`Entry ${e} not found`);return}if(s.json){console.log(JSON.stringify(o,null,2)),t.success(`Showed entry ${e}`);return}console.log(n.blue(`
  Notebook Entry: ${e}
`)),console.log(`  ${n.white.bold("Context:")} ${o.context}`),console.log(`  ${n.white.bold("Concepts:")} ${o.concepts.join(", ")}`),console.log(`  ${n.white.bold("Tags:")} ${o.tags.join(", ")||"(none)"}`),console.log(`  ${n.white.bold("Confidence:")} ${(o.confidence*100).toFixed(0)}%`),console.log(`  ${n.white.bold("Applied:")} ${o.appliedCount} times`),console.log(`  ${n.white.bold("Provenance:")} ${o.provenance.source}${o.provenance.loreEntryId?` (${o.provenance.loreEntryId})`:""}`),console.log(`  ${n.white.bold("Created:")} ${o.created}`),console.log(`  ${n.white.bold("Updated:")} ${o.updated}`),console.log(`
  ${n.white.bold("Snippet:")}`),console.log(n.gray("  \u2500".repeat(25)));for(let i of o.snippet.split(`
`))console.log(`  ${i}`);console.log(n.gray("  \u2500".repeat(25))),console.log(""),t.success(`Showed entry ${e}`);}async function S(e={}){let s=process.cwd(),c=a$1.command("notebook-export").start("Exporting notebook entries",{cwd:s}),t=u(s,e.agent),r=e.format||"yaml";console.log(r==="json"?JSON.stringify(t,null,2):f.dump(t,{lineWidth:120,noRefs:true})),c.success(`Exported ${t.length} entries as ${r}`);}function u(e,s){let c=[],t=[];if(s)t.push(d.join(b,s)),t.push(d.join(e,m,s));else for(let o of [b,d.join(e,m)])if(a.existsSync(o))try{let i=a.readdirSync(o,{withFileTypes:!0}).filter(l=>l.isDirectory()).map(l=>d.join(o,l.name));t.push(...i);}catch{}let r=new Set;for(let o of t)if(a.existsSync(o))try{let i=a.readdirSync(o).filter(l=>l.startsWith($)&&l.endsWith(k));for(let l of i)try{let h=a.readFileSync(d.join(o,l),"utf-8"),p=f.load(h);p?.id&&!r.has(p.id)&&(r.add(p.id),c.push(p));}catch{}}catch{}return c.sort((o,i)=>i.appliedCount-o.appliedCount)}function w(e){return {id:e.id,context:e.context.slice(0,100),concepts:e.concepts,appliedCount:e.appliedCount,confidence:e.confidence,provenance:e.provenance.source}}export{S as notebookExportCommand,x as notebookListCommand,N as notebookShowCommand};