#!/usr/bin/env node
import {b as b$1,i,h,f,a,c,d,q as q$1,k,e as e$1,o,t,u,g,p as p$1,m,n,s,r,x,v,A,w,y,z}from'./chunk-CUOEZAVL.js';import'./chunk-5TAVYPOV.js';import e from'chalk';import*as b from'path';import*as p from'fs';import*as q from'os';async function te(s){let o=process.cwd();if(s.remote){await Y(o,s.remote);return}let r=b$1(o);console.log(e.green(`\u2713 Joined as ${e.bold(r.id)}`));let i$1=i().filter(l=>l.id!==r.id);if(i$1.length>0){console.log(e.cyan(`
  Found ${i$1.length} other session${i$1.length!==1?"s":""}:`));for(let l of i$1){let t=h(l)?e.yellow("asleep"):e.green("awake");console.log(`    ${e.white(l.id)} \u2014 ${l.name} [${t}]`);}}else console.log(e.gray(`
  No other sessions found. Open another terminal and run "paradigm symphony join".`));console.log(e.gray(`
  Tip: Set up polling with: /loop 10s paradigm_symphony_poll`));}async function Y(s,o){let{SymphonyRelay:r}=await import('./symphony-relay-CIMRXQHI.js'),n,i;if(o.includes("#")){let c=o.split("#");n=c[0],i=c[1];}else n=o;n.includes(":")||(n=`${n}:3939`);let l=f(s);l||(l=b$1(s));let t;if(i)t=i,console.log(e.cyan(`
  Connecting to ${n} with embedded pairing code...`));else if(console.log(e.cyan(`
  Connecting to ${n}...`)),console.log(e.white("  Enter the 6-digit pairing code shown on the host:")),t=await K("  Code: "),t=t.trim(),!/^\d{6}$/.test(t)){console.log(e.red("  Invalid code. Must be 6 digits."));return}let a=new r({mode:"client",peerId:l.id,events:{onPeerConnected:(c,g)=>{console.log(e.green(`  \u2713 Connected to ${e.bold(g)} (${c})`));},onPeerDisconnected:c=>{console.log(e.yellow(`  Peer ${c} disconnected. Reconnecting...`));},onMessageRelayed:(c,g,y)=>{console.log(e.gray(`  \u2190 Message ${c.slice(0,8)} from ${g} \u2192 ${y}`));},onError:c=>{console.log(e.red(`  Error: ${c.message}`));}}});try{await a.connectToServer(n,t),console.log(e.green(`
  \u2713 Paired and connected!`)),console.log(e.gray("  Messages from remote agents will appear in your inbox.")),console.log(e.gray(`  Press Ctrl+C to disconnect.
`)),process.on("SIGINT",()=>{console.log(e.yellow(`
  Disconnecting...`)),a.stop(),process.exit(0);}),await new Promise(()=>{});}catch(c){console.log(e.red(`  Failed to connect: ${c.message}`)),a.stop();}}function K(s){return new Promise(o=>{process.stdout.write(s);let r="";process.stdin.setEncoding("utf-8"),process.stdin.resume(),process.stdin.once("data",n=>{r=n.toString(),process.stdin.pause(),o(r);});})}async function se(){let s=process.cwd(),o=a(s),r=c(o);console.log(r?e.green(`\u2713 Left the score: ${o}`):e.yellow("No active part found for this project."));}async function re(){let s=process.cwd(),o=f(s);if(!o){console.log(e.yellow('Not joined. Run "paradigm symphony join" first.'));return}let n=d().filter(t=>t.id!==o.id),i=q$1("active"),l=k(o.id);console.log(e.cyan(`
  ${e.bold(o.id)}`)),console.log(e.gray(`  Project: ${o.project}`)),console.log(e.gray(`  Role: ${o.role}`)),console.log(e.gray(`  PID: ${o.pid}`)),console.log(e.gray(`  Started: ${o.startedAt}`)),o.statusBlurb&&console.log(e.white(`  Status: ${o.statusBlurb}`)),console.log(`
  ${e.white(`${n.length} linked peer${n.length!==1?"s":""}`)} \u2014 ${e.white(`${i.length} active thread${i.length!==1?"s":""}`)} \u2014 ${e.white(`${l.length} unread`)}`);}async function ie(s){e$1();let o=d(),{loadPeers:r}=await import('./symphony-peers-X5NGWXFP.js'),n=r(),i=[];for(let t of n)if(!t.revoked)for(let a of t.agents||[])i.push({...a,peerId:t.id});let l=o.length+i.length;if(s.json){console.log(JSON.stringify({local:o,remote:i},null,2));return}if(l===0){console.log(e.yellow('No agents joined. Run "paradigm symphony join" in each terminal.'));return}console.log(e.cyan(`
  Symphony Agents (${l})
`)),console.log(e.gray(`  ${"AGENT ID".padEnd(30)} ${"PROJECT".padEnd(15)} ${"ROLE".padEnd(10)} STATUS`)),console.log(e.gray(`  ${"\u2500".repeat(30)} ${"\u2500".repeat(15)} ${"\u2500".repeat(10)} ${"\u2500".repeat(8)}`));for(let t of o){let a=h(t)?e.yellow("asleep"):e.green("awake");console.log(`  ${e.white(t.id.padEnd(30))} ${t.project.padEnd(15)} ${t.role.padEnd(10)} ${a}`),t.statusBlurb&&console.log(`  ${e.gray(`  \u2514 ${t.statusBlurb}`)}`);}if(i.length>0){console.log(e.gray(`
  ${"\u2500".repeat(65)}`)),console.log(e.cyan(`  Remote Agents (${i.length})
`));for(let t of i){let a=t.status==="awake"?e.green("awake"):e.yellow("asleep"),c=e.magenta(`(remote: ${t.peerId})`);console.log(`  ${e.white(t.id.padEnd(30))} ${t.project.padEnd(15)} ${t.role.padEnd(10)} ${a} ${c}`);}}console.log();}async function le(s,o$1){let r=process.cwd(),n=f(r);n||(n=b$1(r),console.log(e.gray(`Auto-joined as ${n.id}`)));let i={id:n.id,name:n.name,type:"human",project:n.project,role:n.role},l;o$1.to&&(l=[{id:o$1.to,name:o$1.to,type:"agent"}]);let t$1=o$1.thread;if(!t$1){let g=s.length>60?s.slice(0,60)+"...":s;t$1=o(g,i).id;}let a=t({sender:i,recipients:l,intent:"context",text:s,threadRoot:t$1}),c=u(a);console.log(e.green(`\u2713 Sent to ${c} agent${c!==1?"s":""}`)),console.log(e.gray(`  Thread: ${t$1}`)),console.log(e.gray(`  Note: ${a.id}`));}async function ce(){let s=process.cwd(),o=f(s);if(!o){console.log(e.yellow('Not joined. Run "paradigm symphony join" first.'));return}g(o.id);let r=k(o.id);if(r.length===0){console.log(e.gray(`
  No unread notes.
`));return}let n$1=new Map;for(let l of r){let t=l.threadRoot||"direct";n$1.has(t)||n$1.set(t,[]),n$1.get(t).push(l);}console.log(e.cyan(`
  ${r.length} unread note${r.length!==1?"s":""}
`));for(let[l,t]of n$1){let a=l;if(l!=="direct"){let c=p$1(l);c&&(a=`${c.topic} (${l})`);}console.log(e.white(`  \u250C\u2500 ${a}`));for(let c=0;c<t.length;c++){let g=t[c],y=c===t.length-1,d=y?"  \u2514\u2500":"  \u251C\u2500",h=new Date(g.timestamp).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"});console.log(`${d} ${e.cyan(g.sender.name)} ${e.gray(`[${g.intent}]`)} ${e.gray(h)}`);let u=g.content.text.split(`
`),m=y?"     ":"  \u2502  ";for(let $ of u)console.log(`${m}${$}`);g.symbols.length>0&&console.log(`${m}${e.gray(`Symbols: ${g.symbols.join(", ")}`)}`);}console.log();}let i=r[r.length-1].id;m(o.id,i),n(o.id);}async function ae(s){let o=q$1();if(s.json){console.log(JSON.stringify(o,null,2));return}if(o.length===0){console.log(e.gray(`
  No threads.
`));return}console.log(e.cyan(`
  Threads (${o.length})
`)),console.log(e.gray(`  ${"ID".padEnd(14)} ${"TOPIC".padEnd(35)} ${"MSGS".padEnd(6)} ${"STATUS".padEnd(10)} LAST ACTIVITY`)),console.log(e.gray(`  ${"\u2500".repeat(14)} ${"\u2500".repeat(35)} ${"\u2500".repeat(6)} ${"\u2500".repeat(10)} ${"\u2500".repeat(20)}`));for(let r of o){let n=r.topic.length>33?r.topic.slice(0,33)+"..":r.topic,i=r.status==="active"?e.green("active"):e.gray("resolved"),l=new Date(r.lastActivity).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});console.log(`  ${e.white(r.id.padEnd(14))} ${n.padEnd(35)} ${String(r.messageCount).padEnd(6)} ${i.padEnd(10)} ${e.gray(l)}`);}console.log();}async function ge(s$1){let o=p$1(s$1);if(!o){console.log(e.red(`Thread not found: ${s$1}`));return}let r=s(s$1);console.log(e.cyan(`
  Thread: ${o.topic}`)),console.log(e.gray(`  ID: ${o.id} | Status: ${o.status} | Notes: ${o.messageCount}`)),console.log(e.gray(`  Participants: ${o.participants.map(n=>n.name).join(", ")}`)),o.decision&&console.log(e.green(`  Decision: ${o.decision}`)),console.log(e.gray(`
  ${"\u2500".repeat(60)}
`));for(let n of r){let i=new Date(n.timestamp).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});console.log(`  ${e.cyan(n.sender.name)} ${e.gray(`[${n.intent}]`)} ${e.gray(i)}`);let l=n.content.text.split(`
`);for(let t of l)console.log(`    ${t}`);n.symbols.length>0&&console.log(`    ${e.gray(`Symbols: ${n.symbols.join(", ")}`)}`),n.content.decision&&console.log(`    ${e.green(`Decision: ${n.content.decision}`)}`),console.log();}}async function de(s,o){let r$1=p$1(s);if(!r$1){console.log(e.red(`Thread not found: ${s}`));return}r(s,o.decision)?(console.log(e.green(`\u2713 Thread resolved: ${r$1.topic}`)),o.decision&&console.log(e.gray(`  Decision: ${o.decision}`)),console.log(e.gray(`  Tip: Record this as lore with "paradigm lore record --title 'Thread: ${r$1.topic}'"`))):console.log(e.red("Failed to resolve thread."));}async function ye(s){e$1();let o=process.cwd(),r=f(o),n=d(),i=q$1("active"),l=x("pending"),t=r?k(r.id):[],{loadPeers:a}=await import('./symphony-peers-X5NGWXFP.js'),g=a().filter(d=>!d.revoked);if(s.json){console.log(JSON.stringify({identity:r?{id:r.id,project:r.project,role:r.role}:null,agents:n.map(d=>({id:d.id,status:h(d)?"asleep":"awake",statusBlurb:d.statusBlurb})),peers:g.map(d=>({id:d.id,address:d.address,agents:d.agents?.length??0,lastSeen:d.lastSeen})),activeThreads:i.length,unreadMessages:t.length,pendingFileRequests:l.length},null,2));return}console.log(e.cyan(`
  Symphony Status
`)),console.log(r?`  ${e.white("Identity:")} ${r.id}`:`  ${e.yellow("Not joined.")} Run "paradigm symphony join" to join.`);let y=n.filter(d=>!h(d)).length;console.log(`  ${e.white("Agents:")} ${n.length} joined (${y} awake)`);for(let d of n){let h$1=h(d)?e.yellow("asleep"):e.green("awake"),u=d.statusBlurb?e.gray(` \u2014 ${d.statusBlurb}`):"";console.log(`    ${e.white(d.id)} [${h$1}]${u}`);}if(g.length>0){let d=g.reduce((h,u)=>h+(u.agents?.length??0),0);console.log(`  ${e.white("Peers:")} ${g.length} connected (${d} remote agents)`);for(let h of g){let u=h.agents?.length??0;console.log(`    ${e.white(h.id)} at ${h.address} (${u} agent${u!==1?"s":""})`);}}else console.log(`  ${e.white("Peers:")} ${e.gray('none (run "paradigm symphony serve" to accept connections)')}`);console.log(`  ${e.white("Threads:")} ${i.length} active`),console.log(`  ${e.white("Unread:")} ${t.length} note${t.length!==1?"s":""}`),console.log(`  ${e.white("File Requests:")} ${l.length} pending`),console.log();}async function pe(s){let o=parseInt(s.port||"3939",10),r=process.cwd(),{SymphonyRelay:n}=await import('./symphony-relay-CIMRXQHI.js'),i=f(r);i||(i=b$1(r)),console.log(e.cyan(`
  Starting Symphony relay server...
`));let l=new n({mode:"server",peerId:i.id,port:o,events:{onPeerConnected:(t,a)=>{console.log(e.green(`  \u2713 Peer connected: ${e.bold(a)} (${t})`));let c=l.getRemoteAgents();c.length>0&&console.log(e.gray(`    Remote agents: ${c.map(g=>g.id).join(", ")}`));},onPeerDisconnected:t=>{console.log(e.yellow(`  Peer disconnected: ${t}`));},onPeerAuthFailed:(t,a)=>{console.log(e.red(`  Auth failed from ${t}: ${a}`));},onMessageRelayed:(t,a,c)=>{console.log(e.gray(`  \u2194 Relayed ${t.slice(0,8)} from ${a} to ${c}`));},onError:t=>{console.log(e.red(`  Error: ${t.message}`));}}});try{let t=await l.startServer(),a=Q();if(console.log(e.green(`  \u2713 Symphony relay listening on port ${o}`)),console.log(),console.log(e.white("  Pairing Code:")),console.log(),console.log(e.bold.cyan(`      ${t.code.slice(0,3)} ${t.code.slice(3)}`)),console.log(),console.log(e.gray("  Share this code with the person connecting.")),console.log(e.gray(`  Code rotates every 5 minutes.
`)),console.log(e.white("  LAN connect:")),console.log(e.gray(`    paradigm symphony join --remote ${a}:${o}`)),s.public){let g=`${a}:${o}#${t.code}`;console.log(),console.log(e.white("  Internet connect (connection string):")),console.log(e.cyan(`    paradigm symphony join --remote ${g}`)),console.log(e.gray("  (Requires port 3939 reachable: port forward, VPN, or SSH tunnel)"));}console.log(e.gray(`
  Press Ctrl+C to stop.
`));let c=setInterval(()=>{let g=l.rotatePairingCode();console.log(e.cyan(`  Code rotated: ${g.code.slice(0,3)} ${g.code.slice(3)}`));},300*1e3);process.on("SIGINT",()=>{console.log(e.yellow(`
  Shutting down relay...`)),clearInterval(c),l.stop(),process.exit(0);}),await new Promise(()=>{});}catch(t){console.log(e.red(`  Failed to start server: ${t.message}`)),l.stop();}}function Q(){let s=q.networkInterfaces();for(let o of Object.keys(s))for(let r of s[o]||[])if(r.family==="IPv4"&&!r.internal)return r.address;return "127.0.0.1"}async function he(s,o){let r=process.cwd(),n=f(r);n||(n=b$1(r));let i=o.from,l=o.reason||"Needed for current task";if(!i){console.log(e.red("--from is required. Specify which agent to request from."));let g=d().filter(y=>y.id!==n.id);if(g.length>0){console.log(e.gray(`
Available agents:`));for(let y of g)console.log(e.gray(`  ${y.id}`));}return}let t$1=v();if(A(s,t$1)){console.log(e.red(`\u2717 "${s}" is on the hard-deny list and cannot be requested.`));return}let a=w({filePath:s,requester:{id:n.id,name:n.name,type:"agent",project:n.project,role:n.role},reason:l}),c=t({sender:{id:n.id,name:n.name,type:"agent",project:n.project,role:n.role},recipients:[{id:i,name:i,type:"agent"}],intent:"fileRequest",text:`File request: ${s}
Reason: ${l}`,symbols:[]});u(c),console.log(e.green(`\u2713 File request created: ${a.request.requestId}`)),console.log(e.gray(`  File: ${s}`)),console.log(e.gray(`  From: ${i}`)),console.log(e.gray(`  Reason: ${l}`)),console.log(e.gray(`
  The owning agent's human must approve with:`)),console.log(e.white(`    paradigm symphony approve ${a.request.requestId}`));}async function ue(){let s=x("pending");if(s.length===0){console.log(e.gray(`
  No pending file requests.
`));return}console.log(e.cyan(`
  Pending File Requests (${s.length})
`));for(let o of s){let r=Date.now()-new Date(o.createdAt).getTime(),n=Math.round(r/6e4);console.log(`  ${e.white(o.request.requestId)}`),console.log(`    File: ${o.request.filePath}`),console.log(`    From: ${o.request.requester.name} (${o.request.requester.id})`),console.log(`    Reason: ${o.request.reason}`),console.log(e.gray(`    ${n}m ago`)),console.log(e.gray(`    \u2192 paradigm symphony approve ${o.request.requestId}`)),console.log(e.gray(`    \u2192 paradigm symphony deny ${o.request.requestId}`)),console.log();}}async function me(s,o){let r=process.cwd(),n=y(s,r,o.redact);if(!n.success){console.log(e.red(`\u2717 ${n.error}`));return}let i=o.redact?"approved (redacted)":"approved";console.log(e.green(`\u2713 File request ${i}`)),console.log(e.gray(`  File: ${n.delivery?.filePath}`)),console.log(e.gray(`  Size: ${n.delivery?.size} bytes`)),console.log(e.gray(`  SHA-256: ${n.delivery?.hash?.slice(0,16)}...`));}async function fe(s,o){z(s,o.reason)?(console.log(e.green(`\u2713 File request denied: ${s}`)),o.reason&&console.log(e.gray(`  Reason: ${o.reason}`))):console.log(e.red(`\u2717 File request not found or already resolved: ${s}`));}var X={question:e.blue,context:e.gray,clarification:e.blue,proposal:e.cyan,verification:e.blue,action:e.cyan,decision:e.yellow,alert:e.red,approval:e.green,rejection:e.red,reference:e.gray,handoff:e.magenta,fileRequest:e.green,fileApproved:e.green,fileDenied:e.red,fileDelivery:e.green};function Z(s){let o=new Date(s.timestamp).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"}),n=(X[s.intent]||e.white)(`[${s.intent}]`),i=e.cyan(s.sender.name),l=s.threadRoot?e.gray(` (${s.threadRoot})`):"",t=[];t.push(`  ${e.gray(o)} ${i} ${n}${l}`);let a=s.content.text.split(`
`);for(let c of a)t.push(`    ${c}`);return s.symbols.length>0&&t.push(`    ${e.gray(`Symbols: ${s.symbols.join(", ")}`)}`),s.content.decision&&t.push(`    ${e.yellow(`Decision: ${s.content.decision}`)}`),s.content.diff&&t.push(`    ${e.gray("[diff attached]")}`),t.join(`
`)}async function $e(s){let o=process.cwd(),r=f(o);r||(r=b$1(o),console.log(e.gray(`Auto-joined as ${r.id}`)));let n=parseInt(s.interval||"2000",10),i=s.thread,l=s.quiet,t=b.join(q.homedir(),".paradigm","score"),a=b.join(t,"agents",...r.id.split("/"),"inbox.jsonl"),c=0,g$1=0;p.existsSync(a)&&(c=p.readFileSync(a,"utf-8").split(`
`).filter($=>$.trim().length>0).length,g$1=p.statSync(a).size),l||(console.log(e.cyan(`
  Symphony Watch`)),console.log(e.gray(`  Agent: ${r.id}`)),console.log(e.gray(`  Inbox: ${a}`)),console.log(e.gray(`  Poll: ${n}ms`)),i&&console.log(e.gray(`  Filter: thread ${i}`)),console.log(e.gray(`  Press Ctrl+C to stop
`)),console.log(e.gray(`  ${"\u2500".repeat(60)}
`)));let y=b.join(t,"threads"),d=new Set;if(p.existsSync(y))for(let m of p.readdirSync(y))d.add(m);let h=()=>{try{if(p.existsSync(a)){let m=p.statSync(a);if(m.size>g$1){let w=p.readFileSync(a,"utf-8").split(`
`).filter(T=>T.trim().length>0);if(w.length>c){let T=w.slice(c);for(let V of T)try{let F=JSON.parse(V);if(i&&F.threadRoot!==i)continue;console.log(Z(F)),console.log();}catch{}c=w.length;}g$1=m.size;}}if(p.existsSync(y)){let m=p.readdirSync(y);for(let $ of m)if(!d.has($)){d.add($);try{let w=JSON.parse(p.readFileSync(b.join(y,$),"utf-8"));l||(console.log(`  ${e.green("+")} ${e.white("New thread:")} ${w.topic||w.id}`),console.log(`    ${e.gray(`by ${w.initiator?.name||"unknown"} \u2014 ${w.id}`)}`),console.log());}catch{}}}g(r.id);}catch{}};h();let u=setInterval(h,n);process.on("SIGINT",()=>{clearInterval(u),l||console.log(e.gray(`
  Watch stopped.
`)),process.exit(0);}),await new Promise(()=>{});}export{me as symphonyApproveCommand,fe as symphonyDenyCommand,te as symphonyJoinCommand,se as symphonyLeaveCommand,ie as symphonyListCommand,ce as symphonyReadCommand,he as symphonyRequestCommand,ue as symphonyRequestsCommand,de as symphonyResolveCommand,le as symphonySendCommand,pe as symphonyServeCommand,ye as symphonyStatusCommand,ge as symphonyThreadCommand,ae as symphonyThreadsCommand,$e as symphonyWatchCommand,re as symphonyWhoamiCommand};