#!/usr/bin/env node
import {c as c$1,b}from'./chunk-5TAVYPOV.js';import*as c from'fs';import*as l from'path';import*as w from'os';import*as u from'js-yaml';var x={};c$1(x,{addNotebookEntry:()=>N,incrementApplied:()=>P,loadNotebookEntries:()=>E,promoteFromLore:()=>L,searchNotebooks:()=>j});function E(s,a,e){let r=new Map,i=l.join(d,s);h(i,r);let t=l.join(a,m,s);h(t,r);let n=Array.from(r.values());if(e?.concepts&&e.concepts.length>0){let p=new Set(e.concepts.map(o=>o.toLowerCase()));n=n.filter(o=>o.concepts.some(f=>p.has(f.toLowerCase())));}if(e?.tags&&e.tags.length>0){let p=new Set(e.tags.map(o=>o.toLowerCase()));n=n.filter(o=>o.tags.some(f=>p.has(f.toLowerCase())));}return n.sort((p,o)=>o.appliedCount-p.appliedCount)}function h(s,a){if(c.existsSync(s))try{let e=c.readdirSync(s).filter(r=>r.startsWith(O)&&r.endsWith(g));for(let r of e)try{let i=c.readFileSync(l.join(s,r),"utf-8"),t=u.load(i);t?.id&&a.set(t.id,t);}catch{}}catch{}}function j(s,a,e){let r=E(s,e),i=a.toLowerCase();return r.filter(t=>t.context.toLowerCase().includes(i)||t.snippet.toLowerCase().includes(i)||t.concepts.some(n=>n.toLowerCase().includes(i))||t.tags.some(n=>n.toLowerCase().includes(i)))}function N(s,a,e,r){let i=new Date().toISOString(),t=(a.concepts[0]||"entry").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),n=Date.now().toString(36),p=`nb-${t}-${n}`,o={...a,id:p,appliedCount:0,created:i,updated:i},f=e==="global"?l.join(d,s):l.join(r||process.cwd(),m,s);c.existsSync(f)||c.mkdirSync(f,{recursive:true});let y=`${p}${g}`,b=l.join(f,y),S=u.dump(o,{lineWidth:120,noRefs:true,sortKeys:false});return c.writeFileSync(b,S,"utf-8"),{entry:o,filePath:b}}async function L(s,a,e,r="global"){let{loadLoreEntry:i}=await import('./lore-loader-RVQI5GXL.js'),t=await i(e,a);if(!t)return null;let n=[];if(t.symbols_touched)for(let f of t.symbols_touched){let y=f.replace(/^[#$^!~]/,"").toLowerCase();n.push(y);}let p=t.summary||"";t.body&&(p+=`

`+t.body);let o={source:"lore",loreEntryId:a,originProject:l.basename(e),createdBy:s};return N(s,{context:t.title||`Promoted from ${a}`,snippet:p,provenance:o,confidence:t.confidence??.7,concepts:n,tags:t.tags||[]},r,e)}function P(s,a,e){let r=l.join(e,m,s),i=l.join(d,s);for(let t of [r,i]){let n=l.join(t,`${a}${g}`);if(c.existsSync(n))try{let p=c.readFileSync(n,"utf-8"),o=u.load(p);if(o)return o.appliedCount=(o.appliedCount||0)+1,o.updated=new Date().toISOString(),c.writeFileSync(n,u.dump(o,{lineWidth:120,noRefs:!0,sortKeys:!1}),"utf-8"),!0}catch{}}return  false}var d,m,O,g,$=b(()=>{d=l.join(w.homedir(),".paradigm","notebooks"),m=".paradigm/notebooks",O="nb-",g=".yaml";});export{E as a,j as b,N as c,L as d,P as e,x as f,$ as g};