#!/usr/bin/env node
import'./chunk-5TAVYPOV.js';import*as o from'fs';import*as f from'path';import c from'chalk';import*as p from'js-yaml';var b=`# Thread - Session Continuity

> Pass context between AI agent sessions. Updated by \`paradigm thread save\`.

## Last Session: {timestamp}

### Trail (What was done)
{trail}

### Loose Ends (Unfinished)
{looseEnds}

### Breadcrumbs (Notes for next agent)
{breadcrumbs}

---
*Run \`paradigm thread save "message"\` to update*
*Run \`paradigm thread clear\` to reset*
`;function u(){try{let t=f.join(process.cwd(),".paradigm","config.yaml");if(o.existsSync(t)){let n=o.readFileSync(t,"utf8"),r=p.load(n)?.limits;if(r?.threadTrailMax&&typeof r.threadTrailMax=="number")return r.threadTrailMax}}catch{}return 10}function m(t){let n={trail:[],looseEnds:[],breadcrumbs:[]},l=t.match(/## Last Session: (.+)/);l&&(n.lastSession=l[1].trim());let r=t.match(/### Trail \(What was done\)\n([\s\S]*?)(?=\n### |$)/);if(r){let e=r[1].split(`
`).filter(s=>s.startsWith("- "));for(let s of e){let i=s.replace(/^- /,"").trim();if(i&&i!=="_No activity recorded yet_"){let h=i.match(/[@#^!$%~?][\w-]+/g)||[];n.trail.push({timestamp:n.lastSession||new Date().toISOString(),message:i,symbols:h.length>0?h:void 0});}}}let d=t.match(/### Loose Ends \(Unfinished\)\n([\s\S]*?)(?=\n### |$)/);if(d){let e=d[1].split(`
`).filter(s=>s.startsWith("- "));for(let s of e){let i=s.replace(/^- \[[ x]\] /,"").replace(/^- /,"").trim();i&&i!=="_No pending tasks_"&&n.looseEnds.push(i);}}let a=t.match(/### Breadcrumbs \(Notes for next agent\)\n([\s\S]*?)(?=\n---|$)/);if(a){let e=a[1].split(`
`).filter(s=>s.startsWith("- "));for(let s of e){let i=s.replace(/^- /,"").trim();i&&i!=="_No notes yet_"&&n.breadcrumbs.push(i);}}return n}function g(t){let n=new Date().toISOString().replace("T"," ").split(".")[0],l="_No activity recorded yet_";t.trail.length>0&&(l=t.trail.slice(-u()).map(a=>`- ${a.message}`).join(`
`));let r="_No pending tasks_";t.looseEnds.length>0&&(r=t.looseEnds.map(a=>`- [ ] ${a}`).join(`
`));let d="_No notes yet_";return t.breadcrumbs.length>0&&(d=t.breadcrumbs.slice(-u()).map(a=>`- ${a}`).join(`
`)),b.replace("{timestamp}",n).replace("{trail}",l).replace("{looseEnds}",r).replace("{breadcrumbs}",d)}async function w(t,n={}){let l=process.cwd(),r=t?f.resolve(l,t):l,d=f.join(r,".paradigm","thread.md");if(!o.existsSync(d)){if(n.json){console.log(JSON.stringify({exists:false,trail:[],looseEnds:[],breadcrumbs:[]},null,2));return}console.log(c.yellow(`
\u{1F4DC} No thread found.
`)),console.log(c.gray('  Run `paradigm thread save "message"` to start a thread.\n'));return}let a=o.readFileSync(d,"utf8"),e=m(a);if(n.json){console.log(JSON.stringify({exists:true,lastSession:e.lastSession,trail:e.trail,looseEnds:e.looseEnds,breadcrumbs:e.breadcrumbs},null,2));return}if(console.log(c.blue(`
\u{1F4DC} Current Thread
`)),console.log(c.gray("\u2500".repeat(50))),e.lastSession&&(console.log(c.white(`Last Session: ${c.cyan(e.lastSession)}`)),console.log("")),e.trail.length>0){console.log(c.white("Trail (What was done):"));for(let s of e.trail.slice(-5))console.log(c.gray(`  - ${s.message}`));e.trail.length>5&&console.log(c.gray(`  ... and ${e.trail.length-5} more`)),console.log("");}if(e.looseEnds.length>0){console.log(c.white("Loose Ends (Unfinished):"));for(let s of e.looseEnds)console.log(c.yellow(`  \u25A1 ${s}`));console.log("");}if(e.breadcrumbs.length>0){console.log(c.white("Breadcrumbs (Notes):"));for(let s of e.breadcrumbs.slice(-5))console.log(c.gray(`  - ${s}`));console.log("");}console.log(c.gray(`Path: ${d}
`));}async function T(t,n,l={}){let r=process.cwd(),d=n?f.resolve(r,n):r,a=f.join(d,".paradigm"),e=f.join(a,"thread.md");o.existsSync(a)||o.mkdirSync(a,{recursive:true});let s={trail:[],looseEnds:[],breadcrumbs:[]};if(o.existsSync(e)){let y=o.readFileSync(e,"utf8");s=m(y);}let i=t.match(/[@#^!$%~?][\w-]+/g)||[];s.trail.push({timestamp:new Date().toISOString(),message:t,symbols:i.length>0?i:void 0});let h=g(s);o.writeFileSync(e,h,"utf8"),l.quiet||console.log(c.green(`
\u2713 Thread updated: ${t}
`));}async function x(t,n,l={}){let r=process.cwd(),d=n?f.resolve(r,n):r,a=f.join(d,".paradigm"),e=f.join(a,"thread.md");o.existsSync(a)||o.mkdirSync(a,{recursive:true});let s={trail:[],looseEnds:[],breadcrumbs:[]};if(o.existsSync(e)){let h=o.readFileSync(e,"utf8");s=m(h);}s.looseEnds.push(t);let i=g(s);o.writeFileSync(e,i,"utf8"),l.quiet||console.log(c.yellow(`
\u25A1 Loose end added: ${t}
`));}async function E(t,n,l={}){let r=process.cwd(),d=n?f.resolve(r,n):r,a=f.join(d,".paradigm"),e=f.join(a,"thread.md");o.existsSync(a)||o.mkdirSync(a,{recursive:true});let s={trail:[],looseEnds:[],breadcrumbs:[]};if(o.existsSync(e)){let h=o.readFileSync(e,"utf8");s=m(h);}s.breadcrumbs.push(t);let i=g(s);o.writeFileSync(e,i,"utf8"),l.quiet||console.log(c.cyan(`
\u{1F4CC} Breadcrumb added: ${t}
`));}async function $(t,n={}){let l=process.cwd(),r=t?f.resolve(l,t):l,d=f.join(r,".paradigm","thread.md");if(o.existsSync(d)){let e=g({trail:[],looseEnds:[],breadcrumbs:[]});o.writeFileSync(d,e,"utf8"),n.quiet||console.log(c.green(`
\u2713 Thread cleared.
`));}else n.quiet||console.log(c.gray(`
  No thread to clear.
`));}export{$ as threadClearCommand,E as threadNoteCommand,T as threadSaveCommand,w as threadShowCommand,x as threadTodoCommand};