scip-query 0.6.1 → 0.6.3

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.
Files changed (160) hide show
  1. package/dist/{chunk-K5FQFCSN.js → chunk-2OXZVIED.js} +2 -2
  2. package/dist/{chunk-ZSRXMNMK.js → chunk-56LPZC3S.js} +3 -3
  3. package/dist/chunk-5IM4IQ6N.js +2 -0
  4. package/dist/chunk-5KWWENJZ.js +2 -0
  5. package/dist/chunk-5OV6CUTY.js +2 -0
  6. package/dist/{chunk-2DSS2NGF.js → chunk-6QXYWGE5.js} +2 -2
  7. package/dist/{chunk-XVDASCN7.js → chunk-6TRXTRCW.js} +2 -2
  8. package/dist/{chunk-BDBRZPX3.js → chunk-C6PQLWHR.js} +2 -2
  9. package/dist/{chunk-ZXKURFVB.js → chunk-CH47OLNL.js} +2 -2
  10. package/dist/{chunk-4QJ7LVW5.js → chunk-DM56ECPZ.js} +2 -2
  11. package/dist/{chunk-WTSTDJZ7.js → chunk-DX5YEUX4.js} +2 -2
  12. package/dist/chunk-DXXROCSQ.js +19 -0
  13. package/dist/chunk-EARGTC7U.js +12 -0
  14. package/dist/{chunk-D7YBWSON.js → chunk-EJXPKSWV.js} +2 -2
  15. package/dist/{chunk-BE6EQIWY.js → chunk-EUHHVFTI.js} +2 -2
  16. package/dist/chunk-F2TGKDMW.js +2 -0
  17. package/dist/{chunk-JS2RNIC7.js → chunk-GSVIC6KN.js} +2 -2
  18. package/dist/{chunk-LX4H4LLG.js → chunk-H4IWC7KJ.js} +2 -2
  19. package/dist/{chunk-STOGKRJH.js → chunk-H7BWAMFI.js} +2 -2
  20. package/dist/{chunk-RWE6FHG3.js → chunk-HLILTI7S.js} +2 -2
  21. package/dist/chunk-HUEIPY4M.js +5 -0
  22. package/dist/chunk-ID7TO4P6.js +65 -0
  23. package/dist/{chunk-IBGBI3VU.js → chunk-IUNRL2AQ.js} +2 -2
  24. package/dist/chunk-J22I2FWD.js +6 -0
  25. package/dist/chunk-KOGVTPGE.js +7 -0
  26. package/dist/chunk-LUYN4IWJ.js +2 -0
  27. package/dist/{chunk-DE5ZBHMK.js → chunk-MDUIJELV.js} +2 -2
  28. package/dist/{chunk-GXVB36TG.js → chunk-MMKNCPHB.js} +2 -2
  29. package/dist/chunk-MSNW2AR2.js +2 -0
  30. package/dist/chunk-NB3GIT4Z.js +7 -0
  31. package/dist/{chunk-FCC3XJTI.js → chunk-OBPP5RRE.js} +2 -2
  32. package/dist/chunk-ORBQ3HJD.js +2 -0
  33. package/dist/{chunk-NXMYYHDO.js → chunk-P6IUCZA3.js} +2 -2
  34. package/dist/chunk-Q2MCCKWZ.js +2 -0
  35. package/dist/{chunk-IYFZS4PV.js → chunk-QRULHDMO.js} +6 -6
  36. package/dist/{chunk-YIPCV7M7.js → chunk-RAJHIEBM.js} +2 -2
  37. package/dist/{chunk-XAZTIDST.js → chunk-RKZBRDFK.js} +2 -2
  38. package/dist/{chunk-AJ5PWKD4.js → chunk-RPRIZ43D.js} +2 -2
  39. package/dist/{chunk-D7KLLMPB.js → chunk-RXGCTLHY.js} +2 -2
  40. package/dist/{chunk-HMKJTAZD.js → chunk-S6IGA6KK.js} +2 -2
  41. package/dist/{chunk-DHYIJHXZ.js → chunk-TPOYTT6O.js} +2 -2
  42. package/dist/{chunk-SG35Y7J2.js → chunk-TRBNQ273.js} +2 -2
  43. package/dist/chunk-TVJMEDHH.js +2 -0
  44. package/dist/{chunk-2RLP74AO.js → chunk-UDKLKBPQ.js} +2 -2
  45. package/dist/{chunk-SDX6MDBL.js → chunk-UGUBEKK5.js} +2 -2
  46. package/dist/{chunk-Y7LOQSWY.js → chunk-VKYLXCV6.js} +2 -2
  47. package/dist/{chunk-BQ3INTYT.js → chunk-VQXXSUQF.js} +2 -2
  48. package/dist/{chunk-NTDA4A2D.js → chunk-VZE4SOJG.js} +2 -2
  49. package/dist/{chunk-QXE6EDY2.js → chunk-VZHI3TUX.js} +2 -2
  50. package/dist/chunk-YSEQFGGH.js +2 -0
  51. package/dist/cli.js +218 -169
  52. package/dist/{db-BSTtBG_H.d.ts → db-DKhNQ75l.d.ts} +15 -1
  53. package/dist/index.d.ts +36 -3
  54. package/dist/index.js +60 -12
  55. package/dist/queries/affected.d.ts +1 -1
  56. package/dist/queries/affected.js +1 -1
  57. package/dist/queries/bottlenecks.d.ts +1 -1
  58. package/dist/queries/bottlenecks.js +1 -1
  59. package/dist/queries/by-kind.d.ts +1 -1
  60. package/dist/queries/by-kind.js +1 -1
  61. package/dist/queries/call-graph.d.ts +1 -1
  62. package/dist/queries/call-graph.js +1 -1
  63. package/dist/queries/change-surface.d.ts +1 -1
  64. package/dist/queries/change-surface.js +1 -1
  65. package/dist/queries/code.d.ts +1 -1
  66. package/dist/queries/code.js +1 -1
  67. package/dist/queries/complexity-hotspots.d.ts +1 -1
  68. package/dist/queries/complexity-hotspots.js +1 -1
  69. package/dist/queries/complexity.d.ts +1 -1
  70. package/dist/queries/complexity.js +1 -1
  71. package/dist/queries/convergence.d.ts +1 -1
  72. package/dist/queries/convergence.js +1 -1
  73. package/dist/queries/coupling.d.ts +1 -1
  74. package/dist/queries/coupling.js +1 -1
  75. package/dist/queries/cycles.d.ts +1 -1
  76. package/dist/queries/cycles.js +1 -1
  77. package/dist/queries/dataflow.d.ts +1 -1
  78. package/dist/queries/dataflow.js +1 -1
  79. package/dist/queries/dead.d.ts +1 -1
  80. package/dist/queries/dead.js +1 -1
  81. package/dist/queries/deep-chains.d.ts +1 -1
  82. package/dist/queries/deep-chains.js +1 -1
  83. package/dist/queries/deps.d.ts +1 -1
  84. package/dist/queries/deps.js +1 -1
  85. package/dist/queries/diff-impact.d.ts +1 -1
  86. package/dist/queries/diff-impact.js +1 -1
  87. package/dist/queries/drift.d.ts +1 -1
  88. package/dist/queries/drift.js +1 -1
  89. package/dist/queries/extract-candidates.d.ts +1 -1
  90. package/dist/queries/extract-candidates.js +1 -1
  91. package/dist/queries/fan.d.ts +1 -1
  92. package/dist/queries/fan.js +1 -1
  93. package/dist/queries/files.d.ts +1 -1
  94. package/dist/queries/health.d.ts +1 -1
  95. package/dist/queries/health.js +1 -1
  96. package/dist/queries/hierarchy.d.ts +1 -1
  97. package/dist/queries/hierarchy.js +1 -1
  98. package/dist/queries/hotspots.d.ts +1 -1
  99. package/dist/queries/hotspots.js +1 -1
  100. package/dist/queries/imports.d.ts +1 -1
  101. package/dist/queries/imports.js +1 -1
  102. package/dist/queries/index.d.ts +1 -1
  103. package/dist/queries/index.js +1 -1
  104. package/dist/queries/isolated.d.ts +1 -1
  105. package/dist/queries/isolated.js +1 -1
  106. package/dist/queries/members.d.ts +1 -1
  107. package/dist/queries/members.js +1 -1
  108. package/dist/queries/methods.d.ts +1 -1
  109. package/dist/queries/methods.js +1 -1
  110. package/dist/queries/outline.d.ts +1 -1
  111. package/dist/queries/outline.js +1 -1
  112. package/dist/queries/passthrough-candidates.d.ts +1 -1
  113. package/dist/queries/passthrough-candidates.js +1 -1
  114. package/dist/queries/redundant-reexports.d.ts +1 -1
  115. package/dist/queries/redundant-reexports.js +1 -1
  116. package/dist/queries/refs.d.ts +1 -1
  117. package/dist/queries/refs.js +1 -1
  118. package/dist/queries/similar-chains.d.ts +1 -1
  119. package/dist/queries/similar-chains.js +1 -1
  120. package/dist/queries/similar-files.d.ts +1 -1
  121. package/dist/queries/similar-files.js +1 -1
  122. package/dist/queries/similar-signatures.d.ts +1 -1
  123. package/dist/queries/similar-signatures.js +1 -1
  124. package/dist/queries/similar.d.ts +1 -1
  125. package/dist/queries/similar.js +1 -1
  126. package/dist/queries/slice.d.ts +1 -1
  127. package/dist/queries/slice.js +1 -1
  128. package/dist/queries/stale-abstractions.d.ts +2 -1
  129. package/dist/queries/stale-abstractions.js +1 -1
  130. package/dist/queries/stats.d.ts +1 -1
  131. package/dist/queries/surface.d.ts +1 -1
  132. package/dist/queries/surface.js +1 -1
  133. package/dist/queries/symbols.d.ts +1 -1
  134. package/dist/queries/symbols.js +1 -1
  135. package/dist/queries/system.d.ts +1 -1
  136. package/dist/queries/system.js +1 -1
  137. package/dist/queries/trace.d.ts +1 -1
  138. package/dist/queries/trace.js +1 -1
  139. package/dist/queries/wrapper-candidates.d.ts +1 -1
  140. package/dist/queries/wrapper-candidates.js +1 -1
  141. package/dist/reindex-worker.js +63 -5
  142. package/package.json +15 -16
  143. package/skills/concrete-plan/SKILL.md +48 -22
  144. package/dist/chunk-5IADAU5B.js +0 -7
  145. package/dist/chunk-7754WFFV.js +0 -18
  146. package/dist/chunk-7VOF4ZG6.js +0 -2
  147. package/dist/chunk-7Z4COVMC.js +0 -2
  148. package/dist/chunk-EEF3YEHW.js +0 -2
  149. package/dist/chunk-F2LLHRRZ.js +0 -2
  150. package/dist/chunk-GNXRLK5G.js +0 -2
  151. package/dist/chunk-JH3A7HTU.js +0 -2
  152. package/dist/chunk-K6GBKEQE.js +0 -6
  153. package/dist/chunk-KO7YJRWP.js +0 -12
  154. package/dist/chunk-PZ6ESKRH.js +0 -7
  155. package/dist/chunk-RJ7SPBJ5.js +0 -5
  156. package/dist/chunk-TINPMWJK.js +0 -2
  157. package/dist/chunk-UJB62HV3.js +0 -2
  158. package/dist/chunk-VEUMRDHW.js +0 -2
  159. package/dist/chunk-WCDXJGYT.js +0 -65
  160. package/dist/chunk-Y7H6D2EV.js +0 -2
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{program as C}from"commander";import{createRequire as du}from"module";import{existsSync as rn,realpathSync as Ho}from"fs";import{join as pu}from"path";import{fileURLToPath as fu}from"url";import Yo from"better-sqlite3";import{statSync as qn}from"fs";var ft=class{db;config;pathFilter;constructor(n,t){this.config=n,this.pathFilter=t??null,this.db=new Yo(n.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000")}isIgnored(n){return this.pathFilter?.isIgnored(n)??!1}get localSymbolPredicate(){return`(
2
+ import{program as v}from"commander";import{createRequire as yd}from"module";import{existsSync as hn,realpathSync as pr}from"fs";import{join as bd}from"path";import{fileURLToPath as Sd}from"url";import br from"better-sqlite3";import{statSync as os}from"fs";var Lt=class{db;config;pathFilter;constructor(n,t){this.config=n,this.pathFilter=t??null,this.db=new br(n.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000")}isIgnored(n){return this.pathFilter?.isIgnored(n)??!1}get localSymbolPredicate(){return`(
3
3
  EXISTS (
4
4
  SELECT 1
5
5
  FROM defn_enclosing_ranges local_der
@@ -17,7 +17,7 @@ import{program as C}from"commander";import{createRequire as du}from"module";impo
17
17
  ${this.pathExclusionsFor("local_d").trimStart()}
18
18
  )
19
19
  )`}get pathExclusions(){return this.pathExclusionsFor("d")}get symbolNoise(){return this.symbolNoiseFor("gs")}pathExclusionsFor(...n){return n.flatMap(t=>[`AND ${t}.relative_path NOT LIKE 'node_modules/%'`,`AND ${t}.relative_path NOT LIKE '.git/%'`]).join(`
20
- `)}symbolNoiseFor(n){return`AND ${n}.symbol NOT LIKE '%().(%' AND ${n}.symbol NOT LIKE '%typeLiteral%'`}all(n,...t){return this.db.prepare(n).all(...t)}get(n,...t){return this.db.prepare(n).get(...t)}sizeBytes(){try{return qn(this.config.dbPath).size}catch{return 0}}lastModified(){try{return qn(this.config.dbPath).mtime}catch{return null}}close(){this.db.close()}};import Ko from"ignore";import{readFileSync as Vo,existsSync as ln}from"fs";import{dirname as cn,isAbsolute as zn,join as mn,relative as Qo,resolve as Xo}from"path";function gt(e){let n=Ko(),t=!1,i=Zo(e);for(let s of i)try{let o=Vo(s,"utf-8");n.add(o),t=!0}catch{}return t||n.add(er),{isIgnored:s=>Gn(n,e,s),filter:s=>s.filter(o=>!Gn(n,e,o))}}function Zo(e){let n=[],t=mn(e,".gitignore");ln(t)&&n.push(t);let i=cn(e),s=0;for(;i!==cn(i)&&s<5;){let o=mn(i,".gitignore");if(ln(o)&&n.push(o),ln(mn(i,".git")))break;i=cn(i),s++}return n}var er=`
20
+ `)}symbolNoiseFor(n){return`AND ${n}.symbol NOT LIKE '%().(%' AND ${n}.symbol NOT LIKE '%typeLiteral%'`}all(n,...t){return this.db.prepare(n).all(...t)}get(n,...t){return this.db.prepare(n).get(...t)}sizeBytes(){try{return os(this.config.dbPath).size}catch{return 0}}lastModified(){try{return os(this.config.dbPath).mtime}catch{return null}}close(){this.db.close()}};import Sr from"ignore";import{readFileSync as _r,existsSync as Sn}from"fs";import{dirname as _n,isAbsolute as rs,join as xn,relative as xr,resolve as Ir}from"path";function Ue(e){let n=Sr(),t=!1,s=Nr(e);for(let i of s)try{let o=_r(i,"utf-8");n.add(o),t=!0}catch{}return t||n.add(vr),{isIgnored:i=>as(n,e,i),filter:i=>i.filter(o=>!as(n,e,o))}}function Nr(e){let n=[],t=xn(e,".gitignore");Sn(t)&&n.push(t);let s=_n(e),i=0;for(;s!==_n(s)&&i<5;){let o=xn(s,".gitignore");if(Sn(o)&&n.push(o),Sn(xn(s,".git")))break;s=_n(s),i++}return n}var vr=`
21
21
  # Dependencies
22
22
  node_modules/
23
23
  vendor/
@@ -74,20 +74,71 @@ Thumbs.db
74
74
 
75
75
  # Type definitions (often noise in queries)
76
76
  *.d.ts
77
- `;function Gn(e,n,t){let i=tr(n,t);if(!i)return!1;try{return e.ignores(i)}catch{return!1}}function tr(e,n){if(!n||n===".")return null;if(!zn(n)&&!n.startsWith(".."))return n.replaceAll("\\","/");let t=zn(n)?n:Xo(e,n),i=Qo(e,t).replaceAll("\\","/");return!i||i==="."||i.startsWith("..")?null:i}import{readFileSync as nr,writeFileSync as ir,existsSync as Kn,mkdirSync as sr}from"fs";import{join as Oe,resolve as Yn}from"path";import{createHash as or}from"crypto";import{homedir as rr}from"os";var Vn=".scipquery.json",ar={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function $e(e){let n=Oe(e,Vn);if(!Kn(n))return{};try{let t=nr(n,"utf-8");return JSON.parse(t)}catch{return{}}}function Qn(e){return{...ar,...e.watch}}function lr(e,n){let t=process.env.SCIP_QUERY_CACHE_DIR;if(t)return un(t);if(n?.dbPath)return un(Yn(e,n.dbPath));let s=process.env.XDG_CACHE_HOME||Oe(rr(),".cache"),o=or("sha256").update(Yn(e)).digest("hex").slice(0,12),a=Oe(s,"scip-query","projects",o);return un(a)}function ke(e,n){let t=lr(e,n);return{cacheDir:t,dbPath:Oe(t,"index.db"),indexPath:Oe(t,"index.scip"),metaPath:Oe(t,"meta.json")}}function Xn(e,n){let t=Oe(e,Vn);return Kn(t)||ir(t,JSON.stringify({languages:n,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
78
- `),t}function un(e){return sr(e,{recursive:!0}),e}import{execFileSync as Si}from"child_process";import{existsSync as _i,renameSync as xi,rmSync as Wr}from"fs";import{basename as Hr,dirname as Jr,extname as Ur,join as It}from"path";import{execFileSync as yt}from"child_process";import{platform as bt,arch as cr}from"os";var Zn=bt()==="win32",ei="v0.7.0";function ht(e){let n=Zn?"where":"which";try{return yt(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function dn(){try{return yt(Zn?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function mr(){let e=bt(),n=cr(),t,i,s;switch(e){case"darwin":t="darwin",s="tar.gz";break;case"linux":t="linux",s="tar.gz";break;case"win32":t="windows",s="zip";break;default:return null}switch(n){case"arm64":i="arm64";break;case"x64":i="amd64";break;default:return null}let o=`scip-${t}-${i}.${s}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${ei}/${o}`,filename:o}}function pn(){let e=mr();console.log("\nThe `scip` CLI is required but not found on PATH.\n"),bt()==="darwin"?(console.log("Install via Homebrew:"),console.log(` brew install sourcegraph/scip/scip
77
+ `;function as(e,n,t){let s=Cr(n,t);if(!s)return!1;try{return e.ignores(s)}catch{return!1}}function Cr(e,n){if(!n||n===".")return null;if(!rs(n)&&!n.startsWith(".."))return n.replaceAll("\\","/");let t=rs(n)?n:Ir(e,n),s=xr(e,t).replaceAll("\\","/");return!s||s==="."||s.startsWith("..")?null:s}import{readFileSync as Er,writeFileSync as Rr,existsSync as cs,mkdirSync as Lr}from"fs";import{join as Fe,resolve as ls}from"path";import{createHash as wr}from"crypto";import{homedir as Dr}from"os";var us=".scipquery.json",kr={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function Te(e){let n=Fe(e,us);if(!cs(n))return{};try{let t=Er(n,"utf-8");return JSON.parse(t)}catch{return{}}}function ms(e){return{...kr,...e.watch}}function Or(e,n){let t=process.env.SCIP_QUERY_CACHE_DIR;if(t)return In(t);if(n?.dbPath)return In(ls(e,n.dbPath));let i=process.env.XDG_CACHE_HOME||Fe(Dr(),".cache"),o=wr("sha256").update(ls(e)).digest("hex").slice(0,12),a=Fe(i,"scip-query","projects",o);return In(a)}function Ae(e,n){let t=Or(e,n);return{cacheDir:t,dbPath:Fe(t,"index.db"),indexPath:Fe(t,"index.scip"),metaPath:Fe(t,"meta.json")}}function ds(e,n){let t=Fe(e,us);return cs(t)||Rr(t,JSON.stringify({languages:n,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
78
+ `),t}function In(e){return Lr(e,{recursive:!0}),e}import{execFileSync as js}from"child_process";import{existsSync as Bs,renameSync as Ws,rmSync as Ja}from"fs";import{basename as Ua,dirname as qa,extname as za,join as At}from"path";import{execFileSync as Dt}from"child_process";import{platform as kt,arch as $r}from"os";var ps=kt()==="win32",fs="v0.7.0";function wt(e){let n=ps?"where":"which";try{return Dt(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function Nn(){try{return Dt(ps?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function Pr(){let e=kt(),n=$r(),t,s,i;switch(e){case"darwin":t="darwin",i="tar.gz";break;case"linux":t="linux",i="tar.gz";break;case"win32":t="windows",i="zip";break;default:return null}switch(n){case"arm64":s="arm64";break;case"x64":s="amd64";break;default:return null}let o=`scip-${t}-${s}.${i}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${fs}/${o}`,filename:o}}function vn(){let e=Pr();console.log("\nThe `scip` CLI is required but not found on PATH.\n"),kt()==="darwin"?(console.log("Install via Homebrew:"),console.log(` brew install sourcegraph/scip/scip
79
79
  `),console.log("Or download manually:")):console.log("Download from:"),console.log(e?` ${e.url}
80
- `:` https://github.com/sourcegraph/scip/releases/tag/${ei}
81
- `),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function ti(e){if(bt()==="darwin"&&ht("brew")){e("Installing scip CLI via Homebrew...");try{if(yt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),ht("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`Homebrew install failed: ${t}`)}}if(ht("go")){e("Installing scip CLI via go install...");try{if(yt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),ht("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`go install failed: ${t}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import{existsSync as ur,readdirSync as ii}from"fs";import{extname as dr,join as si}from"path";var pr=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),fr=[{language:"typescript",files:["tsconfig.json","tsconfig.base.json"],extensions:[".ts",".tsx",".mts",".cts"]},{language:"rust",files:["Cargo.toml"],extensions:[".rs"]},{language:"go",files:["go.mod"],extensions:[".go"]},{language:"java",files:["pom.xml","build.gradle","build.gradle.kts"],extensions:[".java"]},{language:"kotlin",files:["build.gradle.kts"],extensions:[".kt",".kts"]},{language:"scala",files:["build.sbt"],extensions:[".scala"]},{language:"python",files:["pyproject.toml","setup.py","setup.cfg","Pipfile"],extensions:[".py",".pyi"]},{language:"ruby",files:["Gemfile"],extensions:[".rb"]},{language:"cpp",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".cc",".cpp",".cxx",".hpp",".hh",".hxx"]},{language:"c",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".c",".h"]},{language:"csharp",globs:["*.csproj","*.sln"],extensions:[".cs"]},{language:"vb",globs:["*.vbproj"],extensions:[".vb"]},{language:"dart",files:["pubspec.yaml"],extensions:[".dart"]},{language:"php",files:["composer.json"],extensions:[".php"]},{language:"javascript",files:["package.json"],extensions:[".js",".jsx",".mjs",".cjs"]}];function je(e){let n=[],t=gr(e),i=Sr(e);for(let s of fr){if(hr(e,s.files)){n.push(s.language);continue}if(yr(t,s.globs)){n.push(s.language);continue}_r(i,s.extensions)&&n.push(s.language)}return n.includes("typescript")&&ni(n,"javascript"),n.includes("cpp")&&!i.has(".c")&&ni(n,"c"),n}function gr(e){try{return ii(e)}catch{return[]}}function hr(e,n){return n?.length?n.some(t=>ur(si(e,t))):!1}function yr(e,n){return n?.length?e.some(t=>n.some(i=>br(t,i))):!1}function br(e,n){if(n==="*")return!0;if(!n.includes("*"))return e===n;let[t,i]=n.split("*");return e.startsWith(t??"")&&e.endsWith(i??"")}function Sr(e){let n=new Set,t=[e];for(;t.length>0;){let i=t.pop();if(!i)continue;let s;try{s=ii(i,{withFileTypes:!0})}catch{continue}for(let o of s){if(o.name.startsWith(".")&&!o.name.endsWith("proj")&&!o.name.endsWith("sln")&&o.isDirectory())continue;let a=si(i,o.name);if(o.isDirectory()){pr.has(o.name)||t.push(a);continue}let r=dr(o.name).toLowerCase();r&&n.add(r)}}return n}function _r(e,n){return n?.length?n.some(t=>e.has(t)):!1}function ni(e,n){let t=e.indexOf(n);t!==-1&&e.splice(t,1)}import{existsSync as oi,readdirSync as xr}from"fs";import{join as fn}from"path";var Ir={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:n})=>{let t=["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"];return n&&t.splice(2,0,"--pnpm-workspaces"),{binary:"npx",args:t}},markerFiles:["tsconfig.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},javascript:{language:"javascript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"]}),markerFiles:["package.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},java:{language:"java",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["pom.xml","build.gradle"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},scala:{language:"scala",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.sbt"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},kotlin:{language:"kotlin",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.gradle.kts"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},rust:{language:"rust",indexerBinary:"rust-analyzer",checkCommand:"rust-analyzer --version",indexArgs:({outputPath:e})=>({binary:"rust-analyzer",args:["scip",".","--output",e]}),markerFiles:["Cargo.toml"],installMethods:[{label:"rustup",prerequisite:"rustup",binary:"rustup",args:["component","add","rust-analyzer"]}],installUrl:"https://github.com/rust-lang/rust-analyzer"},python:{language:"python",indexerBinary:"scip-python",binaryAliases:["scip-python-plus"],checkCommand:"npx scip-python --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-python","index","--output",e,"--project-name","project"]}),markerFiles:["pyproject.toml","setup.py"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","scip-python-plus"]}],installUrl:"https://github.com/PlunderStruck/scip-python",bundledNpmPackage:"scip-python-plus"},ruby:{language:"ruby",indexerBinary:"scip-ruby",checkCommand:"scip-ruby --version",indexArgs:({indexerBinary:e})=>({binary:e,args:["--dir","."]}),defaultOutputPath:"index.scip",markerFiles:["Gemfile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-ruby/releases"},go:{language:"go",indexerBinary:"scip-go",checkCommand:"scip-go --version",indexArgs:({outputPath:e})=>({binary:"scip-go",args:["--output",e]}),markerFiles:["go.mod"],installMethods:[{label:"go install",prerequisite:"go",binary:"go",args:["install","github.com/sourcegraph/scip-go@latest"]}],installUrl:"https://github.com/sourcegraph/scip-go"},cpp:{language:"cpp",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},c:{language:"c",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},csharp:{language:"csharp",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".csproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.csproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},vb:{language:"vb",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".vbproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.vbproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},dart:{language:"dart",indexerBinary:"scip-dart",checkCommand:"scip-dart --version",indexArgs:({indexerBinary:e,outputPath:n})=>({binary:e,args:["--output",n]}),markerFiles:["pubspec.yaml"],installMethods:[{label:"dart pub",prerequisite:"dart",binary:"dart",args:["pub","global","activate","scip_dart"]}],installUrl:"https://github.com/Workiva/scip-dart/releases"},php:{language:"php",indexerBinary:"scip-php",projectLocalBinaries:["vendor/davidrjenni/scip-php/bin/scip-php","vendor/bin/scip-php"],checkCommand:"scip-php --version",indexArgs:({projectRoot:e,indexerBinary:n})=>{let t=fn(e,"vendor","bin","scip-php"),i=fn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",oi(i)?i:oi(t)?t:n]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function St(e){return Ir[e]}function ri(e,n){let t;try{t=xr(e)}catch{return null}for(let i of t)if(n.some(s=>i.endsWith(s)))return fn(e,i);return null}import{readFileSync as Nr,writeFileSync as Cr}from"fs";import{create as gn}from"@bufbuild/protobuf";import{deserializeSCIP as vr,serializeSCIP as Er,DocumentSchema as Lr,IndexSchema as Rr,SymbolInformationSchema as Dr}from"@c4312/scip";function wr(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let n=Or(e),t=$r(e.flatMap(s=>s.documents??[])),i=li(e.flatMap(s=>s.externalSymbols??[]));return gn(Rr,{metadata:n,documents:t,externalSymbols:i})}function ai(e,n){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let t=e.map(s=>vr(Nr(s))),i=wr(t);return Cr(n,Buffer.from(Er(i))),{documentCount:i.documents.length,externalSymbolCount:i.externalSymbols.length,inputCount:e.length}}function Or(e){let n=e[0]?.metadata;if(!n)return;let t=n.projectRoot;for(let i of e.slice(1)){let s=i.metadata?.projectRoot;if(t&&s&&s!==t)throw new Error(`Cannot merge SCIP indexes with different project roots: ${t} vs ${s}`)}return n}function $r(e){let n=new Map;for(let t of e){let i=n.get(t.relativePath);if(!i){n.set(t.relativePath,t);continue}n.set(t.relativePath,gn(Lr,{language:i.language||t.language,relativePath:i.relativePath||t.relativePath,occurrences:[...i.occurrences,...t.occurrences],symbols:li([...i.symbols,...t.symbols]),text:Pr(i.text,t.text),positionEncoding:i.positionEncoding||t.positionEncoding}))}return[...n.values()]}function li(e){let n=new Map;for(let t of e){let i=n.get(t.symbol);if(!i){n.set(t.symbol,t);continue}n.set(t.symbol,gn(Dr,{symbol:i.symbol,documentation:Mr([...i.documentation,...t.documentation]),relationships:kr([...i.relationships,...t.relationships]),kind:i.kind||t.kind,displayName:i.displayName||t.displayName,enclosingSymbol:i.enclosingSymbol||t.enclosingSymbol,signatureDocumentation:i.signatureDocumentation??t.signatureDocumentation}))}return[...n.values()]}function kr(e){let n=new Set,t=[];for(let i of e){let s=[i.symbol,i.isReference?"1":"0",i.isImplementation?"1":"0",i.isTypeDefinition?"1":"0",i.isDefinition?"1":"0"].join("|");n.has(s)||(n.add(s),t.push(i))}return t}function Pr(e,n){return e?n?e.length>=n.length?e:n:e:n}function Mr(e){return[...new Set(e)]}import{execFileSync as _t}from"child_process";import{existsSync as hn}from"fs";import{createRequire as Fr}from"module";import{platform as ci}from"os";import{join as mi}from"path";var Tr=Fr(import.meta.url),Ar=ci()==="win32";function Ze(e){let n=Ar?"where":"which";try{return _t(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function ui(e){return[e.indexerBinary,...e.binaryAliases??[]]}function xt(e){let n=ui(e);return n.length===1?n[0]:n.join(" or ")}function Be(e){for(let n of ui(e))if(Ze(n))return n;return pi(e)?e.indexerBinary:null}function di(e){return Be(e)!==null||pi(e)}function pi(e){if(!e.bundledNpmPackage)return!1;try{return Tr.resolve(`${e.bundledNpmPackage}/package.json`),!0}catch{return!1}}function yn(e,n){for(let t of e.projectLocalBinaries??[]){let i=mi(n,t);if(hn(i))return i}return null}function jr(e,n){return yn(e,n)??Be(e)}function fi(e,n=process.env,t=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||bn(t,n))return n;let i=yi(t,n);return i?{...n,DOTNET_ROOT:i}:n}function gi(e,n){let t=xt(e),i=n?jr(e,n):Be(e);if(!i)return{language:e.language,binaryLabel:t,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:t,installed:!0,runnable:!0,resolvedBinary:i};let s=Br(i);return{language:e.language,binaryLabel:t,installed:!0,runnable:s.runnable,resolvedBinary:i,installUrl:e.installUrl,note:s.note}}function hi(e,n){let t=e.installMethods,i=xt(e);if(!t?.length)return n(`No auto-install method available for ${i}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1;for(let s of t)if(Ze(s.prerequisite)){n(`Installing ${i} via ${s.label}...`);try{_t(s.binary,s.args,{stdio:"inherit",timeout:3e5,env:process.env});let o=Be(e);if(o){let a=o===e.indexerBinary?"":` (using ${o})`;return n(`Successfully installed ${i} via ${s.label}${a}`),!0}n(`${s.label} command completed but ${i} was not found on PATH`)}catch(o){let a=o instanceof Error?o.message:String(o);n(`${s.label} install failed: ${a}`)}}return n(`Could not auto-install ${i}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1}function Br(e){if(bn(e,process.env))return{runnable:!0};let n=yi(e,process.env);if(n)return{runnable:!0,note:`using .NET 9 runtime from ${n}`};let t=bi(process.env);return{runnable:!1,note:t.length>0?`.NET 9 runtime still unavailable after checking ${t.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function yi(e,n){for(let t of bi(n))if(bn(e,{...n,DOTNET_ROOT:t}))return t;return null}function bi(e){let n=[],t=e.DOTNET_ROOT;if(t&&hn(t)&&n.push(t),ci()==="darwin"&&Ze("brew"))try{let i=_t("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),s=mi(i,"libexec");hn(s)&&!n.includes(s)&&n.push(s)}catch{}return n}function bn(e,n){try{return _t(e,["--version"],{stdio:"pipe",env:n}),!0}catch{return!1}}async function Ii(e){let{projectRoot:n,maxHeapMb:t=8192,onStatus:i=console.log,skipAutoInstall:s=!1}=e,o=e.outputScip??It(n,"index.scip"),a=e.outputDb??It(n,"index.db"),r=Date.now(),l=e.languages??je(n);if(l.length===0)throw new Error("No supported languages detected in this project. Looked for: tsconfig.json, Cargo.toml, go.mod, pyproject.toml, etc.");if(i(`Detected languages: ${l.join(", ")}`),!Ze("scip")){if(s)throw new Error(`The scip CLI is required but not found on PATH.
82
- Install from: https://github.com/sourcegraph/scip/releases`);if(i("scip CLI not found on PATH. Attempting auto-install..."),!ti(i))throw new Error(`The scip CLI is required but could not be installed.
83
- Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...process.env,NODE_OPTIONS:`--max-old-space-size=${t}`},m=l.map((p,g)=>({language:p,scipPath:l.length>1?zr(o,p,g):o})),u=[],d=[];for(let{language:p,scipPath:g}of m){let y=St(p),h=xt(y),b=yn(y,n);if(!b&&!di(y)){if(s){let D=`${h} not found on PATH (auto-install disabled). ${y.installUrl??""}`.trim();i(`Skipping ${p}: ${D}`),d.push({language:p,reason:D});continue}if(i(`${h} not found. Attempting auto-install...`),!hi(y,i)){let D=`${h} could not be auto-installed. ${y.installUrl?`Install manually from ${y.installUrl}`:`Install ${h} and put it on PATH.`}`;i(`Skipping ${p}: ${D}`),d.push({language:p,reason:D});continue}}let x=b??Be(y);if(!x){let D=`${h} was not found after installation checks.`;i(`Skipping ${p}: ${D}`),d.push({language:p,reason:D});continue}i(`Indexing ${p} with ${x}...`);let S=fi(y,c,x),{binary:I,args:L}=y.indexArgs({projectRoot:n,outputPath:g,pnpmWorkspaces:e.pnpmWorkspaces,indexerBinary:x});try{Si(I,L,{cwd:n,env:S,stdio:"pipe",maxBuffer:50*1024*1024})}catch(D){let k=D instanceof Error?D.message:String(D),U=`${x} indexer failed: ${k.split(`
84
- `)[0]}`;i(`Skipping ${p}: ${U}`),d.push({language:p,reason:U});continue}qr(y,n,g),u.push({language:p,scipPath:g})}if(u.length===0){let p=d.map(g=>` - ${g.language}: ${g.reason}`).join(`
80
+ `:` https://github.com/sourcegraph/scip/releases/tag/${fs}
81
+ `),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function gs(e){if(kt()==="darwin"&&wt("brew")){e("Installing scip CLI via Homebrew...");try{if(Dt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),wt("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`Homebrew install failed: ${t}`)}}if(wt("go")){e("Installing scip CLI via go install...");try{if(Dt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),wt("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`go install failed: ${t}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import Br from"better-sqlite3";import{existsSync as Wr,readdirSync as Hr,readFileSync as Jr}from"fs";import{extname as En,join as bs}from"path";import{readdirSync as Mr}from"fs";import{extname as hs,join as Fr}from"path";function W(e){let n=new WeakMap,t=s=>{let i=n.get(s);return i||(i=new Map,n.set(s,i)),i};return{get(s,i,o){let a=t(s);if(a.has(i))return a.get(i);let r=o();return a.set(i,r),r},invalidate(s,i){n.get(s)?.delete(i)},invalidateAll(s){n.delete(s)},size(s){return n.get(s)?.size??0}}}function je(e){let n=new WeakMap;return{get(t,s){let i=n.get(t);if(i)return i.value;let o=s();return n.set(t,{value:o}),o},invalidate(t){n.delete(t)},has(t){return n.has(t)}}}function Ot(e){let n=new WeakMap,t=s=>{let i=n.get(s);return i||(i=new Map,n.set(s,i)),i};return{get(s,i,o,a){let r=t(s),l=r.get(i);if(l&&l.source===o)return l.value;let c=a();return r.set(i,{source:o,value:c}),c},invalidate(s,i){n.get(s)?.delete(i)},invalidateAll(s){n.delete(s)}}}var Tr=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue",".rs",".py",".pyi",".java",".kt",".kts",".scala",".sc",".rb",".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx",".cs",".vb",".php",".dart"],ys=[".vue"],Cn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Re(e,n={}){let t=n.includeIndexed??!0,s=n.includeAuxiliary??!0,i=n.extensions?new Set(n.extensions.map(a=>a.toLowerCase())):new Set(Tr.map(a=>a.toLowerCase())),o=`${t?"1":"0"}|${s?"1":"0"}|${[...i].sort().join(",")}`;return Ar.get(e,o,()=>{let a=new Set;if(t){let r=e.all(`SELECT relative_path
82
+ FROM documents
83
+ WHERE 1 = 1
84
+ ${e.pathExclusionsFor("documents")}`);for(let l of r)e.isIgnored(l.relative_path)||i.has(hs(l.relative_path).toLowerCase())&&a.add(l.relative_path)}if(s)for(let r of jr(e.config.projectRoot,i))e.isIgnored(r)||a.add(r);return[...a].sort()})}var Ar=W("source-files");function jr(e,n){let t=new Set,s=i=>{let o=i?Fr(e,i):e,a=[];try{a=Mr(o,{withFileTypes:!0})}catch{return}for(let r of a)if(!Cn.has(r.name)){if(r.isDirectory()){s(i?`${i}/${r.name}`:r.name);continue}n.has(hs(r.name).toLowerCase())&&t.add(i?`${i}/${r.name}`:r.name)}};return s(""),t}function Be(e){let n=new Set((e.extensions??ys).map(o=>o.toLowerCase()));if(n.size===0)return{scanned:0,inserted:0,existing:0};if(!Wr(e.dbPath))throw new Error(`SCIP SQLite database not found at ${e.dbPath}`);let t=Ue(e.projectRoot),s=Ur(e.projectRoot,n).filter(o=>!t.isIgnored(o)),i=new Br(e.dbPath);try{let o=s.length===0?new Set:new Set(i.prepare(`SELECT relative_path FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s).map(m=>m.relative_path)),a=i.prepare(`INSERT OR IGNORE INTO documents (language, relative_path, position_encoding, text)
85
+ VALUES (?, ?, NULL, ?)`),l=i.transaction(m=>{let u=0;for(let d of m){if(o.has(d))continue;let g=Jr(bs(e.projectRoot,d),"utf-8"),p=a.run(qr(d),d,g);u+=Number(p.changes)}return u})(s),c={scanned:s.length,inserted:l,existing:s.length-l};return e.onStatus?.(`Augmented SQLite documents with ${l} auxiliary source file${l===1?"":"s"} (${c.existing} already present).`),c}finally{i.close()}}function Ur(e,n){let t=[],s=i=>{let o=i?bs(e,i):e,a=[];try{a=Hr(o,{withFileTypes:!0})}catch{return}for(let r of a){if(Cn.has(r.name))continue;let l=i?`${i}/${r.name}`:r.name;if(r.isDirectory()){s(l);continue}n.has(En(r.name).toLowerCase())&&t.push(l)}};return s(""),t.sort()}function qr(e){return En(e).toLowerCase()===".vue"?"vue":En(e).replace(/^\./,"").toLowerCase()||"source"}import{existsSync as zr,readdirSync as _s}from"fs";import{extname as Vr,join as xs}from"path";var Gr=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),Yr=[{language:"typescript",files:["tsconfig.json","tsconfig.base.json"],extensions:[".ts",".tsx",".mts",".cts"]},{language:"rust",files:["Cargo.toml"],extensions:[".rs"]},{language:"go",files:["go.mod"],extensions:[".go"]},{language:"java",files:["pom.xml","build.gradle","build.gradle.kts"],extensions:[".java"]},{language:"kotlin",files:["build.gradle.kts"],extensions:[".kt",".kts"]},{language:"scala",files:["build.sbt"],extensions:[".scala"]},{language:"python",files:["pyproject.toml","setup.py","setup.cfg","Pipfile"],extensions:[".py",".pyi"]},{language:"ruby",files:["Gemfile"],extensions:[".rb"]},{language:"cpp",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".cc",".cpp",".cxx",".hpp",".hh",".hxx"]},{language:"c",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".c",".h"]},{language:"csharp",globs:["*.csproj","*.sln"],extensions:[".cs"]},{language:"vb",globs:["*.vbproj"],extensions:[".vb"]},{language:"dart",files:["pubspec.yaml"],extensions:[".dart"]},{language:"php",files:["composer.json"],extensions:[".php"]},{language:"javascript",files:["package.json"],extensions:[".js",".jsx",".mjs",".cjs"]}];function qe(e){let n=[],t=Kr(e),s=ea(e);for(let i of Yr){if(Qr(e,i.files)){n.push(i.language);continue}if(Xr(t,i.globs)){n.push(i.language);continue}ta(s,i.extensions)&&n.push(i.language)}return n.includes("typescript")&&Ss(n,"javascript"),n.includes("cpp")&&!s.has(".c")&&Ss(n,"c"),n}function Kr(e){try{return _s(e)}catch{return[]}}function Qr(e,n){return n?.length?n.some(t=>zr(xs(e,t))):!1}function Xr(e,n){return n?.length?e.some(t=>n.some(s=>Zr(t,s))):!1}function Zr(e,n){if(n==="*")return!0;if(!n.includes("*"))return e===n;let[t,s]=n.split("*");return e.startsWith(t??"")&&e.endsWith(s??"")}function ea(e){let n=new Set,t=[e];for(;t.length>0;){let s=t.pop();if(!s)continue;let i;try{i=_s(s,{withFileTypes:!0})}catch{continue}for(let o of i){if(o.name.startsWith(".")&&!o.name.endsWith("proj")&&!o.name.endsWith("sln")&&o.isDirectory())continue;let a=xs(s,o.name);if(o.isDirectory()){Gr.has(o.name)||t.push(a);continue}let r=Vr(o.name).toLowerCase();r&&n.add(r)}}return n}function ta(e,n){return n?.length?n.some(t=>e.has(t)):!1}function Ss(e,n){let t=e.indexOf(n);t!==-1&&e.splice(t,1)}import{existsSync as Is,readdirSync as na}from"fs";import{join as Rn}from"path";var sa={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:n})=>{let t=["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"];return n&&t.splice(2,0,"--pnpm-workspaces"),{binary:"npx",args:t}},markerFiles:["tsconfig.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},javascript:{language:"javascript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"]}),markerFiles:["package.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},java:{language:"java",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["pom.xml","build.gradle"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},scala:{language:"scala",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.sbt"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},kotlin:{language:"kotlin",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.gradle.kts"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},rust:{language:"rust",indexerBinary:"rust-analyzer",checkCommand:"rust-analyzer --version",indexArgs:({outputPath:e})=>({binary:"rust-analyzer",args:["scip",".","--output",e]}),markerFiles:["Cargo.toml"],installMethods:[{label:"rustup",prerequisite:"rustup",binary:"rustup",args:["component","add","rust-analyzer"]}],installUrl:"https://github.com/rust-lang/rust-analyzer"},python:{language:"python",indexerBinary:"scip-python",binaryAliases:["scip-python-plus"],checkCommand:"npx scip-python --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-python","index","--output",e,"--project-name","project"]}),markerFiles:["pyproject.toml","setup.py"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","scip-python-plus"]}],installUrl:"https://github.com/PlunderStruck/scip-python",bundledNpmPackage:"scip-python-plus"},ruby:{language:"ruby",indexerBinary:"scip-ruby",checkCommand:"scip-ruby --version",indexArgs:({indexerBinary:e})=>({binary:e,args:["--dir","."]}),defaultOutputPath:"index.scip",markerFiles:["Gemfile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-ruby/releases"},go:{language:"go",indexerBinary:"scip-go",checkCommand:"scip-go --version",indexArgs:({outputPath:e})=>({binary:"scip-go",args:["--output",e]}),markerFiles:["go.mod"],installMethods:[{label:"go install",prerequisite:"go",binary:"go",args:["install","github.com/sourcegraph/scip-go@latest"]}],installUrl:"https://github.com/sourcegraph/scip-go"},cpp:{language:"cpp",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},c:{language:"c",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},csharp:{language:"csharp",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",Ns(e,[".sln",".csproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.csproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},vb:{language:"vb",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",Ns(e,[".sln",".vbproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.vbproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},dart:{language:"dart",indexerBinary:"scip-dart",checkCommand:"scip-dart --version",indexArgs:({indexerBinary:e,outputPath:n})=>({binary:e,args:["--output",n]}),markerFiles:["pubspec.yaml"],installMethods:[{label:"dart pub",prerequisite:"dart",binary:"dart",args:["pub","global","activate","scip_dart"]}],installUrl:"https://github.com/Workiva/scip-dart/releases"},php:{language:"php",indexerBinary:"scip-php",projectLocalBinaries:["vendor/davidrjenni/scip-php/bin/scip-php","vendor/bin/scip-php"],checkCommand:"scip-php --version",indexArgs:({projectRoot:e,indexerBinary:n})=>{let t=Rn(e,"vendor","bin","scip-php"),s=Rn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",Is(s)?s:Is(t)?t:n]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function $t(e){return sa[e]}function Ns(e,n){let t;try{t=na(e)}catch{return null}for(let s of t)if(n.some(i=>s.endsWith(i)))return Rn(e,s);return null}import{readFileSync as ia,writeFileSync as oa}from"fs";import{create as Ln}from"@bufbuild/protobuf";import{deserializeSCIP as ra,serializeSCIP as aa,DocumentSchema as la,IndexSchema as ca,SymbolInformationSchema as ua}from"@c4312/scip";function ma(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let n=da(e),t=pa(e.flatMap(i=>i.documents??[])),s=Cs(e.flatMap(i=>i.externalSymbols??[]));return Ln(ca,{metadata:n,documents:t,externalSymbols:s})}function vs(e,n){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let t=e.map(i=>ra(ia(i))),s=ma(t);return oa(n,Buffer.from(aa(s))),{documentCount:s.documents.length,externalSymbolCount:s.externalSymbols.length,inputCount:e.length}}function da(e){let n=e[0]?.metadata;if(!n)return;let t=n.projectRoot;for(let s of e.slice(1)){let i=s.metadata?.projectRoot;if(t&&i&&i!==t)throw new Error(`Cannot merge SCIP indexes with different project roots: ${t} vs ${i}`)}return n}function pa(e){let n=new Map;for(let t of e){let s=n.get(t.relativePath);if(!s){n.set(t.relativePath,t);continue}n.set(t.relativePath,Ln(la,{language:s.language||t.language,relativePath:s.relativePath||t.relativePath,occurrences:[...s.occurrences,...t.occurrences],symbols:Cs([...s.symbols,...t.symbols]),text:ga(s.text,t.text),positionEncoding:s.positionEncoding||t.positionEncoding}))}return[...n.values()]}function Cs(e){let n=new Map;for(let t of e){let s=n.get(t.symbol);if(!s){n.set(t.symbol,t);continue}n.set(t.symbol,Ln(ua,{symbol:s.symbol,documentation:ha([...s.documentation,...t.documentation]),relationships:fa([...s.relationships,...t.relationships]),kind:s.kind||t.kind,displayName:s.displayName||t.displayName,enclosingSymbol:s.enclosingSymbol||t.enclosingSymbol,signatureDocumentation:s.signatureDocumentation??t.signatureDocumentation}))}return[...n.values()]}function fa(e){let n=new Set,t=[];for(let s of e){let i=[s.symbol,s.isReference?"1":"0",s.isImplementation?"1":"0",s.isTypeDefinition?"1":"0",s.isDefinition?"1":"0"].join("|");n.has(i)||(n.add(i),t.push(s))}return t}function ga(e,n){return e?n?e.length>=n.length?e:n:e:n}function ha(e){return[...new Set(e)]}import{execFileSync as Pt}from"child_process";import{existsSync as wn}from"fs";import{createRequire as ya}from"module";import{platform as Es}from"os";import{join as Rs}from"path";var ba=ya(import.meta.url),Sa=Es()==="win32";function lt(e){let n=Sa?"where":"which";try{return Pt(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function Ls(e){return[e.indexerBinary,...e.binaryAliases??[]]}function Mt(e){let n=Ls(e);return n.length===1?n[0]:n.join(" or ")}function ze(e){for(let n of Ls(e))if(lt(n))return n;return Ds(e)?e.indexerBinary:null}function ws(e){return ze(e)!==null||Ds(e)}function Ds(e){if(!e.bundledNpmPackage)return!1;try{return ba.resolve(`${e.bundledNpmPackage}/package.json`),!0}catch{return!1}}function Dn(e,n){for(let t of e.projectLocalBinaries??[]){let s=Rs(n,t);if(wn(s))return s}return null}function _a(e,n){return Dn(e,n)??ze(e)}function ks(e,n=process.env,t=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||kn(t,n))return n;let s=Ps(t,n);return s?{...n,DOTNET_ROOT:s}:n}function Os(e,n){let t=Mt(e),s=n?_a(e,n):ze(e);if(!s)return{language:e.language,binaryLabel:t,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:t,installed:!0,runnable:!0,resolvedBinary:s};let i=xa(s);return{language:e.language,binaryLabel:t,installed:!0,runnable:i.runnable,resolvedBinary:s,installUrl:e.installUrl,note:i.note}}function $s(e,n){let t=e.installMethods,s=Mt(e);if(!t?.length)return n(`No auto-install method available for ${s}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1;for(let i of t)if(lt(i.prerequisite)){n(`Installing ${s} via ${i.label}...`);try{Pt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let o=ze(e);if(o){let a=o===e.indexerBinary?"":` (using ${o})`;return n(`Successfully installed ${s} via ${i.label}${a}`),!0}n(`${i.label} command completed but ${s} was not found on PATH`)}catch(o){let a=o instanceof Error?o.message:String(o);n(`${i.label} install failed: ${a}`)}}return n(`Could not auto-install ${s}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1}function xa(e){if(kn(e,process.env))return{runnable:!0};let n=Ps(e,process.env);if(n)return{runnable:!0,note:`using .NET 9 runtime from ${n}`};let t=Ms(process.env);return{runnable:!1,note:t.length>0?`.NET 9 runtime still unavailable after checking ${t.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function Ps(e,n){for(let t of Ms(n))if(kn(e,{...n,DOTNET_ROOT:t}))return t;return null}function Ms(e){let n=[],t=e.DOTNET_ROOT;if(t&&wn(t)&&n.push(t),Es()==="darwin"&&lt("brew"))try{let s=Pt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Rs(s,"libexec");wn(i)&&!n.includes(i)&&n.push(i)}catch{}return n}function kn(e,n){try{return Pt(e,["--version"],{stdio:"pipe",env:n}),!0}catch{return!1}}import Ia from"better-sqlite3";import{createRequire as Na}from"module";import{existsSync as Fs,readFileSync as Ft}from"fs";import{dirname as va,extname as Ca,join as Ts,relative as Ea,resolve as Ra}from"path";import{pathToFileURL as La}from"url";function On(e){Be({projectRoot:e.projectRoot,dbPath:e.dbPath});let n=Ra(e.projectRoot,e.tsconfig);if(!Fs(n))throw new Error(`Vue tsconfig not found at ${n}`);let t=Da(e.projectRoot,n),s=t.fileNames.filter(o=>o.endsWith(".vue")),i=new Ia(e.dbPath);try{wa(i);let o=ka(i,e.projectRoot),a=Oa(i,e.projectRoot,s),r=[],l=0;for(let m of s){let u=t.language.scripts.get(m),d=u?.generated?.languagePlugin.typescript?.getServiceScript(u.generated.root)?.code;if(!u||!d){l++;continue}let g=t.language.maps.get(d,u),p=Ft(m,"utf-8");for(let f of Ma(p)){let y=Fa(g,f.start);if(y===null)continue;let b=(t.languageService.getDefinitionAtPosition(m,y+1)??[]).find(x=>!Aa(e.projectRoot,x.fileName));if(!b){l++;continue}let _=$a(b,o,a,t,e.projectRoot);if(_===null){l++;continue}let S=As(p,f.start);r.push({sourceFile:Tt(e.projectRoot,m),sourceLine:S.line,sourceStartChar:S.character,sourceEndChar:S.character+f.text.length,symbolId:_})}}let c=Pa(i,r);return e.onStatus?.(`Resolved ${r.length} Vue references with Volar; inserted ${c} mentions.`),{vueFiles:s.length,resolvedReferences:r.length,insertedMentions:c,skippedReferences:l,syntheticSymbols:a.syntheticSymbols}}finally{i.close()}}function wa(e){e.transaction(()=>{e.prepare(`
86
+ DELETE FROM mentions
87
+ WHERE chunk_id IN (
88
+ SELECT c.id
89
+ FROM chunks c
90
+ JOIN documents d ON d.id = c.document_id
91
+ WHERE d.language = 'vue' OR d.relative_path LIKE '%.vue'
92
+ )
93
+ `).run(),e.prepare(`
94
+ DELETE FROM chunks
95
+ WHERE document_id IN (
96
+ SELECT id
97
+ FROM documents
98
+ WHERE language = 'vue' OR relative_path LIKE '%.vue'
99
+ )
100
+ `).run()})()}function Da(e,n){let t=Na(La(Ts(e,"package.json")).href),s=t("typescript"),i=t("@vue/language-core"),o=t("@volar/typescript"),a=s.readConfigFile(n,s.sys.readFile);if(a.error||!a.config)throw new Error(`Failed to read ${n}`);let l=i.createParsedCommandLine(s,s.sys,n).vueOptions;typeof i.createGlobalTypesWriter=="function"&&(l.globalTypesPath=i.createGlobalTypesWriter(l,s.sys.writeFile));let c=i.getAllExtensions(l).map(h=>({extension:h.slice(1),isMixedContent:!0,scriptKind:s.ScriptKind.Deferred})),m=va(n),u=s.parseJsonConfigFileContent(a.config,s.sys,m,void 0,n,void 0,c),d=i.createVueLanguagePlugin(s,u.options,l,h=>h),g;g=i.createLanguage([d],new Map,h=>{if(!Fs(h))return;let b=Ft(h,"utf-8");g.scripts.set(h,s.ScriptSnapshot.fromString(b),d.getLanguageId(h)??ja(h))});let p={getCurrentDirectory:()=>m,getCompilationSettings:()=>u.options,getScriptFileNames:()=>u.fileNames,getProjectReferences:()=>u.projectReferences,getProjectVersion:()=>"0"},{languageServiceHost:f}=o.createLanguageServiceHost(s,s.sys,g,h=>h,p),y=s.createLanguageService(f);return{ts:s,language:g,languageService:y,fileNames:u.fileNames,configDir:m}}function ka(e,n){let t=e.prepare(`
101
+ SELECT der.symbol_id AS symbolId
102
+ FROM defn_enclosing_ranges der
103
+ JOIN documents d ON d.id = der.document_id
104
+ WHERE d.relative_path = ?
105
+ AND der.start_line <= ?
106
+ AND der.end_line >= ?
107
+ ORDER BY (der.end_line - der.start_line) ASC
108
+ LIMIT 1
109
+ `),s=e.prepare(`
110
+ SELECT der.symbol_id AS symbolId
111
+ FROM defn_enclosing_ranges der
112
+ JOIN documents d ON d.id = der.document_id
113
+ WHERE d.relative_path = ?
114
+ AND der.start_line BETWEEN ? AND ?
115
+ ORDER BY ABS(der.start_line - ?) ASC
116
+ LIMIT 1
117
+ `);return i=>{let o=Tt(n,i.fileName),a=Ba(i.fileName);if(!a)return null;let r=As(a,i.textSpan.start),l=t.get(o,r.line,r.line);return l?l.symbolId:s.get(o,Math.max(0,r.line-2),r.line+2,r.line)?.symbolId??null}}function Oa(e,n,t){let s=Wa(n),i=e.prepare("SELECT id FROM global_symbols WHERE symbol = ?"),o=e.prepare(`
118
+ INSERT OR IGNORE INTO global_symbols (symbol, display_name, kind, documentation)
119
+ VALUES (?, ?, ?, ?)
120
+ `),a=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),r=e.prepare(`
121
+ INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
122
+ VALUES (?, ?, ?, ?, X'00')
123
+ `),l=e.prepare(`
124
+ INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
125
+ VALUES (?, ?, 1)
126
+ `),c=0,m=new Map;return e.transaction(()=>{for(let d of t){let g=Tt(n,d),p=Ha(s.name,s.version,g);o.run(p,"default",7,`Vue component|${g}`);let f=i.get(p);if(!f)continue;c++,m.set(d,f.id);let y=a.get(g);if(!y)continue;let h=r.run(y.id,-1,0,0);l.run(Number(h.lastInsertRowid),f.id)}})(),{get(d){return m.get(d)??null},syntheticSymbols:c}}function $a(e,n,t,s,i){if(e.fileName.endsWith(".vue")){let o=s.language.scripts.get(e.fileName),a=o?.generated?.languagePlugin.typescript?.getServiceScript(o.generated.root)?.code;if(o&&a){let r=s.language.maps.get(a,o);if(Ta(r,e.textSpan.start)!==null)return t.get(e.fileName)}return e.fileName.startsWith(i)?t.get(e.fileName):null}return n(e)}function Pa(e,n){let t=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),s=e.prepare(`
127
+ INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
128
+ VALUES (?, ?, ?, ?, X'00')
129
+ `),i=e.prepare(`
130
+ INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
131
+ VALUES (?, ?, 0)
132
+ `),o=new Set;return e.transaction(()=>{let r=0,l=0;for(let c of n){let m=`${c.sourceFile}:${c.sourceLine}:${c.sourceStartChar}:${c.symbolId}`;if(o.has(m))continue;o.add(m);let u=t.get(c.sourceFile);if(!u)continue;let d=s.run(u.id,l++,c.sourceLine,c.sourceLine),g=i.run(Number(d.lastInsertRowid),c.symbolId);r+=Number(g.changes)}return r})()}function*Ma(e){let n=/\b[A-Za-z_$][A-Za-z0-9_$]*\b/g,t=new Set(["script","setup","template","style","lang","scoped","true","false","null","undefined","const","let","var","import","from","export","return","if","else","for","while","function","class","type","interface","as","await","async"]),s;for(;s=n.exec(e);){let i=s[0];t.has(i)||(yield{text:i,start:s.index,end:s.index+i.length})}}function Fa(e,n){for(let[t]of e.toGeneratedLocation(n,s=>!!s.navigation))return t;return null}function Ta(e,n){let t=e;for(let[s]of t.toSourceLocation(n,i=>!!i.navigation))return s;return null}function As(e,n){let t=0,s=0;for(let i=0;i<n;i++)e.charCodeAt(i)===10&&(t++,s=i+1);return{line:t,character:n-s}}function Aa(e,n){return Tt(e,n).startsWith("node_modules/")}function Tt(e,n){return Ea(e,n).replaceAll("\\","/")}function ja(e){switch(Ca(e)){case".vue":return"vue";case".tsx":return"typescriptreact";case".ts":case".mts":case".cts":return"typescript";case".jsx":return"javascriptreact";case".js":case".mjs":case".cjs":return"javascript";case".json":return"json";default:return"typescript"}}function Ba(e){try{return Ft(e,"utf-8")}catch{return null}}function Wa(e){try{let n=JSON.parse(Ft(Ts(e,"package.json"),"utf-8"));return{name:n.name??"workspace",version:n.version??"0.0.0"}}catch{return{name:"workspace",version:"0.0.0"}}}function Ha(e,n,t){let s=t.split("/").map(i=>`\`${i.replaceAll("`","")}\``).join("/");return`scip-vue npm ${e} ${n} ${s}/default.`}async function Hs(e){let{projectRoot:n,maxHeapMb:t=8192,onStatus:s=console.log,skipAutoInstall:i=!1}=e,o=e.outputScip??At(n,"index.scip"),a=e.outputDb??At(n,"index.db"),r=Date.now(),l=e.languages??qe(n);if(l.length===0)throw new Error("No supported languages detected in this project. Looked for: tsconfig.json, Cargo.toml, go.mod, pyproject.toml, etc.");if(s(`Detected languages: ${l.join(", ")}`),!lt("scip")){if(i)throw new Error(`The scip CLI is required but not found on PATH.
133
+ Install from: https://github.com/sourcegraph/scip/releases`);if(s("scip CLI not found on PATH. Attempting auto-install..."),!gs(s))throw new Error(`The scip CLI is required but could not be installed.
134
+ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...process.env,NODE_OPTIONS:`--max-old-space-size=${t}`},m=l.map((p,f)=>({language:p,scipPath:l.length>1?Ga(o,p,f):o})),u=[],d=[];for(let{language:p,scipPath:f}of m){let y=$t(p),h=Mt(y),b=Dn(y,n);if(!b&&!ws(y)){if(i){let w=`${h} not found on PATH (auto-install disabled). ${y.installUrl??""}`.trim();s(`Skipping ${p}: ${w}`),d.push({language:p,reason:w});continue}if(s(`${h} not found. Attempting auto-install...`),!$s(y,s)){let w=`${h} could not be auto-installed. ${y.installUrl?`Install manually from ${y.installUrl}`:`Install ${h} and put it on PATH.`}`;s(`Skipping ${p}: ${w}`),d.push({language:p,reason:w});continue}}let _=b??ze(y);if(!_){let w=`${h} was not found after installation checks.`;s(`Skipping ${p}: ${w}`),d.push({language:p,reason:w});continue}s(`Indexing ${p} with ${_}...`);let S=ks(y,c,_),{binary:x,args:L}=y.indexArgs({projectRoot:n,outputPath:f,pnpmWorkspaces:e.pnpmWorkspaces,indexerBinary:_});try{js(x,L,{cwd:n,env:S,stdio:"pipe",maxBuffer:50*1024*1024})}catch(w){let $=w instanceof Error?w.message:String(w),q=`${_} indexer failed: ${$.split(`
135
+ `)[0]}`;s(`Skipping ${p}: ${q}`),d.push({language:p,reason:q});continue}Va(y,n,f),u.push({language:p,scipPath:f})}if(u.length===0){let p=d.map(f=>` - ${f.language}: ${f.reason}`).join(`
85
136
  `);throw new Error(`No language indexers ran successfully. Install at least one indexer for the languages in this project.
86
- `+p)}if(d.length>0&&i(`Indexed ${u.length} of ${l.length} languages; skipped ${d.map(p=>p.language).join(", ")}.`),l.length>1&&(u.length>1?(i(`Merging ${u.length} language indexes...`),ai(u.map(p=>p.scipPath),o)):u[0].scipPath!==o&&xi(u[0].scipPath,o)),i("Converting to SQLite..."),!_i(o))throw new Error(`SCIP index not found at ${o} after indexing`);try{Si("scip",["expt-convert","--output",a,o],{env:c,stdio:"pipe",maxBuffer:50*1024*1024})}catch(p){let g=p instanceof Error?p.message:String(p);throw new Error(`Failed to convert SCIP index to SQLite: ${g}`,{cause:p})}finally{for(let{scipPath:p}of m)p!==o&&Wr(p,{force:!0})}let f=Date.now()-r;return i(`Done in ${(f/1e3).toFixed(1)}s`),{languages:u.map(p=>p.language),indexPath:o,dbPath:a,durationMs:f,skipped:d}}function qr(e,n,t){if(!e.defaultOutputPath)return;let i=It(n,e.defaultOutputPath);t!==i&&_i(i)&&xi(i,t)}function zr(e,n,t){let i=Ur(e)||".scip",s=Hr(e,i);return It(Jr(e),`${s}.${t+1}.${n}${i}`)}import{watch as Gr}from"fs";import{existsSync as Ni,renameSync as Ci}from"fs";import{join as Yr,relative as Kr}from"path";import{fork as Vr}from"child_process";import Qr from"ignore";var Nt=class{projectRoot;watchConfig;indexPaths;languages;pnpmWorkspaces;onStatus;onReindexComplete;onError;status={state:"idle"};debounceTimer=null;cooldownTimer=null;dirty=!1;changedFiles=0;reindexInFlight=!1;lastReindexEnd=0;fsWatchers=[];gitignoreFilter;extraIgnore;stopped=!1;constructor(n){this.projectRoot=n.projectRoot,this.watchConfig=Qn(n.config),this.indexPaths=ke(n.projectRoot,n.config),this.languages=n.languages,this.pnpmWorkspaces=n.config.indexer?.typescript?.pnpmWorkspaces??!1,this.onStatus=n.onStatus??(()=>{}),this.onReindexComplete=n.onReindexComplete??(()=>{}),this.onError=n.onError??(t=>console.error(t.message)),this.gitignoreFilter=gt(n.projectRoot),this.extraIgnore=Qr(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let n=Gr(this.projectRoot,{recursive:!0},(t,i)=>{i&&!this.stopped&&this.handleFileChange(i)});this.fsWatchers.push(n)}catch{this.onError(new Error("Failed to start file watcher. On Linux, you may need to increase inotify limits: sysctl -w fs.inotify.max_user_watches=524288"))}}stop(){this.stopped=!0;for(let n of this.fsWatchers)n.close();this.fsWatchers=[],this.debounceTimer&&clearTimeout(this.debounceTimer),this.cooldownTimer&&clearTimeout(this.cooldownTimer),this.setStatus({state:"idle"})}handleFileChange(n){let t=Kr(this.projectRoot,Yr(this.projectRoot,n));if(this.gitignoreFilter.isIgnored(t)||this.extraIgnore.ignores(t)||n.endsWith("index.db")||n.endsWith("index.scip")||n.endsWith("index.db.tmp")||n.endsWith(".scipquery.json"))return;if(this.changedFiles++,this.reindexInFlight){this.dirty=!0,this.setStatus({state:"indexing",startedAt:this.status.startedAt});return}if(this.status.state==="cooldown"){this.dirty=!0,this.setStatus({state:"cooldown",until:this.status.until,dirty:!0});return}this.debounceTimer&&clearTimeout(this.debounceTimer);let i=Date.now()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:i}),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped)return;let n=Date.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&n<this.watchConfig.cooldownMs){let i=this.watchConfig.cooldownMs-n;this.dirty=!0;let s=Date.now()+i;this.setStatus({state:"cooldown",until:s,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},i);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let t=Date.now();this.setStatus({state:"indexing",startedAt:t}),this.runReindex().then(i=>{if(this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onReindexComplete(i),this.dirty&&!this.stopped){let s=Date.now()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:s,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"})}).catch(i=>{this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onError(i instanceof Error?i:new Error(String(i))),this.setStatus({state:"idle"})})}runReindex(){return new Promise((n,t)=>{let i=Date.now(),s=this.indexPaths.dbPath+".tmp",o=Xr(this.indexPaths.indexPath),a=Vr(new URL("./reindex-worker.js",import.meta.url).pathname,[],{env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:this.projectRoot,SCIP_REINDEX_OUTPUT_SCIP:o,SCIP_REINDEX_OUTPUT_DB:s,SCIP_REINDEX_LANGUAGES:this.languages?.join(",")??"",SCIP_REINDEX_PNPM_WORKSPACES:this.pnpmWorkspaces?"1":""},stdio:"pipe"});a.on("exit",r=>{if(r===0)try{Ni(s)&&Ci(s,this.indexPaths.dbPath),Ni(o)&&Ci(o,this.indexPaths.indexPath),n(Date.now()-i)}catch(l){t(new Error(`Atomic swap failed: ${l}`))}else t(new Error(`Reindex worker exited with code ${r}`))}),a.on("error",t)})}setStatus(n){this.status=n,this.onStatus(n)}};function Xr(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}function Ct(e){let n=e.get("SELECT COUNT(*) as c FROM documents").c,t=e.get("SELECT COUNT(*) as c FROM global_symbols").c,i=e.get("SELECT COUNT(*) as c FROM mentions WHERE role = 1").c,s=e.get("SELECT COUNT(*) as c FROM mentions WHERE role != 1").c;return{documents:n,symbols:t,definitions:i,references:s,indexSizeBytes:e.sizeBytes(),lastBuilt:e.lastModified()}}function Zr(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function vi(e,n){let t=Zr(n);return e.all(`SELECT relative_path FROM documents
137
+ `+p)}if(d.length>0&&s(`Indexed ${u.length} of ${l.length} languages; skipped ${d.map(p=>p.language).join(", ")}.`),l.length>1&&(u.length>1?(s(`Merging ${u.length} language indexes...`),vs(u.map(p=>p.scipPath),o)):u[0].scipPath!==o&&Ws(u[0].scipPath,o)),s("Converting to SQLite..."),!Bs(o))throw new Error(`SCIP index not found at ${o} after indexing`);try{js("scip",["expt-convert","--output",a,o],{env:c,stdio:"pipe",maxBuffer:50*1024*1024})}catch(p){let f=p instanceof Error?p.message:String(p);throw new Error(`Failed to convert SCIP index to SQLite: ${f}`,{cause:p})}finally{for(let{scipPath:p}of m)p!==o&&Ja(p,{force:!0})}Be({projectRoot:n,dbPath:a,onStatus:s});let g=Date.now()-r;return s(`Done in ${(g/1e3).toFixed(1)}s`),{languages:u.map(p=>p.language),indexPath:o,dbPath:a,durationMs:g,skipped:d}}function Va(e,n,t){if(!e.defaultOutputPath)return;let s=At(n,e.defaultOutputPath);t!==s&&Bs(s)&&Ws(s,t)}function Ga(e,n,t){let s=za(e)||".scip",i=Ua(e,s);return At(qa(e),`${i}.${t+1}.${n}${s}`)}import{watch as Ya}from"fs";import{existsSync as Js,renameSync as Us}from"fs";import{join as Ka,relative as Qa}from"path";import{fork as Xa}from"child_process";import Za from"ignore";var jt=class{projectRoot;watchConfig;indexPaths;languages;pnpmWorkspaces;onStatus;onReindexComplete;onError;status={state:"idle"};debounceTimer=null;cooldownTimer=null;dirty=!1;changedFiles=0;reindexInFlight=!1;lastReindexEnd=0;fsWatchers=[];gitignoreFilter;extraIgnore;stopped=!1;constructor(n){this.projectRoot=n.projectRoot,this.watchConfig=ms(n.config),this.indexPaths=Ae(n.projectRoot,n.config),this.languages=n.languages,this.pnpmWorkspaces=n.config.indexer?.typescript?.pnpmWorkspaces??!1,this.onStatus=n.onStatus??(()=>{}),this.onReindexComplete=n.onReindexComplete??(()=>{}),this.onError=n.onError??(t=>console.error(t.message)),this.gitignoreFilter=Ue(n.projectRoot),this.extraIgnore=Za(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let n=Ya(this.projectRoot,{recursive:!0},(t,s)=>{s&&!this.stopped&&this.handleFileChange(s)});this.fsWatchers.push(n)}catch{this.onError(new Error("Failed to start file watcher. On Linux, you may need to increase inotify limits: sysctl -w fs.inotify.max_user_watches=524288"))}}stop(){this.stopped=!0;for(let n of this.fsWatchers)n.close();this.fsWatchers=[],this.debounceTimer&&clearTimeout(this.debounceTimer),this.cooldownTimer&&clearTimeout(this.cooldownTimer),this.setStatus({state:"idle"})}handleFileChange(n){let t=Qa(this.projectRoot,Ka(this.projectRoot,n));if(this.gitignoreFilter.isIgnored(t)||this.extraIgnore.ignores(t)||n.endsWith("index.db")||n.endsWith("index.scip")||n.endsWith("index.db.tmp")||n.endsWith(".scipquery.json"))return;if(this.changedFiles++,this.reindexInFlight){this.dirty=!0,this.setStatus({state:"indexing",startedAt:this.status.startedAt});return}if(this.status.state==="cooldown"){this.dirty=!0,this.setStatus({state:"cooldown",until:this.status.until,dirty:!0});return}this.debounceTimer&&clearTimeout(this.debounceTimer);let s=Date.now()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:s}),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped)return;let n=Date.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&n<this.watchConfig.cooldownMs){let s=this.watchConfig.cooldownMs-n;this.dirty=!0;let i=Date.now()+s;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},s);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let t=Date.now();this.setStatus({state:"indexing",startedAt:t}),this.runReindex().then(s=>{if(this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onReindexComplete(s),this.dirty&&!this.stopped){let i=Date.now()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"})}).catch(s=>{this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onError(s instanceof Error?s:new Error(String(s))),this.setStatus({state:"idle"})})}runReindex(){return new Promise((n,t)=>{let s=Date.now(),i=this.indexPaths.dbPath+".tmp",o=el(this.indexPaths.indexPath),a=Xa(new URL("./reindex-worker.js",import.meta.url).pathname,[],{env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:this.projectRoot,SCIP_REINDEX_OUTPUT_SCIP:o,SCIP_REINDEX_OUTPUT_DB:i,SCIP_REINDEX_LANGUAGES:this.languages?.join(",")??"",SCIP_REINDEX_PNPM_WORKSPACES:this.pnpmWorkspaces?"1":""},stdio:"pipe"});a.on("exit",r=>{if(r===0)try{Js(i)&&Us(i,this.indexPaths.dbPath),Js(o)&&Us(o,this.indexPaths.indexPath),n(Date.now()-s)}catch(l){t(new Error(`Atomic swap failed: ${l}`))}else t(new Error(`Reindex worker exited with code ${r}`))}),a.on("error",t)})}setStatus(n){this.status=n,this.onStatus(n)}};function el(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}function Bt(e){let n=e.get("SELECT COUNT(*) as c FROM documents").c,t=e.get("SELECT COUNT(*) as c FROM global_symbols").c,s=e.get("SELECT COUNT(*) as c FROM mentions WHERE role = 1").c,i=e.get("SELECT COUNT(*) as c FROM mentions WHERE role != 1").c;return{documents:n,symbols:t,definitions:s,references:i,indexSizeBytes:e.sizeBytes(),lastBuilt:e.lastModified()}}function tl(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function qs(e,n){let t=tl(n);return e.all(`SELECT relative_path FROM documents
87
138
  WHERE relative_path LIKE ?
88
- ORDER BY relative_path`,t).filter(s=>!e.isIgnored(s.relative_path)).map(s=>({relativePath:s.relative_path}))}import{extname as wi}from"path";import{createRequire as oa}from"module";import{existsSync as ea,readFileSync as ta}from"fs";import{join as na}from"path";function W(e){let n=new WeakMap,t=i=>{let s=n.get(i);return s||(s=new Map,n.set(i,s)),s};return{get(i,s,o){let a=t(i);if(a.has(s))return a.get(s);let r=o();return a.set(s,r),r},invalidate(i,s){n.get(i)?.delete(s)},invalidateAll(i){n.delete(i)},size(i){return n.get(i)?.size??0}}}function Pe(e){let n=new WeakMap;return{get(t,i){let s=n.get(t);if(s)return s.value;let o=i();return n.set(t,{value:o}),o},invalidate(t){n.delete(t)},has(t){return n.has(t)}}}function vt(e){let n=new WeakMap,t=i=>{let s=n.get(i);return s||(s=new Map,n.set(i,s)),s};return{get(i,s,o,a){let r=t(i),l=r.get(s);if(l&&l.source===o)return l.value;let c=a();return r.set(s,{source:o,value:c}),c},invalidate(i,s){n.get(i)?.delete(s)},invalidateAll(i){n.delete(i)}}}var ia=W("source-text");function P(e,n){let t=n.replace(/\\/g,"/");return ia.get(e,t,()=>{let i=na(e.config.projectRoot,t);return ea(i)?ta(i,"utf-8"):""})}var sa=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift)?/i;function ue(e,n,t){if(t<=0)return!1;let i=P(e,n);if(!i)return!1;let s=i.split(`
89
- `);for(let o=t-1;o>=0&&o>=t-5;o-=1){let a=(s[o]??"").trim();if(a!==""){if(sa.test(a))return!0;if(!a.startsWith("//")&&!a.startsWith("*")&&!a.startsWith("/*")&&!a.startsWith("@")&&!a.startsWith("#"))return!1}}return!1}var K=oa(import.meta.url),Et=null,Ei=!1;function Oi(){if(Ei)return null;if(Et)return Et;try{return Et=K("tree-sitter"),Et}catch{return Ei=!0,null}}var ra={".rs":"rust",".ts":"typescript",".mts":"typescript",".cts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"javascript",".mjs":"javascript",".cjs":"javascript",".py":"python",".pyi":"python",".java":"java",".kt":"kotlin",".kts":"kotlin",".scala":"scala",".sc":"scala",".rb":"ruby",".c":"c",".h":"c",".cc":"cpp",".cpp":"cpp",".cxx":"cpp",".hpp":"cpp",".hh":"cpp",".hxx":"cpp",".cs":"csharp",".php":"php",".vb":"vb"},Li=new Map,Sn=new Set;function $i(e){if(Sn.has(e))return null;let n=Li.get(e);if(n)return n;let t;try{switch(e){case"rust":t=K("tree-sitter-rust");break;case"typescript":t=K("tree-sitter-typescript").typescript;break;case"tsx":t=K("tree-sitter-typescript").tsx;break;case"javascript":t=K("tree-sitter-javascript");break;case"python":t=K("tree-sitter-python");break;case"java":t=K("tree-sitter-java");break;case"kotlin":t=K("tree-sitter-kotlin");break;case"scala":t=K("tree-sitter-scala");break;case"ruby":t=K("tree-sitter-ruby");break;case"c":t=K("tree-sitter-c");break;case"cpp":t=K("tree-sitter-cpp");break;case"csharp":t=K("tree-sitter-c-sharp");break;case"php":t=K("tree-sitter-php").php;break;case"vb":{let i=K("tree-sitter-vb-dotnet");t=i.language??i;break}}}catch{return Sn.add(e),null}return Li.set(e,t),t}var Ri=new Map;function ki(e){let n=Ri.get(e);if(n)return n;let t=$i(e);if(!t)return null;let i=Oi();if(!i)return null;let s=new i;try{s.setLanguage(t)}catch{return Sn.add(e),null}return Ri.set(e,s),s}function T(e){return ra[wi(e).toLowerCase()]??null}function nt(e){return wi(e).toLowerCase()===".vue"}var Pi=vt("ast-trees");function $(e,n){if(nt(n))return aa(e,n);let t=T(n);if(!t)return null;let i=P(e,n);return i?Pi.get(e,n,i,()=>{let s=ki(t);return s?s.parse(i):null}):null}function aa(e,n){let t=P(e,n);return t?Pi.get(e,n,t,()=>{let i=la(t);if(!i)return null;let s=ki(i.language);if(!s)return null;let o=`
90
- `.repeat(i.startLine)+i.body;return s.parse(o)}):null}function la(e){let n=[],t=/<script\b([^>]*)>([\s\S]*?)<\/script>/g;for(let l of e.matchAll(t))typeof l.index=="number"&&n.push({tagOpen:l[1]??"",body:l[2]??"",openIdx:l.index+(l[0].length-(l[2]?.length??0)-9)});if(n.length===0)return null;let i=n.find(l=>/\bsetup\b/.test(l.tagOpen))??n[0],o=i.tagOpen.match(/\blang\s*=\s*["']?([\w-]+)/)?.[1]?.toLowerCase(),a=o==="ts"||o==="typescript"?"typescript":o==="tsx"?"tsx":"javascript",r=ca(e,i.openIdx);return{body:i.body,startLine:r,language:a}}function ca(e,n){let t=0;for(let i=0;i<n&&i<e.length;i++)e.charCodeAt(i)===10&&t++;return t}var et=new Map;function ma(e,n){let t=`${e}::${n}`;if(et.has(t))return et.get(t)??null;let i=$i(e);if(!i)return et.set(t,null),null;let s=Oi();if(!s)return et.set(t,null),null;let o=null;try{o=new s.Query(i,n)}catch{o=null}return et.set(t,o),o}var ua={rust:`
139
+ ORDER BY relative_path`,t).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path}))}import{extname as Ks}from"path";import{createRequire as al}from"module";import{existsSync as nl,readFileSync as sl}from"fs";import{join as il}from"path";var ol=W("source-text");function M(e,n){let t=n.replace(/\\/g,"/");return ol.get(e,t,()=>{let s=il(e.config.projectRoot,t);return nl(s)?sl(s,"utf-8"):""})}var rl=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift)?/i;function pe(e,n,t){if(t<=0)return!1;let s=M(e,n);if(!s)return!1;let i=s.split(`
140
+ `);for(let o=t-1;o>=0&&o>=t-5;o-=1){let a=(i[o]??"").trim();if(a!==""){if(rl.test(a))return!0;if(!a.startsWith("//")&&!a.startsWith("*")&&!a.startsWith("/*")&&!a.startsWith("@")&&!a.startsWith("#"))return!1}}return!1}var X=al(import.meta.url),Wt=null,zs=!1;function Qs(){if(zs)return null;if(Wt)return Wt;try{return Wt=X("tree-sitter"),Wt}catch{return zs=!0,null}}var ll={".rs":"rust",".ts":"typescript",".mts":"typescript",".cts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"javascript",".mjs":"javascript",".cjs":"javascript",".py":"python",".pyi":"python",".java":"java",".kt":"kotlin",".kts":"kotlin",".scala":"scala",".sc":"scala",".rb":"ruby",".c":"c",".h":"c",".cc":"cpp",".cpp":"cpp",".cxx":"cpp",".hpp":"cpp",".hh":"cpp",".hxx":"cpp",".cs":"csharp",".php":"php",".vb":"vb"},Vs=new Map,$n=new Set;function Xs(e){if($n.has(e))return null;let n=Vs.get(e);if(n)return n;let t;try{switch(e){case"rust":t=X("tree-sitter-rust");break;case"typescript":t=X("tree-sitter-typescript").typescript;break;case"tsx":t=X("tree-sitter-typescript").tsx;break;case"javascript":t=X("tree-sitter-javascript");break;case"python":t=X("tree-sitter-python");break;case"java":t=X("tree-sitter-java");break;case"kotlin":t=X("tree-sitter-kotlin");break;case"scala":t=X("tree-sitter-scala");break;case"ruby":t=X("tree-sitter-ruby");break;case"c":t=X("tree-sitter-c");break;case"cpp":t=X("tree-sitter-cpp");break;case"csharp":t=X("tree-sitter-c-sharp");break;case"php":t=X("tree-sitter-php").php;break;case"vb":{let s=X("tree-sitter-vb-dotnet");t=s.language??s;break}}}catch{return $n.add(e),null}return Vs.set(e,t),t}var Gs=new Map;function Zs(e){let n=Gs.get(e);if(n)return n;let t=Xs(e);if(!t)return null;let s=Qs();if(!s)return null;let i=new s;try{i.setLanguage(t)}catch{return $n.add(e),null}return Gs.set(e,i),i}function P(e){return ll[Ks(e).toLowerCase()]??null}function mt(e){return Ks(e).toLowerCase()===".vue"}var ei=Ot("ast-trees");function O(e,n){if(mt(n))return cl(e,n);let t=P(n);if(!t)return null;let s=M(e,n);return s?ei.get(e,n,s,()=>{let i=Zs(t);if(!i)return null;try{return i.parse(s)}catch{return null}}):null}function cl(e,n){let t=M(e,n);return t?ei.get(e,n,t,()=>{let s=ul(t);if(!s)return null;let i=Zs(s.language);if(!i)return null;let o=`
141
+ `.repeat(s.startLine)+s.body;try{return i.parse(o)}catch{return null}}):null}function ul(e){let n=[],t=/<script\b([^>]*)>([\s\S]*?)<\/script>/g;for(let l of e.matchAll(t))typeof l.index=="number"&&n.push({tagOpen:l[1]??"",body:l[2]??"",openIdx:l.index+(l[0].length-(l[2]?.length??0)-9)});if(n.length===0)return null;let s=n.find(l=>/\bsetup\b/.test(l.tagOpen))??n[0],o=s.tagOpen.match(/\blang\s*=\s*["']?([\w-]+)/)?.[1]?.toLowerCase(),a=o==="ts"||o==="typescript"?"typescript":o==="tsx"?"tsx":"javascript",r=ml(e,s.openIdx);return{body:s.body,startLine:r,language:a}}function ml(e,n){let t=0;for(let s=0;s<n&&s<e.length;s++)e.charCodeAt(s)===10&&t++;return t}var ct=new Map;function dl(e,n){let t=`${e}::${n}`;if(ct.has(t))return ct.get(t)??null;let s=Xs(e);if(!s)return ct.set(t,null),null;let i=Qs();if(!i)return ct.set(t,null),null;let o=null;try{o=new i.Query(s,n)}catch{o=null}return ct.set(t,o),o}var pl={rust:`
91
142
  (function_item name: (identifier) @name) @def
92
143
  (function_signature_item name: (identifier) @name) @def
93
144
  `,typescript:`
@@ -113,7 +164,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
113
164
  (variable_declarator name: (identifier) @name value: (function_expression)) @def
114
165
  `,python:`
115
166
  (function_definition name: (identifier) @name) @def
116
- `},da=new WeakMap;function Mi(e,n){return Ti(e,n,da,ua,t=>{let i=[];for(let s of t){let o=null,a=null;for(let r of s.captures)r.name==="name"?o=r.node.text:r.name==="def"&&(a={startLine:r.node.startPosition.row,endLine:r.node.endPosition.row});o&&a&&i.push({name:o,startLine:a.startLine,endLine:a.endLine})}return i})}var pa={rust:`
167
+ `},fl=new WeakMap;function ti(e,n){return si(e,n,fl,pl,t=>{let s=[];for(let i of t){let o=null,a=null;for(let r of i.captures)r.name==="name"?o=r.node.text:r.name==="def"&&(a={startLine:r.node.startPosition.row,endLine:r.node.endPosition.row});o&&a&&s.push({name:o,startLine:a.startLine,endLine:a.endLine})}return s})}var gl={rust:`
117
168
  (call_expression function: (_) @target) @call
118
169
  (macro_invocation macro: (_) @target) @call
119
170
  `,typescript:`
@@ -127,7 +178,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
127
178
  (new_expression constructor: (_) @target) @call
128
179
  `,python:`
129
180
  (call function: (_) @target) @call
130
- `},fa=new WeakMap;function Lt(e,n){return Ti(e,n,fa,pa,t=>{let i=[];for(let s of t){let o=null,a=null;for(let l of s.captures)l.name==="target"?o=l.node:l.name==="call"&&(a=l.node);if(!o||!a)continue;let r=tt(o);r&&i.push({calleeLeaf:r,line:a.startPosition.row})}return i})}function Fi(e,n){return _n(e,n,ga,()=>new Map,(t,i,s)=>{let o=(l,c)=>{if(l===c)return;let m=s.get(l);m||(m=new Set,s.set(l,m)),m.add(c)},a=i==="python"?new Set(["identifier"]):new Set(["type_identifier"]),r=(l,c)=>{let m=u=>{a.has(u.type)&&u.text!==c&&o(u.text,c);for(let d of u.children)m(d)};for(let u of l.children)m(u)};if(i==="rust")for(let l of t.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let c=l.namedChildren.find(u=>u.type==="type_identifier")?.text;if(!c)continue;let m=l.namedChildren.find(u=>u.type==="field_declaration_list"||u.type==="enum_variant_list"||u.type==="ordered_field_declaration_list");m&&r(m,c),l.type==="type_item"&&r(l,c)}else if(i==="python")for(let l of t.rootNode.descendantsOfType("class_definition")){let c=l.namedChildren.find(u=>u.type==="identifier")?.text;if(!c)continue;let m=l.namedChildren.find(u=>u.type==="block");if(m)for(let u of m.descendantsOfType("type"))for(let d of u.descendantsOfType("identifier"))d.text!==c&&o(d.text,c)}else for(let l of t.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let c=l.namedChildren.find(m=>m.type==="type_identifier")?.text;c&&r(l,c)}})??new Map}function _n(e,n,t,i,s){let o=T(n);if(!o)return null;let a=$(e,n);if(!a)return null;let r=t.get(a);if(r)return r;let l=i();return s(a,o,l),t.set(a,l),l}function Ti(e,n,t,i,s){let o=T(n);if(!o)return null;let a=i[o];if(!a)return null;let r=$(e,n);if(!r)return null;let l=t.get(r);if(l)return l;let c=ma(o,a);if(!c)return null;let m=s(c.matches(r.rootNode));return t.set(r,m),m}var ga=new WeakMap,Di=new WeakMap;function xn(e,n,t,i){let s=T(n);if(!s)return null;let o=$(e,n);if(!o)return null;let a=Di.get(o);return a||(a=ha(o,s),Di.set(o,a)),a.get(`${t}:${i}`)??null}function ha(e,n){let t=n==="rust"?new Set(["function_item","function_signature_item"]):n==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),i=new Map,s=o=>{if(t.has(o.type)){let a=o.namedChildren.find(l=>l.type==="parameters"||l.type==="formal_parameters"),r=0;if(a)for(let l of a.namedChildren)l.type==="comment"||l.type==="line_comment"||l.type==="block_comment"||(r+=1);i.set(`${o.startPosition.row}:${o.endPosition.row}`,{paramCount:r})}for(let a of o.children)s(a)};return s(e.rootNode),i}function tt(e){switch(e.type){case"identifier":case"type_identifier":case"property_identifier":case"shorthand_property_identifier":return e.text;case"field_expression":case"member_expression":case"attribute":{let n=e.namedChild(e.namedChildCount-1);return n?tt(n):null}case"scoped_identifier":{let n=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return n?tt(n):null}case"super":case"self":case"this":return null;default:return null}}var ya={"/":"namespace","#":"type",".":"term","[":"type-param",":":"meta","!":"macro"};function te(e){if(e.startsWith("local "))return{kind:"local",id:e.slice(6),raw:e};let n=e.split(" ");if(n.length<4)return{scheme:n[0]??"",manager:n[1]??"",packageName:n[2]??"",version:"",descriptors:[],raw:e};let t=n[0],i=n[1],s=e.slice(t.length+1+i.length+1),o;if(s.startsWith("`")){let c=s.indexOf("`",1);c===-1?(o=s.slice(1),s=""):(o=s.slice(1,c),s=s.slice(c+2))}else{let c=s.indexOf(" ");c===-1?(o=s,s=""):(o=s.slice(0,c),s=s.slice(c+1))}let a,r=s.indexOf(" ");r===-1?(a=s,s=""):(a=s.slice(0,r),s=s.slice(r+1));let l=ba(s);return{scheme:t,manager:i,packageName:o,version:a,descriptors:l,raw:e}}function ba(e){let n=[],t=0;for(;t<e.length;){if(e[t]==="["){let o=e.indexOf("]",t+1);if(o===-1){n.push({name:e.slice(t+1),suffix:"type-param"});break}n.push({name:e.slice(t+1,o),suffix:"type-param"}),t=o+1;continue}if(e[t]==="("&&(n.length===0||t===0||Ai(e[t-1]))){let o=e.indexOf(")",t+1);if(o!==-1&&e[o+1]!=="."){n.push({name:e.slice(t+1,o),suffix:"parameter"}),t=o+1;continue}}let i;if(e[t]==="`"){let o=e.indexOf("`",t+1);if(o===-1){i=e.slice(t+1),n.push({name:i,suffix:"term"});break}i=e.slice(t+1,o),t=o+1}else{let o=t;for(;t<e.length&&!Ai(e[t]);)t++;i=e.slice(o,t)}if(t>=e.length){i&&n.push({name:i,suffix:"term"});break}let s=e[t];if(s==="("){let o=e.indexOf(")",t+1);o!==-1&&e[o+1]==="."?(n.push({name:i,suffix:"method"}),t=o+2):o!==-1?(n.push({name:i,suffix:"method"}),t=o+1):(n.push({name:i,suffix:"term"}),t++)}else{let o=ya[s];o&&n.push({name:i,suffix:o}),t+=1}}return n}function Ai(e){return e==="/"||e==="#"||e==="."||e==="("||e==="["||e===":"||e==="!"}function _(e){let n=te(e);if("kind"in n&&n.kind==="local")return`local:${n.id}`;let t=n;if(t.descriptors.length===0)return t.raw;let i=[];for(let s of t.descriptors){let o=s.name;s.suffix==="namespace"&&(o=o.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/,"").replace(/\.(py|pyi)$/,"").replace(/\.(rs)$/,"").replace(/\.(java|scala|kt|kts)$/,"").replace(/\.(rb)$/,"").replace(/\.(go)$/,"").replace(/\.(cs|vb)$/,"").replace(/\.(dart)$/,"").replace(/\.(php)$/,"").replace(/\.(c|cc|cpp|cxx|h|hpp)$/,"")),o&&(s.suffix==="method"?i.push(`${o}()`):i.push(o))}return i.join(":")}function M(e){let n=te(e);if("kind"in n&&n.kind==="local")return n.id;let t=n;return t.descriptors.length===0?"":t.descriptors[t.descriptors.length-1].name}function ne(e){let n=te(e);if("kind"in n&&n.kind==="local")return null;let t=n;return t.descriptors[t.descriptors.length-1]?.suffix??null}function Rt(e){return e.endsWith("().")||ne(e)==="method"}function j(e){let n=ne(e);return n==="method"||n==="term"}function We(e){return ne(e)==="namespace"}function ji(e,n){let t=te(e),i=te(n);if("kind"in t||"kind"in i)return!1;let s=t.descriptors,o=i.descriptors;if(o.length!==s.length+1)return!1;for(let a=0;a<s.length;a++){let r=s[a],l=o[a];if(r.name!==l.name||r.suffix!==l.suffix)return!1}return!0}function Bi(e,n){let t=te(e),i=te(n);if("kind"in t||"kind"in i)return!1;let s=t.descriptors,o=i.descriptors;if(o.length<=s.length)return!1;for(let a=0;a<s.length;a++){let r=s[a],l=o[a];if(r.name!==l.name||r.suffix!==l.suffix)return!1}return!0}function it(e){return!e||!e.trim()?null:e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim()||null}function st(e){if(!e)return null;let n=e.indexOf("|");return n===-1?e.replace(/\n/g," "):e.slice(n+1).replace(/\n/g," ")}var Sa=W("file-definitions");function A(e,n){return Sa.get(e,n,()=>{let t=e.all(`SELECT
181
+ `},hl=new WeakMap;function Ht(e,n){return si(e,n,hl,gl,t=>{let s=[];for(let i of t){let o=null,a=null;for(let l of i.captures)l.name==="target"?o=l.node:l.name==="call"&&(a=l.node);if(!o||!a)continue;let r=ut(o);r&&s.push({calleeLeaf:r,line:a.startPosition.row})}return s})}function ni(e,n){return Jt(e,n,yl,()=>new Map,(t,s,i)=>{let o=(l,c)=>{if(l===c)return;let m=i.get(l);m||(m=new Set,i.set(l,m)),m.add(c)},a=s==="python"?new Set(["identifier"]):new Set(["type_identifier"]),r=(l,c)=>{let m=u=>{a.has(u.type)&&u.text!==c&&o(u.text,c);for(let d of u.children)m(d)};for(let u of l.children)m(u)};if(s==="rust")for(let l of t.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let c=l.namedChildren.find(u=>u.type==="type_identifier")?.text;if(!c)continue;let m=l.namedChildren.find(u=>u.type==="field_declaration_list"||u.type==="enum_variant_list"||u.type==="ordered_field_declaration_list");m&&r(m,c),l.type==="type_item"&&r(l,c)}else if(s==="python")for(let l of t.rootNode.descendantsOfType("class_definition")){let c=l.namedChildren.find(u=>u.type==="identifier")?.text;if(!c)continue;let m=l.namedChildren.find(u=>u.type==="block");if(m)for(let u of m.descendantsOfType("type"))for(let d of u.descendantsOfType("identifier"))d.text!==c&&o(d.text,c)}else for(let l of t.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let c=l.namedChildren.find(m=>m.type==="type_identifier")?.text;c&&r(l,c)}})??new Map}function Jt(e,n,t,s,i){let o=P(n);if(!o)return null;let a=O(e,n);if(!a)return null;let r=t.get(a);if(r)return r;let l=s();return i(a,o,l),t.set(a,l),l}function si(e,n,t,s,i){let o=P(n);if(!o)return null;let a=s[o];if(!a)return null;let r=O(e,n);if(!r)return null;let l=t.get(r);if(l)return l;let c=dl(o,a);if(!c)return null;let m=i(c.matches(r.rootNode));return t.set(r,m),m}var yl=new WeakMap,Ys=new WeakMap;function Pn(e,n,t,s){let i=P(n);if(!i)return null;let o=O(e,n);if(!o)return null;let a=Ys.get(o);return a||(a=bl(o,i),Ys.set(o,a)),a.get(`${t}:${s}`)??null}function bl(e,n){let t=n==="rust"?new Set(["function_item","function_signature_item"]):n==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),s=new Map,i=o=>{if(t.has(o.type)){let a=o.namedChildren.find(l=>l.type==="parameters"||l.type==="formal_parameters"),r=0;if(a)for(let l of a.namedChildren)l.type==="comment"||l.type==="line_comment"||l.type==="block_comment"||(r+=1);s.set(`${o.startPosition.row}:${o.endPosition.row}`,{paramCount:r})}for(let a of o.children)i(a)};return i(e.rootNode),s}function ut(e){switch(e.type){case"identifier":case"type_identifier":case"property_identifier":case"shorthand_property_identifier":return e.text;case"field_expression":case"member_expression":case"attribute":{let n=e.namedChild(e.namedChildCount-1);return n?ut(n):null}case"scoped_identifier":{let n=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return n?ut(n):null}case"super":case"self":case"this":return null;default:return null}}var Sl={"/":"namespace","#":"type",".":"term","[":"type-param",":":"meta","!":"macro"};function V(e){if(e.startsWith("local "))return{kind:"local",id:e.slice(6),raw:e};let n=e.split(" ");if(n.length<4)return{scheme:n[0]??"",manager:n[1]??"",packageName:n[2]??"",version:"",descriptors:[],raw:e};let t=n[0],s=n[1],i=e.slice(t.length+1+s.length+1),o;if(i.startsWith("`")){let c=i.indexOf("`",1);c===-1?(o=i.slice(1),i=""):(o=i.slice(1,c),i=i.slice(c+2))}else{let c=i.indexOf(" ");c===-1?(o=i,i=""):(o=i.slice(0,c),i=i.slice(c+1))}let a,r=i.indexOf(" ");r===-1?(a=i,i=""):(a=i.slice(0,r),i=i.slice(r+1));let l=_l(i);return{scheme:t,manager:s,packageName:o,version:a,descriptors:l,raw:e}}function _l(e){let n=[],t=0;for(;t<e.length;){if(e[t]==="["){let o=e.indexOf("]",t+1);if(o===-1){n.push({name:e.slice(t+1),suffix:"type-param"});break}n.push({name:e.slice(t+1,o),suffix:"type-param"}),t=o+1;continue}if(e[t]==="("&&(n.length===0||t===0||ii(e[t-1]))){let o=e.indexOf(")",t+1);if(o!==-1&&e[o+1]!=="."){n.push({name:e.slice(t+1,o),suffix:"parameter"}),t=o+1;continue}}let s;if(e[t]==="`"){let o=e.indexOf("`",t+1);if(o===-1){s=e.slice(t+1),n.push({name:s,suffix:"term"});break}s=e.slice(t+1,o),t=o+1}else{let o=t;for(;t<e.length&&!ii(e[t]);)t++;s=e.slice(o,t)}if(t>=e.length){s&&n.push({name:s,suffix:"term"});break}let i=e[t];if(i==="("){let o=e.indexOf(")",t+1);o!==-1&&e[o+1]==="."?(n.push({name:s,suffix:"method"}),t=o+2):o!==-1?(n.push({name:s,suffix:"method"}),t=o+1):(n.push({name:s,suffix:"term"}),t++)}else{let o=Sl[i];o&&n.push({name:s,suffix:o}),t+=1}}return n}function ii(e){return e==="/"||e==="#"||e==="."||e==="("||e==="["||e===":"||e==="!"}function I(e){let n=V(e);if("kind"in n&&n.kind==="local")return`local:${n.id}`;let t=n;if(t.descriptors.length===0)return t.raw;let s=[];for(let i of t.descriptors){let o=i.name;i.suffix==="namespace"&&(o=o.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/,"").replace(/\.(py|pyi)$/,"").replace(/\.(rs)$/,"").replace(/\.(java|scala|kt|kts)$/,"").replace(/\.(rb)$/,"").replace(/\.(go)$/,"").replace(/\.(cs|vb)$/,"").replace(/\.(dart)$/,"").replace(/\.(php)$/,"").replace(/\.(c|cc|cpp|cxx|h|hpp)$/,"")),o&&(i.suffix==="method"?s.push(`${o}()`):s.push(o))}return s.join(":")}function F(e){let n=V(e);if("kind"in n&&n.kind==="local")return n.id;let t=n;return t.descriptors.length===0?"":t.descriptors[t.descriptors.length-1].name}function ie(e){let n=V(e);if("kind"in n&&n.kind==="local")return null;let t=n;return t.descriptors[t.descriptors.length-1]?.suffix??null}function Ve(e){return e.endsWith("().")||ie(e)==="method"}function j(e){let n=ie(e);return n==="method"||n==="term"}function Ge(e){return ie(e)==="namespace"}var xl=/^rust-analyzer\b.*[\s/]impl#\[[^\]]+\]\[[^\]]+\]/;function Ye(e){return xl.test(e)}var Il=new Set(["test","tests","_tests"]);function G(e){let n=V(e);if("kind"in n)return!1;for(let t=0;t<n.descriptors.length-1;t+=1){let s=n.descriptors[t];if(s?.suffix==="namespace"&&s.name&&Il.has(s.name))return!0}return!1}function oi(e,n){let t=V(e),s=V(n);if("kind"in t||"kind"in s)return!1;let i=t.descriptors,o=s.descriptors;if(o.length!==i.length+1)return!1;for(let a=0;a<i.length;a++){let r=i[a],l=o[a];if(r.name!==l.name||r.suffix!==l.suffix)return!1}return!0}function ri(e,n){let t=V(e),s=V(n);if("kind"in t||"kind"in s)return!1;let i=t.descriptors,o=s.descriptors;if(o.length<=i.length)return!1;for(let a=0;a<i.length;a++){let r=i[a],l=o[a];if(r.name!==l.name||r.suffix!==l.suffix)return!1}return!0}function dt(e){return!e||!e.trim()?null:e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim()||null}function pt(e){if(!e)return null;let n=e.indexOf("|");return n===-1?e.replace(/\n/g," "):e.slice(n+1).replace(/\n/g," ")}var Nl=W("file-definitions");function A(e,n){return Nl.get(e,n,()=>{let t=e.all(`SELECT
131
182
  gs.id,
132
183
  gs.symbol,
133
184
  der.document_id,
@@ -143,7 +194,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
143
194
  JOIN documents d ON der.document_id = d.id
144
195
  WHERE d.relative_path = ?
145
196
  ${e.symbolNoiseFor("gs")}
146
- ORDER BY der.start_line, der.end_line`,n),i=t.length>0?[]:e.all(`SELECT
197
+ ORDER BY der.start_line, der.end_line`,n),s=t.length>0?[]:e.all(`SELECT
147
198
  gs.id,
148
199
  gs.symbol,
149
200
  c.document_id,
@@ -162,12 +213,12 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
162
213
  AND m.role = 1
163
214
  ${e.symbolNoiseFor("gs")}
164
215
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
165
- ORDER BY start_line, end_line`,n);return _a(e,n,(t.length>0?t:i).map(s=>({symbolId:s.id,symbol:s.symbol,documentId:s.document_id,startLine:s.start_line,endLine:s.end_line,relativePath:s.relative_path,leaf:M(s.symbol),parentTypeName:Ea(s.symbol),isFunctionLike:j(s.symbol),isTypeLike:ne(s.symbol)==="type",kind:s.kind??null,documentation:s.documentation??null,enclosingSymbol:s.enclosing_symbol??null})))})}function V(e,n={}){return z(e,n.scope)}function z(e,n){let t=n?`AND relative_path LIKE '%${n}%'`:"";return e.all(`SELECT relative_path
216
+ ORDER BY start_line, end_line`,n);return vl(e,n,(t.length>0?t:s).map(i=>({symbolId:i.id,symbol:i.symbol,documentId:i.document_id,startLine:i.start_line,endLine:i.end_line,relativePath:i.relative_path,leaf:F(i.symbol),parentTypeName:Dl(i.symbol),isFunctionLike:j(i.symbol),isTypeLike:ie(i.symbol)==="type",kind:i.kind??null,documentation:i.documentation??null,enclosingSymbol:i.enclosing_symbol??null})))})}function Z(e,n={}){return Y(e,n.scope)}function Y(e,n){let t=n?`AND relative_path LIKE '%${n}%'`:"";return e.all(`SELECT relative_path
166
217
  FROM documents
167
218
  WHERE 1 = 1
168
219
  ${e.pathExclusionsFor("documents")}
169
220
  ${t}
170
- ORDER BY relative_path`).flatMap(i=>A(e,i.relative_path)).filter(i=>!e.isIgnored(i.relativePath))}function He(e,n,t={}){if(n.length===0)return[];let i=n.flatMap(s=>A(e,s)).filter(s=>!e.isIgnored(s.relativePath));return t.onlyDocumented&&(i=i.filter(s=>s.documentation!==null&&s.documentation!=="")),t.sort&&(i=i.sort((s,o)=>s.relativePath.localeCompare(o.relativePath)||s.startLine-o.startLine||s.endLine-o.endLine)),i.map(s=>({startLine:s.startLine,endLine:s.endLine,symbol:s.symbol,shortName:_(s.symbol),signature:it(st(s.documentation)),relativePath:s.relativePath,enclosingSymbol:s.enclosingSymbol}))}function de(e,n){let t=null;for(let i of e)i.startLine>n||i.endLine<n||(!t||i.endLine-i.startLine<t.endLine-t.startLine)&&(t=i);return t}function Je(e,n){let t=A(e,n.relative_path).find(i=>i.symbolId===n.id);return t?{symbolId:t.symbolId,symbol:t.symbol,documentId:t.documentId,startLine:t.startLine,endLine:t.endLine,relativePath:t.relativePath}:{symbolId:n.id,symbol:n.symbol,documentId:n.document_id,startLine:n.start_line,endLine:n.end_line,relativePath:n.relative_path}}function _a(e,n,t){let i=Mi(e,n);if(i)return xa(t,i);let s=P(e,n);if(!s)return t;let o=s.split(/\r?\n/),a=t.some(m=>Dt(m.symbol))?Na(o):null,r=new Map;for(let m of t)r.set(m.symbolId,Ia(o,a,m));let l=new Map,c=t.filter(m=>Dt(m.symbol)).map(m=>({definition:m,startLine:r.get(m.symbolId)??m.startLine})).sort((m,u)=>m.startLine-u.startLine||m.definition.startLine-u.definition.startLine||m.definition.symbol.localeCompare(u.definition.symbol));for(let m=0;m<c.length;m+=1){let u=c[m],d=c[m+1],f=d?Math.max(u.startLine,d.startLine-1):o.length-1;l.set(u.definition.symbolId,{startLine:u.startLine,endLine:Ca(o,u.definition,u.startLine,f)})}return t.map(m=>{let u=l.get(m.symbolId);return u?{...m,startLine:u.startLine,endLine:u.endLine}:m})}function xa(e,n){let t=new Map;for(let i of n){let s=t.get(i.name);s?s.push(i):t.set(i.name,[i])}return e.map(i=>{if(!Dt(i.symbol)||!i.leaf)return i;let s=t.get(i.leaf);if(!s||s.length===0)return i;let o=s[0],a=Math.abs(o.startLine-i.startLine);for(let r=1;r<s.length;r+=1){let l=s[r],c=Math.abs(l.startLine-i.startLine);c<a&&(o=l,a=c)}return{...i,startLine:o.startLine,endLine:o.endLine}})}function Ia(e,n,t){if(!Dt(t.symbol))return t.startLine;let i=Math.max(0,Math.min(t.startLine,e.length-1));if(!n)return i;let s=n.get(t.leaf);if(!s||s.length===0)return i;let o=null;for(let a of s){let r=Math.abs(a-t.startLine);(!o||r<o.distance)&&(o={line:a,distance:r})}return o?.line??i}function Na(e){let n=/\b(?:function|def|fn)\s+([A-Za-z_$][\w$]*)/g,t=/\b([A-Za-z_$][\w$]*)\s*[:=]\s*(?:async\s*)?(?:function\b|\()/g,i=/^\s*(?:(?:export|public|private|protected|static|readonly|async|abstract|get|set)\s+)*([A-Za-z_$][\w$]*)\s*(?:<[^(]*>)?\s*\(/,s=/\b([A-Za-z_$][\w$]*)\s*\(/g,o=new Map,a=(r,l)=>{let c=o.get(r);if(!c){o.set(r,[l]);return}c[c.length-1]!==l&&c.push(l)};for(let r=0;r<e.length;r+=1){let l=e[r]??"";for(let m of l.matchAll(n))m[1]&&a(m[1],r);for(let m of l.matchAll(t))m[1]&&a(m[1],r);let c=l.match(i);c?.[1]&&a(c[1],r);for(let m of l.matchAll(s))m[1]&&a(m[1],r)}return o}function Ca(e,n,t,i){let s=Math.max(t,Math.min(e.length-1,i)),o=Math.max(t,Math.min(s,n.endLine)),a=0,r=0,l=!1;for(let c=t;c<=s;c+=1){let m=va(e[c]??"");for(let u of m)u==="{"?(a+=1,l=!0):u==="}"?a=Math.max(0,a-1):u==="("?r+=1:u===")"&&(r=Math.max(0,r-1));if(l&&a===0||!l&&r===0&&c>=o)return c}return o}function va(e){let n="",t=null,i=!1;for(let s=0;s<e.length;s+=1){let o=e[s],a=e[s+1];if(!t&&o==="/"&&a==="/"){n+=" ".repeat(e.length-s);break}if(t){if(i){i=!1,n+=" ";continue}if(o==="\\"){i=!0,n+=" ";continue}o===t&&(t=null),n+=" ";continue}if(o==='"'||o==="'"||o==="`"){t=o,n+=" ";continue}n+=o}return n}function Dt(e){return e.includes("().")}function Ea(e){let n=te(e);if("kind"in n)return null;for(let t=n.descriptors.length-2;t>=0;t--){let i=n.descriptors[t];if(i?.suffix==="type")return i.name}return null}import{existsSync as $a}from"fs";import{basename as Hi,isAbsolute as ka,join as Pa}from"path";function O(e,n){let t=Ue(e,n.trim());if(t)return t;let i=n.match(/^(.+):(\d+)-(\d+)$/);if(i){let[,c,m,u]=i,d=Math.max(0,parseInt(m,10)-1),f=Math.max(d,parseInt(u,10)-1),p=e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
221
+ ORDER BY relative_path`).flatMap(s=>A(e,s.relative_path)).filter(s=>!e.isIgnored(s.relativePath))}function Ke(e,n,t={}){if(n.length===0)return[];let s=n.flatMap(i=>A(e,i)).filter(i=>!e.isIgnored(i.relativePath));return t.onlyDocumented&&(s=s.filter(i=>i.documentation!==null&&i.documentation!=="")),t.sort&&(s=s.sort((i,o)=>i.relativePath.localeCompare(o.relativePath)||i.startLine-o.startLine||i.endLine-o.endLine)),s.map(i=>({startLine:i.startLine,endLine:i.endLine,symbol:i.symbol,shortName:I(i.symbol),signature:dt(pt(i.documentation)),relativePath:i.relativePath,enclosingSymbol:i.enclosingSymbol}))}function fe(e,n){let t=null;for(let s of e)s.startLine>n||s.endLine<n||(!t||s.endLine-s.startLine<t.endLine-t.startLine)&&(t=s);return t}function Qe(e,n){let t=A(e,n.relative_path).find(s=>s.symbolId===n.id);return t?{symbolId:t.symbolId,symbol:t.symbol,documentId:t.documentId,startLine:t.startLine,endLine:t.endLine,relativePath:t.relativePath}:{symbolId:n.id,symbol:n.symbol,documentId:n.document_id,startLine:n.start_line,endLine:n.end_line,relativePath:n.relative_path}}function vl(e,n,t){let s=ti(e,n);if(s)return Cl(t,s);let i=M(e,n);if(!i)return t;let o=i.split(/\r?\n/),a=t.some(m=>Ut(m.symbol))?Rl(o):null,r=new Map;for(let m of t)r.set(m.symbolId,El(o,a,m));let l=new Map,c=t.filter(m=>Ut(m.symbol)).map(m=>({definition:m,startLine:r.get(m.symbolId)??m.startLine})).sort((m,u)=>m.startLine-u.startLine||m.definition.startLine-u.definition.startLine||m.definition.symbol.localeCompare(u.definition.symbol));for(let m=0;m<c.length;m+=1){let u=c[m],d=c[m+1],g=d?Math.max(u.startLine,d.startLine-1):o.length-1;l.set(u.definition.symbolId,{startLine:u.startLine,endLine:Ll(o,u.definition,u.startLine,g)})}return t.map(m=>{let u=l.get(m.symbolId);return u?{...m,startLine:u.startLine,endLine:u.endLine}:m})}function Cl(e,n){let t=new Map;for(let s of n){let i=t.get(s.name);i?i.push(s):t.set(s.name,[s])}return e.map(s=>{if(!Ut(s.symbol)||!s.leaf)return s;let i=t.get(s.leaf);if(!i||i.length===0)return s;let o=i[0],a=Math.abs(o.startLine-s.startLine);for(let r=1;r<i.length;r+=1){let l=i[r],c=Math.abs(l.startLine-s.startLine);c<a&&(o=l,a=c)}return{...s,startLine:o.startLine,endLine:o.endLine}})}function El(e,n,t){if(!Ut(t.symbol))return t.startLine;let s=Math.max(0,Math.min(t.startLine,e.length-1));if(!n)return s;let i=n.get(t.leaf);if(!i||i.length===0)return s;let o=null;for(let a of i){let r=Math.abs(a-t.startLine);(!o||r<o.distance)&&(o={line:a,distance:r})}return o?.line??s}function Rl(e){let n=/\b(?:function|def|fn)\s+([A-Za-z_$][\w$]*)/g,t=/\b([A-Za-z_$][\w$]*)\s*[:=]\s*(?:async\s*)?(?:function\b|\()/g,s=/^\s*(?:(?:export|public|private|protected|static|readonly|async|abstract|get|set)\s+)*([A-Za-z_$][\w$]*)\s*(?:<[^(]*>)?\s*\(/,i=/\b([A-Za-z_$][\w$]*)\s*\(/g,o=new Map,a=(r,l)=>{let c=o.get(r);if(!c){o.set(r,[l]);return}c[c.length-1]!==l&&c.push(l)};for(let r=0;r<e.length;r+=1){let l=e[r]??"";for(let m of l.matchAll(n))m[1]&&a(m[1],r);for(let m of l.matchAll(t))m[1]&&a(m[1],r);let c=l.match(s);c?.[1]&&a(c[1],r);for(let m of l.matchAll(i))m[1]&&a(m[1],r)}return o}function Ll(e,n,t,s){let i=Math.max(t,Math.min(e.length-1,s)),o=Math.max(t,Math.min(i,n.endLine)),a=0,r=0,l=!1;for(let c=t;c<=i;c+=1){let m=wl(e[c]??"");for(let u of m)u==="{"?(a+=1,l=!0):u==="}"?a=Math.max(0,a-1):u==="("?r+=1:u===")"&&(r=Math.max(0,r-1));if(l&&a===0||!l&&r===0&&c>=o)return c}return o}function wl(e){let n="",t=null,s=!1;for(let i=0;i<e.length;i+=1){let o=e[i],a=e[i+1];if(!t&&o==="/"&&a==="/"){n+=" ".repeat(e.length-i);break}if(t){if(s){s=!1,n+=" ";continue}if(o==="\\"){s=!0,n+=" ";continue}o===t&&(t=null),n+=" ";continue}if(o==='"'||o==="'"||o==="`"){t=o,n+=" ";continue}n+=o}return n}function Ut(e){return e.includes("().")}function Dl(e){let n=V(e);if("kind"in n)return null;for(let t=n.descriptors.length-2;t>=0;t--){let s=n.descriptors[t];if(s?.suffix==="type")return s.name}return null}function ai(e){let n=V(e);if("kind"in n)return[];let t=[];for(let s=n.descriptors.length-2;s>=0;s-=1){let i=n.descriptors[s];i?.suffix==="type"&&i.name&&t.push(i.name)}return t}import{existsSync as Fl}from"fs";import{basename as ci,isAbsolute as Tl,join as Al}from"path";function k(e,n){let t=Xe(e,n.trim());if(t)return t;let s=n.match(/^(.+):(\d+)-(\d+)$/);if(s){let[,c,m,u]=s,d=Math.max(0,parseInt(m,10)-1),g=Math.max(d,parseInt(u,10)-1),p=e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
171
222
  FROM global_symbols gs
172
223
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
173
224
  JOIN documents d ON der.document_id = d.id
@@ -175,7 +226,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
175
226
  AND der.start_line <= ? AND der.end_line >= ?
176
227
  ${e.pathExclusionsFor("d")}
177
228
  ORDER BY (der.end_line - der.start_line) ASC
178
- LIMIT 1`,`%${c}%`,d,f);if(p||(p=e.get(`SELECT gs.id, gs.symbol, c.document_id, MIN(c.start_line) AS start_line, MAX(c.end_line) AS end_line, d.relative_path
229
+ LIMIT 1`,`%${c}%`,d,g);if(p||(p=e.get(`SELECT gs.id, gs.symbol, c.document_id, MIN(c.start_line) AS start_line, MAX(c.end_line) AS end_line, d.relative_path
179
230
  FROM global_symbols gs
180
231
  JOIN mentions m ON m.symbol_id = gs.id
181
232
  JOIN chunks c ON m.chunk_id = c.id
@@ -186,7 +237,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
186
237
  ${e.pathExclusionsFor("d")}
187
238
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
188
239
  ORDER BY (MAX(c.end_line) - MIN(c.start_line)) ASC
189
- LIMIT 1`,`%${c}%`,d,f)),p&&!e.isIgnored(p.relative_path))return Je(e,p)}let s=Wi(n),o=wa(n),a=Ra(e,o),r=Oa(a,n,s);if(r&&!e.isIgnored(r.relative_path))return Je(e,r);let l=null;for(let c of a){if(e.isIgnored(c.relative_path))continue;let m=Da(c,n,s,o);m<=0||(!l||m>l.score)&&(l={row:c,score:m})}return l?Je(e,l.row):null}function Ue(e,n){let i=e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
240
+ LIMIT 1`,`%${c}%`,d,g)),p&&!e.isIgnored(p.relative_path))return Qe(e,p)}let i=li(n),o=Pl(n),a=Ol(e,o),r=Ml(a,n,i);if(r&&!e.isIgnored(r.relative_path))return Qe(e,r);let l=null;for(let c of a){if(e.isIgnored(c.relative_path))continue;let m=$l(c,n,i,o);m<=0||(!l||m>l.score)&&(l={row:c,score:m})}return l?Qe(e,l.row):null}function Xe(e,n){let s=e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
190
241
  FROM global_symbols gs
191
242
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
192
243
  JOIN documents d ON der.document_id = d.id
@@ -209,7 +260,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
209
260
  ${e.pathExclusionsFor("d")}
210
261
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
211
262
  ORDER BY d.relative_path, start_line
212
- LIMIT 1`,n);return!i||e.isIgnored(i.relative_path)?null:Je(e,i)}function wt(e,n){if("symbol"in n&&"relativePath"in n)return n;let t=La(e,n.symbolId)[0];return t?Je(e,t):null}function La(e,n){let t=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name
263
+ LIMIT 1`,n);return!s||e.isIgnored(s.relative_path)?null:Qe(e,s)}function qt(e,n){if("symbol"in n&&"relativePath"in n)return n;let t=kl(e,n.symbolId)[0];return t?Qe(e,t):null}function kl(e,n){let t=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name
213
264
  FROM global_symbols gs
214
265
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
215
266
  JOIN documents d ON der.document_id = d.id
@@ -230,14 +281,14 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
230
281
  AND m.role = 1
231
282
  ${e.pathExclusionsFor("d")}
232
283
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name
233
- ORDER BY start_line, end_line`,n)}function Ra(e,n){let t=n.map(()=>"(gs.symbol LIKE ? OR d.relative_path LIKE ? OR COALESCE(gs.display_name, '') LIKE ?)"),i=n.flatMap(o=>{let a=`%${o}%`;return[a,a,a]}),s=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name
284
+ ORDER BY start_line, end_line`,n)}function Ol(e,n){let t=n.map(()=>"(gs.symbol LIKE ? OR d.relative_path LIKE ? OR COALESCE(gs.display_name, '') LIKE ?)"),s=n.flatMap(o=>{let a=`%${o}%`;return[a,a,a]}),i=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name
234
285
  FROM global_symbols gs
235
286
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
236
287
  JOIN documents d ON der.document_id = d.id
237
288
  WHERE ${t.join(`
238
289
  AND `)}
239
290
  ${e.pathExclusionsFor("d")}
240
- LIMIT 200`,...i);return s.length>0?s:e.all(`SELECT
291
+ LIMIT 200`,...s);return i.length>0?i:e.all(`SELECT
241
292
  gs.id,
242
293
  gs.symbol,
243
294
  c.document_id,
@@ -254,17 +305,17 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
254
305
  AND `)}
255
306
  ${e.pathExclusionsFor("d")}
256
307
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name
257
- LIMIT 200`,...i)}function Da(e,n,t,i){let s=n.trim(),o=t,a=o.replace(/\(\)$/,""),r=n.toLowerCase(),l=t.toLowerCase(),c=l.replace(/\(\)$/,""),m=e.symbol,u=_(e.symbol),d=M(e.symbol),f=e.display_name??"",p=e.symbol.toLowerCase(),g=u.toLowerCase(),y=d.toLowerCase(),h=f.toLowerCase(),b=e.relative_path.toLowerCase(),x=/[/:.]/.test(t),S=0;return(m===s||m===o)&&(S+=1150),(u===s||u===o)&&(S+=1100),f===a&&(S+=980),d===a&&(S+=960),(`${d}()`===s||`${d}()`===o)&&(S+=955),(p===r||p===l)&&(S+=1e3),(g===r||g===l)&&(S+=950),(b===r||b===l)&&(S+=925),(b.endsWith(`/${l}`)||b.endsWith(`/${r}`))&&(S+=875),h===c&&(S+=850),y===c&&(S+=825),(`${y}()`===r||`${y}()`===l)&&(S+=820),(g.endsWith(`:${l}`)||g.endsWith(`:${c}`)||g.endsWith(`:${c}()`))&&(S+=800),p.includes(l)&&(S+=120),g.includes(l)&&(S+=140),b.includes(l)&&(S+=140),h.includes(l)&&(S+=110),i.every(I=>{let L=I.toLowerCase();return p.includes(L)||g.includes(L)||b.includes(L)||h.includes(L)})&&(S+=100+i.length*15),j(e.symbol)&&y===c&&(S+=60),!x&&We(e.symbol)&&(S-=160),S-=Math.min(50,Math.max(0,e.end_line-e.start_line)),S}function Wi(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function wa(e){let n=Wi(e),t=n.split(/[^A-Za-z0-9_]+/).map(i=>i.trim()).filter(i=>i.length>0);return t.length>0?[...new Set(t)]:[n]}function Oa(e,n,t){let i=n.trim(),s=e.filter(o=>{let a=_(o.symbol),r=(o.display_name??"").trim();return o.symbol===i||a===i||a===t||r===i||r===t||`${r}()`===i||o.relative_path===i});return s.length===0?null:(s.sort((o,a)=>o.end_line-o.start_line-(a.end_line-a.start_line)||o.relative_path.localeCompare(a.relative_path)||o.symbol.localeCompare(a.symbol)),s[0]??null)}function Q(e,n){let t=Ji(e,n,{allowMultiple:!1})[0]?.relativePath;return t||Ma(e,n)}function Ce(e,n){return Ji(e,n,{allowMultiple:!0}).map(t=>t.relativePath)}function Ma(e,n){if(!n)return null;let t=n.replace(/\\/g,"/").replace(/^\.\//,""),i=ka(t)&&t.startsWith(e.config.projectRoot)?t.slice(e.config.projectRoot.length).replace(/^\/+/,""):t,s=Pa(e.config.projectRoot,i);return $a(s)?i:null}function Ji(e,n,t){let i=Ui(n);if(!i)return[];let o=e.all(`SELECT relative_path
308
+ LIMIT 200`,...s)}function $l(e,n,t,s){let i=n.trim(),o=t,a=o.replace(/\(\)$/,""),r=n.toLowerCase(),l=t.toLowerCase(),c=l.replace(/\(\)$/,""),m=e.symbol,u=I(e.symbol),d=F(e.symbol),g=e.display_name??"",p=e.symbol.toLowerCase(),f=u.toLowerCase(),y=d.toLowerCase(),h=g.toLowerCase(),b=e.relative_path.toLowerCase(),_=/[/:.]/.test(t),S=0;return(m===i||m===o)&&(S+=1150),(u===i||u===o)&&(S+=1100),g===a&&(S+=980),d===a&&(S+=960),(`${d}()`===i||`${d}()`===o)&&(S+=955),(p===r||p===l)&&(S+=1e3),(f===r||f===l)&&(S+=950),(b===r||b===l)&&(S+=925),(b.endsWith(`/${l}`)||b.endsWith(`/${r}`))&&(S+=875),h===c&&(S+=850),y===c&&(S+=825),(`${y}()`===r||`${y}()`===l)&&(S+=820),(f.endsWith(`:${l}`)||f.endsWith(`:${c}`)||f.endsWith(`:${c}()`))&&(S+=800),p.includes(l)&&(S+=120),f.includes(l)&&(S+=140),b.includes(l)&&(S+=140),h.includes(l)&&(S+=110),s.every(x=>{let L=x.toLowerCase();return p.includes(L)||f.includes(L)||b.includes(L)||h.includes(L)})&&(S+=100+s.length*15),j(e.symbol)&&y===c&&(S+=60),!_&&Ge(e.symbol)&&(S-=160),S-=Math.min(50,Math.max(0,e.end_line-e.start_line)),S}function li(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function Pl(e){let n=li(e),t=n.split(/[^A-Za-z0-9_]+/).map(s=>s.trim()).filter(s=>s.length>0);return t.length>0?[...new Set(t)]:[n]}function Ml(e,n,t){let s=n.trim(),i=e.filter(o=>{let a=I(o.symbol),r=(o.display_name??"").trim();return o.symbol===s||a===s||a===t||r===s||r===t||`${r}()`===s||o.relative_path===s});return i.length===0?null:(i.sort((o,a)=>o.end_line-o.start_line-(a.end_line-a.start_line)||o.relative_path.localeCompare(a.relative_path)||o.symbol.localeCompare(a.symbol)),i[0]??null)}function ee(e,n){let t=ui(e,n,{allowMultiple:!1})[0]?.relativePath;return t||jl(e,n)}function Le(e,n){return ui(e,n,{allowMultiple:!0}).map(t=>t.relativePath)}function jl(e,n){if(!n)return null;let t=n.replace(/\\/g,"/").replace(/^\.\//,""),s=Tl(t)&&t.startsWith(e.config.projectRoot)?t.slice(e.config.projectRoot.length).replace(/^\/+/,""):t,i=Al(e.config.projectRoot,s);return Fl(i)?s:null}function ui(e,n,t){let s=mi(n);if(!s)return[];let o=e.all(`SELECT relative_path
258
309
  FROM documents
259
310
  WHERE 1 = 1
260
311
  ${e.pathExclusionsFor("documents")}
261
- ORDER BY relative_path`).filter(r=>!e.isIgnored(r.relative_path)).map(r=>({relativePath:r.relative_path,score:Fa(r.relative_path,i)})).filter(r=>r.score>0).sort((r,l)=>l.score-r.score||r.relativePath.localeCompare(l.relativePath));if(o.length===0){let r=O(e,n);return!r||e.isIgnored(r.relativePath)?[]:[{relativePath:r.relativePath,score:700}]}let a=o.filter(r=>r.score>=800);return a.length>0?t.allowMultiple?a:[a[0]]:t.allowMultiple?o:[o[0]]}function Fa(e,n){let t=Ui(e),i=Hi(t),s=Hi(n),o=0;return t===n&&(o+=1200),t.endsWith(`/${n}`)&&(o+=1100),i===s&&(o+=900),t.startsWith(`${n}/`)&&(o+=850),t.includes(n)&&(o+=250),o}function Ui(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function qi(e,n){let t=Ce(e,n);return He(e,t).map(({relativePath:i,...s})=>s)}import{basename as Ta}from"path";function zi(e,n){let t=O(e,n);if(!t)return[];let i=M(t.symbol),s=A(e,t.relativePath).filter(r=>Rt(r.symbol)),o=s.filter(r=>r.parentTypeName===i||r.symbol.includes(i));return(o.length>0?o:Aa(Ta(t.relativePath))===i?s.filter(r=>r.symbol.includes("<invalid-global-code>")):[]).map(r=>({startLine:r.startLine,endLine:r.endLine,name:M(r.symbol)}))}function Aa(e){return e.replace(/\.[^.]+$/,"")}function Ot(e){return e.replace(/'''[\s\S]*?'''/g,ve).replace(/"""[\s\S]*?"""/g,ve).replace(/#.*$/gm,ve).replace(/\/\/.*$/gm,ve).replace(/\/\*[\s\S]*?\*\//g,ve).replace(/`(?:\\[\s\S]|[^`])*`/g,ve).replace(/'(?:\\.|[^'\\\r\n])*'/g,ve).replace(/"(?:\\.|[^"\\\r\n])*"/g,ve)}function ve(e){return e.replace(/[^\r\n]/g," ")}var ja=vt("stripped-lines");function Yi(e,n,t){return ja.get(e,n,t,()=>Ot(t).split(`
262
- `))}var Gi=null,In="";function Ba(e){return Gi===e||(Gi=e,In=Ot(e)),In}function q(e,n,t){let i=Ba(e);return`${i.slice(0,n)}${" ".repeat(t-n)}${i.slice(t)}`}function X(e,n){return new RegExp(`\\b${$t(n)}\\b`,"m").test(e)}function qe(e,n){let t=new Set,i=new RegExp(`\\b${$t(n)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let s of e.matchAll(i)){let o=s[1];o&&t.add(o)}return[...t]}function $t(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function kt(e,n,t,i={}){if(!t)return[];let s=P(e,n);if(!s)return[];if(s.indexOf(t)===-1)return[];if(T(n))return(Me(e,n).get(t)??[]).filter(m=>!Ki(m,i));let o=Yi(e,n,s),a=new RegExp(`\\b${$t(t)}\\b`),r=[];for(let l=0;l<o.length;l++)Ki(l,i)||a.test(o[l]??"")&&r.push(l);return r}function Ki(e,n){return typeof n.excludeStartLine=="number"&&typeof n.excludeEndLine=="number"&&e>=n.excludeStartLine&&e<=n.excludeEndLine}var Wa=W("file-identifiers");function Vi(e,n){return Wa.get(e,n,()=>new Set(Me(e,n).keys()))}var Ha=W("file-ident-lines");function Me(e,n){return Ha.get(e,n,()=>Ua(e,n))}var Ja=W("file-idents-by-line");function Qi(e,n){return Ja.get(e,n,()=>{let t=Me(e,n),i=0;for(let o of t.values()){let a=o[o.length-1];a!==void 0&&a>i&&(i=a)}let s=new Array(i+1);for(let o=0;o<=i;o+=1)s[o]=new Set;for(let[o,a]of t)for(let r of a)s[r].add(o);return s})}function Ua(e,n){let t=new Map,i=(r,l)=>{let c=t.get(r);if(!c){t.set(r,[l]);return}c[c.length-1]!==l&&c.push(l)};if(T(n)){let r=$(e,n);if(r){let l=T(n),c=l==="rust"?new Set(["identifier","type_identifier","field_identifier"]):l==="python"?new Set(["identifier"]):new Set(["identifier","property_identifier","type_identifier"]),m=new Set(["rust","python"]),u=/\{(?:\?\s*)?([A-Za-z_][\w]*)/g,d=f=>{if(c.has(f.type)&&i(f.text,f.startPosition.row),l&&m.has(l)&&f.type==="string_content"){let p=f.startPosition.row;for(let g of f.text.matchAll(u))g[1]&&i(g[1],p)}for(let p of f.children)d(p)};return d(r.rootNode),t}}let s=P(e,n);if(!s)return t;let o=Ot(s).split(/\r?\n/),a=/\b([A-Za-z_$][\w$]*)\b/g;for(let r=0;r<o.length;r+=1){let l=o[r]??"";for(let c of l.matchAll(a))c[1]&&i(c[1],r)}return t}import{existsSync as Ss,readFileSync as _s}from"fs";import{join as xs}from"path";import{existsSync as ze}from"fs";import{basename as qa,dirname as Ee,extname as _e,join as le,relative as Fe,resolve as se}from"path";var za=Pe("indexed-paths"),Pt=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],Nn=[".py",".pyi"],ce=[".java",".scala",".kt",".kts"],Cn=[".rs"],vn=[".rb"],Xi=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],Ge=[".cs",".vb"],En=[".dart"],ot=[".php"],Ga=[Pt,Nn,ce,Cn,vn,Xi,Ge,En,ot];function Le(e,n){return n.includes(_e(e).toLowerCase())}function Ya(e){return Le(e,Nn)}function Ka(e){return Le(e,ce)}function Va(e){return Le(e,Cn)}function Qa(e){return Le(e,vn)}function Xa(e){return Le(e,Xi)}function Za(e){return Le(e,Ge)}function Zi(e){return _e(e).toLowerCase()===".vb"}function el(e){return Le(e,En)}function tl(e){return Le(e,ot)}function Ln(e){let n=_e(e).toLowerCase();for(let t of Ga)if(t.includes(n))return t;return Pt}function nl(e){return Ka(e)||Za(e)||tl(e)}function Te(e,n,t){return Ya(n)?Ye(e,n,t):Va(n)?xe(e,n,t):Qa(n)?Mt(e,n,t):Xa(n)?Ft(e,n,t):nl(n)?H(e,t.replace(/\\/g,"."),Ln(n)):el(n)?Tt(e,n,t):il(e,n,t)}function il(e,n,t){if(!t.startsWith(".")&&!t.startsWith("/"))return null;let i=Ee(le(e.config.projectRoot,n)),s=se(i,t),o=Ae(e);for(let a of ll(s)){let r=oe(Fe(e.config.projectRoot,a));if(o.has(r)||ze(a))return r}return oe(Fe(e.config.projectRoot,s))}function Ye(e,n,t){let i=Ae(e),s;if(t.startsWith(".")){let o=t.match(/^(\.+)(.*)$/);if(!o)return null;let a=o[1].length,r=o[2].replace(/^\./,""),l=Ee(le(e.config.projectRoot,n));for(let c=1;c<a;c++)l=Ee(l);s=r?se(l,r.replace(/\./g,"/")):l}else s=se(e.config.projectRoot,t.replace(/\./g,"/"));for(let o of sl(s)){let a=oe(Fe(e.config.projectRoot,o));if(i.has(a)||ze(o))return a}return null}function xe(e,n,t){if(!t)return null;let i=t.replace(/\s+as\s+.+$/,"").trim();if(!i.startsWith("crate::")&&!i.startsWith("self::")&&!i.startsWith("super::"))return null;let s=Ee(le(e.config.projectRoot,n)),o;i.startsWith("crate::")?o=se(e.config.projectRoot,"src",i.slice(7).replace(/::/g,"/")):i.startsWith("self::")?o=se(s,i.slice(6).replace(/::/g,"/")):o=se(Ee(s),i.slice(7).replace(/::/g,"/"));for(let a of ol(o)){let r=oe(Fe(e.config.projectRoot,a));if(Ae(e).has(r)||ze(a))return r}return null}function Mt(e,n,t){let i=Ee(le(e.config.projectRoot,n)),s=se(i,t);for(let o of rl(s)){let a=oe(Fe(e.config.projectRoot,o));if(Ae(e).has(a)||ze(o))return a}return null}function Ft(e,n,t){let i=Ae(e),s=Ee(le(e.config.projectRoot,n)),o=[se(s,t),se(e.config.projectRoot,t),se(e.config.projectRoot,"include",t),se(e.config.projectRoot,"src",t)];for(let a of o){let r=oe(Fe(e.config.projectRoot,a));if(i.has(r)||ze(a))return r}return null}function H(e,n,t){let i=Ae(e),s=n.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),o=s.replace(/\./g,"/"),a=s.split(".").pop()??s;for(let l of t){let c=`${o}${l}`,m=[...i].find(u=>u.endsWith(c));if(m)return m}for(let l of t){let c=[...i].find(m=>qa(m)===`${a}${l}`);if(c)return c}let r=[...i].filter(l=>t.includes(_e(l).toLowerCase())).filter(l=>l.includes(`/${o}/`)||l.includes(`/${a}/`)).sort((l,c)=>l.localeCompare(c));return r.length===1?r[0]:null}function Tt(e,n,t){let i=Ae(e);if(t.startsWith("package:")){let a=t.slice(8),r=a.indexOf("/");if(r<0)return null;let l=a.slice(r+1),c=oe(l.startsWith("lib/")?l:`lib/${l}`);return i.has(c)?c:null}let s=Ee(le(e.config.projectRoot,n)),o=se(s,t);for(let a of al(o)){let r=oe(Fe(e.config.projectRoot,a));if(i.has(r)||ze(a))return r}return null}function sl(e){let n=_e(e);return Nn.includes(n)?[e]:[`${e}.py`,`${e}.pyi`,le(e,"__init__.py"),le(e,"__init__.pyi")]}function ol(e){let n=_e(e);return Cn.includes(n)?[e]:[`${e}.rs`,le(e,"mod.rs")]}function rl(e){let n=_e(e);return vn.includes(n)?[e]:[`${e}.rb`,le(e,"index.rb")]}function al(e){let n=_e(e);return En.includes(n)?[e]:[`${e}.dart`,e]}function ll(e){let n=_e(e),t=new Set;if(n){t.add(e);for(let i of Pt)t.add(e.slice(0,-n.length)+i)}else for(let i of Pt)t.add(`${e}${i}`),t.add(le(e,`index${i}`));return[...t]}function Ae(e){return za.get(e,()=>new Set(e.all(`SELECT relative_path
312
+ ORDER BY relative_path`).filter(r=>!e.isIgnored(r.relative_path)).map(r=>({relativePath:r.relative_path,score:Bl(r.relative_path,s)})).filter(r=>r.score>0).sort((r,l)=>l.score-r.score||r.relativePath.localeCompare(l.relativePath));if(o.length===0){let r=k(e,n);return!r||e.isIgnored(r.relativePath)?[]:[{relativePath:r.relativePath,score:700}]}let a=o.filter(r=>r.score>=800);return a.length>0?t.allowMultiple?a:[a[0]]:t.allowMultiple?o:[o[0]]}function Bl(e,n){let t=mi(e),s=ci(t),i=ci(n),o=0;return t===n&&(o+=1200),t.endsWith(`/${n}`)&&(o+=1100),s===i&&(o+=900),t.startsWith(`${n}/`)&&(o+=850),t.includes(n)&&(o+=250),o}function mi(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function di(e,n){let t=Le(e,n);return Ke(e,t).map(({relativePath:s,...i})=>i)}import{basename as Wl}from"path";function pi(e,n){let t=k(e,n);if(!t)return[];let s=F(t.symbol),i=A(e,t.relativePath).filter(r=>Ve(r.symbol)),o=i.filter(r=>r.parentTypeName===s||r.symbol.includes(s));return(o.length>0?o:Hl(Wl(t.relativePath))===s?i.filter(r=>r.symbol.includes("<invalid-global-code>")):[]).map(r=>({startLine:r.startLine,endLine:r.endLine,name:F(r.symbol)}))}function Hl(e){return e.replace(/\.[^.]+$/,"")}var ft=new WeakMap;function hi(e,n){let t=P(n);return t==="rust"?Vl(e,n):t==="typescript"||t==="tsx"||t==="javascript"?Ul(e,n):[]}var Jl=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function Ul(e,n){let t=O(e,n);if(!t)return[];let s=ft.get(t);if(s)return s;let i=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(n)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(n),o=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(n),a=!1,r=t.rootNode;for(let c of r.namedChildren){if(c.type!=="expression_statement")continue;let m=c.namedChild(0);if(!m||m.type!=="call_expression")continue;let u=m.namedChild(0);if(!u)continue;let d=u.type==="member_expression"?u.namedChild(u.namedChildCount-1)?.text:u.text;if(d&&Jl.has(d)){a=!0;break}}let l=[];a&&l.push({startLine:0,endLine:r.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(i||o)&&l.push({startLine:0,endLine:r.endPosition.row,reason:i?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of r.namedChildren){let m=null,u=null;if(c.type==="function_declaration")m=c.namedChild(0)?.text??null,u=c;else if(c.type==="export_statement"){let d=c.namedChild(0);d?.type==="function_declaration"&&(m=d.namedChild(0)?.text??null,u=d)}else if(c.type==="lexical_declaration"){let d=c.namedChild(0);if(d?.type==="variable_declarator"){let g=d.namedChild(0)?.text,p=d.namedChild(1);g&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(m=g,u=d)}}m&&/^use[A-Z]/.test(m)&&u&&l.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...yi(t,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),ft.set(t,l),l}var ql=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function zl(e){return ql.test(e)}function yi(e,n,t){let s=[],i=o=>{if(n.has(o.type)&&o.parent){let r=o.parent.children,l=-1;for(let c=0;c<r.length;c+=1)if(r[c].startIndex===o.startIndex&&r[c].type===o.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let m=r[c];if(t.has(m.type)){if(zl(m.text)){s.push({startLine:o.startPosition.row,endLine:o.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(m.type==="attribute_item"||m.type==="inner_attribute_item"))break}}for(let a of o.namedChildren)i(a)};return i(e.rootNode),s}function Vl(e,n){let t=O(e,n);if(!t)return[];let s=ft.get(t);if(s)return s;let i=[];if(Gl(t.rootNode)){let u={startLine:0,endLine:t.rootNode.endPosition.row,reason:"generated file (@generated header)"};return ft.set(t,[u]),[u]}let o=u=>{let d=u.parent;if(!d)return[];let g=d.children,p=-1;for(let y=0;y<g.length;y+=1)if(g[y].startIndex===u.startIndex&&g[y].type===u.type){p=y;break}if(p<=0)return[];let f=[];for(let y=p-1;y>=0;y-=1){let h=g[y];if(h.type==="attribute_item"||h.type==="inner_attribute_item")f.push(h.text);else{if(h.type==="line_comment"||h.type==="block_comment")continue;break}}return f},a=u=>/#\[\s*tauri::command\b/.test(u)?"#[tauri::command]":/#\[\s*command\b/.test(u)?"#[command]":/#\[\s*test\b/.test(u)?"#[test]":/#\[\s*bench\b/.test(u)?"#[bench]":/#\[\s*tokio::test\b/.test(u)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(u)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(u)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(u)?"#[no_mangle]":/#\[\s*napi\b/.test(u)?"#[napi]":/#\[\s*pyfunction\b/.test(u)?"#[pyfunction]":/#\[\s*pymethod\b/.test(u)?"#[pymethod]":/#\[\s*pyo3\b/.test(u)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(u)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(u)?"#[doc(hidden)]":null,r=u=>/#\[\s*derive\s*\(/.test(u)?/\bSerialize\b/.test(u)||/\bDeserialize\b/.test(u)||/\bFromRow\b/.test(u)||/\bDeriveEntityModel\b/.test(u)||/\bIntoSchema\b/.test(u)||/\bToSchema\b/.test(u)||/\bDeriveValueType\b/.test(u)||/\bsqlx::FromRow\b/.test(u)||/\bError\b/.test(u)||/\bthiserror::Error\b/.test(u):!1,l=u=>/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(u),c=(u,d,g,p)=>{let f=d,y=g,h=p;if(u.type==="trait_item"&&(h=!0,i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait declaration body (dynamic dispatch)"})),u.type==="impl_item"&&u.childForFieldName("trait")&&(y=!0,i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait impl block (dynamic dispatch)"})),u.type==="function_item"||u.type==="function_signature_item"){let b=o(u),_=null;g?_="trait impl method (dynamic dispatch)":d&&(_="inside #[cfg(test)] mod");for(let S of b){let x=a(S);if(x){_=x;break}if(l(S)){_="#[allow(dead_code)]";break}}_&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:_})}else if(g&&(u.type==="const_item"||u.type==="type_item"||u.type==="static_item"||u.type==="associated_type"))i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait impl associated item (dynamic dispatch)"});else if(u.type==="struct_item"||u.type==="enum_item"||u.type==="union_item"){let b=o(u),_=b.some(r),S=b.some(l),x=u.namedChildren.find(L=>L.type==="type_identifier")?.text;_&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:x}),S&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"#[allow(dead_code)]",containerName:x}),d&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:x})}else u.type==="mod_item"&&o(u).some(_=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(_))&&(f=!0);for(let b of u.namedChildren)c(b,f,y,h)};c(t.rootNode,!1,!1,!1),i.push(...yi(t,new Set(["function_item","function_signature_item","struct_item","enum_item","union_item","impl_item","mod_item","static_item","const_item"]),new Set(["line_comment","block_comment"])));let m=Zl(t.rootNode);if(m.size>0)for(let u of t.rootNode.descendantsOfType("mod_item")){let d=u.childForFieldName("name")?.text;d&&m.has(d)&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:'serde `with = "..."` module \u2014 body invoked via reflection',containerName:d})}return ft.set(t,i),i}function Gl(e){for(let n=0;n<Math.min(e.namedChildCount,12);n+=1){let t=e.namedChild(n);if(!t||t.type!=="line_comment"&&t.type!=="block_comment")break;if(/@generated\b/.test(t.text)||/This file is .*generated\b/i.test(t.text)||/Code generated by/i.test(t.text)||/Generated by:\s*https?:\/\/openapi-generator/i.test(t.text)||/openapi-generator/i.test(t.text)&&/Generated by/i.test(t.text))return!0}return!1}var Yl=[{key:"default",re:/\bdefault\s*=\s*"([^"]+)"/g},{key:"with",re:/\bwith\s*=\s*"([^"]+)"/g},{key:"serialize_with",re:/\bserialize_with\s*=\s*"([^"]+)"/g},{key:"deserialize_with",re:/\bdeserialize_with\s*=\s*"([^"]+)"/g},{key:"skip_serializing_if",re:/\bskip_serializing_if\s*=\s*"([^"]+)"/g},{key:"getter",re:/\bgetter\s*=\s*"([^"]+)"/g},{key:"rename_all_with",re:/\brename_all_with\s*=\s*"([^"]+)"/g},{key:"schema_with",re:/\bschema_with\s*=\s*"([^"]+)"/g}],bi=/^#!?\[\s*serde\s*\(/,Kl=/^#!?\[\s*schemars\s*\(/,Ql=/^#!?\[\s*validate\s*\(/,fi=/\bwith\s*=\s*"([^"]+)"/g;function we(e,n){return Jt(e,n,Xl,()=>new Set,(t,s,i)=>{if(s==="rust"){for(let o of t.rootNode.descendantsOfType("attribute_item"))gi(o.text,i);for(let o of t.rootNode.descendantsOfType("inner_attribute_item"))gi(o.text,i)}})??new Set}var Xl=new WeakMap;function gi(e,n){let t=bi.test(e),s=Kl.test(e),i=Ql.test(e);if(!(!t&&!s&&!i))for(let{re:o}of Yl){o.lastIndex=0;let a;for(;(a=o.exec(e))!==null;){let r=a[1],l=r.split("::").pop()??r;l==="is_none"&&/\bOption\b/.test(r)||l==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(r)||l&&n.add(l)}}}function Zl(e){let n=new Set;for(let t of e.descendantsOfType("attribute_item")){if(!bi.test(t.text))continue;fi.lastIndex=0;let s;for(;(s=fi.exec(t.text))!==null;){let i=s[1],o=i.split("::").pop()??i;o&&n.add(o)}}return n}var ec=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function Si(e,n){return Jt(e,n,tc,()=>new Set,(t,s,i)=>{if(!(s!=="typescript"&&s!=="tsx"&&s!=="javascript"))for(let o of t.rootNode.descendantsOfType("call_expression")){let a=o.namedChild(0);if(!a)continue;let r=ut(a);if(!r||!ec.has(r))continue;let l=o.namedChildren.find(u=>u.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let m=c.namedChildren.find(u=>u.type==="string_fragment");m&&i.add(m.text)}})??new Set}var tc=new WeakMap;function zt(e){return e.replace(/'''[\s\S]*?'''/g,De).replace(/"""[\s\S]*?"""/g,De).replace(/#.*$/gm,De).replace(/\/\/.*$/gm,De).replace(/\/\*[\s\S]*?\*\//g,De).replace(/`(?:\\[\s\S]|[^`])*`/g,De).replace(/'(?:\\.|[^'\\\r\n])*'/g,De).replace(/"(?:\\.|[^"\\\r\n])*"/g,De)}function De(e){return e.replace(/[^\r\n]/g," ")}var nc=Ot("stripped-lines");function xi(e,n,t){return nc.get(e,n,t,()=>zt(t).split(`
313
+ `))}var _i=null,Mn="";function sc(e){return _i===e||(_i=e,Mn=zt(e)),Mn}function z(e,n,t){let s=sc(e);return`${s.slice(0,n)}${" ".repeat(t-n)}${s.slice(t)}`}function te(e,n){return new RegExp(`\\b${Vt(n)}\\b`,"m").test(e)}function Ze(e,n){let t=new Set,s=new RegExp(`\\b${Vt(n)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let i of e.matchAll(s)){let o=i[1];o&&t.add(o)}return[...t]}function Vt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Gt(e,n,t,s={}){if(!t)return[];let i=M(e,n);if(!i)return[];if(i.indexOf(t)===-1)return[];if(P(n))return(xe(e,n).get(t)??[]).filter(m=>!Ii(m,s));let o=xi(e,n,i),a=new RegExp(`\\b${Vt(t)}\\b`),r=[];for(let l=0;l<o.length;l++)Ii(l,s)||a.test(o[l]??"")&&r.push(l);return r}function Ii(e,n){return typeof n.excludeStartLine=="number"&&typeof n.excludeEndLine=="number"&&e>=n.excludeStartLine&&e<=n.excludeEndLine}var ic=W("file-identifiers");function Ni(e,n){return ic.get(e,n,()=>new Set(xe(e,n).keys()))}var oc=W("file-ident-lines");function xe(e,n){return oc.get(e,n,()=>ac(e,n))}var rc=W("file-idents-by-line");function vi(e,n){return rc.get(e,n,()=>{let t=xe(e,n),s=0;for(let o of t.values()){let a=o[o.length-1];a!==void 0&&a>s&&(s=a)}let i=new Array(s+1);for(let o=0;o<=s;o+=1)i[o]=new Set;for(let[o,a]of t)for(let r of a)i[r].add(o);return i})}function ac(e,n){let t=new Map,s=(r,l)=>{let c=t.get(r);if(!c){t.set(r,[l]);return}c[c.length-1]!==l&&c.push(l)};if(P(n)){let r=O(e,n);if(r){let l=P(n),c=l==="rust"?new Set(["identifier","type_identifier","field_identifier"]):l==="python"?new Set(["identifier"]):new Set(["identifier","property_identifier","type_identifier"]),m=new Set(["rust","python"]),u=/\{([^{}]*)\}/g,d=/\b([A-Za-z_][\w]*)\b/g,g=p=>{if(c.has(p.type)&&s(p.text,p.startPosition.row),l&&m.has(l)&&p.type==="string_content"){let f=p.startPosition.row;for(let y of p.text.matchAll(u)){let h=y[1]??"";for(let b of h.matchAll(d))b[1]&&s(b[1],f)}}for(let f of p.children)g(f)};return g(r.rootNode),t}}let i=M(e,n);if(!i)return t;let o=zt(i).split(/\r?\n/),a=/\b([A-Za-z_$][\w$]*)\b/g;for(let r=0;r<o.length;r+=1){let l=o[r]??"";for(let c of l.matchAll(a))c[1]&&s(c[1],r)}return t}import{existsSync as zi,readFileSync as Vi}from"fs";import{join as Gi}from"path";import{existsSync as et}from"fs";import{basename as lc,dirname as ke,extname as Ie,join as ue,relative as We,resolve as re}from"path";var cc=je("indexed-paths"),Yt=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],Fn=[".py",".pyi"],me=[".java",".scala",".kt",".kts"],Tn=[".rs"],An=[".rb"],Ci=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],tt=[".cs",".vb"],jn=[".dart"],gt=[".php"],uc=[Yt,Fn,me,Tn,An,Ci,tt,jn,gt];function Oe(e,n){return n.includes(Ie(e).toLowerCase())}function mc(e){return Oe(e,Fn)}function dc(e){return Oe(e,me)}function pc(e){return Oe(e,Tn)}function fc(e){return Oe(e,An)}function gc(e){return Oe(e,Ci)}function hc(e){return Oe(e,tt)}function Ei(e){return Ie(e).toLowerCase()===".vb"}function yc(e){return Oe(e,jn)}function bc(e){return Oe(e,gt)}function Bn(e){let n=Ie(e).toLowerCase();for(let t of uc)if(t.includes(n))return t;return Yt}function Sc(e){return dc(e)||hc(e)||bc(e)}function He(e,n,t){return mc(n)?nt(e,n,t):pc(n)?Ne(e,n,t):fc(n)?Kt(e,n,t):gc(n)?Qt(e,n,t):Sc(n)?H(e,t.replace(/\\/g,"."),Bn(n)):yc(n)?Xt(e,n,t):_c(e,n,t)}function _c(e,n,t){if(!t.startsWith(".")&&!t.startsWith("/"))return null;let s=ke(ue(e.config.projectRoot,n)),i=re(s,t),o=Je(e);for(let a of Cc(i)){let r=ae(We(e.config.projectRoot,a));if(o.has(r)||et(a))return r}return ae(We(e.config.projectRoot,i))}function nt(e,n,t){let s=Je(e),i;if(t.startsWith(".")){let o=t.match(/^(\.+)(.*)$/);if(!o)return null;let a=o[1].length,r=o[2].replace(/^\./,""),l=ke(ue(e.config.projectRoot,n));for(let c=1;c<a;c++)l=ke(l);i=r?re(l,r.replace(/\./g,"/")):l}else i=re(e.config.projectRoot,t.replace(/\./g,"/"));for(let o of xc(i)){let a=ae(We(e.config.projectRoot,o));if(s.has(a)||et(o))return a}return null}function Ne(e,n,t){if(!t)return null;let s=t.replace(/\s+as\s+.+$/,"").trim();if(!s.startsWith("crate::")&&!s.startsWith("self::")&&!s.startsWith("super::"))return null;let i=ke(ue(e.config.projectRoot,n)),o;s.startsWith("crate::")?o=re(e.config.projectRoot,"src",s.slice(7).replace(/::/g,"/")):s.startsWith("self::")?o=re(i,s.slice(6).replace(/::/g,"/")):o=re(ke(i),s.slice(7).replace(/::/g,"/"));for(let a of Ic(o)){let r=ae(We(e.config.projectRoot,a));if(Je(e).has(r)||et(a))return r}return null}function Kt(e,n,t){let s=ke(ue(e.config.projectRoot,n)),i=re(s,t);for(let o of Nc(i)){let a=ae(We(e.config.projectRoot,o));if(Je(e).has(a)||et(o))return a}return null}function Qt(e,n,t){let s=Je(e),i=ke(ue(e.config.projectRoot,n)),o=[re(i,t),re(e.config.projectRoot,t),re(e.config.projectRoot,"include",t),re(e.config.projectRoot,"src",t)];for(let a of o){let r=ae(We(e.config.projectRoot,a));if(s.has(r)||et(a))return r}return null}function H(e,n,t){let s=Je(e),i=n.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),o=i.replace(/\./g,"/"),a=i.split(".").pop()??i;for(let l of t){let c=`${o}${l}`,m=[...s].find(u=>u.endsWith(c));if(m)return m}for(let l of t){let c=[...s].find(m=>lc(m)===`${a}${l}`);if(c)return c}let r=[...s].filter(l=>t.includes(Ie(l).toLowerCase())).filter(l=>l.includes(`/${o}/`)||l.includes(`/${a}/`)).sort((l,c)=>l.localeCompare(c));return r.length===1?r[0]:null}function Xt(e,n,t){let s=Je(e);if(t.startsWith("package:")){let a=t.slice(8),r=a.indexOf("/");if(r<0)return null;let l=a.slice(r+1),c=ae(l.startsWith("lib/")?l:`lib/${l}`);return s.has(c)?c:null}let i=ke(ue(e.config.projectRoot,n)),o=re(i,t);for(let a of vc(o)){let r=ae(We(e.config.projectRoot,a));if(s.has(r)||et(a))return r}return null}function xc(e){let n=Ie(e);return Fn.includes(n)?[e]:[`${e}.py`,`${e}.pyi`,ue(e,"__init__.py"),ue(e,"__init__.pyi")]}function Ic(e){let n=Ie(e);return Tn.includes(n)?[e]:[`${e}.rs`,ue(e,"mod.rs")]}function Nc(e){let n=Ie(e);return An.includes(n)?[e]:[`${e}.rb`,ue(e,"index.rb")]}function vc(e){let n=Ie(e);return jn.includes(n)?[e]:[`${e}.dart`,e]}function Cc(e){let n=Ie(e),t=new Set;if(n){t.add(e);for(let s of Yt)t.add(e.slice(0,-n.length)+s)}else for(let s of Yt)t.add(`${e}${s}`),t.add(ue(e,`index${s}`));return[...t]}function Je(e){return cc.get(e,()=>new Set(e.all(`SELECT relative_path
263
314
  FROM documents
264
315
  WHERE 1 = 1
265
- ${e.pathExclusionsFor("documents")}`).map(n=>oe(n.relative_path)).filter(n=>!e.isIgnored(n))))}function oe(e){return e.replace(/\\/g,"/")}function ie(e){let n=[],t=0,i=0;for(let s=0;s<e.length;s++){let o=e[s];(o==="{"||o==="["||o==="(")&&t++,(o==="}"||o==="]"||o===")")&&t--,o===","&&t===0&&(n.push(e.slice(i,s)),i=s+1)}return n.push(e.slice(i)),n}function re(e,n){for(let t of e.namedChildren)if(t.type===n)return t;return null}function J(e,n){let t=new Set,i=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]),s=(o,a)=>{let r=a||n.has(o.type);!r&&i.has(o.type)&&t.add(o.text);for(let l of o.children)s(l,r)};return s(e.rootNode,!1),t}function pe(e,n,t,i,s,o,a){return{importedName:s,localName:o,sourcePath:a??H(e,i,Ln(n)),kind:"named",used:X(t,o),usedMembers:[]}}function ts(e,n,t){let i=$(e,n);return i?cl(e,n,i):dl(t).flatMap(s=>pl(e,n,s.clause,s.specifier,s.start,s.end,t))}function cl(e,n,t){let i=J(t,new Set(["import_statement"]));if(nt(n))for(let o of xl(e,n))i.add(o);let s=[];for(let o of t.rootNode.descendantsOfType("import_statement")){let a=ml(o);if(!a)continue;let r=Te(e,n,a),l=re(o,"import_clause");if(!l){s.push({importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]});continue}for(let c of l.namedChildren)switch(c.type){case"identifier":{let m=c.text;s.push({importedName:"default",localName:m,sourcePath:r,kind:"default",used:i.has(m),usedMembers:[]});break}case"namespace_import":{let u=re(c,"identifier")?.text??"";if(!u)break;let d=ul(t,u);s.push({importedName:"*",localName:u,sourcePath:r,kind:"namespace",used:d.length>0||i.has(u),usedMembers:d});break}case"named_imports":{for(let m of c.namedChildren){if(m.type!=="import_specifier")continue;let u=m.namedChild(0),d=m.namedChild(1);if(!u)continue;let f=u.text,p=d?.text??f;s.push({importedName:f,localName:p,sourcePath:r,kind:"named",used:i.has(p),usedMembers:[]})}break}}}return s}function ml(e){let n=re(e,"string");if(!n)return null;let t=re(n,"string_fragment");return t?t.text:null}function ul(e,n){let t=new Set;for(let i of e.rootNode.descendantsOfType("member_expression")){let s=i.namedChild(0),o=i.namedChild(1);!s||!o||s.type!=="identifier"||s.text!==n||(o.type==="property_identifier"||o.type==="identifier")&&t.add(o.text)}return[...t]}function dl(e){let n=[],t=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of e.matchAll(t)){let o=s[0],a=s[1],r=s[2];!o||!r||typeof s.index!="number"||n.push({clause:a,specifier:r,start:s.index,end:s.index+o.length})}let i=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of e.matchAll(i)){let o=s[0],a=s[1];!o||!a||typeof s.index!="number"||n.push({clause:null,specifier:a,start:s.index,end:s.index+o.length})}return n.sort((s,o)=>s.start-o.start)}function pl(e,n,t,i,s,o,a){let r=Te(e,n,i),l=q(a,s,o);return t?fl(t).map(m=>({...m,sourcePath:r})).map(m=>{if(m.kind==="namespace"){let u=qe(l,m.localName);return{...m,used:u.length>0||X(l,m.localName),usedMembers:u}}return m.kind==="side-effect"?{...m,used:!0,usedMembers:[]}:{...m,used:m.localName?X(l,m.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]}]}function fl(e){let n=e.trim().replace(/^type\s+/,""),[t,i]=gl(n),s=[];return t&&s.push(...es(t)),i&&s.push(...es(i)),s}function es(e){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let t=n.slice(1,-1).trim();return t?ie(t).map(i=>{let s=i.trim().replace(/^type\s+/,""),[o,a]=s.split(/\s+as\s+/);return{importedName:o.trim(),localName:(a??o).trim(),kind:"named"}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace"}]:[{importedName:"default",localName:n,kind:"default"}]}function gl(e){let n=0;for(let t=0;t<e.length;t++){let i=e[t];if(i==="{"&&n++,i==="}"&&n--,i===","&&n===0)return[e.slice(0,t).trim(),e.slice(t+1).trim()]}return[e.trim(),null]}function ns(e,n){let t=$(e,n);if(t)return yl(e,n,t);let i=P(e,n);if(!i)return[];let s=[],o=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of i.matchAll(o)){if(typeof l.index!="number")continue;let c=l[1]??"",m=l[2]??"",u=ie(c).map(p=>hl(p.trim())).filter(p=>!!p),d=Ke(i,l.index),f=Ke(i,l.index+l[0].length-1);s.push({kind:"named",sourcePath:Te(e,n,m),names:u,startLine:d,endLine:f})}let a=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of i.matchAll(a)){if(typeof l.index!="number")continue;let c=l[2]??"",m=Ke(i,l.index),u=Ke(i,l.index+l[0].length-1);s.push({kind:"star-as",sourcePath:Te(e,n,c),names:[],startLine:m,endLine:u})}let r=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of i.matchAll(r)){if(typeof l.index!="number")continue;let c=l[1]??"",m=Ke(i,l.index),u=Ke(i,l.index+l[0].length-1);s.push({kind:"star",sourcePath:Te(e,n,c),names:[],startLine:m,endLine:u})}return s}function hl(e){if(!e)return null;let n=e.replace(/^type\s+/,"").trim();if(!n)return null;let t=n.match(/^(\w+)\s+as\s+(\w+)$/);if(t)return t[2]??null;let i=n.match(/^(\w+)$/);return i?i[1]??null:null}function Ke(e,n){let t=0;for(let i=0;i<n&&i<e.length;i++)e.charCodeAt(i)===10&&t++;return t}function yl(e,n,t){let i=[];for(let s of t.rootNode.descendantsOfType("export_statement")){let o=bl(e,n,s);if(o===void 0)continue;let a=s.startPosition.row,r=s.endPosition.row,l=Sl(s,o,a,r);i.push(l)}return i}function bl(e,n,t){let i=re(t,"string");if(!i)return;let s=re(i,"string_fragment");if(s)return Te(e,n,s.text)}function Sl(e,n,t,i){let s=re(e,"export_clause");if(s){let a=[];for(let r of s.namedChildren){if(r.type!=="export_specifier")continue;let l=r.namedChild(0),c=r.namedChild(1);l&&a.push((c??l).text)}return{kind:"named",sourcePath:n,names:a,startLine:t,endLine:i}}return re(e,"namespace_export")?{kind:"star-as",sourcePath:n,names:[],startLine:t,endLine:i}:{kind:"star",sourcePath:n,names:[],startLine:t,endLine:i}}var _l=W("vue-non-script-identifiers");function xl(e,n){return _l.get(e,n,()=>{let t=new Set,i=P(e,n);if(!i)return t;let o=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,a=>a.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,a=>a.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,a=>a.replace(/[^\r\n]/g," "));for(let a of o.matchAll(/[A-Za-z_$][\w$]*/g))t.add(a[0]);return t})}import{basename as is}from"path";function ss(e,n,t){let i=$(e,n);if(i)return Il(e,n,i);let s=[];for(let o of t.matchAll(/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=q(t,o.index,o.index+r.length),c=is(a).replace(/\.[^.]+$/,"");s.push({importedName:a,localName:c,sourcePath:Ft(e,n,a),kind:"named",used:X(l,c),usedMembers:[]})}return s}function Il(e,n,t){let i=J(t,new Set(["preproc_include"])),s=[];for(let o of t.rootNode.descendantsOfType("preproc_include")){let a=null;for(let l of o.namedChildren){if(l.type==="system_lib_string"){a=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){a=l.namedChildren.find(m=>m.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!a)continue;let r=is(a).replace(/\.[^.]+$/,"");s.push({importedName:a,localName:r,sourcePath:Ft(e,n,a),kind:"named",used:i.has(r),usedMembers:[]})}return s}function os(e,n,t){let i=[];for(let s of t.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let o=s[1]?.trim(),a=s[2]?.trim()??null,r=s[0];if(!o||!r||typeof s.index!="number")continue;let l=q(t,s.index,s.index+r.length);i.push({importedName:o,localName:a,sourcePath:Tt(e,n,o),kind:a?"namespace":"side-effect",used:a?X(l,a):!0,usedMembers:a?qe(l,a):[]})}return i}function rs(e,n,t){let i=[];for(let s of t.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let o=s[1]?.trim();o&&i.push({specifier:o,sourcePath:Tt(e,n,o)})}return i}function as(e,n,t){let i=$(e,n),s=T(n);if(i&&s==="csharp")return Cl(e,n,i);if(i&&s==="vb")return Nl(e,n,i);let o=[],a=Zi(n)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;for(let r of t.matchAll(a)){let l=r[1]?.trim(),c=r[0];if(!l||!c||typeof r.index!="number")continue;let m=q(t,r.index,r.index+c.length),[u,d]=l.split(/\s*=\s*/),f=!!d,p=(f?d:u)?.trim()??l,g=p.split(".").pop()??p,y=f?u?.trim()??g:g;o.push(pe(e,n,m,p,g,y,H(e,p,Ge)))}return o}function Nl(e,n,t){let i=J(t,new Set(["imports_statement"])),s=[];for(let o of t.rootNode.descendantsOfType("imports_statement")){let a=o.namedChildren.filter(d=>d.type==="namespace_name");if(a.length===0)continue;let r=a[a.length-1],l=a.length>1?a[0]:null,c=r.text,m=c.split(".").pop()??c,u=l?.text??m;s.push({importedName:m,localName:u,sourcePath:H(e,c,Ge),kind:l?"namespace":"named",used:i.has(u),usedMembers:[]})}return s}function Cl(e,n,t){let i=J(t,new Set(["using_directive"])),s=[];for(let o of t.rootNode.descendantsOfType("using_directive")){let a=o.namedChildren;if(a.length===0)continue;let r=null,l=null;if(a.length>=2&&a[0].type==="identifier"&&(a[1].type==="qualified_name"||a[1].type==="identifier")?(r=a[0],l=a[1]):l=a[a.length-1],!l)continue;let c=l.text,m=c.split(".").pop()??c,u=r?.text??m;s.push({importedName:m,localName:u,sourcePath:H(e,c,Ge),kind:r?"namespace":"named",used:i.has(u),usedMembers:[]})}return s}function ls(e,n,t){let i=$(e,n),s=T(n);if(i&&s==="java")return vl(e,n,i);if(i&&s==="kotlin")return El(e,n,i);if(i&&s==="scala")return Ll(e,n,i);let o=[];for(let a of t.matchAll(/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm)){let r=a[1]?.trim(),l=a[0];if(!r||!l||typeof a.index!="number")continue;let c=q(t,a.index,a.index+l.length);o.push(...Rl(e,n,r,c))}return o}function vl(e,n,t){let i=J(t,new Set(["import_declaration"])),s=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.children.some(u=>u.type==="asterisk"),l=o.namedChildren.find(u=>u.type==="scoped_identifier")??o.namedChildren.find(u=>u.type==="identifier");if(!l)continue;let c=l.text;if(a){s.push({importedName:"*",localName:null,sourcePath:H(e,c,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let m=c.split(".").pop()??c;s.push({importedName:m,localName:m,sourcePath:H(e,c,ce),kind:"named",used:i.has(m),usedMembers:[]})}return s}function El(e,n,t){let i=J(t,new Set(["import_header","import_list"])),s=[];for(let o of t.rootNode.descendantsOfType("import_header")){let a=o.namedChildren.find(f=>f.type==="identifier");if(!a)continue;let r=o.namedChildren.some(f=>f.type==="wildcard_import"),l=o.namedChildren.find(f=>f.type==="import_alias");if(r){s.push({importedName:"*",localName:null,sourcePath:H(e,a.text,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let c=a.text,m=c.split(".").pop()??c,d=l?.namedChild(0)?.text??m;s.push({importedName:m,localName:d,sourcePath:H(e,c,ce),kind:"named",used:i.has(d),usedMembers:[]})}return s}function Ll(e,n,t){let i=J(t,new Set(["import_declaration"])),s=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.namedChildren.find(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),r=o.namedChildren.filter(u=>u!==a&&(u.type==="identifier"||u.type==="stable_identifier")),l=r.map(u=>u.text).join(".");if(!l)continue;if(a?.type==="namespace_wildcard"){s.push({importedName:"*",localName:null,sourcePath:H(e,l,ce),kind:"namespace",used:!0,usedMembers:[]});continue}if(a?.type==="namespace_selectors"){for(let u of a.namedChildren)if(u.type==="arrow_renamed_identifier"){let[d,f]=u.namedChildren;if(!d)continue;let p=d.text,g=f?.text??p;if(p==="_")continue;s.push({importedName:p,localName:g,sourcePath:H(e,`${l}.${p}`,ce),kind:"named",used:i.has(g),usedMembers:[]})}else if(u.type==="identifier"){let d=u.text;s.push({importedName:d,localName:d,sourcePath:H(e,`${l}.${d}`,ce),kind:"named",used:i.has(d),usedMembers:[]})}continue}let c=r[r.length-1]?.text??l,m=r.slice(0,-1).map(u=>u.text).join(".")||l;s.push({importedName:c,localName:c,sourcePath:H(e,m&&r.length>1?`${m}.${c}`:l,ce),kind:"named",used:i.has(c),usedMembers:[]})}return s}function Rl(e,n,t,i){if(t.includes("{")&&t.includes("}")){let s=t.slice(0,t.indexOf("{")).replace(/\.$/,"").trim(),o=t.slice(t.indexOf("{")+1,t.lastIndexOf("}")).trim();return ie(o).flatMap(a=>{let r=a.trim();if(!r)return[];let[l,c]=r.includes("=>")?r.split(/\s*=>\s*/):r.split(/\s+as\s+/),m=l?.trim();if(!m||m==="_")return[];let u=(c??m.split(".").pop()??m).trim(),d=m==="_"?s:`${s}.${m}`.replace(/\.\./g,".");return[pe(e,n,i,d,m,u)]})}return[pe(e,n,i,t,t.split(".").pop()??t,t.split(".").pop()??t)]}function ms(e,n,t){let i=$(e,n);if(i)return Dl(e,n,i);let s=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=q(t,o.index,o.index+r.length);for(let c of ie(a)){let m=c.trim();if(!m)continue;let[u,d]=m.split(/\s+as\s+/i),f=u?.trim()??m,p=f.split("\\").pop()??f,g=(d??p).trim();s.push(pe(e,n,l,f,p,g,H(e,f.replace(/\\/g,"."),ot)))}}return s}function Dl(e,n,t){let i=J(t,new Set(["namespace_use_declaration"])),s=[],o=(a,r,l)=>{s.push({importedName:r,localName:l,sourcePath:H(e,a.replace(/\\/g,"."),ot),kind:"named",used:i.has(l),usedMembers:[]})};for(let a of t.rootNode.descendantsOfType("namespace_use_declaration")){let r=a.namedChildren.find(l=>l.type==="namespace_use_group");if(r){let l=a.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of r.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:m,localName:u,qualified:d}=cs(c,l);m&&o(d,m,u)}continue}for(let l of a.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:m,qualified:u}=cs(l,"");c&&o(u,c,m)}}return s}function cs(e,n){let t=e.namedChildren.find(c=>c.type==="qualified_name"),i=e.namedChildren.filter(c=>c.type==="name"),s="";t?s=t.text:i.length>=1&&(s=i[0].text);let o=t&&i.length>0?i[i.length-1]:null,a=s.split("\\").pop()??s,r=o?.text??a,l=n?`${n}\\${s}`:s;return{importedName:a,localName:r,qualified:l}}function ps(e,n,t){let i=$(e,n);return i?wl(e,n,i):$l(t).flatMap(s=>Pl(e,n,s,t))}function wl(e,n,t){let i=J(t,new Set(["import_statement","import_from_statement"])),s=[];for(let o of t.rootNode.descendantsOfType("import_statement"))for(let a of o.namedChildren){let r=us(a);if(!r)continue;let l=Ye(e,n,r.qualifiedName);s.push({importedName:r.qualifiedName,localName:r.localName,sourcePath:l,kind:"namespace",used:i.has(r.localName),usedMembers:[]})}for(let o of t.rootNode.descendantsOfType("import_from_statement")){let a=o.namedChild(0);if(!a)continue;let r=Ol(a);if(r===null)continue;let l=Ye(e,n,r);for(let c=1;c<o.namedChildCount;c+=1){let m=o.namedChild(c);if(m.type==="wildcard_import"){s.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=us(m);u&&s.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:i.has(u.localName),usedMembers:[]})}}return s}function us(e){if(e.type==="aliased_import"){let n=e.namedChild(0),t=e.namedChild(1);return!n||!t?null:{qualifiedName:n.text,localName:t.text}}if(e.type==="dotted_name"){let n=e.text;return{qualifiedName:n,localName:n.split(".")[0]??n}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function Ol(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let n=re(e,"import_prefix")?.text??"",t=re(e,"dotted_name")?.text??"";return`${n}${t}`}return null}function $l(e){let n=e.split(`
266
- `),t=[],i=0;for(let s=0;s<n.length;s++){let o=n[s],a=o.trimStart(),r=i;if(i+=o.length+1,!a.startsWith("import ")&&!a.startsWith("from "))continue;let l=o,c=r+o.length,m=ds(o);for(;s+1<n.length&&(m>0||l.trimEnd().endsWith("\\"));){s++;let d=n[s];l+=`
267
- ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,end:c})}return t}function kl(e){let n=e.replace(/\\\s*\n/g," ").trim();if(n.startsWith("import "))return{kind:"import",module:null,clause:n.slice(7).trim()};let t=n.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!t)return null;let i=t[2].trim();return i.startsWith("(")&&i.endsWith(")")&&(i=i.slice(1,-1).trim()),{kind:"from",module:t[1],clause:i}}function Pl(e,n,t,i){let s=q(i,t.start,t.end),o=t.clause.replace(/\n/g," ").trim();if(t.kind==="import")return ie(o).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[m,u]=c.split(/\s+as\s+/),d=m.trim(),f=(u??d.split(".")[0]??d).trim(),p=Ye(e,n,d),g=qe(s,f);return[{importedName:d,localName:f,sourcePath:p,kind:"namespace",used:X(s,f)||g.length>0,usedMembers:g}]});let a=t.module?Ye(e,n,t.module):null,r=[];for(let l of ie(o)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){r.push({importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]});continue}let[m,u]=c.split(/\s+as\s+/),d=(u??m).trim();r.push({importedName:m.trim(),localName:d,sourcePath:a,kind:"named",used:X(s,d),usedMembers:[]})}return r}function ds(e){let n=0;for(let t of e)t==="("&&n++,t===")"&&n--;return n}import{basename as Ml}from"path";function fs(e,n,t){let i=$(e,n);if(i)return Fl(e,n,i);let s=[];for(let o of t.matchAll(/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm)){let a=o[1],r=o[2],l=o[0];if(!a||!r||!l||typeof o.index!="number")continue;let c=q(t,o.index,o.index+l.length),m=a==="require_relative"?Mt(e,n,r):null;if(m){let u=gs(r);s.push({importedName:u,localName:u,sourcePath:m,kind:"named",used:X(c,u),usedMembers:[]});continue}s.push({importedName:r,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return s}function Fl(e,n,t){let i=J(t,new Set([])),s=[],o=new Set(["require","require_relative","load"]);for(let a of t.rootNode.descendantsOfType("call")){let r=a.namedChild(0);if(!r||r.type!=="identifier"||!o.has(r.text))continue;let c=a.namedChildren.find(f=>f.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(f=>f.type==="string_content")?.text;if(!u)continue;let d=r.text==="require_relative"?Mt(e,n,u):null;if(d){let f=gs(u);s.push({importedName:f,localName:f,sourcePath:d,kind:"named",used:i.has(f),usedMembers:[]})}else s.push({importedName:u,localName:null,sourcePath:d,kind:"side-effect",used:!0,usedMembers:[]})}return s}function gs(e){return Ml(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function hs(e,n,t){let i=$(e,n);if(i)return Tl(e,n,i);let s=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=q(t,o.index,o.index+r.length);s.push(...Al(e,n,a,l))}return s}function Tl(e,n,t){let i=J(t,new Set(["use_declaration"])),s=[];for(let o of t.rootNode.descendantsOfType("use_declaration")){let a=o.namedChild(0);if(a)for(let r of rt(a,"")){if(!r.importedName||r.importedName==="*")continue;let l=xe(e,n,r.qualifiedName)??xe(e,n,r.qualifiedName.split("::").slice(0,-1).join("::"));s.push({importedName:r.importedName,localName:r.localName,sourcePath:l,kind:"named",used:i.has(r.localName),usedMembers:[]})}}return s}function rt(e,n){switch(e.type){case"identifier":case"super":case"self":case"crate":{let t=e.text;return[{qualifiedName:At(n,t),importedName:t,localName:t}]}case"scoped_identifier":{let t=e.text,i=t.split("::").pop()??t;return[{qualifiedName:At(n,t),importedName:i,localName:i}]}case"scoped_use_list":{let t=e.namedChild(0),i=e.namedChild(1);if(!t||!i)return[];let s=At(n,t.text),o=[];for(let a of i.namedChildren)o.push(...rt(a,s));return o}case"use_list":{let t=[];for(let i of e.namedChildren)t.push(...rt(i,n));return t}case"use_as_clause":{let t=e.namedChild(0),i=e.namedChild(1);if(!t||!i)return[];let s=rt(t,n),o=i.text;return s.map(a=>({...a,localName:o}))}case"use_wildcard":{let t=e.namedChild(0),i=t?t.text:"";return[{qualifiedName:At(n,`${i}::*`),importedName:"*",localName:"*"}]}default:return[]}}function At(e,n){return e?n?`${e}::${n}`:e:n}function Al(e,n,t,i){let s=t.trim();if(s.includes("{")&&s.includes("}")){let m=s.slice(0,s.indexOf("{")).replace(/::$/,"").trim(),u=s.slice(s.indexOf("{")+1,s.lastIndexOf("}")).trim();return ie(u).flatMap(d=>{let f=d.trim();if(!f||f==="self")return[];let[p,g]=f.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let h=(g??y.split("::").pop()??y).trim(),b=`${m}::${y}`.replace(/::::/g,"::");return[pe(e,n,i,b,y.split("::").pop()??y,h,xe(e,n,m))]})}let[o,a]=s.split(/\s+as\s+/),r=o?.trim()??s,l=(a??r.split("::").pop()??r).trim(),c=xe(e,n,r)??xe(e,n,r.split("::").slice(0,-1).join("::"));return[pe(e,n,i,r,r.split("::").pop()??r,l,c)]}function ys(e,n,t){let i=$(e,n);if(i)return jl(e,n,i);let s=[];for(let o of t.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim();a&&s.push(...Wl(e,n,a))}return s}function jl(e,n,t){let i=[];for(let s of t.rootNode.descendantsOfType("use_declaration")){if(!Bl(s))continue;let o=s.namedChildren.find(a=>a.type!=="visibility_modifier");if(o)for(let a of rt(o,""))a.importedName&&i.push(Rn(e,n,a.qualifiedName))}return i}function Bl(e){for(let n of e.children)if(n.type==="visibility_modifier"&&n.text.startsWith("pub"))return!0;return!1}function Wl(e,n,t){let i=t.trim();if(i.includes("{")&&i.includes("}")){let s=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),o=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return ie(o).flatMap(a=>{let r=a.trim();if(!r||r==="self")return[];let[l]=r.split(/\s+as\s+/),c=`${s}::${l?.trim()??r}`.replace(/::::/g,"::");return[Rn(e,n,c)]})}return[Rn(e,n,i)]}function Rn(e,n,t){return{specifier:t,sourcePath:xe(e,n,t)??xe(e,n,t.split("::").slice(0,-1).join("::"))}}function bs(e,n){let t=n.toLowerCase();for(let i of e)for(let s of i.extensions)if(t.endsWith(s))return i;return null}var Hl={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:ts},Jl={language:"python",extensions:[".py",".pyi"],parseImports:ps},Ul={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:ls},ql={language:"rust",extensions:[".rs"],parseImports:hs,parseExports:ys},zl={language:"ruby",extensions:[".rb"],parseImports:fs},Gl={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:ss},Yl={language:"dotnet",extensions:[".cs",".vb"],parseImports:as},Kl={language:"dart",extensions:[".dart"],parseImports:os,parseExports:rs},Vl={language:"php",extensions:[".php"],parseImports:ms},Ql=[Hl,Jl,Ul,ql,zl,Gl,Yl,Kl,Vl];function Dn(e){return bs(Ql,e)}function Is(e,n){return ns(e,n)}var Xl=W("source-imports"),Zl=W("source-exports");function me(e,n){let t=oe(n);return Xl.get(e,t,()=>{let i=Dn(t);if(!i)return[];let s=xs(e.config.projectRoot,t);if(!Ss(s))return[];let o=_s(s,"utf-8");return i.parseImports(e,t,o)})}function wn(e,n){let t=oe(n);return Zl.get(e,t,()=>{let i=Dn(t);if(!i?.parseExports)return[];let s=xs(e.config.projectRoot,t);if(!Ss(s))return[];let o=_s(s,"utf-8");return i.parseExports(e,t,o)})}var ec=W("file-dep-graph");function G(e,n){return ec.get(e,n??"",()=>{let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",i=e.all(`SELECT DISTINCT
316
+ ${e.pathExclusionsFor("documents")}`).map(n=>ae(n.relative_path)).filter(n=>!e.isIgnored(n))))}function ae(e){return e.replace(/\\/g,"/")}function oe(e){let n=[],t=0,s=0;for(let i=0;i<e.length;i++){let o=e[i];(o==="{"||o==="["||o==="(")&&t++,(o==="}"||o==="]"||o===")")&&t--,o===","&&t===0&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}function le(e,n){for(let t of e.namedChildren)if(t.type===n)return t;return null}function J(e,n){let t=new Set,s=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]),i=(o,a)=>{let r=a||n.has(o.type);!r&&s.has(o.type)&&t.add(o.text);for(let l of o.children)i(l,r)};return i(e.rootNode,!1),t}function ge(e,n,t,s,i,o,a){return{importedName:i,localName:o,sourcePath:a??H(e,s,Bn(n)),kind:"named",used:te(t,o),usedMembers:[]}}function Li(e,n,t){let s=O(e,n);return s?Ec(e,n,s):wc(t).flatMap(i=>Dc(e,n,i.clause,i.specifier,i.start,i.end,t))}function Ec(e,n,t){let s=J(t,new Set(["import_statement"]));if(mt(n))for(let o of Ac(e,n))s.add(o);let i=[];for(let o of t.rootNode.descendantsOfType("import_statement")){let a=Rc(o);if(!a)continue;let r=He(e,n,a),l=le(o,"import_clause");if(!l){i.push({importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]});continue}for(let c of l.namedChildren)switch(c.type){case"identifier":{let m=c.text;i.push({importedName:"default",localName:m,sourcePath:r,kind:"default",used:s.has(m),usedMembers:[]});break}case"namespace_import":{let u=le(c,"identifier")?.text??"";if(!u)break;let d=Lc(t,u);i.push({importedName:"*",localName:u,sourcePath:r,kind:"namespace",used:d.length>0||s.has(u),usedMembers:d});break}case"named_imports":{for(let m of c.namedChildren){if(m.type!=="import_specifier")continue;let u=m.namedChild(0),d=m.namedChild(1);if(!u)continue;let g=u.text,p=d?.text??g;i.push({importedName:g,localName:p,sourcePath:r,kind:"named",used:s.has(p),usedMembers:[]})}break}}}return i}function Rc(e){let n=le(e,"string");if(!n)return null;let t=le(n,"string_fragment");return t?t.text:null}function Lc(e,n){let t=new Set;for(let s of e.rootNode.descendantsOfType("member_expression")){let i=s.namedChild(0),o=s.namedChild(1);!i||!o||i.type!=="identifier"||i.text!==n||(o.type==="property_identifier"||o.type==="identifier")&&t.add(o.text)}return[...t]}function wc(e){let n=[],t=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(t)){let o=i[0],a=i[1],r=i[2];!o||!r||typeof i.index!="number"||n.push({clause:a,specifier:r,start:i.index,end:i.index+o.length})}let s=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(s)){let o=i[0],a=i[1];!o||!a||typeof i.index!="number"||n.push({clause:null,specifier:a,start:i.index,end:i.index+o.length})}return n.sort((i,o)=>i.start-o.start)}function Dc(e,n,t,s,i,o,a){let r=He(e,n,s),l=z(a,i,o);return t?kc(t).map(m=>({...m,sourcePath:r})).map(m=>{if(m.kind==="namespace"){let u=Ze(l,m.localName);return{...m,used:u.length>0||te(l,m.localName),usedMembers:u}}return m.kind==="side-effect"?{...m,used:!0,usedMembers:[]}:{...m,used:m.localName?te(l,m.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]}]}function kc(e){let n=e.trim().replace(/^type\s+/,""),[t,s]=Oc(n),i=[];return t&&i.push(...Ri(t)),s&&i.push(...Ri(s)),i}function Ri(e){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let t=n.slice(1,-1).trim();return t?oe(t).map(s=>{let i=s.trim().replace(/^type\s+/,""),[o,a]=i.split(/\s+as\s+/);return{importedName:o.trim(),localName:(a??o).trim(),kind:"named"}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace"}]:[{importedName:"default",localName:n,kind:"default"}]}function Oc(e){let n=0;for(let t=0;t<e.length;t++){let s=e[t];if(s==="{"&&n++,s==="}"&&n--,s===","&&n===0)return[e.slice(0,t).trim(),e.slice(t+1).trim()]}return[e.trim(),null]}function wi(e,n){let t=O(e,n);if(t)return Pc(e,n,t);let s=M(e,n);if(!s)return[];let i=[],o=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(o)){if(typeof l.index!="number")continue;let c=l[1]??"",m=l[2]??"",u=oe(c).map(p=>$c(p.trim())).filter(p=>!!p),d=st(s,l.index),g=st(s,l.index+l[0].length-1);i.push({kind:"named",sourcePath:He(e,n,m),names:u,startLine:d,endLine:g})}let a=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(a)){if(typeof l.index!="number")continue;let c=l[2]??"",m=st(s,l.index),u=st(s,l.index+l[0].length-1);i.push({kind:"star-as",sourcePath:He(e,n,c),names:[],startLine:m,endLine:u})}let r=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(r)){if(typeof l.index!="number")continue;let c=l[1]??"",m=st(s,l.index),u=st(s,l.index+l[0].length-1);i.push({kind:"star",sourcePath:He(e,n,c),names:[],startLine:m,endLine:u})}return i}function $c(e){if(!e)return null;let n=e.replace(/^type\s+/,"").trim();if(!n)return null;let t=n.match(/^(\w+)\s+as\s+(\w+)$/);if(t)return t[2]??null;let s=n.match(/^(\w+)$/);return s?s[1]??null:null}function st(e,n){let t=0;for(let s=0;s<n&&s<e.length;s++)e.charCodeAt(s)===10&&t++;return t}function Pc(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("export_statement")){let o=Mc(e,n,i);if(o===void 0)continue;let a=i.startPosition.row,r=i.endPosition.row,l=Fc(i,o,a,r);s.push(l)}return s}function Mc(e,n,t){let s=le(t,"string");if(!s)return;let i=le(s,"string_fragment");if(i)return He(e,n,i.text)}function Fc(e,n,t,s){let i=le(e,"export_clause");if(i){let a=[];for(let r of i.namedChildren){if(r.type!=="export_specifier")continue;let l=r.namedChild(0),c=r.namedChild(1);l&&a.push((c??l).text)}return{kind:"named",sourcePath:n,names:a,startLine:t,endLine:s}}return le(e,"namespace_export")?{kind:"star-as",sourcePath:n,names:[],startLine:t,endLine:s}:{kind:"star",sourcePath:n,names:[],startLine:t,endLine:s}}var Tc=W("vue-non-script-identifiers");function Ac(e,n){return Tc.get(e,n,()=>{let t=new Set,s=M(e,n);if(!s)return t;let o=s.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,a=>a.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,a=>a.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,a=>a.replace(/[^\r\n]/g," "));for(let a of o.matchAll(/[A-Za-z_$][\w$]*/g))t.add(a[0]);return t})}import{basename as Di}from"path";function ki(e,n,t){let s=O(e,n);if(s)return jc(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length),c=Di(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:c,sourcePath:Qt(e,n,a),kind:"named",used:te(l,c),usedMembers:[]})}return i}function jc(e,n,t){let s=J(t,new Set(["preproc_include"])),i=[];for(let o of t.rootNode.descendantsOfType("preproc_include")){let a=null;for(let l of o.namedChildren){if(l.type==="system_lib_string"){a=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){a=l.namedChildren.find(m=>m.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!a)continue;let r=Di(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:r,sourcePath:Qt(e,n,a),kind:"named",used:s.has(r),usedMembers:[]})}return i}function Oi(e,n,t){let s=[];for(let i of t.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let o=i[1]?.trim(),a=i[2]?.trim()??null,r=i[0];if(!o||!r||typeof i.index!="number")continue;let l=z(t,i.index,i.index+r.length);s.push({importedName:o,localName:a,sourcePath:Xt(e,n,o),kind:a?"namespace":"side-effect",used:a?te(l,a):!0,usedMembers:a?Ze(l,a):[]})}return s}function $i(e,n,t){let s=[];for(let i of t.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let o=i[1]?.trim();o&&s.push({specifier:o,sourcePath:Xt(e,n,o)})}return s}function Pi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="csharp")return Wc(e,n,s);if(s&&i==="vb")return Bc(e,n,s);let o=[],a=Ei(n)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;for(let r of t.matchAll(a)){let l=r[1]?.trim(),c=r[0];if(!l||!c||typeof r.index!="number")continue;let m=z(t,r.index,r.index+c.length),[u,d]=l.split(/\s*=\s*/),g=!!d,p=(g?d:u)?.trim()??l,f=p.split(".").pop()??p,y=g?u?.trim()??f:f;o.push(ge(e,n,m,p,f,y,H(e,p,tt)))}return o}function Bc(e,n,t){let s=J(t,new Set(["imports_statement"])),i=[];for(let o of t.rootNode.descendantsOfType("imports_statement")){let a=o.namedChildren.filter(d=>d.type==="namespace_name");if(a.length===0)continue;let r=a[a.length-1],l=a.length>1?a[0]:null,c=r.text,m=c.split(".").pop()??c,u=l?.text??m;i.push({importedName:m,localName:u,sourcePath:H(e,c,tt),kind:l?"namespace":"named",used:s.has(u),usedMembers:[]})}return i}function Wc(e,n,t){let s=J(t,new Set(["using_directive"])),i=[];for(let o of t.rootNode.descendantsOfType("using_directive")){let a=o.namedChildren;if(a.length===0)continue;let r=null,l=null;if(a.length>=2&&a[0].type==="identifier"&&(a[1].type==="qualified_name"||a[1].type==="identifier")?(r=a[0],l=a[1]):l=a[a.length-1],!l)continue;let c=l.text,m=c.split(".").pop()??c,u=r?.text??m;i.push({importedName:m,localName:u,sourcePath:H(e,c,tt),kind:r?"namespace":"named",used:s.has(u),usedMembers:[]})}return i}function Mi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="java")return Hc(e,n,s);if(s&&i==="kotlin")return Jc(e,n,s);if(s&&i==="scala")return Uc(e,n,s);let o=[];for(let a of t.matchAll(/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm)){let r=a[1]?.trim(),l=a[0];if(!r||!l||typeof a.index!="number")continue;let c=z(t,a.index,a.index+l.length);o.push(...qc(e,n,r,c))}return o}function Hc(e,n,t){let s=J(t,new Set(["import_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.children.some(u=>u.type==="asterisk"),l=o.namedChildren.find(u=>u.type==="scoped_identifier")??o.namedChildren.find(u=>u.type==="identifier");if(!l)continue;let c=l.text;if(a){i.push({importedName:"*",localName:null,sourcePath:H(e,c,me),kind:"namespace",used:!0,usedMembers:[]});continue}let m=c.split(".").pop()??c;i.push({importedName:m,localName:m,sourcePath:H(e,c,me),kind:"named",used:s.has(m),usedMembers:[]})}return i}function Jc(e,n,t){let s=J(t,new Set(["import_header","import_list"])),i=[];for(let o of t.rootNode.descendantsOfType("import_header")){let a=o.namedChildren.find(g=>g.type==="identifier");if(!a)continue;let r=o.namedChildren.some(g=>g.type==="wildcard_import"),l=o.namedChildren.find(g=>g.type==="import_alias");if(r){i.push({importedName:"*",localName:null,sourcePath:H(e,a.text,me),kind:"namespace",used:!0,usedMembers:[]});continue}let c=a.text,m=c.split(".").pop()??c,d=l?.namedChild(0)?.text??m;i.push({importedName:m,localName:d,sourcePath:H(e,c,me),kind:"named",used:s.has(d),usedMembers:[]})}return i}function Uc(e,n,t){let s=J(t,new Set(["import_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.namedChildren.find(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),r=o.namedChildren.filter(u=>u!==a&&(u.type==="identifier"||u.type==="stable_identifier")),l=r.map(u=>u.text).join(".");if(!l)continue;if(a?.type==="namespace_wildcard"){i.push({importedName:"*",localName:null,sourcePath:H(e,l,me),kind:"namespace",used:!0,usedMembers:[]});continue}if(a?.type==="namespace_selectors"){for(let u of a.namedChildren)if(u.type==="arrow_renamed_identifier"){let[d,g]=u.namedChildren;if(!d)continue;let p=d.text,f=g?.text??p;if(p==="_")continue;i.push({importedName:p,localName:f,sourcePath:H(e,`${l}.${p}`,me),kind:"named",used:s.has(f),usedMembers:[]})}else if(u.type==="identifier"){let d=u.text;i.push({importedName:d,localName:d,sourcePath:H(e,`${l}.${d}`,me),kind:"named",used:s.has(d),usedMembers:[]})}continue}let c=r[r.length-1]?.text??l,m=r.slice(0,-1).map(u=>u.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:H(e,m&&r.length>1?`${m}.${c}`:l,me),kind:"named",used:s.has(c),usedMembers:[]})}return i}function qc(e,n,t,s){if(t.includes("{")&&t.includes("}")){let i=t.slice(0,t.indexOf("{")).replace(/\.$/,"").trim(),o=t.slice(t.indexOf("{")+1,t.lastIndexOf("}")).trim();return oe(o).flatMap(a=>{let r=a.trim();if(!r)return[];let[l,c]=r.includes("=>")?r.split(/\s*=>\s*/):r.split(/\s+as\s+/),m=l?.trim();if(!m||m==="_")return[];let u=(c??m.split(".").pop()??m).trim(),d=m==="_"?i:`${i}.${m}`.replace(/\.\./g,".");return[ge(e,n,s,d,m,u)]})}return[ge(e,n,s,t,t.split(".").pop()??t,t.split(".").pop()??t)]}function Ti(e,n,t){let s=O(e,n);if(s)return zc(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length);for(let c of oe(a)){let m=c.trim();if(!m)continue;let[u,d]=m.split(/\s+as\s+/i),g=u?.trim()??m,p=g.split("\\").pop()??g,f=(d??p).trim();i.push(ge(e,n,l,g,p,f,H(e,g.replace(/\\/g,"."),gt)))}}return i}function zc(e,n,t){let s=J(t,new Set(["namespace_use_declaration"])),i=[],o=(a,r,l)=>{i.push({importedName:r,localName:l,sourcePath:H(e,a.replace(/\\/g,"."),gt),kind:"named",used:s.has(l),usedMembers:[]})};for(let a of t.rootNode.descendantsOfType("namespace_use_declaration")){let r=a.namedChildren.find(l=>l.type==="namespace_use_group");if(r){let l=a.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of r.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:m,localName:u,qualified:d}=Fi(c,l);m&&o(d,m,u)}continue}for(let l of a.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:m,qualified:u}=Fi(l,"");c&&o(u,c,m)}}return i}function Fi(e,n){let t=e.namedChildren.find(c=>c.type==="qualified_name"),s=e.namedChildren.filter(c=>c.type==="name"),i="";t?i=t.text:s.length>=1&&(i=s[0].text);let o=t&&s.length>0?s[s.length-1]:null,a=i.split("\\").pop()??i,r=o?.text??a,l=n?`${n}\\${i}`:i;return{importedName:a,localName:r,qualified:l}}function Bi(e,n,t){let s=O(e,n);return s?Vc(e,n,s):Yc(t).flatMap(i=>Qc(e,n,i,t))}function Vc(e,n,t){let s=J(t,new Set(["import_statement","import_from_statement"])),i=[];for(let o of t.rootNode.descendantsOfType("import_statement"))for(let a of o.namedChildren){let r=Ai(a);if(!r)continue;let l=nt(e,n,r.qualifiedName);i.push({importedName:r.qualifiedName,localName:r.localName,sourcePath:l,kind:"namespace",used:s.has(r.localName),usedMembers:[]})}for(let o of t.rootNode.descendantsOfType("import_from_statement")){let a=o.namedChild(0);if(!a)continue;let r=Gc(a);if(r===null)continue;let l=nt(e,n,r);for(let c=1;c<o.namedChildCount;c+=1){let m=o.namedChild(c);if(m.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=Ai(m);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:s.has(u.localName),usedMembers:[]})}}return i}function Ai(e){if(e.type==="aliased_import"){let n=e.namedChild(0),t=e.namedChild(1);return!n||!t?null:{qualifiedName:n.text,localName:t.text}}if(e.type==="dotted_name"){let n=e.text;return{qualifiedName:n,localName:n.split(".")[0]??n}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function Gc(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let n=le(e,"import_prefix")?.text??"",t=le(e,"dotted_name")?.text??"";return`${n}${t}`}return null}function Yc(e){let n=e.split(`
317
+ `),t=[],s=0;for(let i=0;i<n.length;i++){let o=n[i],a=o.trimStart(),r=s;if(s+=o.length+1,!a.startsWith("import ")&&!a.startsWith("from "))continue;let l=o,c=r+o.length,m=ji(o);for(;i+1<n.length&&(m>0||l.trimEnd().endsWith("\\"));){i++;let d=n[i];l+=`
318
+ ${d}`,c+=1+d.length,m+=ji(d),s+=d.length+1}let u=Kc(l);u&&t.push({...u,start:r,end:c})}return t}function Kc(e){let n=e.replace(/\\\s*\n/g," ").trim();if(n.startsWith("import "))return{kind:"import",module:null,clause:n.slice(7).trim()};let t=n.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!t)return null;let s=t[2].trim();return s.startsWith("(")&&s.endsWith(")")&&(s=s.slice(1,-1).trim()),{kind:"from",module:t[1],clause:s}}function Qc(e,n,t,s){let i=z(s,t.start,t.end),o=t.clause.replace(/\n/g," ").trim();if(t.kind==="import")return oe(o).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[m,u]=c.split(/\s+as\s+/),d=m.trim(),g=(u??d.split(".")[0]??d).trim(),p=nt(e,n,d),f=Ze(i,g);return[{importedName:d,localName:g,sourcePath:p,kind:"namespace",used:te(i,g)||f.length>0,usedMembers:f}]});let a=t.module?nt(e,n,t.module):null,r=[];for(let l of oe(o)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){r.push({importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]});continue}let[m,u]=c.split(/\s+as\s+/),d=(u??m).trim();r.push({importedName:m.trim(),localName:d,sourcePath:a,kind:"named",used:te(i,d),usedMembers:[]})}return r}function ji(e){let n=0;for(let t of e)t==="("&&n++,t===")"&&n--;return n}import{basename as Xc}from"path";function Wi(e,n,t){let s=O(e,n);if(s)return Zc(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm)){let a=o[1],r=o[2],l=o[0];if(!a||!r||!l||typeof o.index!="number")continue;let c=z(t,o.index,o.index+l.length),m=a==="require_relative"?Kt(e,n,r):null;if(m){let u=Hi(r);i.push({importedName:u,localName:u,sourcePath:m,kind:"named",used:te(c,u),usedMembers:[]});continue}i.push({importedName:r,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function Zc(e,n,t){let s=J(t,new Set([])),i=[],o=new Set(["require","require_relative","load"]);for(let a of t.rootNode.descendantsOfType("call")){let r=a.namedChild(0);if(!r||r.type!=="identifier"||!o.has(r.text))continue;let c=a.namedChildren.find(g=>g.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(g=>g.type==="string_content")?.text;if(!u)continue;let d=r.text==="require_relative"?Kt(e,n,u):null;if(d){let g=Hi(u);i.push({importedName:g,localName:g,sourcePath:d,kind:"named",used:s.has(g),usedMembers:[]})}else i.push({importedName:u,localName:null,sourcePath:d,kind:"side-effect",used:!0,usedMembers:[]})}return i}function Hi(e){return Xc(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function Ji(e,n,t){let s=O(e,n);if(s)return eu(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length);i.push(...tu(e,n,a,l))}return i}function eu(e,n,t){let s=J(t,new Set(["use_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("use_declaration")){let a=o.namedChild(0);if(a)for(let r of ht(a,"")){if(!r.importedName||r.importedName==="*")continue;let l=Ne(e,n,r.qualifiedName)??Ne(e,n,r.qualifiedName.split("::").slice(0,-1).join("::"));i.push({importedName:r.importedName,localName:r.localName,sourcePath:l,kind:"named",used:s.has(r.localName),usedMembers:[]})}}return i}function ht(e,n){switch(e.type){case"identifier":case"super":case"self":case"crate":{let t=e.text;return[{qualifiedName:Zt(n,t),importedName:t,localName:t}]}case"scoped_identifier":{let t=e.text,s=t.split("::").pop()??t;return[{qualifiedName:Zt(n,t),importedName:s,localName:s}]}case"scoped_use_list":{let t=e.namedChild(0),s=e.namedChild(1);if(!t||!s)return[];let i=Zt(n,t.text),o=[];for(let a of s.namedChildren)o.push(...ht(a,i));return o}case"use_list":{let t=[];for(let s of e.namedChildren)t.push(...ht(s,n));return t}case"use_as_clause":{let t=e.namedChild(0),s=e.namedChild(1);if(!t||!s)return[];let i=ht(t,n),o=s.text;return i.map(a=>({...a,localName:o}))}case"use_wildcard":{let t=e.namedChild(0),s=t?t.text:"";return[{qualifiedName:Zt(n,`${s}::*`),importedName:"*",localName:"*"}]}default:return[]}}function Zt(e,n){return e?n?`${e}::${n}`:e:n}function tu(e,n,t,s){let i=t.trim();if(i.includes("{")&&i.includes("}")){let m=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),u=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return oe(u).flatMap(d=>{let g=d.trim();if(!g||g==="self")return[];let[p,f]=g.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let h=(f??y.split("::").pop()??y).trim(),b=`${m}::${y}`.replace(/::::/g,"::");return[ge(e,n,s,b,y.split("::").pop()??y,h,Ne(e,n,m))]})}let[o,a]=i.split(/\s+as\s+/),r=o?.trim()??i,l=(a??r.split("::").pop()??r).trim(),c=Ne(e,n,r)??Ne(e,n,r.split("::").slice(0,-1).join("::"));return[ge(e,n,s,r,r.split("::").pop()??r,l,c)]}function Ui(e,n,t){let s=O(e,n);if(s)return nu(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim();a&&i.push(...iu(e,n,a))}return i}function nu(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("use_declaration")){if(!su(i))continue;let o=i.namedChildren.find(a=>a.type!=="visibility_modifier");if(o)for(let a of ht(o,""))a.importedName&&s.push(Wn(e,n,a.qualifiedName))}return s}function su(e){for(let n of e.children)if(n.type==="visibility_modifier"&&n.text.startsWith("pub"))return!0;return!1}function iu(e,n,t){let s=t.trim();if(s.includes("{")&&s.includes("}")){let i=s.slice(0,s.indexOf("{")).replace(/::$/,"").trim(),o=s.slice(s.indexOf("{")+1,s.lastIndexOf("}")).trim();return oe(o).flatMap(a=>{let r=a.trim();if(!r||r==="self")return[];let[l]=r.split(/\s+as\s+/),c=`${i}::${l?.trim()??r}`.replace(/::::/g,"::");return[Wn(e,n,c)]})}return[Wn(e,n,s)]}function Wn(e,n,t){return{specifier:t,sourcePath:Ne(e,n,t)??Ne(e,n,t.split("::").slice(0,-1).join("::"))}}function qi(e,n){let t=n.toLowerCase();for(let s of e)for(let i of s.extensions)if(t.endsWith(i))return s;return null}var ou={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Li},ru={language:"python",extensions:[".py",".pyi"],parseImports:Bi},au={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:Mi},lu={language:"rust",extensions:[".rs"],parseImports:Ji,parseExports:Ui},cu={language:"ruby",extensions:[".rb"],parseImports:Wi},uu={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:ki},mu={language:"dotnet",extensions:[".cs",".vb"],parseImports:Pi},du={language:"dart",extensions:[".dart"],parseImports:Oi,parseExports:$i},pu={language:"php",extensions:[".php"],parseImports:Ti},fu=[ou,ru,au,lu,cu,uu,mu,du,pu];function Hn(e){return qi(fu,e)}function Yi(e,n){return wi(e,n)}var gu=W("source-imports"),hu=W("source-exports");function de(e,n){let t=ae(n);return gu.get(e,t,()=>{let s=Hn(t);if(!s)return[];let i=Gi(e.config.projectRoot,t);if(!zi(i))return[];let o=Vi(i,"utf-8");return s.parseImports(e,t,o)})}function Jn(e,n){let t=ae(n);return hu.get(e,t,()=>{let s=Hn(t);if(!s?.parseExports)return[];let i=Gi(e.config.projectRoot,t);if(!zi(i))return[];let o=Vi(i,"utf-8");return s.parseExports(e,t,o)})}var yu=W("file-dep-graph");function K(e,n){return yu.get(e,n??"",()=>{let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",s=e.all(`SELECT DISTINCT
268
319
  d1.relative_path AS from_file,
269
320
  d2.relative_path AS to_file
270
321
  FROM mentions m
@@ -282,18 +333,18 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
282
333
  WHERE d1.id != d2.id
283
334
  AND m.role != 1
284
335
  ${e.pathExclusionsFor("d1","d2")}
285
- ${t}`),s=new Map,o=new Set(e.all(`SELECT relative_path
336
+ ${t}`),i=new Map,o=new Set(e.all(`SELECT relative_path
286
337
  FROM documents
287
338
  WHERE 1 = 1
288
339
  ${e.pathExclusionsFor("documents")}
289
- ORDER BY relative_path`).map(r=>r.relative_path).filter(r=>!e.isIgnored(r))),a=(r,l)=>{r!==l&&(e.isIgnored(r)||e.isIgnored(l)||o.has(l)&&(s.has(r)||s.set(r,new Set),s.get(r).add(l)))};for(let r of i)a(r.from_file,r.to_file);for(let r of o)if(!(n&&!r.includes(n)))for(let l of me(e,r))l.sourcePath&&a(r,l.sourcePath);return s})}function Z(e,n,t={}){let s=ee(e,[n]).get(n.symbolId)??[];return typeof t.limit=="number"?s.slice(0,t.limit):s}function fe(e,n,t={}){let s=nc(e).get(n.symbolId)??[];return typeof t.limit=="number"?s.slice(0,t.limit):s}var tc=Pe("caller-rows");function nc(e){return tc.get(e,()=>{let n=V(e),t=ee(e,n),i=new Map;for(let a of n)i.set(a.symbol,a.symbolId);let s=new Map,o=new Map;for(let a of n){let r=t.get(a.symbolId);if(!(!r||r.length===0))for(let l of r){let c=i.get(l.symbol);if(c===void 0||c===a.symbolId)continue;let m=s.get(c);m||(m=[],s.set(c,m),o.set(c,new Set));let u=`${a.symbol}|${a.relativePath}`;o.get(c).has(u)||(o.get(c).add(u),m.push({symbol:a.symbol,file:a.relativePath}))}}return s})}function Re(e,n){let t=sc(e,n);return t?oc(e,ic(e,t.match,t.identifier)):[]}function ic(e,n,t){let i=e.all(`SELECT DISTINCT d.relative_path, c.start_line, c.end_line
340
+ ORDER BY relative_path`).map(r=>r.relative_path).filter(r=>!e.isIgnored(r))),a=(r,l)=>{r!==l&&(e.isIgnored(r)||e.isIgnored(l)||o.has(l)&&(i.has(r)||i.set(r,new Set),i.get(r).add(l)))};for(let r of s)a(r.from_file,r.to_file);for(let r of o)if(!(n&&!r.includes(n)))for(let l of de(e,r))l.sourcePath&&a(r,l.sourcePath);return i})}function ne(e,n,t={}){let i=se(e,[n]).get(n.symbolId)??[];return typeof t.limit=="number"?i.slice(0,t.limit):i}function he(e,n,t={}){let i=Su(e).get(n.symbolId)??[];return typeof t.limit=="number"?i.slice(0,t.limit):i}var bu=je("caller-rows");function Su(e){return bu.get(e,()=>{let n=Z(e),t=se(e,n),s=new Map;for(let a of n)s.set(a.symbol,a.symbolId);let i=new Map,o=new Map;for(let a of n){let r=t.get(a.symbolId);if(!(!r||r.length===0))for(let l of r){let c=s.get(l.symbol);if(c===void 0||c===a.symbolId)continue;let m=i.get(c);m||(m=[],i.set(c,m),o.set(c,new Set));let u=`${a.symbol}|${a.relativePath}`;o.get(c).has(u)||(o.get(c).add(u),m.push({symbol:a.symbol,file:a.relativePath}))}}return i})}function $e(e,n){let t=xu(e,n);return t?Iu(e,_u(e,t.match,t.identifier)):[]}function _u(e,n,t){let s=e.all(`SELECT DISTINCT d.relative_path, c.start_line, c.end_line
290
341
  FROM mentions m
291
342
  JOIN chunks c ON m.chunk_id = c.id
292
343
  JOIN documents d ON c.document_id = d.id
293
344
  WHERE m.symbol_id = ?
294
345
  AND m.role != 1
295
346
  ${e.pathExclusionsFor("d")}
296
- ORDER BY d.relative_path, c.start_line`,n.symbolId),s=new Map;for(let a of i){if(e.isIgnored(a.relative_path))continue;let r=s.get(a.relative_path);r||(r=[],s.set(a.relative_path,r)),r.push({start_line:a.start_line,end_line:a.end_line})}let o=new Map;for(let[a,r]of s){let l=a===n.relativePath?{excludeStartLine:n.startLine,excludeEndLine:n.endLine}:{},c=t?kt(e,a,t,l):[],m=[];for(let u of r){let d=c.filter(p=>p>=u.start_line&&p<=u.end_line),f=d.length>0?d:[u.start_line];for(let p of f)m.push(p)}o.set(a,m)}return o}function sc(e,n){let t=wt(e,n);return t?{match:t,identifier:M(t.symbol)||null}:null}function oc(e,n){let t=[],i=new Set;for(let[s,o]of n){let a=A(e,s);for(let r of o){let l=de(a,r),c=`${s}|${r}|${l?.symbol??""}`;i.has(c)||(i.add(c),t.push({file:s,line:r,enclosingSymbol:l?.symbol??null}))}}return t}function ee(e,n,t={}){if(n.length===0)return new Map;let i=t.additive??!1,s=[],o=[];for(let c of n)T(c.relativePath)&&Lt(e,c.relativePath)!==null?s.push(c):o.push(c);let a=new Map,r=c=>{for(let[m,u]of c){let d=a.get(m);d||(d=[],a.set(m,d));let f=new Set(d.map(p=>`${p.symbol}|${p.chunkId}`));for(let p of u){let g=`${p.symbol}|${p.chunkId}`;f.has(g)||(f.add(g),d.push(p))}}};s.length>0&&r(rc(e,s));let l=i?n:o;return l.length>0&&r(lc(e,l)),a}function rc(e,n){let t=new Map,i=new Map;for(let o of n){let a=i.get(o.relativePath);a?a.push(o):i.set(o.relativePath,[o]),t.set(o.symbolId,[])}let s=jt(e);for(let[o,a]of i){let r=Lt(e,o);if(!r)continue;let l=[...a].sort((c,m)=>{let u=c.endLine-c.startLine,d=m.endLine-m.startLine;return u-d});for(let c of r){let m=null;for(let g of l)if(c.line>=g.startLine&&c.line<=g.endLine){m=g;break}if(!m)continue;let u=s.get(c.calleeLeaf);if(!u||u.length===0)continue;let d=null,f=u.find(g=>g.file===o);if(f?d=f:u.length===1&&(d=u[0]),!d||d.symbol===m.symbol)continue;t.get(m.symbolId).push({symbol:d.symbol,file:d.file,chunkId:c.line})}}return t}var ac=Pe("global-leaf-index");function jt(e){return ac.get(e,()=>{let n=e.all(`SELECT gs.id, gs.symbol,
347
+ ORDER BY d.relative_path, c.start_line`,n.symbolId),i=new Map;for(let a of s){if(e.isIgnored(a.relative_path))continue;let r=i.get(a.relative_path);r||(r=[],i.set(a.relative_path,r)),r.push({start_line:a.start_line,end_line:a.end_line})}let o=new Map;for(let[a,r]of i){let l=a===n.relativePath?{excludeStartLine:n.startLine,excludeEndLine:n.endLine}:{},c=t?Gt(e,a,t,l):[],m=[];for(let u of r){let d=c.filter(p=>p>=u.start_line&&p<=u.end_line),g=d.length>0?d:[u.start_line];for(let p of g)m.push(p)}o.set(a,m)}return o}function xu(e,n){let t=qt(e,n);return t?{match:t,identifier:F(t.symbol)||null}:null}function Iu(e,n){let t=[],s=new Set;for(let[i,o]of n){let a=A(e,i);for(let r of o){let l=fe(a,r),c=`${i}|${r}|${l?.symbol??""}`;s.has(c)||(s.add(c),t.push({file:i,line:r,enclosingSymbol:l?.symbol??null}))}}return t}function se(e,n,t={}){if(n.length===0)return new Map;let s=t.additive??!1,i=[],o=[];for(let c of n)P(c.relativePath)&&Ht(e,c.relativePath)!==null?i.push(c):o.push(c);let a=new Map,r=c=>{for(let[m,u]of c){let d=a.get(m);d||(d=[],a.set(m,d));let g=new Set(d.map(p=>`${p.symbol}|${p.chunkId}`));for(let p of u){let f=`${p.symbol}|${p.chunkId}`;g.has(f)||(g.add(f),d.push(p))}}};i.length>0&&r(Nu(e,i));let l=s?n:o;return l.length>0&&r(Cu(e,l)),a}function Nu(e,n){let t=new Map,s=new Map;for(let o of n){let a=s.get(o.relativePath);a?a.push(o):s.set(o.relativePath,[o]),t.set(o.symbolId,[])}let i=yt(e);for(let[o,a]of s){let r=Ht(e,o);if(!r)continue;let l=[...a].sort((c,m)=>{let u=c.endLine-c.startLine,d=m.endLine-m.startLine;return u-d});for(let c of r){let m=null;for(let f of l)if(c.line>=f.startLine&&c.line<=f.endLine){m=f;break}if(!m)continue;let u=i.get(c.calleeLeaf);if(!u||u.length===0)continue;let d=null,g=u.find(f=>f.file===o);if(g?d=g:u.length===1&&(d=u[0]),!d||d.symbol===m.symbol)continue;t.get(m.symbolId).push({symbol:d.symbol,file:d.file,chunkId:c.line})}}return t}var vu=je("global-leaf-index");function yt(e){return vu.get(e,()=>{let n=e.all(`SELECT gs.id, gs.symbol,
297
348
  COALESCE(der_doc.relative_path, mention_doc.relative_path) AS relative_path
298
349
  FROM global_symbols gs
299
350
  LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
@@ -307,10 +358,10 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
307
358
  GROUP BY m.symbol_id
308
359
  ) mention_doc ON mention_doc.symbol_id = gs.id
309
360
  WHERE 1 = 1
310
- ${e.symbolNoiseFor("gs")}`),t=new Map;for(let i of n){if(!i.relative_path||e.isIgnored(i.relative_path))continue;let s=M(i.symbol);if(!s)continue;let o=t.get(s);o||(o=[],t.set(s,o)),o.some(a=>a.symbolId===i.id)||o.push({symbol:i.symbol,symbolId:i.id,file:i.relative_path})}return t})}function lc(e,n){if(n.length===0)return new Map;let t=e.all(`SELECT c.document_id, c.id AS chunk_id, c.start_line, c.end_line, m.symbol_id
361
+ ${e.symbolNoiseFor("gs")}`),t=new Map;for(let s of n){if(!s.relative_path||e.isIgnored(s.relative_path))continue;let i=F(s.symbol);if(!i)continue;let o=t.get(i);o||(o=[],t.set(i,o)),o.some(a=>a.symbolId===s.id)||o.push({symbol:s.symbol,symbolId:s.id,file:s.relative_path})}return t})}function Cu(e,n){if(n.length===0)return new Map;let t=e.all(`SELECT c.document_id, c.id AS chunk_id, c.start_line, c.end_line, m.symbol_id
311
362
  FROM mentions m
312
363
  JOIN chunks c ON m.chunk_id = c.id
313
- WHERE m.role != 1`),i=new Map;for(let c of t)i.has(c.document_id)||i.set(c.document_id,[]),i.get(c.document_id).push(c);let s=new Map(e.all("SELECT id, relative_path FROM documents").map(c=>[c.id,c.relative_path])),o=new Map,a=e.all(`SELECT gs.id AS symbol_id, gs.symbol,
364
+ WHERE m.role != 1`),s=new Map;for(let c of t)s.has(c.document_id)||s.set(c.document_id,[]),s.get(c.document_id).push(c);let i=new Map(e.all("SELECT id, relative_path FROM documents").map(c=>[c.id,c.relative_path])),o=new Map,a=e.all(`SELECT gs.id AS symbol_id, gs.symbol,
314
365
  COALESCE(der.document_id, def_chunk.document_id) AS document_id
315
366
  FROM global_symbols gs
316
367
  LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
@@ -320,24 +371,21 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
320
371
  JOIN chunks c ON m.chunk_id = c.id
321
372
  WHERE m.role = 1
322
373
  GROUP BY m.symbol_id
323
- ) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of a)o.has(c.symbol_id)||o.set(c.symbol_id,{symbol:c.symbol,file:c.document_id!==null?s.get(c.document_id)??"":""});let r=new Map,l=s;for(let c of n){let m=i.get(c.documentId)??[],u=new Set,d=[],f=null,p=()=>{if(f)return f;let g=l.get(c.documentId)??"",y=new Set;if(g){let h=Qi(e,g),b=Math.max(0,c.startLine),x=Math.min(h.length-1,c.endLine);for(let S=b;S<=x;S+=1)for(let I of h[S])y.add(I)}return f=y,y};for(let g of m){if(g.symbol_id===c.symbolId)continue;let y=o.get(g.symbol_id);if(!y)continue;if(!(g.start_line>=c.startLine&&g.end_line<=c.endLine)){if(!(g.start_line<=c.endLine&&g.end_line>=c.startLine))continue;let S=M(y.symbol);if(!S||!p().has(S))continue}let b=`${y.symbol}|${g.chunk_id}`;u.has(b)||(u.add(b),d.push({...y,chunkId:g.chunk_id}))}r.set(c.symbolId,d)}return r}function ge(e,n){let t=new Map,i=e.all(`SELECT relative_path FROM documents
324
- WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),s=jt(e);for(let r of i){if(!T(r.relative_path)||e.isIgnored(r.relative_path))continue;let l=Lt(e,r.relative_path);if(l)for(let c of l){let m=s.get(c.calleeLeaf);if(!m||m.length===0)continue;let d=m.find(p=>p.file===r.relative_path)??(m.length===1?m[0]:null);if(!d||d.file===r.relative_path)continue;let f=t.get(d.symbolId);f||(f=new Set,t.set(d.symbolId,f)),f.add(r.relative_path)}}let o=e.all(`SELECT DISTINCT m.symbol_id, d.relative_path, c.document_id,
374
+ ) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of a)o.has(c.symbol_id)||o.set(c.symbol_id,{symbol:c.symbol,file:c.document_id!==null?i.get(c.document_id)??"":""});let r=new Map,l=i;for(let c of n){let m=s.get(c.documentId)??[],u=new Set,d=[],g=null,p=()=>{if(g)return g;let f=l.get(c.documentId)??"",y=new Set;if(f){let h=vi(e,f),b=Math.max(0,c.startLine),_=Math.min(h.length-1,c.endLine);for(let S=b;S<=_;S+=1)for(let x of h[S])y.add(x)}return g=y,y};for(let f of m){if(f.symbol_id===c.symbolId)continue;let y=o.get(f.symbol_id);if(!y)continue;if(!(f.start_line>=c.startLine&&f.end_line<=c.endLine)){if(!(f.start_line<=c.endLine&&f.end_line>=c.startLine))continue;let S=F(y.symbol);if(!S||!p().has(S))continue}let b=`${y.symbol}|${f.chunk_id}`;u.has(b)||(u.add(b),d.push({...y,chunkId:f.chunk_id}))}r.set(c.symbolId,d)}return r}function ye(e,n){let t=new Map,s=e.all(`SELECT relative_path FROM documents
375
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=yt(e);for(let r of s){if(!P(r.relative_path)||e.isIgnored(r.relative_path))continue;let l=Ht(e,r.relative_path);if(l)for(let c of l){let m=i.get(c.calleeLeaf);if(!m||m.length===0)continue;let d=m.find(p=>p.file===r.relative_path)??(m.length===1?m[0]:null);if(!d||d.file===r.relative_path)continue;let g=t.get(d.symbolId);g||(g=new Set,t.set(d.symbolId,g)),g.add(r.relative_path)}}let o=e.all(`SELECT DISTINCT m.symbol_id, d.relative_path, c.document_id,
325
376
  c.start_line AS chunk_start, c.end_line AS chunk_end
326
377
  FROM mentions m
327
378
  JOIN chunks c ON m.chunk_id = c.id
328
379
  JOIN documents d ON c.document_id = d.id
329
380
  WHERE m.role != 1
330
- ${e.pathExclusionsFor("d")}`),a=new Map;if(n)for(let r of n)a.set(r.symbolId,{docId:r.documentId,startLine:r.startLine,endLine:r.endLine});for(let r of o){if(e.isIgnored(r.relative_path))continue;let l=a.get(r.symbol_id);if(l&&l.docId===r.document_id&&r.chunk_start>=l.startLine&&r.chunk_end<=l.endLine)continue;let c=t.get(r.symbol_id);c||(c=new Set,t.set(r.symbol_id,c)),c.add(r.relative_path)}return t}import{readdirSync as cc}from"fs";import{extname as Ns,join as mc}from"path";var uc=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue",".rs",".py",".pyi",".java",".kt",".kts",".scala",".sc",".rb",".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx",".cs",".vb",".php",".dart"];var dc=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function De(e,n={}){let t=n.includeIndexed??!0,i=n.includeAuxiliary??!0,s=n.extensions?new Set(n.extensions.map(a=>a.toLowerCase())):new Set(uc.map(a=>a.toLowerCase())),o=`${t?"1":"0"}|${i?"1":"0"}|${[...s].sort().join(",")}`;return pc.get(e,o,()=>{let a=new Set;if(t){let r=e.all(`SELECT relative_path
331
- FROM documents
332
- WHERE 1 = 1
333
- ${e.pathExclusionsFor("documents")}`);for(let l of r)e.isIgnored(l.relative_path)||s.has(Ns(l.relative_path).toLowerCase())&&a.add(l.relative_path)}if(i)for(let r of fc(e.config.projectRoot,s))e.isIgnored(r)||a.add(r);return[...a].sort()})}var pc=W("source-files");function fc(e,n){let t=new Set,i=s=>{let o=s?mc(e,s):e,a=[];try{a=cc(o,{withFileTypes:!0})}catch{return}for(let r of a)if(!dc.has(r.name)){if(r.isDirectory()){i(s?`${s}/${r.name}`:r.name);continue}n.has(Ns(r.name).toLowerCase())&&t.add(s?`${s}/${r.name}`:r.name)}};return i(""),t}function at(e,n,t){let i=jt(e).get(t);if(!i||i.length===0)return[];if(i.length===1)return[Bt(i[0])];let s=i.find(l=>l.file===n);if(s)return[Bt(s)];let o=gc(e,n),a=o.get(t);if(a)for(let l of a){let c=i.filter(m=>Cs(l,m.file));if(c.length>0)return c.map(Bt)}let r=new Set;for(let l of o.values())for(let c of l)r.add(c);for(let l of r){let c=i.filter(m=>Cs(l,m.file));if(c.length>0&&c.length===i.length)return c.map(Bt)}return[]}function we(e,n){let t=wt(e,n);if(!t)return[];let i=M(t.symbol);if(!i)return[];let s=new Map;for(let o of De(e)){let a=P(e,o);if(!a||a.indexOf(i)===-1||o!==t.relativePath&&!at(e,o,i).some(c=>c.symbolId===t.symbolId))continue;let r=kt(e,o,i,o===t.relativePath?{excludeStartLine:t.startLine,excludeEndLine:t.endLine}:{});r.length>0&&s.set(o,r)}return hc(e,s)}function Ve(e,n){let t=new Map;for(let o of n){if(!o.leaf)continue;let a=t.get(o.leaf)??[];a.push(o),t.set(o.leaf,a)}if(t.size===0)return new Map;let i=new Set(n.map(o=>o.symbolId)),s=new Map;for(let o of De(e)){let a=Vi(e,o);if(a.size!==0){for(let r of a)if(t.has(r))for(let l of at(e,o,r)){if(!i.has(l.symbolId)||o===l.relativePath)continue;let c=s.get(l.symbolId);c||(c=new Set,s.set(l.symbolId,c)),c.add(o)}}}return s}function gc(e,n){let t=new Map;for(let i of me(e,n)){if(!i.sourcePath)continue;let s=i.localName??i.importedName;if(s){let o=t.get(s);o||(o=new Set,t.set(s,o)),o.add(i.sourcePath)}if(i.kind==="namespace")for(let o of i.usedMembers){let a=t.get(o);a||(a=new Set,t.set(o,a)),a.add(i.sourcePath)}}return t}function Cs(e,n){let t=i=>i.replace(/\\/g,"/").replace(/^\.\//,"");return t(e)===t(n)}function Bt(e){return{symbolId:e.symbolId,symbol:e.symbol,relativePath:e.file}}function hc(e,n){let t=[],i=new Set;for(let[s,o]of n){let a=A(e,s);for(let r of o){let l=de(a,r),c=`${s}|${r}|${l?.symbol??""}`;i.has(c)||(i.add(c),t.push({file:s,line:r,enclosingSymbol:l?.symbol??null}))}}return t}function vs(e,n){let t=O(e,n);if(!t)return[];let s=!j(t.symbol)&&!e.isIgnored(t.relativePath)?[{relativePath:t.relativePath,line:t.startLine}]:[],o=we(e,t),a=(o.length>0?o:Re(e,t)).filter(m=>!e.isIgnored(m.file)).map(m=>({relativePath:m.file,line:m.line})),r=yc(e,t),l=new Set,c=[];for(let m of[...s,...a,...r]){let u=`${m.relativePath}:${m.line}`;l.has(u)||(l.add(u),c.push(m))}return c}function yc(e,n){if(!n.relativePath.endsWith(".rb"))return[];let t=bc(n.symbol);if(t.length===0)return[];let i=e.all(`SELECT relative_path
381
+ ${e.pathExclusionsFor("d")}`),a=new Map;if(n)for(let r of n)a.set(r.symbolId,{docId:r.documentId,startLine:r.startLine,endLine:r.endLine});for(let r of o){if(e.isIgnored(r.relative_path))continue;let l=a.get(r.symbol_id);if(l&&l.docId===r.document_id&&r.chunk_start>=l.startLine&&r.chunk_end<=l.endLine)continue;let c=t.get(r.symbol_id);c||(c=new Set,t.set(r.symbol_id,c)),c.add(r.relative_path)}for(let r of s){if(e.isIgnored(r.relative_path)||P(r.relative_path)!=="rust")continue;let l=we(e,r.relative_path);if(l.size!==0)for(let c of l){let m=i.get(c);if(m)for(let u of m){if(u.file===r.relative_path)continue;let d=t.get(u.symbolId);d||(d=new Set,t.set(u.symbolId,d)),d.add(r.relative_path)}}}return t}function it(e,n,t){let s=yt(e).get(t);if(!s||s.length===0)return[];if(s.length===1)return[bt(s[0])];let i=s.filter(l=>l.file===n);if(i.length>0)return i.map(bt);let o=Eu(e,n),a=o.get(t);if(a)for(let l of a){let c=s.filter(m=>Ki(l,m.file));if(c.length>0)return c.map(bt)}let r=new Set;for(let l of o.values())for(let c of l)r.add(c);for(let l of r){let c=s.filter(m=>Ki(l,m.file));if(c.length>0&&c.length===s.length)return c.map(bt)}return[]}function St(e,n,t){let s=it(e,n,t);if(s.length>0)return s;let i=yt(e).get(t);return!i||i.length===0?[]:i.map(bt)}function Pe(e,n){let t=qt(e,n);if(!t)return[];let s=F(t.symbol);if(!s)return[];let i=new Map;for(let o of Re(e)){let a=M(e,o);if(!a||a.indexOf(s)===-1||o!==t.relativePath&&!it(e,o,s).some(c=>c.symbolId===t.symbolId))continue;let r=Gt(e,o,s,o===t.relativePath?{excludeStartLine:t.startLine,excludeEndLine:t.endLine}:{});r.length>0&&i.set(o,r)}return Ru(e,i)}function ot(e,n){let t=new Map;for(let o of n){if(!o.leaf)continue;let a=t.get(o.leaf)??[];a.push(o),t.set(o.leaf,a)}if(t.size===0)return new Map;let s=new Set(n.map(o=>o.symbolId)),i=new Map;for(let o of Re(e)){let a=Ni(e,o);if(a.size!==0){for(let r of a)if(t.has(r))for(let l of it(e,o,r)){if(!s.has(l.symbolId)||o===l.relativePath)continue;let c=i.get(l.symbolId);c||(c=new Set,i.set(l.symbolId,c)),c.add(o)}}}return i}function Eu(e,n){let t=new Map;for(let s of de(e,n)){if(!s.sourcePath)continue;let i=s.localName??s.importedName;if(i){let o=t.get(i);o||(o=new Set,t.set(i,o)),o.add(s.sourcePath)}if(s.kind==="namespace")for(let o of s.usedMembers){let a=t.get(o);a||(a=new Set,t.set(o,a)),a.add(s.sourcePath)}}return t}function Ki(e,n){let t=s=>s.replace(/\\/g,"/").replace(/^\.\//,"");return t(e)===t(n)}function bt(e){return{symbolId:e.symbolId,symbol:e.symbol,relativePath:e.file}}function Ru(e,n){let t=[],s=new Set;for(let[i,o]of n){let a=A(e,i);for(let r of o){let l=fe(a,r),c=`${i}|${r}|${l?.symbol??""}`;s.has(c)||(s.add(c),t.push({file:i,line:r,enclosingSymbol:l?.symbol??null}))}}return t}function Qi(e,n){let t=k(e,n);if(!t)return[];let i=!j(t.symbol)&&!e.isIgnored(t.relativePath)?[{relativePath:t.relativePath,line:t.startLine}]:[],o=Pe(e,t),a=(o.length>0?o:$e(e,t)).filter(m=>!e.isIgnored(m.file)).map(m=>({relativePath:m.file,line:m.line})),r=Lu(e,t),l=new Set,c=[];for(let m of[...i,...a,...r]){let u=`${m.relativePath}:${m.line}`;l.has(u)||(l.add(u),c.push(m))}return c}function Lu(e,n){if(!n.relativePath.endsWith(".rb"))return[];let t=wu(n.symbol);if(t.length===0)return[];let s=e.all(`SELECT relative_path
334
382
  FROM documents
335
383
  WHERE relative_path LIKE '%.rb'
336
384
  ${e.pathExclusionsFor("documents")}
337
- ORDER BY relative_path`),s=[];for(let o of i){if(e.isIgnored(o.relative_path))continue;let a=P(e,o.relative_path);if(!a)continue;let r=a.split(`
338
- `);for(let l=0;l<r.length;l++){let c=r[l]??"";t.some(m=>new RegExp(`@${m}\\b|\\b${m}:`).test(c))&&s.push({relativePath:o.relative_path,line:l})}}return s}function bc(e){let t=(e.split(":").pop()??e).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9_]+/g,"_").toLowerCase().replace(/^_+|_+$/g,""),i=t.split("_").filter(Boolean),s=new Set;return t&&s.add(t),i.length>=1&&s.add(i[i.length-1]),i.length>=2&&s.add(i.slice(-2).join("_")),[...s]}function Es(e,n){let t=O(e,n);if(!t)return{definitions:[],referencedBy:[]};let i=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",t.symbolId),s=st(i?.documentation??null),o=e.isIgnored(t.relativePath)?[]:[{relativePath:t.relativePath,startLine:t.startLine,endLine:t.endLine,signature:_c(s,i?.display_name??null,t.symbol),source:Sc(e,t.relativePath,t.startLine,t.endLine)}],a=we(e,t),l=(a.length>0?a:Re(e,t)).filter(c=>!e.isIgnored(c.file)).map(c=>({relativePath:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol,enclosingShort:c.enclosingSymbol?_(c.enclosingSymbol):"(top-level)"}));return{definitions:o,referencedBy:l}}function Sc(e,n,t,i){let s=P(e,n);if(!s)return null;let a=s.split(`
339
- `).slice(t,i+1).join(`
340
- `).trimEnd();return a.length>0?a:null}function _c(e,n,t){let i=it(e);if(i&&!xc(i))return i;let s=(n??"").trim();return s?j(t)&&!s.endsWith("()")?`${s}()`:s:_(t)}function xc(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function Ls(e,n){let t=Q(e,n);return t?e.all(`SELECT DISTINCT d2.relative_path
385
+ ORDER BY relative_path`),i=[];for(let o of s){if(e.isIgnored(o.relative_path))continue;let a=M(e,o.relative_path);if(!a)continue;let r=a.split(`
386
+ `);for(let l=0;l<r.length;l++){let c=r[l]??"";t.some(m=>new RegExp(`@${m}\\b|\\b${m}:`).test(c))&&i.push({relativePath:o.relative_path,line:l})}}return i}function wu(e){let t=(e.split(":").pop()??e).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9_]+/g,"_").toLowerCase().replace(/^_+|_+$/g,""),s=t.split("_").filter(Boolean),i=new Set;return t&&i.add(t),s.length>=1&&i.add(s[s.length-1]),s.length>=2&&i.add(s.slice(-2).join("_")),[...i]}function Xi(e,n){let t=k(e,n);if(!t)return{definitions:[],referencedBy:[]};let s=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",t.symbolId),i=pt(s?.documentation??null),o=e.isIgnored(t.relativePath)?[]:[{relativePath:t.relativePath,startLine:t.startLine,endLine:t.endLine,signature:ku(i,s?.display_name??null,t.symbol),source:Du(e,t.relativePath,t.startLine,t.endLine)}],a=Pe(e,t),l=(a.length>0?a:$e(e,t)).filter(c=>!e.isIgnored(c.file)).map(c=>({relativePath:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol,enclosingShort:c.enclosingSymbol?I(c.enclosingSymbol):"(top-level)"}));return{definitions:o,referencedBy:l}}function Du(e,n,t,s){let i=M(e,n);if(!i)return null;let a=i.split(`
387
+ `).slice(t,s+1).join(`
388
+ `).trimEnd();return a.length>0?a:null}function ku(e,n,t){let s=dt(e);if(s&&!Ou(s))return s;let i=(n??"").trim();return i?j(t)&&!i.endsWith("()")?`${i}()`:i:I(t)}function Ou(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function Zi(e,n){let t=ee(e,n);return t?e.all(`SELECT DISTINCT d2.relative_path
341
389
  FROM mentions m
342
390
  JOIN chunks c ON m.chunk_id = c.id
343
391
  JOIN documents d1 ON c.document_id = d1.id
@@ -353,7 +401,7 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
353
401
  WHERE d1.relative_path = ?
354
402
  AND d2.relative_path <> d1.relative_path
355
403
  AND ${e.localSymbolPredicate}
356
- ORDER BY d2.relative_path`,t).filter(s=>!e.isIgnored(s.relative_path)).map(s=>({relativePath:s.relative_path})):[]}function Rs(e,n){let t=Q(e,n);return t?e.all(`SELECT DISTINCT d1.relative_path
404
+ ORDER BY d2.relative_path`,t).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function eo(e,n){let t=ee(e,n);return t?e.all(`SELECT DISTINCT d1.relative_path
357
405
  FROM mentions m
358
406
  JOIN chunks c ON m.chunk_id = c.id
359
407
  JOIN documents d1 ON c.document_id = d1.id
@@ -368,9 +416,9 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
368
416
  JOIN documents d2 ON sym_def.document_id = d2.id
369
417
  WHERE d2.relative_path = ?
370
418
  AND d1.relative_path != ?
371
- ORDER BY d1.relative_path`,t,t).filter(s=>!e.isIgnored(s.relative_path)).map(s=>({relativePath:s.relative_path})):[]}function Ds(e,n){let t=Ce(e,n);if(t.length===0)return{files:[],symbols:[],dependsOn:[],dependedOnBy:[]};let i=t.map(()=>"?").join(", "),o=e.all(`SELECT relative_path FROM documents
372
- WHERE relative_path IN (${i})
373
- ORDER BY relative_path`,...t).map(u=>u.relative_path).filter(u=>!e.isIgnored(u)),a=He(e,o,{onlyDocumented:!0,sort:!0}).map(({relativePath:u,...d})=>d),l=e.all(`SELECT DISTINCT d2.relative_path
419
+ ORDER BY d1.relative_path`,t,t).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function to(e,n){let t=Le(e,n);if(t.length===0)return{files:[],symbols:[],dependsOn:[],dependedOnBy:[]};let s=t.map(()=>"?").join(", "),o=e.all(`SELECT relative_path FROM documents
420
+ WHERE relative_path IN (${s})
421
+ ORDER BY relative_path`,...t).map(u=>u.relative_path).filter(u=>!e.isIgnored(u)),a=Ke(e,o,{onlyDocumented:!0,sort:!0}).map(({relativePath:u,...d})=>d),l=e.all(`SELECT DISTINCT d2.relative_path
374
422
  FROM mentions m
375
423
  JOIN chunks c ON m.chunk_id = c.id
376
424
  JOIN documents d1 ON c.document_id = d1.id
@@ -383,8 +431,8 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
383
431
  GROUP BY m2.symbol_id
384
432
  ) sym_def ON sym_def.symbol_id = gs.id
385
433
  JOIN documents d2 ON sym_def.document_id = d2.id
386
- WHERE d1.relative_path IN (${i})
387
- AND d2.relative_path NOT IN (${i})
434
+ WHERE d1.relative_path IN (${s})
435
+ AND d2.relative_path NOT IN (${s})
388
436
  AND ${e.localSymbolPredicate}
389
437
  ORDER BY d2.relative_path`,...t,...t).map(u=>u.relative_path).filter(u=>!e.isIgnored(u)),m=e.all(`SELECT DISTINCT d1.relative_path
390
438
  FROM mentions m
@@ -399,21 +447,21 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
399
447
  GROUP BY m2.symbol_id
400
448
  ) sym_def ON sym_def.symbol_id = gs.id
401
449
  JOIN documents d2 ON sym_def.document_id = d2.id
402
- WHERE d2.relative_path IN (${i})
403
- AND d1.relative_path NOT IN (${i})
404
- ORDER BY d1.relative_path`,...t,...t).map(u=>u.relative_path).filter(u=>!e.isIgnored(u));return{files:o,symbols:a,dependsOn:l,dependedOnBy:m}}function ws(e,n){let t=Ce(e,n);if(t.length===0)return[];let i=t.map(()=>"?").join(", "),s=e.all(`SELECT DISTINCT d1.relative_path, gs.symbol
450
+ WHERE d2.relative_path IN (${s})
451
+ AND d1.relative_path NOT IN (${s})
452
+ ORDER BY d1.relative_path`,...t,...t).map(u=>u.relative_path).filter(u=>!e.isIgnored(u));return{files:o,symbols:a,dependsOn:l,dependedOnBy:m}}function no(e,n){let t=Le(e,n);if(t.length===0)return[];let s=t.map(()=>"?").join(", "),i=e.all(`SELECT DISTINCT d1.relative_path, gs.symbol
405
453
  FROM mentions m
406
454
  JOIN chunks c ON m.chunk_id = c.id
407
455
  JOIN documents d1 ON c.document_id = d1.id
408
456
  JOIN global_symbols gs ON m.symbol_id = gs.id
409
- WHERE d1.relative_path NOT IN (${i})
457
+ WHERE d1.relative_path NOT IN (${s})
410
458
  AND (
411
459
  EXISTS (
412
460
  SELECT 1
413
461
  FROM defn_enclosing_ranges der
414
462
  JOIN documents d2 ON der.document_id = d2.id
415
463
  WHERE der.symbol_id = gs.id
416
- AND d2.relative_path IN (${i})
464
+ AND d2.relative_path IN (${s})
417
465
  )
418
466
  OR EXISTS (
419
467
  SELECT 1
@@ -422,13 +470,13 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
422
470
  JOIN documents d2 ON def_c.document_id = d2.id
423
471
  WHERE def_m.symbol_id = gs.id
424
472
  AND def_m.role = 1
425
- AND d2.relative_path IN (${i})
473
+ AND d2.relative_path IN (${s})
426
474
  )
427
475
  )
428
476
  AND m.role != 1
429
477
  AND ${e.localSymbolPredicate}
430
478
  ${e.pathExclusionsFor("d1")}
431
- ORDER BY d1.relative_path`,...t,...t,...t),o=t.flatMap(r=>A(e,r).filter(l=>Rt(l.symbol)).map(l=>({relative_path:r,symbol:l.symbol}))),a=new Set;return[...s,...o].filter(r=>!e.isIgnored(r.relative_path)).filter(r=>{let l=`${r.relative_path}|${r.symbol}`;return a.has(l)?!1:(a.add(l),!0)}).map(r=>({consumer:r.relative_path,symbol:r.symbol,shortName:_(r.symbol)}))}function Wt(e){let n=Ms(e);return Nc(n)?"test":Cc(n)?"worker":vc(n)?"entry":Ec(n)?"barrel":"source"}function Ht(e){return Wt(e)==="barrel"}function Os(e){return Ic.get(e,()=>{let n=G(e),t=De(e).filter(o=>{let a=Wt(o);return a==="entry"||a==="worker"}),i=new Set,s=new Set;for(;t.length>0;){let o=t.shift();if(!i.has(o)){i.add(o),Wt(o)==="barrel"&&s.add(o);for(let a of n.get(o)??[])i.has(a)||t.push(a)}}return s})}var Ic=Pe("live-barrels");function On(e,n){return Os(e).has(Ms(n))}function $s(e){let n=Os(e);return De(e).filter(t=>Ht(t)&&!n.has(t))}function Ie(e,n){let t=Wt(n);return t==="entry"||t==="worker"||On(e,n)}var ks=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],Ps=["%/test-utils/%"];function Nc(e){return!!(/\.(?:test|spec)\.[a-z0-9]+$/i.test(e)||/(?:^|\/)(?:_)?test_[^/]+$/i.test(e)||/(?:^|\/)spec_[^/]+$/i.test(e)||/(?:^|\/)[^/]+_test\.[a-z0-9]+$/i.test(e)||/(?:^|\/)[^/]+_spec\.[a-z0-9]+$/i.test(e)||/(?:^|\/)__tests__\//i.test(e)||/(?:^|\/)test\//i.test(e)||/(?:^|\/)tests\//i.test(e)||/(?:^|\/)__fixtures__\//i.test(e)||/(?:^|\/)__mocks__\//i.test(e)||/(?:^|\/)test-support\//i.test(e)||/(?:^|\/)test-utils\//i.test(e)||/(?:^|\/)testing\//i.test(e))}function Cc(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function vc(e){let n=e.split("/"),t=n[n.length-1]??e;return t==="cli.ts"||t==="cli.js"||t==="postinstall.ts"||t==="postinstall.js"||t==="main.ts"||t==="main.js"||t==="main.rs"||t==="main.go"||t==="main.py"||t==="build.rs"||t==="lib.rs"||/\bsrc\/bin\/[^/]+\.rs$/.test(e)||/(?:^|\/)examples\/[^/]+\.rs$/.test(e)||/(?:^|\/)tests\/[^/]+\.rs$/.test(e)||/(?:^|\/)benches\/[^/]+\.rs$/.test(e)?!0:t==="index.ts"||t==="index.js"?n.length<=2:!1}function Ec(e){return e==="index.ts"||e==="index.js"||e.endsWith("/index.ts")||e.endsWith("/index.js")||e.endsWith("/mod.rs")||e.endsWith("/__init__.py")}function Ms(e){return e.replace(/\\/g,"/")}var Jt=new WeakMap;function Fs(e,n){let t=T(n);return t==="rust"?Oc(e,n):t==="typescript"||t==="tsx"||t==="javascript"?Rc(e,n):[]}var Lc=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function Rc(e,n){let t=$(e,n);if(!t)return[];let i=Jt.get(t);if(i)return i;let s=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(n)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(n),o=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(n),a=!1,r=t.rootNode;for(let c of r.namedChildren){if(c.type!=="expression_statement")continue;let m=c.namedChild(0);if(!m||m.type!=="call_expression")continue;let u=m.namedChild(0);if(!u)continue;let d=u.type==="member_expression"?u.namedChild(u.namedChildCount-1)?.text:u.text;if(d&&Lc.has(d)){a=!0;break}}let l=[];a&&l.push({startLine:0,endLine:r.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(s||o)&&l.push({startLine:0,endLine:r.endPosition.row,reason:s?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of r.namedChildren){let m=null,u=null;if(c.type==="function_declaration")m=c.namedChild(0)?.text??null,u=c;else if(c.type==="export_statement"){let d=c.namedChild(0);d?.type==="function_declaration"&&(m=d.namedChild(0)?.text??null,u=d)}else if(c.type==="lexical_declaration"){let d=c.namedChild(0);if(d?.type==="variable_declarator"){let f=d.namedChild(0)?.text,p=d.namedChild(1);f&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(m=f,u=d)}}m&&/^use[A-Z]/.test(m)&&u&&l.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...Ts(t,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),Jt.set(t,l),l}var Dc=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function wc(e){return Dc.test(e)}function Ts(e,n,t){let i=[],s=o=>{if(n.has(o.type)&&o.parent){let r=o.parent.children,l=-1;for(let c=0;c<r.length;c+=1)if(r[c].startIndex===o.startIndex&&r[c].type===o.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let m=r[c];if(t.has(m.type)){if(wc(m.text)){i.push({startLine:o.startPosition.row,endLine:o.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(m.type==="attribute_item"||m.type==="inner_attribute_item"))break}}for(let a of o.namedChildren)s(a)};return s(e.rootNode),i}function Oc(e,n){let t=$(e,n);if(!t)return[];let i=Jt.get(t);if(i)return i;let s=[],o=m=>{let u=m.parent;if(!u)return[];let d=u.children,f=-1;for(let g=0;g<d.length;g+=1)if(d[g].startIndex===m.startIndex&&d[g].type===m.type){f=g;break}if(f<=0)return[];let p=[];for(let g=f-1;g>=0;g-=1){let y=d[g];if(y.type==="attribute_item"||y.type==="inner_attribute_item")p.push(y.text);else{if(y.type==="line_comment"||y.type==="block_comment")continue;break}}return p},a=m=>/#\[\s*tauri::command\b/.test(m)?"#[tauri::command]":/#\[\s*command\b/.test(m)?"#[command]":/#\[\s*test\b/.test(m)?"#[test]":/#\[\s*bench\b/.test(m)?"#[bench]":/#\[\s*tokio::test\b/.test(m)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(m)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(m)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(m)?"#[no_mangle]":/#\[\s*napi\b/.test(m)?"#[napi]":/#\[\s*pyfunction\b/.test(m)?"#[pyfunction]":/#\[\s*pymethod\b/.test(m)?"#[pymethod]":/#\[\s*pyo3\b/.test(m)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(m)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(m)?"#[doc(hidden)]":null,r=m=>/#\[\s*derive\s*\(/.test(m)?/\bSerialize\b/.test(m)||/\bDeserialize\b/.test(m)||/\bFromRow\b/.test(m)||/\bDeriveEntityModel\b/.test(m)||/\bIntoSchema\b/.test(m)||/\bToSchema\b/.test(m)||/\bDeriveValueType\b/.test(m)||/\bsqlx::FromRow\b/.test(m):!1,l=m=>/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(m),c=(m,u,d)=>{let f=u,p=d;if(m.type==="impl_item"&&m.namedChildren.filter(y=>y.type==="type_identifier").length>=2&&(p=!0),m.type==="function_item"||m.type==="function_signature_item"){let g=o(m),y=null;d?y="trait impl method (dynamic dispatch)":u&&(y="inside #[cfg(test)] mod");for(let h of g){let b=a(h);if(b){y=b;break}if(l(h)){y="#[allow(dead_code)]";break}}y&&s.push({startLine:m.startPosition.row,endLine:m.endPosition.row,reason:y})}else if(m.type==="struct_item"||m.type==="enum_item"||m.type==="union_item"){let g=o(m),y=g.some(r),h=g.some(l),b=m.namedChildren.find(x=>x.type==="type_identifier")?.text;y&&s.push({startLine:m.startPosition.row,endLine:m.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:b}),h&&s.push({startLine:m.startPosition.row,endLine:m.endPosition.row,reason:"#[allow(dead_code)]",containerName:b}),u&&s.push({startLine:m.startPosition.row,endLine:m.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:b})}else m.type==="mod_item"&&o(m).some(y=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(y))&&(f=!0);for(let g of m.namedChildren)c(g,f,p)};return c(t.rootNode,!1,!1),s.push(...Ts(t,new Set(["function_item","function_signature_item","struct_item","enum_item","union_item","impl_item","mod_item","static_item","const_item"]),new Set(["line_comment","block_comment"]))),Jt.set(t,s),s}var $c=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function As(e,n){return _n(e,n,kc,()=>new Set,(t,i,s)=>{if(!(i!=="typescript"&&i!=="tsx"&&i!=="javascript"))for(let o of t.rootNode.descendantsOfType("call_expression")){let a=o.namedChild(0);if(!a)continue;let r=tt(a);if(!r||!$c.has(r))continue;let l=o.namedChildren.find(u=>u.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let m=c.namedChildren.find(u=>u.type==="string_fragment");m&&s.add(m.text)}})??new Set}var kc=new WeakMap;function Ut(e,n={}){let{scope:t,minLoc:i=1,includeTests:s=!1,skipBarrels:o=!1,includeMembers:a=!1}=n,r=o?new Set($s(e)):new Set,l=e.all(`SELECT
479
+ ORDER BY d1.relative_path`,...t,...t,...t),o=t.flatMap(r=>A(e,r).filter(l=>Ve(l.symbol)).map(l=>({relative_path:r,symbol:l.symbol}))),a=new Set;return[...i,...o].filter(r=>!e.isIgnored(r.relative_path)).filter(r=>{let l=`${r.relative_path}|${r.symbol}`;return a.has(l)?!1:(a.add(l),!0)}).map(r=>({consumer:r.relative_path,symbol:r.symbol,shortName:I(r.symbol)}))}function U(e){let n=_t(e);return Pu(n)?"test":Mu(n)?"worker":Fu(n)?"entry":Tu(n)?"barrel":"source"}function en(e){return U(e)==="barrel"}function io(e){return $u.get(e,()=>{let n=K(e),t=Re(e).filter(o=>{let a=U(o);return a==="entry"||a==="worker"}),s=new Set,i=new Set;for(;t.length>0;){let o=t.shift();if(!s.has(o)){s.add(o),U(o)==="barrel"&&i.add(o);for(let a of n.get(o)??[])s.has(a)||t.push(a)}}return i})}var $u=je("live-barrels");function Un(e,n){return io(e).has(_t(n))}function oo(e){let n=io(e);return Re(e).filter(t=>en(t)&&!n.has(t))}function ve(e,n){let t=U(n);return t==="entry"||t==="worker"||Un(e,n)}function rt(e,n,t){let s=e.config.entryRoots;if(!s)return!1;let i=_t(t);return!!(s.files?.some(o=>_t(o)===i)||s.pathPrefixes?.some(o=>i.startsWith(_t(o)))||s.qualifiedVars?.some(o=>Au(n,o))||s.symbolPatterns?.some(o=>{try{return new RegExp(o).test(n)}catch{return!1}}))}var ro=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],ao=["%/test-utils/%"];function Pu(e){return!!(/\.(?:test|spec)\.[a-z0-9]+$/i.test(e)||/(?:^|\/)(?:_)?test_[^/]+$/i.test(e)||/(?:^|\/)spec_[^/]+$/i.test(e)||/(?:^|\/)[^/]+_test\.[a-z0-9]+$/i.test(e)||/(?:^|\/)[^/]+_tests\.rs$/i.test(e)||/(?:^|\/)tests\.rs$/i.test(e)||/(?:^|\/)[^/]+_spec\.[a-z0-9]+$/i.test(e)||/(?:^|\/)__tests__\//i.test(e)||/(?:^|\/)test\//i.test(e)||/(?:^|\/)tests\//i.test(e)||/(?:^|\/)__fixtures__\//i.test(e)||/(?:^|\/)__mocks__\//i.test(e)||/(?:^|\/)test-support\//i.test(e)||/(?:^|\/)test-utils\//i.test(e)||/(?:^|\/)testing\//i.test(e))}function Mu(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function Fu(e){let n=e.split("/"),t=n[n.length-1]??e;return t==="cli.ts"||t==="cli.js"||t==="postinstall.ts"||t==="postinstall.js"||t==="main.ts"||t==="main.js"||t==="main.rs"||t==="main.go"||t==="main.py"||t==="build.rs"||t==="lib.rs"||/\bsrc\/bin\/[^/]+\.rs$/.test(e)||/(?:^|\/)examples\/[^/]+\.rs$/.test(e)||/(?:^|\/)tests\/[^/]+\.rs$/.test(e)||/(?:^|\/)benches\/[^/]+\.rs$/.test(e)?!0:t==="index.ts"||t==="index.js"?n.length<=2:!1}function Tu(e){return e==="index.ts"||e==="index.js"||e.endsWith("/index.ts")||e.endsWith("/index.js")||e.endsWith("/mod.rs")||e.endsWith("/__init__.py")}function _t(e){return e.replace(/\\/g,"/")}function Au(e,n){let t=n.lastIndexOf("/");if(t<0)return!1;let s=n.slice(0,t),i=n.slice(t+1);return e.includes(so(s)+"/")&&e.includes(so(i)+".")}function so(e){return/^[A-Za-z0-9_$+-]+$/.test(e)?e:"`"+e.replace(/`/g,"``")+"`"}function tn(e,n={}){let{scope:t,minLoc:s=1,includeTests:i=!1,skipBarrels:o=!1,includeMembers:a=!1}=n,r=o?new Set(oo(e)):new Set,l=e.all(`SELECT
432
480
  m.symbol_id,
433
481
  d.relative_path,
434
482
  COUNT(*) AS ref_count
@@ -437,8 +485,8 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
437
485
  JOIN documents d ON c.document_id = d.id
438
486
  WHERE m.role != 1
439
487
  ${e.pathExclusionsFor("d")}
440
- GROUP BY m.symbol_id, d.relative_path`),c=new Map;for(let h of l){if(e.isIgnored(h.relative_path)||r.has(h.relative_path))continue;let b=c.get(h.symbol_id);b||(b=new Map,c.set(h.symbol_id,b)),b.set(h.relative_path,h.ref_count)}Pc(e,c,r);let m=Mc(e),d=V(e,{scope:t}).filter(h=>!e.isIgnored(h.relativePath)).filter(h=>!We(h.symbol)).filter(h=>$n(h.symbol)).filter(h=>h.isFunctionLike||!h.enclosingSymbol||!$n(h.enclosingSymbol)).filter(h=>s||Fc(h.relativePath)).filter(h=>s||!m(h.relativePath,h.startLine,h.parentTypeName)).filter(h=>a||$n(h.symbol)).filter(h=>h.endLine-h.startLine+1>=i).map(h=>{let b=c.get(h.symbolId)??new Map,x=b.get(h.relativePath)??0,S=0;for(let[I,L]of b)I!==h.relativePath&&(S+=L);return{relative_path:h.relativePath,start_line:h.startLine,end_line:h.endLine,loc:h.endLine-h.startLine+1,symbol:h.symbol,same_file_refs:x,cross_file_refs:S}}).filter(h=>h.cross_file_refs===0).sort((h,b)=>b.loc-h.loc||h.relative_path.localeCompare(b.relative_path)||h.start_line-b.start_line),f=0,p=0,g=0,y=d.filter(h=>!e.isIgnored(h.relative_path)).filter(h=>!Ie(e,h.relative_path)).map(h=>{let b=h.same_file_refs===0?"dead-code":"file-internal";return b==="dead-code"?f++:p++,g+=h.loc,{relativePath:h.relative_path,startLine:h.start_line,endLine:h.end_line,loc:h.loc,symbol:h.symbol,shortName:_(h.symbol),sameFileRefs:h.same_file_refs,kind:b}});return{symbols:y,totalCount:y.length,deadCodeCount:f,fileInternalCount:p,totalLoc:g}}function Pc(e,n,t){let i=e.all(`SELECT relative_path FROM documents
441
- WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),s=new Set(i.map(r=>r.relative_path)),o=new Set(De(e));for(let r of s)o.add(r);let a=(r,l,c)=>{if(c<=0)return;let m=n.get(r);m||(m=new Map,n.set(r,m)),m.set(l,(m.get(l)??0)+c)};for(let r of o){if(!T(r)&&!nt(r)||e.isIgnored(r)||t.has(r))continue;let l=Me(e,r);for(let[m,u]of l){let d=at(e,r,m);if(d.length!==0)for(let f of d){let p=f.relativePath===r?Math.max(0,u.length-1):u.length;a(f.symbolId,r,p)}}let c=As(e,r);for(let m of c){let u=at(e,r,m);for(let d of u)d.relativePath!==r&&a(d.symbolId,r,1)}}}function Mc(e){let n=new Map,t=i=>{let s=n.get(i);if(s)return s;let o=Fs(e,i);return s={ranges:o.map(a=>({startLine:a.startLine,endLine:a.endLine})),containers:new Set(o.map(a=>a.containerName).filter(a=>!!a))},n.set(i,s),s};return(i,s,o)=>{let a=t(i);for(let r of a.ranges)if(s>=r.startLine&&s<=r.endLine)return!0;return!!(o&&a.containers.has(o))}}function Fc(e){return[...new Set([...ks,...Ps])].every(t=>!Tc(e,t))}function Tc(e,n){return new RegExp(`^${n.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function $n(e){return j(e)||e.endsWith("().")||e.endsWith(".")}function js(e,n={}){let{limit:t=30,scope:i}=n,s=i?`AND def_d.relative_path LIKE '%${i}%'`:"",a=e.all(`SELECT
488
+ GROUP BY m.symbol_id, d.relative_path`),c=new Map;for(let h of l){if(e.isIgnored(h.relative_path)||r.has(h.relative_path))continue;let b=c.get(h.symbol_id);b||(b=new Map,c.set(h.symbol_id,b)),b.set(h.relative_path,h.ref_count)}ju(e,c,r);let m=Bu(e),d=Z(e,{scope:t}).filter(h=>!e.isIgnored(h.relativePath)).filter(h=>!Ge(h.symbol)).filter(h=>qn(h.symbol)).filter(h=>h.isFunctionLike||!h.enclosingSymbol||!qn(h.enclosingSymbol)).filter(h=>i||Wu(h.relativePath)).filter(h=>i||!m(h.relativePath,h.startLine,h.symbol,h.parentTypeName)).filter(h=>!Ye(h.symbol)).filter(h=>!G(h.symbol)).filter(h=>a||qn(h.symbol)).filter(h=>h.endLine-h.startLine+1>=s).map(h=>{let b=c.get(h.symbolId)??new Map,_=b.get(h.relativePath)??0,S=0;for(let[x,L]of b)x!==h.relativePath&&(S+=L);return{relative_path:h.relativePath,start_line:h.startLine,end_line:h.endLine,loc:h.endLine-h.startLine+1,symbol:h.symbol,same_file_refs:_,cross_file_refs:S}}).filter(h=>h.cross_file_refs===0).sort((h,b)=>b.loc-h.loc||h.relative_path.localeCompare(b.relative_path)||h.start_line-b.start_line),g=0,p=0,f=0,y=d.filter(h=>!e.isIgnored(h.relative_path)).filter(h=>!ve(e,h.relative_path)).filter(h=>!rt(e,h.symbol,h.relative_path)).map(h=>{let b=h.same_file_refs===0?"dead-code":"file-internal";return b==="dead-code"?g++:p++,f+=h.loc,{relativePath:h.relative_path,startLine:h.start_line,endLine:h.end_line,loc:h.loc,symbol:h.symbol,shortName:I(h.symbol),sameFileRefs:h.same_file_refs,kind:b}});return{symbols:y,totalCount:y.length,deadCodeCount:g,fileInternalCount:p,totalLoc:f}}function ju(e,n,t){let s=e.all(`SELECT relative_path FROM documents
489
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=new Set(s.map(r=>r.relative_path)),o=new Set(Re(e));for(let r of i)o.add(r);let a=(r,l,c)=>{if(c<=0)return;let m=n.get(r);m||(m=new Map,n.set(r,m)),m.set(l,(m.get(l)??0)+c)};for(let r of o){if(!P(r)&&!mt(r)||e.isIgnored(r)||t.has(r))continue;let l=xe(e,r);for(let[u,d]of l){let g=St(e,r,u);if(g.length!==0)for(let p of g){let f=p.relativePath===r?Math.max(0,d.length-1):d.length;a(p.symbolId,r,f)}}let c=Si(e,r);for(let u of c){let d=it(e,r,u);for(let g of d)g.relativePath!==r&&a(g.symbolId,r,1)}let m=we(e,r);for(let u of m){let d=it(e,r,u);for(let g of d)a(g.symbolId,r,1)}}}function Bu(e){let n=new Map,t=s=>{let i=n.get(s);if(i)return i;let o=hi(e,s);return i={ranges:o.map(a=>({startLine:a.startLine,endLine:a.endLine})),containers:new Set(o.map(a=>a.containerName).filter(a=>!!a))},n.set(s,i),i};return(s,i,o,a)=>{let r=t(s);for(let l of r.ranges)if(i>=l.startLine&&i<=l.endLine)return!0;if(a&&r.containers.has(a))return!0;for(let l of ai(o))if(r.containers.has(l))return!0;return!1}}function Wu(e){return[...new Set([...ro,...ao])].every(t=>!Hu(e,t))}function Hu(e,n){return new RegExp(`^${n.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function qn(e){return j(e)||e.endsWith("().")||e.endsWith(".")}function lo(e,n={}){let{limit:t=30,scope:s}=n,i=s?`AND def_d.relative_path LIKE '%${s}%'`:"",a=e.all(`SELECT
442
490
  gs.symbol,
443
491
  COUNT(*) AS ref_count,
444
492
  COUNT(DISTINCT ref_d.id) AS file_count,
@@ -458,21 +506,21 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
458
506
  WHERE m.role != 1
459
507
  ${e.pathExclusionsFor("def_d")}
460
508
  ${e.symbolNoiseFor("gs")}
461
- ${s}
509
+ ${i}
462
510
  GROUP BY gs.id
463
511
  ORDER BY ref_count DESC
464
- LIMIT ?`,t).filter(r=>!e.isIgnored(r.defined_in)).map(r=>({symbol:r.symbol,shortName:_(r.symbol),refCount:r.ref_count,fileCount:r.file_count,definedIn:r.defined_in}));return a.length>0?a:Ac(e,i,t)}function Ac(e,n,t){return V(e,{scope:n}).filter(i=>!e.isIgnored(i.relativePath)).map(i=>jc(e,i)).filter(i=>i.refCount>0).sort((i,s)=>s.refCount-i.refCount||s.fileCount-i.fileCount).slice(0,t)}function jc(e,n){let t=fe(e,n,{limit:500});return{symbol:n.symbol,shortName:_(n.symbol),refCount:t.length,fileCount:new Set(t.map(i=>i.file)).size,definedIn:n.relativePath}}function Ws(e,n){return Us(e,n)?.map(t=>({symbol:t.symbol,shortName:t.shortName,fromFile:t.fromFile}))??[]}function Hs(e,n){let i=e.all(`SELECT DISTINCT gs.symbol, d.relative_path AS importer
512
+ LIMIT ?`,t).filter(r=>!e.isIgnored(r.defined_in)).map(r=>({symbol:r.symbol,shortName:I(r.symbol),refCount:r.ref_count,fileCount:r.file_count,definedIn:r.defined_in}));return a.length>0?a:Ju(e,s,t)}function Ju(e,n,t){return Z(e,{scope:n}).filter(s=>!e.isIgnored(s.relativePath)).map(s=>Uu(e,s)).filter(s=>s.refCount>0).sort((s,i)=>i.refCount-s.refCount||i.fileCount-s.fileCount).slice(0,t)}function Uu(e,n){let t=he(e,n,{limit:500});return{symbol:n.symbol,shortName:I(n.symbol),refCount:t.length,fileCount:new Set(t.map(s=>s.file)).size,definedIn:n.relativePath}}function uo(e,n){return fo(e,n)?.map(t=>({symbol:t.symbol,shortName:t.shortName,fromFile:t.fromFile}))??[]}function mo(e,n){let s=e.all(`SELECT DISTINCT gs.symbol, d.relative_path AS importer
465
513
  FROM mentions m
466
514
  JOIN chunks c ON m.chunk_id = c.id
467
515
  JOIN documents d ON c.document_id = d.id
468
516
  JOIN global_symbols gs ON m.symbol_id = gs.id
469
517
  WHERE gs.symbol LIKE ?
470
518
  AND m.role = 2
471
- ORDER BY d.relative_path`,`%${n}%`).filter(m=>!e.isIgnored(m.importer)).map(m=>({symbol:m.symbol,shortName:_(m.symbol),fromFile:m.importer}));if(i.length>0)return i;let s=O(e,n),o=s?.relativePath??null,a=s?M(s.symbol):n.replace(/\(\)$/,""),r=s?We(s.symbol):!1,l=e.all(`SELECT relative_path
519
+ ORDER BY d.relative_path`,`%${n}%`).filter(m=>!e.isIgnored(m.importer)).map(m=>({symbol:m.symbol,shortName:I(m.symbol),fromFile:m.importer}));if(s.length>0)return s;let i=k(e,n),o=i?.relativePath??null,a=i?F(i.symbol):n.replace(/\(\)$/,""),r=i?Ge(i.symbol):!1,l=e.all(`SELECT relative_path
472
520
  FROM documents
473
521
  WHERE 1 = 1
474
522
  ${e.pathExclusionsFor("documents")}
475
- ORDER BY relative_path`),c=new Set;for(let m of l)if(!e.isIgnored(m.relative_path)){for(let u of me(e,m.relative_path))if(u.sourcePath&&!(o&&Bs(u.sourcePath)!==Bs(o))){if(u.kind==="side-effect"){c.add(m.relative_path);continue}if(o&&Wc(m.relative_path)){c.add(m.relative_path);continue}if(r){c.add(m.relative_path);continue}if(u.kind==="named"&&u.importedName===a){c.add(m.relative_path);continue}u.kind==="namespace"&&u.usedMembers.includes(a)&&c.add(m.relative_path)}}return[...c].sort().map(m=>({symbol:s?.symbol??a,shortName:s?_(s.symbol):a,fromFile:m}))}function Js(e,n){return Us(e,n)?.filter(t=>!t.used).map(t=>({symbol:t.symbol,shortName:t.shortName,importedIn:t.importer}))??[]}function Us(e,n){let t=Q(e,n);if(!t)return null;let s=e.all(`SELECT DISTINCT
523
+ ORDER BY relative_path`),c=new Set;for(let m of l)if(!e.isIgnored(m.relative_path)){for(let u of de(e,m.relative_path))if(u.sourcePath&&!(o&&co(u.sourcePath)!==co(o))){if(u.kind==="side-effect"){c.add(m.relative_path);continue}if(o&&zu(m.relative_path)){c.add(m.relative_path);continue}if(r){c.add(m.relative_path);continue}if(u.kind==="named"&&u.importedName===a){c.add(m.relative_path);continue}u.kind==="namespace"&&u.usedMembers.includes(a)&&c.add(m.relative_path)}}return[...c].sort().map(m=>({symbol:i?.symbol??a,shortName:i?I(i.symbol):a,fromFile:m}))}function po(e,n){return fo(e,n)?.filter(t=>!t.used).map(t=>({symbol:t.symbol,shortName:t.shortName,importedIn:t.importer}))??[]}function fo(e,n){let t=ee(e,n);if(!t)return null;let i=e.all(`SELECT DISTINCT
476
524
  gs.symbol,
477
525
  def_d.relative_path AS from_file,
478
526
  imp_d.relative_path AS importer,
@@ -498,11 +546,11 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
498
546
  LEFT JOIN documents def_d ON sym_def.document_id = def_d.id
499
547
  WHERE imp_d.relative_path = ?
500
548
  AND m.role = 2
501
- ORDER BY def_d.relative_path, gs.symbol`,t).filter(o=>!e.isIgnored(o.importer));return s.length>0?s.map(o=>({symbol:o.symbol,shortName:_(o.symbol),fromFile:o.from_file??"(external)",importer:o.importer,used:o.used!==0})):me(e,t).map(o=>{let a=Bc(o.importedName,o.localName,o.kind),r=o.kind==="side-effect"?!0:o.used;return{symbol:a,shortName:a,fromFile:o.sourcePath??"(external)",importer:t,used:r}})}function Bc(e,n,t){return t==="namespace"&&e==="*"&&n?`* as ${n}`:t==="default"&&n?`default as ${n}`:t==="side-effect"?"(side effect import)":n&&n!==e?`${e} as ${n}`:e}function Bs(e){return e.replace(/\\/g,"/")}function Wc(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function qs(e,n){let t=Ce(e,n),i=He(e,t,{sort:!0});if(i.length===0)return[];let s=i.map(r=>({symbol:r.symbol,shortName:r.shortName,startLine:r.startLine,endLine:r.endLine,children:[]})),o=new Map;for(let r of s)o.set(r.symbol,r);let a=[];for(let r=0;r<i.length;r++){let l=i[r],c=s[r];if(l.enclosingSymbol&&o.has(l.enclosingSymbol)){o.get(l.enclosingSymbol).children.push(c);continue}let m=null,u=1/0;for(let d of s)if(d!==c&&d.startLine<=c.startLine&&d.endLine>=c.endLine){if(d.startLine===c.startLine&&d.endLine===c.endLine&&!Bi(d.symbol,c.symbol))continue;let p=d.endLine-d.startLine;p<u&&(u=p,m=d)}m?m.children.push(c):a.push(c)}return a}function zs(e,n){let t=O(e,n);return t?A(e,t.relativePath).filter(i=>i.symbol!==t.symbol).filter(i=>ji(t.symbol,i.symbol)).sort((i,s)=>i.startLine-s.startLine||i.endLine-s.endLine).map(i=>({symbol:i.symbol,shortName:_(i.symbol),startLine:i.startLine,endLine:i.endLine,kind:ne(i.symbol)??"unknown"})):[]}function Gs(e,n){let t=O(e,n);if(!t)return[];let i=e.get(`SELECT COUNT(DISTINCT c.document_id) AS file_count
549
+ ORDER BY def_d.relative_path, gs.symbol`,t).filter(o=>!e.isIgnored(o.importer));return i.length>0?i.map(o=>({symbol:o.symbol,shortName:I(o.symbol),fromFile:o.from_file??"(external)",importer:o.importer,used:o.used!==0})):de(e,t).map(o=>{let a=qu(o.importedName,o.localName,o.kind),r=o.kind==="side-effect"?!0:o.used;return{symbol:a,shortName:a,fromFile:o.sourcePath??"(external)",importer:t,used:r}})}function qu(e,n,t){return t==="namespace"&&e==="*"&&n?`* as ${n}`:t==="default"&&n?`default as ${n}`:t==="side-effect"?"(side effect import)":n&&n!==e?`${e} as ${n}`:e}function co(e){return e.replace(/\\/g,"/")}function zu(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function go(e,n){let t=Le(e,n),s=Ke(e,t,{sort:!0});if(s.length===0)return[];let i=s.map(r=>({symbol:r.symbol,shortName:r.shortName,startLine:r.startLine,endLine:r.endLine,children:[]})),o=new Map;for(let r of i)o.set(r.symbol,r);let a=[];for(let r=0;r<s.length;r++){let l=s[r],c=i[r];if(l.enclosingSymbol&&o.has(l.enclosingSymbol)){o.get(l.enclosingSymbol).children.push(c);continue}let m=null,u=1/0;for(let d of i)if(d!==c&&d.startLine<=c.startLine&&d.endLine>=c.endLine){if(d.startLine===c.startLine&&d.endLine===c.endLine&&!ri(d.symbol,c.symbol))continue;let p=d.endLine-d.startLine;p<u&&(u=p,m=d)}m?m.children.push(c):a.push(c)}return a}function ho(e,n){let t=k(e,n);return t?A(e,t.relativePath).filter(s=>s.symbol!==t.symbol).filter(s=>oi(t.symbol,s.symbol)).sort((s,i)=>s.startLine-i.startLine||s.endLine-i.endLine).map(s=>({symbol:s.symbol,shortName:I(s.symbol),startLine:s.startLine,endLine:s.endLine,kind:ie(s.symbol)??"unknown"})):[]}function yo(e,n){let t=k(e,n);if(!t)return[];let s=e.get(`SELECT COUNT(DISTINCT c.document_id) AS file_count
502
550
  FROM mentions m
503
551
  JOIN chunks c ON m.chunk_id = c.id
504
552
  WHERE m.symbol_id = ?
505
- AND m.role != 1`,t.symbolId);return[{name:_(t.symbol),count:i?.file_count??0}]}function Ys(e,n){let t=Q(e,n);if(!t)return[];let s=e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
553
+ AND m.role != 1`,t.symbolId);return[{name:I(t.symbol),count:s?.file_count??0}]}function bo(e,n){let t=ee(e,n);if(!t)return[];let i=e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
506
554
  FROM mentions m
507
555
  JOIN chunks c ON m.chunk_id = c.id
508
556
  JOIN documents d ON c.document_id = d.id
@@ -519,7 +567,7 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
519
567
  AND m.role != 1
520
568
  AND def_d.id != d.id
521
569
  GROUP BY d.id
522
- ORDER BY symbol_count DESC`,t).filter(r=>!e.isIgnored(r.relative_path)).map(r=>({name:r.relative_path,count:r.symbol_count}));if(s.length>0)return s;let a=G(e).get(t);return!a||a.size===0?[]:[{name:t,count:a.size}]}function Ks(e,n={}){return Hc(e,n).map(t=>({name:_(t.symbol),count:t.file_count}))}function Hc(e,n){let{limit:t=30,scope:i}=n,s=i?`AND def_d.relative_path LIKE '%${i}%'`:"";return e.all(`SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
570
+ ORDER BY symbol_count DESC`,t).filter(r=>!e.isIgnored(r.relative_path)).map(r=>({name:r.relative_path,count:r.symbol_count}));if(i.length>0)return i;let a=K(e).get(t);return!a||a.size===0?[]:[{name:t,count:a.size}]}function So(e,n={}){return Vu(e,n).map(t=>({name:I(t.symbol),count:t.file_count}))}function Vu(e,n){let{limit:t=30,scope:s}=n,i=s?`AND def_d.relative_path LIKE '%${s}%'`:"";return e.all(`SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
523
571
  FROM mentions m
524
572
  JOIN chunks c ON m.chunk_id = c.id
525
573
  JOIN global_symbols gs ON m.symbol_id = gs.id
@@ -534,11 +582,11 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
534
582
  WHERE m.role != 1
535
583
  ${e.pathExclusionsFor("def_d")}
536
584
  ${e.symbolNoiseFor("gs")}
537
- ${s}
585
+ ${i}
538
586
  GROUP BY gs.id
539
587
  HAVING file_count > 1
540
588
  ORDER BY file_count DESC
541
- LIMIT ?`,t)}function Vs(e,n={}){let{limit:t=30,scope:i}=n,s=i?`AND d.relative_path LIKE '%${i}%'`:"";return e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
589
+ LIMIT ?`,t)}function _o(e,n={}){let{limit:t=30,scope:s}=n,i=s?`AND d.relative_path LIKE '%${s}%'`:"";return e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
542
590
  FROM mentions m
543
591
  JOIN chunks c ON m.chunk_id = c.id
544
592
  JOIN documents d ON c.document_id = d.id
@@ -555,10 +603,10 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
555
603
  AND def_d.id != d.id
556
604
  ${e.pathExclusionsFor("d")}
557
605
  ${e.symbolNoiseFor("gs")}
558
- ${s}
606
+ ${i}
559
607
  GROUP BY d.id
560
608
  ORDER BY symbol_count DESC
561
- LIMIT ?`,t).filter(a=>!e.isIgnored(a.relative_path)).map(a=>({name:a.relative_path,count:a.symbol_count}))}function Qs(e,n,t){let i=Q(e,n)??n,s=Q(e,t)??t,o=e.get(`SELECT COUNT(DISTINCT gs.id) AS shared
609
+ LIMIT ?`,t).filter(a=>!e.isIgnored(a.relative_path)).map(a=>({name:a.relative_path,count:a.symbol_count}))}function xo(e,n,t){let s=ee(e,n)??n,i=ee(e,t)??t,o=e.get(`SELECT COUNT(DISTINCT gs.id) AS shared
562
610
  FROM global_symbols gs
563
611
  WHERE (
564
612
  -- Defined in file1, referenced in file2
@@ -590,7 +638,7 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
590
638
  JOIN documents d ON c.document_id = d.id
591
639
  WHERE m.symbol_id = gs.id AND m.role != 1 AND d.relative_path = ?
592
640
  )
593
- )`,i,s,s,i);return{file1:i,file2:s,sharedSymbols:o?.shared??0}}function Xs(e,n={}){let{limit:t=20,scope:i}=n,s=i?`AND d1.relative_path LIKE '%${i}%' AND d2.relative_path LIKE '%${i}%'`:"";return e.all(`SELECT
641
+ )`,s,i,i,s);return{file1:s,file2:i,sharedSymbols:o?.shared??0}}function Io(e,n={}){let{limit:t=20,scope:s}=n,i=s?`AND d1.relative_path LIKE '%${s}%' AND d2.relative_path LIKE '%${s}%'`:"";return e.all(`SELECT
594
642
  def_d.relative_path AS file1,
595
643
  ref_d.relative_path AS file2,
596
644
  COUNT(DISTINCT gs.id) AS shared
@@ -609,10 +657,10 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
609
657
  WHERE m.role != 1
610
658
  AND def_d.id != ref_d.id
611
659
  ${e.pathExclusionsFor("def_d","ref_d")}
612
- ${s}
660
+ ${i}
613
661
  GROUP BY def_d.id, ref_d.id
614
662
  ORDER BY shared DESC
615
- LIMIT ?`,t).filter(a=>!e.isIgnored(a.file1)&&!e.isIgnored(a.file2)).map(a=>({file1:a.file1,file2:a.file2,sharedSymbols:a.shared}))}function qt(e,n={}){let{scope:t,maxDepth:i=10}=n,s=G(e,t),o=[],a=new Set,r=new Set,l=[];function c(u,d){if(d>i)return;if(r.has(u)){let p=l.indexOf(u);if(p!==-1){let g=l.slice(p).concat(u),y=g.indexOf(g.reduce((x,S)=>x<S?x:S)),h=[...g.slice(y,-1),...g.slice(0,y),g[y]],b=h.join(" -> ");m.has(b)||(m.add(b),o.push({path:h,kind:Jc(h)}))}return}if(a.has(u))return;a.add(u),r.add(u),l.push(u);let f=s.get(u);if(f)for(let p of f)c(p,d+1);l.pop(),r.delete(u)}let m=new Set;for(let u of s.keys())a.has(u)||c(u,0);return o.sort((u,d)=>u.kind!==d.kind?u.kind==="real"?-1:1:u.path.length-d.path.length),o}function Jc(e){if(e.length!==3)return"real";let[n,t]=e;return!n||!t?"real":Ht(n)||Ht(t)?"module-hierarchy":"real"}function Zs(e,n={}){let{limit:t=20,scope:i,minFanIn:s=2,minFanOut:o=2}=n,a=i?`AND def_d.relative_path LIKE '%${i}%'`:"",l=e.all(`SELECT * FROM (
663
+ LIMIT ?`,t).filter(a=>!e.isIgnored(a.file1)&&!e.isIgnored(a.file2)).map(a=>({file1:a.file1,file2:a.file2,sharedSymbols:a.shared}))}function nn(e,n={}){let{scope:t,maxDepth:s=10}=n,i=K(e,t),o=[],a=new Set,r=new Set,l=[];function c(u,d){if(d>s)return;if(r.has(u)){let p=l.indexOf(u);if(p!==-1){let f=l.slice(p).concat(u),y=f.indexOf(f.reduce((_,S)=>_<S?_:S)),h=[...f.slice(y,-1),...f.slice(0,y),f[y]],b=h.join(" -> ");m.has(b)||(m.add(b),o.push({path:h,kind:Gu(h)}))}return}if(a.has(u))return;a.add(u),r.add(u),l.push(u);let g=i.get(u);if(g)for(let p of g)c(p,d+1);l.pop(),r.delete(u)}let m=new Set;for(let u of i.keys())a.has(u)||c(u,0);return o.sort((u,d)=>u.kind!==d.kind?u.kind==="real"?-1:1:u.path.length-d.path.length),o}function Gu(e){for(let s of e){let i=U(s);if(i==="test"||i==="barrel"||i==="entry")return"module-hierarchy"}if(e.length!==3)return"real";let[n,t]=e;return!n||!t?"real":en(n)||en(t)||No(n,t)||No(t,n)||vo(n,t)||vo(t,n)||U(n)==="entry"||U(t)==="entry"?"module-hierarchy":"real"}function No(e,n){if(!/\.rs$/.test(e)||!/\.rs$/.test(n))return!1;let t=n.replace(/\.rs$/,"/");return e.startsWith(t)?!e.slice(t.length).includes("/"):!1}function vo(e,n){if(!/\.rs$/.test(e)||!/\.rs$/.test(n))return!1;let t=e.replace(/\.rs$/,""),s=n.replace(/\.rs$/,"");if(t===s+"_tests"||t===s+"/tests")return!0;let i=e.split("/"),o=n.split("/");if(i.length===o.length&&i.includes("tests")&&o.includes("src")){let a=i[i.length-1],r=o[o.length-1];if(a&&a===r)return!0}return!1}function Co(e,n={}){let{limit:t=20,scope:s,minFanIn:i=2,minFanOut:o=2}=n,a=s?`AND def_d.relative_path LIKE '%${s}%'`:"",l=e.all(`SELECT * FROM (
616
664
  SELECT
617
665
  gs.symbol,
618
666
  def_d.relative_path AS defined_in,
@@ -651,22 +699,22 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
651
699
  ${a}
652
700
  ) WHERE fan_in >= ? AND fan_out >= ?
653
701
  ORDER BY (fan_in * fan_out) DESC
654
- LIMIT ?`,s,o,t).filter(c=>!e.isIgnored(c.defined_in)).map(c=>({symbol:c.symbol,shortName:_(c.symbol),fanIn:c.fan_in,fanOut:c.fan_out,score:c.fan_in*c.fan_out,definedIn:c.defined_in}));return l.length>0?l:Uc(e,i,{minFanIn:s,minFanOut:o,limit:t})}function Uc(e,n,t){let{minFanIn:i,minFanOut:s,limit:o}=t;return V(e,{scope:n}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>qc(e,r)).filter(r=>r.fanIn>=i&&r.fanOut>=s).sort((r,l)=>l.score-r.score||l.fanIn-r.fanIn).slice(0,o)}function qc(e,n){let t=new Set(fe(e,n,{limit:500}).map(s=>s.file)).size,i=new Set(Z(e,n,{limit:500}).filter(s=>s.file!==n.relativePath).map(s=>`${s.symbol}|${s.file}`)).size;return{symbol:n.symbol,shortName:_(n.symbol),fanIn:t,fanOut:i,score:t*i,definedIn:n.relativePath}}function zt(e,n={}){let{scope:t,minLoc:i=3}=n,o=z(e,t).filter(d=>!e.isIgnored(d.relativePath)).filter(d=>!Ie(e,d.relativePath)).filter(d=>d.isFunctionLike).filter(d=>d.endLine-d.startLine+1>=i),a=ge(e,o),r=Ve(e,o),l=new Set([...a.keys(),...r.keys()]),c=new Map(o.map(d=>[d.symbolId,d.symbol])),m=ee(e,o,{additive:!0}),u=new Set([...m.entries()].filter(([d,f])=>{let p=c.get(d);return f.some(g=>g.symbol!==p)}).map(([d])=>d));return o.filter(d=>!l.has(d.symbolId)).filter(d=>!u.has(d.symbolId)).sort((d,f)=>f.endLine-f.startLine-(d.endLine-d.startLine)||d.relativePath.localeCompare(f.relativePath)||d.startLine-f.startLine).map(d=>({symbol:d.symbol,shortName:_(d.symbol),relativePath:d.relativePath,startLine:d.startLine,endLine:d.endLine,loc:d.endLine-d.startLine+1}))}var Pn={0:"UnspecifiedKind",1:"AbstractMethod",2:"Accessor",3:"Array",4:"Assertion",5:"AssociatedType",6:"Attribute",7:"Axiom",8:"Boolean",9:"Class",10:"Constant",11:"Constructor",12:"Contract",13:"DataFamily",14:"DefinitionMacro",15:"Delegate",16:"Enum",17:"EnumMember",18:"Error",19:"Event",20:"Fact",21:"Field",22:"File",23:"Function",24:"Getter",25:"Grammar",26:"Instance",27:"Interface",28:"Key",29:"Lang",30:"Lemma",31:"Library",32:"Macro",33:"Method",34:"MethodAlias",35:"MethodReceiver",36:"MethodSpecification",37:"Message",38:"Modifier",39:"Module",40:"Namespace",41:"Null",42:"Number",43:"Object",44:"Operator",45:"Package",46:"PackageObject",47:"Parameter",48:"ParameterLabel",49:"Pattern",50:"Predicate",51:"Property",52:"Protocol",53:"ProtocolMethod",54:"PureVirtualMethod",55:"Quasiquoter",56:"SelfParameter",57:"Setter",58:"Signature",59:"SingletonClass",60:"SingletonMethod",61:"StaticDataMember",62:"StaticEvent",63:"StaticField",64:"StaticMethod",65:"StaticProperty",66:"StaticVariable",67:"String",68:"Struct",69:"Subscript",70:"Tactic",71:"Theorem",72:"ThisParameter",73:"Trait",74:"TraitMethod",75:"Type",76:"TypeAlias",77:"TypeClass",78:"TypeClassMethod",79:"TypeFamily",80:"TypeParameter",81:"Union",82:"Value",83:"Variable"},kn=new Map;for(let[e,n]of Object.entries(Pn))kn.set(n.toLowerCase(),Number(e));function zc(e){let n=parseInt(e,10);if(!isNaN(n))return n;let t=e.toLowerCase(),i=kn.get(t);if(i!==void 0)return i;for(let[s,o]of kn)if(s.includes(t))return o;return null}function eo(e,n,t={}){let{scope:i,limit:s=100}=t,o=zc(n);return o===null?[]:no(e,i).map(r=>({row:r,resolvedKind:io(r)})).filter(r=>r.resolvedKind===o).slice(0,s).map(({row:r,resolvedKind:l})=>({symbol:r.symbol,shortName:_(r.symbol),kind:l,kindName:Pn[l]??"Unknown",relativePath:r.relative_path,startLine:r.start_line,endLine:r.end_line}))}function to(e,n={}){let t=new Map;for(let i of no(e,n.scope)){let s=io(i);s===null||s===0||t.set(s,(t.get(s)??0)+1)}return[...t.entries()].sort((i,s)=>s[1]-i[1]||i[0]-s[0]).map(([i,s])=>({kind:i,kindName:Pn[i]??"Unknown",count:s}))}function no(e,n){return V(e,{scope:n}).map(Gc)}function Gc(e){return{symbol:e.symbol,kind:e.kind,documentation:e.documentation,enclosing_symbol:e.enclosingSymbol,relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine}}function io(e){return e.kind!==null&&e.kind!==0?Yc(e.kind,e.symbol,e.documentation):Kc(e.symbol,e.documentation,e.enclosing_symbol)}function Yc(e,n,t){let i=(t??"").toLowerCase();if(ne(n)==="type"){if(i.includes("type "))return 76;if(i.includes("interface "))return 27;if(i.includes("struct "))return 68;if(i.includes("trait "))return 73;if(i.includes("class "))return 9}return e}function Kc(e,n,t){let i=te(e);if("kind"in i)return null;let s=i.descriptors,o=s[s.length-2]??null,a=ne(e),r=(n??"").toLowerCase();return a==="type"?r.includes("type ")?76:r.includes("interface ")?27:r.includes("struct ")?68:r.includes("trait ")?73:(r.includes("class "),9):a==="method"?o?.suffix==="type"?33:23:a==="namespace"?39:a!=="term"?null:r.includes("async def ")||r.includes("def ")?23:(t?ne(t):o?.suffix??null)==="type"?21:83}function so(e,n={}){let{limit:t=10,scope:i,minDepth:s=3}=n,o=G(e,i),a=new Map,r=[],l=new Map,c=new Map,m=new Set,u=[],d=0;for(let I of o.keys()){if(l.has(I))continue;let L=[],D=(o.get(I)??new Set).values();for(l.set(I,d),c.set(I,d),d+=1,u.push(I),m.add(I),L.push({node:I,iter:D,pendingChild:null});L.length>0;){let k=L[L.length-1];if(k.pendingChild!==null){let F=k.pendingChild;k.pendingChild=null,c.set(k.node,Math.min(c.get(k.node),c.get(F)))}let U=k.iter.next();if(U.done){if(c.get(k.node)===l.get(k.node)){let F=[];for(;;){let Se=u.pop();if(m.delete(Se),F.push(Se),a.set(Se,r.length),Se===k.node)break}r.push(F)}L.pop();continue}let B=U.value;if(l.has(B))m.has(B)&&c.set(k.node,Math.min(c.get(k.node),l.get(B)));else{l.set(B,d),c.set(B,d),d+=1,u.push(B),m.add(B);let F=(o.get(B)??new Set).values();k.pendingChild=B,L.push({node:B,iter:F,pendingChild:null})}}}let f=new Map,p=new Array(r.length);for(let I=0;I<r.length;I++)p[I]=r[I].length,f.set(I,new Set);for(let[I,L]of o){let D=a.get(I);for(let k of L){let U=a.get(k);U!==D&&f.get(D).add(U)}}let g=new Array(r.length),y=new Array(r.length);for(let I=0;I<r.length;I++){let L=[],D=0;for(let k of f.get(I)){let U=y[k];U>D&&(D=U,L=g[k])}g[I]=[I,...L],y[I]=p[I]+D}function h(I){return g[I]}let b=r.map(I=>[...I].sort()),x=new Set,S=[];for(let I=0;I<r.length;I++){let L=h(I),D=[];for(let U of L)D.push(...b[U]);if(D.length<s)continue;let k=D.join(" ");x.has(k)||(x.add(k),S.push({chain:D,depth:D.length}))}return S.sort((I,L)=>L.depth-I.depth),S.slice(0,t)}function oo(e,n){let t=O(e,n);if(!t)return[];let i=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
655
- WHERE id = ? LIMIT 1`,t.symbolId);if(!i)return[];let s=[{symbol:i.symbol,shortName:_(i.symbol),depth:0}],o=i.enclosing_symbol,a=1,r=new Set([i.symbol]);for(;o&&!r.has(o)&&a<20;){r.add(o);let u=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",o);if(!u)break;s.push({symbol:u.symbol,shortName:_(u.symbol),depth:a}),o=u.enclosing_symbol,a++}if(s.length>1)return s;let l=te(i.symbol);if("kind"in l)return s;let c=l.descriptors;if(c.length<=1)return s;let m=[s[0]];for(let u=c.length-2,d=1;u>=0;u--,d++){let p=c.slice(0,u+1).map(g=>g.suffix==="method"?`${g.name}()`:g.name.replace(/\.(ts|tsx|js|jsx|mjs|cjs|py|pyi|rs|java|scala|kt|kts|rb|go|cs|vb|dart|php|c|cc|cpp|cxx|h|hpp)$/,"")).join(":");m.push({symbol:p,shortName:p,depth:d})}return m}function ro(e,n){let t=O(e,n);if(!t)return null;let i=fe(e,t,{limit:50}),s=Vc(Z(e,t,{limit:50}));return{symbol:t.symbol,shortName:_(t.symbol),callers:i.map(o=>({symbol:o.symbol,shortName:_(o.symbol),file:o.file})),callees:s.map(o=>({symbol:o.symbol,shortName:_(o.symbol),file:o.file}))}}function Vc(e){let n=new Set,t=[];for(let i of e){let s=`${i.symbol}|${i.file}`;n.has(s)||(n.add(s),t.push(i))}return t}function lt(e,n){let t=new Set;for(let i of e)n.has(i)&&t.add(i);return t}function ct(e,n){let t=new Set;for(let i of e)n.has(i)||t.add(i);return t}function ao(e,n){if(e.size===0&&n.size===0)return 0;let t=0;for(let s of e)n.has(s)&&(t+=1);let i=e.size+n.size-t;return i===0?0:t/i}function Mn(e){let n=e.length;if(n===0)return new Map;let t=new Map;for(let s of e)for(let o of s)t.set(o,(t.get(o)??0)+1);let i=new Map;for(let[s,o]of t)i.set(s,Math.log(n/o));return i}function Qc(e){let n=[...e.values()].sort((i,s)=>i-s);if(n.length===0)return 0;let t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function lo(e,n,t){let i=lt(e,n);if(i.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let s=0,o=0,a=0,r=new Set([...e,...n]);for(let f of r){let p=t.get(f)??0,g=e.has(f)?p:0,y=n.has(f)?p:0;s+=g*y,o+=g*g,a+=y*y}let l=Math.sqrt(o)*Math.sqrt(a),c=l>0?s/l:0,m=Qc(t),u=[],d=[];for(let f of i)(t.get(f)??0)>=m?u.push(f):d.push(f);return u.sort((f,p)=>(t.get(p)??0)-(t.get(f)??0)),{similarity:c,significantShared:u,trivialShared:d}}function co(e,n,t={}){let{minSimilarity:i=.4,limit:s=20}=t,o=Zc(e,n);if(!o)return[];if(!j(o.symbol))return[];let a=Xc(e,o,i);return a.length>0?a.slice(0,s):em(e,n,{minSimilarity:i,limit:s})}function Xc(e,n,t){let i=uo(e,{minCallees:3,excludeSymbol:n.symbol}),s=Mn([n,...i].map(a=>a.callees)),o=[];for(let a of i){if(a.callees.size<3)continue;let r=mo(n,a,s,{minSimilarity:t,requireSignificantShared:1,requireSharedCount:0});r&&o.push(r)}return o.sort((a,r)=>r.similarity-a.similarity),o}function mo(e,n,t,i){let{similarity:s,significantShared:o}=lo(e.callees,n.callees,t);if(s<i.minSimilarity)return null;let a=lt(e.callees,n.callees).size;if(o.length<i.requireSignificantShared&&a<i.requireSharedCount)return null;let r=o.length>0?o:[...lt(e.callees,n.callees)];return{symbolA:e.symbol,shortNameA:_(e.symbol),fileA:e.file,symbolB:n.symbol,shortNameB:_(n.symbol),fileB:n.file,similarity:s,sharedCallees:r.map(_),uniqueToA:[...ct(e.callees,n.callees)].map(_),uniqueToB:[...ct(n.callees,e.callees)].map(_)}}function Gt(e,n={}){let{minSimilarity:t=.5,limit:i=20,scope:s,minCallees:o=4,crossFileOnly:a=!1}=n,r=uo(e,{minCallees:o,scope:s}),l=Mn(r.map(p=>p.callees)),c=new Map;for(let p of r)for(let g of p.callees)c.set(g,(c.get(g)??0)+1);let m=Math.max(8,Math.ceil(Math.sqrt(r.length))),u=new Map;for(let p=0;p<r.length;p+=1)for(let g of r[p].callees){if((c.get(g)??0)>m)continue;let y=u.get(g);y||(y=[],u.set(g,y)),y.push(p)}let d=[],f=new Set;e:for(let p=0;p<r.length;p+=1){let g=r[p],y=new Set;for(let h of g.callees){let b=u.get(h);if(b)for(let x of b)x>p&&y.add(x)}for(let h of y){let b=`${p}|${h}`;if(f.has(b))continue;f.add(b);let x=r[h];if(a&&g.file===x.file)continue;if(g.paramCount>=0&&x.paramCount>=0){let I=Math.abs(g.paramCount-x.paramCount),L=Math.max(2,Math.ceil(Math.max(g.paramCount,x.paramCount)*.5));if(I>L)continue}let S=mo(g,x,l,{minSimilarity:t,requireSignificantShared:2,requireSharedCount:4});if(S&&(d.push(S),d.length>i*5))break e}}return d.sort((p,g)=>g.similarity-p.similarity),d.slice(0,i)}function Zc(e,n){let t=O(e,n);if(!t)return null;let i=Z(e,t);return{symbol:t.symbol,file:t.relativePath,callees:new Set(i.map(s=>s.symbol)),paramCount:xn(e,t.relativePath,t.startLine,t.endLine)?.paramCount??-1}}function uo(e,n){let{minCallees:t,scope:i,excludeSymbol:s}=n,o=z(e,i).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>r.isFunctionLike).filter(r=>s===void 0||r.symbol!==s).filter(r=>r.endLine-r.startLine+1>=5).filter(r=>!ue(e,r.relativePath,r.startLine)),a=ee(e,o);return o.map(r=>({symbol:r.symbol,file:r.relativePath,callees:new Set((a.get(r.symbolId)??[]).map(l=>l.symbol)),paramCount:xn(e,r.relativePath,r.startLine,r.endLine)?.paramCount??-1})).filter(r=>r.callees.size>=t)}function em(e,n,t){let i=tm(e,n);if(!i||i.tokens.size<3)return[];let s=t.minSimilarity>=.5?t.minSimilarity:.3,o=[];for(let a of im(e)){if(a.symbol===i.symbol||a.tokens.size<3)continue;let r=lt(i.tokens,a.tokens);if(r.size<2)continue;let l=new Set([...i.tokens,...a.tokens]),c=l.size>0?r.size/l.size:0;c<s||o.push({symbolA:i.symbol,shortNameA:_(i.symbol),fileA:i.file,symbolB:a.symbol,shortNameB:_(a.symbol),fileB:a.file,similarity:c,sharedCallees:[...r].sort(),uniqueToA:[...ct(i.tokens,a.tokens)].sort(),uniqueToB:[...ct(a.tokens,i.tokens)].sort()})}return o.sort((a,r)=>r.similarity-a.similarity||a.shortNameB.localeCompare(r.shortNameB)),o.slice(0,t.limit)}function tm(e,n){let t=O(e,n);if(!t||!j(t.symbol))return null;let i=nm(e,t);return i?{symbol:t.symbol,file:t.relativePath,tokens:i}:null}function nm(e,n){let t=M(n.symbol),i=po(e,n.relativePath,n.startLine,n.endLine,t),s=fo(i,t);return s.size>0?s:null}function im(e){return V(e).filter(n=>n.isFunctionLike).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:fo(po(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function po(e,n,t,i,s){let o=P(e,n);if(!o)return"";let a=o.split(`
656
- `);if(i>=t&&i-t<=12)return a.slice(t,i+1).join(`
657
- `);let r=[new RegExp(`\\bdef\\s+${mt(s)}\\b`),new RegExp(`\\bfun\\s+${mt(s)}\\b`),new RegExp(`\\bfn\\s+${mt(s)}\\b`),new RegExp(`\\bfunction\\s+${mt(s)}\\b`),new RegExp(`\\b${mt(s)}\\s*\\(`)],l=a.findIndex(c=>r.some(m=>m.test(c)));if(l>=0){let c=l;for(let m=l+1;m<a.length&&m<=l+8;m++){let u=a[m]??"";if(m>l&&om(u)||(c=m,u.trim()===""&&m>l+1))break}return a.slice(l,c+1).join(`
702
+ LIMIT ?`,i,o,t).filter(c=>!e.isIgnored(c.defined_in)).map(c=>({symbol:c.symbol,shortName:I(c.symbol),fanIn:c.fan_in,fanOut:c.fan_out,score:c.fan_in*c.fan_out,definedIn:c.defined_in}));return l.length>0?l:Yu(e,s,{minFanIn:i,minFanOut:o,limit:t})}function Yu(e,n,t){let{minFanIn:s,minFanOut:i,limit:o}=t;return Z(e,{scope:n}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>Ku(e,r)).filter(r=>r.fanIn>=s&&r.fanOut>=i).sort((r,l)=>l.score-r.score||l.fanIn-r.fanIn).slice(0,o)}function Ku(e,n){let t=new Set(he(e,n,{limit:500}).map(i=>i.file)).size,s=new Set(ne(e,n,{limit:500}).filter(i=>i.file!==n.relativePath).map(i=>`${i.symbol}|${i.file}`)).size;return{symbol:n.symbol,shortName:I(n.symbol),fanIn:t,fanOut:s,score:t*s,definedIn:n.relativePath}}function sn(e,n={}){let{scope:t,minLoc:s=3}=n,o=Y(e,t).filter(p=>!e.isIgnored(p.relativePath)).filter(p=>!ve(e,p.relativePath)).filter(p=>p.isFunctionLike).filter(p=>!Ye(p.symbol)).filter(p=>!G(p.symbol)).filter(p=>p.endLine-p.startLine+1>=s),a=ye(e,o),r=ot(e,o),l=new Set([...a.keys(),...r.keys()]),c=new Map;for(let p of o){let f=F(p.symbol);if(!f)continue;let y=c.get(f)??[];y.push(p.symbolId),c.set(f,y)}let m=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of m){if(e.isIgnored(p.relative_path)||P(p.relative_path)!=="rust")continue;let f=we(e,p.relative_path);for(let y of f){let h=c.get(y);if(h)for(let b of h)l.add(b)}}let u=new Map(o.map(p=>[p.symbolId,p.symbol])),d=se(e,o,{additive:!0}),g=new Set([...d.entries()].filter(([p,f])=>{let y=u.get(p);return f.some(h=>h.symbol!==y)}).map(([p])=>p));return o.filter(p=>!l.has(p.symbolId)).filter(p=>!g.has(p.symbolId)).sort((p,f)=>f.endLine-f.startLine-(p.endLine-p.startLine)||p.relativePath.localeCompare(f.relativePath)||p.startLine-f.startLine).map(p=>({symbol:p.symbol,shortName:I(p.symbol),relativePath:p.relativePath,startLine:p.startLine,endLine:p.endLine,loc:p.endLine-p.startLine+1}))}var Vn={0:"UnspecifiedKind",1:"AbstractMethod",2:"Accessor",3:"Array",4:"Assertion",5:"AssociatedType",6:"Attribute",7:"Axiom",8:"Boolean",9:"Class",10:"Constant",11:"Constructor",12:"Contract",13:"DataFamily",14:"DefinitionMacro",15:"Delegate",16:"Enum",17:"EnumMember",18:"Error",19:"Event",20:"Fact",21:"Field",22:"File",23:"Function",24:"Getter",25:"Grammar",26:"Instance",27:"Interface",28:"Key",29:"Lang",30:"Lemma",31:"Library",32:"Macro",33:"Method",34:"MethodAlias",35:"MethodReceiver",36:"MethodSpecification",37:"Message",38:"Modifier",39:"Module",40:"Namespace",41:"Null",42:"Number",43:"Object",44:"Operator",45:"Package",46:"PackageObject",47:"Parameter",48:"ParameterLabel",49:"Pattern",50:"Predicate",51:"Property",52:"Protocol",53:"ProtocolMethod",54:"PureVirtualMethod",55:"Quasiquoter",56:"SelfParameter",57:"Setter",58:"Signature",59:"SingletonClass",60:"SingletonMethod",61:"StaticDataMember",62:"StaticEvent",63:"StaticField",64:"StaticMethod",65:"StaticProperty",66:"StaticVariable",67:"String",68:"Struct",69:"Subscript",70:"Tactic",71:"Theorem",72:"ThisParameter",73:"Trait",74:"TraitMethod",75:"Type",76:"TypeAlias",77:"TypeClass",78:"TypeClassMethod",79:"TypeFamily",80:"TypeParameter",81:"Union",82:"Value",83:"Variable"},zn=new Map;for(let[e,n]of Object.entries(Vn))zn.set(n.toLowerCase(),Number(e));function Qu(e){let n=parseInt(e,10);if(!isNaN(n))return n;let t=e.toLowerCase(),s=zn.get(t);if(s!==void 0)return s;for(let[i,o]of zn)if(i.includes(t))return o;return null}function Eo(e,n,t={}){let{scope:s,limit:i=100}=t,o=Qu(n);return o===null?[]:Lo(e,s).map(r=>({row:r,resolvedKind:wo(r)})).filter(r=>r.resolvedKind===o).slice(0,i).map(({row:r,resolvedKind:l})=>({symbol:r.symbol,shortName:I(r.symbol),kind:l,kindName:Vn[l]??"Unknown",relativePath:r.relative_path,startLine:r.start_line,endLine:r.end_line}))}function Ro(e,n={}){let t=new Map;for(let s of Lo(e,n.scope)){let i=wo(s);i===null||i===0||t.set(i,(t.get(i)??0)+1)}return[...t.entries()].sort((s,i)=>i[1]-s[1]||s[0]-i[0]).map(([s,i])=>({kind:s,kindName:Vn[s]??"Unknown",count:i}))}function Lo(e,n){return Z(e,{scope:n}).map(Xu)}function Xu(e){return{symbol:e.symbol,kind:e.kind,documentation:e.documentation,enclosing_symbol:e.enclosingSymbol,relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine}}function wo(e){return e.kind!==null&&e.kind!==0?Zu(e.kind,e.symbol,e.documentation):em(e.symbol,e.documentation,e.enclosing_symbol)}function Zu(e,n,t){let s=(t??"").toLowerCase();if(ie(n)==="type"){if(s.includes("type "))return 76;if(s.includes("interface "))return 27;if(s.includes("struct "))return 68;if(s.includes("trait "))return 73;if(s.includes("class "))return 9}return e}function em(e,n,t){let s=V(e);if("kind"in s)return null;let i=s.descriptors,o=i[i.length-2]??null,a=ie(e),r=(n??"").toLowerCase();return a==="type"?r.includes("type ")?76:r.includes("interface ")?27:r.includes("struct ")?68:r.includes("trait ")?73:(r.includes("class "),9):a==="method"?o?.suffix==="type"?33:23:a==="namespace"?39:a!=="term"?null:r.includes("async def ")||r.includes("def ")?23:(t?ie(t):o?.suffix??null)==="type"?21:83}function Do(e,n={}){let{limit:t=10,scope:s,minDepth:i=3}=n,o=K(e,s),a=new Map,r=[],l=new Map,c=new Map,m=new Set,u=[],d=0;for(let x of o.keys()){if(l.has(x))continue;let L=[],w=(o.get(x)??new Set).values();for(l.set(x,d),c.set(x,d),d+=1,u.push(x),m.add(x),L.push({node:x,iter:w,pendingChild:null});L.length>0;){let $=L[L.length-1];if($.pendingChild!==null){let T=$.pendingChild;$.pendingChild=null,c.set($.node,Math.min(c.get($.node),c.get(T)))}let q=$.iter.next();if(q.done){if(c.get($.node)===l.get($.node)){let T=[];for(;;){let _e=u.pop();if(m.delete(_e),T.push(_e),a.set(_e,r.length),_e===$.node)break}r.push(T)}L.pop();continue}let B=q.value;if(l.has(B))m.has(B)&&c.set($.node,Math.min(c.get($.node),l.get(B)));else{l.set(B,d),c.set(B,d),d+=1,u.push(B),m.add(B);let T=(o.get(B)??new Set).values();$.pendingChild=B,L.push({node:B,iter:T,pendingChild:null})}}}let g=new Map,p=new Array(r.length);for(let x=0;x<r.length;x++)p[x]=r[x].length,g.set(x,new Set);for(let[x,L]of o){let w=a.get(x);for(let $ of L){let q=a.get($);q!==w&&g.get(w).add(q)}}let f=new Array(r.length),y=new Array(r.length);for(let x=0;x<r.length;x++){let L=[],w=0;for(let $ of g.get(x)){let q=y[$];q>w&&(w=q,L=f[$])}f[x]=[x,...L],y[x]=p[x]+w}function h(x){return f[x]}let b=r.map(x=>[...x].sort()),_=new Set,S=[];for(let x=0;x<r.length;x++){let L=h(x),w=[];for(let q of L)w.push(...b[q]);if(w.length<i)continue;let $=w.join(" ");_.has($)||(_.add($),S.push({chain:w,depth:w.length}))}return S.sort((x,L)=>L.depth-x.depth),S.slice(0,t)}function ko(e,n){let t=k(e,n);if(!t)return[];let s=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
703
+ WHERE id = ? LIMIT 1`,t.symbolId);if(!s)return[];let i=[{symbol:s.symbol,shortName:I(s.symbol),depth:0}],o=s.enclosing_symbol,a=1,r=new Set([s.symbol]);for(;o&&!r.has(o)&&a<20;){r.add(o);let u=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",o);if(!u)break;i.push({symbol:u.symbol,shortName:I(u.symbol),depth:a}),o=u.enclosing_symbol,a++}if(i.length>1)return i;let l=V(s.symbol);if("kind"in l)return i;let c=l.descriptors;if(c.length<=1)return i;let m=[i[0]];for(let u=c.length-2,d=1;u>=0;u--,d++){let p=c.slice(0,u+1).map(f=>f.suffix==="method"?`${f.name}()`:f.name.replace(/\.(ts|tsx|js|jsx|mjs|cjs|py|pyi|rs|java|scala|kt|kts|rb|go|cs|vb|dart|php|c|cc|cpp|cxx|h|hpp)$/,"")).join(":");m.push({symbol:p,shortName:p,depth:d})}return m}function Oo(e,n){let t=k(e,n);if(!t)return null;let s=he(e,t,{limit:50}),i=tm(ne(e,t,{limit:50}));return{symbol:t.symbol,shortName:I(t.symbol),callers:s.map(o=>({symbol:o.symbol,shortName:I(o.symbol),file:o.file})),callees:i.map(o=>({symbol:o.symbol,shortName:I(o.symbol),file:o.file}))}}function tm(e){let n=new Set,t=[];for(let s of e){let i=`${s.symbol}|${s.file}`;n.has(i)||(n.add(i),t.push(s))}return t}function xt(e,n){let t=new Set;for(let s of e)n.has(s)&&t.add(s);return t}function It(e,n){let t=new Set;for(let s of e)n.has(s)||t.add(s);return t}function $o(e,n){if(e.size===0&&n.size===0)return 0;let t=0;for(let i of e)n.has(i)&&(t+=1);let s=e.size+n.size-t;return s===0?0:t/s}function Gn(e){let n=e.length;if(n===0)return new Map;let t=new Map;for(let i of e)for(let o of i)t.set(o,(t.get(o)??0)+1);let s=new Map;for(let[i,o]of t)s.set(i,Math.log(n/o));return s}function nm(e){let n=[...e.values()].sort((s,i)=>s-i);if(n.length===0)return 0;let t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function Po(e,n,t){let s=xt(e,n);if(s.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let i=0,o=0,a=0,r=new Set([...e,...n]);for(let g of r){let p=t.get(g)??0,f=e.has(g)?p:0,y=n.has(g)?p:0;i+=f*y,o+=f*f,a+=y*y}let l=Math.sqrt(o)*Math.sqrt(a),c=l>0?i/l:0,m=nm(t),u=[],d=[];for(let g of s)(t.get(g)??0)>=m?u.push(g):d.push(g);return u.sort((g,p)=>(t.get(p)??0)-(t.get(g)??0)),{similarity:c,significantShared:u,trivialShared:d}}function Mo(e,n,t={}){let{minSimilarity:s=.4,limit:i=20}=t,o=im(e,n);if(!o)return[];if(!j(o.symbol))return[];let a=sm(e,o,s);return a.length>0?a.slice(0,i):om(e,n,{minSimilarity:s,limit:i})}function sm(e,n,t){let s=To(e,{minCallees:3,excludeSymbol:n.symbol}),i=Gn([n,...s].map(a=>a.callees)),o=[];for(let a of s){if(a.callees.size<3)continue;let r=Fo(n,a,i,{minSimilarity:t,requireSignificantShared:1,requireSharedCount:0});r&&o.push(r)}return o.sort((a,r)=>r.similarity-a.similarity),o}function Fo(e,n,t,s){let{similarity:i,significantShared:o}=Po(e.callees,n.callees,t);if(i<s.minSimilarity)return null;let a=xt(e.callees,n.callees).size;if(o.length<s.requireSignificantShared&&a<s.requireSharedCount)return null;let r=o.length>0?o:[...xt(e.callees,n.callees)];return{symbolA:e.symbol,shortNameA:I(e.symbol),fileA:e.file,symbolB:n.symbol,shortNameB:I(n.symbol),fileB:n.file,similarity:i,sharedCallees:r.map(I),uniqueToA:[...It(e.callees,n.callees)].map(I),uniqueToB:[...It(n.callees,e.callees)].map(I)}}function on(e,n={}){let{minSimilarity:t=.5,limit:s=20,scope:i,minCallees:o=4,crossFileOnly:a=!1}=n,r=To(e,{minCallees:o,scope:i}),l=Gn(r.map(p=>p.callees)),c=new Map;for(let p of r)for(let f of p.callees)c.set(f,(c.get(f)??0)+1);let m=Math.max(8,Math.ceil(Math.sqrt(r.length))),u=new Map;for(let p=0;p<r.length;p+=1)for(let f of r[p].callees){if((c.get(f)??0)>m)continue;let y=u.get(f);y||(y=[],u.set(f,y)),y.push(p)}let d=[],g=new Set;e:for(let p=0;p<r.length;p+=1){let f=r[p],y=new Set;for(let h of f.callees){let b=u.get(h);if(b)for(let _ of b)_>p&&y.add(_)}for(let h of y){let b=`${p}|${h}`;if(g.has(b))continue;g.add(b);let _=r[h];if(a&&f.file===_.file)continue;if(f.paramCount>=0&&_.paramCount>=0){let x=Math.abs(f.paramCount-_.paramCount),L=Math.max(2,Math.ceil(Math.max(f.paramCount,_.paramCount)*.5));if(x>L)continue}let S=Fo(f,_,l,{minSimilarity:t,requireSignificantShared:2,requireSharedCount:4});if(S&&(d.push(S),d.length>s*5))break e}}return d.sort((p,f)=>f.similarity-p.similarity),d.slice(0,s)}function im(e,n){let t=k(e,n);if(!t)return null;let s=ne(e,t);return{symbol:t.symbol,file:t.relativePath,callees:new Set(s.map(i=>i.symbol)),paramCount:Pn(e,t.relativePath,t.startLine,t.endLine)?.paramCount??-1}}function To(e,n){let{minCallees:t,scope:s,excludeSymbol:i}=n,o=Y(e,s).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>r.isFunctionLike).filter(r=>i===void 0||r.symbol!==i).filter(r=>r.endLine-r.startLine+1>=5).filter(r=>U(r.relativePath)!=="test").filter(r=>!G(r.symbol)).filter(r=>!pe(e,r.relativePath,r.startLine)),a=se(e,o);return o.map(r=>({symbol:r.symbol,file:r.relativePath,callees:new Set((a.get(r.symbolId)??[]).map(l=>l.symbol)),paramCount:Pn(e,r.relativePath,r.startLine,r.endLine)?.paramCount??-1})).filter(r=>r.callees.size>=t)}function om(e,n,t){let s=rm(e,n);if(!s||s.tokens.size<3)return[];let i=t.minSimilarity>=.5?t.minSimilarity:.3,o=[];for(let a of lm(e)){if(a.symbol===s.symbol||a.tokens.size<3)continue;let r=xt(s.tokens,a.tokens);if(r.size<2)continue;let l=new Set([...s.tokens,...a.tokens]),c=l.size>0?r.size/l.size:0;c<i||o.push({symbolA:s.symbol,shortNameA:I(s.symbol),fileA:s.file,symbolB:a.symbol,shortNameB:I(a.symbol),fileB:a.file,similarity:c,sharedCallees:[...r].sort(),uniqueToA:[...It(s.tokens,a.tokens)].sort(),uniqueToB:[...It(a.tokens,s.tokens)].sort()})}return o.sort((a,r)=>r.similarity-a.similarity||a.shortNameB.localeCompare(r.shortNameB)),o.slice(0,t.limit)}function rm(e,n){let t=k(e,n);if(!t||!j(t.symbol))return null;let s=am(e,t);return s?{symbol:t.symbol,file:t.relativePath,tokens:s}:null}function am(e,n){let t=F(n.symbol),s=Ao(e,n.relativePath,n.startLine,n.endLine,t),i=jo(s,t);return i.size>0?i:null}function lm(e){return Z(e).filter(n=>n.isFunctionLike).filter(n=>U(n.relativePath)!=="test").filter(n=>!G(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:jo(Ao(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function Ao(e,n,t,s,i){let o=M(e,n);if(!o)return"";let a=o.split(`
704
+ `);if(s>=t&&s-t<=12)return a.slice(t,s+1).join(`
705
+ `);let r=[new RegExp(`\\bdef\\s+${Nt(i)}\\b`),new RegExp(`\\bfun\\s+${Nt(i)}\\b`),new RegExp(`\\bfn\\s+${Nt(i)}\\b`),new RegExp(`\\bfunction\\s+${Nt(i)}\\b`),new RegExp(`\\b${Nt(i)}\\s*\\(`)],l=a.findIndex(c=>r.some(m=>m.test(c)));if(l>=0){let c=l;for(let m=l+1;m<a.length&&m<=l+8;m++){let u=a[m]??"";if(m>l&&um(u)||(c=m,u.trim()===""&&m>l+1))break}return a.slice(l,c+1).join(`
658
706
  `)}return a.slice(t,Math.min(a.length,t+8)).join(`
659
- `)}function fo(e,n){if(!e)return new Set;let t=new Set(["public","private","protected","final","static","class","def","fun","fn","function","return","string","bool","boolean","void","unit","self","this","new","const","let","var","end","pub"]),i=sm(n),o=e.replace(/["'`]/g," ").replace(/\b\d+\b/g," NUM ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9_]+/g," ").replace(/_/g," ").toLowerCase().split(/\s+/).map(a=>a.trim()).filter(a=>a.length>1).filter(a=>!t.has(a)).filter(a=>!i.has(a));return new Set(o)}function sm(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(n=>n.toLowerCase()).filter(n=>n.length>1))}function om(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function mt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ho(e,n={}){let{minSimilarity:t=.5,limit:i=20,scope:s,filePattern:o}=n,a=n.minDeps??(o?1:3),r=rm(e,{scope:s,minDeps:a}),l=[];if(o){let c=r.find(m=>m.file.includes(o));if(!c)return[];for(let m of r){if(m.file===c.file)continue;let u=go(c,m,t);u&&l.push(u)}}else for(let c=0;c<r.length;c++){for(let m=c+1;m<r.length;m++){let u=go(r[c],r[m],t);u&&l.push(u)}if(l.length>i*5)break}return l.sort((c,m)=>m.similarity-c.similarity),l.slice(0,i)}function rm(e,n){let{scope:t,minDeps:i}=n,s=G(e,t),o=am(s),a=[];for(let[r,l]of s)l.size>=i&&a.push({file:r,deps:new Set([...l].filter(c=>!o.has(c)))});return a}function am(e){let n=new Set,t=e.size;if(t===0)return n;let i=new Map;for(let s of e.values())for(let o of s)i.set(o,(i.get(o)??0)+1);for(let[s,o]of i)o>=5&&o/t>.3&&n.add(s);return n}function go(e,n,t){let i=new Set;for(let r of e.deps)n.deps.has(r)&&i.add(r);if(i.size<3||e.deps.size<4||n.deps.size<4)return null;let s=ao(e.deps,n.deps);if(s<t)return null;let o=[];for(let r of e.deps)n.deps.has(r)||o.push(r);let a=[];for(let r of n.deps)e.deps.has(r)||a.push(r);return{fileA:e.file,fileB:n.file,similarity:s,sharedDeps:[...i],uniqueToA:o,uniqueToB:a}}function bo(e,n={}){let{minSimilarity:t=.5,limit:i=15,scope:s,minChainLength:o=3,maxChainLength:a=8}=n,r=G(e,s),l=lm(r,o,a);if(l.length===0)return[];let c=new Map,m=new Map;for(let b of l){let x=new Set;for(let S of b)x.has(S)||(c.set(S,(c.get(S)??0)+1),x.add(S));for(let S=Math.max(0,b.length-2);S<b.length;S++)m.set(b[S],(m.get(b[S])??0)+1)}let u=l.length*.9,d=l.length*.8,f=new Set;for(let[b,x]of c)x>u&&f.add(b);for(let[b,x]of m)x>d&&f.add(b);let p=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let b of c.keys()){let x=b.split("/").pop()??"";p.includes(x)&&f.add(b)}let g=[];for(let b of l){let x=b.filter(S=>!f.has(S));x.length>=2&&g.push({original:b,filtered:x})}if(g.length<2)return[];let y=[];for(let b=0;b<g.length;b++){for(let x=b+1;x<g.length;x++){let S=g[b],I=g[x],L=new Set(S.filtered),D=!1;for(let ae of I.filtered)if(L.has(ae)){D=!0;break}if(!D)continue;let{distance:k,ops:U}=cm(S.filtered,I.filtered),B=Math.max(S.filtered.length,I.filtered.length);if(B===0)continue;let F=1-k/B;if(F<t||k===0)continue;let Se=U.filter(ae=>ae.type==="substitute").map(ae=>({index:ae.indexA,nodeA:S.filtered[ae.indexA],nodeB:I.filtered[ae.indexB]}));if(Se.length===0||U.filter(ae=>ae.type==="match").length<2)continue;let dt=mm(S.original,I.original),an=um(S.original,I.original);y.push({chainA:S.original,chainB:I.original,similarity:F,editDistance:k,divergencePoints:Se,commonPrefix:dt,commonSuffix:an})}if(y.length>i*10)break}y.sort((b,x)=>Math.abs(x.similarity-b.similarity)>.01?x.similarity-b.similarity:b.divergencePoints.length-x.divergencePoints.length);let h=[];for(let b of y)if(h.some(S=>yo(b.chainA,S.chainA)&&yo(b.chainB,S.chainB))||h.push(b),h.length>=i)break;return h}function lm(e,n,t){let i=[];for(let o of e.keys()){if(i.length>=500)break;So(e,o,[o],new Set([o]),n,t,i,500)}return i}function So(e,n,t,i,s,o,a,r){if(a.length>=r)return;if(t.length>=o){t.length>=s&&a.push([...t]);return}let l=e.get(n);if(!l||l.size===0){t.length>=s&&a.push([...t]);return}let c=!1;for(let m of l)if(!i.has(m)&&(i.add(m),t.push(m),So(e,m,t,i,s,o,a,r),t.pop(),i.delete(m),c=!0,a.length>=r))return;!c&&t.length>=s&&a.push([...t])}function cm(e,n){let t=e.length,i=n.length,s=Array.from({length:t+1},()=>Array(i+1).fill(0));for(let l=0;l<=t;l++)s[l][0]=l;for(let l=0;l<=i;l++)s[0][l]=l;for(let l=1;l<=t;l++)for(let c=1;c<=i;c++)e[l-1]===n[c-1]?s[l][c]=s[l-1][c-1]:s[l][c]=1+Math.min(s[l-1][c],s[l][c-1],s[l-1][c-1]);let o=[],a=t,r=i;for(;a>0||r>0;)a>0&&r>0&&e[a-1]===n[r-1]?(o.unshift({type:"match",indexA:a-1,indexB:r-1}),a--,r--):a>0&&r>0&&s[a][r]===s[a-1][r-1]+1?(o.unshift({type:"substitute",indexA:a-1,indexB:r-1}),a--,r--):r>0&&s[a][r]===s[a][r-1]+1?(o.unshift({type:"insert",indexA:a,indexB:r-1}),r--):(o.unshift({type:"delete",indexA:a-1,indexB:r}),a--);return{distance:s[t][i],ops:o}}function mm(e,n){let t=[];for(let i=0;i<Math.min(e.length,n.length)&&e[i]===n[i];i++)t.push(e[i]);return t}function um(e,n){let t=[],i=e.length-1,s=n.length-1;for(;i>=0&&s>=0&&e[i]===n[s];)t.unshift(e[i]),i--,s--;return t}function yo(e,n){if(e.length>n.length)return!1;let t=n.join("\u2192"),i=e.join("\u2192");return t.includes(i)}function Kt(e,n={}){let{scope:t,minLoc:i=10,minCallees:s=6,limit:o=20}=n,a=z(e,t).filter(c=>!e.isIgnored(c.relativePath)).filter(c=>Yt(c)>=i&&j(c.symbol)).filter(c=>!(c.relativePath.split("/").pop()??"").includes("types")).filter(c=>!ue(e,c.relativePath,c.startLine)).sort((c,m)=>Yt(m)-Yt(c)),r=ee(e,a),l=[];for(let c of a){let m=r.get(c.symbolId)??[],u=new Set(m.map(h=>h.symbol));if(u.size<s)continue;let d=new Map;for(let h of u)d.set(h,new Set);let f=new Map;for(let h of m)f.has(h.chunkId)||f.set(h.chunkId,new Set),f.get(h.chunkId).add(h.symbol);for(let h of f.values()){let b=[...h];for(let x=0;x<b.length;x++)for(let S=x+1;S<b.length;S++)d.get(b[x]).add(b[S]),d.get(b[S]).add(b[x])}let p=new Set,g=[];for(let h of u){if(p.has(h))continue;let b=new Set,x=[h];for(;x.length>0;){let S=x.pop();if(!p.has(S)){p.add(S),b.add(S);for(let I of d.get(S)??[])p.has(I)||x.push(I)}}g.push(b)}if(g.length<2)continue;let y=g.filter(h=>h.size>=3).map(h=>{let b=new Set;for(let L of g)if(L!==h)for(let D of L)b.add(D);let x=0;for(let L of h)for(let D of d.get(L)??[])b.has(D)&&x++;let S=h.size*b.size,I=S>0?1-x/S:1;return{callees:[...h].map(_),isolation:I}}).filter(h=>h.isolation>.5).sort((h,b)=>b.isolation-h.isolation);y.length>0&&l.push({symbol:c.symbol,shortName:_(c.symbol),relativePath:c.relativePath,startLine:c.startLine,endLine:c.endLine,loc:Yt(c),totalCallees:u.size,clusters:y})}return l.sort((c,m)=>m.clusters.length-c.clusters.length||m.loc-c.loc),l.slice(0,o)}function Yt(e){return e.endLine-e.startLine+1}function _o(e,n,t={}){let{maxDepth:i=5,scope:s}=t,o=O(e,n);if(!o)return[];let a=[],r=new Set([o.symbolId]),l=new Set,c=[o];for(let m=1;m<=i&&c.length!==0;m++){let u=[];for(let d of c)for(let f of dm(e,d,s)){let p=`${f.file}|${f.shortName}`;if(f.symbolId!==null){if(r.has(f.symbolId))continue;r.add(f.symbolId)}else if(l.has(p))continue;l.add(p),a.push({symbol:f.symbol,shortName:f.shortName,file:f.file,depth:m}),f.symbolId!==null&&f.symbolMatch&&u.push(f.symbolMatch)}c=u}return a.sort((m,u)=>m.depth-u.depth||m.file.localeCompare(u.file)),a}function dm(e,n,t){let i=fe(e,n,{limit:500}).filter(m=>!e.isIgnored(m.file)).filter(m=>!t||m.file.includes(t)),s=new Set(i.map(m=>m.file)),o=ge(e).get(n.symbolId)??new Set,a=[];for(let m of o){if(s.has(m)||e.isIgnored(m)||t&&!m.includes(t))continue;let u=A(e,m),d=u.length>0?de(u,u[0].startLine):null;a.push({symbol:d?.symbol??m,file:m})}let r=[...i,...a],l=[],c=new Set;for(let m of r){let u=Ue(e,m.symbol);if(!u){let f=`${m.file}|${m.symbol}`;if(c.has(f))continue;c.add(f),l.push({symbolId:null,symbol:m.symbol,shortName:_(m.symbol),file:m.file,symbolMatch:null});continue}if(u.symbolId===n.symbolId||e.isIgnored(u.relativePath))continue;let d=`${u.symbolId}|${u.relativePath}`;c.has(d)||(c.add(d),l.push({symbolId:u.symbolId,symbol:u.symbol,shortName:_(u.symbol),file:u.relativePath,symbolMatch:u}))}return l}function xo(e,n){let t=Q(e,n);if(!t)return null;let i=e.get(`SELECT id, relative_path FROM documents
707
+ `)}function jo(e,n){if(!e)return new Set;let t=new Set(["public","private","protected","final","static","class","def","fun","fn","function","return","string","bool","boolean","void","unit","self","this","new","const","let","var","end","pub"]),s=cm(n),o=e.replace(/["'`]/g," ").replace(/\b\d+\b/g," NUM ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9_]+/g," ").replace(/_/g," ").toLowerCase().split(/\s+/).map(a=>a.trim()).filter(a=>a.length>1).filter(a=>!t.has(a)).filter(a=>!s.has(a));return new Set(o)}function cm(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(n=>n.toLowerCase()).filter(n=>n.length>1))}function um(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function Nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Wo(e,n={}){let{minSimilarity:t=.5,limit:s=20,scope:i,filePattern:o}=n,a=n.minDeps??(o?1:3),r=mm(e,{scope:i,minDeps:a}),l=[];if(o){let c=r.find(m=>m.file.includes(o));if(!c)return[];for(let m of r){if(m.file===c.file)continue;let u=Bo(c,m,t);u&&l.push(u)}}else for(let c=0;c<r.length;c++){for(let m=c+1;m<r.length;m++){let u=Bo(r[c],r[m],t);u&&l.push(u)}if(l.length>s*5)break}return l.sort((c,m)=>m.similarity-c.similarity),l.slice(0,s)}function mm(e,n){let{scope:t,minDeps:s}=n,i=K(e,t),o=dm(i),a=[];for(let[r,l]of i)l.size>=s&&a.push({file:r,deps:new Set([...l].filter(c=>!o.has(c)))});return a}function dm(e){let n=new Set,t=e.size;if(t===0)return n;let s=new Map;for(let i of e.values())for(let o of i)s.set(o,(s.get(o)??0)+1);for(let[i,o]of s)o>=5&&o/t>.3&&n.add(i);return n}function Bo(e,n,t){let s=new Set;for(let r of e.deps)n.deps.has(r)&&s.add(r);if(s.size<3||e.deps.size<4||n.deps.size<4)return null;let i=$o(e.deps,n.deps);if(i<t)return null;let o=[];for(let r of e.deps)n.deps.has(r)||o.push(r);let a=[];for(let r of n.deps)e.deps.has(r)||a.push(r);return{fileA:e.file,fileB:n.file,similarity:i,sharedDeps:[...s],uniqueToA:o,uniqueToB:a}}function Jo(e,n={}){let{minSimilarity:t=.5,limit:s=15,scope:i,minChainLength:o=3,maxChainLength:a=8}=n,r=K(e,i),l=pm(r,o,a);if(l.length===0)return[];let c=new Map,m=new Map;for(let b of l){let _=new Set;for(let S of b)_.has(S)||(c.set(S,(c.get(S)??0)+1),_.add(S));for(let S=Math.max(0,b.length-2);S<b.length;S++)m.set(b[S],(m.get(b[S])??0)+1)}let u=l.length*.9,d=l.length*.8,g=new Set;for(let[b,_]of c)_>u&&g.add(b);for(let[b,_]of m)_>d&&g.add(b);let p=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let b of c.keys()){let _=b.split("/").pop()??"";p.includes(_)&&g.add(b)}let f=[];for(let b of l){let _=b.filter(S=>!g.has(S));_.length>=2&&f.push({original:b,filtered:_})}if(f.length<2)return[];let y=[];for(let b=0;b<f.length;b++){for(let _=b+1;_<f.length;_++){let S=f[b],x=f[_],L=new Set(S.filtered),w=!1;for(let ce of x.filtered)if(L.has(ce)){w=!0;break}if(!w)continue;let{distance:$,ops:q}=fm(S.filtered,x.filtered),B=Math.max(S.filtered.length,x.filtered.length);if(B===0)continue;let T=1-$/B;if(T<t||$===0)continue;let _e=q.filter(ce=>ce.type==="substitute").map(ce=>({index:ce.indexA,nodeA:S.filtered[ce.indexA],nodeB:x.filtered[ce.indexB]}));if(_e.length===0||q.filter(ce=>ce.type==="match").length<2)continue;let Et=gm(S.original,x.original),bn=hm(S.original,x.original);y.push({chainA:S.original,chainB:x.original,similarity:T,editDistance:$,divergencePoints:_e,commonPrefix:Et,commonSuffix:bn})}if(y.length>s*10)break}y.sort((b,_)=>Math.abs(_.similarity-b.similarity)>.01?_.similarity-b.similarity:b.divergencePoints.length-_.divergencePoints.length);let h=[];for(let b of y)if(h.some(S=>Ho(b.chainA,S.chainA)&&Ho(b.chainB,S.chainB))||h.push(b),h.length>=s)break;return h}function pm(e,n,t){let s=[];for(let o of e.keys()){if(s.length>=500)break;Uo(e,o,[o],new Set([o]),n,t,s,500)}return s}function Uo(e,n,t,s,i,o,a,r){if(a.length>=r)return;if(t.length>=o){t.length>=i&&a.push([...t]);return}let l=e.get(n);if(!l||l.size===0){t.length>=i&&a.push([...t]);return}let c=!1;for(let m of l)if(!s.has(m)&&(s.add(m),t.push(m),Uo(e,m,t,s,i,o,a,r),t.pop(),s.delete(m),c=!0,a.length>=r))return;!c&&t.length>=i&&a.push([...t])}function fm(e,n){let t=e.length,s=n.length,i=Array.from({length:t+1},()=>Array(s+1).fill(0));for(let l=0;l<=t;l++)i[l][0]=l;for(let l=0;l<=s;l++)i[0][l]=l;for(let l=1;l<=t;l++)for(let c=1;c<=s;c++)e[l-1]===n[c-1]?i[l][c]=i[l-1][c-1]:i[l][c]=1+Math.min(i[l-1][c],i[l][c-1],i[l-1][c-1]);let o=[],a=t,r=s;for(;a>0||r>0;)a>0&&r>0&&e[a-1]===n[r-1]?(o.unshift({type:"match",indexA:a-1,indexB:r-1}),a--,r--):a>0&&r>0&&i[a][r]===i[a-1][r-1]+1?(o.unshift({type:"substitute",indexA:a-1,indexB:r-1}),a--,r--):r>0&&i[a][r]===i[a][r-1]+1?(o.unshift({type:"insert",indexA:a,indexB:r-1}),r--):(o.unshift({type:"delete",indexA:a-1,indexB:r}),a--);return{distance:i[t][s],ops:o}}function gm(e,n){let t=[];for(let s=0;s<Math.min(e.length,n.length)&&e[s]===n[s];s++)t.push(e[s]);return t}function hm(e,n){let t=[],s=e.length-1,i=n.length-1;for(;s>=0&&i>=0&&e[s]===n[i];)t.unshift(e[s]),s--,i--;return t}function Ho(e,n){if(e.length>n.length)return!1;let t=n.join("\u2192"),s=e.join("\u2192");return t.includes(s)}function an(e,n={}){let{scope:t,minLoc:s=10,minCallees:i=6,limit:o=20}=n,a=Y(e,t).filter(c=>!e.isIgnored(c.relativePath)).filter(c=>rn(c)>=s&&j(c.symbol)).filter(c=>!(c.relativePath.split("/").pop()??"").includes("types")).filter(c=>U(c.relativePath)!=="test").filter(c=>!G(c.symbol)).filter(c=>!pe(e,c.relativePath,c.startLine)).sort((c,m)=>rn(m)-rn(c)),r=se(e,a),l=[];for(let c of a){let m=r.get(c.symbolId)??[],u=new Set(m.map(h=>h.symbol));if(u.size<i)continue;let d=new Map;for(let h of u)d.set(h,new Set);let g=new Map;for(let h of m)g.has(h.chunkId)||g.set(h.chunkId,new Set),g.get(h.chunkId).add(h.symbol);for(let h of g.values()){let b=[...h];for(let _=0;_<b.length;_++)for(let S=_+1;S<b.length;S++)d.get(b[_]).add(b[S]),d.get(b[S]).add(b[_])}let p=new Set,f=[];for(let h of u){if(p.has(h))continue;let b=new Set,_=[h];for(;_.length>0;){let S=_.pop();if(!p.has(S)){p.add(S),b.add(S);for(let x of d.get(S)??[])p.has(x)||_.push(x)}}f.push(b)}if(f.length<2)continue;let y=f.filter(h=>h.size>=3).map(h=>{let b=new Set;for(let L of f)if(L!==h)for(let w of L)b.add(w);let _=0;for(let L of h)for(let w of d.get(L)??[])b.has(w)&&_++;let S=h.size*b.size,x=S>0?1-_/S:1;return{callees:[...h].map(I),isolation:x}}).filter(h=>h.isolation>.5).sort((h,b)=>b.isolation-h.isolation);y.length>0&&l.push({symbol:c.symbol,shortName:I(c.symbol),relativePath:c.relativePath,startLine:c.startLine,endLine:c.endLine,loc:rn(c),totalCallees:u.size,clusters:y})}return l.sort((c,m)=>m.clusters.length-c.clusters.length||m.loc-c.loc),l.slice(0,o)}function rn(e){return e.endLine-e.startLine+1}function qo(e,n,t={}){let{maxDepth:s=5,scope:i}=t,o=k(e,n);if(!o)return[];let a=[],r=new Set([o.symbolId]),l=new Set,c=[o];for(let m=1;m<=s&&c.length!==0;m++){let u=[];for(let d of c)for(let g of ym(e,d,i)){let p=`${g.file}|${g.shortName}`;if(g.symbolId!==null){if(r.has(g.symbolId))continue;r.add(g.symbolId)}else if(l.has(p))continue;l.add(p),a.push({symbol:g.symbol,shortName:g.shortName,file:g.file,depth:m}),g.symbolId!==null&&g.symbolMatch&&u.push(g.symbolMatch)}c=u}return a.sort((m,u)=>m.depth-u.depth||m.file.localeCompare(u.file)),a}function ym(e,n,t){let s=he(e,n,{limit:500}).filter(m=>!e.isIgnored(m.file)).filter(m=>!t||m.file.includes(t)),i=new Set(s.map(m=>m.file)),o=ye(e).get(n.symbolId)??new Set,a=[];for(let m of o){if(i.has(m)||e.isIgnored(m)||t&&!m.includes(t))continue;let u=A(e,m),d=u.length>0?fe(u,u[0].startLine):null;a.push({symbol:d?.symbol??m,file:m})}let r=[...s,...a],l=[],c=new Set;for(let m of r){let u=Xe(e,m.symbol);if(!u){let g=`${m.file}|${m.symbol}`;if(c.has(g))continue;c.add(g),l.push({symbolId:null,symbol:m.symbol,shortName:I(m.symbol),file:m.file,symbolMatch:null});continue}if(u.symbolId===n.symbolId||e.isIgnored(u.relativePath))continue;let d=`${u.symbolId}|${u.relativePath}`;c.has(d)||(c.add(d),l.push({symbolId:u.symbolId,symbol:u.symbol,shortName:I(u.symbol),file:u.relativePath,symbolMatch:u}))}return l}function zo(e,n){let t=ee(e,n);if(!t)return null;let s=e.get(`SELECT id, relative_path FROM documents
660
708
  WHERE relative_path = ?
661
709
  ${e.pathExclusionsFor("documents")}
662
- LIMIT 1`,t);if(!i||e.isIgnored(i.relative_path))return null;let s=A(e,i.relative_path).sort((r,l)=>r.startLine-l.startLine||r.endLine-l.endLine),o=[],a=0;for(let r of s){let c=e.get(`SELECT COUNT(DISTINCT c.document_id) AS consumer_count
710
+ LIMIT 1`,t);if(!s||e.isIgnored(s.relative_path))return null;let i=A(e,s.relative_path).sort((r,l)=>r.startLine-l.startLine||r.endLine-l.endLine),o=[],a=0;for(let r of i){let c=e.get(`SELECT COUNT(DISTINCT c.document_id) AS consumer_count
663
711
  FROM mentions m
664
712
  JOIN chunks c ON m.chunk_id = c.id
665
713
  WHERE m.symbol_id = ?
666
714
  AND m.role != 1
667
- AND c.document_id != ?`,r.symbolId,i.id)?.consumer_count??0,m;c>10?m="high":c>0?m="medium":m="low",a+=c,o.push({symbol:r.symbol,shortName:_(r.symbol),startLine:r.startLine,endLine:r.endLine,externalConsumers:c,riskLevel:m})}return{file:i.relative_path,symbols:o,totalExternalConsumers:a}}import{execFileSync as Fn}from"child_process";function Io(e,n={}){let{base:t="HEAD"}=n,i;try{i=pm(e.config.projectRoot,t)}catch{return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"Unable to compute git diff."}}}if(i.length===0)return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"No changed files found."}};let s=[],o=[];for(let u of i){let d=e.get(`SELECT id, relative_path FROM documents
715
+ AND c.document_id != ?`,r.symbolId,s.id)?.consumer_count??0,m;c>10?m="high":c>0?m="medium":m="low",a+=c,o.push({symbol:r.symbol,shortName:I(r.symbol),startLine:r.startLine,endLine:r.endLine,externalConsumers:c,riskLevel:m})}return{file:s.relative_path,symbols:o,totalExternalConsumers:a}}import{execFileSync as Yn}from"child_process";function Vo(e,n={}){let{base:t="HEAD"}=n,s;try{s=bm(e.config.projectRoot,t)}catch{return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"Unable to compute git diff."}}}if(s.length===0)return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"No changed files found."}};let i=[],o=[];for(let u of s){let d=e.get(`SELECT id, relative_path FROM documents
668
716
  WHERE relative_path LIKE ?
669
- LIMIT 1`,`%${u}`);d&&!e.isIgnored(d.relative_path)&&(s.push(d.relative_path),o.push(d.id))}if(o.length===0)return{changedFiles:i,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:i.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let a=o.map(()=>"?").join(","),r=e.all(`SELECT DISTINCT gs.id AS symbol_id, gs.symbol, d.relative_path
717
+ LIMIT 1`,`%${u}`);d&&!e.isIgnored(d.relative_path)&&(i.push(d.relative_path),o.push(d.id))}if(o.length===0)return{changedFiles:s,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:s.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let a=o.map(()=>"?").join(","),r=e.all(`SELECT DISTINCT gs.id AS symbol_id, gs.symbol, d.relative_path
670
718
  FROM mentions m
671
719
  JOIN chunks c ON m.chunk_id = c.id
672
720
  JOIN global_symbols gs ON m.symbol_id = gs.id
@@ -674,19 +722,19 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
674
722
  WHERE m.role = 1
675
723
  AND c.document_id IN (${a})
676
724
  ${e.symbolNoiseFor("gs")}
677
- ORDER BY d.relative_path`,...o),l=[],c=new Map;for(let u of r){let f=e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
725
+ ORDER BY d.relative_path`,...o),l=[],c=new Map;for(let u of r){let g=e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
678
726
  FROM mentions m
679
727
  JOIN chunks c ON m.chunk_id = c.id
680
728
  WHERE m.symbol_id = ?
681
- AND m.role != 1`,u.symbol_id)?.fan_in??0,p=_(u.symbol);l.push({symbol:u.symbol,shortName:p,file:u.relative_path,fanIn:f});let g=e.all(`SELECT DISTINCT ref_d.relative_path
729
+ AND m.role != 1`,u.symbol_id)?.fan_in??0,p=I(u.symbol);l.push({symbol:u.symbol,shortName:p,file:u.relative_path,fanIn:g});let f=e.all(`SELECT DISTINCT ref_d.relative_path
682
730
  FROM mentions m
683
731
  JOIN chunks c ON m.chunk_id = c.id
684
732
  JOIN documents ref_d ON c.document_id = ref_d.id
685
733
  WHERE m.symbol_id = ?
686
734
  AND m.role != 1
687
- AND ref_d.relative_path NOT IN (${s.map(()=>"?").join(",")})
688
- ${e.pathExclusionsFor("ref_d")}`,u.symbol_id,...s);for(let y of g)e.isIgnored(y.relative_path)||(c.has(y.relative_path)||c.set(y.relative_path,new Set),c.get(y.relative_path).add(p))}let m=[...c.entries()].map(([u,d])=>({file:u,consumedSymbols:d.size})).sort((u,d)=>d.consumedSymbols-u.consumedSymbols);return{changedFiles:s,changedSymbols:l,affectedConsumers:m,summary:{totalChangedFiles:s.length,totalChangedSymbols:l.length,totalAffectedFiles:m.length}}}function pm(e,n){let t=Fn("git",["diff","--name-only",n],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Fn("git",["diff","--name-only","--cached",n],{encoding:"utf-8",cwd:e,timeout:1e4}),s=Fn("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([t,i,s].flatMap(o=>o.split(`
689
- `)).map(o=>o.trim()).filter(o=>o.length>0))]}import Vt from"path";function Xt(e,n){let{scope:t}=n??{},i=G(e,t),s=fm(e,t),o=[];for(let[l,c]of i){if(he(l))continue;let m=s.get(l)??new Set;for(let u of c)if(!he(u)&&!m.has(u)){if(hm(u)||ym(e,l,u))continue;o.push({file:l,kind:"unused-import",description:`Depends on ${u} but references none of its symbols`,dep:u})}}let a=gm(i);for(let[l,c]of i){if(he(l))continue;let m=Qt(l);for(let u of c){if(he(u))continue;let d=Qt(u);if(m===d)continue;a.get(`${m}->${d}`)==="violation"&&o.push({file:l,kind:"layer-violation",description:`Imports from ${d}/ (${u}) \u2014 may cross architectural boundary`,dep:u,detail:`${m}/ should not depend on ${d}/`})}}let r=new Map;for(let l of i.keys()){let c=Vt.dirname(l);r.has(c)||r.set(c,[]),r.get(c).push(l)}for(let[l,c]of r){if(c.length<3)continue;let m=new Map;for(let u of c)if(!he(u))for(let d of i.get(u)??[])he(d)||m.set(d,(m.get(d)??0)+1);for(let u of c)if(!he(u)){for(let d of i.get(u)??[])if(!he(d)&&(m.get(d)??0)===1){if(Vt.dirname(d)===l)continue;o.push({file:u,kind:"pattern-deviation",description:`Only file in ${l}/ that depends on ${d}`,dep:d})}}}return{results:o,unusedImports:o.filter(l=>l.kind==="unused-import").length,layerViolations:o.filter(l=>l.kind==="layer-violation").length,patternDeviations:o.filter(l=>l.kind==="pattern-deviation").length}}function fm(e,n){let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",i=e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
735
+ AND ref_d.relative_path NOT IN (${i.map(()=>"?").join(",")})
736
+ ${e.pathExclusionsFor("ref_d")}`,u.symbol_id,...i);for(let y of f)e.isIgnored(y.relative_path)||(c.has(y.relative_path)||c.set(y.relative_path,new Set),c.get(y.relative_path).add(p))}let m=[...c.entries()].map(([u,d])=>({file:u,consumedSymbols:d.size})).sort((u,d)=>d.consumedSymbols-u.consumedSymbols);return{changedFiles:i,changedSymbols:l,affectedConsumers:m,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:m.length}}}function bm(e,n){let t=Yn("git",["diff","--name-only",n],{encoding:"utf-8",cwd:e,timeout:1e4}),s=Yn("git",["diff","--name-only","--cached",n],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Yn("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([t,s,i].flatMap(o=>o.split(`
737
+ `)).map(o=>o.trim()).filter(o=>o.length>0))]}import vt from"path";function cn(e,n){let{scope:t}=n??{},s=K(e,t),i=Sm(e,t),o=[];for(let[l,c]of s){if(Ce(l))continue;let m=i.get(l)??new Set;for(let u of c)if(!Ce(u)&&!m.has(u)){if(xm(u)||Im(e,l,u))continue;o.push({file:l,kind:"unused-import",description:`Depends on ${u} but references none of its symbols`,dep:u})}}let a=_m(s);for(let[l,c]of s){if(Ce(l))continue;let m=ln(l);for(let u of c){if(Ce(u))continue;let d=ln(u);if(m===d)continue;a.get(`${m}->${d}`)==="violation"&&o.push({file:l,kind:"layer-violation",description:`Imports from ${d}/ (${u}) \u2014 may cross architectural boundary`,dep:u,detail:`${m}/ should not depend on ${d}/`})}}let r=new Map;for(let l of s.keys()){let c=vt.dirname(l);r.has(c)||r.set(c,[]),r.get(c).push(l)}for(let[l,c]of r){let m=c.filter(d=>!Ce(d));if(m.length<5)continue;let u=new Map;for(let d of m)for(let g of s.get(d)??[])Ce(g)||u.set(g,(u.get(g)??0)+1);for(let d of m)for(let g of s.get(d)??[])Ce(g)||(u.get(g)??0)===1&&vt.dirname(g)!==l&&vt.dirname(g)!==vt.dirname(l)&&o.push({file:d,kind:"pattern-deviation",description:`Only file in ${l}/ that depends on ${g}`,dep:g})}return{results:o,unusedImports:o.filter(l=>l.kind==="unused-import").length,layerViolations:o.filter(l=>l.kind==="layer-violation").length,patternDeviations:o.filter(l=>l.kind==="pattern-deviation").length}}function Sm(e,n){let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",s=e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
690
738
  FROM mentions m
691
739
  JOIN chunks c ON m.chunk_id = c.id
692
740
  JOIN documents d1 ON c.document_id = d1.id
@@ -702,24 +750,25 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
702
750
  WHERE d1.id != d2.id
703
751
  AND m.role != 1
704
752
  ${e.pathExclusionsFor("d1","d2")}
705
- ${t}`),s=new Map;for(let o of i)e.isIgnored(o.from_file)||e.isIgnored(o.to_file)||(s.has(o.from_file)||s.set(o.from_file,new Set),s.get(o.from_file).add(o.to_file));return s}function gm(e){let n=new Map,t=new Set;for(let[s,o]of e){if(he(s))continue;let a=Qt(s);t.add(a);for(let r of o){if(he(r))continue;let l=Qt(r);if(a===l)continue;t.add(l);let c=`${a}->${l}`;n.set(c,(n.get(c)??0)+1)}}let i=new Map;for(let[s,o]of n)i.set(s,o<=2?"violation":"ok");return i}function Qt(e){let t=e.replace(/\\/g,"/").split("/").filter(Boolean);return t.length<=1?"(root)":t.length>=3&&["src","lib","app","server","client"].includes(t[0])?`${t[0]}/${t[1]}`:t[0]}function hm(e){return e.includes("types")||e.endsWith(".d.ts")}function ym(e,n,t){let i=me(e,n).filter(s=>s.sourcePath===t);return i.length===0?!1:i.every(s=>s.kind==="side-effect"||s.kind==="namespace"&&s.usedMembers.length===0&&!s.used)}function he(e){return bm(Vt.basename(e))||Sm(e)}function bm(e){return!!(e==="index.ts"||e==="index.js"||e==="cli.ts"||e==="main.ts"||e==="main.rs"||e.includes("worker.")||e.includes("postinstall.")||e==="health.ts"||e==="health.js")}function Sm(e){let n=e.replace(/\\/g,"/"),t=Vt.basename(n);return n.includes("/__tests__/")||n.includes("/tests/")||n.includes("/test/")||/\.(test|spec)\.[A-Za-z0-9]+$/.test(t)||/_(test|spec)\.[A-Za-z0-9]+$/.test(t)||/^test[_-]/.test(t)||/^test\./.test(t)}import{basename as ut,extname as Zt}from"path";function en(e,n){let{scope:t,maxLoc:i=15,limit:s=30}=n??{},o=Nm(G(e,t)),a=_m(e,t,i),r=Im(ge(e,a),Ve(e,a)),l=[];for(let c of a){if(ue(e,c.relativePath,c.startLine))continue;let m=ut(c.relativePath,Zt(c.relativePath)),u=[...r.get(c.symbolId)??[]].filter(S=>S!==c.relativePath).filter(S=>ut(S,Zt(S))!==m);if(u.length!==1)continue;let d=u[0],f=e.get(`SELECT c.start_line, c.end_line
753
+ ${t}`),i=new Map;for(let a of s)e.isIgnored(a.from_file)||e.isIgnored(a.to_file)||(i.has(a.from_file)||i.set(a.from_file,new Set),i.get(a.from_file).add(a.to_file));let o=e.all(`SELECT relative_path FROM documents
754
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let a of o){if(e.isIgnored(a.relative_path)||!P(a.relative_path))continue;let r=xe(e,a.relative_path),l=i.get(a.relative_path);for(let c of r.keys()){let m=St(e,a.relative_path,c);for(let u of m)u.relativePath!==a.relative_path&&(e.isIgnored(u.relativePath)||(l||(l=new Set,i.set(a.relative_path,l)),l.add(u.relativePath)))}if(P(a.relative_path)==="rust"){let c=we(e,a.relative_path);for(let m of c){let u=St(e,a.relative_path,m);for(let d of u)d.relativePath!==a.relative_path&&(e.isIgnored(d.relativePath)||(l||(l=new Set,i.set(a.relative_path,l)),l.add(d.relativePath)))}}}return i}function _m(e){let n=new Map,t=new Set;for(let[i,o]of e){if(Ce(i))continue;let a=ln(i);t.add(a);for(let r of o){if(Ce(r))continue;let l=ln(r);if(a===l)continue;t.add(l);let c=`${a}->${l}`;n.set(c,(n.get(c)??0)+1)}}let s=new Map;for(let[i,o]of n)s.set(i,o<=2?"violation":"ok");return s}function ln(e){let t=e.replace(/\\/g,"/").split("/").filter(Boolean);return t.length<=1?"(root)":t.length>=3&&["src","lib","app","server","client"].includes(t[0])?`${t[0]}/${t[1]}`:t[0]}function xm(e){return e.includes("types")||e.endsWith(".d.ts")}function Im(e,n,t){let s=de(e,n).filter(i=>i.sourcePath===t);return s.length===0?!1:s.every(i=>i.kind==="side-effect"||i.kind==="namespace"&&i.usedMembers.length===0&&!i.used)}function Ce(e){let n=U(e);return!!(n==="entry"||n==="barrel"||n==="test"||n==="worker"||Nm(vt.basename(e)))}function Nm(e){return!!(e==="index.ts"||e==="index.js"||e==="cli.ts"||e==="main.ts"||e==="main.rs"||e.includes("worker.")||e.includes("postinstall.")||e==="health.ts"||e==="health.js")}import{basename as Ct,extname as un}from"path";function mn(e,n){let{scope:t,maxLoc:s=15,limit:i=30}=n??{},o=Rm(K(e,t)),a=vm(e,t,s),r=Em(ye(e,a),ot(e,a)),l=[];for(let c of a){if(pe(e,c.relativePath,c.startLine))continue;let m=Ct(c.relativePath,un(c.relativePath)),u=[...r.get(c.symbolId)??[]].filter(S=>S!==c.relativePath).filter(S=>Ct(S,un(S))!==m).filter(S=>{let x=U(S);return x!=="barrel"&&x!=="entry"&&x!=="test"});if(u.length!==1)continue;let d=u[0],g=e.get(`SELECT c.start_line, c.end_line
706
755
  FROM mentions m
707
756
  JOIN chunks c ON m.chunk_id = c.id
708
757
  JOIN documents d ON c.document_id = d.id
709
758
  WHERE m.symbol_id = ? AND m.role != 1 AND d.relative_path = ?
710
- LIMIT 1`,c.symbolId,d);if(!f)continue;let p=A(e,d),g=xm(e,d,c.symbol,f.start_line,f.end_line),y=de(p,g),h,b=y?.symbol??"",x=y?.isFunctionLike?_(y.symbol):ut(d);if(y?.isFunctionLike&&y.symbolId!==c.symbolId){let S=[...r.get(y.symbolId)??[]].filter(I=>I!==y.relativePath);h=S.length>0?S.length:No(o,d)}else h=No(o,d);h<=3||l.push({symbol:c.symbol,shortName:_(c.symbol),file:c.relativePath,startLine:c.startLine,endLine:c.endLine,loc:Tn(c),singleCaller:b,singleCallerShort:x,callerFanIn:h})}return l.sort((c,m)=>m.callerFanIn-c.callerFanIn||m.loc-c.loc),l.slice(0,s)}function Tn(e){return e.endLine-e.startLine+1}function _m(e,n,t){return z(e,n).filter(i=>!e.isIgnored(i.relativePath)).filter(i=>j(i.symbol)).filter(i=>Tn(i)<=t&&Tn(i)>=2)}function xm(e,n,t,i,s){let o=M(t);if(!o)return i;let a=Me(e,n).get(o);if(!a||a.length===0)return i;for(let r of a)if(r>=i&&r<=s)return r;return i}function Im(...e){let n=new Map;for(let t of e)for(let[i,s]of t){let o=n.get(i);o||(o=new Set,n.set(i,o));for(let a of s)o.add(a)}return n}function Nm(e){let n=new Map;for(let[t,i]of e){n.has(t)||n.set(t,n.get(t)??0);for(let s of i)n.set(s,(n.get(s)??0)+1)}return n}function No(e,n){let t=e.get(n)??0;if(t>0)return t;let i=ut(n,Zt(n)),s=0;for(let[o,a]of e)o!==n&&ut(o,Zt(o))===i&&a>s&&(s=a);return s}function vo(e,n,t,i){let s=T(n);if(!s)return!0;let o=$(e,n);if(!o)return!0;let a=Co.get(o);return a||(a=Cm(o,s),Co.set(o,a)),a.get(`${t}:${i}`)??!0}var Co=new WeakMap;function Cm(e,n){let t=n==="rust"?new Set(["function_item","function_signature_item"]):n==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),i=new Map,s=o=>{t.has(o.type)&&i.set(`${o.startPosition.row}:${o.endPosition.row}`,vm(o,n));for(let a of o.children)s(a)};return s(e.rootNode),i}function vm(e,n){let t=e.namedChildren.find(u=>u.type==="block"||u.type==="statement_block");if(!t)return!1;let i=t.namedChildren.filter(u=>u.type!=="comment"&&u.type!=="line_comment"&&u.type!=="block_comment");if(i.length!==1)return!1;let s=i[0],o=null;if(s.type==="return_statement"||s.type==="expression_statement"?o=s.namedChild(0)??null:n==="rust"&&(s.type==="call_expression"||s.type==="macro_invocation")&&(o=s),!o)return!1;let a=n==="python"?"call":"call_expression";if(o.type!==a)return!1;let r=o.namedChildren.find(u=>u.type==="arguments"||u.type==="argument_list");if(!r)return!1;let l=r.namedChildren.filter(u=>u.type!=="comment"),c=e.namedChildren.find(u=>u.type==="parameters"||u.type==="formal_parameters");if(!c)return!1;let m=[];for(let u of c.namedChildren)if(u.type==="identifier")m.push(u.text);else{let d=u.namedChildren.find(f=>f.type==="identifier");d&&m.push(d.text)}if(l.length!==m.length)return!1;for(let u=0;u<m.length;u+=1){let d=l[u];if(d.type!=="identifier"||d.text!==m[u])return!1}return!0}function tn(e,n){let{scope:t,maxLoc:i=15,limit:s=30}=n??{},o=Em(e,t,i),a=ee(e,o),r=[];for(let l of o){if(ue(e,l.relativePath,l.startLine))continue;let c=a.get(l.symbolId)??[],m=c.some(f=>j(f.symbol))?c.filter(f=>j(f.symbol)):c,u=new Map;for(let f of m)u.has(f.symbol)||u.set(f.symbol,f);if(u.size!==1||!vo(e,l.relativePath,l.startLine,l.endLine))continue;let[,d]=[...u.entries()][0];r.push({symbol:l.symbol,shortName:_(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:An(l),forwardsTo:d.symbol,forwardsToShort:_(d.symbol),forwardsToFile:d.file})}return r.sort((l,c)=>l.loc-c.loc||l.file.localeCompare(c.file)),r.slice(0,s)}function Em(e,n,t){return z(e,n).filter(i=>!e.isIgnored(i.relativePath)).filter(i=>j(i.symbol)).filter(i=>An(i)>=3&&An(i)<=t)}function An(e){return e.endLine-e.startLine+1}function nn(e,n){let{scope:t,minLoc:i=3,limit:s=30,includeLowConfidence:o=!1}=n??{},a=Lm(e,t),r=z(e,t).filter(p=>p.isTypeLike&&Eo(p)>=i).filter(p=>!e.isIgnored(p.relativePath)).filter(p=>!ue(e,p.relativePath,p.startLine)),l=ge(e,r),c=Ve(e,r),m=Am(l,c),u=new Map;for(let p of r){let g=u.get(p.relativePath);g||(g=new Map,u.set(p.relativePath,g));let y=M(p.symbol);y&&g.set(y,p)}return r.map(p=>{let y=[...m.get(p.symbolId)??new Set].filter(S=>S!==p.relativePath&&!e.isIgnored(S)),{realConsumers:h,barrelConsumers:b}=Dm(e,p.relativePath,p.symbol,y),x=wm(e,p,m,u);return{definition:p,realConsumers:h,barrelConsumers:b,transitivelyReachable:x}}).filter(p=>!p.transitivelyReachable).filter(p=>p.realConsumers.length<=1).filter(p=>!(p.realConsumers.length===0&&p.barrelConsumers>0)).filter(p=>Rm(p.definition,p.realConsumers.length,a)).map(p=>{let g=Mm(e,p.definition.relativePath,p.definition.startLine),y=Fm(e,p.definition),{confidence:h,reason:b}=Tm(p.realConsumers.length,g,y);return{symbol:p.definition.symbol,shortName:_(p.definition.symbol),file:p.definition.relativePath,startLine:p.definition.startLine,endLine:p.definition.endLine,loc:Eo(p.definition),consumers:p.realConsumers.length,barrelConsumers:p.barrelConsumers,kind:g,definerUsesType:y,confidence:h,reason:b}}).filter(p=>o||p.confidence!=="low").sort((p,g)=>{let y={high:0,medium:1,low:2};return y[p.confidence]-y[g.confidence]||g.loc-p.loc||p.file.localeCompare(g.file)||p.startLine-g.startLine}).slice(0,s)}function Lm(e,n){return new Set(z(e,n).filter(t=>t.isFunctionLike).map(t=>t.relativePath))}function Rm(e,n,t){return!(((e.relativePath.split("/").pop()??"").includes("types")||e.relativePath.includes("/types/"))&&n>0||n===0&&t.has(e.relativePath))}function Dm(e,n,t,i){let s=[],o=0,a=M(t);for(let r of i)Pm(e,r,n,a)||$m(e,r,a)?o++:s.push(r);return{realConsumers:s,barrelConsumers:o}}function wm(e,n,t,i){let s=Fi(e,n.relativePath),o=M(n.symbol);if(!o)return!1;let a=s.get(o);if(!a||a.size===0)return!1;let r=i.get(n.relativePath);if(!r)return!1;for(let l of a){let c=r.get(l);if(!c)continue;let m=t.get(c.symbolId);if(m){for(let u of m)if(u!==n.relativePath&&!e.isIgnored(u))return!0}}return!1}var Om=W("stale-abs-file-usage");function $m(e,n,t){if(!t)return!1;let i=T(n);if(!i)return!1;let s=Om.get(e,n,()=>km(e,n,i));return s.importedLeaves.has(t)&&!s.usedLeaves.has(t)}function km(e,n,t){let i=new Set,s=new Set,o=$(e,n);if(!o)return{importedLeaves:i,usedLeaves:s};let a=t==="rust"?new Set(["use_declaration"]):t==="python"?new Set(["import_statement","import_from_statement"]):new Set(["import_statement"]),r=(l,c)=>{let m=c||a.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(m?i.add(l.text):s.add(l.text));for(let u of l.children)r(u,m)};return r(o.rootNode,!1),{importedLeaves:i,usedLeaves:s}}function Pm(e,n,t,i){if(!i)return!1;let s=P(e,n);if(!s)return!1;let o=Is(e,n);if(o.length===0)return!1;let a=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`\\b${a}\\b`),l=s.split(`
711
- `),c=0;for(let m=0;m<l.length;m++){if(!r.test(l[m]??""))continue;if(c++,!o.find(d=>d.startLine<=m&&m<=d.endLine))return!1}return c>0}function Mm(e,n,t){let i=P(e,n);if(!i)return"other";let s=i.split(`
712
- `),o=Math.max(0,t-2),a=Math.min(s.length-1,t+2);for(let r=o;r<=a;r++){let c=(s[r]??"").replace(/^\s*\/\/.*$/g,"");if(/\b(?:export\s+)?(?:abstract\s+)?class\s+\w/.test(c))return"class";if(/\b(?:export\s+)?interface\s+\w/.test(c))return"interface";if(/\b(?:export\s+)?type\s+\w/.test(c))return"type";if(/\b(?:export\s+)?(?:const\s+)?enum\s+\w/.test(c))return"enum"}return"other"}function Fm(e,n){let t=P(e,n.relativePath);if(!t)return!1;let i=M(n.symbol);if(!i)return!1;let s=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`\\b${s}\\b`),a=t.split(`
713
- `);for(let r=0;r<a.length;r++)if(!(r>=n.startLine&&r<=n.endLine)&&o.test(a[r]??""))return!0;return!1}function Tm(e,n,t){return e===0?{confidence:"high",reason:"unused \u2014 no consumers and defining file has no real usage"}:e===1&&n==="class"?{confidence:"low",reason:"1 consumer + class kind \u2014 likely 1:1 encapsulation, not over-abstraction"}:e===1&&!t?{confidence:"high",reason:"1 consumer + defining file never uses it \u2014 type belongs with its consumer"}:{confidence:"medium",reason:"1 consumer \u2014 single-use abstraction"}}function Eo(e){return e.endLine-e.startLine+1}function Am(...e){let n=new Map;for(let t of e)for(let[i,s]of t){let o=n.get(i);o||(o=new Set,n.set(i,o));for(let a of s)o.add(a)}return n}function sn(e,n){let{scope:t,minLoc:i=10,limit:s=30}=n??{},{definitions:o,callerMap:a,calleeMap:r}=jm(e,t);return o.map(l=>{let c=l.endLine-l.startLine+1,m=a.get(l.symbolId)?.size??0,u=r.get(l.symbolId)??[],d=u.filter(g=>g.file!==l.relativePath),f=new Set(d.map(g=>`${g.symbol}|${g.file}`)).size,p=new Set(u.map(g=>`${g.symbol}|${g.file}`)).size;return{symbol:l.symbol,shortName:_(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:m,fanOut:f,calleeCount:p,score:Math.round(c/50*(m/5)*Math.max(f/5,1)*100)/100}}).filter(l=>l.loc>=i).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,s)}function jm(e,n){let t=z(e,n).filter(i=>i.isFunctionLike&&!e.isIgnored(i.relativePath));return{definitions:t,callerMap:ge(e,t),calleeMap:ee(e,t)}}function Lo(e,n={}){let{scope:t}=n,i=Ct(e),s=Ut(e,{scope:t,minLoc:3,skipBarrels:!0}),o=zt(e,{scope:t,minLoc:3}),a=qt(e,{scope:t}),r=Gt(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),l=Kt(e,{scope:t,minLoc:15,minCallees:5,limit:50}),c=en(e,{scope:t,maxLoc:15,limit:50}),m=tn(e,{scope:t,maxLoc:15,limit:50}),u=nn(e,{scope:t,minLoc:3,limit:50}),d=Xt(e,{scope:t}),f=sn(e,{scope:t,minLoc:10,limit:10}),p=s.symbols.filter(R=>!Ie(e,R.relativePath)&&R.kind==="dead-code"),g=p.length,y=p.reduce((R,Y)=>R+Y.loc,0),h=o.filter(R=>!Ie(e,R.relativePath)).length,b=u.length,x=d.results.length,S=r.length,I=[];g>0&&I.push({category:"Dead code",description:`${g} symbols with zero references anywhere \u2014 safe to delete`,effort:"low",impact:"high",count:g,locRecoverable:y}),h>0&&I.push({category:"Isolated symbols",description:`${h} symbols completely disconnected from the codebase graph`,effort:"low",impact:"medium",count:h,locRecoverable:o.filter(R=>!Ie(e,R.relativePath)).reduce((R,Y)=>R+Y.loc,0)});let L=a.filter(R=>R.kind==="real");if(L.length>0&&I.push({category:"Circular dependencies",description:`${L.length} cycle(s) \u2014 break with dependency inversion or module restructuring`,effort:"medium",impact:"high",count:L.length,locRecoverable:0}),S>0&&I.push({category:"Similar functions",description:`${S} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,effort:"medium",impact:"medium",count:S,locRecoverable:0}),l.length>0&&I.push({category:"Extraction candidates",description:`${l.length} large functions with isolated callee clusters \u2014 extract method opportunities`,effort:"medium",impact:"medium",count:l.length,locRecoverable:0}),c.length>0&&I.push({category:"Wrapper functions",description:`${c.length} single-consumer symbols that could be inlined`,effort:"low",impact:"low",count:c.length,locRecoverable:c.reduce((R,Y)=>R+Y.loc,0)}),m.length>0&&I.push({category:"Passthrough functions",description:`${m.length} functions that just forward to one callee \u2014 unnecessary indirection`,effort:"low",impact:"low",count:m.length,locRecoverable:m.reduce((R,Y)=>R+Y.loc,0)}),b>0){let R=u.filter(pt=>pt.consumers===0).length,Y=b-R,Xe=[];R>0&&Xe.push(`${R} unused`),Y>0&&Xe.push(`${Y} single-consumer (not in types file)`),I.push({category:"Stale abstractions",description:`${Xe.join(", ")} \u2014 premature abstraction`,effort:"low",impact:"medium",count:b,locRecoverable:u.reduce((pt,Go)=>pt+Go.loc,0)})}if(x>0){let R=[];d.unusedImports>0&&R.push(`${d.unusedImports} unused imports`),d.layerViolations>0&&R.push(`${d.layerViolations} layer violations`),d.patternDeviations>0&&R.push(`${d.patternDeviations} unique deps`),I.push({category:"Structural drift",description:R.join(", "),effort:d.layerViolations>0?"medium":"low",impact:d.layerViolations>0?"medium":"low",count:x,locRecoverable:0})}let D={high:3,medium:2,low:1},k={low:3,medium:2,high:1};I.sort((R,Y)=>{let Xe=D[R.impact]*k[R.effort];return D[Y.impact]*k[Y.effort]-Xe});let U=Math.max(i.documents,1),B=Math.max(i.symbols,1),F=100,Se=g/B;F-=Math.min(20,Math.round(Se*200));let Un=h/B;F-=Math.min(10,Math.round(Un*200));let dt=a.filter(R=>R.kind==="real").length;F-=Math.min(15,dt*5);let an=S/B*1e3;F-=Math.min(10,Math.round(an));let ae=l.length/B*1e3;F-=Math.min(5,Math.round(ae/2)),F-=Math.min(3,c.length),F-=Math.min(3,m.length);let Uo=b/Math.max(B*.1,1);F-=Math.min(8,Math.round(Uo*10));let qo=x/U;F-=Math.min(5,Math.round(qo*50));let zo=f.filter(R=>R.score>50).length;return F-=Math.min(5,zo*2),F=Math.max(0,Math.min(100,F)),{score:F,overview:{documents:i.documents,symbols:i.symbols,indexSizeBytes:i.indexSizeBytes},findings:{deadSymbols:g,deadLoc:y,isolatedSymbols:h,isolatedLoc:o.filter(R=>!Ie(e,R.relativePath)).reduce((R,Y)=>R+Y.loc,0),cycles:dt,similarPairs:S,extractionCandidates:l.length,wrappers:c.length,passthroughs:m.length,staleTypes:b,driftedFiles:x,complexityHotspotCount:f.length},actions:I,topComplexity:f.slice(0,5).map(R=>({symbol:R.shortName,score:R.score}))}}function Ro(e,n,t){let i=O(e,n),s=O(e,t);if(!i||!s)return null;let o=new Set(Z(e,i).map(g=>g.symbol)),a=new Set(Z(e,s).map(g=>g.symbol)),r=[];for(let g of o)a.has(g)&&r.push(g);let l=[];for(let g of o)a.has(g)||l.push(g);let c=[];for(let g of a)o.has(g)||c.push(g);let m=new Set([...o,...a]),u=m.size>0?r.length/m.size:0,d;m.size===0?d="Neither function calls other tracked symbols. There is no callee-pattern evidence for consolidation; inspect the source bodies directly.":r.length===0?d="These functions do not share any callees. They are not a callee-based consolidation candidate.":l.length===0&&c.length===0?d="These functions have identical tracked callee sets. They are a strong structural match, but identical callees do not prove interchangeable semantics; inspect signatures, control flow, and return values before consolidating.":l.length===0?d="A's tracked callees are a subset of B's. B may subsume part of A's structure, but verify signatures, guards, and non-call logic before replacing A with B.":c.length===0?d="B's tracked callees are a subset of A's. A may subsume part of B's structure, but verify signatures, guards, and non-call logic before replacing B with A.":l.length<=2&&c.length<=2?d=`Create a shared function with the ${r.length} common callees. Pass the ${l.length+c.length} divergent callees as parameters or strategy callbacks.`:d=`Extract the ${r.length} shared callees into a common helper. Each function calls the helper plus its own unique logic (${l.length} callees in A, ${c.length} in B).`;let f=i.endLine-i.startLine+1,p=s.endLine-s.startLine+1;return{symbolA:{symbol:i.symbol,shortName:_(i.symbol),file:i.relativePath,loc:f},symbolB:{symbol:s.symbol,shortName:_(s.symbol),file:s.relativePath,loc:p},similarity:u,sharedCallees:r.map(_),uniqueToA:l.map(_),uniqueToB:c.map(_),consolidationStrategy:d}}import{readFileSync as Do}from"fs";import{join as wo}from"path";function Oo(e,n,t={}){let{context:i=0}=t,s=n.match(/^(.+\.\w+):(\d+)-(\d+)$/);if(s)return Bm(e,s[1],parseInt(s[2],10),parseInt(s[3],10),i);let o=O(e,n);if(!o)return null;let a=e.get("SELECT language FROM documents WHERE relative_path = ?",o.relativePath),r=wo(e.config.projectRoot,o.relativePath),l;try{l=Do(r,"utf-8")}catch{return null}let c=l.split(`
714
- `),m=Math.max(0,o.startLine-i),u=Math.min(c.length-1,o.endLine+i),d=c.slice(m,u+1).join(`
715
- `);return{symbol:o.symbol,shortName:_(o.symbol),relativePath:o.relativePath,startLine:m,endLine:u,language:a?.language??null,source:d}}function Bm(e,n,t,i,s){let o=Q(e,n);if(!o)return null;let a=e.get("SELECT relative_path, language FROM documents WHERE relative_path = ?",o);if(!a)return null;let r=wo(e.config.projectRoot,a.relative_path),l;try{l=Do(r,"utf-8")}catch{return null}let c=l.split(`
716
- `),m=Math.max(0,t-1-s),u=Math.min(c.length-1,i-1+s),d=c.slice(m,u+1).join(`
717
- `);return{symbol:`${a.relative_path}:${t}-${i}`,shortName:`${a.relative_path}:${t}-${i}`,relativePath:a.relative_path,startLine:m,endLine:u,language:a.language,source:d}}import{readFileSync as Wm}from"fs";import{join as Hm}from"path";function $o(e,n){let t=O(e,n);if(!t)return null;let s=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath)?.language??"unknown",o=Hm(e.config.projectRoot,t.relativePath),a="";try{a=Wm(o,"utf-8").split(`
759
+ LIMIT 1`,c.symbolId,d);if(!g)continue;let p=A(e,d),f=Cm(e,d,c.symbol,g.start_line,g.end_line),y=fe(p,f);if(y&&G(y.symbol))continue;let h,b=y?.symbol??"",_=y?.isFunctionLike?I(y.symbol):Ct(d);if(y?.isFunctionLike&&y.symbolId!==c.symbolId){let S=[...r.get(y.symbolId)??[]].filter(x=>x!==y.relativePath);h=S.length>0?S.length:Go(o,d)}else h=Go(o,d);h<=3||l.push({symbol:c.symbol,shortName:I(c.symbol),file:c.relativePath,startLine:c.startLine,endLine:c.endLine,loc:Kn(c),singleCaller:b,singleCallerShort:_,callerFanIn:h})}return l.sort((c,m)=>m.callerFanIn-c.callerFanIn||m.loc-c.loc),l.slice(0,i)}function Kn(e){return e.endLine-e.startLine+1}function vm(e,n,t){return Y(e,n).filter(s=>!e.isIgnored(s.relativePath)).filter(s=>j(s.symbol)).filter(s=>!G(s.symbol)).filter(s=>Kn(s)<=t&&Kn(s)>=2)}function Cm(e,n,t,s,i){let o=F(t);if(!o)return s;let a=xe(e,n).get(o);if(!a||a.length===0)return s;for(let r of a)if(r>=s&&r<=i)return r;return s}function Em(...e){let n=new Map;for(let t of e)for(let[s,i]of t){let o=n.get(s);o||(o=new Set,n.set(s,o));for(let a of i)o.add(a)}return n}function Rm(e){let n=new Map;for(let[t,s]of e){n.has(t)||n.set(t,n.get(t)??0);for(let i of s)n.set(i,(n.get(i)??0)+1)}return n}function Go(e,n){let t=e.get(n)??0;if(t>0)return t;let s=Ct(n,un(n)),i=0;for(let[o,a]of e)o!==n&&Ct(o,un(o))===s&&a>i&&(i=a);return i}function Ko(e,n,t,s){let i=P(n);if(!i)return!0;let o=O(e,n);if(!o)return!0;let a=Yo.get(o);return a||(a=Lm(o,i),Yo.set(o,a)),a.get(`${t}:${s}`)??!0}var Yo=new WeakMap;function Lm(e,n){let t=n==="rust"?new Set(["function_item","function_signature_item"]):n==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),s=new Map,i=o=>{t.has(o.type)&&s.set(`${o.startPosition.row}:${o.endPosition.row}`,wm(o,n));for(let a of o.children)i(a)};return i(e.rootNode),s}function wm(e,n){let t=e.namedChildren.find(u=>u.type==="block"||u.type==="statement_block");if(!t)return!1;let s=t.namedChildren.filter(u=>u.type!=="comment"&&u.type!=="line_comment"&&u.type!=="block_comment");if(s.length!==1)return!1;let i=s[0],o=null;if(i.type==="return_statement"||i.type==="expression_statement"?o=i.namedChild(0)??null:n==="rust"&&(i.type==="call_expression"||i.type==="macro_invocation")&&(o=i),!o)return!1;let a=n==="python"?"call":"call_expression";if(o.type!==a)return!1;let r=o.namedChildren.find(u=>u.type==="arguments"||u.type==="argument_list");if(!r)return!1;let l=r.namedChildren.filter(u=>u.type!=="comment"),c=e.namedChildren.find(u=>u.type==="parameters"||u.type==="formal_parameters");if(!c)return!1;let m=[];for(let u of c.namedChildren)if(u.type==="identifier")m.push(u.text);else{let d=u.namedChildren.find(g=>g.type==="identifier");d&&m.push(d.text)}if(l.length!==m.length)return!1;for(let u=0;u<m.length;u+=1){let d=l[u];if(d.type!=="identifier"||d.text!==m[u])return!1}return!0}function dn(e,n){let{scope:t,maxLoc:s=15,limit:i=30}=n??{},o=Dm(e,t,s),a=se(e,o),r=[];for(let l of o){if(pe(e,l.relativePath,l.startLine))continue;let c=a.get(l.symbolId)??[],m=c.some(g=>j(g.symbol))?c.filter(g=>j(g.symbol)):c,u=new Map;for(let g of m)u.has(g.symbol)||u.set(g.symbol,g);if(u.size!==1||!Ko(e,l.relativePath,l.startLine,l.endLine))continue;let[,d]=[...u.entries()][0];r.push({symbol:l.symbol,shortName:I(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:Qn(l),forwardsTo:d.symbol,forwardsToShort:I(d.symbol),forwardsToFile:d.file})}return r.sort((l,c)=>l.loc-c.loc||l.file.localeCompare(c.file)),r.slice(0,i)}function Dm(e,n,t){return Y(e,n).filter(s=>!e.isIgnored(s.relativePath)).filter(s=>j(s.symbol)).filter(s=>!Ye(s.symbol)).filter(s=>!G(s.symbol)).filter(s=>Qn(s)>=3&&Qn(s)<=t)}function Qn(e){return e.endLine-e.startLine+1}function pn(e,n){let{scope:t,minLoc:s=3,maxLoc:i=80,limit:o=30,includeLowConfidence:a=!1}=n??{},r=km(e,t),l=Y(e,t).filter(f=>f.isTypeLike&&Xn(f)>=s).filter(f=>Xn(f)<=i).filter(f=>!e.isIgnored(f.relativePath)).filter(f=>!Om(f.symbol)).filter(f=>!pe(e,f.relativePath,f.startLine)),c=ye(e,l),m=ot(e,l),u=Jm(c,m),d=new Map;for(let f of l){let y=d.get(f.relativePath);y||(y=new Map,d.set(f.relativePath,y));let h=F(f.symbol);h&&y.set(h,f)}return l.map(f=>{let h=[...u.get(f.symbolId)??new Set].filter(x=>x!==f.relativePath&&!e.isIgnored(x)),{realConsumers:b,barrelConsumers:_}=Pm(e,f.relativePath,f.symbol,h),S=Mm(e,f,u,d);return{definition:f,realConsumers:b,barrelConsumers:_,transitivelyReachable:S}}).filter(f=>!f.transitivelyReachable).filter(f=>f.realConsumers.length<=1).filter(f=>!(f.realConsumers.length===0&&f.barrelConsumers>0)).filter(f=>$m(f.definition,f.realConsumers.length,r)).map(f=>{let y=Bm(e,f.definition.relativePath,f.definition.startLine),h=Qo(f.definition.relativePath)?!0:Wm(e,f.definition),{confidence:b,reason:_}=Hm(f.realConsumers.length,y,h);return{symbol:f.definition.symbol,shortName:I(f.definition.symbol),file:f.definition.relativePath,startLine:f.definition.startLine,endLine:f.definition.endLine,loc:Xn(f.definition),consumers:f.realConsumers.length,barrelConsumers:f.barrelConsumers,kind:y,definerUsesType:h,confidence:b,reason:_}}).filter(f=>a||f.confidence!=="low").sort((f,y)=>{let h={high:0,medium:1,low:2};return h[f.confidence]-h[y.confidence]||y.loc-f.loc||f.file.localeCompare(y.file)||f.startLine-y.startLine}).slice(0,o)}function km(e,n){return new Set(Y(e,n).filter(t=>t.isFunctionLike).map(t=>t.relativePath))}function Om(e){let n=V(e);if("kind"in n)return!1;let t=n.descriptors;if(t.length<2)return!1;let s=t[t.length-1],i=t[t.length-2];return s?.suffix==="type"&&i?.suffix==="type"}function Qo(e){let t=(e.split("/").pop()??"").replace(/\.[^.]+$/,"");return!!(t==="types"||t==="models"||t==="schema"||t==="common"||t==="protocol"||t==="proto"||t==="dto"||t==="mod"||/(^|\/)types(\/|\.)/.test(e)||/(^|\/)models?(\/|\.)/.test(e)||/(^|\/)proto(?:col)?(\/|\.)/.test(e)||/(^|\/)schema(\/|\.)/.test(e))}function $m(e,n,t){return!(Qo(e.relativePath)&&n>0||n===0&&t.has(e.relativePath))}function Pm(e,n,t,s){let i=[],o=0,a=F(t);for(let r of s)jm(e,r,n,a)||Tm(e,r,a)?o++:i.push(r);return{realConsumers:i,barrelConsumers:o}}function Mm(e,n,t,s){let i=ni(e,n.relativePath),o=F(n.symbol);if(!o)return!1;let a=i.get(o);if(!a||a.size===0)return!1;let r=s.get(n.relativePath);if(!r)return!1;for(let l of a){let c=r.get(l);if(!c)continue;let m=t.get(c.symbolId);if(m){for(let u of m)if(u!==n.relativePath&&!e.isIgnored(u))return!0}}return!1}var Fm=W("stale-abs-file-usage");function Tm(e,n,t){if(!t)return!1;let s=P(n);if(!s)return!1;let i=Fm.get(e,n,()=>Am(e,n,s));return i.importedLeaves.has(t)&&!i.usedLeaves.has(t)}function Am(e,n,t){let s=new Set,i=new Set,o=O(e,n);if(!o)return{importedLeaves:s,usedLeaves:i};let a=t==="rust"?new Set(["use_declaration"]):t==="python"?new Set(["import_statement","import_from_statement"]):new Set(["import_statement"]),r=(l,c)=>{let m=c||a.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(m?s.add(l.text):i.add(l.text));for(let u of l.children)r(u,m)};return r(o.rootNode,!1),{importedLeaves:s,usedLeaves:i}}function jm(e,n,t,s){if(!s)return!1;let i=M(e,n);if(!i)return!1;let o=Yi(e,n);if(o.length===0)return!1;let a=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`\\b${a}\\b`),l=i.split(`
760
+ `),c=0;for(let m=0;m<l.length;m++){if(!r.test(l[m]??""))continue;if(c++,!o.find(d=>d.startLine<=m&&m<=d.endLine))return!1}return c>0}function Bm(e,n,t){let s=M(e,n);if(!s)return"other";let i=s.split(`
761
+ `),o=Math.max(0,t-2),a=Math.min(i.length-1,t+2);for(let r=o;r<=a;r++){let c=(i[r]??"").replace(/^\s*\/\/.*$/g,"");if(/\b(?:export\s+)?(?:abstract\s+)?class\s+\w/.test(c))return"class";if(/\b(?:export\s+)?interface\s+\w/.test(c))return"interface";if(/\b(?:export\s+)?type\s+\w/.test(c))return"type";if(/\b(?:export\s+)?(?:const\s+)?enum\s+\w/.test(c))return"enum"}return"other"}function Wm(e,n){let t=M(e,n.relativePath);if(!t)return!1;let s=F(n.symbol);if(!s)return!1;let i=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`\\b${i}\\b`),a=t.split(`
762
+ `);for(let r=0;r<a.length;r++)if(!(r>=n.startLine&&r<=n.endLine)&&o.test(a[r]??""))return!0;return!1}function Hm(e,n,t){return e===0?{confidence:"high",reason:"unused \u2014 no consumers and defining file has no real usage"}:e===1&&n==="class"?{confidence:"low",reason:"1 consumer + class kind \u2014 likely 1:1 encapsulation, not over-abstraction"}:e===1&&!t?{confidence:"high",reason:"1 consumer + defining file never uses it \u2014 type belongs with its consumer"}:{confidence:"medium",reason:"1 consumer \u2014 single-use abstraction"}}function Xn(e){return e.endLine-e.startLine+1}function Jm(...e){let n=new Map;for(let t of e)for(let[s,i]of t){let o=n.get(s);o||(o=new Set,n.set(s,o));for(let a of i)o.add(a)}return n}function fn(e,n){let{scope:t,minLoc:s=10,limit:i=30}=n??{},{definitions:o,callerMap:a,calleeMap:r}=Um(e,t);return o.map(l=>{let c=l.endLine-l.startLine+1,m=a.get(l.symbolId)?.size??0,u=r.get(l.symbolId)??[],d=u.filter(f=>f.file!==l.relativePath),g=new Set(d.map(f=>`${f.symbol}|${f.file}`)).size,p=new Set(u.map(f=>`${f.symbol}|${f.file}`)).size;return{symbol:l.symbol,shortName:I(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:m,fanOut:g,calleeCount:p,score:Math.round(c/50*(m/5)*Math.max(g/5,1)*100)/100}}).filter(l=>l.loc>=s).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,i)}function Um(e,n){let t=Y(e,n).filter(s=>Ve(s.symbol)&&!e.isIgnored(s.relativePath)).filter(s=>U(s.relativePath)!=="test").filter(s=>!G(s.symbol));return{definitions:t,callerMap:ye(e,t),calleeMap:se(e,t)}}function Xo(e,n={}){let{scope:t}=n,s=Bt(e),i=tn(e,{scope:t,minLoc:3,skipBarrels:!0}),o=sn(e,{scope:t,minLoc:3}),a=nn(e,{scope:t}),r=on(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),l=an(e,{scope:t,minLoc:15,minCallees:5,limit:50}),c=mn(e,{scope:t,maxLoc:15,limit:50}),m=dn(e,{scope:t,maxLoc:15,limit:50}),u=pn(e,{scope:t,minLoc:3,limit:50}),d=cn(e,{scope:t}),g=fn(e,{scope:t,minLoc:10,limit:10}),p=i.symbols.filter(R=>!ve(e,R.relativePath)&&!rt(e,R.symbol,R.relativePath)&&R.kind==="dead-code"),f=p.length,y=p.reduce((R,Q)=>R+Q.loc,0),h=o.filter(R=>!ve(e,R.relativePath)&&!rt(e,R.symbol,R.relativePath)).length,b=u.length,_=d.unusedImports+d.layerViolations,S=r.length,x=[];f>0&&x.push({category:"Dead code",description:`${f} symbols with zero references anywhere \u2014 safe to delete`,effort:"low",impact:"high",count:f,locRecoverable:y}),h>0&&x.push({category:"Isolated symbols",description:`${h} symbols completely disconnected from the codebase graph`,effort:"low",impact:"medium",count:h,locRecoverable:o.filter(R=>!ve(e,R.relativePath)&&!rt(e,R.symbol,R.relativePath)).reduce((R,Q)=>R+Q.loc,0)});let L=a.filter(R=>R.kind==="real");if(L.length>0&&x.push({category:"Circular dependencies",description:`${L.length} cycle(s) \u2014 break with dependency inversion or module restructuring`,effort:"medium",impact:"high",count:L.length,locRecoverable:0}),S>0&&x.push({category:"Similar functions",description:`${S} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,effort:"medium",impact:"medium",count:S,locRecoverable:0}),l.length>0&&x.push({category:"Extraction candidates",description:`${l.length} large functions with isolated callee clusters \u2014 extract method opportunities`,effort:"medium",impact:"medium",count:l.length,locRecoverable:0}),c.length>0&&x.push({category:"Wrapper functions",description:`${c.length} single-consumer symbols that could be inlined`,effort:"low",impact:"low",count:c.length,locRecoverable:c.reduce((R,Q)=>R+Q.loc,0)}),m.length>0&&x.push({category:"Passthrough functions",description:`${m.length} functions that just forward to one callee \u2014 unnecessary indirection`,effort:"low",impact:"low",count:m.length,locRecoverable:m.reduce((R,Q)=>R+Q.loc,0)}),b>0){let R=u.filter(Rt=>Rt.consumers===0).length,Q=b-R,at=[];R>0&&at.push(`${R} unused`),Q>0&&at.push(`${Q} single-consumer (not in types file)`),x.push({category:"Stale abstractions",description:`${at.join(", ")} \u2014 premature abstraction`,effort:"low",impact:"medium",count:b,locRecoverable:u.reduce((Rt,yr)=>Rt+yr.loc,0)})}if(_>0||d.patternDeviations>0){let R=[];d.unusedImports>0&&R.push(`${d.unusedImports} unused imports`),d.layerViolations>0&&R.push(`${d.layerViolations} layer violations`),d.patternDeviations>0&&R.push(`${d.patternDeviations} unique deps`),x.push({category:"Structural drift",description:R.join(", "),effort:d.layerViolations>0?"medium":"low",impact:d.layerViolations>0?"medium":"low",count:_,locRecoverable:0})}let w={high:3,medium:2,low:1},$={low:3,medium:2,high:1};x.sort((R,Q)=>{let at=w[R.impact]*$[R.effort];return w[Q.impact]*$[Q.effort]-at});let q=Math.max(s.documents,1),B=Math.max(s.symbols,1),T=100,_e=f/B;T-=Math.min(20,Math.round(_e*200));let is=h/B;T-=Math.min(10,Math.round(is*200));let Et=a.filter(R=>R.kind==="real").length;T-=Math.min(15,Et*5);let bn=S/B*1e3;T-=Math.min(10,Math.round(bn));let ce=l.length/B*1e3;T-=Math.min(5,Math.round(ce/2)),T-=Math.min(3,c.length),T-=Math.min(3,m.length);let fr=b/Math.max(B*.1,1);T-=Math.min(8,Math.round(fr*10));let gr=_/q;T-=Math.min(5,Math.round(gr*50));let hr=g.filter(R=>R.score>50).length;return T-=Math.min(5,hr*2),T=Math.max(0,Math.min(100,T)),{score:T,overview:{documents:s.documents,symbols:s.symbols,indexSizeBytes:s.indexSizeBytes},findings:{deadSymbols:f,deadLoc:y,isolatedSymbols:h,isolatedLoc:o.filter(R=>!ve(e,R.relativePath)).reduce((R,Q)=>R+Q.loc,0),cycles:Et,similarPairs:S,extractionCandidates:l.length,wrappers:c.length,passthroughs:m.length,staleTypes:b,driftedFiles:_,complexityHotspotCount:g.length},actions:x,topComplexity:g.slice(0,5).map(R=>({symbol:R.shortName,score:R.score}))}}function Zo(e,n,t){let s=k(e,n),i=k(e,t);if(!s||!i)return null;let o=new Set(ne(e,s).map(f=>f.symbol)),a=new Set(ne(e,i).map(f=>f.symbol)),r=[];for(let f of o)a.has(f)&&r.push(f);let l=[];for(let f of o)a.has(f)||l.push(f);let c=[];for(let f of a)o.has(f)||c.push(f);let m=new Set([...o,...a]),u=m.size>0?r.length/m.size:0,d;m.size===0?d="Neither function calls other tracked symbols. There is no callee-pattern evidence for consolidation; inspect the source bodies directly.":r.length===0?d="These functions do not share any callees. They are not a callee-based consolidation candidate.":l.length===0&&c.length===0?d="These functions have identical tracked callee sets. They are a strong structural match, but identical callees do not prove interchangeable semantics; inspect signatures, control flow, and return values before consolidating.":l.length===0?d="A's tracked callees are a subset of B's. B may subsume part of A's structure, but verify signatures, guards, and non-call logic before replacing A with B.":c.length===0?d="B's tracked callees are a subset of A's. A may subsume part of B's structure, but verify signatures, guards, and non-call logic before replacing B with A.":l.length<=2&&c.length<=2?d=`Create a shared function with the ${r.length} common callees. Pass the ${l.length+c.length} divergent callees as parameters or strategy callbacks.`:d=`Extract the ${r.length} shared callees into a common helper. Each function calls the helper plus its own unique logic (${l.length} callees in A, ${c.length} in B).`;let g=s.endLine-s.startLine+1,p=i.endLine-i.startLine+1;return{symbolA:{symbol:s.symbol,shortName:I(s.symbol),file:s.relativePath,loc:g},symbolB:{symbol:i.symbol,shortName:I(i.symbol),file:i.relativePath,loc:p},similarity:u,sharedCallees:r.map(I),uniqueToA:l.map(I),uniqueToB:c.map(I),consolidationStrategy:d}}import{readFileSync as er}from"fs";import{join as tr}from"path";function nr(e,n,t={}){let{context:s=0}=t,i=n.match(/^(.+\.\w+):(\d+)-(\d+)$/);if(i)return qm(e,i[1],parseInt(i[2],10),parseInt(i[3],10),s);let o=k(e,n);if(!o)return null;let a=e.get("SELECT language FROM documents WHERE relative_path = ?",o.relativePath),r=tr(e.config.projectRoot,o.relativePath),l;try{l=er(r,"utf-8")}catch{return null}let c=l.split(`
763
+ `),m=Math.max(0,o.startLine-s),u=Math.min(c.length-1,o.endLine+s),d=c.slice(m,u+1).join(`
764
+ `);return{symbol:o.symbol,shortName:I(o.symbol),relativePath:o.relativePath,startLine:m,endLine:u,language:a?.language??null,source:d}}function qm(e,n,t,s,i){let o=ee(e,n);if(!o)return null;let a=e.get("SELECT relative_path, language FROM documents WHERE relative_path = ?",o);if(!a)return null;let r=tr(e.config.projectRoot,a.relative_path),l;try{l=er(r,"utf-8")}catch{return null}let c=l.split(`
765
+ `),m=Math.max(0,t-1-i),u=Math.min(c.length-1,s-1+i),d=c.slice(m,u+1).join(`
766
+ `);return{symbol:`${a.relative_path}:${t}-${s}`,shortName:`${a.relative_path}:${t}-${s}`,relativePath:a.relative_path,startLine:m,endLine:u,language:a.language,source:d}}import{readFileSync as zm}from"fs";import{join as Vm}from"path";function sr(e,n){let t=k(e,n);if(!t)return null;let i=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath)?.language??"unknown",o=Vm(e.config.projectRoot,t.relativePath),a="";try{a=zm(o,"utf-8").split(`
718
767
  `).slice(t.startLine,t.endLine+1).join(`
719
- `)}catch{}let r=Jm(a,s),l=t.endLine-t.startLine+1,m=ee(e,[t],{additive:!0}).get(t.symbolId)??[],u=new Set(m.map(p=>p.symbol)),d=e.get(`SELECT COUNT(DISTINCT c.document_id) AS c
768
+ `)}catch{}let r=Gm(a,i),l=t.endLine-t.startLine+1,m=se(e,[t],{additive:!0}).get(t.symbolId)??[],u=new Set(m.map(p=>p.symbol)),d=e.get(`SELECT COUNT(DISTINCT c.document_id) AS c
720
769
  FROM mentions m
721
770
  JOIN chunks c ON m.chunk_id = c.id
722
- WHERE m.symbol_id = ? AND m.role != 1`,t.symbolId),f=new Set(m.filter(p=>p.file!==t.relativePath).map(p=>p.symbol)).size;return{symbol:t.symbol,shortName:_(t.symbol),relativePath:t.relativePath,startLine:t.startLine,endLine:t.endLine,loc:l,branches:r,cyclomaticEstimate:r+1,calleeCount:u.size,fanIn:d?.c??0,fanOut:f}}function Jm(e,n){let t=Um(e),i=0,s=[/\bif\b/g,/\belse\s+if\b/g,/\belse\b/g,/\bfor\b/g,/\bwhile\b/g,/\bswitch\b/g,/\bcase\b/g,/\bcatch\b/g,/\?\s*[^?]/g,/&&/g,/\|\|/g];for(let o of s){let a=t.match(o);a&&(i+=a.length)}if(n==="python"){let o=[/\belif\b/g,/\bexcept\b/g,/\bfinally\b/g];for(let a of o){let r=t.match(a);r&&(i+=r.length)}}else if(n==="rust"){let o=[/\bmatch\b/g,/=>/g,/\bloop\b/g];for(let a of o){let r=t.match(a);r&&(i+=r.length)}}else if(n==="ruby"){let o=[/\belsif\b/g,/\bunless\b/g,/\brescue\b/g,/\bwhen\b/g];for(let a of o){let r=t.match(a);r&&(i+=r.length)}}else if(n==="go"){let o=[/\bselect\b/g,/\bdefer\b/g];for(let a of o){let r=t.match(a);r&&(i+=r.length)}}return i}function Um(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function ko(e,n){let t=O(e,n);if(!t)return null;let i=[{file:t.relativePath,line:t.startLine}],s=we(e,t),a=(s.length>0?s:Re(e,t)).filter(c=>!e.isIgnored(c.file)).map(c=>({file:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol??"(top-level)",enclosingShort:c.enclosingSymbol?_(c.enclosingSymbol):"(top-level)"})),{producers:r,consumers:l}=qm(e,t,a);return{symbol:t.symbol,shortName:_(t.symbol),relativePath:t.relativePath,definitionSites:i.filter(c=>!e.isIgnored(c.file)),usageSites:a,producers:r.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:_(c.symbol),file:c.file})),consumers:l.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:c.symbol===c.file?"(top-level)":_(c.symbol),file:c.file}))}}function qm(e,n,t){let i=jn(Z(e,n,{limit:30}).map(a=>({symbol:a.symbol,file:a.file}))),s=jn(fe(e,n,{limit:30})),o=s.length>0?s:jn(t.map(a=>({symbol:a.enclosingSymbol==="(top-level)"?a.file:a.enclosingSymbol,file:a.file})));return{producers:i,consumers:o}}function jn(e){let n=new Set,t=[];for(let i of e){let s=`${i.symbol}|${i.file}`;n.has(s)||(n.add(s),t.push(i))}return t}function Po(e,n,t={}){let{direction:i="backward",maxDepth:s=3}=t,o=O(e,n);return o?i==="backward"?zm(e,o,s):Gm(e,o):null}function zm(e,n,t){let i=[],s=new Set([n.symbol]),o=[n];for(let a=1;a<=t&&o.length!==0;a++){let r=[];for(let l of o){let c=Z(e,l);for(let m of c){if(s.has(m.symbol))continue;s.add(m.symbol),i.push({symbol:m.symbol,shortName:_(m.symbol),file:m.file,relationship:a===1?"referenced within definition (callee)":`depth ${a} callee`});let u=Ue(e,m.symbol);u&&!e.isIgnored(u.relativePath)&&r.push(u)}}o=r}return{symbol:n.symbol,shortName:_(n.symbol),direction:"backward",connectedSymbols:i}}function Gm(e,n){let t=we(e,n),i=t.length>0?t:Re(e,n),s=new Set,o=[];for(let a of i){if(o.length>=30)break;if(e.isIgnored(a.file))continue;let r=a.enclosingSymbol??de(A(e,a.file),a.line)?.symbol??null;if(!r||r===n.symbol)continue;let l=Ue(e,r);if(l){for(let c of Z(e,l))if(c.symbol!==n.symbol&&c.symbol!==r&&c.file!==a.file&&!e.isIgnored(c.file)&&!s.has(c.symbol)&&(s.add(c.symbol),o.push({symbol:c.symbol,shortName:_(c.symbol),file:c.file,relationship:`used alongside target in ${_(r)}`}),o.length>=30))break}}return o.sort((a,r)=>a.file.localeCompare(r.file)),{symbol:n.symbol,shortName:_(n.symbol),direction:"forward",connectedSymbols:o}}function Fo(e,n={}){let{scope:t,limit:i}=n,s=t?`AND barrel_d.relative_path LIKE '%${t}%'`:"",o=e.all(`SELECT DISTINCT
771
+ WHERE m.symbol_id = ? AND m.role != 1`,t.symbolId),g=new Set(m.filter(p=>p.file!==t.relativePath).map(p=>p.symbol)).size;return{symbol:t.symbol,shortName:I(t.symbol),relativePath:t.relativePath,startLine:t.startLine,endLine:t.endLine,loc:l,branches:r,cyclomaticEstimate:r+1,calleeCount:u.size,fanIn:d?.c??0,fanOut:g}}function Gm(e,n){let t=Ym(e),s=0,i=[/\bif\b/g,/\belse\s+if\b/g,/\belse\b/g,/\bfor\b/g,/\bwhile\b/g,/\bswitch\b/g,/\bcase\b/g,/\bcatch\b/g,/\?\s*[^?]/g,/&&/g,/\|\|/g];for(let o of i){let a=t.match(o);a&&(s+=a.length)}if(n==="python"){let o=[/\belif\b/g,/\bexcept\b/g,/\bfinally\b/g];for(let a of o){let r=t.match(a);r&&(s+=r.length)}}else if(n==="rust"){let o=[/\bmatch\b/g,/=>/g,/\bloop\b/g];for(let a of o){let r=t.match(a);r&&(s+=r.length)}}else if(n==="ruby"){let o=[/\belsif\b/g,/\bunless\b/g,/\brescue\b/g,/\bwhen\b/g];for(let a of o){let r=t.match(a);r&&(s+=r.length)}}else if(n==="go"){let o=[/\bselect\b/g,/\bdefer\b/g];for(let a of o){let r=t.match(a);r&&(s+=r.length)}}return s}function Ym(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function ir(e,n){let t=k(e,n);if(!t)return null;let s=[{file:t.relativePath,line:t.startLine}],i=Pe(e,t),a=(i.length>0?i:$e(e,t)).filter(c=>!e.isIgnored(c.file)).map(c=>({file:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol??"(top-level)",enclosingShort:c.enclosingSymbol?I(c.enclosingSymbol):"(top-level)"})),{producers:r,consumers:l}=Km(e,t,a);return{symbol:t.symbol,shortName:I(t.symbol),relativePath:t.relativePath,definitionSites:s.filter(c=>!e.isIgnored(c.file)),usageSites:a,producers:r.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:I(c.symbol),file:c.file})),consumers:l.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:c.symbol===c.file?"(top-level)":I(c.symbol),file:c.file}))}}function Km(e,n,t){let s=Zn(ne(e,n,{limit:30}).map(a=>({symbol:a.symbol,file:a.file}))),i=Zn(he(e,n,{limit:30})),o=i.length>0?i:Zn(t.map(a=>({symbol:a.enclosingSymbol==="(top-level)"?a.file:a.enclosingSymbol,file:a.file})));return{producers:s,consumers:o}}function Zn(e){let n=new Set,t=[];for(let s of e){let i=`${s.symbol}|${s.file}`;n.has(i)||(n.add(i),t.push(s))}return t}function or(e,n,t={}){let{direction:s="backward",maxDepth:i=3}=t,o=k(e,n);return o?s==="backward"?Qm(e,o,i):Xm(e,o):null}function Qm(e,n,t){let s=[],i=new Set([n.symbol]),o=[n];for(let a=1;a<=t&&o.length!==0;a++){let r=[];for(let l of o){let c=ne(e,l);for(let m of c){if(i.has(m.symbol))continue;i.add(m.symbol),s.push({symbol:m.symbol,shortName:I(m.symbol),file:m.file,relationship:a===1?"referenced within definition (callee)":`depth ${a} callee`});let u=Xe(e,m.symbol);u&&!e.isIgnored(u.relativePath)&&r.push(u)}}o=r}return{symbol:n.symbol,shortName:I(n.symbol),direction:"backward",connectedSymbols:s}}function Xm(e,n){let t=Pe(e,n),s=t.length>0?t:$e(e,n),i=new Set,o=[];for(let a of s){if(o.length>=30)break;if(e.isIgnored(a.file))continue;let r=a.enclosingSymbol??fe(A(e,a.file),a.line)?.symbol??null;if(!r||r===n.symbol)continue;let l=Xe(e,r);if(l){for(let c of ne(e,l))if(c.symbol!==n.symbol&&c.symbol!==r&&c.file!==a.file&&!e.isIgnored(c.file)&&!i.has(c.symbol)&&(i.add(c.symbol),o.push({symbol:c.symbol,shortName:I(c.symbol),file:c.file,relationship:`used alongside target in ${I(r)}`}),o.length>=30))break}}return o.sort((a,r)=>a.file.localeCompare(r.file)),{symbol:n.symbol,shortName:I(n.symbol),direction:"forward",connectedSymbols:o}}function ar(e,n={}){let{scope:t,limit:s}=n,i=t?`AND barrel_d.relative_path LIKE '%${t}%'`:"",o=e.all(`SELECT DISTINCT
723
772
  barrel_d.id AS barrel_doc_id,
724
773
  barrel_d.relative_path AS barrel_path,
725
774
  gs.id AS symbol_id,
@@ -748,8 +797,8 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
748
797
  ${e.symbolNoiseFor("gs")}
749
798
  -- Only function-level symbols (ending with ().), not module-level
750
799
  AND gs.symbol LIKE '%().'
751
- ${s}
752
- ORDER BY barrel_d.relative_path, gs.symbol`),a=[];for(let l of o){if(e.isIgnored(l.barrel_path)||e.isIgnored(l.original_path)||On(e,l.barrel_path))continue;let c=e.get(`SELECT
800
+ ${i}
801
+ ORDER BY barrel_d.relative_path, gs.symbol`),a=[];for(let l of o){if(e.isIgnored(l.barrel_path)||e.isIgnored(l.original_path)||Un(e,l.barrel_path))continue;let c=e.get(`SELECT
753
802
  SUM(CASE WHEN uses_barrel = 1 THEN 1 ELSE 0 END) AS barrel_consumers,
754
803
  SUM(CASE WHEN uses_barrel = 0 THEN 1 ELSE 0 END) AS direct_consumers
755
804
  FROM (
@@ -778,91 +827,91 @@ ${d}`,c+=1+d.length,m+=ds(d),i+=d.length+1}let u=kl(l);u&&t.push({...u,start:r,e
778
827
  AND consumer_d.id != ?
779
828
  ${e.pathExclusionsFor("consumer_d")}
780
829
  GROUP BY consumer_d.id
781
- )`,l.barrel_doc_id,l.symbol_id,l.barrel_doc_id,l.original_doc_id),m=c?.barrel_consumers??0,u=c?.direct_consumers??0;m===0&&u===0&&a.push({barrelFile:l.barrel_path,symbol:l.symbol,shortName:_(l.symbol),originalFile:l.original_path,barrelConsumers:m,directConsumers:u})}a.sort((l,c)=>c.directConsumers-l.directConsumers||l.barrelFile.localeCompare(c.barrelFile)||l.shortName.localeCompare(c.shortName));let r=Vm([...a,...Ym(e,t)]);return r.sort((l,c)=>c.directConsumers-l.directConsumers||l.barrelFile.localeCompare(c.barrelFile)||l.shortName.localeCompare(c.shortName)),i?r.slice(0,i):r}function Ym(e,n){let i=e.all(`SELECT relative_path
830
+ )`,l.barrel_doc_id,l.symbol_id,l.barrel_doc_id,l.original_doc_id),m=c?.barrel_consumers??0,u=c?.direct_consumers??0;m===0&&u===0&&a.push({barrelFile:l.barrel_path,symbol:l.symbol,shortName:I(l.symbol),originalFile:l.original_path,barrelConsumers:m,directConsumers:u})}a.sort((l,c)=>c.directConsumers-l.directConsumers||l.barrelFile.localeCompare(c.barrelFile)||l.shortName.localeCompare(c.shortName));let r=td([...a,...Zm(e,t)]);return r.sort((l,c)=>c.directConsumers-l.directConsumers||l.barrelFile.localeCompare(c.barrelFile)||l.shortName.localeCompare(c.shortName)),s?r.slice(0,s):r}function Zm(e,n){let s=e.all(`SELECT relative_path
782
831
  FROM documents
783
832
  WHERE 1 = 1
784
833
  ${n?"AND relative_path LIKE ?":""}
785
834
  ${e.pathExclusionsFor("documents")}
786
- ORDER BY relative_path`,...n?[`%${n}%`]:[]).map(o=>o.relative_path).filter(o=>!e.isIgnored(o)).filter(o=>wn(e,o).length>0),s=[];for(let o of i){let a=wn(e,o).filter(l=>l.sourcePath&&!e.isIgnored(l.sourcePath));if(!(a.length===0||Mo(e,o,o)>0))for(let l of a){let c=l.sourcePath,m=Km(e,c);m&&s.push({barrelFile:o,symbol:m.symbol,shortName:_(m.symbol),originalFile:c,barrelConsumers:0,directConsumers:Mo(e,c,o)})}}return s}function Mo(e,n,t){let i=e.all(`SELECT relative_path
835
+ ORDER BY relative_path`,...n?[`%${n}%`]:[]).map(o=>o.relative_path).filter(o=>!e.isIgnored(o)).filter(o=>Jn(e,o).length>0),i=[];for(let o of s){let a=Jn(e,o).filter(l=>l.sourcePath&&!e.isIgnored(l.sourcePath));if(!(a.length===0||rr(e,o,o)>0))for(let l of a){let c=l.sourcePath,m=ed(e,c);m&&i.push({barrelFile:o,symbol:m.symbol,shortName:I(m.symbol),originalFile:c,barrelConsumers:0,directConsumers:rr(e,c,o)})}}return i}function rr(e,n,t){let s=e.all(`SELECT relative_path
787
836
  FROM documents
788
837
  WHERE 1 = 1
789
838
  ${e.pathExclusionsFor("documents")}
790
- ORDER BY relative_path`),s=new Set;for(let o of i)if(!(e.isIgnored(o.relative_path)||o.relative_path===t))for(let a of me(e,o.relative_path))a.sourcePath===n&&s.add(o.relative_path);return s.size}function Km(e,n){let t=A(e,n);return t.find(i=>ne(i.symbol)==="method")??t[0]??null}function Vm(e){let n=new Set,t=[];for(let i of e){let s=`${i.barrelFile}|${i.symbol}|${i.originalFile}`;n.has(s)||(n.add(s),t.push(i))}return t}function To(e,n={}){let{scope:t,minLoc:i=1,limit:s}=n,o=new Map;for(let r of V(e,{scope:t})){if(!r.isFunctionLike||e.isIgnored(r.relativePath))continue;let l=r.endLine-r.startLine+1;if(l<i)continue;let c=Qm(e,r);if(!c)continue;let m={symbol:r.symbol,shortName:_(r.symbol),file:r.relativePath,startLine:r.startLine,endLine:r.endLine,loc:l},u=o.get(c);u?u.push(m):o.set(c,[m])}let a=[];for(let[r,l]of o)l.length<2||a.push({signature:r,functions:l});return a.sort((r,l)=>{let c=l.functions.length-r.functions.length;if(c!==0)return c;let m=r.functions.reduce((d,f)=>d+f.loc,0);return l.functions.reduce((d,f)=>d+f.loc,0)-m}),s?a.slice(0,s):a}function Qm(e,n){let t=Xm(n.documentation),i=t?tu(t):null;return i||nu(Zm(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)}function Xm(e){if(!e||!e.includes("|"))return null;let n=e.slice(e.indexOf("|")+1).replace(/\n/g," ").trim();return n.length>0?n:null}function Zm(e,n,t,i,s){let o=P(e,n);if(!o)return null;let a=o.split(/\r?\n/),r=iu(a,t,i,s);for(let l of r){let c=Math.min(a.length-1,Math.max(l,l+4)),m="";for(let u=l;u<=c;u+=1){let d=a[u]?.trim();if(d&&(m=m?`${m} ${d}`:d,eu(m)))return m}if(m&&m.includes("("))return m}return null}function eu(e){let n=e.replace(/\s+/g," ").trim();return!n.includes("(")||su(n)>0?!1:/[;{]$/.test(n)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(n)||/\)\s*As\s+.+$/i.test(n)}function tu(e){if(!e||!e.trim())return null;let n=e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim(),t=n.indexOf("(");return t===-1||(n=n.slice(t),n=n.replace(/\s+/g,"").toLowerCase(),n.length<3)?null:n}function nu(e,n){if(!e||!e.trim())return null;let t=e.replace(/\s+/g," ").trim(),i=t.indexOf("(");if(i===-1)return null;let s=t.slice(0,i),a=new RegExp(`\\b${Ao(n)}\\b`,"i").exec(s);a&&typeof a.index=="number"&&(s=s.slice(0,a.index)),s=s.replace(/\b(public|private|protected|internal|final|static|abstract|sealed|virtual|override|async|suspend|inline|constexpr|consteval|constinit|const|pub|fn|function|def|sub|friend|shared|readonly|new|open|partial|export)\b/gi," ").replace(/\s+/g," ").trim();let r=t.slice(i).replace(/\s*\{[\s\S]*$/,"").replace(/\s*=>[\s\S]*$/,"").replace(/\)\s*=\s*[\s\S]*$/,")").replace(/\s+throws\s+[^={]+$/i,"").replace(/\s+where\s+.+$/i,"").replace(/\s+/g," ").trim();if(!r.startsWith("("))return null;let l=`${s?`${s} `:""}${r}`.replace(/\s+/g,"").toLowerCase();return l.length>=3?l:null}function iu(e,n,t,i){let s=Ao(i),o=new RegExp(`\\b${s}\\b\\s*\\(`,"i"),a=new RegExp(`\\bdef\\s+${s}\\b`,"i"),r=[],l=new Set,c=Math.max(0,Math.min(n,e.length-1)),m=Math.max(c,Math.min(e.length-1,Math.max(t,n+4)));for(let u=c;u<=m;u+=1){let d=e[u]??"";(o.test(d)||a.test(d))&&!l.has(u)&&(l.add(u),r.push(u))}for(let u=0;u<e.length;u+=1){let d=e[u]??"";(o.test(d)||a.test(d))&&!l.has(u)&&(l.add(u),r.push(u))}return r}function su(e){let n=0;for(let t of e)t==="("&&(n+=1),t===")"&&(n-=1);return n}function Ao(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}import{existsSync as Bn,mkdirSync as ou,symlinkSync as ru,readlinkSync as au,unlinkSync as lu}from"fs";import{join as on,dirname as jo,resolve as Wn}from"path";import{homedir as Bo,platform as cu}from"os";import{fileURLToPath as mu}from"url";var uu=cu()==="win32",Hn=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function Wo(e={}){let n=e.quiet?()=>{}:console.log,t=mu(import.meta.url),i=Wn(jo(t),"..","skills"),s=[on(Bo(),".claude","skills"),on(Bo(),".codex","skills")],o={installed:[],skipped:[],alreadyLinked:[]};for(let a of s){let r=jo(a);if(!Bn(r))continue;ou(a,{recursive:!0});let l=a.includes(".codex")?"Codex":"Claude";for(let c of Hn){let m=on(i,c),u=on(a,c);if(!Bn(m)){o.skipped.push(`${l}/${c}`);continue}if(Bn(u)){try{let d=au(u);if(Wn(d)===Wn(m)){o.alreadyLinked.push(`${l}/${c}`),n(` ok: ${c} \u2192 ${l} (already linked)`);continue}}catch{o.skipped.push(`${l}/${c}`),n(` skip: ${c} \u2192 ${l} (exists, not a symlink)`);continue}lu(u)}ru(m,u,uu?"junction":"dir"),o.installed.push(`${l}/${c}`),n(` done: ${c} \u2192 ${l}`)}}return o}function Ne(e){return e+1}function ye(e,n){return`${Ne(e)}-${Ne(n)}`}function be(e,n,t){return`${e}:${ye(n,t)}`}var N={empty(e){console.log(e)},list(e,n){for(let t of e)console.log(n(t))},groupedByFile(e,n,t=i=>i.relativePath){let i="";for(let s of e){let o=t(s);o!==i&&(i&&console.log(""),console.log(o),i=o),console.log(n(s))}},sectionedReport(e){let n=!0;for(let t of e)if(!(t.skipIfEmpty&&t.rows.length===0)){n||console.log(""),n=!1,t.title!==void 0&&console.log(`\u2550\u2550\u2550 ${t.title} \u2550\u2550\u2550`),t.explanation!==void 0&&console.log(t.explanation);for(let i of t.rows)console.log(i)}},table(e,n,t){console.log(` ${e.join(" ")}`);let i=t??e.map(s=>s.length);console.log(` ${i.map(s=>"\u2500".repeat(s)).join(" ")}`);for(let s of n)console.log(s)}};var gu=du(import.meta.url),{version:hu}=gu("../package.json");function Qe(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function Jo(e){let n=$e(e),t=ke(e,n);return process.env.SCIP_QUERY_INDEX_DB??(rn(t.dbPath)?t.dbPath:pu(e,"index.db"))}function yu(){let e=Qe(),n=$e(e),t=ke(e,n),i=Jo(e);rn(i)||(console.error("error: No index.db found. Run: scip-query reindex"),process.exit(1));let s={dbPath:i,indexPath:process.env.SCIP_QUERY_INDEX_SCIP??t.indexPath,projectRoot:e},o=gt(e);return new ft(s,o)}function E(e){let n=yu();try{e(n)}finally{n.close()}}var v={stats:Ct,files:vi,symbols:qi,methods:zi,refs:vs,trace:Es,deps:Ls,rdeps:Rs,system:Ds,surface:ws,dead:Ut,hotspots:js,imports:Ws,importedBy:Hs,unusedImports:Js,outline:qs,members:zs,fanIn:Gs,fanOut:Ys,topFanIn:Ks,topFanOut:Vs,coupling:Qs,topCoupling:Xs,cycles:qt,bottlenecks:Zs,isolated:zt,byKind:eo,kindCounts:to,deepChains:so,hierarchy:oo,callGraph:ro,similar:co,similarAll:Gt,similarFiles:ho,similarChains:bo,extractCandidates:Kt,affected:_o,changeSurface:xo,diffImpact:Io,drift:Xt,wrapperCandidates:en,passthroughCandidates:tn,staleAbstractions:nn,complexityHotspots:sn,health:Lo,convergence:Ro,code:Oo,complexity:$o,dataflow:ko,slice:Po,redundantReexports:Fo,similarSignatures:To};C.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(hu);C.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",Su,[]).option("--pnpm-workspaces","Enable pnpm workspace support (TypeScript)").action(async e=>{let n=Qe(),t=$e(n),i=ke(n,t);try{let s=await Ii({projectRoot:n,languages:e.language.length>0?e.language:t.languages,outputScip:i.indexPath,outputDb:i.dbPath,pnpmWorkspaces:e.pnpmWorkspaces||t.indexer?.typescript?.pnpmWorkspaces});console.log(`Indexed ${s.languages.join(", ")} in ${(s.durationMs/1e3).toFixed(1)}s`)}catch(s){console.error(`error: ${s instanceof Error?s.message:s}`),process.exit(1)}});C.command("stats").description("Show index statistics").action(()=>E(e=>{let n=v.stats(e);console.log(`Documents: ${n.documents}`),console.log(`Symbols: ${n.symbols}`),console.log(`Definitions: ${n.definitions}`),console.log(`References: ${n.references}`),console.log(`Index size: ${Jn(n.indexSizeBytes)}`),n.lastBuilt&&console.log(`Last built: ${n.lastBuilt.toISOString().replace("T"," ").slice(0,19)}`)}));C.command("files <pattern>").description("Find files matching a pattern").action(e=>E(n=>{N.list(v.files(n,e),t=>t.relativePath)}));C.command("symbols <file>").description("List symbols defined in a file (with line ranges + signatures)").action(e=>E(n=>{N.list(v.symbols(n,e),t=>{let i=t.signature?` \u2014 ${t.signature}`:"";return` ${ye(t.startLine,t.endLine)} ${t.shortName}${i}`})}));C.command("methods <className>").description("List methods of a class (with line ranges)").action(e=>E(n=>{N.list(v.methods(n,e),t=>` ${ye(t.startLine,t.endLine)} ${t.name}`)}));C.command("refs <symbol>").description("Find all files referencing a symbol").action(e=>E(n=>{N.groupedByFile(v.refs(n,e),t=>` line ${Ne(t.line)}`)}));C.command("trace <symbol>").description("Trace a symbol: definition + all references").action(e=>E(n=>{let t=v.trace(n,e),i=[];for(let a of t.definitions){let r=a.signature?` \u2014 ${a.signature}`:"";i.push(` ${be(a.relativePath,a.startLine,a.endLine)}${r}`),a.source&&i.push(a.source.split(`
791
- `).map((l,c)=>` ${Ne(a.startLine+c)} ${l}`).join(`
792
- `))}let s=[],o="";for(let a of t.referencedBy)a.relativePath!==o&&(o&&s.push(""),s.push(` ${a.relativePath}`),o=a.relativePath),s.push(` line ${Ne(a.line)} in ${a.enclosingShort}`);N.sectionedReport([{title:"DEFINITION",rows:i},{title:"REFERENCED BY",rows:s}])}));C.command("deps <file>").description("Files this file depends on (internal)").action(e=>E(n=>{N.list(v.deps(n,e),t=>t.relativePath)}));C.command("rdeps <file>").description("Files that depend on this file/module").action(e=>E(n=>{N.list(v.rdeps(n,e),t=>t.relativePath)}));C.command("system <module>").description("Full module map: files, symbols, deps in/out").action(e=>E(n=>{let t=v.system(n,e);N.sectionedReport([{title:"FILES",rows:t.files},{title:"EXPORTED SYMBOLS",rows:t.symbols.map(i=>` ${ye(i.startLine,i.endLine)} ${i.shortName}`)},{title:"DEPENDS ON (internal)",rows:t.dependsOn.map(i=>` ${i}`)},{title:"DEPENDED ON BY",rows:t.dependedOnBy.map(i=>` ${i}`)}])}));C.command("surface <module>").description("What symbols consumers actually use from this module").action(e=>E(n=>{N.list(v.surface(n,e),t=>` ${t.consumer} \u2192 ${t.shortName}`)}));C.command("dead [scope]").description("Find dead code and file-internal symbols (no cross-file consumers)").option("--min-loc <n>","Only show symbols >= N lines",w,1).option("--include-tests","Include test files").option("--skip-barrels","Ignore refs from barrel re-export files").option("--include-members","Include class members").option("--only-dead","Show only [dead code] symbols (skip [file-internal only])").option("--only-internal","Show only [file-internal only] symbols (skip [dead code])").action((e,n)=>E(t=>{let i={scope:e||void 0,minLoc:n.minLoc,includeTests:n.includeTests,skipBarrels:n.skipBarrels,includeMembers:n.includeMembers},s=v.dead(t,i);if(s.symbols.length===0)return N.empty("No dead code found.");let o=s.symbols.filter(d=>d.kind==="dead-code"),a=s.symbols.filter(d=>d.kind!=="dead-code"),r=!n.onlyInternal,l=!n.onlyDead,c=(d,f,p,g)=>{console.log(`\u2550\u2550\u2550 ${f} (${d.length}, ${g} LOC) \u2550\u2550\u2550`),console.log(p),console.log("");let y=new Map;for(let x of d){let S=y.get(x.relativePath)??[];S.push(x),y.set(x.relativePath,S)}let h=[...y.entries()].map(([x,S])=>({file:x,bucket:S,totalLoc:S.reduce((I,L)=>I+L.loc,0)})).sort((x,S)=>S.totalLoc-x.totalLoc||x.file.localeCompare(S.file)),b=!0;for(let{file:x,bucket:S}of h){b||console.log(""),b=!1,console.log(` ${x}`),S.sort((I,L)=>I.startLine-L.startLine);for(let I of S)console.log(` ${ye(I.startLine,I.endLine)} (${I.loc} LOC) ${I.shortName}`)}},m=o.reduce((d,f)=>d+f.loc,0),u=a.reduce((d,f)=>d+f.loc,0);r&&o.length>0&&c(o,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
839
+ ORDER BY relative_path`),i=new Set;for(let o of s)if(!(e.isIgnored(o.relative_path)||o.relative_path===t))for(let a of de(e,o.relative_path))a.sourcePath===n&&i.add(o.relative_path);return i.size}function ed(e,n){let t=A(e,n);return t.find(s=>ie(s.symbol)==="method")??t[0]??null}function td(e){let n=new Set,t=[];for(let s of e){let i=`${s.barrelFile}|${s.symbol}|${s.originalFile}`;n.has(i)||(n.add(i),t.push(s))}return t}function lr(e,n={}){let{scope:t,minLoc:s=1,limit:i}=n,o=new Map;for(let r of Z(e,{scope:t})){if(!r.isFunctionLike||e.isIgnored(r.relativePath))continue;let l=r.endLine-r.startLine+1;if(l<s)continue;let c=nd(e,r);if(!c)continue;let m={symbol:r.symbol,shortName:I(r.symbol),file:r.relativePath,startLine:r.startLine,endLine:r.endLine,loc:l},u=o.get(c);u?u.push(m):o.set(c,[m])}let a=[];for(let[r,l]of o)l.length<2||a.push({signature:r,functions:l});return a.sort((r,l)=>{let c=l.functions.length-r.functions.length;if(c!==0)return c;let m=r.functions.reduce((d,g)=>d+g.loc,0);return l.functions.reduce((d,g)=>d+g.loc,0)-m}),i?a.slice(0,i):a}function nd(e,n){let t=sd(n.documentation),s=t?rd(t):null;return s||ad(id(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)}function sd(e){if(!e||!e.includes("|"))return null;let n=e.slice(e.indexOf("|")+1).replace(/\n/g," ").trim();return n.length>0?n:null}function id(e,n,t,s,i){let o=M(e,n);if(!o)return null;let a=o.split(/\r?\n/),r=ld(a,t,s,i);for(let l of r){let c=Math.min(a.length-1,Math.max(l,l+4)),m="";for(let u=l;u<=c;u+=1){let d=a[u]?.trim();if(d&&(m=m?`${m} ${d}`:d,od(m)))return m}if(m&&m.includes("("))return m}return null}function od(e){let n=e.replace(/\s+/g," ").trim();return!n.includes("(")||cd(n)>0?!1:/[;{]$/.test(n)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(n)||/\)\s*As\s+.+$/i.test(n)}function rd(e){if(!e||!e.trim())return null;let n=e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim(),t=n.indexOf("(");return t===-1||(n=n.slice(t),n=n.replace(/\s+/g,"").toLowerCase(),n.length<3)?null:n}function ad(e,n){if(!e||!e.trim())return null;let t=e.replace(/\s+/g," ").trim(),s=t.indexOf("(");if(s===-1)return null;let i=t.slice(0,s),a=new RegExp(`\\b${cr(n)}\\b`,"i").exec(i);a&&typeof a.index=="number"&&(i=i.slice(0,a.index)),i=i.replace(/\b(public|private|protected|internal|final|static|abstract|sealed|virtual|override|async|suspend|inline|constexpr|consteval|constinit|const|pub|fn|function|def|sub|friend|shared|readonly|new|open|partial|export)\b/gi," ").replace(/\s+/g," ").trim();let r=t.slice(s).replace(/\s*\{[\s\S]*$/,"").replace(/\s*=>[\s\S]*$/,"").replace(/\)\s*=\s*[\s\S]*$/,")").replace(/\s+throws\s+[^={]+$/i,"").replace(/\s+where\s+.+$/i,"").replace(/\s+/g," ").trim();if(!r.startsWith("("))return null;let l=`${i?`${i} `:""}${r}`.replace(/\s+/g,"").toLowerCase();return l.length>=3?l:null}function ld(e,n,t,s){let i=cr(s),o=new RegExp(`\\b${i}\\b\\s*\\(`,"i"),a=new RegExp(`\\bdef\\s+${i}\\b`,"i"),r=[],l=new Set,c=Math.max(0,Math.min(n,e.length-1)),m=Math.max(c,Math.min(e.length-1,Math.max(t,n+4)));for(let u=c;u<=m;u+=1){let d=e[u]??"";(o.test(d)||a.test(d))&&!l.has(u)&&(l.add(u),r.push(u))}for(let u=0;u<e.length;u+=1){let d=e[u]??"";(o.test(d)||a.test(d))&&!l.has(u)&&(l.add(u),r.push(u))}return r}function cd(e){let n=0;for(let t of e)t==="("&&(n+=1),t===")"&&(n-=1);return n}function cr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}import{existsSync as es,mkdirSync as ud,symlinkSync as md,readlinkSync as dd,unlinkSync as pd}from"fs";import{join as gn,dirname as ur,resolve as ts}from"path";import{homedir as mr,platform as fd}from"os";import{fileURLToPath as gd}from"url";var hd=fd()==="win32",ns=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function dr(e={}){let n=e.quiet?()=>{}:console.log,t=gd(import.meta.url),s=ts(ur(t),"..","skills"),i=[gn(mr(),".claude","skills"),gn(mr(),".codex","skills")],o={installed:[],skipped:[],alreadyLinked:[]};for(let a of i){let r=ur(a);if(!es(r))continue;ud(a,{recursive:!0});let l=a.includes(".codex")?"Codex":"Claude";for(let c of ns){let m=gn(s,c),u=gn(a,c);if(!es(m)){o.skipped.push(`${l}/${c}`);continue}if(es(u)){try{let d=dd(u);if(ts(d)===ts(m)){o.alreadyLinked.push(`${l}/${c}`),n(` ok: ${c} \u2192 ${l} (already linked)`);continue}}catch{o.skipped.push(`${l}/${c}`),n(` skip: ${c} \u2192 ${l} (exists, not a symlink)`);continue}pd(u)}md(m,u,hd?"junction":"dir"),o.installed.push(`${l}/${c}`),n(` done: ${c} \u2192 ${l}`)}}return o}function Ee(e){return e+1}function be(e,n){return`${Ee(e)}-${Ee(n)}`}function Se(e,n,t){return`${e}:${be(n,t)}`}var N={empty(e){console.log(e)},list(e,n){for(let t of e)console.log(n(t))},groupedByFile(e,n,t=s=>s.relativePath){let s="";for(let i of e){let o=t(i);o!==s&&(s&&console.log(""),console.log(o),s=o),console.log(n(i))}},sectionedReport(e){let n=!0;for(let t of e)if(!(t.skipIfEmpty&&t.rows.length===0)){n||console.log(""),n=!1,t.title!==void 0&&console.log(`\u2550\u2550\u2550 ${t.title} \u2550\u2550\u2550`),t.explanation!==void 0&&console.log(t.explanation);for(let s of t.rows)console.log(s)}},table(e,n,t){console.log(` ${e.join(" ")}`);let s=t??e.map(i=>i.length);console.log(` ${s.map(i=>"\u2500".repeat(i)).join(" ")}`);for(let i of n)console.log(i)}};var _d=yd(import.meta.url),{version:xd}=_d("../package.json");function Me(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function yn(e){let n=Te(e),t=Ae(e,n);return process.env.SCIP_QUERY_INDEX_DB??(hn(t.dbPath)?t.dbPath:bd(e,"index.db"))}function Id(){let e=Me(),n=Te(e),t=Ae(e,n),s=yn(e);hn(s)||(console.error("error: No index.db found. Run: scip-query reindex"),process.exit(1));let i={dbPath:s,indexPath:process.env.SCIP_QUERY_INDEX_SCIP??t.indexPath,projectRoot:e,entryRoots:n.entryRoots},o=Ue(e);return new Lt(i,o)}function E(e){let n=Id();try{e(n)}finally{n.close()}}var C={stats:Bt,files:qs,symbols:di,methods:pi,refs:Qi,trace:Xi,deps:Zi,rdeps:eo,system:to,surface:no,dead:tn,hotspots:lo,imports:uo,importedBy:mo,unusedImports:po,outline:go,members:ho,fanIn:yo,fanOut:bo,topFanIn:So,topFanOut:_o,coupling:xo,topCoupling:Io,cycles:nn,bottlenecks:Co,isolated:sn,byKind:Eo,kindCounts:Ro,deepChains:Do,hierarchy:ko,callGraph:Oo,similar:Mo,similarAll:on,similarFiles:Wo,similarChains:Jo,extractCandidates:an,affected:qo,changeSurface:zo,diffImpact:Vo,drift:cn,wrapperCandidates:mn,passthroughCandidates:dn,staleAbstractions:pn,complexityHotspots:fn,health:Xo,convergence:Zo,code:nr,complexity:sr,dataflow:ir,slice:or,redundantReexports:ar,similarSignatures:lr};v.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(xd);v.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",vd,[]).option("--pnpm-workspaces","Enable pnpm workspace support (TypeScript)").action(async e=>{let n=Me(),t=Te(n),s=Ae(n,t);try{let i=await Hs({projectRoot:n,languages:e.language.length>0?e.language:t.languages,outputScip:s.indexPath,outputDb:s.dbPath,pnpmWorkspaces:e.pnpmWorkspaces||t.indexer?.typescript?.pnpmWorkspaces});console.log(`Indexed ${i.languages.join(", ")} in ${(i.durationMs/1e3).toFixed(1)}s`)}catch(i){console.error(`error: ${i instanceof Error?i.message:i}`),process.exit(1)}});v.command("augment-sources").description("Add source files skipped by upstream SCIP indexers to the SQLite documents table").action(()=>{let e=Me(),n=yn(e);try{let t=Be({projectRoot:e,dbPath:n,onStatus:s=>console.log(s)});console.log(`Scanned ${t.scanned} auxiliary source files; inserted ${t.inserted}.`)}catch(t){console.error(`error: ${t instanceof Error?t.message:t}`),process.exit(1)}});v.command("augment-vue").description("Add compiler-resolved Vue SFC references to the SQLite index using Volar").option("--project <tsconfig>","Vue tsconfig path","frontend/tsconfig.scip.json").action(e=>{let n=Me(),t=yn(n);try{let s=On({projectRoot:n,dbPath:t,tsconfig:e.project,onStatus:i=>console.log(i)});console.log(`Vue files: ${s.vueFiles}; resolved references: ${s.resolvedReferences}; inserted mentions: ${s.insertedMentions}.`)}catch(s){console.error(`error: ${s instanceof Error?s.message:s}`),process.exit(1)}});v.command("stats").description("Show index statistics").action(()=>E(e=>{let n=C.stats(e);console.log(`Documents: ${n.documents}`),console.log(`Symbols: ${n.symbols}`),console.log(`Definitions: ${n.definitions}`),console.log(`References: ${n.references}`),console.log(`Index size: ${ss(n.indexSizeBytes)}`),n.lastBuilt&&console.log(`Last built: ${n.lastBuilt.toISOString().replace("T"," ").slice(0,19)}`)}));v.command("files <pattern>").description("Find files matching a pattern").action(e=>E(n=>{N.list(C.files(n,e),t=>t.relativePath)}));v.command("symbols <file>").description("List symbols defined in a file (with line ranges + signatures)").action(e=>E(n=>{N.list(C.symbols(n,e),t=>{let s=t.signature?` \u2014 ${t.signature}`:"";return` ${be(t.startLine,t.endLine)} ${t.shortName}${s}`})}));v.command("methods <className>").description("List methods of a class (with line ranges)").action(e=>E(n=>{N.list(C.methods(n,e),t=>` ${be(t.startLine,t.endLine)} ${t.name}`)}));v.command("refs <symbol>").description("Find all files referencing a symbol").action(e=>E(n=>{N.groupedByFile(C.refs(n,e),t=>` line ${Ee(t.line)}`)}));v.command("trace <symbol>").description("Trace a symbol: definition + all references").action(e=>E(n=>{let t=C.trace(n,e),s=[];for(let a of t.definitions){let r=a.signature?` \u2014 ${a.signature}`:"";s.push(` ${Se(a.relativePath,a.startLine,a.endLine)}${r}`),a.source&&s.push(a.source.split(`
840
+ `).map((l,c)=>` ${Ee(a.startLine+c)} ${l}`).join(`
841
+ `))}let i=[],o="";for(let a of t.referencedBy)a.relativePath!==o&&(o&&i.push(""),i.push(` ${a.relativePath}`),o=a.relativePath),i.push(` line ${Ee(a.line)} in ${a.enclosingShort}`);N.sectionedReport([{title:"DEFINITION",rows:s},{title:"REFERENCED BY",rows:i}])}));v.command("deps <file>").description("Files this file depends on (internal)").action(e=>E(n=>{N.list(C.deps(n,e),t=>t.relativePath)}));v.command("rdeps <file>").description("Files that depend on this file/module").action(e=>E(n=>{N.list(C.rdeps(n,e),t=>t.relativePath)}));v.command("system <module>").description("Full module map: files, symbols, deps in/out").action(e=>E(n=>{let t=C.system(n,e);N.sectionedReport([{title:"FILES",rows:t.files},{title:"EXPORTED SYMBOLS",rows:t.symbols.map(s=>` ${be(s.startLine,s.endLine)} ${s.shortName}`)},{title:"DEPENDS ON (internal)",rows:t.dependsOn.map(s=>` ${s}`)},{title:"DEPENDED ON BY",rows:t.dependedOnBy.map(s=>` ${s}`)}])}));v.command("surface <module>").description("What symbols consumers actually use from this module").action(e=>E(n=>{N.list(C.surface(n,e),t=>` ${t.consumer} \u2192 ${t.shortName}`)}));v.command("dead [scope]").description("Find dead code and file-internal symbols (no cross-file consumers)").option("--min-loc <n>","Only show symbols >= N lines",D,1).option("--include-tests","Include test files").option("--skip-barrels","Ignore refs from barrel re-export files").option("--include-members","Include class members").option("--only-dead","Show only [dead code] symbols (skip [file-internal only])").option("--only-internal","Show only [file-internal only] symbols (skip [dead code])").action((e,n)=>E(t=>{let s={scope:e||void 0,minLoc:n.minLoc,includeTests:n.includeTests,skipBarrels:n.skipBarrels,includeMembers:n.includeMembers},i=C.dead(t,s);if(i.symbols.length===0)return N.empty("No dead code found.");let o=i.symbols.filter(d=>d.kind==="dead-code"),a=i.symbols.filter(d=>d.kind!=="dead-code"),r=!n.onlyInternal,l=!n.onlyDead,c=(d,g,p,f)=>{console.log(`\u2550\u2550\u2550 ${g} (${d.length}, ${f} LOC) \u2550\u2550\u2550`),console.log(p),console.log("");let y=new Map;for(let _ of d){let S=y.get(_.relativePath)??[];S.push(_),y.set(_.relativePath,S)}let h=[...y.entries()].map(([_,S])=>({file:_,bucket:S,totalLoc:S.reduce((x,L)=>x+L.loc,0)})).sort((_,S)=>S.totalLoc-_.totalLoc||_.file.localeCompare(S.file)),b=!0;for(let{file:_,bucket:S}of h){b||console.log(""),b=!1,console.log(` ${_}`),S.sort((x,L)=>x.startLine-L.startLine);for(let x of S)console.log(` ${be(x.startLine,x.endLine)} (${x.loc} LOC) ${x.shortName}`)}},m=o.reduce((d,g)=>d+g.loc,0),u=a.reduce((d,g)=>d+g.loc,0);r&&o.length>0&&c(o,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
793
842
  Safe to delete.`,m),l&&a.length>0&&(r&&o.length>0&&console.log(""),c(a,"FILE-INTERNAL ONLY",` Used only within the same file (no cross-file callers). Could be a
794
843
  single-use helper, an abstraction-in-progress, or a callback registered
795
844
  through a framework path that static analysis cannot trace (signal
796
845
  handlers, event listeners, dependency injection). NOT necessarily dead \u2014
797
846
  review case by case.`,u)),console.log(`
798
- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`),console.log(`Total: ${s.totalCount} symbols \u2014 ${s.deadCodeCount} dead code (${m} LOC) + ${s.fileInternalCount} file-internal (${u} LOC)`)}));C.command("hotspots").description("Most-referenced symbols in the codebase (choke points)").option("-n, --limit <n>","Number of results",w,30).option("-s, --scope <path>","Limit to files matching path").action(e=>E(n=>{let t=v.hotspots(n,{limit:e.limit,scope:e.scope});N.table(["refs","files","symbol"],t.map(i=>` ${String(i.refCount).padStart(4)} ${String(i.fileCount).padStart(5)} ${i.shortName}`))}));C.command("imports <file>").description("What symbols does this file import?").action(e=>E(n=>{let t=v.imports(n,e);if(t.length===0){N.empty("No imports found (indexer may not emit role=2 for this language).");return}N.list(t,i=>` ${i.shortName} \u2190 ${i.fromFile}`)}));C.command("imported-by <symbol>").description("Which files import this symbol?").action(e=>E(n=>{N.list(v.importedBy(n,e),t=>` ${t.fromFile}`)}));C.command("unused-imports <file>").description("Find imports not referenced in the same file").action(e=>E(n=>{let t=v.unusedImports(n,e);if(t.length===0)return N.empty("No unused imports found.");N.list(t,i=>` ${i.shortName} in ${i.importedIn}`),console.log(`
799
- ${t.length} unused import(s)`)}));C.command("outline <file>").description("Tree view of symbols in a file (using nesting hierarchy)").action(e=>E(n=>{let t=v.outline(n,e);function i(s,o){for(let a of s){let r=" ".repeat(o);console.log(`${r}${ye(a.startLine,a.endLine)} ${a.shortName}`),i(a.children,o+1)}}i(t,0)}));C.command("members <symbol>").description("All children of a symbol (methods, fields, nested types)").action(e=>E(n=>{N.list(v.members(n,e),t=>` ${ye(t.startLine,t.endLine)} [${t.kind}] ${t.shortName}`)}));C.command("fan-in [symbol]").description("How many files reference a symbol (or top fan-in across codebase)").option("-n, --limit <n>","Number of results for top mode",w,30).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{if(e){let i=v.fanIn(t,e);if(i.length===0)return N.empty(`No fan-in for ${e}.`);N.list(i,s=>` ${String(s.count).padStart(4)} files ${s.name}`)}else N.table(["files","symbol"],v.topFanIn(t,{limit:n.limit,scope:n.scope}).map(i=>` ${String(i.count).padStart(5)} ${i.name}`))}));C.command("fan-out [file]").description("How many external symbols a file uses (or top fan-out across codebase)").option("-n, --limit <n>","Number of results for top mode",w,30).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{if(e){let i=v.fanOut(t,e);if(i.length===0)return N.empty(`No fan-out for ${e}.`);N.list(i,s=>` ${String(s.count).padStart(4)} symbols ${s.name}`)}else N.table(["symbols","file"],v.topFanOut(t,{limit:n.limit,scope:n.scope}).map(i=>` ${String(i.count).padStart(7)} ${i.name}`))}));C.command("coupling [file1] [file2]").description("Coupling between two files, or top coupled pairs in codebase").option("-n, --limit <n>","Number of results for top mode",w,20).option("-s, --scope <path>","Limit to files matching path").action((e,n,t)=>E(i=>{if(e&&n){let s=v.coupling(i,e,n);console.log(`${s.file1} \u2194 ${s.file2}: ${s.sharedSymbols} shared symbols`)}else N.table(["shared","file1 \u2192 file2"],v.topCoupling(i,{limit:t.limit,scope:t.scope}).map(s=>` ${String(s.sharedSymbols).padStart(6)} ${s.file1} \u2192 ${s.file2}`))}));C.command("cycles").description("Detect circular dependency chains between files").option("-s, --scope <path>","Limit to files matching path").option("--max-depth <n>","Maximum cycle depth",w,10).action(e=>E(n=>{let t=v.cycles(n,{scope:e.scope,maxDepth:e.maxDepth});if(t.length===0)return N.empty("No circular dependencies found.");let i=t.filter(o=>o.kind==="real"),s=t.filter(o=>o.kind==="module-hierarchy");for(let o=0;o<i.length;o++){console.log(`
800
- Cycle ${o+1} (${i[o].path.length-1} files):`);for(let a=0;a<i[o].path.length;a++){let r=a<i[o].path.length-1?" \u2192":" (cycle)";console.log(` ${i[o].path[a]}${r}`)}}i.length===0?console.log("No real circular dependencies found."):console.log(`
801
- ${i.length} real cycle(s) found.`),s.length>0&&console.log(`(${s.length} module-hierarchy cycle(s) hidden \u2014 barrel files participating in normal parent/child re-export patterns. Pass --include-module-hierarchy to see them.)`)}));C.command("bottlenecks").description("Find coupling hubs: high fan-in AND high fan-out").option("-n, --limit <n>","Number of results",w,20).option("-s, --scope <path>","Limit to files matching path").option("--min-fan-in <n>","Minimum fan-in",w,2).option("--min-fan-out <n>","Minimum fan-out",w,2).action(e=>E(n=>{let t=v.bottlenecks(n,{limit:e.limit,scope:e.scope,minFanIn:e.minFanIn,minFanOut:e.minFanOut});if(t.length===0)return N.empty("No bottlenecks found.");N.table(["score","fan-in","fan-out","symbol"],t.map(i=>` ${String(i.score).padStart(5)} ${String(i.fanIn).padStart(6)} ${String(i.fanOut).padStart(7)} ${i.shortName}`))}));C.command("isolated").description("Find completely orphaned symbols (no references at all)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum lines of code",w,3).action(e=>E(n=>{let t=v.isolated(n,{scope:e.scope,minLoc:e.minLoc});if(t.length===0)return N.empty("No isolated symbols found.");N.groupedByFile(t,i=>` ${ye(i.startLine,i.endLine)} (${i.loc} LOC) ${i.shortName}`),console.log(`
802
- ${t.length} isolated symbol(s)`)}));C.command("by-kind <kind>").description("Find symbols by SCIP kind (class, interface, enum, function, etc.)").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",w,100).action((e,n)=>E(t=>{let i=v.byKind(t,e,{scope:n.scope,limit:n.limit});if(i.length===0)return N.empty(`No symbols found for kind "${e}". Use "kind-counts" to see available kinds.`);N.list(i,s=>` ${be(s.relativePath,s.startLine,s.endLine)} [${s.kindName}] ${s.shortName}`),console.log(`
803
- ${i.length} symbol(s)`)}));C.command("kind-counts").description("Histogram of symbol kinds in the codebase").option("-s, --scope <path>","Limit to files matching path").action(e=>E(n=>{let t=v.kindCounts(n,{scope:e.scope});N.table(["count","kind"],t.map(i=>` ${String(i.count).padStart(5)} ${i.kindName} (${i.kind})`))}));C.command("deep-chains").description("Find the longest transitive dependency chains").option("-n, --limit <n>","Number of chains to show",w,10).option("-s, --scope <path>","Limit to files matching path").option("--min-depth <n>","Minimum chain depth",w,3).action(e=>E(n=>{let t=v.deepChains(n,{limit:e.limit,scope:e.scope,minDepth:e.minDepth});if(t.length===0)return N.empty("No deep chains found.");for(let i=0;i<t.length;i++){console.log(`
804
- Chain ${i+1} (depth ${t[i].depth}):`);for(let s of t[i].chain)console.log(` \u2192 ${s}`)}}));C.command("hierarchy <symbol>").description("Show a symbol's ancestry chain (method \u2192 class \u2192 module)").action(e=>E(n=>{let t=v.hierarchy(n,e);if(t.length===0)return N.empty("Symbol not found.");N.list(t,i=>`${" ".repeat(i.depth)}${i.shortName}`)}));C.command("call-graph <symbol>").description("Show incoming callers and outgoing callees for a symbol").action(e=>E(n=>{let t=v.callGraph(n,e);if(!t)return N.empty("Symbol not found.");console.log(`Symbol: ${t.shortName}
805
- `),N.sectionedReport([{title:`CALLERS (${t.callers.length})`,rows:t.callers.map(i=>` ${i.file} ${i.shortName}`)},{title:`CALLEES (${t.callees.length})`,rows:t.callees.map(i=>` ${i.file} ${i.shortName}`)}])}));C.command("similar [symbol]").description("Find functions with similar callee fingerprints (consolidation candidates)").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.4).option("-n, --limit <n>","Number of results",w,20).option("-s, --scope <path>","Limit to files matching path").option("--min-callees <n>","Minimum callees to consider",w,4).option("--cross-file-only","Only show cross-file pairs (skip same-file matches)").action((e,n)=>E(t=>{if(e){let i=v.similar(t,e,{minSimilarity:n.minSimilarity,limit:n.limit});if(i.length===0)return N.empty("No similar symbols found.");N.list(i,s=>{let o=[`
806
- ${Math.round(s.similarity*100)}% similar:`,` A: ${s.shortNameA} (${s.fileA})`,` B: ${s.shortNameB} (${s.fileB})`,` Shared callees: ${s.sharedCallees.join(", ")}`];return s.uniqueToA.length&&o.push(` Only in A: ${s.uniqueToA.join(", ")}`),s.uniqueToB.length&&o.push(` Only in B: ${s.uniqueToB.join(", ")}`),o.join(`
807
- `)})}else{let i=v.similarAll(t,{minSimilarity:n.minSimilarity,limit:n.limit,scope:n.scope,minCallees:n.minCallees,crossFileOnly:n.crossFileOnly});if(i.length===0)return N.empty("No similar symbol pairs found.");N.list(i,s=>`
808
- ${Math.round(s.similarity*100)}% similar:
809
- A: ${s.shortNameA} (${s.fileA})
810
- B: ${s.shortNameB} (${s.fileB})
811
- Shared: ${s.sharedCallees.join(", ")}`),console.log(`
812
- ${i.length} similar pair(s) found.`)}}));C.command("similar-files [file]").description("Find files with similar dependency profiles").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",w,20).option("-s, --scope <path>","Limit to files matching path").option("--min-deps <n>","Minimum dependencies to consider",w).action((e,n)=>E(t=>{let i=v.similarFiles(t,{minSimilarity:n.minSimilarity,limit:n.limit,scope:n.scope,minDeps:n.minDeps,filePattern:e});if(i.length===0)return N.empty("No similar file pairs found.");N.list(i,s=>{let o=[`
813
- ${Math.round(s.similarity*100)}% similar:`,` ${s.fileA}`,` ${s.fileB}`,` Shared deps (${s.sharedDeps.length}): ${s.sharedDeps.join(", ")}`];return s.uniqueToA.length&&o.push(` Only in first: ${s.uniqueToA.join(", ")}`),s.uniqueToB.length&&o.push(` Only in second: ${s.uniqueToB.join(", ")}`),o.join(`
847
+ \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`),console.log(`Total: ${i.totalCount} symbols \u2014 ${i.deadCodeCount} dead code (${m} LOC) + ${i.fileInternalCount} file-internal (${u} LOC)`)}));v.command("hotspots").description("Most-referenced symbols in the codebase (choke points)").option("-n, --limit <n>","Number of results",D,30).option("-s, --scope <path>","Limit to files matching path").action(e=>E(n=>{let t=C.hotspots(n,{limit:e.limit,scope:e.scope});N.table(["refs","files","symbol"],t.map(s=>` ${String(s.refCount).padStart(4)} ${String(s.fileCount).padStart(5)} ${s.shortName}`))}));v.command("imports <file>").description("What symbols does this file import?").action(e=>E(n=>{let t=C.imports(n,e);if(t.length===0){N.empty("No imports found (indexer may not emit role=2 for this language).");return}N.list(t,s=>` ${s.shortName} \u2190 ${s.fromFile}`)}));v.command("imported-by <symbol>").description("Which files import this symbol?").action(e=>E(n=>{N.list(C.importedBy(n,e),t=>` ${t.fromFile}`)}));v.command("unused-imports <file>").description("Find imports not referenced in the same file").action(e=>E(n=>{let t=C.unusedImports(n,e);if(t.length===0)return N.empty("No unused imports found.");N.list(t,s=>` ${s.shortName} in ${s.importedIn}`),console.log(`
848
+ ${t.length} unused import(s)`)}));v.command("outline <file>").description("Tree view of symbols in a file (using nesting hierarchy)").action(e=>E(n=>{let t=C.outline(n,e);function s(i,o){for(let a of i){let r=" ".repeat(o);console.log(`${r}${be(a.startLine,a.endLine)} ${a.shortName}`),s(a.children,o+1)}}s(t,0)}));v.command("members <symbol>").description("All children of a symbol (methods, fields, nested types)").action(e=>E(n=>{N.list(C.members(n,e),t=>` ${be(t.startLine,t.endLine)} [${t.kind}] ${t.shortName}`)}));v.command("fan-in [symbol]").description("How many files reference a symbol (or top fan-in across codebase)").option("-n, --limit <n>","Number of results for top mode",D,30).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{if(e){let s=C.fanIn(t,e);if(s.length===0)return N.empty(`No fan-in for ${e}.`);N.list(s,i=>` ${String(i.count).padStart(4)} files ${i.name}`)}else N.table(["files","symbol"],C.topFanIn(t,{limit:n.limit,scope:n.scope}).map(s=>` ${String(s.count).padStart(5)} ${s.name}`))}));v.command("fan-out [file]").description("How many external symbols a file uses (or top fan-out across codebase)").option("-n, --limit <n>","Number of results for top mode",D,30).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{if(e){let s=C.fanOut(t,e);if(s.length===0)return N.empty(`No fan-out for ${e}.`);N.list(s,i=>` ${String(i.count).padStart(4)} symbols ${i.name}`)}else N.table(["symbols","file"],C.topFanOut(t,{limit:n.limit,scope:n.scope}).map(s=>` ${String(s.count).padStart(7)} ${s.name}`))}));v.command("coupling [file1] [file2]").description("Coupling between two files, or top coupled pairs in codebase").option("-n, --limit <n>","Number of results for top mode",D,20).option("-s, --scope <path>","Limit to files matching path").action((e,n,t)=>E(s=>{if(e&&n){let i=C.coupling(s,e,n);console.log(`${i.file1} \u2194 ${i.file2}: ${i.sharedSymbols} shared symbols`)}else N.table(["shared","file1 \u2192 file2"],C.topCoupling(s,{limit:t.limit,scope:t.scope}).map(i=>` ${String(i.sharedSymbols).padStart(6)} ${i.file1} \u2192 ${i.file2}`))}));v.command("cycles").description("Detect circular dependency chains between files").option("-s, --scope <path>","Limit to files matching path").option("--max-depth <n>","Maximum cycle depth",D,10).action(e=>E(n=>{let t=C.cycles(n,{scope:e.scope,maxDepth:e.maxDepth});if(t.length===0)return N.empty("No circular dependencies found.");let s=t.filter(o=>o.kind==="real"),i=t.filter(o=>o.kind==="module-hierarchy");for(let o=0;o<s.length;o++){console.log(`
849
+ Cycle ${o+1} (${s[o].path.length-1} files):`);for(let a=0;a<s[o].path.length;a++){let r=a<s[o].path.length-1?" \u2192":" (cycle)";console.log(` ${s[o].path[a]}${r}`)}}s.length===0?console.log("No real circular dependencies found."):console.log(`
850
+ ${s.length} real cycle(s) found.`),i.length>0&&console.log(`(${i.length} module-hierarchy cycle(s) hidden \u2014 barrel files participating in normal parent/child re-export patterns. Pass --include-module-hierarchy to see them.)`)}));v.command("bottlenecks").description("Find coupling hubs: high fan-in AND high fan-out").option("-n, --limit <n>","Number of results",D,20).option("-s, --scope <path>","Limit to files matching path").option("--min-fan-in <n>","Minimum fan-in",D,2).option("--min-fan-out <n>","Minimum fan-out",D,2).action(e=>E(n=>{let t=C.bottlenecks(n,{limit:e.limit,scope:e.scope,minFanIn:e.minFanIn,minFanOut:e.minFanOut});if(t.length===0)return N.empty("No bottlenecks found.");N.table(["score","fan-in","fan-out","symbol"],t.map(s=>` ${String(s.score).padStart(5)} ${String(s.fanIn).padStart(6)} ${String(s.fanOut).padStart(7)} ${s.shortName}`))}));v.command("isolated").description("Find completely orphaned symbols (no references at all)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum lines of code",D,3).action(e=>E(n=>{let t=C.isolated(n,{scope:e.scope,minLoc:e.minLoc});if(t.length===0)return N.empty("No isolated symbols found.");N.groupedByFile(t,s=>` ${be(s.startLine,s.endLine)} (${s.loc} LOC) ${s.shortName}`),console.log(`
851
+ ${t.length} isolated symbol(s)`)}));v.command("by-kind <kind>").description("Find symbols by SCIP kind (class, interface, enum, function, etc.)").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",D,100).action((e,n)=>E(t=>{let s=C.byKind(t,e,{scope:n.scope,limit:n.limit});if(s.length===0)return N.empty(`No symbols found for kind "${e}". Use "kind-counts" to see available kinds.`);N.list(s,i=>` ${Se(i.relativePath,i.startLine,i.endLine)} [${i.kindName}] ${i.shortName}`),console.log(`
852
+ ${s.length} symbol(s)`)}));v.command("kind-counts").description("Histogram of symbol kinds in the codebase").option("-s, --scope <path>","Limit to files matching path").action(e=>E(n=>{let t=C.kindCounts(n,{scope:e.scope});N.table(["count","kind"],t.map(s=>` ${String(s.count).padStart(5)} ${s.kindName} (${s.kind})`))}));v.command("deep-chains").description("Find the longest transitive dependency chains").option("-n, --limit <n>","Number of chains to show",D,10).option("-s, --scope <path>","Limit to files matching path").option("--min-depth <n>","Minimum chain depth",D,3).action(e=>E(n=>{let t=C.deepChains(n,{limit:e.limit,scope:e.scope,minDepth:e.minDepth});if(t.length===0)return N.empty("No deep chains found.");for(let s=0;s<t.length;s++){console.log(`
853
+ Chain ${s+1} (depth ${t[s].depth}):`);for(let i of t[s].chain)console.log(` \u2192 ${i}`)}}));v.command("hierarchy <symbol>").description("Show a symbol's ancestry chain (method \u2192 class \u2192 module)").action(e=>E(n=>{let t=C.hierarchy(n,e);if(t.length===0)return N.empty("Symbol not found.");N.list(t,s=>`${" ".repeat(s.depth)}${s.shortName}`)}));v.command("call-graph <symbol>").description("Show incoming callers and outgoing callees for a symbol").action(e=>E(n=>{let t=C.callGraph(n,e);if(!t)return N.empty("Symbol not found.");console.log(`Symbol: ${t.shortName}
854
+ `),N.sectionedReport([{title:`CALLERS (${t.callers.length})`,rows:t.callers.map(s=>` ${s.file} ${s.shortName}`)},{title:`CALLEES (${t.callees.length})`,rows:t.callees.map(s=>` ${s.file} ${s.shortName}`)}])}));v.command("similar [symbol]").description("Find functions with similar callee fingerprints (consolidation candidates)").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.4).option("-n, --limit <n>","Number of results",D,20).option("-s, --scope <path>","Limit to files matching path").option("--min-callees <n>","Minimum callees to consider",D,4).option("--cross-file-only","Only show cross-file pairs (skip same-file matches)").action((e,n)=>E(t=>{if(e){let s=C.similar(t,e,{minSimilarity:n.minSimilarity,limit:n.limit});if(s.length===0)return N.empty("No similar symbols found.");N.list(s,i=>{let o=[`
855
+ ${Math.round(i.similarity*100)}% similar:`,` A: ${i.shortNameA} (${i.fileA})`,` B: ${i.shortNameB} (${i.fileB})`,` Shared callees: ${i.sharedCallees.join(", ")}`];return i.uniqueToA.length&&o.push(` Only in A: ${i.uniqueToA.join(", ")}`),i.uniqueToB.length&&o.push(` Only in B: ${i.uniqueToB.join(", ")}`),o.join(`
856
+ `)})}else{let s=C.similarAll(t,{minSimilarity:n.minSimilarity,limit:n.limit,scope:n.scope,minCallees:n.minCallees,crossFileOnly:n.crossFileOnly});if(s.length===0)return N.empty("No similar symbol pairs found.");N.list(s,i=>`
857
+ ${Math.round(i.similarity*100)}% similar:
858
+ A: ${i.shortNameA} (${i.fileA})
859
+ B: ${i.shortNameB} (${i.fileB})
860
+ Shared: ${i.sharedCallees.join(", ")}`),console.log(`
861
+ ${s.length} similar pair(s) found.`)}}));v.command("similar-files [file]").description("Find files with similar dependency profiles").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",D,20).option("-s, --scope <path>","Limit to files matching path").option("--min-deps <n>","Minimum dependencies to consider",D).action((e,n)=>E(t=>{let s=C.similarFiles(t,{minSimilarity:n.minSimilarity,limit:n.limit,scope:n.scope,minDeps:n.minDeps,filePattern:e});if(s.length===0)return N.empty("No similar file pairs found.");N.list(s,i=>{let o=[`
862
+ ${Math.round(i.similarity*100)}% similar:`,` ${i.fileA}`,` ${i.fileB}`,` Shared deps (${i.sharedDeps.length}): ${i.sharedDeps.join(", ")}`];return i.uniqueToA.length&&o.push(` Only in first: ${i.uniqueToA.join(", ")}`),i.uniqueToB.length&&o.push(` Only in second: ${i.uniqueToB.join(", ")}`),o.join(`
814
863
  `)}),console.log(`
815
- ${i.length} similar pair(s) found.`)}));C.command("similar-chains").description("Find end-to-end dependency flows that diverge at few points").option("--min-similarity <n>","Minimum chain similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",w,15).option("-s, --scope <path>","Limit to files matching path").option("--min-length <n>","Minimum chain length",w,3).option("--max-length <n>","Maximum chain length",w,8).action(e=>E(n=>{let t=v.similarChains(n,{minSimilarity:e.minSimilarity,limit:e.limit,scope:e.scope,minChainLength:e.minLength,maxChainLength:e.maxLength});if(t.length===0)return N.empty("No similar chains found.");for(let i=0;i<t.length;i++){let s=t[i];console.log(`
816
- \u2500\u2500 Chain pair ${i+1} (${Math.round(s.similarity*100)}% similar, ${s.divergencePoints.length} divergence point(s)) \u2500\u2500`),console.log(` Chain A: ${s.chainA.join(" \u2192 ")}`),console.log(` Chain B: ${s.chainB.join(" \u2192 ")}`),s.commonPrefix.length&&console.log(` Common prefix: ${s.commonPrefix.join(" \u2192 ")}`),s.commonSuffix.length&&console.log(` Common suffix: ${s.commonSuffix.join(" \u2192 ")}`),console.log(" Divergence points (consolidation targets):");for(let o of s.divergencePoints)console.log(` [${o.index}] ${o.nodeA} \u2194 ${o.nodeB}`)}console.log(`
817
- ${t.length} similar chain pair(s) found.`)}));C.command("extract-candidates").description("Find functions with natural extraction seams (isolated callee clusters)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum function LOC",w,10).option("--min-callees <n>","Minimum callees to analyze",w,6).option("-n, --limit <n>","Number of results",w,20).action(e=>E(n=>{let t=v.extractCandidates(n,{scope:e.scope,minLoc:e.minLoc,minCallees:e.minCallees,limit:e.limit});if(t.length===0)return N.empty("No extraction candidates found.");for(let i of t){console.log(`
818
- ${be(i.relativePath,i.startLine,i.endLine)} ${i.shortName} (${i.loc} LOC, ${i.totalCallees} callees)`);for(let s=0;s<i.clusters.length;s++){let o=i.clusters[s];console.log(` Cluster ${s+1} (${Math.round(o.isolation*100)}% isolated, ${o.callees.length} callees):`);for(let a of o.callees)console.log(` ${a}`)}}console.log(`
819
- ${t.length} extraction candidate(s) found.`)}));C.command("affected <symbol>").description("Transitive closure of symbols that could break if this symbol changes").option("--max-depth <n>","Maximum traversal depth",w,5).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{let i=v.affected(t,e,{maxDepth:n.maxDepth,scope:n.scope});if(i.length===0)return N.empty("No affected symbols found.");let s=-1;for(let o of i)o.depth!==s&&(console.log(`
820
- \u2500\u2500 Depth ${o.depth} \u2500\u2500`),s=o.depth),console.log(` ${o.file} ${o.shortName}`);console.log(`
821
- ${i.length} affected symbol(s) across ${new Set(i.map(o=>o.file)).size} files.`)}));C.command("change-surface <file>").description("Pre-change briefing: exports, consumers, and blast-radius risk").action(e=>E(n=>{let t=v.changeSurface(n,e);if(!t)return N.empty("File not found in index.");console.log(`File: ${t.file}`),console.log(`External consumers: ${t.totalExternalConsumers}
822
- `),N.list(t.symbols,i=>{let s=i.riskLevel==="high"?" *** HIGH RISK ***":i.riskLevel==="medium"?" * medium risk *":"";return` ${ye(i.startLine,i.endLine)} ${i.shortName} [${i.externalConsumers} consumers]${s}`})}));C.command("diff-impact").description("Compute changed symbols and downstream consumers from current git diff").option("--base <ref>","Git ref to diff against (default: HEAD)").action(e=>E(n=>{let t=v.diffImpact(n,{base:e.base});console.log(`Changed files: ${t.summary.totalChangedFiles}`),console.log(`Changed symbols: ${t.summary.totalChangedSymbols}`),console.log(`Affected consumer files: ${t.summary.totalAffectedFiles}`),t.summary.note&&console.log(`Note: ${t.summary.note}`),console.log(""),t.changedSymbols.length>0&&(console.log("Changed symbols:"),N.list(t.changedSymbols,i=>` ${i.file} ${i.shortName} (fan-in: ${i.fanIn})`)),t.affectedConsumers.length>0&&(console.log(`
823
- Affected consumer files:`),N.list(t.affectedConsumers,i=>` ${i.file} (${i.consumedSymbols} symbol(s))`))}));C.command("drift [module]").description("Detect unused imports, layer violations, and pattern deviations").action(e=>E(n=>{let t=v.drift(n,{scope:e});if(t.results.length===0)return N.empty("No drift detected.");console.log(""),N.groupedByFile(t.results,i=>{let o=` [${i.kind==="unused-import"?"UNUSED":i.kind==="layer-violation"?"LAYER":"UNIQUE"}] ${i.description}`;return i.detail?`${o}
824
- ${i.detail}`:o},i=>i.file),console.log(`
825
- ${t.unusedImports} unused import(s), ${t.layerViolations} layer violation(s), ${t.patternDeviations} pattern deviation(s)`)}));C.command("wrapper-candidates").description("Find symbols only called by one consumer (premature abstractions)").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",w,15).option("-n, --limit <n>","Number of results",w,30).action(e=>E(n=>{let t=v.wrapperCandidates(n,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(t.length===0)return N.empty("No wrapper candidates found.");N.list(t,i=>` ${be(i.file,i.startLine,i.endLine)} ${i.shortName} (${i.loc} LOC)
826
- Only called by: ${i.singleCallerShort} (fan-in: ${i.callerFanIn})`),console.log(`
827
- ${t.length} wrapper candidate(s).`)}));C.command("passthrough-candidates").description("Find functions that just forward to one other function").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",w,15).option("-n, --limit <n>","Number of results",w,30).action(e=>E(n=>{let t=v.passthroughCandidates(n,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(t.length===0)return N.empty("No passthrough candidates found.");N.list(t,i=>` ${be(i.file,i.startLine,i.endLine)} ${i.shortName} (${i.loc} LOC)
828
- Forwards to: ${i.forwardsToShort} (${i.forwardsToFile})`),console.log(`
829
- ${t.length} passthrough candidate(s).`)}));C.command("stale-abstractions").description("Find types/interfaces with 0-1 consumers (premature abstractions)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",w,3).option("-n, --limit <n>","Number of results",w,30).option("--include-low-confidence","Include 1-consumer classes (usually encapsulation, not stale)",!1).action(e=>E(n=>{let t=v.staleAbstractions(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit,includeLowConfidence:!!e.includeLowConfidence});if(t.length===0)return N.empty("No stale abstractions found.");N.list(t,i=>{let s=i.consumers===0?"unused":`${i.consumers} consumer`,o=i.barrelConsumers>0?`, +${i.barrelConsumers} barrel`:"";return` [${i.confidence}] ${be(i.file,i.startLine,i.endLine)} ${i.shortName} (${i.kind}, ${i.loc} LOC, ${s}${o})
830
- ${i.reason}`}),console.log(`
831
- ${t.length} stale abstraction(s).`)}));C.command("complexity-hotspots").description("Composite complexity score: LOC x fan-in x fan-out").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",w,10).option("-n, --limit <n>","Number of results",w,20).action(e=>E(n=>{let t=v.complexityHotspots(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(t.length===0)return N.empty("No complexity hotspots found.");N.table(["score"," LOC","fan-in","fan-out","callees","symbol"],t.map(i=>` ${i.score.toFixed(1).padStart(5)} ${String(i.loc).padStart(4)} ${String(i.fanIn).padStart(6)} ${String(i.fanOut).padStart(7)} ${String(i.calleeCount).padStart(7)} ${i.shortName}`),[5,4,6,7,7,6])}));C.command("health").description("Composite codebase health report with prioritized action list").option("-s, --scope <path>","Limit to files matching path").option("--json","Output as JSON for programmatic consumption").action(e=>E(n=>{let t=v.health(n,{scope:e.scope});if(e.json){console.log(JSON.stringify(t,null,2));return}console.log(`
864
+ ${s.length} similar pair(s) found.`)}));v.command("similar-chains").description("Find end-to-end dependency flows that diverge at few points").option("--min-similarity <n>","Minimum chain similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",D,15).option("-s, --scope <path>","Limit to files matching path").option("--min-length <n>","Minimum chain length",D,3).option("--max-length <n>","Maximum chain length",D,8).action(e=>E(n=>{let t=C.similarChains(n,{minSimilarity:e.minSimilarity,limit:e.limit,scope:e.scope,minChainLength:e.minLength,maxChainLength:e.maxLength});if(t.length===0)return N.empty("No similar chains found.");for(let s=0;s<t.length;s++){let i=t[s];console.log(`
865
+ \u2500\u2500 Chain pair ${s+1} (${Math.round(i.similarity*100)}% similar, ${i.divergencePoints.length} divergence point(s)) \u2500\u2500`),console.log(` Chain A: ${i.chainA.join(" \u2192 ")}`),console.log(` Chain B: ${i.chainB.join(" \u2192 ")}`),i.commonPrefix.length&&console.log(` Common prefix: ${i.commonPrefix.join(" \u2192 ")}`),i.commonSuffix.length&&console.log(` Common suffix: ${i.commonSuffix.join(" \u2192 ")}`),console.log(" Divergence points (consolidation targets):");for(let o of i.divergencePoints)console.log(` [${o.index}] ${o.nodeA} \u2194 ${o.nodeB}`)}console.log(`
866
+ ${t.length} similar chain pair(s) found.`)}));v.command("extract-candidates").description("Find functions with natural extraction seams (isolated callee clusters)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum function LOC",D,10).option("--min-callees <n>","Minimum callees to analyze",D,6).option("-n, --limit <n>","Number of results",D,20).action(e=>E(n=>{let t=C.extractCandidates(n,{scope:e.scope,minLoc:e.minLoc,minCallees:e.minCallees,limit:e.limit});if(t.length===0)return N.empty("No extraction candidates found.");for(let s of t){console.log(`
867
+ ${Se(s.relativePath,s.startLine,s.endLine)} ${s.shortName} (${s.loc} LOC, ${s.totalCallees} callees)`);for(let i=0;i<s.clusters.length;i++){let o=s.clusters[i];console.log(` Cluster ${i+1} (${Math.round(o.isolation*100)}% isolated, ${o.callees.length} callees):`);for(let a of o.callees)console.log(` ${a}`)}}console.log(`
868
+ ${t.length} extraction candidate(s) found.`)}));v.command("affected <symbol>").description("Transitive closure of symbols that could break if this symbol changes").option("--max-depth <n>","Maximum traversal depth",D,5).option("-s, --scope <path>","Limit to files matching path").action((e,n)=>E(t=>{let s=C.affected(t,e,{maxDepth:n.maxDepth,scope:n.scope});if(s.length===0)return N.empty("No affected symbols found.");let i=-1;for(let o of s)o.depth!==i&&(console.log(`
869
+ \u2500\u2500 Depth ${o.depth} \u2500\u2500`),i=o.depth),console.log(` ${o.file} ${o.shortName}`);console.log(`
870
+ ${s.length} affected symbol(s) across ${new Set(s.map(o=>o.file)).size} files.`)}));v.command("change-surface <file>").description("Pre-change briefing: exports, consumers, and blast-radius risk").action(e=>E(n=>{let t=C.changeSurface(n,e);if(!t)return N.empty("File not found in index.");console.log(`File: ${t.file}`),console.log(`External consumers: ${t.totalExternalConsumers}
871
+ `),N.list(t.symbols,s=>{let i=s.riskLevel==="high"?" *** HIGH RISK ***":s.riskLevel==="medium"?" * medium risk *":"";return` ${be(s.startLine,s.endLine)} ${s.shortName} [${s.externalConsumers} consumers]${i}`})}));v.command("diff-impact").description("Compute changed symbols and downstream consumers from current git diff").option("--base <ref>","Git ref to diff against (default: HEAD)").action(e=>E(n=>{let t=C.diffImpact(n,{base:e.base});console.log(`Changed files: ${t.summary.totalChangedFiles}`),console.log(`Changed symbols: ${t.summary.totalChangedSymbols}`),console.log(`Affected consumer files: ${t.summary.totalAffectedFiles}`),t.summary.note&&console.log(`Note: ${t.summary.note}`),console.log(""),t.changedSymbols.length>0&&(console.log("Changed symbols:"),N.list(t.changedSymbols,s=>` ${s.file} ${s.shortName} (fan-in: ${s.fanIn})`)),t.affectedConsumers.length>0&&(console.log(`
872
+ Affected consumer files:`),N.list(t.affectedConsumers,s=>` ${s.file} (${s.consumedSymbols} symbol(s))`))}));v.command("drift [module]").description("Detect unused imports, layer violations, and pattern deviations").action(e=>E(n=>{let t=C.drift(n,{scope:e});if(t.results.length===0)return N.empty("No drift detected.");console.log(""),N.groupedByFile(t.results,s=>{let o=` [${s.kind==="unused-import"?"UNUSED":s.kind==="layer-violation"?"LAYER":"UNIQUE"}] ${s.description}`;return s.detail?`${o}
873
+ ${s.detail}`:o},s=>s.file),console.log(`
874
+ ${t.unusedImports} unused import(s), ${t.layerViolations} layer violation(s), ${t.patternDeviations} pattern deviation(s)`)}));v.command("wrapper-candidates").description("Find symbols only called by one consumer (premature abstractions)").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",D,15).option("-n, --limit <n>","Number of results",D,30).action(e=>E(n=>{let t=C.wrapperCandidates(n,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(t.length===0)return N.empty("No wrapper candidates found.");N.list(t,s=>` ${Se(s.file,s.startLine,s.endLine)} ${s.shortName} (${s.loc} LOC)
875
+ Only called by: ${s.singleCallerShort} (fan-in: ${s.callerFanIn})`),console.log(`
876
+ ${t.length} wrapper candidate(s).`)}));v.command("passthrough-candidates").description("Find functions that just forward to one other function").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",D,15).option("-n, --limit <n>","Number of results",D,30).action(e=>E(n=>{let t=C.passthroughCandidates(n,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(t.length===0)return N.empty("No passthrough candidates found.");N.list(t,s=>` ${Se(s.file,s.startLine,s.endLine)} ${s.shortName} (${s.loc} LOC)
877
+ Forwards to: ${s.forwardsToShort} (${s.forwardsToFile})`),console.log(`
878
+ ${t.length} passthrough candidate(s).`)}));v.command("stale-abstractions").description("Find types/interfaces with 0-1 consumers (premature abstractions)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",D,3).option("-n, --limit <n>","Number of results",D,30).option("--include-low-confidence","Include 1-consumer classes (usually encapsulation, not stale)",!1).action(e=>E(n=>{let t=C.staleAbstractions(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit,includeLowConfidence:!!e.includeLowConfidence});if(t.length===0)return N.empty("No stale abstractions found.");N.list(t,s=>{let i=s.consumers===0?"unused":`${s.consumers} consumer`,o=s.barrelConsumers>0?`, +${s.barrelConsumers} barrel`:"";return` [${s.confidence}] ${Se(s.file,s.startLine,s.endLine)} ${s.shortName} (${s.kind}, ${s.loc} LOC, ${i}${o})
879
+ ${s.reason}`}),console.log(`
880
+ ${t.length} stale abstraction(s).`)}));v.command("complexity-hotspots").description("Composite complexity score: LOC x fan-in x fan-out").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",D,10).option("-n, --limit <n>","Number of results",D,20).action(e=>E(n=>{let t=C.complexityHotspots(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(t.length===0)return N.empty("No complexity hotspots found.");N.table(["score"," LOC","fan-in","fan-out","callees","symbol"],t.map(s=>` ${s.score.toFixed(1).padStart(5)} ${String(s.loc).padStart(4)} ${String(s.fanIn).padStart(6)} ${String(s.fanOut).padStart(7)} ${String(s.calleeCount).padStart(7)} ${s.shortName}`),[5,4,6,7,7,6])}));v.command("health").description("Composite codebase health report with prioritized action list").option("-s, --scope <path>","Limit to files matching path").option("--json","Output as JSON for programmatic consumption").action(e=>E(n=>{let t=C.health(n,{scope:e.scope});if(e.json){console.log(JSON.stringify(t,null,2));return}console.log(`
832
881
  Codebase Health Score: ${t.score}/100
833
- `),console.log(` ${t.overview.documents} files | ${t.overview.symbols} symbols | ${Jn(t.overview.indexSizeBytes)}
834
- `),console.log(" Findings:");let i=t.findings;if(i.deadSymbols>0&&console.log(` Dead code: ${i.deadSymbols} symbols (${i.deadLoc} LOC)`),i.isolatedSymbols>0&&console.log(` Isolated symbols: ${i.isolatedSymbols} (${i.isolatedLoc} LOC)`),i.cycles>0&&console.log(` Circular deps: ${i.cycles}`),i.similarPairs>0&&console.log(` Similar pairs: ${i.similarPairs}`),i.extractionCandidates>0&&console.log(` Extract candidates: ${i.extractionCandidates}`),i.wrappers>0&&console.log(` Wrapper functions: ${i.wrappers}`),i.passthroughs>0&&console.log(` Passthroughs: ${i.passthroughs}`),i.staleTypes>0&&console.log(` Stale abstractions: ${i.staleTypes}`),i.driftedFiles>0&&console.log(` Pattern drift: ${i.driftedFiles} files`),i.complexityHotspotCount>0&&console.log(` Complexity hotspots: ${i.complexityHotspotCount}`),t.actions.length>0){console.log(`
835
- Prioritized Actions (highest impact + lowest effort first):`);for(let s=0;s<t.actions.length;s++){let o=t.actions[s],a=o.locRecoverable>0?` (~${o.locRecoverable} LOC recoverable)`:"";console.log(` ${s+1}. [${o.effort} effort / ${o.impact} impact] ${o.description}${a}`)}}if(t.topComplexity.length>0){console.log(`
836
- Top Complexity Hotspots:`);for(let s of t.topComplexity)console.log(` ${s.score.toFixed(1).padStart(6)} ${s.symbol}`)}t.actions.length===0&&console.log(`
837
- No issues found. Codebase is clean.`)}));C.command("convergence <symbol1> <symbol2>").description("Show what a consolidated version of two similar functions would look like").action((e,n)=>E(t=>{let i=v.convergence(t,e,n);if(!i)return N.empty("One or both symbols not found.");console.log(`
838
- ${Math.round(i.similarity*100)}% callee overlap
839
- `),console.log(` A: ${i.symbolA.shortName} (${i.symbolA.file}, ${i.symbolA.loc} LOC)`),console.log(` B: ${i.symbolB.shortName} (${i.symbolB.file}, ${i.symbolB.loc} LOC)
840
- `),console.log(` Shared callees (${i.sharedCallees.length}):`);for(let s of i.sharedCallees)console.log(` ${s}`);if(i.uniqueToA.length>0){console.log(`
841
- Unique to A (${i.uniqueToA.length}):`);for(let s of i.uniqueToA)console.log(` ${s}`)}if(i.uniqueToB.length>0){console.log(`
842
- Unique to B (${i.uniqueToB.length}):`);for(let s of i.uniqueToB)console.log(` ${s}`)}console.log(`
843
- Strategy: ${i.consolidationStrategy}`)}));C.command("code <symbol>").description("Read the source code for a symbol (bounded to its definition range)").option("-C, --context <n>","Extra lines of context above/below",w,0).action((e,n)=>E(t=>{let i=v.code(t,e,{context:n.context});if(!i)return N.empty("Symbol not found or file unreadable.");console.log(`${be(i.relativePath,i.startLine,i.endLine)} ${i.shortName} [${i.language??"unknown"}]
844
- `);let s=i.source.split(`
845
- `);for(let o=0;o<s.length;o++)console.log(` ${String(Ne(i.startLine+o)).padStart(4)} ${s[o]}`)}));C.command("complexity <symbol>").description("Per-symbol complexity: branches, cyclomatic estimate, fan-in/out, callees").action(e=>E(n=>{let t=v.complexity(n,e);if(!t)return N.empty("Symbol not found.");console.log(`${be(t.relativePath,t.startLine,t.endLine)} ${t.shortName}
846
- `),console.log(` LOC: ${t.loc}`),console.log(` Branches: ${t.branches}`),console.log(` Cyclomatic estimate: ${t.cyclomaticEstimate}`),console.log(` Callees: ${t.calleeCount}`),console.log(` Fan-in: ${t.fanIn}`),console.log(` Fan-out: ${t.fanOut}`)}));C.command("dataflow <symbol>").description("Reference-level dataflow: definition sites, usage sites, producers, consumers").action(e=>E(n=>{let t=v.dataflow(n,e);if(!t)return N.empty("Symbol not found.");if(console.log(`${t.shortName} (${t.relativePath})
847
- `),t.definitionSites.length>0){console.log(" \u2550\u2550\u2550 DEFINED AT \u2550\u2550\u2550");for(let i of t.definitionSites)console.log(` ${i.file}:${Ne(i.line)}`)}if(t.usageSites.length>0){console.log(`
848
- \u2550\u2550\u2550 USED AT \u2550\u2550\u2550`);for(let i of t.usageSites)console.log(` ${i.file}:${Ne(i.line)} in ${i.enclosingShort}`)}if(t.producers.length>0){console.log(`
849
- \u2550\u2550\u2550 PRODUCERS (feeds into this) \u2550\u2550\u2550`);for(let i of t.producers)console.log(` ${i.file} ${i.shortName}`)}if(t.consumers.length>0){console.log(`
850
- \u2550\u2550\u2550 CONSUMERS (this feeds into) \u2550\u2550\u2550`);for(let i of t.consumers)console.log(` ${i.file} ${i.shortName}`)}}));C.command("slice <symbol>").description("Reference-level program slice: what affects this (backward) or what this affects (forward)").option("--forward","Forward slice (what does this affect). Default is backward.").option("--depth <n>","Max transitive depth for backward slice",w,3).action((e,n)=>E(t=>{let i=n.forward?"forward":"backward",s=v.slice(t,e,{direction:i,maxDepth:n.depth});if(!s)return N.empty("Symbol not found.");if(console.log(`${s.direction} slice of ${s.shortName}
851
- `),s.connectedSymbols.length===0){console.log(" No connected symbols found.");return}N.list(s.connectedSymbols,o=>` ${o.file} ${o.shortName}
882
+ `),console.log(` ${t.overview.documents} files | ${t.overview.symbols} symbols | ${ss(t.overview.indexSizeBytes)}
883
+ `),console.log(" Findings:");let s=t.findings;if(s.deadSymbols>0&&console.log(` Dead code: ${s.deadSymbols} symbols (${s.deadLoc} LOC)`),s.isolatedSymbols>0&&console.log(` Isolated symbols: ${s.isolatedSymbols} (${s.isolatedLoc} LOC)`),s.cycles>0&&console.log(` Circular deps: ${s.cycles}`),s.similarPairs>0&&console.log(` Similar pairs: ${s.similarPairs}`),s.extractionCandidates>0&&console.log(` Extract candidates: ${s.extractionCandidates}`),s.wrappers>0&&console.log(` Wrapper functions: ${s.wrappers}`),s.passthroughs>0&&console.log(` Passthroughs: ${s.passthroughs}`),s.staleTypes>0&&console.log(` Stale abstractions: ${s.staleTypes}`),s.driftedFiles>0&&console.log(` Pattern drift: ${s.driftedFiles} files`),s.complexityHotspotCount>0&&console.log(` Complexity hotspots: ${s.complexityHotspotCount}`),t.actions.length>0){console.log(`
884
+ Prioritized Actions (highest impact + lowest effort first):`);for(let i=0;i<t.actions.length;i++){let o=t.actions[i],a=o.locRecoverable>0?` (~${o.locRecoverable} LOC recoverable)`:"";console.log(` ${i+1}. [${o.effort} effort / ${o.impact} impact] ${o.description}${a}`)}}if(t.topComplexity.length>0){console.log(`
885
+ Top Complexity Hotspots:`);for(let i of t.topComplexity)console.log(` ${i.score.toFixed(1).padStart(6)} ${i.symbol}`)}t.actions.length===0&&console.log(`
886
+ No issues found. Codebase is clean.`)}));v.command("convergence <symbol1> <symbol2>").description("Show what a consolidated version of two similar functions would look like").action((e,n)=>E(t=>{let s=C.convergence(t,e,n);if(!s)return N.empty("One or both symbols not found.");console.log(`
887
+ ${Math.round(s.similarity*100)}% callee overlap
888
+ `),console.log(` A: ${s.symbolA.shortName} (${s.symbolA.file}, ${s.symbolA.loc} LOC)`),console.log(` B: ${s.symbolB.shortName} (${s.symbolB.file}, ${s.symbolB.loc} LOC)
889
+ `),console.log(` Shared callees (${s.sharedCallees.length}):`);for(let i of s.sharedCallees)console.log(` ${i}`);if(s.uniqueToA.length>0){console.log(`
890
+ Unique to A (${s.uniqueToA.length}):`);for(let i of s.uniqueToA)console.log(` ${i}`)}if(s.uniqueToB.length>0){console.log(`
891
+ Unique to B (${s.uniqueToB.length}):`);for(let i of s.uniqueToB)console.log(` ${i}`)}console.log(`
892
+ Strategy: ${s.consolidationStrategy}`)}));v.command("code <symbol>").description("Read the source code for a symbol (bounded to its definition range)").option("-C, --context <n>","Extra lines of context above/below",D,0).action((e,n)=>E(t=>{let s=C.code(t,e,{context:n.context});if(!s)return N.empty("Symbol not found or file unreadable.");console.log(`${Se(s.relativePath,s.startLine,s.endLine)} ${s.shortName} [${s.language??"unknown"}]
893
+ `);let i=s.source.split(`
894
+ `);for(let o=0;o<i.length;o++)console.log(` ${String(Ee(s.startLine+o)).padStart(4)} ${i[o]}`)}));v.command("complexity <symbol>").description("Per-symbol complexity: branches, cyclomatic estimate, fan-in/out, callees").action(e=>E(n=>{let t=C.complexity(n,e);if(!t)return N.empty("Symbol not found.");console.log(`${Se(t.relativePath,t.startLine,t.endLine)} ${t.shortName}
895
+ `),console.log(` LOC: ${t.loc}`),console.log(` Branches: ${t.branches}`),console.log(` Cyclomatic estimate: ${t.cyclomaticEstimate}`),console.log(` Callees: ${t.calleeCount}`),console.log(` Fan-in: ${t.fanIn}`),console.log(` Fan-out: ${t.fanOut}`)}));v.command("dataflow <symbol>").description("Reference-level dataflow: definition sites, usage sites, producers, consumers").action(e=>E(n=>{let t=C.dataflow(n,e);if(!t)return N.empty("Symbol not found.");if(console.log(`${t.shortName} (${t.relativePath})
896
+ `),t.definitionSites.length>0){console.log(" \u2550\u2550\u2550 DEFINED AT \u2550\u2550\u2550");for(let s of t.definitionSites)console.log(` ${s.file}:${Ee(s.line)}`)}if(t.usageSites.length>0){console.log(`
897
+ \u2550\u2550\u2550 USED AT \u2550\u2550\u2550`);for(let s of t.usageSites)console.log(` ${s.file}:${Ee(s.line)} in ${s.enclosingShort}`)}if(t.producers.length>0){console.log(`
898
+ \u2550\u2550\u2550 PRODUCERS (feeds into this) \u2550\u2550\u2550`);for(let s of t.producers)console.log(` ${s.file} ${s.shortName}`)}if(t.consumers.length>0){console.log(`
899
+ \u2550\u2550\u2550 CONSUMERS (this feeds into) \u2550\u2550\u2550`);for(let s of t.consumers)console.log(` ${s.file} ${s.shortName}`)}}));v.command("slice <symbol>").description("Reference-level program slice: what affects this (backward) or what this affects (forward)").option("--forward","Forward slice (what does this affect). Default is backward.").option("--depth <n>","Max transitive depth for backward slice",D,3).action((e,n)=>E(t=>{let s=n.forward?"forward":"backward",i=C.slice(t,e,{direction:s,maxDepth:n.depth});if(!i)return N.empty("Symbol not found.");if(console.log(`${i.direction} slice of ${i.shortName}
900
+ `),i.connectedSymbols.length===0){console.log(" No connected symbols found.");return}N.list(i.connectedSymbols,o=>` ${o.file} ${o.shortName}
852
901
  ${o.relationship}`),console.log(`
853
- ${s.connectedSymbols.length} connected symbol(s).`)}));C.command("install-skills").description(`Install skills (${Hn.join(", ")}) into Claude Code and Codex`).action(()=>{let e=Wo(),n=e.installed.length+e.alreadyLinked.length;console.log(`
854
- ${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),n>0&&console.log("Skills will be available in your next Claude Code / Codex session.")});C.command("check-deps").description("Check whether scip-query and the detected language indexers are actually runnable").action(()=>{let e=!1;dn()?console.log("scip CLI: installed"):(pn(),e=!0);let n=Qe(),i=$e(n).languages??je(n);if(i.length===0){console.log(`
902
+ ${i.connectedSymbols.length} connected symbol(s).`)}));v.command("install-skills").description(`Install skills (${ns.join(", ")}) into Claude Code and Codex`).action(()=>{let e=dr(),n=e.installed.length+e.alreadyLinked.length;console.log(`
903
+ ${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),n>0&&console.log("Skills will be available in your next Claude Code / Codex session.")});v.command("check-deps").description("Check whether scip-query and the detected language indexers are actually runnable").action(()=>{let e=!1;Nn()?console.log("scip CLI: installed"):(vn(),e=!0);let n=Me(),s=Te(n).languages??qe(n);if(s.length===0){console.log(`
855
904
  No supported project languages detected in the current directory.`),process.exitCode=e?1:0;return}console.log(`
856
- Detected languages: ${i.join(", ")}`),console.log(`
857
- Indexer readiness:`);for(let s of i){let o=gi(St(s),n),a=o.runnable?" OK":o.installed?" WARN":" MISSING",r=o.resolvedBinary?` (${o.resolvedBinary})`:"";console.log(`${a} ${s}: ${o.binaryLabel}${r}`),o.note&&console.log(` ${o.note}`),!o.installed&&o.installUrl&&console.log(` install: ${o.installUrl}`),o.runnable||(e=!0)}process.exitCode=e?1:0});C.command("redundant-reexports").description("Find barrel re-exports that nobody imports through").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",w,30).action(e=>E(n=>{let t=v.redundantReexports(n,{scope:e.scope,limit:e.limit});if(t.length===0)return N.empty("No redundant re-exports found.");N.groupedByFile(t,i=>` ${i.shortName} (from ${i.originalFile})
858
- barrel: ${i.barrelConsumers} consumer(s) | direct: ${i.directConsumers} consumer(s)`,i=>i.barrelFile),console.log(`
859
- ${t.length} redundant re-export(s).`)}));C.command("similar-signatures").description("Find functions with near-identical type signatures (same shape)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC per function",w,3).option("-n, --limit <n>","Number of groups",w,20).action(e=>E(n=>{let t=v.similarSignatures(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(t.length===0)return N.empty("No same-shape function groups found.");N.list(t,i=>{let s=`
860
- Signature: ${i.signature} (${i.functions.length} functions)`,o=i.functions.map(a=>` ${be(a.file,a.startLine,a.endLine)} ${a.shortName} (${a.loc} LOC)`).join(`
861
- `);return`${s}
905
+ Detected languages: ${s.join(", ")}`),console.log(`
906
+ Indexer readiness:`);for(let i of s){let o=Os($t(i),n),a=o.runnable?" OK":o.installed?" WARN":" MISSING",r=o.resolvedBinary?` (${o.resolvedBinary})`:"";console.log(`${a} ${i}: ${o.binaryLabel}${r}`),o.note&&console.log(` ${o.note}`),!o.installed&&o.installUrl&&console.log(` install: ${o.installUrl}`),o.runnable||(e=!0)}process.exitCode=e?1:0});v.command("redundant-reexports").description("Find barrel re-exports that nobody imports through").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",D,30).action(e=>E(n=>{let t=C.redundantReexports(n,{scope:e.scope,limit:e.limit});if(t.length===0)return N.empty("No redundant re-exports found.");N.groupedByFile(t,s=>` ${s.shortName} (from ${s.originalFile})
907
+ barrel: ${s.barrelConsumers} consumer(s) | direct: ${s.directConsumers} consumer(s)`,s=>s.barrelFile),console.log(`
908
+ ${t.length} redundant re-export(s).`)}));v.command("similar-signatures").description("Find functions with near-identical type signatures (same shape)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC per function",D,3).option("-n, --limit <n>","Number of groups",D,20).action(e=>E(n=>{let t=C.similarSignatures(n,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(t.length===0)return N.empty("No same-shape function groups found.");N.list(t,s=>{let i=`
909
+ Signature: ${s.signature} (${s.functions.length} functions)`,o=s.functions.map(a=>` ${Se(a.file,a.startLine,a.endLine)} ${a.shortName} (${a.loc} LOC)`).join(`
910
+ `);return`${i}
862
911
  ${o}`}),console.log(`
863
- ${t.length} group(s) found.`)}));C.command("init").description("Create a .scipquery.json config file for this project").action(()=>{let e=Qe(),n=je(e),t=Xn(e,n);console.log(`Config written to ${t}`),console.log(`Detected languages: ${n.join(", ")||"(none)"}`)});C.command("watch").description("Watch for file changes and reindex automatically").option("--debounce <ms>","Ms to wait after last change (default: 30000)",parseInt).option("--cooldown <ms>","Min ms between reindexes (default: 60000)",parseInt).action(e=>{let n=Qe(),t=$e(n);e.debounce&&((t.watch??={}).debounceMs=e.debounce),e.cooldown&&((t.watch??={}).cooldownMs=e.cooldown);let i=new Nt({projectRoot:n,config:t,languages:t.languages,onStatus:s=>{process.stdout.write(`\r\x1B[K${_u(s)}`)},onReindexComplete:s=>{console.log(`
864
- Reindex complete in ${(s/1e3).toFixed(1)}s`)},onError:s=>{console.error(`
865
- Watch error: ${s.message}`)}});console.log(`Watching ${n}`),console.log(`Debounce: ${t.watch?.debounceMs??3e4}ms | Cooldown: ${t.watch?.cooldownMs??6e4}ms`),console.log(`Press Ctrl+C to stop.
866
- `),i.start(),process.on("SIGINT",()=>{i.stop(),console.log(`
867
- Stopped.`),process.exit(0)})});C.command("status").description("Show index status for this project").action(()=>{let e=Qe(),n=$e(e),t=ke(e,n),i=Jo(e);console.log(`Project: ${e}`),console.log(`DB path: ${i}`),i!==t.dbPath&&console.log(`Config: ${t.dbPath} (fallback to project root index.db)`),console.log(`Exists: ${rn(i)?"yes":"no"}`),rn(i)&&E(s=>{let o=v.stats(s);if(console.log(`Symbols: ${o.symbols}`),console.log(`Files: ${o.documents}`),console.log(`Size: ${Jn(o.indexSizeBytes)}`),o.lastBuilt){let a=Math.round((Date.now()-o.lastBuilt.getTime())/1e3);console.log(`Built: ${a}s ago`)}})});bu()&&C.parse();function bu(){if(!process.argv[1])return!1;let e=fu(import.meta.url);try{return Ho(e)===Ho(process.argv[1])}catch{return e===process.argv[1]}}function Su(e,n){return n.concat([e])}function w(e){return parseInt(e,10)}function Jn(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function _u(e){switch(e.state){case"idle":return"Watching (idle)";case"waiting":{let n=Math.round((e.reindexAt-Date.now())/1e3);return`${e.changedFiles} file(s) changed, reindexing in ${n}s...`}case"indexing":return`Reindexing... (${Math.round((Date.now()-e.startedAt)/1e3)}s)`;case"cooldown":return`Cooldown (${Math.round((e.until-Date.now())/1e3)}s)${e.dirty?" \u2014 changes pending":""}`}}export{C as program};
912
+ ${t.length} group(s) found.`)}));v.command("init").description("Create a .scipquery.json config file for this project").action(()=>{let e=Me(),n=qe(e),t=ds(e,n);console.log(`Config written to ${t}`),console.log(`Detected languages: ${n.join(", ")||"(none)"}`)});v.command("watch").description("Watch for file changes and reindex automatically").option("--debounce <ms>","Ms to wait after last change (default: 30000)",parseInt).option("--cooldown <ms>","Min ms between reindexes (default: 60000)",parseInt).action(e=>{let n=Me(),t=Te(n);e.debounce&&((t.watch??={}).debounceMs=e.debounce),e.cooldown&&((t.watch??={}).cooldownMs=e.cooldown);let s=new jt({projectRoot:n,config:t,languages:t.languages,onStatus:i=>{process.stdout.write(`\r\x1B[K${Cd(i)}`)},onReindexComplete:i=>{console.log(`
913
+ Reindex complete in ${(i/1e3).toFixed(1)}s`)},onError:i=>{console.error(`
914
+ Watch error: ${i.message}`)}});console.log(`Watching ${n}`),console.log(`Debounce: ${t.watch?.debounceMs??3e4}ms | Cooldown: ${t.watch?.cooldownMs??6e4}ms`),console.log(`Press Ctrl+C to stop.
915
+ `),s.start(),process.on("SIGINT",()=>{s.stop(),console.log(`
916
+ Stopped.`),process.exit(0)})});v.command("status").description("Show index status for this project").action(()=>{let e=Me(),n=Te(e),t=Ae(e,n),s=yn(e);console.log(`Project: ${e}`),console.log(`DB path: ${s}`),s!==t.dbPath&&console.log(`Config: ${t.dbPath} (fallback to project root index.db)`),console.log(`Exists: ${hn(s)?"yes":"no"}`),hn(s)&&E(i=>{let o=C.stats(i);if(console.log(`Symbols: ${o.symbols}`),console.log(`Files: ${o.documents}`),console.log(`Size: ${ss(o.indexSizeBytes)}`),o.lastBuilt){let a=Math.round((Date.now()-o.lastBuilt.getTime())/1e3);console.log(`Built: ${a}s ago`)}})});Nd()&&v.parse();function Nd(){if(!process.argv[1])return!1;let e=Sd(import.meta.url);try{return pr(e)===pr(process.argv[1])}catch{return e===process.argv[1]}}function vd(e,n){return n.concat([e])}function D(e){return parseInt(e,10)}function ss(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function Cd(e){switch(e.state){case"idle":return"Watching (idle)";case"waiting":{let n=Math.round((e.reindexAt-Date.now())/1e3);return`${e.changedFiles} file(s) changed, reindexing in ${n}s...`}case"indexing":return`Reindexing... (${Math.round((Date.now()-e.startedAt)/1e3)}s)`;case"cooldown":return`Cooldown (${Math.round((e.until-Date.now())/1e3)}s)${e.dirty?" \u2014 changes pending":""}`}}export{v as program};
868
917
  //# sourceMappingURL=cli.js.map