@omfalos/mokosh 0.3.3 → 0.4.1

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,36 +1,37 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var wo=Object.create;var Ie=Object.defineProperty;var Co=Object.getOwnPropertyDescriptor;var Fo=Object.getOwnPropertyNames;var Eo=Object.getPrototypeOf,To=Object.prototype.hasOwnProperty;var Po=(t,e)=>{for(var r in e)Ie(t,r,{get:e[r],enumerable:!0})},Rr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Fo(e))!To.call(t,s)&&s!==r&&Ie(t,s,{get:()=>e[s],enumerable:!(n=Co(e,s))||n.enumerable});return t};var d=(t,e,r)=>(r=t!=null?wo(Eo(t)):{},Rr(e||!t||!t.__esModule?Ie(r,"default",{value:t,enumerable:!0}):r,t)),Ao=t=>Rr(Ie({},"__esModule",{value:!0}),t);var il={};Po(il,{createMcpServer:()=>mt});module.exports=Ao(il);var bo=require("@modelcontextprotocol/sdk/server/stdio.js");var So=require("@modelcontextprotocol/sdk/server/index.js"),ft=require("@modelcontextprotocol/sdk/types.js");var $s=d(require("fs"));var Ge=d(require("fs")),St=d(require("path"));var No=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Gr=[];function Me(t){Gr.push(t)}function Lr(t){return[...No,...Gr].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Io=[".test.",".spec.","-test.","-spec."],_r=[];function De(t){_r.push(t)}function ae(){return[...Io,..._r]}var Mo=["jest","vitest","playwright","cypress","@testing-library/"],Or=[];function Re(t){Or.push(t)}function ht(){return[...Mo,...Or]}var jr=.8;function yt(t){jr=t}function xt(){return jr}var Do=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function ce(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=St.default.resolve(t);return Ge.default.existsSync(n)?n.endsWith(".json")?Wr(n):e?zr(n):{}:{}}for(let n of Do){let s=St.default.resolve(t,n);if(Ge.default.existsSync(s)){if(n.endsWith(".json"))return Wr(s);if(e)return zr(s)}}return{}}function Wr(t){return JSON.parse(Ge.default.readFileSync(t,"utf-8"))}function zr(t){let e=require(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function bt(t){for(let e of t.configMatchers??[])Me(e);for(let e of t.testPatterns??[])De(e);for(let e of t.testLibraries??[])Re(e);t.barrelThreshold!==void 0&&yt(t.barrelThreshold)}function Y(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var j=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],kt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];var Br=d(require("fs")),vt=d(require("path"));function wt(t,e){let r=vt.default.resolve(t,e);try{let n=Br.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=vt.default.relative(t,i);o.set(l,c)}return o}catch{return new Map}}var Le={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 Ct=d(require("fs")),$r=d(require("path"));function Ft(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 Ur(t,e){if(typeof t=="string")return Ft(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=Ur(r[n],e);if(s)return s}}return null}function Go(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 Lo(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 Et(t,e){let r=[],n=$r.default.join(e,"package.json");if(Ct.default.existsSync(n))try{let s=JSON.parse(Ct.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=Ur(o,t);i&&!r.includes(i)&&r.push(i)}else if(typeof s.exports=="string"){let o=Ft(s.exports,t);o&&r.push(o)}if(r.length===0)for(let o of[s.main,s.module].filter(Boolean)){let i=Ft(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 _o(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 Oo(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 jo(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(g=>g.name===o))??n[0],p={name:o,definedIn:l,kind:Go(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 Wo(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 Tt(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=_o(t,e),n=Oo(t,r,e),s=Lo(t,e),o=jo(s,n,t,e),{internalFiles:i,unreachableFromEntry:a,testFiles:c}=Wo(t,r,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:c}}function Pt(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 zo=d(require("fs")),Bo=d(require("path"));function Kr(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 At(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:Kr(t)}}function Nt(t,e){return t.impact.get(e)??[]}var an=require("fs/promises"),pe=d(require("path")),cn=d(require("piscina"));var le=d(require("fs")),Jr=d(require("path")),It=require("js-yaml"),Mt=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function Vr(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function $o(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)),Vr(r)}).filter(Boolean)}function Uo(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 Ko(t){try{let e=(0,It.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=Vr(o);i&&(r.dependencies[i]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function Jo(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=$o(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 Vo(t){let e=le.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 Ho(t){let e=le.default.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=Ko(e);if(r!==null)return r}return Jo(e)}function Qo(t){let e=le.default.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=(0,It.load)(e);if(n.packages)for(let[s,o]of Object.entries(n.packages)){let{name:i,version:a}=Uo(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 Hr(t){let e={"package-lock.json":Vo,"yarn.lock":Ho,"pnpm-lock.yaml":Qo},r=Mt.map(n=>[n,e[n]]);for(let[n,s]of r){let o=Jr.default.join(t,n);if(le.default.existsSync(o))return s(o)}return null}var qo=new Set(["css","scss","less","stylus"]);function Qr(t){return qo.has(t)?"style":"code"}function Yo(t){let e=5381;for(let r=0;r<t.length;r++)e=e*33+t.charCodeAt(r)>>>0;return e.toString(36)}function Xo(t,e){let r=[];for(let n=0;n<=t.length-e;n++)r.push(Yo(t.slice(n,n+e).map(s=>s.text).join(" ")));return r}function Zo(t,e,r){let n=t.get(e.file),s=t.get(r.file);if(!n||!s)return 0;let o=0;for(;e.windowIndex+o+1<n.length&&r.windowIndex+o+1<s.length&&n[e.windowIndex+o+1]===s[r.windowIndex+o+1];)o++;return o}function ei(t,e,r){if(e.windowIndex===0||r.windowIndex===0)return!0;let n=t.get(e.file),s=t.get(r.file);return!n||!s?!0:n[e.windowIndex-1]!==s[r.windowIndex-1]}var Dt=class{parent=new Map;find(e){this.parent.has(e)||this.parent.set(e,e);let r=e;for(;this.parent.get(r)!==r;)r=this.parent.get(r);let n=e;for(;n!==r;){let s=this.parent.get(n);this.parent.set(n,r),n=s}return r}union(e,r){let n=this.find(e),s=this.find(r);n!==s&&this.parent.set(n,s)}root(e){return this.find(e)}};function _e(t){return`${t.file}#${t.startLine}#${t.endLine}`}var ti=new Set(["{","}",":",",","[","]"]);function ri(t,e,r){let n=0;for(let s=e;s<e+r;s++)ti.has(t[s].text)&&n++;return n/r}var ni=400;function qr(t,e,r,n=.5,s=ni){let o=new Map,i=new Map,a=new Map;for(let{file:S,tokens:y}of t){if(y.length<e)continue;i.set(S,y);let b=Xo(y,e);o.set(S,b);for(let x=0;x<b.length;x++){let k={file:S,windowIndex:x},P=a.get(b[x]);P?P.push(k):a.set(b[x],[k])}}let c=[],l=0;for(let S of a.values())if(!(S.length<2)){if(S.length>s){l++;continue}for(let y=0;y<S.length;y++)for(let b=y+1;b<S.length;b++){let x=S[y],k=S[b];if(x.file===k.file&&x.windowIndex===k.windowIndex||!ei(o,x,k))continue;let P=Zo(o,x,k),N=e+P,q=i.get(x.file);if(ri(q,x.windowIndex,N)>n)continue;if(x.file===k.file){let[ko,vo]=x.windowIndex<k.windowIndex?[x,k]:[k,x];if(ko.windowIndex+N>vo.windowIndex)continue}let ie=i.get(k.file),gt={file:x.file,startLine:q[x.windowIndex].line,endLine:q[x.windowIndex+N-1].line},dt={file:k.file,startLine:ie[k.windowIndex].line,endLine:ie[k.windowIndex+N-1].line},Dr=Math.min(gt.endLine-gt.startLine+1,dt.endLine-dt.startLine+1);Dr<r||c.push({occA:gt,occB:dt,lines:Dr,tokens:N})}}let p=new Dt,f=new Map;for(let{occA:S,occB:y}of c){let b=_e(S),x=_e(y);f.set(b,S),f.set(x,y),p.union(b,x)}let g=new Map;for(let S of f.keys()){let y=p.root(S),b=g.get(y);b?b.add(S):g.set(y,new Set([S]))}let h=[];for(let S of g.values()){if(S.size<2)continue;let y=[...S].map(k=>f.get(k)),b=0,x=e;for(let k of c)!S.has(_e(k.occA))||!S.has(_e(k.occB))||k.lines>b&&(b=k.lines,x=k.tokens);h.push({occurrences:y,lines:b,tokens:x})}return{groups:h.sort((S,y)=>y.lines-S.lines),skippedBuckets:l}}var Rt=d(require("postcss")),si=d(require("postcss-less")),oi=si,Xr=new Set(["reference","inline"]);function Yr(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function ii(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function ai(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let o=r[1]?.trim()??"",i=r[2]??"";if(!i)return null;let a=Xr.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...Yr(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",...Yr(s)?{isExternal:!0}:{}}:null}function ci(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let o=s[1]?.trim()??"";ii(o)&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function Zr(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=ai(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...ci(n.value,e))}),r}function li(t){return t.replace(/(?<!:)\/\/.*/g,"")}function pi(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=Xr.has(o)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}s=n.exec(t)}return r}function Oe(t,e){let r=Rt.default.parse(li(t));return{imports:Zr(r,e),root:r}}function ui(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 je(t,e){try{let r=oi.parse(t),{exports:n,tags:s}=ui(r);return{imports:Zr(r,e),root:r,exports:n,tags:s}}catch{return{imports:pi(t,e),root:Rt.default.parse(""),exports:[],tags:[]}}}var tn=require("postcss-scss");function en(t){return t.startsWith("_")||t.startsWith("-")}function fi(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function mi(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 gi(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||en(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||en(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 We(t,e){let r=(0,tn.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}=mi(c);if(!l)return;let f={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...fi(l)?{isExternal:!0}:{}};p&&(f.symbols=[p]),n.push(f)});let{exports:s,tags:o}=gi(r);return{imports:n,root:r,exports:s,tags:o}}function di(t){return t.trim().replace(/\s+/g," ")}function hi(t){try{return t.fileType==="scss"?We(t.source,t.file).root:t.fileType==="less"?je(t.source,t.file).root:t.fileType==="css"?Oe(t.source,t.file).root:void 0}catch{return}}function yi(t){let e=hi(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()}:${di(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function rn(t,e,r=2){let n=new Map;for(let o of t)for(let i of yi(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)}var xi={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 nn(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function Si(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=nn(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=nn(r,o,a),s=a}}return r}var bi=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],Gt=new RegExp(`${bi.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),ki=/^[A-Za-z_$][A-Za-z0-9_$]*$/,sn=/^\d+(?:\.\d+)?$/,vi=/^(".*"|'.*'|`.*`)$/s,wi=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 on(t,e,r=!0){let n=Si(t,xi[e]),s=[],o=1,i=0;Gt.lastIndex=0;let a=Gt.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;ki.test(c)&&!wi.has(c)?l="ID":r&&(sn.test(c)||vi.test(c))&&(l=sn.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=Gt.exec(n)}return s}var Ci=20,Fi=new Set(["css","scss","less"]);function Ei(t){return Mt.includes(pe.default.basename(t))}function Ti(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(pe.default.sep).some(n=>r.has(n))}async function Lt(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:o=!0,maxPunctuationRatio:i=.5,maxBucketSize:a,limit:c=50,ignoreDirs:l=j,parallelTokenizing:p=!0}=r,f=[...t.nodes.values()].filter(h=>!Ei(h.path)&&!Ti(h.path,l)),g=Pi(p,f.length);try{let h=[],S=new Map;await Promise.all(f.map(async x=>{let k;try{k=await(0,an.readFile)(pe.default.join(e,x.path),"utf8")}catch{return}if(Fi.has(x.type)){h.push({file:x.path,source:k,fileType:x.type});return}let P=Qr(x.type),N=g?await g.run({source:k,fileType:x.type,ignoreLiterals:o}):on(k,x.type,o),q={file:x.path,tokens:N},ie=S.get(P);ie?ie.push(q):S.set(P,[q])}));let y=rn(h,n),b=0;for(let[x,k]of S){let P=qr(k,s,n,i,a);b+=P.skippedBuckets;for(let N of P.groups)y.push({...N,family:x})}return{groups:y.sort((x,k)=>k.lines-x.lines).slice(0,c),skippedBuckets:b}}finally{g&&await g.destroy()}}function Pi(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??Ci;if(e<n)return null;try{return new cn.default({filename:pe.default.join(__dirname,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:r.maxThreads}:{}})}catch(s){return process.stderr.write(`
2
+ "use strict";var Fo=Object.create;var Ie=Object.defineProperty;var To=Object.getOwnPropertyDescriptor;var Eo=Object.getOwnPropertyNames;var Ao=Object.getPrototypeOf,Po=Object.prototype.hasOwnProperty;var No=(t,e)=>{for(var r in e)Ie(t,r,{get:e[r],enumerable:!0})},Gr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Eo(e))!Po.call(t,s)&&s!==r&&Ie(t,s,{get:()=>e[s],enumerable:!(n=To(e,s))||n.enumerable});return t};var d=(t,e,r)=>(r=t!=null?Fo(Ao(t)):{},Gr(e||!t||!t.__esModule?Ie(r,"default",{value:t,enumerable:!0}):r,t)),Io=t=>Gr(Ie({},"__esModule",{value:!0}),t);var ul={};No(ul,{createMcpServer:()=>gt});module.exports=Io(ul);var wo=require("@modelcontextprotocol/sdk/server/stdio.js");var Co=require("@modelcontextprotocol/sdk/server/index.js"),mt=require("@modelcontextprotocol/sdk/types.js");var Js=d(require("fs")),Hs=d(require("path"));var Le=d(require("fs")),xt=d(require("path"));var Do=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],_r=[];function De(t){_r.push(t)}function Or(t){return[...Do,..._r].some(e=>typeof e=="string"?t.includes(e):e instanceof RegExp?e.test(t):e(t))}var Mo=[".test.",".spec.","-test.","-spec."],jr=[];function Me(t){jr.push(t)}function ce(){return[...Mo,...jr]}var Ro=["jest","vitest","playwright","cypress","@testing-library/"],zr=[];function Re(t){zr.push(t)}function dt(){return[...Ro,...zr]}var Wr=.8;function ht(t){Wr=t}function yt(){return Wr}var Lo=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function le(t,{allowJs:e=!0,isExplicitPath:r=!1}={}){if(r){let n=xt.default.resolve(t);return Le.default.existsSync(n)?n.endsWith(".json")?$r(n):e?Br(n):{}:{}}for(let n of Lo){let s=xt.default.resolve(t,n);if(Le.default.existsSync(s)){if(n.endsWith(".json"))return $r(s);if(e)return Br(s)}}return{}}function $r(t){return JSON.parse(Le.default.readFileSync(t,"utf-8"))}function Br(t){let e=require(t);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function bt(t){for(let e of t.configMatchers??[])De(e);for(let e of t.testPatterns??[])Me(e);for(let e of t.testLibraries??[])Re(e);t.barrelThreshold!==void 0&&ht(t.barrelThreshold)}function Y(t){return{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing,pathAliases:t?.pathAliases}}var St="mokosh-cache",kt="duplication-tokens.json",j=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],vt=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];var Ur=d(require("fs")),Ct=d(require("path"));function wt(t,e){let r=Ct.default.resolve(t,e);try{let n=Ur.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=Ct.default.relative(t,i);o.set(l,c)}return o}catch{return new Map}}var Ge={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 Ft=d(require("fs")),Kr=d(require("path"));function Tt(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 Jr(t,e){if(typeof t=="string")return Tt(t,e);if(t&&typeof t=="object"){let r=t;for(let n of["import","require","default"]){let s=Jr(r[n],e);if(s)return s}}return null}function _o(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 Oo(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 Et(t,e){let r=[],n=Kr.default.join(e,"package.json");if(Ft.default.existsSync(n))try{let s=JSON.parse(Ft.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=Jr(o,t);i&&!r.includes(i)&&r.push(i)}else if(typeof s.exports=="string"){let o=Tt(s.exports,t);o&&r.push(o)}if(r.length===0)for(let o of[s.main,s.module].filter(Boolean)){let i=Tt(o,t);i&&!r.includes(i)&&r.push(i)}}catch{}if(r.length===0){for(let s of["src/index.ts","src/index.js","index.ts","index.js"])if(t.nodes.has(s)){r.push(s);break}}return r}function jo(t,e){let r=new Set(e);for(let n of e)t.traverse(n,s=>(r.add(s.path),!0),{direction:"outgoing"});return r}function zo(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 Wo(t,e,r,n){let s=[];for(let o of t){let i=e.get(o),a=n.flatMap(u=>r.nodes.get(u)?.exports??[]).find(u=>u.name===o),c=i?.symbol??a,l=i?.file??n.find(u=>r.nodes.get(u)?.exports.some(g=>g.name===o))??n[0],p={name:o,definedIn:l,kind:_o(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 $o(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 At(t,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let l of e)if(!t.nodes.has(l))throw new Error(`Entry point not found in graph: ${l}`);let r=jo(t,e),n=zo(t,r,e),s=Oo(t,e),o=Wo(s,n,t,e),{internalFiles:i,unreachableFromEntry:a,testFiles:c}=$o(t,r,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:c}}function Pt(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 Bo=d(require("fs")),Uo=d(require("path"));function Hr(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 Nt(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:Hr(t)}}function It(t,e){return t.impact.get(e)??[]}var Gt=require("fs/promises"),Z=d(require("path")),gn=d(require("piscina"));var pe=d(require("fs")),Vr=d(require("path")),Dt=require("js-yaml"),Mt=["package-lock.json","yarn.lock","pnpm-lock.yaml"];function Qr(t){let e=t.lastIndexOf("@");return e>0?t.substring(0,e):t}function Ko(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)),Qr(r)}).filter(Boolean)}function Jo(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 Ho(t){try{let e=(0,Dt.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=Qr(o);i&&(r.dependencies[i]={version:s.version,...s.dependencies!==void 0&&{dependencies:s.dependencies}})}return r}catch{return null}}function Vo(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=Ko(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 Qo(t){let e=pe.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 qo(t){let e=pe.default.readFileSync(t,"utf-8");if(e.includes("__metadata:")){let r=Ho(e);if(r!==null)return r}return Vo(e)}function Yo(t){let e=pe.default.readFileSync(t,"utf-8"),r={dependencies:{}};try{let n=(0,Dt.load)(e);if(n.packages)for(let[s,o]of Object.entries(n.packages)){let{name:i,version:a}=Jo(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 qr(t){let e={"package-lock.json":Qo,"yarn.lock":qo,"pnpm-lock.yaml":Yo},r=Mt.map(n=>[n,e[n]]);for(let[n,s]of r){let o=Vr.default.join(t,n);if(pe.default.existsSync(o))return s(o)}return null}var Xo=new Set(["css","scss","less","stylus"]);function Yr(t){return Xo.has(t)?"style":"code"}var Rt=d(require("postcss")),Zo=d(require("postcss-less")),ei=Zo,Zr=new Set(["reference","inline"]);function Xr(t){return t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||t.startsWith("data:")}function ti(t){let e=t.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function ri(t,e){let r=t.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(r){let o=r[1]?.trim()??"",i=r[2]??"";if(!i)return null;let a=Zr.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...Xr(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",...Xr(s)?{isExternal:!0}:{}}:null}function ni(t,e){let r=[],n=/url\(['"]?([^'")]+)['"]?\)/g,s=n.exec(t);for(;s!==null;){let o=s[1]?.trim()??"";ti(o)&&r.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),s=n.exec(t)}return r}function en(t,e){let r=[];return t.walk(n=>{if(n.type==="atrule"&&n.name==="import"){let s=ri(n.params,e);s&&r.push(s)}n.type==="decl"&&r.push(...ni(n.value,e))}),r}function si(t){return t.replace(/(?<!:)\/\/.*/g,"")}function oi(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=Zr.has(o)?"side-effect":"static";r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}s=n.exec(t)}return r}function _e(t,e){let r=Rt.default.parse(si(t));return{imports:en(r,e),root:r}}function ii(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 Oe(t,e){try{let r=ei.parse(t),{exports:n,tags:s}=ii(r);return{imports:en(r,e),root:r,exports:n,tags:s}}catch{return{imports:oi(t,e),root:Rt.default.parse(""),exports:[],tags:[]}}}var rn=require("postcss-scss");function tn(t){return t.startsWith("_")||t.startsWith("-")}function ai(t){return!!(t.startsWith("sass:")||t.startsWith("~")||t.startsWith("http://")||t.startsWith("https://")||t.startsWith("//")||!t.startsWith(".")&&!t.startsWith("/")&&!t.startsWith("_"))}function ci(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 li(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||tn(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||tn(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 je(t,e){let r=(0,rn.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}=ci(c);if(!l)return;let u={fromPath:e,toPath:"",rawSpecifier:l,isStyle:!0,type:a==="forward"?"re-export":"static",...ai(l)?{isExternal:!0}:{}};p&&(u.symbols=[p]),n.push(u)});let{exports:s,tags:o}=li(r);return{imports:n,root:r,exports:s,tags:o}}function pi(t){return t.trim().replace(/\s+/g," ")}function ui(t){try{return t.fileType==="scss"?je(t.source,t.file).root:t.fileType==="less"?Oe(t.source,t.file).root:t.fileType==="css"?_e(t.source,t.file).root:void 0}catch{return}}function fi(t){let e=ui(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()}:${pi(p.value)}`).join(";");r.push({file:t.file,startLine:a,endLine:c,lines:c-a+1,signature:l,declCount:s.length})}),r}function nn(t,e,r=2){let n=new Map;for(let o of t)for(let i of fi(o)){if(i.declCount<r||i.lines<e)continue;let a=n.get(i.signature);a?a.push(i):n.set(i.signature,[i])}let s=[];for(let o of n.values())for(let i=0;i<o.length;i++)for(let a=i+1;a<o.length;a++){let c=o[i],l=o[a];if(c.file===l.file&&c.startLine===l.startLine&&c.endLine===l.endLine)continue;let p={file:c.file,startLine:c.startLine,endLine:c.endLine},u={file:l.file,startLine:l.startLine,endLine:l.endLine};s.push({occurrences:[p,u],lines:Math.min(c.lines,l.lines),tokens:c.declCount,family:"style"})}return s.sort((o,i)=>i.lines-o.lines)}function sn(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 mi=new Set(["{","}",":",",","[","]"]);function on(t,e,r){let n=0;for(let s=e;s<e+r;s++)mi.has(t[s].text)&&n++;return n/r}function an(t){let e=t.length;if(e===0)return[];let r=Array.from({length:e},(o,i)=>i),n=new Array(e);{let o=[...new Set(t)].sort(),i=new Map(o.map((a,c)=>[a,c]));for(let a=0;a<e;a++)n[a]=i.get(t[a])}let s=new Array(e).fill(0);for(let o=1;o<e;o*=2){let i=a=>a+o<e?n[a+o]:-1;r.sort((a,c)=>{let l=n[a]-n[c];return l!==0?l:i(a)-i(c)}),s[r[0]]=0;for(let a=1;a<e;a++){let c=r[a-1],l=r[a],p=n[c]===n[l],u=i(c)===i(l);s[l]=s[c]+(p&&u?0:1)}if([n,s]=[s,n],n[r[e-1]]===e-1)break}return r}function cn(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 ln(t,e,r,n=.5){let s=[],o=[],i=new Map;for(let{file:u,tokens:g}of t)if(g.length!==0){i.set(u,g);for(let h=0;h<g.length;h++)s.push(g[h].text),o.push({file:u,localIndex:h});s.push(` ${u}`),o.push({file:u,localIndex:-1})}if(s.length===0)return[];let a=an(s),c=cn(s,a),l=sn(c),p=[];for(let u of l){let g=gi(u,a,o,i,e,r,n);g&&p.push(g)}return p.sort((u,g)=>g.lines-u.lines)}function gi(t,e,r,n,s,o,i){if(t.lcpLength<s)return;let a=[];for(let h=t.low;h<=t.high;h++){let k=r[e[h]];k.localIndex!==-1&&a.push(k)}if(a.length<2||!di(a,n))return;let c=hi(a,t.lcpLength);if(c.length<2)return;let l=c[0],p=n.get(l.file);if(on(p,l.localIndex,t.lcpLength)>i)return;let u=c.map(({file:h,localIndex:k})=>{let x=n.get(h);return{file:h,startLine:x[k].line,endLine:x[k+t.lcpLength-1].line}}),g=Math.min(...u.map(h=>h.endLine-h.startLine+1));if(!(g<o))return{occurrences:u,lines:g,tokens:t.lcpLength}}function di(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 hi(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 yi={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 pn(t,e,r){let n=t.slice(e,r).replace(/[^\n]/g," ");return t.slice(0,e)+n+t.slice(r)}function xi(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=pn(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=pn(r,o,a),s=a}}return r}var bi=["===","!==","...","=>","==","!=","<=",">=","&&","||","::","->","..","+=","-=","*=","/="],Lt=new RegExp(`${bi.map(t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")}|[A-Za-z_$][A-Za-z0-9_$]*|\\d+(?:\\.\\d+)?|"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|\`(?:\\\\.|[^\`\\\\])*\`|\\S`,"g"),Si=/^[A-Za-z_$][A-Za-z0-9_$]*$/,un=/^\d+(?:\.\d+)?$/,ki=/^(".*"|'.*'|`.*`)$/s,vi=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 fn(t,e,r=!0){let n=xi(t,yi[e]),s=[],o=1,i=0;Lt.lastIndex=0;let a=Lt.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;Si.test(c)&&!vi.has(c)?l="ID":r&&(un.test(c)||ki.test(c))&&(l=un.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=Lt.exec(n)}return s}var X=d(require("fs")),mn=d(require("path"));function Ci(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 ze(t){try{if(!X.default.existsSync(t))return new Map;let e=X.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"&&Ci(s[1]));return new Map(n)}catch{return new Map}}function We(t,e){let r=mn.default.dirname(e);X.default.existsSync(r)||X.default.mkdirSync(r,{recursive:!0}),X.default.writeFileSync(e,JSON.stringify([...t.entries()]))}var wi=20,Fi=new Set(["css","scss","less"]);function Ti(t){return Mt.includes(Z.default.basename(t))}function Ei(t,e){if(e.length===0)return!1;let r=new Set(e);return t.split(Z.default.sep).some(n=>r.has(n))}async function _t(t,e,r={}){let{minLines:n=6,windowSize:s=15,ignoreLiterals:o=!0,maxPunctuationRatio:i=.5,limit:a=50,ignoreDirs:c=j,parallelTokenizing:l=!0,tokenCache:p}=r,u=[...t.nodes.values()].filter(h=>!Ti(h.path)&&!Ei(h.path,c)),g=Ai(l,u.length);try{let h=[],k=new Map;if(await Promise.all(u.map(async y=>{if(Fi.has(y.type)){let q;try{q=await(0,Gt.readFile)(Z.default.join(e,y.path),"utf8")}catch{return}h.push({file:y.path,source:q,fileType:y.type});return}let C=p?.get(y.path),I=C&&C.mtime===y.mtime&&C.size===y.size&&C.ignoreLiterals===o,N;if(I)N=C.tokens;else{let q;try{q=await(0,Gt.readFile)(Z.default.join(e,y.path),"utf8")}catch{return}N=g?await g.run({source:q,fileType:y.type,ignoreLiterals:o}):fn(q,y.type,o),p?.set(y.path,{mtime:y.mtime,size:y.size,ignoreLiterals:o,tokens:N})}let O=Yr(y.type),Rr={file:y.path,tokens:N},Lr=k.get(O);Lr?Lr.push(Rr):k.set(O,[Rr])})),p){let y=new Set(u.map(C=>C.path));for(let C of p.keys())y.has(C)||p.delete(C)}let x=nn(h,n);for(let[y,C]of k)for(let I of ln(C,s,n,i))x.push({...I,family:y});return{groups:x.sort((y,C)=>C.lines-y.lines).slice(0,a)}}finally{g&&await g.destroy()}}function Ai(t,e){if(t===!1)return null;let r=typeof t=="object"?t:{},n=r.minFiles??wi;if(e<n)return null;try{return new gn.default({filename:Z.default.join(__dirname,"duplication-worker.js"),...r.maxThreads!==void 0?{maxThreads:r.maxThreads}:{}})}catch(s){return process.stderr.write(`
8
8
  Warning: failed to start duplicate-detection worker pool, falling back to synchronous tokenizing: ${s}
9
- `),null}}var ue=d(require("path"));function Ai(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 Ni(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=ue.default.extname(s),c=ue.default.basename(s,a),l=c==="index"?ue.default.basename(ue.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 Ni(t,Ai(t),r)}var Ii=(t,e)=>t.outDegree-e.outDegree;function Mi(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 Di(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 Ri(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 Gi(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function fe(t,e){let r=e?.detectFn??W,n=e?.hubComparator??Ii,s=r(t.nodes,e),o=Mi(t,s),i=Di(t.nodes,s,o,n);return{features:Ri(s,i),unassigned:Gi(t.nodes,s,i)}}var ln=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),pn=new Set(["typescript","javascript","python"]),ze=new Set(["typescript","javascript","go","python"]);function _t(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:ln.has(r),importSymbolsTracked:pn.has(r),callEdgesTracked:ze.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var me=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 R=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 g of s(c))a(g,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.imports.map(a=>a.toPath).filter(Boolean)??[]:o?.get(i)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.callEdges??[]){let s=e.get(n.toFile)??[];s.push(r.path),e.set(n.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.callEdges?.map(a=>a.toFile)??[]:o?.get(i)??[])}getCallers(e){let r=[];return this.traverseCalls(e,n=>(n.path!==e&&r.push(n.path),!0),{direction:"incoming",maxDepth:1}),r}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let r=this.nodes.get(e);return r?r.imports.map(n=>this.nodes.get(n.toPath)).filter(n=>n!==void 0):[]}findUnusedFiles(e){return new me(this.nodes).findUnusedFiles(e)}findCycles(){return new me(this.nodes).findCycles()}};var z=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 ge(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function Ot(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 de(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 z(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 Wt(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 zt(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 Bt(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 $t(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 Ut(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function un(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 C(e,"component")||C(e,"components")?"component":C(e,"controller")||C(e,"controllers")?"controller":C(e,"middleware")?"middleware":C(e,"router")||C(e,"routes")||C(e,"route")?"router":C(e,"store")||C(e,"stores")?"store":C(e,"service")||C(e,"services")?"service":C(e,"handler")||C(e,"handlers")?"handler":C(e,"adapter")||C(e,"adapters")?"adapter":C(e,"plugin")||C(e,"plugins")?"plugin":C(e,"api")?"api":C(e,"cli")||C(e,"commands")||he(e)==="cli"?"cli":C(e,"util")||C(e,"utils")||C(e,"helper")||C(e,"helpers")?"util":C(e,"model")||C(e,"models")||he(e)==="model"?"model":C(e,"parser")||C(e,"parsers")||he(e)==="parser"?"parser":he(e)==="builder"?"builder":he(e)==="resolver"?"resolver":"other"}function C(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function he(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function Kt(t,e){let r=fe(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:un(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return s}function Jt(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if(ze.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=de(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 Li(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function _i(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function Vt(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(!_i(s,n.category))continue;let o=`${n.path}::${s.name}`;e.set(o,{name:s.name,file:n.path,kind:Li(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 Ht(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 En=d(require("path"));var $e=d(require("fs")),Yt=d(require("path"));var X=d(require("fs")),I=d(require("path"));var Qt=d(require("fs")),Oi=d(require("path"));function fn(t){try{return Qt.default.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Be(t){try{return Qt.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function qt(t,e){let r=I.default.join(e,"package.json");if(!X.default.existsSync(r))return null;let n={};try{n=JSON.parse(X.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name;return s?{name:s,root:e,relativeRoot:I.default.relative(t,e),entryPoints:ji(e,n)}:null}function ji(t,e){let r=[];if(e.exports){let s=e.exports;if(typeof s=="string")r.push(I.default.join(t,s));else if(typeof s=="object"&&s!==null){let o=s["."];if(typeof o=="string")r.push(I.default.join(t,o));else if(typeof o=="object"&&o!==null){let i=o.import??o.require??o.default;typeof i=="string"&&r.push(I.default.join(t,i))}}}e.main&&r.push(I.default.join(t,e.main));for(let s of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])r.push(I.default.join(t,s));let n=r.filter(Be);return n.length>0?n.slice(0,1):r.slice(0,1)}function Z(t,e){let r=[],n=new Set;for(let s of e){let o=s.replace(/\/$/,"").replace(/^\.\//,"");Wi(t,o,n,r)}return r}function Wi(t,e,r,n){if(!e.includes("*")){zi(t,e,r,n);return}let s=e.split("/");s.includes("**")?Bi(t,s,r,n):$i(t,s,r,n)}function zi(t,e,r,n){let s=I.default.join(t,e);if(r.has(s)||!fn(s))return;r.add(s);let o=qt(t,s);o&&n.push(o)}function Bi(t,e,r,n){let s=I.default.join(t,e[0]==="**"?"":e[0]??"");mn(t,s,r,n)}function $i(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),o=I.default.join(t,...e.slice(0,s)),i;try{i=X.default.readdirSync(o,{withFileTypes:!0})}catch{return}for(let a of i){if(!a.isDirectory())continue;let c=I.default.join(o,a.name);if(r.has(c))continue;r.add(c);let l=qt(t,c);l&&n.push(l)}}function mn(t,e,r,n){let s;try{s=X.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=I.default.join(e,o.name);if(X.default.existsSync(I.default.join(i,"package.json"))&&!r.has(i)){r.add(i);let a=qt(t,i);a&&n.push(a)}else mn(t,i,r,n)}}var gn={type:"npm",detect(t){let e=Yt.default.join(t,"package.json");if(!$e.default.existsSync(e))return null;let r;try{r=JSON.parse($e.default.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||$e.default.existsSync(Yt.default.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:Z(t,n)}};var B=d(require("fs")),T=d(require("path"));var dn={type:"nx",detect(t){return B.default.existsSync(T.default.join(t,"nx.json"))?hn(t,t,new Set,0).map(r=>Ui(t,r,T.default.join(r,"project.json"))).filter(r=>r!==null):null}};function hn(t,e,r,n){if(n>4)return[];let s;try{s=B.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);B.default.existsSync(T.default.join(c,"project.json"))&&!r.has(c)?(r.add(c),o.push(c)):o.push(...hn(t,c,r,n+1))}return o}function Ui(t,e,r){let n={};try{n=JSON.parse(B.default.readFileSync(r,"utf-8"))}catch{return null}let s=n.name,o,i,a=T.default.join(e,"package.json");if(B.default.existsSync(a))try{let c=JSON.parse(B.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:Ki(e,n,o,i)}:null}function Ki(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(Be);return i.length>0?i.slice(0,1):s.slice(0,1)}var Xt=d(require("fs")),yn=d(require("path")),xn=require("js-yaml");var Sn={type:"pnpm",detect(t){let e=yn.default.join(t,"pnpm-workspace.yaml");if(!Xt.default.existsSync(e))return null;let r=[];try{r=(0,xn.load)(Xt.default.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return Z(t,r)}};var bn=d(require("fs")),kn=d(require("path")),vn={type:"turborepo",detect(t){return bn.default.existsSync(kn.default.join(t,"turbo.json"))?[]:null}};var Ue=d(require("fs")),Zt=d(require("path"));var wn={type:"yarn",detect(t){if(!Ue.default.existsSync(Zt.default.join(t,"yarn.lock")))return null;let e=Zt.default.join(t,"package.json");if(!Ue.default.existsSync(e))return null;let r;try{r=JSON.parse(Ue.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:Z(t,n)}};var Cn=[];function L(t){Cn.push(t)}function Fn(){return Cn}L(vn);L(dn);L(Sn);L(wn);L(gn);function ye(t,e=Fn()){let r=En.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 xe=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 R(o);r.packages.set(n.name,{graph:i,pkg:{...n,root:""}})}return r}};var Tn=new Map;function ee(t,e){Tn.set(t,e)}function Pn(t){return Tn.get(t)}function An(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function Ji(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var Vi=(t,e)=>!e.category||An(t.category,e.category),Hi=(t,e)=>!e.type||An(t.type,e.type),Qi=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,qi=(t,e)=>!e.path||Ji(t.path,e.path),Yi=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,Xi=(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)))},Zi=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),ea=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),ta=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),ra=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,na=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,sa=(t,e)=>e.minSize===void 0||t.size>=e.minSize,oa=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,ia=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,aa=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,ca=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,la=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,pa=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,ua=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,fa=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,ma=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,ga=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,da=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,ha=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,ya=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,xa=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,Sa=(t,e,r)=>!e.any?.length||e.any.some(n=>Se(t,n,r)),ba=[Vi,Hi,Qi,qi,Yi,Xi,Zi,ea,ta,ra,na,sa,oa,ia,aa,ca,la,pa,ua,fa,ma,ga,da,ha,ya,xa,Sa];function Se(t,e,r){return ba.every(n=>n(t,e,r))}function Ke(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=>Se(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 Nn(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 ka(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Nn(s,n),Object.keys(s).length>0&&e.push(s)}return e}function Je(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=ka(o);i.length>0&&(e.any=[...e.any??[],...i]);continue}Nn(e,n)}return e}var gr=d(require("fs/promises")),$n=d(require("path"));var tt=d(require("path")),be=d(require("typescript"));var Dn=d(require("path"));var Mn=d(require("path")),E=d(require("typescript")),In=new Set(["describe","test","it"]);function $(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function er(t){let e=[];for(let r of t.statements){if(!E.default.isExpressionStatement(r))continue;let n=r.expression;if(!E.default.isCallExpression(n))continue;let s=n.expression;E.default.isIdentifier(s)&&In.has(s.text)&&e.push(n),E.default.isPropertyAccessExpression(s)&&E.default.isIdentifier(s.expression)&&In.has(s.expression.text)&&e.push(n)}return e}function tr(t,e,r){for(let n of t.arguments){if(!E.default.isObjectLiteralExpression(n))continue;let s=n.properties.find(o=>E.default.isPropertyAssignment(o)&&E.default.isIdentifier(o.name)&&o.name.text===e);if(!(!s||!E.default.isArrayLiteralExpression(s.initializer)))return s.initializer.elements.filter(E.default.isStringLiteral).map(o=>o.text)}return null}function rr(t,e,r,n){if(t.arguments.length===0)return null;for(let o=1;o<t.arguments.length;o++){let i=$(t.arguments,o);if(!E.default.isObjectLiteralExpression(i))continue;let a=i.properties.find(l=>E.default.isPropertyAssignment(l)&&E.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=$(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function nr(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let o=$(n,s);if(!E.default.isObjectLiteralExpression(o))continue;let i=o.properties.findIndex(c=>E.default.isPropertyAssignment(c)&&E.default.isIdentifier(c.name)&&c.name.text===e);if(i<0)continue;if(o.properties.length===1)return{start:$(n,s-1).getEnd(),end:o.getEnd(),text:""};let a=$(o.properties,i);return i===o.properties.length-1?{start:$(o.properties,i-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:$(o.properties,i+1).getStart(r),text:""}}return null}function sr(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 or(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var D=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function va(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Ve(t,e,r,n){let s=E.default.createSourceFile(Mn.default.basename(t),e,E.default.ScriptTarget.Latest,!0),o=er(s),[i]=o;if(!i)return e;let a=tr(i,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(va(a).sort())===JSON.stringify(c))return e;let l=or(c.map(f=>`@${f}`)),p=o.flatMap(f=>{let g=r.length===0?nr(f,n,s):rr(f,n,l,s);return g?[g]:[]});return p.length>0?sr(e,p):e}var He=class{name="cypress";canHandle(e){return D.has(Dn.default.extname(e).toLowerCase())}apply(e,r,n){return Ve(e,r,n,"tags")}};var Rn=d(require("path")),ir=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,ar=/^@([a-zA-Z0-9_-]+)/gm;function wa(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
9
+ `),null}}var ue=d(require("path"));function Pi(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 Ni(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=ue.default.extname(s),c=ue.default.basename(s,a),l=c==="index"?ue.default.basename(ue.default.dirname(s)):c;n.set(s,{path:s,outDegree:o,tag:`feature:${l}`})}return n}function z(t,e){let r=e?.minOutDegree??5;return Ni(t,Pi(t),r)}var Ii=(t,e)=>t.outDegree-e.outDegree;function Di(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 Mi(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 Ri(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 Li(t,e,r){let n=[];for(let s of t.keys())!e.has(s)&&!r.has(s)&&n.push(s);return n}function fe(t,e){let r=e?.detectFn??z,n=e?.hubComparator??Ii,s=r(t.nodes,e),o=Di(t,s),i=Mi(t.nodes,s,o,n);return{features:Ri(s,i),unassigned:Li(t.nodes,s,i)}}var dn=new Set(["typescript","javascript","python","go","scss","less","lua","coffeescript"]),hn=new Set(["typescript","javascript","python"]),$e=new Set(["typescript","javascript","go","python"]);function Ot(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:dn.has(r),importSymbolsTracked:hn.has(r),callEdgesTracked:$e.has(r)})).sort((r,n)=>n.fileCount-r.fileCount)}var me=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 R=class t{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let r=new Map;for(let n of e.nodes)r.set(n.path,n);return new t(r)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.imports)if(n.toPath){let s=e.get(n.toPath)||[];s.push(r.path),e.set(n.toPath,s)}return this._incomingEdgesCache=e,e}dfs(e,r,n,s){let o=new Set,i=n.maxDepth??1/0,a=(c,l,p)=>{if(l>i||o.has(c))return;let u=this.nodes.get(c);if(u&&(o.add(c),r(u,l,p)!==!1))for(let g of s(c))a(g,l+1,c)};a(e,0,null)}traverse(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.imports.map(a=>a.toPath).filter(Boolean)??[]:o?.get(i)??[])}getCallIncomingCache(){if(this._callIncomingCache)return this._callIncomingCache;let e=new Map;for(let r of this.nodes.values())for(let n of r.callEdges??[]){let s=e.get(n.toFile)??[];s.push(r.path),e.set(n.toFile,s)}return this._callIncomingCache=e,e}traverseCalls(e,r,n={}){let s=n.direction??"outgoing",o=s==="incoming"?this.getCallIncomingCache():null;this.dfs(e,r,n,i=>s==="outgoing"?this.nodes.get(i)?.callEdges?.map(a=>a.toFile)??[]:o?.get(i)??[])}getCallers(e){let r=[];return this.traverseCalls(e,n=>(n.path!==e&&r.push(n.path),!0),{direction:"incoming",maxDepth:1}),r}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let r=this.nodes.get(e);return r?r.imports.map(n=>this.nodes.get(n.toPath)).filter(n=>n!==void 0):[]}findUnusedFiles(e){return new me(this.nodes).findUnusedFiles(e)}findCycles(){return new me(this.nodes).findCycles()}};var W=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 ge(t,e){let r=t.nodes.get(e);if(r)return{category:r.category,exports:r.exports.map(n=>n.name)}}function jt(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 de(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 zt(t,e,r={}){let{testsOnly:n=!1,changedSymbols:s}=r,o=s?new W(e,s):null,i=[];return t.traverse(e,(a,c,l)=>{if(a.path===e)return!0;if(o&&l&&!o.updateAffectedSymbols(a,l))return!1;let p=a.category==="test"||a.tags.some(u=>u.name==="test");return(!n||p)&&i.push(a.path),!0},{direction:"incoming"}),i}function Wt(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 $t(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 Bt(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 Ut(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 Kt(t){return[...t.nodes.values()].some(e=>e.coveragePct!==void 0)}function yn(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 v(e,"component")||v(e,"components")?"component":v(e,"controller")||v(e,"controllers")?"controller":v(e,"middleware")?"middleware":v(e,"router")||v(e,"routes")||v(e,"route")?"router":v(e,"store")||v(e,"stores")?"store":v(e,"service")||v(e,"services")?"service":v(e,"handler")||v(e,"handlers")?"handler":v(e,"adapter")||v(e,"adapters")?"adapter":v(e,"plugin")||v(e,"plugins")?"plugin":v(e,"api")?"api":v(e,"cli")||v(e,"commands")||he(e)==="cli"?"cli":v(e,"util")||v(e,"utils")||v(e,"helper")||v(e,"helpers")?"util":v(e,"model")||v(e,"models")||he(e)==="model"?"model":v(e,"parser")||v(e,"parsers")||he(e)==="parser"?"parser":he(e)==="builder"?"builder":he(e)==="resolver"?"resolver":"other"}function v(t,e){return t.includes(`/${e}/`)||t.includes(`/${e}.`)}function he(t){let e=t.slice(t.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function Jt(t,e){let r=fe(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:yn(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return s}function Ht(t,e){let r=[];for(let n of t.nodes.values())if(n.exports.some(s=>s.name===e))if($e.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=de(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 Gi(t){return t?t.startsWith("interface ")?"interface":t.startsWith("class ")?"class":t.startsWith("enum ")?"enum":"type":"type"}function _i(t,e){if(e==="type-only")return!0;let r=t.signature??"";return r.startsWith("interface ")||r.startsWith("class ")||r.startsWith("enum ")}function Vt(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(!_i(s,n.category))continue;let o=`${n.path}::${s.name}`;e.set(o,{name:s.name,file:n.path,kind:Gi(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 Qt(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 Dn=d(require("path"));var Ue=d(require("fs")),Xt=d(require("path"));var ee=d(require("fs")),A=d(require("path"));var qt=d(require("fs")),Oi=d(require("path"));function xn(t){try{return qt.default.statSync(t,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function Be(t){try{return qt.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function Yt(t,e){let r=A.default.join(e,"package.json");if(!ee.default.existsSync(r))return null;let n={};try{n=JSON.parse(ee.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:ji(e,n)}:null}function ji(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(Be);return n.length>0?n.slice(0,1):r.slice(0,1)}function te(t,e){let r=[],n=new Set;for(let s of e){let o=s.replace(/\/$/,"").replace(/^\.\//,"");zi(t,o,n,r)}return r}function zi(t,e,r,n){if(!e.includes("*")){Wi(t,e,r,n);return}let s=e.split("/");s.includes("**")?$i(t,s,r,n):Bi(t,s,r,n)}function Wi(t,e,r,n){let s=A.default.join(t,e);if(r.has(s)||!xn(s))return;r.add(s);let o=Yt(t,s);o&&n.push(o)}function $i(t,e,r,n){let s=A.default.join(t,e[0]==="**"?"":e[0]??"");bn(t,s,r,n)}function Bi(t,e,r,n){let s=e.findIndex(a=>a.includes("*")),o=A.default.join(t,...e.slice(0,s)),i;try{i=ee.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=Yt(t,c);l&&n.push(l)}}function bn(t,e,r,n){let s;try{s=ee.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(ee.default.existsSync(A.default.join(i,"package.json"))&&!r.has(i)){r.add(i);let a=Yt(t,i);a&&n.push(a)}else bn(t,i,r,n)}}var Sn={type:"npm",detect(t){let e=Xt.default.join(t,"package.json");if(!Ue.default.existsSync(e))return null;let r;try{r=JSON.parse(Ue.default.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!r||Ue.default.existsSync(Xt.default.join(t,"yarn.lock")))return null;let n=Array.isArray(r)?r:r.packages??[];return n.length===0?null:te(t,n)}};var $=d(require("fs")),T=d(require("path"));var kn={type:"nx",detect(t){return $.default.existsSync(T.default.join(t,"nx.json"))?vn(t,t,new Set,0).map(r=>Ui(t,r,T.default.join(r,"project.json"))).filter(r=>r!==null):null}};function vn(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(...vn(t,c,r,n+1))}return o}function Ui(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:Ki(e,n,o,i)}:null}function Ki(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(Be);return i.length>0?i.slice(0,1):s.slice(0,1)}var Zt=d(require("fs")),Cn=d(require("path")),wn=require("js-yaml");var Fn={type:"pnpm",detect(t){let e=Cn.default.join(t,"pnpm-workspace.yaml");if(!Zt.default.existsSync(e))return null;let r=[];try{r=(0,wn.load)(Zt.default.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return te(t,r)}};var Tn=d(require("fs")),En=d(require("path")),An={type:"turborepo",detect(t){return Tn.default.existsSync(En.default.join(t,"turbo.json"))?[]:null}};var Ke=d(require("fs")),er=d(require("path"));var Pn={type:"yarn",detect(t){if(!Ke.default.existsSync(er.default.join(t,"yarn.lock")))return null;let e=er.default.join(t,"package.json");if(!Ke.default.existsSync(e))return null;let r;try{r=JSON.parse(Ke.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:te(t,n)}};var Nn=[];function L(t){Nn.push(t)}function In(){return Nn}L(An);L(kn);L(Fn);L(Pn);L(Sn);function ye(t,e=In()){let r=Dn.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 xe=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 R(o);r.packages.set(n.name,{graph:i,pkg:{...n,root:""}})}return r}};var Mn=new Map;function re(t,e){Mn.set(t,e)}function Rn(t){return Mn.get(t)}function Ln(t,e){return e.startsWith("!")?t!==e.slice(1):t===e}function Ji(t,e){return e.startsWith("!")?!t.includes(e.slice(1)):t.includes(e)}var Hi=(t,e)=>!e.category||Ln(t.category,e.category),Vi=(t,e)=>!e.type||Ln(t.type,e.type),Qi=(t,e)=>e.lastAuthor?e.lastAuthor.startsWith("!")?t.lastAuthor!==e.lastAuthor.slice(1):t.lastAuthor!==void 0&&t.lastAuthor===e.lastAuthor:!0,qi=(t,e)=>!e.path||Ji(t.path,e.path),Yi=(t,e)=>e.isExternal===void 0?!0:t.imports.some(n=>n.isExternal)===e.isExternal,Xi=(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)))},Zi=(t,e)=>!e.allTags?.length||e.allTags.every(r=>t.tags.some(n=>n.name===r)),ea=(t,e)=>!e.importsFile||t.imports.some(r=>r.toPath?.includes(e.importsFile)),ta=(t,e,r)=>e.importedBy===void 0?!0:(r?.get(t.path)??[]).some(s=>s.includes(e.importedBy)),ra=(t,e)=>e.minImports===void 0||t.imports.length>=e.minImports,na=(t,e)=>e.maxImports===void 0||t.imports.length<=e.maxImports,sa=(t,e)=>e.minSize===void 0||t.size>=e.minSize,oa=(t,e)=>e.maxSize===void 0||t.size<=e.maxSize,ia=(t,e)=>e.hasDocstring===void 0||!!t.description===e.hasDocstring,aa=(t,e)=>e.isDocumented===void 0||!!t.documentedBy?.length===e.isDocumented,ca=(t,e)=>e.isStale===void 0||!!t.staleFor?.length===e.isStale,la=(t,e)=>e.minCoverage===void 0||(t.coveragePct??101)>=e.minCoverage,pa=(t,e)=>e.maxCoverage===void 0||(t.coveragePct??0)<=e.maxCoverage,ua=(t,e)=>e.minExportUsage===void 0||(t.avgExportUsage??-1)>=e.minExportUsage,fa=(t,e)=>e.maxExportUsage===void 0||(t.avgExportUsage??0)<=e.maxExportUsage,ma=(t,e)=>e.minComplexity===void 0||(t.complexity??-1/0)>=e.minComplexity,ga=(t,e)=>e.maxComplexity===void 0||(t.complexity??0)<=e.maxComplexity,da=(t,e)=>e.minCognitiveComplexity===void 0||(t.cognitiveComplexity??-1/0)>=e.minCognitiveComplexity,ha=(t,e)=>e.maxCognitiveComplexity===void 0||(t.cognitiveComplexity??0)<=e.maxCognitiveComplexity,ya=(t,e)=>e.minCommits===void 0||(t.commitCount90d??-1/0)>=e.minCommits,xa=(t,e)=>e.maxCommits===void 0||(t.commitCount90d??0)<=e.maxCommits,ba=(t,e,r)=>!e.any?.length||e.any.some(n=>be(t,n,r)),Sa=[Hi,Vi,Qi,qi,Yi,Xi,Zi,ea,ta,ra,na,sa,oa,ia,aa,ca,la,pa,ua,fa,ma,ga,da,ha,ya,xa,ba];function be(t,e,r){return Sa.every(n=>n(t,e,r))}function Je(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=>be(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 Gn(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 ka(t){let e=[];for(let r of t.split("|")){let n=r.trim();if(!n)continue;let s={};Gn(s,n),Object.keys(s).length>0&&e.push(s)}return e}function He(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=ka(o);i.length>0&&(e.any=[...e.any??[],...i]);continue}Gn(e,n)}return e}var dr=d(require("fs/promises")),Qn=d(require("path"));var rt=d(require("path")),Se=d(require("typescript"));var jn=d(require("path"));var On=d(require("path")),F=d(require("typescript")),_n=new Set(["describe","test","it"]);function B(t,e){let r=t[e];if(r===void 0)throw new Error(`Index ${e} out of bounds (length ${t.length})`);return r}function tr(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)&&_n.has(s.text)&&e.push(n),F.default.isPropertyAccessExpression(s)&&F.default.isIdentifier(s.expression)&&_n.has(s.expression.text)&&e.push(n)}return e}function rr(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 nr(t,e,r,n){if(t.arguments.length===0)return null;for(let o=1;o<t.arguments.length;o++){let i=B(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=B(t.arguments,t.arguments.length-1);return{start:s.getStart(n),end:s.getStart(n),text:`{ ${e}: ${r} }, `}}function sr(t,e,r){let n=t.arguments;for(let s=1;s<n.length;s++){let o=B(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:B(n,s-1).getEnd(),end:o.getEnd(),text:""};let a=B(o.properties,i);return i===o.properties.length-1?{start:B(o.properties,i-1).getEnd(),end:a.getEnd(),text:""}:{start:a.getStart(r),end:B(o.properties,i+1).getStart(r),text:""}}return null}function or(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 ir(t){return`[${t.map(e=>JSON.stringify(e)).join(", ")}]`}var D=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function va(t){return t.map(e=>e.startsWith("@")?e.slice(1):e)}function Ve(t,e,r,n){let s=F.default.createSourceFile(On.default.basename(t),e,F.default.ScriptTarget.Latest,!0),o=tr(s),[i]=o;if(!i)return e;let a=rr(i,n,s),c=[...r].sort();if(a!==null&&JSON.stringify(va(a).sort())===JSON.stringify(c))return e;let l=ir(c.map(u=>`@${u}`)),p=o.flatMap(u=>{let g=r.length===0?sr(u,n,s):nr(u,n,l,s);return g?[g]:[]});return p.length>0?or(e,p):e}var Qe=class{name="cypress";canHandle(e){return D.has(jn.default.extname(e).toLowerCase())}apply(e,r,n){return Ve(e,r,n,"tags")}};var zn=d(require("path")),ar=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,cr=/^@([a-zA-Z0-9_-]+)/gm;function Ca(t){return`${["# <mokosh-tags>",...t.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
10
10
  `)}
11
11
 
12
- `}function Ca(t){let e=new Set;ar.lastIndex=0;let r=ar.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=ar.exec(t);return e}var Qe=class{name="gherkin";canHandle(e){return Rn.default.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(ir,""),o=Ca(s),i=n.filter(c=>!o.has(c)),a=i.length>0?wa(i):"";return ir.test(r)?r.replace(ir,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Gn(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 Ln=d(require("path")),cr=/^\/\/go:build mokosh_[^\n]+\n/m,Fa=/^package\s+\S+/m;function Ea(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
13
- `}function Ta(t){let e=cr.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 qe=class{name="go";canHandle(e){return Ln.default.basename(e).endsWith("_test.go")}apply(e,r,n){let s=Ta(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(cr,"");let i=Ea(o);if(s!==null)return r.replace(cr,i);let a=Fa.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+i}
14
- ${r.slice(c)}`}};var _n=d(require("path"));var Pa=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,lr=/^ \* @group (.+)$/gm;function Aa(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
12
+ `}function wa(t){let e=new Set;cr.lastIndex=0;let r=cr.exec(t);for(;r!==null;)r[1]&&e.add(r[1]),r=cr.exec(t);return e}var qe=class{name="gherkin";canHandle(e){return zn.default.extname(e).toLowerCase()===".feature"}apply(e,r,n){let s=r.replace(ar,""),o=wa(s),i=n.filter(c=>!o.has(c)),a=i.length>0?Ca(i):"";return ar.test(r)?r.replace(ar,a):a?r.replace(/^(Feature:)/m,`${a}$1`):r}};function Wn(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 $n=d(require("path")),lr=/^\/\/go:build mokosh_[^\n]+\n/m,Fa=/^package\s+\S+/m;function Ta(t){return`//go:build ${t.map(r=>`mokosh_${r}`).join(" || ")}
13
+ `}function Ea(t){let e=lr.exec(t);if(!e)return null;let r=e[0]??"",n=/mokosh_([a-zA-Z0-9_-]+)/g,s=[],o=n.exec(r);for(;o!==null;)o[1]&&s.push(o[1]),o=n.exec(r);return s}var Ye=class{name="go";canHandle(e){return $n.default.basename(e).endsWith("_test.go")}apply(e,r,n){let s=Ea(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(lr,"");let i=Ta(o);if(s!==null)return r.replace(lr,i);let a=Fa.exec(r);if(!a)return r;let c=a.index;return`${r.slice(0,c)+i}
14
+ ${r.slice(c)}`}};var Bn=d(require("path"));var Aa=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,pr=/^ \* @group (.+)$/gm;function Pa(t){return`${["/**",...t.map(e=>` * @group ${e}`)," */"].join(`
15
15
  `)}
16
16
 
17
- `}function Na(t){let e=[];lr.lastIndex=0;let r=lr.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=lr.exec(t);return e}var Ye=class{name="jest";canHandle(e){return D.has(_n.default.extname(e).toLowerCase())}apply(e,r,n){let s=Pa.exec(r),o=s?Na(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:Aa(i)+a}};var On=d(require("path"));var Xe=class{name="playwright";canHandle(e){return D.has(On.default.extname(e).toLowerCase())}apply(e,r,n){return Ve(e,r,n,"tag")}};var jn=d(require("path")),pr=/^pytestmark\s*=\s*.+$/m,Ia=/^import pytest\s*$/m;function Ma(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Da(t){let e=pr.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 Ze=class{name="pytest";canHandle(e){return jn.default.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Da(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(pr,"").replace(/\n{3,}/g,`
17
+ `}function Na(t){let e=[];pr.lastIndex=0;let r=pr.exec(t);for(;r!==null;)r[1]&&e.push(r[1]),r=pr.exec(t);return e}var Xe=class{name="jest";canHandle(e){return D.has(Bn.default.extname(e).toLowerCase())}apply(e,r,n){let s=Aa.exec(r),o=s?Na(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:Pa(i)+a}};var Un=d(require("path"));var Ze=class{name="playwright";canHandle(e){return D.has(Un.default.extname(e).toLowerCase())}apply(e,r,n){return Ve(e,r,n,"tag")}};var Kn=d(require("path")),ur=/^pytestmark\s*=\s*.+$/m,Ia=/^import pytest\s*$/m;function Da(t){let e=t.map(r=>`pytest.mark.${r}`).join(", ");return t.length===1?`pytestmark = pytest.mark.${t[0]}`:`pytestmark = [${e}]`}function Ma(t){let e=ur.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 et=class{name="pytest";canHandle(e){return Kn.default.extname(e).toLowerCase()===".py"}apply(e,r,n){let s=Ma(r),o=[...n].sort();if(s!==null&&JSON.stringify([...s].sort())===JSON.stringify(o))return r;if(n.length===0)return r.replace(ur,"").replace(/\n{3,}/g,`
18
18
 
19
- `);let i=Ma(o);if(s!==null)return r.replace(pr,i);let a=Ia.test(r),c=Ra(r),l=r.slice(0,c),p=r.slice(c),f=a?"":`import pytest
19
+ `);let i=Da(o);if(s!==null)return r.replace(ur,i);let a=Ia.test(r),c=Ra(r),l=r.slice(0,c),p=r.slice(c),u=a?"":`import pytest
20
20
  `,g=l.endsWith(`
21
21
 
22
22
  `)?"":`
23
- `;return`${l+g+f+i}
23
+ `;return`${l+g+u+i}
24
24
  ${p}`}};function Ra(t){let e=t.split(`
25
- `),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 ur=d(require("path")),fr=d(require("typescript"));var Ga=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,et=class{name="vitest";canHandle(e){return D.has(ur.default.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(Ga,""),o=fr.default.createSourceFile(ur.default.basename(e),s,fr.default.ScriptTarget.Latest,!0),i=er(o),[a]=i;if(!a)return s;let c=tr(a,"tags",o),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=i.flatMap(f=>{let g=n.length===0?nr(f,"tags",o):rr(f,"tags",or(l),o);return g?[g]:[]});return p.length>0?sr(s,p):s}};var Wn={vitest:()=>new et,playwright:()=>new Xe,cypress:()=>new He,jest:()=>new Ye},La={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function _a(t){let e=be.default.createSourceFile("detect.ts",t,be.default.ScriptTarget.Latest,!0);for(let r of e.statements){if(!be.default.isImportDeclaration(r)||!be.default.isStringLiteral(r.moduleSpecifier))continue;let n=La[r.moduleSpecifier.text];if(n)return n}return null}var mr=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return D.has(tt.default.extname(e).toLowerCase())}apply(e,r,n){let s=_a(r)??this.matchOverride(e)??this.defaultFramework;return(Wn[s]??Wn.vitest)().apply(e,r,n)}matchOverride(e){let r=tt.default.relative(this.rootDir,e).split(tt.default.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Gn(n,r))return s;return null}};function zn(t="vitest",e={},r=process.cwd()){return[new Qe,new Ze,new qe,new mr(r,t,Object.entries(e))]}function Bn(t,e){return e.find(r=>r.canHandle(t))??null}var Oa=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,ja=new Set(["import"]),Wa=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 gr.default.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let o=Bn(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 gr.default.writeFile(t,i,"utf8"),{path:t,status:"updated"})}async function dr(t,e,r){let n=ce(e),s=n.tagApplier?.framework??"vitest",o=n.tagApplier?.frameworkOverrides??{},i=zn(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)ja.has(h.kind)&&Oa.test(h.name)&&(Wa.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let f=$n.default.resolve(e,c.path),g=await za(f,p,r.dryRun,i);g.path=c.path,a.files.push(g),g.status==="updated"?a.updated++:g.status==="unchanged"?a.unchanged++:a.errors++}return a}var rt=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};var se=d(require("fs")),A=d(require("path")),Gs=d(require("piscina"));var nt=require("child_process"),st=class{getChangedFiles(){try{let r=[["diff","--name-only"],["diff","--cached","--name-only"],["ls-files","--others","--exclude-standard"]].flatMap(n=>{try{return(0,nt.execFileSync)("git",n,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
26
- `).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),[]}}},Un="%x00%H%x09%ae%x09%at",Kn=256*1024*1024;function Jn(t,e){let r="",n=0;for(let s of t.split(`
27
- `)){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 Vn(t){let e=new Map;try{let r=(0,nt.execFileSync)("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${Un}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Kn});Jn(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,nt.execFileSync)("git",["-C",t,"log","--name-status","-M",`--format=${Un}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Kn});Jn(r,(n,s,o)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:o||void 0})})}catch{}return e}var hr=d(require("path"));function _(t){switch(hr.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 M(t){let e=hr.default.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}var Qn=d(require("coffeescript"));function O(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function te(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 re(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function qn(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return O(t.value)}}function U(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function Ba(t,e){let r=qn(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:M(r),type:"static"}:null}function $a(t,e){let r=e.variable?.base?.value==="require",n=qn(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:M(n),type:"require"}}function Hn(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=U(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>U(s.variable)??U(s)).filter(s=>!!s).map(s=>({name:s}));let n=U(r);return n?[{name:n}]:[]}function Ua(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=U(t.variable)??U(t.variable?.base);return e?[{name:e}]:[]}function Ka(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let o=Ba(t,e);o&&r.push(o)}else if(s==="Call"){let o=$a(t,e);o&&r.push(o)}else if(s==="Assign"){let o=U(e.variable?.base),i=e.variable?.properties?.[0]?.name?.value;o==="module"&&i==="exports"?n.push(...Hn(e,void 0)):o==="exports"&&typeof i=="string"&&n.push(...Hn(e,i))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...Ua(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function yr(t,e,r,n){if(!(!e||typeof e!="object")){Ka(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)yr(t,i,r,n);else yr(t,o,r,n)}}}function Yn(t,e){let r=te(e),n=re(t,r),s=[],o=[];try{yr(t,Qn.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 ne=require("@cucumber/gherkin"),Xn=require("@cucumber/messages");var Ja=Xn.IdGenerator.uuid();function xr(t,e){let r=new Set;try{let n=new ne.AstBuilder(Ja),s=new ne.GherkinClassicTokenMatcher,i=new ne.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"}}ee("gherkin",xr);var ts=d(require("path")),rs=require("@lezer/go");function K(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function ke(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
28
- `&&r++;return r}function Va(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 Ha(t,e){let r=0;function n(s,o,i){let a=s.type.name;if(a==="IfStatement"){r+=i?1:1+o;let p=K(s),f=i?o:o+1,g=p[1];g&&g.type.name!=="Block"&&n(g,f,!1);let h=p.find(y=>y.type.name==="Block");h&&n(h,f,!1);let S=p.findIndex(y=>y.type.name==="else");if(S>=0){let y=p[S+1];y?.type.name==="IfStatement"?n(y,o,!0):y&&(r+=1,n(y,o+1,!1))}return}if(a==="ForStatement"||a==="SwitchStatement"||a==="SelectStatement"){r+=1+o;let p=s.firstChild;for(;p;)n(p,o+1,!1),p=p.nextSibling;return}if(a==="LogicOp"){let p=e.slice(s.from,s.to);(p==="&&"||p==="||")&&(r+=1)}if(o>0&&a==="FunctionLiteral"){r+=1+o;let p=s.firstChild;for(;p;)n(p,o+1,!1),p=p.nextSibling;return}let l=s.firstChild;for(;l;)n(l,o,!1),l=l.nextSibling}return n(t,0,!1),r}function ot(t,e){return{complexity:Va(t,e),cognitiveComplexity:Ha(t,e)}}function Sr(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 Zn(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}=ot(n.node,e);r.push({name:o,line:ke(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=Sr(n.node,e),a=i?`${i}.${o}`:o,{complexity:c,cognitiveComplexity:l}=ot(n.node,e);r.push({name:a,line:ke(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Qa=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,qa=/^\/\/go:build\s+(.+)$/,Ya=/^\/\/\s*\+build\s+(.+)$/;function ns(t,e){let r=[],n=new Map,s=new Set,o=new Set,i=new Map,a=rs.parser.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let b=e.slice(c.from,c.to),x=b.match(Qa);x?.[1]&&s.add(x[1]);let k=b.match(qa);k&&es(k[1],o);let P=b.match(Ya);P&&es(P[1],o);break}case"ImportSpec":{let b=c.node.getChild("String");if(b){let k=e.slice(b.from,b.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:k,isExternal:!0,isStyle:!1,type:"static"});let P=c.node.getChild("DefName"),N=P?e.slice(P.from,P.to):k.split("/").pop();N&&N!=="_"&&N!=="."&&i.set(N,k)}break}case"FunctionDecl":case"MethodDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let b=c.node.getChild("DefName")??c.node.getChild("FieldName")??c.node.getChild("TypeSpec")?.getChild("DefName")??c.node.getChild("VarSpec")?.getChild("DefName")??c.node.getChild("ConstSpec")?.getChild("DefName");if(b){let x=e.slice(b.from,b.to);x!=="_"&&/^[A-Z]/.test(x)&&!n.has(x)&&n.set(x,{name:x})}break}}while(c.next());let l=r.some(b=>b.rawSpecifier==="testing"),p=ts.default.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",f=new Set([...s,...o]),{complexity:g,cognitiveComplexity:h}=ot(a.topNode,e),S=Zn(a,e),y=p==="test"?[]:Xa(a,e,i);return{imports:r,exports:Array.from(n.values()),tags:Array.from(f).map(b=>({name:b,kind:"comment-marker"})),category:p,rawCallEdges:y,complexity:g,cognitiveComplexity:h,...S.length>0?{functions:S}:{}}}function Xa(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 g=e.slice(p.from,p.to),h=r.get(g);if(h){let S=e.slice(f.from,f.to);n.push({from:a,to:S,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=Sr(o.node,e);s(a,l?`${l}.${c}`:c)}}while(o.next());return n}function es(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}var ss=d(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 Za(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 ec(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 Za(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 tc=new Set(["first_line","first_column","last_line","last_column","line","column"]);function rc(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:M(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:M(o),type:"require"}}}}return null}function br(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=rc(t,e);s&&n.push(s),r.push(...ec(t));for(let o in t){if(tc.has(o))continue;let i=t[o];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let a of i)n.push(...br(a,e,r));else n.push(...br(i,e,r))}return n}function os(t,e){let r=te(e),n=re(t,r),s=[],o=[];try{s=br(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 is=d(require("luaparse"));function nc(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:M(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 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 oc(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 ic(t){let e=t.body,r=sc(e),n=oc(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 as(t,e){let r=te(e),n=re(t,r),s=[],o=[];try{let i=is.default.parse(e);s=nc(i,t),o=ic(i)}catch{}return{imports:s,exports:o,tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:n}}var ac=["http://","https://","mailto:","//"],cc="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",lc=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${cc})\\b`,"g"),cs;async function pc(){return cs??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),cs}function uc(t){let e=t.trim();return e.length===0||e.startsWith("#")||ac.some(r=>e.startsWith(r))}function fc(t,e){let r=t.match(lc);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function ls(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!uc(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(...fc(t.value,e)),Array.isArray(t.children))for(let n of t.children)ls(n,e,r)}async function ps(t,e){let n=(await pc()).parse(e),s=[];ls(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 fs=d(require("path")),ms=require("@lezer/python");function mc(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 gc(t){let e=0;function r(n,s){let o=n.type.name;if(o==="IfStatement"){let c=K(n),l=0,p=0;for(;p<c.length;){let f=c[p];if(f?.type.name==="if"||f?.type.name==="elif"){let g=l>0;e+=g?1:1+s;let h=g?s:s+1,S=c[p+1],y=c[p+2];S&&r(S,h),y&&r(y,h),l++,p+=3}else if(f?.type.name==="else"){e+=1;let g=c[p+1];g&&r(g,s+1),p+=2}else p++}return}if(o==="TryStatement"){let c=K(n),l=0;for(;l<c.length;){let p=c[l];if(p?.type.name==="except"){for(e+=1+s,l++;l<c.length&&c[l]?.type.name!=="Body";)r(c[l],s),l++;l<c.length&&(r(c[l],s),l++)}else p?.type.name==="Body"&&r(p,s),l++}return}if(o==="ForStatement"||o==="WhileStatement"){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}if((o==="ConditionalExpression"||o==="and"||o==="or")&&(e+=1),s>0&&(o==="FunctionDefinition"||o==="LambdaExpression")){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}let a=n.firstChild;for(;a;)r(a,s),a=a.nextSibling}return r(t,0),e}function kr(t){return{complexity:mc(t),cognitiveComplexity:gc(t)}}function us(t,e){let r=[];function n(i,a){let{complexity:c,cognitiveComplexity:l}=kr(i);r.push({name:a,line:ke(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"),g=f?e.slice(f.from,f.to):void 0;g&&n(p,c?`${c}.${g}`:g),s(p)}else o(p);p=p.nextSibling}}return}if(i.type.name==="FunctionDefinition"){let a=i.getChild("VariableName");a&&n(i,e.slice(a.from,a.to)),s(i);return}s(i)}return o(t.topNode),r}var dc=new Set(["pytest","unittest","nose","hypothesis"]);function gs(t,e){let r=[],n=[],s=new Set,o=fs.default.basename(t).toLowerCase(),i=ms.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 hc(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 y=a.node.getChild("VariableName");y&&n.push({name:e.slice(y.from,y.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=vc(o,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=kr(i.topNode),f=us(i,e),g=c==="test"?[]:kc(i,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:g,complexity:l,cognitiveComplexity:p,...f.length>0?{functions:f}:{}}}function hc(t,e,r){let n=t.firstChild;return n?n.name==="from"?yc(t,e,r):xc(t,e,r):[]}function yc(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=Sc(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[ve(r,o,i,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[ve(r,l+c.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[ve(r,l.slice(0,-1),["*"],!1)]:i.map(p=>ve(r,l+p,[p],!1))}function xc(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(ve(r,o,["*"],!0))}s=s.nextSibling}return n}function Sc(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 bc(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 g=e.slice(f.from,f.to),h=g;if(f.nextSibling?.type.name==="as"){let y=f.nextSibling.nextSibling;y?.type.name==="VariableName"&&(h=e.slice(y.from,y.to),f=y)}let S=c===0?a:l?p+l.replace(/\./g,"/"):p+g;r.set(h,S)}f=f.nextSibling}}while(n.next());return r}function kc(t,e){let r=bc(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),g=r.get(f);g&&n.push({from:c,to:f,toSpecifier:g})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function o(a){let c=a.firstChild;for(;c;)i(c),c=c.nextSibling}function i(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let f=p.firstChild;for(;f;){if(f.type.name==="FunctionDefinition"){let g=f.getChild("VariableName"),h=g?e.slice(g.from,g.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 ve(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function vc(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=>dc.has(n.rawSpecifier))?"test":"logic"}var Cr=d(require("path")),m=d(require("typescript"));var v=d(require("typescript"));function wc(t){let e=1;function r(n){switch(n.kind){case v.default.SyntaxKind.IfStatement:case v.default.SyntaxKind.ConditionalExpression:case v.default.SyntaxKind.ForStatement:case v.default.SyntaxKind.ForInStatement:case v.default.SyntaxKind.ForOfStatement:case v.default.SyntaxKind.WhileStatement:case v.default.SyntaxKind.DoStatement:case v.default.SyntaxKind.CatchClause:case v.default.SyntaxKind.CaseClause:e++;break;case v.default.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===v.default.SyntaxKind.AmpersandAmpersandToken||s===v.default.SyntaxKind.BarBarToken||s===v.default.SyntaxKind.QuestionQuestionToken)&&e++;break}}v.default.forEachChild(n,r)}return r(t),e}function Cc(t){let e=0;function r(n,s,o){if(v.default.isIfStatement(n)){e+=o?1:1+s;let a=o?s:s+1;r(n.expression,a,!1),r(n.thenStatement,a,!1),n.elseStatement&&(v.default.isIfStatement(n.elseStatement)?r(n.elseStatement,s,!0):(e+=1,r(n.elseStatement,s+1,!1)));return}if(v.default.isForStatement(n)||v.default.isForInStatement(n)||v.default.isForOfStatement(n)||v.default.isWhileStatement(n)||v.default.isDoStatement(n)||v.default.isSwitchStatement(n)){e+=1+s,v.default.forEachChild(n,a=>r(a,s+1,!1));return}if(v.default.isCatchClause(n)){e+=1+s,v.default.forEachChild(n,a=>r(a,s,!1));return}if(v.default.isConditionalExpression(n)&&(e+=1),v.default.isBinaryExpression(n)){let a=n.operatorToken.kind;(a===v.default.SyntaxKind.AmpersandAmpersandToken||a===v.default.SyntaxKind.BarBarToken||a===v.default.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(s>0&&(v.default.isFunctionDeclaration(n)||v.default.isFunctionExpression(n)||v.default.isArrowFunction(n))){e+=1+s,v.default.forEachChild(n,a=>r(a,s+1,!1));return}v.default.forEachChild(n,a=>r(a,s,!1))}return r(t,0,!1),e}function vr(t){return{complexity:wc(t),cognitiveComplexity:Cc(t)}}var F=d(require("typescript")),wr=new Set(["test","describe","it"]);function ds(t,e){Fc(t,e),Tc(t,e),Pc(t,e),Ac(t,e)}function Fc(t,e){if((F.default.isFunctionDeclaration(t)||F.default.isVariableDeclaration(t))&&t.name&&F.default.isIdentifier(t.name)&&Ec(t)){let r;if(F.default.isFunctionDeclaration(t))r="function";else{let n=t.initializer;r=n&&(F.default.isArrowFunction(n)||F.default.isFunctionExpression(n))?"function":"variable"}e.tags.add({name:t.name.text,kind:r})}}function Ec(t){if(F.default.isFunctionDeclaration(t))return F.default.isSourceFile(t.parent);let e=t.parent?.parent;return!!e&&F.default.isSourceFile(e.parent)}function Tc(t,e){if(!F.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 Pc(t,e){if(!F.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 Ac(t,e){if(F.default.isCallExpression(t)&&Nc(t.expression))for(let r of t.arguments)F.default.isObjectLiteralExpression(r)&&Ic(r,e)}function Nc(t){return F.default.isIdentifier(t)?wr.has(t.text):!!(F.default.isPropertyAccessExpression(t)&&(wr.has(t.name.text)||F.default.isIdentifier(t.expression)&&wr.has(t.expression.text)))}function Ic(t,e){for(let r of t.properties){if(!F.default.isPropertyAssignment(r)||!F.default.isIdentifier(r.name)||r.name.text!=="tags"&&r.name.text!=="tag")continue;let{initializer:n}=r,s=F.default.isArrayLiteralExpression(n)?n.elements.filter(F.default.isStringLiteral):r.name.text==="tag"&&F.default.isStringLiteral(n)?[n]:[];for(let o of s)e.tags.add({name:o.text.replace(/^@/,""),kind:"comment-marker"})}}function Fr(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=y=>{Gc(y,a),m.default.forEachChild(y,c)};c(i);let l=Jc(t,a);(l==="test"||l==="barrel")&&o.add({name:l,kind:"comment-marker"}),l!=="test"&&Vc(a,i);let p=i.statements[0],f=p?ys(p):void 0,{complexity:g,cognitiveComplexity:h}=vr(i),S=Mc(i);return{imports:n,exports:Array.from(s.values()),tags:Array.from(o),category:l,rawCallEdges:a.rawCallEdges??[],complexity:g,cognitiveComplexity:h,...S.length>0?{functions:S}:{},...f!==void 0?{description:f}:{}}}function Mc(t){let e=[],r=(s,o)=>{let{complexity:i,cognitiveComplexity:a}=vr(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 hs(t,e,r,n){let s={name:t},o=ys(r);o!==void 0&&(s.doc=o);let i=Dc(e);i!==void 0&&(s.flags=i);let a=Rc(e,n);return a!==void 0&&(s.signature=a),s}function ys(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 Dc(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 Rc(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 Gc(t,e){Lc(t,e),_c(t,e),jc(t,e),Wc(t,e),Kc(t,e),ds(t,e)}function Lc(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)||Er(n)).length}function _c(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)&&!Oc(t)&&(e.hasTypesOnly=!1)}function Oc(t){return t.isTypeOnly?!0:!t.exportClause||!m.default.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function jc(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:M(t.moduleSpecifier.text),type:n,symbols:r.length>0?r:void 0})}function Wc(t,e){m.default.isExportDeclaration(t)?zc(t,e):m.default.isExportAssignment(t)?e.exports.set("default",{name:"default"}):Er(t)&&Uc(t,e)}function zc(t,e){if(t.moduleSpecifier&&m.default.isStringLiteral(t.moduleSpecifier))Bc(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 Bc(t,e,r){let n=$c(t),s={fromPath:r.filePath,toPath:"",rawSpecifier:e,isStyle:M(e),type:"re-export"};n.length>0&&(s.symbols=n),r.imports.push(s)}function $c(t){return t.exportClause?m.default.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Uc(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,hs(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,hs(s,n,t,e.sourceFile))}}}function Kc(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:M(r.text),type:"dynamic"}):m.default.isIdentifier(t.expression)&&t.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.text,isStyle:M(r.text),type:"require"}))}function Jc(t,e){let r=Cr.default.basename(t).toLowerCase(),n=Cr.default.extname(t).toLowerCase();return ae().some(o=>r.includes(o))?"test":Lr(r)?"config":e.imports.some(o=>ht().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>xt()?"barrel":"logic"}function Er(t){return m.default.canHaveModifiers(t)&&m.default.getModifiers(t)?.some(e=>e.kind===m.default.SyntaxKind.ExportKeyword)===!0}function Vc(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=Qc(s);if(o){let i=qc(s);i&&it(i,o,n,r);continue}m.default.isClassDeclaration(s)&&s.name&&Hc(s,s.name.text,n,r)}}function Hc(t,e,r,n){for(let s of t.members)m.default.isMethodDeclaration(s)&&s.body&&m.default.isIdentifier(s.name)?it(s.body,`${e}.${s.name.text}`,r,n):m.default.isConstructorDeclaration(s)&&s.body&&it(s.body,`${e}.constructor`,r,n)}function Qc(t){if(Er(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 qc(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 it(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=>it(s,e,r,n))}function at(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 xs(t,e){let r=[],n=/@require\s+['"]([^'"]+)['"]/g,s=n.exec(t);for(;s!==null;){let i=s[1];i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"require"}),s=n.exec(t)}let o=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(s=o.exec(t);s!==null;){let i=s[1];i&&r.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),s=o.exec(t)}return r}function Ss(t,e){if(e.length===0)return"ui";try{let r=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 we(t,e){let r=_(t);if(r==="stylus"){let o=xs(e,t);return{imports:o,exports:[],tags:[],category:Ss(e,o)}}if(r==="scss"){let{imports:o,root:i,exports:a,tags:c}=We(e,t);return{imports:o,exports:a,tags:c,category:at(i,o)}}if(r==="less"){let{imports:o,root:i,exports:a,tags:c}=je(e,t);return{imports:o,exports:a,tags:c,category:at(i,o)}}let{imports:n,root:s}=Oe(e,t);return{imports:n,exports:[],tags:[],category:at(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Fr(r,n,"javascript")],["typescript",(r,n)=>Fr(r,n,"typescript")],["css",we],["scss",we],["less",we],["stylus",we],["coffeescript",Yn],["livescript",os],["lua",as],["python",gs],["go",ns],["gherkin",xr],["markdown",ps]])ee(t,e);async function bs(t,e){let r=_(t),n=Pn(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}var Tr=d(require("path"));function vs(t,e){for(let r of t.values()){let n=e.get(r.path);n!==void 0&&(r.coveragePct=n)}}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 Cs(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);n&&(n.category!=="logic"&&n.category!=="barrel"||(n.testedBy??=[],n.testedBy.includes(e.path)||n.testedBy.push(e.path)))}}function Fs(t){for(let e of t.values())if(e.type==="markdown")for(let r of e.imports){if(r.isExternal||!r.toPath)continue;let n=t.get(r.toPath);!n||n===e||(n.documentedBy??=[],n.documentedBy.includes(e.path)||n.documentedBy.push(e.path),n.category==="logic"&&(n.lastCommitAt??0)>(e.lastCommitAt??0)&&(e.staleFor??=[],e.staleFor.includes(n.path)||e.staleFor.push(n.path)))}}function ks(t){return Math.round(t*1e4)/1e4}function Es(t){for(let e of t.values()){let r=[];for(let n of e.imports){if(n.isExternal||!n.toPath)continue;let s=t.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=ks(Math.min(1,o)),r.push(n.exportUsageRatio)}r.length>0&&(e.avgExportUsage=ks(r.reduce((n,s)=>n+s,0)/r.length),e.maxExportUsage=Math.max(...r))}}function Pr(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function Yc(t,e){let r=e.toPath,n=Tr.default.basename(r,Tr.default.extname(r)).replace(/\.(test|spec)$/,"");Pr(t.tags,n,"import")}function Xc(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Pr(t.tags,r,"import")}function Zc(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Pr(t.tags,s.name,"comment-marker")}function Ts(t){for(let e of t.values())if(e.category==="test")for(let r of e.imports)!r.toPath||r.isExternal||(Yc(e,r),Xc(e,r),Zc(e,r,t))}var Ae=d(require("fs")),G=d(require("path"));var Ar=d(require("fs")),V=d(require("path")),Ce=class{extensions=[".go"];goModCache=new Map;resolve(e,r,n,s){let{mod:o,replaces:i}=this.readGoMod(n);if(!o)return null;let a=this.applyReplace(r,i,n);if(a!==void 0)return As(a);if(r!==o&&!r.startsWith(`${o}/`))return null;let c=r.slice(o.length).replace(/^\//,"");return c?As(V.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=Ar.default.readFileSync(V.default.join(e,"go.mod"),"utf-8"),o=el(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 V.default.join(o,i)}}}};function el(t,e){let r=t.split(`
29
- `),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("=>")){Ps(a,e,s);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&Ps(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function Ps(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=V.default.isAbsolute(s)?s:V.default.resolve(e,s);r.set(o,i)}function As(t){let e;try{e=Ar.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:V.default.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}var Ns=d(require("fs")),ct=d(require("path")),Fe=class{extensions=[".lua"];resolve(e,r,n,s){let o=r.replace(/\./g,ct.default.sep),i=[n,ct.default.join(n,"lib")];for(let a of i){if(!Ns.default.existsSync(a))continue;let c=s(ct.default.join(a,"_dummy.lua"),o);if(c)return[c]}return null}};var Is=d(require("path")),Ee=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let o=s(Is.default.join(n,"_dummy"),`./${r}`);return o?[o]:null}};var Ds=d(require("fs")),lt=d(require("path")),Te=class{extensions=[".py"];resolve(e,r,n,s){let o=r.replace(/\./g,lt.default.sep),i=lt.default.join(n,`${o}.py`);if(Ms(i))return[{path:i,isExternal:!1}];let a=lt.default.join(n,o,"__init__.py");return Ms(a)?[{path:a,isExternal:!1}]:null}};function Ms(t){try{return Ds.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var Nr=d(require("path")),tl=["~","http://","https://","//","data:","sass:"],Pe=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=Nr.default.dirname(r),a=Nr.default.basename(r),c=i==="."?`_${a}`:`${i}/_${a}`,l=s(e,c);return l?[l]:null}};var H=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 Te,new Fe,new Ce,new Pe,new Ee]}rootDir;workspaceMap;tsconfigSearchPaths;pathAliases;langResolvers;resolveAll(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){let n=this.resolvePathAlias(r);if(n)return n;if(r.startsWith(".")||r.startsWith("/"))return this.resolveLocalPath(e,r);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[0]??null}let o=this.resolveWorkspaceImport(r);return o||{path:r,isExternal:!0}}resolveLocalPath(e,r){let n=G.default.dirname(e),s=r.startsWith("/")?r:G.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=G.default.join(e,`index${r}`);if(this.isFile(o))return{path:o,isExternal:n};if(r===".py"){let i=G.default.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:n}}return null}isFile(e){try{return Ae.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=G.default.join(r,"tsconfig.json");if(Ae.default.existsSync(n))try{let o=JSON.parse(Ae.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=G.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=G.default.join(n,a);try{if(Ae.default.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...o,path:c}}catch{}}return{...o,path:n}}let i=this.resolveLocalPath(G.default.join(n,"_dummy"),s.slice(1));return i?{...o,path:i.path}:null}return null}};var rl=["tests","test","__tests__","specs","spec"],Rs=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),nl=20;function sl(t,e){if(t.length===0)return e;let r=t.map(i=>A.default.dirname(i).split(A.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(A.default.sep)||A.default.sep,o=A.default.relative(e,s);return o.startsWith("..")||A.default.isAbsolute(o)?e:s}var Ne=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 H(e),this.lockFile=Hr(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=>A.default.isAbsolute(n)?n:A.default.resolve(this.rootDir,n));await this.initPool(),this.enableGitStats&&(this.gitStatsMap=Vn(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(sl(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
25
+ `),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 fr=d(require("path")),mr=d(require("typescript"));var La=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,tt=class{name="vitest";canHandle(e){return D.has(fr.default.extname(e).toLowerCase())}apply(e,r,n){let s=r.replace(La,""),o=mr.default.createSourceFile(fr.default.basename(e),s,mr.default.ScriptTarget.Latest,!0),i=tr(o),[a]=i;if(!a)return s;let c=rr(a,"tags",o),l=[...n].sort();if(c!==null&&JSON.stringify([...c].sort())===JSON.stringify(l))return s;let p=i.flatMap(u=>{let g=n.length===0?sr(u,"tags",o):nr(u,"tags",ir(l),o);return g?[g]:[]});return p.length>0?or(s,p):s}};var Jn={vitest:()=>new tt,playwright:()=>new Ze,cypress:()=>new Qe,jest:()=>new Xe},Ga={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function _a(t){let e=Se.default.createSourceFile("detect.ts",t,Se.default.ScriptTarget.Latest,!0);for(let r of e.statements){if(!Se.default.isImportDeclaration(r)||!Se.default.isStringLiteral(r.moduleSpecifier))continue;let n=Ga[r.moduleSpecifier.text];if(n)return n}return null}var gr=class{constructor(e,r,n){this.rootDir=e;this.defaultFramework=r;this.frameworkOverrides=n}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return D.has(rt.default.extname(e).toLowerCase())}apply(e,r,n){let s=_a(r)??this.matchOverride(e)??this.defaultFramework;return(Jn[s]??Jn.vitest)().apply(e,r,n)}matchOverride(e){let r=rt.default.relative(this.rootDir,e).split(rt.default.sep).join("/");for(let[n,s]of this.frameworkOverrides)if(Wn(n,r))return s;return null}};function Hn(t="vitest",e={},r=process.cwd()){return[new qe,new et,new Ye,new gr(r,t,Object.entries(e))]}function Vn(t,e){return e.find(r=>r.canHandle(t))??null}var Oa=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,ja=new Set(["import"]),za=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function Wa(t,e,r,n){let s;try{s=await dr.default.readFile(t,"utf8")}catch(a){return{path:t,status:"error",error:String(a)}}let o=Vn(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 dr.default.writeFile(t,i,"utf8"),{path:t,status:"updated"})}async function hr(t,e,r){let n=le(e),s=n.tagApplier?.framework??"vitest",o=n.tagApplier?.frameworkOverrides??{},i=Hn(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)ja.has(h.kind)&&Oa.test(h.name)&&(za.has(h.name.toLowerCase())||l.has(h.name)||(l.add(h.name),p.push(h.name)));p.sort();let u=Qn.default.resolve(e,c.path),g=await Wa(u,p,r.dryRun,i);g.path=c.path,a.files.push(g),g.status==="updated"?a.updated++:g.status==="unchanged"?a.unchanged++:a.errors++}return a}var nt=class{isTestNode(e){return e.category==="test"||e.tags.some(r=>r.name==="test")}};var ie=d(require("fs")),E=d(require("path")),_s=d(require("piscina"));var st=require("child_process"),ot=class{getChangedFiles(){try{let r=[["diff","--name-only"],["diff","--cached","--name-only"],["ls-files","--others","--exclude-standard"]].flatMap(n=>{try{return(0,st.execFileSync)("git",n,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
26
+ `).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),[]}}},qn="%x00%H%x09%ae%x09%at",Yn=256*1024*1024;function Xn(t,e){let r="",n=0;for(let s of t.split(`
27
+ `)){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 Zn(t){let e=new Map;try{let r=(0,st.execFileSync)("git",["-C",t,"log","--since=90 days ago","--name-status","-M",`--format=${qn}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Yn});Xn(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,st.execFileSync)("git",["-C",t,"log","--name-status","-M",`--format=${qn}`],{encoding:"utf-8",stdio:["ignore","pipe","ignore"],maxBuffer:Yn});Xn(r,(n,s,o)=>{e.has(n)||e.set(n,{commitCount90d:0,lastAuthor:void 0,lastCommitAt:o||void 0})})}catch{}return e}var yr=d(require("path"));function G(t){switch(yr.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=yr.default.extname(t).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}var ts=d(require("coffeescript"));function _(t){return t.startsWith("'")||t.startsWith('"')?t.slice(1,-1):t}function ne(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 se(t,e){let r=t.toLowerCase();return r.includes(".test.")||r.includes(".spec.")||e.has("test")?"test":"logic"}function rs(t){if(t){if(typeof t.originalValue=="string")return t.originalValue;if(typeof t.value=="string")return _(t.value)}}function U(t){if(t){if(typeof t.value=="string")return t.value;if(typeof t.base?.value=="string")return t.base.value}}function $a(t,e){let r=rs(e.source);return r?{fromPath:t,toPath:"",rawSpecifier:r,isStyle:P(r),type:"static"}:null}function Ba(t,e){let r=e.variable?.base?.value==="require",n=rs(e.args?.[0]?.base);return!r||!n?null:{fromPath:t,toPath:"",rawSpecifier:n,isStyle:P(n),type:"require"}}function es(t,e){if(e)return[{name:e}];let r=t.value;if(r?.constructor?.name==="Class"){let s=U(r.variable);return s?[{name:s}]:[]}if(r?.base?.constructor?.name==="Obj"&&Array.isArray(r.base.properties))return r.base.properties.map(s=>U(s.variable)??U(s)).filter(s=>!!s).map(s=>({name:s}));let n=U(r);return n?[{name:n}]:[]}function Ua(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=U(t.variable)??U(t.variable?.base);return e?[{name:e}]:[]}function Ka(t,e,r,n){let s=e.constructor?.name;if(s==="ImportDeclaration"){let o=$a(t,e);o&&r.push(o)}else if(s==="Call"){let o=Ba(t,e);o&&r.push(o)}else if(s==="Assign"){let o=U(e.variable?.base),i=e.variable?.properties?.[0]?.name?.value;o==="module"&&i==="exports"?n.push(...es(e,void 0)):o==="exports"&&typeof i=="string"&&n.push(...es(e,i))}else s==="ExportNamedDeclaration"&&e.clause?n.push(...Ua(e.clause)):s==="ExportDefaultDeclaration"&&n.push({name:"default"})}function xr(t,e,r,n){if(!(!e||typeof e!="object")){Ka(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)xr(t,i,r,n);else xr(t,o,r,n)}}}function ns(t,e){let r=ne(e),n=se(t,r),s=[],o=[];try{xr(t,ts.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 oe=require("@cucumber/gherkin"),ss=require("@cucumber/messages");var Ja=ss.IdGenerator.uuid();function br(t,e){let r=new Set;try{let n=new oe.AstBuilder(Ja),s=new oe.GherkinClassicTokenMatcher,i=new oe.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"}}re("gherkin",br);var as=d(require("path")),cs=require("@lezer/go");function K(t){let e=[],r=t.firstChild;for(;r;)e.push(r),r=r.nextSibling;return e}function ke(t,e){let r=1;for(let n=0;n<e&&n<t.length;n++)t[n]===`
28
+ `&&r++;return r}function Ha(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 Va(t,e){let r=0;function n(s,o,i){let a=s.type.name;if(a==="IfStatement"){r+=i?1:1+o;let p=K(s),u=i?o:o+1,g=p[1];g&&g.type.name!=="Block"&&n(g,u,!1);let h=p.find(x=>x.type.name==="Block");h&&n(h,u,!1);let k=p.findIndex(x=>x.type.name==="else");if(k>=0){let x=p[k+1];x?.type.name==="IfStatement"?n(x,o,!0):x&&(r+=1,n(x,o+1,!1))}return}if(a==="ForStatement"||a==="SwitchStatement"||a==="SelectStatement"){r+=1+o;let p=s.firstChild;for(;p;)n(p,o+1,!1),p=p.nextSibling;return}if(a==="LogicOp"){let p=e.slice(s.from,s.to);(p==="&&"||p==="||")&&(r+=1)}if(o>0&&a==="FunctionLiteral"){r+=1+o;let p=s.firstChild;for(;p;)n(p,o+1,!1),p=p.nextSibling;return}let l=s.firstChild;for(;l;)n(l,o,!1),l=l.nextSibling}return n(t,0,!1),r}function it(t,e){return{complexity:Ha(t,e),cognitiveComplexity:Va(t,e)}}function Sr(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 os(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}=it(n.node,e);r.push({name:o,line:ke(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=Sr(n.node,e),a=i?`${i}.${o}`:o,{complexity:c,cognitiveComplexity:l}=it(n.node,e);r.push({name:a,line:ke(e,n.from),complexity:c,cognitiveComplexity:l})}}while(n.next());return r}var Qa=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,qa=/^\/\/go:build\s+(.+)$/,Ya=/^\/\/\s*\+build\s+(.+)$/;function ls(t,e){let r=[],n=new Map,s=new Set,o=new Set,i=new Map,a=cs.parser.parse(e),c=a.cursor();do switch(c.name){case"LineComment":{let y=e.slice(c.from,c.to),C=y.match(Qa);C?.[1]&&s.add(C[1]);let I=y.match(qa);I&&is(I[1],o);let N=y.match(Ya);N&&is(N[1],o);break}case"ImportSpec":{let y=c.node.getChild("String");if(y){let I=e.slice(y.from,y.to).slice(1,-1);r.push({fromPath:t,toPath:"",rawSpecifier:I,isExternal:!0,isStyle:!1,type:"static"});let N=c.node.getChild("DefName"),O=N?e.slice(N.from,N.to):I.split("/").pop();O&&O!=="_"&&O!=="."&&i.set(O,I)}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 C=e.slice(y.from,y.to);C!=="_"&&/^[A-Z]/.test(C)&&!n.has(C)&&n.set(C,{name:C})}break}}while(c.next());let l=r.some(y=>y.rawSpecifier==="testing"),p=as.default.basename(t).endsWith("_test.go")||s.has("test")||l?"test":"logic",u=new Set([...s,...o]),{complexity:g,cognitiveComplexity:h}=it(a.topNode,e),k=os(a,e),x=p==="test"?[]:Xa(a,e,i);return{imports:r,exports:Array.from(n.values()),tags:Array.from(u).map(y=>({name:y,kind:"comment-marker"})),category:p,rawCallEdges:x,complexity:g,cognitiveComplexity:h,...k.length>0?{functions:k}:{}}}function Xa(t,e,r){let n=[];function s(i,a){if(i.type.name==="CallExpr"){let l=i.firstChild;if(l?.type.name==="SelectorExpr"){let p=l.firstChild,u=l.getChild("FieldName");if(p?.type.name==="VariableName"&&u){let g=e.slice(p.from,p.to),h=r.get(g);if(h){let k=e.slice(u.from,u.to);n.push({from:a,to:k,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=Sr(o.node,e);s(a,l?`${l}.${c}`:c)}}while(o.next());return n}function is(t,e){for(let r of t.split(/[\s,&|!()]+/)){let n=r.trim();n&&n!=="ignore"&&e.add(n)}}var ps=d(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 Za(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 ec(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 Za(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 tc=new Set(["first_line","first_column","last_line","last_column","line","column"]);function rc(t,e){let r=t.constructor?.name||t.type;if(r==="Import"){let n=t.right?.value;if(typeof n=="string"){let s=_(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=_(s);return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:P(o),type:"require"}}}}return null}function kr(t,e,r){if(!t||typeof t!="object")return[];let n=[],s=rc(t,e);s&&n.push(s),r.push(...ec(t));for(let o in t){if(tc.has(o))continue;let i=t[o];if(!(!i||typeof i!="object"))if(Array.isArray(i))for(let a of i)n.push(...kr(a,e,r));else n.push(...kr(i,e,r))}return n}function us(t,e){let r=ne(e),n=se(t,r),s=[],o=[];try{s=kr(ps.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 fs=d(require("luaparse"));function nc(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=_(i.raw))}else if(s.type==="StringCallExpression"){let i=s.argument;i?.type==="StringLiteral"&&(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 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 oc(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 ic(t){let e=t.body,r=sc(e),n=oc(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 ms(t,e){let r=ne(e),n=se(t,r),s=[],o=[];try{let i=fs.default.parse(e);s=nc(i,t),o=ic(i)}catch{}return{imports:s,exports:o,tags:Array.from(r).map(i=>({name:i,kind:"comment-marker"})),category:n}}var ac=["http://","https://","mailto:","//"],cc="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",lc=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${cc})\\b`,"g"),gs;async function pc(){return gs??=(async()=>{let{unified:t}=await import("unified"),e=(await import("remark-parse")).default;return t().use(e)})(),gs}function uc(t){let e=t.trim();return e.length===0||e.startsWith("#")||ac.some(r=>e.startsWith(r))}function fc(t,e){let r=t.match(lc);return r?r.map(n=>({fromPath:e,toPath:"",rawSpecifier:n,isStyle:!1,type:"static"})):[]}function ds(t,e,r){if(t.type==="link"&&typeof t.url=="string"&&!uc(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(...fc(t.value,e)),Array.isArray(t.children))for(let n of t.children)ds(n,e,r)}async function hs(t,e){let n=(await pc()).parse(e),s=[];ds(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 xs=d(require("path")),bs=require("@lezer/python");function mc(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 gc(t){let e=0;function r(n,s){let o=n.type.name;if(o==="IfStatement"){let c=K(n),l=0,p=0;for(;p<c.length;){let u=c[p];if(u?.type.name==="if"||u?.type.name==="elif"){let g=l>0;e+=g?1:1+s;let h=g?s:s+1,k=c[p+1],x=c[p+2];k&&r(k,h),x&&r(x,h),l++,p+=3}else if(u?.type.name==="else"){e+=1;let g=c[p+1];g&&r(g,s+1),p+=2}else p++}return}if(o==="TryStatement"){let c=K(n),l=0;for(;l<c.length;){let p=c[l];if(p?.type.name==="except"){for(e+=1+s,l++;l<c.length&&c[l]?.type.name!=="Body";)r(c[l],s),l++;l<c.length&&(r(c[l],s),l++)}else p?.type.name==="Body"&&r(p,s),l++}return}if(o==="ForStatement"||o==="WhileStatement"){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}if((o==="ConditionalExpression"||o==="and"||o==="or")&&(e+=1),s>0&&(o==="FunctionDefinition"||o==="LambdaExpression")){e+=1+s;let c=n.firstChild;for(;c;)r(c,s+1),c=c.nextSibling;return}let a=n.firstChild;for(;a;)r(a,s),a=a.nextSibling}return r(t,0),e}function vr(t){return{complexity:mc(t),cognitiveComplexity:gc(t)}}function ys(t,e){let r=[];function n(i,a){let{complexity:c,cognitiveComplexity:l}=vr(i);r.push({name:a,line:ke(e,i.from),complexity:c,cognitiveComplexity:l})}function s(i){let a=i.firstChild;for(;a;)o(a),a=a.nextSibling}function o(i){if(i.type.name==="ClassDefinition"){let a=i.getChild("VariableName"),c=a?e.slice(a.from,a.to):void 0,l=i.getChild("Body");if(l){let p=l.firstChild;for(;p;){if(p.type.name==="FunctionDefinition"){let u=p.getChild("VariableName"),g=u?e.slice(u.from,u.to):void 0;g&&n(p,c?`${c}.${g}`:g),s(p)}else o(p);p=p.nextSibling}}return}if(i.type.name==="FunctionDefinition"){let a=i.getChild("VariableName");a&&n(i,e.slice(a.from,a.to)),s(i);return}s(i)}return o(t.topNode),r}var dc=new Set(["pytest","unittest","nose","hypothesis"]);function Ss(t,e){let r=[],n=[],s=new Set,o=xs.default.basename(t).toLowerCase(),i=bs.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 hc(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 x=a.node.getChild("VariableName");x&&n.push({name:e.slice(x.from,x.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=vc(o,r,s);c==="test"&&s.add("test");let{complexity:l,cognitiveComplexity:p}=vr(i.topNode),u=ys(i,e),g=c==="test"?[]:kc(i,e);return{imports:r,exports:n,tags:Array.from(s).map(h=>({name:h,kind:"comment-marker"})),category:c,rawCallEdges:g,complexity:l,cognitiveComplexity:p,...u.length>0?{functions:u}:{}}}function hc(t,e,r){let n=t.firstChild;return n?n.name==="from"?yc(t,e,r):xc(t,e,r):[]}function yc(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=bc(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[ve(r,o,i,!0)];let l=a===1?"./":"../".repeat(a-1);return c?[ve(r,l+c.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[ve(r,l.slice(0,-1),["*"],!1)]:i.map(p=>ve(r,l+p,[p],!1))}function xc(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(ve(r,o,["*"],!0))}s=s.nextSibling}return n}function bc(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 Sc(t,e){let r=new Map,n=t.cursor();do{if(n.name!=="ImportStatement")continue;let o=n.node.firstChild;if(o?.type.name!=="from")continue;let i=o.nextSibling;for(;i&&i.type.name!=="import";)i=i.nextSibling;if(!i)continue;let a=e.slice(o.to,i.from).trim(),c=0;for(;c<a.length&&a[c]===".";)c++;let l=a.slice(c),p=c<=1?"./":"../".repeat(c-1),u=i.nextSibling;for(;u;){if(u.type.name==="VariableName"){let g=e.slice(u.from,u.to),h=g;if(u.nextSibling?.type.name==="as"){let x=u.nextSibling.nextSibling;x?.type.name==="VariableName"&&(h=e.slice(x.from,x.to),u=x)}let k=c===0?a:l?p+l.replace(/\./g,"/"):p+g;r.set(h,k)}u=u.nextSibling}}while(n.next());return r}function kc(t,e){let r=Sc(t,e),n=[];function s(a,c){if(a.type.name==="CallExpression"&&a.firstChild?.type.name==="VariableName"){let p=a.firstChild,u=e.slice(p.from,p.to),g=r.get(u);g&&n.push({from:c,to:u,toSpecifier:g})}let l=a.firstChild;for(;l;)s(l,c),l=l.nextSibling}function o(a){let c=a.firstChild;for(;c;)i(c),c=c.nextSibling}function i(a){if(a.type.name==="ClassDefinition"){let c=a.getChild("VariableName"),l=c?e.slice(c.from,c.to):void 0,p=a.getChild("Body");if(p){let u=p.firstChild;for(;u;){if(u.type.name==="FunctionDefinition"){let g=u.getChild("VariableName"),h=g?e.slice(g.from,g.to):void 0;h&&s(u,l?`${l}.${h}`:h)}else i(u);u=u.nextSibling}}return}if(a.type.name==="FunctionDefinition"){let c=a.getChild("VariableName");c&&s(a,e.slice(c.from,c.to));return}o(a)}return i(t.topNode),n}function ve(t,e,r,n){return{fromPath:t,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:n,type:"static",symbols:r.length>0?r:void 0}}function vc(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=>dc.has(n.rawSpecifier))?"test":"logic"}var Fr=d(require("path")),m=d(require("typescript"));var b=d(require("typescript"));function Cc(t){let e=1;function r(n){switch(n.kind){case b.default.SyntaxKind.IfStatement:case b.default.SyntaxKind.ConditionalExpression:case b.default.SyntaxKind.ForStatement:case b.default.SyntaxKind.ForInStatement:case b.default.SyntaxKind.ForOfStatement:case b.default.SyntaxKind.WhileStatement:case b.default.SyntaxKind.DoStatement:case b.default.SyntaxKind.CatchClause:case b.default.SyntaxKind.CaseClause:e++;break;case b.default.SyntaxKind.BinaryExpression:{let s=n.operatorToken.kind;(s===b.default.SyntaxKind.AmpersandAmpersandToken||s===b.default.SyntaxKind.BarBarToken||s===b.default.SyntaxKind.QuestionQuestionToken)&&e++;break}}b.default.forEachChild(n,r)}return r(t),e}function wc(t){let e=0;function r(n,s,o){if(b.default.isIfStatement(n)){e+=o?1:1+s;let a=o?s:s+1;r(n.expression,a,!1),r(n.thenStatement,a,!1),n.elseStatement&&(b.default.isIfStatement(n.elseStatement)?r(n.elseStatement,s,!0):(e+=1,r(n.elseStatement,s+1,!1)));return}if(b.default.isForStatement(n)||b.default.isForInStatement(n)||b.default.isForOfStatement(n)||b.default.isWhileStatement(n)||b.default.isDoStatement(n)||b.default.isSwitchStatement(n)){e+=1+s,b.default.forEachChild(n,a=>r(a,s+1,!1));return}if(b.default.isCatchClause(n)){e+=1+s,b.default.forEachChild(n,a=>r(a,s,!1));return}if(b.default.isConditionalExpression(n)&&(e+=1),b.default.isBinaryExpression(n)){let a=n.operatorToken.kind;(a===b.default.SyntaxKind.AmpersandAmpersandToken||a===b.default.SyntaxKind.BarBarToken||a===b.default.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(s>0&&(b.default.isFunctionDeclaration(n)||b.default.isFunctionExpression(n)||b.default.isArrowFunction(n))){e+=1+s,b.default.forEachChild(n,a=>r(a,s+1,!1));return}b.default.forEachChild(n,a=>r(a,s,!1))}return r(t,0,!1),e}function Cr(t){return{complexity:Cc(t),cognitiveComplexity:wc(t)}}var w=d(require("typescript")),wr=new Set(["test","describe","it"]);function ks(t,e){Fc(t,e),Ec(t,e),Ac(t,e),Pc(t,e)}function Fc(t,e){if((w.default.isFunctionDeclaration(t)||w.default.isVariableDeclaration(t))&&t.name&&w.default.isIdentifier(t.name)&&Tc(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 Tc(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 Ec(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 Ac(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 Pc(t,e){if(w.default.isCallExpression(t)&&Nc(t.expression))for(let r of t.arguments)w.default.isObjectLiteralExpression(r)&&Ic(r,e)}function Nc(t){return w.default.isIdentifier(t)?wr.has(t.text):!!(w.default.isPropertyAccessExpression(t)&&(wr.has(t.name.text)||w.default.isIdentifier(t.expression)&&wr.has(t.expression.text)))}function Ic(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 Tr(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=x=>{Lc(x,a),m.default.forEachChild(x,c)};c(i);let l=Jc(t,a);(l==="test"||l==="barrel")&&o.add({name:l,kind:"comment-marker"}),l!=="test"&&Hc(a,i);let p=i.statements[0],u=p?Cs(p):void 0,{complexity:g,cognitiveComplexity:h}=Cr(i),k=Dc(i);return{imports:n,exports:Array.from(s.values()),tags:Array.from(o),category:l,rawCallEdges:a.rawCallEdges??[],complexity:g,cognitiveComplexity:h,...k.length>0?{functions:k}:{},...u!==void 0?{description:u}:{}}}function Dc(t){let e=[],r=(s,o)=>{let{complexity:i,cognitiveComplexity:a}=Cr(o),c=t.getLineAndCharacterOfPosition(o.getStart(t)).line+1;e.push({name:s,line:c,complexity:i,cognitiveComplexity:a})},n=(s,o)=>{if(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 vs(t,e,r,n){let s={name:t},o=Cs(r);o!==void 0&&(s.doc=o);let i=Mc(e);i!==void 0&&(s.flags=i);let a=Rc(e,n);return a!==void 0&&(s.signature=a),s}function Cs(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 Mc(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 Rc(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 Lc(t,e){Gc(t,e),_c(t,e),jc(t,e),zc(t,e),Kc(t,e),ks(t,e)}function Gc(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)||Er(n)).length}function _c(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)&&!Oc(t)&&(e.hasTypesOnly=!1)}function Oc(t){return t.isTypeOnly?!0:!t.exportClause||!m.default.isNamedExports(t.exportClause)?!1:t.exportClause.elements.every(e=>e.isTypeOnly)}function jc(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 zc(t,e){m.default.isExportDeclaration(t)?Wc(t,e):m.default.isExportAssignment(t)?e.exports.set("default",{name:"default"}):Er(t)&&Uc(t,e)}function Wc(t,e){if(t.moduleSpecifier&&m.default.isStringLiteral(t.moduleSpecifier))$c(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 $c(t,e,r){let n=Bc(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 Bc(t){return t.exportClause?m.default.isNamedExports(t.exportClause)?t.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Uc(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,vs(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,vs(s,n,t,e.sourceFile))}}}function Kc(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 Jc(t,e){let r=Fr.default.basename(t).toLowerCase(),n=Fr.default.extname(t).toLowerCase();return ce().some(o=>r.includes(o))?"test":Or(r)?"config":e.imports.some(o=>dt().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>yt()?"barrel":"logic"}function Er(t){return m.default.canHaveModifiers(t)&&m.default.getModifiers(t)?.some(e=>e.kind===m.default.SyntaxKind.ExportKeyword)===!0}function Hc(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=Qc(s);if(o){let i=qc(s);i&&at(i,o,n,r);continue}m.default.isClassDeclaration(s)&&s.name&&Vc(s,s.name.text,n,r)}}function Vc(t,e,r,n){for(let s of t.members)m.default.isMethodDeclaration(s)&&s.body&&m.default.isIdentifier(s.name)?at(s.body,`${e}.${s.name.text}`,r,n):m.default.isConstructorDeclaration(s)&&s.body&&at(s.body,`${e}.constructor`,r,n)}function Qc(t){if(Er(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 qc(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 at(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=>at(s,e,r,n))}function ct(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 ws(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 Fs(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 Ce(t,e){let r=G(t);if(r==="stylus"){let o=ws(e,t);return{imports:o,exports:[],tags:[],category:Fs(e,o)}}if(r==="scss"){let{imports:o,root:i,exports:a,tags:c}=je(e,t);return{imports:o,exports:a,tags:c,category:ct(i,o)}}if(r==="less"){let{imports:o,root:i,exports:a,tags:c}=Oe(e,t);return{imports:o,exports:a,tags:c,category:ct(i,o)}}let{imports:n,root:s}=_e(e,t);return{imports:n,exports:[],tags:[],category:ct(s,n)}}for(let[t,e]of[["javascript",(r,n)=>Tr(r,n,"javascript")],["typescript",(r,n)=>Tr(r,n,"typescript")],["css",Ce],["scss",Ce],["less",Ce],["stylus",Ce],["coffeescript",ns],["livescript",us],["lua",ms],["python",Ss],["go",ls],["gherkin",br],["markdown",hs]])re(t,e);async function Ts(t,e){let r=G(t),n=Rn(r);return n?n(t,e):{imports:[],exports:[],tags:[],category:"other"}}var Ar=d(require("path"));function Yc(t,e){let r=e.get(t.path);r!==void 0&&(t.coveragePct=r)}function As(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 Xc(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 Zc(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 Es(t){return Math.round(t*1e4)/1e4}function el(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=Es(Math.min(1,o)),r.push(n.exportUsageRatio)}r.length>0&&(t.avgExportUsage=Es(r.reduce((n,s)=>n+s,0)/r.length),t.maxExportUsage=Math.max(...r))}function Pr(t,e,r){e&&(t.some(n=>n.name===e&&n.kind===r)||t.push({name:e,kind:r}))}function tl(t,e){let r=e.toPath,n=Ar.default.basename(r,Ar.default.extname(r)).replace(/\.(test|spec)$/,"");Pr(t.tags,n,"import")}function rl(t,e){if(!(!e.symbols||e.symbols.includes("*")))for(let r of e.symbols)Pr(t.tags,r,"import")}function nl(t,e,r){let n=r.get(e.toPath);if(!(!n||n.category==="test"))for(let s of n.tags)s.kind==="comment-marker"&&Pr(t.tags,s.name,"comment-marker")}function sl(t,e,r){!e.toPath||e.isExternal||(tl(t,e),rl(t,e),nl(t,e,r))}function Ps(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(el(r,t),e.size>0&&Yc(r,e),r.category==="test")for(let n of r.imports)Xc(r,n,t),sl(r,n,t);Zc(r,t)}}var Pe=d(require("fs")),M=d(require("path"));var Nr=d(require("fs")),H=d(require("path")),we=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 Is(a);if(r!==o&&!r.startsWith(`${o}/`))return null;let c=r.slice(o.length).replace(/^\//,"");return c?Is(H.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=Nr.default.readFileSync(H.default.join(e,"go.mod"),"utf-8"),o=ol(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 H.default.join(o,i)}}}};function ol(t,e){let r=t.split(`
29
+ `),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("=>")){Ns(a,e,s);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&Ns(a.replace(/^replace\s+/,""),e,s)}return{mod:n,replaces:s}}function Ns(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=H.default.isAbsolute(s)?s:H.default.resolve(e,s);r.set(o,i)}function Is(t){let e;try{e=Nr.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:H.default.join(t,n.name),isExternal:!1})).sort((n,s)=>n.path.localeCompare(s.path));return r.length>0?r:null}var Ds=d(require("fs")),lt=d(require("path")),Fe=class{extensions=[".lua"];resolve(e,r,n,s){let o=r.replace(/\./g,lt.default.sep),i=[n,lt.default.join(n,"lib")];for(let a of i){if(!Ds.default.existsSync(a))continue;let c=s(lt.default.join(a,"_dummy.lua"),o);if(c)return[c]}return null}};var Ms=d(require("path")),Te=class{extensions=[".md",".mdx"];resolve(e,r,n,s){let o=s(Ms.default.join(n,"_dummy"),`./${r}`);return o?[o]:null}};var Ls=d(require("fs")),pt=d(require("path")),Ee=class{extensions=[".py"];resolve(e,r,n,s){let o=r.replace(/\./g,pt.default.sep),i=pt.default.join(n,`${o}.py`);if(Rs(i))return[{path:i,isExternal:!1}];let a=pt.default.join(n,o,"__init__.py");return Rs(a)?[{path:a,isExternal:!1}]:null}};function Rs(t){try{return Ls.default.statSync(t,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}var Ir=d(require("path")),il=["~","http://","https://","//","data:","sass:"],Ae=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,r,n,s){if(il.some(p=>r.startsWith(p)))return null;let o=s(e,r);if(o)return[o];let i=Ir.default.dirname(r),a=Ir.default.basename(r),c=i==="."?`_${a}`:`${i}/_${a}`,l=s(e,c);return l?[l]:null}};var V=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 Ee,new Fe,new we,new Ae,new Te]}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`${M.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=M.default.dirname(e),s=r.startsWith("/")?r:M.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=M.default.join(e,`index${r}`);if(this.isFile(o))return{path:o,isExternal:n};if(r===".py"){let i=M.default.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:n}}return null}isFile(e){try{return Pe.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=M.default.join(r,"tsconfig.json");if(Pe.default.existsSync(n))try{let o=JSON.parse(Pe.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=M.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=M.default.join(n,a);try{if(Pe.default.statSync(c,{throwIfNoEntry:!1})?.isFile())return{...o,path:c}}catch{}}return{...o,path:n}}let i=this.resolveLocalPath(M.default.join(n,"_dummy"),s.slice(1));return i?{...o,path:i.path}:null}return null}};var al=["tests","test","__tests__","specs","spec"],Gs=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),cl=600;function ll(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 Ne=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 V(e),this.lockFile=qr(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=Zn(this.rootDir));try{for(let n of r)this.enqueue(n);return await this.drain(),await this.processTestFiles(ll(r,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
30
30
  Done. Total processed: ${this.visited.size} nodes.
31
- `),Ts(this.graph.nodes),Cs(this.graph.nodes),Es(this.graph.nodes),Fs(this.graph.nodes),this.coverageMap.size>0&&vs(this.graph.nodes,this.coverageMap),new R(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)))try{let n=A.default.join(__dirname,"parse-worker.js");this.pool=new Gs.default({filename:n,...e.maxThreads!==void 0?{maxThreads:e.maxThreads}:{}})}catch(n){process.stderr.write(`
31
+ `),Ps(this.graph.nodes,this.coverageMap),new R(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??cl;if(!(r>0&&!this.hasAtLeastFiles(this.rootDir,r)))try{let n=E.default.join(__dirname,"parse-worker.js");this.pool=new _s.default({filename:n,...e.maxThreads!==void 0?{maxThreads:e.maxThreads}:{}})}catch(n){process.stderr.write(`
32
32
  Warning: failed to start parse worker pool, falling back to synchronous parsing: ${n}
33
- `),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=se.default.readdirSync(o,{withFileTypes:!0})}catch{continue}for(let a of i)if(a.isDirectory())Rs.has(a.name)||s.push(A.default.join(o,a.name));else if(a.isFile()&&(n++,n>=r))return!0}return n>=r}async processTestFiles(e){let r=ae(),n=o=>r.some(i=>o.name.includes(i));this.walkProject(e,n);let s=e;for(;s!==this.rootDir;){let o=A.default.dirname(s);if(o===s)break;for(let i of rl){let a=A.default.join(o,i);try{se.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=se.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let o=A.default.join(e,s.name);s.isDirectory()?Rs.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=se.default.statSync(e,{throwIfNoEntry:!1});if(!r?.isFile())return;let n=A.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=se.default.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
33
+ `),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=ie.default.readdirSync(o,{withFileTypes:!0})}catch{continue}for(let a of i)if(a.isDirectory())Gs.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=ce(),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 al){let a=E.default.join(o,i);try{ie.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=ie.default.readdirSync(e,{withFileTypes:!0})}catch{return}for(let s of n){let o=E.default.join(e,s.name);s.isDirectory()?Gs.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=ie.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),As(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=ie.default.readFileSync(e,"utf-8");try{return await this.parseContent(e,n)}catch(s){return process.stderr.write(`
34
34
  Warning: failed to parse ${r}: ${s}
35
- `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):bs(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:A.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:g,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}:{},...g!==void 0?{cognitiveComplexity:g}:{},...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:A.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 Ls(t,e){return{identifier:e?.identifier??new rt,featureMap:e?.featureDetection===!1?new Map:W(t.nodes,e?.featureDetection??void 0)}}function _s(t,e,r,n,s){for(let o of e){let i=t.nodes.get(o);if(!i)continue;let a=new z(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 Ir(t,e,r){let{identifier:n,featureMap:s}=Ls(t,r),o=new Set;for(let i of e){let a=s.get(i);a&&o.add(a.tag)}return _s(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 Mr(t,e,r){let{identifier:n,featureMap:s}=Ls(t,r),o=new Set;return _s(t,e,s,()=>{},i=>{n.isTestNode(i)&&o.add(i.path)}),Array.from(o)}var Os=d(require("fs")),oe=d(require("path"));async function js(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},o=oe.default.resolve(t);return await new Ne(o,r,n.pathAliases?new H(o,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function Ws(t,e={}){let r=oe.default.resolve(t),n=ye(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 xe(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 Ne(r,null,new H(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 zs(t,e={}){let r=[],n=new Set([...e.ignoreDirs??j,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??kt,...e.additionalExtensions??[]]);function o(i){try{let a=Os.default.readdirSync(i,{withFileTypes:!0});for(let c of a){let l=oe.default.join(i,c.name);c.isDirectory()?n.has(c.name)||o(l):c.isFile()&&s.has(oe.default.extname(c.name).toLowerCase())&&r.push(oe.default.relative(t,l))}}catch{}}return o(t),r}var Bs=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;var pt=class{graphs=new Map;configs=new Map;workspaceGraphs=new Map;changeImpactCaches=new Map;dirtyRoots=new Set;watchers=new Map;lastAnalyze=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=await js(e,r,this.graphs.get(e)??null,{...Y(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 Ws(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=At(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=$s.default.watch(e,{recursive:!0},(n,s)=>{!s||Bs.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,Y(r))}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),r}};var Q=d(require("path"));var Us=d(require("fs")),Ks=d(require("os")),ut=d(require("path"));function w(t){return{content:[{type:"text",text:JSON.stringify(t,null,2)}]}}function Js(t){if(!ut.default.isAbsolute(t))throw new Error("root must be an absolute path");let e=ut.default.resolve(t),r=Ks.default.homedir();if(e!==r&&!e.startsWith(r+ut.default.sep))throw new Error("root must be within the user home directory");let n;try{n=Us.default.statSync(e)}catch{throw new Error("root does not exist")}if(!n.isDirectory())throw new Error("root is not a directory")}async function Vs(t,e){let{root:r,entryPoints:n}=e;if(!t.isConfigured(r)){let g=ce(r,{allowJs:!1});bt(g),t.storeConfig(r,g)}if(n.length===0){let g=ye(r);if(g.type!=="none"){let h=t.getConfig(r),S=await t.getOrBuildWorkspace(r,Y(h));t.storeLastAnalyze(r,{kind:"workspace"}),t.startWatching(r);let y=Array.from(S.packages.values()).map(({graph:b,pkg:x})=>({package:x.name,relativeRoot:x.relativeRoot,nodeCount:b.nodes.size}));return w({monorepoType:g.type,packageCount:S.packages.size,packages:y})}}let s=n.map(g=>Q.default.resolve(r,g)),o=t.getConfig(r),i=o?.coverageReportPath?wt(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((g,h)=>(g[h.category]=(g[h.category]??0)+1,g),{}),p=a.findCycles(),f=_t(a);return w({nodeCount:c.nodes.length,categories:l,cycles:p,languageCoverage:f})}async function Hs(t,e){let{root:r,file:n,depth:s=1,withMeta:o=!1}=e,i=await t.ensureFresh(r),a=Ot(i,n,s),c=o?a.map(l=>({...l,...ge(i,l.path)})):a;return w({file:n,dependencies:c})}async function Qs(t,e){let{root:r,file:n,withMeta:s=!1}=e,o=await t.ensureFresh(r),i=de(o,n),a=s?i.map(c=>({...c,...ge(o,c.path)})):i;return w({file:n,dependents:a})}async function qs(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=g=>a?g.map(h=>({path:h,...ge(c,h)})):g;if(o){let g=t.getOrBuildChangeImpact(r),h=Nt(g,n),S=s?h.filter(b=>c.nodes.get(b)?.category==="test"):h,y=l(S);return w({file:n,affected:y,count:y.length})}let p=jt(c,n,{testsOnly:s,changedSymbols:i}),f=l(p);return w({file:n,affected:f,count:f.length})}async function Ys(t,e){let{root:r,file:n,depth:s=1,withEdgeDetail:o=!1}=e,i=await t.ensureFresh(r),a=Wt(i,n,{depth:s,withEdgeDetail:o});return w({file:n,callers:a,count:a.length})}async function Xs(t,e){let{root:r,entryPoints:n}=e,s=n?await t.getOrBuild(r,n.map(a=>Q.default.resolve(r,a))):await t.ensureFresh(r),o=zs(r),i=s.findUnusedFiles(o);return w({unusedFiles:i,count:i.length})}async function Zs(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 w({tags:o,count:o.length})}async function eo(t,e){let{root:r,coverageThreshold:n}=e,s=await t.ensureFresh(r),o=t.getConfig(r),i=n??o?.coverageThreshold??80;if(!Ut(s))return w({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 w({threshold:i,uncovered:a,count:a.length})}async function to(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 w({staleDocs:s,count:s.length})}async function ro(t,e){let{root:r,metric:n="cognitiveComplexity",threshold:s=10,limit:o=20}=e,i=await t.ensureFresh(r),a=zt(i,{metric:n,threshold:s,limit:o});return w({metric:n,threshold:s,functions:a,count:a.length})}async function no(t,e){let{root:r,minLines:n=6,ignoreLiterals:s=!0,maxPunctuationRatio:o=.5,maxBucketSize:i,limit:a=50}=e,c=await t.ensureFresh(r),l=e.ignoreDirs??[...j,...t.getConfig(r)?.ignoreDirs??[]],{groups:p,skippedBuckets:f}=await Lt(c,r,{minLines:n,ignoreLiterals:s,maxPunctuationRatio:o,maxBucketSize:i,limit:a,ignoreDirs:l});return w({minLines:n,groups:p,count:p.length,skippedBuckets:f})}async function so(t,e){let{root:r,changedFiles:n,featureThreshold:s,format:o="tags"}=e,i=await t.ensureFresh(r),a=n??new st().getChangedFiles().map(p=>Q.default.relative(r,Q.default.resolve(r,p))),c=s!==void 0?{featureDetection:{minOutDegree:s}}:void 0;if(o==="paths"){let p=Mr(i,a,c);return w({changedFiles:a,affectedTests:p,count:p.length})}let l=Ir(i,a,c);return w({changedFiles:a,proposedTags:l})}async function oo(t,e){let{root:r,entryPoints:n,featureThreshold:s}=e,o=n?await t.getOrBuild(r,n.map(c=>Q.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 w({features:a,count:a.length})}async function io(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=>Q.default.resolve(r,l))):await t.ensureFresh(r),c=Ke(a.serialize(),Je(s));return o?w(Le.serialize(R.deserialize(c))):i?w(Bt(c)):w(c)}async function ao(t,e){let{root:r}=e,n=await t.ensureFreshWorkspace(r);return w($t(n))}async function co(t,e){let{root:r,file:n}=e,o=(await t.ensureFreshWorkspace(r)).getAffectedAcrossPackages(n);return w({file:n,affected:o,count:o.length})}function lo(t,e){let{root:r}=e,n=t.invalidate(r);return w({root:r,cleared:n,message:n?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function po(t,e){let{root:r,type:n}=e,s=await t.ensureFresh(r),o=Vt(s);if(n)return w(Ht(o,n));let i=Array.from(o.types.values());return w({count:i.length,types:i})}async function uo(t,e){let{root:r,paths:n,minOutDegree:s}=e,o=await t.ensureFresh(r),i=Kt(o,s!==void 0?{minOutDegree:s}:void 0);if(n?.length){let c=n.map(l=>i.get(l)).filter(Boolean);return w({count:c.length,modules:c})}let a=Array.from(i.values());return w({count:a.length,modules:a})}async function fo(t,e){let{root:r,minOutDegree:n}=e,s=await t.ensureFresh(r),o=fe(s,n!==void 0?{minOutDegree:n}:void 0),i=Object.fromEntries(o.features);return w({features:i,unassigned:o.unassigned})}async function mo(t,e){let{root:r,function:n}=e,s=await t.ensureFresh(r);return w(Pt(s,n))}async function go(t,e){let{root:r,name:n}=e,s=await t.ensureFresh(r),o=Jt(s,n);return w({name:n,matches:o,count:o.length})}async function ho(t,e){let{root:r,entryPoints:n}=e,s=await t.ensureFresh(r),o=n?.length?n:Et(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 w(Tt(s,o))}async function yo(t,e){let r=await t.ensureFresh(e.root),n=await dr(r,e.root,{dryRun:e.dryRun??!1});return w(n)}var xo=[{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. Set testsOnly=true to get only test files. Set cached=true to use a pre-computed O(1) lookup cache instead of graph traversal \u2014 faster on repeated calls for the same root. Pass changedSymbols to restrict blast-radius to files that actually import those symbols \u2014 omit to treat the whole file as changed. Set withMeta=true to get { path, category, exports } objects instead of bare path strings.",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_duplicates",description:"Find duplicated code blocks across the project, largest-first. Two matching strategies, picked per file: CSS/SCSS/Less are compared structurally by rule body \u2014 the literal, ordered property:value declarations a rule contains, independent of its selector \u2014 so a genuine copy-pasted declaration list is caught while rules that merely share shape (e.g. display:flex vs display:block) never match. Every other language mokosh parses (TypeScript/JavaScript, Python, Go, CoffeeScript, LiveScript, Lua, Gherkin, Markdown, and Stylus) runs a token-based shingle pipeline instead, partitioned by language family so matching never crosses between Stylus and code languages. Identifiers \u2014 and by default literals \u2014 are normalized before matching in the token-based path, so renamed-variable copies are still caught; blocks that are mostly object/array-literal structural punctuation (e.g. schema/object-literal boilerplate) rather than substantive shared logic are gated out. A block repeated N times across the project is reported once with N occurrences, not as separate pairs. Lock files (package-lock.json, yarn.lock, pnpm-lock.yaml) and files under an ignored directory are always excluded, even if the graph itself contains them. On large repos, tokenizing is offloaded to a worker pool and pathologically common token windows are skipped for scan-time safety (reported as skippedBuckets in the result) so the scan stays within a usable response time. Requires a prior analyze() call.",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."},maxBucketSize:{type:"number",description:"Skip a hash bucket's pairwise comparison once it holds more than this many matching locations (default: 400). Bounds worst-case scan time on large repos where a single pathologically common token window would otherwise blow up quadratically. Set a very large number 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, or path. Returns matching nodes as JSON or a Mermaid diagram. If entryPoints is omitted the cached graph from a prior 'analyze' call is used.",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 typically 85\u201395% fewer tokens than a full graph query.",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: TypeScript/JavaScript, Go, and Python get function-level callers (via call edges) \u2014 though coverage differs per language (Go only tracks package-qualified calls, Python only tracks bare calls to `from module import name` symbols); everything else (CoffeeScript, LiveScript, Lua, Gherkin, Markdown, CSS/SCSS/Stylus) falls back to whole-file dependents, which is import-level only \u2014 a listed importer might not even use this specific export. Files whose parser never records exports (CoffeeScript, LiveScript, Lua, Gherkin, Markdown, CSS/SCSS/Stylus) never appear as matches, so a name that only exists in one of those returns an empty result, same as a typo. Each match's `precision` field is 'call' | 'file-level' \u2014 check it before trusting caller/importer results as symbol-exact.",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. Expands export* chains so every symbol accessible to consumers is listed (not just those directly declared in the entry file). Each export is resolved to its defining file and tagged with a kind (function/class/interface/type/enum/const). The graph is partitioned into: internalFiles (implementation reachable from entry points), unreachableFromEntry (non-test files not reachable from any entry point \u2014 may be separate consumers like CLI/MCP, config, or dead code), and testFiles (test suite). Supports multiple public entry points for libraries with sub-path exports. Requires a prior analyze() call. When entryPoints is omitted, auto-detects all entry points from package.json exports/main/module.",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. Tags of kind 'import' (filename-derived) and 'comment-marker' (domain semantic, propagated from source files) are written as an idempotent block. Re-running is safe: the existing block is replaced in place. Tags already present in the file are excluded from the block to avoid duplication. Supports TypeScript/JavaScript (// <mokosh-tags> block with // @tag lines) and Gherkin .feature files (# <mokosh-tags> block with @tagname lines). Use dryRun=true to preview changes without writing to disk. Requires a prior analyze() call.",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 mt(){let t=new pt,e=new So.Server({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(ft.ListToolsRequestSchema,async()=>({tools:xo})),e.setRequestHandler(ft.CallToolRequestSchema,async r=>{let{name:n,arguments:s}=r.params,o=s,a={analyze:c=>Vs(t,c),get_dependencies:c=>Hs(t,c),get_dependents:c=>Qs(t,c),get_affected:c=>qs(t,c),get_callers:c=>Ys(t,c),find_symbol:c=>go(t,c),find_unused:c=>Xs(t,c),find_uncovered:c=>eo(t,c),list_tags:c=>Zs(t,c),check_doc_drift:c=>to(t,c),find_complex_functions:c=>ro(t,c),find_duplicates:c=>no(t,c),propose_tags:c=>so(t,c),detect_features:c=>oo(t,c),get_type_graph:c=>po(t,c),get_module_responsibility:c=>uo(t,c),get_feature_graph:c=>fo(t,c),get_call_graph:c=>mo(t,c),get_api_surface:c=>ho(t,c),query:c=>io(t,c),get_workspace_packages:c=>ao(t,c),get_workspace_affected:c=>co(t,c),clear_cache:c=>lo(t,c),apply_tags:c=>yo(t,c)}[n];if(!a)throw new Error(`Unknown tool: ${n}`);try{return Js(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 ol(){let t=mt(),e=new bo.StdioServerTransport;await t.connect(e)}ol().catch(console.error);0&&(module.exports={createMcpServer});
35
+ `),null}}parseContent(e,r){return this.pool?this.pool.run({filePath:e,content:r}):Ts(e,r)}makeStubNode(e,r,n){return{path:r,type:G(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:u,cognitiveComplexity:g,functions:h}=s;return{path:r,type:G(e),category:l,imports:i,exports:a,tags:c,mtime:n.mtimeMs,size:n.size,...p!==void 0?{description:p}:{},...o.length>0?{callEdges:o}:{},...u!==void 0?{complexity:u}:{},...g!==void 0?{cognitiveComplexity:g}:{},...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 Os(t,e){return{identifier:e?.identifier??new nt,featureMap:e?.featureDetection===!1?new Map:z(t.nodes,e?.featureDetection??void 0)}}function js(t,e,r,n,s){for(let o of e){let i=t.nodes.get(o);if(!i)continue;let a=new W(o,["*",...i.exports.map(c=>c.name)]);t.traverse(o,(c,l,p)=>{if(!p)return!0;if(!a.updateAffectedSymbols(c,p))return!1;if(l>0){let u=r.get(c.path);if(u)return n(u),!1}return s(c),!0},{direction:"incoming"})}}function Dr(t,e,r){let{identifier:n,featureMap:s}=Os(t,r),o=new Set;for(let i of e){let a=s.get(i);a&&o.add(a.tag)}return js(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 Mr(t,e,r){let{identifier:n,featureMap:s}=Os(t,r),o=new Set;return js(t,e,s,()=>{},i=>{n.isTestNode(i)&&o.add(i.path)}),Array.from(o)}var zs=d(require("fs")),ae=d(require("path"));async function Ws(t,e,r=null,n={}){let s=n.silent?void 0:a=>{process.stderr.write(`Processed ${a} files...\r`)},o=ae.default.resolve(t);return await new Ne(o,r,n.pathAliases?new V(o,{pathAliases:n.pathAliases}):void 0,s,n.gitStats??!1,n.coverageMap??new Map,n.parallelParsing??!0).build(e)}async function $s(t,e={}){let r=ae.default.resolve(t),n=ye(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 xe(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 Ne(r,null,new V(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 Bs(t,e={}){let r=[],n=new Set([...e.ignoreDirs??j,...e.additionalIgnoreDirs??[]]),s=new Set([...e.extensions??vt,...e.additionalExtensions??[]]);function o(i){try{let a=zs.default.readdirSync(i,{withFileTypes:!0});for(let c of a){let l=ae.default.join(i,c.name);c.isDirectory()?n.has(c.name)||o(l):c.isFile()&&s.has(ae.default.extname(c.name).toLowerCase())&&r.push(ae.default.relative(t,l))}}catch{}}return o(t),r}var Us=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;function Ks(t){return Hs.default.join(t,St,kt)}var ut=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=await Ws(e,r,this.graphs.get(e)??null,{...Y(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 $s(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=Nt(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=Js.default.watch(e,{recursive:!0},(n,s)=>{!s||Us.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,Y(r))}async getDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);return r||(r=ze(Ks(e)),this.duplicationTokenCaches.set(e,r)),r}flushDuplicationTokenCache(e){let r=this.duplicationTokenCaches.get(e);if(r)try{We(r,Ks(e))}catch(n){process.stderr.write(`Warning: failed to persist duplication token cache: ${n}
36
+ `)}}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 Q=d(require("path"));var Vs=d(require("fs")),Qs=d(require("os")),ft=d(require("path"));function S(t){return{content:[{type:"text",text:JSON.stringify(t,null,2)}]}}function qs(t){if(!ft.default.isAbsolute(t))throw new Error("root must be an absolute path");let e=ft.default.resolve(t),r=Qs.default.homedir();if(e!==r&&!e.startsWith(r+ft.default.sep))throw new Error("root must be within the user home directory");let n;try{n=Vs.default.statSync(e)}catch{throw new Error("root does not exist")}if(!n.isDirectory())throw new Error("root is not a directory")}async function Ys(t,e){let{root:r,entryPoints:n}=e;if(!t.isConfigured(r)){let g=le(r,{allowJs:!1});bt(g),t.storeConfig(r,g)}if(n.length===0){let g=ye(r);if(g.type!=="none"){let h=t.getConfig(r),k=await t.getOrBuildWorkspace(r,Y(h));t.storeLastAnalyze(r,{kind:"workspace"}),t.startWatching(r);let x=Array.from(k.packages.values()).map(({graph:y,pkg:C})=>({package:C.name,relativeRoot:C.relativeRoot,nodeCount:y.nodes.size}));return S({monorepoType:g.type,packageCount:k.packages.size,packages:x})}}let s=n.map(g=>Q.default.resolve(r,g)),o=t.getConfig(r),i=o?.coverageReportPath?wt(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((g,h)=>(g[h.category]=(g[h.category]??0)+1,g),{}),p=a.findCycles(),u=Ot(a);return S({nodeCount:c.nodes.length,categories:l,cycles:p,languageCoverage:u})}async function Xs(t,e){let{root:r,file:n,depth:s=1,withMeta:o=!1}=e,i=await t.ensureFresh(r),a=jt(i,n,s),c=o?a.map(l=>({...l,...ge(i,l.path)})):a;return S({file:n,dependencies:c})}async function Zs(t,e){let{root:r,file:n,withMeta:s=!1}=e,o=await t.ensureFresh(r),i=de(o,n),a=s?i.map(c=>({...c,...ge(o,c.path)})):i;return S({file:n,dependents:a})}async function eo(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=g=>a?g.map(h=>({path:h,...ge(c,h)})):g;if(o){let g=t.getOrBuildChangeImpact(r),h=It(g,n),k=s?h.filter(y=>c.nodes.get(y)?.category==="test"):h,x=l(k);return S({file:n,affected:x,count:x.length})}let p=zt(c,n,{testsOnly:s,changedSymbols:i}),u=l(p);return S({file:n,affected:u,count:u.length})}async function to(t,e){let{root:r,file:n,depth:s=1,withEdgeDetail:o=!1}=e,i=await t.ensureFresh(r),a=Wt(i,n,{depth:s,withEdgeDetail:o});return S({file:n,callers:a,count:a.length})}async function ro(t,e){let{root:r,entryPoints:n}=e,s=n?await t.getOrBuild(r,n.map(a=>Q.default.resolve(r,a))):await t.ensureFresh(r),o=Bs(r),i=s.findUnusedFiles(o);return S({unusedFiles:i,count:i.length})}async function no(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 S({tags:o,count:o.length})}async function so(t,e){let{root:r,coverageThreshold:n}=e,s=await t.ensureFresh(r),o=t.getConfig(r),i=n??o?.coverageThreshold??80;if(!Kt(s))return S({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 S({threshold:i,uncovered:a,count:a.length})}async function oo(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 S({staleDocs:s,count:s.length})}async function io(t,e){let{root:r,metric:n="cognitiveComplexity",threshold:s=10,limit:o=20}=e,i=await t.ensureFresh(r),a=$t(i,{metric:n,threshold:s,limit:o});return S({metric:n,threshold:s,functions:a,count:a.length})}async function ao(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??[...j,...t.getConfig(r)?.ignoreDirs??[]],{groups:l}=await _t(a,r,{minLines:n,ignoreLiterals:s,maxPunctuationRatio:o,limit:i,ignoreDirs:c,tokenCache:await t.getDuplicationTokenCache(r)});return t.flushDuplicationTokenCache(r),S({minLines:n,groups:l,count:l.length})}async function co(t,e){let{root:r,changedFiles:n,featureThreshold:s,format:o="tags"}=e,i=await t.ensureFresh(r),a=n??new ot().getChangedFiles().map(p=>Q.default.relative(r,Q.default.resolve(r,p))),c=s!==void 0?{featureDetection:{minOutDegree:s}}:void 0;if(o==="paths"){let p=Mr(i,a,c);return S({changedFiles:a,affectedTests:p,count:p.length})}let l=Dr(i,a,c);return S({changedFiles:a,proposedTags:l})}async function lo(t,e){let{root:r,entryPoints:n,featureThreshold:s}=e,o=n?await t.getOrBuild(r,n.map(c=>Q.default.resolve(r,c))):await t.ensureFresh(r),i=z(o.nodes,s!==void 0?{minOutDegree:s}:void 0),a=Array.from(i.values()).sort((c,l)=>l.outDegree-c.outDegree);return S({features:a,count:a.length})}async function po(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=>Q.default.resolve(r,l))):await t.ensureFresh(r),c=Je(a.serialize(),He(s));return o?S(Ge.serialize(R.deserialize(c))):i?S(Bt(c)):S(c)}async function uo(t,e){let{root:r}=e,n=await t.ensureFreshWorkspace(r);return S(Ut(n))}async function fo(t,e){let{root:r,file:n}=e,o=(await t.ensureFreshWorkspace(r)).getAffectedAcrossPackages(n);return S({file:n,affected:o,count:o.length})}function mo(t,e){let{root:r}=e,n=t.invalidate(r);return S({root:r,cleared:n,message:n?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function go(t,e){let{root:r,type:n}=e,s=await t.ensureFresh(r),o=Vt(s);if(n)return S(Qt(o,n));let i=Array.from(o.types.values());return S({count:i.length,types:i})}async function ho(t,e){let{root:r,paths:n,minOutDegree:s}=e,o=await t.ensureFresh(r),i=Jt(o,s!==void 0?{minOutDegree:s}:void 0);if(n?.length){let c=n.map(l=>i.get(l)).filter(Boolean);return S({count:c.length,modules:c})}let a=Array.from(i.values());return S({count:a.length,modules:a})}async function yo(t,e){let{root:r,minOutDegree:n}=e,s=await t.ensureFresh(r),o=fe(s,n!==void 0?{minOutDegree:n}:void 0),i=Object.fromEntries(o.features);return S({features:i,unassigned:o.unassigned})}async function xo(t,e){let{root:r,function:n}=e,s=await t.ensureFresh(r);return S(Pt(s,n))}async function bo(t,e){let{root:r,name:n}=e,s=await t.ensureFresh(r),o=Ht(s,n);return S({name:n,matches:o,count:o.length})}async function So(t,e){let{root:r,entryPoints:n}=e,s=await t.ensureFresh(r),o=n?.length?n:Et(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 S(At(s,o))}async function ko(t,e){let r=await t.ensureFresh(e.root),n=await hr(r,e.root,{dryRun:e.dryRun??!1});return S(n)}var vo=[{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. Set testsOnly=true to get only test files. Set cached=true to use a pre-computed O(1) lookup cache instead of graph traversal \u2014 faster on repeated calls for the same root. Pass changedSymbols to restrict blast-radius to files that actually import those symbols \u2014 omit to treat the whole file as changed. Set withMeta=true to get { path, category, exports } objects instead of bare path strings.",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_duplicates",description:"Find duplicated code blocks across the project, largest-first. Two matching strategies, picked per file: CSS/SCSS/Less are compared structurally by rule body \u2014 the literal, ordered property:value declarations a rule contains, independent of its selector \u2014 so a genuine copy-pasted declaration list is caught while rules that merely share shape (e.g. display:flex vs display:block) never match. Every other language mokosh parses (TypeScript/JavaScript, Python, Go, CoffeeScript, LiveScript, Lua, Gherkin, Markdown, and Stylus) is tokenized and matched via a suffix array over the whole candidate token stream instead, partitioned by language family so matching never crosses between Stylus and code languages \u2014 exact and complete regardless of how repetitive the repo is, with no truncation caveat. Identifiers \u2014 and by default literals \u2014 are normalized before matching in the token-based path, so renamed-variable copies are still caught; blocks that are mostly object/array-literal structural punctuation (e.g. schema/object-literal boilerplate) rather than substantive shared logic are gated out. A block repeated N times across the project is reported once with N occurrences, not as separate pairs. Lock files (package-lock.json, yarn.lock, pnpm-lock.yaml) and files under an ignored directory are always excluded, even if the graph itself contains them. On large repos, tokenizing is offloaded to a worker pool and tokenized files are cached per session, so repeated calls against an unchanged root only re-tokenize what actually changed. Requires a prior analyze() call.",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, or path. Returns matching nodes as JSON or a Mermaid diagram. If entryPoints is omitted the cached graph from a prior 'analyze' call is used.",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 typically 85\u201395% fewer tokens than a full graph query.",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: TypeScript/JavaScript, Go, and Python get function-level callers (via call edges) \u2014 though coverage differs per language (Go only tracks package-qualified calls, Python only tracks bare calls to `from module import name` symbols); everything else (CoffeeScript, LiveScript, Lua, Gherkin, Markdown, CSS/SCSS/Stylus) falls back to whole-file dependents, which is import-level only \u2014 a listed importer might not even use this specific export. Files whose parser never records exports (CoffeeScript, LiveScript, Lua, Gherkin, Markdown, CSS/SCSS/Stylus) never appear as matches, so a name that only exists in one of those returns an empty result, same as a typo. Each match's `precision` field is 'call' | 'file-level' \u2014 check it before trusting caller/importer results as symbol-exact.",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. Expands export* chains so every symbol accessible to consumers is listed (not just those directly declared in the entry file). Each export is resolved to its defining file and tagged with a kind (function/class/interface/type/enum/const). The graph is partitioned into: internalFiles (implementation reachable from entry points), unreachableFromEntry (non-test files not reachable from any entry point \u2014 may be separate consumers like CLI/MCP, config, or dead code), and testFiles (test suite). Supports multiple public entry points for libraries with sub-path exports. Requires a prior analyze() call. When entryPoints is omitted, auto-detects all entry points from package.json exports/main/module.",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. Tags of kind 'import' (filename-derived) and 'comment-marker' (domain semantic, propagated from source files) are written as an idempotent block. Re-running is safe: the existing block is replaced in place. Tags already present in the file are excluded from the block to avoid duplication. Supports TypeScript/JavaScript (// <mokosh-tags> block with // @tag lines) and Gherkin .feature files (# <mokosh-tags> block with @tagname lines). Use dryRun=true to preview changes without writing to disk. Requires a prior analyze() call.",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 gt(){let t=new ut,e=new Co.Server({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(mt.ListToolsRequestSchema,async()=>({tools:vo})),e.setRequestHandler(mt.CallToolRequestSchema,async r=>{let{name:n,arguments:s}=r.params,o=s,a={analyze:c=>Ys(t,c),get_dependencies:c=>Xs(t,c),get_dependents:c=>Zs(t,c),get_affected:c=>eo(t,c),get_callers:c=>to(t,c),find_symbol:c=>bo(t,c),find_unused:c=>ro(t,c),find_uncovered:c=>so(t,c),list_tags:c=>no(t,c),check_doc_drift:c=>oo(t,c),find_complex_functions:c=>io(t,c),find_duplicates:c=>ao(t,c),propose_tags:c=>co(t,c),detect_features:c=>lo(t,c),get_type_graph:c=>go(t,c),get_module_responsibility:c=>ho(t,c),get_feature_graph:c=>yo(t,c),get_call_graph:c=>xo(t,c),get_api_surface:c=>So(t,c),query:c=>po(t,c),get_workspace_packages:c=>uo(t,c),get_workspace_affected:c=>fo(t,c),clear_cache:c=>mo(t,c),apply_tags:c=>ko(t,c)}[n];if(!a)throw new Error(`Unknown tool: ${n}`);try{return qs(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 pl(){let t=gt(),e=new wo.StdioServerTransport;await t.connect(e)}pl().catch(console.error);0&&(module.exports={createMcpServer});
36
37
  //# sourceMappingURL=mcp.js.map