@omfalos/mokosh 0.1.5 → 0.1.6

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.mjs CHANGED
@@ -1,28 +1,30 @@
1
1
  #!/usr/bin/env node
2
- var Ge=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});import{StdioServerTransport as Qi}from"@modelcontextprotocol/sdk/server/stdio.js";import{Server as Ki}from"@modelcontextprotocol/sdk/server/index.js";import{CallToolRequestSchema as Ji,ListToolsRequestSchema as Hi}from"@modelcontextprotocol/sdk/types.js";import Bi from"fs";import Le from"fs";import jt from"path";var Gs=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Rt=[];function le(r){Rt.push(r)}function Nt(r){return[...Gs,...Rt].some(e=>typeof e=="string"?r.includes(e):e instanceof RegExp?e.test(r):e(r))}var Ds=[".test.",".spec.","-test.","-spec."],Gt=[];function ue(r){Gt.push(r)}function J(){return[...Ds,...Gt]}var _s=["jest","vitest","playwright","cypress","@testing-library/"],Dt=[];function fe(r){Dt.push(r)}function De(){return[..._s,...Dt]}var _t=.8;function _e(r){_t=r}function je(){return _t}var js=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function H(r,{allowJs:e=!0,isExplicitPath:t=!1}={}){if(t){let s=jt.resolve(r);return Le.existsSync(s)?s.endsWith(".json")?Lt(s):e?Ot(s):{}:{}}for(let s of js){let n=jt.resolve(r,s);if(Le.existsSync(n)){if(s.endsWith(".json"))return Lt(n);if(e)return Ot(n)}}return{}}function Lt(r){return JSON.parse(Le.readFileSync(r,"utf-8"))}function Ot(r){let e=Ge(r);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function Oe(r){for(let e of r.configMatchers??[])le(e);for(let e of r.testPatterns??[])ue(e);for(let e of r.testLibraries??[])fe(e);r.barrelThreshold!==void 0&&_e(r.barrelThreshold)}var We=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],ze=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature"];import Ls from"fs";import Wt from"path";function $e(r,e){let t=Wt.resolve(r,e);try{let s=Ls.readFileSync(t,"utf-8"),n=JSON.parse(s),o=new Map;for(let[i,a]of Object.entries(n)){if(i==="total")continue;let p=a?.lines?.pct;if(typeof p!="number")continue;let c=Wt.relative(r,i);o.set(c,p)}return o}catch{return new Map}}var ge={serialize(r){let e=["graph TD"],t=new Set;for(let s of r.nodes.values()){let n=`"${s.path}"`;for(let o of s.imports){if(!o.toPath)continue;let i=`"${o.toPath}"`,a=`${s.path} -> ${o.toPath}`;if(!t.has(a)){let p=o.isStyle?"-- styles -->":"-->";e.push(` ${n} ${p} ${i}`),t.add(a)}}}return e.join(`
3
- `)}};import zt from"fs";import Ws from"path";function Be(r,e){let t=r.replace(/^\.\//,"");if(e.nodes.has(t))return t;let s=t.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(s)?s:null}function $t(r,e){if(typeof r=="string")return Be(r,e);if(r&&typeof r=="object"){let t=r;for(let s of["import","require","default"]){let n=$t(t[s],e);if(n)return n}}return null}function zs(r){if(!r)return"unknown";let e=r.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 $s(r,e){let t=new Set,s=new Set,n=[...e];for(;n.length;){let o=n.shift();if(s.has(o))continue;s.add(o);let i=r.nodes.get(o);if(i){for(let a of i.exports)t.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 c=r.nodes.get(a.toPath);if(c)for(let m of c.exports)t.add(m.name);n.push(a.toPath)}else for(let c of a.symbols)t.add(c)}}}return t}function Ue(r,e){let t=[],s=Ws.join(e,"package.json");if(zt.existsSync(s))try{let n=JSON.parse(zt.readFileSync(s,"utf8"));if(n.exports&&typeof n.exports=="object"&&!Array.isArray(n.exports))for(let o of Object.values(n.exports)){let i=$t(o,r);i&&!t.includes(i)&&t.push(i)}else if(typeof n.exports=="string"){let o=Be(n.exports,r);o&&t.push(o)}if(t.length===0)for(let o of[n.main,n.module].filter(Boolean)){let i=Be(o,r);i&&!t.includes(i)&&t.push(i)}}catch{}if(t.length===0){for(let n of["src/index.ts","src/index.js","index.ts","index.js"])if(r.nodes.has(n)){t.push(n);break}}return t}function Bs(r,e){let t=new Set(e);for(let s of e)r.traverse(s,n=>(t.add(n.path),!0),{direction:"outgoing"});return t}function Us(r,e,t){let s=new Map;for(let n of e){if(t.includes(n))continue;let o=r.nodes.get(n);if(!o)continue;let i=o.category==="barrel";for(let a of o.exports){let p=s.get(a.name),c=!!(a.signature||a.doc);(!p||c&&!i)&&s.set(a.name,{file:n,symbol:a})}}return s}function qs(r,e,t,s){let n=[];for(let o of r){let i=e.get(o),a=s.flatMap(g=>t.nodes.get(g)?.exports??[]).find(g=>g.name===o),p=i?.symbol??a,c=i?.file??s.find(g=>t.nodes.get(g)?.exports.some(h=>h.name===o))??s[0],m={name:o,definedIn:c,kind:zs(p?.signature)};p?.doc&&(m.doc=p.doc),p?.signature&&(m.signature=p.signature),n.push(m)}return n.sort((o,i)=>o.name.localeCompare(i.name)),n}function Ks(r,e,t){let s=p=>r.nodes.get(p)?.category==="test",n=[...e].filter(p=>!t.includes(p)&&!s(p)),o=[...r.nodes.keys()].filter(p=>!e.has(p)),i=o.filter(p=>!s(p)),a=o.filter(p=>s(p));return{internalFiles:n,unreachableFromEntry:i,testFiles:a}}function qe(r,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let c of e)if(!r.nodes.has(c))throw new Error(`Entry point not found in graph: ${c}`);let t=Bs(r,e),s=Us(r,t,e),n=$s(r,e),o=qs(n,s,r,e),{internalFiles:i,unreachableFromEntry:a,testFiles:p}=Ks(r,t,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:p}}function Ke(r,e){let t=null,s=[];for(let o of r.nodes.values()){o.exports.some(i=>i.name===e)&&(t=o.path);for(let i of o.callEdges??[])i.to===e&&s.push({file:o.path,callerFunction:i.from})}let n=[];if(t){let o=r.nodes.get(t);for(let i of o?.callEdges??[])i.from===e&&n.push({file:i.toFile,calleeFunction:i.to})}return{functionName:e,definedIn:t,callers:s,callees:n}}import Ca from"fs";import Ea from"path";function Bt(r){let e=[...r.nodes.entries()].sort(([s],[n])=>s.localeCompare(n)).map(([s,n])=>`${s}:${n.mtime}:${n.size}`).join("|"),t=2166136261;for(let s=0;s<e.length;s++)t^=e.charCodeAt(s),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function Je(r){let e=new Map;for(let t of r.nodes.keys()){let s=[];r.traverse(t,n=>(n.path!==t&&s.push(n.path),!0),{direction:"incoming"}),e.set(t,s)}return{impact:e,graphHash:Bt(r)}}function He(r,e){return r.impact.get(e)??[]}import me from"path";function Js(r){let e=new Map;for(let[t,s]of r){let n=s.imports.filter(o=>o.toPath&&!o.isExternal).length;n>0&&e.set(t,n)}return e}function Hs(r,e,t){let s=new Map;for(let[n,o]of e){if(o<t)continue;let i=r.get(n);if(!i||i.category==="test"||i.category==="barrel")continue;let a=me.extname(n),p=me.basename(n,a),c=p==="index"?me.basename(me.dirname(n)):p;s.set(n,{path:n,outDegree:o,tag:`feature:${c}`})}return s}function R(r,e){let t=e?.minOutDegree??5;return Hs(r,Js(r),t)}var Qs=(r,e)=>r.outDegree-e.outDegree;function Vs(r,e){let t=new Map;for(let s of e.values()){let n=new Set;r.traverse(s.path,o=>(o.path!==s.path&&n.add(o.path),!0),{direction:"outgoing"}),t.set(s.path,n)}return t}function Xs(r,e,t,s){let n=new Map;for(let[o]of r){if(e.has(o))continue;let i=null;for(let a of e.values())t.get(a.path)?.has(o)&&(!i||s(a,i)<0)&&(i=a);i&&n.set(o,i.path)}return n}function Zs(r,e){let t=new Map;for(let s of r.values()){let n=s.tag.replace("feature:",""),o=[];for(let[i,a]of e)a===s.path&&o.push(i);t.set(n,{hub:s.path,outDegree:s.outDegree,files:o})}return t}function Ys(r,e,t){let s=[];for(let n of r.keys())!e.has(n)&&!t.has(n)&&s.push(n);return s}function Q(r,e){let t=e?.detectFn??R,s=e?.hubComparator??Qs,n=t(r.nodes,e),o=Vs(r,n),i=Xs(r.nodes,n,o,s);return{features:Zs(n,i),unassigned:Ys(r.nodes,n,i)}}var V=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let t=new Set(this.nodes.keys());return e.filter(s=>!t.has(s))}findHighExportUsage(e){let t=[];for(let s of this.nodes.values()){if(s.maxExportUsage===void 0||s.maxExportUsage<e)continue;let n=s.imports.reduce((o,i)=>(i.exportUsageRatio??0)>(o?.exportUsageRatio??0)?i:o,null);t.push({path:s.path,maxExportUsage:s.maxExportUsage,tightestDep:n?.toPath??""})}return t.sort((s,n)=>n.maxExportUsage-s.maxExportUsage)}findCycles(){let e=[],t=new Set,s=new Set,n=[],o=i=>{t.add(i),s.add(i),n.push(i);let a=this.nodes.get(i);if(a){for(let p of a.imports)if(!(!p.toPath||p.isExternal))if(s.has(p.toPath)){let c=n.indexOf(p.toPath);e.push([...n.slice(c),p.toPath])}else t.has(p.toPath)||o(p.toPath)}s.delete(i),n.pop()};for(let i of this.nodes.keys())t.has(i)||o(i);return e}};var T=class r{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let t=new Map;for(let s of e.nodes)t.set(s.path,s);return new r(t)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let t of this.nodes.values())for(let s of t.imports)if(s.toPath){let n=e.get(s.toPath)||[];n.push(t.path),e.set(s.toPath,n)}return this._incomingEdgesCache=e,e}dfs(e,t,s,n){let o=new Set,i=s.maxDepth??1/0,a=(p,c,m)=>{if(c>i||o.has(p))return;let g=this.nodes.get(p);if(g&&(o.add(p),t(g,c,m)!==!1))for(let h of n(p))a(h,c+1,p)};a(e,0,null)}traverse(e,t,s={}){let n=s.direction??"outgoing",o=n==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,t,s,i=>n==="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 t of this.nodes.values())for(let s of t.callEdges??[]){let n=e.get(s.toFile)??[];n.push(t.path),e.set(s.toFile,n)}return this._callIncomingCache=e,e}traverseCalls(e,t,s={}){let n=s.direction??"outgoing",o=n==="incoming"?this.getCallIncomingCache():null;this.dfs(e,t,s,i=>n==="outgoing"?this.nodes.get(i)?.callEdges?.map(a=>a.toFile)??[]:o?.get(i)??[])}getCallers(e){let t=[];return this.traverseCalls(e,s=>(s.path!==e&&t.push(s.path),!0),{direction:"incoming",maxDepth:1}),t}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let t=this.nodes.get(e);return t?t.imports.map(s=>this.nodes.get(s.toPath)).filter(s=>s!==void 0):[]}findUnusedFiles(e){return new V(this.nodes).findUnusedFiles(e)}findCycles(){return new V(this.nodes).findCycles()}};var N=class{affectedSymbols=new Map;constructor(e,t){this.affectedSymbols.set(e,new Set(["default",...t]))}updateAffectedSymbols(e,t){let s=this.affectedSymbols.get(t)||new Set,n=e.imports.find(p=>p.toPath===t);if(!n)return!1;let o=n.symbols||["*"],i=new Set;for(let p of o)(p==="*"||s.has("*")||s.has(p))&&i.add("*");if(i.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let p of i)a.add(p);return this.affectedSymbols.set(e.path,a),!0}};function Qe(r,e,t=1){let s=[];return r.traverse(e,(n,o,i)=>{if(n.path===e)return!0;let a=i?r.nodes.get(i)?.imports.find(p=>p.toPath===n.path):void 0;return s.push({path:n.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:t}),s}function Ve(r,e){let t=[];return r.traverse(e,s=>{if(s.path===e)return!0;let n=s.imports.find(o=>o.toPath===e);return t.push({path:s.path,...n?.symbols?{symbols:n.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),t}function Xe(r,e,t={}){let{testsOnly:s=!1,changedSymbols:n}=t,o=n?new N(e,n):null,i=[];return r.traverse(e,(a,p,c)=>{if(a.path===e)return!0;if(o&&c&&!o.updateAffectedSymbols(a,c))return!1;let m=a.category==="test"||a.tags.some(g=>g.name==="test");return(!s||m)&&i.push(a.path),!0},{direction:"incoming"}),i}function Ze(r,e,t={}){let{depth:s=1,withEdgeDetail:n=!1}=t,o=[];return r.traverseCalls(e,i=>{if(i.path===e)return!0;let a={file:i.path};return n&&(a.edges=(i.callEdges??[]).filter(p=>p.toFile===e).map(p=>({from:p.from,to:p.to}))),o.push(a),!0},{direction:"incoming",maxDepth:s}),o}function Ye(r,e={}){let{metric:t="cognitiveComplexity",threshold:s=10,limit:n=20}=e;return[...r.nodes.values()].flatMap(o=>(o.functions??[]).filter(i=>i[t]>=s).map(i=>({file:o.path,name:i.name,line:i.line,complexity:i.complexity,cognitiveComplexity:i.cognitiveComplexity}))).sort((o,i)=>i[t]-o[t]).slice(0,n)}function et(r){return{nodes:r.nodes.map(t=>({path:t.path,type:t.type,category:t.category,exports:t.exports.map(s=>s.name),tags:t.tags.filter(s=>s.kind==="comment-marker"||s.kind==="import").map(s=>s.name),importsFiles:t.imports.filter(s=>!s.isExternal&&s.toPath).map(s=>s.toPath),...t.description!==void 0&&{description:t.description},...t.testedBy!==void 0&&{testedBy:t.testedBy},...t.coveragePct!==void 0&&{coveragePct:t.coveragePct},...t.avgExportUsage!==void 0&&{avgExportUsage:t.avgExportUsage},...t.maxExportUsage!==void 0&&{maxExportUsage:t.maxExportUsage}})),cycles:r.cycles}}function tt(r){let e=r.getPackageDependencies(),t=Array.from(r.packages.values()).map(({graph:s,pkg:n})=>({name:n.name,relativeRoot:n.relativeRoot,nodeCount:s.nodes.size,dependsOn:e.get(n.name)??[]}));return{monorepoType:r.type,packageCount:t.length,packages:t}}function rt(r){return[...r.nodes.values()].some(e=>e.coveragePct!==void 0)}function Ut(r){if(r.category==="test")return"test";if(r.category==="config")return"config";if(r.category==="type-only")return"types";let e=r.path;return y(e,"component")||y(e,"components")?"component":y(e,"controller")||y(e,"controllers")?"controller":y(e,"middleware")?"middleware":y(e,"router")||y(e,"routes")||y(e,"route")?"router":y(e,"store")||y(e,"stores")?"store":y(e,"service")||y(e,"services")?"service":y(e,"handler")||y(e,"handlers")?"handler":y(e,"adapter")||y(e,"adapters")?"adapter":y(e,"plugin")||y(e,"plugins")?"plugin":y(e,"api")?"api":y(e,"cli")||y(e,"commands")||X(e)==="cli"?"cli":y(e,"util")||y(e,"utils")||y(e,"helper")||y(e,"helpers")?"util":y(e,"model")||y(e,"models")||X(e)==="model"?"model":y(e,"parser")||y(e,"parsers")||X(e)==="parser"?"parser":X(e)==="builder"?"builder":X(e)==="resolver"?"resolver":"other"}function y(r,e){return r.includes(`/${e}/`)||r.includes(`/${e}.`)}function X(r){let e=r.slice(r.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function st(r,e){let t=Q(r,e),s=new Map;for(let[o,i]of t.features){for(let a of i.files)s.set(a,o);s.set(i.hub,o)}let n=new Map;for(let o of r.nodes.values()){let i=s.get(o.path);n.set(o.path,{path:o.path,role:Ut(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return n}function en(r){return r?r.startsWith("interface ")?"interface":r.startsWith("class ")?"class":r.startsWith("enum ")?"enum":"type":"type"}function tn(r,e){if(e==="type-only")return!0;let t=r.signature??"";return t.startsWith("interface ")||t.startsWith("class ")||t.startsWith("enum ")}function nt(r){let e=new Map;for(let s of r.nodes.values())if(!(s.type!=="typescript"&&s.type!=="javascript"))for(let n of s.exports){if(!tn(n,s.category))continue;let o=`${s.path}::${n.name}`;e.set(o,{name:n.name,file:s.path,kind:en(n.signature),...n.doc?{doc:n.doc}:{}})}let t=[];for(let s of r.nodes.values())if(!(s.type!=="typescript"&&s.type!=="javascript")){for(let n of s.imports)if(!(!n.toPath||n.isExternal||!n.symbols?.length))for(let o of n.symbols)e.has(`${n.toPath}::${o}`)&&t.push({fromFile:s.path,toType:o,toFile:n.toPath})}return{types:e,edges:t}}function ot(r,e){let t=null;for(let o of r.types.values())if(o.name===e){t=o;break}if(!t)return{type:null,usedByFiles:[],uses:[]};let s=new Set,n=new Map;for(let o of r.edges)if(o.toType===e&&o.toFile===t.file&&s.add(o.fromFile),o.fromFile===t.file){let i=r.types.get(`${o.toFile}::${o.toType}`);i&&n.set(`${i.file}::${i.name}`,i)}return{type:t,usedByFiles:Array.from(s),uses:Array.from(n.values())}}import mn from"path";import at from"fs";import Ht from"path";import Z from"fs";import C from"path";import qt from"fs";import tp from"path";function Kt(r){try{return qt.statSync(r,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function de(r){try{return qt.statSync(r,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function it(r,e){let t=C.join(e,"package.json");if(!Z.existsSync(t))return null;let s={};try{s=JSON.parse(Z.readFileSync(t,"utf-8"))}catch{return null}let n=s.name;return n?{name:n,root:e,relativeRoot:C.relative(r,e),entryPoints:rn(e,s)}:null}function rn(r,e){let t=[];if(e.exports){let n=e.exports;if(typeof n=="string")t.push(C.join(r,n));else if(typeof n=="object"&&n!==null){let o=n["."];if(typeof o=="string")t.push(C.join(r,o));else if(typeof o=="object"&&o!==null){let i=o.import??o.require??o.default;typeof i=="string"&&t.push(C.join(r,i))}}}e.main&&t.push(C.join(r,e.main));for(let n of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])t.push(C.join(r,n));let s=t.filter(de);return s.length>0?s.slice(0,1):t.slice(0,1)}function G(r,e){let t=[],s=new Set;for(let n of e){let o=n.replace(/\/$/,"").replace(/^\.\//,"");sn(r,o,s,t)}return t}function sn(r,e,t,s){if(!e.includes("*")){nn(r,e,t,s);return}let n=e.split("/");n.includes("**")?on(r,n,t,s):an(r,n,t,s)}function nn(r,e,t,s){let n=C.join(r,e);if(t.has(n)||!Kt(n))return;t.add(n);let o=it(r,n);o&&s.push(o)}function on(r,e,t,s){let n=C.join(r,e[0]==="**"?"":e[0]??"");Jt(r,n,t,s)}function an(r,e,t,s){let n=e.findIndex(a=>a.includes("*")),o=C.join(r,...e.slice(0,n)),i;try{i=Z.readdirSync(o,{withFileTypes:!0})}catch{return}for(let a of i){if(!a.isDirectory())continue;let p=C.join(o,a.name);if(t.has(p))continue;t.add(p);let c=it(r,p);c&&s.push(c)}}function Jt(r,e,t,s){let n;try{n=Z.readdirSync(e,{withFileTypes:!0})}catch{return}for(let o of n){if(!o.isDirectory()||o.name==="node_modules"||o.name.startsWith("."))continue;let i=C.join(e,o.name);if(Z.existsSync(C.join(i,"package.json"))&&!t.has(i)){t.add(i);let a=it(r,i);a&&s.push(a)}else Jt(r,i,t,s)}}var Qt={type:"npm",detect(r){let e=Ht.join(r,"package.json");if(!at.existsSync(e))return null;let t;try{t=JSON.parse(at.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!t||at.existsSync(Ht.join(r,"yarn.lock")))return null;let s=Array.isArray(t)?t:t.packages??[];return s.length===0?null:G(r,s)}};import D from"fs";import v from"path";var Vt={type:"nx",detect(r){return D.existsSync(v.join(r,"nx.json"))?Xt(r,r,new Set,0).map(t=>pn(r,t,v.join(t,"project.json"))).filter(t=>t!==null):null}};function Xt(r,e,t,s){if(s>4)return[];let n;try{n=D.readdirSync(e,{withFileTypes:!0})}catch{return[]}let o=[];for(let i of n){if(!i.isDirectory())continue;let a=i.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let p=v.join(e,a);D.existsSync(v.join(p,"project.json"))&&!t.has(p)?(t.add(p),o.push(p)):o.push(...Xt(r,p,t,s+1))}return o}function pn(r,e,t){let s={};try{s=JSON.parse(D.readFileSync(t,"utf-8"))}catch{return null}let n=s.name,o,i,a=v.join(e,"package.json");if(D.existsSync(a))try{let p=JSON.parse(D.readFileSync(a,"utf-8"));n=p.name??n,o=p.main,i=p.exports}catch{}return n?{name:n,root:e,relativeRoot:v.relative(r,e),entryPoints:cn(e,s,o,i)}:null}function cn(r,e,t,s){let n=[],o=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(o){let a=v.resolve(r,"../..");n.push(v.resolve(a,o)),n.push(v.resolve(r,o))}if(s){let a=s;if(typeof a=="string")n.push(v.join(r,a));else if(typeof a=="object"&&a!==null){let p=a["."];typeof p=="string"&&n.push(v.join(r,p))}}if(t&&n.push(v.join(r,t)),e.sourceRoot){let a=v.resolve(r,"../.."),p=v.resolve(a,e.sourceRoot);n.push(v.join(p,"index.ts"),v.join(p,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])n.push(v.join(r,a));let i=n.filter(de);return i.length>0?i.slice(0,1):n.slice(0,1)}import Zt from"fs";import ln from"path";import un from"js-yaml";var Yt={type:"pnpm",detect(r){let e=ln.join(r,"pnpm-workspace.yaml");if(!Zt.existsSync(e))return null;let t=[];try{t=un.load(Zt.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return G(r,t)}};import fn from"fs";import gn from"path";var er={type:"turborepo",detect(r){return fn.existsSync(gn.join(r,"turbo.json"))?[]:null}};import pt from"fs";import tr from"path";var rr={type:"yarn",detect(r){if(!pt.existsSync(tr.join(r,"yarn.lock")))return null;let e=tr.join(r,"package.json");if(!pt.existsSync(e))return null;let t;try{t=JSON.parse(pt.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!t)return null;let s=Array.isArray(t)?t:t.packages??[];return s.length===0?null:G(r,s)}};var sr=[];function P(r){sr.push(r)}function nr(){return sr}P(er);P(Vt);P(Yt);P(rr);P(Qt);function Y(r,e=nr()){let t=mn.resolve(r),s=new Map,n=[];for(let i of e){let a=i.detect(t);if(a!==null){n.push(i.type);for(let p of a)s.has(p.name)||s.set(p.name,p)}}if(n.length===0)return{root:t,type:"none",types:[],packages:[],packageMap:new Map};let o=Array.from(s.values());return{root:t,type:n[0],types:n,packages:o,packageMap:new Map(o.map(i=>[i.name,i]))}}var ee=class r{constructor(e,t){this.monorepoRoot=e;this.type=t}monorepoRoot;type;packages=new Map;addPackage(e,t){this.packages.set(e.name,{graph:t,pkg:e})}getPackageForFile(e){for(let{pkg:t}of this.packages.values())if(e===t.relativeRoot||e.startsWith(`${t.relativeRoot}/`))return t}getPackageDependencies(){let e=new Map;for(let{graph:t,pkg:s}of this.packages.values()){let n=new Set;for(let o of t.nodes.values())for(let i of o.imports)i.isWorkspace&&i.workspacePackage&&n.add(i.workspacePackage);e.set(s.name,[...n])}return e}getAffectedAcrossPackages(e){let t=this.getPackageForFile(e);if(!t)return[];let s=this.packages.get(t.name);if(!s)return[];let n=[];s.graph.traverse(e,o=>(o.path!==e&&n.push({file:o.path,package:t.name}),!0),{direction:"incoming"});for(let{graph:o,pkg:i}of this.packages.values())if(i.name!==t.name)for(let a of o.nodes.values())a.imports.some(c=>c.isWorkspace&&c.workspacePackage===t.name)&&n.push({file:a.path,package:i.name});return n}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:t})=>({pkg:{name:t.name,relativeRoot:t.relativeRoot,entryPoints:t.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let t=new r(e.monorepoRoot,e.type);for(let{pkg:s,nodes:n}of e.packages){let o=new Map(n.map(a=>[a.path,a])),i=new T(o);t.packages.set(s.name,{graph:i,pkg:{...s,root:""}})}return t}};var or=new Map;function _(r,e){or.set(r,e)}function ir(r){return or.get(r)}function ar(r,e){return e.startsWith("!")?r!==e.slice(1):r===e}function dn(r,e){return e.startsWith("!")?!r.includes(e.slice(1)):r.includes(e)}var hn=(r,e)=>!e.category||ar(r.category,e.category),yn=(r,e)=>!e.type||ar(r.type,e.type),xn=(r,e)=>!e.path||dn(r.path,e.path),Sn=(r,e)=>e.isExternal===void 0?!0:r.imports.some(s=>s.isExternal)===e.isExternal,bn=(r,e)=>{if(!e.tags||e.tags.length===0)return!0;let t=e.tags.filter(n=>!n.startsWith("!")),s=e.tags.filter(n=>n.startsWith("!")).map(n=>n.slice(1));return!(t.length>0&&!t.some(n=>r.tags.some(o=>o.name===n))||s.some(n=>r.tags.some(o=>o.name===n)))},vn=(r,e)=>!e.allTags?.length||e.allTags.every(t=>r.tags.some(s=>s.name===t)),kn=(r,e)=>!e.importsFile||r.imports.some(t=>t.toPath?.includes(e.importsFile)),wn=(r,e,t)=>e.importedBy===void 0?!0:(t?.get(r.path)??[]).some(n=>n.includes(e.importedBy)),Cn=(r,e)=>e.minImports===void 0||r.imports.length>=e.minImports,Fn=(r,e)=>e.maxImports===void 0||r.imports.length<=e.maxImports,En=(r,e)=>e.minSize===void 0||r.size>=e.minSize,Tn=(r,e)=>e.maxSize===void 0||r.size<=e.maxSize,Pn=(r,e)=>e.hasDocstring===void 0||!!r.description===e.hasDocstring,An=(r,e)=>e.minCoverage===void 0||(r.coveragePct??101)>=e.minCoverage,In=(r,e)=>e.maxCoverage===void 0||(r.coveragePct??0)<=e.maxCoverage,Mn=(r,e)=>e.minExportUsage===void 0||(r.avgExportUsage??-1)>=e.minExportUsage,Rn=(r,e)=>e.maxExportUsage===void 0||(r.avgExportUsage??0)<=e.maxExportUsage,pr=[hn,yn,xn,Sn,bn,vn,kn,wn,Cn,Fn,En,Tn,Pn,An,In,Mn,Rn];function cr(r,e,t){return pr.every(s=>s(r,e,t))}function he(r,e){let t=new Map;if(e.importedBy!==void 0){for(let i of r.nodes)for(let a of i.imports)if(a.toPath){let p=t.get(a.toPath)??[];p.push(i.path),t.set(a.toPath,p)}}let s=r.nodes.filter(i=>cr(i,e,t)),n=new Set(s.map(i=>i.path)),o=s.map(i=>({...i,imports:i.imports.filter(a=>!a.toPath||n.has(a.toPath))}));return e.sort&&o.sort((i,a)=>e.sort==="size"?a.size-i.size:e.sort==="imports"?a.imports.length-i.imports.length:e.sort==="commitCount90d"?(a.commitCount90d??0)-(i.commitCount90d??0):e.sort==="exportUsage"?(a.avgExportUsage??0)-(i.avgExportUsage??0):0),e.limit!==void 0&&o.splice(e.limit),{nodes:o,cycles:r.cycles?.filter(i=>i.every(a=>n.has(a)))??void 0}}function ye(r){let e={},t=r.split(",");for(let s of t){let n=s.indexOf(":");if(n===-1)continue;let o=s.slice(0,n).trim().toLowerCase(),i=s.slice(n+1).trim();if(!(!o||!i))switch(o){case"category":e.category=i;break;case"type":e.type=i;break;case"tag":case"tags":i.includes("+")?e.allTags=[...e.allTags??[],...i.split("+")]:e.tags=[...e.tags??[],i];break;case"path":e.path=i;break;case"external":e.isExternal=i.toLowerCase()==="true";break;case"importsfile":e.importsFile=i;break;case"importedby":e.importedBy=i;break;case"minimports":e.minImports=parseInt(i,10);break;case"maximports":e.maxImports=parseInt(i,10);break;case"minsize":e.minSize=parseInt(i,10);break;case"maxsize":e.maxSize=parseInt(i,10);break;case"sort":e.sort=i;break;case"limit":e.limit=parseInt(i,10);break;case"hasdocstring":e.hasDocstring=i.toLowerCase()!=="false";break;case"mincoverage":e.minCoverage=parseInt(i,10);break;case"maxcoverage":e.maxCoverage=parseInt(i,10);break;case"minexportusage":e.minExportUsage=parseFloat(i);break;case"maxexportusage":e.maxExportUsage=parseFloat(i);break}}return e}import vr from"fs/promises";import ro from"path";import mt from"path";import Fe from"typescript";import ur from"path";import fr from"typescript";import k from"typescript";var lr=new Set(["describe","test","it"]);function j(r){let e=[];for(let t of r.statements){if(!k.isExpressionStatement(t))continue;let s=t.expression;if(!k.isCallExpression(s))continue;let n=s.expression;k.isIdentifier(n)&&lr.has(n.text)&&e.push(s),k.isPropertyAccessExpression(n)&&k.isIdentifier(n.expression)&&lr.has(n.expression.text)&&e.push(s)}return e}function L(r,e,t){for(let s of r.arguments){if(!k.isObjectLiteralExpression(s))continue;let n=s.properties.find(o=>k.isPropertyAssignment(o)&&k.isIdentifier(o.name)&&o.name.text===e);if(!(!n||!k.isArrayLiteralExpression(n.initializer)))return n.initializer.elements.filter(k.isStringLiteral).map(o=>o.text)}return null}function O(r,e,t,s){if(r.arguments.length===0)return null;for(let o=1;o<r.arguments.length;o++){let i=r.arguments[o];if(!k.isObjectLiteralExpression(i))continue;let a=i.properties.find(c=>k.isPropertyAssignment(c)&&k.isIdentifier(c.name)&&c.name.text===e);if(a)return{start:a.initializer.getStart(s),end:a.initializer.getEnd(),text:t};let p=i.getEnd()-1;return{start:p,end:p,text:`${i.properties.length>0?", ":""}${e}: ${t}`}}let n=r.arguments[r.arguments.length-1];return{start:n.getStart(s),end:n.getStart(s),text:`{ ${e}: ${t} }, `}}function W(r,e,t){let s=r.arguments;for(let n=1;n<s.length;n++){let o=s[n];if(!k.isObjectLiteralExpression(o))continue;let i=o.properties.findIndex(p=>k.isPropertyAssignment(p)&&k.isIdentifier(p.name)&&p.name.text===e);if(i<0)continue;if(o.properties.length===1)return{start:s[n-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(t),end:o.properties[i+1].getStart(t),text:""}}return null}function z(r,e){let t=[...e].sort((n,o)=>o.start-n.start),s=r;for(let n of t)s=s.slice(0,n.start)+n.text+s.slice(n.end);return s}function $(r){return`[${r.map(e=>JSON.stringify(e)).join(", ")}]`}var E=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Nn(r){return $(r.map(e=>`@${e}`))}function Gn(r){return r.map(e=>e.startsWith("@")?e.slice(1):e)}var xe=class{name="cypress";canHandle(e){return E.has(ur.extname(e).toLowerCase())}apply(e,t,s){let n=fr.createSourceFile(ur.basename(e),t,fr.ScriptTarget.Latest,!0),o=j(n);if(o.length===0)return t;let i=L(o[0],"tags",n),a=[...s].sort();if(i!==null&&JSON.stringify(Gn(i).sort())===JSON.stringify(a))return t;let p=o.flatMap(c=>{let m=s.length===0?W(c,"tags",n):O(c,"tags",Nn(a),n);return m?[m]:[]});return p.length>0?z(t,p):t}};import Dn from"path";var ct=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,lt=/^@([a-zA-Z0-9_-]+)/gm;function _n(r){return["# <mokosh-tags>",...r.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
2
+ var Ge=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});import zs from"path";import{fileURLToPath as $s}from"url";var Bs=()=>$s(import.meta.url),Us=()=>zs.dirname(Bs()),u=Us();import{StdioServerTransport as da}from"@modelcontextprotocol/sdk/server/stdio.js";import{Server as fa}from"@modelcontextprotocol/sdk/server/index.js";import{CallToolRequestSchema as ga,ListToolsRequestSchema as ma}from"@modelcontextprotocol/sdk/types.js";import ca from"fs";import Le from"fs";import Lt from"path";var qs=[".config.","biome.json","tsconfig.json","package.json",".prettierrc",".eslintrc"],Dt=[];function fe(r){Dt.push(r)}function Gt(r){return[...qs,...Dt].some(e=>typeof e=="string"?r.includes(e):e instanceof RegExp?e.test(r):e(r))}var Ks=[".test.",".spec.","-test.","-spec."],_t=[];function ge(r){_t.push(r)}function J(){return[...Ks,..._t]}var Js=["jest","vitest","playwright","cypress","@testing-library/"],jt=[];function me(r){jt.push(r)}function _e(){return[...Js,...jt]}var Ot=.8;function je(r){Ot=r}function Oe(){return Ot}var Hs=["mokosh.config.js","mokosh.config.cjs","mokosh.config.json"];function H(r,{allowJs:e=!0,isExplicitPath:t=!1}={}){if(t){let s=Lt.resolve(r);return Le.existsSync(s)?s.endsWith(".json")?Wt(s):e?zt(s):{}:{}}for(let s of Hs){let n=Lt.resolve(r,s);if(Le.existsSync(n)){if(s.endsWith(".json"))return Wt(n);if(e)return zt(n)}}return{}}function Wt(r){return JSON.parse(Le.readFileSync(r,"utf-8"))}function zt(r){let e=Ge(r);return e&&typeof e=="object"&&"default"in e&&(e=e.default),typeof e=="function"?e({}):e}function We(r){for(let e of r.configMatchers??[])fe(e);for(let e of r.testPatterns??[])ge(e);for(let e of r.testLibraries??[])me(e);r.barrelThreshold!==void 0&&je(r.barrelThreshold)}var ze=["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"],$e=[".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".go",".feature",".md",".mdx"];import Qs from"fs";import $t from"path";function Be(r,e){let t=$t.resolve(r,e);try{let s=Qs.readFileSync(t,"utf-8"),n=JSON.parse(s),o=new Map;for(let[i,a]of Object.entries(n)){if(i==="total")continue;let p=a?.lines?.pct;if(typeof p!="number")continue;let c=$t.relative(r,i);o.set(c,p)}return o}catch{return new Map}}var de={serialize(r){let e=["graph TD"],t=new Set;for(let s of r.nodes.values()){let n=`"${s.path}"`;for(let o of s.imports){if(!o.toPath)continue;let i=`"${o.toPath}"`,a=`${s.path} -> ${o.toPath}`;if(!t.has(a)){let p=o.isStyle?"-- styles -->":"-->";e.push(` ${n} ${p} ${i}`),t.add(a)}}}return e.join(`
3
+ `)}};import Bt from"fs";import Xs from"path";function Ue(r,e){let t=r.replace(/^\.\//,"");if(e.nodes.has(t))return t;let s=t.replace(/^dist\//,"src/").replace(/\.(js|mjs|cjs)$/,".ts");return e.nodes.has(s)?s:null}function Ut(r,e){if(typeof r=="string")return Ue(r,e);if(r&&typeof r=="object"){let t=r;for(let s of["import","require","default"]){let n=Ut(t[s],e);if(n)return n}}return null}function Zs(r){if(!r)return"unknown";let e=r.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 Ys(r,e){let t=new Set,s=new Set,n=[...e];for(;n.length;){let o=n.shift();if(s.has(o))continue;s.add(o);let i=r.nodes.get(o);if(i){for(let a of i.exports)t.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 c=r.nodes.get(a.toPath);if(c)for(let m of c.exports)t.add(m.name);n.push(a.toPath)}else for(let c of a.symbols)t.add(c)}}}return t}function qe(r,e){let t=[],s=Xs.join(e,"package.json");if(Bt.existsSync(s))try{let n=JSON.parse(Bt.readFileSync(s,"utf8"));if(n.exports&&typeof n.exports=="object"&&!Array.isArray(n.exports))for(let o of Object.values(n.exports)){let i=Ut(o,r);i&&!t.includes(i)&&t.push(i)}else if(typeof n.exports=="string"){let o=Ue(n.exports,r);o&&t.push(o)}if(t.length===0)for(let o of[n.main,n.module].filter(Boolean)){let i=Ue(o,r);i&&!t.includes(i)&&t.push(i)}}catch{}if(t.length===0){for(let n of["src/index.ts","src/index.js","index.ts","index.js"])if(r.nodes.has(n)){t.push(n);break}}return t}function en(r,e){let t=new Set(e);for(let s of e)r.traverse(s,n=>(t.add(n.path),!0),{direction:"outgoing"});return t}function tn(r,e,t){let s=new Map;for(let n of e){if(t.includes(n))continue;let o=r.nodes.get(n);if(!o)continue;let i=o.category==="barrel";for(let a of o.exports){let p=s.get(a.name),c=!!(a.signature||a.doc);(!p||c&&!i)&&s.set(a.name,{file:n,symbol:a})}}return s}function rn(r,e,t,s){let n=[];for(let o of r){let i=e.get(o),a=s.flatMap(g=>t.nodes.get(g)?.exports??[]).find(g=>g.name===o),p=i?.symbol??a,c=i?.file??s.find(g=>t.nodes.get(g)?.exports.some(h=>h.name===o))??s[0],m={name:o,definedIn:c,kind:Zs(p?.signature)};p?.doc&&(m.doc=p.doc),p?.signature&&(m.signature=p.signature),n.push(m)}return n.sort((o,i)=>o.name.localeCompare(i.name)),n}function sn(r,e,t){let s=p=>r.nodes.get(p)?.category==="test",n=[...e].filter(p=>!t.includes(p)&&!s(p)),o=[...r.nodes.keys()].filter(p=>!e.has(p)),i=o.filter(p=>!s(p)),a=o.filter(p=>s(p));return{internalFiles:n,unreachableFromEntry:i,testFiles:a}}function Ke(r,e){if(e.length===0)throw new Error("buildApiSurface requires at least one entry point");for(let c of e)if(!r.nodes.has(c))throw new Error(`Entry point not found in graph: ${c}`);let t=en(r,e),s=tn(r,t,e),n=Ys(r,e),o=rn(n,s,r,e),{internalFiles:i,unreachableFromEntry:a,testFiles:p}=sn(r,t,e);return{entryPoints:e,publicExports:o,internalFiles:i,unreachableFromEntry:a,testFiles:p}}function Je(r,e){let t=null,s=[];for(let o of r.nodes.values()){o.exports.some(i=>i.name===e)&&(t=o.path);for(let i of o.callEdges??[])i.to===e&&s.push({file:o.path,callerFunction:i.from})}let n=[];if(t){let o=r.nodes.get(t);for(let i of o?.callEdges??[])i.from===e&&n.push({file:i.toFile,calleeFunction:i.to})}return{functionName:e,definedIn:t,callers:s,callees:n}}import Ja from"fs";import Qa from"path";function qt(r){let e=[...r.nodes.entries()].sort(([s],[n])=>s.localeCompare(n)).map(([s,n])=>`${s}:${n.mtime}:${n.size}`).join("|"),t=2166136261;for(let s=0;s<e.length;s++)t^=e.charCodeAt(s),t=Math.imul(t,16777619)>>>0;return t.toString(16).padStart(8,"0")}function He(r){let e=new Map;for(let t of r.nodes.keys()){let s=[];r.traverse(t,n=>(n.path!==t&&s.push(n.path),!0),{direction:"incoming"}),e.set(t,s)}return{impact:e,graphHash:qt(r)}}function Qe(r,e){return r.impact.get(e)??[]}import he from"path";function nn(r){let e=new Map;for(let[t,s]of r){let n=s.imports.filter(o=>o.toPath&&!o.isExternal).length;n>0&&e.set(t,n)}return e}function on(r,e,t){let s=new Map;for(let[n,o]of e){if(o<t)continue;let i=r.get(n);if(!i||i.category==="test"||i.category==="barrel")continue;let a=he.extname(n),p=he.basename(n,a),c=p==="index"?he.basename(he.dirname(n)):p;s.set(n,{path:n,outDegree:o,tag:`feature:${c}`})}return s}function R(r,e){let t=e?.minOutDegree??5;return on(r,nn(r),t)}var an=(r,e)=>r.outDegree-e.outDegree;function pn(r,e){let t=new Map;for(let s of e.values()){let n=new Set;r.traverse(s.path,o=>(o.path!==s.path&&n.add(o.path),!0),{direction:"outgoing"}),t.set(s.path,n)}return t}function cn(r,e,t,s){let n=new Map;for(let[o]of r){if(e.has(o))continue;let i=null;for(let a of e.values())t.get(a.path)?.has(o)&&(!i||s(a,i)<0)&&(i=a);i&&n.set(o,i.path)}return n}function ln(r,e){let t=new Map;for(let s of r.values()){let n=s.tag.replace("feature:",""),o=[];for(let[i,a]of e)a===s.path&&o.push(i);t.set(n,{hub:s.path,outDegree:s.outDegree,files:o})}return t}function un(r,e,t){let s=[];for(let n of r.keys())!e.has(n)&&!t.has(n)&&s.push(n);return s}function Q(r,e){let t=e?.detectFn??R,s=e?.hubComparator??an,n=t(r.nodes,e),o=pn(r,n),i=cn(r.nodes,n,o,s);return{features:ln(n,i),unassigned:un(r.nodes,n,i)}}var V=class{constructor(e){this.nodes=e}nodes;findUnusedFiles(e){let t=new Set(this.nodes.keys());return e.filter(s=>!t.has(s))}findHighExportUsage(e){let t=[];for(let s of this.nodes.values()){if(s.maxExportUsage===void 0||s.maxExportUsage<e)continue;let n=s.imports.reduce((o,i)=>(i.exportUsageRatio??0)>(o?.exportUsageRatio??0)?i:o,null);t.push({path:s.path,maxExportUsage:s.maxExportUsage,tightestDep:n?.toPath??""})}return t.sort((s,n)=>n.maxExportUsage-s.maxExportUsage)}findCycles(){let e=[],t=new Set,s=new Set,n=[],o=i=>{t.add(i),s.add(i),n.push(i);let a=this.nodes.get(i);if(a){for(let p of a.imports)if(!(!p.toPath||p.isExternal))if(s.has(p.toPath)){let c=n.indexOf(p.toPath);e.push([...n.slice(c),p.toPath])}else t.has(p.toPath)||o(p.toPath)}s.delete(i),n.pop()};for(let i of this.nodes.keys())t.has(i)||o(i);return e}};var P=class r{constructor(e){this.nodes=e}nodes;_incomingEdgesCache=null;_callIncomingCache=null;serialize(){return{nodes:Array.from(this.nodes.values())}}static deserialize(e){let t=new Map;for(let s of e.nodes)t.set(s.path,s);return new r(t)}getIncomingEdgesMap(){if(this._incomingEdgesCache)return this._incomingEdgesCache;let e=new Map;for(let t of this.nodes.values())for(let s of t.imports)if(s.toPath){let n=e.get(s.toPath)||[];n.push(t.path),e.set(s.toPath,n)}return this._incomingEdgesCache=e,e}dfs(e,t,s,n){let o=new Set,i=s.maxDepth??1/0,a=(p,c,m)=>{if(c>i||o.has(p))return;let g=this.nodes.get(p);if(g&&(o.add(p),t(g,c,m)!==!1))for(let h of n(p))a(h,c+1,p)};a(e,0,null)}traverse(e,t,s={}){let n=s.direction??"outgoing",o=n==="incoming"?this.getIncomingEdgesMap():null;this.dfs(e,t,s,i=>n==="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 t of this.nodes.values())for(let s of t.callEdges??[]){let n=e.get(s.toFile)??[];n.push(t.path),e.set(s.toFile,n)}return this._callIncomingCache=e,e}traverseCalls(e,t,s={}){let n=s.direction??"outgoing",o=n==="incoming"?this.getCallIncomingCache():null;this.dfs(e,t,s,i=>n==="outgoing"?this.nodes.get(i)?.callEdges?.map(a=>a.toFile)??[]:o?.get(i)??[])}getCallers(e){let t=[];return this.traverseCalls(e,s=>(s.path!==e&&t.push(s.path),!0),{direction:"incoming",maxDepth:1}),t}getCallEdgesFor(e){return this.nodes.get(e)?.callEdges??[]}getNeighbors(e){let t=this.nodes.get(e);return t?t.imports.map(s=>this.nodes.get(s.toPath)).filter(s=>s!==void 0):[]}findUnusedFiles(e){return new V(this.nodes).findUnusedFiles(e)}findCycles(){return new V(this.nodes).findCycles()}};var N=class{affectedSymbols=new Map;constructor(e,t){this.affectedSymbols.set(e,new Set(["default",...t]))}updateAffectedSymbols(e,t){let s=this.affectedSymbols.get(t)||new Set,n=e.imports.find(p=>p.toPath===t);if(!n)return!1;let o=n.symbols||["*"],i=new Set;for(let p of o)(p==="*"||s.has("*")||s.has(p))&&i.add("*");if(i.size===0)return!1;let a=this.affectedSymbols.get(e.path)||new Set;for(let p of i)a.add(p);return this.affectedSymbols.set(e.path,a),!0}};function Ve(r,e,t=1){let s=[];return r.traverse(e,(n,o,i)=>{if(n.path===e)return!0;let a=i?r.nodes.get(i)?.imports.find(p=>p.toPath===n.path):void 0;return s.push({path:n.path,...a?.symbols?{symbols:a.symbols}:{}}),!0},{direction:"outgoing",maxDepth:t}),s}function Xe(r,e){let t=[];return r.traverse(e,s=>{if(s.path===e)return!0;let n=s.imports.find(o=>o.toPath===e);return t.push({path:s.path,...n?.symbols?{symbols:n.symbols}:{}}),!0},{direction:"incoming",maxDepth:1}),t}function Ze(r,e,t={}){let{testsOnly:s=!1,changedSymbols:n}=t,o=n?new N(e,n):null,i=[];return r.traverse(e,(a,p,c)=>{if(a.path===e)return!0;if(o&&c&&!o.updateAffectedSymbols(a,c))return!1;let m=a.category==="test"||a.tags.some(g=>g.name==="test");return(!s||m)&&i.push(a.path),!0},{direction:"incoming"}),i}function Ye(r,e,t={}){let{depth:s=1,withEdgeDetail:n=!1}=t,o=[];return r.traverseCalls(e,i=>{if(i.path===e)return!0;let a={file:i.path};return n&&(a.edges=(i.callEdges??[]).filter(p=>p.toFile===e).map(p=>({from:p.from,to:p.to}))),o.push(a),!0},{direction:"incoming",maxDepth:s}),o}function et(r,e={}){let{metric:t="cognitiveComplexity",threshold:s=10,limit:n=20}=e;return[...r.nodes.values()].flatMap(o=>(o.functions??[]).filter(i=>i[t]>=s).map(i=>({file:o.path,name:i.name,line:i.line,complexity:i.complexity,cognitiveComplexity:i.cognitiveComplexity}))).sort((o,i)=>i[t]-o[t]).slice(0,n)}function tt(r){return{nodes:r.nodes.map(t=>({path:t.path,type:t.type,category:t.category,exports:t.exports.map(s=>s.name),tags:t.tags.filter(s=>s.kind==="comment-marker"||s.kind==="import").map(s=>s.name),importsFiles:t.imports.filter(s=>!s.isExternal&&s.toPath).map(s=>s.toPath),...t.description!==void 0&&{description:t.description},...t.testedBy!==void 0&&{testedBy:t.testedBy},...t.coveragePct!==void 0&&{coveragePct:t.coveragePct},...t.avgExportUsage!==void 0&&{avgExportUsage:t.avgExportUsage},...t.maxExportUsage!==void 0&&{maxExportUsage:t.maxExportUsage}})),cycles:r.cycles}}function rt(r){let e=r.getPackageDependencies(),t=Array.from(r.packages.values()).map(({graph:s,pkg:n})=>({name:n.name,relativeRoot:n.relativeRoot,nodeCount:s.nodes.size,dependsOn:e.get(n.name)??[]}));return{monorepoType:r.type,packageCount:t.length,packages:t}}function st(r){return[...r.nodes.values()].some(e=>e.coveragePct!==void 0)}function Kt(r){if(r.category==="test")return"test";if(r.category==="config")return"config";if(r.category==="type-only")return"types";let e=r.path;return x(e,"component")||x(e,"components")?"component":x(e,"controller")||x(e,"controllers")?"controller":x(e,"middleware")?"middleware":x(e,"router")||x(e,"routes")||x(e,"route")?"router":x(e,"store")||x(e,"stores")?"store":x(e,"service")||x(e,"services")?"service":x(e,"handler")||x(e,"handlers")?"handler":x(e,"adapter")||x(e,"adapters")?"adapter":x(e,"plugin")||x(e,"plugins")?"plugin":x(e,"api")?"api":x(e,"cli")||x(e,"commands")||X(e)==="cli"?"cli":x(e,"util")||x(e,"utils")||x(e,"helper")||x(e,"helpers")?"util":x(e,"model")||x(e,"models")||X(e)==="model"?"model":x(e,"parser")||x(e,"parsers")||X(e)==="parser"?"parser":X(e)==="builder"?"builder":X(e)==="resolver"?"resolver":"other"}function x(r,e){return r.includes(`/${e}/`)||r.includes(`/${e}.`)}function X(r){let e=r.slice(r.lastIndexOf("/")+1);return e.slice(0,e.lastIndexOf("."))||e}function nt(r,e){let t=Q(r,e),s=new Map;for(let[o,i]of t.features){for(let a of i.files)s.set(a,o);s.set(i.hub,o)}let n=new Map;for(let o of r.nodes.values()){let i=s.get(o.path);n.set(o.path,{path:o.path,role:Kt(o),...o.description?{description:o.description}:{},exports:o.exports.map(a=>a.name),...i?{featureHub:i}:{}})}return n}function fn(r){return r?r.startsWith("interface ")?"interface":r.startsWith("class ")?"class":r.startsWith("enum ")?"enum":"type":"type"}function gn(r,e){if(e==="type-only")return!0;let t=r.signature??"";return t.startsWith("interface ")||t.startsWith("class ")||t.startsWith("enum ")}function ot(r){let e=new Map;for(let s of r.nodes.values())if(!(s.type!=="typescript"&&s.type!=="javascript"))for(let n of s.exports){if(!gn(n,s.category))continue;let o=`${s.path}::${n.name}`;e.set(o,{name:n.name,file:s.path,kind:fn(n.signature),...n.doc?{doc:n.doc}:{}})}let t=[];for(let s of r.nodes.values())if(!(s.type!=="typescript"&&s.type!=="javascript")){for(let n of s.imports)if(!(!n.toPath||n.isExternal||!n.symbols?.length))for(let o of n.symbols)e.has(`${n.toPath}::${o}`)&&t.push({fromFile:s.path,toType:o,toFile:n.toPath})}return{types:e,edges:t}}function it(r,e){let t=null;for(let o of r.types.values())if(o.name===e){t=o;break}if(!t)return{type:null,usedByFiles:[],uses:[]};let s=new Set,n=new Map;for(let o of r.edges)if(o.toType===e&&o.toFile===t.file&&s.add(o.fromFile),o.fromFile===t.file){let i=r.types.get(`${o.toFile}::${o.toType}`);i&&n.set(`${i.file}::${i.name}`,i)}return{type:t,usedByFiles:Array.from(s),uses:Array.from(n.values())}}import Fn from"path";import pt from"fs";import Vt from"path";import Z from"fs";import C from"path";import Jt from"fs";import Cp from"path";function Ht(r){try{return Jt.statSync(r,{throwIfNoEntry:!1})?.isDirectory()===!0}catch{return!1}}function ye(r){try{return Jt.statSync(r,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}function at(r,e){let t=C.join(e,"package.json");if(!Z.existsSync(t))return null;let s={};try{s=JSON.parse(Z.readFileSync(t,"utf-8"))}catch{return null}let n=s.name;return n?{name:n,root:e,relativeRoot:C.relative(r,e),entryPoints:mn(e,s)}:null}function mn(r,e){let t=[];if(e.exports){let n=e.exports;if(typeof n=="string")t.push(C.join(r,n));else if(typeof n=="object"&&n!==null){let o=n["."];if(typeof o=="string")t.push(C.join(r,o));else if(typeof o=="object"&&o!==null){let i=o.import??o.require??o.default;typeof i=="string"&&t.push(C.join(r,i))}}}e.main&&t.push(C.join(r,e.main));for(let n of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"])t.push(C.join(r,n));let s=t.filter(ye);return s.length>0?s.slice(0,1):t.slice(0,1)}function D(r,e){let t=[],s=new Set;for(let n of e){let o=n.replace(/\/$/,"").replace(/^\.\//,"");dn(r,o,s,t)}return t}function dn(r,e,t,s){if(!e.includes("*")){hn(r,e,t,s);return}let n=e.split("/");n.includes("**")?yn(r,n,t,s):xn(r,n,t,s)}function hn(r,e,t,s){let n=C.join(r,e);if(t.has(n)||!Ht(n))return;t.add(n);let o=at(r,n);o&&s.push(o)}function yn(r,e,t,s){let n=C.join(r,e[0]==="**"?"":e[0]??"");Qt(r,n,t,s)}function xn(r,e,t,s){let n=e.findIndex(a=>a.includes("*")),o=C.join(r,...e.slice(0,n)),i;try{i=Z.readdirSync(o,{withFileTypes:!0})}catch{return}for(let a of i){if(!a.isDirectory())continue;let p=C.join(o,a.name);if(t.has(p))continue;t.add(p);let c=at(r,p);c&&s.push(c)}}function Qt(r,e,t,s){let n;try{n=Z.readdirSync(e,{withFileTypes:!0})}catch{return}for(let o of n){if(!o.isDirectory()||o.name==="node_modules"||o.name.startsWith("."))continue;let i=C.join(e,o.name);if(Z.existsSync(C.join(i,"package.json"))&&!t.has(i)){t.add(i);let a=at(r,i);a&&s.push(a)}else Qt(r,i,t,s)}}var Xt={type:"npm",detect(r){let e=Vt.join(r,"package.json");if(!pt.existsSync(e))return null;let t;try{t=JSON.parse(pt.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!t||pt.existsSync(Vt.join(r,"yarn.lock")))return null;let s=Array.isArray(t)?t:t.packages??[];return s.length===0?null:D(r,s)}};import G from"fs";import v from"path";var Zt={type:"nx",detect(r){return G.existsSync(v.join(r,"nx.json"))?Yt(r,r,new Set,0).map(t=>Sn(r,t,v.join(t,"project.json"))).filter(t=>t!==null):null}};function Yt(r,e,t,s){if(s>4)return[];let n;try{n=G.readdirSync(e,{withFileTypes:!0})}catch{return[]}let o=[];for(let i of n){if(!i.isDirectory())continue;let a=i.name;if(a.startsWith(".")||a==="node_modules"||a==="dist"||a===".nx")continue;let p=v.join(e,a);G.existsSync(v.join(p,"project.json"))&&!t.has(p)?(t.add(p),o.push(p)):o.push(...Yt(r,p,t,s+1))}return o}function Sn(r,e,t){let s={};try{s=JSON.parse(G.readFileSync(t,"utf-8"))}catch{return null}let n=s.name,o,i,a=v.join(e,"package.json");if(G.existsSync(a))try{let p=JSON.parse(G.readFileSync(a,"utf-8"));n=p.name??n,o=p.main,i=p.exports}catch{}return n?{name:n,root:e,relativeRoot:v.relative(r,e),entryPoints:bn(e,s,o,i)}:null}function bn(r,e,t,s){let n=[],o=e.targets?.build?.options?.main??e.targets?.build?.options?.entryFile;if(o){let a=v.resolve(r,"../..");n.push(v.resolve(a,o)),n.push(v.resolve(r,o))}if(s){let a=s;if(typeof a=="string")n.push(v.join(r,a));else if(typeof a=="object"&&a!==null){let p=a["."];typeof p=="string"&&n.push(v.join(r,p))}}if(t&&n.push(v.join(r,t)),e.sourceRoot){let a=v.resolve(r,"../.."),p=v.resolve(a,e.sourceRoot);n.push(v.join(p,"index.ts"),v.join(p,"index.tsx"))}for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx"])n.push(v.join(r,a));let i=n.filter(ye);return i.length>0?i.slice(0,1):n.slice(0,1)}import er from"fs";import vn from"path";import kn from"js-yaml";var tr={type:"pnpm",detect(r){let e=vn.join(r,"pnpm-workspace.yaml");if(!er.existsSync(e))return null;let t=[];try{t=kn.load(er.readFileSync(e,"utf-8"))?.packages??[]}catch{return null}return D(r,t)}};import wn from"fs";import Cn from"path";var rr={type:"turborepo",detect(r){return wn.existsSync(Cn.join(r,"turbo.json"))?[]:null}};import ct from"fs";import sr from"path";var nr={type:"yarn",detect(r){if(!ct.existsSync(sr.join(r,"yarn.lock")))return null;let e=sr.join(r,"package.json");if(!ct.existsSync(e))return null;let t;try{t=JSON.parse(ct.readFileSync(e,"utf-8")).workspaces}catch{return null}if(!t)return null;let s=Array.isArray(t)?t:t.packages??[];return s.length===0?null:D(r,s)}};var or=[];function T(r){or.push(r)}function ir(){return or}T(rr);T(Zt);T(tr);T(nr);T(Xt);function Y(r,e=ir()){let t=Fn.resolve(r),s=new Map,n=[];for(let i of e){let a=i.detect(t);if(a!==null){n.push(i.type);for(let p of a)s.has(p.name)||s.set(p.name,p)}}if(n.length===0)return{root:t,type:"none",types:[],packages:[],packageMap:new Map};let o=Array.from(s.values());return{root:t,type:n[0],types:n,packages:o,packageMap:new Map(o.map(i=>[i.name,i]))}}var ee=class r{constructor(e,t){this.monorepoRoot=e;this.type=t}monorepoRoot;type;packages=new Map;addPackage(e,t){this.packages.set(e.name,{graph:t,pkg:e})}getPackageForFile(e){for(let{pkg:t}of this.packages.values())if(e===t.relativeRoot||e.startsWith(`${t.relativeRoot}/`))return t}getPackageDependencies(){let e=new Map;for(let{graph:t,pkg:s}of this.packages.values()){let n=new Set;for(let o of t.nodes.values())for(let i of o.imports)i.isWorkspace&&i.workspacePackage&&n.add(i.workspacePackage);e.set(s.name,[...n])}return e}getAffectedAcrossPackages(e){let t=this.getPackageForFile(e);if(!t)return[];let s=this.packages.get(t.name);if(!s)return[];let n=[];s.graph.traverse(e,o=>(o.path!==e&&n.push({file:o.path,package:t.name}),!0),{direction:"incoming"});for(let{graph:o,pkg:i}of this.packages.values())if(i.name!==t.name)for(let a of o.nodes.values())a.imports.some(c=>c.isWorkspace&&c.workspacePackage===t.name)&&n.push({file:a.path,package:i.name});return n}serialize(){return{monorepoRoot:this.monorepoRoot,type:this.type,packages:Array.from(this.packages.values()).map(({graph:e,pkg:t})=>({pkg:{name:t.name,relativeRoot:t.relativeRoot,entryPoints:t.entryPoints},nodes:Array.from(e.nodes.values())}))}}static deserialize(e){let t=new r(e.monorepoRoot,e.type);for(let{pkg:s,nodes:n}of e.packages){let o=new Map(n.map(a=>[a.path,a])),i=new P(o);t.packages.set(s.name,{graph:i,pkg:{...s,root:""}})}return t}};var ar=new Map;function _(r,e){ar.set(r,e)}function pr(r){return ar.get(r)}function cr(r,e){return e.startsWith("!")?r!==e.slice(1):r===e}function En(r,e){return e.startsWith("!")?!r.includes(e.slice(1)):r.includes(e)}var Pn=(r,e)=>!e.category||cr(r.category,e.category),Tn=(r,e)=>!e.type||cr(r.type,e.type),An=(r,e)=>!e.path||En(r.path,e.path),In=(r,e)=>e.isExternal===void 0?!0:r.imports.some(s=>s.isExternal)===e.isExternal,Mn=(r,e)=>{if(!e.tags||e.tags.length===0)return!0;let t=e.tags.filter(n=>!n.startsWith("!")),s=e.tags.filter(n=>n.startsWith("!")).map(n=>n.slice(1));return!(t.length>0&&!t.some(n=>r.tags.some(o=>o.name===n))||s.some(n=>r.tags.some(o=>o.name===n)))},Rn=(r,e)=>!e.allTags?.length||e.allTags.every(t=>r.tags.some(s=>s.name===t)),Nn=(r,e)=>!e.importsFile||r.imports.some(t=>t.toPath?.includes(e.importsFile)),Dn=(r,e,t)=>e.importedBy===void 0?!0:(t?.get(r.path)??[]).some(n=>n.includes(e.importedBy)),Gn=(r,e)=>e.minImports===void 0||r.imports.length>=e.minImports,_n=(r,e)=>e.maxImports===void 0||r.imports.length<=e.maxImports,jn=(r,e)=>e.minSize===void 0||r.size>=e.minSize,On=(r,e)=>e.maxSize===void 0||r.size<=e.maxSize,Ln=(r,e)=>e.hasDocstring===void 0||!!r.description===e.hasDocstring,Wn=(r,e)=>e.minCoverage===void 0||(r.coveragePct??101)>=e.minCoverage,zn=(r,e)=>e.maxCoverage===void 0||(r.coveragePct??0)<=e.maxCoverage,$n=(r,e)=>e.minExportUsage===void 0||(r.avgExportUsage??-1)>=e.minExportUsage,Bn=(r,e)=>e.maxExportUsage===void 0||(r.avgExportUsage??0)<=e.maxExportUsage,lr=[Pn,Tn,An,In,Mn,Rn,Nn,Dn,Gn,_n,jn,On,Ln,Wn,zn,$n,Bn];function ur(r,e,t){return lr.every(s=>s(r,e,t))}function xe(r,e){let t=new Map;if(e.importedBy!==void 0){for(let i of r.nodes)for(let a of i.imports)if(a.toPath){let p=t.get(a.toPath)??[];p.push(i.path),t.set(a.toPath,p)}}let s=r.nodes.filter(i=>ur(i,e,t)),n=new Set(s.map(i=>i.path)),o=s.map(i=>({...i,imports:i.imports.filter(a=>!a.toPath||n.has(a.toPath))}));return e.sort&&o.sort((i,a)=>e.sort==="size"?a.size-i.size:e.sort==="imports"?a.imports.length-i.imports.length:e.sort==="commitCount90d"?(a.commitCount90d??0)-(i.commitCount90d??0):e.sort==="exportUsage"?(a.avgExportUsage??0)-(i.avgExportUsage??0):0),e.limit!==void 0&&o.splice(e.limit),{nodes:o,cycles:r.cycles?.filter(i=>i.every(a=>n.has(a)))??void 0}}function Se(r){let e={},t=r.split(",");for(let s of t){let n=s.indexOf(":");if(n===-1)continue;let o=s.slice(0,n).trim().toLowerCase(),i=s.slice(n+1).trim();if(!(!o||!i))switch(o){case"category":e.category=i;break;case"type":e.type=i;break;case"tag":case"tags":i.includes("+")?e.allTags=[...e.allTags??[],...i.split("+")]:e.tags=[...e.tags??[],i];break;case"path":e.path=i;break;case"external":e.isExternal=i.toLowerCase()==="true";break;case"importsfile":e.importsFile=i;break;case"importedby":e.importedBy=i;break;case"minimports":e.minImports=parseInt(i,10);break;case"maximports":e.maxImports=parseInt(i,10);break;case"minsize":e.minSize=parseInt(i,10);break;case"maxsize":e.maxSize=parseInt(i,10);break;case"sort":e.sort=i;break;case"limit":e.limit=parseInt(i,10);break;case"hasdocstring":e.hasDocstring=i.toLowerCase()!=="false";break;case"mincoverage":e.minCoverage=parseInt(i,10);break;case"maxcoverage":e.maxCoverage=parseInt(i,10);break;case"minexportusage":e.minExportUsage=parseFloat(i);break;case"maxexportusage":e.maxExportUsage=parseFloat(i);break}}return e}import wr from"fs/promises";import go from"path";import dt from"path";import Pe from"typescript";import gr from"path";import mr from"typescript";import k from"typescript";var fr=new Set(["describe","test","it"]);function j(r){let e=[];for(let t of r.statements){if(!k.isExpressionStatement(t))continue;let s=t.expression;if(!k.isCallExpression(s))continue;let n=s.expression;k.isIdentifier(n)&&fr.has(n.text)&&e.push(s),k.isPropertyAccessExpression(n)&&k.isIdentifier(n.expression)&&fr.has(n.expression.text)&&e.push(s)}return e}function O(r,e,t){for(let s of r.arguments){if(!k.isObjectLiteralExpression(s))continue;let n=s.properties.find(o=>k.isPropertyAssignment(o)&&k.isIdentifier(o.name)&&o.name.text===e);if(!(!n||!k.isArrayLiteralExpression(n.initializer)))return n.initializer.elements.filter(k.isStringLiteral).map(o=>o.text)}return null}function L(r,e,t,s){if(r.arguments.length===0)return null;for(let o=1;o<r.arguments.length;o++){let i=r.arguments[o];if(!k.isObjectLiteralExpression(i))continue;let a=i.properties.find(c=>k.isPropertyAssignment(c)&&k.isIdentifier(c.name)&&c.name.text===e);if(a)return{start:a.initializer.getStart(s),end:a.initializer.getEnd(),text:t};let p=i.getEnd()-1;return{start:p,end:p,text:`${i.properties.length>0?", ":""}${e}: ${t}`}}let n=r.arguments[r.arguments.length-1];return{start:n.getStart(s),end:n.getStart(s),text:`{ ${e}: ${t} }, `}}function W(r,e,t){let s=r.arguments;for(let n=1;n<s.length;n++){let o=s[n];if(!k.isObjectLiteralExpression(o))continue;let i=o.properties.findIndex(p=>k.isPropertyAssignment(p)&&k.isIdentifier(p.name)&&p.name.text===e);if(i<0)continue;if(o.properties.length===1)return{start:s[n-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(t),end:o.properties[i+1].getStart(t),text:""}}return null}function z(r,e){let t=[...e].sort((n,o)=>o.start-n.start),s=r;for(let n of t)s=s.slice(0,n.start)+n.text+s.slice(n.end);return s}function $(r){return`[${r.map(e=>JSON.stringify(e)).join(", ")}]`}var E=new Set([".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"]);function Un(r){return $(r.map(e=>`@${e}`))}function qn(r){return r.map(e=>e.startsWith("@")?e.slice(1):e)}var be=class{name="cypress";canHandle(e){return E.has(gr.extname(e).toLowerCase())}apply(e,t,s){let n=mr.createSourceFile(gr.basename(e),t,mr.ScriptTarget.Latest,!0),o=j(n);if(o.length===0)return t;let i=O(o[0],"tags",n),a=[...s].sort();if(i!==null&&JSON.stringify(qn(i).sort())===JSON.stringify(a))return t;let p=o.flatMap(c=>{let m=s.length===0?W(c,"tags",n):L(c,"tags",Un(a),n);return m?[m]:[]});return p.length>0?z(t,p):t}};import Kn from"path";var lt=/# <mokosh-tags>[\s\S]*?# <\/mokosh-tags>\n*/,ut=/^@([a-zA-Z0-9_-]+)/gm;function Jn(r){return["# <mokosh-tags>",...r.map(e=>`@${e}`),"# </mokosh-tags>"].join(`
4
4
  `)+`
5
5
 
6
- `}function jn(r){let e=new Set;lt.lastIndex=0;let t=lt.exec(r);for(;t!==null;)t[1]&&e.add(t[1]),t=lt.exec(r);return e}var Se=class{name="gherkin";canHandle(e){return Dn.extname(e).toLowerCase()===".feature"}apply(e,t,s){let n=t.replace(ct,""),o=jn(n),i=s.filter(p=>!o.has(p)),a=i.length>0?_n(i):"";return ct.test(t)?t.replace(ct,a):a?t.replace(/^(Feature:)/m,`${a}$1`):t}};function gr(r,e){let t=r.replace(/\\/g,"/"),s=e.replace(/\\/g,"/"),n="";for(let o=0;o<t.length;o++){let i=t[o];i==="*"?t[o+1]==="*"?(n+=".*",o++):n+="[^/]*":i==="?"?n+="[^/]":i!==void 0&&(n+=i.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${n}$`).test(s)}import Ln from"path";var ut=/^\/\/go:build mokosh_[^\n]+\n/m,On=/^package\s+\S+/m;function Wn(r){return`//go:build ${r.map(t=>`mokosh_${t}`).join(" || ")}
7
- `}function zn(r){let e=ut.exec(r);if(!e)return null;let t=e[0],s=/mokosh_([a-zA-Z0-9_-]+)/g,n=[],o=s.exec(t);for(;o!==null;)o[1]&&n.push(o[1]),o=s.exec(t);return n}var be=class{name="go";canHandle(e){return Ln.basename(e).endsWith("_test.go")}apply(e,t,s){let n=zn(t),o=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(o))return t;if(s.length===0)return t.replace(ut,"");let i=Wn(o);if(n!==null)return t.replace(ut,i);let a=On.exec(t);if(!a)return t;let p=a.index;return t.slice(0,p)+i+`
8
- `+t.slice(p)}};import $n from"path";var Bn=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,ft=/^ \* @group (.+)$/gm;function Un(r){return["/**",...r.map(e=>` * @group ${e}`)," */"].join(`
6
+ `}function Hn(r){let e=new Set;ut.lastIndex=0;let t=ut.exec(r);for(;t!==null;)t[1]&&e.add(t[1]),t=ut.exec(r);return e}var ve=class{name="gherkin";canHandle(e){return Kn.extname(e).toLowerCase()===".feature"}apply(e,t,s){let n=t.replace(lt,""),o=Hn(n),i=s.filter(p=>!o.has(p)),a=i.length>0?Jn(i):"";return lt.test(t)?t.replace(lt,a):a?t.replace(/^(Feature:)/m,`${a}$1`):t}};function dr(r,e){let t=r.replace(/\\/g,"/"),s=e.replace(/\\/g,"/"),n="";for(let o=0;o<t.length;o++){let i=t[o];i==="*"?t[o+1]==="*"?(n+=".*",o++):n+="[^/]*":i==="?"?n+="[^/]":i!==void 0&&(n+=i.replace(/[.+^${}()|[\]\\]/g,"\\$&"))}return new RegExp(`^${n}$`).test(s)}import Qn from"path";var ft=/^\/\/go:build mokosh_[^\n]+\n/m,Vn=/^package\s+\S+/m;function Xn(r){return`//go:build ${r.map(t=>`mokosh_${t}`).join(" || ")}
7
+ `}function Zn(r){let e=ft.exec(r);if(!e)return null;let t=e[0],s=/mokosh_([a-zA-Z0-9_-]+)/g,n=[],o=s.exec(t);for(;o!==null;)o[1]&&n.push(o[1]),o=s.exec(t);return n}var ke=class{name="go";canHandle(e){return Qn.basename(e).endsWith("_test.go")}apply(e,t,s){let n=Zn(t),o=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(o))return t;if(s.length===0)return t.replace(ft,"");let i=Xn(o);if(n!==null)return t.replace(ft,i);let a=Vn.exec(t);if(!a)return t;let p=a.index;return t.slice(0,p)+i+`
8
+ `+t.slice(p)}};import Yn from"path";var eo=/^\/\*\*\n(?: \* @group .+\n)+ \*\/\n+/,gt=/^ \* @group (.+)$/gm;function to(r){return["/**",...r.map(e=>` * @group ${e}`)," */"].join(`
9
9
  `)+`
10
10
 
11
- `}function qn(r){let e=[];ft.lastIndex=0;let t=ft.exec(r);for(;t!==null;)t[1]&&e.push(t[1]),t=ft.exec(r);return e}var ve=class{name="jest";canHandle(e){return E.has($n.extname(e).toLowerCase())}apply(e,t,s){let n=Bn.exec(t),o=n?qn(n[0]):null,i=[...s].sort();if(o!==null&&JSON.stringify([...o].sort())===JSON.stringify(i))return t;let a=n?t.slice(n[0].length):t;return s.length===0?a:Un(i)+a}};import mr from"path";import dr from"typescript";function Kn(r){return $(r.map(e=>`@${e}`))}function Jn(r){return r.map(e=>e.startsWith("@")?e.slice(1):e)}var ke=class{name="playwright";canHandle(e){return E.has(mr.extname(e).toLowerCase())}apply(e,t,s){let n=dr.createSourceFile(mr.basename(e),t,dr.ScriptTarget.Latest,!0),o=j(n);if(o.length===0)return t;let i=L(o[0],"tag",n),a=[...s].sort();if(i!==null&&JSON.stringify(Jn(i).sort())===JSON.stringify(a))return t;let p=o.flatMap(c=>{let m=s.length===0?W(c,"tag",n):O(c,"tag",Kn(a),n);return m?[m]:[]});return p.length>0?z(t,p):t}};import Hn from"path";var gt=/^pytestmark\s*=\s*.+$/m,Qn=/^import pytest\s*$/m;function Vn(r){let e=r.map(t=>`pytest.mark.${t}`).join(", ");return r.length===1?`pytestmark = pytest.mark.${r[0]}`:`pytestmark = [${e}]`}function Xn(r){let e=gt.exec(r);if(!e)return null;let t=e[0],s=[],n=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,o=n.exec(t);for(;o!==null;)o[1]&&s.push(o[1]),o=n.exec(t);return s}var we=class{name="pytest";canHandle(e){return Hn.extname(e).toLowerCase()===".py"}apply(e,t,s){let n=Xn(t),o=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(o))return t;if(s.length===0)return t.replace(gt,"").replace(/\n{3,}/g,`
11
+ `}function ro(r){let e=[];gt.lastIndex=0;let t=gt.exec(r);for(;t!==null;)t[1]&&e.push(t[1]),t=gt.exec(r);return e}var we=class{name="jest";canHandle(e){return E.has(Yn.extname(e).toLowerCase())}apply(e,t,s){let n=eo.exec(t),o=n?ro(n[0]):null,i=[...s].sort();if(o!==null&&JSON.stringify([...o].sort())===JSON.stringify(i))return t;let a=n?t.slice(n[0].length):t;return s.length===0?a:to(i)+a}};import hr from"path";import yr from"typescript";function so(r){return $(r.map(e=>`@${e}`))}function no(r){return r.map(e=>e.startsWith("@")?e.slice(1):e)}var Ce=class{name="playwright";canHandle(e){return E.has(hr.extname(e).toLowerCase())}apply(e,t,s){let n=yr.createSourceFile(hr.basename(e),t,yr.ScriptTarget.Latest,!0),o=j(n);if(o.length===0)return t;let i=O(o[0],"tag",n),a=[...s].sort();if(i!==null&&JSON.stringify(no(i).sort())===JSON.stringify(a))return t;let p=o.flatMap(c=>{let m=s.length===0?W(c,"tag",n):L(c,"tag",so(a),n);return m?[m]:[]});return p.length>0?z(t,p):t}};import oo from"path";var mt=/^pytestmark\s*=\s*.+$/m,io=/^import pytest\s*$/m;function ao(r){let e=r.map(t=>`pytest.mark.${t}`).join(", ");return r.length===1?`pytestmark = pytest.mark.${r[0]}`:`pytestmark = [${e}]`}function po(r){let e=mt.exec(r);if(!e)return null;let t=e[0],s=[],n=/pytest\.mark\.([a-zA-Z0-9_-]+)/g,o=n.exec(t);for(;o!==null;)o[1]&&s.push(o[1]),o=n.exec(t);return s}var Fe=class{name="pytest";canHandle(e){return oo.extname(e).toLowerCase()===".py"}apply(e,t,s){let n=po(t),o=[...s].sort();if(n!==null&&JSON.stringify([...n].sort())===JSON.stringify(o))return t;if(s.length===0)return t.replace(mt,"").replace(/\n{3,}/g,`
12
12
 
13
- `);let i=Vn(o);if(n!==null)return t.replace(gt,i);let a=Qn.test(t),p=Zn(t),c=t.slice(0,p),m=t.slice(p),g=a?"":`import pytest
13
+ `);let i=ao(o);if(n!==null)return t.replace(mt,i);let a=io.test(t),p=co(t),c=t.slice(0,p),m=t.slice(p),g=a?"":`import pytest
14
14
  `,h=c.endsWith(`
15
15
 
16
16
  `)?"":`
17
17
  `;return c+h+g+i+`
18
- `+m}};function Zn(r){let e=r.split(`
19
- `),t=-1;for(let n=0;n<e.length;n++){let o=e[n].trimStart();(o.startsWith("import ")||o.startsWith("from "))&&(t=n)}if(t<0)return 0;let s=0;for(let n=0;n<=t;n++)s+=e[n].length+1;return s}import hr from"path";import yr from"typescript";var Yn=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,Ce=class{name="vitest";canHandle(e){return E.has(hr.extname(e).toLowerCase())}apply(e,t,s){let n=t.replace(Yn,""),o=yr.createSourceFile(hr.basename(e),n,yr.ScriptTarget.Latest,!0),i=j(o);if(i.length===0)return n;let a=L(i[0],"tags",o),p=[...s].sort();if(a!==null&&JSON.stringify([...a].sort())===JSON.stringify(p))return n;let c=i.flatMap(m=>{let g=s.length===0?W(m,"tags",o):O(m,"tags",$(p),o);return g?[g]:[]});return c.length>0?z(n,c):n}};var xr={vitest:()=>new Ce,playwright:()=>new ke,cypress:()=>new xe,jest:()=>new ve},eo={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function to(r){let e=Fe.createSourceFile("detect.ts",r,Fe.ScriptTarget.Latest,!0);for(let t of e.statements){if(!Fe.isImportDeclaration(t)||!Fe.isStringLiteral(t.moduleSpecifier))continue;let s=eo[t.moduleSpecifier.text];if(s)return s}return null}var dt=class{constructor(e,t,s){this.rootDir=e;this.defaultFramework=t;this.frameworkOverrides=s}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return E.has(mt.extname(e).toLowerCase())}apply(e,t,s){let n=to(t)??this.matchOverride(e)??this.defaultFramework;return(xr[n]??xr.vitest)().apply(e,t,s)}matchOverride(e){let t=mt.relative(this.rootDir,e).split(mt.sep).join("/");for(let[s,n]of this.frameworkOverrides)if(gr(s,t))return n;return null}};function Sr(r="vitest",e={},t=process.cwd()){return[new Se,new we,new be,new dt(t,r,Object.entries(e))]}function br(r,e){return e.find(t=>t.canHandle(r))??null}var so=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,no=new Set(["import"]),oo=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function io(r,e,t,s){let n;try{n=await vr.readFile(r,"utf8")}catch(a){return{path:r,status:"error",error:String(a)}}let o=br(r,s);if(!o)return{path:r,status:"unchanged"};let i=o.apply(r,n,e);return i===n?{path:r,status:"unchanged"}:(t||await vr.writeFile(r,i,"utf8"),{path:r,status:"updated"})}async function ht(r,e,t){let s=H(e),n=s.tagApplier?.framework??"vitest",o=s.tagApplier?.frameworkOverrides??{},i=Sr(n,o,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let p of r.nodes.values()){if(p.category!=="test")continue;let c=new Set,m=[];for(let b of p.tags)no.has(b.kind)&&so.test(b.name)&&(oo.has(b.name.toLowerCase())||c.has(b.name)||(c.add(b.name),m.push(b.name)));m.sort();let g=ro.resolve(e,p.path),h=await io(g,m,t.dryRun,i);h.path=p.path,a.files.push(h),h.status==="updated"?a.updated++:h.status==="unchanged"?a.unchanged++:a.errors++}return a}var Ee=class{isTestNode(e){return e.category==="test"||e.tags.some(t=>t.name==="test")}};import Re from"fs";import w from"path";import{execSync as kr}from"child_process";var Te=class{getChangedFiles(){try{let t=["git diff --name-only","git diff --cached --name-only","git ls-files --others --exclude-standard"].flatMap(s=>{try{return kr(s,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
20
- `).map(o=>o.trim()).filter(o=>o!=="")}catch{return[]}});return Array.from(new Set(t))}catch(e){return console.error("Error getting git diff:",e),[]}}};function wr(r,e){let s=kr(`git -C "${r}" log --follow --format="%ae" --since="90 days ago" -- "${e}"`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
21
- `).filter(Boolean);return{commitCount90d:s.length,lastAuthor:s[0]}}import Pe from"fs";import ao from"path";import Cr from"js-yaml";function Fr(r){let e=r.lastIndexOf("@");return e>0?r.substring(0,e):r}function po(r){return r.replace(/:$/,"").split(",").map(e=>{let t=e.trim();return t.startsWith('"')&&(t=t.slice(1)),t.endsWith('"')&&(t=t.slice(0,-1)),Fr(t)}).filter(Boolean)}function co(r,e){let t=r.startsWith("/")?r.slice(1):r,s=t.lastIndexOf("@");return s>0?{name:t.substring(0,s),version:e||t.substring(s+1)}:{name:t,version:e}}function lo(r){try{let e=Cr.load(r),t={dependencies:{}};for(let[s,n]of Object.entries(e))if(!(s==="__metadata"||!n?.version))for(let o of s.split(", ")){let i=Fr(o);i&&(t.dependencies[i]={version:n.version,...n.dependencies!==void 0&&{dependencies:n.dependencies}})}return t}catch{return null}}function uo(r){let e={dependencies:{}};for(let t of r.split(/\n\n+/)){let s=t.split(`
22
- `).filter(p=>p.trim().length>0&&!p.trim().startsWith("#"));if(s.length<2)continue;let n=s[0];if(!n||n.startsWith(" "))continue;let o=po(n);if(o.length===0)continue;let a=s.find(p=>p.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let p of o)e.dependencies[p]={version:a}}return e}function fo(r){let e=Pe.readFileSync(r,"utf-8"),t=JSON.parse(e),s={dependencies:{}};if(t.packages)for(let[n,o]of Object.entries(t.packages)){if(!n.startsWith("node_modules/"))continue;let i=n.replace("node_modules/","");i.includes("node_modules/")||(s.dependencies[i]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}else if(t.dependencies)for(let[n,o]of Object.entries(t.dependencies))s.dependencies[n]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}};return s}function go(r){let e=Pe.readFileSync(r,"utf-8");if(e.includes("__metadata:")){let t=lo(e);if(t!==null)return t}return uo(e)}function mo(r){let e=Pe.readFileSync(r,"utf-8"),t={dependencies:{}};try{let s=Cr.load(e);if(s.packages)for(let[n,o]of Object.entries(s.packages)){let{name:i,version:a}=co(n,o.version);i&&(t.dependencies[i]={version:a,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}if(s.dependencies)for(let[n,o]of Object.entries(s.dependencies)){if(t.dependencies[n])continue;let i=typeof o=="string"?o:o.version;t.dependencies[n]={version:i||""}}}catch{}return t}function Er(r){let e=[["package-lock.json",fo],["yarn.lock",go],["pnpm-lock.yaml",mo]];for(let[t,s]of e){let n=ao.join(r,t);if(Pe.existsSync(n))return s(n)}return null}import Tr from"path";function A(r){switch(Tr.extname(r).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";default:return"unknown"}}function F(r){let e=Tr.extname(r).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import ho from"coffeescript";function yo(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function xo(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}function So(r,e){let t=e.source?.value;return t?{fromPath:r,toPath:"",rawSpecifier:t,isStyle:F(t),type:"static"}:null}function bo(r,e){let t=e.variable?.base?.value==="require",s=e.args?.[0]?.base?.value;return!t||!s?null:{fromPath:r,toPath:"",rawSpecifier:s,isStyle:F(s),type:"require"}}function vo(r,e,t){let s=e.constructor?.name;if(s==="ImportDeclaration"){let n=So(r,e);n&&t.push(n)}else if(s==="Call"){let n=bo(r,e);n&&t.push(n)}}function yt(r,e,t){if(!(!e||typeof e!="object")){vo(r,e,t);for(let s in e){if(s==="locationData")continue;let n=e[s];if(!(!n||typeof n!="object"))if(Array.isArray(n))for(let o of n)yt(r,o,t);else yt(r,n,t)}}}function Pr(r,e){let t=yo(e),s=xo(r,t),n=[];try{yt(r,ho.nodes(e),n)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}import{AstBuilder as ko,GherkinClassicTokenMatcher as wo,Parser as Co}from"@cucumber/gherkin";import{IdGenerator as Fo}from"@cucumber/messages";var Eo=Fo.uuid();function xt(r,e){let t=new Set;try{let s=new ko(Eo),n=new wo,i=new Co(s,n).parse(e);i.feature&&(i.feature.tags.forEach(a=>{t.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),i.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(p=>{t.add(p.name.startsWith("@")?p.name.slice(1):p.name)}),a.scenario.examples.forEach(p=>{p.tags.forEach(c=>{t.add(c.name.startsWith("@")?c.name.slice(1):c.name)})})),a.rule&&a.rule.children.forEach(p=>{p.scenario&&p.scenario.tags.forEach(c=>{t.add(c.name.startsWith("@")?c.name.slice(1):c.name)})})}))}catch(s){console.warn(`[GherkinParser] Failed to parse ${r}:`,s)}return{imports:[],exports:[],tags:Array.from(t).map(s=>({name:s,kind:"comment-marker"})),category:"test"}}_("gherkin",xt);import To from"path";import{parser as Po}from"@lezer/go";var Ao=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,Io=/^\/\/go:build\s+(.+)$/,Mo=/^\/\/\s*\+build\s+(.+)$/;function Ir(r,e){let t=[],s=new Map,n=new Set,o=new Set,a=Po.parse(e).cursor();do switch(a.name){case"LineComment":{let g=e.slice(a.from,a.to),h=g.match(Ao);h?.[1]&&n.add(h[1]);let b=g.match(Io);b&&Ar(b[1],o);let M=g.match(Mo);M&&Ar(M[1],o);break}case"ImportSpec":{let g=a.node.getChild("String");if(g){let b=e.slice(g.from,g.to).slice(1,-1);t.push({fromPath:r,toPath:"",rawSpecifier:b,isExternal:!0,isStyle:!1,type:"static"})}break}case"FunctionDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let g=a.node.getChild("DefName")??a.node.getChild("TypeSpec")?.getChild("DefName")??a.node.getChild("VarSpec")?.getChild("DefName")??a.node.getChild("ConstSpec")?.getChild("DefName");if(g){let h=e.slice(g.from,g.to);h!=="_"&&/^[A-Z]/.test(h)&&!s.has(h)&&s.set(h,{name:h})}break}}while(a.next());let p=t.some(g=>g.rawSpecifier==="testing"),c=To.basename(r).endsWith("_test.go")||n.has("test")||p?"test":"logic",m=new Set([...n,...o]);return{imports:t,exports:Array.from(s.values()),tags:Array.from(m).map(g=>({name:g,kind:"comment-marker"})),category:c}}function Ar(r,e){for(let t of r.split(/[\s,&|!()]+/)){let s=t.trim();s&&s!=="ignore"&&e.add(s)}}import Ro from"livescript";function B(r){return r.startsWith("'")||r.startsWith('"')?r.slice(1,-1):r}function No(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function Go(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}var Do=new Set(["first_line","first_column","last_line","last_column","line","column"]);function _o(r,e){let t=r.constructor?.name||r.type;if(t==="Import"){let s=r.right?.value;if(typeof s=="string"){let n=B(s);return{fromPath:e,toPath:"",rawSpecifier:n,isStyle:F(n),type:"static"}}}if(t==="Chain"&&r.head?.value==="require"){let s=r.tails?.[0];if(s?.constructor?.name==="Call"||s?.type==="Call"){let n=s.args?.[0]?.value;if(typeof n=="string"){let o=B(n);return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:F(o),type:"require"}}}}return null}function St(r,e){if(!r||typeof r!="object")return[];let t=[],s=_o(r,e);s&&t.push(s);for(let n in r){if(Do.has(n))continue;let o=r[n];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let i of o)t.push(...St(i,e));else t.push(...St(o,e))}return t}function Mr(r,e){let t=No(e),s=Go(r,t),n=[];try{n=St(Ro.ast(e),r)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}import jo from"luaparse";function Lo(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function Oo(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}function Wo(r,e){let t=[];function s(n){if(!(!n||typeof n!="object")){if((n.type==="CallExpression"||n.type==="StringCallExpression")&&n.base?.type==="Identifier"&&n.base?.name==="require"){let o;if(n.type==="CallExpression"){let i=n.arguments?.[0];i?.type==="StringLiteral"&&(o=B(i.raw))}else if(n.type==="StringCallExpression"){let i=n.argument;i?.type==="StringLiteral"&&(o=B(i.raw))}o&&t.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:F(o),type:"require"})}for(let o in n){if(o==="loc")continue;let i=n[o];if(i&&typeof i=="object")if(Array.isArray(i))for(let a of i)s(a);else s(i)}}}return s(r),t}function Rr(r,e){let t=Lo(e),s=Oo(r,t),n=[];try{let o=jo.parse(e);n=Wo(o,r)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}import zo from"path";import{parser as $o}from"@lezer/python";var Bo=new Set(["pytest","unittest","nose","hypothesis"]);function Nr(r,e){let t=[],s=[],n=new Set,o=zo.basename(r).toLowerCase(),a=$o.parse(e).cursor();do switch(a.name){case"Comment":{let c=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);c?.[1]&&n.add(c[1]);break}case"ImportStatement":{for(let c of Uo(a.node,e,r))t.push(c);break}case"FunctionDefinition":case"ClassDefinition":{let c=a.node.parent;if(c?.name==="Script"||c?.name==="DecoratedStatement"&&c.parent?.name==="Script"){let g=a.node.getChild("VariableName");g&&s.push({name:e.slice(g.from,g.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let c=a.node.firstChild;c?.name==="VariableName"&&s.push({name:e.slice(c.from,c.to)})}break}}while(a.next());let p=Ho(o,t,n);return p==="test"&&n.add("test"),{imports:t,exports:s,tags:Array.from(n).map(c=>({name:c,kind:"comment-marker"})),category:p}}function Uo(r,e,t){let s=r.firstChild;return s?s.name==="from"?qo(r,e,t):Ko(r,e,t):[]}function qo(r,e,t){let s=r.firstChild;if(!s)return[];let n=s.nextSibling;for(;n&&n.name!=="import";)n=n.nextSibling;if(!n)return[];let o=e.slice(s.to,n.from).trim(),i=Jo(n.nextSibling,e);if(!i.length)return[];let a=0;for(;a<o.length&&o[a]===".";)a++;let p=o.slice(a);if(a===0)return[te(t,o,i,!0)];let c=a===1?"./":"../".repeat(a-1);return p?[te(t,c+p.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[te(t,c.slice(0,-1),["*"],!1)]:i.map(m=>te(t,c+m,[m],!1))}function Ko(r,e,t){let s=[],n=r.firstChild?.nextSibling??null;for(;n;){if(n.name==="VariableName"){let o=e.slice(n.from,n.to);for(;n.nextSibling?.name==="."&&n.nextSibling.nextSibling?.name==="VariableName";)n=n.nextSibling.nextSibling,o+=`.${e.slice(n.from,n.to)}`;n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling),s.push(te(t,o,["*"],!0))}n=n.nextSibling}return s}function Jo(r,e){let t=[],s=r;for(;s;)s.name==="*"?t.push("*"):s.name==="VariableName"&&(t.push(e.slice(s.from,s.to)),s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling)),s=s.nextSibling;return t}function te(r,e,t,s){return{fromPath:r,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:s,type:"static",symbols:t.length>0?t:void 0}}function Ho(r,e,t){return r.startsWith("test_")||r.endsWith("_test.py")?"test":r==="conftest.py"||r==="setup.py"?"config":t.has("test")||e.some(s=>Bo.has(s.rawSpecifier))?"test":"logic"}import Dr from"path";import l from"typescript";import d from"typescript";function Qo(r){let e=1;function t(s){switch(s.kind){case d.SyntaxKind.IfStatement:case d.SyntaxKind.ConditionalExpression:case d.SyntaxKind.ForStatement:case d.SyntaxKind.ForInStatement:case d.SyntaxKind.ForOfStatement:case d.SyntaxKind.WhileStatement:case d.SyntaxKind.DoStatement:case d.SyntaxKind.CatchClause:case d.SyntaxKind.CaseClause:e++;break;case d.SyntaxKind.BinaryExpression:{let n=s.operatorToken.kind;(n===d.SyntaxKind.AmpersandAmpersandToken||n===d.SyntaxKind.BarBarToken||n===d.SyntaxKind.QuestionQuestionToken)&&e++;break}}d.forEachChild(s,t)}return t(r),e}function Vo(r){let e=0;function t(s,n,o){if(d.isIfStatement(s)){e+=o?1:1+n;let a=o?n:n+1;t(s.expression,a,!1),t(s.thenStatement,a,!1),s.elseStatement&&(d.isIfStatement(s.elseStatement)?t(s.elseStatement,n,!0):(e+=1,t(s.elseStatement,n+1,!1)));return}if(d.isForStatement(s)||d.isForInStatement(s)||d.isForOfStatement(s)||d.isWhileStatement(s)||d.isDoStatement(s)||d.isSwitchStatement(s)){e+=1+n,d.forEachChild(s,a=>t(a,n+1,!1));return}if(d.isCatchClause(s)){e+=1+n,d.forEachChild(s,a=>t(a,n,!1));return}if(d.isConditionalExpression(s)&&(e+=1),d.isBinaryExpression(s)){let a=s.operatorToken.kind;(a===d.SyntaxKind.AmpersandAmpersandToken||a===d.SyntaxKind.BarBarToken||a===d.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(n>0&&(d.isFunctionDeclaration(s)||d.isFunctionExpression(s)||d.isArrowFunction(s))){e+=1+n,d.forEachChild(s,a=>t(a,n+1,!1));return}d.forEachChild(s,a=>t(a,n,!1))}return t(r,0,!1),e}function bt(r){return{complexity:Qo(r),cognitiveComplexity:Vo(r)}}import S from"typescript";var vt=new Set(["test","describe","it"]);function Gr(r,e){Xo(r,e),Yo(r,e),ei(r,e),ti(r,e)}function Xo(r,e){if((S.isFunctionDeclaration(r)||S.isVariableDeclaration(r))&&r.name&&S.isIdentifier(r.name)&&Zo(r)){let t;if(S.isFunctionDeclaration(r))t="function";else{let s=r.initializer;t=s&&(S.isArrowFunction(s)||S.isFunctionExpression(s))?"function":"variable"}e.tags.add({name:r.name.text,kind:t})}}function Zo(r){if(S.isFunctionDeclaration(r))return S.isSourceFile(r.parent);let e=r.parent?.parent;return!!e&&S.isSourceFile(e.parent)}function Yo(r,e){if(!S.isStringLiteral(r))return;let t=r.text.match(/@[\w-]+/g);if(t)for(let s of t)e.tags.add({name:s.substring(1),kind:"comment-marker"})}function ei(r,e){if(!S.isSourceFile(r))return;let t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=r.getFullText(),n=t.exec(s);for(;n!==null;)n[1]&&e.tags.add({name:n[1],kind:"comment-marker"}),n=t.exec(s)}function ti(r,e){if(S.isCallExpression(r)&&ri(r.expression))for(let t of r.arguments)S.isObjectLiteralExpression(t)&&si(t,e)}function ri(r){return S.isIdentifier(r)?vt.has(r.text):!!(S.isPropertyAccessExpression(r)&&(vt.has(r.name.text)||S.isIdentifier(r.expression)&&vt.has(r.expression.text)))}function si(r,e){for(let t of r.properties){if(!S.isPropertyAssignment(t)||!S.isIdentifier(t.name)||t.name.text!=="tags"&&t.name.text!=="tag")continue;let{initializer:s}=t,n=S.isArrayLiteralExpression(s)?s.elements.filter(S.isStringLiteral):t.name.text==="tag"&&S.isStringLiteral(s)?[s]:[];for(let o of n)e.tags.add({name:o.text.replace(/^@/,""),kind:"comment-marker"})}}function kt(r,e,t){let s=[],n=new Map,o=new Set,i=l.createSourceFile(r,e,l.ScriptTarget.Latest,!0,t==="typescript"?l.ScriptKind.TSX:l.ScriptKind.JSX),a={filePath:r,imports:s,exports:n,tags:o,rawCallEdges:[],sourceFile:i,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},p=ce=>{ai(ce,a),l.forEachChild(ce,p)};p(i);let c=xi(r,a);(c==="test"||c==="barrel")&&o.add({name:c,kind:"comment-marker"}),c!=="test"&&Si(a,i);let m=i.statements[0],g=m?jr(m):void 0,{complexity:h,cognitiveComplexity:b}=bt(i),M=ni(i);return{imports:s,exports:Array.from(n.values()),tags:Array.from(o),category:c,rawCallEdges:a.rawCallEdges??[],complexity:h,cognitiveComplexity:b,...M.length>0?{functions:M}:{},...g!==void 0?{description:g}:{}}}function ni(r){let e=[],t=(n,o)=>{let{complexity:i,cognitiveComplexity:a}=bt(o),p=r.getLineAndCharacterOfPosition(o.getStart(r)).line+1;e.push({name:n,line:p,complexity:i,cognitiveComplexity:a})},s=(n,o)=>{if(l.isFunctionDeclaration(n)&&n.name&&n.body?t(n.name.text,n):l.isVariableDeclaration(n)&&l.isIdentifier(n.name)&&n.initializer&&(l.isArrowFunction(n.initializer)||l.isFunctionExpression(n.initializer))?t(n.name.text,n.initializer):o&&l.isMethodDeclaration(n)&&l.isIdentifier(n.name)&&n.body?t(`${o}.${n.name.text}`,n):o&&l.isConstructorDeclaration(n)&&n.body?t(`${o}.constructor`,n):o&&l.isGetAccessorDeclaration(n)&&l.isIdentifier(n.name)&&n.body?t(`${o}.get ${n.name.text}`,n):o&&l.isSetAccessorDeclaration(n)&&l.isIdentifier(n.name)&&n.body&&t(`${o}.set ${n.name.text}`,n),l.isClassDeclaration(n)&&n.name){let i=n.name.text;l.forEachChild(n,a=>s(a,i));return}l.forEachChild(n,i=>s(i,o))};return s(r,void 0),e}function _r(r,e,t,s){let n={name:r},o=jr(t);o!==void 0&&(n.doc=o);let i=oi(e);i!==void 0&&(n.flags=i);let a=ii(e,s);return a!==void 0&&(n.signature=a),n}function jr(r){let e=l.getJSDocCommentsAndTags(r);for(let t of e)if(l.isJSDoc(t)&&t.comment)return l.getTextOfJSDocComment(t.comment)||void 0}function oi(r){let e=new Set(["deprecated","internal","public","alpha","beta"]),t=l.getJSDocTags(r).map(s=>s.tagName.text).filter(s=>e.has(s));return t.length>0?t:void 0}function ii(r,e){let t=l.createPrinter({removeComments:!0}),s=n=>t.printNode(l.EmitHint.Unspecified,n,e);if(l.isFunctionDeclaration(r)||l.isMethodDeclaration(r)){let n=r.parameters.map(s).join(", "),o=r.type?s(r.type):"void";return`${r.typeParameters?`<${r.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${n}) => ${o}`}if(l.isVariableDeclaration(r)){if(r.type)return s(r.type);if(r.initializer&&(l.isArrowFunction(r.initializer)||l.isFunctionExpression(r.initializer))){let n=r.initializer,o=n.parameters.map(s).join(", "),i=n.type?s(n.type):"unknown";return`(${o}) => ${i}`}return}if(l.isClassDeclaration(r)&&r.name)return`class ${r.name.text}`;if(l.isInterfaceDeclaration(r))return`interface ${r.name.text}`;if(l.isTypeAliasDeclaration(r))return s(r.type);if(l.isEnumDeclaration(r))return`enum ${r.name.text}`}function ai(r,e){pi(r,e),ci(r,e),ui(r,e),fi(r,e),yi(r,e),Gr(r,e)}function pi(r,e){if(!l.isSourceFile(r))return;let t=r.statements.filter(s=>!l.isEmptyStatement(s));e.totalStatements=t.length,e.exportStatements=t.filter(s=>l.isExportDeclaration(s)||l.isExportAssignment(s)||wt(s)).length}function ci(r,e){if(l.isJsxElement(r)||l.isJsxSelfClosingElement(r)||l.isJsxFragment(r)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(l.isFunctionDeclaration(r)||l.isMethodDeclaration(r)||l.isArrowFunction(r)||l.isClassDeclaration(r)||l.isVariableStatement(r)||l.isEnumDeclaration(r)){e.hasTypesOnly=!1;return}l.isExportDeclaration(r)&&!li(r)&&(e.hasTypesOnly=!1)}function li(r){return r.isTypeOnly?!0:!r.exportClause||!l.isNamedExports(r.exportClause)?!1:r.exportClause.elements.every(e=>e.isTypeOnly)}function ui(r,e){if(!l.isImportDeclaration(r)||!r.moduleSpecifier||!l.isStringLiteral(r.moduleSpecifier))return;let t=[];if(r.importClause&&(r.importClause.name&&t.push("default"),r.importClause.namedBindings))if(l.isNamedImports(r.importClause.namedBindings))for(let n of r.importClause.namedBindings.elements)t.push(n.name.text);else l.isNamespaceImport(r.importClause.namedBindings)&&t.push("*");let s=t.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.moduleSpecifier.text,isStyle:F(r.moduleSpecifier.text),type:s,symbols:t.length>0?t:void 0})}function fi(r,e){l.isExportDeclaration(r)?gi(r,e):l.isExportAssignment(r)?e.exports.set("default",{name:"default"}):wt(r)&&hi(r,e)}function gi(r,e){if(r.moduleSpecifier&&l.isStringLiteral(r.moduleSpecifier))mi(r,r.moduleSpecifier.text,e);else if(r.exportClause&&l.isNamedExports(r.exportClause))for(let t of r.exportClause.elements){let s=t.name.text;e.exports.set(s,{name:s})}}function mi(r,e,t){let s=di(r),n={fromPath:t.filePath,toPath:"",rawSpecifier:e,isStyle:F(e),type:"re-export"};s.length>0&&(n.symbols=s),t.imports.push(n)}function di(r){return r.exportClause?l.isNamedExports(r.exportClause)?r.exportClause.elements.map(e=>e.name.text):[]:["*"]}function hi(r,e){if((l.isFunctionDeclaration(r)||l.isClassDeclaration(r)||l.isInterfaceDeclaration(r)||l.isTypeAliasDeclaration(r)||l.isEnumDeclaration(r))&&r.name){let s=r.name.text;e.exports.set(s,_r(s,r,r,e.sourceFile));return}if(l.isVariableStatement(r)){for(let s of r.declarationList.declarations)if(l.isIdentifier(s.name)){let n=s.name.text;e.exports.set(n,_r(n,s,r,e.sourceFile))}}}function yi(r,e){if(!l.isCallExpression(r))return;let t=r.arguments[0];!t||!l.isStringLiteral(t)||(r.expression.kind===l.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.text,isStyle:F(t.text),type:"dynamic"}):l.isIdentifier(r.expression)&&r.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.text,isStyle:F(t.text),type:"require"}))}function xi(r,e){let t=Dr.basename(r).toLowerCase(),s=Dr.extname(r).toLowerCase();return J().some(o=>t.includes(o))?"test":Nt(t)?"config":e.imports.some(o=>De().some(i=>o.rawSpecifier.includes(i)))?"test":s===".tsx"||s===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>je()?"barrel":"logic"}function wt(r){return l.canHaveModifiers(r)&&l.getModifiers(r)?.some(e=>e.kind===l.SyntaxKind.ExportKeyword)===!0}function Si(r,e){let t=r.rawCallEdges??[];r.rawCallEdges=t;let s=new Map;for(let n of e.statements){if(!l.isImportDeclaration(n)||!l.isStringLiteral(n.moduleSpecifier))continue;let o=n.moduleSpecifier.text,i=n.importClause;if(i&&(i.name&&s.set(i.name.text,o),i.namedBindings&&l.isNamedImports(i.namedBindings)))for(let a of i.namedBindings.elements)s.set(a.name.text,o)}if(s.size!==0)for(let n of e.statements){let o=vi(n);if(o){let i=ki(n);i&&Ae(i,o,s,t);continue}l.isClassDeclaration(n)&&n.name&&bi(n,s,t)}}function bi(r,e,t){let s=r.name.text;for(let n of r.members)l.isMethodDeclaration(n)&&n.body&&l.isIdentifier(n.name)?Ae(n.body,`${s}.${n.name.text}`,e,t):l.isConstructorDeclaration(n)&&n.body&&Ae(n.body,`${s}.constructor`,e,t)}function vi(r){if(wt(r)){if(l.isFunctionDeclaration(r)&&r.name)return r.name.text;if(l.isVariableStatement(r)){for(let e of r.declarationList.declarations)if(l.isIdentifier(e.name)&&e.initializer&&(l.isArrowFunction(e.initializer)||l.isFunctionExpression(e.initializer)))return e.name.text}}}function ki(r){if(l.isFunctionDeclaration(r))return r.body;if(l.isVariableStatement(r)){for(let e of r.declarationList.declarations)if(e.initializer&&(l.isArrowFunction(e.initializer)||l.isFunctionExpression(e.initializer)))return e.initializer}}function Ae(r,e,t,s){if(l.isCallExpression(r)&&l.isIdentifier(r.expression)){let n=r.expression.text,o=t.get(n);o&&!s.some(i=>i.from===e&&i.to===n&&i.toSpecifier===o)&&s.push({from:e,to:n,toSpecifier:o})}l.forEachChild(r,n=>Ae(n,e,t,s))}function Ie(r,e){if(e.length===0)return"ui";let t=!1;return r.walk(s=>{if(s.type==="rule")return t=!0,!1}),t?"ui":"barrel"}import Or from"postcss";import*as wi from"postcss-less";var Ci=wi,Wr=new Set(["reference","inline"]);function Lr(r){return r.startsWith("~")||r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("data:")}function Fi(r){let e=r.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function Ei(r,e){let t=r.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(t){let o=t[1]?.trim()??"",i=t[2]??"";if(!i)return null;let a=Wr.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...Lr(i)?{isExternal:!0}:{}}}let s=r.match(/^url\(['"]?([^'")]+)['"]?\)/),n=s?s[1]?.trim()??"":r.match(/^['"]([^'"]+)['"]/)?.[1]??"";return n?{fromPath:e,toPath:"",rawSpecifier:n,isStyle:!0,type:"static",...Lr(n)?{isExternal:!0}:{}}:null}function Ti(r,e){let t=[],s=/url\(['"]?([^'")]+)['"]?\)/g,n=s.exec(r);for(;n!==null;){let o=n[1]?.trim()??"";Fi(o)&&t.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),n=s.exec(r)}return t}function zr(r,e){let t=[];return r.walk(s=>{if(s.type==="atrule"&&s.name==="import"){let n=Ei(s.params,e);n&&t.push(n)}s.type==="decl"&&t.push(...Ti(s.value,e))}),t}function Pi(r){return r.replace(/(?<!:)\/\/.*/g,"")}function Ai(r,e){let t=[],s=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,n=s.exec(r);for(;n!==null;){let o=n[1]?.trim()??"",i=n[2]??"";if(i){let a=Wr.has(o)?"side-effect":"static";t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}n=s.exec(r)}return t}function $r(r,e){let t=Or.parse(Pi(r));return{imports:zr(t,e),root:t}}function Br(r,e){try{let t=Ci.parse(r);return{imports:zr(t,e),root:t}}catch{return{imports:Ai(r,e),root:Or.parse("")}}}import{parse as Ii}from"postcss-scss";function Mi(r){return!!(r.startsWith("sass:")||r.startsWith("~")||r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||!r.startsWith(".")&&!r.startsWith("/")&&!r.startsWith("_"))}function Ri(r){let e=r.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let t=e[1],n=r.match(/\bas\s+(\S+)/)?.[1];return n!==void 0?{specifier:t,alias:n}:{specifier:t}}function Ur(r,e){let t=Ii(r),s=[];return t.walk(n=>{if(n.type!=="atrule")return;let{name:o,params:i}=n;if(o!=="import"&&o!=="use"&&o!=="forward")return;let{specifier:a,alias:p}=Ri(i);if(!a)return;let c={fromPath:e,toPath:"",rawSpecifier:a,isStyle:!0,type:o==="forward"?"re-export":"static",...Mi(a)?{isExternal:!0}:{}};p&&(c.symbols=[p]),s.push(c)}),{imports:s,root:t}}function qr(r,e){let t=[],s=/@require\s+['"]([^'"]+)['"]/g,n=s.exec(r);for(;n!==null;){let i=n[1];i&&t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"require"}),n=s.exec(r)}let o=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(n=o.exec(r);n!==null;){let i=n[1];i&&t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),n=o.exec(r)}return t}function Kr(r,e){if(e.length===0)return"ui";try{let t=Ge("stylus");return new t.Parser(r).parse().nodes.some(o=>o.constructor.name!=="Import")?"ui":"barrel"}catch{return r.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function re(r,e){let t=A(r);if(t==="stylus"){let o=qr(e,r);return{imports:o,exports:[],tags:[],category:Kr(e,o)}}if(t==="scss"){let{imports:o,root:i}=Ur(e,r);return{imports:o,exports:[],tags:[],category:Ie(i,o)}}if(t==="less"){let{imports:o,root:i}=Br(e,r);return{imports:o,exports:[],tags:[],category:Ie(i,o)}}let{imports:s,root:n}=$r(e,r);return{imports:s,exports:[],tags:[],category:Ie(n,s)}}for(let[r,e]of[["javascript",(t,s)=>kt(t,s,"javascript")],["typescript",(t,s)=>kt(t,s,"typescript")],["css",re],["scss",re],["less",re],["stylus",re],["coffeescript",Pr],["livescript",Mr],["lua",Rr],["python",Nr],["go",Ir],["gherkin",xt]])_(r,e);async function Jr(r,e){let t=A(r),s=ir(t);return s?s(r,e):{imports:[],exports:[],tags:[],category:"other"}}import Hr from"path";function Vr(r,e){for(let t of r.values()){let s=e.get(t.path);s!==void 0&&(t.coveragePct=s)}}function Xr(r,e){for(let t of r)if(t.isExternal){let s=t.rawSpecifier.startsWith("@")?t.rawSpecifier.split("/").slice(0,2).join("/"):t.rawSpecifier.split("/")[0];s&&!e.some(n=>n.name===s)&&e.push({name:s,kind:"library"})}}function Zr(r){for(let e of r.values())if(e.category==="test")for(let t of e.imports){if(t.isExternal||!t.toPath)continue;let s=r.get(t.toPath);s&&(s.category!=="logic"&&s.category!=="barrel"||(s.testedBy??=[],s.testedBy.includes(e.path)||s.testedBy.push(e.path)))}}function Qr(r){return Math.round(r*1e4)/1e4}function Yr(r){for(let e of r.values()){let t=[];for(let s of e.imports){if(s.isExternal||!s.toPath)continue;let n=r.get(s.toPath);if(!n||n.exports.length===0)continue;let o;if(s.symbols===void 0){if(s.type==="side-effect")continue;o=1}else s.symbols.includes("*")?o=1:o=s.symbols.length/n.exports.length;s.exportUsageRatio=Qr(Math.min(1,o)),t.push(s.exportUsageRatio)}t.length>0&&(e.avgExportUsage=Qr(t.reduce((s,n)=>s+n,0)/t.length),e.maxExportUsage=Math.max(...t))}}function Ct(r,e,t){e&&(r.some(s=>s.name===e&&s.kind===t)||r.push({name:e,kind:t}))}function Ni(r,e){let t=e.toPath,s=Hr.basename(t,Hr.extname(t)).replace(/\.(test|spec)$/,"");Ct(r.tags,s,"import")}function Gi(r,e){if(!(!e.symbols||e.symbols.includes("*")))for(let t of e.symbols)Ct(r.tags,t,"import")}function Di(r,e,t){let s=t.get(e.toPath);if(!(!s||s.category==="test"))for(let n of s.tags)n.kind==="comment-marker"&&Ct(r.tags,n.name,"comment-marker")}function es(r){for(let e of r.values())if(e.category==="test")for(let t of e.imports)!t.toPath||t.isExternal||(Ni(e,t),Gi(e,t),Di(e,t,r))}import Me from"fs";import I from"path";import ss from"fs";import U from"path";var se=class{extensions=[".go"];goModCache=new Map;resolve(e,t,s,n){let{mod:o,replaces:i}=this.readGoMod(s);if(!o)return null;let a=this.applyReplace(t,i,s);if(a!==void 0)return rs(a);if(t!==o&&!t.startsWith(`${o}/`))return null;let p=t.slice(o.length).replace(/^\//,"");return p?rs(U.join(s,p)):null}readGoMod(e){let t=this.goModCache.get(e);if(t!==void 0)return t;let s={mod:null,replaces:new Map};try{let n=ss.readFileSync(U.join(e,"go.mod"),"utf-8"),o=_i(n,e);return this.goModCache.set(e,o),o}catch{return this.goModCache.set(e,s),s}}applyReplace(e,t,s){for(let[n,o]of t){if(e===n)return o;if(e.startsWith(`${n}/`)){let i=e.slice(n.length+1);return U.join(o,i)}}}};function _i(r,e){let t=r.split(`
23
- `),s=null,n=new Map,o=!1;for(let i of t){let a=i.trim();if(a.startsWith("module ")){s=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){o=!0;continue}if(o&&a===")"){o=!1;continue}if(o&&a.includes("=>")){ts(a,e,n);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&ts(a.replace(/^replace\s+/,""),e,n)}return{mod:s,replaces:n}}function ts(r,e,t){let[s,n]=r.split("=>").map(a=>a.trim());if(!s||!n)return;let o=s.split(/\s+/)[0];if(!n.startsWith(".")&&!n.startsWith("/"))return;let i=U.isAbsolute(n)?n:U.resolve(e,n);t.set(o,i)}function rs(r){let e;try{e=ss.readdirSync(r,{withFileTypes:!0})}catch{return null}let t=e.filter(s=>s.isFile()&&s.name.endsWith(".go")&&!s.name.endsWith("_test.go")).map(s=>({path:U.join(r,s.name),isExternal:!1})).sort((s,n)=>s.path.localeCompare(n.path));return t.length>0?t:null}import ji from"fs";import Ft from"path";var ne=class{extensions=[".lua"];resolve(e,t,s,n){let o=t.replace(/\./g,Ft.sep),i=[s,Ft.join(s,"lib")];for(let a of i){if(!ji.existsSync(a))continue;let p=n(Ft.join(a,"_dummy.lua"),o);if(p)return[p]}return null}};import Li from"fs";import Et from"path";var oe=class{extensions=[".py"];resolve(e,t,s,n){let o=t.replace(/\./g,Et.sep),i=Et.join(s,`${o}.py`);if(ns(i))return[{path:i,isExternal:!1}];let a=Et.join(s,o,"__init__.py");return ns(a)?[{path:a,isExternal:!1}]:null}};function ns(r){try{return Li.statSync(r,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import os from"path";var Oi=["~","http://","https://","//","data:","sass:"],ie=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,t,s,n){if(Oi.some(m=>t.startsWith(m)))return null;let o=n(e,t);if(o)return[o];let i=os.dirname(t),a=os.basename(t),p=i==="."?`_${a}`:`${i}/_${a}`,c=n(e,p);return c?[c]:null}};var q=class{constructor(e,t={}){this.rootDir=e;this.workspaceMap=t.workspaceMap??new Map,this.tsconfigSearchPaths=t.tsconfigSearchPaths??[e],this.langResolvers=t.langResolvers??[new oe,new ne,new se,new ie]}rootDir;workspaceMap;tsconfigSearchPaths;langResolvers;resolveAll(e,t){let s=this.resolvePathAlias(t);if(s)return[s];if(t.startsWith(".")||t.startsWith("/")){let i=this.resolveLocalPath(e,t);return i?[i]:[]}let n=(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,t,this.rootDir,n);if(a)return a}let o=this.resolveWorkspaceImport(t);return o?[o]:[{path:t,isExternal:!0}]}resolve(e,t){let s=this.resolvePathAlias(t);if(s)return s;if(t.startsWith(".")||t.startsWith("/"))return this.resolveLocalPath(e,t);let n=(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,t,this.rootDir,n);if(a)return a[0]??null}let o=this.resolveWorkspaceImport(t);return o||{path:t,isExternal:!0}}resolveLocalPath(e,t){let s=I.dirname(e),n=t.startsWith("/")?t:I.resolve(s,t),o=!n.startsWith(this.rootDir),i=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature"],a=n.match(/\.(js|mjs|cjs)$/);if(a){let p=n.slice(0,-a[0].length);for(let c of[".ts",".tsx"]){let m=this.tryExtensions(p,c,o);if(m)return m}}for(let p of i){let c=this.tryExtensions(n,p,o);if(c)return c}return o?{path:n,isExternal:!0}:null}tryExtensions(e,t,s){let n=e+t;if(this.isFile(n))return{path:n,isExternal:s};let o=I.join(e,`index${t}`);if(this.isFile(o))return{path:o,isExternal:s};if(t===".py"){let i=I.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:s}}return null}isFile(e){try{return Me.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){for(let t of this.tsconfigSearchPaths){let s=I.join(t,"tsconfig.json");if(Me.existsSync(s))try{let o=JSON.parse(Me.readFileSync(s,"utf-8")).compilerOptions?.paths;if(!o)continue;for(let i in o){let a=this.matchAliasPattern(i,e);if(a){let p=this.tryAliasSubstitutions(o[i],a[1]||"",t);if(p)return p}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,t){let s=this.aliasRegexCache.get(e);if(!s){let n=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");s=new RegExp(`^${n}$`),this.aliasRegexCache.set(e,s)}return t.match(s)}tryAliasSubstitutions(e,t,s=this.rootDir){let n=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let o of e){let i=o.replace("*",t),a=I.resolve(s,i);for(let p of n){let c=this.tryExtensions(a,p,!1);if(c)return c}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[t,s]of this.workspaceMap){if(e!==t&&!e.startsWith(`${t}/`))continue;let n=e.slice(t.length),o={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:t};if(!n){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let p=I.join(s,a);try{if(Me.statSync(p,{throwIfNoEntry:!1})?.isFile())return{...o,path:p}}catch{}}return{...o,path:s}}let i=this.resolveLocalPath(I.join(s,"_dummy"),n.slice(1));return i?{...o,path:i.path}:null}return null}};var Wi=["tests","test","__tests__","specs","spec"];function zi(r,e){if(r.length===0)return e;let t=r.map(i=>w.dirname(i).split(w.sep)),s=t[0];for(let i of t.slice(1)){let a=0;for(;a<s.length&&a<i.length&&s[a]===i[a];)a++;s=s.slice(0,a)}let n=s.join(w.sep)||w.sep,o=w.relative(e,n);return o.startsWith("..")||w.isAbsolute(o)?e:n}var ae=class{constructor(e,t=null,s,n,o=!1,i=new Map){this.rootDir=e;this.enableGitStats=o;this.coverageMap=i;this.previousGraph=t,this.resolver=s||new q(e),this.lockFile=Er(e),n&&(this.progressCallback=n)}rootDir;enableGitStats;coverageMap;graph={nodes:new Map};visited=new Set;previousGraph=null;resolver;lockFile=null;progressCallback;async build(e){let t=e.map(s=>w.isAbsolute(s)?s:w.resolve(this.rootDir,s));for(let s of t)await this.processFile(s);return await this.processTestFiles(zi(t,this.rootDir)),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
18
+ `+m}};function co(r){let e=r.split(`
19
+ `),t=-1;for(let n=0;n<e.length;n++){let o=e[n].trimStart();(o.startsWith("import ")||o.startsWith("from "))&&(t=n)}if(t<0)return 0;let s=0;for(let n=0;n<=t;n++)s+=e[n].length+1;return s}import xr from"path";import Sr from"typescript";var lo=/\/\/ <mokosh-tags>[\s\S]*?\/\/ <\/mokosh-tags>\n*/,Ee=class{name="vitest";canHandle(e){return E.has(xr.extname(e).toLowerCase())}apply(e,t,s){let n=t.replace(lo,""),o=Sr.createSourceFile(xr.basename(e),n,Sr.ScriptTarget.Latest,!0),i=j(o);if(i.length===0)return n;let a=O(i[0],"tags",o),p=[...s].sort();if(a!==null&&JSON.stringify([...a].sort())===JSON.stringify(p))return n;let c=i.flatMap(m=>{let g=s.length===0?W(m,"tags",o):L(m,"tags",$(p),o);return g?[g]:[]});return c.length>0?z(n,c):n}};var br={vitest:()=>new Ee,playwright:()=>new Ce,cypress:()=>new be,jest:()=>new we},uo={"@playwright/test":"playwright",cypress:"cypress","@jest/globals":"jest",vitest:"vitest"};function fo(r){let e=Pe.createSourceFile("detect.ts",r,Pe.ScriptTarget.Latest,!0);for(let t of e.statements){if(!Pe.isImportDeclaration(t)||!Pe.isStringLiteral(t.moduleSpecifier))continue;let s=uo[t.moduleSpecifier.text];if(s)return s}return null}var ht=class{constructor(e,t,s){this.rootDir=e;this.defaultFramework=t;this.frameworkOverrides=s}rootDir;defaultFramework;frameworkOverrides;name="auto";canHandle(e){return E.has(dt.extname(e).toLowerCase())}apply(e,t,s){let n=fo(t)??this.matchOverride(e)??this.defaultFramework;return(br[n]??br.vitest)().apply(e,t,s)}matchOverride(e){let t=dt.relative(this.rootDir,e).split(dt.sep).join("/");for(let[s,n]of this.frameworkOverrides)if(dr(s,t))return n;return null}};function vr(r="vitest",e={},t=process.cwd()){return[new ve,new Fe,new ke,new ht(t,r,Object.entries(e))]}function kr(r,e){return e.find(t=>t.canHandle(r))??null}var mo=/^[a-zA-Z][a-zA-Z0-9_-]{1,}$/,ho=new Set(["import"]),yo=new Set(["common","fixture","fixtures","helper","helpers","index","main","mock","mocks","setup","shared","spec","test","tests","types","util","utils"]);async function xo(r,e,t,s){let n;try{n=await wr.readFile(r,"utf8")}catch(a){return{path:r,status:"error",error:String(a)}}let o=kr(r,s);if(!o)return{path:r,status:"unchanged"};let i=o.apply(r,n,e);return i===n?{path:r,status:"unchanged"}:(t||await wr.writeFile(r,i,"utf8"),{path:r,status:"updated"})}async function yt(r,e,t){let s=H(e),n=s.tagApplier?.framework??"vitest",o=s.tagApplier?.frameworkOverrides??{},i=vr(n,o,e),a={updated:0,unchanged:0,errors:0,files:[]};for(let p of r.nodes.values()){if(p.category!=="test")continue;let c=new Set,m=[];for(let b of p.tags)ho.has(b.kind)&&mo.test(b.name)&&(yo.has(b.name.toLowerCase())||c.has(b.name)||(c.add(b.name),m.push(b.name)));m.sort();let g=go.resolve(e,p.path),h=await xo(g,m,t.dryRun,i);h.path=p.path,a.files.push(h),h.status==="updated"?a.updated++:h.status==="unchanged"?a.unchanged++:a.errors++}return a}var Te=class{isTestNode(e){return e.category==="test"||e.tags.some(t=>t.name==="test")}};import pe from"fs";import w from"path";import na from"piscina";import{execSync as xt}from"child_process";var Ae=class{getChangedFiles(){try{let t=["git diff --name-only","git diff --cached --name-only","git ls-files --others --exclude-standard"].flatMap(s=>{try{return xt(s,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
20
+ `).map(o=>o.trim()).filter(o=>o!=="")}catch{return[]}});return Array.from(new Set(t))}catch(e){return console.error("Error getting git diff:",e),[]}}};function Cr(r,e){let s=xt(`git -C "${r}" log --follow --format="%ae" --since="90 days ago" -- "${e}"`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).split(`
21
+ `).filter(Boolean),n=xt(`git -C "${r}" log -1 --format="%at" -- "${e}"`,{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim();return{commitCount90d:s.length,lastAuthor:s[0],lastCommitAt:n?Number(n)*1e3:void 0}}import Ie from"fs";import So from"path";import Fr from"js-yaml";function Er(r){let e=r.lastIndexOf("@");return e>0?r.substring(0,e):r}function bo(r){return r.replace(/:$/,"").split(",").map(e=>{let t=e.trim();return t.startsWith('"')&&(t=t.slice(1)),t.endsWith('"')&&(t=t.slice(0,-1)),Er(t)}).filter(Boolean)}function vo(r,e){let t=r.startsWith("/")?r.slice(1):r,s=t.lastIndexOf("@");return s>0?{name:t.substring(0,s),version:e||t.substring(s+1)}:{name:t,version:e}}function ko(r){try{let e=Fr.load(r),t={dependencies:{}};for(let[s,n]of Object.entries(e))if(!(s==="__metadata"||!n?.version))for(let o of s.split(", ")){let i=Er(o);i&&(t.dependencies[i]={version:n.version,...n.dependencies!==void 0&&{dependencies:n.dependencies}})}return t}catch{return null}}function wo(r){let e={dependencies:{}};for(let t of r.split(/\n\n+/)){let s=t.split(`
22
+ `).filter(p=>p.trim().length>0&&!p.trim().startsWith("#"));if(s.length<2)continue;let n=s[0];if(!n||n.startsWith(" "))continue;let o=bo(n);if(o.length===0)continue;let a=s.find(p=>p.trim().startsWith('version "'))?.match(/version "(.*?)"/)?.[1]??"";for(let p of o)e.dependencies[p]={version:a}}return e}function Co(r){let e=Ie.readFileSync(r,"utf-8"),t=JSON.parse(e),s={dependencies:{}};if(t.packages)for(let[n,o]of Object.entries(t.packages)){if(!n.startsWith("node_modules/"))continue;let i=n.replace("node_modules/","");i.includes("node_modules/")||(s.dependencies[i]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}else if(t.dependencies)for(let[n,o]of Object.entries(t.dependencies))s.dependencies[n]={version:o.version,...o.dependencies!==void 0&&{dependencies:o.dependencies}};return s}function Fo(r){let e=Ie.readFileSync(r,"utf-8");if(e.includes("__metadata:")){let t=ko(e);if(t!==null)return t}return wo(e)}function Eo(r){let e=Ie.readFileSync(r,"utf-8"),t={dependencies:{}};try{let s=Fr.load(e);if(s.packages)for(let[n,o]of Object.entries(s.packages)){let{name:i,version:a}=vo(n,o.version);i&&(t.dependencies[i]={version:a,...o.dependencies!==void 0&&{dependencies:o.dependencies}})}if(s.dependencies)for(let[n,o]of Object.entries(s.dependencies)){if(t.dependencies[n])continue;let i=typeof o=="string"?o:o.version;t.dependencies[n]={version:i||""}}}catch{}return t}function Pr(r){let e=[["package-lock.json",Co],["yarn.lock",Fo],["pnpm-lock.yaml",Eo]];for(let[t,s]of e){let n=So.join(r,t);if(Ie.existsSync(n))return s(n)}return null}import Tr from"path";function A(r){switch(Tr.extname(r).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 F(r){let e=Tr.extname(r).toLowerCase();return[".css",".scss",".sass",".less",".styl"].includes(e)}import Po from"coffeescript";function To(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function Ao(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}function Io(r,e){let t=e.source?.value;return t?{fromPath:r,toPath:"",rawSpecifier:t,isStyle:F(t),type:"static"}:null}function Mo(r,e){let t=e.variable?.base?.value==="require",s=e.args?.[0]?.base?.value;return!t||!s?null:{fromPath:r,toPath:"",rawSpecifier:s,isStyle:F(s),type:"require"}}function Ro(r,e,t){let s=e.constructor?.name;if(s==="ImportDeclaration"){let n=Io(r,e);n&&t.push(n)}else if(s==="Call"){let n=Mo(r,e);n&&t.push(n)}}function St(r,e,t){if(!(!e||typeof e!="object")){Ro(r,e,t);for(let s in e){if(s==="locationData")continue;let n=e[s];if(!(!n||typeof n!="object"))if(Array.isArray(n))for(let o of n)St(r,o,t);else St(r,n,t)}}}function Ar(r,e){let t=To(e),s=Ao(r,t),n=[];try{St(r,Po.nodes(e),n)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}import{AstBuilder as No,GherkinClassicTokenMatcher as Do,Parser as Go}from"@cucumber/gherkin";import{IdGenerator as _o}from"@cucumber/messages";var jo=_o.uuid();function bt(r,e){let t=new Set;try{let s=new No(jo),n=new Do,i=new Go(s,n).parse(e);i.feature&&(i.feature.tags.forEach(a=>{t.add(a.name.startsWith("@")?a.name.slice(1):a.name)}),i.feature.children.forEach(a=>{a.scenario&&(a.scenario.tags.forEach(p=>{t.add(p.name.startsWith("@")?p.name.slice(1):p.name)}),a.scenario.examples.forEach(p=>{p.tags.forEach(c=>{t.add(c.name.startsWith("@")?c.name.slice(1):c.name)})})),a.rule&&a.rule.children.forEach(p=>{p.scenario&&p.scenario.tags.forEach(c=>{t.add(c.name.startsWith("@")?c.name.slice(1):c.name)})})}))}catch(s){console.warn(`[GherkinParser] Failed to parse ${r}:`,s)}return{imports:[],exports:[],tags:Array.from(t).map(s=>({name:s,kind:"comment-marker"})),category:"test"}}_("gherkin",bt);import Oo from"path";import{parser as Lo}from"@lezer/go";var Wo=/\/\/\s*@tag\s+([a-zA-Z0-9_-]+)/,zo=/^\/\/go:build\s+(.+)$/,$o=/^\/\/\s*\+build\s+(.+)$/;function Mr(r,e){let t=[],s=new Map,n=new Set,o=new Set,a=Lo.parse(e).cursor();do switch(a.name){case"LineComment":{let g=e.slice(a.from,a.to),h=g.match(Wo);h?.[1]&&n.add(h[1]);let b=g.match(zo);b&&Ir(b[1],o);let M=g.match($o);M&&Ir(M[1],o);break}case"ImportSpec":{let g=a.node.getChild("String");if(g){let b=e.slice(g.from,g.to).slice(1,-1);t.push({fromPath:r,toPath:"",rawSpecifier:b,isExternal:!0,isStyle:!1,type:"static"})}break}case"FunctionDecl":case"TypeDecl":case"VarDecl":case"ConstDecl":{let g=a.node.getChild("DefName")??a.node.getChild("TypeSpec")?.getChild("DefName")??a.node.getChild("VarSpec")?.getChild("DefName")??a.node.getChild("ConstSpec")?.getChild("DefName");if(g){let h=e.slice(g.from,g.to);h!=="_"&&/^[A-Z]/.test(h)&&!s.has(h)&&s.set(h,{name:h})}break}}while(a.next());let p=t.some(g=>g.rawSpecifier==="testing"),c=Oo.basename(r).endsWith("_test.go")||n.has("test")||p?"test":"logic",m=new Set([...n,...o]);return{imports:t,exports:Array.from(s.values()),tags:Array.from(m).map(g=>({name:g,kind:"comment-marker"})),category:c}}function Ir(r,e){for(let t of r.split(/[\s,&|!()]+/)){let s=t.trim();s&&s!=="ignore"&&e.add(s)}}import Bo from"livescript";function B(r){return r.startsWith("'")||r.startsWith('"')?r.slice(1,-1):r}function Uo(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function qo(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}var Ko=new Set(["first_line","first_column","last_line","last_column","line","column"]);function Jo(r,e){let t=r.constructor?.name||r.type;if(t==="Import"){let s=r.right?.value;if(typeof s=="string"){let n=B(s);return{fromPath:e,toPath:"",rawSpecifier:n,isStyle:F(n),type:"static"}}}if(t==="Chain"&&r.head?.value==="require"){let s=r.tails?.[0];if(s?.constructor?.name==="Call"||s?.type==="Call"){let n=s.args?.[0]?.value;if(typeof n=="string"){let o=B(n);return{fromPath:e,toPath:"",rawSpecifier:o,isStyle:F(o),type:"require"}}}}return null}function vt(r,e){if(!r||typeof r!="object")return[];let t=[],s=Jo(r,e);s&&t.push(s);for(let n in r){if(Ko.has(n))continue;let o=r[n];if(!(!o||typeof o!="object"))if(Array.isArray(o))for(let i of o)t.push(...vt(i,e));else t.push(...vt(o,e))}return t}function Rr(r,e){let t=Uo(e),s=qo(r,t),n=[];try{n=vt(Bo.ast(e),r)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}import Ho from"luaparse";function Qo(r){let e=new Set,t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=t.exec(r);for(;s!==null;)s[1]&&e.add(s[1]),s=t.exec(r);return e}function Vo(r,e){let t=r.toLowerCase();return t.includes(".test.")||t.includes(".spec.")||e.has("test")?"test":"logic"}function Xo(r,e){let t=[];function s(n){if(!(!n||typeof n!="object")){if((n.type==="CallExpression"||n.type==="StringCallExpression")&&n.base?.type==="Identifier"&&n.base?.name==="require"){let o;if(n.type==="CallExpression"){let i=n.arguments?.[0];i?.type==="StringLiteral"&&(o=B(i.raw))}else if(n.type==="StringCallExpression"){let i=n.argument;i?.type==="StringLiteral"&&(o=B(i.raw))}o&&t.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:F(o),type:"require"})}for(let o in n){if(o==="loc")continue;let i=n[o];if(i&&typeof i=="object")if(Array.isArray(i))for(let a of i)s(a);else s(i)}}}return s(r),t}function Nr(r,e){let t=Qo(e),s=Vo(r,t),n=[];try{let o=Ho.parse(e);n=Xo(o,r)}catch{}return{imports:n,exports:[],tags:Array.from(t).map(o=>({name:o,kind:"comment-marker"})),category:s}}var Zo=["http://","https://","mailto:","//"],Yo="ts|tsx|js|jsx|mjs|cjs|py|go|lua|css|scss|less|styl|coffee|ls|feature|md|mdx|json",ei=new RegExp(`(?:\\.{1,2}/)?[\\w.-]+(?:/[\\w.-]+)*\\.(?:${Yo})\\b`,"g"),Dr;async function ti(){return Dr??=(async()=>{let{unified:r}=await import("unified"),e=(await import("remark-parse")).default;return r().use(e)})(),Dr}function ri(r){let e=r.trim();return e.length===0||e.startsWith("#")||Zo.some(t=>e.startsWith(t))}function si(r,e){let t=r.match(ei);return t?t.map(s=>({fromPath:e,toPath:"",rawSpecifier:s,isStyle:!1,type:"static"})):[]}function Gr(r,e,t){if(r.type==="link"&&typeof r.url=="string"&&!ri(r.url)&&t.push({fromPath:e,toPath:"",rawSpecifier:r.url,isStyle:!1,type:"static"}),(r.type==="code"||r.type==="inlineCode")&&typeof r.value=="string"&&t.push(...si(r.value,e)),Array.isArray(r.children))for(let s of r.children)Gr(s,e,t)}async function _r(r,e){let s=(await ti()).parse(e),n=[];Gr(s,r,n);let o=new Set;return{imports:n.filter(a=>o.has(a.rawSpecifier)?!1:(o.add(a.rawSpecifier),!0)),exports:[],tags:[],category:"other"}}import ni from"path";import{parser as oi}from"@lezer/python";var ii=new Set(["pytest","unittest","nose","hypothesis"]);function jr(r,e){let t=[],s=[],n=new Set,o=ni.basename(r).toLowerCase(),a=oi.parse(e).cursor();do switch(a.name){case"Comment":{let c=e.slice(a.from,a.to).match(/#\s*@tag\s+([a-zA-Z0-9_-]+)/);c?.[1]&&n.add(c[1]);break}case"ImportStatement":{for(let c of ai(a.node,e,r))t.push(c);break}case"FunctionDefinition":case"ClassDefinition":{let c=a.node.parent;if(c?.name==="Script"||c?.name==="DecoratedStatement"&&c.parent?.name==="Script"){let g=a.node.getChild("VariableName");g&&s.push({name:e.slice(g.from,g.to)})}break}case"AssignStatement":{if(a.node.parent?.name==="Script"){let c=a.node.firstChild;c?.name==="VariableName"&&s.push({name:e.slice(c.from,c.to)})}break}}while(a.next());let p=ui(o,t,n);return p==="test"&&n.add("test"),{imports:t,exports:s,tags:Array.from(n).map(c=>({name:c,kind:"comment-marker"})),category:p}}function ai(r,e,t){let s=r.firstChild;return s?s.name==="from"?pi(r,e,t):ci(r,e,t):[]}function pi(r,e,t){let s=r.firstChild;if(!s)return[];let n=s.nextSibling;for(;n&&n.name!=="import";)n=n.nextSibling;if(!n)return[];let o=e.slice(s.to,n.from).trim(),i=li(n.nextSibling,e);if(!i.length)return[];let a=0;for(;a<o.length&&o[a]===".";)a++;let p=o.slice(a);if(a===0)return[te(t,o,i,!0)];let c=a===1?"./":"../".repeat(a-1);return p?[te(t,c+p.replace(/\./g,"/"),i,!1)]:i[0]==="*"?[te(t,c.slice(0,-1),["*"],!1)]:i.map(m=>te(t,c+m,[m],!1))}function ci(r,e,t){let s=[],n=r.firstChild?.nextSibling??null;for(;n;){if(n.name==="VariableName"){let o=e.slice(n.from,n.to);for(;n.nextSibling?.name==="."&&n.nextSibling.nextSibling?.name==="VariableName";)n=n.nextSibling.nextSibling,o+=`.${e.slice(n.from,n.to)}`;n.nextSibling?.name==="as"&&(n=n.nextSibling.nextSibling??n.nextSibling),s.push(te(t,o,["*"],!0))}n=n.nextSibling}return s}function li(r,e){let t=[],s=r;for(;s;)s.name==="*"?t.push("*"):s.name==="VariableName"&&(t.push(e.slice(s.from,s.to)),s.nextSibling?.name==="as"&&(s=s.nextSibling.nextSibling??s.nextSibling)),s=s.nextSibling;return t}function te(r,e,t,s){return{fromPath:r,toPath:"",rawSpecifier:e,isStyle:!1,isExternal:s,type:"static",symbols:t.length>0?t:void 0}}function ui(r,e,t){return r.startsWith("test_")||r.endsWith("_test.py")?"test":r==="conftest.py"||r==="setup.py"?"config":t.has("test")||e.some(s=>ii.has(s.rawSpecifier))?"test":"logic"}import Lr from"path";import l from"typescript";import d from"typescript";function fi(r){let e=1;function t(s){switch(s.kind){case d.SyntaxKind.IfStatement:case d.SyntaxKind.ConditionalExpression:case d.SyntaxKind.ForStatement:case d.SyntaxKind.ForInStatement:case d.SyntaxKind.ForOfStatement:case d.SyntaxKind.WhileStatement:case d.SyntaxKind.DoStatement:case d.SyntaxKind.CatchClause:case d.SyntaxKind.CaseClause:e++;break;case d.SyntaxKind.BinaryExpression:{let n=s.operatorToken.kind;(n===d.SyntaxKind.AmpersandAmpersandToken||n===d.SyntaxKind.BarBarToken||n===d.SyntaxKind.QuestionQuestionToken)&&e++;break}}d.forEachChild(s,t)}return t(r),e}function gi(r){let e=0;function t(s,n,o){if(d.isIfStatement(s)){e+=o?1:1+n;let a=o?n:n+1;t(s.expression,a,!1),t(s.thenStatement,a,!1),s.elseStatement&&(d.isIfStatement(s.elseStatement)?t(s.elseStatement,n,!0):(e+=1,t(s.elseStatement,n+1,!1)));return}if(d.isForStatement(s)||d.isForInStatement(s)||d.isForOfStatement(s)||d.isWhileStatement(s)||d.isDoStatement(s)||d.isSwitchStatement(s)){e+=1+n,d.forEachChild(s,a=>t(a,n+1,!1));return}if(d.isCatchClause(s)){e+=1+n,d.forEachChild(s,a=>t(a,n,!1));return}if(d.isConditionalExpression(s)&&(e+=1),d.isBinaryExpression(s)){let a=s.operatorToken.kind;(a===d.SyntaxKind.AmpersandAmpersandToken||a===d.SyntaxKind.BarBarToken||a===d.SyntaxKind.QuestionQuestionToken)&&(e+=1)}if(n>0&&(d.isFunctionDeclaration(s)||d.isFunctionExpression(s)||d.isArrowFunction(s))){e+=1+n,d.forEachChild(s,a=>t(a,n+1,!1));return}d.forEachChild(s,a=>t(a,n,!1))}return t(r,0,!1),e}function kt(r){return{complexity:fi(r),cognitiveComplexity:gi(r)}}import S from"typescript";var wt=new Set(["test","describe","it"]);function Or(r,e){mi(r,e),hi(r,e),yi(r,e),xi(r,e)}function mi(r,e){if((S.isFunctionDeclaration(r)||S.isVariableDeclaration(r))&&r.name&&S.isIdentifier(r.name)&&di(r)){let t;if(S.isFunctionDeclaration(r))t="function";else{let s=r.initializer;t=s&&(S.isArrowFunction(s)||S.isFunctionExpression(s))?"function":"variable"}e.tags.add({name:r.name.text,kind:t})}}function di(r){if(S.isFunctionDeclaration(r))return S.isSourceFile(r.parent);let e=r.parent?.parent;return!!e&&S.isSourceFile(e.parent)}function hi(r,e){if(!S.isStringLiteral(r))return;let t=r.text.match(/@[\w-]+/g);if(t)for(let s of t)e.tags.add({name:s.substring(1),kind:"comment-marker"})}function yi(r,e){if(!S.isSourceFile(r))return;let t=/@tag\s+([a-zA-Z0-9_-]+)/g,s=r.getFullText(),n=t.exec(s);for(;n!==null;)n[1]&&e.tags.add({name:n[1],kind:"comment-marker"}),n=t.exec(s)}function xi(r,e){if(S.isCallExpression(r)&&Si(r.expression))for(let t of r.arguments)S.isObjectLiteralExpression(t)&&bi(t,e)}function Si(r){return S.isIdentifier(r)?wt.has(r.text):!!(S.isPropertyAccessExpression(r)&&(wt.has(r.name.text)||S.isIdentifier(r.expression)&&wt.has(r.expression.text)))}function bi(r,e){for(let t of r.properties){if(!S.isPropertyAssignment(t)||!S.isIdentifier(t.name)||t.name.text!=="tags"&&t.name.text!=="tag")continue;let{initializer:s}=t,n=S.isArrayLiteralExpression(s)?s.elements.filter(S.isStringLiteral):t.name.text==="tag"&&S.isStringLiteral(s)?[s]:[];for(let o of n)e.tags.add({name:o.text.replace(/^@/,""),kind:"comment-marker"})}}function Ct(r,e,t){let s=[],n=new Map,o=new Set,i=l.createSourceFile(r,e,l.ScriptTarget.Latest,!0,t==="typescript"?l.ScriptKind.TSX:l.ScriptKind.JSX),a={filePath:r,imports:s,exports:n,tags:o,rawCallEdges:[],sourceFile:i,hasUI:!1,hasTypesOnly:!0,totalStatements:0,exportStatements:0},p=ue=>{Ci(ue,a),l.forEachChild(ue,p)};p(i);let c=Gi(r,a);(c==="test"||c==="barrel")&&o.add({name:c,kind:"comment-marker"}),c!=="test"&&_i(a,i);let m=i.statements[0],g=m?zr(m):void 0,{complexity:h,cognitiveComplexity:b}=kt(i),M=vi(i);return{imports:s,exports:Array.from(n.values()),tags:Array.from(o),category:c,rawCallEdges:a.rawCallEdges??[],complexity:h,cognitiveComplexity:b,...M.length>0?{functions:M}:{},...g!==void 0?{description:g}:{}}}function vi(r){let e=[],t=(n,o)=>{let{complexity:i,cognitiveComplexity:a}=kt(o),p=r.getLineAndCharacterOfPosition(o.getStart(r)).line+1;e.push({name:n,line:p,complexity:i,cognitiveComplexity:a})},s=(n,o)=>{if(l.isFunctionDeclaration(n)&&n.name&&n.body?t(n.name.text,n):l.isVariableDeclaration(n)&&l.isIdentifier(n.name)&&n.initializer&&(l.isArrowFunction(n.initializer)||l.isFunctionExpression(n.initializer))?t(n.name.text,n.initializer):o&&l.isMethodDeclaration(n)&&l.isIdentifier(n.name)&&n.body?t(`${o}.${n.name.text}`,n):o&&l.isConstructorDeclaration(n)&&n.body?t(`${o}.constructor`,n):o&&l.isGetAccessorDeclaration(n)&&l.isIdentifier(n.name)&&n.body?t(`${o}.get ${n.name.text}`,n):o&&l.isSetAccessorDeclaration(n)&&l.isIdentifier(n.name)&&n.body&&t(`${o}.set ${n.name.text}`,n),l.isClassDeclaration(n)&&n.name){let i=n.name.text;l.forEachChild(n,a=>s(a,i));return}l.forEachChild(n,i=>s(i,o))};return s(r,void 0),e}function Wr(r,e,t,s){let n={name:r},o=zr(t);o!==void 0&&(n.doc=o);let i=ki(e);i!==void 0&&(n.flags=i);let a=wi(e,s);return a!==void 0&&(n.signature=a),n}function zr(r){let e=l.getJSDocCommentsAndTags(r);for(let t of e)if(l.isJSDoc(t)&&t.comment)return l.getTextOfJSDocComment(t.comment)||void 0}function ki(r){let e=new Set(["deprecated","internal","public","alpha","beta"]),t=l.getJSDocTags(r).map(s=>s.tagName.text).filter(s=>e.has(s));return t.length>0?t:void 0}function wi(r,e){let t=l.createPrinter({removeComments:!0}),s=n=>t.printNode(l.EmitHint.Unspecified,n,e);if(l.isFunctionDeclaration(r)||l.isMethodDeclaration(r)){let n=r.parameters.map(s).join(", "),o=r.type?s(r.type):"void";return`${r.typeParameters?`<${r.typeParameters.map(a=>a.name.text).join(", ")}>`:""}(${n}) => ${o}`}if(l.isVariableDeclaration(r)){if(r.type)return s(r.type);if(r.initializer&&(l.isArrowFunction(r.initializer)||l.isFunctionExpression(r.initializer))){let n=r.initializer,o=n.parameters.map(s).join(", "),i=n.type?s(n.type):"unknown";return`(${o}) => ${i}`}return}if(l.isClassDeclaration(r)&&r.name)return`class ${r.name.text}`;if(l.isInterfaceDeclaration(r))return`interface ${r.name.text}`;if(l.isTypeAliasDeclaration(r))return s(r.type);if(l.isEnumDeclaration(r))return`enum ${r.name.text}`}function Ci(r,e){Fi(r,e),Ei(r,e),Ti(r,e),Ai(r,e),Di(r,e),Or(r,e)}function Fi(r,e){if(!l.isSourceFile(r))return;let t=r.statements.filter(s=>!l.isEmptyStatement(s));e.totalStatements=t.length,e.exportStatements=t.filter(s=>l.isExportDeclaration(s)||l.isExportAssignment(s)||Ft(s)).length}function Ei(r,e){if(l.isJsxElement(r)||l.isJsxSelfClosingElement(r)||l.isJsxFragment(r)){e.hasUI=!0,e.hasTypesOnly=!1;return}if(l.isFunctionDeclaration(r)||l.isMethodDeclaration(r)||l.isArrowFunction(r)||l.isClassDeclaration(r)||l.isVariableStatement(r)||l.isEnumDeclaration(r)){e.hasTypesOnly=!1;return}l.isExportDeclaration(r)&&!Pi(r)&&(e.hasTypesOnly=!1)}function Pi(r){return r.isTypeOnly?!0:!r.exportClause||!l.isNamedExports(r.exportClause)?!1:r.exportClause.elements.every(e=>e.isTypeOnly)}function Ti(r,e){if(!l.isImportDeclaration(r)||!r.moduleSpecifier||!l.isStringLiteral(r.moduleSpecifier))return;let t=[];if(r.importClause&&(r.importClause.name&&t.push("default"),r.importClause.namedBindings))if(l.isNamedImports(r.importClause.namedBindings))for(let n of r.importClause.namedBindings.elements)t.push(n.name.text);else l.isNamespaceImport(r.importClause.namedBindings)&&t.push("*");let s=t.length>0?"static":"side-effect";e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:r.moduleSpecifier.text,isStyle:F(r.moduleSpecifier.text),type:s,symbols:t.length>0?t:void 0})}function Ai(r,e){l.isExportDeclaration(r)?Ii(r,e):l.isExportAssignment(r)?e.exports.set("default",{name:"default"}):Ft(r)&&Ni(r,e)}function Ii(r,e){if(r.moduleSpecifier&&l.isStringLiteral(r.moduleSpecifier))Mi(r,r.moduleSpecifier.text,e);else if(r.exportClause&&l.isNamedExports(r.exportClause))for(let t of r.exportClause.elements){let s=t.name.text;e.exports.set(s,{name:s})}}function Mi(r,e,t){let s=Ri(r),n={fromPath:t.filePath,toPath:"",rawSpecifier:e,isStyle:F(e),type:"re-export"};s.length>0&&(n.symbols=s),t.imports.push(n)}function Ri(r){return r.exportClause?l.isNamedExports(r.exportClause)?r.exportClause.elements.map(e=>e.name.text):[]:["*"]}function Ni(r,e){if((l.isFunctionDeclaration(r)||l.isClassDeclaration(r)||l.isInterfaceDeclaration(r)||l.isTypeAliasDeclaration(r)||l.isEnumDeclaration(r))&&r.name){let s=r.name.text;e.exports.set(s,Wr(s,r,r,e.sourceFile));return}if(l.isVariableStatement(r)){for(let s of r.declarationList.declarations)if(l.isIdentifier(s.name)){let n=s.name.text;e.exports.set(n,Wr(n,s,r,e.sourceFile))}}}function Di(r,e){if(!l.isCallExpression(r))return;let t=r.arguments[0];!t||!l.isStringLiteral(t)||(r.expression.kind===l.SyntaxKind.ImportKeyword?e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.text,isStyle:F(t.text),type:"dynamic"}):l.isIdentifier(r.expression)&&r.expression.text==="require"&&e.imports.push({fromPath:e.filePath,toPath:"",rawSpecifier:t.text,isStyle:F(t.text),type:"require"}))}function Gi(r,e){let t=Lr.basename(r).toLowerCase(),s=Lr.extname(r).toLowerCase();return J().some(o=>t.includes(o))?"test":Gt(t)?"config":e.imports.some(o=>_e().some(i=>o.rawSpecifier.includes(i)))?"test":s===".tsx"||s===".jsx"||e.hasUI?"ui":e.hasTypesOnly&&e.totalStatements>0?"type-only":e.totalStatements>0&&e.exportStatements/e.totalStatements>Oe()?"barrel":"logic"}function Ft(r){return l.canHaveModifiers(r)&&l.getModifiers(r)?.some(e=>e.kind===l.SyntaxKind.ExportKeyword)===!0}function _i(r,e){let t=r.rawCallEdges??[];r.rawCallEdges=t;let s=new Map;for(let n of e.statements){if(!l.isImportDeclaration(n)||!l.isStringLiteral(n.moduleSpecifier))continue;let o=n.moduleSpecifier.text,i=n.importClause;if(i&&(i.name&&s.set(i.name.text,o),i.namedBindings&&l.isNamedImports(i.namedBindings)))for(let a of i.namedBindings.elements)s.set(a.name.text,o)}if(s.size!==0)for(let n of e.statements){let o=Oi(n);if(o){let i=Li(n);i&&Me(i,o,s,t);continue}l.isClassDeclaration(n)&&n.name&&ji(n,s,t)}}function ji(r,e,t){let s=r.name.text;for(let n of r.members)l.isMethodDeclaration(n)&&n.body&&l.isIdentifier(n.name)?Me(n.body,`${s}.${n.name.text}`,e,t):l.isConstructorDeclaration(n)&&n.body&&Me(n.body,`${s}.constructor`,e,t)}function Oi(r){if(Ft(r)){if(l.isFunctionDeclaration(r)&&r.name)return r.name.text;if(l.isVariableStatement(r)){for(let e of r.declarationList.declarations)if(l.isIdentifier(e.name)&&e.initializer&&(l.isArrowFunction(e.initializer)||l.isFunctionExpression(e.initializer)))return e.name.text}}}function Li(r){if(l.isFunctionDeclaration(r))return r.body;if(l.isVariableStatement(r)){for(let e of r.declarationList.declarations)if(e.initializer&&(l.isArrowFunction(e.initializer)||l.isFunctionExpression(e.initializer)))return e.initializer}}function Me(r,e,t,s){if(l.isCallExpression(r)&&l.isIdentifier(r.expression)){let n=r.expression.text,o=t.get(n);o&&!s.some(i=>i.from===e&&i.to===n&&i.toSpecifier===o)&&s.push({from:e,to:n,toSpecifier:o})}l.forEachChild(r,n=>Me(n,e,t,s))}function Re(r,e){if(e.length===0)return"ui";let t=!1;return r.walk(s=>{if(s.type==="rule")return t=!0,!1}),t?"ui":"barrel"}import Br from"postcss";import*as Wi from"postcss-less";var zi=Wi,Ur=new Set(["reference","inline"]);function $r(r){return r.startsWith("~")||r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||r.startsWith("data:")}function $i(r){let e=r.trim();return e.length>0&&!e.startsWith("http://")&&!e.startsWith("https://")&&!e.startsWith("//")&&!e.startsWith("data:")&&!e.startsWith("#")}function Bi(r,e){let t=r.match(/^\(([^)]+)\)\s+['"]([^'"]+)['"]/);if(t){let o=t[1]?.trim()??"",i=t[2]??"";if(!i)return null;let a=Ur.has(o)?"side-effect":"static";return{fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a,...$r(i)?{isExternal:!0}:{}}}let s=r.match(/^url\(['"]?([^'")]+)['"]?\)/),n=s?s[1]?.trim()??"":r.match(/^['"]([^'"]+)['"]/)?.[1]??"";return n?{fromPath:e,toPath:"",rawSpecifier:n,isStyle:!0,type:"static",...$r(n)?{isExternal:!0}:{}}:null}function Ui(r,e){let t=[],s=/url\(['"]?([^'")]+)['"]?\)/g,n=s.exec(r);for(;n!==null;){let o=n[1]?.trim()??"";$i(o)&&t.push({fromPath:e,toPath:"",rawSpecifier:o,isStyle:!0,type:"static"}),n=s.exec(r)}return t}function qr(r,e){let t=[];return r.walk(s=>{if(s.type==="atrule"&&s.name==="import"){let n=Bi(s.params,e);n&&t.push(n)}s.type==="decl"&&t.push(...Ui(s.value,e))}),t}function qi(r){return r.replace(/(?<!:)\/\/.*/g,"")}function Ki(r,e){let t=[],s=/@import\s+(?:\(([^)]+)\)\s+)?['"]([^'"]+)['"]/g,n=s.exec(r);for(;n!==null;){let o=n[1]?.trim()??"",i=n[2]??"";if(i){let a=Ur.has(o)?"side-effect":"static";t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:a})}n=s.exec(r)}return t}function Kr(r,e){let t=Br.parse(qi(r));return{imports:qr(t,e),root:t}}function Jr(r,e){try{let t=zi.parse(r);return{imports:qr(t,e),root:t}}catch{return{imports:Ki(r,e),root:Br.parse("")}}}import{parse as Ji}from"postcss-scss";function Hi(r){return!!(r.startsWith("sass:")||r.startsWith("~")||r.startsWith("http://")||r.startsWith("https://")||r.startsWith("//")||!r.startsWith(".")&&!r.startsWith("/")&&!r.startsWith("_"))}function Qi(r){let e=r.match(/^['"]([^'"]+)['"]/);if(!e?.[1])return{specifier:""};let t=e[1],n=r.match(/\bas\s+(\S+)/)?.[1];return n!==void 0?{specifier:t,alias:n}:{specifier:t}}function Hr(r,e){let t=Ji(r),s=[];return t.walk(n=>{if(n.type!=="atrule")return;let{name:o,params:i}=n;if(o!=="import"&&o!=="use"&&o!=="forward")return;let{specifier:a,alias:p}=Qi(i);if(!a)return;let c={fromPath:e,toPath:"",rawSpecifier:a,isStyle:!0,type:o==="forward"?"re-export":"static",...Hi(a)?{isExternal:!0}:{}};p&&(c.symbols=[p]),s.push(c)}),{imports:s,root:t}}function Qr(r,e){let t=[],s=/@require\s+['"]([^'"]+)['"]/g,n=s.exec(r);for(;n!==null;){let i=n[1];i&&t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"require"}),n=s.exec(r)}let o=/(?<!@)(?:import|require)\s*\(?\s*['"]([^'"]+)['"]/g;for(n=o.exec(r);n!==null;){let i=n[1];i&&t.push({fromPath:e,toPath:"",rawSpecifier:i,isStyle:!0,type:"static"}),n=o.exec(r)}return t}function Vr(r,e){if(e.length===0)return"ui";try{let t=Ge("stylus");return new t.Parser(r).parse().nodes.some(o=>o.constructor.name!=="Import")?"ui":"barrel"}catch{return r.replace(/^\s*@?(?:require|import)\b.*/gm,"").trim().length>0?"ui":"barrel"}}function re(r,e){let t=A(r);if(t==="stylus"){let o=Qr(e,r);return{imports:o,exports:[],tags:[],category:Vr(e,o)}}if(t==="scss"){let{imports:o,root:i}=Hr(e,r);return{imports:o,exports:[],tags:[],category:Re(i,o)}}if(t==="less"){let{imports:o,root:i}=Jr(e,r);return{imports:o,exports:[],tags:[],category:Re(i,o)}}let{imports:s,root:n}=Kr(e,r);return{imports:s,exports:[],tags:[],category:Re(n,s)}}for(let[r,e]of[["javascript",(t,s)=>Ct(t,s,"javascript")],["typescript",(t,s)=>Ct(t,s,"typescript")],["css",re],["scss",re],["less",re],["stylus",re],["coffeescript",Ar],["livescript",Rr],["lua",Nr],["python",jr],["go",Mr],["gherkin",bt],["markdown",_r]])_(r,e);async function Xr(r,e){let t=A(r),s=pr(t);return s?s(r,e):{imports:[],exports:[],tags:[],category:"other"}}import Zr from"path";function es(r,e){for(let t of r.values()){let s=e.get(t.path);s!==void 0&&(t.coveragePct=s)}}function ts(r,e){for(let t of r)if(t.isExternal){let s=t.rawSpecifier.startsWith("@")?t.rawSpecifier.split("/").slice(0,2).join("/"):t.rawSpecifier.split("/")[0];s&&!e.some(n=>n.name===s)&&e.push({name:s,kind:"library"})}}function rs(r){for(let e of r.values())if(e.category==="test")for(let t of e.imports){if(t.isExternal||!t.toPath)continue;let s=r.get(t.toPath);s&&(s.category!=="logic"&&s.category!=="barrel"||(s.testedBy??=[],s.testedBy.includes(e.path)||s.testedBy.push(e.path)))}}function ss(r){for(let e of r.values())if(e.type==="markdown")for(let t of e.imports){if(t.isExternal||!t.toPath)continue;let s=r.get(t.toPath);!s||s===e||(s.documentedBy??=[],s.documentedBy.includes(e.path)||s.documentedBy.push(e.path),s.category==="logic"&&(s.lastCommitAt??0)>(e.lastCommitAt??0)&&(e.staleFor??=[],e.staleFor.includes(s.path)||e.staleFor.push(s.path)))}}function Yr(r){return Math.round(r*1e4)/1e4}function ns(r){for(let e of r.values()){let t=[];for(let s of e.imports){if(s.isExternal||!s.toPath)continue;let n=r.get(s.toPath);if(!n||n.exports.length===0)continue;let o;if(s.symbols===void 0){if(s.type==="side-effect")continue;o=1}else s.symbols.includes("*")?o=1:o=s.symbols.length/n.exports.length;s.exportUsageRatio=Yr(Math.min(1,o)),t.push(s.exportUsageRatio)}t.length>0&&(e.avgExportUsage=Yr(t.reduce((s,n)=>s+n,0)/t.length),e.maxExportUsage=Math.max(...t))}}function Et(r,e,t){e&&(r.some(s=>s.name===e&&s.kind===t)||r.push({name:e,kind:t}))}function Vi(r,e){let t=e.toPath,s=Zr.basename(t,Zr.extname(t)).replace(/\.(test|spec)$/,"");Et(r.tags,s,"import")}function Xi(r,e){if(!(!e.symbols||e.symbols.includes("*")))for(let t of e.symbols)Et(r.tags,t,"import")}function Zi(r,e,t){let s=t.get(e.toPath);if(!(!s||s.category==="test"))for(let n of s.tags)n.kind==="comment-marker"&&Et(r.tags,n.name,"comment-marker")}function os(r){for(let e of r.values())if(e.category==="test")for(let t of e.imports)!t.toPath||t.isExternal||(Vi(e,t),Xi(e,t),Zi(e,t,r))}import Ne from"fs";import I from"path";import ps from"fs";import U from"path";var se=class{extensions=[".go"];goModCache=new Map;resolve(e,t,s,n){let{mod:o,replaces:i}=this.readGoMod(s);if(!o)return null;let a=this.applyReplace(t,i,s);if(a!==void 0)return as(a);if(t!==o&&!t.startsWith(`${o}/`))return null;let p=t.slice(o.length).replace(/^\//,"");return p?as(U.join(s,p)):null}readGoMod(e){let t=this.goModCache.get(e);if(t!==void 0)return t;let s={mod:null,replaces:new Map};try{let n=ps.readFileSync(U.join(e,"go.mod"),"utf-8"),o=Yi(n,e);return this.goModCache.set(e,o),o}catch{return this.goModCache.set(e,s),s}}applyReplace(e,t,s){for(let[n,o]of t){if(e===n)return o;if(e.startsWith(`${n}/`)){let i=e.slice(n.length+1);return U.join(o,i)}}}};function Yi(r,e){let t=r.split(`
23
+ `),s=null,n=new Map,o=!1;for(let i of t){let a=i.trim();if(a.startsWith("module ")){s=a.slice(7).trim();continue}if(/^replace\s*\(/.test(a)){o=!0;continue}if(o&&a===")"){o=!1;continue}if(o&&a.includes("=>")){is(a,e,n);continue}!o&&/^replace\s+/.test(a)&&a.includes("=>")&&is(a.replace(/^replace\s+/,""),e,n)}return{mod:s,replaces:n}}function is(r,e,t){let[s,n]=r.split("=>").map(a=>a.trim());if(!s||!n)return;let o=s.split(/\s+/)[0];if(!n.startsWith(".")&&!n.startsWith("/"))return;let i=U.isAbsolute(n)?n:U.resolve(e,n);t.set(o,i)}function as(r){let e;try{e=ps.readdirSync(r,{withFileTypes:!0})}catch{return null}let t=e.filter(s=>s.isFile()&&s.name.endsWith(".go")&&!s.name.endsWith("_test.go")).map(s=>({path:U.join(r,s.name),isExternal:!1})).sort((s,n)=>s.path.localeCompare(n.path));return t.length>0?t:null}import ea from"fs";import Pt from"path";var ne=class{extensions=[".lua"];resolve(e,t,s,n){let o=t.replace(/\./g,Pt.sep),i=[s,Pt.join(s,"lib")];for(let a of i){if(!ea.existsSync(a))continue;let p=n(Pt.join(a,"_dummy.lua"),o);if(p)return[p]}return null}};import ta from"path";var oe=class{extensions=[".md",".mdx"];resolve(e,t,s,n){let o=n(ta.join(s,"_dummy"),`./${t}`);return o?[o]:null}};import ra from"fs";import Tt from"path";var ie=class{extensions=[".py"];resolve(e,t,s,n){let o=t.replace(/\./g,Tt.sep),i=Tt.join(s,`${o}.py`);if(cs(i))return[{path:i,isExternal:!1}];let a=Tt.join(s,o,"__init__.py");return cs(a)?[{path:a,isExternal:!1}]:null}};function cs(r){try{return ra.statSync(r,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}import ls from"path";var sa=["~","http://","https://","//","data:","sass:"],ae=class{extensions=[".css",".scss",".sass",".less",".styl"];resolve(e,t,s,n){if(sa.some(m=>t.startsWith(m)))return null;let o=n(e,t);if(o)return[o];let i=ls.dirname(t),a=ls.basename(t),p=i==="."?`_${a}`:`${i}/_${a}`,c=n(e,p);return c?[c]:null}};var q=class{constructor(e,t={}){this.rootDir=e;this.workspaceMap=t.workspaceMap??new Map,this.tsconfigSearchPaths=t.tsconfigSearchPaths??[e],this.langResolvers=t.langResolvers??[new ie,new ne,new se,new ae,new oe]}rootDir;workspaceMap;tsconfigSearchPaths;langResolvers;resolveAll(e,t){let s=this.resolvePathAlias(t);if(s)return[s];if(t.startsWith(".")||t.startsWith("/")){let i=this.resolveLocalPath(e,t);return i?[i]:[]}let n=(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,t,this.rootDir,n);if(a)return a}let o=this.resolveWorkspaceImport(t);return o?[o]:[{path:t,isExternal:!0}]}resolve(e,t){let s=this.resolvePathAlias(t);if(s)return s;if(t.startsWith(".")||t.startsWith("/"))return this.resolveLocalPath(e,t);let n=(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,t,this.rootDir,n);if(a)return a[0]??null}let o=this.resolveWorkspaceImport(t);return o||{path:t,isExternal:!0}}resolveLocalPath(e,t){let s=I.dirname(e),n=t.startsWith("/")?t:I.resolve(s,t),o=!n.startsWith(this.rootDir),i=["",".ts",".tsx",".js",".jsx",".mjs",".cjs",".css",".scss",".sass",".less",".styl",".coffee",".ls",".lua",".py",".feature",".md",".mdx"],a=n.match(/\.(js|mjs|cjs)$/);if(a){let p=n.slice(0,-a[0].length);for(let c of[".ts",".tsx"]){let m=this.tryExtensions(p,c,o);if(m)return m}}for(let p of i){let c=this.tryExtensions(n,p,o);if(c)return c}return o?{path:n,isExternal:!0}:null}tryExtensions(e,t,s){let n=e+t;if(this.isFile(n))return{path:n,isExternal:s};let o=I.join(e,`index${t}`);if(this.isFile(o))return{path:o,isExternal:s};if(t===".py"){let i=I.join(e,"__init__.py");if(this.isFile(i))return{path:i,isExternal:s}}return null}isFile(e){try{return Ne.statSync(e,{throwIfNoEntry:!1})?.isFile()===!0}catch{return!1}}resolvePathAlias(e){for(let t of this.tsconfigSearchPaths){let s=I.join(t,"tsconfig.json");if(Ne.existsSync(s))try{let o=JSON.parse(Ne.readFileSync(s,"utf-8")).compilerOptions?.paths;if(!o)continue;for(let i in o){let a=this.matchAliasPattern(i,e);if(a){let p=this.tryAliasSubstitutions(o[i],a[1]||"",t);if(p)return p}}}catch{}}return null}aliasRegexCache=new Map;matchAliasPattern(e,t){let s=this.aliasRegexCache.get(e);if(!s){let n=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace("\\*","(.*)");s=new RegExp(`^${n}$`),this.aliasRegexCache.set(e,s)}return t.match(s)}tryAliasSubstitutions(e,t,s=this.rootDir){let n=["",".ts",".tsx",".js",".jsx",".coffee",".ls",".lua",".feature"];for(let o of e){let i=o.replace("*",t),a=I.resolve(s,i);for(let p of n){let c=this.tryExtensions(a,p,!1);if(c)return c}}return null}resolveWorkspaceImport(e){if(this.workspaceMap.size===0)return null;for(let[t,s]of this.workspaceMap){if(e!==t&&!e.startsWith(`${t}/`))continue;let n=e.slice(t.length),o={path:"",isExternal:!1,isWorkspace:!0,workspacePackage:t};if(!n){for(let a of["src/index.ts","src/index.tsx","index.ts","index.tsx","index.js"]){let p=I.join(s,a);try{if(Ne.statSync(p,{throwIfNoEntry:!1})?.isFile())return{...o,path:p}}catch{}}return{...o,path:s}}let i=this.resolveLocalPath(I.join(s,"_dummy"),n.slice(1));return i?{...o,path:i.path}:null}return null}};var oa=["tests","test","__tests__","specs","spec"],us=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),ia=20;function aa(r,e){if(r.length===0)return e;let t=r.map(i=>w.dirname(i).split(w.sep)),s=t[0];for(let i of t.slice(1)){let a=0;for(;a<s.length&&a<i.length&&s[a]===i[a];)a++;s=s.slice(0,a)}let n=s.join(w.sep)||w.sep,o=w.relative(e,n);return o.startsWith("..")||w.isAbsolute(o)?e:n}var ce=class{constructor(e,t=null,s,n,o=!1,i=new Map,a=!0){this.rootDir=e;this.enableGitStats=o;this.coverageMap=i;this.parallelParsing=a;this.previousGraph=t,this.resolver=s||new q(e),this.lockFile=Pr(e),n&&(this.progressCallback=n)}rootDir;enableGitStats;coverageMap;parallelParsing;graph={nodes:new Map};visited=new Set;queue=[];previousGraph=null;resolver;lockFile=null;progressCallback;pool=null;async build(e){let t=e.map(s=>w.isAbsolute(s)?s:w.resolve(this.rootDir,s));await this.initPool();try{for(let s of t)this.enqueue(s);return await this.drain(),await this.processTestFiles(aa(t,this.rootDir)),await this.processDocFiles(),this.progressCallback&&this.visited.size>=100&&process.stderr.write(`
24
24
  Done. Total processed: ${this.visited.size} nodes.
25
- `),es(this.graph.nodes),Zr(this.graph.nodes),Yr(this.graph.nodes),this.coverageMap.size>0&&Vr(this.graph.nodes,this.coverageMap),new T(this.graph.nodes)}async processTestFiles(e){let t=J(),s=new Set(["node_modules",".git","dist","build",".next",".cache","mokosh-cache","coverage"]),n=async i=>{let a;try{a=Re.readdirSync(i,{withFileTypes:!0})}catch{return}for(let p of a){let c=w.join(i,p.name);p.isDirectory()?s.has(p.name)||await n(c):p.isFile()&&t.some(m=>p.name.includes(m))&&await this.processFile(c)}};await n(e);let o=e;for(;o!==this.rootDir;){let i=w.dirname(o);if(i===o)break;for(let a of Wi){let p=w.join(i,a);try{Re.statSync(p).isDirectory()&&await n(p)}catch{}}o=i}}async processFile(e){if(this.visited.has(e))return;this.visited.add(e),this.showProgress();let t=Re.statSync(e,{throwIfNoEntry:!1});if(!t?.isFile())return;let s=w.relative(this.rootDir,e),n=await this.getNode(e,s,t);n.imports=await this.resolveImports(e,n.imports),Xr(n.imports,n.tags),this.graph.nodes.set(n.path,n)}async getNode(e,t,s){let n=this.previousGraph?.nodes.get(t);if(n&&n.mtime===s.mtimeMs&&n.size===s.size)return{...n};let o=await this.tryParse(e,t);if(!o)return this.makeStubNode(e,t,s);let i=this.resolveCallEdges(e,o.rawCallEdges),a=this.buildNode(e,t,s,o,i);return this.attachGitStats(a,t),a}async tryParse(e,t){let s=Re.readFileSync(e,"utf-8");try{return await Jr(e,s)}catch(n){return process.stderr.write(`
25
+ `),os(this.graph.nodes),rs(this.graph.nodes),ns(this.graph.nodes),ss(this.graph.nodes),this.coverageMap.size>0&&es(this.graph.nodes,this.coverageMap),new P(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:{},t=e.minFiles??ia;if(!(t>0&&!this.hasAtLeastFiles(this.rootDir,t)))try{let s=w.join(u,"parse-worker.js");this.pool=new na({filename:s,...e.maxThreads!==void 0?{maxThreads:e.maxThreads}:{}})}catch(s){process.stderr.write(`
26
+ Warning: failed to start parse worker pool, falling back to synchronous parsing: ${s}
27
+ `),this.pool=null}}hasAtLeastFiles(e,t){let s=0,n=[e];for(;n.length>0;){let o=n.pop(),i;try{i=pe.readdirSync(o,{withFileTypes:!0})}catch{continue}for(let a of i)if(a.isDirectory())us.has(a.name)||n.push(w.join(o,a.name));else if(a.isFile()&&(s++,s>=t))return!0}return s>=t}async processTestFiles(e){let t=J(),s=o=>t.some(i=>o.name.includes(i));this.walkProject(e,s);let n=e;for(;n!==this.rootDir;){let o=w.dirname(n);if(o===n)break;for(let i of oa){let a=w.join(o,i);try{pe.statSync(a).isDirectory()&&this.walkProject(a,s)}catch{}}n=o}await this.drain()}async processDocFiles(){this.walkProject(this.rootDir,e=>e.name.endsWith(".md")||e.name.endsWith(".mdx")),await this.drain()}walkProject(e,t){let s;try{s=pe.readdirSync(e,{withFileTypes:!0})}catch{return}for(let n of s){let o=w.join(e,n.name);n.isDirectory()?us.has(n.name)||this.walkProject(o,t):n.isFile()&&t(n)&&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(t=>this.finishFile(t)))}}async finishFile(e){let t=pe.statSync(e,{throwIfNoEntry:!1});if(!t?.isFile())return;let s=w.relative(this.rootDir,e),n=await this.getNode(e,s,t);n.imports=await this.resolveImports(e,n.imports),ts(n.imports,n.tags),this.graph.nodes.set(n.path,n)}async getNode(e,t,s){let n=this.previousGraph?.nodes.get(t);if(n&&n.mtime===s.mtimeMs&&n.size===s.size)return{...n};let o=await this.tryParse(e,t);if(!o)return this.makeStubNode(e,t,s);let i=this.resolveCallEdges(e,o.rawCallEdges),a=this.buildNode(e,t,s,o,i);return this.attachGitStats(a,t),a}async tryParse(e,t){let s=pe.readFileSync(e,"utf-8");try{return await this.parseContent(e,s)}catch(n){return process.stderr.write(`
26
28
  Warning: failed to parse ${t}: ${n}
27
- `),null}}makeStubNode(e,t,s){return{path:t,type:A(e),category:"other",imports:[],exports:[],tags:[],mtime:s.mtimeMs,size:s.size}}resolveCallEdges(e,t){let s=[];for(let n of t??[])try{let o=this.resolver.resolve(e,n.toSpecifier);o&&!o.isExternal&&s.push({from:n.from,to:n.to,toFile:w.relative(this.rootDir,o.path)})}catch{}return s}buildNode(e,t,s,n,o){let{imports:i,exports:a,tags:p,category:c,description:m,complexity:g,cognitiveComplexity:h,functions:b}=n;return{path:t,type:A(e),category:c,imports:i,exports:a,tags:p,mtime:s.mtimeMs,size:s.size,...m!==void 0?{description:m}:{},...o.length>0?{callEdges:o}:{},...g!==void 0?{complexity:g}:{},...h!==void 0?{cognitiveComplexity:h}:{},...b!==void 0?{functions:b}:{}}}attachGitStats(e,t){if(this.enableGitStats)try{let s=wr(this.rootDir,t);e.commitCount90d=s.commitCount90d,s.lastAuthor!==void 0&&(e.lastAuthor=s.lastAuthor)}catch{}}async resolveImports(e,t){let s=[];for(let n of t){let o=this.resolver.resolveAll(e,n.rawSpecifier);if(o.length!==0)for(let i of o){let a={...n,toPath:i.isExternal?i.path:w.relative(this.rootDir,i.path),isExternal:i.isExternal};i.isWorkspace&&(a.isWorkspace=!0,a.workspacePackage=i.workspacePackage),i.isExternal?this.attachLockfileVersion(a):await this.processFile(i.path),s.push(a)}}return s}attachLockfileVersion(e){if(!this.lockFile)return;let t=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],s=t?this.lockFile.dependencies[t]:void 0;s&&(e.version=s.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function is(r,e){return{identifier:e?.identifier??new Ee,featureMap:e?.featureDetection===!1?new Map:R(r.nodes,e?.featureDetection??void 0)}}function as(r,e,t,s,n){for(let o of e){let i=r.nodes.get(o);if(!i)continue;let a=new N(o,["*",...i.exports.map(p=>p.name)]);r.traverse(o,(p,c,m)=>{if(!m)return!0;if(!a.updateAffectedSymbols(p,m))return!1;if(c>0){let g=t.get(p.path);if(g)return s(g),!1}return n(p),!0},{direction:"incoming"})}}function Tt(r,e,t){let{identifier:s,featureMap:n}=is(r,t),o=new Set;for(let i of e){let a=n.get(i);a&&o.add(a.tag)}return as(r,e,n,i=>o.add(i.tag),i=>{if(s.isTestNode(i))for(let a of i.tags)o.add(a.name)}),Array.from(o)}function Pt(r,e,t){let{identifier:s,featureMap:n}=is(r,t),o=new Set;return as(r,e,n,()=>{},i=>{s.isTestNode(i)&&o.add(i.path)}),Array.from(o)}import $i from"fs";import pe from"path";async function ps(r,e,t=null,s={}){let n=s.silent?void 0:i=>{process.stderr.write(`Processed ${i} files...\r`)};return await new ae(pe.resolve(r),t,void 0,n,s.gitStats??!1,s.coverageMap??new Map).build(e)}async function cs(r,e={}){let t=pe.resolve(r),s=Y(t),n=e.packages?s.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):s.packages,o=new Map(s.packages.map(a=>[a.name,a.root])),i=new ee(t,s.type);for(let a of n){let p=e.silent?void 0:g=>{process.stderr.write(`[${a.name}] Processed ${g} files...\r`)},m=await new ae(t,null,new q(t,{workspaceMap:o,tsconfigSearchPaths:[a.root,t]}),p,e.gitStats??!1).build(a.entryPoints);i.addPackage(a,m)}return i}function ls(r,e={}){let t=[],s=new Set([...e.ignoreDirs??We,...e.additionalIgnoreDirs??[]]),n=new Set([...e.extensions??ze,...e.additionalExtensions??[]]);function o(i){try{let a=$i.readdirSync(i,{withFileTypes:!0});for(let p of a){let c=pe.join(i,p.name);p.isDirectory()?s.has(p.name)||o(c):p.isFile()&&n.has(pe.extname(p.name).toLowerCase())&&t.push(pe.relative(r,c))}}catch{}}return o(r),t}var us=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;var Ne=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,t){this.configs.set(e,t)}getConfig(e){return this.configs.get(e)}async getOrBuild(e,t,s=new Map){let n=this.configs.get(e),o=await ps(e,t,this.graphs.get(e)??null,{gitStats:n?.gitStats??!1,coverageMap:s});return this.graphs.set(e,o),o}require(e){let t=this.graphs.get(e);if(!t)throw new Error('No graph cached for this root. Call "analyze" first.');return t}async getOrBuildWorkspace(e,t={}){let s=this.workspaceGraphs.get(e);if(s)return s;let n=await cs(e,t);return this.workspaceGraphs.set(e,n),n}requireWorkspace(e){let t=this.workspaceGraphs.get(e);if(!t)throw new Error('No workspace graph cached for this root. Call "analyze" first.');return t}hasWorkspace(e){return this.workspaceGraphs.has(e)}getOrBuildChangeImpact(e){let t=this.changeImpactCaches.get(e);if(t)return t;let s=this.require(e),n=Je(s);return this.changeImpactCaches.set(e,n),n}storeLastAnalyze(e,t){this.lastAnalyze.set(e,t)}startWatching(e){if(!this.watchers.has(e))try{let t=Bi.watch(e,{recursive:!0},(s,n)=>{!n||us.test(n)||this.dirtyRoots.add(e)});t.on("error",()=>{this.watchers.delete(e)}),this.watchers.set(e,t)}catch{}}async ensureFresh(e){if(!this.dirtyRoots.has(e))return this.require(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e);let t=this.lastAnalyze.get(e);return t?.kind==="single"?this.getOrBuild(e,t.entryPoints,t.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 t=this.configs.get(e);return this.getOrBuildWorkspace(e,{gitStats:t?.gitStats??!1})}invalidate(e){let t=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),t}};import K from"path";import Ui from"fs";import qi from"os";import At from"path";function x(r){return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}function fs(r){if(!At.isAbsolute(r))throw new Error("root must be an absolute path");let e=At.resolve(r),t=qi.homedir();if(e!==t&&!e.startsWith(t+At.sep))throw new Error("root must be within the user home directory");let s;try{s=Ui.statSync(e)}catch{throw new Error("root does not exist")}if(!s.isDirectory())throw new Error("root is not a directory")}async function gs(r,e){let{root:t,entryPoints:s}=e;if(!r.isConfigured(t)){let g=H(t,{allowJs:!1});Oe(g),r.storeConfig(t,g)}if(s.length===0){let g=Y(t);if(g.type!=="none"){let h=r.getConfig(t),b=await r.getOrBuildWorkspace(t,{gitStats:h?.gitStats??!1});r.storeLastAnalyze(t,{kind:"workspace"}),r.startWatching(t);let M=Array.from(b.packages.values()).map(({graph:ce,pkg:Mt})=>({package:Mt.name,relativeRoot:Mt.relativeRoot,nodeCount:ce.nodes.size}));return x({monorepoType:g.type,packageCount:b.packages.size,packages:M})}}let n=s.map(g=>K.resolve(t,g)),o=r.getConfig(t),i=o?.coverageReportPath?$e(t,o.coverageReportPath):new Map,a=await r.getOrBuild(t,n,i);r.storeLastAnalyze(t,{kind:"single",entryPoints:n,coverageMap:i}),r.startWatching(t);let p=a.serialize(),c=p.nodes.reduce((g,h)=>(g[h.category]=(g[h.category]??0)+1,g),{}),m=a.findCycles();return x({nodeCount:p.nodes.length,categories:c,cycles:m})}async function ms(r,e){let{root:t,file:s,depth:n=1}=e,o=await r.ensureFresh(t),i=Qe(o,s,n);return x({file:s,dependencies:i})}async function ds(r,e){let{root:t,file:s}=e,n=await r.ensureFresh(t),o=Ve(n,s);return x({file:s,dependents:o})}async function hs(r,e){let{root:t,file:s,testsOnly:n=!1,cached:o=!1,changedSymbols:i}=e,a=await r.ensureFresh(t);if(o){let c=r.getOrBuildChangeImpact(t),m=He(c,s),g=n?m.filter(h=>a.nodes.get(h)?.category==="test"):m;return x({file:s,affected:g,count:g.length})}let p=Xe(a,s,{testsOnly:n,changedSymbols:i});return x({file:s,affected:p,count:p.length})}async function ys(r,e){let{root:t,file:s,depth:n=1,withEdgeDetail:o=!1}=e,i=await r.ensureFresh(t),a=Ze(i,s,{depth:n,withEdgeDetail:o});return x({file:s,callers:a,count:a.length})}async function xs(r,e){let{root:t,entryPoints:s}=e,n=s.map(p=>K.resolve(t,p)),o=await r.getOrBuild(t,n),i=ls(t),a=o.findUnusedFiles(i);return x({unusedFiles:a,count:a.length})}async function Ss(r,e){let{root:t,coverageThreshold:s}=e,n=await r.ensureFresh(t),o=r.getConfig(t),i=s??o?.coverageThreshold??80;if(!rt(n))return x({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let a=[...n.nodes.values()].filter(p=>p.category!=="test"&&p.category!=="config").filter(p=>p.coveragePct!==void 0&&p.coveragePct<i).map(p=>({file:p.path,coveragePct:p.coveragePct}));return x({threshold:i,uncovered:a,count:a.length})}async function bs(r,e){let{root:t,metric:s="cognitiveComplexity",threshold:n=10,limit:o=20}=e,i=await r.ensureFresh(t),a=Ye(i,{metric:s,threshold:n,limit:o});return x({metric:s,threshold:n,functions:a,count:a.length})}async function vs(r,e){let{root:t,changedFiles:s,featureThreshold:n,format:o="tags"}=e,i=await r.ensureFresh(t),a=s??new Te().getChangedFiles().map(m=>K.relative(t,K.resolve(t,m))),p=n!==void 0?{featureDetection:{minOutDegree:n}}:void 0;if(o==="paths"){let m=Pt(i,a,p);return x({changedFiles:a,affectedTests:m,count:m.length})}let c=Tt(i,a,p);return x({changedFiles:a,proposedTags:c})}async function ks(r,e){let{root:t,entryPoints:s,featureThreshold:n}=e,o=s?await r.getOrBuild(t,s.map(p=>K.resolve(t,p))):await r.ensureFresh(t),i=R(o.nodes,n!==void 0?{minOutDegree:n}:void 0),a=Array.from(i.values()).sort((p,c)=>c.outDegree-p.outDegree);return x({features:a,count:a.length})}async function ws(r,e){let{root:t,entryPoints:s,filter:n,mermaid:o=!1,slim:i=!0}=e,a=s?await r.getOrBuild(t,s.map(c=>K.resolve(t,c))):await r.ensureFresh(t),p=he(a.serialize(),ye(n));return o?x(ge.serialize(T.deserialize(p))):i?x(et(p)):x(p)}async function Cs(r,e){let{root:t}=e,s=await r.ensureFreshWorkspace(t);return x(tt(s))}async function Fs(r,e){let{root:t,file:s}=e,o=(await r.ensureFreshWorkspace(t)).getAffectedAcrossPackages(s);return x({file:s,affected:o,count:o.length})}function Es(r,e){let{root:t}=e,s=r.invalidate(t);return x({root:t,cleared:s,message:s?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function Ts(r,e){let{root:t,type:s}=e,n=await r.ensureFresh(t),o=nt(n);if(s)return x(ot(o,s));let i=Array.from(o.types.values());return x({count:i.length,types:i})}async function Ps(r,e){let{root:t,paths:s,minOutDegree:n}=e,o=await r.ensureFresh(t),i=st(o,n!==void 0?{minOutDegree:n}:void 0);if(s?.length){let p=s.map(c=>i.get(c)).filter(Boolean);return x({count:p.length,modules:p})}let a=Array.from(i.values());return x({count:a.length,modules:a})}async function As(r,e){let{root:t,minOutDegree:s}=e,n=await r.ensureFresh(t),o=Q(n,s!==void 0?{minOutDegree:s}:void 0),i=Object.fromEntries(o.features);return x({features:i,unassigned:o.unassigned})}async function Is(r,e){let{root:t,function:s}=e,n=await r.ensureFresh(t);return x(Ke(n,s))}async function Ms(r,e){let{root:t,entryPoints:s}=e,n=await r.ensureFresh(t),o=s?.length?s:Ue(n,t);if(o.length===0)throw new Error("No entry points found. Pass entryPoints explicitly or ensure package.json has a main/exports field.");return x(qe(n,o))}async function Rs(r,e){let t=await r.ensureFresh(e.root),s=await ht(t,e.root,{dryRun:e.dryRun??!1});return x(s)}var Ns=[{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)"}},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"}},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.",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)."}},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.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"}}},required:["root","entryPoints"]}},{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:"find_complex_functions",description:"Find individual functions/methods above a cognitive (or cyclomatic) complexity threshold, sorted worst-first. Requires a prior analyze() call. TypeScript/JavaScript only.",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:"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. sort: size|imports|commitCount90d|exportUsage. 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. Pass false only when full edge metadata is needed."}},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:"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 It(){let r=new Ne,e=new Ki({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(Hi,async()=>({tools:Ns})),e.setRequestHandler(Ji,async t=>{let{name:s,arguments:n}=t.params,o=n,a={analyze:p=>gs(r,p),get_dependencies:p=>ms(r,p),get_dependents:p=>ds(r,p),get_affected:p=>hs(r,p),get_callers:p=>ys(r,p),find_unused:p=>xs(r,p),find_uncovered:p=>Ss(r,p),find_complex_functions:p=>bs(r,p),propose_tags:p=>vs(r,p),detect_features:p=>ks(r,p),get_type_graph:p=>Ts(r,p),get_module_responsibility:p=>Ps(r,p),get_feature_graph:p=>As(r,p),get_call_graph:p=>Is(r,p),get_api_surface:p=>Ms(r,p),query:p=>ws(r,p),get_workspace_packages:p=>Cs(r,p),get_workspace_affected:p=>Fs(r,p),clear_cache:p=>Es(r,p),apply_tags:p=>Rs(r,p)}[s];if(!a)throw new Error(`Unknown tool: ${s}`);try{return fs(o.root),await a(o)}catch(p){return{content:[{type:"text",text:`Error: ${p instanceof Error?p.message:String(p)}`}],isError:!0}}}),e}async function Vi(){let r=It(),e=new Qi;await r.connect(e)}Vi().catch(console.error);export{It as createMcpServer};
29
+ `),null}}parseContent(e,t){return this.pool?this.pool.run({filePath:e,content:t}):Xr(e,t)}makeStubNode(e,t,s){return{path:t,type:A(e),category:"other",imports:[],exports:[],tags:[],mtime:s.mtimeMs,size:s.size}}resolveCallEdges(e,t){let s=[];for(let n of t??[])try{let o=this.resolver.resolve(e,n.toSpecifier);o&&!o.isExternal&&s.push({from:n.from,to:n.to,toFile:w.relative(this.rootDir,o.path)})}catch{}return s}buildNode(e,t,s,n,o){let{imports:i,exports:a,tags:p,category:c,description:m,complexity:g,cognitiveComplexity:h,functions:b}=n;return{path:t,type:A(e),category:c,imports:i,exports:a,tags:p,mtime:s.mtimeMs,size:s.size,...m!==void 0?{description:m}:{},...o.length>0?{callEdges:o}:{},...g!==void 0?{complexity:g}:{},...h!==void 0?{cognitiveComplexity:h}:{},...b!==void 0?{functions:b}:{}}}attachGitStats(e,t){if(this.enableGitStats)try{let s=Cr(this.rootDir,t);e.commitCount90d=s.commitCount90d,s.lastAuthor!==void 0&&(e.lastAuthor=s.lastAuthor),s.lastCommitAt!==void 0&&(e.lastCommitAt=s.lastCommitAt)}catch{}}async resolveImports(e,t){let s=[];for(let n of t){let o=this.resolver.resolveAll(e,n.rawSpecifier);if(o.length!==0)for(let i of o){let a={...n,toPath:i.isExternal?i.path:w.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),s.push(a)}}return s}attachLockfileVersion(e){if(!this.lockFile)return;let t=e.rawSpecifier.startsWith("@")?e.rawSpecifier.split("/").slice(0,2).join("/"):e.rawSpecifier.split("/")[0],s=t?this.lockFile.dependencies[t]:void 0;s&&(e.version=s.version)}showProgress(){this.progressCallback&&this.visited.size%100===0&&this.progressCallback(this.visited.size)}};function fs(r,e){return{identifier:e?.identifier??new Te,featureMap:e?.featureDetection===!1?new Map:R(r.nodes,e?.featureDetection??void 0)}}function gs(r,e,t,s,n){for(let o of e){let i=r.nodes.get(o);if(!i)continue;let a=new N(o,["*",...i.exports.map(p=>p.name)]);r.traverse(o,(p,c,m)=>{if(!m)return!0;if(!a.updateAffectedSymbols(p,m))return!1;if(c>0){let g=t.get(p.path);if(g)return s(g),!1}return n(p),!0},{direction:"incoming"})}}function At(r,e,t){let{identifier:s,featureMap:n}=fs(r,t),o=new Set;for(let i of e){let a=n.get(i);a&&o.add(a.tag)}return gs(r,e,n,i=>o.add(i.tag),i=>{if(s.isTestNode(i))for(let a of i.tags)o.add(a.name)}),Array.from(o)}function It(r,e,t){let{identifier:s,featureMap:n}=fs(r,t),o=new Set;return gs(r,e,n,()=>{},i=>{s.isTestNode(i)&&o.add(i.path)}),Array.from(o)}import pa from"fs";import le from"path";async function ms(r,e,t=null,s={}){let n=s.silent?void 0:i=>{process.stderr.write(`Processed ${i} files...\r`)};return await new ce(le.resolve(r),t,void 0,n,s.gitStats??!1,s.coverageMap??new Map,s.parallelParsing??!0).build(e)}async function ds(r,e={}){let t=le.resolve(r),s=Y(t),n=e.packages?s.packages.filter(a=>e.packages?.includes(a.name)||e.packages?.includes(a.relativeRoot)):s.packages,o=new Map(s.packages.map(a=>[a.name,a.root])),i=new ee(t,s.type);for(let a of n){let p=e.silent?void 0:g=>{process.stderr.write(`[${a.name}] Processed ${g} files...\r`)},m=await new ce(t,null,new q(t,{workspaceMap:o,tsconfigSearchPaths:[a.root,t]}),p,e.gitStats??!1,new Map,e.parallelParsing??!0).build(a.entryPoints);i.addPackage(a,m)}return i}function hs(r,e={}){let t=[],s=new Set([...e.ignoreDirs??ze,...e.additionalIgnoreDirs??[]]),n=new Set([...e.extensions??$e,...e.additionalExtensions??[]]);function o(i){try{let a=pa.readdirSync(i,{withFileTypes:!0});for(let p of a){let c=le.join(i,p.name);p.isDirectory()?s.has(p.name)||o(c):p.isFile()&&n.has(le.extname(p.name).toLowerCase())&&t.push(le.relative(r,c))}}catch{}}return o(r),t}var ys=/(?:^|[/\\])(?:node_modules|\.git|dist|build|coverage)(?:[/\\]|$)/;var De=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,t){this.configs.set(e,t)}getConfig(e){return this.configs.get(e)}async getOrBuild(e,t,s=new Map){let n=this.configs.get(e),o=await ms(e,t,this.graphs.get(e)??null,{gitStats:n?.gitStats??!1,coverageMap:s,parallelParsing:n?.parallelParsing});return this.graphs.set(e,o),o}require(e){let t=this.graphs.get(e);if(!t)throw new Error('No graph cached for this root. Call "analyze" first.');return t}async getOrBuildWorkspace(e,t={}){let s=this.workspaceGraphs.get(e);if(s)return s;let n=await ds(e,t);return this.workspaceGraphs.set(e,n),n}requireWorkspace(e){let t=this.workspaceGraphs.get(e);if(!t)throw new Error('No workspace graph cached for this root. Call "analyze" first.');return t}hasWorkspace(e){return this.workspaceGraphs.has(e)}getOrBuildChangeImpact(e){let t=this.changeImpactCaches.get(e);if(t)return t;let s=this.require(e),n=He(s);return this.changeImpactCaches.set(e,n),n}storeLastAnalyze(e,t){this.lastAnalyze.set(e,t)}startWatching(e){if(!this.watchers.has(e))try{let t=ca.watch(e,{recursive:!0},(s,n)=>{!n||ys.test(n)||this.dirtyRoots.add(e)});t.on("error",()=>{this.watchers.delete(e)}),this.watchers.set(e,t)}catch{}}async ensureFresh(e){if(!this.dirtyRoots.has(e))return this.require(e);this.dirtyRoots.delete(e),this.changeImpactCaches.delete(e);let t=this.lastAnalyze.get(e);return t?.kind==="single"?this.getOrBuild(e,t.entryPoints,t.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 t=this.configs.get(e);return this.getOrBuildWorkspace(e,{gitStats:t?.gitStats??!1,parallelParsing:t?.parallelParsing})}invalidate(e){let t=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),t}};import K from"path";import la from"fs";import ua from"os";import Mt from"path";function y(r){return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}function xs(r){if(!Mt.isAbsolute(r))throw new Error("root must be an absolute path");let e=Mt.resolve(r),t=ua.homedir();if(e!==t&&!e.startsWith(t+Mt.sep))throw new Error("root must be within the user home directory");let s;try{s=la.statSync(e)}catch{throw new Error("root does not exist")}if(!s.isDirectory())throw new Error("root is not a directory")}async function Ss(r,e){let{root:t,entryPoints:s}=e;if(!r.isConfigured(t)){let g=H(t,{allowJs:!1});We(g),r.storeConfig(t,g)}if(s.length===0){let g=Y(t);if(g.type!=="none"){let h=r.getConfig(t),b=await r.getOrBuildWorkspace(t,{gitStats:h?.gitStats??!1,parallelParsing:h?.parallelParsing});r.storeLastAnalyze(t,{kind:"workspace"}),r.startWatching(t);let M=Array.from(b.packages.values()).map(({graph:ue,pkg:Nt})=>({package:Nt.name,relativeRoot:Nt.relativeRoot,nodeCount:ue.nodes.size}));return y({monorepoType:g.type,packageCount:b.packages.size,packages:M})}}let n=s.map(g=>K.resolve(t,g)),o=r.getConfig(t),i=o?.coverageReportPath?Be(t,o.coverageReportPath):new Map,a=await r.getOrBuild(t,n,i);r.storeLastAnalyze(t,{kind:"single",entryPoints:n,coverageMap:i}),r.startWatching(t);let p=a.serialize(),c=p.nodes.reduce((g,h)=>(g[h.category]=(g[h.category]??0)+1,g),{}),m=a.findCycles();return y({nodeCount:p.nodes.length,categories:c,cycles:m})}async function bs(r,e){let{root:t,file:s,depth:n=1}=e,o=await r.ensureFresh(t),i=Ve(o,s,n);return y({file:s,dependencies:i})}async function vs(r,e){let{root:t,file:s}=e,n=await r.ensureFresh(t),o=Xe(n,s);return y({file:s,dependents:o})}async function ks(r,e){let{root:t,file:s,testsOnly:n=!1,cached:o=!1,changedSymbols:i}=e,a=await r.ensureFresh(t);if(o){let c=r.getOrBuildChangeImpact(t),m=Qe(c,s),g=n?m.filter(h=>a.nodes.get(h)?.category==="test"):m;return y({file:s,affected:g,count:g.length})}let p=Ze(a,s,{testsOnly:n,changedSymbols:i});return y({file:s,affected:p,count:p.length})}async function ws(r,e){let{root:t,file:s,depth:n=1,withEdgeDetail:o=!1}=e,i=await r.ensureFresh(t),a=Ye(i,s,{depth:n,withEdgeDetail:o});return y({file:s,callers:a,count:a.length})}async function Cs(r,e){let{root:t,entryPoints:s}=e,n=s.map(p=>K.resolve(t,p)),o=await r.getOrBuild(t,n),i=hs(t),a=o.findUnusedFiles(i);return y({unusedFiles:a,count:a.length})}async function Fs(r,e){let{root:t,coverageThreshold:s}=e,n=await r.ensureFresh(t),o=r.getConfig(t),i=s??o?.coverageThreshold??80;if(!st(n))return y({error:"No coverage data available. Set coverageReportPath in mokosh.config and call analyze again."});let a=[...n.nodes.values()].filter(p=>p.category!=="test"&&p.category!=="config").filter(p=>p.coveragePct!==void 0&&p.coveragePct<i).map(p=>({file:p.path,coveragePct:p.coveragePct}));return y({threshold:i,uncovered:a,count:a.length})}async function Es(r,e){let{root:t}=e,n=[...(await r.ensureFresh(t)).nodes.values()].filter(o=>o.type==="markdown"&&o.staleFor&&o.staleFor.length>0).map(o=>({doc:o.path,staleFor:o.staleFor}));return y({staleDocs:n,count:n.length})}async function Ps(r,e){let{root:t,metric:s="cognitiveComplexity",threshold:n=10,limit:o=20}=e,i=await r.ensureFresh(t),a=et(i,{metric:s,threshold:n,limit:o});return y({metric:s,threshold:n,functions:a,count:a.length})}async function Ts(r,e){let{root:t,changedFiles:s,featureThreshold:n,format:o="tags"}=e,i=await r.ensureFresh(t),a=s??new Ae().getChangedFiles().map(m=>K.relative(t,K.resolve(t,m))),p=n!==void 0?{featureDetection:{minOutDegree:n}}:void 0;if(o==="paths"){let m=It(i,a,p);return y({changedFiles:a,affectedTests:m,count:m.length})}let c=At(i,a,p);return y({changedFiles:a,proposedTags:c})}async function As(r,e){let{root:t,entryPoints:s,featureThreshold:n}=e,o=s?await r.getOrBuild(t,s.map(p=>K.resolve(t,p))):await r.ensureFresh(t),i=R(o.nodes,n!==void 0?{minOutDegree:n}:void 0),a=Array.from(i.values()).sort((p,c)=>c.outDegree-p.outDegree);return y({features:a,count:a.length})}async function Is(r,e){let{root:t,entryPoints:s,filter:n,mermaid:o=!1,slim:i=!0}=e,a=s?await r.getOrBuild(t,s.map(c=>K.resolve(t,c))):await r.ensureFresh(t),p=xe(a.serialize(),Se(n));return o?y(de.serialize(P.deserialize(p))):i?y(tt(p)):y(p)}async function Ms(r,e){let{root:t}=e,s=await r.ensureFreshWorkspace(t);return y(rt(s))}async function Rs(r,e){let{root:t,file:s}=e,o=(await r.ensureFreshWorkspace(t)).getAffectedAcrossPackages(s);return y({file:s,affected:o,count:o.length})}function Ns(r,e){let{root:t}=e,s=r.invalidate(t);return y({root:t,cleared:s,message:s?"Cache cleared. Call analyze to rebuild.":"No cache was present for this root."})}async function Ds(r,e){let{root:t,type:s}=e,n=await r.ensureFresh(t),o=ot(n);if(s)return y(it(o,s));let i=Array.from(o.types.values());return y({count:i.length,types:i})}async function Gs(r,e){let{root:t,paths:s,minOutDegree:n}=e,o=await r.ensureFresh(t),i=nt(o,n!==void 0?{minOutDegree:n}:void 0);if(s?.length){let p=s.map(c=>i.get(c)).filter(Boolean);return y({count:p.length,modules:p})}let a=Array.from(i.values());return y({count:a.length,modules:a})}async function _s(r,e){let{root:t,minOutDegree:s}=e,n=await r.ensureFresh(t),o=Q(n,s!==void 0?{minOutDegree:s}:void 0),i=Object.fromEntries(o.features);return y({features:i,unassigned:o.unassigned})}async function js(r,e){let{root:t,function:s}=e,n=await r.ensureFresh(t);return y(Je(n,s))}async function Os(r,e){let{root:t,entryPoints:s}=e,n=await r.ensureFresh(t),o=s?.length?s:qe(n,t);if(o.length===0)throw new Error("No entry points found. Pass entryPoints explicitly or ensure package.json has a main/exports field.");return y(Ke(n,o))}async function Ls(r,e){let t=await r.ensureFresh(e.root),s=await yt(t,e.root,{dryRun:e.dryRun??!1});return y(s)}var Ws=[{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)"}},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"}},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.",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)."}},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.",inputSchema:{type:"object",properties:{root:{type:"string"},entryPoints:{type:"array",items:{type:"string"}}},required:["root","entryPoints"]}},{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. TypeScript/JavaScript only.",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:"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. sort: size|imports|commitCount90d|exportUsage. 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. Pass false only when full edge metadata is needed."}},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:"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 Rt(){let r=new De,e=new fa({name:"mokosh",version:"0.0.1"},{capabilities:{tools:{}}});return e.setRequestHandler(ma,async()=>({tools:Ws})),e.setRequestHandler(ga,async t=>{let{name:s,arguments:n}=t.params,o=n,a={analyze:p=>Ss(r,p),get_dependencies:p=>bs(r,p),get_dependents:p=>vs(r,p),get_affected:p=>ks(r,p),get_callers:p=>ws(r,p),find_unused:p=>Cs(r,p),find_uncovered:p=>Fs(r,p),check_doc_drift:p=>Es(r,p),find_complex_functions:p=>Ps(r,p),propose_tags:p=>Ts(r,p),detect_features:p=>As(r,p),get_type_graph:p=>Ds(r,p),get_module_responsibility:p=>Gs(r,p),get_feature_graph:p=>_s(r,p),get_call_graph:p=>js(r,p),get_api_surface:p=>Os(r,p),query:p=>Is(r,p),get_workspace_packages:p=>Ms(r,p),get_workspace_affected:p=>Rs(r,p),clear_cache:p=>Ns(r,p),apply_tags:p=>Ls(r,p)}[s];if(!a)throw new Error(`Unknown tool: ${s}`);try{return xs(o.root),await a(o)}catch(p){return{content:[{type:"text",text:`Error: ${p instanceof Error?p.message:String(p)}`}],isError:!0}}}),e}async function ha(){let r=Rt(),e=new da;await r.connect(e)}ha().catch(console.error);export{Rt as createMcpServer};
28
30
  //# sourceMappingURL=mcp.mjs.map