@cupel-sh/cli 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/cli.js +45 -41
- package/package.json +4 -3
package/bundle/cli.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{randomBytes as Vl}from"node:crypto";import{readFileSync as Oh,renameSync as Ph,writeFileSync as Wl}from"node:fs";import $h from"node:path";import{fileURLToPath as Mh}from"node:url";var Gl=/^(\d{1,10})\.(\d{1,10})\.(\d{1,10})$/u;function Hl(e){let n=Gl.exec(e);return n===null?null:{kind:"npm",release:[Number(n[1]),Number(n[2]),Number(n[3])]}}function Xl(e,n){for(let t=0;t<3;t+=1){let r=e.release[t]??0,o=n.release[t]??0;if(r!==o)return r<o?-1:1}return 0}var Yl=/^v?(?:(?<epoch>[0-9]+)!)?(?<release>[0-9]+(?:\.[0-9]+)*)(?:[-_.]?(?<preL>a|b|c|rc|alpha|beta|pre|preview)[-_.]?(?<preN>[0-9]+)?)?(?:(?:-(?<postImplicit>[0-9]+))|(?:[-_.]?(?<postL>post|rev|r)[-_.]?(?<postN>[0-9]+)?))?(?:[-_.]?(?<devL>dev)[-_.]?(?<devN>[0-9]+)?)?(?:\+(?<local>[a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/u,Jl={a:"a",alpha:"a",b:"b",beta:"b",c:"rc",pre:"rc",preview:"rc",rc:"rc"};function Dn(e){if(e===void 0)return null;let n=Number(e);return Number.isSafeInteger(n)?n:null}function Zl(e){let n=Yl.exec(e.toLowerCase());if(n===null||n.groups===void 0)return null;let t=n.groups,r=(t.release??"").split(".");if(r.length===0||r.length>32)return null;let o=[];for(let u of r){let p=Dn(u);if(p===null)return null;o.push(p)}let i=0;if(t.epoch!==void 0){let u=Dn(t.epoch);if(u===null)return null;i=u}let a=null;if(t.preL!==void 0){let u=t.preN===void 0?0:Dn(t.preN);if(u===null)return null;a=[Jl[t.preL]??t.preL,u]}let l=null;if(t.postImplicit!==void 0){let u=Dn(t.postImplicit);if(u===null)return null;l=u}else if(t.postL!==void 0){let u=t.postN===void 0?0:Dn(t.postN);if(u===null)return null;l=u}let s=null;if(t.devL!==void 0){let u=t.devN===void 0?0:Dn(t.devN);if(u===null)return null;s=u}let d=t.local===void 0?null:t.local.split(/[-_.]/u).map(u=>/^[0-9]+$/u.test(u)?Number(u):u);return{kind:"PyPI",epoch:i,release:o,pre:a,post:l,dev:s,local:d}}function Tn(e,n){return e===n?0:e<n?-1:1}function ti(e){let n=e.length;for(;n>1&&e[n-1]===0;)n-=1;return e.slice(0,n)}function Ql(e,n){let t=ti(e),r=ti(n),o=Math.max(t.length,r.length);for(let i=0;i<o;i+=1){let a=Tn(t[i]??0,r[i]??0);if(a!==0)return a}return 0}function ri(e){return e.pre!==null?0:e.post===null&&e.dev!==null?-1:1}function ed(e,n){let t=ri(e),r=ri(n);return t!==r?t<r?-1:1:t!==0||e.pre===null||n.pre===null?0:e.pre[0]!==n.pre[0]?e.pre[0]<n.pre[0]?-1:1:Tn(e.pre[1],n.pre[1])}function nd(e,n){return e===null&&n===null?0:e===null?-1:n===null?1:Tn(e,n)}function td(e,n){return e===null&&n===null?0:e===null?1:n===null?-1:Tn(e,n)}function rd(e,n){let t=typeof e=="number",r=typeof n=="number";return t&&r?Tn(e,n):!t&&!r?e===n?0:e<n?-1:1:t?1:-1}function od(e,n){if(e===null&&n===null)return 0;if(e===null)return-1;if(n===null)return 1;let t=Math.max(e.length,n.length);for(let r=0;r<t;r+=1){let o=e[r],i=n[r];if(o===void 0)return-1;if(i===void 0)return 1;let a=rd(o,i);if(a!==0)return a}return 0}function id(e,n){let t=Tn(e.epoch,n.epoch);if(t!==0)return t;let r=Ql(e.release,n.release);if(r!==0)return r;let o=ed(e,n);if(o!==0)return o;let i=nd(e.post,n.post);if(i!==0)return i;let a=td(e.dev,n.dev);return a!==0?a:od(e.local,n.local)}function sd(e,n){if(typeof n!="string"||n.length===0||n.length>256)return null;let t=e==="npm"?Hl(n):Zl(n);return t===null?null:{ecosystem:e,raw:n,parsed:t}}function Hn(e,n){let t=sd(e,n);if(t===null)throw new Error(`not a valid ${e} version: ${JSON.stringify(n)}`);return t}function It(e,n){if(e.ecosystem!==n.ecosystem)throw new Error(`cannot compare ${e.ecosystem} with ${n.ecosystem}`);if(e.parsed.kind==="npm"&&n.parsed.kind==="npm")return Xl(e.parsed,n.parsed);if(e.parsed.kind==="PyPI"&&n.parsed.kind==="PyPI")return id(e.parsed,n.parsed);throw new Error("unreachable: ecosystem/parsed mismatch")}function oi(e,n,t){let r=Hn(e,n);return!(t.introduced!=="0"&&It(r,Hn(e,t.introduced))<0||t.fixed!==void 0&&It(r,Hn(e,t.fixed))>=0||t.lastAffected!==void 0&&It(r,Hn(e,t.lastAffected))>0)}var mr=["no-entrypoint","dynamic-load","resolution-divergence","analysis-cap","dep-opaque"];function En(e,n){return oi(n.ecosystem??"npm",e,n)}function At(e,n,t){let r=new Map(e.functions.map(l=>[l.id,l])),o=new Map(e.classes.map(l=>[l.id,l.name])),i=new Map(e.callSites.map(l=>[l.id,l])),a=[];for(let l of e.callEdges){if(l.resolution!=="resolved"&&l.resolution!=="field-based")continue;let s=i.get(l.callSiteId);if(s===void 0)continue;let d=r.get(s.enclosingFunctionId);if(d===void 0||!t.has(d.moduleId))continue;let u=n.get(d.moduleId);if(u===void 0)continue;let p=r.get(l.calleeFunctionId);if(p===void 0||p.name===void 0)continue;let f=n.get(p.moduleId);f!==void 0&&f.packageName!==u.packageName&&a.push({packageName:f.packageName,exportName:p.name,container:p.enclosingClassId!==void 0?o.get(p.enclosingClassId)??null:null,resolution:l.resolution})}return a}function ad(e,n){return(e.get(n)??[]).filter(t=>t.status==="summarized").slice().sort((t,r)=>t.analyzedVersion<r.analyzedVersion?1:t.analyzedVersion>r.analyzedVersion?-1:0)}function ld(e,n,t){return e.target.kind!=="symbol"||t!==n.packageName?!1:e.target.exportName===n.exportName&&e.target.container===n.container&&e.target.symbolKind===n.symbolKind}function ii(e,n,t,r,o,i){if(i<=0)return null;let a=null,l=s=>{(a===null||s.hops<a.hops)&&(a=s)};for(let s of ad(e,n))for(let d of s.edges){if(d.entryExport!==t||d.entryContainer!==r)continue;if(ld(d,o,s.packageName)){l({viaPackages:[],hops:d.hops,provenance:{tool:s.tool,toolVersion:s.toolVersion,analyzedVersion:s.analyzedVersion}});continue}if(d.target.kind!=="dep")continue;let u=ii(e,d.target.calleePackage,d.target.calleeExport,null,o,i-1);u!==null&&l({viaPackages:[d.target.calleePackage,...u.viaPackages],hops:d.hops+u.hops,provenance:u.provenance})}return a}function hr(e,n,t,r,o,i){let a=null;for(let l of At(e,n,t)){let s=ii(o,l.packageName,l.exportName,l.container,r,i);s!==null&&(a===null||s.hops<a.totalHops)&&(a={tier:"reachable-low",anchorPackage:l.packageName,entryExport:l.exportName,viaPackages:s.viaPackages,totalHops:s.hops,provenance:s.provenance})}return a}function Xn(e){switch(e){case"all-resolved":return"reachable-high";case"field-based":return"reachable-medium";case"modeled":return"reachable-low"}}function Ln(e){let n=new Map;for(let t of e.modules)n.set(t.id,t);return n}function gr(e){let n=new Map,t=new Map(e.imports.map(r=>[r.id,r]));for(let r of e.importEdges){let o=t.get(r.importId);if(o===void 0)continue;let i=n.get(o.moduleId)??[];i.push(r.resolvedModuleId),n.set(o.moduleId,i)}return n}function dd(e){let n=new Map,t=new Map(e.imports.map(r=>[r.id,r]));for(let r of e.importEdges){let o=t.get(r.importId);if(o===void 0)continue;let i=n.get(r.resolvedModuleId)??[];i.push(o.moduleId),n.set(r.resolvedModuleId,i)}return n}function Ze(e){let n=gr(e),t=new Set,r=e.modules.filter(o=>o.isEntrypoint).map(o=>o.id);for(;r.length>0;){let o=r.pop();if(!(o===void 0||t.has(o))){t.add(o);for(let i of n.get(o)??[])t.has(i)||r.push(i)}}return t}function cd(e,n){let t=dd(e),r=new Set,o=[n];for(;o.length>0;){let i=o.pop();if(!(i===void 0||r.has(i))){r.add(i);for(let a of t.get(i)??[])r.has(a)||o.push(a)}}return r}function ud(e,n,t){let r=gr(e),o=Ln(e),i=new Set,a=[n];for(;a.length>0;){let l=a.pop();if(l===void 0||i.has(l))continue;i.add(l);let s=o.get(l);if(s===void 0||s.externalSurface===!0||t.has(l))return!0;for(let d of r.get(l)??[])i.has(d)||a.push(d)}return!1}function Yn(e,n,t,r=new Set){let o=gr(e),i=Ln(e),a=new Set,l=[],s=[n];for(;s.length>0;){let d=s.pop();if(d===void 0||a.has(d))continue;a.add(d);let u=i.get(d);if(u===void 0){l.push({module:d,kind:"absent"});continue}if(t.has(d)){l.push({module:d,kind:"unbounded"});continue}if(u.externalSurface===!0&&!r.has(d)){l.push({module:d,kind:"surface"});continue}for(let p of o.get(d)??[])a.has(p)||s.push(p)}return l}function fd(e){let n=new Set(e.modules.filter(a=>a.isEntrypoint).map(a=>a.id)),t=new Map(e.functions.map(a=>[a.id,a])),r=Ln(e),o=new Map;for(let a of e.functions)n.has(a.moduleId)&&(a.publicSurfaceReachable||a.name==="<toplevel>")&&o.set(a.id,a);let i=new Map(e.exports.map(a=>[a.id,a]));for(let a of e.exportBindings){if(a.target.kind!=="function")continue;let l=i.get(a.exportId);if(l===void 0||!n.has(l.moduleId))continue;let s=t.get(a.target.functionId);s===void 0||r.get(s.moduleId)?.externalSurface===!0||o.set(s.id,s)}return[...o.values()]}function ai(e){let n="node_modules/",t=e.lastIndexOf(n);if(t===-1)return e;let o=e.slice(t+n.length).split("/"),i=o[0]?.startsWith("@")===!0?2:1;return o.slice(i).join("/")}function pd(e,n,t){if(t.symbolKind==="accessor"||t.symbolKind==="pattern")return;let r=t.symbolKind==="method"||t.symbolKind==="ctor",o=new Map(e.classes.map(i=>[i.id,i]));return e.functions.find(i=>{if(i.name!==t.exportName)return!1;let a=n.get(i.moduleId);if(a===void 0||a.packageName!==t.packageName)return!1;if(r){if(i.kind!==t.symbolKind||i.enclosingClassId===void 0||o.get(i.enclosingClassId)?.name!==t.container)return!1}else if(i.kind!=="function")return!1;return a.externalSurface===!0?!0:ai(a.path)===t.sourcePath})}function si(e,n){return e.modules.find(t=>t.externalSurface!==!0&&t.packageName===n.packageName&&ai(t.path)===n.sourcePath)}function md(e,n,t,r){let o=new Map(e.functions.map(i=>[i.id,i]));return e.callSites.some(i=>i.calleeExprShape!=="member"||i.resolution!=="resolved"?!1:i.resolvedTargetIds.some(a=>{let l=o.get(a);if(l?.name!==r.exportName)return!1;let s=n.get(l.moduleId);return s?.externalSurface===!0&&s.packageName===r.packageName&&t.has(l.moduleId)}))}function hd(e,n,t){return t.container===null?!0:e.classes.some(r=>{if(r.name!==t.container)return!1;let o=n.get(r.moduleId);return o!==void 0&&o.packageName===t.packageName&&o.externalSurface!==!0})}function gd(e,n,t){let r=new Map(e.callSites.map(s=>[s.id,s.enclosingFunctionId])),o=new Map;for(let s of e.callEdges){let d=r.get(s.callSiteId);if(d===void 0)continue;let u=o.get(d)??[];u.push({to:s.calleeFunctionId,res:s.resolution}),o.set(d,u)}let i=s=>{let d=new Set,u=n.map(p=>({id:p.id,prev:null}));for(let p of u)d.add(p.id);for(;u.length>0;){let p=u.shift();if(p===void 0)break;if(p.id===t){let f=[];for(let h=p;h!==null;h=h.prev)f.unshift(h.id);return f}for(let f of o.get(p.id)??[])f.res!=="unresolved"&&(f.res==="field-based"&&!s||d.has(f.to)||(d.add(f.to),u.push({id:f.to,prev:p})))}return null},a=i(!1);if(a!==null)return{path:a,usedFieldBased:!1};let l=i(!0);return l!==null?{path:l,usedFieldBased:!0}:null}function yr(e){return li(e,Ln(e),Ze(e),di(e))}function li(e,n,t,r){let o=[],i=[],a=new Map(e.functions.map(s=>[s.id,s.moduleId])),l=s=>s!==void 0&&t.has(s)&&r.has(n.get(s)?.packageName??"");for(let s of e.callSites)s.resolution==="unresolved"&&l(a.get(s.enclosingFunctionId))&&o.push(s.range);for(let s of e.imports)!s.specifierIsLiteral&&t.has(s.moduleId)&&i.push({path:n.get(s.moduleId)?.path??"",start:0,end:0});return{dispatch:o,load:i}}function di(e){return new Set(e.modules.filter(n=>n.isEntrypoint).map(n=>n.packageName))}function yd(e,n){let t=new Map(e.functions.map(o=>[o.id,o])),r=Ln(e);return n.map(o=>{let i=t.get(o),a=i!==void 0?r.get(i.moduleId):void 0;return{functionId:o,functionName:i?.name,modulePath:a?.path??""}})}function xr(e){let{graph:n,installed:t,range:r,symbol:o,coverage:i}=e,a=[],l={unresolvedSites:a,unresolvedEvidence:{own:a,sets:[]}},s=B=>({unresolvedSites:B,unresolvedEvidence:{own:B,sets:[]}}),d=di(n),u=new Set;for(let B of e.incompleteness)B.reach.kind==="unbounded"&&u.add(B.source);let p=e.incompleteness.some(B=>B.reach.kind==="assumed-bounded")?"loader-assumption":"complete",f=B=>B==="not-reachable"?p:void 0,h=new Map,g=B=>{let W=h.get(B);return W===void 0&&(W=ud(n,B,u),h.set(B,W)),W},S=B=>B.reach.kind==="class-scope"&&o!==null&&o.packageName===B.reach.packageName&&o.container===B.reach.container,E=B=>{if(e.analysisAborted!==null)return{cause:e.analysisAborted,source:null};for(let W of mr)for(let $ of e.incompleteness)if($.cause===W&&B($))return{cause:$.cause,source:$.source};return null},w=B=>{let W;return E($=>$.reach.kind==="unbounded"?!0:$.reach.kind==="class-scope"?S($):B===void 0||g($.reach.anchor)?!0:(W??=cd(n,B),W.has($.reach.anchor)))},I=()=>E(B=>B.reach.kind==="unbounded"?!0:B.reach.kind==="class-scope"?S(B):g(B.reach.anchor));if(t===null)return{tier:"not-affected",decidedAtStage:"presence",reason:`${r.packageName} is not installed`,unknownKind:void 0,attribution:void 0,basis:f("not-affected"),path:void 0,...l};let v;try{if((t.ecosystem??"npm")!==(r.ecosystem??"npm"))throw new Error("ecosystem mismatch");v=En(t.version,r)}catch{return{tier:"unknown",decidedAtStage:"version-match",reason:`cannot compare version ${JSON.stringify(t.version)} against the advisory range`,unknownKind:"version-undecidable",attribution:void 0,basis:f("unknown"),path:void 0,...l}}if(!v)return{tier:"not-affected",decidedAtStage:"version-match",reason:`${r.packageName}@${t.version} is outside the affected range`,unknownKind:void 0,attribution:void 0,basis:f("not-affected"),path:void 0,...l};let _=Ln(n),k=Ze(n),m=B=>{if(B.cause!=="dynamic-load"||B.source===null)return a;let W=_.get(B.source);return W===void 0?a:[{path:W.path,start:0,end:0}]},{dispatch:y,load:A}=li(n,_,k,d),C=[...y,...A],T={unresolvedSites:A,unresolvedEvidence:{own:a,sets:["load"]}},P={unresolvedSites:C,unresolvedEvidence:{own:a,sets:["dispatch","load"]}},R=B=>{for(let W of k)if(_.get(W)?.packageName===B)return!0;return!1},F=B=>({tier:"unknown",decidedAtStage:B,reason:`${o?.exportName??"the certified symbols"} not reached from the application's entrypoints, but the advisory's symbol set is known to be incomplete (surface_complete=0) \u2014 a symbol cupel could not name may be reached; cannot confirm it is unreachable`,unknownKind:"incomplete-surface",attribution:void 0,basis:f("unknown"),path:void 0,...l}),O=()=>{if(!R(r.packageName)){if(A.length>0)return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.packageName} is not statically loaded, but a dynamic module load (a non-literal require/import) could pull it`,unknownKind:"dynamic-load",attribution:void 0,basis:f("unknown"),path:void 0,...T};let B=I();return B!==null?{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.packageName} is not statically loaded, but an incompleteness fact (loader escape / analysis cap / opaque module) could hide a load \u2014 cannot confirm it is unreachable`,unknownKind:B.cause,attribution:void 0,basis:f("unknown"),path:void 0,...s(m(B))}:t!==null&&t.outOfGraphExecution.length>0?{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.packageName} is never loaded from the application's entrypoints, but it can still execute outside the module graph (${t.outOfGraphExecution.join(", ")}) \u2014 "not loaded as a module" is not "not executed"`,unknownKind:"analysis-cap",attribution:void 0,basis:f("unknown"),path:void 0,...l}:{tier:"not-reachable",decidedAtStage:"symbol-reachable",reason:t?.devOnly===!0?`${r.packageName} is not reachable at runtime \u2014 installed as a dev-only dependency and never loaded from the application's entrypoints (assumes no dependency loader loads it); still a build-time exposure`:`${r.packageName} is installed but never loaded from the application's entrypoints (no static import, no dynamic load, corridor complete)`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}}return null};if(o===null||!o.verified)return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:o===null?"no derived vulnerable symbol for this advisory (package-level only)":"vulnerable symbol is unverified; cannot claim reachability",unknownKind:o===null?"db-gap":"unverified-symbol",attribution:void 0,basis:f("unknown"),path:void 0,...P};if(i!==null&&!i.comparedPaths.has(o.sourcePath))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`derivation did not cover ${o.sourcePath}; symbol reachability undetermined`,unknownKind:"db-gap",attribution:void 0,basis:f("unknown"),path:void 0,...P};if(o.symbolKind==="accessor"||o.symbolKind==="pattern")return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.exportName} is a ${o.symbolKind} symbol; call-graph reachability is not evaluated`,unknownKind:"symbol-unsupported",attribution:void 0,basis:f("unknown"),path:void 0,...P};let L=pd(n,_,o);if(L===void 0||!k.has(L.moduleId)){if(L===void 0&&(o.symbolKind==="method"||o.symbolKind==="ctor")&&md(n,_,k,o))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.exportName} may be a static method reached via an ambiguous package-surface member call`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...P};if(L===void 0&&(o.symbolKind==="method"||o.symbolKind==="ctor")&&!hd(n,_,o))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.exportName} is a method of the dependency class ${o.container??"?"}, whose body cupel does not analyze \u2014 a sibling method may reach it through an internal edge`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...P};let B=O();if(B!==null)return B;if(C.length>0){let q=L!==void 0?_.get(L.moduleId):si(n,o),H=L===void 0&&q!==void 0&&q.externalSurface!==!0&&k.has(q.id)&&!d.has(q.packageName);return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.exportName} not statically reached, but unresolved dynamic access exists`,unknownKind:A.length>0?"dynamic-load":H?"dep-opaque":"dispatch",attribution:void 0,basis:f("unknown"),path:void 0,...P}}let W=L!==void 0?_.get(L.moduleId):si(n,o);if(L===void 0&&W!==void 0&&W.externalSurface!==!0&&k.has(W.id)&&!d.has(W.packageName))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.exportName} is in a loaded dependency module whose bodies are not analyzed (bodyless CJS/member-export surface) \u2014 cannot confirm it is unreachable`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...l};let $=W!==void 0?w(W.id):I();return $!==null?{tier:"unknown",decidedAtStage:L===void 0?"symbol-reachable":"module-reachable",reason:`${o.exportName} not statically reached, but an incompleteness fact can hide a path to its corridor \u2014 cannot confirm it is unreachable`,unknownKind:$.cause,attribution:void 0,basis:f("unknown"),path:void 0,...s(m($))}:r.surfaceComplete?{tier:"not-reachable",decidedAtStage:L===void 0?"symbol-reachable":"module-reachable",reason:`${o.exportName} is never reached from the application's entrypoints`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}:F(L===void 0?"symbol-reachable":"module-reachable")}let K=gd(n,fd(n),L.id);if(K!==null)return{tier:Xn(K.usedFieldBased?"field-based":"all-resolved"),decidedAtStage:"call-path-confirmed",reason:`${o.exportName} is called from an application entrypoint`,unknownKind:void 0,attribution:_t(o),basis:f("reachable-high"),path:yd(n,K.path),...l};if(C.length>0)return{tier:"unknown",decidedAtStage:"call-path-confirmed",reason:`no resolved call path to ${o.exportName}, but unresolved edges exist`,unknownKind:A.length>0?"dynamic-load":"dispatch",attribution:void 0,basis:f("unknown"),path:void 0,...P};let G=w(L.moduleId);return G!==null?{tier:"unknown",decidedAtStage:"call-path-confirmed",reason:`no resolved call path to ${o.exportName}, but an incompleteness fact can hide a path to its corridor \u2014 cannot confirm it is uncalled`,unknownKind:G.cause,attribution:void 0,basis:f("unknown"),path:void 0,...s(m(G))}:r.surfaceComplete?{tier:"not-reachable",decidedAtStage:"call-path-confirmed",reason:`${o.exportName} is imported but never called from an entrypoint`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}:F("call-path-confirmed")}function xd(e,n){return e.packageName===n.packageName&&e.exportName===n.exportName&&e.container===n.container}function Sd(e,n,t){let r=new Map(e.classes.map(o=>[o.id,o.name]));for(let o of e.functions){if(o.name!==t.exportName)continue;let i=n.get(o.moduleId);if(!(i===void 0||i.packageName!==t.packageName||(o.enclosingClassId!==void 0?r.get(o.enclosingClassId)??null:null)!==t.container))return o.id}return null}function bd(e,n,t){if(n===t)return[];let r=new Map(e.functions.map(s=>[s.id,s])),o=new Map(e.callSites.map(s=>[s.id,s])),i=new Map;for(let s of e.callEdges){if(s.resolution!=="resolved"&&s.resolution!=="field-based")continue;let d=o.get(s.callSiteId);if(d===void 0)continue;let u=d.enclosingFunctionId;if(!r.has(u)||!r.has(s.calleeFunctionId))continue;let p=i.get(u),f={to:s.calleeFunctionId,label:s.resolution};p===void 0?i.set(u,[f]):p.push(f)}let a=new Set([n]),l=[{at:n,labels:[]}];for(let s=0;s<l.length;s++){let d=l[s];for(let u of i.get(d.at)??[]){if(a.has(u.to))continue;let p=[...d.labels,u.label];if(u.to===t)return p;a.add(u.to),l.push({at:u.to,labels:p})}}return null}function Jn(e,n,t,r,o){if(o.length===0)return null;let i=At(e,n,t);if(i.length===0)return null;let a=Sd(e,n,r);for(let l of o){let s=i.filter(u=>u.packageName===l.anchor.packageName&&u.exportName===l.anchor.exportName&&u.container===l.anchor.container),d=s.find(u=>u.resolution==="resolved")??s[0];if(d!==void 0){if(xd(l.callee,r))return{tier:Xn("modeled"),modelId:l.modelId,anchorPackage:l.anchor.packageName,entryExport:l.anchor.exportName,pathLabels:[d.resolution,"modeled"]};if(l.callee.realFunctionId!==null&&a!==null){let u=bd(e,l.callee.realFunctionId,a);if(u!==null)return{tier:Xn("modeled"),modelId:l.modelId,anchorPackage:l.anchor.packageName,entryExport:l.anchor.exportName,pathLabels:[d.resolution,"modeled",...u]}}}}return null}var ci=["presence","version-match","module-reachable","symbol-reachable","call-path-confirmed"],ui=["not-affected","not-reachable","reachable-high","reachable-medium","reachable-low","unknown"];function _t(e){return e.verified?"gated":"candidate"}var Sr=["no-entrypoint","analyzer-crash","version-undecidable","db-gap","unverified-symbol","symbol-unsupported","dep-opaque","dynamic-load","dispatch","resolution-divergence","analysis-cap","coverage-gap","incomplete-surface"],br=["cupel","project"],Fe={"no-entrypoint":"project","dynamic-load":"project",dispatch:"project","analyzer-crash":"cupel","version-undecidable":"cupel","db-gap":"cupel","unverified-symbol":"cupel","symbol-unsupported":"cupel","dep-opaque":"cupel","resolution-divergence":"cupel","analysis-cap":"cupel","coverage-gap":"cupel","incomplete-surface":"cupel"};function fi(e){return Fe[e]}import{randomBytes as Wa}from"node:crypto";import{mkdirSync as qa,readdirSync as Ja,readFileSync as $p,realpathSync as gt,renameSync as Ga,statSync as No,writeFileSync as Ha}from"node:fs";import tn from"node:path";import{createRequire as kd}from"node:module";var Ed=kd(import.meta.url);function wd(){try{return Ed("node:sqlite")}catch{throw new Error("node:sqlite is unavailable on this runtime (needs Node >= 22.13, or 24+). See ADR-013.")}}function vd(e){return{all:n=>n===void 0?e.all():e.all(n),get:n=>n===void 0?e.get():e.get(n),run:n=>n===void 0?e.run():e.run(n)}}var Nt={open(e,n){let{DatabaseSync:t}=wd(),r=n==="readonly"?new t(e,{readOnly:!0}):new t(e);return n==="readonly"?r.exec("PRAGMA query_only = ON;"):r.exec("PRAGMA journal_mode = DELETE;"),{exec:o=>r.exec(o),prepare:o=>vd(r.prepare(o)),close:()=>r.close()}}};function be(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="bigint"?String(e):""}function ge(e){return typeof e=="string"?e:null}function Qe(e){return typeof e=="number"?e:typeof e=="bigint"?Number(e):null}var Id=`
|
|
2
|
+
import{randomBytes as Hd}from"node:crypto";import{readFileSync as My,renameSync as Ty,writeFileSync as Xd}from"node:fs";import Dy from"node:path";import{fileURLToPath as Ly}from"node:url";var Jd=/^(\d{1,10})\.(\d{1,10})\.(\d{1,10})$/u;function Zd(e){let n=Jd.exec(e);return n===null?null:{kind:"npm",release:[Number(n[1]),Number(n[2]),Number(n[3])]}}function Qd(e,n){for(let t=0;t<3;t+=1){let o=e.release[t]??0,r=n.release[t]??0;if(o!==r)return o<r?-1:1}return 0}var ec=/^v?(?:(?<epoch>[0-9]+)!)?(?<release>[0-9]+(?:\.[0-9]+)*)(?:[-_.]?(?<preL>a|b|c|rc|alpha|beta|pre|preview)[-_.]?(?<preN>[0-9]+)?)?(?:(?:-(?<postImplicit>[0-9]+))|(?:[-_.]?(?<postL>post|rev|r)[-_.]?(?<postN>[0-9]+)?))?(?:[-_.]?(?<devL>dev)[-_.]?(?<devN>[0-9]+)?)?(?:\+(?<local>[a-z0-9]+(?:[-_.][a-z0-9]+)*))?$/u,nc={a:"a",alpha:"a",b:"b",beta:"b",c:"rc",pre:"rc",preview:"rc",rc:"rc"};function Zn(e){if(e===void 0)return null;let n=Number(e);return Number.isSafeInteger(n)?n:null}function tc(e){let n=ec.exec(e.toLowerCase());if(n===null||n.groups===void 0)return null;let t=n.groups,o=(t.release??"").split(".");if(o.length===0||o.length>32)return null;let r=[];for(let u of o){let p=Zn(u);if(p===null)return null;r.push(p)}let s=0;if(t.epoch!==void 0){let u=Zn(t.epoch);if(u===null)return null;s=u}let a=null;if(t.preL!==void 0){let u=t.preN===void 0?0:Zn(t.preN);if(u===null)return null;a=[nc[t.preL]??t.preL,u]}let l=null;if(t.postImplicit!==void 0){let u=Zn(t.postImplicit);if(u===null)return null;l=u}else if(t.postL!==void 0){let u=t.postN===void 0?0:Zn(t.postN);if(u===null)return null;l=u}let i=null;if(t.devL!==void 0){let u=t.devN===void 0?0:Zn(t.devN);if(u===null)return null;i=u}let d=t.local===void 0?null:t.local.split(/[-_.]/u).map(u=>/^[0-9]+$/u.test(u)?Number(u):u);return{kind:"PyPI",epoch:s,release:r,pre:a,post:l,dev:i,local:d}}function Qn(e,n){return e===n?0:e<n?-1:1}function Ks(e){let n=e.length;for(;n>1&&e[n-1]===0;)n-=1;return e.slice(0,n)}function oc(e,n){let t=Ks(e),o=Ks(n),r=Math.max(t.length,o.length);for(let s=0;s<r;s+=1){let a=Qn(t[s]??0,o[s]??0);if(a!==0)return a}return 0}function Us(e){return e.pre!==null?0:e.post===null&&e.dev!==null?-1:1}function rc(e,n){let t=Us(e),o=Us(n);return t!==o?t<o?-1:1:t!==0||e.pre===null||n.pre===null?0:e.pre[0]!==n.pre[0]?e.pre[0]<n.pre[0]?-1:1:Qn(e.pre[1],n.pre[1])}function sc(e,n){return e===null&&n===null?0:e===null?-1:n===null?1:Qn(e,n)}function ic(e,n){return e===null&&n===null?0:e===null?1:n===null?-1:Qn(e,n)}function ac(e,n){let t=typeof e=="number",o=typeof n=="number";return t&&o?Qn(e,n):!t&&!o?e===n?0:e<n?-1:1:t?1:-1}function lc(e,n){if(e===null&&n===null)return 0;if(e===null)return-1;if(n===null)return 1;let t=Math.max(e.length,n.length);for(let o=0;o<t;o+=1){let r=e[o],s=n[o];if(r===void 0)return-1;if(s===void 0)return 1;let a=ac(r,s);if(a!==0)return a}return 0}function dc(e,n){let t=Qn(e.epoch,n.epoch);if(t!==0)return t;let o=oc(e.release,n.release);if(o!==0)return o;let r=rc(e,n);if(r!==0)return r;let s=sc(e.post,n.post);if(s!==0)return s;let a=ic(e.dev,n.dev);return a!==0?a:lc(e.local,n.local)}function cc(e,n){if(typeof n!="string"||n.length===0||n.length>256)return null;let t=e==="npm"?Zd(n):tc(n);return t===null?null:{ecosystem:e,raw:n,parsed:t}}function ht(e,n){let t=cc(e,n);if(t===null)throw new Error(`not a valid ${e} version: ${JSON.stringify(n)}`);return t}function Qt(e,n){if(e.ecosystem!==n.ecosystem)throw new Error(`cannot compare ${e.ecosystem} with ${n.ecosystem}`);if(e.parsed.kind==="npm"&&n.parsed.kind==="npm")return Qd(e.parsed,n.parsed);if(e.parsed.kind==="PyPI"&&n.parsed.kind==="PyPI")return dc(e.parsed,n.parsed);throw new Error("unreachable: ecosystem/parsed mismatch")}function zs(e,n,t){let o=ht(e,n);return!(t.introduced!=="0"&&Qt(o,ht(e,t.introduced))<0||t.fixed!==void 0&&Qt(o,ht(e,t.fixed))>=0||t.lastAffected!==void 0&&Qt(o,ht(e,t.lastAffected))>0)}var Go=["no-entrypoint","dynamic-load","resolution-divergence","analysis-cap","dep-opaque"];function Ln(e,n){return zs(n.ecosystem??"npm",e,n)}function eo(e,n,t){let o=new Map(e.functions.map(l=>[l.id,l])),r=new Map(e.classes.map(l=>[l.id,l.name])),s=new Map(e.callSites.map(l=>[l.id,l])),a=[];for(let l of e.callEdges){if(l.resolution!=="resolved"&&l.resolution!=="field-based")continue;let i=s.get(l.callSiteId);if(i===void 0)continue;let d=o.get(i.enclosingFunctionId);if(d===void 0||!t.has(d.moduleId))continue;let u=n.get(d.moduleId);if(u===void 0)continue;let p=o.get(l.calleeFunctionId);if(p===void 0||p.name===void 0)continue;let f=n.get(p.moduleId);f!==void 0&&f.packageName!==u.packageName&&a.push({packageName:f.packageName,exportName:p.name,container:p.enclosingClassId!==void 0?r.get(p.enclosingClassId)??null:null,resolution:l.resolution})}return a}function uc(e,n){return(e.get(n)??[]).filter(t=>t.status==="summarized").slice().sort((t,o)=>t.analyzedVersion<o.analyzedVersion?1:t.analyzedVersion>o.analyzedVersion?-1:0)}function fc(e,n,t){return e.target.kind!=="symbol"||t!==n.packageName?!1:e.target.exportName===n.exportName&&e.target.container===n.container&&e.target.symbolKind===n.symbolKind}function Ws(e,n,t,o,r,s){if(s<=0)return null;let a=null,l=i=>{(a===null||i.hops<a.hops)&&(a=i)};for(let i of uc(e,n))for(let d of i.edges){if(d.entryExport!==t||d.entryContainer!==o)continue;if(fc(d,r,i.packageName)){l({viaPackages:[],hops:d.hops,provenance:{tool:i.tool,toolVersion:i.toolVersion,analyzedVersion:i.analyzedVersion}});continue}if(d.target.kind!=="dep")continue;let u=Ws(e,d.target.calleePackage,d.target.calleeExport,null,r,s-1);u!==null&&l({viaPackages:[d.target.calleePackage,...u.viaPackages],hops:d.hops+u.hops,provenance:u.provenance})}return a}function Ho(e,n,t,o,r,s){let a=null;for(let l of eo(e,n,t)){let i=Ws(r,l.packageName,l.exportName,l.container,o,s);i!==null&&(a===null||i.hops<a.totalHops)&&(a={tier:"reachable-low",anchorPackage:l.packageName,entryExport:l.exportName,viaPackages:i.viaPackages,totalHops:i.hops,provenance:i.provenance})}return a}function gt(e){switch(e){case"all-resolved":return"reachable-high";case"field-based":return"reachable-medium";case"modeled":return"reachable-low"}}function et(e){let n=new Map;for(let t of e.modules)n.set(t.id,t);return n}function Xo(e){let n=new Map,t=new Map(e.imports.map(o=>[o.id,o]));for(let o of e.importEdges){let r=t.get(o.importId);if(r===void 0)continue;let s=n.get(r.moduleId)??[];s.push(o.resolvedModuleId),n.set(r.moduleId,s)}return n}function pc(e){let n=new Map,t=new Map(e.imports.map(o=>[o.id,o]));for(let o of e.importEdges){let r=t.get(o.importId);if(r===void 0)continue;let s=n.get(o.resolvedModuleId)??[];s.push(r.moduleId),n.set(o.resolvedModuleId,s)}return n}function ln(e){let n=Xo(e),t=new Set,o=e.modules.filter(r=>r.isEntrypoint).map(r=>r.id);for(;o.length>0;){let r=o.pop();if(!(r===void 0||t.has(r))){t.add(r);for(let s of n.get(r)??[])t.has(s)||o.push(s)}}return t}function mc(e,n){let t=pc(e),o=new Set,r=[n];for(;r.length>0;){let s=r.pop();if(!(s===void 0||o.has(s))){o.add(s);for(let a of t.get(s)??[])o.has(a)||r.push(a)}}return o}function hc(e,n,t){let o=Xo(e),r=et(e),s=new Set,a=[n];for(;a.length>0;){let l=a.pop();if(l===void 0||s.has(l))continue;s.add(l);let i=r.get(l);if(i===void 0||i.externalSurface===!0||t.has(l))return!0;for(let d of o.get(l)??[])s.has(d)||a.push(d)}return!1}function yt(e,n,t,o=new Set){let r=Xo(e),s=et(e),a=new Set,l=[],i=[n];for(;i.length>0;){let d=i.pop();if(d===void 0||a.has(d))continue;a.add(d);let u=s.get(d);if(u===void 0){l.push({module:d,kind:"absent"});continue}if(t.has(d)){l.push({module:d,kind:"unbounded"});continue}if(u.externalSurface===!0&&!o.has(d)){l.push({module:d,kind:"surface"});continue}for(let p of r.get(d)??[])a.has(p)||i.push(p)}return l}function gc(e){let n=new Set(e.modules.filter(a=>a.isEntrypoint).map(a=>a.id)),t=new Map(e.functions.map(a=>[a.id,a])),o=et(e),r=new Map;for(let a of e.functions)n.has(a.moduleId)&&(a.publicSurfaceReachable||a.name==="<toplevel>")&&r.set(a.id,a);let s=new Map(e.exports.map(a=>[a.id,a]));for(let a of e.exportBindings){if(a.target.kind!=="function")continue;let l=s.get(a.exportId);if(l===void 0||!n.has(l.moduleId))continue;let i=t.get(a.target.functionId);i===void 0||o.get(i.moduleId)?.externalSurface===!0||r.set(i.id,i)}return[...r.values()]}function qs(e){let n="node_modules/",t=e.lastIndexOf(n);if(t===-1)return e;let r=e.slice(t+n.length).split("/"),s=r[0]?.startsWith("@")===!0?2:1;return r.slice(s).join("/")}function yc(e,n,t){if(t.symbolKind==="accessor"||t.symbolKind==="pattern")return;let o=t.symbolKind==="method"||t.symbolKind==="ctor",r=new Map(e.classes.map(s=>[s.id,s]));return e.functions.find(s=>{if(s.name!==t.exportName)return!1;let a=n.get(s.moduleId);if(a===void 0||a.packageName!==t.packageName)return!1;if(o){if(s.kind!==t.symbolKind||s.enclosingClassId===void 0||r.get(s.enclosingClassId)?.name!==t.container)return!1}else if(s.kind!=="function")return!1;return a.externalSurface===!0?!0:qs(a.path)===t.sourcePath})}function Vs(e,n){return e.modules.find(t=>t.externalSurface!==!0&&t.packageName===n.packageName&&qs(t.path)===n.sourcePath)}function xc(e,n,t,o){let r=new Map(e.functions.map(s=>[s.id,s]));return e.callSites.some(s=>s.calleeExprShape!=="member"||s.resolution!=="resolved"?!1:s.resolvedTargetIds.some(a=>{let l=r.get(a);if(l?.name!==o.exportName)return!1;let i=n.get(l.moduleId);return i?.externalSurface===!0&&i.packageName===o.packageName&&t.has(l.moduleId)}))}function Sc(e,n,t){return t.container===null?!0:e.classes.some(o=>{if(o.name!==t.container)return!1;let r=n.get(o.moduleId);return r!==void 0&&r.packageName===t.packageName&&r.externalSurface!==!0})}function bc(e,n,t){let o=new Map(e.callSites.map(i=>[i.id,i.enclosingFunctionId])),r=new Map;for(let i of e.callEdges){let d=o.get(i.callSiteId);if(d===void 0)continue;let u=r.get(d)??[];u.push({to:i.calleeFunctionId,res:i.resolution}),r.set(d,u)}let s=i=>{let d=new Set,u=n.map(p=>({id:p.id,prev:null}));for(let p of u)d.add(p.id);for(;u.length>0;){let p=u.shift();if(p===void 0)break;if(p.id===t){let f=[];for(let m=p;m!==null;m=m.prev)f.unshift(m.id);return f}for(let f of r.get(p.id)??[])f.res!=="unresolved"&&(f.res==="field-based"&&!i||d.has(f.to)||(d.add(f.to),u.push({id:f.to,prev:p})))}return null},a=s(!1);if(a!==null)return{path:a,usedFieldBased:!1};let l=s(!0);return l!==null?{path:l,usedFieldBased:!0}:null}function Yo(e){return Gs(e,et(e),ln(e),Hs(e))}function Gs(e,n,t,o){let r=[],s=[],a=new Map(e.functions.map(i=>[i.id,i.moduleId])),l=i=>i!==void 0&&t.has(i)&&o.has(n.get(i)?.packageName??"");for(let i of e.callSites)i.resolution==="unresolved"&&l(a.get(i.enclosingFunctionId))&&r.push(i.range);for(let i of e.imports)!i.specifierIsLiteral&&t.has(i.moduleId)&&s.push({path:n.get(i.moduleId)?.path??"",start:0,end:0});return{dispatch:r,load:s}}function Hs(e){return new Set(e.modules.filter(n=>n.isEntrypoint).map(n=>n.packageName))}function kc(e,n){let t=new Map(e.functions.map(r=>[r.id,r])),o=et(e);return n.map(r=>{let s=t.get(r),a=s!==void 0?o.get(s.moduleId):void 0;return{functionId:r,functionName:s?.name,modulePath:a?.path??""}})}function Jo(e){let{graph:n,installed:t,range:o,symbol:r,coverage:s}=e,a=[],l={unresolvedSites:a,unresolvedEvidence:{own:a,sets:[]}},i=U=>({unresolvedSites:U,unresolvedEvidence:{own:U,sets:[]}}),d=Hs(n),u=new Set;for(let U of e.incompleteness)U.reach.kind==="unbounded"&&u.add(U.source);let p=e.incompleteness.some(U=>U.reach.kind==="assumed-bounded")?"loader-assumption":"complete",f=U=>U==="not-reachable"?p:void 0,m=new Map,g=U=>{let X=m.get(U);return X===void 0&&(X=hc(n,U,u),m.set(U,X)),X},y=U=>U.reach.kind==="class-scope"&&r!==null&&r.packageName===U.reach.packageName&&r.container===U.reach.container,b=U=>{if(e.analysisAborted!==null)return{cause:e.analysisAborted,source:null};for(let X of Go)for(let D of e.incompleteness)if(D.cause===X&&U(D))return{cause:D.cause,source:D.source};return null},x=U=>{let X;return b(D=>D.reach.kind==="unbounded"?!0:D.reach.kind==="class-scope"?y(D):U===void 0||g(D.reach.anchor)?!0:(X??=mc(n,U),X.has(D.reach.anchor)))},I=()=>b(U=>U.reach.kind==="unbounded"?!0:U.reach.kind==="class-scope"?y(U):g(U.reach.anchor));if(t===null)return{tier:"not-affected",decidedAtStage:"presence",reason:`${o.packageName} is not installed`,unknownKind:void 0,attribution:void 0,basis:f("not-affected"),path:void 0,...l};let w;try{if((t.ecosystem??"npm")!==(o.ecosystem??"npm"))throw new Error("ecosystem mismatch");w=Ln(t.version,o)}catch{return{tier:"unknown",decidedAtStage:"version-match",reason:`cannot compare version ${JSON.stringify(t.version)} against the advisory range`,unknownKind:"version-undecidable",attribution:void 0,basis:f("unknown"),path:void 0,...l}}if(!w)return{tier:"not-affected",decidedAtStage:"version-match",reason:`${o.packageName}@${t.version} is outside the affected range`,unknownKind:void 0,attribution:void 0,basis:f("not-affected"),path:void 0,...l};let A=et(n),k=ln(n),h=U=>{if(U.cause!=="dynamic-load"||U.source===null)return a;let X=A.get(U.source);return X===void 0?a:[{path:X.path,start:0,end:0}]},{dispatch:S,load:_}=Gs(n,A,k,d),P=[...S,..._],v={unresolvedSites:_,unresolvedEvidence:{own:a,sets:["load"]}},T={unresolvedSites:P,unresolvedEvidence:{own:a,sets:["dispatch","load"]}},N=U=>{for(let X of k)if(A.get(X)?.packageName===U)return!0;return!1},j=U=>({tier:"unknown",decidedAtStage:U,reason:`${r?.exportName??"the certified symbols"} not reached from the application's entrypoints, but the advisory's symbol set is known to be incomplete (surface_complete=0) \u2014 a symbol cupel could not name may be reached; cannot confirm it is unreachable`,unknownKind:"incomplete-surface",attribution:void 0,basis:f("unknown"),path:void 0,...l}),O=()=>{if(!N(o.packageName)){if(_.length>0)return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.packageName} is not statically loaded, but a dynamic module load (a non-literal require/import) could pull it`,unknownKind:"dynamic-load",attribution:void 0,basis:f("unknown"),path:void 0,...v};let U=I();return U!==null?{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.packageName} is not statically loaded, but an incompleteness fact (loader escape / analysis cap / opaque module) could hide a load \u2014 cannot confirm it is unreachable`,unknownKind:U.cause,attribution:void 0,basis:f("unknown"),path:void 0,...i(h(U))}:t!==null&&t.outOfGraphExecution.length>0?{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${o.packageName} is never loaded from the application's entrypoints, but it can still execute outside the module graph (${t.outOfGraphExecution.join(", ")}) \u2014 "not loaded as a module" is not "not executed"`,unknownKind:"analysis-cap",attribution:void 0,basis:f("unknown"),path:void 0,...l}:{tier:"not-reachable",decidedAtStage:"symbol-reachable",reason:t?.devOnly===!0?`${o.packageName} is not reachable at runtime \u2014 installed as a dev-only dependency and never loaded from the application's entrypoints (assumes no dependency loader loads it); still a build-time exposure`:`${o.packageName} is installed but never loaded from the application's entrypoints (no static import, no dynamic load, corridor complete)`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}}return null};if(r===null||!r.verified)return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:r===null?"no derived vulnerable symbol for this advisory (package-level only)":"vulnerable symbol is unverified; cannot claim reachability",unknownKind:r===null?"db-gap":"unverified-symbol",attribution:void 0,basis:f("unknown"),path:void 0,...T};if(s!==null&&!s.comparedPaths.has(r.sourcePath))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`derivation did not cover ${r.sourcePath}; symbol reachability undetermined`,unknownKind:"db-gap",attribution:void 0,basis:f("unknown"),path:void 0,...T};if(r.symbolKind==="accessor"||r.symbolKind==="pattern")return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.exportName} is a ${r.symbolKind} symbol; call-graph reachability is not evaluated`,unknownKind:"symbol-unsupported",attribution:void 0,basis:f("unknown"),path:void 0,...T};let F=yc(n,A,r);if(F===void 0||!k.has(F.moduleId)){if(F===void 0&&(r.symbolKind==="method"||r.symbolKind==="ctor")&&xc(n,A,k,r))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.exportName} may be a static method reached via an ambiguous package-surface member call`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...T};if(F===void 0&&(r.symbolKind==="method"||r.symbolKind==="ctor")&&!Sc(n,A,r))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.exportName} is a method of the dependency class ${r.container??"?"}, whose body cupel does not analyze \u2014 a sibling method may reach it through an internal edge`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...T};let U=O();if(U!==null)return U;if(P.length>0){let C=F!==void 0?A.get(F.moduleId):Vs(n,r),H=F===void 0&&C!==void 0&&C.externalSurface!==!0&&k.has(C.id)&&!d.has(C.packageName);return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.exportName} not statically reached, but unresolved dynamic access exists`,unknownKind:_.length>0?"dynamic-load":H?"dep-opaque":"dispatch",attribution:void 0,basis:f("unknown"),path:void 0,...T}}let X=F!==void 0?A.get(F.moduleId):Vs(n,r);if(F===void 0&&X!==void 0&&X.externalSurface!==!0&&k.has(X.id)&&!d.has(X.packageName))return{tier:"unknown",decidedAtStage:"symbol-reachable",reason:`${r.exportName} is in a loaded dependency module whose bodies are not analyzed (bodyless CJS/member-export surface) \u2014 cannot confirm it is unreachable`,unknownKind:"dep-opaque",attribution:void 0,basis:f("unknown"),path:void 0,...l};let D=X!==void 0?x(X.id):I();return D!==null?{tier:"unknown",decidedAtStage:F===void 0?"symbol-reachable":"module-reachable",reason:`${r.exportName} not statically reached, but an incompleteness fact can hide a path to its corridor \u2014 cannot confirm it is unreachable`,unknownKind:D.cause,attribution:void 0,basis:f("unknown"),path:void 0,...i(h(D))}:o.surfaceComplete?{tier:"not-reachable",decidedAtStage:F===void 0?"symbol-reachable":"module-reachable",reason:`${r.exportName} is never reached from the application's entrypoints`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}:j(F===void 0?"symbol-reachable":"module-reachable")}let K=bc(n,gc(n),F.id);if(K!==null)return{tier:gt(K.usedFieldBased?"field-based":"all-resolved"),decidedAtStage:"call-path-confirmed",reason:`${r.exportName} is called from an application entrypoint`,unknownKind:void 0,attribution:no(r),basis:f("reachable-high"),path:kc(n,K.path),...l};if(P.length>0)return{tier:"unknown",decidedAtStage:"call-path-confirmed",reason:`no resolved call path to ${r.exportName}, but unresolved edges exist`,unknownKind:_.length>0?"dynamic-load":"dispatch",attribution:void 0,basis:f("unknown"),path:void 0,...T};let te=x(F.moduleId);return te!==null?{tier:"unknown",decidedAtStage:"call-path-confirmed",reason:`no resolved call path to ${r.exportName}, but an incompleteness fact can hide a path to its corridor \u2014 cannot confirm it is uncalled`,unknownKind:te.cause,attribution:void 0,basis:f("unknown"),path:void 0,...i(h(te))}:o.surfaceComplete?{tier:"not-reachable",decidedAtStage:"call-path-confirmed",reason:`${r.exportName} is imported but never called from an entrypoint`,unknownKind:void 0,attribution:void 0,basis:f("not-reachable"),path:void 0,...l}:j("call-path-confirmed")}function Ec(e,n){return e.packageName===n.packageName&&e.exportName===n.exportName&&e.container===n.container}function wc(e,n,t){let o=new Map(e.classes.map(r=>[r.id,r.name]));for(let r of e.functions){if(r.name!==t.exportName)continue;let s=n.get(r.moduleId);if(!(s===void 0||s.packageName!==t.packageName||(r.enclosingClassId!==void 0?o.get(r.enclosingClassId)??null:null)!==t.container))return r.id}return null}function vc(e,n,t){if(n===t)return[];let o=new Map(e.functions.map(i=>[i.id,i])),r=new Map(e.callSites.map(i=>[i.id,i])),s=new Map;for(let i of e.callEdges){if(i.resolution!=="resolved"&&i.resolution!=="field-based")continue;let d=r.get(i.callSiteId);if(d===void 0)continue;let u=d.enclosingFunctionId;if(!o.has(u)||!o.has(i.calleeFunctionId))continue;let p=s.get(u),f={to:i.calleeFunctionId,label:i.resolution};p===void 0?s.set(u,[f]):p.push(f)}let a=new Set([n]),l=[{at:n,labels:[]}];for(let i=0;i<l.length;i++){let d=l[i];for(let u of s.get(d.at)??[]){if(a.has(u.to))continue;let p=[...d.labels,u.label];if(u.to===t)return p;a.add(u.to),l.push({at:u.to,labels:p})}}return null}function xt(e,n,t,o,r){if(r.length===0)return null;let s=eo(e,n,t);if(s.length===0)return null;let a=wc(e,n,o);for(let l of r){let i=s.filter(u=>u.packageName===l.anchor.packageName&&u.exportName===l.anchor.exportName&&u.container===l.anchor.container),d=i.find(u=>u.resolution==="resolved")??i[0];if(d!==void 0){if(Ec(l.callee,o))return{tier:gt("modeled"),modelId:l.modelId,anchorPackage:l.anchor.packageName,entryExport:l.anchor.exportName,pathLabels:[d.resolution,"modeled"]};if(l.callee.realFunctionId!==null&&a!==null){let u=vc(e,l.callee.realFunctionId,a);if(u!==null)return{tier:gt("modeled"),modelId:l.modelId,anchorPackage:l.anchor.packageName,entryExport:l.anchor.exportName,pathLabels:[d.resolution,"modeled",...u]}}}}return null}var Xs=["presence","version-match","module-reachable","symbol-reachable","call-path-confirmed"],Ys=["not-affected","not-reachable","reachable-high","reachable-medium","reachable-low","unknown"];function no(e){return e.verified?"gated":"candidate"}var Zo=["no-entrypoint","analyzer-crash","version-undecidable","db-gap","unverified-symbol","symbol-unsupported","dep-opaque","dynamic-load","dispatch","resolution-divergence","analysis-cap","coverage-gap","incomplete-surface"],Qo=["cupel","project"],Ve={"no-entrypoint":"project","dynamic-load":"project",dispatch:"project","analyzer-crash":"cupel","version-undecidable":"cupel","db-gap":"cupel","unverified-symbol":"cupel","symbol-unsupported":"cupel","dep-opaque":"cupel","resolution-divergence":"cupel","analysis-cap":"cupel","coverage-gap":"cupel","incomplete-surface":"cupel"};function Js(e){return Ve[e]}import{randomBytes as Hl}from"node:crypto";import{mkdirSync as Xl,readdirSync as ed,readFileSync as Th,realpathSync as Wt,renameSync as Yl,statSync as ps,writeFileSync as Jl}from"node:fs";import mn from"node:path";import{createRequire as Ic}from"node:module";var Ac=Ic(import.meta.url);function _c(){try{return Ac("node:sqlite")}catch{throw new Error("node:sqlite is unavailable on this runtime (needs Node >= 22.13, or 24+). See ADR-013.")}}function Nc(e){return{all:n=>n===void 0?e.all():e.all(n),get:n=>n===void 0?e.get():e.get(n),run:n=>n===void 0?e.run():e.run(n)}}var to={open(e,n){let{DatabaseSync:t}=_c(),o=n==="readonly"?new t(e,{readOnly:!0}):new t(e);return n==="readonly"?o.exec("PRAGMA query_only = ON;"):o.exec("PRAGMA journal_mode = DELETE;"),{exec:r=>o.exec(r),prepare:r=>Nc(o.prepare(r)),close:()=>o.close()}}};function Ae(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="bigint"?String(e):""}function Ee(e){return typeof e=="string"?e:null}function dn(e){return typeof e=="number"?e:typeof e=="bigint"?Number(e):null}var Rc=`
|
|
3
3
|
SELECT a.id AS a_id, a.osv_id, a.cve_id, a.summary, a.severity, a.published, a.source,
|
|
4
4
|
ap.id AS ap_id, ap.advisory_id, ap.ecosystem, ap.package_name,
|
|
5
|
-
ap.introduced, ap.fixed, ap.last_affected, ap.fix_commit, ap.repo_url`,
|
|
5
|
+
ap.introduced, ap.fixed, ap.last_affected, ap.fix_commit, ap.repo_url`,Pc=`
|
|
6
6
|
FROM affected_package ap
|
|
7
7
|
JOIN advisory a ON a.id = ap.advisory_id
|
|
8
|
-
WHERE ap.ecosystem = :eco AND ap.package_name = :name
|
|
9
|
-
WHERE vs.affected_package_id = ap.id AND vs.verified = 1) AS surface_complete`,
|
|
8
|
+
WHERE ap.ecosystem = :eco AND ap.package_name = :name`,$c=`EXISTS (SELECT 1 FROM vulnerable_symbol vs
|
|
9
|
+
WHERE vs.affected_package_id = ap.id AND vs.verified = 1) AS surface_complete`,Oc=5,Cc=6;function Mc(e){let n=e>=Cc?"a.details":"NULL AS details",t=e>=Oc?"ap.surface_complete":$c;return`${Rc}, ${n}, ${t}${Pc}`}var Tc="SELECT * FROM vulnerable_symbol WHERE affected_package_id = :id",Dc="SELECT * FROM symbol_alias WHERE vulnerable_symbol_id = :id",Lc="SELECT value FROM ingest_meta WHERE key = 'schema_version'",Fc="SELECT DISTINCT ecosystem FROM affected_package ORDER BY ecosystem";function St(e,n=to){let t=n.open(e,"readonly"),o=t.prepare(Lc).get(),r=o!==void 0?Ae(o.value):"",s=/^\d+$/u.test(r)?Number(r):0,a=t.prepare(Mc(s)),l=t.prepare(Tc),i=t.prepare(Dc),d=t.prepare(Fc);return{schemaVersion:r,ecosystems(){return d.all({}).map(u=>Ae(u.ecosystem))},advisoriesForPackage(u,p){return a.all({eco:u,name:p}).map(f=>({affected:{id:dn(f.ap_id)??0,advisoryId:Ae(f.advisory_id),ecosystem:Ae(f.ecosystem),packageName:Ae(f.package_name),introduced:Ee(f.introduced),fixed:Ee(f.fixed),lastAffected:Ee(f.last_affected),fixCommit:Ee(f.fix_commit),repoUrl:Ee(f.repo_url),surfaceComplete:dn(f.surface_complete)===1?1:0},advisory:{id:Ae(f.a_id),osvId:Ee(f.osv_id),cveId:Ee(f.cve_id),summary:Ee(f.summary),details:Ee(f.details),severity:Ee(f.severity),published:Ee(f.published),source:Ae(f.source)==="osv"?"osv":"ghsa"}}))},symbolsForAffected(u){return l.all({id:u}).map(p=>({id:dn(p.id)??0,affectedPackageId:dn(p.affected_package_id)??0,exportName:Ee(p.export_name),symbolKind:Ae(p.symbol_kind),matchPattern:Ee(p.match_pattern),matchGlobs:Ee(p.match_globs),container:Ee(p.container),sourcePath:Ee(p.source_path),declStart:dn(p.decl_start),declEnd:dn(p.decl_end),astHashBefore:Ee(p.ast_hash_before),astHashAfter:Ee(p.ast_hash_after),derivation:Ae(p.derivation),confidence:Ae(p.confidence),verified:dn(p.verified)===1?1:0}))},aliasesForSymbol(u){return i.all({id:u}).map(p=>({id:dn(p.id)??0,vulnerableSymbolId:dn(p.vulnerable_symbol_id)??0,aliasPath:Ae(p.alias_path),aliasName:Ae(p.alias_name)}))},allModels(){let u;try{u=t.prepare(`SELECT id, package_name, introduced, fixed_before, evidence_ref
|
|
10
10
|
FROM model_package ORDER BY package_name, introduced`).all({})}catch{return[]}let p=t.prepare(`SELECT kind, anchor_export, anchor_container, callee_package, callee_container, callee_export
|
|
11
|
-
FROM model_edge WHERE model_package_id = :id ORDER BY id`);return u.map(f=>{let h=Qe(f.id)??0;return{packageName:be(f.package_name),modelId:be(f.evidence_ref),introduced:be(f.introduced),fixedBefore:ge(f.fixed_before),evidenceRef:be(f.evidence_ref),edges:p.all({id:h}).map(g=>({kind:be(g.kind),anchorExport:be(g.anchor_export),anchorContainer:ge(g.anchor_container),calleePackage:be(g.callee_package),calleeContainer:ge(g.callee_container),calleeExport:be(g.callee_export)}))}})},close(){t.close()}}}function kr(e){let n=e[0];if(n===void 0)throw new Error("compositeShardReader: at least one shard is required");for(let p of e)if(p.schemaVersion!==n.schemaVersion)throw new Error(`compositeShardReader: shards disagree on schema version (${n.schemaVersion} vs ${p.schemaVersion}); refusing to scan against a mixed schema`);let t=new Map,r=new Map,o=new Map,i=new Map,a=1,l=(p,f,h,g)=>{let S=`${String(h)}:${String(g)}`,E=p.get(S);if(E!==void 0)return E;let w=a;a+=1,p.set(S,w);let I=e[h];if(I===void 0)throw new Error("unreachable: reader index out of range");return f.set(w,{reader:I,id:g}),w},s=e.map(p=>new Set(p.ecosystems?.()??[])),d=p=>{let f=e.map((h,g)=>g).filter(h=>s[h]?.has(p)===!0);return f.length>0?f:e.map((h,g)=>g).filter(h=>e[h]?.ecosystems===void 0)},u=(p,f)=>({...f,id:l(o,i,p,f.id),affectedPackageId:l(t,r,p,f.affectedPackageId)});return{schemaVersion:n.schemaVersion,ecosystems(){let p=new Set;for(let f of s)for(let h of f)p.add(h);return[...p].sort()},advisoriesForPackage(p,f){let h=[];for(let g of d(p)){let S=e[g];if(S!==void 0)for(let E of S.advisoriesForPackage(p,f))h.push({...E,affected:{...E.affected,id:l(t,r,g,E.affected.id)}})}return h},symbolsForAffected(p){let f=r.get(p);if(f===void 0)return[];let h=e.indexOf(f.reader);return f.reader.symbolsForAffected(f.id).map(g=>u(h,g))},aliasesForSymbol(p){let f=i.get(p);if(f===void 0)return[];let h=e.indexOf(f.reader);return f.reader.aliasesForSymbol(f.id).map(g=>({...g,vulnerableSymbolId:l(o,i,h,g.vulnerableSymbolId)}))},allModels(){return e.flatMap(p=>p.allModels?.()??[])},close(){for(let p of e)p.close()}}}var wn="6";import{realpathSync as dn}from"node:fs";import ze from"node:path";import{realpathSync as An}from"node:fs";import{isBuiltin as Tr}from"node:module";import Re from"node:path";import b from"typescript";function Er(e){let n=e.trim().replace(/\\/gu,"/"),t=n.length;for(;t>0&&n.charCodeAt(t-1)===47;)t-=1;return t===n.length?n:n.slice(0,t)}function ye(e){let n=Er(e);if(n===""||n.startsWith(".")||n.startsWith("/"))return"relative";if(n.startsWith("@")){let t=n.indexOf("/");return t===-1||n.indexOf("/",t+1)===-1?"package-root":"package-subpath"}return n.includes("/")?"package-subpath":"package-root"}function je(e){let n=Er(e);if(n.startsWith("@")){let r=n.indexOf("/");if(r===-1)return n;let o=n.indexOf("/",r+1);return o===-1?n:n.slice(0,o)}let t=n.indexOf("/");return t===-1?n:n.slice(0,t)}function pi(e){let n=Er(e),t=je(n);return n.length>t.length+1?n.slice(t.length+1):""}import{readFileSync as jd,statSync as wr}from"node:fs";var pn=16*1024*1024;function Fn(e,n){try{let t=wr(e);return t.isFile()?t.size>n?{kind:"too-large",bytes:t.size}:{kind:"ok",text:jd(e,"utf8")}:{kind:"not-regular"}}catch{return{kind:"not-regular"}}}function _e(e){let n=Fn(e,pn);return n.kind==="ok"?n.text:null}function en(e){try{return wr(e).isFile()}catch{return!1}}function mi(e){try{let n=wr(e);return n.isFile()?"file":n.isDirectory()?"dir":"other"}catch{return"other"}}import{opendirSync as Kd,realpathSync as Ar}from"node:fs";import re from"node:path";import Rt from"typescript";var bi=[[".d.mts",[".mjs"]],[".d.cts",[".cjs"]],[".d.ts",[".js",".cjs",".mjs",".jsx"]]];function Me(e){return bi.some(([n])=>e.endsWith(n))}function Bd(e){for(let[n,t]of bi)if(e.endsWith(n)){let r=e.slice(0,-n.length);return t.map(o=>r+o)}return[]}var zd=[[".tsx",[".js",".jsx",".cjs",".mjs"]],[".cts",[".cjs"]],[".mts",[".mjs"]],[".ts",[".js",".cjs",".mjs",".jsx"]]];function ki(e){if(Me(e))return e;for(let[n,t]of zd)if(e.endsWith(n)){let r=e.slice(0,-n.length);for(let o of t){let i=r+o;if(en(i))return i}return e}return e}var _r=[Rt.ModuleKind.CommonJS,Rt.ModuleKind.ESNext],Nr=[[],["node-addons"],["module-sync"],["node-addons","module-sync"]];function Qn(e,n,t,r,o,i){let a=Rt.resolveModuleName(e,n,t,r,void 0,void 0,o).resolvedModule;if(a===void 0)return null;let l=a.resolvedFileName;if(i){for(let s of Bd(l))if(en(s))return s}return l}var Ei=[".js",".jsx",".cjs",".mjs",".ts",".tsx",".cts",".mts"],Ud=[".js",".json",".node"],Vd=["index.js","index.json","index.node"];function Ct(e){return!Me(e)&&Ei.some(n=>e.endsWith(n))}function wi(e){if(en(e))return e;for(let n of Ud)if(en(e+n))return e+n;return null}function hi(e){for(let n of Vd){let t=re.join(e,n);if(en(t))return t}return null}var vi=[".ts",".tsx",".cts",".mts",".jsx"];function Wd(e){for(let n of vi)if(en(e+n))return e+n;return null}function qd(e){for(let n of vi){let t=re.join(e,"index"+n);if(en(t))return t}return null}function Rr(e){let n=_e(re.join(e,"package.json"));if(n!==null)try{let t=JSON.parse(n).main;if(typeof t=="string"&&t.length>0){let r=re.join(e,t),o=wi(r)??hi(r);if(o!==null)return o}}catch{}return hi(e)}function Ii(e){return wi(e)??Rr(e)??Wd(e)??qd(e)}function Ai(e){return Ii(e)!==null}function Gd(e,n){let t=e.split(re.sep),r=n.split("/"),o=null;for(let a=t.length-r.length-1;a>=0;a-=1)if(t[a]==="node_modules"&&r.every((l,s)=>t[a+1+s]===l)){o=t.slice(0,a+1+r.length).join(re.sep);break}if(o===null||o==="")return null;let i=_e(re.join(o,"package.json"));if(i===null)return null;try{let a=JSON.parse(i),l=a.exports,s=typeof l=="string"||Array.isArray(l)||typeof l=="object"&&l!==null;if(a.name!==n||s)return null}catch{return null}try{return Ar(o)}catch{return null}}function Hd(e,n){let t=Ii(re.join(e,n));if(t===null)return null;let r;try{r=Ar(t)}catch{return null}let o=e.endsWith(re.sep)?e:e+re.sep;return r!==e&&!r.startsWith(o)||Me(r)||!Ei.some(i=>r.endsWith(i))?null:r}function Xd(e,n){let t=pi(e);return t===""||t.includes("\0")||t.split("/").some(r=>r===""||r==="."||r===".."||r==="node_modules")?null:Hd(n,t)}var vn={kind:"nothing-loads"},vr=8192;function Ir(e,n){let t=n.get(e);if(t!==void 0)return t;let r,o=null;try{o=Kd(e);let i=new Set,a=!1;for(;;){let l=o.readSync();if(l===null)break;if(i.size>=vr){a=!0;break}i.add(l.name)}r={names:i,truncated:a}}catch{r=null}finally{try{o?.closeSync()}catch{}}return n.set(e,r),r}var Yd=[".json",".css",".scss",".sass",".less",".styl",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico",".bmp",".woff",".woff2",".ttf",".otf",".eot",".mp3",".mp4",".webm",".txt"];function _i(e){return Yd.some(n=>e.length>n.length&&e.endsWith(n))}function mn(e,n){let t=e.endsWith(re.sep)?e:e+re.sep;return n===e||n.startsWith(t)}function gi(e,n){let t;try{t=Ar(n)}catch{return{kind:"missing"}}return mn(e,t)?{kind:"ok",real:t}:{kind:"escaped"}}function yi(e,n){let t=(n+".").toLowerCase(),r=[];for(let o of e){let i=o.toLowerCase();i.length>t.length&&i.startsWith(t)&&r.push(o)}return r}function Jd(e,n,t){let r=re.dirname(n);if(!mn(e,r))return null;let o=Ir(r,t);if(o===null)return null;let i=re.basename(n);return o.names.has(i)?i:null}function xi(e,n){let t=e.filter(o=>!_i(o));if(t.length===0)return vn;let r=[...t].sort()[0]??"";return{kind:"unanalyzable",reason:`${n} ("${r}") the analyzer cannot parse`,why:"sibling-unparsable"}}function Ni(e,n,t,r){let o=e,i=o.indexOf("?");i!==-1&&(o=o.slice(0,i));let a=o.indexOf("#");if(a!==-1&&(o=o.slice(0,a)),o===""||o.includes("\0"))return vn;let l=re.resolve(re.dirname(n),o);if(!mn(t,l))return{kind:"unanalyzable",reason:"its target is outside the scan root and was not probed",why:"out-of-root"};let s=gi(t,l);if(s.kind==="escaped")return{kind:"unanalyzable",reason:"a symlink carries its target outside the scan root, which was not probed",why:"out-of-root"};if(s.kind==="ok"){let h=mi(s.real);if(h==="file"){let E=Jd(t,s.real,r);return E!==null&&_i(E)?vn:{kind:"unanalyzable",reason:E===null?"a file exists at that path under a name its directory listing did not confirm":`a file exists at that path ("${E}") the analyzer cannot parse`,why:E===null?"probe-refused":"sibling-unparsable"}}if(h!=="dir")return{kind:"unanalyzable",reason:"its target exists but is not a regular file",why:"probe-refused"};let g=Ir(s.real,r);if(g===null)return{kind:"unanalyzable",reason:"its target directory could not be listed",why:"probe-refused"};let S=xi(yi(g.names,"index"),"a directory index");return S.kind==="unanalyzable"?S:g.names.has("package.json")?{kind:"unanalyzable",reason:"its target is a directory whose package.json main did not resolve",why:"probe-refused"}:g.truncated?{kind:"unanalyzable",reason:`its target directory exceeds ${String(vr)} entries and was not fully probed`,why:"probe-refused"}:vn}let d=re.basename(l);if(d===""||d==="."||d==="..")return vn;let u=gi(t,re.dirname(l));if(u.kind==="escaped")return{kind:"unanalyzable",reason:"a symlink carries its target directory outside the scan root, which was not probed",why:"out-of-root"};if(u.kind==="missing")return vn;let p=Ir(u.real,r);if(p===null)return{kind:"unanalyzable",reason:"its target directory could not be listed",why:"probe-refused"};let f=xi(yi(p.names,d),"a sibling file exists");return f.kind==="unanalyzable"?f:p.truncated?{kind:"unanalyzable",reason:`its target directory exceeds ${String(vr)} entries and was not fully probed`,why:"probe-refused"}:vn}function Cr(e,n){let t=je(e),r=re.dirname(n);for(let o=0;o<64;o+=1){let i=re.join(r,"node_modules",...t.split("/"));if(_e(re.join(i,"package.json"))!==null)return i;let a=re.dirname(r);if(a===r)return null;r=a}return null}function Si(e,n,t,r,o){let i;for(let a of _r)for(let l of Nr){let s={...t,noDtsResolution:!0,customConditions:[...l]},d=Qn(e,n,s,r,a,o);if(i===void 0)i=d;else if(i!==d)return null}return i??null}function Ke(e,n,t,r){let o=ye(e);if(o==="relative")return Qn(e,n,t,r,void 0,!0);if(o==="package-root"){let l=Si(e,n,t,r,!0);if(l!==null)return l;let s=Cr(e,n);if(s===null||_e(re.join(s,"package.json"))?.includes('"exports"')===!0)return null;let d=Rr(s);return d===null||Me(d)?null:mn(s,d)?d:null}let i=Si(e,n,t,r,!1);if(i===null)return null;let a=Gd(i,je(e));return a!==null?Xd(e,a):Me(i)?i:ki(i)}function Ri(e){let n=e.trim();return n.startsWith("@/")||n==="~"||n.startsWith("~/")||n.startsWith("#")}function et(e,n,t,r){let o=ye(e);if(o==="relative")return"no-candidate";if(Ri(e))return"alias-unmapped";let i=new Set;for(let g of _r)for(let S of Nr){let E={...t,noDtsResolution:!0,customConditions:[...S]};i.add(Qn(e,n,E,r,g,o==="package-root"))}if(i.size>1)return"divergent-exports";let a=Cr(e,n);if(a===null)return"not-installed";let l=_e(re.join(a,"package.json"));if(l===null)return"unreadable-manifest";let s;try{s=JSON.parse(l)}catch{return"unreadable-manifest"}if(typeof s!="object"||s===null)return"unreadable-manifest";let d=s,u=d.exports!==void 0&&d.exports!==null,p=typeof d.typesVersions=="object"&&d.typesVersions!==null,[f]=i;if(f!=null)return mn(a,f)?!u&&p?"types-versions-remap":Me(f)?"declaration-only":"no-candidate":"out-of-root";let h=Qn(e,n,t,r,void 0,!1);if(h!==null&&Me(h))return!u&&p?"types-versions-remap":"declaration-only";if(o==="package-root"&&!u){let g=Rr(a);if(g!==null&&!mn(a,g))return"out-of-root"}return"no-candidate"}function jn(e,n,t,r){let o=Ke(e,n,t,r);if(o!==null)return[o];let i=ye(e);if(i==="relative")return[];let a=new Set;for(let d of _r)for(let u of Nr){let p={...t,noDtsResolution:!0,customConditions:[...u]};a.add(Qn(e,n,p,r,d,i==="package-root"))}if(a.size<2||a.has(null))return[];let l=Cr(e,n);if(l===null)return[];let s=[];for(let d of a){if(d===null)return[];let u=ki(d);if(Me(u)||!mn(l,u))return[];s.push(u)}return[...new Set(s)].sort()}function Ci(e,n){let t=re.dirname(e);for(let r=0;r<64;r+=1){let o=_e(re.join(t,"package.json"));if(o!==null){try{let a=JSON.parse(o);if(typeof a!="object"||a===null)return!1;let l=a.optionalDependencies;if(typeof l=="object"&&l!==null&&n in l)return!0;let s=a.peerDependenciesMeta;if(typeof s=="object"&&s!==null){let d=s[n];if(typeof d=="object"&&d!==null)return d.optional===!0}}catch{return!1}return!1}let i=re.dirname(t);if(i===t)return!1;t=i}return!1}function Oi(e,n,t){let r=_e(re.join(e,"tsconfig.json"));if(r===null)return()=>null;let o=Rt.parseConfigFileTextToJson(re.join(e,"tsconfig.json"),r);if(o.error!==void 0)return()=>null;let i=o.config?.compilerOptions;if(typeof i!="object"||i===null)return()=>null;let a=i.paths;if(typeof a!="object"||a===null)return()=>null;let l=i.baseUrl,s=typeof l=="string"?re.resolve(e,l):e,d=new Map,u=[];for(let[f,h]of Object.entries(a)){if(!Array.isArray(h))continue;let g=h.filter(E=>typeof E=="string");if(g.length===0)continue;let S=f.indexOf("*");S===-1?d.set(f,g):f.indexOf("*",S+1)===-1&&u.push({prefix:f.slice(0,S),suffix:f.slice(S+1),targets:g})}if(u.sort((f,h)=>h.prefix.length-f.prefix.length),d.size===0&&u.length===0)return()=>null;let p=f=>{let h=d.get(f);if(h!==void 0)return h;for(let g of u){if(f.length<g.prefix.length+g.suffix.length||!f.startsWith(g.prefix)||!f.endsWith(g.suffix))continue;let S=f.slice(g.prefix.length,f.length-g.suffix.length);return g.targets.map(E=>{let w=E.indexOf("*");return w===-1?E:E.slice(0,w)+S+E.slice(w+1)})}return[]};return(f,h)=>{let g=p(f);if(g.length===0||Ke(f,h,n,t)!==null)return null;for(let S of g){let E=re.resolve(s,S),w=re.relative(re.dirname(h),E).split(re.sep).join("/");if(w==="")continue;w.startsWith(".")||(w=`./${w}`);let I=Ke(w,h,n,t);if(I!==null&&mn(e,I))return I}return null}}import{readdirSync as Zd,realpathSync as Qd}from"node:fs";import an from"node:path";import V from"typescript";function nt(e,n){if(V.isIdentifier(e))n.add(e.text);else for(let t of e.elements)V.isBindingElement(t)&&nt(t.name,n)}function Kn(e){let n=new Map,t=new Set,r=s=>{n.set(s,(n.get(s)??0)+1)},o=s=>{let d=De(s);if(V.isIdentifier(d))t.add(d.text);else if(V.isArrayLiteralExpression(d))for(let u of d.elements)o(u);else if(V.isObjectLiteralExpression(d))for(let u of d.properties)V.isShorthandPropertyAssignment(u)?t.add(u.name.text):V.isPropertyAssignment(u)?o(u.initializer):V.isSpreadAssignment(u)&&o(u.expression);else V.isSpreadElement(d)?o(d.expression):V.isBinaryExpression(d)&&d.operatorToken.kind===V.SyntaxKind.EqualsToken&&o(d.left)},i=s=>{let d=new Set;nt(s,d);for(let u of d)r(u)},a=s=>{V.isVariableDeclaration(s)?i(s.name):V.isFunctionDeclaration(s)&&s.name!==void 0||V.isClassDeclaration(s)&&s.name!==void 0?r(s.name.text):V.isParameter(s)?i(s.name):((V.isFunctionExpression(s)||V.isClassExpression(s))&&s.name!==void 0&&V.isIdentifier(s.name)&&!(s.parent!==void 0&&V.isVariableDeclaration(s.parent)&&s.parent.initializer===s&&V.isIdentifier(s.parent.name)&&s.parent.name.text===s.name.text)||V.isImportClause(s)&&s.name!==void 0||V.isNamespaceImport(s)||V.isImportSpecifier(s)||V.isImportEqualsDeclaration(s))&&r(s.name.text),V.isBinaryExpression(s)&&s.operatorToken.kind>=V.SyntaxKind.FirstAssignment&&s.operatorToken.kind<=V.SyntaxKind.LastAssignment?o(s.left):(V.isPrefixUnaryExpression(s)||V.isPostfixUnaryExpression(s))&&(s.operator===V.SyntaxKind.PlusPlusToken||s.operator===V.SyntaxKind.MinusMinusToken)?o(s.operand):(V.isForOfStatement(s)||V.isForInStatement(s))&&!V.isVariableDeclarationList(s.initializer)&&o(s.initializer),V.forEachChild(s,a)};a(e);let l=new Set(t);for(let[s,d]of n)d>1&&l.add(s);return l}function In(e,n,t){let r=Kn(e),o=new Map,i=a=>{V.isVariableDeclaration(a)&&V.isIdentifier(a.name)&&a.initializer!==void 0&&!r.has(a.name.text)&&!o.has(a.name.text)&&o.set(a.name.text,a.initializer),V.forEachChild(a,i)};return i(e),{containingFile:n,taintedNames:r,constBindings:o,resolveParamDirs:t}}var ec=1024,nc=32,tc=new Set(["filter","sort","slice","reverse"]),rc=new Set(["forEach","map","filter","flatMap","find","some","every"]);function De(e){let n=e;for(;V.isParenthesizedExpression(n);)n=n.expression;return n}function Pi(e,n){return V.isPropertyAccessExpression(e)&&V.isIdentifier(e.expression)&&e.expression.text==="path"&&e.name.text===n}function hn(e,n,t,r){if(t>nc)return null;let o=De(e);if(V.isStringLiteralLike(o))return o.text;if(V.isTemplateExpression(o)){let i=o.head.text;for(let a of o.templateSpans){let l=hn(a.expression,n,t+1,r);if(l===null)return null;i+=l+a.literal.text}return i}if(V.isBinaryExpression(o)&&o.operatorToken.kind===V.SyntaxKind.PlusToken){let i=hn(o.left,n,t+1,r);if(i===null)return null;let a=hn(o.right,n,t+1,r);return a===null?null:i+a}if(V.isIdentifier(o)){if(o.text==="__dirname")return an.dirname(n.containingFile);if(o.text==="__filename")return n.containingFile;if(n.taintedNames.has(o.text)||r.has(o.text))return null;let i=n.constBindings.get(o.text);if(i===void 0)return null;r.add(o.text);let a=hn(i,n,t+1,r);return r.delete(o.text),a}if(V.isCallExpression(o)){let i=Pi(o.expression,"join"),a=Pi(o.expression,"resolve");if(!i&&!a)return null;let l=[];for(let d of o.arguments){let u=hn(d,n,t+1,r);if(u===null)return null;l.push(u)}let s=l[0];return s===void 0||a&&!an.isAbsolute(s)?null:a?an.resolve(...l):an.join(...l)}return null}function Ot(e){let n=De(e);if(V.isBinaryExpression(n)&&n.operatorToken.kind===V.SyntaxKind.PlusToken)return[...Ot(n.left),...Ot(n.right)];if(V.isTemplateExpression(n)){let t=[];n.head.text.length>0&&t.push({lit:n.head.text});for(let r of n.templateSpans)t.push({expr:r.expression}),r.literal.text.length>0&&t.push({lit:r.literal.text});return t}return V.isStringLiteralLike(n)?[{lit:n.text}]:[{expr:n}]}function Di(e){let n=e,t=0;for(;t++<4096;){let r=n.parent;if(r===void 0)return null;if(V.isForOfStatement(r)&&r.statement===n){let o=r.initializer;if(V.isVariableDeclarationList(o)&&o.declarations.length===1&&o.declarations[0]!==void 0&&V.isIdentifier(o.declarations[0].name)&&o.declarations[0].name.text===e.text){let i=$i(r.expression);if(i!==null)return i}}if((V.isArrowFunction(n)||V.isFunctionExpression(n))&&V.isCallExpression(r)&&r.arguments.length>0&&r.arguments[0]===n&&V.isPropertyAccessExpression(r.expression)&&rc.has(r.expression.name.text)){let o=n.parameters[0];if(o!==void 0&&V.isIdentifier(o.name)&&o.name.text===e.text){let i=$i(r.expression.expression);if(i!==null)return i}}n=r}return null}function $i(e){let n=De(e),t=0;for(;V.isCallExpression(n)&&t++<16;){let r=n.expression;if(V.isPropertyAccessExpression(r)){let o=r.name.text;if(o==="readdirSync")return n.arguments[0]??null;if(tc.has(o)){n=De(r.expression);continue}return null}return V.isIdentifier(r)&&r.text==="readdirSync"?n.arguments[0]??null:null}return null}function oc(e,n){let t=Ot(e);if(t.length<2)return null;let r=t[t.length-1];if(r===void 0||!("expr"in r)||!V.isIdentifier(r.expr))return null;let o=r.expr;if(n.taintedNames.has(o.text))return null;let i="";for(let d=0;d<t.length-1;d+=1){let u=t[d];if(u===void 0)return null;if("lit"in u)i+=u.lit;else{let p=hn(u.expr,n,0,new Set);if(p===null)return null;i+=p}}let a=Di(o),l=a===null?null:hn(a,n,0,new Set);if(l===null)return null;let s=an.resolve(i);return s!==an.resolve(l)?null:s}function ic(e){if((V.isFunctionDeclaration(e)||V.isFunctionExpression(e))&&e.name!==void 0&&V.isIdentifier(e.name)||V.isMethodDeclaration(e)&&V.isIdentifier(e.name))return e.name.text;let n=e.parent;return n!==void 0&&V.isVariableDeclaration(n)&&V.isIdentifier(n.name)?n.name.text:null}function sc(e,n){for(let t=e.parent;t!==void 0;t=t.parent){if(!V.isFunctionLike(t))continue;let r=-1;for(let i=0;i<t.parameters.length;i+=1){let a=t.parameters[i];if(a!==void 0&&V.isIdentifier(a.name)&&a.name.text===n){r=i;break}}if(r<0)continue;let o=ic(t);return o===null?null:{fnName:o,paramIndex:r}}return null}function tt(e,n){let t=Ot(e);if(t.length!==2)return null;let[r,o]=t;if(r===void 0||!("expr"in r)||!V.isIdentifier(r.expr)||o===void 0||!("expr"in o)||!V.isIdentifier(o.expr))return null;let i=r.expr,a=o.expr;if(n.taintedNames.has(i.text)||n.taintedNames.has(a.text))return null;let l=Di(a);return l===null||!V.isIdentifier(l)||l.text!==i.text?null:sc(i,i.text)}function ac(e,n){if(n.resolveParamDirs===void 0)return null;let t=tt(e,n);return t===null?null:n.resolveParamDirs(n.containingFile,t.fnName,t.paramIndex)}function Pt(e){for(let n=e.parent;n!==void 0;n=n.parent){if(V.isSourceFile(n))return!0;if(!V.isArrowFunction(n)&&V.isFunctionLike(n))return!1}return!0}function Or(e,n){let t=hn(e,n,0,new Set);if(t!==null)return{kind:"const",value:t};let r=oc(e,n);if(r!==null)return{kind:"dir",dir:r};let o=ac(e,n);return o!==null&&o.length>0?{kind:"dirs",dirs:[...o]}:{kind:"opaque"}}function Ti(e,n){let t;try{t=Qd(e)}catch{return null}let r=n.endsWith(an.sep)?n:n+an.sep;return t===n||t.startsWith(r)?t:null}function Li(e,n,t,r,o){let i=Ke(e,n,r,o);return i===null||Me(i)||!Ct(i)?null:Ti(i,t)}function Mi(e,n,t,r,o){let i=Ti(e,t);if(i===null)return[];let a;try{a=Zd(i)}catch{return[]}if(a.length===0||a.length>ec)return[];a.sort();let l=new Set,s=[];for(let d of a){let u=Li(an.join(i,d),n,t,r,o);u!==null&&!l.has(u)&&(l.add(u),s.push(u))}return s}function $t(e,n,t,r,o){let i=Or(e,n);if(i.kind==="const"){if(ye(i.value)==="package-root")return[];let a=Li(i.value,n.containingFile,t,r,o);return a===null?[]:[a]}if(i.kind==="dir")return Mi(i.dir,n.containingFile,t,r,o);if(i.kind==="dirs"){let a=new Set,l=[];for(let s of i.dirs)for(let d of Mi(s,n.containingFile,t,r,o))a.has(d)||(a.add(d),l.push(d));return l}return[]}import lc from"node:path";import ae from"typescript";var dc=32,Mt="\0",Fi=(e,n)=>`${e}${Mt}${n}`,ji=(e,n,t)=>`${e}${Mt}${n}${Mt}${String(t)}`;function cc(e){let n=new Map,t=new Set,r=(o,i)=>{if(t.has(o)){n.delete(o);return}t.add(o),n.set(o,i)};for(let o of e.statements)if(ae.isImportDeclaration(o)&&ae.isStringLiteralLike(o.moduleSpecifier)){let i=o.moduleSpecifier.text,a=o.importClause;if(a===void 0)continue;a.name!==void 0&&r(a.name.text,{kind:"module",specifier:i});let l=a.namedBindings;if(l!==void 0&&ae.isNamespaceImport(l))r(l.name.text,{kind:"module",specifier:i});else if(l!==void 0&&ae.isNamedImports(l))for(let s of l.elements)r(s.name.text,{kind:"named",specifier:i,imported:(s.propertyName??s.name).text})}else if(ae.isImportEqualsDeclaration(o)&&ae.isExternalModuleReference(o.moduleReference)&&ae.isStringLiteralLike(o.moduleReference.expression))r(o.name.text,{kind:"module",specifier:o.moduleReference.expression.text});else if(ae.isFunctionDeclaration(o)&&o.name!==void 0)r(o.name.text,{kind:"local"});else if(ae.isVariableStatement(o))for(let i of o.declarationList.declarations){if(i.initializer===void 0)continue;let a=i.initializer;if(ae.isIdentifier(i.name))ae.isArrowFunction(a)||ae.isFunctionExpression(a)?r(i.name.text,{kind:"local"}):Ki(a)&&r(i.name.text,{kind:"module",specifier:Bi(a)});else if(ae.isObjectBindingPattern(i.name)&&Ki(a)){let l=Bi(a);for(let s of i.name.elements){if(s.dotDotDotToken!==void 0||!ae.isIdentifier(s.name))continue;let d=s.propertyName??s.name;!ae.isIdentifier(d)&&!ae.isStringLiteralLike(d)||r(s.name.text,{kind:"named",specifier:l,imported:d.text})}}}return n}function Ki(e){return ae.isCallExpression(e)&&ae.isIdentifier(e.expression)&&e.expression.text==="require"&&e.arguments.length===1&&e.arguments[0]!==void 0&&ae.isStringLiteralLike(e.arguments[0])}function Bi(e){let n=e.arguments[0];return n!==void 0&&ae.isStringLiteralLike(n)?n.text:"\0"}function uc(e){let n=e.expression;if(ae.isPropertyAccessExpression(n))return n.name.text;if(ae.isIdentifier(n))return n.text}function fc(e,n,t,r,o,i){let a=e.expression,l=s=>{let d=`${s}${Mt}${n}`,u=i.get(d);if(u!==void 0||i.has(d))return u??null;let p=Ke(s,n,r,o),f=p===null?null:lc.resolve(p);return i.set(d,f),f};if(ae.isPropertyAccessExpression(a)&&ae.isIdentifier(a.expression)){let s=t.get(a.expression.text);if(s?.kind==="module"){let d=l(s.specifier);return d===null?null:{moduleReal:d,fnName:a.name.text}}return null}if(ae.isIdentifier(a)){let s=t.get(a.text);if(s?.kind==="named"){let d=l(s.specifier);return d===null?null:{moduleReal:d,fnName:s.imported}}return s?.kind==="local"?{moduleReal:n,fnName:a.text}:null}return null}function zi(e,n,t,r,o=new Map){if(n.length===0)return()=>null;let i=new Map,a=new Set;for(let s of n){let d=Fi(s.definingModuleReal,s.fnName),u=i.get(d);u===void 0&&(u=new Set,i.set(d,u)),u.add(s.paramIndex),a.add(s.fnName)}let l=new Map;for(let s of e){let d=In(s.sf,s.real),u=cc(s.sf),p=f=>{if(ae.isCallExpression(f)){let h=uc(f);if(h!==void 0&&a.has(h)&&Pt(f)){let g=fc(f,s.real,u,t,r,o);if(g!==null){let S=i.get(Fi(g.moduleReal,g.fnName));if(S!==void 0)for(let E of S){let w=f.arguments[E];if(w===void 0)continue;let I=Or(w,d);if(I.kind==="const"){let v=ji(g.moduleReal,g.fnName,E),_=l.get(v);_===void 0&&(_=new Set,l.set(v,_)),_.add(I.value)}}}}}ae.forEachChild(f,p)};p(s.sf)}return(s,d,u)=>{let p=l.get(ji(s,d,u));return p===void 0||p.size===0||p.size>dc?null:[...p].sort()}}var Ne={allowJs:!0,checkJs:!1,noEmit:!0,skipLibCheck:!0,target:b.ScriptTarget.ES2020,module:b.ModuleKind.CommonJS,moduleResolution:b.ModuleResolutionKind.Node10,types:[]},Dt=5e3;function Oe(e,n){let t;try{t=An(n)}catch{t=Re.resolve(n)}let r=e.endsWith(Re.sep)?e:e+Re.sep;return t!==e&&!t.startsWith(r)?null:t===e?"":t.slice(r.length).split(Re.sep).join("/")}function ke(e){let n=e;for(;;)if(b.isParenthesizedExpression(n))n=n.expression;else if(b.isBinaryExpression(n)&&n.operatorToken.kind===b.SyntaxKind.CommaToken)n=n.right;else return n}function ln(e){return b.isPropertyAccessExpression(e)?{receiver:ke(e.expression),name:e.name.text}:b.isElementAccessExpression(e)&&b.isStringLiteralLike(e.argumentExpression)?{receiver:ke(e.expression),name:e.argumentExpression.text}:null}function it(e){let n=ke(e.expression);if(b.isIdentifier(n)&&n.text==="require")return{specifierArg:e.arguments[0]};if(n.kind===b.SyntaxKind.ImportKeyword)return{specifierArg:e.arguments[0]};let t=ln(n);if(t!==null){if(t.name==="require"&&b.isIdentifier(t.receiver)&&t.receiver.text==="module")return{specifierArg:e.arguments[0]};if(b.isIdentifier(t.receiver)&&t.receiver.text==="require"){if(t.name==="call")return{specifierArg:e.arguments[1]};if(t.name==="apply"){let r=e.arguments[1];return{specifierArg:r!==void 0&&b.isArrayLiteralExpression(r)?r.elements[0]:void 0}}}}return null}function Ui(e){let n=[],t=r=>{if(b.isImportDeclaration(r)&&b.isStringLiteralLike(r.moduleSpecifier))n.push({text:r.moduleSpecifier.text,runtime:r.importClause?.isTypeOnly!==!0});else if(b.isImportEqualsDeclaration(r)&&b.isExternalModuleReference(r.moduleReference)&&b.isStringLiteralLike(r.moduleReference.expression))n.push({text:r.moduleReference.expression.text,runtime:!0});else if(b.isExportDeclaration(r)&&r.moduleSpecifier!==void 0&&b.isStringLiteralLike(r.moduleSpecifier))n.push({text:r.moduleSpecifier.text,runtime:r.isTypeOnly!==!0});else if(b.isCallExpression(r)){let o=it(r),i=o?.specifierArg;o!==null&&i!==void 0&&b.isStringLiteralLike(i)&&n.push({text:i.text,runtime:!0})}b.forEachChild(r,t)};return t(e),n}function pc(e,n){let t=n===b.ScriptKind.TSX?"__scriptkind_probe.tsx":n===b.ScriptKind.TS?"__scriptkind_probe.ts":"__scriptkind_probe.js",r=b.createSourceFile(t,e,b.ScriptTarget.ES2020,!0,n),o={allowJs:!0,noLib:!0,noResolve:!0,noEmit:!0},i={getSourceFile:a=>a===t?r:void 0,getDefaultLibFileName:()=>"lib.d.ts",writeFile:()=>{},getCurrentDirectory:()=>"",getCanonicalFileName:a=>a,useCaseSensitiveFileNames:()=>!0,getNewLine:()=>`
|
|
12
|
-
`,fileExists:a=>a===t,readFile:a=>a===t?e:void 0};return
|
|
11
|
+
FROM model_edge WHERE model_package_id = :id ORDER BY id`);return u.map(f=>{let m=dn(f.id)??0;return{packageName:Ae(f.package_name),modelId:Ae(f.evidence_ref),introduced:Ae(f.introduced),fixedBefore:Ee(f.fixed_before),evidenceRef:Ae(f.evidence_ref),edges:p.all({id:m}).map(g=>({kind:Ae(g.kind),anchorExport:Ae(g.anchor_export),anchorContainer:Ee(g.anchor_container),calleePackage:Ae(g.callee_package),calleeContainer:Ee(g.callee_container),calleeExport:Ae(g.callee_export)}))}})},close(){t.close()}}}function er(e){let n=e[0];if(n===void 0)throw new Error("compositeShardReader: at least one shard is required");for(let p of e)if(p.schemaVersion!==n.schemaVersion)throw new Error(`compositeShardReader: shards disagree on schema version (${n.schemaVersion} vs ${p.schemaVersion}); refusing to scan against a mixed schema`);let t=new Map,o=new Map,r=new Map,s=new Map,a=1,l=(p,f,m,g)=>{let y=`${String(m)}:${String(g)}`,b=p.get(y);if(b!==void 0)return b;let x=a;a+=1,p.set(y,x);let I=e[m];if(I===void 0)throw new Error("unreachable: reader index out of range");return f.set(x,{reader:I,id:g}),x},i=e.map(p=>new Set(p.ecosystems?.()??[])),d=p=>{let f=e.map((m,g)=>g).filter(m=>i[m]?.has(p)===!0);return f.length>0?f:e.map((m,g)=>g).filter(m=>e[m]?.ecosystems===void 0)},u=(p,f)=>({...f,id:l(r,s,p,f.id),affectedPackageId:l(t,o,p,f.affectedPackageId)});return{schemaVersion:n.schemaVersion,ecosystems(){let p=new Set;for(let f of i)for(let m of f)p.add(m);return[...p].sort()},advisoriesForPackage(p,f){let m=[];for(let g of d(p)){let y=e[g];if(y!==void 0)for(let b of y.advisoriesForPackage(p,f))m.push({...b,affected:{...b.affected,id:l(t,o,g,b.affected.id)}})}return m},symbolsForAffected(p){let f=o.get(p);if(f===void 0)return[];let m=e.indexOf(f.reader);return f.reader.symbolsForAffected(f.id).map(g=>u(m,g))},aliasesForSymbol(p){let f=s.get(p);if(f===void 0)return[];let m=e.indexOf(f.reader);return f.reader.aliasesForSymbol(f.id).map(g=>({...g,vulnerableSymbolId:l(r,s,m,g.vulnerableSymbolId)}))},allModels(){return e.flatMap(p=>p.allModels?.()??[])},close(){for(let p of e)p.close()}}}var Fn="6";import{realpathSync as kn}from"node:fs";import Xe from"node:path";import{realpathSync as Kn}from"node:fs";import{isBuiltin as hr}from"node:module";import Me from"node:path";import E from"typescript";function nr(e){let n=e.trim().replace(/\\/gu,"/"),t=n.length;for(;t>0&&n.charCodeAt(t-1)===47;)t-=1;return t===n.length?n:n.slice(0,t)}function we(e){let n=nr(e);if(n===""||n.startsWith(".")||n.startsWith("/"))return"relative";if(n.startsWith("@")){let t=n.indexOf("/");return t===-1||n.indexOf("/",t+1)===-1?"package-root":"package-subpath"}return n.includes("/")?"package-subpath":"package-root"}function qe(e){let n=nr(e);if(n.startsWith("@")){let o=n.indexOf("/");if(o===-1)return n;let r=n.indexOf("/",o+1);return r===-1?n:n.slice(0,r)}let t=n.indexOf("/");return t===-1?n:n.slice(0,t)}function Zs(e){let n=nr(e),t=qe(n);return n.length>t.length+1?n.slice(t.length+1):""}import{readFileSync as zc,statSync as tr}from"node:fs";var In=16*1024*1024;function nt(e,n){try{let t=tr(e);return t.isFile()?t.size>n?{kind:"too-large",bytes:t.size}:{kind:"ok",text:zc(e,"utf8")}:{kind:"not-regular"}}catch{return{kind:"not-regular"}}}function Oe(e){let n=nt(e,In);return n.kind==="ok"?n.text:null}function cn(e){try{return tr(e).isFile()}catch{return!1}}function Qs(e){try{let n=tr(e);return n.isFile()?"file":n.isDirectory()?"dir":"other"}catch{return"other"}}import{opendirSync as Wc,realpathSync as sr}from"node:fs";import ae from"node:path";import oo from"typescript";var si=[[".d.mts",[".mjs"]],[".d.cts",[".cjs"]],[".d.ts",[".js",".cjs",".mjs",".jsx"]]];function Be(e){return si.some(([n])=>e.endsWith(n))}function Vc(e){for(let[n,t]of si)if(e.endsWith(n)){let o=e.slice(0,-n.length);return t.map(r=>o+r)}return[]}var qc=[[".tsx",[".js",".jsx",".cjs",".mjs"]],[".cts",[".cjs"]],[".mts",[".mjs"]],[".ts",[".js",".cjs",".mjs",".jsx"]]];function ii(e){if(Be(e))return e;for(let[n,t]of qc)if(e.endsWith(n)){let o=e.slice(0,-n.length);for(let r of t){let s=o+r;if(cn(s))return s}return e}return e}var ir=[oo.ModuleKind.CommonJS,oo.ModuleKind.ESNext],ar=[[],["node-addons"],["module-sync"],["node-addons","module-sync"]];function bt(e,n,t,o,r,s){let a=oo.resolveModuleName(e,n,t,o,void 0,void 0,r).resolvedModule;if(a===void 0)return null;let l=a.resolvedFileName;if(s){for(let i of Vc(l))if(cn(i))return i}return l}var ai=[".js",".jsx",".cjs",".mjs",".ts",".tsx",".cts",".mts"],Gc=[".js",".json",".node"],Hc=["index.js","index.json","index.node"];function ro(e){return!Be(e)&&ai.some(n=>e.endsWith(n))}function li(e){if(cn(e))return e;for(let n of Gc)if(cn(e+n))return e+n;return null}function ei(e){for(let n of Hc){let t=ae.join(e,n);if(cn(t))return t}return null}var di=[".ts",".tsx",".cts",".mts",".jsx"];function Xc(e){for(let n of di)if(cn(e+n))return e+n;return null}function Yc(e){for(let n of di){let t=ae.join(e,"index"+n);if(cn(t))return t}return null}function lr(e){let n=Oe(ae.join(e,"package.json"));if(n!==null)try{let t=JSON.parse(n).main;if(typeof t=="string"&&t.length>0){let o=ae.join(e,t),r=li(o)??ei(o);if(r!==null)return r}}catch{}return ei(e)}function ci(e){return li(e)??lr(e)??Xc(e)??Yc(e)}function ui(e){return ci(e)!==null}function Jc(e,n){let t=e.split(ae.sep),o=n.split("/"),r=null;for(let a=t.length-o.length-1;a>=0;a-=1)if(t[a]==="node_modules"&&o.every((l,i)=>t[a+1+i]===l)){r=t.slice(0,a+1+o.length).join(ae.sep);break}if(r===null||r==="")return null;let s=Oe(ae.join(r,"package.json"));if(s===null)return null;try{let a=JSON.parse(s),l=a.exports,i=typeof l=="string"||Array.isArray(l)||typeof l=="object"&&l!==null;if(a.name!==n||i)return null}catch{return null}try{return sr(r)}catch{return null}}function Zc(e,n){let t=ci(ae.join(e,n));if(t===null)return null;let o;try{o=sr(t)}catch{return null}let r=e.endsWith(ae.sep)?e:e+ae.sep;return o!==e&&!o.startsWith(r)||Be(o)||!ai.some(s=>o.endsWith(s))?null:o}function Qc(e,n){let t=Zs(e);return t===""||t.includes("\0")||t.split("/").some(o=>o===""||o==="."||o===".."||o==="node_modules")?null:Zc(n,t)}var jn={kind:"nothing-loads"},or=8192;function rr(e,n){let t=n.get(e);if(t!==void 0)return t;let o,r=null;try{r=Wc(e);let s=new Set,a=!1;for(;;){let l=r.readSync();if(l===null)break;if(s.size>=or){a=!0;break}s.add(l.name)}o={names:s,truncated:a}}catch{o=null}finally{try{r?.closeSync()}catch{}}return n.set(e,o),o}var eu=[".json",".css",".scss",".sass",".less",".styl",".svg",".png",".jpg",".jpeg",".gif",".webp",".avif",".ico",".bmp",".woff",".woff2",".ttf",".otf",".eot",".mp3",".mp4",".webm",".txt"];function fi(e){return eu.some(n=>e.length>n.length&&e.endsWith(n))}function An(e,n){let t=e.endsWith(ae.sep)?e:e+ae.sep;return n===e||n.startsWith(t)}function ni(e,n){let t;try{t=sr(n)}catch{return{kind:"missing"}}return An(e,t)?{kind:"ok",real:t}:{kind:"escaped"}}function ti(e,n){let t=(n+".").toLowerCase(),o=[];for(let r of e){let s=r.toLowerCase();s.length>t.length&&s.startsWith(t)&&o.push(r)}return o}function nu(e,n,t){let o=ae.dirname(n);if(!An(e,o))return null;let r=rr(o,t);if(r===null)return null;let s=ae.basename(n);return r.names.has(s)?s:null}function oi(e,n){let t=e.filter(r=>!fi(r));if(t.length===0)return jn;let o=[...t].sort()[0]??"";return{kind:"unanalyzable",reason:`${n} ("${o}") the analyzer cannot parse`,why:"sibling-unparsable"}}function pi(e,n,t,o){let r=e,s=r.indexOf("?");s!==-1&&(r=r.slice(0,s));let a=r.indexOf("#");if(a!==-1&&(r=r.slice(0,a)),r===""||r.includes("\0"))return jn;let l=ae.resolve(ae.dirname(n),r);if(!An(t,l))return{kind:"unanalyzable",reason:"its target is outside the scan root and was not probed",why:"out-of-root"};let i=ni(t,l);if(i.kind==="escaped")return{kind:"unanalyzable",reason:"a symlink carries its target outside the scan root, which was not probed",why:"out-of-root"};if(i.kind==="ok"){let m=Qs(i.real);if(m==="file"){let b=nu(t,i.real,o);return b!==null&&fi(b)?jn:{kind:"unanalyzable",reason:b===null?"a file exists at that path under a name its directory listing did not confirm":`a file exists at that path ("${b}") the analyzer cannot parse`,why:b===null?"probe-refused":"sibling-unparsable"}}if(m!=="dir")return{kind:"unanalyzable",reason:"its target exists but is not a regular file",why:"probe-refused"};let g=rr(i.real,o);if(g===null)return{kind:"unanalyzable",reason:"its target directory could not be listed",why:"probe-refused"};let y=oi(ti(g.names,"index"),"a directory index");return y.kind==="unanalyzable"?y:g.names.has("package.json")?{kind:"unanalyzable",reason:"its target is a directory whose package.json main did not resolve",why:"probe-refused"}:g.truncated?{kind:"unanalyzable",reason:`its target directory exceeds ${String(or)} entries and was not fully probed`,why:"probe-refused"}:jn}let d=ae.basename(l);if(d===""||d==="."||d==="..")return jn;let u=ni(t,ae.dirname(l));if(u.kind==="escaped")return{kind:"unanalyzable",reason:"a symlink carries its target directory outside the scan root, which was not probed",why:"out-of-root"};if(u.kind==="missing")return jn;let p=rr(u.real,o);if(p===null)return{kind:"unanalyzable",reason:"its target directory could not be listed",why:"probe-refused"};let f=oi(ti(p.names,d),"a sibling file exists");return f.kind==="unanalyzable"?f:p.truncated?{kind:"unanalyzable",reason:`its target directory exceeds ${String(or)} entries and was not fully probed`,why:"probe-refused"}:jn}function dr(e,n){let t=qe(e),o=ae.dirname(n);for(let r=0;r<64;r+=1){let s=ae.join(o,"node_modules",...t.split("/"));if(Oe(ae.join(s,"package.json"))!==null)return s;let a=ae.dirname(o);if(a===o)return null;o=a}return null}function ri(e,n,t,o,r){let s;for(let a of ir)for(let l of ar){let i={...t,noDtsResolution:!0,customConditions:[...l]},d=bt(e,n,i,o,a,r);if(s===void 0)s=d;else if(s!==d)return null}return s??null}function Ge(e,n,t,o){let r=we(e);if(r==="relative")return bt(e,n,t,o,void 0,!0);if(r==="package-root"){let l=ri(e,n,t,o,!0);if(l!==null)return l;let i=dr(e,n);if(i===null||Oe(ae.join(i,"package.json"))?.includes('"exports"')===!0)return null;let d=lr(i);return d===null||Be(d)?null:An(i,d)?d:null}let s=ri(e,n,t,o,!1);if(s===null)return null;let a=Jc(s,qe(e));return a!==null?Qc(e,a):Be(s)?s:ii(s)}function mi(e){let n=e.trim();return n.startsWith("@/")||n==="~"||n.startsWith("~/")||n.startsWith("#")}function kt(e,n,t,o){let r=we(e);if(r==="relative")return"no-candidate";if(mi(e))return"alias-unmapped";let s=new Set;for(let g of ir)for(let y of ar){let b={...t,noDtsResolution:!0,customConditions:[...y]};s.add(bt(e,n,b,o,g,r==="package-root"))}if(s.size>1)return"divergent-exports";let a=dr(e,n);if(a===null)return"not-installed";let l=Oe(ae.join(a,"package.json"));if(l===null)return"unreadable-manifest";let i;try{i=JSON.parse(l)}catch{return"unreadable-manifest"}if(typeof i!="object"||i===null)return"unreadable-manifest";let d=i,u=d.exports!==void 0&&d.exports!==null,p=typeof d.typesVersions=="object"&&d.typesVersions!==null,[f]=s;if(f!=null)return An(a,f)?!u&&p?"types-versions-remap":Be(f)?"declaration-only":"no-candidate":"out-of-root";let m=bt(e,n,t,o,void 0,!1);if(m!==null&&Be(m))return!u&&p?"types-versions-remap":"declaration-only";if(r==="package-root"&&!u){let g=lr(a);if(g!==null&&!An(a,g))return"out-of-root"}return"no-candidate"}function tt(e,n,t,o){let r=Ge(e,n,t,o);if(r!==null)return[r];let s=we(e);if(s==="relative")return[];let a=new Set;for(let d of ir)for(let u of ar){let p={...t,noDtsResolution:!0,customConditions:[...u]};a.add(bt(e,n,p,o,d,s==="package-root"))}if(a.size<2||a.has(null))return[];let l=dr(e,n);if(l===null)return[];let i=[];for(let d of a){if(d===null)return[];let u=ii(d);if(Be(u)||!An(l,u))return[];i.push(u)}return[...new Set(i)].sort()}function hi(e,n){let t=ae.dirname(e);for(let o=0;o<64;o+=1){let r=Oe(ae.join(t,"package.json"));if(r!==null){try{let a=JSON.parse(r);if(typeof a!="object"||a===null)return!1;let l=a.optionalDependencies;if(typeof l=="object"&&l!==null&&n in l)return!0;let i=a.peerDependenciesMeta;if(typeof i=="object"&&i!==null){let d=i[n];if(typeof d=="object"&&d!==null)return d.optional===!0}}catch{return!1}return!1}let s=ae.dirname(t);if(s===t)return!1;t=s}return!1}function gi(e,n,t){let o=Oe(ae.join(e,"tsconfig.json"));if(o===null)return()=>null;let r=oo.parseConfigFileTextToJson(ae.join(e,"tsconfig.json"),o);if(r.error!==void 0)return()=>null;let s=r.config?.compilerOptions;if(typeof s!="object"||s===null)return()=>null;let a=s.paths;if(typeof a!="object"||a===null)return()=>null;let l=s.baseUrl,i=typeof l=="string"?ae.resolve(e,l):e,d=new Map,u=[];for(let[f,m]of Object.entries(a)){if(!Array.isArray(m))continue;let g=m.filter(b=>typeof b=="string");if(g.length===0)continue;let y=f.indexOf("*");y===-1?d.set(f,g):f.indexOf("*",y+1)===-1&&u.push({prefix:f.slice(0,y),suffix:f.slice(y+1),targets:g})}if(u.sort((f,m)=>m.prefix.length-f.prefix.length),d.size===0&&u.length===0)return()=>null;let p=f=>{let m=d.get(f);if(m!==void 0)return m;for(let g of u){if(f.length<g.prefix.length+g.suffix.length||!f.startsWith(g.prefix)||!f.endsWith(g.suffix))continue;let y=f.slice(g.prefix.length,f.length-g.suffix.length);return g.targets.map(b=>{let x=b.indexOf("*");return x===-1?b:b.slice(0,x)+y+b.slice(x+1)})}return[]};return(f,m)=>{let g=p(f);if(g.length===0||Ge(f,m,n,t)!==null)return null;for(let y of g){let b=ae.resolve(i,y),x=ae.relative(ae.dirname(m),b).split(ae.sep).join("/");if(x==="")continue;x.startsWith(".")||(x=`./${x}`);let I=Ge(x,m,n,t);if(I!==null&&An(e,I))return I}return null}}import{readdirSync as tu,realpathSync as ou}from"node:fs";import Sn from"node:path";import V from"typescript";function Et(e,n){if(V.isIdentifier(e))n.add(e.text);else for(let t of e.elements)V.isBindingElement(t)&&Et(t.name,n)}function ot(e){let n=new Map,t=new Set,o=i=>{n.set(i,(n.get(i)??0)+1)},r=i=>{let d=Ke(i);if(V.isIdentifier(d))t.add(d.text);else if(V.isArrayLiteralExpression(d))for(let u of d.elements)r(u);else if(V.isObjectLiteralExpression(d))for(let u of d.properties)V.isShorthandPropertyAssignment(u)?t.add(u.name.text):V.isPropertyAssignment(u)?r(u.initializer):V.isSpreadAssignment(u)&&r(u.expression);else V.isSpreadElement(d)?r(d.expression):V.isBinaryExpression(d)&&d.operatorToken.kind===V.SyntaxKind.EqualsToken&&r(d.left)},s=i=>{let d=new Set;Et(i,d);for(let u of d)o(u)},a=i=>{V.isVariableDeclaration(i)?s(i.name):V.isFunctionDeclaration(i)&&i.name!==void 0||V.isClassDeclaration(i)&&i.name!==void 0?o(i.name.text):V.isParameter(i)?s(i.name):((V.isFunctionExpression(i)||V.isClassExpression(i))&&i.name!==void 0&&V.isIdentifier(i.name)&&!(i.parent!==void 0&&V.isVariableDeclaration(i.parent)&&i.parent.initializer===i&&V.isIdentifier(i.parent.name)&&i.parent.name.text===i.name.text)||V.isImportClause(i)&&i.name!==void 0||V.isNamespaceImport(i)||V.isImportSpecifier(i)||V.isImportEqualsDeclaration(i))&&o(i.name.text),V.isBinaryExpression(i)&&i.operatorToken.kind>=V.SyntaxKind.FirstAssignment&&i.operatorToken.kind<=V.SyntaxKind.LastAssignment?r(i.left):(V.isPrefixUnaryExpression(i)||V.isPostfixUnaryExpression(i))&&(i.operator===V.SyntaxKind.PlusPlusToken||i.operator===V.SyntaxKind.MinusMinusToken)?r(i.operand):(V.isForOfStatement(i)||V.isForInStatement(i))&&!V.isVariableDeclarationList(i.initializer)&&r(i.initializer),V.forEachChild(i,a)};a(e);let l=new Set(t);for(let[i,d]of n)d>1&&l.add(i);return l}function Bn(e,n,t){let o=ot(e),r=new Map,s=a=>{V.isVariableDeclaration(a)&&V.isIdentifier(a.name)&&a.initializer!==void 0&&!o.has(a.name.text)&&!r.has(a.name.text)&&r.set(a.name.text,a.initializer),V.forEachChild(a,s)};return s(e),{containingFile:n,taintedNames:o,constBindings:r,resolveParamDirs:t}}var ru=1024,su=32,iu=new Set(["filter","sort","slice","reverse"]),au=new Set(["forEach","map","filter","flatMap","find","some","every"]);function Ke(e){let n=e;for(;V.isParenthesizedExpression(n);)n=n.expression;return n}function yi(e,n){return V.isPropertyAccessExpression(e)&&V.isIdentifier(e.expression)&&e.expression.text==="path"&&e.name.text===n}function _n(e,n,t,o){if(t>su)return null;let r=Ke(e);if(V.isStringLiteralLike(r))return r.text;if(V.isTemplateExpression(r)){let s=r.head.text;for(let a of r.templateSpans){let l=_n(a.expression,n,t+1,o);if(l===null)return null;s+=l+a.literal.text}return s}if(V.isBinaryExpression(r)&&r.operatorToken.kind===V.SyntaxKind.PlusToken){let s=_n(r.left,n,t+1,o);if(s===null)return null;let a=_n(r.right,n,t+1,o);return a===null?null:s+a}if(V.isIdentifier(r)){if(r.text==="__dirname")return Sn.dirname(n.containingFile);if(r.text==="__filename")return n.containingFile;if(n.taintedNames.has(r.text)||o.has(r.text))return null;let s=n.constBindings.get(r.text);if(s===void 0)return null;o.add(r.text);let a=_n(s,n,t+1,o);return o.delete(r.text),a}if(V.isCallExpression(r)){let s=yi(r.expression,"join"),a=yi(r.expression,"resolve");if(!s&&!a)return null;let l=[];for(let d of r.arguments){let u=_n(d,n,t+1,o);if(u===null)return null;l.push(u)}let i=l[0];return i===void 0||a&&!Sn.isAbsolute(i)?null:a?Sn.resolve(...l):Sn.join(...l)}return null}function so(e){let n=Ke(e);if(V.isBinaryExpression(n)&&n.operatorToken.kind===V.SyntaxKind.PlusToken)return[...so(n.left),...so(n.right)];if(V.isTemplateExpression(n)){let t=[];n.head.text.length>0&&t.push({lit:n.head.text});for(let o of n.templateSpans)t.push({expr:o.expression}),o.literal.text.length>0&&t.push({lit:o.literal.text});return t}return V.isStringLiteralLike(n)?[{lit:n.text}]:[{expr:n}]}function bi(e){let n=e,t=0;for(;t++<4096;){let o=n.parent;if(o===void 0)return null;if(V.isForOfStatement(o)&&o.statement===n){let r=o.initializer;if(V.isVariableDeclarationList(r)&&r.declarations.length===1&&r.declarations[0]!==void 0&&V.isIdentifier(r.declarations[0].name)&&r.declarations[0].name.text===e.text){let s=xi(o.expression);if(s!==null)return s}}if((V.isArrowFunction(n)||V.isFunctionExpression(n))&&V.isCallExpression(o)&&o.arguments.length>0&&o.arguments[0]===n&&V.isPropertyAccessExpression(o.expression)&&au.has(o.expression.name.text)){let r=n.parameters[0];if(r!==void 0&&V.isIdentifier(r.name)&&r.name.text===e.text){let s=xi(o.expression.expression);if(s!==null)return s}}n=o}return null}function xi(e){let n=Ke(e),t=0;for(;V.isCallExpression(n)&&t++<16;){let o=n.expression;if(V.isPropertyAccessExpression(o)){let r=o.name.text;if(r==="readdirSync")return n.arguments[0]??null;if(iu.has(r)){n=Ke(o.expression);continue}return null}return V.isIdentifier(o)&&o.text==="readdirSync"?n.arguments[0]??null:null}return null}function lu(e,n){let t=so(e);if(t.length<2)return null;let o=t[t.length-1];if(o===void 0||!("expr"in o)||!V.isIdentifier(o.expr))return null;let r=o.expr;if(n.taintedNames.has(r.text))return null;let s="";for(let d=0;d<t.length-1;d+=1){let u=t[d];if(u===void 0)return null;if("lit"in u)s+=u.lit;else{let p=_n(u.expr,n,0,new Set);if(p===null)return null;s+=p}}let a=bi(r),l=a===null?null:_n(a,n,0,new Set);if(l===null)return null;let i=Sn.resolve(s);return i!==Sn.resolve(l)?null:i}function du(e){if((V.isFunctionDeclaration(e)||V.isFunctionExpression(e))&&e.name!==void 0&&V.isIdentifier(e.name)||V.isMethodDeclaration(e)&&V.isIdentifier(e.name))return e.name.text;let n=e.parent;return n!==void 0&&V.isVariableDeclaration(n)&&V.isIdentifier(n.name)?n.name.text:null}function cu(e,n){for(let t=e.parent;t!==void 0;t=t.parent){if(!V.isFunctionLike(t))continue;let o=-1;for(let s=0;s<t.parameters.length;s+=1){let a=t.parameters[s];if(a!==void 0&&V.isIdentifier(a.name)&&a.name.text===n){o=s;break}}if(o<0)continue;let r=du(t);return r===null?null:{fnName:r,paramIndex:o}}return null}function wt(e,n){let t=so(e);if(t.length!==2)return null;let[o,r]=t;if(o===void 0||!("expr"in o)||!V.isIdentifier(o.expr)||r===void 0||!("expr"in r)||!V.isIdentifier(r.expr))return null;let s=o.expr,a=r.expr;if(n.taintedNames.has(s.text)||n.taintedNames.has(a.text))return null;let l=bi(a);return l===null||!V.isIdentifier(l)||l.text!==s.text?null:cu(s,s.text)}function uu(e,n){if(n.resolveParamDirs===void 0)return null;let t=wt(e,n);return t===null?null:n.resolveParamDirs(n.containingFile,t.fnName,t.paramIndex)}function io(e){for(let n=e.parent;n!==void 0;n=n.parent){if(V.isSourceFile(n))return!0;if(!V.isArrowFunction(n)&&V.isFunctionLike(n))return!1}return!0}function cr(e,n){let t=_n(e,n,0,new Set);if(t!==null)return{kind:"const",value:t};let o=lu(e,n);if(o!==null)return{kind:"dir",dir:o};let r=uu(e,n);return r!==null&&r.length>0?{kind:"dirs",dirs:[...r]}:{kind:"opaque"}}function ki(e,n){let t;try{t=ou(e)}catch{return null}let o=n.endsWith(Sn.sep)?n:n+Sn.sep;return t===n||t.startsWith(o)?t:null}function Ei(e,n,t,o,r){let s=Ge(e,n,o,r);return s===null||Be(s)||!ro(s)?null:ki(s,t)}function Si(e,n,t,o,r){let s=ki(e,t);if(s===null)return[];let a;try{a=tu(s)}catch{return[]}if(a.length===0||a.length>ru)return[];a.sort();let l=new Set,i=[];for(let d of a){let u=Ei(Sn.join(s,d),n,t,o,r);u!==null&&!l.has(u)&&(l.add(u),i.push(u))}return i}function ao(e,n,t,o,r){let s=cr(e,n);if(s.kind==="const"){if(we(s.value)==="package-root")return[];let a=Ei(s.value,n.containingFile,t,o,r);return a===null?[]:[a]}if(s.kind==="dir")return Si(s.dir,n.containingFile,t,o,r);if(s.kind==="dirs"){let a=new Set,l=[];for(let i of s.dirs)for(let d of Si(i,n.containingFile,t,o,r))a.has(d)||(a.add(d),l.push(d));return l}return[]}import fu from"node:path";import me from"typescript";var pu=32,lo="\0",wi=(e,n)=>`${e}${lo}${n}`,vi=(e,n,t)=>`${e}${lo}${n}${lo}${String(t)}`;function mu(e){let n=new Map,t=new Set,o=(r,s)=>{if(t.has(r)){n.delete(r);return}t.add(r),n.set(r,s)};for(let r of e.statements)if(me.isImportDeclaration(r)&&me.isStringLiteralLike(r.moduleSpecifier)){let s=r.moduleSpecifier.text,a=r.importClause;if(a===void 0)continue;a.name!==void 0&&o(a.name.text,{kind:"module",specifier:s});let l=a.namedBindings;if(l!==void 0&&me.isNamespaceImport(l))o(l.name.text,{kind:"module",specifier:s});else if(l!==void 0&&me.isNamedImports(l))for(let i of l.elements)o(i.name.text,{kind:"named",specifier:s,imported:(i.propertyName??i.name).text})}else if(me.isImportEqualsDeclaration(r)&&me.isExternalModuleReference(r.moduleReference)&&me.isStringLiteralLike(r.moduleReference.expression))o(r.name.text,{kind:"module",specifier:r.moduleReference.expression.text});else if(me.isFunctionDeclaration(r)&&r.name!==void 0)o(r.name.text,{kind:"local"});else if(me.isVariableStatement(r))for(let s of r.declarationList.declarations){if(s.initializer===void 0)continue;let a=s.initializer;if(me.isIdentifier(s.name))me.isArrowFunction(a)||me.isFunctionExpression(a)?o(s.name.text,{kind:"local"}):Ii(a)&&o(s.name.text,{kind:"module",specifier:Ai(a)});else if(me.isObjectBindingPattern(s.name)&&Ii(a)){let l=Ai(a);for(let i of s.name.elements){if(i.dotDotDotToken!==void 0||!me.isIdentifier(i.name))continue;let d=i.propertyName??i.name;!me.isIdentifier(d)&&!me.isStringLiteralLike(d)||o(i.name.text,{kind:"named",specifier:l,imported:d.text})}}}return n}function Ii(e){return me.isCallExpression(e)&&me.isIdentifier(e.expression)&&e.expression.text==="require"&&e.arguments.length===1&&e.arguments[0]!==void 0&&me.isStringLiteralLike(e.arguments[0])}function Ai(e){let n=e.arguments[0];return n!==void 0&&me.isStringLiteralLike(n)?n.text:"\0"}function hu(e){let n=e.expression;if(me.isPropertyAccessExpression(n))return n.name.text;if(me.isIdentifier(n))return n.text}function gu(e,n,t,o,r,s){let a=e.expression,l=i=>{let d=`${i}${lo}${n}`,u=s.get(d);if(u!==void 0||s.has(d))return u??null;let p=Ge(i,n,o,r),f=p===null?null:fu.resolve(p);return s.set(d,f),f};if(me.isPropertyAccessExpression(a)&&me.isIdentifier(a.expression)){let i=t.get(a.expression.text);if(i?.kind==="module"){let d=l(i.specifier);return d===null?null:{moduleReal:d,fnName:a.name.text}}return null}if(me.isIdentifier(a)){let i=t.get(a.text);if(i?.kind==="named"){let d=l(i.specifier);return d===null?null:{moduleReal:d,fnName:i.imported}}return i?.kind==="local"?{moduleReal:n,fnName:a.text}:null}return null}function _i(e,n,t,o,r=new Map){if(n.length===0)return()=>null;let s=new Map,a=new Set;for(let i of n){let d=wi(i.definingModuleReal,i.fnName),u=s.get(d);u===void 0&&(u=new Set,s.set(d,u)),u.add(i.paramIndex),a.add(i.fnName)}let l=new Map;for(let i of e){let d=Bn(i.sf,i.real),u=mu(i.sf),p=f=>{if(me.isCallExpression(f)){let m=hu(f);if(m!==void 0&&a.has(m)&&io(f)){let g=gu(f,i.real,u,t,o,r);if(g!==null){let y=s.get(wi(g.moduleReal,g.fnName));if(y!==void 0)for(let b of y){let x=f.arguments[b];if(x===void 0)continue;let I=cr(x,d);if(I.kind==="const"){let w=vi(g.moduleReal,g.fnName,b),A=l.get(w);A===void 0&&(A=new Set,l.set(w,A)),A.add(I.value)}}}}}me.forEachChild(f,p)};p(i.sf)}return(i,d,u)=>{let p=l.get(vi(i,d,u));return p===void 0||p.size===0||p.size>pu?null:[...p].sort()}}var Ce={allowJs:!0,checkJs:!1,noEmit:!0,skipLibCheck:!0,target:E.ScriptTarget.ES2020,module:E.ModuleKind.CommonJS,moduleResolution:E.ModuleResolutionKind.Node10,types:[]},co=5e3;function Le(e,n){let t;try{t=Kn(n)}catch{t=Me.resolve(n)}let o=e.endsWith(Me.sep)?e:e+Me.sep;return t!==e&&!t.startsWith(o)?null:t===e?"":t.slice(o.length).split(Me.sep).join("/")}function _e(e){let n=e;for(;;)if(E.isParenthesizedExpression(n))n=n.expression;else if(E.isBinaryExpression(n)&&n.operatorToken.kind===E.SyntaxKind.CommaToken)n=n.right;else return n}function bn(e){return E.isPropertyAccessExpression(e)?{receiver:_e(e.expression),name:e.name.text}:E.isElementAccessExpression(e)&&E.isStringLiteralLike(e.argumentExpression)?{receiver:_e(e.expression),name:e.argumentExpression.text}:null}function At(e){let n=_e(e.expression);if(E.isIdentifier(n)&&n.text==="require")return{specifierArg:e.arguments[0]};if(n.kind===E.SyntaxKind.ImportKeyword)return{specifierArg:e.arguments[0]};let t=bn(n);if(t!==null){if(t.name==="require"&&E.isIdentifier(t.receiver)&&t.receiver.text==="module")return{specifierArg:e.arguments[0]};if(E.isIdentifier(t.receiver)&&t.receiver.text==="require"){if(t.name==="call")return{specifierArg:e.arguments[1]};if(t.name==="apply"){let o=e.arguments[1];return{specifierArg:o!==void 0&&E.isArrayLiteralExpression(o)?o.elements[0]:void 0}}}}return null}function Ni(e){let n=[],t=o=>{if(E.isImportDeclaration(o)&&E.isStringLiteralLike(o.moduleSpecifier))n.push({text:o.moduleSpecifier.text,runtime:o.importClause?.isTypeOnly!==!0});else if(E.isImportEqualsDeclaration(o)&&E.isExternalModuleReference(o.moduleReference)&&E.isStringLiteralLike(o.moduleReference.expression))n.push({text:o.moduleReference.expression.text,runtime:!0});else if(E.isExportDeclaration(o)&&o.moduleSpecifier!==void 0&&E.isStringLiteralLike(o.moduleSpecifier))n.push({text:o.moduleSpecifier.text,runtime:o.isTypeOnly!==!0});else if(E.isCallExpression(o)){let r=At(o),s=r?.specifierArg;r!==null&&s!==void 0&&E.isStringLiteralLike(s)&&n.push({text:s.text,runtime:!0})}E.forEachChild(o,t)};return t(e),n}function yu(e,n){let t=n===E.ScriptKind.TSX?"__scriptkind_probe.tsx":n===E.ScriptKind.TS?"__scriptkind_probe.ts":"__scriptkind_probe.js",o=E.createSourceFile(t,e,E.ScriptTarget.ES2020,!0,n),r={allowJs:!0,noLib:!0,noResolve:!0,noEmit:!0},s={getSourceFile:a=>a===t?o:void 0,getDefaultLibFileName:()=>"lib.d.ts",writeFile:()=>{},getCurrentDirectory:()=>"",getCanonicalFileName:a=>a,useCaseSensitiveFileNames:()=>!0,getNewLine:()=>`
|
|
12
|
+
`,fileExists:a=>a===t,readFile:a=>a===t?e:void 0};return E.createProgram({rootNames:[t],options:r,host:s}).getSyntacticDiagnostics(o).length}function gr(e){return e.endsWith(".js")||e.endsWith(".jsx")}function Ri(e){let n=0,t=o=>{(E.isCallExpression(o)||E.isNewExpression(o)||E.isTaggedTemplateExpression(o))&&(n+=1),E.forEachChild(o,t)};return t(e),n}function Oi(e,n){let t=Ni(E.createSourceFile(e,n,E.ScriptTarget.ES2020,!0));if(!gr(e)||!n.includes("<")||!n.includes("require"))return t;let o=E.createSourceFile(e,n,E.ScriptTarget.ES2020,!0,E.ScriptKind.TSX),r=new Set(t.map(s=>`${s.runtime?"R":"T"}:${s.text}`));for(let s of Ni(o)){let a=`${s.runtime?"R":"T"}:${s.text}`;r.has(a)||(r.add(a),t.push(s))}return t}function Pi(e,n,t,o,r){if(!n.includes("require")&&!n.includes("import("))return[];let s=E.createSourceFile(e,n,E.ScriptTarget.ES2020,!0),a=Bn(s,e,r),l=[],i=new Set;return Ci(s,d=>{for(let u of ao(d,a,t,Ce,o))i.has(u)||(i.add(u),l.push(u))}),l}function Ci(e,n){let t=o=>{if(E.isCallExpression(o)){let r=At(o),s=r?.specifierArg;r!==null&&s!==void 0&&!E.isStringLiteralLike(s)&&n(s)}E.forEachChild(o,t)};t(e)}function xu(e){let n=[];for(let t of e){let o=Bn(t.sf,t.real);Ci(t.sf,r=>{let s=wt(r,o);s!==null&&n.push({definingModuleReal:t.real,fnName:s.fnName,paramIndex:s.paramIndex})})}return n}var Su=4,ur=co,fr=new Set(["eval","Function","createRequire"]),bu=new Set(["require","eval","Function","createRequire"]),po=new Set(["module","Module","require","process","global","globalThis"]),mo=new Set(["_load","require","createRequire","eval","getBuiltinModule","dlopen","binding","_linkedBinding","_compile"]);function ku(e){return e===E.SyntaxKind.LessThanToken||e===E.SyntaxKind.GreaterThanToken||e===E.SyntaxKind.LessThanEqualsToken||e===E.SyntaxKind.GreaterThanEqualsToken||e===E.SyntaxKind.EqualsEqualsToken||e===E.SyntaxKind.EqualsEqualsEqualsToken||e===E.SyntaxKind.ExclamationEqualsToken||e===E.SyntaxKind.ExclamationEqualsEqualsToken||e===E.SyntaxKind.InstanceOfKeyword||e===E.SyntaxKind.InKeyword}function Eu(e){let n=e.parent;return(E.isParameter(n)||E.isVariableDeclaration(n)||E.isBindingElement(n)||E.isFunctionDeclaration(n)||E.isFunctionExpression(n)||E.isClassDeclaration(n)||E.isClassExpression(n)||E.isPropertyAssignment(n)||E.isPropertyDeclaration(n)||E.isMethodDeclaration(n))&&n.name===e?!0:E.isPropertyAccessExpression(n)&&n.name===e}function wu(e,n){return E.isCallExpression(n)&&n.expression===e||(E.isPropertyAccessExpression(n)||E.isElementAccessExpression(n))&&n.expression===e||E.isTypeOfExpression(n)||E.isVoidExpression(n)||E.isDeleteExpression(n)||E.isPrefixUnaryExpression(n)||E.isPostfixUnaryExpression(n)?!0:E.isBinaryExpression(n)&&ku(n.operatorToken.kind)}function Mi(e){let n=e,t=e.parent;for(;;)if(E.isParenthesizedExpression(t))n=t,t=t.parent;else if(E.isBinaryExpression(t)&&t.operatorToken.kind===E.SyntaxKind.CommaToken&&t.right===n)n=t,t=t.parent;else break;return!wu(n,t)}function vu(e){return Eu(e)?!1:Mi(e)}function Ti(e){let n=bn(e);if(n!==null&&mo.has(n.name))return!0;if(E.isElementAccessExpression(e)&&!E.isStringLiteralLike(e.argumentExpression)){let t=_e(e.expression);if(E.isIdentifier(t)&&po.has(t.text))return!0}return!1}function vt(e){let n=bn(e);if(n===null||n.name!=="constructor")return!1;let t=bn(n.receiver);return t!==null&&t.name==="constructor"}function Di(e){if(!E.isCallExpression(e))return!1;let n=_e(e.expression);if(!E.isIdentifier(n)||n.text!=="require")return!1;let t=e.arguments[0];return t!==void 0&&E.isStringLiteralLike(t)&&t.text==="module"}var Iu={roots:new Map,nodes:new Set,saturated:!1};function Li(e){return E.isSourceFile(e)||E.isFunctionDeclaration(e)||E.isFunctionExpression(e)||E.isArrowFunction(e)||E.isMethodDeclaration(e)||E.isConstructorDeclaration(e)||E.isGetAccessorDeclaration(e)||E.isSetAccessorDeclaration(e)||E.isClassStaticBlockDeclaration(e)||E.isModuleDeclaration(e)}function Fi(e,n){let t=e.parent;for(;t!==void 0;){if(Li(t))return t;t=t.parent}return n}function Au(e){let n=new Set;if(E.isFunctionLike(e))for(let o of e.parameters)for(let r of It(o.name))n.add(r);let t=[e];for(;t.length>0;){let o=t.pop();if(o===void 0)break;if(!(o!==e&&Li(o))){if(E.isVariableDeclaration(o)&&E.isVariableDeclarationList(o.parent)&&!((o.parent.flags&E.NodeFlags.BlockScoped)!==0))for(let s of It(o.name))n.add(s);E.forEachChild(o,r=>{t.push(r)})}}return n}function _u(e,n,t){let o=Fi(e,n);if(E.isSourceFile(o))return n;let r=t.get(o);return r===void 0&&(r=Au(o),t.set(o,r)),r.has(e.text)?o:n}function uo(e,n){let t=e.roots.get(n.text);if(t===void 0)return!1;let o=n;for(;;){if(t.has(o))return!0;let r=o.parent;if(r===void 0)return!E.isSourceFile(o);o=r}}var Nu=12,Ru=8;function fo(e,n){let t=_e(e);for(;;){if(n.nodes.has(t))return!0;if(E.isIdentifier(t))return po.has(t.text)||uo(n,t);if(E.isCallExpression(t))return Di(t);let o=bn(t);if(o!==null){if(o.name==="constructor")return!0;t=o.receiver;continue}if(E.isElementAccessExpression(t)){t=_e(t.expression);continue}return!1}}function ji(e){let n=bn(_e(e.expression));if(n===null||n.name!=="get"||!E.isIdentifier(n.receiver)||n.receiver.text!=="Reflect")return null;let t=e.arguments[0];return t===void 0?null:{target:t,key:e.arguments[1]}}function Pu(e,n){let t=ji(e);if(t===null||!fo(t.target,n))return!1;let o=t.key;return o===void 0||!E.isStringLiteralLike(o)?!0:mo.has(o.text)}function pr(e){if(!E.isFunctionExpression(e)&&!E.isFunctionDeclaration(e))return!1;let n=e.body;if(n===void 0)return!1;let t=!1,o=r=>{if(!(t||E.isFunctionExpression(r)||E.isFunctionDeclaration(r)||E.isClassLike(r))){if(E.isReturnStatement(r)&&r.expression!==void 0&&_e(r.expression).kind===E.SyntaxKind.ThisKeyword){t=!0;return}E.forEachChild(r,o)}};return o(n),t}function It(e){if(E.isIdentifier(e))return[e.text];let n=[];for(let t of e.elements)E.isOmittedExpression(t)||n.push(...It(t.name));return n}function Bi(e){return e.parameters.map(n=>It(n.name))}function $u(e){let n=new Map,t=new Set,o=(s,a)=>{let l={fn:a,slots:Bi(a)},i=n.get(s);i===void 0?n.set(s,[l]):i.push(l),pr(a)&&t.add(s)},r=s=>{if(E.isFunctionDeclaration(s)&&s.name!==void 0)o(s.name.text,s);else if(E.isVariableDeclaration(s)&&E.isIdentifier(s.name)&&s.initializer!==void 0){let a=_e(s.initializer);(E.isFunctionExpression(a)||E.isArrowFunction(a))&&o(s.name.text,a)}E.forEachChild(s,r)};return r(e),{params:n,thisReturning:t}}function Ou(e){let n=new Map,t=new Set,o={roots:n,nodes:t},r=$u(e),s=new Map,a=new Set(r.thisReturning),l=!0;for(let i=0;l;i+=1){if(i>=Nu)return{roots:n,nodes:t,saturated:!0};l=!1;let d=(y,b)=>{b!==""&&!y.has(b)&&(y.add(b),l=!0)},u=(y,b)=>{if(y==="")return;let x=n.get(y);x===void 0&&(x=new Set,n.set(y,x)),x.has(b)||(x.add(b),l=!0)},p=y=>{t.has(y)||(t.add(y),l=!0)},f=(y,b)=>{let x=_e(y.expression);if(E.isIdentifier(x)&&fr.has(x.text)||vt(x)||E.isCallExpression(y)&&Di(y)||pr(x))return!0;let I=bn(x);if(I!==null&&(I.name==="call"||I.name==="apply"||I.name==="bind")){let w=I.receiver;if(pr(w)||t.has(w)||E.isIdentifier(w)&&(uo(o,w)||a.has(w.text)))return!0}if(t.has(x)||(E.isCallExpression(x)||E.isNewExpression(x))&&f(x,b+1)||E.isIdentifier(x)&&(uo(o,x)||a.has(x.text)))return!0;if(E.isCallExpression(y)){let w=ji(y);if(w!==null&&fo(w.target,o))return!0}return!1},m=(y,b)=>{if(b>=Ru)return!0;let x=_e(y);if(t.has(x))return!0;if(E.isIdentifier(x))return po.has(x.text)||uo(o,x);if(E.isBinaryExpression(x)){let I=x.operatorToken.kind;return I===E.SyntaxKind.BarBarToken||I===E.SyntaxKind.AmpersandAmpersandToken||I===E.SyntaxKind.QuestionQuestionToken?m(x.left,b+1)||m(x.right,b+1):!1}return E.isConditionalExpression(x)?m(x.whenTrue,b+1)||m(x.whenFalse,b+1):E.isPropertyAccessExpression(x)||E.isElementAccessExpression(x)?fo(x,o):E.isCallExpression(x)||E.isNewExpression(x)?f(x,b+1):!1},g=(y,b)=>{if((E.isVariableDeclaration(y)||E.isParameter(y)||E.isBindingElement(y))&&y.initializer!==void 0){if(m(y.initializer,0)){let I=Fi(y,e);for(let w of It(y.name))u(w,I)}}else if(E.isBinaryExpression(y)&&y.operatorToken.kind===E.SyntaxKind.EqualsToken&&E.isIdentifier(y.left)&&m(y.right,0))u(y.left.text,_u(y.left,e,s));else if(E.isReturnStatement(y)&&y.expression!==void 0&&b!==void 0&&m(y.expression,0))d(a,b);else if(E.isCallExpression(y)||E.isNewExpression(y)){f(y,0)&&p(y);let I=_e(y.expression),w=bn(I),A=w!==null&&w.name==="call",k=w!==null&&w.name==="apply",h=A||k?w.receiver:I,S=A?1:0,_=[];E.isFunctionExpression(h)||E.isArrowFunction(h)?_.push({fn:h,slots:Bi(h)}):E.isIdentifier(h)&&_.push(...r.params.get(h.text)??[]);let P=y.arguments??[];if(k){let v=P[1]===void 0?void 0:_e(P[1]);for(let{fn:T,slots:N}of _)if(v!==void 0&&E.isArrayLiteralExpression(v))for(let j=0;j<v.elements.length;j+=1){let O=v.elements[j],F=N[j];if(!(O===void 0||F===void 0)&&m(O,0))for(let K of F)u(K,T)}else if(v!==void 0)for(let j of N)for(let O of j)u(O,T)}else for(let{fn:v,slots:T}of _)for(let N=S;N<P.length;N+=1){let j=P[N],O=T[N-S];if(!(j===void 0||O===void 0)&&m(j,0))for(let F of O)u(F,v)}}let x=b;if(E.isFunctionDeclaration(y))x=y.name?.text;else if(E.isFunctionExpression(y)||E.isArrowFunction(y)){let I=y.parent;x=E.isVariableDeclaration(I)&&E.isIdentifier(I.name)?I.name.text:void 0}E.forEachChild(y,I=>g(I,x))};g(e,void 0)}return{roots:n,nodes:t,saturated:!1}}function Cu(e){if(E.isIdentifier(e)&&fr.has(e.text)||vt(e))return!0;let n=bn(e);if(n!==null&&(mo.has(n.name)||(n.name==="call"||n.name==="apply")&&(E.isIdentifier(n.receiver)&&fr.has(n.receiver.text)||vt(n.receiver)||(E.isPropertyAccessExpression(n.receiver)||E.isElementAccessExpression(n.receiver))&&Ti(n.receiver))))return!0;if(E.isElementAccessExpression(e)&&!E.isStringLiteralLike(e.argumentExpression)){let t=_e(e.expression);if(E.isIdentifier(t)&&po.has(t.text))return!0}return!1}var Mu=4;function $i(e,n){for(let t of e){if(!E.isStringLiteralLike(t)||n>=Mu)return!0;let o=E.createSourceFile("<eval>",`async function* __cupel_eval_probe__(){
|
|
13
13
|
${t.text}
|
|
14
|
-
}`,b.ScriptTarget.Latest,!0),o=r.parseDiagnostics;if(o!==void 0&&o.length>0||Oc(r,n+1,!0))return!0}return!1}function Oc(e,n=0,t=!1){return Dr(e,n,t).size>0}function Dr(e,n=0,t=!1){let r=new Set,o=t?kc:Nc(e);if(o.saturated)return r.add("saturated"),r;let i=l=>b.isElementAccessExpression(l)&&!b.isStringLiteralLike(l.argumentExpression)&&Lt(ke(l.expression),o),a=l=>{if(t&&(b.isCallExpression(l)||b.isNewExpression(l)||b.isTaggedTemplateExpression(l))){r.add("eval-invocation");return}if(b.isCallExpression(l)){let s=it(l);if(s!==null){let d=s.specifierArg;if(d===void 0||!b.isStringLiteralLike(d)||t){r.add("non-literal-load");return}}else{let d=ke(l.expression);if(b.isIdentifier(d)&&(d.text==="eval"||d.text==="Function")){if(qi(l.arguments,n)){r.add("eval-code");return}}else if(Rc(d)){r.add("loader-callee");return}else if(i(d)){r.add("computed-loader");return}else if(Ac(l,o)){r.add("reflect-get");return}}}else if(b.isNewExpression(l)){let s=ke(l.expression);if(b.isIdentifier(s)&&s.text==="Function"){if(qi(l.arguments??[],n)){r.add("function-ctor");return}}else if(rt(s)){r.add("ctor-chain");return}}else if(b.isIdentifier(l)&&gc.has(l.text)&&bc(l)){r.add("captured-loader");return}else if((b.isPropertyAccessExpression(l)||b.isElementAccessExpression(l))&&(Yi(l)||rt(l)||i(l))&&Xi(l)){r.add("captured-member");return}else if(b.isBindingElement(l)){let s=l.propertyName??l.name,d=b.isIdentifier(s)||b.isStringLiteralLike(s)?s.text:b.isComputedPropertyName(s)&&b.isStringLiteralLike(s.expression)?s.expression.text:void 0;if(d!==void 0&&jt.has(d)){r.add("destructured-member");return}}b.forEachChild(l,a)};return a(e),r}function ts(e,n,t){let r=new Set(Dr(t));if(Lr(e)&&n.includes("<")&&n.includes("require")){let o=b.createSourceFile(e,n,b.ScriptTarget.ES2020,!0,b.ScriptKind.TSX);for(let i of Dr(o))r.add(i)}return r}function Pc(e,n,t){if(Tr(e))return!0;let r=t.endsWith(Re.sep)?t:t+Re.sep,o=e.split("/"),i=n;for(;;){let a=Re.join(i,"node_modules",...o),l;try{l=An(Re.join(a,"package.json"))}catch{l=null}if(l!==null){if(!l.startsWith(r))return!1;let d=_e(l);if(d===null)return!1;let u;try{u=JSON.parse(d).exports}catch{return!1}if(typeof u=="string"||Array.isArray(u)||typeof u=="object"&&u!==null)return!1}if(Ai(a))return!1;if(i===t)break;let s=Re.dirname(i);if(s===i||s!==t&&!s.startsWith(r))break;i=s}return!0}function $c(e,n){let t=n.endsWith(Re.sep)?n:n+Re.sep,r=Re.dirname(e);for(;;){let o=Re.join(r,"package.json"),i;try{i=An(o)}catch{i=null}if(i!==null&&(i===n||i.startsWith(t))){let l=_e(i);if(l!==null)try{let s=JSON.parse(l).name;if(typeof s=="string"&&s.length>0)return s}catch{return null}}if(r===n)break;let a=Re.dirname(r);if(a===r||a!==n&&!a.startsWith(t))break;r=a}return null}function Mc(e,n,t,r,o){let i=[],a=[],l=new Set,s={},d=[],u=[],p=new Set,f=new Set,h=[],g=!1,S=(w,I)=>{let v;try{v=An(I)}catch{return!1}let _=Oe(e,v);if(_===null)return o.push({code:"out-of-root",path:v,detail:"dependency module resolved outside the app root; not followed"}),!1;let k=!t.has(v)&&!f.has(v);return k&&f.size>=Pr?(g=!0,!1):(a.push({from:w,to:{module:_}}),k?(f.add(v),i.push(_),!0):!1)},E=(w,I)=>{if(l.add(I),p.has(I))return;p.add(I);let v=Ke(I,w,Ne,n),_=v!==null?[v]:jn(I,w,Ne,n);_.length>=2&&d.push({path:Oe(e,w)??w,specifier:I,candidates:_.map(m=>Oe(e,m)??m)});let k=!1;for(let m of _)if(!Me(m)&&(k=!0,S({surface:I},m))){h.push(m);try{let y=Oe(e,An(m)),A=$c(m,e);y!==null&&A!==null&&(s[y]=A)}catch{}}k||Pc(I,Re.dirname(w),e)||o.push({code:"unresolved-specifier",path:I,reason:et(I,w,Ne,n),detail:`dependency "${I}" is installed and Node loads an entry for it, but its runtime entry did not resolve here (divergent conditional exports / a typesVersions remap / a declaration-only surface / an unreadable manifest / an out-of-root install); its module was not analyzed (degraded to unbounded)`})};for(let w of r)E(w.containingFile,w.packageName);for(;h.length>0&&f.size<Pr;){let w=h.pop();if(w===void 0)break;let I=Oe(e,w);if(I===null)continue;let v=Fn(w,pn);if(v.kind==="too-large"){o.push({code:"limit-exceeded",path:I,detail:`dependency module over the ${String(pn/1048576)}MiB cap; its imports were not followed (degraded to unbounded)`});continue}if(v.kind==="not-regular"){o.push({code:"parse-error",path:I,detail:"dependency module unreadable or not a regular file; its imports were not followed (degraded to unbounded)"});continue}let _=b.createSourceFile(w,v.text,b.ScriptTarget.ES2020,!0),k=_.parseDiagnostics;if(k!==void 0&&k.length>0){o.push({code:"dependency-body",path:I,detail:"dependency module has syntax errors; its tolerant parse may have dropped import/loader nodes \u2014 module reach unbounded (ADR-050 2A parse-cap)"});continue}let m=ts(w,v.text,_);if(m.size>0){o.push({code:"dependency-body",path:I,detail:"dependency module contains a loader escape (eval / Function / reflective or non-literal loader / captured loader value); its module reach is unbounded (ADR-045 Attack #1 dep-side mirror)",escapes:[...m].sort()});continue}o.push({code:"dependency-body",path:I,detail:"dependency module followed at module-import granularity only; its function bodies are not analyzed (ADR-050 2A, bodyless)",anchor:I});for(let y of Gi(w,v.text))if(y.runtime)if(ye(y.text)==="package-root"){let A=je(y.text);a.push({from:{module:I},to:{surface:A}}),E(w,A)}else{if(Tr(je(y.text)))continue;let A=Ke(y.text,w,Ne,n),C=A!==null?[A]:jn(y.text,w,Ne,n);if(C.length===0){if(ye(y.text)==="package-subpath"){let T=et(y.text,w,Ne,n);if(T==="no-candidate"||T==="not-installed"&&Ci(w,je(y.text))){u.push({path:I,specifier:y.text,why:T});continue}o.push({code:"unresolved-specifier",path:I,reason:T,detail:`runtime package-subpath import "${y.text}" did not resolve under Node10 (an exports-map/typesVersions subpath Node may load); its module was not analyzed`})}continue}C.length>=2&&d.push({path:I,specifier:y.text,candidates:C.map(T=>Oe(e,T)??T)});for(let T of C){if(Me(T)){let P=Oe(e,T);o.push({code:P===null?"out-of-root":"declaration-shadow",path:I,detail:P===null?`runtime import "${y.text}" resolved outside the app root; its module was not analyzed`:`runtime import "${y.text}" resolved to the declaration file "${P}" with no co-located runtime module; its code was not analyzed`});continue}S({module:I},T)&&h.push(T)}}}return(g||h.length>0)&&o.push({code:"limit-exceeded",path:e,detail:`dependency module closure hit the ${String(Pr)} cap; module-reachability truncated (degraded to unbounded)`}),{modules:i,edges:a,surfacePackages:[...l],entryRealNames:s,conditionUnions:d,provenAbsent:u}}function rs(e,n,t=!1){let r=An(e),o=[],i=[],a=b.createCompilerHost(Ne,!0),l=t?Oi(r,Ne,a):()=>null,s=new Set,d=new Set,u=n.map(R=>Re.join(r,R)),p=[],f=new Map,h=new Map,g=new Map,S=new Map,E=new Set,w=(R,F,O)=>{let L=`${String(R.length)}:${R}${F}`;E.has(L)||(E.add(L),o.push({code:"unresolved-specifier",path:R,detail:F,reason:O}))},I=()=>null,v=0,_=(R,F)=>{let O=h.get(R);return O===void 0&&(O=b.createSourceFile(R,F,b.ScriptTarget.ES2020,!0),h.set(R,O)),{real:R,sf:O}};for(;d.size<Dt;){let R=u.pop();if(R===void 0){if(v>=hc)break;v+=1;let K=[];for(let[$,q]of f)q.includes("readdir")&&(q.includes("require")||q.includes("import("))&&K.push(_($,q));let G=mc(K);if(G.length===0)break;let B=[];for(let[$,q]of f)B.push(_($,q));I=zi(B,G,Ne,a,g);let W=!1;for(let $ of K){let q=f.get($.real);if(q!==void 0)for(let H of Wi($.real,q,r,a,I))d.has(H)||(u.push(H),W=!0)}if(!W)break;continue}let F;try{F=An(R)}catch{continue}if(d.has(F))continue;if(d.add(F),Oe(r,F)===null){o.push({code:"out-of-root",path:R,detail:"resolved outside app root"});continue}let O=Fn(F,pn);if(O.kind==="too-large"){o.push({code:"limit-exceeded",path:F,detail:`file is ${String(Math.round(O.bytes/1048576))}MiB, over the ${String(pn/1048576)}MiB per-file cap; skipped (degraded to unknown)`});continue}if(O.kind==="not-regular"){o.push({code:"parse-error",path:F,detail:"unreadable or not a regular file"});continue}let L=O.text;s.add(F),f.set(F,L);for(let K of Gi(F,L)){let G=K.runtime?l(K.text,F):null;if(G===null&&ye(K.text)==="package-root"){K.runtime&&p.push({containingFile:F,packageName:je(K.text)});continue}let B=G??Ke(K.text,F,Ne,a),W=B!==null?[B]:K.runtime&&G===null?jn(K.text,F,Ne,a):[];if(W.length===0){if(K.runtime){let $=ye(K.text);if(!($==="package-subpath"&&Tr(je(K.text)))){if($==="package-subpath")w(F,`runtime package-subpath import "${K.text}" did not resolve under Node10 (an exports-map/typesVersions subpath Node may load); its module was not analyzed`,et(K.text,F,Ne,a));else if($==="relative"){let q=Ni(K.text,F,r,S);q.kind==="unanalyzable"&&w(F,`runtime relative import "${K.text}" did not resolve and its absence could not be proven \u2014 ${q.reason}; a bundler/loader may load a module the analyzer never saw`,q.why)}}}continue}W.length>=2&&i.push({path:Oe(r,F)??F,specifier:K.text,candidates:W.map($=>Oe(r,$)??$)});for(let $ of W){if(Oe(r,$)===null){o.push({code:"out-of-root",path:$,detail:`specifier "${K.text}" resolved outside app root`});continue}if(K.runtime&&Me($)){o.push({code:"declaration-shadow",path:$,detail:`runtime import "${K.text}" resolved to a declaration file with no co-located runtime module; its code was not analyzed`});continue}if(K.runtime&&!Ct($)){o.push({code:"unanalyzable-module",path:$,detail:`runtime import "${K.text}" resolved to a file the analyzer cannot parse (extensionless/.json/.node); its module was not analyzed`});continue}u.push($)}}for(let K of Wi(F,L,r,a,I))d.has(K)||u.push(K)}d.size>=Dt&&u.length>0&&o.push({code:"limit-exceeded",path:r,detail:`reachable file set exceeds ${String(Dt)}; analysis truncated (${String(u.length)}+ files not analyzed)`});let k=Mc(r,a,s,p,o),m=b.createProgram({rootNames:[...s],options:Ne,host:a}),y=new Set,A=new Map;for(let R of m.getSourceFiles()){if(R.isDeclarationFile||m.isSourceFileDefaultLibrary(R)||Oe(r,R.fileName)===null||!Lr(R.fileName))continue;let F=m.getSyntacticDiagnostics(R).length>0;if(!F&&!R.text.includes("<")||pc(R.text,b.ScriptKind.TSX)!==0)continue;let O=b.createSourceFile(R.fileName,R.text,b.ScriptTarget.ES2020,!0,b.ScriptKind.TSX);(F||Vi(O)>Vi(R))&&(y.add(R.fileName),A.set(R.fileName,R.text))}let C=m;if(y.size>0){let R=a.getSourceFile.bind(a);a.getSourceFile=(F,O,L,K)=>{let G=A.get(F);return G!==void 0?b.createSourceFile(F,G,b.ScriptTarget.ES2020,!0,b.ScriptKind.TSX):R(F,O,L,K)},C=b.createProgram({rootNames:[...s],options:Ne,host:a,oldProgram:m})}let T=C.getTypeChecker(),P=[];for(let R of C.getSourceFiles()){if(R.isDeclarationFile||C.isSourceFileDefaultLibrary(R)||Oe(r,R.fileName)===null)continue;P.push(R);let F=C.getSyntacticDiagnostics(R);if(F.length>0){let K=F[0],G=K!==void 0?b.flattenDiagnosticMessageText(K.messageText," "):"syntax error";o.push({code:"parse-error",path:R.fileName,detail:`${String(F.length)} syntax error(s): ${G}`})}let O=Oe(r,R.fileName),L=O===null?null:ts(R.fileName,R.text,R);O!==null&&L!==null&&L.size>0&&o.push({code:"loader-escape",path:O,detail:"module contains a loader escape (eval / Function / reflective or non-literal loader / captured or destructured loader); its module reach is unbounded (ADR-050 2B)",escapes:[...L].sort()})}return{program:C,checker:T,host:a,options:Ne,appRoot:r,sourceFiles:P,diagnostics:o,depReach:k,conditionUnions:[...i,...k.conditionUnions],provenAbsent:k.provenAbsent,resolveParamDirs:I,toRel:R=>Oe(r,R)}}import{opendirSync as Dc,statSync as Tc}from"node:fs";import Fr from"node:path";var Lc=8192,Fc=2e4,jc=new Set(["node_modules"]),os=new Set(["test","tests","__tests__","__mocks__","fixtures","e2e","dist","build","out","coverage","vendor"]),Kc=16;function Kt(e,n,t,r,o={}){let i=o.maxEntries??Fc,a=o.prune,l=[],s=!1,d=0,u=[{dir:Fr.join(e,n),rel:n,depth:0}];for(;u.length>0;){let p=u.pop();if(p===void 0)break;if(p.depth>Kc){s=!0;continue}let f;try{f=Dc(p.dir)}catch{s=!0;continue}try{let h=0;for(;;){let g=f.readSync();if(g===null)break;if(h+=1,d+=1,h>Lc||d>i){s=!0;break}let S=p.rel+g.name;if(g.isSymbolicLink()){let E;try{E=Tc(Fr.join(p.dir,g.name)).isDirectory()}catch{s=!0;continue}if(E){s=!0;continue}}else if(g.isDirectory()){if(jc.has(g.name)||g.name.startsWith(".")||a?.has(g.name)===!0){s=!0;continue}u.push({dir:Fr.join(p.dir,g.name),rel:`${S}/`,depth:p.depth+1});continue}else if(!g.isFile())continue;if(t(S)){if(l.length>=r){s=!0;break}l.push(S)}}}finally{try{f.closeSync()}catch{}}}return{matches:l,truncated:s}}var Bc=64;function is(e,n){let t=n.indexOf("*");if(t===-1||n.indexOf("*",t+1)!==-1)return null;let r=n.slice(0,t),o=n.slice(t+1);if(r.startsWith("./")&&(r=r.slice(2)),r.startsWith("/")||o.includes("/")||r.split("/").includes("..")||r.includes("\\")||n.includes("\0"))return null;let i=r.slice(0,r.lastIndexOf("/")+1);return Kt(e,i,a=>a.length>=r.length+o.length&&a.startsWith(r)&&a.endsWith(o),Bc)}import{existsSync as zc}from"node:fs";import Uc from"node:path";var Vc=[{name:"Astro",dependency:"astro",configFiles:["astro.config.mjs","astro.config.js","astro.config.ts","astro.config.mts"],entryHint:"your route files under src/pages/",rootDirs:["pages","actions"]},{name:"Next.js",dependency:"next",configFiles:["next.config.js","next.config.mjs","next.config.ts","next.config.cjs"],entryHint:"your route files under app/ or pages/",rootDirs:["app","pages"]},{name:"SvelteKit",dependency:"@sveltejs/kit",configFiles:["svelte.config.js","svelte.config.mjs","svelte.config.ts"],entryHint:"your route files under src/routes/",rootDirs:["routes"]},{name:"Nuxt",dependency:"nuxt",configFiles:["nuxt.config.js","nuxt.config.mjs","nuxt.config.ts"],entryHint:"app.vue, or your route files under pages/",rootDirs:["server","pages","middleware","plugins"]},{name:"Remix",dependency:"@remix-run/dev",configFiles:["remix.config.js","remix.config.mjs","vite.config.js","vite.config.ts"],entryHint:"app/root.tsx, or your route files under app/routes/",rootDirs:["app","routes"]},{name:"Vite",dependency:"vite",configFiles:["vite.config.js","vite.config.ts","vite.config.mjs","vite.config.mts"],entryHint:"the module script your index.html loads",rootDirs:[]}],Wc=["dependencies","devDependencies"];function qc(e,n){for(let t of Wc){let r=e[t];if(!(typeof r!="object"||r===null||Array.isArray(r))&&Object.hasOwn(r,n))return!0}return!1}function jr(e,n){if(n===null)return null;for(let t of Vc)if(qc(n,t.dependency)){for(let r of t.configFiles)if(zc(Uc.join(e,r)))return{name:t.name,configFile:r,entryHint:t.entryHint,rootDirs:t.rootDirs}}return null}function Kr(e){return`This looks like ${e.name} (${e.configFile} plus the dependency), and ${e.name} resolves its entry at build time \u2014 there is nothing in package.json for cupel to start from. Pass --entry ${e.entryHint}.`}var Gc=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"],Hc=256,Xc=12e4;function Br(e,n){let t=new Set(n.rootDirs);if(t.size===0)return{roots:[],truncated:!1};let r=Kt(e,"",o=>{let i=o.split("/");for(let a=0;a<i.length-1;a+=1){let l=i[a];if(l!==void 0&&t.has(l))return Gc.some(s=>o.endsWith(s))}return!1},Hc,{maxEntries:Xc,prune:os});return{roots:r.matches,truncated:r.truncated}}function Be(e){let n=e.length<=120?e:`${e.slice(0,120)}\u2026`,t="";for(let r of n){let o=r.codePointAt(0)??0;t+=o<32||o>=127&&o<=159?`\\x${o.toString(16).padStart(2,"0")}`:r}return t}function Yc(e){for(let n of e){let t=n.codePointAt(0)??0;if(t<32||t===127||t>=128&&t<=159||"&|;<>$`(){}[]*?~#!\\\"'".includes(n))return!0}return!1}function Jc(e){let n=!1;for(let t=0;t<e.length;t+=1){let r=e.charAt(t),o=r.codePointAt(0)??0;if(o<32||o===127||o>=128&&o<=159)return null;if(r==="\\"){n=!0;let i=e.charAt(t+1);if(!(i>="a"&&i<="z"||i>="A"&&i<="Z"||i>="0"&&i<="9"||i==="."||i==="_"||i==="-"))return null;continue}if("&|;<>$`(){}[]*?~#!\"'".includes(r))return null}return n?{windows:e.split("\\").join("/"),posixShell:e.split("\\").join("")}:null}function Zc(e){let n=[],t="";for(let r of e){if(r===" "||r===" "){if(t.length>0){if(n.length>=64)return null;n.push(t),t=""}continue}t+=r}if(t.length>0){if(n.length>=64)return null;n.push(t)}return n}var Qc=/^[A-Za-z_][A-Za-z0-9_]*=/u;function eu(e){let n=e.slice(e.lastIndexOf("/")+1);return n==="node"||n==="nodejs"}var nu=new Set(["--abort-on-uncaught-exception","--disallow-code-generation-from-strings","--enable-source-maps","--experimental-json-modules","--experimental-modules","--experimental-vm-modules","--frozen-intrinsics","--harmony","--inspect","--inspect-brk","--no-warnings","--preserve-symlinks","--preserve-symlinks-main","--trace-uncaught","--trace-warnings","--use-strict","--zero-fill-buffers"]),tu=new Set(["--dns-result-order","--heapsnapshot-signal","--inspect-port","--max-http-header-size","--max-old-space-size","--max-semi-space-size","--stack-size","--title","--tls-cipher-list","--trace-event-categories","--unhandled-rejections","--v8-pool-size"]),ru=new Set(["-e","--eval","-p","--print","--run","--env-file","--env-file-if-exists"]);function as(e){return e.includes("require")||e.includes("import")||e.includes("loader")}function ss(e){if(as(e))return{token:e,why:"preloads another module; the launch surface is more than one file"};let n=e.indexOf("="),t=n===-1?e:e.slice(0,n);return ru.has(t)?{token:t,why:"runs code that is not the script token (or can inject a preload); the entry file cannot be identified"}:nu.has(t)||n!==-1&&tu.has(t)?null:{token:t,why:"is not on cupel's allowlist of flags that provably do not change which file node runs \u2014 the entry file cannot be identified with certainty"}}var ou=[".js",".cjs",".mjs",".ts",".mts",".cts"];function iu(e){return ou.some(n=>e.endsWith(n))}var su=new Set(["npm","yarn","pnpm"]);function au(e){let n=e[0];return n===void 0||!su.has(n)?!1:e.length===2?e[1]==="start":e.length===3&&e[1]==="run"&&e[2]==="start"}function Ur(e){let n=e.trim();if(n.length===0)return{kind:"unparsed",reason:"empty command"};if(n.length>4096)return{kind:"unparsed",reason:`command exceeds the ${String(4096)}-byte cap; not parsed`};if(!Yc(n))return zr(n);let t=Jc(n);if(t===null)return{kind:"unparsed",reason:"contains shell metacharacters (chaining/expansion/quoting) \u2014 not a plain `node <file>` invocation"};let r=zr(t.windows),o=zr(t.posixShell);if(r.kind==="file"){let i=o.kind==="file"?o.specifier:void 0;return i===void 0||i===r.specifier?{kind:"file",specifier:r.specifier}:{kind:"file",specifier:r.specifier,alt:i}}return o.kind==="file"?{kind:"file",specifier:o.specifier}:r}function zr(e){let n=Zc(e);if(n===null)return{kind:"unparsed",reason:"command has more tokens than cupel will consider"};let t=0;for(n[t]==="env"&&(t+=1);t<n.length;t+=1){let i=n[t];if(i===void 0||!Qc.test(i))break;if(as(i))return{kind:"unparsed",reason:`environment \`${Be(i)}\` preloads another module; the launch surface is more than one file`};let a=i.indexOf("=");if(i.slice(0,a)==="NODE_OPTIONS")for(let l of i.slice(a+1).split(/\s+/u)){if(l===""||!l.startsWith("-"))continue;let s=ss(l);if(s!==null)return{kind:"unparsed",reason:`NODE_OPTIONS flag \`${Be(s.token)}\` ${s.why}`}}}let r=n[t];if(r===void 0)return{kind:"unparsed",reason:"no program in the command"};if(au(n.slice(t)))return{kind:"delegates",target:"scripts.start"};if(!eu(r))return{kind:"unparsed",reason:`runs \`${Be(r)}\`, not node directly \u2014 the entry file cannot be identified`};for(t+=1;t<n.length;t+=1){let i=n[t];if(i===void 0||!i.startsWith("-"))break;let a=ss(i);if(a!==null)return{kind:"unparsed",reason:`node flag \`${Be(a.token)}\` ${a.why}`}}let o=n[t];return o===void 0?{kind:"unparsed",reason:"node is invoked with no script file"}:iu(o)?{kind:"file",specifier:o}:{kind:"unparsed",reason:`\`${Be(o)}\` has no .js/.cjs/.mjs/.ts extension \u2014 not confidently a JS entry file`}}function lu(e){for(let n of e)if(!(n>="a"&&n<="z"||n>="A"&&n<="Z"||n>="0"&&n<="9"||n==="_"||n==="-"))return!1;return e.length>0}var du=64;function Vr(e){let n=e.split(`
|
|
15
|
-
`),t=n.length>64,r=[],o=0;for(let i of n.slice(0,64)){let a=i.trim();if(a.length===0||a.startsWith("#"))continue;let l=a.indexOf(":");if(l<=0)continue;let s=a.slice(l+1).trim();if(s.length===0)continue;let d=a.slice(0,l);if(d.length>du||!lu(d)){o+=1;continue}r.push({name:d,command:s})}return r.sort((i,a)=>i.name===a.name?0:i.name==="web"?-1:a.name==="web"?1:0),{entries:r,truncated:t,unnamedLines:o}}import{realpathSync as ls}from"node:fs";import Te from"node:path";import c from"typescript";var ds=3;function le(e,n,t){if(e===void 0)return;let r=e[n]??={fired:0,refused:{}};t===null?r.fired+=1:r.refused[t]=(r.refused[t]??0)+1}function gn(e,n,t){return{path:e,start:n.getStart(t,!1),end:n.getEnd()}}var zt=16,Hr=256,Wr=class{mods=new Map;fns=new Map;classNodes=new Map;classMembers=new Map;moduleFor(n){let t=`pkg:${n}`;return this.mods.has(n)||this.mods.set(n,{id:t,packageName:n,versionRange:"",path:n,moduleSystem:"dual",isEntrypoint:!1,externalSurface:!0}),t}exportFor(n,t){let r=`${n}#${t}`,o=`pkg:${n}#${t}`;return this.fns.has(r)||(this.moduleFor(n),this.fns.set(r,{id:o,moduleId:`pkg:${n}`,name:t,kind:"function",declRange:{path:n,start:0,end:0},isExported:!0,publicSurfaceReachable:!0})),o}classFor(n,t){let r=`${n}#${t}`,o=`pkg:${n}#${t}`;return this.classNodes.has(r)||(this.moduleFor(n),this.classNodes.set(r,{id:o,moduleId:`pkg:${n}`,name:t,implementsRefs:[],members:[]}),this.classMembers.set(r,[])),o}methodFor(n,t,r,o){let i=`${n}#${t}.${r}`,a=`pkg:${n}#${t}.${r}`;if(!this.fns.has(i)){let l=this.classFor(n,t);this.fns.set(i,{id:a,moduleId:`pkg:${n}`,name:r,kind:o,enclosingClassId:l,declRange:{path:n,start:0,end:0},isExported:!0,publicSurfaceReachable:!0}),this.classMembers.get(`${n}#${t}`)?.push(a)}return a}modules(){return[...this.mods.values()]}functions(){return[...this.fns.values()]}classes(){return[...this.classNodes.entries()].map(([n,t])=>({...t,members:this.classMembers.get(n)??[]}))}};function xs(e,n){let t="node_modules/",r=e.lastIndexOf(t);if(r===-1)return n;let i=e.slice(r+t.length).split("/");return i[0]?.startsWith("@")&&i.length>=2?`${i[0]}/${i[1]}`:i[0]??n}function cs(e,n,t){let r=Te.dirname(e),o=Te.dirname(n),i=[];for(;;){let l=t.get(r);if(l!==void 0){for(let d of i)t.set(d,l);return l}i.push(r);let s=_e(Te.join(r,"package.json"));if(s!==null)try{let d=JSON.parse(s),u={name:d.name??"app",version:d.version??"0.0.0",dir:r};for(let p of i)t.set(p,u);return u}catch{}if(r===o||r===Te.dirname(r))break;r=Te.dirname(r)}let a={name:"app",version:"0.0.0",dir:null};for(let l of i)t.set(l,a);return a}function qr(e){return c.isParenthesizedExpression(e)?qr(e.expression):c.isStringLiteralLike(e)?e.text:c.isTemplateExpression(e)?e.head.text:c.isBinaryExpression(e)&&e.operatorToken.kind===c.SyntaxKind.PlusToken?qr(e.left):null}function cu(e){if(!c.isCallExpression(e))return!1;let n=e.expression,t=c.isPropertyAccessExpression(n)?n.name.text:c.isIdentifier(n)?n.text:null;if(t!=="join"&&t!=="resolve")return!1;let r=e.arguments[0];return r!==void 0&&c.isIdentifier(r)&&(r.text==="__dirname"||r.text==="__filename")}function Ss(e){let n=qr(e);return n!==null?n.startsWith("./")||n.startsWith("../")?"relative-bounded":n.length>0&&!n.startsWith(".")&&!n.startsWith("/")?"bare":"unknown":cu(e)?"relative-bounded":"unknown"}function uu(e){let n=[],t=r=>{if(c.isImportDeclaration(r)&&c.isStringLiteralLike(r.moduleSpecifier))n.push({specifier:r.moduleSpecifier.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isImportEqualsDeclaration(r)&&c.isExternalModuleReference(r.moduleReference)&&c.isStringLiteralLike(r.moduleReference.expression))n.push({specifier:r.moduleReference.expression.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isExportDeclaration(r)&&r.moduleSpecifier!==void 0&&c.isStringLiteralLike(r.moduleSpecifier))n.push({specifier:r.moduleSpecifier.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isCallExpression(r)){let o=it(r);if(o!==null){let i=o.specifierArg,a=i!==void 0&&c.isStringLiteralLike(i);n.push({specifier:a?i.text:void 0,specifierIsLiteral:a,dynamic:!0,...i!==void 0&&!a?{computedArg:i,loadPos:r.getStart(e)}:{}})}}c.forEachChild(r,t)};return t(e),n}function fu(e,n,t){let r=new Map,o=cs(Te.join(e.appRoot,"package.json"),e.appRoot,r),i=[],a=[],l=[],s=new Map,d=new Set,u=[],p=new Set;for(let f of e.sourceFiles){let h=e.toRel(f.fileName);h!==null&&p.add(h)}for(let f of e.sourceFiles){let h=e.toRel(f.fileName);if(h===null)continue;let g=cs(f.fileName,e.appRoot,r),S=xs(h,o.name),E=h.includes("node_modules/");i.push({id:h,packageName:E&&g.name!==o.name?g.name:S,versionRange:g.version,path:h,moduleSystem:"cjs",isEntrypoint:n.has(h)}),g.dir===o.dir&&d.add(h);let w=0,I=null;for(let v of uu(f)){let _=`${h}#import${String(w)}`;w+=1;let k=null,m=[];if(v.specifier!==void 0)if(ye(v.specifier)==="package-root")k=t.moduleFor(je(v.specifier));else{let y=Ke(v.specifier,f.fileName,e.options,e.host),A=y!==null?e.toRel(y):null;if(A!==null)k=A;else if(v.specifier!==void 0){let[C,...T]=jn(v.specifier,f.fileName,e.options,e.host).map(P=>e.toRel(P)).filter(P=>P!==null&&p.has(P));C!==void 0&&T.length>=1&&(k=C,m=T.map(P=>P))}}a.push({id:_,moduleId:h,specifier:v.specifier??"<computed>",isNamespace:!1,isDefault:!1,dynamic:v.dynamic,specifierIsLiteral:v.specifierIsLiteral,...k!==null?{resolvedModuleId:k}:{}}),k!==null&&l.push({importId:_,resolvedModuleId:k});for(let y of m)l.push({importId:_,resolvedModuleId:y});if(v.computedArg!==void 0&&v.loadPos!==void 0&&u.push({importId:String(_),path:h,pos:v.loadPos,shape:Ss(v.computedArg),text:v.computedArg.getText(f).slice(0,160)}),v.computedArg!==void 0&&v.loadPos!==void 0){I??=In(f,f.fileName,e.resolveParamDirs);let y=[];for(let A of $t(v.computedArg,I,e.appRoot,e.options,e.host)){let C=e.toRel(A);if(C===null||!p.has(C))continue;let T=C,P=`${h}#import${String(w)}`;w+=1,a.push({id:P,moduleId:h,specifier:C,isNamespace:!1,isDefault:!1,dynamic:!0,specifierIsLiteral:!0,resolvedModuleId:T}),l.push({importId:P,resolvedModuleId:T}),y.push(C)}if(y.length>0){let A=tt(v.computedArg,I)!==null||Pt(v.computedArg),C=s.get(h)??[];C.push({pos:v.loadPos,candidateRels:y,seedable:A}),s.set(h,C)}}}}return{modules:i,imports:a,importEdges:l,computedLoads:s,appOwnedPaths:d,loadSites:u}}function pu(e){let n=_e(e);if(n===null)return null;let t=c.createSourceFile(e,n,c.ScriptTarget.Latest,!0),r=o=>t.statements.some(i=>c.isFunctionDeclaration(i)?i.name?.text===o:c.isVariableStatement(i)?i.declarationList.declarations.some(a=>c.isIdentifier(a.name)&&a.name.text===o&&a.initializer!==void 0&&(c.isFunctionExpression(a.initializer)||c.isArrowFunction(a.initializer))):!1);for(let o of t.statements){if(c.isFunctionDeclaration(o)&&o.name!==void 0&&o.modifiers?.some(a=>a.kind===c.SyntaxKind.DefaultKeyword)===!0)return o.name.text;if(!c.isExpressionStatement(o)||!c.isBinaryExpression(o.expression))continue;let i=o.expression;if(i.operatorToken.kind===c.SyntaxKind.EqualsToken&&mu(i.left)){if(c.isFunctionExpression(i.right)&&i.right.name!==void 0)return i.right.name.text;if(c.isIdentifier(i.right)&&r(i.right.text))return i.right.text}}return null}function mu(e){return c.isPropertyAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&e.name.text==="exports"?!0:c.isElementAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&c.isStringLiteralLike(e.argumentExpression)&&e.argumentExpression.text==="exports"}function hu(e,n,t){for(let d of e.surfacePackages)n.moduleFor(d);let r=d=>"surface"in d?n.moduleFor(d.surface):d.module,o=[],i=new Set;for(let d of e.modules)t.has(d)||i.has(d)||(i.add(d),o.push({id:d,packageName:e.entryRealNames[d]??xs(d,"app"),versionRange:"",path:d,moduleSystem:"cjs",isEntrypoint:!1}));let a=[],l=[],s=0;for(let d of e.edges){let u=r(d.from),p=r(d.to),f=`${String(u)}#depreach${String(s)}`;s+=1,a.push({id:f,moduleId:u,specifier:"<dep-module-reach>",isNamespace:!1,isDefault:!1,dynamic:!1,specifierIsLiteral:!0,resolvedModuleId:p}),l.push({importId:f,resolvedModuleId:p})}return{modules:o,imports:a,importEdges:l}}function us(e,n,t){let r=e.expression;if(c.isIdentifier(r)&&!t.has(r.text)){let o=n.get(r.text);if(o?.kind==="package-export")return{kind:"package-instance",packageName:o.packageName,className:o.exportName};if(o?.kind==="app-class")return{kind:"app-instance",cls:o.cls}}else if(c.isPropertyAccessExpression(r)&&c.isIdentifier(r.expression)&&!t.has(r.expression.text)){let o=n.get(r.expression.text);if(o?.kind==="package-surface")return{kind:"package-instance",packageName:o.packageName,className:r.name.text}}return null}function _n(e){return c.canHaveModifiers(e)&&(c.getModifiers(e)?.some(n=>n.kind===c.SyntaxKind.ExportKeyword)??!1)}function gu(e){let n=new Set,t;for(let r of e.statements){if(c.isExpressionStatement(r)&&c.isBinaryExpression(r.expression)){let o=r.expression;if(o.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(o.left)&&c.isIdentifier(o.left.expression)&&o.left.expression.text==="module"&&o.left.name.text==="exports"){if(c.isIdentifier(o.right))n.add(o.right.text),t=o.right.text;else if(c.isObjectLiteralExpression(o.right))for(let i of o.right.properties)c.isShorthandPropertyAssignment(i)?n.add(i.name.text):c.isPropertyAssignment(i)&&c.isIdentifier(i.initializer)&&n.add(i.initializer.text)}continue}if(c.isFunctionDeclaration(r)&&r.name!==void 0&&_n(r))n.add(r.name.text);else if(c.isVariableStatement(r)&&_n(r))for(let o of r.declarationList.declarations)c.isIdentifier(o.name)&&n.add(o.name.text);else if(c.isExportDeclaration(r)&&r.exportClause&&c.isNamedExports(r.exportClause))for(let o of r.exportClause.elements)n.add((o.propertyName??o.name).text);else c.isExportAssignment(r)&&c.isIdentifier(r.expression)&&(n.add(r.expression.text),t=r.expression.text)}return{reachableLocals:n,defaultTarget:t}}function yu(e){for(let n of e.statements){if(c.isFunctionDeclaration(n)&&n.name!==void 0&&_n(n)&&c.getModifiers(n)?.some(t=>t.kind===c.SyntaxKind.DefaultKeyword)===!0)return{name:n.name.text,esm:!0};if(c.isExportAssignment(n)&&!n.isExportEquals&&c.isIdentifier(n.expression))return{name:n.expression.text,esm:!0};if(c.isExpressionStatement(n)&&c.isBinaryExpression(n.expression)){let t=n.expression;if(t.operatorToken.kind===c.SyntaxKind.EqualsToken&&$e(t.left)&&c.isIdentifier(t.right))return{name:t.right.text,esm:!1}}}}function nn(e){if(c.isCallExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="require"&&e.arguments.length===1&&e.arguments[0]!==void 0&&c.isStringLiteralLike(e.arguments[0]))return e.arguments[0].text}function $e(e){return c.isPropertyAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&e.name.text==="exports"?!0:c.isElementAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&c.isStringLiteralLike(e.argumentExpression)&&e.argumentExpression.text==="exports"}function qe(e){if($e(e))return!0;if(!c.isPropertyAccessExpression(e)&&!c.isElementAccessExpression(e))return!1;let n=e.expression;return c.isIdentifier(n)&&n.text==="exports"?!0:$e(n)}function zn(e){return c.isPropertyAccessExpression(e.expression)&&c.isIdentifier(e.expression.expression)&&e.expression.expression.text==="Object"&&e.expression.name.text==="assign"}function bs(e){let n=!1,t=r=>{if(!n){if(c.isCallExpression(r)){let o=nn(r);if(o!==void 0&&ye(o)!=="package-root"){n=!0;return}}c.forEachChild(r,t)}};return t(e),n}function ks(e){let n=new Set,t=o=>o!==void 0&&bs(o),r=o=>{c.isVariableDeclaration(o)&&t(o.initializer)&&nt(o.name,n),c.isBinaryExpression(o)&&o.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isIdentifier(o.left)&&t(o.right)&&n.add(o.left.text),c.forEachChild(o,r)};return r(e),n}function Es(e,n){for(let t of e.properties)c.isShorthandPropertyAssignment(t)?n.add(t.name.text):c.isPropertyAssignment(t)&&c.isIdentifier(t.initializer)&&n.add(t.initializer.text)}function xu(e){let n=new Set;for(let l of e.statements)if(c.isFunctionDeclaration(l)&&l.name!==void 0)n.add(l.name.text);else if(c.isClassDeclaration(l)&&l.name!==void 0)n.add(l.name.text);else if(c.isVariableStatement(l))for(let s of l.declarationList.declarations)c.isIdentifier(s.name)&&s.initializer!==void 0&&(c.isFunctionExpression(s.initializer)||c.isArrowFunction(s.initializer)||c.isObjectLiteralExpression(s.initializer))&&n.add(s.name.text);let t=l=>c.isFunctionExpression(l)||c.isArrowFunction(l)||c.isObjectLiteralExpression(l)||c.isIdentifier(l)&&n.has(l.text),r=new Set,o=l=>{c.isIdentifier(l)?r.add(l.text):c.isObjectLiteralExpression(l)&&Es(l,r)},i=!1,a=l=>{if(!i){if(c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken)if($e(l.left)){o(l.right);let s=l.right;(c.isObjectLiteralExpression(s)?s.properties.every(u=>c.isShorthandPropertyAssignment(u)&&n.has(u.name.text)||c.isPropertyAssignment(u)&&t(u.initializer)):t(s))||(i=!0)}else qe(l.left)&&(t(l.right)||(i=!0));else(c.isCallExpression(l)&&zn(l)&&l.arguments[0]!==void 0&&Nn(l.arguments[0])||c.isExportDeclaration(l)&&l.moduleSpecifier!==void 0)&&(i=!0);i||c.forEachChild(l,a)}};if(a(e),!i&&r.size>0){for(let l of As(e))if(r.has(l)){i=!0;break}}return i}function Nn(e){return qe(e)||c.isIdentifier(e)&&e.text==="exports"}function ws(e){if(!c.isPropertyAccessExpression(e.expression)||!c.isIdentifier(e.expression.expression))return!1;let n=e.expression.expression.text,t=e.expression.name.text;return n==="Object"&&(t==="defineProperty"||t==="defineProperties")||n==="Reflect"&&(t==="defineProperty"||t==="set")}function Xr(e){return ws(e)&&e.arguments[0]!==void 0&&Nn(e.arguments[0])}function Su(e){return ws(e)&&e.arguments[0]!==void 0&&c.isIdentifier(e.arguments[0])&&e.arguments[0].text==="module"}function bu(e){for(let n of e.declarations??[])if(c.isExportSpecifier(n)){if(n.isTypeOnly)return!0;let t=n.parent.parent;if(c.isExportDeclaration(t)&&t.isTypeOnly)return!0}else if(c.isImportSpecifier(n)){if(n.isTypeOnly)return!0;let t=n.parent.parent;if(c.isImportClause(t)&&t.isTypeOnly)return!0}return!1}function ku(e,n,t,r,o){let i=(e.declarations??[]).filter(l=>!c.isSourceFile(l)&&!c.isModuleDeclaration(l));for(let l of i){let s=l.getSourceFile(),d=n.toRel(s.fileName);if(d===null||o.has(d))continue;let u=t.get(`${d}::${String(l.getStart(s,!1))}`);if(u!==void 0)return u}let a=e.getName();for(let l of i){let s=n.toRel(l.getSourceFile().fileName);if(s===null||o.has(s))continue;let d=r.get(`${s}::${a}`);if(d!==void 0)return d}}function Ut(e){return c.isPropertyAccessExpression(e)?e.name.text:c.isStringLiteralLike(e.argumentExpression)?e.argumentExpression.text:void 0}var Yr=/^[A-Za-z_$][A-Za-z0-9_$]*$/u;function Jr(e){let n=c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)?Ut(e):void 0;return n!==void 0&&n!=="__proto__"&&Yr.test(n)?n:void 0}function Eu(e){return e!=="__proto__"&&Yr.test(e)}function fs(e){let n=ke(e);return c.isIdentifier(n)&&(n.text==="exports"||n.text==="module")||$e(n)}function wu(e){if(!c.isArrayLiteralExpression(e)&&!c.isObjectLiteralExpression(e))return!1;let n=!1,t=r=>{n||(qe(r)?n=!0:c.forEachChild(r,t))};return t(e),n}function Zr(e){let n=!1,t=new Map,r=o=>{if(!n){if(c.isBinaryExpression(o)&&o.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&o.operatorToken.kind<=c.SyntaxKind.LastAssignment){if($e(o.left)||c.isIdentifier(o.left)&&o.left.text==="exports")n=!0;else if(o.operatorToken.kind===c.SyntaxKind.EqualsToken&&fs(o.right))n=!0;else if(wu(o.left))n=!0;else if(qe(o.left)){let i=Jr(o.left);i===void 0?n=!0:t.set(i,(t.get(i)??0)+1)}}else(c.isCallExpression(o)&&zn(o)&&o.arguments[0]!==void 0&&Nn(o.arguments[0])||c.isCallExpression(o)&&Xr(o)||c.isCallExpression(o)&&Su(o)||c.isVariableDeclaration(o)&&o.initializer!==void 0&&fs(o.initializer))&&(n=!0);n||c.forEachChild(o,r)}};return r(e),{surfaceEscapes:n,assignCount:t}}function Qr(e){let n=[];for(let t of e.statements){if(!c.isExpressionStatement(t)||!c.isBinaryExpression(t.expression))continue;let r=t.expression;r.operatorToken.kind===c.SyntaxKind.EqualsToken&&(!qe(r.left)||$e(r.left)||n.push({bin:r,name:Jr(r.left)}))}return n}function vu(e){let{surfaceEscapes:n,assignCount:t}=Zr(e);if(n)return[];let r=[];for(let{bin:o,name:i}of Qr(e))i===void 0||(t.get(i)??0)!==1||(c.isFunctionExpression(o.right)||c.isArrowFunction(o.right))&&r.push({name:i,value:o.right});return r}function Iu(e,n){let{surfaceEscapes:t,assignCount:r}=Zr(e);if(t)return[];let o=[];for(let{bin:i,name:a}of Qr(e))a===void 0||(r.get(a)??0)!==1||c.isIdentifier(i.right)&&!n.has(i.right.text)&&o.push(i.right.text);return o}function Au(e,n){let{surfaceEscapes:t,assignCount:r}=Zr(e);for(let{bin:o,name:i}of Qr(e)){let a=o.right;if(!(c.isFunctionExpression(a)||c.isArrowFunction(a)||c.isIdentifier(a)))continue;let s=c.isFunctionExpression(a)||c.isArrowFunction(a)||c.isIdentifier(a)&&!n.has(a.text);if(!(!t&&i!==void 0&&(r.get(i)??0)===1&&s))return!0}return!1}function _u(e){let n=c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)?e.expression:void 0;return n!==void 0&&c.isIdentifier(n)&&n.text==="exports"?"exports":"module.exports"}function ps(e){let n=e.parent;return n===void 0?!1:c.isPropertyAccessExpression(n)?n.name===e:c.isQualifiedName(n)?n.right===e:c.isBindingElement(n)||c.isImportSpecifier(n)?n.propertyName===e:c.isExportSpecifier(n)?!0:c.isPropertyAssignment(n)||c.isPropertyDeclaration(n)||c.isPropertySignature(n)||c.isMethodDeclaration(n)||c.isMethodSignature(n)||c.isGetAccessorDeclaration(n)||c.isSetAccessorDeclaration(n)||c.isEnumMember(n)?n.name===e:!1}function ms(e){for(let n=e.parent;n!==void 0;n=n.parent){if(c.isSourceFile(n))return!0;if(!c.isArrowFunction(n)&&(c.isFunctionLike(n)||c.isClassLike(n)))return!1}return!0}function Nu(e,n){let t=r=>{c.isIdentifier(r)&&(r.text==="exports"||r.text==="module")&&n.add(r),c.forEachChild(r,t)};t(e)}function Ru(e){let n=[],t=new Set;for(let i of e.statements){if(c.isExportDeclaration(i)||c.isExportAssignment(i)||c.isImportDeclaration(i)||c.isImportEqualsDeclaration(i)||_n(i))return null;if(!c.isExpressionStatement(i)||!c.isBinaryExpression(i.expression))continue;let a=i.expression;if(a.operatorToken.kind===c.SyntaxKind.EqualsToken){if($e(a.left))n.push({kind:"whole",value:a.right});else if(qe(a.left)){let l=Jr(a.left);if(l===void 0)return null;n.push({kind:"member",name:l,value:a.right,root:_u(a.left)})}else continue;Nu(a.left,t)}}let r=!1,o=i=>{if(!r){if(c.isIdentifier(i)&&(i.text==="exports"||i.text==="module")&&!t.has(i)&&!ps(i)){r=!0;return}if(i.kind===c.SyntaxKind.ThisKeyword&&ms(i)){r=!0;return}if(c.isIdentifier(i)&&i.text==="arguments"&&!ps(i)&&ms(i)){r=!0;return}c.forEachChild(i,o)}};return o(e),r?null:n}function Gr(e){return c.isIdentifier(e)||c.isStringLiteralLike(e)?e.text:void 0}function hs(e,n,t){return c.isIdentifier(e)?n(e.text):t?.(e)}function Cu(e,n,t,r){let o=new Map,i=Ru(e);if(i===null||i.filter(h=>h.kind==="whole").length>1)return o;let a=i.findIndex(h=>h.kind==="whole"),l=(h,g)=>a>=0&&g>a&&h.kind==="member"&&h.root==="exports",s=i.some(l);if(s){let h=i[a];if(h===void 0||h.kind!=="whole"||!c.isObjectLiteralExpression(h.value))return o}let d=s?i.filter((h,g)=>!l(h,g)):i,u=new Map;for(let h of d)h.kind==="member"&&u.set(h.name,(u.get(h.name)??0)+1);let p=h=>n.has(h)?void 0:t(h),f=(h,g)=>{g===void 0?o.delete(h):o.set(h,g)};for(let h of d){if(h.kind==="member"){f(h.name,(u.get(h.name)??0)>1?void 0:hs(h.value,p,r));continue}o.clear();let g=h.value;if(c.isObjectLiteralExpression(g))for(let S of g.properties){if(c.isSpreadAssignment(S))return new Map;if(c.isShorthandPropertyAssignment(S)){f(S.name.text,p(S.name.text));continue}let E=Gr(S.name);if(E===void 0)return new Map;f(E,c.isPropertyAssignment(S)?hs(S.initializer,p,r):void 0)}}return o}function vs(e,n,t,r){let o=new Map,i=l=>l!==void 0&&ye(l)==="relative"?t.get(`${n}::${l}`):void 0,a=l=>{if(c.isVariableDeclaration(l)&&l.initializer!==void 0){let s=l.initializer;if(c.isIdentifier(l.name)&&!r.has(l.name.text)){let d=i(nn(s));if(d!==void 0)o.set(l.name.text,{kind:"whole",target:d});else if((c.isPropertyAccessExpression(s)||c.isElementAccessExpression(s))&&c.isCallExpression(s.expression)){let u=i(nn(s.expression)),p=Ut(s);u!==void 0&&p!==void 0&&o.set(l.name.text,{kind:"member",target:u,member:p})}}else if(c.isObjectBindingPattern(l.name)){let d=i(nn(s));if(d!==void 0){for(let u of l.name.elements)if(c.isIdentifier(u.name)&&!r.has(u.name.text)){let p=u.propertyName!==void 0&&c.isIdentifier(u.propertyName)?u.propertyName.text:u.name.text;o.set(u.name.text,{kind:"member",target:d,member:p})}}}}c.forEachChild(l,a)};return a(e),o}function Ou(e,n,t,r){let o=a=>a!==void 0&&ye(a)==="relative"?t.get(`${n}::${a}`):void 0,i=o(nn(e));if(i!==void 0)return{kind:"whole",target:i};if(c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)){let a=Ut(e);if(a===void 0)return;let l=o(nn(e.expression));if(l!==void 0)return{kind:"member",target:l,member:a};if(c.isIdentifier(e.expression)){let s=r.get(e.expression.text);if(s?.kind==="whole")return{kind:"member",target:s.target,member:a}}return}if(c.isIdentifier(e))return r.get(e.text)}function Is(e,n,t,r,o){let i=[],a=!1,l=p=>{if(bs(p))return!0;let f=!1,h=g=>{f||(c.isIdentifier(g)&&o.has(g.text)?f=!0:c.forEachChild(g,h))};return h(p),f},s=(p,f)=>{let h=Ou(p,n,t,r);h!==void 0?i.push({source:h,exportedName:f}):l(p)&&(a=!0)},d=p=>{if(c.isObjectLiteralExpression(p)){for(let f of p.properties)if(c.isSpreadAssignment(f))s(f.expression,"default");else if(c.isPropertyAssignment(f)){let h=c.isIdentifier(f.name)||c.isStringLiteralLike(f.name)?f.name.text:"default";s(f.initializer,h)}else if(c.isShorthandPropertyAssignment(f)){let h=r.get(f.name.text);h!==void 0&&i.push({source:h,exportedName:f.name.text})}return}s(p,"default")},u=p=>{if(c.isBinaryExpression(p)&&p.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&p.operatorToken.kind<=c.SyntaxKind.LastAssignment){if($e(p.left)){d(p.right);return}if(qe(p.left)){let f=c.isPropertyAccessExpression(p.left)?p.left.name.text:c.isElementAccessExpression(p.left)&&c.isStringLiteralLike(p.left.argumentExpression)?p.left.argumentExpression.text:"default";s(p.right,f);return}}else if(c.isExportAssignment(p)&&p.isExportEquals){s(p.expression,"default");return}else if(c.isCallExpression(p)&&zn(p)&&p.arguments[0]!==void 0&&Nn(p.arguments[0])){for(let f of p.arguments.slice(1))d(f);return}c.forEachChild(p,u)};return u(e),{sources:i,residual:a}}function As(e){let n=new Set,t=o=>{let i=o;for(;c.isPropertyAccessExpression(i)||c.isElementAccessExpression(i);)i=i.expression;return c.isIdentifier(i)?i.text:void 0},r=o=>{let i=_s(o);if(i!==void 0){let a=t(i);a!==void 0&&n.add(a)}c.forEachChild(o,r)};return r(e),n}function _s(e){return c.isBinaryExpression(e)&&e.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&e.operatorToken.kind<=c.SyntaxKind.LastAssignment&&(c.isPropertyAccessExpression(e.left)||c.isElementAccessExpression(e.left))?e.left:void 0}function Bt(e){if(c.isIdentifier(e))return[e.text];let n=[];for(let t of e.elements)c.isBindingElement(t)&&n.push(...Bt(t.name));return n}function Pe(e){if(c.isIdentifier(e))return[e.text];if(c.isParenthesizedExpression(e)||c.isAsExpression(e)||c.isNonNullExpression(e)||c.isSatisfiesExpression(e)||c.isTypeAssertionExpression(e)||c.isAwaitExpression(e))return Pe(e.expression);if(c.isYieldExpression(e))return e.expression!==void 0?Pe(e.expression):[];if(c.isBinaryExpression(e)){let n=e.operatorToken.kind;return n===c.SyntaxKind.BarBarToken||n===c.SyntaxKind.AmpersandAmpersandToken||n===c.SyntaxKind.QuestionQuestionToken?[...Pe(e.left),...Pe(e.right)]:n===c.SyntaxKind.CommaToken?Pe(e.right):[]}return c.isConditionalExpression(e)?[...Pe(e.whenTrue),...Pe(e.whenFalse)]:c.isArrayLiteralExpression(e)?e.elements.flatMap(n=>c.isSpreadElement(n)?Pe(n.expression):c.isOmittedExpression(n)?[]:Pe(n)):c.isObjectLiteralExpression(e)?e.properties.flatMap(n=>c.isShorthandPropertyAssignment(n)?[n.name.text]:c.isPropertyAssignment(n)?Pe(n.initializer):c.isSpreadAssignment(n)?Pe(n.expression):[]):[]}function Ns(e,n){let t=[],r=(l,s)=>{for(let d of l)for(let u of s)d!==u&&t.push({a:d,b:u})},o=l=>c.isIdentifier(l)?[l.text]:c.isArrayLiteralExpression(l)?l.elements.flatMap(o):c.isObjectLiteralExpression(l)?l.properties.flatMap(s=>c.isShorthandPropertyAssignment(s)?[s.name.text]:c.isPropertyAssignment(s)?o(s.initializer):[]):[],i=l=>{c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken?r(o(l.left),Pe(l.right)):c.isVariableDeclaration(l)&&l.initializer!==void 0?r(Bt(l.name),Pe(l.initializer)):(c.isForOfStatement(l)||c.isForInStatement(l))&&c.isVariableDeclarationList(l.initializer)&&l.initializer.declarations[0]!==void 0&&r(Bt(l.initializer.declarations[0].name),Pe(l.expression)),c.forEachChild(l,i)};i(e);let a=new Set(n);for(let l=!0;l;){l=!1;for(let{a:s,b:d}of t)a.has(s)&&!a.has(d)&&(a.add(d),l=!0),a.has(d)&&!a.has(s)&&(a.add(s),l=!0)}return a}function Rs(e,n){let t=l=>{if(!c.isPropertyAccessExpression(l)&&!c.isElementAccessExpression(l))return;let s=l;for(;c.isPropertyAccessExpression(s)||c.isElementAccessExpression(s);)s=s.expression;return c.isIdentifier(s)?s.text:void 0},r=[],o=(l,s)=>{for(let u of Pe(s))r.push({name:l,root:u});let d=t(s);d!==void 0&&r.push({name:l,root:d})},i=l=>{c.isVariableDeclaration(l)&&c.isIdentifier(l.name)&&l.initializer!==void 0?o(l.name.text,l.initializer):c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isIdentifier(l.left)&&o(l.left.text,l.right),c.forEachChild(l,i)};i(e);let a=new Map(n);for(let l=!0;l;){l=!1;for(let{name:s,root:d}of r){let u=a.get(d);u!==void 0&&!a.has(s)&&(a.set(s,u),l=!0)}}return a}function Cs(e){return Ns(e,As(e))}function Pu(e,n){let t=s=>s>=c.SyntaxKind.FirstAssignment&&s<=c.SyntaxKind.LastAssignment,r=s=>{let d=s.parent;if(d===void 0||!c.isObjectLiteralExpression(d))return!1;let u=d.parent;return u!==void 0&&c.isBinaryExpression(u)&&u.operatorToken.kind===c.SyntaxKind.EqualsToken&&u.right===d&&qe(u.left)?!0:u!==void 0&&c.isCallExpression(u)&&zn(u)&&u.arguments[0]!==void 0&&Nn(u.arguments[0])&&u.arguments.indexOf(d)>0},o=(s,d)=>{if((c.isFunctionDeclaration(d)||c.isFunctionExpression(d))&&d.name===s||c.isVariableDeclaration(d)&&d.name===s||c.isParameter(d)&&d.name===s||c.isBindingElement(d)&&d.name===s||(c.isCallExpression(d)||c.isNewExpression(d))&&d.expression===s)return!0;if((c.isPropertyAccessExpression(d)||c.isElementAccessExpression(d))&&d.expression===s){let u=d;for(;u.parent!==void 0&&(c.isPropertyAccessExpression(u.parent)||c.isElementAccessExpression(u.parent))&&u.parent.expression===u;)u=u.parent;let p=u.parent;return!(p!==void 0&&c.isBinaryExpression(p)&&t(p.operatorToken.kind)&&p.left===u)}return c.isBinaryExpression(d)&&d.operatorToken.kind===c.SyntaxKind.EqualsToken&&d.right===s&&qe(d.left)?!0:c.isShorthandPropertyAssignment(d)&&d.name===s||c.isPropertyAssignment(d)&&d.initializer===s?r(d):!!(c.isExportAssignment(d)&&d.expression===s||c.isExportSpecifier(d))},i=(s,d)=>c.isPropertyAccessExpression(d)&&d.name===s||c.isPropertyAssignment(d)&&d.name===s||(c.isMethodDeclaration(d)||c.isGetAccessorDeclaration(d)||c.isSetAccessorDeclaration(d))&&d.name===s,a=!1,l=(s,d)=>{if(!a){if(c.isIdentifier(s)&&d!==void 0&&n.has(s.text)&&!i(s,d)&&!o(s,d)){a=!0;return}c.forEachChild(s,u=>l(u,s))}};return l(e,void 0),a}function $u(e){let n=new Set;for(let s of e.statements)if(c.isFunctionDeclaration(s)&&s.name!==void 0)n.add(s.name.text);else if(c.isVariableStatement(s))for(let d of s.declarationList.declarations)c.isIdentifier(d.name)&&d.initializer!==void 0&&(c.isFunctionExpression(d.initializer)||c.isArrowFunction(d.initializer))&&n.add(d.name.text);let t=new Set,r=s=>{c.isBinaryExpression(s)&&s.operatorToken.kind===c.SyntaxKind.EqualsToken?($e(s.left)&&(c.isIdentifier(s.right)?t.add(s.right.text):c.isObjectLiteralExpression(s.right)&&Es(s.right,t)),$e(s.right)&&c.isIdentifier(s.left)&&t.add(s.left.text)):c.isVariableDeclaration(s)&&c.isIdentifier(s.name)&&s.initializer!==void 0&&$e(s.initializer)&&t.add(s.name.text),c.forEachChild(s,r)};if(r(e),t.size>0){if(Pu(e,t))return!0;let s=Rs(e,new Map([...t].map(u=>[u,u]))),d=Cs(e);for(let u of s.keys())if(d.has(u))return!0}let o=s=>c.isIdentifier(s)&&n.has(s.text),i=s=>s.properties.every(d=>c.isShorthandPropertyAssignment(d)&&n.has(d.name.text)||c.isPropertyAssignment(d)&&o(d.initializer)),a=!1,l=s=>{if(!a){if(c.isBinaryExpression(s)){let d=s.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&s.operatorToken.kind<=c.SyntaxKind.LastAssignment;d&&$e(s.left)?s.operatorToken.kind===c.SyntaxKind.EqualsToken&&(o(s.right)||c.isObjectLiteralExpression(s.right)&&i(s.right))||(a=!0):d&&qe(s.left)&&(a=!0)}else c.isCallExpression(s)?(zn(s)&&s.arguments[0]!==void 0&&Nn(s.arguments[0])||Xr(s))&&(a=!0):(c.isExportAssignment(s)&&s.isExportEquals&&!c.isIdentifier(s.expression)||c.isExportDeclaration(s)&&s.moduleSpecifier!==void 0)&&(a=!0);a||c.forEachChild(s,l)}};return l(e),a}var Mu=8;function gs(e,n,t){let r=new Set,o=vs(e,n,t,Kn(e)),i=Is(e,n,t,o,ks(e));for(let{source:a}of i.sources)r.add(a.target);for(let a of e.statements)if(c.isExportDeclaration(a)&&a.moduleSpecifier!==void 0&&c.isStringLiteralLike(a.moduleSpecifier)&&ye(a.moduleSpecifier.text)==="relative"){let l=t.get(`${n}::${a.moduleSpecifier.text}`);l!==void 0&&r.add(l)}return r}function Du(e,n,t,r=new Map){let o=new Set(n.modules.filter(k=>k.isEntrypoint).map(k=>String(k.id)));if(o.size===0)return{exports:[],exportBindings:[],diagnostics:[]};let i=new Set(n.modules.filter(k=>k.externalSurface===!0).map(k=>String(k.id))),a=new Map,l=new Map,s=new Map,d=new Map;for(let k of t){if(k.name==="<toplevel>"){d.set(String(k.moduleId),k);continue}if(a.set(`${String(k.moduleId)}::${String(k.declRange.start)}`,k),k.name!==void 0&&l.set(`${String(k.moduleId)}::${k.name}`,k),k.isExported&&k.name!==void 0){let m=s.get(String(k.moduleId))??[];m.push(k),s.set(String(k.moduleId),m)}}if(r.size>0){let k=new Map(t.map(m=>[String(m.id),m]));for(let[m,y]of r){let A=k.get(String(y));A!==void 0&&!a.has(m)&&a.set(m,A)}}let u=new Map;for(let k of n.imports)k.resolvedModuleId!==void 0&&u.set(`${k.moduleId}::${k.specifier}`,String(k.resolvedModuleId));let p=new Map;for(let k of e.sourceFiles){let m=e.toRel(k.fileName);m!==null&&p.set(m,k)}let f=new Map,h=k=>{let m=f.get(k);if(m!==void 0)return m;let y=p.get(k),A=y===void 0?!0:$u(y);return f.set(k,A),A},g=new Set,S=(k,m)=>m!==void 0&&ye(m)==="relative"?u.get(`${k}::${m}`):void 0,E=k=>{if(c.isIdentifier(k))return k.text;if(c.isPropertyAccessExpression(k)){let m=E(k.expression);return m===void 0?void 0:`${m}.${k.name.text}`}if(c.isElementAccessExpression(k)&&c.isStringLiteralLike(k.argumentExpression)){let m=E(k.expression);return m===void 0?void 0:`${m}.${k.argumentExpression.text}`}},w=k=>{let m=k;for(;c.isPropertyAccessExpression(m)||c.isElementAccessExpression(m);)m=m.expression;return nn(m)};for(let k of e.sourceFiles){let m=e.toRel(k.fileName);if(m===null)continue;let y=new Map,A=new Map,C=(R,F)=>{let O=S(m,nn(F));if(O!==void 0){if(c.isIdentifier(R))A.set(R.text,O),y.set(R.text,O);else if(c.isObjectBindingPattern(R)||c.isArrayBindingPattern(R))for(let L of Bt(R))A.set(L,O);else if(c.isPropertyAccessExpression(R)||c.isElementAccessExpression(R)){let L=E(R);L!==void 0&&y.set(L,O)}}},T=R=>{c.isVariableDeclaration(R)&&R.initializer!==void 0?C(R.name,R.initializer):c.isBinaryExpression(R)&&R.operatorToken.kind===c.SyntaxKind.EqualsToken&&C(R.left,R.right),c.forEachChild(R,T)};T(k);let P=R=>{let F=_s(R);if(F!==void 0){let O=F.expression,L=S(m,w(O));L!==void 0&&g.add(L);let K=E(O),G=K!==void 0?y.get(K):void 0;G!==void 0&&g.add(G)}c.forEachChild(R,P)};if(P(k),A.size>0){let R=Rs(k,A),F=Cs(k);for(let[O,L]of R)F.has(O)&&g.add(L)}}let I=[],v=[],_=[];for(let k of e.sourceFiles){let m=e.toRel(k.fileName);if(m===null||!o.has(m))continue;let y=e.checker.getSymbolAtLocation(k),A=new Set,C=new Set,T=0,P=($,q)=>{if(i.has(String($.moduleId))||A.has(String($.id)))return;A.add(String($.id));let H=`${m}#reexport:${String(T)}:${q}`;T+=1,I.push({id:H,moduleId:m,exportedName:q,kind:"value",reexportOf:{moduleId:String($.moduleId),name:$.name??q}}),v.push({exportId:H,target:{kind:"function",functionId:$.id}})},R=$=>{if(bu($))return;let q=$;if(($.flags&c.SymbolFlags.Alias)!==0)try{q=e.checker.getAliasedSymbol($)}catch{return}let H=ku(q,e,a,l,i);if(H!==void 0){P(H,$.getName());return}if((q.flags&c.SymbolFlags.Module)!==0&&!C.has(q)){C.add(q);try{for(let Ee of e.checker.getExportsOfModule(q))R(Ee)}catch{}}};if(y!==void 0)for(let $ of e.checker.getExportsOfModule(y))R($);let F=vs(k,m,u,Kn(k)),O=Is(k,m,u,F,ks(k)),L=new Set,K=O.residual,G=$=>{let q=p.get($);$.includes("node_modules/")||q===void 0||xu(q)?K=!0:L.add($)};for(let{source:$,exportedName:q}of O.sources){let H=s.get($.target)??[],Ee=g.has($.target);if($.kind==="whole"){for(let he of H)P(he,he.name??q);Ee?K=!0:(H.length===0||h($.target))&&G($.target)}else{let he=H.filter(ve=>ve.name===$.member);for(let ve of he)P(ve,q);Ee?K=!0:(he.length===0||h($.target))&&G($.target)}}let B=new Set,W=[];for(let $ of gs(k,m,u))W.push({target:$,depth:1});for(;W.length>0;){let $=W.shift();if($===void 0)break;let{target:q,depth:H}=$;if(B.has(q)||H>Mu||(B.add(q),q.split("/").includes("node_modules")))continue;let Ee=p.get(q);if(Ee===void 0)continue;let he=d.get(q);he!==void 0&&!h(q)&&P(he,"<load>");for(let ve of gs(Ee,q,u))B.has(ve)||W.push({target:ve,depth:H+1})}Au(k,Kn(k))&&(K=!0);for(let $ of L)_.push({code:"unresolved-reexport",path:m,detail:`entrypoint whole/member re-exports app-owned relative module ${$} whose exact entry surface could not be lifted; capping at unknown, corridor-scoped to that module (ADR-024, ROADMAP R3.3)`,anchor:$});K&&_.push({code:"unresolved-reexport",path:m,detail:"entrypoint has a CJS re-export the analyzer cannot pin to concrete relative functions (computed/dynamic/package-subpath/tainted, or an externally-mutated barrel); capping at unknown, globally (ADR-024, ROADMAP CJS.5)"})}return{exports:I,exportBindings:v,diagnostics:_}}var Bn=new Set(["valueOf","toString","toJSON","then","catch","finally","next","return","throw"]),Tu=new Set(["defineProperty","defineProperties","create"]);function Lu(e){let n=!0,t=o=>c.isIdentifier(o)||c.isStringLiteral(o)||c.isNumericLiteral(o)?Bn.has(o.text):c.isComputedPropertyName(o)&&c.isStringLiteralLike(o.expression)?Bn.has(o.expression.text):!1,r=o=>{if(n){if(c.isNewExpression(o)||c.isForOfStatement(o)||c.isSpreadElement(o)||c.isSpreadAssignment(o)||c.isArrayBindingPattern(o)||c.isGetAccessorDeclaration(o)||c.isSetAccessorDeclaration(o)||c.isYieldExpression(o)&&o.asteriskToken!==void 0||c.canHaveDecorators(o)&&(c.getDecorators(o)?.length??0)>0){n=!1;return}if((c.isPropertyAccessExpression(o)||c.isMethodDeclaration(o)||c.isPropertyAssignment(o))&&t(o.name)||c.isPropertyDeclaration(o)&&t(o.name)||c.isShorthandPropertyAssignment(o)&&t(o.name)||c.isBindingElement(o)&&t(o.propertyName??o.name)||c.isElementAccessExpression(o)&&c.isStringLiteralLike(o.argumentExpression)&&Bn.has(o.argumentExpression.text)){n=!1;return}if(c.isCallExpression(o)&&c.isPropertyAccessExpression(o.expression)&&c.isIdentifier(o.expression.expression)&&o.expression.expression.text==="Object"&&Tu.has(o.expression.name.text)){n=!1;return}c.forEachChild(o,r)}};return r(e),n}function Vt(e){if(c.isIdentifier(e)||c.isStringLiteral(e)||c.isNumericLiteral(e))return e.text}function Os(e){let n=t=>c.canHaveDecorators(t)&&(c.getDecorators(t)?.length??0)>0;return n(e)||e.members.some(n)}function Fu(e){let n=!1,t=new Set,r=[],o=new Map,i=(f,h)=>{let g=o.get(f);g===void 0?o.set(f,[h]):g.push(h)},a=f=>{c.isIdentifier(f)?t.add(f.text):r.push(f)},l=f=>{for(let h of f.properties)c.isShorthandPropertyAssignment(h)?t.add(h.name.text):c.isPropertyAssignment(h)?r.push(h.initializer):n=!0},s=f=>{if(c.isBinaryExpression(f)&&f.operatorToken.kind===c.SyntaxKind.EqualsToken){let h=f.left,g=f.right;$e(h)?c.isObjectLiteralExpression(g)?l(g):c.isIdentifier(g)||c.isFunctionExpression(g)||c.isArrowFunction(g)||c.isClassExpression(g)?a(g):n=!0:qe(h)?(c.isElementAccessExpression(h)&&!c.isStringLiteralLike(h.argumentExpression)&&(n=!0),a(g)):c.isIdentifier(h)?i(h.text,g):(c.isPropertyAccessExpression(h)||c.isElementAccessExpression(h))&&c.isIdentifier(h.expression)&&i(h.expression.text,g)}else if(c.isCallExpression(f))(zn(f)&&f.arguments[0]!==void 0&&Nn(f.arguments[0])||Xr(f))&&(n=!0);else if(c.isVariableDeclaration(f)&&c.isIdentifier(f.name)&&f.initializer!==void 0)i(f.name.text,f.initializer);else if((c.isFunctionDeclaration(f)||c.isClassDeclaration(f))&&f.name!==void 0)i(f.name.text,f),_n(f)&&t.add(f.name.text);else if(c.isExportDeclaration(f)){if(f.exportClause===void 0)n=!0;else if(f.moduleSpecifier===void 0&&c.isNamedExports(f.exportClause))for(let h of f.exportClause.elements)t.add((h.propertyName??h.name).text)}else if(c.isExportAssignment(f))f.isExportEquals&&!c.isIdentifier(f.expression)?n=!0:a(f.expression);else if(c.isVariableStatement(f)&&_n(f))for(let h of f.declarationList.declarations)c.isIdentifier(h.name)&&t.add(h.name.text);c.forEachChild(f,s)};s(e);let d=new Set,u=[...t],p=f=>{let h=g=>{c.isIdentifier(g)&&u.push(g.text),c.forEachChild(g,h)};h(f)};for(let f of r)p(f);for(;u.length>0;){let f=u.pop();if(!(f===void 0||d.has(f))){d.add(f);for(let h of o.get(f)??[])p(h)}}return{names:d,opaque:n}}var ju=512,Ku=new Set(["get","post","put","patch","delete","options","head"]);function Bu(e){for(let n of e.statements){if(c.isExportAssignment(n)&&n.isExportEquals!==!0)return n.expression;if(c.isExpressionStatement(n)&&c.isBinaryExpression(n.expression)&&n.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(n.expression.left)&&c.isIdentifier(n.expression.left.expression)){let t=n.expression.left.expression.text,r=n.expression.left.name.text;if(t==="module"&&r==="exports"||t==="exports"&&r==="default")return n.expression.right}}return null}function zu(e){let n=new Map,t=Bu(e);if(t===null)return n;let r=i=>{for(let a of i.properties)if(c.isPropertyAssignment(a)&&c.isObjectLiteralExpression(a.initializer)){let l=Vt(a.name);l!==void 0&&n.set(l,a.initializer)}};if(c.isObjectLiteralExpression(t))return r(t),n;if(!c.isIdentifier(t))return n;let o=t.text;for(let i of e.statements)if(c.isVariableStatement(i))for(let a of i.declarationList.declarations)c.isIdentifier(a.name)&&a.name.text===o&&a.initializer!==void 0&&c.isObjectLiteralExpression(a.initializer)&&r(a.initializer);else if(c.isExpressionStatement(i)&&c.isBinaryExpression(i.expression)&&i.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(i.expression.left)&&c.isIdentifier(i.expression.left.expression)&&i.expression.left.expression.text===o&&c.isObjectLiteralExpression(i.expression.right)){let a=i.expression.left.name.text;n.set(a,i.expression.right)}return n}function Uu(e){for(let n of e.properties){if(c.isMethodDeclaration(n)&&c.isIdentifier(n.name)&&n.name.text==="handler")return n;if(c.isPropertyAssignment(n)&&c.isIdentifier(n.name)&&n.name.text==="handler"&&(c.isArrowFunction(n.initializer)||c.isFunctionExpression(n.initializer)))return n.initializer}return null}function Vu(e,n){for(let r of e.properties){let o;if(c.isPropertyAssignment(r)||c.isMethodDeclaration(r)?o=Vt(r.name):c.isShorthandPropertyAssignment(r)&&(o=r.name.text),o==="method"||o==="url"||o==="middlewares")return!0}let t=n.parameters.length;return t>=2&&t<=3}function Wu(e,n){let t=[],r=new Set,o=(l,s,d)=>{if(t.length>=ju||l==="__proto__"||!Yr.test(l))return;let u=`${e}#handler:${l}`;r.has(u)||(r.add(u),t.push({id:u,node:s,memberPath:l,idiom:d}))};for(let[l,s]of zu(n)){let d=Uu(s);d!==null&&Vu(s,d)&&o(l,d,"descriptor-object")}let i=0,a=l=>{if(c.isCallExpression(l)&&c.isPropertyAccessExpression(l.expression)&&c.isIdentifier(l.expression.expression)&&Ku.has(l.expression.name.text)&&l.arguments.length>=2&&l.arguments[0]!==void 0&&c.isStringLiteralLike(l.arguments[0])){let s=l.expression.name.text;for(let d=1;d<l.arguments.length;d+=1){let u=l.arguments[d];u!==void 0&&(c.isArrowFunction(u)||c.isFunctionExpression(u))&&o(`${s}_${String(i)}_${String(d)}`,u,"router-verb")}i+=1}c.forEachChild(l,a)};return a(n),t}function qu(e,n,t,r,o,i){let a=`${e}#class:${t}`,l=[],s=new Set;for(let d of r.members){let u,p,f;if(c.isConstructorDeclaration(d))u="constructor",p="ctor",f=!1;else if(c.isMethodDeclaration(d))u=Vt(d.name),p="method",f=u!==void 0&&!Bn.has(u);else continue;if(u===void 0||s.has(u))continue;s.add(u);let h=`${e}#${t}.${u}`;o.push({id:h,moduleId:e,name:u,kind:p,enclosingClassId:a,declRange:gn(e,d,n),isExported:!1,publicSurfaceReachable:!1}),l.push(h),f&&i.push({start:d.getStart(n,!1),end:d.getEnd(),id:h})}return{id:a,moduleId:e,name:t,implementsRefs:[],members:l}}function Gu(e,n,t=[],r=!1,o){let i=[],a=new Map,l=[],{reachableLocals:s,defaultTarget:d}=gu(n),u=Kn(n),p=`${e}#<toplevel>`;i.push({id:p,moduleId:e,name:"<toplevel>",kind:"function",declRange:{path:e,start:0,end:n.getEnd()},isExported:!1,publicSurfaceReachable:!1});let f=(m,y)=>{let A=`${e}#${m}`;return i.push({id:A,moduleId:e,name:m,kind:"function",declRange:gn(e,y,n),isExported:s.has(m),publicSurfaceReachable:s.has(m)}),a.set(m,{kind:"function",functionId:A}),l.push({start:y.getStart(n,!1),end:y.getEnd(),id:A}),A},h=[],g=!e.split("/").includes("node_modules");if(g)for(let m of Iu(n,u))s.add(m);let S=g?Fu(n):void 0,E=(m,y,A)=>{S===void 0||S.opaque||S.names.has(m)||_n(A)||Os(y)||h.push(qu(e,n,m,y,i,l))};for(let m of n.statements)if(c.isFunctionDeclaration(m)&&m.name!==void 0)f(m.name.text,m);else if(c.isClassDeclaration(m)&&m.name!==void 0)E(m.name.text,m,m);else if(c.isVariableStatement(m))for(let y of m.declarationList.declarations){if(c.isObjectBindingPattern(y.name)&&y.initializer!==void 0&&c.isCallExpression(y.initializer)&&c.isIdentifier(y.initializer.expression)&&y.initializer.expression.text==="require"&&y.initializer.arguments.length===1&&y.initializer.arguments[0]!==void 0&&c.isStringLiteralLike(y.initializer.arguments[0])){let C=y.initializer.arguments[0].text;for(let T of y.name.elements){if(T.dotDotDotToken!==void 0||T.initializer!==void 0||!c.isIdentifier(T.name))continue;let P=T.propertyName??T.name;!c.isIdentifier(P)&&!c.isStringLiteralLike(P)||a.set(T.name.text,{kind:"import",specifier:C,form:{named:P.text}})}continue}if(!c.isIdentifier(y.name)||y.initializer===void 0)continue;let A=y.initializer;if(c.isFunctionExpression(A)||c.isArrowFunction(A))f(y.name.text,y);else if(c.isClassExpression(A))E(y.name.text,A,m);else if(c.isCallExpression(A)&&c.isIdentifier(A.expression)&&A.expression.text==="require"&&A.arguments.length===1&&A.arguments[0]!==void 0&&c.isStringLiteralLike(A.arguments[0]))a.set(y.name.text,{kind:"import",specifier:A.arguments[0].text,form:"whole"});else if((c.isPropertyAccessExpression(A)||c.isElementAccessExpression(A))&&Ut(A)==="default"&&c.isCallExpression(A.expression)){let C=nn(A.expression);C!==void 0&&a.set(y.name.text,{kind:"import",specifier:C,form:"require-default"})}}else if(c.isImportDeclaration(m)&&c.isStringLiteralLike(m.moduleSpecifier)){let y=m.moduleSpecifier.text,A=m.importClause;if(A!==void 0){A.name!==void 0&&a.set(A.name.text,{kind:"import",specifier:y,form:"default"});let C=A.namedBindings;if(C!==void 0&&c.isNamespaceImport(C))a.set(C.name.text,{kind:"import",specifier:y,form:"namespace"});else if(C!==void 0&&c.isNamedImports(C))for(let T of C.elements){let P=(T.propertyName??T.name).text;a.set(T.name.text,{kind:"import",specifier:y,form:{named:P}})}}}else c.isImportEqualsDeclaration(m)&&c.isExternalModuleReference(m.moduleReference)&&c.isStringLiteralLike(m.moduleReference.expression)&&a.set(m.name.text,{kind:"import",specifier:m.moduleReference.expression.text,form:"whole"});let w=new Map,I,v=new Map,_=new Map;if(g)for(let{name:m,value:y}of vu(n)){let A=`${e}#member-export:${m}`;i.push({id:A,moduleId:e,name:m,kind:c.isArrowFunction(y)?"arrow":"function",declRange:gn(e,y,n),isExported:!0,publicSurfaceReachable:!0}),l.push({start:y.getStart(n,!1),end:y.getEnd(),id:A}),w.set(y.getStart(n,!1),A)}if(r&&g){let m=P=>{let R=De(P);return c.isFunctionExpression(R)||c.isArrowFunction(R)?R:void 0},y=(P,R)=>{let F=P;return i.push({id:F,moduleId:e,kind:c.isArrowFunction(R)?"arrow":"function",declRange:gn(e,R,n),isExported:!0,publicSurfaceReachable:!0}),l.push({start:R.getStart(n,!1),end:R.getEnd(),id:F}),w.set(R.getStart(n,!1),F),F},A=[],C=[],T=[];for(let P of n.statements)c.isExportAssignment(P)&&!P.isExportEquals?A.push(P):c.isFunctionDeclaration(P)&&c.getModifiers(P)?.some(R=>R.kind===c.SyntaxKind.DefaultKeyword)===!0?C.push(P):c.isExpressionStatement(P)&&c.isBinaryExpression(P.expression)&&P.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&$e(P.expression.left)&&T.push(P.expression);if(A.length+C.length+T.length===1){let P=A[0],R=C[0],F=T[0];if(P!==void 0){let O=m(P.expression);if(O!==void 0){let L=y(`${e}#<default>`,O);I={id:L,esm:!0},_.set(P.getStart(n,!1),L),le(o,"2a-default",null)}}else if(R!==void 0&&R.name===void 0&&R.body!==void 0){let O=y(`${e}#<default>`,R);I={id:O,esm:!0},_.set(R.getStart(n,!1),O),le(o,"2a-default",null)}else if(F!==void 0){let O=m(F.right);if(O!==void 0){let L=y(`${e}#<default>`,O);I={id:L,esm:!1},_.set(F.getStart(n,!1),L),le(o,"2a-default",null)}else if(c.isObjectLiteralExpression(F.right)){let L=F.right,K=[],G=!0;for(let B of L.properties){if(c.isSpreadAssignment(B)){G=!1;break}let W=B.name,$=W===void 0?void 0:Gr(W);if($===void 0){G=!1;break}K.push($)}if(G){let B=new Map;for(let W of K)B.set(W,(B.get(W)??0)+1);for(let W of L.properties){if(!c.isPropertyAssignment(W))continue;let $=Gr(W.name),q=m(W.initializer);if($!==void 0){if(!Eu($)){q!==void 0&&le(o,"2a-member","charset-refused");continue}if((B.get($)??0)!==1){q!==void 0&&le(o,"2a-member","duplicate-key");continue}if(q!==void 0){let H=y(`${e}#<cjs>.${$}`,q);v.set($,H),_.set(W.getStart(n,!1),H),le(o,"2a-member",null)}}}}else for(let B of L.properties)c.isPropertyAssignment(B)&&m(B.initializer)!==void 0&&le(o,"2a-member","spread-or-computed-literal")}}}else{for(let P of A)m(P.expression)!==void 0&&le(o,"2a-default","duplicate-default-sources");for(let P of C)P.name===void 0&&le(o,"2a-default","duplicate-default-sources");for(let P of T)if(m(P.right)!==void 0)le(o,"2a-default","duplicate-default-sources");else if(c.isObjectLiteralExpression(P.right))for(let R of P.right.properties)c.isPropertyAssignment(R)&&m(R.initializer)!==void 0&&le(o,"2a-member","duplicate-default-sources")}}for(let m of t)i.push({id:m.id,moduleId:e,name:`handler:${m.memberPath}`,kind:c.isArrowFunction(m.node)?"arrow":"function",declRange:gn(e,m.node,n),isExported:!1,publicSurfaceReachable:!1}),l.push({start:m.node.getStart(n,!1),end:m.node.getEnd(),id:m.id});l.sort((m,y)=>m.end-m.start-(y.end-y.start));let k=d!==void 0?`${e}#${d}`:void 0;return{rel:e,sf:n,functions:i,bindings:a,exportedFunctionId:k,exportedNames:s,tainted:u,fnRanges:l,toplevelId:p,classes:h,mintedByPos:w,mintedDefault:I,mintedMembers:v,mintSeedAliases:_}}function Hu(e){return c.isIdentifier(e)?"identifier":c.isPropertyAccessExpression(e)?"member":c.isElementAccessExpression(e)?"computed-member":e.kind===c.SyntaxKind.ImportKeyword?"dynamic-import":"unknown"}function ys(e,n){let t=r=>{if(c.isBinaryExpression(r)&&r.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&r.operatorToken.kind<=c.SyntaxKind.LastAssignment){let o=r.left;c.isPropertyAccessExpression(o)&&c.isIdentifier(o.expression)?n(o.expression.text,o.name.text):c.isElementAccessExpression(o)&&c.isIdentifier(o.expression)&&n(o.expression.text,c.isStringLiteralLike(o.argumentExpression)?o.argumentExpression.text:null)}else if(c.isCallExpression(r)&&c.isPropertyAccessExpression(r.expression)){let o=r.expression,i=r.arguments[0];c.isIdentifier(o.expression)&&i!==void 0&&c.isIdentifier(i)&&(o.expression.text==="Object"&&(o.name.text==="assign"||o.name.text==="defineProperty"||o.name.text==="defineProperties")||o.expression.text==="Reflect"&&o.name.text==="defineProperty")&&n(i.text,null)}c.forEachChild(r,t)};t(e)}function Xu(e){let n=!1,t=r=>{if(!n){if(c.isVariableDeclaration(r)||c.isParameter(r)){let o=new Set;if(nt(r.name,o),o.has("require")){n=!0;return}}else if((c.isFunctionDeclaration(r)||c.isClassDeclaration(r))&&r.name!==void 0&&r.name.text==="require"){n=!0;return}c.forEachChild(r,t)}};return t(e),n}function Yu(e,n,t,r=new Map,o={}){let i=o.additiveForms===!0,a=o.namelessExports===!0,l=i||a?{}:void 0,s=new Map,d=new Map;for(let m of n.imports)m.resolvedModuleId!==void 0&&d.set(`${m.moduleId}::${m.specifier}`,m.resolvedModuleId);for(let m of e.sourceFiles){let y=e.toRel(m.fileName);y!==null&&s.set(y,Gu(y,m,r.get(y)??[],a,l))}let u=new Map;if(i)for(let m of s.values()){let y=new Map;for(let[A,C]of m.bindings)if(C.kind==="import"&&C.form==="whole"&&ye(C.specifier)!=="package-root"){let T=d.get(`${m.rel}::${C.specifier}`);T!==void 0&&y.set(A,String(T))}y.size!==0&&ys(m.sf,(A,C)=>{let T=y.get(A);if(T===void 0)return;let P=u.get(T);if(P!=="*"){if(C===null){u.set(T,"*");return}P===void 0?u.set(T,new Set([C])):P.add(C)}})}let p=new Map;for(let m of s.values())m.exportedFunctionId!==void 0&&p.set(m.rel,m.exportedFunctionId);let f=new Map;for(let m of s.values()){if(m.rel.split("/").includes("node_modules"))continue;let y=yu(m.sf);if(y===void 0){a&&m.mintedDefault!==void 0&&f.set(m.rel,m.mintedDefault);continue}let A=m.bindings.get(y.name);A?.kind==="function"&&f.set(m.rel,{id:A.functionId,esm:y.esm})}let h=new Map;for(let m of s.values()){let y;for(let A of m.exportedNames){let C=m.bindings.get(A);C?.kind==="function"&&(y??=new Map,y.set(A,C.functionId))}y!==void 0&&h.set(m.rel,y)}let g=new Map;for(let m of s.values()){if(m.rel.split("/").includes("node_modules"))continue;let y=Cu(m.sf,m.tainted,A=>{let C=m.bindings.get(A);return C?.kind==="function"?C.functionId:void 0},a?A=>{let C=De(A);return c.isFunctionExpression(C)||c.isArrowFunction(C)?m.mintedByPos.get(C.getStart(m.sf,!1)):void 0}:void 0);y.size>0&&g.set(m.rel,y)}let S=[],E=[],w=[],I=[],v=[],_=[];for(let m of s.values()){S.push(...m.functions),_.push(...m.classes);for(let x of m.exportedNames){let N=m.bindings.get(x);if(N?.kind==="function"){let D=`${m.rel}#export:${x}`;I.push({id:D,moduleId:m.rel,exportedName:x,kind:"value"}),v.push({exportId:D,target:{kind:"function",functionId:N.functionId}})}}if(a){if(m.mintedDefault!==void 0){let x=`${m.rel}#export:<default>`;I.push({id:x,moduleId:m.rel,exportedName:"default",kind:"value"}),v.push({exportId:x,target:{kind:"function",functionId:m.mintedDefault.id}})}for(let[x,N]of m.mintedMembers){let D=`${m.rel}#export:<cjs>.${x}`;I.push({id:D,moduleId:m.rel,exportedName:x,kind:"value"}),v.push({exportId:D,target:{kind:"function",functionId:N}})}}let y=new Map;for(let[x,N]of m.bindings){if(N.kind==="function"){y.set(x,N);continue}if(ye(N.specifier)==="package-root"){let j=je(N.specifier);typeof N.form=="object"?y.set(x,{kind:"package-export",packageName:j,exportName:N.form.named}):N.form==="require-default"?y.set(x,{kind:"package-default",packageName:j}):y.set(x,{kind:"package-surface",packageName:j})}else{let j=d.get(`${m.rel}::${N.specifier}`);if(j!==void 0&&typeof N.form=="object"){let Y=h.get(String(j))?.get(N.form.named);Y!==void 0&&y.set(x,{kind:"app-named-fn",functionId:Y})}else if(j!==void 0&&N.form==="require-default"){let Y=f.get(String(j));Y!==void 0&&Y.esm&&y.set(x,{kind:"app-default-fn",functionId:Y.id})}else j!==void 0&&typeof N.form!="object"&&N.form!=="require-default"&&y.set(x,{kind:"module",resolvedModuleId:j})}}let A=new Map;for(let x of m.functions){if(x.enclosingClassId===void 0||x.name===void 0)continue;let N=A.get(x.enclosingClassId);N===void 0&&(N=new Map,A.set(x.enclosingClassId,N)),N.set(x.name,x.id)}for(let x of m.classes)x.name===void 0||m.tainted.has(x.name)||y.has(x.name)||y.set(x.name,{kind:"app-class",cls:{classId:x.id,className:x.name,memberIds:A.get(x.id)??new Map}});let C=x=>{if(c.isVariableDeclaration(x)&&c.isIdentifier(x.name)&&x.initializer!==void 0&&c.isNewExpression(x.initializer)&&!m.tainted.has(x.name.text)&&!y.has(x.name.text)){let N=us(x.initializer,y,m.tainted);N!==null&&y.set(x.name.text,N)}c.forEachChild(x,C)};C(m.sf);let T=x=>{for(let N of m.fnRanges)if(x>=N.start&&x<N.end)return N.id;return m.toplevelId},P=new Map,R=new Map,F=new Map,O=(x,N,D)=>{if(D===null){x.set(N,"*");return}let j=x.get(N);j!=="*"&&(j===void 0?x.set(N,new Set([D])):j.add(D))},L=(x,N)=>{O(P,x,N);let D=y.get(x);D?.kind==="package-surface"?O(R,D.packageName,N):D?.kind==="module"&&O(F,String(D.resolvedModuleId),N)};ys(m.sf,L);let K=new Map,G=256,B=x=>{let N=K.get(x);return N===void 0&&(N=K.size>=G?new Set([x]):Ns(m.sf,new Set([x])),K.set(x,N)),N},W=(x,N)=>x==="*"||x!==void 0&&x.has(N),$=(x,N)=>{let D=y.get(x);if(D?.kind==="package-surface"&&W(R.get(D.packageName),N)||D?.kind==="module"&&W(F.get(String(D.resolvedModuleId)),N))return!0;for(let j of B(x))if(W(P.get(j),N))return!0;return!1},q=x=>{if(c.isIdentifier(x)){let N=m.tainted.has(x.text)?void 0:y.get(x.text);return N?.kind==="function"?N.functionId:N?.kind==="module"?p.get(String(N.resolvedModuleId))??null:N?.kind==="package-export"?t.exportFor(N.packageName,N.exportName):null}if(c.isPropertyAccessExpression(x)&&c.isIdentifier(x.expression)){let N=x.expression.text;if($(N,x.name.text))return null;let D=m.tainted.has(N)?void 0:y.get(N);return D?.kind==="package-surface"?t.exportFor(D.packageName,x.name.text):D?.kind==="package-export"?t.methodFor(D.packageName,D.exportName,x.name.text,"method"):D?.kind==="package-instance"?t.methodFor(D.packageName,D.className,x.name.text,"method"):null}return null},H=x=>{for(let N=x.parent;N!==void 0;N=N.parent)if(!c.isArrowFunction(N)){if(c.isFunctionExpression(N)||c.isFunctionDeclaration(N))return null;if(c.isMethodDeclaration(N)||c.isConstructorDeclaration(N)||c.isGetAccessorDeclaration(N)||c.isSetAccessorDeclaration(N)){let D=N.parent;if(!c.isClassLike(D)||D.name===void 0)return null;let j=m.tainted.has(D.name.text)?void 0:y.get(D.name.text);return j?.kind==="app-class"?j.cls:null}}return null},Ee=i&&!m.tainted.has("require")&&!Xu(m.sf),he=x=>{if(c.isIdentifier(x)){let j=m.tainted.has(x.text)?void 0:y.get(x.text);return j?.kind==="package-surface"||j?.kind==="package-default"?t.exportFor(j.packageName,"default"):j?.kind==="app-named-fn"||j?.kind==="app-default-fn"?j.functionId:j?.kind==="module"?f.get(String(j.resolvedModuleId))?.id??null:j?.kind==="member-value"?j.functionId:null}if(!c.isPropertyAccessExpression(x))return null;let N=x.expression;if(i&&c.isCallExpression(De(N))){let j=nn(De(N));if(j!==void 0)if(!Ee)le(l,"2b","require-shadow");else if(ye(j)==="package-root")le(l,"2b","package-root");else{let Y=d.get(`${m.rel}::${j}`);if(Y===void 0)le(l,"2b","unresolved-module");else{let Z=x.name.text,te=u.get(String(Y));if(te==="*"||te!==void 0&&te.has(Z))le(l,"2b","module-mutation-gate");else{let ue=g.get(String(Y))?.get(Z);if(ue!==void 0)return le(l,"2b",null),ue;if(Z==="default"){let de=f.get(String(Y));if(de!==void 0&&de.esm)return le(l,"2b",null),de.id;le(l,"2b","non-esm-default")}else le(l,"2b","unknown-member")}}}return null}let D;if(c.isIdentifier(N)){let j=m.tainted.has(N.text)?void 0:y.get(N.text);if(j?.kind==="app-class"||j?.kind==="app-instance")D=j.cls.memberIds;else if(j?.kind==="object-literal")D=j.obj.members;else if(j?.kind==="module"){let Y=g.get(String(j.resolvedModuleId));Y?.has(x.name.text)===!0&&!$(N.text,x.name.text)&&(D=Y)}}else if(c.isNewExpression(N)){let j=us(N,y,m.tainted);j?.kind==="app-instance"&&(D=j.cls.memberIds)}else N.kind===c.SyntaxKind.ThisKeyword&&(D=H(x)?.memberIds);return D?.get(x.name.text)??null},ve=new Map,Sn=x=>{if(c.isVariableDeclaration(x)&&c.isIdentifier(x.name)&&x.initializer!==void 0&&c.isObjectLiteralExpression(x.initializer)&&!m.tainted.has(x.name.text)&&!y.has(x.name.text)&&!ve.has(x.name.text)){let N=new Map;for(let D of x.initializer.properties)if(c.isPropertyAssignment(D)&&c.isIdentifier(D.name)){let j=q(D.initializer);j!==null&&N.set(D.name.text,j)}ve.set(x.name.text,N)}c.forEachChild(x,Sn)};Sn(m.sf);let Gn=x=>{if(c.isBinaryExpression(x)&&x.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(x.left)&&c.isIdentifier(x.left.expression)&&!m.tainted.has(x.left.expression.text)){let N=ve.get(x.left.expression.text);if(N!==void 0){let D=q(x.right);D!==null&&N.set(x.left.name.text,D)}}c.forEachChild(x,Gn)};Gn(m.sf);for(let[x,N]of ve)y.set(x,{kind:"object-literal",obj:{members:N}});let M=(x,N=0)=>{if(N>ds)return null;let D=De(x);if(c.isCallExpression(D)&&c.isPropertyAccessExpression(D.expression)&&D.expression.name.text==="bind")return M(D.expression.expression,N+1);if(c.isIdentifier(D)){let j=q(D);if(j!==null)return j;let Y=m.tainted.has(D.text)?void 0:y.get(D.text);return Y?.kind==="member-value"?Y.functionId:null}return c.isPropertyAccessExpression(D)?q(D)??he(D):null},J=(x,N=0)=>{if(N>ds)return"depth-cap";let D=De(x);if(c.isCallExpression(D)&&c.isPropertyAccessExpression(D.expression)&&D.expression.name.text==="bind")return J(D.expression.expression,N+1);if(c.isIdentifier(D))return m.tainted.has(D.text)?"tainted-receiver":"unresolved-receiver";if(c.isPropertyAccessExpression(D)&&c.isIdentifier(D.expression)){if(m.tainted.has(D.expression.text))return"tainted-receiver";if($(D.expression.text,D.name.text))return"mutated-member"}return"unresolved-receiver"},oe=x=>{if(c.isVariableDeclaration(x)&&c.isIdentifier(x.name)&&x.initializer!==void 0){let N=De(x.initializer),D=c.isPropertyAccessExpression(N),j=c.isCallExpression(N)&&c.isPropertyAccessExpression(N.expression)&&N.expression.name.text==="bind";if(D||j){let Y=D?"D1":"A2";if(m.tainted.has(x.name.text))le(l,Y,"tainted-alias");else if(y.has(x.name.text))le(l,Y,"already-bound");else{let Z=M(N);Z!==null?(y.set(x.name.text,{kind:"member-value",functionId:Z}),le(l,Y,null)):le(l,Y,J(N))}}}c.forEachChild(x,oe)};i&&oe(m.sf);let ie=0,rn=x=>{let N,D;if(c.isCallExpression(x)){let j=x.expression,Y=c.isIdentifier(j)&&j.text==="require",Z=j.kind===c.SyntaxKind.ImportKeyword;!Y&&!Z&&(N=j,D=x.arguments)}else c.isTaggedTemplateExpression(x)&&(N=x.tag);if(N!==void 0){let j=Hu(N),Y=x.getStart(m.sf,!1),Z=`${m.rel}#call${String(ie)}`;ie+=1;let te="unresolved",ue=[],de=q(N);de!==null&&(te="resolved",ue.push(de)),E.push({id:Z,enclosingFunctionId:T(Y),calleeExprShape:j,resolvedTargetIds:ue,resolution:te,range:gn(m.rel,x,m.sf)});for(let fe of ue)w.push({callSiteId:Z,calleeFunctionId:fe,resolution:te});if(de===null){let fe=he(N);if(fe!==null)w.push({callSiteId:Z,calleeFunctionId:fe,resolution:"field-based"});else if(i&&c.isPropertyAccessExpression(N)&&(N.name.text==="call"||N.name.text==="apply")){let ne=M(N.expression);ne!==null?(w.push({callSiteId:Z,calleeFunctionId:ne,resolution:"field-based"}),le(l,"A3",null)):le(l,"A3",J(N.expression))}}for(let fe of D??[]){let ne=q(fe);if(ne!==null)w.push({callSiteId:Z,calleeFunctionId:ne,resolution:"field-based"});else{let on=he(fe);if(on!==null)w.push({callSiteId:Z,calleeFunctionId:on,resolution:"field-based"});else if(i){let sn=M(fe),Le=De(fe),ce=Le!==fe||c.isCallExpression(Le)&&c.isPropertyAccessExpression(Le.expression)&&Le.expression.name.text==="bind";sn!==null?(w.push({callSiteId:Z,calleeFunctionId:sn,resolution:"field-based"}),ce&&le(l,"A2p",null)):ce&&le(l,"A2p",J(fe))}}}}c.forEachChild(x,rn)};rn(m.sf);for(let x of n.computedLoads.get(m.rel)??[]){let N=x.candidateRels.filter(j=>s.has(j)).map(j=>`${j}#<toplevel>`);if(N.length===0)continue;let D=`${m.rel}#dirload${String(ie)}`;ie+=1,E.push({id:D,enclosingFunctionId:T(x.pos),calleeExprShape:"require",resolvedTargetIds:N,resolution:"field-based",range:{path:m.rel,start:x.pos,end:x.pos}});for(let j of N)w.push({callSiteId:D,calleeFunctionId:j,resolution:"field-based"})}let bn=0;for(let x of r.get(m.rel)??[]){let N=`${m.rel}#handlerseed${String(bn)}`;bn+=1;let D=x.node.getStart(m.sf,!1);E.push({id:N,enclosingFunctionId:m.toplevelId,calleeExprShape:"member",resolvedTargetIds:[x.id],resolution:"field-based",range:{path:m.rel,start:D,end:D}}),w.push({callSiteId:N,calleeFunctionId:x.id,resolution:"field-based"})}}let k=new Map;if(a)for(let m of s.values())for(let[y,A]of m.mintSeedAliases)k.set(`${m.rel}::${String(y)}`,A);return{functions:S,callSites:E,callEdges:w,exports:I,exportBindings:v,classes:_,mintSeedAliases:k,bindingApplicability:l}}function Ju(e,n,t){let r=s=>s.length===0||Te.isAbsolute(s)||s.includes("\\")||/^[a-zA-Z]:/u.test(s)||s.split("/").some(d=>d===".."||d==="");if(r(n)||r(t))return null;let o=e.endsWith(Te.sep)?e:e+Te.sep,i;try{i=ls(Te.resolve(e,n))}catch{return null}if(!i.startsWith(o))return null;let a=i.endsWith(Te.sep)?i:i+Te.sep,l;try{l=ls(Te.resolve(i,t))}catch{return null}return l.startsWith(a)?l:null}function Ps(e,n,t){let r=`${e}#class:${t}`,o=[],i=[],a=[],l=new Set;return{pushMember(s,d,u,p){if(s==="__proto__"||l.has(s))return;l.add(s);let f=`${e}#${t}.${s}`;o.push({id:f,moduleId:e,name:s,kind:u,enclosingClassId:r,declRange:gn(e,d,n),isExported:!1,publicSurfaceReachable:!1}),a.push(f),i.push({name:s,id:f,kind:u,body:p})},finish(){return i.length===0?null:{functions:o,classNode:{id:r,moduleId:e,name:t,implementsRefs:[],members:a},members:i}}}}function Zu(e,n,t,r){if(Os(r)||r.members.length>Hr)return null;let o=Ps(e,n,t);for(let i of r.members){let a,l,s;if(c.isConstructorDeclaration(i))a="constructor",l="ctor",s=void 0;else if(c.isMethodDeclaration(i))a=Vt(i.name),l="method",s=a!==void 0&&!Bn.has(a)?i.body??void 0:void 0;else continue;a!==void 0&&o.pushMember(a,i,l,s)}return o.finish()}function Qu(e,n,t){let r;for(let a of n.statements)if(c.isFunctionDeclaration(a)&&a.name?.text===t){r=a;break}if(r===void 0)return null;let o=[];for(let a of n.statements){if(!c.isExpressionStatement(a))continue;let l=a.expression;if(!c.isBinaryExpression(l)||l.operatorToken.kind!==c.SyntaxKind.EqualsToken)continue;let s=l.left;if(c.isPropertyAccessExpression(s)&&c.isPropertyAccessExpression(s.expression)&&c.isIdentifier(s.expression.expression)&&s.expression.expression.text===t&&s.expression.name.text==="prototype"){let d=s.name.text;c.isFunctionExpression(l.right)?o.push({name:d,fn:l.right,walk:!0}):c.isArrowFunction(l.right)&&o.push({name:d,fn:l.right,walk:!1})}}if(o.length===0||o.length+1>Hr)return null;let i=Ps(e,n,t);i.pushMember("constructor",r,"ctor",void 0);for(let a of o){let l=a.walk&&!Bn.has(a.name)&&c.isFunctionExpression(a.fn)?a.fn.body:void 0;i.pushMember(a.name,a.fn,"method",l)}return i.finish()}function ef(e,n,t){for(let r of n.statements)if(c.isClassDeclaration(r)&&r.name?.text===t)return Zu(e,n,t,r);return Qu(e,n,t)}function nf(e,n,t,r,o){let i={modules:[],functions:[],classes:[],callSites:[],callEdges:[],imports:[],importEdges:[],diagnostics:[]};if(n.length===0)return i;let a=new Set(t.map(p=>p.packageName)),l=new Set(t.map(p=>p.path)),s=new Set,d=new Set,u=0;for(let p of n){if(!a.has(p.packageName))continue;let f=Ju(e.appRoot,p.packageRootRel,p.sourcePath);if(f===null)continue;let h=e.toRel(f);if(h===null)continue;let g=`${h}#${p.container}`;if(d.has(g)||!s.has(h)&&s.size>=zt)continue;let S=_e(f);if(S===null)continue;let E;try{E=c.createSourceFile(h,S,c.ScriptTarget.Latest,!0,c.ScriptKind.JS)}catch{continue}let w=ef(h,E,p.container);if(w===null)continue;s.add(h),d.add(g);let I=new Map,v=new Map;for(let k of w.members){let m=o.methodFor(p.packageName,p.container,k.name,k.kind);I.set(k.name,m),v.set(m,k.id)}let _=0;for(let k of w.members){if(k.body===void 0)continue;let m=(y,A)=>{if(A&&c.isCallExpression(y)&&c.isPropertyAccessExpression(y.expression)&&y.expression.expression.kind===c.SyntaxKind.ThisKeyword){let P=I.get(y.expression.name.text);if(P!==void 0){let R=`${h}#depclass:${p.container}.${k.name}#c${String(_)}`;_+=1,i.callSites.push({id:R,enclosingFunctionId:k.id,calleeExprShape:"member",resolvedTargetIds:[],resolution:"unresolved",range:gn(h,y,E)}),i.callEdges.push({callSiteId:R,calleeFunctionId:P,resolution:"field-based"})}}let C=c.isFunctionExpression(y)||c.isFunctionDeclaration(y)||c.isMethodDeclaration(y)||c.isConstructorDeclaration(y)||c.isGetAccessorDeclaration(y)||c.isSetAccessorDeclaration(y)||c.isClassLike(y),T=c.isArrowFunction(y)?A:C?!1:A;c.forEachChild(y,P=>{m(P,T)})};m(k.body,!0)}for(let k of r){let m=v.get(k.calleeFunctionId);m!==void 0&&i.callEdges.push({callSiteId:k.callSiteId,calleeFunctionId:m,resolution:"field-based"})}if(i.functions.push(...w.functions),i.classes.push(w.classNode),!l.has(h)){l.add(h),i.modules.push({id:h,packageName:p.packageName,versionRange:"",path:h,moduleSystem:"cjs",isEntrypoint:!1});let k=o.moduleFor(p.packageName),m=`${String(k)}#depclass${String(u)}`;u+=1,i.imports.push({id:m,moduleId:k,specifier:"<dep-class-corridor>",isNamespace:!1,isDefault:!1,dynamic:!1,specifierIsLiteral:!0,resolvedModuleId:h}),i.importEdges.push({importId:m,resolvedModuleId:h})}i.diagnostics.push({code:"dep-class-corridor",path:h,detail:`lowered dependency class ${p.container} (${p.packageName}) \u2014 ${String(w.members.length)} members; the un-analyzed remainder caps this class's method sinks at unknown`,classScope:{packageName:p.packageName,container:p.container}})}return i}function tf(e,n,t,r){let o=new Set(e.modules.filter(s=>s.isEntrypoint).map(s=>s.packageName)),i=new Map(e.functions.map(s=>[s.id,s.moduleId])),a=new Map;for(let s of e.callSites){if(s.resolution!=="unresolved")continue;let d=i.get(s.enclosingFunctionId);d!==void 0&&a.set(d,(a.get(d)??0)+1)}let l=[];for(let s of e.modules){if(s.externalSurface===!0)continue;let d=n.get(s.path);if(d===void 0||t.has(s.path)||o.has(s.packageName)&&r.has(s.path)&&!s.path.split("/").includes("node_modules"))continue;let u=a.get(s.id)??0;if(u===0&&Lu(d))continue;let p=u>0?`${String(u)} of its call sites are unresolved`:"it invokes (or exposes) a function body through a form that emits no call site \u2014 `new`, an accessor, the iterator protocol, spread, or a coercion member";l.push({code:"dependency-body",path:s.path,detail:`dependency module analyzed with full bodies (package-subpath/relative/computed entry) but ${p}; its hidden call edges are bounded by its own forward module reach (ADR-069 Finding A)`,anchor:s.id})}return l}function $s(e,n,t=[],r={},o=!1){let i=new Wr,a=fu(e,n,i),l=new Set;for(let _ of a.computedLoads.values())for(let k of _)if(k.seedable)for(let m of k.candidateRels)l.add(m);let s=new Map;for(let _ of e.sourceFiles){let k=e.toRel(_.fileName);if(k===null||!l.has(k)||k.split("/").includes("node_modules"))continue;let m=Wu(k,_);m.length>0&&s.set(k,m)}let d=s.size===0?a.modules:a.modules.map(_=>s.has(_.path)&&!_.isEntrypoint?{..._,isEntrypoint:!0}:_),u={...a,modules:d},p=Yu(e,u,i,s,r),f=Du(e,a,p.functions,p.mintSeedAliases),h=new Set(a.modules.map(_=>_.path)),g=hu(e.depReach,i,h),S=[...u.modules,...g.modules,...i.modules()],E=nf(e,t,S,p.callEdges,i),w=[];if(o){let _="#default",k=new Set;for(let y of p.callEdges){let A=String(y.calleeFunctionId);!A.startsWith("pkg:")||!A.endsWith(_)||k.add(A.slice(4,A.length-_.length))}let m=new Map;for(let y of e.depReach.edges){if(!("surface"in y.from)||"surface"in y.to)continue;let A=y.from.surface;m.set(A,m.has(A)?null:y.to.module)}for(let y of k){let A=m.get(y);if(A==null)continue;let C=pu(Te.join(e.appRoot,A));if(C===null||C==="default")continue;let T=i.exportFor(y,C),P=`pkg:${y}${_}`;for(let R of p.callEdges)String(R.calleeFunctionId)===P&&w.push({callSiteId:R.callSiteId,calleeFunctionId:T,resolution:"field-based"})}}let I={modules:[...u.modules,...g.modules,...E.modules,...i.modules()],exports:[...p.exports,...f.exports],imports:[...a.imports,...g.imports,...E.imports],functions:[...p.functions,...i.functions(),...E.functions],callSites:[...p.callSites,...E.callSites],classes:[...p.classes,...i.classes(),...E.classes],callEdges:[...p.callEdges,...E.callEdges,...w],importEdges:[...a.importEdges,...g.importEdges,...E.importEdges],exportBindings:[...p.exportBindings,...f.exportBindings],inheritEdges:[]},v=new Map;for(let _ of e.sourceFiles){let k=e.toRel(_.fileName);k!==null&&v.set(k,_)}return{graph:I,diagnostics:[...f.diagnostics,...E.diagnostics,...tf(I,v,new Set(e.diagnostics.filter(_=>_.code==="dependency-body").map(_=>_.path)),a.appOwnedPaths)],loadSites:a.loadSites,...p.bindingApplicability!==void 0?{bindingApplicability:p.bindingApplicability}:{}}}var rf=/^(@[A-Za-z0-9_.-]{1,100}\/)?[A-Za-z0-9_.-]{1,100}$/u,Wt=/^[A-Za-z0-9_$.-]{1,128}$/u;function of(e){return rf.test(e.calleePackage)?Wt.test(e.anchorExport)?Wt.test(e.calleeExport)?e.anchorContainer!==null&&!Wt.test(e.anchorContainer)?`anchorContainer ${JSON.stringify(e.anchorContainer)}`:e.calleeContainer!==null&&!Wt.test(e.calleeContainer)?`calleeContainer ${JSON.stringify(e.calleeContainer)}`:null:`calleeExport ${JSON.stringify(e.calleeExport)}`:`anchorExport ${JSON.stringify(e.anchorExport)}`:`calleePackage ${JSON.stringify(e.calleePackage)}`}function st(e,n){let t=[],r=[],o=new Map(e.modules.map(d=>[d.id,d])),i=new Map(e.classes.map(d=>[d.id,d.name])),a=(d,u,p)=>e.functions.some(f=>{if(f.name!==u)return!1;let h=o.get(f.moduleId);return h===void 0||h.packageName!==d?!1:(f.enclosingClassId!==void 0?i.get(f.enclosingClassId)??null:null)===p}),l=(d,u,p)=>{for(let f of e.functions){if(f.name!==u)continue;let h=o.get(f.moduleId);if(!(h===void 0||h.packageName!==d||(f.enclosingClassId!==void 0?i.get(f.enclosingClassId)??null:null)!==p))return f.id}return null},s=[...n].sort((d,u)=>d.modelId<u.modelId?-1:d.modelId>u.modelId?1:0);for(let d of s){if(d.edges.length>64){t.push(`model ${d.modelId}: ${String(d.edges.length)} edges over cap ${String(64)} \u2014 dropped WHOLE (all-or-nothing)`);continue}let u=d.edges.map(of).find(h=>h!==null);if(u!==void 0){t.push(`model ${d.modelId}: hostile/invalid edge field ${u} \u2014 model refused WHOLE`);continue}let p=0,f=0;for(let h of d.edges){if(!a(d.packageName,h.anchorExport,h.anchorContainer)){f+=1;continue}r.push({modelId:d.modelId,kind:h.kind,anchor:{packageName:d.packageName,exportName:h.anchorExport,container:h.anchorContainer},callee:{packageName:h.calleePackage,exportName:h.calleeExport,container:h.calleeContainer,realFunctionId:l(h.calleePackage,h.calleeExport,h.calleeContainer)},resolution:"modeled"}),p+=1}p>0?t.push(`model-edge ${d.modelId}: ${String(p)} edge(s) lowered, ${String(f)} reference-gated`):t.push(`model ${d.modelId}: refused \u2014 no anchor surface in the graph (${String(f)} edge(s) reference-gated); models never mint loadedness`)}return{delta:{records:r,notes:t}}}var sf={modules:[],exports:[],imports:[],functions:[],callSites:[],classes:[],callEdges:[],importEdges:[],exportBindings:[],inheritEdges:[]};function to(e){try{let n=rs(e.appRoot,e.entrypoints,e.tsconfigPaths===!0),t=new Set(e.entrypoints.map(l=>l.split(ze.sep).join("/"))),{graph:r,diagnostics:o,loadSites:i,bindingApplicability:a}=$s(n,t,e.depClassAnchors??[],e.bindingForms??{},e.callablePackageResolver===!0);return{graph:r,diagnostics:[...n.diagnostics,...o],loadSites:i,conditionUnions:n.conditionUnions,provenAbsent:n.provenAbsent,...a!==void 0?{bindingApplicability:a}:{}}}catch(n){return{graph:sf,loadSites:[],conditionUnions:[],provenAbsent:[],diagnostics:[{code:"unsupported-syntax",path:e.appRoot,detail:`analysis aborted: ${n instanceof Error?n.message:String(n)}`}]}}}function Ms(e,n){let t=512,r=(o,i,a)=>{if(!(t<=0||i>12)){if(t-=1,typeof o=="string"){n(o,a);return}if(Array.isArray(o)){for(let l of o)r(l,i+1,a);return}if(o!==null&&typeof o=="object")for(let[l,s]of Object.entries(o))l==="types"||l==="typings"||r(s,i+1,a||l.includes("*"))}};r(e,0,!1)}function Fs(e,n,t,r=!1){if(typeof t!="string"||t.length===0||t.endsWith(".d.ts")||t.endsWith(".d.mts")||t.endsWith(".d.cts"))return null;let o;try{o=dn(ze.resolve(e,t))}catch{return null}return o!==e&&!o.startsWith(n)||r&&!en(o)?null:o===e?"":o.slice(n.length).split(ze.sep).join("/")}var af=1024*1024,lf=4096;function Ds(e,n){let t=e.toLowerCase(),r=0;for(;;){let o=t.indexOf(n,r);if(o===-1)return null;let i=o===0?" ":t[o-1],a=o+n.length;for(;a<e.length&&(e[a]===" "||e[a]===" "||e[a]===`
|
|
16
|
-
`||e[a]==="\r");)a+=1;if(/[a-z0-9_:-]/i.test(
|
|
17
|
-
`||e[a]==="\r");)a+=1;let l=e[a];if(l==='"'||l==="'"){let d=e.indexOf(l,a+1);return d===-1?null:e.slice(a+1,d)}let s=a;for(;s<e.length&&!/[\s>]/.test(e[s]??"");)s+=1;return e.slice(a,s)}}function df(e){let n=[],t=e.toLowerCase(),r=0;for(;;){let o=t.indexOf("<script",r);if(o===-1)break;let i=t[o+7];if(i!==void 0&&/[a-z0-9-]/.test(i)){r=o+7;continue}let a=e.indexOf(">",o);if(a===-1)break;r=a+1;let l=e.slice(o+7,a);if(l.length>lf)continue;let s=Ds(l,"type");n.push({module:(s??"").trim().toLowerCase()==="module",src:Ds(l,"src")})}return n}function cf(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function uf(e){let n=e.search(/[?#]/);return(n===-1?e:e.slice(0,n)).replace(/^\/+/,"")}function ff(e){let n=dn(e),t=n.endsWith(ze.sep)?n:n+ze.sep,r=new Set,o=[],i=[],a=[],l=[],s=[],d=!1,u=(O,L,K=!1,G)=>{let B=Fs(n,t,O);return B===null||B.length===0?"unresolved":r.has(B)?"duplicate":(r.add(B),o.push(B),i.push({source:L,specifier:Be(G??(typeof O=="string"?O:"")),entrypoint:B,launch:K}),"added")},p=new Set,f=(O,L,K=!1)=>{let G=u(O,L),B=typeof O=="string"&&O.includes("\\")?u(O.split("\\").join("/"),L,!1,O):"unresolved";if(G!=="unresolved"||B!=="unresolved"||typeof O!="string"||O.trim().length===0||O.endsWith(".d.ts")||O.endsWith(".d.mts")||O.endsWith(".d.cts"))return;if(K&&O.includes("*")){let $=is(n,O),q=!1;if($!==null){for(let H of $.matches)u(H,L,!1,O)!=="unresolved"&&(q=!0);if(!$.truncated&&q)return}l.push({source:L,file:"package.json",detail:`\`${Be(O)}\` is a subpath pattern cupel could not expand completely; the files it names beyond those seeded were NOT analyzed`});return}let W=`${L}\0${O}`;p.has(W)||(p.add(W),l.push({source:L,file:"package.json",detail:`\`${Be(O)}\` did not resolve to a file inside the scan root; the code it names was NOT analyzed`}))},h=[],g=(O,L)=>{a.push({source:O,file:O,detail:L.detail}),h.push({code:L.code,path:O,detail:`${O} ${L.detail}`})},S,E,w,I=null,v=eo(n,t,"package.json",pn);v.kind==="refused"&&g("package.json",v);try{let O=v.kind==="ok"?JSON.parse(v.text):{};if(I=v.kind==="ok"?O:null,f(O.main,"main"),typeof O.bin=="string")f(O.bin,"bin");else if(O.bin!==null&&typeof O.bin=="object")for(let K of Object.values(O.bin))f(K,"bin");Ms(O.exports,(K,G)=>{f(K,"exports",G)}),typeof O.browser=="string"?f(O.browser,"browser"):Ms(O.browser,K=>{u(K,"browser")});let L=O.scripts;if(L!==null&&typeof L=="object"){let K=L;S=K.start,E=K.prestart,w=K.poststart}}catch{}if(o.length===0)try{dn(ze.join(n,"index.js")),u("index.js","index.js fallback")}catch{}let _=(O,L)=>{if(typeof O=="string"&&O.trim().length>0){let K=Ts(O,L,"package.json",u,a,!1)==="used";return K&&(d=!0),K?"resolved":"gapped"}return O===void 0||typeof O=="string"?"absent":(a.push({source:L,file:"package.json",detail:`${L} is not a string; no entry file could be read from it`}),"gapped")},k=_(S,"scripts.start"),m=_(E,"scripts.prestart"),y=_(w,"scripts.poststart"),A=k==="resolved"&&m!=="gapped"&&y!=="gapped",C=eo(n,t,"Procfile",65536);if(C.kind==="refused")g("Procfile",C);else if(C.kind==="ok"){let{entries:O,truncated:L,unnamedLines:K}=Vr(C.text);L&&a.push({source:"Procfile",file:"Procfile",detail:"Procfile has more process types than cupel parses; the remainder was not read"}),K>0&&a.push({source:"Procfile",file:"Procfile",detail:`${String(K)} Procfile line(s) declare a process whose name cupel does not accept; their commands were NOT read`});for(let G of O)Ts(G.command,`Procfile:${G.name}`,"Procfile",u,a,A)==="used"&&(d=!0)}let T=o.length===0,P=eo(n,t,"index.html",af);if(P.kind==="ok")for(let O of df(P.text)){if(O.src===null)continue;let L=Be(O.src);if(!O.module){s.push({kind:"classic-script",file:"index.html",detail:`index.html loads "${L}" as a classic (non-module) script; not seeded (ADR-071 Step 5, decision 2)`,root:""});continue}if(cf(O.src)){s.push({kind:"external-script",file:"index.html",detail:`index.html loads the module script "${L}" from another origin \u2014 not this repository's code; not seeded`,root:""});continue}u(uf(O.src),"index.html",!1,O.src)==="unresolved"&&a.push({source:"index.html",file:"index.html",detail:`index.html names the module script "${L}", which did not resolve to a file inside the root; the browser would load it and cupel did not analyze it`})}else P.kind==="refused"&&s.push({kind:P.code==="limit-exceeded"?"index-html-oversize":"index-html-refused",file:"index.html",detail:`index.html ${P.detail}`,root:""});let R=T?jr(n,I):null;if(R!==null){let O=0;for(let L of Br(n,R).roots)u(L,`framework:${R.name}`)==="added"&&(O+=1);O>0&&h.push({code:"framework-derived-entry",path:"package.json",detail:`entrypoints were derived from ${R.name}'s directory conventions (recognised via ${R.configFile}), not declared by this project. That set cannot be proven complete, so findings that would read \`not-reachable\` are capped at \`unknown\`; pass \`--entry\` for the files your build actually starts to lift it`})}let F=O=>O.map(L=>({...L,root:""}));return{entrypoints:o,sources:F(i),gaps:F(a),surfaceGaps:F(l),launchResolved:d,diagnostics:h,framework:R,observations:s}}function eo(e,n,t,r){let o;try{o=dn(ze.join(e,t))}catch{return{kind:"absent"}}if(!o.startsWith(n))return{kind:"refused",code:"out-of-root",detail:"exists but resolves OUTSIDE the scan root (symlink); it was NOT read, so the declarations it carries were not analyzed"};let i=Fn(o,r);return i.kind==="ok"?i:i.kind==="too-large"?{kind:"refused",code:"limit-exceeded",detail:`is ${String(i.bytes)} bytes, over the ${String(r)}-byte cap; it was NOT read`}:{kind:"refused",code:"parse-error",detail:"exists but is not a readable regular file (FIFO/device/directory); it was NOT read"}}function Ts(e,n,t,r,o,i){let a=Ur(e);if(a.kind==="delegates")return i?"used":(o.push({source:n,file:t,detail:`\`${Be(e)}\`: runs the package \`start\` lifecycle (prestart/start/poststart), which is absent or not fully readable`}),"gapped");if(a.kind==="unparsed")return o.push({source:n,file:t,detail:`\`${Be(e)}\`: ${a.reason}`}),"gapped";let l=r(a.specifier,n,!0),s=a.alt===void 0?"unresolved":r(a.alt,n,!0);return l==="unresolved"&&s==="unresolved"?(o.push({source:n,file:t,detail:`\`${Be(a.specifier)}\` did not resolve to a file inside the app root`}),"gapped"):"used"}function Un(e,n){return e===""?n:`${e}/${n}`}function js(e,n){let t=dn(e),r=t.endsWith(ze.sep)?t:t+ze.sep,o=new Set,i=[],a=[],l=[],s=[],d=[],u=[],p=!1,f=null,h=[...n].sort((g,S)=>g.rel===""?-1:S.rel===""?1:g.rel<S.rel?-1:g.rel>S.rel?1:0);for(let g of h){let S=Un(g.rel,"package.json"),E=g.rel===""?".":g.rel,w;try{w=dn(g.abs)}catch{l.push({source:"root",file:S,detail:`root \`${E}\` could not be resolved; not seeded`,root:g.rel});continue}if(w!==t&&!w.startsWith(r)){l.push({source:"root",file:S,detail:`root \`${E}\` resolves outside the scan root; refused, not seeded`,root:g.rel});continue}let I;try{I=ff(w)}catch{l.push({source:"root",file:S,detail:`root \`${E}\` could not be read; not seeded`,root:g.rel});continue}for(let v of I.sources){let _=Un(g.rel,v.entrypoint),k,m;try{k=dn(ze.resolve(t,_)),m=dn(ze.resolve(w,v.entrypoint))}catch{l.push({source:v.source,file:S,detail:`\`${v.specifier}\` re-based to \`${_}\` did not resolve; not seeded`,root:g.rel});continue}if(!k.startsWith(r)||k!==m){l.push({source:v.source,file:S,detail:`\`${v.specifier}\` re-based to \`${_}\` escapes the scan root or names another file; refused, not seeded`,root:g.rel});continue}o.has(_)||(o.add(_),i.push(_),a.push({...v,entrypoint:_,root:g.rel}))}I.launchResolved&&(p=!0);for(let v of I.gaps)l.push({...v,file:Un(g.rel,v.file),root:g.rel});for(let v of I.surfaceGaps)s.push({...v,file:Un(g.rel,v.file),root:g.rel});for(let v of I.diagnostics)d.push({...v,path:Un(g.rel,v.path)});for(let v of I.observations)u.push({...v,file:Un(g.rel,v.file),root:g.rel});g.rel===""&&(f=I.framework)}return{entrypoints:i,sources:a,gaps:l,surfaceGaps:s,launchResolved:p,diagnostics:d,framework:f,observations:u}}function ro(e){let{gaps:n,launchResolved:t}=e;if(n.length===0||!t)return[];let r=n.slice(0,3).map(o=>o.source).join(", ");return[{code:"unresolved-launch-entry",path:n[0]?.file??"package.json",detail:`${String(n.length)} launch declaration(s) (${r}) name code this project starts but cupel could not resolve to an entry file, while other launch declarations DID seed the analysis; verdicts that would be \`not-reachable\` are capped at \`unknown\`. To clear it, make those commands a direct \`node <file.js>\` invocation cupel can read. \`--entry <file>\` analyzes that code too (so a sink there is still reported), but the cap remains while the command itself is unreadable`}]}function oo(e,n){let{surfaceGaps:t}=e;if(t.length===0||n===0)return[];let r=[...new Set(t.slice(0,3).map(o=>o.source))].join(", ");return[{code:"unresolved-entry-declaration",path:t[0]?.file??"package.json",detail:`${String(t.length)} package.json entry declaration(s) (${r}) name a file this package owns that cupel could not resolve inside the scan root, while the analysis was seeded from elsewhere; the code they name was NOT analyzed, so verdicts that would be \`not-reachable\` are capped at \`unknown\`. To clear it, point those fields at a file that exists (a Windows-style \`lib\\index.js\` does not resolve on a posix host). \`--entry <file>\` analyzes that code too, but the cap remains while the declaration is unresolvable`}]}function Ks(e,n){let t=dn(e),r=t.endsWith(ze.sep)?t:t+ze.sep,o=new Set,i=[],a=[];for(let l of n){let s=Fs(t,r,l,!0);if(s===null||s.length===0){a.push(l);continue}o.has(s)||(o.add(s),i.push(s))}return{entrypoints:i,rejected:a}}import{readdirSync as ba,readFileSync as go,realpathSync as yo,statSync as ft}from"node:fs";import He from"node:path";function pf(e){if(e.startsWith("<<:")||e.startsWith("- &")||e.startsWith("- *"))return!0;let n=e.charCodeAt(0);if(n===38||n===42)return!0;let t=e.indexOf(": ");if(t===-1)return!1;let r=t+2;for(;r<e.length&&e.charCodeAt(r)===32;)r+=1;let o=e.charCodeAt(r);return o===38||o===42}function at(e,n,t){let r=n.maxLines??2e6,o=n.maxLineBytes??16384,i=!1,a=!1,l=0,s=0,d=e.charCodeAt(0)===65279?1:0;for(;d<=e.length;){let u=e.indexOf(`
|
|
18
|
-
`,d),p=u===-1;p&&(u=e.length);let f=u>d&&e.charCodeAt(u-1)===13?u-1:u;if(s+=1,s>r){i=!0;break}if(f-d>o)l+=1;else{let h=d;for(;h<f&&e.charCodeAt(h)===32;)h+=1;let g=h-d,S=f;for(;S>h&&(e.charCodeAt(S-1)===32||e.charCodeAt(S-1)===9);)S-=1;if(h<S&&e.charCodeAt(h)!==35){let E=e.slice(h,S);if(pf(E)){a=!0;break}t(g,E)}}if(p)break;d=u+1}return{truncated:i||l>0,refusedAnchors:a,oversizeLines:l}}function qt(e){let n=e.charCodeAt(0);if(n===34||n===39){let r=e.indexOf(String.fromCharCode(n),1);if(r===-1)return null;let o=r+1;for(;o<e.length&&e.charCodeAt(o)===32;)o+=1;return e.charCodeAt(o)===58?e.slice(0,r+1):null}let t=e.indexOf(":");return t>0?e.slice(0,t):null}function Vn(e){return e.endsWith(":")}function Ge(e){if(e.length>=2){let n=e.charCodeAt(0);if((n===34||n===39)&&e.charCodeAt(e.length-1)===n)return e.slice(1,-1)}return e}function Gt(e){if(e.length===0||e.length>214)return!1;let n=e.charCodeAt(0)===64,t=n?e.slice(1):e,r=t.indexOf("/");if(n){if(r<=0||t.indexOf("/",r+1)!==-1)return!1}else if(r!==-1)return!1;let o=n?[t.slice(0,r),t.slice(r+1)]:[t];for(let i of o){if(i.length===0||i.charCodeAt(0)===46||i.charCodeAt(0)===95)return!1;for(let a=0;a<i.length;a+=1){let l=i.charCodeAt(a);if(!(l>=97&&l<=122||l>=65&&l<=90||l>=48&&l<=57||l===45||l===46||l===95||l===126))return!1}}return!0}function lt(e){return Gt(e)?`node_modules/${e}`:""}function dt(e,n){let t=`${e}@${n}`;return t.length<=96?t:`${t.slice(0,96)}\u2026`}var Ht=2e5,Bs=64,Xt=1024,mf=5,hf=[1,2,3];function gf(e){let n="node_modules/",t=e.lastIndexOf(n);if(t===-1)return null;let r=e.slice(t+n.length);if(r==="")return null;let o=r.split("/");return o[0]?.startsWith("@")?o.length>=2?`${o[0]}/${o[1]}`:null:o[0]??null}function zs(e,n){if(!n.startsWith("npm:"))return[{name:e,version:n}];let t=n.slice(4);if(t.length===0)return[{name:e,version:n}];let r=t.indexOf("@",1);if(r>0){let o=t.slice(0,r),i=t.slice(r+1);if(o.length>0&&i.length>0)return[{name:o,version:i}]}return t===e?[{name:e,version:n}]:[{name:e,version:n},{name:t,version:n}]}function Wn(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function Us(e){return{deps:[],seen:new Set,maxEntries:e,unread:0,visited:0,capped:!1}}function Vs(e){return e.capped?!1:(e.visited+=1,e.visited>e.maxEntries?(e.capped=!0,!1):!0)}function Ws(e,n,t,r,o=!1){let i=JSON.stringify([n,t,r]);if(!e.seen.has(i)){if(e.deps.length>=e.maxEntries){e.capped=!0;return}e.seen.add(i),e.deps.push({name:n,version:t,lockKey:r,dev:o})}}function yf(e,n){for(let[t,r]of Object.entries(e)){if(t==="")continue;if(!Vs(n))return;let o=t.startsWith("node_modules/")||t.includes("/node_modules/"),i=Wn(r);if(i===null){n.unread+=1;continue}if(i.link===!0)continue;let a=i.name,l=typeof a=="string"&&a!==""?a:gf(t),s=i.version;if(l===null||typeof s!="string"){o&&(n.unread+=1);continue}let d=i.dev===!0||i.devOptional===!0;for(let u of zs(l,s))Ws(n,u.name,u.version,t,d)}}function qs(e,n,t){let r=[{deps:e,prefix:"",depth:0,pathSafe:!0,dev:!1}],o=!1;for(let i=0;i<r.length;i+=1){let a=r[i];if(a===void 0)break;for(let[l,s]of Object.entries(a.deps)){if(!Vs(n))return{depthCapped:o};if(l===""){n.unread+=1;continue}let d=Wn(s);if(d===null){n.unread+=1;continue}let u=a.pathSafe&&Gt(l),p=u?`${a.prefix}node_modules/${l}`:"",f=u&&p.length<=Xt,h=f?p:"",g=d.version,S=d.dev===!0||a.dev;if(d.link!==!0&&typeof g=="string"&&g!=="")for(let w of zs(l,g))Ws(n,w.name,w.version,h,S);else n.unread+=1;let E=Wn(d.dependencies);if(E!==null){if(a.depth+1>t){o=!0;continue}r.push({deps:E,prefix:f?`${h}/`:a.prefix,depth:a.depth+1,pathSafe:f,dev:S})}}}return{depthCapped:o}}function xf(e,n,t){let r=Us(n.maxEntries),{depthCapped:o}=qs(e,r,t),i=[],a=new Set(n.deps.map(d=>JSON.stringify([d.name,d.version]))),l=new Set,s=[];for(let d of r.deps){if(d.version.includes(":"))continue;let u=JSON.stringify([d.name,d.version]);a.has(u)||l.has(u)||(l.add(u),s.length<mf&&s.push(dt(d.name,d.version)))}if(l.size>0){let d=l.size-s.length;i.push(`package-lock.json carries BOTH a v2/v3 \`packages\` map and a legacy v1 \`dependencies\` tree, and they DISAGREE: ${String(l.size)} install(s) the tree describes are absent from the map (${s.join(", ")}${d>0?`, and ${String(d)} more`:""}). npm 6 installs from the tree and npm 7+ from the map, so what is on disk depends on which npm ran; cupel enumerated the map`)}return(r.capped||o)&&i.push("package-lock.json's legacy `dependencies` tree hit a cap before it could be cross-checked against the `packages` map; a disagreement between the two would not have been seen"),i}function Yt(e,n={}){let t=[],r;try{r=JSON.parse(e)}catch{return{deps:[],diagnostics:["package-lock.json is not valid JSON"],truncated:!1}}let o=Wn(r);if(o===null)return{deps:[],diagnostics:["package-lock.json is not an object"],truncated:!1};let i=o.lockfileVersion,a=typeof i=="number"&&Number.isInteger(i)?i:null,l=typeof i=="number"?String(i):"?",s=Wn(o.packages),d=Wn(o.dependencies);if(s===null&&d===null)return{deps:[],diagnostics:[`package-lock.json (lockfileVersion ${l}) has neither a v2/v3 \`packages\` map nor a v1 \`dependencies\` tree; NO dependency was enumerated`],truncated:!1};(a===null||!hf.includes(a))&&t.push(`package-lock.json declares unsupported lockfileVersion ${l} (cupel knows v1, v2 and v3); its shape may differ, so what was read may be incomplete`);let u=n.maxDepth??Bs,p=Us(n.maxEntries??Ht),f=!1;return s!==null?(yf(s,p),d!==null&&t.push(...xf(d,p,u))):d!==null&&(f=qs(d,p,u).depthCapped),p.capped&&t.push(`lockfile exceeds ${String(p.maxEntries)} entries; truncated`),f&&t.push(`package-lock.json nests \`dependencies\` deeper than ${String(u)} levels; the deeper subtree(s) were NOT enumerated`),p.unread>0&&t.push(`package-lock.json has ${String(p.unread)} entr(ies) with no version cupel could read (an odd shape or a missing \`version\`); they were not enumerated`),{deps:p.deps,diagnostics:t,truncated:p.capped||f}}var Sf=["workspace:","link:","portal:","file:","exec:"];function bf(e){let n=e.charCodeAt(0);if(n>=48&&n<=57||n===94||n===126||n===62||n===60||n===61||n===42||n===124)return!0;if(n===118||n===86){let t=e.charCodeAt(1);return t>=48&&t<=57}return!1}function kf(e){let n=e.trim();if(n.length===0)return[];let t=n.indexOf("@",1);if(t<=0)return[];let r=n.slice(0,t),o=n.slice(t+1);if(r.length===0)return[];for(let l of Sf)if(o.startsWith(l))return[];if(!o.startsWith("npm:"))return[r];let i=o.slice(4),a=i.indexOf("@",1);if(a>0){let l=i.slice(0,a);return l.length>0?[l]:[r]}return i.length===0||bf(i)?[r]:[r,i]}function Ef(e){if(Vn(e))return e.slice(0,-1);let n=0;for(let t=0;t<e.length-1;t+=1){let r=e.charCodeAt(t);if(r===34||r===39){n===0?n=r:n===r&&(n=0);continue}if(n===0&&r===58&&e.charCodeAt(t+1)===32)return e.slice(0,t)}return null}function wf(e){let n=e.replaceAll('"',"").replaceAll("'",""),t=[];for(let r of n.split(",")){let o=r.trim();o.length>0&&t.push(o)}return t}function vf(e){let n=e.charCodeAt(0)===65279?e.slice(1,64):e.slice(0,64),t="# yarn lockfile v";if(!n.startsWith(t))return null;let r=t.length;for(;r<n.length&&r<t.length+3;){let i=n.charCodeAt(r);if(i<48||i>57)break;r+=1}let o=n.slice(t.length,r);return o.length>0?o:null}function Gs(e){if(!e.startsWith("version"))return null;let n=e.charCodeAt(7);if(n!==58&&n!==32)return null;let t=Ge(e.slice(8).trim());return t.length>0?t:null}function io(e,n={}){let t=[],r=[],o=new Set,i=n.maxEntries??2e5,a=!1,l=null,s=!1,d=[],u=!1,p=-1,f=!1,h=0,g=()=>{d.length>0&&!u&&(h+=1)},S=at(e,n,(v,_)=>{if(v===0){g(),d=[],u=!1,p=-1,s=!1;let m=Ef(_);if(m===null)return;let y=Ge(m.trim());if(y==="__metadata"){a=!0,s=Vn(_);return}for(let A of wf(y))d.push(...kf(A));return}if(s){if(v===2&&l===null){let m=Gs(_);m!==null&&(l=m)}return}if(d.length===0||(p===-1&&(p=v),v!==p||u))return;let k=Gs(_);if(k!==null){u=!0;for(let m of d){let y=JSON.stringify([m,k]);if(!o.has(y)){if(r.length>=i){f=!0;return}o.add(y),r.push({name:m,version:k,lockKey:lt(m),dev:!1})}}}});g();let E=a?"yarn.lock (Berry)":"yarn.lock (v1)";if(S.refusedAnchors)return{deps:[],diagnostics:[`${E} uses YAML anchors/aliases (& / * / <<:); cupel refuses to expand them (expansion-bomb shape) and did NOT read the dependency set`],truncated:!1};S.oversizeLines>0&&t.push(`${E} has ${String(S.oversizeLines)} over-long line(s) that were not parsed; the dependency set is incomplete`),f&&t.push(`${E} exceeds ${String(i)} entries; truncated`);let w=l??vf(e),I=w===null?null:Number(w.split(".")[0]);return w!==null&&(I===null||!Number.isInteger(I)||I<1||I>8)&&t.push(`${E} declares unsupported lockfileVersion ${w} (cupel knows v1 and Berry 4-8); its shape may differ, so what was read may be incomplete`),h>0&&t.push(`${E} has ${String(h)} entr(ies) with no version cupel could read (an unusual body shape or a missing \`version\`); they were not enumerated`),{deps:r,diagnostics:t,truncated:S.truncated||f}}function so(e){let n=e.trim(),t=n.indexOf("(");t!==-1&&(n=n.slice(0,t));let r=n.indexOf("_");return r!==-1&&(n=n.slice(0,r)),n.trim()}function ao(e){let n=e.charCodeAt(0);return e.length>0&&n>=48&&n<=57}function Hs(e){let n=Ge(e.trim());if(n.length===0)return null;let t=n.indexOf("(");t!==-1&&(n=n.slice(0,t));let r=n.charCodeAt(0)===47;if(r&&(n=n.slice(1)),n.length===0)return null;if(!r&&n.charCodeAt(0)!==64){let u=n.indexOf("/"),p=n.indexOf("@",1);u>0&&(p===-1||u<p)&&n.slice(0,u).includes(".")&&n.indexOf("/",u+1)!==-1&&(n=n.slice(u+1))}let o=n.charCodeAt(0)===64,i=o?n.indexOf("/"):-1;if(o&&i<=0)return null;let a=o?i+1:0,l=-1;for(let u=a;u<n.length;u+=1){let p=n.charCodeAt(u);if(p===47||p===64){l=u;break}}if(l<=a)return null;let s=n.slice(0,l),d=so(n.slice(l+1));return ao(d)?{name:s,version:d}:null}var If=new Set(["packages","snapshots","importers"]),Af=new Set([5,6,7,8,9]);function _f(e){let n=Ge(e.trim()),t=0;for(;t<n.length&&n.charCodeAt(t)>=48&&n.charCodeAt(t)<=57;)t+=1;return t===0||t>6?null:Number(n.slice(0,t))}function Zt(e){let n=e.indexOf(":");if(n<=0)return null;let t=e.slice(n+1).trim();return t.length===0?null:{key:Ge(e.slice(0,n).trim()),value:Ge(t)}}function lo(e,n={}){let t=[],r=[],o=new Set,i=n.maxEntries??2e5,a="",l=null,s=!1,d=0,u=[],p=(h,g)=>{let S=JSON.stringify([h,g]);if(!o.has(S)){if(r.length>=i){s=!0;return}o.add(S),r.push({name:h,version:g,lockKey:lt(h),dev:!1})}},f=at(e,n,(h,g)=>{if(h===0){let S=qt(g);if(a=S===null?"":Ge(S.trim()),l=null,a==="lockfileVersion"){let E=Zt(g),w=E===null?null:_f(E.value);E!==null&&(w===null||!Af.has(w))&&u.push(`pnpm-lock.yaml declares unsupported lockfileVersion ${E.value} (cupel knows 5.x-9.x); its shape may differ, so what was read may be incomplete`),a="";return}if(If.has(a)&&!Vn(g)){let E=Zt(g)?.value.trim()??"";E!=="{}"&&E!=="[]"&&(d+=1),a=""}return}if(a==="packages"||a==="snapshots"){if(h!==2)return;let S=qt(g),E=S===null?null:Hs(S);if(E===null){d+=1;return}p(E.name,E.version);return}if(a==="importers"){if(h===6){let S=Zt(g);if(S===null){l=g.endsWith(":")?Ge(g.slice(0,-1).trim()):null;return}l=null;let E=so(S.value);ao(E)&&p(S.key,E);return}if(h===8&&l!==null){let S=Zt(g);if(S===null||S.key!=="version")return;let E=so(S.value);ao(E)&&p(l,E)}}});return f.refusedAnchors?{deps:[],diagnostics:["pnpm-lock.yaml uses YAML anchors/aliases (& / * / <<:); cupel refuses to expand them (expansion-bomb shape) and did NOT read the dependency set"],truncated:!1}:(t.push(...u),f.oversizeLines>0&&t.push(`pnpm-lock.yaml has ${String(f.oversizeLines)} over-long line(s) that were not parsed; the dependency set is incomplete`),s&&t.push(`pnpm-lock.yaml exceeds ${String(i)} entries; truncated`),d>0&&t.push(`pnpm-lock.yaml has ${String(d)} entr(ies) with no registry name@version key (git/tarball/link); they were not enumerated`),{deps:r,diagnostics:t,truncated:f.truncated||s})}function Ys(e){return e.toLowerCase().replace(/[-_.]+/gu,"-")}var Nf=1e6,Xs=2e5,Rf=4096,Cf=65536,ct=/^[A-Za-z_][A-Za-z0-9_]*$/u;function Js(e){if(e.length>Nf)return null;let n,t;for(let r of e.split(/\r?\n/u)){if(r==="")break;let o=/^([A-Za-z][A-Za-z0-9-]*):[ \t]*(.*)$/u.exec(r);if(o===null)continue;let i=o[1]?.toLowerCase();i==="name"&&n===void 0?n=o[2]?.trim():i==="version"&&t===void 0&&(t=o[2]?.trim())}return n===void 0||t===void 0||n===""||t===""?null:{name:n,version:t}}function Zs(e){return e.split(/\r?\n/u).map(n=>n.trim()).filter(n=>n.length>0&&ct.test(n))}function Qs(e){if(!e.startsWith('"'))return e.split(",")[0]??"";let n="";for(let t=1;t<e.length;t+=1){let r=e[t];if(r==='"'){if(e[t+1]==='"'){n+='"',t+=1;continue}return n}n+=r}return n}function ea(e){return e===""||e==="."||e===".."||e==="__pycache__"||e.startsWith("__editable__")||e.endsWith(".dist-info")||e.endsWith(".egg-info")||e.endsWith(".data")}function na(e){return e.endsWith(".py")?e.slice(0,-3):e.endsWith(".so")||e.endsWith(".pyd")?e.split(".")[0]??null:null}function ta(e){let n=e.split(/\r?\n/u);return n.length>Xs?n.slice(0,Xs):n}function ra(e){let n=new Set;for(let t of ta(e)){if(t==="")continue;let r=Qs(t).split("/"),o=r[0]??"";if(ea(o))continue;if(r.length>1){ct.test(o)&&n.add(o);continue}let i=na(o);i!==null&&ct.test(i)&&n.add(i)}return[...n].sort((t,r)=>t<r?-1:t>r?1:0)}function Of(e){let n=e.split("/"),t=n[0]??"";if(ea(t))return null;let r=n[n.length-1]??"",o=na(r);if(o===null)return null;let i=n.slice(0,-1);if(i.some(l=>!ct.test(l)||l==="__pycache__"))return null;let a=o==="__init__"?i:[...i,o];return a.length===0||!ct.test(o==="__init__"?i[i.length-1]??"":o)?null:a}function oa(e,n=Rf){let t=new Set,r=0,o=!1;for(let i of ta(e)){if(i==="")continue;let a=Of(Qs(i));if(a!==null){r+=1;for(let l=1;l<=Math.min(2,a.length);l+=1){let s=a.slice(0,l).join(".");if(!t.has(s)){if(t.size>=n){o=!0;break}t.add(s)}}}}return{prefixes:[...t].sort((i,a)=>i<a?-1:i>a?1:0),moduleFiles:r,capped:o}}function ia(e){if(e.length>Cf)return null;let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let t=n,r=typeof t.dir_info=="object"&&t.dir_info!==null&&!Array.isArray(t.dir_info)?t.dir_info:null;return{url:typeof t.url=="string"?t.url:null,editable:r?.editable===!0}}function co(e,n){let t=Js(e);if(t===null)return null;let r=n.topLevelText!==void 0?Zs(n.topLevelText):[],o=r.length>0?r:n.recordText!==void 0?ra(n.recordText):[],i=n.recordText!==void 0?oa(n.recordText):{prefixes:[],moduleFiles:0,capped:!1},a=n.directUrlText!==void 0?ia(n.directUrlText)?.editable??!1:!1;return{name:Ys(t.name),version:t.version,importNames:o,modulePrefixes:i.prefixes,moduleFiles:i.moduleFiles,editable:a}}import{statSync as Jf}from"node:fs";import Zf from"node:path";import{lstatSync as Pf,readFileSync as $f,readdirSync as Mf,realpathSync as uo,statSync as ut}from"node:fs";import pe from"node:path";function fo(e){return e.ecosystem==="PyPI"||e.alsoPython===!0}var da=2e4,ca=32,ua=256,Df=2*1024*1024,Tf=256*1024,fa=256,Lf=16,Ff=["package-lock.json","npm-shrinkwrap.json","yarn.lock","pnpm-lock.yaml"],jf=["pyproject.toml","setup.py","setup.cfg"],Kf=["requirements.txt","Pipfile"],Bf=["uv.lock","poetry.lock","Pipfile.lock","pdm.lock"],pa={roots:[],observations:[],budget:"not-attempted",counts:{dirsWalked:0,manifestsSeen:0,rootsAdmitted:0,dotDirectoriesSkipped:0}};function sa(e,n){try{let t=ut(e);return!t.isFile()||t.size>n?null:$f(e,"utf8")}catch{return null}}function yn(e){let n;try{n=ut(e)}catch(t){return t?.code==="ENOENT"?"absent":"refused"}return n.isFile()?"regular":"refused"}function zf(e){try{return ut(e).isDirectory()}catch{return!1}}function Uf(e,n){let t=0,r=0,o=-1,i=0;for(;r<n.length;)if(t<e.length&&(e.charAt(t)==="?"||e.charAt(t)===n.charAt(r)))t+=1,r+=1;else if(t<e.length&&e.charAt(t)==="*")o=t,i=r,t+=1;else if(o>=0)t=o+1,i+=1,r=i;else return!1;for(;t<e.length&&e.charAt(t)==="*";)t+=1;return t===e.length}function Vf(e,n){let t=(r,o)=>{if(r===e.length)return o===n.length;let i=e[r]??"";if(i==="**"){for(let l=o;l<=n.length;l+=1)if(t(r+1,l))return!0;return!1}if(o>=n.length)return!1;let a=n[o]??"";return(i.includes("*")||i.includes("?")?Uf(i,a):i===a)?t(r+1,o+1):!1};return t(0,0)}function Wf(e){let n=[],t=sa(pe.join(e,"package.json"),Df);if(t!==null)try{let a=JSON.parse(t)?.workspaces;if(Array.isArray(a))for(let l of a)typeof l=="string"&&n.push(l);else if(typeof a=="object"&&a!==null){let l=a.packages;if(Array.isArray(l))for(let s of l)typeof s=="string"&&n.push(s)}}catch{}let r=sa(pe.join(e,"pnpm-workspace.yaml"),Tf);r!==null&&n.push(...qf(r));let o=[];for(let i of n){if(o.length>=fa)break;let a=i.trim();if(a.length===0)continue;for(;a.startsWith("./");)a=a.slice(2);if(a.startsWith("/")||pe.isAbsolute(a))continue;let l=a.split("/").filter(s=>s.length>0);l.length===0||l.length>Lf||l.includes("..")||o.push(l.join("/"))}return o}function qf(e){let n=[],t=!1;for(let r of e.split(`
|
|
19
|
-
`)){if(n.length>=fa)break;if(/^packages:\s*(#.*)?$/.test(r)){t=!0;continue}if(!t)continue;let o=/^\s+-\s*(.*?)\s*$/.exec(r);if(o===null){r.trim().length>0&&(t=!1);continue}let i=(o[1]??"").trim(),a=i.indexOf(" #");a>=0&&(i=i.slice(0,a).trim()),(i.startsWith('"')&&i.endsWith('"')&&i.length>=2||i.startsWith("'")&&i.endsWith("'")&&i.length>=2)&&(i=i.slice(1,-1)),i.length>0&&n.push(i)}return n}function aa(e,n){let t=pe.relative(n,e);return t.length===0?!1:t.split(pe.sep).includes("node_modules")}function la(e,n){return pe.relative(e,n).split(pe.sep).join("/")}function po(e,n){let t=n?.maxDirs??da,r=n?.maxDepth??ca,o=n?.maxRoots??ua,i=n?.discoverPythonRoots??!0,a;try{a=uo(e)}catch{return{...pa,observations:[{kind:"refused-unreadable",rel:""}]}}let l=[],s=[],d=new Set([a]),u=0,p=0,f=0,h="complete",g=Wf(a).map(v=>v.split("/")),S=v=>{let _="absent";for(let m of jf){let y=yn(pe.join(v,m));if(y==="regular"){_="declared";break}y==="refused"&&(_="refused")}if(_==="absent"&&Kf.some(m=>yn(pe.join(v,m))==="regular")&&(_="listed"),_==="absent")return{candidate:_,witnesses:[]};let k=[];return Bf.some(m=>yn(pe.join(v,m))==="regular")&&k.push("own-lockfile"),zf(pe.join(v,".venv"))&&k.push("installed-env"),{candidate:_,witnesses:k}},E=(v,_)=>{let k=S(v);return k.candidate==="absent"?"not-root":(k.candidate!=="listed"&&(p+=1),k.witnesses.length===0&&k.candidate!=="refused"?(k.candidate==="declared"&&s.push({kind:"undeclared-manifest",rel:_}),"not-root"):l.length>=o?"exhausted":(l.push({rel:_,abs:v,witnesses:k.witnesses,manifestRefused:k.candidate==="refused",ecosystem:"PyPI"}),"root"))},w=(v,_)=>{if(_.length===0){let C=yn(pe.join(v,"package.json"))!=="absent",T=i?S(v):{candidate:"absent",witnesses:[]};return!C&&T.candidate!=="absent"?(l.push({rel:"",abs:v,witnesses:["scan-root",...T.witnesses],manifestRefused:!1,ecosystem:"PyPI"}),"root"):(l.push({rel:"",abs:v,witnesses:["scan-root",...T.witnesses],manifestRefused:!1,...T.witnesses.length>0?{alsoPython:!0}:{}}),"root")}let k=yn(pe.join(v,"package.json"));if(k==="absent")return i?E(v,_):"not-root";p+=1;let m=[],y=_.split("/");g.some(C=>Vf(C,y))&&m.push("workspace-declared"),Ff.some(C=>yn(pe.join(v,C))==="regular")&&m.push("own-lockfile");let A=i?S(v):{candidate:"absent",witnesses:[]};for(let C of A.witnesses)m.includes(C)||m.push(C);return m.length===0&&k!=="refused"?(s.push({kind:"undeclared-manifest",rel:_}),"not-root"):l.length>=o?"exhausted":(l.push({rel:_,abs:v,witnesses:m,manifestRefused:k==="refused",...A.witnesses.length>0?{alsoPython:!0}:{}}),"root")},I=[{abs:a,rel:"",depth:0}];for(;I.length>0;){let v=I.pop();if(v===void 0)break;if(u>=t){h="dirs-exhausted";break}u+=1;let _=w(v.abs,v.rel);if(_==="exhausted"){h="roots-exhausted";break}let k=_==="root";if(v.depth>=r){h=h==="complete"?"depth-clamped":h;continue}let m;try{m=Mf(v.abs)}catch{s.push({kind:"refused-unreadable",rel:v.rel});continue}m.sort().reverse();for(let y of m){let A=pe.join(v.abs,y),C=v.rel.length===0?y:`${v.rel}/${y}`,T;try{let F=Pf(A);T=F.isDirectory()||F.isSymbolicLink()&&ut(A).isDirectory()}catch{continue}if(!T)continue;if(y==="node_modules"){k||s.push({kind:"unenumerated-install",rel:C});continue}if(y.startsWith(".")){f+=1,s.push({kind:"skipped-dot-directory",rel:C}),yn(pe.join(A,"package.json"))!=="absent"&&s.push({kind:"undeclared-manifest",rel:C});continue}let P;try{P=uo(A)}catch{s.push({kind:"refused-unreadable",rel:C});continue}let R=a.endsWith(pe.sep)?a:a+pe.sep;if(P!==a&&!P.startsWith(R)){s.push({kind:"refused-out-of-root",rel:C});continue}aa(P,a)||d.has(P)||(d.add(P),I.push({abs:P,rel:la(a,P),depth:v.depth+1}))}}for(let v of n?.operatorRoots??[]){let _=typeof v=="string"?v.slice(0,512):"",k=()=>{s.push({kind:"refused-operator-root",rel:_})};if(_.length===0||_.includes("\0")){k();continue}let m;try{m=uo(pe.resolve(a,_))}catch{k();continue}let y=a.endsWith(pe.sep)?a:a+pe.sep;if(m!==a&&(!m.startsWith(y)||aa(m,a))){k();continue}let A;try{A=ut(m).isDirectory()}catch{A=!1}if(!A||yn(pe.join(m,"package.json"))!=="regular"){k();continue}let C=l.findIndex(R=>R.abs===m);if(C>=0){let R=l[C];R!==void 0&&!R.witnesses.includes("operator")&&(l[C]={...R,witnesses:[...R.witnesses,"operator"]});continue}let T=la(a,m);l.push({rel:T,abs:m,witnesses:["operator"],manifestRefused:!1});let P=s.findIndex(R=>R.kind==="undeclared-manifest"&&R.rel===T);P>=0&&s.splice(P,1)}return l.sort((v,_)=>v.rel<_.rel?-1:v.rel>_.rel?1:0),s.sort((v,_)=>v.kind!==_.kind?v.kind<_.kind?-1:1:v.rel<_.rel?-1:v.rel>_.rel?1:0),{roots:l,observations:s,budget:h,counts:{dirsWalked:u,manifestsSeen:p,rootsAdmitted:l.length,dotDirectoriesSkipped:f}}}import{lstatSync as ma,readdirSync as Gf,readFileSync as Hf,realpathSync as ya,statSync as xa}from"node:fs";import Ue from"node:path";var Rn={envDir:".venv",maxDistributions:2e4,maxMetadataBytes:1e6,maxRecordBytes:32*1024*1024,maxTopLevelBytes:256*1024,maxDirectUrlBytes:64*1024,maxPyvenvCfgBytes:64*1024},Xf=/^python\d+\.\d+$/u;function Cn(e,n){let t;try{t=xa(e)}catch(r){return{why:r?.code==="ENOENT"?"absent":"unreadable"}}if(!t.isFile())return{why:"not-regular"};if(t.size>n)return{why:"oversize"};try{return{text:Hf(e,"utf8")}}catch{return{why:"unreadable"}}}function mo(e,n){let t;try{if(t=ya(n),!xa(t).isDirectory())return null}catch{return null}return t===e||t.startsWith(e+Ue.sep)?t:null}function ha(e,n){return Ue.relative(e,n).split(Ue.sep).join("/")}function ga(e){try{return Gf(e).sort()}catch{return null}}function Yf(e){let n=null;for(let t of e.split(/\r?\n/u)){let r=/^\s*(version_info|version)\s*=\s*(\S+)\s*$/u.exec(t);if(r!==null){if(r[1]==="version_info")return r[2]??null;n??=r[2]??null}}return n}function ho(e,n){let t=n?.envDir??Rn.envDir,r=n?.maxDistributions??Rn.maxDistributions,o=n?.maxMetadataBytes??Rn.maxMetadataBytes,i=n?.maxRecordBytes??Rn.maxRecordBytes,a=n?.maxTopLevelBytes??Rn.maxTopLevelBytes,l=n?.maxDirectUrlBytes??Rn.maxDirectUrlBytes,s=t,d=[],u=(A,C,T=null)=>({envRel:s,refused:A,sitePackages:[],interpreter:T,distInfos:[],pthFiles:[],unreadable:0,diagnostics:[...d,C],truncated:!1}),p;try{p=ya(e)}catch{return u("absent","the root itself could not be resolved")}let f=Ue.join(p,t),h;try{h=ma(f)}catch(A){return A?.code==="ENOENT"?u("absent",`${s}: absent`):u("not-a-directory",`${s}: could not be inspected`)}if(!h.isDirectory()&&!h.isSymbolicLink())return u("not-a-directory",`${s}: not a directory`);let g=mo(p,f);if(g===null)return u("escapes-root",`${s}: resolves outside the project root (a symlinked environment is not the project's); refused, never followed`);let S=Cn(Ue.join(g,"pyvenv.cfg"),Rn.maxPyvenvCfgBytes),E="text"in S?Yf(S.text):null;"text"in S||d.push(`${s}/pyvenv.cfg: ${S.why} \u2014 interpreter version unknown`);let w=[];for(let A of["lib","lib64"]){let C=ga(Ue.join(g,A));if(C!==null)for(let T of C)Xf.test(T)&&w.push(Ue.join(g,A,T,"site-packages"))}w.push(Ue.join(g,"Lib","site-packages"));let I=[],v=new Set;for(let A of w){let C=mo(g,A);C===null||v.has(C)||(v.add(C),I.push(C))}if(I.length===0)return u("no-site-packages",`${s}: no site-packages directory (lib/pythonX.Y/site-packages or Lib/site-packages)`,E);I.length>1&&d.push(`${s}: ${String(I.length)} site-packages directories; all enumerated`);let _=[],k=[],m=0,y=!1;e:for(let A of I){let C=ha(p,A),T=ga(A);if(T===null){d.push(`${C}: unreadable; nothing enumerated there`);continue}for(let P of T){let R=Ue.join(A,P),F=P.endsWith(".dist-info"),O=P.endsWith(".egg-info");if(P.endsWith(".pth")){let H=Cn(R,0);("text"in H||H.why==="oversize")&&k.push(P);continue}if(!F&&!O)continue;if(_.length>=r){y=!0,d.push(`${C}: the distribution cap (${String(r)}) was hit at ${P}; the enumeration is INCOMPLETE`);break e}let L;try{L=ma(R)}catch{m+=1,d.push(`${C}/${P}: could not be inspected; not enumerated`);continue}let K=F?"dist-info":"egg-info";if(L.isFile()&&O){let H=Cn(R,o);"text"in H?_.push({dir:P,kind:K,metadata:H.text}):(m+=1,d.push(`${C}/${P}: ${H.why}; not enumerated`));continue}let G=mo(g,R);if(G===null){m+=1,d.push(`${C}/${P}: not a directory inside the environment; not enumerated`);continue}let B=F?"METADATA":"PKG-INFO",W=Cn(Ue.join(G,B),o);if(!("text"in W)){m+=1,d.push(`${C}/${P}: ${B} ${W.why}; not enumerated`);continue}let $={dir:P,kind:K,metadata:W.text},q=Cn(Ue.join(G,"top_level.txt"),a);if("text"in q?$.topLevel=q.text:q.why!=="absent"&&d.push(`${C}/${P}/top_level.txt: ${q.why}; ignored`),F){let H=Cn(Ue.join(G,"RECORD"),i);"text"in H?$.record=H.text:d.push(`${C}/${P}/RECORD: ${H.why}; import names from top_level.txt only`);let Ee=Cn(Ue.join(G,"direct_url.json"),l);"text"in Ee&&($.directUrl=Ee.text)}_.push($)}}return{envRel:s,refused:null,sitePackages:I.map(A=>ha(p,A)),interpreter:E,distInfos:_,pthFiles:k,unreadable:m,diagnostics:d,truncated:y}}var Qf=["uv.lock","poetry.lock","Pipfile.lock","pdm.lock"];function ep(e,n){for(let t of n)try{if(Jf(Zf.join(e,t)).isFile())return t}catch{}return null}function Sa(e){let n=[],t=[],r=(p,f)=>{t.push({kind:p,detail:f,blindsAnalysis:!1,rootRel:""}),n.push(f)},o=ep(e,Qf),i=ho(e);if(i.refused!==null){let p=i.refused==="absent"?`no \`${i.envRel}\` is installed`:`\`${i.envRel}\` could not be read (${i.refused})`;return r("no-installed-env",`${o??"the Python manifest"} declares a dependency set but ${p}: ZERO distributions were enumerated, so this scan reports nothing about Python dependencies \u2014 it is not a clean bill of health. Install the environment (\`uv sync\`) and re-scan.`),{packages:[],source:"none",lockfilePath:o,diagnostics:[...n,...i.diagnostics],truncated:!1,gaps:t}}let a=[],l=new Set,s=[],d=0;for(let p of i.distInfos){let f=co(p.metadata,{...p.topLevel!==void 0?{topLevelText:p.topLevel}:{},...p.record!==void 0?{recordText:p.record}:{},...p.directUrl!==void 0?{directUrlText:p.directUrl}:{}});if(f===null){d+=1,n.push(`${p.dir}: METADATA carries no Name/Version; not enumerated`);continue}let h=JSON.stringify([f.name,f.version]);l.has(h)||(l.add(h),f.importNames.length===0&&s.push(f.name),a.push({name:f.name,version:f.version,lockKey:"",dev:!1,declaredIn:"",ecosystem:"PyPI"}))}n.push(...i.diagnostics);let u=i.unreadable+d;return u>0&&r("installed-env-partial",`${String(u)} entr${u===1?"y":"ies"} under ${i.sitePackages.join(", ")} could not be read as a distribution (see the diagnostics): those distributions are MISSING from this scan; the ${String(a.length)} enumerated were assessed normally.`),i.truncated&&r("installed-env-partial",`the environment walk under ${i.sitePackages.join(", ")} hit its distribution cap: the enumeration is INCOMPLETE, and a partial (possibly false-clean) set is never reported.`),s.length>0&&n.push(`${String(s.length)} distribution(s) carry no import name (distribution-unmapped, Tier-B): ${s.slice(0,5).join(", ")}${s.length>5?", \u2026":""} \u2014 advisories on them are enumerated; their modules cannot be resolved (ADR-109 D5)`),{packages:a,source:a.length>0?"installed-env":"none",lockfilePath:o,diagnostics:n,truncated:i.truncated,gaps:t}}var np=128*1024*1024,tp=[{file:"package-lock.json",source:"npm-lockfile",parse:(e,n)=>Yt(e,n===void 0?{}:{maxEntries:n})},{file:"npm-shrinkwrap.json",source:"npm-lockfile",parse:(e,n)=>Yt(e,n===void 0?{}:{maxEntries:n})},{file:"yarn.lock",source:"yarn-lockfile",parse:(e,n)=>io(e,n===void 0?{}:{maxEntries:n})},{file:"pnpm-lock.yaml",source:"pnpm-lockfile",parse:(e,n)=>lo(e,n===void 0?{}:{maxEntries:n})}],rp=[".pnp.cjs",".pnp.data.json",".pnp.js"];function xo(e,n){let t;try{t=yo(He.join(e,n))}catch{return null}let r=e.endsWith(He.sep)?e:e+He.sep;return t.startsWith(r)?t:null}function ka(e,n){let t=He.join(e,"package.json"),r;try{r=yo(t)}catch{return null}if(!r.startsWith(n+He.sep))return null;try{if(!ft(r).isFile())return null;let o=JSON.parse(go(r,"utf8"));return typeof o.name!="string"||typeof o.version!="string"?null:{name:o.name,version:o.version}}catch{return null}}function Ea(e,n){try{return ft(He.join(e,n)),!0}catch{return!1}}function op(e,n){if(Ea(e,"pnpm-workspace.yaml"))return!0;let t=xo(e,"package.json");if(t===null)return Ea(e,"package.json");let r;try{let a=ft(t);if(!a.isFile()||a.size>n)return!0;r=go(t,"utf8")}catch{return!0}let o;try{o=JSON.parse(r)}catch{return!0}for(let a of["dependencies","devDependencies","optionalDependencies","peerDependencies"]){let l=o[a];if(typeof l=="object"&&l!==null&&Object.keys(l).length>0)return!0}let i=o.workspaces;return Array.isArray(i)?i.length>0:typeof i=="object"&&i!==null}function wa(e,n){let t=He.join(e,"node_modules"),r=[],o;try{o=ba(t,{withFileTypes:!0})}catch{return r}for(let i of o){let a=i.name;if(a.startsWith("."))continue;if(a.startsWith("@")){let s;try{s=ba(He.join(t,a),{withFileTypes:!0})}catch{continue}for(let d of s){let u=ka(He.join(t,a,d.name),n);u!==null&&r.push({dev:!1,name:u.name,version:u.version,lockKey:`node_modules/${a}/${d.name}`,linked:d.isSymbolicLink()||i.isSymbolicLink()})}continue}let l=ka(He.join(t,a),n);l!==null&&r.push({dev:!1,name:l.name,version:l.version,lockKey:`node_modules/${a}`,linked:i.isSymbolicLink()})}return r}var ip=5;function sp(e,n,t){let r=xo(e,n);if(r===null){try{ft(He.join(e,n))}catch{return null}return{gap:`${n} resolves outside the scan root (symlink); refused, not read`}}let o;try{o=ft(r)}catch{return null}if(!o.isFile())return{gap:`${n} is not a regular file; refused, not read`};if(o.size>t)return{gap:`${n} is ${String(o.size)} bytes (> ${String(t)}); skipped before reading to avoid a memory DoS`};try{return{text:go(r,"utf8")}}catch{return{gap:`${n} could not be read`}}}function ap(e,n){let t=yo(e),r=[],o=[],i=n?.maxLockfileBytes??np,a=[],l=new Set,s=[],d=op(t,i),u=null,p=!1,f=(g,S,E)=>{o.push({kind:g,detail:S,blindsAnalysis:E,rootRel:""}),r.push(S)};for(let g of tp){let S=sp(t,g.file,i);if(S===null)continue;if("gap"in S){f("lockfile-unreadable",S.gap,!1);continue}let E=g.parse(S.text,n?.maxLockfileEntries);if(E.truncated&&(p=!0),E.deps.length===0){if(E.diagnostics.length>0||d){let w=E.diagnostics.length>0?E.diagnostics.join("; "):"no entries found";f("lockfile-unparsed",`${g.file} yielded NO dependencies (${w}); its transitive dependency set was not enumerated`,!1)}continue}E.diagnostics.length>0&&f("lockfile-partial",`${g.file} was only partly enumerated (${E.diagnostics.join("; ")})`,!1),u===null&&(u=g.file),s.includes(g.source)||s.push(g.source);for(let w of E.deps){let I=JSON.stringify([w.name,w.version,w.lockKey]);l.has(I)||(l.add(I),a.push({...w,declaredIn:g.file}))}}for(let g of rp)if(xo(t,g)!==null){f("yarn-pnp",`${g} present: this project uses Yarn Plug'n'Play, whose dependency code lives in zips cupel does not resolve or read \u2014 NO dependency code was analyzed, so no finding here can be read as not-reachable. Set \`nodeLinker: node-modules\` for a full scan.`,!0);break}if(a.length>0){let g=s.length===1?s[0]??"none":"multi-lockfile";s.length>1&&r.push(`multiple lockfiles present (${s.join(", ")}); enumerated the UNION of all of them`);let S=new Set(a.map(I=>JSON.stringify([I.name,I.version]))),E=new Set,w=[];for(let I of wa(t,t)){let v=JSON.stringify([I.name,I.version,I.lockKey]);l.has(v)||(l.add(v),a.push({name:I.name,version:I.version,lockKey:I.lockKey,dev:I.dev,declaredIn:""}));let _=JSON.stringify([I.name,I.version]);I.linked||S.has(_)||E.has(_)||(E.add(_),w.length<ip&&w.push(dt(I.name,I.version)))}if(E.size>0){let I=E.size-w.length;f("lockfile-skew",`node_modules holds ${String(E.size)} package(s) at a (name, version) no lockfile lists (${w.join(", ")}${I>0?`, and ${String(I)} more`:""}): ${u??"the lockfile"} and the installed tree DISAGREE, so cupel enumerated BOTH. A stale lockfile or an \`npm i --no-save\` is the usual cause \u2014 re-install and commit the lockfile so the reviewed set is the installed set.`,!1)}return{packages:a,source:g,lockfilePath:u,diagnostics:r,truncated:p,gaps:o}}let h=wa(t,t);return h.length>0?(f("shallow-node-modules",`no usable lockfile (package-lock.json / npm-shrinkwrap.json / yarn.lock / pnpm-lock.yaml), so the installed set came from a SHALLOW node_modules scan: ${String(h.length)} top-level package(s), with every transitive dependency missing. Commit a lockfile for a complete scan.`,!1),{packages:h.map(g=>({name:g.name,version:g.version,lockKey:g.lockKey,dev:!1,declaredIn:""})),source:"node-modules",lockfilePath:null,diagnostics:r,truncated:p,gaps:o}):(d&&f("no-enumeration","package.json declares dependencies but there is no lockfile and no readable node_modules: ZERO packages were enumerated, so this scan reports nothing about dependencies \u2014 it is not a clean bill of health. Install the project (or commit a lockfile) and re-scan.",!1),{packages:[],source:"none",lockfilePath:null,diagnostics:r,truncated:p,gaps:o})}function lp(e){return e.rel===""||e.witnesses.includes("own-lockfile")||e.witnesses.includes("operator")||e.witnesses.includes("installed-env")||e.manifestRefused}function dp(e){if(e.length===0||e==="."||e==="..")return!1;for(let n=0;n<e.length;n+=1){let t=e.charCodeAt(n);if(t<32||t===127||t>=128&&t<=159||t===92)return!1}return!0}function Ia(e){return e===""||e.split("/").every(dp)}function cp(e,n){if(e===""||n==="")return n;if(!Ia(e))return"";let t=`${e}/${n}`;return t.length<=Xt?t:""}function va(e,n){return e===""?n:`${e}: ${n}`}function up(e){return{rel:"",abs:e,witnesses:["scan-root"],manifestRefused:!1}}function Aa(e,n,t){let r=t?.maxUnionEntries??Ht,o=n.roots.filter(lp),i=o.some(g=>g.rel==="")?o:[up(e),...o],a=[],l=[],s=new Set,d=[],u=[],p=!1,f=!1;for(let g of i){let S=g.rel===""?e:g.abs,E=ap(S,t),w=fo(g)?Sa(S):null,I=w===null?E:mp(E,w),v=I.diagnostics.map(k=>va(g.rel,k));!Ia(g.rel)&&I.packages.length>0&&v.push(`${g.rel}: its path holds a segment no install key may be built from, so the install location of its ${String(I.packages.length)} row(s) is refused \u2014 dependency-class evidence and execution context for them read fail-closed (ADR-071)`);let _={...I,rootRel:g.rel,...g.ecosystem!==void 0?{ecosystem:g.ecosystem}:{},...w!==null?{pythonLockfilePath:w.lockfilePath===null||g.rel===""?w.lockfilePath:`${g.rel}/${w.lockfilePath}`}:{},packages:I.packages.map(k=>({...k,lockKey:cp(g.rel,k.lockKey),declaredIn:k.declaredIn===""||g.rel===""?k.declaredIn:`${g.rel}/${k.declaredIn}`})),lockfilePath:I.lockfilePath===null||g.rel===""?I.lockfilePath:`${g.rel}/${I.lockfilePath}`,gaps:I.gaps.map(k=>({...k,rootRel:g.rel,detail:va(g.rel,k.detail)})),diagnostics:v};a.push(_),I.truncated&&(p=!0);for(let k of _.packages){let m=JSON.stringify([k.name,k.version,k.lockKey]);if(!s.has(m)){if(l.length>=r){f=!0;break}s.add(m),l.push(k)}}d.push(..._.gaps),u.push(..._.diagnostics)}f&&(p=!0,u.push(`the union of installed sets across ${String(i.length)} roots exceeds its ceiling of ${String(r)} distinct rows; truncated \u2014 a partial enumeration is never reported (ADR-071)`));let h=a[0];if(h===void 0)throw new Error("unreachable: the scan root is always enumerated");return{packages:l,source:h.source,lockfilePath:h.lockfilePath,diagnostics:u,truncated:p,gaps:d,perRoot:a}}function fp(e,n){let t;for(let r of e.perRoot){if(r.rootRel===""){t??=r;continue}n.startsWith(`${r.rootRel}/`)&&(t===void 0||r.rootRel.length>t.rootRel.length)&&(t=r)}return t}function Qt(e,n){return n.declaredIn!==""?n.declaredIn:fp(e,n.lockKey)?.lockfilePath??null}function _a(e,n){let t=e.perRoot.find(r=>r.rootRel===n.rootRel);return pp.has(n.kind)?t?.pythonLockfilePath!==void 0&&t.pythonLockfilePath!==null?t.pythonLockfilePath:n.rootRel===""?null:`${n.rootRel}/pyproject.toml`:t?.lockfilePath!==void 0&&t.lockfilePath!==null?t.lockfilePath:n.rootRel===""?null:`${n.rootRel}/${t?.ecosystem==="PyPI"?"pyproject.toml":"package.json"}`}var pp=new Set(["no-installed-env","installed-env-partial"]);function mp(e,n){return{packages:[...e.packages,...n.packages],source:e.packages.length===0&&n.packages.length>0?n.source:e.source,lockfilePath:e.lockfilePath??n.lockfilePath,diagnostics:[...e.diagnostics,...n.diagnostics],truncated:e.truncated||n.truncated,gaps:[...e.gaps,...n.gaps]}}function Na(e){let n=new Map;for(let t of e){let r=n.get(t.name)??new Set;r.add(t.version),n.set(t.name,r)}return t=>{let r=n.get(t);if(r===void 0)return;let o=[...r].sort();return o.length===1?o[0]:o}}function pt(e){return new Set(e.map(n=>n.root))}function qn(e,n){let t=pt(n);return e.roots.filter(r=>!t.has(r.rel)&&(r.rel===""||r.ecosystem!=="PyPI"))}function So(e){let n=e.slice(0,8),t=e.length-n.length;return n.join(", ")+(t>0?`, \u2026 and ${String(t)} more`:"")}function bo(e,n){return qn(e,n).map(t=>({code:"unanalyzed-project-root",path:t.rel===""?".":t.rel,detail:t.rel===""?`the scan root declares no entrypoint of its own (${t.witnesses.join(" + ")}) \u2014 its code, if any, was not analyzed while a nested root's was; pass \`--entry <file>\` or declare \`main\`, else every \`not-reachable\` is capped at \`unknown\` (ADR-071)`:`\`${t.rel}\` is a project root (${t.witnesses.join(" + ")}${t.manifestRefused?", manifest refused":""}) this scan did not analyze; code there can load any installed package, so every \`not-reachable\` is capped at \`unknown\` until it is analyzed (ADR-071)`}))}function Ra(e){let n=[],t=e.observations.filter(r=>r.kind==="unenumerated-install").map(r=>r.rel);if(t.length>0&&n.push({kind:"unenumerated-install",detail:`${String(t.length)} node_modules director${t.length===1?"y":"ies"} under no admitted project root (${So(t)}) were not enumerated: packages installed there are MISSING from this scan. The enumerated ones were analyzed normally (ADR-071)`,blindsAnalysis:!1,rootRel:""}),e.budget!=="complete"){let r=e.counts;n.push({kind:"root-discovery-truncated",detail:`root discovery did not finish (${e.budget}: ${String(r.dirsWalked)} dirs walked, ${String(r.rootsAdmitted)} roots admitted) \u2014 a project root with its own install location may have been missed, so every \`not-reachable\` is capped at \`unknown\` (ADR-071 Invariant C)`,blindsAnalysis:!0,rootRel:""})}return n}function Ca(e){let n=new Set;for(let t of e)t.blindsAnalysis&&n.add(t.kind==="root-discovery-truncated"?"analysis-cap":"resolution-divergence");return[...n]}import{readdirSync as hp,readFileSync as gp}from"node:fs";import yp from"node:path";var xp=new Set(["summarized","crashed","over-cap"]),Sp=new Set(["function","method","ctor"]);function me(e,n){throw new Error(`summary facts file ${e}: ${n}`)}function ko(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function bp(e,n){ko(e)||me(n,"edge is not an object");let{entryPath:t,entryExport:r,entryContainer:o,hops:i}=e;(typeof t!="string"||typeof r!="string")&&me(n,"edge entry fields must be strings"),o!==null&&typeof o!="string"&&me(n,"entryContainer must be string or null"),(typeof i!="number"||!Number.isInteger(i)||i<0)&&me(n,"hops must be a non-negative integer");let a=e.target;if(ko(a)||me(n,"edge target missing"),a.kind==="symbol"){let{exportName:l,container:s,symbolKind:d}=a;return typeof l!="string"&&me(n,"symbol target exportName"),s!==null&&typeof s!="string"&&me(n,"symbol target container"),(typeof d!="string"||!Sp.has(d))&&me(n,`symbol target kind ${JSON.stringify(d)}`),{entryPath:t,entryExport:r,entryContainer:o,target:{kind:"symbol",exportName:l,container:s,symbolKind:d},hops:i}}if(a.kind==="dep"){let{calleePackage:l,calleeSubpath:s,calleeExport:d}=a;return(typeof l!="string"||l.length===0)&&me(n,"dep target calleePackage"),s!==null&&typeof s!="string"&&me(n,"dep target calleeSubpath"),(typeof d!="string"||d.length===0)&&me(n,"dep target calleeExport"),{entryPath:t,entryExport:r,entryContainer:o,target:{kind:"dep",calleePackage:l,calleeSubpath:s,calleeExport:d},hops:i}}me(n,`unknown target kind ${JSON.stringify(a.kind)}`)}function kp(e,n){ko(e)||me(n,"root is not an object");let{packageName:t,analyzedVersion:r,tool:o,toolVersion:i,maxIndirections:a,status:l}=e;(typeof t!="string"||t.length===0)&&me(n,"packageName"),typeof r!="string"&&me(n,"analyzedVersion"),o!=="jelly"&&me(n,`tool ${JSON.stringify(o)} (only 'jelly' exists)`),typeof i!="string"&&me(n,"toolVersion"),typeof a!="number"&&me(n,"maxIndirections"),(typeof l!="string"||!xp.has(l))&&me(n,`status ${JSON.stringify(l)} not in the enum`);let s=e.edges;return Array.isArray(s)||me(n,"edges is not an array"),l!=="summarized"&&s.length>0&&me(n,`status='${l}' with edges (CS-W6: edge rows only under summarized)`),{packageName:t,analyzedVersion:r,tool:o,toolVersion:i,maxIndirections:a,status:l,edges:s.map(d=>bp(d,n))}}function Oa(e){let n=new Map,t=hp(e).filter(r=>r.endsWith(".summary.json"));for(let r of t){let o=yp.join(e,r),i;try{i=JSON.parse(gp(o,"utf8"))}catch(s){me(r,`unparseable JSON: ${s instanceof Error?s.message:String(s)}`)}let a=kp(i,r),l=n.get(a.packageName);l===void 0?n.set(a.packageName,[a]):l.push(a)}return n}import{isBuiltin as Pa}from"node:module";function U(e){let n="";for(let t of e){let r=t.charCodeAt(0),o=r<32||r>=127&&r<=159;n+=o?"\\x"+r.toString(16).padStart(2,"0"):t}return n}var $a=1024,Ma=4096,er=8,Da=512,Ta=512,Eo=8,Ep=160,wp=new Set(["unresolved-specifier","declaration-shadow","unresolved-reexport","unanalyzable-module"]),wo=new Set(["limit-exceeded","parse-error","unsupported-syntax"]),vp=/^(@[^/@\s]+\/)?[^/@\s.][^/\s]*$/u,Ip=/\.[cm]?[jt]sx?$/u;function La(e,n){let t=n.get(e);if(t!==void 0)return t.packageName;let r=e.lastIndexOf("node_modules/");if(r!==-1){let o=e.slice(r+13).split("/"),i=o[0]??"";return i.startsWith("@")?o[1]===void 0?null:`${i}/${o[1]}`:i===""?null:i}return vp.test(e)&&!Ip.test(e)?e:null}function Ap(e){return U(`${e.code} ${e.path}: ${e.detail}`.slice(0,Ep))}function Fa(e){let{graph:n,facts:t,diagnostics:r}=e,o=new Map(n.modules.map(M=>[M.id,M])),i=new Map(n.modules.map(M=>[M.path,M])),a=Ze(n),l=new Set;for(let M of a){let J=o.get(M);J!==void 0&&l.add(J.packageName)}let s=new Map,d=0,u=!1,p=!1,f=M=>M.startsWith(`${e.appRootReal}/`)?M.slice(e.appRootReal.length+1):M;for(let M of r){if(M.code==="limit-exceeded"&&M.path===e.appRootReal){u=!0;continue}let J=La(f(M.path),i);if(J===null){M.code==="out-of-root"&&d++,wo.has(M.code)&&(p=!0);continue}let oe=i.get(f(M.path));oe!==void 0&&wo.has(M.code)&&!oe.path.includes("node_modules/")&&(p=!0);let ie=s.get(J);ie===void 0?s.set(J,[M]):ie.push(M)}let h=new Map(n.imports.map(M=>[M.id,M])),g=new Set;for(let M of n.importEdges){let J=h.get(M.importId);J!==void 0&&o.get(J.moduleId)?.externalSurface===!0&&g.add(J.moduleId)}let S=[],E=new Set,w=n.modules.filter(M=>M.externalSurface===!0);for(let M of w){let J=s.get(M.packageName)??[],oe=g.has(M.id),ie=[],rn=ne=>ne.code==="dependency-body"&&ne.anchor===void 0&&/syntax/u.test(ne.detail),bn=ne=>ne.code==="loader-escape"||ne.code==="dependency-body"&&ne.anchor===void 0&&!/syntax/u.test(ne.detail),x=J.filter(ne=>wp.has(ne.code)),N=J.filter(bn),D=J.filter(ne=>wo.has(ne.code)||rn(ne)),j=J.filter(ne=>ne.code==="out-of-root"),Y=oe&&x.length===0,Z=N.length===0,te=!u&&D.length===0,ue=d===0&&j.length===0;oe||ie.push("(a) the package's entry was never followed to a module");for(let ne of[...x,...N,...D,...j]){if(ie.length>=Eo)break;ie.push(Ap(ne))}u&&ie.length<Eo&&ie.push("(c) the dependency module closure hit its cap \u2014 every follow is truncated"),d>0&&ie.length<Eo&&ie.push(`(d) ${String(d)} out-of-root diagnostic(s) no package can be read from`);let de=["a","b","c","d"].filter(ne=>!{a:Y,b:Z,c:te,d:ue}[ne]),fe=de.length===0;fe&&E.add(M.id),S.push({packageName:U(M.packageName),module:U(String(M.id)),inReach:a.has(M.id),builtin:Pa(M.packageName),followed:oe,d1:{a:Y,b:Z,c:te,d:ue},failing:de,transparent:fe,evidence:ie})}let I=new Set;for(let M of t)M.reach.kind==="unbounded"&&I.add(M.source);let v=M=>({module:U(String(M.module)),kind:M.kind,packageName:o.get(M.module)?.packageName??null}),_=new Set(w.filter(M=>Pa(M.packageName)).map(M=>M.id)),k=new Set([...E,..._]),m=[],y=new Map,A=0,C=0,T=0,P=0,R=[],F=new Set;for(let M of t)M.reach.kind==="unbounded"&&F.add(M.cause);for(let M of t){if(M.reach.kind==="class-scope"){R.push({packageName:M.reach.packageName,container:M.reach.container});continue}if(M.reach.kind==="unbounded")continue;P++;let J=M.reach.anchor,oe=y.get(String(J));oe===void 0&&(oe={today:Yn(n,J,I),d1:Yn(n,J,I,E),d1Builtins:Yn(n,J,I,k)},y.set(String(J),oe)),oe.d1Builtins.length>0&&T++,oe.today.length>0&&(A++,F.add(M.cause)),oe.d1.length>0&&C++,m.length<Ma&&m.push({anchor:U(String(J)),packageName:U(o.get(J)?.packageName??""),cause:M.cause,reachKind:M.reach.kind,blockersToday:oe.today.slice(0,er).map(v),blockersUnderD1:oe.d1.slice(0,er).map(v),blockedUnderD1Builtins:oe.d1Builtins.length>0,moreToday:Math.max(0,oe.today.length-er),moreUnderD1:Math.max(0,oe.d1.length-er)})}let O=r.filter(M=>M.anchor===void 0&&M.classScope===void 0),L=new Map(e.loadSites.map(M=>[M.importId,M])),K=new Map;for(let M of e.loadSites){let J=K.get(M.path);J===void 0?K.set(M.path,[M.shape]):J.push(M.shape)}let G=M=>{if(M.code!=="loader-escape")return!1;let J=M.escapes??[];if(J.length===0||J.some(ie=>ie!=="non-literal-load"))return!1;let oe=K.get(M.path)??[];return oe.length>0&&oe.every(ie=>ie==="relative-bounded")},B=O.slice(0,Ta).map(M=>({cause:e.causeOf(M.code),code:M.code,path:U(f(M.path)),attributedPackage:La(f(M.path),i),...M.escapes!==void 0?{escapes:[...M.escapes]}:{},...M.reason!==void 0?{reason:M.reason}:{},d2Dischargeable:G(M)})),W={};for(let M of O){if(M.code!=="unresolved-specifier")continue;let J=M.reason??"(none)";W[J]=(W[J]??0)+1}let $=I.size===0?0:t.filter(M=>M.reach.kind==="unbounded").length,q=Math.max(0,$-O.length),H=$-O.filter(G).length,Ee=[],he=0,ve=0,Sn=0;for(let M of n.imports){if(M.specifierIsLiteral)continue;Sn++;let J=a.has(M.moduleId),oe=L.get(String(M.id)),ie=oe?.shape??"unrecorded";J&&(he++,ie==="relative-bounded"&&ve++),Ee.length<Da&&Ee.push({importId:U(String(M.id)),path:U(o.get(M.moduleId)?.path??""),shape:ie,text:U(oe?.text??""),inReach:J})}return{report:{adr:"ADR-105",aborted:e.analysisAborted,rootBudget:e.rootBudget,closureCapHit:u,appCapHit:p,unattributedOutOfRoot:d,blindUnbounded:q,unbounded:B,anchors:m,surfaces:S.slice(0,$a),loads:Ee,counts:{modules:n.modules.length,reachMods:a.size,surfaces:w.length,surfacesInReach:S.filter(M=>M.inReach).length,transparentSurfaces:E.size,builtinSurfaces:_.size,anchors:P,anchorsBlockedToday:A,anchorsBlockedUnderD1:C,anchorsBlockedUnderD1Builtins:T,unbounded:$,loadsInReach:he,loadsRelativeBounded:ve,unresolvedByReason:W,conditionUnions:e.conditionUnions.length,provenAbsent:e.provenAbsent.length},truncated:{surfaces:Math.max(0,S.length-$a),anchors:Math.max(0,P-Ma),loads:Math.max(0,Sn-Da),unbounded:Math.max(0,O.length-Ta)}},reachedPackages:l,aborted:e.analysisAborted,unboundedFacts:$,unboundedHard:H,anchorsBlockedToday:A,anchorsBlockedUnderD1:C,anchorsBlockedUnderD1Builtins:T,loadsInReach:he,loadsAllBounded:he>0&&ve===he,d2Eligible:e.rootBudget==="complete"&&!p&&!u,classScope:R,taintCausesToday:F}}var _p=new Set(["unverified-symbol","db-gap","symbol-unsupported","incomplete-surface"]),Np=["no-entrypoint","dynamic-load","resolution-divergence","analysis-cap","dep-opaque"];function ja(e,n,t,r,o){if(t===null||e.reachedPackages.has(t.packageName))return;let i=e.classScope.some(A=>A.packageName===t.packageName&&A.container===t.container),a=e.aborted!==null||e.unboundedFacts>0||e.anchorsBlockedToday>0||i,l=t.symbolKind==="method"||t.symbolKind==="ctor",d=!t.verified||t.symbolKind==="accessor"||t.symbolKind==="pattern"||l||n.unknownKind!==void 0&&_p.has(n.unknownKind)?"pre-2b":n.tier==="not-reachable"?"denial":e.loadsInReach>0?"load":a?"taint":r>0?"oog":"unexpected",u=new Set(e.taintCausesToday);i&&u.add("dep-opaque");let p=e.aborted!==null?e.aborted:Np.find(A=>u.has(A)),f=d==="pre-2b"?n.tier==="unknown"&&(l?n.unknownKind==="dep-opaque":!0):d==="denial"?n.tier==="not-reachable":d==="load"?n.tier==="unknown"&&n.unknownKind==="dynamic-load":d==="taint"?n.tier==="unknown"&&n.unknownKind===p:d==="oog"?n.tier==="unknown"&&n.unknownKind==="analysis-cap":!1,h=t.verified&&o===!0,g=e.aborted===null&&e.unboundedFacts===0&&!i&&r===0,S=e.loadsInReach===0||e.d2Eligible&&e.loadsAllBounded,E=h&&d==="taint"&&g&&e.loadsInReach===0&&e.anchorsBlockedUnderD1===0,w=h&&d==="load"&&g&&e.d2Eligible&&e.loadsAllBounded&&e.anchorsBlockedToday===0,I=h&&(d==="load"||d==="taint")&&g&&S&&e.anchorsBlockedUnderD1===0,v=e.aborted===null&&e.unboundedHard===0&&!i&&r===0,_=h&&d==="load"&&v&&e.d2Eligible&&e.loadsAllBounded&&e.anchorsBlockedToday===0,k=h&&(d==="load"||d==="taint")&&v&&S&&e.anchorsBlockedUnderD1===0,m=h&&d==="taint"&&g&&e.loadsInReach===0&&e.anchorsBlockedUnderD1Builtins===0,y=h&&(d==="load"||d==="taint")&&v&&S&&e.anchorsBlockedUnderD1Builtins===0;return{unloaded:!0,exit:d,agrees:f,verified:t.verified,surfaceComplete:o,oog:r,classScoped:i,predicted:{d1:E,d2:w,d1d2:I,d2Amended:_,d1d2Amended:k,d1Builtins:m,d1d2AmendedBuiltins:y}}}import{readFileSync as Rp,statSync as Cp}from"node:fs";var Io=/^(@[A-Za-z0-9_.-]{1,100}\/)?[A-Za-z0-9_.-]{1,100}$/u,nr=/^[A-Za-z0-9_$.-]{1,128}$/u,Ka=64,Ba=1024*1024,za=/^(0|\d{1,10}\.\d{1,10}\.\d{1,10})$/u,Ua=/^[A-Za-z0-9@_.-]{1,128}$/u;function xe(e){throw new Error(`model claims rejected: ${e}`)}function vo(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Op(e,n){vo(e)||xe(`${n}: edge is not an object`);let{kind:t,anchorExport:r,anchorContainer:o,calleePackage:i,calleeContainer:a,calleeExport:l}=e;return t!=="alias"&&t!=="dispatch"&&xe(`${n}: edge kind`),(typeof r!="string"||!nr.test(r))&&xe(`${n}: anchorExport ${JSON.stringify(r)}`),o!==null&&(typeof o!="string"||!nr.test(o))&&xe(`${n}: anchorContainer`),(typeof i!="string"||!Io.test(i))&&xe(`${n}: calleePackage ${JSON.stringify(i)}`),a!==null&&(typeof a!="string"||!nr.test(a))&&xe(`${n}: calleeContainer`),(typeof l!="string"||!nr.test(l))&&xe(`${n}: calleeExport ${JSON.stringify(l)}`),{kind:t,anchorExport:r,anchorContainer:o,calleePackage:i,calleeContainer:a,calleeExport:l}}function Va(e){let n=Cp(e).size;n>Ba&&xe(`file is ${String(n)} bytes, over the ${String(Ba)} cap`);let t;try{t=JSON.parse(Rp(e,"utf8"))}catch(o){xe(`unparseable JSON: ${o instanceof Error?o.message:String(o)}`)}Array.isArray(t)||xe("root is not an array"),t.length>Ka&&xe(`${String(t.length)} claims over cap ${String(Ka)}`);let r=[];for(let o of t){vo(o)||xe("claim is not an object");let{packageName:i,modelId:a,range:l,edges:s}=o;(typeof i!="string"||!Io.test(i))&&xe("packageName"),(typeof a!="string"||!Ua.test(a))&&xe("modelId (identifier charset, 1-128 chars)"),r.some(u=>u.model.modelId===a)&&xe(`duplicate modelId ${a} \u2014 the V5 promote\u2192claim join must be unambiguous`),(!vo(l)||typeof l.introduced!="string")&&xe(`${a}: range`),za.test(l.introduced)||xe(`${a}: range.introduced ${JSON.stringify(l.introduced)} is not '0' or an exact x.y.z triple`);let d=l.fixedBefore;d!==null&&typeof d!="string"&&xe(`${a}: fixedBefore`),typeof d=="string"&&!za.test(d)&&xe(`${a}: range.fixedBefore ${JSON.stringify(d)} is not an exact x.y.z triple`),Array.isArray(s)||xe(`${a}: edges`),s.length>64&&xe(`${a}: ${String(s.length)} edges over cap ${String(64)}`),r.push({model:{packageName:i,modelId:a,edges:s.map(u=>Op(u,a))},introduced:l.introduced,fixedBefore:d})}return r}var Pp=["in-app-purchase@1-v1"];function Ao(e,n,t){let r=[],o=[],i=[],a=(l,s,d,u)=>{o.push(d),i.push({modelId:u??l.model.modelId,status:s,reason:d,edgeCount:l.model.edges.length})};for(let l of e){if(!Io.test(l.model.packageName)||!Ua.test(l.model.modelId)){a(l,"refused","model (unprintable id): hostile-shaped packageName/modelId \u2014 refused WHOLE","(unprintable id)");continue}if(t?.shadowConsultDenylisted!==!0&&Pp.includes(l.model.modelId)){a(l,"denylisted",`model ${l.model.modelId}: DENYLISTED (ADR-081 F-081-A a-prime) \u2014 dropped, never consulted`);continue}if(l.model.edges.some(u=>u.kind!=="alias"&&u.kind!=="dispatch")){a(l,"refused",`model ${l.model.modelId}: unknown edge kind \u2014 refused WHOLE`);continue}let s=n(l.model.packageName);if(typeof s!="string"&&s!==void 0){a(l,"inert",`model ${l.model.modelId}: anchor ${l.model.packageName} installed at more than one version (${s.join(", ")}) \u2014 inert, never guessed (ADR-071)`);continue}if(s===void 0){a(l,"inert",`model ${l.model.modelId}: anchor ${l.model.packageName} not installed \u2014 inert`);continue}let d;try{d=En(s,{advisoryId:l.model.modelId,packageName:l.model.packageName,introduced:l.introduced,...l.fixedBefore!==null?{fixed:l.fixedBefore}:{},surfaceComplete:!1})}catch{a(l,"inert",`model ${l.model.modelId}: installed ${l.model.packageName}@${s} not an exact triple \u2014 inert (never guessed)`);continue}if(!d){a(l,"inert",`model ${l.model.modelId}: installed ${l.model.packageName}@${s} outside [${l.introduced}, ${l.fixedBefore??"\u221E"}) \u2014 inert`);continue}r.push(l.model),i.push({modelId:l.model.modelId,status:"active",reason:null,edgeCount:l.model.edges.length})}return{models:r,notes:o,dispositions:i}}var Mp=4,Dp={additiveForms:!0,namelessExports:!0},Tp=new Set(["dep-opaque","dynamic-load","dispatch"]),Lp={base:new Set(["symbol-reachable"]),widened:new Set(["symbol-reachable","call-path-confirmed"])};function Ro(e,n,t){return e.tier==="unknown"&&Lp[t].has(e.decidedAtStage)&&e.unknownKind!==void 0&&Tp.has(e.unknownKind)&&n!==null&&n.verified}var Fp=()=>({"not-affected":0,"not-reachable":0,"reachable-high":0,"reachable-medium":0,"reachable-low":0,unknown:0}),Xe=class extends Error{},Co="cupel/coverage-gap",Za={"loader-escape":"dynamic-load","out-of-root":"resolution-divergence","unresolved-specifier":"resolution-divergence","declaration-shadow":"resolution-divergence","unanalyzable-module":"resolution-divergence","unresolved-reexport":"resolution-divergence","limit-exceeded":"analysis-cap","parse-error":"analysis-cap","unsupported-syntax":"analysis-cap","unresolved-launch-entry":"analysis-cap","unresolved-entry-declaration":"analysis-cap","framework-derived-entry":"analysis-cap","unanalyzed-project-root":"no-entrypoint","dependency-body":"dep-opaque","dep-class-corridor":"dep-opaque"};function ht(e,n,t){return{advisoryId:e,packageName:n,...t.ecosystem==="PyPI"?{ecosystem:"PyPI"}:{},introduced:t.introduced??"0",...t.fixed!==null?{fixed:t.fixed}:{},...t.lastAffected!==null?{lastAffected:t.lastAffected}:{},surfaceComplete:t.surfaceComplete===1}}function Xa(e,n){return e===0?"no-entrypoint":n.modules.length===0?"analyzer-crash":null}function Ya(e,n,t){let r=new Map(e.modules.map(a=>[a.path,a.id])),o=e.modules[0]?.id;if(o===void 0)return[];let i=n.map(a=>({source:r.get(a.path)??o,cause:Za[a.code],reach:a.classScope!==void 0?{kind:"class-scope",packageName:a.classScope.packageName,container:a.classScope.container}:a.anchor!==void 0?{kind:"via-module",anchor:a.anchor}:{kind:"unbounded"}}));for(let a of t)i.push({source:o,reach:{kind:"unbounded"},cause:a});return i}function _o(e,n,t,r,o){let i=t.filter(a=>a.exportName!==null&&(r===1||o||a.verified!==1));return i.length>0?i.map(a=>({advisoryId:e,packageName:n,exportName:a.exportName??"",container:a.container,symbolKind:a.symbolKind,sourcePath:a.sourcePath??"",derivation:a.derivation,confidence:a.confidence,verified:a.verified===1})):t.length===0||t.every(a=>a.exportName!==null&&a.verified===1)?[null]:[]}function jp(e,n){let t;try{t=gt(e)}catch{return!0}let r=3,o=(i,a)=>{if(a>r)return!1;let l;try{l=Ja(i)}catch{return!1}for(let s of l){if(s==="node_modules"||s.startsWith("."))continue;let d=tn.join(i,s),u;try{u=No(d)}catch{continue}if(!u.isDirectory())continue;let p=tn.relative(t,d).split(tn.sep).join("/");try{if(No(tn.join(d,"package.json")).isFile()&&!n.has(p))return!0}catch{}if(o(d,a+1))return!0}return!1};return o(t,1)}function Kp(e,n){let t="";for(let r of e)r.rel!==""&&n.startsWith(`${r.rel}/`)&&r.rel.length>t.length&&(t=r.rel);return t}function Bp(e,n,t){let r=[];if(t&&r.push("nested-app-root"),n==="")return[...r,"manifest-unreadable"];let o;try{if(o=gt(tn.resolve(e,n)),!o.startsWith(gt(e)+tn.sep))return[...r,"manifest-unreadable"]}catch{return[...r,"manifest-unreadable"]}let i;try{let u=tn.join(o,"package.json");if(!No(u).isFile())return[...r,"manifest-unreadable"];i=$p(u,"utf8")}catch{return[...r,"manifest-unreadable"]}let a;try{a=JSON.parse(i)}catch{return[...r,"manifest-unreadable"]}if(typeof a!="object"||a===null)return[...r,"manifest-unreadable"];let l=a;(typeof l.bin=="string"||typeof l.bin=="object"&&l.bin!==null)&&r.push("bin");let s=["preinstall","install","postinstall","prepare","prepublish"],d=l.scripts;if(typeof d=="object"&&d!==null){let u=d;s.some(p=>typeof u[p]=="string")&&r.push("install-script")}return(l.gypfile===!0||zp(o))&&r.push("native-artifact"),r}function zp(e){for(let n of["","build/Release","build/Debug","prebuilds","lib/binding"]){let t=tn.join(e,n),r;try{r=Ja(t)}catch{continue}if(r.some(o=>o.endsWith(".node")))return!0}return!1}function Up(e,n){let t=new Set(["npm",...n.ecosystems?.()??[]]),r=[];for(let o of e.perRoot){let i=new Map;for(let a of o.packages){let l=a.ecosystem??"npm";t.has(l)||i.set(l,(i.get(l)??0)+1)}for(let[a,l]of[...i.entries()].sort())r.push({kind:"ecosystem-uncovered",detail:`${o.rootRel===""?"":`${o.rootRel}: `}${String(l)} ${a} distribution(s) were enumerated but the loaded shard carries no ${a} advisories: they were NOT assessed, so this is not a clean bill of health for them. Scan with a ${a} shard to assess them (ADR-109 D5).`,blindsAnalysis:!1,rootRel:o.rootRel})}return r}function Qa(e){return JSON.stringify([e.ecosystem??"npm",e.name,e.version,e.lockKey])}function Vp(e,n,t){return new Map(n.map(r=>[Qa(r),Bp(e,r.lockKey,t)]))}function Wp(e){let n=new Map;for(let t of e){let r=n.get(t.advisory.id);r===void 0?n.set(t.advisory.id,[t]):r.push(t)}return n}function qp(e,n,t,r,o,i,a){let{finding:l}=mt(e,n,{name:t.name,version:t.version,...t.ecosystem!==void 0?{ecosystem:t.ecosystem}:{},devOnly:t.dev,outOfGraphExecution:a(t)},ht(r.advisory.id,t.name,r.affected),null,o,i);return l.decidedAtStage!=="presence"&&l.decidedAtStage!=="version-match"}function mt(e,n,t,r,o,i,a){let l=xr({graph:e,installed:t,range:r,symbol:o,coverage:null,incompleteness:i,analysisAborted:a});if(n!==null&&o!==null&&Ro(l,o,"base")){let s=Jn(e,n.modulesById,n.reachMods,o,n.records);if(s!==null)return{finding:l,hit:s}}return{finding:l,hit:null}}function Gp(e,n){let t=new Set,r=[];for(let o of e.packages)if((o.ecosystem??"npm")==="npm")for(let{advisory:i,affected:a}of n.advisoriesForPackage(o.ecosystem??"npm",o.name)){let l=ht(i.id,o.name,a),s;try{s=En(o.version,l)}catch{continue}if(s)for(let d of n.symbolsForAffected(a.id)){if(d.verified!==1||d.symbolKind!=="method"&&d.symbolKind!=="ctor"||d.container===null||d.sourcePath===null)continue;let u=`${o.lockKey}\0${d.container}\0${d.sourcePath}`;t.has(u)||(t.add(u),r.push({packageName:o.name,packageRootRel:o.lockKey,container:d.container,sourcePath:d.sourcePath}))}}return r.sort((o,i)=>`${o.packageRootRel}\0${o.container}\0${o.sourcePath}`.localeCompare(`${i.packageRootRel}\0${i.container}\0${i.sourcePath}`)),r.slice(0,zt)}function Hp(e,n,t){let r=new Map(e.functions.map(l=>[l.id,l])),o=new Map(e.classes.map(l=>[l.id,l.name])),i=new Map(e.callSites.map(l=>[l.id,l])),a=[];for(let l of e.callEdges){if(l.resolution!=="resolved"&&l.resolution!=="field-based")continue;let s=i.get(l.callSiteId);if(s===void 0)continue;let d=r.get(s.enclosingFunctionId);if(d===void 0||!t.has(d.moduleId))continue;let u=n.get(d.moduleId);if(u===void 0)continue;let p=r.get(l.calleeFunctionId);if(p===void 0||p.name===void 0)continue;let f=n.get(p.moduleId);f!==void 0&&f.packageName!==u.packageName&&a.push({packageName:f.packageName,exportName:p.name,container:p.enclosingClassId!==void 0?o.get(p.enclosingClassId)??null:null,resolution:l.resolution,callerFunctionId:d.id})}return a}function Xp(e){let n=new Set(e.modules.filter(u=>u.isEntrypoint).map(u=>u.id)),t=new Map(e.modules.map(u=>[u.id,u])),r=new Map(e.functions.map(u=>[u.id,u])),o=new Set;for(let u of e.functions)n.has(u.moduleId)&&(u.publicSurfaceReachable||u.name==="<toplevel>")&&o.add(u.id);let i=new Map(e.exports.map(u=>[u.id,u]));for(let u of e.exportBindings){if(u.target.kind!=="function")continue;let p=i.get(u.exportId);if(p===void 0||!n.has(p.moduleId))continue;let f=r.get(u.target.functionId);f===void 0||t.get(f.moduleId)?.externalSurface===!0||o.add(f.id)}let a=new Map(e.callSites.map(u=>[u.id,u.enclosingFunctionId])),l=new Map;for(let u of e.callEdges){if(u.resolution!=="resolved"&&u.resolution!=="field-based")continue;let p=a.get(u.callSiteId);if(p===void 0)continue;let f=l.get(p);f===void 0?l.set(p,[u.calleeFunctionId]):f.push(u.calleeFunctionId)}let s=new Set(o),d=[...o];for(;d.length>0;){let u=d.pop();if(u!==void 0)for(let p of l.get(u)??[])s.has(p)||(s.add(p),d.push(p))}return s}function Yp(e,n,t,r){for(let o of n){if(o.modelId!==e.modelId||o.anchor.packageName!==e.anchorPackage||o.anchor.exportName!==e.entryExport)continue;let i=t.filter(l=>l.packageName===o.anchor.packageName&&l.exportName===o.anchor.exportName&&l.container===o.anchor.container),a=i.find(l=>l.resolution==="resolved")??i[0];if(a!==void 0)return r.has(a.callerFunctionId)}return null}function Jp(e,n,t){if(t===void 0||t===!1)return!1;if(t===!0||t==="all")return n>0||e.some(i=>i.modelId!==void 0);let r=new Set(t),o=i=>r.has(i)||r.has(Fe[i]??"");return e.some(i=>i.tier==="unknown"&&i.unknownKind!==void 0&&o(i.unknownKind)||i.modelPromotedFromKind!==void 0&&o(i.modelPromotedFromKind))}function Oo(e){let n=gt(e.dir),t=e.reader??(e.shardPathPypi!==void 0?kr([Zn(e.shardPath),Zn(e.shardPathPypi)]):Zn(e.shardPath)),r=e.partialRows===!0;try{if(!/^\d+$/u.test(t.schemaVersion)||Number(t.schemaVersion)>Number(wn))throw new Xe(`shard schema ${JSON.stringify(t.schemaVersion)} is unreadable or newer than this cupel understands (v${wn})`);let o=null;if(e.summaryShadow!==void 0)try{o=Oa(e.summaryShadow)}catch(x){throw new Xe(`--summary-shadow facts dir rejected: ${x instanceof Error?x.message:String(x)}`)}let i=null;if(e.modelShadow!==void 0)try{i=Va(e.modelShadow.claimsPath)}catch(x){throw new Xe(`--model-shadow claims rejected: ${x instanceof Error?x.message:String(x)}`)}let a=po(n,{...e.rootDiscovery,...e.root!==void 0?{operatorRoots:e.root}:{}}),l=Aa(n,a,e.installedSet);if(l.truncated){let x=l.perRoot.filter(N=>N.truncated).map(N=>N.rootRel===""?"the scan root":`\`${N.rootRel}\``);throw new Xe(`the dependency enumeration hit a hard cap and is incomplete at ${x.length>0?x.join(", "):"the union across roots"} (${l.diagnostics.join("; ")}) \u2014 refusing to report a partial (possibly false-clean) scan`)}let s=Na(l.packages.filter(x=>(x.ecosystem??"npm")==="npm")),d=e.entry??[],u=d.length>0?Ks(n,d):{entrypoints:[],rejected:[]},p=u.rejected,f=js(n,a.roots),h=[...new Set([...f.entrypoints,...u.entrypoints])],g=[...f.sources];for(let x of u.entrypoints)f.entrypoints.includes(x)||g.push({source:"--entry",specifier:x,entrypoint:x,launch:!1,root:Kp(a.roots,x)});let S=Gp(l,t),E=e.bindingForms??Dp,w=e.callablePackageResolver===!0,I=e.tsconfigPaths!==!1,v=jp(n,pt(g)),_=Vp(n,l.packages,v),k=x=>_.get(Qa(x))??["manifest-unreadable"],m=to({appRoot:n,entrypoints:h,depClassAnchors:S,bindingForms:E,callablePackageResolver:w,tsconfigPaths:I}),y=m.graph,A=yr(y),C=[...f.diagnostics,...ro(f),...oo(f,h.length),...bo(a,g),...m.diagnostics],T=Xa(h.length,y),P=[...l.gaps,...Ra(a),...Up(l,t)],R=Ca(P),F=Ya(y,C,R),O=n;try{O=gt(n)}catch{}let L=Fa({graph:y,facts:F,diagnostics:C,analysisAborted:T,loadSites:m.loadSites,conditionUnions:m.conditionUnions,provenAbsent:m.provenAbsent,appRootReal:O,rootBudget:a.budget,causeOf:x=>Za[x]}),K=t.allModels?.()??[],G=Ao(K.map(x=>({model:{packageName:x.packageName,modelId:x.modelId,edges:x.edges},introduced:x.introduced,fixedBefore:x.fixedBefore})),s),B=G.models.length>0?st(y,G.models).delta:null,W=B!==null?{records:B.records,reachMods:Ze(y),modulesById:new Map(y.modules.map(x=>[x.id,x]))}:null,$=[],q=new Map,H=Fp(),Ee=[],he=[];for(let x of l.packages)for(let[,N]of Wp(t.advisoriesForPackage(x.ecosystem??"npm",x.name))){let D=N[0];if(D!==void 0){let te=q.get(D.advisory.id),ue=N.map(de=>de.affected);te===void 0?q.set(D.advisory.id,{advisory:D.advisory,ranges:ue}):te.ranges.push(...ue)}let j=N.filter(te=>qp(y,W,x,te,F,T,k)),Y=j.length>0?j:N.slice(0,1),Z=j.length===0;for(let{advisory:te,affected:ue}of Y){let de=ht(te.id,x.name,ue),fe=te.cveId??te.id,ne=Z?[]:t.symbolsForAffected(ue.id),on=ne.filter(ce=>ce.exportName===null),sn=_o(te.id,x.name,ne,ue.surfaceComplete,r),Le=mt(y,W,{name:x.name,version:x.version,...x.ecosystem!==void 0?{ecosystem:x.ecosystem}:{},devOnly:x.dev,outOfGraphExecution:k(x)},de,null,F,T).finding;if(Le.decidedAtStage==="presence"||Le.decidedAtStage==="version-match"){H[Le.tier]+=1,$.push({...Le,modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:de.surfaceComplete,advisoryId:te.id,displayId:fe,packageName:x.name,version:x.version,symbolName:null,symbolPath:null,severity:te.severity,packageLocation:Qt(l,x)});continue}for(let ce of sn){let{finding:Ye,hit:Ce}=mt(y,W,{name:x.name,version:x.version,...x.ecosystem!==void 0?{ecosystem:x.ecosystem}:{},devOnly:x.dev,outOfGraphExecution:k(x)},de,ce,F,T),Je=Ye,fn,z;Ce!==null&&ce!==null&&(fn=Ce.modelId,z=Ye.unknownKind,Je={basis:void 0,tier:Ce.tier,decidedAtStage:Ye.decidedAtStage,reason:`boundary model ${Ce.modelId}: ${Ce.anchorPackage}.${Ce.entryExport} reaches ${ce.exportName} [${Ce.pathLabels.join(" \u2192 ")}]`,unknownKind:void 0,attribution:_t(ce),path:void 0,unresolvedSites:Ye.unresolvedSites,unresolvedEvidence:Ye.unresolvedEvidence}),H[Je.tier]+=1;let X=ja(L,Je,ce,k(x).length,de.surfaceComplete),Q={...Je,...X!==void 0?{adr105:X}:{},modelId:fn,modelPromotedFromKind:z,surfaceComplete:de.surfaceComplete,advisoryId:te.id,displayId:fe,packageName:x.name,version:x.version,symbolName:ce?.exportName??null,symbolPath:ce?.sourcePath||null,severity:te.severity,packageLocation:Qt(l,x)};$.push(Q);let Ie=new Set(["dep-opaque","dynamic-load","dispatch"]);o!==null&&Q.tier==="unknown"&&Q.decidedAtStage==="symbol-reachable"&&Q.unknownKind!==void 0&&Ie.has(Q.unknownKind)&&ce!==null&&Ee.push({finding:Q,symbol:ce}),i!==null&&Q.tier==="unknown"&&ce!==null&&he.push({finding:Q,symbol:ce})}for(let ce of on)H.unknown+=1,$.push({modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:de.surfaceComplete,tier:"unknown",decidedAtStage:"symbol-reachable",reason:`advisory ${fe} carries a ${ce.symbolKind} pattern symbol; pattern matching is not evaluated yet`,unknownKind:"symbol-unsupported",attribution:void 0,basis:void 0,path:void 0,unresolvedSites:[],unresolvedEvidence:{own:[],sets:[]},advisoryId:te.id,displayId:fe,packageName:x.name,version:x.version,symbolName:null,symbolPath:null,severity:te.severity,packageLocation:Qt(l,x)})}}for(let x of P)H.unknown+=1,$.push({modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:void 0,tier:"unknown",decidedAtStage:"presence",reason:x.detail,attribution:void 0,basis:void 0,path:void 0,unresolvedSites:[],unresolvedEvidence:{own:[],sets:[]},advisoryId:Co,displayId:Co,packageName:x.kind,version:"",symbolName:null,symbolPath:null,severity:null,unknownKind:"coverage-gap",packageLocation:_a(l,x)});let ve=H["reachable-high"]+H["reachable-medium"],Sn=e.failOnReachable===!0&&ve>0,Gn=Jp($,H.unknown,e.failOnUnknown),M=e.requireCompleteDenial===!0&&$.some(x=>x.tier==="not-reachable"&&x.basis==="loader-assumption"),J=Sn||Gn||M?2:0,oe;if(o!==null){let x=Ze(y),N=new Map(y.modules.map(j=>[j.id,j])),D=[];for(let{finding:j,symbol:Y}of Ee){let Z=hr(y,N,x,Y,o,Mp);D.push({advisoryId:j.advisoryId,packageName:j.packageName,symbolName:j.symbolName,unknownKind:j.unknownKind??null,wouldPromote:Z!==null,...Z!==null?{anchorPackage:Z.anchorPackage,entryExport:Z.entryExport,viaPackages:Z.viaPackages,totalHops:Z.totalHops}:{}})}oe={records:D}}let ie;if(i!==null&&e.modelShadow!==void 0){let x=e.modelShadow.widened===!0?"widened":"base",{models:N,notes:D,dispositions:j}=Ao(i,s,{shadowConsultDenylisted:!0}),{delta:Y}=st(y,N),Z=Ze(y),te=new Map(y.modules.map(z=>[z.id,z])),ue=Hp(y,te,Z),de=Xp(y),fe=Y.records.some(z=>ue.some(X=>X.packageName===z.anchor.packageName&&X.exportName===z.anchor.exportName&&X.container===z.anchor.container)),ne=[],on=Date.now();for(let{finding:z,symbol:X}of he){let Q=Y.records,Ie=Ro(z,X,x),Se=Ie?Jn(y,te,Z,X,Q):null,se=Y.records.filter(Ae=>Ae.callee.packageName===X.packageName&&Ae.callee.exportName===X.exportName&&Ae.callee.container===X.container||Ae.callee.packageName===X.packageName&&Ae.callee.realFunctionId!==null);ne.push({advisoryId:z.advisoryId,packageName:z.packageName,symbolName:z.symbolName,unknownKind:z.unknownKind??null,decidedAtStage:z.decidedAtStage,consultSurface:x,noHitReason:Se!==null?null:Ie?fe?"no-key-match-no-continuation":"no-matching-anchor":"not-eligible-base",anchorFunctionEntryReachable:Se!==null?Yp(Se,Q,ue,de):null,verdictBefore:z.tier,verdictAfter:Se!==null?"reachable-low":z.tier,wouldPromote:Se!==null,...Se!==null?{modelId:Se.modelId,anchorPackage:Se.anchorPackage,entryExport:Se.entryExport,pathLabels:Se.pathLabels,calleeBinding:se.find(Ae=>Ae.callee.realFunctionId!==null)?.callee.realFunctionId??"key:any-installed-in-range-copy"}:Ie?se.length>0?{reason:"model-covers-symbol-but-no-baseline-anchor",nearestBlockedHop:`anchor:${se[0]?.anchor.packageName??"?"}#${se[0]?.anchor.exportName??"?"} (no resolved|field-based baseline edge from a reachable module)`}:{reason:"no-model-coverage"}:{}})}let sn=Date.now()-on,Le=j.map(z=>{if(z.status!=="active")return{modelId:z.modelId,state:z.status,reason:z.reason,edgesLowered:0,edgesReferenceGated:0};let X=Y.records.filter(Ie=>Ie.modelId===z.modelId).length;if(X>0)return{modelId:z.modelId,state:"lowered",reason:null,edgesLowered:X,edgesReferenceGated:z.edgeCount-X};let Q=Y.notes.find(Ie=>Ie.startsWith(`model ${z.modelId}:`)||Ie.startsWith(`model-edge ${z.modelId}:`));return{modelId:z.modelId,state:"refused",reason:Q??"refused \u2014 no anchor surface in the graph (all edges reference-gated)",edgesLowered:0,edgesReferenceGated:z.edgeCount}}),ce=ne.filter(z=>z.wouldPromote).length,Ye=H.unknown-ce,Ce=H["reachable-high"]+H["reachable-medium"],Je=z=>({none:0,"fail-on-reachable":Ce>0?2:0,"fail-on-unknown":z>0?2:0,both:Ce>0||z>0?2:0});ie={records:ne,notes:[...D,...Y.notes],laneStates:Le,exitCodes:{baseline:Je(H.unknown),withModels:Je(Ye)},overlayWallMs:sn},qa(tn.dirname(e.modelShadow.outPath),{recursive:!0});let fn=`${e.modelShadow.outPath}.tmp-${Wa(8).toString("hex")}`;Ha(fn,`${JSON.stringify(ie,null,2)}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`,{flag:"wx",mode:384}),um(i,r),r}function ul(e){let n=or(e),t;try{t=fm(n)}catch(a){if(a instanceof Error&&a.code==="ENOENT")return;throw a}if(process.platform!=="win32"&&(t.mode&63)!==0)throw new xt(`the stored delivery token at ${n} is readable by other users \u2014 run \`chmod 600 ${n}\`, or \`cupel login\` again to rewrite it`);let r;try{r=JSON.parse(cm(n,"utf8"))}catch{throw new xt(`the stored delivery token at ${n} is not readable \u2014 run \`cupel login\` again to rewrite it`)}let o=typeof r=="object"&&r!==null&&"delivery_token"in r?r.delivery_token:void 0,i=To(typeof o=="string"?o:"");if(!i.ok)throw new xt(`the stored credential at ${n} is not a delivery token \u2014 run \`cupel login\` with one from app.cupel.sh (Settings \u2192 Tokens)`);return i.token}function fl(e){try{return pm(or(e)),!0}catch(n){if(n instanceof Error&&n.code==="ENOENT")return!1;throw n}}var St="CUPEL_DELIVERY_TOKEN",Lo=class extends ee{constructor(n){super(n),this.name="NoDeliveryTokenError"}},Fo=class extends ee{constructor(n){super(n),this.name="DeliveryCredentialError"}};function km(e){let n=e.CUPEL_DELIVERY_TOKEN;return n===void 0||n===""?void 0:n}function pl(e,n,t=()=>{}){let r=km(e)??t();return r!==void 0?()=>Promise.resolve(r):e.ACTIONS_ID_TOKEN_REQUEST_URL!==void 0&&e.ACTIONS_ID_TOKEN_REQUEST_URL!==""?n:void 0}async function ml(e){if(e===void 0)throw new Lo(`no delivery credential \u2014 on GitHub Actions add \`permissions: id-token: write\` to the workflow; elsewhere run \`cupel login\` with a delivery token from app.cupel.sh (Settings \u2192 Tokens), or set ${St} in CI; or pass --shard <path> (a local shard needs no account)`);try{return await e()}catch(n){throw new Fo(`could not obtain a delivery credential: ${n instanceof Error?n.message:String(n)}`)}}var Em="Paste a delivery token from app.cupel.sh (Settings \u2192 Tokens); input is hidden: ";function wm(){return new Promise(e=>{let n=process.stdin;process.stderr.write(Em),n.setRawMode(!0),n.resume(),n.setEncoding("utf8");let t="",r=i=>{n.setRawMode(!1),n.pause(),n.removeListener("data",o),process.stderr.write(`
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
`)
|
|
14
|
+
}`,E.ScriptTarget.Latest,!0),r=o.parseDiagnostics;if(r!==void 0&&r.length>0||Tu(o,n+1,!0))return!0}return!1}function Tu(e,n=0,t=!1){return mr(e,n,t).size>0}function mr(e,n=0,t=!1){let o=new Set,r=t?Iu:Ou(e);if(r.saturated)return o.add("saturated"),o;let s=l=>E.isElementAccessExpression(l)&&!E.isStringLiteralLike(l.argumentExpression)&&fo(_e(l.expression),r),a=l=>{if(t&&(E.isCallExpression(l)||E.isNewExpression(l)||E.isTaggedTemplateExpression(l))){o.add("eval-invocation");return}if(E.isCallExpression(l)){let i=At(l);if(i!==null){let d=i.specifierArg;if(d===void 0||!E.isStringLiteralLike(d)||t){o.add("non-literal-load");return}}else{let d=_e(l.expression);if(E.isIdentifier(d)&&(d.text==="eval"||d.text==="Function")){if($i(l.arguments,n)){o.add("eval-code");return}}else if(Cu(d)){o.add("loader-callee");return}else if(s(d)){o.add("computed-loader");return}else if(Pu(l,r)){o.add("reflect-get");return}}}else if(E.isNewExpression(l)){let i=_e(l.expression);if(E.isIdentifier(i)&&i.text==="Function"){if($i(l.arguments??[],n)){o.add("function-ctor");return}}else if(vt(i)){o.add("ctor-chain");return}}else if(E.isIdentifier(l)&&bu.has(l.text)&&vu(l)){o.add("captured-loader");return}else if((E.isPropertyAccessExpression(l)||E.isElementAccessExpression(l))&&(Ti(l)||vt(l)||s(l))&&Mi(l)){o.add("captured-member");return}else if(E.isBindingElement(l)){let i=l.propertyName??l.name,d=E.isIdentifier(i)||E.isStringLiteralLike(i)?i.text:E.isComputedPropertyName(i)&&E.isStringLiteralLike(i.expression)?i.expression.text:void 0;if(d!==void 0&&mo.has(d)){o.add("destructured-member");return}}E.forEachChild(l,a)};return a(e),o}function Ki(e,n,t){let o=new Set(mr(t));if(gr(e)&&n.includes("<")&&n.includes("require")){let r=E.createSourceFile(e,n,E.ScriptTarget.ES2020,!0,E.ScriptKind.TSX);for(let s of mr(r))o.add(s)}return o}function Du(e,n,t){if(hr(e))return!0;let o=t.endsWith(Me.sep)?t:t+Me.sep,r=e.split("/"),s=n;for(;;){let a=Me.join(s,"node_modules",...r),l;try{l=Kn(Me.join(a,"package.json"))}catch{l=null}if(l!==null){if(!l.startsWith(o))return!1;let d=Oe(l);if(d===null)return!1;let u;try{u=JSON.parse(d).exports}catch{return!1}if(typeof u=="string"||Array.isArray(u)||typeof u=="object"&&u!==null)return!1}if(ui(a))return!1;if(s===t)break;let i=Me.dirname(s);if(i===s||i!==t&&!i.startsWith(o))break;s=i}return!0}function Lu(e,n){let t=n.endsWith(Me.sep)?n:n+Me.sep,o=Me.dirname(e);for(;;){let r=Me.join(o,"package.json"),s;try{s=Kn(r)}catch{s=null}if(s!==null&&(s===n||s.startsWith(t))){let l=Oe(s);if(l!==null)try{let i=JSON.parse(l).name;if(typeof i=="string"&&i.length>0)return i}catch{return null}}if(o===n)break;let a=Me.dirname(o);if(a===o||a!==n&&!a.startsWith(t))break;o=a}return null}function Fu(e,n,t,o,r){let s=[],a=[],l=new Set,i={},d=[],u=[],p=new Set,f=new Set,m=[],g=!1,y=(x,I)=>{let w;try{w=Kn(I)}catch{return!1}let A=Le(e,w);if(A===null)return r.push({code:"out-of-root",path:w,detail:"dependency module resolved outside the app root; not followed"}),!1;let k=!t.has(w)&&!f.has(w);return k&&f.size>=ur?(g=!0,!1):(a.push({from:x,to:{module:A}}),k?(f.add(w),s.push(A),!0):!1)},b=(x,I)=>{if(l.add(I),p.has(I))return;p.add(I);let w=Ge(I,x,Ce,n),A=w!==null?[w]:tt(I,x,Ce,n);A.length>=2&&d.push({path:Le(e,x)??x,specifier:I,candidates:A.map(h=>Le(e,h)??h)});let k=!1;for(let h of A)if(!Be(h)&&(k=!0,y({surface:I},h))){m.push(h);try{let S=Le(e,Kn(h)),_=Lu(h,e);S!==null&&_!==null&&(i[S]=_)}catch{}}k||Du(I,Me.dirname(x),e)||r.push({code:"unresolved-specifier",path:I,reason:kt(I,x,Ce,n),detail:`dependency "${I}" is installed and Node loads an entry for it, but its runtime entry did not resolve here (divergent conditional exports / a typesVersions remap / a declaration-only surface / an unreadable manifest / an out-of-root install); its module was not analyzed (degraded to unbounded)`})};for(let x of o)b(x.containingFile,x.packageName);for(;m.length>0&&f.size<ur;){let x=m.pop();if(x===void 0)break;let I=Le(e,x);if(I===null)continue;let w=nt(x,In);if(w.kind==="too-large"){r.push({code:"limit-exceeded",path:I,detail:`dependency module over the ${String(In/1048576)}MiB cap; its imports were not followed (degraded to unbounded)`});continue}if(w.kind==="not-regular"){r.push({code:"parse-error",path:I,detail:"dependency module unreadable or not a regular file; its imports were not followed (degraded to unbounded)"});continue}let A=E.createSourceFile(x,w.text,E.ScriptTarget.ES2020,!0),k=A.parseDiagnostics;if(k!==void 0&&k.length>0){r.push({code:"dependency-body",path:I,detail:"dependency module has syntax errors; its tolerant parse may have dropped import/loader nodes \u2014 module reach unbounded (ADR-050 2A parse-cap)"});continue}let h=Ki(x,w.text,A);if(h.size>0){r.push({code:"dependency-body",path:I,detail:"dependency module contains a loader escape (eval / Function / reflective or non-literal loader / captured loader value); its module reach is unbounded (ADR-045 Attack #1 dep-side mirror)",escapes:[...h].sort()});continue}r.push({code:"dependency-body",path:I,detail:"dependency module followed at module-import granularity only; its function bodies are not analyzed (ADR-050 2A, bodyless)",anchor:I});for(let S of Oi(x,w.text))if(S.runtime)if(we(S.text)==="package-root"){let _=qe(S.text);a.push({from:{module:I},to:{surface:_}}),b(x,_)}else{if(hr(qe(S.text)))continue;let _=Ge(S.text,x,Ce,n),P=_!==null?[_]:tt(S.text,x,Ce,n);if(P.length===0){if(we(S.text)==="package-subpath"){let v=kt(S.text,x,Ce,n);if(v==="no-candidate"||v==="not-installed"&&hi(x,qe(S.text))){u.push({path:I,specifier:S.text,why:v});continue}r.push({code:"unresolved-specifier",path:I,reason:v,detail:`runtime package-subpath import "${S.text}" did not resolve under Node10 (an exports-map/typesVersions subpath Node may load); its module was not analyzed`})}continue}P.length>=2&&d.push({path:I,specifier:S.text,candidates:P.map(v=>Le(e,v)??v)});for(let v of P){if(Be(v)){let T=Le(e,v);r.push({code:T===null?"out-of-root":"declaration-shadow",path:I,detail:T===null?`runtime import "${S.text}" resolved outside the app root; its module was not analyzed`:`runtime import "${S.text}" resolved to the declaration file "${T}" with no co-located runtime module; its code was not analyzed`});continue}y({module:I},v)&&m.push(v)}}}return(g||m.length>0)&&r.push({code:"limit-exceeded",path:e,detail:`dependency module closure hit the ${String(ur)} cap; module-reachability truncated (degraded to unbounded)`}),{modules:s,edges:a,surfacePackages:[...l],entryRealNames:i,conditionUnions:d,provenAbsent:u}}function Ui(e,n,t=!1){let o=Kn(e),r=[],s=[],a=E.createCompilerHost(Ce,!0),l=t?gi(o,Ce,a):()=>null,i=new Set,d=new Set,u=n.map(N=>Me.join(o,N)),p=[],f=new Map,m=new Map,g=new Map,y=new Map,b=new Set,x=(N,j,O)=>{let F=`${String(N.length)}:${N}${j}`;b.has(F)||(b.add(F),r.push({code:"unresolved-specifier",path:N,detail:j,reason:O}))},I=()=>null,w=0,A=(N,j)=>{let O=m.get(N);return O===void 0&&(O=E.createSourceFile(N,j,E.ScriptTarget.ES2020,!0),m.set(N,O)),{real:N,sf:O}};for(;d.size<co;){let N=u.pop();if(N===void 0){if(w>=Su)break;w+=1;let K=[];for(let[D,C]of f)C.includes("readdir")&&(C.includes("require")||C.includes("import("))&&K.push(A(D,C));let te=xu(K);if(te.length===0)break;let U=[];for(let[D,C]of f)U.push(A(D,C));I=_i(U,te,Ce,a,g);let X=!1;for(let D of K){let C=f.get(D.real);if(C!==void 0)for(let H of Pi(D.real,C,o,a,I))d.has(H)||(u.push(H),X=!0)}if(!X)break;continue}let j;try{j=Kn(N)}catch{continue}if(d.has(j))continue;if(d.add(j),Le(o,j)===null){r.push({code:"out-of-root",path:N,detail:"resolved outside app root"});continue}let O=nt(j,In);if(O.kind==="too-large"){r.push({code:"limit-exceeded",path:j,detail:`file is ${String(Math.round(O.bytes/1048576))}MiB, over the ${String(In/1048576)}MiB per-file cap; skipped (degraded to unknown)`});continue}if(O.kind==="not-regular"){r.push({code:"parse-error",path:j,detail:"unreadable or not a regular file"});continue}let F=O.text;i.add(j),f.set(j,F);for(let K of Oi(j,F)){let te=K.runtime?l(K.text,j):null;if(te===null&&we(K.text)==="package-root"){K.runtime&&p.push({containingFile:j,packageName:qe(K.text)});continue}let U=te??Ge(K.text,j,Ce,a),X=U!==null?[U]:K.runtime&&te===null?tt(K.text,j,Ce,a):[];if(X.length===0){if(K.runtime){let D=we(K.text);if(!(D==="package-subpath"&&hr(qe(K.text)))){if(D==="package-subpath")x(j,`runtime package-subpath import "${K.text}" did not resolve under Node10 (an exports-map/typesVersions subpath Node may load); its module was not analyzed`,kt(K.text,j,Ce,a));else if(D==="relative"){let C=pi(K.text,j,o,y);C.kind==="unanalyzable"&&x(j,`runtime relative import "${K.text}" did not resolve and its absence could not be proven \u2014 ${C.reason}; a bundler/loader may load a module the analyzer never saw`,C.why)}}}continue}X.length>=2&&s.push({path:Le(o,j)??j,specifier:K.text,candidates:X.map(D=>Le(o,D)??D)});for(let D of X){if(Le(o,D)===null){r.push({code:"out-of-root",path:D,detail:`specifier "${K.text}" resolved outside app root`});continue}if(K.runtime&&Be(D)){r.push({code:"declaration-shadow",path:D,detail:`runtime import "${K.text}" resolved to a declaration file with no co-located runtime module; its code was not analyzed`});continue}if(K.runtime&&!ro(D)){r.push({code:"unanalyzable-module",path:D,detail:`runtime import "${K.text}" resolved to a file the analyzer cannot parse (extensionless/.json/.node); its module was not analyzed`});continue}u.push(D)}}for(let K of Pi(j,F,o,a,I))d.has(K)||u.push(K)}d.size>=co&&u.length>0&&r.push({code:"limit-exceeded",path:o,detail:`reachable file set exceeds ${String(co)}; analysis truncated (${String(u.length)}+ files not analyzed)`});let k=Fu(o,a,i,p,r),h=E.createProgram({rootNames:[...i],options:Ce,host:a}),S=new Set,_=new Map;for(let N of h.getSourceFiles()){if(N.isDeclarationFile||h.isSourceFileDefaultLibrary(N)||Le(o,N.fileName)===null||!gr(N.fileName))continue;let j=h.getSyntacticDiagnostics(N).length>0;if(!j&&!N.text.includes("<")||yu(N.text,E.ScriptKind.TSX)!==0)continue;let O=E.createSourceFile(N.fileName,N.text,E.ScriptTarget.ES2020,!0,E.ScriptKind.TSX);(j||Ri(O)>Ri(N))&&(S.add(N.fileName),_.set(N.fileName,N.text))}let P=h;if(S.size>0){let N=a.getSourceFile.bind(a);a.getSourceFile=(j,O,F,K)=>{let te=_.get(j);return te!==void 0?E.createSourceFile(j,te,E.ScriptTarget.ES2020,!0,E.ScriptKind.TSX):N(j,O,F,K)},P=E.createProgram({rootNames:[...i],options:Ce,host:a,oldProgram:h})}let v=P.getTypeChecker(),T=[];for(let N of P.getSourceFiles()){if(N.isDeclarationFile||P.isSourceFileDefaultLibrary(N)||Le(o,N.fileName)===null)continue;T.push(N);let j=P.getSyntacticDiagnostics(N);if(j.length>0){let K=j[0],te=K!==void 0?E.flattenDiagnosticMessageText(K.messageText," "):"syntax error";r.push({code:"parse-error",path:N.fileName,detail:`${String(j.length)} syntax error(s): ${te}`})}let O=Le(o,N.fileName),F=O===null?null:Ki(N.fileName,N.text,N);O!==null&&F!==null&&F.size>0&&r.push({code:"loader-escape",path:O,detail:"module contains a loader escape (eval / Function / reflective or non-literal loader / captured or destructured loader); its module reach is unbounded (ADR-050 2B)",escapes:[...F].sort()})}return{program:P,checker:v,host:a,options:Ce,appRoot:o,sourceFiles:T,diagnostics:r,depReach:k,conditionUnions:[...s,...k.conditionUnions],provenAbsent:k.provenAbsent,resolveParamDirs:I,toRel:N=>Le(o,N)}}import{opendirSync as ju,statSync as Bu}from"node:fs";import yr from"node:path";var Ku=8192,Uu=2e4,zu=new Set(["node_modules"]),zi=new Set(["test","tests","__tests__","__mocks__","fixtures","e2e","dist","build","out","coverage","vendor"]),Wu=16;function ho(e,n,t,o,r={}){let s=r.maxEntries??Uu,a=r.prune,l=[],i=!1,d=0,u=[{dir:yr.join(e,n),rel:n,depth:0}];for(;u.length>0;){let p=u.pop();if(p===void 0)break;if(p.depth>Wu){i=!0;continue}let f;try{f=ju(p.dir)}catch{i=!0;continue}try{let m=0;for(;;){let g=f.readSync();if(g===null)break;if(m+=1,d+=1,m>Ku||d>s){i=!0;break}let y=p.rel+g.name;if(g.isSymbolicLink()){let b;try{b=Bu(yr.join(p.dir,g.name)).isDirectory()}catch{i=!0;continue}if(b){i=!0;continue}}else if(g.isDirectory()){if(zu.has(g.name)||g.name.startsWith(".")||a?.has(g.name)===!0){i=!0;continue}u.push({dir:yr.join(p.dir,g.name),rel:`${y}/`,depth:p.depth+1});continue}else if(!g.isFile())continue;if(t(y)){if(l.length>=o){i=!0;break}l.push(y)}}}finally{try{f.closeSync()}catch{}}}return{matches:l,truncated:i}}var Vu=64;function Wi(e,n){let t=n.indexOf("*");if(t===-1||n.indexOf("*",t+1)!==-1)return null;let o=n.slice(0,t),r=n.slice(t+1);if(o.startsWith("./")&&(o=o.slice(2)),o.startsWith("/")||r.includes("/")||o.split("/").includes("..")||o.includes("\\")||n.includes("\0"))return null;let s=o.slice(0,o.lastIndexOf("/")+1);return ho(e,s,a=>a.length>=o.length+r.length&&a.startsWith(o)&&a.endsWith(r),Vu)}import{existsSync as qu}from"node:fs";import Gu from"node:path";var Hu=[{name:"Astro",dependency:"astro",configFiles:["astro.config.mjs","astro.config.js","astro.config.ts","astro.config.mts"],entryHint:"your route files under src/pages/",rootDirs:["pages","actions"]},{name:"Next.js",dependency:"next",configFiles:["next.config.js","next.config.mjs","next.config.ts","next.config.cjs"],entryHint:"your route files under app/ or pages/",rootDirs:["app","pages"]},{name:"SvelteKit",dependency:"@sveltejs/kit",configFiles:["svelte.config.js","svelte.config.mjs","svelte.config.ts"],entryHint:"your route files under src/routes/",rootDirs:["routes"]},{name:"Nuxt",dependency:"nuxt",configFiles:["nuxt.config.js","nuxt.config.mjs","nuxt.config.ts"],entryHint:"app.vue, or your route files under pages/",rootDirs:["server","pages","middleware","plugins"]},{name:"Remix",dependency:"@remix-run/dev",configFiles:["remix.config.js","remix.config.mjs","vite.config.js","vite.config.ts"],entryHint:"app/root.tsx, or your route files under app/routes/",rootDirs:["app","routes"]},{name:"Vite",dependency:"vite",configFiles:["vite.config.js","vite.config.ts","vite.config.mjs","vite.config.mts"],entryHint:"the module script your index.html loads",rootDirs:[]}],Xu=["dependencies","devDependencies"];function Yu(e,n){for(let t of Xu){let o=e[t];if(!(typeof o!="object"||o===null||Array.isArray(o))&&Object.hasOwn(o,n))return!0}return!1}function xr(e,n){if(n===null)return null;for(let t of Hu)if(Yu(n,t.dependency)){for(let o of t.configFiles)if(qu(Gu.join(e,o)))return{name:t.name,configFile:o,entryHint:t.entryHint,rootDirs:t.rootDirs}}return null}function Sr(e){return`This looks like ${e.name} (${e.configFile} plus the dependency), and ${e.name} resolves its entry at build time \u2014 there is nothing in package.json for cupel to start from. Pass --entry ${e.entryHint}.`}var Ju=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"],Zu=256,Qu=12e4;function br(e,n){let t=new Set(n.rootDirs);if(t.size===0)return{roots:[],truncated:!1};let o=ho(e,"",r=>{let s=r.split("/");for(let a=0;a<s.length-1;a+=1){let l=s[a];if(l!==void 0&&t.has(l))return Ju.some(i=>r.endsWith(i))}return!1},Zu,{maxEntries:Qu,prune:zi});return{roots:o.matches,truncated:o.truncated}}function He(e){let n=e.length<=120?e:`${e.slice(0,120)}\u2026`,t="";for(let o of n){let r=o.codePointAt(0)??0;t+=r<32||r>=127&&r<=159?`\\x${r.toString(16).padStart(2,"0")}`:o}return t}function ef(e){for(let n of e){let t=n.codePointAt(0)??0;if(t<32||t===127||t>=128&&t<=159||"&|;<>$`(){}[]*?~#!\\\"'".includes(n))return!0}return!1}function nf(e){let n=!1;for(let t=0;t<e.length;t+=1){let o=e.charAt(t),r=o.codePointAt(0)??0;if(r<32||r===127||r>=128&&r<=159)return null;if(o==="\\"){n=!0;let s=e.charAt(t+1);if(!(s>="a"&&s<="z"||s>="A"&&s<="Z"||s>="0"&&s<="9"||s==="."||s==="_"||s==="-"))return null;continue}if("&|;<>$`(){}[]*?~#!\"'".includes(o))return null}return n?{windows:e.split("\\").join("/"),posixShell:e.split("\\").join("")}:null}function tf(e){let n=[],t="";for(let o of e){if(o===" "||o===" "){if(t.length>0){if(n.length>=64)return null;n.push(t),t=""}continue}t+=o}if(t.length>0){if(n.length>=64)return null;n.push(t)}return n}var of=/^[A-Za-z_][A-Za-z0-9_]*=/u;function rf(e){let n=e.slice(e.lastIndexOf("/")+1);return n==="node"||n==="nodejs"}var sf=new Set(["--abort-on-uncaught-exception","--disallow-code-generation-from-strings","--enable-source-maps","--experimental-json-modules","--experimental-modules","--experimental-vm-modules","--frozen-intrinsics","--harmony","--inspect","--inspect-brk","--no-warnings","--preserve-symlinks","--preserve-symlinks-main","--trace-uncaught","--trace-warnings","--use-strict","--zero-fill-buffers"]),af=new Set(["--dns-result-order","--heapsnapshot-signal","--inspect-port","--max-http-header-size","--max-old-space-size","--max-semi-space-size","--stack-size","--title","--tls-cipher-list","--trace-event-categories","--unhandled-rejections","--v8-pool-size"]),lf=new Set(["-e","--eval","-p","--print","--run","--env-file","--env-file-if-exists"]);function qi(e){return e.includes("require")||e.includes("import")||e.includes("loader")}function Vi(e){if(qi(e))return{token:e,why:"preloads another module; the launch surface is more than one file"};let n=e.indexOf("="),t=n===-1?e:e.slice(0,n);return lf.has(t)?{token:t,why:"runs code that is not the script token (or can inject a preload); the entry file cannot be identified"}:sf.has(t)||n!==-1&&af.has(t)?null:{token:t,why:"is not on cupel's allowlist of flags that provably do not change which file node runs \u2014 the entry file cannot be identified with certainty"}}var df=[".js",".cjs",".mjs",".ts",".mts",".cts"];function cf(e){return df.some(n=>e.endsWith(n))}var uf=new Set(["npm","yarn","pnpm"]);function ff(e){let n=e[0];return n===void 0||!uf.has(n)?!1:e.length===2?e[1]==="start":e.length===3&&e[1]==="run"&&e[2]==="start"}function Er(e){let n=e.trim();if(n.length===0)return{kind:"unparsed",reason:"empty command"};if(n.length>4096)return{kind:"unparsed",reason:`command exceeds the ${String(4096)}-byte cap; not parsed`};if(!ef(n))return kr(n);let t=nf(n);if(t===null)return{kind:"unparsed",reason:"contains shell metacharacters (chaining/expansion/quoting) \u2014 not a plain `node <file>` invocation"};let o=kr(t.windows),r=kr(t.posixShell);if(o.kind==="file"){let s=r.kind==="file"?r.specifier:void 0;return s===void 0||s===o.specifier?{kind:"file",specifier:o.specifier}:{kind:"file",specifier:o.specifier,alt:s}}return r.kind==="file"?{kind:"file",specifier:r.specifier}:o}function kr(e){let n=tf(e);if(n===null)return{kind:"unparsed",reason:"command has more tokens than cupel will consider"};let t=0;for(n[t]==="env"&&(t+=1);t<n.length;t+=1){let s=n[t];if(s===void 0||!of.test(s))break;if(qi(s))return{kind:"unparsed",reason:`environment \`${He(s)}\` preloads another module; the launch surface is more than one file`};let a=s.indexOf("=");if(s.slice(0,a)==="NODE_OPTIONS")for(let l of s.slice(a+1).split(/\s+/u)){if(l===""||!l.startsWith("-"))continue;let i=Vi(l);if(i!==null)return{kind:"unparsed",reason:`NODE_OPTIONS flag \`${He(i.token)}\` ${i.why}`}}}let o=n[t];if(o===void 0)return{kind:"unparsed",reason:"no program in the command"};if(ff(n.slice(t)))return{kind:"delegates",target:"scripts.start"};if(!rf(o))return{kind:"unparsed",reason:`runs \`${He(o)}\`, not node directly \u2014 the entry file cannot be identified`};for(t+=1;t<n.length;t+=1){let s=n[t];if(s===void 0||!s.startsWith("-"))break;let a=Vi(s);if(a!==null)return{kind:"unparsed",reason:`node flag \`${He(a.token)}\` ${a.why}`}}let r=n[t];return r===void 0?{kind:"unparsed",reason:"node is invoked with no script file"}:cf(r)?{kind:"file",specifier:r}:{kind:"unparsed",reason:`\`${He(r)}\` has no .js/.cjs/.mjs/.ts extension \u2014 not confidently a JS entry file`}}function pf(e){for(let n of e)if(!(n>="a"&&n<="z"||n>="A"&&n<="Z"||n>="0"&&n<="9"||n==="_"||n==="-"))return!1;return e.length>0}var mf=64;function wr(e){let n=e.split(`
|
|
15
|
+
`),t=n.length>64,o=[],r=0;for(let s of n.slice(0,64)){let a=s.trim();if(a.length===0||a.startsWith("#"))continue;let l=a.indexOf(":");if(l<=0)continue;let i=a.slice(l+1).trim();if(i.length===0)continue;let d=a.slice(0,l);if(d.length>mf||!pf(d)){r+=1;continue}o.push({name:d,command:i})}return o.sort((s,a)=>s.name===a.name?0:s.name==="web"?-1:a.name==="web"?1:0),{entries:o,truncated:t,unnamedLines:r}}import{realpathSync as Gi}from"node:fs";import Ue from"node:path";import c from"typescript";var Hi=3;function he(e,n,t){if(e===void 0)return;let o=e[n]??={fired:0,refused:{}};t===null?o.fired+=1:o.refused[t]=(o.refused[t]??0)+1}function Nn(e,n,t){return{path:e,start:n.getStart(t,!1),end:n.getEnd()}}var yo=16,_r=256,vr=class{mods=new Map;fns=new Map;classNodes=new Map;classMembers=new Map;moduleFor(n){let t=`pkg:${n}`;return this.mods.has(n)||this.mods.set(n,{id:t,packageName:n,versionRange:"",path:n,moduleSystem:"dual",isEntrypoint:!1,externalSurface:!0}),t}exportFor(n,t){let o=`${n}#${t}`,r=`pkg:${n}#${t}`;return this.fns.has(o)||(this.moduleFor(n),this.fns.set(o,{id:r,moduleId:`pkg:${n}`,name:t,kind:"function",declRange:{path:n,start:0,end:0},isExported:!0,publicSurfaceReachable:!0})),r}classFor(n,t){let o=`${n}#${t}`,r=`pkg:${n}#${t}`;return this.classNodes.has(o)||(this.moduleFor(n),this.classNodes.set(o,{id:r,moduleId:`pkg:${n}`,name:t,implementsRefs:[],members:[]}),this.classMembers.set(o,[])),r}methodFor(n,t,o,r){let s=`${n}#${t}.${o}`,a=`pkg:${n}#${t}.${o}`;if(!this.fns.has(s)){let l=this.classFor(n,t);this.fns.set(s,{id:a,moduleId:`pkg:${n}`,name:o,kind:r,enclosingClassId:l,declRange:{path:n,start:0,end:0},isExported:!0,publicSurfaceReachable:!0}),this.classMembers.get(`${n}#${t}`)?.push(a)}return a}modules(){return[...this.mods.values()]}functions(){return[...this.fns.values()]}classes(){return[...this.classNodes.entries()].map(([n,t])=>({...t,members:this.classMembers.get(n)??[]}))}};function oa(e,n){let t="node_modules/",o=e.lastIndexOf(t);if(o===-1)return n;let s=e.slice(o+t.length).split("/");return s[0]?.startsWith("@")&&s.length>=2?`${s[0]}/${s[1]}`:s[0]??n}function Xi(e,n,t){let o=Ue.dirname(e),r=Ue.dirname(n),s=[];for(;;){let l=t.get(o);if(l!==void 0){for(let d of s)t.set(d,l);return l}s.push(o);let i=Oe(Ue.join(o,"package.json"));if(i!==null)try{let d=JSON.parse(i),u={name:d.name??"app",version:d.version??"0.0.0",dir:o};for(let p of s)t.set(p,u);return u}catch{}if(o===r||o===Ue.dirname(o))break;o=Ue.dirname(o)}let a={name:"app",version:"0.0.0",dir:null};for(let l of s)t.set(l,a);return a}function Ir(e){return c.isParenthesizedExpression(e)?Ir(e.expression):c.isStringLiteralLike(e)?e.text:c.isTemplateExpression(e)?e.head.text:c.isBinaryExpression(e)&&e.operatorToken.kind===c.SyntaxKind.PlusToken?Ir(e.left):null}function hf(e){if(!c.isCallExpression(e))return!1;let n=e.expression,t=c.isPropertyAccessExpression(n)?n.name.text:c.isIdentifier(n)?n.text:null;if(t!=="join"&&t!=="resolve")return!1;let o=e.arguments[0];return o!==void 0&&c.isIdentifier(o)&&(o.text==="__dirname"||o.text==="__filename")}function ra(e){let n=Ir(e);return n!==null?n.startsWith("./")||n.startsWith("../")?"relative-bounded":n.length>0&&!n.startsWith(".")&&!n.startsWith("/")?"bare":"unknown":hf(e)?"relative-bounded":"unknown"}function gf(e){let n=[],t=o=>{if(c.isImportDeclaration(o)&&c.isStringLiteralLike(o.moduleSpecifier))n.push({specifier:o.moduleSpecifier.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isImportEqualsDeclaration(o)&&c.isExternalModuleReference(o.moduleReference)&&c.isStringLiteralLike(o.moduleReference.expression))n.push({specifier:o.moduleReference.expression.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isExportDeclaration(o)&&o.moduleSpecifier!==void 0&&c.isStringLiteralLike(o.moduleSpecifier))n.push({specifier:o.moduleSpecifier.text,specifierIsLiteral:!0,dynamic:!1});else if(c.isCallExpression(o)){let r=At(o);if(r!==null){let s=r.specifierArg,a=s!==void 0&&c.isStringLiteralLike(s);n.push({specifier:a?s.text:void 0,specifierIsLiteral:a,dynamic:!0,...s!==void 0&&!a?{computedArg:s,loadPos:o.getStart(e)}:{}})}}c.forEachChild(o,t)};return t(e),n}function yf(e,n,t){let o=new Map,r=Xi(Ue.join(e.appRoot,"package.json"),e.appRoot,o),s=[],a=[],l=[],i=new Map,d=new Set,u=[],p=new Set;for(let f of e.sourceFiles){let m=e.toRel(f.fileName);m!==null&&p.add(m)}for(let f of e.sourceFiles){let m=e.toRel(f.fileName);if(m===null)continue;let g=Xi(f.fileName,e.appRoot,o),y=oa(m,r.name),b=m.includes("node_modules/");s.push({id:m,packageName:b&&g.name!==r.name?g.name:y,versionRange:g.version,path:m,moduleSystem:"cjs",isEntrypoint:n.has(m)}),g.dir===r.dir&&d.add(m);let x=0,I=null;for(let w of gf(f)){let A=`${m}#import${String(x)}`;x+=1;let k=null,h=[];if(w.specifier!==void 0)if(we(w.specifier)==="package-root")k=t.moduleFor(qe(w.specifier));else{let S=Ge(w.specifier,f.fileName,e.options,e.host),_=S!==null?e.toRel(S):null;if(_!==null)k=_;else if(w.specifier!==void 0){let[P,...v]=tt(w.specifier,f.fileName,e.options,e.host).map(T=>e.toRel(T)).filter(T=>T!==null&&p.has(T));P!==void 0&&v.length>=1&&(k=P,h=v.map(T=>T))}}a.push({id:A,moduleId:m,specifier:w.specifier??"<computed>",isNamespace:!1,isDefault:!1,dynamic:w.dynamic,specifierIsLiteral:w.specifierIsLiteral,...k!==null?{resolvedModuleId:k}:{}}),k!==null&&l.push({importId:A,resolvedModuleId:k});for(let S of h)l.push({importId:A,resolvedModuleId:S});if(w.computedArg!==void 0&&w.loadPos!==void 0&&u.push({importId:String(A),path:m,pos:w.loadPos,shape:ra(w.computedArg),text:w.computedArg.getText(f).slice(0,160)}),w.computedArg!==void 0&&w.loadPos!==void 0){I??=Bn(f,f.fileName,e.resolveParamDirs);let S=[];for(let _ of ao(w.computedArg,I,e.appRoot,e.options,e.host)){let P=e.toRel(_);if(P===null||!p.has(P))continue;let v=P,T=`${m}#import${String(x)}`;x+=1,a.push({id:T,moduleId:m,specifier:P,isNamespace:!1,isDefault:!1,dynamic:!0,specifierIsLiteral:!0,resolvedModuleId:v}),l.push({importId:T,resolvedModuleId:v}),S.push(P)}if(S.length>0){let _=wt(w.computedArg,I)!==null||io(w.computedArg),P=i.get(m)??[];P.push({pos:w.loadPos,candidateRels:S,seedable:_}),i.set(m,P)}}}}return{modules:s,imports:a,importEdges:l,computedLoads:i,appOwnedPaths:d,loadSites:u}}function xf(e){let n=Oe(e);if(n===null)return null;let t=c.createSourceFile(e,n,c.ScriptTarget.Latest,!0),o=r=>t.statements.some(s=>c.isFunctionDeclaration(s)?s.name?.text===r:c.isVariableStatement(s)?s.declarationList.declarations.some(a=>c.isIdentifier(a.name)&&a.name.text===r&&a.initializer!==void 0&&(c.isFunctionExpression(a.initializer)||c.isArrowFunction(a.initializer))):!1);for(let r of t.statements){if(c.isFunctionDeclaration(r)&&r.name!==void 0&&r.modifiers?.some(a=>a.kind===c.SyntaxKind.DefaultKeyword)===!0)return r.name.text;if(!c.isExpressionStatement(r)||!c.isBinaryExpression(r.expression))continue;let s=r.expression;if(s.operatorToken.kind===c.SyntaxKind.EqualsToken&&Sf(s.left)){if(c.isFunctionExpression(s.right)&&s.right.name!==void 0)return s.right.name.text;if(c.isIdentifier(s.right)&&o(s.right.text))return s.right.text}}return null}function Sf(e){return c.isPropertyAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&e.name.text==="exports"?!0:c.isElementAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&c.isStringLiteralLike(e.argumentExpression)&&e.argumentExpression.text==="exports"}function bf(e,n,t){for(let d of e.surfacePackages)n.moduleFor(d);let o=d=>"surface"in d?n.moduleFor(d.surface):d.module,r=[],s=new Set;for(let d of e.modules)t.has(d)||s.has(d)||(s.add(d),r.push({id:d,packageName:e.entryRealNames[d]??oa(d,"app"),versionRange:"",path:d,moduleSystem:"cjs",isEntrypoint:!1}));let a=[],l=[],i=0;for(let d of e.edges){let u=o(d.from),p=o(d.to),f=`${String(u)}#depreach${String(i)}`;i+=1,a.push({id:f,moduleId:u,specifier:"<dep-module-reach>",isNamespace:!1,isDefault:!1,dynamic:!1,specifierIsLiteral:!0,resolvedModuleId:p}),l.push({importId:f,resolvedModuleId:p})}return{modules:r,imports:a,importEdges:l}}function Yi(e,n,t){let o=e.expression;if(c.isIdentifier(o)&&!t.has(o.text)){let r=n.get(o.text);if(r?.kind==="package-export")return{kind:"package-instance",packageName:r.packageName,className:r.exportName};if(r?.kind==="app-class")return{kind:"app-instance",cls:r.cls}}else if(c.isPropertyAccessExpression(o)&&c.isIdentifier(o.expression)&&!t.has(o.expression.text)){let r=n.get(o.expression.text);if(r?.kind==="package-surface")return{kind:"package-instance",packageName:r.packageName,className:o.name.text}}return null}function Un(e){return c.canHaveModifiers(e)&&(c.getModifiers(e)?.some(n=>n.kind===c.SyntaxKind.ExportKeyword)??!1)}function kf(e){let n=new Set,t;for(let o of e.statements){if(c.isExpressionStatement(o)&&c.isBinaryExpression(o.expression)){let r=o.expression;if(r.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(r.left)&&c.isIdentifier(r.left.expression)&&r.left.expression.text==="module"&&r.left.name.text==="exports"){if(c.isIdentifier(r.right))n.add(r.right.text),t=r.right.text;else if(c.isObjectLiteralExpression(r.right))for(let s of r.right.properties)c.isShorthandPropertyAssignment(s)?n.add(s.name.text):c.isPropertyAssignment(s)&&c.isIdentifier(s.initializer)&&n.add(s.initializer.text)}continue}if(c.isFunctionDeclaration(o)&&o.name!==void 0&&Un(o))n.add(o.name.text);else if(c.isVariableStatement(o)&&Un(o))for(let r of o.declarationList.declarations)c.isIdentifier(r.name)&&n.add(r.name.text);else if(c.isExportDeclaration(o)&&o.exportClause&&c.isNamedExports(o.exportClause))for(let r of o.exportClause.elements)n.add((r.propertyName??r.name).text);else c.isExportAssignment(o)&&c.isIdentifier(o.expression)&&(n.add(o.expression.text),t=o.expression.text)}return{reachableLocals:n,defaultTarget:t}}function Ef(e){for(let n of e.statements){if(c.isFunctionDeclaration(n)&&n.name!==void 0&&Un(n)&&c.getModifiers(n)?.some(t=>t.kind===c.SyntaxKind.DefaultKeyword)===!0)return{name:n.name.text,esm:!0};if(c.isExportAssignment(n)&&!n.isExportEquals&&c.isIdentifier(n.expression))return{name:n.expression.text,esm:!0};if(c.isExpressionStatement(n)&&c.isBinaryExpression(n.expression)){let t=n.expression;if(t.operatorToken.kind===c.SyntaxKind.EqualsToken&&je(t.left)&&c.isIdentifier(t.right))return{name:t.right.text,esm:!1}}}}function un(e){if(c.isCallExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="require"&&e.arguments.length===1&&e.arguments[0]!==void 0&&c.isStringLiteralLike(e.arguments[0]))return e.arguments[0].text}function je(e){return c.isPropertyAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&e.name.text==="exports"?!0:c.isElementAccessExpression(e)&&c.isIdentifier(e.expression)&&e.expression.text==="module"&&c.isStringLiteralLike(e.argumentExpression)&&e.argumentExpression.text==="exports"}function tn(e){if(je(e))return!0;if(!c.isPropertyAccessExpression(e)&&!c.isElementAccessExpression(e))return!1;let n=e.expression;return c.isIdentifier(n)&&n.text==="exports"?!0:je(n)}function st(e){return c.isPropertyAccessExpression(e.expression)&&c.isIdentifier(e.expression.expression)&&e.expression.expression.text==="Object"&&e.expression.name.text==="assign"}function sa(e){let n=!1,t=o=>{if(!n){if(c.isCallExpression(o)){let r=un(o);if(r!==void 0&&we(r)!=="package-root"){n=!0;return}}c.forEachChild(o,t)}};return t(e),n}function ia(e){let n=new Set,t=r=>r!==void 0&&sa(r),o=r=>{c.isVariableDeclaration(r)&&t(r.initializer)&&Et(r.name,n),c.isBinaryExpression(r)&&r.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isIdentifier(r.left)&&t(r.right)&&n.add(r.left.text),c.forEachChild(r,o)};return o(e),n}function aa(e,n){for(let t of e.properties)c.isShorthandPropertyAssignment(t)?n.add(t.name.text):c.isPropertyAssignment(t)&&c.isIdentifier(t.initializer)&&n.add(t.initializer.text)}function wf(e){let n=new Set;for(let l of e.statements)if(c.isFunctionDeclaration(l)&&l.name!==void 0)n.add(l.name.text);else if(c.isClassDeclaration(l)&&l.name!==void 0)n.add(l.name.text);else if(c.isVariableStatement(l))for(let i of l.declarationList.declarations)c.isIdentifier(i.name)&&i.initializer!==void 0&&(c.isFunctionExpression(i.initializer)||c.isArrowFunction(i.initializer)||c.isObjectLiteralExpression(i.initializer))&&n.add(i.name.text);let t=l=>c.isFunctionExpression(l)||c.isArrowFunction(l)||c.isObjectLiteralExpression(l)||c.isIdentifier(l)&&n.has(l.text),o=new Set,r=l=>{c.isIdentifier(l)?o.add(l.text):c.isObjectLiteralExpression(l)&&aa(l,o)},s=!1,a=l=>{if(!s){if(c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken)if(je(l.left)){r(l.right);let i=l.right;(c.isObjectLiteralExpression(i)?i.properties.every(u=>c.isShorthandPropertyAssignment(u)&&n.has(u.name.text)||c.isPropertyAssignment(u)&&t(u.initializer)):t(i))||(s=!0)}else tn(l.left)&&(t(l.right)||(s=!0));else(c.isCallExpression(l)&&st(l)&&l.arguments[0]!==void 0&&zn(l.arguments[0])||c.isExportDeclaration(l)&&l.moduleSpecifier!==void 0)&&(s=!0);s||c.forEachChild(l,a)}};if(a(e),!s&&o.size>0){for(let l of ua(e))if(o.has(l)){s=!0;break}}return s}function zn(e){return tn(e)||c.isIdentifier(e)&&e.text==="exports"}function la(e){if(!c.isPropertyAccessExpression(e.expression)||!c.isIdentifier(e.expression.expression))return!1;let n=e.expression.expression.text,t=e.expression.name.text;return n==="Object"&&(t==="defineProperty"||t==="defineProperties")||n==="Reflect"&&(t==="defineProperty"||t==="set")}function Nr(e){return la(e)&&e.arguments[0]!==void 0&&zn(e.arguments[0])}function vf(e){return la(e)&&e.arguments[0]!==void 0&&c.isIdentifier(e.arguments[0])&&e.arguments[0].text==="module"}function If(e){for(let n of e.declarations??[])if(c.isExportSpecifier(n)){if(n.isTypeOnly)return!0;let t=n.parent.parent;if(c.isExportDeclaration(t)&&t.isTypeOnly)return!0}else if(c.isImportSpecifier(n)){if(n.isTypeOnly)return!0;let t=n.parent.parent;if(c.isImportClause(t)&&t.isTypeOnly)return!0}return!1}function Af(e,n,t,o,r){let s=(e.declarations??[]).filter(l=>!c.isSourceFile(l)&&!c.isModuleDeclaration(l));for(let l of s){let i=l.getSourceFile(),d=n.toRel(i.fileName);if(d===null||r.has(d))continue;let u=t.get(`${d}::${String(l.getStart(i,!1))}`);if(u!==void 0)return u}let a=e.getName();for(let l of s){let i=n.toRel(l.getSourceFile().fileName);if(i===null||r.has(i))continue;let d=o.get(`${i}::${a}`);if(d!==void 0)return d}}function xo(e){return c.isPropertyAccessExpression(e)?e.name.text:c.isStringLiteralLike(e.argumentExpression)?e.argumentExpression.text:void 0}var Rr=/^[A-Za-z_$][A-Za-z0-9_$]*$/u;function Pr(e){let n=c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)?xo(e):void 0;return n!==void 0&&n!=="__proto__"&&Rr.test(n)?n:void 0}function _f(e){return e!=="__proto__"&&Rr.test(e)}function Ji(e){let n=_e(e);return c.isIdentifier(n)&&(n.text==="exports"||n.text==="module")||je(n)}function Nf(e){if(!c.isArrayLiteralExpression(e)&&!c.isObjectLiteralExpression(e))return!1;let n=!1,t=o=>{n||(tn(o)?n=!0:c.forEachChild(o,t))};return t(e),n}function $r(e){let n=!1,t=new Map,o=r=>{if(!n){if(c.isBinaryExpression(r)&&r.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&r.operatorToken.kind<=c.SyntaxKind.LastAssignment){if(je(r.left)||c.isIdentifier(r.left)&&r.left.text==="exports")n=!0;else if(r.operatorToken.kind===c.SyntaxKind.EqualsToken&&Ji(r.right))n=!0;else if(Nf(r.left))n=!0;else if(tn(r.left)){let s=Pr(r.left);s===void 0?n=!0:t.set(s,(t.get(s)??0)+1)}}else(c.isCallExpression(r)&&st(r)&&r.arguments[0]!==void 0&&zn(r.arguments[0])||c.isCallExpression(r)&&Nr(r)||c.isCallExpression(r)&&vf(r)||c.isVariableDeclaration(r)&&r.initializer!==void 0&&Ji(r.initializer))&&(n=!0);n||c.forEachChild(r,o)}};return o(e),{surfaceEscapes:n,assignCount:t}}function Or(e){let n=[];for(let t of e.statements){if(!c.isExpressionStatement(t)||!c.isBinaryExpression(t.expression))continue;let o=t.expression;o.operatorToken.kind===c.SyntaxKind.EqualsToken&&(!tn(o.left)||je(o.left)||n.push({bin:o,name:Pr(o.left)}))}return n}function Rf(e){let{surfaceEscapes:n,assignCount:t}=$r(e);if(n)return[];let o=[];for(let{bin:r,name:s}of Or(e))s===void 0||(t.get(s)??0)!==1||(c.isFunctionExpression(r.right)||c.isArrowFunction(r.right))&&o.push({name:s,value:r.right});return o}function Pf(e,n){let{surfaceEscapes:t,assignCount:o}=$r(e);if(t)return[];let r=[];for(let{bin:s,name:a}of Or(e))a===void 0||(o.get(a)??0)!==1||c.isIdentifier(s.right)&&!n.has(s.right.text)&&r.push(s.right.text);return r}function $f(e,n){let{surfaceEscapes:t,assignCount:o}=$r(e);for(let{bin:r,name:s}of Or(e)){let a=r.right;if(!(c.isFunctionExpression(a)||c.isArrowFunction(a)||c.isIdentifier(a)))continue;let i=c.isFunctionExpression(a)||c.isArrowFunction(a)||c.isIdentifier(a)&&!n.has(a.text);if(!(!t&&s!==void 0&&(o.get(s)??0)===1&&i))return!0}return!1}function Of(e){let n=c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)?e.expression:void 0;return n!==void 0&&c.isIdentifier(n)&&n.text==="exports"?"exports":"module.exports"}function Zi(e){let n=e.parent;return n===void 0?!1:c.isPropertyAccessExpression(n)?n.name===e:c.isQualifiedName(n)?n.right===e:c.isBindingElement(n)||c.isImportSpecifier(n)?n.propertyName===e:c.isExportSpecifier(n)?!0:c.isPropertyAssignment(n)||c.isPropertyDeclaration(n)||c.isPropertySignature(n)||c.isMethodDeclaration(n)||c.isMethodSignature(n)||c.isGetAccessorDeclaration(n)||c.isSetAccessorDeclaration(n)||c.isEnumMember(n)?n.name===e:!1}function Qi(e){for(let n=e.parent;n!==void 0;n=n.parent){if(c.isSourceFile(n))return!0;if(!c.isArrowFunction(n)&&(c.isFunctionLike(n)||c.isClassLike(n)))return!1}return!0}function Cf(e,n){let t=o=>{c.isIdentifier(o)&&(o.text==="exports"||o.text==="module")&&n.add(o),c.forEachChild(o,t)};t(e)}function Mf(e){let n=[],t=new Set;for(let s of e.statements){if(c.isExportDeclaration(s)||c.isExportAssignment(s)||c.isImportDeclaration(s)||c.isImportEqualsDeclaration(s)||Un(s))return null;if(!c.isExpressionStatement(s)||!c.isBinaryExpression(s.expression))continue;let a=s.expression;if(a.operatorToken.kind===c.SyntaxKind.EqualsToken){if(je(a.left))n.push({kind:"whole",value:a.right});else if(tn(a.left)){let l=Pr(a.left);if(l===void 0)return null;n.push({kind:"member",name:l,value:a.right,root:Of(a.left)})}else continue;Cf(a.left,t)}}let o=!1,r=s=>{if(!o){if(c.isIdentifier(s)&&(s.text==="exports"||s.text==="module")&&!t.has(s)&&!Zi(s)){o=!0;return}if(s.kind===c.SyntaxKind.ThisKeyword&&Qi(s)){o=!0;return}if(c.isIdentifier(s)&&s.text==="arguments"&&!Zi(s)&&Qi(s)){o=!0;return}c.forEachChild(s,r)}};return r(e),o?null:n}function Ar(e){return c.isIdentifier(e)||c.isStringLiteralLike(e)?e.text:void 0}function ea(e,n,t){return c.isIdentifier(e)?n(e.text):t?.(e)}function Tf(e,n,t,o){let r=new Map,s=Mf(e);if(s===null||s.filter(m=>m.kind==="whole").length>1)return r;let a=s.findIndex(m=>m.kind==="whole"),l=(m,g)=>a>=0&&g>a&&m.kind==="member"&&m.root==="exports",i=s.some(l);if(i){let m=s[a];if(m===void 0||m.kind!=="whole"||!c.isObjectLiteralExpression(m.value))return r}let d=i?s.filter((m,g)=>!l(m,g)):s,u=new Map;for(let m of d)m.kind==="member"&&u.set(m.name,(u.get(m.name)??0)+1);let p=m=>n.has(m)?void 0:t(m),f=(m,g)=>{g===void 0?r.delete(m):r.set(m,g)};for(let m of d){if(m.kind==="member"){f(m.name,(u.get(m.name)??0)>1?void 0:ea(m.value,p,o));continue}r.clear();let g=m.value;if(c.isObjectLiteralExpression(g))for(let y of g.properties){if(c.isSpreadAssignment(y))return new Map;if(c.isShorthandPropertyAssignment(y)){f(y.name.text,p(y.name.text));continue}let b=Ar(y.name);if(b===void 0)return new Map;f(b,c.isPropertyAssignment(y)?ea(y.initializer,p,o):void 0)}}return r}function da(e,n,t,o){let r=new Map,s=l=>l!==void 0&&we(l)==="relative"?t.get(`${n}::${l}`):void 0,a=l=>{if(c.isVariableDeclaration(l)&&l.initializer!==void 0){let i=l.initializer;if(c.isIdentifier(l.name)&&!o.has(l.name.text)){let d=s(un(i));if(d!==void 0)r.set(l.name.text,{kind:"whole",target:d});else if((c.isPropertyAccessExpression(i)||c.isElementAccessExpression(i))&&c.isCallExpression(i.expression)){let u=s(un(i.expression)),p=xo(i);u!==void 0&&p!==void 0&&r.set(l.name.text,{kind:"member",target:u,member:p})}}else if(c.isObjectBindingPattern(l.name)){let d=s(un(i));if(d!==void 0){for(let u of l.name.elements)if(c.isIdentifier(u.name)&&!o.has(u.name.text)){let p=u.propertyName!==void 0&&c.isIdentifier(u.propertyName)?u.propertyName.text:u.name.text;r.set(u.name.text,{kind:"member",target:d,member:p})}}}}c.forEachChild(l,a)};return a(e),r}function Df(e,n,t,o){let r=a=>a!==void 0&&we(a)==="relative"?t.get(`${n}::${a}`):void 0,s=r(un(e));if(s!==void 0)return{kind:"whole",target:s};if(c.isPropertyAccessExpression(e)||c.isElementAccessExpression(e)){let a=xo(e);if(a===void 0)return;let l=r(un(e.expression));if(l!==void 0)return{kind:"member",target:l,member:a};if(c.isIdentifier(e.expression)){let i=o.get(e.expression.text);if(i?.kind==="whole")return{kind:"member",target:i.target,member:a}}return}if(c.isIdentifier(e))return o.get(e.text)}function ca(e,n,t,o,r){let s=[],a=!1,l=p=>{if(sa(p))return!0;let f=!1,m=g=>{f||(c.isIdentifier(g)&&r.has(g.text)?f=!0:c.forEachChild(g,m))};return m(p),f},i=(p,f)=>{let m=Df(p,n,t,o);m!==void 0?s.push({source:m,exportedName:f}):l(p)&&(a=!0)},d=p=>{if(c.isObjectLiteralExpression(p)){for(let f of p.properties)if(c.isSpreadAssignment(f))i(f.expression,"default");else if(c.isPropertyAssignment(f)){let m=c.isIdentifier(f.name)||c.isStringLiteralLike(f.name)?f.name.text:"default";i(f.initializer,m)}else if(c.isShorthandPropertyAssignment(f)){let m=o.get(f.name.text);m!==void 0&&s.push({source:m,exportedName:f.name.text})}return}i(p,"default")},u=p=>{if(c.isBinaryExpression(p)&&p.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&p.operatorToken.kind<=c.SyntaxKind.LastAssignment){if(je(p.left)){d(p.right);return}if(tn(p.left)){let f=c.isPropertyAccessExpression(p.left)?p.left.name.text:c.isElementAccessExpression(p.left)&&c.isStringLiteralLike(p.left.argumentExpression)?p.left.argumentExpression.text:"default";i(p.right,f);return}}else if(c.isExportAssignment(p)&&p.isExportEquals){i(p.expression,"default");return}else if(c.isCallExpression(p)&&st(p)&&p.arguments[0]!==void 0&&zn(p.arguments[0])){for(let f of p.arguments.slice(1))d(f);return}c.forEachChild(p,u)};return u(e),{sources:s,residual:a}}function ua(e){let n=new Set,t=r=>{let s=r;for(;c.isPropertyAccessExpression(s)||c.isElementAccessExpression(s);)s=s.expression;return c.isIdentifier(s)?s.text:void 0},o=r=>{let s=fa(r);if(s!==void 0){let a=t(s);a!==void 0&&n.add(a)}c.forEachChild(r,o)};return o(e),n}function fa(e){return c.isBinaryExpression(e)&&e.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&e.operatorToken.kind<=c.SyntaxKind.LastAssignment&&(c.isPropertyAccessExpression(e.left)||c.isElementAccessExpression(e.left))?e.left:void 0}function go(e){if(c.isIdentifier(e))return[e.text];let n=[];for(let t of e.elements)c.isBindingElement(t)&&n.push(...go(t.name));return n}function Fe(e){if(c.isIdentifier(e))return[e.text];if(c.isParenthesizedExpression(e)||c.isAsExpression(e)||c.isNonNullExpression(e)||c.isSatisfiesExpression(e)||c.isTypeAssertionExpression(e)||c.isAwaitExpression(e))return Fe(e.expression);if(c.isYieldExpression(e))return e.expression!==void 0?Fe(e.expression):[];if(c.isBinaryExpression(e)){let n=e.operatorToken.kind;return n===c.SyntaxKind.BarBarToken||n===c.SyntaxKind.AmpersandAmpersandToken||n===c.SyntaxKind.QuestionQuestionToken?[...Fe(e.left),...Fe(e.right)]:n===c.SyntaxKind.CommaToken?Fe(e.right):[]}return c.isConditionalExpression(e)?[...Fe(e.whenTrue),...Fe(e.whenFalse)]:c.isArrayLiteralExpression(e)?e.elements.flatMap(n=>c.isSpreadElement(n)?Fe(n.expression):c.isOmittedExpression(n)?[]:Fe(n)):c.isObjectLiteralExpression(e)?e.properties.flatMap(n=>c.isShorthandPropertyAssignment(n)?[n.name.text]:c.isPropertyAssignment(n)?Fe(n.initializer):c.isSpreadAssignment(n)?Fe(n.expression):[]):[]}function pa(e,n){let t=[],o=(l,i)=>{for(let d of l)for(let u of i)d!==u&&t.push({a:d,b:u})},r=l=>c.isIdentifier(l)?[l.text]:c.isArrayLiteralExpression(l)?l.elements.flatMap(r):c.isObjectLiteralExpression(l)?l.properties.flatMap(i=>c.isShorthandPropertyAssignment(i)?[i.name.text]:c.isPropertyAssignment(i)?r(i.initializer):[]):[],s=l=>{c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken?o(r(l.left),Fe(l.right)):c.isVariableDeclaration(l)&&l.initializer!==void 0?o(go(l.name),Fe(l.initializer)):(c.isForOfStatement(l)||c.isForInStatement(l))&&c.isVariableDeclarationList(l.initializer)&&l.initializer.declarations[0]!==void 0&&o(go(l.initializer.declarations[0].name),Fe(l.expression)),c.forEachChild(l,s)};s(e);let a=new Set(n);for(let l=!0;l;){l=!1;for(let{a:i,b:d}of t)a.has(i)&&!a.has(d)&&(a.add(d),l=!0),a.has(d)&&!a.has(i)&&(a.add(i),l=!0)}return a}function ma(e,n){let t=l=>{if(!c.isPropertyAccessExpression(l)&&!c.isElementAccessExpression(l))return;let i=l;for(;c.isPropertyAccessExpression(i)||c.isElementAccessExpression(i);)i=i.expression;return c.isIdentifier(i)?i.text:void 0},o=[],r=(l,i)=>{for(let u of Fe(i))o.push({name:l,root:u});let d=t(i);d!==void 0&&o.push({name:l,root:d})},s=l=>{c.isVariableDeclaration(l)&&c.isIdentifier(l.name)&&l.initializer!==void 0?r(l.name.text,l.initializer):c.isBinaryExpression(l)&&l.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isIdentifier(l.left)&&r(l.left.text,l.right),c.forEachChild(l,s)};s(e);let a=new Map(n);for(let l=!0;l;){l=!1;for(let{name:i,root:d}of o){let u=a.get(d);u!==void 0&&!a.has(i)&&(a.set(i,u),l=!0)}}return a}function ha(e){return pa(e,ua(e))}function Lf(e,n){let t=i=>i>=c.SyntaxKind.FirstAssignment&&i<=c.SyntaxKind.LastAssignment,o=i=>{let d=i.parent;if(d===void 0||!c.isObjectLiteralExpression(d))return!1;let u=d.parent;return u!==void 0&&c.isBinaryExpression(u)&&u.operatorToken.kind===c.SyntaxKind.EqualsToken&&u.right===d&&tn(u.left)?!0:u!==void 0&&c.isCallExpression(u)&&st(u)&&u.arguments[0]!==void 0&&zn(u.arguments[0])&&u.arguments.indexOf(d)>0},r=(i,d)=>{if((c.isFunctionDeclaration(d)||c.isFunctionExpression(d))&&d.name===i||c.isVariableDeclaration(d)&&d.name===i||c.isParameter(d)&&d.name===i||c.isBindingElement(d)&&d.name===i||(c.isCallExpression(d)||c.isNewExpression(d))&&d.expression===i)return!0;if((c.isPropertyAccessExpression(d)||c.isElementAccessExpression(d))&&d.expression===i){let u=d;for(;u.parent!==void 0&&(c.isPropertyAccessExpression(u.parent)||c.isElementAccessExpression(u.parent))&&u.parent.expression===u;)u=u.parent;let p=u.parent;return!(p!==void 0&&c.isBinaryExpression(p)&&t(p.operatorToken.kind)&&p.left===u)}return c.isBinaryExpression(d)&&d.operatorToken.kind===c.SyntaxKind.EqualsToken&&d.right===i&&tn(d.left)?!0:c.isShorthandPropertyAssignment(d)&&d.name===i||c.isPropertyAssignment(d)&&d.initializer===i?o(d):!!(c.isExportAssignment(d)&&d.expression===i||c.isExportSpecifier(d))},s=(i,d)=>c.isPropertyAccessExpression(d)&&d.name===i||c.isPropertyAssignment(d)&&d.name===i||(c.isMethodDeclaration(d)||c.isGetAccessorDeclaration(d)||c.isSetAccessorDeclaration(d))&&d.name===i,a=!1,l=(i,d)=>{if(!a){if(c.isIdentifier(i)&&d!==void 0&&n.has(i.text)&&!s(i,d)&&!r(i,d)){a=!0;return}c.forEachChild(i,u=>l(u,i))}};return l(e,void 0),a}function Ff(e){let n=new Set;for(let i of e.statements)if(c.isFunctionDeclaration(i)&&i.name!==void 0)n.add(i.name.text);else if(c.isVariableStatement(i))for(let d of i.declarationList.declarations)c.isIdentifier(d.name)&&d.initializer!==void 0&&(c.isFunctionExpression(d.initializer)||c.isArrowFunction(d.initializer))&&n.add(d.name.text);let t=new Set,o=i=>{c.isBinaryExpression(i)&&i.operatorToken.kind===c.SyntaxKind.EqualsToken?(je(i.left)&&(c.isIdentifier(i.right)?t.add(i.right.text):c.isObjectLiteralExpression(i.right)&&aa(i.right,t)),je(i.right)&&c.isIdentifier(i.left)&&t.add(i.left.text)):c.isVariableDeclaration(i)&&c.isIdentifier(i.name)&&i.initializer!==void 0&&je(i.initializer)&&t.add(i.name.text),c.forEachChild(i,o)};if(o(e),t.size>0){if(Lf(e,t))return!0;let i=ma(e,new Map([...t].map(u=>[u,u]))),d=ha(e);for(let u of i.keys())if(d.has(u))return!0}let r=i=>c.isIdentifier(i)&&n.has(i.text),s=i=>i.properties.every(d=>c.isShorthandPropertyAssignment(d)&&n.has(d.name.text)||c.isPropertyAssignment(d)&&r(d.initializer)),a=!1,l=i=>{if(!a){if(c.isBinaryExpression(i)){let d=i.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&i.operatorToken.kind<=c.SyntaxKind.LastAssignment;d&&je(i.left)?i.operatorToken.kind===c.SyntaxKind.EqualsToken&&(r(i.right)||c.isObjectLiteralExpression(i.right)&&s(i.right))||(a=!0):d&&tn(i.left)&&(a=!0)}else c.isCallExpression(i)?(st(i)&&i.arguments[0]!==void 0&&zn(i.arguments[0])||Nr(i))&&(a=!0):(c.isExportAssignment(i)&&i.isExportEquals&&!c.isIdentifier(i.expression)||c.isExportDeclaration(i)&&i.moduleSpecifier!==void 0)&&(a=!0);a||c.forEachChild(i,l)}};return l(e),a}var jf=8;function na(e,n,t){let o=new Set,r=da(e,n,t,ot(e)),s=ca(e,n,t,r,ia(e));for(let{source:a}of s.sources)o.add(a.target);for(let a of e.statements)if(c.isExportDeclaration(a)&&a.moduleSpecifier!==void 0&&c.isStringLiteralLike(a.moduleSpecifier)&&we(a.moduleSpecifier.text)==="relative"){let l=t.get(`${n}::${a.moduleSpecifier.text}`);l!==void 0&&o.add(l)}return o}function Bf(e,n,t,o=new Map){let r=new Set(n.modules.filter(k=>k.isEntrypoint).map(k=>String(k.id)));if(r.size===0)return{exports:[],exportBindings:[],diagnostics:[]};let s=new Set(n.modules.filter(k=>k.externalSurface===!0).map(k=>String(k.id))),a=new Map,l=new Map,i=new Map,d=new Map;for(let k of t){if(k.name==="<toplevel>"){d.set(String(k.moduleId),k);continue}if(a.set(`${String(k.moduleId)}::${String(k.declRange.start)}`,k),k.name!==void 0&&l.set(`${String(k.moduleId)}::${k.name}`,k),k.isExported&&k.name!==void 0){let h=i.get(String(k.moduleId))??[];h.push(k),i.set(String(k.moduleId),h)}}if(o.size>0){let k=new Map(t.map(h=>[String(h.id),h]));for(let[h,S]of o){let _=k.get(String(S));_!==void 0&&!a.has(h)&&a.set(h,_)}}let u=new Map;for(let k of n.imports)k.resolvedModuleId!==void 0&&u.set(`${k.moduleId}::${k.specifier}`,String(k.resolvedModuleId));let p=new Map;for(let k of e.sourceFiles){let h=e.toRel(k.fileName);h!==null&&p.set(h,k)}let f=new Map,m=k=>{let h=f.get(k);if(h!==void 0)return h;let S=p.get(k),_=S===void 0?!0:Ff(S);return f.set(k,_),_},g=new Set,y=(k,h)=>h!==void 0&&we(h)==="relative"?u.get(`${k}::${h}`):void 0,b=k=>{if(c.isIdentifier(k))return k.text;if(c.isPropertyAccessExpression(k)){let h=b(k.expression);return h===void 0?void 0:`${h}.${k.name.text}`}if(c.isElementAccessExpression(k)&&c.isStringLiteralLike(k.argumentExpression)){let h=b(k.expression);return h===void 0?void 0:`${h}.${k.argumentExpression.text}`}},x=k=>{let h=k;for(;c.isPropertyAccessExpression(h)||c.isElementAccessExpression(h);)h=h.expression;return un(h)};for(let k of e.sourceFiles){let h=e.toRel(k.fileName);if(h===null)continue;let S=new Map,_=new Map,P=(N,j)=>{let O=y(h,un(j));if(O!==void 0){if(c.isIdentifier(N))_.set(N.text,O),S.set(N.text,O);else if(c.isObjectBindingPattern(N)||c.isArrayBindingPattern(N))for(let F of go(N))_.set(F,O);else if(c.isPropertyAccessExpression(N)||c.isElementAccessExpression(N)){let F=b(N);F!==void 0&&S.set(F,O)}}},v=N=>{c.isVariableDeclaration(N)&&N.initializer!==void 0?P(N.name,N.initializer):c.isBinaryExpression(N)&&N.operatorToken.kind===c.SyntaxKind.EqualsToken&&P(N.left,N.right),c.forEachChild(N,v)};v(k);let T=N=>{let j=fa(N);if(j!==void 0){let O=j.expression,F=y(h,x(O));F!==void 0&&g.add(F);let K=b(O),te=K!==void 0?S.get(K):void 0;te!==void 0&&g.add(te)}c.forEachChild(N,T)};if(T(k),_.size>0){let N=ma(k,_),j=ha(k);for(let[O,F]of N)j.has(O)&&g.add(F)}}let I=[],w=[],A=[];for(let k of e.sourceFiles){let h=e.toRel(k.fileName);if(h===null||!r.has(h))continue;let S=e.checker.getSymbolAtLocation(k),_=new Set,P=new Set,v=0,T=(D,C)=>{if(s.has(String(D.moduleId))||_.has(String(D.id)))return;_.add(String(D.id));let H=`${h}#reexport:${String(v)}:${C}`;v+=1,I.push({id:H,moduleId:h,exportedName:C,kind:"value",reexportOf:{moduleId:String(D.moduleId),name:D.name??C}}),w.push({exportId:H,target:{kind:"function",functionId:D.id}})},N=D=>{if(If(D))return;let C=D;if((D.flags&c.SymbolFlags.Alias)!==0)try{C=e.checker.getAliasedSymbol(D)}catch{return}let H=Af(C,e,a,l,s);if(H!==void 0){T(H,D.getName());return}if((C.flags&c.SymbolFlags.Module)!==0&&!P.has(C)){P.add(C);try{for(let J of e.checker.getExportsOfModule(C))N(J)}catch{}}};if(S!==void 0)for(let D of e.checker.getExportsOfModule(S))N(D);let j=da(k,h,u,ot(k)),O=ca(k,h,u,j,ia(k)),F=new Set,K=O.residual,te=D=>{let C=p.get(D);D.includes("node_modules/")||C===void 0||wf(C)?K=!0:F.add(D)};for(let{source:D,exportedName:C}of O.sources){let H=i.get(D.target)??[],J=g.has(D.target);if(D.kind==="whole"){for(let G of H)T(G,G.name??C);J?K=!0:(H.length===0||m(D.target))&&te(D.target)}else{let G=H.filter(Y=>Y.name===D.member);for(let Y of G)T(Y,C);J?K=!0:(G.length===0||m(D.target))&&te(D.target)}}let U=new Set,X=[];for(let D of na(k,h,u))X.push({target:D,depth:1});for(;X.length>0;){let D=X.shift();if(D===void 0)break;let{target:C,depth:H}=D;if(U.has(C)||H>jf||(U.add(C),C.split("/").includes("node_modules")))continue;let J=p.get(C);if(J===void 0)continue;let G=d.get(C);G!==void 0&&!m(C)&&T(G,"<load>");for(let Y of na(J,C,u))U.has(Y)||X.push({target:Y,depth:H+1})}$f(k,ot(k))&&(K=!0);for(let D of F)A.push({code:"unresolved-reexport",path:h,detail:`entrypoint whole/member re-exports app-owned relative module ${D} whose exact entry surface could not be lifted; capping at unknown, corridor-scoped to that module (ADR-024, ROADMAP R3.3)`,anchor:D});K&&A.push({code:"unresolved-reexport",path:h,detail:"entrypoint has a CJS re-export the analyzer cannot pin to concrete relative functions (computed/dynamic/package-subpath/tainted, or an externally-mutated barrel); capping at unknown, globally (ADR-024, ROADMAP CJS.5)"})}return{exports:I,exportBindings:w,diagnostics:A}}var rt=new Set(["valueOf","toString","toJSON","then","catch","finally","next","return","throw"]),Kf=new Set(["defineProperty","defineProperties","create"]);function Uf(e){let n=!0,t=r=>c.isIdentifier(r)||c.isStringLiteral(r)||c.isNumericLiteral(r)?rt.has(r.text):c.isComputedPropertyName(r)&&c.isStringLiteralLike(r.expression)?rt.has(r.expression.text):!1,o=r=>{if(n){if(c.isNewExpression(r)||c.isForOfStatement(r)||c.isSpreadElement(r)||c.isSpreadAssignment(r)||c.isArrayBindingPattern(r)||c.isGetAccessorDeclaration(r)||c.isSetAccessorDeclaration(r)||c.isYieldExpression(r)&&r.asteriskToken!==void 0||c.canHaveDecorators(r)&&(c.getDecorators(r)?.length??0)>0){n=!1;return}if((c.isPropertyAccessExpression(r)||c.isMethodDeclaration(r)||c.isPropertyAssignment(r))&&t(r.name)||c.isPropertyDeclaration(r)&&t(r.name)||c.isShorthandPropertyAssignment(r)&&t(r.name)||c.isBindingElement(r)&&t(r.propertyName??r.name)||c.isElementAccessExpression(r)&&c.isStringLiteralLike(r.argumentExpression)&&rt.has(r.argumentExpression.text)){n=!1;return}if(c.isCallExpression(r)&&c.isPropertyAccessExpression(r.expression)&&c.isIdentifier(r.expression.expression)&&r.expression.expression.text==="Object"&&Kf.has(r.expression.name.text)){n=!1;return}c.forEachChild(r,o)}};return o(e),n}function So(e){if(c.isIdentifier(e)||c.isStringLiteral(e)||c.isNumericLiteral(e))return e.text}function ga(e){let n=t=>c.canHaveDecorators(t)&&(c.getDecorators(t)?.length??0)>0;return n(e)||e.members.some(n)}function zf(e){let n=!1,t=new Set,o=[],r=new Map,s=(f,m)=>{let g=r.get(f);g===void 0?r.set(f,[m]):g.push(m)},a=f=>{c.isIdentifier(f)?t.add(f.text):o.push(f)},l=f=>{for(let m of f.properties)c.isShorthandPropertyAssignment(m)?t.add(m.name.text):c.isPropertyAssignment(m)?o.push(m.initializer):n=!0},i=f=>{if(c.isBinaryExpression(f)&&f.operatorToken.kind===c.SyntaxKind.EqualsToken){let m=f.left,g=f.right;je(m)?c.isObjectLiteralExpression(g)?l(g):c.isIdentifier(g)||c.isFunctionExpression(g)||c.isArrowFunction(g)||c.isClassExpression(g)?a(g):n=!0:tn(m)?(c.isElementAccessExpression(m)&&!c.isStringLiteralLike(m.argumentExpression)&&(n=!0),a(g)):c.isIdentifier(m)?s(m.text,g):(c.isPropertyAccessExpression(m)||c.isElementAccessExpression(m))&&c.isIdentifier(m.expression)&&s(m.expression.text,g)}else if(c.isCallExpression(f))(st(f)&&f.arguments[0]!==void 0&&zn(f.arguments[0])||Nr(f))&&(n=!0);else if(c.isVariableDeclaration(f)&&c.isIdentifier(f.name)&&f.initializer!==void 0)s(f.name.text,f.initializer);else if((c.isFunctionDeclaration(f)||c.isClassDeclaration(f))&&f.name!==void 0)s(f.name.text,f),Un(f)&&t.add(f.name.text);else if(c.isExportDeclaration(f)){if(f.exportClause===void 0)n=!0;else if(f.moduleSpecifier===void 0&&c.isNamedExports(f.exportClause))for(let m of f.exportClause.elements)t.add((m.propertyName??m.name).text)}else if(c.isExportAssignment(f))f.isExportEquals&&!c.isIdentifier(f.expression)?n=!0:a(f.expression);else if(c.isVariableStatement(f)&&Un(f))for(let m of f.declarationList.declarations)c.isIdentifier(m.name)&&t.add(m.name.text);c.forEachChild(f,i)};i(e);let d=new Set,u=[...t],p=f=>{let m=g=>{c.isIdentifier(g)&&u.push(g.text),c.forEachChild(g,m)};m(f)};for(let f of o)p(f);for(;u.length>0;){let f=u.pop();if(!(f===void 0||d.has(f))){d.add(f);for(let m of r.get(f)??[])p(m)}}return{names:d,opaque:n}}var Wf=512,Vf=new Set(["get","post","put","patch","delete","options","head"]);function qf(e){for(let n of e.statements){if(c.isExportAssignment(n)&&n.isExportEquals!==!0)return n.expression;if(c.isExpressionStatement(n)&&c.isBinaryExpression(n.expression)&&n.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(n.expression.left)&&c.isIdentifier(n.expression.left.expression)){let t=n.expression.left.expression.text,o=n.expression.left.name.text;if(t==="module"&&o==="exports"||t==="exports"&&o==="default")return n.expression.right}}return null}function Gf(e){let n=new Map,t=qf(e);if(t===null)return n;let o=s=>{for(let a of s.properties)if(c.isPropertyAssignment(a)&&c.isObjectLiteralExpression(a.initializer)){let l=So(a.name);l!==void 0&&n.set(l,a.initializer)}};if(c.isObjectLiteralExpression(t))return o(t),n;if(!c.isIdentifier(t))return n;let r=t.text;for(let s of e.statements)if(c.isVariableStatement(s))for(let a of s.declarationList.declarations)c.isIdentifier(a.name)&&a.name.text===r&&a.initializer!==void 0&&c.isObjectLiteralExpression(a.initializer)&&o(a.initializer);else if(c.isExpressionStatement(s)&&c.isBinaryExpression(s.expression)&&s.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(s.expression.left)&&c.isIdentifier(s.expression.left.expression)&&s.expression.left.expression.text===r&&c.isObjectLiteralExpression(s.expression.right)){let a=s.expression.left.name.text;n.set(a,s.expression.right)}return n}function Hf(e){for(let n of e.properties){if(c.isMethodDeclaration(n)&&c.isIdentifier(n.name)&&n.name.text==="handler")return n;if(c.isPropertyAssignment(n)&&c.isIdentifier(n.name)&&n.name.text==="handler"&&(c.isArrowFunction(n.initializer)||c.isFunctionExpression(n.initializer)))return n.initializer}return null}function Xf(e,n){for(let o of e.properties){let r;if(c.isPropertyAssignment(o)||c.isMethodDeclaration(o)?r=So(o.name):c.isShorthandPropertyAssignment(o)&&(r=o.name.text),r==="method"||r==="url"||r==="middlewares")return!0}let t=n.parameters.length;return t>=2&&t<=3}function Yf(e,n){let t=[],o=new Set,r=(l,i,d)=>{if(t.length>=Wf||l==="__proto__"||!Rr.test(l))return;let u=`${e}#handler:${l}`;o.has(u)||(o.add(u),t.push({id:u,node:i,memberPath:l,idiom:d}))};for(let[l,i]of Gf(n)){let d=Hf(i);d!==null&&Xf(i,d)&&r(l,d,"descriptor-object")}let s=0,a=l=>{if(c.isCallExpression(l)&&c.isPropertyAccessExpression(l.expression)&&c.isIdentifier(l.expression.expression)&&Vf.has(l.expression.name.text)&&l.arguments.length>=2&&l.arguments[0]!==void 0&&c.isStringLiteralLike(l.arguments[0])){let i=l.expression.name.text;for(let d=1;d<l.arguments.length;d+=1){let u=l.arguments[d];u!==void 0&&(c.isArrowFunction(u)||c.isFunctionExpression(u))&&r(`${i}_${String(s)}_${String(d)}`,u,"router-verb")}s+=1}c.forEachChild(l,a)};return a(n),t}function Jf(e,n,t,o,r,s){let a=`${e}#class:${t}`,l=[],i=new Set;for(let d of o.members){let u,p,f;if(c.isConstructorDeclaration(d))u="constructor",p="ctor",f=!1;else if(c.isMethodDeclaration(d))u=So(d.name),p="method",f=u!==void 0&&!rt.has(u);else continue;if(u===void 0||i.has(u))continue;i.add(u);let m=`${e}#${t}.${u}`;r.push({id:m,moduleId:e,name:u,kind:p,enclosingClassId:a,declRange:Nn(e,d,n),isExported:!1,publicSurfaceReachable:!1}),l.push(m),f&&s.push({start:d.getStart(n,!1),end:d.getEnd(),id:m})}return{id:a,moduleId:e,name:t,implementsRefs:[],members:l}}function Zf(e,n,t=[],o=!1,r){let s=[],a=new Map,l=[],{reachableLocals:i,defaultTarget:d}=kf(n),u=ot(n),p=`${e}#<toplevel>`;s.push({id:p,moduleId:e,name:"<toplevel>",kind:"function",declRange:{path:e,start:0,end:n.getEnd()},isExported:!1,publicSurfaceReachable:!1});let f=(h,S)=>{let _=`${e}#${h}`;return s.push({id:_,moduleId:e,name:h,kind:"function",declRange:Nn(e,S,n),isExported:i.has(h),publicSurfaceReachable:i.has(h)}),a.set(h,{kind:"function",functionId:_}),l.push({start:S.getStart(n,!1),end:S.getEnd(),id:_}),_},m=[],g=!e.split("/").includes("node_modules");if(g)for(let h of Pf(n,u))i.add(h);let y=g?zf(n):void 0,b=(h,S,_)=>{y===void 0||y.opaque||y.names.has(h)||Un(_)||ga(S)||m.push(Jf(e,n,h,S,s,l))};for(let h of n.statements)if(c.isFunctionDeclaration(h)&&h.name!==void 0)f(h.name.text,h);else if(c.isClassDeclaration(h)&&h.name!==void 0)b(h.name.text,h,h);else if(c.isVariableStatement(h))for(let S of h.declarationList.declarations){if(c.isObjectBindingPattern(S.name)&&S.initializer!==void 0&&c.isCallExpression(S.initializer)&&c.isIdentifier(S.initializer.expression)&&S.initializer.expression.text==="require"&&S.initializer.arguments.length===1&&S.initializer.arguments[0]!==void 0&&c.isStringLiteralLike(S.initializer.arguments[0])){let P=S.initializer.arguments[0].text;for(let v of S.name.elements){if(v.dotDotDotToken!==void 0||v.initializer!==void 0||!c.isIdentifier(v.name))continue;let T=v.propertyName??v.name;!c.isIdentifier(T)&&!c.isStringLiteralLike(T)||a.set(v.name.text,{kind:"import",specifier:P,form:{named:T.text}})}continue}if(!c.isIdentifier(S.name)||S.initializer===void 0)continue;let _=S.initializer;if(c.isFunctionExpression(_)||c.isArrowFunction(_))f(S.name.text,S);else if(c.isClassExpression(_))b(S.name.text,_,h);else if(c.isCallExpression(_)&&c.isIdentifier(_.expression)&&_.expression.text==="require"&&_.arguments.length===1&&_.arguments[0]!==void 0&&c.isStringLiteralLike(_.arguments[0]))a.set(S.name.text,{kind:"import",specifier:_.arguments[0].text,form:"whole"});else if((c.isPropertyAccessExpression(_)||c.isElementAccessExpression(_))&&xo(_)==="default"&&c.isCallExpression(_.expression)){let P=un(_.expression);P!==void 0&&a.set(S.name.text,{kind:"import",specifier:P,form:"require-default"})}}else if(c.isImportDeclaration(h)&&c.isStringLiteralLike(h.moduleSpecifier)){let S=h.moduleSpecifier.text,_=h.importClause;if(_!==void 0){_.name!==void 0&&a.set(_.name.text,{kind:"import",specifier:S,form:"default"});let P=_.namedBindings;if(P!==void 0&&c.isNamespaceImport(P))a.set(P.name.text,{kind:"import",specifier:S,form:"namespace"});else if(P!==void 0&&c.isNamedImports(P))for(let v of P.elements){let T=(v.propertyName??v.name).text;a.set(v.name.text,{kind:"import",specifier:S,form:{named:T}})}}}else c.isImportEqualsDeclaration(h)&&c.isExternalModuleReference(h.moduleReference)&&c.isStringLiteralLike(h.moduleReference.expression)&&a.set(h.name.text,{kind:"import",specifier:h.moduleReference.expression.text,form:"whole"});let x=new Map,I,w=new Map,A=new Map;if(g)for(let{name:h,value:S}of Rf(n)){let _=`${e}#member-export:${h}`;s.push({id:_,moduleId:e,name:h,kind:c.isArrowFunction(S)?"arrow":"function",declRange:Nn(e,S,n),isExported:!0,publicSurfaceReachable:!0}),l.push({start:S.getStart(n,!1),end:S.getEnd(),id:_}),x.set(S.getStart(n,!1),_)}if(o&&g){let h=T=>{let N=Ke(T);return c.isFunctionExpression(N)||c.isArrowFunction(N)?N:void 0},S=(T,N)=>{let j=T;return s.push({id:j,moduleId:e,kind:c.isArrowFunction(N)?"arrow":"function",declRange:Nn(e,N,n),isExported:!0,publicSurfaceReachable:!0}),l.push({start:N.getStart(n,!1),end:N.getEnd(),id:j}),x.set(N.getStart(n,!1),j),j},_=[],P=[],v=[];for(let T of n.statements)c.isExportAssignment(T)&&!T.isExportEquals?_.push(T):c.isFunctionDeclaration(T)&&c.getModifiers(T)?.some(N=>N.kind===c.SyntaxKind.DefaultKeyword)===!0?P.push(T):c.isExpressionStatement(T)&&c.isBinaryExpression(T.expression)&&T.expression.operatorToken.kind===c.SyntaxKind.EqualsToken&&je(T.expression.left)&&v.push(T.expression);if(_.length+P.length+v.length===1){let T=_[0],N=P[0],j=v[0];if(T!==void 0){let O=h(T.expression);if(O!==void 0){let F=S(`${e}#<default>`,O);I={id:F,esm:!0},A.set(T.getStart(n,!1),F),he(r,"2a-default",null)}}else if(N!==void 0&&N.name===void 0&&N.body!==void 0){let O=S(`${e}#<default>`,N);I={id:O,esm:!0},A.set(N.getStart(n,!1),O),he(r,"2a-default",null)}else if(j!==void 0){let O=h(j.right);if(O!==void 0){let F=S(`${e}#<default>`,O);I={id:F,esm:!1},A.set(j.getStart(n,!1),F),he(r,"2a-default",null)}else if(c.isObjectLiteralExpression(j.right)){let F=j.right,K=[],te=!0;for(let U of F.properties){if(c.isSpreadAssignment(U)){te=!1;break}let X=U.name,D=X===void 0?void 0:Ar(X);if(D===void 0){te=!1;break}K.push(D)}if(te){let U=new Map;for(let X of K)U.set(X,(U.get(X)??0)+1);for(let X of F.properties){if(!c.isPropertyAssignment(X))continue;let D=Ar(X.name),C=h(X.initializer);if(D!==void 0){if(!_f(D)){C!==void 0&&he(r,"2a-member","charset-refused");continue}if((U.get(D)??0)!==1){C!==void 0&&he(r,"2a-member","duplicate-key");continue}if(C!==void 0){let H=S(`${e}#<cjs>.${D}`,C);w.set(D,H),A.set(X.getStart(n,!1),H),he(r,"2a-member",null)}}}}else for(let U of F.properties)c.isPropertyAssignment(U)&&h(U.initializer)!==void 0&&he(r,"2a-member","spread-or-computed-literal")}}}else{for(let T of _)h(T.expression)!==void 0&&he(r,"2a-default","duplicate-default-sources");for(let T of P)T.name===void 0&&he(r,"2a-default","duplicate-default-sources");for(let T of v)if(h(T.right)!==void 0)he(r,"2a-default","duplicate-default-sources");else if(c.isObjectLiteralExpression(T.right))for(let N of T.right.properties)c.isPropertyAssignment(N)&&h(N.initializer)!==void 0&&he(r,"2a-member","duplicate-default-sources")}}for(let h of t)s.push({id:h.id,moduleId:e,name:`handler:${h.memberPath}`,kind:c.isArrowFunction(h.node)?"arrow":"function",declRange:Nn(e,h.node,n),isExported:!1,publicSurfaceReachable:!1}),l.push({start:h.node.getStart(n,!1),end:h.node.getEnd(),id:h.id});l.sort((h,S)=>h.end-h.start-(S.end-S.start));let k=d!==void 0?`${e}#${d}`:void 0;return{rel:e,sf:n,functions:s,bindings:a,exportedFunctionId:k,exportedNames:i,tainted:u,fnRanges:l,toplevelId:p,classes:m,mintedByPos:x,mintedDefault:I,mintedMembers:w,mintSeedAliases:A}}function Qf(e){return c.isIdentifier(e)?"identifier":c.isPropertyAccessExpression(e)?"member":c.isElementAccessExpression(e)?"computed-member":e.kind===c.SyntaxKind.ImportKeyword?"dynamic-import":"unknown"}function ta(e,n){let t=o=>{if(c.isBinaryExpression(o)&&o.operatorToken.kind>=c.SyntaxKind.FirstAssignment&&o.operatorToken.kind<=c.SyntaxKind.LastAssignment){let r=o.left;c.isPropertyAccessExpression(r)&&c.isIdentifier(r.expression)?n(r.expression.text,r.name.text):c.isElementAccessExpression(r)&&c.isIdentifier(r.expression)&&n(r.expression.text,c.isStringLiteralLike(r.argumentExpression)?r.argumentExpression.text:null)}else if(c.isCallExpression(o)&&c.isPropertyAccessExpression(o.expression)){let r=o.expression,s=o.arguments[0];c.isIdentifier(r.expression)&&s!==void 0&&c.isIdentifier(s)&&(r.expression.text==="Object"&&(r.name.text==="assign"||r.name.text==="defineProperty"||r.name.text==="defineProperties")||r.expression.text==="Reflect"&&r.name.text==="defineProperty")&&n(s.text,null)}c.forEachChild(o,t)};t(e)}function ep(e){let n=!1,t=o=>{if(!n){if(c.isVariableDeclaration(o)||c.isParameter(o)){let r=new Set;if(Et(o.name,r),r.has("require")){n=!0;return}}else if((c.isFunctionDeclaration(o)||c.isClassDeclaration(o))&&o.name!==void 0&&o.name.text==="require"){n=!0;return}c.forEachChild(o,t)}};return t(e),n}function np(e,n,t,o=new Map,r={}){let s=r.additiveForms===!0,a=r.namelessExports===!0,l=s||a?{}:void 0,i=new Map,d=new Map;for(let h of n.imports)h.resolvedModuleId!==void 0&&d.set(`${h.moduleId}::${h.specifier}`,h.resolvedModuleId);for(let h of e.sourceFiles){let S=e.toRel(h.fileName);S!==null&&i.set(S,Zf(S,h,o.get(S)??[],a,l))}let u=new Map;if(s)for(let h of i.values()){let S=new Map;for(let[_,P]of h.bindings)if(P.kind==="import"&&P.form==="whole"&&we(P.specifier)!=="package-root"){let v=d.get(`${h.rel}::${P.specifier}`);v!==void 0&&S.set(_,String(v))}S.size!==0&&ta(h.sf,(_,P)=>{let v=S.get(_);if(v===void 0)return;let T=u.get(v);if(T!=="*"){if(P===null){u.set(v,"*");return}T===void 0?u.set(v,new Set([P])):T.add(P)}})}let p=new Map;for(let h of i.values())h.exportedFunctionId!==void 0&&p.set(h.rel,h.exportedFunctionId);let f=new Map;for(let h of i.values()){if(h.rel.split("/").includes("node_modules"))continue;let S=Ef(h.sf);if(S===void 0){a&&h.mintedDefault!==void 0&&f.set(h.rel,h.mintedDefault);continue}let _=h.bindings.get(S.name);_?.kind==="function"&&f.set(h.rel,{id:_.functionId,esm:S.esm})}let m=new Map;for(let h of i.values()){let S;for(let _ of h.exportedNames){let P=h.bindings.get(_);P?.kind==="function"&&(S??=new Map,S.set(_,P.functionId))}S!==void 0&&m.set(h.rel,S)}let g=new Map;for(let h of i.values()){if(h.rel.split("/").includes("node_modules"))continue;let S=Tf(h.sf,h.tainted,_=>{let P=h.bindings.get(_);return P?.kind==="function"?P.functionId:void 0},a?_=>{let P=Ke(_);return c.isFunctionExpression(P)||c.isArrowFunction(P)?h.mintedByPos.get(P.getStart(h.sf,!1)):void 0}:void 0);S.size>0&&g.set(h.rel,S)}let y=[],b=[],x=[],I=[],w=[],A=[];for(let h of i.values()){y.push(...h.functions),A.push(...h.classes);for(let R of h.exportedNames){let M=h.bindings.get(R);if(M?.kind==="function"){let B=`${h.rel}#export:${R}`;I.push({id:B,moduleId:h.rel,exportedName:R,kind:"value"}),w.push({exportId:B,target:{kind:"function",functionId:M.functionId}})}}if(a){if(h.mintedDefault!==void 0){let R=`${h.rel}#export:<default>`;I.push({id:R,moduleId:h.rel,exportedName:"default",kind:"value"}),w.push({exportId:R,target:{kind:"function",functionId:h.mintedDefault.id}})}for(let[R,M]of h.mintedMembers){let B=`${h.rel}#export:<cjs>.${R}`;I.push({id:B,moduleId:h.rel,exportedName:R,kind:"value"}),w.push({exportId:B,target:{kind:"function",functionId:M}})}}let S=new Map;for(let[R,M]of h.bindings){if(M.kind==="function"){S.set(R,M);continue}if(we(M.specifier)==="package-root"){let q=qe(M.specifier);typeof M.form=="object"?S.set(R,{kind:"package-export",packageName:q,exportName:M.form.named}):M.form==="require-default"?S.set(R,{kind:"package-default",packageName:q}):S.set(R,{kind:"package-surface",packageName:q})}else{let q=d.get(`${h.rel}::${M.specifier}`);if(q!==void 0&&typeof M.form=="object"){let le=m.get(String(q))?.get(M.form.named);le!==void 0&&S.set(R,{kind:"app-named-fn",functionId:le})}else if(q!==void 0&&M.form==="require-default"){let le=f.get(String(q));le!==void 0&&le.esm&&S.set(R,{kind:"app-default-fn",functionId:le.id})}else q!==void 0&&typeof M.form!="object"&&M.form!=="require-default"&&S.set(R,{kind:"module",resolvedModuleId:q})}}let _=new Map;for(let R of h.functions){if(R.enclosingClassId===void 0||R.name===void 0)continue;let M=_.get(R.enclosingClassId);M===void 0&&(M=new Map,_.set(R.enclosingClassId,M)),M.set(R.name,R.id)}for(let R of h.classes)R.name===void 0||h.tainted.has(R.name)||S.has(R.name)||S.set(R.name,{kind:"app-class",cls:{classId:R.id,className:R.name,memberIds:_.get(R.id)??new Map}});let P=R=>{if(c.isVariableDeclaration(R)&&c.isIdentifier(R.name)&&R.initializer!==void 0&&c.isNewExpression(R.initializer)&&!h.tainted.has(R.name.text)&&!S.has(R.name.text)){let M=Yi(R.initializer,S,h.tainted);M!==null&&S.set(R.name.text,M)}c.forEachChild(R,P)};P(h.sf);let v=R=>{for(let M of h.fnRanges)if(R>=M.start&&R<M.end)return M.id;return h.toplevelId},T=new Map,N=new Map,j=new Map,O=(R,M,B)=>{if(B===null){R.set(M,"*");return}let q=R.get(M);q!=="*"&&(q===void 0?R.set(M,new Set([B])):q.add(B))},F=(R,M)=>{O(T,R,M);let B=S.get(R);B?.kind==="package-surface"?O(N,B.packageName,M):B?.kind==="module"&&O(j,String(B.resolvedModuleId),M)};ta(h.sf,F);let K=new Map,te=256,U=R=>{let M=K.get(R);return M===void 0&&(M=K.size>=te?new Set([R]):pa(h.sf,new Set([R])),K.set(R,M)),M},X=(R,M)=>R==="*"||R!==void 0&&R.has(M),D=(R,M)=>{let B=S.get(R);if(B?.kind==="package-surface"&&X(N.get(B.packageName),M)||B?.kind==="module"&&X(j.get(String(B.resolvedModuleId)),M))return!0;for(let q of U(R))if(X(T.get(q),M))return!0;return!1},C=R=>{if(c.isIdentifier(R)){let M=h.tainted.has(R.text)?void 0:S.get(R.text);return M?.kind==="function"?M.functionId:M?.kind==="module"?p.get(String(M.resolvedModuleId))??null:M?.kind==="package-export"?t.exportFor(M.packageName,M.exportName):null}if(c.isPropertyAccessExpression(R)&&c.isIdentifier(R.expression)){let M=R.expression.text;if(D(M,R.name.text))return null;let B=h.tainted.has(M)?void 0:S.get(M);return B?.kind==="package-surface"?t.exportFor(B.packageName,R.name.text):B?.kind==="package-export"?t.methodFor(B.packageName,B.exportName,R.name.text,"method"):B?.kind==="package-instance"?t.methodFor(B.packageName,B.className,R.name.text,"method"):null}return null},H=R=>{for(let M=R.parent;M!==void 0;M=M.parent)if(!c.isArrowFunction(M)){if(c.isFunctionExpression(M)||c.isFunctionDeclaration(M))return null;if(c.isMethodDeclaration(M)||c.isConstructorDeclaration(M)||c.isGetAccessorDeclaration(M)||c.isSetAccessorDeclaration(M)){let B=M.parent;if(!c.isClassLike(B)||B.name===void 0)return null;let q=h.tainted.has(B.name.text)?void 0:S.get(B.name.text);return q?.kind==="app-class"?q.cls:null}}return null},J=s&&!h.tainted.has("require")&&!ep(h.sf),G=R=>{if(c.isIdentifier(R)){let q=h.tainted.has(R.text)?void 0:S.get(R.text);return q?.kind==="package-surface"||q?.kind==="package-default"?t.exportFor(q.packageName,"default"):q?.kind==="app-named-fn"||q?.kind==="app-default-fn"?q.functionId:q?.kind==="module"?f.get(String(q.resolvedModuleId))?.id??null:q?.kind==="member-value"?q.functionId:null}if(!c.isPropertyAccessExpression(R))return null;let M=R.expression;if(s&&c.isCallExpression(Ke(M))){let q=un(Ke(M));if(q!==void 0)if(!J)he(l,"2b","require-shadow");else if(we(q)==="package-root")he(l,"2b","package-root");else{let le=d.get(`${h.rel}::${q}`);if(le===void 0)he(l,"2b","unresolved-module");else{let ge=R.name.text,Te=u.get(String(le));if(Te==="*"||Te!==void 0&&Te.has(ge))he(l,"2b","module-mutation-gate");else{let Ze=g.get(String(le))?.get(ge);if(Ze!==void 0)return he(l,"2b",null),Ze;if(ge==="default"){let L=f.get(String(le));if(L!==void 0&&L.esm)return he(l,"2b",null),L.id;he(l,"2b","non-esm-default")}else he(l,"2b","unknown-member")}}}return null}let B;if(c.isIdentifier(M)){let q=h.tainted.has(M.text)?void 0:S.get(M.text);if(q?.kind==="app-class"||q?.kind==="app-instance")B=q.cls.memberIds;else if(q?.kind==="object-literal")B=q.obj.members;else if(q?.kind==="module"){let le=g.get(String(q.resolvedModuleId));le?.has(R.name.text)===!0&&!D(M.text,R.name.text)&&(B=le)}}else if(c.isNewExpression(M)){let q=Yi(M,S,h.tainted);q?.kind==="app-instance"&&(B=q.cls.memberIds)}else M.kind===c.SyntaxKind.ThisKeyword&&(B=H(R)?.memberIds);return B?.get(R.name.text)??null},Y=new Map,re=R=>{if(c.isVariableDeclaration(R)&&c.isIdentifier(R.name)&&R.initializer!==void 0&&c.isObjectLiteralExpression(R.initializer)&&!h.tainted.has(R.name.text)&&!S.has(R.name.text)&&!Y.has(R.name.text)){let M=new Map;for(let B of R.initializer.properties)if(c.isPropertyAssignment(B)&&c.isIdentifier(B.name)){let q=C(B.initializer);q!==null&&M.set(B.name.text,q)}Y.set(R.name.text,M)}c.forEachChild(R,re)};re(h.sf);let ne=R=>{if(c.isBinaryExpression(R)&&R.operatorToken.kind===c.SyntaxKind.EqualsToken&&c.isPropertyAccessExpression(R.left)&&c.isIdentifier(R.left.expression)&&!h.tainted.has(R.left.expression.text)){let M=Y.get(R.left.expression.text);if(M!==void 0){let B=C(R.right);B!==null&&M.set(R.left.name.text,B)}}c.forEachChild(R,ne)};ne(h.sf);for(let[R,M]of Y)S.set(R,{kind:"object-literal",obj:{members:M}});let $=(R,M=0)=>{if(M>Hi)return null;let B=Ke(R);if(c.isCallExpression(B)&&c.isPropertyAccessExpression(B.expression)&&B.expression.name.text==="bind")return $(B.expression.expression,M+1);if(c.isIdentifier(B)){let q=C(B);if(q!==null)return q;let le=h.tainted.has(B.text)?void 0:S.get(B.text);return le?.kind==="member-value"?le.functionId:null}return c.isPropertyAccessExpression(B)?C(B)??G(B):null},Z=(R,M=0)=>{if(M>Hi)return"depth-cap";let B=Ke(R);if(c.isCallExpression(B)&&c.isPropertyAccessExpression(B.expression)&&B.expression.name.text==="bind")return Z(B.expression.expression,M+1);if(c.isIdentifier(B))return h.tainted.has(B.text)?"tainted-receiver":"unresolved-receiver";if(c.isPropertyAccessExpression(B)&&c.isIdentifier(B.expression)){if(h.tainted.has(B.expression.text))return"tainted-receiver";if(D(B.expression.text,B.name.text))return"mutated-member"}return"unresolved-receiver"},Q=R=>{if(c.isVariableDeclaration(R)&&c.isIdentifier(R.name)&&R.initializer!==void 0){let M=Ke(R.initializer),B=c.isPropertyAccessExpression(M),q=c.isCallExpression(M)&&c.isPropertyAccessExpression(M.expression)&&M.expression.name.text==="bind";if(B||q){let le=B?"D1":"A2";if(h.tainted.has(R.name.text))he(l,le,"tainted-alias");else if(S.has(R.name.text))he(l,le,"already-bound");else{let ge=$(M);ge!==null?(S.set(R.name.text,{kind:"member-value",functionId:ge}),he(l,le,null)):he(l,le,Z(M))}}}c.forEachChild(R,Q)};s&&Q(h.sf);let ce=0,Mn=R=>{let M,B;if(c.isCallExpression(R)){let q=R.expression,le=c.isIdentifier(q)&&q.text==="require",ge=q.kind===c.SyntaxKind.ImportKeyword;!le&&!ge&&(M=q,B=R.arguments)}else c.isTaggedTemplateExpression(R)&&(M=R.tag);if(M!==void 0){let q=Qf(M),le=R.getStart(h.sf,!1),ge=`${h.rel}#call${String(ce)}`;ce+=1;let Te="unresolved",Ze=[],L=C(M);L!==null&&(Te="resolved",Ze.push(L)),b.push({id:ge,enclosingFunctionId:v(le),calleeExprShape:q,resolvedTargetIds:Ze,resolution:Te,range:Nn(h.rel,R,h.sf)});for(let oe of Ze)x.push({callSiteId:ge,calleeFunctionId:oe,resolution:Te});if(L===null){let oe=G(M);if(oe!==null)x.push({callSiteId:ge,calleeFunctionId:oe,resolution:"field-based"});else if(s&&c.isPropertyAccessExpression(M)&&(M.name.text==="call"||M.name.text==="apply")){let se=$(M.expression);se!==null?(x.push({callSiteId:ge,calleeFunctionId:se,resolution:"field-based"}),he(l,"A3",null)):he(l,"A3",Z(M.expression))}}for(let oe of B??[]){let se=C(oe);if(se!==null)x.push({callSiteId:ge,calleeFunctionId:se,resolution:"field-based"});else{let Ie=G(oe);if(Ie!==null)x.push({callSiteId:ge,calleeFunctionId:Ie,resolution:"field-based"});else if(s){let Ne=$(oe),pe=Ke(oe),Qe=pe!==oe||c.isCallExpression(pe)&&c.isPropertyAccessExpression(pe.expression)&&pe.expression.name.text==="bind";Ne!==null?(x.push({callSiteId:ge,calleeFunctionId:Ne,resolution:"field-based"}),Qe&&he(l,"A2p",null)):Qe&&he(l,"A2p",Z(oe))}}}}c.forEachChild(R,Mn)};Mn(h.sf);for(let R of n.computedLoads.get(h.rel)??[]){let M=R.candidateRels.filter(q=>i.has(q)).map(q=>`${q}#<toplevel>`);if(M.length===0)continue;let B=`${h.rel}#dirload${String(ce)}`;ce+=1,b.push({id:B,enclosingFunctionId:v(R.pos),calleeExprShape:"require",resolvedTargetIds:M,resolution:"field-based",range:{path:h.rel,start:R.pos,end:R.pos}});for(let q of M)x.push({callSiteId:B,calleeFunctionId:q,resolution:"field-based"})}let Yn=0;for(let R of o.get(h.rel)??[]){let M=`${h.rel}#handlerseed${String(Yn)}`;Yn+=1;let B=R.node.getStart(h.sf,!1);b.push({id:M,enclosingFunctionId:h.toplevelId,calleeExprShape:"member",resolvedTargetIds:[R.id],resolution:"field-based",range:{path:h.rel,start:B,end:B}}),x.push({callSiteId:M,calleeFunctionId:R.id,resolution:"field-based"})}}let k=new Map;if(a)for(let h of i.values())for(let[S,_]of h.mintSeedAliases)k.set(`${h.rel}::${String(S)}`,_);return{functions:y,callSites:b,callEdges:x,exports:I,exportBindings:w,classes:A,mintSeedAliases:k,bindingApplicability:l}}function tp(e,n,t){let o=i=>i.length===0||Ue.isAbsolute(i)||i.includes("\\")||/^[a-zA-Z]:/u.test(i)||i.split("/").some(d=>d===".."||d==="");if(o(n)||o(t))return null;let r=e.endsWith(Ue.sep)?e:e+Ue.sep,s;try{s=Gi(Ue.resolve(e,n))}catch{return null}if(!s.startsWith(r))return null;let a=s.endsWith(Ue.sep)?s:s+Ue.sep,l;try{l=Gi(Ue.resolve(s,t))}catch{return null}return l.startsWith(a)?l:null}function ya(e,n,t){let o=`${e}#class:${t}`,r=[],s=[],a=[],l=new Set;return{pushMember(i,d,u,p){if(i==="__proto__"||l.has(i))return;l.add(i);let f=`${e}#${t}.${i}`;r.push({id:f,moduleId:e,name:i,kind:u,enclosingClassId:o,declRange:Nn(e,d,n),isExported:!1,publicSurfaceReachable:!1}),a.push(f),s.push({name:i,id:f,kind:u,body:p})},finish(){return s.length===0?null:{functions:r,classNode:{id:o,moduleId:e,name:t,implementsRefs:[],members:a},members:s}}}}function op(e,n,t,o){if(ga(o)||o.members.length>_r)return null;let r=ya(e,n,t);for(let s of o.members){let a,l,i;if(c.isConstructorDeclaration(s))a="constructor",l="ctor",i=void 0;else if(c.isMethodDeclaration(s))a=So(s.name),l="method",i=a!==void 0&&!rt.has(a)?s.body??void 0:void 0;else continue;a!==void 0&&r.pushMember(a,s,l,i)}return r.finish()}function rp(e,n,t){let o;for(let a of n.statements)if(c.isFunctionDeclaration(a)&&a.name?.text===t){o=a;break}if(o===void 0)return null;let r=[];for(let a of n.statements){if(!c.isExpressionStatement(a))continue;let l=a.expression;if(!c.isBinaryExpression(l)||l.operatorToken.kind!==c.SyntaxKind.EqualsToken)continue;let i=l.left;if(c.isPropertyAccessExpression(i)&&c.isPropertyAccessExpression(i.expression)&&c.isIdentifier(i.expression.expression)&&i.expression.expression.text===t&&i.expression.name.text==="prototype"){let d=i.name.text;c.isFunctionExpression(l.right)?r.push({name:d,fn:l.right,walk:!0}):c.isArrowFunction(l.right)&&r.push({name:d,fn:l.right,walk:!1})}}if(r.length===0||r.length+1>_r)return null;let s=ya(e,n,t);s.pushMember("constructor",o,"ctor",void 0);for(let a of r){let l=a.walk&&!rt.has(a.name)&&c.isFunctionExpression(a.fn)?a.fn.body:void 0;s.pushMember(a.name,a.fn,"method",l)}return s.finish()}function sp(e,n,t){for(let o of n.statements)if(c.isClassDeclaration(o)&&o.name?.text===t)return op(e,n,t,o);return rp(e,n,t)}function ip(e,n,t,o,r){let s={modules:[],functions:[],classes:[],callSites:[],callEdges:[],imports:[],importEdges:[],diagnostics:[]};if(n.length===0)return s;let a=new Set(t.map(p=>p.packageName)),l=new Set(t.map(p=>p.path)),i=new Set,d=new Set,u=0;for(let p of n){if(!a.has(p.packageName))continue;let f=tp(e.appRoot,p.packageRootRel,p.sourcePath);if(f===null)continue;let m=e.toRel(f);if(m===null)continue;let g=`${m}#${p.container}`;if(d.has(g)||!i.has(m)&&i.size>=yo)continue;let y=Oe(f);if(y===null)continue;let b;try{b=c.createSourceFile(m,y,c.ScriptTarget.Latest,!0,c.ScriptKind.JS)}catch{continue}let x=sp(m,b,p.container);if(x===null)continue;i.add(m),d.add(g);let I=new Map,w=new Map;for(let k of x.members){let h=r.methodFor(p.packageName,p.container,k.name,k.kind);I.set(k.name,h),w.set(h,k.id)}let A=0;for(let k of x.members){if(k.body===void 0)continue;let h=(S,_)=>{if(_&&c.isCallExpression(S)&&c.isPropertyAccessExpression(S.expression)&&S.expression.expression.kind===c.SyntaxKind.ThisKeyword){let T=I.get(S.expression.name.text);if(T!==void 0){let N=`${m}#depclass:${p.container}.${k.name}#c${String(A)}`;A+=1,s.callSites.push({id:N,enclosingFunctionId:k.id,calleeExprShape:"member",resolvedTargetIds:[],resolution:"unresolved",range:Nn(m,S,b)}),s.callEdges.push({callSiteId:N,calleeFunctionId:T,resolution:"field-based"})}}let P=c.isFunctionExpression(S)||c.isFunctionDeclaration(S)||c.isMethodDeclaration(S)||c.isConstructorDeclaration(S)||c.isGetAccessorDeclaration(S)||c.isSetAccessorDeclaration(S)||c.isClassLike(S),v=c.isArrowFunction(S)?_:P?!1:_;c.forEachChild(S,T=>{h(T,v)})};h(k.body,!0)}for(let k of o){let h=w.get(k.calleeFunctionId);h!==void 0&&s.callEdges.push({callSiteId:k.callSiteId,calleeFunctionId:h,resolution:"field-based"})}if(s.functions.push(...x.functions),s.classes.push(x.classNode),!l.has(m)){l.add(m),s.modules.push({id:m,packageName:p.packageName,versionRange:"",path:m,moduleSystem:"cjs",isEntrypoint:!1});let k=r.moduleFor(p.packageName),h=`${String(k)}#depclass${String(u)}`;u+=1,s.imports.push({id:h,moduleId:k,specifier:"<dep-class-corridor>",isNamespace:!1,isDefault:!1,dynamic:!1,specifierIsLiteral:!0,resolvedModuleId:m}),s.importEdges.push({importId:h,resolvedModuleId:m})}s.diagnostics.push({code:"dep-class-corridor",path:m,detail:`lowered dependency class ${p.container} (${p.packageName}) \u2014 ${String(x.members.length)} members; the un-analyzed remainder caps this class's method sinks at unknown`,classScope:{packageName:p.packageName,container:p.container}})}return s}function ap(e,n,t,o){let r=new Set(e.modules.filter(i=>i.isEntrypoint).map(i=>i.packageName)),s=new Map(e.functions.map(i=>[i.id,i.moduleId])),a=new Map;for(let i of e.callSites){if(i.resolution!=="unresolved")continue;let d=s.get(i.enclosingFunctionId);d!==void 0&&a.set(d,(a.get(d)??0)+1)}let l=[];for(let i of e.modules){if(i.externalSurface===!0)continue;let d=n.get(i.path);if(d===void 0||t.has(i.path)||r.has(i.packageName)&&o.has(i.path)&&!i.path.split("/").includes("node_modules"))continue;let u=a.get(i.id)??0;if(u===0&&Uf(d))continue;let p=u>0?`${String(u)} of its call sites are unresolved`:"it invokes (or exposes) a function body through a form that emits no call site \u2014 `new`, an accessor, the iterator protocol, spread, or a coercion member";l.push({code:"dependency-body",path:i.path,detail:`dependency module analyzed with full bodies (package-subpath/relative/computed entry) but ${p}; its hidden call edges are bounded by its own forward module reach (ADR-069 Finding A)`,anchor:i.id})}return l}function xa(e,n,t=[],o={},r=!1){let s=new vr,a=yf(e,n,s),l=new Set;for(let A of a.computedLoads.values())for(let k of A)if(k.seedable)for(let h of k.candidateRels)l.add(h);let i=new Map;for(let A of e.sourceFiles){let k=e.toRel(A.fileName);if(k===null||!l.has(k)||k.split("/").includes("node_modules"))continue;let h=Yf(k,A);h.length>0&&i.set(k,h)}let d=i.size===0?a.modules:a.modules.map(A=>i.has(A.path)&&!A.isEntrypoint?{...A,isEntrypoint:!0}:A),u={...a,modules:d},p=np(e,u,s,i,o),f=Bf(e,a,p.functions,p.mintSeedAliases),m=new Set(a.modules.map(A=>A.path)),g=bf(e.depReach,s,m),y=[...u.modules,...g.modules,...s.modules()],b=ip(e,t,y,p.callEdges,s),x=[];if(r){let A="#default",k=new Set;for(let S of p.callEdges){let _=String(S.calleeFunctionId);!_.startsWith("pkg:")||!_.endsWith(A)||k.add(_.slice(4,_.length-A.length))}let h=new Map;for(let S of e.depReach.edges){if(!("surface"in S.from)||"surface"in S.to)continue;let _=S.from.surface;h.set(_,h.has(_)?null:S.to.module)}for(let S of k){let _=h.get(S);if(_==null)continue;let P=xf(Ue.join(e.appRoot,_));if(P===null||P==="default")continue;let v=s.exportFor(S,P),T=`pkg:${S}${A}`;for(let N of p.callEdges)String(N.calleeFunctionId)===T&&x.push({callSiteId:N.callSiteId,calleeFunctionId:v,resolution:"field-based"})}}let I={modules:[...u.modules,...g.modules,...b.modules,...s.modules()],exports:[...p.exports,...f.exports],imports:[...a.imports,...g.imports,...b.imports],functions:[...p.functions,...s.functions(),...b.functions],callSites:[...p.callSites,...b.callSites],classes:[...p.classes,...s.classes(),...b.classes],callEdges:[...p.callEdges,...b.callEdges,...x],importEdges:[...a.importEdges,...g.importEdges,...b.importEdges],exportBindings:[...p.exportBindings,...f.exportBindings],inheritEdges:[]},w=new Map;for(let A of e.sourceFiles){let k=e.toRel(A.fileName);k!==null&&w.set(k,A)}return{graph:I,diagnostics:[...f.diagnostics,...b.diagnostics,...ap(I,w,new Set(e.diagnostics.filter(A=>A.code==="dependency-body").map(A=>A.path)),a.appOwnedPaths)],loadSites:a.loadSites,...p.bindingApplicability!==void 0?{bindingApplicability:p.bindingApplicability}:{}}}var lp=/^(@[A-Za-z0-9_.-]{1,100}\/)?[A-Za-z0-9_.-]{1,100}$/u,bo=/^[A-Za-z0-9_$.-]{1,128}$/u;function dp(e){return lp.test(e.calleePackage)?bo.test(e.anchorExport)?bo.test(e.calleeExport)?e.anchorContainer!==null&&!bo.test(e.anchorContainer)?`anchorContainer ${JSON.stringify(e.anchorContainer)}`:e.calleeContainer!==null&&!bo.test(e.calleeContainer)?`calleeContainer ${JSON.stringify(e.calleeContainer)}`:null:`calleeExport ${JSON.stringify(e.calleeExport)}`:`anchorExport ${JSON.stringify(e.anchorExport)}`:`calleePackage ${JSON.stringify(e.calleePackage)}`}function _t(e,n){let t=[],o=[],r=new Map(e.modules.map(d=>[d.id,d])),s=new Map(e.classes.map(d=>[d.id,d.name])),a=(d,u,p)=>e.functions.some(f=>{if(f.name!==u)return!1;let m=r.get(f.moduleId);return m===void 0||m.packageName!==d?!1:(f.enclosingClassId!==void 0?s.get(f.enclosingClassId)??null:null)===p}),l=(d,u,p)=>{for(let f of e.functions){if(f.name!==u)continue;let m=r.get(f.moduleId);if(!(m===void 0||m.packageName!==d||(f.enclosingClassId!==void 0?s.get(f.enclosingClassId)??null:null)!==p))return f.id}return null},i=[...n].sort((d,u)=>d.modelId<u.modelId?-1:d.modelId>u.modelId?1:0);for(let d of i){if(d.edges.length>64){t.push(`model ${d.modelId}: ${String(d.edges.length)} edges over cap ${String(64)} \u2014 dropped WHOLE (all-or-nothing)`);continue}let u=d.edges.map(dp).find(m=>m!==null);if(u!==void 0){t.push(`model ${d.modelId}: hostile/invalid edge field ${u} \u2014 model refused WHOLE`);continue}let p=0,f=0;for(let m of d.edges){if(!a(d.packageName,m.anchorExport,m.anchorContainer)){f+=1;continue}o.push({modelId:d.modelId,kind:m.kind,anchor:{packageName:d.packageName,exportName:m.anchorExport,container:m.anchorContainer},callee:{packageName:m.calleePackage,exportName:m.calleeExport,container:m.calleeContainer,realFunctionId:l(m.calleePackage,m.calleeExport,m.calleeContainer)},resolution:"modeled"}),p+=1}p>0?t.push(`model-edge ${d.modelId}: ${String(p)} edge(s) lowered, ${String(f)} reference-gated`):t.push(`model ${d.modelId}: refused \u2014 no anchor surface in the graph (${String(f)} edge(s) reference-gated); models never mint loadedness`)}return{delta:{records:o,notes:t}}}var cp={modules:[],exports:[],imports:[],functions:[],callSites:[],classes:[],callEdges:[],importEdges:[],exportBindings:[],inheritEdges:[]};function Tr(e){try{let n=Ui(e.appRoot,e.entrypoints,e.tsconfigPaths===!0),t=new Set(e.entrypoints.map(l=>l.split(Xe.sep).join("/"))),{graph:o,diagnostics:r,loadSites:s,bindingApplicability:a}=xa(n,t,e.depClassAnchors??[],e.bindingForms??{},e.callablePackageResolver===!0);return{graph:o,diagnostics:[...n.diagnostics,...r],loadSites:s,conditionUnions:n.conditionUnions,provenAbsent:n.provenAbsent,...a!==void 0?{bindingApplicability:a}:{}}}catch(n){return{graph:cp,loadSites:[],conditionUnions:[],provenAbsent:[],diagnostics:[{code:"unsupported-syntax",path:e.appRoot,detail:`analysis aborted: ${n instanceof Error?n.message:String(n)}`}]}}}function Sa(e,n){let t=512,o=(r,s,a)=>{if(!(t<=0||s>12)){if(t-=1,typeof r=="string"){n(r,a);return}if(Array.isArray(r)){for(let l of r)o(l,s+1,a);return}if(r!==null&&typeof r=="object")for(let[l,i]of Object.entries(r))l==="types"||l==="typings"||o(i,s+1,a||l.includes("*"))}};o(e,0,!1)}function wa(e,n,t,o=!1){if(typeof t!="string"||t.length===0||t.endsWith(".d.ts")||t.endsWith(".d.mts")||t.endsWith(".d.cts"))return null;let r;try{r=kn(Xe.resolve(e,t))}catch{return null}return r!==e&&!r.startsWith(n)||o&&!cn(r)?null:r===e?"":r.slice(n.length).split(Xe.sep).join("/")}var up=1024*1024,fp=4096;function ba(e,n){let t=e.toLowerCase(),o=0;for(;;){let r=t.indexOf(n,o);if(r===-1)return null;let s=r===0?" ":t[r-1],a=r+n.length;for(;a<e.length&&(e[a]===" "||e[a]===" "||e[a]===`
|
|
16
|
+
`||e[a]==="\r");)a+=1;if(/[a-z0-9_:-]/i.test(s??" ")||e[a]!=="="){o=r+n.length;continue}for(a+=1;a<e.length&&(e[a]===" "||e[a]===" "||e[a]===`
|
|
17
|
+
`||e[a]==="\r");)a+=1;let l=e[a];if(l==='"'||l==="'"){let d=e.indexOf(l,a+1);return d===-1?null:e.slice(a+1,d)}let i=a;for(;i<e.length&&!/[\s>]/.test(e[i]??"");)i+=1;return e.slice(a,i)}}function pp(e){let n=[],t=e.toLowerCase(),o=0;for(;;){let r=t.indexOf("<script",o);if(r===-1)break;let s=t[r+7];if(s!==void 0&&/[a-z0-9-]/.test(s)){o=r+7;continue}let a=e.indexOf(">",r);if(a===-1)break;o=a+1;let l=e.slice(r+7,a);if(l.length>fp)continue;let i=ba(l,"type");n.push({module:(i??"").trim().toLowerCase()==="module",src:ba(l,"src")})}return n}function mp(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function hp(e){let n=e.search(/[?#]/);return(n===-1?e:e.slice(0,n)).replace(/^\/+/,"")}function gp(e){let n=kn(e),t=n.endsWith(Xe.sep)?n:n+Xe.sep,o=new Set,r=[],s=[],a=[],l=[],i=[],d=!1,u=(O,F,K=!1,te)=>{let U=wa(n,t,O);return U===null||U.length===0?"unresolved":o.has(U)?"duplicate":(o.add(U),r.push(U),s.push({source:F,specifier:He(te??(typeof O=="string"?O:"")),entrypoint:U,launch:K}),"added")},p=new Set,f=(O,F,K=!1)=>{let te=u(O,F),U=typeof O=="string"&&O.includes("\\")?u(O.split("\\").join("/"),F,!1,O):"unresolved";if(te!=="unresolved"||U!=="unresolved"||typeof O!="string"||O.trim().length===0||O.endsWith(".d.ts")||O.endsWith(".d.mts")||O.endsWith(".d.cts"))return;if(K&&O.includes("*")){let D=Wi(n,O),C=!1;if(D!==null){for(let H of D.matches)u(H,F,!1,O)!=="unresolved"&&(C=!0);if(!D.truncated&&C)return}l.push({source:F,file:"package.json",detail:`\`${He(O)}\` is a subpath pattern cupel could not expand completely; the files it names beyond those seeded were NOT analyzed`});return}let X=`${F}\0${O}`;p.has(X)||(p.add(X),l.push({source:F,file:"package.json",detail:`\`${He(O)}\` did not resolve to a file inside the scan root; the code it names was NOT analyzed`}))},m=[],g=(O,F)=>{a.push({source:O,file:O,detail:F.detail}),m.push({code:F.code,path:O,detail:`${O} ${F.detail}`})},y,b,x,I=null,w=Cr(n,t,"package.json",In);w.kind==="refused"&&g("package.json",w);try{let O=w.kind==="ok"?JSON.parse(w.text):{};if(I=w.kind==="ok"?O:null,f(O.main,"main"),typeof O.bin=="string")f(O.bin,"bin");else if(O.bin!==null&&typeof O.bin=="object")for(let K of Object.values(O.bin))f(K,"bin");Sa(O.exports,(K,te)=>{f(K,"exports",te)}),typeof O.browser=="string"?f(O.browser,"browser"):Sa(O.browser,K=>{u(K,"browser")});let F=O.scripts;if(F!==null&&typeof F=="object"){let K=F;y=K.start,b=K.prestart,x=K.poststart}}catch{}if(r.length===0)try{kn(Xe.join(n,"index.js")),u("index.js","index.js fallback")}catch{}let A=(O,F)=>{if(typeof O=="string"&&O.trim().length>0){let K=ka(O,F,"package.json",u,a,!1)==="used";return K&&(d=!0),K?"resolved":"gapped"}return O===void 0||typeof O=="string"?"absent":(a.push({source:F,file:"package.json",detail:`${F} is not a string; no entry file could be read from it`}),"gapped")},k=A(y,"scripts.start"),h=A(b,"scripts.prestart"),S=A(x,"scripts.poststart"),_=k==="resolved"&&h!=="gapped"&&S!=="gapped",P=Cr(n,t,"Procfile",65536);if(P.kind==="refused")g("Procfile",P);else if(P.kind==="ok"){let{entries:O,truncated:F,unnamedLines:K}=wr(P.text);F&&a.push({source:"Procfile",file:"Procfile",detail:"Procfile has more process types than cupel parses; the remainder was not read"}),K>0&&a.push({source:"Procfile",file:"Procfile",detail:`${String(K)} Procfile line(s) declare a process whose name cupel does not accept; their commands were NOT read`});for(let te of O)ka(te.command,`Procfile:${te.name}`,"Procfile",u,a,_)==="used"&&(d=!0)}let v=r.length===0,T=Cr(n,t,"index.html",up);if(T.kind==="ok")for(let O of pp(T.text)){if(O.src===null)continue;let F=He(O.src);if(!O.module){i.push({kind:"classic-script",file:"index.html",detail:`index.html loads "${F}" as a classic (non-module) script; not seeded (ADR-071 Step 5, decision 2)`,root:""});continue}if(mp(O.src)){i.push({kind:"external-script",file:"index.html",detail:`index.html loads the module script "${F}" from another origin \u2014 not this repository's code; not seeded`,root:""});continue}u(hp(O.src),"index.html",!1,O.src)==="unresolved"&&a.push({source:"index.html",file:"index.html",detail:`index.html names the module script "${F}", which did not resolve to a file inside the root; the browser would load it and cupel did not analyze it`})}else T.kind==="refused"&&i.push({kind:T.code==="limit-exceeded"?"index-html-oversize":"index-html-refused",file:"index.html",detail:`index.html ${T.detail}`,root:""});let N=v?xr(n,I):null;if(N!==null){let O=0;for(let F of br(n,N).roots)u(F,`framework:${N.name}`)==="added"&&(O+=1);O>0&&m.push({code:"framework-derived-entry",path:"package.json",detail:`entrypoints were derived from ${N.name}'s directory conventions (recognised via ${N.configFile}), not declared by this project. That set cannot be proven complete, so findings that would read \`not-reachable\` are capped at \`unknown\`; pass \`--entry\` for the files your build actually starts to lift it`})}let j=O=>O.map(F=>({...F,root:""}));return{entrypoints:r,sources:j(s),gaps:j(a),surfaceGaps:j(l),launchResolved:d,diagnostics:m,framework:N,observations:i}}function Cr(e,n,t,o){let r;try{r=kn(Xe.join(e,t))}catch{return{kind:"absent"}}if(!r.startsWith(n))return{kind:"refused",code:"out-of-root",detail:"exists but resolves OUTSIDE the scan root (symlink); it was NOT read, so the declarations it carries were not analyzed"};let s=nt(r,o);return s.kind==="ok"?s:s.kind==="too-large"?{kind:"refused",code:"limit-exceeded",detail:`is ${String(s.bytes)} bytes, over the ${String(o)}-byte cap; it was NOT read`}:{kind:"refused",code:"parse-error",detail:"exists but is not a readable regular file (FIFO/device/directory); it was NOT read"}}function ka(e,n,t,o,r,s){let a=Er(e);if(a.kind==="delegates")return s?"used":(r.push({source:n,file:t,detail:`\`${He(e)}\`: runs the package \`start\` lifecycle (prestart/start/poststart), which is absent or not fully readable`}),"gapped");if(a.kind==="unparsed")return r.push({source:n,file:t,detail:`\`${He(e)}\`: ${a.reason}`}),"gapped";let l=o(a.specifier,n,!0),i=a.alt===void 0?"unresolved":o(a.alt,n,!0);return l==="unresolved"&&i==="unresolved"?(r.push({source:n,file:t,detail:`\`${He(a.specifier)}\` did not resolve to a file inside the app root`}),"gapped"):"used"}function it(e,n){return e===""?n:`${e}/${n}`}function va(e,n){let t=kn(e),o=t.endsWith(Xe.sep)?t:t+Xe.sep,r=new Set,s=[],a=[],l=[],i=[],d=[],u=[],p=!1,f=null,m=[...n].sort((g,y)=>g.rel===""?-1:y.rel===""?1:g.rel<y.rel?-1:g.rel>y.rel?1:0);for(let g of m){let y=it(g.rel,"package.json"),b=g.rel===""?".":g.rel,x;try{x=kn(g.abs)}catch{l.push({source:"root",file:y,detail:`root \`${b}\` could not be resolved; not seeded`,root:g.rel});continue}if(x!==t&&!x.startsWith(o)){l.push({source:"root",file:y,detail:`root \`${b}\` resolves outside the scan root; refused, not seeded`,root:g.rel});continue}let I;try{I=gp(x)}catch{l.push({source:"root",file:y,detail:`root \`${b}\` could not be read; not seeded`,root:g.rel});continue}for(let w of I.sources){let A=it(g.rel,w.entrypoint),k,h;try{k=kn(Xe.resolve(t,A)),h=kn(Xe.resolve(x,w.entrypoint))}catch{l.push({source:w.source,file:y,detail:`\`${w.specifier}\` re-based to \`${A}\` did not resolve; not seeded`,root:g.rel});continue}if(!k.startsWith(o)||k!==h){l.push({source:w.source,file:y,detail:`\`${w.specifier}\` re-based to \`${A}\` escapes the scan root or names another file; refused, not seeded`,root:g.rel});continue}r.has(A)||(r.add(A),s.push(A),a.push({...w,entrypoint:A,root:g.rel}))}I.launchResolved&&(p=!0);for(let w of I.gaps)l.push({...w,file:it(g.rel,w.file),root:g.rel});for(let w of I.surfaceGaps)i.push({...w,file:it(g.rel,w.file),root:g.rel});for(let w of I.diagnostics)d.push({...w,path:it(g.rel,w.path)});for(let w of I.observations)u.push({...w,file:it(g.rel,w.file),root:g.rel});g.rel===""&&(f=I.framework)}return{entrypoints:s,sources:a,gaps:l,surfaceGaps:i,launchResolved:p,diagnostics:d,framework:f,observations:u}}function Dr(e){let{gaps:n,launchResolved:t}=e;if(n.length===0||!t)return[];let o=n.slice(0,3).map(r=>r.source).join(", ");return[{code:"unresolved-launch-entry",path:n[0]?.file??"package.json",detail:`${String(n.length)} launch declaration(s) (${o}) name code this project starts but cupel could not resolve to an entry file, while other launch declarations DID seed the analysis; verdicts that would be \`not-reachable\` are capped at \`unknown\`. To clear it, make those commands a direct \`node <file.js>\` invocation cupel can read. \`--entry <file>\` analyzes that code too (so a sink there is still reported), but the cap remains while the command itself is unreadable`}]}function Lr(e,n){let{surfaceGaps:t}=e;if(t.length===0||n===0)return[];let o=[...new Set(t.slice(0,3).map(r=>r.source))].join(", ");return[{code:"unresolved-entry-declaration",path:t[0]?.file??"package.json",detail:`${String(t.length)} package.json entry declaration(s) (${o}) name a file this package owns that cupel could not resolve inside the scan root, while the analysis was seeded from elsewhere; the code they name was NOT analyzed, so verdicts that would be \`not-reachable\` are capped at \`unknown\`. To clear it, point those fields at a file that exists (a Windows-style \`lib\\index.js\` does not resolve on a posix host). \`--entry <file>\` analyzes that code too, but the cap remains while the declaration is unresolvable`}]}function Ia(e,n){let t=kn(e),o=t.endsWith(Xe.sep)?t:t+Xe.sep,r=new Set,s=[],a=[];for(let l of n){let i=wa(t,o,l,!0);if(i===null||i.length===0){a.push(l);continue}r.has(i)||(r.add(i),s.push(i))}return{entrypoints:s,rejected:a}}import{readdirSync as il,readFileSync as qr,realpathSync as Gr,statSync as Dt}from"node:fs";import sn from"node:path";function yp(e){if(e.startsWith("<<:")||e.startsWith("- &")||e.startsWith("- *"))return!0;let n=e.charCodeAt(0);if(n===38||n===42)return!0;let t=e.indexOf(": ");if(t===-1)return!1;let o=t+2;for(;o<e.length&&e.charCodeAt(o)===32;)o+=1;let r=e.charCodeAt(o);return r===38||r===42}function Nt(e,n,t){let o=n.maxLines??2e6,r=n.maxLineBytes??16384,s=!1,a=!1,l=0,i=0,d=e.charCodeAt(0)===65279?1:0;for(;d<=e.length;){let u=e.indexOf(`
|
|
18
|
+
`,d),p=u===-1;p&&(u=e.length);let f=u>d&&e.charCodeAt(u-1)===13?u-1:u;if(i+=1,i>o){s=!0;break}if(f-d>r)l+=1;else{let m=d;for(;m<f&&e.charCodeAt(m)===32;)m+=1;let g=m-d,y=f;for(;y>m&&(e.charCodeAt(y-1)===32||e.charCodeAt(y-1)===9);)y-=1;if(m<y&&e.charCodeAt(m)!==35){let b=e.slice(m,y);if(yp(b)){a=!0;break}t(g,b)}}if(p)break;d=u+1}return{truncated:s||l>0,refusedAnchors:a,oversizeLines:l}}function ko(e){let n=e.charCodeAt(0);if(n===34||n===39){let o=e.indexOf(String.fromCharCode(n),1);if(o===-1)return null;let r=o+1;for(;r<e.length&&e.charCodeAt(r)===32;)r+=1;return e.charCodeAt(r)===58?e.slice(0,o+1):null}let t=e.indexOf(":");return t>0?e.slice(0,t):null}function at(e){return e.endsWith(":")}function on(e){if(e.length>=2){let n=e.charCodeAt(0);if((n===34||n===39)&&e.charCodeAt(e.length-1)===n)return e.slice(1,-1)}return e}function Eo(e){if(e.length===0||e.length>214)return!1;let n=e.charCodeAt(0)===64,t=n?e.slice(1):e,o=t.indexOf("/");if(n){if(o<=0||t.indexOf("/",o+1)!==-1)return!1}else if(o!==-1)return!1;let r=n?[t.slice(0,o),t.slice(o+1)]:[t];for(let s of r){if(s.length===0||s.charCodeAt(0)===46||s.charCodeAt(0)===95)return!1;for(let a=0;a<s.length;a+=1){let l=s.charCodeAt(a);if(!(l>=97&&l<=122||l>=65&&l<=90||l>=48&&l<=57||l===45||l===46||l===95||l===126))return!1}}return!0}function Rt(e){return Eo(e)?`node_modules/${e}`:""}function Pt(e,n){let t=`${e}@${n}`;return t.length<=96?t:`${t.slice(0,96)}\u2026`}var wo=2e5,Aa=64,vo=1024,xp=5,Sp=[1,2,3];function bp(e){let n="node_modules/",t=e.lastIndexOf(n);if(t===-1)return null;let o=e.slice(t+n.length);if(o==="")return null;let r=o.split("/");return r[0]?.startsWith("@")?r.length>=2?`${r[0]}/${r[1]}`:null:r[0]??null}function _a(e,n){if(!n.startsWith("npm:"))return[{name:e,version:n}];let t=n.slice(4);if(t.length===0)return[{name:e,version:n}];let o=t.indexOf("@",1);if(o>0){let r=t.slice(0,o),s=t.slice(o+1);if(r.length>0&&s.length>0)return[{name:r,version:s}]}return t===e?[{name:e,version:n}]:[{name:e,version:n},{name:t,version:n}]}function lt(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function Na(e){return{deps:[],seen:new Set,maxEntries:e,unread:0,visited:0,capped:!1}}function Ra(e){return e.capped?!1:(e.visited+=1,e.visited>e.maxEntries?(e.capped=!0,!1):!0)}function Pa(e,n,t,o,r=!1){let s=JSON.stringify([n,t,o]);if(!e.seen.has(s)){if(e.deps.length>=e.maxEntries){e.capped=!0;return}e.seen.add(s),e.deps.push({name:n,version:t,lockKey:o,dev:r})}}function kp(e,n){for(let[t,o]of Object.entries(e)){if(t==="")continue;if(!Ra(n))return;let r=t.startsWith("node_modules/")||t.includes("/node_modules/"),s=lt(o);if(s===null){n.unread+=1;continue}if(s.link===!0)continue;let a=s.name,l=typeof a=="string"&&a!==""?a:bp(t),i=s.version;if(l===null||typeof i!="string"){r&&(n.unread+=1);continue}let d=s.dev===!0||s.devOptional===!0;for(let u of _a(l,i))Pa(n,u.name,u.version,t,d)}}function $a(e,n,t){let o=[{deps:e,prefix:"",depth:0,pathSafe:!0,dev:!1}],r=!1;for(let s=0;s<o.length;s+=1){let a=o[s];if(a===void 0)break;for(let[l,i]of Object.entries(a.deps)){if(!Ra(n))return{depthCapped:r};if(l===""){n.unread+=1;continue}let d=lt(i);if(d===null){n.unread+=1;continue}let u=a.pathSafe&&Eo(l),p=u?`${a.prefix}node_modules/${l}`:"",f=u&&p.length<=vo,m=f?p:"",g=d.version,y=d.dev===!0||a.dev;if(d.link!==!0&&typeof g=="string"&&g!=="")for(let x of _a(l,g))Pa(n,x.name,x.version,m,y);else n.unread+=1;let b=lt(d.dependencies);if(b!==null){if(a.depth+1>t){r=!0;continue}o.push({deps:b,prefix:f?`${m}/`:a.prefix,depth:a.depth+1,pathSafe:f,dev:y})}}}return{depthCapped:r}}function Ep(e,n,t){let o=Na(n.maxEntries),{depthCapped:r}=$a(e,o,t),s=[],a=new Set(n.deps.map(d=>JSON.stringify([d.name,d.version]))),l=new Set,i=[];for(let d of o.deps){if(d.version.includes(":"))continue;let u=JSON.stringify([d.name,d.version]);a.has(u)||l.has(u)||(l.add(u),i.length<xp&&i.push(Pt(d.name,d.version)))}if(l.size>0){let d=l.size-i.length;s.push(`package-lock.json carries BOTH a v2/v3 \`packages\` map and a legacy v1 \`dependencies\` tree, and they DISAGREE: ${String(l.size)} install(s) the tree describes are absent from the map (${i.join(", ")}${d>0?`, and ${String(d)} more`:""}). npm 6 installs from the tree and npm 7+ from the map, so what is on disk depends on which npm ran; cupel enumerated the map`)}return(o.capped||r)&&s.push("package-lock.json's legacy `dependencies` tree hit a cap before it could be cross-checked against the `packages` map; a disagreement between the two would not have been seen"),s}function Io(e,n={}){let t=[],o;try{o=JSON.parse(e)}catch{return{deps:[],diagnostics:["package-lock.json is not valid JSON"],truncated:!1}}let r=lt(o);if(r===null)return{deps:[],diagnostics:["package-lock.json is not an object"],truncated:!1};let s=r.lockfileVersion,a=typeof s=="number"&&Number.isInteger(s)?s:null,l=typeof s=="number"?String(s):"?",i=lt(r.packages),d=lt(r.dependencies);if(i===null&&d===null)return{deps:[],diagnostics:[`package-lock.json (lockfileVersion ${l}) has neither a v2/v3 \`packages\` map nor a v1 \`dependencies\` tree; NO dependency was enumerated`],truncated:!1};(a===null||!Sp.includes(a))&&t.push(`package-lock.json declares unsupported lockfileVersion ${l} (cupel knows v1, v2 and v3); its shape may differ, so what was read may be incomplete`);let u=n.maxDepth??Aa,p=Na(n.maxEntries??wo),f=!1;return i!==null?(kp(i,p),d!==null&&t.push(...Ep(d,p,u))):d!==null&&(f=$a(d,p,u).depthCapped),p.capped&&t.push(`lockfile exceeds ${String(p.maxEntries)} entries; truncated`),f&&t.push(`package-lock.json nests \`dependencies\` deeper than ${String(u)} levels; the deeper subtree(s) were NOT enumerated`),p.unread>0&&t.push(`package-lock.json has ${String(p.unread)} entr(ies) with no version cupel could read (an odd shape or a missing \`version\`); they were not enumerated`),{deps:p.deps,diagnostics:t,truncated:p.capped||f}}var wp=["workspace:","link:","portal:","file:","exec:"];function vp(e){let n=e.charCodeAt(0);if(n>=48&&n<=57||n===94||n===126||n===62||n===60||n===61||n===42||n===124)return!0;if(n===118||n===86){let t=e.charCodeAt(1);return t>=48&&t<=57}return!1}function Ip(e){let n=e.trim();if(n.length===0)return[];let t=n.indexOf("@",1);if(t<=0)return[];let o=n.slice(0,t),r=n.slice(t+1);if(o.length===0)return[];for(let l of wp)if(r.startsWith(l))return[];if(!r.startsWith("npm:"))return[o];let s=r.slice(4),a=s.indexOf("@",1);if(a>0){let l=s.slice(0,a);return l.length>0?[l]:[o]}return s.length===0||vp(s)?[o]:[o,s]}function Ap(e){if(at(e))return e.slice(0,-1);let n=0;for(let t=0;t<e.length-1;t+=1){let o=e.charCodeAt(t);if(o===34||o===39){n===0?n=o:n===o&&(n=0);continue}if(n===0&&o===58&&e.charCodeAt(t+1)===32)return e.slice(0,t)}return null}function _p(e){let n=e.replaceAll('"',"").replaceAll("'",""),t=[];for(let o of n.split(",")){let r=o.trim();r.length>0&&t.push(r)}return t}function Np(e){let n=e.charCodeAt(0)===65279?e.slice(1,64):e.slice(0,64),t="# yarn lockfile v";if(!n.startsWith(t))return null;let o=t.length;for(;o<n.length&&o<t.length+3;){let s=n.charCodeAt(o);if(s<48||s>57)break;o+=1}let r=n.slice(t.length,o);return r.length>0?r:null}function Oa(e){if(!e.startsWith("version"))return null;let n=e.charCodeAt(7);if(n!==58&&n!==32)return null;let t=on(e.slice(8).trim());return t.length>0?t:null}function Fr(e,n={}){let t=[],o=[],r=new Set,s=n.maxEntries??2e5,a=!1,l=null,i=!1,d=[],u=!1,p=-1,f=!1,m=0,g=()=>{d.length>0&&!u&&(m+=1)},y=Nt(e,n,(w,A)=>{if(w===0){g(),d=[],u=!1,p=-1,i=!1;let h=Ap(A);if(h===null)return;let S=on(h.trim());if(S==="__metadata"){a=!0,i=at(A);return}for(let _ of _p(S))d.push(...Ip(_));return}if(i){if(w===2&&l===null){let h=Oa(A);h!==null&&(l=h)}return}if(d.length===0||(p===-1&&(p=w),w!==p||u))return;let k=Oa(A);if(k!==null){u=!0;for(let h of d){let S=JSON.stringify([h,k]);if(!r.has(S)){if(o.length>=s){f=!0;return}r.add(S),o.push({name:h,version:k,lockKey:Rt(h),dev:!1})}}}});g();let b=a?"yarn.lock (Berry)":"yarn.lock (v1)";if(y.refusedAnchors)return{deps:[],diagnostics:[`${b} uses YAML anchors/aliases (& / * / <<:); cupel refuses to expand them (expansion-bomb shape) and did NOT read the dependency set`],truncated:!1};y.oversizeLines>0&&t.push(`${b} has ${String(y.oversizeLines)} over-long line(s) that were not parsed; the dependency set is incomplete`),f&&t.push(`${b} exceeds ${String(s)} entries; truncated`);let x=l??Np(e),I=x===null?null:Number(x.split(".")[0]);return x!==null&&(I===null||!Number.isInteger(I)||I<1||I>8)&&t.push(`${b} declares unsupported lockfileVersion ${x} (cupel knows v1 and Berry 4-8); its shape may differ, so what was read may be incomplete`),m>0&&t.push(`${b} has ${String(m)} entr(ies) with no version cupel could read (an unusual body shape or a missing \`version\`); they were not enumerated`),{deps:o,diagnostics:t,truncated:y.truncated||f}}function jr(e){let n=e.trim(),t=n.indexOf("(");t!==-1&&(n=n.slice(0,t));let o=n.indexOf("_");return o!==-1&&(n=n.slice(0,o)),n.trim()}function Br(e){let n=e.charCodeAt(0);return e.length>0&&n>=48&&n<=57}function Ca(e){let n=on(e.trim());if(n.length===0)return null;let t=n.indexOf("(");t!==-1&&(n=n.slice(0,t));let o=n.charCodeAt(0)===47;if(o&&(n=n.slice(1)),n.length===0)return null;if(!o&&n.charCodeAt(0)!==64){let u=n.indexOf("/"),p=n.indexOf("@",1);u>0&&(p===-1||u<p)&&n.slice(0,u).includes(".")&&n.indexOf("/",u+1)!==-1&&(n=n.slice(u+1))}let r=n.charCodeAt(0)===64,s=r?n.indexOf("/"):-1;if(r&&s<=0)return null;let a=r?s+1:0,l=-1;for(let u=a;u<n.length;u+=1){let p=n.charCodeAt(u);if(p===47||p===64){l=u;break}}if(l<=a)return null;let i=n.slice(0,l),d=jr(n.slice(l+1));return Br(d)?{name:i,version:d}:null}var Rp=new Set(["packages","snapshots","importers"]),Pp=new Set([5,6,7,8,9]);function $p(e){let n=on(e.trim()),t=0;for(;t<n.length&&n.charCodeAt(t)>=48&&n.charCodeAt(t)<=57;)t+=1;return t===0||t>6?null:Number(n.slice(0,t))}function _o(e){let n=e.indexOf(":");if(n<=0)return null;let t=e.slice(n+1).trim();return t.length===0?null:{key:on(e.slice(0,n).trim()),value:on(t)}}function Kr(e,n={}){let t=[],o=[],r=new Set,s=n.maxEntries??2e5,a="",l=null,i=!1,d=0,u=[],p=(m,g)=>{let y=JSON.stringify([m,g]);if(!r.has(y)){if(o.length>=s){i=!0;return}r.add(y),o.push({name:m,version:g,lockKey:Rt(m),dev:!1})}},f=Nt(e,n,(m,g)=>{if(m===0){let y=ko(g);if(a=y===null?"":on(y.trim()),l=null,a==="lockfileVersion"){let b=_o(g),x=b===null?null:$p(b.value);b!==null&&(x===null||!Pp.has(x))&&u.push(`pnpm-lock.yaml declares unsupported lockfileVersion ${b.value} (cupel knows 5.x-9.x); its shape may differ, so what was read may be incomplete`),a="";return}if(Rp.has(a)&&!at(g)){let b=_o(g)?.value.trim()??"";b!=="{}"&&b!=="[]"&&(d+=1),a=""}return}if(a==="packages"||a==="snapshots"){if(m!==2)return;let y=ko(g),b=y===null?null:Ca(y);if(b===null){d+=1;return}p(b.name,b.version);return}if(a==="importers"){if(m===6){let y=_o(g);if(y===null){l=g.endsWith(":")?on(g.slice(0,-1).trim()):null;return}l=null;let b=jr(y.value);Br(b)&&p(y.key,b);return}if(m===8&&l!==null){let y=_o(g);if(y===null||y.key!=="version")return;let b=jr(y.value);Br(b)&&p(l,b)}}});return f.refusedAnchors?{deps:[],diagnostics:["pnpm-lock.yaml uses YAML anchors/aliases (& / * / <<:); cupel refuses to expand them (expansion-bomb shape) and did NOT read the dependency set"],truncated:!1}:(t.push(...u),f.oversizeLines>0&&t.push(`pnpm-lock.yaml has ${String(f.oversizeLines)} over-long line(s) that were not parsed; the dependency set is incomplete`),i&&t.push(`pnpm-lock.yaml exceeds ${String(s)} entries; truncated`),d>0&&t.push(`pnpm-lock.yaml has ${String(d)} entr(ies) with no registry name@version key (git/tarball/link); they were not enumerated`),{deps:o,diagnostics:t,truncated:f.truncated||i})}function Da(e){return e.toLowerCase().replace(/[-_.]+/gu,"-")}var Op=1e6,Ma=2e5,Cp=4096,Mp=65536,Tp=262144,$t=/^[A-Za-z_][A-Za-z0-9_]*$/u;function La(e){if(e.length>Op)return null;let n,t;for(let o of e.split(/\r?\n/u)){if(o==="")break;let r=/^([A-Za-z][A-Za-z0-9-]*):[ \t]*(.*)$/u.exec(o);if(r===null)continue;let s=r[1]?.toLowerCase();s==="name"&&n===void 0?n=r[2]?.trim():s==="version"&&t===void 0&&(t=r[2]?.trim())}return n===void 0||t===void 0||n===""||t===""?null:{name:n,version:t}}function Fa(e){return e.split(/\r?\n/u).map(n=>n.trim()).filter(n=>n.length>0&&$t.test(n))}function ja(e){if(!e.startsWith('"'))return e.split(",")[0]??"";let n="";for(let t=1;t<e.length;t+=1){let o=e[t];if(o==='"'){if(e[t+1]==='"'){n+='"',t+=1;continue}return n}n+=o}return n}function Ba(e){return e===""||e==="."||e===".."||e==="__pycache__"||e.startsWith("__editable__")||e.endsWith(".dist-info")||e.endsWith(".egg-info")||e.endsWith(".data")}function Ka(e){return e.endsWith(".py")?e.slice(0,-3):e.endsWith(".so")||e.endsWith(".pyd")?e.split(".")[0]??null:null}function Ua(e){let n=e.split(/\r?\n/u);return n.length>Ma?n.slice(0,Ma):n}function za(e){let n=new Set;for(let t of Ua(e)){if(t==="")continue;let o=ja(t).split("/"),r=o[0]??"";if(Ba(r))continue;if(o.length>1){$t.test(r)&&n.add(r);continue}let s=Ka(r);s!==null&&$t.test(s)&&n.add(s)}return[...n].sort((t,o)=>t<o?-1:t>o?1:0)}function Dp(e){let n=e.split("/"),t=n[0]??"";if(Ba(t))return null;let o=n[n.length-1]??"",r=Ka(o);if(r===null)return null;let s=n.slice(0,-1);if(s.some(l=>!$t.test(l)||l==="__pycache__"))return null;let a=r==="__init__"?s:[...s,r];return a.length===0||!$t.test(r==="__init__"?s[s.length-1]??"":r)?null:a}function Wa(e,n=Cp){let t=new Set,o=0,r=0,s=!1;for(let a of Ua(e)){if(a==="")continue;let l=ja(a),i=Dp(l);if(i!==null){o+=1,(l.endsWith(".so")||l.endsWith(".pyd"))&&(r+=1);for(let d=1;d<=Math.min(2,i.length);d+=1){let u=i.slice(0,d).join(".");if(!t.has(u)){if(t.size>=n){s=!0;break}t.add(u)}}}}return{prefixes:[...t].sort((a,l)=>a<l?-1:a>l?1:0),moduleFiles:o,extensionModules:r,capped:s}}function Lp(e){if(e.length>Tp)return!0;let n=!1;for(let t of e.split(/\r?\n/u)){let o=t.trim();if(!(o===""||o.startsWith("#")||o.startsWith(";"))){if(o.startsWith("[")){let r=o.slice(1,o.endsWith("]")?-1:void 0).trim();n=r==="console_scripts"||r==="gui_scripts";continue}if(n&&o.includes("="))return!0}}return!1}function Va(e){if(e.length>Mp)return null;let n;try{n=JSON.parse(e)}catch{return null}if(typeof n!="object"||n===null||Array.isArray(n))return null;let t=n,o=typeof t.dir_info=="object"&&t.dir_info!==null&&!Array.isArray(t.dir_info)?t.dir_info:null;return{url:typeof t.url=="string"?t.url:null,editable:o?.editable===!0}}function Ot(e,n){let t=La(e);if(t===null)return null;let o=n.topLevelText!==void 0?Fa(n.topLevelText):[],r=o.length>0?o:n.recordText!==void 0?za(n.recordText):[],s=n.recordText!==void 0?Wa(n.recordText):{prefixes:[],moduleFiles:0,extensionModules:0,capped:!1},a=n.entryPointsText!==void 0?Lp(n.entryPointsText)?"declared":"none":n.entryPointsUnknown===!0?"unknown":"none",l=n.directUrlText!==void 0?Va(n.directUrlText)?.editable??!1:!1;return{name:Da(t.name),version:t.version,importNames:r,modulePrefixes:s.prefixes,moduleFiles:s.moduleFiles,editable:l,consoleScripts:a,extensionModules:s.extensionModules,recordKnown:n.recordText!==void 0}}function Ta(e,n,t){let o=e.get(n);o===void 0?e.set(n,[t]):o.includes(t)||o.push(t)}function Ur(e){let n=new Map,t=new Map,o=[];for(let r of e){if(r.importNames.length===0){o.push(r);continue}for(let s of r.importNames)Ta(n,s,r);for(let s of r.modulePrefixes)Ta(t,s,r)}return{byImportName:n,byModulePrefix:t,unmapped:o}}function No(e,n){let t=n.split(".").filter(r=>r.length>0),o=t[0];if(o===void 0)return[];for(let r=Math.min(2,t.length);r>=1;r-=1){let s=e.byModulePrefix.get(t.slice(0,r).join("."));if(s!==void 0&&s.length>0)return s}return e.byImportName.get(o)??[]}import{statSync as rm}from"node:fs";import sm from"node:path";import{lstatSync as Fp,readFileSync as jp,readdirSync as Bp,realpathSync as zr,statSync as Ct}from"node:fs";import Se from"node:path";function Mt(e){return e.ecosystem==="PyPI"||e.alsoPython===!0}var Xa=2e4,Ya=32,Ja=256,Kp=2*1024*1024,Up=256*1024,Za=256,zp=16,Wp=["package-lock.json","npm-shrinkwrap.json","yarn.lock","pnpm-lock.yaml"],Vp=["pyproject.toml","setup.py","setup.cfg"],qp=["requirements.txt","Pipfile"],Gp=["uv.lock","poetry.lock","Pipfile.lock","pdm.lock"],Qa={roots:[],observations:[],budget:"not-attempted",counts:{dirsWalked:0,manifestsSeen:0,rootsAdmitted:0,dotDirectoriesSkipped:0}};function qa(e,n){try{let t=Ct(e);return!t.isFile()||t.size>n?null:jp(e,"utf8")}catch{return null}}function Rn(e){let n;try{n=Ct(e)}catch(t){return t?.code==="ENOENT"?"absent":"refused"}return n.isFile()?"regular":"refused"}function Hp(e){try{return Ct(e).isDirectory()}catch{return!1}}function Xp(e,n){let t=0,o=0,r=-1,s=0;for(;o<n.length;)if(t<e.length&&(e.charAt(t)==="?"||e.charAt(t)===n.charAt(o)))t+=1,o+=1;else if(t<e.length&&e.charAt(t)==="*")r=t,s=o,t+=1;else if(r>=0)t=r+1,s+=1,o=s;else return!1;for(;t<e.length&&e.charAt(t)==="*";)t+=1;return t===e.length}function Yp(e,n){let t=(o,r)=>{if(o===e.length)return r===n.length;let s=e[o]??"";if(s==="**"){for(let l=r;l<=n.length;l+=1)if(t(o+1,l))return!0;return!1}if(r>=n.length)return!1;let a=n[r]??"";return(s.includes("*")||s.includes("?")?Xp(s,a):s===a)?t(o+1,r+1):!1};return t(0,0)}function Jp(e){let n=[],t=qa(Se.join(e,"package.json"),Kp);if(t!==null)try{let a=JSON.parse(t)?.workspaces;if(Array.isArray(a))for(let l of a)typeof l=="string"&&n.push(l);else if(typeof a=="object"&&a!==null){let l=a.packages;if(Array.isArray(l))for(let i of l)typeof i=="string"&&n.push(i)}}catch{}let o=qa(Se.join(e,"pnpm-workspace.yaml"),Up);o!==null&&n.push(...Zp(o));let r=[];for(let s of n){if(r.length>=Za)break;let a=s.trim();if(a.length===0)continue;for(;a.startsWith("./");)a=a.slice(2);if(a.startsWith("/")||Se.isAbsolute(a))continue;let l=a.split("/").filter(i=>i.length>0);l.length===0||l.length>zp||l.includes("..")||r.push(l.join("/"))}return r}function Zp(e){let n=[],t=!1;for(let o of e.split(`
|
|
19
|
+
`)){if(n.length>=Za)break;if(/^packages:\s*(#.*)?$/.test(o)){t=!0;continue}if(!t)continue;let r=/^\s+-\s*(.*?)\s*$/.exec(o);if(r===null){o.trim().length>0&&(t=!1);continue}let s=(r[1]??"").trim(),a=s.indexOf(" #");a>=0&&(s=s.slice(0,a).trim()),(s.startsWith('"')&&s.endsWith('"')&&s.length>=2||s.startsWith("'")&&s.endsWith("'")&&s.length>=2)&&(s=s.slice(1,-1)),s.length>0&&n.push(s)}return n}function Ga(e,n){let t=Se.relative(n,e);return t.length===0?!1:t.split(Se.sep).includes("node_modules")}function Ha(e,n){return Se.relative(e,n).split(Se.sep).join("/")}function Wr(e,n){let t=n?.maxDirs??Xa,o=n?.maxDepth??Ya,r=n?.maxRoots??Ja,s=n?.discoverPythonRoots??!0,a;try{a=zr(e)}catch{return{...Qa,observations:[{kind:"refused-unreadable",rel:""}]}}let l=[],i=[],d=new Set([a]),u=0,p=0,f=0,m="complete",g=Jp(a).map(w=>w.split("/")),y=w=>{let A="absent";for(let h of Vp){let S=Rn(Se.join(w,h));if(S==="regular"){A="declared";break}S==="refused"&&(A="refused")}if(A==="absent"&&qp.some(h=>Rn(Se.join(w,h))==="regular")&&(A="listed"),A==="absent")return{candidate:A,witnesses:[]};let k=[];return Gp.some(h=>Rn(Se.join(w,h))==="regular")&&k.push("own-lockfile"),Hp(Se.join(w,".venv"))&&k.push("installed-env"),{candidate:A,witnesses:k}},b=(w,A)=>{let k=y(w);return k.candidate==="absent"?"not-root":(k.candidate!=="listed"&&(p+=1),k.witnesses.length===0&&k.candidate!=="refused"?(k.candidate==="declared"&&i.push({kind:"undeclared-manifest",rel:A}),"not-root"):l.length>=r?"exhausted":(l.push({rel:A,abs:w,witnesses:k.witnesses,manifestRefused:k.candidate==="refused",ecosystem:"PyPI"}),"root"))},x=(w,A)=>{if(A.length===0){let P=Rn(Se.join(w,"package.json"))!=="absent",v=s?y(w):{candidate:"absent",witnesses:[]};return!P&&v.candidate!=="absent"?(l.push({rel:"",abs:w,witnesses:["scan-root",...v.witnesses],manifestRefused:!1,ecosystem:"PyPI"}),"root"):(l.push({rel:"",abs:w,witnesses:["scan-root",...v.witnesses],manifestRefused:!1,...v.witnesses.length>0?{alsoPython:!0}:{}}),"root")}let k=Rn(Se.join(w,"package.json"));if(k==="absent")return s?b(w,A):"not-root";p+=1;let h=[],S=A.split("/");g.some(P=>Yp(P,S))&&h.push("workspace-declared"),Wp.some(P=>Rn(Se.join(w,P))==="regular")&&h.push("own-lockfile");let _=s?y(w):{candidate:"absent",witnesses:[]};for(let P of _.witnesses)h.includes(P)||h.push(P);return h.length===0&&k!=="refused"?(i.push({kind:"undeclared-manifest",rel:A}),"not-root"):l.length>=r?"exhausted":(l.push({rel:A,abs:w,witnesses:h,manifestRefused:k==="refused",..._.witnesses.length>0?{alsoPython:!0}:{}}),"root")},I=[{abs:a,rel:"",depth:0}];for(;I.length>0;){let w=I.pop();if(w===void 0)break;if(u>=t){m="dirs-exhausted";break}u+=1;let A=x(w.abs,w.rel);if(A==="exhausted"){m="roots-exhausted";break}let k=A==="root";if(w.depth>=o){m=m==="complete"?"depth-clamped":m;continue}let h;try{h=Bp(w.abs)}catch{i.push({kind:"refused-unreadable",rel:w.rel});continue}h.sort().reverse();for(let S of h){let _=Se.join(w.abs,S),P=w.rel.length===0?S:`${w.rel}/${S}`,v;try{let j=Fp(_);v=j.isDirectory()||j.isSymbolicLink()&&Ct(_).isDirectory()}catch{continue}if(!v)continue;if(S==="node_modules"){k||i.push({kind:"unenumerated-install",rel:P});continue}if(S.startsWith(".")){f+=1,i.push({kind:"skipped-dot-directory",rel:P}),Rn(Se.join(_,"package.json"))!=="absent"&&i.push({kind:"undeclared-manifest",rel:P});continue}let T;try{T=zr(_)}catch{i.push({kind:"refused-unreadable",rel:P});continue}let N=a.endsWith(Se.sep)?a:a+Se.sep;if(T!==a&&!T.startsWith(N)){i.push({kind:"refused-out-of-root",rel:P});continue}Ga(T,a)||d.has(T)||(d.add(T),I.push({abs:T,rel:Ha(a,T),depth:w.depth+1}))}}for(let w of n?.operatorRoots??[]){let A=typeof w=="string"?w.slice(0,512):"",k=()=>{i.push({kind:"refused-operator-root",rel:A})};if(A.length===0||A.includes("\0")){k();continue}let h;try{h=zr(Se.resolve(a,A))}catch{k();continue}let S=a.endsWith(Se.sep)?a:a+Se.sep;if(h!==a&&(!h.startsWith(S)||Ga(h,a))){k();continue}let _;try{_=Ct(h).isDirectory()}catch{_=!1}if(!_||Rn(Se.join(h,"package.json"))!=="regular"){k();continue}let P=l.findIndex(N=>N.abs===h);if(P>=0){let N=l[P];N!==void 0&&!N.witnesses.includes("operator")&&(l[P]={...N,witnesses:[...N.witnesses,"operator"]});continue}let v=Ha(a,h);l.push({rel:v,abs:h,witnesses:["operator"],manifestRefused:!1});let T=i.findIndex(N=>N.kind==="undeclared-manifest"&&N.rel===v);T>=0&&i.splice(T,1)}return l.sort((w,A)=>w.rel<A.rel?-1:w.rel>A.rel?1:0),i.sort((w,A)=>w.kind!==A.kind?w.kind<A.kind?-1:1:w.rel<A.rel?-1:w.rel>A.rel?1:0),{roots:l,observations:i,budget:m,counts:{dirsWalked:u,manifestsSeen:p,rootsAdmitted:l.length,dotDirectoriesSkipped:f}}}import{lstatSync as el,readdirSync as Qp,readFileSync as em,realpathSync as ol,statSync as rl}from"node:fs";import ze from"node:path";var rn={envDir:".venv",maxDistributions:2e4,maxMetadataBytes:1e6,maxRecordBytes:32*1024*1024,maxTopLevelBytes:256*1024,maxDirectUrlBytes:64*1024,maxPyvenvCfgBytes:64*1024,maxEntryPointsBytes:256*1024,maxPthBytes:256*1024,maxPthPaths:1024},nm=/^python\d+\.\d+$/u;function Pn(e,n){let t;try{t=rl(e)}catch(o){return{why:o?.code==="ENOENT"?"absent":"unreadable"}}if(!t.isFile())return{why:"not-regular"};if(t.size>n)return{why:"oversize"};try{return{text:em(e,"utf8")}}catch{return{why:"unreadable"}}}function Vr(e,n){let t;try{if(t=ol(n),!rl(t).isDirectory())return null}catch{return null}return t===e||t.startsWith(e+ze.sep)?t:null}function nl(e,n){return ze.relative(e,n).split(ze.sep).join("/")}function tl(e){try{return Qp(e).sort()}catch{return null}}function tm(e){let n=[],t=[],o=0;for(let r of e.split(/\r?\n/u)){let s=r.trim();if(!(s===""||s.startsWith("#"))){if(/^import[ \t]/u.test(s)){o+=1;let a=/^import[ \t]+([A-Za-z_][A-Za-z0-9_.]*)/u.exec(s);a?.[1]!==void 0&&t.length<rn.maxPthPaths&&t.push(a[1]);continue}n.length<rn.maxPthPaths&&n.push(s)}}return{paths:n,importLines:o,importModules:t}}function om(e){let n=null;for(let t of e.split(/\r?\n/u)){let o=/^\s*(version_info|version)\s*=\s*(\S+)\s*$/u.exec(t);if(o!==null){if(o[1]==="version_info")return o[2]??null;n??=o[2]??null}}return n}function Tt(e,n){let t=n?.envDir??rn.envDir,o=n?.maxDistributions??rn.maxDistributions,r=n?.maxMetadataBytes??rn.maxMetadataBytes,s=n?.maxRecordBytes??rn.maxRecordBytes,a=n?.maxTopLevelBytes??rn.maxTopLevelBytes,l=n?.maxDirectUrlBytes??rn.maxDirectUrlBytes,i=rn.maxEntryPointsBytes,d=t,u=[],p=(P,v,T=null)=>({envRel:d,refused:P,sitePackages:[],interpreter:T,distInfos:[],pthFiles:[],unreadable:0,diagnostics:[...u,v],truncated:!1}),f;try{f=ol(e)}catch{return p("absent","the root itself could not be resolved")}let m=ze.join(f,t),g;try{g=el(m)}catch(P){return P?.code==="ENOENT"?p("absent",`${d}: absent`):p("not-a-directory",`${d}: could not be inspected`)}if(!g.isDirectory()&&!g.isSymbolicLink())return p("not-a-directory",`${d}: not a directory`);let y=Vr(f,m);if(y===null)return p("escapes-root",`${d}: resolves outside the project root (a symlinked environment is not the project's); refused, never followed`);let b=Pn(ze.join(y,"pyvenv.cfg"),rn.maxPyvenvCfgBytes),x="text"in b?om(b.text):null;"text"in b||u.push(`${d}/pyvenv.cfg: ${b.why} \u2014 interpreter version unknown`);let I=[];for(let P of["lib","lib64"]){let v=tl(ze.join(y,P));if(v!==null)for(let T of v)nm.test(T)&&I.push(ze.join(y,P,T,"site-packages"))}I.push(ze.join(y,"Lib","site-packages"));let w=[],A=new Set;for(let P of I){let v=Vr(y,P);v===null||A.has(v)||(A.add(v),w.push(v))}if(w.length===0)return p("no-site-packages",`${d}: no site-packages directory (lib/pythonX.Y/site-packages or Lib/site-packages)`,x);w.length>1&&u.push(`${d}: ${String(w.length)} site-packages directories; all enumerated`);let k=[],h=[],S=0,_=!1;e:for(let P of w){let v=nl(f,P),T=tl(P);if(T===null){u.push(`${v}: unreadable; nothing enumerated there`);continue}for(let N of T){let j=ze.join(P,N),O=N.endsWith(".dist-info"),F=N.endsWith(".egg-info");if(N.endsWith(".pth")){let G=Pn(j,rn.maxPthBytes);if(!("text"in G)){u.push(`${v}/${N}: ${G.why}; the paths it adds were NOT enumerated`);continue}h.push({name:N,sitePackages:v,...tm(G.text)});continue}if(!O&&!F)continue;if(k.length>=o){_=!0,u.push(`${v}: the distribution cap (${String(o)}) was hit at ${N}; the enumeration is INCOMPLETE`);break e}let K;try{K=el(j)}catch{S+=1,u.push(`${v}/${N}: could not be inspected; not enumerated`);continue}let te=O?"dist-info":"egg-info";if(K.isFile()&&F){let G=Pn(j,r);"text"in G?k.push({dir:N,kind:te,metadata:G.text,entryPointsUnknown:!0}):(S+=1,u.push(`${v}/${N}: ${G.why}; not enumerated`));continue}let U=Vr(y,j);if(U===null){S+=1,u.push(`${v}/${N}: not a directory inside the environment; not enumerated`);continue}let X=O?"METADATA":"PKG-INFO",D=Pn(ze.join(U,X),r);if(!("text"in D)){S+=1,u.push(`${v}/${N}: ${X} ${D.why}; not enumerated`);continue}let C={dir:N,kind:te,metadata:D.text},H=Pn(ze.join(U,"entry_points.txt"),i);"text"in H?C.entryPoints=H.text:H.why!=="absent"&&(C.entryPointsUnknown=!0,u.push(`${v}/${N}/entry_points.txt: ${H.why}; the commands it declares are UNKNOWN`));let J=Pn(ze.join(U,"top_level.txt"),a);if("text"in J?C.topLevel=J.text:J.why!=="absent"&&u.push(`${v}/${N}/top_level.txt: ${J.why}; ignored`),O){let G=Pn(ze.join(U,"RECORD"),s);"text"in G?C.record=G.text:u.push(`${v}/${N}/RECORD: ${G.why}; import names from top_level.txt only`);let Y=Pn(ze.join(U,"direct_url.json"),l);"text"in Y&&(C.directUrl=Y.text)}k.push(C)}}return{envRel:d,refused:null,sitePackages:w.map(P=>nl(f,P)),interpreter:x,distInfos:k,pthFiles:h,unreadable:S,diagnostics:u,truncated:_}}var im=["uv.lock","poetry.lock","Pipfile.lock","pdm.lock"];function am(e,n){for(let t of n)try{if(rm(sm.join(e,t)).isFile())return t}catch{}return null}function sl(e){let n=[],t=[],o=(p,f)=>{t.push({kind:p,detail:f,blindsAnalysis:!1,rootRel:""}),n.push(f)},r=am(e,im),s=Tt(e);if(s.refused!==null){let p=s.refused==="absent"?`no \`${s.envRel}\` is installed`:`\`${s.envRel}\` could not be read (${s.refused})`;return o("no-installed-env",`${r??"the Python manifest"} declares a dependency set but ${p}: ZERO distributions were enumerated, so this scan reports nothing about Python dependencies \u2014 it is not a clean bill of health. Install the environment (\`uv sync\`) and re-scan.`),{packages:[],source:"none",lockfilePath:r,diagnostics:[...n,...s.diagnostics],truncated:!1,gaps:t}}let a=[],l=new Set,i=[],d=0;for(let p of s.distInfos){let f=Ot(p.metadata,{...p.topLevel!==void 0?{topLevelText:p.topLevel}:{},...p.record!==void 0?{recordText:p.record}:{},...p.directUrl!==void 0?{directUrlText:p.directUrl}:{}});if(f===null){d+=1,n.push(`${p.dir}: METADATA carries no Name/Version; not enumerated`);continue}let m=JSON.stringify([f.name,f.version]);l.has(m)||(l.add(m),f.importNames.length===0&&i.push(f.name),a.push({name:f.name,version:f.version,lockKey:"",dev:!1,declaredIn:"",ecosystem:"PyPI"}))}n.push(...s.diagnostics);let u=s.unreadable+d;return u>0&&o("installed-env-partial",`${String(u)} entr${u===1?"y":"ies"} under ${s.sitePackages.join(", ")} could not be read as a distribution (see the diagnostics): those distributions are MISSING from this scan; the ${String(a.length)} enumerated were assessed normally.`),s.truncated&&o("installed-env-partial",`the environment walk under ${s.sitePackages.join(", ")} hit its distribution cap: the enumeration is INCOMPLETE, and a partial (possibly false-clean) set is never reported.`),i.length>0&&n.push(`${String(i.length)} distribution(s) carry no import name (distribution-unmapped, Tier-B): ${i.slice(0,5).join(", ")}${i.length>5?", \u2026":""} \u2014 advisories on them are enumerated; their modules cannot be resolved (ADR-109 D5)`),{packages:a,source:a.length>0?"installed-env":"none",lockfilePath:r,diagnostics:n,truncated:s.truncated,gaps:t}}var lm=128*1024*1024,dm=[{file:"package-lock.json",source:"npm-lockfile",parse:(e,n)=>Io(e,n===void 0?{}:{maxEntries:n})},{file:"npm-shrinkwrap.json",source:"npm-lockfile",parse:(e,n)=>Io(e,n===void 0?{}:{maxEntries:n})},{file:"yarn.lock",source:"yarn-lockfile",parse:(e,n)=>Fr(e,n===void 0?{}:{maxEntries:n})},{file:"pnpm-lock.yaml",source:"pnpm-lockfile",parse:(e,n)=>Kr(e,n===void 0?{}:{maxEntries:n})}],cm=[".pnp.cjs",".pnp.data.json",".pnp.js"];function Hr(e,n){let t;try{t=Gr(sn.join(e,n))}catch{return null}let o=e.endsWith(sn.sep)?e:e+sn.sep;return t.startsWith(o)?t:null}function al(e,n){let t=sn.join(e,"package.json"),o;try{o=Gr(t)}catch{return null}if(!o.startsWith(n+sn.sep))return null;try{if(!Dt(o).isFile())return null;let r=JSON.parse(qr(o,"utf8"));return typeof r.name!="string"||typeof r.version!="string"?null:{name:r.name,version:r.version}}catch{return null}}function ll(e,n){try{return Dt(sn.join(e,n)),!0}catch{return!1}}function um(e,n){if(ll(e,"pnpm-workspace.yaml"))return!0;let t=Hr(e,"package.json");if(t===null)return ll(e,"package.json");let o;try{let a=Dt(t);if(!a.isFile()||a.size>n)return!0;o=qr(t,"utf8")}catch{return!0}let r;try{r=JSON.parse(o)}catch{return!0}for(let a of["dependencies","devDependencies","optionalDependencies","peerDependencies"]){let l=r[a];if(typeof l=="object"&&l!==null&&Object.keys(l).length>0)return!0}let s=r.workspaces;return Array.isArray(s)?s.length>0:typeof s=="object"&&s!==null}function dl(e,n){let t=sn.join(e,"node_modules"),o=[],r;try{r=il(t,{withFileTypes:!0})}catch{return o}for(let s of r){let a=s.name;if(a.startsWith("."))continue;if(a.startsWith("@")){let i;try{i=il(sn.join(t,a),{withFileTypes:!0})}catch{continue}for(let d of i){let u=al(sn.join(t,a,d.name),n);u!==null&&o.push({dev:!1,name:u.name,version:u.version,lockKey:`node_modules/${a}/${d.name}`,linked:d.isSymbolicLink()||s.isSymbolicLink()})}continue}let l=al(sn.join(t,a),n);l!==null&&o.push({dev:!1,name:l.name,version:l.version,lockKey:`node_modules/${a}`,linked:s.isSymbolicLink()})}return o}var fm=5;function pm(e,n,t){let o=Hr(e,n);if(o===null){try{Dt(sn.join(e,n))}catch{return null}return{gap:`${n} resolves outside the scan root (symlink); refused, not read`}}let r;try{r=Dt(o)}catch{return null}if(!r.isFile())return{gap:`${n} is not a regular file; refused, not read`};if(r.size>t)return{gap:`${n} is ${String(r.size)} bytes (> ${String(t)}); skipped before reading to avoid a memory DoS`};try{return{text:qr(o,"utf8")}}catch{return{gap:`${n} could not be read`}}}function mm(e,n){let t=Gr(e),o=[],r=[],s=n?.maxLockfileBytes??lm,a=[],l=new Set,i=[],d=um(t,s),u=null,p=!1,f=(g,y,b)=>{r.push({kind:g,detail:y,blindsAnalysis:b,rootRel:""}),o.push(y)};for(let g of dm){let y=pm(t,g.file,s);if(y===null)continue;if("gap"in y){f("lockfile-unreadable",y.gap,!1);continue}let b=g.parse(y.text,n?.maxLockfileEntries);if(b.truncated&&(p=!0),b.deps.length===0){if(b.diagnostics.length>0||d){let x=b.diagnostics.length>0?b.diagnostics.join("; "):"no entries found";f("lockfile-unparsed",`${g.file} yielded NO dependencies (${x}); its transitive dependency set was not enumerated`,!1)}continue}b.diagnostics.length>0&&f("lockfile-partial",`${g.file} was only partly enumerated (${b.diagnostics.join("; ")})`,!1),u===null&&(u=g.file),i.includes(g.source)||i.push(g.source);for(let x of b.deps){let I=JSON.stringify([x.name,x.version,x.lockKey]);l.has(I)||(l.add(I),a.push({...x,declaredIn:g.file}))}}for(let g of cm)if(Hr(t,g)!==null){f("yarn-pnp",`${g} present: this project uses Yarn Plug'n'Play, whose dependency code lives in zips cupel does not resolve or read \u2014 NO dependency code was analyzed, so no finding here can be read as not-reachable. Set \`nodeLinker: node-modules\` for a full scan.`,!0);break}if(a.length>0){let g=i.length===1?i[0]??"none":"multi-lockfile";i.length>1&&o.push(`multiple lockfiles present (${i.join(", ")}); enumerated the UNION of all of them`);let y=new Set(a.map(I=>JSON.stringify([I.name,I.version]))),b=new Set,x=[];for(let I of dl(t,t)){let w=JSON.stringify([I.name,I.version,I.lockKey]);l.has(w)||(l.add(w),a.push({name:I.name,version:I.version,lockKey:I.lockKey,dev:I.dev,declaredIn:""}));let A=JSON.stringify([I.name,I.version]);I.linked||y.has(A)||b.has(A)||(b.add(A),x.length<fm&&x.push(Pt(I.name,I.version)))}if(b.size>0){let I=b.size-x.length;f("lockfile-skew",`node_modules holds ${String(b.size)} package(s) at a (name, version) no lockfile lists (${x.join(", ")}${I>0?`, and ${String(I)} more`:""}): ${u??"the lockfile"} and the installed tree DISAGREE, so cupel enumerated BOTH. A stale lockfile or an \`npm i --no-save\` is the usual cause \u2014 re-install and commit the lockfile so the reviewed set is the installed set.`,!1)}return{packages:a,source:g,lockfilePath:u,diagnostics:o,truncated:p,gaps:r}}let m=dl(t,t);return m.length>0?(f("shallow-node-modules",`no usable lockfile (package-lock.json / npm-shrinkwrap.json / yarn.lock / pnpm-lock.yaml), so the installed set came from a SHALLOW node_modules scan: ${String(m.length)} top-level package(s), with every transitive dependency missing. Commit a lockfile for a complete scan.`,!1),{packages:m.map(g=>({name:g.name,version:g.version,lockKey:g.lockKey,dev:!1,declaredIn:""})),source:"node-modules",lockfilePath:null,diagnostics:o,truncated:p,gaps:r}):(d&&f("no-enumeration","package.json declares dependencies but there is no lockfile and no readable node_modules: ZERO packages were enumerated, so this scan reports nothing about dependencies \u2014 it is not a clean bill of health. Install the project (or commit a lockfile) and re-scan.",!1),{packages:[],source:"none",lockfilePath:null,diagnostics:o,truncated:p,gaps:r})}function hm(e){return e.rel===""||e.witnesses.includes("own-lockfile")||e.witnesses.includes("operator")||e.witnesses.includes("installed-env")||e.manifestRefused}function gm(e){if(e.length===0||e==="."||e==="..")return!1;for(let n=0;n<e.length;n+=1){let t=e.charCodeAt(n);if(t<32||t===127||t>=128&&t<=159||t===92)return!1}return!0}function ul(e){return e===""||e.split("/").every(gm)}function ym(e,n){if(e===""||n==="")return n;if(!ul(e))return"";let t=`${e}/${n}`;return t.length<=vo?t:""}function cl(e,n){return e===""?n:`${e}: ${n}`}function xm(e){return{rel:"",abs:e,witnesses:["scan-root"],manifestRefused:!1}}function fl(e,n,t){let o=t?.maxUnionEntries??wo,r=n.roots.filter(hm),s=r.some(g=>g.rel==="")?r:[xm(e),...r],a=[],l=[],i=new Set,d=[],u=[],p=!1,f=!1;for(let g of s){let y=g.rel===""?e:g.abs,b=mm(y,t),x=Mt(g)?sl(y):null,I=x===null?b:km(b,x),w=I.diagnostics.map(k=>cl(g.rel,k));!ul(g.rel)&&I.packages.length>0&&w.push(`${g.rel}: its path holds a segment no install key may be built from, so the install location of its ${String(I.packages.length)} row(s) is refused \u2014 dependency-class evidence and execution context for them read fail-closed (ADR-071)`);let A={...I,rootRel:g.rel,...g.ecosystem!==void 0?{ecosystem:g.ecosystem}:{},...x!==null?{pythonLockfilePath:x.lockfilePath===null||g.rel===""?x.lockfilePath:`${g.rel}/${x.lockfilePath}`}:{},packages:I.packages.map(k=>({...k,lockKey:ym(g.rel,k.lockKey),declaredIn:k.declaredIn===""||g.rel===""?k.declaredIn:`${g.rel}/${k.declaredIn}`})),lockfilePath:I.lockfilePath===null||g.rel===""?I.lockfilePath:`${g.rel}/${I.lockfilePath}`,gaps:I.gaps.map(k=>({...k,rootRel:g.rel,detail:cl(g.rel,k.detail)})),diagnostics:w};a.push(A),I.truncated&&(p=!0);for(let k of A.packages){let h=JSON.stringify([k.name,k.version,k.lockKey]);if(!i.has(h)){if(l.length>=o){f=!0;break}i.add(h),l.push(k)}}d.push(...A.gaps),u.push(...A.diagnostics)}f&&(p=!0,u.push(`the union of installed sets across ${String(s.length)} roots exceeds its ceiling of ${String(o)} distinct rows; truncated \u2014 a partial enumeration is never reported (ADR-071)`));let m=a[0];if(m===void 0)throw new Error("unreachable: the scan root is always enumerated");return{packages:l,source:m.source,lockfilePath:m.lockfilePath,diagnostics:u,truncated:p,gaps:d,perRoot:a}}function Sm(e,n){let t;for(let o of e.perRoot){if(o.rootRel===""){t??=o;continue}n.startsWith(`${o.rootRel}/`)&&(t===void 0||o.rootRel.length>t.rootRel.length)&&(t=o)}return t}function Ro(e,n){return n.declaredIn!==""?n.declaredIn:Sm(e,n.lockKey)?.lockfilePath??null}function pl(e,n){let t=e.perRoot.find(o=>o.rootRel===n.rootRel);return bm.has(n.kind)?t?.pythonLockfilePath!==void 0&&t.pythonLockfilePath!==null?t.pythonLockfilePath:n.rootRel===""?null:`${n.rootRel}/pyproject.toml`:t?.lockfilePath!==void 0&&t.lockfilePath!==null?t.lockfilePath:n.rootRel===""?null:`${n.rootRel}/${t?.ecosystem==="PyPI"?"pyproject.toml":"package.json"}`}var bm=new Set(["no-installed-env","installed-env-partial"]);function km(e,n){return{packages:[...e.packages,...n.packages],source:e.packages.length===0&&n.packages.length>0?n.source:e.source,lockfilePath:e.lockfilePath??n.lockfilePath,diagnostics:[...e.diagnostics,...n.diagnostics],truncated:e.truncated||n.truncated,gaps:[...e.gaps,...n.gaps]}}function ml(e){let n=new Map;for(let t of e){let o=n.get(t.name)??new Set;o.add(t.version),n.set(t.name,o)}return t=>{let o=n.get(t);if(o===void 0)return;let r=[...o].sort();return r.length===1?r[0]:r}}function Lt(e){return new Set(e.map(n=>n.root))}function dt(e,n){let t=Lt(n);return e.roots.filter(o=>!t.has(o.rel)&&(o.rel===""||o.ecosystem!=="PyPI"))}function Xr(e){let n=e.slice(0,8),t=e.length-n.length;return n.join(", ")+(t>0?`, \u2026 and ${String(t)} more`:"")}function Yr(e,n){return dt(e,n).map(t=>({code:"unanalyzed-project-root",path:t.rel===""?".":t.rel,detail:t.rel===""?`the scan root declares no JavaScript entrypoint of its own (${t.witnesses.join(" + ")}) \u2014 its JavaScript, if any, was not analyzed while a nested root's was; pass \`--entry <file>\` or declare \`main\`, else every npm \`not-reachable\` is capped at \`unknown\` (ADR-071)`:`\`${t.rel}\` is a project root (${t.witnesses.join(" + ")}${t.manifestRefused?", manifest refused":""}) whose JavaScript this scan did not analyze; code there can load any installed npm package, so every npm \`not-reachable\` is capped at \`unknown\` until it is analyzed (ADR-071)`}))}function hl(e){let n=[],t=e.observations.filter(o=>o.kind==="unenumerated-install").map(o=>o.rel);if(t.length>0&&n.push({kind:"unenumerated-install",detail:`${String(t.length)} node_modules director${t.length===1?"y":"ies"} under no admitted project root (${Xr(t)}) were not enumerated: packages installed there are MISSING from this scan. The enumerated ones were analyzed normally (ADR-071)`,blindsAnalysis:!1,rootRel:""}),e.budget!=="complete"){let o=e.counts;n.push({kind:"root-discovery-truncated",detail:`root discovery did not finish (${e.budget}: ${String(o.dirsWalked)} dirs walked, ${String(o.rootsAdmitted)} roots admitted) \u2014 a project root with its own install location may have been missed, so every \`not-reachable\` is capped at \`unknown\` (ADR-071 Invariant C)`,blindsAnalysis:!0,rootRel:""})}return n}function gl(e){let n=new Set;for(let t of e)t.blindsAnalysis&&n.add(t.kind==="root-discovery-truncated"?"analysis-cap":"resolution-divergence");return[...n]}import{statSync as sh}from"node:fs";import qn from"node:path";import{spawnSync as Hm}from"node:child_process";import{fileURLToPath as Xm}from"node:url";import{readdirSync as Em,realpathSync as yl,statSync as xl}from"node:fs";import En from"node:path";var Sl=32,wm=512,vm=/^[A-Za-z_][A-Za-z0-9_]*$/u,Im=[".so",".pyd",".dylib"],Po=e=>({resolved:e,failure:null}),ct=e=>({resolved:null,failure:e});function Am(e){if(e.length===0||e.length>wm)return null;let n=e.split(".");return n.length>Sl?null:n.every(t=>vm.test(t))?n:null}function Jr(e){try{return xl(e).isDirectory()}catch{return!1}}function ut(e){try{return xl(e).isFile()}catch{return!1}}function Ft(e,n){let t,o;try{t=yl(n),o=yl(e)}catch{return null}return t===o||t.startsWith(o+En.sep)?t:null}function _m(e,n){let t;try{t=Em(e)}catch{return null}for(let o of t)if(o.startsWith(`${n}.`)&&Im.some(r=>o.endsWith(r))&&ut(En.join(e,o)))return En.join(e,o);return null}function $n(e,n){let t=Am(n);if(t===null)return ct("refused");let o=null,r=!1;for(let[s,a]of e.roots.entries()){let l=a,i=!1;for(let y of t.slice(0,-1)){let b=En.join(l,y);if(ut(En.join(b,"__init__.py"))||Jr(b)){if(!Jr(b)){i=!0;break}l=b;continue}i=!0,ut(`${b}.py`)&&(r=!0);break}if(i)continue;let d=t[t.length-1];if(d===void 0)return ct("refused");let u=En.join(l,d,"__init__.py");if(ut(u)){let y=Ft(a,u);return y===null?ct("escapes-root"):Po({module:n,kind:"package",path:y,rootIndex:s})}let p=En.join(l,`${d}.py`);if(ut(p)){let y=Ft(a,p);return y===null?ct("escapes-root"):Po({module:n,kind:"module",path:y,rootIndex:s})}let f=_m(l,d);if(f!==null){let y=Ft(a,f);return y===null?ct("escapes-root"):Po({module:n,kind:"extension",path:y,rootIndex:s})}let m=En.join(l,d);if(o===null&&Jr(m)){let y=Ft(a,m);y!==null&&(o={module:n,kind:"namespace",path:y,rootIndex:s});continue}let g=En.join(l,`${d}.pyi`);if(o===null&&ut(g)){let y=Ft(a,g);y!==null&&(o={module:n,kind:"stub-only",path:y,rootIndex:s})}}return o!==null?Po(o):ct(r?"not-a-package":"not-found")}function bl(e,n){if(n)return e;let t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function $o(e,n,t,o){if(t<1||t>Sl)return{failure:"refused"};let r=bl(e,n),s=r===""?[]:r.split("."),a=t-1;if(a>s.length)return{failure:"beyond-top-level"};let l=s.slice(0,s.length-a),i=o===null||o===""?[]:o.split("."),d=[...l,...i].join(".");return d===""?{failure:"beyond-top-level"}:{dotted:d}}var Zr="<toplevel>";var Nm=new Set(["self","cls"]),Rm=8;function El(e,n){return{path:e,start:n.start,end:n.end}}function kl(e,n){return n!==null?n.includes(e):!e.startsWith("_")}function es(e,n,t,o){let r=[],s=[],a=[],l=[],i=new Map,d=new Map,u=new Map,p=new Map,f=new Map,m=`${n}#${Zr}`;r.push({id:m,moduleId:n,name:Zr,kind:"function",declRange:{path:t,start:0,end:0},isExported:!1,publicSurfaceReachable:!1});for(let y of e.classes){let b=`${n}#class:${y.qualname}`;u.set(y.qualname,b),f.set(y.qualname,y.bases.filter(x=>x!==null)),s.push({id:b,moduleId:n,name:y.name,implementsRefs:[],members:[]})}for(let y of e.functions){let b=`${n}#${y.qualname}`;i.set(y.qualname,b);let x=y.enclosingClass,I=x===null?void 0:u.get(x),w=x===null&&y.enclosingFunction===null,A=w?kl(y.name,e.all):x!==null&&!x.includes(".")?kl(x,e.all):!1;if(r.push({id:b,moduleId:n,name:y.name,kind:I!==void 0?y.name==="__init__"?"ctor":"method":"function",...I!==void 0?{enclosingClassId:I}:{},declRange:El(t,y.range),isExported:A,publicSurfaceReachable:A}),w&&(d.set(y.name,b),A)){let k=o();a.push({id:k,moduleId:n,exportedName:y.name,kind:"value"}),l.push({exportId:k,target:{kind:"function",functionId:b}})}if(x!==null){let k=p.get(x)??new Map;k.set(y.name,b),p.set(x,k)}}let g=s.map(y=>{let b=[...u.entries()].find(([,I])=>I===y.id)?.[0],x=b===void 0?void 0:p.get(b);return x===void 0?y:{...y,members:[...x.values()]}});return{moduleId:n,functions:r,classes:g,exports:a,exportBindings:l,byQualname:i,topLevel:d,classByName:u,methods:p,baseNames:f,toplevelId:m}}function ns(e){let{decls:n,envs:t}=e,o=[],r=new Map;for(let[f,m]of n){let g=t.get(f);for(let[y,b]of m.baseNames){let x=m.classByName.get(y);if(x!==void 0)for(let I of b){let w=Pm(I,m,g,n);if(w===void 0)continue;o.push({subclassId:x,superclassId:w,relation:"extends"});let A=r.get(w)??[];A.push(x),r.set(w,A)}}}let s=new Map,a=(f,m)=>{let g=s.get(f)??[];g.includes(m)||g.push(m),s.set(f,g)};for(let f of n.values())for(let m of f.methods.values())for(let[g,y]of m)a(g,y);for(let f of e.rebinds??[]){let m=n.get(f.moduleId)?.topLevel.get(f.target);m!==void 0&&a(f.attr,m)}let l=new Map;for(let f of n.values())for(let m of f.classByName.values())l.set(m,f);let i=[],d=[],u=0,p=0;for(let{moduleId:f,path:m,call:g}of e.pending){let y=n.get(f);if(y===void 0)continue;let b=g.enclosingFunction===null?y.toplevelId:y.byQualname.get(g.enclosingFunction)??y.toplevelId,x=$m(g,f,y,t.get(f),n,t,{byMethodName:s,subclassesOf:r,classOwner:l}),I=`py-call:${f}:${String(u)}`;u+=1,x.resolution==="unresolved"&&(p+=1),i.push({id:I,enclosingFunctionId:b,calleeExprShape:g.receiver===null?"identifier":"member",resolvedTargetIds:x.ids,resolution:x.resolution,range:El(m,g.range)});for(let w of x.ids)d.push({callSiteId:I,calleeFunctionId:w,resolution:x.resolution})}return{callSites:i,callEdges:d,inheritEdges:o,unresolved:p}}function Qr(e,n,t,o,r=new Set,s=0){if(s>Rm)return;let a=`${e}${n}`;if(r.has(a))return;r.add(a);let l=t.get(e)?.topLevel.get(n);if(l!==void 0)return l;let i=o.get(e)?.names.get(n);if(i!==void 0)return Qr(i.moduleId,i.name,t,o,r,s+1)}function Pm(e,n,t,o){let r=n.classByName.get(e);if(r!==void 0)return r;let s=t?.names.get(e);if(s!==void 0)return o.get(s.moduleId)?.classByName.get(s.name)}var ft={ids:[],resolution:"unresolved"};function $m(e,n,t,o,r,s,a){if(e.callee===null)return ft;if(e.receiver===null){let u=t.topLevel.get(e.callee);if(u!==void 0)return{ids:[u],resolution:"resolved"};let p=o?.names.get(e.callee);if(p!==void 0){let f=Qr(p.moduleId,p.name,r,s);if(f!==void 0)return{ids:[f],resolution:"resolved"}}return ft}let l=e.attr;if(l===null)return ft;if(Nm.has(e.receiver)&&e.enclosingFunction!==null){let u=e.enclosingFunction.split(".").slice(0,-1).join("."),p=t.classByName.get(u);if(p!==void 0){let f=Om(p,l,a);return f.length===1?{ids:f,resolution:"resolved"}:f.length>1?{ids:f,resolution:"field-based"}:ft}}let i=o?.modules.get(e.receiver);if(i!==void 0){let u=Qr(i,l,r,s);return u!==void 0?{ids:[u],resolution:"resolved"}:ft}let d=a.byMethodName.get(l)??[];return d.length===0||d.length>64?ft:{ids:d,resolution:"field-based"}}function Om(e,n,t){let o=[],r=new Set,s=[e];for(;s.length>0;){let a=s.shift();if(a===void 0||r.has(a))continue;r.add(a);let l=t.classOwner.get(a);if(l!==void 0){let i=[...l.classByName.entries()].find(([,u])=>u===a)?.[0],d=i===void 0?void 0:l.methods.get(i)?.get(n);d!==void 0&&!o.includes(d)&&o.push(d)}for(let i of t.subclassesOf.get(a)??[])s.push(i)}return o}var Cm=5e3,wl=200,vl=100,Il={modules:[],exports:[],imports:[],functions:[],callSites:[],classes:[],callEdges:[],importEdges:[],exportBindings:[],inheritEdges:[]};function _l(e){return`pkg:${e}`}function fn(e){return e.split(/[\\/]+/u).join("/")}function Al(e,n){let t=e.endsWith("/")?e:`${e}/`,o=fn(n),r=fn(t);return o.startsWith(r)?o.slice(r.length):null}function Nl(e){let n=fn(e).split("/"),t=n[n.length-1]??"";if(t==="__init__.py")return{dotted:n.slice(0,-1).join("."),isPackage:!0};let o=t.endsWith(".py")?t.slice(0,-3):t;return{dotted:[...n.slice(0,-1),o].filter(r=>r!=="").join("."),isPackage:!1}}function ts(e){return e.split(".")[0]??e}var Mm="site-packages:";function os(e){let n=e.extract??Oo,t=e.maxModules??Cm,o=(e.externalRoots??[]).map(C=>fn(C).endsWith("/")?fn(C):`${fn(C)}/`),r=C=>{let H=fn(C);return o.find(J=>H.startsWith(J))??null},s=C=>r(C)!==null,a=[],l=new Map,i=[],d=[],u=new Set,p=new Set,f=new Map,m=new Map,g=[],y=new Map,b=[],x=0,I=()=>{let C=`py-export:${String(x)}`;return x+=1,C},w=null,A=!1,k=new Set,h=[];for(let C of e.entryFiles){let H=Al(e.projectRoot,C);if(H===null){a.push({code:"unresolved-import",where:fn(C),detail:"entrypoint lies outside the project root; not analyzed"});continue}u.has(C)||(u.add(C),h.push({file:C,rel:H,isEntry:!0,packageName:"",modulePath:H}))}let S=C=>{let H=_l(C);return l.has(H)||(p.add(C),l.set(H,{id:H,packageName:C,versionRange:"",path:C,moduleSystem:"dual",isEntrypoint:!1,externalSurface:!0})),H},_=0,P=(C,H,J,G)=>{let Y=`py-import:${String(_)}`;_+=1,i.push({id:Y,moduleId:C,specifier:H,...J!==null?{resolvedModuleId:J}:{},isNamespace:!1,isDefault:!1,dynamic:G,specifierIsLiteral:!0}),J!==null&&d.push({importId:Y,resolvedModuleId:J})};for(let C=0;C<vl&&h.length>0;C+=1){let H=h.slice(0,wl);h=h.slice(wl);let J=n(H.map(Y=>Y.file),e.python!==void 0?{python:e.python}:{});if(w??=J.interpreter,k.size===0&&J.stdlib.length>0&&(k=new Set(J.stdlib)),J.refused!==null)return a.push({code:"extract-refused",where:"",detail:`${J.refused}: ${J.diagnostics.join("; ")}`}),{graph:Il,diagnostics:a,interpreter:J.interpreter,counts:{modules:0,surfaces:0}};let G=new Map(J.files.map(Y=>[Y.path,Y]));for(let Y of H){let re=G.get(Y.file),ne=Y.rel,$=Nl(Y.modulePath);if(l.set(ne,{id:ne,packageName:Y.packageName,versionRange:"",path:Y.modulePath,moduleSystem:"dual",isEntrypoint:Y.isEntry}),re===void 0||re.refused!==null){a.push({code:"file-refused",where:Y.rel,detail:re?.refused??"no row was returned for this file"});continue}v(re,ne,$),F(re,Y.rel),f.set(ne,es(re,ne,Y.rel,I)),m.set(ne,O(re,ne,$));for(let Z of re.calls)g.push({moduleId:ne,path:Y.rel,call:Z});for(let Z of re.escapes){if(Z.kind!=="attr-rebind")continue;let Q=Z.attr??null;Q===null||Z.target===null||b.push({moduleId:ne,attr:Q,target:Z.target})}}}function v(C,H,J){for(let G of C.imports){if(G.guards.includes("type-checking"))continue;let Y=[];if(G.level>0){let ne=$o(J.dotted,J.isPackage,G.level,G.module);if("failure"in ne){a.push({code:"unresolved-import",where:C.path,detail:`relative import (level ${String(G.level)}) ${ne.failure}`});continue}Y.push(ne.dotted);for(let $ of G.names)Y.push(`${ne.dotted}.${$.name}`)}else if(G.module!==null){Y.push(G.module);for(let ne of G.names)Y.push(`${G.module}.${ne.name}`)}else continue;let re=!1;for(let ne of Y)T(ne,H,G.deferred)&&(re=!0);if(!re){let ne=Y[0]??"";P(H,ne,null,G.deferred);let $=ts(ne);if(k.has($)||G.guards.includes("optional")||(e.environmentComplete??!1)&&e.distributionOf($)===null)continue;a.push({code:"unresolved-import",where:C.path,detail:`\`${ne}\` did not resolve on the search path`})}}}function T(C,H,J){let G=C.split("."),Y=!1;for(let re=1;re<=G.length;re+=1){let ne=G.slice(0,re).join("."),$=$n(e.paths,ne);$.resolved!==null&&(j($.resolved,H,ne,J),re===G.length&&(Y=!0))}return Y}function N(C){return u.has(C.file)||l.has(C.rel)?!0:u.size>=t?(A||(A=!0,a.push({code:"module-cap",where:C.rel,detail:`the analyzed-module ceiling (${String(t)}) was hit; the graph is INCOMPLETE`})),!1):(u.add(C.file),h.push(C),!0)}function j(C,H,J,G){if(C.kind==="stub-only")return;let Y=C.kind==="module"||C.kind==="package",re=Al(e.projectRoot,C.path);if(re!==null&&!s(C.path)&&Y){let Q=re;P(H,J,Q,G),y.set(J,Q),N({file:C.path,rel:re,isEntry:!1,packageName:"",modulePath:re});return}let ne=e.distributionOf(ts(J));if(ne===null){P(H,J,null,G),a.push({code:"unresolved-import",where:J,detail:`resolved to ${C.kind} outside the project, but no installed distribution provides \`${ts(J)}\``});return}let $=r(C.path);if(!Y||$===null){P(H,J,S(ne),G);return}let Z=`${Mm}${fn(C.path).slice($.length)}`;P(H,J,Z,G),y.set(J,Z),N({file:C.path,rel:Z,isEntry:!1,packageName:ne,modulePath:fn(C.path).slice($.length)})}function O(C,H,J){let G=new Map,Y=new Map;for(let re of C.imports){if(re.guards.includes("type-checking"))continue;let ne=re.module;if(re.level>0){let $=$o(J.dotted,J.isPackage,re.level,re.module);if("failure"in $)continue;ne=$.dotted}if(ne!==null){if(re.form==="import"){let $=re.names[0]?.asname??null;if($!==null){let ce=y.get(ne);ce!==void 0&&G.set($,ce);continue}let Z=ne.split(".")[0]??ne,Q=y.get(Z)??y.get(ne);Q!==void 0&&G.set(Z,Q);continue}for(let $ of re.names){let Z=$.asname??$.name,Q=y.get(`${ne}.${$.name}`);if(Q!==void 0){G.set(Z,Q);continue}let ce=y.get(ne);ce!==void 0&&Y.set(Z,{moduleId:ce,name:$.name})}}}return G.set("",H),{modules:G,names:Y}}function F(C,H){for(let J of C.escapes)switch(J.kind){case"loader-escape":a.push({code:"loader-escape",where:H,detail:`${J.callee} loads a module this analysis cannot name`});break;case"pkgutil-scan":case"runpy":case"entry-point-load":a.push({code:"dynamic-load-set",where:H,detail:`${J.callee} loads a set of modules the syntax does not name`});break;case"sys-modules":a.push({code:"module-registry-write",where:H,detail:`${J.callee} rewrites the module registry at run time`});break;case"import-module-literal":{let G=J.target;if(G===null)break;T(G,H,!0);break}case"dispatch-escape":break}}h.length>0&&a.push({code:"module-cap",where:"",detail:`the walk did not finish within ${String(vl)} waves; the graph is INCOMPLETE`});let K=ns({decls:f,envs:m,pending:g,rebinds:b}),te=[...f.values()].flatMap(C=>C.functions),U=[...f.values()].flatMap(C=>C.classes),X=[...f.values()].flatMap(C=>C.exports),D=[...f.values()].flatMap(C=>C.exportBindings);return{graph:{...Il,modules:[...l.values()],imports:i,importEdges:d,functions:te,classes:U,exports:X,exportBindings:D,callSites:K.callSites,callEdges:K.callEdges,inheritEdges:K.inheritEdges},diagnostics:a,interpreter:w,counts:{modules:l.size-p.size,surfaces:p.size}}}import{readdirSync as Tm,readFileSync as Dm,statSync as rs}from"node:fs";import pn from"node:path";import{spawnSync as Lm}from"node:child_process";import{fileURLToPath as Fm}from"node:url";var jm="python3",Bm=256*1024,Km=8*1024*1024,Um=/^([A-Za-z_][A-Za-z0-9_.]*)(?::([A-Za-z_][A-Za-z0-9_.]*))?$/u,zm=/(?:^|\s)([A-Za-z_][A-Za-z0-9_.]*:[A-Za-z_][A-Za-z0-9_.]*)(?:\s|$)/u;function $l(){return Fm(new URL("../py/metadata.py",import.meta.url))}function jt(e){try{return rs(e).isFile()}catch{return!1}}function Rl(e){try{return rs(e).isDirectory()}catch{return!1}}function Wm(e,n){return pn.relative(e,n).split(pn.sep).join("/")}function Vm(e){let n=e.python??process.env.CUPEL_PYTHON??jm,t=Lm(n,["-I","-S",$l(),e.projectRoot],{encoding:"utf8",maxBuffer:Km,timeout:6e4}),o=i=>({entries:[],projectName:null,gaps:[{source:"metadata",declaration:"pyproject.toml / setup.cfg",detail:i}]});if(t.error!==void 0||t.status!==0)return o("the declared entry surface could not be read; it is unknown, not empty");let r;try{r=JSON.parse(t.stdout)}catch{return o("the declared entry surface came back unreadable; it is unknown, not empty")}if(typeof r!="object"||r===null)return{entries:[],projectName:null,gaps:[]};let s=r,a=(Array.isArray(s.entryPoints)?s.entryPoints:[]).filter(i=>typeof i=="object"&&i!==null&&typeof i.name=="string"&&typeof i.target=="string"&&typeof i.kind=="string"),l=(Array.isArray(s.gaps)?s.gaps:[]).flatMap(i=>{if(typeof i!="object"||i===null)return[];let d=i,u=typeof d.file=="string"?d.file:"",p=typeof d.why=="string"?d.why:"";return[{source:"metadata",declaration:u,detail:p==="executable-metadata-not-read"?"setup.py declares this project's entry points and is a PROGRAM: cupel never runs it, so the declared surface is INCOMPLETE":p}]});return{entries:a,gaps:l,projectName:typeof s.projectName=="string"?s.projectName:null}}function Pl(e,n){let t=Um.exec(n.trim());if(t===null)return{detail:`\`${n}\` is not a module:attr target`};let o=t[1]??"",r=$n(e.paths,o);if(r.resolved===null)return{detail:`\`${o}\` ${r.failure??"did not resolve"}`};if(r.resolved.kind==="namespace"||r.resolved.kind==="stub-only")return{detail:`\`${o}\` resolved to a ${r.resolved.kind}, which runs no code`};let s=Wm(e.projectRoot,r.resolved.path);return s.startsWith("..")?{detail:`\`${o}\` resolves outside the project root; not seeded`}:{file:s}}function qm(e){let n=[];jt(pn.join(e,"__main__.py"))&&n.push("__main__.py");let t=(o,r)=>{let s;try{s=Tm(o).sort()}catch{return}for(let a of s){if(a.startsWith("."))continue;let l=pn.join(o,a);Rl(l)&&jt(pn.join(l,"__init__.py"))&&jt(pn.join(l,"__main__.py"))&&n.push(`${r}${a}/__main__.py`)}};return t(e,""),Rl(pn.join(e,"src"))&&t(pn.join(e,"src"),"src/"),n}function Gm(e,n){let t=pn.join(e,"Procfile");if(!jt(t))return[];let o;try{if(rs(t).size>n)return[];o=Dm(t,"utf8")}catch{return[]}let r=[];for(let s of o.split(/\r?\n/u)){let a=zm.exec(s);a?.[1]!==void 0&&r.push(a[1])}return r}function ss(e){let n=[],t=[],o=new Set,r=(l,i,d)=>{let u=`${l} ${i}`;o.has(u)||(o.add(u),n.push({file:l,source:i,declaration:d}))},s=Vm(e);t.push(...s.gaps);for(let l of s.entries){let i=l.kind==="entry-point-group"?"entry-point-group":"console-script",d=Pl(e,l.target);"file"in d?r(d.file,i,`${l.name} = ${l.target}`):t.push({source:i,declaration:`${l.name} = ${l.target}`,detail:d.detail})}for(let l of qm(e.projectRoot))r(l,"dunder-main",l);jt(pn.join(e.projectRoot,"manage.py"))&&r("manage.py","manage-py","manage.py");let a=e.maxProcfileBytes??Bm;for(let l of Gm(e.projectRoot,a)){let i=Pl(e,l);"file"in i?r(i.file,"launch-declaration",l):t.push({source:"launch-declaration",declaration:l,detail:i.detail})}return{entrypoints:n,gaps:t,projectName:s.projectName}}var ik=256*1024*1024;var Ol="CUPEL_PYTHON",Ym=["-I","-S"],Jm="python3",Zm=256*1024*1024,Qm=12e4,eh=512;function nh(){return Xm(new URL("../py/extract.py",import.meta.url))}function be(e,n=eh){return typeof e=="string"&&e.length<=n?e:null}function Vn(e){return typeof e=="number"&&Number.isFinite(e)?e:0}function Bt(e){let n=On(e)?e:{};return{line:Vn(n.line),endLine:Vn(n.endLine),col:Vn(n.col),start:Vn(n.start),end:Vn(n.end)}}function On(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Wn(e){return Array.isArray(e)?e:[]}function pt(e){return Wn(e).map(n=>be(n))}var th=new Set(["import-module-literal","loader-escape","pkgutil-scan","runpy","entry-point-load","dispatch-escape","attr-rebind","sys-modules"]),oh=new Set(["unreadable","oversize","nul-byte","undecodable","parse-error","recursion","too-many-nodes"]);function rh(e){let n=be(e.path,4096);if(n===null)return null;let t=e.refused,o=typeof t=="string"&&oh.has(t)?t:null,r=be(e.detail,200),s=Wn(e.imports).filter(On).map(f=>({form:f.form==="import"?"import":"from",module:be(f.module),level:Vn(f.level),names:Wn(f.names).filter(On).map(m=>({name:be(m.name)??"",asname:be(m.asname)})).filter(m=>m.name!==""),star:f.star===!0,deferred:f.deferred===!0,enclosingFunction:be(f.enclosingFunction),guards:pt(f.guards).filter(m=>m!==null),range:Bt(f.range)})),a=Wn(e.functions).filter(On).flatMap(f=>{let m=be(f.name),g=be(f.qualname);return m===null||g===null?[]:[{name:m,qualname:g,kind:f.kind==="async-function"?"async-function":"function",enclosingClass:be(f.enclosingClass),enclosingFunction:be(f.enclosingFunction),decorators:pt(f.decorators),range:Bt(f.range)}]}),l=Wn(e.classes).filter(On).flatMap(f=>{let m=be(f.name),g=be(f.qualname);return m===null||g===null?[]:[{name:m,qualname:g,bases:pt(f.bases),decorators:pt(f.decorators),range:Bt(f.range)}]}),i=Wn(e.calls).filter(On).map(f=>({callee:be(f.callee),attr:be(f.attr),receiver:be(f.receiver),enclosingFunction:be(f.enclosingFunction),argCount:Vn(f.argCount),range:Bt(f.range)})),d=Wn(e.escapes).filter(On).flatMap(f=>{let m=f.kind,g=be(f.callee);return typeof m!="string"||!th.has(m)||g===null?[]:[{kind:m,callee:g,target:be(f.target),attr:be(f.attr),enclosingFunction:be(f.enclosingFunction),range:Bt(f.range)}]}),u=e.all,p=Array.isArray(u)?pt(u).filter(f=>f!==null):null;return{path:n,refused:o,...r!==null?{detail:r}:{},imports:s,functions:a,classes:l,calls:i,escapes:d,all:p,allComputed:e.allComputed===!0,truncated:pt(e.truncated).filter(f=>f!==null)}}function Oo(e,n={}){let t=n.env??process.env,o=n.python??t[Ol]??Jm,r=[],s=e.filter(m=>!m.includes(`
|
|
20
|
+
`));s.length!==e.length&&r.push(`${String(e.length-s.length)} path(s) carried a newline and were not extracted`);let a=[...Ym,nh()];n.maxBytesPerFile!==void 0&&a.push("--max-bytes",String(n.maxBytesPerFile));let l=Hm(o,a,{input:s.length>0?`${s.join(`
|
|
21
|
+
`)}
|
|
22
|
+
`:"",encoding:"utf8",maxBuffer:Zm,timeout:n.timeoutMs??Qm,env:t});if(l.error!==void 0){let m=l.error.code,g=m==="ENOENT";return{refused:g?"no-interpreter":"script-failed",interpreter:null,files:[],stdlib:[],diagnostics:[...r,g?`no Python interpreter: \`${o}\` is not on PATH (set ${Ol} to the interpreter this project runs under)`:`the Python extract could not run (${m??l.error.message})`]}}if(l.status!==0){let m=(l.stderr??"").slice(-400).trim();return{refused:"script-failed",interpreter:null,files:[],stdlib:[],diagnostics:[...r,`the Python extract exited ${String(l.status??"on a signal")}${m!==""?`: ${m}`:""}`]}}let i=(l.stdout??"").split(`
|
|
23
|
+
`).filter(m=>m.trim()!==""),d=null,u=[],p=[];for(let m of i){let g;try{g=JSON.parse(m)}catch{r.push("the Python extract emitted a line that is not JSON; it was skipped");continue}if(!On(g))continue;if(g.kind==="header"){d=be(g.interpreter,64);let b=g.stdlib;Array.isArray(b)&&(u=b.filter(x=>typeof x=="string"&&x.length<=128));continue}let y=rh(g);if(y===null){r.push("the Python extract emitted a file row without a path; it was skipped");continue}p.push(y)}if(d===null)return{refused:"unreadable-output",interpreter:null,files:[],stdlib:[],diagnostics:[...r,"the Python extract did not report an interpreter version"]};let f=s.length-p.length;return f>0&&r.push(`${String(f)} file(s) asked for produced no row \u2014 treat the extract as incomplete`),{refused:null,interpreter:d,files:p,stdlib:u,diagnostics:r}}var ih="python3",ah={"loader-escape":"dynamic-load","dynamic-load-set":"dynamic-load","module-registry-write":"dynamic-load","unresolved-import":"resolution-divergence","file-refused":"analysis-cap","module-cap":"analysis-cap","extract-refused":"analysis-cap"};function lh(e,n,t=o=>Oo([],{python:o}).refused===null){let o=qn.resolve(e,n.envRel);for(let r of["bin/python3","bin/python","Scripts/python.exe"]){let s=qn.join(o,r);try{if(!sh(s).isFile())continue}catch{continue}if(t(s))return s}return ih}function dh(e,n){let t=[e];for(let o of n.sitePackages)t.push(qn.resolve(e,o));for(let o of n.pthFiles)for(let r of o.paths)t.push(qn.isAbsolute(r)?r:qn.resolve(e,o.sitePackages,r));return{roots:[...new Set(t)]}}function ch(e){let n=[];for(let t of e.distInfos){let o=Ot(t.metadata,{...t.topLevel!==void 0?{topLevelText:t.topLevel}:{},...t.record!==void 0?{recordText:t.record}:{},...t.directUrl!==void 0?{directUrlText:t.directUrl}:{},...t.entryPoints!==void 0?{entryPointsText:t.entryPoints}:{},...t.entryPointsUnknown===!0?{entryPointsUnknown:!0}:{}});o!==null&&n.push(o)}return n}function uh(e){return n=>{let t=e.byImportName.get(n);return t===void 0||t.length===0?null:t.length===1?t[0]?.name??null:null}}function fh(e,n,t={}){let r=(t.readEnvironment??Tt)(n),s=ch(r),a=Ur(s),l=r.diagnostics.map(x=>x),i=t.python??lh(n,r),d=dh(n,r),u=gh(r,a,d),p=new Map;for(let x of s)p.set(x.name,mh(x,u.distributions));for(let x of u.seen)l.push(`startup hook: ${x}`);for(let x of u.unattributed)l.push(`startup escape: ${x} \u2014 a module runs at interpreter start that no installed distribution claims`);let f=ss({projectRoot:n,paths:d,python:i});for(let x of f.gaps)l.push(`entrypoint \`${x.declaration}\` (${x.source}): ${x.detail}`);if(f.entrypoints.length===0)return l.push("no Python entrypoint was found (no console script, `__main__.py`, `manage.py` or launch declaration resolved), so no Python dependency can be reported unreachable"),{rootRel:e,graph:Kt,incompleteness:[],analysisAborted:"no-entrypoint",entrypoints:[],entrypointGaps:f.gaps,interpreter:null,diagnostics:l,execution:p};let m=os({projectRoot:n,paths:d,entryFiles:f.entrypoints.map(x=>qn.join(n,x.file)),environmentComplete:!r.truncated&&r.refused===null,externalRoots:r.sitePackages.map(x=>qn.resolve(n,x)),distributionOf:uh(a),python:i,...t.maxModules!==void 0?{maxModules:t.maxModules}:{}});for(let x of m.diagnostics)l.push(`${x.code} at ${x.where}: ${x.detail}`);if(m.graph.modules.length===0)return{rootRel:e,graph:Kt,incompleteness:[],analysisAborted:"analyzer-crash",entrypoints:f.entrypoints,entrypointGaps:f.gaps,interpreter:m.interpreter,diagnostics:l,execution:p};let g=new Map;for(let x of m.graph.modules)g.set(x.id,x.id),g.set(x.path,x.id);let y=m.graph.modules[0]?.id,b=m.diagnostics.map(x=>({source:g.get(x.where)??y,cause:ah[x.code],reach:{kind:"unbounded"}}));return u.unattributed.length>0&&b.push({source:y,cause:"dynamic-load",reach:{kind:"unbounded"}}),{rootRel:e,graph:m.graph,incompleteness:b,analysisAborted:null,entrypoints:f.entrypoints,entrypointGaps:f.gaps,interpreter:m.interpreter,diagnostics:l,execution:p}}var Kt={modules:[],exports:[],imports:[],functions:[],callSites:[],classes:[],callEdges:[],importEdges:[],exportBindings:[],inheritEdges:[]};function ph(e){if(e.length===0)return null;let n=[],t=new Map;for(let x of e){let I=x.rootRel===""?".":x.rootRel;for(let w of x.diagnostics)n.push(`${I}: ${w}`);for(let[w,A]of x.execution){let k=t.get(w);t.set(w,k===void 0?A:[...new Set([...k,...A])])}}let o=e.filter(x=>x.analysisAborted===null);if(o.length===0)return{graph:Kt,incompleteness:[],analysisAborted:e[0]?.analysisAborted??"no-entrypoint",roots:e,diagnostics:n,execution:t};let r=[],s=[],a=[],l=[],i=[],d=[],u=[],p=[],f=[],m=[],g=[],y=new Set;for(let x of o){let I=x.rootRel===""?"":`${x.rootRel}::`,w=new Set(x.graph.modules.filter(v=>v.externalSurface===!0).map(v=>v.id)),A=v=>w.has(v)?v:`${I}${v}`,k=v=>`${I}${v}`,h=v=>`${I}${v}`,S=v=>`${I}${v}`,_=v=>`${I}${v}`,P=v=>`${I}${v}`;for(let v of x.graph.modules){if(v.externalSurface===!0){if(y.has(v.id))continue;y.add(v.id),r.push(v);continue}r.push({...v,id:A(v.id)})}for(let v of x.graph.imports)s.push({...v,id:k(v.id),moduleId:A(v.moduleId),...v.resolvedModuleId!==void 0?{resolvedModuleId:A(v.resolvedModuleId)}:{}});for(let v of x.graph.importEdges)a.push({importId:k(v.importId),resolvedModuleId:A(v.resolvedModuleId)});for(let v of x.incompleteness)g.push({...v,source:A(v.source)});for(let v of x.graph.functions)l.push({...v,id:h(v.id),moduleId:A(v.moduleId),...v.enclosingClassId!==void 0?{enclosingClassId:S(v.enclosingClassId)}:{}});for(let v of x.graph.classes)i.push({...v,id:S(v.id),moduleId:A(v.moduleId),members:v.members.map(h)});for(let v of x.graph.exports)d.push({...v,id:P(v.id),moduleId:A(v.moduleId)});for(let v of x.graph.exportBindings)u.push({exportId:P(v.exportId),target:v.target.kind==="function"?{kind:"function",functionId:h(v.target.functionId)}:{kind:"module",moduleId:A(v.target.moduleId)}});for(let v of x.graph.callSites)p.push({...v,id:_(v.id),enclosingFunctionId:h(v.enclosingFunctionId),resolvedTargetIds:v.resolvedTargetIds.map(h)});for(let v of x.graph.callEdges)f.push({...v,callSiteId:_(v.callSiteId),calleeFunctionId:h(v.calleeFunctionId)});for(let v of x.graph.inheritEdges)m.push({...v,subclassId:S(v.subclassId),superclassId:S(v.superclassId)})}let b=r[0]?.id;for(let x of e)x.analysisAborted===null||b===void 0||g.push({source:b,cause:x.analysisAborted==="no-entrypoint"?"no-entrypoint":"analysis-cap",reach:{kind:"unbounded"}});return{graph:{modules:r,imports:s,importEdges:a,functions:l,classes:i,exports:d,exportBindings:u,callSites:p,callEdges:f,inheritEdges:m},incompleteness:g,analysisAborted:null,roots:e,diagnostics:n,execution:t}}function Cl(e,n={}){let t=e.filter(o=>Mt(o));return t.length===0?null:ph(t.map(o=>fh(o.rel,o.abs,n)))}function mh(e,n){let t=[];return e.consoleScripts==="declared"&&t.push("bin"),e.extensionModules>0&&t.push("native-artifact"),n.has(e.name)&&t.push("install-script"),(e.consoleScripts==="unknown"||!e.recordKnown)&&t.push("manifest-unreadable"),t}var hh=["sitecustomize","usercustomize"];function gh(e,n,t){let o=new Set,r=[],s=[];for(let a of e.pthFiles){for(let i of a.importModules){let d=No(n,i);for(let p of d)o.add(p.name);let u=$n(t,i);if(u.resolved!==null){s.push(`${a.sitePackages}/${a.name}: \`import ${i}\` runs ${u.resolved.path}`);continue}d.length===0&&r.push(`${a.sitePackages}/${a.name}: \`import ${i}\``)}let l=a.importModules.length;a.importLines>l&&r.push(`${a.sitePackages}/${a.name}: ${String(a.importLines-l)} import line(s) whose module could not be read`)}for(let a of hh){let l=$n(t,a);if(l.resolved===null)continue;let i=No(n,a);for(let d of i)o.add(d.name);i.length===0?r.push(`${l.resolved.path}: \`import ${a}\` runs at every interpreter start`):s.push(`${a}: \`import ${a}\` runs ${l.resolved.path}`)}return{distributions:o,unattributed:r,seen:s}}import{readdirSync as yh,readFileSync as xh}from"node:fs";import Sh from"node:path";var bh=new Set(["summarized","crashed","over-cap"]),kh=new Set(["function","method","ctor"]);function ke(e,n){throw new Error(`summary facts file ${e}: ${n}`)}function is(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Eh(e,n){is(e)||ke(n,"edge is not an object");let{entryPath:t,entryExport:o,entryContainer:r,hops:s}=e;(typeof t!="string"||typeof o!="string")&&ke(n,"edge entry fields must be strings"),r!==null&&typeof r!="string"&&ke(n,"entryContainer must be string or null"),(typeof s!="number"||!Number.isInteger(s)||s<0)&&ke(n,"hops must be a non-negative integer");let a=e.target;if(is(a)||ke(n,"edge target missing"),a.kind==="symbol"){let{exportName:l,container:i,symbolKind:d}=a;return typeof l!="string"&&ke(n,"symbol target exportName"),i!==null&&typeof i!="string"&&ke(n,"symbol target container"),(typeof d!="string"||!kh.has(d))&&ke(n,`symbol target kind ${JSON.stringify(d)}`),{entryPath:t,entryExport:o,entryContainer:r,target:{kind:"symbol",exportName:l,container:i,symbolKind:d},hops:s}}if(a.kind==="dep"){let{calleePackage:l,calleeSubpath:i,calleeExport:d}=a;return(typeof l!="string"||l.length===0)&&ke(n,"dep target calleePackage"),i!==null&&typeof i!="string"&&ke(n,"dep target calleeSubpath"),(typeof d!="string"||d.length===0)&&ke(n,"dep target calleeExport"),{entryPath:t,entryExport:o,entryContainer:r,target:{kind:"dep",calleePackage:l,calleeSubpath:i,calleeExport:d},hops:s}}ke(n,`unknown target kind ${JSON.stringify(a.kind)}`)}function wh(e,n){is(e)||ke(n,"root is not an object");let{packageName:t,analyzedVersion:o,tool:r,toolVersion:s,maxIndirections:a,status:l}=e;(typeof t!="string"||t.length===0)&&ke(n,"packageName"),typeof o!="string"&&ke(n,"analyzedVersion"),r!=="jelly"&&ke(n,`tool ${JSON.stringify(r)} (only 'jelly' exists)`),typeof s!="string"&&ke(n,"toolVersion"),typeof a!="number"&&ke(n,"maxIndirections"),(typeof l!="string"||!bh.has(l))&&ke(n,`status ${JSON.stringify(l)} not in the enum`);let i=e.edges;return Array.isArray(i)||ke(n,"edges is not an array"),l!=="summarized"&&i.length>0&&ke(n,`status='${l}' with edges (CS-W6: edge rows only under summarized)`),{packageName:t,analyzedVersion:o,tool:r,toolVersion:s,maxIndirections:a,status:l,edges:i.map(d=>Eh(d,n))}}function Ml(e){let n=new Map,t=yh(e).filter(o=>o.endsWith(".summary.json"));for(let o of t){let r=Sh.join(e,o),s;try{s=JSON.parse(xh(r,"utf8"))}catch(i){ke(o,`unparseable JSON: ${i instanceof Error?i.message:String(i)}`)}let a=wh(s,o),l=n.get(a.packageName);l===void 0?n.set(a.packageName,[a]):l.push(a)}return n}import{isBuiltin as Tl}from"node:module";function W(e){let n="";for(let t of e){let o=t.charCodeAt(0),r=o<32||o>=127&&o<=159;n+=r?"\\x"+o.toString(16).padStart(2,"0"):t}return n}var Dl=1024,Ll=4096,Co=8,Fl=512,jl=512,as=8,vh=160,Ih=new Set(["unresolved-specifier","declaration-shadow","unresolved-reexport","unanalyzable-module"]),ls=new Set(["limit-exceeded","parse-error","unsupported-syntax"]),Ah=/^(@[^/@\s]+\/)?[^/@\s.][^/\s]*$/u,_h=/\.[cm]?[jt]sx?$/u;function Bl(e,n){let t=n.get(e);if(t!==void 0)return t.packageName;let o=e.lastIndexOf("node_modules/");if(o!==-1){let r=e.slice(o+13).split("/"),s=r[0]??"";return s.startsWith("@")?r[1]===void 0?null:`${s}/${r[1]}`:s===""?null:s}return Ah.test(e)&&!_h.test(e)?e:null}function Nh(e){return W(`${e.code} ${e.path}: ${e.detail}`.slice(0,vh))}function Kl(e){let{graph:n,facts:t,diagnostics:o}=e,r=new Map(n.modules.map($=>[$.id,$])),s=new Map(n.modules.map($=>[$.path,$])),a=ln(n),l=new Set;for(let $ of a){let Z=r.get($);Z!==void 0&&l.add(Z.packageName)}let i=new Map,d=0,u=!1,p=!1,f=$=>$.startsWith(`${e.appRootReal}/`)?$.slice(e.appRootReal.length+1):$;for(let $ of o){if($.code==="limit-exceeded"&&$.path===e.appRootReal){u=!0;continue}let Z=Bl(f($.path),s);if(Z===null){$.code==="out-of-root"&&d++,ls.has($.code)&&(p=!0);continue}let Q=s.get(f($.path));Q!==void 0&&ls.has($.code)&&!Q.path.includes("node_modules/")&&(p=!0);let ce=i.get(Z);ce===void 0?i.set(Z,[$]):ce.push($)}let m=new Map(n.imports.map($=>[$.id,$])),g=new Set;for(let $ of n.importEdges){let Z=m.get($.importId);Z!==void 0&&r.get(Z.moduleId)?.externalSurface===!0&&g.add(Z.moduleId)}let y=[],b=new Set,x=n.modules.filter($=>$.externalSurface===!0);for(let $ of x){let Z=i.get($.packageName)??[],Q=g.has($.id),ce=[],Mn=se=>se.code==="dependency-body"&&se.anchor===void 0&&/syntax/u.test(se.detail),Yn=se=>se.code==="loader-escape"||se.code==="dependency-body"&&se.anchor===void 0&&!/syntax/u.test(se.detail),R=Z.filter(se=>Ih.has(se.code)),M=Z.filter(Yn),B=Z.filter(se=>ls.has(se.code)||Mn(se)),q=Z.filter(se=>se.code==="out-of-root"),le=Q&&R.length===0,ge=M.length===0,Te=!u&&B.length===0,Ze=d===0&&q.length===0;Q||ce.push("(a) the package's entry was never followed to a module");for(let se of[...R,...M,...B,...q]){if(ce.length>=as)break;ce.push(Nh(se))}u&&ce.length<as&&ce.push("(c) the dependency module closure hit its cap \u2014 every follow is truncated"),d>0&&ce.length<as&&ce.push(`(d) ${String(d)} out-of-root diagnostic(s) no package can be read from`);let L=["a","b","c","d"].filter(se=>!{a:le,b:ge,c:Te,d:Ze}[se]),oe=L.length===0;oe&&b.add($.id),y.push({packageName:W($.packageName),module:W(String($.id)),inReach:a.has($.id),builtin:Tl($.packageName),followed:Q,d1:{a:le,b:ge,c:Te,d:Ze},failing:L,transparent:oe,evidence:ce})}let I=new Set;for(let $ of t)$.reach.kind==="unbounded"&&I.add($.source);let w=$=>({module:W(String($.module)),kind:$.kind,packageName:r.get($.module)?.packageName??null}),A=new Set(x.filter($=>Tl($.packageName)).map($=>$.id)),k=new Set([...b,...A]),h=[],S=new Map,_=0,P=0,v=0,T=0,N=[],j=new Set;for(let $ of t)$.reach.kind==="unbounded"&&j.add($.cause);for(let $ of t){if($.reach.kind==="class-scope"){N.push({packageName:$.reach.packageName,container:$.reach.container});continue}if($.reach.kind==="unbounded")continue;T++;let Z=$.reach.anchor,Q=S.get(String(Z));Q===void 0&&(Q={today:yt(n,Z,I),d1:yt(n,Z,I,b),d1Builtins:yt(n,Z,I,k)},S.set(String(Z),Q)),Q.d1Builtins.length>0&&v++,Q.today.length>0&&(_++,j.add($.cause)),Q.d1.length>0&&P++,h.length<Ll&&h.push({anchor:W(String(Z)),packageName:W(r.get(Z)?.packageName??""),cause:$.cause,reachKind:$.reach.kind,blockersToday:Q.today.slice(0,Co).map(w),blockersUnderD1:Q.d1.slice(0,Co).map(w),blockedUnderD1Builtins:Q.d1Builtins.length>0,moreToday:Math.max(0,Q.today.length-Co),moreUnderD1:Math.max(0,Q.d1.length-Co)})}let O=o.filter($=>$.anchor===void 0&&$.classScope===void 0),F=new Map(e.loadSites.map($=>[$.importId,$])),K=new Map;for(let $ of e.loadSites){let Z=K.get($.path);Z===void 0?K.set($.path,[$.shape]):Z.push($.shape)}let te=$=>{if($.code!=="loader-escape")return!1;let Z=$.escapes??[];if(Z.length===0||Z.some(ce=>ce!=="non-literal-load"))return!1;let Q=K.get($.path)??[];return Q.length>0&&Q.every(ce=>ce==="relative-bounded")},U=O.slice(0,jl).map($=>({cause:e.causeOf($.code),code:$.code,path:W(f($.path)),attributedPackage:Bl(f($.path),s),...$.escapes!==void 0?{escapes:[...$.escapes]}:{},...$.reason!==void 0?{reason:$.reason}:{},d2Dischargeable:te($)})),X={};for(let $ of O){if($.code!=="unresolved-specifier")continue;let Z=$.reason??"(none)";X[Z]=(X[Z]??0)+1}let D=I.size===0?0:t.filter($=>$.reach.kind==="unbounded").length,C=Math.max(0,D-O.length),H=D-O.filter(te).length,J=[],G=0,Y=0,re=0;for(let $ of n.imports){if($.specifierIsLiteral)continue;re++;let Z=a.has($.moduleId),Q=F.get(String($.id)),ce=Q?.shape??"unrecorded";Z&&(G++,ce==="relative-bounded"&&Y++),J.length<Fl&&J.push({importId:W(String($.id)),path:W(r.get($.moduleId)?.path??""),shape:ce,text:W(Q?.text??""),inReach:Z})}return{report:{adr:"ADR-105",aborted:e.analysisAborted,rootBudget:e.rootBudget,closureCapHit:u,appCapHit:p,unattributedOutOfRoot:d,blindUnbounded:C,unbounded:U,anchors:h,surfaces:y.slice(0,Dl),loads:J,counts:{modules:n.modules.length,reachMods:a.size,surfaces:x.length,surfacesInReach:y.filter($=>$.inReach).length,transparentSurfaces:b.size,builtinSurfaces:A.size,anchors:T,anchorsBlockedToday:_,anchorsBlockedUnderD1:P,anchorsBlockedUnderD1Builtins:v,unbounded:D,loadsInReach:G,loadsRelativeBounded:Y,unresolvedByReason:X,conditionUnions:e.conditionUnions.length,provenAbsent:e.provenAbsent.length},truncated:{surfaces:Math.max(0,y.length-Dl),anchors:Math.max(0,T-Ll),loads:Math.max(0,re-Fl),unbounded:Math.max(0,O.length-jl)}},reachedPackages:l,aborted:e.analysisAborted,unboundedFacts:D,unboundedHard:H,anchorsBlockedToday:_,anchorsBlockedUnderD1:P,anchorsBlockedUnderD1Builtins:v,loadsInReach:G,loadsAllBounded:G>0&&Y===G,d2Eligible:e.rootBudget==="complete"&&!p&&!u,classScope:N,taintCausesToday:j}}var Rh=new Set(["unverified-symbol","db-gap","symbol-unsupported","incomplete-surface"]),Ph=["no-entrypoint","dynamic-load","resolution-divergence","analysis-cap","dep-opaque"];function Ul(e,n,t,o,r){if(t===null||e.reachedPackages.has(t.packageName))return;let s=e.classScope.some(_=>_.packageName===t.packageName&&_.container===t.container),a=e.aborted!==null||e.unboundedFacts>0||e.anchorsBlockedToday>0||s,l=t.symbolKind==="method"||t.symbolKind==="ctor",d=!t.verified||t.symbolKind==="accessor"||t.symbolKind==="pattern"||l||n.unknownKind!==void 0&&Rh.has(n.unknownKind)?"pre-2b":n.tier==="not-reachable"?"denial":e.loadsInReach>0?"load":a?"taint":o>0?"oog":"unexpected",u=new Set(e.taintCausesToday);s&&u.add("dep-opaque");let p=e.aborted!==null?e.aborted:Ph.find(_=>u.has(_)),f=d==="pre-2b"?n.tier==="unknown"&&(l?n.unknownKind==="dep-opaque":!0):d==="denial"?n.tier==="not-reachable":d==="load"?n.tier==="unknown"&&n.unknownKind==="dynamic-load":d==="taint"?n.tier==="unknown"&&n.unknownKind===p:d==="oog"?n.tier==="unknown"&&n.unknownKind==="analysis-cap":!1,m=t.verified&&r===!0,g=e.aborted===null&&e.unboundedFacts===0&&!s&&o===0,y=e.loadsInReach===0||e.d2Eligible&&e.loadsAllBounded,b=m&&d==="taint"&&g&&e.loadsInReach===0&&e.anchorsBlockedUnderD1===0,x=m&&d==="load"&&g&&e.d2Eligible&&e.loadsAllBounded&&e.anchorsBlockedToday===0,I=m&&(d==="load"||d==="taint")&&g&&y&&e.anchorsBlockedUnderD1===0,w=e.aborted===null&&e.unboundedHard===0&&!s&&o===0,A=m&&d==="load"&&w&&e.d2Eligible&&e.loadsAllBounded&&e.anchorsBlockedToday===0,k=m&&(d==="load"||d==="taint")&&w&&y&&e.anchorsBlockedUnderD1===0,h=m&&d==="taint"&&g&&e.loadsInReach===0&&e.anchorsBlockedUnderD1Builtins===0,S=m&&(d==="load"||d==="taint")&&w&&y&&e.anchorsBlockedUnderD1Builtins===0;return{unloaded:!0,exit:d,agrees:f,verified:t.verified,surfaceComplete:r,oog:o,classScoped:s,predicted:{d1:b,d2:x,d1d2:I,d2Amended:A,d1d2Amended:k,d1Builtins:h,d1d2AmendedBuiltins:S}}}import{readFileSync as $h,statSync as Oh}from"node:fs";var cs=/^(@[A-Za-z0-9_.-]{1,100}\/)?[A-Za-z0-9_.-]{1,100}$/u,Mo=/^[A-Za-z0-9_$.-]{1,128}$/u,zl=64,Wl=1024*1024,Vl=/^(0|\d{1,10}\.\d{1,10}\.\d{1,10})$/u,ql=/^[A-Za-z0-9@_.-]{1,128}$/u;function ve(e){throw new Error(`model claims rejected: ${e}`)}function ds(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ch(e,n){ds(e)||ve(`${n}: edge is not an object`);let{kind:t,anchorExport:o,anchorContainer:r,calleePackage:s,calleeContainer:a,calleeExport:l}=e;return t!=="alias"&&t!=="dispatch"&&ve(`${n}: edge kind`),(typeof o!="string"||!Mo.test(o))&&ve(`${n}: anchorExport ${JSON.stringify(o)}`),r!==null&&(typeof r!="string"||!Mo.test(r))&&ve(`${n}: anchorContainer`),(typeof s!="string"||!cs.test(s))&&ve(`${n}: calleePackage ${JSON.stringify(s)}`),a!==null&&(typeof a!="string"||!Mo.test(a))&&ve(`${n}: calleeContainer`),(typeof l!="string"||!Mo.test(l))&&ve(`${n}: calleeExport ${JSON.stringify(l)}`),{kind:t,anchorExport:o,anchorContainer:r,calleePackage:s,calleeContainer:a,calleeExport:l}}function Gl(e){let n=Oh(e).size;n>Wl&&ve(`file is ${String(n)} bytes, over the ${String(Wl)} cap`);let t;try{t=JSON.parse($h(e,"utf8"))}catch(r){ve(`unparseable JSON: ${r instanceof Error?r.message:String(r)}`)}Array.isArray(t)||ve("root is not an array"),t.length>zl&&ve(`${String(t.length)} claims over cap ${String(zl)}`);let o=[];for(let r of t){ds(r)||ve("claim is not an object");let{packageName:s,modelId:a,range:l,edges:i}=r;(typeof s!="string"||!cs.test(s))&&ve("packageName"),(typeof a!="string"||!ql.test(a))&&ve("modelId (identifier charset, 1-128 chars)"),o.some(u=>u.model.modelId===a)&&ve(`duplicate modelId ${a} \u2014 the V5 promote\u2192claim join must be unambiguous`),(!ds(l)||typeof l.introduced!="string")&&ve(`${a}: range`),Vl.test(l.introduced)||ve(`${a}: range.introduced ${JSON.stringify(l.introduced)} is not '0' or an exact x.y.z triple`);let d=l.fixedBefore;d!==null&&typeof d!="string"&&ve(`${a}: fixedBefore`),typeof d=="string"&&!Vl.test(d)&&ve(`${a}: range.fixedBefore ${JSON.stringify(d)} is not an exact x.y.z triple`),Array.isArray(i)||ve(`${a}: edges`),i.length>64&&ve(`${a}: ${String(i.length)} edges over cap ${String(64)}`),o.push({model:{packageName:s,modelId:a,edges:i.map(u=>Ch(u,a))},introduced:l.introduced,fixedBefore:d})}return o}var Mh=["in-app-purchase@1-v1"];function us(e,n,t){let o=[],r=[],s=[],a=(l,i,d,u)=>{r.push(d),s.push({modelId:u??l.model.modelId,status:i,reason:d,edgeCount:l.model.edges.length})};for(let l of e){if(!cs.test(l.model.packageName)||!ql.test(l.model.modelId)){a(l,"refused","model (unprintable id): hostile-shaped packageName/modelId \u2014 refused WHOLE","(unprintable id)");continue}if(t?.shadowConsultDenylisted!==!0&&Mh.includes(l.model.modelId)){a(l,"denylisted",`model ${l.model.modelId}: DENYLISTED (ADR-081 F-081-A a-prime) \u2014 dropped, never consulted`);continue}if(l.model.edges.some(u=>u.kind!=="alias"&&u.kind!=="dispatch")){a(l,"refused",`model ${l.model.modelId}: unknown edge kind \u2014 refused WHOLE`);continue}let i=n(l.model.packageName);if(typeof i!="string"&&i!==void 0){a(l,"inert",`model ${l.model.modelId}: anchor ${l.model.packageName} installed at more than one version (${i.join(", ")}) \u2014 inert, never guessed (ADR-071)`);continue}if(i===void 0){a(l,"inert",`model ${l.model.modelId}: anchor ${l.model.packageName} not installed \u2014 inert`);continue}let d;try{d=Ln(i,{advisoryId:l.model.modelId,packageName:l.model.packageName,introduced:l.introduced,...l.fixedBefore!==null?{fixed:l.fixedBefore}:{},surfaceComplete:!1})}catch{a(l,"inert",`model ${l.model.modelId}: installed ${l.model.packageName}@${i} not an exact triple \u2014 inert (never guessed)`);continue}if(!d){a(l,"inert",`model ${l.model.modelId}: installed ${l.model.packageName}@${i} outside [${l.introduced}, ${l.fixedBefore??"\u221E"}) \u2014 inert`);continue}o.push(l.model),s.push({modelId:l.model.modelId,status:"active",reason:null,edgeCount:l.model.edges.length})}return{models:o,notes:r,dispositions:s}}var Dh=4,Lh={additiveForms:!0,namelessExports:!0},Fh=new Set(["dep-opaque","dynamic-load","dispatch"]),jh={base:new Set(["symbol-reachable"]),widened:new Set(["symbol-reachable","call-path-confirmed"])};function ms(e,n,t){return e.tier==="unknown"&&jh[t].has(e.decidedAtStage)&&e.unknownKind!==void 0&&Fh.has(e.unknownKind)&&n!==null&&n.verified}var Bh=()=>({"not-affected":0,"not-reachable":0,"reachable-high":0,"reachable-medium":0,"reachable-low":0,unknown:0}),an=class extends Error{},hs="cupel/coverage-gap",nd={"loader-escape":"dynamic-load","out-of-root":"resolution-divergence","unresolved-specifier":"resolution-divergence","declaration-shadow":"resolution-divergence","unanalyzable-module":"resolution-divergence","unresolved-reexport":"resolution-divergence","limit-exceeded":"analysis-cap","parse-error":"analysis-cap","unsupported-syntax":"analysis-cap","unresolved-launch-entry":"analysis-cap","unresolved-entry-declaration":"analysis-cap","framework-derived-entry":"analysis-cap","unanalyzed-project-root":"no-entrypoint","dependency-body":"dep-opaque","dep-class-corridor":"dep-opaque"};function zt(e,n,t){return{advisoryId:e,packageName:n,...t.ecosystem==="PyPI"?{ecosystem:"PyPI"}:{},introduced:t.introduced??"0",...t.fixed!==null?{fixed:t.fixed}:{},...t.lastAffected!==null?{lastAffected:t.lastAffected}:{},surfaceComplete:t.surfaceComplete===1}}function Zl(e,n){return e===0?"no-entrypoint":n.modules.length===0?"analyzer-crash":null}function Ql(e,n,t){let o=new Map(e.modules.map(a=>[a.path,a.id])),r=e.modules[0]?.id;if(r===void 0)return[];let s=n.map(a=>({source:o.get(a.path)??r,cause:nd[a.code],reach:a.classScope!==void 0?{kind:"class-scope",packageName:a.classScope.packageName,container:a.classScope.container}:a.anchor!==void 0?{kind:"via-module",anchor:a.anchor}:{kind:"unbounded"}}));for(let a of t)s.push({source:r,reach:{kind:"unbounded"},cause:a});return s}function fs(e,n,t,o,r){let s=t.filter(a=>a.exportName!==null&&(o===1||r||a.verified!==1));return s.length>0?s.map(a=>({advisoryId:e,packageName:n,exportName:a.exportName??"",container:a.container,symbolKind:a.symbolKind,sourcePath:a.sourcePath??"",derivation:a.derivation,confidence:a.confidence,verified:a.verified===1})):t.length===0||t.every(a=>a.exportName!==null&&a.verified===1)?[null]:[]}function Kh(e,n){let t;try{t=Wt(e)}catch{return!0}let o=3,r=(s,a)=>{if(a>o)return!1;let l;try{l=ed(s)}catch{return!1}for(let i of l){if(i==="node_modules"||i.startsWith("."))continue;let d=mn.join(s,i),u;try{u=ps(d)}catch{continue}if(!u.isDirectory())continue;let p=mn.relative(t,d).split(mn.sep).join("/");try{if(ps(mn.join(d,"package.json")).isFile()&&!n.has(p))return!0}catch{}if(r(d,a+1))return!0}return!1};return r(t,1)}function Uh(e,n){let t="";for(let o of e)o.rel!==""&&n.startsWith(`${o.rel}/`)&&o.rel.length>t.length&&(t=o.rel);return t}function zh(e,n,t){let o=[];if(t&&o.push("nested-app-root"),n==="")return[...o,"manifest-unreadable"];let r;try{if(r=Wt(mn.resolve(e,n)),!r.startsWith(Wt(e)+mn.sep))return[...o,"manifest-unreadable"]}catch{return[...o,"manifest-unreadable"]}let s;try{let u=mn.join(r,"package.json");if(!ps(u).isFile())return[...o,"manifest-unreadable"];s=Th(u,"utf8")}catch{return[...o,"manifest-unreadable"]}let a;try{a=JSON.parse(s)}catch{return[...o,"manifest-unreadable"]}if(typeof a!="object"||a===null)return[...o,"manifest-unreadable"];let l=a;(typeof l.bin=="string"||typeof l.bin=="object"&&l.bin!==null)&&o.push("bin");let i=["preinstall","install","postinstall","prepare","prepublish"],d=l.scripts;if(typeof d=="object"&&d!==null){let u=d;i.some(p=>typeof u[p]=="string")&&o.push("install-script")}return(l.gypfile===!0||Wh(r))&&o.push("native-artifact"),o}function Wh(e){for(let n of["","build/Release","build/Debug","prebuilds","lib/binding"]){let t=mn.join(e,n),o;try{o=ed(t)}catch{continue}if(o.some(r=>r.endsWith(".node")))return!0}return!1}function Vh(e,n){let t=new Set(["npm",...n.ecosystems?.()??[]]),o=[];for(let r of e.perRoot){let s=new Map;for(let a of r.packages){let l=a.ecosystem??"npm";t.has(l)||s.set(l,(s.get(l)??0)+1)}for(let[a,l]of[...s.entries()].sort())o.push({kind:"ecosystem-uncovered",detail:`${r.rootRel===""?"":`${r.rootRel}: `}${String(l)} ${a} distribution(s) were enumerated but the loaded shard carries no ${a} advisories: they were NOT assessed, so this is not a clean bill of health for them. Scan with a ${a} shard to assess them (ADR-109 D5).`,blindsAnalysis:!1,rootRel:r.rootRel})}return o}function td(e){return JSON.stringify([e.ecosystem??"npm",e.name,e.version,e.lockKey])}function qh(e,n,t){return new Map(n.map(o=>[td(o),zh(e,o.lockKey,t)]))}function Gh(e){let n=new Map;for(let t of e){let o=n.get(t.advisory.id);o===void 0?n.set(t.advisory.id,[t]):o.push(t)}return n}function Hh(e,n,t){return n.symbolsDecidable||e.tier!=="not-reachable"||!n.graph.modules.some(r=>r.packageName===t.name)?e:{...e,tier:"unknown",reason:`${t.name} is loaded, and cupel does not yet follow calls in this ecosystem's code \u2014 "no call path found" here is a property of the analysis, not of the application`,unknownKind:"symbol-unsupported",basis:void 0,path:void 0}}function Xh(e,n,t,o,r,s,a){let{finding:l}=Ut(e,n,{name:t.name,version:t.version,...t.ecosystem!==void 0?{ecosystem:t.ecosystem}:{},devOnly:t.dev,outOfGraphExecution:a(t)},zt(o.advisory.id,t.name,o.affected),null,r,s);return l.decidedAtStage!=="presence"&&l.decidedAtStage!=="version-match"}function Ut(e,n,t,o,r,s,a){let l=Jo({graph:e,installed:t,range:o,symbol:r,coverage:null,incompleteness:s,analysisAborted:a});if(n!==null&&r!==null&&ms(l,r,"base")){let i=xt(e,n.modulesById,n.reachMods,r,n.records);if(i!==null)return{finding:l,hit:i}}return{finding:l,hit:null}}function Yh(e,n){let t=new Set,o=[];for(let r of e.packages)if((r.ecosystem??"npm")==="npm")for(let{advisory:s,affected:a}of n.advisoriesForPackage(r.ecosystem??"npm",r.name)){let l=zt(s.id,r.name,a),i;try{i=Ln(r.version,l)}catch{continue}if(i)for(let d of n.symbolsForAffected(a.id)){if(d.verified!==1||d.symbolKind!=="method"&&d.symbolKind!=="ctor"||d.container===null||d.sourcePath===null)continue;let u=`${r.lockKey}\0${d.container}\0${d.sourcePath}`;t.has(u)||(t.add(u),o.push({packageName:r.name,packageRootRel:r.lockKey,container:d.container,sourcePath:d.sourcePath}))}}return o.sort((r,s)=>`${r.packageRootRel}\0${r.container}\0${r.sourcePath}`.localeCompare(`${s.packageRootRel}\0${s.container}\0${s.sourcePath}`)),o.slice(0,yo)}function Jh(e,n,t){let o=new Map(e.functions.map(l=>[l.id,l])),r=new Map(e.classes.map(l=>[l.id,l.name])),s=new Map(e.callSites.map(l=>[l.id,l])),a=[];for(let l of e.callEdges){if(l.resolution!=="resolved"&&l.resolution!=="field-based")continue;let i=s.get(l.callSiteId);if(i===void 0)continue;let d=o.get(i.enclosingFunctionId);if(d===void 0||!t.has(d.moduleId))continue;let u=n.get(d.moduleId);if(u===void 0)continue;let p=o.get(l.calleeFunctionId);if(p===void 0||p.name===void 0)continue;let f=n.get(p.moduleId);f!==void 0&&f.packageName!==u.packageName&&a.push({packageName:f.packageName,exportName:p.name,container:p.enclosingClassId!==void 0?r.get(p.enclosingClassId)??null:null,resolution:l.resolution,callerFunctionId:d.id})}return a}function Zh(e){let n=new Set(e.modules.filter(u=>u.isEntrypoint).map(u=>u.id)),t=new Map(e.modules.map(u=>[u.id,u])),o=new Map(e.functions.map(u=>[u.id,u])),r=new Set;for(let u of e.functions)n.has(u.moduleId)&&(u.publicSurfaceReachable||u.name==="<toplevel>")&&r.add(u.id);let s=new Map(e.exports.map(u=>[u.id,u]));for(let u of e.exportBindings){if(u.target.kind!=="function")continue;let p=s.get(u.exportId);if(p===void 0||!n.has(p.moduleId))continue;let f=o.get(u.target.functionId);f===void 0||t.get(f.moduleId)?.externalSurface===!0||r.add(f.id)}let a=new Map(e.callSites.map(u=>[u.id,u.enclosingFunctionId])),l=new Map;for(let u of e.callEdges){if(u.resolution!=="resolved"&&u.resolution!=="field-based")continue;let p=a.get(u.callSiteId);if(p===void 0)continue;let f=l.get(p);f===void 0?l.set(p,[u.calleeFunctionId]):f.push(u.calleeFunctionId)}let i=new Set(r),d=[...r];for(;d.length>0;){let u=d.pop();if(u!==void 0)for(let p of l.get(u)??[])i.has(p)||(i.add(p),d.push(p))}return i}function Qh(e,n,t,o){for(let r of n){if(r.modelId!==e.modelId||r.anchor.packageName!==e.anchorPackage||r.anchor.exportName!==e.entryExport)continue;let s=t.filter(l=>l.packageName===r.anchor.packageName&&l.exportName===r.anchor.exportName&&l.container===r.anchor.container),a=s.find(l=>l.resolution==="resolved")??s[0];if(a!==void 0)return o.has(a.callerFunctionId)}return null}function eg(e,n,t){if(t===void 0||t===!1)return!1;if(t===!0||t==="all")return n>0||e.some(s=>s.modelId!==void 0);let o=new Set(t),r=s=>o.has(s)||o.has(Ve[s]??"");return e.some(s=>s.tier==="unknown"&&s.unknownKind!==void 0&&r(s.unknownKind)||s.modelPromotedFromKind!==void 0&&r(s.modelPromotedFromKind))}function gs(e){let n=Wt(e.dir),t=e.reader??(e.shardPathPypi!==void 0?er([St(e.shardPath),St(e.shardPathPypi)]):St(e.shardPath)),o=e.partialRows===!0;try{if(!/^\d+$/u.test(t.schemaVersion)||Number(t.schemaVersion)>Number(Fn))throw new an(`shard schema ${JSON.stringify(t.schemaVersion)} is unreadable or newer than this cupel understands (v${Fn})`);let r=null;if(e.summaryShadow!==void 0)try{r=Ml(e.summaryShadow)}catch(L){throw new an(`--summary-shadow facts dir rejected: ${L instanceof Error?L.message:String(L)}`)}let s=null;if(e.modelShadow!==void 0)try{s=Gl(e.modelShadow.claimsPath)}catch(L){throw new an(`--model-shadow claims rejected: ${L instanceof Error?L.message:String(L)}`)}let a=Wr(n,{...e.rootDiscovery,...e.root!==void 0?{operatorRoots:e.root}:{}}),l=fl(n,a,e.installedSet);if(l.truncated){let L=l.perRoot.filter(oe=>oe.truncated).map(oe=>oe.rootRel===""?"the scan root":`\`${oe.rootRel}\``);throw new an(`the dependency enumeration hit a hard cap and is incomplete at ${L.length>0?L.join(", "):"the union across roots"} (${l.diagnostics.join("; ")}) \u2014 refusing to report a partial (possibly false-clean) scan`)}let i=Cl(a.roots),d=i?.execution??null,u=ml(l.packages.filter(L=>(L.ecosystem??"npm")==="npm")),p=e.entry??[],f=p.length>0?Ia(n,p):{entrypoints:[],rejected:[]},m=f.rejected,g=va(n,a.roots),y=[...new Set([...g.entrypoints,...f.entrypoints])],b=[...g.sources];for(let L of f.entrypoints)g.entrypoints.includes(L)||b.push({source:"--entry",specifier:L,entrypoint:L,launch:!1,root:Uh(a.roots,L)});let x=[...b];for(let L of i?.roots??[])for(let oe of L.entrypoints)b.push({source:`python:${oe.source}`,specifier:oe.declaration,entrypoint:L.rootRel===""?oe.file:`${L.rootRel}/${oe.file}`,launch:oe.source==="console-script"||oe.source==="launch-declaration",root:L.rootRel});let I=Yh(l,t),w=e.bindingForms??Lh,A=e.callablePackageResolver===!0,k=e.tsconfigPaths!==!1,h=Kh(n,Lt(b)),S=qh(n,l.packages,h),_=L=>(L.ecosystem??"npm")!=="npm"?d?.get(L.name)??["manifest-unreadable"]:S.get(td(L))??["manifest-unreadable"],P=Tr({appRoot:n,entrypoints:y,depClassAnchors:I,bindingForms:w,callablePackageResolver:A,tsconfigPaths:k}),v=P.graph,T=Yo(v),N=[...g.diagnostics,...Dr(g),...Lr(g,y.length),...Yr(a,x),...P.diagnostics],j=Zl(y.length,v),O=L=>l.packages.some(oe=>(oe.ecosystem??"npm")===L),F=i===null?"no-entrypoint":i.analysisAborted,K=(O("npm")?j:null)??(O("PyPI")?F:null)??(O("npm")||O("PyPI")?null:j),te=[...l.gaps,...hl(a),...Vh(l,t)],U=gl(te),X=Ql(v,N,U),D={graph:Kt,incompleteness:[],analysisAborted:"no-entrypoint",symbolsDecidable:!1},C=L=>(L.ecosystem??"npm")==="npm"?{graph:v,incompleteness:X,analysisAborted:j,symbolsDecidable:!0}:i===null?D:{...i,symbolsDecidable:!0},H=n;try{H=Wt(n)}catch{}let J=Kl({graph:v,facts:X,diagnostics:N,analysisAborted:j,loadSites:P.loadSites,conditionUnions:P.conditionUnions,provenAbsent:P.provenAbsent,appRootReal:H,rootBudget:a.budget,causeOf:L=>nd[L]}),G=t.allModels?.()??[],Y=us(G.map(L=>({model:{packageName:L.packageName,modelId:L.modelId,edges:L.edges},introduced:L.introduced,fixedBefore:L.fixedBefore})),u),re=Y.models.length>0?_t(v,Y.models).delta:null,ne=re!==null?{records:re.records,reachMods:ln(v),modulesById:new Map(v.modules.map(L=>[L.id,L]))}:null,$=[],Z=new Map,Q=Bh(),ce=[],Mn=[];for(let L of l.packages){let oe=C(L),se=(L.ecosystem??"npm")==="npm"?ne:null;for(let[,Ie]of Gh(t.advisoriesForPackage(L.ecosystem??"npm",L.name))){let Ne=Ie[0];if(Ne!==void 0){let xe=Z.get(Ne.advisory.id),en=Ie.map(De=>De.affected);xe===void 0?Z.set(Ne.advisory.id,{advisory:Ne.advisory,ranges:en}):xe.ranges.push(...en)}let pe=Ie.filter(xe=>Xh(oe.graph,se,L,xe,oe.incompleteness,oe.analysisAborted,_)),Qe=pe.length>0?pe:Ie.slice(0,1),hn=pe.length===0;for(let{advisory:xe,affected:en}of Qe){let De=zt(xe.id,L.name,en),gn=xe.cveId??xe.id,Tn=hn?[]:t.symbolsForAffected(en.id),mt=Tn.filter(ye=>ye.exportName===null),yn=fs(xe.id,L.name,Tn,en.surfaceComplete,o),xn=Ut(oe.graph,se,{name:L.name,version:L.version,...L.ecosystem!==void 0?{ecosystem:L.ecosystem}:{},devOnly:L.dev,outOfGraphExecution:_(L)},De,null,oe.incompleteness,oe.analysisAborted).finding;if(xn.decidedAtStage==="presence"||xn.decidedAtStage==="version-match"){Q[xn.tier]+=1,$.push({...xn,modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:De.surfaceComplete,advisoryId:xe.id,displayId:gn,packageName:L.name,version:L.version,ecosystem:L.ecosystem??"npm",symbolName:null,symbolPath:null,severity:xe.severity,packageLocation:Ro(l,L)});continue}for(let ye of yn){let{finding:nn,hit:We}=Ut(oe.graph,se,{name:L.name,version:L.version,...L.ecosystem!==void 0?{ecosystem:L.ecosystem}:{},devOnly:L.dev,outOfGraphExecution:_(L)},De,ye,oe.incompleteness,oe.analysisAborted),z=Hh(nn,oe,L),ee,de;We!==null&&ye!==null&&(ee=We.modelId,de=nn.unknownKind,z={basis:void 0,tier:We.tier,decidedAtStage:nn.decidedAtStage,reason:`boundary model ${We.modelId}: ${We.anchorPackage}.${We.entryExport} reaches ${ye.exportName} [${We.pathLabels.join(" \u2192 ")}]`,unknownKind:void 0,attribution:no(ye),path:void 0,unresolvedSites:nn.unresolvedSites,unresolvedEvidence:nn.unresolvedEvidence}),Q[z.tier]+=1;let Re=Ul(J,z,ye,_(L).length,De.surfaceComplete),fe={...z,...Re!==void 0?{adr105:Re}:{},modelId:ee,modelPromotedFromKind:de,surfaceComplete:De.surfaceComplete,advisoryId:xe.id,displayId:gn,packageName:L.name,version:L.version,ecosystem:L.ecosystem??"npm",symbolName:ye?.exportName??null,symbolPath:ye?.sourcePath||null,severity:xe.severity,packageLocation:Ro(l,L)};$.push(fe);let ue=new Set(["dep-opaque","dynamic-load","dispatch"]);r!==null&&fe.tier==="unknown"&&fe.decidedAtStage==="symbol-reachable"&&fe.unknownKind!==void 0&&ue.has(fe.unknownKind)&&ye!==null&&ce.push({finding:fe,symbol:ye}),s!==null&&fe.tier==="unknown"&&ye!==null&&Mn.push({finding:fe,symbol:ye})}for(let ye of mt)Q.unknown+=1,$.push({modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:De.surfaceComplete,tier:"unknown",decidedAtStage:"symbol-reachable",reason:`advisory ${gn} carries a ${ye.symbolKind} pattern symbol; pattern matching is not evaluated yet`,unknownKind:"symbol-unsupported",attribution:void 0,basis:void 0,path:void 0,unresolvedSites:[],unresolvedEvidence:{own:[],sets:[]},advisoryId:xe.id,displayId:gn,packageName:L.name,version:L.version,ecosystem:L.ecosystem??"npm",symbolName:null,symbolPath:null,severity:xe.severity,packageLocation:Ro(l,L)})}}}for(let L of te)Q.unknown+=1,$.push({modelId:void 0,modelPromotedFromKind:void 0,surfaceComplete:void 0,tier:"unknown",decidedAtStage:"presence",reason:L.detail,attribution:void 0,basis:void 0,path:void 0,unresolvedSites:[],unresolvedEvidence:{own:[],sets:[]},advisoryId:hs,displayId:hs,packageName:L.kind,version:"",ecosystem:"npm",symbolName:null,symbolPath:null,severity:null,unknownKind:"coverage-gap",packageLocation:pl(l,L)});let Yn=Q["reachable-high"]+Q["reachable-medium"],R=e.failOnReachable===!0&&Yn>0,M=eg($,Q.unknown,e.failOnUnknown),B=e.requireCompleteDenial===!0&&$.some(L=>L.tier==="not-reachable"&&L.basis==="loader-assumption"),q=R||M||B?2:0,le;if(r!==null){let L=ln(v),oe=new Map(v.modules.map(Ie=>[Ie.id,Ie])),se=[];for(let{finding:Ie,symbol:Ne}of ce){let pe=Ho(v,oe,L,Ne,r,Dh);se.push({advisoryId:Ie.advisoryId,packageName:Ie.packageName,symbolName:Ie.symbolName,unknownKind:Ie.unknownKind??null,wouldPromote:pe!==null,...pe!==null?{anchorPackage:pe.anchorPackage,entryExport:pe.entryExport,viaPackages:pe.viaPackages,totalHops:pe.totalHops}:{}})}le={records:se}}let ge;if(s!==null&&e.modelShadow!==void 0){let L=e.modelShadow.widened===!0?"widened":"base",{models:oe,notes:se,dispositions:Ie}=us(s,u,{shadowConsultDenylisted:!0}),{delta:Ne}=_t(v,oe),pe=ln(v),Qe=new Map(v.modules.map(z=>[z.id,z])),hn=Jh(v,Qe,pe),xe=Zh(v),en=Ne.records.some(z=>hn.some(ee=>ee.packageName===z.anchor.packageName&&ee.exportName===z.anchor.exportName&&ee.container===z.anchor.container)),De=[],gn=Date.now();for(let{finding:z,symbol:ee}of Mn){let de=Ne.records,Re=ms(z,ee,L),fe=Re?xt(v,Qe,pe,ee,de):null,ue=Ne.records.filter($e=>$e.callee.packageName===ee.packageName&&$e.callee.exportName===ee.exportName&&$e.callee.container===ee.container||$e.callee.packageName===ee.packageName&&$e.callee.realFunctionId!==null);De.push({advisoryId:z.advisoryId,packageName:z.packageName,symbolName:z.symbolName,unknownKind:z.unknownKind??null,decidedAtStage:z.decidedAtStage,consultSurface:L,noHitReason:fe!==null?null:Re?en?"no-key-match-no-continuation":"no-matching-anchor":"not-eligible-base",anchorFunctionEntryReachable:fe!==null?Qh(fe,de,hn,xe):null,verdictBefore:z.tier,verdictAfter:fe!==null?"reachable-low":z.tier,wouldPromote:fe!==null,...fe!==null?{modelId:fe.modelId,anchorPackage:fe.anchorPackage,entryExport:fe.entryExport,pathLabels:fe.pathLabels,calleeBinding:ue.find($e=>$e.callee.realFunctionId!==null)?.callee.realFunctionId??"key:any-installed-in-range-copy"}:Re?ue.length>0?{reason:"model-covers-symbol-but-no-baseline-anchor",nearestBlockedHop:`anchor:${ue[0]?.anchor.packageName??"?"}#${ue[0]?.anchor.exportName??"?"} (no resolved|field-based baseline edge from a reachable module)`}:{reason:"no-model-coverage"}:{}})}let Tn=Date.now()-gn,mt=Ie.map(z=>{if(z.status!=="active")return{modelId:z.modelId,state:z.status,reason:z.reason,edgesLowered:0,edgesReferenceGated:0};let ee=Ne.records.filter(Re=>Re.modelId===z.modelId).length;if(ee>0)return{modelId:z.modelId,state:"lowered",reason:null,edgesLowered:ee,edgesReferenceGated:z.edgeCount-ee};let de=Ne.notes.find(Re=>Re.startsWith(`model ${z.modelId}:`)||Re.startsWith(`model-edge ${z.modelId}:`));return{modelId:z.modelId,state:"refused",reason:de??"refused \u2014 no anchor surface in the graph (all edges reference-gated)",edgesLowered:0,edgesReferenceGated:z.edgeCount}}),yn=De.filter(z=>z.wouldPromote).length,xn=Q.unknown-yn,ye=Q["reachable-high"]+Q["reachable-medium"],nn=z=>({none:0,"fail-on-reachable":ye>0?2:0,"fail-on-unknown":z>0?2:0,both:ye>0||z>0?2:0});ge={records:De,notes:[...se,...Ne.notes],laneStates:mt,exitCodes:{baseline:nn(Q.unknown),withModels:nn(xn)},overlayWallMs:Tn},Xl(mn.dirname(e.modelShadow.outPath),{recursive:!0});let We=`${e.modelShadow.outPath}.tmp-${Hl(8).toString("hex")}`;Jl(We,`${JSON.stringify(ge,null,2)}
|
|
24
|
+
`,{encoding:"utf8",flag:"wx"}),Yl(We,e.modelShadow.outPath)}let Te;if(e.bindingShadow!==void 0){let L=Date.now(),oe=z=>Y.models.length>0?{records:_t(z,Y.models).delta.records,reachMods:ln(z),modulesById:new Map(z.modules.map(ee=>[ee.id,ee]))}:null,se=(z,ee,de,Re)=>{let fe=[];for(let ue of l.packages)for(let{advisory:$e,affected:Dn}of t.advisoriesForPackage(ue.ecosystem??"npm",ue.name)){let Jn=zt($e.id,ue.name,Dn),Yd=fs($e.id,ue.name,t.symbolsForAffected(Dn.id),Dn.surfaceComplete,o);for(let js of Yd){let{finding:Bs,hit:qo}=Ut(z,Re,{name:ue.name,version:ue.version,...ue.ecosystem!==void 0?{ecosystem:ue.ecosystem}:{},devOnly:ue.dev,outOfGraphExecution:_(ue)},Jn,js,ee,de);fe.push({advisoryId:$e.id,packageName:ue.name,symbolName:js?.exportName??null,tier:qo!==null?qo.tier:Bs.tier,unknownKind:qo!==null?null:Bs.unknownKind??null})}}return fe},Ie=z=>{let ee=Tr({appRoot:n,entrypoints:y,depClassAnchors:I,bindingForms:z,callablePackageResolver:A,tsconfigPaths:k}),de=[...g.diagnostics,...Dr(g),...Lr(g,y.length),...Yr(a,x),...ee.diagnostics];return{graph:ee.graph,inc:Ql(ee.graph,de,U),aborted:Zl(y.length,ee.graph),live:oe(ee.graph),applicability:ee.bindingApplicability}},Ne=z=>{let ee=Ie(z);return se(ee.graph,ee.inc,ee.aborted,ee.live)},pe=Ie({}),Qe=se(pe.graph,pe.inc,pe.aborted,pe.live),hn=se(v,X,j,ne);if(hn.length!==Qe.length)throw new an("--binding-shadow dual-run row counts diverged; refusing to write a misaligned diff");let xe=(z,ee)=>ee.tier!==z.tier||ee.unknownKind!==z.unknownKind,en=Qe.some((z,ee)=>{let de=hn[ee];return de!==void 0&&xe(z,de)}),De=en?Ne({additiveForms:!0}):null,gn=en?Ne({namelessExports:!0}):null,Tn=0,mt=Qe.map((z,ee)=>{let de=hn[ee];if(de===void 0||de.advisoryId!==z.advisoryId||de.packageName!==z.packageName||de.symbolName!==z.symbolName)throw new an("--binding-shadow dual-run row identities diverged; refusing to write a misaligned diff");let Re={advisoryId:z.advisoryId,packageName:z.packageName,symbolName:z.symbolName,unknownKind:z.unknownKind,verdictBefore:z.tier,verdictAfter:de.tier,wouldPromote:de.tier!==z.tier&&(de.tier==="reachable-high"||de.tier==="reachable-medium"||de.tier==="reachable-low")};if(!xe(z,de)||De===null||gn===null)return Re;Tn+=1;let fe=De[ee],ue=gn[ee],$e=fe!==void 0&&xe(z,fe),Dn=ue!==void 0&&xe(z,ue);return{...Re,attributedArm:$e&&!Dn?"additiveForms":Dn&&!$e?"namelessExports":"both",...fe!==void 0?{verdictArmA:fe.tier}:{},...ue!==void 0?{verdictArmB:ue.tier}:{}}}),yn={...Q};Qe.forEach((z,ee)=>{let de=hn[ee];de!==void 0&&de.tier!==z.tier&&(yn[de.tier]-=1,yn[z.tier]+=1)});let xn=(z,ee)=>({none:0,"fail-on-reachable":z>0?2:0,"fail-on-unknown":ee>0?2:0,both:z>0||ee>0?2:0}),ye;if(Y.models.length>0&&ne!==null){ye=[];for(let z of l.packages)for(let{advisory:ee,affected:de}of t.advisoriesForPackage(z.ecosystem??"npm",z.name)){let Re=zt(ee.id,z.name,de),fe=fs(ee.id,z.name,t.symbolsForAffected(de.id),de.surfaceComplete,o);for(let ue of fe){if(ue===null||!ue.verified)continue;let $e=Ut(pe.graph,pe.live,{name:z.name,version:z.version,...z.ecosystem!==void 0?{ecosystem:z.ecosystem}:{},devOnly:z.dev,outOfGraphExecution:_(z)},Re,ue,pe.inc,pe.aborted);if(!($e.hit===null&&ms($e.finding,ue,"base")))continue;let Jn=xt(v,ne.modulesById,ne.reachMods,ue,ne.records);ye.push({advisoryId:ee.id,packageName:z.name,symbolName:ue.exportName,modelWouldPromote:Jn!==null,...Jn!==null?{modelId:Jn.modelId}:{},anchorCleared:Jn!==null})}}}let nn=$.some(z=>z.modelId!==void 0);Te={records:mt,deltas:Tn,exitCodes:{baseline:xn(yn["reachable-high"]+yn["reachable-medium"],yn.unknown+(nn?1:0)),withBindingForms:xn(Q["reachable-high"]+Q["reachable-medium"],Q.unknown+(nn?1:0))},dualRunWallMs:Date.now()-L,...P.bindingApplicability!==void 0?{applicability:P.bindingApplicability}:{},...ye!==void 0?{modelProbe:ye}:{}},Xl(mn.dirname(e.bindingShadow.outPath),{recursive:!0});let We=`${e.bindingShadow.outPath}.tmp-${Hl(8).toString("hex")}`;Jl(We,`${JSON.stringify(Te,null,2)}
|
|
25
|
+
`,{encoding:"utf8",flag:"wx"}),Yl(We,e.bindingShadow.outPath)}let Ze=G.length>0||Y.notes.length>0?{active:Y.models.length,stored:G.length,promoted:$.filter(L=>L.modelId!==void 0).length,notes:[...Y.notes,...re!==null?re.notes:[]]}:void 0;return{...le!==void 0?{summaryShadow:le}:{},...ge!==void 0?{modelShadow:ge}:{},...Te!==void 0?{bindingShadow:Te}:{},...Ze!==void 0?{modelLane:Ze}:{},dir:n,shardSchemaVersion:t.schemaVersion,installed:l,findings:$,counts:Q,analyzerDiagnostics:N,pythonDiagnostics:i?.diagnostics??[],analysisAborted:K,rejectedEntries:m,entrypointSources:b,entrypointGaps:[...g.gaps,...g.surfaceGaps],entrypointObservations:g.observations,framework:g.framework,unresolved:T,advisories:[...Z.values()],rootSet:a,exitCode:q,adr105:J.report}}finally{e.reader===void 0&&t.close()}}var ng="cupel",tg="reachability-first SCA \u2014 verdict + call path + confidence";function ys(e){return[`${ng} v${e} \u2014 ${tg}`,`cascade: ${Xs.join(" \u2192 ")}`,`verdicts: ${Ys.join(", ")}`,"","usage: cupel scan <dir> [--shard <npm.sqlite>] [--sarif <file>] [--fail-on-reachable] [--fail-on-unknown]"," --shard path to the npm symbol shard (or set CUPEL_SHARD_NPM)"," --shard-pypi path to the PyPI shard (or set CUPEL_SHARD_PYPI); Python distributions"," found in a .venv are assessed against it, else reported as not assessed"," --sarif also write a SARIF 2.1.0 report"," --fail-on-reachable exit 2 when any reachable finding is present (for CI)"," --fail-on-unknown exit 2 when any unknown verdict is present (strict CI)",""," cupel login store a delivery token for this machine (read from stdin)"," cupel logout forget it"," On GitHub Actions neither is needed: the workflow authenticates with a token GitHub"," signs per run. Elsewhere a scan fetches the advisory database with the stored token,"," or CUPEL_DELIVERY_TOKEN, or works offline from a shard you already have (--shard)."].join(`
|
|
26
|
+
`)}var og=new Set([...Zo,...Qo]);function wn(e,n,t){let o=e[n+1];if(o===void 0||o.startsWith("--"))throw new Error(`${t} requires a value`);return o}function rg(e){let n=e.split(",").map(r=>r.trim()),t=[...Zo,...Qo].join(", ");if(n.length===0||n.some(r=>r===""))throw new Error(`--fail-on-unknown= requires a non-empty comma-separated list of: ${t} (or pass the bare --fail-on-unknown to fail on every kind)`);let o=[];for(let r of n){if(!og.has(r))throw new Error(`unknown --fail-on-unknown selector ${JSON.stringify(r)}; valid: ${t}`);o.push(r)}return o}function od(e){let n=".",t,o,r,s=!1,a=!1,l=!1,i=!1,d=!1,u,p,f,m=!1,g=!1,y,b=!1,x=!0,I=!1,w,A=[],k=[];for(let h=0;h<e.length;h+=1){let S=e[h];if(S==="--require-complete-denial"){a=!0;continue}if(S==="--fail-on-reachable")s=!0;else if(S==="--fail-on-unknown")l="all";else if(S!==void 0&&S.startsWith("--fail-on-unknown="))l=rg(S.slice(18));else if(S==="--offline")i=!0;else if(S==="--sarif")t=wn(e,h,"--sarif"),h+=1;else if(S==="--shard")o=wn(e,h,"--shard"),h+=1;else if(S==="--shard-pypi")r=wn(e,h,"--shard-pypi"),h+=1;else if(S==="--entry")A.push(wn(e,h,"--entry")),h+=1;else if(S==="--root")k.push(wn(e,h,"--root")),h+=1;else if(S==="--summary-shadow")u=wn(e,h,"--summary-shadow"),h+=1;else if(S==="--model-shadow")p=wn(e,h,"--model-shadow"),h+=1;else if(S==="--model-shadow-out")f=wn(e,h,"--model-shadow-out"),h+=1;else if(S==="--model-shadow-widened")m=!0;else if(S==="--binding-shadow")g=!0;else if(S==="--binding-shadow-out")y=wn(e,h,"--binding-shadow-out"),h+=1;else if(S==="--x-partial-rows")b=!0;else if(S==="--no-tsconfig-paths")x=!1;else if(S==="--x-tsconfig-paths")x=!0;else if(S==="--push")I=!0;else if(S!==void 0&&S.startsWith("--auth=")){let _=S.slice(7);if(_!=="oidc"&&_!=="token")throw new Error(`--auth must be oidc or token, got ${JSON.stringify(_)}`);w=_}else{if(S!==void 0&&S.startsWith("--"))throw new Error(`unknown flag ${S}`);S!==void 0&&!d&&(n=S,d=!0)}}if(p===void 0!=(f===void 0))throw new Error("--model-shadow and --model-shadow-out must be given together");if(m&&p===void 0)throw new Error("--model-shadow-widened only means something with --model-shadow");if(g!==(y!==void 0))throw new Error("--binding-shadow and --binding-shadow-out must be given together");if(w!==void 0&&!I)throw new Error("--auth only means something with --push");return{dir:n,sarif:t,shard:o,shardPypi:r,failOnReachable:s,requireCompleteDenial:a,failOnUnknown:l,offline:i,entry:A,root:k,summaryShadow:u,modelShadow:p,modelShadowOut:f,modelShadowWidened:m,push:I,auth:w,bindingShadow:g,bindingShadowOut:y,partialRows:b,tsconfigPaths:x}}import{chmodSync as ug,mkdirSync as fg,readFileSync as pg,renameSync as mg,statSync as hg,unlinkSync as gg,writeFileSync as yg}from"node:fs";import{randomBytes as xg}from"node:crypto";import{homedir as Sg}from"node:os";import Hn from"node:path";import{createPublicKey as sg,verify as ig}from"node:crypto";function Ye(e,n){let t=new URL(e);if(t.protocol!=="https:")throw new Error(`refusing non-https url: ${e}`);if(t.username!==""||t.password!=="")throw new Error(`refusing url carrying userinfo for host ${t.hostname}`);if(t.port!=="")throw new Error(`refusing url with explicit port ${t.port} for host ${t.hostname}`);if(!n.has(t.hostname))throw new Error(`refusing unpinned host ${t.hostname} (allowed: ${[...n].join(", ")})`);if(t.origin!==`https://${t.hostname}`)throw new Error(`refusing non-canonical authority for host ${t.hostname}`);return t}async function rd(e,n={}){let t=n.maxBytes??1073741824,o=n.timeoutMs??3e4,{get:r}=await import("node:https");return await new Promise((s,a)=>{let l=r(e,n.headers!==void 0?{headers:n.headers}:{},i=>{let d=i.statusCode??0;if(d<200||d>=300){i.resume(),a(new Error(`GET ${e} \u2192 HTTP ${String(d)}`));return}let u=[],p=0;i.on("data",f=>{if(p+=f.length,p>t){i.destroy(),a(new Error(`GET ${e} exceeded ${String(t)} bytes`));return}u.push(f)}),i.on("end",()=>{s(Buffer.concat(u))}),i.on("error",a)});l.on("error",a),l.setTimeout(o,()=>{l.destroy(new Error(`GET ${e} timed out after ${String(o)}ms`))})})}async function Vt(e,n,t,o,r,s=3e4){let{request:a}=await import("node:https"),l=new URL(n).hostname;return await new Promise((i,d)=>{let u=a(n,{method:e,headers:t},p=>{let f=[],m=0;p.on("data",g=>{if(m+=g.length,m>r){p.destroy(),d(new Error(`${e} to ${l} returned more than ${String(r)} bytes`));return}f.push(g)}),p.on("end",()=>{i({status:p.statusCode??0,body:Buffer.concat(f).toString("utf8")})}),p.on("error",()=>{d(new Error(`${e} to ${l} failed`))})});u.on("error",()=>{d(new Error(`${e} to ${l} failed`))}),u.setTimeout(s,()=>{u.destroy(new Error(`${e} to ${l} timed out after ${String(s)}ms`))}),o!==void 0&&u.write(o),u.end()})}var ie=class extends Error{constructor(n){super(n),this.name="DistError"}},Gn=class extends ie{constructor(n){super(n),this.name="NoCachedShardError"}},ag=Buffer.from("302a300506032b6570032100","hex"),lg=32;function ld(e){let n;try{n=Buffer.from(e,"base64")}catch{return}if(n.length===lg)try{return sg({key:Buffer.concat([ag,n]),format:"der",type:"spki"})}catch{return}}function xs(e,n,t){for(let o of t){let r=ld(o);if(r!==void 0)try{if(ig(null,e,r,n))return!0}catch{}}return!1}function dd(e){return e.some(n=>ld(n)!==void 0)}var dg=/^[0-9a-f]{64}$/u,cg=/^[a-z0-9-]+$/u;function sd(e,n){if(typeof e!="object"||e===null||Array.isArray(e))throw new ie(`${n} must be an object`);return e}function id(e,n){if(!Array.isArray(e))throw new ie(`${n} must be an array`);return e}function To(e,n){if(typeof e!="number"||!Number.isInteger(e))throw new ie(`${n} must be an integer`);return e}function Do(e,n){if(typeof e!="string")throw new ie(`${n} must be a string`);return e}function ad(e,n){let t=Do(e,n);if(Number.isNaN(Date.parse(t)))throw new ie(`${n} is not a valid timestamp: ${t}`);return t}function Ss(e,n){let t;try{t=JSON.parse(e.toString("utf8"))}catch{throw new ie("distribution index is not valid JSON")}let o=sd(t,"index"),r=To(o.schema_version,"schema_version");if(r!==n.supportedIndexSchemaVersion)throw new ie(`index schema_version ${String(r)} is not understood (this cupel speaks ${String(n.supportedIndexSchemaVersion)})`);let s=To(o.sequence,"sequence");if(s<0)throw new ie("sequence must be non-negative");let a=ad(o.generated,"generated"),l=id(o.shards,"shards"),i;for(let g of l){let y=sd(g,"shard entry"),b=Do(y.ecosystem,"ecosystem");if(!cg.test(b))throw new ie(`ecosystem ${JSON.stringify(b)} is malformed`);if(b===n.ecosystem){i=y;break}}if(i===void 0)throw new ie(`no shard for ecosystem ${JSON.stringify(n.ecosystem)}`);ad(i.built,"built");let d=To(i.db_schema_version,"db_schema_version");if(d<1)throw new ie("db_schema_version must be >= 1");if(d>n.supportedDbSchemaVersion)throw new ie(`this shard needs a newer cupel (db_schema_version ${String(d)} > supported ${String(n.supportedDbSchemaVersion)}); upgrade cupel (npm i -g @cupel-sh/cli) or pass an older --shard`);let u=Do(i.sha256,"sha256");if(!dg.test(u))throw new ie(`sha256 must be 64 lowercase hex, got ${JSON.stringify(u)}`);let p=To(i.size_bytes,"size_bytes");if(p<=0||p>n.hardMaxBytes)throw new ie(`size_bytes ${String(p)} out of bounds (0, ${String(n.hardMaxBytes)}]`);let f=id(i.urls,"urls");if(f.length===0)throw new ie("urls must be a non-empty array");let m=[];for(let g of f){let y=Do(g,"url");try{m.push(Ye(y,n.shardHosts))}catch(b){throw new ie(`refusing shard url ${JSON.stringify(y)}: ${b.message}`)}}return{ecosystem:n.ecosystem,sha256:u,sizeBytes:p,dbSchemaVersion:d,urls:m,sequence:s,generated:a}}var cd="CUPEL_CONFIG_DIR",ud="credentials.json",bs="cpd_",bg="cpl_",kg=bs.length+6+32,Eg=200,wg=/^[A-Za-z0-9_-]+$/u,qt=class extends ie{constructor(n){super(n),this.name="StoredCredentialError"}};function fd(e){let n=e.CUPEL_CONFIG_DIR;if(n!==void 0&&n!=="")return n;let t=Sg();if(process.platform==="darwin")return Hn.join(t,"Library","Application Support","cupel");if(process.platform==="win32"){let s=e.APPDATA,a=s!==void 0&&s!==""?s:Hn.join(t,"AppData","Roaming");return Hn.join(a,"cupel")}let o=e.XDG_CONFIG_HOME,r=o!==void 0&&o!==""?o:Hn.join(t,".config");return Hn.join(r,"cupel")}function Lo(e){return Hn.join(fd(e),ud)}function ks(e){let n=e.trim();return n.startsWith(bg)?{ok:!1,reason:"push-token"}:n.startsWith(bs)?n.length<kg||n.length>Eg?{ok:!1,reason:"malformed"}:wg.test(n.slice(bs.length))?{ok:!0,token:n}:{ok:!1,reason:"malformed"}:{ok:!1,reason:"malformed"}}function pd(e,n){let t=fd(e),o=Hn.join(t,ud);fg(t,{recursive:!0,mode:448}),process.platform!=="win32"&&ug(t,448);let r=JSON.stringify({version:1,delivery_token:n,written_at:new Date().toISOString()}),s=`${o}.tmp-${xg(8).toString("hex")}`;return yg(s,`${r}
|
|
27
|
+
`,{flag:"wx",mode:384}),mg(s,o),o}function md(e){let n=Lo(e),t;try{t=hg(n)}catch(a){if(a instanceof Error&&a.code==="ENOENT")return;throw a}if(process.platform!=="win32"&&(t.mode&63)!==0)throw new qt(`the stored delivery token at ${n} is readable by other users \u2014 run \`chmod 600 ${n}\`, or \`cupel login\` again to rewrite it`);let o;try{o=JSON.parse(pg(n,"utf8"))}catch{throw new qt(`the stored delivery token at ${n} is not readable \u2014 run \`cupel login\` again to rewrite it`)}let r=typeof o=="object"&&o!==null&&"delivery_token"in o?o.delivery_token:void 0,s=ks(typeof r=="string"?r:"");if(!s.ok)throw new qt(`the stored credential at ${n} is not a delivery token \u2014 run \`cupel login\` with one from app.cupel.sh (Settings \u2192 Tokens)`);return s.token}function hd(e){try{return gg(Lo(e)),!0}catch(n){if(n instanceof Error&&n.code==="ENOENT")return!1;throw n}}var Gt="CUPEL_DELIVERY_TOKEN",Es=class extends ie{constructor(n){super(n),this.name="NoDeliveryTokenError"}},ws=class extends ie{constructor(n){super(n),this.name="DeliveryCredentialError"}};function vg(e){let n=e.CUPEL_DELIVERY_TOKEN;return n===void 0||n===""?void 0:n}function gd(e,n,t=()=>{}){let o=vg(e)??t();return o!==void 0?()=>Promise.resolve(o):e.ACTIONS_ID_TOKEN_REQUEST_URL!==void 0&&e.ACTIONS_ID_TOKEN_REQUEST_URL!==""?n:void 0}async function yd(e){if(e===void 0)throw new Es(`no delivery credential \u2014 on GitHub Actions add \`permissions: id-token: write\` to the workflow; elsewhere run \`cupel login\` with a delivery token from app.cupel.sh (Settings \u2192 Tokens), or set ${Gt} in CI; or pass --shard <path> (a local shard needs no account)`);try{return await e()}catch(n){throw new ws(`could not obtain a delivery credential: ${n instanceof Error?n.message:String(n)}`)}}var Ig="Paste a delivery token from app.cupel.sh (Settings \u2192 Tokens); input is hidden: ";function Ag(){return new Promise(e=>{let n=process.stdin;process.stderr.write(Ig),n.setRawMode(!0),n.resume(),n.setEncoding("utf8");let t="",o=s=>{n.setRawMode(!1),n.pause(),n.removeListener("data",r),process.stderr.write(`
|
|
28
|
+
`),s===null&&process.exit(130),e(s)},r=s=>{for(let a of s){if(a==="")return o(null);if(a==="\r"||a===`
|
|
29
|
+
`)return o(t);if(a==="\x7F"||a==="\b"){t=t.slice(0,-1);continue}t+=a}};n.on("data",r)})}async function _g(){let e=[];for await(let t of process.stdin)e.push(Buffer.isBuffer(t)?t:Buffer.from(String(t),"utf8"));return Buffer.concat(e).toString("utf8").split(/\r?\n/u).find(t=>t.trim()!=="")??""}function xd(e,n){let t=e[0];return t===void 0?!1:(process.stderr.write(`cupel ${n}: unknown option '${W(t)}' \u2014 the token is read from standard input, never from an argument (it would land in shell history and \`ps\`)
|
|
30
|
+
`),!0)}async function Sd(e){if(xd(e,"login"))return 1;let n=process.stdin.isTTY?await Ag():await _g(),t=ks(n);if(!t.ok)return process.stderr.write(t.reason==="push-token"?`cupel login: that is a push token (cpl_\u2026), which authenticates one repository's findings push and is set as CUPEL_TOKEN in CI. Sign in with a delivery token (cpd_\u2026) from app.cupel.sh \u2014 Settings \u2192 Tokens \u2014 which fetches the advisory database for the whole organisation.
|
|
27
31
|
`:`cupel login: that is not a delivery token. Paste the whole token as shown once on app.cupel.sh (Settings \u2192 Tokens); it starts with cpd_.
|
|
28
|
-
`),1;let
|
|
29
|
-
`),0}function
|
|
30
|
-
`):process.stdout.write(`nothing to sign out of: no delivery token stored at ${n} (${
|
|
31
|
-
`),0}import ih from"node:path";import{randomBytes as Im,createHash as Am}from"node:crypto";import{mkdirSync as _m,readFileSync as Nm,renameSync as Rm,writeFileSync as Cm}from"node:fs";import{homedir as Om}from"node:os";import $n from"node:path";var jo="latest.json",Ko="latest.json.sig";function ir(e){return Am("sha256").update(e).digest("hex")}function Bo(){let e=process.env.CUPEL_CACHE_DIR;if(e!==void 0&&e!=="")return e;let n=Om();if(process.platform==="darwin")return $n.join(n,"Library","Caches","cupel","shards");if(process.platform==="win32"){let o=process.env.LOCALAPPDATA,i=o!==void 0&&o!==""?o:$n.join(n,"AppData","Local");return $n.join(i,"cupel","shards")}let t=process.env.XDG_CACHE_HOME,r=t!==void 0&&t!==""?t:$n.join(n,".cache");return $n.join(r,"cupel","shards")}function zo(e,n,t){return $n.join(e,`${n}-${t}.sqlite`)}function sr(e,n){_m($n.dirname(e),{recursive:!0});let t=`${e}.tmp-${Im(8).toString("hex")}`;Cm(t,n,{flag:"wx"}),Rm(t,e)}function bt(e){try{return Nm(e)}catch(n){if(n instanceof Error&&n.code==="ENOENT")return;throw n}}function xl(e,n,t,r){let o=zo(e,n,t),i=bt(o);if(i===void 0)return;let a=ir(i);if(a!==t)throw r(`cached shard ${o} failed sha256 re-verify (expected ${t}, got ${a})`);return{path:o,bytes:i}}var Sl="api.cupel.sh",ar=new Set(["2b68896688aea5d7cd558798f0d8fbf8.r2.cloudflarestorage.com"]),bl=["tVK6LxjAkqVPe7fE3w09f3mOSGSI6mWf5BXatNoVv8k="];import lr from"node:path";var Pm="/v1/resolve",Uo=1024*1024,Vo=4096,kl=Uo+Vo+64*1024,$m=8,Mm=2048,Dm=/^[A-Za-z0-9+/]+={0,2}$/u,Tm=3e4,we=class extends ee{constructor(n){super(n),this.name="DeliveryRefusedError"}},kt=class extends we{constructor(n){super(n),this.name="EcosystemUnpublishedError"}},Et=class extends ee{constructor(n){super(n),this.name="ControlPlaneUnavailableError"}},wt=class extends ee{constructor(n){super(n),this.name="SequenceFloorRefusedError"}};function Lm(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Fm(e){if(typeof e!="string"||e.length===0)throw new we("the delivery response carried no index signature");if(e.length>Vo||!Dm.test(e))throw new we("the delivery response's index signature is not base64");let n=Buffer.from(e,"base64");if(n.toString("base64")!==e)throw new we("the delivery response's index signature is not canonical base64");return n}function jm(e){if(typeof e!="string"||e.length===0)throw new we("the delivery response carried no index");let n=Buffer.from(e,"utf8");if(n.length>Uo)throw new we("the delivery response's index is larger than one can be");return n}function Km(e){if(!Array.isArray(e)||e.length===0)throw new we("the delivery response named no shard urls");if(e.length>$m)throw new we("the delivery response named more shard urls than one shard has");let n=[];for(let t of e){if(typeof t!="string"||t.length===0||t.length>Mm)throw new we("the delivery response carried a malformed shard url");n.push(t)}return n}function Bm(e,n){throw e===401||e===403?new we(`${n} rejected the delivery credential \u2014 check ${St} or the token \`cupel login\` stored, or that the token has not been revoked in the dashboard (Settings \u2192 Tokens)`):e===404?new kt(`${n} publishes no shard for this ecosystem \u2014 cannot scan without vulnerability data`):e===409?new wt(`${n} holds nothing newer than the shard index already cached`):e===429?new Et(`${n} rate-limited the delivery request`):e>=500?new Et(`${n} answered ${String(e)}`):new we(`${n} refused the delivery request with status ${String(e)}`)}async function El(e,n,t,r,o=Tm){let i=Ve(`https://${e}${Pm}`,new Set([e])),a=JSON.stringify({ecosystem:t.ecosystem,sequence_floor:t.sequenceFloor}),l;try{l=await r(i.href,{authorization:`Bearer ${n}`,"content-type":"application/json",accept:"application/json","user-agent":"cupel"},a,o)}catch{throw new Et(`${e} could not be reached`)}if(l.status!==200&&Bm(l.status,e),Buffer.byteLength(l.body,"utf8")>kl)throw new we(`${e} returned a delivery response larger than one can be`);let s;try{s=JSON.parse(l.body)}catch{throw new we(`${e} returned a delivery response that is not JSON`)}if(!Lm(s))throw new we(`${e} returned a delivery response that is not an object`);return{index:jm(s.index),sig:Fm(s.signature),shardUrls:Km(s.shardUrls)}}var wl=async(e,n,t,r)=>await yt("POST",e,{...n,"content-length":String(Buffer.byteLength(t,"utf8"))},t,kl,r);var zm=8,qo=class extends ee{constructor(n){super(n),this.name="NoUsableShardUrlError"}};function Wo(e){return`${e.origin}${e.pathname}`}function vl(e,n,t){let r=new Map;for(let a of n)r.set(Wo(a),a);let o=[],i=[];for(let a of e.slice(0,zm)){let l;try{l=Ve(a,t)}catch(u){i.push(u.message);continue}if(l.hash!==""){i.push("a candidate carried a fragment");continue}let s=r.get(Wo(l));if(s===void 0){i.push("a candidate named an object the signed index does not list");continue}let d=new URL(`${Wo(s)}${l.search}`);o.push(Ve(d.href,t))}if(o.length===0)throw new qo(`no pre-signed shard url matched the signed index (${i.length===0?"none offered":i.join("; ")})`);return o}var Vm=1,Wm=1024*1024*1024;function qm(e=ar){return{async resolve(n){return await El(n.host,n.token,{ecosystem:n.ecosystem,sequenceFloor:n.sequenceFloor},wl)},async fetchShard(n,t){return Ve(n.href,e),await nl(n.href,{maxBytes:t,timeoutMs:3e4})}}}function Go(e){return e instanceof Error?e.message:String(e)}function Il(e){return{ecosystem:e.ecosystem,supportedIndexSchemaVersion:Vm,supportedDbSchemaVersion:e.supportedDbSchemaVersion,shardHosts:e.shardHosts,hardMaxBytes:Wm}}function Gm(e){let n=bt(lr.join(e.cacheDir,jo)),t=bt(lr.join(e.cacheDir,Ko));if(!(n===void 0||t===void 0)&&$o(n,t,e.pubkeys))try{return Mo(n,Il(e))}catch{return}}function Al(e,n){let t=Date.parse(e.generated);if(Number.isNaN(t)||n.now-t<=n.maxAgeMs)return[];let r=Math.floor((n.now-t)/864e5);return[`the ${e.ecosystem} shard is ${String(r)} days old (built ${e.generated}); its advisory data may be stale \u2014 connect online to refresh`]}function dr(e,n,t){let r=xl(n.cacheDir,e.ecosystem,e.sha256,o=>new ee(o));if(r===void 0)throw new ee(`the cached index names ${e.ecosystem} shard ${e.sha256} but it is not in the cache \u2014 connect online to repopulate, or pass --shard <path>`);return{path:r.path,fromCache:!0,warnings:[...t,...Al(e,n)],sequence:e.sequence}}async function Hm(e,n,t,r){let o=zo(t.cacheDir,e.ecosystem,e.sha256),i=bt(o);if(i!==void 0&&ir(i)===e.sha256)return{path:o,downloaded:!1};let a="no shard urls";for(let l of n){let s;try{s=await r.fetchShard(l,e.sizeBytes)}catch(u){a=Go(u);continue}let d=ir(s);if(d!==e.sha256){a=`sha256 mismatch (expected ${e.sha256}, got ${d})`;continue}return sr(o,s),{path:o,downloaded:!0}}throw new ee(`could not fetch a verified ${e.ecosystem} shard from any mirror: ${a}`)}function Xm(e,n,t){if(e instanceof we)throw e;if(e instanceof wt){if(n===void 0)throw new ee(`the control plane refused to serve an index at or above the requested sequence, and there is no cached ${t.ecosystem} shard \u2014 pass --shard <path>`);return dr(n,t,["the control plane holds nothing newer than the cached shard index; keeping the cached shard"])}if(n===void 0)throw new On(`no cached ${t.ecosystem} shard and the delivery seam is unreachable (${Go(e)}) \u2014 cannot scan without vulnerability data; connect once to populate the cache, or pass --shard <path>`);return dr(n,t,[`could not refresh the shard index (${Go(e)}); using the cached shard`])}async function _l(e,n){if(!e.activated)throw new ee("zero-config shard delivery is not yet available (ADR-063 token-gated delivery ships in P5) \u2014 pass --shard <path> or set CUPEL_SHARD_NPM");let t=n??qm(e.shardHosts);if(!sl(e.pubkeys))throw new ee("zero-config shard delivery is not activated in this build \u2014 pass --shard <path> or set CUPEL_SHARD_NPM");let r=Gm(e);if(e.offline){if(r===void 0)throw new On(`--offline and no cached ${e.ecosystem} shard \u2014 connect once to populate the cache, or pass --shard <path>`);return dr(r,e,[])}let o=await ml(e.credential),i;try{i=await t.resolve({host:e.indexHost,token:o,ecosystem:e.ecosystem,sequenceFloor:r?.sequence??0})}catch(d){return Xm(d,r,e)}if(!$o(i.index,i.sig,e.pubkeys))throw new ee("shard index signature did not verify against any pinned key");let a=Mo(i.index,Il(e));if(r!==void 0&&a.sequence<r.sequence)return dr(r,e,[`refusing a rolled-back shard index (served sequence ${String(a.sequence)} < cached ${String(r.sequence)}); keeping the newer cached shard`]);let l=vl(i.shardUrls,a.urls,e.shardHosts),s=await Hm(a,l,e,t);return sr(lr.join(e.cacheDir,jo),i.index),sr(lr.join(e.cacheDir,Ko),i.sig),{path:s.path,fromCache:!s.downloaded,warnings:Al(a,e),sequence:a.sequence}}var Ym="https://api.cupel.sh",Nl=".actions.githubusercontent.com",Jm=8192;function Rl(e){return e.kind==="oidc"||/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/u.test(e.value)?"oidc":"token"}var We=class extends Error{constructor(n){super(n),this.name="PushCredentialError"}};function Zm(e){let n;try{n=new URL(e).hostname}catch{throw new We("ACTIONS_ID_TOKEN_REQUEST_URL is not a URL")}let t=Nl.slice(1);if(n!==t&&!n.endsWith(Nl))throw new We(`refusing to send the ID-token request credential to unpinned host ${n}`);try{return Ve(e,new Set([n]))}catch{throw new We(`ACTIONS_ID_TOKEN_REQUEST_URL for host ${n} is not a plain https authority`)}}async function cr(e,n){let t=e.ACTIONS_ID_TOKEN_REQUEST_URL,r=e.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(t===void 0||t==="")throw new We("ACTIONS_ID_TOKEN_REQUEST_URL is not set \u2014 the workflow needs `permissions: id-token: write`");if(r===void 0||r==="")throw new We("ACTIONS_ID_TOKEN_REQUEST_TOKEN is not set \u2014 the workflow needs `permissions: id-token: write`");let o=Zm(t);o.searchParams.set("audience",Ym);let i;try{i=await n(o.href,{authorization:`Bearer ${r}`,accept:"application/json","user-agent":"cupel"})}catch{throw new We("the ID-token request failed")}if(i.length>Jm)throw new We("the ID-token response was larger than a token can be");let a;try{a=JSON.parse(i)}catch{throw new We("the ID-token response was not JSON")}let l=typeof a=="object"&&a!==null?a.value:void 0;if(typeof l!="string"||l.length===0)throw new We("the ID-token response carried no token");return l}async function Cl(e,n,t={}){let r=e.CUPEL_TOKEN!==void 0&&e.CUPEL_TOKEN!=="",o=e.ACTIONS_ID_TOKEN_REQUEST_URL!==void 0&&e.ACTIONS_ID_TOKEN_REQUEST_URL!=="";if(t.auth==="token"){if(!r)throw new We("--auth=token, but CUPEL_TOKEN is not set");return{kind:"token",value:e.CUPEL_TOKEN??""}}if(t.auth==="oidc")return{kind:"oidc",value:await cr(e,n)};if(r)return o&&t.warn?.("both CUPEL_TOKEN and GitHub Actions OIDC are available; using CUPEL_TOKEN. Remove the secret to use keyless auth, or pass --auth=oidc."),{kind:"token",value:e.CUPEL_TOKEN??""};if(o)return{kind:"oidc",value:await cr(e,n)};throw new We("no credential for the findings push: set CUPEL_TOKEN, or add `permissions: id-token: write` to the workflow")}var Ho="api.cupel.sh",Qm=`https://${Ho}/v1/findings`,eh=64*1024,ur=8*1024*1024,nh=3e4,xn=class extends Error{constructor(n){super(n),this.name="PushError"}};async function Ol(e,n,t,r={}){if(e.length>ur)throw new xn(`findings payload is ${String(e.length)} bytes, over the ${String(ur)}-byte limit`);let o=Ve(Qm,new Set([Ho])),i;try{i=await t(o.href,{authorization:`Bearer ${n}`,"content-type":"application/json","user-agent":"cupel"},e,r.timeoutMs??nh)}catch{throw new xn(`the findings push to ${Ho} failed`)}if(i.body.length>eh)throw new xn("the control plane returned a response larger than it should");if(!(i.status===202||i.status===200))throw i.status===401||i.status===403?new xn("the control plane rejected the credential \u2014 check CUPEL_TOKEN, or that the workflow grants `permissions: id-token: write` and the repository is connected in the dashboard"):i.status===400?new xn("the control plane rejected the findings payload as malformed"):new xn(`the findings push was refused with status ${String(i.status)}`)}var th=64*1024,rh=64*1024,Pl=async(e,n,t,r)=>{if(Buffer.byteLength(t,"utf8")>ur)throw new Error("findings payload is over the size limit");return await yt("POST",e,{...n,"content-length":String(Buffer.byteLength(t,"utf8"))},t,rh,r)};async function fr(e,n){let t=await yt("GET",e,n,void 0,th,15e3);if(t.status!==200)throw new Error(`the ID-token request was refused with status ${String(t.status)}`);return t.body}var sh=720*60*60*1e3,ah=Number(wn);function $l(e){let n=process.env.CUPEL_SHARD_PYPI;return e??(n!==void 0&&n!==""?n:void 0)}function Ml(e){let n=process.env.CUPEL_SHARD_NPM,t=e??(n!==void 0&&n!==""?n:void 0);if(t===void 0)throw new Xe("no npm shard configured \u2014 pass --shard <path> or set CUPEL_SHARD_NPM (zero-config token-gated delivery ships in P5 \u2014 ADR-063)");return t}async function Xo(e){let n=e.ecosystem??"npm",t=await _l({ecosystem:n,activated:!0,pubkeys:bl,indexHost:Sl,shardHosts:ar,credential:pl(process.env,()=>cr(process.env,fr),()=>ul(process.env)),cacheDir:n==="npm"?Bo():ih.join(Bo(),n),offline:e.offline,now:Date.now(),maxAgeMs:sh,supportedDbSchemaVersion:ah});for(let r of t.warnings)process.stderr.write(`cupel: ${r}
|
|
32
|
-
`);return{path:t.path,sequence:t.sequence}}var
|
|
33
|
-
${
|
|
34
|
-
`)}import{createHash as
|
|
35
|
-
`)});function
|
|
36
|
-
`,
|
|
37
|
-
`);else throw
|
|
38
|
-
`),l.modelLane!==void 0){let
|
|
39
|
-
`)}if(n.summaryShadow!==void 0&&l.summaryShadow!==void 0){let
|
|
40
|
-
`),process.stdout.write(`summary-shadow: ${String(l.summaryShadow.records.length)} counterfactual record(s) -> ${
|
|
41
|
-
`)}if(l.modelShadow!==void 0&&n.modelShadowOut!==void 0){let
|
|
32
|
+
`),1;let o=pd(process.env,t.token);return process.stdout.write(`signed in: delivery token stored at ${o} (readable by you alone). \`cupel scan\` uses it outside GitHub Actions; ${Gt} in the environment still wins, and \`cupel logout\` forgets it.
|
|
33
|
+
`),0}function bd(e){if(xd(e,"logout"))return 1;let n=Lo(process.env);return hd(process.env)?process.stdout.write(`signed out: removed ${n}. The token itself still works until it is revoked on app.cupel.sh (Settings \u2192 Tokens).
|
|
34
|
+
`):process.stdout.write(`nothing to sign out of: no delivery token stored at ${n} (${cd} would point elsewhere).
|
|
35
|
+
`),0}import ly from"node:path";import{randomBytes as Ng,createHash as Rg}from"node:crypto";import{mkdirSync as Pg,readFileSync as $g,renameSync as Og,writeFileSync as Cg}from"node:fs";import{homedir as Mg}from"node:os";import Xn from"node:path";var vs="latest.json",Is="latest.json.sig";function Fo(e){return Rg("sha256").update(e).digest("hex")}function As(){let e=process.env.CUPEL_CACHE_DIR;if(e!==void 0&&e!=="")return e;let n=Mg();if(process.platform==="darwin")return Xn.join(n,"Library","Caches","cupel","shards");if(process.platform==="win32"){let r=process.env.LOCALAPPDATA,s=r!==void 0&&r!==""?r:Xn.join(n,"AppData","Local");return Xn.join(s,"cupel","shards")}let t=process.env.XDG_CACHE_HOME,o=t!==void 0&&t!==""?t:Xn.join(n,".cache");return Xn.join(o,"cupel","shards")}function _s(e,n,t){return Xn.join(e,`${n}-${t}.sqlite`)}function jo(e,n){Pg(Xn.dirname(e),{recursive:!0});let t=`${e}.tmp-${Ng(8).toString("hex")}`;Cg(t,n,{flag:"wx"}),Og(t,e)}function Ht(e){try{return $g(e)}catch(n){if(n instanceof Error&&n.code==="ENOENT")return;throw n}}function kd(e,n,t,o){let r=_s(e,n,t),s=Ht(r);if(s===void 0)return;let a=Fo(s);if(a!==t)throw o(`cached shard ${r} failed sha256 re-verify (expected ${t}, got ${a})`);return{path:r,bytes:s}}var Ed="api.cupel.sh",Bo=new Set(["2b68896688aea5d7cd558798f0d8fbf8.r2.cloudflarestorage.com"]),wd=["tVK6LxjAkqVPe7fE3w09f3mOSGSI6mWf5BXatNoVv8k="];import Ko from"node:path";var Tg="/v1/resolve",Ns=1024*1024,Rs=4096,vd=Ns+Rs+64*1024,Dg=8,Lg=2048,Fg=/^[A-Za-z0-9+/]+={0,2}$/u,jg=3e4,Pe=class extends ie{constructor(n){super(n),this.name="DeliveryRefusedError"}},Xt=class extends Pe{constructor(n){super(n),this.name="EcosystemUnpublishedError"}},Yt=class extends ie{constructor(n){super(n),this.name="ControlPlaneUnavailableError"}},Jt=class extends ie{constructor(n){super(n),this.name="SequenceFloorRefusedError"}};function Bg(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Kg(e){if(typeof e!="string"||e.length===0)throw new Pe("the delivery response carried no index signature");if(e.length>Rs||!Fg.test(e))throw new Pe("the delivery response's index signature is not base64");let n=Buffer.from(e,"base64");if(n.toString("base64")!==e)throw new Pe("the delivery response's index signature is not canonical base64");return n}function Ug(e){if(typeof e!="string"||e.length===0)throw new Pe("the delivery response carried no index");let n=Buffer.from(e,"utf8");if(n.length>Ns)throw new Pe("the delivery response's index is larger than one can be");return n}function zg(e){if(!Array.isArray(e)||e.length===0)throw new Pe("the delivery response named no shard urls");if(e.length>Dg)throw new Pe("the delivery response named more shard urls than one shard has");let n=[];for(let t of e){if(typeof t!="string"||t.length===0||t.length>Lg)throw new Pe("the delivery response carried a malformed shard url");n.push(t)}return n}function Wg(e,n){throw e===401||e===403?new Pe(`${n} rejected the delivery credential \u2014 check ${Gt} or the token \`cupel login\` stored, or that the token has not been revoked in the dashboard (Settings \u2192 Tokens)`):e===404?new Xt(`${n} publishes no shard for this ecosystem \u2014 cannot scan without vulnerability data`):e===409?new Jt(`${n} holds nothing newer than the shard index already cached`):e===429?new Yt(`${n} rate-limited the delivery request`):e>=500?new Yt(`${n} answered ${String(e)}`):new Pe(`${n} refused the delivery request with status ${String(e)}`)}async function Id(e,n,t,o,r=jg){let s=Ye(`https://${e}${Tg}`,new Set([e])),a=JSON.stringify({ecosystem:t.ecosystem,sequence_floor:t.sequenceFloor}),l;try{l=await o(s.href,{authorization:`Bearer ${n}`,"content-type":"application/json",accept:"application/json","user-agent":"cupel"},a,r)}catch{throw new Yt(`${e} could not be reached`)}if(l.status!==200&&Wg(l.status,e),Buffer.byteLength(l.body,"utf8")>vd)throw new Pe(`${e} returned a delivery response larger than one can be`);let i;try{i=JSON.parse(l.body)}catch{throw new Pe(`${e} returned a delivery response that is not JSON`)}if(!Bg(i))throw new Pe(`${e} returned a delivery response that is not an object`);return{index:Ug(i.index),sig:Kg(i.signature),shardUrls:zg(i.shardUrls)}}var Ad=async(e,n,t,o)=>await Vt("POST",e,{...n,"content-length":String(Buffer.byteLength(t,"utf8"))},t,vd,o);var Vg=8,$s=class extends ie{constructor(n){super(n),this.name="NoUsableShardUrlError"}};function Ps(e){return`${e.origin}${e.pathname}`}function _d(e,n,t){let o=new Map;for(let a of n)o.set(Ps(a),a);let r=[],s=[];for(let a of e.slice(0,Vg)){let l;try{l=Ye(a,t)}catch(u){s.push(u.message);continue}if(l.hash!==""){s.push("a candidate carried a fragment");continue}let i=o.get(Ps(l));if(i===void 0){s.push("a candidate named an object the signed index does not list");continue}let d=new URL(`${Ps(i)}${l.search}`);r.push(Ye(d.href,t))}if(r.length===0)throw new $s(`no pre-signed shard url matched the signed index (${s.length===0?"none offered":s.join("; ")})`);return r}var Gg=1,Hg=1024*1024*1024;function Xg(e=Bo){return{async resolve(n){return await Id(n.host,n.token,{ecosystem:n.ecosystem,sequenceFloor:n.sequenceFloor},Ad)},async fetchShard(n,t){return Ye(n.href,e),await rd(n.href,{maxBytes:t,timeoutMs:3e4})}}}function Os(e){return e instanceof Error?e.message:String(e)}function Nd(e){return{ecosystem:e.ecosystem,supportedIndexSchemaVersion:Gg,supportedDbSchemaVersion:e.supportedDbSchemaVersion,shardHosts:e.shardHosts,hardMaxBytes:Hg}}function Yg(e){let n=Ht(Ko.join(e.cacheDir,vs)),t=Ht(Ko.join(e.cacheDir,Is));if(!(n===void 0||t===void 0)&&xs(n,t,e.pubkeys))try{return Ss(n,Nd(e))}catch{return}}function Rd(e,n){let t=Date.parse(e.generated);if(Number.isNaN(t)||n.now-t<=n.maxAgeMs)return[];let o=Math.floor((n.now-t)/864e5);return[`the ${e.ecosystem} shard is ${String(o)} days old (built ${e.generated}); its advisory data may be stale \u2014 connect online to refresh`]}function Uo(e,n,t){let o=kd(n.cacheDir,e.ecosystem,e.sha256,r=>new ie(r));if(o===void 0)throw new ie(`the cached index names ${e.ecosystem} shard ${e.sha256} but it is not in the cache \u2014 connect online to repopulate, or pass --shard <path>`);return{path:o.path,fromCache:!0,warnings:[...t,...Rd(e,n)],sequence:e.sequence}}async function Jg(e,n,t,o){let r=_s(t.cacheDir,e.ecosystem,e.sha256),s=Ht(r);if(s!==void 0&&Fo(s)===e.sha256)return{path:r,downloaded:!1};let a="no shard urls";for(let l of n){let i;try{i=await o.fetchShard(l,e.sizeBytes)}catch(u){a=Os(u);continue}let d=Fo(i);if(d!==e.sha256){a=`sha256 mismatch (expected ${e.sha256}, got ${d})`;continue}return jo(r,i),{path:r,downloaded:!0}}throw new ie(`could not fetch a verified ${e.ecosystem} shard from any mirror: ${a}`)}function Zg(e,n,t){if(e instanceof Pe)throw e;if(e instanceof Jt){if(n===void 0)throw new ie(`the control plane refused to serve an index at or above the requested sequence, and there is no cached ${t.ecosystem} shard \u2014 pass --shard <path>`);return Uo(n,t,["the control plane holds nothing newer than the cached shard index; keeping the cached shard"])}if(n===void 0)throw new Gn(`no cached ${t.ecosystem} shard and the delivery seam is unreachable (${Os(e)}) \u2014 cannot scan without vulnerability data; connect once to populate the cache, or pass --shard <path>`);return Uo(n,t,[`could not refresh the shard index (${Os(e)}); using the cached shard`])}async function Pd(e,n){if(!e.activated)throw new ie("zero-config shard delivery is not yet available (ADR-063 token-gated delivery ships in P5) \u2014 pass --shard <path> or set CUPEL_SHARD_NPM");let t=n??Xg(e.shardHosts);if(!dd(e.pubkeys))throw new ie("zero-config shard delivery is not activated in this build \u2014 pass --shard <path> or set CUPEL_SHARD_NPM");let o=Yg(e);if(e.offline){if(o===void 0)throw new Gn(`--offline and no cached ${e.ecosystem} shard \u2014 connect once to populate the cache, or pass --shard <path>`);return Uo(o,e,[])}let r=await yd(e.credential),s;try{s=await t.resolve({host:e.indexHost,token:r,ecosystem:e.ecosystem,sequenceFloor:o?.sequence??0})}catch(d){return Zg(d,o,e)}if(!xs(s.index,s.sig,e.pubkeys))throw new ie("shard index signature did not verify against any pinned key");let a=Ss(s.index,Nd(e));if(o!==void 0&&a.sequence<o.sequence)return Uo(o,e,[`refusing a rolled-back shard index (served sequence ${String(a.sequence)} < cached ${String(o.sequence)}); keeping the newer cached shard`]);let l=_d(s.shardUrls,a.urls,e.shardHosts),i=await Jg(a,l,e,t);return jo(Ko.join(e.cacheDir,vs),s.index),jo(Ko.join(e.cacheDir,Is),s.sig),{path:i.path,fromCache:!i.downloaded,warnings:Rd(a,e),sequence:a.sequence}}var Qg="https://api.cupel.sh",$d=".actions.githubusercontent.com",ey=8192;function Od(e){return e.kind==="oidc"||/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/u.test(e.value)?"oidc":"token"}var Je=class extends Error{constructor(n){super(n),this.name="PushCredentialError"}};function ny(e){let n;try{n=new URL(e).hostname}catch{throw new Je("ACTIONS_ID_TOKEN_REQUEST_URL is not a URL")}let t=$d.slice(1);if(n!==t&&!n.endsWith($d))throw new Je(`refusing to send the ID-token request credential to unpinned host ${n}`);try{return Ye(e,new Set([n]))}catch{throw new Je(`ACTIONS_ID_TOKEN_REQUEST_URL for host ${n} is not a plain https authority`)}}async function zo(e,n){let t=e.ACTIONS_ID_TOKEN_REQUEST_URL,o=e.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(t===void 0||t==="")throw new Je("ACTIONS_ID_TOKEN_REQUEST_URL is not set \u2014 the workflow needs `permissions: id-token: write`");if(o===void 0||o==="")throw new Je("ACTIONS_ID_TOKEN_REQUEST_TOKEN is not set \u2014 the workflow needs `permissions: id-token: write`");let r=ny(t);r.searchParams.set("audience",Qg);let s;try{s=await n(r.href,{authorization:`Bearer ${o}`,accept:"application/json","user-agent":"cupel"})}catch{throw new Je("the ID-token request failed")}if(s.length>ey)throw new Je("the ID-token response was larger than a token can be");let a;try{a=JSON.parse(s)}catch{throw new Je("the ID-token response was not JSON")}let l=typeof a=="object"&&a!==null?a.value:void 0;if(typeof l!="string"||l.length===0)throw new Je("the ID-token response carried no token");return l}async function Cd(e,n,t={}){let o=e.CUPEL_TOKEN!==void 0&&e.CUPEL_TOKEN!=="",r=e.ACTIONS_ID_TOKEN_REQUEST_URL!==void 0&&e.ACTIONS_ID_TOKEN_REQUEST_URL!=="";if(t.auth==="token"){if(!o)throw new Je("--auth=token, but CUPEL_TOKEN is not set");return{kind:"token",value:e.CUPEL_TOKEN??""}}if(t.auth==="oidc")return{kind:"oidc",value:await zo(e,n)};if(o)return r&&t.warn?.("both CUPEL_TOKEN and GitHub Actions OIDC are available; using CUPEL_TOKEN. Remove the secret to use keyless auth, or pass --auth=oidc."),{kind:"token",value:e.CUPEL_TOKEN??""};if(r)return{kind:"oidc",value:await zo(e,n)};throw new Je("no credential for the findings push: set CUPEL_TOKEN, or add `permissions: id-token: write` to the workflow")}var Cs="api.cupel.sh",ty=`https://${Cs}/v1/findings`,oy=64*1024,Wo=8*1024*1024,ry=3e4,Cn=class extends Error{constructor(n){super(n),this.name="PushError"}};async function Md(e,n,t,o={}){if(e.length>Wo)throw new Cn(`findings payload is ${String(e.length)} bytes, over the ${String(Wo)}-byte limit`);let r=Ye(ty,new Set([Cs])),s;try{s=await t(r.href,{authorization:`Bearer ${n}`,"content-type":"application/json","user-agent":"cupel"},e,o.timeoutMs??ry)}catch{throw new Cn(`the findings push to ${Cs} failed`)}if(s.body.length>oy)throw new Cn("the control plane returned a response larger than it should");if(!(s.status===202||s.status===200))throw s.status===401||s.status===403?new Cn("the control plane rejected the credential \u2014 check CUPEL_TOKEN, or that the workflow grants `permissions: id-token: write` and the repository is connected in the dashboard"):s.status===400?new Cn("the control plane rejected the findings payload as malformed"):new Cn(`the findings push was refused with status ${String(s.status)}`)}var sy=64*1024,iy=64*1024,Td=async(e,n,t,o)=>{if(Buffer.byteLength(t,"utf8")>Wo)throw new Error("findings payload is over the size limit");return await Vt("POST",e,{...n,"content-length":String(Buffer.byteLength(t,"utf8"))},t,iy,o)};async function Vo(e,n){let t=await Vt("GET",e,n,void 0,sy,15e3);if(t.status!==200)throw new Error(`the ID-token request was refused with status ${String(t.status)}`);return t.body}var dy=720*60*60*1e3,cy=Number(Fn);function Dd(e){let n=process.env.CUPEL_SHARD_PYPI;return e??(n!==void 0&&n!==""?n:void 0)}function Ld(e){let n=process.env.CUPEL_SHARD_NPM,t=e??(n!==void 0&&n!==""?n:void 0);if(t===void 0)throw new an("no npm shard configured \u2014 pass --shard <path> or set CUPEL_SHARD_NPM (zero-config token-gated delivery ships in P5 \u2014 ADR-063)");return t}async function Ms(e){let n=e.ecosystem??"npm",t=await Pd({ecosystem:n,activated:!0,pubkeys:wd,indexHost:Ed,shardHosts:Bo,credential:gd(process.env,()=>zo(process.env,Vo),()=>md(process.env)),cacheDir:n==="npm"?As():ly.join(As(),n),offline:e.offline,now:Date.now(),maxAgeMs:dy,supportedDbSchemaVersion:cy});for(let o of t.warnings)process.stderr.write(`cupel: ${o}
|
|
36
|
+
`);return{path:t.path,sequence:t.sequence}}var uy=9,fy={maxFindings:2e4,maxPathSteps:512,maxUnresolvedSites:131072,maxStringLength:4096,maxReasonLength:8192,maxAdvisories:2e4,maxAdvisoryRanges:64,maxAdvisoryDetails:8e3},vn=class extends Error{constructor(n){super(n),this.name="PayloadError"}};function Ts(e){return{path:e.path,start:e.start,end:e.end}}function py(e){if(e.tier==="unknown"&&e.unknownKind===void 0)throw new vn(`finding ${e.advisoryId} is unknown with no kind \u2014 an unknown without its kind is a hedge`);let n=e.tier==="unknown"?e.unknownKind:null,t=e.modelId??null,o=e.modelPromotedFromKind??null;if(t===null!=(o===null))throw new vn(`finding ${e.advisoryId} carries half a model provenance \u2014 the model and the kind it promoted from travel together`);if(t!==null&&e.tier!=="reachable-low")throw new vn(`finding ${e.advisoryId} claims model provenance on ${e.tier}; only reachable-low can`);return{advisoryId:e.advisoryId,displayId:e.displayId,packageName:e.packageName,packageVersion:e.version,ecosystem:e.ecosystem,symbolName:e.symbolName,severity:e.severity,tier:e.tier,reason:e.reason,unknownKind:n,unknownOwner:n===null?null:Js(n),basis:e.basis??null,path:e.path===void 0?null:e.path.map(r=>({functionName:r.functionName??null,modulePath:r.modulePath})),unresolvedSites:e.unresolvedEvidence.own.map(Ts),unresolvedSets:[...e.unresolvedEvidence.sets],modelId:t,modelPromotedFromKind:o,surfaceComplete:e.surfaceComplete??null}}var my="";function hy(e){let n=[e.advisoryId,e.packageName,e.packageVersion,e.symbolName??""];return(e.ecosystem==="npm"?n:[...n,e.ecosystem]).join(my)}function gy(e){let n=new Map;for(let t of e){let o=hy(t),r=n.get(o);if(r===void 0){n.set(o,t);continue}if(r.tier!==t.tier||r.unknownKind!==t.unknownKind)throw new vn(`the scan produced two different verdicts for ${t.advisoryId} on ${t.packageName}@${t.packageVersion}${t.symbolName===null?"":` (${t.symbolName})`}: ${r.tier} and ${t.tier}. They share one finding identity, so only the second would be stored \u2014 refusing to push rather than let a verdict be dropped. This is a cupel bug; please report it.`)}return[...n.values()]}function yy(e){let n=fy,t=(o,r,s)=>{throw new vn(`${o} has ${String(r)} entries, over the ${String(s)} the control plane accepts`)};e.findings.length>n.maxFindings&&t("the findings list",e.findings.length,n.maxFindings);for(let o of["dispatch","load"]){let r=e.unresolved[o].length;r>n.maxUnresolvedSites&&t(`the app-global ${o} set`,r,n.maxUnresolvedSites)}for(let o of e.findings)o.path!==null&&o.path.length>n.maxPathSteps&&t(`the call path of finding ${o.advisoryId}`,o.path.length,n.maxPathSteps),o.unresolvedSites.length>n.maxUnresolvedSites&&t(`the unresolved sites of finding ${o.advisoryId}`,o.unresolvedSites.length,n.maxUnresolvedSites);e.advisories.length>n.maxAdvisories&&t("the advisories list",e.advisories.length,n.maxAdvisories);for(let o of e.advisories){if(o.ranges.length>n.maxAdvisoryRanges&&t(`the ranges of advisory ${o.id}`,o.ranges.length,n.maxAdvisoryRanges),o.summary!==null&&o.summary.length>n.maxStringLength)throw new vn(`the summary of advisory ${o.id} is ${String(o.summary.length)} characters, over the ${String(n.maxStringLength)} the control plane accepts`);if(o.details!==null&&o.details.length>n.maxAdvisoryDetails)throw new vn(`the description of advisory ${o.id} is ${String(o.details.length)} characters, over the ${String(n.maxAdvisoryDetails)} the control plane accepts`)}}function xy(e,n){let t=new Set(n.map(o=>o.advisoryId));return e.advisories.filter(o=>t.has(o.advisory.id)).map(o=>({id:o.advisory.id,cveId:o.advisory.cveId,osvId:o.advisory.osvId,summary:o.advisory.summary,details:o.advisory.details??null,severity:o.advisory.severity,published:o.advisory.published,source:o.advisory.source,ranges:o.ranges.map(r=>({packageName:r.packageName,introduced:r.introduced,fixed:r.fixed,lastAffected:r.lastAffected}))}))}function Fd(e,n){let t=gy(e.findings.map(py)),o={version:uy,scanId:n.scanId,scannedAt:n.scannedAt,context:{shardSequence:n.shardSequence,shardSchemaVersion:e.shardSchemaVersion,ecosystem:n.ecosystem,analysisAborted:e.analysisAborted,entrypointCount:e.entrypointSources.length,installedPackageCount:e.installed.packages.length},findings:t,unresolved:{dispatch:e.unresolved.dispatch.map(Ts),load:e.unresolved.load.map(Ts)},advisories:xy(e,t)};return yy(o),o}function jd(e){let n=new Set(e.installed.packages.map(o=>o.ecosystem??"npm")),t=["npm","PyPI"].filter(o=>n.has(o));return t.length===0?"npm":t.join("+")}function Sy(e){return e.counts["not-reachable"]===0?" (ignorable)":e.findings.some(t=>t.tier==="not-reachable"&&t.basis==="loader-assumption")?" (assumed: no dependency loader loads them)":" (ignorable)"}var by={"reachable-high":"HIGH ","reachable-medium":"MED ","reachable-low":"LOW "},Bd=4,Ds=3,Ls=10,Kd={"no-entrypoint":"no entrypoint analyzed \u2014 pass --entry <file> or declare main","analyzer-crash":"cupel's analyzer produced no graph \u2014 please report this","version-undecidable":"installed version is not an exact x.y.z; pin a release to get a verdict","db-gap":"no symbol data for the advisory yet","unverified-symbol":"candidate symbol named but not gate-certified","symbol-unsupported":"the trigger is a property access or pattern, not a call","dep-opaque":"the corridor runs through dependency bodies cupel does not analyze","dynamic-load":"non-literal require/import or loader escape in reach",dispatch:"unresolved call target in reach","resolution-divergence":"cupel may be analyzing a different file than Node runs","analysis-cap":"cupel hit a budget or could not parse a file in reach","coverage-gap":"cupel's dependency enumeration was incomplete \u2014 packages may be missing","incomplete-surface":"the named symbols are not reached, but the advisory's symbol set is known incomplete \u2014 an unnamed one may be"},ky="(symbol set known incomplete)";function Ey(e){let n=(e.path??[]).map(t=>W(t.functionName??"<anon>"));return n.length>0?n.join(" \u2192 "):"(no path)"}function Ud(e){return[...new Set(e.unresolvedSites.map(n=>n.path).filter(n=>n!==""))]}function wy(e){let n=e.findings.filter(d=>d.tier==="unknown"&&d.unknownKind!==void 0);if(n.length===0)return[];let t=new Map;for(let d of n){let u=t.get(d.unknownKind)??[];u.push(d),t.set(d.unknownKind,u)}let o={cupel:0,project:0};for(let[d,u]of t)o[Ve[d]]+=u.length;let r=[];r.push(`\u2753 Unknown (${String(n.length)}) \u2014 cupel could NOT decide reachability. This is not a clean result.`);let s=(d,u)=>{if(o[d]===0)return;r.push(""),r.push(` ${u} (${String(o[d])}):`);let p=[...t.entries()].filter(([m])=>Ve[m]===d).sort((m,g)=>g[1].length-m[1].length||m[0].localeCompare(g[0])),f=p.slice(0,Bd);for(let[m,g]of f){let y=d==="project"?[...new Set(g.flatMap(Ud))]:[],b=y.slice(0,Ds).map(W).join(", "),x=y.length>Ds?` (+${String(y.length-Ds)} more files)`:"";r.push(` ${m.padEnd(21)} ${String(g.length).padStart(4)} ${Kd[m]}`+(b!==""?`
|
|
37
|
+
${b}${x}`:""))}for(let[m,g]of p.slice(Bd))r.push(` ${m.padEnd(21)} ${String(g.length).padStart(4)} ${Kd[m]}`)};s("project","Your code \u2014 a change on your side would produce a real verdict"),s("cupel","cupel's gap \u2014 nothing you can do today");let a=new Map;for(let d of n)if(Ve[d.unknownKind]==="project")for(let u of Ud(d))a.set(u,(a.get(u)??0)+1);let l=[...a.entries()].sort((d,u)=>u[1]-d[1]||d[0].localeCompare(u[0]))[0];l!==void 0&&o.project>0&&(r.push(""),r.push(` \u279C Start here: ${W(l[0])} appears in ${String(l[1])} of your ${String(o.project)} finding(s), across ${String(a.size)} file(s) total. A finding is decided only once EVERY site it lists resolves.`));let i=n.filter(d=>Ve[d.unknownKind]==="project");if(i.length>0){r.push("");for(let d of i.slice(0,Ls))r.push(` ${W(d.displayId)} ${W(d.packageName)}@${W(d.version)} [${d.unknownKind}] ${W(d.reason)}`);i.length>Ls&&r.push(` \u2026 and ${String(i.length-Ls)} more`)}return r.push(""),r}function zd(e){let n=[],t=e.counts,o=e.findings.filter(d=>d.tier==="reachable-high"||d.tier==="reachable-medium"||d.tier==="reachable-low");if(n.push(`cupel scan: ${W(e.dir)}`),n.push(` ${e.installed.packages.length} installed packages (${e.installed.source}); shard schema v${e.shardSchemaVersion}`),n.push(""),e.entrypointSources.length>0){let d=e.entrypointSources.slice(0,8);n.push(`\u{1F4CD} Entrypoints analyzed (${String(e.entrypointSources.length)}): `+d.map(u=>`${W(u.entrypoint)} [${W(u.source)}]`).join(", ")+(e.entrypointSources.length>d.length?`, \u2026 and ${String(e.entrypointSources.length-d.length)} more`:"")),n.push("")}if(e.entrypointObservations.length>0){let d=new Map;for(let u of e.entrypointObservations)d.set(u.kind,(d.get(u.kind)??0)+1);n.push("\u2139\uFE0F index.html scripts not seeded: "+[...d.entries()].map(([u,p])=>`${String(p)} ${u}`).join(", ")+` (${W(e.entrypointObservations[0]?.detail??"")}${e.entrypointObservations.length>1?", \u2026":""})`),n.push("")}if(e.rootSet.budget!=="not-attempted"){let d=e.rootSet,u=d.roots.slice(0,8);if(n.push(`\u{1F5C2} Project roots (${String(d.counts.rootsAdmitted)}): `+u.map(m=>`${W(m.rel===""?".":m.rel)} [${m.witnesses.join("+")}${m.ecosystem==="PyPI"?"; PyPI":m.alsoPython===!0?"; npm+PyPI":""}]`).join(", ")+(d.roots.length>u.length?`, \u2026 and ${String(d.roots.length-u.length)} more`:"")),d.observations.length>0){let m=new Map;for(let g of d.observations)m.set(g.kind,(m.get(g.kind)??0)+1);n.push(" not admitted: "+[...m.entries()].map(([g,y])=>`${String(y)} ${g}`).join(", "))}n.push(` walk: ${String(d.counts.dirsWalked)} dirs, ${String(d.counts.manifestsSeen)} manifests seen, ${String(d.counts.dotDirectoriesSkipped)} dot-dirs skipped \u2014 budget ${d.budget}`);let p=e.installed.perRoot.filter(m=>m.rootRel!=="");p.length>0&&n.push(` enumerated (${String(p.length)} nested root${p.length===1?"":"s"}): `+p.slice(0,8).map(m=>`${W(m.rootRel)} (${String(m.packages.length)} packages, ${m.source})`).join(", ")+(p.length>8?`, \u2026 and ${String(p.length-8)} more`:""));let f=dt(d,e.entrypointSources);f.length>0&&n.push(` NOT analyzed (${String(f.length)}): ${W(Xr(f.map(m=>m.rel===""?".":m.rel)))} \u2014 code there can load any installed package, so every not-reachable in this scan is capped at unknown until they are analyzed`),d.budget!=="complete"&&d.budget!=="not-attempted"&&n.push(` the walk did not finish (${d.budget}) \u2014 a root with its own install may have been missed; every not-reachable in this scan is capped at unknown`),n.push("")}if(e.entrypointGaps.length>0){n.push(`\u26A0\uFE0F Start command(s) cupel could not resolve to an entry file (${String(e.entrypointGaps.length)}) \u2014 that code was NOT analyzed:`);for(let d of e.entrypointGaps.slice(0,5))n.push(` - ${W(d.source)} (${W(d.file)}): ${W(d.detail)}`);e.entrypointGaps.length>5&&n.push(` \u2026 and ${String(e.entrypointGaps.length-5)} more`),n.push(" Fix: make it a direct `node <file.js>` invocation cupel can read. --entry <file> analyzes that code too, but verdicts stay capped while the command is unreadable."),n.push("")}e.rejectedEntries.length>0&&(n.push("\u26A0\uFE0F Ignored --entry (did not resolve to a file inside the app root): "+e.rejectedEntries.map(W).join(", ")),n.push("")),e.analysisAborted==="no-entrypoint"?(n.push("\u{1F6D1} No entrypoint analyzed \u2014 this scan is NOT a clean bill of health."),n.push(" No app entrypoint was found (no --entry; package.json declares no main/bin/exports; no index.js; no usable scripts.start or Procfile command), so cupel analyzed ZERO application code and every finding below is capped at `unknown`, never `not-reachable`."),n.push(e.framework===null?' Fix: pass --entry <file> (the file your start script or Procfile runs, e.g. --entry server.js), or declare "main" in package.json.':` ${Sr(e.framework)}`),n.push("")):e.analysisAborted==="analyzer-crash"&&(n.push("\u{1F6D1} cupel's analyzer failed on this project \u2014 this scan is NOT a clean bill of health."),n.push(" An entrypoint WAS found, but the analyzer produced no module graph, so cupel analyzed ZERO application code and every finding below is capped at `unknown`, never `not-reachable`."),n.push(' Fix: this is a cupel bug \u2014 please report it at https://github.com/cupel-sh/cupel/issues (the "Analysis incomplete" diagnostics below name the file). `--entry` will not help.'),n.push(""));let r=e.installed.gaps,s=r.find(d=>d.kind==="no-enumeration")??null;s!==null&&(n.push("\u{1F6D1} No dependency enumerated \u2014 this scan is NOT a clean bill of health."),n.push(` [no-enumeration] ${W(s.detail)}`),n.push(" cupel saw ZERO dependencies, so no advisory could be matched and nothing below is a verdict about your dependencies. Commit a lockfile (package-lock.json, yarn.lock or pnpm-lock.yaml) or install before scanning."),n.push(""));let a=r.filter(d=>d!==s);if(a.length>0){n.push(`\u{1F573}\uFE0F Dependency enumeration INCOMPLETE (${String(a.length)}) \u2014 packages may be missing from this scan entirely; it is NOT a clean bill of health:`);for(let d of a.slice(0,10))n.push(` - [${W(d.kind)}] ${W(d.detail)}`);a.length>10&&n.push(` \u2026 and ${String(a.length-10)} more`),n.push("")}let l=new Set(r.map(d=>d.detail)),i=[...e.analyzerDiagnostics.map(d=>`${W(d.code)}: ${W(d.detail)}`),...e.pythonDiagnostics.map(d=>`python: ${W(d)}`),...e.installed.diagnostics.filter(d=>!l.has(d)).map(W)];if(i.length>0){n.push(`\u26A0\uFE0F Analysis incomplete (${String(i.length)}) \u2014 verdicts are conservative:`);for(let d of i.slice(0,10))n.push(` - ${d}`);i.length>10&&n.push(` \u2026 and ${String(i.length-10)} more`),n.push("")}if(o.length>0){n.push(`\u{1F3AF} Reachable (${String(o.length)}) \u2014 fix these:`);for(let d of o)n.push(` ${by[d.tier]} ${W(d.displayId)} ${W(d.packageName)}@${W(d.version)} ${W(d.symbolName??"")}`+(d.surfaceComplete===!1?` ${ky}`:"")),n.push(` path: ${Ey(d)}`);n.push("")}return n.push(...wy(e)),n.push(`Summary: ${String(t["reachable-high"])} high, ${String(t["reachable-medium"])} medium, ${String(t["reachable-low"])} low (modeled), ${String(t.unknown)} unknown, ${String(t["not-reachable"])} not-reachable${Sy(e)}, ${String(t["not-affected"])} not-affected.`),n.join(`
|
|
38
|
+
`)}import{createHash as vy}from"node:crypto";var Iy="https://json.schemastore.org/sarif-2.1.0.json",Wd="cupel-reachability",Fs=new Set(["dispatch","dynamic-load","coverage-gap"]);function Ay(e,n){return(e==="no-entrypoint"||e==="analyzer-crash")&&n===e}var _y=500,Ny=10;function Ry(e){return e.counts["not-reachable"]===0?{}:e.findings.some(t=>t.tier==="not-reachable"&&t.basis==="loader-assumption")?{denialBasis:{value:"loader-assumption",assumption:"no dynamic loader inside a dependency (a non-literal require/import(), eval/Function, a reflective or captured loader, or a global-object loader) loads this package at runtime"}}:{denialBasis:{value:"complete"}}}function Py(e,n){return`${e}::${n}`}function $y(e){switch((e??"").toUpperCase()){case"CRITICAL":return"9.8";case"HIGH":return"7.5";case"MODERATE":case"MEDIUM":return"5.0";case"LOW":return"2.0";default:return}}function Oy(e){let n=e.path?.find(t=>t.modulePath!=="")?.modulePath??e.packageLocation??"";return vy("sha256").update(`${e.displayId}:${e.packageName}:${e.symbolName??""}:${n}`).digest("hex").slice(0,32)}function Cy(e){return e.tier==="reachable-high"||e.tier==="reachable-medium"||e.tier==="reachable-low"?!0:e.tier!=="unknown"||e.unknownKind===void 0?!1:Fs.has(e.unknownKind)}var Vd={"no-entrypoint":"no application entrypoint was analyzed, so no finding below is a reachability result","analyzer-crash":"cupel's analyzer produced no module graph for this project","version-undecidable":"the installed version could not be compared against the advisory range (not an exact x.y.z)","db-gap":"cupel has no vulnerable-symbol data for these advisories yet (package-level only)","unverified-symbol":"cupel has a named but uncertified candidate symbol for these advisories; the name is in the finding","symbol-unsupported":"the vulnerable trigger is a property access or a pattern, not a call \u2014 cupel's call graph cannot express it","dep-opaque":"the corridor runs through dependency bodies cupel does not analyze (ADR-011 analysis depth)","dynamic-load":"code in reach can load modules cupel cannot enumerate",dispatch:"a call site in reach has no statically resolvable target","resolution-divergence":"cupel may be analyzing a different file than Node runs, or could not follow an import; the per-file diagnostics name each one","analysis-cap":"cupel hit a budget, could not parse a file in reach, or could not read a start command; the per-file diagnostics name each one","incomplete-surface":"cupel certified some of these advisories' symbols and none of them is reached \u2014 but the symbol set is known to be incomplete (ADR-087), so an unnamed symbol may still be; not a clean","coverage-gap":"cupel's dependency enumeration was incomplete, so packages may be missing from this scan entirely \u2014 never read this as clean"};function qd(e){let n=[],t=new Map,o=[];for(let i of e.findings){if(!Cy(i))continue;let d=Py(i.displayId,i.packageName);if(!t.has(d)){t.set(d,n.length);let b=$y(i.severity);n.push({id:W(d),properties:{tags:i.unknownKind==="coverage-gap"?["security","coverage-gap",`gap/${W(i.packageName)}`]:["security","reachability",`package/${W(i.packageName)}`],...b!==void 0?{"security-severity":b}:{}}})}let u=i.tier==="reachable-high"||i.tier==="reachable-medium"||i.tier==="reachable-low",p=i.path??[],f=p.find(b=>b.modulePath!==""),m=[...new Set(i.unresolvedSites.map(b=>b.path).filter(b=>b!==""))],g=u?f!==void 0?{physicalLocation:{artifactLocation:{uri:W(f.modulePath)}},message:{text:`calls ${W(i.symbolName??"the vulnerable symbol")}`}}:{physicalLocation:{artifactLocation:{uri:W(i.packageLocation??"package-lock.json")}}}:m[0]!==void 0?{physicalLocation:{artifactLocation:{uri:W(m[0])}},message:{text:`unresolved ${W(i.unknownKind??"access")} in reach`}}:{physicalLocation:{artifactLocation:{uri:W(i.packageLocation??(i.unknownKind==="coverage-gap"?"package.json":"package-lock.json"))}}},y=u?p.map(b=>({physicalLocation:{artifactLocation:{uri:W(b.modulePath||"package-lock.json")}},message:{text:W(b.functionName??"<step>")}})):m.slice(1,Ny+1).map(b=>({physicalLocation:{artifactLocation:{uri:W(b)}},message:{text:"also blocked here"}}));o.push({ruleId:W(d),ruleIndex:t.get(d),level:u?"error":"warning",message:{text:W(`[${i.tier}] ${i.displayId} in ${i.packageName}@${i.version}`+(i.symbolName!==null?` \u2014 reaches ${i.symbolName}`:"")+(i.surfaceComplete===!1?" (symbol set known incomplete)":"")+`. ${i.reason}`)},locations:[g],...y.length>0?{relatedLocations:y}:{},partialFingerprints:{"cupelReachability/v1":Oy(i)},properties:{tier:i.tier,advisoryId:W(i.advisoryId),...i.surfaceComplete===!1?{surfaceComplete:!1}:{},...i.modelId!==void 0?{modelId:W(i.modelId),modelPromotedFromKind:i.modelPromotedFromKind}:{},...i.unknownKind!==void 0?{unknownKind:i.unknownKind,unknownOwner:Ve[i.unknownKind],unresolvedSiteCount:i.unresolvedSites.length}:{},...i.adr105!==void 0?{adr105:i.adr105}:{}}})}let r=new Map,s=new Map;for(let i of e.findings){if(i.tier!=="unknown"||i.unknownKind===void 0||(r.set(i.unknownKind,(r.get(i.unknownKind)??0)+1),Fs.has(i.unknownKind)))continue;let d=s.get(i.unknownKind)??[];d.length<_y&&d.push({advisory:W(i.displayId),package:W(i.packageName),version:W(i.version)}),s.set(i.unknownKind,d)}let a={cupel:0,project:0};for(let[i,d]of r)a[Ve[i]]+=d;let l={};for(let[i,d]of s){let u=r.get(i)??d.length;l[i]={count:u,owner:Ve[i],note:Vd[i],truncated:u>d.length,advisories:d}}return{$schema:Iy,version:"2.1.0",runs:[{tool:{driver:{name:"cupel",informationUri:"https://cupel.sh",rules:n}},automationDetails:{id:Wd},invocations:[{executionSuccessful:e.analysisAborted===null&&e.analyzerDiagnostics.length===0&&e.pythonDiagnostics.length===0&&e.installed.diagnostics.length===0,toolExecutionNotifications:[...e.analysisAborted==="no-entrypoint"?[{descriptor:{id:"no-entrypoint"},level:"error",message:{text:"no app entrypoint analyzed (no --entry; package.json declares no main/bin/exports; no index.js; no usable scripts.start or Procfile command); ZERO application code was analyzed \u2014 every finding is capped at unknown, not a clean result. Pass --entry <file> or declare main."}}]:[],...e.analysisAborted==="analyzer-crash"?[{descriptor:{id:"analyzer-crash"},level:"error",message:{text:"an app entrypoint was found but cupel's analyzer produced NO module graph; ZERO application code was analyzed \u2014 every finding is capped at unknown, not a clean result. This is a cupel bug: please report it (the analyzer diagnostics below name the file)."}}]:[],...e.entrypointSources.length>0?[{descriptor:{id:"entrypoints"},level:"note",message:{text:W(`analyzed ${String(e.entrypointSources.length)} entrypoint(s): `+e.entrypointSources.slice(0,20).map(i=>`${i.entrypoint} (${i.source})`).join(", ")+(e.entrypointSources.length>20?", \u2026":""))}}]:[],...[...r.keys()].filter(i=>!Fs.has(i)&&!Ay(i,e.analysisAborted)).sort().map(i=>({descriptor:{id:`unknown-${i}`},level:"warning",message:{text:`${String(r.get(i)??0)} finding(s) are unknown because ${Vd[i]} (owner: ${Ve[i]}). These are counted in counts.unknown and itemised in run.properties.unknown.grouped["${i}"]; they are NOT a clean result.`}})),...e.entrypointGaps.slice(0,20).map(i=>({descriptor:{id:"entry-source-unresolved"},level:"warning",message:{text:W(`${i.source} (${i.file}): ${i.detail}`)}})),...e.rejectedEntries.map(i=>({descriptor:{id:"entry-rejected"},level:"warning",message:{text:W(`--entry did not resolve to a file inside the app root: ${i}`)}})),...e.entrypointObservations.map(i=>({descriptor:{id:`entrypoint-observation:${i.kind}`},level:"note",message:{text:W(`${i.detail} (${i.file})`)}})),...e.analyzerDiagnostics.map(i=>({descriptor:{id:i.code},level:"warning",message:{text:W(`${i.detail}${i.reason===void 0?"":` [reason: ${i.reason}]`} (${i.path})`)}})),...e.pythonDiagnostics.map(i=>({descriptor:{id:"python-analysis"},level:"warning",message:{text:W(i)}})),...e.installed.diagnostics.map(i=>({descriptor:{id:"resolve"},level:"warning",message:{text:W(i)}}))]}],results:o,properties:{category:Wd,summary:e.counts,installed:{count:e.installed.packages.length,byRoot:e.installed.perRoot.slice(0,64).map(i=>({path:W(i.rootRel),count:i.packages.length,source:i.source}))},...e.rootSet.budget!=="not-attempted"?{roots:{budget:e.rootSet.budget,unanalyzed:{count:dt(e.rootSet,e.entrypointSources).length,named:dt(e.rootSet,e.entrypointSources).slice(0,8).map(i=>W(i.rel===""?".":i.rel))},analyzed:[...Lt(e.entrypointSources)].sort().slice(0,64).map(i=>W(i===""?".":i)),counts:e.rootSet.counts,admitted:e.rootSet.roots.slice(0,64).map(i=>({path:W(i.rel),witnesses:i.witnesses,...i.manifestRefused?{manifestRefused:!0}:{},...i.ecosystem!==void 0?{ecosystem:i.ecosystem}:{},...i.alsoPython===!0?{alsoPython:!0}:{}})),observations:e.rootSet.observations.slice(0,64).map(i=>({kind:i.kind,path:W(i.rel)}))}}:{},...Ry(e),unknown:{total:e.counts.unknown,byKind:Object.fromEntries([...r].sort((i,d)=>d[1]-i[1])),byOwner:a,grouped:l},dbCoverageGaps:e.findings.filter(i=>i.tier==="unknown"&&i.unknownKind==="db-gap").map(i=>({advisory:W(i.displayId),package:W(i.packageName),version:W(i.version)})),...e.adr105!==void 0?{adr105:{...e.adr105,findings:e.findings.filter(i=>i.adr105!==void 0).map(i=>({advisory:W(i.displayId),package:W(i.packageName),version:W(i.version),symbol:W(i.symbolName??""),tier:i.tier,...i.unknownKind!==void 0?{unknownKind:i.unknownKind}:{},...i.adr105}))}}:{}}}]}}process.removeAllListeners("warning");process.on("warning",e=>{e.name==="ExperimentalWarning"&&/SQLite/u.test(e.message)||process.stderr.write(`${e.name}: ${e.message}
|
|
39
|
+
`)});function Gd(){try{let e=My(Ly(new URL("../package.json",import.meta.url)),"utf8"),n=JSON.parse(e);if(typeof n=="object"&&n!==null&&"version"in n&&typeof n.version=="string")return n.version}catch{}return"0.0.0"}function Fy(e,n){let t=`${JSON.stringify(n,null,2)}
|
|
40
|
+
`,o=`${e}.tmp-${Hd(8).toString("hex")}`;Xd(o,t,{encoding:"utf8",flag:"wx"}),Ty(o,e)}async function jy(e){let n=od(e),t=n.shard!==void 0||(process.env.CUPEL_SHARD_NPM??"")!=="",o=t?{path:Ld(n.shard),sequence:null}:await Ms({offline:n.offline}),r=o.path,a=Dd(n.shardPypi);if(a===void 0&&!t)try{a=(await Ms({offline:n.offline,ecosystem:"pypi"})).path}catch(i){if(i instanceof Xt||i instanceof Gn)process.stderr.write(`cupel: no PyPI shard available (${i.message}); Python distributions, if any, will be reported as not assessed
|
|
41
|
+
`);else throw i}let l=gs({dir:n.dir,shardPath:r,...a!==void 0?{shardPathPypi:a}:{},failOnReachable:n.failOnReachable,requireCompleteDenial:n.requireCompleteDenial,failOnUnknown:n.failOnUnknown,entry:n.entry,root:n.root,...n.summaryShadow!==void 0?{summaryShadow:n.summaryShadow}:{},...n.modelShadow!==void 0&&n.modelShadowOut!==void 0?{modelShadow:{claimsPath:n.modelShadow,outPath:n.modelShadowOut,widened:n.modelShadowWidened}}:{},...n.bindingShadow&&n.bindingShadowOut!==void 0?{bindingShadow:{outPath:n.bindingShadowOut}}:{},...n.partialRows?{partialRows:!0}:{},tsconfigPaths:n.tsconfigPaths});if(process.stdout.write(`${zd(l)}
|
|
42
|
+
`),l.modelLane!==void 0){let i=l.modelLane.notes.length>0?` (${l.modelLane.notes.map(d=>W(d)).join("; ")})`:"";process.stdout.write(`boundary models: ${String(l.modelLane.active)}/${String(l.modelLane.stored)} active, ${String(l.modelLane.promoted)} promoted to reachable-low${i}
|
|
43
|
+
`)}if(n.summaryShadow!==void 0&&l.summaryShadow!==void 0){let i=Dy.join(n.summaryShadow,"shadow-report.json");Xd(i,`${JSON.stringify(l.summaryShadow,null,2)}
|
|
44
|
+
`),process.stdout.write(`summary-shadow: ${String(l.summaryShadow.records.length)} counterfactual record(s) -> ${i}
|
|
45
|
+
`)}if(l.modelShadow!==void 0&&n.modelShadowOut!==void 0){let i=l.modelShadow.records.filter(d=>d.wouldPromote).length;process.stdout.write(`model-shadow: ${String(i)}/${String(l.modelShadow.records.length)} wouldPromote -> ${n.modelShadowOut}
|
|
42
46
|
`)}if(l.bindingShadow!==void 0&&n.bindingShadowOut!==void 0&&process.stdout.write(`binding-shadow: ${String(l.bindingShadow.deltas)}/${String(l.bindingShadow.records.length)} verdict delta(s) -> ${n.bindingShadowOut}
|
|
43
|
-
`),n.sarif!==void 0&&
|
|
44
|
-
`)});try{await
|
|
45
|
-
`),l.exitCode===0?1:l.exitCode}let u=
|
|
46
|
-
`)}return l.exitCode}async function
|
|
47
|
-
`),1}if(e[0]==="login")return await
|
|
48
|
-
`),0):(process.stderr.write(`cupel: unknown command '${
|
|
49
|
-
`),process.stderr.write(`${
|
|
50
|
-
`),1)}
|
|
47
|
+
`),n.sarif!==void 0&&Fy(n.sarif,qd(l)),n.push){let i=Fd(l,{scanId:Hd(16).toString("hex"),scannedAt:new Date().toISOString(),ecosystem:jd(l),shardSequence:o.sequence}),d=await Cd(process.env,Vo,{...n.auth!==void 0?{auth:n.auth}:{},warn:p=>process.stderr.write(`cupel: ${p}
|
|
48
|
+
`)});try{await Md(JSON.stringify(i),d.value,Td)}catch(p){let f=p instanceof Error?p.message:String(p);return process.stderr.write(`cupel: ${f}
|
|
49
|
+
`),l.exitCode===0?1:l.exitCode}let u=o.sequence===null?" \u2014 shard version unverified, shown as unknown on the dashboard":"";process.stdout.write(`pushed ${String(i.findings.length)} finding(s) to api.cupel.sh (${Od(d)})${u}
|
|
50
|
+
`)}return l.exitCode}async function By(){let e=process.argv.slice(2);if(e[0]==="scan")try{return await jy(e.slice(1))}catch(t){let o=t instanceof Error?t.message:String(t);return process.stderr.write(`cupel scan: ${o}
|
|
51
|
+
`),1}if(e[0]==="login")return await Sd(e.slice(1));if(e[0]==="logout")return bd(e.slice(1));let n=e[0];return n===void 0||n==="help"||n==="--help"||n==="-h"?(process.stdout.write(`${ys(Gd())}
|
|
52
|
+
`),0):(process.stderr.write(`cupel: unknown command '${W(n)}'
|
|
53
|
+
`),process.stderr.write(`${ys(Gd())}
|
|
54
|
+
`),1)}By().then(e=>{process.exit(e)},e=>{let n=e instanceof Error?e.message:String(e);process.stderr.write(`cupel: ${n}
|
|
51
55
|
`),process.exit(1)});
|