scip-query 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +43 -6
  2. package/dist/augment-vue-worker.js +1 -1
  3. package/dist/{chunk-FG6A6ZUP.js → chunk-25HOGELX.js} +2 -2
  4. package/dist/{chunk-XV3XUZ3X.js → chunk-2TLYCK2L.js} +2 -2
  5. package/dist/chunk-3PVIYZ74.js +84 -0
  6. package/dist/{chunk-MO32JMOD.js → chunk-4TX5IMMK.js} +2 -2
  7. package/dist/{chunk-3UB2DPLP.js → chunk-6DVA22YE.js} +2 -2
  8. package/dist/{chunk-C5BFS23M.js → chunk-6GPFHZP3.js} +2 -2
  9. package/dist/{chunk-YDKWDTAW.js → chunk-7PRMSA4Z.js} +2 -2
  10. package/dist/{chunk-MTK3JAJT.js → chunk-7YI2M2AQ.js} +2 -2
  11. package/dist/{chunk-M5QTG55L.js → chunk-AADJ7MCQ.js} +2 -2
  12. package/dist/{chunk-A5UNS4DR.js → chunk-AV7BOODV.js} +2 -2
  13. package/dist/{chunk-PBFMZKXE.js → chunk-AXP4H62Q.js} +2 -2
  14. package/dist/{chunk-IJWIYZO5.js → chunk-C4C3T4K3.js} +2 -2
  15. package/dist/{chunk-ZFCQQ4B5.js → chunk-CSRPJCWO.js} +2 -2
  16. package/dist/{chunk-U5MVUPOO.js → chunk-CYJMOTIH.js} +2 -2
  17. package/dist/{chunk-URUVLDM7.js → chunk-DLWRLPKO.js} +2 -2
  18. package/dist/{chunk-5YYMKE3G.js → chunk-E2V5SE6M.js} +2 -2
  19. package/dist/{chunk-FHSD5RKF.js → chunk-GPY33RTH.js} +2 -2
  20. package/dist/{chunk-PFMGJ4BR.js → chunk-HVNVO6UW.js} +2 -2
  21. package/dist/{chunk-BNCTPTVX.js → chunk-I377UMS2.js} +2 -2
  22. package/dist/{chunk-F4KR22Z2.js → chunk-IKQYNTW3.js} +2 -2
  23. package/dist/{chunk-RT5PV5JQ.js → chunk-IZ4KV37N.js} +2 -2
  24. package/dist/{chunk-DRLWW74T.js → chunk-KBGFYKOJ.js} +2 -2
  25. package/dist/chunk-KW2F3WSV.js +5 -0
  26. package/dist/{chunk-FVVEIGP3.js → chunk-NIN762LD.js} +2 -2
  27. package/dist/{chunk-YDNCX5PF.js → chunk-O6VBAW7P.js} +2 -2
  28. package/dist/{chunk-EB5IVUNU.js → chunk-PIRXZGV6.js} +2 -2
  29. package/dist/{chunk-MKFH7QJG.js → chunk-Q4R2IYA3.js} +2 -2
  30. package/dist/{chunk-Z5CTXSWT.js → chunk-QFBJZHMV.js} +2 -2
  31. package/dist/{chunk-WHGCGENP.js → chunk-QPJG6VRT.js} +2 -2
  32. package/dist/{chunk-HUASU3AD.js → chunk-TBJDUS4E.js} +7 -7
  33. package/dist/{chunk-K6H3XJQW.js → chunk-TUV2VI7D.js} +2 -2
  34. package/dist/chunk-UAPNU7UP.js +2 -0
  35. package/dist/{chunk-WNMAH3P7.js → chunk-URCJTFOD.js} +2 -2
  36. package/dist/{chunk-QFCK6WV2.js → chunk-UUIWMLDX.js} +2 -2
  37. package/dist/{chunk-WIIZF5FP.js → chunk-VEXS3I3N.js} +2 -2
  38. package/dist/{chunk-ROWAEEOD.js → chunk-VRC3WKKE.js} +2 -2
  39. package/dist/{chunk-5LQ6CVX3.js → chunk-WFDTS7XL.js} +2 -2
  40. package/dist/chunk-Y4DS3MDC.js +5 -0
  41. package/dist/{chunk-LT2CPEQ4.js → chunk-YJODB2F5.js} +2 -2
  42. package/dist/{chunk-PK4U6NWP.js → chunk-YXMHTJYY.js} +2 -2
  43. package/dist/chunk-Z4AMQWVY.js +90 -0
  44. package/dist/cli.js +111 -111
  45. package/dist/index.d.ts +8 -5
  46. package/dist/index.js +11 -11
  47. package/dist/queries/affected.js +1 -1
  48. package/dist/queries/bottlenecks.js +1 -1
  49. package/dist/queries/call-graph.js +1 -1
  50. package/dist/queries/change-surface.js +1 -1
  51. package/dist/queries/complexity-hotspots.js +1 -1
  52. package/dist/queries/complexity.js +1 -1
  53. package/dist/queries/convergence.js +1 -1
  54. package/dist/queries/cycles.js +1 -1
  55. package/dist/queries/dataflow.js +1 -1
  56. package/dist/queries/dead.js +1 -1
  57. package/dist/queries/deep-chains.js +1 -1
  58. package/dist/queries/diff-impact.js +1 -1
  59. package/dist/queries/drift.js +1 -1
  60. package/dist/queries/extract-candidates.js +1 -1
  61. package/dist/queries/fan.js +1 -1
  62. package/dist/queries/health.js +1 -1
  63. package/dist/queries/hotspots.js +1 -1
  64. package/dist/queries/imports.js +1 -1
  65. package/dist/queries/index.js +1 -1
  66. package/dist/queries/isolated.js +1 -1
  67. package/dist/queries/members.js +1 -1
  68. package/dist/queries/methods.js +1 -1
  69. package/dist/queries/passthrough-candidates.js +1 -1
  70. package/dist/queries/redundant-reexports.js +1 -1
  71. package/dist/queries/refs.js +1 -1
  72. package/dist/queries/similar-chains.js +1 -1
  73. package/dist/queries/similar-files.js +1 -1
  74. package/dist/queries/similar-signatures.js +1 -1
  75. package/dist/queries/similar.js +1 -1
  76. package/dist/queries/slice.js +1 -1
  77. package/dist/queries/stale-abstractions.js +1 -1
  78. package/dist/queries/surface.js +1 -1
  79. package/dist/queries/trace.js +1 -1
  80. package/dist/queries/wrapper-candidates.js +1 -1
  81. package/dist/reindex-worker.js +1 -1
  82. package/package.json +2 -2
  83. package/dist/chunk-2ZGHRI2A.js +0 -5
  84. package/dist/chunk-32R4VYYA.js +0 -2
  85. package/dist/chunk-4X7C236P.js +0 -84
  86. package/dist/chunk-KTCODJNQ.js +0 -5
  87. package/dist/chunk-YU25IHJX.js +0 -90
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- var Ha=Object.defineProperty;var Va=(e,t)=>{for(var n in t)Ha(e,n,{get:t[n],enumerable:!0})};import{program as S}from"commander";import{createRequire as lS}from"module";import{existsSync as Ba,realpathSync as Wa}from"fs";import{fileURLToPath as cS}from"url";import{readFileSync as Ua,writeFileSync as Ja,existsSync as jr,mkdirSync as qa}from"fs";import{join as Te,resolve as Ar}from"path";import{createHash as za}from"crypto";import{homedir as Ga}from"os";var Br=".scipquery.json",Ka={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function Ce(e){let t=Te(e,Br);if(!jr(t))return{};try{let n=Ua(t,"utf-8");return JSON.parse(n)}catch{return{}}}function Wr(e){return{...Ka,...e.watch}}function Qa(e,t){let n=process.env.SCIP_QUERY_CACHE_DIR;if(n)return Fn(n);if(t?.dbPath)return Fn(Ar(e,t.dbPath));let i=process.env.XDG_CACHE_HOME||Te(Ga(),".cache"),s=za("sha256").update(Ar(e)).digest("hex").slice(0,12),o=Te(i,"scip-query","projects",s);return Fn(o)}function ve(e,t){let n=Qa(e,t);return{cacheDir:n,dbPath:Te(n,"index.db"),indexPath:Te(n,"index.scip"),metaPath:Te(n,"meta.json")}}function Hr(e,t){let n=Te(e,Br);return jr(n)||Ja(n,JSON.stringify({languages:t,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
3
- `),n}function Fn(e){return qa(e,{recursive:!0}),e}import{execFile as Su,execFileSync as xu}from"child_process";import{closeSync as _u,existsSync as Be,mkdirSync as Ei,mkdtempSync as Iu,openSync as Ru,readFileSync as Cu,renameSync as Ze,rmSync as et,writeFileSync as Di}from"fs";import{cpus as vu}from"os";import{basename as Kt,dirname as je,extname as Nu,join as se}from"path";import{execFileSync as jt}from"child_process";import{platform as Bt,arch as Ya}from"os";var Vr=Bt()==="win32",Ur="v0.7.0";function At(e){let t=Vr?"where":"which";try{return jt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Tn(){try{return jt(Vr?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function Xa(){let e=Bt(),t=Ya(),n,r,i;switch(e){case"darwin":n="darwin",i="tar.gz";break;case"linux":n="linux",i="tar.gz";break;case"win32":n="windows",i="zip";break;default:return null}switch(t){case"arm64":r="arm64";break;case"x64":r="amd64";break;default:return null}let s=`scip-${n}-${r}.${i}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${Ur}/${s}`,filename:s}}function $n(){let e=Xa();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
2
+ var Ga=Object.defineProperty;var Ka=(e,t)=>{for(var n in t)Ga(e,n,{get:t[n],enumerable:!0})};import{program as S}from"commander";import{createRequire as ES}from"module";import{existsSync as qa,realpathSync as za}from"fs";import{fileURLToPath as DS}from"url";import{readFileSync as Ya,writeFileSync as Qa,existsSync as jr,mkdirSync as Xa}from"fs";import{join as $e,resolve as Ar}from"path";import{createHash as Za}from"crypto";import{homedir as el}from"os";var Br=".scipquery.json",tl={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function ve(e){let t=$e(e,Br);if(!jr(t))return{};try{let n=Ya(t,"utf-8");return JSON.parse(n)}catch{return{}}}function Wr(e){return{...tl,...e.watch}}function nl(e,t){let n=process.env.SCIP_QUERY_CACHE_DIR;if(n)return Mn(n);if(t?.dbPath)return Mn(Ar(e,t.dbPath));let i=process.env.XDG_CACHE_HOME||$e(el(),".cache"),s=Za("sha256").update(Ar(e)).digest("hex").slice(0,12),o=$e(i,"scip-query","projects",s);return Mn(o)}function Ne(e,t){let n=nl(e,t);return{cacheDir:n,dbPath:$e(n,"index.db"),indexPath:$e(n,"index.scip"),metaPath:$e(n,"meta.json")}}function Hr(e,t){let n=$e(e,Br);return jr(n)||Qa(n,JSON.stringify({languages:t,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
3
+ `),n}function Mn(e){return Xa(e,{recursive:!0}),e}import{execFile as Nu,execFileSync as Eu}from"child_process";import{closeSync as Du,existsSync as We,mkdirSync as Di,mkdtempSync as Lu,openSync as ku,readFileSync as wu,renameSync as Ze,rmSync as et,writeFileSync as Li}from"fs";import{cpus as Pu}from"os";import{basename as Kt,dirname as Be,extname as Ou,join as se}from"path";import{execFileSync as jt}from"child_process";import{platform as Bt,arch as rl}from"os";var Vr=Bt()==="win32",Ur="v0.7.0";function At(e){let t=Vr?"where":"which";try{return jt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Fn(){try{return jt(Vr?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function il(){let e=Bt(),t=rl(),n,r,i;switch(e){case"darwin":n="darwin",i="tar.gz";break;case"linux":n="linux",i="tar.gz";break;case"win32":n="windows",i="zip";break;default:return null}switch(t){case"arm64":r="arm64";break;case"x64":r="amd64";break;default:return null}let s=`scip-${n}-${r}.${i}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${Ur}/${s}`,filename:s}}function Tn(){let e=il();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
4
4
  `),console.log("Or download manually:")):console.log("Download from:"),console.log(e?` ${e.url}
5
5
  `:` https://github.com/sourcegraph/scip/releases/tag/${Ur}
6
- `),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function Jr(e){if(Bt()==="darwin"&&At("brew")){e("Installing scip CLI via Homebrew...");try{if(jt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`Homebrew install failed: ${n}`)}}if(At("go")){e("Installing scip CLI via go install...");try{if(jt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`go install failed: ${n}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import dl from"better-sqlite3";import{execFileSync as ml}from"child_process";import{existsSync as pl,readdirSync as fl,readFileSync as gl}from"fs";import{extname as Ht,join as Qr}from"path";import Za from"ignore";import{readFileSync as el,existsSync as An}from"fs";import{dirname as jn,isAbsolute as qr,join as Bn,relative as tl,resolve as nl}from"path";function Qe(e){let t=Za(),n=!1,r=rl(e);for(let i of r)try{let s=el(i,"utf-8");t.add(s),n=!0}catch{}return n||t.add(il),{isIgnored:i=>zr(t,e,i),filter:i=>i.filter(s=>!zr(t,e,s))}}function rl(e){let t=[],n=Bn(e,".gitignore");An(n)&&t.push(n);let r=jn(e),i=0;for(;r!==jn(r)&&i<5;){let s=Bn(r,".gitignore");if(An(s)&&t.push(s),An(Bn(r,".git")))break;r=jn(r),i++}return t}var il=`
6
+ `),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function Jr(e){if(Bt()==="darwin"&&At("brew")){e("Installing scip CLI via Homebrew...");try{if(jt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`Homebrew install failed: ${n}`)}}if(At("go")){e("Installing scip CLI via go install...");try{if(jt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`go install failed: ${n}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import bl from"better-sqlite3";import{execFileSync as Sl}from"child_process";import{existsSync as xl,readdirSync as _l,readFileSync as Il}from"fs";import{extname as Ht,join as Qr}from"path";import sl from"ignore";import{readFileSync as ol,existsSync as $n}from"fs";import{dirname as An,isAbsolute as qr,join as jn,relative as al,resolve as ll}from"path";function Ye(e){let t=sl(),n=!1,r=cl(e);for(let i of r)try{let s=ol(i,"utf-8");t.add(s),n=!0}catch{}return n||t.add(ul),{isIgnored:i=>zr(t,e,i),filter:i=>i.filter(s=>!zr(t,e,s))}}function cl(e){let t=[],n=jn(e,".gitignore");$n(n)&&t.push(n);let r=An(e),i=0;for(;r!==An(r)&&i<5;){let s=jn(r,".gitignore");if($n(s)&&t.push(s),$n(jn(r,".git")))break;r=An(r),i++}return t}var ul=`
7
7
  # Dependencies
8
8
  node_modules/
9
9
  vendor/
@@ -60,15 +60,15 @@ Thumbs.db
60
60
 
61
61
  # Type definitions (often noise in queries)
62
62
  *.d.ts
63
- `;function zr(e,t,n){let r=sl(t,n);if(!r)return!1;try{return e.ignores(r)}catch{return!1}}function sl(e,t){if(!t||t===".")return null;if(!qr(t)&&!t.startsWith(".."))return t.replaceAll("\\","/");let n=qr(t)?t:nl(e,t),r=tl(e,n).replaceAll("\\","/");return!r||r==="."||r.startsWith("..")?null:r}import{readdirSync as ol}from"fs";import{extname as Gr,join as al}from"path";function $(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s){let o=n(r);if(o.has(i))return o.get(i);let a=s();return o.set(i,a),a},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)},size(r){return t.get(r)?.size??0}}}function $e(e){let t=new WeakMap;return{get(n,r){let i=t.get(n);if(i)return i.value;let s=r();return t.set(n,{value:s}),s},invalidate(n){t.delete(n)},has(n){return t.has(n)}}}function Wt(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s,o){let a=n(r),l=a.get(i);if(l&&l.source===s)return l.value;let c=o();return a.set(i,{source:s,value:c}),c},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)}}}var ll=[".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"],Kr=[".vue"],Wn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Ne(e,t={}){let n=t.includeIndexed??!0,r=t.includeAuxiliary??!0,i=t.extensions?new Set(t.extensions.map(o=>o.toLowerCase())):new Set(ll.map(o=>o.toLowerCase())),s=`${n?"1":"0"}|${r?"1":"0"}|${[...i].sort().join(",")}`;return cl.get(e,s,()=>{let o=new Set;if(n){let a=e.all(`SELECT relative_path
63
+ `;function zr(e,t,n){let r=dl(t,n);if(!r)return!1;try{return e.ignores(r)}catch{return!1}}function dl(e,t){if(!t||t===".")return null;if(!qr(t)&&!t.startsWith(".."))return t.replaceAll("\\","/");let n=qr(t)?t:ll(e,t),r=al(e,n).replaceAll("\\","/");return!r||r==="."||r.startsWith("..")?null:r}import{readdirSync as ml}from"fs";import{extname as Gr,join as pl}from"path";function $(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s){let o=n(r);if(o.has(i))return o.get(i);let a=s();return o.set(i,a),a},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)},size(r){return t.get(r)?.size??0}}}function Ae(e){let t=new WeakMap;return{get(n,r){let i=t.get(n);if(i)return i.value;let s=r();return t.set(n,{value:s}),s},invalidate(n){t.delete(n)},has(n){return t.has(n)}}}function Wt(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s,o){let a=n(r),l=a.get(i);if(l&&l.source===s)return l.value;let c=o();return a.set(i,{source:s,value:c}),c},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)}}}var fl=[".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"],Kr=[".vue"],Yr=new Set(fl.map(e=>e.toLowerCase())),gl=[...Yr].sort().join(","),Bn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Ee(e,t={}){let n=t.includeIndexed??!0,r=t.includeAuxiliary??!0,i=t.extensions?.map(l=>l.toLowerCase()),s=i?new Set(i):Yr,o=i?[...s].sort().join(","):gl,a=`${n?"1":"0"}|${r?"1":"0"}|${o}`;return hl.get(e,a,()=>{let l=new Set;if(n){let c=e.all(`SELECT relative_path
64
64
  FROM documents
65
65
  WHERE 1 = 1
66
- ${e.pathExclusionsFor("documents")}`);for(let l of a)e.isIgnored(l.relative_path)||i.has(Gr(l.relative_path).toLowerCase())&&o.add(l.relative_path)}if(r)for(let a of ul(e.config.projectRoot,i))e.isIgnored(a)||o.add(a);return[...o].sort()})}var cl=$("source-files");function ul(e,t){let n=new Set,r=i=>{let s=i?al(e,i):e,o;try{o=ol(s,{withFileTypes:!0})}catch{return}for(let a of o)if(!Wn.has(a.name)){if(a.isDirectory()){r(i?`${i}/${a.name}`:a.name);continue}t.has(Gr(a.name).toLowerCase())&&n.add(i?`${i}/${a.name}`:a.name)}};return r(""),n}function Ee(e){let t=new Set((e.extensions??Kr).map(s=>s.toLowerCase()));if(t.size===0)return{scanned:0,inserted:0,existing:0};if(!pl(e.dbPath))throw new Error(`SCIP SQLite database not found at ${e.dbPath}`);let n=Qe(e.projectRoot),r=hl(e.projectRoot,t).filter(s=>!n.isIgnored(s)),i=new dl(e.dbPath);try{let s=bl(i,r),o=i.prepare(`INSERT OR IGNORE INTO documents (language, relative_path, position_encoding, text)
67
- VALUES (?, ?, NULL, ?)`),l=i.transaction(d=>{let u=0;for(let m of d){if(s.has(m))continue;let f=gl(Qr(e.projectRoot,m),"utf-8"),p=o.run(Sl(m),m,f);u+=Number(p.changes)}return u})(r),c={scanned:r.length,inserted:l,existing:r.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 hl(e,t){let n=yl(e,t);if(n)return n;let r=[],i=s=>{let o=s?Qr(e,s):e,a;try{a=fl(o,{withFileTypes:!0})}catch{return}for(let l of a){if(Wn.has(l.name))continue;let c=s?`${s}/${l.name}`:l.name;if(l.isDirectory()){i(c);continue}t.has(Ht(l.name).toLowerCase())&&r.push(c)}};return i(""),r.sort()}function yl(e,t){try{return ml("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}).split(`
68
- `).filter(r=>r&&t.has(Ht(r).toLowerCase())).sort()}catch{return null}}function bl(e,t){let n=new Set,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT relative_path FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.add(a.relative_path)}return n}function Sl(e){return Ht(e).toLowerCase()===".vue"?"vue":Ht(e).replace(/^\./,"").toLowerCase()||"source"}import{execFileSync as xl}from"child_process";import{existsSync as _l,readdirSync as Xr}from"fs";import{extname as Zr,join as ei}from"path";var Il=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),Rl=[{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 Ae(e){let t=[],n=Cl(e),r=Dl(e);for(let i of Rl){if(vl(e,i.files)){t.push(i.language);continue}if(Nl(n,i.globs)){t.push(i.language);continue}kl(r,i.extensions)&&t.push(i.language)}return t.includes("typescript")&&Yr(t,"javascript"),t.includes("cpp")&&!r.has(".c")&&Yr(t,"c"),t}function Cl(e){try{return Xr(e)}catch{return[]}}function vl(e,t){return t?.length?t.some(n=>_l(ei(e,n))):!1}function Nl(e,t){return t?.length?e.some(n=>t.some(r=>El(n,r))):!1}function El(e,t){if(t==="*")return!0;if(!t.includes("*"))return e===t;let[n,r]=t.split("*");return e.startsWith(n??"")&&e.endsWith(r??"")}function Dl(e){let t=Ll(e);if(t)return t;let n=new Set,r=[e];for(;r.length>0;){let i=r.pop();if(!i)continue;let s;try{s=Xr(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=ei(i,o.name);if(o.isDirectory()){Il.has(o.name)||r.push(a);continue}let l=Zr(o.name).toLowerCase();l&&n.add(l)}}return n}function Ll(e){try{let t=xl("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}),n=new Set;for(let r of t.split(`
69
- `)){if(!r)continue;let i=Zr(r).toLowerCase();i&&n.add(i)}return n}catch{return null}}function kl(e,t){return t?.length?t.some(n=>e.has(n)):!1}function Yr(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}import{existsSync as ti,readdirSync as wl}from"fs";import{join as Hn}from"path";var Pl={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:t,indexerBinary:n})=>{let r=["index","--infer-tsconfig","--output",e,"--no-progress-bar"];return t&&r.splice(1,0,"--pnpm-workspaces"),{binary:n,args:r}},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,indexerBinary:t})=>({binary:t,args:["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-plus",binaryAliases:["scip-python"],checkCommand:"scip-python-plus --version",indexArgs:({outputPath:e,indexerBinary:t})=>({binary:t,args:["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:t})=>({binary:"scip-dotnet",args:["index",ni(e,[".sln",".csproj"])??e,"--output",t,"--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:t})=>({binary:"scip-dotnet",args:["index",ni(e,[".sln",".vbproj"])??e,"--output",t,"--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:t})=>({binary:e,args:["--output",t]}),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:t})=>{let n=Hn(e,"vendor","bin","scip-php"),r=Hn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",ti(r)?r:ti(n)?n:t]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function Vt(e){return Pl[e]}function ni(e,t){let n;try{n=wl(e)}catch{return null}for(let r of n)if(t.some(i=>r.endsWith(i)))return Hn(e,r);return null}import{readFileSync as Ol,writeFileSync as Ml}from"fs";import{create as Vn}from"@bufbuild/protobuf";import{deserializeSCIP as Fl,serializeSCIP as Tl,DocumentSchema as $l,IndexSchema as Al,SymbolInformationSchema as jl}from"@c4312/scip";function Bl(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let t=Wl(e),n=Hl(e.flatMap(i=>i.documents??[])),r=ii(e.flatMap(i=>i.externalSymbols??[]));return Vn(Al,{metadata:t,documents:n,externalSymbols:r})}function ri(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let n=e.map(i=>Fl(Ol(i))),r=Bl(n);return Ml(t,Buffer.from(Tl(r))),{documentCount:r.documents.length,externalSymbolCount:r.externalSymbols.length,inputCount:e.length}}function Wl(e){let t=e[0]?.metadata;if(!t)return;let n=t.projectRoot;for(let r of e.slice(1)){let i=r.metadata?.projectRoot;if(n&&i&&i!==n)throw new Error(`Cannot merge SCIP indexes with different project roots: ${n} vs ${i}`)}return t}function Hl(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);if(!r){t.set(n.relativePath,n);continue}t.set(n.relativePath,Vn($l,{language:r.language||n.language,relativePath:r.relativePath||n.relativePath,occurrences:[...r.occurrences,...n.occurrences],symbols:ii([...r.symbols,...n.symbols]),text:Ul(r.text,n.text),positionEncoding:r.positionEncoding||n.positionEncoding}))}return[...t.values()]}function ii(e){let t=new Map;for(let n of e){let r=t.get(n.symbol);if(!r){t.set(n.symbol,n);continue}t.set(n.symbol,Vn(jl,{symbol:r.symbol,documentation:Jl([...r.documentation,...n.documentation]),relationships:Vl([...r.relationships,...n.relationships]),kind:r.kind||n.kind,displayName:r.displayName||n.displayName,enclosingSymbol:r.enclosingSymbol||n.enclosingSymbol,signatureDocumentation:r.signatureDocumentation??n.signatureDocumentation}))}return[...t.values()]}function Vl(e){let t=new Set,n=[];for(let r of e){let i=[r.symbol,r.isReference?"1":"0",r.isImplementation?"1":"0",r.isTypeDefinition?"1":"0",r.isDefinition?"1":"0"].join("|");t.has(i)||(t.add(i),n.push(r))}return n}function Ul(e,t){return e?t?e.length>=t.length?e:t:e:t}function Jl(e){return[...new Set(e)]}import{execFileSync as ql}from"child_process";import{createHash as zl}from"crypto";import{readdirSync as Gl,readFileSync as Kl}from"fs";import{join as si}from"path";function Ql(e){return(Yl(e)??Xl(e)).filter(t=>t&&!oi(t)).sort()}function Ut(e){return Ql(e).map(t=>{let n=si(e,t);try{let r=Kl(n);return{path:t,size:r.byteLength,hash:zl("sha256").update(r).digest("hex")}}catch{return{path:t,size:-1,hash:"unreadable"}}})}function Yl(e){try{return ql("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:50*1024*1024,stdio:["ignore","pipe","ignore"]}).split(`
70
- `).filter(Boolean)}catch{return null}}function Xl(e){let t=[],n=[""];for(;n.length>0;){let r=n.pop(),i=r?si(e,r):e,s;try{s=Gl(i,{withFileTypes:!0})}catch{continue}for(let o of s){let a=r?`${r}/${o.name}`:o.name;if(o.isDirectory()){oi(a)||n.push(a);continue}t.push(a)}}return t}function oi(e){return e.split("/").some(n=>Zl.has(n))||e.endsWith(".db")||e.endsWith(".db-wal")||e.endsWith(".db-shm")||e.endsWith(".scip")}var Zl=new Set([".git","node_modules",".scipquery-cache",".stryker-tmp","dist","build","coverage",".next",".nuxt","target"]);import{readFileSync as ec,writeFileSync as tc}from"fs";import{create as ai}from"@bufbuild/protobuf";import{deserializeSCIP as nc,DocumentSchema as rc,IndexSchema as ic,serializeSCIP as sc,SymbolRole as oc}from"@c4312/scip";function li(e){let t;try{t=nc(ec(e))}catch{return{removedDefinitionOccurrences:0,touchedDocuments:0}}let n=ac(t);return n.removedDefinitionOccurrences>0&&tc(e,Buffer.from(sc(n.index))),{removedDefinitionOccurrences:n.removedDefinitionOccurrences,touchedDocuments:n.touchedDocuments}}function ac(e){let t=new Set;for(let s of e.documents)for(let o of s.symbols)o.symbol&&t.add(o.symbol);for(let s of e.externalSymbols)s.symbol&&t.add(s.symbol);let n=0,r=0,i=[];for(let s of e.documents){let o=s.occurrences.filter(a=>(a.symbolRoles&oc.Definition)===0||t.has(a.symbol)?!0:(n+=1,!1));if(o.length===s.occurrences.length){i.push(s);continue}r+=1,i.push(ai(rc,{language:s.language,relativePath:s.relativePath,occurrences:o,symbols:s.symbols,text:s.text,positionEncoding:s.positionEncoding}))}return{index:n===0?e:ai(ic,{metadata:e.metadata,documents:i,externalSymbols:e.externalSymbols}),removedDefinitionOccurrences:n,touchedDocuments:r}}import{execFileSync as qt}from"child_process";import{existsSync as Un,readFileSync as lc}from"fs";import{createRequire as cc}from"module";import{platform as ui}from"os";import{dirname as ci,join as Jt}from"path";var uc=cc(import.meta.url),dc=ui()==="win32";function pt(e){let t=dc?"where":"which";try{return qt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Jn(e){return[e.indexerBinary,...e.binaryAliases??[]]}function zt(e){let t=Jn(e);return t.length===1?t[0]:t.join(" or ")}function Ye(e){for(let t of Jn(e))if(pt(t))return t;return pc(e)}function di(e){return Ye(e)!==null||mc(e)}function mc(e){return mi(e)!==null}function pc(e){let t=mi(e);if(!t)return null;let r=JSON.parse(lc(t,"utf8")).bin;if(!r)return null;if(typeof r=="string")return Jt(ci(t),r);for(let i of Jn(e)){let s=r[i];if(s)return Jt(ci(t),s)}return null}function mi(e){if(!e.bundledNpmPackage)return null;try{return uc.resolve(`${e.bundledNpmPackage}/package.json`)}catch{return null}}function qn(e,t){for(let n of e.projectLocalBinaries??[]){let r=Jt(t,n);if(Un(r))return r}return null}function fc(e,t){return qn(e,t)??Ye(e)}function pi(e,t=process.env,n=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||zn(n,t))return t;let r=hi(n,t);return r?{...t,DOTNET_ROOT:r}:t}function fi(e,t){let n=zt(e),r=t?fc(e,t):Ye(e);if(!r)return{language:e.language,binaryLabel:n,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:n,installed:!0,runnable:!0,resolvedBinary:r};let i=gc(r);return{language:e.language,binaryLabel:n,installed:!0,runnable:i.runnable,resolvedBinary:r,installUrl:e.installUrl,note:i.note}}function gi(e,t){let n=e.installMethods,r=zt(e);if(!n?.length)return t(`No auto-install method available for ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1;for(let i of n)if(pt(i.prerequisite)){t(`Installing ${r} via ${i.label}...`);try{qt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let s=Ye(e);if(s){let o=s===e.indexerBinary?"":` (using ${s})`;return t(`Successfully installed ${r} via ${i.label}${o}`),!0}t(`${i.label} command completed but ${r} was not found on PATH`)}catch(s){let o=s instanceof Error?s.message:String(s);t(`${i.label} install failed: ${o}`)}}return t(`Could not auto-install ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1}function gc(e){if(zn(e,process.env))return{runnable:!0};let t=hi(e,process.env);if(t)return{runnable:!0,note:`using .NET 9 runtime from ${t}`};let n=yi(process.env);return{runnable:!1,note:n.length>0?`.NET 9 runtime still unavailable after checking ${n.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function hi(e,t){for(let n of yi(t))if(zn(e,{...t,DOTNET_ROOT:n}))return n;return null}function yi(e){let t=[],n=e.DOTNET_ROOT;if(n&&Un(n)&&t.push(n),ui()==="darwin"&&pt("brew"))try{let r=qt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Jt(r,"libexec");Un(i)&&!t.includes(i)&&t.push(i)}catch{}return t}function zn(e,t){try{return qt(e,["--version"],{stdio:"pipe",env:t}),!0}catch{return!1}}import hc from"better-sqlite3";import{createRequire as yc}from"module";import{existsSync as Si,mkdtempSync as bc,readFileSync as ft,rmSync as Sc,statSync as xc,writeFileSync as _c}from"fs";import{cpus as Ic,tmpdir as Rc}from"os";import{dirname as Kn,extname as Cc,join as Xe,relative as vc,resolve as xi}from"path";import{pathToFileURL as Nc}from"url";import{Worker as Ec}from"worker_threads";function Qn(e){Ee({projectRoot:e.projectRoot,dbPath:e.dbPath});let t=xi(e.projectRoot,e.tsconfig);if(!Si(t))throw new Error(`Vue tsconfig not found at ${t}`);let n=new hc(e.dbPath);try{let r=Kc(n,e.projectRoot),i=Xe(Kn(e.dbPath),"augment-vue-meta.json"),s=bi(n,e.projectRoot,e.tsconfig),o=Dc(i,s,e.onStatus);if(o)return o;let a=iu(n,e.projectRoot,r),l=Lc(n,e,t,r,a),c=lu(l.occurrences),d=kc(n,e,r,a,c);e.onStatus?.(`Resolved ${c.length} Vue references with Volar; inserted ${d} mentions.`);let u=wc(r,c,d,l,a);return Oc(i,bi(n,e.projectRoot,e.tsconfig),u),u}finally{n.close()}}function Dc(e,t,n){let r=Pc(e,t);return r&&n?.(`Vue references unchanged; reused ${r.resolvedReferences} cached resolved references.`),r}function Lc(e,t,n,r,i){if(Wc(r))return Hc({projectRoot:t.projectRoot,dbPath:t.dbPath,tsconfig:t.tsconfig,vueFiles:r});let s=fu(),o=Qc(t.projectRoot,n);return Mc({projectRoot:t.projectRoot,vueFiles:o.fileNames.filter(a=>a.endsWith(".vue")),context:o,symbolLookup:tu(e,t.projectRoot,s),vueSymbolLookup:i,sourceCache:s})}function kc(e,t,n,r,i){return su(e,t.projectRoot,n,r,i)}function wc(e,t,n,r,i){return{vueFiles:e.length,resolvedReferences:t.length,insertedMentions:n,skippedReferences:r.skippedReferences,syntheticSymbols:i.syntheticSymbols}}function Pc(e,t){try{let n=JSON.parse(ft(e,"utf-8"));return JSON.stringify(n.fingerprint)===JSON.stringify(t)?n.result:null}catch{return null}}function Oc(e,t,n){_c(e,JSON.stringify({updatedAt:new Date().toISOString(),fingerprint:t,result:n},null,2)+`
71
- `)}function bi(e,t,n){let r=e.prepare(`
66
+ ${e.pathExclusionsFor("documents")}`);for(let u of c)e.isIgnored(u.relative_path)||s.has(Gr(u.relative_path).toLowerCase())&&l.add(u.relative_path)}if(r)for(let c of yl(e.config.projectRoot,s))e.isIgnored(c)||l.add(c);return[...l].sort()})}var hl=$("source-files");function yl(e,t){let n=new Set,r=i=>{let s=i?pl(e,i):e,o;try{o=ml(s,{withFileTypes:!0})}catch{return}for(let a of o)if(!Bn.has(a.name)){if(a.isDirectory()){r(i?`${i}/${a.name}`:a.name);continue}t.has(Gr(a.name).toLowerCase())&&n.add(i?`${i}/${a.name}`:a.name)}};return r(""),n}function De(e){let t=new Set((e.extensions??Kr).map(s=>s.toLowerCase()));if(t.size===0)return{scanned:0,inserted:0,existing:0};if(!xl(e.dbPath))throw new Error(`SCIP SQLite database not found at ${e.dbPath}`);let n=Ye(e.projectRoot),r=Rl(e.projectRoot,t).filter(s=>!n.isIgnored(s)),i=new bl(e.dbPath);try{let s=vl(i,r),o=i.prepare(`INSERT OR IGNORE INTO documents (language, relative_path, position_encoding, text)
67
+ VALUES (?, ?, NULL, ?)`),l=i.transaction(u=>{let d=0;for(let m of u){if(s.has(m))continue;let g=Il(Qr(e.projectRoot,m),"utf-8"),p=o.run(Nl(m),m,g);d+=Number(p.changes)}return d})(r),c={scanned:r.length,inserted:l,existing:r.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 Rl(e,t){let n=Cl(e,t);if(n)return n;let r=[],i=s=>{let o=s?Qr(e,s):e,a;try{a=_l(o,{withFileTypes:!0})}catch{return}for(let l of a){if(Bn.has(l.name))continue;let c=s?`${s}/${l.name}`:l.name;if(l.isDirectory()){i(c);continue}t.has(Ht(l.name).toLowerCase())&&r.push(c)}};return i(""),r.sort()}function Cl(e,t){try{return Sl("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}).split(`
68
+ `).filter(r=>r&&t.has(Ht(r).toLowerCase())).sort()}catch{return null}}function vl(e,t){let n=new Set,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT relative_path FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.add(a.relative_path)}return n}function Nl(e){return Ht(e).toLowerCase()===".vue"?"vue":Ht(e).replace(/^\./,"").toLowerCase()||"source"}import{execFileSync as El}from"child_process";import{existsSync as Dl,readdirSync as Zr}from"fs";import{extname as ei,join as ti}from"path";var Ll=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),kl=[{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 t=[],n=wl(e),r=Fl(e);for(let i of kl){if(Pl(e,i.files)){t.push(i.language);continue}if(Ol(n,i.globs)){t.push(i.language);continue}$l(r,i.extensions)&&t.push(i.language)}return t.includes("typescript")&&Xr(t,"javascript"),t.includes("cpp")&&!r.has(".c")&&Xr(t,"c"),t}function wl(e){try{return Zr(e)}catch{return[]}}function Pl(e,t){return t?.length?t.some(n=>Dl(ti(e,n))):!1}function Ol(e,t){return t?.length?e.some(n=>t.some(r=>Ml(n,r))):!1}function Ml(e,t){if(t==="*")return!0;if(!t.includes("*"))return e===t;let[n,r]=t.split("*");return e.startsWith(n??"")&&e.endsWith(r??"")}function Fl(e){let t=Tl(e);if(t)return t;let n=new Set,r=[e];for(;r.length>0;){let i=r.pop();if(!i)continue;let s;try{s=Zr(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=ti(i,o.name);if(o.isDirectory()){Ll.has(o.name)||r.push(a);continue}let l=ei(o.name).toLowerCase();l&&n.add(l)}}return n}function Tl(e){try{let t=El("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}),n=new Set;for(let r of t.split(`
69
+ `)){if(!r)continue;let i=ei(r).toLowerCase();i&&n.add(i)}return n}catch{return null}}function $l(e,t){return t?.length?t.some(n=>e.has(n)):!1}function Xr(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}import{existsSync as ni,readdirSync as Al}from"fs";import{join as Wn}from"path";var jl={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:t,indexerBinary:n})=>{let r=["index","--infer-tsconfig","--output",e,"--no-progress-bar"];return t&&r.splice(1,0,"--pnpm-workspaces"),{binary:n,args:r}},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,indexerBinary:t})=>({binary:t,args:["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-plus",binaryAliases:["scip-python"],checkCommand:"scip-python-plus --version",indexArgs:({outputPath:e,indexerBinary:t})=>({binary:t,args:["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:t})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".csproj"])??e,"--output",t,"--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:t})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".vbproj"])??e,"--output",t,"--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:t})=>({binary:e,args:["--output",t]}),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:t})=>{let n=Wn(e,"vendor","bin","scip-php"),r=Wn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",ni(r)?r:ni(n)?n:t]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function Vt(e){return jl[e]}function ri(e,t){let n;try{n=Al(e)}catch{return null}for(let r of n)if(t.some(i=>r.endsWith(i)))return Wn(e,r);return null}import{readFileSync as Bl,writeFileSync as Wl}from"fs";import{create as Hn}from"@bufbuild/protobuf";import{deserializeSCIP as Hl,serializeSCIP as Vl,DocumentSchema as Ul,IndexSchema as Jl,SymbolInformationSchema as ql}from"@c4312/scip";function zl(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let t=Gl(e),n=Kl(e.flatMap(i=>i.documents??[])),r=si(e.flatMap(i=>i.externalSymbols??[]));return Hn(Jl,{metadata:t,documents:n,externalSymbols:r})}function ii(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let n=e.map(i=>Hl(Bl(i))),r=zl(n);return Wl(t,Buffer.from(Vl(r))),{documentCount:r.documents.length,externalSymbolCount:r.externalSymbols.length,inputCount:e.length}}function Gl(e){let t=e[0]?.metadata;if(!t)return;let n=t.projectRoot;for(let r of e.slice(1)){let i=r.metadata?.projectRoot;if(n&&i&&i!==n)throw new Error(`Cannot merge SCIP indexes with different project roots: ${n} vs ${i}`)}return t}function Kl(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);if(!r){t.set(n.relativePath,n);continue}t.set(n.relativePath,Hn(Ul,{language:r.language||n.language,relativePath:r.relativePath||n.relativePath,occurrences:[...r.occurrences,...n.occurrences],symbols:si([...r.symbols,...n.symbols]),text:Ql(r.text,n.text),positionEncoding:r.positionEncoding||n.positionEncoding}))}return[...t.values()]}function si(e){let t=new Map;for(let n of e){let r=t.get(n.symbol);if(!r){t.set(n.symbol,n);continue}t.set(n.symbol,Hn(ql,{symbol:r.symbol,documentation:Xl([...r.documentation,...n.documentation]),relationships:Yl([...r.relationships,...n.relationships]),kind:r.kind||n.kind,displayName:r.displayName||n.displayName,enclosingSymbol:r.enclosingSymbol||n.enclosingSymbol,signatureDocumentation:r.signatureDocumentation??n.signatureDocumentation}))}return[...t.values()]}function Yl(e){let t=new Set,n=[];for(let r of e){let i=[r.symbol,r.isReference?"1":"0",r.isImplementation?"1":"0",r.isTypeDefinition?"1":"0",r.isDefinition?"1":"0"].join("|");t.has(i)||(t.add(i),n.push(r))}return n}function Ql(e,t){return e?t?e.length>=t.length?e:t:e:t}function Xl(e){return[...new Set(e)]}import{execFileSync as Zl}from"child_process";import{createHash as ec}from"crypto";import{readdirSync as tc,readFileSync as nc}from"fs";import{join as oi}from"path";function rc(e){return(ic(e)??sc(e)).filter(t=>t&&!ai(t)).sort()}function Ut(e){return rc(e).map(t=>{let n=oi(e,t);try{let r=nc(n);return{path:t,size:r.byteLength,hash:ec("sha256").update(r).digest("hex")}}catch{return{path:t,size:-1,hash:"unreadable"}}})}function ic(e){try{return Zl("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:50*1024*1024,stdio:["ignore","pipe","ignore"]}).split(`
70
+ `).filter(Boolean)}catch{return null}}function sc(e){let t=[],n=[""];for(;n.length>0;){let r=n.pop(),i=r?oi(e,r):e,s;try{s=tc(i,{withFileTypes:!0})}catch{continue}for(let o of s){let a=r?`${r}/${o.name}`:o.name;if(o.isDirectory()){ai(a)||n.push(a);continue}t.push(a)}}return t}function ai(e){return e.split("/").some(n=>oc.has(n))||e.endsWith(".db")||e.endsWith(".db-wal")||e.endsWith(".db-shm")||e.endsWith(".scip")}var oc=new Set([".git","node_modules",".scipquery-cache",".stryker-tmp","dist","build","coverage",".next",".nuxt","target"]);import{readFileSync as ac,writeFileSync as lc}from"fs";import{create as li}from"@bufbuild/protobuf";import{deserializeSCIP as cc,DocumentSchema as uc,IndexSchema as dc,serializeSCIP as mc,SymbolRole as pc}from"@c4312/scip";function ci(e){let t;try{t=cc(ac(e))}catch{return{removedDefinitionOccurrences:0,touchedDocuments:0}}let n=fc(t);return n.removedDefinitionOccurrences>0&&lc(e,Buffer.from(mc(n.index))),{removedDefinitionOccurrences:n.removedDefinitionOccurrences,touchedDocuments:n.touchedDocuments}}function fc(e){let t=new Set;for(let s of e.documents)for(let o of s.symbols)o.symbol&&t.add(o.symbol);for(let s of e.externalSymbols)s.symbol&&t.add(s.symbol);let n=0,r=0,i=[];for(let s of e.documents){let o=s.occurrences.filter(a=>(a.symbolRoles&pc.Definition)===0||t.has(a.symbol)?!0:(n+=1,!1));if(o.length===s.occurrences.length){i.push(s);continue}r+=1,i.push(li(uc,{language:s.language,relativePath:s.relativePath,occurrences:o,symbols:s.symbols,text:s.text,positionEncoding:s.positionEncoding}))}return{index:n===0?e:li(dc,{metadata:e.metadata,documents:i,externalSymbols:e.externalSymbols}),removedDefinitionOccurrences:n,touchedDocuments:r}}import{execFileSync as qt}from"child_process";import{existsSync as Vn,readFileSync as gc}from"fs";import{createRequire as hc}from"module";import{platform as di}from"os";import{dirname as ui,join as Jt}from"path";var yc=hc(import.meta.url),bc=di()==="win32";function mt(e){let t=bc?"where":"which";try{return qt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Un(e){return[e.indexerBinary,...e.binaryAliases??[]]}function zt(e){let t=Un(e);return t.length===1?t[0]:t.join(" or ")}function Qe(e){for(let t of Un(e))if(mt(t))return t;return xc(e)}function mi(e){return Qe(e)!==null||Sc(e)}function Sc(e){return pi(e)!==null}function xc(e){let t=pi(e);if(!t)return null;let r=JSON.parse(gc(t,"utf8")).bin;if(!r)return null;if(typeof r=="string")return Jt(ui(t),r);for(let i of Un(e)){let s=r[i];if(s)return Jt(ui(t),s)}return null}function pi(e){if(!e.bundledNpmPackage)return null;try{return yc.resolve(`${e.bundledNpmPackage}/package.json`)}catch{return null}}function Jn(e,t){for(let n of e.projectLocalBinaries??[]){let r=Jt(t,n);if(Vn(r))return r}return null}function _c(e,t){return Jn(e,t)??Qe(e)}function fi(e,t=process.env,n=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||qn(n,t))return t;let r=yi(n,t);return r?{...t,DOTNET_ROOT:r}:t}function gi(e,t){let n=zt(e),r=t?_c(e,t):Qe(e);if(!r)return{language:e.language,binaryLabel:n,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:n,installed:!0,runnable:!0,resolvedBinary:r};let i=Ic(r);return{language:e.language,binaryLabel:n,installed:!0,runnable:i.runnable,resolvedBinary:r,installUrl:e.installUrl,note:i.note}}function hi(e,t){let n=e.installMethods,r=zt(e);if(!n?.length)return t(`No auto-install method available for ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1;for(let i of n)if(mt(i.prerequisite)){t(`Installing ${r} via ${i.label}...`);try{qt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let s=Qe(e);if(s){let o=s===e.indexerBinary?"":` (using ${s})`;return t(`Successfully installed ${r} via ${i.label}${o}`),!0}t(`${i.label} command completed but ${r} was not found on PATH`)}catch(s){let o=s instanceof Error?s.message:String(s);t(`${i.label} install failed: ${o}`)}}return t(`Could not auto-install ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1}function Ic(e){if(qn(e,process.env))return{runnable:!0};let t=yi(e,process.env);if(t)return{runnable:!0,note:`using .NET 9 runtime from ${t}`};let n=bi(process.env);return{runnable:!1,note:n.length>0?`.NET 9 runtime still unavailable after checking ${n.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function yi(e,t){for(let n of bi(t))if(qn(e,{...t,DOTNET_ROOT:n}))return n;return null}function bi(e){let t=[],n=e.DOTNET_ROOT;if(n&&Vn(n)&&t.push(n),di()==="darwin"&&mt("brew"))try{let r=qt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Jt(r,"libexec");Vn(i)&&!t.includes(i)&&t.push(i)}catch{}return t}function qn(e,t){try{return qt(e,["--version"],{stdio:"pipe",env:t}),!0}catch{return!1}}import Rc from"better-sqlite3";import{createRequire as Cc}from"module";import{existsSync as xi,mkdtempSync as vc,readFileSync as pt,rmSync as Nc,statSync as Ec,writeFileSync as Dc}from"fs";import{cpus as Lc,tmpdir as kc}from"os";import{dirname as Gn,extname as wc,join as Xe,relative as Pc,resolve as _i}from"path";import{pathToFileURL as Oc}from"url";import{Worker as Mc}from"worker_threads";function Kn(e){De({projectRoot:e.projectRoot,dbPath:e.dbPath});let t=_i(e.projectRoot,e.tsconfig);if(!xi(t))throw new Error(`Vue tsconfig not found at ${t}`);let n=new Rc(e.dbPath);try{let r=nu(n,e.projectRoot),i=Xe(Gn(e.dbPath),"augment-vue-meta.json"),s=Si(n,e.projectRoot,e.tsconfig),o=Fc(i,s,e.onStatus);if(o)return o;let a=du(n,e.projectRoot,r),l=Tc(n,e,t,r,a),c=gu(l.occurrences),u=$c(n,e,r,a,c);e.onStatus?.(`Resolved ${c.length} Vue references with Volar; inserted ${u} mentions.`);let d=Ac(r,c,u,l,a);return Bc(i,Si(n,e.projectRoot,e.tsconfig),d),d}finally{n.close()}}function Fc(e,t,n){let r=jc(e,t);return r&&n?.(`Vue references unchanged; reused ${r.resolvedReferences} cached resolved references.`),r}function Tc(e,t,n,r,i){if(Gc(r))return Kc({projectRoot:t.projectRoot,dbPath:t.dbPath,tsconfig:t.tsconfig,vueFiles:r});let s=_u(),o=ru(t.projectRoot,n);return Wc({projectRoot:t.projectRoot,vueFiles:o.fileNames.filter(a=>a.endsWith(".vue")),context:o,symbolLookup:lu(e,t.projectRoot,s),vueSymbolLookup:i,sourceCache:s})}function $c(e,t,n,r,i){return mu(e,t.projectRoot,n,r,i)}function Ac(e,t,n,r,i){return{vueFiles:e.length,resolvedReferences:t.length,insertedMentions:n,skippedReferences:r.skippedReferences,syntheticSymbols:i.syntheticSymbols}}function jc(e,t){try{let n=JSON.parse(pt(e,"utf-8"));return JSON.stringify(n.fingerprint)===JSON.stringify(t)?n.result:null}catch{return null}}function Bc(e,t,n){Dc(e,JSON.stringify({updatedAt:new Date().toISOString(),fingerprint:t,result:n},null,2)+`
71
+ `)}function Si(e,t,n){let r=e.prepare(`
72
72
  SELECT
73
73
  (SELECT COUNT(*) FROM documents) AS documents,
74
74
  (SELECT COUNT(*) FROM global_symbols) AS symbols,
@@ -77,7 +77,7 @@ Thumbs.db
77
77
  (SELECT COUNT(*) FROM defn_enclosing_ranges) AS ranges,
78
78
  (SELECT MAX(id) FROM chunks) AS maxChunkId,
79
79
  (SELECT MAX(id) FROM global_symbols) AS maxSymbolId
80
- `).get();return{version:2,tsconfig:n,files:Ut(t),db:r}}function Mc(e){let t=[],n=0,r=e.tasks??e.vueFiles.map(i=>({fileName:i,startOffset:0,endOffset:Number.POSITIVE_INFINITY,countFileSkip:!0}));for(let i of r){let s=Fc(e,i);t.push(...s.occurrences),n+=s.skippedReferences}return{occurrences:t,skippedReferences:n}}function Fc(e,t){let n=e.context.language.scripts.get(t.fileName),r=n?.generated?.languagePlugin.typescript?.getServiceScript(n.generated.root)?.code;if(!n||!r)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let i=e.sourceCache(t.fileName);if(!i)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let s=e.context.language.maps.get(r,n),o=gt(e.projectRoot,t.fileName),a=[...uu(i.text)],l={tokens:a.filter(c=>c.start>=t.startOffset&&c.start<t.endOffset),tokenByStart:new Map(a.map(c=>[c.start,c])),tokenTextCounts:Ac(a),processedStarts:new Set};return Tc({...e,fileName:t.fileName,sourceInfo:i,sourceFile:o,map:s,tokenContext:l})}function Tc(e){let t=[],n=0;for(let r of e.tokenContext.tokens){if(e.tokenContext.processedStarts.has(r.start))continue;let i=du(e.map,r.start);if(i===null)continue;let o=(e.context.languageService.getDefinitionAtPosition(e.fileName,i+1)??[]).find(l=>!mu(e.projectRoot,l.fileName));if(!o){n++;continue}let a=au(o,e.symbolLookup,e.vueSymbolLookup,e.context,e.projectRoot);if(a===null){n++;continue}_i(t,e.sourceInfo,e.sourceFile,r,a),e.tokenContext.processedStarts.add(r.start),$c(t,e,r,i,a)}return{occurrences:t,skippedReferences:n}}function $c(e,t,n,r,i){if(!((t.tokenContext.tokenTextCounts.get(n.text)??0)<=1))for(let s of jc(t.context.languageService,t.fileName,r+1,t.map,n,t.tokenContext.tokenByStart)){if(t.tokenContext.processedStarts.has(s))continue;let o=t.tokenContext.tokenByStart.get(s);o&&(_i(e,t.sourceInfo,t.sourceFile,o,i),t.tokenContext.processedStarts.add(s))}}function _i(e,t,n,r,i){let s=Ni(t,r.start);e.push({sourceFile:n,sourceLine:s.line,sourceStartChar:s.character,sourceEndChar:s.character+r.text.length,symbolId:i})}function Ac(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return t}function jc(e,t,n,r,i,s){let o=e.getDocumentHighlights?.(t,n,[t])??[],a=[];for(let l of o)if(l.fileName===t)for(let c of l.highlightSpans){let d=Bc(r,c.textSpan.start,s,i.text);d!==null&&a.push(d)}return a}function Bc(e,t,n,r){let i=n.get(t);if(i?.text===r)return i.start;let s=vi(e,t);if(s===null)return null;let o=n.get(s);return o?.text===r?o.start:null}function Wc(e){return e.length>=8&&Ii(e.length)>1}function Hc(e){let t=Ii(e.vueFiles.length),n=Uc(e.vueFiles),r=qc(n,t),i=new URL("./augment-vue-worker.js",import.meta.url),s=bc(Xe(Rc(),"scip-query-vue-workers-")),o=new SharedArrayBuffer(4),a=new Int32Array(o),l=Vc(),c=Date.now();try{for(let u=0;u<r.length;u++)new Ec(i,{workerData:{projectRoot:e.projectRoot,dbPath:e.dbPath,tsconfig:e.tsconfig,tasks:r[u],resultPath:Xe(s,`${u}.json`),sharedBuffer:o}});for(;Atomics.load(a,0)<r.length;){if(Date.now()-c>l)throw new Error(`Vue reference workers timed out after ${(l/1e3).toFixed(0)}s`);Atomics.wait(a,0,Atomics.load(a,0),100)}let d=r.map((u,m)=>{let f=JSON.parse(ft(Xe(s,`${m}.json`),"utf-8"));if(!f.ok)throw new Error(`Vue reference worker failed: ${f.error}`);return f.result});return{occurrences:d.flatMap(u=>u.occurrences),skippedReferences:d.reduce((u,m)=>u+m.skippedReferences,0)}}finally{Sc(s,{recursive:!0,force:!0})}}function Ii(e){let t=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKERS??0),n=Number.isFinite(t)&&t>0?t:Math.min(8,Math.max(1,Ic().length-1));return Math.max(1,Math.min(e,n))}function Vc(){let e=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKER_TIMEOUT_MS??0);return Number.isFinite(e)&&e>0?e:3e5}function Uc(e){let t=Jc(),n=[];for(let r of e){let i=Ri(r),s=Math.max(1,Math.ceil(i/t));for(let o=0;o<s;o++)n.push({fileName:r,startOffset:Math.floor(i*o/s),endOffset:o===s-1?Number.POSITIVE_INFINITY:Math.floor(i*(o+1)/s),countFileSkip:o===0})}return n}function Jc(){return Number.POSITIVE_INFINITY}function qc(e,t){let n=Array.from({length:t},()=>({tasks:[],weight:0})),r=e.map(i=>({task:i,weight:zc(i)})).sort((i,s)=>s.weight-i.weight);for(let i of r){let s=n.reduce((o,a)=>a.weight<o.weight?a:o);s.tasks.push(i.task),s.weight+=i.weight}return n.map(i=>i.tasks).filter(i=>i.length>0)}function zc(e){return Number.isFinite(e.endOffset)?Math.max(1,e.endOffset-e.startOffset):Math.max(1,Ri(e.fileName)-e.startOffset)}function Ri(e){try{return xc(e).size}catch{return 1}}function Gc(e){e.transaction(()=>{e.prepare(`
80
+ `).get();return{version:2,tsconfig:n,files:Ut(t),db:r}}function Wc(e){let t=[],n=0,r=e.tasks??e.vueFiles.map(i=>({fileName:i,startOffset:0,endOffset:Number.POSITIVE_INFINITY,countFileSkip:!0}));for(let i of r){let s=Hc(e,i);t.push(...s.occurrences),n+=s.skippedReferences}return{occurrences:t,skippedReferences:n}}function Hc(e,t){let n=e.context.language.scripts.get(t.fileName),r=n?.generated?.languagePlugin.typescript?.getServiceScript(n.generated.root)?.code;if(!n||!r)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let i=e.sourceCache(t.fileName);if(!i)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let s=e.context.language.maps.get(r,n),o=ft(e.projectRoot,t.fileName),a=[...yu(i.text)],l={tokens:a.filter(c=>c.start>=t.startOffset&&c.start<t.endOffset),tokenByStart:new Map(a.map(c=>[c.start,c])),tokenTextCounts:Jc(a),processedStarts:new Set};return Vc({...e,fileName:t.fileName,sourceInfo:i,sourceFile:o,map:s,tokenContext:l})}function Vc(e){let t=[],n=0;for(let r of e.tokenContext.tokens){if(e.tokenContext.processedStarts.has(r.start))continue;let i=bu(e.map,r.start);if(i===null)continue;let o=(e.context.languageService.getDefinitionAtPosition(e.fileName,i+1)??[]).find(l=>!Su(e.projectRoot,l.fileName));if(!o){n++;continue}let a=fu(o,e.symbolLookup,e.vueSymbolLookup,e.context,e.projectRoot);if(a===null){n++;continue}Ii(t,e.sourceInfo,e.sourceFile,r,a),e.tokenContext.processedStarts.add(r.start),Uc(t,e,r,i,a)}return{occurrences:t,skippedReferences:n}}function Uc(e,t,n,r,i){if(!((t.tokenContext.tokenTextCounts.get(n.text)??0)<=1))for(let s of qc(t.context.languageService,t.fileName,r+1,t.map,n,t.tokenContext.tokenByStart)){if(t.tokenContext.processedStarts.has(s))continue;let o=t.tokenContext.tokenByStart.get(s);o&&(Ii(e,t.sourceInfo,t.sourceFile,o,i),t.tokenContext.processedStarts.add(s))}}function Ii(e,t,n,r,i){let s=Ei(t,r.start);e.push({sourceFile:n,sourceLine:s.line,sourceStartChar:s.character,sourceEndChar:s.character+r.text.length,symbolId:i})}function Jc(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return t}function qc(e,t,n,r,i,s){let o=e.getDocumentHighlights?.(t,n,[t])??[],a=[];for(let l of o)if(l.fileName===t)for(let c of l.highlightSpans){let u=zc(r,c.textSpan.start,s,i.text);u!==null&&a.push(u)}return a}function zc(e,t,n,r){let i=n.get(t);if(i?.text===r)return i.start;let s=Ni(e,t);if(s===null)return null;let o=n.get(s);return o?.text===r?o.start:null}function Gc(e){return e.length>=8&&Ri(e.length)>1}function Kc(e){let t=Ri(e.vueFiles.length),n=Qc(e.vueFiles),r=Zc(n,t),i=new URL("./augment-vue-worker.js",import.meta.url),s=vc(Xe(kc(),"scip-query-vue-workers-")),o=new SharedArrayBuffer(4),a=new Int32Array(o),l=Yc(),c=Date.now();try{for(let d=0;d<r.length;d++)new Mc(i,{workerData:{projectRoot:e.projectRoot,dbPath:e.dbPath,tsconfig:e.tsconfig,tasks:r[d],resultPath:Xe(s,`${d}.json`),sharedBuffer:o}});for(;Atomics.load(a,0)<r.length;){if(Date.now()-c>l)throw new Error(`Vue reference workers timed out after ${(l/1e3).toFixed(0)}s`);Atomics.wait(a,0,Atomics.load(a,0),100)}let u=r.map((d,m)=>{let g=JSON.parse(pt(Xe(s,`${m}.json`),"utf-8"));if(!g.ok)throw new Error(`Vue reference worker failed: ${g.error}`);return g.result});return{occurrences:u.flatMap(d=>d.occurrences),skippedReferences:u.reduce((d,m)=>d+m.skippedReferences,0)}}finally{Nc(s,{recursive:!0,force:!0})}}function Ri(e){let t=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKERS??0),n=Number.isFinite(t)&&t>0?t:Math.min(8,Math.max(1,Lc().length-1));return Math.max(1,Math.min(e,n))}function Yc(){let e=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKER_TIMEOUT_MS??0);return Number.isFinite(e)&&e>0?e:3e5}function Qc(e){let t=Xc(),n=[];for(let r of e){let i=Ci(r),s=Math.max(1,Math.ceil(i/t));for(let o=0;o<s;o++)n.push({fileName:r,startOffset:Math.floor(i*o/s),endOffset:o===s-1?Number.POSITIVE_INFINITY:Math.floor(i*(o+1)/s),countFileSkip:o===0})}return n}function Xc(){return Number.POSITIVE_INFINITY}function Zc(e,t){let n=Array.from({length:t},()=>({tasks:[],weight:0})),r=e.map(i=>({task:i,weight:eu(i)})).sort((i,s)=>s.weight-i.weight);for(let i of r){let s=n.reduce((o,a)=>a.weight<o.weight?a:o);s.tasks.push(i.task),s.weight+=i.weight}return n.map(i=>i.tasks).filter(i=>i.length>0)}function eu(e){return Number.isFinite(e.endOffset)?Math.max(1,e.endOffset-e.startOffset):Math.max(1,Ci(e.fileName)-e.startOffset)}function Ci(e){try{return Ec(e).size}catch{return 1}}function tu(e){e.transaction(()=>{e.prepare(`
81
81
  DELETE FROM mentions
82
82
  WHERE chunk_id IN (
83
83
  SELECT c.id
@@ -92,12 +92,12 @@ Thumbs.db
92
92
  FROM documents
93
93
  WHERE language = 'vue' OR relative_path LIKE '%.vue'
94
94
  )
95
- `).run()})()}function Kc(e,t){return e.prepare(`
95
+ `).run()})()}function nu(e,t){return e.prepare(`
96
96
  SELECT relative_path AS relativePath
97
97
  FROM documents
98
98
  WHERE language = 'vue' OR relative_path LIKE '%.vue'
99
99
  ORDER BY relative_path
100
- `).all().map(r=>xi(t,r.relativePath))}function Qc(e,t){let{vueCore:n,ts:r,volarTs:i}=Yc(e),{parsed:s,vueOptions:o}=Xc(n,r,t),a=Kn(t),l=n.createVueLanguagePlugin(r,s.options,o,f=>f),c=Zc(n,r,l),d=eu(a,s),{languageServiceHost:u}=i.createLanguageServiceHost(r,r.sys,c,f=>f,d),m=r.createLanguageService(u);return{ts:r,language:c,languageService:m,fileNames:s.fileNames,configDir:a}}function Yc(e){let t=yc(Nc(Xe(e,"package.json")).href);return{vueCore:Gn(t,"@vue/language-core",e),ts:Gn(t,"typescript",e),volarTs:Gn(t,"@volar/typescript",e)}}function Xc(e,t,n){let r=t.readConfigFile(n,t.sys.readFile);if(r.error||!r.config)throw new Error(`Failed to read ${n}`);let s=e.createParsedCommandLine(t,t.sys,n).vueOptions;return typeof e.createGlobalTypesWriter=="function"&&(s.globalTypesPath=e.createGlobalTypesWriter(s,t.sys.writeFile)),{parsed:t.parseJsonConfigFileContent(r.config,t.sys,Kn(n),void 0,n,void 0,e.getAllExtensions(s).map(o=>({extension:o.slice(1),isMixedContent:!0,scriptKind:t.ScriptKind.Deferred}))),vueOptions:s}}function Zc(e,t,n){let r={},i=e.createLanguage([n],new Map,s=>{if(!Si(s))return;let o=ft(s,"utf-8");r.current?.scripts.set(s,t.ScriptSnapshot.fromString(o),n.getLanguageId(s)??pu(s))});return r.current=i,i}function eu(e,t){return{getCurrentDirectory:()=>e,getCompilationSettings:()=>t.options,getScriptFileNames:()=>t.fileNames,getProjectReferences:()=>t.projectReferences,getProjectVersion:()=>"0"}}function Gn(e,t,n){try{return e(t)}catch(r){throw(typeof r=="object"&&r!==null&&"code"in r?r.code:null)==="MODULE_NOT_FOUND"?new Error(`Vue augmentation requires ${t} to be installed in ${n}. Install Vue/Volar dependencies for that project, then rerun augment-vue.`,{cause:r}):r}}function tu(e,t,n){let r=nu(e);return i=>{let s=gt(t,i.fileName),o=n(i.fileName);if(!o)return null;let a=Ni(o,i.textSpan.start),l=r.get(s);if(!l)return null;let c=l.containingByLine.get(a.line);return c!==void 0?c:ru(l.starts,a.line,2)}}function nu(e){let t=e.prepare(`
100
+ `).all().map(r=>_i(t,r.relativePath))}function ru(e,t){let{vueCore:n,ts:r,volarTs:i}=iu(e),{parsed:s,vueOptions:o}=su(n,r,t),a=Gn(t),l=n.createVueLanguagePlugin(r,s.options,o,g=>g),c=ou(n,r,l),u=au(a,s),{languageServiceHost:d}=i.createLanguageServiceHost(r,r.sys,c,g=>g,u),m=r.createLanguageService(d);return{ts:r,language:c,languageService:m,fileNames:s.fileNames,configDir:a}}function iu(e){let t=Cc(Oc(Xe(e,"package.json")).href);return{vueCore:zn(t,"@vue/language-core",e),ts:zn(t,"typescript",e),volarTs:zn(t,"@volar/typescript",e)}}function su(e,t,n){let r=t.readConfigFile(n,t.sys.readFile);if(r.error||!r.config)throw new Error(`Failed to read ${n}`);let s=e.createParsedCommandLine(t,t.sys,n).vueOptions;return typeof e.createGlobalTypesWriter=="function"&&(s.globalTypesPath=e.createGlobalTypesWriter(s,t.sys.writeFile)),{parsed:t.parseJsonConfigFileContent(r.config,t.sys,Gn(n),void 0,n,void 0,e.getAllExtensions(s).map(o=>({extension:o.slice(1),isMixedContent:!0,scriptKind:t.ScriptKind.Deferred}))),vueOptions:s}}function ou(e,t,n){let r={},i=e.createLanguage([n],new Map,s=>{if(!xi(s))return;let o=pt(s,"utf-8");r.current?.scripts.set(s,t.ScriptSnapshot.fromString(o),n.getLanguageId(s)??xu(s))});return r.current=i,i}function au(e,t){return{getCurrentDirectory:()=>e,getCompilationSettings:()=>t.options,getScriptFileNames:()=>t.fileNames,getProjectReferences:()=>t.projectReferences,getProjectVersion:()=>"0"}}function zn(e,t,n){try{return e(t)}catch(r){throw(typeof r=="object"&&r!==null&&"code"in r?r.code:null)==="MODULE_NOT_FOUND"?new Error(`Vue augmentation requires ${t} to be installed in ${n}. Install Vue/Volar dependencies for that project, then rerun augment-vue.`,{cause:r}):r}}function lu(e,t,n){let r=cu(e);return i=>{let s=ft(t,i.fileName),o=n(i.fileName);if(!o)return null;let a=Ei(o,i.textSpan.start),l=r.get(s);if(!l)return null;let c=l.containingByLine.get(a.line);return c!==void 0?c:uu(l.starts,a.line,2)}}function cu(e){let t=e.prepare(`
101
101
  SELECT
102
102
  d.relative_path AS relativePath,
103
103
  der.start_line AS startLine,
@@ -106,31 +106,31 @@ Thumbs.db
106
106
  FROM defn_enclosing_ranges der
107
107
  JOIN documents d ON d.id = der.document_id
108
108
  ORDER BY d.relative_path, (der.end_line - der.start_line) DESC
109
- `).all(),n=new Map;for(let r of t){let i=n.get(r.relativePath);i||(i={containingByLine:new Map,starts:[]},n.set(r.relativePath,i)),i.starts.push({line:r.startLine,symbolId:r.symbolId});for(let s=r.startLine;s<=r.endLine;s++)i.containingByLine.set(s,r.symbolId)}for(let r of n.values())r.starts.sort((i,s)=>i.line-s.line);return n}function ru(e,t,n){let r=0,i=e.length-1;for(;r<=i;){let o=Math.floor((r+i)/2);e[o].line<t?r=o+1:i=o-1}let s=null;for(let o of[i,r]){let a=e[o];if(!a)continue;let l=Math.abs(a.line-t);l>n||(!s||l<s.distance)&&(s={distance:l,symbolId:a.symbolId})}return s?.symbolId??null}function iu(e,t,n){let r=yu(t),i=e.prepare("SELECT id FROM global_symbols WHERE symbol = ?"),s=e.prepare(`
109
+ `).all(),n=new Map;for(let r of t){let i=n.get(r.relativePath);i||(i={containingByLine:new Map,starts:[]},n.set(r.relativePath,i)),i.starts.push({line:r.startLine,symbolId:r.symbolId});for(let s=r.startLine;s<=r.endLine;s++)i.containingByLine.set(s,r.symbolId)}for(let r of n.values())r.starts.sort((i,s)=>i.line-s.line);return n}function uu(e,t,n){let r=0,i=e.length-1;for(;r<=i;){let o=Math.floor((r+i)/2);e[o].line<t?r=o+1:i=o-1}let s=null;for(let o of[i,r]){let a=e[o];if(!a)continue;let l=Math.abs(a.line-t);l>n||(!s||l<s.distance)&&(s={distance:l,symbolId:a.symbolId})}return s?.symbolId??null}function du(e,t,n){let r=Cu(t),i=e.prepare("SELECT id FROM global_symbols WHERE symbol = ?"),s=e.prepare(`
110
110
  INSERT OR IGNORE INTO global_symbols (symbol, display_name, kind, documentation)
111
111
  VALUES (?, ?, ?, ?)
112
- `),o=0,a=new Map;return e.transaction(()=>{for(let c of n){let d=gt(t,c),u=bu(r.name,r.version,d);s.run(u,"default",7,`Vue component|${d}`);let m=i.get(u);m&&(o++,a.set(c,m.id))}})(),{get(c){return a.get(c)??null},syntheticSymbols:o}}function su(e,t,n,r,i){return e.transaction(()=>(Gc(e),ou(e,t,n,r),cu(e,i)))()}function ou(e,t,n,r){let i=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),s=e.prepare(`
112
+ `),o=0,a=new Map;return e.transaction(()=>{for(let c of n){let u=ft(t,c),d=vu(r.name,r.version,u);s.run(d,"default",7,`Vue component|${u}`);let m=i.get(d);m&&(o++,a.set(c,m.id))}})(),{get(c){return a.get(c)??null},syntheticSymbols:o}}function mu(e,t,n,r,i){return e.transaction(()=>(tu(e),pu(e,t,n,r),hu(e,i)))()}function pu(e,t,n,r){let i=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),s=e.prepare(`
113
113
  INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
114
114
  VALUES (?, ?, ?, ?, X'00')
115
115
  `),o=e.prepare(`
116
116
  INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
117
117
  VALUES (?, ?, 1)
118
- `);for(let a of n){let l=r.get(a);if(!l)continue;let c=gt(t,a),d=i.get(c);if(!d)continue;let u=s.run(d.id,-1,0,0);o.run(Number(u.lastInsertRowid),l)}}function au(e,t,n,r,i){if(e.fileName.endsWith(".vue")){let s=r.language.scripts.get(e.fileName),o=s?.generated?.languagePlugin.typescript?.getServiceScript(s.generated.root)?.code;if(s&&o){let a=r.language.maps.get(o,s);if(vi(a,e.textSpan.start)!==null)return n.get(e.fileName)}return e.fileName.startsWith(i)?n.get(e.fileName):null}return t(e)}function lu(e){let t=new Set,n=[];for(let r of e){let i=Ci(r);t.has(i)||(t.add(i),n.push(r))}return n}function Ci(e){return[e.sourceFile,e.sourceLine,e.sourceStartChar,e.sourceEndChar,e.symbolId].join(":")}function cu(e,t){let n=hu(e,[...new Set(t.map(l=>l.sourceFile))]),r=e.prepare(`
118
+ `);for(let a of n){let l=r.get(a);if(!l)continue;let c=ft(t,a),u=i.get(c);if(!u)continue;let d=s.run(u.id,-1,0,0);o.run(Number(d.lastInsertRowid),l)}}function fu(e,t,n,r,i){if(e.fileName.endsWith(".vue")){let s=r.language.scripts.get(e.fileName),o=s?.generated?.languagePlugin.typescript?.getServiceScript(s.generated.root)?.code;if(s&&o){let a=r.language.maps.get(o,s);if(Ni(a,e.textSpan.start)!==null)return n.get(e.fileName)}return e.fileName.startsWith(i)?n.get(e.fileName):null}return t(e)}function gu(e){let t=new Set,n=[];for(let r of e){let i=vi(r);t.has(i)||(t.add(i),n.push(r))}return n}function vi(e){return[e.sourceFile,e.sourceLine,e.sourceStartChar,e.sourceEndChar,e.symbolId].join(":")}function hu(e,t){let n=Ru(e,[...new Set(t.map(l=>l.sourceFile))]),r=e.prepare(`
119
119
  INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
120
120
  VALUES (?, ?, ?, ?, X'00')
121
121
  `),i=e.prepare(`
122
122
  INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
123
123
  VALUES (?, ?, 0)
124
- `),s=new Set,o=0,a=0;for(let l of t){let c=Ci(l);if(s.has(c))continue;s.add(c);let d=n.get(l.sourceFile);if(!d)continue;let u=r.run(d,a++,l.sourceLine,l.sourceLine),m=i.run(Number(u.lastInsertRowid),l.symbolId);o+=Number(m.changes)}return o}function*uu(e){let t=/\b[A-Za-z_$][A-Za-z0-9_$]*\b/g,n=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"]),r;for(;r=t.exec(e);){let i=r[0];n.has(i)||(yield{text:i,start:r.index,end:r.index+i.length})}}function du(e,t){for(let[n]of e.toGeneratedLocation(t,r=>!!r.navigation))return n;return null}function vi(e,t){let n=e;for(let[r]of n.toSourceLocation(t,i=>!!i.navigation))return r;return null}function Ni(e,t){let n=0,r=e.lineStarts.length-1;for(;n<=r;){let s=Math.floor((n+r)/2);e.lineStarts[s]<=t?n=s+1:r=s-1}let i=Math.max(0,r);return{line:i,character:t-e.lineStarts[i]}}function mu(e,t){return gt(e,t).startsWith("node_modules/")}function gt(e,t){return vc(e,t).replaceAll("\\","/")}function pu(e){switch(Cc(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 fu(){let e=new Map;return t=>{if(e.has(t))return e.get(t)??null;try{let n=ft(t,"utf-8"),r={text:n,lineStarts:gu(n)};return e.set(t,r),r}catch{return e.set(t,null),null}}}function gu(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return t}function hu(e,t){let n=new Map,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT id, relative_path AS relativePath FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.set(a.relativePath,a.id)}return n}function yu(e){try{let t=JSON.parse(ft(Xe(e,"package.json"),"utf-8"));return{name:t.name??"workspace",version:t.version??"0.0.0"}}catch{return{name:"workspace",version:"0.0.0"}}}function bu(e,t,n){let r=n.split("/").map(i=>`\`${i.replaceAll("`","")}\``).join("/");return`scip-vue npm ${e} ${t} ${r}/default.`}async function Li(e){let{projectRoot:t,maxHeapMb:n=8192,onStatus:r=console.log,skipAutoInstall:i=!1}=e,s=Eu(e),o=Date.now();Ei(je(s.outputScip),{recursive:!0}),Ei(je(s.outputDb),{recursive:!0});let a=e.languages??Ae(t);if(a.length===0)throw new Error("No supported languages detected in this project. Looked for: tsconfig.json, Cargo.toml, go.mod, pyproject.toml, etc.");r(`Detected languages: ${a.join(", ")}`);let l=Qu(t,a,{pnpmWorkspaces:e.pnpmWorkspaces}),c=Uu(se(je(s.outputDb),"index.lock")),d=null;try{let u=Du({opts:e,paths:s,languages:a,fingerprint:l,start:o,onStatus:r});if(u)return u;Ou(i,r);let m=Lu(s);return d=m.runDir,await ku({opts:e,languages:a,projectRoot:t,paths:s,tempPaths:m,fingerprint:l,start:o,maxHeapMb:n,skipAutoInstall:i,onStatus:r})}finally{d&&et(d,{recursive:!0,force:!0}),c()}}function Eu(e){let t=e.outputScip??se(e.projectRoot,"index.scip"),n=e.outputDb??se(e.projectRoot,"index.db");return{outputScip:t,outputDb:n,metaPath:se(je(n),"meta.json")}}function Du(e){if(e.opts.skipIfUnchanged===!1||!Be(e.paths.outputScip)||!Be(e.paths.outputDb)||!Yu(e.paths.metaPath,e.fingerprint))return null;Ee({projectRoot:e.opts.projectRoot,dbPath:e.paths.outputDb,onStatus:e.onStatus});let t=Date.now()-e.start;return e.onStatus(`Index unchanged; reused existing SQLite index in ${(t/1e3).toFixed(1)}s`),{languages:e.languages,indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:t,reused:!0,skipped:[]}}function Lu(e){let t=Iu(se(je(e.outputDb),"reindex-"));return{runDir:t,tempOutputScip:se(t,Kt(e.outputScip)),tempOutputDb:se(t,Kt(e.outputDb)),tempMetaPath:se(t,Kt(e.metaPath))}}async function ku(e){let t={...process.env,NODE_OPTIONS:`--max-old-space-size=${e.maxHeapMb}`},{indexedOutputs:n,skippedLanguages:r}=await wu(e,t);Pu(e,t,n,r);let i=Date.now()-e.start;return e.onStatus(`Done in ${(i/1e3).toFixed(1)}s`),{languages:n.map(s=>s.language),indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:i,reused:!1,skipped:r}}async function wu(e,t){let{preparedRuns:n,skippedLanguages:r}=Mu({languages:e.languages,tempOutputScip:e.tempPaths.tempOutputScip,projectRoot:e.projectRoot,env:t,skipAutoInstall:e.skipAutoInstall,pnpmWorkspaces:e.opts.pnpmWorkspaces,onStatus:e.onStatus}),i=await zu(n,e.projectRoot,e.onStatus,e.opts.indexerConcurrency),{indexedOutputs:s}=Tu(i,r);return $u(s,r,e.languages,e.opts.allowPartial,e.onStatus),{indexedOutputs:s,skippedLanguages:r}}function Pu(e,t,n,r){Au(n,e.tempPaths.tempOutputScip,e.onStatus),ju(e.tempPaths.tempOutputScip,e.tempPaths.tempOutputDb,t,e.onStatus),Ee({projectRoot:e.projectRoot,dbPath:e.tempPaths.tempOutputDb,onStatus:e.onStatus}),Xu(e.tempPaths.tempMetaPath,{version:2,status:r.length===0?"complete":"partial",updatedAt:new Date().toISOString(),fingerprint:e.fingerprint,requestedLanguages:e.languages,indexedLanguages:n.map(i=>i.language),skipped:[...r]}),Ju({tempOutputScip:e.tempPaths.tempOutputScip,tempOutputDb:e.tempPaths.tempOutputDb,tempMetaPath:e.tempPaths.tempMetaPath,outputScip:e.paths.outputScip,outputDb:e.paths.outputDb,metaPath:e.paths.metaPath})}function Ou(e,t){if(!pt("scip")){if(e)throw new Error(`The scip CLI is required but not found on PATH.
124
+ `),s=new Set,o=0,a=0;for(let l of t){let c=vi(l);if(s.has(c))continue;s.add(c);let u=n.get(l.sourceFile);if(!u)continue;let d=r.run(u,a++,l.sourceLine,l.sourceLine),m=i.run(Number(d.lastInsertRowid),l.symbolId);o+=Number(m.changes)}return o}function*yu(e){let t=/\b[A-Za-z_$][A-Za-z0-9_$]*\b/g,n=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"]),r;for(;r=t.exec(e);){let i=r[0];n.has(i)||(yield{text:i,start:r.index,end:r.index+i.length})}}function bu(e,t){for(let[n]of e.toGeneratedLocation(t,r=>!!r.navigation))return n;return null}function Ni(e,t){let n=e;for(let[r]of n.toSourceLocation(t,i=>!!i.navigation))return r;return null}function Ei(e,t){let n=0,r=e.lineStarts.length-1;for(;n<=r;){let s=Math.floor((n+r)/2);e.lineStarts[s]<=t?n=s+1:r=s-1}let i=Math.max(0,r);return{line:i,character:t-e.lineStarts[i]}}function Su(e,t){return ft(e,t).startsWith("node_modules/")}function ft(e,t){return Pc(e,t).replaceAll("\\","/")}function xu(e){switch(wc(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 _u(){let e=new Map;return t=>{if(e.has(t))return e.get(t)??null;try{let n=pt(t,"utf-8"),r={text:n,lineStarts:Iu(n)};return e.set(t,r),r}catch{return e.set(t,null),null}}}function Iu(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return t}function Ru(e,t){let n=new Map,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT id, relative_path AS relativePath FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.set(a.relativePath,a.id)}return n}function Cu(e){try{let t=JSON.parse(pt(Xe(e,"package.json"),"utf-8"));return{name:t.name??"workspace",version:t.version??"0.0.0"}}catch{return{name:"workspace",version:"0.0.0"}}}function vu(e,t,n){let r=n.split("/").map(i=>`\`${i.replaceAll("`","")}\``).join("/");return`scip-vue npm ${e} ${t} ${r}/default.`}async function ki(e){let{projectRoot:t,maxHeapMb:n=8192,onStatus:r=console.log,skipAutoInstall:i=!1}=e,s=Mu(e),o=Date.now();Di(Be(s.outputScip),{recursive:!0}),Di(Be(s.outputDb),{recursive:!0});let a=e.languages??je(t);if(a.length===0)throw new Error("No supported languages detected in this project. Looked for: tsconfig.json, Cargo.toml, go.mod, pyproject.toml, etc.");r(`Detected languages: ${a.join(", ")}`);let l=rd(t,a,{pnpmWorkspaces:e.pnpmWorkspaces}),c=Qu(se(Be(s.outputDb),"index.lock")),u=null;try{let d=Fu({opts:e,paths:s,languages:a,fingerprint:l,start:o,onStatus:r});if(d)return d;Bu(i,r);let m=Tu(s);return u=m.runDir,await $u({opts:e,languages:a,projectRoot:t,paths:s,tempPaths:m,fingerprint:l,start:o,maxHeapMb:n,skipAutoInstall:i,onStatus:r})}finally{u&&et(u,{recursive:!0,force:!0}),c()}}function Mu(e){let t=e.outputScip??se(e.projectRoot,"index.scip"),n=e.outputDb??se(e.projectRoot,"index.db");return{outputScip:t,outputDb:n,metaPath:se(Be(n),"meta.json")}}function Fu(e){if(e.opts.skipIfUnchanged===!1||!We(e.paths.outputScip)||!We(e.paths.outputDb)||!id(e.paths.metaPath,e.fingerprint))return null;De({projectRoot:e.opts.projectRoot,dbPath:e.paths.outputDb,onStatus:e.onStatus});let t=Date.now()-e.start;return e.onStatus(`Index unchanged; reused existing SQLite index in ${(t/1e3).toFixed(1)}s`),{languages:e.languages,indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:t,reused:!0,skipped:[]}}function Tu(e){let t=Lu(se(Be(e.outputDb),"reindex-"));return{runDir:t,tempOutputScip:se(t,Kt(e.outputScip)),tempOutputDb:se(t,Kt(e.outputDb)),tempMetaPath:se(t,Kt(e.metaPath))}}async function $u(e){let t={...process.env,NODE_OPTIONS:`--max-old-space-size=${e.maxHeapMb}`},{indexedOutputs:n,skippedLanguages:r}=await Au(e,t);ju(e,t,n,r);let i=Date.now()-e.start;return e.onStatus(`Done in ${(i/1e3).toFixed(1)}s`),{languages:n.map(s=>s.language),indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:i,reused:!1,skipped:r}}async function Au(e,t){let{preparedRuns:n,skippedLanguages:r}=Wu({languages:e.languages,tempOutputScip:e.tempPaths.tempOutputScip,projectRoot:e.projectRoot,env:t,skipAutoInstall:e.skipAutoInstall,pnpmWorkspaces:e.opts.pnpmWorkspaces,onStatus:e.onStatus}),i=await ed(n,e.projectRoot,e.onStatus,e.opts.indexerConcurrency),{indexedOutputs:s}=Vu(i,r);return Uu(s,r,e.languages,e.opts.allowPartial,e.onStatus),{indexedOutputs:s,skippedLanguages:r}}function ju(e,t,n,r){Ju(n,e.tempPaths.tempOutputScip,e.onStatus),qu(e.tempPaths.tempOutputScip,e.tempPaths.tempOutputDb,t,e.onStatus),De({projectRoot:e.projectRoot,dbPath:e.tempPaths.tempOutputDb,onStatus:e.onStatus}),sd(e.tempPaths.tempMetaPath,{version:2,status:r.length===0?"complete":"partial",updatedAt:new Date().toISOString(),fingerprint:e.fingerprint,requestedLanguages:e.languages,indexedLanguages:n.map(i=>i.language),skipped:[...r]}),Xu({tempOutputScip:e.tempPaths.tempOutputScip,tempOutputDb:e.tempPaths.tempOutputDb,tempMetaPath:e.tempPaths.tempMetaPath,outputScip:e.paths.outputScip,outputDb:e.paths.outputDb,metaPath:e.paths.metaPath})}function Bu(e,t){if(!mt("scip")){if(e)throw new Error(`The scip CLI is required but not found on PATH.
125
125
  Install from: https://github.com/sourcegraph/scip/releases`);if(t("scip CLI not found on PATH. Attempting auto-install..."),!Jr(t))throw new Error(`The scip CLI is required but could not be installed.
126
- Install manually from: https://github.com/sourcegraph/scip/releases`)}}function Mu(e){let t=[],n=[],r=e.languages.map((i,s)=>({language:i,scipPath:e.languages.length>1?Vu(e.tempOutputScip,i,s):e.tempOutputScip}));for(let{language:i,scipPath:s}of r){let o=Fu({...e,language:i,scipPath:s});"skipped"in o?n.push(o.skipped):t.push(o.prepared)}return{preparedRuns:t,skippedLanguages:n}}function Fu(e){let t=Vt(e.language),n=zt(t),r=qn(t,e.projectRoot);if(!r&&!di(t)){if(e.skipAutoInstall){let a=`${n} not found on PATH (auto-install disabled). ${t.installUrl??""}`.trim();return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}if(e.onStatus(`${n} not found. Attempting auto-install...`),!gi(t,e.onStatus)){let a=`${n} could not be auto-installed. ${t.installUrl?`Install manually from ${t.installUrl}`:`Install ${n} and put it on PATH.`}`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}}let i=r??Ye(t);if(!i){let a=`${n} was not found after installation checks.`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}let{binary:s,args:o}=t.indexArgs({projectRoot:e.projectRoot,outputPath:e.scipPath,pnpmWorkspaces:e.pnpmWorkspaces,indexerBinary:i});return{prepared:{language:e.language,scipPath:e.scipPath,config:t,resolvedBinary:i,binary:s,args:o,env:pi(t,e.env,i)}}}function Tu(e,t){let n=[];for(let r of e)r.skipped?t.push(r.skipped):n.push({language:r.language,scipPath:r.scipPath});return{indexedOutputs:n}}function $u(e,t,n,r,i){if(e.length===0){let s=t.map(o=>` - ${o.language}: ${o.reason}`).join(`
126
+ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function Wu(e){let t=[],n=[],r=e.languages.map((i,s)=>({language:i,scipPath:e.languages.length>1?Yu(e.tempOutputScip,i,s):e.tempOutputScip}));for(let{language:i,scipPath:s}of r){let o=Hu({...e,language:i,scipPath:s});"skipped"in o?n.push(o.skipped):t.push(o.prepared)}return{preparedRuns:t,skippedLanguages:n}}function Hu(e){let t=Vt(e.language),n=zt(t),r=Jn(t,e.projectRoot);if(!r&&!mi(t)){if(e.skipAutoInstall){let a=`${n} not found on PATH (auto-install disabled). ${t.installUrl??""}`.trim();return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}if(e.onStatus(`${n} not found. Attempting auto-install...`),!hi(t,e.onStatus)){let a=`${n} could not be auto-installed. ${t.installUrl?`Install manually from ${t.installUrl}`:`Install ${n} and put it on PATH.`}`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}}let i=r??Qe(t);if(!i){let a=`${n} was not found after installation checks.`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}let{binary:s,args:o}=t.indexArgs({projectRoot:e.projectRoot,outputPath:e.scipPath,pnpmWorkspaces:e.pnpmWorkspaces,indexerBinary:i});return{prepared:{language:e.language,scipPath:e.scipPath,config:t,resolvedBinary:i,binary:s,args:o,env:fi(t,e.env,i)}}}function Vu(e,t){let n=[];for(let r of e)r.skipped?t.push(r.skipped):n.push({language:r.language,scipPath:r.scipPath});return{indexedOutputs:n}}function Uu(e,t,n,r,i){if(e.length===0){let s=t.map(o=>` - ${o.language}: ${o.reason}`).join(`
127
127
  `);throw new Error(`No language indexers ran successfully. Install at least one indexer for the languages in this project.
128
128
  `+s)}if(t.length!==0&&(i(`Indexed ${e.length} of ${n.length} languages; skipped ${t.map(s=>s.language).join(", ")}.`),!r))throw new Error(`Failed to index all required languages; preserving the previous index. Pass --allow-partial to intentionally write an incomplete index.
129
129
  `+t.map(s=>` - ${s.language}: ${s.reason}`).join(`
130
- `))}function Au(e,t,n){e.length>1?(n(`Merging ${e.length} language indexes...`),ri(e.map(r=>r.scipPath),t)):e[0].scipPath!==t&&Ze(e[0].scipPath,t)}function ju(e,t,n,r){if(r("Converting to SQLite..."),!Be(e))throw new Error(`SCIP index not found at ${e} after indexing`);try{let i=li(e);i.removedDefinitionOccurrences>0&&r(`Sanitized ${i.removedDefinitionOccurrences} invalid definition occurrences across ${i.touchedDocuments} documents before SQLite conversion.`),xu("scip",["expt-convert","--output",t,e],{env:n,stdio:"pipe",maxBuffer:50*1024*1024})}catch(i){let s=i instanceof Error?i.message:String(i);throw new Error(`Failed to convert SCIP index to SQLite: ${s}`,{cause:i})}}function Bu(e,t,n){if(!e.defaultOutputPath)return;let r=se(t,e.defaultOutputPath);n!==r&&Be(r)&&Ze(r,n)}function Wu(e,t,n){if(!e.defaultOutputPath)return null;let r=se(t,e.defaultOutputPath);if(r===n)return null;let i=`${n}.default-output-backup`;return et(i,{force:!0}),Be(r)?(Ze(r,i),{defaultOutputPath:r,backupPath:i}):{defaultOutputPath:r,backupPath:null}}function Hu(e){e&&(et(e.defaultOutputPath,{force:!0}),e.backupPath&&Be(e.backupPath)&&Ze(e.backupPath,e.defaultOutputPath))}function Vu(e,t,n){let r=Nu(e)||".scip",i=Kt(e,r);return se(je(e),`${i}.${n+1}.${t}${r}`)}function Uu(e){let t;try{t=Ru(e,"wx")}catch(n){throw(typeof n=="object"&&n&&"code"in n?n.code:void 0)==="EEXIST"?new Error(`Another scip-query reindex is already running for ${je(e)}.`,{cause:n}):n}return Di(t,JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()})+`
131
- `),()=>{try{_u(t)}finally{et(e,{force:!0})}}}function Ju(e){Yn(e.tempOutputScip,e.outputScip),Yn(e.tempOutputDb,e.outputDb),Yn(e.tempMetaPath,e.metaPath)}function Yn(e,t){et(`${t}.tmp-replace`,{force:!0}),Ze(e,`${t}.tmp-replace`),Ze(`${t}.tmp-replace`,t)}function qu(e,t){if(e<=1)return 1;let n=Number(process.env.SCIP_QUERY_INDEXER_CONCURRENCY??0),r=Number.isFinite(t)&&t&&t>0?t:Number.isFinite(n)&&n>0?n:Math.min(2,Math.max(1,vu().length-1));return Math.max(1,Math.min(e,Math.floor(r)))}async function zu(e,t,n,r){let i=e.filter(c=>c.config.defaultOutputPath),s=e.filter(c=>!c.config.defaultOutputPath),o=[],a=qu(s.length,r),l=await Ku(s,a,c=>Xn(c,t,n));if(a>1){let c=new Map;for(let d of l.filter(u=>u.skipped)){let u=s.find(m=>m.language===d.language);u&&(n(`Retrying ${u.language} indexer serially after parallel failure...`),c.set(u.language,await Xn(u,t,n)))}o.push(...l.map(d=>c.get(d.language)??d))}else o.push(...l);for(let c of i)o.push(await Xn(c,t,n));return o.sort((c,d)=>e.findIndex(u=>u.language===c.language)-e.findIndex(u=>u.language===d.language))}async function Xn(e,t,n){n(`Indexing ${e.language} with ${e.resolvedBinary}...`),et(e.scipPath,{force:!0});let r=Wu(e.config,t,e.scipPath);try{await Gu(e.binary,e.args,{cwd:t,env:e.env,maxBuffer:50*1024*1024}),Bu(e.config,t,e.scipPath)}catch(i){let s=i instanceof Error?i.message:String(i),o=`${e.resolvedBinary} indexer failed: ${s.split(`
132
- `)[0]}`;return n(`Skipping ${e.language}: ${o}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:o}}}finally{Hu(r)}if(!Be(e.scipPath)){let i=`${e.resolvedBinary} indexer completed but did not produce ${e.scipPath}`;return n(`Skipping ${e.language}: ${i}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:i}}}return{language:e.language,scipPath:e.scipPath}}function Gu(e,t,n){return new Promise((r,i)=>{Su(e,[...t],n,s=>{s?i(s):r()})})}async function Ku(e,t,n){if(e.length===0)return[];let r=new Array(e.length),i=0,s=Math.max(1,Math.min(e.length,t)),o=Array.from({length:s},async()=>{for(;i<e.length;){let a=i++;r[a]=await n(e[a])}});return await Promise.all(o),r}function Qu(e,t,n){return{version:1,languages:[...t].sort(),pnpmWorkspaces:n.pnpmWorkspaces===!0,files:Ut(e)}}function Yu(e,t){try{let n=JSON.parse(Cu(e,"utf-8"));return n.version===2&&n.status==="complete"&&Gt(n.fingerprint)===Gt(t)&&Gt([...n.indexedLanguages??[]].sort())===Gt(t.languages)}catch{return!1}}function Xu(e,t){Di(e,`${JSON.stringify(t,null,2)}
133
- `)}function Gt(e){return JSON.stringify(e)}import{createRequire as id}from"module";import{existsSync as ht,readFileSync as Zu,readdirSync as ed,statSync as td}from"fs";import A from"path";var er=["tsconfig.json","tsconfig.app.json","tsconfig.node.json","tsconfig.base.json"];function tr(e,t){let r=t?A.dirname(A.join(e,t)):e,i=A.resolve(e);for(;r.startsWith(i);){for(let o of er){let a=A.join(r,o);if(ht(a))return a}let s=A.dirname(r);if(s===r)break;r=s}for(let s of er){let o=A.join(e,s);if(ht(o))return o}return null}function ki(e){let t=e.config.projectRoot,n=new Set(nr(t,e.config.semantic?.typescript?.tsconfigs)),r=e.all(`SELECT relative_path
130
+ `))}function Ju(e,t,n){e.length>1?(n(`Merging ${e.length} language indexes...`),ii(e.map(r=>r.scipPath),t)):e[0].scipPath!==t&&Ze(e[0].scipPath,t)}function qu(e,t,n,r){if(r("Converting to SQLite..."),!We(e))throw new Error(`SCIP index not found at ${e} after indexing`);try{let i=ci(e);i.removedDefinitionOccurrences>0&&r(`Sanitized ${i.removedDefinitionOccurrences} invalid definition occurrences across ${i.touchedDocuments} documents before SQLite conversion.`),Eu("scip",["expt-convert","--output",t,e],{env:n,stdio:"pipe",maxBuffer:50*1024*1024})}catch(i){let s=i instanceof Error?i.message:String(i);throw new Error(`Failed to convert SCIP index to SQLite: ${s}`,{cause:i})}}function zu(e,t,n){if(!e.defaultOutputPath)return;let r=se(t,e.defaultOutputPath);n!==r&&We(r)&&Ze(r,n)}function Gu(e,t,n){if(!e.defaultOutputPath)return null;let r=se(t,e.defaultOutputPath);if(r===n)return null;let i=`${n}.default-output-backup`;return et(i,{force:!0}),We(r)?(Ze(r,i),{defaultOutputPath:r,backupPath:i}):{defaultOutputPath:r,backupPath:null}}function Ku(e){e&&(et(e.defaultOutputPath,{force:!0}),e.backupPath&&We(e.backupPath)&&Ze(e.backupPath,e.defaultOutputPath))}function Yu(e,t,n){let r=Ou(e)||".scip",i=Kt(e,r);return se(Be(e),`${i}.${n+1}.${t}${r}`)}function Qu(e){let t;try{t=ku(e,"wx")}catch(n){throw(typeof n=="object"&&n&&"code"in n?n.code:void 0)==="EEXIST"?new Error(`Another scip-query reindex is already running for ${Be(e)}.`,{cause:n}):n}return Li(t,JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()})+`
131
+ `),()=>{try{Du(t)}finally{et(e,{force:!0})}}}function Xu(e){Yn(e.tempOutputScip,e.outputScip),Yn(e.tempOutputDb,e.outputDb),Yn(e.tempMetaPath,e.metaPath)}function Yn(e,t){et(`${t}.tmp-replace`,{force:!0}),Ze(e,`${t}.tmp-replace`),Ze(`${t}.tmp-replace`,t)}function Zu(e,t){if(e<=1)return 1;let n=Number(process.env.SCIP_QUERY_INDEXER_CONCURRENCY??0),r=Number.isFinite(t)&&t&&t>0?t:Number.isFinite(n)&&n>0?n:Math.min(2,Math.max(1,Pu().length-1));return Math.max(1,Math.min(e,Math.floor(r)))}async function ed(e,t,n,r){let i=e.filter(c=>c.config.defaultOutputPath),s=e.filter(c=>!c.config.defaultOutputPath),o=[],a=Zu(s.length,r),l=await nd(s,a,c=>Qn(c,t,n));if(a>1){let c=new Map;for(let u of l.filter(d=>d.skipped)){let d=s.find(m=>m.language===u.language);d&&(n(`Retrying ${d.language} indexer serially after parallel failure...`),c.set(d.language,await Qn(d,t,n)))}o.push(...l.map(u=>c.get(u.language)??u))}else o.push(...l);for(let c of i)o.push(await Qn(c,t,n));return o.sort((c,u)=>e.findIndex(d=>d.language===c.language)-e.findIndex(d=>d.language===u.language))}async function Qn(e,t,n){n(`Indexing ${e.language} with ${e.resolvedBinary}...`),et(e.scipPath,{force:!0});let r=Gu(e.config,t,e.scipPath);try{await td(e.binary,e.args,{cwd:t,env:e.env,maxBuffer:50*1024*1024}),zu(e.config,t,e.scipPath)}catch(i){let s=i instanceof Error?i.message:String(i),o=`${e.resolvedBinary} indexer failed: ${s.split(`
132
+ `)[0]}`;return n(`Skipping ${e.language}: ${o}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:o}}}finally{Ku(r)}if(!We(e.scipPath)){let i=`${e.resolvedBinary} indexer completed but did not produce ${e.scipPath}`;return n(`Skipping ${e.language}: ${i}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:i}}}return{language:e.language,scipPath:e.scipPath}}function td(e,t,n){return new Promise((r,i)=>{Nu(e,[...t],n,s=>{s?i(s):r()})})}async function nd(e,t,n){if(e.length===0)return[];let r=new Array(e.length),i=0,s=Math.max(1,Math.min(e.length,t)),o=Array.from({length:s},async()=>{for(;i<e.length;){let a=i++;r[a]=await n(e[a])}});return await Promise.all(o),r}function rd(e,t,n){return{version:1,languages:[...t].sort(),pnpmWorkspaces:n.pnpmWorkspaces===!0,files:Ut(e)}}function id(e,t){try{let n=JSON.parse(wu(e,"utf-8"));return n.version===2&&n.status==="complete"&&Gt(n.fingerprint)===Gt(t)&&Gt([...n.indexedLanguages??[]].sort())===Gt(t.languages)}catch{return!1}}function sd(e,t){Li(e,`${JSON.stringify(t,null,2)}
133
+ `)}function Gt(e){return JSON.stringify(e)}import{createRequire as dd}from"module";import{existsSync as gt,readFileSync as od,readdirSync as ad,statSync as ld}from"fs";import A from"path";var Zn=["tsconfig.json","tsconfig.app.json","tsconfig.node.json","tsconfig.base.json"];function er(e,t){let r=t?A.dirname(A.join(e,t)):e,i=A.resolve(e);for(;r.startsWith(i);){for(let o of Zn){let a=A.join(r,o);if(gt(a))return a}let s=A.dirname(r);if(s===r)break;r=s}for(let s of Zn){let o=A.join(e,s);if(gt(o))return o}return null}function wi(e){let t=e.config.projectRoot,n=new Set(tr(t,e.config.semantic?.typescript?.tsconfigs)),r=e.all(`SELECT relative_path
134
134
  FROM documents
135
135
  WHERE (
136
136
  relative_path LIKE '%.ts'
@@ -142,7 +142,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
142
142
  OR relative_path LIKE '%.mjs'
143
143
  OR relative_path LIKE '%.cjs'
144
144
  )
145
- ${e.pathExclusionsFor("documents")}`);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=tr(t,i.relative_path);s&&n.add(A.resolve(s))}if(n.size===0){let i=tr(t);i&&n.add(A.resolve(i))}return[...n].filter(i=>!wi(t,i)).sort((i,s)=>i.localeCompare(s))}function nr(e,t=[]){let n=new Set;for(let r of t){let i=A.isAbsolute(r)?r:A.join(e,r);ht(i)&&n.add(A.resolve(i))}for(let r of nd(e))for(let i of er){let s=A.join(r,i);ht(s)&&n.add(A.resolve(s))}if(n.size===0){let r=tr(e);r&&n.add(A.resolve(r))}return[...n].filter(r=>!wi(e,r)).sort((r,i)=>r.localeCompare(i))}function nd(e){let t=A.join(e,"package.json");if(!ht(t))return[];let n;try{n=JSON.parse(Zu(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>rd(e,i))}function rd(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=A.join(e,t);return Zn(o)?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=A.join(e,r||".");return Zn(s)?ed(s).map(o=>A.join(s,o,i)).filter(Zn):[]}function Zn(e){try{return td(e).isDirectory()}catch{return!1}}function wi(e,t){let n=A.relative(e,t).replace(/\\/g,"/");return n.startsWith("..")||n.includes("/node_modules/")||n.startsWith("node_modules/")||n.includes("/dist/")||n.startsWith("dist/")}var sd=id(import.meta.url);function rr(e,t=[]){let n=od(),r=nr(e,t),i=r[0];return n?r.length===0?{available:!1,dependencyAvailable:n,reason:"no tsconfig found"}:{available:!0,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r}:{available:!1,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r,reason:"ts-morph is not installed"}}function od(){try{return sd.resolve("ts-morph"),!0}catch{return!1}}import{watch as ad}from"fs";import{existsSync as Pi,renameSync as Oi}from"fs";import{join as ld,relative as cd}from"path";import{fork as ud}from"child_process";import dd from"ignore";var Qt=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(t){this.projectRoot=t.projectRoot,this.watchConfig=Wr(t.config),this.indexPaths=ve(t.projectRoot,t.config),this.languages=t.languages,this.pnpmWorkspaces=t.config.indexer?.typescript?.pnpmWorkspaces??!1,this.onStatus=t.onStatus??(()=>{}),this.onReindexComplete=t.onReindexComplete??(()=>{}),this.onError=t.onError??(n=>console.error(n.message)),this.gitignoreFilter=Qe(t.projectRoot),this.extraIgnore=dd(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let t=ad(this.projectRoot,{recursive:!0},(n,r)=>{r&&!this.stopped&&this.handleFileChange(r)});this.fsWatchers.push(t)}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 t of this.fsWatchers)t.close();this.fsWatchers=[],this.debounceTimer&&clearTimeout(this.debounceTimer),this.cooldownTimer&&clearTimeout(this.cooldownTimer),this.setStatus({state:"idle"})}handleFileChange(t){let n=cd(this.projectRoot,ld(this.projectRoot,t));if(this.gitignoreFilter.isIgnored(n)||this.extraIgnore.ignores(n)||t.endsWith("index.db")||t.endsWith("index.scip")||t.endsWith("index.db.tmp")||t.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 r=Date.now()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:r}),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped)return;let t=Date.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&t<this.watchConfig.cooldownMs){let r=this.watchConfig.cooldownMs-t;this.dirty=!0;let i=Date.now()+r;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},r);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let n=Date.now();this.setStatus({state:"indexing",startedAt:n}),this.runReindex().then(r=>{if(this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onReindexComplete(r),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(r=>{this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onError(r instanceof Error?r:new Error(String(r))),this.setStatus({state:"idle"})})}runReindex(){return new Promise((t,n)=>{let r=Date.now(),i=this.indexPaths.dbPath+".tmp",s=md(this.indexPaths.indexPath),o=ud(new URL("./reindex-worker.js",import.meta.url).pathname,[],{env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:this.projectRoot,SCIP_REINDEX_OUTPUT_SCIP:s,SCIP_REINDEX_OUTPUT_DB:i,SCIP_REINDEX_LANGUAGES:this.languages?.join(",")??"",SCIP_REINDEX_PNPM_WORKSPACES:this.pnpmWorkspaces?"1":""},stdio:"pipe"});o.on("exit",a=>{if(a===0)try{Pi(i)&&Oi(i,this.indexPaths.dbPath),Pi(s)&&Oi(s,this.indexPaths.indexPath),t(Date.now()-r)}catch(l){n(new Error(`Atomic swap failed: ${l}`))}else n(new Error(`Reindex worker exited with code ${a}`))}),o.on("error",n)})}setStatus(t){this.status=t,this.onStatus(t)}};function md(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}import{existsSync as ir,mkdirSync as pd,symlinkSync as fd,readlinkSync as gd,unlinkSync as hd}from"fs";import{join as Yt,dirname as Mi,resolve as sr}from"path";import{homedir as Fi,platform as yd}from"os";import{fileURLToPath as bd}from"url";var Sd=yd()==="win32",or=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function Ti(e={}){let t=e.quiet?()=>{}:console.log,n=bd(import.meta.url),r=sr(Mi(n),"..","skills"),i=[Yt(Fi(),".claude","skills"),Yt(Fi(),".codex","skills")],s={installed:[],skipped:[],alreadyLinked:[]};for(let o of i){let a=Mi(o);if(!ir(a))continue;pd(o,{recursive:!0});let l=o.includes(".codex")?"Codex":"Claude";for(let c of or){let d=Yt(r,c),u=Yt(o,c);if(!ir(d)){s.skipped.push(`${l}/${c}`);continue}if(ir(u)){try{let m=gd(u);if(sr(m)===sr(d)){s.alreadyLinked.push(`${l}/${c}`),t(` ok: ${c} \u2192 ${l} (already linked)`);continue}}catch{s.skipped.push(`${l}/${c}`),t(` skip: ${c} \u2192 ${l} (exists, not a symlink)`);continue}hd(u)}fd(d,u,Sd?"junction":"dir"),s.installed.push(`${l}/${c}`),t(` done: ${c} \u2192 ${l}`)}}return s}function be(e){return e+1}function me(e,t){return`${be(e)}-${be(t)}`}function pe(e,t,n){return`${e}:${me(t,n)}`}var b={empty(e){console.log(e)},list(e,t){for(let n of e)console.log(t(n))},groupedByFile(e,t,n=r=>r.relativePath){let r="";for(let i of e){let s=n(i);s!==r&&(r&&console.log(""),console.log(s),r=s),console.log(t(i))}},sectionedReport(e){let t=!0;for(let n of e)if(!(n.skipIfEmpty&&n.rows.length===0)){t||console.log(""),t=!1,n.title!==void 0&&console.log(`\u2550\u2550\u2550 ${n.title} \u2550\u2550\u2550`),n.explanation!==void 0&&console.log(n.explanation);for(let r of n.rows)console.log(r)}},table(e,t,n){console.log(` ${e.join(" ")}`);let r=n??e.map(i=>i.length);console.log(` ${r.map(i=>"\u2500".repeat(i)).join(" ")}`);for(let i of t)console.log(i)}};import{existsSync as $a}from"fs";import{join as oS}from"path";import xd from"better-sqlite3";var Xt=class{db;config;pathFilter;constructor(t,n){this.config=t,this.pathFilter=n??null,this.db=new xd(t.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000")}isIgnored(t){return this.pathFilter?.isIgnored(t)??!1}get localSymbolPredicate(){return`(
145
+ ${e.pathExclusionsFor("documents")}`);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=er(t,i.relative_path);s&&n.add(A.resolve(s))}if(n.size===0){let i=er(t);i&&n.add(A.resolve(i))}return[...n].filter(i=>!Pi(t,i)).sort((i,s)=>i.localeCompare(s))}function tr(e,t=[]){let n=new Set;for(let r of t){let i=A.isAbsolute(r)?r:A.join(e,r);gt(i)&&n.add(A.resolve(i))}for(let r of cd(e))for(let i of Zn){let s=A.join(r,i);gt(s)&&n.add(A.resolve(s))}if(n.size===0){let r=er(e);r&&n.add(A.resolve(r))}return[...n].filter(r=>!Pi(e,r)).sort((r,i)=>r.localeCompare(i))}function cd(e){let t=A.join(e,"package.json");if(!gt(t))return[];let n;try{n=JSON.parse(od(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>ud(e,i))}function ud(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=A.join(e,t);return Xn(o)?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=A.join(e,r||".");return Xn(s)?ad(s).map(o=>A.join(s,o,i)).filter(Xn):[]}function Xn(e){try{return ld(e).isDirectory()}catch{return!1}}function Pi(e,t){let n=A.relative(e,t).replace(/\\/g,"/");return n.startsWith("..")||n.includes("/node_modules/")||n.startsWith("node_modules/")||n.includes("/dist/")||n.startsWith("dist/")}var md=dd(import.meta.url);function nr(e,t=[]){let n=pd(),r=tr(e,t),i=r[0];return n?r.length===0?{available:!1,dependencyAvailable:n,reason:"no tsconfig found"}:{available:!0,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r}:{available:!1,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r,reason:"ts-morph is not installed"}}function pd(){try{return md.resolve("ts-morph"),!0}catch{return!1}}import{watch as fd}from"fs";import{existsSync as Oi,renameSync as Mi}from"fs";import{join as gd,relative as hd}from"path";import{fork as yd}from"child_process";import bd from"ignore";var Yt=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(t){this.projectRoot=t.projectRoot,this.watchConfig=Wr(t.config),this.indexPaths=Ne(t.projectRoot,t.config),this.languages=t.languages,this.pnpmWorkspaces=t.config.indexer?.typescript?.pnpmWorkspaces??!1,this.onStatus=t.onStatus??(()=>{}),this.onReindexComplete=t.onReindexComplete??(()=>{}),this.onError=t.onError??(n=>console.error(n.message)),this.gitignoreFilter=Ye(t.projectRoot),this.extraIgnore=bd(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let t=fd(this.projectRoot,{recursive:!0},(n,r)=>{r&&!this.stopped&&this.handleFileChange(r)});this.fsWatchers.push(t)}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 t of this.fsWatchers)t.close();this.fsWatchers=[],this.clearDebounceTimer(),this.clearCooldownTimer(),this.setStatus({state:"idle"})}handleFileChange(t){let n=hd(this.projectRoot,gd(this.projectRoot,t));if(this.gitignoreFilter.isIgnored(n)||this.extraIgnore.ignores(n)||t.endsWith("index.db")||t.endsWith("index.scip")||t.endsWith("index.db.tmp")||t.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.clearDebounceTimer();let r=Date.now()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:r}),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped)return;let t=Date.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&t<this.watchConfig.cooldownMs){let r=this.watchConfig.cooldownMs-t;this.dirty=!0;let i=Date.now()+r;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},r);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let n=Date.now();this.setStatus({state:"indexing",startedAt:n}),this.runReindex().then(r=>{if(this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onReindexComplete(r),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(r=>{this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onError(r instanceof Error?r:new Error(String(r))),this.setStatus({state:"idle"})})}runReindex(){return new Promise((t,n)=>{let r=Date.now(),i=this.indexPaths.dbPath+".tmp",s=Sd(this.indexPaths.indexPath),o=yd(new URL("./reindex-worker.js",import.meta.url).pathname,[],{env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:this.projectRoot,SCIP_REINDEX_OUTPUT_SCIP:s,SCIP_REINDEX_OUTPUT_DB:i,SCIP_REINDEX_LANGUAGES:this.languages?.join(",")??"",SCIP_REINDEX_PNPM_WORKSPACES:this.pnpmWorkspaces?"1":""},stdio:"pipe"});o.on("exit",a=>{if(a===0)try{Oi(i)&&Mi(i,this.indexPaths.dbPath),Oi(s)&&Mi(s,this.indexPaths.indexPath),t(Date.now()-r)}catch(l){n(new Error(`Atomic swap failed: ${l}`))}else n(new Error(`Reindex worker exited with code ${a}`))}),o.on("error",n)})}setStatus(t){this.status=t,this.onStatus(t)}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}clearCooldownTimer(){this.cooldownTimer&&(clearTimeout(this.cooldownTimer),this.cooldownTimer=null)}};function Sd(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}import{existsSync as rr,mkdirSync as xd,symlinkSync as _d,readlinkSync as Id,unlinkSync as Rd}from"fs";import{join as Qt,dirname as Fi,resolve as ir}from"path";import{homedir as Ti,platform as Cd}from"os";import{fileURLToPath as vd}from"url";var Nd=Cd()==="win32",sr=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function $i(e={}){let t=e.quiet?()=>{}:console.log,n=vd(import.meta.url),r=ir(Fi(n),"..","skills"),i=[Qt(Ti(),".claude","skills"),Qt(Ti(),".codex","skills")],s={installed:[],skipped:[],alreadyLinked:[]};for(let o of i){let a=Fi(o);if(!rr(a))continue;xd(o,{recursive:!0});let l=o.includes(".codex")?"Codex":"Claude";for(let c of sr){let u=Qt(r,c),d=Qt(o,c);if(!rr(u)){s.skipped.push(`${l}/${c}`);continue}if(rr(d)){try{let m=Id(d);if(ir(m)===ir(u)){s.alreadyLinked.push(`${l}/${c}`),t(` ok: ${c} \u2192 ${l} (already linked)`);continue}}catch{s.skipped.push(`${l}/${c}`),t(` skip: ${c} \u2192 ${l} (exists, not a symlink)`);continue}Rd(d)}_d(u,d,Nd?"junction":"dir"),s.installed.push(`${l}/${c}`),t(` done: ${c} \u2192 ${l}`)}}return s}function be(e){return e+1}function me(e,t){return`${be(e)}-${be(t)}`}function pe(e,t,n){return`${e}:${me(t,n)}`}var b={empty(e){console.log(e)},list(e,t){for(let n of e)console.log(t(n))},groupedByFile(e,t,n=r=>r.relativePath){let r="";for(let i of e){let s=n(i);s!==r&&(r&&console.log(""),console.log(s),r=s),console.log(t(i))}},sectionedReport(e){let t=!0;for(let n of e)if(!(n.skipIfEmpty&&n.rows.length===0)){t||console.log(""),t=!1,n.title!==void 0&&console.log(`\u2550\u2550\u2550 ${n.title} \u2550\u2550\u2550`),n.explanation!==void 0&&console.log(n.explanation);for(let r of n.rows)console.log(r)}},table(e,t,n){console.log(` ${e.join(" ")}`);let r=n??e.map(i=>i.length);console.log(` ${r.map(i=>"\u2500".repeat(i)).join(" ")}`);for(let i of t)console.log(i)}};import{existsSync as Va}from"fs";import{join as CS}from"path";import Ed from"better-sqlite3";var Xt=class{db;config;pathFilter;constructor(t,n){this.config=t,this.pathFilter=n??null,this.db=new Ed(t.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000")}isIgnored(t){return this.pathFilter?.isIgnored(t)??!1}get localSymbolPredicate(){return`(
146
146
  EXISTS (
147
147
  SELECT 1
148
148
  FROM defn_enclosing_ranges local_der
@@ -160,11 +160,11 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
160
160
  ${this.pathExclusionsFor("local_d").trimStart()}
161
161
  )
162
162
  )`}get pathExclusions(){return this.pathExclusionsFor("d")}get symbolNoise(){return this.symbolNoiseFor("gs")}pathExclusionsFor(...t){return t.flatMap(n=>[`AND ${n}.relative_path NOT LIKE 'node_modules/%'`,`AND ${n}.relative_path NOT LIKE '.git/%'`]).join(`
163
- `)}symbolNoiseFor(t){return`AND ${t}.symbol NOT LIKE '%().(%' AND ${t}.symbol NOT LIKE '%typeLiteral%'`}all(t,...n){return this.db.prepare(t).all(...n)}get(t,...n){return this.db.prepare(t).get(...n)}close(){this.db.close()}};var x={};Va(x,{affected:()=>ca,bottlenecks:()=>Ho,byKind:()=>Vo,callGraph:()=>Ko,changeSurface:()=>ua,code:()=>Da,complexity:()=>ka,complexityHotspots:()=>On,convergence:()=>va,coupling:()=>Ao,cycles:()=>Rn,dataflow:()=>wa,dead:()=>In,deepChains:()=>zo,deps:()=>So,diffImpact:()=>pa,drift:()=>Dn,extractCandidates:()=>Nn,fanIn:()=>Mo,fanOut:()=>Fo,files:()=>$i,health:()=>Ra,hierarchy:()=>Go,hotspots:()=>vo,importedBy:()=>Do,imports:()=>Eo,isolated:()=>Cn,kindCounts:()=>Uo,members:()=>Oo,methods:()=>ho,outline:()=>Po,passthroughCandidates:()=>wn,rdeps:()=>xo,redundantReexports:()=>Oa,refs:()=>yo,similar:()=>Xo,similarAll:()=>vn,similarChains:()=>aa,similarFiles:()=>sa,similarSignatures:()=>Fa,slice:()=>Pa,staleAbstractions:()=>Pn,stats:()=>Zt,surface:()=>Io,symbols:()=>os,system:()=>_o,topCoupling:()=>jo,topFanIn:()=>To,topFanOut:()=>$o,trace:()=>bo,unusedImports:()=>Lo,wrapperCandidates:()=>kn});import{statSync as _d}from"fs";function Zt(e){let t=e.get("SELECT COUNT(*) as c FROM documents").c,n=e.get("SELECT COUNT(*) as c FROM global_symbols").c,r=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:t,symbols:n,definitions:r,references:i,...Id(e.config.dbPath)}}function Id(e){try{let t=_d(e);return{indexSizeBytes:t.size,lastBuilt:t.mtime}}catch{return{indexSizeBytes:0,lastBuilt:null}}}function Rd(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function $i(e,t){let n=Rd(t);return e.all(`SELECT relative_path FROM documents
163
+ `)}symbolNoiseFor(t){return`AND ${t}.symbol NOT LIKE '%().(%' AND ${t}.symbol NOT LIKE '%typeLiteral%'`}all(t,...n){return this.db.prepare(t).all(...n)}get(t,...n){return this.db.prepare(t).get(...n)}close(){this.db.close()}};var x={};Ka(x,{affected:()=>ga,bottlenecks:()=>Go,byKind:()=>Ko,callGraph:()=>ta,changeSurface:()=>ha,code:()=>Ma,complexity:()=>Ta,complexityHotspots:()=>Pn,convergence:()=>wa,coupling:()=>Uo,cycles:()=>In,dataflow:()=>$a,dead:()=>_n,deepChains:()=>Zo,deps:()=>vo,diffImpact:()=>Sa,drift:()=>En,extractCandidates:()=>vn,fanIn:()=>Bo,fanOut:()=>Wo,files:()=>Ai,health:()=>La,hierarchy:()=>ea,hotspots:()=>wo,importedBy:()=>Mo,imports:()=>Oo,isolated:()=>Rn,kindCounts:()=>Yo,members:()=>jo,methods:()=>Io,outline:()=>Ao,passthroughCandidates:()=>kn,rdeps:()=>No,redundantReexports:()=>ja,refs:()=>Ro,similar:()=>ia,similarAll:()=>Cn,similarChains:()=>pa,similarFiles:()=>da,similarSignatures:()=>Wa,slice:()=>Aa,staleAbstractions:()=>wn,stats:()=>Zt,surface:()=>Do,symbols:()=>as,system:()=>Eo,topCoupling:()=>Jo,topFanIn:()=>Ho,topFanOut:()=>Vo,trace:()=>Co,unusedImports:()=>Fo,wrapperCandidates:()=>Ln});import{statSync as Dd}from"fs";function Zt(e){let t=e.get("SELECT COUNT(*) as c FROM documents").c,n=e.get("SELECT COUNT(*) as c FROM global_symbols").c,r=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:t,symbols:n,definitions:r,references:i,...Ld(e.config.dbPath)}}function Ld(e){try{let t=Dd(e);return{indexSizeBytes:t.size,lastBuilt:t.mtime}}catch{return{indexSizeBytes:0,lastBuilt:null}}}function kd(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function Ai(e,t){let n=kd(t);return e.all(`SELECT relative_path FROM documents
164
164
  WHERE relative_path LIKE ?
165
- ORDER BY relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path}))}import{extname as Hi}from"path";import{createRequire as Ld}from"module";import{existsSync as Cd,readFileSync as vd}from"fs";import{join as Nd}from"path";var Ed=$("source-text");function O(e,t){let n=t.replace(/\\/g,"/");return Ed.get(e,n,()=>{let r=Nd(e.config.projectRoot,n);return Cd(r)?vd(r,"utf-8"):""})}var Dd=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift|extract)?/i;function ar(e,t,n){if(n<=0)return!1;let r=O(e,t);if(!r)return!1;let i=r.split(`
166
- `);for(let s=n-1;s>=0&&s>=n-5;s-=1){let o=(i[s]??"").trim();if(o!==""){if(Dd.test(o))return!0;if(!o.startsWith("//")&&!o.startsWith("*")&&!o.startsWith("/*")&&!o.startsWith("@")&&!o.startsWith("#"))return!1}}return!1}var q=Ld(import.meta.url),en=null,Ai=!1;function Vi(){if(Ai)return null;if(en)return en;try{return en=q("tree-sitter"),en}catch{return Ai=!0,null}}var kd={".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"},ji=new Map,lr=new Set;function Ui(e){if(lr.has(e))return null;let t=ji.get(e);if(t)return t;let n;try{switch(e){case"rust":n=q("tree-sitter-rust");break;case"typescript":n=q("tree-sitter-typescript").typescript;break;case"tsx":n=q("tree-sitter-typescript").tsx;break;case"javascript":n=q("tree-sitter-javascript");break;case"python":n=q("tree-sitter-python");break;case"java":n=q("tree-sitter-java");break;case"kotlin":n=q("tree-sitter-kotlin");break;case"scala":n=q("tree-sitter-scala");break;case"ruby":n=q("tree-sitter-ruby");break;case"c":n=q("tree-sitter-c");break;case"cpp":n=q("tree-sitter-cpp");break;case"csharp":n=q("tree-sitter-c-sharp");break;case"php":n=q("tree-sitter-php").php;break;case"vb":{let r=q("tree-sitter-vb-dotnet");n=r.language??r;break}}}catch{return lr.add(e),null}return ji.set(e,n),n}var Bi=new Map;function Ji(e){let t=Bi.get(e);if(t)return t;let n=Ui(e);if(!n)return null;let r=Vi();if(!r)return null;let i=new r;try{i.setLanguage(n)}catch{return lr.add(e),null}return Bi.set(e,i),i}function M(e){return kd[Hi(e).toLowerCase()]??null}function bt(e){return Hi(e).toLowerCase()===".vue"}var qi=Wt("ast-trees");function w(e,t){if(bt(t))return wd(e,t);let n=M(t);if(!n)return null;let r=O(e,t);return r?qi.get(e,t,r,()=>{let i=Ji(n);if(!i)return null;try{return zi(i,r)}catch{return null}}):null}function wd(e,t){let n=O(e,t);return n?qi.get(e,t,n,()=>{let r=Pd(n);if(!r)return null;let i=Ji(r.language);if(!i)return null;let s=`
167
- `.repeat(r.startLine)+r.body;try{return zi(i,s)}catch{return null}}):null}function zi(e,t){return e.parse(r=>r>=t.length?null:t.slice(r,Math.min(t.length,r+16384)))}function Pd(e){let t=[],n=/<script\b([^>]*)>([\s\S]*?)<\/script>/g;for(let l of e.matchAll(n))typeof l.index=="number"&&t.push({tagOpen:l[1]??"",body:l[2]??"",openIdx:l.index+(l[0].length-(l[2]?.length??0)-9)});if(t.length===0)return null;let r=t.find(l=>/\bsetup\b/.test(l.tagOpen))??t[0],s=r.tagOpen.match(/\blang\s*=\s*["']?([\w-]+)/)?.[1]?.toLowerCase(),o=s==="ts"||s==="typescript"?"typescript":s==="tsx"?"tsx":"javascript",a=Od(e,r.openIdx);return{body:r.body,startLine:a,language:o}}function Od(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}var tt=new Map;function Md(e,t){let n=`${e}::${t}`;if(tt.has(n))return tt.get(n)??null;let r=Ui(e);if(!r)return tt.set(n,null),null;let i=Vi();if(!i)return tt.set(n,null),null;try{let s=new i.Query(r,t);return tt.set(n,s),s}catch{return tt.set(n,null),null}}var Fd={rust:`
165
+ ORDER BY relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path}))}import{extname as Vi}from"path";import{createRequire as Td}from"module";import{existsSync as wd,readFileSync as Pd}from"fs";import{join as Od}from"path";var Md=$("source-text");function w(e,t){let n=t.replace(/\\/g,"/");return Md.get(e,n,()=>{let r=Od(e.config.projectRoot,n);return wd(r)?Pd(r,"utf-8"):""})}var Fd=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift|extract)?/i;function or(e,t,n){if(n<=0)return!1;let r=w(e,t);if(!r)return!1;let i=r.split(`
166
+ `);for(let s=n-1;s>=0&&s>=n-5;s-=1){let o=(i[s]??"").trim();if(o!==""){if(Fd.test(o))return!0;if(!o.startsWith("//")&&!o.startsWith("*")&&!o.startsWith("/*")&&!o.startsWith("@")&&!o.startsWith("#"))return!1}}return!1}var q=Td(import.meta.url),en=null,ji=!1;function Ui(){if(ji)return null;if(en)return en;try{return en=q("tree-sitter"),en}catch{return ji=!0,null}}var $d={".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"},Bi=new Map,ar=new Set;function Ji(e){if(ar.has(e))return null;let t=Bi.get(e);if(t)return t;let n;try{switch(e){case"rust":n=q("tree-sitter-rust");break;case"typescript":n=q("tree-sitter-typescript").typescript;break;case"tsx":n=q("tree-sitter-typescript").tsx;break;case"javascript":n=q("tree-sitter-javascript");break;case"python":n=q("tree-sitter-python");break;case"java":n=q("tree-sitter-java");break;case"kotlin":n=q("tree-sitter-kotlin");break;case"scala":n=q("tree-sitter-scala");break;case"ruby":n=q("tree-sitter-ruby");break;case"c":n=q("tree-sitter-c");break;case"cpp":n=q("tree-sitter-cpp");break;case"csharp":n=q("tree-sitter-c-sharp");break;case"php":n=q("tree-sitter-php").php;break;case"vb":{let r=q("tree-sitter-vb-dotnet");n=r.language??r;break}}}catch{return ar.add(e),null}return Bi.set(e,n),n}var Wi=new Map;function qi(e){let t=Wi.get(e);if(t)return t;let n=Ji(e);if(!n)return null;let r=Ui();if(!r)return null;let i=new r;try{i.setLanguage(n)}catch{return ar.add(e),null}return Wi.set(e,i),i}function M(e){return $d[Vi(e).toLowerCase()]??null}function yt(e){return Vi(e).toLowerCase()===".vue"}var zi=Wt("ast-trees");function P(e,t){if(yt(t))return Ad(e,t);let n=M(t);if(!n)return null;let r=w(e,t);return r?zi.get(e,t,r,()=>{let i=qi(n);if(!i)return null;try{return Gi(i,r)}catch{return null}}):null}function Ad(e,t){let n=w(e,t);return n?zi.get(e,t,n,()=>{let r=jd(n);if(!r)return null;let i=qi(r.language);if(!i)return null;let s=`
167
+ `.repeat(r.startLine)+r.body;try{return Gi(i,s)}catch{return null}}):null}function Gi(e,t){return e.parse(r=>r>=t.length?null:t.slice(r,Math.min(t.length,r+16384)))}function jd(e){let t=[],n=/<script\b([^>]*)>([\s\S]*?)<\/script>/g;for(let l of e.matchAll(n))typeof l.index=="number"&&t.push({tagOpen:l[1]??"",body:l[2]??"",openIdx:l.index+(l[0].length-(l[2]?.length??0)-9)});if(t.length===0)return null;let r=t.find(l=>/\bsetup\b/.test(l.tagOpen))??t[0],s=r.tagOpen.match(/\blang\s*=\s*["']?([\w-]+)/)?.[1]?.toLowerCase(),o=s==="ts"||s==="typescript"?"typescript":s==="tsx"?"tsx":"javascript",a=Bd(e,r.openIdx);return{body:r.body,startLine:a,language:o}}function Bd(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}var tt=new Map;function Wd(e,t){let n=`${e}::${t}`;if(tt.has(n))return tt.get(n)??null;let r=Ji(e);if(!r)return tt.set(n,null),null;let i=Ui();if(!i)return tt.set(n,null),null;try{let s=new i.Query(r,t);return tt.set(n,s),s}catch{return tt.set(n,null),null}}var Hd={rust:`
168
168
  (function_item name: (identifier) @name) @def
169
169
  (function_signature_item name: (identifier) @name) @def
170
170
  `,typescript:`
@@ -190,7 +190,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
190
190
  (variable_declarator name: (identifier) @name value: (function_expression)) @def
191
191
  `,python:`
192
192
  (function_definition name: (identifier) @name) @def
193
- `},Td=new WeakMap;function Gi(e,t){return Qi(e,t,Td,Fd,n=>{let r=[];for(let i of n){let s=null,o=null;for(let a of i.captures)a.name==="name"?s=a.node.text:a.name==="def"&&(o={startLine:a.node.startPosition.row,endLine:a.node.endPosition.row});s&&o&&r.push({name:s,startLine:o.startLine,endLine:o.endLine})}return r})}var $d={rust:`
193
+ `},Vd=new WeakMap;function Ki(e,t){return Qi(e,t,Vd,Hd,n=>{let r=[];for(let i of n){let s=null,o=null;for(let a of i.captures)a.name==="name"?s=a.node.text:a.name==="def"&&(o={startLine:a.node.startPosition.row,endLine:a.node.endPosition.row});s&&o&&r.push({name:s,startLine:o.startLine,endLine:o.endLine})}return r})}var Ud={rust:`
194
194
  (call_expression function: (_) @target) @call
195
195
  (macro_invocation macro: (_) @target) @call
196
196
  `,typescript:`
@@ -204,7 +204,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
204
204
  (new_expression constructor: (_) @target) @call
205
205
  `,python:`
206
206
  (call function: (_) @target) @call
207
- `},Ad=new WeakMap;function tn(e,t){return Qi(e,t,Ad,$d,n=>{let r=[];for(let i of n){let s=null,o=null;for(let l of i.captures)l.name==="target"?s=l.node:l.name==="call"&&(o=l.node);if(!s||!o)continue;let a=yt(s);a&&r.push({calleeLeaf:a,memberAccess:jd(s),line:o.startPosition.row})}return r})}function jd(e){switch(e.type){case"field_expression":case"member_expression":case"attribute":return!0;default:return!1}}function Ki(e,t){return nn(e,t,Bd,()=>new Map,(n,r,i)=>{let s=(l,c)=>{if(l===c)return;let d=i.get(l);d||(d=new Set,i.set(l,d)),d.add(c)},o=r==="python"?new Set(["identifier"]):new Set(["type_identifier"]),a=(l,c)=>{let d=u=>{o.has(u.type)&&u.text!==c&&s(u.text,c);for(let m of u.children)d(m)};for(let u of l.children)d(u)};if(r==="rust")for(let l of n.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 d=l.namedChildren.find(u=>u.type==="field_declaration_list"||u.type==="enum_variant_list"||u.type==="ordered_field_declaration_list");d&&a(d,c),l.type==="type_item"&&a(l,c)}else if(r==="python")for(let l of n.rootNode.descendantsOfType("class_definition")){let c=l.namedChildren.find(u=>u.type==="identifier")?.text;if(!c)continue;let d=l.namedChildren.find(u=>u.type==="block");if(d)for(let u of d.descendantsOfType("type"))for(let m of u.descendantsOfType("identifier"))m.text!==c&&s(m.text,c)}else for(let l of n.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let c=l.namedChildren.find(d=>d.type==="type_identifier")?.text;c&&a(l,c)}})??new Map}function nn(e,t,n,r,i){let s=M(t);if(!s)return null;let o=w(e,t);if(!o)return null;let a=n.get(o);if(a)return a;let l=r();return i(o,s,l),n.set(o,l),l}function Qi(e,t,n,r,i){let s=M(t);if(!s)return null;let o=r[s];if(!o)return null;let a=w(e,t);if(!a)return null;let l=n.get(a);if(l)return l;let c=Md(s,o);if(!c)return null;let d=i(c.matches(a.rootNode));return n.set(a,d),d}var Bd=new WeakMap,Wi=new WeakMap;function Yi(e,t,n,r){let i=M(t);if(!i)return null;let s=w(e,t);if(!s)return null;let o=Wi.get(s);return o||(o=Wd(s,i),Wi.set(s,o)),o.get(`${n}:${r}`)??null}function Wd(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{if(n.has(s.type)){let o=s.namedChildren.find(l=>l.type==="parameters"||l.type==="formal_parameters"),a=0;if(o)for(let l of o.namedChildren)l.type==="comment"||l.type==="line_comment"||l.type==="block_comment"||(a+=1);r.set(`${s.startPosition.row}:${s.endPosition.row}`,{paramCount:a})}for(let o of s.children)i(o)};return i(e.rootNode),r}function yt(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 t=e.namedChild(e.namedChildCount-1);return t?yt(t):null}case"scoped_identifier":{let t=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return t?yt(t):null}case"super":case"self":case"this":return null;default:return null}}var Hd={"/":"namespace","#":"type",".":"term","[":"type-param",":":"meta","!":"macro"};function H(e){if(e.startsWith("local "))return{kind:"local",id:e.slice(6),raw:e};let t=e.split(" ");if(t.length<4)return{scheme:t[0]??"",manager:t[1]??"",packageName:t[2]??"",version:"",descriptors:[],raw:e};let n=t[0],r=t[1],i=e.slice(n.length+1+r.length+1),s;if(i.startsWith("`")){let c=i.indexOf("`",1);c===-1?(s=i.slice(1),i=""):(s=i.slice(1,c),i=i.slice(c+2))}else{let c=i.indexOf(" ");c===-1?(s=i,i=""):(s=i.slice(0,c),i=i.slice(c+1))}let o,a=i.indexOf(" ");a===-1?(o=i,i=""):(o=i.slice(0,a),i=i.slice(a+1));let l=Vd(i);return{scheme:n,manager:r,packageName:s,version:o,descriptors:l,raw:e}}function Vd(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="["){let s=e.indexOf("]",n+1);if(s===-1){t.push({name:e.slice(n+1),suffix:"type-param"});break}t.push({name:e.slice(n+1,s),suffix:"type-param"}),n=s+1;continue}if(e[n]==="("&&(t.length===0||n===0||Xi(e[n-1]))){let s=e.indexOf(")",n+1);if(s!==-1&&e[s+1]!=="."){t.push({name:e.slice(n+1,s),suffix:"parameter"}),n=s+1;continue}}let r;if(e[n]==="`"){let s=e.indexOf("`",n+1);if(s===-1){r=e.slice(n+1),t.push({name:r,suffix:"term"});break}r=e.slice(n+1,s),n=s+1}else{let s=n;for(;n<e.length&&!Xi(e[n]);)n++;r=e.slice(s,n)}if(n>=e.length){r&&t.push({name:r,suffix:"term"});break}let i=e[n];if(i==="("){let s=e.indexOf(")",n+1);s!==-1&&e[s+1]==="."?(t.push({name:r,suffix:"method"}),n=s+2):s!==-1?(t.push({name:r,suffix:"method"}),n=s+1):(t.push({name:r,suffix:"term"}),n++)}else{let s=Hd[i];s&&t.push({name:r,suffix:s}),n+=1}}return t}function Xi(e){return e==="/"||e==="#"||e==="."||e==="("||e==="["||e===":"||e==="!"}function h(e){let t=H(e);if("kind"in t&&t.kind==="local")return`local:${t.id}`;let n=t;if(n.descriptors.length===0)return n.raw;let r=[];for(let i of n.descriptors){let s=Ud(i);s&&r.push(s)}return r.join(":")}function Ud(e){let t=e.suffix==="namespace"?Jd(e.name):e.name;return t?e.suffix==="method"?`${t}()`:t:""}function Jd(e){return e.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)$/,"")}function k(e){let t=H(e);if("kind"in t&&t.kind==="local")return t.id;let n=t;return n.descriptors.length===0?"":n.descriptors[n.descriptors.length-1].name}function V(e){let t=H(e);if("kind"in t&&t.kind==="local")return null;let n=t;return n.descriptors[n.descriptors.length-1]?.suffix??null}function U(e){return e.endsWith("().")||V(e)==="method"}function W(e){let t=V(e);return t==="method"||t==="term"}function De(e){return V(e)==="namespace"}var qd=/^rust-analyzer\b.*[\s/]impl#\[[^\]]+\]\[[^\]]+\]/;function rn(e){return qd.test(e)}var zd=new Set(["test","tests","_tests"]);function Le(e){let t=H(e);if("kind"in t)return!1;for(let n=0;n<t.descriptors.length-1;n+=1){let r=t.descriptors[n];if(r?.suffix==="namespace"&&r.name&&zd.has(r.name))return!0}return!1}function Zi(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length!==i.length+1)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function es(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length<=i.length)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function We(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 He(e){if(!e)return null;let t=ts(e);if(t)return t.replace(/\n/g," ");let n=e.indexOf("|");if(n===-1)return e.replace(/\n/g," ");let r=e.slice(n+1);return(ts(r)??r).replace(/\n/g," ")}function ts(e){return/^```(?:\w+)?\s*\n?([\s\S]*?)\n?```/.exec(e.trimStart())?.[1]?.trim()||null}var Gd=$("file-definitions");function ee(e,t){return Gd.get(e,t,()=>{let n=Xd(Kd(e,t),Qd(e,t));return em(e,t,n.map(Yd))})}function Kd(e,t){return e.all(`SELECT
207
+ `},Jd=new WeakMap;function tn(e,t){return Qi(e,t,Jd,Ud,n=>{let r=[];for(let i of n){let s=null,o=null;for(let l of i.captures)l.name==="target"?s=l.node:l.name==="call"&&(o=l.node);if(!s||!o)continue;let a=ht(s);a&&r.push({calleeLeaf:a,memberAccess:qd(s),line:o.startPosition.row})}return r})}function qd(e){switch(e.type){case"field_expression":case"member_expression":case"attribute":return!0;default:return!1}}function Yi(e,t){return nn(e,t,zd,()=>new Map,(n,r,i)=>{let s=(l,c)=>{if(l===c)return;let u=i.get(l);u||(u=new Set,i.set(l,u)),u.add(c)},o=r==="python"?new Set(["identifier"]):new Set(["type_identifier"]),a=(l,c)=>{let u=d=>{o.has(d.type)&&d.text!==c&&s(d.text,c);for(let m of d.children)u(m)};for(let d of l.children)u(d)};if(r==="rust")for(let l of n.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let c=l.namedChildren.find(d=>d.type==="type_identifier")?.text;if(!c)continue;let u=l.namedChildren.find(d=>d.type==="field_declaration_list"||d.type==="enum_variant_list"||d.type==="ordered_field_declaration_list");u&&a(u,c),l.type==="type_item"&&a(l,c)}else if(r==="python")for(let l of n.rootNode.descendantsOfType("class_definition")){let c=l.namedChildren.find(d=>d.type==="identifier")?.text;if(!c)continue;let u=l.namedChildren.find(d=>d.type==="block");if(u)for(let d of u.descendantsOfType("type"))for(let m of d.descendantsOfType("identifier"))m.text!==c&&s(m.text,c)}else for(let l of n.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let c=l.namedChildren.find(u=>u.type==="type_identifier")?.text;c&&a(l,c)}})??new Map}function nn(e,t,n,r,i){let s=M(t);if(!s)return null;let o=P(e,t);if(!o)return null;let a=n.get(o);if(a)return a;let l=r();return i(o,s,l),n.set(o,l),l}function Qi(e,t,n,r,i){let s=M(t);if(!s)return null;let o=r[s];if(!o)return null;let a=P(e,t);if(!a)return null;let l=n.get(a);if(l)return l;let c=Wd(s,o);if(!c)return null;let u=i(c.matches(a.rootNode));return n.set(a,u),u}var zd=new WeakMap,Hi=new WeakMap;function Xi(e,t,n,r){let i=M(t);if(!i)return null;let s=P(e,t);if(!s)return null;let o=Hi.get(s);return o||(o=Gd(s,i),Hi.set(s,o)),o.get(`${n}:${r}`)??null}function Gd(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{if(n.has(s.type)){let o=s.namedChildren.find(l=>l.type==="parameters"||l.type==="formal_parameters"),a=0;if(o)for(let l of o.namedChildren)l.type==="comment"||l.type==="line_comment"||l.type==="block_comment"||(a+=1);r.set(`${s.startPosition.row}:${s.endPosition.row}`,{paramCount:a})}for(let o of s.children)i(o)};return i(e.rootNode),r}function ht(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 t=e.namedChild(e.namedChildCount-1);return t?ht(t):null}case"scoped_identifier":{let t=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return t?ht(t):null}case"super":case"self":case"this":return null;default:return null}}var Kd={"/":"namespace","#":"type",".":"term","[":"type-param",":":"meta","!":"macro"};function H(e){if(e.startsWith("local "))return{kind:"local",id:e.slice(6),raw:e};let t=e.split(" ");if(t.length<4)return{scheme:t[0]??"",manager:t[1]??"",packageName:t[2]??"",version:"",descriptors:[],raw:e};let n=t[0],r=t[1],i=e.slice(n.length+1+r.length+1),s;if(i.startsWith("`")){let c=i.indexOf("`",1);c===-1?(s=i.slice(1),i=""):(s=i.slice(1,c),i=i.slice(c+2))}else{let c=i.indexOf(" ");c===-1?(s=i,i=""):(s=i.slice(0,c),i=i.slice(c+1))}let o,a=i.indexOf(" ");a===-1?(o=i,i=""):(o=i.slice(0,a),i=i.slice(a+1));let l=Yd(i);return{scheme:n,manager:r,packageName:s,version:o,descriptors:l,raw:e}}function Yd(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="["){let s=e.indexOf("]",n+1);if(s===-1){t.push({name:e.slice(n+1),suffix:"type-param"});break}t.push({name:e.slice(n+1,s),suffix:"type-param"}),n=s+1;continue}if(e[n]==="("&&(t.length===0||n===0||Zi(e[n-1]))){let s=e.indexOf(")",n+1);if(s!==-1&&e[s+1]!=="."){t.push({name:e.slice(n+1,s),suffix:"parameter"}),n=s+1;continue}}let r;if(e[n]==="`"){let s=e.indexOf("`",n+1);if(s===-1){r=e.slice(n+1),t.push({name:r,suffix:"term"});break}r=e.slice(n+1,s),n=s+1}else{let s=n;for(;n<e.length&&!Zi(e[n]);)n++;r=e.slice(s,n)}if(n>=e.length){r&&t.push({name:r,suffix:"term"});break}let i=e[n];if(i==="("){let s=e.indexOf(")",n+1);s!==-1&&e[s+1]==="."?(t.push({name:r,suffix:"method"}),n=s+2):s!==-1?(t.push({name:r,suffix:"method"}),n=s+1):(t.push({name:r,suffix:"term"}),n++)}else{let s=Kd[i];s&&t.push({name:r,suffix:s}),n+=1}}return t}function Zi(e){return e==="/"||e==="#"||e==="."||e==="("||e==="["||e===":"||e==="!"}function h(e){let t=H(e);if("kind"in t&&t.kind==="local")return`local:${t.id}`;let n=t;if(n.descriptors.length===0)return n.raw;let r=[];for(let i of n.descriptors){let s=Qd(i);s&&r.push(s)}return r.join(":")}function Qd(e){let t=e.suffix==="namespace"?Xd(e.name):e.name;return t?e.suffix==="method"?`${t}()`:t:""}function Xd(e){return e.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)$/,"")}function D(e){let t=H(e);if("kind"in t&&t.kind==="local")return t.id;let n=t;return n.descriptors.length===0?"":n.descriptors[n.descriptors.length-1].name}function V(e){let t=H(e);if("kind"in t&&t.kind==="local")return null;let n=t;return n.descriptors[n.descriptors.length-1]?.suffix??null}function U(e){return e.endsWith("().")||V(e)==="method"}function W(e){let t=V(e);return t==="method"||t==="term"}function Le(e){return V(e)==="namespace"}var Zd=/^rust-analyzer\b.*[\s/]impl#\[[^\]]+\]\[[^\]]+\]/;function rn(e){return Zd.test(e)}var em=new Set(["test","tests","_tests"]);function ke(e){let t=H(e);if("kind"in t)return!1;for(let n=0;n<t.descriptors.length-1;n+=1){let r=t.descriptors[n];if(r?.suffix==="namespace"&&r.name&&em.has(r.name))return!0}return!1}function es(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length!==i.length+1)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function ts(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length<=i.length)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function He(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 Ve(e){if(!e)return null;let t=ns(e);if(t)return t.replace(/\n/g," ");let n=e.indexOf("|");if(n===-1)return e.replace(/\n/g," ");let r=e.slice(n+1);return(ns(r)??r).replace(/\n/g," ")}function ns(e){return/^```(?:\w+)?\s*\n?([\s\S]*?)\n?```/.exec(e.trimStart())?.[1]?.trim()||null}var tm=$("file-definitions");function Q(e,t){return tm.get(e,t,()=>{let n=sm(nm(e,t),rm(e,t));return am(e,t,n.map(im))})}function nm(e,t){return e.all(`SELECT
208
208
  gs.id,
209
209
  gs.symbol,
210
210
  der.document_id,
@@ -220,7 +220,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
220
220
  JOIN documents d ON der.document_id = d.id
221
221
  WHERE d.relative_path = ?
222
222
  ${e.symbolNoiseFor("gs")}
223
- ORDER BY der.start_line, der.end_line`,t)}function Qd(e,t){return e.all(`SELECT
223
+ ORDER BY der.start_line, der.end_line`,t)}function rm(e,t){return e.all(`SELECT
224
224
  gs.id,
225
225
  gs.symbol,
226
226
  c.document_id,
@@ -239,18 +239,18 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
239
239
  AND m.role = 1
240
240
  ${e.symbolNoiseFor("gs")}
241
241
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
242
- ORDER BY start_line, end_line`,t)}function Yd(e){return{symbolId:e.id,symbol:e.symbol,documentId:e.document_id,startLine:e.start_line,endLine:e.end_line,relativePath:e.relative_path,leaf:k(e.symbol),parentTypeName:Ue(e.symbol),isFunctionLike:W(e.symbol),isTypeLike:V(e.symbol)==="type",kind:e.kind??null,documentation:e.documentation??null,enclosingSymbol:e.enclosing_symbol??null}}function Xd(e,t){let n=new Map;for(let r of t)e.length>0&&!Zd(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()].sort((r,i)=>r.start_line-i.start_line||r.end_line-i.end_line||r.symbol.localeCompare(i.symbol))}function Zd(e){if(Ue(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function oe(e,t={}){return cr(e,t.scope)}function cr(e,t){let n=t?`AND relative_path LIKE '%${t}%'`:"";return e.all(`SELECT relative_path
242
+ ORDER BY start_line, end_line`,t)}function im(e){return{symbolId:e.id,symbol:e.symbol,documentId:e.document_id,startLine:e.start_line,endLine:e.end_line,relativePath:e.relative_path,leaf:D(e.symbol),parentTypeName:Je(e.symbol),isFunctionLike:W(e.symbol),isTypeLike:V(e.symbol)==="type",kind:e.kind??null,documentation:e.documentation??null,enclosingSymbol:e.enclosing_symbol??null}}function sm(e,t){let n=new Map;for(let r of t)e.length>0&&!om(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()].sort((r,i)=>r.start_line-i.start_line||r.end_line-i.end_line||r.symbol.localeCompare(i.symbol))}function om(e){if(Je(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function oe(e,t={}){return lr(e,t.scope)}function lr(e,t){let n=t?`AND relative_path LIKE '%${t}%'`:"";return e.all(`SELECT relative_path
243
243
  FROM documents
244
244
  WHERE 1 = 1
245
245
  ${e.pathExclusionsFor("documents")}
246
246
  ${n}
247
- ORDER BY relative_path`).flatMap(r=>ee(e,r.relative_path)).filter(r=>!e.isIgnored(r.relativePath))}function nt(e,t,n={}){if(t.length===0)return[];let r=t.flatMap(i=>ee(e,i)).filter(i=>!e.isIgnored(i.relativePath));return n.onlyDocumented&&(r=r.filter(i=>i.documentation!==null&&i.documentation!=="")),n.sort&&(r=r.sort((i,s)=>i.relativePath.localeCompare(s.relativePath)||i.startLine-s.startLine||i.endLine-s.endLine)),r.map(i=>({startLine:i.startLine,endLine:i.endLine,symbol:i.symbol,shortName:h(i.symbol),signature:We(He(i.documentation)),relativePath:i.relativePath,enclosingSymbol:i.enclosingSymbol}))}function ae(e,t){let n=null;for(let r of e)r.startLine>t||r.endLine<t||(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}function Ve(e,t){let n=ee(e,t.relative_path).find(r=>r.symbolId===t.id);return n?{symbolId:n.symbolId,symbol:n.symbol,documentId:n.documentId,startLine:n.startLine,endLine:n.endLine,relativePath:n.relativePath}:{symbolId:t.id,symbol:t.symbol,documentId:t.document_id,startLine:t.start_line,endLine:t.end_line,relativePath:t.relative_path}}function em(e,t,n){let r=O(e,t),i=Gi(e,t);return i?om(n,i,r):r?tm(n,r):n}function tm(e,t){let n=t.split(/\r?\n/),r=nm(e,n),i=rm(e,r),s=im(i,n);return sm(e,s)}function nm(e,t){let n=e.some(i=>sn(i.symbol))?lm(t):null,r=new Map;for(let i of e)r.set(i.symbolId,am(t,n,i));return r}function rm(e,t){return e.filter(n=>sn(n.symbol)).map(n=>({definition:n,startLine:t.get(n.symbolId)??n.startLine})).sort((n,r)=>n.startLine-r.startLine||n.definition.startLine-r.definition.startLine||n.definition.symbol.localeCompare(r.definition.symbol))}function im(e,t){let n=new Map;for(let r=0;r<e.length;r+=1){let i=e[r],s=e[r+1],o=s?Math.max(i.startLine,s.startLine-1):t.length-1;n.set(i.definition.symbolId,{startLine:i.startLine,endLine:cm(t,i.definition,i.startLine,o)})}return n}function sm(e,t){return e.map(n=>{let r=t.get(n.symbolId);return r?{...n,startLine:r.startLine,endLine:r.endLine}:n})}function om(e,t,n=null){let r=new Map;for(let i of t){let s=r.get(i.name);s?s.push(i):r.set(i.name,[i])}return e.map(i=>{if(!sn(i.symbol)||!i.leaf)return ns(i,n);let s=r.get(i.leaf);if(!s||s.length===0)return ns(i,n);let o=s[0],a=Math.abs(o.startLine-i.startLine);for(let l=1;l<s.length;l+=1){let c=s[l],d=Math.abs(c.startLine-i.startLine);d<a&&(o=c,a=d)}return{...i,startLine:o.startLine,endLine:o.endLine}})}function ns(e,t){if(!t||!e.leaf||V(e.symbol)!=="term"||Ue(e.symbol)!==null)return e;let n=e.leaf.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`\\b(?:export\\s+)?(?:const|let|var)\\s+${n}\\b`),s=t.split(/\r?\n/).findIndex(o=>r.test(o));return s>=0?{...e,startLine:s,endLine:s}:e}function am(e,t,n){if(!sn(n.symbol))return n.startLine;let r=Math.max(0,Math.min(n.startLine,e.length-1));if(!t)return r;let i=t.get(n.leaf);if(!i||i.length===0)return r;let s=null;for(let o of i){let a=Math.abs(o-n.startLine);(!s||a<s.distance)&&(s={line:o,distance:a})}return s?.line??r}function lm(e){let t=/\b(?:function|def|fn)\s+([A-Za-z_$][\w$]*)/g,n=/\b([A-Za-z_$][\w$]*)\s*[:=]\s*(?:async\s*)?(?:function\b|\()/g,r=/^\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,s=new Map,o=(a,l)=>{let c=s.get(a);if(!c){s.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};for(let a=0;a<e.length;a+=1){let l=e[a]??"";for(let d of l.matchAll(t))d[1]&&o(d[1],a);for(let d of l.matchAll(n))d[1]&&o(d[1],a);let c=l.match(r);c?.[1]&&o(c[1],a);for(let d of l.matchAll(i))d[1]&&o(d[1],a)}return s}function cm(e,t,n,r){let i=Math.max(n,Math.min(e.length-1,r)),s=Math.max(n,Math.min(i,t.endLine)),o=0,a=0,l=!1;for(let c=n;c<=i;c+=1){let d=um(e[c]??"");for(let u of d)u==="{"?(o+=1,l=!0):u==="}"?o=Math.max(0,o-1):u==="("?a+=1:u===")"&&(a=Math.max(0,a-1));if(l&&o===0||!l&&a===0&&c>=s)return c}return s}function um(e){let t="",n=null,r=!1;for(let i=0;i<e.length;i+=1){let s=e[i],o=e[i+1];if(!n&&s==="/"&&o==="/"){t+=" ".repeat(e.length-i);break}if(n){if(r){r=!1,t+=" ";continue}if(s==="\\"){r=!0,t+=" ";continue}s===n&&(n=null),t+=" ";continue}if(s==='"'||s==="'"||s==="`"){n=s,t+=" ";continue}t+=s}return t}function sn(e){return e.includes("().")}function Ue(e){let t=H(e);if("kind"in t)return null;for(let n=t.descriptors.length-2;n>=0;n--){let r=t.descriptors[n];if(r?.suffix==="type")return r.name}return null}function ur(e){let t=H(e);if("kind"in t)return[];let n=[];for(let r=t.descriptors.length-2;r>=0;r-=1){let i=t.descriptors[r];i?.suffix==="type"&&i.name&&n.push(i.name)}return n}import{existsSync as vm}from"fs";import{basename as rs,isAbsolute as Nm,join as Em}from"path";function L(e,t){let n=it(e,t.trim());if(n)return n;let r=hm(e,t);if(r)return r;let i=dm(e,t);return i||gm(e,t)}function dm(e,t){let n=pr(t),r=mr(n);if(!r)return null;let i=`%${r.path}%`,s=r.leaf,a=mm(e,i,s,n)[0];return a?Ve(e,a):null}function mm(e,t,n,r){let i=dr([],[...pm(e,t,n),...fm(e,t,n)]).filter(s=>!e.isIgnored(s.relative_path)).filter(s=>rt(s,r)>1);return i.sort((s,o)=>rt(o,r)-rt(s,r)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.start_line-o.start_line||s.symbol.localeCompare(o.symbol)),i}function pm(e,t,n){return e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
247
+ ORDER BY relative_path`).flatMap(r=>Q(e,r.relative_path)).filter(r=>!e.isIgnored(r.relativePath))}function nt(e,t,n={}){if(t.length===0)return[];let r=t.flatMap(i=>Q(e,i)).filter(i=>!e.isIgnored(i.relativePath));return n.onlyDocumented&&(r=r.filter(i=>i.documentation!==null&&i.documentation!=="")),n.sort&&(r=r.sort((i,s)=>i.relativePath.localeCompare(s.relativePath)||i.startLine-s.startLine||i.endLine-s.endLine)),r.map(i=>({startLine:i.startLine,endLine:i.endLine,symbol:i.symbol,shortName:h(i.symbol),signature:He(Ve(i.documentation)),relativePath:i.relativePath,enclosingSymbol:i.enclosingSymbol}))}function ae(e,t){let n=null;for(let r of e)r.startLine>t||r.endLine<t||(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}function Ue(e,t){let n=Q(e,t.relative_path).find(r=>r.symbolId===t.id);return n?{symbolId:n.symbolId,symbol:n.symbol,documentId:n.documentId,startLine:n.startLine,endLine:n.endLine,relativePath:n.relativePath}:{symbolId:t.id,symbol:t.symbol,documentId:t.document_id,startLine:t.start_line,endLine:t.end_line,relativePath:t.relative_path}}function am(e,t,n){let r=w(e,t),i=Ki(e,t);return i?pm(n,i,r):r?lm(n,r):n}function lm(e,t){let n=t.split(/\r?\n/),r=cm(e,n),i=um(e,r),s=dm(i,n);return mm(e,s)}function cm(e,t){let n=e.some(i=>sn(i.symbol))?gm(t):null,r=new Map;for(let i of e)r.set(i.symbolId,fm(t,n,i));return r}function um(e,t){return e.filter(n=>sn(n.symbol)).map(n=>({definition:n,startLine:t.get(n.symbolId)??n.startLine})).sort((n,r)=>n.startLine-r.startLine||n.definition.startLine-r.definition.startLine||n.definition.symbol.localeCompare(r.definition.symbol))}function dm(e,t){let n=new Map;for(let r=0;r<e.length;r+=1){let i=e[r],s=e[r+1],o=s?Math.max(i.startLine,s.startLine-1):t.length-1;n.set(i.definition.symbolId,{startLine:i.startLine,endLine:hm(t,i.definition,i.startLine,o)})}return n}function mm(e,t){return e.map(n=>{let r=t.get(n.symbolId);return r?{...n,startLine:r.startLine,endLine:r.endLine}:n})}function pm(e,t,n=null){let r=new Map;for(let i of t){let s=r.get(i.name);s?s.push(i):r.set(i.name,[i])}return e.map(i=>{if(!sn(i.symbol)||!i.leaf)return rs(i,n);let s=r.get(i.leaf);if(!s||s.length===0)return rs(i,n);let o=s[0],a=Math.abs(o.startLine-i.startLine);for(let l=1;l<s.length;l+=1){let c=s[l],u=Math.abs(c.startLine-i.startLine);u<a&&(o=c,a=u)}return{...i,startLine:o.startLine,endLine:o.endLine}})}function rs(e,t){if(!t||!e.leaf||V(e.symbol)!=="term"||Je(e.symbol)!==null)return e;let n=e.leaf.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`\\b(?:export\\s+)?(?:const|let|var)\\s+${n}\\b`),s=t.split(/\r?\n/).findIndex(o=>r.test(o));return s>=0?{...e,startLine:s,endLine:s}:e}function fm(e,t,n){if(!sn(n.symbol))return n.startLine;let r=Math.max(0,Math.min(n.startLine,e.length-1));if(!t)return r;let i=t.get(n.leaf);if(!i||i.length===0)return r;let s=null;for(let o of i){let a=Math.abs(o-n.startLine);(!s||a<s.distance)&&(s={line:o,distance:a})}return s?.line??r}function gm(e){let t=/\b(?:function|def|fn)\s+([A-Za-z_$][\w$]*)/g,n=/\b([A-Za-z_$][\w$]*)\s*[:=]\s*(?:async\s*)?(?:function\b|\()/g,r=/^\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,s=new Map,o=(a,l)=>{let c=s.get(a);if(!c){s.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};for(let a=0;a<e.length;a+=1){let l=e[a]??"";for(let u of l.matchAll(t))u[1]&&o(u[1],a);for(let u of l.matchAll(n))u[1]&&o(u[1],a);let c=l.match(r);c?.[1]&&o(c[1],a);for(let u of l.matchAll(i))u[1]&&o(u[1],a)}return s}function hm(e,t,n,r){let i=Math.max(n,Math.min(e.length-1,r)),s=Math.max(n,Math.min(i,t.endLine)),o=0,a=0,l=!1;for(let c=n;c<=i;c+=1){let u=ym(e[c]??"");for(let d of u)d==="{"?(o+=1,l=!0):d==="}"?o=Math.max(0,o-1):d==="("?a+=1:d===")"&&(a=Math.max(0,a-1));if(l&&o===0||!l&&a===0&&c>=s)return c}return s}function ym(e){let t="",n=null,r=!1;for(let i=0;i<e.length;i+=1){let s=e[i],o=e[i+1];if(!n&&s==="/"&&o==="/"){t+=" ".repeat(e.length-i);break}if(n){if(r){r=!1,t+=" ";continue}if(s==="\\"){r=!0,t+=" ";continue}s===n&&(n=null),t+=" ";continue}if(s==='"'||s==="'"||s==="`"){n=s,t+=" ";continue}t+=s}return t}function sn(e){return e.includes("().")}function Je(e){let t=H(e);if("kind"in t)return null;for(let n=t.descriptors.length-2;n>=0;n--){let r=t.descriptors[n];if(r?.suffix==="type")return r.name}return null}function cr(e){let t=H(e);if("kind"in t)return[];let n=[];for(let r=t.descriptors.length-2;r>=0;r-=1){let i=t.descriptors[r];i?.suffix==="type"&&i.name&&n.push(i.name)}return n}import{existsSync as Pm}from"fs";import{basename as is,isAbsolute as Om,join as Mm}from"path";function E(e,t){let n=it(e,t.trim());if(n)return n;let r=Rm(e,t);if(r)return r;let i=bm(e,t);return i||Im(e,t)}function bm(e,t){let n=mr(t),r=dr(n);if(!r)return null;let i=`%${r.path}%`,s=r.leaf,a=Sm(e,i,s,n)[0];return a?Ue(e,a):null}function Sm(e,t,n,r){let i=ur([],[...xm(e,t,n),..._m(e,t,n)]).filter(s=>!e.isIgnored(s.relative_path)).filter(s=>rt(s,r)>1);return i.sort((s,o)=>rt(o,r)-rt(s,r)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.start_line-o.start_line||s.symbol.localeCompare(o.symbol)),i}function xm(e,t,n){return e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
248
248
  FROM global_symbols gs
249
249
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
250
250
  JOIN documents d ON der.document_id = d.id
251
251
  WHERE d.relative_path LIKE ?
252
252
  AND (gs.display_name = ? OR gs.symbol LIKE ?)
253
- ${e.pathExclusionsFor("d")}`,t,n,`%/${n}.%`)}function fm(e,t,n){return e.all(`SELECT
253
+ ${e.pathExclusionsFor("d")}`,t,n,`%/${n}.%`)}function _m(e,t,n){return e.all(`SELECT
254
254
  gs.id,
255
255
  gs.symbol,
256
256
  c.document_id,
@@ -267,7 +267,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
267
267
  AND d.relative_path LIKE ?
268
268
  AND (gs.display_name = ? OR gs.symbol LIKE ?)
269
269
  ${e.pathExclusionsFor("d")}
270
- GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation`,t,n,`%/${n}.%`)}function gm(e,t){let n=pr(t),r=Rm(t),i=xm(e,r),s=Cm(i,t,n);if(s&&!e.isIgnored(s.relative_path))return Ve(e,s);let o=null;for(let a of i){if(e.isIgnored(a.relative_path))continue;let l=Im(a,t,n,r);l<=0||(!o||l>o.score)&&(o={row:a,score:l})}return o?Ve(e,o.row):null}function hm(e,t){let n=t.match(/^(.+):(\d+)-(\d+)$/);if(!n)return null;let[,r,i,s]=n,o=Math.max(0,parseInt(i,10)-1),a=Math.max(o,parseInt(s,10)-1),l=ym(e,r,o,a)??bm(e,r,o,a);return l&&!e.isIgnored(l.relative_path)?Ve(e,l):null}function ym(e,t,n,r){return e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
270
+ GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation`,t,n,`%/${n}.%`)}function Im(e,t){let n=mr(t),r=km(t),i=Em(e,r),s=wm(i,t,n);if(s&&!e.isIgnored(s.relative_path))return Ue(e,s);let o=null;for(let a of i){if(e.isIgnored(a.relative_path))continue;let l=Lm(a,t,n,r);l<=0||(!o||l>o.score)&&(o={row:a,score:l})}return o?Ue(e,o.row):null}function Rm(e,t){let n=t.match(/^(.+):(\d+)-(\d+)$/);if(!n)return null;let[,r,i,s]=n,o=Math.max(0,parseInt(i,10)-1),a=Math.max(o,parseInt(s,10)-1),l=Cm(e,r,o,a)??vm(e,r,o,a);return l&&!e.isIgnored(l.relative_path)?Ue(e,l):null}function Cm(e,t,n,r){return e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
271
271
  FROM global_symbols gs
272
272
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
273
273
  JOIN documents d ON der.document_id = d.id
@@ -275,7 +275,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
275
275
  AND der.start_line <= ? AND der.end_line >= ?
276
276
  ${e.pathExclusionsFor("d")}
277
277
  ORDER BY (der.end_line - der.start_line) ASC
278
- LIMIT 1`,`%${t}%`,n,r)}function bm(e,t,n,r){return 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
278
+ LIMIT 1`,`%${t}%`,n,r)}function vm(e,t,n,r){return 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
279
279
  FROM global_symbols gs
280
280
  JOIN mentions m ON m.symbol_id = gs.id
281
281
  JOIN chunks c ON m.chunk_id = c.id
@@ -309,7 +309,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
309
309
  ${e.pathExclusionsFor("d")}
310
310
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
311
311
  ORDER BY d.relative_path, start_line
312
- LIMIT 1`,t);return!r||e.isIgnored(r.relative_path)?null:Ve(e,r)}function on(e,t){if("symbol"in t&&"relativePath"in t)return t;let n=Sm(e,t.symbolId)[0];return n?Ve(e,n):null}function Sm(e,t){let n=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
312
+ LIMIT 1`,t);return!r||e.isIgnored(r.relative_path)?null:Ue(e,r)}function on(e,t){if("symbol"in t&&"relativePath"in t)return t;let n=Nm(e,t.symbolId)[0];return n?Ue(e,n):null}function Nm(e,t){let n=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
313
313
  FROM global_symbols gs
314
314
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
315
315
  JOIN documents d ON der.document_id = d.id
@@ -331,7 +331,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
331
331
  AND m.role = 1
332
332
  ${e.pathExclusionsFor("d")}
333
333
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation
334
- ORDER BY start_line, end_line`,t);return dr(n,r)}function xm(e,t){let n=t.map(()=>"(gs.symbol LIKE ? OR d.relative_path LIKE ? OR COALESCE(gs.display_name, '') LIKE ?)"),r=t.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, gs.documentation
334
+ ORDER BY start_line, end_line`,t);return ur(n,r)}function Em(e,t){let n=t.map(()=>"(gs.symbol LIKE ? OR d.relative_path LIKE ? OR COALESCE(gs.display_name, '') LIKE ?)"),r=t.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, gs.documentation
335
335
  FROM global_symbols gs
336
336
  JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
337
337
  JOIN documents d ON der.document_id = d.id
@@ -356,17 +356,17 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}}function
356
356
  AND `)}
357
357
  ${e.pathExclusionsFor("d")}
358
358
  GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation
359
- LIMIT 200`,...r);return dr(i,s)}function dr(e,t){let n=new Map;for(let r of t)e.length>0&&!_m(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()]}function _m(e){if(Ue(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function Im(e,t,n,r){let i=t.trim(),s=n,o=s.replace(/\(\)$/,""),a=t.toLowerCase(),l=n.toLowerCase(),c=l.replace(/\(\)$/,""),d=e.symbol,u=h(e.symbol),m=k(e.symbol),f=e.display_name??"",p=e.symbol.toLowerCase(),g=u.toLowerCase(),y=m.toLowerCase(),E=f.toLowerCase(),N=e.relative_path.toLowerCase(),F=/[/:.]/.test(n),T=mr(n),R=T?.leaf.toLowerCase(),_=0;return(d===i||d===s)&&(_+=1150),(u===i||u===s)&&(_+=1100),f===o&&(_+=1180),m===o&&(_+=1160),(`${m}()`===i||`${m}()`===s)&&(_+=955),(p===a||p===l)&&(_+=1e3),(g===a||g===l)&&(_+=950),(N===a||N===l)&&(_+=925),(N.endsWith(`/${l}`)||N.endsWith(`/${a}`))&&(_+=875),E===c&&(_+=850),y===c&&(_+=825),(`${y}()`===a||`${y}()`===l)&&(_+=820),(g.endsWith(`:${l}`)||g.endsWith(`:${c}`)||g.endsWith(`:${c}()`))&&(_+=800),p.includes(l)&&(_+=120),g.includes(l)&&(_+=140),N.includes(l)&&(_+=140),E.includes(l)&&(_+=110),r.every(P=>{let D=P.toLowerCase();return p.includes(D)||g.includes(D)||N.includes(D)||E.includes(D)})&&(_+=100+r.length*15),T&&N.includes(T.path.toLowerCase())&&(_+=360,R&&(y===R||`${y}()`===R||`${y}()`==`${R}()`)&&(_+=700),U(e.symbol)&&(_+=180)),W(e.symbol)&&y===c&&(_+=60),!F&&De(e.symbol)&&(_-=160),_-=Math.min(50,Math.max(0,e.end_line-e.start_line)),_}function mr(e){let t=e.trim().replace(/\\/g,"/"),n=t.lastIndexOf("/");if(n<=0||n===t.length-1)return null;let r=t.slice(n+1).replace(/\(\)$/,"");return!r||r.includes(".")?null:{path:t.slice(0,n),leaf:r}}function pr(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function Rm(e){let t=pr(e),n=t.split(/[^A-Za-z0-9_]+/).map(r=>r.trim()).filter(r=>r.length>0);return n.length>0?[...new Set(n)]:[t]}function Cm(e,t,n){let r=t.trim(),i=e.filter(s=>{let o=h(s.symbol),a=(s.display_name??"").trim();return s.symbol===r||o===r||o===n||a===r||a===n||`${a}()`===r||rt(s,n)>1||s.relative_path===r});return i.length===0?null:(i.sort((s,o)=>rt(o,n)-rt(s,n)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.relative_path.localeCompare(o.relative_path)||s.symbol.localeCompare(o.symbol)),i[0]??null)}function rt(e,t){let n=mr(t);if(!n)return 0;let r=e.relative_path.toLowerCase(),i=k(e.symbol).toLowerCase(),s=n.path.toLowerCase(),o=n.leaf.toLowerCase();return r.includes(s)?i!==o?1:U(e.symbol)?Ue(e.symbol)===null?5:4:Ue(e.symbol)===null?3:2:0}function G(e,t){let n=is(e,t,{allowMultiple:!1})[0]?.relativePath;return n||Dm(e,t)}function ke(e,t){return is(e,t,{allowMultiple:!0}).map(n=>n.relativePath)}function Dm(e,t){if(!t)return null;let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=Nm(n)&&n.startsWith(e.config.projectRoot)?n.slice(e.config.projectRoot.length).replace(/^\/+/,""):n,i=Em(e.config.projectRoot,r);return vm(i)?r:null}function is(e,t,n){let r=ss(t);if(!r)return[];let s=e.all(`SELECT relative_path
359
+ LIMIT 200`,...r);return ur(i,s)}function ur(e,t){let n=new Map;for(let r of t)e.length>0&&!Dm(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()]}function Dm(e){if(Je(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function Lm(e,t,n,r){let i=t.trim(),s=n,o=s.replace(/\(\)$/,""),a=t.toLowerCase(),l=n.toLowerCase(),c=l.replace(/\(\)$/,""),u=e.symbol,d=h(e.symbol),m=D(e.symbol),g=e.display_name??"",p=e.symbol.toLowerCase(),f=d.toLowerCase(),y=m.toLowerCase(),L=g.toLowerCase(),k=e.relative_path.toLowerCase(),F=/[/:.]/.test(n),T=dr(n),R=T?.leaf.toLowerCase(),_=0;return(u===i||u===s)&&(_+=1150),(d===i||d===s)&&(_+=1100),g===o&&(_+=1180),m===o&&(_+=1160),(`${m}()`===i||`${m}()`===s)&&(_+=955),(p===a||p===l)&&(_+=1e3),(f===a||f===l)&&(_+=950),(k===a||k===l)&&(_+=925),(k.endsWith(`/${l}`)||k.endsWith(`/${a}`))&&(_+=875),L===c&&(_+=850),y===c&&(_+=825),(`${y}()`===a||`${y}()`===l)&&(_+=820),(f.endsWith(`:${l}`)||f.endsWith(`:${c}`)||f.endsWith(`:${c}()`))&&(_+=800),p.includes(l)&&(_+=120),f.includes(l)&&(_+=140),k.includes(l)&&(_+=140),L.includes(l)&&(_+=110),r.every(O=>{let N=O.toLowerCase();return p.includes(N)||f.includes(N)||k.includes(N)||L.includes(N)})&&(_+=100+r.length*15),T&&k.includes(T.path.toLowerCase())&&(_+=360,R&&(y===R||`${y}()`===R||`${y}()`==`${R}()`)&&(_+=700),U(e.symbol)&&(_+=180)),W(e.symbol)&&y===c&&(_+=60),!F&&Le(e.symbol)&&(_-=160),_-=Math.min(50,Math.max(0,e.end_line-e.start_line)),_}function dr(e){let t=e.trim().replace(/\\/g,"/"),n=t.lastIndexOf("/");if(n<=0||n===t.length-1)return null;let r=t.slice(n+1).replace(/\(\)$/,"");return!r||r.includes(".")?null:{path:t.slice(0,n),leaf:r}}function mr(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function km(e){let t=mr(e),n=t.split(/[^A-Za-z0-9_]+/).map(r=>r.trim()).filter(r=>r.length>0);return n.length>0?[...new Set(n)]:[t]}function wm(e,t,n){let r=t.trim(),i=e.filter(s=>{let o=h(s.symbol),a=(s.display_name??"").trim();return s.symbol===r||o===r||o===n||a===r||a===n||`${a}()`===r||rt(s,n)>1||s.relative_path===r});return i.length===0?null:(i.sort((s,o)=>rt(o,n)-rt(s,n)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.relative_path.localeCompare(o.relative_path)||s.symbol.localeCompare(o.symbol)),i[0]??null)}function rt(e,t){let n=dr(t);if(!n)return 0;let r=e.relative_path.toLowerCase(),i=D(e.symbol).toLowerCase(),s=n.path.toLowerCase(),o=n.leaf.toLowerCase();return r.includes(s)?i!==o?1:U(e.symbol)?Je(e.symbol)===null?5:4:Je(e.symbol)===null?3:2:0}function G(e,t){let n=ss(e,t,{allowMultiple:!1})[0]?.relativePath;return n||Fm(e,t)}function we(e,t){return ss(e,t,{allowMultiple:!0}).map(n=>n.relativePath)}function Fm(e,t){if(!t)return null;let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=Om(n)&&n.startsWith(e.config.projectRoot)?n.slice(e.config.projectRoot.length).replace(/^\/+/,""):n,i=Mm(e.config.projectRoot,r);return Pm(i)?r:null}function ss(e,t,n){let r=os(t);if(!r)return[];let s=e.all(`SELECT relative_path
360
360
  FROM documents
361
361
  WHERE 1 = 1
362
362
  ${e.pathExclusionsFor("documents")}
363
- ORDER BY relative_path`).filter(l=>!e.isIgnored(l.relative_path)).map(l=>({relativePath:l.relative_path,score:Lm(l.relative_path,r)})).filter(l=>l.score>0).sort((l,c)=>c.score-l.score||l.relativePath.localeCompare(c.relativePath));if(s.length===0){let l=L(e,t);return!l||e.isIgnored(l.relativePath)?[]:[{relativePath:l.relativePath,score:700}]}let o=s.filter(l=>l.score>=1100);if(o.length>0)return n.allowMultiple?o:[o[0]];let a=s.filter(l=>l.score>=800);return a.length>0?n.allowMultiple?a:[a[0]]:n.allowMultiple?s:[s[0]]}function Lm(e,t){let n=ss(e),r=rs(n),i=rs(t),s=0;return n===t&&(s+=1200),n.endsWith(`/${t}`)&&(s+=1100),r===i&&(s+=900),n.startsWith(`${t}/`)&&(s+=850),n.includes(t)&&(s+=250),s}function ss(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function os(e,t){let n=ke(e,t);return nt(e,n).map(({relativePath:r,...i})=>i)}import{basename as Tg}from"path";var St=new WeakMap;function cs(e,t){let n=M(t);return n==="rust"?Mm(e,t):n==="typescript"||n==="tsx"||n==="javascript"?wm(e,t):[]}var km=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function wm(e,t){let n=w(e,t);if(!n)return[];let r=St.get(n);if(r)return r;let i=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(t)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(t),s=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(t),o=!1,a=n.rootNode;for(let c of a.namedChildren){if(c.type!=="expression_statement")continue;let d=c.namedChild(0);if(!d||d.type!=="call_expression")continue;let u=d.namedChild(0);if(!u)continue;let m=u.type==="member_expression"?u.namedChild(u.namedChildCount-1)?.text:u.text;if(m&&km.has(m)){o=!0;break}}let l=[];o&&l.push({startLine:0,endLine:a.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(i||s)&&l.push({startLine:0,endLine:a.endPosition.row,reason:i?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of a.namedChildren){let d=null,u=null;if(c.type==="function_declaration")d=c.namedChild(0)?.text??null,u=c;else if(c.type==="export_statement"){let m=c.namedChild(0);m?.type==="function_declaration"&&(d=m.namedChild(0)?.text??null,u=m)}else if(c.type==="lexical_declaration"){let m=c.namedChild(0);if(m?.type==="variable_declarator"){let f=m.namedChild(0)?.text,p=m.namedChild(1);f&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(d=f,u=m)}}d&&/^use[A-Z]/.test(d)&&u&&l.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...us(n,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),St.set(n,l),l}var Pm=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function Om(e){return Pm.test(e)}function us(e,t,n){let r=[],i=s=>{if(t.has(s.type)&&s.parent){let a=s.parent.children,l=-1;for(let c=0;c<a.length;c+=1)if(a[c].startIndex===s.startIndex&&a[c].type===s.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let d=a[c];if(n.has(d.type)){if(Om(d.text)){r.push({startLine:s.startPosition.row,endLine:s.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(d.type==="attribute_item"||d.type==="inner_attribute_item"))break}}for(let o of s.namedChildren)i(o)};return i(e.rootNode),r}function Mm(e,t){let n=w(e,t);if(!n)return[];let r=St.get(n);if(r)return r;let i=[],s=Fm(n);return s?(St.set(n,s),s):(ds(n.rootNode,i,!1,!1),i.push(...us(n,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"]))),i.push(...Wm(n.rootNode)),St.set(n,i),i)}function Fm(e){return Hm(e.rootNode)?[{startLine:0,endLine:e.rootNode.endPosition.row,reason:"generated file (@generated header)"}]:null}function ds(e,t,n,r){let i=n,s=r;e.type==="trait_item"&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait declaration body (dynamic dispatch)"}),e.type==="impl_item"&&e.childForFieldName("trait")&&(s=!0,t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl block (dynamic dispatch)"})),e.type==="function_item"||e.type==="function_signature_item"?Tm(e,t,n,r):r&&Bm(e)?t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl associated item (dynamic dispatch)"}):e.type==="struct_item"||e.type==="enum_item"||e.type==="union_item"?$m(e,t,n):e.type==="mod_item"&&fr(e).some(o=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(o))&&(i=!0);for(let o of e.namedChildren)ds(o,t,i,s)}function Tm(e,t,n,r){let i=fr(e),s=null;r?s="trait impl method (dynamic dispatch)":n&&(s="inside #[cfg(test)] mod");for(let o of i){let a=Am(o);if(a){s=a;break}if(ms(o)){s="#[allow(dead_code)]";break}}s&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:s})}function $m(e,t,n){let r=fr(e),i=e.namedChildren.find(s=>s.type==="type_identifier")?.text;r.some(jm)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:i}),r.some(ms)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[allow(dead_code)]",containerName:i}),n&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:i})}function fr(e){let t=e.parent;if(!t)return[];let n=t.children,r=-1;for(let s=0;s<n.length;s+=1)if(n[s].startIndex===e.startIndex&&n[s].type===e.type){r=s;break}if(r<=0)return[];let i=[];for(let s=r-1;s>=0;s-=1){let o=n[s];if(o.type==="attribute_item"||o.type==="inner_attribute_item")i.push(o.text);else{if(o.type==="line_comment"||o.type==="block_comment")continue;break}}return i}function Am(e){return/#\[\s*tauri::command\b/.test(e)?"#[tauri::command]":/#\[\s*command\b/.test(e)?"#[command]":/#\[\s*test\b/.test(e)?"#[test]":/#\[\s*bench\b/.test(e)?"#[bench]":/#\[\s*tokio::test\b/.test(e)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(e)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(e)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(e)?"#[no_mangle]":/#\[\s*napi\b/.test(e)?"#[napi]":/#\[\s*pyfunction\b/.test(e)?"#[pyfunction]":/#\[\s*pymethod\b/.test(e)?"#[pymethod]":/#\[\s*pyo3\b/.test(e)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(e)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(e)?"#[doc(hidden)]":null}function jm(e){return/#\[\s*derive\s*\(/.test(e)?/\bSerialize\b/.test(e)||/\bDeserialize\b/.test(e)||/\bFromRow\b/.test(e)||/\bDeriveEntityModel\b/.test(e)||/\bIntoSchema\b/.test(e)||/\bToSchema\b/.test(e)||/\bDeriveValueType\b/.test(e)||/\bsqlx::FromRow\b/.test(e)||/\bError\b/.test(e)||/\bthiserror::Error\b/.test(e):!1}function ms(e){return/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(e)}function Bm(e){return e.type==="const_item"||e.type==="type_item"||e.type==="static_item"||e.type==="associated_type"}function Wm(e){let t=zm(e);if(t.size===0)return[];let n=[];for(let r of e.descendantsOfType("mod_item")){let i=r.childForFieldName("name")?.text;i&&t.has(i)&&n.push({startLine:r.startPosition.row,endLine:r.endPosition.row,reason:'serde `with = "..."` module \u2014 body invoked via reflection',containerName:i})}return n}function Hm(e){for(let t=0;t<Math.min(e.namedChildCount,12);t+=1){let n=e.namedChild(t);if(!n||n.type!=="line_comment"&&n.type!=="block_comment")break;if(/@generated\b/.test(n.text)||/This file is .*generated\b/i.test(n.text)||/Code generated by/i.test(n.text)||/Generated by:\s*https?:\/\/openapi-generator/i.test(n.text)||/openapi-generator/i.test(n.text)&&/Generated by/i.test(n.text))return!0}return!1}var Vm=[{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}],ps=/^#!?\[\s*serde\s*\(/,Um=/^#!?\[\s*schemars\s*\(/,Jm=/^#!?\[\s*validate\s*\(/,as=/\bwith\s*=\s*"([^"]+)"/g;function st(e,t){return nn(e,t,qm,()=>new Set,(n,r,i)=>{if(r==="rust"){for(let s of n.rootNode.descendantsOfType("attribute_item"))ls(s.text,i);for(let s of n.rootNode.descendantsOfType("inner_attribute_item"))ls(s.text,i)}})??new Set}var qm=new WeakMap;function ls(e,t){let n=ps.test(e),r=Um.test(e),i=Jm.test(e);if(!(!n&&!r&&!i))for(let{re:s}of Vm){s.lastIndex=0;let o;for(;(o=s.exec(e))!==null;){let a=o[1],l=a.split("::").pop()??a;l==="is_none"&&/\bOption\b/.test(a)||l==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(a)||l&&t.add(l)}}}function zm(e){let t=new Set;for(let n of e.descendantsOfType("attribute_item")){if(!ps.test(n.text))continue;as.lastIndex=0;let r;for(;(r=as.exec(n.text))!==null;){let i=r[1],s=i.split("::").pop()??i;s&&t.add(s)}}return t}var Gm=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function fs(e,t){return nn(e,t,Km,()=>new Set,(n,r,i)=>{if(!(r!=="typescript"&&r!=="tsx"&&r!=="javascript"))for(let s of n.rootNode.descendantsOfType("call_expression")){let o=s.namedChild(0);if(!o)continue;let a=yt(o);if(!a||!Gm.has(a))continue;let l=s.namedChildren.find(u=>u.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let d=c.namedChildren.find(u=>u.type==="string_fragment");d&&i.add(d.text)}})??new Set}var Km=new WeakMap;function an(e){return e.replace(/'''[\s\S]*?'''/g,we).replace(/"""[\s\S]*?"""/g,we).replace(/#.*$/gm,we).replace(/\/\/.*$/gm,we).replace(/\/\*[\s\S]*?\*\//g,we).replace(/`(?:\\[\s\S]|[^`])*`/g,we).replace(/'(?:\\.|[^'\\\r\n])*'/g,we).replace(/"(?:\\.|[^"\\\r\n])*"/g,we)}function we(e){return e.replace(/[^\r\n]/g," ")}var Qm=Wt("stripped-lines");function hs(e,t,n){return Qm.get(e,t,n,()=>an(n).split(`
364
- `))}var gs=null,gr="";function Ym(e){return gs===e||(gs=e,gr=an(e)),gr}function Pe(e,t,n){let r=Ym(e);return`${r.slice(0,t)}${" ".repeat(n-t)}${r.slice(n)}`}function K(e,t){return new RegExp(`\\b${ln(t)}\\b`,"m").test(e)}function ot(e,t){let n=new Set,r=new RegExp(`\\b${ln(t)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let i of e.matchAll(r)){let s=i[1];s&&n.add(s)}return[...n]}function ln(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cn(e,t,n,r={}){if(!n)return[];let i=O(e,t);if(!i)return[];if(i.indexOf(n)===-1)return[];if(M(t))return(Je(e,t).get(n)??[]).filter(d=>!ys(d,r));let s=hs(e,t,i),o=new RegExp(`\\b${ln(n)}\\b`),a=[];for(let l=0;l<s.length;l++)ys(l,r)||o.test(s[l]??"")&&a.push(l);return a}function ys(e,t){return typeof t.excludeStartLine=="number"&&typeof t.excludeEndLine=="number"&&e>=t.excludeStartLine&&e<=t.excludeEndLine}var Xm=$("file-identifiers");function bs(e,t){return Xm.get(e,t,()=>new Set(Je(e,t).keys()))}var Zm=$("file-ident-lines");function Je(e,t){return Zm.get(e,t,()=>tp(e,t))}var ep=$("file-idents-by-line");function Ss(e,t){return ep.get(e,t,()=>{let n=Je(e,t),r=0;for(let s of n.values()){let o=s[s.length-1];o!==void 0&&o>r&&(r=o)}let i=new Array(r+1);for(let s=0;s<=r;s+=1)i[s]=new Set;for(let[s,o]of n)for(let a of o)i[a].add(s);return i})}function tp(e,t){let n=new Map,r=(a,l)=>{let c=n.get(a);if(!c){n.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};if(M(t)){let a=w(e,t);if(a){let l=M(t),c=l==="rust"?new Set(["identifier","type_identifier","field_identifier"]):l==="python"?new Set(["identifier"]):new Set(["identifier","property_identifier","type_identifier"]),d=new Set(["rust","python"]),u=/\{([^{}]*)\}/g,m=/\b([A-Za-z_][\w]*)\b/g,f=p=>{if(c.has(p.type)&&r(p.text,p.startPosition.row),l&&d.has(l)&&p.type==="string_content"){let g=p.startPosition.row;for(let y of p.text.matchAll(u)){let E=y[1]??"";for(let N of E.matchAll(m))N[1]&&r(N[1],g)}}for(let g of p.children)f(g)};return f(a.rootNode),n}}let i=O(e,t);if(!i)return n;let s=an(i).split(/\r?\n/),o=/\b([A-Za-z_$][\w$]*)\b/g;for(let a=0;a<s.length;a+=1){let l=s[a]??"";for(let c of l.matchAll(o))c[1]&&r(c[1],a)}return n}import{existsSync as Ws,readFileSync as Hs}from"fs";import{join as Vs}from"path";import{existsSync as dn}from"fs";import{basename as np,dirname as Oe,extname as Se,join as le,relative as xt,resolve as te}from"path";var rp=$e("indexed-paths"),un=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],hr=[".py",".pyi"],ce=[".java",".scala",".kt",".kts"],yr=[".rs"],br=[".rb"],xs=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],at=[".cs",".vb"],Sr=[".dart"],_t=[".php"],ip=[un,hr,ce,yr,br,xs,at,Sr,_t];function Me(e,t){return t.includes(Se(e).toLowerCase())}function sp(e){return Me(e,hr)}function op(e){return Me(e,ce)}function ap(e){return Me(e,yr)}function lp(e){return Me(e,br)}function cp(e){return Me(e,xs)}function up(e){return Me(e,at)}function _s(e){return Se(e).toLowerCase()===".vb"}function dp(e){return Me(e,Sr)}function mp(e){return Me(e,_t)}function xr(e){let t=Se(e).toLowerCase();for(let n of ip)if(n.includes(t))return n;return un}function pp(e){return op(e)||up(e)||mp(e)}function ge(e,t,n){return sp(t)?lt(e,t,n):ap(t)?xe(e,t,n):lp(t)?mn(e,t,n):cp(t)?pn(e,t,n):pp(t)?j(e,n.replace(/\\/g,"."),xr(t)):dp(t)?fn(e,t,n):fp(e,t,n)}function fp(e,t,n){if(!n.startsWith(".")&&!n.startsWith("/"))return null;let r=Oe(le(e.config.projectRoot,t)),i=te(r,n),s=It(e);for(let o of Sp(i)){let a=fe(xt(e.config.projectRoot,o));if(s.has(a)||dn(o))return a}return fe(xt(e.config.projectRoot,i))}function lt(e,t,n){let r=It(e),i;if(n.startsWith(".")){let s=n.match(/^(\.+)(.*)$/);if(!s)return null;let o=s[1].length,a=s[2].replace(/^\./,""),l=Oe(le(e.config.projectRoot,t));for(let c=1;c<o;c++)l=Oe(l);i=a?te(l,a.replace(/\./g,"/")):l}else i=te(e.config.projectRoot,n.replace(/\./g,"/"));for(let s of gp(i)){let o=fe(xt(e.config.projectRoot,s));if(r.has(o)||dn(s))return o}return null}function xe(e,t,n){if(!n)return null;let r=n.replace(/\s+as\s+.+$/,"").trim();if(!r.startsWith("crate::")&&!r.startsWith("self::")&&!r.startsWith("super::"))return null;let i=Oe(le(e.config.projectRoot,t)),s;return r.startsWith("crate::")?s=te(e.config.projectRoot,"src",r.slice(7).replace(/::/g,"/")):r.startsWith("self::")?s=te(i,r.slice(6).replace(/::/g,"/")):s=te(Oe(i),r.slice(7).replace(/::/g,"/")),_r(e,hp(s))}function mn(e,t,n){let r=Oe(le(e.config.projectRoot,t)),i=te(r,n);return _r(e,yp(i))}function pn(e,t,n){let r=Oe(le(e.config.projectRoot,t)),i=[te(r,n),te(e.config.projectRoot,n),te(e.config.projectRoot,"include",n),te(e.config.projectRoot,"src",n)];return _r(e,i)}function j(e,t,n){let r=It(e),i=t.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),s=i.replace(/\./g,"/"),o=i.split(".").pop()??i;for(let l of n){let c=`${s}${l}`,d=[...r].find(u=>u.endsWith(c));if(d)return d}for(let l of n){let c=[...r].find(d=>np(d)===`${o}${l}`);if(c)return c}let a=[...r].filter(l=>n.includes(Se(l).toLowerCase())).filter(l=>l.includes(`/${s}/`)||l.includes(`/${o}/`)).sort((l,c)=>l.localeCompare(c));return a.length===1?a[0]:null}function fn(e,t,n){let r=It(e);if(n.startsWith("package:")){let o=n.slice(8),a=o.indexOf("/");if(a<0)return null;let l=o.slice(a+1),c=fe(l.startsWith("lib/")?l:`lib/${l}`);return r.has(c)?c:null}let i=Oe(le(e.config.projectRoot,t)),s=te(i,n);for(let o of bp(s)){let a=fe(xt(e.config.projectRoot,o));if(r.has(a)||dn(o))return a}return null}function gp(e){let t=Se(e);return hr.includes(t)?[e]:[`${e}.py`,`${e}.pyi`,le(e,"__init__.py"),le(e,"__init__.pyi")]}function _r(e,t){let n=It(e);for(let r of t){let i=fe(xt(e.config.projectRoot,r));if(n.has(i)||dn(r))return i}return null}function hp(e){let t=Se(e);return yr.includes(t)?[e]:[`${e}.rs`,le(e,"mod.rs")]}function yp(e){let t=Se(e);return br.includes(t)?[e]:[`${e}.rb`,le(e,"index.rb")]}function bp(e){let t=Se(e);return Sr.includes(t)?[e]:[`${e}.dart`,e]}function Sp(e){let t=Se(e),n=new Set;if(t){n.add(e);for(let r of un)n.add(e.slice(0,-t.length)+r)}else for(let r of un)n.add(`${e}${r}`),n.add(le(e,`index${r}`));return[...n]}function It(e){return rp.get(e,()=>new Set(e.all(`SELECT relative_path
363
+ ORDER BY relative_path`).filter(l=>!e.isIgnored(l.relative_path)).map(l=>({relativePath:l.relative_path,score:Tm(l.relative_path,r)})).filter(l=>l.score>0).sort((l,c)=>c.score-l.score||l.relativePath.localeCompare(c.relativePath));if(s.length===0){let l=E(e,t);return!l||e.isIgnored(l.relativePath)?[]:[{relativePath:l.relativePath,score:700}]}let o=s.filter(l=>l.score>=1100);if(o.length>0)return n.allowMultiple?o:[o[0]];let a=s.filter(l=>l.score>=800);return a.length>0?n.allowMultiple?a:[a[0]]:n.allowMultiple?s:[s[0]]}function Tm(e,t){let n=os(e),r=is(n),i=is(t),s=0;return n===t&&(s+=1200),n.endsWith(`/${t}`)&&(s+=1100),r===i&&(s+=900),n.startsWith(`${t}/`)&&(s+=850),n.includes(t)&&(s+=250),s}function os(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function as(e,t){let n=we(e,t);return nt(e,n).map(({relativePath:r,...i})=>i)}import{basename as eh}from"path";var bt=new WeakMap;function us(e,t){let n=M(t);return n==="rust"?Wm(e,t):n==="typescript"||n==="tsx"||n==="javascript"?Am(e,t):[]}var $m=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function Am(e,t){let n=P(e,t);if(!n)return[];let r=bt.get(n);if(r)return r;let i=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(t)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(t),s=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(t),o=!1,a=n.rootNode;for(let c of a.namedChildren){if(c.type!=="expression_statement")continue;let u=c.namedChild(0);if(!u||u.type!=="call_expression")continue;let d=u.namedChild(0);if(!d)continue;let m=d.type==="member_expression"?d.namedChild(d.namedChildCount-1)?.text:d.text;if(m&&$m.has(m)){o=!0;break}}let l=[];o&&l.push({startLine:0,endLine:a.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(i||s)&&l.push({startLine:0,endLine:a.endPosition.row,reason:i?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of a.namedChildren){let u=null,d=null;if(c.type==="function_declaration")u=c.namedChild(0)?.text??null,d=c;else if(c.type==="export_statement"){let m=c.namedChild(0);m?.type==="function_declaration"&&(u=m.namedChild(0)?.text??null,d=m)}else if(c.type==="lexical_declaration"){let m=c.namedChild(0);if(m?.type==="variable_declarator"){let g=m.namedChild(0)?.text,p=m.namedChild(1);g&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(u=g,d=m)}}u&&/^use[A-Z]/.test(u)&&d&&l.push({startLine:d.startPosition.row,endLine:d.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...ds(n,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),bt.set(n,l),l}var jm=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function Bm(e){return jm.test(e)}function ds(e,t,n){let r=[],i=s=>{if(t.has(s.type)&&s.parent){let a=s.parent.children,l=-1;for(let c=0;c<a.length;c+=1)if(a[c].startIndex===s.startIndex&&a[c].type===s.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let u=a[c];if(n.has(u.type)){if(Bm(u.text)){r.push({startLine:s.startPosition.row,endLine:s.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(u.type==="attribute_item"||u.type==="inner_attribute_item"))break}}for(let o of s.namedChildren)i(o)};return i(e.rootNode),r}function Wm(e,t){let n=P(e,t);if(!n)return[];let r=bt.get(n);if(r)return r;let i=[],s=Hm(n);return s?(bt.set(n,s),s):(ms(n.rootNode,i,!1,!1),i.push(...ds(n,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"]))),i.push(...Gm(n.rootNode)),bt.set(n,i),i)}function Hm(e){return Km(e.rootNode)?[{startLine:0,endLine:e.rootNode.endPosition.row,reason:"generated file (@generated header)"}]:null}function ms(e,t,n,r){let i=n,s=r;e.type==="trait_item"&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait declaration body (dynamic dispatch)"}),e.type==="impl_item"&&e.childForFieldName("trait")&&(s=!0,t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl block (dynamic dispatch)"})),e.type==="function_item"||e.type==="function_signature_item"?Vm(e,t,n,r):r&&zm(e)?t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl associated item (dynamic dispatch)"}):e.type==="struct_item"||e.type==="enum_item"||e.type==="union_item"?Um(e,t,n):e.type==="mod_item"&&pr(e).some(o=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(o))&&(i=!0);for(let o of e.namedChildren)ms(o,t,i,s)}function Vm(e,t,n,r){let i=pr(e),s=null;r?s="trait impl method (dynamic dispatch)":n&&(s="inside #[cfg(test)] mod");for(let o of i){let a=Jm(o);if(a){s=a;break}if(ps(o)){s="#[allow(dead_code)]";break}}s&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:s})}function Um(e,t,n){let r=pr(e),i=e.namedChildren.find(s=>s.type==="type_identifier")?.text;r.some(qm)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:i}),r.some(ps)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[allow(dead_code)]",containerName:i}),n&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:i})}function pr(e){let t=e.parent;if(!t)return[];let n=t.children,r=-1;for(let s=0;s<n.length;s+=1)if(n[s].startIndex===e.startIndex&&n[s].type===e.type){r=s;break}if(r<=0)return[];let i=[];for(let s=r-1;s>=0;s-=1){let o=n[s];if(o.type==="attribute_item"||o.type==="inner_attribute_item")i.push(o.text);else{if(o.type==="line_comment"||o.type==="block_comment")continue;break}}return i}function Jm(e){return/#\[\s*tauri::command\b/.test(e)?"#[tauri::command]":/#\[\s*command\b/.test(e)?"#[command]":/#\[\s*test\b/.test(e)?"#[test]":/#\[\s*bench\b/.test(e)?"#[bench]":/#\[\s*tokio::test\b/.test(e)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(e)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(e)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(e)?"#[no_mangle]":/#\[\s*napi\b/.test(e)?"#[napi]":/#\[\s*pyfunction\b/.test(e)?"#[pyfunction]":/#\[\s*pymethod\b/.test(e)?"#[pymethod]":/#\[\s*pyo3\b/.test(e)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(e)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(e)?"#[doc(hidden)]":null}function qm(e){return/#\[\s*derive\s*\(/.test(e)?/\bSerialize\b/.test(e)||/\bDeserialize\b/.test(e)||/\bFromRow\b/.test(e)||/\bDeriveEntityModel\b/.test(e)||/\bIntoSchema\b/.test(e)||/\bToSchema\b/.test(e)||/\bDeriveValueType\b/.test(e)||/\bsqlx::FromRow\b/.test(e)||/\bError\b/.test(e)||/\bthiserror::Error\b/.test(e):!1}function ps(e){return/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(e)}function zm(e){return e.type==="const_item"||e.type==="type_item"||e.type==="static_item"||e.type==="associated_type"}function Gm(e){let t=ep(e);if(t.size===0)return[];let n=[];for(let r of e.descendantsOfType("mod_item")){let i=r.childForFieldName("name")?.text;i&&t.has(i)&&n.push({startLine:r.startPosition.row,endLine:r.endPosition.row,reason:'serde `with = "..."` module \u2014 body invoked via reflection',containerName:i})}return n}function Km(e){for(let t=0;t<Math.min(e.namedChildCount,12);t+=1){let n=e.namedChild(t);if(!n||n.type!=="line_comment"&&n.type!=="block_comment")break;if(/@generated\b/.test(n.text)||/This file is .*generated\b/i.test(n.text)||/Code generated by/i.test(n.text)||/Generated by:\s*https?:\/\/openapi-generator/i.test(n.text)||/openapi-generator/i.test(n.text)&&/Generated by/i.test(n.text))return!0}return!1}var Ym=[{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}],fs=/^#!?\[\s*serde\s*\(/,Qm=/^#!?\[\s*schemars\s*\(/,Xm=/^#!?\[\s*validate\s*\(/,ls=/\bwith\s*=\s*"([^"]+)"/g;function st(e,t){return nn(e,t,Zm,()=>new Set,(n,r,i)=>{if(r==="rust"){for(let s of n.rootNode.descendantsOfType("attribute_item"))cs(s.text,i);for(let s of n.rootNode.descendantsOfType("inner_attribute_item"))cs(s.text,i)}})??new Set}var Zm=new WeakMap;function cs(e,t){let n=fs.test(e),r=Qm.test(e),i=Xm.test(e);if(!(!n&&!r&&!i))for(let{re:s}of Ym){s.lastIndex=0;let o;for(;(o=s.exec(e))!==null;){let a=o[1],l=a.split("::").pop()??a;l==="is_none"&&/\bOption\b/.test(a)||l==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(a)||l&&t.add(l)}}}function ep(e){let t=new Set;for(let n of e.descendantsOfType("attribute_item")){if(!fs.test(n.text))continue;ls.lastIndex=0;let r;for(;(r=ls.exec(n.text))!==null;){let i=r[1],s=i.split("::").pop()??i;s&&t.add(s)}}return t}var tp=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function gs(e,t){return nn(e,t,np,()=>new Set,(n,r,i)=>{if(!(r!=="typescript"&&r!=="tsx"&&r!=="javascript"))for(let s of n.rootNode.descendantsOfType("call_expression")){let o=s.namedChild(0);if(!o)continue;let a=ht(o);if(!a||!tp.has(a))continue;let l=s.namedChildren.find(d=>d.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(d=>d.type==="string_fragment");u&&i.add(u.text)}})??new Set}var np=new WeakMap;function an(e){return e.replace(/'''[\s\S]*?'''/g,Pe).replace(/"""[\s\S]*?"""/g,Pe).replace(/#.*$/gm,Pe).replace(/\/\/.*$/gm,Pe).replace(/\/\*[\s\S]*?\*\//g,Pe).replace(/`(?:\\[\s\S]|[^`])*`/g,Pe).replace(/'(?:\\.|[^'\\\r\n])*'/g,Pe).replace(/"(?:\\.|[^"\\\r\n])*"/g,Pe)}function Pe(e){return e.replace(/[^\r\n]/g," ")}var rp=Wt("stripped-lines");function ys(e,t,n){return rp.get(e,t,n,()=>an(n).split(`
364
+ `))}var hs=null,fr="";function ip(e){return hs===e||(hs=e,fr=an(e)),fr}function Oe(e,t,n){let r=ip(e);return`${r.slice(0,t)}${" ".repeat(n-t)}${r.slice(n)}`}function K(e,t){return new RegExp(`\\b${ln(t)}\\b`,"m").test(e)}function ot(e,t){let n=new Set,r=new RegExp(`\\b${ln(t)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let i of e.matchAll(r)){let s=i[1];s&&n.add(s)}return[...n]}function ln(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var sp=new Set(["identifier","type_identifier","field_identifier"]),op=new Set(["identifier"]),ap=new Set(["identifier","property_identifier","type_identifier"]),lp=new Set(["rust","python"]),cp=/\{([^{}]*)\}/g,up=/\b([A-Za-z_][\w]*)\b/g;function cn(e,t,n,r={}){if(!n)return[];let i=w(e,t);if(!i)return[];if(i.indexOf(n)===-1)return[];if(M(t))return(qe(e,t).get(n)??[]).filter(u=>!bs(u,r));let s=ys(e,t,i),o=new RegExp(`\\b${ln(n)}\\b`),a=[];for(let l=0;l<s.length;l++)bs(l,r)||o.test(s[l]??"")&&a.push(l);return a}function bs(e,t){return typeof t.excludeStartLine=="number"&&typeof t.excludeEndLine=="number"&&e>=t.excludeStartLine&&e<=t.excludeEndLine}var dp=$("file-identifiers");function Ss(e,t){return dp.get(e,t,()=>new Set(qe(e,t).keys()))}var mp=$("file-ident-lines");function qe(e,t){return mp.get(e,t,()=>fp(e,t))}var pp=$("file-idents-by-line");function xs(e,t){return pp.get(e,t,()=>{let n=qe(e,t),r=0;for(let s of n.values()){let o=s[s.length-1];o!==void 0&&o>r&&(r=o)}let i=new Array(r+1);for(let s=0;s<=r;s+=1)i[s]=new Set;for(let[s,o]of n)for(let a of o)i[a].add(s);return i})}function fp(e,t){let n=new Map,r=(a,l)=>{let c=n.get(a);if(!c){n.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};if(M(t)){let a=P(e,t);if(a){let l=M(t),c=l==="rust"?sp:l==="python"?op:ap,u=d=>{if(c.has(d.type)&&r(d.text,d.startPosition.row),l&&lp.has(l)&&d.type==="string_content"){let m=d.startPosition.row;for(let g of d.text.matchAll(cp)){let p=g[1]??"";for(let f of p.matchAll(up))f[1]&&r(f[1],m)}}for(let m of d.children)u(m)};return u(a.rootNode),n}}let i=w(e,t);if(!i)return n;let s=an(i).split(/\r?\n/),o=/\b([A-Za-z_$][\w$]*)\b/g;for(let a=0;a<s.length;a+=1){let l=s[a]??"";for(let c of l.matchAll(o))c[1]&&r(c[1],a)}return n}import{existsSync as un}from"fs";import{basename as gp,dirname as Me,extname as Se,join as le,relative as St,resolve as te}from"path";var hp=Ae("indexed-paths"),xt=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],_s=[".py",".pyi"],ce=[".java",".scala",".kt",".kts"],Is=[".rs"],Rs=[".rb"],Cs=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],at=[".cs",".vb"],vs=[".dart"],_t=[".php"],yp=new Set(xt),gr=new Set(_s),Ns=new Set(ce),hr=new Set(Is),yr=new Set(Rs),Es=new Set(Cs),Ds=new Set(at),br=new Set(vs),Ls=new Set(_t),bp=[{extensions:xt,lookup:yp},{extensions:_s,lookup:gr},{extensions:ce,lookup:Ns},{extensions:Is,lookup:hr},{extensions:Rs,lookup:yr},{extensions:Cs,lookup:Es},{extensions:at,lookup:Ds},{extensions:vs,lookup:br},{extensions:_t,lookup:Ls}];function Fe(e,t){return t.has(Se(e).toLowerCase())}function Sp(e){return Fe(e,gr)}function xp(e){return Fe(e,Ns)}function _p(e){return Fe(e,hr)}function Ip(e){return Fe(e,yr)}function Rp(e){return Fe(e,Es)}function Cp(e){return Fe(e,Ds)}function ks(e){return Se(e).toLowerCase()===".vb"}function vp(e){return Fe(e,br)}function Np(e){return Fe(e,Ls)}function Sr(e){let t=Se(e).toLowerCase();for(let n of bp)if(n.lookup.has(t))return n.extensions;return xt}function Ep(e){return xp(e)||Cp(e)||Np(e)}function ge(e,t,n){return Sp(t)?lt(e,t,n):_p(t)?xe(e,t,n):Ip(t)?dn(e,t,n):Rp(t)?mn(e,t,n):Ep(t)?j(e,n.replace(/\\/g,"."),Sr(t)):vp(t)?pn(e,t,n):Dp(e,t,n)}function Dp(e,t,n){if(!n.startsWith(".")&&!n.startsWith("/"))return null;let r=Me(le(e.config.projectRoot,t)),i=te(r,n),s=It(e);for(let o of Op(i)){let a=fe(St(e.config.projectRoot,o));if(s.has(a)||un(o))return a}return fe(St(e.config.projectRoot,i))}function lt(e,t,n){let r=It(e),i;if(n.startsWith(".")){let s=n.match(/^(\.+)(.*)$/);if(!s)return null;let o=s[1].length,a=s[2].replace(/^\./,""),l=Me(le(e.config.projectRoot,t));for(let c=1;c<o;c++)l=Me(l);i=a?te(l,a.replace(/\./g,"/")):l}else i=te(e.config.projectRoot,n.replace(/\./g,"/"));for(let s of Lp(i)){let o=fe(St(e.config.projectRoot,s));if(r.has(o)||un(s))return o}return null}function xe(e,t,n){if(!n)return null;let r=n.replace(/\s+as\s+.+$/,"").trim();if(!r.startsWith("crate::")&&!r.startsWith("self::")&&!r.startsWith("super::"))return null;let i=Me(le(e.config.projectRoot,t)),s;return r.startsWith("crate::")?s=te(e.config.projectRoot,"src",r.slice(7).replace(/::/g,"/")):r.startsWith("self::")?s=te(i,r.slice(6).replace(/::/g,"/")):s=te(Me(i),r.slice(7).replace(/::/g,"/")),xr(e,kp(s))}function dn(e,t,n){let r=Me(le(e.config.projectRoot,t)),i=te(r,n);return xr(e,wp(i))}function mn(e,t,n){let r=Me(le(e.config.projectRoot,t)),i=[te(r,n),te(e.config.projectRoot,n),te(e.config.projectRoot,"include",n),te(e.config.projectRoot,"src",n)];return xr(e,i)}function j(e,t,n){let r=It(e),i=t.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),s=i.replace(/\./g,"/"),o=i.split(".").pop()??i;for(let l of n){let c=`${s}${l}`,u=[...r].find(d=>d.endsWith(c));if(u)return u}for(let l of n){let c=[...r].find(u=>gp(u)===`${o}${l}`);if(c)return c}let a=[...r].filter(l=>n.includes(Se(l).toLowerCase())).filter(l=>l.includes(`/${s}/`)||l.includes(`/${o}/`)).sort((l,c)=>l.localeCompare(c));return a.length===1?a[0]:null}function pn(e,t,n){let r=It(e);if(n.startsWith("package:")){let o=n.slice(8),a=o.indexOf("/");if(a<0)return null;let l=o.slice(a+1),c=fe(l.startsWith("lib/")?l:`lib/${l}`);return r.has(c)?c:null}let i=Me(le(e.config.projectRoot,t)),s=te(i,n);for(let o of Pp(s)){let a=fe(St(e.config.projectRoot,o));if(r.has(a)||un(o))return a}return null}function Lp(e){let t=Se(e);return gr.has(t)?[e]:[`${e}.py`,`${e}.pyi`,le(e,"__init__.py"),le(e,"__init__.pyi")]}function xr(e,t){let n=It(e);for(let r of t){let i=fe(St(e.config.projectRoot,r));if(n.has(i)||un(r))return i}return null}function kp(e){let t=Se(e);return hr.has(t)?[e]:[`${e}.rs`,le(e,"mod.rs")]}function wp(e){let t=Se(e);return yr.has(t)?[e]:[`${e}.rb`,le(e,"index.rb")]}function Pp(e){let t=Se(e);return br.has(t)?[e]:[`${e}.dart`,e]}function Op(e){let t=Se(e),n=new Set;if(t){n.add(e);for(let r of xt)n.add(e.slice(0,-t.length)+r)}else for(let r of xt)n.add(`${e}${r}`),n.add(le(e,`index${r}`));return[...n]}function It(e){return hp.get(e,()=>new Set(e.all(`SELECT relative_path
365
365
  FROM documents
366
366
  WHERE 1 = 1
367
- ${e.pathExclusionsFor("documents")}`).map(t=>fe(t.relative_path)).filter(t=>!e.isIgnored(t))))}function fe(e){return e.replace(/\\/g,"/")}function Y(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let s=e[i];(s==="{"||s==="["||s==="(")&&n++,(s==="}"||s==="]"||s===")")&&n--,s===","&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function ne(e,t){for(let n of e.namedChildren)if(n.type===t)return n;return null}function B(e,t){let n=new Set,r=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]),i=(s,o)=>{let a=o||t.has(s.type);!a&&r.has(s.type)&&n.add(s.text);for(let l of s.children)i(l,a)};return i(e.rootNode,!1),n}function he(e,t,n,r,i,s,o){return{importedName:i,localName:s,sourcePath:o??j(e,r,xr(t)),kind:"named",used:K(n,s),usedMembers:[]}}function re(e,t,n){let r=[];for(let i of e.matchAll(t)){let s=i[0];if(!s||typeof i.index!="number")continue;let o=Pe(e,i.index,i.index+s.length);r.push(...n(i,o))}return r}function Rs(e,t,n){let r=w(e,t);return r?xp(e,t,r):Pp(n).flatMap(i=>Op(e,t,i.clause,i.specifier,i.start,i.end,n))}function xp(e,t,n){let r=_p(e,t,n),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))i.push(...Ip(e,t,n,s,r));return i}function _p(e,t,n){let r=B(n,new Set(["import_statement"]));if(bt(t))for(let i of Jp(e,t))r.add(i);return r}function Ip(e,t,n,r,i){let s=Dp(r);if(!s)return[];let o=ge(e,t,s),a=ne(r,"import_clause");return a?Rp(n,a,o,i,Lp(r.text)):[Cp(o)]}function Rp(e,t,n,r,i){let s=[];for(let o of t.namedChildren)if(o.type==="identifier")s.push(vp(o.text,n,r,i));else if(o.type==="namespace_import"){let a=Np(e,o,n,r,i);a&&s.push(a)}else o.type==="named_imports"&&s.push(...Ep(o,n,r,i));return s}function Cp(e){return{importedName:"*",localName:null,sourcePath:e,kind:"side-effect",used:!0,usedMembers:[]}}function vp(e,t,n,r){return{importedName:"default",localName:e,sourcePath:t,kind:"default",used:n.has(e),usedMembers:[],isTypeOnly:r}}function Np(e,t,n,r,i){let o=ne(t,"identifier")?.text??"";if(!o)return null;let a=wp(e,o);return{importedName:"*",localName:o,sourcePath:n,kind:"namespace",used:a.length>0||r.has(o),usedMembers:a,isTypeOnly:i}}function Ep(e,t,n,r){let i=[];for(let s of e.namedChildren){if(s.type!=="import_specifier")continue;let o=s.namedChild(0),a=s.namedChild(1);if(!o)continue;let l=o.text,c=a?.text??l;i.push({importedName:l,localName:c,sourcePath:t,kind:"named",used:n.has(c),usedMembers:[],isTypeOnly:r||kp(s.text)})}return i}function Dp(e){let t=ne(e,"string");if(!t)return null;let n=ne(t,"string_fragment");return n?n.text:null}function Lp(e){return/^\s*import\s+type\b/.test(e)}function kp(e){return/^\s*type\b/.test(e.trim())}function wp(e,t){let n=new Set;for(let r of e.rootNode.descendantsOfType("member_expression")){let i=r.namedChild(0),s=r.namedChild(1);!i||!s||i.type!=="identifier"||i.text!==t||(s.type==="property_identifier"||s.type==="identifier")&&n.add(s.text)}return[...n]}function Pp(e){let t=[],n=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(n)){let s=i[0],o=i[1],a=i[2];!s||!a||typeof i.index!="number"||t.push({clause:o,specifier:a,start:i.index,end:i.index+s.length})}let r=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(r)){let s=i[0],o=i[1];!s||!o||typeof i.index!="number"||t.push({clause:null,specifier:o,start:i.index,end:i.index+s.length})}return t.sort((i,s)=>i.start-s.start)}function Op(e,t,n,r,i,s,o){let a=ge(e,t,r),l=Pe(o,i,s);return n?Mp(n).map(d=>({...d,sourcePath:a})).map(d=>{if(d.kind==="namespace"){let u=ot(l,d.localName);return{...d,used:u.length>0||K(l,d.localName),usedMembers:u}}return d.kind==="side-effect"?{...d,used:!0,usedMembers:[]}:{...d,used:d.localName?K(l,d.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]}]}function Mp(e){let t=e.trim(),n=/^type\b/.test(t),r=t.replace(/^type\s+/,""),[i,s]=Fp(r),o=[];return i&&o.push(...Is(i,n)),s&&o.push(...Is(s,n)),o}function Is(e,t){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let r=n.slice(1,-1).trim();return r?Y(r).map(i=>{let s=i.trim(),o=t||/^type\b/.test(s),a=s.replace(/^type\s+/,""),[l,c]=a.split(/\s+as\s+/);return{importedName:l.trim(),localName:(c??l).trim(),kind:"named",isTypeOnly:o}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace",isTypeOnly:t}]:[{importedName:"default",localName:n,kind:"default",isTypeOnly:t}]}function Fp(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="{"&&t++,r==="}"&&t--,r===","&&t===0)return[e.slice(0,n).trim(),e.slice(n+1).trim()]}return[e.trim(),null]}function Cs(e,t){let n=w(e,t);if(n)return Wp(e,t,n);let r=O(e,t);return r?Tp(e,t,r):[]}function Tp(e,t,n){return[...$p(e,t,n),...Ap(e,t,n),...jp(e,t,n)]}function $p(e,t,n){let r=[],i=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=s[2]??"",l=Y(o).map(u=>Bp(u.trim())).filter(u=>!!u),c=ct(n,s.index),d=ct(n,s.index+s[0].length-1);r.push({kind:"named",sourcePath:ge(e,t,a),names:l,startLine:c,endLine:d})}return r}function Ap(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[2]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star-as",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function jp(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function Bp(e){if(!e)return null;let t=e.replace(/^type\s+/,"").trim();if(!t)return null;let n=t.match(/^(\w+)\s+as\s+(\w+)$/);if(n)return n[2]??null;let r=t.match(/^(\w+)$/);return r?r[1]??null:null}function ct(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function Wp(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("export_statement")){let s=Hp(e,t,i);if(s===void 0)continue;let o=i.startPosition.row,a=i.endPosition.row,l=Vp(i,s,o,a);r.push(l)}return r}function Hp(e,t,n){let r=ne(n,"string");if(!r)return;let i=ne(r,"string_fragment");if(i)return ge(e,t,i.text)}function Vp(e,t,n,r){let i=ne(e,"export_clause");if(i){let o=[];for(let a of i.namedChildren){if(a.type!=="export_specifier")continue;let l=a.namedChild(0),c=a.namedChild(1);l&&o.push((c??l).text)}return{kind:"named",sourcePath:t,names:o,startLine:n,endLine:r}}return ne(e,"namespace_export")?{kind:"star-as",sourcePath:t,names:[],startLine:n,endLine:r}:{kind:"star",sourcePath:t,names:[],startLine:n,endLine:r}}var Up=$("vue-non-script-identifiers");function Jp(e,t){return Up.get(e,t,()=>{let n=new Set,r=O(e,t);if(!r)return n;let s=r.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,o=>o.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,o=>o.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,o=>o.replace(/[^\r\n]/g," "));for(let o of s.matchAll(/[A-Za-z_$][\w$]*/g))n.add(o[0]);return n})}import{basename as vs}from"path";function Ns(e,t,n){let r=w(e,t);return r?qp(e,t,r):re(n,/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm,(i,s)=>{let o=i[1]?.trim();if(!o)return[];let a=vs(o).replace(/\.[^.]+$/,"");return[{importedName:o,localName:a,sourcePath:pn(e,t,o),kind:"named",used:K(s,a),usedMembers:[]}]})}function qp(e,t,n){let r=B(n,new Set(["preproc_include"])),i=[];for(let s of n.rootNode.descendantsOfType("preproc_include")){let o=null;for(let l of s.namedChildren){if(l.type==="system_lib_string"){o=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){o=l.namedChildren.find(d=>d.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!o)continue;let a=vs(o).replace(/\.[^.]+$/,"");i.push({importedName:o,localName:a,sourcePath:pn(e,t,o),kind:"named",used:r.has(a),usedMembers:[]})}return i}function Es(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let s=i[1]?.trim(),o=i[2]?.trim()??null,a=i[0];if(!s||!a||typeof i.index!="number")continue;let l=Pe(n,i.index,i.index+a.length);r.push({importedName:s,localName:o,sourcePath:fn(e,t,s),kind:o?"namespace":"side-effect",used:o?K(l,o):!0,usedMembers:o?ot(l,o):[]})}return r}function Ds(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let s=i[1]?.trim();s&&r.push({specifier:s,sourcePath:fn(e,t,s)})}return r}function Ls(e,t,n){let r=w(e,t),i=M(t);if(r&&i==="csharp")return Gp(e,t,r);if(r&&i==="vb")return zp(e,t,r);let s=_s(t)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;return re(n,s,(o,a)=>{let l=o[1]?.trim();if(!l)return[];let[c,d]=l.split(/\s*=\s*/),u=!!d,m=(u?d:c)?.trim()??l,f=m.split(".").pop()??m,p=u?c?.trim()??f:f;return[he(e,t,a,m,f,p,j(e,m,at))]})}function zp(e,t,n){let r=B(n,new Set(["imports_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("imports_statement")){let o=s.namedChildren.filter(m=>m.type==="namespace_name");if(o.length===0)continue;let a=o[o.length-1],l=o.length>1?o[0]:null,c=a.text,d=c.split(".").pop()??c,u=l?.text??d;i.push({importedName:d,localName:u,sourcePath:j(e,c,at),kind:l?"namespace":"named",used:r.has(u),usedMembers:[]})}return i}function Gp(e,t,n){let r=B(n,new Set(["using_directive"])),i=[];for(let s of n.rootNode.descendantsOfType("using_directive")){let o=s.namedChildren;if(o.length===0)continue;let a=null,l;o.length>=2&&o[0].type==="identifier"&&(o[1].type==="qualified_name"||o[1].type==="identifier")?(a=o[0],l=o[1]):l=o[o.length-1];let c=l.text,d=c.split(".").pop()??c,u=a?.text??d;i.push({importedName:d,localName:u,sourcePath:j(e,c,at),kind:a?"namespace":"named",used:r.has(u),usedMembers:[]})}return i}function ks(e,t,n){let r=w(e,t),i=M(t);return r&&i==="java"?Kp(e,t,r):r&&i==="kotlin"?Qp(e,t,r):r&&i==="scala"?Yp(e,t,r):re(n,/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm,(s,o)=>{let a=s[1]?.trim();return a?Xp(e,t,a,o):[]})}function Kp(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.children.some(u=>u.type==="asterisk"),l=s.namedChildren.find(u=>u.type==="scoped_identifier")??s.namedChildren.find(u=>u.type==="identifier");if(!l)continue;let c=l.text;if(o){i.push({importedName:"*",localName:null,sourcePath:j(e,c,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let d=c.split(".").pop()??c;i.push({importedName:d,localName:d,sourcePath:j(e,c,ce),kind:"named",used:r.has(d),usedMembers:[]})}return i}function Qp(e,t,n){let r=B(n,new Set(["import_header","import_list"])),i=[];for(let s of n.rootNode.descendantsOfType("import_header")){let o=s.namedChildren.find(f=>f.type==="identifier");if(!o)continue;let a=s.namedChildren.some(f=>f.type==="wildcard_import"),l=s.namedChildren.find(f=>f.type==="import_alias");if(a){i.push({importedName:"*",localName:null,sourcePath:j(e,o.text,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let c=o.text,d=c.split(".").pop()??c,m=l?.namedChild(0)?.text??d;i.push({importedName:d,localName:m,sourcePath:j(e,c,ce),kind:"named",used:r.has(m),usedMembers:[]})}return i}function Yp(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.namedChildren.find(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),a=s.namedChildren.filter(u=>u!==o&&(u.type==="identifier"||u.type==="stable_identifier")),l=a.map(u=>u.text).join(".");if(!l)continue;if(o?.type==="namespace_wildcard"){i.push({importedName:"*",localName:null,sourcePath:j(e,l,ce),kind:"namespace",used:!0,usedMembers:[]});continue}if(o?.type==="namespace_selectors"){for(let u of o.namedChildren)if(u.type==="arrow_renamed_identifier"){let[m,f]=u.namedChildren;if(!m)continue;let p=m.text,g=f?.text??p;if(p==="_")continue;i.push({importedName:p,localName:g,sourcePath:j(e,`${l}.${p}`,ce),kind:"named",used:r.has(g),usedMembers:[]})}else if(u.type==="identifier"){let m=u.text;i.push({importedName:m,localName:m,sourcePath:j(e,`${l}.${m}`,ce),kind:"named",used:r.has(m),usedMembers:[]})}continue}let c=a[a.length-1]?.text??l,d=a.slice(0,-1).map(u=>u.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:j(e,d&&a.length>1?`${d}.${c}`:l,ce),kind:"named",used:r.has(c),usedMembers:[]})}return i}function Xp(e,t,n,r){if(n.includes("{")&&n.includes("}")){let i=n.slice(0,n.indexOf("{")).replace(/\.$/,"").trim(),s=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim();return Y(s).flatMap(o=>{let a=o.trim();if(!a)return[];let[l,c]=a.includes("=>")?a.split(/\s*=>\s*/):a.split(/\s+as\s+/),d=l?.trim();if(!d||d==="_")return[];let u=(c??d.split(".").pop()??d).trim(),m=d==="_"?i:`${i}.${d}`.replace(/\.\./g,".");return[he(e,t,r,m,d,u)]})}return[he(e,t,r,n,n.split(".").pop()??n,n.split(".").pop()??n)]}function Ps(e,t,n){let r=w(e,t);return r?Zp(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?Y(o).flatMap(a=>{let l=a.trim();if(!l)return[];let[c,d]=l.split(/\s+as\s+/i),u=c?.trim()??l,m=u.split("\\").pop()??u,f=(d??m).trim();return[he(e,t,s,u,m,f,j(e,u.replace(/\\/g,"."),_t))]}):[]})}function Zp(e,t,n){let r=B(n,new Set(["namespace_use_declaration"])),i=[],s=(o,a,l)=>{i.push({importedName:a,localName:l,sourcePath:j(e,o.replace(/\\/g,"."),_t),kind:"named",used:r.has(l),usedMembers:[]})};for(let o of n.rootNode.descendantsOfType("namespace_use_declaration")){let a=o.namedChildren.find(l=>l.type==="namespace_use_group");if(a){let l=o.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of a.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:d,localName:u,qualified:m}=ws(c,l);d&&s(m,d,u)}continue}for(let l of o.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:d,qualified:u}=ws(l,"");c&&s(u,c,d)}}return i}function ws(e,t){let n=e.namedChildren.find(c=>c.type==="qualified_name"),r=e.namedChildren.filter(c=>c.type==="name"),i="";n?i=n.text:r.length>=1&&(i=r[0].text);let s=n&&r.length>0?r[r.length-1]:null,o=i.split("\\").pop()??i,a=s?.text??o,l=t?`${t}\\${i}`:i;return{importedName:o,localName:a,qualified:l}}function Fs(e,t,n){let r=w(e,t);return r?ef(e,t,r):nf(n).flatMap(i=>sf(e,t,i,n))}function ef(e,t,n){let r=B(n,new Set(["import_statement","import_from_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))for(let o of s.namedChildren){let a=Os(o);if(!a)continue;let l=lt(e,t,a.qualifiedName);i.push({importedName:a.qualifiedName,localName:a.localName,sourcePath:l,kind:"namespace",used:r.has(a.localName),usedMembers:[]})}for(let s of n.rootNode.descendantsOfType("import_from_statement")){let o=s.namedChild(0);if(!o)continue;let a=tf(o);if(a===null)continue;let l=lt(e,t,a);for(let c=1;c<s.namedChildCount;c+=1){let d=s.namedChild(c);if(d.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=Os(d);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:r.has(u.localName),usedMembers:[]})}}return i}function Os(e){if(e.type==="aliased_import"){let t=e.namedChild(0),n=e.namedChild(1);return!t||!n?null:{qualifiedName:t.text,localName:n.text}}if(e.type==="dotted_name"){let t=e.text;return{qualifiedName:t,localName:t.split(".")[0]??t}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function tf(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let t=ne(e,"import_prefix")?.text??"",n=ne(e,"dotted_name")?.text??"";return`${t}${n}`}return null}function nf(e){let t=e.split(`
368
- `),n=[],r=0;for(let i=0;i<t.length;i++){let s=t[i],o=s.trimStart(),a=r;if(r+=s.length+1,!o.startsWith("import ")&&!o.startsWith("from "))continue;let l=s,c=a+s.length,d=Ms(s);for(;i+1<t.length&&(d>0||l.trimEnd().endsWith("\\"));){i++;let m=t[i];l+=`
369
- ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,end:c})}return n}function rf(e){let t=e.replace(/\\\s*\n/g," ").trim();if(t.startsWith("import "))return{kind:"import",module:null,clause:t.slice(7).trim()};let n=t.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!n)return null;let r=n[2].trim();return r.startsWith("(")&&r.endsWith(")")&&(r=r.slice(1,-1).trim()),{kind:"from",module:n[1],clause:r}}function sf(e,t,n,r){let i=Pe(r,n.start,n.end),s=n.clause.replace(/\n/g," ").trim();if(n.kind==="import")return Y(s).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[d,u]=c.split(/\s+as\s+/),m=d.trim(),f=(u??m.split(".")[0]??m).trim(),p=lt(e,t,m),g=ot(i,f);return[{importedName:m,localName:f,sourcePath:p,kind:"namespace",used:K(i,f)||g.length>0,usedMembers:g}]});let o=n.module?lt(e,t,n.module):null,a=[];for(let l of Y(s)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){a.push({importedName:"*",localName:null,sourcePath:o,kind:"side-effect",used:!0,usedMembers:[]});continue}let[d,u]=c.split(/\s+as\s+/),m=(u??d).trim();a.push({importedName:d.trim(),localName:m,sourcePath:o,kind:"named",used:K(i,m),usedMembers:[]})}return a}function Ms(e){let t=0;for(let n of e)n==="("&&t++,n===")"&&t--;return t}import{basename as of}from"path";function Ts(e,t,n){let r=w(e,t);return r?af(e,t,r):re(n,/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm,(i,s)=>{let o=i[1],a=i[2];if(!o||!a)return[];let l=o==="require_relative"?mn(e,t,a):null;if(l){let c=$s(a);return[{importedName:c,localName:c,sourcePath:l,kind:"named",used:K(s,c),usedMembers:[]}]}return[{importedName:a,localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]}]})}function af(e,t,n){let r=B(n,new Set([])),i=[],s=new Set(["require","require_relative","load"]);for(let o of n.rootNode.descendantsOfType("call")){let a=o.namedChild(0);if(!a||a.type!=="identifier"||!s.has(a.text))continue;let c=o.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 m=a.text==="require_relative"?mn(e,t,u):null;if(m){let f=$s(u);i.push({importedName:f,localName:f,sourcePath:m,kind:"named",used:r.has(f),usedMembers:[]})}else i.push({importedName:u,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function $s(e){return of(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function As(e,t,n){let r=w(e,t);return r?lf(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?cf(e,t,o,s):[]})}function lf(e,t,n){let r=B(n,new Set(["use_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("use_declaration")){let o=s.namedChild(0);if(o)for(let a of Rt(o,"")){if(!a.importedName||a.importedName==="*")continue;let l=xe(e,t,a.qualifiedName)??xe(e,t,a.qualifiedName.split("::").slice(0,-1).join("::"));i.push({importedName:a.importedName,localName:a.localName,sourcePath:l,kind:"named",used:r.has(a.localName),usedMembers:[]})}}return i}function Rt(e,t){switch(e.type){case"identifier":case"super":case"self":case"crate":{let n=e.text;return[{qualifiedName:gn(t,n),importedName:n,localName:n}]}case"scoped_identifier":{let n=e.text,r=n.split("::").pop()??n;return[{qualifiedName:gn(t,n),importedName:r,localName:r}]}case"scoped_use_list":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=gn(t,n.text),s=[];for(let o of r.namedChildren)s.push(...Rt(o,i));return s}case"use_list":{let n=[];for(let r of e.namedChildren)n.push(...Rt(r,t));return n}case"use_as_clause":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=Rt(n,t),s=r.text;return i.map(o=>({...o,localName:s}))}case"use_wildcard":{let n=e.namedChild(0),r=n?n.text:"";return[{qualifiedName:gn(t,`${r}::*`),importedName:"*",localName:"*"}]}default:return[]}}function gn(e,t){return e?t?`${e}::${t}`:e:t}function cf(e,t,n,r){let i=n.trim();if(i.includes("{")&&i.includes("}")){let d=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),u=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return Y(u).flatMap(m=>{let f=m.trim();if(!f||f==="self")return[];let[p,g]=f.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let E=(g??y.split("::").pop()??y).trim(),N=`${d}::${y}`.replace(/::::/g,"::");return[he(e,t,r,N,y.split("::").pop()??y,E,xe(e,t,d))]})}let[s,o]=i.split(/\s+as\s+/),a=s?.trim()??i,l=(o??a.split("::").pop()??a).trim(),c=xe(e,t,a)??xe(e,t,a.split("::").slice(0,-1).join("::"));return[he(e,t,r,a,a.split("::").pop()??a,l,c)]}function js(e,t,n){let r=w(e,t);if(r)return uf(e,t,r);let i=[];for(let s of n.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let o=s[1]?.trim();o&&i.push(...mf(e,t,o))}return i}function uf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("use_declaration")){if(!df(i))continue;let s=i.namedChildren.find(o=>o.type!=="visibility_modifier");if(s)for(let o of Rt(s,""))o.importedName&&r.push(Ir(e,t,o.qualifiedName))}return r}function df(e){for(let t of e.children)if(t.type==="visibility_modifier"&&t.text.startsWith("pub"))return!0;return!1}function mf(e,t,n){let r=n.trim();if(r.includes("{")&&r.includes("}")){let i=r.slice(0,r.indexOf("{")).replace(/::$/,"").trim(),s=r.slice(r.indexOf("{")+1,r.lastIndexOf("}")).trim();return Y(s).flatMap(o=>{let a=o.trim();if(!a||a==="self")return[];let[l]=a.split(/\s+as\s+/),c=`${i}::${l?.trim()??a}`.replace(/::::/g,"::");return[Ir(e,t,c)]})}return[Ir(e,t,r)]}function Ir(e,t,n){return{specifier:n,sourcePath:xe(e,t,n)??xe(e,t,n.split("::").slice(0,-1).join("::"))}}function Bs(e,t){let n=t.toLowerCase();for(let r of e)for(let i of r.extensions)if(n.endsWith(i))return r;return null}var pf={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Rs},ff={language:"python",extensions:[".py",".pyi"],parseImports:Fs},gf={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:ks},hf={language:"rust",extensions:[".rs"],parseImports:As,parseExports:js},yf={language:"ruby",extensions:[".rb"],parseImports:Ts},bf={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:Ns},Sf={language:"dotnet",extensions:[".cs",".vb"],parseImports:Ls},xf={language:"dart",extensions:[".dart"],parseImports:Es,parseExports:Ds},_f={language:"php",extensions:[".php"],parseImports:Ps},If=[pf,ff,gf,hf,yf,bf,Sf,xf,_f];function Rr(e){return Bs(If,e)}function Us(e,t){return Cs(e,t)}var Rf=$("source-imports"),Cf=$("source-exports");function J(e,t){let n=fe(t);return Rf.get(e,n,()=>{let r=Rr(n);if(!r)return[];let i=Vs(e.config.projectRoot,n);if(!Ws(i))return[];let s=Hs(i,"utf-8");return r.parseImports(e,n,s)})}function Cr(e,t){let n=fe(t);return Cf.get(e,n,()=>{let r=Rr(n);if(!r?.parseExports)return[];let i=Vs(e.config.projectRoot,n);if(!Ws(i))return[];let s=Hs(i,"utf-8");return r.parseExports(e,n,s)})}import ue from"path";import{createRequire as vf}from"module";import{existsSync as hn,readdirSync as Nf,readFileSync as Gs}from"fs";var Ef=vf(import.meta.url),Ct;function Ks(e,t){let n=Df();if(!n)return vr("ts-morph is not installed");let r=ki(e);if(r.length===0)return vr("no tsconfig found");try{let i=r.map(s=>({tsconfigPath:s,project:new n.Project({tsConfigFilePath:s,skipFileDependencyResolution:!1})}));return new Nr(e,n,i)}catch(i){return vr(i instanceof Error?i.message:String(i),r[0],r)}}function Df(){if(Ct!==void 0)return Ct;try{Ct=Ef("ts-morph")}catch{Ct=null}return Ct}function vr(e,t,n){return{language:"typescript",availability:()=>({available:!1,reason:e,tsconfigPath:t,tsconfigPaths:n}),importUsage:()=>[],referencesFor:()=>[],calleesFor:()=>[],signatureFor:()=>null}}var Nr=class{constructor(t,n,r){this.db=t;this.tsMorph=n;this.projects=r;this.workspacePackages=wf(t.config.projectRoot)}db;tsMorph;projects;language="typescript";importUsageCache=new Map;referencesCache=new Map;calleesCache=new Map;fileCalleesCache=new Map;signatureCache=new Map;sourceFileCache=new Map;indexedDefinitionLeafCache=new Map;packageImportReferenceIndex=null;packageExportIndex=null;workspacePackages;availability(){return{available:!0,tsconfigPath:this.projects[0]?.tsconfigPath,tsconfigPaths:this.projects.map(t=>t.tsconfigPath)}}importUsage(t){return qe(this.importUsageCache,t,()=>{let n=this.sourceFile(t);if(!n)return[];let r=[];for(let i of n.getImportDeclarations())r.push(...this.importUsageForDeclaration(t,i));return r})}referencesFor(t){return qe(this.referencesCache,t.symbolId,()=>{let n=this.nodeForDefinition(t),r=this.packageImportReferencesForDefinition(t);if(!n)return r;let i=$f(n);return Er([...i.flatMap(s=>Tf(s,this.db.config.projectRoot)).filter(s=>s.file!==t.relativePath||s.line<t.startLine||s.line>t.endLine),...r])})}calleesFor(t){return qe(this.calleesCache,t.symbolId,()=>qe(this.fileCalleesCache,t.relativePath,()=>this.calleeMapForFile(t.relativePath)).get(t.symbolId)??[])}signatureFor(t){return qe(this.signatureCache,t.symbolId,()=>{let n=this.nodeForDefinition(t);if(!n||!this.tsMorph.Node.isFunctionDeclaration(n)&&!this.tsMorph.Node.isMethodDeclaration(n)&&!this.tsMorph.Node.isArrowFunction(n)&&!this.tsMorph.Node.isFunctionExpression(n)&&!this.tsMorph.Node.isConstructorDeclaration(n))return null;let r=n.getType().getCallSignatures()[0];if(!r)return null;let i=r.getParameters().map(o=>{let a=o.getDeclarations()[0],l=a?o.getTypeAtLocation(a).getText(a):o.getValueDeclaration()?.getType().getText()??"unknown";return zs(l)}),s=r.getReturnType().getText(n);return`(${i.join(",")})=>${zs(s)}`})}importUsageForDeclaration(t,n){let r=ge(this.db,t,n.getModuleSpecifierValue()),i=Js(n);return n.getImportClause()?.isTypeOnly()?i.map(s=>Lf(t,r,s)):i.map(s=>this.valueImportUsageForEntry(t,r,s))}valueImportUsageForEntry(t,n,r){let s=(r.identifier?r.identifier.findReferences():[]).flatMap(c=>Af(c,t,r.identifier,this.db.config.projectRoot)),o=s.some(c=>!qs(c.node)),a=s.some(c=>qs(c.node)),l=r.isTypeOnly;return{importer:t,sourcePath:n,importedName:r.importedName,localName:r.localName,kind:r.kind,isTypeOnly:l,isUsed:l||s.length>0,isTypeUsed:l||a,isValueUsed:o,references:s.map(c=>c.location)}}sourceFile(t){return this.sourceFileMatch(t)?.sourceFile??null}sourceFileMatch(t){return qf(t)?qe(this.sourceFileCache,t,()=>{let n=ue.join(this.db.config.projectRoot,t);for(let{project:r}of this.projects){let i=r.getSourceFile(n)??r.addSourceFileAtPathIfExists(n)??null;if(i)return{project:r,sourceFile:i}}return null}):null}packageImportReferencesForDefinition(t){return this.packageImportReferences().get(t.symbolId)??[]}packageImportReferences(){if(this.packageImportReferenceIndex)return this.packageImportReferenceIndex;let t=new Map,n=this.packageExports();for(let r of this.indexedTypeScriptLikeDocuments())this.addPackageImportReferencesForDocument(t,n,r);for(let[r,i]of t)t.set(r,Er(i));return this.packageImportReferenceIndex=t,t}indexedTypeScriptLikeDocuments(){return this.db.all(`SELECT relative_path
367
+ ${e.pathExclusionsFor("documents")}`).map(t=>fe(t.relative_path)).filter(t=>!e.isIgnored(t))))}function fe(e){return e.replace(/\\/g,"/")}var Mp=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]);function X(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let s=e[i];(s==="{"||s==="["||s==="(")&&n++,(s==="}"||s==="]"||s===")")&&n--,s===","&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function ne(e,t){for(let n of e.namedChildren)if(n.type===t)return n;return null}function B(e,t){let n=new Set,r=(i,s)=>{let o=s||t.has(i.type);!o&&Mp.has(i.type)&&n.add(i.text);for(let a of i.children)r(a,o)};return r(e.rootNode,!1),n}function he(e,t,n,r,i,s,o){return{importedName:i,localName:s,sourcePath:o??j(e,r,Sr(t)),kind:"named",used:K(n,s),usedMembers:[]}}function re(e,t,n){let r=[];for(let i of e.matchAll(t)){let s=i[0];if(!s||typeof i.index!="number")continue;let o=Oe(e,i.index,i.index+s.length);for(let a of n(i,o))r.push(a)}return r}function Ps(e,t,n){let r=P(e,t);return r?Fp(e,t,r):zp(n).flatMap(i=>Gp(e,t,i.clause,i.specifier,i.start,i.end,n))}function Fp(e,t,n){let r=Tp(e,t,n),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))i.push(...$p(e,t,n,s,r));return i}function Tp(e,t,n){let r=B(n,new Set(["import_statement"]));if(yt(t))for(let i of af(e,t))r.add(i);return r}function $p(e,t,n,r,i){let s=Vp(r);if(!s)return[];let o=ge(e,t,s),a=ne(r,"import_clause");return a?Ap(n,a,o,i,Up(r.text)):[jp(o)]}function Ap(e,t,n,r,i){let s=[];for(let o of t.namedChildren)if(o.type==="identifier")s.push(Bp(o.text,n,r,i));else if(o.type==="namespace_import"){let a=Wp(e,o,n,r,i);a&&s.push(a)}else o.type==="named_imports"&&s.push(...Hp(o,n,r,i));return s}function jp(e){return{importedName:"*",localName:null,sourcePath:e,kind:"side-effect",used:!0,usedMembers:[]}}function Bp(e,t,n,r){return{importedName:"default",localName:e,sourcePath:t,kind:"default",used:n.has(e),usedMembers:[],isTypeOnly:r}}function Wp(e,t,n,r,i){let o=ne(t,"identifier")?.text??"";if(!o)return null;let a=qp(e,o);return{importedName:"*",localName:o,sourcePath:n,kind:"namespace",used:a.length>0||r.has(o),usedMembers:a,isTypeOnly:i}}function Hp(e,t,n,r){let i=[];for(let s of e.namedChildren){if(s.type!=="import_specifier")continue;let o=s.namedChild(0),a=s.namedChild(1);if(!o)continue;let l=o.text,c=a?.text??l;i.push({importedName:l,localName:c,sourcePath:t,kind:"named",used:n.has(c),usedMembers:[],isTypeOnly:r||Jp(s.text)})}return i}function Vp(e){let t=ne(e,"string");if(!t)return null;let n=ne(t,"string_fragment");return n?n.text:null}function Up(e){return/^\s*import\s+type\b/.test(e)}function Jp(e){return/^\s*type\b/.test(e.trim())}function qp(e,t){let n=new Set;for(let r of e.rootNode.descendantsOfType("member_expression")){let i=r.namedChild(0),s=r.namedChild(1);!i||!s||i.type!=="identifier"||i.text!==t||(s.type==="property_identifier"||s.type==="identifier")&&n.add(s.text)}return[...n]}function zp(e){let t=[],n=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(n)){let s=i[0],o=i[1],a=i[2];!s||!a||typeof i.index!="number"||t.push({clause:o,specifier:a,start:i.index,end:i.index+s.length})}let r=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(r)){let s=i[0],o=i[1];!s||!o||typeof i.index!="number"||t.push({clause:null,specifier:o,start:i.index,end:i.index+s.length})}return t.sort((i,s)=>i.start-s.start)}function Gp(e,t,n,r,i,s,o){let a=ge(e,t,r),l=Oe(o,i,s);return n?Kp(n).map(u=>({...u,sourcePath:a})).map(u=>{if(u.kind==="namespace"){let d=ot(l,u.localName);return{...u,used:d.length>0||K(l,u.localName),usedMembers:d}}return u.kind==="side-effect"?{...u,used:!0,usedMembers:[]}:{...u,used:u.localName?K(l,u.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]}]}function Kp(e){let t=e.trim(),n=/^type\b/.test(t),r=t.replace(/^type\s+/,""),[i,s]=Yp(r),o=[];return i&&o.push(...ws(i,n)),s&&o.push(...ws(s,n)),o}function ws(e,t){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let r=n.slice(1,-1).trim();return r?X(r).map(i=>{let s=i.trim(),o=t||/^type\b/.test(s),a=s.replace(/^type\s+/,""),[l,c]=a.split(/\s+as\s+/);return{importedName:l.trim(),localName:(c??l).trim(),kind:"named",isTypeOnly:o}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace",isTypeOnly:t}]:[{importedName:"default",localName:n,kind:"default",isTypeOnly:t}]}function Yp(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="{"&&t++,r==="}"&&t--,r===","&&t===0)return[e.slice(0,n).trim(),e.slice(n+1).trim()]}return[e.trim(),null]}function Os(e,t){let n=P(e,t);if(n)return nf(e,t,n);let r=w(e,t);return r?Qp(e,t,r):[]}function Qp(e,t,n){return[...Xp(e,t,n),...Zp(e,t,n),...ef(e,t,n)]}function Xp(e,t,n){let r=[],i=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=s[2]??"",l=X(o).map(d=>tf(d.trim())).filter(d=>!!d),c=ct(n,s.index),u=ct(n,s.index+s[0].length-1);r.push({kind:"named",sourcePath:ge(e,t,a),names:l,startLine:c,endLine:u})}return r}function Zp(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[2]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star-as",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function ef(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function tf(e){if(!e)return null;let t=e.replace(/^type\s+/,"").trim();if(!t)return null;let n=t.match(/^(\w+)\s+as\s+(\w+)$/);if(n)return n[2]??null;let r=t.match(/^(\w+)$/);return r?r[1]??null:null}function ct(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function nf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("export_statement")){let s=rf(e,t,i);if(s===void 0)continue;let o=i.startPosition.row,a=i.endPosition.row,l=sf(i,s,o,a);r.push(l)}return r}function rf(e,t,n){let r=ne(n,"string");if(!r)return;let i=ne(r,"string_fragment");if(i)return ge(e,t,i.text)}function sf(e,t,n,r){let i=ne(e,"export_clause");if(i){let o=[];for(let a of i.namedChildren){if(a.type!=="export_specifier")continue;let l=a.namedChild(0),c=a.namedChild(1);l&&o.push((c??l).text)}return{kind:"named",sourcePath:t,names:o,startLine:n,endLine:r}}return ne(e,"namespace_export")?{kind:"star-as",sourcePath:t,names:[],startLine:n,endLine:r}:{kind:"star",sourcePath:t,names:[],startLine:n,endLine:r}}var of=$("vue-non-script-identifiers");function af(e,t){return of.get(e,t,()=>{let n=new Set,r=w(e,t);if(!r)return n;let s=r.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,o=>o.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,o=>o.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,o=>o.replace(/[^\r\n]/g," "));for(let o of s.matchAll(/[A-Za-z_$][\w$]*/g))n.add(o[0]);return n})}import{basename as Ms}from"path";function Fs(e,t,n){let r=P(e,t);return r?lf(e,t,r):re(n,/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm,(i,s)=>{let o=i[1]?.trim();if(!o)return[];let a=Ms(o).replace(/\.[^.]+$/,"");return[{importedName:o,localName:a,sourcePath:mn(e,t,o),kind:"named",used:K(s,a),usedMembers:[]}]})}function lf(e,t,n){let r=B(n,new Set(["preproc_include"])),i=[];for(let s of n.rootNode.descendantsOfType("preproc_include")){let o=null;for(let l of s.namedChildren){if(l.type==="system_lib_string"){o=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){o=l.namedChildren.find(u=>u.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!o)continue;let a=Ms(o).replace(/\.[^.]+$/,"");i.push({importedName:o,localName:a,sourcePath:mn(e,t,o),kind:"named",used:r.has(a),usedMembers:[]})}return i}function Ts(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let s=i[1]?.trim(),o=i[2]?.trim()??null,a=i[0];if(!s||!a||typeof i.index!="number")continue;let l=Oe(n,i.index,i.index+a.length);r.push({importedName:s,localName:o,sourcePath:pn(e,t,s),kind:o?"namespace":"side-effect",used:o?K(l,o):!0,usedMembers:o?ot(l,o):[]})}return r}function $s(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let s=i[1]?.trim();s&&r.push({specifier:s,sourcePath:pn(e,t,s)})}return r}function As(e,t,n){let r=P(e,t),i=M(t);if(r&&i==="csharp")return uf(e,t,r);if(r&&i==="vb")return cf(e,t,r);let s=ks(t)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;return re(n,s,(o,a)=>{let l=o[1]?.trim();if(!l)return[];let[c,u]=l.split(/\s*=\s*/),d=!!u,m=(d?u:c)?.trim()??l,g=m.split(".").pop()??m,p=d?c?.trim()??g:g;return[he(e,t,a,m,g,p,j(e,m,at))]})}function cf(e,t,n){let r=B(n,new Set(["imports_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("imports_statement")){let o=s.namedChildren.filter(m=>m.type==="namespace_name");if(o.length===0)continue;let a=o[o.length-1],l=o.length>1?o[0]:null,c=a.text,u=c.split(".").pop()??c,d=l?.text??u;i.push({importedName:u,localName:d,sourcePath:j(e,c,at),kind:l?"namespace":"named",used:r.has(d),usedMembers:[]})}return i}function uf(e,t,n){let r=B(n,new Set(["using_directive"])),i=[];for(let s of n.rootNode.descendantsOfType("using_directive")){let o=s.namedChildren;if(o.length===0)continue;let a=null,l;o.length>=2&&o[0].type==="identifier"&&(o[1].type==="qualified_name"||o[1].type==="identifier")?(a=o[0],l=o[1]):l=o[o.length-1];let c=l.text,u=c.split(".").pop()??c,d=a?.text??u;i.push({importedName:u,localName:d,sourcePath:j(e,c,at),kind:a?"namespace":"named",used:r.has(d),usedMembers:[]})}return i}function js(e,t,n){let r=P(e,t),i=M(t);return r&&i==="java"?df(e,t,r):r&&i==="kotlin"?mf(e,t,r):r&&i==="scala"?pf(e,t,r):re(n,/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm,(s,o)=>{let a=s[1]?.trim();return a?ff(e,t,a,o):[]})}function df(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.children.some(d=>d.type==="asterisk"),l=s.namedChildren.find(d=>d.type==="scoped_identifier")??s.namedChildren.find(d=>d.type==="identifier");if(!l)continue;let c=l.text;if(o){i.push({importedName:"*",localName:null,sourcePath:j(e,c,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let u=c.split(".").pop()??c;i.push({importedName:u,localName:u,sourcePath:j(e,c,ce),kind:"named",used:r.has(u),usedMembers:[]})}return i}function mf(e,t,n){let r=B(n,new Set(["import_header","import_list"])),i=[];for(let s of n.rootNode.descendantsOfType("import_header")){let o=s.namedChildren.find(g=>g.type==="identifier");if(!o)continue;let a=s.namedChildren.some(g=>g.type==="wildcard_import"),l=s.namedChildren.find(g=>g.type==="import_alias");if(a){i.push({importedName:"*",localName:null,sourcePath:j(e,o.text,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let c=o.text,u=c.split(".").pop()??c,m=l?.namedChild(0)?.text??u;i.push({importedName:u,localName:m,sourcePath:j(e,c,ce),kind:"named",used:r.has(m),usedMembers:[]})}return i}function pf(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.namedChildren.find(d=>d.type==="namespace_selectors"||d.type==="namespace_wildcard"),a=s.namedChildren.filter(d=>d!==o&&(d.type==="identifier"||d.type==="stable_identifier")),l=a.map(d=>d.text).join(".");if(!l)continue;if(o?.type==="namespace_wildcard"){i.push({importedName:"*",localName:null,sourcePath:j(e,l,ce),kind:"namespace",used:!0,usedMembers:[]});continue}if(o?.type==="namespace_selectors"){for(let d of o.namedChildren)if(d.type==="arrow_renamed_identifier"){let[m,g]=d.namedChildren;if(!m)continue;let p=m.text,f=g?.text??p;if(p==="_")continue;i.push({importedName:p,localName:f,sourcePath:j(e,`${l}.${p}`,ce),kind:"named",used:r.has(f),usedMembers:[]})}else if(d.type==="identifier"){let m=d.text;i.push({importedName:m,localName:m,sourcePath:j(e,`${l}.${m}`,ce),kind:"named",used:r.has(m),usedMembers:[]})}continue}let c=a[a.length-1]?.text??l,u=a.slice(0,-1).map(d=>d.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:j(e,u&&a.length>1?`${u}.${c}`:l,ce),kind:"named",used:r.has(c),usedMembers:[]})}return i}function ff(e,t,n,r){if(n.includes("{")&&n.includes("}")){let i=n.slice(0,n.indexOf("{")).replace(/\.$/,"").trim(),s=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim();return X(s).flatMap(o=>{let a=o.trim();if(!a)return[];let[l,c]=a.includes("=>")?a.split(/\s*=>\s*/):a.split(/\s+as\s+/),u=l?.trim();if(!u||u==="_")return[];let d=(c??u.split(".").pop()??u).trim(),m=u==="_"?i:`${i}.${u}`.replace(/\.\./g,".");return[he(e,t,r,m,u,d)]})}return[he(e,t,r,n,n.split(".").pop()??n,n.split(".").pop()??n)]}function Ws(e,t,n){let r=P(e,t);return r?gf(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?X(o).flatMap(a=>{let l=a.trim();if(!l)return[];let[c,u]=l.split(/\s+as\s+/i),d=c?.trim()??l,m=d.split("\\").pop()??d,g=(u??m).trim();return[he(e,t,s,d,m,g,j(e,d.replace(/\\/g,"."),_t))]}):[]})}function gf(e,t,n){let r=B(n,new Set(["namespace_use_declaration"])),i=[],s=(o,a,l)=>{i.push({importedName:a,localName:l,sourcePath:j(e,o.replace(/\\/g,"."),_t),kind:"named",used:r.has(l),usedMembers:[]})};for(let o of n.rootNode.descendantsOfType("namespace_use_declaration")){let a=o.namedChildren.find(l=>l.type==="namespace_use_group");if(a){let l=o.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of a.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:u,localName:d,qualified:m}=Bs(c,l);u&&s(m,u,d)}continue}for(let l of o.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:u,qualified:d}=Bs(l,"");c&&s(d,c,u)}}return i}function Bs(e,t){let n=e.namedChildren.find(c=>c.type==="qualified_name"),r=e.namedChildren.filter(c=>c.type==="name"),i="";n?i=n.text:r.length>=1&&(i=r[0].text);let s=n&&r.length>0?r[r.length-1]:null,o=i.split("\\").pop()??i,a=s?.text??o,l=t?`${t}\\${i}`:i;return{importedName:o,localName:a,qualified:l}}function Us(e,t,n){let r=P(e,t);return r?hf(e,t,r):bf(n).flatMap(i=>xf(e,t,i,n))}function hf(e,t,n){let r=B(n,new Set(["import_statement","import_from_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))for(let o of s.namedChildren){let a=Hs(o);if(!a)continue;let l=lt(e,t,a.qualifiedName);i.push({importedName:a.qualifiedName,localName:a.localName,sourcePath:l,kind:"namespace",used:r.has(a.localName),usedMembers:[]})}for(let s of n.rootNode.descendantsOfType("import_from_statement")){let o=s.namedChild(0);if(!o)continue;let a=yf(o);if(a===null)continue;let l=lt(e,t,a);for(let c=1;c<s.namedChildCount;c+=1){let u=s.namedChild(c);if(u.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let d=Hs(u);d&&i.push({importedName:d.qualifiedName,localName:d.localName,sourcePath:l,kind:"named",used:r.has(d.localName),usedMembers:[]})}}return i}function Hs(e){if(e.type==="aliased_import"){let t=e.namedChild(0),n=e.namedChild(1);return!t||!n?null:{qualifiedName:t.text,localName:n.text}}if(e.type==="dotted_name"){let t=e.text;return{qualifiedName:t,localName:t.split(".")[0]??t}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function yf(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let t=ne(e,"import_prefix")?.text??"",n=ne(e,"dotted_name")?.text??"";return`${t}${n}`}return null}function bf(e){let t=e.split(`
368
+ `),n=[],r=0;for(let i=0;i<t.length;i++){let s=t[i],o=s.trimStart(),a=r;if(r+=s.length+1,!o.startsWith("import ")&&!o.startsWith("from "))continue;let l=s,c=a+s.length,u=Vs(s);for(;i+1<t.length&&(u>0||l.trimEnd().endsWith("\\"));){i++;let m=t[i];l+=`
369
+ ${m}`,c+=1+m.length,u+=Vs(m),r+=m.length+1}let d=Sf(l);d&&n.push({...d,start:a,end:c})}return n}function Sf(e){let t=e.replace(/\\\s*\n/g," ").trim();if(t.startsWith("import "))return{kind:"import",module:null,clause:t.slice(7).trim()};let n=t.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!n)return null;let r=n[2].trim();return r.startsWith("(")&&r.endsWith(")")&&(r=r.slice(1,-1).trim()),{kind:"from",module:n[1],clause:r}}function xf(e,t,n,r){let i=Oe(r,n.start,n.end),s=n.clause.replace(/\n/g," ").trim();if(n.kind==="import")return X(s).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[u,d]=c.split(/\s+as\s+/),m=u.trim(),g=(d??m.split(".")[0]??m).trim(),p=lt(e,t,m),f=ot(i,g);return[{importedName:m,localName:g,sourcePath:p,kind:"namespace",used:K(i,g)||f.length>0,usedMembers:f}]});let o=n.module?lt(e,t,n.module):null,a=[];for(let l of X(s)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){a.push({importedName:"*",localName:null,sourcePath:o,kind:"side-effect",used:!0,usedMembers:[]});continue}let[u,d]=c.split(/\s+as\s+/),m=(d??u).trim();a.push({importedName:u.trim(),localName:m,sourcePath:o,kind:"named",used:K(i,m),usedMembers:[]})}return a}function Vs(e){let t=0;for(let n of e)n==="("&&t++,n===")"&&t--;return t}import{basename as _f}from"path";function Js(e,t,n){let r=P(e,t);return r?If(e,t,r):re(n,/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm,(i,s)=>{let o=i[1],a=i[2];if(!o||!a)return[];let l=o==="require_relative"?dn(e,t,a):null;if(l){let c=qs(a);return[{importedName:c,localName:c,sourcePath:l,kind:"named",used:K(s,c),usedMembers:[]}]}return[{importedName:a,localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]}]})}function If(e,t,n){let r=B(n,new Set([])),i=[],s=new Set(["require","require_relative","load"]);for(let o of n.rootNode.descendantsOfType("call")){let a=o.namedChild(0);if(!a||a.type!=="identifier"||!s.has(a.text))continue;let c=o.namedChildren.find(g=>g.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let d=c.namedChildren.find(g=>g.type==="string_content")?.text;if(!d)continue;let m=a.text==="require_relative"?dn(e,t,d):null;if(m){let g=qs(d);i.push({importedName:g,localName:g,sourcePath:m,kind:"named",used:r.has(g),usedMembers:[]})}else i.push({importedName:d,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function qs(e){return _f(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function zs(e,t,n){let r=P(e,t);return r?Rf(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?Cf(e,t,o,s):[]})}function Rf(e,t,n){let r=B(n,new Set(["use_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("use_declaration")){let o=s.namedChild(0);if(o)for(let a of Rt(o,"")){if(!a.importedName||a.importedName==="*")continue;let l=xe(e,t,a.qualifiedName)??xe(e,t,a.qualifiedName.split("::").slice(0,-1).join("::"));i.push({importedName:a.importedName,localName:a.localName,sourcePath:l,kind:"named",used:r.has(a.localName),usedMembers:[]})}}return i}function Rt(e,t){switch(e.type){case"identifier":case"super":case"self":case"crate":{let n=e.text;return[{qualifiedName:fn(t,n),importedName:n,localName:n}]}case"scoped_identifier":{let n=e.text,r=n.split("::").pop()??n;return[{qualifiedName:fn(t,n),importedName:r,localName:r}]}case"scoped_use_list":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=fn(t,n.text),s=[];for(let o of r.namedChildren)s.push(...Rt(o,i));return s}case"use_list":{let n=[];for(let r of e.namedChildren)n.push(...Rt(r,t));return n}case"use_as_clause":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=Rt(n,t),s=r.text;return i.map(o=>({...o,localName:s}))}case"use_wildcard":{let n=e.namedChild(0),r=n?n.text:"";return[{qualifiedName:fn(t,`${r}::*`),importedName:"*",localName:"*"}]}default:return[]}}function fn(e,t){return e?t?`${e}::${t}`:e:t}function Cf(e,t,n,r){let i=n.trim();if(i.includes("{")&&i.includes("}")){let u=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),d=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return X(d).flatMap(m=>{let g=m.trim();if(!g||g==="self")return[];let[p,f]=g.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let L=(f??y.split("::").pop()??y).trim(),k=`${u}::${y}`.replace(/::::/g,"::");return[he(e,t,r,k,y.split("::").pop()??y,L,xe(e,t,u))]})}let[s,o]=i.split(/\s+as\s+/),a=s?.trim()??i,l=(o??a.split("::").pop()??a).trim(),c=xe(e,t,a)??xe(e,t,a.split("::").slice(0,-1).join("::"));return[he(e,t,r,a,a.split("::").pop()??a,l,c)]}function Gs(e,t,n){let r=P(e,t);if(r)return vf(e,t,r);let i=[];for(let s of n.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let o=s[1]?.trim();o&&i.push(...Ef(e,t,o))}return i}function vf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("use_declaration")){if(!Nf(i))continue;let s=i.namedChildren.find(o=>o.type!=="visibility_modifier");if(s)for(let o of Rt(s,""))o.importedName&&r.push(_r(e,t,o.qualifiedName))}return r}function Nf(e){for(let t of e.children)if(t.type==="visibility_modifier"&&t.text.startsWith("pub"))return!0;return!1}function Ef(e,t,n){let r=n.trim();if(r.includes("{")&&r.includes("}")){let i=r.slice(0,r.indexOf("{")).replace(/::$/,"").trim(),s=r.slice(r.indexOf("{")+1,r.lastIndexOf("}")).trim();return X(s).flatMap(o=>{let a=o.trim();if(!a||a==="self")return[];let[l]=a.split(/\s+as\s+/),c=`${i}::${l?.trim()??a}`.replace(/::::/g,"::");return[_r(e,t,c)]})}return[_r(e,t,r)]}function _r(e,t,n){return{specifier:n,sourcePath:xe(e,t,n)??xe(e,t,n.split("::").slice(0,-1).join("::"))}}function Ks(e,t){let n=t.toLowerCase();for(let r of e)for(let i of r.extensions)if(n.endsWith(i))return r;return null}var Df={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Ps},Lf={language:"python",extensions:[".py",".pyi"],parseImports:Us},kf={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:js},wf={language:"rust",extensions:[".rs"],parseImports:zs,parseExports:Gs},Pf={language:"ruby",extensions:[".rb"],parseImports:Js},Of={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:Fs},Mf={language:"dotnet",extensions:[".cs",".vb"],parseImports:As},Ff={language:"dart",extensions:[".dart"],parseImports:Ts,parseExports:$s},Tf={language:"php",extensions:[".php"],parseImports:Ws},$f=[Df,Lf,kf,wf,Pf,Of,Mf,Ff,Tf];function Ir(e){return Ks($f,e)}function Ys(e,t){return Os(e,t)}var Af=$("source-imports"),jf=$("source-exports");function J(e,t){let n=fe(t);return Af.get(e,n,()=>{let r=Ir(n);if(!r)return[];let i=w(e,n);return i?r.parseImports(e,n,i):[]})}function Rr(e,t){let n=fe(t);return jf.get(e,n,()=>{let r=Ir(n);if(!r?.parseExports)return[];let i=w(e,n);return i?r.parseExports(e,n,i):[]})}import ue from"path";import{createRequire as Bf}from"module";import{existsSync as gn,readdirSync as Wf,readFileSync as eo}from"fs";var Hf=Bf(import.meta.url),Ct;function to(e,t){let n=Vf();if(!n)return Cr("ts-morph is not installed");let r=wi(e);if(r.length===0)return Cr("no tsconfig found");try{let i=r.map(s=>({tsconfigPath:s,project:new n.Project({tsConfigFilePath:s,skipFileDependencyResolution:!1})}));return new vr(e,n,i)}catch(i){return Cr(i instanceof Error?i.message:String(i),r[0],r)}}function Vf(){if(Ct!==void 0)return Ct;try{Ct=Hf("ts-morph")}catch{Ct=null}return Ct}function Cr(e,t,n){return{language:"typescript",availability:()=>({available:!1,reason:e,tsconfigPath:t,tsconfigPaths:n}),importUsage:()=>[],referencesFor:()=>[],calleesFor:()=>[],signatureFor:()=>null}}var vr=class{constructor(t,n,r){this.db=t;this.tsMorph=n;this.projects=r;this.workspacePackages=Gf(t.config.projectRoot)}db;tsMorph;projects;language="typescript";importUsageCache=new Map;referencesCache=new Map;calleesCache=new Map;fileCalleesCache=new Map;signatureCache=new Map;sourceFileCache=new Map;definitionNodeCache=new Map;fileDefinitionNodeCache=new Map;indexedDefinitionLeafCache=new Map;packageImportReferenceIndex=null;packageExportIndex=null;workspacePackages;availability(){return{available:!0,tsconfigPath:this.projects[0]?.tsconfigPath,tsconfigPaths:this.projects.map(t=>t.tsconfigPath)}}importUsage(t){return _e(this.importUsageCache,t,()=>{let n=this.sourceFile(t);if(!n)return[];let r=[];for(let i of n.getImportDeclarations())for(let s of this.importUsageForDeclaration(t,i))r.push(s);return r})}referencesFor(t){return _e(this.referencesCache,t.symbolId,()=>{let n=this.nodeForDefinition(t),r=this.packageImportReferencesForDefinition(t);return n?tg(n,t,r,this.db.config.projectRoot):r})}calleesFor(t){return _e(this.calleesCache,t.symbolId,()=>_e(this.fileCalleesCache,t.relativePath,()=>this.calleeMapForFile(t.relativePath)).get(t.symbolId)??[])}signatureFor(t){return _e(this.signatureCache,t.symbolId,()=>{let n=this.nodeForDefinition(t);if(!n||!this.tsMorph.Node.isFunctionDeclaration(n)&&!this.tsMorph.Node.isMethodDeclaration(n)&&!this.tsMorph.Node.isArrowFunction(n)&&!this.tsMorph.Node.isFunctionExpression(n)&&!this.tsMorph.Node.isConstructorDeclaration(n))return null;let r=n.getType().getCallSignatures()[0];if(!r)return null;let i=r.getParameters().map(o=>{let a=o.getDeclarations()[0],l=a?o.getTypeAtLocation(a).getText(a):o.getValueDeclaration()?.getType().getText()??"unknown";return Zs(l)}),s=r.getReturnType().getText(n);return`(${i.join(",")})=>${Zs(s)}`})}importUsageForDeclaration(t,n){let r=ge(this.db,t,n.getModuleSpecifierValue()),i=Qs(n);return n.getImportClause()?.isTypeOnly()?i.map(s=>qf(t,r,s)):i.map(s=>this.valueImportUsageForEntry(t,r,s))}valueImportUsageForEntry(t,n,r){let i=r.identifier?r.identifier.findReferences():[],s=[];for(let c of i)for(let u of ng(c,t,r.identifier,this.db.config.projectRoot))s.push(u);let o=s.some(c=>!Xs(c.node)),a=s.some(c=>Xs(c.node)),l=r.isTypeOnly;return{importer:t,sourcePath:n,importedName:r.importedName,localName:r.localName,kind:r.kind,isTypeOnly:l,isUsed:l||s.length>0,isTypeUsed:l||a,isValueUsed:o,references:s.map(c=>c.location)}}sourceFile(t){return this.sourceFileMatch(t)?.sourceFile??null}sourceFileMatch(t){return ug(t)?_e(this.sourceFileCache,t,()=>{let n=ue.join(this.db.config.projectRoot,t);for(let{project:r}of this.projects){let i=r.getSourceFile(n)??r.addSourceFileAtPathIfExists(n)??null;if(i)return{project:r,sourceFile:i}}return null}):null}packageImportReferencesForDefinition(t){return this.packageImportReferences().get(t.symbolId)??[]}packageImportReferences(){if(this.packageImportReferenceIndex)return this.packageImportReferenceIndex;let t=new Map,n=this.packageExports();for(let r of this.indexedTypeScriptLikeDocuments())this.addPackageImportReferencesForDocument(t,n,r);for(let[r,i]of t)t.set(r,Nr(i));return this.packageImportReferenceIndex=t,t}indexedTypeScriptLikeDocuments(){return this.db.all(`SELECT relative_path
370
370
  FROM documents
371
371
  WHERE (
372
372
  relative_path LIKE '%.ts'
@@ -378,8 +378,8 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
378
378
  OR relative_path LIKE '%.mjs'
379
379
  OR relative_path LIKE '%.cjs'
380
380
  )
381
- ${this.db.pathExclusionsFor("documents")}`).map(t=>t.relative_path)}addPackageImportReferencesForDocument(t,n,r){if(this.db.isIgnored(r))return;let i=this.sourceFileMatch(r);if(i)for(let s of i.sourceFile.getImportDeclarations())this.addPackageImportReferencesForDeclaration(t,n,r,s)}addPackageImportReferencesForDeclaration(t,n,r,i){let s=Mf(this.workspacePackages,i.getModuleSpecifierValue());if(!s)return;let o=n.get(s);if(o)for(let a of Js(i)){if(a.kind!=="named"||!a.identifier)continue;let l=o.get(a.importedName);if(!l||l.size===0)continue;let c=jf(a.identifier,r,this.db.config.projectRoot);c.length>0&&Uf(t,l,c)}}packageExports(){if(this.packageExportIndex)return this.packageExportIndex;let t=new Map;for(let n of this.workspacePackages){let r=new Map;for(let i of Ff(n))this.collectPackageExports(n,i,r,new Set);r.size>0&&t.set(n.name,r)}return this.packageExportIndex=t,t}collectPackageExports(t,n,r,i){if(i.has(n))return;i.add(n);let s=this.sourceFile(n);if(s)for(let o of s.getExportDeclarations()){let a=o.getModuleSpecifierValue(),l=a?ge(this.db,n,a):n;if(!l||!l.startsWith(`${t.sourceRootRelative}/`))continue;let c=o.getNamedExports();if(c.length===0){if(o.isNamespaceExport())continue;this.collectPackageExports(t,l,r,i);continue}for(let d of c){let u=d.getNameNode().getText(),m=d.getAliasNode()?.getText()??u,f=this.indexedDefinitionByLeaf(l,u);if(!f)continue;let p=r.get(m);p||(p=new Set,r.set(m,p)),p.add(f.symbolId)}}}indexedDefinitionByLeaf(t,n){return qe(this.indexedDefinitionLeafCache,t,()=>Hf(this.db,t)).get(n)??null}nodeForDefinition(t){let n=this.sourceFile(t.relativePath);if(!n)return null;let r=k(t.symbol)??t.leaf,i=[];return n.forEachDescendant(s=>{if(!Bf(this.tsMorph,s,r))return;let o=ut(n,s);o<t.startLine-1||o>t.endLine+1||i.push(s)}),i.sort((s,o)=>Math.abs(ut(n,s)-t.startLine)-Math.abs(ut(n,o)-t.startLine))[0]??null}definitionFromSymbol(t){let n=t.getDeclarations();for(let r of n){let i=r.getSourceFile(),s=yn(this.db.config.projectRoot,i.getFilePath());if(!s||this.db.isIgnored(s))continue;let o=ut(i,r),a=Wf(this.db,s,o,t.getName());if(a)return{symbol:a.symbol,file:a.relativePath,line:a.startLine}}return null}calleeMapForFile(t){let n=this.sourceFile(t);if(!n)return new Map;let r=ee(this.db,t).sort((s,o)=>s.startLine-o.startLine||o.endLine-s.endLine);if(r.length===0)return new Map;let i=new Map;n.forEachDescendant(s=>{if(!this.tsMorph.Node.isCallExpression(s)&&!this.tsMorph.Node.isNewExpression(s))return;let o=this.semanticCalleeForCallNode(n,r,s);o&&kf(i,o.callerId,o.target)});for(let[s,o]of i)i.set(s,Jf(o));return i}semanticCalleeForCallNode(t,n,r){let i=Vf(n,ut(t,r));if(!i)return null;let s=r.getExpression(),o=s.getSymbol()??s.getType().getSymbol(),a=o?this.definitionFromSymbol(o):null;return a?{callerId:i.symbolId,target:{symbol:a.symbol,file:a.file,line:a.line}}:null}};function Js(e){let t=[],n=e.getDefaultImport();n&&t.push({identifier:n,importedName:"default",localName:n.getText(),kind:"default",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});let r=e.getNamespaceImport();r&&t.push({identifier:r,importedName:"*",localName:r.getText(),kind:"namespace",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});for(let i of e.getNamedImports()){let s=i.getNameNode(),a=i.getAliasNode()??(s.getKindName()==="Identifier"?s:null);t.push({identifier:a,importedName:s.getText(),localName:a?.getText()??s.getText(),kind:"named",isTypeOnly:i.isTypeOnly()||(e.getImportClause()?.isTypeOnly()??!1)})}return t.length===0&&t.push({identifier:null,importedName:"*",localName:null,kind:"side-effect",isTypeOnly:!1}),t}function Lf(e,t,n){return{importer:e,sourcePath:t,importedName:n.importedName,localName:n.localName,kind:n.kind,isTypeOnly:!0,isUsed:!0,isTypeUsed:!0,isValueUsed:!1,references:[]}}function kf(e,t,n){let r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}function wf(e){let t=ue.join(e,"package.json");if(!hn(t))return[];let n;try{n=JSON.parse(Gs(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>Pf(e,i)).flatMap(i=>Of(e,i))}function Pf(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=ue.join(e,t);return hn(ue.join(o,"package.json"))?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=ue.join(e,r||".");if(!hn(s))return[];try{return Nf(s).map(o=>ue.join(s,o,i)).filter(o=>hn(ue.join(o,"package.json")))}catch{return[]}}function Of(e,t){try{let n=JSON.parse(Gs(ue.join(t,"package.json"),"utf8"));if(!n.name)return[];let r=ue.relative(e,t).replace(/\\/g,"/");return[{name:n.name,rootRelative:r,sourceRootRelative:`${r}/src`}]}catch{return[]}}function Mf(e,t){for(let n of e)if(t===n.name||t.startsWith(`${n.name}/`))return n.name;return null}function Ff(e){return[`${e.sourceRootRelative}/index.ts`,`${e.sourceRootRelative}/index.tsx`,`${e.sourceRootRelative}/index.mts`,`${e.sourceRootRelative}/index.cts`]}function Tf(e,t){return e.getReferences().map(n=>{let r=n.getNode();return Qs(r,t)})}function $f(e){let t=e;return typeof t.findReferences=="function"?t.findReferences():[]}function Af(e,t,n,r){return e.getReferences().map(i=>i.getNode()).filter(i=>yn(r,i.getSourceFile().getFilePath())===t).filter(i=>!n||i.getStart()!==n.getStart()).map(i=>({location:Qs(i,r),node:i}))}function Qs(e,t){let n=e.getSourceFile(),r=n.getLineAndColumnAtPos(e.getStart());return{file:yn(t,n.getFilePath())??n.getBaseName(),line:r.line-1,column:r.column-1}}function jf(e,t,n){let r=e.getSourceFile(),i=ut(r,e),s=e.getText(),o=new RegExp(`\\b${zf(s)}\\b`,"g"),a=r.getFullText().split(`
382
- `),l=[];for(let c=0;c<a.length;c++){if(c===i)continue;let d=a[c]??"";o.lastIndex=0;let u;for(;(u=o.exec(d))!==null;)l.push({file:t,line:c,column:u.index})}return Er(l.filter(c=>yn(n,ue.join(n,c.file))===t))}function qs(e){for(let t=e;t;t=t.getParent()){let n=t.getKindName();if(n.includes("Type")||n==="InterfaceDeclaration"||n==="TypeAliasDeclaration")return!0;if(n==="CallExpression"||n==="NewExpression"||n==="ExpressionStatement")return!1}return!1}function Bf(e,t,n){return"getNameNode"in t&&typeof t.getNameNode=="function"&&t.getNameNode()?.getText()===n||"getName"in t&&typeof t.getName=="function"&&t.getName()===n?!0:e.Node.isIdentifier(t)&&t.getText()===n}function Wf(e,t,n,r){return e.all(`SELECT
381
+ ${this.db.pathExclusionsFor("documents")}`).map(t=>t.relative_path)}addPackageImportReferencesForDocument(t,n,r){if(this.db.isIgnored(r))return;let i=this.sourceFileMatch(r);if(i)for(let s of i.sourceFile.getImportDeclarations())this.addPackageImportReferencesForDeclaration(t,n,r,s)}addPackageImportReferencesForDeclaration(t,n,r,i){let s=Qf(this.workspacePackages,i.getModuleSpecifierValue());if(!s)return;let o=n.get(s);if(o)for(let a of Qs(i)){if(a.kind!=="named"||!a.identifier)continue;let l=o.get(a.importedName);if(!l||l.size===0)continue;let c=rg(a.identifier,r,this.db.config.projectRoot);c.length>0&&lg(t,l,c)}}packageExports(){if(this.packageExportIndex)return this.packageExportIndex;let t=new Map;for(let n of this.workspacePackages){let r=new Map;for(let i of Xf(n))this.collectPackageExports(n,i,r,new Set);r.size>0&&t.set(n.name,r)}return this.packageExportIndex=t,t}collectPackageExports(t,n,r,i){if(i.has(n))return;i.add(n);let s=this.sourceFile(n);if(s)for(let o of s.getExportDeclarations()){let a=o.getModuleSpecifierValue(),l=a?ge(this.db,n,a):n;if(!l||!l.startsWith(`${t.sourceRootRelative}/`))continue;let c=o.getNamedExports();if(c.length===0){if(o.isNamespaceExport())continue;this.collectPackageExports(t,l,r,i);continue}for(let u of c){let d=u.getNameNode().getText(),m=u.getAliasNode()?.getText()??d,g=this.indexedDefinitionByLeaf(l,d);if(!g)continue;let p=r.get(m);p||(p=new Set,r.set(m,p)),p.add(g.symbolId)}}}indexedDefinitionByLeaf(t,n){return _e(this.indexedDefinitionLeafCache,t,()=>og(this.db,t)).get(n)??null}nodeForDefinition(t){return _e(this.definitionNodeCache,t.symbolId,()=>this.definitionNodesForFile(t.relativePath).get(t.symbolId)??null)}definitionNodesForFile(t){return _e(this.fileDefinitionNodeCache,t,()=>{let n=this.sourceFile(t);if(!n)return new Map;let r=Uf(this.db,t);return r.size===0?new Map:Jf(this.tsMorph,n,r)})}definitionFromSymbol(t){let n=t.getDeclarations();for(let r of n){let i=r.getSourceFile(),s=yn(this.db.config.projectRoot,i.getFilePath());if(!s||this.db.isIgnored(s))continue;let o=hn(i,r),a=sg(this.db,s,o,t.getName());if(a)return{symbol:a.symbol,file:a.relativePath,line:a.startLine}}return null}calleeMapForFile(t){let n=this.sourceFile(t);if(!n)return new Map;let r=Q(this.db,t).sort((s,o)=>s.startLine-o.startLine||o.endLine-s.endLine);if(r.length===0)return new Map;let i=new Map;n.forEachDescendant(s=>{if(!this.tsMorph.Node.isCallExpression(s)&&!this.tsMorph.Node.isNewExpression(s))return;let o=this.semanticCalleeForCallNode(n,r,s);o&&zf(i,o.callerId,o.target)});for(let[s,o]of i)i.set(s,cg(o));return i}semanticCalleeForCallNode(t,n,r){let i=ag(n,hn(t,r));if(!i)return null;let s=r.getExpression(),o=s.getSymbol()??s.getType().getSymbol(),a=o?this.definitionFromSymbol(o):null;return a?{callerId:i.symbolId,target:{symbol:a.symbol,file:a.file,line:a.line}}:null}};function Qs(e){let t=[],n=e.getDefaultImport();n&&t.push({identifier:n,importedName:"default",localName:n.getText(),kind:"default",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});let r=e.getNamespaceImport();r&&t.push({identifier:r,importedName:"*",localName:r.getText(),kind:"namespace",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});for(let i of e.getNamedImports()){let s=i.getNameNode(),a=i.getAliasNode()??(s.getKindName()==="Identifier"?s:null);t.push({identifier:a,importedName:s.getText(),localName:a?.getText()??s.getText(),kind:"named",isTypeOnly:i.isTypeOnly()||(e.getImportClause()?.isTypeOnly()??!1)})}return t.length===0&&t.push({identifier:null,importedName:"*",localName:null,kind:"side-effect",isTypeOnly:!1}),t}function Uf(e,t){let n=new Map;for(let r of Q(e,t)){let i=D(r.symbol)??r.leaf;if(!i)continue;let s=n.get(i);s||(s=[],n.set(i,s)),s.push(r)}return n}function Jf(e,t,n){let r=new Map,i=new Map;return t.forEachDescendant(s=>{for(let o of ig(e,s)){let a=n.get(o);if(!a)continue;let l=hn(t,s);for(let c of a){if(l<c.startLine-1||l>c.endLine+1)continue;let u=Math.abs(l-c.startLine),d=i.get(c.symbolId);d!==void 0&&d<=u||(i.set(c.symbolId,u),r.set(c.symbolId,s))}}}),r}function qf(e,t,n){return{importer:e,sourcePath:t,importedName:n.importedName,localName:n.localName,kind:n.kind,isTypeOnly:!0,isUsed:!0,isTypeUsed:!0,isValueUsed:!1,references:[]}}function zf(e,t,n){let r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}function Gf(e){let t=ue.join(e,"package.json");if(!gn(t))return[];let n;try{n=JSON.parse(eo(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>Kf(e,i)).flatMap(i=>Yf(e,i))}function Kf(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=ue.join(e,t);return gn(ue.join(o,"package.json"))?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=ue.join(e,r||".");if(!gn(s))return[];try{return Wf(s).map(o=>ue.join(s,o,i)).filter(o=>gn(ue.join(o,"package.json")))}catch{return[]}}function Yf(e,t){try{let n=JSON.parse(eo(ue.join(t,"package.json"),"utf8"));if(!n.name)return[];let r=ue.relative(e,t).replace(/\\/g,"/");return[{name:n.name,rootRelative:r,sourceRootRelative:`${r}/src`}]}catch{return[]}}function Qf(e,t){for(let n of e)if(t===n.name||t.startsWith(`${n.name}/`))return n.name;return null}function Xf(e){return[`${e.sourceRootRelative}/index.ts`,`${e.sourceRootRelative}/index.tsx`,`${e.sourceRootRelative}/index.mts`,`${e.sourceRootRelative}/index.cts`]}function Zf(e,t){return e.getReferences().map(n=>{let r=n.getNode();return no(r,t)})}function eg(e){let t=e;return typeof t.findReferences=="function"?t.findReferences():[]}function tg(e,t,n,r){let i=[];for(let s of eg(e))for(let o of Zf(s,r))o.file===t.relativePath&&o.line>=t.startLine&&o.line<=t.endLine||i.push(o);for(let s of n)i.push(s);return Nr(i)}function ng(e,t,n,r){let i=[],s=n?.getStart();for(let o of e.getReferences()){let a=o.getNode();yn(r,a.getSourceFile().getFilePath())===t&&(s!==void 0&&a.getStart()===s||i.push({location:no(a,r),node:a}))}return i}function no(e,t){let n=e.getSourceFile(),r=n.getLineAndColumnAtPos(e.getStart());return{file:yn(t,n.getFilePath())??n.getBaseName(),line:r.line-1,column:r.column-1}}function rg(e,t,n){let r=e.getSourceFile(),i=hn(r,e),s=e.getText(),o=new RegExp(`\\b${dg(s)}\\b`,"g"),a=r.getFullText().split(`
382
+ `),l=[];for(let c=0;c<a.length;c++){if(c===i)continue;let u=a[c]??"";o.lastIndex=0;let d;for(;(d=o.exec(u))!==null;)l.push({file:t,line:c,column:d.index})}return Nr(l.filter(c=>yn(n,ue.join(n,c.file))===t))}function Xs(e){for(let t=e;t;t=t.getParent()){let n=t.getKindName();if(n.includes("Type")||n==="InterfaceDeclaration"||n==="TypeAliasDeclaration")return!0;if(n==="CallExpression"||n==="NewExpression"||n==="ExpressionStatement")return!1}return!1}function ig(e,t){let n=[],r=i=>{i&&!n.includes(i)&&n.push(i)};if("getNameNode"in t&&typeof t.getNameNode=="function"){let i=t.getNameNode();r(i?.getText())}if("getName"in t&&typeof t.getName=="function"){let i=t.getName();r(i)}return e.Node.isIdentifier(t)&&r(t.getText()),n}function sg(e,t,n,r){return e.all(`SELECT
383
383
  gs.id AS symbolId,
384
384
  gs.symbol,
385
385
  d.relative_path AS relativePath,
@@ -399,7 +399,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
399
399
  WHERE d.relative_path = ?
400
400
  AND COALESCE(gs.display_name, gs.symbol) LIKE ?
401
401
  ORDER BY ABS(COALESCE(der.start_line, c.start_line) - ?)
402
- LIMIT 5`,t,`%${r}%`,n)[0]??null}function Hf(e,t){let n=e.all(`SELECT
402
+ LIMIT 5`,t,`%${r}%`,n)[0]??null}function og(e,t){let n=e.all(`SELECT
403
403
  d.id AS documentId,
404
404
  gs.id AS symbolId,
405
405
  gs.symbol,
@@ -439,7 +439,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
439
439
  WHERE d.relative_path = ?
440
440
  AND m.role = 1
441
441
  GROUP BY gs.id, gs.symbol, d.id, d.relative_path, gs.display_name, gs.kind, gs.documentation, gs.enclosing_symbol
442
- ORDER BY startLine, endLine`,t,t),r=new Set,i=new Map;for(let s of n){if(r.has(s.symbolId))continue;r.add(s.symbolId);let o=s.leaf||k(s.symbol);!o||i.has(o)||i.set(o,{...s,leaf:o})}return i}function Vf(e,t){let n=null;for(let r of e)t<r.startLine||t>r.endLine||(!n||r.startLine>=n.startLine)&&(n=r);return n}function ut(e,t){return e.getLineAndColumnAtPos(t.getStart()).line-1}function Er(e){let t=new Set,n=[];for(let r of e){let i=`${r.file}:${r.line}:${r.column}`;t.has(i)||(t.add(i),n.push(r))}return n}function Uf(e,t,n){for(let r of t){let i=e.get(r)??[];i.push(...n),e.set(r,i)}}function Jf(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}|${r.line}`;t.has(i)||(t.add(i),n.push(r))}return n}function qe(e,t,n){if(e.has(t))return e.get(t);let r=n();return e.set(t,r),r}function yn(e,t){let n=ue.relative(e||process.cwd(),t).replace(/\\/g,"/");return!n||n.startsWith("..")?null:n}function qf(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}function zs(e){return e.replace(/\s+/g," ").replace(/\bimport\("[^"]+"\)\./g,"").trim()}function zf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ys=new WeakMap;function Xs(e,t){let n=`${e.config.projectRoot}:typescript-workspace`,r=Ys.get(e);r||(r=new Map,Ys.set(e,r));let i=r.get(n);if(i)return i;let s=Ks(e,t);return r.set(n,s),s}function vt(e,t){let n=bn(e,t);return n?n.importUsage(t):[]}function Nt(e,t){let n=bn(e,t.relativePath);return n?n.referencesFor(t):[]}function dt(e,t){let n=new Map;for(let r of t)for(let i of Nt(e,r)){if(i.file===r.relativePath||e.isIgnored(i.file))continue;let s=n.get(r.symbolId);s||(s=new Set,n.set(r.symbolId,s)),s.add(i.file)}return n}function Zs(e,t){let n=new Map;for(let r of t){let i=bn(e,r.relativePath);if(!i)continue;let s=i.calleesFor(r);s.length>0&&n.set(r.symbolId,s)}return n}function eo(e,t){let n=bn(e,t.relativePath);return n?n.signatureFor(t):null}function bn(e,t){if(!Gf(t))return null;let n=Xs(e,t);return n.availability().available?n:null}function Gf(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}var Kf=$("file-dep-graph");function Q(e,t){return Kf.get(e,t??"",()=>{let n=new Map,r=Yf(e),i=(s,o)=>Xf(e,n,r,s,o);for(let s of Qf(e,t))i(s.from_file,s.to_file);for(let s of r)if(!(t&&!s.includes(t)))for(let o of J(e,s))o.sourcePath&&i(s,o.sourcePath);return n})}function Qf(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
442
+ ORDER BY startLine, endLine`,t,t),r=new Set,i=new Map;for(let s of n){if(r.has(s.symbolId))continue;r.add(s.symbolId);let o=s.leaf||D(s.symbol);!o||i.has(o)||i.set(o,{...s,leaf:o})}return i}function ag(e,t){let n=null;for(let r of e)t<r.startLine||t>r.endLine||(!n||r.startLine>=n.startLine)&&(n=r);return n}function hn(e,t){return e.getLineAndColumnAtPos(t.getStart()).line-1}function Nr(e){let t=new Set,n=[];for(let r of e){let i=`${r.file}:${r.line}:${r.column}`;t.has(i)||(t.add(i),n.push(r))}return n}function lg(e,t,n){for(let r of t){let i=e.get(r)??[];i.push(...n),e.set(r,i)}}function cg(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}|${r.line}`;t.has(i)||(t.add(i),n.push(r))}return n}function _e(e,t,n){if(e.has(t))return e.get(t);let r=n();return e.set(t,r),r}function yn(e,t){let n=ue.relative(e||process.cwd(),t).replace(/\\/g,"/");return!n||n.startsWith("..")?null:n}function ug(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}function Zs(e){return e.replace(/\s+/g," ").replace(/\bimport\("[^"]+"\)\./g,"").trim()}function dg(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ro=new WeakMap;function io(e,t){let n=`${e.config.projectRoot}:typescript-workspace`,r=ro.get(e);r||(r=new Map,ro.set(e,r));let i=r.get(n);if(i)return i;let s=to(e,t);return r.set(n,s),s}function vt(e,t){let n=bn(e,t);return n?n.importUsage(t):[]}function Nt(e,t){let n=bn(e,t.relativePath);return n?n.referencesFor(t):[]}function ut(e,t){let n=new Map;for(let r of t)for(let i of Nt(e,r)){if(i.file===r.relativePath||e.isIgnored(i.file))continue;let s=n.get(r.symbolId);s||(s=new Set,n.set(r.symbolId,s)),s.add(i.file)}return n}function so(e,t){let n=new Map;for(let r of t){let i=bn(e,r.relativePath);if(!i)continue;let s=i.calleesFor(r);s.length>0&&n.set(r.symbolId,s)}return n}function oo(e,t){let n=bn(e,t.relativePath);return n?n.signatureFor(t):null}function bn(e,t){if(!mg(t))return null;let n=io(e,t);return n.availability().available?n:null}function mg(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}var pg=$("file-dep-graph");function Y(e,t){return pg.get(e,t??"",()=>{let n=new Map,r=gg(e),i=(s,o)=>hg(e,n,r,s,o);for(let s of fg(e,t))i(s.from_file,s.to_file);for(let s of r)if(!(t&&!s.includes(t)))for(let o of J(e,s))o.sourcePath&&i(s,o.sourcePath);return n})}function fg(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
443
443
  d1.relative_path AS from_file,
444
444
  d2.relative_path AS to_file
445
445
  FROM mentions m
@@ -457,11 +457,11 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
457
457
  WHERE d1.id != d2.id
458
458
  AND m.role != 1
459
459
  ${e.pathExclusionsFor("d1","d2")}
460
- ${n}`)}function Yf(e){return new Set(e.all(`SELECT relative_path
460
+ ${n}`)}function gg(e){return new Set(e.all(`SELECT relative_path
461
461
  FROM documents
462
462
  WHERE 1 = 1
463
463
  ${e.pathExclusionsFor("documents")}
464
- ORDER BY relative_path`).map(t=>t.relative_path).filter(t=>!e.isIgnored(t)))}function Xf(e,t,n,r,i){if(r===i||e.isIgnored(r)||e.isIgnored(i)||!n.has(i))return;let s=t.get(r);s||(s=new Set,t.set(r,s)),s.add(i)}function X(e,t,n={}){let r=Sn(e,[t],{additive:n.additive}),i=n.callableOnly?(r.get(t.symbolId)??[]).filter(s=>U(s.symbol)):r.get(t.symbolId)??[];return typeof n.limit=="number"?i.slice(0,n.limit):i}function ie(e,t,n={}){let r=tg(e)?rg(e,t):ng(e).get(t.symbolId)??[];return typeof n.limit=="number"?r.slice(0,n.limit):r}var Zf=$e("caller-rows"),eg=2e4;function tg(e){return(e.get("SELECT COUNT(*) AS count FROM global_symbols")?.count??0)>eg}function ng(e){return Zf.get(e,()=>{let t=oe(e),n=Sn(e,t),r=new Map;for(let o of t)r.set(o.symbol,o.symbolId);let i=new Map,s=new Map;for(let o of t){let a=n.get(o.symbolId);if(!(!a||a.length===0))for(let l of a){let c=r.get(l.symbol);if(c===void 0||c===o.symbolId)continue;let d=i.get(c);d||(d=[],i.set(c,d),s.set(c,new Set));let u=`${o.symbol}|${o.relativePath}`;s.get(c).has(u)||(s.get(c).add(u),d.push({symbol:o.symbol,file:o.relativePath}))}}return i})}function rg(e,t){let n=[],r=new Set,i=o=>{if(o.symbol===t.symbol)return;let a=`${o.symbol}|${o.file}`;r.has(a)||(r.add(a),n.push(o))};for(let o of _e(e,t))o.file!==t.relativePath&&i({symbol:o.enclosingSymbol??o.file,file:o.file});let s=ig(e,t);if(s)for(let o of Nt(e,s)){if(o.file===t.relativePath||e.isIgnored(o.file))continue;let a=ae(ee(e,o.file),o.line);i({symbol:a?.symbol??o.file,file:o.file})}return n}function ig(e,t){return e.get(`SELECT
464
+ ORDER BY relative_path`).map(t=>t.relative_path).filter(t=>!e.isIgnored(t)))}function hg(e,t,n,r,i){if(r===i||e.isIgnored(r)||e.isIgnored(i)||!n.has(i))return;let s=t.get(r);s||(s=new Set,t.set(r,s)),s.add(i)}function Z(e,t,n={}){let r=Sn(e,[t],{additive:n.additive}),i=n.callableOnly?(r.get(t.symbolId)??[]).filter(s=>U(s.symbol)):r.get(t.symbolId)??[];return typeof n.limit=="number"?i.slice(0,n.limit):i}function ie(e,t,n={}){let r=Sg(e)?_g(e,t):xg(e).get(t.symbolId)??[];return typeof n.limit=="number"?r.slice(0,n.limit):r}var yg=Ae("caller-rows"),bg=2e4;function Sg(e){return(e.get("SELECT COUNT(*) AS count FROM global_symbols")?.count??0)>bg}function xg(e){return yg.get(e,()=>{let t=oe(e),n=Sn(e,t),r=new Map;for(let o of t)r.set(o.symbol,o.symbolId);let i=new Map,s=new Map;for(let o of t){let a=n.get(o.symbolId);if(!(!a||a.length===0))for(let l of a){let c=r.get(l.symbol);if(c===void 0||c===o.symbolId)continue;let u=i.get(c);u||(u=[],i.set(c,u),s.set(c,new Set));let d=`${o.symbol}|${o.relativePath}`;s.get(c).has(d)||(s.get(c).add(d),u.push({symbol:o.symbol,file:o.relativePath}))}}return i})}function _g(e,t){let n=[],r=new Set,i=o=>{if(o.symbol===t.symbol)return;let a=`${o.symbol}|${o.file}`;r.has(a)||(r.add(a),n.push(o))};for(let o of Ie(e,t))o.file!==t.relativePath&&i({symbol:o.enclosingSymbol??o.file,file:o.file});let s=Ig(e,t);if(s)for(let o of Nt(e,s)){if(o.file===t.relativePath||e.isIgnored(o.file))continue;let a=ae(Q(e,o.file),o.line);i({symbol:a?.symbol??o.file,file:o.file})}return n}function Ig(e,t){return e.get(`SELECT
465
465
  d.id AS documentId,
466
466
  gs.id AS symbolId,
467
467
  gs.symbol,
@@ -480,14 +480,14 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
480
480
  LEFT JOIN chunks c ON c.document_id = der.document_id
481
481
  JOIN documents d ON d.id = COALESCE(der.document_id, c.document_id)
482
482
  WHERE gs.id = ?
483
- LIMIT 1`,t.symbolId)??null}function _e(e,t){let n=cg(e,t);return n?ug(e,sg(e,n.match,n.identifier)):[]}function sg(e,t,n){let r=new Map;for(let[i,s]of og(e,t.symbolId))r.set(i,ag(e,i,s,t,n));return r}function og(e,t){let n=new Map,r=e.all(`SELECT DISTINCT d.relative_path, c.start_line, c.end_line
483
+ LIMIT 1`,t.symbolId)??null}function Ie(e,t){let n=Eg(e,t);return n?Dg(e,Rg(e,n.match,n.identifier)):[]}function Rg(e,t,n){let r=new Map;for(let[i,s]of Cg(e,t.symbolId))r.set(i,vg(e,i,s,t,n));return r}function Cg(e,t){let n=new Map,r=e.all(`SELECT DISTINCT d.relative_path, c.start_line, c.end_line
484
484
  FROM mentions m
485
485
  JOIN chunks c ON m.chunk_id = c.id
486
486
  JOIN documents d ON c.document_id = d.id
487
487
  WHERE m.symbol_id = ?
488
488
  AND m.role != 1
489
489
  ${e.pathExclusionsFor("d")}
490
- ORDER BY d.relative_path, c.start_line`,t);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=n.get(i.relative_path);s||(s=[],n.set(i.relative_path,s)),s.push({start_line:i.start_line,end_line:i.end_line})}return n}function ag(e,t,n,r,i){let s=t===r.relativePath?{excludeStartLine:r.startLine,excludeEndLine:r.endLine}:{},o=i?cn(e,t,i,s):[];return n.flatMap(a=>lg(o,a))}function lg(e,t){let n=e.filter(r=>r>=t.start_line&&r<=t.end_line);return n.length>0?n:[t.start_line]}function cg(e,t){let n=on(e,t);return n?{match:n,identifier:k(n.symbol)||null}:null}function ug(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=ee(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function Sn(e,t,n={}){if(t.length===0)return new Map;let r=n.additive??!1,i=[],s=[];for(let c of t)M(c.relativePath)&&tn(e,c.relativePath)!==null?i.push(c):s.push(c);let o=new Map,a=c=>{for(let[d,u]of c){let m=o.get(d);m||(m=[],o.set(d,m));let f=new Set(m.map(p=>`${p.symbol}|${p.chunkId}`));for(let p of u){let g=`${p.symbol}|${p.chunkId}`;f.has(g)||(f.add(g),m.push(p))}}};i.length>0&&a(dg(e,i)),a(vg(Zs(e,t)));let l=r?t:s;return l.length>0&&a(yg(e,l)),o}function dg(e,t){let n=new Map,r=mg(t,n),i=Et(e);for(let[s,o]of r){let a=tn(e,s);if(a)for(let l of a){let c=pg(o,l.line);if(!c)continue;let d=fg(e,s,i,l.calleeLeaf,l.memberAccess);d&&d.symbol!==c.symbol&&n.get(c.symbolId).push({symbol:d.symbol,file:d.file,chunkId:l.line})}}return n}function mg(e,t){let n=new Map;for(let r of e){let i=n.get(r.relativePath);i?i.push(r):n.set(r.relativePath,[r]),t.set(r.symbolId,[])}for(let r of n.values())r.sort((i,s)=>i.endLine-i.startLine-(s.endLine-s.startLine));return n}function pg(e,t){return e.find(n=>t>=n.startLine&&t<=n.endLine)??null}function fg(e,t,n,r,i){let s=no(t,n.get(r)??[]);return s.length===0?null:ro(e,t,s,i)}function no(e,t){let n=to(e);return n?t.filter(r=>to(r.file)===n):t}function ro(e,t,n,r){let i=n.find(s=>s.file===t);if(i)return i;if(r){let s=new Set(J(e,t).map(o=>o.sourcePath).filter(o=>!!o));return n.find(o=>[...s].some(a=>gg(a,o.file)))??null}return n.length===1?n[0]:null}function gg(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function to(e){let t=M(e);return t?t==="typescript"||t==="tsx"||t==="javascript"?"javascript-family":t:null}var hg=$e("global-leaf-index");function Et(e){return hg.get(e,()=>{let t=e.all(`SELECT gs.id, gs.symbol,
490
+ ORDER BY d.relative_path, c.start_line`,t);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=n.get(i.relative_path);s||(s=[],n.set(i.relative_path,s)),s.push({start_line:i.start_line,end_line:i.end_line})}return n}function vg(e,t,n,r,i){let s=t===r.relativePath?{excludeStartLine:r.startLine,excludeEndLine:r.endLine}:{},o=i?cn(e,t,i,s):[];return n.flatMap(a=>Ng(o,a))}function Ng(e,t){let n=e.filter(r=>r>=t.start_line&&r<=t.end_line);return n.length>0?n:[t.start_line]}function Eg(e,t){let n=on(e,t);return n?{match:n,identifier:D(n.symbol)||null}:null}function Dg(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=Q(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function Sn(e,t,n={}){if(t.length===0)return new Map;let r=n.additive??!1,i=[],s=[];for(let u of t)M(u.relativePath)&&tn(e,u.relativePath)!==null?i.push(u):s.push(u);let o=new Map,a=new Map,l=u=>{for(let[d,m]of u){let g=o.get(d);g||(g=[],o.set(d,g));let p=a.get(d);p||(p=new Set,a.set(d,p));for(let f of m){let y=`${f.symbol}|${f.chunkId}`;p.has(y)||(p.add(y),g.push(f))}}};i.length>0&&l(Lg(e,i)),l(Vg(so(e,t)));let c=r?t:s;return c.length>0&&l(Fg(e,c)),o}function Lg(e,t){let n=new Map,r=kg(t,n),i=Et(e);for(let[s,o]of r){let a=tn(e,s);if(a)for(let l of a){let c=wg(o,l.line);if(!c)continue;let u=Pg(e,s,i,l.calleeLeaf,l.memberAccess);u&&u.symbol!==c.symbol&&n.get(c.symbolId).push({symbol:u.symbol,file:u.file,chunkId:l.line})}}return n}function kg(e,t){let n=new Map;for(let r of e){let i=n.get(r.relativePath);i?i.push(r):n.set(r.relativePath,[r]),t.set(r.symbolId,[])}for(let r of n.values())r.sort((i,s)=>i.endLine-i.startLine-(s.endLine-s.startLine));return n}function wg(e,t){return e.find(n=>t>=n.startLine&&t<=n.endLine)??null}function Pg(e,t,n,r,i){let s=lo(t,n.get(r)??[]);return s.length===0?null:co(e,t,s,i)}function lo(e,t){let n=ao(e);return n?t.filter(r=>ao(r.file)===n):t}function co(e,t,n,r){let i=n.find(s=>s.file===t);if(i)return i;if(r){let s=new Set(J(e,t).map(o=>o.sourcePath).filter(o=>!!o));for(let o of n)for(let a of s)if(Og(a,o.file))return o;return null}return n.length===1?n[0]:null}function Og(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function ao(e){let t=M(e);return t?t==="typescript"||t==="tsx"||t==="javascript"?"javascript-family":t:null}var Mg=Ae("global-leaf-index");function Et(e){return Mg.get(e,()=>{let t=e.all(`SELECT gs.id, gs.symbol,
491
491
  COALESCE(der_doc.relative_path, mention_doc.relative_path) AS relative_path
492
492
  FROM global_symbols gs
493
493
  LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
@@ -501,7 +501,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
501
501
  GROUP BY m.symbol_id
502
502
  ) mention_doc ON mention_doc.symbol_id = gs.id
503
503
  WHERE 1 = 1
504
- ${e.symbolNoiseFor("gs")}`),n=new Map;for(let r of t){if(!r.relative_path||e.isIgnored(r.relative_path))continue;let i=k(r.symbol);if(!i)continue;let s=n.get(i);s||(s=[],n.set(i,s)),s.some(o=>o.symbolId===r.id)||s.push({symbol:r.symbol,symbolId:r.id,file:r.relative_path})}return n})}function yg(e,t){if(t.length===0)return new Map;let n=e.all(`SELECT c.document_id, c.id AS chunk_id, c.start_line, c.end_line, m.symbol_id
504
+ ${e.symbolNoiseFor("gs")}`),n=new Map;for(let r of t){if(!r.relative_path||e.isIgnored(r.relative_path))continue;let i=D(r.symbol);if(!i)continue;let s=n.get(i);s||(s=[],n.set(i,s)),s.some(o=>o.symbolId===r.id)||s.push({symbol:r.symbol,symbolId:r.id,file:r.relative_path})}return n})}function Fg(e,t){if(t.length===0)return new Map;let n=e.all(`SELECT c.document_id, c.id AS chunk_id, c.start_line, c.end_line, m.symbol_id
505
505
  FROM mentions m
506
506
  JOIN chunks c ON m.chunk_id = c.id
507
507
  WHERE m.role != 1`),r=new Map;for(let c of n)r.has(c.document_id)||r.set(c.document_id,[]),r.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])),s=new Map,o=e.all(`SELECT gs.id AS symbol_id, gs.symbol,
@@ -514,21 +514,21 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
514
514
  JOIN chunks c ON m.chunk_id = c.id
515
515
  WHERE m.role = 1
516
516
  GROUP BY m.symbol_id
517
- ) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of o)s.has(c.symbol_id)||s.set(c.symbol_id,{symbol:c.symbol,file:c.document_id!==null?i.get(c.document_id)??"":""});let a=new Map,l=i;for(let c of t){let d=r.get(c.documentId)??[],u=new Set,m=[],f=null,p=()=>{if(f)return f;let g=l.get(c.documentId)??"",y=new Set;if(g){let E=Ss(e,g),N=Math.max(0,c.startLine),F=Math.min(E.length-1,c.endLine);for(let T=N;T<=F;T+=1)for(let R of E[T])y.add(R)}return f=y,y};for(let g of d){if(g.symbol_id===c.symbolId)continue;let y=s.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 T=k(y.symbol);if(!T||!p().has(T))continue}let N=`${y.symbol}|${g.chunk_id}`;u.has(N)||(u.add(N),m.push({...y,chunkId:g.chunk_id}))}a.set(c.symbolId,m)}return a}function io(e,t){let n=new Map,r=e.all(`SELECT relative_path FROM documents
518
- WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=Et(e),s=t??oe(e);return bg(e,n,r,i),Sg(e,n,s),Rg(e,n,r,i),Ng(n,dt(e,Cg(s))),n}function bg(e,t,n,r){for(let i of n){if(!M(i.relative_path)||e.isIgnored(i.relative_path))continue;let s=tn(e,i.relative_path);if(s)for(let o of s){let a=no(i.relative_path,r.get(o.calleeLeaf)??[]);if(!a||a.length===0)continue;let l=ro(e,i.relative_path,a,o.memberAccess);l&&l.file!==i.relative_path&&Dr(t,l.symbolId,i.relative_path)}}}function Sg(e,t,n){let r=_g(n);for(let i of xg(e))e.isIgnored(i.relative_path)||Ig(i,r.get(i.symbol_id))||Dr(t,i.symbol_id,i.relative_path)}function xg(e){return e.all(`SELECT DISTINCT m.symbol_id, d.relative_path, c.document_id,
517
+ ) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of o)s.has(c.symbol_id)||s.set(c.symbol_id,{symbol:c.symbol,file:c.document_id!==null?i.get(c.document_id)??"":""});let a=new Map,l=i;for(let c of t){let u=r.get(c.documentId)??[],d=new Set,m=[],g=null,p=()=>{if(g)return g;let f=l.get(c.documentId)??"",y=new Set;if(f){let L=xs(e,f),k=Math.max(0,c.startLine),F=Math.min(L.length-1,c.endLine);for(let T=k;T<=F;T+=1)for(let R of L[T])y.add(R)}return g=y,y};for(let f of u){if(f.symbol_id===c.symbolId)continue;let y=s.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 T=D(y.symbol);if(!T||!p().has(T))continue}let k=`${y.symbol}|${f.chunk_id}`;d.has(k)||(d.add(k),m.push({...y,chunkId:f.chunk_id}))}a.set(c.symbolId,m)}return a}function uo(e,t){let n=new Map,r=e.all(`SELECT relative_path FROM documents
518
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=Et(e),s=t??oe(e);return Tg(e,n,r,i),$g(e,n,s),Wg(e,n,r,i),Ug(n,ut(e,Hg(s))),n}function Tg(e,t,n,r){for(let i of n){if(!M(i.relative_path)||e.isIgnored(i.relative_path))continue;let s=tn(e,i.relative_path);if(s)for(let o of s){let a=lo(i.relative_path,r.get(o.calleeLeaf)??[]);if(!a||a.length===0)continue;let l=co(e,i.relative_path,a,o.memberAccess);l&&l.file!==i.relative_path&&Er(t,l.symbolId,i.relative_path)}}}function $g(e,t,n){let r=jg(n);for(let i of Ag(e))e.isIgnored(i.relative_path)||Bg(i,r.get(i.symbol_id))||Er(t,i.symbol_id,i.relative_path)}function Ag(e){return e.all(`SELECT DISTINCT m.symbol_id, d.relative_path, c.document_id,
519
519
  c.start_line AS chunk_start, c.end_line AS chunk_end
520
520
  FROM mentions m
521
521
  JOIN chunks c ON m.chunk_id = c.id
522
522
  JOIN documents d ON c.document_id = d.id
523
523
  WHERE m.role != 1
524
- ${e.pathExclusionsFor("d")}`)}function _g(e){let t=new Map;for(let n of e)t.set(n.symbolId,{docId:n.documentId,startLine:n.startLine,endLine:n.endLine});return t}function Ig(e,t){return!!t&&t.docId===e.document_id&&e.chunk_start>=t.startLine&&e.chunk_end<=t.endLine}function Rg(e,t,n,r){for(let i of n){if(e.isIgnored(i.relative_path)||M(i.relative_path)!=="rust")continue;let s=st(e,i.relative_path);if(s.size!==0)for(let o of s){let a=r.get(o);if(a)for(let l of a)l.file!==i.relative_path&&Dr(t,l.symbolId,i.relative_path)}}}function Dr(e,t,n){let r=e.get(t);r||(r=new Set,e.set(t,r)),r.add(n)}function Cg(e){return e.filter(t=>"relativePath"in t&&"symbol"in t&&"leaf"in t)}function vg(e){let t=new Map;for(let[n,r]of e)t.set(n,r.map(i=>({...i,chunkId:-1})));return t}function Ng(e,t){for(let[n,r]of t){let i=e.get(n);i||(i=new Set,e.set(n,i));for(let s of r)i.add(s)}}function Z(e){let t=Dt(e);return Dg(t)?"test":Lg(t)?"worker":kg(t)?"entry":wg(t)?"barrel":"source"}function xn(e){return Z(e)==="barrel"}function oo(e){return Eg.get(e,()=>{let t=Q(e),n=Ne(e).filter(s=>{let o=Z(s);return o==="entry"||o==="worker"}),r=new Set,i=new Set;for(;n.length>0;){let s=n.shift();if(!r.has(s)){r.add(s),Z(s)==="barrel"&&i.add(s);for(let o of t.get(s)??[])r.has(o)||n.push(o)}}return i})}var Eg=$e("live-barrels");function Lr(e,t){return oo(e).has(Dt(t))}function ao(e){let t=oo(e);return Ne(e).filter(n=>xn(n)&&!t.has(n))}function ze(e,t){let n=Z(t);return n==="entry"||n==="worker"||Lr(e,t)}function Lt(e,t,n){let r=e.config.entryRoots;if(!r)return!1;let i=Dt(n);return!!(r.files?.some(s=>Dt(s)===i)||r.pathPrefixes?.some(s=>i.startsWith(Dt(s)))||r.qualifiedVars?.some(s=>Pg(t,s))||r.symbolPatterns?.some(s=>{try{return new RegExp(s).test(t)}catch{return!1}}))}var lo=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],co=["%/test-utils/%"];function Dg(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 Lg(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function kg(e){let t=e.split("/"),n=t[t.length-1]??e;return n==="cli.ts"||n==="cli.js"||n==="postinstall.ts"||n==="postinstall.js"||n==="main.ts"||n==="main.js"||n==="main.rs"||n==="main.go"||n==="main.py"||n==="build.rs"||n==="lib.rs"||/\bsrc\/bin\/[^/]+\.rs$/.test(e)||/(?:^|\/)examples\/[^/]+\.rs$/.test(e)||/(?:^|\/)tests\/[^/]+\.rs$/.test(e)||/(?:^|\/)benches\/[^/]+\.rs$/.test(e)?!0:n==="index.ts"||n==="index.js"?/(?:^|\/)(?:apps|services)\/[^/]+\/src\/index\.(?:ts|js)$/.test(e)?!0:t.length<=2:!1}function wg(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 Dt(e){return e.replace(/\\/g,"/")}function Pg(e,t){let n=t.lastIndexOf("/");if(n<0)return!1;let r=t.slice(0,n),i=t.slice(n+1);return e.includes(so(r)+"/")&&e.includes(so(i)+".")}function so(e){return/^[A-Za-z0-9_$+-]+$/.test(e)?e:"`"+e.replace(/`/g,"``")+"`"}function mt(e,t,n){let r=Et(e).get(n);if(!r||r.length===0)return[];if(r.length===1)return[kt(r[0])];let i=r.filter(l=>l.file===t);if(i.length>0)return i.map(kt);let s=Og(e,t),o=s.get(n);if(o)for(let l of o){let c=r.filter(d=>uo(l,d.file));if(c.length>0)return c.map(kt)}let a=new Set;for(let l of s.values())for(let c of l)a.add(c);for(let l of a){let c=r.filter(d=>uo(l,d.file));if(c.length>0&&c.length===r.length)return c.map(kt)}return[]}function po(e,t,n){let r=mt(e,t,n);if(r.length>0)return r;let i=Et(e).get(n);return!i||i.length===0?[]:i.map(kt)}function Fe(e,t){let n=on(e,t);if(!n)return[];let r=k(n.symbol);if(!r)return[];let i=Nt(e,{...n,leaf:r,parentTypeName:null,isFunctionLike:!1,isTypeLike:!1,kind:null,documentation:null,enclosingSymbol:null});if(i.length>0){let o=new Map;for(let a of i){let l=o.get(a.file)??[];l.push(a.line),o.set(a.file,l)}return mo(e,o)}let s=new Map;for(let o of Ne(e)){let a=O(e,o);if(!a||a.indexOf(r)===-1||o!==n.relativePath&&!mt(e,o,r).some(d=>d.symbolId===n.symbolId))continue;let l=cn(e,o,r,o===n.relativePath?{excludeStartLine:n.startLine,excludeEndLine:n.endLine}:{});l.length>0&&s.set(o,l)}return mo(e,s)}function fo(e,t){let n=new Map;for(let s of t){if(!s.leaf)continue;let o=n.get(s.leaf)??[];o.push(s),n.set(s.leaf,o)}if(n.size===0)return new Map;let r=new Set(t.map(s=>s.symbolId)),i=new Map;for(let s of Ne(e)){let o=bs(e,s);if(o.size!==0){for(let a of o)if(n.has(a))for(let l of mt(e,s,a)){if(!r.has(l.symbolId)||s===l.relativePath)continue;let c=i.get(l.symbolId);c||(c=new Set,i.set(l.symbolId,c)),c.add(s)}}}return i}function Og(e,t){let n=new Map;for(let r of J(e,t)){if(!r.sourcePath)continue;let i=r.localName??r.importedName;if(i){let s=n.get(i);s||(s=new Set,n.set(i,s)),s.add(r.sourcePath)}if(r.kind==="namespace")for(let s of r.usedMembers){let o=n.get(s);o||(o=new Set,n.set(s,o)),o.add(r.sourcePath)}}return n}function uo(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function kt(e){return{symbolId:e.symbolId,symbol:e.symbol,relativePath:e.file}}function mo(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=ee(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function go(e,t,n){let r=t.identifierResolution==="strict"?mt:po;for(let i of t.paths){let s=M(i);if(!s&&!(t.includeVueSfc&&bt(i))||e.isIgnored(i)||t.skipPath?.(i))continue;let o=Je(e,i);for(let[a,l]of o)for(let c of r(e,i,a))n({sourceFile:i,name:a,target:c,occurrences:l.length,kind:"identifier"});if(t.includeCrossLanguageDispatchNames)for(let a of fs(e,i))for(let l of mt(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"cross-language-dispatch"});if(t.includeRustAttributeNames&&s==="rust")for(let a of st(e,i))for(let l of r(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"rust-attribute"})}}var C=class{constructor(t){this.db=t}db;scopedDefinitions(t){return cr(this.db,t)}definitionsForFile(t){return ee(this.db,t)}productionCallableDefinitions(t={}){let{scope:n,minLoc:r=1,maxLoc:i=Number.POSITIVE_INFINITY,excludeSymbol:s,excludeEntrySurfaces:o=!1,excludeTypesFiles:a=!1,requireFunctionLikeSymbol:l=!1,requireCallableSymbol:c=!1,excludeRustTraitImplMembers:d=!1,includeSuppressed:u=!1,sortByLocDesc:m=!1}=t,f=this.scopedDefinitions(n).filter(p=>!this.db.isIgnored(p.relativePath)).filter(p=>!o||!ze(this.db,p.relativePath)).filter(p=>Mg(p,{requireFunctionLikeSymbol:l,requireCallableSymbol:c})).filter(p=>s===void 0||p.symbol!==s).filter(p=>_n(p)>=r&&_n(p)<=i).filter(p=>!a||!Fg(p.relativePath)).filter(p=>!d||!rn(p.symbol)).filter(p=>Z(p.relativePath)!=="test").filter(p=>!Le(p.symbol)).filter(p=>u||!ar(this.db,p.relativePath,p.startLine));return m?[...f].sort((p,g)=>_n(g)-_n(p)):f}calleeMap(t,n={}){return Sn(this.db,t,n)}crossFileCallerMap(t){return io(this.db,t)}sourceFallbackCallerFiles(t){return fo(this.db,t)}fileDependencyGraph(t){return Q(this.db,t)}fileKind(t){return Z(t)}hasSuppressionComment(t){return ar(this.db,t.relativePath,t.startLine)}sourceFiles(){return Ne(this.db)}scanSourceReferences(t,n){go(this.db,t,n)}callableSignature(t){return Yi(this.db,t.relativePath,t.startLine,t.endLine)}};function _n(e){return e.endLine-e.startLine+1}function Mg(e,t){return t.requireCallableSymbol?U(e.symbol):t.requireFunctionLikeSymbol?W(e.symbol):e.isFunctionLike}function Fg(e){return(e.split("/").pop()??"").includes("types")}function ho(e,t){let n=L(e,t);if(!n)return[];let r=k(n.symbol),s=new C(e).definitionsForFile(n.relativePath).filter(l=>U(l.symbol)),o=s.filter(l=>l.parentTypeName===r||l.symbol.includes(r));return(o.length>0?o:$g(Tg(n.relativePath))===r?s.filter(l=>l.symbol.includes("<invalid-global-code>")):[]).map(l=>({startLine:l.startLine,endLine:l.endLine,name:k(l.symbol)}))}function $g(e){return e.replace(/\.[^.]+$/,"")}function yo(e,t){let n=L(e,t);if(!n)return[];let i=!W(n.symbol)&&!e.isIgnored(n.relativePath)?[{relativePath:n.relativePath,line:n.startLine}]:[],s=Fe(e,n),o=(s.length>0?s:_e(e,n)).filter(d=>!e.isIgnored(d.file)).map(d=>({relativePath:d.file,line:d.line})),a=Ag(e,n),l=new Set,c=[];for(let d of[...i,...o,...a]){let u=`${d.relativePath}:${d.line}`;l.has(u)||(l.add(u),c.push(d))}return c}function Ag(e,t){if(!t.relativePath.endsWith(".rb"))return[];let n=jg(t.symbol);if(n.length===0)return[];let r=e.all(`SELECT relative_path
524
+ ${e.pathExclusionsFor("d")}`)}function jg(e){let t=new Map;for(let n of e)t.set(n.symbolId,{docId:n.documentId,startLine:n.startLine,endLine:n.endLine});return t}function Bg(e,t){return!!t&&t.docId===e.document_id&&e.chunk_start>=t.startLine&&e.chunk_end<=t.endLine}function Wg(e,t,n,r){for(let i of n){if(e.isIgnored(i.relative_path)||M(i.relative_path)!=="rust")continue;let s=st(e,i.relative_path);if(s.size!==0)for(let o of s){let a=r.get(o);if(a)for(let l of a)l.file!==i.relative_path&&Er(t,l.symbolId,i.relative_path)}}}function Er(e,t,n){let r=e.get(t);r||(r=new Set,e.set(t,r)),r.add(n)}function Hg(e){return e.filter(t=>"relativePath"in t&&"symbol"in t&&"leaf"in t)}function Vg(e){let t=new Map;for(let[n,r]of e){let i=[];for(let s of r)i.push({symbol:s.symbol,file:s.file,chunkId:-1});t.set(n,i)}return t}function Ug(e,t){for(let[n,r]of t){let i=e.get(n);i||(i=new Set,e.set(n,i));for(let s of r)i.add(s)}}function ee(e){let t=Dt(e);return qg(t)?"test":zg(t)?"worker":Gg(t)?"entry":Kg(t)?"barrel":"source"}function xn(e){return ee(e)==="barrel"}function po(e){return Jg.get(e,()=>{let t=Y(e),n=Ee(e).filter(s=>{let o=ee(s);return o==="entry"||o==="worker"}),r=new Set,i=new Set;for(;n.length>0;){let s=n.shift();if(!r.has(s)){r.add(s),ee(s)==="barrel"&&i.add(s);for(let o of t.get(s)??[])r.has(o)||n.push(o)}}return i})}var Jg=Ae("live-barrels");function Dr(e,t){return po(e).has(Dt(t))}function fo(e){let t=po(e);return Ee(e).filter(n=>xn(n)&&!t.has(n))}function ze(e,t){let n=ee(t);return n==="entry"||n==="worker"||Dr(e,t)}function Lt(e,t,n){let r=e.config.entryRoots;if(!r)return!1;let i=Dt(n);return!!(r.files?.some(s=>Dt(s)===i)||r.pathPrefixes?.some(s=>i.startsWith(Dt(s)))||r.qualifiedVars?.some(s=>Yg(t,s))||r.symbolPatterns?.some(s=>{try{return new RegExp(s).test(t)}catch{return!1}}))}var go=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],ho=["%/test-utils/%"];function qg(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 zg(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function Gg(e){let t=e.split("/"),n=t[t.length-1]??e;return n==="cli.ts"||n==="cli.js"||n==="postinstall.ts"||n==="postinstall.js"||n==="main.ts"||n==="main.js"||n==="main.rs"||n==="main.go"||n==="main.py"||n==="build.rs"||n==="lib.rs"||/\bsrc\/bin\/[^/]+\.rs$/.test(e)||/(?:^|\/)examples\/[^/]+\.rs$/.test(e)||/(?:^|\/)tests\/[^/]+\.rs$/.test(e)||/(?:^|\/)benches\/[^/]+\.rs$/.test(e)?!0:n==="index.ts"||n==="index.js"?/(?:^|\/)(?:apps|services)\/[^/]+\/src\/index\.(?:ts|js)$/.test(e)?!0:t.length<=2:!1}function Kg(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 Dt(e){return e.replace(/\\/g,"/")}function Yg(e,t){let n=t.lastIndexOf("/");if(n<0)return!1;let r=t.slice(0,n),i=t.slice(n+1);return e.includes(mo(r)+"/")&&e.includes(mo(i)+".")}function mo(e){return/^[A-Za-z0-9_$+-]+$/.test(e)?e:"`"+e.replace(/`/g,"``")+"`"}function dt(e,t,n){let r=Et(e).get(n);if(!r||r.length===0)return[];if(r.length===1)return[kt(r[0])];let i=r.filter(l=>l.file===t);if(i.length>0)return i.map(kt);let s=Qg(e,t),o=s.get(n);if(o)for(let l of o){let c=r.filter(u=>yo(l,u.file));if(c.length>0)return c.map(kt)}let a=new Set;for(let l of s.values())for(let c of l)a.add(c);for(let l of a){let c=r.filter(u=>yo(l,u.file));if(c.length>0&&c.length===r.length)return c.map(kt)}return[]}function So(e,t,n){let r=dt(e,t,n);if(r.length>0)return r;let i=Et(e).get(n);return!i||i.length===0?[]:i.map(kt)}function Te(e,t){let n=on(e,t);if(!n)return[];let r=D(n.symbol);if(!r)return[];let i=Nt(e,{...n,leaf:r,parentTypeName:null,isFunctionLike:!1,isTypeLike:!1,kind:null,documentation:null,enclosingSymbol:null});if(i.length>0){let o=new Map;for(let a of i){let l=o.get(a.file)??[];l.push(a.line),o.set(a.file,l)}return bo(e,o)}let s=new Map;for(let o of Ee(e)){let a=w(e,o);if(!a||a.indexOf(r)===-1||o!==n.relativePath&&!dt(e,o,r).some(u=>u.symbolId===n.symbolId))continue;let l=cn(e,o,r,o===n.relativePath?{excludeStartLine:n.startLine,excludeEndLine:n.endLine}:{});l.length>0&&s.set(o,l)}return bo(e,s)}function xo(e,t){let n=new Map;for(let s of t){if(!s.leaf)continue;let o=n.get(s.leaf)??[];o.push(s),n.set(s.leaf,o)}if(n.size===0)return new Map;let r=new Set(t.map(s=>s.symbolId)),i=new Map;for(let s of Ee(e)){let o=Ss(e,s);if(o.size!==0){for(let a of o)if(n.has(a))for(let l of dt(e,s,a)){if(!r.has(l.symbolId)||s===l.relativePath)continue;let c=i.get(l.symbolId);c||(c=new Set,i.set(l.symbolId,c)),c.add(s)}}}return i}function Qg(e,t){let n=new Map;for(let r of J(e,t)){if(!r.sourcePath)continue;let i=r.localName??r.importedName;if(i){let s=n.get(i);s||(s=new Set,n.set(i,s)),s.add(r.sourcePath)}if(r.kind==="namespace")for(let s of r.usedMembers){let o=n.get(s);o||(o=new Set,n.set(s,o)),o.add(r.sourcePath)}}return n}function yo(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function kt(e){return{symbolId:e.symbolId,symbol:e.symbol,relativePath:e.file}}function bo(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=Q(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function _o(e,t,n){let r=t.identifierResolution==="strict"?dt:So;for(let i of t.paths){let s=M(i);if(!s&&!(t.includeVueSfc&&yt(i))||e.isIgnored(i)||t.skipPath?.(i))continue;let o=qe(e,i);for(let[a,l]of o)for(let c of r(e,i,a))n({sourceFile:i,name:a,target:c,occurrences:l.length,kind:"identifier"});if(t.includeCrossLanguageDispatchNames)for(let a of gs(e,i))for(let l of dt(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"cross-language-dispatch"});if(t.includeRustAttributeNames&&s==="rust")for(let a of st(e,i))for(let l of r(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"rust-attribute"})}}var C=class{constructor(t){this.db=t}db;scopedDefinitions(t){return lr(this.db,t)}definitionsForFile(t){return Q(this.db,t)}productionCallableDefinitions(t={}){let{scope:n,minLoc:r=1,maxLoc:i=Number.POSITIVE_INFINITY,excludeSymbol:s,excludeEntrySurfaces:o=!1,excludeTypesFiles:a=!1,requireFunctionLikeSymbol:l=!1,requireCallableSymbol:c=!1,excludeRustTraitImplMembers:u=!1,includeSuppressed:d=!1,sortByLocDesc:m=!1}=t,g=[];for(let p of this.scopedDefinitions(n)){let f=p.relativePath;if(this.db.isIgnored(f)||o&&ze(this.db,f)||!Xg(p,{requireFunctionLikeSymbol:l,requireCallableSymbol:c})||s!==void 0&&p.symbol===s)continue;let y=Lr(p);y<r||y>i||a&&Zg(f)||u&&rn(p.symbol)||ee(f)!=="test"&&(ke(p.symbol)||!d&&or(this.db,f,p.startLine)||g.push(p))}return m?g.sort((p,f)=>Lr(f)-Lr(p)):g}calleeMap(t,n={}){return Sn(this.db,t,n)}crossFileCallerMap(t){return uo(this.db,t)}sourceFallbackCallerFiles(t){return xo(this.db,t)}fileDependencyGraph(t){return Y(this.db,t)}fileKind(t){return ee(t)}hasSuppressionComment(t){return or(this.db,t.relativePath,t.startLine)}sourceFiles(){return Ee(this.db)}scanSourceReferences(t,n){_o(this.db,t,n)}callableSignature(t){return Xi(this.db,t.relativePath,t.startLine,t.endLine)}};function Lr(e){return e.endLine-e.startLine+1}function Xg(e,t){return t.requireCallableSymbol?U(e.symbol):t.requireFunctionLikeSymbol?W(e.symbol):e.isFunctionLike}function Zg(e){return(e.split("/").pop()??"").includes("types")}function Io(e,t){let n=E(e,t);if(!n)return[];let r=D(n.symbol),s=new C(e).definitionsForFile(n.relativePath).filter(l=>U(l.symbol)),o=s.filter(l=>l.parentTypeName===r||l.symbol.includes(r));return(o.length>0?o:th(eh(n.relativePath))===r?s.filter(l=>l.symbol.includes("<invalid-global-code>")):[]).map(l=>({startLine:l.startLine,endLine:l.endLine,name:D(l.symbol)}))}function th(e){return e.replace(/\.[^.]+$/,"")}function Ro(e,t){let n=E(e,t);if(!n)return[];let i=!W(n.symbol)&&!e.isIgnored(n.relativePath)?[{relativePath:n.relativePath,line:n.startLine}]:[],s=Te(e,n),o=(s.length>0?s:Ie(e,n)).filter(u=>!e.isIgnored(u.file)).map(u=>({relativePath:u.file,line:u.line})),a=nh(e,n),l=new Set,c=[];for(let u of[...i,...o,...a]){let d=`${u.relativePath}:${u.line}`;l.has(d)||(l.add(d),c.push(u))}return c}function nh(e,t){if(!t.relativePath.endsWith(".rb"))return[];let n=rh(t.symbol);if(n.length===0)return[];let r=e.all(`SELECT relative_path
525
525
  FROM documents
526
526
  WHERE relative_path LIKE '%.rb'
527
527
  ${e.pathExclusionsFor("documents")}
528
- ORDER BY relative_path`),i=[];for(let s of r){if(e.isIgnored(s.relative_path))continue;let o=O(e,s.relative_path);if(!o)continue;let a=o.split(`
529
- `);for(let l=0;l<a.length;l++){let c=a[l]??"";n.some(d=>new RegExp(`@${d}\\b|\\b${d}:`).test(c))&&i.push({relativePath:s.relative_path,line:l})}}return i}function jg(e){let n=(e.split(":").pop()??e).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9_]+/g,"_").toLowerCase().replace(/^_+|_+$/g,""),r=n.split("_").filter(Boolean),i=new Set;return n&&i.add(n),r.length>=1&&i.add(r[r.length-1]),r.length>=2&&i.add(r.slice(-2).join("_")),[...i]}function bo(e,t){let n=L(e,t);if(!n)return{definitions:[],referencedBy:[]};let r=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",n.symbolId),i=He(r?.documentation??null),s=e.isIgnored(n.relativePath)?[]:[{relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,signature:Wg(i,r?.display_name??null,n.symbol),source:Bg(e,n.relativePath,n.startLine,n.endLine)}],o=Fe(e,n),l=(o.length>0?o:_e(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({relativePath:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol,enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"}));return{definitions:s,referencedBy:l}}function Bg(e,t,n,r){let i=O(e,t);if(!i)return null;let o=i.split(`
528
+ ORDER BY relative_path`),i=[];for(let s of r){if(e.isIgnored(s.relative_path))continue;let o=w(e,s.relative_path);if(!o)continue;let a=o.split(`
529
+ `);for(let l=0;l<a.length;l++){let c=a[l]??"";n.some(u=>new RegExp(`@${u}\\b|\\b${u}:`).test(c))&&i.push({relativePath:s.relative_path,line:l})}}return i}function rh(e){let n=(e.split(":").pop()??e).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9_]+/g,"_").toLowerCase().replace(/^_+|_+$/g,""),r=n.split("_").filter(Boolean),i=new Set;return n&&i.add(n),r.length>=1&&i.add(r[r.length-1]),r.length>=2&&i.add(r.slice(-2).join("_")),[...i]}function Co(e,t){let n=E(e,t);if(!n)return{definitions:[],referencedBy:[]};let r=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",n.symbolId),i=Ve(r?.documentation??null),s=e.isIgnored(n.relativePath)?[]:[{relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,signature:sh(i,r?.display_name??null,n.symbol),source:ih(e,n.relativePath,n.startLine,n.endLine)}],o=Te(e,n),l=(o.length>0?o:Ie(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({relativePath:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol,enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"}));return{definitions:s,referencedBy:l}}function ih(e,t,n,r){let i=w(e,t);if(!i)return null;let o=i.split(`
530
530
  `).slice(n,r+1).join(`
531
- `).trimEnd();return o.length>0?o:null}function Wg(e,t,n){let r=We(e);if(r&&!Hg(r))return r;let i=(t??"").trim();return i?W(n)&&!i.endsWith("()")?`${i}()`:i:h(n)}function Hg(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function So(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d2.relative_path
531
+ `).trimEnd();return o.length>0?o:null}function sh(e,t,n){let r=He(e);if(r&&!oh(r))return r;let i=(t??"").trim();return i?W(n)&&!i.endsWith("()")?`${i}()`:i:h(n)}function oh(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function vo(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d2.relative_path
532
532
  FROM mentions m
533
533
  JOIN chunks c ON m.chunk_id = c.id
534
534
  JOIN documents d1 ON c.document_id = d1.id
@@ -544,7 +544,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
544
544
  WHERE d1.relative_path = ?
545
545
  AND d2.relative_path <> d1.relative_path
546
546
  AND ${e.localSymbolPredicate}
547
- ORDER BY d2.relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function xo(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d1.relative_path
547
+ ORDER BY d2.relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function No(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d1.relative_path
548
548
  FROM mentions m
549
549
  JOIN chunks c ON m.chunk_id = c.id
550
550
  JOIN documents d1 ON c.document_id = d1.id
@@ -559,9 +559,9 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
559
559
  JOIN documents d2 ON sym_def.document_id = d2.id
560
560
  WHERE d2.relative_path = ?
561
561
  AND d1.relative_path != ?
562
- ORDER BY d1.relative_path`,n,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function _o(e,t){let n=ke(e,t);if(n.length===0)return{files:[],symbols:[],dependsOn:[],dependedOnBy:[]};let r=n.map(()=>"?").join(", "),s=e.all(`SELECT relative_path FROM documents
562
+ ORDER BY d1.relative_path`,n,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function Eo(e,t){let n=we(e,t);if(n.length===0)return{files:[],symbols:[],dependsOn:[],dependedOnBy:[]};let r=n.map(()=>"?").join(", "),s=e.all(`SELECT relative_path FROM documents
563
563
  WHERE relative_path IN (${r})
564
- ORDER BY relative_path`,...n).map(u=>u.relative_path).filter(u=>!e.isIgnored(u)),o=nt(e,s,{onlyDocumented:!0,sort:!0}).map(({relativePath:u,...m})=>m),l=e.all(`SELECT DISTINCT d2.relative_path
564
+ ORDER BY relative_path`,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d)),o=nt(e,s,{onlyDocumented:!0,sort:!0}).map(({relativePath:d,...m})=>m),l=e.all(`SELECT DISTINCT d2.relative_path
565
565
  FROM mentions m
566
566
  JOIN chunks c ON m.chunk_id = c.id
567
567
  JOIN documents d1 ON c.document_id = d1.id
@@ -577,7 +577,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
577
577
  WHERE d1.relative_path IN (${r})
578
578
  AND d2.relative_path NOT IN (${r})
579
579
  AND ${e.localSymbolPredicate}
580
- ORDER BY d2.relative_path`,...n,...n).map(u=>u.relative_path).filter(u=>!e.isIgnored(u)),d=e.all(`SELECT DISTINCT d1.relative_path
580
+ ORDER BY d2.relative_path`,...n,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d)),u=e.all(`SELECT DISTINCT d1.relative_path
581
581
  FROM mentions m
582
582
  JOIN chunks c ON m.chunk_id = c.id
583
583
  JOIN documents d1 ON c.document_id = d1.id
@@ -592,7 +592,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
592
592
  JOIN documents d2 ON sym_def.document_id = d2.id
593
593
  WHERE d2.relative_path IN (${r})
594
594
  AND d1.relative_path NOT IN (${r})
595
- ORDER BY d1.relative_path`,...n,...n).map(u=>u.relative_path).filter(u=>!e.isIgnored(u));return{files:s,symbols:o,dependsOn:l,dependedOnBy:d}}function Io(e,t){let n=ke(e,t);return n.length===0?[]:Jg([...Vg(e,n),...Ug(e,n)]).filter(r=>!e.isIgnored(r.relative_path)).map(qg)}function Vg(e,t){let n=t.map(()=>"?").join(", ");return e.all(`SELECT DISTINCT d1.relative_path, gs.symbol
595
+ ORDER BY d1.relative_path`,...n,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d));return{files:s,symbols:o,dependsOn:l,dependedOnBy:u}}function Do(e,t){let n=we(e,t);return n.length===0?[]:ch([...ah(e,n),...lh(e,n)]).filter(r=>!e.isIgnored(r.relative_path)).map(uh)}function ah(e,t){let n=t.map(()=>"?").join(", ");return e.all(`SELECT DISTINCT d1.relative_path, gs.symbol
596
596
  FROM mentions m
597
597
  JOIN chunks c ON m.chunk_id = c.id
598
598
  JOIN documents d1 ON c.document_id = d1.id
@@ -619,7 +619,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
619
619
  AND m.role != 1
620
620
  AND ${e.localSymbolPredicate}
621
621
  ${e.pathExclusionsFor("d1")}
622
- ORDER BY d1.relative_path`,...t,...t,...t)}function Ug(e,t){let n=new C(e);return t.flatMap(r=>n.definitionsForFile(r).filter(i=>U(i.symbol)).map(i=>({relative_path:r,symbol:i.symbol})))}function Jg(e){let t=new Set;return e.filter(n=>{let r=`${n.relative_path}|${n.symbol}`;return t.has(r)?!1:(t.add(r),!0)})}function qg(e){return{consumer:e.relative_path,symbol:e.symbol,shortName:h(e.symbol)}}function In(e,t={}){let{scope:n,minLoc:r=1,includeTests:i=!1,skipBarrels:s=!1,includeMembers:o=!1}=t,a=s?new Set(ao(e)):new Set,l=zg(e,a);Xg(e,l,a);let c=Gg(e,{scope:n,minLoc:r,includeTests:i,includeMembers:o});return ih(e,c,l,{includeTests:i,inactiveBarrelPaths:a}),Yg(e,Kg(c,l))}function zg(e,t){let n=e.all(`SELECT
622
+ ORDER BY d1.relative_path`,...t,...t,...t)}function lh(e,t){let n=new C(e);return t.flatMap(r=>n.definitionsForFile(r).filter(i=>U(i.symbol)).map(i=>({relative_path:r,symbol:i.symbol})))}function ch(e){let t=new Set;return e.filter(n=>{let r=`${n.relative_path}|${n.symbol}`;return t.has(r)?!1:(t.add(r),!0)})}function uh(e){return{consumer:e.relative_path,symbol:e.symbol,shortName:h(e.symbol)}}function _n(e,t={}){let{scope:n,minLoc:r=1,includeTests:i=!1,skipBarrels:s=!1,includeMembers:o=!1}=t,a=s?new Set(fo(e)):new Set,l=dh(e,a);hh(e,l,a);let c=mh(e,{scope:n,minLoc:r,includeTests:i,includeMembers:o});return Ih(e,c,l,{includeTests:i,inactiveBarrelPaths:a}),gh(e,ph(c,l))}function dh(e,t){let n=e.all(`SELECT
623
623
  m.symbol_id,
624
624
  d.relative_path,
625
625
  COUNT(*) AS ref_count
@@ -628,8 +628,8 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
628
628
  JOIN documents d ON c.document_id = d.id
629
629
  WHERE m.role != 1
630
630
  ${e.pathExclusionsFor("d")}
631
- GROUP BY m.symbol_id, d.relative_path`),r=new Map;for(let i of n){if(e.isIgnored(i.relative_path)||t.has(i.relative_path))continue;let s=r.get(i.symbol_id);s||(s=new Map,r.set(i.symbol_id,s)),s.set(i.relative_path,i.ref_count)}return r}function Gg(e,t){let n=sh(e);return oe(e,{scope:t.scope}).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>!De(r.symbol)).filter(r=>Ro(r.symbol)).filter(r=>r.isFunctionLike||!r.enclosingSymbol||!Ro(r.enclosingSymbol)).filter(r=>t.includeTests||Co(r.relativePath)).filter(r=>t.includeTests||!n(r.relativePath,r.startLine,r.symbol,r.parentTypeName)).filter(r=>!rn(r.symbol)).filter(r=>!Le(r.symbol)).filter(r=>t.includeMembers||ah(r)).filter(r=>r.endLine-r.startLine+1>=t.minLoc)}function Kg(e,t){return e.map(n=>Qg(n,t)).filter(n=>n.cross_file_refs===0).sort((n,r)=>r.loc-n.loc||n.relative_path.localeCompare(r.relative_path)||n.start_line-r.start_line)}function Qg(e,t){let n=t.get(e.symbolId)??new Map,r=n.get(e.relativePath)??0,i=0;for(let[s,o]of n)s!==e.relativePath&&(i+=o);return{relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine,loc:e.endLine-e.startLine+1,symbol:e.symbol,same_file_refs:r,cross_file_refs:i}}function Yg(e,t){let n=[],r=0,i=0,s=0;for(let o of t){if(e.isIgnored(o.relative_path)||ze(e,o.relative_path)||Lt(e,o.symbol,o.relative_path))continue;let a=o.same_file_refs===0?"dead-code":"file-internal";a==="dead-code"?r++:i++,s+=o.loc,n.push({relativePath:o.relative_path,startLine:o.start_line,endLine:o.end_line,loc:o.loc,symbol:o.symbol,shortName:h(o.symbol),sameFileRefs:o.same_file_refs,kind:a})}return{symbols:n,totalCount:n.length,deadCodeCount:r,fileInternalCount:i,totalLoc:s}}function Xg(e,t,n){let r=new C(e),i=new Set(r.sourceFiles());for(let s of Zg(e))i.add(s);r.scanSourceReferences({paths:i,includeVueSfc:!0,includeCrossLanguageDispatchNames:!0,includeRustAttributeNames:!0,identifierResolution:"permissive",skipPath:s=>n.has(s)},s=>{eh(e,s)||nh(t,s.target.symbolId,s.sourceFile,th(s))})}function Zg(e){let t=e.all(`SELECT relative_path FROM documents
632
- WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);return new Set(t.map(n=>n.relative_path))}function eh(e,t){return t.kind==="cross-language-dispatch"&&t.target.relativePath===t.sourceFile?!0:t.kind==="identifier"&&rh(e,t)}function th(e){return e.kind==="identifier"&&e.target.relativePath===e.sourceFile?Math.max(0,e.occurrences-1):e.occurrences}function nh(e,t,n,r){if(r<=0)return;let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,(i.get(n)??0)+r)}function rh(e,t){return t.occurrences>1?!1:J(e,t.sourceFile).some(n=>n.used||n.sourcePath!==t.target.relativePath?!1:n.importedName===t.name||n.localName===t.name)}function ih(e,t,n,r){for(let i of t){let s=ie(e,i);if(s.length===0)continue;let o=n.get(i.symbolId);o||(o=new Map,n.set(i.symbolId,o));for(let a of s){let l=a.file;l===i.relativePath||e.isIgnored(l)||r.inactiveBarrelPaths.has(l)||!r.includeTests&&!Co(l)||o.set(l,Math.max(1,o.get(l)??0))}}}function sh(e){let t=new Map,n=r=>{let i=t.get(r);if(i)return i;let s=cs(e,r);return i={ranges:s.map(o=>({startLine:o.startLine,endLine:o.endLine})),containers:new Set(s.map(o=>o.containerName).filter(o=>!!o))},t.set(r,i),i};return(r,i,s,o)=>{let a=n(r);for(let l of a.ranges)if(i>=l.startLine&&i<=l.endLine)return!0;if(o&&a.containers.has(o))return!0;for(let l of ur(s))if(a.containers.has(l))return!0;return!1}}function Co(e){return[...new Set([...lo,...co])].every(n=>!oh(e,n))}function oh(e,t){return new RegExp(`^${t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function Ro(e){return W(e)||e.endsWith("().")||e.endsWith(".")}function ah(e){return U(e.symbol)||ur(e.symbol).length===0}function vo(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"",o=e.all(`SELECT
631
+ GROUP BY m.symbol_id, d.relative_path`),r=new Map;for(let i of n){if(e.isIgnored(i.relative_path)||t.has(i.relative_path))continue;let s=r.get(i.symbol_id);s||(s=new Map,r.set(i.symbol_id,s)),s.set(i.relative_path,i.ref_count)}return r}function mh(e,t){let n=Rh(e);return oe(e,{scope:t.scope}).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>!Le(r.symbol)).filter(r=>Lo(r.symbol)).filter(r=>r.isFunctionLike||!r.enclosingSymbol||!Lo(r.enclosingSymbol)).filter(r=>t.includeTests||ko(r.relativePath)).filter(r=>t.includeTests||!n(r.relativePath,r.startLine,r.symbol,r.parentTypeName)).filter(r=>!rn(r.symbol)).filter(r=>!ke(r.symbol)).filter(r=>t.includeMembers||vh(r)).filter(r=>r.endLine-r.startLine+1>=t.minLoc)}function ph(e,t){return e.map(n=>fh(n,t)).filter(n=>n.cross_file_refs===0).sort((n,r)=>r.loc-n.loc||n.relative_path.localeCompare(r.relative_path)||n.start_line-r.start_line)}function fh(e,t){let n=t.get(e.symbolId)??new Map,r=n.get(e.relativePath)??0,i=0;for(let[s,o]of n)s!==e.relativePath&&(i+=o);return{relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine,loc:e.endLine-e.startLine+1,symbol:e.symbol,same_file_refs:r,cross_file_refs:i}}function gh(e,t){let n=[],r=0,i=0,s=0;for(let o of t){if(e.isIgnored(o.relative_path)||ze(e,o.relative_path)||Lt(e,o.symbol,o.relative_path))continue;let a=o.same_file_refs===0?"dead-code":"file-internal";a==="dead-code"?r++:i++,s+=o.loc,n.push({relativePath:o.relative_path,startLine:o.start_line,endLine:o.end_line,loc:o.loc,symbol:o.symbol,shortName:h(o.symbol),sameFileRefs:o.same_file_refs,kind:a})}return{symbols:n,totalCount:n.length,deadCodeCount:r,fileInternalCount:i,totalLoc:s}}function hh(e,t,n){let r=new C(e),i=new Set(r.sourceFiles());for(let s of yh(e))i.add(s);r.scanSourceReferences({paths:i,includeVueSfc:!0,includeCrossLanguageDispatchNames:!0,includeRustAttributeNames:!0,identifierResolution:"permissive",skipPath:s=>n.has(s)},s=>{bh(e,s)||xh(t,s.target.symbolId,s.sourceFile,Sh(s))})}function yh(e){let t=e.all(`SELECT relative_path FROM documents
632
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);return new Set(t.map(n=>n.relative_path))}function bh(e,t){return t.kind==="cross-language-dispatch"&&t.target.relativePath===t.sourceFile?!0:t.kind==="identifier"&&_h(e,t)}function Sh(e){return e.kind==="identifier"&&e.target.relativePath===e.sourceFile?Math.max(0,e.occurrences-1):e.occurrences}function xh(e,t,n,r){if(r<=0)return;let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,(i.get(n)??0)+r)}function _h(e,t){return t.occurrences>1?!1:J(e,t.sourceFile).some(n=>n.used||n.sourcePath!==t.target.relativePath?!1:n.importedName===t.name||n.localName===t.name)}function Ih(e,t,n,r){for(let i of t){let s=ie(e,i);if(s.length===0)continue;let o=n.get(i.symbolId);o||(o=new Map,n.set(i.symbolId,o));for(let a of s){let l=a.file;l===i.relativePath||e.isIgnored(l)||r.inactiveBarrelPaths.has(l)||!r.includeTests&&!ko(l)||o.set(l,Math.max(1,o.get(l)??0))}}}function Rh(e){let t=new Map,n=r=>{let i=t.get(r);if(i)return i;let s=us(e,r);return i={ranges:s.map(o=>({startLine:o.startLine,endLine:o.endLine})),containers:new Set(s.map(o=>o.containerName).filter(o=>!!o))},t.set(r,i),i};return(r,i,s,o)=>{let a=n(r);for(let l of a.ranges)if(i>=l.startLine&&i<=l.endLine)return!0;if(o&&a.containers.has(o))return!0;for(let l of cr(s))if(a.containers.has(l))return!0;return!1}}function ko(e){return[...new Set([...go,...ho])].every(n=>!Ch(e,n))}function Ch(e,t){return new RegExp(`^${t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function Lo(e){return W(e)||e.endsWith("().")||e.endsWith(".")}function vh(e){return U(e.symbol)||cr(e.symbol).length===0}function wo(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"",o=e.all(`SELECT
633
633
  gs.symbol,
634
634
  COUNT(*) AS ref_count,
635
635
  COUNT(DISTINCT ref_d.id) AS file_count,
@@ -652,18 +652,18 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
652
652
  ${i}
653
653
  GROUP BY gs.id
654
654
  ORDER BY ref_count DESC
655
- LIMIT ?`,n).filter(a=>!e.isIgnored(a.defined_in)).map(a=>({symbol:a.symbol,shortName:h(a.symbol),refCount:a.ref_count,fileCount:a.file_count,definedIn:a.defined_in}));return o.length>0?o:lh(e,r,n)}function lh(e,t,n){return oe(e,{scope:t}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>ch(e,r)).filter(r=>r.refCount>0).sort((r,i)=>i.refCount-r.refCount||i.fileCount-r.fileCount).slice(0,n)}function ch(e,t){let n=ie(e,t,{limit:500});return{symbol:t.symbol,shortName:h(t.symbol),refCount:n.length,fileCount:new Set(n.map(r=>r.file)).size,definedIn:t.relativePath}}function Eo(e,t){return ko(e,t)?.map(n=>({symbol:n.symbol,shortName:n.shortName,fromFile:n.fromFile}))??[]}function Do(e,t){let n=uh(e,t);return n.length>0?n:dh(e,t)}function Lo(e,t){return ko(e,t)?.filter(n=>!n.used).map(n=>({symbol:n.symbol,shortName:n.shortName,importedIn:n.importer}))??[]}function uh(e,t){return e.all(`SELECT DISTINCT gs.symbol, d.relative_path AS importer
655
+ LIMIT ?`,n).filter(a=>!e.isIgnored(a.defined_in)).map(a=>({symbol:a.symbol,shortName:h(a.symbol),refCount:a.ref_count,fileCount:a.file_count,definedIn:a.defined_in}));return o.length>0?o:Nh(e,r,n)}function Nh(e,t,n){return oe(e,{scope:t}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>Eh(e,r)).filter(r=>r.refCount>0).sort((r,i)=>i.refCount-r.refCount||i.fileCount-r.fileCount).slice(0,n)}function Eh(e,t){let n=ie(e,t,{limit:500});return{symbol:t.symbol,shortName:h(t.symbol),refCount:n.length,fileCount:new Set(n.map(r=>r.file)).size,definedIn:t.relativePath}}function Oo(e,t){return To(e,t)?.map(n=>({symbol:n.symbol,shortName:n.shortName,fromFile:n.fromFile}))??[]}function Mo(e,t){let n=Dh(e,t);return n.length>0?n:Lh(e,t)}function Fo(e,t){return To(e,t)?.filter(n=>!n.used).map(n=>({symbol:n.symbol,shortName:n.shortName,importedIn:n.importer}))??[]}function Dh(e,t){return e.all(`SELECT DISTINCT gs.symbol, d.relative_path AS importer
656
656
  FROM mentions m
657
657
  JOIN chunks c ON m.chunk_id = c.id
658
658
  JOIN documents d ON c.document_id = d.id
659
659
  JOIN global_symbols gs ON m.symbol_id = gs.id
660
660
  WHERE gs.symbol LIKE ?
661
661
  AND m.role = 2
662
- ORDER BY d.relative_path`,`%${t}%`).filter(r=>!e.isIgnored(r.importer)).map(r=>({symbol:r.symbol,shortName:h(r.symbol),fromFile:r.importer}))}function dh(e,t){let n=L(e,t),r=n?.relativePath??null,i=n?k(n.symbol):t.replace(/\(\)$/,""),s=n?De(n.symbol):!1,o=e.all(`SELECT relative_path
662
+ ORDER BY d.relative_path`,`%${t}%`).filter(r=>!e.isIgnored(r.importer)).map(r=>({symbol:r.symbol,shortName:h(r.symbol),fromFile:r.importer}))}function Lh(e,t){let n=E(e,t),r=n?.relativePath??null,i=n?D(n.symbol):t.replace(/\(\)$/,""),s=n?Le(n.symbol):!1,o=e.all(`SELECT relative_path
663
663
  FROM documents
664
664
  WHERE 1 = 1
665
665
  ${e.pathExclusionsFor("documents")}
666
- ORDER BY relative_path`),a=new Set;for(let l of o)if(!e.isIgnored(l.relative_path))for(let c of J(e,l.relative_path))mh(c,l.relative_path,{targetFile:r,targetLeaf:i,targetIsModule:s})&&a.add(l.relative_path);return[...a].sort().map(l=>({symbol:n?.symbol??i,shortName:n?h(n.symbol):i,fromFile:l}))}function mh(e,t,n){return!e.sourcePath||n.targetFile&&No(e.sourcePath)!==No(n.targetFile)?!1:e.kind==="side-effect"||n.targetFile&&hh(t)||n.targetIsModule||e.kind==="named"&&e.importedName===n.targetLeaf?!0:e.kind==="namespace"&&e.usedMembers.includes(n.targetLeaf)}function ko(e,t){let n=G(e,t);return n?ph(e,n)??fh(e,n)??gh(e,n):null}function ph(e,t){let r=e.all(`SELECT DISTINCT
666
+ ORDER BY relative_path`),a=new Set;for(let l of o)if(!e.isIgnored(l.relative_path))for(let c of J(e,l.relative_path))kh(c,l.relative_path,{targetFile:r,targetLeaf:i,targetIsModule:s})&&a.add(l.relative_path);return[...a].sort().map(l=>({symbol:n?.symbol??i,shortName:n?h(n.symbol):i,fromFile:l}))}function kh(e,t,n){return!e.sourcePath||n.targetFile&&Po(e.sourcePath)!==Po(n.targetFile)?!1:e.kind==="side-effect"||n.targetFile&&Mh(t)||n.targetIsModule||e.kind==="named"&&e.importedName===n.targetLeaf?!0:e.kind==="namespace"&&e.usedMembers.includes(n.targetLeaf)}function To(e,t){let n=G(e,t);return n?wh(e,n)??Ph(e,n)??Oh(e,n):null}function wh(e,t){let r=e.all(`SELECT DISTINCT
667
667
  gs.symbol,
668
668
  def_d.relative_path AS from_file,
669
669
  imp_d.relative_path AS importer,
@@ -689,11 +689,11 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
689
689
  LEFT JOIN documents def_d ON sym_def.document_id = def_d.id
690
690
  WHERE imp_d.relative_path = ?
691
691
  AND m.role = 2
692
- ORDER BY def_d.relative_path, gs.symbol`,t).filter(i=>!e.isIgnored(i.importer));if(r.length>0){let i=vt(e,t);return r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),fromFile:s.from_file??"(external)",importer:s.importer,used:s.used!==0||i.some(o=>o.isUsed&&o.sourcePath===s.from_file)}))}return null}function fh(e,t){let n=vt(e,t);return n.length>0?n.map(r=>{let i=wo(r.importedName,r.localName,r.kind);return{symbol:i,shortName:i,fromFile:r.sourcePath??"(external)",importer:t,used:r.kind==="side-effect"?!0:r.isUsed}}):null}function gh(e,t){return J(e,t).map(n=>{let r=wo(n.importedName,n.localName,n.kind),i=n.kind==="side-effect"?!0:n.used;return{symbol:r,shortName:r,fromFile:n.sourcePath??"(external)",importer:t,used:i}})}function wo(e,t,n){return n==="namespace"&&e==="*"&&t?`* as ${t}`:n==="default"&&t?`default as ${t}`:n==="side-effect"?"(side effect import)":t&&t!==e?`${e} as ${t}`:e}function No(e){return e.replace(/\\/g,"/")}function hh(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function Po(e,t){let n=ke(e,t),r=nt(e,n,{sort:!0});if(r.length===0)return[];let i=r.map(a=>({symbol:a.symbol,shortName:a.shortName,startLine:a.startLine,endLine:a.endLine,children:[]})),s=new Map;for(let a of i)s.set(a.symbol,a);let o=[];for(let a=0;a<r.length;a++){let l=r[a],c=i[a];if(l.enclosingSymbol&&s.has(l.enclosingSymbol)){s.get(l.enclosingSymbol).children.push(c);continue}let d=null,u=1/0;for(let m of i)if(m!==c&&m.startLine<=c.startLine&&m.endLine>=c.endLine){if(m.startLine===c.startLine&&m.endLine===c.endLine&&!es(m.symbol,c.symbol))continue;let p=m.endLine-m.startLine;p<u&&(u=p,d=m)}d?d.children.push(c):o.push(c)}return o}function Oo(e,t){let n=L(e,t);return n?new C(e).definitionsForFile(n.relativePath).filter(i=>i.symbol!==n.symbol).filter(i=>Zi(n.symbol,i.symbol)).sort((i,s)=>i.startLine-s.startLine||i.endLine-s.endLine).map(i=>({symbol:i.symbol,shortName:h(i.symbol),startLine:i.startLine,endLine:i.endLine,kind:V(i.symbol)??"unknown"})):[]}function Mo(e,t){let n=L(e,t);if(!n)return[];let r=e.get(`SELECT COUNT(DISTINCT c.document_id) AS file_count
692
+ ORDER BY def_d.relative_path, gs.symbol`,t).filter(i=>!e.isIgnored(i.importer));if(r.length>0){let i=vt(e,t);return r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),fromFile:s.from_file??"(external)",importer:s.importer,used:s.used!==0||i.some(o=>o.isUsed&&o.sourcePath===s.from_file)}))}return null}function Ph(e,t){let n=vt(e,t);return n.length>0?n.map(r=>{let i=$o(r.importedName,r.localName,r.kind);return{symbol:i,shortName:i,fromFile:r.sourcePath??"(external)",importer:t,used:r.kind==="side-effect"?!0:r.isUsed}}):null}function Oh(e,t){return J(e,t).map(n=>{let r=$o(n.importedName,n.localName,n.kind),i=n.kind==="side-effect"?!0:n.used;return{symbol:r,shortName:r,fromFile:n.sourcePath??"(external)",importer:t,used:i}})}function $o(e,t,n){return n==="namespace"&&e==="*"&&t?`* as ${t}`:n==="default"&&t?`default as ${t}`:n==="side-effect"?"(side effect import)":t&&t!==e?`${e} as ${t}`:e}function Po(e){return e.replace(/\\/g,"/")}function Mh(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function Ao(e,t){let n=we(e,t),r=nt(e,n,{sort:!0});if(r.length===0)return[];let i=r.map(a=>({symbol:a.symbol,shortName:a.shortName,startLine:a.startLine,endLine:a.endLine,children:[]})),s=new Map;for(let a of i)s.set(a.symbol,a);let o=[];for(let a=0;a<r.length;a++){let l=r[a],c=i[a];if(l.enclosingSymbol&&s.has(l.enclosingSymbol)){s.get(l.enclosingSymbol).children.push(c);continue}let u=null,d=1/0;for(let m of i)if(m!==c&&m.startLine<=c.startLine&&m.endLine>=c.endLine){if(m.startLine===c.startLine&&m.endLine===c.endLine&&!ts(m.symbol,c.symbol))continue;let p=m.endLine-m.startLine;p<d&&(d=p,u=m)}u?u.children.push(c):o.push(c)}return o}function jo(e,t){let n=E(e,t);return n?new C(e).definitionsForFile(n.relativePath).filter(i=>i.symbol!==n.symbol).filter(i=>es(n.symbol,i.symbol)).sort((i,s)=>i.startLine-s.startLine||i.endLine-s.endLine).map(i=>({symbol:i.symbol,shortName:h(i.symbol),startLine:i.startLine,endLine:i.endLine,kind:V(i.symbol)??"unknown"})):[]}function Bo(e,t){let n=E(e,t);if(!n)return[];let r=e.get(`SELECT COUNT(DISTINCT c.document_id) AS file_count
693
693
  FROM mentions m
694
694
  JOIN chunks c ON m.chunk_id = c.id
695
695
  WHERE m.symbol_id = ?
696
- AND m.role != 1`,n.symbolId);return[{name:h(n.symbol),count:r?.file_count??0}]}function Fo(e,t){let n=G(e,t);if(!n)return[];let i=e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
696
+ AND m.role != 1`,n.symbolId);return[{name:h(n.symbol),count:r?.file_count??0}]}function Wo(e,t){let n=G(e,t);if(!n)return[];let i=e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
697
697
  FROM mentions m
698
698
  JOIN chunks c ON m.chunk_id = c.id
699
699
  JOIN documents d ON c.document_id = d.id
@@ -710,7 +710,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
710
710
  AND m.role != 1
711
711
  AND def_d.id != d.id
712
712
  GROUP BY d.id
713
- ORDER BY symbol_count DESC`,n).filter(a=>!e.isIgnored(a.relative_path)).map(a=>({name:a.relative_path,count:a.symbol_count}));if(i.length>0)return i;let o=Q(e).get(n);return!o||o.size===0?[]:[{name:n,count:o.size}]}function To(e,t={}){return yh(e,t).map(n=>({name:h(n.symbol),count:n.file_count}))}function yh(e,t){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
713
+ ORDER BY symbol_count DESC`,n).filter(a=>!e.isIgnored(a.relative_path)).map(a=>({name:a.relative_path,count:a.symbol_count}));if(i.length>0)return i;let o=Y(e).get(n);return!o||o.size===0?[]:[{name:n,count:o.size}]}function Ho(e,t={}){return Fh(e,t).map(n=>({name:h(n.symbol),count:n.file_count}))}function Fh(e,t){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
714
714
  FROM mentions m
715
715
  JOIN chunks c ON m.chunk_id = c.id
716
716
  JOIN global_symbols gs ON m.symbol_id = gs.id
@@ -729,7 +729,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
729
729
  GROUP BY gs.id
730
730
  HAVING file_count > 1
731
731
  ORDER BY file_count DESC
732
- LIMIT ?`,n)}function $o(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
732
+ LIMIT ?`,n)}function Vo(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
733
733
  FROM mentions m
734
734
  JOIN chunks c ON m.chunk_id = c.id
735
735
  JOIN documents d ON c.document_id = d.id
@@ -749,7 +749,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
749
749
  ${i}
750
750
  GROUP BY d.id
751
751
  ORDER BY symbol_count DESC
752
- LIMIT ?`,n).filter(o=>!e.isIgnored(o.relative_path)).map(o=>({name:o.relative_path,count:o.symbol_count}))}function Ao(e,t,n){let r=G(e,t)??t,i=G(e,n)??n,s=e.get(`SELECT COUNT(DISTINCT gs.id) AS shared
752
+ LIMIT ?`,n).filter(o=>!e.isIgnored(o.relative_path)).map(o=>({name:o.relative_path,count:o.symbol_count}))}function Uo(e,t,n){let r=G(e,t)??t,i=G(e,n)??n,s=e.get(`SELECT COUNT(DISTINCT gs.id) AS shared
753
753
  FROM global_symbols gs
754
754
  WHERE (
755
755
  -- Defined in file1, referenced in file2
@@ -781,7 +781,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
781
781
  JOIN documents d ON c.document_id = d.id
782
782
  WHERE m.symbol_id = gs.id AND m.role != 1 AND d.relative_path = ?
783
783
  )
784
- )`,r,i,i,r);return{file1:r,file2:i,sharedSymbols:s?.shared??0}}function jo(e,t={}){let{limit:n=20,scope:r}=t,i=r?`AND d1.relative_path LIKE '%${r}%' AND d2.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT
784
+ )`,r,i,i,r);return{file1:r,file2:i,sharedSymbols:s?.shared??0}}function Jo(e,t={}){let{limit:n=20,scope:r}=t,i=r?`AND d1.relative_path LIKE '%${r}%' AND d2.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT
785
785
  def_d.relative_path AS file1,
786
786
  ref_d.relative_path AS file2,
787
787
  COUNT(DISTINCT gs.id) AS shared
@@ -803,35 +803,35 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
803
803
  ${i}
804
804
  GROUP BY def_d.id, ref_d.id
805
805
  ORDER BY shared DESC
806
- LIMIT ?`,n).filter(o=>!e.isIgnored(o.file1)&&!e.isIgnored(o.file2)).map(o=>({file1:o.file1,file2:o.file2,sharedSymbols:o.shared}))}function Rn(e,t={}){let{scope:n,maxDepth:r=10}=t,i=Q(e,n),s=[],o=new Set,a=new Set,l=[];function c(u,m){if(m>r)return;if(a.has(u)){let p=l.indexOf(u);if(p!==-1){let g=l.slice(p).concat(u),y=g.indexOf(g.reduce((F,T)=>F<T?F:T)),E=[...g.slice(y,-1),...g.slice(0,y),g[y]],N=E.join(" -> ");d.has(N)||(d.add(N),s.push({path:E,kind:bh(E)}))}return}if(o.has(u))return;o.add(u),a.add(u),l.push(u);let f=i.get(u);if(f)for(let p of f)c(p,m+1);l.pop(),a.delete(u)}let d=new Set;for(let u of i.keys())o.has(u)||c(u,0);return s.sort((u,m)=>u.kind!==m.kind?u.kind==="real"?-1:1:u.path.length-m.path.length),s}function bh(e){for(let r of e){let i=Z(r);if(i==="test"||i==="barrel"||i==="entry")return"module-hierarchy"}if(e.length!==3)return"real";let[t,n]=e;return!t||!n?"real":xn(t)||xn(n)||Bo(t,n)||Bo(n,t)||Wo(t,n)||Wo(n,t)||Z(t)==="entry"||Z(n)==="entry"?"module-hierarchy":"real"}function Bo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=t.replace(/\.rs$/,"/");return e.startsWith(n)?!e.slice(n.length).includes("/"):!1}function Wo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=e.replace(/\.rs$/,""),r=t.replace(/\.rs$/,"");if(n===r+"_tests"||n===r+"/tests")return!0;let i=e.split("/"),s=t.split("/");if(i.length===s.length&&i.includes("tests")&&s.includes("src")){let o=i[i.length-1],a=s[s.length-1];if(o&&o===a)return!0}return!1}function Ho(e,t={}){let{limit:n=20,scope:r,minFanIn:i=2,minFanOut:s=2}=t;return new C(e).productionCallableDefinitions({scope:r,requireCallableSymbol:!0,includeSuppressed:!0}).map(l=>Sh(e,l)).filter(l=>l.fanIn>=i&&l.fanOut>=s).sort((l,c)=>c.score-l.score||c.fanIn-l.fanIn).slice(0,n)}function Sh(e,t){let n=new Set(ie(e,t,{limit:500}).map(i=>i.file)).size,r=new Set(X(e,t,{limit:500}).filter(i=>i.file!==t.relativePath).map(i=>`${i.symbol}|${i.file}`)).size;return{symbol:t.symbol,shortName:h(t.symbol),fanIn:n,fanOut:r,score:n*r,definedIn:t.relativePath}}function Cn(e,t={}){let{scope:n,minLoc:r=3}=t,i=new C(e),s=i.productionCallableDefinitions({scope:n,minLoc:r,excludeEntrySurfaces:!0,excludeRustTraitImplMembers:!0,includeSuppressed:!0}),o=i.crossFileCallerMap(s),a=i.sourceFallbackCallerFiles(s),l=new Set([...o.keys(),...a.keys()]),c=new Map;for(let p of s){let g=k(p.symbol);if(!g)continue;let y=c.get(g)??[];y.push(p.symbolId),c.set(g,y)}let d=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of d){if(e.isIgnored(p.relative_path)||M(p.relative_path)!=="rust")continue;let g=st(e,p.relative_path);for(let y of g){let E=c.get(y);if(E)for(let N of E)l.add(N)}}let u=new Map(s.map(p=>[p.symbolId,p.symbol])),m=i.calleeMap(s,{additive:!0}),f=new Set([...m.entries()].filter(([p,g])=>{let y=u.get(p);return g.some(E=>E.symbol!==y)}).map(([p])=>p));return s.filter(p=>!l.has(p.symbolId)).filter(p=>!f.has(p.symbolId)).sort((p,g)=>g.endLine-g.startLine-(p.endLine-p.startLine)||p.relativePath.localeCompare(g.relativePath)||p.startLine-g.startLine).map(p=>({symbol:p.symbol,shortName:h(p.symbol),relativePath:p.relativePath,startLine:p.startLine,endLine:p.endLine,loc:p.endLine-p.startLine+1}))}var wr={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"},kr=new Map;for(let[e,t]of Object.entries(wr))kr.set(t.toLowerCase(),Number(e));function xh(e){let t=parseInt(e,10);if(!isNaN(t))return t;let n=e.toLowerCase(),r=kr.get(n);if(r!==void 0)return r;for(let[i,s]of kr)if(i.includes(n))return s;return null}function Vo(e,t,n={}){let{scope:r,limit:i=100}=n,s=xh(t);return s===null?[]:Jo(e,r).map(a=>({row:a,resolvedKind:qo(a)})).filter(a=>a.resolvedKind===s).slice(0,i).map(({row:a,resolvedKind:l})=>({symbol:a.symbol,shortName:h(a.symbol),kind:l,kindName:wr[l]??"Unknown",relativePath:a.relative_path,startLine:a.start_line,endLine:a.end_line}))}function Uo(e,t={}){let n=new Map;for(let r of Jo(e,t.scope)){let i=qo(r);i===null||i===0||n.set(i,(n.get(i)??0)+1)}return[...n.entries()].sort((r,i)=>i[1]-r[1]||r[0]-i[0]).map(([r,i])=>({kind:r,kindName:wr[r]??"Unknown",count:i}))}function Jo(e,t){return oe(e,{scope:t}).map(_h)}function _h(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 qo(e){return e.kind!==null&&e.kind!==0?Ih(e.kind,e.symbol,e.documentation):Rh(e.symbol,e.documentation,e.enclosing_symbol)}function Ih(e,t,n){let r=(n??"").toLowerCase();if(V(t)==="type"){if(r.includes("type "))return 76;if(r.includes("interface "))return 27;if(r.includes("struct "))return 68;if(r.includes("trait "))return 73;if(r.includes("class "))return 9}return e}function Rh(e,t,n){let r=H(e);if("kind"in r)return null;let i=r.descriptors,s=i[i.length-2]??null,o=V(e),a=(t??"").toLowerCase();return o==="type"?a.includes("type ")?76:a.includes("interface ")?27:a.includes("struct ")?68:a.includes("trait ")?73:(a.includes("class "),9):o==="method"?s?.suffix==="type"?33:23:o==="namespace"?39:o!=="term"?null:a.includes("async def ")||a.includes("def ")?23:(n?V(n):s?.suffix??null)==="type"?21:83}function zo(e,t={}){let{limit:n=10,scope:r,minDepth:i=3}=t,s=Q(e,r),o=new Map,a=[],l=new Map,c=new Map,d=new Set,u=[],m=0;for(let R of s.keys()){if(l.has(R))continue;let _=[],P=(s.get(R)??new Set).values();for(l.set(R,m),c.set(R,m),m+=1,u.push(R),d.add(R),_.push({node:R,iter:P,pendingChild:null});_.length>0;){let D=_[_.length-1];if(D.pendingChild!==null){let Ke=D.pendingChild;D.pendingChild=null,c.set(D.node,Math.min(c.get(D.node),c.get(Ke)))}let z=D.iter.next();if(z.done){if(c.get(D.node)===l.get(D.node)){let Ke=[];for(;;){let $t=u.pop();if(d.delete($t),Ke.push($t),o.set($t,a.length),$t===D.node)break}a.push(Ke)}_.pop();continue}let de=z.value;if(l.has(de))d.has(de)&&c.set(D.node,Math.min(c.get(D.node),l.get(de)));else{l.set(de,m),c.set(de,m),m+=1,u.push(de),d.add(de);let Ke=(s.get(de)??new Set).values();D.pendingChild=de,_.push({node:de,iter:Ke,pendingChild:null})}}}let f=new Map,p=new Array(a.length);for(let R=0;R<a.length;R++)p[R]=a[R].length,f.set(R,new Set);for(let[R,_]of s){let P=o.get(R);for(let D of _){let z=o.get(D);z!==P&&f.get(P).add(z)}}let g=new Array(a.length),y=new Array(a.length);for(let R=0;R<a.length;R++){let _=[],P=0;for(let D of f.get(R)){let z=y[D];z>P&&(P=z,_=g[D])}g[R]=[R,..._],y[R]=p[R]+P}function E(R){return g[R]}let N=a.map(R=>[...R].sort()),F=new Set,T=[];for(let R=0;R<a.length;R++){let _=E(R),P=[];for(let z of _)P.push(...N[z]);if(P.length<i)continue;let D=P.join(" ");F.has(D)||(F.add(D),T.push({chain:P,depth:P.length}))}return T.sort((R,_)=>_.depth-R.depth),T.slice(0,n)}function Go(e,t){let n=L(e,t);if(!n)return[];let r=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
807
- WHERE id = ? LIMIT 1`,n.symbolId);if(!r)return[];let i=[{symbol:r.symbol,shortName:h(r.symbol),depth:0}],s=r.enclosing_symbol,o=1,a=new Set([r.symbol]);for(;s&&!a.has(s)&&o<20;){a.add(s);let u=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",s);if(!u)break;i.push({symbol:u.symbol,shortName:h(u.symbol),depth:o}),s=u.enclosing_symbol,o++}if(i.length>1)return i;let l=H(r.symbol);if("kind"in l)return i;let c=l.descriptors;if(c.length<=1)return i;let d=[i[0]];for(let u=c.length-2,m=1;u>=0;u--,m++){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(":");d.push({symbol:p,shortName:p,depth:m})}return d}function Ko(e,t){let n=L(e,t);if(!n)return null;let r=ie(e,n,{limit:50}),i=Ch(X(e,n,{limit:50,additive:!0,callableOnly:!0}));return{symbol:n.symbol,shortName:h(n.symbol),callers:r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file})),callees:i.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file}))}}function Ch(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function wt(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function Pt(e,t){let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function Qo(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let i of e)t.has(i)&&(n+=1);let r=e.size+t.size-n;return r===0?0:n/r}function Pr(e){let t=e.length;if(t===0)return new Map;let n=new Map;for(let i of e)for(let s of i)n.set(s,(n.get(s)??0)+1);let r=new Map;for(let[i,s]of n)r.set(i,Math.log(t/s));return r}function vh(e){let t=[...e.values()].sort((r,i)=>r-i);if(t.length===0)return 0;let n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function Yo(e,t,n){let r=wt(e,t);if(r.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let i=0,s=0,o=0,a=new Set([...e,...t]);for(let f of a){let p=n.get(f)??0,g=e.has(f)?p:0,y=t.has(f)?p:0;i+=g*y,s+=g*g,o+=y*y}let l=Math.sqrt(s)*Math.sqrt(o),c=l>0?i/l:0,d=vh(n),u=[],m=[];for(let f of r)(n.get(f)??0)>=d?u.push(f):m.push(f);return u.sort((f,p)=>(n.get(p)??0)-(n.get(f)??0)),{similarity:c,significantShared:u,trivialShared:m}}function Xo(e,t,n={}){let{minSimilarity:r=.4,limit:i=20}=n,s=Dh(e,t);if(!s)return[];if(!W(s.symbol))return[];let o=Nh(e,s,r);return o.length>0?o.slice(0,i):kh(e,t,{minSimilarity:r,limit:i})}function Nh(e,t,n){let r=ea(e,{minCallees:3,excludeSymbol:t.symbol}),i=Pr([t,...r].map(o=>o.callees)),s=[];for(let o of r){if(o.callees.size<3)continue;let a=Zo(t,o,i,{minSimilarity:n,requireSignificantShared:1,requireSharedCount:0});a&&s.push(a)}return s.sort((o,a)=>a.similarity-o.similarity),s}function Zo(e,t,n,r){let{similarity:i,significantShared:s}=Yo(e.callees,t.callees,n);if(i<r.minSimilarity)return null;let o=wt(e.callees,t.callees).size;if(s.length<r.requireSignificantShared&&o<r.requireSharedCount)return null;let a=s.length>0?s:[...wt(e.callees,t.callees)];return{symbolA:e.symbol,shortNameA:h(e.symbol),fileA:e.file,symbolB:t.symbol,shortNameB:h(t.symbol),fileB:t.file,similarity:i,similarityBasis:"callees",sharedCallees:a.map(h),uniqueToA:[...Pt(e.callees,t.callees)].map(h),uniqueToB:[...Pt(t.callees,e.callees)].map(h)}}function vn(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,minCallees:s=4,crossFileOnly:o=!1}=t,a=ea(e,{minCallees:s,scope:i}),l=Pr(a.map(p=>p.callees)),c=new Map;for(let p of a)for(let g of p.callees)c.set(g,(c.get(g)??0)+1);let d=Math.max(8,Math.ceil(Math.sqrt(a.length))),u=new Map;for(let p=0;p<a.length;p+=1)for(let g of a[p].callees){if((c.get(g)??0)>d)continue;let y=u.get(g);y||(y=[],u.set(g,y)),y.push(p)}let m=[],f=new Set;e:for(let p=0;p<a.length;p+=1){let g=a[p],y=new Set;for(let E of g.callees){let N=u.get(E);if(N)for(let F of N)F>p&&y.add(F)}for(let E of y){let N=`${p}|${E}`;if(f.has(N))continue;f.add(N);let F=a[E];if(o&&g.file===F.file)continue;if(g.paramCount>=0&&F.paramCount>=0){let R=Math.abs(g.paramCount-F.paramCount),_=Math.max(2,Math.ceil(Math.max(g.paramCount,F.paramCount)*.5));if(R>_)continue}let T=Zo(g,F,l,{minSimilarity:n,requireSignificantShared:2,requireSharedCount:4});if(T&&(m.push(T),m.length>r*5))break e}}return m.sort((p,g)=>g.similarity-p.similarity),m.slice(0,r)}var Eh=["ScipDatabase#all","ScipDatabase#get","ScipDatabase#prepare","ScipDatabase#pathExclusionsFor","ScipDatabase#isIgnored","ScipDatabase#symbolNoiseFor","PerDbValue#get","PerDbValue#has",":storage:db:ScipDatabase:all",":storage:db:ScipDatabase:get",":storage:db:ScipDatabase:prepare",":storage:db:ScipDatabase:pathExclusionsFor",":storage:db:ScipDatabase:isIgnored",":storage:db:ScipDatabase:symbolNoiseFor",":storage:per-db-cache:PerDbValue:get",":storage:per-db-cache:PerDbValue:has"];function Dh(e,t){let n=L(e,t),r=new C(e);if(!n)return null;let i=X(e,n);return{symbol:n.symbol,file:n.relativePath,callees:ta(i.map(s=>s.symbol)),paramCount:r.callableSignature(n)?.paramCount??-1}}function ea(e,t){let{minCallees:n,scope:r,excludeSymbol:i}=t,s=new C(e),o=s.productionCallableDefinitions({scope:r,minLoc:5,excludeSymbol:i}),a=s.calleeMap(o);return o.map(l=>({symbol:l.symbol,file:l.relativePath,callees:ta((a.get(l.symbolId)??[]).map(c=>c.symbol)),paramCount:s.callableSignature(l)?.paramCount??-1})).filter(l=>l.callees.size>=n)}function ta(e){return new Set([...e].filter(t=>!Lh(t)))}function Lh(e){return Eh.some(t=>e.includes(t))}function kh(e,t,n){let r=wh(e,t);if(!r||r.tokens.size<3)return[];let i=n.minSimilarity>=.5?n.minSimilarity:.3,s=[];for(let o of Oh(e)){if(o.symbol===r.symbol||o.tokens.size<3)continue;let a=wt(r.tokens,o.tokens);if(a.size<2)continue;let l=new Set([...r.tokens,...o.tokens]),c=l.size>0?a.size/l.size:0;c<i||s.push({symbolA:r.symbol,shortNameA:h(r.symbol),fileA:r.file,symbolB:o.symbol,shortNameB:h(o.symbol),fileB:o.file,similarity:c,similarityBasis:"source-tokens",sharedCallees:[...a].sort(),uniqueToA:[...Pt(r.tokens,o.tokens)].sort(),uniqueToB:[...Pt(o.tokens,r.tokens)].sort()})}return s.sort((o,a)=>a.similarity-o.similarity||o.shortNameB.localeCompare(a.shortNameB)),s.slice(0,n.limit)}function wh(e,t){let n=L(e,t);if(!n||!W(n.symbol))return null;let r=Ph(e,n);return r?{symbol:n.symbol,file:n.relativePath,tokens:r}:null}function Ph(e,t){let n=k(t.symbol),r=na(e,t.relativePath,t.startLine,t.endLine,n),i=ra(r,n);return i.size>0?i:null}function Oh(e){let t=new C(e);return t.scopedDefinitions().filter(n=>n.isFunctionLike).filter(n=>t.fileKind(n.relativePath)!=="test").filter(n=>!Le(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:ra(na(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function na(e,t,n,r,i){let s=O(e,t);if(!s)return"";let o=s.split(`
806
+ LIMIT ?`,n).filter(o=>!e.isIgnored(o.file1)&&!e.isIgnored(o.file2)).map(o=>({file1:o.file1,file2:o.file2,sharedSymbols:o.shared}))}function In(e,t={}){let{scope:n,maxDepth:r=10}=t,i=Y(e,n),s=[],o=new Set,a=new Set,l=[];function c(d,m){if(m>r)return;if(a.has(d)){let p=l.indexOf(d);if(p!==-1){let f=l.slice(p).concat(d),y=f.indexOf(f.reduce((F,T)=>F<T?F:T)),L=[...f.slice(y,-1),...f.slice(0,y),f[y]],k=L.join(" -> ");u.has(k)||(u.add(k),s.push({path:L,kind:Th(L)}))}return}if(o.has(d))return;o.add(d),a.add(d),l.push(d);let g=i.get(d);if(g)for(let p of g)c(p,m+1);l.pop(),a.delete(d)}let u=new Set;for(let d of i.keys())o.has(d)||c(d,0);return s.sort((d,m)=>d.kind!==m.kind?d.kind==="real"?-1:1:d.path.length-m.path.length),s}function Th(e){for(let r of e){let i=ee(r);if(i==="test"||i==="barrel"||i==="entry")return"module-hierarchy"}if(e.length!==3)return"real";let[t,n]=e;return!t||!n?"real":xn(t)||xn(n)||qo(t,n)||qo(n,t)||zo(t,n)||zo(n,t)||ee(t)==="entry"||ee(n)==="entry"?"module-hierarchy":"real"}function qo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=t.replace(/\.rs$/,"/");return e.startsWith(n)?!e.slice(n.length).includes("/"):!1}function zo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=e.replace(/\.rs$/,""),r=t.replace(/\.rs$/,"");if(n===r+"_tests"||n===r+"/tests")return!0;let i=e.split("/"),s=t.split("/");if(i.length===s.length&&i.includes("tests")&&s.includes("src")){let o=i[i.length-1],a=s[s.length-1];if(o&&o===a)return!0}return!1}function Go(e,t={}){let{limit:n=20,scope:r,minFanIn:i=2,minFanOut:s=2}=t;return new C(e).productionCallableDefinitions({scope:r,requireCallableSymbol:!0,includeSuppressed:!0}).map(l=>$h(e,l)).filter(l=>l.fanIn>=i&&l.fanOut>=s).sort((l,c)=>c.score-l.score||c.fanIn-l.fanIn).slice(0,n)}function $h(e,t){let n=new Set(ie(e,t,{limit:500}).map(i=>i.file)).size,r=new Set(Z(e,t,{limit:500}).filter(i=>i.file!==t.relativePath).map(i=>`${i.symbol}|${i.file}`)).size;return{symbol:t.symbol,shortName:h(t.symbol),fanIn:n,fanOut:r,score:n*r,definedIn:t.relativePath}}function Rn(e,t={}){let{scope:n,minLoc:r=3}=t,i=new C(e),s=i.productionCallableDefinitions({scope:n,minLoc:r,excludeEntrySurfaces:!0,excludeRustTraitImplMembers:!0,includeSuppressed:!0}),o=i.crossFileCallerMap(s),a=i.sourceFallbackCallerFiles(s),l=new Set([...o.keys(),...a.keys()]),c=new Map;for(let p of s){let f=D(p.symbol);if(!f)continue;let y=c.get(f)??[];y.push(p.symbolId),c.set(f,y)}let u=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of u){if(e.isIgnored(p.relative_path)||M(p.relative_path)!=="rust")continue;let f=st(e,p.relative_path);for(let y of f){let L=c.get(y);if(L)for(let k of L)l.add(k)}}let d=new Map(s.map(p=>[p.symbolId,p.symbol])),m=i.calleeMap(s,{additive:!0}),g=new Set([...m.entries()].filter(([p,f])=>{let y=d.get(p);return f.some(L=>L.symbol!==y)}).map(([p])=>p));return s.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:h(p.symbol),relativePath:p.relativePath,startLine:p.startLine,endLine:p.endLine,loc:p.endLine-p.startLine+1}))}var wr={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"},kr=new Map;for(let[e,t]of Object.entries(wr))kr.set(t.toLowerCase(),Number(e));function Ah(e){let t=parseInt(e,10);if(!isNaN(t))return t;let n=e.toLowerCase(),r=kr.get(n);if(r!==void 0)return r;for(let[i,s]of kr)if(i.includes(n))return s;return null}function Ko(e,t,n={}){let{scope:r,limit:i=100}=n,s=Ah(t);return s===null?[]:Qo(e,r).map(a=>({row:a,resolvedKind:Xo(a)})).filter(a=>a.resolvedKind===s).slice(0,i).map(({row:a,resolvedKind:l})=>({symbol:a.symbol,shortName:h(a.symbol),kind:l,kindName:wr[l]??"Unknown",relativePath:a.relative_path,startLine:a.start_line,endLine:a.end_line}))}function Yo(e,t={}){let n=new Map;for(let r of Qo(e,t.scope)){let i=Xo(r);i===null||i===0||n.set(i,(n.get(i)??0)+1)}return[...n.entries()].sort((r,i)=>i[1]-r[1]||r[0]-i[0]).map(([r,i])=>({kind:r,kindName:wr[r]??"Unknown",count:i}))}function Qo(e,t){return oe(e,{scope:t}).map(jh)}function jh(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 Xo(e){return e.kind!==null&&e.kind!==0?Bh(e.kind,e.symbol,e.documentation):Wh(e.symbol,e.documentation,e.enclosing_symbol)}function Bh(e,t,n){let r=(n??"").toLowerCase();if(V(t)==="type"){if(r.includes("type "))return 76;if(r.includes("interface "))return 27;if(r.includes("struct "))return 68;if(r.includes("trait "))return 73;if(r.includes("class "))return 9}return e}function Wh(e,t,n){let r=H(e);if("kind"in r)return null;let i=r.descriptors,s=i[i.length-2]??null,o=V(e),a=(t??"").toLowerCase();return o==="type"?a.includes("type ")?76:a.includes("interface ")?27:a.includes("struct ")?68:a.includes("trait ")?73:(a.includes("class "),9):o==="method"?s?.suffix==="type"?33:23:o==="namespace"?39:o!=="term"?null:a.includes("async def ")||a.includes("def ")?23:(n?V(n):s?.suffix??null)==="type"?21:83}function Zo(e,t={}){let{limit:n=10,scope:r,minDepth:i=3}=t,s=Y(e,r),o=new Map,a=[],l=new Map,c=new Map,u=new Set,d=[],m=0;for(let R of s.keys()){if(l.has(R))continue;let _=[],O=(s.get(R)??new Set).values();for(l.set(R,m),c.set(R,m),m+=1,d.push(R),u.add(R),_.push({node:R,iter:O,pendingChild:null});_.length>0;){let N=_[_.length-1];if(N.pendingChild!==null){let Ke=N.pendingChild;N.pendingChild=null,c.set(N.node,Math.min(c.get(N.node),c.get(Ke)))}let z=N.iter.next();if(z.done){if(c.get(N.node)===l.get(N.node)){let Ke=[];for(;;){let $t=d.pop();if(u.delete($t),Ke.push($t),o.set($t,a.length),$t===N.node)break}a.push(Ke)}_.pop();continue}let de=z.value;if(l.has(de))u.has(de)&&c.set(N.node,Math.min(c.get(N.node),l.get(de)));else{l.set(de,m),c.set(de,m),m+=1,d.push(de),u.add(de);let Ke=(s.get(de)??new Set).values();N.pendingChild=de,_.push({node:de,iter:Ke,pendingChild:null})}}}let g=new Map,p=new Array(a.length);for(let R=0;R<a.length;R++)p[R]=a[R].length,g.set(R,new Set);for(let[R,_]of s){let O=o.get(R);for(let N of _){let z=o.get(N);z!==O&&g.get(O).add(z)}}let f=new Array(a.length),y=new Array(a.length);for(let R=0;R<a.length;R++){let _=[],O=0;for(let N of g.get(R)){let z=y[N];z>O&&(O=z,_=f[N])}f[R]=[R,..._],y[R]=p[R]+O}function L(R){return f[R]}let k=a.map(R=>[...R].sort()),F=new Set,T=[];for(let R=0;R<a.length;R++){let _=L(R),O=[];for(let z of _)O.push(...k[z]);if(O.length<i)continue;let N=O.join(" ");F.has(N)||(F.add(N),T.push({chain:O,depth:O.length}))}return T.sort((R,_)=>_.depth-R.depth),T.slice(0,n)}function ea(e,t){let n=E(e,t);if(!n)return[];let r=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
807
+ WHERE id = ? LIMIT 1`,n.symbolId);if(!r)return[];let i=[{symbol:r.symbol,shortName:h(r.symbol),depth:0}],s=r.enclosing_symbol,o=1,a=new Set([r.symbol]);for(;s&&!a.has(s)&&o<20;){a.add(s);let d=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",s);if(!d)break;i.push({symbol:d.symbol,shortName:h(d.symbol),depth:o}),s=d.enclosing_symbol,o++}if(i.length>1)return i;let l=H(r.symbol);if("kind"in l)return i;let c=l.descriptors;if(c.length<=1)return i;let u=[i[0]];for(let d=c.length-2,m=1;d>=0;d--,m++){let p=c.slice(0,d+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(":");u.push({symbol:p,shortName:p,depth:m})}return u}function ta(e,t){let n=E(e,t);if(!n)return null;let r=ie(e,n,{limit:50}),i=Hh(Z(e,n,{limit:50,additive:!0,callableOnly:!0}));return{symbol:n.symbol,shortName:h(n.symbol),callers:r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file})),callees:i.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file}))}}function Hh(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function wt(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function Pt(e,t){let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function na(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let i of e)t.has(i)&&(n+=1);let r=e.size+t.size-n;return r===0?0:n/r}function Pr(e){let t=e.length;if(t===0)return new Map;let n=new Map;for(let i of e)for(let s of i)n.set(s,(n.get(s)??0)+1);let r=new Map;for(let[i,s]of n)r.set(i,Math.log(t/s));return r}function Vh(e){let t=[...e.values()].sort((r,i)=>r-i);if(t.length===0)return 0;let n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function ra(e,t,n){let r=wt(e,t);if(r.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let i=0,s=0,o=0,a=new Set([...e,...t]);for(let g of a){let p=n.get(g)??0,f=e.has(g)?p:0,y=t.has(g)?p:0;i+=f*y,s+=f*f,o+=y*y}let l=Math.sqrt(s)*Math.sqrt(o),c=l>0?i/l:0,u=Vh(n),d=[],m=[];for(let g of r)(n.get(g)??0)>=u?d.push(g):m.push(g);return d.sort((g,p)=>(n.get(p)??0)-(n.get(g)??0)),{similarity:c,significantShared:d,trivialShared:m}}function ia(e,t,n={}){let{minSimilarity:r=.4,limit:i=20}=n,s=qh(e,t);if(!s)return[];if(!W(s.symbol))return[];let o=Uh(e,s,r);return o.length>0?o.slice(0,i):Gh(e,t,{minSimilarity:r,limit:i})}function Uh(e,t,n){let r=oa(e,{minCallees:3,excludeSymbol:t.symbol}),i=Pr([t,...r].map(o=>o.callees)),s=[];for(let o of r){if(o.callees.size<3)continue;let a=sa(t,o,i,{minSimilarity:n,requireSignificantShared:1,requireSharedCount:0});a&&s.push(a)}return s.sort((o,a)=>a.similarity-o.similarity),s}function sa(e,t,n,r){let{similarity:i,significantShared:s}=ra(e.callees,t.callees,n);if(i<r.minSimilarity)return null;let o=wt(e.callees,t.callees).size;if(s.length<r.requireSignificantShared&&o<r.requireSharedCount)return null;let a=s.length>0?s:[...wt(e.callees,t.callees)];return{symbolA:e.symbol,shortNameA:h(e.symbol),fileA:e.file,symbolB:t.symbol,shortNameB:h(t.symbol),fileB:t.file,similarity:i,similarityBasis:"callees",sharedCallees:a.map(h),uniqueToA:[...Pt(e.callees,t.callees)].map(h),uniqueToB:[...Pt(t.callees,e.callees)].map(h)}}function Cn(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,minCallees:s=4,crossFileOnly:o=!1}=t,a=oa(e,{minCallees:s,scope:i}),l=Pr(a.map(p=>p.callees)),c=new Map;for(let p of a)for(let f of p.callees)c.set(f,(c.get(f)??0)+1);let u=Math.max(8,Math.ceil(Math.sqrt(a.length))),d=new Map;for(let p=0;p<a.length;p+=1)for(let f of a[p].callees){if((c.get(f)??0)>u)continue;let y=d.get(f);y||(y=[],d.set(f,y)),y.push(p)}let m=[],g=new Set;e:for(let p=0;p<a.length;p+=1){let f=a[p],y=new Set;for(let L of f.callees){let k=d.get(L);if(k)for(let F of k)F>p&&y.add(F)}for(let L of y){let k=`${p}|${L}`;if(g.has(k))continue;g.add(k);let F=a[L];if(o&&f.file===F.file)continue;if(f.paramCount>=0&&F.paramCount>=0){let R=Math.abs(f.paramCount-F.paramCount),_=Math.max(2,Math.ceil(Math.max(f.paramCount,F.paramCount)*.5));if(R>_)continue}let T=sa(f,F,l,{minSimilarity:n,requireSignificantShared:2,requireSharedCount:4});if(T&&(m.push(T),m.length>r*5))break e}}return m.sort((p,f)=>f.similarity-p.similarity),m.slice(0,r)}var Jh=["ScipDatabase#all","ScipDatabase#get","ScipDatabase#prepare","ScipDatabase#pathExclusionsFor","ScipDatabase#isIgnored","ScipDatabase#symbolNoiseFor","PerDbValue#get","PerDbValue#has",":storage:db:ScipDatabase:all",":storage:db:ScipDatabase:get",":storage:db:ScipDatabase:prepare",":storage:db:ScipDatabase:pathExclusionsFor",":storage:db:ScipDatabase:isIgnored",":storage:db:ScipDatabase:symbolNoiseFor",":storage:per-db-cache:PerDbValue:get",":storage:per-db-cache:PerDbValue:has"];function qh(e,t){let n=E(e,t),r=new C(e);if(!n)return null;let i=Z(e,n);return{symbol:n.symbol,file:n.relativePath,callees:aa(i.map(s=>s.symbol)),paramCount:r.callableSignature(n)?.paramCount??-1}}function oa(e,t){let{minCallees:n,scope:r,excludeSymbol:i}=t,s=new C(e),o=s.productionCallableDefinitions({scope:r,minLoc:5,excludeSymbol:i}),a=s.calleeMap(o);return o.map(l=>({symbol:l.symbol,file:l.relativePath,callees:aa((a.get(l.symbolId)??[]).map(c=>c.symbol)),paramCount:s.callableSignature(l)?.paramCount??-1})).filter(l=>l.callees.size>=n)}function aa(e){return new Set([...e].filter(t=>!zh(t)))}function zh(e){return Jh.some(t=>e.includes(t))}function Gh(e,t,n){let r=Kh(e,t);if(!r||r.tokens.size<3)return[];let i=n.minSimilarity>=.5?n.minSimilarity:.3,s=[];for(let o of Qh(e)){if(o.symbol===r.symbol||o.tokens.size<3)continue;let a=wt(r.tokens,o.tokens);if(a.size<2)continue;let l=new Set([...r.tokens,...o.tokens]),c=l.size>0?a.size/l.size:0;c<i||s.push({symbolA:r.symbol,shortNameA:h(r.symbol),fileA:r.file,symbolB:o.symbol,shortNameB:h(o.symbol),fileB:o.file,similarity:c,similarityBasis:"source-tokens",sharedCallees:[...a].sort(),uniqueToA:[...Pt(r.tokens,o.tokens)].sort(),uniqueToB:[...Pt(o.tokens,r.tokens)].sort()})}return s.sort((o,a)=>a.similarity-o.similarity||o.shortNameB.localeCompare(a.shortNameB)),s.slice(0,n.limit)}function Kh(e,t){let n=E(e,t);if(!n||!W(n.symbol))return null;let r=Yh(e,n);return r?{symbol:n.symbol,file:n.relativePath,tokens:r}:null}function Yh(e,t){let n=D(t.symbol),r=la(e,t.relativePath,t.startLine,t.endLine,n),i=ca(r,n);return i.size>0?i:null}function Qh(e){let t=new C(e);return t.scopedDefinitions().filter(n=>n.isFunctionLike).filter(n=>t.fileKind(n.relativePath)!=="test").filter(n=>!ke(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:ca(la(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function la(e,t,n,r,i){let s=w(e,t);if(!s)return"";let o=s.split(`
808
808
  `);if(r>=n&&r-n<=12)return o.slice(n,r+1).join(`
809
- `);let a=[new RegExp(`\\bdef\\s+${Ot(i)}\\b`),new RegExp(`\\bfun\\s+${Ot(i)}\\b`),new RegExp(`\\bfn\\s+${Ot(i)}\\b`),new RegExp(`\\bfunction\\s+${Ot(i)}\\b`),new RegExp(`\\b${Ot(i)}\\s*\\(`)],l=o.findIndex(c=>a.some(d=>d.test(c)));if(l>=0){let c=l;for(let d=l+1;d<o.length&&d<=l+8;d++){let u=o[d]??"";if(d>l&&Fh(u)||(c=d,u.trim()===""&&d>l+1))break}return o.slice(l,c+1).join(`
809
+ `);let a=[new RegExp(`\\bdef\\s+${Ot(i)}\\b`),new RegExp(`\\bfun\\s+${Ot(i)}\\b`),new RegExp(`\\bfn\\s+${Ot(i)}\\b`),new RegExp(`\\bfunction\\s+${Ot(i)}\\b`),new RegExp(`\\b${Ot(i)}\\s*\\(`)],l=o.findIndex(c=>a.some(u=>u.test(c)));if(l>=0){let c=l;for(let u=l+1;u<o.length&&u<=l+8;u++){let d=o[u]??"";if(u>l&&Zh(d)||(c=u,d.trim()===""&&u>l+1))break}return o.slice(l,c+1).join(`
810
810
  `)}return o.slice(n,Math.min(o.length,n+8)).join(`
811
- `)}function ra(e,t){if(!e)return new Set;let n=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"]),r=Mh(t),s=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(o=>o.trim()).filter(o=>o.length>1).filter(o=>!n.has(o)).filter(o=>!r.has(o));return new Set(s)}function Mh(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(t=>t.toLowerCase()).filter(t=>t.length>1))}function Fh(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function Ot(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function sa(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,filePattern:s}=t,o=t.minDeps??(s?1:3),a=Th(e,{scope:i,minDeps:o}),l=[];if(s){let c=a.find(d=>d.file.includes(s));if(!c)return[];for(let d of a){if(d.file===c.file)continue;let u=ia(c,d,n);u&&l.push(u)}}else for(let c=0;c<a.length;c++){for(let d=c+1;d<a.length;d++){let u=ia(a[c],a[d],n);u&&l.push(u)}if(l.length>r*5)break}return l.sort((c,d)=>d.similarity-c.similarity),l.slice(0,r)}function Th(e,t){let{scope:n,minDeps:r}=t,i=Q(e,n),s=$h(i),o=[];for(let[a,l]of i)l.size>=r&&o.push({file:a,deps:new Set([...l].filter(c=>!s.has(c)))});return o}function $h(e){let t=new Set,n=e.size;if(n===0)return t;let r=new Map;for(let i of e.values())for(let s of i)r.set(s,(r.get(s)??0)+1);for(let[i,s]of r)s>=5&&s/n>.3&&t.add(i);return t}function ia(e,t,n){let r=new Set;for(let a of e.deps)t.deps.has(a)&&r.add(a);if(r.size<3||e.deps.size<4||t.deps.size<4)return null;let i=Qo(e.deps,t.deps);if(i<n)return null;let s=[];for(let a of e.deps)t.deps.has(a)||s.push(a);let o=[];for(let a of t.deps)e.deps.has(a)||o.push(a);return{fileA:e.file,fileB:t.file,similarity:i,sharedDeps:[...r],uniqueToA:s,uniqueToB:o}}function aa(e,t={}){let{minSimilarity:n=.5,limit:r=15,scope:i,minChainLength:s=3,maxChainLength:o=8}=t,a=Q(e,i),l=Jh(a,s,o);if(l.length===0)return[];let c=Ah(l);return c.length<2?[]:Uh(Wh(c,n,r),r)}function Ah(e){let t=jh(e),n=[];for(let r of e){let i=r.filter(s=>!t.has(s));i.length>=2&&n.push({original:r,filtered:i})}return n}function jh(e){let{nodeFreq:t,tailFreq:n}=Bh(e),r=e.length*.9,i=e.length*.8,s=new Set;for(let[a,l]of t)l>r&&s.add(a);for(let[a,l]of n)l>i&&s.add(a);let o=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let a of t.keys()){let l=a.split("/").pop()??"";o.includes(l)&&s.add(a)}return s}function Bh(e){let t=new Map,n=new Map;for(let r of e){let i=new Set;for(let s of r)i.has(s)||(t.set(s,(t.get(s)??0)+1),i.add(s));for(let s=Math.max(0,r.length-2);s<r.length;s++)n.set(r[s],(n.get(r[s])??0)+1)}return{nodeFreq:t,tailFreq:n}}function Wh(e,t,n){let r=[];for(let i=0;i<e.length;i++){for(let s=i+1;s<e.length;s++){let o=Hh(e[i],e[s],t);o&&r.push(o)}if(r.length>n*10)break}return r.sort((i,s)=>Math.abs(s.similarity-i.similarity)>.01?s.similarity-i.similarity:i.divergencePoints.length-s.divergencePoints.length),r}function Hh(e,t,n){if(!Vh(e.filtered,t.filtered))return null;let{distance:r,ops:i}=qh(e.filtered,t.filtered),s=Math.max(e.filtered.length,t.filtered.length);if(s===0)return null;let o=1-r/s;if(o<n||r===0)return null;let a=i.filter(c=>c.type==="substitute").map(c=>({index:c.indexA,nodeA:e.filtered[c.indexA],nodeB:t.filtered[c.indexB]}));return a.length===0||i.filter(c=>c.type==="match").length<2?null:{chainA:e.original,chainB:t.original,similarity:o,editDistance:r,divergencePoints:a,commonPrefix:zh(e.original,t.original),commonSuffix:Gh(e.original,t.original)}}function Vh(e,t){let n=new Set(e);return t.some(r=>n.has(r))}function Uh(e,t){let n=[];for(let r of e)if(n.some(s=>oa(r.chainA,s.chainA)&&oa(r.chainB,s.chainB))||n.push(r),n.length>=t)break;return n}function Jh(e,t,n){let r=[];for(let s of e.keys()){if(r.length>=500)break;la(e,s,[s],new Set([s]),t,n,r,500)}return r}function la(e,t,n,r,i,s,o,a){if(o.length>=a)return;if(n.length>=s){n.length>=i&&o.push([...n]);return}let l=e.get(t);if(!l||l.size===0){n.length>=i&&o.push([...n]);return}let c=!1;for(let d of l)if(!r.has(d)&&(r.add(d),n.push(d),la(e,d,n,r,i,s,o,a),n.pop(),r.delete(d),c=!0,o.length>=a))return;!c&&n.length>=i&&o.push([...n])}function qh(e,t){let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let l=0;l<=n;l++)i[l][0]=l;for(let l=0;l<=r;l++)i[0][l]=l;for(let l=1;l<=n;l++)for(let c=1;c<=r;c++)e[l-1]===t[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 s=[],o=n,a=r;for(;o>0||a>0;)o>0&&a>0&&e[o-1]===t[a-1]?(s.unshift({type:"match",indexA:o-1,indexB:a-1}),o--,a--):o>0&&a>0&&i[o][a]===i[o-1][a-1]+1?(s.unshift({type:"substitute",indexA:o-1,indexB:a-1}),o--,a--):a>0&&i[o][a]===i[o][a-1]+1?(s.unshift({type:"insert",indexA:o,indexB:a-1}),a--):(s.unshift({type:"delete",indexA:o-1,indexB:a}),o--);return{distance:i[n][r],ops:s}}function zh(e,t){let n=[];for(let r=0;r<Math.min(e.length,t.length)&&e[r]===t[r];r++)n.push(e[r]);return n}function Gh(e,t){let n=[],r=e.length-1,i=t.length-1;for(;r>=0&&i>=0&&e[r]===t[i];)n.unshift(e[r]),r--,i--;return n}function oa(e,t){if(e.length>t.length)return!1;let n=t.join("\u2192"),r=e.join("\u2192");return n.includes(r)}function Nn(e,t={}){let{scope:n,minLoc:r=10,minCallees:i=6,limit:s=20}=t,o=new C(e),a=o.productionCallableDefinitions({scope:n,minLoc:r,excludeTypesFiles:!0,requireFunctionLikeSymbol:!0,sortByLocDesc:!0}),l=o.calleeMap(a),c=[];for(let d of a){let u=Kh(d,l.get(d.symbolId)??[],i);u&&c.push(u)}return c.sort((d,u)=>u.clusters.length-d.clusters.length||u.loc-d.loc),c.slice(0,s)}function Kh(e,t,n){let r=new Set(t.map(a=>a.symbol));if(r.size<n)return null;let i=Qh(r,t),s=Yh(r,i);if(s.length<2)return null;let o=Xh(s,i);return o.length===0?null:{symbol:e.symbol,shortName:h(e.symbol),relativePath:e.relativePath,startLine:e.startLine,endLine:e.endLine,loc:ey(e),totalCallees:r.size,clusters:o}}function Qh(e,t){let n=new Map;for(let i of e)n.set(i,new Set);let r=new Map;for(let i of t){let s=r.get(i.chunkId);s||(s=new Set,r.set(i.chunkId,s)),s.add(i.symbol)}for(let i of r.values()){let s=[...i];for(let o=0;o<s.length;o++)for(let a=o+1;a<s.length;a++)n.get(s[o]).add(s[a]),n.get(s[a]).add(s[o])}return n}function Yh(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i))continue;let s=new Set,o=[i];for(;o.length>0;){let a=o.pop();if(!n.has(a)){n.add(a),s.add(a);for(let l of t.get(a)??[])n.has(l)||o.push(l)}}r.push(s)}return r}function Xh(e,t){return e.filter(n=>n.size>=3).map(n=>Zh(n,e,t)).filter(n=>n.isolation>.5).sort((n,r)=>r.isolation-n.isolation)}function Zh(e,t,n){let r=new Set;for(let a of t)if(a!==e)for(let l of a)r.add(l);let i=0;for(let a of e)for(let l of n.get(a)??[])r.has(l)&&i++;let s=e.size*r.size,o=s>0?1-i/s:1;return{callees:[...e].map(h),isolation:o}}function ey(e){return e.endLine-e.startLine+1}function ca(e,t,n={}){let{maxDepth:r=5,scope:i}=n,s=L(e,t);if(!s)return[];let o=[],a=new Set([s.symbolId]),l=new Set,c=[s];for(let d=1;d<=r&&c.length!==0;d++){let u=[];for(let m of c)for(let f of ty(e,m,i)){let p=`${f.file}|${f.shortName}`;if(f.symbolId!==null){if(a.has(f.symbolId))continue;a.add(f.symbolId)}else if(l.has(p))continue;l.add(p),o.push({symbol:f.symbol,shortName:f.shortName,file:f.file,depth:d}),f.symbolId!==null&&f.symbolMatch&&u.push(f.symbolMatch)}c=u}return o.sort((d,u)=>d.depth-u.depth||d.file.localeCompare(u.file)),o}function ty(e,t,n){let r=new C(e),i=ie(e,t,{limit:500}).filter(u=>!e.isIgnored(u.file)).filter(u=>!n||u.file.includes(n)),s=new Set(i.map(u=>u.file)),o=r.crossFileCallerMap().get(t.symbolId)??new Set,a=[];for(let u of o){if(s.has(u)||e.isIgnored(u)||n&&!u.includes(n))continue;let m=r.definitionsForFile(u),f=m.length>0?ae(m,m[0].startLine):null;a.push({symbol:f?.symbol??u,file:u})}let l=[...i,...a],c=[],d=new Set;for(let u of l){let m=it(e,u.symbol);if(!m){let p=`${u.file}|${u.symbol}`;if(d.has(p))continue;d.add(p),c.push({symbolId:null,symbol:u.symbol,shortName:h(u.symbol),file:u.file,symbolMatch:null});continue}if(m.symbolId===t.symbolId||e.isIgnored(m.relativePath)||!ny(m.symbol))continue;let f=`${m.symbolId}|${m.relativePath}`;d.has(f)||(d.add(f),c.push({symbolId:m.symbolId,symbol:m.symbol,shortName:h(m.symbol),file:m.relativePath,symbolMatch:m}))}return c}function ny(e){let t=V(e);return t==="method"||t==="type"||e.endsWith("().")}function ua(e,t){let n=G(e,t);if(!n)return null;let r=ry(e,n);if(!r||e.isIgnored(r.relative_path))return null;let i=[],s=0;for(let o of iy(e,r.relative_path)){let a=sy(e,r,o);s+=a,i.push({symbol:o.symbol,shortName:h(o.symbol),startLine:o.startLine,endLine:o.endLine,externalConsumers:a,riskLevel:oy(a)})}return{file:r.relative_path,symbols:i,totalExternalConsumers:s}}function ry(e,t){return e.get(`SELECT id, relative_path FROM documents
811
+ `)}function ca(e,t){if(!e)return new Set;let n=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"]),r=Xh(t),s=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(o=>o.trim()).filter(o=>o.length>1).filter(o=>!n.has(o)).filter(o=>!r.has(o));return new Set(s)}function Xh(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(t=>t.toLowerCase()).filter(t=>t.length>1))}function Zh(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function Ot(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function da(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,filePattern:s}=t,o=t.minDeps??(s?1:3),a=ey(e,{scope:i,minDeps:o}),l=[];if(s){let c=a.find(u=>u.file.includes(s));if(!c)return[];for(let u of a){if(u.file===c.file)continue;let d=ua(c,u,n);d&&l.push(d)}}else for(let c=0;c<a.length;c++){for(let u=c+1;u<a.length;u++){let d=ua(a[c],a[u],n);d&&l.push(d)}if(l.length>r*5)break}return l.sort((c,u)=>u.similarity-c.similarity),l.slice(0,r)}function ey(e,t){let{scope:n,minDeps:r}=t,i=Y(e,n),s=ty(i),o=[];for(let[a,l]of i)l.size>=r&&o.push({file:a,deps:new Set([...l].filter(c=>!s.has(c)))});return o}function ty(e){let t=new Set,n=e.size;if(n===0)return t;let r=new Map;for(let i of e.values())for(let s of i)r.set(s,(r.get(s)??0)+1);for(let[i,s]of r)s>=5&&s/n>.3&&t.add(i);return t}function ua(e,t,n){let r=new Set;for(let a of e.deps)t.deps.has(a)&&r.add(a);if(r.size<3||e.deps.size<4||t.deps.size<4)return null;let i=na(e.deps,t.deps);if(i<n)return null;let s=[];for(let a of e.deps)t.deps.has(a)||s.push(a);let o=[];for(let a of t.deps)e.deps.has(a)||o.push(a);return{fileA:e.file,fileB:t.file,similarity:i,sharedDeps:[...r],uniqueToA:s,uniqueToB:o}}function pa(e,t={}){let{minSimilarity:n=.5,limit:r=15,scope:i,minChainLength:s=3,maxChainLength:o=8}=t,a=Y(e,i),l=cy(a,s,o);if(l.length===0)return[];let c=ny(l);return c.length<2?[]:ly(sy(c,n,r),r)}function ny(e){let t=ry(e),n=[];for(let r of e){let i=r.filter(s=>!t.has(s));i.length>=2&&n.push({original:r,filtered:i})}return n}function ry(e){let{nodeFreq:t,tailFreq:n}=iy(e),r=e.length*.9,i=e.length*.8,s=new Set;for(let[a,l]of t)l>r&&s.add(a);for(let[a,l]of n)l>i&&s.add(a);let o=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let a of t.keys()){let l=a.split("/").pop()??"";o.includes(l)&&s.add(a)}return s}function iy(e){let t=new Map,n=new Map;for(let r of e){let i=new Set;for(let s of r)i.has(s)||(t.set(s,(t.get(s)??0)+1),i.add(s));for(let s=Math.max(0,r.length-2);s<r.length;s++)n.set(r[s],(n.get(r[s])??0)+1)}return{nodeFreq:t,tailFreq:n}}function sy(e,t,n){let r=[];for(let i=0;i<e.length;i++){for(let s=i+1;s<e.length;s++){let o=oy(e[i],e[s],t);o&&r.push(o)}if(r.length>n*10)break}return r.sort((i,s)=>Math.abs(s.similarity-i.similarity)>.01?s.similarity-i.similarity:i.divergencePoints.length-s.divergencePoints.length),r}function oy(e,t,n){if(!ay(e.filtered,t.filtered))return null;let{distance:r,ops:i}=uy(e.filtered,t.filtered),s=Math.max(e.filtered.length,t.filtered.length);if(s===0)return null;let o=1-r/s;if(o<n||r===0)return null;let a=i.filter(c=>c.type==="substitute").map(c=>({index:c.indexA,nodeA:e.filtered[c.indexA],nodeB:t.filtered[c.indexB]}));return a.length===0||i.filter(c=>c.type==="match").length<2?null:{chainA:e.original,chainB:t.original,similarity:o,editDistance:r,divergencePoints:a,commonPrefix:dy(e.original,t.original),commonSuffix:my(e.original,t.original)}}function ay(e,t){let n=new Set(e);return t.some(r=>n.has(r))}function ly(e,t){let n=[];for(let r of e)if(n.some(s=>ma(r.chainA,s.chainA)&&ma(r.chainB,s.chainB))||n.push(r),n.length>=t)break;return n}function cy(e,t,n){let r=[];for(let s of e.keys()){if(r.length>=500)break;fa(e,s,[s],new Set([s]),t,n,r,500)}return r}function fa(e,t,n,r,i,s,o,a){if(o.length>=a)return;if(n.length>=s){n.length>=i&&o.push([...n]);return}let l=e.get(t);if(!l||l.size===0){n.length>=i&&o.push([...n]);return}let c=!1;for(let u of l)if(!r.has(u)&&(r.add(u),n.push(u),fa(e,u,n,r,i,s,o,a),n.pop(),r.delete(u),c=!0,o.length>=a))return;!c&&n.length>=i&&o.push([...n])}function uy(e,t){let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let l=0;l<=n;l++)i[l][0]=l;for(let l=0;l<=r;l++)i[0][l]=l;for(let l=1;l<=n;l++)for(let c=1;c<=r;c++)e[l-1]===t[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 s=[],o=n,a=r;for(;o>0||a>0;)o>0&&a>0&&e[o-1]===t[a-1]?(s.unshift({type:"match",indexA:o-1,indexB:a-1}),o--,a--):o>0&&a>0&&i[o][a]===i[o-1][a-1]+1?(s.unshift({type:"substitute",indexA:o-1,indexB:a-1}),o--,a--):a>0&&i[o][a]===i[o][a-1]+1?(s.unshift({type:"insert",indexA:o,indexB:a-1}),a--):(s.unshift({type:"delete",indexA:o-1,indexB:a}),o--);return{distance:i[n][r],ops:s}}function dy(e,t){let n=[];for(let r=0;r<Math.min(e.length,t.length)&&e[r]===t[r];r++)n.push(e[r]);return n}function my(e,t){let n=[],r=e.length-1,i=t.length-1;for(;r>=0&&i>=0&&e[r]===t[i];)n.unshift(e[r]),r--,i--;return n}function ma(e,t){if(e.length>t.length)return!1;let n=t.join("\u2192"),r=e.join("\u2192");return n.includes(r)}function vn(e,t={}){let{scope:n,minLoc:r=10,minCallees:i=6,limit:s=20}=t,o=new C(e),a=o.productionCallableDefinitions({scope:n,minLoc:r,excludeTypesFiles:!0,requireFunctionLikeSymbol:!0,sortByLocDesc:!0}),l=o.calleeMap(a),c=[];for(let u of a){let d=py(u,l.get(u.symbolId)??[],i);d&&c.push(d)}return c.sort((u,d)=>d.clusters.length-u.clusters.length||d.loc-u.loc),c.slice(0,s)}function py(e,t,n){let r=new Set(t.map(a=>a.symbol));if(r.size<n)return null;let i=fy(r,t),s=gy(r,i);if(s.length<2)return null;let o=hy(s,i);return o.length===0?null:{symbol:e.symbol,shortName:h(e.symbol),relativePath:e.relativePath,startLine:e.startLine,endLine:e.endLine,loc:by(e),totalCallees:r.size,clusters:o}}function fy(e,t){let n=new Map;for(let i of e)n.set(i,new Set);let r=new Map;for(let i of t){let s=r.get(i.chunkId);s||(s=new Set,r.set(i.chunkId,s)),s.add(i.symbol)}for(let i of r.values()){let s=[...i];for(let o=0;o<s.length;o++)for(let a=o+1;a<s.length;a++)n.get(s[o]).add(s[a]),n.get(s[a]).add(s[o])}return n}function gy(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i))continue;let s=new Set,o=[i];for(;o.length>0;){let a=o.pop();if(!n.has(a)){n.add(a),s.add(a);for(let l of t.get(a)??[])n.has(l)||o.push(l)}}r.push(s)}return r}function hy(e,t){return e.filter(n=>n.size>=3).map(n=>yy(n,e,t)).filter(n=>n.isolation>.5).sort((n,r)=>r.isolation-n.isolation)}function yy(e,t,n){let r=new Set;for(let a of t)if(a!==e)for(let l of a)r.add(l);let i=0;for(let a of e)for(let l of n.get(a)??[])r.has(l)&&i++;let s=e.size*r.size,o=s>0?1-i/s:1;return{callees:[...e].map(h),isolation:o}}function by(e){return e.endLine-e.startLine+1}function ga(e,t,n={}){let{maxDepth:r=5,scope:i}=n,s=E(e,t);if(!s)return[];let o=[],a=new Set([s.symbolId]),l=new Set,c=[s];for(let u=1;u<=r&&c.length!==0;u++){let d=[];for(let m of c)for(let g of Sy(e,m,i)){let p=`${g.file}|${g.shortName}`;if(g.symbolId!==null){if(a.has(g.symbolId))continue;a.add(g.symbolId)}else if(l.has(p))continue;l.add(p),o.push({symbol:g.symbol,shortName:g.shortName,file:g.file,depth:u}),g.symbolId!==null&&g.symbolMatch&&d.push(g.symbolMatch)}c=d}return o.sort((u,d)=>u.depth-d.depth||u.file.localeCompare(d.file)),o}function Sy(e,t,n){let r=new C(e),i=ie(e,t,{limit:500}).filter(d=>!e.isIgnored(d.file)).filter(d=>!n||d.file.includes(n)),s=new Set(i.map(d=>d.file)),o=r.crossFileCallerMap().get(t.symbolId)??new Set,a=[];for(let d of o){if(s.has(d)||e.isIgnored(d)||n&&!d.includes(n))continue;let m=r.definitionsForFile(d),g=m.length>0?ae(m,m[0].startLine):null;a.push({symbol:g?.symbol??d,file:d})}let l=[...i,...a],c=[],u=new Set;for(let d of l){let m=it(e,d.symbol);if(!m){let p=`${d.file}|${d.symbol}`;if(u.has(p))continue;u.add(p),c.push({symbolId:null,symbol:d.symbol,shortName:h(d.symbol),file:d.file,symbolMatch:null});continue}if(m.symbolId===t.symbolId||e.isIgnored(m.relativePath)||!xy(m.symbol))continue;let g=`${m.symbolId}|${m.relativePath}`;u.has(g)||(u.add(g),c.push({symbolId:m.symbolId,symbol:m.symbol,shortName:h(m.symbol),file:m.relativePath,symbolMatch:m}))}return c}function xy(e){let t=V(e);return t==="method"||t==="type"||e.endsWith("().")}function ha(e,t){let n=G(e,t);if(!n)return null;let r=_y(e,n);if(!r||e.isIgnored(r.relative_path))return null;let i=[],s=0;for(let o of Iy(e,r.relative_path)){let a=Ry(e,r,o);s+=a,i.push({symbol:o.symbol,shortName:h(o.symbol),startLine:o.startLine,endLine:o.endLine,externalConsumers:a,riskLevel:Cy(a)})}return{file:r.relative_path,symbols:i,totalExternalConsumers:s}}function _y(e,t){return e.get(`SELECT id, relative_path FROM documents
812
812
  WHERE relative_path = ?
813
813
  ${e.pathExclusionsFor("documents")}
814
- LIMIT 1`,t)??null}function iy(e,t){return new C(e).definitionsForFile(t).sort((n,r)=>n.startLine-r.startLine||n.endLine-r.endLine)}function sy(e,t,n){let r=e.all(`SELECT DISTINCT consumer_d.relative_path
814
+ LIMIT 1`,t)??null}function Iy(e,t){return new C(e).definitionsForFile(t).sort((n,r)=>n.startLine-r.startLine||n.endLine-r.endLine)}function Ry(e,t,n){let r=e.all(`SELECT DISTINCT consumer_d.relative_path
815
815
  FROM mentions m
816
816
  JOIN chunks c ON m.chunk_id = c.id
817
817
  JOIN documents consumer_d ON consumer_d.id = c.document_id
818
818
  WHERE m.symbol_id = ?
819
819
  AND m.role != 1
820
- AND c.document_id != ?`,n.symbolId,t.id),i=dt(e,[n]).get(n.symbolId)??new Set;return new Set([...r.map(s=>s.relative_path),...[...i].filter(s=>s!==t.relative_path)]).size}function oy(e){return e>10?"high":e>0?"medium":"low"}import{execFileSync as Or}from"child_process";function pa(e,t={}){let{base:n="HEAD"}=t,r;try{r=ay(e.config.projectRoot,n)}catch{return da("Unable to compute git diff.")}if(r.length===0)return da("No changed files found.");let i=ly(e,r);if(i.length===0)return{changedFiles:r,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:r.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let s=new C(e),o=new Set(i),a=cy(s,i),l=[],c=new Map;for(let u of a)uy(e,u,i,o,l,c);let d=py(c);return{changedFiles:i,changedSymbols:l,affectedConsumers:d,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:d.length}}}function da(e){return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:e}}}function ay(e,t){let n=Or("git",["diff","--name-only",t],{encoding:"utf-8",cwd:e,timeout:1e4}),r=Or("git",["diff","--name-only","--cached",t],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Or("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([n,r,i].flatMap(s=>s.split(`
821
- `)).map(s=>s.trim()).filter(s=>s.length>0))]}function ly(e,t){let n=[];for(let r of t){let i=e.get(`SELECT relative_path FROM documents
820
+ AND c.document_id != ?`,n.symbolId,t.id),i=ut(e,[n]).get(n.symbolId)??new Set;return new Set([...r.map(s=>s.relative_path),...[...i].filter(s=>s!==t.relative_path)]).size}function Cy(e){return e>10?"high":e>0?"medium":"low"}import{execFileSync as Or}from"child_process";function Sa(e,t={}){let{base:n="HEAD"}=t,r;try{r=vy(e.config.projectRoot,n)}catch{return ya("Unable to compute git diff.")}if(r.length===0)return ya("No changed files found.");let i=Ny(e,r);if(i.length===0)return{changedFiles:r,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:r.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let s=new C(e),o=new Set(i),a=Ey(s,i),l=[],c=new Map;for(let d of a)Dy(e,d,i,o,l,c);let u=wy(c);return{changedFiles:i,changedSymbols:l,affectedConsumers:u,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:u.length}}}function ya(e){return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:e}}}function vy(e,t){let n=Or("git",["diff","--name-only",t],{encoding:"utf-8",cwd:e,timeout:1e4}),r=Or("git",["diff","--name-only","--cached",t],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Or("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([n,r,i].flatMap(s=>s.split(`
821
+ `)).map(s=>s.trim()).filter(s=>s.length>0))]}function Ny(e,t){let n=[];for(let r of t){let i=e.get(`SELECT relative_path FROM documents
822
822
  WHERE relative_path LIKE ?
823
- LIMIT 1`,`%${r}`);i&&!e.isIgnored(i.relative_path)&&n.push(i.relative_path)}return n}function cy(e,t){return t.flatMap(n=>e.definitionsForFile(n)).filter(fy).sort((n,r)=>n.relativePath.localeCompare(r.relativePath)||n.startLine-r.startLine)}function uy(e,t,n,r,i,s){let o=dt(e,[t]).get(t.symbolId)??new Set,a=Math.max(dy(e,t.symbolId),o.size);if(!gy(t,a))return;let l=h(t.symbol);i.push({symbol:t.symbol,shortName:l,file:t.relativePath,fanIn:a});for(let c of my(e,t.symbolId,n))ma(e,r,s,c,l);for(let c of o)ma(e,r,s,c,l)}function dy(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
823
+ LIMIT 1`,`%${r}`);i&&!e.isIgnored(i.relative_path)&&n.push(i.relative_path)}return n}function Ey(e,t){return t.flatMap(n=>e.definitionsForFile(n)).filter(Py).sort((n,r)=>n.relativePath.localeCompare(r.relativePath)||n.startLine-r.startLine)}function Dy(e,t,n,r,i,s){let o=ut(e,[t]).get(t.symbolId)??new Set,a=Math.max(Ly(e,t.symbolId),o.size);if(!Oy(t,a))return;let l=h(t.symbol);i.push({symbol:t.symbol,shortName:l,file:t.relativePath,fanIn:a});for(let c of ky(e,t.symbolId,n))ba(e,r,s,c,l);for(let c of o)ba(e,r,s,c,l)}function Ly(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
824
824
  FROM mentions m
825
825
  JOIN chunks c ON m.chunk_id = c.id
826
826
  WHERE m.symbol_id = ?
827
- AND m.role != 1`,t)?.fan_in??0}function my(e,t,n){return n.length===0?[]:e.all(`SELECT DISTINCT ref_d.relative_path
827
+ AND m.role != 1`,t)?.fan_in??0}function ky(e,t,n){return n.length===0?[]:e.all(`SELECT DISTINCT ref_d.relative_path
828
828
  FROM mentions m
829
829
  JOIN chunks c ON m.chunk_id = c.id
830
830
  JOIN documents ref_d ON c.document_id = ref_d.id
831
831
  WHERE m.symbol_id = ?
832
832
  AND m.role != 1
833
833
  AND ref_d.relative_path NOT IN (${n.map(()=>"?").join(",")})
834
- ${e.pathExclusionsFor("ref_d")}`,t,...n).map(i=>i.relative_path)}function ma(e,t,n,r,i){if(e.isIgnored(r)||t.has(r))return;let s=n.get(r);s||(s=new Set,n.set(r,s)),s.add(i)}function py(e){return[...e.entries()].map(([t,n])=>({file:t,consumedSymbols:n.size})).sort((t,n)=>n.consumedSymbols-t.consumedSymbols)}function fy(e){return!(De(e.symbol)||e.parentTypeName!==null&&!U(e.symbol))}function gy(e,t){return U(e.symbol)||e.isTypeLike?!0:e.parentTypeName===null&&t>0}import Mt from"path";function Ge(e){let n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n.length<=1?"(root)":n.length>=3&&["src","lib","app","server","client"].includes(n[0])?`${n[0]}/${n[1]}`:n[0]}function Mr(e,t){if(e===t)return"ok";let n=En(e),r=En(t);return n&&r?hy(n,r)?"ok":"violation":yy(e,t)}function fa(e,t){let n=En(Ge(e)),r=En(Ge(t));return!!n&&!!r}function En(e){return/^src\/([^/]+)$/.exec(e)?.[1]??null}function hy(e,t){return t==="domain"?!0:e==="domain"?!1:{analysis:new Set(["domain","source","storage","symbols"]),core:new Set(["analysis","domain","resolution","source","storage","symbols"]),"language-parsers":new Set(["domain","resolution","source","storage"]),queries:new Set(["analysis","core","domain","language-parsers","resolution","semantic","source","storage","symbols"]),reindex:new Set(["domain","language-parsers","resolution","runtime","source","storage","symbols"]),resolution:new Set(["domain","source","storage","symbols"]),runtime:new Set(["domain","queries","reindex","resolution","source","storage","symbols"]),semantic:new Set(["domain","resolution","storage","symbols"]),source:new Set(["domain","storage"]),storage:new Set(["domain","source"]),symbols:new Set(["analysis","domain","language-parsers","resolution","semantic","source","storage"])}[e]?.has(t)??!1}function yy(e,t){if(t==="shared")return"ok";let n={app:new Set(["core","shared","ui"]),core:new Set(["shared"]),infra:new Set(["core","shared"]),ui:new Set(["core","shared"])};return n[e]?n[e].has(t)?"ok":"violation":null}function Dn(e,t){let{scope:n,minDeviation:r=5}=t??{},s=new C(e).fileDependencyGraph(n),o=Cy(e,n);return _y([...by(e,s,o),...Sy(s),...xy(s,r)])}function by(e,t,n){let r=[];for(let[i,s]of t){if(Ie(i))continue;let o=n.get(i)??new Set;for(let a of s)if(!Ie(a)&&!o.has(a)){if(ky(e,i,a)||wy(e,i,a)||Py(e,i,a)||Ly(a)||My(e,i,a)||Oy(a))continue;r.push({file:i,kind:"unused-import",description:`Depends on ${a} but references none of its symbols`,dep:a})}}return r}function Sy(e){let t=[],n=Dy(e);for(let[r,i]of e){if(Ie(r))continue;let s=Ge(r);for(let o of i){if(Ie(o))continue;let a=Ge(o);if(s===a)continue;(Mr(s,a)??n.get(`${s}->${a}`))==="violation"&&t.push({file:r,kind:"layer-violation",description:`Imports from ${a}/ (${o}) \u2014 may cross architectural boundary`,dep:o,detail:`${s}/ should not depend on ${a}/`})}}return t}function xy(e,t){let n=[];for(let[r,i]of Iy(e)){let s=i.filter(a=>!Ie(a));if(s.length<t)continue;let o=Ry(e,s);for(let a of s)for(let l of e.get(a)??[])Ie(l)||(o.get(l)??0)===1&&Mt.dirname(l)!==r&&Mt.dirname(l)!==Mt.dirname(r)&&(fa(a,l)||n.push({file:a,kind:"pattern-deviation",description:`Only file in ${r}/ that depends on ${l}`,dep:l}))}return n}function _y(e){return{results:e,unusedImports:e.filter(t=>t.kind==="unused-import").length,layerViolations:e.filter(t=>t.kind==="layer-violation").length,patternDeviations:e.filter(t=>t.kind==="pattern-deviation").length}}function Iy(e){let t=new Map;for(let n of e.keys()){let r=Mt.dirname(n),i=t.get(r);i||(i=[],t.set(r,i)),i.push(n)}return t}function Ry(e,t){let n=new Map;for(let r of t)for(let i of e.get(r)??[])Ie(i)||n.set(i,(n.get(i)??0)+1);return n}function Cy(e,t){let n=new Map;return vy(e,n,t),Ey(e,n),n}function vy(e,t,n){for(let r of Ny(e,n))ga(e,t,r.from_file,r.to_file)}function Ny(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
834
+ ${e.pathExclusionsFor("ref_d")}`,t,...n).map(i=>i.relative_path)}function ba(e,t,n,r,i){if(e.isIgnored(r)||t.has(r))return;let s=n.get(r);s||(s=new Set,n.set(r,s)),s.add(i)}function wy(e){return[...e.entries()].map(([t,n])=>({file:t,consumedSymbols:n.size})).sort((t,n)=>n.consumedSymbols-t.consumedSymbols)}function Py(e){return!(Le(e.symbol)||e.parentTypeName!==null&&!U(e.symbol))}function Oy(e,t){return U(e.symbol)||e.isTypeLike?!0:e.parentTypeName===null&&t>0}import Mt from"path";function Ge(e){let n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n.length<=1?"(root)":n.length>=3&&["src","lib","app","server","client"].includes(n[0])?`${n[0]}/${n[1]}`:n[0]}function Mr(e,t){if(e===t)return"ok";let n=Nn(e),r=Nn(t);return n&&r?My(n,r)?"ok":"violation":Fy(e,t)}function xa(e,t){let n=Nn(Ge(e)),r=Nn(Ge(t));return!!n&&!!r}function Nn(e){return/^src\/([^/]+)$/.exec(e)?.[1]??null}function My(e,t){return t==="domain"?!0:e==="domain"?!1:{analysis:new Set(["domain","source","storage","symbols"]),core:new Set(["analysis","domain","resolution","source","storage","symbols"]),"language-parsers":new Set(["domain","resolution","source","storage"]),queries:new Set(["analysis","core","domain","language-parsers","resolution","semantic","source","storage","symbols"]),reindex:new Set(["domain","language-parsers","resolution","runtime","source","storage","symbols"]),resolution:new Set(["domain","source","storage","symbols"]),runtime:new Set(["domain","queries","reindex","resolution","source","storage","symbols"]),semantic:new Set(["domain","resolution","storage","symbols"]),source:new Set(["domain","storage"]),storage:new Set(["domain","source"]),symbols:new Set(["analysis","domain","language-parsers","resolution","semantic","source","storage"])}[e]?.has(t)??!1}function Fy(e,t){if(t==="shared")return"ok";let n={app:new Set(["core","shared","ui"]),core:new Set(["shared"]),infra:new Set(["core","shared"]),ui:new Set(["core","shared"])};return n[e]?n[e].has(t)?"ok":"violation":null}function En(e,t){let{scope:n,minDeviation:r=5}=t??{},s=new C(e).fileDependencyGraph(n),o=Hy(e,n);return jy([...Ty(e,s,o),...$y(s),...Ay(s,r)])}function Ty(e,t,n){let r=[];for(let[i,s]of t){if(Re(i))continue;let o=n.get(i)??new Set;for(let a of s)if(!Re(a)&&!o.has(a)){if(Gy(e,i,a)||Ky(e,i,a)||Yy(e,i,a)||zy(a)||Xy(e,i,a)||Qy(a))continue;r.push({file:i,kind:"unused-import",description:`Depends on ${a} but references none of its symbols`,dep:a})}}return r}function $y(e){let t=[],n=qy(e);for(let[r,i]of e){if(Re(r))continue;let s=Ge(r);for(let o of i){if(Re(o))continue;let a=Ge(o);if(s===a)continue;(Mr(s,a)??n.get(`${s}->${a}`))==="violation"&&t.push({file:r,kind:"layer-violation",description:`Imports from ${a}/ (${o}) \u2014 may cross architectural boundary`,dep:o,detail:`${s}/ should not depend on ${a}/`})}}return t}function Ay(e,t){let n=[];for(let[r,i]of By(e)){let s=i.filter(a=>!Re(a));if(s.length<t)continue;let o=Wy(e,s);for(let a of s)for(let l of e.get(a)??[])Re(l)||(o.get(l)??0)===1&&Mt.dirname(l)!==r&&Mt.dirname(l)!==Mt.dirname(r)&&(xa(a,l)||n.push({file:a,kind:"pattern-deviation",description:`Only file in ${r}/ that depends on ${l}`,dep:l}))}return n}function jy(e){return{results:e,unusedImports:e.filter(t=>t.kind==="unused-import").length,layerViolations:e.filter(t=>t.kind==="layer-violation").length,patternDeviations:e.filter(t=>t.kind==="pattern-deviation").length}}function By(e){let t=new Map;for(let n of e.keys()){let r=Mt.dirname(n),i=t.get(r);i||(i=[],t.set(r,i)),i.push(n)}return t}function Wy(e,t){let n=new Map;for(let r of t)for(let i of e.get(r)??[])Re(i)||n.set(i,(n.get(i)??0)+1);return n}function Hy(e,t){let n=new Map;return Vy(e,n,t),Jy(e,n),n}function Vy(e,t,n){for(let r of Uy(e,n))_a(e,t,r.from_file,r.to_file)}function Uy(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
835
835
  FROM mentions m
836
836
  JOIN chunks c ON m.chunk_id = c.id
837
837
  JOIN documents d1 ON c.document_id = d1.id
@@ -847,25 +847,25 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
847
847
  WHERE d1.id != d2.id
848
848
  AND m.role != 1
849
849
  ${e.pathExclusionsFor("d1","d2")}
850
- ${n}`)}function Ey(e,t){let n=new C(e),r=e.all(`SELECT relative_path FROM documents
851
- WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);n.scanSourceReferences({paths:r.map(i=>i.relative_path),includeRustAttributeNames:!0,identifierResolution:"permissive"},i=>{i.target.relativePath!==i.sourceFile&&(e.isIgnored(i.target.relativePath)||ga(e,t,i.sourceFile,i.target.relativePath))})}function ga(e,t,n,r){if(e.isIgnored(n)||e.isIgnored(r))return;let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(r)}function Dy(e){let t=new Map;for(let[r,i]of e){if(Ie(r))continue;let s=Ge(r);for(let o of i){if(Ie(o))continue;let a=Ge(o);if(s===a||Mr(s,a))continue;let l=`${s}->${a}`;t.set(l,(t.get(l)??0)+1)}}let n=new Map;for(let[r,i]of t)n.set(r,i<=2?"violation":"ok");return n}function Ly(e){return e.includes("types")||e.endsWith(".d.ts")}function ky(e,t,n){let r=vt(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.isUsed)}function wy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.used)}function Py(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.every(i=>i.isTypeOnly===!0)}function Oy(e){return e.endsWith(".vue")}function My(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length===0?!1:r.every(i=>i.kind==="side-effect"||i.kind==="namespace"&&i.usedMembers.length===0&&!i.used)}function Ie(e){let t=Z(e);return!!(t==="entry"||t==="barrel"||t==="test"||t==="worker"||Fy(Mt.basename(e)))}function Fy(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 Ft,extname as Ln}from"path";function kn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=Jy(s.fileDependencyGraph(n)),a=Ay(s,n,r),l=Uy(s.crossFileCallerMap(a),s.sourceFallbackCallerFiles(a)),c=[];for(let d of a){let u=Ty(e,s,d,{callerFileMap:l,reverseFanIn:o});u&&c.push(u)}return c.sort((d,u)=>u.callerFanIn-d.callerFanIn||u.loc-d.loc),c.slice(0,i)}function Ty(e,t,n,r){let i=jy(t,n,r.callerFileMap);if(i.length!==1)return null;let s=i[0],o=By(e,n.symbolId,s);if(!o)return null;let a=Wy(t,e,s,n.symbol,o);if(a&&Le(a.symbol))return null;let l=Hy(r.callerFileMap,r.reverseFanIn,s,a);return l<=3?null:{symbol:n.symbol,shortName:h(n.symbol),file:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:$y(n),singleCaller:a?.symbol??"",singleCallerShort:a?.isFunctionLike?h(a.symbol):Ft(s),callerFanIn:l}}function $y(e){return e.endLine-e.startLine+1}function Ay(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:2,maxLoc:n,requireFunctionLikeSymbol:!0})}function jy(e,t,n){let r=Ft(t.relativePath,Ln(t.relativePath));return[...n.get(t.symbolId)??[]].filter(i=>i!==t.relativePath).filter(i=>Ft(i,Ln(i))!==r).filter(i=>{let s=e.fileKind(i);return s!=="barrel"&&s!=="entry"&&s!=="test"})}function By(e,t,n){return e.get(`SELECT c.start_line, c.end_line
850
+ ${n}`)}function Jy(e,t){let n=new C(e),r=e.all(`SELECT relative_path FROM documents
851
+ WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);n.scanSourceReferences({paths:r.map(i=>i.relative_path),includeRustAttributeNames:!0,identifierResolution:"permissive"},i=>{i.target.relativePath!==i.sourceFile&&(e.isIgnored(i.target.relativePath)||_a(e,t,i.sourceFile,i.target.relativePath))})}function _a(e,t,n,r){if(e.isIgnored(n)||e.isIgnored(r))return;let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(r)}function qy(e){let t=new Map;for(let[r,i]of e){if(Re(r))continue;let s=Ge(r);for(let o of i){if(Re(o))continue;let a=Ge(o);if(s===a||Mr(s,a))continue;let l=`${s}->${a}`;t.set(l,(t.get(l)??0)+1)}}let n=new Map;for(let[r,i]of t)n.set(r,i<=2?"violation":"ok");return n}function zy(e){return e.includes("types")||e.endsWith(".d.ts")}function Gy(e,t,n){let r=vt(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.isUsed)}function Ky(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.used)}function Yy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.every(i=>i.isTypeOnly===!0)}function Qy(e){return e.endsWith(".vue")}function Xy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length===0?!1:r.every(i=>i.kind==="side-effect"||i.kind==="namespace"&&i.usedMembers.length===0&&!i.used)}function Re(e){let t=ee(e);return!!(t==="entry"||t==="barrel"||t==="test"||t==="worker"||Zy(Mt.basename(e)))}function Zy(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 Ft,extname as Dn}from"path";function Ln(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=cb(s.fileDependencyGraph(n)),a=nb(s,n,r),l=lb(s.crossFileCallerMap(a),s.sourceFallbackCallerFiles(a)),c=[];for(let u of a){let d=eb(e,s,u,{callerFileMap:l,reverseFanIn:o});d&&c.push(d)}return c.sort((u,d)=>d.callerFanIn-u.callerFanIn||d.loc-u.loc),c.slice(0,i)}function eb(e,t,n,r){let i=rb(t,n,r.callerFileMap);if(i.length!==1)return null;let s=i[0],o=ib(e,n.symbolId,s);if(!o)return null;let a=sb(t,e,s,n.symbol,o);if(a&&ke(a.symbol))return null;let l=ob(r.callerFileMap,r.reverseFanIn,s,a);return l<=3?null:{symbol:n.symbol,shortName:h(n.symbol),file:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:tb(n),singleCaller:a?.symbol??"",singleCallerShort:a?.isFunctionLike?h(a.symbol):Ft(s),callerFanIn:l}}function tb(e){return e.endLine-e.startLine+1}function nb(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:2,maxLoc:n,requireFunctionLikeSymbol:!0})}function rb(e,t,n){let r=Ft(t.relativePath,Dn(t.relativePath));return[...n.get(t.symbolId)??[]].filter(i=>i!==t.relativePath).filter(i=>Ft(i,Dn(i))!==r).filter(i=>{let s=e.fileKind(i);return s!=="barrel"&&s!=="entry"&&s!=="test"})}function ib(e,t,n){return e.get(`SELECT c.start_line, c.end_line
852
852
  FROM mentions m
853
853
  JOIN chunks c ON m.chunk_id = c.id
854
854
  JOIN documents d ON c.document_id = d.id
855
855
  WHERE m.symbol_id = ? AND m.role != 1 AND d.relative_path = ?
856
- LIMIT 1`,t,n)}function Wy(e,t,n,r,i){let s=e.definitionsForFile(n),o=Vy(t,n,r,i.start_line,i.end_line);return ae(s,o)}function Hy(e,t,n,r){if(r?.isFunctionLike){let i=[...e.get(r.symbolId)??[]].filter(s=>s!==r.relativePath);if(i.length>0)return i.length}return qy(t,n)}function Vy(e,t,n,r,i){let s=k(n);if(!s)return r;let o=Je(e,t).get(s);if(!o||o.length===0)return r;for(let a of o)if(a>=r&&a<=i)return a;return r}function Uy(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function Jy(e){let t=new Map;for(let[n,r]of e){t.has(n)||t.set(n,t.get(n)??0);for(let i of r)t.set(i,(t.get(i)??0)+1)}return t}function qy(e,t){let n=e.get(t)??0;if(n>0)return n;let r=Ft(t,Ln(t)),i=0;for(let[s,o]of e)s!==t&&Ft(s,Ln(s))===r&&o>i&&(i=o);return i}function ya(e,t,n,r){let i=M(t);if(!i)return!0;let s=w(e,t);if(!s)return!0;let o=ha.get(s);return o||(o=zy(s,i),ha.set(s,o)),o.get(`${n}:${r}`)??!0}var ha=new WeakMap;function zy(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{n.has(s.type)&&r.set(`${s.startPosition.row}:${s.endPosition.row}`,Gy(s,t));for(let o of s.children)i(o)};return i(e.rootNode),r}function Gy(e,t){let n=e.namedChildren.find(u=>u.type==="block"||u.type==="statement_block");if(!n)return!1;let r=n.namedChildren.filter(u=>u.type!=="comment"&&u.type!=="line_comment"&&u.type!=="block_comment");if(r.length!==1)return!1;let i=r[0],s=null;if(i.type==="return_statement"||i.type==="expression_statement"?s=i.namedChild(0)??null:t==="rust"&&(i.type==="call_expression"||i.type==="macro_invocation")&&(s=i),!s)return!1;let o=t==="python"?"call":"call_expression";if(s.type!==o)return!1;let a=s.namedChildren.find(u=>u.type==="arguments"||u.type==="argument_list");if(!a)return!1;let l=a.namedChildren.filter(u=>u.type!=="comment"),c=e.namedChildren.find(u=>u.type==="parameters"||u.type==="formal_parameters");if(!c)return!1;let d=[];for(let u of c.namedChildren)if(u.type==="identifier")d.push(u.text);else{let m=u.namedChildren.find(f=>f.type==="identifier");m&&d.push(m.text)}if(l.length!==d.length)return!1;for(let u=0;u<d.length;u+=1){let m=l[u];if(m.type!=="identifier"||m.text!==d[u])return!1}return!0}function wn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=Yy(s,n,r),a=s.calleeMap(o),l=[];for(let c of o){let d=Ky(e,c,a.get(c.symbolId)??[]);d&&l.push(d)}return l.sort((c,d)=>c.loc-d.loc||c.file.localeCompare(d.file)),l.slice(0,i)}function Ky(e,t,n){let r=Qy(n);if(r.size!==1||!ya(e,t.relativePath,t.startLine,t.endLine))return null;let[,i]=[...r.entries()][0];return{symbol:t.symbol,shortName:h(t.symbol),file:t.relativePath,startLine:t.startLine,endLine:t.endLine,loc:Xy(t),forwardsTo:i.symbol,forwardsToShort:h(i.symbol),forwardsToFile:i.file}}function Qy(e){let t=e.some(r=>W(r.symbol))?e.filter(r=>W(r.symbol)):e,n=new Map;for(let r of t)n.has(r.symbol)||n.set(r.symbol,r);return n}function Yy(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:3,maxLoc:n,requireFunctionLikeSymbol:!0,excludeRustTraitImplMembers:!0})}function Xy(e){return e.endLine-e.startLine+1}function Pn(e,t){let{scope:n,minLoc:r=3,maxLoc:i=80,limit:s=30,includeLowConfidence:o=!1}=t??{},a=new C(e),l=a.scopedDefinitions(n),c=ub(a,n),d=Zy(e,a,l,{minLoc:r,maxLoc:i}),u=eb(a,d),m=ib(e,a,l,d),f=tb(d);return nb(e,d,u,f).filter(y=>!m.has(y.definition.symbolId)).filter(y=>!y.transitivelyReachable).filter(y=>y.realConsumers.length<=1).filter(y=>!(y.realConsumers.length===0&&y.barrelConsumers>0)).filter(y=>mb(y.definition,y.realConsumers.length,c)).map(y=>rb(e,y)).filter(y=>o||y.confidence!=="low").sort((y,E)=>{let N={high:0,medium:1,low:2};return N[y.confidence]-N[E.confidence]||E.loc-y.loc||y.file.localeCompare(E.file)||y.startLine-E.startLine}).slice(0,s)}function Zy(e,t,n,r){return n.filter(i=>i.isTypeLike&&Fr(i)>=r.minLoc).filter(i=>Fr(i)<=r.maxLoc).filter(i=>!e.isIgnored(i.relativePath)).filter(i=>!db(i.symbol)).filter(i=>!t.hasSuppressionComment(i))}function eb(e,t){return Ia(e.crossFileCallerMap(t),e.sourceFallbackCallerFiles(t))}function tb(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);r||(r=new Map,t.set(n.relativePath,r));let i=k(n.symbol);i&&r.set(i,n)}return t}function nb(e,t,n,r){return t.map(i=>{let o=[...n.get(i.symbolId)??new Set].filter(d=>d!==i.relativePath&&!e.isIgnored(d)),{realConsumers:a,barrelConsumers:l}=pb(e,i.relativePath,i.symbol,o),c=fb(e,i,n,r);return{definition:i,realConsumers:a,barrelConsumers:l,transitivelyReachable:c}})}function rb(e,t){let n=_a(e,t.definition.relativePath,t.definition.startLine),r=Sa(t.definition.relativePath)?!0:bb(e,t.definition),{confidence:i,reason:s}=Sb(t.realConsumers.length,n,r);return{symbol:t.definition.symbol,shortName:h(t.definition.symbol),file:t.definition.relativePath,startLine:t.definition.startLine,endLine:t.definition.endLine,loc:Fr(t.definition),consumers:t.realConsumers.length,barrelConsumers:t.barrelConsumers,kind:n,definerUsesType:r,confidence:i,reason:s}}function ib(e,t,n,r){let i=ob(e,sb(n),r),s=i.map(l=>l.singleton);if(i.length===0)return new Set;let o=Ia(t.crossFileCallerMap(s),t.sourceFallbackCallerFiles(s)),a=new Set;for(let{singleton:l,classId:c}of i)lb(e,l,o)&&a.add(c);return a}function sb(e){let t=new Map;for(let n of e){let r=k(n.symbol);r&&t.set(ba(n.relativePath,r),n)}return t}function ob(e,t,n){let r=[];for(let i of n){let s=ab(e,t,i);s&&r.push({singleton:s,classId:i.symbolId})}return r}function ab(e,t,n){if(_a(e,n.relativePath,n.startLine)!=="class")return null;let r=k(n.symbol);if(!r)return null;let i=cb(e,n.relativePath,r);return i?t.get(ba(n.relativePath,i))??null:null}function lb(e,t,n){let r=k(t.symbol),i=n.get(t.symbolId);return!r||!i?!1:[...i].some(s=>s!==t.relativePath&&!e.isIgnored(s)&&!xa(e,s,r))}function ba(e,t){return`${e}\0${t}`}function cb(e,t,n){let r=O(e,t);if(!r)return null;let i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\bexport\\s+const\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*new\\s+${i}\\s*\\(`);return r.match(s)?.[1]??null}function ub(e,t){return new Set(e.scopedDefinitions(t).filter(n=>n.isFunctionLike).map(n=>n.relativePath))}function db(e){let t=H(e);if("kind"in t)return!1;let n=t.descriptors;if(n.length<2)return!1;let r=n[n.length-1],i=n[n.length-2];return r?.suffix==="type"&&i?.suffix==="type"}function Sa(e){let n=(e.split("/").pop()??"").replace(/\.[^.]+$/,"");return!!(n==="types"||n==="models"||n==="schema"||n==="common"||n==="protocol"||n==="proto"||n==="dto"||n==="mod"||/(^|\/)types(\/|\.)/.test(e)||/(^|\/)models?(\/|\.)/.test(e)||/(^|\/)proto(?:col)?(\/|\.)/.test(e)||/(^|\/)schema(\/|\.)/.test(e))}function mb(e,t,n){return!(Sa(e.relativePath)&&t>0||t===0&&n.has(e.relativePath))}function pb(e,t,n,r){let i=[],s=0,o=k(n);for(let a of r)yb(e,a,t,o)||xa(e,a,o)?s++:i.push(a);return{realConsumers:i,barrelConsumers:s}}function fb(e,t,n,r){let i=Ki(e,t.relativePath),s=k(t.symbol);if(!s)return!1;let o=i.get(s);if(!o||o.size===0)return!1;let a=r.get(t.relativePath);if(!a)return!1;for(let l of o){let c=a.get(l);if(!c)continue;let d=n.get(c.symbolId);if(d){for(let u of d)if(u!==t.relativePath&&!e.isIgnored(u))return!0}}return!1}var gb=$("stale-abs-file-usage");function xa(e,t,n){if(!n)return!1;let r=M(t);if(!r)return!1;let i=gb.get(e,t,()=>hb(e,t,r));return i.importedLeaves.has(n)&&!i.usedLeaves.has(n)}function hb(e,t,n){let r=new Set,i=new Set,s=w(e,t);if(!s)return{importedLeaves:r,usedLeaves:i};let o=n==="rust"?new Set(["use_declaration"]):n==="python"?new Set(["import_statement","import_from_statement"]):new Set(["import_statement"]),a=(l,c)=>{let d=c||o.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(d?r.add(l.text):i.add(l.text));for(let u of l.children)a(u,d)};return a(s.rootNode,!1),{importedLeaves:r,usedLeaves:i}}function yb(e,t,n,r){if(!r)return!1;let i=O(e,t);if(!i)return!1;let s=Us(e,t);if(s.length===0)return!1;let o=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`\\b${o}\\b`),l=i.split(`
857
- `),c=0;for(let d=0;d<l.length;d++){if(!a.test(l[d]??""))continue;if(c++,!s.find(m=>m.startLine<=d&&d<=m.endLine))return!1}return c>0}function _a(e,t,n){let r=O(e,t);if(!r)return"other";let i=r.split(`
858
- `),s=Math.max(0,n-2),o=Math.min(i.length-1,n+2);for(let a=s;a<=o;a++){let c=(i[a]??"").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 bb(e,t){let n=O(e,t.relativePath);if(!n)return!1;let r=k(t.symbol);if(!r)return!1;let i=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\b${i}\\b`),o=n.split(`
859
- `);for(let a=0;a<o.length;a++)if(!(a>=t.startLine&&a<=t.endLine)&&s.test(o[a]??""))return!0;return!1}function Sb(e,t,n){return e===0?{confidence:"high",reason:"unused \u2014 no consumers and defining file has no real usage"}:e===1&&t==="class"?{confidence:"low",reason:"1 consumer + class kind \u2014 likely 1:1 encapsulation, not over-abstraction"}:e===1&&!n?{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 Fr(e){return e.endLine-e.startLine+1}function Ia(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function On(e,t){let{scope:n,minLoc:r=10,limit:i=30}=t??{},{definitions:s,callerMap:o,calleeMap:a}=xb(e,n);return s.map(l=>{let c=l.endLine-l.startLine+1,d=o.get(l.symbolId)?.size??0,u=a.get(l.symbolId)??[],m=u.filter(g=>g.file!==l.relativePath),f=new Set(m.map(g=>`${g.symbol}|${g.file}`)).size,p=new Set(u.map(g=>`${g.symbol}|${g.file}`)).size;return{symbol:l.symbol,shortName:h(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:d,fanOut:f,calleeCount:p,score:Math.round(c/50*(d/5)*Math.max(f/5,1)*100)/100}}).filter(l=>l.loc>=r).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,i)}function xb(e,t){let n=new C(e),r=n.productionCallableDefinitions({scope:t,requireCallableSymbol:!0,includeSuppressed:!0});return{definitions:r,callerMap:n.crossFileCallerMap(r),calleeMap:n.calleeMap(r)}}var _b=50;function Ra(e,t={}){let n=Ib(e,t.scope),r=Rb(e,n),i=Cb(n,r);return{score:vb(n,r),overview:{documents:n.statsResult.documents,symbols:n.statsResult.symbols,indexSizeBytes:n.statsResult.indexSizeBytes},findings:{deadSymbols:r.trueDeadCount,deadLoc:r.trueDeadLoc,isolatedSymbols:r.trueIsolatedCount,isolatedLoc:r.trueIsolatedLoc,cycles:r.realCycleCount,similarPairs:r.trueSimilarCount,extractionCandidates:n.extractResult.length,wrappers:n.wrapperResult.length,passthroughs:n.passthroughResult.length,staleTypes:r.trueStaleCount,driftedFiles:r.trueDriftCount,complexityHotspotCount:Ca(n)},actions:i,topComplexity:n.complexResult.slice(0,5).map(o=>({symbol:o.shortName,score:o.score}))}}function Ib(e,t){return{statsResult:Zt(e),deadResult:In(e,{scope:t,minLoc:3,skipBarrels:!0}),isolatedResult:Cn(e,{scope:t,minLoc:3}),cycleResult:Rn(e,{scope:t}),similarResult:vn(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),extractResult:Nn(e,{scope:t,minLoc:15,minCallees:5,limit:50}),wrapperResult:kn(e,{scope:t,maxLoc:15,limit:50}),passthroughResult:wn(e,{scope:t,maxLoc:15,limit:50}),staleResult:Pn(e,{scope:t,minLoc:3,limit:50}),driftResult:Dn(e,{scope:t}),complexResult:On(e,{scope:t,minLoc:10,limit:10})}}function Rb(e,t){let n=t.deadResult.symbols.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath)&&i.kind==="dead-code"),r=t.isolatedResult.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath));return{trueDeadCount:n.length,trueDeadLoc:n.reduce((i,s)=>i+s.loc,0),trueIsolatedCount:r.length,trueIsolatedLoc:r.reduce((i,s)=>i+s.loc,0),trueStaleCount:t.staleResult.length,trueDriftCount:t.driftResult.unusedImports+t.driftResult.layerViolations,trueSimilarCount:t.similarResult.length,realCycleCount:t.cycleResult.filter(i=>i.kind==="real").length}}function Cb(e,t){let n=[];if(t.trueDeadCount>0&&n.push({category:"Dead code",description:`${t.trueDeadCount} symbols with zero references anywhere \u2014 safe to delete`,effort:"low",impact:"high",count:t.trueDeadCount,locRecoverable:t.trueDeadLoc}),t.trueIsolatedCount>0&&n.push({category:"Isolated symbols",description:`${t.trueIsolatedCount} symbols completely disconnected from the codebase graph`,effort:"low",impact:"medium",count:t.trueIsolatedCount,locRecoverable:t.trueIsolatedLoc}),t.realCycleCount>0&&n.push({category:"Circular dependencies",description:`${t.realCycleCount} cycle(s) \u2014 break with dependency inversion or module restructuring`,effort:"medium",impact:"high",count:t.realCycleCount,locRecoverable:0}),t.trueSimilarCount>0&&n.push({category:"Similar functions",description:`${t.trueSimilarCount} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,effort:"medium",impact:"medium",count:t.trueSimilarCount,locRecoverable:0}),e.extractResult.length>0&&n.push({category:"Extraction candidates",description:`${e.extractResult.length} large functions with isolated callee clusters \u2014 extract method opportunities`,effort:"medium",impact:"medium",count:e.extractResult.length,locRecoverable:0}),e.wrapperResult.length>0&&n.push({category:"Wrapper functions",description:`${e.wrapperResult.length} single-consumer symbols that could be inlined`,effort:"low",impact:"low",count:e.wrapperResult.length,locRecoverable:e.wrapperResult.reduce((s,o)=>s+o.loc,0)}),e.passthroughResult.length>0&&n.push({category:"Passthrough functions",description:`${e.passthroughResult.length} functions that just forward to one callee \u2014 unnecessary indirection`,effort:"low",impact:"low",count:e.passthroughResult.length,locRecoverable:e.passthroughResult.reduce((s,o)=>s+o.loc,0)}),t.trueStaleCount>0){let s=e.staleResult.filter(l=>l.consumers===0).length,o=t.trueStaleCount-s,a=[];s>0&&a.push(`${s} unused`),o>0&&a.push(`${o} single-consumer (not in types file)`),n.push({category:"Stale abstractions",description:`${a.join(", ")} \u2014 premature abstraction`,effort:"low",impact:"medium",count:t.trueStaleCount,locRecoverable:e.staleResult.reduce((l,c)=>l+c.loc,0)})}if(t.trueDriftCount>0){let s=[];e.driftResult.unusedImports>0&&s.push(`${e.driftResult.unusedImports} unused imports`),e.driftResult.layerViolations>0&&s.push(`${e.driftResult.layerViolations} layer violations`),n.push({category:"Structural drift",description:s.join(", "),effort:e.driftResult.layerViolations>0?"medium":"low",impact:e.driftResult.layerViolations>0?"medium":"low",count:t.trueDriftCount,locRecoverable:0})}let r={high:3,medium:2,low:1},i={low:3,medium:2,high:1};return n.sort((s,o)=>{let a=r[s.impact]*i[s.effort];return r[o.impact]*i[o.effort]-a}),n}function vb(e,t){let n=Math.max(e.statsResult.documents,1),r=Math.max(e.statsResult.symbols,1),i=100,s=t.trueDeadCount/r;i-=Math.min(20,Math.round(s*200));let o=t.trueIsolatedCount/r;i-=Math.min(10,Math.round(o*200)),i-=Math.min(15,t.realCycleCount*5);let a=t.trueSimilarCount/r*1e3;i-=Math.min(10,Math.round(a));let l=e.extractResult.length/r*1e3;i-=Math.min(5,Math.round(l/2)),i-=Math.min(3,e.wrapperResult.length),i-=Math.min(3,e.passthroughResult.length);let c=t.trueStaleCount/Math.max(r*.1,1);i-=Math.min(8,Math.round(c*10));let d=t.trueDriftCount/n;i-=Math.min(5,Math.round(d*50));let u=Ca(e);return i-=Math.min(5,u*2),Math.max(0,Math.min(100,i))}function Ca(e){return e.complexResult.filter(t=>t.score>_b).length}function va(e,t,n){let r=L(e,t),i=L(e,n);if(!r||!i)return null;let s=new Set(X(e,r).map(g=>g.symbol)),o=new Set(X(e,i).map(g=>g.symbol)),a=[];for(let g of s)o.has(g)&&a.push(g);let l=[];for(let g of s)o.has(g)||l.push(g);let c=[];for(let g of o)s.has(g)||c.push(g);let d=new Set([...s,...o]),u=d.size>0?a.length/d.size:0,m;d.size===0?m="Neither function calls other tracked symbols. There is no callee-pattern evidence for consolidation; inspect the source bodies directly.":a.length===0?m="These functions do not share any callees. They are not a callee-based consolidation candidate.":l.length===0&&c.length===0?m="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?m="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?m="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?m=`Create a shared function with the ${a.length} common callees. Pass the ${l.length+c.length} divergent callees as parameters or strategy callbacks.`:m=`Extract the ${a.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=r.endLine-r.startLine+1,p=i.endLine-i.startLine+1;return{symbolA:{symbol:r.symbol,shortName:h(r.symbol),file:r.relativePath,loc:f},symbolB:{symbol:i.symbol,shortName:h(i.symbol),file:i.relativePath,loc:p},similarity:u,sharedCallees:a.map(h),uniqueToA:l.map(h),uniqueToB:c.map(h),consolidationStrategy:m}}import{readFileSync as Na}from"fs";import{extname as Nb,join as Ea}from"path";function Da(e,t,n={}){let{context:r=0}=n,i=Eb(t);if(i)return Lb(e,i.filePath,i.startLine,i.endLine,r);let s=L(e,t);return s?Db(e,s,r):null}function Eb(e){let t=e.match(/^(.+\.\w+):(\d+)-(\d+)$/);return t?{filePath:t[1],startLine:parseInt(t[2],10),endLine:parseInt(t[3],10)}:null}function Db(e,t,n){let r=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath),i=Ea(e.config.projectRoot,t.relativePath),s;try{s=Na(i,"utf-8")}catch{return null}let o=s.split(`
856
+ LIMIT 1`,t,n)}function sb(e,t,n,r,i){let s=e.definitionsForFile(n),o=ab(t,n,r,i.start_line,i.end_line);return ae(s,o)}function ob(e,t,n,r){if(r?.isFunctionLike){let i=[...e.get(r.symbolId)??[]].filter(s=>s!==r.relativePath);if(i.length>0)return i.length}return ub(t,n)}function ab(e,t,n,r,i){let s=D(n);if(!s)return r;let o=qe(e,t).get(s);if(!o||o.length===0)return r;for(let a of o)if(a>=r&&a<=i)return a;return r}function lb(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function cb(e){let t=new Map;for(let[n,r]of e){t.has(n)||t.set(n,t.get(n)??0);for(let i of r)t.set(i,(t.get(i)??0)+1)}return t}function ub(e,t){let n=e.get(t)??0;if(n>0)return n;let r=Ft(t,Dn(t)),i=0;for(let[s,o]of e)s!==t&&Ft(s,Dn(s))===r&&o>i&&(i=o);return i}function Ra(e,t,n,r){let i=M(t);if(!i)return!0;let s=P(e,t);if(!s)return!0;let o=Ia.get(s);return o||(o=db(s,i),Ia.set(s,o)),o.get(`${n}:${r}`)??!0}var Ia=new WeakMap;function db(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{n.has(s.type)&&r.set(`${s.startPosition.row}:${s.endPosition.row}`,mb(s,t));for(let o of s.children)i(o)};return i(e.rootNode),r}function mb(e,t){let n=e.namedChildren.find(d=>d.type==="block"||d.type==="statement_block");if(!n)return!1;let r=n.namedChildren.filter(d=>d.type!=="comment"&&d.type!=="line_comment"&&d.type!=="block_comment");if(r.length!==1)return!1;let i=r[0],s=null;if(i.type==="return_statement"||i.type==="expression_statement"?s=i.namedChild(0)??null:t==="rust"&&(i.type==="call_expression"||i.type==="macro_invocation")&&(s=i),!s)return!1;let o=t==="python"?"call":"call_expression";if(s.type!==o)return!1;let a=s.namedChildren.find(d=>d.type==="arguments"||d.type==="argument_list");if(!a)return!1;let l=a.namedChildren.filter(d=>d.type!=="comment"),c=e.namedChildren.find(d=>d.type==="parameters"||d.type==="formal_parameters");if(!c)return!1;let u=[];for(let d of c.namedChildren)if(d.type==="identifier")u.push(d.text);else{let m=d.namedChildren.find(g=>g.type==="identifier");m&&u.push(m.text)}if(l.length!==u.length)return!1;for(let d=0;d<u.length;d+=1){let m=l[d];if(m.type!=="identifier"||m.text!==u[d])return!1}return!0}function kn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=gb(s,n,r),a=s.calleeMap(o),l=[];for(let c of o){let u=pb(e,c,a.get(c.symbolId)??[]);u&&l.push(u)}return l.sort((c,u)=>c.loc-u.loc||c.file.localeCompare(u.file)),l.slice(0,i)}function pb(e,t,n){let r=fb(n);if(r.size!==1||!Ra(e,t.relativePath,t.startLine,t.endLine))return null;let[,i]=[...r.entries()][0];return{symbol:t.symbol,shortName:h(t.symbol),file:t.relativePath,startLine:t.startLine,endLine:t.endLine,loc:hb(t),forwardsTo:i.symbol,forwardsToShort:h(i.symbol),forwardsToFile:i.file}}function fb(e){let t=e.some(r=>W(r.symbol))?e.filter(r=>W(r.symbol)):e,n=new Map;for(let r of t)n.has(r.symbol)||n.set(r.symbol,r);return n}function gb(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:3,maxLoc:n,requireFunctionLikeSymbol:!0,excludeRustTraitImplMembers:!0})}function hb(e){return e.endLine-e.startLine+1}function wn(e,t){let{scope:n,minLoc:r=3,maxLoc:i=80,limit:s=30,includeLowConfidence:o=!1}=t??{},a=new C(e),l=a.scopedDefinitions(n),c=Db(a,n),u=yb(e,a,l,{minLoc:r,maxLoc:i}),d=bb(a,u),m=Ib(e,a,l,u),g=Sb(u);return xb(e,u,d,g).filter(y=>!m.has(y.definition.symbolId)).filter(y=>!y.transitivelyReachable).filter(y=>y.realConsumers.length<=1).filter(y=>!(y.realConsumers.length===0&&y.barrelConsumers>0)).filter(y=>kb(y.definition,y.realConsumers.length,c)).map(y=>_b(e,y)).filter(y=>o||y.confidence!=="low").sort((y,L)=>{let k={high:0,medium:1,low:2};return k[y.confidence]-k[L.confidence]||L.loc-y.loc||y.file.localeCompare(L.file)||y.startLine-L.startLine}).slice(0,s)}function yb(e,t,n,r){return n.filter(i=>i.isTypeLike&&Fr(i)>=r.minLoc).filter(i=>Fr(i)<=r.maxLoc).filter(i=>!e.isIgnored(i.relativePath)).filter(i=>!Lb(i.symbol)).filter(i=>!t.hasSuppressionComment(i))}function bb(e,t){return Da(e.crossFileCallerMap(t),e.sourceFallbackCallerFiles(t))}function Sb(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);r||(r=new Map,t.set(n.relativePath,r));let i=D(n.symbol);i&&r.set(i,n)}return t}function xb(e,t,n,r){return t.map(i=>{let o=[...n.get(i.symbolId)??new Set].filter(u=>u!==i.relativePath&&!e.isIgnored(u)),{realConsumers:a,barrelConsumers:l}=wb(e,i.relativePath,i.symbol,o),c=Pb(e,i,n,r);return{definition:i,realConsumers:a,barrelConsumers:l,transitivelyReachable:c}})}function _b(e,t){let n=Ea(e,t.definition.relativePath,t.definition.startLine),r=va(t.definition.relativePath)?!0:Tb(e,t.definition),{confidence:i,reason:s}=$b(t.realConsumers.length,n,r);return{symbol:t.definition.symbol,shortName:h(t.definition.symbol),file:t.definition.relativePath,startLine:t.definition.startLine,endLine:t.definition.endLine,loc:Fr(t.definition),consumers:t.realConsumers.length,barrelConsumers:t.barrelConsumers,kind:n,definerUsesType:r,confidence:i,reason:s}}function Ib(e,t,n,r){let i=Cb(e,Rb(n),r),s=i.map(l=>l.singleton);if(i.length===0)return new Set;let o=Da(t.crossFileCallerMap(s),t.sourceFallbackCallerFiles(s)),a=new Set;for(let{singleton:l,classId:c}of i)Nb(e,l,o)&&a.add(c);return a}function Rb(e){let t=new Map;for(let n of e){let r=D(n.symbol);r&&t.set(Ca(n.relativePath,r),n)}return t}function Cb(e,t,n){let r=[];for(let i of n){let s=vb(e,t,i);s&&r.push({singleton:s,classId:i.symbolId})}return r}function vb(e,t,n){if(Ea(e,n.relativePath,n.startLine)!=="class")return null;let r=D(n.symbol);if(!r)return null;let i=Eb(e,n.relativePath,r);return i?t.get(Ca(n.relativePath,i))??null:null}function Nb(e,t,n){let r=D(t.symbol),i=n.get(t.symbolId);return!r||!i?!1:[...i].some(s=>s!==t.relativePath&&!e.isIgnored(s)&&!Na(e,s,r))}function Ca(e,t){return`${e}\0${t}`}function Eb(e,t,n){let r=w(e,t);if(!r)return null;let i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\bexport\\s+const\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*new\\s+${i}\\s*\\(`);return r.match(s)?.[1]??null}function Db(e,t){return new Set(e.scopedDefinitions(t).filter(n=>n.isFunctionLike).map(n=>n.relativePath))}function Lb(e){let t=H(e);if("kind"in t)return!1;let n=t.descriptors;if(n.length<2)return!1;let r=n[n.length-1],i=n[n.length-2];return r?.suffix==="type"&&i?.suffix==="type"}function va(e){let n=(e.split("/").pop()??"").replace(/\.[^.]+$/,"");return!!(n==="types"||n==="models"||n==="schema"||n==="common"||n==="protocol"||n==="proto"||n==="dto"||n==="mod"||/(^|\/)types(\/|\.)/.test(e)||/(^|\/)models?(\/|\.)/.test(e)||/(^|\/)proto(?:col)?(\/|\.)/.test(e)||/(^|\/)schema(\/|\.)/.test(e))}function kb(e,t,n){return!(va(e.relativePath)&&t>0||t===0&&n.has(e.relativePath))}function wb(e,t,n,r){let i=[],s=0,o=D(n);for(let a of r)Fb(e,a,t,o)||Na(e,a,o)?s++:i.push(a);return{realConsumers:i,barrelConsumers:s}}function Pb(e,t,n,r){let i=Yi(e,t.relativePath),s=D(t.symbol);if(!s)return!1;let o=i.get(s);if(!o||o.size===0)return!1;let a=r.get(t.relativePath);if(!a)return!1;for(let l of o){let c=a.get(l);if(!c)continue;let u=n.get(c.symbolId);if(u){for(let d of u)if(d!==t.relativePath&&!e.isIgnored(d))return!0}}return!1}var Ob=$("stale-abs-file-usage");function Na(e,t,n){if(!n)return!1;let r=M(t);if(!r)return!1;let i=Ob.get(e,t,()=>Mb(e,t,r));return i.importedLeaves.has(n)&&!i.usedLeaves.has(n)}function Mb(e,t,n){let r=new Set,i=new Set,s=P(e,t);if(!s)return{importedLeaves:r,usedLeaves:i};let o=n==="rust"?new Set(["use_declaration"]):n==="python"?new Set(["import_statement","import_from_statement"]):new Set(["import_statement"]),a=(l,c)=>{let u=c||o.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(u?r.add(l.text):i.add(l.text));for(let d of l.children)a(d,u)};return a(s.rootNode,!1),{importedLeaves:r,usedLeaves:i}}function Fb(e,t,n,r){if(!r)return!1;let i=w(e,t);if(!i)return!1;let s=Ys(e,t);if(s.length===0)return!1;let o=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`\\b${o}\\b`),l=i.split(`
857
+ `),c=0;for(let u=0;u<l.length;u++){if(!a.test(l[u]??""))continue;if(c++,!s.find(m=>m.startLine<=u&&u<=m.endLine))return!1}return c>0}function Ea(e,t,n){let r=w(e,t);if(!r)return"other";let i=r.split(`
858
+ `),s=Math.max(0,n-2),o=Math.min(i.length-1,n+2);for(let a=s;a<=o;a++){let c=(i[a]??"").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 Tb(e,t){let n=w(e,t.relativePath);if(!n)return!1;let r=D(t.symbol);if(!r)return!1;let i=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\b${i}\\b`),o=n.split(`
859
+ `);for(let a=0;a<o.length;a++)if(!(a>=t.startLine&&a<=t.endLine)&&s.test(o[a]??""))return!0;return!1}function $b(e,t,n){return e===0?{confidence:"high",reason:"unused \u2014 no consumers and defining file has no real usage"}:e===1&&t==="class"?{confidence:"low",reason:"1 consumer + class kind \u2014 likely 1:1 encapsulation, not over-abstraction"}:e===1&&!n?{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 Fr(e){return e.endLine-e.startLine+1}function Da(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function Pn(e,t){let{scope:n,minLoc:r=10,limit:i=30}=t??{},{definitions:s,callerMap:o,calleeMap:a}=Ab(e,n);return s.map(l=>{let c=l.endLine-l.startLine+1,u=o.get(l.symbolId)?.size??0,d=a.get(l.symbolId)??[],m=d.filter(f=>f.file!==l.relativePath),g=new Set(m.map(f=>`${f.symbol}|${f.file}`)).size,p=new Set(d.map(f=>`${f.symbol}|${f.file}`)).size;return{symbol:l.symbol,shortName:h(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:u,fanOut:g,calleeCount:p,score:Math.round(c/50*(u/5)*Math.max(g/5,1)*100)/100}}).filter(l=>l.loc>=r).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,i)}function Ab(e,t){let n=new C(e),r=n.productionCallableDefinitions({scope:t,requireCallableSymbol:!0,includeSuppressed:!0});return{definitions:r,callerMap:n.crossFileCallerMap(r),calleeMap:n.calleeMap(r)}}var jb=50;function La(e,t={}){let n=Bb(e,t.scope),r=Wb(e,n),i=Hb(n,r);return{score:Vb(n,r),overview:{documents:n.statsResult.documents,symbols:n.statsResult.symbols,indexSizeBytes:n.statsResult.indexSizeBytes},findings:{deadSymbols:r.trueDeadCount,deadLoc:r.trueDeadLoc,isolatedSymbols:r.trueIsolatedCount,isolatedLoc:r.trueIsolatedLoc,cycles:r.realCycleCount,similarPairs:r.trueSimilarCount,extractionCandidates:n.extractResult.length,wrappers:n.wrapperResult.length,passthroughs:n.passthroughResult.length,staleTypes:r.trueStaleCount,driftedFiles:r.trueDriftCount,complexityHotspotCount:ka(n)},actions:i,topComplexity:n.complexResult.slice(0,5).map(o=>({symbol:o.shortName,score:o.score}))}}function Bb(e,t){return{statsResult:Zt(e),deadResult:_n(e,{scope:t,minLoc:3,skipBarrels:!0}),isolatedResult:Rn(e,{scope:t,minLoc:3}),cycleResult:In(e,{scope:t}),similarResult:Cn(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),extractResult:vn(e,{scope:t,minLoc:15,minCallees:5,limit:50}),wrapperResult:Ln(e,{scope:t,maxLoc:15,limit:50}),passthroughResult:kn(e,{scope:t,maxLoc:15,limit:50}),staleResult:wn(e,{scope:t,minLoc:3,limit:50}),driftResult:En(e,{scope:t}),complexResult:Pn(e,{scope:t,minLoc:10,limit:10})}}function Wb(e,t){let n=t.deadResult.symbols.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath)&&i.kind==="dead-code"),r=t.isolatedResult.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath));return{trueDeadCount:n.length,trueDeadLoc:n.reduce((i,s)=>i+s.loc,0),trueIsolatedCount:r.length,trueIsolatedLoc:r.reduce((i,s)=>i+s.loc,0),trueStaleCount:t.staleResult.length,trueDriftCount:t.driftResult.unusedImports+t.driftResult.layerViolations,trueSimilarCount:t.similarResult.length,realCycleCount:t.cycleResult.filter(i=>i.kind==="real").length}}function Hb(e,t){let n=[];if(t.trueDeadCount>0&&n.push({category:"Dead code",description:`${t.trueDeadCount} symbols with zero references anywhere \u2014 safe to delete`,effort:"low",impact:"high",count:t.trueDeadCount,locRecoverable:t.trueDeadLoc}),t.trueIsolatedCount>0&&n.push({category:"Isolated symbols",description:`${t.trueIsolatedCount} symbols completely disconnected from the codebase graph`,effort:"low",impact:"medium",count:t.trueIsolatedCount,locRecoverable:t.trueIsolatedLoc}),t.realCycleCount>0&&n.push({category:"Circular dependencies",description:`${t.realCycleCount} cycle(s) \u2014 break with dependency inversion or module restructuring`,effort:"medium",impact:"high",count:t.realCycleCount,locRecoverable:0}),t.trueSimilarCount>0&&n.push({category:"Similar functions",description:`${t.trueSimilarCount} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,effort:"medium",impact:"medium",count:t.trueSimilarCount,locRecoverable:0}),e.extractResult.length>0&&n.push({category:"Extraction candidates",description:`${e.extractResult.length} large functions with isolated callee clusters \u2014 extract method opportunities`,effort:"medium",impact:"medium",count:e.extractResult.length,locRecoverable:0}),e.wrapperResult.length>0&&n.push({category:"Wrapper functions",description:`${e.wrapperResult.length} single-consumer symbols that could be inlined`,effort:"low",impact:"low",count:e.wrapperResult.length,locRecoverable:e.wrapperResult.reduce((s,o)=>s+o.loc,0)}),e.passthroughResult.length>0&&n.push({category:"Passthrough functions",description:`${e.passthroughResult.length} functions that just forward to one callee \u2014 unnecessary indirection`,effort:"low",impact:"low",count:e.passthroughResult.length,locRecoverable:e.passthroughResult.reduce((s,o)=>s+o.loc,0)}),t.trueStaleCount>0){let s=e.staleResult.filter(l=>l.consumers===0).length,o=t.trueStaleCount-s,a=[];s>0&&a.push(`${s} unused`),o>0&&a.push(`${o} single-consumer (not in types file)`),n.push({category:"Stale abstractions",description:`${a.join(", ")} \u2014 premature abstraction`,effort:"low",impact:"medium",count:t.trueStaleCount,locRecoverable:e.staleResult.reduce((l,c)=>l+c.loc,0)})}if(t.trueDriftCount>0){let s=[];e.driftResult.unusedImports>0&&s.push(`${e.driftResult.unusedImports} unused imports`),e.driftResult.layerViolations>0&&s.push(`${e.driftResult.layerViolations} layer violations`),n.push({category:"Structural drift",description:s.join(", "),effort:e.driftResult.layerViolations>0?"medium":"low",impact:e.driftResult.layerViolations>0?"medium":"low",count:t.trueDriftCount,locRecoverable:0})}let r={high:3,medium:2,low:1},i={low:3,medium:2,high:1};return n.sort((s,o)=>{let a=r[s.impact]*i[s.effort];return r[o.impact]*i[o.effort]-a}),n}function Vb(e,t){let n=Math.max(e.statsResult.documents,1),r=Math.max(e.statsResult.symbols,1),i=100,s=t.trueDeadCount/r;i-=Math.min(20,Math.round(s*200));let o=t.trueIsolatedCount/r;i-=Math.min(10,Math.round(o*200)),i-=Math.min(15,t.realCycleCount*5);let a=t.trueSimilarCount/r*1e3;i-=Math.min(10,Math.round(a));let l=e.extractResult.length/r*1e3;i-=Math.min(5,Math.round(l/2)),i-=Math.min(3,e.wrapperResult.length),i-=Math.min(3,e.passthroughResult.length);let c=t.trueStaleCount/Math.max(r*.1,1);i-=Math.min(8,Math.round(c*10));let u=t.trueDriftCount/n;i-=Math.min(5,Math.round(u*50));let d=ka(e);return i-=Math.min(5,d*2),Math.max(0,Math.min(100,i))}function ka(e){return e.complexResult.filter(t=>t.score>jb).length}function wa(e,t,n){let r=E(e,t),i=E(e,n);if(!r||!i)return null;let s=new Set(Z(e,r).map(f=>f.symbol)),o=new Set(Z(e,i).map(f=>f.symbol)),a=[];for(let f of s)o.has(f)&&a.push(f);let l=[];for(let f of s)o.has(f)||l.push(f);let c=[];for(let f of o)s.has(f)||c.push(f);let u=new Set([...s,...o]),d=u.size>0?a.length/u.size:0,m;u.size===0?m="Neither function calls other tracked symbols. There is no callee-pattern evidence for consolidation; inspect the source bodies directly.":a.length===0?m="These functions do not share any callees. They are not a callee-based consolidation candidate.":l.length===0&&c.length===0?m="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?m="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?m="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?m=`Create a shared function with the ${a.length} common callees. Pass the ${l.length+c.length} divergent callees as parameters or strategy callbacks.`:m=`Extract the ${a.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=r.endLine-r.startLine+1,p=i.endLine-i.startLine+1;return{symbolA:{symbol:r.symbol,shortName:h(r.symbol),file:r.relativePath,loc:g},symbolB:{symbol:i.symbol,shortName:h(i.symbol),file:i.relativePath,loc:p},similarity:d,sharedCallees:a.map(h),uniqueToA:l.map(h),uniqueToB:c.map(h),consolidationStrategy:m}}import{readFileSync as Pa}from"fs";import{extname as Ub,join as Oa}from"path";function Ma(e,t,n={}){let{context:r=0}=n,i=Jb(t);if(i)return zb(e,i.filePath,i.startLine,i.endLine,r);let s=E(e,t);return s?qb(e,s,r):null}function Jb(e){let t=e.match(/^(.+\.\w+):(\d+)-(\d+)$/);return t?{filePath:t[1],startLine:parseInt(t[2],10),endLine:parseInt(t[3],10)}:null}function qb(e,t,n){let r=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath),i=Oa(e.config.projectRoot,t.relativePath),s;try{s=Pa(i,"utf-8")}catch{return null}let o=s.split(`
860
860
  `),a=Math.max(0,t.startLine-n),l=Math.min(o.length-1,t.endLine+n),c=o.slice(a,l+1).join(`
861
- `);return{symbol:t.symbol,shortName:h(t.symbol),relativePath:t.relativePath,startLine:a,endLine:l,language:r?.language??La(t.relativePath),source:c}}function Lb(e,t,n,r,i){let s=G(e,t);if(!s)return null;let o=e.get("SELECT relative_path, language FROM documents WHERE relative_path = ?",s);if(!o)return null;let a=Ea(e.config.projectRoot,o.relative_path),l;try{l=Na(a,"utf-8")}catch{return null}let c=l.split(`
862
- `),d=Math.max(0,n-1-i),u=Math.min(c.length-1,r-1+i),m=c.slice(d,u+1).join(`
863
- `);return{symbol:`${o.relative_path}:${n}-${r}`,shortName:`${o.relative_path}:${n}-${r}`,relativePath:o.relative_path,startLine:d,endLine:u,language:o.language??La(o.relative_path),source:m}}function La(e){switch(Nb(e).toLowerCase()){case".ts":case".tsx":case".mts":case".cts":return"typescript";case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".py":case".pyi":return"python";case".rs":return"rust";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":return"scala";case".rb":return"ruby";case".php":return"php";case".cs":return"csharp";case".vb":return"vb";case".dart":return"dart";case".c":case".h":return"c";case".cc":case".cpp":case".cxx":case".hpp":case".hh":case".hxx":return"cpp";case".vue":return"vue";default:return null}}import{readFileSync as kb}from"fs";import{join as wb}from"path";function ka(e,t){let n=L(e,t);if(!n)return null;let r=new C(e),i=Tb(Ob(e,n.relativePath,n.startLine,n.endLine),Pb(e,n.relativePath)),s=n.endLine-n.startLine+1,a=r.calleeMap([n],{additive:!0}).get(n.symbolId)??[],l=new Set(a.map(c=>c.symbol));return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:s,branches:i,cyclomaticEstimate:i+1,calleeCount:l.size,fanIn:Mb(e,n.symbolId),fanOut:Fb(a,n.relativePath)}}function Pb(e,t){return e.get("SELECT language FROM documents WHERE relative_path = ?",t)?.language??"unknown"}function Ob(e,t,n,r){try{return kb(wb(e.config.projectRoot,t),"utf-8").split(`
861
+ `);return{symbol:t.symbol,shortName:h(t.symbol),relativePath:t.relativePath,startLine:a,endLine:l,language:r?.language??Fa(t.relativePath),source:c}}function zb(e,t,n,r,i){let s=G(e,t);if(!s)return null;let o=e.get("SELECT relative_path, language FROM documents WHERE relative_path = ?",s);if(!o)return null;let a=Oa(e.config.projectRoot,o.relative_path),l;try{l=Pa(a,"utf-8")}catch{return null}let c=l.split(`
862
+ `),u=Math.max(0,n-1-i),d=Math.min(c.length-1,r-1+i),m=c.slice(u,d+1).join(`
863
+ `);return{symbol:`${o.relative_path}:${n}-${r}`,shortName:`${o.relative_path}:${n}-${r}`,relativePath:o.relative_path,startLine:u,endLine:d,language:o.language??Fa(o.relative_path),source:m}}function Fa(e){switch(Ub(e).toLowerCase()){case".ts":case".tsx":case".mts":case".cts":return"typescript";case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".py":case".pyi":return"python";case".rs":return"rust";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":return"scala";case".rb":return"ruby";case".php":return"php";case".cs":return"csharp";case".vb":return"vb";case".dart":return"dart";case".c":case".h":return"c";case".cc":case".cpp":case".cxx":case".hpp":case".hh":case".hxx":return"cpp";case".vue":return"vue";default:return null}}import{readFileSync as Gb}from"fs";import{join as Kb}from"path";function Ta(e,t){let n=E(e,t);if(!n)return null;let r=new C(e),i=eS(Qb(e,n.relativePath,n.startLine,n.endLine),Yb(e,n.relativePath)),s=n.endLine-n.startLine+1,a=r.calleeMap([n],{additive:!0}).get(n.symbolId)??[],l=new Set(a.map(c=>c.symbol));return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:s,branches:i,cyclomaticEstimate:i+1,calleeCount:l.size,fanIn:Xb(e,n.symbolId),fanOut:Zb(a,n.relativePath)}}function Yb(e,t){return e.get("SELECT language FROM documents WHERE relative_path = ?",t)?.language??"unknown"}function Qb(e,t,n,r){try{return Gb(Kb(e.config.projectRoot,t),"utf-8").split(`
864
864
  `).slice(n,r+1).join(`
865
- `)}catch{return""}}function Mb(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS c
865
+ `)}catch{return""}}function Xb(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS c
866
866
  FROM mentions m
867
867
  JOIN chunks c ON m.chunk_id = c.id
868
- WHERE m.symbol_id = ? AND m.role != 1`,t)?.c??0}function Fb(e,t){return new Set(e.filter(n=>n.file!==t).map(n=>n.symbol)).size}function Tb(e,t){let n=$b(e),r=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 s of i){let o=n.match(s);o&&(r+=o.length)}if(t==="python"){let s=[/\belif\b/g,/\bexcept\b/g,/\bfinally\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="rust"){let s=[/\bmatch\b/g,/=>/g,/\bloop\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="ruby"){let s=[/\belsif\b/g,/\bunless\b/g,/\brescue\b/g,/\bwhen\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="go"){let s=[/\bselect\b/g,/\bdefer\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}return r}function $b(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function wa(e,t){let n=L(e,t);if(!n)return null;let r=[{file:n.relativePath,line:n.startLine}],i=Fe(e,n),o=(i.length>0?i:_e(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({file:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol??"(top-level)",enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"})),{producers:a,consumers:l}=Ab(e,n,o);return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,definitionSites:r.filter(c=>!e.isIgnored(c.file)),usageSites:o,producers:a.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:h(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)":h(c.symbol),file:c.file}))}}function Ab(e,t,n){let r=Tr(X(e,t,{limit:30}).map(o=>({symbol:o.symbol,file:o.file}))),i=Tr(ie(e,t,{limit:30})),s=i.length>0?i:Tr(n.map(o=>({symbol:o.enclosingSymbol==="(top-level)"?o.file:o.enclosingSymbol,file:o.file})));return{producers:r,consumers:s}}function Tr(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function Pa(e,t,n={}){let{direction:r="backward",maxDepth:i=3}=n,s=L(e,t);return s?r==="backward"?jb(e,s,i):Bb(e,s):null}function jb(e,t,n){let r=[],i=new Set([t.symbol]),s=[t];for(let o=1;o<=n&&s.length!==0;o++){let a=[];for(let l of s){let c=X(e,l);for(let d of c){if(i.has(d.symbol))continue;i.add(d.symbol),r.push({symbol:d.symbol,shortName:h(d.symbol),file:d.file,relationship:o===1?"referenced within definition (callee)":`depth ${o} callee`});let u=it(e,d.symbol);u&&!e.isIgnored(u.relativePath)&&a.push(u)}}s=a}return{symbol:t.symbol,shortName:h(t.symbol),direction:"backward",connectedSymbols:r}}function Bb(e,t){let n=Fe(e,t),r=n.length>0?n:_e(e,t),i=new Set,s=[],o=new C(e);for(let a of r){if(s.length>=30)break;if(e.isIgnored(a.file))continue;let l=a.enclosingSymbol??ae(o.definitionsForFile(a.file),a.line)?.symbol??null;if(!l||l===t.symbol)continue;let c=it(e,l);!c||e.isIgnored(c.relativePath)||i.has(c.symbol)||(i.add(c.symbol),s.push({symbol:c.symbol,shortName:h(c.symbol),file:c.relativePath,relationship:`references target at ${a.file}:${a.line+1}`}))}return s.sort((a,l)=>a.file.localeCompare(l.file)),{symbol:t.symbol,shortName:h(t.symbol),direction:"forward",connectedSymbols:s}}function Oa(e,t={}){let{scope:n,limit:r}=t,i=new C(e),s=Kb([...Wb(e,n),...Ub(e,i,n)]);return Qb(s),r?s.slice(0,r):s}function Wb(e,t){let n=[];for(let r of Hb(e,t)){if(e.isIgnored(r.barrel_path)||e.isIgnored(r.original_path)||Lr(e,r.barrel_path))continue;let i=Vb(e,r),s=i?.barrel_consumers??0,o=i?.direct_consumers??0;s!==0||o!==0||n.push({barrelFile:r.barrel_path,symbol:r.symbol,shortName:h(r.symbol),originalFile:r.original_path,barrelConsumers:s,directConsumers:o})}return n}function Hb(e,t){let n=t?`AND barrel_d.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
868
+ WHERE m.symbol_id = ? AND m.role != 1`,t)?.c??0}function Zb(e,t){return new Set(e.filter(n=>n.file!==t).map(n=>n.symbol)).size}function eS(e,t){let n=tS(e),r=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 s of i){let o=n.match(s);o&&(r+=o.length)}if(t==="python"){let s=[/\belif\b/g,/\bexcept\b/g,/\bfinally\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="rust"){let s=[/\bmatch\b/g,/=>/g,/\bloop\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="ruby"){let s=[/\belsif\b/g,/\bunless\b/g,/\brescue\b/g,/\bwhen\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="go"){let s=[/\bselect\b/g,/\bdefer\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}return r}function tS(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function $a(e,t){let n=E(e,t);if(!n)return null;let r=[{file:n.relativePath,line:n.startLine}],i=Te(e,n),o=(i.length>0?i:Ie(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({file:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol??"(top-level)",enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"})),{producers:a,consumers:l}=nS(e,n,o);return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,definitionSites:r.filter(c=>!e.isIgnored(c.file)),usageSites:o,producers:a.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:h(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)":h(c.symbol),file:c.file}))}}function nS(e,t,n){let r=Tr(Z(e,t,{limit:30}).map(o=>({symbol:o.symbol,file:o.file}))),i=Tr(ie(e,t,{limit:30})),s=i.length>0?i:Tr(n.map(o=>({symbol:o.enclosingSymbol==="(top-level)"?o.file:o.enclosingSymbol,file:o.file})));return{producers:r,consumers:s}}function Tr(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function Aa(e,t,n={}){let{direction:r="backward",maxDepth:i=3}=n,s=E(e,t);return s?r==="backward"?rS(e,s,i):iS(e,s):null}function rS(e,t,n){let r=[],i=new Set([t.symbol]),s=[t];for(let o=1;o<=n&&s.length!==0;o++){let a=[];for(let l of s){let c=Z(e,l);for(let u of c){if(i.has(u.symbol))continue;i.add(u.symbol),r.push({symbol:u.symbol,shortName:h(u.symbol),file:u.file,relationship:o===1?"referenced within definition (callee)":`depth ${o} callee`});let d=it(e,u.symbol);d&&!e.isIgnored(d.relativePath)&&a.push(d)}}s=a}return{symbol:t.symbol,shortName:h(t.symbol),direction:"backward",connectedSymbols:r}}function iS(e,t){let n=Te(e,t),r=n.length>0?n:Ie(e,t),i=new Set,s=[],o=new C(e);for(let a of r){if(s.length>=30)break;if(e.isIgnored(a.file))continue;let l=a.enclosingSymbol??ae(o.definitionsForFile(a.file),a.line)?.symbol??null;if(!l||l===t.symbol)continue;let c=it(e,l);!c||e.isIgnored(c.relativePath)||i.has(c.symbol)||(i.add(c.symbol),s.push({symbol:c.symbol,shortName:h(c.symbol),file:c.relativePath,relationship:`references target at ${a.file}:${a.line+1}`}))}return s.sort((a,l)=>a.file.localeCompare(l.file)),{symbol:t.symbol,shortName:h(t.symbol),direction:"forward",connectedSymbols:s}}function ja(e,t={}){let{scope:n,limit:r}=t,i=new C(e),s=pS([...sS(e,n),...lS(e,i,n)]);return fS(s),r?s.slice(0,r):s}function sS(e,t){let n=[];for(let r of oS(e,t)){if(e.isIgnored(r.barrel_path)||e.isIgnored(r.original_path)||Dr(e,r.barrel_path))continue;let i=aS(e,r),s=i?.barrel_consumers??0,o=i?.direct_consumers??0;s!==0||o!==0||n.push({barrelFile:r.barrel_path,symbol:r.symbol,shortName:h(r.symbol),originalFile:r.original_path,barrelConsumers:s,directConsumers:o})}return n}function oS(e,t){let n=t?`AND barrel_d.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
869
869
  barrel_d.id AS barrel_doc_id,
870
870
  barrel_d.relative_path AS barrel_path,
871
871
  gs.id AS symbol_id,
@@ -895,7 +895,7 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
895
895
  -- Only function-level symbols (ending with ().), not module-level
896
896
  AND gs.symbol LIKE '%().'
897
897
  ${n}
898
- ORDER BY barrel_d.relative_path, gs.symbol`)}function Vb(e,t){return e.get(`SELECT
898
+ ORDER BY barrel_d.relative_path, gs.symbol`)}function aS(e,t){return e.get(`SELECT
899
899
  SUM(CASE WHEN uses_barrel = 1 THEN 1 ELSE 0 END) AS barrel_consumers,
900
900
  SUM(CASE WHEN uses_barrel = 0 THEN 1 ELSE 0 END) AS direct_consumers
901
901
  FROM (
@@ -924,25 +924,25 @@ ${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,e
924
924
  AND consumer_d.id != ?
925
925
  ${e.pathExclusionsFor("consumer_d")}
926
926
  GROUP BY consumer_d.id
927
- )`,t.barrel_doc_id,t.symbol_id,t.barrel_doc_id,t.original_doc_id)}function Ub(e,t,n){let r=[];for(let i of Jb(e,n))Ma(e,i,i)>0||r.push(...qb(e,t,i));return r}function Jb(e,t){return e.all(`SELECT relative_path
927
+ )`,t.barrel_doc_id,t.symbol_id,t.barrel_doc_id,t.original_doc_id)}function lS(e,t,n){let r=[];for(let i of cS(e,n))Ba(e,i,i)>0||r.push(...uS(e,t,i));return r}function cS(e,t){return e.all(`SELECT relative_path
928
928
  FROM documents
929
929
  WHERE 1 = 1
930
930
  ${t?"AND relative_path LIKE ?":""}
931
931
  ${e.pathExclusionsFor("documents")}
932
- ORDER BY relative_path`,...t?[`%${t}%`]:[]).map(r=>r.relative_path).filter(r=>!e.isIgnored(r)).filter(r=>Cr(e,r).length>0)}function qb(e,t,n){return Cr(e,n).filter(r=>r.sourcePath&&!e.isIgnored(r.sourcePath)).flatMap(r=>zb(e,t,n,r.sourcePath))}function zb(e,t,n,r){let i=Gb(t,r);return i?[{barrelFile:n,symbol:i.symbol,shortName:h(i.symbol),originalFile:r,barrelConsumers:0,directConsumers:Ma(e,r,n)}]:[]}function Ma(e,t,n){let r=e.all(`SELECT relative_path
932
+ ORDER BY relative_path`,...t?[`%${t}%`]:[]).map(r=>r.relative_path).filter(r=>!e.isIgnored(r)).filter(r=>Rr(e,r).length>0)}function uS(e,t,n){return Rr(e,n).filter(r=>r.sourcePath&&!e.isIgnored(r.sourcePath)).flatMap(r=>dS(e,t,n,r.sourcePath))}function dS(e,t,n,r){let i=mS(t,r);return i?[{barrelFile:n,symbol:i.symbol,shortName:h(i.symbol),originalFile:r,barrelConsumers:0,directConsumers:Ba(e,r,n)}]:[]}function Ba(e,t,n){let r=e.all(`SELECT relative_path
933
933
  FROM documents
934
934
  WHERE 1 = 1
935
935
  ${e.pathExclusionsFor("documents")}
936
- ORDER BY relative_path`),i=new Set;for(let s of r)if(!(e.isIgnored(s.relative_path)||s.relative_path===n))for(let o of J(e,s.relative_path))o.sourcePath===t&&i.add(s.relative_path);return i.size}function Gb(e,t){let n=e.definitionsForFile(t);return n.find(r=>V(r.symbol)==="method")??n[0]??null}function Kb(e){let t=new Set,n=[];for(let r of e){let i=`${r.barrelFile}|${r.symbol}|${r.originalFile}`;t.has(i)||(t.add(i),n.push(r))}return n}function Qb(e){e.sort((t,n)=>n.directConsumers-t.directConsumers||t.barrelFile.localeCompare(n.barrelFile)||t.shortName.localeCompare(n.shortName))}function Fa(e,t={}){let{scope:n,minLoc:r=1,limit:i}=t,s=new Map;for(let a of oe(e,{scope:n})){if(!a.isFunctionLike||e.isIgnored(a.relativePath))continue;let l=a.endLine-a.startLine+1;if(l<r)continue;let c=Yb(e,a);if(!c)continue;let d={symbol:a.symbol,shortName:h(a.symbol),file:a.relativePath,startLine:a.startLine,endLine:a.endLine,loc:l},u=s.get(c);u?u.push(d):s.set(c,[d])}let o=[];for(let[a,l]of s)l.length<2||o.push({signature:a,functions:l});return o.sort((a,l)=>{let c=l.functions.length-a.functions.length;if(c!==0)return c;let d=a.functions.reduce((m,f)=>m+f.loc,0);return l.functions.reduce((m,f)=>m+f.loc,0)-d}),i?o.slice(0,i):o}function Yb(e,t){let n=eo(e,t);if(n)return n;let r=Xb(t.documentation),i=r?tS(r):null;return i||nS(Zb(e,t.relativePath,t.startLine,t.endLine,t.leaf),t.leaf)}function Xb(e){return We(He(e))}function Zb(e,t,n,r,i){let s=O(e,t);if(!s)return null;let o=s.split(/\r?\n/),a=iS(o,n,r,i);for(let l of a){let c=Math.min(o.length-1,Math.max(l,l+4)),d="";for(let u=l;u<=c;u+=1){let m=o[u]?.trim();if(m&&(d=d?`${d} ${m}`:m,eS(d)))return d}if(d&&d.includes("("))return d}return null}function eS(e){let t=e.replace(/\s+/g," ").trim();return!t.includes("(")||sS(t)>0?!1:/[;{]$/.test(t)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(t)||/\)\s*As\s+.+$/i.test(t)}function tS(e){if(!e||!e.trim())return null;let t=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(),n=t.indexOf("(");return n===-1||(t=t.slice(n),t=t.replace(/\s+/g,"").toLowerCase(),t.length<3)?null:t}function nS(e,t){if(!e||!e.trim())return null;let n=e.replace(/\s+/g," ").trim(),r=n.indexOf("(");if(r===-1)return null;let i=n.slice(0,r),o=new RegExp(`\\b${Ta(t)}\\b`,"i").exec(i);o&&typeof o.index=="number"&&(i=i.slice(0,o.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 a=rS(n.slice(r)).replace(/\)\s*=\s*[\s\S]*$/,")").replace(/\s+throws\s+[^={]+$/i,"").replace(/\s+where\s+.+$/i,"").replace(/\s+/g," ").trim();if(!a.startsWith("("))return null;let l=`${i?`${i} `:""}${a}`.replace(/\s+/g,"").toLowerCase();return l.length>=3?l:null}function rS(e){let t=0,n=0,r=0,i=0,s=null,o=!1;for(let a=0;a<e.length;a+=1){let l=e[a];if(s){if(o){o=!1;continue}if(l==="\\"){o=!0;continue}l===s&&(s=null);continue}if(l==='"'||l==="'"||l==="`"){s=l;continue}if(l==="(")t+=1;else if(l===")")t=Math.max(0,t-1);else if(l==="[")r+=1;else if(l==="]")r=Math.max(0,r-1);else if(l==="<")i+=1;else if(l===">")i=Math.max(0,i-1);else if(l==="{"){if(t===0&&r===0&&i===0)return e.slice(0,a);n+=1}else if(l==="}")n=Math.max(0,n-1);else if(l==="="&&e[a+1]===">"&&t===0&&n===0&&r===0&&i===0)return e.slice(0,a)}return e}function iS(e,t,n,r){let i=Ta(r),s=new RegExp(`\\b${i}\\b\\s*\\(`,"i"),o=new RegExp(`\\bdef\\s+${i}\\b`,"i"),a=[],l=new Set,c=Math.max(0,Math.min(t,e.length-1)),d=Math.max(c,Math.min(e.length-1,Math.max(n,t+4)));for(let u=c;u<=d;u+=1){let m=e[u]??"";(s.test(m)||o.test(m))&&!l.has(u)&&(l.add(u),a.push(u))}for(let u=0;u<e.length;u+=1){let m=e[u]??"";(s.test(m)||o.test(m))&&!l.has(u)&&(l.add(u),a.push(u))}return a}function sS(e){let t=0;for(let n of e)n==="("&&(t+=1),n===")"&&(t-=1);return t}function Ta(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Re(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function Tt(e){let t=Ce(e),n=ve(e,t);return process.env.SCIP_QUERY_INDEX_DB??($a(n.dbPath)?n.dbPath:oS(e,"index.db"))}function aS(){let e=Re(),t=Ce(e),n=ve(e,t),r=Tt(e);$a(r)||(console.error("error: No index.db found. Run: scip-query reindex"),process.exit(1));let i={dbPath:r,indexPath:process.env.SCIP_QUERY_INDEX_SCIP??n.indexPath,projectRoot:e,entryRoots:t.entryRoots,semantic:t.semantic},s=Qe(e);return new Xt(i,s)}function I(e){let t=aS();try{e(t)}finally{t.close()}}function Aa(e,t){return t.concat([e])}function v(e){return parseInt(e,10)}function $r(e){let t=parseInt(e,10);if(!Number.isFinite(t)||t<1)throw new Error(`Expected a positive integer, got ${e}`);return t}function Mn(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 ja(e){switch(e.state){case"idle":return"Watching (idle)";case"waiting":{let t=Math.round((e.reindexAt-Date.now())/1e3);return`${e.changedFiles} file(s) changed, reindexing in ${t}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":""}`}}var uS=lS(import.meta.url),{version:dS}=mS();function mS(){for(let e of["../package.json","../../package.json"])try{return uS(e)}catch{}return{version:"0.0.0"}}function ye(e){console.log(`Heuristic ${e}: review before acting; these are candidates, not exact compiler facts.
937
- `)}S.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(dS);S.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",Aa,[]).option("--pnpm-workspaces","Enable pnpm workspace support (TypeScript)").option("--force","Rebuild even if source inputs are unchanged").option("--allow-partial","Write an incomplete index when one or more detected languages fail").option("--indexer-concurrency <n>","Number of language indexers to run at once",$r).action(async e=>{let t=Re(),n=Ce(t),r=ve(t,n);try{let i=await Li({projectRoot:t,languages:e.language.length>0?e.language:n.languages,outputScip:r.indexPath,outputDb:r.dbPath,pnpmWorkspaces:e.pnpmWorkspaces||n.indexer?.typescript?.pnpmWorkspaces,skipIfUnchanged:!e.force,allowPartial:e.allowPartial,indexerConcurrency:e.indexerConcurrency});console.log(`${i.reused?"Reused":"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)}});S.command("augment-sources").description("Add source files skipped by upstream SCIP indexers to the SQLite documents table").action(()=>{let e=Re(),t=Tt(e);try{let n=Ee({projectRoot:e,dbPath:t,onStatus:r=>console.log(r)});console.log(`Scanned ${n.scanned} auxiliary source files; inserted ${n.inserted}.`)}catch(n){console.error(`error: ${n instanceof Error?n.message:n}`),process.exit(1)}});S.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 t=Re(),n=Tt(t);try{let r=Qn({projectRoot:t,dbPath:n,tsconfig:e.project,onStatus:i=>console.log(i)});console.log(`Vue files: ${r.vueFiles}; resolved references: ${r.resolvedReferences}; inserted mentions: ${r.insertedMentions}.`)}catch(r){console.error(`error: ${r instanceof Error?r.message:r}`),process.exit(1)}});S.command("stats").description("Show index statistics").action(()=>I(e=>{let t=x.stats(e);console.log(`Documents: ${t.documents}`),console.log(`Symbols: ${t.symbols}`),console.log(`Definitions: ${t.definitions}`),console.log(`References: ${t.references}`),console.log(`Index size: ${Mn(t.indexSizeBytes)}`),t.lastBuilt&&console.log(`Last built: ${t.lastBuilt.toISOString().replace("T"," ").slice(0,19)}`)}));S.command("files <pattern>").description("Find files matching a pattern").action(e=>I(t=>{b.list(x.files(t,e),n=>n.relativePath)}));S.command("symbols <file>").description("List symbols defined in a file (with line ranges + signatures)").action(e=>I(t=>{b.list(x.symbols(t,e),n=>{let r=n.signature?` \u2014 ${n.signature}`:"";return` ${me(n.startLine,n.endLine)} ${n.shortName}${r}`})}));S.command("methods <className>").description("List methods of a class (with line ranges)").action(e=>I(t=>{b.list(x.methods(t,e),n=>` ${me(n.startLine,n.endLine)} ${n.name}`)}));S.command("refs <symbol>").description("Find all files referencing a symbol").action(e=>I(t=>{b.groupedByFile(x.refs(t,e),n=>` line ${be(n.line)}`)}));S.command("trace <symbol>").description("Trace a symbol: definition + all references").action(e=>I(t=>{let n=x.trace(t,e),r=[];for(let o of n.definitions){let a=o.signature?` \u2014 ${o.signature}`:"";r.push(` ${pe(o.relativePath,o.startLine,o.endLine)}${a}`),o.source&&r.push(o.source.split(`
936
+ ORDER BY relative_path`),i=new Set;for(let s of r)if(!(e.isIgnored(s.relative_path)||s.relative_path===n))for(let o of J(e,s.relative_path))o.sourcePath===t&&i.add(s.relative_path);return i.size}function mS(e,t){let n=e.definitionsForFile(t);return n.find(r=>V(r.symbol)==="method")??n[0]??null}function pS(e){let t=new Set,n=[];for(let r of e){let i=`${r.barrelFile}|${r.symbol}|${r.originalFile}`;t.has(i)||(t.add(i),n.push(r))}return n}function fS(e){e.sort((t,n)=>n.directConsumers-t.directConsumers||t.barrelFile.localeCompare(n.barrelFile)||t.shortName.localeCompare(n.shortName))}function Wa(e,t={}){let{scope:n,minLoc:r=1,limit:i}=t,s=new Map;for(let a of oe(e,{scope:n})){if(!a.isFunctionLike||e.isIgnored(a.relativePath))continue;let l=a.endLine-a.startLine+1;if(l<r)continue;let c=gS(e,a);if(!c)continue;let u={symbol:a.symbol,shortName:h(a.symbol),file:a.relativePath,startLine:a.startLine,endLine:a.endLine,loc:l},d=s.get(c);d?d.push(u):s.set(c,[u])}let o=[];for(let[a,l]of s)l.length<2||o.push({signature:a,functions:l});return o.sort((a,l)=>{let c=l.functions.length-a.functions.length;if(c!==0)return c;let u=a.functions.reduce((m,g)=>m+g.loc,0);return l.functions.reduce((m,g)=>m+g.loc,0)-u}),i?o.slice(0,i):o}function gS(e,t){let n=oo(e,t);if(n)return n;let r=hS(t.documentation),i=r?SS(r):null;return i||xS(yS(e,t.relativePath,t.startLine,t.endLine,t.leaf),t.leaf)}function hS(e){return He(Ve(e))}function yS(e,t,n,r,i){let s=w(e,t);if(!s)return null;let o=s.split(/\r?\n/),a=IS(o,n,r,i);for(let l of a){let c=Math.min(o.length-1,Math.max(l,l+4)),u="";for(let d=l;d<=c;d+=1){let m=o[d]?.trim();if(m&&(u=u?`${u} ${m}`:m,bS(u)))return u}if(u&&u.includes("("))return u}return null}function bS(e){let t=e.replace(/\s+/g," ").trim();return!t.includes("(")||RS(t)>0?!1:/[;{]$/.test(t)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(t)||/\)\s*As\s+.+$/i.test(t)}function SS(e){if(!e||!e.trim())return null;let t=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(),n=t.indexOf("(");return n===-1||(t=t.slice(n),t=t.replace(/\s+/g,"").toLowerCase(),t.length<3)?null:t}function xS(e,t){if(!e||!e.trim())return null;let n=e.replace(/\s+/g," ").trim(),r=n.indexOf("(");if(r===-1)return null;let i=n.slice(0,r),o=new RegExp(`\\b${Ha(t)}\\b`,"i").exec(i);o&&typeof o.index=="number"&&(i=i.slice(0,o.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 a=_S(n.slice(r)).replace(/\)\s*=\s*[\s\S]*$/,")").replace(/\s+throws\s+[^={]+$/i,"").replace(/\s+where\s+.+$/i,"").replace(/\s+/g," ").trim();if(!a.startsWith("("))return null;let l=`${i?`${i} `:""}${a}`.replace(/\s+/g,"").toLowerCase();return l.length>=3?l:null}function _S(e){let t=0,n=0,r=0,i=0,s=null,o=!1;for(let a=0;a<e.length;a+=1){let l=e[a];if(s){if(o){o=!1;continue}if(l==="\\"){o=!0;continue}l===s&&(s=null);continue}if(l==='"'||l==="'"||l==="`"){s=l;continue}if(l==="(")t+=1;else if(l===")")t=Math.max(0,t-1);else if(l==="[")r+=1;else if(l==="]")r=Math.max(0,r-1);else if(l==="<")i+=1;else if(l===">")i=Math.max(0,i-1);else if(l==="{"){if(t===0&&r===0&&i===0)return e.slice(0,a);n+=1}else if(l==="}")n=Math.max(0,n-1);else if(l==="="&&e[a+1]===">"&&t===0&&n===0&&r===0&&i===0)return e.slice(0,a)}return e}function IS(e,t,n,r){let i=Ha(r),s=new RegExp(`\\b${i}\\b\\s*\\(`,"i"),o=new RegExp(`\\bdef\\s+${i}\\b`,"i"),a=[],l=new Set,c=Math.max(0,Math.min(t,e.length-1)),u=Math.max(c,Math.min(e.length-1,Math.max(n,t+4)));for(let d=c;d<=u;d+=1){let m=e[d]??"";(s.test(m)||o.test(m))&&!l.has(d)&&(l.add(d),a.push(d))}for(let d=0;d<e.length;d+=1){let m=e[d]??"";(s.test(m)||o.test(m))&&!l.has(d)&&(l.add(d),a.push(d))}return a}function RS(e){let t=0;for(let n of e)n==="("&&(t+=1),n===")"&&(t-=1);return t}function Ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ce(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function Tt(e){let t=ve(e),n=Ne(e,t);return process.env.SCIP_QUERY_INDEX_DB??(Va(n.dbPath)?n.dbPath:CS(e,"index.db"))}function vS(){let e=Ce(),t=ve(e),n=Ne(e,t),r=Tt(e);Va(r)||(console.error("error: No index.db found. Run: scip-query reindex"),process.exit(1));let i={dbPath:r,indexPath:process.env.SCIP_QUERY_INDEX_SCIP??n.indexPath,projectRoot:e,entryRoots:t.entryRoots,semantic:t.semantic},s=Ye(e);return new Xt(i,s)}function I(e){let t=vS();try{e(t)}finally{t.close()}}function Ua(e,t){return t.concat([e])}function v(e){return parseInt(e,10)}function $r(e){let t=parseInt(e,10);if(!Number.isFinite(t)||t<1)throw new Error(`Expected a positive integer, got ${e}`);return t}function On(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 Ja(e){switch(e.state){case"idle":return"Watching (idle)";case"waiting":{let t=Math.round((e.reindexAt-Date.now())/1e3);return`${e.changedFiles} file(s) changed, reindexing in ${t}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":""}`;default:return NS(e)}}function NS(e){throw new Error(`Unhandled watcher status: ${JSON.stringify(e)}`)}var LS=ES(import.meta.url),{version:kS}=wS();function wS(){for(let e of["../package.json","../../package.json"])try{return LS(e)}catch{}return{version:"0.0.0"}}function ye(e){console.log(`Heuristic ${e}: review before acting; these are candidates, not exact compiler facts.
937
+ `)}S.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(kS);S.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",Ua,[]).option("--pnpm-workspaces","Enable pnpm workspace support (TypeScript)").option("--force","Rebuild even if source inputs are unchanged").option("--allow-partial","Write an incomplete index when one or more detected languages fail").option("--indexer-concurrency <n>","Number of language indexers to run at once",$r).action(async e=>{let t=Ce(),n=ve(t),r=Ne(t,n);try{let i=await ki({projectRoot:t,languages:e.language.length>0?e.language:n.languages,outputScip:r.indexPath,outputDb:r.dbPath,pnpmWorkspaces:e.pnpmWorkspaces||n.indexer?.typescript?.pnpmWorkspaces,skipIfUnchanged:!e.force,allowPartial:e.allowPartial,indexerConcurrency:e.indexerConcurrency});console.log(`${i.reused?"Reused":"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)}});S.command("augment-sources").description("Add source files skipped by upstream SCIP indexers to the SQLite documents table").action(()=>{let e=Ce(),t=Tt(e);try{let n=De({projectRoot:e,dbPath:t,onStatus:r=>console.log(r)});console.log(`Scanned ${n.scanned} auxiliary source files; inserted ${n.inserted}.`)}catch(n){console.error(`error: ${n instanceof Error?n.message:n}`),process.exit(1)}});S.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 t=Ce(),n=Tt(t);try{let r=Kn({projectRoot:t,dbPath:n,tsconfig:e.project,onStatus:i=>console.log(i)});console.log(`Vue files: ${r.vueFiles}; resolved references: ${r.resolvedReferences}; inserted mentions: ${r.insertedMentions}.`)}catch(r){console.error(`error: ${r instanceof Error?r.message:r}`),process.exit(1)}});S.command("stats").description("Show index statistics").action(()=>I(e=>{let t=x.stats(e);console.log(`Documents: ${t.documents}`),console.log(`Symbols: ${t.symbols}`),console.log(`Definitions: ${t.definitions}`),console.log(`References: ${t.references}`),console.log(`Index size: ${On(t.indexSizeBytes)}`),t.lastBuilt&&console.log(`Last built: ${t.lastBuilt.toISOString().replace("T"," ").slice(0,19)}`)}));S.command("files <pattern>").description("Find files matching a pattern").action(e=>I(t=>{b.list(x.files(t,e),n=>n.relativePath)}));S.command("symbols <file>").description("List symbols defined in a file (with line ranges + signatures)").action(e=>I(t=>{b.list(x.symbols(t,e),n=>{let r=n.signature?` \u2014 ${n.signature}`:"";return` ${me(n.startLine,n.endLine)} ${n.shortName}${r}`})}));S.command("methods <className>").description("List methods of a class (with line ranges)").action(e=>I(t=>{b.list(x.methods(t,e),n=>` ${me(n.startLine,n.endLine)} ${n.name}`)}));S.command("refs <symbol>").description("Find all files referencing a symbol").action(e=>I(t=>{b.groupedByFile(x.refs(t,e),n=>` line ${be(n.line)}`)}));S.command("trace <symbol>").description("Trace a symbol: definition + all references").action(e=>I(t=>{let n=x.trace(t,e),r=[];for(let o of n.definitions){let a=o.signature?` \u2014 ${o.signature}`:"";r.push(` ${pe(o.relativePath,o.startLine,o.endLine)}${a}`),o.source&&r.push(o.source.split(`
938
938
  `).map((l,c)=>` ${be(o.startLine+c)} ${l}`).join(`
939
- `))}let i=[],s="";for(let o of n.referencedBy)o.relativePath!==s&&(s&&i.push(""),i.push(` ${o.relativePath}`),s=o.relativePath),i.push(` line ${be(o.line)} in ${o.enclosingShort}`);b.sectionedReport([{title:"DEFINITION",rows:r},{title:"REFERENCED BY",rows:i}])}));S.command("deps <file>").description("Files this file depends on (internal)").action(e=>I(t=>{b.list(x.deps(t,e),n=>n.relativePath)}));S.command("rdeps <file>").description("Files that depend on this file/module").action(e=>I(t=>{b.list(x.rdeps(t,e),n=>n.relativePath)}));S.command("system <module>").description("Full module map: files, symbols, deps in/out").action(e=>I(t=>{let n=x.system(t,e);b.sectionedReport([{title:"FILES",rows:n.files},{title:"EXPORTED SYMBOLS",rows:n.symbols.map(r=>` ${me(r.startLine,r.endLine)} ${r.shortName}`)},{title:"DEPENDS ON (internal)",rows:n.dependsOn.map(r=>` ${r}`)},{title:"DEPENDED ON BY",rows:n.dependedOnBy.map(r=>` ${r}`)}])}));S.command("surface <module>").description("What symbols consumers actually use from this module").action(e=>I(t=>{b.list(x.surface(t,e),n=>` ${n.consumer} \u2192 ${n.shortName}`)}));S.command("dead [scope]").description("Find dead code and file-internal symbols (no cross-file consumers)").option("--min-loc <n>","Only show symbols >= N lines",v,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,t)=>I(n=>{let r={scope:e||void 0,minLoc:t.minLoc,includeTests:t.includeTests,skipBarrels:t.skipBarrels,includeMembers:t.includeMembers},i=x.dead(n,r),s=i.symbols.filter(g=>g.kind==="dead-code"),o=i.symbols.filter(g=>g.kind!=="dead-code"),a=!t.onlyInternal,l=!t.onlyDead,c=a?s:[],d=l?o:[];if(c.length===0&&d.length===0)return b.empty("No matching dead-code symbols found.");let u=(g,y,E,N)=>{console.log(`\u2550\u2550\u2550 ${y} (${g.length}, ${N} LOC) \u2550\u2550\u2550`),console.log(E),console.log("");let F=new Map;for(let _ of g){let P=F.get(_.relativePath)??[];P.push(_),F.set(_.relativePath,P)}let T=[...F.entries()].map(([_,P])=>({file:_,bucket:P,totalLoc:P.reduce((D,z)=>D+z.loc,0)})).sort((_,P)=>P.totalLoc-_.totalLoc||_.file.localeCompare(P.file)),R=!0;for(let{file:_,bucket:P}of T){R||console.log(""),R=!1,console.log(` ${_}`),P.sort((D,z)=>D.startLine-z.startLine);for(let D of P)console.log(` ${me(D.startLine,D.endLine)} (${D.loc} LOC) ${D.shortName}`)}},m=c.reduce((g,y)=>g+y.loc,0),f=d.reduce((g,y)=>g+y.loc,0);c.length>0&&u(c,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
940
- Safe to delete.`,m),d.length>0&&(c.length>0&&console.log(""),u(d,"FILE-INTERNAL ONLY",` Used only within the same file (no cross-file callers). Could be a
939
+ `))}let i=[],s="";for(let o of n.referencedBy)o.relativePath!==s&&(s&&i.push(""),i.push(` ${o.relativePath}`),s=o.relativePath),i.push(` line ${be(o.line)} in ${o.enclosingShort}`);b.sectionedReport([{title:"DEFINITION",rows:r},{title:"REFERENCED BY",rows:i}])}));S.command("deps <file>").description("Files this file depends on (internal)").action(e=>I(t=>{b.list(x.deps(t,e),n=>n.relativePath)}));S.command("rdeps <file>").description("Files that depend on this file/module").action(e=>I(t=>{b.list(x.rdeps(t,e),n=>n.relativePath)}));S.command("system <module>").description("Full module map: files, symbols, deps in/out").action(e=>I(t=>{let n=x.system(t,e);b.sectionedReport([{title:"FILES",rows:n.files},{title:"EXPORTED SYMBOLS",rows:n.symbols.map(r=>` ${me(r.startLine,r.endLine)} ${r.shortName}`)},{title:"DEPENDS ON (internal)",rows:n.dependsOn.map(r=>` ${r}`)},{title:"DEPENDED ON BY",rows:n.dependedOnBy.map(r=>` ${r}`)}])}));S.command("surface <module>").description("What symbols consumers actually use from this module").action(e=>I(t=>{b.list(x.surface(t,e),n=>` ${n.consumer} \u2192 ${n.shortName}`)}));S.command("dead [scope]").description("Find dead code and file-internal symbols (no cross-file consumers)").option("--min-loc <n>","Only show symbols >= N lines",v,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,t)=>I(n=>{let r={scope:e||void 0,minLoc:t.minLoc,includeTests:t.includeTests,skipBarrels:t.skipBarrels,includeMembers:t.includeMembers},i=x.dead(n,r),s=i.symbols.filter(f=>f.kind==="dead-code"),o=i.symbols.filter(f=>f.kind!=="dead-code"),a=!t.onlyInternal,l=!t.onlyDead,c=a?s:[],u=l?o:[];if(c.length===0&&u.length===0)return b.empty("No matching dead-code symbols found.");let d=(f,y,L,k)=>{console.log(`\u2550\u2550\u2550 ${y} (${f.length}, ${k} LOC) \u2550\u2550\u2550`),console.log(L),console.log("");let F=new Map;for(let _ of f){let O=F.get(_.relativePath)??[];O.push(_),F.set(_.relativePath,O)}let T=[...F.entries()].map(([_,O])=>({file:_,bucket:O,totalLoc:O.reduce((N,z)=>N+z.loc,0)})).sort((_,O)=>O.totalLoc-_.totalLoc||_.file.localeCompare(O.file)),R=!0;for(let{file:_,bucket:O}of T){R||console.log(""),R=!1,console.log(` ${_}`),O.sort((N,z)=>N.startLine-z.startLine);for(let N of O)console.log(` ${me(N.startLine,N.endLine)} (${N.loc} LOC) ${N.shortName}`)}},m=c.reduce((f,y)=>f+y.loc,0),g=u.reduce((f,y)=>f+y.loc,0);c.length>0&&d(c,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
940
+ Safe to delete.`,m),u.length>0&&(c.length>0&&console.log(""),d(u,"FILE-INTERNAL ONLY",` Used only within the same file (no cross-file callers). Could be a
941
941
  single-use helper, an abstraction-in-progress, or a callback registered
942
942
  through a framework path that static analysis cannot trace (signal
943
943
  handlers, event listeners, dependency injection). NOT necessarily dead \u2014
944
- review case by case.`,f));let p=[];a&&p.push(`${c.length} dead code (${m} LOC)`),l&&p.push(`${d.length} file-internal (${f} LOC)`),console.log(`
945
- \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: ${c.length+d.length} symbols \u2014 ${p.join(" + ")}`)}));S.command("hotspots").description("Most-referenced symbols in the codebase (choke points)").option("-n, --limit <n>","Number of results",v,30).option("-s, --scope <path>","Limit to files matching path").action(e=>I(t=>{let n=x.hotspots(t,{limit:e.limit,scope:e.scope});b.table(["refs","files","symbol"],n.map(r=>` ${String(r.refCount).padStart(4)} ${String(r.fileCount).padStart(5)} ${r.shortName}`))}));S.command("imports <file>").description("What symbols does this file import?").action(e=>I(t=>{let n=x.imports(t,e);if(n.length===0){b.empty("No imports found (indexer may not emit role=2 for this language).");return}b.list(n,r=>` ${r.shortName} \u2190 ${r.fromFile}`)}));S.command("imported-by <symbol>").description("Which files import this symbol?").action(e=>I(t=>{b.list(x.importedBy(t,e),n=>` ${n.fromFile}`)}));S.command("unused-imports <file>").description("Find imports not referenced in the same file").action(e=>I(t=>{let n=x.unusedImports(t,e);if(n.length===0)return b.empty("No unused imports found.");b.list(n,r=>` ${r.shortName} in ${r.importedIn}`),console.log(`
944
+ review case by case.`,g));let p=[];a&&p.push(`${c.length} dead code (${m} LOC)`),l&&p.push(`${u.length} file-internal (${g} LOC)`),console.log(`
945
+ \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: ${c.length+u.length} symbols \u2014 ${p.join(" + ")}`)}));S.command("hotspots").description("Most-referenced symbols in the codebase (choke points)").option("-n, --limit <n>","Number of results",v,30).option("-s, --scope <path>","Limit to files matching path").action(e=>I(t=>{let n=x.hotspots(t,{limit:e.limit,scope:e.scope});b.table(["refs","files","symbol"],n.map(r=>` ${String(r.refCount).padStart(4)} ${String(r.fileCount).padStart(5)} ${r.shortName}`))}));S.command("imports <file>").description("What symbols does this file import?").action(e=>I(t=>{let n=x.imports(t,e);if(n.length===0){b.empty("No imports found (indexer may not emit role=2 for this language).");return}b.list(n,r=>` ${r.shortName} \u2190 ${r.fromFile}`)}));S.command("imported-by <symbol>").description("Which files import this symbol?").action(e=>I(t=>{b.list(x.importedBy(t,e),n=>` ${n.fromFile}`)}));S.command("unused-imports <file>").description("Find imports not referenced in the same file").action(e=>I(t=>{let n=x.unusedImports(t,e);if(n.length===0)return b.empty("No unused imports found.");b.list(n,r=>` ${r.shortName} in ${r.importedIn}`),console.log(`
946
946
  ${n.length} unused import(s)`)}));S.command("outline <file>").description("Tree view of symbols in a file (using nesting hierarchy)").action(e=>I(t=>{let n=x.outline(t,e);function r(i,s){for(let o of i){let a=" ".repeat(s);console.log(`${a}${me(o.startLine,o.endLine)} ${o.shortName}`),r(o.children,s+1)}}r(n,0)}));S.command("members <symbol>").description("All children of a symbol (methods, fields, nested types)").action(e=>I(t=>{b.list(x.members(t,e),n=>` ${me(n.startLine,n.endLine)} [${n.kind}] ${n.shortName}`)}));S.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",v,30).option("-s, --scope <path>","Limit to files matching path").action((e,t)=>I(n=>{if(e){let r=x.fanIn(n,e);if(r.length===0)return b.empty(`No fan-in for ${e}.`);b.list(r,i=>` ${String(i.count).padStart(4)} files ${i.name}`)}else b.table(["files","symbol"],x.topFanIn(n,{limit:t.limit,scope:t.scope}).map(r=>` ${String(r.count).padStart(5)} ${r.name}`))}));S.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",v,30).option("-s, --scope <path>","Limit to files matching path").action((e,t)=>I(n=>{if(e){let r=x.fanOut(n,e);if(r.length===0)return b.empty(`No fan-out for ${e}.`);b.list(r,i=>` ${String(i.count).padStart(4)} symbols ${i.name}`)}else b.table(["symbols","file"],x.topFanOut(n,{limit:t.limit,scope:t.scope}).map(r=>` ${String(r.count).padStart(7)} ${r.name}`))}));S.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",v,20).option("-s, --scope <path>","Limit to files matching path").action((e,t,n)=>I(r=>{if(e&&t){let i=x.coupling(r,e,t);console.log(`${i.file1} \u2194 ${i.file2}: ${i.sharedSymbols} shared symbols`)}else b.table(["shared","file1 \u2192 file2"],x.topCoupling(r,{limit:n.limit,scope:n.scope}).map(i=>` ${String(i.sharedSymbols).padStart(6)} ${i.file1} \u2192 ${i.file2}`))}));S.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",v,10).action(e=>I(t=>{let n=x.cycles(t,{scope:e.scope,maxDepth:e.maxDepth});if(n.length===0)return b.empty("No circular dependencies found.");let r=n.filter(s=>s.kind==="real"),i=n.filter(s=>s.kind==="module-hierarchy");for(let s=0;s<r.length;s++){console.log(`
947
947
  Cycle ${s+1} (${r[s].path.length-1} files):`);for(let o=0;o<r[s].path.length;o++){let a=o<r[s].path.length-1?" \u2192":" (cycle)";console.log(` ${r[s].path[o]}${a}`)}}r.length===0?console.log("No real circular dependencies found."):console.log(`
948
948
  ${r.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.)`)}));S.command("bottlenecks").description("Find coupling hubs: high fan-in AND high fan-out").option("-n, --limit <n>","Number of results",v,20).option("-s, --scope <path>","Limit to files matching path").option("--min-fan-in <n>","Minimum fan-in",v,2).option("--min-fan-out <n>","Minimum fan-out",v,2).action(e=>I(t=>{let n=x.bottlenecks(t,{limit:e.limit,scope:e.scope,minFanIn:e.minFanIn,minFanOut:e.minFanOut});if(n.length===0)return b.empty("No bottlenecks found.");b.table(["score","fan-in","fan-out","symbol"],n.map(r=>` ${String(r.score).padStart(5)} ${String(r.fanIn).padStart(6)} ${String(r.fanOut).padStart(7)} ${r.shortName}`))}));S.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",v,3).action(e=>I(t=>{let n=x.isolated(t,{scope:e.scope,minLoc:e.minLoc});if(n.length===0)return b.empty("No isolated symbols found.");b.groupedByFile(n,r=>` ${me(r.startLine,r.endLine)} (${r.loc} LOC) ${r.shortName}`),console.log(`
@@ -977,7 +977,7 @@ ${n.length} passthrough candidate(s).`)}));S.command("stale-abstractions").descr
977
977
  ${r.reason}`}),console.log(`
978
978
  ${n.length} stale abstraction(s).`)}));S.command("complexity-hotspots").description("Find heuristic complexity hotspot candidates from LOC x fan-in x fan-out").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",v,10).option("-n, --limit <n>","Number of results",v,20).action(e=>I(t=>{let n=x.complexityHotspots(t,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(n.length===0)return b.empty("No complexity hotspots found.");ye("complexity hotspot candidates"),b.table(["score"," LOC","fan-in","fan-out","callees","symbol"],n.map(r=>` ${r.score.toFixed(1).padStart(5)} ${String(r.loc).padStart(4)} ${String(r.fanIn).padStart(6)} ${String(r.fanOut).padStart(7)} ${String(r.calleeCount).padStart(7)} ${r.shortName}`),[5,4,6,7,7,6])}));S.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=>I(t=>{let n=x.health(t,{scope:e.scope});if(e.json){console.log(JSON.stringify(n,null,2));return}console.log(`
979
979
  Codebase Health Score: ${n.score}/100
980
- `),console.log(` ${n.overview.documents} files | ${n.overview.symbols} symbols | ${Mn(n.overview.indexSizeBytes)}
980
+ `),console.log(` ${n.overview.documents} files | ${n.overview.symbols} symbols | ${On(n.overview.indexSizeBytes)}
981
981
  `),console.log(" Findings:");let r=n.findings;if(r.deadSymbols>0&&console.log(` Dead code: ${r.deadSymbols} symbols (${r.deadLoc} LOC)`),r.isolatedSymbols>0&&console.log(` Isolated symbols: ${r.isolatedSymbols} (${r.isolatedLoc} LOC)`),r.cycles>0&&console.log(` Circular deps: ${r.cycles}`),r.similarPairs>0&&console.log(` Similar pairs: ${r.similarPairs}`),r.extractionCandidates>0&&console.log(` Extract candidates: ${r.extractionCandidates}`),r.wrappers>0&&console.log(` Wrapper functions: ${r.wrappers}`),r.passthroughs>0&&console.log(` Passthroughs: ${r.passthroughs}`),r.staleTypes>0&&console.log(` Stale abstractions: ${r.staleTypes}`),r.driftedFiles>0&&console.log(` Pattern drift: ${r.driftedFiles} files`),r.complexityHotspotCount>0&&console.log(` Complexity hotspots: ${r.complexityHotspotCount}`),n.actions.length>0){console.log(`
982
982
  Prioritized Actions (highest impact + lowest effort first):`);for(let i=0;i<n.actions.length;i++){let s=n.actions[i],o=s.locRecoverable>0?` (~${s.locRecoverable} LOC recoverable)`:"";console.log(` ${i+1}. [${s.effort} effort / ${s.impact} impact] ${s.description}${o}`)}}if(n.topComplexity.length>0){console.log(`
983
983
  Top Complexity Hotspots:`);for(let i of n.topComplexity)console.log(` ${i.score.toFixed(1).padStart(6)} ${i.symbol}`)}n.actions.length===0&&console.log(`
@@ -997,20 +997,20 @@ ${Math.round(r.similarity*100)}% callee overlap
997
997
  \u2550\u2550\u2550 CONSUMERS (this feeds into) \u2550\u2550\u2550`);for(let r of n.consumers)console.log(` ${r.file} ${r.shortName}`)}}));S.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",v,3).action((e,t)=>I(n=>{let r=t.forward?"forward":"backward",i=x.slice(n,e,{direction:r,maxDepth:t.depth});if(!i)return b.empty("Symbol not found.");if(console.log(`${i.direction} slice of ${i.shortName}
998
998
  `),i.connectedSymbols.length===0){console.log(" No connected symbols found.");return}b.list(i.connectedSymbols,s=>` ${s.file} ${s.shortName}
999
999
  ${s.relationship}`),console.log(`
1000
- ${i.connectedSymbols.length} connected symbol(s).`)}));S.command("install-skills").description(`Install skills (${or.join(", ")}) into Claude Code and Codex`).action(()=>{let e=Ti(),t=e.installed.length+e.alreadyLinked.length;console.log(`
1001
- ${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),t>0&&console.log("Skills will be available in your next Claude Code / Codex session.")});S.command("check-deps").description("Check whether scip-query and the detected language indexers are actually runnable").action(()=>{let e=!1;Tn()?console.log("scip CLI: installed"):($n(),e=!0);let t=Re(),n=Ce(t),r=n.languages??Ae(t);if(r.length===0){console.log(`
1000
+ ${i.connectedSymbols.length} connected symbol(s).`)}));S.command("install-skills").description(`Install skills (${sr.join(", ")}) into Claude Code and Codex`).action(()=>{let e=$i(),t=e.installed.length+e.alreadyLinked.length;console.log(`
1001
+ ${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),t>0&&console.log("Skills will be available in your next Claude Code / Codex session.")});S.command("check-deps").description("Check whether scip-query and the detected language indexers are actually runnable").action(()=>{let e=!1;Fn()?console.log("scip CLI: installed"):(Tn(),e=!0);let t=Ce(),n=ve(t),r=n.languages??je(t);if(r.length===0){console.log(`
1002
1002
  No supported project languages detected in the current directory.`),process.exitCode=e?1:0;return}console.log(`
1003
1003
  Detected languages: ${r.join(", ")}`),console.log(`
1004
- Indexer readiness:`);for(let i of r){let s=fi(Vt(i),t),o=s.runnable?" OK":s.installed?" WARN":" MISSING",a=s.resolvedBinary?` (${s.resolvedBinary})`:"";console.log(`${o} ${i}: ${s.binaryLabel}${a}`),s.note&&console.log(` ${s.note}`),!s.installed&&s.installUrl&&console.log(` install: ${s.installUrl}`),s.runnable||(e=!0)}if(r.includes("typescript")){let i=rr(t,n.semantic?.typescript?.tsconfigs),s=i.available?" OK":i.dependencyAvailable?" WARN":" MISSING",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`
1004
+ Indexer readiness:`);for(let i of r){let s=gi(Vt(i),t),o=s.runnable?" OK":s.installed?" WARN":" MISSING",a=s.resolvedBinary?` (${s.resolvedBinary})`:"";console.log(`${o} ${i}: ${s.binaryLabel}${a}`),s.note&&console.log(` ${s.note}`),!s.installed&&s.installUrl&&console.log(` install: ${s.installUrl}`),s.runnable||(e=!0)}if(r.includes("typescript")){let i=nr(t,n.semantic?.typescript?.tsconfigs),s=i.available?" OK":i.dependencyAvailable?" WARN":" MISSING",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`
1005
1005
  Semantic provider readiness:`),console.log(`${s} typescript: ts-morph${o}`),i.reason&&console.log(` ${i.reason}; semantic checks will fall back to SCIP/source evidence`)}process.exitCode=e?1:0});S.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",v,30).action(e=>I(t=>{let n=x.redundantReexports(t,{scope:e.scope,limit:e.limit});if(n.length===0)return b.empty("No redundant re-exports found.");b.groupedByFile(n,r=>` ${r.shortName} (from ${r.originalFile})
1006
1006
  barrel: ${r.barrelConsumers} consumer(s) | direct: ${r.directConsumers} consumer(s)`,r=>r.barrelFile),console.log(`
1007
1007
  ${n.length} redundant re-export(s).`)}));S.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",v,3).option("-n, --limit <n>","Number of groups",v,20).action(e=>I(t=>{let n=x.similarSignatures(t,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(n.length===0)return b.empty("No same-shape function groups found.");b.list(n,r=>{let i=`
1008
1008
  Signature: ${r.signature} (${r.functions.length} functions)`,s=r.functions.map(o=>` ${pe(o.file,o.startLine,o.endLine)} ${o.shortName} (${o.loc} LOC)`).join(`
1009
1009
  `);return`${i}
1010
1010
  ${s}`}),console.log(`
1011
- ${n.length} group(s) found.`)}));S.command("init").description("Create a .scipquery.json config file for this project").action(()=>{let e=Re(),t=Ae(e),n=Hr(e,t);console.log(`Config written to ${n}`),console.log(`Detected languages: ${t.join(", ")||"(none)"}`)});S.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 t=Re(),n=Ce(t);e.debounce&&((n.watch??={}).debounceMs=e.debounce),e.cooldown&&((n.watch??={}).cooldownMs=e.cooldown);let r=new Qt({projectRoot:t,config:n,languages:n.languages,onStatus:i=>{process.stdout.write(`\r\x1B[K${ja(i)}`)},onReindexComplete:i=>{console.log(`
1011
+ ${n.length} group(s) found.`)}));S.command("init").description("Create a .scipquery.json config file for this project").action(()=>{let e=Ce(),t=je(e),n=Hr(e,t);console.log(`Config written to ${n}`),console.log(`Detected languages: ${t.join(", ")||"(none)"}`)});S.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 t=Ce(),n=ve(t);e.debounce&&((n.watch??={}).debounceMs=e.debounce),e.cooldown&&((n.watch??={}).cooldownMs=e.cooldown);let r=new Yt({projectRoot:t,config:n,languages:n.languages,onStatus:i=>{process.stdout.write(`\r\x1B[K${Ja(i)}`)},onReindexComplete:i=>{console.log(`
1012
1012
  Reindex complete in ${(i/1e3).toFixed(1)}s`)},onError:i=>{console.error(`
1013
1013
  Watch error: ${i.message}`)}});console.log(`Watching ${t}`),console.log(`Debounce: ${n.watch?.debounceMs??3e4}ms | Cooldown: ${n.watch?.cooldownMs??6e4}ms`),console.log(`Press Ctrl+C to stop.
1014
1014
  `),r.start(),process.on("SIGINT",()=>{r.stop(),console.log(`
1015
- Stopped.`),process.exit(0)})});S.command("status").description("Show index status for this project").action(()=>{let e=Re(),t=Ce(e),n=ve(e,t),r=Tt(e);if(console.log(`Project: ${e}`),console.log(`DB path: ${r}`),r!==n.dbPath&&console.log(`Config: ${n.dbPath} (fallback to project root index.db)`),(t.languages??Ae(e)).includes("typescript")){let i=rr(e,t.semantic?.typescript?.tsconfigs),s=i.available?"available":"fallback",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`TS sem: ${s}${o}`),i.reason&&console.log(`TS note: ${i.reason}`)}console.log(`Exists: ${Ba(r)?"yes":"no"}`),Ba(r)&&I(i=>{let s=x.stats(i);if(console.log(`Symbols: ${s.symbols}`),console.log(`Files: ${s.documents}`),console.log(`Size: ${Mn(s.indexSizeBytes)}`),s.lastBuilt){let o=Math.round((Date.now()-s.lastBuilt.getTime())/1e3);console.log(`Built: ${o}s ago`)}})});pS()&&S.parse();function pS(){if(!process.argv[1])return!1;let e=cS(import.meta.url);try{return Wa(e)===Wa(process.argv[1])}catch{return e===process.argv[1]}}export{S as program,ye as renderHeuristicNotice};
1015
+ Stopped.`),process.exit(0)})});S.command("status").description("Show index status for this project").action(()=>{let e=Ce(),t=ve(e),n=Ne(e,t),r=Tt(e);if(console.log(`Project: ${e}`),console.log(`DB path: ${r}`),r!==n.dbPath&&console.log(`Config: ${n.dbPath} (fallback to project root index.db)`),(t.languages??je(e)).includes("typescript")){let i=nr(e,t.semantic?.typescript?.tsconfigs),s=i.available?"available":"fallback",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`TS sem: ${s}${o}`),i.reason&&console.log(`TS note: ${i.reason}`)}console.log(`Exists: ${qa(r)?"yes":"no"}`),qa(r)&&I(i=>{let s=x.stats(i);if(console.log(`Symbols: ${s.symbols}`),console.log(`Files: ${s.documents}`),console.log(`Size: ${On(s.indexSizeBytes)}`),s.lastBuilt){let o=Math.round((Date.now()-s.lastBuilt.getTime())/1e3);console.log(`Built: ${o}s ago`)}})});PS()&&S.parse();function PS(){if(!process.argv[1])return!1;let e=DS(import.meta.url);try{return za(e)===za(process.argv[1])}catch{return e===process.argv[1]}}export{S as program,ye as renderHeuristicNotice};
1016
1016
  //# sourceMappingURL=cli.js.map