@omfalos/mokosh 0.4.3 → 0.4.4

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/mcp.js CHANGED
@@ -1,41 +1,41 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var _o=Object.create;var Re=Object.defineProperty;var Oo=Object.getOwnPropertyDescriptor;var jo=Object.getOwnPropertyNames;var zo=Object.getPrototypeOf,Wo=Object.prototype.hasOwnProperty;var Bo=(t,e)=>{for(var r in e)Re(t,r,{get:e[r],enumerable:!0})},$r=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of jo(e))!Wo.call(t,s)&&s!==r&&Re(t,s,{get:()=>e[s],enumerable:!(n=Oo(e,s))||n.enumerable});return t};var g=(t,e,r)=>(r=t!=null?_o(zo(t)):{},$r(e||!t||!t.__esModule?Re(r,"default",{value:t,enumerable:!0}):r,t)),$o=t=>$r(Re({},"__esModule",{value:!0}),t);var Dl={};Bo(Dl,{createMcpServer:()=>kt});module.exports=$o(Dl);var Go=require("@modelcontextprotocol/sdk/server/stdio.js");var Lo=require("@modelcontextprotocol/sdk/server/index.js"),St=require("@modelcontextprotocol/sdk/types.js");var ht=g(require("fs")),yt=g(require("path"));var Oe=g(require("fs")),Ft=g(require("path"));var Uo=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Ur=[];function Le(t){Ur.push(t)}function Hr(t){return[...Uo,...Ur].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Ho=[".test.",".spec.","-test.","-spec."],Kr=[];function Ge(t){Kr.push(t)}function ue(){return[...Ho,...Kr]}var Ko=["jest","vitest","playwright","cypress","@testing-library/"],Jr=[];function _e(t){Jr.push(t)}function Ct(){return[...Ko,...Jr]}var Vr=.8;function vt(t){Vr=t}function wt(){return Vr}var Jo=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function fe(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=Ft.default.resolve(t);return Oe.default.existsSync(n)?n.endsWith(".json")?Qr(n):e?qr(n):{}:{}}for(let n of Jo){let s=Ft.default.resolve(t,n);if(Oe.default.existsSync(s)){if(n.endsWith(".json"))return Qr(s);if(e)return qr(s)}}return{}}function Qr(t){return JSON.parse(Oe.default.readFileSync(t,"utf-8"))}function qr(t){let e=require(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function Tt(t){for(let e of t.configMatchers??[])Le(e);for(let e of t.testPatterns??[])Ge(e);for(let e of t.testLibraries??[])_e(e);t.barrelThreshold!==void 0&&vt(t.barrelThreshold)}function Z(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var je="mokosh-cache",Et="duplication-tokens.json",At="graph.json",z=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],Pt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];var Yr=g(require("fs")),Nt=g(require("path"));function It(t,e){let r=Nt.default.resolve(t,e);try{let n=Yr.default.readFileSync(r,"utf-8"),s=JSON.parse(n),o=new Map;for(let[i,a]of Object.entries(s)){if(i==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Nt.default.relative(t,i);o.set(l,c)}return o}catch{return new Map}}var ze={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(`
3
- `)}};var Mt=g(require("fs")),Xr=g(require("path"));function Dt(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 Zr(t,e){if(typeof t=="string")return Dt(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=Zr(r[n],e);if(s)return s}}return null}function Qo(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 qo(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 Rt(t,e){let r=[],n=Xr.default.join(e,"package.json");if(Mt.default.existsSync(n))try{let s=JSON.parse(Mt.default.readFileSync(n,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let o of Object.values(s.exports)){let i=Zr(o,t);i&&!r.includes(i)&&r.push(i)}else if(typeof s.exports=="string"){let o=Dt(s.exports,t);o&&r.push(o)}if(r.length===0)for(let o of[s.main,s.module].filter(Boolean)){let i=Dt(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 Yo(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 Xo(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 Zo(t,e,r,n){let s=[];for(let o of t){let i=e.get(o),a=n.flatMap(f=>r.nodes.get(f)?.exports??[]).find(f=>f.name===o),c=i?.symbol??a,l=i?.file??n.find(f=>r.nodes.get(f)?.exports.some(d=>d.name===o))??n[0],p={name:o,definedIn:l,kind:Qo(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 ei(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 Lt(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=Yo(t,e),n=Xo(t,r,e),s=qo(t,e),o=Zo(s,n,t,e),{internalFiles:i,unreachableFromEntry:a,testFiles:c}=ei(t,r,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:c}}function Gt(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}}var ti=g(require("fs")),ri=g(require("path"));function en(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 _t(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:en(t)}}function Ot(t,e){return t.impact.get(e)??[]}var $t=require("fs/promises"),te=g(require("path")),kn=g(require("piscina"));var me=g(require("fs")),tn=g(require("path")),jt=require("js-yaml"),zt=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function rn(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function ni(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)),rn(r)}).filter(Boolean)}function si(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 oi(t){try{let e=(0,jt.load)(t),r={dependencies:{}};for(let[n,s]of Object.entries(e))if(!(n==="__metadata"||!s?.version))for(let o of n.split(", ")){let i=rn(o);i&&(r.dependencies[i]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function ii(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=ni(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 ai(t){let e=me.default.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 ci(t){let e=me.default.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=oi(e);if(r!==null)return r}return ii(e)}function li(t){let e=me.default.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=(0,jt.load)(e);if(n.packages)for(let[s,o]of Object.entries(n.packages)){let{name:i,version:a}=si(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}function nn(t){let e={"package-lock.json":ai,"yarn.lock":ci,"pnpm-lock.yaml":li},r=zt.map(n=>[n,e[n]]);for(let[n,s]of r){let o=tn.default.join(t,n);if(me.default.existsSync(o))return s(o)}return null}var pi=new Set(["css","scss","less","stylus"]);function sn(t){return pi.has(t)?"style":"code"}var Wt=g(require("postcss")),ui=g(require("postcss-less")),fi=ui,an=new Set(["reference","inline"]);function on(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function mi(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function gi(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let o=r[1]?.trim()??"",i=r[2]??"";if(!i)return null;let a=an.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...on(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",...on(s)?{isExternal:!0}:{}}:null}function di(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let o=s[1]?.trim()??"";mi(o)&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function cn(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=gi(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...di(n.value,e))}),r}function hi(t){return t.replace(/(?<!:)\/\/.*/g,"")}function yi(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=an.has(o)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}s=n.exec(t)}return r}function We(t,e){let r=Wt.default.parse(hi(t));return{imports:cn(r,e),root:r}}function xi(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 Be(t,e){try{let r=fi.parse(t),{exports:n,tags:s}=xi(r);return{imports:cn(r,e),root:r,exports:n,tags:s}}catch{return{imports:yi(t,e),root:Wt.default.parse(""),exports:[],tags:[]}}}var pn=require("postcss-scss");function ln(t){return t.startsWith("_")||t.startsWith("-")}function bi(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Si(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 ki(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||ln(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||ln(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 $e(t,e){let r=(0,pn.parse)(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}=Si(c);if(!l)return;let f={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...bi(l)?{isExternal:!0}:{}};p&&(f.symbols=[p]),n.push(f)});let{exports:s,tags:o}=ki(r);return{imports:n,root:r,exports:s,tags:o}}function Ci(t){return t.trim().replace(/\s+/g," ")}function vi(t){try{return t.fileType==="scss"?$e(t.source,t.file).root:t.fileType==="less"?Be(t.source,t.file).root:t.fileType==="css"?We(t.source,t.file).root:void 0}catch{return}}function wi(t){let e=vi(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()}:${Ci(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function un(t,e,r=2){let n=new Map;for(let o of t)for(let i of wi(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},f={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,f],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((o,i)=>i.lines-o.lines)}function fn(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 Fi=new Set(["{","}",":",",","[","]"]);function mn(t,e,r){let n=0;for(let s=e;s<e+r;s++)Fi.has(t[s].text)&&n++;return n/r}function gn(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],f=i(c)===i(l);s[l]=s[c]+(p&&f?0:1)}if([n,s]=[s,n],n[r[e-1]]===e-1)break}return r}function dn(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 hn(t,e,r,n=.5){let s=[],o=[],i=new Map;for(let{file:f,tokens:d}of t)if(d.length!==0){i.set(f,d);for(let h=0;h<d.length;h++)s.push(d[h].text),o.push({file:f,localIndex:h});s.push(` ${f}`),o.push({file:f,localIndex:-1})}if(s.length===0)return[];let a=gn(s),c=dn(s,a),l=fn(c),p=[];for(let f of l){let d=Ti(f,a,o,i,e,r,n);d&&p.push(d)}return p.sort((f,d)=>d.lines-f.lines)}function Ti(t,e,r,n,s,o,i){if(t.lcpLength<s)return;let a=[];for(let h=t.low;h<=t.high;h++){let C=r[e[h]];C.localIndex!==-1&&a.push(C)}if(a.length<2||!Ei(a,n))return;let c=Ai(a,t.lcpLength);if(c.length<2)return;let l=c[0],p=n.get(l.file);if(mn(p,l.localIndex,t.lcpLength)>i)return;let f=c.map(({file:h,localIndex:C})=>{let v=n.get(h);return{file:h,startLine:v[C].line,endLine:v[C+t.lcpLength-1].line}}),d=Math.min(...f.map(h=>h.endLine-h.startLine+1));if(!(d<o))return{occurrences:f,lines:d,tokens:t.lcpLength}}function Ei(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 Ai(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 Pi={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{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 yn(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function Ni(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=yn(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(`
5
- `,o),a=i===-1?r.length:i;r=yn(r,o,a),s=a}}return r}var Ii=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],Bt=new RegExp(`${Ii.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),Mi=/^[A-Za-z_$][A-Za-z0-9_$]*$/,xn=/^\d+(?:\.\d+)?$/,Di=/^(".*"|'.*'|`.*`)$/s,Ri=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 bn(t,e,r=!0){let n=Ni(t,Pi[e]),s=[],o=1,i=0;Bt.lastIndex=0;let a=Bt.exec(n);for(;a!==null;){for(let p=i;p<a.index;p++)n[p]===`
6
- `&&o++;i=a.index;let c=a[0],l=c;Mi.test(c)&&!Ri.has(c)?l="ID":r&&(xn.test(c)||Di.test(c))&&(l=xn.test(c)?"NUM":"STR"),s.push({text:l,line:o});for(let p=i;p<a.index+c.length;p++)n[p]===`
7
- `&&o++;i=a.index+c.length,a=Bt.exec(n)}return s}var ee=g(require("fs")),Sn=g(require("path"));function Li(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mtime=="number"&&typeof e.size=="number"&&typeof e.ignoreLiterals=="boolean"&&Array.isArray(e.tokens)}function Ue(t){try{if(!ee.default.existsSync(t))return new Map;let e=ee.default.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"&&Li(s[1]));return new Map(n)}catch{return new Map}}function He(t,e){let r=Sn.default.dirname(e);ee.default.existsSync(r)||ee.default.mkdirSync(r,{recursive:!0}),ee.default.writeFileSync(e,JSON.stringify([...t.entries()]))}var Gi=20,_i=new Set(["css","scss","less"]);function Oi(t){return zt.includes(te.default.basename(t))}function ji(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(te.default.sep).some(n=>r.has(n))}async function Ut(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:o=!0,maxPunctuationRatio:i=.5,limit:a=50,ignoreDirs:c=z,parallelTokenizing:l=!0,tokenCache:p}=r,f=[...t.nodes.values()].filter(h=>!Oi(h.path)&&!ji(h.path,c)),d=zi(l,f.length);try{let h=[],C=new Map;if(await Promise.all(f.map(async y=>{if(_i.has(y.type)){let X;try{X=await(0,$t.readFile)(te.default.join(e,y.path),"utf8")}catch{return}h.push({file:y.path,source:X,fileType:y.type});return}let k=p?.get(y.path),M=k&&k.mtime===y.mtime&&k.size===y.size&&k.ignoreLiterals===o,N;if(M)N=k.tokens;else{let X;try{X=await(0,$t.readFile)(te.default.join(e,y.path),"utf8")}catch{return}N=d?await d.run({source:X,fileType:y.type,ignoreLiterals:o}):bn(X,y.type,o),p?.set(y.path,{mtime:y.mtime,size:y.size,ignoreLiterals:o,tokens:N})}let j=sn(y.type),Wr={file:y.path,tokens:N},Br=C.get(j);Br?Br.push(Wr):C.set(j,[Wr])})),p){let y=new Set(f.map(k=>k.path));for(let k of p.keys())y.has(k)||p.delete(k)}let v=un(h,n);for(let[y,k]of C)for(let M of hn(k,s,n,i))v.push({...M,family:y});return{groups:v.sort((y,k)=>k.lines-y.lines).slice(0,a)}}finally{d&&await d.destroy()}}function zi(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??Gi;if(e<n)return null;r.maxThreads!==void 0&&r.maxThreads<1&&process.stderr.write(`
2
+ "use strict";var Oi=Object.create;var Re=Object.defineProperty;var ji=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Wi=Object.getPrototypeOf,Bi=Object.prototype.hasOwnProperty;var $i=(t,e)=>{for(var r in e)Re(t,r,{get:e[r],enumerable:!0})},Vr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of zi(e))!Bi.call(t,s)&&s!==r&&Re(t,s,{get:()=>e[s],enumerable:!(n=ji(e,s))||n.enumerable});return t};var g=(t,e,r)=>(r=t!=null?Oi(Wi(t)):{},Vr(e||!t||!t.__esModule?Re(r,"default",{value:t,enumerable:!0}):r,t)),Ui=t=>Vr(Re({},"__esModule",{value:!0}),t);var Ll={};$i(Ll,{createMcpServer:()=>Ct});module.exports=Ui(Ll);var _i=require("@modelcontextprotocol/sdk/server/stdio.js");var Gi=require("@modelcontextprotocol/sdk/server/index.js"),kt=require("@modelcontextprotocol/sdk/types.js");var yt=g(require("fs")),xt=g(require("path"));var je=g(require("fs")),Nt=g(require("path"));var Hi=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],vt=[];function Le(t){vt.push(t)}function Qr(t){return[...Hi,...vt].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Ki=[".test.",".spec.","-test.","-spec."],wt=[];function Ge(t){wt.push(t)}function ue(){return[...Ki,...wt]}var Ji=["jest","vitest","playwright","cypress","@testing-library/"],Ft=[];function _e(t){Ft.push(t)}function Tt(){return[...Ji,...Ft]}var qr=.8,Et=qr;function At(t){Et=t}function Pt(){return Et}function Oe(){vt.length=0,wt.length=0,Ft.length=0,Et=qr}var Vi=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function fe(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=Nt.default.resolve(t);return je.default.existsSync(n)?n.endsWith(".json")?Yr(n):e?Xr(n):{}:{}}for(let n of Vi){let s=Nt.default.resolve(t,n);if(je.default.existsSync(s)){if(n.endsWith(".json"))return Yr(s);if(e)return Xr(s)}}return{}}function Yr(t){return JSON.parse(je.default.readFileSync(t,"utf-8"))}function Xr(t){let e=require(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function It(t){Oe();for(let e of t.configMatchers??[])Le(e);for(let e of t.testPatterns??[])Ge(e);for(let e of t.testLibraries??[])_e(e);t.barrelThreshold!==void 0&&At(t.barrelThreshold)}function Z(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var ze="mokosh-cache",Dt="duplication-tokens.json",Mt="graph.json",z=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],Rt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];var Zr=g(require("fs")),Lt=g(require("path"));function Gt(t,e){let r=Lt.default.resolve(t,e);try{let n=Zr.default.readFileSync(r,"utf-8"),s=JSON.parse(n),i=new Map;for(let[o,a]of Object.entries(s)){if(o==="total")continue;let c=a?.lines?.pct;if(typeof c!="number")continue;let l=Lt.default.relative(t,o);i.set(l,c)}return i}catch{return new Map}}var We={serialize(t){let e=["graph TD"],r=new Set;for(let n of t.nodes.values()){let s=`"${n.path}"`;for(let i of n.imports){if(!i.toPath)continue;let o=`"${i.toPath}"`,a=`${n.path} -> ${i.toPath}`;if(!r.has(a)){let c=i.isStyle?"-- styles -->":"-->";e.push(` ${s} ${c} ${o}`),r.add(a)}}}return e.join(`
3
+ `)}};var _t=g(require("fs")),en=g(require("path"));function Ot(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 Ot(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 qi(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 Yi(t,e){let r=new Set,n=new Set,s=[...e];for(;s.length;){let i=s.shift();if(n.has(i))continue;n.add(i);let o=t.nodes.get(i);if(o){for(let a of o.exports)r.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)r.add(p.name);s.push(a.toPath)}else for(let l of a.symbols)r.add(l)}}}return r}function jt(t,e){let r=[],n=en.default.join(e,"package.json");if(_t.default.existsSync(n))try{let s=JSON.parse(_t.default.readFileSync(n,"utf8"));if(s.exports&&typeof s.exports=="object"&&!Array.isArray(s.exports))for(let i of Object.values(s.exports)){let o=tn(i,t);o&&!r.includes(o)&&r.push(o)}else if(typeof s.exports=="string"){let i=Ot(s.exports,t);i&&r.push(i)}if(r.length===0)for(let i of[s.main,s.module].filter(Boolean)){let o=Ot(i,t);o&&!r.includes(o)&&r.push(o)}}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 Xi(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 Zi(t,e,r){let n=new Map;for(let s of e){if(r.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=n.get(a.name),l=!!(a.signature||a.doc);(!c||l&&!o)&&n.set(a.name,{file:s,symbol:a})}}return n}function eo(t,e,r,n){let s=[];for(let i of t){let o=e.get(i),a=n.flatMap(u=>r.nodes.get(u)?.exports??[]).find(u=>u.name===i),c=o?.symbol??a,l=o?.file??n.find(u=>r.nodes.get(u)?.exports.some(d=>d.name===i))??n[0],p={name:i,definedIn:l,kind:qi(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 to(t,e,r){let n=c=>t.nodes.get(c)?.category==="test",s=[...e].filter(c=>!r.includes(c)&&!n(c)),i=[...t.nodes.keys()].filter(c=>!e.has(c)),o=i.filter(c=>!n(c)),a=i.filter(c=>n(c));return{internalFiles:s,unreachableFromEntry:o,testFiles:a}}function zt(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=Xi(t,e),n=Zi(t,r,e),s=Yi(t,e),i=eo(s,n,t,e),{internalFiles:o,unreachableFromEntry:a,testFiles:c}=to(t,r,e);return{entryPoints:e,publicExports:i,internalFiles:o,unreachableFromEntry:a,testFiles:c}}function Wt(t,e){let r=null,n=[];for(let i of t.nodes.values()){i.exports.some(o=>o.name===e)&&(r=i.path);for(let o of i.callEdges??[])o.to===e&&n.push({file:i.path,callerFunction:o.from})}let s=[];if(r){let i=t.nodes.get(r);for(let o of i?.callEdges??[])o.from===e&&s.push({file:o.toFile,calleeFunction:o.to})}return{functionName:e,definedIn:r,callers:n,callees:s}}var ro=g(require("fs")),no=g(require("path"));function rn(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 Bt(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:rn(t)}}function $t(t,e){return t.impact.get(e)??[]}var Vt=require("fs/promises"),te=g(require("path")),vn=g(require("piscina"));var me=g(require("fs")),nn=g(require("path")),Ut=require("js-yaml"),Ht=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function sn(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function so(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)),sn(r)}).filter(Boolean)}function io(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 oo(t){try{let e=(0,Ut.load)(t),r={dependencies:{}};for(let[n,s]of Object.entries(e))if(!(n==="__metadata"||!s?.version))for(let i of n.split(", ")){let o=sn(i);o&&(r.dependencies[o]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function ao(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 i=so(s);if(i.length===0)continue;let a=n.find(c=>c.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let c of i)e.dependencies[c]={version:a}}return e}function co(t){let e=me.default.readFileSync(t,"utf-8"),r=JSON.parse(e),n={dependencies:{}};if(r.packages)for(let[s,i]of Object.entries(r.packages)){if(!s.startsWith("node_modules/"))continue;let o=s.replace("node_modules/","");o.includes("node_modules/")||(n.dependencies[o]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}else if(r.dependencies)for(let[s,i]of Object.entries(r.dependencies))n.dependencies[s]={version:i.version,...i.dependencies!==void 0&&{dependencies:i.dependencies}};return n}function lo(t){let e=me.default.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=oo(e);if(r!==null)return r}return ao(e)}function po(t){let e=me.default.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=(0,Ut.load)(e);if(n.packages)for(let[s,i]of Object.entries(n.packages)){let{name:o,version:a}=io(s,i.version);o&&(r.dependencies[o]={version:a,...i.dependencies!==void 0&&{dependencies:i.dependencies}})}if(n.dependencies)for(let[s,i]of Object.entries(n.dependencies)){if(r.dependencies[s])continue;let o=typeof i=="string"?i:i.version;r.dependencies[s]={version:o||""}}}catch{}return r}function on(t){let e={"package-lock.json":co,"yarn.lock":lo,"pnpm-lock.yaml":po},r=Ht.map(n=>[n,e[n]]);for(let[n,s]of r){let i=nn.default.join(t,n);if(me.default.existsSync(i))return s(i)}return null}var uo=new Set(["css","scss","less","stylus"]);function an(t){return uo.has(t)?"style":"code"}var Kt=g(require("postcss")),fo=g(require("postcss-less")),mo=fo,ln=new Set(["reference","inline"]);function cn(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function go(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function ho(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let i=r[1]?.trim()??"",o=r[2]??"";if(!o)return null;let a=ln.has(i)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a,...cn(o)?{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",...cn(s)?{isExternal:!0}:{}}:null}function yo(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"";go(i)&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function pn(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=ho(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...yo(n.value,e))}),r}function xo(t){return t.replace(/(?<!:)\/\/.*/g,"")}function bo(t,e){let r=[],n=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let i=s[1]?.trim()??"",o=s[2]??"";if(o){let a=ln.has(i)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:a})}s=n.exec(t)}return r}function Be(t,e){let r=Kt.default.parse(xo(t));return{imports:pn(r,e),root:r}}function So(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 i=n.name;i&&(e.push({name:i}),r.push({name:i,kind:"variable"}))}return{exports:e,tags:r}}function $e(t,e){try{let r=mo.parse(t),{exports:n,tags:s}=So(r);return{imports:pn(r,e),root:r,exports:n,tags:s}}catch{return{imports:bo(t,e),root:Kt.default.parse(""),exports:[],tags:[]}}}var fn=require("postcss-scss");function un(t){return t.startsWith("_")||t.startsWith("-")}function ko(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function Co(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 vo(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||un(s))continue;e.push({name:s}),r.push({name:s,kind:"variable"});continue}if(n.type==="atrule"&&(n.name==="mixin"||n.name==="function")){let i=n.params.match(/^([\w-]+)/)?.[1];if(!i||un(i))continue;let o=n.params.trim();e.push(o.includes("(")?{name:i,signature:o}:{name:i}),r.push({name:i,kind:"function"})}}return{exports:e,tags:r}}function Ue(t,e){let r=(0,fn.parse)(t),n=[];r.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}=Co(c);if(!l)return;let u={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...ko(l)?{isExternal:!0}:{}};p&&(u.symbols=[p]),n.push(u)});let{exports:s,tags:i}=vo(r);return{imports:n,root:r,exports:s,tags:i}}function wo(t){return t.trim().replace(/\s+/g," ")}function Fo(t){try{return t.fileType==="scss"?Ue(t.source,t.file).root:t.fileType==="less"?$e(t.source,t.file).root:t.fileType==="css"?Be(t.source,t.file).root:void 0}catch{return}}function To(t){let e=Fo(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 i=s[0],o=s[s.length-1],a=n.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()}:${wo(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function mn(t,e,r=2){let n=new Map;for(let i of t)for(let o of To(i)){if(o.declCount<r||o.lines<e)continue;let a=n.get(o.signature);a?a.push(o):n.set(o.signature,[o])}let s=[];for(let i of n.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 gn(t){let e=t.length,r=[],n=[{lcpLength:0,low:0}];for(let s=1;s<e;s++){let i=s-1;for(;t[s]<n[n.length-1].lcpLength;){let o=n.pop();r.push({lcpLength:o.lcpLength,low:o.low,high:s-1}),i=o.low}t[s]>n[n.length-1].lcpLength&&n.push({lcpLength:t[s],low:i})}for(;n.length>1;){let s=n.pop();r.push({lcpLength:s.lcpLength,low:s.low,high:e-1})}return r}var Eo=new Set(["{","}",":",",","[","]"]);function dn(t,e,r){let n=0;for(let s=e;s<e+r;s++)Eo.has(t[s].text)&&n++;return n/r}function hn(t){let e=t.length;if(e===0)return[];let r=Array.from({length:e},(i,o)=>o),n=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++)n[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?n[a+i]:-1;r.sort((a,c)=>{let l=n[a]-n[c];return l!==0?l:o(a)-o(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=o(c)===o(l);s[l]=s[c]+(p&&u?0:1)}if([n,s]=[s,n],n[r[e-1]]===e-1)break}return r}function yn(t,e){let r=t.length,n=new Array(r).fill(0);if(r===0)return n;let s=new Array(r);for(let o=0;o<r;o++)s[e[o]]=o;let i=0;for(let o=0;o<r;o++){let a=s[o];if(a>0){let c=e[a-1];for(;o+i<r&&c+i<r&&t[o+i]===t[c+i];)i++;n[a]=i,i>0&&i--}else i=0}return n}function xn(t,e,r,n=.5){let s=[],i=[],o=new Map;for(let{file:u,tokens:d}of t)if(d.length!==0){o.set(u,d);for(let h=0;h<d.length;h++)s.push(d[h].text),i.push({file:u,localIndex:h});s.push(` ${u}`),i.push({file:u,localIndex:-1})}if(s.length===0)return[];let a=hn(s),c=yn(s,a),l=gn(c),p=[];for(let u of l){let d=Ao(u,a,i,o,e,r,n);d&&p.push(d)}return p.sort((u,d)=>d.lines-u.lines)}function Ao(t,e,r,n,s,i,o){if(t.lcpLength<s)return;let a=[];for(let h=t.low;h<=t.high;h++){let C=r[e[h]];C.localIndex!==-1&&a.push(C)}if(a.length<2||!Po(a,n))return;let c=No(a,t.lcpLength);if(c.length<2)return;let l=c[0],p=n.get(l.file);if(dn(p,l.localIndex,t.lcpLength)>o)return;let u=c.map(({file:h,localIndex:C})=>{let v=n.get(h);return{file:h,startLine:v[C].line,endLine:v[C+t.lcpLength-1].line}}),d=Math.min(...u.map(h=>h.endLine-h.startLine+1));if(!(d<i))return{occurrences:u,lines:d,tokens:t.lcpLength}}function Po(t,e){let r=null;for(let{file:n,localIndex:s}of t){if(s===0)return!0;let o=e.get(n)[s-1].text;if(r===null)r=o;else if(r!==o)return!0}return!1}function No(t,e){let r=new Map;for(let{file:s,localIndex:i}of t){let o=r.get(s);o?o.push(i):r.set(s,[i])}let n=[];for(let[s,i]of r){i.sort((a,c)=>a-c);let o=Number.NEGATIVE_INFINITY;for(let a of i)a>=o&&(n.push({file:s,localIndex:a}),o=a+e)}return n}var Io={typescript:{line:["//"],block:[["/*","*/"]]},javascript:{line:["//"],block:[["/*","*/"]]},go:{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 bn(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function Do(t,e){if(!e)return t;let r=t;for(let[n,s]of e.block??[]){let i=0;for(;;){let o=r.indexOf(n,i);if(o===-1)break;let a=r.indexOf(s,o+n.length),c=a===-1?r.length:a+s.length;r=bn(r,o,c),i=c}}for(let n of e.line??[]){let s=0;for(;;){let i=r.indexOf(n,s);if(i===-1)break;let o=r.indexOf(`
5
+ `,i),a=o===-1?r.length:o;r=bn(r,i,a),s=a}}return r}var Mo=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],Jt=new RegExp(`${Mo.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),Ro=/^[A-Za-z_$][A-Za-z0-9_$]*$/,Sn=/^\d+(?:\.\d+)?$/,Lo=/^(".*"|'.*'|`.*`)$/s,Go=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 kn(t,e,r=!0){let n=Do(t,Io[e]),s=[],i=1,o=0;Jt.lastIndex=0;let a=Jt.exec(n);for(;a!==null;){for(let p=o;p<a.index;p++)n[p]===`
6
+ `&&i++;o=a.index;let c=a[0],l=c;Ro.test(c)&&!Go.has(c)?l="ID":r&&(Sn.test(c)||Lo.test(c))&&(l=Sn.test(c)?"NUM":"STR"),s.push({text:l,line:i});for(let p=o;p<a.index+c.length;p++)n[p]===`
7
+ `&&i++;o=a.index+c.length,a=Jt.exec(n)}return s}var ee=g(require("fs")),Cn=g(require("path"));function _o(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mtime=="number"&&typeof e.size=="number"&&typeof e.ignoreLiterals=="boolean"&&Array.isArray(e.tokens)}function He(t){try{if(!ee.default.existsSync(t))return new Map;let e=ee.default.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"&&_o(s[1]));return new Map(n)}catch{return new Map}}function Ke(t,e){let r=Cn.default.dirname(e);ee.default.existsSync(r)||ee.default.mkdirSync(r,{recursive:!0}),ee.default.writeFileSync(e,JSON.stringify([...t.entries()]))}var Oo=20,jo=new Set(["css","scss","less"]);function zo(t){return Ht.includes(te.default.basename(t))}function Wo(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(te.default.sep).some(n=>r.has(n))}async function Qt(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:i=!0,maxPunctuationRatio:o=.5,limit:a=50,ignoreDirs:c=z,parallelTokenizing:l=!0,tokenCache:p}=r,u=[...t.nodes.values()].filter(h=>!zo(h.path)&&!Wo(h.path,c)),d=Bo(l,u.length);try{let h=[],C=new Map;if(await Promise.all(u.map(async y=>{if(jo.has(y.type)){let X;try{X=await(0,Vt.readFile)(te.default.join(e,y.path),"utf8")}catch{return}h.push({file:y.path,source:X,fileType:y.type});return}let k=p?.get(y.path),D=k&&k.mtime===y.mtime&&k.size===y.size&&k.ignoreLiterals===i,N;if(D)N=k.tokens;else{let X;try{X=await(0,Vt.readFile)(te.default.join(e,y.path),"utf8")}catch{return}N=d?await d.run({source:X,fileType:y.type,ignoreLiterals:i}):kn(X,y.type,i),p?.set(y.path,{mtime:y.mtime,size:y.size,ignoreLiterals:i,tokens:N})}let j=an(y.type),Kr={file:y.path,tokens:N},Jr=C.get(j);Jr?Jr.push(Kr):C.set(j,[Kr])})),p){let y=new Set(u.map(k=>k.path));for(let k of p.keys())y.has(k)||p.delete(k)}let v=mn(h,n);for(let[y,k]of C)for(let D of xn(k,s,n,o))v.push({...D,family:y});return{groups:v.sort((y,k)=>k.lines-y.lines).slice(0,a)}}finally{d&&await d.destroy()}}function Bo(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??Oo;if(e<n)return null;r.maxThreads!==void 0&&r.maxThreads<1&&process.stderr.write(`
8
8
  Warning: parallelTokenizing.maxThreads (${r.maxThreads}) must be at least 1; using 1.
9
- `);try{return new kn.default({filename:te.default.join(__dirname,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:Math.max(1,r.maxThreads)}:{}})}catch(s){return process.stderr.write(`
9
+ `);try{return new vn.default({filename:te.default.join(__dirname,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:Math.max(1,r.maxThreads)}:{}})}catch(s){return process.stderr.write(`
10
10
  Warning: failed to start duplicate-detection worker pool, falling back to synchronous tokenizing: ${s}
11
- `),null}}var ge=g(require("path"));function Wi(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 Bi(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=ge.default.extname(s),c=ge.default.basename(s,a),l=c==="index"?ge.default.basename(ge.default.dirname(s)):c;n.set(s,{path:s,outDegree:o,tag:`feature:${l}`})}return n}function W(t,e){let r=e?.minOutDegree??5;return Bi(t,Wi(t),r)}var $i=(t,e)=>t.outDegree-e.outDegree;function Ui(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 Hi(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 Ki(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 Ji(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function de(t,e){let r=e?.detectFn??W,n=e?.hubComparator??$i,s=r(t.nodes,e),o=Ui(t,s),i=Hi(t.nodes,s,o,n);return{features:Ki(s,i),unassigned:Ji(t.nodes,s,i)}}var Cn=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),vn=new Set(["typescript","javascript","python"]),Ke=new Set(["typescript","javascript","go","python"]);function Ht(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:Cn.has(r),importSymbolsTracked:vn.has(r),callEdgesTracked:Ke.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var he=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(){let e=[],r=new Set,n=new Set,s=[],o=i=>{r.add(i),n.add(i),s.push(i);let a=this.nodes.get(i);if(a){for(let c of a.imports)if(!(!c.toPath||c.isExternal))if(n.has(c.toPath)){let l=s.indexOf(c.toPath);e.push([...s.slice(l),c.toPath])}else r.has(c.toPath)||o(c.toPath)}n.delete(i),s.pop()};for(let i of this.nodes.keys())r.has(i)||o(i);return e}};var I=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 f=this.nodes.get(c);if(f&&(o.add(c),r(f,l,p)!==!1))for(let d of s(c))a(d,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 he(this.nodes).findUnusedFiles(e)}findCycles(){return new he(this.nodes).findCycles()}};var B=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 ye(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function Kt(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 xe(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 Jt(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,o=s?new B(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(f=>f.name==="test");return(!n||p)&&i.push(a.path),!0},{direction:"incoming"}),i}function Vt(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 Qt(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 qt(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 Yt(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 Je(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function wn(t){return[...t.nodes.values()].some(e=>e.commitCount90d!==void 0)}function Xt(t,e={}){let{metric:r="cognitiveComplexity",minComplexity:n=10,maxCoveragePct:s=50,minChurn:o=0,limit:i=20}=e,a=wn(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}}function Fn(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path;return S(e,"component")||S(e,"components")?"component":S(e,"controller")||S(e,"controllers")?"controller":S(e,"middleware")?"middleware":S(e,"router")||S(e,"routes")||S(e,"route")?"router":S(e,"store")||S(e,"stores")?"store":S(e,"service")||S(e,"services")?"service":S(e,"handler")||S(e,"handlers")?"handler":S(e,"adapter")||S(e,"adapters")?"adapter":S(e,"plugin")||S(e,"plugins")?"plugin":S(e,"api")?"api":S(e,"cli")||S(e,"commands")||be(e)==="cli"?"cli":S(e,"util")||S(e,"utils")||S(e,"helper")||S(e,"helpers")?"util":S(e,"model")||S(e,"models")||be(e)==="model"?"model":S(e,"parser")||S(e,"parsers")||be(e)==="parser"?"parser":be(e)==="builder"?"builder":be(e)==="resolver"?"resolver":"other"}function S(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function be(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function Zt(t,e){let r=de(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:Fn(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return s}function er(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(Ke.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=xe(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 Vi(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function Qi(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function tr(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(!Qi(s,n.category))continue;let o=`${n.path}::${s.name}`;e.set(o,{name:s.name,file:n.path,kind:Vi(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 rr(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())}}var zn=g(require("path"));var Qe=g(require("fs")),or=g(require("path"));var re=g(require("fs")),A=g(require("path"));var nr=g(require("fs")),qi=g(require("path"));function Tn(t){try{return nr.default.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Ve(t){try{return nr.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function sr(t,e){let r=A.default.join(e,"package.json");if(!re.default.existsSync(r))return null;let n={};try{n=JSON.parse(re.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:A.default.relative(t,e),entryPoints:Yi(e,n)}:null}function Yi(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(A.default.join(t,s));else if(typeof s=="object"&&s!==null){let o=s["."];if(typeof o=="string")r.push(A.default.join(t,o));else if(typeof o=="object"&&o!==null){let i=o.import??o.require??o.default;typeof i=="string"&&r.push(A.default.join(t,i))}}}e.main&&r.push(A.default.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(A.default.join(t,s));let n=r.filter(Ve);return n.length>0?n.slice(0,1):r.slice(0,1)}function ne(t,e){let r=[],n=new Set;for(let s of e){let o=s.replace(/\/$/,"").replace(/^\.\//,"");Xi(t,o,n,r)}return r}function Xi(t,e,r,n){if(!e.includes("*")){Zi(t,e,r,n);return}let s=e.split("/");s.includes("**")?ea(t,s,r,n):ta(t,s,r,n)}function Zi(t,e,r,n){let s=A.default.join(t,e);if(r.has(s)||!Tn(s))return;r.add(s);let o=sr(t,s);o&&n.push(o)}function ea(t,e,r,n){let s=A.default.join(t,e[0]==="**"?"":e[0]??"");En(t,s,r,n)}function ta(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),o=A.default.join(t,...e.slice(0,s)),i;try{i=re.default.readdirSync(o,{withFileTypes:!0})}catch{return}for(let a of i){if(!a.isDirectory())continue;let c=A.default.join(o,a.name);if(r.has(c))continue;r.add(c);let l=sr(t,c);l&&n.push(l)}}function En(t,e,r,n){let s;try{s=re.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let o of s){if(!o.isDirectory()||o.name==="node_modules"||o.name.startsWith("."))continue;let i=A.default.join(e,o.name);if(re.default.existsSync(A.default.join(i,"package.json"))&&!r.has(i)){r.add(i);let a=sr(t,i);a&&n.push(a)}else En(t,i,r,n)}}var An={type:"npm",detect(t){let e=or.default.join(t,"package.json");if(!Qe.default.existsSync(e))return null;let r;try{r=JSON.parse(Qe.default.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||Qe.default.existsSync(or.default.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:ne(t,n)}};var $=g(require("fs")),T=g(require("path"));var Pn={type:"nx",detect(t){return $.default.existsSync(T.default.join(t,"nx.json"))?Nn(t,t,new Set,0).map(r=>ra(t,r,T.default.join(r,"project.json"))).filter(r=>r!==null):null}};function Nn(t,e,r,n){if(n>4)return[];let s;try{s=$.default.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.default.join(e,a);$.default.existsSync(T.default.join(c,"project.json"))&&!r.has(c)?(r.add(c),o.push(c)):o.push(...Nn(t,c,r,n+1))}return o}function ra(t,e,r){let n={};try{n=JSON.parse($.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,o,i,a=T.default.join(e,"package.json");if($.default.existsSync(a))try{let c=JSON.parse($.default.readFileSync(a,"utf-8"));s=c.name??s,o=c.main,i=c.exports}catch{}return s?{name:s,root:e,relativeRoot:T.default.relative(t,e),entryPoints:na(e,n,o,i)}:null}function na(t,e,r,n){let s=[],o=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(o){let a=T.default.resolve(t,"../..");s.push(T.default.resolve(a,o)),s.push(T.default.resolve(t,o))}if(n){let a=n;if(typeof a=="string")s.push(T.default.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(T.default.join(t,c))}}if(r&&s.push(T.default.join(t,r)),e.sourceRoot){let a=T.default.resolve(t,"../.."),c=T.default.resolve(a,e.sourceRoot);s.push(T.default.join(c,"index.ts"),T.default.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(T.default.join(t,a));let i=s.filter(Ve);return i.length>0?i.slice(0,1):s.slice(0,1)}var ir=g(require("fs")),In=g(require("path")),Mn=require("js-yaml");var Dn={type:"pnpm",detect(t){let e=In.default.join(t,"pnpm-workspace.yaml");if(!ir.default.existsSync(e))return null;let r=[];try{r=(0,Mn.load)(ir.default.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return ne(t,r)}};var Rn=g(require("fs")),Ln=g(require("path")),Gn={type:"turborepo",detect(t){return Rn.default.existsSync(Ln.default.join(t,"turbo.json"))?[]:null}};var qe=g(require("fs")),ar=g(require("path"));var _n={type:"yarn",detect(t){if(!qe.default.existsSync(ar.default.join(t,"yarn.lock")))return null;let e=ar.default.join(t,"package.json");if(!qe.default.existsSync(e))return null;let r;try{r=JSON.parse(qe.default.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:ne(t,n)}};var On=[];function G(t){On.push(t)}function jn(){return On}G(Gn);G(Pn);G(Dn);G(_n);G(An);function Se(t,e=jn()){let r=zn.default.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 ke=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})}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 I(o);r.packages.set(n.name,{graph:i,pkg:{...n,root:""}})}return r}};var Wn=new Map;function se(t,e){Wn.set(t,e)}function Bn(t){return Wn.get(t)}function $n(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function sa(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var oa=(t,e)=>!e.category||$n(t.category,e.category),ia=(t,e)=>!e.type||$n(t.type,e.type),aa=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,ca=(t,e)=>!e.path||sa(t.path,e.path),la=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,pa=(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)))},ua=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),fa=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),ma=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),ga=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,da=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,ha=(t,e)=>e.minSize===void 0||t.size>=e.minSize,ya=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,xa=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,ba=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,Sa=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,ka=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,Ca=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,va=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,wa=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,Fa=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,Ta=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,Ea=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,Aa=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,Pa=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,Na=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,Ia=(t,e,r)=>!e.any?.length||e.any.some(n=>Ce(t,n,r)),Ma=[oa,ia,aa,ca,la,pa,ua,fa,ma,ga,da,ha,ya,xa,ba,Sa,ka,Ca,va,wa,Fa,Ta,Ea,Aa,Pa,Na,Ia];function Ce(t,e,r){return Ma.every(n=>n(t,e,r))}function Ye(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=>Ce(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;return e.sort==="size"?l=c.size-a.size:e.sort==="imports"?l=c.imports.length-a.imports.length:e.sort==="commitCount90d"?l=(c.commitCount90d??0)-(a.commitCount90d??0):e.sort==="exportUsage"?l=(c.avgExportUsage??0)-(a.avgExportUsage??0):e.sort==="complexity"?l=(c.complexity??0)-(a.complexity??0):e.sort==="cognitiveComplexity"&&(l=(c.cognitiveComplexity??0)-(a.cognitiveComplexity??0)),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}}function Un(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))switch(n){case"category":t.category=s;break;case"type":t.type=s;break;case"tag":case"tags":s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];break;case"path":t.path=s;break;case"external":t.isExternal=s.toLowerCase()==="true";break;case"importsfile":t.importsFile=s;break;case"importedby":t.importedBy=s;break;case"minimports":t.minImports=parseInt(s,10);break;case"maximports":t.maxImports=parseInt(s,10);break;case"minsize":t.minSize=parseInt(s,10);break;case"maxsize":t.maxSize=parseInt(s,10);break;case"sort":t.sort=s;break;case"sortdir":t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";break;case"limit":t.limit=parseInt(s,10);break;case"hasdocstring":t.hasDocstring=s.toLowerCase()!=="false";break;case"mincoverage":t.minCoverage=parseInt(s,10);break;case"maxcoverage":t.maxCoverage=parseInt(s,10);break;case"minexportusage":t.minExportUsage=parseFloat(s);break;case"maxexportusage":t.maxExportUsage=parseFloat(s);break;case"mincomplexity":t.minComplexity=parseInt(s,10);break;case"maxcomplexity":t.maxComplexity=parseInt(s,10);break;case"mincognitivecomplexity":t.minCognitiveComplexity=parseInt(s,10);break;case"maxcognitivecomplexity":t.maxCognitiveComplexity=parseInt(s,10);break;case"mincommits":t.minCommits=parseInt(s,10);break;case"maxcommits":t.maxCommits=parseInt(s,10);break;case"isdocumented":t.isDocumented=s.toLowerCase()!=="false";break;case"isstale":t.isStale=s.toLowerCase()!=="false";break;case"lastauthor":t.lastAuthor=s;break}}function Da(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Un(s,n),Object.keys(s).length>0&&e.push(s)}return e}function Xe(t){let e={},r=t.split(",");for(let n of r){let s=n.trim();if(s.toLowerCase().startsWith("any(")&&s.endsWith(")")){let o=s.slice(4,-1),i=Da(o);i.length>0&&(e.any=[...e.any??[],...i]);continue}Un(e,n)}return e}var Cr=g(require("fs/promises")),ns=g(require("path"));var at=g(require("path")),ve=g(require("typescript"));var Jn=g(require("path"));var Kn=g(require("path")),F=g(require("typescript")),Hn=new Set(["describe","test","it"]);function U(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function cr(t){let e=[];for(let r of t.statements){if(!F.default.isExpressionStatement(r))continue;let n=r.expression;if(!F.default.isCallExpression(n))continue;let s=n.expression;F.default.isIdentifier(s)&&Hn.has(s.text)&&e.push(n),F.default.isPropertyAccessExpression(s)&&F.default.isIdentifier(s.expression)&&Hn.has(s.expression.text)&&e.push(n)}return e}function lr(t,e,r){for(let n of t.arguments){if(!F.default.isObjectLiteralExpression(n))continue;let s=n.properties.find(o=>F.default.isPropertyAssignment(o)&&F.default.isIdentifier(o.name)&&o.name.text===e);if(!(!s||!F.default.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(F.default.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=U(t.arguments,o);if(!F.default.isObjectLiteralExpression(i))continue;let a=i.properties.find(l=>F.default.isPropertyAssignment(l)&&F.default.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=U(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function ur(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let o=U(n,s);if(!F.default.isObjectLiteralExpression(o))continue;let i=o.properties.findIndex(c=>F.default.isPropertyAssignment(c)&&F.default.isIdentifier(c.name)&&c.name.text===e);if(i<0)continue;if(o.properties.length===1)return{start:U(n,s-1).getEnd(),end:o.getEnd(),text:""};let a=U(o.properties,i);return i===o.properties.length-1?{start:U(o.properties,i-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:U(o.properties,i+1).getStart(r),text:""}}return null}function fr(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 mr(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var D=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Ra(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Ze(t,e,r,n){let s=F.default.createSourceFile(Kn.default.basename(t),e,F.default.ScriptTarget.Latest,!0),o=cr(s),[i]=o;if(!i)return e;let a=lr(i,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(Ra(a).sort())===JSON.stringify(c))return e;let l=mr(c.map(f=>`@${f}`)),p=o.flatMap(f=>{let d=r.length===0?ur(f,n,s):pr(f,n,l,s);return d?[d]:[]});return p.length>0?fr(e,p):e}var et=class{name="cypress";canHandle(e){return D.has(Jn.default.extname(e).toLowerCase())}apply(e,r,n){return Ze(e,r,n,"tags")}};var Vn=g(require("path")),gr=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,dr=/^@([a-zA-Z0-9_-]+)/gm;function La(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
11
+ `),null}}var ge=g(require("path"));function $o(t){let e=new Map;for(let[r,n]of t){let s=n.imports.filter(i=>i.toPath&&!i.isExternal).length;s>0&&e.set(r,s)}return e}function Uo(t,e,r){let n=new Map;for(let[s,i]of e){if(i<r)continue;let o=t.get(s);if(!o||o.category==="test"||o.category==="barrel")continue;let a=ge.default.extname(s),c=ge.default.basename(s,a),l=c==="index"?ge.default.basename(ge.default.dirname(s)):c;n.set(s,{path:s,outDegree:i,tag:`feature:${l}`})}return n}function W(t,e){let r=e?.minOutDegree??5;return Uo(t,$o(t),r)}var Ho=(t,e)=>t.outDegree-e.outDegree;function Ko(t,e){let r=new Map;for(let n of e.values()){let s=new Set;t.traverse(n.path,i=>(i.path!==n.path&&s.add(i.path),!0),{direction:"outgoing"}),r.set(n.path,s)}return r}function Jo(t,e,r,n){let s=new Map;for(let[i]of t){if(e.has(i))continue;let o=null;for(let a of e.values())r.get(a.path)?.has(i)&&(!o||n(a,o)<0)&&(o=a);o&&s.set(i,o.path)}return s}function Vo(t,e){let r=new Map;for(let n of t.values()){let s=n.tag.replace("feature:",""),i=[];for(let[o,a]of e)a===n.path&&i.push(o);r.set(s,{hub:n.path,outDegree:n.outDegree,files:i})}return r}function Qo(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function de(t,e){let r=e?.detectFn??W,n=e?.hubComparator??Ho,s=r(t.nodes,e),i=Ko(t,s),o=Jo(t.nodes,s,i,n);return{features:Vo(s,o),unassigned:Qo(t.nodes,s,o)}}var wn=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),Fn=new Set(["typescript","javascript","python"]),Je=new Set(["typescript","javascript","go","python"]);function qt(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:wn.has(r),importSymbolsTracked:Fn.has(r),callEdgesTracked:Je.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var he=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((i,o)=>(o.exportUsageRatio??0)>(i?.exportUsageRatio??0)?o:i,null);r.push({path:n.path,maxExportUsage:n.maxExportUsage,tightestDep:s?.toPath??""})}return r.sort((n,s)=>s.maxExportUsage-n.maxExportUsage)}findCycles(){let e=[],r=new Set,n=new Set,s=[],i=o=>{r.add(o),n.add(o),s.push(o);let a=this.nodes.get(o);if(a){for(let c of a.imports)if(!(!c.toPath||c.isExternal))if(n.has(c.toPath)){let l=s.indexOf(c.toPath);e.push([...s.slice(l),c.toPath])}else r.has(c.toPath)||i(c.toPath)}n.delete(o),s.pop()};for(let o of this.nodes.keys())r.has(o)||i(o);return e}};var I=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 i=new Set,o=n.maxDepth??1/0,a=(c,l,p)=>{if(l>o||i.has(c))return;let u=this.nodes.get(c);if(u&&(i.add(c),r(u,l,p)!==!1))for(let d of s(c))a(d,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",i=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,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 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",i=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,o=>s==="outgoing"?this.nodes.get(o)?.callEdges?.map(a=>a.toFile)??[]:i?.get(o)??[])}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 he(this.nodes).findUnusedFiles(e)}findCycles(){return new he(this.nodes).findCycles()}};var B=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 i=s.symbols||["*"],o=new Set;for(let c of i)(c==="*"||n.has("*")||n.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 ye(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function Yt(t,e,r=1){let n=[];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 n.push({path:s.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:r}),n}function xe(t,e){let r=[];return t.traverse(e,n=>{if(n.path===e)return!0;let s=n.imports.find(i=>i.toPath===e);return r.push({path:n.path,...s?.symbols?{symbols:s.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),r}function Xt(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,i=s?new B(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(!n||p)&&o.push(a.path),!0},{direction:"incoming"}),o}function Zt(t,e,r={}){let{depth:n=1,withEdgeDetail:s=!1}=r,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:n}),i}function er(t,e={}){let{metric:r="cognitiveComplexity",threshold:n=10,limit:s=20}=e;return[...t.nodes.values()].flatMap(i=>(i.functions??[]).filter(o=>o[r]>=n).map(o=>({file:i.path,name:o.name,line:o.line,complexity:o.complexity,cognitiveComplexity:o.cognitiveComplexity}))).sort((i,o)=>o[r]-i[r]).slice(0,s)}function tr(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 rr(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 Ve(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function Tn(t){return[...t.nodes.values()].some(e=>e.commitCount90d!==void 0)}function nr(t,e={}){let{metric:r="cognitiveComplexity",minComplexity:n=10,maxCoveragePct:s=50,minChurn:i=0,limit:o=20}=e,a=Tn(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[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,o);return{hotspots:c,count:c.length,churnDataAvailable:a}}function En(t){if(t.category==="test")return"test";if(t.category==="config")return"config";if(t.category==="type-only")return"types";let e=t.path;return S(e,"component")||S(e,"components")?"component":S(e,"controller")||S(e,"controllers")?"controller":S(e,"middleware")?"middleware":S(e,"router")||S(e,"routes")||S(e,"route")?"router":S(e,"store")||S(e,"stores")?"store":S(e,"service")||S(e,"services")?"service":S(e,"handler")||S(e,"handlers")?"handler":S(e,"adapter")||S(e,"adapters")?"adapter":S(e,"plugin")||S(e,"plugins")?"plugin":S(e,"api")?"api":S(e,"cli")||S(e,"commands")||be(e)==="cli"?"cli":S(e,"util")||S(e,"utils")||S(e,"helper")||S(e,"helpers")?"util":S(e,"model")||S(e,"models")||be(e)==="model"?"model":S(e,"parser")||S(e,"parsers")||be(e)==="parser"?"parser":be(e)==="builder"?"builder":be(e)==="resolver"?"resolver":"other"}function S(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function be(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function sr(t,e){let r=de(t,e),n=new Map;for(let[i,o]of r.features){for(let a of o.files)n.set(a,i);n.set(o.hub,i)}let s=new Map;for(let i of t.nodes.values()){let o=n.get(i.path);s.set(i.path,{path:i.path,role:En(i),...i.description?{description:i.description}:{},exports:i.exports.map(a=>a.name),...o?{featureHub:o}:{}})}return s}function ir(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(Je.has(n.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});r.push({path:n.path,category:n.category,precision:"call",callers:s})}else{let s=xe(t,n.path).map(i=>({file:i.path,...i.symbols?{symbols:i.symbols}:{}}));r.push({path:n.path,category:n.category,precision:"file-level",importers:s})}return r}function qo(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function Yo(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function or(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(!Yo(s,n.category))continue;let i=`${n.path}::${s.name}`;e.set(i,{name:s.name,file:n.path,kind:qo(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 i of s.symbols)e.has(`${s.toPath}::${i}`)&&r.push({fromFile:n.path,toType:i,toFile:s.toPath})}return{types:e,edges:r}}function ar(t,e){let r=null;for(let i of t.types.values())if(i.name===e){r=i;break}if(!r)return{type:null,usedByFiles:[],uses:[]};let n=new Set,s=new Map;for(let i of t.edges)if(i.toType===e&&i.toFile===r.file&&n.add(i.fromFile),i.fromFile===r.file){let o=t.types.get(`${i.toFile}::${i.toType}`);o&&s.set(`${o.file}::${o.name}`,o)}return{type:r,usedByFiles:Array.from(n),uses:Array.from(s.values())}}var Bn=g(require("path"));var qe=g(require("fs")),pr=g(require("path"));var re=g(require("fs")),A=g(require("path"));var cr=g(require("fs")),Xo=g(require("path"));function An(t){try{return cr.default.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Qe(t){try{return cr.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function lr(t,e){let r=A.default.join(e,"package.json");if(!re.default.existsSync(r))return null;let n={};try{n=JSON.parse(re.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:A.default.relative(t,e),entryPoints:Zo(e,n)}:null}function Zo(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(A.default.join(t,s));else if(typeof s=="object"&&s!==null){let i=s["."];if(typeof i=="string")r.push(A.default.join(t,i));else if(typeof i=="object"&&i!==null){let o=i.import??i.require??i.default;typeof o=="string"&&r.push(A.default.join(t,o))}}}e.main&&r.push(A.default.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(A.default.join(t,s));let n=r.filter(Qe);return n.length>0?n.slice(0,1):r.slice(0,1)}function ne(t,e){let r=[],n=new Set;for(let s of e){let i=s.replace(/\/$/,"").replace(/^\.\//,"");ea(t,i,n,r)}return r}function ea(t,e,r,n){if(!e.includes("*")){ta(t,e,r,n);return}let s=e.split("/");s.includes("**")?ra(t,s,r,n):na(t,s,r,n)}function ta(t,e,r,n){let s=A.default.join(t,e);if(r.has(s)||!An(s))return;r.add(s);let i=lr(t,s);i&&n.push(i)}function ra(t,e,r,n){let s=A.default.join(t,e[0]==="**"?"":e[0]??"");Pn(t,s,r,n)}function na(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),i=A.default.join(t,...e.slice(0,s)),o;try{o=re.default.readdirSync(i,{withFileTypes:!0})}catch{return}for(let a of o){if(!a.isDirectory())continue;let c=A.default.join(i,a.name);if(r.has(c))continue;r.add(c);let l=lr(t,c);l&&n.push(l)}}function Pn(t,e,r,n){let s;try{s=re.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of s){if(!i.isDirectory()||i.name==="node_modules"||i.name.startsWith("."))continue;let o=A.default.join(e,i.name);if(re.default.existsSync(A.default.join(o,"package.json"))&&!r.has(o)){r.add(o);let a=lr(t,o);a&&n.push(a)}else Pn(t,o,r,n)}}var Nn={type:"npm",detect(t){let e=pr.default.join(t,"package.json");if(!qe.default.existsSync(e))return null;let r;try{r=JSON.parse(qe.default.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||qe.default.existsSync(pr.default.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:ne(t,n)}};var $=g(require("fs")),T=g(require("path"));var In={type:"nx",detect(t){return $.default.existsSync(T.default.join(t,"nx.json"))?Dn(t,t,new Set,0).map(r=>sa(t,r,T.default.join(r,"project.json"))).filter(r=>r!==null):null}};function Dn(t,e,r,n){if(n>4)return[];let s;try{s=$.default.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=T.default.join(e,a);$.default.existsSync(T.default.join(c,"project.json"))&&!r.has(c)?(r.add(c),i.push(c)):i.push(...Dn(t,c,r,n+1))}return i}function sa(t,e,r){let n={};try{n=JSON.parse($.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,i,o,a=T.default.join(e,"package.json");if($.default.existsSync(a))try{let c=JSON.parse($.default.readFileSync(a,"utf-8"));s=c.name??s,i=c.main,o=c.exports}catch{}return s?{name:s,root:e,relativeRoot:T.default.relative(t,e),entryPoints:ia(e,n,i,o)}:null}function ia(t,e,r,n){let s=[],i=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(i){let a=T.default.resolve(t,"../..");s.push(T.default.resolve(a,i)),s.push(T.default.resolve(t,i))}if(n){let a=n;if(typeof a=="string")s.push(T.default.join(t,a));else if(typeof a=="object"&&a!==null){let c=a["."];typeof c=="string"&&s.push(T.default.join(t,c))}}if(r&&s.push(T.default.join(t,r)),e.sourceRoot){let a=T.default.resolve(t,"../.."),c=T.default.resolve(a,e.sourceRoot);s.push(T.default.join(c,"index.ts"),T.default.join(c,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])s.push(T.default.join(t,a));let o=s.filter(Qe);return o.length>0?o.slice(0,1):s.slice(0,1)}var ur=g(require("fs")),Mn=g(require("path")),Rn=require("js-yaml");var Ln={type:"pnpm",detect(t){let e=Mn.default.join(t,"pnpm-workspace.yaml");if(!ur.default.existsSync(e))return null;let r=[];try{r=(0,Rn.load)(ur.default.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return ne(t,r)}};var Gn=g(require("fs")),_n=g(require("path")),On={type:"turborepo",detect(t){return Gn.default.existsSync(_n.default.join(t,"turbo.json"))?[]:null}};var Ye=g(require("fs")),fr=g(require("path"));var jn={type:"yarn",detect(t){if(!Ye.default.existsSync(fr.default.join(t,"yarn.lock")))return null;let e=fr.default.join(t,"package.json");if(!Ye.default.existsSync(e))return null;let r;try{r=JSON.parse(Ye.default.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:ne(t,n)}};var zn=[];function G(t){zn.push(t)}function Wn(){return zn}G(On);G(In);G(Ln);G(jn);G(Nn);function Se(t,e=Wn()){let r=Bn.default.resolve(t),n=new Map,s=[];for(let o of e){let a=o.detect(r);if(a!==null){s.push(o.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 i=Array.from(n.values());return{root:r,type:s[0],types:s,packages:i,packageMap:new Map(i.map(o=>[o.name,o]))}}var ke=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})}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 i of r.nodes.values())for(let o of i.imports)o.isWorkspace&&o.workspacePackage&&s.add(o.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,i=>(i.path!==e&&s.push({file:i.path,package:r.name}),!0),{direction:"incoming"});for(let{graph:i,pkg:o}of this.packages.values())if(o.name!==r.name)for(let a of i.nodes.values())a.imports.some(l=>l.isWorkspace&&l.workspacePackage===r.name)&&s.push({file:a.path,package:o.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 i=new Map(s.map(a=>[a.path,a])),o=new I(i);r.packages.set(n.name,{graph:o,pkg:{...n,root:""}})}return r}};var $n=new Map;function se(t,e){$n.set(t,e)}function Un(t){return $n.get(t)}function Hn(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function oa(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var aa=(t,e)=>!e.category||Hn(t.category,e.category),ca=(t,e)=>!e.type||Hn(t.type,e.type),la=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,pa=(t,e)=>!e.path||oa(t.path,e.path),ua=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,fa=(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(i=>i.name===s))||n.some(s=>t.tags.some(i=>i.name===s)))},ma=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),ga=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),da=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),ha=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,ya=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,xa=(t,e)=>e.minSize===void 0||t.size>=e.minSize,ba=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,Sa=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,ka=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,Ca=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,va=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,wa=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,Fa=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,Ta=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,Ea=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,Aa=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,Pa=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,Na=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,Ia=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,Da=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,Ma=(t,e,r)=>!e.any?.length||e.any.some(n=>Ce(t,n,r)),Ra=[aa,ca,la,pa,ua,fa,ma,ga,da,ha,ya,xa,ba,Sa,ka,Ca,va,wa,Fa,Ta,Ea,Aa,Pa,Na,Ia,Da,Ma];function Ce(t,e,r){return Ra.every(n=>n(t,e,r))}function Xe(t,e){let r=new Map;if(e.importedBy!==void 0){for(let o of t.nodes)for(let a of o.imports)if(a.toPath){let c=r.get(a.toPath)??[];c.push(o.path),r.set(a.toPath,c)}}let n=t.nodes.filter(o=>Ce(o,e,r)),s=new Set(n.map(o=>o.path)),i=n.map(o=>({...o,imports:o.imports.filter(a=>!a.toPath||s.has(a.toPath))}));if(e.sort){let o=e.sortDir==="asc"?-1:1;i.sort((a,c)=>{let l=0;return e.sort==="size"?l=c.size-a.size:e.sort==="imports"?l=c.imports.length-a.imports.length:e.sort==="commitCount90d"?l=(c.commitCount90d??0)-(a.commitCount90d??0):e.sort==="exportUsage"?l=(c.avgExportUsage??0)-(a.avgExportUsage??0):e.sort==="complexity"?l=(c.complexity??0)-(a.complexity??0):e.sort==="cognitiveComplexity"&&(l=(c.cognitiveComplexity??0)-(a.cognitiveComplexity??0)),l*o})}return e.limit!==void 0&&i.splice(e.limit),{nodes:i,cycles:t.cycles?.filter(o=>o.every(a=>s.has(a)))??void 0}}function Kn(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))switch(n){case"category":t.category=s;break;case"type":t.type=s;break;case"tag":case"tags":s.includes("+")?t.allTags=[...t.allTags??[],...s.split("+")]:t.tags=[...t.tags??[],s];break;case"path":t.path=s;break;case"external":t.isExternal=s.toLowerCase()==="true";break;case"importsfile":t.importsFile=s;break;case"importedby":t.importedBy=s;break;case"minimports":t.minImports=parseInt(s,10);break;case"maximports":t.maxImports=parseInt(s,10);break;case"minsize":t.minSize=parseInt(s,10);break;case"maxsize":t.maxSize=parseInt(s,10);break;case"sort":t.sort=s;break;case"sortdir":t.sortDir=s.toLowerCase()==="asc"?"asc":"desc";break;case"limit":t.limit=parseInt(s,10);break;case"hasdocstring":t.hasDocstring=s.toLowerCase()!=="false";break;case"mincoverage":t.minCoverage=parseInt(s,10);break;case"maxcoverage":t.maxCoverage=parseInt(s,10);break;case"minexportusage":t.minExportUsage=parseFloat(s);break;case"maxexportusage":t.maxExportUsage=parseFloat(s);break;case"mincomplexity":t.minComplexity=parseInt(s,10);break;case"maxcomplexity":t.maxComplexity=parseInt(s,10);break;case"mincognitivecomplexity":t.minCognitiveComplexity=parseInt(s,10);break;case"maxcognitivecomplexity":t.maxCognitiveComplexity=parseInt(s,10);break;case"mincommits":t.minCommits=parseInt(s,10);break;case"maxcommits":t.maxCommits=parseInt(s,10);break;case"isdocumented":t.isDocumented=s.toLowerCase()!=="false";break;case"isstale":t.isStale=s.toLowerCase()!=="false";break;case"lastauthor":t.lastAuthor=s;break}}function La(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Kn(s,n),Object.keys(s).length>0&&e.push(s)}return e}function Ze(t){let e={},r=t.split(",");for(let n of r){let s=n.trim();if(s.toLowerCase().startsWith("any(")&&s.endsWith(")")){let i=s.slice(4,-1),o=La(i);o.length>0&&(e.any=[...e.any??[],...o]);continue}Kn(e,n)}return e}var Er=g(require("fs/promises")),is=g(require("path"));var ct=g(require("path")),ve=g(require("typescript"));var Qn=g(require("path"));var Vn=g(require("path")),F=g(require("typescript")),Jn=new Set(["describe","test","it"]);function U(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function mr(t){let e=[];for(let r of t.statements){if(!F.default.isExpressionStatement(r))continue;let n=r.expression;if(!F.default.isCallExpression(n))continue;let s=n.expression;F.default.isIdentifier(s)&&Jn.has(s.text)&&e.push(n),F.default.isPropertyAccessExpression(s)&&F.default.isIdentifier(s.expression)&&Jn.has(s.expression.text)&&e.push(n)}return e}function gr(t,e,r){for(let n of t.arguments){if(!F.default.isObjectLiteralExpression(n))continue;let s=n.properties.find(i=>F.default.isPropertyAssignment(i)&&F.default.isIdentifier(i.name)&&i.name.text===e);if(!(!s||!F.default.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(F.default.isStringLiteral).map(i=>i.text)}return null}function dr(t,e,r,n){if(t.arguments.length===0)return null;for(let i=1;i<t.arguments.length;i++){let o=U(t.arguments,i);if(!F.default.isObjectLiteralExpression(o))continue;let a=o.properties.find(l=>F.default.isPropertyAssignment(l)&&F.default.isIdentifier(l.name)&&l.name.text===e);if(a)return{start:a.initializer.getStart(n),end:a.initializer.getEnd(),text:r};let c=o.getEnd()-1;return{start:c,end:c,text:`${o.properties.length>0?", ":""}${e}: ${r}`}}let s=U(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function hr(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let i=U(n,s);if(!F.default.isObjectLiteralExpression(i))continue;let o=i.properties.findIndex(c=>F.default.isPropertyAssignment(c)&&F.default.isIdentifier(c.name)&&c.name.text===e);if(o<0)continue;if(i.properties.length===1)return{start:U(n,s-1).getEnd(),end:i.getEnd(),text:""};let a=U(i.properties,o);return o===i.properties.length-1?{start:U(i.properties,o-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:U(i.properties,o+1).getStart(r),text:""}}return null}function yr(t,e){let r=[...e].sort((s,i)=>i.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 xr(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var M=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Ga(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function et(t,e,r,n){let s=F.default.createSourceFile(Vn.default.basename(t),e,F.default.ScriptTarget.Latest,!0),i=mr(s),[o]=i;if(!o)return e;let a=gr(o,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(Ga(a).sort())===JSON.stringify(c))return e;let l=xr(c.map(u=>`@${u}`)),p=i.flatMap(u=>{let d=r.length===0?hr(u,n,s):dr(u,n,l,s);return d?[d]:[]});return p.length>0?yr(e,p):e}var tt=class{name="cypress";canHandle(e){return M.has(Qn.default.extname(e).toLowerCase())}apply(e,r,n){return et(e,r,n,"tags")}};var qn=g(require("path")),br=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,Sr=/^@([a-zA-Z0-9_-]+)/gm;function _a(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
12
12
  `)}
13
13
 
14
- `}function Ga(t){let e=new Set;dr.lastIndex=0;let r=dr.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=dr.exec(t);return e}var tt=class{name="gherkin";canHandle(e){return Vn.default.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(gr,""),o=Ga(s),i=n.filter(c=>!o.has(c)),a=i.length>0?La(i):"";return gr.test(r)?r.replace(gr,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Qn(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)}var qn=g(require("path")),hr=/^\/\/go:build mokosh_[^\n]+\n/m,_a=/^package\s+\S+/m;function Oa(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
15
- `}function ja(t){let e=hr.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 rt=class{name="go";canHandle(e){return qn.default.basename(e).endsWith("_test.go")}apply(e,r,n){let s=ja(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(hr,"");let i=Oa(o);if(s!==null)return r.replace(hr,i);let a=_a.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+i}
16
- ${r.slice(c)}`}};var Yn=g(require("path"));var za=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,yr=/^ \* @group (.+)$/gm;function Wa(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
14
+ `}function Oa(t){let e=new Set;Sr.lastIndex=0;let r=Sr.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=Sr.exec(t);return e}var rt=class{name="gherkin";canHandle(e){return qn.default.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(br,""),i=Oa(s),o=n.filter(c=>!i.has(c)),a=o.length>0?_a(o):"";return br.test(r)?r.replace(br,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Yn(t,e){let r=t.replace(/\\/g,"/"),n=e.replace(/\\/g,"/"),s="";for(let i=0;i<r.length;i++){let o=r[i];o==="*"?r[i+1]==="*"?(s+=".*",i++):s+="[^/]*":o==="?"?s+="[^/]":o!==void 0&&(s+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${s}$`).test(n)}var Xn=g(require("path")),kr=/^\/\/go:build mokosh_[^\n]+\n/m,ja=/^package\s+\S+/m;function za(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
15
+ `}function Wa(t){let e=kr.exec(t);if(!e)return null;let r=e[0]??"",n=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],i=n.exec(r);for(;i!==null;)i[1]&&s.push(i[1]),i=n.exec(r);return s}var nt=class{name="go";canHandle(e){return Xn.default.basename(e).endsWith("_test.go")}apply(e,r,n){let s=Wa(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(kr,"");let o=za(i);if(s!==null)return r.replace(kr,o);let a=ja.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+o}
16
+ ${r.slice(c)}`}};var Zn=g(require("path"));var Ba=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,Cr=/^ \* @group (.+)$/gm;function $a(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
17
17
  `)}
18
18
 
19
- `}function Ba(t){let e=[];yr.lastIndex=0;let r=yr.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=yr.exec(t);return e}var nt=class{name="jest";canHandle(e){return D.has(Yn.default.extname(e).toLowerCase())}apply(e,r,n){let s=za.exec(r),o=s?Ba(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:Wa(i)+a}};var Xn=g(require("path"));var st=class{name="playwright";canHandle(e){return D.has(Xn.default.extname(e).toLowerCase())}apply(e,r,n){return Ze(e,r,n,"tag")}};var Zn=g(require("path")),xr=/^pytestmark\s*=\s*.+$/m,$a=/^import pytest\s*$/m;function Ua(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Ha(t){let e=xr.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 ot=class{name="pytest";canHandle(e){return Zn.default.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Ha(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(xr,"").replace(/\n{3,}/g,`
19
+ `}function Ua(t){let e=[];Cr.lastIndex=0;let r=Cr.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=Cr.exec(t);return e}var st=class{name="jest";canHandle(e){return M.has(Zn.default.extname(e).toLowerCase())}apply(e,r,n){let s=Ba.exec(r),i=s?Ua(s[0]):null,o=[...n].sort();if(i!==null&&JSON.stringify([...i].sort())===JSON.stringify(o))return r;let a=s?r.slice(s[0].length):r;return n.length===0?a:$a(o)+a}};var es=g(require("path"));var it=class{name="playwright";canHandle(e){return M.has(es.default.extname(e).toLowerCase())}apply(e,r,n){return et(e,r,n,"tag")}};var ts=g(require("path")),vr=/^pytestmark\s*=\s*.+$/m,Ha=/^import pytest\s*$/m;function Ka(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Ja(t){let e=vr.exec(t);if(!e)return null;let r=e[0],n=[],s=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,i=s.exec(r);for(;i!==null;)i[1]&&n.push(i[1]),i=s.exec(r);return n}var ot=class{name="pytest";canHandle(e){return ts.default.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Ja(r),i=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(i))return r;if(n.length===0)return r.replace(vr,"").replace(/\n{3,}/g,`
20
20
 
21
- `);let i=Ua(o);if(s!==null)return r.replace(xr,i);let a=$a.test(r),c=Ka(r),l=r.slice(0,c),p=r.slice(c),f=a?"":`import pytest
21
+ `);let o=Ka(i);if(s!==null)return r.replace(vr,o);let a=Ha.test(r),c=Va(r),l=r.slice(0,c),p=r.slice(c),u=a?"":`import pytest
22
22
  `,d=l.endsWith(`
23
23
 
24
24
  `)?"":`
25
- `;return`${l+d+f+i}
26
- ${p}`}};function Ka(t){let e=t.split(`
27
- `),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)}var br=g(require("path")),Sr=g(require("typescript"));var Ja=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,it=class{name="vitest";canHandle(e){return D.has(br.default.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(Ja,""),o=Sr.default.createSourceFile(br.default.basename(e),s,Sr.default.ScriptTarget.Latest,!0),i=cr(o),[a]=i;if(!a)return s;let c=lr(a,"tags",o),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=i.flatMap(f=>{let d=n.length===0?ur(f,"tags",o):pr(f,"tags",mr(l),o);return d?[d]:[]});return p.length>0?fr(s,p):s}};var es={vitest:()=>new it,playwright:()=>new st,cypress:()=>new et,jest:()=>new nt},Va={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function Qa(t){let e=ve.default.createSourceFile("detect.ts",t,ve.default.ScriptTarget.Latest,!0);for(let r of e.statements){if(!ve.default.isImportDeclaration(r)||!ve.default.isStringLiteral(r.moduleSpecifier))continue;let n=Va[r.moduleSpecifier.text];if(n)return n}return null}var kr=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return D.has(at.default.extname(e).toLowerCase())}apply(e,r,n){let s=Qa(r)??this.matchOverride(e)??this.defaultFramework;return(es[s]??es.vitest)().apply(e,r,n)}matchOverride(e){let r=at.default.relative(this.rootDir,e).split(at.default.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Qn(n,r))return s;return null}};function ts(t="vitest",e={},r=process.cwd()){return[new tt,new ot,new rt,new kr(r,t,Object.entries(e))]}function rs(t,e){return e.find(r=>r.canHandle(t))??null}var qa=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,Ya=new Set(["import"]),Xa=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function Za(t,e,r,n){let s;try{s=await Cr.default.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let o=rs(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 Cr.default.writeFile(t,i,"utf8"),{path:t,status:"updated"})}async function vr(t,e,r){let n=fe(e),s=n.tagApplier?.framework??"vitest",o=n.tagApplier?.frameworkOverrides??{},i=ts(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 h of c.tags)Ya.has(h.kind)&&qa.test(h.name)&&(Xa.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let f=ns.default.resolve(e,c.path),d=await Za(f,p,r.dryRun,i);d.path=c.path,a.files.push(d),d.status==="updated"?a.updated++:d.status==="unchanged"?a.unchanged++:a.errors++}return a}var ct=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};var le=g(require("fs")),E=g(require("path")),qs=g(require("piscina"));var lt=require("child_process"),pt=class{getChangedFiles(){try{let r=[["diff","--name-only"],["diff","--cached","--name-only"],["ls-files","--others","--exclude-standard"]].flatMap(n=>{try{return(0,lt.execFileSync)("git",n,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
28
- `).map(o=>o.trim()).filter(o=>o!=="")}catch{return[]}});return Array.from(new Set(r))}catch(e){return console.error("Error getting git diff:",e),[]}}},ss="%x00%H%x09%ae%x09%at",os=256*1024*1024;function is(t,e){let r="",n=0;for(let s of t.split(`
29
- `)){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 as(t){let e=new Map;try{let r=(0,lt.execFileSync)("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${ss}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:os});is(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=(0,lt.execFileSync)("git",["-C",t,"log","--name-status","-M",`--format=${ss}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:os});is(r,(n,s,o)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:o||void 0})})}catch{}return e}var wr=g(require("path"));function _(t){switch(wr.default.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":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=wr.default.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}var ls=g(require("coffeescript"));function O(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 ps(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return O(t.value)}}function H(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function ec(t,e){let r=ps(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:P(r),type:"static"}:null}function tc(t,e){let r=e.variable?.base?.value==="require",n=ps(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:P(n),type:"require"}}function cs(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=H(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>H(s.variable)??H(s)).filter(s=>!!s).map(s=>({name:s}));let n=H(r);return n?[{name:n}]:[]}function rc(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=H(t.variable)??H(t.variable?.base);return e?[{name:e}]:[]}function nc(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let o=ec(t,e);o&&r.push(o)}else if(s==="Call"){let o=tc(t,e);o&&r.push(o)}else if(s==="Assign"){let o=H(e.variable?.base),i=e.variable?.properties?.[0]?.name?.value;o==="module"&&i==="exports"?n.push(...cs(e,void 0)):o==="exports"&&typeof i=="string"&&n.push(...cs(e,i))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...rc(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function Fr(t,e,r,n){if(!(!e||typeof e!="object")){nc(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)Fr(t,i,r,n);else Fr(t,o,r,n)}}}function us(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{Fr(t,ls.default.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}}var ae=require("@cucumber/gherkin"),fs=require("@cucumber/messages");var sc=fs.IdGenerator.uuid();function Tr(t,e){let r=new Set;try{let n=new ae.AstBuilder(sc),s=new ae.GherkinClassicTokenMatcher,i=new ae.Parser(n,s).parse(e);i.feature&&(i.feature.tags.forEach(a=>{r.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),i.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(c=>{r.add(c.name.startsWith("@")?c.name.slice(1):c.name)}),a.scenario.examples.forEach(c=>{c.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})),a.rule&&a.rule.children.forEach(c=>{c.scenario&&c.scenario.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})}))}catch(n){console.warn(`[GherkinParser] Failed to parse ${t}:`,n)}return{imports:[],exports:[],tags:Array.from(r).map(n=>({name:n,kind:"comment-marker"})),category:"test"}}se("gherkin",Tr);var ys=g(require("path")),xs=require("@lezer/go");function K(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function we(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
30
- `&&r++;return r}function oc(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 gs(t,e,r,n){let s=r?1:1+e,o=K(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+=gs(p,e,!0,n):p&&(s+=1+ce(p,e+1,!1,n))}return s}function ms(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 ic(t,e,r){let n=0,s=t.firstChild;for(;s;)n+=ce(s,e,!1,r),s=s.nextSibling;return n}function ac(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 gs(t,e,r,n);if(s==="ForStatement"||s==="SwitchStatement"||s==="SelectStatement")return ms(t,e,n);let o=s==="LogicOp"&&ac(t,n)?1:0;return e>0&&s==="FunctionLiteral"?o+ms(t,e,n):o+ic(t,e,n)}function cc(t,e){return ce(t,0,!1,e)}function ut(t,e){return{complexity:oc(t,e),cognitiveComplexity:cc(t,e)}}function Er(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 ds(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}=ut(n.node,e);r.push({name:o,line:we(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=Er(n.node,e),a=i?`${i}.${o}`:o,{complexity:c,cognitiveComplexity:l}=ut(n.node,e);r.push({name:a,line:we(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var lc=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,pc=/^\/\/go:build\s+(.+)$/,uc=/^\/\/\s*\+build\s+(.+)$/;function bs(t,e){let r=[],n=new Map,s=new Set,o=new Set,i=new Map,a=xs.parser.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let y=e.slice(c.from,c.to),k=y.match(lc);k?.[1]&&s.add(k[1]);let M=y.match(pc);M&&hs(M[1],o);let N=y.match(uc);N&&hs(N[1],o);break}case"ImportSpec":{let y=c.node.getChild("String");if(y){let M=e.slice(y.from,y.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:M,isExternal:!0,isStyle:!1,type:"static"});let N=c.node.getChild("DefName"),j=N?e.slice(N.from,N.to):M.split("/").pop();j&&j!=="_"&&j!=="."&&i.set(j,M)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let y=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(y){let k=e.slice(y.from,y.to);k!=="_"&&/^[A-Z]/.test(k)&&!n.has(k)&&n.set(k,{name:k})}break}}while(c.next());let l=r.some(y=>y.rawSpecifier==="testing"),p=ys.default.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",f=new Set([...s,...o]),{complexity:d,cognitiveComplexity:h}=ut(a.topNode,e),C=ds(a,e),v=p==="test"?[]:fc(a,e,i);return{imports:r,exports:Array.from(n.values()),tags:Array.from(f).map(y=>({name:y,kind:"comment-marker"})),category:p,rawCallEdges:v,complexity:d,cognitiveComplexity:h,...C.length>0?{functions:C}:{}}}function fc(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,f=l.getChild("FieldName");if(p?.type.name==="VariableName"&&f){let d=e.slice(p.from,p.to),h=r.get(d);if(h){let C=e.slice(f.from,f.to);n.push({from:a,to:C,toSpecifier:h})}}}}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=Er(o.node,e);s(a,l?`${l}.${c}`:c)}}while(o.next());return n}function hs(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}var Ss=g(require("livescript"));function J(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function mc(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=J(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>J(r.key)??J(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=J(t);return e?[{name:e}]:[]}function gc(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,n=J(r.head),o=r.tails?.[0]?.key?.name;if(n==="module"&&o==="exports")return mc(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=>J(n.val)??J(n.key)).filter(n=>!!n).map(n=>({name:n}))}return[]}var dc=new Set(["first_line","first_column","last_line","last_column","line","column"]);function hc(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=O(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:P(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=O(s);return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:P(o),type:"require"}}}}return null}function Ar(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=hc(t,e);s&&n.push(s),r.push(...gc(t));for(let o in t){if(dc.has(o))continue;let i=t[o];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let a of i)n.push(...Ar(a,e,r));else n.push(...Ar(i,e,r))}return n}function ks(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{s=Ar(Ss.default.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}}var Cs=g(require("luaparse"));function yc(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=O(i.raw))}else if(s.type==="StringCallExpression"){let i=s.argument;i?.type==="StringLiteral"&&(o=O(i.raw))}o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:P(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 xc(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 bc(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 Sc(t){let e=t.body,r=xc(e),n=bc(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 vs(t,e){let r=oe(e),n=ie(t,r),s=[],o=[];try{let i=Cs.default.parse(e);s=yc(i,t),o=Sc(i)}catch{}return{imports:s,exports:o,tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:n}}var kc=["http://","https://","mailto:","//"],Cc="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",vc=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${Cc})\\b`,"g"),ws;async function wc(){return ws??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),ws}function Fc(t){let e=t.trim();return e.length===0||e.startsWith("#")||kc.some(r=>e.startsWith(r))}function Tc(t,e){let r=t.match(vc);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function Fs(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!Fc(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static"}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...Tc(t.value,e)),Array.isArray(t.children))for(let n of t.children)Fs(n,e,r)}async function Ts(t,e){let n=(await wc()).parse(e),s=[];Fs(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"}}var Ps=g(require("path")),Ns=require("@lezer/python");function Ec(t){let e=1;function r(n){switch(n.type.name){case"IfStatement":{e+=K(n).filter(o=>o.type.name==="if"||o.type.name==="elif").length;break}case"TryStatement":{e+=K(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 Ac(t,e){let r=0,n=K(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+=L(l,c)),p&&(r+=L(p,c)),s++,o+=3}else if(i?.type.name==="else"){r+=1;let a=n[o+1];a&&(r+=L(a,e+1)),o+=2}else o++}return r}function Pc(t,e){let r=0,n=K(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+=L(n[s],e),s++;s<n.length&&(r+=L(n[s],e),s++)}else o?.type.name==="Body"&&(r+=L(o,e)),s++}return r}function Es(t,e){let r=1+e,n=t.firstChild;for(;n;)r+=L(n,e+1),n=n.nextSibling;return r}function Nc(t,e){let r=0,n=t.firstChild;for(;n;)r+=L(n,e),n=n.nextSibling;return r}function L(t,e){let r=t.type.name;if(r==="IfStatement")return Ac(t,e);if(r==="TryStatement")return Pc(t,e);if(r==="ForStatement"||r==="WhileStatement")return Es(t,e);let n=r==="ConditionalExpression"||r==="and"||r==="or"?1:0;return e>0&&(r==="FunctionDefinition"||r==="LambdaExpression")?n+Es(t,e):n+Nc(t,e)}function Ic(t){return L(t,0)}function Pr(t){return{complexity:Ec(t),cognitiveComplexity:Ic(t)}}function As(t,e){let r=[];function n(i,a){let{complexity:c,cognitiveComplexity:l}=Pr(i);r.push({name:a,line:we(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 f=p.getChild("VariableName"),d=f?e.slice(f.from,f.to):void 0;d&&n(p,c?`${c}.${d}`:d),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 Mc=new Set(["pytest","unittest","nose","hypothesis"]);function Is(t,e){let r=[],n=[],s=new Set,o=Ps.default.basename(t).toLowerCase(),i=Ns.parser.parse(e),a=i.cursor();do switch(a.name){case"Comment":{let h=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);h?.[1]&&s.add(h[1]);break}case"ImportStatement":{for(let h of Dc(a.node,e,t))r.push(h);break}case"FunctionDefinition":case"ClassDefinition":{let h=a.node.parent;if(h?.name==="Script"||h?.name==="DecoratedStatement"&&h.parent?.name==="Script"){let v=a.node.getChild("VariableName");v&&n.push({name:e.slice(v.from,v.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let h=a.node.firstChild;h?.name==="VariableName"&&n.push({name:e.slice(h.from,h.to)})}break}}while(a.next());let c=jc(o,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=Pr(i.topNode),f=As(i,e),d=c==="test"?[]:Oc(i,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:d,complexity:l,cognitiveComplexity:p,...f.length>0?{functions:f}:{}}}function Dc(t,e,r){let n=t.firstChild;return n?n.name==="from"?Rc(t,e,r):Lc(t,e,r):[]}function Rc(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=Gc(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[Fe(r,o,i,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[Fe(r,l+c.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[Fe(r,l.slice(0,-1),["*"],!1)]:i.map(p=>Fe(r,l+p,[p],!1))}function Lc(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(Fe(r,o,["*"],!0))}s=s.nextSibling}return n}function Gc(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 _c(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),f=i.nextSibling;for(;f;){if(f.type.name==="VariableName"){let d=e.slice(f.from,f.to),h=d;if(f.nextSibling?.type.name==="as"){let v=f.nextSibling.nextSibling;v?.type.name==="VariableName"&&(h=e.slice(v.from,v.to),f=v)}let C=c===0?a:l?p+l.replace(/\./g,"/"):p+d;r.set(h,C)}f=f.nextSibling}}while(n.next());return r}function Oc(t,e){let r=_c(t,e),n=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,f=e.slice(p.from,p.to),d=r.get(f);d&&n.push({from:c,to:f,toSpecifier:d})}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 f=p.firstChild;for(;f;){if(f.type.name==="FunctionDefinition"){let d=f.getChild("VariableName"),h=d?e.slice(d.from,d.to):void 0;h&&s(f,l?`${l}.${h}`:h)}else i(f);f=f.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 Fe(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function jc(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=>Mc.has(n.rawSpecifier))?"test":"logic"}var Mr=g(require("path")),m=g(require("typescript"));var x=g(require("typescript"));function zc(t){let e=1;function r(n){switch(n.kind){case x.default.SyntaxKind.IfStatement:case x.default.SyntaxKind.ConditionalExpression:case x.default.SyntaxKind.ForStatement:case x.default.SyntaxKind.ForInStatement:case x.default.SyntaxKind.ForOfStatement:case x.default.SyntaxKind.WhileStatement:case x.default.SyntaxKind.DoStatement:case x.default.SyntaxKind.CatchClause:case x.default.SyntaxKind.CaseClause:e++;break;case x.default.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===x.default.SyntaxKind.AmpersandAmpersandToken||s===x.default.SyntaxKind.BarBarToken||s===x.default.SyntaxKind.QuestionQuestionToken)&&e++;break}}x.default.forEachChild(n,r)}return r(t),e}function Ds(t,e,r){let n=r?1:1+e,s=r?e:e+1;return n+=V(t.expression,s,!1),n+=V(t.thenStatement,s,!1),t.elseStatement&&(x.default.isIfStatement(t.elseStatement)?n+=Ds(t.elseStatement,e,!0):n+=1+V(t.elseStatement,e+1,!1)),n}function Ms(t,e){let r=1+e;return x.default.forEachChild(t,n=>{r+=V(n,e+1,!1)}),r}function Wc(t,e){let r=1+e;return x.default.forEachChild(t,n=>{r+=V(n,e,!1)}),r}function Bc(t,e){let r=0;return x.default.forEachChild(t,n=>{r+=V(n,e,!1)}),r}function $c(t){let e=t.operatorToken.kind;return e===x.default.SyntaxKind.AmpersandAmpersandToken||e===x.default.SyntaxKind.BarBarToken||e===x.default.SyntaxKind.QuestionQuestionToken}function V(t,e,r){if(x.default.isIfStatement(t))return Ds(t,e,r);if(x.default.isForStatement(t)||x.default.isForInStatement(t)||x.default.isForOfStatement(t)||x.default.isWhileStatement(t)||x.default.isDoStatement(t)||x.default.isSwitchStatement(t))return Ms(t,e);if(x.default.isCatchClause(t))return Wc(t,e);let n=0;return x.default.isConditionalExpression(t)&&(n+=1),x.default.isBinaryExpression(t)&&$c(t)&&(n+=1),e>0&&(x.default.isFunctionDeclaration(t)||x.default.isFunctionExpression(t)||x.default.isArrowFunction(t))?n+Ms(t,e):n+Bc(t,e)}function Uc(t){return V(t,0,!1)}function Nr(t){return{complexity:zc(t),cognitiveComplexity:Uc(t)}}var w=g(require("typescript")),Ir=new Set(["test","describe","it"]);function Rs(t,e){Hc(t,e),Jc(t,e),Vc(t,e),Qc(t,e)}function Hc(t,e){if((w.default.isFunctionDeclaration(t)||w.default.isVariableDeclaration(t))&&t.name&&w.default.isIdentifier(t.name)&&Kc(t)){let r;if(w.default.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(w.default.isArrowFunction(n)||w.default.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Kc(t){if(w.default.isFunctionDeclaration(t))return w.default.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&w.default.isSourceFile(e.parent)}function Jc(t,e){if(!w.default.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 Vc(t,e){if(!w.default.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 Qc(t,e){if(w.default.isCallExpression(t)&&qc(t.expression))for(let r of t.arguments)w.default.isObjectLiteralExpression(r)&&Yc(r,e)}function qc(t){return w.default.isIdentifier(t)?Ir.has(t.text):!!(w.default.isPropertyAccessExpression(t)&&(Ir.has(t.name.text)||w.default.isIdentifier(t.expression)&&Ir.has(t.expression.text)))}function Yc(t,e){for(let r of t.properties){if(!w.default.isPropertyAssignment(r)||!w.default.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=w.default.isArrayLiteralExpression(n)?n.elements.filter(w.default.isStringLiteral):r.name.text==="tag"&&w.default.isStringLiteral(n)?[n]:[];for(let o of s)e.tags.add({name:o.text.replace(/^@/,""),kind:"comment-marker"})}}function Dr(t,e,r){let n=[],s=new Map,o=new Set,i=m.default.createSourceFile(t,e,m.default.ScriptTarget.Latest,!0,r==="typescript"?m.default.ScriptKind.TSX:m.default.ScriptKind.JSX),a={filePath:t,imports:n,exports:s,tags:o,rawCallEdges:[],sourceFile:i,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=v=>{tl(v,a),m.default.forEachChild(v,c)};c(i);let l=fl(t,a);(l==="test"||l==="barrel")&&o.add({name:l,kind:"comment-marker"}),l!=="test"&&ml(a,i);let p=i.statements[0],f=p?Gs(p):void 0,{complexity:d,cognitiveComplexity:h}=Nr(i),C=Xc(i);return{imports:n,exports:Array.from(s.values()),tags:Array.from(o),category:l,rawCallEdges:a.rawCallEdges??[],complexity:d,cognitiveComplexity:h,...C.length>0?{functions:C}:{},...f!==void 0?{description:f}:{}}}function Xc(t){let e=[],r=(s,o)=>{let{complexity:i,cognitiveComplexity:a}=Nr(o),c=t.getLineAndCharacterOfPosition(o.getStart(t)).line+1;e.push({name:s,line:c,complexity:i,cognitiveComplexity:a})},n=(s,o)=>{if(m.default.isFunctionDeclaration(s)&&s.name&&s.body?r(s.name.text,s):m.default.isVariableDeclaration(s)&&m.default.isIdentifier(s.name)&&s.initializer&&(m.default.isArrowFunction(s.initializer)||m.default.isFunctionExpression(s.initializer))?r(s.name.text,s.initializer):o&&m.default.isMethodDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body?r(`${o}.${s.name.text}`,s):o&&m.default.isConstructorDeclaration(s)&&s.body?r(`${o}.constructor`,s):o&&m.default.isGetAccessorDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body?r(`${o}.get ${s.name.text}`,s):o&&m.default.isSetAccessorDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body&&r(`${o}.set ${s.name.text}`,s),m.default.isClassDeclaration(s)&&s.name){let i=s.name.text;m.default.forEachChild(s,a=>n(a,i));return}m.default.forEachChild(s,i=>n(i,o))};return n(t,void 0),e}function Ls(t,e,r,n){let s={name:t},o=Gs(r);o!==void 0&&(s.doc=o);let i=Zc(e);i!==void 0&&(s.flags=i);let a=el(e,n);return a!==void 0&&(s.signature=a),s}function Gs(t){let e=m.default.getJSDocCommentsAndTags(t);for(let r of e)if(m.default.isJSDoc(r)&&r.comment)return m.default.getTextOfJSDocComment(r.comment)||void 0}function Zc(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=m.default.getJSDocTags(t).map(n=>n.tagName.text).filter(n=>e.has(n));return r.length>0?r:void 0}function el(t,e){let r=m.default.createPrinter({removeComments:!0}),n=s=>r.printNode(m.default.EmitHint.Unspecified,s,e);if(m.default.isFunctionDeclaration(t)||m.default.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(m.default.isVariableDeclaration(t)){if(t.type)return n(t.type);if(t.initializer&&(m.default.isArrowFunction(t.initializer)||m.default.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(m.default.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(m.default.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(m.default.isTypeAliasDeclaration(t))return n(t.type);if(m.default.isEnumDeclaration(t))return`enum ${t.name.text}`}function tl(t,e){rl(t,e),nl(t,e),ol(t,e),il(t,e),ul(t,e),Rs(t,e)}function rl(t,e){if(!m.default.isSourceFile(t))return;let r=t.statements.filter(n=>!m.default.isEmptyStatement(n));e.totalStatements=r.length,e.exportStatements=r.filter(n=>m.default.isExportDeclaration(n)||m.default.isExportAssignment(n)||Rr(n)).length}function nl(t,e){if(m.default.isJsxElement(t)||m.default.isJsxSelfClosingElement(t)||m.default.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(m.default.isFunctionDeclaration(t)||m.default.isMethodDeclaration(t)||m.default.isArrowFunction(t)||m.default.isClassDeclaration(t)||m.default.isVariableStatement(t)||m.default.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}m.default.isExportDeclaration(t)&&!sl(t)&&(e.hasTypesOnly=!1)}function sl(t){return t.isTypeOnly?!0:!t.exportClause||!m.default.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function ol(t,e){if(!m.default.isImportDeclaration(t)||!t.moduleSpecifier||!m.default.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(m.default.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)r.push(s.name.text);else m.default.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:P(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function il(t,e){m.default.isExportDeclaration(t)?al(t,e):m.default.isExportAssignment(t)?e.exports.set("default",{name:"default"}):Rr(t)&&pl(t,e)}function al(t,e){if(t.moduleSpecifier&&m.default.isStringLiteral(t.moduleSpecifier))cl(t,t.moduleSpecifier.text,e);else if(t.exportClause&&m.default.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let n=r.name.text;e.exports.set(n,{name:n})}}function cl(t,e,r){let n=ll(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:P(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function ll(t){return t.exportClause?m.default.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function pl(t,e){if((m.default.isFunctionDeclaration(t)||m.default.isClassDeclaration(t)||m.default.isInterfaceDeclaration(t)||m.default.isTypeAliasDeclaration(t)||m.default.isEnumDeclaration(t))&&t.name){let n=t.name.text;e.exports.set(n,Ls(n,t,t,e.sourceFile));return}if(m.default.isVariableStatement(t)){for(let n of t.declarationList.declarations)if(m.default.isIdentifier(n.name)){let s=n.name.text;e.exports.set(s,Ls(s,n,t,e.sourceFile))}}}function ul(t,e){if(!m.default.isCallExpression(t))return;let r=t.arguments[0];!r||!m.default.isStringLiteral(r)||(t.expression.kind===m.default.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:P(r.text),type:"dynamic"}):m.default.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:P(r.text),type:"require"}))}function fl(t,e){let r=Mr.default.basename(t).toLowerCase(),n=Mr.default.extname(t).toLowerCase();return ue().some(o=>r.includes(o))?"test":Hr(r)?"config":e.imports.some(o=>Ct().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>wt()?"barrel":"logic"}function Rr(t){return m.default.canHaveModifiers(t)&&m.default.getModifiers(t)?.some(e=>e.kind===m.default.SyntaxKind.ExportKeyword)===!0}function ml(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let n=new Map;for(let s of e.statements){if(!m.default.isImportDeclaration(s)||!m.default.isStringLiteral(s.moduleSpecifier))continue;let o=s.moduleSpecifier.text,i=s.importClause;if(i&&(i.name&&n.set(i.name.text,o),i.namedBindings&&m.default.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=dl(s);if(o){let i=hl(s);i&&ft(i,o,n,r);continue}m.default.isClassDeclaration(s)&&s.name&&gl(s,s.name.text,n,r)}}function gl(t,e,r,n){for(let s of t.members)m.default.isMethodDeclaration(s)&&s.body&&m.default.isIdentifier(s.name)?ft(s.body,`${e}.${s.name.text}`,r,n):m.default.isConstructorDeclaration(s)&&s.body&&ft(s.body,`${e}.constructor`,r,n)}function dl(t){if(Rr(t)){if(m.default.isFunctionDeclaration(t)&&t.name)return t.name.text;if(m.default.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(m.default.isIdentifier(e.name)&&e.initializer&&(m.default.isArrowFunction(e.initializer)||m.default.isFunctionExpression(e.initializer)))return e.name.text}}}function hl(t){if(m.default.isFunctionDeclaration(t))return t.body;if(m.default.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(m.default.isArrowFunction(e.initializer)||m.default.isFunctionExpression(e.initializer)))return e.initializer}}function ft(t,e,r,n){if(m.default.isCallExpression(t)&&m.default.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})}m.default.forEachChild(t,s=>ft(s,e,r,n))}function mt(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"}function _s(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 Os(t,e){if(e.length===0)return"ui";try{let r=require("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 Te(t,e){let r=_(t);if(r==="stylus"){let o=_s(e,t);return{imports:o,exports:[],tags:[],category:Os(e,o)}}if(r==="scss"){let{imports:o,root:i,exports:a,tags:c}=$e(e,t);return{imports:o,exports:a,tags:c,category:mt(i,o)}}if(r==="less"){let{imports:o,root:i,exports:a,tags:c}=Be(e,t);return{imports:o,exports:a,tags:c,category:mt(i,o)}}let{imports:n,root:s}=We(e,t);return{imports:n,exports:[],tags:[],category:mt(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Dr(r,n,"javascript")],["typescript",(r,n)=>Dr(r,n,"typescript")],["css",Te],["scss",Te],["less",Te],["stylus",Te],["coffeescript",us],["livescript",ks],["lua",vs],["python",Is],["go",bs],["gherkin",Tr],["markdown",Ts]])se(t,e);async function js(t,e){let r=_(t),n=Bn(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}var Lr=g(require("path"));function yl(t,e){let r=e.get(t.path);r!==void 0&&(t.coveragePct=r)}function Ws(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 xl(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 bl(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 zs(t){return Math.round(t*1e4)/1e4}function Sl(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=zs(Math.min(1,o)),r.push(n.exportUsageRatio)}r.length>0&&(t.avgExportUsage=zs(r.reduce((n,s)=>n+s,0)/r.length),t.maxExportUsage=Math.max(...r))}function Gr(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function kl(t,e){let r=e.toPath,n=Lr.default.basename(r,Lr.default.extname(r)).replace(/\.(test|spec)$/,"");Gr(t.tags,n,"import")}function Cl(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Gr(t.tags,r,"import")}function vl(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Gr(t.tags,s.name,"comment-marker")}function wl(t,e,r){!e.toPath||e.isExternal||(kl(t,e),Cl(t,e),vl(t,e,r))}function Bs(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(Sl(r,t),e.size>0&&yl(r,e),r.category==="test")for(let n of r.imports)xl(r,n,t),wl(r,n,t);bl(r,t)}}var Me=g(require("fs")),R=g(require("path"));var _r=g(require("fs")),Q=g(require("path")),Ee=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 Us(a);if(r!==o&&!r.startsWith(`${o}/`))return null;let c=r.slice(o.length).replace(/^\//,"");return c?Us(Q.default.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=_r.default.readFileSync(Q.default.join(e,"go.mod"),"utf-8"),o=Fl(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 Q.default.join(o,i)}}}};function Fl(t,e){let r=t.split(`
31
- `),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("=>")){$s(a,e,s);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&$s(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function $s(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=Q.default.isAbsolute(s)?s:Q.default.resolve(e,s);r.set(o,i)}function Us(t){let e;try{e=_r.default.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:Q.default.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}var Hs=g(require("fs")),gt=g(require("path")),Ae=class{extensions=[".lua"];resolve(e,r,n,s){let o=r.replace(/\./g,gt.default.sep),i=[n,gt.default.join(n,"lib")];for(let a of i){if(!Hs.default.existsSync(a))continue;let c=s(gt.default.join(a,"_dummy.lua"),o);if(c)return[c]}return null}};var Ks=g(require("path")),Pe=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let o=s(Ks.default.join(n,"_dummy"),`./${r}`);return o?[o]:null}};var Vs=g(require("fs")),dt=g(require("path")),Ne=class{extensions=[".py"];resolve(e,r,n,s){let o=r.replace(/\./g,dt.default.sep),i=dt.default.join(n,`${o}.py`);if(Js(i))return[{path:i,isExternal:!1}];let a=dt.default.join(n,o,"__init__.py");return Js(a)?[{path:a,isExternal:!1}]:null}};function Js(t){try{return Vs.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var Or=g(require("path")),Tl=["~","http://","https://","//","data:","sass:"],Ie=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(Tl.some(p=>r.startsWith(p)))return null;let o=s(e,r);if(o)return[o];let i=Or.default.dirname(r),a=Or.default.basename(r),c=i==="."?`_${a}`:`${i}/_${a}`,l=s(e,c);return l?[l]:null}};var q=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??[new Ne,new Ae,new Ee,new Ie,new Pe]}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`${R.default.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=R.default.dirname(e),s=r.startsWith("/")?r:R.default.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=R.default.join(e,`index${r}`);if(this.isFile(o))return{path:o,isExternal:n};if(r===".py"){let i=R.default.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:n}}return null}isFile(e){try{return Me.default.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=R.default.join(r,"tsconfig.json");if(Me.default.existsSync(n))try{let o=JSON.parse(Me.default.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=R.default.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=R.default.join(n,a);try{if(Me.default.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...o,path:c}}catch{}}return{...o,path:n}}let i=this.resolveLocalPath(R.default.join(n,"_dummy"),s.slice(1));return i?{...o,path:i.path}:null}return null}};var El=["tests","test","__tests__","specs","spec"],Qs=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),Al=600;function Pl(t,e){if(t.length===0)return e;let r=t.map(i=>E.default.dirname(i).split(E.default.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(E.default.sep)||E.default.sep,o=E.default.relative(e,s);return o.startsWith("..")||E.default.isAbsolute(o)?e:s}var De=class{constructor(e,r=null,n,s,o=!1,i=new Map,a=!0){this.rootDir=e;this.enableGitStats=o;this.coverageMap=i;this.parallelParsing=a;this.previousGraph=r,this.resolver=n||new q(e),this.lockFile=nn(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;async build(e){let r=e.map(n=>E.default.isAbsolute(n)?n:E.default.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=as(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(Pl(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
25
+ `;return`${l+d+u+o}
26
+ ${p}`}};function Va(t){let e=t.split(`
27
+ `),r=-1;return e.forEach((s,i)=>{(s.trimStart().startsWith("import ")||s.trimStart().startsWith("from "))&&(r=i)}),r<0?0:e.slice(0,r+1).reduce((s,i)=>s+i.length+1,0)}var wr=g(require("path")),Fr=g(require("typescript"));var Qa=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,at=class{name="vitest";canHandle(e){return M.has(wr.default.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(Qa,""),i=Fr.default.createSourceFile(wr.default.basename(e),s,Fr.default.ScriptTarget.Latest,!0),o=mr(i),[a]=o;if(!a)return s;let c=gr(a,"tags",i),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=o.flatMap(u=>{let d=n.length===0?hr(u,"tags",i):dr(u,"tags",xr(l),i);return d?[d]:[]});return p.length>0?yr(s,p):s}};var rs={vitest:()=>new at,playwright:()=>new it,cypress:()=>new tt,jest:()=>new st},qa={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function Ya(t){let e=ve.default.createSourceFile("detect.ts",t,ve.default.ScriptTarget.Latest,!0);for(let r of e.statements){if(!ve.default.isImportDeclaration(r)||!ve.default.isStringLiteral(r.moduleSpecifier))continue;let n=qa[r.moduleSpecifier.text];if(n)return n}return null}var Tr=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return M.has(ct.default.extname(e).toLowerCase())}apply(e,r,n){let s=Ya(r)??this.matchOverride(e)??this.defaultFramework;return(rs[s]??rs.vitest)().apply(e,r,n)}matchOverride(e){let r=ct.default.relative(this.rootDir,e).split(ct.default.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Yn(n,r))return s;return null}};function ns(t="vitest",e={},r=process.cwd()){return[new rt,new ot,new nt,new Tr(r,t,Object.entries(e))]}function ss(t,e){return e.find(r=>r.canHandle(t))??null}var Xa=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,Za=new Set(["import"]),ec=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function tc(t,e,r,n){let s;try{s=await Er.default.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let i=ss(t,n);if(!i)return{path:t,status:"unchanged"};let o=i.apply(t,s,e);return o===s?{path:t,status:"unchanged"}:(r||await Er.default.writeFile(t,o,"utf8"),{path:t,status:"updated"})}async function Ar(t,e,r){let n=fe(e),s=n.tagApplier?.framework??"vitest",i=n.tagApplier?.frameworkOverrides??{},o=ns(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 h of c.tags)Za.has(h.kind)&&Xa.test(h.name)&&(ec.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let u=is.default.resolve(e,c.path),d=await tc(u,p,r.dryRun,o);d.path=c.path,a.files.push(d),d.status==="updated"?a.updated++:d.status==="unchanged"?a.unchanged++:a.errors++}return a}var lt=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};var le=g(require("fs")),E=g(require("path")),Xs=g(require("piscina"));var pt=require("child_process"),ut=class{getChangedFiles(e,r){try{let s=[["diff","--name-only"],["diff","--cached","--name-only"],["ls-files","--others","--exclude-standard"],...r?[["diff","--name-only","--end-of-options",`${r}...HEAD`]]:[]].flatMap(i=>{try{return(0,pt.execFileSync)("git",i,{cwd:e,encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
28
+ `).map(a=>a.trim()).filter(a=>a!=="")}catch{return[]}});return Array.from(new Set(s))}catch(n){return console.error("Error getting git diff:",n),[]}}},os="%x00%H%x09%ae%x09%at",as=256*1024*1024;function cs(t,e){let r="",n=0;for(let s of t.split(`
29
+ `)){if(s.startsWith("\0")){let[,c,l]=s.slice(1).split(" ");r=c??"",n=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,r,n)}}function ls(t){let e=new Map;try{let r=(0,pt.execFileSync)("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${os}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:as});cs(r,(n,s,i)=>{let o=e.get(n);if(o){o.commitCount90d+=1;return}e.set(n,{commitCount90d:1,lastAuthor:s||void 0,lastCommitAt:i||void 0})})}catch{return e}try{let r=(0,pt.execFileSync)("git",["-C",t,"log","--name-status","-M",`--format=${os}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:as});cs(r,(n,s,i)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:i||void 0})})}catch{}return e}var Pr=g(require("path"));function _(t){switch(Pr.default.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":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=Pr.default.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}var us=g(require("coffeescript"));function O(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function ie(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 oe(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.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 O(t.value)}}function H(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function rc(t,e){let r=fs(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:P(r),type:"static"}:null}function nc(t,e){let r=e.variable?.base?.value==="require",n=fs(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:P(n),type:"require"}}function ps(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=H(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>H(s.variable)??H(s)).filter(s=>!!s).map(s=>({name:s}));let n=H(r);return n?[{name:n}]:[]}function sc(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=H(t.variable)??H(t.variable?.base);return e?[{name:e}]:[]}function ic(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let i=rc(t,e);i&&r.push(i)}else if(s==="Call"){let i=nc(t,e);i&&r.push(i)}else if(s==="Assign"){let i=H(e.variable?.base),o=e.variable?.properties?.[0]?.name?.value;i==="module"&&o==="exports"?n.push(...ps(e,void 0)):i==="exports"&&typeof o=="string"&&n.push(...ps(e,o))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...sc(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function Nr(t,e,r,n){if(!(!e||typeof e!="object")){ic(t,e,r,n);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)Nr(t,o,r,n);else Nr(t,i,r,n)}}}function ms(t,e){let r=ie(e),n=oe(t,r),s=[],i=[];try{Nr(t,us.default.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(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}var ae=require("@cucumber/gherkin"),gs=require("@cucumber/messages");var oc=gs.IdGenerator.uuid();function Ir(t,e){let r=new Set;try{let n=new ae.AstBuilder(oc),s=new ae.GherkinClassicTokenMatcher,o=new ae.Parser(n,s).parse(e);o.feature&&(o.feature.tags.forEach(a=>{r.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),o.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(c=>{r.add(c.name.startsWith("@")?c.name.slice(1):c.name)}),a.scenario.examples.forEach(c=>{c.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})),a.rule&&a.rule.children.forEach(c=>{c.scenario&&c.scenario.tags.forEach(l=>{r.add(l.name.startsWith("@")?l.name.slice(1):l.name)})})}))}catch(n){console.warn(`[GherkinParser] Failed to parse ${t}:`,n)}return{imports:[],exports:[],tags:Array.from(r).map(n=>({name:n,kind:"comment-marker"})),category:"test"}}se("gherkin",Ir);var bs=g(require("path")),Ss=require("@lezer/go");function K(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function we(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
30
+ `&&r++;return r}function ac(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 o=e.slice(s.from,s.to);(o==="&&"||o==="||")&&r++;break}}let i=s.firstChild;for(;i;)n(i),i=i.nextSibling}return n(t),r}function hs(t,e,r,n){let s=r?1:1+e,i=K(t),o=r?e:e+1,a=i[1];a&&a.type.name!=="Block"&&(s+=ce(a,o,!1,n));let c=i.find(p=>p.type.name==="Block");c&&(s+=ce(c,o,!1,n));let l=i.findIndex(p=>p.type.name==="else");if(l>=0){let p=i[l+1];p?.type.name==="IfStatement"?s+=hs(p,e,!0,n):p&&(s+=1+ce(p,e+1,!1,n))}return s}function ds(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 cc(t,e,r){let n=0,s=t.firstChild;for(;s;)n+=ce(s,e,!1,r),s=s.nextSibling;return n}function lc(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 hs(t,e,r,n);if(s==="ForStatement"||s==="SwitchStatement"||s==="SelectStatement")return ds(t,e,n);let i=s==="LogicOp"&&lc(t,n)?1:0;return e>0&&s==="FunctionLiteral"?i+ds(t,e,n):i+cc(t,e,n)}function pc(t,e){return ce(t,0,!1,e)}function ft(t,e){return{complexity:ac(t,e),cognitiveComplexity:pc(t,e)}}function Dr(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 ys(t,e){let r=[],n=t.cursor();do if(n.name==="FunctionDecl"){let s=n.node.getChild("DefName");if(s){let i=e.slice(s.from,s.to),{complexity:o,cognitiveComplexity:a}=ft(n.node,e);r.push({name:i,line:we(e,n.from),complexity:o,cognitiveComplexity:a})}}else if(n.name==="MethodDecl"){let s=n.node.getChild("FieldName");if(s){let i=e.slice(s.from,s.to),o=Dr(n.node,e),a=o?`${o}.${i}`:i,{complexity:c,cognitiveComplexity:l}=ft(n.node,e);r.push({name:a,line:we(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var uc=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,fc=/^\/\/go:build\s+(.+)$/,mc=/^\/\/\s*\+build\s+(.+)$/;function ks(t,e){let r=[],n=new Map,s=new Set,i=new Set,o=new Map,a=Ss.parser.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let y=e.slice(c.from,c.to),k=y.match(uc);k?.[1]&&s.add(k[1]);let D=y.match(fc);D&&xs(D[1],i);let N=y.match(mc);N&&xs(N[1],i);break}case"ImportSpec":{let y=c.node.getChild("String");if(y){let D=e.slice(y.from,y.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:D,isExternal:!0,isStyle:!1,type:"static"});let N=c.node.getChild("DefName"),j=N?e.slice(N.from,N.to):D.split("/").pop();j&&j!=="_"&&j!=="."&&o.set(j,D)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let y=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(y){let k=e.slice(y.from,y.to);k!=="_"&&/^[A-Z]/.test(k)&&!n.has(k)&&n.set(k,{name:k})}break}}while(c.next());let l=r.some(y=>y.rawSpecifier==="testing"),p=bs.default.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",u=new Set([...s,...i]),{complexity:d,cognitiveComplexity:h}=ft(a.topNode,e),C=ys(a,e),v=p==="test"?[]:gc(a,e,o);return{imports:r,exports:Array.from(n.values()),tags:Array.from(u).map(y=>({name:y,kind:"comment-marker"})),category:p,rawCallEdges:v,complexity:d,cognitiveComplexity:h,...C.length>0?{functions:C}:{}}}function gc(t,e,r){let n=[];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 d=e.slice(p.from,p.to),h=r.get(d);if(h){let C=e.slice(u.from,u.to);n.push({from:a,to:C,toSpecifier:h})}}}}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=Dr(i.node,e);s(a,l?`${l}.${c}`:c)}}while(i.next());return n}function xs(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}var Cs=g(require("livescript"));function J(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function dc(t){if(!t)return[];if(t.constructor?.name==="Class"){let r=J(t.title);return r?[{name:r}]:[]}if(t.constructor?.name==="Obj"&&Array.isArray(t.items))return t.items.map(r=>J(r.key)??J(r.val)).filter(r=>!!r).map(r=>({name:r}));let e=J(t);return e?[{name:e}]:[]}function hc(t){let e=t.constructor?.name||t.type;if(e==="Assign"&&t.left?.constructor?.name==="Chain"){let r=t.left,n=J(r.head),i=r.tails?.[0]?.key?.name;if(n==="module"&&i==="exports")return dc(t.right);if(n==="exports"&&typeof i=="string")return[{name:i}];if(r.head?.verb==="out"&&typeof i=="string")return[{name:i}]}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=>J(n.val)??J(n.key)).filter(n=>!!n).map(n=>({name:n}))}return[]}var yc=new Set(["first_line","first_column","last_line","last_column","line","column"]);function xc(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=O(n);return{fromPath:e,toPath:"",rawSpecifier:s,isStyle:P(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 i=O(s);return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:P(i),type:"require"}}}}return null}function Mr(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=xc(t,e);s&&n.push(s),r.push(...hc(t));for(let i in t){if(yc.has(i))continue;let o=t[i];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let a of o)n.push(...Mr(a,e,r));else n.push(...Mr(o,e,r))}return n}function vs(t,e){let r=ie(e),n=oe(t,r),s=[],i=[];try{s=Mr(Cs.default.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(r).map(c=>({name:c,kind:"comment-marker"})),category:n}}var ws=g(require("luaparse"));function bc(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 i;if(s.type==="CallExpression"){let o=s.arguments?.[0];o?.type==="StringLiteral"&&(i=O(o.raw))}else if(s.type==="StringCallExpression"){let o=s.argument;o?.type==="StringLiteral"&&(i=O(o.raw))}i&&r.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)n(a);else n(o)}}}return n(t),r}function Sc(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 kc(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 Cc(t){let e=t.body,r=Sc(e),n=kc(e);for(let i of e)if(i.type==="FunctionDeclaration")i.identifier?.type==="MemberExpression"?i.identifier.base.type==="Identifier"&&r.has(i.identifier.base.name)&&n.push({name:i.identifier.identifier.name}):i.identifier?.type==="Identifier"&&!i.isLocal&&n.push({name:i.identifier.name});else if(i.type==="AssignmentStatement")for(let o of i.variables)o.type==="MemberExpression"&&o.base.type==="Identifier"&&r.has(o.base.name)&&n.push({name:o.identifier.name});let s=new Set;return n.filter(i=>s.has(i.name)?!1:(s.add(i.name),!0))}function Fs(t,e){let r=ie(e),n=oe(t,r),s=[],i=[];try{let o=ws.default.parse(e);s=bc(o,t),i=Cc(o)}catch{}return{imports:s,exports:i,tags:Array.from(r).map(o=>({name:o,kind:"comment-marker"})),category:n}}var vc=["http://","https://","mailto:","//"],wc="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",Fc=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${wc})\\b`,"g"),Ts;async function Tc(){return Ts??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),Ts}function Ec(t){let e=t.trim();return e.length===0||e.startsWith("#")||vc.some(r=>e.startsWith(r))}function Ac(t,e){let r=t.match(Fc);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function Es(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!Ec(t.url)&&r.push({fromPath:e,toPath:"",rawSpecifier:t.url,isStyle:!1,type:"static"}),(t.type==="code"||t.type==="inlineCode")&&typeof t.value=="string"&&r.push(...Ac(t.value,e)),Array.isArray(t.children))for(let n of t.children)Es(n,e,r)}async function As(t,e){let n=(await Tc()).parse(e),s=[];Es(n,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"}}var Is=g(require("path")),Ds=require("@lezer/python");function Pc(t){let e=1;function r(n){switch(n.type.name){case"IfStatement":{e+=K(n).filter(i=>i.type.name==="if"||i.type.name==="elif").length;break}case"TryStatement":{e+=K(n).filter(i=>i.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 Nc(t,e){let r=0,n=K(t),s=0,i=0;for(;i<n.length;){let o=n[i];if(o?.type.name==="if"||o?.type.name==="elif"){let a=s>0;r+=a?1:1+e;let c=a?e:e+1,l=n[i+1],p=n[i+2];l&&(r+=L(l,c)),p&&(r+=L(p,c)),s++,i+=3}else if(o?.type.name==="else"){r+=1;let a=n[i+1];a&&(r+=L(a,e+1)),i+=2}else i++}return r}function Ic(t,e){let r=0,n=K(t),s=0;for(;s<n.length;){let i=n[s];if(i?.type.name==="except"){for(r+=1+e,s++;s<n.length&&n[s]?.type.name!=="Body";)r+=L(n[s],e),s++;s<n.length&&(r+=L(n[s],e),s++)}else i?.type.name==="Body"&&(r+=L(i,e)),s++}return r}function Ps(t,e){let r=1+e,n=t.firstChild;for(;n;)r+=L(n,e+1),n=n.nextSibling;return r}function Dc(t,e){let r=0,n=t.firstChild;for(;n;)r+=L(n,e),n=n.nextSibling;return r}function L(t,e){let r=t.type.name;if(r==="IfStatement")return Nc(t,e);if(r==="TryStatement")return Ic(t,e);if(r==="ForStatement"||r==="WhileStatement")return Ps(t,e);let n=r==="ConditionalExpression"||r==="and"||r==="or"?1:0;return e>0&&(r==="FunctionDefinition"||r==="LambdaExpression")?n+Ps(t,e):n+Dc(t,e)}function Mc(t){return L(t,0)}function Rr(t){return{complexity:Pc(t),cognitiveComplexity:Mc(t)}}function Ns(t,e){let r=[];function n(o,a){let{complexity:c,cognitiveComplexity:l}=Rr(o);r.push({name:a,line:we(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"),d=u?e.slice(u.from,u.to):void 0;d&&n(p,c?`${c}.${d}`:d),s(p)}else i(p);p=p.nextSibling}}return}if(o.type.name==="FunctionDefinition"){let a=o.getChild("VariableName");a&&n(o,e.slice(a.from,a.to)),s(o);return}s(o)}return i(t.topNode),r}var Rc=new Set(["pytest","unittest","nose","hypothesis"]);function Ms(t,e){let r=[],n=[],s=new Set,i=Is.default.basename(t).toLowerCase(),o=Ds.parser.parse(e),a=o.cursor();do switch(a.name){case"Comment":{let h=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);h?.[1]&&s.add(h[1]);break}case"ImportStatement":{for(let h of Lc(a.node,e,t))r.push(h);break}case"FunctionDefinition":case"ClassDefinition":{let h=a.node.parent;if(h?.name==="Script"||h?.name==="DecoratedStatement"&&h.parent?.name==="Script"){let v=a.node.getChild("VariableName");v&&n.push({name:e.slice(v.from,v.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let h=a.node.firstChild;h?.name==="VariableName"&&n.push({name:e.slice(h.from,h.to)})}break}}while(a.next());let c=Wc(i,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=Rr(o.topNode),u=Ns(o,e),d=c==="test"?[]:zc(o,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:d,complexity:l,cognitiveComplexity:p,...u.length>0?{functions:u}:{}}}function Lc(t,e,r){let n=t.firstChild;return n?n.name==="from"?Gc(t,e,r):_c(t,e,r):[]}function Gc(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 i=e.slice(n.to,s.from).trim(),o=Oc(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[Fe(r,i,o,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[Fe(r,l+c.replace(/\./g,"/"),o,!1)]:o[0]==="*"?[Fe(r,l.slice(0,-1),["*"],!1)]:o.map(p=>Fe(r,l+p,[p],!1))}function _c(t,e,r){let n=[],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),n.push(Fe(r,i,["*"],!0))}s=s.nextSibling}return n}function Oc(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 jc(t,e){let r=new Map,n=t.cursor();do{if(n.name!=="ImportStatement")continue;let i=n.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 d=e.slice(u.from,u.to),h=d;if(u.nextSibling?.type.name==="as"){let v=u.nextSibling.nextSibling;v?.type.name==="VariableName"&&(h=e.slice(v.from,v.to),u=v)}let C=c===0?a:l?p+l.replace(/\./g,"/"):p+d;r.set(h,C)}u=u.nextSibling}}while(n.next());return r}function zc(t,e){let r=jc(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),d=r.get(u);d&&n.push({from:c,to:u,toSpecifier:d})}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 d=u.getChild("VariableName"),h=d?e.slice(d.from,d.to):void 0;h&&s(u,l?`${l}.${h}`:h)}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),n}function Fe(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function Wc(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=>Rc.has(n.rawSpecifier))?"test":"logic"}var _r=g(require("path")),m=g(require("typescript"));var x=g(require("typescript"));function Bc(t){let e=1;function r(n){switch(n.kind){case x.default.SyntaxKind.IfStatement:case x.default.SyntaxKind.ConditionalExpression:case x.default.SyntaxKind.ForStatement:case x.default.SyntaxKind.ForInStatement:case x.default.SyntaxKind.ForOfStatement:case x.default.SyntaxKind.WhileStatement:case x.default.SyntaxKind.DoStatement:case x.default.SyntaxKind.CatchClause:case x.default.SyntaxKind.CaseClause:e++;break;case x.default.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===x.default.SyntaxKind.AmpersandAmpersandToken||s===x.default.SyntaxKind.BarBarToken||s===x.default.SyntaxKind.QuestionQuestionToken)&&e++;break}}x.default.forEachChild(n,r)}return r(t),e}function Ls(t,e,r){let n=r?1:1+e,s=r?e:e+1;return n+=V(t.expression,s,!1),n+=V(t.thenStatement,s,!1),t.elseStatement&&(x.default.isIfStatement(t.elseStatement)?n+=Ls(t.elseStatement,e,!0):n+=1+V(t.elseStatement,e+1,!1)),n}function Rs(t,e){let r=1+e;return x.default.forEachChild(t,n=>{r+=V(n,e+1,!1)}),r}function $c(t,e){let r=1+e;return x.default.forEachChild(t,n=>{r+=V(n,e,!1)}),r}function Uc(t,e){let r=0;return x.default.forEachChild(t,n=>{r+=V(n,e,!1)}),r}function Hc(t){let e=t.operatorToken.kind;return e===x.default.SyntaxKind.AmpersandAmpersandToken||e===x.default.SyntaxKind.BarBarToken||e===x.default.SyntaxKind.QuestionQuestionToken}function V(t,e,r){if(x.default.isIfStatement(t))return Ls(t,e,r);if(x.default.isForStatement(t)||x.default.isForInStatement(t)||x.default.isForOfStatement(t)||x.default.isWhileStatement(t)||x.default.isDoStatement(t)||x.default.isSwitchStatement(t))return Rs(t,e);if(x.default.isCatchClause(t))return $c(t,e);let n=0;return x.default.isConditionalExpression(t)&&(n+=1),x.default.isBinaryExpression(t)&&Hc(t)&&(n+=1),e>0&&(x.default.isFunctionDeclaration(t)||x.default.isFunctionExpression(t)||x.default.isArrowFunction(t))?n+Rs(t,e):n+Uc(t,e)}function Kc(t){return V(t,0,!1)}function Lr(t){return{complexity:Bc(t),cognitiveComplexity:Kc(t)}}var w=g(require("typescript")),Gr=new Set(["test","describe","it"]);function Gs(t,e){Jc(t,e),Qc(t,e),qc(t,e),Yc(t,e)}function Jc(t,e){if((w.default.isFunctionDeclaration(t)||w.default.isVariableDeclaration(t))&&t.name&&w.default.isIdentifier(t.name)&&Vc(t)){let r;if(w.default.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(w.default.isArrowFunction(n)||w.default.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Vc(t){if(w.default.isFunctionDeclaration(t))return w.default.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&w.default.isSourceFile(e.parent)}function Qc(t,e){if(!w.default.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 qc(t,e){if(!w.default.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 Yc(t,e){if(w.default.isCallExpression(t)&&Xc(t.expression))for(let r of t.arguments)w.default.isObjectLiteralExpression(r)&&Zc(r,e)}function Xc(t){return w.default.isIdentifier(t)?Gr.has(t.text):!!(w.default.isPropertyAccessExpression(t)&&(Gr.has(t.name.text)||w.default.isIdentifier(t.expression)&&Gr.has(t.expression.text)))}function Zc(t,e){for(let r of t.properties){if(!w.default.isPropertyAssignment(r)||!w.default.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=w.default.isArrayLiteralExpression(n)?n.elements.filter(w.default.isStringLiteral):r.name.text==="tag"&&w.default.isStringLiteral(n)?[n]:[];for(let i of s)e.tags.add({name:i.text.replace(/^@/,""),kind:"comment-marker"})}}function Or(t,e,r){let n=[],s=new Map,i=new Set,o=m.default.createSourceFile(t,e,m.default.ScriptTarget.Latest,!0,r==="typescript"?m.default.ScriptKind.TSX:m.default.ScriptKind.JSX),a={filePath:t,imports:n,exports:s,tags:i,rawCallEdges:[],sourceFile:o,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},c=v=>{nl(v,a),m.default.forEachChild(v,c)};c(o);let l=gl(t,a);(l==="test"||l==="barrel")&&i.add({name:l,kind:"comment-marker"}),l!=="test"&&dl(a,o);let p=o.statements[0],u=p?Os(p):void 0,{complexity:d,cognitiveComplexity:h}=Lr(o),C=el(o);return{imports:n,exports:Array.from(s.values()),tags:Array.from(i),category:l,rawCallEdges:a.rawCallEdges??[],complexity:d,cognitiveComplexity:h,...C.length>0?{functions:C}:{},...u!==void 0?{description:u}:{}}}function el(t){let e=[],r=(s,i)=>{let{complexity:o,cognitiveComplexity:a}=Lr(i),c=t.getLineAndCharacterOfPosition(i.getStart(t)).line+1;e.push({name:s,line:c,complexity:o,cognitiveComplexity:a})},n=(s,i)=>{if(m.default.isFunctionDeclaration(s)&&s.name&&s.body?r(s.name.text,s):m.default.isVariableDeclaration(s)&&m.default.isIdentifier(s.name)&&s.initializer&&(m.default.isArrowFunction(s.initializer)||m.default.isFunctionExpression(s.initializer))?r(s.name.text,s.initializer):i&&m.default.isMethodDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body?r(`${i}.${s.name.text}`,s):i&&m.default.isConstructorDeclaration(s)&&s.body?r(`${i}.constructor`,s):i&&m.default.isGetAccessorDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body?r(`${i}.get ${s.name.text}`,s):i&&m.default.isSetAccessorDeclaration(s)&&m.default.isIdentifier(s.name)&&s.body&&r(`${i}.set ${s.name.text}`,s),m.default.isClassDeclaration(s)&&s.name){let o=s.name.text;m.default.forEachChild(s,a=>n(a,o));return}m.default.forEachChild(s,o=>n(o,i))};return n(t,void 0),e}function _s(t,e,r,n){let s={name:t},i=Os(r);i!==void 0&&(s.doc=i);let o=tl(e);o!==void 0&&(s.flags=o);let a=rl(e,n);return a!==void 0&&(s.signature=a),s}function Os(t){let e=m.default.getJSDocCommentsAndTags(t);for(let r of e)if(m.default.isJSDoc(r)&&r.comment)return m.default.getTextOfJSDocComment(r.comment)||void 0}function tl(t){let e=new Set(["deprecated","internal","public","alpha","beta"]),r=m.default.getJSDocTags(t).map(n=>n.tagName.text).filter(n=>e.has(n));return r.length>0?r:void 0}function rl(t,e){let r=m.default.createPrinter({removeComments:!0}),n=s=>r.printNode(m.default.EmitHint.Unspecified,s,e);if(m.default.isFunctionDeclaration(t)||m.default.isMethodDeclaration(t)){let s=t.parameters.map(n).join(", "),i=t.type?n(t.type):"void";return`${t.typeParameters?`<${t.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${s}) => ${i}`}if(m.default.isVariableDeclaration(t)){if(t.type)return n(t.type);if(t.initializer&&(m.default.isArrowFunction(t.initializer)||m.default.isFunctionExpression(t.initializer))){let s=t.initializer,i=s.parameters.map(n).join(", "),o=s.type?n(s.type):"unknown";return`(${i}) => ${o}`}return}if(m.default.isClassDeclaration(t)&&t.name)return`class ${t.name.text}`;if(m.default.isInterfaceDeclaration(t))return`interface ${t.name.text}`;if(m.default.isTypeAliasDeclaration(t))return n(t.type);if(m.default.isEnumDeclaration(t))return`enum ${t.name.text}`}function nl(t,e){sl(t,e),il(t,e),al(t,e),cl(t,e),ml(t,e),Gs(t,e)}function sl(t,e){if(!m.default.isSourceFile(t))return;let r=t.statements.filter(n=>!m.default.isEmptyStatement(n));e.totalStatements=r.length,e.exportStatements=r.filter(n=>m.default.isExportDeclaration(n)||m.default.isExportAssignment(n)||jr(n)).length}function il(t,e){if(m.default.isJsxElement(t)||m.default.isJsxSelfClosingElement(t)||m.default.isJsxFragment(t)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(m.default.isFunctionDeclaration(t)||m.default.isMethodDeclaration(t)||m.default.isArrowFunction(t)||m.default.isClassDeclaration(t)||m.default.isVariableStatement(t)||m.default.isEnumDeclaration(t)){e.hasTypesOnly=!1;return}m.default.isExportDeclaration(t)&&!ol(t)&&(e.hasTypesOnly=!1)}function ol(t){return t.isTypeOnly?!0:!t.exportClause||!m.default.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function al(t,e){if(!m.default.isImportDeclaration(t)||!t.moduleSpecifier||!m.default.isStringLiteral(t.moduleSpecifier))return;let r=[];if(t.importClause&&(t.importClause.name&&r.push("default"),t.importClause.namedBindings))if(m.default.isNamedImports(t.importClause.namedBindings))for(let s of t.importClause.namedBindings.elements)r.push(s.name.text);else m.default.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:P(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function cl(t,e){m.default.isExportDeclaration(t)?ll(t,e):m.default.isExportAssignment(t)?e.exports.set("default",{name:"default"}):jr(t)&&fl(t,e)}function ll(t,e){if(t.moduleSpecifier&&m.default.isStringLiteral(t.moduleSpecifier))pl(t,t.moduleSpecifier.text,e);else if(t.exportClause&&m.default.isNamedExports(t.exportClause))for(let r of t.exportClause.elements){let n=r.name.text;e.exports.set(n,{name:n})}}function pl(t,e,r){let n=ul(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:P(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function ul(t){return t.exportClause?m.default.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function fl(t,e){if((m.default.isFunctionDeclaration(t)||m.default.isClassDeclaration(t)||m.default.isInterfaceDeclaration(t)||m.default.isTypeAliasDeclaration(t)||m.default.isEnumDeclaration(t))&&t.name){let n=t.name.text;e.exports.set(n,_s(n,t,t,e.sourceFile));return}if(m.default.isVariableStatement(t)){for(let n of t.declarationList.declarations)if(m.default.isIdentifier(n.name)){let s=n.name.text;e.exports.set(s,_s(s,n,t,e.sourceFile))}}}function ml(t,e){if(!m.default.isCallExpression(t))return;let r=t.arguments[0];!r||!m.default.isStringLiteral(r)||(t.expression.kind===m.default.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:P(r.text),type:"dynamic"}):m.default.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:P(r.text),type:"require"}))}function gl(t,e){let r=_r.default.basename(t).toLowerCase(),n=_r.default.extname(t).toLowerCase();return ue().some(i=>r.includes(i))?"test":Qr(r)?"config":e.imports.some(i=>Tt().some(o=>i.rawSpecifier.includes(o)))?"test":n===".tsx"||n===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>Pt()?"barrel":"logic"}function jr(t){return m.default.canHaveModifiers(t)&&m.default.getModifiers(t)?.some(e=>e.kind===m.default.SyntaxKind.ExportKeyword)===!0}function dl(t,e){let r=t.rawCallEdges??[];t.rawCallEdges=r;let n=new Map;for(let s of e.statements){if(!m.default.isImportDeclaration(s)||!m.default.isStringLiteral(s.moduleSpecifier))continue;let i=s.moduleSpecifier.text,o=s.importClause;if(o&&(o.name&&n.set(o.name.text,i),o.namedBindings&&m.default.isNamedImports(o.namedBindings)))for(let a of o.namedBindings.elements)n.set(a.name.text,i)}if(n.size!==0)for(let s of e.statements){let i=yl(s);if(i){let o=xl(s);o&&mt(o,i,n,r);continue}m.default.isClassDeclaration(s)&&s.name&&hl(s,s.name.text,n,r)}}function hl(t,e,r,n){for(let s of t.members)m.default.isMethodDeclaration(s)&&s.body&&m.default.isIdentifier(s.name)?mt(s.body,`${e}.${s.name.text}`,r,n):m.default.isConstructorDeclaration(s)&&s.body&&mt(s.body,`${e}.constructor`,r,n)}function yl(t){if(jr(t)){if(m.default.isFunctionDeclaration(t)&&t.name)return t.name.text;if(m.default.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(m.default.isIdentifier(e.name)&&e.initializer&&(m.default.isArrowFunction(e.initializer)||m.default.isFunctionExpression(e.initializer)))return e.name.text}}}function xl(t){if(m.default.isFunctionDeclaration(t))return t.body;if(m.default.isVariableStatement(t)){for(let e of t.declarationList.declarations)if(e.initializer&&(m.default.isArrowFunction(e.initializer)||m.default.isFunctionExpression(e.initializer)))return e.initializer}}function mt(t,e,r,n){if(m.default.isCallExpression(t)&&m.default.isIdentifier(t.expression)){let s=t.expression.text,i=r.get(s);i&&!n.some(o=>o.from===e&&o.to===s&&o.toSpecifier===i)&&n.push({from:e,to:s,toSpecifier:i})}m.default.forEachChild(t,s=>mt(s,e,r,n))}function gt(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"}function js(t,e){let r=[],n=/@require\s+['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"require"}),s=n.exec(t)}let i=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=i.exec(t);s!==null;){let o=s[1];o&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=i.exec(t)}return r}function zs(t,e){if(e.length===0)return"ui";try{let r=require("stylus");return new r.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 Te(t,e){let r=_(t);if(r==="stylus"){let i=js(e,t);return{imports:i,exports:[],tags:[],category:zs(e,i)}}if(r==="scss"){let{imports:i,root:o,exports:a,tags:c}=Ue(e,t);return{imports:i,exports:a,tags:c,category:gt(o,i)}}if(r==="less"){let{imports:i,root:o,exports:a,tags:c}=$e(e,t);return{imports:i,exports:a,tags:c,category:gt(o,i)}}let{imports:n,root:s}=Be(e,t);return{imports:n,exports:[],tags:[],category:gt(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Or(r,n,"javascript")],["typescript",(r,n)=>Or(r,n,"typescript")],["css",Te],["scss",Te],["less",Te],["stylus",Te],["coffeescript",ms],["livescript",vs],["lua",Fs],["python",Ms],["go",ks],["gherkin",Ir],["markdown",As]])se(t,e);async function Ws(t,e){let r=_(t),n=Un(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}var zr=g(require("path"));function bl(t,e){let r=e.get(t.path);r!==void 0&&(t.coveragePct=r)}function $s(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 Sl(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 kl(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 Bs(t){return Math.round(t*1e4)/1e4}function Cl(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 i;if(n.symbols===void 0){if(n.type==="side-effect")continue;i=1}else n.symbols.includes("*")?i=1:i=n.symbols.length/s.exports.length;n.exportUsageRatio=Bs(Math.min(1,i)),r.push(n.exportUsageRatio)}r.length>0&&(t.avgExportUsage=Bs(r.reduce((n,s)=>n+s,0)/r.length),t.maxExportUsage=Math.max(...r))}function Wr(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function vl(t,e){let r=e.toPath,n=zr.default.basename(r,zr.default.extname(r)).replace(/\.(test|spec)$/,"");Wr(t.tags,n,"import")}function wl(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Wr(t.tags,r,"import")}function Fl(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Wr(t.tags,s.name,"comment-marker")}function Tl(t,e,r){!e.toPath||e.isExternal||(vl(t,e),wl(t,e),Fl(t,e,r))}function Us(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(Cl(r,t),e.size>0&&bl(r,e),r.category==="test")for(let n of r.imports)Sl(r,n,t),Tl(r,n,t);kl(r,t)}}var De=g(require("fs")),R=g(require("path"));var Br=g(require("fs")),Q=g(require("path")),Ee=class{extensions=[".go"];goModCache=new Map;resolve(e,r,n,s){let{mod:i,replaces:o}=this.readGoMod(n);if(!i)return null;let a=this.applyReplace(r,o,n);if(a!==void 0)return Ks(a);if(r!==i&&!r.startsWith(`${i}/`))return null;let c=r.slice(i.length).replace(/^\//,"");return c?Ks(Q.default.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=Br.default.readFileSync(Q.default.join(e,"go.mod"),"utf-8"),i=El(s,e);return this.goModCache.set(e,i),i}catch{return this.goModCache.set(e,n),n}}applyReplace(e,r,n){for(let[s,i]of r){if(e===s)return i;if(e.startsWith(`${s}/`)){let o=e.slice(s.length+1);return Q.default.join(i,o)}}}};function El(t,e){let r=t.split(`
31
+ `),n=null,s=new Map,i=!1;for(let o of r){let a=o.trim();if(a.startsWith("module ")){n=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){i=!0;continue}if(i&&a===")"){i=!1;continue}if(i&&a.includes("=>")){Hs(a,e,s);continue}!i&&/^replace\s+/.test(a)&&a.includes("=>")&&Hs(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function Hs(t,e,r){let[n,s]=t.split("=>").map(a=>a.trim());if(!n||!s)return;let i=n.split(/\s+/)[0];if(!s.startsWith(".")&&!s.startsWith("/"))return;let o=Q.default.isAbsolute(s)?s:Q.default.resolve(e,s);r.set(i,o)}function Ks(t){let e;try{e=Br.default.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:Q.default.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}var Js=g(require("fs")),dt=g(require("path")),Ae=class{extensions=[".lua"];resolve(e,r,n,s){let i=r.replace(/\./g,dt.default.sep),o=[n,dt.default.join(n,"lib")];for(let a of o){if(!Js.default.existsSync(a))continue;let c=s(dt.default.join(a,"_dummy.lua"),i);if(c)return[c]}return null}};var Vs=g(require("path")),Pe=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let i=s(Vs.default.join(n,"_dummy"),`./${r}`);return i?[i]:null}};var qs=g(require("fs")),ht=g(require("path")),Ne=class{extensions=[".py"];resolve(e,r,n,s){let i=r.replace(/\./g,ht.default.sep),o=ht.default.join(n,`${i}.py`);if(Qs(o))return[{path:o,isExternal:!1}];let a=ht.default.join(n,i,"__init__.py");return Qs(a)?[{path:a,isExternal:!1}]:null}};function Qs(t){try{return qs.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var $r=g(require("path")),Al=["~","http://","https://","//","data:","sass:"],Ie=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(Al.some(p=>r.startsWith(p)))return null;let i=s(e,r);if(i)return[i];let o=$r.default.dirname(r),a=$r.default.basename(r),c=o==="."?`_${a}`:`${o}/_${a}`,l=s(e,c);return l?[l]:null}};var q=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??[new Ne,new Ae,new Ee,new Ie,new Pe]}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`${R.default.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 i=this.resolveAllUncached(e,r);return this.resolutionCache.set(n,i.length>0?i:null),i}resolveAllUncached(e,r){let n=this.resolvePathAlias(r);if(n)return[n];if(r.startsWith(".")||r.startsWith("/")){let o=this.resolveLocalPath(e,r);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=o.resolve(e,r,this.rootDir,s);if(a)return a}let i=this.resolveWorkspaceImport(r);return i?[i]:[{path:r,isExternal:!0}]}resolve(e,r){return this.resolveAll(e,r)[0]??null}resolveLocalPath(e,r){let n=R.default.dirname(e),s=r.startsWith("/")?r:R.default.resolve(n,r),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,r,n){let s=e+r;if(this.isFile(s))return{path:s,isExternal:n};let i=R.default.join(e,`index${r}`);if(this.isFile(i))return{path:i,isExternal:n};if(r===".py"){let o=R.default.join(e,"__init__.py");if(this.isFile(o))return{path:o,isExternal:n}}return null}isFile(e){try{return De.default.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 i=this.tryAliasSubstitutions(s,n[1]||"");if(i)return i}}for(let r of this.tsconfigSearchPaths){let n=R.default.join(r,"tsconfig.json");if(De.default.existsSync(n))try{let i=JSON.parse(De.default.readFileSync(n,"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]||"",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 i of e){let o=i.replace("*",r),a=R.default.resolve(n,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[r,n]of this.workspaceMap){if(e!==r&&!e.startsWith(`${r}/`))continue;let s=e.slice(r.length),i={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=R.default.join(n,a);try{if(De.default.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...i,path:c}}catch{}}return{...i,path:n}}let o=this.resolveLocalPath(R.default.join(n,"_dummy"),s.slice(1));return o?{...i,path:o.path}:null}return null}};var Pl=["tests","test","__tests__","specs","spec"],Ys=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),Nl=600;function Il(t,e){if(t.length===0)return e;let r=t.map(o=>E.default.dirname(o).split(E.default.sep)),n=r[0]??[];for(let o of r.slice(1)){let a=0;for(;a<n.length&&a<o.length&&n[a]===o[a];)a++;n=n.slice(0,a)}let s=n.join(E.default.sep)||E.default.sep,i=E.default.relative(e,s);return i.startsWith("..")||E.default.isAbsolute(i)?e:s}var Me=class{constructor(e,r=null,n,s,i=!1,o=new Map,a=!0){this.rootDir=e;this.enableGitStats=i;this.coverageMap=o;this.parallelParsing=a;this.previousGraph=r,this.resolver=n||new q(e),this.lockFile=on(e),s&&(this.progressCallback=s)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;gitStatsMap=null;async build(e){let r=e.map(n=>E.default.isAbsolute(n)?n:E.default.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=ls(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(Il(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
32
32
  Done. Total processed: ${this.visited.size} nodes.
33
- `),Bs(this.graph.nodes,this.coverageMap),new I(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??Al;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r))){e.maxThreads!==void 0&&e.maxThreads<1&&process.stderr.write(`
33
+ `),Us(this.graph.nodes,this.coverageMap),new I(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??Nl;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r))){e.maxThreads!==void 0&&e.maxThreads<1&&process.stderr.write(`
34
34
  Warning: parallelParsing.maxThreads (${e.maxThreads}) must be at least 1; using 1.
35
- `);try{let n=E.default.join(__dirname,"parse-worker.js");this.pool=new qs.default({filename:n,...e.maxThreads!==void 0?{maxThreads:Math.max(1,e.maxThreads)}:{}})}catch(n){process.stderr.write(`
35
+ `);try{let n=E.default.join(__dirname,"parse-worker.js");this.pool=new Xs.default({filename:n,...e.maxThreads!==void 0?{maxThreads:Math.max(1,e.maxThreads)}:{}})}catch(n){process.stderr.write(`
36
36
  Warning: failed to start parse worker pool, falling back to synchronous parsing: ${n}
37
- `),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=le.default.readdirSync(o,{withFileTypes:!0})}catch{continue}for(let a of i)if(a.isDirectory())Qs.has(a.name)||s.push(E.default.join(o,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=ue(),n=o=>r.some(i=>o.name.includes(i));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let o=E.default.dirname(s);if(o===s)break;for(let i of El){let a=E.default.join(o,i);try{le.default.statSync(a).isDirectory()&&this.walkProject(a,n)}catch{}}s=o}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,r){let n;try{n=le.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let o=E.default.join(e,s.name);s.isDirectory()?Qs.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=le.default.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=E.default.relative(this.rootDir,e),s=await this.getNode(e,n,r);s.imports=await this.resolveImports(e,s.imports),Ws(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=le.default.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
37
+ `),this.pool=null}}}hasAtLeastFiles(e,r){let n=0,s=[e];for(;s.length>0;){let i=s.pop();if(i===void 0)continue;let o;try{o=le.default.readdirSync(i,{withFileTypes:!0})}catch{continue}for(let a of o)if(a.isDirectory())Ys.has(a.name)||s.push(E.default.join(i,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=ue(),n=i=>r.some(o=>i.name.includes(o));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let i=E.default.dirname(s);if(i===s)break;for(let o of Pl){let a=E.default.join(i,o);try{le.default.statSync(a).isDirectory()&&this.walkProject(a,n)}catch{}}s=i}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,r){let n;try{n=le.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let i=E.default.join(e,s.name);s.isDirectory()?Ys.has(s.name)||this.walkProject(i,r):s.isFile()&&r(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(r=>this.finishFile(r)))}}async finishFile(e){let r=le.default.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=E.default.relative(this.rootDir,e),s=await this.getNode(e,n,r);s.imports=await this.resolveImports(e,s.imports),$s(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 i=await this.tryParse(e,r);if(!i)return this.makeStubNode(e,r,n);let o=this.resolveCallEdges(e,i.rawCallEdges),a=this.buildNode(e,r,n,i,o);return this.attachGitStats(a,r),a}async tryParse(e,r){let n=le.default.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
38
38
  Warning: failed to parse ${r}: ${s}
39
- `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):js(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:E.default.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:f,cognitiveComplexity:d,functions:h}=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}:{},...f!==void 0?{complexity:f}:{},...d!==void 0?{cognitiveComplexity:d}:{},...h!==void 0?{functions:h}:{}}}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)for(let i of o){let a={...s,toPath:i.isExternal?i.path:E.default.relative(this.rootDir,i.path),isExternal:i.isExternal};i.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=i.workspacePackage),i.isExternal?this.attachLockfileVersion(a):this.enqueue(i.path),n.push(a)}}return n}attachLockfileVersion(e){if(!this.lockFile)return;let r=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],n=r?this.lockFile.dependencies[r]:void 0;n&&(e.version=n.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function Ys(t,e){return{identifier:e?.identifier??new ct,featureMap:e?.featureDetection===!1?new Map:W(t.nodes,e?.featureDetection??void 0)}}function Xs(t,e,r,n,s){for(let o of e){let i=t.nodes.get(o);if(!i)continue;let a=new B(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 f=r.get(c.path);if(f)return n(f),!1}return s(c),!0},{direction:"incoming"})}}function jr(t,e,r){let{identifier:n,featureMap:s}=Ys(t,r),o=new Set;for(let i of e){let a=s.get(i);a&&o.add(a.tag)}return Xs(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 zr(t,e,r){let{identifier:n,featureMap:s}=Ys(t,r),o=new Set;return Xs(t,e,s,()=>{},i=>{n.isTestNode(i)&&o.add(i.path)}),Array.from(o)}var Zs=g(require("fs")),pe=g(require("path"));async function eo(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},o=pe.default.resolve(t);return await new De(o,r,n.pathAliases?new q(o,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function to(t,e={}){let r=pe.default.resolve(t),n=Se(r),s=e.packages?n.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):n.packages,o=new Map(n.packages.map(a=>[a.name,a.root])),i=new ke(r,n.type);for(let a of s){let c=e.silent?void 0:f=>{process.stderr.write(`[${a.name}] Processed ${f} files...\r`)},p=await new De(r,null,new q(r,{workspaceMap:o,tsconfigSearchPaths:[a.root,r],pathAliases:e.pathAliases}),c,e.gitStats??!1,new Map,e.parallelParsing??!0).build(a.entryPoints);i.addPackage(a,p)}return i}function ro(t,e={}){let r=[],n=new Set([...e.ignoreDirs??z,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??Pt,...e.additionalExtensions??[]]);function o(i){try{let a=Zs.default.readdirSync(i,{withFileTypes:!0});for(let c of a){let l=pe.default.join(i,c.name);c.isDirectory()?n.has(c.name)||o(l):c.isFile()&&s.has(pe.default.extname(c.name).toLowerCase())&&r.push(pe.default.relative(t,l))}}catch{}}return o(t),r}var no=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;function so(t){return yt.default.join(t,je,Et)}function Nl(t,e){return e?.cachePath?yt.default.resolve(t,e.cachePath):yt.default.join(t,je,At)}function Il(t){try{if(!ht.default.existsSync(t))return null;let e=ht.default.readFileSync(t,"utf-8");return I.deserialize(JSON.parse(e))}catch{return null}}var xt=class{graphs=new Map;configs=new Map;workspaceGraphs=new Map;changeImpactCaches=new Map;dirtyRoots=new Set;watchers=new Map;lastAnalyze=new Map;duplicationTokenCaches=new Map;isConfigured(e){return this.configs.has(e)}storeConfig(e,r){this.configs.set(e,r)}getConfig(e){return this.configs.get(e)}async getOrBuild(e,r,n=new Map){let s=this.configs.get(e),o=this.graphs.get(e)??Il(Nl(e,s)),i=await eo(e,r,o,{...Z(s),coverageMap:n});return this.graphs.set(e,i),i}require(e){let r=this.graphs.get(e);if(!r)throw new Error('No graph cached for this root. Call "analyze" first.');return r}async getOrBuildWorkspace(e,r={}){let n=this.workspaceGraphs.get(e);if(n)return n;let s=await to(e,r);return this.workspaceGraphs.set(e,s),s}requireWorkspace(e){let r=this.workspaceGraphs.get(e);if(!r)throw new Error('No workspace graph cached for this root. Call "analyze" first.');return r}hasWorkspace(e){return this.workspaceGraphs.has(e)}getOrBuildChangeImpact(e){let r=this.changeImpactCaches.get(e);if(r)return r;let n=this.require(e),s=_t(n);return this.changeImpactCaches.set(e,s),s}storeLastAnalyze(e,r){this.lastAnalyze.set(e,r)}startWatching(e){if(!this.watchers.has(e))try{let r=ht.default.watch(e,{recursive:!0},(n,s)=>{!s||no.test(s)||this.dirtyRoots.add(e)});r.on("error",()=>{this.watchers.delete(e)}),this.watchers.set(e,r)}catch{}}async ensureFresh(e){if(!this.dirtyRoots.has(e))return this.require(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e);let r=this.lastAnalyze.get(e);return r?.kind==="single"?this.getOrBuild(e,r.entryPoints,r.coverageMap):this.require(e)}async ensureFreshWorkspace(e){if(!this.dirtyRoots.has(e))return this.requireWorkspace(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e),this.workspaceGraphs.delete(e);let r=this.configs.get(e);return this.getOrBuildWorkspace(e,Z(r))}async getDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);return r||(r=Ue(so(e)),this.duplicationTokenCaches.set(e,r)),r}flushDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);if(r)try{He(r,so(e))}catch(n){process.stderr.write(`Warning: failed to persist duplication token cache: ${n}
40
- `)}}invalidate(e){let r=this.graphs.has(e)||this.workspaceGraphs.has(e);return this.graphs.delete(e),this.workspaceGraphs.delete(e),this.changeImpactCaches.delete(e),this.dirtyRoots.delete(e),this.duplicationTokenCaches.delete(e),r}};var Y=g(require("path"));var oo=g(require("fs")),io=g(require("os")),bt=g(require("path"));function b(t){return{content:[{type:"text",text:JSON.stringify(t)}]}}function ao(t){if(!bt.default.isAbsolute(t))throw new Error("root must be an absolute path");let e=bt.default.resolve(t),r=io.default.homedir();if(e!==r&&!e.startsWith(r+bt.default.sep))throw new Error("root must be within the user home directory");let n;try{n=oo.default.statSync(e)}catch{throw new Error("root does not exist")}if(!n.isDirectory())throw new Error("root is not a directory")}async function co(t,e){let{root:r,entryPoints:n}=e;if(!t.isConfigured(r)){let d=fe(r,{allowJs:!1});Tt(d),t.storeConfig(r,d)}if(n.length===0){let d=Se(r);if(d.type!=="none"){let h=t.getConfig(r),C=await t.getOrBuildWorkspace(r,Z(h));t.storeLastAnalyze(r,{kind:"workspace"}),t.startWatching(r);let v=Array.from(C.packages.values()).map(({graph:y,pkg:k})=>({package:k.name,relativeRoot:k.relativeRoot,nodeCount:y.nodes.size}));return b({monorepoType:d.type,packageCount:C.packages.size,packages:v})}}let s=n.map(d=>Y.default.resolve(r,d)),o=t.getConfig(r),i=o?.coverageReportPath?It(r,o.coverageReportPath):new Map,a=await t.getOrBuild(r,s,i);t.storeLastAnalyze(r,{kind:"single",entryPoints:s,coverageMap:i}),t.startWatching(r);let c=a.serialize(),l=c.nodes.reduce((d,h)=>(d[h.category]=(d[h.category]??0)+1,d),{}),p=a.findCycles(),f=Ht(a);return b({nodeCount:c.nodes.length,categories:l,cycles:p,languageCoverage:f})}async function lo(t,e){let{root:r,file:n,depth:s=1,withMeta:o=!1}=e,i=await t.ensureFresh(r),a=Kt(i,n,s),c=o?a.map(l=>({...l,...ye(i,l.path)})):a;return b({file:n,dependencies:c})}async function po(t,e){let{root:r,file:n,withMeta:s=!1}=e,o=await t.ensureFresh(r),i=xe(o,n),a=s?i.map(c=>({...c,...ye(o,c.path)})):i;return b({file:n,dependents:a})}async function uo(t,e){let{root:r,file:n,testsOnly:s=!1,cached:o=!1,changedSymbols:i,withMeta:a=!1}=e,c=await t.ensureFresh(r),l=d=>a?d.map(h=>({path:h,...ye(c,h)})):d;if(o){let d=t.getOrBuildChangeImpact(r),h=Ot(d,n),C=s?h.filter(y=>c.nodes.get(y)?.category==="test"):h,v=l(C);return b({file:n,affected:v,count:v.length})}let p=Jt(c,n,{testsOnly:s,changedSymbols:i}),f=l(p);return b({file:n,affected:f,count:f.length})}async function fo(t,e){let{root:r,file:n,depth:s=1,withEdgeDetail:o=!1}=e,i=await t.ensureFresh(r),a=Vt(i,n,{depth:s,withEdgeDetail:o});return b({file:n,callers:a,count:a.length})}async function mo(t,e){let{root:r,entryPoints:n}=e,s=n?await t.getOrBuild(r,n.map(a=>Y.default.resolve(r,a))):await t.ensureFresh(r),o=ro(r),i=s.findUnusedFiles(o);return b({unusedFiles:i,count:i.length})}async function go(t,e){let{root:r}=e,n=await t.ensureFresh(r),s=new Map;for(let i of n.nodes.values())for(let a of i.tags)s.set(a.name,(s.get(a.name)??0)+1);let o=[...s.entries()].map(([i,a])=>({name:i,count:a})).sort((i,a)=>a.count-i.count);return b({tags:o,count:o.length})}async function ho(t,e){let{root:r,coverageThreshold:n}=e,s=await t.ensureFresh(r),o=t.getConfig(r),i=n??o?.coverageThreshold??80;if(!Je(s))return b({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let a=[...s.nodes.values()].filter(c=>c.category!=="test"&&c.category!=="config").filter(c=>c.coveragePct!==void 0&&c.coveragePct<i).map(c=>({file:c.path,coveragePct:c.coveragePct}));return b({threshold:i,uncovered:a,count:a.length})}async function yo(t,e){let{root:r}=e,s=[...(await t.ensureFresh(r)).nodes.values()].filter(o=>o.type==="markdown"&&o.staleFor&&o.staleFor.length>0).map(o=>({doc:o.path,staleFor:o.staleFor}));return b({staleDocs:s,count:s.length})}async function xo(t,e){let{root:r,metric:n="cognitiveComplexity",threshold:s=10,limit:o=20}=e,i=await t.ensureFresh(r),a=Qt(i,{metric:n,threshold:s,limit:o});return b({metric:n,threshold:s,functions:a,count:a.length})}async function bo(t,e){let{root:r,metric:n="cognitiveComplexity",minComplexity:s=10,maxCoveragePct:o=50,minChurn:i=0,limit:a=20}=e,c=await t.ensureFresh(r);if(!Je(c))return b({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let{hotspots:l,count:p,churnDataAvailable:f}=Xt(c,{metric:n,minComplexity:s,maxCoveragePct:o,minChurn:i,limit:a});return b({metric:n,minComplexity:s,maxCoveragePct:o,minChurn:i,churnDataAvailable:f,hotspots:l,count:p})}async function So(t,e){let{root:r,minLines:n=6,ignoreLiterals:s=!0,maxPunctuationRatio:o=.5,limit:i=50}=e,a=await t.ensureFresh(r),c=e.ignoreDirs??[...z,...t.getConfig(r)?.ignoreDirs??[]],{groups:l}=await Ut(a,r,{minLines:n,ignoreLiterals:s,maxPunctuationRatio:o,limit:i,ignoreDirs:c,tokenCache:await t.getDuplicationTokenCache(r)});return t.flushDuplicationTokenCache(r),b({minLines:n,groups:l,count:l.length})}async function ko(t,e){let{root:r,changedFiles:n,featureThreshold:s,format:o="tags"}=e,i=await t.ensureFresh(r),a=n??new pt().getChangedFiles().map(p=>Y.default.relative(r,Y.default.resolve(r,p))),c=s!==void 0?{featureDetection:{minOutDegree:s}}:void 0;if(o==="paths"){let p=zr(i,a,c);return b({changedFiles:a,affectedTests:p,count:p.length})}let l=jr(i,a,c);return b({changedFiles:a,proposedTags:l})}async function Co(t,e){let{root:r,entryPoints:n,featureThreshold:s}=e,o=n?await t.getOrBuild(r,n.map(c=>Y.default.resolve(r,c))):await t.ensureFresh(r),i=W(o.nodes,s!==void 0?{minOutDegree:s}:void 0),a=Array.from(i.values()).sort((c,l)=>l.outDegree-c.outDegree);return b({features:a,count:a.length})}async function vo(t,e){let{root:r,entryPoints:n,filter:s,mermaid:o=!1,slim:i=!0}=e,a=n?await t.getOrBuild(r,n.map(l=>Y.default.resolve(r,l))):await t.ensureFresh(r),c=Ye(a.serialize(),Xe(s));return o?b(ze.serialize(I.deserialize(c))):i?b(qt(c)):b(c)}async function wo(t,e){let{root:r}=e,n=await t.ensureFreshWorkspace(r);return b(Yt(n))}async function Fo(t,e){let{root:r,file:n}=e,o=(await t.ensureFreshWorkspace(r)).getAffectedAcrossPackages(n);return b({file:n,affected:o,count:o.length})}function To(t,e){let{root:r}=e,n=t.invalidate(r);return b({root:r,cleared:n,message:n?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function Eo(t,e){let{root:r,type:n}=e,s=await t.ensureFresh(r),o=tr(s);if(n)return b(rr(o,n));let i=Array.from(o.types.values());return b({count:i.length,types:i})}async function Ao(t,e){let{root:r,paths:n,minOutDegree:s}=e,o=await t.ensureFresh(r),i=Zt(o,s!==void 0?{minOutDegree:s}:void 0);if(n?.length){let c=n.map(l=>i.get(l)).filter(Boolean);return b({count:c.length,modules:c})}let a=Array.from(i.values());return b({count:a.length,modules:a})}async function Po(t,e){let{root:r,minOutDegree:n}=e,s=await t.ensureFresh(r),o=de(s,n!==void 0?{minOutDegree:n}:void 0),i=Object.fromEntries(o.features);return b({features:i,unassigned:o.unassigned})}async function No(t,e){let{root:r,function:n}=e,s=await t.ensureFresh(r);return b(Gt(s,n))}async function Io(t,e){let{root:r,name:n}=e,s=await t.ensureFresh(r),o=er(s,n);return b({name:n,matches:o,count:o.length})}async function Mo(t,e){let{root:r,entryPoints:n}=e,s=await t.ensureFresh(r),o=n?.length?n:Rt(s,r);if(o.length===0)throw new Error("No entry points found. Pass entryPoints explicitly or ensure package.json has a main/exports field.");return b(Lt(s,o))}async function Do(t,e){let r=await t.ensureFresh(e.root),n=await vr(r,e.root,{dryRun:e.dryRun??!1});return b(n)}var Ro=[{name:"analyze",description:"Build the dependency graph for a project from entry points. Returns a summary of node count, categories, and cycles. Must be called before get_dependencies, get_dependents, get_affected, or propose_tags. Pass an empty entryPoints array to auto-detect a monorepo (pnpm/npm/yarn/Nx/Turborepo) and build per-package graphs \u2014 use get_workspace_packages and get_workspace_affected for monorepo queries.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root (or monorepo root)"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root (e.g. ['src/index.ts']). Pass [] to trigger monorepo auto-detection."}},required:["root","entryPoints"]}},{name:"get_dependencies",description:"Get files that a given file imports (outgoing traversal). depth=1 returns immediate imports; omit for the full transitive tree. Each result includes the specific symbols imported from that file (when known).",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},depth:{type:"number",description:"Max traversal depth (default: 1)"},withMeta:{type:"boolean",description:"Include each result's category and export names alongside the path (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_dependents",description:"Get files that directly import a given file (one-hop incoming edges). Each result includes the specific symbols that dependent file imports from this file (when known).",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},withMeta:{type:"boolean",description:"Include each result's category and export names alongside the path (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_affected",description:"Get all files transitively affected if a given file changes \u2014 full incoming traversal upward. Use before a refactor to understand blast radius. See docs/mcp.md for details on the testsOnly, cached, changedSymbols, and withMeta options.",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},testsOnly:{type:"boolean",description:"Return only test/spec files (default: false)"},cached:{type:"boolean",description:"Use a pre-computed impact cache for O(1) lookup instead of graph traversal. Cache is built lazily on first use and reused for the session (default: false)."},changedSymbols:{type:"array",items:{type:"string"},description:"Restrict blast-radius to files that import at least one of these symbols. Omit to treat the whole file as changed (conservative, same as before)."},withMeta:{type:"boolean",description:"Return each affected file as { path, category, exports } instead of a bare path string (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_callers",description:"Get files whose exported functions call into a given file (call-graph dependents). More precise than get_affected: only files with actual runtime call edges, not mere imports. Requires prior analyze() call.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to project root"},file:{type:"string",description:"File path relative to root"},depth:{type:"number",description:"Max traversal depth (default: 1)"},withEdgeDetail:{type:"boolean",description:"Include from/to function names per edge (default: false)"}},required:["root","file"]}},{name:"find_unused",description:"Find files in the project that are not reachable from any entry point. Useful before cleanup passes. Omit entryPoints to reuse the cached graph from a prior analyze() call instead of rebuilding.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root. Omit to reuse the cached graph from a prior analyze() call."}},required:["root"]}},{name:"list_tags",description:"List every distinct tag name present in the graph, with how many nodes carry each one. Call this before querying with tag:<name> to avoid a speculative filter silently returning zero results. Includes all tag kinds \u2014 a superset of what query's slim mode keeps (slim only retains comment-marker and import tags).",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"}},required:["root"]}},{name:"find_uncovered",description:"Find non-test files whose line coverage is below the configured threshold. Requires a prior analyze() call and coverageReportPath set in mokosh.config. coverageThreshold overrides the config default (default: 80).",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},coverageThreshold:{type:"number",description:"Line-coverage % below which a file is considered uncovered. Overrides config value."}},required:["root"]}},{name:"check_doc_drift",description:"Find markdown docs whose referenced files changed more recently than the doc itself \u2014 a commit-recency heuristic for stale documentation, not a content diff. Requires a prior analyze() call with gitStats: true in mokosh.config (otherwise no file has commit-timestamp data and nothing is flagged). See docs/adr-009-markdown-parsing.md for known limitations.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"}},required:["root"]}},{name:"find_complex_functions",description:"Find individual functions/methods above a cognitive (or cyclomatic) complexity threshold, sorted worst-first. Requires a prior analyze() call. Populated for TypeScript/JavaScript, Go, and Python.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},metric:{type:"string",enum:["cognitiveComplexity","complexity"],description:"Which score to threshold/sort on (default: cognitiveComplexity)"},threshold:{type:"number",description:"Minimum score to include (default: 10)"},limit:{type:"number",description:"Max results to return, worst-first (default: 20)"}},required:["root"]}},{name:"find_risk_hotspots",description:"Find functions that are complex, in a poorly-covered file, and \u2014 when gitStats is enabled in mokosh.config \u2014 in a frequently-changed file. Requires a prior analyze() call and coverageReportPath set in mokosh.config; errors if no coverage data was loaded. Churn filtering is skipped (churnDataAvailable: false) when gitStats wasn't enabled, since complexity + low coverage alone is still a meaningful signal.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},metric:{type:"string",enum:["cognitiveComplexity","complexity"],description:"Which per-function score to filter/sort on (default: cognitiveComplexity)"},minComplexity:{type:"number",description:"Minimum per-function complexity score to include (default: 10)"},maxCoveragePct:{type:"number",description:"Maximum containing-file coverage % to include (default: 50)"},minChurn:{type:"number",description:"Minimum containing-file 90-day commit count to include (default: 0). Ignored when gitStats wasn't enabled at analyze time."},limit:{type:"number",description:"Max results to return, worst-first by metric (default: 20)"}},required:["root"]}},{name:"find_duplicates",description:"Find duplicated code blocks across the project, largest-first. CSS/SCSS/Less are matched structurally by rule body; every other parsed language is tokenized and matched via suffix array. Lock files and ignored directories are always excluded. Requires a prior analyze() call. See docs/mcp.md for matching-strategy, normalization, and caching details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},minLines:{type:"number",description:"Minimum duplicated block size in lines to report (default: 6)"},ignoreLiterals:{type:"boolean",description:"Normalize string/number literals too, not just identifiers, so only structural shape drives a match (default: true). Set false for stricter, exact-text-only matching."},maxPunctuationRatio:{type:"number",description:"Maximum fraction of a token-shingled block's window that may be object/array-literal structural punctuation ({ } : , [ ]) (default: 0.5). Filters out blocks that are mostly schema/object-literal shape instead of substantive shared logic. Does not apply to the CSS/Less/SCSS structural comparator. Set 1 to disable."},ignoreDirs:{type:"array",items:{type:"string"},description:"Directory names to exclude, matched against any path segment (default: DEFAULT_IGNORE_DIRS merged with this root's configured ignoreDirs, if any). Pass [] to disable."},limit:{type:"number",description:"Max duplicate blocks to return, largest-first (default: 50)"}},required:["root"]}},{name:"propose_tags",description:"Propose what to run based on changed files. Pass changedFiles explicitly or omit to use git diff. format='tags' (default) returns test tags for CI tag-filtering; format='paths' returns test file paths ready to pipe directly to a test runner (e.g. vitest). Feature hubs act as traversal boundaries in both modes.",inputSchema:{type:"object",properties:{root:{type:"string"},changedFiles:{type:"array",items:{type:"string"},description:"Changed files relative to root. Omit to read from git diff."},featureThreshold:{type:"number",description:"Min importers for a file to be treated as a feature hub (default: 5). A hub short-circuits traversal and emits a feature:<name> tag instead of all downstream tags."},format:{type:"string",enum:["tags","paths"],description:"Output format: 'tags' returns test tag names for CI filtering (default); 'paths' returns test file paths to pipe to a test runner."}},required:["root"]}},{name:"detect_features",description:"Identify feature hub files \u2014 non-test files that import many other internal modules (orchestrators / aggregators like src/parser.ts or src/cli/runner.ts). Returns a list sorted by import count descending.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root. Omit to use the cached graph."},featureThreshold:{type:"number",description:"Min internal imports a file must have to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"query",description:"Filter the graph by category, tag, path, or other node metadata. Returns matching nodes as JSON or a Mermaid diagram. If entryPoints is omitted the cached graph from a prior 'analyze' call is used. See docs/mcp.md for the full query DSL reference.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry points to build the graph. Omit to reuse the cached graph from a prior 'analyze' call."},filter:{type:"string",description:"Query string e.g. 'category:logic' or 'category:logic,tag:auth'. Supports: category, type, tag, path, external, importsFile, importedBy, minImports, maxImports, minSize, maxSize, hasDocstring, minCoverage, maxCoverage, minExportUsage, maxExportUsage, minComplexity, maxComplexity, minCognitiveComplexity, maxCognitiveComplexity, minCommits, maxCommits, isDocumented, isStale, lastAuthor. OR logic: any(key:val|key:val) matches if any single-key clause holds, ANDed with the rest of the query. sort: size|imports|commitCount90d|exportUsage|complexity|cognitiveComplexity, with sortDir: asc|desc (default desc). limit: N."},mermaid:{type:"boolean",description:"Return a Mermaid diagram (default: false)"},slim:{type:"boolean",description:"Compact response mode (default: true). Returns export names, meaningful tags, and a flat importsFiles path list \u2014 no edge objects, no mtime/size. Tags are filtered to kinds comment-marker and import only; function/class/variable/type/library tags are dropped in slim output. Use list_tags to see the full tag inventory, or pass slim: false to get every tag kind on matching nodes."}},required:["root","filter"]}},{name:"get_workspace_packages",description:"List all workspace packages detected in a monorepo, with their node counts and inter-package dependencies. Requires a prior analyze() call with empty entryPoints on a monorepo root.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the monorepo root"}},required:["root"]}},{name:"get_workspace_affected",description:"Cross-package blast-radius analysis. Returns every file that could be affected if a given file changes, annotated with the package it belongs to. Requires a prior analyze() call with empty entryPoints on a monorepo root.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the monorepo root"},file:{type:"string",description:"Monorepo-root-relative path of the changed file (e.g. 'packages/shared/src/utils.ts')"}},required:["root","file"]}},{name:"get_type_graph",description:"Return type-level relationships for the project. Without a type name, returns an inventory of all interfaces, classes, enums, and type aliases with their file and kind. With a type name, returns which files import that type (usedByFiles) and which types the defining file imports (uses). Requires a prior analyze() call. Only covers TypeScript/JavaScript files.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},type:{type:"string",description:"Exact exported name of the type to look up (e.g. 'FileNode'). Omit to get the full type inventory."}},required:["root"]}},{name:"get_module_responsibility",description:"Return what each file is responsible for: its semantic role, JSDoc description (when present), exported symbol names, and which feature hub it belongs to. Pass specific paths to filter, or omit paths to get all files. Requires a prior analyze() call.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},paths:{type:"array",items:{type:"string"},description:"Project-relative file paths to include. Omit to return all files."},minOutDegree:{type:"number",description:"Min imports for a file to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"get_feature_graph",description:"Group files by domain: returns which files each feature hub (high-import orchestrator) transitively owns. Each file is assigned to the most specific hub that can reach it (lowest out-degree wins). Use this instead of a full query when answering 'what files are in the X feature/module?' \u2014 it returns only paths grouped by hub, so it's substantially smaller than a full graph query for the same question; compare output sizes yourself if you need an exact figure for your repo.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},minOutDegree:{type:"number",description:"Minimum internal imports a file must have to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"get_call_graph",description:"Look up callers and callees for a named function. Returns the file that defines the function, all files/functions that call it, and all files/functions it calls. Always requires a function name \u2014 never returns the full call graph unfiltered. Call edges are only populated for TypeScript/JavaScript files.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},function:{type:"string",description:"Exact name of the function to look up (e.g. 'parseFile')."}},required:["root","function"]}},{name:"find_symbol",description:"Find every file that exports a symbol by exact name, with the best available usage info per match. Precision varies by the defining file's language \u2014 check each match's `precision` field ('call' | 'file-level') before trusting caller/importer results as symbol-exact. See docs/mcp.md for per-language coverage details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},name:{type:"string",description:"Exact export name to look up (e.g. 'parseFile')."}},required:["root","name"]}},{name:"get_api_surface",description:"Build the API surface report for a project: every exported symbol resolved to its defining file and kind, partitioned into internalFiles, unreachableFromEntry, and testFiles. Requires a prior analyze() call. When entryPoints is omitted, auto-detects from package.json exports/main/module. See docs/mcp.md for the export* expansion and partition semantics.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},entryPoints:{type:"array",items:{type:"string"},description:"Project-relative paths of public entry points (e.g. ['src/index.ts', 'src/utils.ts']). Omit to auto-detect from package.json exports / main / module fields."}},required:["root"]}},{name:"clear_cache",description:"Drop the cached dependency graph for a project root, forcing the next analyze() call to rebuild from disk. Call this after editing source files mid-session \u2014 otherwise get_affected, get_dependencies, and other query tools will reason from stale data.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root to invalidate."}},required:["root"]}},{name:"apply_tags",description:"Write @tag annotations into test file source code based on the dependency graph, as an idempotent block \u2014 re-running is safe, the existing block is replaced in place. Use dryRun=true to preview changes without writing to disk. Requires a prior analyze() call. See docs/mcp.md for tag-kind and per-language block syntax details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root."},dryRun:{type:"boolean",description:"When true, computes which files would change but does not write to disk (default: false)."}},required:["root"]}}];function kt(){let t=new xt,e=new Lo.Server({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(St.ListToolsRequestSchema,async()=>({tools:Ro})),e.setRequestHandler(St.CallToolRequestSchema,async r=>{let{name:n,arguments:s}=r.params,o=s,a={analyze:c=>co(t,c),get_dependencies:c=>lo(t,c),get_dependents:c=>po(t,c),get_affected:c=>uo(t,c),get_callers:c=>fo(t,c),find_symbol:c=>Io(t,c),find_unused:c=>mo(t,c),find_uncovered:c=>ho(t,c),list_tags:c=>go(t,c),check_doc_drift:c=>yo(t,c),find_complex_functions:c=>xo(t,c),find_risk_hotspots:c=>bo(t,c),find_duplicates:c=>So(t,c),propose_tags:c=>ko(t,c),detect_features:c=>Co(t,c),get_type_graph:c=>Eo(t,c),get_module_responsibility:c=>Ao(t,c),get_feature_graph:c=>Po(t,c),get_call_graph:c=>No(t,c),get_api_surface:c=>Mo(t,c),query:c=>vo(t,c),get_workspace_packages:c=>wo(t,c),get_workspace_affected:c=>Fo(t,c),clear_cache:c=>To(t,c),apply_tags:c=>Do(t,c)}[n];if(!a)throw new Error(`Unknown tool: ${n}`);try{return ao(o.root),await a(o)}catch(c){return{content:[{type:"text",text:`Error: ${c instanceof Error?c.message:String(c)}`}],isError:!0}}}),e}async function Ml(){let t=kt(),e=new Go.StdioServerTransport;await t.connect(e)}Ml().catch(console.error);0&&(module.exports={createMcpServer});
39
+ `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):Ws(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 i=this.resolver.resolve(e,s.toSpecifier);i&&!i.isExternal&&n.push({from:s.from,to:s.to,toFile:E.default.relative(this.rootDir,i.path)})}catch{}return n}buildNode(e,r,n,s,i){let{imports:o,exports:a,tags:c,category:l,description:p,complexity:u,cognitiveComplexity:d,functions:h}=s;return{path:r,type:_(e),category:l,imports:o,exports:a,tags:c,mtime:n.mtimeMs,size:n.size,...p!==void 0?{description:p}:{},...i.length>0?{callEdges:i}:{},...u!==void 0?{complexity:u}:{},...d!==void 0?{cognitiveComplexity:d}:{},...h!==void 0?{functions:h}:{}}}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 i=this.resolver.resolveAll(e,s.rawSpecifier);if(i.length!==0)for(let o of i){let a={...s,toPath:o.isExternal?o.path:E.default.relative(this.rootDir,o.path),isExternal:o.isExternal};o.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=o.workspacePackage),o.isExternal?this.attachLockfileVersion(a):this.enqueue(o.path),n.push(a)}}return n}attachLockfileVersion(e){if(!this.lockFile)return;let r=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],n=r?this.lockFile.dependencies[r]:void 0;n&&(e.version=n.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function Zs(t,e){return{identifier:e?.identifier??new lt,featureMap:e?.featureDetection===!1?new Map:W(t.nodes,e?.featureDetection??void 0)}}function ei(t,e,r,n,s){for(let i of e){let o=t.nodes.get(i);if(!o)continue;let a=new B(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=r.get(c.path);if(u)return n(u),!1}return s(c),!0},{direction:"incoming"})}}function Ur(t,e,r){let{identifier:n,featureMap:s}=Zs(t,r),i=new Set;for(let o of e){let a=s.get(o);a&&i.add(a.tag)}return ei(t,e,s,o=>i.add(o.tag),o=>{if(n.isTestNode(o))for(let a of o.tags)i.add(a.name)}),Array.from(i)}function Hr(t,e,r){let{identifier:n,featureMap:s}=Zs(t,r),i=new Set;return ei(t,e,s,()=>{},o=>{n.isTestNode(o)&&i.add(o.path)}),Array.from(i)}var ti=g(require("fs")),pe=g(require("path"));async function ri(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},i=pe.default.resolve(t);return await new Me(i,r,n.pathAliases?new q(i,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function ni(t,e={}){let r=pe.default.resolve(t),n=Se(r),s=e.packages?n.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):n.packages,i=new Map(n.packages.map(a=>[a.name,a.root])),o=new ke(r,n.type);for(let a of s){let c=e.silent?void 0:u=>{process.stderr.write(`[${a.name}] Processed ${u} files...\r`)},p=await new Me(r,null,new q(r,{workspaceMap:i,tsconfigSearchPaths:[a.root,r],pathAliases:e.pathAliases}),c,e.gitStats??!1,new Map,e.parallelParsing??!0).build(a.entryPoints);o.addPackage(a,p)}return o}function si(t,e={}){let r=[],n=new Set([...e.ignoreDirs??z,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??Rt,...e.additionalExtensions??[]]);function i(o){try{let a=ti.default.readdirSync(o,{withFileTypes:!0});for(let c of a){let l=pe.default.join(o,c.name);c.isDirectory()?n.has(c.name)||i(l):c.isFile()&&s.has(pe.default.extname(c.name).toLowerCase())&&r.push(pe.default.relative(t,l))}}catch{}}return i(t),r}var ii=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;function oi(t){return xt.default.join(t,ze,Dt)}function Dl(t,e){return e?.cachePath?xt.default.resolve(t,e.cachePath):xt.default.join(t,ze,Mt)}function Ml(t){try{if(!yt.default.existsSync(t))return null;let e=yt.default.readFileSync(t,"utf-8");return I.deserialize(JSON.parse(e))}catch{return null}}var bt=class{graphs=new Map;configs=new Map;workspaceGraphs=new Map;changeImpactCaches=new Map;dirtyRoots=new Set;watchers=new Map;lastAnalyze=new Map;duplicationTokenCaches=new Map;isConfigured(e){return this.configs.has(e)}storeConfig(e,r){this.configs.set(e,r)}getConfig(e){return this.configs.get(e)}async getOrBuild(e,r,n=new Map){let s=this.configs.get(e),i=this.graphs.get(e)??Ml(Dl(e,s)),o=await ri(e,r,i,{...Z(s),coverageMap:n});return this.graphs.set(e,o),o}require(e){let r=this.graphs.get(e);if(!r)throw new Error('No graph cached for this root. Call "analyze" first.');return r}async getOrBuildWorkspace(e,r={}){let n=this.workspaceGraphs.get(e);if(n)return n;let s=await ni(e,r);return this.workspaceGraphs.set(e,s),s}requireWorkspace(e){let r=this.workspaceGraphs.get(e);if(!r)throw new Error('No workspace graph cached for this root. Call "analyze" first.');return r}hasWorkspace(e){return this.workspaceGraphs.has(e)}getOrBuildChangeImpact(e){let r=this.changeImpactCaches.get(e);if(r)return r;let n=this.require(e),s=Bt(n);return this.changeImpactCaches.set(e,s),s}storeLastAnalyze(e,r){this.lastAnalyze.set(e,r)}startWatching(e){if(!this.watchers.has(e))try{let r=yt.default.watch(e,{recursive:!0},(n,s)=>{!s||ii.test(s)||this.dirtyRoots.add(e)});r.on("error",()=>{this.watchers.delete(e)}),this.watchers.set(e,r)}catch{}}async ensureFresh(e){if(!this.dirtyRoots.has(e))return this.require(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e);let r=this.lastAnalyze.get(e);return r?.kind==="single"?this.getOrBuild(e,r.entryPoints,r.coverageMap):this.require(e)}async ensureFreshWorkspace(e){if(!this.dirtyRoots.has(e))return this.requireWorkspace(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e),this.workspaceGraphs.delete(e);let r=this.configs.get(e);return this.getOrBuildWorkspace(e,Z(r))}async getDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);return r||(r=He(oi(e)),this.duplicationTokenCaches.set(e,r)),r}flushDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);if(r)try{Ke(r,oi(e))}catch(n){process.stderr.write(`Warning: failed to persist duplication token cache: ${n}
40
+ `)}}invalidate(e){let r=this.graphs.has(e)||this.workspaceGraphs.has(e);return this.graphs.delete(e),this.workspaceGraphs.delete(e),this.changeImpactCaches.delete(e),this.dirtyRoots.delete(e),this.duplicationTokenCaches.delete(e),this.configs.delete(e),r}};var Y=g(require("path"));var ai=g(require("fs")),ci=g(require("os")),St=g(require("path"));function b(t){return{content:[{type:"text",text:JSON.stringify(t)}]}}function li(t){if(!St.default.isAbsolute(t))throw new Error("root must be an absolute path");let e=St.default.resolve(t),r=ci.default.homedir();if(e!==r&&!e.startsWith(r+St.default.sep))throw new Error("root must be within the user home directory");let n;try{n=ai.default.statSync(e)}catch{throw new Error("root does not exist")}if(!n.isDirectory())throw new Error("root is not a directory")}async function pi(t,e){let{root:r,entryPoints:n}=e;if(!t.isConfigured(r)){let d=fe(r,{allowJs:!1});It(d),t.storeConfig(r,d)}if(n.length===0){let d=Se(r);if(d.type!=="none"){let h=t.getConfig(r),C=await t.getOrBuildWorkspace(r,Z(h));t.storeLastAnalyze(r,{kind:"workspace"}),t.startWatching(r);let v=Array.from(C.packages.values()).map(({graph:y,pkg:k})=>({package:k.name,relativeRoot:k.relativeRoot,nodeCount:y.nodes.size}));return b({monorepoType:d.type,packageCount:C.packages.size,packages:v})}}let s=n.map(d=>Y.default.resolve(r,d)),i=t.getConfig(r),o=i?.coverageReportPath?Gt(r,i.coverageReportPath):new Map,a=await t.getOrBuild(r,s,o);t.storeLastAnalyze(r,{kind:"single",entryPoints:s,coverageMap:o}),t.startWatching(r);let c=a.serialize(),l=c.nodes.reduce((d,h)=>(d[h.category]=(d[h.category]??0)+1,d),{}),p=a.findCycles(),u=qt(a);return b({nodeCount:c.nodes.length,categories:l,cycles:p,languageCoverage:u})}async function ui(t,e){let{root:r,file:n,depth:s=1,withMeta:i=!1}=e,o=await t.ensureFresh(r),a=Yt(o,n,s),c=i?a.map(l=>({...l,...ye(o,l.path)})):a;return b({file:n,dependencies:c})}async function fi(t,e){let{root:r,file:n,withMeta:s=!1}=e,i=await t.ensureFresh(r),o=xe(i,n),a=s?o.map(c=>({...c,...ye(i,c.path)})):o;return b({file:n,dependents:a})}async function mi(t,e){let{root:r,file:n,testsOnly:s=!1,cached:i=!1,changedSymbols:o,withMeta:a=!1}=e,c=await t.ensureFresh(r),l=d=>a?d.map(h=>({path:h,...ye(c,h)})):d;if(i){let d=t.getOrBuildChangeImpact(r),h=$t(d,n),C=s?h.filter(y=>c.nodes.get(y)?.category==="test"):h,v=l(C);return b({file:n,affected:v,count:v.length})}let p=Xt(c,n,{testsOnly:s,changedSymbols:o}),u=l(p);return b({file:n,affected:u,count:u.length})}async function gi(t,e){let{root:r,file:n,depth:s=1,withEdgeDetail:i=!1}=e,o=await t.ensureFresh(r),a=Zt(o,n,{depth:s,withEdgeDetail:i});return b({file:n,callers:a,count:a.length})}async function di(t,e){let{root:r,entryPoints:n}=e,s=n?await t.getOrBuild(r,n.map(c=>Y.default.resolve(r,c))):await t.ensureFresh(r),i=t.getConfig(r),o=si(r,{additionalIgnoreDirs:i?.ignoreDirs??[],additionalExtensions:i?.extensions??[]}),a=s.findUnusedFiles(o);return b({unusedFiles:a,count:a.length})}async function hi(t,e){let{root:r}=e,n=await t.ensureFresh(r),s=new Map;for(let o of n.nodes.values())for(let a of o.tags)s.set(a.name,(s.get(a.name)??0)+1);let i=[...s.entries()].map(([o,a])=>({name:o,count:a})).sort((o,a)=>a.count-o.count);return b({tags:i,count:i.length})}async function yi(t,e){let{root:r,coverageThreshold:n}=e,s=await t.ensureFresh(r),i=t.getConfig(r),o=n??i?.coverageThreshold??80;if(!Ve(s))return b({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let a=[...s.nodes.values()].filter(c=>c.category!=="test"&&c.category!=="config").filter(c=>c.coveragePct!==void 0&&c.coveragePct<o).map(c=>({file:c.path,coveragePct:c.coveragePct}));return b({threshold:o,uncovered:a,count:a.length})}async function xi(t,e){let{root:r}=e,s=[...(await t.ensureFresh(r)).nodes.values()].filter(i=>i.type==="markdown"&&i.staleFor&&i.staleFor.length>0).map(i=>({doc:i.path,staleFor:i.staleFor}));return b({staleDocs:s,count:s.length})}async function bi(t,e){let{root:r,metric:n="cognitiveComplexity",threshold:s=10,limit:i=20}=e,o=await t.ensureFresh(r),a=er(o,{metric:n,threshold:s,limit:i});return b({metric:n,threshold:s,functions:a,count:a.length})}async function Si(t,e){let{root:r,metric:n="cognitiveComplexity",minComplexity:s=10,maxCoveragePct:i=50,minChurn:o=0,limit:a=20}=e,c=await t.ensureFresh(r);if(!Ve(c))return b({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let{hotspots:l,count:p,churnDataAvailable:u}=nr(c,{metric:n,minComplexity:s,maxCoveragePct:i,minChurn:o,limit:a});return b({metric:n,minComplexity:s,maxCoveragePct:i,minChurn:o,churnDataAvailable:u,hotspots:l,count:p})}async function ki(t,e){let{root:r,minLines:n=6,ignoreLiterals:s=!0,maxPunctuationRatio:i=.5,limit:o=50}=e,a=await t.ensureFresh(r),c=e.ignoreDirs??[...z,...t.getConfig(r)?.ignoreDirs??[]],{groups:l}=await Qt(a,r,{minLines:n,ignoreLiterals:s,maxPunctuationRatio:i,limit:o,ignoreDirs:c,tokenCache:await t.getDuplicationTokenCache(r)});return t.flushDuplicationTokenCache(r),b({minLines:n,groups:l,count:l.length})}async function Ci(t,e){let{root:r,changedFiles:n,base:s,featureThreshold:i,format:o="tags"}=e,a=await t.ensureFresh(r),c=n??new ut().getChangedFiles(r,s).map(u=>Y.default.relative(r,Y.default.resolve(r,u))),l=i!==void 0?{featureDetection:{minOutDegree:i}}:void 0;if(o==="paths"){let u=Hr(a,c,l);return b({changedFiles:c,affectedTests:u,count:u.length})}let p=Ur(a,c,l);return b({changedFiles:c,proposedTags:p})}async function vi(t,e){let{root:r,entryPoints:n,featureThreshold:s}=e,i=n?await t.getOrBuild(r,n.map(c=>Y.default.resolve(r,c))):await t.ensureFresh(r),o=W(i.nodes,s!==void 0?{minOutDegree:s}:void 0),a=Array.from(o.values()).sort((c,l)=>l.outDegree-c.outDegree);return b({features:a,count:a.length})}async function wi(t,e){let{root:r,entryPoints:n,filter:s,mermaid:i=!1,slim:o=!0}=e,a=n?await t.getOrBuild(r,n.map(l=>Y.default.resolve(r,l))):await t.ensureFresh(r),c=Xe(a.serialize(),Ze(s));return i?b(We.serialize(I.deserialize(c))):o?b(tr(c)):b(c)}async function Fi(t,e){let{root:r}=e,n=await t.ensureFreshWorkspace(r);return b(rr(n))}async function Ti(t,e){let{root:r,file:n}=e,i=(await t.ensureFreshWorkspace(r)).getAffectedAcrossPackages(n);return b({file:n,affected:i,count:i.length})}function Ei(t,e){let{root:r}=e,n=t.invalidate(r);return b({root:r,cleared:n,message:n?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function Ai(t,e){let{root:r,type:n}=e,s=await t.ensureFresh(r),i=or(s);if(n)return b(ar(i,n));let o=Array.from(i.types.values());return b({count:o.length,types:o})}async function Pi(t,e){let{root:r,paths:n,minOutDegree:s}=e,i=await t.ensureFresh(r),o=sr(i,s!==void 0?{minOutDegree:s}:void 0);if(n?.length){let c=n.map(l=>o.get(l)).filter(Boolean);return b({count:c.length,modules:c})}let a=Array.from(o.values());return b({count:a.length,modules:a})}async function Ni(t,e){let{root:r,minOutDegree:n}=e,s=await t.ensureFresh(r),i=de(s,n!==void 0?{minOutDegree:n}:void 0),o=Object.fromEntries(i.features);return b({features:o,unassigned:i.unassigned})}async function Ii(t,e){let{root:r,function:n}=e,s=await t.ensureFresh(r);return b(Wt(s,n))}async function Di(t,e){let{root:r,name:n}=e,s=await t.ensureFresh(r),i=ir(s,n);return b({name:n,matches:i,count:i.length})}async function Mi(t,e){let{root:r,entryPoints:n}=e,s=await t.ensureFresh(r),i=n?.length?n:jt(s,r);if(i.length===0)throw new Error("No entry points found. Pass entryPoints explicitly or ensure package.json has a main/exports field.");return b(zt(s,i))}async function Ri(t,e){let r=await t.ensureFresh(e.root),n=await Ar(r,e.root,{dryRun:e.dryRun??!1});return b(n)}var Li=[{name:"analyze",description:"Build the dependency graph for a project from entry points. Returns a summary of node count, categories, and cycles. Must be called before get_dependencies, get_dependents, get_affected, or propose_tags. Pass an empty entryPoints array to auto-detect a monorepo (pnpm/npm/yarn/Nx/Turborepo) and build per-package graphs \u2014 use get_workspace_packages and get_workspace_affected for monorepo queries.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root (or monorepo root)"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root (e.g. ['src/index.ts']). Pass [] to trigger monorepo auto-detection."}},required:["root","entryPoints"]}},{name:"get_dependencies",description:"Get files that a given file imports (outgoing traversal). depth=1 returns immediate imports; omit for the full transitive tree. Each result includes the specific symbols imported from that file (when known).",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},depth:{type:"number",description:"Max traversal depth (default: 1)"},withMeta:{type:"boolean",description:"Include each result's category and export names alongside the path (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_dependents",description:"Get files that directly import a given file (one-hop incoming edges). Each result includes the specific symbols that dependent file imports from this file (when known).",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},withMeta:{type:"boolean",description:"Include each result's category and export names alongside the path (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_affected",description:"Get all files transitively affected if a given file changes \u2014 full incoming traversal upward. Use before a refactor to understand blast radius. See docs/mcp.md for details on the testsOnly, cached, changedSymbols, and withMeta options.",inputSchema:{type:"object",properties:{root:{type:"string"},file:{type:"string",description:"File path relative to root"},testsOnly:{type:"boolean",description:"Return only test/spec files (default: false)"},cached:{type:"boolean",description:"Use a pre-computed impact cache for O(1) lookup instead of graph traversal. Cache is built lazily on first use and reused for the session (default: false)."},changedSymbols:{type:"array",items:{type:"string"},description:"Restrict blast-radius to files that import at least one of these symbols. Omit to treat the whole file as changed (conservative, same as before)."},withMeta:{type:"boolean",description:"Return each affected file as { path, category, exports } instead of a bare path string (default: false). Set true when you need to decide what to do with a result without a follow-up lookup."}},required:["root","file"]}},{name:"get_callers",description:"Get files whose exported functions call into a given file (call-graph dependents). More precise than get_affected: only files with actual runtime call edges, not mere imports. Requires prior analyze() call.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to project root"},file:{type:"string",description:"File path relative to root"},depth:{type:"number",description:"Max traversal depth (default: 1)"},withEdgeDetail:{type:"boolean",description:"Include from/to function names per edge (default: false)"}},required:["root","file"]}},{name:"find_unused",description:"Find files in the project that are not reachable from any entry point. Useful before cleanup passes. Omit entryPoints to reuse the cached graph from a prior analyze() call instead of rebuilding.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root. Omit to reuse the cached graph from a prior analyze() call."}},required:["root"]}},{name:"list_tags",description:"List every distinct tag name present in the graph, with how many nodes carry each one. Call this before querying with tag:<name> to avoid a speculative filter silently returning zero results. Includes all tag kinds \u2014 a superset of what query's slim mode keeps (slim only retains comment-marker and import tags).",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"}},required:["root"]}},{name:"find_uncovered",description:"Find non-test files whose line coverage is below the configured threshold. Requires a prior analyze() call and coverageReportPath set in mokosh.config. coverageThreshold overrides the config default (default: 80).",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},coverageThreshold:{type:"number",description:"Line-coverage % below which a file is considered uncovered. Overrides config value."}},required:["root"]}},{name:"check_doc_drift",description:"Find markdown docs whose referenced files changed more recently than the doc itself \u2014 a commit-recency heuristic for stale documentation, not a content diff. Requires a prior analyze() call with gitStats: true in mokosh.config (otherwise no file has commit-timestamp data and nothing is flagged). See docs/adr-009-markdown-parsing.md for known limitations.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"}},required:["root"]}},{name:"find_complex_functions",description:"Find individual functions/methods above a cognitive (or cyclomatic) complexity threshold, sorted worst-first. Requires a prior analyze() call. Populated for TypeScript/JavaScript, Go, and Python.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},metric:{type:"string",enum:["cognitiveComplexity","complexity"],description:"Which score to threshold/sort on (default: cognitiveComplexity)"},threshold:{type:"number",description:"Minimum score to include (default: 10)"},limit:{type:"number",description:"Max results to return, worst-first (default: 20)"}},required:["root"]}},{name:"find_risk_hotspots",description:"Find functions that are complex, in a poorly-covered file, and \u2014 when gitStats is enabled in mokosh.config \u2014 in a frequently-changed file. Requires a prior analyze() call and coverageReportPath set in mokosh.config; errors if no coverage data was loaded. Churn filtering is skipped (churnDataAvailable: false) when gitStats wasn't enabled, since complexity + low coverage alone is still a meaningful signal.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},metric:{type:"string",enum:["cognitiveComplexity","complexity"],description:"Which per-function score to filter/sort on (default: cognitiveComplexity)"},minComplexity:{type:"number",description:"Minimum per-function complexity score to include (default: 10)"},maxCoveragePct:{type:"number",description:"Maximum containing-file coverage % to include (default: 50)"},minChurn:{type:"number",description:"Minimum containing-file 90-day commit count to include (default: 0). Ignored when gitStats wasn't enabled at analyze time."},limit:{type:"number",description:"Max results to return, worst-first by metric (default: 20)"}},required:["root"]}},{name:"find_duplicates",description:"Find duplicated code blocks across the project, largest-first. CSS/SCSS/Less are matched structurally by rule body; every other parsed language is tokenized and matched via suffix array. Lock files and ignored directories are always excluded. Requires a prior analyze() call. See docs/mcp.md for matching-strategy, normalization, and caching details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},minLines:{type:"number",description:"Minimum duplicated block size in lines to report (default: 6)"},ignoreLiterals:{type:"boolean",description:"Normalize string/number literals too, not just identifiers, so only structural shape drives a match (default: true). Set false for stricter, exact-text-only matching."},maxPunctuationRatio:{type:"number",description:"Maximum fraction of a token-shingled block's window that may be object/array-literal structural punctuation ({ } : , [ ]) (default: 0.5). Filters out blocks that are mostly schema/object-literal shape instead of substantive shared logic. Does not apply to the CSS/Less/SCSS structural comparator. Set 1 to disable."},ignoreDirs:{type:"array",items:{type:"string"},description:"Directory names to exclude, matched against any path segment (default: DEFAULT_IGNORE_DIRS merged with this root's configured ignoreDirs, if any). Pass [] to disable."},limit:{type:"number",description:"Max duplicate blocks to return, largest-first (default: 50)"}},required:["root"]}},{name:"propose_tags",description:"Propose what to run based on changed files. Pass changedFiles explicitly or omit to use git diff. format='tags' (default) returns test tags for CI tag-filtering; format='paths' returns test file paths ready to pipe directly to a test runner (e.g. vitest). Feature hubs act as traversal boundaries in both modes.",inputSchema:{type:"object",properties:{root:{type:"string"},changedFiles:{type:"array",items:{type:"string"},description:"Changed files relative to root. Omit to read from git diff."},base:{type:"string",description:"Diff against this ref (e.g. 'origin/main') instead of only local working-tree/staged/untracked changes. Ignored when changedFiles is given. Needed in CI, where the checkout is already clean."},featureThreshold:{type:"number",description:"Min importers for a file to be treated as a feature hub (default: 5). A hub short-circuits traversal and emits a feature:<name> tag instead of all downstream tags."},format:{type:"string",enum:["tags","paths"],description:"Output format: 'tags' returns test tag names for CI filtering (default); 'paths' returns test file paths to pipe to a test runner."}},required:["root"]}},{name:"detect_features",description:"Identify feature hub files \u2014 non-test files that import many other internal modules (orchestrators / aggregators like src/parser.ts or src/cli/runner.ts). Returns a list sorted by import count descending.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry point files relative to root. Omit to use the cached graph."},featureThreshold:{type:"number",description:"Min internal imports a file must have to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"query",description:"Filter the graph by category, tag, path, or other node metadata. Returns matching nodes as JSON or a Mermaid diagram. If entryPoints is omitted the cached graph from a prior 'analyze' call is used. See docs/mcp.md for the full query DSL reference.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"},description:"Entry points to build the graph. Omit to reuse the cached graph from a prior 'analyze' call."},filter:{type:"string",description:"Query string e.g. 'category:logic' or 'category:logic,tag:auth'. Supports: category, type, tag, path, external, importsFile, importedBy, minImports, maxImports, minSize, maxSize, hasDocstring, minCoverage, maxCoverage, minExportUsage, maxExportUsage, minComplexity, maxComplexity, minCognitiveComplexity, maxCognitiveComplexity, minCommits, maxCommits, isDocumented, isStale, lastAuthor. OR logic: any(key:val|key:val) matches if any single-key clause holds, ANDed with the rest of the query. sort: size|imports|commitCount90d|exportUsage|complexity|cognitiveComplexity, with sortDir: asc|desc (default desc). limit: N."},mermaid:{type:"boolean",description:"Return a Mermaid diagram (default: false)"},slim:{type:"boolean",description:"Compact response mode (default: true). Returns export names, meaningful tags, and a flat importsFiles path list \u2014 no edge objects, no mtime/size. Tags are filtered to kinds comment-marker and import only; function/class/variable/type/library tags are dropped in slim output. Use list_tags to see the full tag inventory, or pass slim: false to get every tag kind on matching nodes."}},required:["root","filter"]}},{name:"get_workspace_packages",description:"List all workspace packages detected in a monorepo, with their node counts and inter-package dependencies. Requires a prior analyze() call with empty entryPoints on a monorepo root.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the monorepo root"}},required:["root"]}},{name:"get_workspace_affected",description:"Cross-package blast-radius analysis. Returns every file that could be affected if a given file changes, annotated with the package it belongs to. Requires a prior analyze() call with empty entryPoints on a monorepo root.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the monorepo root"},file:{type:"string",description:"Monorepo-root-relative path of the changed file (e.g. 'packages/shared/src/utils.ts')"}},required:["root","file"]}},{name:"get_type_graph",description:"Return type-level relationships for the project. Without a type name, returns an inventory of all interfaces, classes, enums, and type aliases with their file and kind. With a type name, returns which files import that type (usedByFiles) and which types the defining file imports (uses). Requires a prior analyze() call. Only covers TypeScript/JavaScript files.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},type:{type:"string",description:"Exact exported name of the type to look up (e.g. 'FileNode'). Omit to get the full type inventory."}},required:["root"]}},{name:"get_module_responsibility",description:"Return what each file is responsible for: its semantic role, JSDoc description (when present), exported symbol names, and which feature hub it belongs to. Pass specific paths to filter, or omit paths to get all files. Requires a prior analyze() call.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},paths:{type:"array",items:{type:"string"},description:"Project-relative file paths to include. Omit to return all files."},minOutDegree:{type:"number",description:"Min imports for a file to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"get_feature_graph",description:"Group files by domain: returns which files each feature hub (high-import orchestrator) transitively owns. Each file is assigned to the most specific hub that can reach it (lowest out-degree wins). Use this instead of a full query when answering 'what files are in the X feature/module?' \u2014 it returns only paths grouped by hub, so it's substantially smaller than a full graph query for the same question; compare output sizes yourself if you need an exact figure for your repo.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},minOutDegree:{type:"number",description:"Minimum internal imports a file must have to qualify as a feature hub (default: 5)."}},required:["root"]}},{name:"get_call_graph",description:"Look up callers and callees for a named function. Returns the file that defines the function, all files/functions that call it, and all files/functions it calls. Always requires a function name \u2014 never returns the full call graph unfiltered. Call edges are only populated for TypeScript/JavaScript files.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},function:{type:"string",description:"Exact name of the function to look up (e.g. 'parseFile')."}},required:["root","function"]}},{name:"find_symbol",description:"Find every file that exports a symbol by exact name, with the best available usage info per match. Precision varies by the defining file's language \u2014 check each match's `precision` field ('call' | 'file-level') before trusting caller/importer results as symbol-exact. See docs/mcp.md for per-language coverage details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},name:{type:"string",description:"Exact export name to look up (e.g. 'parseFile')."}},required:["root","name"]}},{name:"get_api_surface",description:"Build the API surface report for a project: every exported symbol resolved to its defining file and kind, partitioned into internalFiles, unreachableFromEntry, and testFiles. Requires a prior analyze() call. When entryPoints is omitted, auto-detects from package.json exports/main/module. See docs/mcp.md for the export* expansion and partition semantics.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root"},entryPoints:{type:"array",items:{type:"string"},description:"Project-relative paths of public entry points (e.g. ['src/index.ts', 'src/utils.ts']). Omit to auto-detect from package.json exports / main / module fields."}},required:["root"]}},{name:"clear_cache",description:"Drop the cached dependency graph and loaded mokosh.config.json for a project root, forcing the next analyze() call to rebuild from disk and re-read config. Call this after editing source files OR mokosh.config.json mid-session \u2014 otherwise get_affected, get_dependencies, and other query tools will reason from stale data (or a stale config).",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root to invalidate."}},required:["root"]}},{name:"apply_tags",description:"Write @tag annotations into test file source code based on the dependency graph, as an idempotent block \u2014 re-running is safe, the existing block is replaced in place. Use dryRun=true to preview changes without writing to disk. Requires a prior analyze() call. See docs/mcp.md for tag-kind and per-language block syntax details.",inputSchema:{type:"object",properties:{root:{type:"string",description:"Absolute path to the project root."},dryRun:{type:"boolean",description:"When true, computes which files would change but does not write to disk (default: false)."}},required:["root"]}}];function Ct(){let t=new bt,e=new Gi.Server({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(kt.ListToolsRequestSchema,async()=>({tools:Li})),e.setRequestHandler(kt.CallToolRequestSchema,async r=>{let{name:n,arguments:s}=r.params,i=s,a={analyze:c=>pi(t,c),get_dependencies:c=>ui(t,c),get_dependents:c=>fi(t,c),get_affected:c=>mi(t,c),get_callers:c=>gi(t,c),find_symbol:c=>Di(t,c),find_unused:c=>di(t,c),find_uncovered:c=>yi(t,c),list_tags:c=>hi(t,c),check_doc_drift:c=>xi(t,c),find_complex_functions:c=>bi(t,c),find_risk_hotspots:c=>Si(t,c),find_duplicates:c=>ki(t,c),propose_tags:c=>Ci(t,c),detect_features:c=>vi(t,c),get_type_graph:c=>Ai(t,c),get_module_responsibility:c=>Pi(t,c),get_feature_graph:c=>Ni(t,c),get_call_graph:c=>Ii(t,c),get_api_surface:c=>Mi(t,c),query:c=>wi(t,c),get_workspace_packages:c=>Fi(t,c),get_workspace_affected:c=>Ti(t,c),clear_cache:c=>Ei(t,c),apply_tags:c=>Ri(t,c)}[n];if(!a)throw new Error(`Unknown tool: ${n}`);try{return li(i.root),await a(i)}catch(c){return{content:[{type:"text",text:`Error: ${c instanceof Error?c.message:String(c)}`}],isError:!0}}}),e}async function Rl(){let t=Ct(),e=new _i.StdioServerTransport;await t.connect(e)}Rl().catch(console.error);0&&(module.exports={createMcpServer});
41
41
  //# sourceMappingURL=mcp.js.map