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