import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";import"./DIQmuJJZ.js";var n=e(t(),1),r={ts:`typescript`,tsx:`tsx`,mts:`typescript`,cts:`typescript`,js:`javascript`,jsx:`javascript`,mjs:`javascript`,cjs:`javascript`,py:`python`,pyi:`python`,go:`go`,rs:`rust`,java:`java`,c:`c`,h:`c`,cpp:`cpp`,cc:`cpp`,cxx:`cpp`,hpp:`cpp`,hh:`cpp`,rb:`ruby`};function i(e){let t=e.split(`.`).pop()?.toLowerCase();if(t)return r[t]}[...new Set(Object.values(r))];var a=(0,n.createRequire)(import.meta.url);function o(e){try{return a(e)}catch{return null}}var s=null,c=null,l=null,u=!1,d=!1;function f(){if(u)return d;u=!0;let e=o(`tree-sitter`);return e===null?(d=!1,!1):(s=e,c=e.Query??null,d=s!==null&&c!==null,d)}function p(){if(l)return l;if(!f()||s===null)throw Error(`tree-sitter native module not available. Run: pnpm install (tree-sitter is a bundled dependency)`);return l=new s,l}var m=new Map,h={typescript:{pkg:`tree-sitter-typescript`,prop:`typescript`},tsx:{pkg:`tree-sitter-typescript`,prop:`tsx`},javascript:{pkg:`tree-sitter-javascript`},python:{pkg:`tree-sitter-python`},go:{pkg:`tree-sitter-go`},rust:{pkg:`tree-sitter-rust`},java:{pkg:`tree-sitter-java`},c:{pkg:`tree-sitter-c`},cpp:{pkg:`tree-sitter-cpp`},ruby:{pkg:`tree-sitter-ruby`}};function g(e){if(m.has(e))return m.get(e)??null;let t=h[e];if(!t)return null;let n=o(t.pkg);if(n===null)return m.set(e,null),null;let r=t.prop?n[t.prop]:n;return m.set(e,r??null),r??null}var _={typescript:`
(function_declaration name: (identifier) @name) @definition.function
(method_definition name: (property_identifier) @name) @definition.method
(class_declaration name: (type_identifier) @name) @definition.class
(interface_declaration name: (type_identifier) @name) @definition.interface
(type_alias_declaration name: (type_identifier) @name) @definition.type
(enum_declaration name: (identifier) @name) @definition.enum
(lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
(export_statement (function_declaration name: (identifier) @name)) @definition.function
(export_statement (class_declaration name: (type_identifier) @name)) @definition.class
(arrow_function) @definition.function
`,javascript:`
(function_declaration name: (identifier) @name) @definition.function
(method_definition name: (property_identifier) @name) @definition.method
(class_declaration name: (identifier) @name) @definition.class
(lexical_declaration (variable_declarator name: (identifier) @name)) @definition.variable
(export_statement (function_declaration name: (identifier) @name)) @definition.function
(export_statement (class_declaration name: (identifier) @name)) @definition.class
(arrow_function) @definition.function
`,python:`
(function_definition name: (identifier) @name) @definition.function
(class_definition name: (identifier) @name) @definition.class
(decorated_definition (function_definition name: (identifier) @name)) @definition.function
(decorated_definition (class_definition name: (identifier) @name)) @definition.class
`,go:`
(function_declaration name: (identifier) @name) @definition.function
(method_declaration name: (field_identifier) @name) @definition.method
(type_declaration (type_spec name: (type_identifier) @name)) @definition.type
`,rust:`
(function_item name: (identifier) @name) @definition.function
(impl_item type: (type_identifier) @name) @definition.impl
(struct_item name: (type_identifier) @name) @definition.struct
(enum_item name: (type_identifier) @name) @definition.enum
(trait_item name: (type_identifier) @name) @definition.trait
(type_item name: (type_identifier) @name) @definition.type
(mod_item name: (identifier) @name) @definition.module
`,ruby:`
(method name: (identifier) @name) @definition.method
(class name: (constant) @name) @definition.class
(module name: (constant) @name) @definition.module
(singleton_method name: (identifier) @name) @definition.method
`,java:`
(method_declaration name: (identifier) @name) @definition.method
(class_declaration name: (identifier) @name) @definition.class
(interface_declaration name: (identifier) @name) @definition.interface
(enum_declaration name: (identifier) @name) @definition.enum
`,c:`
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
(struct_specifier name: (type_identifier) @name) @definition.struct
(enum_specifier name: (type_identifier) @name) @definition.enum
(type_definition declarator: (type_identifier) @name) @definition.type
`,cpp:`
(function_definition declarator: (function_declarator declarator: (qualified_identifier) @name)) @definition.function
(function_definition declarator: (function_declarator declarator: (identifier) @name)) @definition.function
(class_specifier name: (type_identifier) @name) @definition.class
(struct_specifier name: (type_identifier) @name) @definition.struct
(enum_specifier name: (type_identifier) @name) @definition.enum
(namespace_definition name: (identifier) @name) @definition.module
`};function v(e){return e===`tsx`?`typescript`:e}function y(e){return{function:`function`,method:`method`,class:`class`,interface:`interface`,type:`type`,enum:`enum`,variable:`variable`,constant:`constant`,module:`module`,import:`import`,export:`export`,struct:`struct`,trait:`trait`,impl:`impl`}[e]??`function`}var b=new Map;function x(e,t,n){let r=t;if(b.has(r))return b.get(r)??null;if(c===null)return null;try{let t=new c(e,n);return b.set(r,t),t}catch{return null}}function S(e,t,n){let r=[],i=0;for(;i<e.length;){let a=e[i];if(a.name.startsWith(`definition.`)){let o=y(a.name.slice(11)),s=a.node.startPosition.row+1,c=a.node.endPosition.row+1,l=e[i+1];if(l&&l.name===`name`){let e=l.node.text;e&&r.push({name:e,kind:o,startLine:s,endLine:c,filePath:t,language:n}),i+=2;continue}}i++}return r}function C(e,t){let r=(0,n.relative)(t??process.cwd(),e),a=i(e);if(!a)return{filePath:r,language:`unknown`,symbols:[],errors:[`Unsupported language`]};if(!f())return{filePath:r,language:a,symbols:[],errors:[`tree-sitter native module not available. Run: pnpm install (tree-sitter is a bundled dependency)`]};let o=v(a),s=_[o];if(!s)return{filePath:r,language:a,symbols:[],errors:[`No query pattern for ${a}`]};let c=g(a);if(!c)return{filePath:r,language:a,symbols:[],errors:[`Grammar package not installed for ${a}`]};let l;try{l=(0,n.readFileSync)(e,`utf-8`)}catch(e){return{filePath:r,language:a,symbols:[],errors:[`Failed to read file: ${e instanceof Error?e.message:String(e)}`]}}try{let e=p();e.setLanguage(c);let t=e.parse(l),n=x(c,o,s);return n?{filePath:r,language:a,symbols:S(n.captures(t.rootNode),r,a),errors:[]}:{filePath:r,language:a,symbols:[],errors:[`Failed to compile query for ${a}`]}}catch(e){return{filePath:r,language:a,symbols:[],errors:[e instanceof Error?e.message:String(e)]}}}function w(e,t){let r=t??process.cwd(),a=[],o=[];for(let t of e){if(!i(t)){o.push((0,n.relative)(r,t));continue}a.push(C(t,r))}return{results:a,skipped:o,totalSymbols:a.reduce((e,t)=>e+t.symbols.length,0)}}function T(e,t){let r=new Set([`node_modules`,`dist`,`.git`,`.cleo`,`target`,`__pycache__`,`.next`,`.nuxt`,`build`,`coverage`,`.turbo`,`.cache`]),a=[];function o(s){let c;try{c=(0,n.readdirSync)(s,{withFileTypes:!0,encoding:`utf-8`})}catch{return}for(let l of c)if(l.isDirectory())!r.has(l.name)&&!l.name.startsWith(`.`)&&o((0,n.join)(s,l.name));else if(l.isFile()){let r=(0,n.join)(s,l.name),o=i(l.name);if(!o||t.language&&o!==t.language)continue;if(t.filePattern){let i=(0,n.relative)(e,r);if(t.filePattern.startsWith(`*.`)){let e=t.filePattern.slice(1);if(!l.name.endsWith(e))continue}else if(!i.includes(t.filePattern.replace(`/**`,``)))continue}a.push(r)}}return o(e),a}function E(e,t){let n=t.toLowerCase(),r=e.name.toLowerCase(),i=e.filePath.toLowerCase();if(r===n)return{score:10,matchType:`exact`};if(r.includes(n))return{score:5,matchType:`substring`};if(i.includes(n))return{score:3,matchType:`path`};let a=0;for(let e=0;e<r.length&&a<n.length;e++)r[e]===n[a]&&a++;return a===n.length?{score:1,matchType:`fuzzy`}:{score:0,matchType:`fuzzy`}}function D(e,t={}){let n=t.rootDir??process.cwd(),r=t.maxResults??20,i=w(T(n,t),n),a=[];for(let t of i.results)for(let n of t.symbols){let{score:t,matchType:r}=E(n,e);t>0&&a.push({symbol:n,score:t,matchType:r})}return a.sort((e,t)=>t.score-e.score||e.symbol.name.localeCompare(t.symbol.name)),a.slice(0,r)}var O=new Set([`imports`,`extends`,`implements`]),k=[`calls`,`imports`,`extends`,`implements`,`method_overrides`,`method_implements`];function A(e,t,n,r,i){let a=t.length,o=a+n.length+r.length,s=e.filePath,c=i.filter(e=>O.has(e.type)&&e.source!==s&&e.target!==s).length;return e.exported&&c>=5&&o>=10||e.exported&&a>=10?`critical`:a>=10||a>=5&&c>=3?`high`:a>=4||c>=2?`medium`:`low`}function j(e,t,n,r){let i=t.toUpperCase();return r===0?`${e}: no dependants found — risk ${i}`:`${e}: ${n} direct dependant(s), ${r} total affected node(s) — risk ${i}`}function M(e,t,n,r){let i=new Map;for(let a of e){if(!t.has(a.type)||a.confidence<r)continue;let e=n===`upstream`?a.target:a.source,o=n===`upstream`?a.source:a.target,s=i.get(e);s||(s=new Set,i.set(e,s)),s.add(o)}return i}function N(e,t,n,r){let i=r?.maxDepth??3,a=r?.direction??`upstream`,o=r?.minConfidence??0,s=r?.relationTypes?new Set(r.relationTypes):new Set(k),c=new Map,l=new Map;for(let e of t)c.set(e.id,e),l.has(e.name)||l.set(e.name,e);let u=l.get(e)??c.get(e);if(!u)return{target:e,riskLevel:`low`,summary:`${e}: not found in graph`,affectedByDepth:{depth1_willBreak:[],depth2_likelyAffected:[],depth3_mayNeedTesting:[]},totalAffected:0};let d=M(n,s,a,o),f=new Set([u.id]),p=[],m=[],h=[],g=[u.id];for(let e=1;e<=Math.min(i,3);e++){let t=[];for(let n of g){let r=d.get(n);if(r)for(let n of r){if(f.has(n))continue;f.add(n);let r=c.get(n);r&&(t.push(n),e===1?p.push(r):e===2?m.push(r):e===3&&h.push(r))}}if(g=t,g.length===0)break}let _=p.length+m.length+h.length,v=A(u,p,m,h,n);return{target:e,riskLevel:v,summary:j(e,v,p.length,_),affectedByDepth:{depth1_willBreak:p,depth2_likelyAffected:m,depth3_mayNeedTesting:h},totalAffected:_}}Object.freeze({get:()=>void 0,getInsensitive:()=>void 0,getFilesInDir:()=>[]});var P=(0,n.createRequire)(import.meta.url);P(`graphology`),P(`@aflsolutions/graphology-communities-leiden`),(0,n.createRequire)(import.meta.url);export{N as analyzeImpact,D as smartSearch};