#!/usr/bin/env node
import {c as c$1}from'./chunk-Z72SDTBJ.js';import {a}from'./chunk-LKAT7IAK.js';import'./chunk-5TAVYPOV.js';import*as c from'fs';import*as u from'path';import*as v from'os';import e from'chalk';import*as k from'js-yaml';var S=process.env.NEVR_REGISTRY_URL||"https://nevr-api.onrender.com",x=u.join(v.homedir(),".paradigm","agents"),A=".paradigm/agents";async function O(g,p){let r=a.command("agent-search").start("Searching nevr.land registry",{query:g}),s=parseInt(p.limit||"10",10);try{let{RegistryClient:a}=await import('./dist-QBTQW4ZW.js'),d=await new a({baseUrl:S}).search(g,{page:1}),o=d.agents.slice(0,s);if(!o||o.length===0){console.log(e.dim(`
  No agents found.
`)),r.success("No results");return}console.log(e.bold(`
  ${o.length} agent(s) found`)+e.dim(` (of ${d.total})
`));for(let n of o){let i=n.scope.startsWith("@")?n.scope:`@${n.scope}`,h=e.cyan(`${i}/${n.name}`),t=e.dim("v"+(n.latestVersion||"0.1.0")),m=n.downloads>0?e.dim(` | ${n.downloads} downloads`):"",b=n.calibrationScore!=null?e.dim(` | calibration: ${(n.calibrationScore*100).toFixed(0)}%`):"";console.log(`  ${h} ${t}${m}${b}`),n.description&&console.log(`  ${n.description}`),n.tags?.length&&console.log(`  ${e.dim("tags:")} ${n.tags.join(", ")}`),console.log();}console.log(e.dim(`  Install: paradigm agent install @scope/name
`)),r.success(`Found ${o.length} agents`);}catch(a){console.error(e.red(`
  Search failed:`),a instanceof Error?a.message:a),console.log(""),r.error("Search failed");}}async function D(g,p){let r=a.command("agent-install").start("Installing agent from registry",{source:g}),s=g,a$1,f=s.lastIndexOf("@");f>0&&s[f-1]!=="/"&&(a$1=s.substring(f+1),s=s.substring(0,f));let d=s.indexOf("/");if(d===-1){console.error(e.red(`
  Invalid agent name. Use @scope/name format.
`)),r.error("Invalid agent name format");return}let o=s.substring(0,d).replace(/^@/,""),n=s.substring(d+1);console.log(e.dim(`
  Installing ${o}/${n}${a$1?"@"+a$1:""}...`));try{let{RegistryClient:i}=await import('./dist-QBTQW4ZW.js'),h=new i({baseUrl:S}),t=await h.getAgent(o,n);if(!t){console.error(e.red(`
  Agent @${o}/${n} not found.
`)),r.error("Agent not found");return}let m=p.global?x:u.join(process.cwd(),A);c.existsSync(m)||c.mkdirSync(m,{recursive:!0});let b=!1;try{let y=await h.downloadPackage(o,n,a$1||"latest"),R=u.join(m,`${n}.nevr.tar.gz`);c.writeFileSync(R,y.buffer),b=!0,a.component("#agent-registry").info("Package downloaded",{agent:`${o}/${n}`,hash:y.hash.slice(0,12),size:y.buffer.length});}catch{a.component("#agent-registry").info("Package not available, creating metadata-only profile",{agent:`${o}/${n}`});}let $={id:n,nickname:t.nickname||t.displayName||n,role:t.description||"",description:t.description||"",version:a$1||t.latestVersion||"0.1.0",scope:`@${o}`,registry:S,distribution:t.distribution,installedAt:new Date().toISOString(),personality:{style:"deliberate",risk:"balanced",verbosity:"concise"},expertise:[],transferable:[],contexts:{},created:new Date().toISOString(),updated:new Date().toISOString()};t.brandColor&&($.brandColor=t.brandColor),t.tags?.length&&($.tags=t.tags);let w=u.join(m,`${n}.agent`);c.writeFileSync(w,k.dump($,{lineWidth:120,noRefs:!0,sortKeys:!1}),"utf-8");try{await c$1(process.cwd(),n,{adopted:new Date().toISOString(),source:"marketplace",defaultsAccepted:!0,version:a$1||t.latestVersion||"0.1.0"});}catch{a.component("#agent-registry").info("Adoption record skipped (no .paradigm dir)",{agent:n});}b?console.log(e.green(`
  \u2713 Installed @${o}/${n}`)):(console.log(e.green(`
  \u2713 Installed @${o}/${n} (metadata only)`)),console.log(e.dim("    Package not yet available for download."))),console.log(e.dim(`    Location: ${w}`)),console.log(e.dim(`    Run: paradigm agent show ${n}
`)),r.success(`Installed ${o}/${n}`);}catch(i){console.error(e.red(`
  Install failed:`),i instanceof Error?i.message:i),console.log(""),r.error("Install failed");}}async function F(g){let p=a.command("agent-publish").start("Agent publish info",{});console.log(e.bold(`
  Publishing agents to nevr.land
`)),console.log("  Use the nevr CLI to publish:"),console.log(e.cyan("    npm install -g @a-company/nevr")),console.log(e.cyan("    nevr auth login")),console.log(e.cyan("    nevr publish")),console.log(""),console.log(e.dim(`  Full paradigm publish integration coming soon.
`)),p.success("Showed publish instructions");}export{D as agentInstallCommand,F as agentPublishCommand,O as agentSearchCommand};