@omfalos/mokosh 0.5.1 → 0.5.2

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/dist/index.mjs CHANGED
@@ -1,53 +1,61 @@
1
- var Pt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import Po from"path";import{fileURLToPath as Ro}from"url";var Io=()=>Ro(import.meta.url),Do=()=>Po.dirname(Io()),m=Do();import Ot from"fs";import Yr from"path";var Mo=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Rt=[];function Ge(t){Rt.push(t)}function Jr(t){return[...Mo,...Rt].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Ao=[".test.",".spec.","-test.","-spec."],It=[];function je(t){It.push(t)}function he(){return[...Ao,...It]}var Lo=["jest","vitest","playwright","cypress","@testing-library/"],Dt=[];function $e(t){Dt.push(t)}function Mt(){return[...Lo,...Dt]}var Vr=.8,At=Vr;function Lt(t){At=t}function _t(){return At}function We(){Rt.length=0,It.length=0,Dt.length=0,At=Vr}var _o=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function Gt(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=Yr.resolve(t);return Ot.existsSync(n)?n.endsWith(".json")?Qr(n):e?Xr(n):{}:{}}for(let n of _o){let s=Yr.resolve(t,n);if(Ot.existsSync(s)){if(n.endsWith(".json"))return Qr(s);if(e)return Xr(s)}}return{}}function Qr(t){return JSON.parse(Ot.readFileSync(t,"utf-8"))}function Xr(t){let e=Pt(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function Oo(t){We();for(let e of t.configMatchers??[])Ge(e);for(let e of t.testPatterns??[])je(e);for(let e of t.testLibraries??[])$e(e);t.barrelThreshold!==void 0&&Lt(t.barrelThreshold)}function Go(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases,additionalIgnoreDirs:t?.ignoreDirs}}var jt="mokosh-cache",$t="duplication-tokens.json",jo="graph.json",$o="workspace-graph.json",Wt="branch-graphs",I=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage",".pytest_cache","__pycache__",".gradle","target"],zt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".java",".kt",".kts",".scala",".sc",".groovy",".gradle",".feature",".md",".mdx"];import Wo from"fs";import Zr from"path";function zo(t,e){let r=Zr.resolve(t,e);try{let n=Wo.readFileSync(r,"utf-8"),s=JSON.parse(n),o=new Map;if(typeof s!="object"||s===null)return o;for(let[i,a]of Object.entries(s)){if(i==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Zr.relative(t,i);o.set(l,c)}return o}catch{return new Map}}var Bt={serialize(t){let e=["graph TD"],r=new Set;for(let n of t.nodes.values()){let s=`"${n.path}"`;for(let o of n.imports){if(!o.toPath)continue;let i=`"${o.toPath}"`,a=`${n.path} -> ${o.toPath}`;if(!r.has(a)){let c=o.isStyle?"-- styles -->":"-->";e.push(` ${s} ${c} ${i}`),r.add(a)}}}return e.join(`
2
- `)}};function qr(t){return Bt.serialize(t)}var se=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let r=new Set(this.nodes.keys());return e.filter(n=>!r.has(n))}findHighExportUsage(e){let r=[];for(let n of this.nodes.values()){if(n.maxExportUsage===void 0||n.maxExportUsage<e)continue;let s=n.imports.reduce((o,i)=>(i.exportUsageRatio??0)>(o?.exportUsageRatio??0)?i:o,null);r.push({path:n.path,maxExportUsage:n.maxExportUsage,tightestDep:s?.toPath??""})}return r.sort((n,s)=>s.maxExportUsage-n.maxExportUsage)}findCycles(e={}){let r=new Set(e.includeKinds??[]),n=[],s=new Set,o=new Set,i=[],a=c=>{s.add(c),o.add(c),i.push(c);let l=this.nodes.get(c);if(l){for(let p of l.imports)if(!(!p.toPath||p.isExternal)&&!(p.isSamePackage&&!r.has("samePackage"))&&!(p.isDocReference&&!r.has("docReference")))if(o.has(p.toPath)){let u=i.indexOf(p.toPath);n.push([...i.slice(u),p.toPath])}else s.has(p.toPath)||a(p.toPath)}o.delete(c),i.pop()};for(let c of this.nodes.keys())s.has(c)||a(c);return n}};import en from"fs";import Bo from"path";function Ht(t,e){let r=t.replace(/^\.\//,"");if(e.nodes.has(r))return r;let n=r.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(n)?n:null}function tn(t,e){if(typeof t=="string")return Ht(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=tn(r[n],e);if(s)return s}}return null}function Ho(t){if(!t)return"unknown";let e=t.trimStart();return e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":e.startsWith("type ")?"type":e.startsWith("namespace ")?"namespace":e.startsWith("const ")||e.startsWith("let ")||e.startsWith("var ")||e.startsWith("readonly ")?"const":e.startsWith("(")||e.startsWith("async ")||e.startsWith("function ")||e.includes("=>")?"function":"unknown"}function Uo(t,e){let r=new Set,n=new Set,s=[...e];for(;s.length;){let o=s.shift();if(n.has(o))continue;n.add(o);let i=t.nodes.get(o);if(i){for(let a of i.exports)r.add(a.name);for(let a of i.imports){if(a.type!=="re-export"||a.isExternal||!a.toPath)continue;if(!a.symbols?.length||a.symbols.includes("*")){let l=t.nodes.get(a.toPath);if(l)for(let p of l.exports)r.add(p.name);s.push(a.toPath)}else for(let l of a.symbols)r.add(l)}}}return r}function Ko(t,e){return rn(t,e)[0]??null}function rn(t,e){let r=[],n=Bo.join(e,"package.json");if(en.existsSync(n))try{let s=JSON.parse(en.readFileSync(n,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let o of Object.values(s.exports)){let i=tn(o,t);i&&!r.includes(i)&&r.push(i)}else if(typeof s.exports=="string"){let o=Ht(s.exports,t);o&&r.push(o)}if(r.length===0)for(let o of[s.main,s.module].filter(Boolean)){let i=Ht(o,t);i&&!r.includes(i)&&r.push(i)}}catch{}if(r.length===0){for(let s of["src/index.ts","src/index.js","index.ts","index.js"])if(t.nodes.has(s)){r.push(s);break}}return r}function Jo(t,e){let r=new Set(e);for(let n of e)t.traverse(n,s=>(r.add(s.path),!0),{direction:"outgoing"});return r}function Vo(t,e,r){let n=new Map;for(let s of e){if(r.includes(s))continue;let o=t.nodes.get(s);if(!o)continue;let i=o.category==="barrel";for(let a of o.exports){let c=n.get(a.name),l=!!(a.signature||a.doc);(!c||l&&!i)&&n.set(a.name,{file:s,symbol:a})}}return n}function Yo(t,e,r,n){let s=[];for(let o of t){let i=e.get(o),a=n.flatMap(u=>r.nodes.get(u)?.exports??[]).find(u=>u.name===o),c=i?.symbol??a,l=i?.file??n.find(u=>r.nodes.get(u)?.exports.some(g=>g.name===o))??n[0],p={name:o,definedIn:l,kind:Ho(c?.signature)};c?.doc&&(p.doc=c.doc),c?.signature&&(p.signature=c.signature),s.push(p)}return s.sort((o,i)=>o.name.localeCompare(i.name)),s}function Qo(t,e,r){let n=c=>t.nodes.get(c)?.category==="test",s=[...e].filter(c=>!r.includes(c)&&!n(c)),o=[...t.nodes.keys()].filter(c=>!e.has(c)),i=o.filter(c=>!n(c)),a=o.filter(c=>n(c));return{internalFiles:s,unreachableFromEntry:i,testFiles:a}}function Xo(t,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let l of e)if(!t.nodes.has(l))throw new Error(`Entry point not found in graph: ${l}`);let r=Jo(t,e),n=Vo(t,r,e),s=Uo(t,e),o=Yo(s,n,t,e),{internalFiles:i,unreachableFromEntry:a,testFiles:c}=Qo(t,r,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:c}}function Zo(t,e){let r=null,n=[];for(let o of t.nodes.values()){o.exports.some(i=>i.name===e)&&(r=o.path);for(let i of o.callEdges??[])i.to===e&&n.push({file:o.path,callerFunction:i.from})}let s=[];if(r){let o=t.nodes.get(r);for(let i of o?.callEdges??[])i.from===e&&s.push({file:i.toFile,calleeFunction:i.to})}return{functionName:e,definedIn:r,callers:n,callees:s}}import ye from"fs";import qo from"path";function Ut(t){let e=[...t.nodes.entries()].sort(([n],[s])=>n.localeCompare(s)).map(([n,s])=>`${n}:${s.mtime}:${s.size}`).join("|"),r=2166136261;for(let n=0;n<e.length;n++)r^=e.charCodeAt(n),r=Math.imul(r,16777619)>>>0;return r.toString(16).padStart(8,"0")}function ei(t){let e=new Map;for(let r of t.nodes.keys()){let n=[];t.traverse(r,s=>(s.path!==r&&n.push(s.path),!0),{direction:"incoming"}),e.set(r,n)}return{impact:e,graphHash:Ut(t)}}function ti(t,e){return t.impact.get(e)??[]}function ri(t,e){return t.graphHash===Ut(e)}function ni(t,e){let r=qo.dirname(e);ye.existsSync(r)||ye.mkdirSync(r,{recursive:!0});let n={graphHash:t.graphHash,impact:[...t.impact.entries()]};ye.writeFileSync(e,JSON.stringify(n))}function si(t){if(!ye.existsSync(t))return null;try{let e=ye.readFileSync(t,"utf-8"),r=JSON.parse(e);return{graphHash:r.graphHash,impact:new Map(r.impact)}}catch{return null}}import $l from"path";import xe from"fs";import nn from"path";var L=class t{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let r=new Map;for(let n of e.nodes)r.set(n.path,n);return new t(r)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.imports)if(n.toPath){let s=e.get(n.toPath)||[];s.push(r.path),e.set(n.toPath,s)}return this._incomingEdgesCache=e,e}dfs(e,r,n,s){let o=new Set,i=n.maxDepth??1/0,a=(c,l,p)=>{if(l>i||o.has(c))return;let u=this.nodes.get(c);if(u&&(o.add(c),r(u,l,p)!==!1))for(let g of s(c))a(g,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.imports.map(a=>a.toPath).filter(Boolean)??[]:o?.get(i)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.callEdges??[]){let s=e.get(n.toFile)??[];s.push(r.path),e.set(n.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.callEdges?.map(a=>a.toFile)??[]:o?.get(i)??[])}getCallers(e){let r=[];return this.traverseCalls(e,n=>(n.path!==e&&r.push(n.path),!0),{direction:"incoming",maxDepth:1}),r}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let r=this.nodes.get(e);return r?r.imports.map(n=>this.nodes.get(n.toPath)).filter(n=>n!==void 0):[]}findUnusedFiles(e){return new se(this.nodes).findUnusedFiles(e)}findCycles(e){return new se(this.nodes).findCycles(e)}};function ze(t){return nn.join(t,jt,Wt)}function sn(t,e){return nn.join(ze(t),`${e}.json`)}function on(t,e){let r=sn(t,e);if(!xe.existsSync(r))return null;try{let n=xe.readFileSync(r,"utf-8");return L.deserialize(JSON.parse(n))}catch{return null}}function an(t,e,r){let n=ze(t);xe.existsSync(n)||xe.mkdirSync(n,{recursive:!0}),xe.writeFileSync(sn(t,e),JSON.stringify(r.serialize()))}import Ne from"fs";import F from"path";import Xc from"piscina";import{execFileSync as cn}from"child_process";var ln="%x00%H%x09%ae%x09%at",pn=256*1024*1024;function un(t,e){let r="",n=0;for(let s of t.split(`
3
- `)){if(s.startsWith("\0")){let[,c,l]=s.slice(1).split(" ");r=c??"",n=l?Number(l)*1e3:0;continue}if(s==="")continue;let o=s.split(" "),i=o[0];if(!i)continue;let a=i.startsWith("R")||i.startsWith("C")?o[2]:o[1];a&&e(a,r,n)}}function mn(t){let e=new Map;try{let r=cn("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${ln}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:pn});un(r,(n,s,o)=>{let i=e.get(n);if(i){i.commitCount90d+=1;return}e.set(n,{commitCount90d:1,lastAuthor:s||void 0,lastCommitAt:o||void 0})})}catch{return e}try{let r=cn("git",["-C",t,"log","--name-status","-M",`--format=${ln}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:pn});un(r,(n,s,o)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:o||void 0})})}catch{}return e}import Be from"fs";import oi from"path";import{load as fn}from"js-yaml";var Se=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function gn(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function ii(t){return t.replace(/:$/,"").split(",").map(e=>{let r=e.trim();return r.startsWith('"')&&(r=r.slice(1)),r.endsWith('"')&&(r=r.slice(0,-1)),gn(r)}).filter(Boolean)}function ai(t,e){let r=t.startsWith("/")?t.slice(1):t,n=r.lastIndexOf("@");return n>0?{name:r.substring(0,n),version:e||r.substring(n+1)}:{name:r,version:e}}function ci(t){try{let e=fn(t),r={dependencies:{}};for(let[n,s]of Object.entries(e))if(!(n==="__metadata"||!s?.version))for(let o of n.split(", ")){let i=gn(o);i&&(r.dependencies[i]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function li(t){let e={dependencies:{}};for(let r of t.split(/\n\n+/)){let n=r.split(`
4
- `).filter(c=>c.trim().length>0&&!c.trim().startsWith("#"));if(n.length<2)continue;let s=n[0];if(!s||s.startsWith(" "))continue;let o=ii(s);if(o.length===0)continue;let a=n.find(c=>c.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let c of o)e.dependencies[c]={version:a}}return e}function dn(t){let e=Be.readFileSync(t,"utf-8"),r=JSON.parse(e),n={dependencies:{}};if(r.packages)for(let[s,o]of Object.entries(r.packages)){if(!s.startsWith("node_modules/"))continue;let i=s.replace("node_modules/","");i.includes("node_modules/")||(n.dependencies[i]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}else if(r.dependencies)for(let[s,o]of Object.entries(r.dependencies))n.dependencies[s]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}};return n}function hn(t){let e=Be.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=ci(e);if(r!==null)return r}return li(e)}function yn(t){let e=Be.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=fn(e);if(n.packages)for(let[s,o]of Object.entries(n.packages)){let{name:i,version:a}=ai(s,o.version);i&&(r.dependencies[i]={version:a,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}if(n.dependencies)for(let[s,o]of Object.entries(n.dependencies)){if(r.dependencies[s])continue;let i=typeof o=="string"?o:o.version;r.dependencies[s]={version:i||""}}}catch{}return r}var pi={"package-lock.json":dn,"yarn.lock":hn,"pnpm-lock.yaml":yn};function Kt(t){for(let e of Se){let r=oi.join(t,e);if(Be.existsSync(r))return pi[e](r)}return null}import Ke from"fs";import Ue from"path";function xn(t){let e=t.trim();return e.length>=2&&(e[0]==='"'||e[0]==="'")&&e[e.length-1]===e[0]?e.slice(1,-1):e}function ui(t){let e=t.trim();if(e.startsWith('"')||e.startsWith("'")){let a=xn(e).split(":");return a.length>=3&&a[0]&&a[2]?{group:a[0],version:a[2]}:null}if(!e.startsWith("{"))return null;let r=e.match(/module\s*=\s*["']([^"']+)["']/),n=e.match(/group\s*=\s*["']([^"']+)["']/),s=r?r[1].split(":")[0]:n?.[1];if(!s)return null;let o=e.match(/version\.ref\s*=\s*["']([^"']+)["']/)??e.match(/version\s*=\s*\{\s*ref\s*=\s*["']([^"']+)["']/),i=e.match(/version\s*=\s*["']([^"']+)["']/);return{group:s,...i?.[1]!==void 0&&{version:i[1]},...o?.[1]!==void 0&&{versionRef:o[1]}}}function Jt(t){let e=t.split(/\r?\n/).map(o=>o.replace(/#.*$/,"").trim()),r={},n="";for(let o of e){let i=o.match(/^\[([\w.-]+)\]$/);if(i){n=i[1];continue}if(n!=="versions"||!o)continue;let a=o.indexOf("=");if(a===-1)continue;let c=o.slice(0,a).trim(),l=xn(o.slice(a+1));c&&l&&(r[c]=l)}let s={};n="";for(let o of e){let i=o.match(/^\[([\w.-]+)\]$/);if(i){n=i[1];continue}if(n!=="libraries"||!o)continue;let a=o.indexOf("=");if(a===-1)continue;let c=ui(o.slice(a+1));if(!c)continue;let l=c.versionRef?r[c.versionRef]:c.version;l&&(s[c.group]=l)}return s}function Vt(t){let e={};for(let r of t.split(/\r?\n/)){let n=r.trim();if(!n||n.startsWith("#")||n.startsWith("empty="))continue;let o=n.split("=")[0].split(":");o.length>=3&&o[0]&&o[2]&&(e[o[0]]=o[2])}return e}function Yt(t){let e={},r=/["']([\w.-]+):([\w.-]+):([\w.\-+]+)["']/g;for(let s=r.exec(t);s;s=r.exec(t)){let[,o,,i]=s;o&&i&&/\d/.test(i)&&(e[o]=i)}let n=/group:\s*["']([\w.-]+)["'][^\n)]*?version:\s*["']([\w.\-+]+)["']/g;for(let s=n.exec(t);s;s=n.exec(t))s[1]&&s[2]&&/\d/.test(s[2])&&(e[s[1]]=s[2]);return e}function He(t){let e={},r=/["']([\w.-]+)["']\s*%%?\s*["']([\w.-]+)["']\s*%\s*["']([\w.\-+]+)["']/g;for(let n=r.exec(t);n;n=r.exec(t)){let[,s,,o]=n;s&&o&&(e[s]=o)}return e}var mi=new Set(["node_modules","build",".gradle","target",".git","dist"]),fi=2;function be(t){try{return Ke.existsSync(t)?Ke.readFileSync(t,"utf-8"):null}catch{return null}}function Qt(t){let e={},r=p=>{for(let[u,g]of Object.entries(p))!e[u]&&g&&(e[u]=g)},n=be(Ue.join(t,"gradle","libs.versions.toml"));n&&r(Jt(n));let s=[],o=[],i=[],a=(p,u)=>{let g;try{g=Ke.readdirSync(p,{withFileTypes:!0})}catch{return}for(let d of g){let y=Ue.join(p,d.name);if(d.isDirectory()){u<fi&&!d.name.startsWith(".")&&!mi.has(d.name)&&a(y,u+1);continue}d.isFile()&&(d.name==="gradle.lockfile"?s.push(y):d.name==="build.gradle"||d.name==="build.gradle.kts"?o.push(y):d.name==="build.sbt"&&i.push(y))}};a(t,0);for(let p of s){let u=be(p);u&&r(Vt(u))}for(let p of o){let u=be(p);u&&r(Yt(u))}for(let p of i){let u=be(p);u&&r(He(u))}try{let p=Ue.join(t,"project");for(let u of Ke.readdirSync(p,{withFileTypes:!0}))if(u.isFile()&&u.name.endsWith(".scala")){let g=be(Ue.join(p,u.name));g&&r(He(g))}}catch{}let c=Object.keys(e);if(c.length===0)return null;let l={};for(let p of c)l[p]={version:e[p]};return l}function Sn(t){let e=Kt(t),r=Qt(t);return r?{...e??{dependencies:{}},jvmDependencies:r}:e}import bn from"path";function _(t){switch(bn.extname(t).toLowerCase()){case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".ts":case".tsx":return"typescript";case".css":return"css";case".scss":case".sass":return"scss";case".less":return"less";case".styl":return"stylus";case".coffee":return"coffeescript";case".ls":return"livescript";case".lua":return"lua";case".py":return"python";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":case".sc":return"scala";case".groovy":case".gradle":return"groovy";case".cpp":case".cc":case".cxx":case".c":return"unknown";case".feature":return"gherkin";case".md":case".mdx":return"markdown";default:return"unknown"}}function N(t){let e=bn.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import gi from"coffeescript";function B(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function oe(t){let e=new Set,r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=r.exec(t);for(;n!==null;)n[1]&&e.add(n[1]),n=r.exec(t);return e}function ie(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function vn(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return B(t.value)}}function J(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function di(t,e){let r=vn(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:N(r),type:"static"}:null}function hi(t,e){let r=e.variable?.base?.value==="require",n=vn(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:N(n),type:"require"}}function kn(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=J(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>J(s.variable)??J(s)).filter(s=>!!s).map(s=>({name:s}));let n=J(r);return n?[{name:n}]:[]}function yi(t){if(Array.isArray(t.specifiers))return t.specifiers.map(r=>r.identifier??r.original?.value).filter(r=>!!r).map(r=>({name:r}));let e=J(t.variable)??J(t.variable?.base);return e?[{name:e}]:[]}function xi(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let o=di(t,e);o&&r.push(o)}else if(s==="Call"){let o=hi(t,e);o&&r.push(o)}else if(s==="Assign"){let o=J(e.variable?.base),i=e.variable?.properties?.[0]?.name?.value;o==="module"&&i==="exports"?n.push(...kn(e,void 0)):o==="exports"&&typeof i=="string"&&n.push(...kn(e,i))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...yi(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function Xt(t,e,r,n){if(!(!e||typeof e!="object")){xi(t,e,r,n);for(let s in e){if(s==="locationData")continue;let o=e[s];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let i of o)Xt(t,i,r,n);else Xt(t,o,r,n)}}}function Cn(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{Xt(t,gi.nodes(e),s,o)}catch{}let i=new Set,a=o.filter(c=>i.has(c.name)?!1:(i.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import{AstBuilder as Si,GherkinClassicTokenMatcher as bi,Parser as ki}from"@cucumber/gherkin";import{IdGenerator as vi}from"@cucumber/messages";var wn=new Map;function ae(t,e){wn.set(t,e)}function En(t){return wn.get(t)}var Ci=vi.uuid();function Zt(t,e){let r=new Set,n=s=>{for(let o of s)r.add(o.name.startsWith("@")?o.name.slice(1):o.name)};try{let s=new Si(Ci),o=new bi,a=new ki(s,o).parse(e);if(a.feature){n(a.feature.tags);for(let c of a.feature.children){if(c.scenario){n(c.scenario.tags);for(let l of c.scenario.examples)n(l.tags)}if(c.rule)for(let l of c.rule.children)l.scenario&&n(l.scenario.tags)}}}catch(s){console.warn(`[GherkinParser] Failed to parse ${t}:`,s)}return{imports:[],exports:[],tags:Array.from(r).map(s=>({name:s,kind:"comment-marker"})),category:"test"}}ae("gherkin",Zt);import Ni from"path";import{parser as Pi}from"@lezer/go";function V(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function Y(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
5
- `&&r++;return r}function wi(t,e){let r=1;function n(s){switch(s.type.name){case"IfStatement":case"ForStatement":r++;break;case"Case":{s.firstChild?.type.name==="case"&&r++;break}case"LogicOp":{let i=e.slice(s.from,s.to);(i==="&&"||i==="||")&&r++;break}}let o=s.firstChild;for(;o;)n(o),o=o.nextSibling}return n(t),r}function Fn(t,e,r,n){let s=r?1:1+e,o=V(t),i=r?e:e+1,a=o[1];a&&a.type.name!=="Block"&&(s+=ce(a,i,!1,n));let c=o.find(p=>p.type.name==="Block");c&&(s+=ce(c,i,!1,n));let l=o.findIndex(p=>p.type.name==="else");if(l>=0){let p=o[l+1];p?.type.name==="IfStatement"?s+=Fn(p,e,!0,n):p&&(s+=1+ce(p,e+1,!1,n))}return s}function Tn(t,e,r){let n=1+e,s=t.firstChild;for(;s;)n+=ce(s,e+1,!1,r),s=s.nextSibling;return n}function Ei(t,e,r){let n=0,s=t.firstChild;for(;s;)n+=ce(s,e,!1,r),s=s.nextSibling;return n}function Ti(t,e){let r=e.slice(t.from,t.to);return r==="&&"||r==="||"}function ce(t,e,r,n){let s=t.type.name;if(s==="IfStatement")return Fn(t,e,r,n);if(s==="ForStatement"||s==="SwitchStatement"||s==="SelectStatement")return Tn(t,e,n);let o=s==="LogicOp"&&Ti(t,n)?1:0;return e>0&&s==="FunctionLiteral"?o+Tn(t,e,n):o+Ei(t,e,n)}function Fi(t,e){return ce(t,0,!1,e)}function Je(t,e){return{complexity:wi(t,e),cognitiveComplexity:Fi(t,e)}}function qt(t,e){let n=t.getChild("Parameters")?.getChild("Parameter"),s=n?.getChild("TypeName")??n?.getChild("PointerType")?.getChild("TypeName");return s?e.slice(s.from,s.to):void 0}function Nn(t,e){let r=[],n=t.cursor();do if(n.name==="FunctionDecl"){let s=n.node.getChild("DefName");if(s){let o=e.slice(s.from,s.to),{complexity:i,cognitiveComplexity:a}=Je(n.node,e);r.push({name:o,line:Y(e,n.from),complexity:i,cognitiveComplexity:a})}}else if(n.name==="MethodDecl"){let s=n.node.getChild("FieldName");if(s){let o=e.slice(s.from,s.to),i=qt(n.node,e),a=i?`${i}.${o}`:o,{complexity:c,cognitiveComplexity:l}=Je(n.node,e);r.push({name:a,line:Y(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Ri=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,Ii=/^\/\/go:build\s+(.+)$/,Di=/^\/\/\s*\+build\s+(.+)$/;function Rn(t,e){let r=[],n=new Map,s=new Set,o=new Set,i=new Map,a=Pi.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let S=e.slice(c.from,c.to),v=S.match(Ri);v?.[1]&&s.add(v[1]);let R=S.match(Ii);R&&Pn(R[1],o);let x=S.match(Di);x&&Pn(x[1],o);break}case"ImportSpec":{let S=c.node.getChild("String");if(S){let R=e.slice(S.from,S.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:R,isExternal:!0,isStyle:!1,type:"static"});let x=c.node.getChild("DefName"),w=x?e.slice(x.from,x.to):R.split("/").pop();w&&w!=="_"&&w!=="."&&i.set(w,R)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let S=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(S){let v=e.slice(S.from,S.to);v!=="_"&&/^[A-Z]/.test(v)&&!n.has(v)&&n.set(v,{name:v})}break}}while(c.next());let l=r.some(S=>S.rawSpecifier==="testing"),p=Ni.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",u=new Set([...s,...o]),{complexity:g,cognitiveComplexity:d}=Je(a.topNode,e),y=Nn(a,e),k=p==="test"?[]:Mi(a,e,i);return{imports:r,exports:Array.from(n.values()),tags:Array.from(u).map(S=>({name:S,kind:"comment-marker"})),category:p,rawCallEdges:k,complexity:g,cognitiveComplexity:d,...y.length>0?{functions:y}:{}}}function Mi(t,e,r){let n=[];function s(i,a){if(i.type.name==="CallExpr"){let l=i.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,u=l.getChild("FieldName");if(p?.type.name==="VariableName"&&u){let g=e.slice(p.from,p.to),d=r.get(g);if(d){let y=e.slice(u.from,u.to);n.push({from:a,to:y,toSpecifier:d})}}}}let c=i.firstChild;for(;c;)s(c,a),c=c.nextSibling}let o=t.cursor();do if(o.name==="FunctionDecl"){let i=o.node.getChild("DefName"),a=o.node.getChild("Block");if(i&&a){let c=e.slice(i.from,i.to);/^[A-Z]/.test(c)&&s(a,c)}}else if(o.name==="MethodDecl"){let i=o.node.getChild("FieldName"),a=o.node.getChild("Block");if(i&&a){let c=e.slice(i.from,i.to),l=qt(o.node,e);s(a,l?`${l}.${c}`:c)}}while(o.next());return n}function Pn(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}var Ai=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/g,Li=["org.junit","androidx.test","org.robolectric","org.mockito","org.scalatest","munit","spock.lang","io.kotest","org.spekframework","org.testng","org.assertj","com.google.truth","org.hamcrest","io.mockk","com.nhaarman.mockitokotlin2"],er=["test","androidTest","integrationTest","it"],_i=new RegExp(`/src/(${er.join("|")})/`),Oi=/(?:Test|Tests|Spec|IT|ITCase)$/;function tr(t){let e=t.replace(/\.\w+$/,"");return Oi.test(e)}function le(t){let e=new Set;for(let r of t.matchAll(Ai))r[1]&&e.add(r[1]);return e}function H(t){let e=t.replace(/\/\*[\s\S]*?\*\//g,r=>r.replace(/[^\n]/g," "));return e=e.replace(/\/\/[^\n]*/g,r=>" ".repeat(r.length)),e}function pe(t){let e=H(t),r=new Set;for(let s of e.matchAll(/@([A-Z]\w*)/g))s[1]&&r.add(s[1]);let n=new Set;for(let s of e.matchAll(/\b(?:class|object|interface|trait|enum)\s+([A-Za-z_]\w*)/g))s[1]&&n.add(s[1]);return{annotations:[...r],typeNames:[...n]}}function ue(t,e){return{fromPath:t,toPath:"",rawSpecifier:e,isExternal:!0,isStyle:!1,type:"static"}}function U(t,e){return{fromPath:t,toPath:"",rawSpecifier:`${e}.*`,isExternal:!0,isStyle:!1,type:"side-effect",isSamePackage:!0}}function D(t,e){let r=[];for(let n of H(t).split(`
6
- `)){let s=n.trim();if(!s||s.startsWith("@")||s.startsWith("*"))continue;let o=s.match(/^package\s+(?:object\s+)?([\w.]+)/);if(o?.[1]){if(r.push(o[1]),!e)break;continue}if(!(e&&/^import\s/.test(s)))break}return r.length>0?r.join("."):null}var Gi=new Set(["Configuration","SpringBootApplication","EnableAutoConfiguration"]),ji=new Set(["Composable","Preview"]),$i=new Set(["RestController","Controller","Service","Repository","Component","Entity","MappedSuperclass","Embeddable"]),Wi=["Activity","Fragment","ViewModel","Screen","Composable"];function O(t,e,r={}){let n=t.replace(/\\/g,"/"),s=n.split("/").pop()??"";if(s.endsWith(".gradle")||s==="build.gradle.kts"||s==="settings.gradle.kts")return"config";if(_i.test(n)||e.some(i=>Li.some(a=>i===a||i.startsWith(`${a}.`))))return"test";let o=r.annotations??[];return o.some(i=>Gi.has(i))?"config":o.some(i=>ji.has(i))||(r.typeNames??[]).some(i=>Wi.some(a=>i.endsWith(a)))?"ui":o.some(i=>$i.has(i))?"logic":tr(s)?"test":"logic"}var zi=/^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,Bi=/^(?:@\w+\s+)*(?:public\s+|private\s+|protected\s+|final\s+|abstract\s+|static\s+)*(class|interface|trait|enum|def)\s+([A-Za-z_][A-Za-z0-9_]*)/;function Hi(t,e){return t?e.endsWith(".*")?e.slice(0,-2)||null:e.split(".").slice(0,-1).join(".")||null:e||null}function In(t,e){let r=le(e),s=H(e).split(`
7
- `),o=[],i=new Set;for(let l of s){let p=l.match(zi);if(p?.[2]){let g=Hi(!!p[1],p[2]);g&&o.push(ue(t,g));continue}let u=l.match(Bi);u?.[2]&&i.add(u[2])}let a=D(e,!1);a&&o.push(U(t,a));let c=Array.from(i,l=>({name:l}));return{imports:o,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:O(t,o.map(l=>l.rawSpecifier),{typeNames:[...i],annotations:pe(e).annotations})}}import{parser as Qi}from"@lezer/java";var Dn=new Set(["ForStatement","EnhancedForStatement","WhileStatement","DoStatement"]),Ui=new Set(["ClassDeclaration","InterfaceDeclaration","EnumDeclaration","RecordDeclaration","AnnotationTypeDeclaration"]);function Ki(t,e){let r=1;function n(s){let o=s.type.name;if(o==="IfStatement"||o==="CatchClause"||o==="TernaryExpression")r++;else if(Dn.has(o))r++;else if(o==="SwitchLabel")s.firstChild?.type.name==="case"&&r++;else if(o==="LogicOp"){let a=e.slice(s.from,s.to);(a==="&&"||a==="||")&&r++}let i=s.firstChild;for(;i;)n(i),i=i.nextSibling}return n(t),r}function Mn(t,e,r,n){let s=r?1:1+e,o=[];for(let p=t.firstChild;p;p=p.nextSibling)o.push(p);let i=r?e:e+1,a=o[1];a&&a.type.name!=="Block"&&(s+=me(a,i,!1,n));let c=o.find(p=>p.type.name==="Block");c&&(s+=me(c,i,!1,n));let l=o.findIndex(p=>p.type.name==="else");if(l>=0){let p=o[l+1];p?.type.name==="IfStatement"?s+=Mn(p,e,!0,n):p&&(s+=1+me(p,e+1,!1,n))}return s}function rr(t,e,r){let n=1+e,s=t.firstChild;for(;s;)n+=me(s,e+1,!1,r),s=s.nextSibling;return n}function Ji(t,e,r){let n=0,s=t.firstChild;for(;s;)n+=me(s,e,!1,r),s=s.nextSibling;return n}function Vi(t,e){let r=e.slice(t.from,t.to);return r==="&&"||r==="||"}function me(t,e,r,n){let s=t.type.name;if(s==="IfStatement")return Mn(t,e,r,n);if(Dn.has(s)||s==="SwitchStatement"||s==="CatchClause"||s==="TernaryExpression")return rr(t,e,n);let o=s==="LogicOp"&&Vi(t,n)?1:0;return e>0&&s==="LambdaExpression"?o+rr(t,e,n):o+Ji(t,e,n)}function Yi(t,e){return me(t,0,!1,e)}function nr(t,e){return{complexity:Ki(t,e),cognitiveComplexity:Yi(t,e)}}function sr(t,e){for(let r=t.parent;r;r=r.parent)if(Ui.has(r.type.name)){let n=r.getChild("Definition");if(n)return e.slice(n.from,n.to)}}function An(t,e){let r=[],n=t.cursor();do if(n.name==="MethodDeclaration"||n.name==="ConstructorDeclaration"){let s=n.node.getChild("Definition");if(s){let o=e.slice(s.from,s.to),i=sr(n.node,e),a=i&&n.name==="MethodDeclaration"?`${i}.${o}`:o,{complexity:c,cognitiveComplexity:l}=nr(n.node,e);r.push({name:a,line:Y(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Xi=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/;function Zi(t,e){let r=t.getChild("ScopedIdentifier");if(!r)return null;let n=t.getChild("static")!=null,s=t.getChild("Asterisk")!=null,o=e.slice(r.from,r.to);return n?(s||(o=o.split(".").slice(0,-1).join(".")),o?{specifier:o,wildcard:!1}:null):s?{specifier:`${o}.*`,wildcard:!0}:{specifier:o,wildcard:!1}}function qi(t){let e=new Map;for(let r of t){if(r.type==="side-effect")continue;let n=r.rawSpecifier;if(n.endsWith(".*"))continue;let s=n.split(".").pop();s&&e.set(s,n)}return e}function ea(t,e){let r=t;if(r.name==="GenericType"&&(r=r.firstChild),!r)return null;if(r.name==="TypeName")return e.slice(r.from,r.to);if(r.name==="ScopedTypeName"){let n=null;for(let s=r.firstChild;s;s=s.nextSibling)s.name==="TypeName"&&(n=s);return n?e.slice(n.from,n.to):null}return null}function ta(t,e,r){let n=[];function s(i,a){let c=i.type.name;if(c==="MethodInvocation"){let p=i.firstChild;if(p?.type.name==="Identifier"){let u=r.get(e.slice(p.from,p.to)),g=i.getChild("MethodName");u&&g&&n.push({from:a,to:e.slice(g.from,g.to),toSpecifier:u})}}else if(c==="ObjectCreationExpression"){let p=i.getChild("TypeName")??i.getChild("GenericType")??i.getChild("ScopedTypeName"),u=p&&ea(p,e);if(u){let g=r.get(u);g&&n.push({from:a,to:"new",toSpecifier:g})}}let l=i.firstChild;for(;l;)s(l,a),l=l.nextSibling}let o=t.cursor();do if(o.name==="MethodDeclaration"||o.name==="ConstructorDeclaration"){let i=o.node.getChild("Definition"),a=o.node.getChild("Block")??o.node.getChild("ConstructorBody");if(i&&a){let c=e.slice(i.from,i.to),l=sr(o.node,e),p=l&&o.name==="MethodDeclaration"?`${l}.${c}`:c;s(a,p)}}while(o.next());return n}function Ln(t,e){let r=[],n=new Map,s=new Set,o=new Set,i;try{i=Qi.parse(e)}catch{return{imports:[],exports:[],tags:[],category:O(t,[])}}let a=i.cursor();do switch(a.name){case"LineComment":{let y=e.slice(a.from,a.to).match(Xi);y?.[1]&&s.add(y[1]);break}case"MarkerAnnotation":case"Annotation":{let y=a.node.getChild("Identifier");y&&o.add(e.slice(y.from,y.to));break}case"ImportDeclaration":{let y=Zi(a.node,e);y&&r.push({fromPath:t,toPath:"",rawSpecifier:y.specifier,isExternal:!0,isStyle:!1,type:"static"});break}case"ClassDeclaration":case"InterfaceDeclaration":case"EnumDeclaration":case"AnnotationTypeDeclaration":{if(a.node.parent?.name==="Program"){let y=a.node.getChild("Definition");if(y){let k=e.slice(y.from,y.to);n.has(k)||n.set(k,{name:k})}}break}}while(a.next());let c=D(e,!1);c&&r.push(U(t,c));let l=O(t,r.map(y=>y.rawSpecifier),{typeNames:[...n.keys()],annotations:[...o]}),{complexity:p,cognitiveComplexity:u}=nr(i.topNode,e),g=An(i,e),d=l==="test"?[]:ta(i,e,qi(r));return{imports:r,exports:Array.from(n.values()),tags:Array.from(s).map(y=>({name:y,kind:"comment-marker"})),category:l,rawCallEdges:d,complexity:p,cognitiveComplexity:u,...g.length>0?{functions:g}:{}}}var ra=/^\s*import\s+([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,or="(?:public\\s+|internal\\s+|private\\s+|protected\\s+|open\\s+|abstract\\s+|final\\s+|sealed\\s+|data\\s+|value\\s+|inline\\s+|noinline\\s+|crossinline\\s+|external\\s+|expect\\s+|actual\\s+|suspend\\s+|operator\\s+|infix\\s+|tailrec\\s+|const\\s+|lateinit\\s+)*",na=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${or}(?:(?:enum|annotation)\\s+)?(class|interface|object|typealias)\\s+([A-Za-z_][A-Za-z0-9_]*)`),sa=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${or}fun\\s+(?:<[^>]*>\\s*)?(?:[A-Za-z_][\\w.]*(?:<[^>]*>)?\\.)?([A-Za-z_][A-Za-z0-9_]*)\\s*[(<]`),oa=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${or}(?:val|var)\\s+(?:<[^>]*>\\s*)?([A-Za-z_][A-Za-z0-9_]*)`);function _n(t,e){let r=le(e),s=H(e).split(`
8
- `),o=[],i=new Set;for(let l of s){let p=l.match(ra);if(p?.[1]){o.push(ue(t,p[1]));continue}let u=l.match(na);if(u?.[2]){i.add(u[2]);continue}let g=l.match(sa);if(g?.[1]){i.add(g[1]);continue}let d=l.match(oa);d?.[1]&&i.add(d[1])}let a=D(e,!1);a&&o.push(U(t,a));let c=Array.from(i,l=>({name:l}));return{imports:o,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:O(t,o.map(l=>l.rawSpecifier),{typeNames:[...i],annotations:pe(e).annotations})}}import ia from"livescript";function Q(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function aa(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=Q(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>Q(r.key)??Q(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=Q(t);return e?[{name:e}]:[]}function ca(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,n=Q(r.head),o=r.tails?.[0]?.key?.name;if(n==="module"&&o==="exports")return aa(t.right);if(n==="exports"&&typeof o=="string")return[{name:o}];if(r.head?.verb==="out"&&typeof o=="string")return[{name:o}]}if(e==="Import"&&t.left?.verb==="out"){let r=t.right;if(r?.constructor?.name==="Obj"&&Array.isArray(r.items))return r.items.map(n=>Q(n.val)??Q(n.key)).filter(n=>!!n).map(n=>({name:n}))}return[]}var la=new Set(["first_line","first_column","last_line","last_column","line","column"]);function pa(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=B(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:N(s),type:"static"}}}if(r==="Chain"&&t.head?.value==="require"){let n=t.tails?.[0];if(n?.constructor?.name==="Call"||n?.type==="Call"){let s=n.args?.[0]?.value;if(typeof s=="string"){let o=B(s);return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:N(o),type:"require"}}}}return null}function ir(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=pa(t,e);s&&n.push(s),r.push(...ca(t));for(let o in t){if(la.has(o))continue;let i=t[o];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let a of i)n.push(...ir(a,e,r));else n.push(...ir(i,e,r))}return n}function On(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{s=ir(ia.ast(e),t,o)}catch{}let i=new Set,a=o.filter(c=>i.has(c.name)?!1:(i.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}import ua from"luaparse";function ma(t,e){let r=[];function n(s){if(!(!s||typeof s!="object")){if((s.type==="CallExpression"||s.type==="StringCallExpression")&&s.base?.type==="Identifier"&&s.base?.name==="require"){let o;if(s.type==="CallExpression"){let i=s.arguments?.[0];i?.type==="StringLiteral"&&(o=B(i.raw))}else if(s.type==="StringCallExpression"){let i=s.argument;i?.type==="StringLiteral"&&(o=B(i.raw))}o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:N(o),type:"require"})}for(let o in s){if(o==="loc")continue;let i=s[o];if(i&&typeof i=="object")if(Array.isArray(i))for(let a of i)n(a);else n(i)}}}return n(t),r}function fa(t){let e=new Set;for(let r of t)r.type==="LocalStatement"&&r.variables.forEach((n,s)=>{r.init[s]?.type==="TableConstructorExpression"&&e.add(n.name)});return e}function ga(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let r=e.arguments[0];if(r?.type!=="TableConstructorExpression")return[];let n=[];for(let s of r.fields)s.type==="TableKeyString"&&n.push({name:s.key.name});return n}function da(t){let e=t.body,r=fa(e),n=ga(e);for(let o of e)if(o.type==="FunctionDeclaration")o.identifier?.type==="MemberExpression"?o.identifier.base.type==="Identifier"&&r.has(o.identifier.base.name)&&n.push({name:o.identifier.identifier.name}):o.identifier?.type==="Identifier"&&!o.isLocal&&n.push({name:o.identifier.name});else if(o.type==="AssignmentStatement")for(let i of o.variables)i.type==="MemberExpression"&&i.base.type==="Identifier"&&r.has(i.base.name)&&n.push({name:i.identifier.name});let s=new Set;return n.filter(o=>s.has(o.name)?!1:(s.add(o.name),!0))}function Gn(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{let i=ua.parse(e);s=ma(i,t),o=da(i)}catch{}return{imports:s,exports:o,tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:n}}var ha=["http://","https://","mailto:","//"],ya="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",xa=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${ya})\\b`,"g"),jn;async function Sa(){return jn??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),jn}function ba(t){let e=t.trim();return e.length===0||e.startsWith("#")||ha.some(r=>e.startsWith(r))}function ka(t,e){let r=t.match(xa);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static",isDocReference:!0})):[]}function $n(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!ba(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static",isDocReference:!0}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...ka(t.value,e)),Array.isArray(t.children))for(let n of t.children)$n(n,e,r)}async function Wn(t,e){let n=(await Sa()).parse(e),s=[];$n(n,t,s);let o=new Set;return{imports:s.filter(a=>o.has(a.rawSpecifier)?!1:(o.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import Fa from"path";import{parser as Na}from"@lezer/python";function va(t){let e=1;function r(n){switch(n.type.name){case"IfStatement":{e+=V(n).filter(o=>o.type.name==="if"||o.type.name==="elif").length;break}case"TryStatement":{e+=V(n).filter(o=>o.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let s=n.firstChild;for(;s;)r(s),s=s.nextSibling}return r(t),e}function Ca(t,e){let r=0,n=V(t),s=0,o=0;for(;o<n.length;){let i=n[o];if(i?.type.name==="if"||i?.type.name==="elif"){let a=s>0;r+=a?1:1+e;let c=a?e:e+1,l=n[o+1],p=n[o+2];l&&(r+=G(l,c)),p&&(r+=G(p,c)),s++,o+=3}else if(i?.type.name==="else"){r+=1;let a=n[o+1];a&&(r+=G(a,e+1)),o+=2}else o++}return r}function wa(t,e){let r=0,n=V(t),s=0;for(;s<n.length;){let o=n[s];if(o?.type.name==="except"){for(r+=1+e,s++;s<n.length&&n[s]?.type.name!=="Body";)r+=G(n[s],e),s++;s<n.length&&(r+=G(n[s],e),s++)}else o?.type.name==="Body"&&(r+=G(o,e)),s++}return r}function zn(t,e){let r=1+e,n=t.firstChild;for(;n;)r+=G(n,e+1),n=n.nextSibling;return r}function Ea(t,e){let r=0,n=t.firstChild;for(;n;)r+=G(n,e),n=n.nextSibling;return r}function G(t,e){let r=t.type.name;switch(r){case"IfStatement":return Ca(t,e);case"TryStatement":return wa(t,e);case"ForStatement":case"WhileStatement":return zn(t,e);default:{let n=r==="ConditionalExpression"||r==="and"||r==="or"?1:0;return e>0&&(r==="FunctionDefinition"||r==="LambdaExpression")?n+zn(t,e):n+Ea(t,e)}}}function Ta(t){return G(t,0)}function ar(t){return{complexity:va(t),cognitiveComplexity:Ta(t)}}function Bn(t,e){let r=[];function n(i,a){let{complexity:c,cognitiveComplexity:l}=ar(i);r.push({name:a,line:Y(e,i.from),complexity:c,cognitiveComplexity:l})}function s(i){let a=i.firstChild;for(;a;)o(a),a=a.nextSibling}function o(i){if(i.type.name==="ClassDefinition"){let a=i.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=i.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let u=p.getChild("VariableName"),g=u?e.slice(u.from,u.to):void 0;g&&n(p,c?`${c}.${g}`:g),s(p)}else o(p);p=p.nextSibling}}return}if(i.type.name==="FunctionDefinition"){let a=i.getChild("VariableName");a&&n(i,e.slice(a.from,a.to)),s(i);return}s(i)}return o(t.topNode),r}var Pa=new Set(["pytest","unittest","nose","hypothesis"]);function Hn(t,e){let r=[],n=[],s=new Set,o=Fa.basename(t).toLowerCase(),i=Na.parse(e),a=i.cursor();do switch(a.name){case"Comment":{let d=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);d?.[1]&&s.add(d[1]);break}case"ImportStatement":{for(let d of Ra(a.node,e,t))r.push(d);break}case"FunctionDefinition":case"ClassDefinition":{let d=a.node.parent;if(d?.name==="Script"||d?.name==="DecoratedStatement"&&d.parent?.name==="Script"){let k=a.node.getChild("VariableName");k&&n.push({name:e.slice(k.from,k.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let d=a.node.firstChild;d?.name==="VariableName"&&n.push({name:e.slice(d.from,d.to)})}break}}while(a.next());let c=_a(o,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=ar(i.topNode),u=Bn(i,e),g=c==="test"?[]:La(i,e);return{imports:r,exports:n,tags:Array.from(s).map(d=>({name:d,kind:"comment-marker"})),category:c,rawCallEdges:g,complexity:l,cognitiveComplexity:p,...u.length>0?{functions:u}:{}}}function Ra(t,e,r){let n=t.firstChild;return n?n.name==="from"?Ia(t,e,r):Da(t,e,r):[]}function Ia(t,e,r){let n=t.firstChild;if(!n)return[];let s=n.nextSibling;for(;s&&s.name!=="import";)s=s.nextSibling;if(!s)return[];let o=e.slice(n.to,s.from).trim(),i=Ma(s.nextSibling,e);if(!i.length)return[];let a=0;for(;a<o.length&&o[a]===".";)a++;let c=o.slice(a);if(a===0)return[ke(r,o,i,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[ke(r,l+c.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[ke(r,l.slice(0,-1),["*"],!1)]:i.map(p=>ke(r,l+p,[p],!1))}function Da(t,e,r){let n=[],s=t.firstChild?.nextSibling??null;for(;s;){if(s.name==="VariableName"){let o=e.slice(s.from,s.to);for(;s.nextSibling?.name==="."&&s.nextSibling.nextSibling?.name==="VariableName";)s=s.nextSibling.nextSibling,o+=`.${e.slice(s.from,s.to)}`;s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling),n.push(ke(r,o,["*"],!0))}s=s.nextSibling}return n}function Ma(t,e){let r=[],n=t;for(;n;)n.name==="*"?r.push("*"):n.name==="VariableName"&&(r.push(e.slice(n.from,n.to)),n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling)),n=n.nextSibling;return r}function Aa(t,e){let r=new Map,n=t.cursor();do{if(n.name!=="ImportStatement")continue;let o=n.node.firstChild;if(o?.type.name!=="from")continue;let i=o.nextSibling;for(;i&&i.type.name!=="import";)i=i.nextSibling;if(!i)continue;let a=e.slice(o.to,i.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),u=i.nextSibling;for(;u;){if(u.type.name==="VariableName"){let g=e.slice(u.from,u.to),d=g;if(u.nextSibling?.type.name==="as"){let k=u.nextSibling.nextSibling;k?.type.name==="VariableName"&&(d=e.slice(k.from,k.to),u=k)}let y=c===0?a:l?p+l.replace(/\./g,"/"):p+g;r.set(d,y)}u=u.nextSibling}}while(n.next());return r}function La(t,e){let r=Aa(t,e),n=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,u=e.slice(p.from,p.to),g=r.get(u);g&&n.push({from:c,to:u,toSpecifier:g})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function o(a){let c=a.firstChild;for(;c;)i(c),c=c.nextSibling}function i(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let u=p.firstChild;for(;u;){if(u.type.name==="FunctionDefinition"){let g=u.getChild("VariableName"),d=g?e.slice(g.from,g.to):void 0;d&&s(u,l?`${l}.${d}`:d)}else i(u);u=u.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&s(a,e.slice(c.from,c.to));return}o(a)}return i(t.topNode),n}function ke(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function _a(t,e,r){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":r.has("test")||e.some(n=>Pa.has(n.rawSpecifier))?"test":"logic"}var Oa=/^\s*import\s+(.+?)\s*$/,Ga=/^(?:@\w+\s+)*(?:private\s+|protected\s+|final\s+|sealed\s+|abstract\s+|implicit\s+|case\s+)*(class|trait|object|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/;function ja(t,e){let r=e.split("=>")[0]?.trim();return r?r==="_"||r==="*"||r==="given"?`${t}.*`:`${t}.${r}`:null}function $a(t){let e=t.indexOf("{");if(e!==-1){let n=t.indexOf("}",e),s=t.slice(0,e).trim().replace(/\.$/,""),o=t.slice(e+1,n===-1?void 0:n);return s?o.split(",").map(i=>ja(s,i.trim())).filter(i=>i!=null):[]}let r=[];for(let n of t.split(",")){let s=n.trim().replace(/\s+as\s+\w+$/,"");if(s)if(s.endsWith("._")||s.endsWith(".*")||s.endsWith(".given")){let o=s.replace(/\.(_|\*|given)$/,"");o&&r.push(`${o}.*`)}else r.push(s)}return r}function Un(t,e){let r=le(e),s=H(e).split(`
9
- `),o=[],i=new Set;for(let l of s){let p=l.match(Oa);if(p?.[1]){for(let g of $a(p[1]))o.push(ue(t,g));continue}let u=l.match(Ga);u?.[2]&&i.add(u[2])}let a=D(e,!0);a&&o.push(U(t,a));let c=Array.from(i,l=>({name:l}));return{imports:o,exports:c,tags:Array.from(r).map(l=>({name:l,kind:"comment-marker"})),category:O(t,o.map(l=>l.rawSpecifier),{typeNames:[...i],annotations:pe(e).annotations})}}import Yn from"path";import h from"typescript";import b from"typescript";function Wa(t){let e=1;function r(n){switch(n.kind){case b.SyntaxKind.IfStatement:case b.SyntaxKind.ConditionalExpression:case b.SyntaxKind.ForStatement:case b.SyntaxKind.ForInStatement:case b.SyntaxKind.ForOfStatement:case b.SyntaxKind.WhileStatement:case b.SyntaxKind.DoStatement:case b.SyntaxKind.CatchClause:case b.SyntaxKind.CaseClause:e++;break;case b.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===b.SyntaxKind.AmpersandAmpersandToken||s===b.SyntaxKind.BarBarToken||s===b.SyntaxKind.QuestionQuestionToken)&&e++;break}}b.forEachChild(n,r)}return r(t),e}function Jn(t,e,r){let n=r?1:1+e,s=r?e:e+1;return n+=X(t.expression,s,!1),n+=X(t.thenStatement,s,!1),t.elseStatement&&(b.isIfStatement(t.elseStatement)?n+=Jn(t.elseStatement,e,!0):n+=1+X(t.elseStatement,e+1,!1)),n}function Kn(t,e){let r=1+e;return b.forEachChild(t,n=>{r+=X(n,e+1,!1)}),r}function za(t,e){let r=1+e;return b.forEachChild(t,n=>{r+=X(n,e,!1)}),r}function Ba(t,e){let r=0;return b.forEachChild(t,n=>{r+=X(n,e,!1)}),r}function Ha(t){let e=t.operatorToken.kind;return e===b.SyntaxKind.AmpersandAmpersandToken||e===b.SyntaxKind.BarBarToken||e===b.SyntaxKind.QuestionQuestionToken}function X(t,e,r){if(b.isIfStatement(t))return Jn(t,e,r);if(b.isForStatement(t)||b.isForInStatement(t)||b.isForOfStatement(t)||b.isWhileStatement(t)||b.isDoStatement(t)||b.isSwitchStatement(t))return Kn(t,e);if(b.isCatchClause(t))return za(t,e);let n=0;return b.isConditionalExpression(t)&&(n+=1),b.isBinaryExpression(t)&&Ha(t)&&(n+=1),e>0&&(b.isFunctionDeclaration(t)||b.isFunctionExpression(t)||b.isArrowFunction(t))?n+Kn(t,e):n+Ba(t,e)}function Ua(t){return X(t,0,!1)}function cr(t){return{complexity:Wa(t),cognitiveComplexity:Ua(t)}}import C from"typescript";var lr=new Set(["test","describe","it"]);function Vn(t,e){Ka(t,e),Va(t,e),Ya(t,e),Qa(t,e)}function Ka(t,e){if((C.isFunctionDeclaration(t)||C.isVariableDeclaration(t))&&t.name&&C.isIdentifier(t.name)&&Ja(t)){let r;if(C.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(C.isArrowFunction(n)||C.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Ja(t){if(C.isFunctionDeclaration(t))return C.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&C.isSourceFile(e.parent)}function Va(t,e){if(!C.isStringLiteral(t))return;let r=t.text.match(/@[\w-]+/g);if(r)for(let n of r)e.tags.add({name:n.substring(1),kind:"comment-marker"})}function Ya(t,e){if(!C.isSourceFile(t))return;let r=/@tag\s+([a-zA-Z0-9_-]+)/g,n=t.getFullText(),s=r.exec(n);for(;s!==null;)s[1]&&e.tags.add({name:s[1],kind:"comment-marker"}),s=r.exec(n)}function Qa(t,e){if(C.isCallExpression(t)&&Xa(t.expression))for(let r of t.arguments)C.isObjectLiteralExpression(r)&&Za(r,e)}function Xa(t){return C.isIdentifier(t)?lr.has(t.text):!!(C.isPropertyAccessExpression(t)&&(lr.has(t.name.text)||C.isIdentifier(t.expression)&&lr.has(t.expression.text)))}function Za(t,e){for(let r of t.properties){if(!C.isPropertyAssignment(r)||!C.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=C.isArrayLiteralExpression(n)?n.elements.filter(C.isStringLiteral):r.name.text==="tag"&&C.isStringLiteral(n)?[n]:[];for(let o of s)e.tags.add({name:o.text.replace(/^@/,""),kind:"comment-marker"})}}function pr(t,e,r){let n=[],s=new Map,o=new Set,i=h.createSourceFile(t,e,h.ScriptTarget.Latest,!0,r==="typescript"?h.ScriptKind.TSX:h.ScriptKind.JSX),a={filePath:t,imports:n,exports:s,tags:o,rawCallEdges:[],sourceFile:i,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=k=>{rc(k,a),h.forEachChild(k,c)};c(i);let l=fc(t,a);(l==="test"||l==="barrel")&&o.add({name:l,kind:"comment-marker"}),l!=="test"&&gc(a,i);let p=i.statements[0],u=p?Xn(p):void 0,{complexity:g,cognitiveComplexity:d}=cr(i),y=qa(i);return{imports:n,exports:Array.from(s.values()),tags:Array.from(o),category:l,rawCallEdges:a.rawCallEdges??[],complexity:g,cognitiveComplexity:d,...y.length>0?{functions:y}:{},...u!==void 0?{description:u}:{}}}function qa(t){let e=[],r=(s,o)=>{let{complexity:i,cognitiveComplexity:a}=cr(o),c=t.getLineAndCharacterOfPosition(o.getStart(t)).line+1;e.push({name:s,line:c,complexity:i,cognitiveComplexity:a})},n=(s,o)=>{if(h.isFunctionDeclaration(s)&&s.name&&s.body?r(s.name.text,s):h.isVariableDeclaration(s)&&h.isIdentifier(s.name)&&s.initializer&&(h.isArrowFunction(s.initializer)||h.isFunctionExpression(s.initializer))?r(s.name.text,s.initializer):o&&h.isMethodDeclaration(s)&&h.isIdentifier(s.name)&&s.body?r(`${o}.${s.name.text}`,s):o&&h.isConstructorDeclaration(s)&&s.body?r(`${o}.constructor`,s):o&&h.isGetAccessorDeclaration(s)&&h.isIdentifier(s.name)&&s.body?r(`${o}.get ${s.name.text}`,s):o&&h.isSetAccessorDeclaration(s)&&h.isIdentifier(s.name)&&s.body&&r(`${o}.set ${s.name.text}`,s),h.isClassDeclaration(s)&&s.name){let i=s.name.text;h.forEachChild(s,a=>n(a,i));return}h.forEachChild(s,i=>n(i,o))};return n(t,void 0),e}function Qn(t,e,r,n){let s={name:t},o=Xn(r);o!==void 0&&(s.doc=o);let i=ec(e);i!==void 0&&(s.flags=i);let a=tc(e,n);return a!==void 0&&(s.signature=a),s}function Xn(t){let e=h.getJSDocCommentsAndTags(t);for(let r of e)if(h.isJSDoc(r)&&r.comment)return h.getTextOfJSDocComment(r.comment)||void 0}function ec(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=h.getJSDocTags(t).map(n=>n.tagName.text).filter(n=>e.has(n));return r.length>0?r:void 0}function tc(t,e){let r=h.createPrinter({removeComments:!0}),n=s=>r.printNode(h.EmitHint.Unspecified,s,e);if(h.isFunctionDeclaration(t)||h.isMethodDeclaration(t)){let s=t.parameters.map(n).join(", "),o=t.type?n(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${s}) => ${o}`}if(h.isVariableDeclaration(t)){if(t.type)return n(t.type);if(t.initializer&&(h.isArrowFunction(t.initializer)||h.isFunctionExpression(t.initializer))){let s=t.initializer,o=s.parameters.map(n).join(", "),i=s.type?n(s.type):"unknown";return`(${o}) => ${i}`}return}if(h.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(h.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(h.isTypeAliasDeclaration(t))return n(t.type);if(h.isEnumDeclaration(t))return`enum ${t.name.text}`}function rc(t,e){nc(t,e),sc(t,e),ic(t,e),ac(t,e),mc(t,e),Vn(t,e)}function nc(t,e){if(!h.isSourceFile(t))return;let r=t.statements.filter(n=>!h.isEmptyStatement(n));e.totalStatements=r.length,e.exportStatements=r.filter(n=>h.isExportDeclaration(n)||h.isExportAssignment(n)||ur(n)).length}function sc(t,e){if(h.isJsxElement(t)||h.isJsxSelfClosingElement(t)||h.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(h.isFunctionDeclaration(t)||h.isMethodDeclaration(t)||h.isArrowFunction(t)||h.isClassDeclaration(t)||h.isVariableStatement(t)||h.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}h.isExportDeclaration(t)&&!oc(t)&&(e.hasTypesOnly=!1)}function oc(t){return t.isTypeOnly?!0:!t.exportClause||!h.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function ic(t,e){if(!h.isImportDeclaration(t)||!t.moduleSpecifier||!h.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(h.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)r.push(s.name.text);else h.isNamespaceImport(t.importClause.namedBindings)&&r.push("*");let n=r.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:N(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function ac(t,e){h.isExportDeclaration(t)?cc(t,e):h.isExportAssignment(t)?e.exports.set("default",{name:"default"}):ur(t)&&uc(t,e)}function cc(t,e){if(t.moduleSpecifier&&h.isStringLiteral(t.moduleSpecifier))lc(t,t.moduleSpecifier.text,e);else if(t.exportClause&&h.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let n=r.name.text;e.exports.set(n,{name:n})}}function lc(t,e,r){let n=pc(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:N(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function pc(t){return t.exportClause?h.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function uc(t,e){if((h.isFunctionDeclaration(t)||h.isClassDeclaration(t)||h.isInterfaceDeclaration(t)||h.isTypeAliasDeclaration(t)||h.isEnumDeclaration(t))&&t.name){let n=t.name.text;e.exports.set(n,Qn(n,t,t,e.sourceFile));return}if(h.isVariableStatement(t)){for(let n of t.declarationList.declarations)if(h.isIdentifier(n.name)){let s=n.name.text;e.exports.set(s,Qn(s,n,t,e.sourceFile))}}}function mc(t,e){if(!h.isCallExpression(t))return;let r=t.arguments[0];!r||!h.isStringLiteral(r)||(t.expression.kind===h.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"dynamic"}):h.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:N(r.text),type:"require"}))}function fc(t,e){let r=Yn.basename(t).toLowerCase(),n=Yn.extname(t).toLowerCase();return he().some(o=>r.includes(o))?"test":Jr(r)?"config":e.imports.some(o=>Mt().some(i=>o.rawSpecifier.includes(i)))?"test":n===".tsx"||n===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>_t()?"barrel":"logic"}function ur(t){return h.canHaveModifiers(t)&&h.getModifiers(t)?.some(e=>e.kind===h.SyntaxKind.ExportKeyword)===!0}function gc(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let n=new Map;for(let s of e.statements){if(!h.isImportDeclaration(s)||!h.isStringLiteral(s.moduleSpecifier))continue;let o=s.moduleSpecifier.text,i=s.importClause;if(i&&(i.name&&n.set(i.name.text,o),i.namedBindings&&h.isNamedImports(i.namedBindings)))for(let a of i.namedBindings.elements)n.set(a.name.text,o)}if(n.size!==0)for(let s of e.statements){let o=hc(s);if(o){let i=yc(s);i&&Ve(i,o,n,r);continue}h.isClassDeclaration(s)&&s.name&&dc(s,s.name.text,n,r)}}function dc(t,e,r,n){for(let s of t.members)h.isMethodDeclaration(s)&&s.body&&h.isIdentifier(s.name)?Ve(s.body,`${e}.${s.name.text}`,r,n):h.isConstructorDeclaration(s)&&s.body&&Ve(s.body,`${e}.constructor`,r,n)}function hc(t){if(ur(t)){if(h.isFunctionDeclaration(t)&&t.name)return t.name.text;if(h.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(h.isIdentifier(e.name)&&e.initializer&&(h.isArrowFunction(e.initializer)||h.isFunctionExpression(e.initializer)))return e.name.text}}}function yc(t){if(h.isFunctionDeclaration(t))return t.body;if(h.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(h.isArrowFunction(e.initializer)||h.isFunctionExpression(e.initializer)))return e.initializer}}function Ve(t,e,r,n){if(h.isCallExpression(t)&&h.isIdentifier(t.expression)){let s=t.expression.text,o=r.get(s);o&&!n.some(i=>i.from===e&&i.to===s&&i.toSpecifier===o)&&n.push({from:e,to:s,toSpecifier:o})}h.forEachChild(t,s=>Ve(s,e,r,n))}function Ye(t,e){if(e.length===0)return"ui";let r=!1;return t.walk(n=>{if(n.type==="rule")return r=!0,!1}),r?"ui":"barrel"}import qn from"postcss";import*as xc from"postcss-less";var Sc=xc,es=new Set(["reference","inline"]);function Zn(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function bc(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function kc(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let o=r[1]?.trim()??"",i=r[2]??"";if(!i)return null;let a=es.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...Zn(i)?{isExternal:!0}:{}}}let n=t.match(/^url\(['"]?([^'")]+)['"]?\)/),s=n?n[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return s?{fromPath:e,toPath:"",rawSpecifier:s,isStyle:!0,type:"static",...Zn(s)?{isExternal:!0}:{}}:null}function vc(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let o=s[1]?.trim()??"";bc(o)&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function ts(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=kc(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...vc(n.value,e))}),r}function Cc(t){return t.replace(/(?<!:)\/\/.*/g,"")}function wc(t,e){let r=[],n=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let o=s[1]?.trim()??"",i=s[2]??"";if(i){let a=es.has(o)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}s=n.exec(t)}return r}function Qe(t,e){let r=qn.parse(Cc(t));return{imports:ts(r,e),root:r}}function Ec(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type!=="atrule")continue;let{value:s}=n;if(s===void 0)continue;let o=n.name;o&&(e.push({name:o}),r.push({name:o,kind:"variable"}))}return{exports:e,tags:r}}function Xe(t,e){try{let r=Sc.parse(t),{exports:n,tags:s}=Ec(r);return{imports:ts(r,e),root:r,exports:n,tags:s}}catch{return{imports:wc(t,e),root:qn.parse(""),exports:[],tags:[]}}}import{parse as Tc}from"postcss-scss";function rs(t){return t.startsWith("_")||t.startsWith("-")}function Fc(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Nc(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let r=e[1],s=t.match(/\bas\s+(\S+)/)?.[1];return s!==void 0?{specifier:r,alias:s}:{specifier:r}}function Pc(t){let e=[],r=[];for(let n of t.nodes??[]){if(n.type==="decl"&&n.prop.startsWith("$")){let s=n.prop.slice(1);if(!s||rs(s))continue;e.push({name:s}),r.push({name:s,kind:"variable"});continue}if(n.type==="atrule"&&(n.name==="mixin"||n.name==="function")){let o=n.params.match(/^([\w-]+)/)?.[1];if(!o||rs(o))continue;let i=n.params.trim();e.push(i.includes("(")?{name:o,signature:i}:{name:o}),r.push({name:o,kind:"function"})}}return{exports:e,tags:r}}function Ze(t,e){let r=Tc(t),n=[];r.walk(i=>{if(i.type!=="atrule")return;let{name:a,params:c}=i;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=Nc(c);if(!l)return;let u={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...Fc(l)?{isExternal:!0}:{}};p&&(u.symbols=[p]),n.push(u)});let{exports:s,tags:o}=Pc(r);return{imports:n,root:r,exports:s,tags:o}}function ns(t,e){let r=[],n=/@require\s+['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let i=s[1];i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"require"}),s=n.exec(t)}let o=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=o.exec(t);s!==null;){let i=s[1];i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=o.exec(t)}return r}function ss(t,e){if(e.length===0)return"ui";try{let r=Pt("stylus");return new r.Parser(t).parse().nodes.some(o=>o.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function ve(t,e){let r=_(t);if(r==="stylus"){let o=ns(e,t);return{imports:o,exports:[],tags:[],category:ss(e,o)}}if(r==="scss"){let{imports:o,root:i,exports:a,tags:c}=Ze(e,t);return{imports:o,exports:a,tags:c,category:Ye(i,o)}}if(r==="less"){let{imports:o,root:i,exports:a,tags:c}=Xe(e,t);return{imports:o,exports:a,tags:c,category:Ye(i,o)}}let{imports:n,root:s}=Qe(e,t);return{imports:n,exports:[],tags:[],category:Ye(s,n)}}for(let[t,e]of[["javascript",(r,n)=>pr(r,n,"javascript")],["typescript",(r,n)=>pr(r,n,"typescript")],["css",ve],["scss",ve],["less",ve],["stylus",ve],["coffeescript",Cn],["livescript",On],["lua",Gn],["python",Hn],["go",Rn],["java",Ln],["kotlin",_n],["scala",Un],["groovy",In],["gherkin",Zt],["markdown",Wn]])ae(t,e);async function os(t,e){let r=_(t),n=En(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}import is from"path";function Rc(t,e){let r=e.get(t.path);r!==void 0&&(t.coveragePct=r)}function cs(t,e){for(let r of t)if(r.isExternal){let n=r.rawSpecifier.startsWith("@")?r.rawSpecifier.split("/").slice(0,2).join("/"):r.rawSpecifier.split("/")[0];n&&!e.some(s=>s.name===n)&&e.push({name:n,kind:"library"})}}function Ic(t,e,r){if(e.isExternal||!e.toPath)return;let n=r.get(e.toPath);n&&(n.category!=="logic"&&n.category!=="barrel"||(n.testedBy??=[],n.testedBy.includes(t.path)||n.testedBy.push(t.path)))}function Dc(t,e){if(t.type==="markdown")for(let r of t.imports){if(r.isExternal||!r.toPath)continue;let n=e.get(r.toPath);!n||n===t||(n.documentedBy??=[],n.documentedBy.includes(t.path)||n.documentedBy.push(t.path),n.category==="logic"&&(n.lastCommitAt??0)>(t.lastCommitAt??0)&&(t.staleFor??=[],t.staleFor.includes(n.path)||t.staleFor.push(n.path)))}}function as(t){return Math.round(t*1e4)/1e4}function Mc(t,e){let r=[];for(let n of t.imports){if(n.isExternal||!n.toPath)continue;let s=e.get(n.toPath);if(!s||s.exports.length===0)continue;let o;if(n.symbols===void 0){if(n.type==="side-effect")continue;o=1}else n.symbols.includes("*")?o=1:o=n.symbols.length/s.exports.length;n.exportUsageRatio=as(Math.min(1,o)),r.push(n.exportUsageRatio)}r.length>0&&(t.avgExportUsage=as(r.reduce((n,s)=>n+s,0)/r.length),t.maxExportUsage=Math.max(...r))}function mr(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function Ac(t,e){let r=e.toPath,n=is.basename(r,is.extname(r)).replace(/\.(test|spec)$/,"");mr(t.tags,n,"import")}function Lc(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)mr(t.tags,r,"import")}function _c(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&mr(t.tags,s.name,"comment-marker")}function Oc(t,e,r){!e.toPath||e.isExternal||(Ac(t,e),Lc(t,e),_c(t,e,r))}function ls(t,e){for(let r of t.values())delete r.testedBy,delete r.documentedBy,delete r.staleFor,r.category==="test"&&(r.tags=r.tags.filter(n=>n.kind!=="import"));for(let r of t.values()){if(Mc(r,t),e.size>0&&Rc(r,e),r.category==="test")for(let n of r.imports)Ic(r,n,t),Oc(r,n,t);Dc(r,t)}}var ps=new Set(["java","kotlin","scala","groovy"]),us=new Set(["typescript","javascript","python","go","java","kotlin","scala","groovy","scss","less","lua","coffeescript"]),ms=new Set(["typescript","javascript","python"]),qe=new Set(["typescript","javascript","go","python","java"]);function Gc(t){let e=new Map;for(let r of t.nodes.values())e.set(r.type,(e.get(r.type)??0)+1);return[...e.entries()].map(([r,n])=>({type:r,fileCount:n,exportsTracked:us.has(r),importSymbolsTracked:ms.has(r),callEdgesTracked:qe.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}import nt from"fs";import j from"path";import ds from"fs";import fe from"path";var Ce=class{extensions=[".go"];goModCache=new Map;resolve(e,r,n,s){let{mod:o,replaces:i}=this.readGoMod(n);if(!o)return null;let a=this.applyReplace(r,i,n);if(a!==void 0)return gs(a);if(r!==o&&!r.startsWith(`${o}/`))return null;let c=r.slice(o.length).replace(/^\//,"");return c?gs(fe.join(n,c)):null}readGoMod(e){let r=this.goModCache.get(e);if(r!==void 0)return r;let n={mod:null,replaces:new Map};try{let s=ds.readFileSync(fe.join(e,"go.mod"),"utf-8"),o=jc(s,e);return this.goModCache.set(e,o),o}catch{return this.goModCache.set(e,n),n}}applyReplace(e,r,n){for(let[s,o]of r){if(e===s)return o;if(e.startsWith(`${s}/`)){let i=e.slice(s.length+1);return fe.join(o,i)}}}};function jc(t,e){let r=t.split(`
10
- `),n=null,s=new Map,o=!1;for(let i of r){let a=i.trim();if(a.startsWith("module ")){n=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){o=!0;continue}if(o&&a===")"){o=!1;continue}if(o&&a.includes("=>")){fs(a,e,s);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&fs(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function fs(t,e,r){let[n,s]=t.split("=>").map(a=>a.trim());if(!n||!s)return;let o=n.split(/\s+/)[0];if(!s.startsWith(".")&&!s.startsWith("/"))return;let i=fe.isAbsolute(s)?s:fe.resolve(e,s);r.set(o,i)}function gs(t){let e;try{e=ds.readdirSync(t,{withFileTypes:!0})}catch{return null}let r=e.filter(n=>n.isFile()&&n.name.endsWith(".go")&&!n.name.endsWith("_test.go")).map(n=>({path:fe.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}import et from"fs";import tt from"path";var $c=new Set([".java",".kt",".kts",".scala",".sc",".groovy"]),Wc=12,hs=4096,zc=new Set(er);function xs(t){let e=t.replace(/\\/g,"/"),r=e.match(/^(.*)\/src\/([^/]+)(?:\/|$)/);if(!r?.[1]||!r[2]){let o=e.lastIndexOf("/");return{module:o===-1?e:e.slice(0,o),rootSegment:"",sourceRoot:"unknown"}}let n=r[2],s=n==="main"?"main":zc.has(n)?n:"unknown";return{module:r[1],rootSegment:n,sourceRoot:s}}var Z=class{constructor(e=[]){this.extraIgnoreDirs=e}extraIgnoreDirs;extensions=[".java",".kt",".kts",".scala",".sc",".groovy",".gradle"];indexCache=new Map;resolve(e,r,n,s){let o=this.getIndex(n);if(o.size===0)return null;let i=r.endsWith(".*"),a=(i?r.slice(0,-2):r).split(".").filter(Boolean);if(a.length===0)return null;if(i){let c=o.get(a.join("."));if(!c)return null;let l=xs(e),p=c.filter(d=>d.module===l.module&&d.rootSegment===l.rootSegment),u=l.sourceRoot!=="main"&&l.sourceRoot!=="unknown",g=p.flatMap(d=>u?d.files:d.files.filter(y=>!tr(ys(y))));return fr(g)}for(let c=a.length-1;c>=1;c--){let l=Hc(o,a.slice(0,c).join("."));if(!l)continue;let p=a[c],u=l.filter(g=>ys(g)===p);if(u.length>0)return fr(u);if(c===a.length-1)return fr(l)}return null}getIndex(e){let r=this.indexCache.get(e);if(r)return r;let n=Bc(e,this.extraIgnoreDirs);return this.indexCache.set(e,n),n}};function Bc(t,e=[]){let r=new Map,n=(process.env.MOKOSH_IGNORE_DIRS??"").split(",").map(a=>a.trim()).filter(Boolean),s=new Set([...I,...n,...e]),o=(a,c)=>{let{module:l,rootSegment:p,sourceRoot:u}=xs(c),g=r.get(a);if(!g){r.set(a,[{module:l,rootSegment:p,sourceRoot:u,files:[c]}]);return}let d=g.find(y=>y.module===l&&y.rootSegment===p);d?d.files.push(c):g.push({module:l,rootSegment:p,sourceRoot:u,files:[c]})},i=(a,c)=>{if(c>Wc)return;let l;try{l=et.readdirSync(a,{withFileTypes:!0})}catch{return}for(let p of l){let u=tt.join(a,p.name);if(p.isDirectory()){!p.name.startsWith(".")&&!s.has(p.name)&&i(u,c+1);continue}if(!p.isFile())continue;let g=tt.extname(p.name);if(!$c.has(g))continue;let d=Uc(u,g===".scala"||g===".sc");d&&o(d,u)}};i(t,0);for(let a of r.values())for(let c of a)c.files.sort();return r}function Hc(t,e){let r=t.get(e);if(!(!r||r.length===0))return r.length===1?r[0]?.files:r.flatMap(n=>n.files).sort()}function Uc(t,e){let r;try{let n=et.openSync(t,"r");try{let s=Buffer.alloc(hs),o=et.readSync(n,s,0,hs,0);r=s.toString("utf8",0,o)}finally{et.closeSync(n)}}catch{return null}return D(r,e)}function fr(t){return!t||t.length===0?null:t.map(e=>({path:e,isExternal:!1}))}function ys(t){return tt.basename(t,tt.extname(t))}import Kc from"fs";import gr from"path";var we=class{extensions=[".lua"];resolve(e,r,n,s){let o=r.replace(/\./g,gr.sep),i=[n,gr.join(n,"lib")];for(let a of i){if(!Kc.existsSync(a))continue;let c=s(gr.join(a,"_dummy.lua"),o);if(c)return[c]}return null}};import Jc from"path";var Vc=new Set(I),Ee=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let o=r.replace(/^\.\//,"").split("/")[0];if(o&&Vc.has(o))return null;let i=s(Jc.join(n,"_dummy"),`./${r}`);return i?[i]:null}};import Yc from"fs";import dr from"path";var Te=class{extensions=[".py"];resolve(e,r,n,s){let o=r.replace(/\./g,dr.sep),i=dr.join(n,`${o}.py`);if(Ss(i))return[{path:i,isExternal:!1}];let a=dr.join(n,o,"__init__.py");return Ss(a)?[{path:a,isExternal:!1}]:null}};function Ss(t){try{return Yc.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import bs from"path";var Qc=["~","http://","https://","//","data:","sass:"],Fe=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(Qc.some(p=>r.startsWith(p)))return null;let o=s(e,r);if(o)return[o];let i=bs.dirname(r),a=bs.basename(r),c=i==="."?`_${a}`:`${i}/_${a}`,l=s(e,c);return l?[l]:null}};function rt(t={}){return[new Te,new we,new Ce,t.jvm??new Z,new Fe,new Ee]}var $=class{constructor(e,r={}){this.rootDir=e;this.workspaceMap=r.workspaceMap??new Map,this.tsconfigSearchPaths=r.tsconfigSearchPaths??[e],this.pathAliases=r.pathAliases,this.langResolvers=r.langResolvers??rt()}rootDir;workspaceMap;tsconfigSearchPaths;pathAliases;langResolvers;resolutionCache=new Map;langBucketFor(e){for(let r=0;r<this.langResolvers.length;r++)if(this.langResolvers[r]?.extensions.some(n=>e.endsWith(n)))return String(r);return"none"}cacheKey(e,r){return`${j.dirname(e)}\0${this.langBucketFor(e)}\0${r}`}resolveAll(e,r){let n=this.cacheKey(e,r),s=this.resolutionCache.get(n);if(s!==void 0)return s??[];let o=this.resolveAllUncached(e,r);return this.resolutionCache.set(n,o.length>0?o:null),o}resolveAllUncached(e,r){let n=this.resolvePathAlias(r);if(n)return[n];if(r.startsWith(".")||r.startsWith("/")){let i=this.resolveLocalPath(e,r);return i?[i]:[]}let s=(i,a)=>this.resolveLocalPath(i,a);for(let i of this.langResolvers)if(i.extensions.some(a=>e.endsWith(a))){let a=i.resolve(e,r,this.rootDir,s);if(a)return a}let o=this.resolveWorkspaceImport(r);return o?[o]:[{path:r,isExternal:!0}]}resolve(e,r){return this.resolveAll(e,r)[0]??null}resolveLocalPath(e,r){let n=j.dirname(e),s=r.startsWith("/")?r:j.resolve(n,r),o=!s.startsWith(this.rootDir),i=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=s.match(/\.(js|mjs|cjs)$/);if(a){let c=s.slice(0,-a[0].length);for(let l of[".ts",".tsx"]){let p=this.tryExtensions(c,l,o);if(p)return p}}for(let c of i){let l=this.tryExtensions(s,c,o);if(l)return l}return o?{path:s,isExternal:!0}:null}tryExtensions(e,r,n){let s=e+r;if(this.isFile(s))return{path:s,isExternal:n};let o=j.join(e,`index${r}`);if(this.isFile(o))return{path:o,isExternal:n};if(r===".py"){let i=j.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:n}}return null}isFile(e){try{return nt.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){if(this.pathAliases)for(let r in this.pathAliases){let n=this.matchAliasPattern(r,e),s=this.pathAliases[r];if(n&&s){let o=this.tryAliasSubstitutions(s,n[1]||"");if(o)return o}}for(let r of this.tsconfigSearchPaths){let n=j.join(r,"tsconfig.json");if(nt.existsSync(n))try{let o=JSON.parse(nt.readFileSync(n,"utf-8")).compilerOptions?.paths;if(!o)continue;for(let i in o){let a=this.matchAliasPattern(i,e);if(a){let c=this.tryAliasSubstitutions(o[i],a[1]||"",r);if(c)return c}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,r){let n=this.aliasRegexCache.get(e);if(!n){let s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");n=new RegExp(`^${s}$`),this.aliasRegexCache.set(e,n)}return r.match(n)}tryAliasSubstitutions(e,r,n=this.rootDir){let s=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let o of e){let i=o.replace("*",r),a=j.resolve(n,i);for(let c of s){let l=this.tryExtensions(a,c,!1);if(l)return l}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[r,n]of this.workspaceMap){if(e!==r&&!e.startsWith(`${r}/`))continue;let s=e.slice(r.length),o={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:r};if(!s){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let c=j.join(n,a);try{if(nt.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...o,path:c}}catch{}}return{...o,path:n}}let i=this.resolveLocalPath(j.join(n,"_dummy"),s.slice(1));return i?{...o,path:i.path}:null}return null}};var Zc=["tests","test","__tests__","specs","spec"],qc=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage",".pytest_cache","__pycache__"],el=600;function tl(){return(process.env.MOKOSH_IGNORE_DIRS??"").split(",").map(t=>t.trim()).filter(Boolean)}function rl(t,e){if(t.length===0)return e;let r=t.map(i=>F.dirname(i).split(F.sep)),n=r[0]??[];for(let i of r.slice(1)){let a=0;for(;a<n.length&&a<i.length&&n[a]===i[a];)a++;n=n.slice(0,a)}let s=n.join(F.sep)||F.sep,o=F.relative(e,s);return o.startsWith("..")||F.isAbsolute(o)?e:s}var q=class{constructor(e,r=null,n,s,o=!1,i=new Map,a=!0,c=[],l=null){this.rootDir=e;this.enableGitStats=o;this.coverageMap=i;this.parallelParsing=a;this.docFiles=l;this.previousGraph=r,this.walkIgnoreDirs=new Set([...qc,...c,...tl()]),this.resolver=n||new $(e),this.lockFile=Sn(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;docFiles;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;walkIgnoreDirs;async build(e){let r=e.map(n=>F.isAbsolute(n)?n:F.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=mn(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(rl(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
1
+ var sn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});import ea from"path";import{fileURLToPath as ta}from"url";var na=()=>ta(import.meta.url),ra=()=>ea.dirname(na()),f=ra();import yn from"fs";import $r from"path";var sa=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],on=[];function st(t){on.push(t)}function _r(t){return[...sa,...on].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var ia=[".test.",".spec.","-test.","-spec."],an=[];function it(t){an.push(t)}function Le(){return[...ia,...an]}var oa=["jest","vitest","playwright","cypress","@testing-library/"],cn=[];function ot(t){cn.push(t)}function ln(){return[...oa,...cn]}var Gr=.8,pn=Gr;function un(t){pn=t}function fn(){return pn}function at(){on.length=0,an.length=0,cn.length=0,pn=Gr}var ct=["comment-marker","import"],Or=new Set(["test","barrel"]),jr=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,lt=new Set(["index","main","common","shared","types","type","constants","const","config","util","utils","helper","helpers","mock","mocks","fixture","fixtures","setup","spec","test","tests","args","props","options","opts","context","ctx","handler","handlers","callback","cb","fn","impl","run","get","set","use","name","value","data","item","result","node","org","linux","darwin","windows","freebsd","openbsd","netbsd","dragonfly","solaris","android","ios","js","wasm","wasip1","plan9","aix","illumos","amd64","arm","arm64","ppc64","ppc64le","mips","mips64","riscv64","s390x","loong64","cgo","gc","gccgo","unix"]),mn=new Set(lt);function gn(t){let e=new Set(lt);for(let n of t?.blocklist??[])e.add(n.toLowerCase());for(let n of t?.allowlist??[])e.delete(n.toLowerCase());mn=e}function dn(){mn=new Set(lt)}function pt(t){if(!jr.test(t))return!1;let e=t.toLowerCase();return!Or.has(e)&&!mn.has(e)}function ne(t){return ct.includes(t.kind)&&pt(t.name)}function hn(t){let e=new Set,n=[];for(let r of t)!ne(r)||e.has(r.name)||(e.add(r.name),n.push(r.name));return n}var aa=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function xn(t,{allowJs:e=!0,isExplicitPath:n=!1}={}){if(n){let r=$r.resolve(t);return yn.existsSync(r)?r.endsWith(".json")?Wr(r):e?zr(r):{}:{}}for(let r of aa){let s=$r.resolve(t,r);if(yn.existsSync(s)){if(r.endsWith(".json"))return Wr(s);if(e)return zr(s)}}return{}}function Wr(t){return JSON.parse(yn.readFileSync(t,"utf-8"))}function zr(t){let e=sn(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function ca(t){at(),dn(),gn(t.tags);for(let e of t.configMatchers??[])st(e);for(let e of t.testPatterns??[])it(e);for(let e of t.testLibraries??[])ot(e);t.barrelThreshold!==void 0&&un(t.barrelThreshold)}function la(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases,additionalIgnoreDirs:t?.ignoreDirs}}var Sn="mokosh-cache",bn="duplication-tokens.json",pa="duplication-result.json",ua="graph.json",fa="workspace-graph.json",ma="workspace",ga="manifest.json",da=1,ha=50331648,kn="branch-graphs",I=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage",".pytest_cache","__pycache__",".gradle","target"],vn=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".java",".kt",".kts",".scala",".sc",".groovy",".gradle",".feature",".md",".mdx"];import ya from"fs";import Br from"path";function xa(t,e){let n=Br.resolve(t,e);try{let r=ya.readFileSync(n,"utf-8"),s=JSON.parse(r),i=new Map;if(typeof s!="object"||s===null)return i;for(let[o,a]of Object.entries(s)){if(o==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Br.relative(t,o);i.set(l,c)}return i}catch{return new Map}}var Cn={serialize(t){let e=["graph TD"],n=new Set;for(let r of t.nodes.values()){let s=`"${r.path}"`;for(let i of r.imports){if(!i.toPath)continue;let o=`"${i.toPath}"`,a=`${r.path} -> ${i.toPath}`;if(!n.has(a)){let c=i.isStyle?"-- styles -->":"-->";e.push(` ${s} ${c} ${o}`),n.add(a)}}}return e.join(`
2
+ `)}};function Kr(t){return Cn.serialize(t)}var he=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let n=new Set(this.nodes.keys());return e.filter(r=>!n.has(r))}findHighExportUsage(e){let n=[];for(let r of this.nodes.values()){if(r.maxExportUsage===void 0||r.maxExportUsage<e)continue;let s=r.imports.reduce((i,o)=>(o.exportUsageRatio??0)>(i?.exportUsageRatio??0)?o:i,null);n.push({path:r.path,maxExportUsage:r.maxExportUsage,tightestDep:s?.toPath??""})}return n.sort((r,s)=>s.maxExportUsage-r.maxExportUsage)}traversableTargets(e,n){let r=this.nodes.get(e);if(!r)return[];let s=new Set;for(let i of r.imports)!i.toPath||i.isExternal||i.isSamePackage&&!n.has("samePackage")||i.isDocReference&&!n.has("docReference")||s.add(i.toPath);return[...s]}findCycles(e={}){let n=new Set(e.includeKinds??[]),r=[],s=new Set,i=new Set,o=[],a=c=>{s.add(c),i.add(c),o.push(c);for(let l of this.traversableTargets(c,n))if(i.has(l)){let p=o.indexOf(l);r.push([...o.slice(p),l])}else s.has(l)||a(l);i.delete(c),o.pop()};for(let c of this.nodes.keys())s.has(c)||a(c);return e.expandComponents?r:this.collapseByComponent(r,n)}collapseByComponent(e,n){if(e.length<=1)return e;let r=this.componentIds(n),s=new Map,i=new Map;for(let[o,a]of e.entries()){let c=r.get(a[0]);if(c===void 0)continue;i.has(c)||i.set(c,o);let l=s.get(c);(l===void 0||Sa(a,l))&&s.set(c,a)}return[...s.entries()].sort(([o],[a])=>i.get(o)-i.get(a)).map(([,o])=>o)}componentIds(e){let n=new Map,r=new Map,s=new Set,i=[],o=new Map,a=0,c=0;for(let l of this.nodes.keys()){if(n.has(l))continue;let p=[{node:l,targets:this.traversableTargets(l,e),next:0}];for(n.set(l,a),r.set(l,a),a++,i.push(l),s.add(l);p.length>0;){let u=p[p.length-1];if(u.next<u.targets.length){let m=u.targets[u.next++];n.has(m)?s.has(m)&&r.set(u.node,Math.min(r.get(u.node),n.get(m))):(n.set(m,a),r.set(m,a),a++,i.push(m),s.add(m),p.push({node:m,targets:this.traversableTargets(m,e),next:0}))}else{if(r.get(u.node)===n.get(u.node)){let d=[],y;do y=i.pop(),s.delete(y),d.push(y);while(y!==u.node);if(d.length>1){for(let k of d)o.set(k,c);c++}}p.pop();let m=p[p.length-1];m&&r.set(m.node,Math.min(r.get(m.node),r.get(u.node)))}}}return o}};function Sa(t,e){return t.length!==e.length?t.length<e.length:t.join("\0")<e.join("\0")}import Ur from"fs";import ba from"path";var ka=25,va=30,Ca=50;function Ea(t,e={}){let n=e.maxExports??va,r=e.maxUnreachable??Ca,s={};for(let c of t.publicExports)s[c.kind]=(s[c.kind]??0)+1;let i=t.publicExports.slice(0,n).map(c=>({name:c.name,kind:c.kind})),o=t.unreachableFromEntry.slice(0,r),a={entryPoints:t.entryPoints.slice(0,ka),entryPointCount:t.entryPoints.length,publicExportCount:t.publicExports.length,publicExports:i,byKind:s,internalFileCount:t.internalFiles.length,unreachableFromEntryCount:t.unreachableFromEntry.length,unreachableFromEntry:o,testFileCount:t.testFiles.length,hint:`Pass view:"exports" for all ${t.publicExports.length} exports with docs, signatures and definedIn; view:"full" for that plus the internalFiles / testFiles path lists.`};return t.entryPoints.length>a.entryPoints.length&&(a.entryPointsTruncated=!0),i.length<t.publicExports.length&&(a.publicExportsTruncated=!0),o.length<t.unreachableFromEntry.length&&(a.unreachableFromEntryTruncated=!0),a}function ut(t,e){let n=t.replace(/^\.\//,"");if(e.nodes.has(n))return n;let r=n.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(r)?r:null}function Hr(t,e){if(typeof t=="string")return ut(t,e);if(t&&typeof t=="object"){let n=t;for(let r of["import","require","default"]){let s=Hr(n[r],e);if(s)return s}}return null}function wa(t){if(!t)return"unknown";let e=t.trimStart();return e.startsWith("interface ")?"interface":e.startsWith("class ")?"class":e.startsWith("enum ")?"enum":e.startsWith("type ")?"type":e.startsWith("namespace ")?"namespace":e.startsWith("const ")||e.startsWith("let ")||e.startsWith("var ")||e.startsWith("readonly ")?"const":e.startsWith("(")||e.startsWith("async ")||e.startsWith("function ")||e.includes("=>")?"function":"unknown"}function Ta(t,e){let n=new Set,r=new Set,s=[...e];for(;s.length;){let i=s.shift();if(r.has(i))continue;r.add(i);let o=t.nodes.get(i);if(o){for(let a of o.exports)n.add(a.name);for(let a of o.imports){if(a.type!=="re-export"||a.isExternal||!a.toPath)continue;if(!a.symbols?.length||a.symbols.includes("*")){let l=t.nodes.get(a.toPath);if(l)for(let p of l.exports)n.add(p.name);s.push(a.toPath)}else for(let l of a.symbols)n.add(l)}}}return n}function Fa(t,e){return Jr(t,e)[0]??null}function Jr(t,e){let n=[],r=ba.join(e,"package.json");if(Ur.existsSync(r))try{let s=JSON.parse(Ur.readFileSync(r,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let o of Object.values(s.exports)){let a=Hr(o,t);a&&!n.includes(a)&&n.push(a)}else if(typeof s.exports=="string"){let o=ut(s.exports,t);o&&n.push(o)}let i=typeof s.bin=="string"?[s.bin]:s.bin&&typeof s.bin=="object"&&!Array.isArray(s.bin)?Object.values(s.bin).filter(o=>typeof o=="string"):[];for(let o of i){let a=ut(o,t);a&&!n.includes(a)&&n.push(a)}if(n.length===0)for(let o of[s.main,s.module].filter(Boolean)){let a=ut(o,t);a&&!n.includes(a)&&n.push(a)}}catch{}if(n.length===0){for(let s of["src/index.ts","src/index.js","index.ts","index.js"])if(t.nodes.has(s)){n.push(s);break}}return n.length===0?Ra(t):n}var Da=new Set(["java","kotlin","scala","groovy"]);function Na(t){return t.endsWith("_test.go")||/(^|\/)(test|tests|__tests__|testdata)\//.test(t)||/[._-](test|spec)\.[^/]+$/.test(t)}function Ra(t){let e=[...t.nodes.values()],n=o=>e.filter(a=>o(a.type)&&a.category!=="test"&&!Na(a.path)),r=n(o=>o==="python");if(r.length>0){let o=r.filter(a=>a.path.replace(/^.*\//,"")==="__init__.py");if(o.length>0){let a=Math.min(...o.map(c=>c.path.split("/").length));return o.filter(c=>c.path.split("/").length===a).map(c=>c.path).sort()}return r.map(a=>a.path).sort()}let s=n(o=>o==="go");if(s.length>0)return s.map(o=>o.path).sort();let i=n(o=>Da.has(o));return i.length>0?i.map(o=>o.path).sort():[]}function Pa(t,e){let n=new Set(e);for(let r of e)t.traverse(r,s=>(n.add(s.path),!0),{direction:"outgoing"});return n}function La(t,e,n){let r=new Map;for(let s of e){if(n.includes(s))continue;let i=t.nodes.get(s);if(!i)continue;let o=i.category==="barrel";for(let a of i.exports){let c=r.get(a.name),l=!!(a.signature||a.doc);(!c||l&&!o)&&r.set(a.name,{file:s,symbol:a})}}return r}function Aa(t,e,n,r){let s=[];for(let i of t){let o=e.get(i),a=r.flatMap(u=>n.nodes.get(u)?.exports??[]).find(u=>u.name===i),c=o?.symbol??a,l=o?.file??r.find(u=>n.nodes.get(u)?.exports.some(m=>m.name===i))??r[0],p={name:i,definedIn:l,kind:wa(c?.signature)};c?.doc&&(p.doc=c.doc),c?.signature&&(p.signature=c.signature),s.push(p)}return s.sort((i,o)=>i.name.localeCompare(o.name)),s}function Ia(t,e,n){let r=c=>t.nodes.get(c)?.category==="test",s=[...e].filter(c=>!n.includes(c)&&!r(c)),i=[...t.nodes.keys()].filter(c=>!e.has(c)),o=i.filter(c=>!r(c)),a=i.filter(c=>r(c));return{internalFiles:s,unreachableFromEntry:o,testFiles:a}}function Ma(t,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let l of e)if(!t.nodes.has(l))throw new Error(`Entry point not found in graph: ${l}`);let n=Pa(t,e),r=La(t,n,e),s=Ta(t,e),i=Aa(s,r,t,e),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=Ia(t,n,e);return{entryPoints:e,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function _a(t,e){let n=null,r=[];for(let i of t.nodes.values()){i.exports.some(o=>o.name===e)&&(n=i.path);for(let o of i.callEdges??[])o.to===e&&r.push({file:i.path,callerFunction:o.from})}let s=[];if(n){let i=t.nodes.get(n);for(let o of i?.callEdges??[])o.from===e&&s.push({file:o.toFile,calleeFunction:o.to})}return{functionName:e,definedIn:n,callers:r,callees:s}}import Ae from"fs";import Ga from"path";function En(t){let e=[...t.nodes.entries()].sort(([r],[s])=>r.localeCompare(s)).map(([r,s])=>`${r}:${s.mtime}:${s.size}`).join("|"),n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}function Oa(t){let e=new Map;for(let n of t.nodes.keys()){let r=[];t.traverse(n,s=>(s.path!==n&&r.push(s.path),!0),{direction:"incoming"}),e.set(n,r)}return{impact:e,graphHash:En(t)}}function ja(t,e){return t.impact.get(e)??[]}function $a(t,e){return t.graphHash===En(e)}function Wa(t,e){let n=Ga.dirname(e);Ae.existsSync(n)||Ae.mkdirSync(n,{recursive:!0});let r={graphHash:t.graphHash,impact:[...t.impact.entries()]};Ae.writeFileSync(e,JSON.stringify(r))}function za(t){if(!Ae.existsSync(t))return null;try{let e=Ae.readFileSync(t,"utf-8"),n=JSON.parse(e);return{graphHash:n.graphHash,impact:new Map(n.impact)}}catch{return null}}import sf from"path";import Ie from"fs";import Vr from"path";var O=class t{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let n=new Map;for(let r of e.nodes)n.set(r.path,r);return new t(n)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let n of this.nodes.values())for(let r of n.imports)if(r.toPath){let s=e.get(r.toPath)||[];s.push(n.path),e.set(r.toPath,s)}return this._incomingEdgesCache=e,e}dfs(e,n,r,s){let i=new Set,o=r.maxDepth??1/0,a=[{path:e,depth:0,parent:null}];for(;a.length>0;){let c=a.pop(),{path:l,depth:p,parent:u}=c;if(p>o||i.has(l))continue;let m=this.nodes.get(l);if(!m||(i.add(l),n(m,p,u)===!1))continue;let d=s(l);for(let y=d.length-1;y>=0;y--)a.push({path:d[y],depth:p+1,parent:l})}}traverse(e,n,r={}){let s=r.direction??"outgoing",i=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,n,r,o=>s==="outgoing"?this.nodes.get(o)?.imports.map(a=>a.toPath).filter(Boolean)??[]:i?.get(o)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let n of this.nodes.values())for(let r of n.callEdges??[]){let s=e.get(r.toFile)??[];s.push(n.path),e.set(r.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,n,r={}){let s=r.direction??"outgoing",i=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,n,r,o=>s==="outgoing"?this.nodes.get(o)?.callEdges?.map(a=>a.toFile)??[]:i?.get(o)??[])}getCallers(e){let n=[];return this.traverseCalls(e,r=>(r.path!==e&&n.push(r.path),!0),{direction:"incoming",maxDepth:1}),n}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let n=this.nodes.get(e);return n?n.imports.map(r=>this.nodes.get(r.toPath)).filter(r=>r!==void 0):[]}findUnusedFiles(e){return new he(this.nodes).findUnusedFiles(e)}findCycles(e){return new he(this.nodes).findCycles(e)}};function ft(t){return Vr.join(t,Sn,kn)}function Qr(t,e){return Vr.join(ft(t),`${e}.json`)}function Yr(t,e){let n=Qr(t,e);if(!Ie.existsSync(n))return null;try{let r=Ie.readFileSync(n,"utf-8");return O.deserialize(JSON.parse(r))}catch{return null}}function Xr(t,e,n){let r=ft(t);Ie.existsSync(r)||Ie.mkdirSync(r,{recursive:!0}),Ie.writeFileSync(Qr(t,e),JSON.stringify(n.serialize()))}import Ue from"fs";import R from"path";import zp from"piscina";import{execFileSync as Zr}from"child_process";var qr="%x00%H%x09%ae%x09%at",es=256*1024*1024;function ts(t,e){let n="",r=0;for(let s of t.split(`
3
+ `)){if(s.startsWith("\0")){let[,c,l]=s.slice(1).split(" ");n=c??"",r=l?Number(l)*1e3:0;continue}if(s==="")continue;let i=s.split(" "),o=i[0];if(!o)continue;let a=o.startsWith("R")||o.startsWith("C")?i[2]:i[1];a&&e(a,n,r)}}function ns(t){let e=new Map;try{let n=Zr("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${qr}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:es});ts(n,(r,s,i)=>{let o=e.get(r);if(o){o.commitCount90d+=1;return}e.set(r,{commitCount90d:1,lastAuthor:s||void 0,lastCommitAt:i||void 0})})}catch{return e}try{let n=Zr("git",["-C",t,"log","--name-status","-M",`--format=${qr}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:es});ts(n,(r,s,i)=>{e.has(r)||e.set(r,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:i||void 0})})}catch{}return e}import mt from"fs";import Ba from"path";import{load as rs}from"js-yaml";var Me=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function ss(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function Ka(t){return t.replace(/:$/,"").split(",").map(e=>{let n=e.trim();return n.startsWith('"')&&(n=n.slice(1)),n.endsWith('"')&&(n=n.slice(0,-1)),ss(n)}).filter(Boolean)}function Ua(t,e){let n=t.startsWith("/")?t.slice(1):t,r=n.lastIndexOf("@");return r>0?{name:n.substring(0,r),version:e||n.substring(r+1)}:{name:n,version:e}}function Ha(t){try{let e=rs(t),n={dependencies:{}};for(let[r,s]of Object.entries(e))if(!(r==="__metadata"||!s?.version))for(let i of r.split(", ")){let o=ss(i);o&&(n.dependencies[o]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return n}catch{return null}}function Ja(t){let e={dependencies:{}};for(let n of t.split(/\n\n+/)){let r=n.split(`
4
+ `).filter(c=>c.trim().length>0&&!c.trim().startsWith("#"));if(r.length<2)continue;let s=r[0];if(!s||s.startsWith(" "))continue;let i=Ka(s);if(i.length===0)continue;let a=r.find(c=>c.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let c of i)e.dependencies[c]={version:a}}return e}function is(t){let e=mt.readFileSync(t,"utf-8"),n=JSON.parse(e),r={dependencies:{}};if(n.packages)for(let[s,i]of Object.entries(n.packages)){if(!s.startsWith("node_modules/"))continue;let o=s.replace("node_modules/","");o.includes("node_modules/")||(r.dependencies[o]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}else if(n.dependencies)for(let[s,i]of Object.entries(n.dependencies))r.dependencies[s]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}};return r}function os(t){let e=mt.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let n=Ha(e);if(n!==null)return n}return Ja(e)}function as(t){let e=mt.readFileSync(t,"utf-8"),n={dependencies:{}};try{let r=rs(e);if(r.packages)for(let[s,i]of Object.entries(r.packages)){let{name:o,version:a}=Ua(s,i.version);o&&(n.dependencies[o]={version:a,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}if(r.dependencies)for(let[s,i]of Object.entries(r.dependencies)){if(n.dependencies[s])continue;let o=typeof i=="string"?i:i.version;n.dependencies[s]={version:o||""}}}catch{}return n}var Va={"package-lock.json":is,"yarn.lock":os,"pnpm-lock.yaml":as};function wn(t){for(let e of Me){let n=Ba.join(t,e);if(mt.existsSync(n))return Va[e](n)}return null}import ht from"fs";import dt from"path";function cs(t){let e=t.trim();return e.length>=2&&(e[0]==='"'||e[0]==="'")&&e[e.length-1]===e[0]?e.slice(1,-1):e}function Qa(t){let e=t.trim();if(e.startsWith('"')||e.startsWith("'")){let a=cs(e).split(":");return a.length>=3&&a[0]&&a[2]?{group:a[0],version:a[2]}:null}if(!e.startsWith("{"))return null;let n=e.match(/module\s*=\s*["']([^"']+)["']/),r=e.match(/group\s*=\s*["']([^"']+)["']/),s=n?n[1].split(":")[0]:r?.[1];if(!s)return null;let i=e.match(/version\.ref\s*=\s*["']([^"']+)["']/)??e.match(/version\s*=\s*\{\s*ref\s*=\s*["']([^"']+)["']/),o=e.match(/version\s*=\s*["']([^"']+)["']/);return{group:s,...o?.[1]!==void 0&&{version:o[1]},...i?.[1]!==void 0&&{versionRef:i[1]}}}function Tn(t){let e=t.split(/\r?\n/).map(i=>i.replace(/#.*$/,"").trim()),n={},r="";for(let i of e){let o=i.match(/^\[([\w.-]+)\]$/);if(o){r=o[1];continue}if(r!=="versions"||!i)continue;let a=i.indexOf("=");if(a===-1)continue;let c=i.slice(0,a).trim(),l=cs(i.slice(a+1));c&&l&&(n[c]=l)}let s={};r="";for(let i of e){let o=i.match(/^\[([\w.-]+)\]$/);if(o){r=o[1];continue}if(r!=="libraries"||!i)continue;let a=i.indexOf("=");if(a===-1)continue;let c=Qa(i.slice(a+1));if(!c)continue;let l=c.versionRef?n[c.versionRef]:c.version;l&&(s[c.group]=l)}return s}function Fn(t){let e={};for(let n of t.split(/\r?\n/)){let r=n.trim();if(!r||r.startsWith("#")||r.startsWith("empty="))continue;let i=r.split("=")[0].split(":");i.length>=3&&i[0]&&i[2]&&(e[i[0]]=i[2])}return e}function Dn(t){let e={},n=/["']([\w.-]+):([\w.-]+):([\w.\-+]+)["']/g;for(let s=n.exec(t);s;s=n.exec(t)){let[,i,,o]=s;i&&o&&/\d/.test(o)&&(e[i]=o)}let r=/group:\s*["']([\w.-]+)["'][^\n)]*?version:\s*["']([\w.\-+]+)["']/g;for(let s=r.exec(t);s;s=r.exec(t))s[1]&&s[2]&&/\d/.test(s[2])&&(e[s[1]]=s[2]);return e}function gt(t){let e={},n=/["']([\w.-]+)["']\s*%%?\s*["']([\w.-]+)["']\s*%\s*["']([\w.\-+]+)["']/g;for(let r=n.exec(t);r;r=n.exec(t)){let[,s,,i]=r;s&&i&&(e[s]=i)}return e}var Ya=new Set(["node_modules","build",".gradle","target",".git","dist"]),Xa=2;function _e(t){try{return ht.existsSync(t)?ht.readFileSync(t,"utf-8"):null}catch{return null}}function Nn(t){let e={},n=p=>{for(let[u,m]of Object.entries(p))!e[u]&&m&&(e[u]=m)},r=_e(dt.join(t,"gradle","libs.versions.toml"));r&&n(Tn(r));let s=[],i=[],o=[],a=(p,u)=>{let m;try{m=ht.readdirSync(p,{withFileTypes:!0})}catch{return}for(let d of m){let y=dt.join(p,d.name);if(d.isDirectory()){u<Xa&&!d.name.startsWith(".")&&!Ya.has(d.name)&&a(y,u+1);continue}d.isFile()&&(d.name==="gradle.lockfile"?s.push(y):d.name==="build.gradle"||d.name==="build.gradle.kts"?i.push(y):d.name==="build.sbt"&&o.push(y))}};a(t,0);for(let p of s){let u=_e(p);u&&n(Fn(u))}for(let p of i){let u=_e(p);u&&n(Dn(u))}for(let p of o){let u=_e(p);u&&n(gt(u))}try{let p=dt.join(t,"project");for(let u of ht.readdirSync(p,{withFileTypes:!0}))if(u.isFile()&&u.name.endsWith(".scala")){let m=_e(dt.join(p,u.name));m&&n(gt(m))}}catch{}let c=Object.keys(e);if(c.length===0)return null;let l={};for(let p of c)l[p]={version:e[p]};return l}function ls(t){let e=wn(t),n=Nn(t);return n?{...e??{dependencies:{}},jvmDependencies:n}:e}import ps from"path";function M(t){switch(ps.extname(t).toLowerCase()){case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".ts":case".tsx":return"typescript";case".css":return"css";case".scss":case".sass":return"scss";case".less":return"less";case".styl":return"stylus";case".coffee":return"coffeescript";case".ls":return"livescript";case".lua":return"lua";case".py":return"python";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":case".sc":return"scala";case".groovy":case".gradle":return"groovy";case".cpp":case".cc":case".cxx":case".c":return"unknown";case".feature":return"gherkin";case".md":case".mdx":return"markdown";default:return"unknown"}}function P(t){let e=ps.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import Za from"coffeescript";function X(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function ye(t){let e=new Set,n=/@tag\s+([a-zA-Z0-9_-]+)/g,r=n.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=n.exec(t);return e}function xe(t,e){let n=t.toLowerCase();return n.includes(".test.")||n.includes(".spec.")||e.has("test")?"test":"logic"}function fs(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return X(t.value)}}function re(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function qa(t,e){let n=fs(e.source);return n?{fromPath:t,toPath:"",rawSpecifier:n,isStyle:P(n),type:"static"}:null}function ec(t,e){let n=e.variable?.base?.value==="require",r=fs(e.args?.[0]?.base);return!n||!r?null:{fromPath:t,toPath:"",rawSpecifier:r,isStyle:P(r),type:"require"}}function us(t,e){if(e)return[{name:e}];let n=t.value;if(n?.constructor?.name==="Class"){let s=re(n.variable);return s?[{name:s}]:[]}if(n?.base?.constructor?.name==="Obj"&&Array.isArray(n.base.properties))return n.base.properties.map(s=>re(s.variable)??re(s)).filter(s=>!!s).map(s=>({name:s}));let r=re(n);return r?[{name:r}]:[]}function tc(t){if(Array.isArray(t.specifiers))return t.specifiers.map(n=>n.identifier??n.original?.value).filter(n=>!!n).map(n=>({name:n}));let e=re(t.variable)??re(t.variable?.base);return e?[{name:e}]:[]}function nc(t,e,n,r){let s=e.constructor?.name;if(s==="ImportDeclaration"){let i=qa(t,e);i&&n.push(i)}else if(s==="Call"){let i=ec(t,e);i&&n.push(i)}else if(s==="Assign"){let i=re(e.variable?.base),o=e.variable?.properties?.[0]?.name?.value;i==="module"&&o==="exports"?r.push(...us(e,void 0)):i==="exports"&&typeof o=="string"&&r.push(...us(e,o))}else s==="ExportNamedDeclaration"&&e.clause?r.push(...tc(e.clause)):s==="ExportDefaultDeclaration"&&r.push({name:"default"})}function Rn(t,e,n,r){if(!(!e||typeof e!="object")){nc(t,e,n,r);for(let s in e){if(s==="locationData")continue;let i=e[s];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let o of i)Rn(t,o,n,r);else Rn(t,i,n,r)}}}function ms(t,e){let n=ye(e),r=xe(t,n),s=[],i=[];try{Rn(t,Za.nodes(e),s,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(n).map(c=>({name:c,kind:"comment-marker"})),category:r}}import{AstBuilder as rc,GherkinClassicTokenMatcher as sc,Parser as ic}from"@cucumber/gherkin";import{IdGenerator as oc}from"@cucumber/messages";var gs=new Map;function Se(t,e){gs.set(t,e)}function ds(t){return gs.get(t)}var ac=oc.uuid();function Pn(t,e){let n=new Set,r=s=>{for(let i of s)n.add(i.name.startsWith("@")?i.name.slice(1):i.name)};try{let s=new rc(ac),i=new sc,a=new ic(s,i).parse(e);if(a.feature){r(a.feature.tags);for(let c of a.feature.children){if(c.scenario){r(c.scenario.tags);for(let l of c.scenario.examples)r(l.tags)}if(c.rule)for(let l of c.rule.children)l.scenario&&r(l.scenario.tags)}}}catch(s){console.warn(`[GherkinParser] Failed to parse ${t}:`,s)}return{imports:[],exports:[],tags:Array.from(n).map(s=>({name:s,kind:"comment-marker"})),category:"test"}}Se("gherkin",Pn);import fc from"path";import{parser as mc}from"@lezer/go";function se(t){let e=[],n=t.firstChild;for(;n;)e.push(n),n=n.nextSibling;return e}function ie(t,e){let n=1;for(let r=0;r<e&&r<t.length;r++)t[r]===`
5
+ `&&n++;return n}function cc(t,e){let n=1;function r(s){switch(s.type.name){case"IfStatement":case"ForStatement":n++;break;case"Case":{s.firstChild?.type.name==="case"&&n++;break}case"LogicOp":{let o=e.slice(s.from,s.to);(o==="&&"||o==="||")&&n++;break}}let i=s.firstChild;for(;i;)r(i),i=i.nextSibling}return r(t),n}function ys(t,e,n,r){let s=n?1:1+e,i=se(t),o=n?e:e+1,a=i[1];a&&a.type.name!=="Block"&&(s+=be(a,o,!1,r));let c=i.find(p=>p.type.name==="Block");c&&(s+=be(c,o,!1,r));let l=i.findIndex(p=>p.type.name==="else");if(l>=0){let p=i[l+1];p?.type.name==="IfStatement"?s+=ys(p,e,!0,r):p&&(s+=1+be(p,e+1,!1,r))}return s}function hs(t,e,n){let r=1+e,s=t.firstChild;for(;s;)r+=be(s,e+1,!1,n),s=s.nextSibling;return r}function lc(t,e,n){let r=0,s=t.firstChild;for(;s;)r+=be(s,e,!1,n),s=s.nextSibling;return r}function pc(t,e){let n=e.slice(t.from,t.to);return n==="&&"||n==="||"}function be(t,e,n,r){let s=t.type.name;if(s==="IfStatement")return ys(t,e,n,r);if(s==="ForStatement"||s==="SwitchStatement"||s==="SelectStatement")return hs(t,e,r);let i=s==="LogicOp"&&pc(t,r)?1:0;return e>0&&s==="FunctionLiteral"?i+hs(t,e,r):i+lc(t,e,r)}function uc(t,e){return be(t,0,!1,e)}function yt(t,e){return{complexity:cc(t,e),cognitiveComplexity:uc(t,e)}}function Ln(t,e){let r=t.getChild("Parameters")?.getChild("Parameter"),s=r?.getChild("TypeName")??r?.getChild("PointerType")?.getChild("TypeName");return s?e.slice(s.from,s.to):void 0}function xs(t,e){let n=[],r=t.cursor();do if(r.name==="FunctionDecl"){let s=r.node.getChild("DefName");if(s){let i=e.slice(s.from,s.to),{complexity:o,cognitiveComplexity:a}=yt(r.node,e);n.push({name:i,line:ie(e,r.from),complexity:o,cognitiveComplexity:a})}}else if(r.name==="MethodDecl"){let s=r.node.getChild("FieldName");if(s){let i=e.slice(s.from,s.to),o=Ln(r.node,e),a=o?`${o}.${i}`:i,{complexity:c,cognitiveComplexity:l}=yt(r.node,e);n.push({name:a,line:ie(e,r.from),complexity:c,cognitiveComplexity:l})}}while(r.next());return n}var gc=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,dc=/^\/\/go:build\s+(.+)$/,hc=/^\/\/\s*\+build\s+(.+)$/;function bs(t,e){let n=[],r=new Map,s=new Set,i=new Set,o=new Map,a=mc.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let b=e.slice(c.from,c.to),v=b.match(gc);v?.[1]&&s.add(v[1]);let L=b.match(dc);L&&Ss(L[1],i);let A=b.match(hc);A&&Ss(A[1],i);break}case"ImportSpec":{let b=c.node.getChild("String");if(b){let L=e.slice(b.from,b.to).slice(1,-1);n.push({fromPath:t,toPath:"",rawSpecifier:L,isExternal:!0,isStyle:!1,type:"static"});let A=c.node.getChild("DefName"),_=A?e.slice(A.from,A.to):L.split("/").pop();_&&_!=="_"&&_!=="."&&o.set(_,L)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let b=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(b){let v=e.slice(b.from,b.to);v!=="_"&&/^[A-Z]/.test(v)&&!r.has(v)&&r.set(v,{name:v})}break}}while(c.next());let l=n.some(b=>b.rawSpecifier==="testing"),p=fc.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",u=new Set([...s,...i]),{complexity:m,cognitiveComplexity:d}=yt(a.topNode,e),y=xs(a,e),k=p==="test"?[]:yc(a,e,o);return{imports:n,exports:Array.from(r.values()),tags:Array.from(u).map(b=>({name:b,kind:"comment-marker"})),category:p,rawCallEdges:k,complexity:m,cognitiveComplexity:d,...y.length>0?{functions:y}:{}}}function yc(t,e,n){let r=[];function s(o,a){if(o.type.name==="CallExpr"){let l=o.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,u=l.getChild("FieldName");if(p?.type.name==="VariableName"&&u){let m=e.slice(p.from,p.to),d=n.get(m);if(d){let y=e.slice(u.from,u.to);r.push({from:a,to:y,toSpecifier:d})}}}}let c=o.firstChild;for(;c;)s(c,a),c=c.nextSibling}let i=t.cursor();do if(i.name==="FunctionDecl"){let o=i.node.getChild("DefName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to);/^[A-Z]/.test(c)&&s(a,c)}}else if(i.name==="MethodDecl"){let o=i.node.getChild("FieldName"),a=i.node.getChild("Block");if(o&&a){let c=e.slice(o.from,o.to),l=Ln(i.node,e);s(a,l?`${l}.${c}`:c)}}while(i.next());return r}function Ss(t,e){for(let n of t.split(/[\s,&|!()]+/)){let r=n.trim();r&&r!=="ignore"&&e.add(r)}}var xc=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/g,Sc=["org.junit","androidx.test","org.robolectric","org.mockito","org.scalatest","munit","spock.lang","io.kotest","org.spekframework","org.testng","org.assertj","com.google.truth","org.hamcrest","io.mockk","com.nhaarman.mockitokotlin2"],An=["test","androidTest","integrationTest","it"],bc=new RegExp(`/src/(${An.join("|")})/`),kc=/(?:Test|Tests|Spec|IT|ITCase)$/;function In(t){let e=t.replace(/\.\w+$/,"");return kc.test(e)}function ke(t){let e=new Set;for(let n of t.matchAll(xc))n[1]&&e.add(n[1]);return e}function Z(t){let e=t.replace(/\/\*[\s\S]*?\*\//g,n=>n.replace(/[^\n]/g," "));return e=e.replace(/\/\/[^\n]*/g,n=>" ".repeat(n.length)),e}function ve(t){let e=Z(t),n=new Set;for(let s of e.matchAll(/@([A-Z]\w*)/g))s[1]&&n.add(s[1]);let r=new Set;for(let s of e.matchAll(/\b(?:class|object|interface|trait|enum)\s+([A-Za-z_]\w*)/g))s[1]&&r.add(s[1]);return{annotations:[...n],typeNames:[...r]}}function xt(t){let e=t.split(".").pop();return e&&e!=="*"?e:void 0}function Ce(t,e,n=e){let r=xt(n);return{fromPath:t,toPath:"",rawSpecifier:e,isExternal:!0,isStyle:!1,type:"static",symbols:r?[r]:void 0}}function q(t,e){return{fromPath:t,toPath:"",rawSpecifier:`${e}.*`,isExternal:!0,isStyle:!1,type:"side-effect",isSamePackage:!0}}function j(t,e){let n=[];for(let r of Z(t).split(`
6
+ `)){let s=r.trim();if(!s||s.startsWith("@")||s.startsWith("*"))continue;let i=s.match(/^package\s+(?:object\s+)?([\w.]+)/);if(i?.[1]){if(n.push(i[1]),!e)break;continue}if(!(e&&/^import\s/.test(s)))break}return n.length>0?n.join("."):null}var vc=new Set(["Configuration","SpringBootApplication","EnableAutoConfiguration"]),Cc=new Set(["Composable","Preview"]),Ec=new Set(["RestController","Controller","Service","Repository","Component","Entity","MappedSuperclass","Embeddable"]),wc=["Activity","Fragment","ViewModel","Screen","Composable"];function B(t,e,n={}){let r=t.replace(/\\/g,"/"),s=r.split("/").pop()??"";if(s.endsWith(".gradle")||s==="build.gradle.kts"||s==="settings.gradle.kts")return"config";if(bc.test(r)||e.some(o=>Sc.some(a=>o===a||o.startsWith(`${a}.`))))return"test";let i=n.annotations??[];return i.some(o=>vc.has(o))?"config":i.some(o=>Cc.has(o))||(n.typeNames??[]).some(o=>wc.some(a=>o.endsWith(a)))?"ui":i.some(o=>Ec.has(o))?"logic":In(s)?"test":"logic"}var Tc=/^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,Fc=/^(?:@\w+\s+)*(?:public\s+|private\s+|protected\s+|final\s+|abstract\s+|static\s+)*(class|interface|trait|enum|def)\s+([A-Za-z_][A-Za-z0-9_]*)/;function Dc(t,e){return t?e.endsWith(".*")?e.slice(0,-2)||null:e.split(".").slice(0,-1).join(".")||null:e||null}function ks(t,e){let n=ke(e),s=Z(e).split(`
7
+ `),i=[],o=new Set;for(let l of s){let p=l.match(Tc);if(p?.[2]){let m=Dc(!!p[1],p[2]);m&&i.push(Ce(t,m,p[2]));continue}let u=l.match(Fc);u?.[2]&&o.add(u[2])}let a=j(e,!1);a&&i.push(q(t,a));let c=Array.from(o,l=>({name:l}));return{imports:i,exports:c,tags:Array.from(n).map(l=>({name:l,kind:"comment-marker"})),category:B(t,i.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:ve(e).annotations})}}import{parser as Ic}from"@lezer/java";var vs=new Set(["ForStatement","EnhancedForStatement","WhileStatement","DoStatement"]),Nc=new Set(["ClassDeclaration","InterfaceDeclaration","EnumDeclaration","RecordDeclaration","AnnotationTypeDeclaration"]);function Rc(t,e){let n=1;function r(s){let i=s.type.name;if(i==="IfStatement"||i==="CatchClause"||i==="TernaryExpression")n++;else if(vs.has(i))n++;else if(i==="SwitchLabel")s.firstChild?.type.name==="case"&&n++;else if(i==="LogicOp"){let a=e.slice(s.from,s.to);(a==="&&"||a==="||")&&n++}let o=s.firstChild;for(;o;)r(o),o=o.nextSibling}return r(t),n}function Cs(t,e,n,r){let s=n?1:1+e,i=[];for(let p=t.firstChild;p;p=p.nextSibling)i.push(p);let o=n?e:e+1,a=i[1];a&&a.type.name!=="Block"&&(s+=Ee(a,o,!1,r));let c=i.find(p=>p.type.name==="Block");c&&(s+=Ee(c,o,!1,r));let l=i.findIndex(p=>p.type.name==="else");if(l>=0){let p=i[l+1];p?.type.name==="IfStatement"?s+=Cs(p,e,!0,r):p&&(s+=1+Ee(p,e+1,!1,r))}return s}function Mn(t,e,n){let r=1+e,s=t.firstChild;for(;s;)r+=Ee(s,e+1,!1,n),s=s.nextSibling;return r}function Pc(t,e,n){let r=0,s=t.firstChild;for(;s;)r+=Ee(s,e,!1,n),s=s.nextSibling;return r}function Lc(t,e){let n=e.slice(t.from,t.to);return n==="&&"||n==="||"}function Ee(t,e,n,r){let s=t.type.name;if(s==="IfStatement")return Cs(t,e,n,r);if(vs.has(s)||s==="SwitchStatement"||s==="CatchClause"||s==="TernaryExpression")return Mn(t,e,r);let i=s==="LogicOp"&&Lc(t,r)?1:0;return e>0&&s==="LambdaExpression"?i+Mn(t,e,r):i+Pc(t,e,r)}function Ac(t,e){return Ee(t,0,!1,e)}function _n(t,e){return{complexity:Rc(t,e),cognitiveComplexity:Ac(t,e)}}function Gn(t,e){for(let n=t.parent;n;n=n.parent)if(Nc.has(n.type.name)){let r=n.getChild("Definition");if(r)return e.slice(r.from,r.to)}}function Es(t,e){let n=[],r=t.cursor();do if(r.name==="MethodDeclaration"||r.name==="ConstructorDeclaration"){let s=r.node.getChild("Definition");if(s){let i=e.slice(s.from,s.to),o=Gn(r.node,e),a=o&&r.name==="MethodDeclaration"?`${o}.${i}`:i,{complexity:c,cognitiveComplexity:l}=_n(r.node,e);n.push({name:a,line:ie(e,r.from),complexity:c,cognitiveComplexity:l})}}while(r.next());return n}var Mc=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/;function _c(t,e){let n=t.getChild("ScopedIdentifier");if(!n)return null;let r=t.getChild("static")!=null,s=t.getChild("Asterisk")!=null,i=e.slice(n.from,n.to);if(r){if(s)return i?{specifier:i,wildcard:!1}:null;let o=i.split(".").slice(0,-1).join(".");return o?{specifier:o,wildcard:!1,symbol:xt(i)}:null}return s?{specifier:`${i}.*`,wildcard:!0}:{specifier:i,wildcard:!1,symbol:xt(i)}}function Gc(t){let e=new Map;for(let n of t){if(n.type==="side-effect")continue;let r=n.rawSpecifier;if(r.endsWith(".*"))continue;let s=r.split(".").pop();s&&e.set(s,r)}return e}function Oc(t,e){let n=t;if(n.name==="GenericType"&&(n=n.firstChild),!n)return null;if(n.name==="TypeName")return e.slice(n.from,n.to);if(n.name==="ScopedTypeName"){let r=null;for(let s=n.firstChild;s;s=s.nextSibling)s.name==="TypeName"&&(r=s);return r?e.slice(r.from,r.to):null}return null}function jc(t,e,n){let r=[];function s(o,a){let c=o.type.name;if(c==="MethodInvocation"){let p=o.firstChild;if(p?.type.name==="Identifier"){let u=n.get(e.slice(p.from,p.to)),m=o.getChild("MethodName");u&&m&&r.push({from:a,to:e.slice(m.from,m.to),toSpecifier:u})}}else if(c==="ObjectCreationExpression"){let p=o.getChild("TypeName")??o.getChild("GenericType")??o.getChild("ScopedTypeName"),u=p&&Oc(p,e);if(u){let m=n.get(u);m&&r.push({from:a,to:"new",toSpecifier:m})}}let l=o.firstChild;for(;l;)s(l,a),l=l.nextSibling}let i=t.cursor();do if(i.name==="MethodDeclaration"||i.name==="ConstructorDeclaration"){let o=i.node.getChild("Definition"),a=i.node.getChild("Block")??i.node.getChild("ConstructorBody");if(o&&a){let c=e.slice(o.from,o.to),l=Gn(i.node,e),p=l&&i.name==="MethodDeclaration"?`${l}.${c}`:c;s(a,p)}}while(i.next());return r}function ws(t,e){let n=[],r=new Map,s=new Set,i=new Set,o;try{o=Ic.parse(e)}catch{return{imports:[],exports:[],tags:[],category:B(t,[])}}let a=o.cursor();do switch(a.name){case"LineComment":{let y=e.slice(a.from,a.to).match(Mc);y?.[1]&&s.add(y[1]);break}case"MarkerAnnotation":case"Annotation":{let y=a.node.getChild("Identifier");y&&i.add(e.slice(y.from,y.to));break}case"ImportDeclaration":{let y=_c(a.node,e);y&&n.push({fromPath:t,toPath:"",rawSpecifier:y.specifier,isExternal:!0,isStyle:!1,type:"static",symbols:y.symbol?[y.symbol]:void 0});break}case"ClassDeclaration":case"InterfaceDeclaration":case"EnumDeclaration":case"AnnotationTypeDeclaration":{if(a.node.parent?.name==="Program"){let y=a.node.getChild("Definition");if(y){let k=e.slice(y.from,y.to);r.has(k)||r.set(k,{name:k})}}break}}while(a.next());let c=j(e,!1);c&&n.push(q(t,c));let l=B(t,n.map(y=>y.rawSpecifier),{typeNames:[...r.keys()],annotations:[...i]}),{complexity:p,cognitiveComplexity:u}=_n(o.topNode,e),m=Es(o,e),d=l==="test"?[]:jc(o,e,Gc(n));return{imports:n,exports:Array.from(r.values()),tags:Array.from(s).map(y=>({name:y,kind:"comment-marker"})),category:l,rawCallEdges:d,complexity:p,cognitiveComplexity:u,...m.length>0?{functions:m}:{}}}var $c=/^\s*import\s+([\w.]+(?:\.\*)?)(?:\s+as\s+\w+)?\s*$/,On="(?:public\\s+|internal\\s+|private\\s+|protected\\s+|open\\s+|abstract\\s+|final\\s+|sealed\\s+|data\\s+|value\\s+|inline\\s+|noinline\\s+|crossinline\\s+|external\\s+|expect\\s+|actual\\s+|suspend\\s+|operator\\s+|infix\\s+|tailrec\\s+|const\\s+|lateinit\\s+)*",Wc=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${On}(?:(?:enum|annotation)\\s+)?(class|interface|object|typealias)\\s+([A-Za-z_][A-Za-z0-9_]*)`),zc=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${On}fun\\s+(?:<[^>]*>\\s*)?(?:[A-Za-z_][\\w.]*(?:<[^>]*>)?\\.)?([A-Za-z_][A-Za-z0-9_]*)\\s*[(<]`),Bc=new RegExp(`^(?:@[\\w.]+(?:\\([^)]*\\))?\\s+)*${On}(?:val|var)\\s+(?:<[^>]*>\\s*)?([A-Za-z_][A-Za-z0-9_]*)`);function Ts(t,e){let n=ke(e),s=Z(e).split(`
8
+ `),i=[],o=new Set;for(let l of s){let p=l.match($c);if(p?.[1]){i.push(Ce(t,p[1]));continue}let u=l.match(Wc);if(u?.[2]){o.add(u[2]);continue}let m=l.match(zc);if(m?.[1]){o.add(m[1]);continue}let d=l.match(Bc);d?.[1]&&o.add(d[1])}let a=j(e,!1);a&&i.push(q(t,a));let c=Array.from(o,l=>({name:l}));return{imports:i,exports:c,tags:Array.from(n).map(l=>({name:l,kind:"comment-marker"})),category:B(t,i.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:ve(e).annotations})}}import Kc from"livescript";function oe(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function Uc(t){if(!t)return[];if(t.constructor?.name==="Class"){let n=oe(t.title);return n?[{name:n}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(n=>oe(n.key)??oe(n.val)).filter(n=>!!n).map(n=>({name:n}));let e=oe(t);return e?[{name:e}]:[]}function Hc(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let n=t.left,r=oe(n.head),i=n.tails?.[0]?.key?.name;if(r==="module"&&i==="exports")return Uc(t.right);if(r==="exports"&&typeof i=="string")return[{name:i}];if(n.head?.verb==="out"&&typeof i=="string")return[{name:i}]}if(e==="Import"&&t.left?.verb==="out"){let n=t.right;if(n?.constructor?.name==="Obj"&&Array.isArray(n.items))return n.items.map(r=>oe(r.val)??oe(r.key)).filter(r=>!!r).map(r=>({name:r}))}return[]}var Jc=new Set(["first_line","first_column","last_line","last_column","line","column"]);function Vc(t,e){let n=t.constructor?.name||t.type;if(n==="Import"){let r=t.right?.value;if(typeof r=="string"){let s=X(r);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:P(s),type:"static"}}}if(n==="Chain"&&t.head?.value==="require"){let r=t.tails?.[0];if(r?.constructor?.name==="Call"||r?.type==="Call"){let s=r.args?.[0]?.value;if(typeof s=="string"){let i=X(s);return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:P(i),type:"require"}}}}return null}function jn(t,e,n){if(!t||typeof t!="object")return[];let r=[],s=Vc(t,e);s&&r.push(s),n.push(...Hc(t));for(let i in t){if(Jc.has(i))continue;let o=t[i];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)r.push(...jn(a,e,n));else r.push(...jn(o,e,n))}return r}function Fs(t,e){let n=ye(e),r=xe(t,n),s=[],i=[];try{s=jn(Kc.ast(e),t,i)}catch{}let o=new Set,a=i.filter(c=>o.has(c.name)?!1:(o.add(c.name),!0));return{imports:s,exports:a,tags:Array.from(n).map(c=>({name:c,kind:"comment-marker"})),category:r}}import Qc from"luaparse";function Yc(t,e){let n=[];function r(s){if(!(!s||typeof s!="object")){if((s.type==="CallExpression"||s.type==="StringCallExpression")&&s.base?.type==="Identifier"&&s.base?.name==="require"){let i;if(s.type==="CallExpression"){let o=s.arguments?.[0];o?.type==="StringLiteral"&&(i=X(o.raw))}else if(s.type==="StringCallExpression"){let o=s.argument;o?.type==="StringLiteral"&&(i=X(o.raw))}i&&n.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:P(i),type:"require"})}for(let i in s){if(i==="loc")continue;let o=s[i];if(o&&typeof o=="object")if(Array.isArray(o))for(let a of o)r(a);else r(o)}}}return r(t),n}function Xc(t){let e=new Set;for(let n of t)n.type==="LocalStatement"&&n.variables.forEach((r,s)=>{n.init[s]?.type==="TableConstructorExpression"&&e.add(r.name)});return e}function Zc(t){let e=t[t.length-1];if(e?.type!=="ReturnStatement")return[];let n=e.arguments[0];if(n?.type!=="TableConstructorExpression")return[];let r=[];for(let s of n.fields)s.type==="TableKeyString"&&r.push({name:s.key.name});return r}function qc(t){let e=t.body,n=Xc(e),r=Zc(e);for(let i of e)if(i.type==="FunctionDeclaration")i.identifier?.type==="MemberExpression"?i.identifier.base.type==="Identifier"&&n.has(i.identifier.base.name)&&r.push({name:i.identifier.identifier.name}):i.identifier?.type==="Identifier"&&!i.isLocal&&r.push({name:i.identifier.name});else if(i.type==="AssignmentStatement")for(let o of i.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&n.has(o.base.name)&&r.push({name:o.identifier.name});let s=new Set;return r.filter(i=>s.has(i.name)?!1:(s.add(i.name),!0))}function Ds(t,e){let n=ye(e),r=xe(t,n),s=[],i=[];try{let o=Qc.parse(e);s=Yc(o,t),i=qc(o)}catch{}return{imports:s,exports:i,tags:Array.from(n).map(o=>({name:o,kind:"comment-marker"})),category:r}}var el=["http://","https://","mailto:","//"],tl="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",nl=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${tl})\\b`,"g"),Ns;async function rl(){return Ns??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),Ns}function sl(t){let e=t.trim();return e.length===0||e.startsWith("#")||el.some(n=>e.startsWith(n))}function il(t,e){let n=t.match(nl);return n?n.map(r=>({fromPath:e,toPath:"",rawSpecifier:r,isStyle:!1,type:"static",isDocReference:!0})):[]}function Rs(t,e,n){if(t.type==="link"&&typeof t.url=="string"&&!sl(t.url)&&n.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static",isDocReference:!0}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&n.push(...il(t.value,e)),Array.isArray(t.children))for(let r of t.children)Rs(r,e,n)}async function Ps(t,e){let r=(await rl()).parse(e),s=[];Rs(r,t,s);let i=new Set;return{imports:s.filter(a=>i.has(a.rawSpecifier)?!1:(i.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import ul from"path";import{parser as fl}from"@lezer/python";function ol(t){let e=1;function n(r){switch(r.type.name){case"IfStatement":{e+=se(r).filter(i=>i.type.name==="if"||i.type.name==="elif").length;break}case"TryStatement":{e+=se(r).filter(i=>i.type.name==="except").length;break}case"ForStatement":case"WhileStatement":case"ConditionalExpression":e++;break;case"and":case"or":e++;break}let s=r.firstChild;for(;s;)n(s),s=s.nextSibling}return n(t),e}function al(t,e){let n=0,r=se(t),s=0,i=0;for(;i<r.length;){let o=r[i];if(o?.type.name==="if"||o?.type.name==="elif"){let a=s>0;n+=a?1:1+e;let c=a?e:e+1,l=r[i+1],p=r[i+2];l&&(n+=K(l,c)),p&&(n+=K(p,c)),s++,i+=3}else if(o?.type.name==="else"){n+=1;let a=r[i+1];a&&(n+=K(a,e+1)),i+=2}else i++}return n}function cl(t,e){let n=0,r=se(t),s=0;for(;s<r.length;){let i=r[s];if(i?.type.name==="except"){for(n+=1+e,s++;s<r.length&&r[s]?.type.name!=="Body";)n+=K(r[s],e),s++;s<r.length&&(n+=K(r[s],e),s++)}else i?.type.name==="Body"&&(n+=K(i,e)),s++}return n}function Ls(t,e){let n=1+e,r=t.firstChild;for(;r;)n+=K(r,e+1),r=r.nextSibling;return n}function ll(t,e){let n=0,r=t.firstChild;for(;r;)n+=K(r,e),r=r.nextSibling;return n}function K(t,e){let n=t.type.name;switch(n){case"IfStatement":return al(t,e);case"TryStatement":return cl(t,e);case"ForStatement":case"WhileStatement":return Ls(t,e);default:{let r=n==="ConditionalExpression"||n==="and"||n==="or"?1:0;return e>0&&(n==="FunctionDefinition"||n==="LambdaExpression")?r+Ls(t,e):r+ll(t,e)}}}function pl(t){return K(t,0)}function $n(t){return{complexity:ol(t),cognitiveComplexity:pl(t)}}function As(t,e){let n=[];function r(o,a){let{complexity:c,cognitiveComplexity:l}=$n(o);n.push({name:a,line:ie(e,o.from),complexity:c,cognitiveComplexity:l})}function s(o){let a=o.firstChild;for(;a;)i(a),a=a.nextSibling}function i(o){if(o.type.name==="ClassDefinition"){let a=o.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=o.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let u=p.getChild("VariableName"),m=u?e.slice(u.from,u.to):void 0;m&&r(p,c?`${c}.${m}`:m),s(p)}else i(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&r(o,e.slice(a.from,a.to)),s(o);return}s(o)}return i(t.topNode),n}var ml=new Set(["pytest","unittest","nose","hypothesis"]);function Is(t,e){let n=[],r=[],s=new Set,i=ul.basename(t).toLowerCase(),o=fl.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let d=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);d?.[1]&&s.add(d[1]);break}case"ImportStatement":{for(let d of gl(a.node,e,t))n.push(d);break}case"FunctionDefinition":case"ClassDefinition":{let d=a.node.parent;if(d?.name==="Script"||d?.name==="DecoratedStatement"&&d.parent?.name==="Script"){let k=a.node.getChild("VariableName");k&&r.push({name:e.slice(k.from,k.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let d=a.node.firstChild;d?.name==="VariableName"&&r.push({name:e.slice(d.from,d.to)})}break}}while(a.next());let c=bl(i,n,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=$n(o.topNode),u=As(o,e),m=c==="test"?[]:Sl(o,e);return{imports:n,exports:r,tags:Array.from(s).map(d=>({name:d,kind:"comment-marker"})),category:c,rawCallEdges:m,complexity:l,cognitiveComplexity:p,...u.length>0?{functions:u}:{}}}function gl(t,e,n){let r=t.firstChild;return r?r.name==="from"?dl(t,e,n):hl(t,e,n):[]}function dl(t,e,n){let r=t.firstChild;if(!r)return[];let s=r.nextSibling;for(;s&&s.name!=="import";)s=s.nextSibling;if(!s)return[];let i=e.slice(r.to,s.from).trim(),o=yl(s.nextSibling,e);if(!o.length)return[];let a=0;for(;a<i.length&&i[a]===".";)a++;let c=i.slice(a);if(a===0)return[Ge(n,i,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[Ge(n,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[Ge(n,l.slice(0,-1),["*"],!1)]:o.map(p=>Ge(n,l+p,[p],!1))}function hl(t,e,n){let r=[],s=t.firstChild?.nextSibling??null;for(;s;){if(s.name==="VariableName"){let i=e.slice(s.from,s.to);for(;s.nextSibling?.name==="."&&s.nextSibling.nextSibling?.name==="VariableName";)s=s.nextSibling.nextSibling,i+=`.${e.slice(s.from,s.to)}`;s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling),r.push(Ge(n,i,["*"],!0))}s=s.nextSibling}return r}function yl(t,e){let n=[],r=t;for(;r;)r.name==="*"?n.push("*"):r.name==="VariableName"&&(n.push(e.slice(r.from,r.to)),r.nextSibling?.name==="as"&&(r=r.nextSibling.nextSibling??r.nextSibling)),r=r.nextSibling;return n}function xl(t,e){let n=new Map,r=t.cursor();do{if(r.name!=="ImportStatement")continue;let i=r.node.firstChild;if(i?.type.name!=="from")continue;let o=i.nextSibling;for(;o&&o.type.name!=="import";)o=o.nextSibling;if(!o)continue;let a=e.slice(i.to,o.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),u=o.nextSibling;for(;u;){if(u.type.name==="VariableName"){let m=e.slice(u.from,u.to),d=m;if(u.nextSibling?.type.name==="as"){let k=u.nextSibling.nextSibling;k?.type.name==="VariableName"&&(d=e.slice(k.from,k.to),u=k)}let y=c===0?a:l?p+l.replace(/\./g,"/"):p+m;n.set(d,y)}u=u.nextSibling}}while(r.next());return n}function Sl(t,e){let n=xl(t,e),r=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,u=e.slice(p.from,p.to),m=n.get(u);m&&r.push({from:c,to:u,toSpecifier:m})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function i(a){let c=a.firstChild;for(;c;)o(c),c=c.nextSibling}function o(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let u=p.firstChild;for(;u;){if(u.type.name==="FunctionDefinition"){let m=u.getChild("VariableName"),d=m?e.slice(m.from,m.to):void 0;d&&s(u,l?`${l}.${d}`:d)}else o(u);u=u.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&s(a,e.slice(c.from,c.to));return}i(a)}return o(t.topNode),r}function Ge(t,e,n,r){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:r,type:"static",symbols:n.length>0?n:void 0}}function bl(t,e,n){return t.startsWith("test_")||t.endsWith("_test.py")?"test":t==="conftest.py"||t==="setup.py"?"config":n.has("test")||e.some(r=>ml.has(r.rawSpecifier))?"test":"logic"}var kl=/^\s*import\s+(.+?)\s*$/,vl=/^(?:@\w+\s+)*(?:private\s+|protected\s+|final\s+|sealed\s+|abstract\s+|implicit\s+|case\s+)*(class|trait|object|type|enum)\s+([A-Za-z_$][A-Za-z0-9_$]*)/;function Cl(t,e){let n=e.split("=>")[0]?.trim();return n?n==="_"||n==="*"||n==="given"?`${t}.*`:`${t}.${n}`:null}function El(t){let e=t.indexOf("{");if(e!==-1){let r=t.indexOf("}",e),s=t.slice(0,e).trim().replace(/\.$/,""),i=t.slice(e+1,r===-1?void 0:r);return s?i.split(",").map(o=>Cl(s,o.trim())).filter(o=>o!=null):[]}let n=[];for(let r of t.split(",")){let s=r.trim().replace(/\s+as\s+\w+$/,"");if(s)if(s.endsWith("._")||s.endsWith(".*")||s.endsWith(".given")){let i=s.replace(/\.(_|\*|given)$/,"");i&&n.push(`${i}.*`)}else n.push(s)}return n}function Ms(t,e){let n=ke(e),s=Z(e).split(`
9
+ `),i=[],o=new Set;for(let l of s){let p=l.match(kl);if(p?.[1]){for(let m of El(p[1]))i.push(Ce(t,m));continue}let u=l.match(vl);u?.[2]&&o.add(u[2])}let a=j(e,!0);a&&i.push(q(t,a));let c=Array.from(o,l=>({name:l}));return{imports:i,exports:c,tags:Array.from(n).map(l=>({name:l,kind:"comment-marker"})),category:B(t,i.map(l=>l.rawSpecifier),{typeNames:[...o],annotations:ve(e).annotations})}}import js from"path";import h from"typescript";import S from"typescript";function wl(t){let e=1;function n(r){switch(r.kind){case S.SyntaxKind.IfStatement:case S.SyntaxKind.ConditionalExpression:case S.SyntaxKind.ForStatement:case S.SyntaxKind.ForInStatement:case S.SyntaxKind.ForOfStatement:case S.SyntaxKind.WhileStatement:case S.SyntaxKind.DoStatement:case S.SyntaxKind.CatchClause:case S.SyntaxKind.CaseClause:e++;break;case S.SyntaxKind.BinaryExpression:{let s=r.operatorToken.kind;(s===S.SyntaxKind.AmpersandAmpersandToken||s===S.SyntaxKind.BarBarToken||s===S.SyntaxKind.QuestionQuestionToken)&&e++;break}}S.forEachChild(r,n)}return n(t),e}function Gs(t,e,n){let r=n?1:1+e,s=n?e:e+1;return r+=ae(t.expression,s,!1),r+=ae(t.thenStatement,s,!1),t.elseStatement&&(S.isIfStatement(t.elseStatement)?r+=Gs(t.elseStatement,e,!0):r+=1+ae(t.elseStatement,e+1,!1)),r}function _s(t,e){let n=1+e;return S.forEachChild(t,r=>{n+=ae(r,e+1,!1)}),n}function Tl(t,e){let n=1+e;return S.forEachChild(t,r=>{n+=ae(r,e,!1)}),n}function Fl(t,e){let n=0;return S.forEachChild(t,r=>{n+=ae(r,e,!1)}),n}function Dl(t){let e=t.operatorToken.kind;return e===S.SyntaxKind.AmpersandAmpersandToken||e===S.SyntaxKind.BarBarToken||e===S.SyntaxKind.QuestionQuestionToken}function ae(t,e,n){if(S.isIfStatement(t))return Gs(t,e,n);if(S.isForStatement(t)||S.isForInStatement(t)||S.isForOfStatement(t)||S.isWhileStatement(t)||S.isDoStatement(t)||S.isSwitchStatement(t))return _s(t,e);if(S.isCatchClause(t))return Tl(t,e);let r=0;return S.isConditionalExpression(t)&&(r+=1),S.isBinaryExpression(t)&&Dl(t)&&(r+=1),e>0&&(S.isFunctionDeclaration(t)||S.isFunctionExpression(t)||S.isArrowFunction(t))?r+_s(t,e):r+Fl(t,e)}function Nl(t){return ae(t,0,!1)}function Wn(t){return{complexity:wl(t),cognitiveComplexity:Nl(t)}}import C from"typescript";var zn=new Set(["test","describe","it"]);function Os(t,e){Rl(t,e),Ll(t,e),Al(t,e)}function Rl(t,e){if((C.isFunctionDeclaration(t)||C.isVariableDeclaration(t))&&t.name&&C.isIdentifier(t.name)&&Pl(t)){let n;if(C.isFunctionDeclaration(t))n="function";else{let r=t.initializer;n=r&&(C.isArrowFunction(r)||C.isFunctionExpression(r))?"function":"variable"}e.tags.add({name:t.name.text,kind:n})}}function Pl(t){if(C.isFunctionDeclaration(t))return C.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&C.isSourceFile(e.parent)}function Ll(t,e){if(!C.isSourceFile(t))return;let n=/@tag\s+([a-zA-Z0-9_-]+)/g,r=t.getFullText(),s=n.exec(r);for(;s!==null;)s[1]&&e.tags.add({name:s[1],kind:"comment-marker"}),s=n.exec(r)}function Al(t,e){if(!C.isCallExpression(t)||!Il(t.expression))return;let[n]=t.arguments;if(n&&C.isStringLiteral(n))for(let r of n.text.match(/@[\w-]+/g)??[])e.tags.add({name:r.substring(1),kind:"comment-marker"});for(let r of t.arguments)C.isObjectLiteralExpression(r)&&Ml(r,e)}function Il(t){return C.isIdentifier(t)?zn.has(t.text):!!(C.isPropertyAccessExpression(t)&&(zn.has(t.name.text)||C.isIdentifier(t.expression)&&zn.has(t.expression.text)))}function Ml(t,e){for(let n of t.properties){if(!C.isPropertyAssignment(n)||!C.isIdentifier(n.name)||n.name.text!=="tags"&&n.name.text!=="tag")continue;let{initializer:r}=n,s=C.isArrayLiteralExpression(r)?r.elements.filter(C.isStringLiteral):n.name.text==="tag"&&C.isStringLiteral(r)?[r]:[];for(let i of s)e.tags.add({name:i.text.replace(/^@/,""),kind:"comment-marker"})}}function Bn(t,e,n){let r=[],s=new Map,i=new Set,o=h.createSourceFile(t,e,h.ScriptTarget.Latest,!0,n==="typescript"?h.ScriptKind.TSX:h.ScriptKind.JSX),a={filePath:t,imports:r,exports:s,tags:i,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=k=>{jl(k,a),h.forEachChild(k,c)};c(o);let l=Yl(t,a);(l==="test"||l==="barrel")&&i.add({name:l,kind:"comment-marker"}),l!=="test"&&Xl(a,o);let p=o.statements[0],u=p?Ws(p):void 0,{complexity:m,cognitiveComplexity:d}=Wn(o),y=_l(o);return{imports:r,exports:Array.from(s.values()),tags:Array.from(i),category:l,rawCallEdges:a.rawCallEdges??[],complexity:m,cognitiveComplexity:d,...y.length>0?{functions:y}:{},...u!==void 0?{description:u}:{}}}function _l(t){let e=[],n=(s,i)=>{let{complexity:o,cognitiveComplexity:a}=Wn(i),c=t.getLineAndCharacterOfPosition(i.getStart(t)).line+1;e.push({name:s,line:c,complexity:o,cognitiveComplexity:a})},r=(s,i)=>{if(h.isFunctionDeclaration(s)&&s.name&&s.body?n(s.name.text,s):h.isVariableDeclaration(s)&&h.isIdentifier(s.name)&&s.initializer&&(h.isArrowFunction(s.initializer)||h.isFunctionExpression(s.initializer))?n(s.name.text,s.initializer):i&&h.isMethodDeclaration(s)&&h.isIdentifier(s.name)&&s.body?n(`${i}.${s.name.text}`,s):i&&h.isConstructorDeclaration(s)&&s.body?n(`${i}.constructor`,s):i&&h.isGetAccessorDeclaration(s)&&h.isIdentifier(s.name)&&s.body?n(`${i}.get ${s.name.text}`,s):i&&h.isSetAccessorDeclaration(s)&&h.isIdentifier(s.name)&&s.body&&n(`${i}.set ${s.name.text}`,s),h.isClassDeclaration(s)&&s.name){let o=s.name.text;h.forEachChild(s,a=>r(a,o));return}h.forEachChild(s,o=>r(o,i))};return r(t,void 0),e}function $s(t,e,n,r){let s={name:t},i=Ws(n);i!==void 0&&(s.doc=i);let o=Gl(e);o!==void 0&&(s.flags=o);let a=Ol(e,r);return a!==void 0&&(s.signature=a),s}function Ws(t){let e=h.getJSDocCommentsAndTags(t);for(let n of e)if(h.isJSDoc(n)&&n.comment)return h.getTextOfJSDocComment(n.comment)||void 0}function Gl(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),n=h.getJSDocTags(t).map(r=>r.tagName.text).filter(r=>e.has(r));return n.length>0?n:void 0}function Ol(t,e){let n=h.createPrinter({removeComments:!0}),r=s=>n.printNode(h.EmitHint.Unspecified,s,e);if(h.isFunctionDeclaration(t)||h.isMethodDeclaration(t)){let s=t.parameters.map(r).join(", "),i=t.type?r(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${s}) => ${i}`}if(h.isVariableDeclaration(t)){if(t.type)return r(t.type);if(t.initializer&&(h.isArrowFunction(t.initializer)||h.isFunctionExpression(t.initializer))){let s=t.initializer,i=s.parameters.map(r).join(", "),o=s.type?r(s.type):"unknown";return`(${i}) => ${o}`}return}if(h.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(h.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(h.isTypeAliasDeclaration(t))return r(t.type);if(h.isEnumDeclaration(t))return`enum ${t.name.text}`}function jl(t,e){$l(t,e),Wl(t,e),Bl(t,e),Kl(t,e),Ql(t,e),Os(t,e)}function $l(t,e){if(!h.isSourceFile(t))return;let n=t.statements.filter(r=>!h.isEmptyStatement(r));e.totalStatements=n.length,e.exportStatements=n.filter(r=>h.isExportDeclaration(r)||h.isExportAssignment(r)||Kn(r)).length}function Wl(t,e){if(h.isJsxElement(t)||h.isJsxSelfClosingElement(t)||h.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(h.isFunctionDeclaration(t)||h.isMethodDeclaration(t)||h.isArrowFunction(t)||h.isClassDeclaration(t)||h.isVariableStatement(t)||h.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}h.isExportDeclaration(t)&&!zl(t)&&(e.hasTypesOnly=!1)}function zl(t){return t.isTypeOnly?!0:!t.exportClause||!h.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function Bl(t,e){if(!h.isImportDeclaration(t)||!t.moduleSpecifier||!h.isStringLiteral(t.moduleSpecifier))return;let n=[];if(t.importClause&&(t.importClause.name&&n.push("default"),t.importClause.namedBindings))if(h.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)n.push(s.name.text);else h.isNamespaceImport(t.importClause.namedBindings)&&n.push("*");let r=n.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.moduleSpecifier.text,isStyle:P(t.moduleSpecifier.text),type:r,symbols:n.length>0?n:void 0})}function Kl(t,e){h.isExportDeclaration(t)?Ul(t,e):h.isExportAssignment(t)?e.exports.set("default",{name:"default"}):Kn(t)&&Vl(t,e)}function Ul(t,e){if(t.moduleSpecifier&&h.isStringLiteral(t.moduleSpecifier))Hl(t,t.moduleSpecifier.text,e);else if(t.exportClause&&h.isNamedExports(t.exportClause))for(let n of t.exportClause.elements){let r=n.name.text;e.exports.set(r,{name:r})}}function Hl(t,e,n){let r=Jl(t),s={fromPath:n.filePath,toPath:"",rawSpecifier:e,isStyle:P(e),type:"re-export"};r.length>0&&(s.symbols=r),n.imports.push(s)}function Jl(t){return t.exportClause?h.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Vl(t,e){if((h.isFunctionDeclaration(t)||h.isClassDeclaration(t)||h.isInterfaceDeclaration(t)||h.isTypeAliasDeclaration(t)||h.isEnumDeclaration(t))&&t.name){let r=t.name.text;e.exports.set(r,$s(r,t,t,e.sourceFile));return}if(h.isVariableStatement(t)){for(let r of t.declarationList.declarations)if(h.isIdentifier(r.name)){let s=r.name.text;e.exports.set(s,$s(s,r,t,e.sourceFile))}}}function Ql(t,e){if(!h.isCallExpression(t))return;let n=t.arguments[0];!n||!h.isStringLiteral(n)||(t.expression.kind===h.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:n.text,isStyle:P(n.text),type:"dynamic"}):h.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:n.text,isStyle:P(n.text),type:"require"}))}function Yl(t,e){let n=js.basename(t).toLowerCase(),r=js.extname(t).toLowerCase();return Le().some(i=>n.includes(i))?"test":_r(n)?"config":e.imports.some(i=>ln().some(o=>i.rawSpecifier.includes(o)))?"test":r===".tsx"||r===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>fn()?"barrel":"logic"}function Kn(t){return h.canHaveModifiers(t)&&h.getModifiers(t)?.some(e=>e.kind===h.SyntaxKind.ExportKeyword)===!0}function Xl(t,e){let n=t.rawCallEdges??[];t.rawCallEdges=n;let r=new Map;for(let s of e.statements){if(!h.isImportDeclaration(s)||!h.isStringLiteral(s.moduleSpecifier))continue;let i=s.moduleSpecifier.text,o=s.importClause;if(o&&(o.name&&r.set(o.name.text,i),o.namedBindings&&h.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)r.set(a.name.text,i)}if(r.size!==0)for(let s of e.statements){let i=ql(s);if(i){let o=ep(s);o&&St(o,i,r,n);continue}h.isClassDeclaration(s)&&s.name&&Zl(s,s.name.text,r,n)}}function Zl(t,e,n,r){for(let s of t.members)h.isMethodDeclaration(s)&&s.body&&h.isIdentifier(s.name)?St(s.body,`${e}.${s.name.text}`,n,r):h.isConstructorDeclaration(s)&&s.body&&St(s.body,`${e}.constructor`,n,r)}function ql(t){if(Kn(t)){if(h.isFunctionDeclaration(t)&&t.name)return t.name.text;if(h.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(h.isIdentifier(e.name)&&e.initializer&&(h.isArrowFunction(e.initializer)||h.isFunctionExpression(e.initializer)))return e.name.text}}}function ep(t){if(h.isFunctionDeclaration(t))return t.body;if(h.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(h.isArrowFunction(e.initializer)||h.isFunctionExpression(e.initializer)))return e.initializer}}function St(t,e,n,r){if(h.isCallExpression(t)&&h.isIdentifier(t.expression)){let s=t.expression.text,i=n.get(s);i&&!r.some(o=>o.from===e&&o.to===s&&o.toSpecifier===i)&&r.push({from:e,to:s,toSpecifier:i})}h.forEachChild(t,s=>St(s,e,n,r))}function bt(t,e){if(e.length===0)return"ui";let n=!1;return t.walk(r=>{if(r.type==="rule")return n=!0,!1}),n?"ui":"barrel"}import Bs from"postcss";import*as tp from"postcss-less";var np=tp,Ks=new Set(["reference","inline"]);function zs(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function rp(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function sp(t,e){let n=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(n){let i=n[1]?.trim()??"",o=n[2]??"";if(!o)return null;let a=Ks.has(i)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...zs(o)?{isExternal:!0}:{}}}let r=t.match(/^url\(['"]?([^'")]+)['"]?\)/),s=r?r[1]?.trim()??"":t.match(/^['"]([^'"]+)['"]/)?.[1]??"";return s?{fromPath:e,toPath:"",rawSpecifier:s,isStyle:!0,type:"static",...zs(s)?{isExternal:!0}:{}}:null}function ip(t,e){let n=[],r=/url\(['"]?([^'")]+)['"]?\)/g,s=r.exec(t);for(;s!==null;){let i=s[1]?.trim()??"";rp(i)&&n.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=r.exec(t)}return n}function Us(t,e){let n=[];return t.walk(r=>{if(r.type==="atrule"&&r.name==="import"){let s=sp(r.params,e);s&&n.push(s)}r.type==="decl"&&n.push(...ip(r.value,e))}),n}function op(t){return t.replace(/(?<!:)\/\/.*/g,"")}function ap(t,e){let n=[],r=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,s=r.exec(t);for(;s!==null;){let i=s[1]?.trim()??"",o=s[2]??"";if(o){let a=Ks.has(i)?"side-effect":"static";n.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}s=r.exec(t)}return n}function kt(t,e){let n=Bs.parse(op(t));return{imports:Us(n,e),root:n}}function cp(t){let e=[],n=[];for(let r of t.nodes??[]){if(r.type!=="atrule")continue;let{value:s}=r;if(s===void 0)continue;let i=r.name;i&&(e.push({name:i}),n.push({name:i,kind:"variable"}))}return{exports:e,tags:n}}function vt(t,e){try{let n=np.parse(t),{exports:r,tags:s}=cp(n);return{imports:Us(n,e),root:n,exports:r,tags:s}}catch{return{imports:ap(t,e),root:Bs.parse(""),exports:[],tags:[]}}}import{parse as lp}from"postcss-scss";function Hs(t){return t.startsWith("_")||t.startsWith("-")}function pp(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function up(t){let e=t.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let n=e[1],s=t.match(/\bas\s+(\S+)/)?.[1];return s!==void 0?{specifier:n,alias:s}:{specifier:n}}function fp(t){let e=[],n=[];for(let r of t.nodes??[]){if(r.type==="decl"&&r.prop.startsWith("$")){let s=r.prop.slice(1);if(!s||Hs(s))continue;e.push({name:s}),n.push({name:s,kind:"variable"});continue}if(r.type==="atrule"&&(r.name==="mixin"||r.name==="function")){let i=r.params.match(/^([\w-]+)/)?.[1];if(!i||Hs(i))continue;let o=r.params.trim();e.push(o.includes("(")?{name:i,signature:o}:{name:i}),n.push({name:i,kind:"function"})}}return{exports:e,tags:n}}function Ct(t,e){let n=lp(t),r=[];n.walk(o=>{if(o.type!=="atrule")return;let{name:a,params:c}=o;if(a!=="import"&&a!=="use"&&a!=="forward")return;let{specifier:l,alias:p}=up(c);if(!l)return;let u={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...pp(l)?{isExternal:!0}:{}};p&&(u.symbols=[p]),r.push(u)});let{exports:s,tags:i}=fp(n);return{imports:r,root:n,exports:s,tags:i}}function Js(t,e){let n=[],r=/@require\s+['"]([^'"]+)['"]/g,s=r.exec(t);for(;s!==null;){let o=s[1];o&&n.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),s=r.exec(t)}let i=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=i.exec(t);s!==null;){let o=s[1];o&&n.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=i.exec(t)}return n}function Vs(t,e){if(e.length===0)return"ui";try{let n=sn("stylus");return new n.Parser(t).parse().nodes.some(i=>i.constructor.name!=="Import")?"ui":"barrel"}catch{return t.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function Oe(t,e){let n=M(t);if(n==="stylus"){let i=Js(e,t);return{imports:i,exports:[],tags:[],category:Vs(e,i)}}if(n==="scss"){let{imports:i,root:o,exports:a,tags:c}=Ct(e,t);return{imports:i,exports:a,tags:c,category:bt(o,i)}}if(n==="less"){let{imports:i,root:o,exports:a,tags:c}=vt(e,t);return{imports:i,exports:a,tags:c,category:bt(o,i)}}let{imports:r,root:s}=kt(e,t);return{imports:r,exports:[],tags:[],category:bt(s,r)}}for(let[t,e]of[["javascript",(n,r)=>Bn(n,r,"javascript")],["typescript",(n,r)=>Bn(n,r,"typescript")],["css",Oe],["scss",Oe],["less",Oe],["stylus",Oe],["coffeescript",ms],["livescript",Fs],["lua",Ds],["python",Is],["go",bs],["java",ws],["kotlin",Ts],["scala",Ms],["groovy",ks],["gherkin",Pn],["markdown",Ps]])Se(t,e);async function Qs(t,e){let n=M(t),r=ds(n);return r?r(t,e):{imports:[],exports:[],tags:[],category:"other"}}import Ys from"path";function mp(t,e){let n=e.get(t.path);n!==void 0&&(t.coveragePct=n)}function Zs(t,e){for(let n of t)if(n.isExternal){let r=n.rawSpecifier.startsWith("@")?n.rawSpecifier.split("/").slice(0,2).join("/"):n.rawSpecifier.split("/")[0];r&&!e.some(s=>s.name===r)&&e.push({name:r,kind:"library"})}}function gp(t,e,n){if(e.isExternal||!e.toPath)return;let r=n.get(e.toPath);r&&(r.category!=="logic"&&r.category!=="barrel"||(r.testedBy??=[],r.testedBy.includes(t.path)||r.testedBy.push(t.path)))}function dp(t,e){if(t.type==="markdown")for(let n of t.imports){if(n.isExternal||!n.toPath)continue;let r=e.get(n.toPath);!r||r===t||(r.documentedBy??=[],r.documentedBy.includes(t.path)||r.documentedBy.push(t.path),r.category==="logic"&&(r.lastCommitAt??0)>(t.lastCommitAt??0)&&(t.staleFor??=[],t.staleFor.includes(r.path)||t.staleFor.push(r.path)))}}function Xs(t){return Math.round(t*1e4)/1e4}function hp(t,e){let n=[];for(let r of t.imports){if(r.isExternal||!r.toPath)continue;let s=e.get(r.toPath);if(!s||s.exports.length===0)continue;let i;if(r.symbols===void 0){if(r.type==="side-effect")continue;i=1}else r.symbols.includes("*")?i=1:i=r.symbols.length/s.exports.length;r.exportUsageRatio=Xs(Math.min(1,i)),n.push(r.exportUsageRatio)}n.length>0&&(t.avgExportUsage=Xs(n.reduce((r,s)=>r+s,0)/n.length),t.maxExportUsage=Math.max(...n))}function qs(t,e,n){e&&(t.some(r=>r.name===e&&r.kind===n)||t.push({name:e,kind:n}))}function yp(t,e){let n=e.toPath,r=Ys.basename(n,Ys.extname(n)).replace(/\.(test|spec)$/,"");qs(t.tags,r,"import")}function xp(t,e,n){let r=n.get(e.toPath);if(!(!r||r.category==="test"))for(let s of r.tags)s.kind==="comment-marker"&&qs(t.tags,s.name,"comment-marker")}function Sp(t,e,n){!e.toPath||e.isExternal||(yp(t,e),xp(t,e,n))}function ei(t,e){for(let n of t.values())delete n.testedBy,delete n.documentedBy,delete n.staleFor,n.category==="test"&&(n.tags=n.tags.filter(r=>r.kind!=="import"));for(let n of t.values()){if(hp(n,t),e.size>0&&mp(n,e),n.category==="test")for(let r of n.imports)gp(n,r,t),Sp(n,r,t);dp(n,t)}}var ti=new Set(["java","kotlin","scala","groovy"]),ni=new Set(["typescript","javascript","python","go","java","kotlin","scala","groovy","scss","less","lua","coffeescript"]),ri=new Set(["typescript","javascript","python","java","kotlin","scala","groovy"]),je=new Set(["typescript","javascript","go","python","java"]),si=new Set(["typescript","javascript","go","python","java"]),bp=new Set(["typescript","javascript","python","go","java","groovy","kotlin","scala","gherkin"]),ii=new Set(["typescript","javascript"]),kp={callEdges:je,functionComplexity:si,typeGraph:ii},vp={callEdges:"call edges",functionComplexity:"per-function complexity",typeGraph:"type extraction"};function Cp(t,e){let n=Array.isArray(t)?t:[t],r=kp[e],s=new Set;for(let c of n)for(let l of c.nodes.values()){if(r.has(l.type))return;l.type!=="markdown"&&l.type!=="unknown"&&s.add(l.type)}let i=[...s].sort(),o=i.length===0?"this project":i.join(", "),a=i.length===1?"is":"are";return`${vp[e]} is only tracked for ${[...r].sort().join(", ")} \u2014 ${o} ${a} unsupported, so this result is empty by design.`}function w(t,e,n,r,s,i,o,a){return{importResolution:t,exportSymbols:e,importSymbols:n,callEdges:r,complexity:s,category:i,duplication:o,testTags:a}}var Un={typescript:w("full","full","full","full","full","full","partial","full"),javascript:w("full","full","full","full","full","full","partial","full"),python:w("full","partial","partial","full","full","partial","partial","full"),go:w("full","partial","none","full","full","partial","partial","full"),java:w("partial","partial","partial","partial","full","partial","partial","full"),kotlin:w("partial","partial","partial","none","none","partial","partial","full"),scala:w("partial","partial","partial","none","none","partial","partial","full"),groovy:w("partial","partial","partial","none","none","partial","partial","full"),coffeescript:w("partial","partial","none","none","none","partial","partial","none"),livescript:w("partial","none","none","none","none","partial","partial","none"),lua:w("partial","partial","none","none","none","partial","partial","none"),css:w("full","none","none","none","none","full","full","none"),scss:w("full","partial","none","none","none","full","full","none"),less:w("full","partial","none","none","none","full","full","none"),stylus:w("full","none","none","none","none","full","partial","none"),gherkin:w("none","none","none","none","none","full","partial","full"),markdown:w("partial","none","none","none","none","full","partial","none"),unknown:w("none","none","none","none","none","none","none","none")},Ep={importResolution:"import resolution",exportSymbols:"export symbols",importSymbols:"per-import symbol tracking",callEdges:"call edges",complexity:"complexity",category:"category classification",duplication:"duplicate detection",testTags:"test-tag strategy"},wp={python:{exportSymbols:"tracked at module level, not per-symbol",importSymbols:"only star imports and re-exports are tracked (ADR-002)"},go:{exportSymbols:"identifier-level, no per-symbol doc/signature",importSymbols:"not tracked \u2014 per-import symbol resolution is not implemented"},java:{importResolution:"index-based: matched by type name across the module, not by resolving the exact package path (ADR-017)",exportSymbols:"top-level types only, no field/method-level exports",importSymbols:"one symbol per import (the FQN's last segment, or the static member for `import static`); wildcard imports carry none, and re-exports aren't tracked",callEdges:"static calls and constructors only (incl. through generics), not virtual dispatch"},kotlin:{importResolution:"index-based, shared with Java's JvmLangResolver (ADR-017)",exportSymbols:"top-level types only",importSymbols:"one symbol per import (the FQN's last segment); wildcard imports carry none, and re-exports aren't tracked",callEdges:"not extracted \u2014 Kotlin needs its own grammar (issue 8c)",complexity:"not computed \u2014 Kotlin needs its own grammar (issue 8c)"},scala:{importResolution:"index-based, shared with Java's JvmLangResolver; brace-package imports are a known gap",exportSymbols:"top-level types only",importSymbols:"one symbol per import (the FQN's last segment, brace groups expanded to one edge per member); wildcard imports carry none, and re-exports aren't tracked",callEdges:"not extracted \u2014 Scala needs its own grammar (issue 8c)",complexity:"not computed \u2014 Scala needs its own grammar (issue 8c)"},groovy:{importResolution:"index-based, shared with Java's JvmLangResolver",exportSymbols:"top-level types only",importSymbols:"one symbol per import (the FQN's last segment, or the static member for `import static`); wildcard imports carry none, and re-exports aren't tracked",callEdges:"not extracted \u2014 Groovy needs its own grammar (issue 8c)",complexity:"not computed \u2014 Groovy needs its own grammar (issue 8c)"},coffeescript:{importResolution:"generic relative-path fallback, no ecosystem-specific rules",exportSymbols:"best-effort, less validated than TS/JS",callEdges:"not extracted (backfill planned \u2014 see the language coverage roadmap)",complexity:"not computed (backfill planned \u2014 see the language coverage roadmap)",testTags:"no framework-aware strategy \u2014 falls back to the generic path-glob applier"},livescript:{importResolution:"generic relative-path fallback",exportSymbols:"not tracked",callEdges:"not extracted (backfill planned)",complexity:"not computed (backfill planned)",testTags:"no framework-aware strategy \u2014 falls back to the generic path-glob applier"},lua:{importResolution:"basic dot-path handling only",exportSymbols:"best-effort module-return inspection",callEdges:"not extracted (backfill planned)",complexity:"not computed (backfill planned)",testTags:"no framework-aware strategy \u2014 falls back to the generic path-glob applier"},scss:{exportSymbols:"root-level $/@ variables, mixins and functions only"},less:{exportSymbols:"root-level $/@ variables, mixins and functions only"},stylus:{duplication:"generic token pipeline \u2014 no shared PostCSS AST for structural comparison"},markdown:{importResolution:"edges only via code-span file references (`` `src/foo.ts` ``) (ADR-009)"},gherkin:{importResolution:"feature files have no imports"}},Tp=["importResolution","exportSymbols","importSymbols","callEdges","complexity"];function oi(t,e){let n=Array.isArray(t)?t:[t],r=new Set;for(let i of n)for(let o of i.nodes.values())o.type!=="markdown"&&o.type!=="unknown"&&r.add(o.type);let s=[];for(let i of r){let o=Un[i][e];if(o==="full")continue;let a=wp[i]?.[e];!a&&o!=="none"||s.push(`${i}: ${Ep[e]} is ${a??"not available for this language \u2014 see docs/language-support.md"}`)}return s.sort()}function Fp(t){let e=new Set;for(let n of Tp)for(let r of oi(t,n))e.add(r);return[...e].sort()}function Dp(t){let e=new Map;for(let n of t.nodes.values())e.set(n.type,(e.get(n.type)??0)+1);return[...e.entries()].map(([n,r])=>({type:n,fileCount:r,exportsTracked:ni.has(n),importSymbolsTracked:ri.has(n),callEdgesTracked:je.has(n),fidelity:Un[n]})).sort((n,r)=>r.fileCount-n.fileCount)}import Ft from"fs";import U from"path";import li from"fs";import we from"path";var $e=class{extensions=[".go"];goModCache=new Map;resolve(e,n,r,s){let{mod:i,replaces:o}=this.readGoMod(r);if(!i)return null;let a=this.applyReplace(n,o,r);if(a!==void 0)return ci(a);if(n!==i&&!n.startsWith(`${i}/`))return null;let c=n.slice(i.length).replace(/^\//,"");return c?ci(we.join(r,c)):null}readGoMod(e){let n=this.goModCache.get(e);if(n!==void 0)return n;let r={mod:null,replaces:new Map};try{let s=li.readFileSync(we.join(e,"go.mod"),"utf-8"),i=Np(s,e);return this.goModCache.set(e,i),i}catch{return this.goModCache.set(e,r),r}}applyReplace(e,n,r){for(let[s,i]of n){if(e===s)return i;if(e.startsWith(`${s}/`)){let o=e.slice(s.length+1);return we.join(i,o)}}}};function Np(t,e){let n=t.split(`
10
+ `),r=null,s=new Map,i=!1;for(let o of n){let a=o.trim();if(a.startsWith("module ")){r=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){ai(a,e,s);continue}!i&&/^replace\s+/.test(a)&&a.includes("=>")&&ai(a.replace(/^replace\s+/,""),e,s)}return{mod:r,replaces:s}}function ai(t,e,n){let[r,s]=t.split("=>").map(a=>a.trim());if(!r||!s)return;let i=r.split(/\s+/)[0];if(!s.startsWith(".")&&!s.startsWith("/"))return;let o=we.isAbsolute(s)?s:we.resolve(e,s);n.set(i,o)}function ci(t){let e;try{e=li.readdirSync(t,{withFileTypes:!0})}catch{return null}let n=e.filter(r=>r.isFile()&&r.name.endsWith(".go")&&!r.name.endsWith("_test.go")).map(r=>({path:we.join(t,r.name),isExternal:!1})).sort((r,s)=>r.path.localeCompare(s.path));return n.length>0?n:null}import Et from"fs";import wt from"path";var Rp=new Set([".java",".kt",".kts",".scala",".sc",".groovy"]),Pp=12,pi=4096,Lp=new Set(An);function fi(t){let e=t.replace(/\\/g,"/"),n=e.match(/^(.*)\/src\/([^/]+)(?:\/|$)/);if(!n?.[1]||!n[2]){let i=e.lastIndexOf("/");return{module:i===-1?e:e.slice(0,i),rootSegment:"",sourceRoot:"unknown"}}let r=n[2],s=r==="main"?"main":Lp.has(r)?r:"unknown";return{module:n[1],rootSegment:r,sourceRoot:s}}var ce=class{constructor(e=[]){this.extraIgnoreDirs=e}extraIgnoreDirs;extensions=[".java",".kt",".kts",".scala",".sc",".groovy",".gradle"];indexCache=new Map;resolve(e,n,r,s){let i=this.getIndex(r);if(i.size===0)return null;let o=n.endsWith(".*"),a=(o?n.slice(0,-2):n).split(".").filter(Boolean);if(a.length===0)return null;if(o){let c=i.get(a.join("."));if(!c)return null;let l=fi(e),p=c.filter(d=>d.module===l.module&&d.rootSegment===l.rootSegment),u=l.sourceRoot!=="main"&&l.sourceRoot!=="unknown",m=p.flatMap(d=>u?d.files:d.files.filter(y=>!In(ui(y))));return Hn(m)}for(let c=a.length-1;c>=1;c--){let l=Ip(i,a.slice(0,c).join("."));if(!l)continue;let p=a[c],u=l.filter(m=>ui(m)===p);if(u.length>0)return Hn(u);if(c===a.length-1)return Hn(l)}return null}getIndex(e){let n=this.indexCache.get(e);if(n)return n;let r=Ap(e,this.extraIgnoreDirs);return this.indexCache.set(e,r),r}};function Ap(t,e=[]){let n=new Map,r=(process.env.MOKOSH_IGNORE_DIRS??"").split(",").map(a=>a.trim()).filter(Boolean),s=new Set([...I,...r,...e]),i=(a,c)=>{let{module:l,rootSegment:p,sourceRoot:u}=fi(c),m=n.get(a);if(!m){n.set(a,[{module:l,rootSegment:p,sourceRoot:u,files:[c]}]);return}let d=m.find(y=>y.module===l&&y.rootSegment===p);d?d.files.push(c):m.push({module:l,rootSegment:p,sourceRoot:u,files:[c]})},o=(a,c)=>{if(c>Pp)return;let l;try{l=Et.readdirSync(a,{withFileTypes:!0})}catch{return}for(let p of l){let u=wt.join(a,p.name);if(p.isDirectory()){!p.name.startsWith(".")&&!s.has(p.name)&&o(u,c+1);continue}if(!p.isFile())continue;let m=wt.extname(p.name);if(!Rp.has(m))continue;let d=Mp(u,m===".scala"||m===".sc");d&&i(d,u)}};o(t,0);for(let a of n.values())for(let c of a)c.files.sort();return n}function Ip(t,e){let n=t.get(e);if(!(!n||n.length===0))return n.length===1?n[0]?.files:n.flatMap(r=>r.files).sort()}function Mp(t,e){let n;try{let r=Et.openSync(t,"r");try{let s=Buffer.alloc(pi),i=Et.readSync(r,s,0,pi,0);n=s.toString("utf8",0,i)}finally{Et.closeSync(r)}}catch{return null}return j(n,e)}function Hn(t){return!t||t.length===0?null:t.map(e=>({path:e,isExternal:!1}))}function ui(t){return wt.basename(t,wt.extname(t))}import _p from"fs";import Jn from"path";var We=class{extensions=[".lua"];resolve(e,n,r,s){let i=n.replace(/\./g,Jn.sep),o=[r,Jn.join(r,"lib")];for(let a of o){if(!_p.existsSync(a))continue;let c=s(Jn.join(a,"_dummy.lua"),i);if(c)return[c]}return null}};import Gp from"path";var Op=new Set(I),ze=class{extensions=[".md",".mdx"];resolve(e,n,r,s){let i=n.replace(/^\.\//,"").split("/")[0];if(i&&Op.has(i))return null;let o=s(Gp.join(r,"_dummy"),`./${n}`);return o?[o]:null}};import jp from"fs";import Vn from"path";var Be=class{extensions=[".py"];resolve(e,n,r,s){let i=n.replace(/\./g,Vn.sep),o=Vn.join(r,`${i}.py`);if(mi(o))return[{path:o,isExternal:!1}];let a=Vn.join(r,i,"__init__.py");return mi(a)?[{path:a,isExternal:!1}]:null}};function mi(t){try{return jp.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import gi from"path";var $p=["~","http://","https://","//","data:","sass:"],Ke=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,n,r,s){if($p.some(p=>n.startsWith(p)))return null;let i=s(e,n);if(i)return[i];let o=gi.dirname(n),a=gi.basename(n),c=o==="."?`_${a}`:`${o}/_${a}`,l=s(e,c);return l?[l]:null}};function Tt(t={}){return[new Be,new We,new $e,t.jvm??new ce,new Ke,new ze]}var di=new Set;function Wp(t,e){let n=t.constructor?.name??"LangResolver";if(di.has(n))return;di.add(n);let r=e instanceof Error?e.message:String(e);process.stderr.write(`
11
+ Warning: ${n}.resolve() threw (${r}); affected imports are left unresolved.
12
+ `)}var H=class{constructor(e,n={}){this.rootDir=e;this.workspaceMap=n.workspaceMap??new Map,this.tsconfigSearchPaths=n.tsconfigSearchPaths??[e],this.pathAliases=n.pathAliases,this.langResolvers=n.langResolvers??Tt()}rootDir;workspaceMap;tsconfigSearchPaths;pathAliases;langResolvers;resolutionCache=new Map;langBucketFor(e){for(let n=0;n<this.langResolvers.length;n++)if(this.langResolvers[n]?.extensions.some(r=>e.endsWith(r)))return String(n);return"none"}cacheKey(e,n){return`${U.dirname(e)}\0${this.langBucketFor(e)}\0${n}`}resolveAll(e,n){let r=this.cacheKey(e,n),s=this.resolutionCache.get(r);if(s!==void 0)return s??[];let i=this.resolveAllUncached(e,n);return this.resolutionCache.set(r,i.length>0?i:null),i}resolveAllUncached(e,n){let r=this.resolvePathAlias(n);if(r)return[r];if(n.startsWith(".")||n.startsWith("/")){let o=this.resolveLocalPath(e,n);return o?[o]:[]}let s=(o,a)=>this.resolveLocalPath(o,a);for(let o of this.langResolvers)if(o.extensions.some(a=>e.endsWith(a))){let a=null;try{a=o.resolve(e,n,this.rootDir,s)}catch(c){Wp(o,c)}if(a)return a}let i=this.resolveWorkspaceImport(n);return i?[i]:[{path:n,isExternal:!0}]}resolve(e,n){return this.resolveAll(e,n)[0]??null}resolveLocalPath(e,n){let r=U.dirname(e),s=n.startsWith("/")?n:U.resolve(r,n),i=!s.startsWith(this.rootDir),o=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=s.match(/\.(js|mjs|cjs)$/);if(a){let c=s.slice(0,-a[0].length);for(let l of[".ts",".tsx"]){let p=this.tryExtensions(c,l,i);if(p)return p}}for(let c of o){let l=this.tryExtensions(s,c,i);if(l)return l}return i?{path:s,isExternal:!0}:null}tryExtensions(e,n,r){let s=e+n;if(this.isFile(s))return{path:s,isExternal:r};let i=U.join(e,`index${n}`);if(this.isFile(i))return{path:i,isExternal:r};if(n===".py"){let o=U.join(e,"__init__.py");if(this.isFile(o))return{path:o,isExternal:r}}return null}isFile(e){try{return Ft.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){if(this.pathAliases)for(let n in this.pathAliases){let r=this.matchAliasPattern(n,e),s=this.pathAliases[n];if(r&&s){let i=this.tryAliasSubstitutions(s,r[1]||"");if(i)return i}}for(let n of this.tsconfigSearchPaths){let r=U.join(n,"tsconfig.json");if(Ft.existsSync(r))try{let i=JSON.parse(Ft.readFileSync(r,"utf-8")).compilerOptions?.paths;if(!i)continue;for(let o in i){let a=this.matchAliasPattern(o,e);if(a){let c=this.tryAliasSubstitutions(i[o],a[1]||"",n);if(c)return c}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,n){let r=this.aliasRegexCache.get(e);if(!r){let s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");r=new RegExp(`^${s}$`),this.aliasRegexCache.set(e,r)}return n.match(r)}tryAliasSubstitutions(e,n,r=this.rootDir){let s=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let i of e){let o=i.replace("*",n),a=U.resolve(r,o);for(let c of s){let l=this.tryExtensions(a,c,!1);if(l)return l}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[n,r]of this.workspaceMap){if(e!==n&&!e.startsWith(`${n}/`))continue;let s=e.slice(n.length),i={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:n};if(!s){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let c=U.join(r,a);try{if(Ft.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...i,path:c}}catch{}}return{...i,path:r}}let o=this.resolveLocalPath(U.join(r,"_dummy"),s.slice(1));return o?{...i,path:o.path}:null}return null}};var Bp=["tests","test","__tests__","specs","spec"],Kp=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage",".pytest_cache","__pycache__"],Up=600;function Hp(){return(process.env.MOKOSH_IGNORE_DIRS??"").split(",").map(t=>t.trim()).filter(Boolean)}function Jp(t,e){if(t.length===0)return e;let n=t.map(o=>R.dirname(o).split(R.sep)),r=n[0]??[];for(let o of n.slice(1)){let a=0;for(;a<r.length&&a<o.length&&r[a]===o[a];)a++;r=r.slice(0,a)}let s=r.join(R.sep)||R.sep,i=R.relative(e,s);return i.startsWith("..")||R.isAbsolute(i)?e:s}var le=class{constructor(e,n=null,r,s,i=!1,o=new Map,a=!0,c=[],l=null){this.rootDir=e;this.enableGitStats=i;this.coverageMap=o;this.parallelParsing=a;this.docFiles=l;this.previousGraph=n,this.walkIgnoreDirs=new Set([...Kp,...c,...Hp()]),this.resolver=r||new H(e),this.lockFile=ls(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;docFiles;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;walkIgnoreDirs;async build(e){let n=e.map(r=>R.isAbsolute(r)?r:R.resolve(this.rootDir,r));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=ns(this.rootDir));try{for(let r of n)this.enqueue(r);return await this.drain(),await this.processTestFiles(Jp(n,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
11
13
  Done. Total processed: ${this.visited.size} nodes.
12
- `),ls(this.graph.nodes,this.coverageMap),new L(this.graph.nodes)}finally{this.pool&&(await this.pool.destroy(),this.pool=null)}}async initPool(){if(this.parallelParsing===!1)return;let e=typeof this.parallelParsing=="object"?this.parallelParsing:{},r=e.minFiles??el;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r))){e.maxThreads!==void 0&&e.maxThreads<1&&process.stderr.write(`
14
+ `),ei(this.graph.nodes,this.coverageMap),new O(this.graph.nodes)}finally{this.pool&&(await this.pool.destroy(),this.pool=null)}}async initPool(){if(this.parallelParsing===!1)return;let e=typeof this.parallelParsing=="object"?this.parallelParsing:{},n=e.minFiles??Up;if(!(n>0&&!this.hasAtLeastFiles(this.rootDir,n))){e.maxThreads!==void 0&&e.maxThreads<1&&process.stderr.write(`
13
15
  Warning: parallelParsing.maxThreads (${e.maxThreads}) must be at least 1; using 1.
14
- `);try{let n=F.join(m,"parse-worker.js");this.pool=new Xc({filename:n,...e.maxThreads!==void 0?{maxThreads:Math.max(1,e.maxThreads)}:{}})}catch(n){process.stderr.write(`
15
- Warning: failed to start parse worker pool, falling back to synchronous parsing: ${n}
16
- `),this.pool=null}}}hasAtLeastFiles(e,r){let n=0,s=[e];for(;s.length>0;){let o=s.pop();if(o===void 0)continue;let i;try{i=Ne.readdirSync(o,{withFileTypes:!0})}catch{continue}for(let a of i)if(a.isDirectory())this.walkIgnoreDirs.has(a.name)||s.push(F.join(o,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=he(),n=o=>r.some(i=>o.name.includes(i));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let o=F.dirname(s);if(o===s)break;for(let i of Zc){let a=F.join(o,i);try{Ne.statSync(a).isDirectory()&&this.walkProject(a,n)}catch{}}s=o}await this.drain()}async processDocFiles(){if(this.docFiles!==null){for(let e of this.docFiles)this.enqueue(e);await this.drain();return}this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,r){let n;try{n=Ne.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let o=F.join(e,s.name);s.isDirectory()?this.walkIgnoreDirs.has(s.name)||this.walkProject(o,r):s.isFile()&&r(s)&&this.enqueue(o)}}enqueue(e){this.visited.has(e)||(this.visited.add(e),this.showProgress(),this.queue.push(e))}async drain(){for(;this.queue.length>0;){let e=this.queue;this.queue=[],await Promise.all(e.map(r=>this.finishFile(r)))}}async finishFile(e){let r=Ne.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=F.relative(this.rootDir,e),s=await this.getNode(e,n,r);s.imports=await this.resolveImports(e,s.imports),cs(s.imports,s.tags),this.graph.nodes.set(s.path,s)}async getNode(e,r,n){let s=this.previousGraph?.nodes.get(r);if(s&&s.mtime===n.mtimeMs&&s.size===n.size)return{...s};let o=await this.tryParse(e,r);if(!o)return this.makeStubNode(e,r,n);let i=this.resolveCallEdges(e,o.rawCallEdges),a=this.buildNode(e,r,n,o,i);return this.attachGitStats(a,r),a}async tryParse(e,r){let n=Ne.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
17
- Warning: failed to parse ${r}: ${s}
18
- `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):os(e,r)}makeStubNode(e,r,n){return{path:r,type:_(e),category:"other",imports:[],exports:[],tags:[],mtime:n.mtimeMs,size:n.size}}resolveCallEdges(e,r){let n=[];for(let s of r??[])try{let o=this.resolver.resolve(e,s.toSpecifier);o&&!o.isExternal&&n.push({from:s.from,to:s.to,toFile:F.relative(this.rootDir,o.path)})}catch{}return n}buildNode(e,r,n,s,o){let{imports:i,exports:a,tags:c,category:l,description:p,complexity:u,cognitiveComplexity:g,functions:d}=s;return{path:r,type:_(e),category:l,imports:i,exports:a,tags:c,mtime:n.mtimeMs,size:n.size,...p!==void 0?{description:p}:{},...o.length>0?{callEdges:o}:{},...u!==void 0?{complexity:u}:{},...g!==void 0?{cognitiveComplexity:g}:{},...d!==void 0?{functions:d}:{}}}attachGitStats(e,r){let n=this.gitStatsMap?.get(r);n&&(e.commitCount90d=n.commitCount90d,n.lastAuthor!==void 0&&(e.lastAuthor=n.lastAuthor),n.lastCommitAt!==void 0&&(e.lastCommitAt=n.lastCommitAt))}async resolveImports(e,r){let n=[];for(let s of r){let o=this.resolver.resolveAll(e,s.rawSpecifier);if(!(o.length===0||s.type==="side-effect"&&s.rawSpecifier.endsWith(".*")&&o.every(a=>a.isExternal)))for(let a of o){if(!a.isExternal&&a.path===e)continue;let c={...s,toPath:a.isExternal?a.path:F.relative(this.rootDir,a.path),isExternal:a.isExternal};a.isWorkspace&&(c.isWorkspace=!0,c.workspacePackage=a.workspacePackage),a.isExternal?this.attachLockfileVersion(c):this.enqueue(a.path),n.push(c)}}return n}attachLockfileVersion(e){if(!this.lockFile)return;let r=this.lockFile.jvmDependencies;if(r&&ps.has(_(e.fromPath))){let o=e.rawSpecifier.replace(/\.\*$/,""),i="";for(let a of Object.keys(r))(o===a||o.startsWith(`${a}.`))&&a.length>i.length&&(i=a);i&&(e.version=r[i]?.version);return}let n=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],s=n?this.lockFile.dependencies[n]:void 0;s&&(e.version=s.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};import{readFile as Ds}from"fs/promises";import Ie from"path";import Tl from"piscina";var nl=new Set(["css","scss","less","stylus"]);function ks(t){return nl.has(t)?"style":"code"}import vs from"path";var sl=new Set(["generated","__generated__","__generated","gen","__snapshots__"]),ol=[".pb.go",".pb.ts",".pb.js","_pb2.py","_pb2.pyi","_pb.dart",".g.dart",".generated.ts",".generated.tsx",".generated.js",".generated.jsx","_generated.go",".gen.go",".gen.ts",".snap"],il=["@generated","do not edit","code generated by","autogenerated","auto-generated","this file was automatically generated","this is a generated file","jest snapshot v1"],al=500;function cl(t,e){let r=t.split(/[\\/]/),n=/^\*\*\/(.+?)\/\*\*$/.exec(e);return n?r.includes(n[1]):e.startsWith("*.")?vs.basename(t).endsWith(e.slice(1)):r.includes(e)}function st(t,e=[]){if(t.split(/[\\/]/).some(s=>sl.has(s)))return!0;let n=vs.basename(t);return ol.some(s=>n.endsWith(s))?!0:e.some(s=>cl(t,s))}function Pe(t){let e=t.slice(0,al).toLowerCase();return il.some(r=>e.includes(r))}function ll(t){return t.trim().replace(/\s+/g," ")}function pl(t){try{return t.fileType==="scss"?Ze(t.source,t.file).root:t.fileType==="less"?Xe(t.source,t.file).root:t.fileType==="css"?Qe(t.source,t.file).root:void 0}catch{return}}function ul(t){let e=pl(t);if(!e)return[];let r=[];return e.walkRules(n=>{let s=n.nodes?.filter(p=>p.type==="decl")??[];if(s.length===0)return;let o=s[0],i=s[s.length-1],a=n.source?.start?.line??o?.source?.start?.line,c=i?.source?.end?.line??i?.source?.start?.line??a;if(a===void 0||c===void 0)return;let l=s.map(p=>`${p.prop.trim().toLowerCase()}:${ll(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function Cs(t,e,r=2){let n=new Map;for(let o of t)for(let i of ul(o)){if(i.declCount<r||i.lines<e)continue;let a=n.get(i.signature);a?a.push(i):n.set(i.signature,[i])}let s=[];for(let o of n.values())for(let i=0;i<o.length;i++)for(let a=i+1;a<o.length;a++){let c=o[i],l=o[a];if(c.file===l.file&&c.startLine===l.startLine&&c.endLine===l.endLine)continue;let p={file:c.file,startLine:c.startLine,endLine:c.endLine},u={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,u],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((o,i)=>i.lines-o.lines)}function ws(t){let e=t.length,r=[],n=[{lcpLength:0,low:0}];for(let s=1;s<e;s++){let o=s-1;for(;t[s]<n[n.length-1].lcpLength;){let i=n.pop();r.push({lcpLength:i.lcpLength,low:i.low,high:s-1}),o=i.low}t[s]>n[n.length-1].lcpLength&&n.push({lcpLength:t[s],low:o})}for(;n.length>1;){let s=n.pop();r.push({lcpLength:s.lcpLength,low:s.low,high:e-1})}return r}var ml=new Set(["{","}",":",",","[","]"]);function Es(t,e,r){let n=0;for(let s=e;s<e+r;s++)ml.has(t[s].text)&&n++;return n/r}function Ts(t){let e=t.length;if(e===0)return[];let r=Array.from({length:e},(o,i)=>i),n=new Array(e);{let o=[...new Set(t)].sort(),i=new Map(o.map((a,c)=>[a,c]));for(let a=0;a<e;a++)n[a]=i.get(t[a])}let s=new Array(e).fill(0);for(let o=1;o<e;o*=2){let i=a=>a+o<e?n[a+o]:-1;r.sort((a,c)=>{let l=n[a]-n[c];return l!==0?l:i(a)-i(c)}),s[r[0]]=0;for(let a=1;a<e;a++){let c=r[a-1],l=r[a],p=n[c]===n[l],u=i(c)===i(l);s[l]=s[c]+(p&&u?0:1)}if([n,s]=[s,n],n[r[e-1]]===e-1)break}return r}function Fs(t,e){let r=t.length,n=new Array(r).fill(0);if(r===0)return n;let s=new Array(r);for(let i=0;i<r;i++)s[e[i]]=i;let o=0;for(let i=0;i<r;i++){let a=s[i];if(a>0){let c=e[a-1];for(;i+o<r&&c+o<r&&t[i+o]===t[c+o];)o++;n[a]=o,o>0&&o--}else o=0}return n}function Ns(t,e,r,n=.5){let s=[],o=[],i=new Map;for(let{file:u,tokens:g}of t)if(g.length!==0){i.set(u,g);for(let d=0;d<g.length;d++)s.push(g[d].text),o.push({file:u,localIndex:d});s.push(` ${u}`),o.push({file:u,localIndex:-1})}if(s.length===0)return[];let a=Ts(s),c=Fs(s,a),l=ws(c),p=[];for(let u of l){let g=fl(u,a,o,i,e,r,n);g&&p.push(g)}return p.sort((u,g)=>g.lines-u.lines)}function fl(t,e,r,n,s,o,i){if(t.lcpLength<s)return;let a=[];for(let d=t.low;d<=t.high;d++){let y=r[e[d]];y.localIndex!==-1&&a.push(y)}if(a.length<2||!gl(a,n))return;let c=dl(a,t.lcpLength);if(c.length<2)return;let l=c[0],p=n.get(l.file);if(Es(p,l.localIndex,t.lcpLength)>i)return;let u=c.map(({file:d,localIndex:y})=>{let k=n.get(d);return{file:d,startLine:k[y].line,endLine:k[y+t.lcpLength-1].line}}),g=Math.min(...u.map(d=>d.endLine-d.startLine+1));if(!(g<o))return{occurrences:u,lines:g,tokens:t.lcpLength}}function gl(t,e){let r=null;for(let{file:n,localIndex:s}of t){if(s===0)return!0;let i=e.get(n)[s-1].text;if(r===null)r=i;else if(r!==i)return!0}return!1}function dl(t,e){let r=new Map;for(let{file:s,localIndex:o}of t){let i=r.get(s);i?i.push(o):r.set(s,[o])}let n=[];for(let[s,o]of r){o.sort((a,c)=>a-c);let i=Number.NEGATIVE_INFINITY;for(let a of o)a>=i&&(n.push({file:s,localIndex:a}),i=a+e)}return n}var hl={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{line:["//"],block:[["/*","*/"]]},java:{line:["//"],block:[["/*","*/"]]},kotlin:{line:["//"],block:[["/*","*/"]]},scala:{line:["//"],block:[["/*","*/"]]},groovy:{line:["//"],block:[["/*","*/"]]},css:{block:[["/*","*/"]]},scss:{line:["//"],block:[["/*","*/"]]},less:{line:["//"],block:[["/*","*/"]]},stylus:{line:["//"],block:[["/*","*/"]]},python:{line:["#"]},gherkin:{line:["#"]},coffeescript:{line:["#"],block:[["###","###"]]},livescript:{line:["#"],block:[["###","###"]]},lua:{line:["--"],block:[["--[[","]]"]]},markdown:{block:[["<!--","-->"]]}};function Ps(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function yl(t,e){if(!e)return t;let r=t;for(let[n,s]of e.block??[]){let o=0;for(;;){let i=r.indexOf(n,o);if(i===-1)break;let a=r.indexOf(s,i+n.length),c=a===-1?r.length:a+s.length;r=Ps(r,i,c),o=c}}for(let n of e.line??[]){let s=0;for(;;){let o=r.indexOf(n,s);if(o===-1)break;let i=r.indexOf(`
19
- `,o),a=i===-1?r.length:i;r=Ps(r,o,a),s=a}}return r}var xl={typescript:[/^\s*import[\s{("*]/,/^\s*export\s.*\sfrom\s/],javascript:[/^\s*import[\s{("*]/,/^\s*export\s.*\sfrom\s/],python:[/^\s*import\s+\S/,/^\s*from\s+\S+\s+import[\s(]/],go:[/^\s*import\s+["(]/],java:[/^\s*import\s+/],kotlin:[/^\s*import\s+/],scala:[/^\s*import\s+/],groovy:[/^\s*import\s+/]};function Sl(t,e){let r=xl[e];if(!r)return t;let n=t.split(`
20
- `),s=e==="go",o=!1,i=!1;for(let a=0;a<n.length;a++){let c=n[a],l=()=>{n[a]=c.replace(/[^\r]/g," ")};if(o){l(),c.includes(")")&&(o=!1);continue}if(i){l(),(/}\s*from\s/.test(c)||c.includes("}"))&&(i=!1);continue}r.some(p=>p.test(c))&&(l(),s&&/^\s*import\s+\(/.test(c)&&!c.includes(")")?o=!0:(e==="typescript"||e==="javascript")&&/^\s*import\b/.test(c)&&c.includes("{")&&!c.includes("}")&&(i=!0))}return n.join(`
21
- `)}var bl=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],hr=new RegExp(`${bl.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),kl=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Rs=/^\d+(?:\.\d+)?$/,vl=/^(".*"|'.*'|`.*`)$/s,Cl=new Set(["if","else","elif","for","while","do","switch","case","default","break","continue","return","function","def","class","struct","interface","const","let","var","local","import","export","from","package","try","catch","except","finally","throw","raise","new","this","self","end","then","yield","async","await","nil","null","None","true","false","True","False","and","or","not","in","of","is"]);function Is(t,e,r=!0){let n=Sl(yl(t,hl[e]),e),s=[],o=1,i=0;hr.lastIndex=0;let a=hr.exec(n);for(;a!==null;){for(let p=i;p<a.index;p++)n[p]===`
22
- `&&o++;i=a.index;let c=a[0],l=c;kl.test(c)&&!Cl.has(c)?l="ID":r&&(Rs.test(c)||vl.test(c))&&(l=Rs.test(c)?"NUM":"STR"),s.push({text:l,line:o});for(let p=i;p<a.index+c.length;p++)n[p]===`
23
- `&&o++;i=a.index+c.length,a=hr.exec(n)}return s}import Re from"fs";import wl from"path";function El(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mtime=="number"&&typeof e.size=="number"&&typeof e.ignoreLiterals=="boolean"&&typeof e.generated=="boolean"&&Array.isArray(e.tokens)}function ot(t){try{if(!Re.existsSync(t))return new Map;let e=Re.readFileSync(t,"utf-8"),r=JSON.parse(e);if(!Array.isArray(r))return new Map;let n=r.filter(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string"&&El(s[1]));return new Map(n)}catch{return new Map}}function it(t,e){let r=wl.dirname(e);Re.existsSync(r)||Re.mkdirSync(r,{recursive:!0}),Re.writeFileSync(e,JSON.stringify([...t.entries()]))}var Fl=20,Nl=new Set(["css","scss","less"]);function Pl(t){return Se.includes(Ie.basename(t))}function Rl(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(Ie.sep).some(n=>r.has(n))}function Ms(t,e){let r=[];return new Set(t.occurrences.map(n=>n.file)).size===1&&r.push("same-file"),t.occurrences.some(n=>e.has(n.file))&&r.push("generated"),r.length>0?{...t,signals:r}:t}async function at(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:o=!0,maxPunctuationRatio:i=.5,limit:a=50,ignoreDirs:c=I,includeGenerated:l=!1,ignoreGlobs:p=[],parallelTokenizing:u=!0,tokenCache:g}=r,d=[...t.nodes.values()].filter(S=>!Pl(S.path)&&!Rl(S.path,c)),y=new Set,k=Il(u,d.length);try{let S=[],v=new Map;if(await Promise.all(d.map(async x=>{let w=st(x.path,p);if(w&&!l)return;if(Nl.has(x.type)){let z;try{z=await Ds(Ie.join(e,x.path),"utf8")}catch{return}let Kr=w||Pe(z);if(Kr&&!l)return;Kr&&y.add(x.path),S.push({file:x.path,source:z,fileType:x.type});return}let W=g?.get(x.path),No=W&&W.mtime===x.mtime&&W.size===x.size&&W.ignoreLiterals===o,Oe,ne;if(No)Oe=W.tokens,ne=W.generated;else{let z;try{z=await Ds(Ie.join(e,x.path),"utf8")}catch{return}if(ne=w||Pe(z),ne&&!l)return;Oe=k?await k.run({source:z,fileType:x.type,ignoreLiterals:o}):Is(z,x.type,o),g?.set(x.path,{mtime:x.mtime,size:x.size,ignoreLiterals:o,generated:ne,tokens:Oe})}if(ne&&!l)return;ne&&y.add(x.path);let Br=ks(x.type),Hr={file:x.path,tokens:Oe},Ur=v.get(Br);Ur?Ur.push(Hr):v.set(Br,[Hr])})),g){let x=new Set(d.map(w=>w.path));for(let w of g.keys())x.has(w)||g.delete(w)}let R=Cs(S,n).map(x=>Ms(x,y));for(let[x,w]of v)for(let W of Ns(w,s,n,i))R.push(Ms({...W,family:x},y));return{groups:R.sort((x,w)=>w.lines-x.lines).slice(0,a)}}finally{k&&await k.destroy()}}function Il(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??Fl;if(e<n)return null;r.maxThreads!==void 0&&r.maxThreads<1&&process.stderr.write(`
24
- Warning: parallelTokenizing.maxThreads (${r.maxThreads}) must be at least 1; using 1.
25
- `);try{return new Tl({filename:Ie.join(m,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:Math.max(1,r.maxThreads)}:{}})}catch(s){return process.stderr.write(`
16
+ `);try{let r=R.join(f,"parse-worker.js");this.pool=new zp({filename:r,...e.maxThreads!==void 0?{maxThreads:Math.max(1,e.maxThreads)}:{}})}catch(r){process.stderr.write(`
17
+ Warning: failed to start parse worker pool, falling back to synchronous parsing: ${r}
18
+ `),this.pool=null}}}hasAtLeastFiles(e,n){let r=0,s=[e];for(;s.length>0;){let i=s.pop();if(i===void 0)continue;let o;try{o=Ue.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())this.walkIgnoreDirs.has(a.name)||s.push(R.join(i,a.name));else if(a.isFile()&&(r++,r>=n))return!0}return r>=n}async processTestFiles(e){let n=Le(),r=i=>n.some(o=>i.name.includes(o));this.walkProject(e,r);let s=e;for(;s!==this.rootDir;){let i=R.dirname(s);if(i===s)break;for(let o of Bp){let a=R.join(i,o);try{Ue.statSync(a).isDirectory()&&this.walkProject(a,r)}catch{}}s=i}await this.drain()}async processDocFiles(){if(this.docFiles!==null){for(let e of this.docFiles)this.enqueue(e);await this.drain();return}this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,n){let r;try{r=Ue.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of r){let i=R.join(e,s.name);s.isDirectory()?this.walkIgnoreDirs.has(s.name)||this.walkProject(i,n):s.isFile()&&n(s)&&this.enqueue(i)}}enqueue(e){this.visited.has(e)||(this.visited.add(e),this.showProgress(),this.queue.push(e))}async drain(){for(;this.queue.length>0;){let e=this.queue;this.queue=[],await Promise.all(e.map(n=>this.finishFile(n)))}}async finishFile(e){let n=Ue.statSync(e,{throwIfNoEntry:!1});if(!n?.isFile())return;let r=R.relative(this.rootDir,e),s=await this.getNode(e,r,n);s.imports=await this.resolveImports(e,s.imports),Zs(s.imports,s.tags),this.graph.nodes.set(s.path,s)}async getNode(e,n,r){let s=this.previousGraph?.nodes.get(n);if(s&&s.mtime===r.mtimeMs&&s.size===r.size)return{...s};let i=await this.tryParse(e,n);if(!i)return this.makeStubNode(e,n,r);let o=this.resolveCallEdges(e,i.rawCallEdges),a=this.buildNode(e,n,r,i,o);return this.attachGitStats(a,n),a}async tryParse(e,n){let r=Ue.readFileSync(e,"utf-8");try{return await this.parseContent(e,r)}catch(s){return process.stderr.write(`
19
+ Warning: failed to parse ${n}: ${s}
20
+ `),null}}parseContent(e,n){return this.pool?this.pool.run({filePath:e,content:n}):Qs(e,n)}makeStubNode(e,n,r){return{path:n,type:M(e),category:"other",imports:[],exports:[],tags:[],mtime:r.mtimeMs,size:r.size}}resolveCallEdges(e,n){let r=[];for(let s of n??[])try{let i=this.resolver.resolve(e,s.toSpecifier);i&&!i.isExternal&&r.push({from:s.from,to:s.to,toFile:R.relative(this.rootDir,i.path)})}catch{}return r}buildNode(e,n,r,s,i){let{imports:o,exports:a,tags:c,category:l,description:p,complexity:u,cognitiveComplexity:m,functions:d}=s;return{path:n,type:M(e),category:l,imports:o,exports:a,tags:c,mtime:r.mtimeMs,size:r.size,...p!==void 0?{description:p}:{},...i.length>0?{callEdges:i}:{},...u!==void 0?{complexity:u}:{},...m!==void 0?{cognitiveComplexity:m}:{},...d!==void 0?{functions:d}:{}}}attachGitStats(e,n){let r=this.gitStatsMap?.get(n);r&&(e.commitCount90d=r.commitCount90d,r.lastAuthor!==void 0&&(e.lastAuthor=r.lastAuthor),r.lastCommitAt!==void 0&&(e.lastCommitAt=r.lastCommitAt))}async resolveImports(e,n){let r=[];for(let s of n){let i=this.resolver.resolveAll(e,s.rawSpecifier);if(!(i.length===0||s.type==="side-effect"&&s.rawSpecifier.endsWith(".*")&&i.every(a=>a.isExternal)))for(let a of i){if(!a.isExternal&&a.path===e)continue;let c={...s,toPath:a.isExternal?a.path:R.relative(this.rootDir,a.path),isExternal:a.isExternal};a.isWorkspace&&(c.isWorkspace=!0,c.workspacePackage=a.workspacePackage),a.isExternal?this.attachLockfileVersion(c):this.enqueue(a.path),r.push(c)}}return r}attachLockfileVersion(e){if(!this.lockFile)return;let n=this.lockFile.jvmDependencies;if(n&&ti.has(M(e.fromPath))){let i=e.rawSpecifier.replace(/\.\*$/,""),o="";for(let a of Object.keys(n))(i===a||i.startsWith(`${a}.`))&&a.length>o.length&&(o=a);o&&(e.version=n[o]?.version);return}let r=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],s=r?this.lockFile.dependencies[r]:void 0;s&&(e.version=s.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};import{readFile as er}from"fs/promises";import Fe from"path";import Gu from"piscina";function Qn(t,e){return t.startsWith("!")?e!==t.slice(1):e===t}function hi(t){return t.score??t.lines}function He(t,e){let n=t.occurrences.map(s=>s.file);if(e.path!==void 0){let s=e.path,i=o=>o.includes(s.startsWith("!")?s.slice(1):s);if(s.startsWith("!")?n.some(i):!n.some(i))return!1}if(e.allPaths!==void 0){let s=e.allPaths,i=s.startsWith("!")?s.slice(1):s,o=n.length>0&&n.every(a=>a.includes(i));if(s.startsWith("!")?o:!o)return!1}if(e.family!==void 0&&!Qn(e.family,t.family))return!1;if(e.type!==void 0){let s=e.type.startsWith("!")?e.type.slice(1):e.type,i=n.length>0&&n.every(o=>M(o)===s);if(e.type.startsWith("!")?i:!i)return!1}if(e.kind!==void 0&&!Qn(e.kind,t.kind??"block")||e.defKind!==void 0&&!Qn(e.defKind,t.defKind)||e.minLines!==void 0&&t.lines<e.minLines||e.maxLines!==void 0&&t.lines>e.maxLines)return!1;let r=hi(t);if(e.minScore!==void 0&&r<e.minScore||e.maxScore!==void 0&&r>e.maxScore||e.minOccurrences!==void 0&&t.occurrences.length<e.minOccurrences||e.crossFile!==void 0&&new Set(n).size>=2!==e.crossFile)return!1;if(e.signals!==void 0&&e.signals.length>0){let s=new Set(t.signals??[]),i=e.signals.filter(a=>!a.startsWith("!"));if(e.signals.filter(a=>a.startsWith("!")).map(a=>a.slice(1)).some(a=>s.has(a))||i.length>0&&!i.some(a=>s.has(a)))return!1}return!0}function Yn(t,e){let n=t;if(e.sort){let r=e.sortDir==="asc"?-1:1,s=e.sort==="score"?hi:e.sort==="occurrences"?i=>i.occurrences.length:i=>i.lines;n=[...n].sort((i,o)=>(s(o)-s(i))*r)}return e.limit!==void 0&&(n=n.slice(0,Math.max(0,e.limit))),n}function yi(t,e){return Yn(t.filter(n=>He(n,e)),e)}var bi={path:{field:"path",kind:"string"},allpaths:{field:"allPaths",kind:"string"},family:{field:"family",kind:"string"},type:{field:"type",kind:"string"},kind:{field:"kind",kind:"string"},defkind:{field:"defKind",kind:"string"},minlines:{field:"minLines",kind:"int"},maxlines:{field:"maxLines",kind:"int"},minscore:{field:"minScore",kind:"int"},maxscore:{field:"maxScore",kind:"int"},minoccurrences:{field:"minOccurrences",kind:"int"},crossfile:{field:"crossFile",kind:"bool"},limit:{field:"limit",kind:"int"}},xi=new Set(["lines","score","occurrences"]),Si=new Set([...Object.keys(bi),"signal","signals","sort","sortdir"]);function Vp(t,e,n,r,s){let i=t;if(n==="string"){i[e]=s;return}if(n==="bool"){i[e]=s.toLowerCase()==="true";return}let o=Number(s);if(!Number.isFinite(o))throw new Error(`find_duplicates filter: "${r}" expects a number, got "${s}"`);i[e]=o}function Qp(t,e){let n=e.indexOf(":");if(n===-1)throw new Error(`find_duplicates filter: clause "${e}" is not "key:value"`);let r=e.slice(0,n).trim().toLowerCase(),s=e.slice(n+1).trim();if(!r||!s)return;if(!Si.has(r))throw new Error(`find_duplicates filter: unknown key "${r}". Known keys: ${[...Si].sort().join(", ")}`);if(r==="signal"||r==="signals"){t.signals=[...t.signals??[],s];return}if(r==="sort"){if(!xi.has(s))throw new Error(`find_duplicates filter: sort must be one of ${[...xi].join(", ")}, got "${s}"`);t.sort=s;return}if(r==="sortdir"){t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";return}let i=bi[r];i&&Vp(t,i.field,i.kind,r,s)}function Dt(t){let e={};for(let n of t.split(",")){let r=n.trim();r&&Qp(e,r)}return e}function Yp(t){let e=[...t].sort((r,s)=>r.start-s.start),n=[];for(let r of e){let s=n.at(-1);s&&r.start<=s.end+1?s.end=Math.max(s.end,r.end):n.push({...r})}return n}function Xp(t,e,n){let r=e.flatMap(a=>a.occurrences).filter(a=>a.file===t).map(a=>({start:a.startLine,end:a.endLine})),s=Yp(r).reduce((a,c)=>a+(c.end-c.start+1),0),i=n?.get(t),o=i!==void 0&&i>0?Math.round(s/i*1e3)/10:void 0;return{file:t,coveredLines:s,totalLines:i,coveragePct:o}}function ki(t,e){let n=new Map;for(let s of t){let i=[...new Set(s.occurrences.map(c=>c.file))].sort(),o=i.join("\0"),a=n.get(o);a?a.groups.push(s):n.set(o,{files:i,groups:[s]})}let r=[];for(let{files:s,groups:i}of n.values()){let o=Math.max(...i.map(a=>a.lines));r.push({files:s,groups:[...i].sort((a,c)=>c.lines-a.lines),matchCount:i.length,longestMatch:o,coverage:s.map(a=>Xp(a,i,e))})}return r.sort((s,i)=>i.longestMatch-s.longestMatch||i.matchCount-s.matchCount)}var Zp={css:"style",scss:"style",less:"style",stylus:"style",javascript:"js",typescript:"js",coffeescript:"js",livescript:"js",java:"jvm",kotlin:"jvm",scala:"jvm",groovy:"jvm",python:"python",go:"go",lua:"lua",markdown:"markdown",gherkin:"gherkin"};function vi(t){return Zp[t]??"other"}import Ci from"path";var qp=new Set(["generated","__generated__","__generated","gen","__snapshots__"]),eu=[".pb.go",".pb.ts",".pb.js","_pb2.py","_pb2.pyi","_pb.dart",".g.dart",".generated.ts",".generated.tsx",".generated.js",".generated.jsx","_generated.go",".gen.go",".gen.ts",".snap"],tu=["@generated","do not edit","code generated by","autogenerated","auto-generated","this file was automatically generated","this is a generated file","jest snapshot v1"],nu=500;function ru(t,e){let n=t.split(/[\\/]/),r=/^\*\*\/(.+?)\/\*\*$/.exec(e);return r?n.includes(r[1]):e.startsWith("*.")?Ci.basename(t).endsWith(e.slice(1)):n.includes(e)}function Nt(t,e=[]){if(t.split(/[\\/]/).some(s=>qp.has(s)))return!0;let r=Ci.basename(t);return eu.some(s=>r.endsWith(s))?!0:e.some(s=>ru(t,s))}function Je(t){let e=t.slice(0,nu).toLowerCase();return tu.some(n=>e.includes(n))}import E from"typescript";function Ei(t,e,n){let r=t.tagName.getText(e),s=[];for(let i of t.attributes.properties){if(E.isJsxSpreadAttribute(i))return;let o=i.name.getText(e);if(!i.initializer)s.push(o);else if(E.isStringLiteral(i.initializer))s.push(`${o}=${i.initializer.text}`);else if(E.isJsxExpression(i.initializer))if(!i.initializer.expression)s.push(`${o}={}`);else{let a=n.printNode(E.EmitHint.Unspecified,i.initializer.expression,e);s.push(`${o}=${a}`)}else return}return s.sort(),s.length>0?`${r} ${s.join(" ")}`:r}function su(t,e,n){if(E.isJsxText(t)){let r=t.text.trim().replace(/\s+/g," ");return r.length===0?"":`T:${r}`}if(E.isJsxExpression(t))return t.expression?`E:${n.printNode(E.EmitHint.Unspecified,t.expression,e)}`:"";if(E.isJsxElement(t)||E.isJsxSelfClosingElement(t)||E.isJsxFragment(t))return wi(t,e,n)}function wi(t,e,n){if(E.isJsxSelfClosingElement(t)){let i=Ei(t,e,n);return i===void 0?void 0:`<${i}/>`}let r=[];for(let i of t.children){let o=su(i,e,n);if(o===void 0)return;r.push(o)}if(E.isJsxFragment(t))return`<>${r.join("")}</>`;let s=Ei(t.openingElement,e,n);return s===void 0?void 0:`<${s}>${r.join("")}</>`}function iu(t,e){let n=E.createSourceFile(t.file,t.source,E.ScriptTarget.Latest,!0,E.ScriptKind.TSX),r=E.createPrinter({removeComments:!0}),s=[],i=a=>n.getLineAndCharacterOfPosition(a).line+1,o=a=>{if(E.isJsxElement(a)||E.isJsxSelfClosingElement(a)||E.isJsxFragment(a)){let c=wi(a,n,r);c!==void 0&&c.length>=e&&s.push({file:t.file,startLine:i(a.getStart(n)),endLine:i(a.getEnd()),canonicalShape:c})}E.forEachChild(a,o)};return o(n),s}function ou(t){let e=[...t].sort((s,i)=>i[0].canonicalShape.length-s[0].canonicalShape.length),n=new Map,r=[];for(let s of e){let i=s.filter(o=>!n.get(o.file)?.some(c=>c.start<=o.startLine&&o.endLine<=c.end));if(!(i.length<2)){for(let o of i){let a={start:o.startLine,end:o.endLine},c=n.get(o.file);c?c.push(a):n.set(o.file,[a])}r.push(i)}}return r}function Ti(t,e=40){let n=new Map;for(let i of t)for(let o of iu(i,e)){let a=n.get(o.canonicalShape);a?a.push(o):n.set(o.canonicalShape,[o])}let r=[...n.values()].filter(i=>i.length>=2),s=[];for(let i of ou(r)){let o=i[0],a=i.map(c=>({file:c.file,startLine:c.startLine,endLine:c.endLine}));s.push({occurrences:a,lines:Math.max(...i.map(c=>c.endLine-c.startLine+1)),tokens:o.canonicalShape.length,kind:"definition",defKind:"jsxElement"})}return s}import F from"typescript";function au(t){let e=t;for(;F.isAsExpression(e)||F.isSatisfiesExpression(e)||F.isParenthesizedExpression(e);)e=e.expression;return e}function cu(t,e,n){if(F.isPropertyAssignment(n)){if(F.isComputedPropertyName(n.name))return;let r=n.name.getText(e),s=t.printNode(F.EmitHint.Unspecified,n.initializer,e);return`${r}:${s}`}if(F.isShorthandPropertyAssignment(n)){let r=n.name.getText(e);return`${r}:${r}`}}function lu(t){let e=t.filter(n=>n!==void 0);if(!(e.length<2||e.length!==t.length))return[...e].sort().join(";")}function pu(t){let e=F.createSourceFile(t.file,t.source,F.ScriptTarget.Latest,!0,F.ScriptKind.TSX),n=F.createPrinter({removeComments:!0}),r=[],s=o=>e.getLineAndCharacterOfPosition(o).line+1,i=o=>{if(F.isVariableDeclaration(o)&&F.isIdentifier(o.name)&&o.initializer&&F.isVariableDeclarationList(o.parent)&&(o.parent.flags&F.NodeFlags.Const)!==0){let a=au(o.initializer);if(F.isObjectLiteralExpression(a)){let c=lu(a.properties.map(l=>cu(n,e,l)));c!==void 0&&r.push({file:t.file,name:o.name.text,startLine:s(o.getStart(e)),endLine:s(o.getEnd()),memberCount:a.properties.length,canonicalShape:c})}}F.forEachChild(o,i)};return i(e),r}function Fi(t,e=3){let n=new Map;for(let s of t)for(let i of pu(s)){if(i.memberCount<e)continue;let o=n.get(i.canonicalShape);o?o.push(i):n.set(i.canonicalShape,[i])}let r=[];for(let s of n.values()){if(s.length<2)continue;let i=s[0],o=s.map(a=>({file:a.file,startLine:a.startLine,endLine:a.endLine,name:a.name}));r.push({occurrences:o,lines:Math.max(...s.map(a=>a.endLine-a.startLine+1)),tokens:i.memberCount,kind:"definition",defKind:"objectLiteral"})}return r}function Rt(t){return t.trim().replace(/\s+/g," ")}function Xn(t){try{return t.fileType==="scss"?Ct(t.source,t.file).root:t.fileType==="less"?vt(t.source,t.file).root:t.fileType==="css"?kt(t.source,t.file).root:void 0}catch{return}}function uu(t){let e=Xn(t);if(!e)return[];let n=[];return e.walkRules(r=>{let s=r.nodes?.filter(p=>p.type==="decl")??[];if(s.length===0)return;let i=s[0],o=s[s.length-1],a=r.source?.start?.line??i?.source?.start?.line,c=o?.source?.end?.line??o?.source?.start?.line??a;if(a===void 0||c===void 0)return;let l=s.map(p=>`${p.prop.trim().toLowerCase()}:${Rt(p.value)}`).join(";");n.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),n}function Di(t,e,n=2){let r=new Map;for(let i of t)for(let o of uu(i)){if(o.declCount<n||o.lines<e)continue;let a=r.get(o.signature);a?a.push(o):r.set(o.signature,[o])}let s=[];for(let i of r.values())for(let o=0;o<i.length;o++)for(let a=o+1;a<i.length;a++){let c=i[o],l=i[a];if(c.file===l.file&&c.startLine===l.startLine&&c.endLine===l.endLine)continue;let p={file:c.file,startLine:c.startLine,endLine:c.endLine},u={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,u],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((i,o)=>o.lines-i.lines)}function fu(t){let e=Xn(t);if(!e)return[];let n=[];return e.walkDecls(r=>{let s=r.prop.startsWith("--"),i=t.fileType==="scss"&&r.prop.startsWith("$");if(!s&&!i)return;let o=r.source?.start?.line;o!==void 0&&n.push({file:t.file,line:o,name:r.prop,value:Rt(r.value)})}),t.fileType==="less"&&e.walkAtRules(r=>{let{value:s}=r;if(s===void 0)return;let i=r.source?.start?.line;i!==void 0&&n.push({file:t.file,line:i,name:`@${r.name}`,value:Rt(s)})}),n}function Ni(t,e=2){let n=t.flatMap(fu),r=new Map,s=new Map;for(let a of n){let c=r.get(a.value);c?c.push(a):r.set(a.value,[a]);let l=s.get(a.name);l?l.push(a):s.set(a.name,[a])}let i=(a,c)=>({file:a.file,startLine:a.line,endLine:a.line,name:a.name,...c?{value:a.value}:{}}),o=[];for(let a of r.values())a.length<e||o.push({occurrences:a.map(c=>i(c,!1)),lines:1,tokens:1,kind:"definition",defKind:"cssVar"});for(let a of s.values())a.length<e||new Set(a.map(l=>l.value)).size<2||o.push({occurrences:a.map(l=>i(l,!0)),lines:1,tokens:1,kind:"definition",defKind:"cssVar",signals:["value-drift"]});return o}function Ri(t){let e=t.length,n=[],r=[{lcpLength:0,low:0}];for(let s=1;s<e;s++){let i=s-1;for(;t[s]<r[r.length-1].lcpLength;){let o=r.pop();n.push({lcpLength:o.lcpLength,low:o.low,high:s-1}),i=o.low}t[s]>r[r.length-1].lcpLength&&r.push({lcpLength:t[s],low:i})}for(;r.length>1;){let s=r.pop();n.push({lcpLength:s.lcpLength,low:s.low,high:e-1})}return n}var mu={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{line:["//"],block:[["/*","*/"]]},java:{line:["//"],block:[["/*","*/"]]},kotlin:{line:["//"],block:[["/*","*/"]]},scala:{line:["//"],block:[["/*","*/"]]},groovy:{line:["//"],block:[["/*","*/"]]},css:{block:[["/*","*/"]]},scss:{line:["//"],block:[["/*","*/"]]},less:{line:["//"],block:[["/*","*/"]]},stylus:{line:["//"],block:[["/*","*/"]]},python:{line:["#"]},gherkin:{line:["#"]},coffeescript:{line:["#"],block:[["###","###"]]},livescript:{line:["#"],block:[["###","###"]]},lua:{line:["--"],block:[["--[[","]]"]]},markdown:{block:[["<!--","-->"]]}};function Pi(t,e,n){let r=t.slice(e,n).replace(/[^\n]/g," ");return t.slice(0,e)+r+t.slice(n)}function gu(t,e){if(!e)return t;let n=t;for(let[r,s]of e.block??[]){let i=0;for(;;){let o=n.indexOf(r,i);if(o===-1)break;let a=n.indexOf(s,o+r.length),c=a===-1?n.length:a+s.length;n=Pi(n,o,c),i=c}}for(let r of e.line??[]){let s=0;for(;;){let i=n.indexOf(r,s);if(i===-1)break;let o=n.indexOf(`
21
+ `,i),a=o===-1?n.length:o;n=Pi(n,i,a),s=a}}return n}var du={typescript:[/^\s*import[\s{("*]/,/^\s*export\s.*\sfrom\s/],javascript:[/^\s*import[\s{("*]/,/^\s*export\s.*\sfrom\s/],python:[/^\s*import\s+\S/,/^\s*from\s+\S+\s+import[\s(]/],go:[/^\s*import\s+["(]/],java:[/^\s*import\s+/],kotlin:[/^\s*import\s+/],scala:[/^\s*import\s+/],groovy:[/^\s*import\s+/]};function hu(t,e){let n=du[e];if(!n)return t;let r=t.split(`
22
+ `),s=e==="go",i=!1,o=!1;for(let a=0;a<r.length;a++){let c=r[a],l=()=>{r[a]=c.replace(/[^\r]/g," ")};if(i){l(),c.includes(")")&&(i=!1);continue}if(o){l(),(/}\s*from\s/.test(c)||c.includes("}"))&&(o=!1);continue}n.some(p=>p.test(c))&&(l(),s&&/^\s*import\s+\(/.test(c)&&!c.includes(")")?i=!0:(e==="typescript"||e==="javascript")&&/^\s*import\b/.test(c)&&c.includes("{")&&!c.includes("}")&&(o=!0))}return r.join(`
23
+ `)}var Ai=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],Zn=new RegExp(`${Ai.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),yu=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Li=/^\d+(?:\.\d+)?$/,xu=/^(".*"|'.*'|`.*`)$/s,Ii=new Set(["if","else","elif","for","while","do","switch","case","default","break","continue","return","function","def","class","struct","interface","const","let","var","local","import","export","from","package","try","catch","except","finally","throw","raise","new","this","self","end","then","yield","async","await","nil","null","None","true","false","True","False","and","or","not","in","of","is"]),Su=new Set(["+","-","*","%","&","|","!","^","~","?"]),bu=new Set(Ai);function Mi(t){return t==="ID"||t==="NUM"||t==="STR"?!1:Ii.has(t)?!0:t.length===1?Su.has(t):bu.has(t)}function _i(t,e,n=!0){let r=hu(gu(t,mu[e]),e),s=[],i=1,o=0;Zn.lastIndex=0;let a=Zn.exec(r);for(;a!==null;){for(let p=o;p<a.index;p++)r[p]===`
24
+ `&&i++;o=a.index;let c=a[0],l=c;yu.test(c)&&!Ii.has(c)?l="ID":n&&(Li.test(c)||xu.test(c))&&(l=Li.test(c)?"NUM":"STR"),s.push({text:l,line:i});for(let p=o;p<a.index+c.length;p++)r[p]===`
25
+ `&&i++;o=a.index+c.length,a=Zn.exec(r)}return s}var ku=new Set(["{","}",":",",","[","]"]);function Gi(t,e,n){let r=0;for(let s=e;s<e+n;s++)ku.has(t[s].text)&&r++;return r/n}function Oi(t,e,n){let r=0;for(let s=e;s<e+n;s++)Mi(t[s].text)&&r++;return r}function ji(t){let e=t.length;if(e===0)return[];let n=Array.from({length:e},(i,o)=>o),r=new Array(e);{let i=[...new Set(t)].sort(),o=new Map(i.map((a,c)=>[a,c]));for(let a=0;a<e;a++)r[a]=o.get(t[a])}let s=new Array(e).fill(0);for(let i=1;i<e;i*=2){let o=a=>a+i<e?r[a+i]:-1;n.sort((a,c)=>{let l=r[a]-r[c];return l!==0?l:o(a)-o(c)}),s[n[0]]=0;for(let a=1;a<e;a++){let c=n[a-1],l=n[a],p=r[c]===r[l],u=o(c)===o(l);s[l]=s[c]+(p&&u?0:1)}if([r,s]=[s,r],r[n[e-1]]===e-1)break}return n}function $i(t,e){let n=t.length,r=new Array(n).fill(0);if(n===0)return r;let s=new Array(n);for(let o=0;o<n;o++)s[e[o]]=o;let i=0;for(let o=0;o<n;o++){let a=s[o];if(a>0){let c=e[a-1];for(;o+i<n&&c+i<n&&t[o+i]===t[c+i];)i++;r[a]=i,i>0&&i--}else i=0}return r}function Wi(t,e,n,r=.5){let s=[],i=[],o=new Map;for(let{file:m,tokens:d}of t)if(d.length!==0){o.set(m,d);for(let y=0;y<d.length;y++)s.push(d[y].text),i.push({file:m,localIndex:y});s.push(` ${m}`),i.push({file:m,localIndex:-1})}if(s.length===0)return[];let a=ji(s),c=$i(s,a),l=Ri(c),p=[];for(let m of l){let d=vu(m,a,i,o,e,n,r);d&&p.push(d)}return Cu(p,o).sort((m,d)=>d.lines-m.lines)}function vu(t,e,n,r,s,i,o){if(t.lcpLength<s)return;let a=[];for(let m=t.low;m<=t.high;m++){let d=n[e[m]];d.localIndex!==-1&&a.push(d)}if(a.length<2||!Eu(a,r))return;let c=wu(a,t.lcpLength);if(c.length<2)return;let l=c[0],p=r.get(l.file);if(!(Gi(p,l.localIndex,t.lcpLength)>o||Math.min(...c.map(({file:m,localIndex:d})=>{let y=r.get(m),k=y[d].line;return y[d+t.lcpLength-1].line-k+1}))<i))return{occurrences:c,lcpLength:t.lcpLength}}function Cu(t,e){let n=[...t].sort((i,o)=>o.lcpLength-i.lcpLength),r=new Map,s=[];for(let i of n){let o=i.occurrences.filter(({file:u,localIndex:m})=>{let d=m+i.lcpLength;return!r.get(u)?.some(k=>k.start<=m&&d<=k.end)});if(o.length<2)continue;for(let{file:u,localIndex:m}of o){let d={start:m,end:m+i.lcpLength},y=r.get(u);y?y.push(d):r.set(u,[d])}let a=o.map(({file:u,localIndex:m})=>{let d=e.get(u);return{file:u,startLine:d[m].line,endLine:d[m+i.lcpLength-1].line}}),c=Math.min(...a.map(u=>u.endLine-u.startLine+1)),l=o[0],p=Oi(e.get(l.file),l.localIndex,i.lcpLength);s.push({occurrences:a,lines:c,tokens:i.lcpLength,score:p})}return s}function Eu(t,e){let n=null;for(let{file:r,localIndex:s}of t){if(s===0)return!0;let o=e.get(r)[s-1].text;if(n===null)n=o;else if(n!==o)return!0}return!1}function wu(t,e){let n=new Map;for(let{file:s,localIndex:i}of t){let o=n.get(s);o?o.push(i):n.set(s,[i])}let r=[];for(let[s,i]of n){i.sort((a,c)=>a-c);let o=Number.NEGATIVE_INFINITY;for(let a of i)a>=o&&(r.push({file:s,localIndex:a}),o=a+e)}return r}var Tu=/<\/?\s*(?:svg|path|g|circle|ellipse|rect|line|polygon|polyline|defs|use|symbol|mask|clipPath|linearGradient|radialGradient|stop|pattern|filter|fe[A-Z][A-Za-z]*|marker|foreignObject|tspan|textPath)\b/,Fu=/\b(?:viewBox|xmlns(?::xlink)?|xlink:href|fill-rule|clip-rule|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-miterlimit|gradientUnits|gradientTransform|patternUnits|patternTransform|preserveAspectRatio|pathLength|d|points|cx|cy|rx|ry)\s*=/,Du=/^\s*(?:<\/?[A-Za-z>]|\/?>\s*$|[A-Za-z_$][\w:.$-]*\s*=\s*["'{])/;function zi(t,e,n,r=.6){let s=t.split(`
26
+ `).slice(Math.max(0,e-1),n),i=0,o=0,a=!1;for(let c of s){if(c.trim().length===0)continue;i++;let l=Tu.test(c)||Fu.test(c);l&&(a=!0),(l||Du.test(c))&&o++}return a&&i>0&&o/i>=r}import $ from"typescript";function Nu(t,e,n){if(!$.isPropertySignature(n)||!n.type)return;let r=n.name.getText(e),s=n.questionToken?"?":"",i=t.printNode($.EmitHint.Unspecified,n.type,e);return`${r}${s}:${i}`}function Ru(t){let e=t.filter(n=>n!==void 0);if(!(e.length<2||e.length!==t.length))return[...e].sort().join(";")}function Pu(t){let e=$.createSourceFile(t.file,t.source,$.ScriptTarget.Latest,!0,$.ScriptKind.TSX),n=$.createPrinter({removeComments:!0}),r=[],s=o=>e.getLineAndCharacterOfPosition(o).line+1,i=o=>{let a,c,l;if($.isInterfaceDeclaration(o)?(a=o.name.text,c="interface",l=o.members):$.isTypeAliasDeclaration(o)&&$.isTypeLiteralNode(o.type)&&(a=o.name.text,c="type",l=o.type.members),a&&c&&l){let p=Ru(l.map(u=>Nu(n,e,u)));p!==void 0&&r.push({file:t.file,name:a,defKind:c,startLine:s(o.getStart(e)),endLine:s(o.getEnd()),memberCount:l.length,canonicalShape:p})}$.forEachChild(o,i)};return i(e),r}function Bi(t,e=2){let n=new Map;for(let s of t)for(let i of Pu(s)){if(i.memberCount<e)continue;let o=n.get(i.canonicalShape);o?o.push(i):n.set(i.canonicalShape,[i])}let r=[];for(let s of n.values()){if(s.length<2)continue;let i=s[0],o=s.map(a=>({file:a.file,startLine:a.startLine,endLine:a.endLine,name:a.name}));r.push({occurrences:o,lines:Math.max(...s.map(a=>a.endLine-a.startLine+1)),tokens:i.memberCount,kind:"definition",defKind:i.defKind})}return r}import Lu from"crypto";import Ve from"fs";import Au from"path";function Ki(t){let e=[];for(let r of t)e.push(`${r.path}\0${r.mtime}\0${r.size}`);e.sort();let n=Lu.createHash("sha256");for(let r of e)n.update(`${r}
27
+ `);return n.digest("hex")}function Ui(t){return JSON.stringify({minLines:t.minLines,ignoreLiterals:t.ignoreLiterals,maxPunctuationRatio:t.maxPunctuationRatio,limit:t.limit,scope:t.scope??null,includeGenerated:t.includeGenerated,includeSameFile:t.includeSameFile,includeSvgMarkup:t.includeSvgMarkup,includeDocs:t.includeDocs,ignoreDirs:[...t.ignoreDirs].sort(),ignoreGlobs:[...t.ignoreGlobs].sort()})}function Iu(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.digest=="string"&&typeof e.paramsKey=="string"&&Array.isArray(e.groups)&&Array.isArray(e.clusters)}function Hi(t,e,n){try{if(!Ve.existsSync(t))return null;let r=JSON.parse(Ve.readFileSync(t,"utf-8"));return!Iu(r)||r.digest!==e||r.paramsKey!==n?null:{groups:r.groups,clusters:r.clusters}}catch{return null}}function Ji(t,e,n,r,s){try{let i=Au.dirname(t);Ve.existsSync(i)||Ve.mkdirSync(i,{recursive:!0});let o={digest:e,paramsKey:n,groups:[...r],clusters:[...s]};Ve.writeFileSync(t,JSON.stringify(o))}catch(i){process.stderr.write(`Warning: failed to persist duplication result cache: ${i}
28
+ `)}}function qn(t){let e=t.indexOf("/");return e===-1?".":t.slice(0,e)}function Vi(t){let e={};for(let n of t)e[n]=(e[n]??0)+1;return e}function Qi(t){return[...Qe(t)].sort().join("|")}function Yi(t,e){let n=new Set;for(let r of e)if(!(r.matchCount<2))for(let s of r.groups)n.add(Qi(s));return t.filter(r=>!n.has(Qi(r)))}function Xi(t){let e={},n=[],r=0;for(let s of t){s.lines>r&&(r=s.lines);for(let i of s.signals??[])n.push(i);for(let i of new Set(s.occurrences.map(o=>qn(o.file))))e[i]=(e[i]??0)+1}return{matched:t.length,byFamily:Vi(t.map(s=>s.family??"other")),byTopDir:e,bySignal:Vi(n),largestLines:r}}function Qe(t){return t.occurrences.map(e=>`${e.file}:${e.startLine}-${e.endLine}`)}function Zi(t){let e=t.package;return{lines:t.lines,...t.score!==void 0&&{score:t.score},...t.family!==void 0&&{family:t.family},...t.kind!==void 0&&{kind:t.kind},...t.defKind!==void 0&&{defKind:t.defKind},...t.signals!==void 0&&{signals:t.signals},...e!==void 0&&{package:e},occurrences:Qe(t)}}function qi(t){let e=t.package,n=t.groups[0];return{files:t.files,matchCount:t.matchCount,longestMatch:t.longestMatch,...n!==void 0&&{longestMatchAt:Qe(n)},coverage:t.coverage,...e!==void 0&&{package:e}}}import Ye from"fs";import Mu from"path";function _u(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mtime=="number"&&typeof e.size=="number"&&typeof e.ignoreLiterals=="boolean"&&typeof e.generated=="boolean"&&Array.isArray(e.tokens)}function Pt(t){try{if(!Ye.existsSync(t))return new Map;let e=Ye.readFileSync(t,"utf-8"),n=JSON.parse(e);if(!Array.isArray(n))return new Map;let r=n.filter(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string"&&_u(s[1]));return new Map(r)}catch{return new Map}}function Lt(t,e){let n=Mu.dirname(e);Ye.existsSync(n)||Ye.mkdirSync(n,{recursive:!0}),Ye.writeFileSync(e,JSON.stringify([...t.entries()]))}var Ou=20,ju=new Set(["css","scss","less"]),$u=/(?:^|\/)(?:__tests__|__mocks__|__snapshots__|tests?|e2e)\/|\.(?:test|spec)\.[^/]*$|\.snap$/,Wu=3,zu=6,Bu=120;function Ku(t){return Me.includes(Fe.basename(t))}function Uu(t,e){if(e.length===0)return!1;let n=new Set(e);return t.split(Fe.sep).some(r=>n.has(r))}function Te(t,e,n){let r=[...t.signals??[]];return new Set(t.occurrences.map(s=>s.file)).size===1&&r.push("same-file"),t.occurrences.some(s=>e.has(s.file))&&r.push("generated"),t.occurrences.some(s=>$u.test(s.file))&&r.push("test"),t.family==="markdown"&&r.push("docs"),t.occurrences.length>0&&t.occurrences.every(s=>{let i=n.get(s.file);return i!==void 0&&zi(i,s.startLine,s.endLine)})&&r.push("svg-markup"),r.length>0?{...t,signals:r}:t}function Hu(t){return Math.max(0,...t.groups.map(n=>n.tokens))>=Bu?!0:t.groups.length>=Wu&&t.files.length<=zu}function Ju(t,e){if(e==="all")return!0;let n=t.groups.some(r=>r.signals?.includes("test"));return e==="tests"?n&&Hu(t):!n}async function At(t,e,n={}){let{minLines:r=6,windowSize:s=15,ignoreLiterals:i=!0,maxPunctuationRatio:o=.5,limit:a=50,ignoreDirs:c=I,includeGenerated:l=!1,includeSameFile:p=!1,includeSvgMarkup:u=!1,includeDocs:m=!1,scope:d="src",minScore:y=0,ignoreGlobs:k=[],parallelTokenizing:b=!0,tokenCache:v,filter:L}=n,A=L?Dt(L):void 0,_=[...t.nodes.values()].filter(te=>te.type!=="unknown"&&!Ku(te.path)&&!Uu(te.path,c)),V=new Set,nn=new Map,nt=Vu(b,_.length);try{let te=[],Re=[],rn=new Map;if(await Promise.all(_.map(async x=>{let N=Nt(x.path,k);if(N&&!l)return;if(ju.has(x.type)){let G;try{G=await er(Fe.join(e,x.path),"utf8")}catch{return}let Mr=N||Je(G);if(Mr&&!l)return;Mr&&V.add(x.path),nn.set(x.path,G.split(`
29
+ `).length),te.push({file:x.path,source:G,fileType:x.type});return}let Q=v?.get(x.path),qo=Q&&Q.mtime===x.mtime&&Q.size===x.size&&Q.ignoreLiterals===i,Pe,de,Y;if(qo)Pe=Q.tokens,de=Q.generated;else{let G;try{G=await er(Fe.join(e,x.path),"utf8")}catch{return}if(de=N||Je(G),de&&!l)return;Pe=nt?await nt.run({source:G,fileType:x.type,ignoreLiterals:i}):_i(G,x.type,i),v?.set(x.path,{mtime:x.mtime,size:x.size,ignoreLiterals:i,generated:de,tokens:Pe}),Y=G}if(de&&!l)return;if(de&&V.add(x.path),nn.set(x.path,Y!==void 0?Y.split(`
30
+ `).length:Pe.at(-1)?.line??0),x.type==="typescript"||x.type==="javascript"){if(Y===void 0)try{Y=await er(Fe.join(e,x.path),"utf8")}catch{Y=void 0}Y!==void 0&&Re.push({file:x.path,source:Y})}let Lr=vi(x.type),Ar={file:x.path,tokens:Pe},Ir=rn.get(Lr);Ir?Ir.push(Ar):rn.set(Lr,[Ar])})),v){let x=new Set(_.map(N=>N.path));for(let N of v.keys())x.has(N)||v.delete(N)}let me=new Map(Re.map(x=>[x.file,x.source])),ge=Di(te,r).map(x=>Te(x,V,me));for(let[x,N]of rn)for(let Q of Wi(N,s,r,o))ge.push(Te({...Q,family:x},V,me));for(let x of Ni(te))ge.push(Te({...x,family:"style"},V,me));for(let x of Bi(Re))ge.push(Te({...x,family:"js"},V,me));for(let x of Fi(Re))ge.push(Te({...x,family:"js"},V,me));for(let x of Ti(Re))ge.push(Te({...x,family:"js"},V,me));let Rr=ge.filter(x=>!(!p&&x.signals?.includes("same-file")||!u&&x.signals?.includes("svg-markup")||!m&&x.signals?.includes("docs")||y>0&&(x.kind??"block")==="block"&&(x.score??x.tokens)<y||A&&!He(x,A))),Pr=ki(Rr,nn).filter(x=>Ju(x,d)),Zo=new Set(Pr.flatMap(x=>x.groups)),rt=x=>x.score??x.lines;return{groups:Rr.filter(x=>Zo.has(x)).sort((x,N)=>rt(N)-rt(x)||N.lines-x.lines).slice(0,a),clusters:Pr.sort((x,N)=>Math.max(...N.groups.map(rt))-Math.max(...x.groups.map(rt))||N.longestMatch-x.longestMatch).slice(0,a)}}finally{nt&&await nt.destroy()}}function Vu(t,e){if(t===!1)return null;let n=typeof t=="object"?t:{},r=n.minFiles??Ou;if(e<r)return null;n.maxThreads!==void 0&&n.maxThreads<1&&process.stderr.write(`
31
+ Warning: parallelTokenizing.maxThreads (${n.maxThreads}) must be at least 1; using 1.
32
+ `);try{return new Gu({filename:Fe.join(f,"duplication-worker.js"),...n.maxThreads!==void 0?{maxThreads:Math.max(1,n.maxThreads)}:{}})}catch(s){return process.stderr.write(`
26
33
  Warning: failed to start duplicate-detection worker pool, falling back to synchronous tokenizing: ${s}
27
- `),null}}var ee=class{affectedSymbols=new Map;constructor(e,r){this.affectedSymbols.set(e,new Set(["default",...r]))}updateAffectedSymbols(e,r){let n=this.affectedSymbols.get(r)||new Set,s=e.imports.find(c=>c.toPath===r);if(!s)return!1;let o=s.symbols||["*"],i=new Set;for(let c of o)(c==="*"||n.has("*")||n.has(c))&&i.add("*");if(i.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let c of i)a.add(c);return this.affectedSymbols.set(e.path,a),!0}};function Dl(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function Ml(t,e,r=1){let n=[];return t.traverse(e,(s,o,i)=>{if(s.path===e)return!0;let a=i?t.nodes.get(i)?.imports.find(c=>c.toPath===s.path):void 0;return n.push({path:s.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:r}),n}function yr(t,e){let r=[];return t.traverse(e,n=>{if(n.path===e)return!0;let s=n.imports.find(o=>o.toPath===e);return r.push({path:n.path,...s?.symbols?{symbols:s.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),r}function Al(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,o=s?new ee(e,s):null,i=[];return t.traverse(e,(a,c,l)=>{if(a.path===e)return!0;if(o&&l&&!o.updateAffectedSymbols(a,l))return!1;let p=a.category==="test"||a.tags.some(u=>u.name==="test");return(!n||p)&&i.push(a.path),!0},{direction:"incoming"}),i}function Ll(t,e,r={}){let{depth:n=1,withEdgeDetail:s=!1}=r,o=[];return t.traverseCalls(e,i=>{if(i.path===e)return!0;let a={file:i.path};return s&&(a.edges=(i.callEdges??[]).filter(c=>c.toFile===e).map(c=>({from:c.from,to:c.to}))),o.push(a),!0},{direction:"incoming",maxDepth:n}),o}function ct(t,e={}){let{metric:r="cognitiveComplexity",threshold:n=10,limit:s=20}=e;return[...t.nodes.values()].flatMap(o=>(o.functions??[]).filter(i=>i[r]>=n).map(i=>({file:o.path,name:i.name,line:i.line,complexity:i.complexity,cognitiveComplexity:i.cognitiveComplexity}))).sort((o,i)=>i[r]-o[r]).slice(0,s)}function _l(t){return{nodes:t.nodes.map(r=>({path:r.path,type:r.type,category:r.category,exports:r.exports.map(n=>n.name),tags:r.tags.filter(n=>n.kind==="comment-marker"||n.kind==="import").map(n=>n.name),importsFiles:r.imports.filter(n=>!n.isExternal&&n.toPath).map(n=>n.toPath),...r.description!==void 0&&{description:r.description},...r.testedBy!==void 0&&{testedBy:r.testedBy},...r.coveragePct!==void 0&&{coveragePct:r.coveragePct},...r.avgExportUsage!==void 0&&{avgExportUsage:r.avgExportUsage},...r.maxExportUsage!==void 0&&{maxExportUsage:r.maxExportUsage}})),cycles:t.cycles}}function Ol(t){let e=t.getPackageDependencies(),r=Array.from(t.packages.values()).map(({graph:n,pkg:s})=>({name:s.name,relativeRoot:s.relativeRoot,nodeCount:n.nodes.size,dependsOn:e.get(s.name)??[]}));return{monorepoType:t.type,packageCount:r.length,packages:r}}function lt(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function As(t){return[...t.nodes.values()].some(e=>e.commitCount90d!==void 0)}function pt(t,e={}){let{metric:r="cognitiveComplexity",minComplexity:n=10,maxCoveragePct:s=50,minChurn:o=0,limit:i=20}=e,a=As(t),c=[...t.nodes.values()].filter(l=>l.coveragePct!==void 0&&l.coveragePct<=s&&(!a||(l.commitCount90d??0)>=o)).flatMap(l=>(l.functions??[]).filter(p=>p[r]>=n).map(p=>({file:l.path,name:p.name,line:p.line,complexity:p.complexity,cognitiveComplexity:p.cognitiveComplexity,coveragePct:l.coveragePct,...l.commitCount90d!==void 0&&{commitCount90d:l.commitCount90d}}))).sort((l,p)=>p[r]-l[r]).slice(0,i);return{hotspots:c,count:c.length,churnDataAvailable:a}}import{execFileSync as Sr}from"child_process";import xr from"fs";import Gl from"os";import jl from"path";function br(t,e){try{return Sr("git",["rev-parse","--verify",`${e}^{commit}`],{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{throw new Error(`Could not resolve git ref "${e}" in ${t}`)}}async function Ls(t,e,r){let n=xr.mkdtempSync(jl.join(Gl.tmpdir(),`mokosh-worktree-${e.slice(0,12)}-`));xr.rmdirSync(n);try{return Sr("git",["worktree","add","--detach",n,e],{cwd:t,stdio:["ignore","pipe","pipe"]}),await r(n)}finally{try{Sr("git",["worktree","remove","--force",n],{cwd:t,stdio:["ignore","pipe","pipe"]})}catch{xr.rmSync(n,{recursive:!0,force:!0})}}}async function Ws(t,e,r,n={}){let s=br(t,e),o=on(t,s);if(o)return{sha:s,graph:o};let i=await Ls(t,s,async a=>{let c=n.pathAliases?new $(a,{pathAliases:n.pathAliases}):void 0;return new q(a,null,c,void 0,n.gitStats??!1,new Map,n.parallelParsing??!0,n.additionalIgnoreDirs??[]).build(r)});return an(t,s,i),{sha:s,graph:i}}var _s=t=>Math.round(t*100)/100,Os=t=>t.length>8?t.slice(0,8):t;function Wl(t,e){return`${t.file}:${t.line} ${t.name} (${t[e]})`}function zl(t,e){return`${t.file}:${t.line} ${t.name} (${t[e]}, cov ${t.coveragePct}%)`}function Bl(t,e=4){let r=t.occurrences.slice(0,e).map(o=>`${o.file}:${o.startLine}-${o.endLine}`),n=t.occurrences.length-r.length,s=n>0?`, +${n} more`:"";return`${t.lines}L x${t.occurrences.length}: ${r.join(", ")}${s}`}var te=(t,e)=>`${t} ${e}${t===1?"":"s"}`;function Hl(t,e){let{files:r,staleReferences:n,duplication:s,complexity:o,docDrift:i,coverage:a}=t,c=[],l=[r.added.length&&`${r.added.length} added`,r.changed.length&&`${r.changed.length} changed`,r.removed.length&&`${r.removed.length} removed`].filter(Boolean);c.push(l.length?`Files: ${l.join(", ")}`:"No file changes"),n.length>0&&c.push(`\u26A0 ${te(n.length,"stale reference")} \u2014 removed export still imported`);let p=o.newHotspots[0];return p?c.push(`+${te(o.newHotspots.length,"complexity hotspot")} (max ${e} ${p[e]} in ${p.file})`):o.resolvedHotspots.length>0&&c.push(`${te(o.resolvedHotspots.length,"complexity hotspot")} resolved`),s.newGroups.length>0?c.push(`+${te(s.newGroups.length,"duplication group")}`):s.resolvedGroups.length>0&&c.push(`${te(s.resolvedGroups.length,"duplication group")} resolved`),i.newlyStale.length>0&&c.push(`${te(i.newlyStale.length,"doc")} newly stale`),a&&a.newHotspots.length>0&&c.push(`+${te(a.newHotspots.length,"risk hotspot")}`),c}function Ul(t){let{staleReferences:e,duplication:r,complexity:n,docDrift:s,coverage:o}=t;return e.length>0||(o?.newHotspots.length??0)>0?"attention":n.newHotspots.length>0||r.newGroups.length>0||s.newlyStale.length>0?"review-worthy":"clean"}function Kl(t,e={}){let r=e.metric??"cognitiveComplexity",n=e.maxItems??8,s=e.maxPathList??100,{files:o,staleReferences:i,duplication:a,complexity:c,docDrift:l,coverage:p}=t,u=_s(c.head.avgCognitiveComplexity-c.base.avgCognitiveComplexity),g=o.added.length+o.changed.length+o.removed.length,d={base:`${t.base.ref}@${Os(t.base.sha)}`,head:`${t.head.ref}@${Os(t.head.sha)}`,verdict:Ul(t),headline:Hl(t,r),files:{added:o.added.length,changed:o.changed.length,removed:o.removed.length,...g<=s?{paths:{added:o.added,changed:o.changed,removed:o.removed}}:{}}};return i.length>0&&(d.staleReferences=i),(c.newHotspots.length>0||c.resolvedHotspots.length>0)&&(d.complexity={avgDelta:u,newHotspots:c.newHotspots.slice(0,n).map(y=>Wl(y,r)),newHotspotCount:c.newHotspots.length,resolvedCount:c.resolvedHotspots.length}),(a.newGroups.length>0||a.resolvedGroups.length>0)&&(d.duplication={newGroups:a.newGroups.slice(0,n).map(y=>Bl(y)),newGroupCount:a.newGroups.length,resolvedCount:a.resolvedGroups.length,totalGroups:a.head.groups}),(l.newlyStale.length>0||l.resolved.length>0)&&(d.docDrift={newlyStale:l.newlyStale.slice(0,n).map(y=>y.replace("::"," \u2192 ")),newlyStaleCount:l.newlyStale.length,resolvedCount:l.resolved.length}),p&&(p.newHotspots.length>0||p.resolvedHotspots.length>0)&&(d.coverage={avgDelta:_s(p.head.avgCoveragePct-p.base.avgCoveragePct),newHotspots:p.newHotspots.slice(0,n).map(y=>zl(y,r)),newHotspotCount:p.newHotspots.length,resolvedCount:p.resolvedHotspots.length}),d}function Jl(t,e){let r=[],n=[];for(let[o,i]of e.nodes){let a=t.nodes.get(o);if(!a){r.push(o);continue}let c=JSON.stringify({category:a.category,exports:a.exports.map(p=>p.name).sort(),imports:a.imports.map(p=>p.toPath).sort()}),l=JSON.stringify({category:i.category,exports:i.exports.map(p=>p.name).sort(),imports:i.imports.map(p=>p.toPath).sort()});c!==l&&n.push(o)}let s=[...t.nodes.keys()].filter(o=>!e.nodes.has(o));return{added:r,removed:s,changed:n}}function Vl(t,e){let r=[];for(let[n,s]of t.nodes){let o=e.nodes.get(n);if(!o)continue;let i=new Set(o.exports.map(c=>c.name)),a=s.exports.map(c=>c.name).filter(c=>!i.has(c));if(a.length!==0)for(let c of a){let l=[...e.nodes.values()].filter(p=>p.imports.some(u=>u.toPath===n&&u.symbols?.includes(c))).map(p=>p.path);l.length>0&&r.push({file:n,symbol:c,stillReferencedBy:l})}}return r}function ut(t){return t.occurrences.map(e=>`${e.file}:${e.startLine}-${e.endLine}`).sort().join("|")}async function Yl(t,e,r,n,s){let o=$l.join(ze(t),`${n}-${$t}`),i=ot(o),[{groups:a},{groups:c}]=await Promise.all([at(e,t,{minLines:s,tokenCache:i}),at(r,t,{minLines:s})]);it(i,o);let l=new Set(a.map(ut)),p=new Set(c.map(ut));return{base:{groups:a.length},head:{groups:c.length},newGroups:c.filter(u=>!l.has(ut(u))),resolvedGroups:a.filter(u=>!p.has(ut(u)))}}function Gs(t){let e=[...t.nodes.values()].map(r=>r.cognitiveComplexity).filter(r=>r!==void 0);return e.length===0?0:e.reduce((r,n)=>r+n,0)/e.length}function Ql(t,e,r,n){let s=ct(t,{metric:r,threshold:n,limit:1/0}),o=ct(e,{metric:r,threshold:n,limit:1/0}),i=l=>`${l.file}:${l.name}`,a=new Set(s.map(i)),c=new Set(o.map(i));return{base:{avgCognitiveComplexity:Gs(t)},head:{avgCognitiveComplexity:Gs(e)},newHotspots:o.filter(l=>!a.has(i(l))),resolvedHotspots:s.filter(l=>!c.has(i(l)))}}function js(t){let e=new Set;for(let r of t.nodes.values())if(!(r.type!=="markdown"||!r.staleFor))for(let n of r.staleFor)e.add(`${r.path}::${n}`);return e}function Xl(t,e){let r=js(t),n=js(e);return{base:{staleCount:r.size},head:{staleCount:n.size},newlyStale:[...n].filter(s=>!r.has(s)),resolved:[...r].filter(s=>!n.has(s))}}function $s(t){let e=[...t.nodes.values()].map(r=>r.coveragePct).filter(r=>r!==void 0);return e.length===0?0:e.reduce((r,n)=>r+n,0)/e.length}function Zl(t,e,r){if(!lt(t)||!lt(e))return null;let n=pt(t,{maxCoveragePct:r,limit:1/0}).hotspots,s=pt(e,{maxCoveragePct:r,limit:1/0}).hotspots,o=c=>`${c.file}:${c.name}`,i=new Set(n.map(o)),a=new Set(s.map(o));return{base:{avgCoveragePct:$s(t)},head:{avgCoveragePct:$s(e)},newHotspots:s.filter(c=>!i.has(o(c))),resolvedHotspots:n.filter(c=>!a.has(o(c)))}}async function ql(t,e,r,n={}){let{sha:s,graph:o}=await Ws(t,e,n.entryPoints??[],n),i=br(t,n.headRef??"HEAD"),[a,c]=await Promise.all([Yl(t,o,r,s,n.minDuplicateLines),Promise.resolve(Zl(o,r,n.maxCoveragePct))]);return{base:{ref:e,sha:s},head:{ref:n.headRef??"HEAD",sha:i},files:Jl(o,r),staleReferences:Vl(o,r),duplication:a,complexity:Ql(o,r,n.complexityMetric,n.complexityThreshold),docDrift:Xl(o,r),coverage:c}}import mt from"path";function ep(t){let e=new Map;for(let[r,n]of t){let s=n.imports.filter(o=>o.toPath&&!o.isExternal).length;s>0&&e.set(r,s)}return e}function tp(t,e,r){let n=new Map;for(let[s,o]of e){if(o<r)continue;let i=t.get(s);if(!i||i.category==="test"||i.category==="barrel")continue;let a=mt.extname(s),c=mt.basename(s,a),l=c==="index"?mt.basename(mt.dirname(s)):c;n.set(s,{path:s,outDegree:o,tag:`feature:${l}`})}return n}function De(t,e){let r=e?.minOutDegree??5;return tp(t,ep(t),r)}var rp=(t,e)=>t.outDegree-e.outDegree;function np(t,e){let r=new Map;for(let n of e.values()){let s=new Set;t.traverse(n.path,o=>(o.path!==n.path&&s.add(o.path),!0),{direction:"outgoing"}),r.set(n.path,s)}return r}function sp(t,e,r,n){let s=new Map;for(let[o]of t){if(e.has(o))continue;let i=null;for(let a of e.values())r.get(a.path)?.has(o)&&(!i||n(a,i)<0)&&(i=a);i&&s.set(o,i.path)}return s}function op(t,e){let r=new Map;for(let n of t.values()){let s=n.tag.replace("feature:",""),o=[];for(let[i,a]of e)a===n.path&&o.push(i);r.set(s,{hub:n.path,outDegree:n.outDegree,files:o})}return r}function ip(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function kr(t,e){let r=e?.detectFn??De,n=e?.hubComparator??rp,s=r(t.nodes,e),o=np(t,s),i=sp(t.nodes,s,o,n);return{features:op(s,i),unassigned:ip(t.nodes,s,i)}}var ap=[{role:"component",segments:["component","components"]},{role:"controller",segments:["controller","controllers"]},{role:"middleware",segments:["middleware"]},{role:"router",segments:["router","routes","route"]},{role:"store",segments:["store","stores"]},{role:"service",segments:["service","services"]},{role:"handler",segments:["handler","handlers"]},{role:"adapter",segments:["adapter","adapters"]},{role:"plugin",segments:["plugin","plugins"]},{role:"api",segments:["api"]},{role:"cli",segments:["cli","commands"],basenames:["cli"]},{role:"util",segments:["util","utils","helper","helpers"]},{role:"model",segments:["model","models"],basenames:["model"]},{role:"parser",segments:["parser","parsers"],basenames:["parser"]},{role:"builder",basenames:["builder"]},{role:"resolver",basenames:["resolver"]}];function zs(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path,r=lp(e);for(let n of ap)if(n.segments?.some(s=>cp(e,s))||n.basenames?.includes(r))return n.role;return"other"}function cp(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function lp(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function pp(t,e){let r=kr(t,e),n=new Map;for(let[o,i]of r.features){for(let a of i.files)n.set(a,o);n.set(i.hub,o)}let s=new Map;for(let o of t.nodes.values()){let i=n.get(o.path);s.set(o.path,{path:o.path,role:zs(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return s}function up(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(qe.has(n.type)){let s=[];for(let o of t.nodes.values())for(let i of o.callEdges??[])i.to===e&&s.push({file:o.path,callerFunction:i.from});r.push({path:n.path,category:n.category,precision:"call",callers:s})}else{let s=yr(t,n.path).map(o=>({file:o.path,...o.symbols?{symbols:o.symbols}:{}}));r.push({path:n.path,category:n.category,precision:"file-level",importers:s})}return r}function mp(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function fp(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function gp(t){let e=new Map;for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript"))for(let s of n.exports){if(!fp(s,n.category))continue;let o=`${n.path}::${s.name}`;e.set(o,{name:s.name,file:n.path,kind:mp(s.signature),...s.doc?{doc:s.doc}:{}})}let r=[];for(let n of t.nodes.values())if(!(n.type!=="typescript"&&n.type!=="javascript")){for(let s of n.imports)if(!(!s.toPath||s.isExternal||!s.symbols?.length))for(let o of s.symbols)e.has(`${s.toPath}::${o}`)&&r.push({fromFile:n.path,toType:o,toFile:s.toPath})}return{types:e,edges:r}}function dp(t,e){let r=null;for(let o of t.types.values())if(o.name===e){r=o;break}if(!r)return{type:null,usedByFiles:[],uses:[]};let n=new Set,s=new Map;for(let o of t.edges)if(o.toType===e&&o.toFile===r.file&&n.add(o.fromFile),o.fromFile===r.file){let i=t.types.get(`${o.toFile}::${o.toType}`);i&&s.set(`${i.file}::${i.name}`,i)}return{type:r,usedByFiles:Array.from(n),uses:Array.from(s.values())}}import Gp from"path";import Us from"fs";import Ks from"path";import hp from"fs";import vr from"path";import Bs from"fs";import wx from"path";function ft(t){try{return Bs.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function gt(t){try{return Bs.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var yp=new Set([".java",".kt",".kts",".scala",".sc",".groovy",".gradle"]),xp=new Set(I);function Hs(t,e=[]){let r;try{r=hp.readdirSync(t,{withFileTypes:!0})}catch{return e}for(let n of r){let s=vr.join(t,n.name);n.isDirectory()?!xp.has(n.name)&&!n.name.startsWith(".")&&Hs(s,e):n.isFile()&&yp.has(vr.extname(n.name).toLowerCase())&&e.push(s)}return e}function dt(t,e,r){if(!ft(e))return null;let n=Hs(e);return n.length===0?null:{name:r,root:e,relativeRoot:vr.relative(t,e),entryPoints:n}}function Sp(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"")}function bp(t){let e=Sp(t),r=new Set;for(let n of e.matchAll(/['"](:[A-Za-z0-9_\-.:]+)['"]/g)){let s=n[1].replace(/^:/,"").replace(/:$/,"");s&&r.add(s)}return[...r]}var Js={type:"gradle",detect(t){let e=["settings.gradle.kts","settings.gradle"].map(o=>Ks.join(t,o)).find(o=>Us.existsSync(o));if(!e)return null;let r;try{r=Us.readFileSync(e,"utf-8")}catch{return null}let n=bp(r);if(n.length===0)return null;let s=[];for(let o of n){let i=Ks.join(t,...o.split(":")),a=dt(t,i,o);a&&s.push(a)}return s.length>0?s:null}};import wr from"fs";import Ys from"path";import Me from"fs";import P from"path";function Cr(t,e){let r=P.join(e,"package.json");if(!Me.existsSync(r))return null;let n={};try{n=JSON.parse(Me.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:P.relative(t,e),entryPoints:kp(e,n)}:null}function kp(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(P.join(t,s));else if(typeof s=="object"&&s!==null){let o=s["."];if(typeof o=="string")r.push(P.join(t,o));else if(typeof o=="object"&&o!==null){let i=o.import??o.require??o.default;typeof i=="string"&&r.push(P.join(t,i))}}}e.main&&r.push(P.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(P.join(t,s));let n=r.filter(gt);return n.length>0?n.slice(0,1):r.slice(0,1)}function ge(t,e){let r=[],n=new Set;for(let s of e){let o=s.replace(/\/$/,"").replace(/^\.\//,"");vp(t,o,n,r)}return r}function vp(t,e,r,n){if(!e.includes("*")){Cp(t,e,r,n);return}let s=e.split("/");s.includes("**")?wp(t,s,r,n):Ep(t,s,r,n)}function Cp(t,e,r,n){let s=P.join(t,e);if(r.has(s)||!ft(s))return;r.add(s);let o=Cr(t,s);o&&n.push(o)}function wp(t,e,r,n){let s=P.join(t,e[0]==="**"?"":e[0]??"");Vs(t,s,r,n)}function Ep(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),o=P.join(t,...e.slice(0,s)),i;try{i=Me.readdirSync(o,{withFileTypes:!0})}catch{return}for(let a of i){if(!a.isDirectory())continue;let c=P.join(o,a.name);if(r.has(c))continue;r.add(c);let l=Cr(t,c);l&&n.push(l)}}function Vs(t,e,r,n){let s;try{s=Me.readdirSync(e,{withFileTypes:!0})}catch{return}for(let o of s){if(!o.isDirectory()||o.name==="node_modules"||o.name.startsWith("."))continue;let i=P.join(e,o.name);if(Me.existsSync(P.join(i,"package.json"))&&!r.has(i)){r.add(i);let a=Cr(t,i);a&&n.push(a)}else Vs(t,i,r,n)}}var Qs={type:"npm",detect(t){let e=Ys.join(t,"package.json");if(!wr.existsSync(e))return null;let r;try{r=JSON.parse(wr.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||wr.existsSync(Ys.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:ge(t,n)}};import de from"fs";import T from"path";var Xs={type:"nx",detect(t){return de.existsSync(T.join(t,"nx.json"))?Zs(t,t,new Set,0).map(r=>Tp(t,r,T.join(r,"project.json"))).filter(r=>r!==null):null}};function Zs(t,e,r,n){if(n>4)return[];let s;try{s=de.readdirSync(e,{withFileTypes:!0})}catch{return[]}let o=[];for(let i of s){if(!i.isDirectory())continue;let a=i.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let c=T.join(e,a);de.existsSync(T.join(c,"project.json"))&&!r.has(c)?(r.add(c),o.push(c)):o.push(...Zs(t,c,r,n+1))}return o}function Tp(t,e,r){let n={};try{n=JSON.parse(de.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,o,i,a=T.join(e,"package.json");if(de.existsSync(a))try{let c=JSON.parse(de.readFileSync(a,"utf-8"));s=c.name??s,o=c.main,i=c.exports}catch{}return s?{name:s,root:e,relativeRoot:T.relative(t,e),entryPoints:Fp(e,n,o,i)}:null}function Fp(t,e,r,n){let s=[],o=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(o){let a=T.resolve(t,"../..");s.push(T.resolve(a,o)),s.push(T.resolve(t,o))}if(n){let a=n;if(typeof a=="string")s.push(T.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(T.join(t,c))}}if(r&&s.push(T.join(t,r)),e.sourceRoot){let a=T.resolve(t,"../.."),c=T.resolve(a,e.sourceRoot);s.push(T.join(c,"index.ts"),T.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(T.join(t,a));let i=s.filter(gt);return i.length>0?i.slice(0,1):s.slice(0,1)}import qs from"fs";import Np from"path";import{load as Pp}from"js-yaml";var eo={type:"pnpm",detect(t){let e=Np.join(t,"pnpm-workspace.yaml");if(!qs.existsSync(e))return null;let r=[];try{r=Pp(qs.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return ge(t,r)}};import Ae from"fs";import ht from"path";function Rp(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"")}function Ip(t){let e=Rp(t),r=new Map;for(let n of e.matchAll(/(?:lazy\s+)?val\s+([A-Za-z0-9_]+)\s*=\s*\(?\s*project\b([^\n]*)/g)){let s=n[1],i=n[2].match(/\bfile\s*\(\s*["']([^"']+)["']\s*\)/),a=i?i[1]:s;if(a==="."||a==="./")continue;let c=a.replace(/^\.\//,"").replace(/\/$/,"");r.has(c)||r.set(c,{name:s,dir:c})}return[...r.values()]}var to={type:"sbt",detect(t){let e=ht.join(t,"build.sbt"),r=ht.join(t,"project");if(!Ae.existsSync(e)||!Ae.existsSync(r))return null;let n=[];try{n.push(Ae.readFileSync(e,"utf-8"))}catch{return null}try{for(let a of Ae.readdirSync(r))a.endsWith(".scala")&&n.push(Ae.readFileSync(ht.join(r,a),"utf-8"))}catch{}let s=new Set,o=[];for(let a of n)for(let c of Ip(a))s.has(c.dir)||(s.add(c.dir),o.push(c));if(o.length===0)return null;let i=[];for(let a of o){let c=ht.join(t,...a.dir.split("/")),l=dt(t,c,a.name);l&&i.push(l)}return i.length>0?i:null}};import Dp from"fs";import Mp from"path";var ro={type:"turborepo",detect(t){return Dp.existsSync(Mp.join(t,"turbo.json"))?[]:null}};import Er from"fs";import no from"path";var so={type:"yarn",detect(t){if(!Er.existsSync(no.join(t,"yarn.lock")))return null;let e=no.join(t,"package.json");if(!Er.existsSync(e))return null;let r;try{r=JSON.parse(Er.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r)return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:ge(t,n)}};var oo=[];function M(t){oo.push(t)}function io(){return oo}import Ap from"fs";import Lp from"path";var _p=["dependencies","devDependencies","peerDependencies","optionalDependencies"];function Op(t){try{let e=Ap.readFileSync(Lp.join(t,"package.json"),"utf-8"),r=JSON.parse(e),n=new Set;for(let s of _p){let o=r[s];if(o&&typeof o=="object")for(let i of Object.keys(o))n.add(i)}return n}catch{return null}}function ao(t,e){if(e){let o=e.getPackageDependencies(),i=Array.from(e.packages.values()).map(({graph:a,pkg:c})=>({name:c.name,relativeRoot:c.relativeRoot,dependsOn:o.get(c.name)??[],nodeCount:a.nodes.size}));return{monorepoType:t.type,monorepoTypes:t.types,packageCount:i.length,packages:i,dependsOnResolved:!0,nodeCountsResolved:!0}}let r=new Set(t.packages.map(o=>o.name)),n=!0,s=t.packages.map(o=>{let i=Op(o.root);if(i===null)return n=!1,{name:o.name,relativeRoot:o.relativeRoot,dependsOn:[]};let a=[...i].filter(c=>c!==o.name&&r.has(c)).sort();return{name:o.name,relativeRoot:o.relativeRoot,dependsOn:a}});return{monorepoType:t.type,monorepoTypes:t.types,packageCount:s.length,packages:s,dependsOnResolved:n,nodeCountsResolved:!1,note:"Layout only \u2014 per-package node counts and (for build-system monorepos without package.json) dependency edges require a full graph. Call analyze with empty entryPoints, then get_workspace_packages again."}}M(ro);M(Xs);M(eo);M(so);M(Qs);M(Js);M(to);function Tr(t,e=io()){let r=Gp.resolve(t),n=new Map,s=[];for(let i of e){let a=i.detect(r);if(a!==null){s.push(i.type);for(let c of a)n.has(c.name)||n.set(c.name,c)}}if(s.length===0)return{root:r,type:"none",types:[],packages:[],packageMap:new Map};let o=Array.from(n.values());return{root:r,type:s[0],types:s,packages:o,packageMap:new Map(o.map(i=>[i.name,i]))}}var Le=class t{constructor(e,r){this.monorepoRoot=e;this.type=r}monorepoRoot;type;packages=new Map;addPackage(e,r){this.packages.set(e.name,{graph:r,pkg:e})}annotateCrossPackageEdges(){for(let{graph:e}of this.packages.values())for(let r of e.nodes.values()){let n=this.getPackageForFile(r.path);if(n)for(let s of r.imports){if(s.isExternal||s.isWorkspace)continue;let o=this.getPackageForFile(s.toPath);o&&o.name!==n.name&&(s.isWorkspace=!0,s.workspacePackage=o.name)}}}getPackageForFile(e){for(let{pkg:r}of this.packages.values())if(e===r.relativeRoot||e.startsWith(`${r.relativeRoot}/`))return r}getPackageDependencies(){let e=new Map;for(let{graph:r,pkg:n}of this.packages.values()){let s=new Set;for(let o of r.nodes.values())for(let i of o.imports)i.isWorkspace&&i.workspacePackage&&s.add(i.workspacePackage);e.set(n.name,[...s])}return e}getAffectedAcrossPackages(e){let r=this.getPackageForFile(e);if(!r)return[];let n=this.packages.get(r.name);if(!n)return[];let s=[];n.graph.traverse(e,o=>(o.path!==e&&s.push({file:o.path,package:r.name}),!0),{direction:"incoming"});for(let{graph:o,pkg:i}of this.packages.values())if(i.name!==r.name)for(let a of o.nodes.values())a.imports.some(l=>l.isWorkspace&&l.workspacePackage===r.name)&&s.push({file:a.path,package:i.name});return s}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:r})=>({pkg:{name:r.name,relativeRoot:r.relativeRoot,entryPoints:r.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let r=new t(e.monorepoRoot,e.type);for(let{pkg:n,nodes:s}of e.packages){let o=new Map(s.map(a=>[a.path,a])),i=new L(o);r.packages.set(n.name,{graph:i,pkg:{...n,root:""}})}return r}};function co(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function jp(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var $p=(t,e)=>!e.category||co(t.category,e.category),Wp=(t,e)=>!e.type||co(t.type,e.type),zp=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,Bp=(t,e)=>!e.path||jp(t.path,e.path),Hp=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,Up=(t,e)=>{if(!e.tags||e.tags.length===0)return!0;let r=e.tags.filter(s=>!s.startsWith("!")),n=e.tags.filter(s=>s.startsWith("!")).map(s=>s.slice(1));return!(r.length>0&&!r.some(s=>t.tags.some(o=>o.name===s))||n.some(s=>t.tags.some(o=>o.name===s)))},Kp=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),Jp=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),Vp=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),Yp=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,Qp=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,Xp=(t,e)=>e.minSize===void 0||t.size>=e.minSize,Zp=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,qp=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,eu=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,tu=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,ru=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,nu=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,su=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,ou=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,iu=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,au=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,cu=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,lu=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,pu=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,uu=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,mu=(t,e,r)=>!e.any?.length||e.any.some(n=>_e(t,n,r)),fu=[$p,Wp,zp,Bp,Hp,Up,Kp,Jp,Vp,Yp,Qp,Xp,Zp,qp,eu,tu,ru,nu,su,ou,iu,au,cu,lu,pu,uu,mu];function _e(t,e,r){return fu.every(n=>n(t,e,r))}function lo(t,e){let r=new Map;if(e.importedBy!==void 0){for(let i of t.nodes)for(let a of i.imports)if(a.toPath){let c=r.get(a.toPath)??[];c.push(i.path),r.set(a.toPath,c)}}let n=t.nodes.filter(i=>_e(i,e,r)),s=new Set(n.map(i=>i.path)),o=n.map(i=>({...i,imports:i.imports.filter(a=>!a.toPath||s.has(a.toPath))}));if(e.sort){let i=e.sortDir==="asc"?-1:1;o.sort((a,c)=>{let l=0;switch(e.sort){case"size":l=c.size-a.size;break;case"imports":l=c.imports.length-a.imports.length;break;case"commitCount90d":l=(c.commitCount90d??0)-(a.commitCount90d??0);break;case"exportUsage":l=(c.avgExportUsage??0)-(a.avgExportUsage??0);break;case"complexity":l=(c.complexity??0)-(a.complexity??0);break;case"cognitiveComplexity":l=(c.cognitiveComplexity??0)-(a.cognitiveComplexity??0);break}return l*i})}return e.limit!==void 0&&o.splice(e.limit),{nodes:o,cycles:t.cycles?.filter(i=>i.every(a=>s.has(a)))??void 0}}var gu={category:{field:"category",kind:"string"},type:{field:"type",kind:"string"},path:{field:"path",kind:"string"},importsfile:{field:"importsFile",kind:"string"},importedby:{field:"importedBy",kind:"string"},lastauthor:{field:"lastAuthor",kind:"string"},external:{field:"isExternal",kind:"boolIsTrue"},hasdocstring:{field:"hasDocstring",kind:"boolNotFalse"},isdocumented:{field:"isDocumented",kind:"boolNotFalse"},isstale:{field:"isStale",kind:"boolNotFalse"},minimports:{field:"minImports",kind:"int"},maximports:{field:"maxImports",kind:"int"},minsize:{field:"minSize",kind:"int"},maxsize:{field:"maxSize",kind:"int"},limit:{field:"limit",kind:"int"},mincoverage:{field:"minCoverage",kind:"int"},maxcoverage:{field:"maxCoverage",kind:"int"},minexportusage:{field:"minExportUsage",kind:"float"},maxexportusage:{field:"maxExportUsage",kind:"float"},mincomplexity:{field:"minComplexity",kind:"int"},maxcomplexity:{field:"maxComplexity",kind:"int"},mincognitivecomplexity:{field:"minCognitiveComplexity",kind:"int"},maxcognitivecomplexity:{field:"maxCognitiveComplexity",kind:"int"},mincommits:{field:"minCommits",kind:"int"},maxcommits:{field:"maxCommits",kind:"int"}};function du(t,e,r,n){let s=t;switch(r){case"string":s[e]=n;break;case"int":s[e]=parseInt(n,10);break;case"float":s[e]=parseFloat(n);break;case"boolNotFalse":s[e]=n.toLowerCase()!=="false";break;case"boolIsTrue":s[e]=n.toLowerCase()==="true";break}}function uo(t,e){let r=e.indexOf(":");if(r===-1)return;let n=e.slice(0,r).trim().toLowerCase(),s=e.slice(r+1).trim();if(!n||!s)return;if(n==="tag"||n==="tags"){s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];return}if(n==="sort"){t.sort=s;return}if(n==="sortdir"){t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";return}let o=gu[n];o&&du(t,o.field,o.kind,s)}function hu(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};uo(s,n),Object.keys(s).length>0&&e.push(s)}return e}var po="any(";function mo(t){let e={},r=t.split(",");for(let n of r){let s=n.trim();if(s.toLowerCase().startsWith(po)&&s.endsWith(")")){let o=s.slice(po.length,-1),i=hu(o);i.length>0&&(e.any=[...e.any??[],...i]);continue}uo(e,n)}return e}import Co from"fs/promises";import tm from"path";import Wr from"path";import Ft from"typescript";import Su from"path";import yu from"path";import E from"typescript";var fo=new Set(["describe","test","it"]);function re(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function Fr(t){let e=[];for(let r of t.statements){if(!E.isExpressionStatement(r))continue;let n=r.expression;if(!E.isCallExpression(n))continue;let s=n.expression;E.isIdentifier(s)&&fo.has(s.text)&&e.push(n),E.isPropertyAccessExpression(s)&&E.isIdentifier(s.expression)&&fo.has(s.expression.text)&&e.push(n)}return e}function Nr(t,e,r){for(let n of t.arguments){if(!E.isObjectLiteralExpression(n))continue;let s=n.properties.find(o=>E.isPropertyAssignment(o)&&E.isIdentifier(o.name)&&o.name.text===e);if(!(!s||!E.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(E.isStringLiteral).map(o=>o.text)}return null}function Pr(t,e,r,n){if(t.arguments.length===0)return null;for(let o=1;o<t.arguments.length;o++){let i=re(t.arguments,o);if(!E.isObjectLiteralExpression(i))continue;let a=i.properties.find(l=>E.isPropertyAssignment(l)&&E.isIdentifier(l.name)&&l.name.text===e);if(a)return{start:a.initializer.getStart(n),end:a.initializer.getEnd(),text:r};let c=i.getEnd()-1;return{start:c,end:c,text:`${i.properties.length>0?", ":""}${e}: ${r}`}}let s=re(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function Rr(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let o=re(n,s);if(!E.isObjectLiteralExpression(o))continue;let i=o.properties.findIndex(c=>E.isPropertyAssignment(c)&&E.isIdentifier(c.name)&&c.name.text===e);if(i<0)continue;if(o.properties.length===1)return{start:re(n,s-1).getEnd(),end:o.getEnd(),text:""};let a=re(o.properties,i);return i===o.properties.length-1?{start:re(o.properties,i-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:re(o.properties,i+1).getStart(r),text:""}}return null}function Ir(t,e){let r=[...e].sort((s,o)=>o.start-s.start),n=t;for(let s of r)n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function Dr(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var A=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function xu(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function yt(t,e,r,n){let s=E.createSourceFile(yu.basename(t),e,E.ScriptTarget.Latest,!0),o=Fr(s),[i]=o;if(!i)return e;let a=Nr(i,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(xu(a).sort())===JSON.stringify(c))return e;let l=Dr(c.map(u=>`@${u}`)),p=o.flatMap(u=>{let g=r.length===0?Rr(u,n,s):Pr(u,n,l,s);return g?[g]:[]});return p.length>0?Ir(e,p):e}var xt=class{name="cypress";canHandle(e){return A.has(Su.extname(e).toLowerCase())}apply(e,r,n){return yt(e,r,n,"tags")}};import bu from"path";var Mr=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,Ar=/^@([a-zA-Z0-9_-]+)/gm;function ku(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
34
+ `),null}}var pe=class{affectedSymbols=new Map;constructor(e,n){this.affectedSymbols.set(e,new Set(["default",...n]))}updateAffectedSymbols(e,n){let r=this.affectedSymbols.get(n)||new Set,s=e.imports.find(c=>c.toPath===n);if(!s)return!1;let i=s.symbols||["*"],o=new Set;for(let c of i)(c==="*"||r.has("*")||r.has(c))&&o.add("*");if(o.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let c of o)a.add(c);return this.affectedSymbols.set(e.path,a),!0}};function Qu(t,e){let n=t.nodes.get(e);if(n)return{category:n.category,exports:n.exports.map(r=>r.name)}}function Yu(t,e,n=1){let r=[];return t.traverse(e,(s,i,o)=>{if(s.path===e)return!0;let a=o?t.nodes.get(o)?.imports.find(c=>c.toPath===s.path):void 0;return r.push({path:s.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:n}),r}function tr(t,e){let n=[];return t.traverse(e,r=>{if(r.path===e)return!0;let s=r.imports.find(i=>i.toPath===e);return n.push({path:r.path,...s?.symbols?{symbols:s.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),n}function Xu(t,e,n={}){let{testsOnly:r=!1,changedSymbols:s}=n,i=s?new pe(e,s):null,o=[];return t.traverse(e,(a,c,l)=>{if(a.path===e)return!0;if(i&&l&&!i.updateAffectedSymbols(a,l))return!1;let p=a.category==="test"||a.tags.some(u=>u.name==="test");return(!r||p)&&o.push(a.path),!0},{direction:"incoming"}),o}function Zu(t,e,n={}){let{depth:r=1,withEdgeDetail:s=!1}=n,i=[];return t.traverseCalls(e,o=>{if(o.path===e)return!0;let a={file:o.path};return s&&(a.edges=(o.callEdges??[]).filter(c=>c.toFile===e).map(c=>({from:c.from,to:c.to}))),i.push(a),!0},{direction:"incoming",maxDepth:r}),i}function It(t,e={}){let{metric:n="cognitiveComplexity",threshold:r=10,limit:s=20}=e;return[...t.nodes.values()].flatMap(i=>(i.functions??[]).filter(o=>o[n]>=r).map(o=>({file:i.path,name:o.name,line:o.line,complexity:o.complexity,cognitiveComplexity:o.cognitiveComplexity}))).sort((i,o)=>o[n]-i[n]).slice(0,s)}function qu(t){return{nodes:t.nodes.map(n=>({path:n.path,type:n.type,category:n.category,exports:n.exports.map(r=>r.name),tags:n.tags.filter(r=>r.kind==="comment-marker"||r.kind==="import").map(r=>r.name),importsFiles:n.imports.filter(r=>!r.isExternal&&r.toPath).map(r=>r.toPath),...n.package!==void 0&&{package:n.package},...n.description!==void 0&&{description:n.description},...n.testedBy!==void 0&&{testedBy:n.testedBy},...n.coveragePct!==void 0&&{coveragePct:n.coveragePct},...n.avgExportUsage!==void 0&&{avgExportUsage:n.avgExportUsage},...n.maxExportUsage!==void 0&&{maxExportUsage:n.maxExportUsage}})),cycles:t.cycles}}function ef(t){let e=t.getPackageDependencies(),n=Array.from(t.packages.values()).map(({graph:r,pkg:s})=>({name:s.name,relativeRoot:s.relativeRoot,nodeCount:r.nodes.size,dependsOn:e.get(s.name)??[]}));return{monorepoType:t.type,packageCount:n.length,packages:n}}function Mt(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function eo(t){return[...t.nodes.values()].some(e=>e.commitCount90d!==void 0)}function tf(t){return[...t.nodes.values()].some(e=>e.lastCommitAt!==void 0)}function _t(t,e={}){let{metric:n="cognitiveComplexity",minComplexity:r=10,maxCoveragePct:s=50,minChurn:i=0,limit:o=20}=e,a=eo(t),c=[...t.nodes.values()].filter(l=>l.coveragePct!==void 0&&l.coveragePct<=s&&(!a||(l.commitCount90d??0)>=i)).flatMap(l=>(l.functions??[]).filter(p=>p[n]>=r).map(p=>({file:l.path,name:p.name,line:p.line,complexity:p.complexity,cognitiveComplexity:p.cognitiveComplexity,coveragePct:l.coveragePct,...l.commitCount90d!==void 0&&{commitCount90d:l.commitCount90d}}))).sort((l,p)=>p[n]-l[n]).slice(0,o);return{hotspots:c,count:c.length,churnDataAvailable:a}}import{execFileSync as rr}from"child_process";import nr from"fs";import nf from"os";import rf from"path";function sr(t,e){try{return rr("git",["rev-parse","--verify",`${e}^{commit}`],{cwd:t,encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{throw new Error(`Could not resolve git ref "${e}" in ${t}`)}}async function to(t,e,n){let r=nr.mkdtempSync(rf.join(nf.tmpdir(),`mokosh-worktree-${e.slice(0,12)}-`));nr.rmdirSync(r);try{return rr("git",["worktree","add","--detach",r,e],{cwd:t,stdio:["ignore","pipe","pipe"]}),await n(r)}finally{try{rr("git",["worktree","remove","--force",r],{cwd:t,stdio:["ignore","pipe","pipe"]})}catch{nr.rmSync(r,{recursive:!0,force:!0})}}}async function ao(t,e,n,r={}){let s=sr(t,e),i=Yr(t,s);if(i)return{sha:s,graph:i};let o=await to(t,s,async a=>{if(r.workspaceBuilder)return r.workspaceBuilder(a);let c=r.pathAliases?new H(a,{pathAliases:r.pathAliases}):void 0;return new le(a,null,c,void 0,r.gitStats??!1,new Map,r.parallelParsing??!0,r.additionalIgnoreDirs??[]).build(n)});return Xr(t,s,o),{sha:s,graph:o}}var no=t=>Math.round(t*100)/100,ro=t=>t.length>8?t.slice(0,8):t;function of(t,e){return`${t.file}:${t.line} ${t.name} (${t[e]})`}function af(t,e){return`${t.file}:${t.line} ${t.name} (${t[e]}, cov ${t.coveragePct}%)`}function cf(t,e=4){let n=t.occurrences.slice(0,e).map(i=>`${i.file}:${i.startLine}-${i.endLine}`),r=t.occurrences.length-n.length,s=r>0?`, +${r} more`:"";return`${t.lines}L x${t.occurrences.length}: ${n.join(", ")}${s}`}var ue=(t,e)=>`${t} ${e}${t===1?"":"s"}`;function lf(t,e){let{files:n,staleReferences:r,duplication:s,complexity:i,docDrift:o,coverage:a}=t,c=[],l=[n.added.length&&`${n.added.length} added`,n.changed.length&&`${n.changed.length} changed`,n.removed.length&&`${n.removed.length} removed`].filter(Boolean);c.push(l.length?`Files: ${l.join(", ")}`:"No file changes"),r.length>0&&c.push(`\u26A0 ${ue(r.length,"stale reference")} \u2014 removed export still imported`);let p=i.newHotspots[0];return p?c.push(`+${ue(i.newHotspots.length,"complexity hotspot")} (max ${e} ${p[e]} in ${p.file})`):i.resolvedHotspots.length>0&&c.push(`${ue(i.resolvedHotspots.length,"complexity hotspot")} resolved`),s.newGroups.length>0?c.push(`+${ue(s.newGroups.length,"duplication group")}`):s.resolvedGroups.length>0&&c.push(`${ue(s.resolvedGroups.length,"duplication group")} resolved`),o.newlyStale.length>0&&c.push(`${ue(o.newlyStale.length,"doc")} newly stale`),a&&a.newHotspots.length>0&&c.push(`+${ue(a.newHotspots.length,"risk hotspot")}`),c}function pf(t){let{staleReferences:e,duplication:n,complexity:r,docDrift:s,coverage:i}=t;return e.length>0||(i?.newHotspots.length??0)>0?"attention":r.newHotspots.length>0||n.newGroups.length>0||s.newlyStale.length>0?"review-worthy":"clean"}function uf(t,e={}){let n=e.metric??"cognitiveComplexity",r=e.maxItems??8,s=e.maxPathList??100,{files:i,staleReferences:o,duplication:a,complexity:c,docDrift:l,coverage:p}=t,u=no(c.head.avgCognitiveComplexity-c.base.avgCognitiveComplexity),m=i.added.length+i.changed.length+i.removed.length,d={base:`${t.base.ref}@${ro(t.base.sha)}`,head:`${t.head.ref}@${ro(t.head.sha)}`,verdict:pf(t),headline:lf(t,n),files:{added:i.added.length,changed:i.changed.length,removed:i.removed.length,...m<=s?{paths:{added:i.added,changed:i.changed,removed:i.removed}}:{}}};return o.length>0&&(d.staleReferences=o),(c.newHotspots.length>0||c.resolvedHotspots.length>0)&&(d.complexity={avgDelta:u,newHotspots:c.newHotspots.slice(0,r).map(y=>of(y,n)),newHotspotCount:c.newHotspots.length,resolvedCount:c.resolvedHotspots.length}),(a.newGroups.length>0||a.resolvedGroups.length>0)&&(d.duplication={newGroups:a.newGroups.slice(0,r).map(y=>cf(y)),newGroupCount:a.newGroups.length,resolvedCount:a.resolvedGroups.length,totalGroups:a.head.groups}),(l.newlyStale.length>0||l.resolved.length>0)&&(d.docDrift={newlyStale:l.newlyStale.slice(0,r).map(y=>y.replace("::"," \u2192 ")),newlyStaleCount:l.newlyStale.length,resolvedCount:l.resolved.length}),p&&(p.newHotspots.length>0||p.resolvedHotspots.length>0)&&(d.coverage={avgDelta:no(p.head.avgCoveragePct-p.base.avgCoveragePct),newHotspots:p.newHotspots.slice(0,r).map(y=>af(y,n)),newHotspotCount:p.newHotspots.length,resolvedCount:p.resolvedHotspots.length}),d}function ff(t,e){let n=[],r=[];for(let[i,o]of e.nodes){let a=t.nodes.get(i);if(!a){n.push(i);continue}let c=JSON.stringify({category:a.category,exports:a.exports.map(p=>p.name).sort(),imports:a.imports.map(p=>p.toPath).sort()}),l=JSON.stringify({category:o.category,exports:o.exports.map(p=>p.name).sort(),imports:o.imports.map(p=>p.toPath).sort()});c!==l&&r.push(i)}let s=[...t.nodes.keys()].filter(i=>!e.nodes.has(i));return{added:n,removed:s,changed:r}}function mf(t,e){let n=[];for(let[r,s]of t.nodes){let i=e.nodes.get(r);if(!i)continue;let o=new Set(i.exports.map(c=>c.name)),a=s.exports.map(c=>c.name).filter(c=>!o.has(c));if(a.length!==0)for(let c of a){let l=[...e.nodes.values()].filter(p=>p.imports.some(u=>u.toPath===r&&u.symbols?.includes(c))).map(p=>p.path);l.length>0&&n.push({file:r,symbol:c,stillReferencedBy:l})}}return n}function Gt(t){return t.occurrences.map(e=>`${e.file}:${e.startLine}-${e.endLine}`).sort().join("|")}async function gf(t,e,n,r,s){let i=sf.join(ft(t),`${r}-${bn}`),o=Pt(i),[{groups:a},{groups:c}]=await Promise.all([At(e,t,{minLines:s,tokenCache:o}),At(n,t,{minLines:s})]);Lt(o,i);let l=new Set(a.map(Gt)),p=new Set(c.map(Gt));return{base:{groups:a.length},head:{groups:c.length},newGroups:c.filter(u=>!l.has(Gt(u))),resolvedGroups:a.filter(u=>!p.has(Gt(u)))}}function so(t){let e=[...t.nodes.values()].map(n=>n.cognitiveComplexity).filter(n=>n!==void 0);return e.length===0?0:e.reduce((n,r)=>n+r,0)/e.length}function df(t,e,n,r){let s=It(t,{metric:n,threshold:r,limit:1/0}),i=It(e,{metric:n,threshold:r,limit:1/0}),o=l=>`${l.file}:${l.name}`,a=new Set(s.map(o)),c=new Set(i.map(o));return{base:{avgCognitiveComplexity:so(t)},head:{avgCognitiveComplexity:so(e)},newHotspots:i.filter(l=>!a.has(o(l))),resolvedHotspots:s.filter(l=>!c.has(o(l)))}}function io(t){let e=new Set;for(let n of t.nodes.values())if(!(n.type!=="markdown"||!n.staleFor))for(let r of n.staleFor)e.add(`${n.path}::${r}`);return e}function hf(t,e){let n=io(t),r=io(e);return{base:{staleCount:n.size},head:{staleCount:r.size},newlyStale:[...r].filter(s=>!n.has(s)),resolved:[...n].filter(s=>!r.has(s))}}function oo(t){let e=[...t.nodes.values()].map(n=>n.coveragePct).filter(n=>n!==void 0);return e.length===0?0:e.reduce((n,r)=>n+r,0)/e.length}function yf(t,e,n){if(!Mt(t)||!Mt(e))return null;let r=_t(t,{maxCoveragePct:n,limit:1/0}).hotspots,s=_t(e,{maxCoveragePct:n,limit:1/0}).hotspots,i=c=>`${c.file}:${c.name}`,o=new Set(r.map(i)),a=new Set(s.map(i));return{base:{avgCoveragePct:oo(t)},head:{avgCoveragePct:oo(e)},newHotspots:s.filter(c=>!o.has(i(c))),resolvedHotspots:r.filter(c=>!a.has(i(c)))}}async function xf(t,e,n,r={}){let{sha:s,graph:i}=await ao(t,e,r.entryPoints??[],r),o=sr(t,r.headRef??"HEAD"),[a,c]=await Promise.all([gf(t,i,n,s,r.minDuplicateLines),Promise.resolve(yf(i,n,r.maxCoveragePct))]);return{base:{ref:e,sha:s},head:{ref:r.headRef??"HEAD",sha:o},files:ff(i,n),staleReferences:mf(i,n),duplication:a,complexity:df(i,n,r.complexityMetric,r.complexityThreshold),docDrift:hf(i,n),coverage:c}}import Ot from"path";function Sf(t){let e=new Map;for(let[n,r]of t){let s=r.imports.filter(i=>i.toPath&&!i.isExternal).length;s>0&&e.set(n,s)}return e}function bf(t,e,n){let r=new Map;for(let[s,i]of e){if(i<n)continue;let o=t.get(s);if(!o||o.category==="test"||o.category==="barrel")continue;let a=Ot.extname(s),c=Ot.basename(s,a),l=c==="index"?Ot.basename(Ot.dirname(s)):c;r.set(s,{path:s,outDegree:i,tag:`feature:${l}`})}return r}function Xe(t,e){let n=e?.minOutDegree??5;return bf(t,Sf(t),n)}var kf=(t,e)=>t.outDegree-e.outDegree;function vf(t,e){let n=new Map;for(let r of e.values()){let s=new Set;t.traverse(r.path,i=>(i.path!==r.path&&s.add(i.path),!0),{direction:"outgoing"}),n.set(r.path,s)}return n}function Cf(t,e,n,r){let s=new Map;for(let[i]of t){if(e.has(i))continue;let o=null;for(let a of e.values())n.get(a.path)?.has(i)&&(!o||r(a,o)<0)&&(o=a);o&&s.set(i,o.path)}return s}function Ef(t,e){let n=new Map;for(let r of t.values()){let s=r.tag.replace("feature:",""),i=[];for(let[o,a]of e)a===r.path&&i.push(o);n.set(s,{hub:r.path,outDegree:r.outDegree,files:i})}return n}function wf(t,e,n){let r=[];for(let s of t.keys())!e.has(s)&&!n.has(s)&&r.push(s);return r}function ir(t,e){let n=e?.detectFn??Xe,r=e?.hubComparator??kf,s=n(t.nodes,e),i=vf(t,s),o=Cf(t.nodes,s,i,r);return{features:Ef(s,o),unassigned:wf(t.nodes,s,o)}}var Tf=[{role:"component",segments:["component","components"]},{role:"controller",segments:["controller","controllers"]},{role:"middleware",segments:["middleware"]},{role:"router",segments:["router","routes","route"]},{role:"store",segments:["store","stores"]},{role:"service",segments:["service","services"]},{role:"handler",segments:["handler","handlers"]},{role:"adapter",segments:["adapter","adapters"]},{role:"plugin",segments:["plugin","plugins"]},{role:"api",segments:["api"]},{role:"cli",segments:["cli","commands"],basenames:["cli"]},{role:"util",segments:["util","utils","helper","helpers"]},{role:"model",segments:["model","models"],basenames:["model"]},{role:"parser",segments:["parser","parsers"],basenames:["parser"]},{role:"builder",basenames:["builder"]},{role:"resolver",basenames:["resolver"]}];function co(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path,n=Df(e);for(let r of Tf)if(r.segments?.some(s=>Ff(e,s))||r.basenames?.includes(n))return r.role;return"other"}function Ff(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function Df(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function Nf(t,e){let n=ir(t,e),r=new Map;for(let[i,o]of n.features){for(let a of o.files)r.set(a,i);r.set(o.hub,i)}let s=new Map;for(let i of t.nodes.values()){let o=r.get(i.path);s.set(i.path,{path:i.path,role:co(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return s}function Rf(t,e){let n=[];for(let r of t.nodes.values())if(r.exports.some(s=>s.name===e))if(je.has(r.type)){let s=[];for(let i of t.nodes.values())for(let o of i.callEdges??[])o.to===e&&s.push({file:i.path,callerFunction:o.from});n.push({path:r.path,category:r.category,precision:"call",callers:s})}else{let s=tr(t,r.path).map(i=>({file:i.path,...i.symbols?{symbols:i.symbols}:{}}));n.push({path:r.path,category:r.category,precision:"file-level",importers:s})}return n}var or=ct,po=2,uo=50,ar=250,lo=["function","class","variable","type","import","library","comment-marker"];function Pf(t){let e=new Map;for(let r of t)for(let s of r.nodes.values())for(let i of s.tags){let o=e.get(i.name);o===void 0&&(o={name:i.name,count:0,kinds:[]},e.set(i.name,o)),o.count+=1,o.kinds.includes(i.kind)||o.kinds.push(i.kind)}let n={};for(let r of e.values()){r.kinds.sort((s,i)=>lo.indexOf(s)-lo.indexOf(i));for(let s of r.kinds)n[s]=(n[s]??0)+1}return{entries:e,byKind:n,totalDistinct:e.size}}function Lf(t,e={}){let n=Number.isFinite(e.minCount)?Math.max(1,Math.trunc(e.minCount)):po,r=Number.isFinite(e.limit)?Math.max(0,Math.trunc(e.limit)):uo,s=Math.min(r,ar),i=e.prefix?.toLowerCase(),o=d=>e.kind===void 0?d.kinds.some(y=>or.includes(y))&&pt(d.name):e.kind==="all"?!0:d.kinds.includes(e.kind),a=[...t.entries.values()].filter(d=>d.count>=n&&o(d)&&(i===void 0||d.name.toLowerCase().includes(i))).sort((d,y)=>y.count-d.count||d.name.localeCompare(y.name)),c=a.length,l=a.slice(0,s),p=e.kind===void 0?`${or.join(" + ")} kinds, noise-filtered`:e.kind==="all"?"all kinds":`${e.kind} kind`,u=c>l.length,m={tags:l.map(d=>({name:d.name,count:d.count,kinds:d.kinds})),count:l.length,matched:c,totalDistinct:t.totalDistinct,byKind:t.byKind,hint:`${c} tag${c===1?"":"s"} match (${p}, count>=${n})${u?`; showing the top ${l.length}`:""}. ${t.totalDistinct} distinct tag names exist across all kinds \u2014 see byKind. Narrow with prefix:"\u2026", a higher minCount, or kind:"comment-marker"|"import"|"function"|"variable"|"library"|"all". This response is always capped at ${ar} tags.`};return u&&(m.truncated=!0),m}function Af(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function If(t,e){if(e==="type-only")return!0;let n=t.signature??"";return n.startsWith("interface ")||n.startsWith("class ")||n.startsWith("enum ")}function Mf(t){let e=new Map;for(let r of t.nodes.values())if(!(r.type!=="typescript"&&r.type!=="javascript"))for(let s of r.exports){if(!If(s,r.category))continue;let i=`${r.path}::${s.name}`;e.set(i,{name:s.name,file:r.path,kind:Af(s.signature),...s.doc?{doc:s.doc}:{}})}let n=[];for(let r of t.nodes.values())if(!(r.type!=="typescript"&&r.type!=="javascript")){for(let s of r.imports)if(!(!s.toPath||s.isExternal||!s.symbols?.length))for(let i of s.symbols)e.has(`${s.toPath}::${i}`)&&n.push({fromFile:r.path,toType:i,toFile:s.toPath})}return{types:e,edges:n}}function _f(t,e){let n=null;for(let i of t.types.values())if(i.name===e){n=i;break}if(!n)return{type:null,usedByFiles:[],uses:[]};let r=new Set,s=new Map;for(let i of t.edges)if(i.toType===e&&i.toFile===n.file&&r.add(i.fromFile),i.fromFile===n.file){let o=t.types.get(`${i.toFile}::${i.toType}`);o&&s.set(`${o.file}::${o.name}`,o)}return{type:n,usedByFiles:Array.from(r),uses:Array.from(s.values())}}import om from"path";import go from"fs";import ho from"path";import Gf from"fs";import cr from"path";import fo from"fs";import Lk from"path";function jt(t){try{return fo.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function $t(t){try{return fo.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var Of=new Set([".java",".kt",".kts",".scala",".sc",".groovy",".gradle"]),jf=new Set(I);function mo(t,e=[]){let n;try{n=Gf.readdirSync(t,{withFileTypes:!0})}catch{return e}for(let r of n){let s=cr.join(t,r.name);r.isDirectory()?!jf.has(r.name)&&!r.name.startsWith(".")&&mo(s,e):r.isFile()&&Of.has(cr.extname(r.name).toLowerCase())&&e.push(s)}return e}function Wt(t,e,n){if(!jt(e))return null;let r=mo(e);return r.length===0?null:{name:n,root:e,relativeRoot:cr.relative(t,e),entryPoints:r}}function $f(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"")}function Wf(t){let e=$f(t),n=new Set;for(let r of e.matchAll(/['"](:[A-Za-z0-9_\-.:]+)['"]/g)){let s=r[1].replace(/^:/,"").replace(/:$/,"");s&&n.add(s)}return[...n]}var yo={type:"gradle",detect(t){let e=["settings.gradle.kts","settings.gradle"].map(i=>ho.join(t,i)).find(i=>go.existsSync(i));if(!e)return null;let n;try{n=go.readFileSync(e,"utf-8")}catch{return null}let r=Wf(n);if(r.length===0)return null;let s=[];for(let i of r){let o=ho.join(t,...i.split(":")),a=Wt(t,o,i);a&&s.push(a)}return s.length>0?s:null}};import ur from"fs";import So from"path";import Ze from"fs";import J from"path";function pr(t,e){let n=J.join(e,"package.json");if(!Ze.existsSync(n))return null;let r={};try{r=JSON.parse(Ze.readFileSync(n,"utf-8"))}catch{return null}let s=r.name;return s?{name:s,root:e,relativeRoot:J.relative(t,e),entryPoints:Bf(e,r)}:null}var zf=/\.[mc]?[jt]sx?$/;function lr(t,e){if(typeof t=="string"){zf.test(t)&&!t.endsWith(".d.ts")&&e(t);return}if(t&&typeof t=="object"&&!Array.isArray(t))for(let[n,r]of Object.entries(t))n!=="types"&&lr(r,e)}function Bf(t,e){let n=[],r=new Set,s=a=>{let c=J.join(t,a);r.has(c)||(r.add(c),n.push(c))},i=e.exports;if(typeof i=="string")lr(i,s);else if(i&&typeof i=="object"&&!Array.isArray(i))for(let a of Object.values(i))lr(a,s);e.main&&s(e.main);for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])s(a);let o=n.filter($t);return o.length>0?o:n.slice(0,1)}function De(t,e){let n=[],r=new Set;for(let s of e){let i=s.replace(/\/$/,"").replace(/^\.\//,"");Kf(t,i,r,n)}return n}function Kf(t,e,n,r){if(!e.includes("*")){Uf(t,e,n,r);return}let s=e.split("/");s.includes("**")?Hf(t,s,n,r):Jf(t,s,n,r)}function Uf(t,e,n,r){let s=J.join(t,e);if(n.has(s)||!jt(s))return;n.add(s);let i=pr(t,s);i&&r.push(i)}function Hf(t,e,n,r){let s=J.join(t,e[0]==="**"?"":e[0]??"");xo(t,s,n,r)}function Jf(t,e,n,r){let s=e.findIndex(a=>a.includes("*")),i=J.join(t,...e.slice(0,s)),o;try{o=Ze.readdirSync(i,{withFileTypes:!0})}catch{return}for(let a of o){if(!a.isDirectory())continue;let c=J.join(i,a.name);if(n.has(c))continue;n.add(c);let l=pr(t,c);l&&r.push(l)}}function xo(t,e,n,r){let s;try{s=Ze.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of s){if(!i.isDirectory()||i.name==="node_modules"||i.name.startsWith("."))continue;let o=J.join(e,i.name);if(Ze.existsSync(J.join(o,"package.json"))&&!n.has(o)){n.add(o);let a=pr(t,o);a&&r.push(a)}else xo(t,o,n,r)}}var bo={type:"npm",detect(t){let e=So.join(t,"package.json");if(!ur.existsSync(e))return null;let n;try{n=JSON.parse(ur.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!n||ur.existsSync(So.join(t,"yarn.lock")))return null;let r=Array.isArray(n)?n:n.packages??[];return r.length===0?null:De(t,r)}};import Ne from"fs";import D from"path";var ko={type:"nx",detect(t){return Ne.existsSync(D.join(t,"nx.json"))?vo(t,t,new Set,0).map(n=>Vf(t,n,D.join(n,"project.json"))).filter(n=>n!==null):null}};function vo(t,e,n,r){if(r>4)return[];let s;try{s=Ne.readdirSync(e,{withFileTypes:!0})}catch{return[]}let i=[];for(let o of s){if(!o.isDirectory())continue;let a=o.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let c=D.join(e,a);Ne.existsSync(D.join(c,"project.json"))&&!n.has(c)?(n.add(c),i.push(c)):i.push(...vo(t,c,n,r+1))}return i}function Vf(t,e,n){let r={};try{r=JSON.parse(Ne.readFileSync(n,"utf-8"))}catch{return null}let s=r.name,i,o,a=D.join(e,"package.json");if(Ne.existsSync(a))try{let c=JSON.parse(Ne.readFileSync(a,"utf-8"));s=c.name??s,i=c.main,o=c.exports}catch{}return s?{name:s,root:e,relativeRoot:D.relative(t,e),entryPoints:Qf(e,r,i,o)}:null}function Qf(t,e,n,r){let s=[],i=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(i){let a=D.resolve(t,"../..");s.push(D.resolve(a,i)),s.push(D.resolve(t,i))}if(r){let a=r;if(typeof a=="string")s.push(D.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(D.join(t,c))}}if(n&&s.push(D.join(t,n)),e.sourceRoot){let a=D.resolve(t,"../.."),c=D.resolve(a,e.sourceRoot);s.push(D.join(c,"index.ts"),D.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(D.join(t,a));let o=s.filter($t);return o.length>0?o.slice(0,1):s.slice(0,1)}import Co from"fs";import Yf from"path";import{load as Xf}from"js-yaml";var Eo={type:"pnpm",detect(t){let e=Yf.join(t,"pnpm-workspace.yaml");if(!Co.existsSync(e))return null;let n=[];try{n=Xf(Co.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return De(t,n)}};import qe from"fs";import zt from"path";function Zf(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"")}function qf(t){let e=Zf(t),n=new Map;for(let r of e.matchAll(/(?:lazy\s+)?val\s+([A-Za-z0-9_]+)\s*=\s*\(?\s*project\b([^\n]*)/g)){let s=r[1],o=r[2].match(/\bfile\s*\(\s*["']([^"']+)["']\s*\)/),a=o?o[1]:s;if(a==="."||a==="./")continue;let c=a.replace(/^\.\//,"").replace(/\/$/,"");n.has(c)||n.set(c,{name:s,dir:c})}return[...n.values()]}var wo={type:"sbt",detect(t){let e=zt.join(t,"build.sbt"),n=zt.join(t,"project");if(!qe.existsSync(e)||!qe.existsSync(n))return null;let r=[];try{r.push(qe.readFileSync(e,"utf-8"))}catch{return null}try{for(let a of qe.readdirSync(n))a.endsWith(".scala")&&r.push(qe.readFileSync(zt.join(n,a),"utf-8"))}catch{}let s=new Set,i=[];for(let a of r)for(let c of qf(a))s.has(c.dir)||(s.add(c.dir),i.push(c));if(i.length===0)return null;let o=[];for(let a of i){let c=zt.join(t,...a.dir.split("/")),l=Wt(t,c,a.name);l&&o.push(l)}return o.length>0?o:null}};import em from"fs";import tm from"path";var To={type:"turborepo",detect(t){return em.existsSync(tm.join(t,"turbo.json"))?[]:null}};import fr from"fs";import Fo from"path";var Do={type:"yarn",detect(t){if(!fr.existsSync(Fo.join(t,"yarn.lock")))return null;let e=Fo.join(t,"package.json");if(!fr.existsSync(e))return null;let n;try{n=JSON.parse(fr.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!n)return null;let r=Array.isArray(n)?n:n.packages??[];return r.length===0?null:De(t,r)}};var No=[];function W(t){No.push(t)}function Ro(){return No}import nm from"fs";import rm from"path";var sm=["dependencies","devDependencies","peerDependencies","optionalDependencies"];function im(t){try{let e=nm.readFileSync(rm.join(t,"package.json"),"utf-8"),n=JSON.parse(e),r=new Set;for(let s of sm){let i=n[s];if(i&&typeof i=="object")for(let o of Object.keys(i))r.add(o)}return r}catch{return null}}function Po(t,e){if(e){let i=e.getPackageDependencies(),o=Array.from(e.packages.values()).map(({graph:a,pkg:c})=>({name:c.name,relativeRoot:c.relativeRoot,dependsOn:i.get(c.name)??[],nodeCount:a.nodes.size}));return{monorepoType:t.type,monorepoTypes:t.types,packageCount:o.length,packages:o,dependsOnResolved:!0,nodeCountsResolved:!0}}let n=new Set(t.packages.map(i=>i.name)),r=!0,s=t.packages.map(i=>{let o=im(i.root);if(o===null)return r=!1,{name:i.name,relativeRoot:i.relativeRoot,dependsOn:[]};let a=[...o].filter(c=>c!==i.name&&n.has(c)).sort();return{name:i.name,relativeRoot:i.relativeRoot,dependsOn:a}});return{monorepoType:t.type,monorepoTypes:t.types,packageCount:s.length,packages:s,dependsOnResolved:r,nodeCountsResolved:!1,note:"Layout only \u2014 per-package node counts and (for build-system monorepos without package.json) dependency edges require a full graph. Call analyze with empty entryPoints, then get_workspace_packages again."}}W(To);W(ko);W(Eo);W(Do);W(bo);W(yo);W(wo);function mr(t,e=Ro()){let n=om.resolve(t),r=new Map,s=[];for(let o of e){let a=o.detect(n);if(a!==null){s.push(o.type);for(let c of a)r.has(c.name)||r.set(c.name,c)}}if(s.length===0)return{root:n,type:"none",types:[],packages:[],packageMap:new Map};let i=Array.from(r.values());return{root:n,type:s[0],types:s,packages:i,packageMap:new Map(i.map(o=>[o.name,o]))}}function Bt(t,e){return t===e.relativeRoot||t.startsWith(`${e.relativeRoot}/`)}var et=class t{constructor(e,n){this.monorepoRoot=e;this.type=n}monorepoRoot;type;packages=new Map;flattened;addPackage(e,n){this.packages.set(e.name,{graph:n,pkg:e})}annotateCrossPackageEdges(){for(let{graph:e}of this.packages.values())for(let n of e.nodes.values()){let r=this.getPackageForFile(n.path);if(r)for(let s of n.imports){if(s.isExternal||s.isWorkspace)continue;let i=this.getPackageForFile(s.toPath);i&&i.name!==r.name&&(s.isWorkspace=!0,s.workspacePackage=i.name)}}}flatten(){if(this.flattened)return this.flattened;let e=new Map,n=new Map;for(let{graph:r,pkg:s}of this.packages.values())for(let[i,o]of r.nodes)Bt(i,s)&&(e.set(i,o),n.set(i,s.name));return this.flattened={graph:new O(e),packageOf:n},this.flattened}getPackageForFile(e){for(let{pkg:n}of this.packages.values())if(e===n.relativeRoot||e.startsWith(`${n.relativeRoot}/`))return n}getPackageDependencies(){let e=new Map;for(let{graph:n,pkg:r}of this.packages.values()){let s=new Set;for(let i of n.nodes.values())for(let o of i.imports)o.isWorkspace&&o.workspacePackage&&s.add(o.workspacePackage);e.set(r.name,[...s])}return e}getAffectedAcrossPackages(e){let{graph:n,packageOf:r}=this.flatten();if(!n.nodes.has(e))return[];let s=[];return n.traverse(e,i=>(i.path!==e&&s.push({file:i.path,package:r.get(i.path)??""}),!0),{direction:"incoming"}),s}summarizeAffectedAcrossPackages(e,n={}){let r=n.maxFilesPerPackage??10,s=this.getAffectedAcrossPackages(e),i=new Map;for(let{file:c,package:l}of s){let p=i.get(l)??[];p.push(c),i.set(l,p)}let o=!1,a=[...i.entries()].map(([c,l])=>{let p=l.slice(0,r),u=l.length-p.length;return u>0&&(o=!0),{package:c,count:l.length,sample:p,more:u}}).sort((c,l)=>l.count-c.count);return{file:e,totalAffected:s.length,packageCount:a.length,byPackage:a,truncated:o}}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:n})=>({pkg:{name:n.name,relativeRoot:n.relativeRoot,entryPoints:n.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let n=new t(e.monorepoRoot,e.type);for(let{pkg:r,nodes:s}of e.packages){let i=new Map(s.map(a=>[a.path,a])),o=new O(i);n.packages.set(r.name,{graph:o,pkg:{...r,root:""}})}return n}};function gr(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function am(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var cm=(t,e)=>!e.category||gr(t.category,e.category),lm=(t,e)=>!e.type||gr(t.type,e.type),pm=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,um=(t,e)=>!e.path||am(t.path,e.path),fm=(t,e,n,r)=>{if(!e.package||!r)return!0;let s=r.get(t.path)??"";return gr(s,e.package)},mm=(t,e)=>e.isExternal===void 0?!0:t.imports.some(r=>r.isExternal)===e.isExternal,gm=(t,e)=>{if(!e.tags||e.tags.length===0)return!0;let n=new Set(t.tags.filter(ne).map(i=>i.name)),r=e.tags.filter(i=>!i.startsWith("!")),s=e.tags.filter(i=>i.startsWith("!")).map(i=>i.slice(1));return!(r.length>0&&!r.some(i=>n.has(i))||s.some(i=>n.has(i)))},dm=(t,e)=>{if(!e.allTags?.length)return!0;let n=new Set(t.tags.filter(ne).map(r=>r.name));return e.allTags.every(r=>n.has(r))},hm=(t,e)=>!e.importsFile||t.imports.some(n=>n.toPath?.includes(e.importsFile)),ym=(t,e,n)=>e.importedBy===void 0?!0:(n?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),xm=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,Sm=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,bm=(t,e)=>e.minSize===void 0||t.size>=e.minSize,km=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,vm=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,Cm=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,Em=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,wm=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,Tm=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,Fm=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,Dm=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,Nm=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,Rm=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,Pm=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,Lm=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,Am=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,Im=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,Mm=(t,e,n,r)=>!e.any?.length||e.any.some(s=>tt(t,s,n,r)),_m=[cm,lm,pm,um,fm,mm,gm,dm,hm,ym,xm,Sm,bm,km,vm,Cm,Em,wm,Tm,Fm,Dm,Nm,Rm,Pm,Lm,Am,Im,Mm];function tt(t,e,n,r){return _m.every(s=>s(t,e,n,r))}function Lo(t,e,n={}){let{packageOf:r}=n,s=new Map;if(e.importedBy!==void 0){for(let c of t.nodes)for(let l of c.imports)if(l.toPath){let p=s.get(l.toPath)??[];p.push(c.path),s.set(l.toPath,p)}}let i=t.nodes.filter(c=>tt(c,e,s,r)),o=new Set(i.map(c=>c.path)),a=i.map(c=>{let l=r?.get(c.path);return{...c,imports:c.imports.filter(p=>!p.toPath||o.has(p.toPath)),...l!==void 0&&{package:l}}});if(e.sort){let c=e.sortDir==="asc"?-1:1;a.sort((l,p)=>{let u=0;switch(e.sort){case"size":u=p.size-l.size;break;case"imports":u=p.imports.length-l.imports.length;break;case"commitCount90d":u=(p.commitCount90d??0)-(l.commitCount90d??0);break;case"exportUsage":u=(p.avgExportUsage??0)-(l.avgExportUsage??0);break;case"complexity":u=(p.complexity??0)-(l.complexity??0);break;case"cognitiveComplexity":u=(p.cognitiveComplexity??0)-(l.cognitiveComplexity??0);break}return u*c})}return e.limit!==void 0&&a.splice(e.limit),{nodes:a,cycles:t.cycles?.filter(c=>c.every(l=>o.has(l)))??void 0}}var Gm={category:{field:"category",kind:"string"},type:{field:"type",kind:"string"},path:{field:"path",kind:"string"},package:{field:"package",kind:"string"},importsfile:{field:"importsFile",kind:"string"},importedby:{field:"importedBy",kind:"string"},lastauthor:{field:"lastAuthor",kind:"string"},external:{field:"isExternal",kind:"boolIsTrue"},hasdocstring:{field:"hasDocstring",kind:"boolNotFalse"},isdocumented:{field:"isDocumented",kind:"boolNotFalse"},isstale:{field:"isStale",kind:"boolNotFalse"},minimports:{field:"minImports",kind:"int"},maximports:{field:"maxImports",kind:"int"},minsize:{field:"minSize",kind:"int"},maxsize:{field:"maxSize",kind:"int"},limit:{field:"limit",kind:"int"},mincoverage:{field:"minCoverage",kind:"int"},maxcoverage:{field:"maxCoverage",kind:"int"},minexportusage:{field:"minExportUsage",kind:"float"},maxexportusage:{field:"maxExportUsage",kind:"float"},mincomplexity:{field:"minComplexity",kind:"int"},maxcomplexity:{field:"maxComplexity",kind:"int"},mincognitivecomplexity:{field:"minCognitiveComplexity",kind:"int"},maxcognitivecomplexity:{field:"maxCognitiveComplexity",kind:"int"},mincommits:{field:"minCommits",kind:"int"},maxcommits:{field:"maxCommits",kind:"int"}};function Om(t,e,n,r){let s=t;switch(n){case"string":s[e]=r;break;case"int":s[e]=parseInt(r,10);break;case"float":s[e]=parseFloat(r);break;case"boolNotFalse":s[e]=r.toLowerCase()!=="false";break;case"boolIsTrue":s[e]=r.toLowerCase()==="true";break}}function Io(t,e){let n=e.indexOf(":");if(n===-1)return;let r=e.slice(0,n).trim().toLowerCase(),s=e.slice(n+1).trim();if(!r||!s)return;if(r==="tag"||r==="tags"){s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];return}if(r==="sort"){t.sort=s;return}if(r==="sortdir"){t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";return}let i=Gm[r];i&&Om(t,i.field,i.kind,s)}function jm(t){let e=[];for(let n of t.split("|")){let r=n.trim();if(!r)continue;let s={};Io(s,r),Object.keys(s).length>0&&e.push(s)}return e}var Ao="any(";function Mo(t){let e={},n=t.split(",");for(let r of n){let s=r.trim();if(s.toLowerCase().startsWith(Ao)&&s.endsWith(")")){let i=s.slice(Ao.length,-1),o=jm(i);o.length>0&&(e.any=[...e.any??[],...o]);continue}Io(e,r)}return e}import Uo from"fs/promises";import vg from"path";import Dr from"path";import en from"typescript";import zm from"path";import $m from"path";import T from"typescript";var _o=new Set(["describe","test","it"]);function fe(t,e){let n=t[e];if(n===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return n}function dr(t){let e=[];for(let n of t.statements){if(!T.isExpressionStatement(n))continue;let r=n.expression;if(!T.isCallExpression(r))continue;let s=r.expression;T.isIdentifier(s)&&_o.has(s.text)&&e.push(r),T.isPropertyAccessExpression(s)&&T.isIdentifier(s.expression)&&_o.has(s.expression.text)&&e.push(r)}return e}function hr(t,e,n){for(let r of t.arguments){if(!T.isObjectLiteralExpression(r))continue;let s=r.properties.find(i=>T.isPropertyAssignment(i)&&T.isIdentifier(i.name)&&i.name.text===e);if(!(!s||!T.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(T.isStringLiteral).map(i=>i.text)}return null}function yr(t,e,n,r){if(t.arguments.length===0)return null;for(let i=1;i<t.arguments.length;i++){let o=fe(t.arguments,i);if(!T.isObjectLiteralExpression(o))continue;let a=o.properties.find(l=>T.isPropertyAssignment(l)&&T.isIdentifier(l.name)&&l.name.text===e);if(a)return{start:a.initializer.getStart(r),end:a.initializer.getEnd(),text:n};let c=o.getEnd()-1;return{start:c,end:c,text:`${o.properties.length>0?", ":""}${e}: ${n}`}}let s=fe(t.arguments,t.arguments.length-1);return{start:s.getStart(r),end:s.getStart(r),text:`{ ${e}: ${n} }, `}}function xr(t,e,n){let r=t.arguments;for(let s=1;s<r.length;s++){let i=fe(r,s);if(!T.isObjectLiteralExpression(i))continue;let o=i.properties.findIndex(c=>T.isPropertyAssignment(c)&&T.isIdentifier(c.name)&&c.name.text===e);if(o<0)continue;if(i.properties.length===1)return{start:fe(r,s-1).getEnd(),end:i.getEnd(),text:""};let a=fe(i.properties,o);return o===i.properties.length-1?{start:fe(i.properties,o-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(n),end:fe(i.properties,o+1).getStart(n),text:""}}return null}function Sr(t,e){let n=[...e].sort((s,i)=>i.start-s.start),r=t;for(let s of n)r=r.slice(0,s.start)+s.text+r.slice(s.end);return r}function br(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var z=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Wm(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Kt(t,e,n,r){let s=T.createSourceFile($m.basename(t),e,T.ScriptTarget.Latest,!0),i=dr(s),[o]=i;if(!o)return e;let a=hr(o,r,s),c=[...n].sort();if(a!==null&&JSON.stringify(Wm(a).sort())===JSON.stringify(c))return e;let l=br(c.map(u=>`@${u}`)),p=i.flatMap(u=>{let m=n.length===0?xr(u,r,s):yr(u,r,l,s);return m?[m]:[]});return p.length>0?Sr(e,p):e}var Ut=class{name="cypress";canHandle(e){return z.has(zm.extname(e).toLowerCase())}apply(e,n,r){return Kt(e,n,r,"tags")}};import Bm from"path";var kr=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,vr=/^@([a-zA-Z0-9_-]+)/gm;function Km(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
28
35
  `)}
29
36
 
30
- `}function vu(t){let e=new Set;Ar.lastIndex=0;let r=Ar.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=Ar.exec(t);return e}var St=class{name="gherkin";canHandle(e){return bu.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(Mr,""),o=vu(s),i=n.filter(c=>!o.has(c)),a=i.length>0?ku(i):"";return Mr.test(r)?r.replace(Mr,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function go(t,e){let r=t.replace(/\\/g,"/"),n=e.replace(/\\/g,"/"),s="";for(let o=0;o<r.length;o++){let i=r[o];i==="*"?r[o+1]==="*"?(s+=".*",o++):s+="[^/]*":i==="?"?s+="[^/]":i!==void 0&&(s+=i.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${s}$`).test(n)}import Cu from"path";var Lr=/^\/\/go:build mokosh_[^\n]+\n/m,wu=/^package\s+\S+/m;function Eu(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
31
- `}function Tu(t){let e=Lr.exec(t);if(!e)return null;let r=e[0]??"",n=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],o=n.exec(r);for(;o!==null;)o[1]&&s.push(o[1]),o=n.exec(r);return s}var bt=class{name="go";canHandle(e){return Cu.basename(e).endsWith("_test.go")}apply(e,r,n){let s=Tu(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(Lr,"");let i=Eu(o);if(s!==null)return r.replace(Lr,i);let a=wu.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+i}
32
- ${r.slice(c)}`}};import Fu from"path";var Nu=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,_r=/^ \* @group (.+)$/gm;function Pu(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
37
+ `}function Um(t){let e=new Set;vr.lastIndex=0;let n=vr.exec(t);for(;n!==null;)n[1]&&e.add(n[1]),n=vr.exec(t);return e}var Ht=class{name="gherkin";canHandle(e){return Bm.extname(e).toLowerCase()===".feature"}apply(e,n,r){let s=n.replace(kr,""),i=Um(s),o=r.filter(c=>!i.has(c)),a=o.length>0?Km(o):"";return kr.test(n)?n.replace(kr,a):a?n.replace(/^(Feature:)/m,`${a}$1`):n}};function Go(t,e){let n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/"),s="";for(let i=0;i<n.length;i++){let o=n[i];o==="*"?n[i+1]==="*"?(s+=".*",i++):s+="[^/]*":o==="?"?s+="[^/]":o!==void 0&&(s+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${s}$`).test(r)}import Hm from"path";var Cr=/^\/\/go:build mokosh_[^\n]+\n/m,Jm=/^package\s+\S+/m;function Vm(t){return`//go:build ${t.map(n=>`mokosh_${n}`).join(" || ")}
38
+ `}function Qm(t){let e=Cr.exec(t);if(!e)return null;let n=e[0]??"",r=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],i=r.exec(n);for(;i!==null;)i[1]&&s.push(i[1]),i=r.exec(n);return s}var Jt=class{name="go";canHandle(e){return Hm.basename(e).endsWith("_test.go")}apply(e,n,r){let s=Qm(n),i=[...r].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return n;if(r.length===0)return n.replace(Cr,"");let o=Vm(i);if(s!==null)return n.replace(Cr,o);let a=Jm.exec(n);if(!a)return n;let c=a.index;return`${n.slice(0,c)+o}
39
+ ${n.slice(c)}`}};import Ym from"path";var Xm=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,Er=/^ \* @group (.+)$/gm;function Zm(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
33
40
  `)}
34
41
 
35
- `}function Ru(t){let e=[];_r.lastIndex=0;let r=_r.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=_r.exec(t);return e}var kt=class{name="jest";canHandle(e){return A.has(Fu.extname(e).toLowerCase())}apply(e,r,n){let s=Nu.exec(r),o=s?Ru(s[0]):null,i=[...n].sort();if(o!==null&&JSON.stringify([...o].sort())===JSON.stringify(i))return r;let a=s?r.slice(s[0].length):r;return n.length===0?a:Pu(i)+a}};import Iu from"path";var Du="// mokosh:tags",Gr=/^\/\/ mokosh:tags\n(?:[ \t]*@Tag\("[^"]*"\)\n)*/m,Or="import org.junit.jupiter.api.Tag;",yo=/^import org\.junit\.jupiter\.api\.Tag;\n/m,Mu=/^(?:public\s+|final\s+|abstract\s+|sealed\s+|non-sealed\s+|strictfp\s+)*(?:class|interface|enum|record|@interface)\s+\w+/m,Au=/^import\s+[^\n]+;\n(?![\s\S]*^import\s)/m,Lu=/^package\s+[^\n]+;\n/m,_u=/\/src\/(test|androidTest|integrationTest|it)\//,Ou=/(Test|Tests|Spec|IT)\.(java|groovy)$/;function Gu(t){let e=Gr.exec(t);if(!e)return null;let r=[],n=/@Tag\("([^"]*)"\)/g,s=n.exec(e[0]);for(;s!==null;)s[1]&&r.push(s[1]),s=n.exec(e[0]);return r}function ju(t){return`${Du}
42
+ `}function qm(t){let e=[];Er.lastIndex=0;let n=Er.exec(t);for(;n!==null;)n[1]&&e.push(n[1]),n=Er.exec(t);return e}var Vt=class{name="jest";canHandle(e){return z.has(Ym.extname(e).toLowerCase())}apply(e,n,r){let s=Xm.exec(n),i=s?qm(s[0]):null,o=[...r].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return n;let a=s?n.slice(s[0].length):n;return r.length===0?a:Zm(o)+a}};import Oo from"path";var eg="// mokosh:tags",wr=/^\/\/ mokosh:tags\n(?:[ \t]*@Tag\("[^"]*"\)\n)*/m,tg=/\/src\/(test|androidTest|integrationTest|it)\//,ng=/(Test|Tests|Spec|IT)\.(java|groovy|kt)$/,rg={importLine:"import org.junit.jupiter.api.Tag;",importRe:/^import org\.junit\.jupiter\.api\.Tag;?\n/m,typeDeclRe:/^(?:public\s+|final\s+|abstract\s+|sealed\s+|non-sealed\s+|strictfp\s+)*(?:class|interface|enum|record|@interface)\s+\w+/m,lastImportRe:/^import\s+[^\n]+;\n(?![\s\S]*^import\s)/m,packageRe:/^package\s+[^\n]+;\n/m},sg={importLine:"import org.junit.jupiter.api.Tag",importRe:/^import org\.junit\.jupiter\.api\.Tag;?\n/m,typeDeclRe:/^(?:public\s+|private\s+|protected\s+|internal\s+|open\s+|abstract\s+|final\s+|sealed\s+|data\s+|inner\s+|value\s+|annotation\s+)*(?:enum\s+)?(?:class|interface|object)\s+\w+/m,lastImportRe:/^import\s+[^\n]+\n(?![\s\S]*^import\s)/m,packageRe:/^package\s+[^\n]+\n/m};function ig(t){let e=wr.exec(t);if(!e)return null;let n=[],r=/@Tag\("([^"]*)"\)/g,s=r.exec(e[0]);for(;s!==null;)s[1]&&n.push(s[1]),s=r.exec(e[0]);return n}function og(t){return`${eg}
36
43
  ${t.map(e=>`@Tag("${e}")`).join(`
37
44
  `)}
38
- `}function ho(t){if(yo.test(t))return t;let e=Au.exec(t);if(e){let n=e.index+e[0].length;return t.slice(0,n)+Or+`
39
- `+t.slice(n)}let r=Lu.exec(t);if(r){let n=r.index+r[0].length;return t.slice(0,n)+`
40
- `+Or+`
41
- `+t.slice(n)}return Or+`
42
- `+t}function $u(t){return/@Tag\b/.test(t)?t:t.replace(yo,"")}var vt=class{name="junit";canHandle(e){let r=e.replace(/\\/g,"/"),n=Iu.extname(r).toLowerCase();return n!==".java"&&n!==".groovy"?!1:_u.test(r)||Ou.test(r)}apply(e,r,n){let s=Gu(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return s===null?r:$u(r.replace(Gr,""));let i=ju(o);if(s!==null)return ho(r.replace(Gr,i));let a=Mu.exec(r);if(!a)return r;let c=r.slice(0,a.index)+i+r.slice(a.index);return ho(c)}};import Wu from"path";var Ct=class{name="playwright";canHandle(e){return A.has(Wu.extname(e).toLowerCase())}apply(e,r,n){return yt(e,r,n,"tag")}};import zu from"path";var jr=/^pytestmark\s*=\s*.+$/m,Bu=/^import pytest\s*$/m;function Hu(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Uu(t){let e=jr.exec(t);if(!e)return null;let r=e[0],n=[],s=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,o=s.exec(r);for(;o!==null;)o[1]&&n.push(o[1]),o=s.exec(r);return n}var wt=class{name="pytest";canHandle(e){return zu.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Uu(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(jr,"").replace(/\n{3,}/g,`
45
+ `}function jo(t,e){if(e.importRe.test(t))return t;let n=e.lastImportRe.exec(t);if(n){let s=n.index+n[0].length;return t.slice(0,s)+e.importLine+`
46
+ `+t.slice(s)}let r=e.packageRe.exec(t);if(r){let s=r.index+r[0].length;return t.slice(0,s)+`
47
+ `+e.importLine+`
48
+ `+t.slice(s)}return e.importLine+`
49
+ `+t}function ag(t,e){return/@Tag\b/.test(t)?t:t.replace(e.importRe,"")}var Qt=class{name="junit";canHandle(e){let n=e.replace(/\\/g,"/"),r=Oo.extname(n).toLowerCase();return r!==".java"&&r!==".groovy"&&r!==".kt"?!1:tg.test(n)||ng.test(n)}apply(e,n,r){let s=Oo.extname(e.replace(/\\/g,"/")).toLowerCase()===".kt"?sg:rg,i=ig(n),o=[...r].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return n;if(r.length===0)return i===null?n:ag(n.replace(wr,""),s);let a=og(o);if(i!==null)return jo(n.replace(wr,a),s);let c=s.typeDeclRe.exec(n);if(!c)return n;let l=n.slice(0,c.index)+a+n.slice(c.index);return jo(l,s)}};import cg from"path";var Yt=class{name="playwright";canHandle(e){return z.has(cg.extname(e).toLowerCase())}apply(e,n,r){return Kt(e,n,r,"tag")}};import lg from"path";var Tr=/^pytestmark\s*=\s*.+$/m,pg=/^import pytest\s*$/m;function ug(t){let e=t.map(n=>`pytest.mark.${n}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function fg(t){let e=Tr.exec(t);if(!e)return null;let n=e[0],r=[],s=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,i=s.exec(n);for(;i!==null;)i[1]&&r.push(i[1]),i=s.exec(n);return r}var Xt=class{name="pytest";canHandle(e){return lg.extname(e).toLowerCase()===".py"}apply(e,n,r){let s=fg(n),i=[...r].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return n;if(r.length===0)return n.replace(Tr,"").replace(/\n{3,}/g,`
43
50
 
44
- `);let i=Hu(o);if(s!==null)return r.replace(jr,i);let a=Bu.test(r),c=Ku(r),l=r.slice(0,c),p=r.slice(c),u=a?"":`import pytest
45
- `,g=l.endsWith(`
51
+ `);let o=ug(i);if(s!==null)return n.replace(Tr,o);let a=pg.test(n),c=mg(n),l=n.slice(0,c),p=n.slice(c),u=a?"":`import pytest
52
+ `,m=l.endsWith(`
46
53
 
47
54
  `)?"":`
48
- `;return`${l+g+u+i}
49
- ${p}`}};function Ku(t){let e=t.split(`
50
- `),r=-1;return e.forEach((s,o)=>{(s.trimStart().startsWith("import ")||s.trimStart().startsWith("from "))&&(r=o)}),r<0?0:e.slice(0,r+1).reduce((s,o)=>s+o.length+1,0)}import Ju from"path";var $r=/^\/\/ mokosh:tags .*\n/m,Vu=/^(?:sealed\s+|abstract\s+|final\s+|private\s+|implicit\s+|case\s+)*(?:class|object|trait)\s+\w+/m,Yu=/\/src\/(test|it)\//,Qu=/(Spec|Suite|Test|Props)\.scala$/;function Xu(t){let e=$r.exec(t);return e?e[0].replace(/^\/\/ mokosh:tags /,"").trim().split(/\s*,\s*/).filter(Boolean):null}var Et=class{name="scalatest";canHandle(e){let r=e.replace(/\\/g,"/");return Ju.extname(r).toLowerCase()!==".scala"?!1:Yu.test(r)||Qu.test(r)}apply(e,r,n){let s=Xu(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return s===null?r:r.replace($r,"");let i=`// mokosh:tags ${o.join(", ")}
51
- `;if(s!==null)return r.replace($r,i);let a=Vu.exec(r);return a?r.slice(0,a.index)+i+r.slice(a.index):r}};import xo from"path";import So from"typescript";var Zu=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,Tt=class{name="vitest";canHandle(e){return A.has(xo.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(Zu,""),o=So.createSourceFile(xo.basename(e),s,So.ScriptTarget.Latest,!0),i=Fr(o),[a]=i;if(!a)return s;let c=Nr(a,"tags",o),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=i.flatMap(u=>{let g=n.length===0?Rr(u,"tags",o):Pr(u,"tags",Dr(l),o);return g?[g]:[]});return p.length>0?Ir(s,p):s}};var bo={vitest:()=>new Tt,playwright:()=>new Ct,cypress:()=>new xt,jest:()=>new kt},qu={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function em(t){let e=Ft.createSourceFile("detect.ts",t,Ft.ScriptTarget.Latest,!0);for(let r of e.statements){if(!Ft.isImportDeclaration(r)||!Ft.isStringLiteral(r.moduleSpecifier))continue;let n=qu[r.moduleSpecifier.text];if(n)return n}return null}var zr=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return A.has(Wr.extname(e).toLowerCase())}apply(e,r,n){let s=em(r)??this.matchOverride(e)??this.defaultFramework;return(bo[s]??bo.vitest)().apply(e,r,n)}matchOverride(e){let r=Wr.relative(this.rootDir,e).split(Wr.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(go(n,r))return s;return null}};function ko(t="vitest",e={},r=process.cwd()){return[new St,new wt,new bt,new vt,new Et,new zr(r,t,Object.entries(e))]}function vo(t,e){return e.find(r=>r.canHandle(t))??null}var rm=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,nm=new Set(["import"]),sm=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function om(t,e,r,n){let s;try{s=await Co.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let o=vo(t,n);if(!o)return{path:t,status:"unchanged"};let i=o.apply(t,s,e);return i===s?{path:t,status:"unchanged"}:(r||await Co.writeFile(t,i,"utf8"),{path:t,status:"updated"})}async function im(t,e,r){let n=Gt(e),s=n.tagApplier?.framework??"vitest",o=n.tagApplier?.frameworkOverrides??{},i=ko(s,o,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let c of t.nodes.values()){if(c.category!=="test")continue;let l=new Set,p=[];for(let d of c.tags)nm.has(d.kind)&&rm.test(d.name)&&(sm.has(d.name.toLowerCase())||l.has(d.name)||(l.add(d.name),p.push(d.name)));p.sort();let u=tm.resolve(e,c.path),g=await om(u,p,r.dryRun,i);g.path=c.path,a.files.push(g),g.status==="updated"?a.updated++:g.status==="unchanged"?a.unchanged++:a.errors++}return a}var Nt=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};function wo(t,e){return{identifier:e?.identifier??new Nt,featureMap:e?.featureDetection===!1?new Map:De(t.nodes,e?.featureDetection??void 0)}}function Eo(t,e,r,n,s){for(let o of e){let i=t.nodes.get(o);if(!i)continue;let a=new ee(o,["*",...i.exports.map(c=>c.name)]);t.traverse(o,(c,l,p)=>{if(!p)return!0;if(!a.updateAffectedSymbols(c,p))return!1;if(l>0){let u=r.get(c.path);if(u)return n(u),!1}return s(c),!0},{direction:"incoming"})}}function am(t,e,r){let{identifier:n,featureMap:s}=wo(t,r),o=new Set;for(let i of e){let a=s.get(i);a&&o.add(a.tag)}return Eo(t,e,s,i=>o.add(i.tag),i=>{if(n.isTestNode(i))for(let a of i.tags)o.add(a.name)}),Array.from(o)}function cm(t,e,r){let{identifier:n,featureMap:s}=wo(t,r),o=new Set;return Eo(t,e,s,()=>{},i=>{n.isTestNode(i)&&o.add(i.path)}),Array.from(o)}import lm from"crypto";import To from"fs";import pm from"os";import K from"path";async function Hk(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},o=K.resolve(t);return await new q(o,r,n.pathAliases?new $(o,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0,n.additionalIgnoreDirs??[],n.docFiles??null).build(e)}function um(t){let e=Number.parseInt(process.env.MOKOSH_WORKSPACE_CONCURRENCY??"",10),r=Number.isFinite(e)&&e>0?e:pm.cpus().length||1;return Math.max(1,Math.min(r,Math.max(1,t)))}function mm(t,e,r){let n=new Map(e.map(o=>[o.name,[]])),s=[...e].sort((o,i)=>i.root.length-o.root.length);for(let o of r){if(!o.endsWith(".md")&&!o.endsWith(".mdx"))continue;let i=K.join(t,o),a=s.find(c=>i===c.root||i.startsWith(`${c.root}${K.sep}`));a&&n.get(a.name)?.push(i)}return n}function Uk(t){let e=Fo(t),r=lm.createHash("sha256");for(let n of[...e].sort()){let s=`${n}\0?\0?`;try{let o=To.statSync(K.join(t,n));s=`${n}\0${o.mtimeMs}\0${o.size}`}catch{}r.update(`${s}
52
- `)}return{digest:r.digest("hex"),files:e}}async function Kk(t,e={}){let r=K.resolve(t),n=e.layout??Tr(r),s=e.projectFiles??Fo(r),o=e.additionalIgnoreDirs??[],i=e.packages?n.packages.filter(S=>e.packages?.includes(S.name)||e.packages?.includes(S.relativeRoot)):n.packages,a=new Map(n.packages.map(S=>[S.name,S.root])),c=new Le(r,n.type),l=new Z(o),p=mm(r,i,s),u=um(i.length),g=u>1?!1:e.parallelParsing??!0,d=new Array(i.length),y=0,k=async()=>{for(let S=y++;S<i.length;S=y++){let v=i[S],R=e.silent?void 0:w=>{process.stderr.write(`[${v.name}] Processed ${w} files...\r`)},x=new q(r,e.previousWorkspace?.packages.get(v.name)?.graph??null,new $(r,{workspaceMap:a,tsconfigSearchPaths:[v.root,r],pathAliases:e.pathAliases,langResolvers:rt({jvm:l})}),R,e.gitStats??!1,new Map,g,o,p.get(v.name)??[]);d[S]=await x.build(v.entryPoints)}};return await Promise.all(Array.from({length:u},k)),i.forEach((S,v)=>{c.addPackage(S,d[v])}),c.annotateCrossPackageEdges(),c}function Fo(t,e={}){let r=[],n=new Set([...e.ignoreDirs??I,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??zt,...e.additionalExtensions??[]]);function o(i){try{let a=To.readdirSync(i,{withFileTypes:!0});for(let c of a){let l=K.join(i,c.name);c.isDirectory()?n.has(c.name)||o(l):c.isFile()&&s.has(K.extname(c.name).toLowerCase())&&r.push(K.relative(t,l))}}catch{}}return o(t),r}export{qe as CALL_EDGE_TYPES,Wt as DEFAULT_BRANCH_GRAPH_CACHE_DIR,jt as DEFAULT_CACHE_DIR,$t as DEFAULT_DUPLICATION_TOKEN_CACHE_FILE,zt as DEFAULT_EXTENSIONS,jo as DEFAULT_GRAPH_CACHE_FILE,I as DEFAULT_IGNORE_DIRS,$o as DEFAULT_WORKSPACE_GRAPH_CACHE_FILE,us as EXPORT_TRACKING_TYPES,L as Graph,se as GraphAnalyzer,ms as IMPORT_SYMBOL_TYPES,Bt as MermaidExporter,ee as SymbolTraversalContext,Le as WorkspaceGraph,Oo as applyConfig,im as applyTags,Xo as buildApiSurface,ei as buildChangeImpactCache,kr as buildFeatureGraph,Ws as buildGraphAtRef,pp as buildResponsibilityGraph,gp as buildTypeGraph,ql as compareBranches,Ut as computeGraphHash,Uk as computeWorkspaceSourceDigest,Go as configToGraphOptions,Hk as createImportMap,Kk as createWorkspaceGraph,rn as detectAllEntryPoints,Ko as detectEntryPoint,De as detectFeatures,Tr as detectMonorepo,lo as filterGraph,ct as findComplexFunctions,at as findDuplicates,pt as findRiskHotspots,up as findSymbol,Al as getAffected,Fo as getAllProjectFiles,Ll as getCallers,Ml as getDependencies,yr as getDependents,Gc as getLanguageCoverage,Dl as getNodeMeta,As as hasChurnData,lt as hasCoverageData,Pe as hasGeneratedMarker,ri as isChangeImpactCacheValid,st as isGeneratedPath,si as loadChangeImpactCache,zo as loadCoverageMap,Gt as loadMokoshConfig,ot as loadTokenCacheFromDisk,mo as parseQuery,cm as proposeAffectedTests,am as proposeTags,Zo as queryCallGraph,ti as queryChangeImpact,dp as queryTypeGraph,Ge as registerConfigMatcher,M as registerMonorepoDetector,ae as registerParser,$e as registerTestLibrary,je as registerTestPattern,We as resetClassifyRegistries,ni as saveChangeImpactCache,it as saveTokenCacheToDisk,_l as slimSerialize,Kl as summarizeBranchComparison,ao as summarizeWorkspaceLayout,Ol as summarizeWorkspacePackages,qr as toMermaid};
55
+ `;return`${l+m+u+o}
56
+ ${p}`}};function mg(t){let e=t.split(`
57
+ `),n=-1;return e.forEach((s,i)=>{(s.trimStart().startsWith("import ")||s.trimStart().startsWith("from "))&&(n=i)}),n<0?0:e.slice(0,n+1).reduce((s,i)=>s+i.length+1,0)}import gg from"path";var Fr=/^\/\/ mokosh:tags .*\n/m,dg=/^(?:sealed\s+|abstract\s+|final\s+|private\s+|implicit\s+|case\s+)*(?:class|object|trait)\s+\w+/m,hg=/\/src\/(test|it)\//,yg=/(Spec|Suite|Test|Props)\.scala$/;function xg(t){let e=Fr.exec(t);return e?e[0].replace(/^\/\/ mokosh:tags /,"").trim().split(/\s*,\s*/).filter(Boolean):null}var Zt=class{name="scalatest";canHandle(e){let n=e.replace(/\\/g,"/");return gg.extname(n).toLowerCase()!==".scala"?!1:hg.test(n)||yg.test(n)}apply(e,n,r){let s=xg(n),i=[...r].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return n;if(r.length===0)return s===null?n:n.replace(Fr,"");let o=`// mokosh:tags ${i.join(", ")}
58
+ `;if(s!==null)return n.replace(Fr,o);let a=dg.exec(n);return a?n.slice(0,a.index)+o+n.slice(a.index):n}};import $o from"path";import Wo from"typescript";var Sg=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,qt=class{name="vitest";canHandle(e){return z.has($o.extname(e).toLowerCase())}apply(e,n,r){let s=n.replace(Sg,""),i=Wo.createSourceFile($o.basename(e),s,Wo.ScriptTarget.Latest,!0),o=dr(i),[a]=o;if(!a)return s;let c=hr(a,"tags",i),l=[...r].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=o.flatMap(u=>{let m=r.length===0?xr(u,"tags",i):yr(u,"tags",br(l),i);return m?[m]:[]});return p.length>0?Sr(s,p):s}};var zo={vitest:()=>new qt,playwright:()=>new Yt,cypress:()=>new Ut,jest:()=>new Vt},bg={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function kg(t){let e=en.createSourceFile("detect.ts",t,en.ScriptTarget.Latest,!0);for(let n of e.statements){if(!en.isImportDeclaration(n)||!en.isStringLiteral(n.moduleSpecifier))continue;let r=bg[n.moduleSpecifier.text];if(r)return r}return null}var Nr=class{constructor(e,n,r){this.rootDir=e;this.defaultFramework=n;this.frameworkOverrides=r}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return z.has(Dr.extname(e).toLowerCase())}apply(e,n,r){let s=kg(n)??this.matchOverride(e)??this.defaultFramework;return(zo[s]??zo.vitest)().apply(e,n,r)}matchOverride(e){let n=Dr.relative(this.rootDir,e).split(Dr.sep).join("/");for(let[r,s]of this.frameworkOverrides)if(Go(r,n))return s;return null}};function Bo(t="vitest",e={},n=process.cwd()){return[new Ht,new Xt,new Jt,new Qt,new Zt,new Nr(n,t,Object.entries(e))]}function Ko(t,e){return e.find(n=>n.canHandle(t))??null}async function Cg(t,e,n,r){let s;try{s=await Uo.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let i=Ko(t,r);if(!i)return{path:t,status:"unchanged"};let o=i.apply(t,s,e);return o===s?{path:t,status:"unchanged"}:(n||await Uo.writeFile(t,o,"utf8"),{path:t,status:"updated"})}async function Eg(t,e,n){let r=xn(e),s=r.tagApplier?.framework??"vitest",i=r.tagApplier?.frameworkOverrides??{},o=Bo(s,i,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let c of t.nodes.values()){if(c.category!=="test")continue;let l=new Set,p=[];for(let d of c.tags)ne(d)&&(l.has(d.name)||(l.add(d.name),p.push(d.name)));p.sort();let u=vg.resolve(e,c.path),m=await Cg(u,p,n.dryRun,o);m.path=c.path,a.files.push(m),m.status==="updated"?a.updated++:m.status==="unchanged"?a.unchanged++:a.errors++}return a}var tn=class{isTestNode(e){return e.category==="test"||e.tags.some(n=>n.name==="test")}};function Ho(t,e){return{identifier:e?.identifier??new tn,featureMap:e?.featureDetection===!1?new Map:Xe(t.nodes,e?.featureDetection??void 0)}}function Jo(t,e,n,r,s){for(let i of e){let o=t.nodes.get(i);if(!o)continue;let a=new pe(i,["*",...o.exports.map(c=>c.name)]);t.traverse(i,(c,l,p)=>{if(!p)return!0;if(!a.updateAffectedSymbols(c,p))return!1;if(l>0){let u=n.get(c.path);if(u)return r(u),!1}return s(c),!0},{direction:"incoming"})}}function wg(t,e,n){let{identifier:r,featureMap:s}=Ho(t,n),i=new Set;for(let o of e){let a=s.get(o);a&&i.add(a.tag)}return Jo(t,e,s,o=>i.add(o.tag),o=>{if(r.isTestNode(o))for(let a of hn(o.tags))i.add(a)}),Array.from(i)}function Tg(t,e,n){let{identifier:r,featureMap:s}=Ho(t,n),i=new Set;return Jo(t,e,s,()=>{},o=>{r.isTestNode(o)&&i.add(o.path)}),Array.from(i)}import Vo from"crypto";import Qo from"fs";import Fg from"os";import ee from"path";async function rw(t,e,n=null,r={}){let s=r.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},i=ee.resolve(t);return await new le(i,n,r.pathAliases?new H(i,{pathAliases:r.pathAliases}):void 0,s,r.gitStats??!1,r.coverageMap??new Map,r.parallelParsing??!0,r.additionalIgnoreDirs??[],r.docFiles??null).build(e)}function Dg(t){let e=Number.parseInt(process.env.MOKOSH_WORKSPACE_CONCURRENCY??"",10),n=Number.isFinite(e)&&e>0?e:Fg.cpus().length||1;return Math.max(1,Math.min(n,Math.max(1,t)))}function Ng(t,e,n){let r=new Map(e.map(i=>[i.name,[]])),s=[...e].sort((i,o)=>o.root.length-i.root.length);for(let i of n){if(!i.endsWith(".md")&&!i.endsWith(".mdx"))continue;let o=ee.join(t,i),a=s.find(c=>o===c.root||o.startsWith(`${c.root}${ee.sep}`));a&&r.get(a.name)?.push(o)}return r}function sw(t){let e=Xo(t),n=Vo.createHash("sha256");for(let r of[...e].sort())n.update(`${Yo(t,r)}
59
+ `);return{digest:n.digest("hex"),files:e}}function Yo(t,e){try{let n=Qo.statSync(ee.join(t,e));return`${e}\0${n.mtimeMs}\0${n.size}`}catch{return`${e}\0?\0?`}}function iw(t,e,n){let r=[...e].sort((c,l)=>l.relativeRoot.length-c.relativeRoot.length),s=new Map(e.map(c=>[c.name,[]])),i=[];for(let c of n){let l=r.find(p=>Bt(c,p));(l?s.get(l.name):i).push(c)}let o=c=>{let l=Vo.createHash("sha256");for(let p of[...c].sort())l.update(`${Yo(t,p)}
60
+ `);return l.digest("hex")},a=new Map;for(let[c,l]of s)a.set(c,o(l));return{rootDigest:o(i),packageDigests:a}}async function ow(t,e={}){let n=ee.resolve(t),r=e.layout??mr(n),s=e.projectFiles??Xo(n),i=e.additionalIgnoreDirs??[],o=e.packages?r.packages.filter(b=>e.packages?.includes(b.name)||e.packages?.includes(b.relativeRoot)):r.packages,a=new Map(r.packages.map(b=>[b.name,b.root])),c=new et(n,r.type),l=new ce(i),p=Ng(n,o,s),u=Dg(o.length),m=u>1?!1:e.parallelParsing??!0,d=new Array(o.length),y=0,k=async()=>{for(let b=y++;b<o.length;b=y++){let v=o[b],L=e.silent?void 0:_=>{process.stderr.write(`[${v.name}] Processed ${_} files...\r`)},A=new le(n,e.previousWorkspace?.packages.get(v.name)?.graph??null,new H(n,{workspaceMap:a,tsconfigSearchPaths:[v.root,n],pathAliases:e.pathAliases,langResolvers:Tt({jvm:l})}),L,e.gitStats??!1,new Map,m,i,p.get(v.name)??[]);d[b]=await A.build(v.entryPoints)}};return await Promise.all(Array.from({length:u},k)),o.forEach((b,v)=>{c.addPackage(b,d[v])}),c.annotateCrossPackageEdges(),c}function Xo(t,e={}){let n=[],r=new Set([...e.ignoreDirs??I,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??vn,...e.additionalExtensions??[]]);function i(o){try{let a=Qo.readdirSync(o,{withFileTypes:!0});for(let c of a){let l=ee.join(o,c.name);c.isDirectory()?r.has(c.name)||i(l):c.isFile()&&s.has(ee.extname(c.name).toLowerCase())&&n.push(ee.relative(t,l))}}catch{}}return i(t),n}export{je as CALL_EDGE_TYPES,Or as CATEGORY_MARKER_TAGS,kn as DEFAULT_BRANCH_GRAPH_CACHE_DIR,Sn as DEFAULT_CACHE_DIR,pa as DEFAULT_DUPLICATION_RESULT_CACHE_FILE,bn as DEFAULT_DUPLICATION_TOKEN_CACHE_FILE,vn as DEFAULT_EXTENSIONS,ua as DEFAULT_GRAPH_CACHE_FILE,I as DEFAULT_IGNORE_DIRS,lt as DEFAULT_TAG_BLOCKLIST,uo as DEFAULT_TAG_LIMIT,po as DEFAULT_TAG_MIN_COUNT,ma as DEFAULT_WORKSPACE_CACHE_SUBDIR,fa as DEFAULT_WORKSPACE_GRAPH_CACHE_FILE,ni as EXPORT_TRACKING_TYPES,si as FUNCTION_COMPLEXITY_TYPES,O as Graph,he as GraphAnalyzer,ri as IMPORT_SYMBOL_TYPES,Un as LANGUAGE_FIDELITY,ha as MAX_PACKAGE_CACHE_BYTES,Cn as MermaidExporter,ct as SELECTION_TAG_KINDS,or as SUMMARY_TAG_KINDS,pe as SymbolTraversalContext,ar as TAG_RESPONSE_HARD_CAP,bp as TEST_TAG_STRATEGY_TYPES,ii as TYPE_GRAPH_TYPES,jr as VALID_TAG_NAME_RE,da as WORKSPACE_CACHE_VERSION,ga as WORKSPACE_MANIFEST_FILE,et as WorkspaceGraph,ca as applyConfig,yi as applyDupQuery,Eg as applyTags,Ma as buildApiSurface,Oa as buildChangeImpactCache,ir as buildFeatureGraph,ao as buildGraphAtRef,Nf as buildResponsibilityGraph,Pf as buildTagInventory,Mf as buildTypeGraph,xf as compareBranches,En as computeGraphHash,iw as computeWorkspacePackageDigests,sw as computeWorkspaceSourceDigest,la as configToGraphOptions,gn as configureTagQuality,rw as createImportMap,ow as createWorkspaceGraph,Yi as dedupeGroupsAgainstClusters,Jr as detectAllEntryPoints,Fa as detectEntryPoint,Xe as detectFeatures,mr as detectMonorepo,Ki as duplicationDigest,Ui as duplicationResultCacheKey,Lo as filterGraph,It as findComplexFunctions,At as findDuplicates,_t as findRiskHotspots,Rf as findSymbol,Xu as getAffected,Xo as getAllProjectFiles,Zu as getCallers,Yu as getDependencies,tr as getDependents,Dp as getLanguageCoverage,Qu as getNodeMeta,eo as hasChurnData,Mt as hasCoverageData,Je as hasGeneratedMarker,tf as hasGitTimestampData,$a as isChangeImpactCacheValid,Nt as isGeneratedPath,ne as isSelectionTag,pt as isSelectionTagName,oi as languageCaveats,Fp as languageCaveatsSummary,Cp as languageSupportNote,za as loadChangeImpactCache,xa as loadCoverageMap,Hi as loadDuplicationResult,xn as loadMokoshConfig,Pt as loadTokenCacheFromDisk,He as matchDupGroup,Bt as packageOwnsFile,Dt as parseDupQuery,Mo as parseQuery,Tg as proposeAffectedTests,wg as proposeTags,_a as queryCallGraph,ja as queryChangeImpact,_f as queryTypeGraph,st as registerConfigMatcher,W as registerMonorepoDetector,Se as registerParser,ot as registerTestLibrary,it as registerTestPattern,at as resetClassifyRegistries,dn as resetTagQuality,Wa as saveChangeImpactCache,Ji as saveDuplicationResult,Lt as saveTokenCacheToDisk,hn as selectionTagNames,qi as slimDupCluster,Zi as slimDupGroup,Qe as slimOccurrences,qu as slimSerialize,Yn as sortLimitDupGroups,Ea as summarizeApiSurface,uf as summarizeBranchComparison,Xi as summarizeDuplicates,Lf as summarizeTagInventory,Po as summarizeWorkspaceLayout,ef as summarizeWorkspacePackages,Kr as toMermaid,qn as topDir};
53
61
  //# sourceMappingURL=index.mjs.map