var R=Object.defineProperty;var $=(n,t)=>R(n,"name",{value:t,configurable:!0});import{T as P,a as T,N as x,b,K as j,_ as S,v as z,c as A,f as M}from"./bin.js";import{H as O,e as U,Z as q}from"../packem_shared/ai-analysis-3QD_RS6F.js";var F=Object.defineProperty,H=$((n,t)=>F(n,"name",{value:t,configurable:!0}),"x");const J=/^[\^~>=<]+/,Z=H(async({argument:n,logger:t,options:l,visConfig:u,workspaceRoot:f})=>{if(!f)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const m=n,e=m[0];if(!e)throw new Error("Package name is required. Usage: vis analyze <package> [version]");const p=m[1],{packageManager:E}=P(f);let r,d="default";const C=T(f,E);for(const[o,i]of C){const s=i.get(e);if(s){r=s,d=o;break}}if(!r)throw new Error(`Package "${e}" not found in any catalog or package.json. Make sure it exists in your workspace dependencies.`);let a;if(p)a=p;else{t.info(`Fetching latest version for ${e}...
`);const o=await x(e);if(!o.latest)throw new Error(`Could not determine latest version for "${e}".`);a=o.latest}const w=b(r),v=b(a);if(!w||!v)throw new Error(`Could not parse versions: current="${r}", target="${a}".`);const k=j(w,v);if(k==="none"){t.info(`${e} is already at ${a}. Nothing to analyze.`);return}const N=S(r),g={catalogName:d,currentRange:r,newRange:`${N}${a}`,packageName:e,targetVersion:a,updateType:k},y=O(l.aiType??"impact");if(y==="security"||l.security){t.info(`Checking for known vulnerabilities...
`);const o=r.replace(J,""),i=(await z([{name:e,version:o}])).get(e);i&&i.length>0&&(g.vulnerabilities=i);const s=A(u?.security,{minimumScore:u?.security?.policies?.score?.minimum});if(s.length>0){const c=(await M(s,[{name:e,version:o}])).get(`${e}@${o}`);c&&(g.socketReport={alerts:c.alerts,license:c.license,score:c.score})}}const h=await U([g],t,u?.ai,y);(l.format??"table")==="json"?process.stdout.write(`${JSON.stringify(h,void 0,2)}
`):t.info(q(h))},"execute");export{Z as default};
