#!/usr/bin/env node
import {c,b}from'./chunk-5TAVYPOV.js';import*as i from'fs';import*as l from'path';import*as k from'os';import*as g from'js-yaml';var $={};c($,{addNotebookEntry:()=>N,classifyNotebookScope:()=>w,incrementApplied:()=>P,loadNotebookEntries:()=>S,promoteFromLore:()=>_,searchNotebooks:()=>O});function S(e,t,n){let r=new Map,a=l.join(u,e);h(a,r);let o=l.join(t,d,e);h(o,r);let c=Array.from(r.values());if(n?.concepts&&n.concepts.length>0){let p=new Set(n.concepts.map(s=>s.toLowerCase()));c=c.filter(s=>s.concepts.some(f=>p.has(f.toLowerCase())));}if(n?.tags&&n.tags.length>0){let p=new Set(n.tags.map(s=>s.toLowerCase()));c=c.filter(s=>s.tags.some(f=>p.has(f.toLowerCase())));}return c.sort((p,s)=>s.appliedCount-p.appliedCount)}function h(e,t){if(i.existsSync(e))try{let n=i.readdirSync(e).filter(r=>r.startsWith(L)&&r.endsWith(y));for(let r of n)try{let a=i.readFileSync(l.join(e,r),"utf-8"),o=g.load(a);o?.id&&t.set(o.id,o);}catch{}}catch{}}function O(e,t,n){let r=S(e,n),a=t.toLowerCase();return r.filter(o=>o.context.toLowerCase().includes(a)||o.snippet.toLowerCase().includes(a)||o.concepts.some(c=>c.toLowerCase().includes(a))||o.tags.some(c=>c.toLowerCase().includes(a)))}function w(e){let t=[e.context,e.snippet,...e.concepts,...e.tags].join(" ").toLowerCase();return ["paradigm","mcp_","mcp tool",".paradigm/","lore entry","lore record","aspect","^gate","portal.yaml",".purpose","sentinel","symphony","ambient nomination","paradigm_"," pan ","agent notebook","concept anchor","symbol system","work log","knowledge stream","nevr.land","neverland"].some(r=>t.includes(r))?"platform-specific":/[#$^!~][a-z][a-z0-9-]{2,}/.test(t)||/\/[a-z0-9_-]{2,}\/[a-z0-9_-]/.test(t)?"project-specific":"generalizable"}function N(e,t,n,r){let a=new Date().toISOString(),o=(t.concepts[0]||t.context.split(" ").slice(0,4).join(" ")||"entry").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,40),p=`nb-${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}-${o}`,s=t.scope??w({context:t.context,snippet:t.snippet,concepts:t.concepts,tags:t.tags}),f={...t,id:p,scope:s,publishable:t.publishable??true,appliedCount:0,created:a,updated:a},m=n==="global"?l.join(u,e):l.join(r||process.cwd(),d,e);i.existsSync(m)||i.mkdirSync(m,{recursive:true});let E=`${p}${y}`,b=l.join(m,E),C=g.dump(f,{lineWidth:120,noRefs:true,sortKeys:false});return i.writeFileSync(b,C,"utf-8"),{entry:f,filePath:b}}async function _(e,t,n,r="global"){let{loadLoreEntry:a}=await import('./lore-loader-RVQI5GXL.js'),o=await a(n,t);if(!o)return null;let c=[];if(o.symbols_touched)for(let f of o.symbols_touched){let m=f.replace(/^[#$^!~]/,"").toLowerCase();c.push(m);}let p=o.summary||"";o.body&&(p+=`

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