scip-query 0.19.0 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +17 -1
  3. package/dist/augment-vue-worker.js +1 -1
  4. package/dist/{chunk-YHYTDWFT.js → chunk-24ET4VLC.js} +2 -2
  5. package/dist/{chunk-GBB2RUDN.js → chunk-26JI77AY.js} +130 -130
  6. package/dist/{chunk-MFBXBLHA.js → chunk-2E7QY4B5.js} +2 -2
  7. package/dist/{chunk-PXJIEMND.js → chunk-2ROSOG2I.js} +2 -2
  8. package/dist/{chunk-XKWEMFHP.js → chunk-2WCXKANA.js} +2 -2
  9. package/dist/{chunk-EZGT3NJX.js → chunk-33RLKB6L.js} +2 -2
  10. package/dist/{chunk-GJ3FR5WG.js → chunk-34MLC6UI.js} +2 -2
  11. package/dist/{chunk-G6RQVDTI.js → chunk-4BUMNEYQ.js} +2 -2
  12. package/dist/{chunk-XTSVYYAL.js → chunk-4CZJ4YJB.js} +2 -2
  13. package/dist/{chunk-TCVRJ56J.js → chunk-4FMT4HPC.js} +2 -2
  14. package/dist/{chunk-7FG5M53V.js → chunk-53SUJOJA.js} +2 -2
  15. package/dist/{chunk-AEDB4WXE.js → chunk-5FUAFNMP.js} +2 -2
  16. package/dist/chunk-5GCAM4JE.js +122 -0
  17. package/dist/{chunk-YBAC3RON.js → chunk-5GOBZI34.js} +2 -2
  18. package/dist/{chunk-LJD7V7UO.js → chunk-5OR4QRPR.js} +2 -2
  19. package/dist/{chunk-X36LKKVG.js → chunk-5OZCNAVM.js} +2 -2
  20. package/dist/{chunk-7EI4MU5A.js → chunk-5TZ2MQBG.js} +2 -2
  21. package/dist/{chunk-GNJHHPZE.js → chunk-64QITTX7.js} +2 -2
  22. package/dist/{chunk-HOXI4F5I.js → chunk-6EWBPAA3.js} +2 -2
  23. package/dist/{chunk-EZHARAL4.js → chunk-6FIA5BEB.js} +2 -2
  24. package/dist/{chunk-4ZCNFENR.js → chunk-77IOFJVY.js} +2 -2
  25. package/dist/{chunk-T5CSWYAZ.js → chunk-AD7WUFFT.js} +2 -2
  26. package/dist/{chunk-OGHGTD6Z.js → chunk-AEM24WSF.js} +2 -2
  27. package/dist/{chunk-S65OEY2G.js → chunk-AFVU2GB2.js} +2 -2
  28. package/dist/{chunk-SATRCB5O.js → chunk-AOSFSYEA.js} +2 -2
  29. package/dist/{chunk-3OSRXJKK.js → chunk-APLNTJPJ.js} +2 -2
  30. package/dist/{chunk-TDGCALH6.js → chunk-AYRHVJXW.js} +2 -2
  31. package/dist/{chunk-MDDF67O2.js → chunk-B26UX7ZD.js} +2 -2
  32. package/dist/{chunk-JFGUBZWE.js → chunk-C3KCSAQ4.js} +2 -2
  33. package/dist/{chunk-XESK6725.js → chunk-C3VQZFP2.js} +2 -2
  34. package/dist/{chunk-FLIF3JWA.js → chunk-CAKPEQZB.js} +2 -2
  35. package/dist/{chunk-PKAPOFF5.js → chunk-CIYUFF24.js} +2 -2
  36. package/dist/{chunk-J3U47L4Q.js → chunk-DO775SYA.js} +2 -2
  37. package/dist/{chunk-AM2LGOEX.js → chunk-EGKWRX5I.js} +2 -2
  38. package/dist/{chunk-PAZFJMXB.js → chunk-EHU4TZJJ.js} +2 -2
  39. package/dist/{chunk-YYR7ADNB.js → chunk-EII5ZHL2.js} +2 -2
  40. package/dist/{chunk-F5L7WEZF.js → chunk-EYF5HOUZ.js} +2 -2
  41. package/dist/{chunk-RIGY5DDE.js → chunk-FB6IKAKZ.js} +2 -2
  42. package/dist/{chunk-BGUYAA3Q.js → chunk-FBUNGRKI.js} +2 -2
  43. package/dist/{chunk-M2TRDR25.js → chunk-FC5K7T35.js} +1 -1
  44. package/dist/{chunk-KWBA6FDD.js → chunk-FRXB74RQ.js} +2 -2
  45. package/dist/{chunk-BYPVNKJT.js → chunk-FTRNGQGR.js} +2 -2
  46. package/dist/{chunk-54UYBTZW.js → chunk-FUFNRZFJ.js} +2 -2
  47. package/dist/{chunk-TDZXQAH7.js → chunk-FYE4PWWP.js} +2 -2
  48. package/dist/{chunk-QNMOZ3CJ.js → chunk-GAE7WCBK.js} +2 -2
  49. package/dist/{chunk-2ZNZSNVW.js → chunk-HAC5EI2T.js} +2 -2
  50. package/dist/{chunk-WT7TOU2C.js → chunk-HCSTQGQE.js} +2 -2
  51. package/dist/{chunk-UXOVHGT6.js → chunk-HFBNIIZX.js} +2 -2
  52. package/dist/{chunk-JHK2DMUQ.js → chunk-HGFDYOVB.js} +1 -1
  53. package/dist/{chunk-UJL3N6TC.js → chunk-HHOJH3RJ.js} +2 -2
  54. package/dist/{chunk-X65VYV2S.js → chunk-HNTLCR4F.js} +2 -2
  55. package/dist/{chunk-RJLU7IMR.js → chunk-IICQP2DY.js} +2 -2
  56. package/dist/{chunk-J65FQLDL.js → chunk-IXAALOUP.js} +2 -2
  57. package/dist/{chunk-XDVT7QPG.js → chunk-J4MYRIYT.js} +2 -2
  58. package/dist/{chunk-TAB7AWKO.js → chunk-J5XJWCB3.js} +2 -2
  59. package/dist/{chunk-DWN7QDTV.js → chunk-JFO2UVQP.js} +2 -2
  60. package/dist/{chunk-FMC3BI4I.js → chunk-JRCJEHRG.js} +2 -2
  61. package/dist/{chunk-4XTPZ5CR.js → chunk-KMOMNTB4.js} +2 -2
  62. package/dist/{chunk-ZL5Y23AJ.js → chunk-LM72NQ7T.js} +1 -1
  63. package/dist/{chunk-4ZHJAHLE.js → chunk-LSJDKJIB.js} +2 -2
  64. package/dist/{chunk-VV5WJLRO.js → chunk-MP43RX4O.js} +1 -1
  65. package/dist/{chunk-D5OXYOJP.js → chunk-MQ2B33LQ.js} +1 -1
  66. package/dist/{chunk-MTFHE7ZO.js → chunk-MRYPDVOS.js} +2 -2
  67. package/dist/{chunk-GMZYT44R.js → chunk-NLNZK7RL.js} +5 -5
  68. package/dist/{chunk-ZXWFN7CK.js → chunk-OAM22BCR.js} +2 -2
  69. package/dist/{chunk-TOYQTO44.js → chunk-OLG2YPLS.js} +2 -2
  70. package/dist/{chunk-PBADFBRR.js → chunk-OQ6TCHBB.js} +2 -2
  71. package/dist/{chunk-3KQOIXLO.js → chunk-PCIFZHWS.js} +2 -2
  72. package/dist/{chunk-KD6TPIXM.js → chunk-PJENL245.js} +2 -2
  73. package/dist/{chunk-F334Z5UA.js → chunk-PLDIXTKR.js} +2 -2
  74. package/dist/{chunk-BOXAKNN6.js → chunk-PNESKY2Z.js} +2 -2
  75. package/dist/{chunk-QHOUNTDZ.js → chunk-PTYQQHZM.js} +2 -2
  76. package/dist/{chunk-2FAJTZSX.js → chunk-QKW7ISEW.js} +2 -2
  77. package/dist/{chunk-AWSRND4W.js → chunk-QNO3QIMN.js} +2 -2
  78. package/dist/{chunk-DV6B262O.js → chunk-SJ6XSCG7.js} +2 -2
  79. package/dist/{chunk-XPYXEEDO.js → chunk-SOS256TP.js} +2 -2
  80. package/dist/{chunk-DQIJMKNE.js → chunk-TDUU63FC.js} +2 -2
  81. package/dist/chunk-TOIS2VAI.js +4 -0
  82. package/dist/{chunk-TC3X33N6.js → chunk-TYEGFDOP.js} +2 -2
  83. package/dist/chunk-UJKZQLDB.js +2 -0
  84. package/dist/chunk-V27BEQJN.js +7 -0
  85. package/dist/{chunk-J6BR4MD6.js → chunk-VIKEPD4D.js} +2 -2
  86. package/dist/{chunk-XDSB47KO.js → chunk-WAU7HVDI.js} +2 -2
  87. package/dist/chunk-WFWQWQK6.js +3 -0
  88. package/dist/chunk-WWCZCH7W.js +3 -0
  89. package/dist/{chunk-QB5WSOTY.js → chunk-XAMVIPE2.js} +2 -2
  90. package/dist/{chunk-A45K6VUK.js → chunk-XWE7PZQH.js} +2 -2
  91. package/dist/{chunk-547VY366.js → chunk-XWJ3JYRG.js} +2 -2
  92. package/dist/{chunk-QN67MWDU.js → chunk-XYBNOILR.js} +2 -2
  93. package/dist/{chunk-IWK562KR.js → chunk-XYNWAZ6J.js} +2 -2
  94. package/dist/{chunk-UVMME4FI.js → chunk-YGBHQOB2.js} +2 -2
  95. package/dist/{chunk-ZNSLF5AC.js → chunk-YGQBJUS6.js} +2 -2
  96. package/dist/{chunk-6DHPQS72.js → chunk-YILKXTIY.js} +2 -2
  97. package/dist/{chunk-X3OOU7CF.js → chunk-Z7M7X3ZG.js} +2 -2
  98. package/dist/{chunk-G6QQCX45.js → chunk-ZJGZCBYT.js} +2 -2
  99. package/dist/cli.js +1 -1
  100. package/dist/{command-descriptors-SWFWGIFK.js → command-descriptors-QJEYYND2.js} +168 -166
  101. package/dist/direct-navigation-TT23TDBS.js +3 -0
  102. package/dist/index.js +1 -1
  103. package/dist/queries/affected.js +1 -1
  104. package/dist/queries/architecture.js +1 -1
  105. package/dist/queries/bottlenecks.js +1 -1
  106. package/dist/queries/by-kind.js +1 -1
  107. package/dist/queries/call-graph.js +1 -1
  108. package/dist/queries/change-surface.js +1 -1
  109. package/dist/queries/cleanup-plan.js +1 -1
  110. package/dist/queries/co-change.js +1 -1
  111. package/dist/queries/code.js +1 -1
  112. package/dist/queries/complexity-hotspots.js +1 -1
  113. package/dist/queries/complexity.js +1 -1
  114. package/dist/queries/convergence.js +1 -1
  115. package/dist/queries/coupling.js +1 -1
  116. package/dist/queries/cycles.js +1 -1
  117. package/dist/queries/dataflow.js +1 -1
  118. package/dist/queries/dead.js +1 -1
  119. package/dist/queries/decorative-checkers.js +1 -1
  120. package/dist/queries/deep-chains.js +1 -1
  121. package/dist/queries/deps.js +1 -1
  122. package/dist/queries/diff-gate.js +1 -1
  123. package/dist/queries/diff-impact.js +1 -1
  124. package/dist/queries/doc-drift.js +1 -1
  125. package/dist/queries/drift.js +1 -1
  126. package/dist/queries/duplicate-bodies.js +1 -1
  127. package/dist/queries/extract-candidates.js +1 -1
  128. package/dist/queries/fan.js +1 -1
  129. package/dist/queries/health.js +1 -1
  130. package/dist/queries/hierarchy.js +1 -1
  131. package/dist/queries/hotspots.js +1 -1
  132. package/dist/queries/imports.js +1 -1
  133. package/dist/queries/incomplete-migration.js +1 -1
  134. package/dist/queries/index.js +1 -1
  135. package/dist/queries/isolated.js +1 -1
  136. package/dist/queries/locality-candidates.js +1 -1
  137. package/dist/queries/members.js +1 -1
  138. package/dist/queries/methods.js +1 -1
  139. package/dist/queries/not-implemented.js +1 -1
  140. package/dist/queries/outline.js +1 -1
  141. package/dist/queries/passthrough-candidates.js +1 -1
  142. package/dist/queries/plan-context.js +1 -1
  143. package/dist/queries/react-component-duplicates.js +1 -1
  144. package/dist/queries/react-hook-candidates.js +1 -1
  145. package/dist/queries/react-large-component-pressure.js +1 -1
  146. package/dist/queries/recent-duplicates.js +1 -1
  147. package/dist/queries/redundant-reexports.js +1 -1
  148. package/dist/queries/refs.js +1 -1
  149. package/dist/queries/self-audit.js +1 -1
  150. package/dist/queries/similar-chains.js +1 -1
  151. package/dist/queries/similar-files.js +1 -1
  152. package/dist/queries/similar-signatures.js +1 -1
  153. package/dist/queries/similar.js +1 -1
  154. package/dist/queries/slice.js +1 -1
  155. package/dist/queries/stale-abstractions.js +1 -1
  156. package/dist/queries/surface.js +1 -1
  157. package/dist/queries/symbols.js +1 -1
  158. package/dist/queries/system.js +1 -1
  159. package/dist/queries/test-quality.js +1 -1
  160. package/dist/queries/trace.js +1 -1
  161. package/dist/queries/twin-ab.js +1 -1
  162. package/dist/queries/twin-drift.js +1 -1
  163. package/dist/queries/unused-imports.js +1 -1
  164. package/dist/queries/unused-params.js +1 -1
  165. package/dist/queries/vue-component-duplicates.js +1 -1
  166. package/dist/queries/vue-composable-candidates.js +1 -1
  167. package/dist/queries/vue-large-view-pressure.js +1 -1
  168. package/dist/queries/wrapper-candidates.js +1 -1
  169. package/dist/reindex-worker.js +24 -24
  170. package/dist/reindex.js +38 -38
  171. package/dist/runtime.d.ts +6 -1
  172. package/dist/runtime.js +2 -2
  173. package/dist/rust-semantic-session-server.js +1 -1
  174. package/dist/rust-semantic-session-worker.js +1 -1
  175. package/dist/rust-semantic-worker.js +1 -1
  176. package/dist/watch-server.js +5 -5
  177. package/package.json +1 -1
  178. package/dist/chunk-42QYU6FD.js +0 -3
  179. package/dist/chunk-6SHX42QQ.js +0 -6
  180. package/dist/chunk-AERYQJ52.js +0 -3
  181. package/dist/chunk-IXORBCMR.js +0 -120
  182. package/dist/chunk-NEG77KKH.js +0 -4
  183. package/dist/chunk-OYYZLJVT.js +0 -2
  184. package/dist/direct-navigation-RKMPBXMI.js +0 -3
@@ -1,120 +0,0 @@
1
- import{g as En,h as x,i as pt,j as vn,k as ke,l as Tn}from"./chunk-VV5WJLRO.js";import{a as we,b as j}from"./chunk-KHE7J5ZN.js";import{a as Zt,b as er,e as tr}from"./chunk-JHK2DMUQ.js";import{readFileSync as as}from"fs";import{join as rr}from"path";var fd=4,md=5e3,cs="watch.lock",ls="watch-state.json",ps="watch-activity.json";function gd(e){return{lockPath:rr(e,cs),statePath:rr(e,ls),activityPath:rr(e,ps)}}function yd(e){try{return us(JSON.parse(as(e,"utf8")))}catch{return null}}function us(e){if(!e||typeof e!="object")return null;let t=e;return t.version!==1||typeof t.protocolVersion!="number"||typeof t.pid!="number"||!Number.isInteger(t.pid)||t.pid<=0||typeof t.projectRoot!="string"||t.worktreeId!==void 0&&(typeof t.worktreeId!="string"||t.worktreeId.length===0)||typeof t.cliVersion!="string"||!M(t.startedAt)||!M(t.heartbeatAt)||!M(t.lastActivityAt)||!ds(t.watcher)||t.idleDeadlineAt!==void 0&&!M(t.idleDeadlineAt)||t.indexGeneration!==void 0&&!/^[a-f0-9]{64}$/.test(t.indexGeneration)||t.lastError!==void 0&&!fs(t.lastError)||t.lastRefresh!==void 0&&!ms(t.lastRefresh)||t.typescriptSemantic!==void 0&&!gs(t.typescriptSemantic)||t.typescriptIndex!==void 0&&!ys(t.typescriptIndex)?null:t}function M(e){return typeof e=="string"&&Number.isFinite(Date.parse(e))}function ds(e){if(!e||typeof e!="object"||!("state"in e))return!1;let t=e;switch(t.state){case"idle":return!0;case"waiting":return D(t.changedFiles)&&D(t.reindexAt);case"indexing":return D(t.startedAt);case"cooldown":return D(t.until)&&typeof t.dirty=="boolean";default:return!1}}function fs(e){if(!e||typeof e!="object")return!1;let t=e;return M(t.at)&&typeof t.message=="string"}function ms(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.trigger?.kind=="string"&&typeof t.result=="string"&&M(t.startedAt)&&M(t.completedAt)&&D(t.durationMs)}function gs(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.protocolVersion=="number"&&(t.state==="idle"||t.state==="ready"||t.state==="unavailable"||t.state==="error")&&D(t.requests)&&D(t.sessionsCreated)&&D(t.sessionsReused)&&D(t.sessionsRefreshed)&&D(t.sessionsReplaced)&&D(t.projectsCreated)&&(t.lastRequestAt===void 0||M(t.lastRequestAt))&&(t.lastError===void 0||typeof t.lastError=="string")&&(t.busyUntil===void 0||M(t.busyUntil))}function ys(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.protocolVersion=="number"&&(t.state==="idle"||t.state==="ready"||t.state==="unavailable"||t.state==="error")&&ae(t.requests)&&ae(t.sessionsCreated)&&ae(t.sessionsReplaced)&&ae(t.initializations)&&ae(t.programUpdates)&&ae(t.documentsEmitted)&&ae(t.documentsRemoved)&&(t.lastRequestAt===void 0||M(t.lastRequestAt))&&(t.lastDurationMs===void 0||D(t.lastDurationMs)&&t.lastDurationMs>=0)&&(t.lastError===void 0||typeof t.lastError=="string")&&(t.busyUntil===void 0||M(t.busyUntil))}function D(e){return typeof e=="number"&&Number.isFinite(e)}function ae(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0}import{createHash as hs}from"crypto";import{mkdirSync as Ss,realpathSync as bs}from"fs";import{homedir as xs}from"os";import{join as ce,resolve as wn}from"path";function Is(e,t){let r=process.env.SCIP_QUERY_CACHE_DIR;if(r)return nr(r);if(t?.dbPath)return nr(wn(e,t.dbPath));let n=ir(e);return nr(n)}function kn(){let e=process.env.XDG_CACHE_HOME;return ce(e||ce(xs(),".cache"),"scip-query")}function ir(e){let t=wn(e);try{t=bs(t)}catch{}let r=hs("sha256").update(t).digest("hex").slice(0,12);return ce(kn(),"projects",r)}function or(e){if(!/^[a-f0-9]{24}$/.test(e))throw new Error(`invalid repository cache identity: ${e}`);return ce(kn(),"repositories",e)}function sr(e){return process.env.SCIP_QUERY_SHARED_CACHE!=="0"&&!process.env.SCIP_QUERY_CACHE_DIR&&!process.env.SCIP_QUERY_INDEX_DB&&!e?.dbPath}function Ed(e,t){let r=Is(e,t);return{cacheDir:r,dbPath:ce(r,"index.db"),indexPath:ce(r,"index.scip"),metaPath:ce(r,"meta.json")}}function nr(e){return Ss(e,{recursive:!0}),e}import{createHash as Es}from"crypto";import{readFileSync as vs}from"fs";import{dirname as Ts,join as ut}from"path";var ws=2,ks="typescript-index";function Cd(e){let t=ut(e,ks);return{rootDir:t,requestDir:ut(t,"requests"),responseDir:ut(t,"responses")}}function Rd(e){let t=JSON.parse(e);if(t.protocolVersion!==ws||typeof t.id!="string"||!t.id||typeof t.baseGeneration!="string"||!t.baseGeneration||typeof t.deadlineAtMs!="number"||!Number.isFinite(t.deadlineAtMs)||!Cs(t.request))throw new Error("TypeScript index service received an invalid mailbox request.");return t}function Nd(e){try{let t=JSON.parse(vs(ut(Ts(e),"meta.json"),"utf8"));return t.version!==2&&t.version!==3||t.status!=="complete"||typeof t.updatedAt!="string"||t.fingerprint===void 0?null:Es("sha256").update(JSON.stringify({version:t.version,status:t.status,updatedAt:t.updatedAt,fingerprint:t.fingerprint,indexedLanguages:t.indexedLanguages})).digest("hex")}catch{return null}}function Cs(e){if(!e||typeof e!="object")return!1;let t=e,r=Cn(t.modifiedFiles)?t.modifiedFiles:null,n=Cn(t.affectedFiles)?t.affectedFiles:null;return t.kind==="emit-documents"&&typeof t.tsconfigPath=="string"&&!!t.tsconfigPath&&typeof t.projectArgument=="string"&&!!t.projectArgument&&typeof t.projectIdentity=="string"&&!!t.projectIdentity&&typeof t.producerIdentity=="string"&&!!t.producerIdentity&&r!==null&&r.length>0&&new Set(r).size===r.length&&n!==null&&n.length>0&&new Set(n).size===n.length&&r.every(i=>n.includes(i))}function Cn(e){return Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.length>0)}import{spawnSync as Rs}from"child_process";import{createHash as Ns}from"crypto";import{existsSync as Ps,lstatSync as Ds,realpathSync as _s}from"fs";import{dirname as As,isAbsolute as Fs,join as Os,resolve as ft}from"path";var mt={run(e,t){let r=Nn(e,t);return r.kind==="success"?r.output:void 0},runResult:Nn},Ls=["rev-parse","--show-toplevel","--absolute-git-dir","--git-common-dir","HEAD","HEAD^{tree}"],Rn=/^[0-9a-f]{40,64}$/;function Pn(e,t=mt){let r=t.runResult(e,Ls);if(r.kind==="success"){let n=js(r.output);if(n)return Ms(n,t)}return $s(e,t)}function js(e){let t=e.split(`
2
- `).map(c=>c.trim());if(t.length!==5)return;let[r,n,i,o,s]=t;if(!r||!n||!i||!o||!s||!Rn.test(o)||!Rn.test(s))return;let a=le(r);return{root:a,gitDir:le(dt(a,n)),commonDir:le(dt(a,i)),headCommit:o,treeOid:s}}function Ms(e,t){let r=t.run(e.root,["status","--porcelain=v1","-z","--untracked-files=all"]);return r===void 0?void 0:{...Dn(e.root,e.gitDir),commonDir:e.commonDir,repositoryId:cr("repository",e.commonDir),headCommit:e.headCommit,treeOid:e.treeOid,clean:r.length===0}}function $s(e,t){let r=Gs(e,t);if(r.kind!=="worktree")return;let n=r.identity,i=n.projectRoot,o=t.run(i,["rev-parse","--git-common-dir"])?.trim();if(!o)return;let s=le(dt(i,o)),a=ar(t.run(i,["rev-parse","--verify","HEAD"])),c=ar(t.run(i,["rev-parse","--verify","HEAD^{tree}"])),l=t.run(i,["status","--porcelain=v1","-z","--untracked-files=all"]);if(l!==void 0)return{...n,commonDir:s,repositoryId:cr("repository",s),headCommit:a,treeOid:c,clean:l.length===0}}function Gs(e,t=mt){let r=t.runResult(e,["rev-parse","--show-toplevel"]);if(r.kind==="not-repository")return{kind:"non-git"};if(r.kind==="error")return r;let n=r.output.trim();if(!n)return{kind:"error",message:"Git returned an empty worktree root."};let i=le(n),o=t.run(i,["rev-parse","--absolute-git-dir"])?.trim();if(!o)return{kind:"error",message:"Git did not return an absolute worktree directory."};let s=le(dt(i,o));return{kind:"worktree",identity:Dn(i,s)}}function Dn(e,t){return{projectRoot:e,gitDir:t,worktreeId:cr("worktree",`${e}\0${t}`)}}function Ws(e,t=mt){let r=t.run(e,["worktree","list","--porcelain","-z"]);return r===void 0?[]:Vs(r)}function Vs(e){let t=[],r;for(let n of e.split("\0")){if(n===""){r&&t.push(r),r=void 0;continue}let i=n.indexOf(" "),o=i<0?n:n.slice(0,i),s=i<0?"":n.slice(i+1);if(o==="worktree"){r&&t.push(r),r={path:le(s),detached:!1,bare:!1,prunable:!1,locked:!1};continue}r&&(o==="HEAD"?r.head=s:o==="branch"?r.branch=s:o==="detached"?r.detached=!0:o==="bare"?r.bare=!0:o==="prunable"?r.prunable=!0:o==="locked"&&(r.locked=!0))}return r&&t.push(r),t}function Od(e,t,r=mt){return ar(r.run(e,t))}function dt(e,t){return Fs(t)?t:ft(e,t)}function le(e){try{return _s(e)}catch{return ft(e)}}function cr(e,t){return Ns("sha256").update(`${e}\0${t}`).digest("hex").slice(0,24)}function ar(e){return e?.trim()||void 0}function Nn(e,t){let r=Rs("git",["-C",e,...t],{encoding:"utf-8",env:{...process.env,LC_ALL:"C"},maxBuffer:52428800,stdio:["ignore","pipe","pipe"]});if(r.status===0)return{kind:"success",output:r.stdout.trimEnd()};let i=(typeof r.stderr=="string"?r.stderr.trim():"")||r.error?.message||`git exited with status ${r.status??"unknown"}`,o=r.error?.code;return(/not a git repository/i.test(i)||o==="ENOENT"&&Ps(ft(e)))&&!Bs(e)?{kind:"not-repository"}:{kind:"error",message:i}}function Bs(e){if(process.env.GIT_DIR||process.env.GIT_COMMON_DIR)return!0;let t=ft(e);for(;;){try{return Ds(Os(t,".git")),!0}catch(n){let i=n.code;if(i!=="ENOENT"&&i!=="ENOTDIR")return!0}let r=As(t);if(r===t)return!1;t=r}}import{randomUUID as _n}from"crypto";import{closeSync as An,mkdirSync as Us,openSync as Fn,readFileSync as On,unlinkSync as Ln,writeFileSync as jn}from"fs";import{dirname as Hs,join as qs}from"path";function Mn(e,t={}){return lr(qs(e,"gc.lock"),t)}function lr(e,t={}){let r=t.waitMs??0,n=t.pollMs??10,i=t.now??Date.now,o=Date.now()+r;Us(Hs(e),{recursive:!0});do{let s=_n();try{let a=Fn(e,"wx");try{let c={version:1,pid:process.pid,token:s,startedAt:new Date(i()).toISOString()};jn(a,`${JSON.stringify(c)}
3
- `)}finally{An(a)}return{release:()=>Gn(e,s)}}catch(a){if(a.code!=="EEXIST")return null;let c=$n(e);if(c&&(c.pid===void 0||!we(c.pid))){zs(e,c);continue}if(Date.now()>=o)return null;Js(Math.min(n,Math.max(1,o-Date.now())))}}while(Date.now()<=o);return null}function $n(e){try{let t=On(e,"utf8"),r=JSON.parse(t),n=typeof r.pid=="number"&&Number.isSafeInteger(r.pid)&&r.pid>0?r.pid:void 0;return{raw:t,...n===void 0?{}:{pid:n}}}catch{return null}}function zs(e,t){let r=`${e}.reclaim`,n=_n(),i;try{i=Fn(r,"wx")}catch{return!1}try{jn(i,`${JSON.stringify({version:1,pid:process.pid,token:n,startedAt:new Date().toISOString()})}
4
- `)}finally{An(i)}try{let o=$n(e);return!o||o.raw!==t.raw||o.pid!==void 0&&we(o.pid)?!1:(Ln(e),!0)}catch{return!1}finally{Gn(r,n)}}function Gn(e,t){try{let r=JSON.parse(On(e,"utf8"));r.pid===process.pid&&r.token===t&&Ln(e)}catch{}}function Js(e){let t=new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));Atomics.wait(t,0,0,e)}import Xs from"better-sqlite3";var Ys=["node_modules",".git","dist","build","out","coverage","target",".next",".nuxt",".cache",".turbo",".nbb",".cpcache",".shadow-cljs",".scipquery-cache","__pycache__",".venv","venv"],Wn=class{db;config;pathFilter;statementCache=new Map;constructor(t,r){this.config=t,this.pathFilter=r??null,this.db=new Xs(t.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000"),this.db.pragma("query_only = ON"),this.db.pragma("temp_store = MEMORY"),this.db.pragma("cache_size = -64000"),this.db.pragma("mmap_size = 268435456")}isIgnored(t){return this.pathFilter?.isIgnored(t)??!1}get localSymbolPredicate(){return`(
5
- EXISTS (
6
- SELECT 1
7
- FROM defn_enclosing_ranges local_der
8
- JOIN documents local_d ON local_der.document_id = local_d.id
9
- WHERE local_der.symbol_id = gs.id
10
- ${this.pathExclusionsFor("local_d").trimStart()}
11
- )
12
- OR EXISTS (
13
- SELECT 1
14
- FROM mentions local_m
15
- JOIN chunks local_c ON local_m.chunk_id = local_c.id
16
- JOIN documents local_d ON local_c.document_id = local_d.id
17
- WHERE local_m.symbol_id = gs.id
18
- AND local_m.role = 1
19
- ${this.pathExclusionsFor("local_d").trimStart()}
20
- )
21
- )`}get pathExclusions(){return this.pathExclusionsFor("d")}get symbolNoise(){return this.symbolNoiseFor("gs")}pathExclusionsFor(...t){return t.flatMap(r=>Ys.flatMap(n=>[`AND ${r}.relative_path NOT LIKE '${n}/%'`,`AND ${r}.relative_path NOT LIKE '%/${n}/%'`])).join(`
22
- `)}symbolNoiseFor(t){return`AND ${t}.symbol NOT LIKE '%().(%' AND ${t}.symbol NOT LIKE '%typeLiteral%'`}all(t,...r){return this.statement(t).all(...r)}get(t,...r){return this.statement(t).get(...r)}close(){this.statementCache.clear(),this.db.close()}statement(t){let r=this.statementCache.get(t);return r||(r=this.db.prepare(t),this.statementCache.set(t,r)),r}};import{createHash as Ks}from"crypto";import{existsSync as Qs,mkdirSync as Zs,readFileSync as ea}from"fs";import{dirname as pr,join as Vn}from"path";import ur from"better-sqlite3";var ta="evidence.db";var ra=["source-facts","definition-exclusions","doc-path-tokens","react-component-behavior-profiles"],dr=new Set(ra),na=25e4,ia=512*1024*1024;var gt=new WeakMap,oa=x("evidence-content-hash",{clearGroups:["whole-project","source-file"]}),sa=x("evidence-project-fingerprint",{clearGroups:["whole-project"]}),Y="evidence-v1",Ce="version NOT LIKE 'evidence-%'";function yt(e){return Ks("sha256").update(e).digest("hex")}function je(e,t,r){return oa.get(e,t,()=>yt(r))}function Bn(e){return sa.get(e,"current",()=>{try{let t=JSON.parse(ea(Vn(pr(e.config.dbPath),"meta.json"),"utf-8"));if(t.version!==2&&t.version!==3||t.status!=="complete"&&t.status!=="partial"||t.fingerprint===void 0)return null;let r=Array.isArray(t.indexedLanguages)?[...t.indexedLanguages].sort():[];return yt(JSON.stringify({fingerprint:t.fingerprint,indexedLanguages:r,status:t.status}))}catch(t){return Re("project fingerprint unavailable",t),null}})}function Re(e,t){process.env.SCIP_QUERY_DEBUG&&console.error(`evidence-cache: ${e}: ${t instanceof Error?t.message:String(t)}`)}function Me(e){if(gt.has(e))return gt.get(e)??null;let t=null;try{let r=new ur(Vn(pr(e.config.dbPath),ta));r.pragma("journal_mode = WAL"),r.pragma("busy_timeout = 5000"),r.pragma("synchronous = NORMAL"),r.exec(`
23
- CREATE TABLE IF NOT EXISTS file_evidence (
24
- kind TEXT NOT NULL,
25
- relative_path TEXT NOT NULL,
26
- content_hash TEXT NOT NULL,
27
- version TEXT NOT NULL,
28
- payload TEXT NOT NULL,
29
- PRIMARY KEY (kind, relative_path)
30
- );
31
- CREATE TABLE IF NOT EXISTS project_evidence (
32
- kind TEXT NOT NULL,
33
- cache_key TEXT NOT NULL,
34
- project_fingerprint TEXT NOT NULL,
35
- version TEXT NOT NULL,
36
- payload TEXT NOT NULL,
37
- PRIMARY KEY (kind, cache_key)
38
- );
39
- CREATE TABLE IF NOT EXISTS semantic_callees (
40
- relative_path TEXT NOT NULL,
41
- symbol TEXT NOT NULL,
42
- content_hash TEXT NOT NULL,
43
- deps_digest TEXT NOT NULL,
44
- version TEXT NOT NULL,
45
- payload TEXT NOT NULL,
46
- PRIMARY KEY (relative_path, symbol)
47
- );
48
- CREATE TABLE IF NOT EXISTS semantic_references (
49
- relative_path TEXT NOT NULL,
50
- symbol TEXT NOT NULL,
51
- project_fingerprint TEXT NOT NULL,
52
- version TEXT NOT NULL,
53
- payload TEXT NOT NULL,
54
- PRIMARY KEY (relative_path, symbol)
55
- );
56
- CREATE TABLE IF NOT EXISTS finding_outcome_ledger (
57
- check_name TEXT NOT NULL,
58
- finding_id TEXT NOT NULL,
59
- first_seen INTEGER NOT NULL,
60
- last_seen INTEGER NOT NULL,
61
- times_shown INTEGER NOT NULL,
62
- outcome TEXT NOT NULL,
63
- PRIMARY KEY (check_name, finding_id)
64
- );
65
- `),t={evidence:r,shared:aa(e.config.sharedEvidenceDbPath),readFileEvidence:r.prepare("SELECT payload FROM file_evidence WHERE kind = ? AND relative_path = ? AND content_hash = ? AND version = ?"),readLegacyFileEvidence:r.prepare(`SELECT payload FROM file_evidence
66
- WHERE kind = ? AND relative_path = ? AND content_hash = ? AND ${Ce}
67
- ORDER BY version DESC
68
- LIMIT 1`),writeFileEvidence:r.prepare("INSERT OR REPLACE INTO file_evidence (kind, relative_path, content_hash, version, payload) VALUES (?, ?, ?, ?, ?)"),readProjectEvidence:r.prepare("SELECT payload FROM project_evidence WHERE kind = ? AND cache_key = ? AND project_fingerprint = ? AND version = ?"),readLegacyProjectEvidence:r.prepare(`SELECT payload FROM project_evidence
69
- WHERE kind = ? AND cache_key = ? AND project_fingerprint = ? AND ${Ce}
70
- ORDER BY version DESC
71
- LIMIT 1`),writeProjectEvidence:r.prepare("INSERT OR REPLACE INTO project_evidence (kind, cache_key, project_fingerprint, version, payload) VALUES (?, ?, ?, ?, ?)"),readCallees:r.prepare(`SELECT payload FROM semantic_callees
72
- WHERE relative_path = ? AND symbol = ? AND content_hash = ? AND deps_digest = ? AND version = ?`),readLegacyCallees:r.prepare(`SELECT payload FROM semantic_callees
73
- WHERE relative_path = ? AND symbol = ? AND content_hash = ? AND deps_digest = ? AND ${Ce}
74
- ORDER BY version DESC
75
- LIMIT 1`),readCalleesForFile:r.prepare(`SELECT symbol, payload FROM semantic_callees
76
- WHERE relative_path = ? AND content_hash = ? AND deps_digest = ? AND version = ?`),readLegacyCalleesForFile:r.prepare(`SELECT symbol, payload FROM semantic_callees
77
- WHERE relative_path = ? AND content_hash = ? AND deps_digest = ? AND ${Ce}
78
- ORDER BY symbol, version DESC`),writeCallees:r.prepare(`INSERT OR REPLACE INTO semantic_callees
79
- (relative_path, symbol, content_hash, deps_digest, version, payload) VALUES (?, ?, ?, ?, ?, ?)`),dropStaleCallees:r.prepare("DELETE FROM semantic_callees WHERE relative_path = ? AND content_hash != ?"),readReferences:r.prepare(`SELECT payload FROM semantic_references
80
- WHERE relative_path = ? AND symbol = ? AND project_fingerprint = ? AND version = ?`),readLegacyReferences:r.prepare(`SELECT payload FROM semantic_references
81
- WHERE relative_path = ? AND symbol = ? AND project_fingerprint = ? AND ${Ce}
82
- ORDER BY version DESC
83
- LIMIT 1`),readReferencesForFile:r.prepare(`SELECT symbol, payload FROM semantic_references
84
- WHERE relative_path = ? AND project_fingerprint = ? AND version = ?`),readLegacyReferencesForFile:r.prepare(`SELECT symbol, payload FROM semantic_references
85
- WHERE relative_path = ? AND project_fingerprint = ? AND ${Ce}
86
- ORDER BY symbol, version DESC`),writeReferences:r.prepare(`INSERT OR REPLACE INTO semantic_references
87
- (relative_path, symbol, project_fingerprint, version, payload) VALUES (?, ?, ?, ?, ?)`),dropStaleReferences:r.prepare("DELETE FROM semantic_references WHERE relative_path = ? AND project_fingerprint != ?"),readFindingOutcomeLedger:r.prepare("SELECT check_name, finding_id, first_seen, last_seen, times_shown, outcome FROM finding_outcome_ledger"),deleteFindingOutcomeLedgerForCheck:r.prepare("DELETE FROM finding_outcome_ledger WHERE check_name = ?"),writeFindingOutcomeLedgerRow:r.prepare(`INSERT INTO finding_outcome_ledger
88
- (check_name, finding_id, first_seen, last_seen, times_shown, outcome) VALUES (?, ?, ?, ?, ?, ?)`)}}catch(r){Re("disabled (open failed)",r)}return gt.set(e,t),t}function $e(e,t,r){Re(`disabled (${t})`,r),gt.set(e,null)}function aa(e){if(!e)return null;try{Zs(pr(e),{recursive:!0});let t=new ur(e);return t.pragma("journal_mode = WAL"),t.pragma("busy_timeout = 250"),t.pragma("synchronous = NORMAL"),t.exec(`
89
- CREATE TABLE IF NOT EXISTS file_evidence (
90
- kind TEXT NOT NULL,
91
- relative_path TEXT NOT NULL,
92
- content_hash TEXT NOT NULL,
93
- version TEXT NOT NULL,
94
- payload TEXT NOT NULL,
95
- last_accessed_at INTEGER NOT NULL,
96
- PRIMARY KEY (kind, relative_path, content_hash, version)
97
- );
98
- `),{evidence:t,readFileEvidence:t.prepare("SELECT payload FROM file_evidence WHERE kind = ? AND relative_path = ? AND content_hash = ? AND version = ?"),writeFileEvidence:t.prepare(`INSERT INTO file_evidence (kind, relative_path, content_hash, version, payload, last_accessed_at)
99
- VALUES (?, ?, ?, ?, ?, ?)
100
- ON CONFLICT(kind, relative_path, content_hash, version)
101
- DO UPDATE SET payload = excluded.payload, last_accessed_at = excluded.last_accessed_at`)}}catch(t){return Re("shared cache disabled (open failed)",t),null}}function fr(e,t,r){Re(`shared cache disabled (${t})`,r);try{e.shared?.evidence.close()}catch{}e.shared=null}function Xd(e,t={}){if(!Qs(e))return null;let r;try{r=new ur(e),r.pragma("busy_timeout = 50"),r.pragma("wal_checkpoint(TRUNCATE)");let n=r.prepare("SELECT COUNT(*) AS count FROM file_evidence").get().count,i=t.maxRows??na,o=t.budgetBytes??ia,s=Number(r.pragma("page_size",{simple:!0})),a=Number(r.pragma("page_count",{simple:!0})),c=Number(r.pragma("freelist_count",{simple:!0})),l=Math.max(0,a-c)*s,p=n>0&&l>o?Math.min(n,Math.ceil((l-o)/Math.max(1,l/n))):0,u=Math.max(n-i,p);return u>0&&(r.prepare(`DELETE FROM file_evidence WHERE rowid IN (
102
- SELECT rowid FROM file_evidence ORDER BY last_accessed_at ASC, rowid ASC LIMIT ?
103
- )`).run(u),r.pragma("wal_checkpoint(TRUNCATE)")),{deletedRows:u,remainingRows:n-u}}catch(n){return Re("shared cache maintenance skipped",n),null}finally{try{r?.close()}catch{}}}function Un(e,t,r,n){let i=Me(e);if(!i)return null;try{let o=i.readFileEvidence.get(t,r,n,Y)??i.readLegacyFileEvidence.get(t,r,n);if(o?.payload!==void 0)return o.payload;if(!dr.has(t)||!i.shared)return null;try{return i.shared.readFileEvidence.get(t,r,n,Y)?.payload??null}catch(s){return fr(i,"file_evidence read",s),null}}catch(o){return $e(e,"file_evidence read",o),null}}function Hn(e,t,r,n,i){let o=Me(e);if(o)try{if(o.writeFileEvidence.run(t,r,n,Y,i),dr.has(t)&&o.shared)try{o.shared.writeFileEvidence.run(t,r,n,Y,i,Date.now())}catch(s){fr(o,"file_evidence write",s)}}catch(s){$e(e,"file_evidence write",s)}}function qn(e,t){if(t.length===0)return;let r=Me(e);if(r)try{r.evidence.transaction(()=>{for(let i of t)r.writeFileEvidence.run(i.kind,i.relativePath,i.contentHash,Y,i.payload)})();let n=t.filter(i=>dr.has(i.kind));if(n.length>0&&r.shared)try{r.shared.evidence.transaction(()=>{for(let i of n)r.shared.writeFileEvidence.run(i.kind,i.relativePath,i.contentHash,Y,i.payload,Date.now())})()}catch(i){fr(r,"file_evidence batch write",i)}}catch(n){$e(e,"file_evidence batch write",n)}}function zn(e,t,r,n){let i=Me(e);if(!i)return null;try{return(i.readProjectEvidence.get(t,r,n,Y)??i.readLegacyProjectEvidence.get(t,r,n))?.payload??null}catch(o){return $e(e,"project_evidence read",o),null}}function Jn(e,t,r,n,i){let o=Me(e);if(o)try{o.writeProjectEvidence.run(t,r,n,Y,i)}catch(s){$e(e,"project_evidence write",s)}}function mr(e){return typeof e=="object"&&e!==null}function Kd(e){return Array.isArray(e)&&e.every(t=>typeof t=="string")?e:null}import{execFileSync as ca}from"child_process";import{existsSync as la,readdirSync as Yn}from"fs";import{extname as Kn,join as Qn}from"path";var Zn=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),pa=[{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:"clojure",files:["deps.edn","project.clj","bb.edn","shadow-cljs.edn"],extensions:[".clj",".cljs",".cljc"]},{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 rf(e){let t=[],r=ua(e),n=ga(e);for(let i of pa){if(da(e,i.files)){t.push(i.language);continue}if(fa(r,i.globs)){t.push(i.language);continue}ha(n,i.extensions)&&t.push(i.language)}return t.includes("typescript")&&Xn(t,"javascript"),t.includes("cpp")&&!n.has(".c")&&Xn(t,"c"),t}function ua(e){try{return Yn(e)}catch{return[]}}function da(e,t){return t?.length?t.some(r=>la(Qn(e,r))):!1}function fa(e,t){return t?.length?e.some(r=>t.some(n=>ma(r,n))):!1}function ma(e,t){if(t==="*")return!0;if(!t.includes("*"))return e===t;let[r,n]=t.split("*");return e.startsWith(r??"")&&e.endsWith(n??"")}function ga(e){let t=ya(e);if(t)return t;let r=new Set,n=[e];for(;n.length>0;){let i=n.pop();if(!i)continue;let o;try{o=Yn(i,{withFileTypes:!0})}catch{continue}for(let s of o){if(s.name.startsWith(".")&&!s.name.endsWith("proj")&&!s.name.endsWith("sln")&&s.isDirectory())continue;let a=Qn(i,s.name);if(s.isDirectory()){Zn.has(s.name)||n.push(a);continue}let c=Kn(s.name).toLowerCase();c&&r.add(c)}}return r}function ya(e){try{let t=ca("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}),r=new Set;for(let n of t.split(`
104
- `)){if(!n||n.split("/").some(o=>Zn.has(o)))continue;let i=Kn(n).toLowerCase();i&&r.add(i)}return r}catch{return null}}function ha(e,t){return t?.length?t.some(r=>e.has(r)):!1}function Xn(e,t){let r=e.indexOf(t);r!==-1&&e.splice(r,1)}import{readFileSync as Sa,writeFileSync as ba}from"fs";import{create as ei}from"@bufbuild/protobuf";import{deserializeSCIP as xa,DocumentSchema as Ia,IndexSchema as Ea,serializeSCIP as va,SymbolRole as Ta}from"@c4312/scip";function cf(e){let t;try{t=xa(Sa(e))}catch{return{removedDefinitionOccurrences:0,touchedDocuments:0}}let r=gr(t);return r.removedDefinitionOccurrences>0&&ba(e,Buffer.from(va(r.index))),{removedDefinitionOccurrences:r.removedDefinitionOccurrences,touchedDocuments:r.touchedDocuments}}function gr(e){let t=new Set;for(let o of e.documents)for(let s of o.symbols)s.symbol&&t.add(s.symbol);for(let o of e.externalSymbols)o.symbol&&t.add(o.symbol);let r=0,n=0,i=[];for(let o of e.documents){let s=o.occurrences.filter(a=>(a.symbolRoles&Ta.Definition)===0||t.has(a.symbol)?!0:(r+=1,!1));if(s.length===o.occurrences.length){i.push(o);continue}n+=1,i.push(ei(Ia,{language:o.language,relativePath:o.relativePath,occurrences:s,symbols:o.symbols,text:o.text,positionEncoding:o.positionEncoding}))}return{index:r===0?e:ei(Ea,{metadata:e.metadata,documents:i,externalSymbols:e.externalSymbols}),removedDefinitionOccurrences:r,touchedDocuments:n}}import{readFileSync as yr,writeFileSync as hr}from"fs";import{create as Ge}from"@bufbuild/protobuf";import{deserializeSCIP as Sr,serializeSCIP as br,DocumentSchema as wa,IndexSchema as ti,MetadataSchema as ka,SymbolInformationSchema as Ca}from"@c4312/scip";function ri(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let t=Na(e),r=Pa(e.flatMap(i=>i.documents??[])),n=ii(e.flatMap(i=>i.externalSymbols??[]));return Ge(ti,{metadata:t,documents:r,externalSymbols:n})}function mf(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let r=e.map(i=>Sr(yr(i))),n=ri(r);return hr(t,Buffer.from(br(n))),{documentCount:n.documents.length,externalSymbolCount:n.externalSymbols.length,inputCount:e.length}}function gf(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let r=e.map(i=>Sr(yr(i))),n=gr(ri(r));return hr(t,Buffer.from(br(n.index))),{documentCount:n.index.documents.length,externalSymbolCount:n.index.externalSymbols.length,inputCount:e.length,removedDefinitionOccurrences:n.removedDefinitionOccurrences,touchedDocuments:n.touchedDocuments}}function Ra(e,t,r){let n=e.metadata;if(!n)throw new Error("Cannot rebase a SCIP index without metadata");if(n.projectRoot!==t)throw new Error(`Cannot rebase SCIP project root: expected ${t}, got ${n.projectRoot}`);return Ge(ti,{metadata:Ge(ka,{...n,projectRoot:r}),documents:e.documents,externalSymbols:e.externalSymbols})}function ni(e,t,r){let n=Sr(yr(e)),i=Ra(n,t,r);hr(e,Buffer.from(br(i)))}function Na(e){let t=e[0]?.metadata;if(!t)return;let r=t.projectRoot;for(let n of e.slice(1)){let i=n.metadata?.projectRoot;if(r&&i&&i!==r)throw new Error(`Cannot merge SCIP indexes with different project roots: ${r} vs ${i}`)}return t}function Pa(e){let t=new Map;for(let r of e){let n=t.get(r.relativePath);if(!n){t.set(r.relativePath,r);continue}t.set(r.relativePath,Ge(wa,{language:n.language||r.language,relativePath:n.relativePath||r.relativePath,occurrences:Da([...n.occurrences,...r.occurrences]),symbols:ii([...n.symbols,...r.symbols]),text:Aa(n.text,r.text),positionEncoding:n.positionEncoding||r.positionEncoding}))}return[...t.values()]}function Da(e){let t=new Set,r=[];for(let n of e){let i=JSON.stringify(n);t.has(i)||(t.add(i),r.push(n))}return r}function ii(e){let t=new Map;for(let r of e){let n=t.get(r.symbol);if(!n){t.set(r.symbol,r);continue}t.set(r.symbol,Ge(Ca,{symbol:n.symbol,documentation:Fa([...n.documentation,...r.documentation]),relationships:_a([...n.relationships,...r.relationships]),kind:n.kind||r.kind,displayName:n.displayName||r.displayName,enclosingSymbol:n.enclosingSymbol||r.enclosingSymbol,signatureDocumentation:n.signatureDocumentation??r.signatureDocumentation}))}return[...t.values()]}function _a(e){let t=new Set,r=[];for(let n of e){let i=[n.symbol,n.isReference?"1":"0",n.isImplementation?"1":"0",n.isTypeDefinition?"1":"0",n.isDefinition?"1":"0"].join("|");t.has(i)||(t.add(i),r.push(n))}return r}function Aa(e,t){return e?t?e.length>=t.length?e:t:e:t}function Fa(e){return[...new Set(e)]}import{createHash as Ba}from"crypto";import{existsSync as Ve,mkdirSync as Ua,readFileSync as Ue,readdirSync as Tr,renameSync as Ha,rmSync as xi,writeFileSync as qa}from"fs";import{join as $}from"path";import{createHash as Oa}from"crypto";import{existsSync as Ir,mkdirSync as La,readFileSync as ht,readdirSync as bf,renameSync as ja,rmSync as xf,writeFileSync as Ma}from"fs";import{join as Ne}from"path";import{create as si,fromBinary as ai,toBinary as $a}from"@bufbuild/protobuf";import{deserializeSCIP as St,DocumentSchema as Er,IndexSchema as ci,serializeSCIP as li}from"@c4312/scip";var bt=1,We="typescript-scip-fragments";function wf(e){if(e.length===0)throw new Error("affected TypeScript mini index requires documents");let t=new Set,r=[];for(let o of e){let s=pe(o.relativePath);if(t.has(s))throw new Error(`duplicate TypeScript fragment replacement: ${s}`);if(t.add(s),o.bytes===null)throw new Error(`affected TypeScript mini index cannot contain a deleted document: ${s}`);let a=ai(Er,o.bytes);if(a.relativePath!==s)throw new Error(`TypeScript fragment path mismatch: expected ${s}, got ${a.relativePath}`);r.push(a)}let n=li(si(ci,{documents:r,externalSymbols:[]})),i=St(n);if(i.documents.length!==r.length||i.externalSymbols.length!==0)throw new Error("affected TypeScript SCIP index failed structural verification");return n}function xt(e){let t=Ne(e,We);return{rootDir:t,blobDir:Ne(t,"blobs"),generationDir:Ne(t,"generations")}}function Ga(e){let t=St(e.indexBytes);Si(t.metadata,bi(e)),hi(t.externalSymbols);let r=new Set,n=[];for(let o of t.documents){let s=pe(o.relativePath);if(r.has(s))throw new Error(`duplicate TypeScript SCIP document path: ${s}`);r.add(s);let a=$a(Er,o),c=e.documentIdentities.get(s)??(e.allowUntrackedDocuments?ue(JSON.stringify({version:1,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity,untrackedDocument:s,contentHash:ue(a)})):null);if(!c)throw new Error(`missing TypeScript document identity: ${s}`);n.push(fi(e.cacheDir,{relativePath:s,bytes:a,occurrences:o.occurrences.length,symbols:o.symbols.length,referenceFragments:[]},c))}let i=mi(e,n);return gi(e.cacheDir,i),i}function kf(e){let t=xt(e.cacheDir);if(!Ir(vr(t,e.generationIdentity)))return Ga(e);let r=pi({cacheDir:e.cacheDir,generationIdentity:e.generationIdentity,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity});if(!e.allowUntrackedDocuments&&r.manifest.documents.length!==e.documentIdentities.size)throw new Error("TypeScript fragment generation document identities changed");for(let n of r.manifest.documents){let i=e.documentIdentities.get(n.relativePath);if(!(i===void 0&&e.allowUntrackedDocuments)&&i!==n.documentIdentity)throw new Error(`TypeScript fragment generation document identity changed: ${n.relativePath}`)}return r.manifest}function Cf(e){let t=pi({cacheDir:e.cacheDir,generationIdentity:e.previousGenerationIdentity,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity}).manifest,r=new Map(t.documents.map(o=>[o.relativePath,o])),n=new Set;for(let o of e.fragments){let s=pe(o.relativePath);if(n.has(s))throw new Error(`duplicate TypeScript fragment replacement: ${s}`);if(n.add(s),!r.has(s))throw new Error(`TypeScript fragment replacement has no prior document: ${s}`);let a=e.documentIdentities.get(s);if(!a)throw new Error(`missing TypeScript document identity: ${s}`);o.bytes===null?r.delete(s):r.set(s,fi(e.cacheDir,o,a))}if(n.size===0)throw new Error("TypeScript fragment generation requires at least one replacement");let i=mi(e,[...r.values()]);return gi(e.cacheDir,i),i}function pi(e){let t=xt(e.cacheDir),r=vr(t,e.generationIdentity),n;try{n=yi(ht(r,"utf8"))}catch(o){throw new Error(`TypeScript fragment generation is unavailable: ${o instanceof Error?o.message:String(o)}`,{cause:o})}if(n.generationIdentity!==e.generationIdentity)throw new Error("TypeScript fragment generation identity does not match its manifest path");if(e.producerIdentity&&n.producerIdentity!==e.producerIdentity)throw new Error("TypeScript fragment producer identity changed");if(e.projectIdentity&&n.projectIdentity!==e.projectIdentity)throw new Error("TypeScript fragment project identity changed");let i=new Map;for(let o of n.documents){let s=Ne(t.blobDir,`${o.blobHash}.scipdoc`),a=ht(s);if(a.byteLength!==o.byteLength||ue(a)!==o.blobHash)throw new Error(`TypeScript fragment blob is corrupt: ${o.relativePath}`);i.set(o.relativePath,a)}return{manifest:n,fragments:i}}function ui(e){let t=di(e);return xr(t.baseIndex,t.completeDocuments,"assembled")}function Rf(e){let t=di(e);return Wa(t.deletedAffectedPaths),{completeIndexBytes:xr(t.baseIndex,t.completeDocuments,"assembled"),affectedIndexBytes:xr(t.baseIndex,t.affectedDocuments,"affected")}}function di(e){let t=St(e.baseIndexBytes);Si(t.metadata,bi(e)),hi(t.externalSymbols);let r=new Map;for(let a of e.fragments){let c=pe(a.relativePath);if(r.has(c))throw new Error(`duplicate TypeScript fragment replacement: ${c}`);r.set(c,a)}if(r.size===0)throw new Error("TypeScript index assembly requires at least one replacement");let n=new Set,i=[],o=[],s=[];for(let a of t.documents){let c=pe(a.relativePath);if(n.has(c))throw new Error(`duplicate TypeScript SCIP document path: ${c}`);n.add(c);let l=r.get(c);if(!l){i.push(a);continue}if(r.delete(c),l.bytes===null){s.push(c);continue}let p=ai(Er,l.bytes);if(p.relativePath!==c)throw new Error(`TypeScript fragment path mismatch: expected ${c}, got ${p.relativePath}`);i.push(p),o.push(p)}if(r.size>0)throw new Error(`TypeScript fragment replacement has no prior document: ${[...r.keys()].sort()[0]}`);return{baseIndex:t,completeDocuments:i,affectedDocuments:o,deletedAffectedPaths:s}}function xr(e,t,r){let n=li(si(ci,{metadata:e.metadata,documents:t,externalSymbols:[]})),i=St(n);if(i.documents.length!==t.length||i.externalSymbols.length!==0)throw new Error(`${r} TypeScript SCIP index failed structural verification`);return n}function Wa(e){if(e.length>0)throw new Error(`affected TypeScript mini index cannot contain a deleted document: ${e[0]}`)}function fi(e,t,r){if(t.bytes===null)throw new Error(`cannot persist an empty TypeScript fragment: ${t.relativePath}`);let n=pe(t.relativePath),i=Buffer.from(t.bytes),o=ue(i),s=xt(e);La(s.blobDir,{recursive:!0});let a=Ne(s.blobDir,`${o}.scipdoc`);if(Ir(a)){let c=ht(a);if(c.byteLength!==i.byteLength||ue(c)!==o)throw new Error(`existing TypeScript fragment blob is corrupt: ${n}`)}else{let c=`${a}.${process.pid}.${Date.now()}.tmp`;Ma(c,i),ja(c,a)}return{relativePath:n,blobHash:o,byteLength:i.byteLength,documentIdentity:r}}function mi(e,t){if(!e.producerIdentity||!e.projectIdentity||!e.generationIdentity)throw new Error("TypeScript fragment generation identities must be non-empty");let r=[...t].sort((n,i)=>n.relativePath.localeCompare(i.relativePath));if(new Set(r.map(n=>n.relativePath)).size!==r.length)throw new Error("TypeScript fragment generation contains duplicate document paths");return{version:bt,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity,generationIdentity:e.generationIdentity,createdAt:(e.now??(()=>new Date))().toISOString(),documents:r}}function gi(e,t){let r=xt(e),n=vr(r,t.generationIdentity);if(Ir(n)){let i=yi(ht(n,"utf8"));if(oi(i)!==oi(t))throw new Error(`TypeScript fragment generation is immutable: ${t.generationIdentity}`);return}j(n,t,{spacing:2,trailingNewline:!0})}function oi(e){return ue(JSON.stringify({version:e.version,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity,generationIdentity:e.generationIdentity,documents:e.documents}))}function yi(e){let t=JSON.parse(e);if(t.version!==bt||typeof t.producerIdentity!="string"||typeof t.projectIdentity!="string"||typeof t.generationIdentity!="string"||typeof t.createdAt!="string"||!Number.isFinite(Date.parse(t.createdAt))||!Array.isArray(t.documents))throw new Error("invalid TypeScript fragment generation manifest");let r=new Set;for(let n of t.documents){if(!n||typeof n.relativePath!="string"||typeof n.blobHash!="string"||!/^[a-f0-9]{64}$/.test(n.blobHash)||typeof n.byteLength!="number"||!Number.isInteger(n.byteLength)||n.byteLength<0||typeof n.documentIdentity!="string"||!n.documentIdentity)throw new Error("invalid TypeScript fragment record");if(pe(n.relativePath),r.has(n.relativePath))throw new Error("duplicate TypeScript fragment record");r.add(n.relativePath)}return t}function vr(e,t){return Ne(e.generationDir,Va(t))}function Va(e){if(!e)throw new Error("TypeScript fragment generation identity must be non-empty");return`${ue(e)}.json`}function hi(e){if(e.length>0)throw new Error("scip-typescript emitted external symbols; incremental document assembly is unsupported")}function Si(e,t){if(!e||typeof e!="object")throw new Error("TypeScript SCIP shard has no producer metadata");let r=e,n=r.toolInfo??r.tool_info;if(!n||typeof n!="object")throw new Error("TypeScript SCIP shard has no producer tool identity");let i=n;if(i.name!=="scip-typescript"||i.version!==t)throw new Error("TypeScript SCIP shard producer identity changed")}function bi(e){let t=e.packageVersion??e.runtime?.packageVersion;if(!t)throw new Error("scip-typescript package version is unavailable");return t}function pe(e){if(!e||e.startsWith("/")||e.startsWith("\\")||e.includes("\\"))throw new Error(`invalid TypeScript SCIP document path: ${e}`);let t=e.split("/");if(t.includes("")||t.includes(".")||t.includes(".."))throw new Error(`invalid TypeScript SCIP document path: ${e}`);return e}function ue(e){return Oa("sha256").update(e).digest("hex")}var It=1,Of=64*1024*1024,He="typescript-scip-overlays";function Lf(e){let t=Ei(e.cacheDir,e.previousGenerationIdentity);if(!t&&!e.baseShardCurrent)throw new Error("deferred TypeScript SCIP base has no matching overlay generation");if(t&&(t.producerIdentity!==e.producerIdentity||t.projectIdentity!==e.projectIdentity))throw new Error("TypeScript overlay producer or project identity changed");let r=new Map((t?.overlays??[]).map(o=>[o.relativePath,o])),n=new Set;for(let o of e.fragments){let s=Cr(o.relativePath);if(n.has(s))throw new Error(`duplicate TypeScript overlay: ${s}`);n.add(s),r.set(s,za(e.cacheDir,o))}if(n.size===0)throw new Error("TypeScript overlay generation requires affected documents");let i={version:It,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity,baseGenerationIdentity:t?.baseGenerationIdentity??e.previousGenerationIdentity,generationIdentity:e.nextGenerationIdentity,createdAt:(e.now??(()=>new Date))().toISOString(),overlays:[...r.values()].sort((o,s)=>o.relativePath.localeCompare(s.relativePath))};return Ja(e.cacheDir,i),i}function jf(e){let t=Ei(e.cacheDir,e.generationIdentity);if(!t)throw new Error("TypeScript overlay generation is unavailable");let r=t.overlays.map(n=>{if(n.blobHash===null)return{relativePath:n.relativePath,bytes:null,occurrences:0,symbols:0,referenceFragments:[]};let i=Ue($(qe(e.cacheDir),"blobs",`${n.blobHash}.scipdoc`));if(i.byteLength!==n.byteLength||Be(i)!==n.blobHash)throw new Error(`TypeScript overlay blob is corrupt: ${n.relativePath}`);return{relativePath:n.relativePath,bytes:i,occurrences:0,symbols:0,referenceFragments:[]}});return ui({packageVersion:e.packageVersion,baseIndexBytes:e.baseIndexBytes,fragments:r})}function Mf(e,t){let r=qe(e),n=$(r,"generations");if(!Ve(n))return;let i=new Set(t.map(kr)),o=new Set;for(let a of Tr(n).filter(c=>i.has(c))){let c=wr(Ue($(n,a),"utf8"));for(let l of c.overlays)l.blobHash&&o.add(`${l.blobHash}.scipdoc`)}for(let a of Tr(n))i.has(a)||xi($(n,a),{force:!0});let s=$(r,"blobs");if(Ve(s))for(let a of Tr(s))o.has(a)||xi($(s,a),{force:!0})}function Ei(e,t){let r=$(qe(e),"generations",kr(t));if(!Ve(r))return null;let n=wr(Ue(r,"utf8"));if(n.generationIdentity!==t)throw new Error("TypeScript overlay generation identity does not match its path");return n}function za(e,t){let r=Cr(t.relativePath);if(t.bytes===null)return{relativePath:r,blobHash:null,byteLength:0};let n=Buffer.from(t.bytes),i=Be(n),o=$(qe(e),"blobs");Ua(o,{recursive:!0});let s=$(o,`${i}.scipdoc`);if(Ve(s)){let a=Ue(s);if(a.byteLength!==n.byteLength||Be(a)!==i)throw new Error(`existing TypeScript overlay blob is corrupt: ${r}`)}else{let a=`${s}.${process.pid}.${Date.now()}.tmp`;qa(a,n),Ha(a,s)}return{relativePath:r,blobHash:i,byteLength:n.byteLength}}function Ja(e,t){let r=$(qe(e),"generations",kr(t.generationIdentity));if(Ve(r)){let n=wr(Ue(r,"utf8"));if(Ii(n)!==Ii(t))throw new Error(`TypeScript overlay generation is immutable: ${t.generationIdentity}`);return}j(r,t,{spacing:2,trailingNewline:!0})}function wr(e){let t=JSON.parse(e);if(t.version!==It||typeof t.producerIdentity!="string"||!t.producerIdentity||typeof t.projectIdentity!="string"||!t.projectIdentity||typeof t.baseGenerationIdentity!="string"||!t.baseGenerationIdentity||typeof t.generationIdentity!="string"||!t.generationIdentity||typeof t.createdAt!="string"||!Number.isFinite(Date.parse(t.createdAt))||!Array.isArray(t.overlays))throw new Error("invalid TypeScript overlay manifest");let r=new Set;for(let n of t.overlays){if(!n||typeof n.relativePath!="string"||n.blobHash!==null&&(typeof n.blobHash!="string"||!/^[a-f0-9]{64}$/.test(n.blobHash))||!Number.isInteger(n.byteLength)||n.byteLength<0||n.blobHash===null&&n.byteLength!==0)throw new Error("invalid TypeScript overlay record");if(Cr(n.relativePath),r.has(n.relativePath))throw new Error("duplicate TypeScript overlay record");r.add(n.relativePath)}return t}function qe(e){return $(e,He)}function kr(e){if(!e)throw new Error("TypeScript overlay generation identity must be non-empty");return`${Be(e)}.json`}function Ii(e){return Be(JSON.stringify({version:e.version,producerIdentity:e.producerIdentity,projectIdentity:e.projectIdentity,baseGenerationIdentity:e.baseGenerationIdentity,generationIdentity:e.generationIdentity,overlays:e.overlays}))}function Cr(e){if(!e||e.startsWith("/")||e.includes("\\")||e.split("/").some(t=>!t||t==="."))throw new Error(`invalid TypeScript overlay path: ${e}`);if(e.split("/").includes(".."))throw new Error(`invalid TypeScript overlay path: ${e}`);return e}function Be(e){return Ba("sha256").update(e).digest("hex")}import{createHash as Xa}from"crypto";import{copyFileSync as vi,existsSync as K,linkSync as Ya,mkdirSync as Ti,readFileSync as Ci,readdirSync as wi,renameSync as Nr,rmSync as vt,statSync as Ka}from"fs";import{basename as Et,dirname as ze,join as E,relative as ki}from"path";var Pe=1,Tt=".scipquery-generations";function Ri(e){let t=wt(e.outputDb),r=Qa(e,t);e.onStage?.("after-recovery-retained"),e.preserveOutputScip||Rr(e.tempOutputScip,e.outputScip),e.onStage?.("after-scip-handoff"),Rr(e.tempOutputDb,e.outputDb),e.onStage?.("after-database-handoff"),Rr(e.tempMetaPath,e.metaPath),e.onStage?.("after-metadata-handoff");let n=kt(e.metaPath,e.outputDb),i={version:Pe,currentGeneration:n,...r?{previousGeneration:r}:{},...e.publication?{publication:e.publication}:{},publishedAt:(e.now??(()=>new Date))().toISOString()};return j(E(t,"state.json"),i,{spacing:2,trailingNewline:!0}),{currentGeneration:n,...r?{previousGeneration:r}:{}}}function Ni(e){try{let t=JSON.parse(Ci(E(wt(e),"state.json"),"utf8"));return t.version!==Pe||typeof t.currentGeneration!="string"||!t.currentGeneration||typeof t.publishedAt!="string"||!Number.isFinite(Date.parse(t.publishedAt))||!tc(t.previousGeneration)||!rc(t.publication)?null:t}catch{return null}}function Uf(e,t,r=()=>new Date){if(!K(e)||!K(t))throw new Error("metadata-only generation refresh requires stable database and metadata files");let n=Ni(e),i={version:Pe,currentGeneration:kt(t,e),...n?.previousGeneration?{previousGeneration:n.previousGeneration}:{},...n?.publication?{publication:n.publication}:{},publishedAt:r().toISOString()};return j(E(wt(e),"state.json"),i,{spacing:2,trailingNewline:!0}),i}function Pr(e,t=E(ze(e),"meta.json")){let r=E(wt(e),"state.json");if(!K(r))return{state:"legacy",statePath:r};let n=Ni(e);if(!n)return{state:"invalid",statePath:r,reason:"generation state is malformed"};try{let i=kt(t,e),o=n.currentGeneration===i,s=n.previousGeneration?K(E(ze(e),n.previousGeneration.databasePath)):!0;return!o||!s?{state:"drifted",statePath:r,currentMatches:o,recoveryExists:s,generation:n,reason:o?"retained recovery database is missing":"stable database or metadata no longer matches the published generation"}:{state:"current",statePath:r,currentMatches:o,recoveryExists:s,generation:n}}catch(i){return{state:"drifted",statePath:r,currentMatches:!1,recoveryExists:!1,generation:n,reason:i instanceof Error?i.message:String(i)}}}function wt(e){return E(ze(e),Tt)}function Qa(e,t){if(!K(e.outputDb))return;let r=kt(e.metaPath,e.outputDb),n=E(t,r),i=E(n,Et(e.outputDb)),o=K(e.metaPath)?E(n,Et(e.metaPath)):void 0;if(!K(i)){let s=`${n}.${process.pid}.${Date.now()}.tmp`;vt(s,{recursive:!0,force:!0}),Ti(s,{recursive:!0});let a=E(s,Et(e.outputDb));try{Ya(e.outputDb,a)}catch{vi(e.outputDb,a)}o&&vi(e.metaPath,E(s,Et(e.metaPath))),Ti(t,{recursive:!0}),Nr(s,n)}return Za(t,r),{generationIdentity:r,databasePath:ki(ze(e.outputDb),i),...o?{metadataPath:ki(ze(e.outputDb),o)}:{}}}function Za(e,t){for(let r of wi(e,{withFileTypes:!0}))!r.isDirectory()||r.name===t||r.name.endsWith(".tmp")||vt(E(e,r.name),{recursive:!0,force:!0});for(let r of wi(e,{withFileTypes:!0}))r.isDirectory()&&r.name.endsWith(".tmp")&&vt(E(e,r.name),{recursive:!0,force:!0})}function kt(e,t){let r=Xa("sha256").update(`sqlite-generation-v${Pe}\0`);K(e)&&r.update(ec(Ci(e,"utf8")));let n=Ka(t);return r.update(`\0${n.size}`),r.digest("hex")}function ec(e){try{let t=JSON.parse(e);if((t.version===2||t.version===3)&&t.status==="complete"&&typeof t.updatedAt=="string"&&t.fingerprint!==void 0)return JSON.stringify({version:t.version,status:t.status,updatedAt:t.updatedAt,fingerprint:t.fingerprint,indexedLanguages:t.indexedLanguages,scipCompanion:t.scipCompanion})}catch{}return e}function Rr(e,t){vt(`${t}.tmp-replace`,{force:!0}),Nr(e,`${t}.tmp-replace`),Nr(`${t}.tmp-replace`,t)}function tc(e){if(e===void 0)return!0;if(!e||typeof e!="object")return!1;let t=e;return typeof t.generationIdentity=="string"&&!!t.generationIdentity&&typeof t.databasePath=="string"&&!!t.databasePath&&(t.metadataPath===void 0||typeof t.metadataPath=="string"&&!!t.metadataPath)}function rc(e){if(e===void 0)return!0;if(!e||typeof e!="object")return!1;let t=e,r=[t.converterDurationMs,t.affectedDocumentCount,t.changedDocumentCount,t.producerDurationMs,t.materializationDurationMs,t.patchDurationMs].filter(n=>n!==void 0);return(t.mode==="incremental"||t.mode==="full")&&t.validation==="passed"&&t.converterDurationMs!==void 0&&r.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>=0)&&(t.scipCompanion===void 0||t.scipCompanion==="current"||t.scipCompanion==="deferred")&&(t.typescriptOverlayGeneration===void 0||typeof t.typescriptOverlayGeneration=="string"&&!!t.typescriptOverlayGeneration)&&(t.scipCompanion!=="deferred"||!!t.typescriptOverlayGeneration)&&(t.fallbackReason===void 0||typeof t.fallbackReason=="string")}import{createHash as Mi,randomUUID as Or}from"crypto";import{closeSync as $i,constants as dc,copyFileSync as Fi,existsSync as Z,lstatSync as fc,mkdirSync as U,mkdtempSync as Gi,openSync as Wi,readdirSync as mc,readFileSync as G,realpathSync as gc,renameSync as de,rmSync as Q,statSync as yc,unlinkSync as Ar,writeFileSync as Vi}from"fs";import{dirname as Bi,join as f,resolve as Ke}from"path";import{setTimeout as hc}from"timers/promises";import{pathToFileURL as Oi}from"url";import{deserializeSCIP as Ui}from"@c4312/scip";import Sc from"better-sqlite3";import{createRequire as nc}from"module";var ic=nc(import.meta.url),Pi=oc().version;function oc(){for(let e of["../package.json","../../package.json"])try{return ic(e)}catch{}return{version:"0.0.0"}}import{lstatSync as sc,readdirSync as ac}from"fs";import{join as cc,relative as lc,resolve as Dr,sep as pc}from"path";var Je=1,_r="language-indexes",Di=["index.db","index.scip","meta.json"],_i=[_r,We,He];function Ct(e){let t=[];for(let r of Di)uc(e,r),t.push(r);for(let r of _i)Ai(e,r,t);return{version:Je,files:t.sort()}}function Rt(e){if(!e||e.includes("\0")||e.startsWith("/")||e.includes("\\"))throw new Error(`invalid index artifact path: ${e||"<empty>"}`);let t=e.split("/");if(t.some(n=>!n||n==="."||n===".."))throw new Error(`invalid index artifact path: ${e}`);let r=t[0];if(!Di.includes(e)&&!_i.includes(r))throw new Error(`index artifact path is not shareable: ${e}`);return e}function V(e,t){let r=Rt(t),n=Dr(e),i=Dr(n,...r.split("/"));if(i!==n&&!i.startsWith(`${n}${pc}`))throw new Error(`index artifact escapes cache: ${t}`);return i}function Ai(e,t,r){let n=cc(e,t),i;try{i=ac(n,{withFileTypes:!0,encoding:"utf8"})}catch{return}for(let o of i){let s=`${t}/${o.name}`;if(o.isSymbolicLink())throw new Error(`index artifact cannot be a symlink: ${s}`);o.isDirectory()?Ai(e,s,r):o.isFile()&&r.push(Rt(s))}}function uc(e,t){let r=V(e,t),n;try{n=sc(r)}catch{throw new Error(`required index artifact is missing: ${t}`)}if(!n.isFile()||n.isSymbolicLink())throw new Error(`required index artifact is not a regular file: ${t}`);if(lc(Dr(e),r).startsWith(".."))throw new Error(`index artifact escapes cache: ${t}`)}var Lr=1,Li="SCIP_QUERY_SHARED_CACHE",Fr=JSON.stringify({cliVersion:Pi,artifactCatalogVersion:Je,sqliteGenerationStoreVersion:Pe,typescriptFragmentStoreVersion:bt,typescriptOverlayStoreVersion:It}),Hi="manifest.json",bc="shared-cache.json",jr=[_r,We,He];function hm(e,t){if(!e.clean||!e.treeOid)return;let r=Ze(JSON.stringify({version:Lr,repositoryId:e.repositoryId,treeOid:e.treeOid,fingerprint:t,producerIdentity:Fr}));return{repositoryId:e.repositoryId,worktreeId:e.worktreeId,projectRoot:e.projectRoot,treeOid:e.treeOid,fingerprint:t,producerIdentity:Fr,generationId:r,repositoryCacheDir:or(e.repositoryId)}}function Sm(e,t,r){if(process.env[Li]==="0")return`${Li}=0`;if(!sr(r))return"explicit cache or database override";if(Ke(t)!==Ke(f(ir(e),"index.db")))return"index database is outside the managed worktree cache"}function bm(e,t,r){if(!sr(t))return;let n=r??Pn(e);return n?f(or(n.repositoryId),"evidence.db"):void 0}function Ye(e,t=!0){let r=Mr(e),n;try{n=Ec(G(f(r,Hi),"utf8"))}catch{return null}if(n.generationId!==e.generationId||n.repositoryId!==e.repositoryId||n.treeOid!==e.treeOid||n.producerIdentity!==e.producerIdentity||JSON.stringify(n.fingerprint)!==JSON.stringify(e.fingerprint))return null;if(!t)return n;try{for(let i of n.artifacts){let o=V(r,i.path),s=yc(o);if(!s.isFile()||s.size!==i.size||Ze(G(o))!==i.sha256)return null}}catch{return null}return n}function xm(e){let t=Ye(e.snapshot);if(t)return t;if(!Ji(e.sourceCacheDir,e.sourceProjectRoot,e.snapshot.fingerprint))throw new Error("source index is incomplete, incompatible, or corrupt");let r=ji(e.sourceCacheDir);if(!r)throw new Error("source index artifacts are incomplete");let n=Ct(e.sourceCacheDir),i=f(e.snapshot.repositoryCacheDir,"generations");U(i,{recursive:!0});let o=Gi(f(i,`.tmp-${process.pid}-`));try{let s=[];for(let u of n.files){let d=V(e.sourceCacheDir,u),m=V(o,u);Qe(d,m);let y=G(m);s.push({path:u,size:y.byteLength,sha256:Ze(y)})}let a=Ui(G(f(o,"index.scip"))).metadata?.projectRoot;if(!a)throw new Error("shared SCIP generation has no project root metadata");let c=$r(e.sourceProjectRoot);if(a!==c)throw new Error("shared SCIP generation root does not match its source worktree");if(ji(e.sourceCacheDir)!==r||e.sourceStillValid&&!e.sourceStillValid())throw new Error("source index changed while staging a shared generation");let l={version:Lr,artifactCatalogVersion:Je,generationId:e.snapshot.generationId,repositoryId:e.snapshot.repositoryId,treeOid:e.snapshot.treeOid,fingerprint:e.snapshot.fingerprint,producerIdentity:e.snapshot.producerIdentity,sourceProjectRoot:e.sourceProjectRoot,scipProjectRoot:a,createdAt:(e.now??(()=>new Date))().toISOString(),artifacts:s.sort((u,d)=>u.path.localeCompare(d.path))};j(f(o,Hi),l,{spacing:2,trailingNewline:!0});let p=Mr(e.snapshot);try{if(Z(p)&&!Ye(e.snapshot)){let u=`${p}.corrupt-${process.pid}-${Date.now()}`;de(p,u),Q(u,{recursive:!0,force:!0})}de(o,p)}catch(u){let d=Ye(e.snapshot);if(d)return d;throw u}return l}finally{Q(o,{recursive:!0,force:!0})}}function Im(e){let t=Mr(e.snapshot);U(e.targetCacheDir,{recursive:!0});let r=lr(f(e.targetCacheDir,"cache-lifecycle.lock"),{waitMs:3e4});if(!r)throw new Error("timed out waiting for another cache hydration");let n,i,o=!1;try{n=Gi(f(e.targetCacheDir,".shared-hydrate-")),Pc(e.manifest,e.snapshot);for(let c of e.manifest.artifacts){let l=V(t,c.path),p=V(n,c.path);Qe(l,p);let u=G(p);if(u.byteLength!==c.size||Ze(u)!==c.sha256)throw new Error(`shared artifact is corrupt: ${c.path}`)}let s=$r(e.targetProjectRoot);if(s!==e.manifest.scipProjectRoot)for(let c of e.manifest.artifacts)c.path.endsWith(".scip")&&ni(V(n,c.path),e.manifest.scipProjectRoot,s);if(!Ji(n,e.targetProjectRoot,e.snapshot.fingerprint,!1))throw new Error("staged shared generation failed completeness or integrity validation");i=Cc(e.targetCacheDir,n),o=!0,Rc(n,e.targetCacheDir,i),Ri({tempOutputScip:f(n,"index.scip"),tempOutputDb:f(n,"index.db"),tempMetaPath:f(n,"meta.json"),outputScip:f(e.targetCacheDir,"index.scip"),outputDb:f(e.targetCacheDir,"index.db"),metaPath:f(e.targetCacheDir,"meta.json"),now:e.now});let a=Pr(f(e.targetCacheDir,"index.db"),f(e.targetCacheDir,"meta.json"));if(a.state==="invalid"||a.state==="drifted")throw new Error(`hydrated SQLite generation failed validation: ${a.reason}`);xc(e.snapshot,e.targetCacheDir,e.action??"attached",e.now)}catch(s){throw o&&i&&Nc(e.targetCacheDir,i),s}finally{n&&Q(n,{recursive:!0,force:!0}),r.release()}}async function Em(e,t={}){let r=t.timeoutMs??3e4,n=t.pollMs??100,i=t.now??Date.now,o=i()+r,s=f(e.repositoryCacheDir,"locks"),a=f(s,`${e.generationId}.lock`);for(U(s,{recursive:!0});i()<=o;){if(Ye(e))return{kind:"generation-ready"};let c=Or();try{let l=Wi(a,"wx");try{Vi(l,`${JSON.stringify({version:1,pid:process.pid,token:c,generationId:e.generationId,startedAt:new Date(i()).toISOString()})}
105
- `)}finally{$i(l)}return{kind:"owner",release:()=>{try{let p=JSON.parse(G(a,"utf8"));p.pid===process.pid&&p.token===c&&Ar(a)}catch{}}}}catch(l){if(l.code!=="EEXIST")return{kind:"timeout"};let p=qi(a);if(p&&(p.pid===void 0||!we(p.pid))){wc(a,p);continue}await hc(n)}}return Ye(e)?{kind:"generation-ready"}:{kind:"timeout"}}function xc(e,t,r,n=void 0){let i={version:1,repositoryId:e.repositoryId,worktreeId:e.worktreeId,projectRoot:e.projectRoot,treeOid:e.treeOid,localCacheDir:t,baseGenerationId:e.generationId,activeGenerationId:e.generationId,lastAction:r,lastSeenAt:(n??(()=>new Date))().toISOString()},o={...i,ownershipChecksum:Ic(i)};return kc(e.repositoryCacheDir,o,!0),o}function Ic(e){return Ze(JSON.stringify({version:1,repositoryId:e.repositoryId,worktreeId:e.worktreeId,projectRoot:Ke(e.projectRoot),localCacheDir:Ke(e.localCacheDir)}))}function Ec(e){let t=JSON.parse(e);if(t.version!==Lr||t.artifactCatalogVersion!==Je||typeof t.generationId!="string"||!/^[a-f0-9]{64}$/.test(t.generationId)||typeof t.repositoryId!="string"||!/^[a-f0-9]{24}$/.test(t.repositoryId)||typeof t.treeOid!="string"||!t.treeOid||typeof t.producerIdentity!="string"||t.producerIdentity!==Fr||typeof t.sourceProjectRoot!="string"||typeof t.scipProjectRoot!="string"||typeof t.createdAt!="string"||!Number.isFinite(Date.parse(t.createdAt))||!t.fingerprint||!Array.isArray(t.artifacts))throw new Error("invalid shared generation manifest");let r=new Set;for(let n of t.artifacts){if(!n||typeof n.path!="string"||typeof n.size!="number"||n.size<0||typeof n.sha256!="string"||!/^[a-f0-9]{64}$/.test(n.sha256))throw new Error("invalid shared generation artifact");if(Rt(n.path),r.has(n.path))throw new Error(`duplicate shared generation artifact: ${n.path}`);r.add(n.path)}for(let n of["index.db","index.scip","meta.json"])if(!r.has(n))throw new Error(`shared generation is missing ${n}`);return t}function Qe(e,t){U(Bi(t),{recursive:!0});try{Fi(e,t,dc.COPYFILE_FICLONE)}catch{Fi(e,t)}}function vc(e,t,r){U(e,{recursive:!0}),j(f(e,bc),{version:1,repositoryId:t,worktreeId:r},{spacing:2,trailingNewline:!0})}function ji(e){try{let t=Ct(e),r=Mi("sha256");for(let n of t.files){let i=G(V(e,n));r.update(n).update("\0").update(String(i.byteLength)).update("\0").update(i).update("\0")}return r.digest("hex")}catch{return null}}function Tc(e){try{return JSON.parse(G(f(e,"meta.json"),"utf8"))}catch{return}}function Mr(e){return f(e.repositoryCacheDir,"generations",e.generationId)}function qi(e){try{let t=G(e,"utf8"),r=JSON.parse(t),n=typeof r.pid=="number"&&Number.isSafeInteger(r.pid)&&r.pid>0?r.pid:void 0;return{raw:t,...n===void 0?{}:{pid:n}}}catch{return null}}function wc(e,t){let r=`${e}.reclaim`,n=Or(),i;try{i=Wi(r,"wx")}catch{return!1}try{Vi(i,`${JSON.stringify({version:1,pid:process.pid,token:n,startedAt:new Date().toISOString()})}
106
- `)}finally{$i(i)}try{let o=qi(e);return!o||o.raw!==t.raw||o.pid!==void 0&&we(o.pid)?!1:(Ar(e),!0)}catch{return!1}finally{try{let o=JSON.parse(G(r,"utf8"));o.pid===process.pid&&o.token===n&&Ar(r)}catch{}}}function kc(e,t,r){let n=Mn(e,{waitMs:5e3});if(!n)throw new Error("repository cache cleanup is busy");try{if(r){let o=t.activeGenerationId;if(!o||!Z(f(e,"generations",o)))throw new Error("shared generation disappeared before its lease was attached")}let i=f(e,"worktrees");U(i,{recursive:!0}),j(f(i,`${t.worktreeId}.json`),t,{spacing:2,trailingNewline:!0}),vc(t.localCacheDir,t.repositoryId,t.worktreeId)}finally{n.release()}}function Cc(e,t){let r=f(t,".rollback"),n=new Map,i=new Map;U(r,{recursive:!0});for(let a of["index.scip","index.db","meta.json"]){let c=f(e,a),l=Z(c);n.set(a,l),l&&Qe(c,f(r,"stable",a))}for(let a of jr){let c=f(e,a),l=Z(c);if(l){let p=fc(c);if(!p.isDirectory()||p.isSymbolicLink())throw new Error(`managed artifact path is not a directory: ${a}`)}i.set(a,l)}let o=f(e,Tt),s=Z(o);return s&&zi(o,f(r,"sqlite-generations")),{root:r,stableFiles:n,managedDirectories:i,generationStoreExisted:s}}function Rc(e,t,r){for(let n of jr){let i=f(t,n);if(r.managedDirectories.get(n)){let s=f(r.root,"managed",n);U(Bi(s),{recursive:!0}),de(i,s)}let o=f(e,n);Z(o)&&de(o,i)}}function Nc(e,t){for(let i of jr){let o=f(e,i),s=f(t.root,"managed",i);t.managedDirectories.get(i)?Z(s)&&(Q(o,{recursive:!0,force:!0}),de(s,o)):Q(o,{recursive:!0,force:!0})}for(let[i,o]of t.stableFiles){let s=f(e,i);if(!o){Q(s,{force:!0});continue}let a=`${s}.shared-restore-${Or()}`;Qe(f(t.root,"stable",i),a),Q(s,{force:!0}),de(a,s)}let r=f(e,Tt);Q(r,{recursive:!0,force:!0});let n=f(t.root,"sqlite-generations");t.generationStoreExisted&&Z(n)&&de(n,r)}function zi(e,t){U(t,{recursive:!0});for(let r of mc(e,{withFileTypes:!0})){let n=f(e,r.name),i=f(t,r.name);if(r.isSymbolicLink())throw new Error(`managed cache backup cannot contain a symlink: ${n}`);r.isDirectory()?zi(n,i):r.isFile()&&Qe(n,i)}}function Pc(e,t){if(e.generationId!==t.generationId||e.repositoryId!==t.repositoryId||e.treeOid!==t.treeOid||e.producerIdentity!==t.producerIdentity||JSON.stringify(e.fingerprint)!==JSON.stringify(t.fingerprint))throw new Error("shared generation manifest does not match the requested snapshot")}function Ji(e,t,r,n=!0,i=!0){try{let o=Tc(e);if(o?.status!=="complete"||JSON.stringify(o.fingerprint)!==JSON.stringify(r)||JSON.stringify([...o.indexedLanguages??[]].sort())!==JSON.stringify([...r.languages].sort()))return Xe("source validation rejected metadata"),!1;let s=Ct(e),a=Pr(f(e,"index.db"),f(e,"meta.json"));if(n?a.state!=="current":a.state==="invalid"||a.state==="drifted")return Xe(`source validation rejected SQLite generation state ${a.state}`),!1;let c=new Sc(f(e,"index.db"),{readonly:!0,fileMustExist:!0});try{if(i){if(c.pragma("quick_check(1)",{simple:!0})!=="ok")return!1}else c.pragma("schema_version",{simple:!0})}finally{c.close()}let l=$r(t),u=(i?s.files.filter(d=>d.endsWith(".scip")):["index.scip"]).every(d=>{let m=Ui(G(V(e,d))).metadata?.projectRoot;return m!==l&&Xe(`source validation rejected SCIP root for ${d}: ${String(m)}`),m===l});return u||Xe("source validation rejected SCIP project roots"),u}catch(o){return Xe(`source validation failed: ${o instanceof Error?o.message:String(o)}`),!1}}function Xe(e){process.env.SCIP_QUERY_DEBUG&&console.error(`shared-cache: ${e}`)}function $r(e){try{return Oi(gc(e)).href}catch{return Oi(Ke(e)).href}}function Ze(e){return Mi("sha256").update(e).digest("hex")}import{readFileSync as Xi}from"fs";import{createRequire as Dc}from"module";import{dirname as Br,isAbsolute as _c,relative as Zi,resolve as te,sep as Gr}from"path";var ee=Dc(import.meta.url),Ac=1,Yi="0.4.0";function Fc(){try{let e=eo();if(!e.available)return e;let{packageRoot:t}=e,r=ee.resolve("typescript",{paths:[t]}),n=ee(r),{FileIndexer:i}=ee(te(t,"dist/src/FileIndexer.js")),{Input:o}=ee(te(t,"dist/src/Input.js")),{Packages:s}=ee(te(t,"dist/src/Packages.js")),a=ee(te(t,"dist/src/scip.js"));if(!i||!o||!s||!a.scip?.Document||!a.scip.Index)return{available:!1,reason:"scip-typescript document runtime has an unsupported module shape"};let c={packageVersion:e.packageVersion,typescript:n,Document:a.scip.Document,Index:a.scip.Index,FileIndexer:i,Input:o,Packages:s};return{available:!0,runtime:c,producerIdentity:Ur(c)}}catch(e){return{available:!1,reason:`scip-typescript document runtime unavailable: ${e instanceof Error?e.message:String(e)}`}}}function Cm(){let e=eo();return e.available?{available:!0,packageVersion:e.packageVersion,typescriptVersion:e.typescriptVersion,producerIdentity:e.producerIdentity}:e}function eo(){try{let e=ee.resolve("@sourcegraph/scip-typescript/package.json"),t=JSON.parse(Xi(e,"utf8"));if(t.version!==Yi)return{available:!1,reason:`unsupported scip-typescript version ${String(t.version??"unknown")}; expected ${Yi}`};let r=Br(e),n=ee.resolve("typescript/package.json",{paths:[r]}),i=JSON.parse(Xi(n,"utf8"));return typeof i.version!="string"||!i.version?{available:!1,reason:"scip-typescript TypeScript compiler version is unavailable"}:{available:!0,packageRoot:r,packageVersion:t.version,typescriptVersion:i.version,producerIdentity:to(t.version,i.version)}}catch(e){return{available:!1,reason:`scip-typescript document producer unavailable: ${e instanceof Error?e.message:String(e)}`}}}function Rm(e){let t=e.runtime===void 0?Fc():e.runtime===null?{available:!1,reason:"scip-typescript document runtime unavailable"}:{available:!0,runtime:e.runtime,producerIdentity:Ur(e.runtime)};return t.available?{available:!0,emitter:new Wr(e,t.runtime)}:t}var Wr=class{producerIdentity;workspaceRoot;tsconfigPath;projectRoot;maxFileByteSize;runtime;host;config=null;includedFiles=new Set;program=null;checker=null;symbolTable=new Map;constructorTable=new Map;packages;fragments=new Map;stats={initializations:0,programUpdates:0,documentsEmitted:0,documentsRemoved:0,sourceNodesReused:0,sourceNodesReplaced:0,symbolEntriesPruned:0};constructor(t,r){this.workspaceRoot=te(t.workspaceRoot),this.tsconfigPath=te(this.workspaceRoot,t.tsconfigPath),this.projectRoot=t.projectRoot??Lc(this.workspaceRoot,Br(this.tsconfigPath)),this.maxFileByteSize=t.maxFileByteSize??1024*1024,this.runtime=r,this.producerIdentity=Ur(r);let n=Ki(r.typescript,this.tsconfigPath);this.config=n,this.host=new Vr(r.typescript,n.options,this.workspaceRoot),this.packages=new r.Packages(this.projectRoot)}initialize(){let t=performance.now(),r=this.config??Ki(this.runtime.typescript,this.tsconfigPath);this.includedFiles=new Set(r.fileNames.map(De)),this.program=this.runtime.typescript.createProgram(r.fileNames,r.options,this.host.compilerHost),this.checker=this.program.getTypeChecker(),this.stats.initializations+=1;let n=[];for(let i of this.program.getSourceFiles())this.includedFiles.has(De(i.fileName))&&n.push(this.emitSourceFile(i));return this.result(n,t)}advance(t){if(!this.program||!this.checker||!this.config)return this.initializeAndAdvance(t);let r=performance.now(),n=Nt(t.modifiedFiles),i=Nt(t.affectedFiles);this.validateIncrementalPaths(n,i);let o=this.program,s=new Map;for(let c of n){let l=et(this.workspaceRoot,c),p=o.getSourceFile(l);if(!p)throw new Error(`modified TypeScript source is unavailable: ${c}`);s.set(c,p),this.stats.symbolEntriesPruned+=Qi(this.symbolTable,p),this.stats.symbolEntriesPruned+=Qi(this.constructorTable,p),this.host.invalidate(l)}this.program=this.runtime.typescript.createProgram(this.config.fileNames,this.config.options,this.host.compilerHost,o),this.checker=this.program.getTypeChecker(),this.stats.programUpdates+=1;for(let[c,l]of s)this.program.getSourceFile(et(this.workspaceRoot,c))===l?this.stats.sourceNodesReused+=1:this.stats.sourceNodesReplaced+=1;let a=i.map(c=>{let l=et(this.workspaceRoot,c),p=this.program.getSourceFile(l);if(!p)throw new Error(`affected TypeScript source is unavailable: ${c}`);return this.emitSourceFile(p)});return this.result(a,r)}fragment(t){return this.fragments.get(Pt(t))??null}snapshotStats(){return{...this.stats}}initializeAndAdvance(t){let r=this.initialize(),n=Nt(t.modifiedFiles),i=Nt(t.affectedFiles);this.validateIncrementalPaths(n,i);let o=new Set(i);return{...r,fragments:r.fragments.filter(s=>o.has(s.relativePath))}}validateIncrementalPaths(t,r){if(t.length===0)throw new Error("incremental TypeScript document update requires a modified file");if(r.length===0)throw new Error("incremental TypeScript document update requires an affected file");for(let n of t){let i=et(this.workspaceRoot,n);if(!this.includedFiles.has(De(i)))throw new Error(`modified TypeScript file is outside the configured project: ${n}`)}for(let n of r){let i=et(this.workspaceRoot,n);if(!this.includedFiles.has(De(i)))throw new Error(`affected TypeScript file is outside the configured project: ${n}`)}}emitSourceFile(t){if(!this.checker)throw new Error("TypeScript document emitter is not initialized");let r=Pt(Zi(this.workspaceRoot,t.fileName)),n=new this.runtime.Document({relative_path:r,occurrences:[]});if(new this.runtime.FileIndexer(this.checker,{cwd:this.workspaceRoot,projectRoot:this.projectRoot,projectDisplayName:this.projectRoot,maxFileByteSizeNumber:this.maxFileByteSize},new this.runtime.Input(t.fileName,t.getText()),n,this.symbolTable,this.constructorTable,this.packages,t).index(),this.stats.documentsEmitted+=1,n.occurrences.length===0)return this.fragments.delete(r),this.stats.documentsRemoved+=1,{relativePath:r,bytes:null,occurrences:0,symbols:n.symbols.length,referenceFragments:[]};let o=n.serializeBinary();return this.fragments.set(r,o),{relativePath:r,bytes:o,occurrences:n.occurrences.length,symbols:n.symbols.length,referenceFragments:Oc(r,n)}}result(t,r){return{producerIdentity:this.producerIdentity,fragments:t,durationMs:performance.now()-r,stats:this.snapshotStats()}}};function Oc(e,t){let r=new Map;for(let n of t.occurrences){if(!n.symbol||(n.symbol_roles&1)!==0||n.range.length<3)continue;let i=n.range[0],o=n.range[1];if(!Number.isInteger(i)||!Number.isInteger(o))continue;let s={targetSymbol:n.symbol,location:{file:e,line:i,column:o}};r.set(`${n.symbol}\0${i}\0${o}`,s)}return[...r.values()].sort((n,i)=>n.targetSymbol.localeCompare(i.targetSymbol)||n.location.line-i.location.line||n.location.column-i.location.column)}var Vr=class{compilerHost;sourceFiles=new Map;constructor(t,r,n){let i=t.createCompilerHost(r),o=i.getSourceFile.bind(i);this.compilerHost={...i,getCurrentDirectory:()=>n,getSourceFile:(s,a,c,l)=>{let p=De(s);if(this.sourceFiles.has(p))return this.sourceFiles.get(p);let u=o(s,a,c,l);return this.sourceFiles.set(p,u),u}}}invalidate(t){this.sourceFiles.delete(De(t))}};function Ki(e,t){let r=e.readConfigFile(t,e.sys.readFile);if(r.error)throw new Error(e.formatDiagnostics([r.error],e.createCompilerHost({})));let n=e.parseJsonConfigFileContent(r.config,e.sys,Br(t)),i=n.errors.filter(o=>o.code!==18003);if(i.length>0)throw new Error(e.formatDiagnostics(i,e.createCompilerHost({})));return n}function Ur(e){return to(e.packageVersion,e.typescript.version)}function to(e,t){return`scip-typescript:${e}:typescript:${t}:document-adapter:${Ac}`}function Lc(e,t){return Pt(Zi(e,t))||"."}function et(e,t){if(_c(t))throw new Error(`expected a project-relative path: ${t}`);let r=te(e,t),n=e.endsWith(Gr)?e:`${e}${Gr}`;if(r!==e&&!r.startsWith(n))throw new Error(`path escapes the project root: ${t}`);return r}function Nt(e){return[...new Set(e.map(Pt))].sort()}function Pt(e){return e.split(Gr).join("/").replace(/^\.\//,"")}function De(e){return te(e)}function Qi(e,t){let r=0;for(let n of e.keys())if(jc(n)){try{if(n.getSourceFile()!==t)continue}catch{continue}e.delete(n),r+=1}return r}function jc(e){return!!(e&&typeof e=="object"&&"kind"in e&&"getSourceFile"in e)}var Mc=[v("source-facts",{dependsOn:["content-hash","tool-version"],keyParts:["kind","relativePath","contentHash","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/source/source-facts.ts"}),v("file-definitions",{dependsOn:["content-hash","project-fingerprint","indexed-language-set","tool-version"],keyParts:["kind","relativePath","contentHash","projectFingerprint","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/symbols/definition-catalog.ts"}),v("definition-exclusions",{dependsOn:["content-hash","tool-version"],keyParts:["kind","relativePath","contentHash","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/analysis/framework-patterns.ts"}),v("doc-path-tokens",{dependsOn:["content-hash","tool-version"],keyParts:["kind","relativePath","contentHash","payloadVersion"],stalenessTest:"tests/storage/evidence-products.test.ts",owner:"tests/storage/evidence-cache.test.ts"}),v("doc-path-evidence",{dependsOn:["content-hash","git-history","git-head","tool-version"],keyParts:["kind","relativePath","contentHash","trackedFiles","historyWindow","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/queries/cleanup/doc-drift.ts"}),v("source-imports",{dependsOn:["content-hash","import-resolution-fingerprint","config","tool-version"],keyParts:["kind","relativePath","contentHash","importResolutionFingerprint","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/language-parsers/index.ts"}),v("source-reexports",{dependsOn:["content-hash","import-resolution-fingerprint","config","tool-version"],keyParts:["kind","relativePath","contentHash","importResolutionFingerprint","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/language-parsers/index.ts"}),v("source-fingerprints",{dependsOn:["content-hash","project-fingerprint","indexed-language-set","tool-version"],keyParts:["kind","relativePath","contentHash","projectFingerprint","payloadVersion"],stalenessTest:"tests/symbols/definition-catalog.test.ts",owner:"src/queries/cleanup/similar.ts"}),v("consumer-file-usage",{dependsOn:["content-hash","project-fingerprint","indexed-language-set","tool-version"],keyParts:["kind","relativePath","contentHash","projectFingerprint","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/queries/internal/consumer-evidence.ts"}),v("react-component-behavior-profiles",{dependsOn:["content-hash","tool-version"],keyParts:["kind","relativePath","contentHash","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/source/react-profile.ts"}),v("git-file-adds",{dependsOn:["git-head","git-history","tool-version"],keyParts:["kind","cacheKey","head","historyWindow","payloadVersion"],stalenessTest:"tests/storage/evidence-cache.test.ts",owner:"src/analysis/git-history.ts"}),v("typescript-reference-fragments",{dependsOn:["content-hash","transitive-deps-digest","config","tool-version"],keyParts:["kind","relativePath","semanticIdentity","payloadVersion"],stalenessTest:"tests/semantic/typescript/typescript-reference-fragments.test.ts",owner:"src/semantic/typescript/reference-fragment-shadow.ts"}),v("typescript-import-usage",{dependsOn:["content-hash","transitive-deps-digest","config","tool-version"],keyParts:["kind","relativePath","semanticIdentity","payloadVersion"],stalenessTest:"tests/semantic/typescript/typescript-semantic-provider.test.ts",owner:"src/semantic/shared-primitives.ts"}),v("typescript-signatures",{dependsOn:["content-hash","transitive-deps-digest","config","tool-version"],keyParts:["kind","relativePath","semanticIdentity","payloadVersion"],stalenessTest:"tests/semantic/typescript/typescript-semantic-provider.test.ts",owner:"src/semantic/shared-primitives.ts"}),Dt("file-dependency-graph",{dependsOn:["project-fingerprint","indexed-language-set","import-resolution-fingerprint","tool-version"],keyParts:["kind","scope","projectFingerprint","payloadVersion"],stalenessTest:"tests/symbols/file-dep-graph.test.ts",owner:"src/symbols/graph/file-dep-graph.ts"}),Dt("semantic-import-usage",{dependsOn:["project-fingerprint","indexed-language-set","import-resolution-fingerprint","tool-version"],keyParts:["kind","relativePath","projectFingerprint","language","semanticEngine","payloadVersion"],stalenessTest:"tests/semantic/rust/rust-semantic-cache-gate.test.ts",owner:"src/semantic/shared-primitives.ts"}),Dt("semantic-signatures",{dependsOn:["project-fingerprint","indexed-language-set","tool-version"],keyParts:["kind","relativePath","symbol","projectFingerprint","language","semanticEngine","payloadVersion"],stalenessTest:"tests/semantic/rust/rust-semantic-cache-gate.test.ts",owner:"src/semantic/shared-primitives.ts"}),Dt("health-semantic-prewarm",{dependsOn:["project-fingerprint","indexed-language-set","tool-version"],keyParts:["kind","scope","cliVersion","projectFingerprint","payloadVersion"],stalenessTest:"tests/runtime/cli-support.test.ts",owner:"src/runtime/cli-support.ts"})];function tt(e){let t=new Map;return{kind:e.kind,read(r,n,i){let o=!1,s=0,a;if(Zt()){let c=Bn(r);if(c){let l=`${c}\0${n}\0${i}`;a=t.get(l),a||(a=er(["evidence-product-file-read-v1",e.kind,c,n,i]),t.set(l,a))}}return tr("evidence-product.file.read",()=>{let c=Un(r,e.kind,n,i);if(c===null)return null;s=c.length;try{let l=e.deserialize(c);return o=l!==null,l}catch{return null}},()=>({...a?{workIdentity:a,workOutcome:"computed"}:{},scope:"file",kind:e.kind,available:!0,hit:o,payloadBytes:s}))},write(r,n,i,o){Hn(r,e.kind,n,i,e.serialize(o))},writeBatch(r,n){qn(r,n.map(i=>({kind:e.kind,relativePath:i.relativePath,contentHash:i.contentHash,payload:e.serialize(i.value)})))}}}function Fm(e){let t=new Map;return{kind:e.kind,read(r,n,i){let o=!1,s=0,a;if(Zt()){let c=`${i}\0${n}`;a=t.get(c),a||(a=er(["evidence-product-project-read-v1",e.kind,i,n]),t.set(c,a))}return tr("evidence-product.project.read",()=>{let c=zn(r,e.kind,n,i);if(c===null)return null;s=c.length;try{let l=e.deserialize(c);return o=l!==null,l}catch{return null}},()=>({...a?{workIdentity:a,workOutcome:"computed"}:{},scope:"project",kind:e.kind,available:!0,hit:o,payloadBytes:s}))},write(r,n,i,o){Jn(r,e.kind,n,i,e.serialize(o))}}}function rt(e){let t=Mc.find(r=>r.kind===e);if(!t)throw new Error(`missing evidence product manifest entry for ${e}`);return t.invalidation}function v(e,t){return{scope:"file",kind:e,invalidation:{scope:"file",...t}}}function Dt(e,t){return{scope:"project",kind:e,invalidation:{scope:"project",...t}}}import{isAbsolute as $c,relative as Gc}from"path";function T(e){return e.replace(/\\/g,"/")}function jm(e,t){let r=Gc(e,t);return r===""||!r.startsWith("..")&&!$c(r)}var Wc=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs"];function $m(e){let t=e.toLowerCase();return Wc.some(r=>t.endsWith(r))}import{createRequire as Vc}from"module";var ro=Vc(import.meta.url),nt,_t;function Bc(){if(nt!==void 0)return nt;try{nt=ro("ts-morph")}catch{nt=null}return nt}function Vm(){if(_t)return _t;let e=Bc();if(!e)return"ts-morph:unavailable";let t="unknown";try{t=ro("ts-morph/package.json").version??"unknown"}catch{}return _t=`ts-morph:${t}:typescript:${e.ts.version}`,_t}function Bm(e,t){return t.map(r=>({tsconfigPath:r,project:new e.Project({tsConfigFilePath:r,skipFileDependencyResolution:!0})}))}function Um(e,t,r){return{language:"typescript",availability:()=>({available:!1,reason:e,tsconfigPath:t,tsconfigPaths:r}),importUsage:()=>[],referencesFor:()=>[],calleesFor:()=>[],signatureFor:()=>null}}function qm(e,t,r){let n=new Set(r),i=new Map(r.map(o=>[o,[]]));for(let o of e)for(let s of t.get(o.symbolId)??[])n.has(s.file)&&i.get(s.file).push({targetSymbol:o.symbol,location:s});for(let[o,s]of i)i.set(o,Uc(s));return i}function Uc(e){let t=new Map;for(let r of e){let{location:n}=r;t.set(`${r.targetSymbol}\0${n.file}\0${n.line}\0${n.column}`,r)}return[...t.values()].sort((r,n)=>r.targetSymbol.localeCompare(n.targetSymbol)||Hc(r.location,n.location))}function Hc(e,t){return e.file.localeCompare(t.file)||e.line-t.line||e.column-t.column}import{existsSync as qr,readFileSync as zr,readdirSync as qc,statSync as zc}from"fs";import{join as _e,relative as Jc}from"path";function no(e){let t=Xc(e)??Zc(e);if(!t||t.length===0)return[];let r=[],n=new Set;for(let i of t)for(let o of el(e,i)){if(n.has(o))continue;n.add(o);let s=tl(e,o);s&&r.push(s)}return r}function Xc(e){let t=_e(e,"pnpm-workspace.yaml");if(!qr(t))return null;try{return Yc(zr(t,"utf8"))}catch{return null}}function Yc(e){let t=[],r=!1;for(let n of e.split(/\r?\n/)){let i=Kc(n);if(!r){/^packages\s*:\s*$/.test(i.trim())&&(r=!0);continue}let o=/^\s+-\s*(.+)$/.exec(i);if(o){let s=Qc(o[1].trim());s&&t.push(s);continue}if(i.trim()!=="")break}return t}function Kc(e){let t=e.indexOf("#");return t===-1?e:e.slice(0,t)}function Qc(e){return e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function Zc(e){let t=_e(e,"package.json");if(!qr(t))return null;try{let r=JSON.parse(zr(t,"utf8"));return r.workspaces?Array.isArray(r.workspaces)?r.workspaces:r.workspaces.packages??[]:null}catch{return null}}function el(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let s=_e(e,t);return Hr(s)?[s]:[]}let r=t.indexOf("*"),n=t.slice(0,r).replace(/\/$/,""),i=t.slice(r+1).replace(/^\//,""),o=_e(e,n||".");return Hr(o)?qc(o).map(s=>_e(o,s,i)).filter(Hr):[]}function Hr(e){try{return zc(e).isDirectory()}catch{return!1}}function tl(e,t){let r=_e(t,"package.json");if(!qr(r))return null;try{let n=JSON.parse(zr(r,"utf8"));return typeof n.name!="string"||n.name.length===0?null:{name:n.name,relativeDir:Jc(e,t).replace(/\\/g,"/"),exports:n.exports}}catch{return null}}import{createRequire as rl}from"module";import{existsSync as ge}from"fs";import{basename as io,dirname as C,extname as H,join as _,relative as fe,resolve as b,sep as nl}from"path";var il=pt("indexed-paths",{clearGroups:[]}),ol=pt("indexed-path-digest",{clearGroups:[]}),sl=x("tsconfig-alias-config",{clearGroups:["whole-project"]}),al=x("tsconfig-alias-config-for-dir",{clearGroups:["whole-project"]}),cl=rl(import.meta.url),it;function ll(){if(it!==void 0)return it;try{it=cl("typescript")}catch{it=null}return it}var pl=["tsconfig.json","tsconfig.app.json","tsconfig.node.json","tsconfig.base.json"],ul=pt("workspace-packages",{clearGroups:["whole-project"]}),me=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],At=[".py",".pyi"],R=[".java",".scala",".kt",".kts"],Ft=[".rs"],Ot=[".rb"],Lt=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],re=[".cs",".vb"],jt=[".dart"],ye=[".php"],Ae=[".clj",".cljs",".cljc"],dl=new Set(me),Jr=new Set(At),oo=new Set(R),Xr=new Set(Ft),Yr=new Set(Ot),so=new Set(Lt),ao=new Set(re),Kr=new Set(jt),co=new Set(ye),lo=new Set(Ae),fl=[{extensions:me,lookup:dl},{extensions:At,lookup:Jr},{extensions:R,lookup:oo},{extensions:Ft,lookup:Xr},{extensions:Ot,lookup:Yr},{extensions:Lt,lookup:so},{extensions:re,lookup:ao},{extensions:jt,lookup:Kr},{extensions:ye,lookup:co},{extensions:Ae,lookup:lo}];function q(e,t){return t.has(H(e).toLowerCase())}function ml(e){return q(e,Jr)}function gl(e){return q(e,oo)}function yl(e){return q(e,Xr)}function hl(e){return q(e,Yr)}function Sl(e){return q(e,so)}function bl(e){return q(e,ao)}function po(e){return H(e).toLowerCase()===".vb"}function xl(e){return q(e,Kr)}function Il(e){return q(e,co)}function El(e){return q(e,lo)}function Qr(e){let t=H(e).toLowerCase();for(let r of fl)if(r.lookup.has(t))return r.extensions;return me}function vl(e){return gl(e)||bl(e)||Il(e)}function ne(e,t,r){return ml(t)?Fe(e,t,r):yl(t)?z(e,t,r):hl(t)?Mt(e,t,r):Sl(t)?$t(e,t,r):vl(t)?h(e,r.replace(/\\/g,"."),Qr(t)):xl(t)?Gt(e,t,r):El(t)?Zr(e,r):Tl(e,t,r)}function Tl(e,t,r){if(!r.startsWith(".")&&!r.startsWith("/"))return wl(e,t,r)??Cl(e,r);let n=C(_(e.config.projectRoot,t)),i=b(n,r),o=J(e);for(let s of tn(i)){let a=T(fe(e.config.projectRoot,s));if(o.has(a)||ge(s))return a}return T(fe(e.config.projectRoot,i))}function wl(e,t,r){let n=Al(e,t);if(!n)return null;let i=J(e);for(let o of kl(n,r)){let s=b(n.baseUrl,o);for(let a of tn(s)){let c=T(fe(e.config.projectRoot,a));if(i.has(c)||ge(a))return c}}return null}function kl(e,t){let r=[];for(let[n,i]of Object.entries(e.paths)){let o=n.indexOf("*");if(o===-1){if(t!==n)continue;r.push(...i);continue}let s=n.slice(0,o),a=n.slice(o+1);if(!t.startsWith(s)||!t.endsWith(a)||t.length<s.length+a.length)continue;let c=t.slice(s.length,t.length-a.length);for(let l of i)r.push(l.includes("*")?l.replace("*",c):l)}return r}function Cl(e,t){let r=Nl(Rl(e),t);if(!r)return null;let n=J(e);for(let i of Pl(r)){let o=b(e.config.projectRoot,r.pkg.relativeDir,i);for(let s of tn(o)){let a=T(fe(e.config.projectRoot,s));if(n.has(a)||ge(s))return a}}return null}function Rl(e){return ul.get(e,()=>no(e.config.projectRoot))}function Nl(e,t){let r=null;for(let n of e){let i=null;t===n.name?i="":t.startsWith(`${n.name}/`)&&(i=t.slice(n.name.length+1)),i!==null&&(!r||n.name.length>r.pkg.name.length)&&(r={pkg:n,subpath:i})}return r}function Pl(e){let t=[],r=Dl(e.pkg.exports,e.subpath);if(r){let n=_l(r);n&&t.push(n)}return t.push(e.subpath?`src/${e.subpath}`:"src/index"),t}function Dl(e,t){if(!e||typeof e!="object")return null;let r=t===""?".":`./${t}`;return uo(e[r])}function uo(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return null;let t=e;for(let r of["types","import","default","require","node"]){let n=uo(t[r]);if(n)return n}return null}function _l(e){let t=e.replace(/^\.\//,"");return t.startsWith("dist/")?`src/${t.slice(5)}`:null}function Al(e,t){let r=T(C(t));return al.get(e,r,()=>Fl(e,r))}function Fl(e,t){let r=ll();if(!r)return null;let n=b(e.config.projectRoot),i=b(n,t);for(;i===n||i.startsWith(n+nl);){for(let s of pl){let a=_(i,s);if(!ge(a))continue;let c=sl.get(e,a,()=>Ol(r,a));if(c)return c}let o=C(i);if(o===i)break;i=o}return null}function Ol(e,t){try{let r=e.readConfigFile(t,e.sys.readFile);if(r.error||!r.config)return null;let n=e.parseJsonConfigFileContent(r.config,e.sys,C(t)),i=n.options.paths;return!i||Object.keys(i).length===0?null:{baseUrl:n.options.baseUrl?b(C(t),n.options.baseUrl):C(t),paths:i}}catch{return null}}function Fe(e,t,r){let n=J(e),i;if(r.startsWith(".")){let o=r.match(/^(\.+)(.*)$/);if(!o)return null;let s=o[1].length,a=o[2].replace(/^\./,""),c=C(_(e.config.projectRoot,t));for(let l=1;l<s;l++)c=C(c);i=a?b(c,a.replace(/\./g,"/")):c}else i=b(e.config.projectRoot,r.replace(/\./g,"/"));for(let o of Ll(i)){let s=T(fe(e.config.projectRoot,o));if(n.has(s)||ge(o))return s}return null}function z(e,t,r){if(!r)return null;let n=r.replace(/\s+as\s+.+$/,"").trim();if(!n.startsWith("crate::")&&!n.startsWith("self::")&&!n.startsWith("super::"))return null;let i=C(_(e.config.projectRoot,t)),o;return n.startsWith("crate::")?o=b(e.config.projectRoot,"src",n.slice(7).replace(/::/g,"/")):n.startsWith("self::")?o=b(i,n.slice(6).replace(/::/g,"/")):o=b(C(i),n.slice(7).replace(/::/g,"/")),en(e,jl(o))}function Mt(e,t,r){let n=C(_(e.config.projectRoot,t)),i=b(n,r);return en(e,Ml(i))}function $t(e,t,r){let n=C(_(e.config.projectRoot,t)),i=[b(n,r),b(e.config.projectRoot,r),b(e.config.projectRoot,"include",r),b(e.config.projectRoot,"src",r)];return en(e,i)}function h(e,t,r){let n=J(e),i=t.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),o=i.replace(/\./g,"/"),s=i.split(".").pop()??i;for(let c of r){let l=`${o}${c}`,p=[...n].find(u=>u.endsWith(l));if(p)return p}for(let c of r){let l=[...n].find(p=>io(p)===`${s}${c}`);if(l)return l}let a=[...n].filter(c=>r.includes(H(c).toLowerCase())).filter(c=>c.includes(`/${o}/`)||c.includes(`/${s}/`)).sort((c,l)=>c.localeCompare(l));return a.length===1?a[0]:null}function Gt(e,t,r){let n=J(e);if(r.startsWith("package:")){let s=r.slice(8),a=s.indexOf("/");if(a<0)return null;let c=s.slice(a+1),l=T(c.startsWith("lib/")?c:`lib/${c}`);return n.has(l)?l:null}let i=C(_(e.config.projectRoot,t)),o=b(i,r);for(let s of $l(o)){let a=T(fe(e.config.projectRoot,s));if(n.has(a)||ge(s))return a}return null}function Zr(e,t){let r=t.replace(/-/g,"_").replace(/\./g,"/"),n=J(e);for(let i of Ae){let o=`${r}${i}`,s=[...n].find(a=>a.endsWith(o));if(s)return s}for(let i of Ae){let o=[...n].find(s=>io(s)===`${r.split("/").pop()}${i}`);if(o)return o}return null}function Ll(e){let t=H(e);return Jr.has(t)?[e]:[`${e}.py`,`${e}.pyi`,_(e,"__init__.py"),_(e,"__init__.pyi")]}function en(e,t){let r=J(e);for(let n of t){let i=T(fe(e.config.projectRoot,n));if(r.has(i)||ge(n))return i}return null}function jl(e){let t=H(e);return Xr.has(t)?[e]:[`${e}.rs`,_(e,"mod.rs")]}function Ml(e){let t=H(e);return Yr.has(t)?[e]:[`${e}.rb`,_(e,"index.rb")]}function $l(e){let t=H(e);return Kr.has(t)?[e]:[`${e}.dart`,e]}function tn(e){let t=H(e),r=new Set;if(t){r.add(e);for(let n of me)r.add(e.slice(0,-t.length)+n)}else for(let n of me)r.add(`${e}${n}`),r.add(_(e,`index${n}`));return[...r]}function J(e){return il.get(e,()=>new Set(Tn(e,{includeIgnored:!1}).map(T)))}function rn(e){return ol.get(e,()=>yt([...J(e)].sort().join(`
107
- `)))}import{readFileSync as Gl}from"fs";import{join as Wl}from"path";var Vl=x("source-text",{clearGroups:["whole-project","source-file"]}),Bl=x("source-lines",{clearGroups:["whole-project","source-file"]});function N(e,t){let r=t.replace(/\\/g,"/");return Vl.get(e,r,()=>{let n=Wl(e.config.projectRoot,r);try{return Gl(n,"utf-8")}catch(i){if(Ul(i))return"";throw i}})}function Ul(e){return typeof e=="object"&&e!==null&&"code"in e&&(e.code==="ENOENT"||e.code==="ENOTDIR")}function lg(e,t){let r=t.replace(/\\/g,"/");return Bl.get(e,r,()=>{let n=N(e,r);return n?n.split(`
108
- `):[]})}import{basename as Mo}from"path";function he(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Hl(e){return e.replace(/'''[\s\S]*?'''/g,ie).replace(/"""[\s\S]*?"""/g,ie).replace(/#.*$/gm,ie).replace(/\/\/.*$/gm,ie).replace(/\/\*[\s\S]*?\*\//g,ie).replace(/`(?:\\[\s\S]|[^`])*`/g,ie).replace(/'(?:\\.|[^'\\\r\n])*'/g,ie).replace(/"(?:\\.|[^"\\\r\n])*"/g,ie)}function ie(e){return e.replace(/[^\r\n]/g," ")}var gg=ke("stripped-lines",{clearGroups:["whole-project","source-file"]});En({name:"stripped-source-singleton",groups:["whole-project","source-file"],clearAll:()=>{Wt=null,ot=""},clearFile:()=>{Wt=null,ot=""}});var Wt=null,ot="";function ql(e){return Wt===e||(Wt=e,ot=Hl(e)),ot}function oe(e,t,r){let n=ql(e);return`${n.slice(0,t)}${" ".repeat(r-t)}${n.slice(r)}`}function w(e,t){return new RegExp(`\\b${he(t)}\\b`,"m").test(e)}function Oe(e,t){let r=new Set,n=new RegExp(`\\b${he(t)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let i of e.matchAll(n)){let o=i[1];o&&r.add(o)}return[...r]}function nn(e){let t=0;for(let r of e)r==="("&&(t+=1),r===")"&&(t-=1);return t}import{extname as fo}from"path";var zl={".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",".clj":"clojure",".cljs":"clojure",".cljc":"clojure"};function Se(e){return zl[fo(e).toLowerCase()]??null}function be(e){return fo(e).toLowerCase()===".vue"}import{createRequire as Jl}from"module";var I=Jl(import.meta.url),Vt=null,mo=!1;function Xl(){if(mo)return null;if(Vt)return Vt;try{return Vt=I("tree-sitter"),Vt}catch{return mo=!0,null}}var go=new Map,Bt=new Set;function Yl(e){if(Bt.has(e))return null;let t=go.get(e);if(t)return t;let r;try{switch(e){case"rust":r=I("tree-sitter-rust");break;case"typescript":r=I("tree-sitter-typescript").typescript;break;case"tsx":r=I("tree-sitter-typescript").tsx;break;case"javascript":r=I("tree-sitter-javascript");break;case"python":r=I("tree-sitter-python");break;case"java":r=I("tree-sitter-java");break;case"kotlin":r=I("tree-sitter-kotlin");break;case"scala":r=I("tree-sitter-scala");break;case"ruby":r=I("tree-sitter-ruby");break;case"c":r=I("tree-sitter-c");break;case"cpp":r=I("tree-sitter-cpp");break;case"csharp":r=I("tree-sitter-c-sharp");break;case"php":r=I("tree-sitter-php").php;break;case"vb":{let n=I("tree-sitter-vb-dotnet");r=n.language??n;break}case"clojure":return Bt.add(e),null}}catch{return Bt.add(e),null}return go.set(e,r),r}var yo=new Map;function Kl(e){let t=yo.get(e);if(t)return t;let r=Yl(e);if(!r)return null;let n=Xl();if(!n)return null;let i=new n;try{i.setLanguage(r)}catch{return Bt.add(e),null}return yo.set(e,i),i}function Ql(e,t){return e.parse(n=>n>=t.length?null:t.slice(n,Math.min(t.length,n+16384)))}function on(e,t){let r=Kl(e);if(!r)return null;try{return Ql(r,t)}catch{return null}}import{posix as sn}from"path";import{parse as Zl}from"@vue/compiler-sfc";var wg=vn("vue-sfc-units");function ep(e){return e.replace(/\\/g,"/").replace(/^\.\//,"")}function tp(e){let t=e?.toLowerCase();return!t||t==="js"||t==="javascript"||t==="jsx"?"javascript":t==="ts"||t==="typescript"?"typescript":t==="tsx"?"tsx":null}function bo(e,t,r){let n={relativePath:t,template:null,scripts:[],styles:[],customBlocks:[],errors:[]};if(!r)return n;let i;try{i=Zl(r,{filename:t})}catch(s){return n.errors.push(So(s)),n}n.errors.push(...i.errors.map(So));let{descriptor:o}=i;return o.template&&(n.template=Ut(e,t,"template",o.template)),o.script&&n.scripts.push(ho(e,t,o.script,!1)),o.scriptSetup&&n.scripts.push(ho(e,t,o.scriptSetup,!0)),n.styles=o.styles.map(s=>Ut(e,t,"style",s)),n.customBlocks=o.customBlocks.map(s=>Ut(e,t,"custom",s)),n.errors.push(...[n.template,...n.scripts,...n.styles,...n.customBlocks].flatMap(s=>s?.errors??[])),n}function ho(e,t,r,n){let i=Ut(e,t,"script",r);return{...i,kind:"script",setup:n,astLanguage:tp(i.lang)}}function Ut(e,t,r,n){let i=np(n.attrs),o=typeof i.lang=="string"?i.lang:null,s=typeof i.src=="string"?i.src:typeof n.src=="string"?n.src:void 0;if(s){let c=rp(t,s);if(!c)return{kind:r,ownerPath:t,sourcePath:t,external:!0,src:s,attrs:i,lang:o,body:"",startLine:0,endLine:0,errors:[`Could not resolve Vue ${r} block source: ${s}`]};let l=N(e,c),p=l?Math.max(0,l.split(`
109
- `).length-1):0;return{kind:r,ownerPath:t,sourcePath:c,external:!0,src:s,attrs:i,lang:o,body:l,startLine:0,endLine:p,errors:l?[]:[`Vue ${r} block source not found: ${c}`]}}let a=Math.max(0,n.loc.start.line-1);return{kind:r,ownerPath:t,sourcePath:t,external:!1,attrs:i,lang:o,body:n.content,startLine:a,endLine:Math.max(a,n.loc.end.line-1),errors:[]}}function rp(e,t){let r=t.split(/[?#]/,1)[0];if(!r||r.startsWith("/")||r.includes("://"))return null;let n=ep(sn.normalize(sn.join(sn.dirname(e),r)));return n===".."||n.startsWith("../")?null:n}function np(e){return{...e}}function So(e){return e instanceof Error?e.message:String(e)}function Ht(e,t,r){let i=bo(e,t,r).scripts.filter(s=>s.astLanguage&&s.body.length>0),o=i[0]?.astLanguage;return o?{body:i.map(s=>`${`
110
- `.repeat(s.startLine)}${s.body}`).join(`
111
- `),startLine:0,language:o}:null}var xo=ke("ast-trees",{clearGroups:["whole-project","source-file"]});function B(e,t){if(be(t))return ip(e,t);let r=Se(t);if(!r)return null;let n=N(e,t);return n?xo.get(e,t,n,()=>on(r,n)):null}function ip(e,t){let r=N(e,t);return r?xo.get(e,t,r,()=>{let n=Ht(e,t,r);if(!n)return null;let i=`
112
- `.repeat(n.startLine)+n.body;return on(n.language,i)}):null}function Io(e,t){let r=op(e,t);if(!r)return null;let n=xe(r);return n?{calleeLeaf:n,memberAccess:sp(r),line:e.startPosition.row}:null}function op(e,t){if(t==="rust")return e.type==="call_expression"?e.childForFieldName("function")??e.namedChild(0):e.type==="macro_invocation"?e.childForFieldName("macro")??e.namedChild(0):null;if(t==="python")return e.type!=="call"?null:e.childForFieldName("function")??e.namedChild(0);if(t==="typescript"||t==="tsx"||t==="javascript"){if(e.type==="call_expression")return e.childForFieldName("function")??e.namedChild(0);if(e.type==="new_expression")return e.childForFieldName("constructor")??e.namedChild(0)}return null}function sp(e){switch(e.type){case"field_expression":case"member_expression":case"attribute":return!0;default:return!1}}function xe(e){switch(e.type){case"identifier":case"type_identifier":case"field_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?xe(t):null}case"generic_function":{let t=e.childForFieldName("function")??e.namedChild(0);return t?xe(t):null}case"scoped_identifier":{let t=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return t?xe(t):null}case"super":case"self":case"this":return null;default:return null}}function st(e){return e.type==="comment"||e.type==="line_comment"||e.type==="block_comment"}var ap=new Set(["function_declaration","method_definition","method_signature","function_signature"]);function ko(e,t){let r=lp(e,t);if(r)return{name:r.name,startLine:r.definitionNode.startPosition.row,endLine:r.definitionNode.endPosition.row,paramCount:To(r.functionNode),params:Eo(r.functionNode),paramsEndLine:vo(r.functionNode),isLiteralPassthrough:wo(r.functionNode,t)};if(!cp(e.type,t))return null;let n=e.childForFieldName("name")??e.namedChildren.find(i=>i.type==="identifier"||i.type==="property_identifier");return n?{name:n.text,startLine:e.startPosition.row,endLine:e.endPosition.row,paramCount:To(e),params:Eo(e),paramsEndLine:vo(e),isLiteralPassthrough:wo(e,t)}:null}function Co(e){return e.namedChildren.find(t=>t.type==="parameters"||t.type==="formal_parameters")}function Eo(e){let t=Co(e);if(!t)return[];let r=[];for(let n of t.namedChildren){if(st(n))continue;if(n.type==="identifier"){r.push({name:n.text,simple:!0});continue}let i=n.namedChildren.some(a=>a.type.endsWith("_modifier"))||/^\s*(?:public|private|protected|readonly|override)\b/.test(n.text),o=n.childForFieldName("pattern");if(!i&&o&&o.type==="identifier"){r.push({name:o.text,simple:!0});continue}let s=n.namedChildren.find(a=>a.type==="identifier");r.push({name:o?.type==="identifier"?o.text:s?.text??"",simple:!1})}return r}function vo(e){let t=Co(e);return t?t.endPosition.row:e.startPosition.row}function cp(e,t){return t==="rust"?e==="function_item"||e==="function_signature_item":t==="python"?e==="function_definition":t==="typescript"||t==="tsx"||t==="javascript"?ap.has(e):!1}function lp(e,t){if(t!=="typescript"&&t!=="tsx"&&t!=="javascript")return null;if(e.type==="variable_declarator"){let r=e.childForFieldName("name")??e.namedChild(0),n=e.childForFieldName("value")??e.namedChild(1);return!r||!n||n.type!=="arrow_function"&&n.type!=="function_expression"?null:{name:r.text,definitionNode:e,functionNode:n}}if(e.type==="public_field_definition"){let r=e.childForFieldName("name")??e.namedChild(0),n=e.childForFieldName("value")??e.namedChild(1);return!r||!n||n.type!=="arrow_function"&&n.type!=="function_expression"?null:{name:r.text,definitionNode:e,functionNode:n}}return null}function To(e){let t=e.namedChildren.find(n=>n.type==="parameters"||n.type==="formal_parameters");if(!t)return 0;let r=0;for(let n of t.namedChildren)st(n)||(r+=1);return r}function wo(e,t){let r=e.namedChildren.find(u=>u.type==="block"||u.type==="statement_block");if(!r)return!1;let n=r.namedChildren.filter(u=>!st(u));if(n.length!==1)return!1;let i=n[0],o=null;if(i.type==="return_statement"||i.type==="expression_statement"?o=i.namedChild(0)??null:t==="rust"&&(i.type==="call_expression"||i.type==="macro_invocation")&&(o=i),!o)return!1;let s=t==="python"?"call":"call_expression";if(o.type!==s)return!1;let a=o.namedChildren.find(u=>u.type==="arguments"||u.type==="argument_list");if(!a)return!1;let c=a.namedChildren.filter(u=>!st(u)),l=e.namedChildren.find(u=>u.type==="parameters"||u.type==="formal_parameters");if(!l)return!1;let p=[];for(let u of l.namedChildren){if(u.type==="identifier"){p.push(u.text);continue}let d=u.namedChildren.find(m=>m.type==="identifier");d&&p.push(d.text)}if(c.length!==p.length)return!1;for(let u=0;u<p.length;u+=1){let d=c[u];if(d.type!=="identifier"||d.text!==p[u])return!1}return!0}var pp=new Set(["identifier","type_identifier","field_identifier"]),up=new Set(["identifier"]),dp=new Set(["identifier","property_identifier","type_identifier","shorthand_property_identifier","shorthand_property_identifier_pattern"]),fp=new Set(["rust","python"]),mp=/\{([^{}]*)\}/g,gp=/\b([A-Za-z_][\w]*)\b/g;function Ro(e,t){return yp(t).has(e.type)}function No(e,t){return fp.has(t)&&e.type==="string_content"}function an(e){let t=0;for(let n of e.values()){let i=n[n.length-1];i!==void 0&&i>t&&(t=i)}let r=new Array(t+1);for(let n=0;n<=t;n+=1)r[n]=new Set;for(let[n,i]of e)for(let o of i)r[o].add(n);return r}function yp(e){return e==="rust"?pp:e==="python"?up:dp}function Po(e,t){let r=e.startPosition.row;for(let n of e.text.matchAll(mp)){let i=n[1]??"";for(let o of i.matchAll(gp))o[1]&&t(o[1],r)}}var hp=[/\bdefault\s*=\s*"([^"]+)"/g,/\bwith\s*=\s*"([^"]+)"/g,/\bserialize_with\s*=\s*"([^"]+)"/g,/\bdeserialize_with\s*=\s*"([^"]+)"/g,/\bskip_serializing_if\s*=\s*"([^"]+)"/g,/\bgetter\s*=\s*"([^"]+)"/g,/\brename_all_with\s*=\s*"([^"]+)"/g,/\bschema_with\s*=\s*"([^"]+)"/g],Sp=/^#!?\[\s*serde\s*\(/,bp=/^#!?\[\s*schemars\s*\(/,xp=/^#!?\[\s*validate\s*\(/,Ip=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function Do(e,t,r){if(t!=="typescript"&&t!=="tsx"&&t!=="javascript"||e.type!=="call_expression")return;let n=e.childForFieldName("function")??e.namedChild(0);if(!n)return;let i=xe(n);if(!i||!Ip.has(i))return;let o=e.namedChildren.find(c=>c.type==="arguments");if(!o)return;let s=o.namedChild(0);if(!s||s.type!=="string")return;let a=s.namedChildren.find(c=>c.type==="string_fragment");a&&r.add(a.text)}function _o(e,t){let r=Sp.test(e),n=bp.test(e),i=xp.test(e);if(!(!r&&!n&&!i))for(let o of hp){o.lastIndex=0;let s;for(;(s=o.exec(e))!==null;){let a=s[1],c=a.split("::").pop()??a;c==="is_none"&&/\bOption\b/.test(a)||c==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(a)||c&&t.add(c)}}}function Ao(e,t){let r=new Map,n=(s,a)=>{if(s===a)return;let c=r.get(s);c||(c=new Set,r.set(s,c)),c.add(a)},i=t==="python"?new Set(["identifier"]):new Set(["type_identifier"]),o=(s,a)=>{let c=l=>{i.has(l.type)&&l.text!==a&&n(l.text,a);for(let p of l.children)c(p)};for(let l of s.children)c(l)};if(t==="rust")for(let s of e.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let a=s.namedChildren.find(l=>l.type==="type_identifier")?.text;if(!a)continue;let c=s.namedChildren.find(l=>l.type==="field_declaration_list"||l.type==="enum_variant_list"||l.type==="ordered_field_declaration_list");c&&o(c,a),s.type==="type_item"&&o(s,a)}else if(t==="python")for(let s of e.rootNode.descendantsOfType("class_definition")){let a=s.namedChildren.find(p=>p.type==="identifier")?.text;if(!a)continue;let c=s.childForFieldName("superclasses");c&&o(c,a);let l=s.namedChildren.find(p=>p.type==="block");if(l)for(let p of l.descendantsOfType("type"))for(let u of p.descendantsOfType("identifier"))u.text!==a&&n(u.text,a)}else for(let s of e.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let a=s.namedChildren.find(c=>c.type==="type_identifier")?.text;a&&o(s,a)}return r}var Ep=new Map([["defn","function"],["defn-","function"],["defmacro","macro"],["defmacro-","macro"],["defmethod","method"]]),cn=new Set(["catch","comment","def","defprotocol","defrecord","deftype","defmethod","defmacro","defmacro-","defn","defn-","do","doseq","dotimes","fn","for","if","let","loop","ns","quote","recur","throw","try","extend-protocol","extend-type","when","when-let","when-not"]);function Fo(e){let t=[],r=[],n=[],i=new Map,o=[],s=0,a=0,c=(l,p)=>{let u=i.get(l);if(!u){i.set(l,[p]);return}u[u.length-1]!==p&&u.push(p)};for(;a<e.length;){let l=e[a];if(l===`
113
- `){s+=1,a+=1;continue}if(/\s|,/.test(l)){a+=1;continue}if(l===";"){a=zt(e,a);continue}if(l==='"'){let y=ct(e,a,s);s=y.line,a=y.index;continue}if(l==="("||l==="["||l==="{"){o.push({kind:l,startLine:s,endLine:s,headTokens:[],tokens:[],children:[]}),a+=1;continue}if(l===")"||l==="]"||l==="}"){let y=o.pop();y&&(y.endLine=s,vp(y,{callables:t,callSites:r,clojureMembers:n,recordIdentifier:c}),o[o.length-1]?.children.push(y)),a+=1;continue}if(ln(l)){a+=1;continue}let p=s,u=a;for(;a<e.length&&!pn(e[a]);)a+=1;let d=e.slice(u,a);if(!d)continue;let m={text:d,line:p};Tp(o[o.length-1],m),c(A(d),p)}return{language:"clojure",callables:t,callSites:r,clojureMembers:n,typeContainerMap:new Map,identifierLineMap:i,identifiersByLine:Np(i),fileIdentifiers:new Set(i.keys()),rustAttrReferencedNames:new Set,crossLanguageDispatchNames:new Set}}function vp(e,t){if(e.kind!=="("||e.headTokens.length===0)return;let r=e.headTokens[0],n=A(r.text),i=Ep.get(r.text);if(i){let s=e.headTokens[1];if(s){let a=A(s.text);t.recordIdentifier(a,s.line),t.callables.push({name:a,startLine:e.startLine,endLine:e.endLine,paramCount:0,params:[],paramsEndLine:s.line,isLiteralPassthrough:!1,clojureKind:i})}}if(wp(e,t),!n||cn.has(r.text)||cn.has(n)||n.startsWith(":"))return;let o=Rp(r.text);t.callSites.push({calleeLeaf:o.leaf,calleeQualifier:o.qualifier,calleeText:o.text,memberAccess:!1,line:r.line})}function Tp(e,t){e&&(e.headTokens.length<2&&e.headTokens.push(t),e.tokens.length<200&&e.tokens.push(t))}function wp(e,t){let r=A(e.tokens[0]?.text??"");if(r==="defprotocol"){let n=A(e.tokens[1]?.text??"");if(!n)return;for(let i of qt(e))at(t,n,"protocol",i,"protocol-method");return}if(r==="defrecord"||r==="deftype"){let n=A(e.tokens[1]?.text??"");if(!n)return;let i=r==="defrecord"?"record":"type",o=r==="defrecord"?"record-method":"type-method";for(let s of qt(e))at(t,n,i,s,o);return}if(r==="extend-type"){let n=A(e.tokens[1]?.text??"");if(!n)return;for(let i of qt(e))at(t,n,"extension",i,"extension-method");return}if(r==="extend-protocol"){let n=A(e.tokens[1]?.text??"");for(let i of qt(e)){n&&at(t,n,"extension",i,"extension-method");let o=Cp(e,i.startLine);o&&o!==n&&at(t,o,"extension",i,"extension-method")}}}function qt(e){return e.children.filter(kp)}function kp(e){if(e.kind!=="(")return!1;let t=A(e.tokens[0]?.text??"");return!!(t&&!cn.has(t)&&!t.startsWith(":"))}function at(e,t,r,n,i){let o=n.tokens[0],s=A(o?.text??"");!o||!s||(e.recordIdentifier(s,o.line),e.clojureMembers.push({ownerName:t,ownerKind:r,memberName:s,memberKind:i,startLine:n.startLine,endLine:n.endLine}))}function Cp(e,t){let r=null;for(let n=2;n<e.tokens.length;n+=1){let i=e.tokens[n];if(i.line>t)break;let o=A(i.text);o&&!o.startsWith(":")&&(r=o)}return r}function A(e){return e.replace(/^#?['`~@]+/,"").split("/").pop()?.replace(/^\./,"")??""}function Rp(e){let t=e.replace(/^#?['`~@]+/,""),r=t.lastIndexOf("/"),n=A(t);if(r<=0)return{leaf:n,text:t};let i=t.slice(0,r);return{leaf:n,qualifier:i,text:t}}function zt(e,t){let r=t;for(;r<e.length&&e[r]!==`
114
- `;)r+=1;return r}function ct(e,t,r){let n=t+1,i=r;for(;n<e.length;){let o=e[n];if(o==="\\"){n+=2;continue}if(o===`
115
- `&&(i+=1),n+=1,o==='"')break}return{index:n,line:i}}function ln(e){return e==="'"||e==="`"||e==="~"||e==="@"||e==="^"||e==="#"}function pn(e){return/\s|,/.test(e)||e==="("||e===")"||e==="["||e==="]"||e==="{"||e==="}"||e==='"'||e===";"}function Np(e){let t=[];for(let[r,n]of e)for(let i of n)t[i]??=new Set,t[i].add(r);return t}var Oo=3,Pp=ke("source-facts",{clearGroups:["whole-project","source-file"]}),un=tt({kind:"source-facts",invalidation:rt("source-facts"),serialize:Fp,deserialize:Op});function Lo(e,t){return Dp(e,t).facts}function Dp(e,t){let r=N(e,t);if(!r)return{facts:null};let n=_p(e,t,r);return n?Pp.get(e,t,r,()=>Ap(e,t,n,r)):{facts:null}}function _p(e,t,r){return be(t)?Ht(e,t,r)?.language??null:Se(t)}function Ap(e,t,r,n){let i=je(e,t,n),o=un.read(e,t,i);if(o&&o.language===r)return{facts:o};if(r==="clojure"){let c=Fo(n);return un.write(e,t,i,c),{facts:c}}let s=B(e,t);if(!s)return{facts:null,unavailable:{language:r,reason:"parser-unavailable"}};let a=Lp(s,r);return un.write(e,t,i,a),{facts:a}}function Fp(e){let t={version:Oo,language:e.language,callables:e.callables,callSites:e.callSites,clojureMembers:e.clojureMembers,typeContainerMap:[...e.typeContainerMap.entries()].map(([r,n])=>[r,[...n]]),identifierLineMap:[...e.identifierLineMap.entries()],rustAttrReferencedNames:[...e.rustAttrReferencedNames],crossLanguageDispatchNames:[...e.crossLanguageDispatchNames]};return JSON.stringify(t)}function Op(e){try{let t=JSON.parse(e);if(t.version!==Oo||t.language==="clojure"&&(t.clojureMembers===void 0||t.callSites.some(n=>n.calleeText===void 0)))return null;let r=new Map(t.identifierLineMap);return{language:t.language,callables:t.callables,callSites:t.callSites,clojureMembers:t.clojureMembers??[],typeContainerMap:new Map(t.typeContainerMap.map(([n,i])=>[n,new Set(i)])),identifierLineMap:r,identifiersByLine:an(r),fileIdentifiers:new Set(r.keys()),rustAttrReferencedNames:new Set(t.rustAttrReferencedNames),crossLanguageDispatchNames:new Set(t.crossLanguageDispatchNames)}}catch{return null}}function Lp(e,t){let r=[],n=[],i=new Set,o=new Set,s=new Map,a=(l,p)=>{let u=s.get(l);if(!u){s.set(l,[p]);return}u[u.length-1]!==p&&u.push(p)},c=l=>{let p=ko(l,t);p&&r.push(p);let u=Io(l,t);u&&n.push(u),Do(l,t,o),t==="rust"&&(l.type==="attribute_item"||l.type==="inner_attribute_item")&&_o(l.text,i),Ro(l,t)&&a(l.text,l.startPosition.row),No(l,t)&&Po(l,a);for(let d of l.children)c(d)};return c(e.rootNode),{language:t,callables:r,callSites:n,clojureMembers:[],typeContainerMap:Ao(e,t),identifierLineMap:s,identifiersByLine:an(s),fileIdentifiers:new Set(s.keys()),rustAttrReferencedNames:i,crossLanguageDispatchNames:o}}var jp=new Set(["rust","typescript","tsx","javascript","python","clojure"]);function Mp(e,t){let r=Lo(e,t);return!r||!jp.has(r.language)?null:r.callables.map(n=>({name:n.name,startLine:n.startLine,endLine:n.endLine}))}function jo(e,t){return e.split(t).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}var $p=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]);function k(e){let t=[],r=0,n=0;for(let i=0;i<e.length;i++){let o=e[i];(o==="{"||o==="["||o==="(")&&r++,(o==="}"||o==="]"||o===")")&&r--,o===","&&r===0&&(t.push(e.slice(n,i)),n=i+1)}return t.push(e.slice(n)),t}function P(e,t){for(let r of e.namedChildren)if(r.type===t)return r;return null}function S(e,t){let r=new Set,n=(i,o)=>{let s=o||t.has(i.type);!s&&$p.has(i.type)&&r.add(i.text);for(let a of i.children)n(a,s)};return n(e.rootNode,!1),r}function W(e,t,r,n,i,o,s){return{importedName:i,localName:o,sourcePath:s??h(e,n,Qr(t)),kind:"named",used:w(r,o),usedMembers:[]}}function g(e,t,r,n,i="named",o={}){return{importedName:e,localName:t,sourcePath:r,kind:i,used:n.has(t),usedMembers:[],isTypeOnly:o.isTypeOnly}}function X(e,t,r,n,i="named",o=[],s={}){return{importedName:e,localName:t,sourcePath:r,kind:i,used:n,usedMembers:o,isTypeOnly:s.isTypeOnly}}function Ie(e,t){return{importedName:e,localName:null,sourcePath:t,kind:"side-effect",used:!0,usedMembers:[]}}function Ee(e,t,r={}){return{importedName:e,localName:r.localName??null,sourcePath:t,kind:"namespace",used:r.used??!0,usedMembers:r.usedMembers??[],isTypeOnly:r.isTypeOnly}}function F(e,t,r){let n=[];for(let i of e.matchAll(t)){let o=i[0];if(!o||typeof i.index!="number")continue;let s=oe(e,i.index,i.index+o.length);for(let a of r(i,s))n.push(a)}return n}function O(e,t,r,n){let i=B(e,t);if(i){let o=r(i);if(o)return o}return n()}function Jt(e,t,r,n){let i=B(e,t),o=Se(t),s=o?r[o]:void 0;return i&&s?s(i):n()}function $o(e,t,r){return O(e,t,n=>Wp(e,t,n),()=>Gp(e,t,r))}function Gp(e,t,r){return F(r,/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm,(n,i)=>{let o=n[1]?.trim();if(!o)return[];let s=Mo(o).replace(/\.[^.]+$/,"");return[X(o,s,$t(e,t,o),w(i,s))]})}function Wp(e,t,r){let n=S(r,new Set(["preproc_include"])),i=[];for(let o of r.rootNode.descendantsOfType("preproc_include")){let s=null;for(let c of o.namedChildren){if(c.type==="system_lib_string"){s=c.text.replace(/^<|>$/g,"");break}if(c.type==="string_literal"){s=c.namedChildren.find(p=>p.type==="string_content")?.text??c.text.replace(/^"|"$/g,"");break}}if(!s)continue;let a=Mo(s).replace(/\.[^.]+$/,"");i.push(g(s,a,$t(e,t,s),n))}return i}var Vp=new Set([":require",":require-macros",":use"]),mn=String.raw`A-Za-z0-9_$*+!?.<>=-`;function Wo(e,t,r){let n=Zp(r);if(!n)return[];let i=Qp(r,n.start,n.end),o=[];for(let s of n.children.slice(2)){if(s.type!=="list"||s.children.length===0)continue;let a=L(s.children[0]);if(a){if(Vp.has(a)){for(let c of Hp(s.children.slice(1)))o.push(...Up(e,c,i));continue}if(a===":import")for(let c of zp(s.children.slice(1)))o.push(c)}}return o}function Bp(e){return e.type==="list"&&L(e.children[0])==="ns"}function Up(e,t,r){let n=Zr(e,t.namespace),i=t.alias??t.namespace,o=Xp(r,i),s=[{importedName:t.namespace,localName:i,sourcePath:n,kind:"namespace",used:t.refers.length>0||t.referAll||o.length>0||Yp(r,t.namespace),usedMembers:o}];t.referAll&&s.push({importedName:"*",localName:null,sourcePath:n,kind:"side-effect",used:!0,usedMembers:[]});for(let a of t.refers)s.push({importedName:a,localName:a,sourcePath:n,kind:"named",used:Kp(r,a),usedMembers:[]});return s}function Hp(e){return e.flatMap(t=>Xt(t,null))}function Xt(e,t){if(e.type==="atom")return e.text.startsWith(":")?[]:[{namespace:fn(t,e.text),alias:null,refers:[],referAll:!1}];if(e.type==="vector")return e.children.length>0&&L(e.children[0])===null?e.children.flatMap(r=>Xt(r,t)):qp(e,t);if(e.type==="list"&&e.children.length>0){let r=L(e.children[0]);return r?!r||r.startsWith(":")?[]:e.children.slice(1).flatMap(n=>Xt(n,fn(t,r))):e.children.flatMap(n=>Xt(n,t))}return[]}function qp(e,t){let r=L(e.children[0]);if(!r||r.startsWith(":"))return[];let n={namespace:fn(t,r),alias:null,refers:[],referAll:!1};for(let i=1;i<e.children.length;i+=1){let o=L(e.children[i]);if(!o?.startsWith(":"))continue;let s=e.children[i+1];if((o===":as"||o===":as-alias")&&s){n.alias=L(s),i+=1;continue}o===":refer"&&s&&(L(s)===":all"?n.referAll=!0:(s.type==="vector"||s.type==="list")&&n.refers.push(...s.children.map(L).filter(Jp)),i+=1)}return[n]}function zp(e){let t=[];for(let r of e){if(r.type==="atom"){let i=r.text.split(".").pop()??r.text;t.push(X(i,i,null,!0));continue}if(r.type!=="vector")continue;let n=L(r.children[0]);if(n)for(let i of r.children.slice(1)){let o=L(i);o&&t.push(X(`${n}.${o}`,o,null,!0))}}return t}function fn(e,t){return e?`${e}.${t}`:t}function L(e){return e?.type==="atom"?e.text:null}function Jp(e){return!!(e&&!e.startsWith(":"))}function Xp(e,t){let r=new Set,n=new RegExp(`${gn()}${he(t)}\\s*/\\s*([${mn}]+)`,"g");for(let i of e.matchAll(n)){let o=i[1];o&&r.add(o)}return[...r]}function Yp(e,t){return new RegExp(`${gn()}${he(t)}\\s*/`,"m").test(e)}function Kp(e,t){return new RegExp(`${gn()}${he(t)}(?![${mn}])`,"m").test(e)}function gn(){return`(?<![${mn}])`}function Qp(e,t,r){let n="",i=0;for(;i<e.length;){if(i>=t&&i<r){n+=e[i]===`
116
- `?`
117
- `:" ",i+=1;continue}let o=e[i];if(o===";"){let s=zt(e,i);n+=Go(e.slice(i,s)),i=s;continue}if(o==='"'){let s=ct(e,i,0).index;n+=Go(e.slice(i,s)),i=s;continue}n+=o,i+=1}return n}function Zp(e){let t=0;for(;t<e.length&&(t=yn(e,t),!(t>=e.length));){let r=Yt(e,t);if(!r){t+=1;continue}if(Bp(r.form))return r.form;t=r.index}return null}function Yt(e,t){let r=yn(e,t);if(e.startsWith("#?@",r)||e.startsWith("#?",r))return eu(e,r);if(e.startsWith("#_",r)){let i=Yt(e,r+2);return i?{form:{type:"atom",text:"",start:r,end:i.index},index:i.index}:null}for(;ln(e[r]);)r+=1;let n=e[r];return n?n==="("?dn(e,r,"list",")"):n==="["?dn(e,r,"vector","]"):n==="{"?dn(e,r,"map","}"):n==='"'?{form:{type:"atom",text:"",start:r,end:ct(e,r,0).index},index:ct(e,r,0).index}:ru(e,r):null}function eu(e,t){let r=e.startsWith("#?@",t)?3:2,n=Yt(e,t+r);return n?{form:{type:"list",children:n.form.type==="list"||n.form.type==="vector"||n.form.type==="map"?tu(n.form.children):[],start:t,end:n.index},index:n.index}:null}function tu(e){let t=[];for(let r=0;r<e.length;r+=2){let n=L(e[r]),i=e[r+1];n?.startsWith(":")&&i&&t.push(i)}return t}function dn(e,t,r,n){let i=[],o=t+1;for(;o<e.length;){if(o=yn(e,o),e[o]===n)return{form:{type:r,children:i,start:t,end:o+1},index:o+1};let s=Yt(e,o);if(!s){o+=1;continue}s.form.type==="atom"&&s.form.text===""||i.push(s.form),o=s.index}return{form:{type:r,children:i,start:t,end:e.length},index:e.length}}function ru(e,t){let r=t;for(;r<e.length&&!pn(e[r]);)r+=1;return{form:{type:"atom",text:e.slice(t,r),start:t,end:r},index:r}}function yn(e,t){let r=t;for(;r<e.length;){let n=e[r];if(/\s|,/.test(n)){r+=1;continue}if(n===";"){r=zt(e,r);continue}break}return r}function Go(e){return e.replace(/[^\r\n]/g," ")}function Vo(e,t,r){let n=[];for(let i of r.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let o=i[1]?.trim(),s=i[2]?.trim()??null,a=i[0];if(!o||!a||typeof i.index!="number")continue;let c=oe(r,i.index,i.index+a.length);n.push({importedName:o,localName:s,sourcePath:Gt(e,t,o),kind:s?"namespace":"side-effect",used:s?w(c,s):!0,usedMembers:s?Oe(c,s):[]})}return n}function Bo(e,t,r){let n=[];for(let i of r.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let o=i[1]?.trim();o&&n.push({specifier:o,sourcePath:Gt(e,t,o)})}return n}function Uo(e,t,r){return Jt(e,t,{csharp:n=>iu(e,t,n),vb:n=>nu(e,t,n)},()=>{let n=po(t)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;return F(r,n,(i,o)=>{let s=i[1]?.trim();if(!s)return[];let[a,c]=s.split(/\s*=\s*/),l=!!c,p=(l?c:a)?.trim()??s,u=p.split(".").pop()??p,d=l?a?.trim()??u:u;return[W(e,t,o,p,u,d,h(e,p,re))]})})}function nu(e,t,r){let n=S(r,new Set(["imports_statement"])),i=[];for(let o of r.rootNode.descendantsOfType("imports_statement")){let s=o.namedChildren.filter(d=>d.type==="namespace_name");if(s.length===0)continue;let a=s[s.length-1],c=s.length>1?s[0]:null,l=a.text,p=l.split(".").pop()??l,u=c?.text??p;i.push(g(p,u,h(e,l,re),n,c?"namespace":"named"))}return i}function iu(e,t,r){let n=S(r,new Set(["using_directive"])),i=[];for(let o of r.rootNode.descendantsOfType("using_directive")){let s=o.namedChildren;if(s.length===0)continue;let a=null,c;s.length>=2&&s[0].type==="identifier"&&(s[1].type==="qualified_name"||s[1].type==="identifier")?(a=s[0],c=s[1]):c=s[s.length-1];let l=c.text,p=l.split(".").pop()??l,u=a?.text??p;i.push(g(p,u,h(e,l,re),n,a?"namespace":"named"))}return i}var ou=x("vue-non-script-identifiers",{clearGroups:["whole-project","source-file"]});function Ho(e,t){return ou.get(e,t,()=>{let r=new Set,n=N(e,t);if(!n)return r;let o=n.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,s=>s.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,s=>s.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,s=>s.replace(/[^\r\n]/g," "));for(let s of o.matchAll(/[A-Za-z_$][\w$]*/g))r.add(s[0]);return r})}function hn(e,t,r){return O(e,t,n=>au(e,t,n),()=>su(e,t,r))}function su(e,t,r){return Su(r).flatMap(n=>bu(e,t,n.clause,n.specifier,n.start,n.end,r))}function au(e,t,r){let n=cu(e,t,r),i=[];for(let o of r.rootNode.descendantsOfType("import_statement"))i.push(...lu(e,t,r,o,n));return i}function cu(e,t,r){let n=S(r,new Set(["import_statement"]));if(be(t))for(let i of Ho(e,t))n.add(i);return n}function lu(e,t,r,n,i){let o=mu(n);if(!o)return[];let s=ne(e,t,o),a=P(n,"import_clause");return a?pu(r,a,s,i,gu(n.text)):[Ie("*",s)]}function pu(e,t,r,n,i){let o=[];for(let s of t.namedChildren)if(s.type==="identifier")o.push(uu(s.text,r,n,i));else if(s.type==="namespace_import"){let a=du(e,s,r,n,i);a&&o.push(a)}else s.type==="named_imports"&&o.push(...fu(s,r,n,i));return o}function uu(e,t,r,n){return g("default",e,t,r,"default",{isTypeOnly:n})}function du(e,t,r,n,i){let s=P(t,"identifier")?.text??"";if(!s)return null;let a=hu(e,s);return Ee("*",r,{localName:s,usedMembers:a,isTypeOnly:i,used:a.length>0||n.has(s)})}function fu(e,t,r,n){let i=[];for(let o of e.namedChildren){if(o.type!=="import_specifier")continue;let s=o.namedChild(0),a=o.namedChild(1);if(!s)continue;let c=s.text,l=a?.text??c;i.push(g(c,l,t,r,"named",{isTypeOnly:n||yu(o.text)}))}return i}function mu(e){let t=P(e,"string");if(!t)return null;let r=P(t,"string_fragment");return r?r.text:null}function gu(e){return/^\s*import\s+type\b/.test(e)}function yu(e){return/^\s*type\b/.test(e.trim())}function hu(e,t){let r=new Set;for(let n of e.rootNode.descendantsOfType("member_expression")){let i=n.namedChild(0),o=n.namedChild(1);!i||!o||i.type!=="identifier"||i.text!==t||(o.type==="property_identifier"||o.type==="identifier")&&r.add(o.text)}return[...r]}function Su(e){let t=[],r=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(r)){let o=i[0],s=i[1],a=i[2];!o||!a||typeof i.index!="number"||t.push({clause:s,specifier:a,start:i.index,end:i.index+o.length})}let n=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(n)){let o=i[0],s=i[1];!o||!s||typeof i.index!="number"||t.push({clause:null,specifier:s,start:i.index,end:i.index+o.length})}return t.sort((i,o)=>i.start-o.start)}function bu(e,t,r,n,i,o,s){let a=ne(e,t,n),c=oe(s,i,o);return r?xu(r).map(p=>({...p,sourcePath:a})).map(p=>{if(p.kind==="namespace"){let u=Oe(c,p.localName);return Ee(p.importedName,p.sourcePath,{localName:p.localName,usedMembers:u,used:u.length>0||w(c,p.localName),isTypeOnly:p.isTypeOnly})}return p.kind==="side-effect"?Ie(p.importedName,p.sourcePath):X(p.importedName,p.localName??"",p.sourcePath,p.localName?w(c,p.localName):!1,p.kind,[],{isTypeOnly:p.isTypeOnly})}):[Ie("*",a)]}function xu(e){let t=e.trim(),r=/^type\b/.test(t),n=t.replace(/^type\s+/,""),[i,o]=Iu(n),s=[];return i&&s.push(...qo(i,r)),o&&s.push(...qo(o,r)),s}function qo(e,t){let r=e.trim();if(!r)return[];if(r.startsWith("{")){let n=r.slice(1,-1).trim();return n?k(n).map(i=>{let o=i.trim(),s=t||/^type\b/.test(o),a=o.replace(/^type\s+/,""),[c,l]=a.split(/\s+as\s+/);return{importedName:c.trim(),localName:(l??c).trim(),kind:"named",isTypeOnly:s}}):[]}return r.startsWith("* as ")?[{importedName:"*",localName:r.slice(5).trim(),kind:"namespace",isTypeOnly:t}]:[{importedName:"default",localName:r,kind:"default",isTypeOnly:t}]}function Iu(e){let t=0;for(let r=0;r<e.length;r++){let n=e[r];if(n==="{"&&t++,n==="}"&&t--,n===","&&t===0)return[e.slice(0,r).trim(),e.slice(r+1).trim()]}return[e.trim(),null]}function Sn(e,t,r){let n=B(e,t);return n?Cu(e,t,n):Eu(e,t,r)}function Eu(e,t,r){return[...vu(e,t,r),...Tu(e,t,r),...wu(e,t,r)]}function vu(e,t,r){let n=[],i=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let o of r.matchAll(i)){if(typeof o.index!="number")continue;let s=o[1]??"",a=o[2]??"",c=k(s).map(u=>ku(u.trim())).filter(u=>!!u),l=Le(r,o.index),p=Le(r,o.index+o[0].length-1);n.push({kind:"named",sourcePath:ne(e,t,a),names:c,startLine:l,endLine:p})}return n}function Tu(e,t,r){let n=[],i=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let o of r.matchAll(i)){if(typeof o.index!="number")continue;let s=o[2]??"",a=Le(r,o.index),c=Le(r,o.index+o[0].length-1);n.push({kind:"star-as",sourcePath:ne(e,t,s),names:[],startLine:a,endLine:c})}return n}function wu(e,t,r){let n=[],i=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let o of r.matchAll(i)){if(typeof o.index!="number")continue;let s=o[1]??"",a=Le(r,o.index),c=Le(r,o.index+o[0].length-1);n.push({kind:"star",sourcePath:ne(e,t,s),names:[],startLine:a,endLine:c})}return n}function ku(e){if(!e)return null;let t=e.replace(/^type\s+/,"").trim();if(!t)return null;let r=t.match(/^(\w+)\s+as\s+(\w+)$/);if(r)return r[2]??null;let n=t.match(/^(\w+)$/);return n?n[1]??null:null}function Le(e,t){let r=0;for(let n=0;n<t&&n<e.length;n++)e.charCodeAt(n)===10&&r++;return r}function Cu(e,t,r){let n=[];for(let i of r.rootNode.descendantsOfType("export_statement")){let o=Ru(e,t,i);if(o===void 0)continue;let s=i.startPosition.row,a=i.endPosition.row,c=Nu(i,o,s,a);n.push(c)}return n}function Ru(e,t,r){let n=P(r,"string");if(!n)return;let i=P(n,"string_fragment");if(i)return ne(e,t,i.text)}function Nu(e,t,r,n){let i=P(e,"export_clause");if(i){let s=[];for(let a of i.namedChildren){if(a.type!=="export_specifier")continue;let c=a.namedChild(0),l=a.namedChild(1);c&&s.push((l??c).text)}return{kind:"named",sourcePath:t,names:s,startLine:r,endLine:n}}return P(e,"namespace_export")?{kind:"star-as",sourcePath:t,names:[],startLine:r,endLine:n}:{kind:"star",sourcePath:t,names:[],startLine:r,endLine:n}}function zo(e,t,r){return Jt(e,t,{java:n=>Pu(e,t,n),kotlin:n=>Du(e,t,n),scala:n=>_u(e,t,n)},()=>F(r,/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm,(n,i)=>{let o=n[1]?.trim();return o?Au(e,t,o,i):[]}))}function Pu(e,t,r){let n=S(r,new Set(["import_declaration"])),i=[];for(let o of r.rootNode.descendantsOfType("import_declaration")){let s=o.children.some(u=>u.type==="asterisk"),c=o.namedChildren.find(u=>u.type==="scoped_identifier")??o.namedChildren.find(u=>u.type==="identifier");if(!c)continue;let l=c.text;if(s){i.push(Ee("*",h(e,l,R)));continue}let p=l.split(".").pop()??l;i.push(g(p,p,h(e,l,R),n))}return i}function Du(e,t,r){let n=S(r,new Set(["import_header","import_list"])),i=[];for(let o of r.rootNode.descendantsOfType("import_header")){let s=o.namedChildren.find(m=>m.type==="identifier");if(!s)continue;let a=o.namedChildren.some(m=>m.type==="wildcard_import"),c=o.namedChildren.find(m=>m.type==="import_alias");if(a){i.push(Ee("*",h(e,s.text,R)));continue}let l=s.text,p=l.split(".").pop()??l,d=c?.namedChild(0)?.text??p;i.push(g(p,d,h(e,l,R),n))}return i}function _u(e,t,r){let n=S(r,new Set(["import_declaration"])),i=[];for(let o of r.rootNode.descendantsOfType("import_declaration")){let s=o.namedChildren.find(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),a=o.namedChildren.filter(u=>u!==s&&(u.type==="identifier"||u.type==="stable_identifier")),c=a.map(u=>u.text).join(".");if(!c)continue;if(s?.type==="namespace_wildcard"){i.push(Ee("*",h(e,c,R)));continue}if(s?.type==="namespace_selectors"){for(let u of s.namedChildren)if(u.type==="arrow_renamed_identifier"){let[d,m]=u.namedChildren;if(!d)continue;let y=d.text,ve=m?.text??y;if(y==="_")continue;i.push(g(y,ve,h(e,`${c}.${y}`,R),n))}else if(u.type==="identifier"){let d=u.text;i.push(g(d,d,h(e,`${c}.${d}`,R),n))}continue}let l=a[a.length-1]?.text??c,p=a.slice(0,-1).map(u=>u.text).join(".")||c;i.push(g(l,l,h(e,p&&a.length>1?`${p}.${l}`:c,R),n))}return i}function Au(e,t,r,n){if(r.includes("{")&&r.includes("}")){let i=r.slice(0,r.indexOf("{")).replace(/\.$/,"").trim(),o=r.slice(r.indexOf("{")+1,r.lastIndexOf("}")).trim();return k(o).flatMap(s=>{let a=s.trim();if(!a)return[];let[c,l]=a.includes("=>")?a.split(/\s*=>\s*/):a.split(/\s+as\s+/),p=c?.trim();if(!p||p==="_")return[];let u=(l??p.split(".").pop()??p).trim(),d=p==="_"?i:`${i}.${p}`.replace(/\.\./g,".");return[W(e,t,n,d,p,u)]})}return[W(e,t,n,r,r.split(".").pop()??r,r.split(".").pop()??r)]}function Xo(e,t,r){return O(e,t,n=>Fu(e,t,n),()=>F(r,/^[ \t]*use\s+(.+?)\s*;$/gm,(n,i)=>{let o=n[1]?.trim();return o?k(o).flatMap(s=>{let a=s.trim();if(!a)return[];let[c,l]=a.split(/\s+as\s+/i),p=c?.trim()??a,u=p.split("\\").pop()??p,d=(l??u).trim();return[W(e,t,i,p,u,d,h(e,p.replace(/\\/g,"."),ye))]}):[]}))}function Fu(e,t,r){let n=S(r,new Set(["namespace_use_declaration"])),i=[],o=(s,a,c)=>{i.push(g(a,c,h(e,s.replace(/\\/g,"."),ye),n))};for(let s of r.rootNode.descendantsOfType("namespace_use_declaration")){let a=s.namedChildren.find(c=>c.type==="namespace_use_group");if(a){let c=s.namedChildren.find(l=>l.type==="namespace_name")?.text??"";for(let l of a.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:p,localName:u,qualified:d}=Jo(l,c);p&&o(d,p,u)}continue}for(let c of s.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:l,localName:p,qualified:u}=Jo(c,"");l&&o(u,l,p)}}return i}function Jo(e,t){let r=e.namedChildren.find(l=>l.type==="qualified_name"),n=e.namedChildren.filter(l=>l.type==="name"),i="";r?i=r.text:n.length>=1&&(i=n[0].text);let o=r&&n.length>0?n[n.length-1]:null,s=i.split("\\").pop()??i,a=o?.text??s,c=t?`${t}\\${i}`:i;return{importedName:s,localName:a,qualified:c}}function Ko(e,t,r){return O(e,t,n=>Ou(e,t,n),()=>ju(r).flatMap(n=>$u(e,t,n,r)))}function Ou(e,t,r){let n=S(r,new Set(["import_statement","import_from_statement"])),i=[];for(let o of r.rootNode.descendantsOfType("import_statement"))for(let s of o.namedChildren){let a=Yo(s);if(!a)continue;let c=Fe(e,t,a.qualifiedName);i.push({importedName:a.qualifiedName,localName:a.localName,sourcePath:c,kind:"namespace",used:n.has(a.localName),usedMembers:[]})}for(let o of r.rootNode.descendantsOfType("import_from_statement")){let s=o.namedChild(0);if(!s)continue;let a=Lu(s);if(a===null)continue;let c=Fe(e,t,a);for(let l=1;l<o.namedChildCount;l+=1){let p=o.namedChild(l);if(p.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:c,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=Yo(p);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:c,kind:"named",used:n.has(u.localName),usedMembers:[]})}}return i}function Yo(e){if(e.type==="aliased_import"){let t=e.namedChild(0),r=e.namedChild(1);return!t||!r?null:{qualifiedName:t.text,localName:r.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 Lu(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let t=P(e,"import_prefix")?.text??"",r=P(e,"dotted_name")?.text??"";return`${t}${r}`}return null}function ju(e){let t=e.split(`
118
- `),r=[],n=0;for(let i=0;i<t.length;i++){let o=t[i],s=o.trimStart(),a=n;if(n+=o.length+1,!s.startsWith("import ")&&!s.startsWith("from "))continue;let c=o,l=a+o.length,p=nn(o);for(;i+1<t.length&&(p>0||c.trimEnd().endsWith("\\"));){i++;let d=t[i];c+=`
119
- ${d}`,l+=1+d.length,p+=nn(d),n+=d.length+1}let u=Mu(c);u&&r.push({...u,start:a,end:l})}return r}function Mu(e){let t=e.replace(/\\\s*\n/g," ").trim();if(t.startsWith("import "))return{kind:"import",module:null,clause:t.slice(7).trim()};let r=t.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!r)return null;let n=r[2].trim();return n.startsWith("(")&&n.endsWith(")")&&(n=n.slice(1,-1).trim()),{kind:"from",module:r[1],clause:n}}function $u(e,t,r,n){let i=oe(n,r.start,r.end),o=r.clause.replace(/\n/g," ").trim();if(r.kind==="import")return k(o).flatMap(c=>{let l=c.trim().replace(/,$/,"");if(!l)return[];let[p,u]=l.split(/\s+as\s+/),d=p.trim(),m=(u??d.split(".")[0]??d).trim(),y=Fe(e,t,d),ve=Oe(i,m);return[{importedName:d,localName:m,sourcePath:y,kind:"namespace",used:w(i,m)||ve.length>0,usedMembers:ve}]});let s=r.module?Fe(e,t,r.module):null,a=[];for(let c of k(o)){let l=c.trim().replace(/,$/,"");if(!l)continue;if(l==="*"){a.push({importedName:"*",localName:null,sourcePath:s,kind:"side-effect",used:!0,usedMembers:[]});continue}let[p,u]=l.split(/\s+as\s+/),d=(u??p).trim();a.push({importedName:p.trim(),localName:d,sourcePath:s,kind:"named",used:w(i,d),usedMembers:[]})}return a}import{basename as Gu}from"path";function Qo(e,t,r){return O(e,t,n=>Vu(e,t,n),()=>Wu(e,t,r))}function Wu(e,t,r){return F(r,/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm,(n,i)=>{let o=n[1],s=n[2];if(!o||!s)return[];let a=o==="require_relative"?Mt(e,t,s):null;if(a){let c=Zo(s);return[X(c,c,a,w(i,c))]}return[Ie(s,a)]})}function Vu(e,t,r){let n=S(r,new Set([])),i=[],o=new Set(["require","require_relative","load"]);for(let s of r.rootNode.descendantsOfType("call")){let a=s.namedChild(0);if(!a||a.type!=="identifier"||!o.has(a.text))continue;let l=s.namedChildren.find(m=>m.type==="argument_list")?.namedChild(0);if(!l||l.type!=="string")continue;let u=l.namedChildren.find(m=>m.type==="string_content")?.text;if(!u)continue;let d=a.text==="require_relative"?Mt(e,t,u):null;if(d){let m=Zo(u);i.push(g(m,m,d,n))}else i.push(Ie(u,d))}return i}function Zo(e){return jo(Gu(e).replace(/\.[^.]+$/,""),/_/)}function es(e,t,r){return O(e,t,n=>Bu(e,t,n),()=>F(r,/^[ \t]*use\s+(.+?)\s*;$/gm,(n,i)=>{let o=n[1]?.trim();return o?Uu(e,t,o,i):[]}))}function Bu(e,t,r){let n=S(r,new Set(["use_declaration"])),i=[];for(let o of r.rootNode.descendantsOfType("use_declaration")){let s=o.namedChild(0);if(s)for(let a of lt(s,"")){if(!a.importedName||a.importedName==="*")continue;let c=z(e,t,a.qualifiedName)??z(e,t,a.qualifiedName.split("::").slice(0,-1).join("::"));i.push(g(a.importedName,a.localName,c,n))}}return i}function lt(e,t){switch(e.type){case"identifier":case"super":case"crate":{let r=e.text;return[{qualifiedName:Kt(t,r),importedName:r,localName:r}]}case"self":{let r=t.split("::").filter(Boolean).pop()??"self";return[{qualifiedName:t||"self",importedName:r,localName:r}]}case"scoped_identifier":{let r=e.text,n=r.split("::").pop()??r;return[{qualifiedName:Kt(t,r),importedName:n,localName:n}]}case"scoped_use_list":{let r=e.namedChild(0),n=e.namedChild(1);if(!r||!n)return[];let i=Kt(t,r.text),o=[];for(let s of n.namedChildren)o.push(...lt(s,i));return o}case"use_list":{let r=[];for(let n of e.namedChildren)r.push(...lt(n,t));return r}case"use_as_clause":{let r=e.namedChild(0),n=e.namedChild(1);if(!r||!n)return[];let i=lt(r,t),o=n.text;return i.map(s=>({...s,localName:o}))}case"use_wildcard":{let r=e.namedChild(0),n=r?r.text:"";return[{qualifiedName:Kt(t,`${n}::*`),importedName:"*",localName:"*"}]}default:return[]}}function Kt(e,t){return e?t?`${e}::${t}`:e:t}function Uu(e,t,r,n){let i=r.trim();if(i.includes("{")&&i.includes("}")){let p=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),u=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return k(u).flatMap(d=>{let m=d.trim();if(!m)return[];if(m==="self"){let Qt=p.split("::").filter(Boolean).pop();return Qt?[W(e,t,n,p,Qt,Qt)]:[]}let[y,ve]=m.split(/\s+as\s+/),Te=y?.trim();if(!Te)return[];let os=(ve??Te.split("::").pop()??Te).trim(),ss=`${p}::${Te}`.replace(/::::/g,"::");return[W(e,t,n,ss,Te.split("::").pop()??Te,os,z(e,t,p))]})}let[o,s]=i.split(/\s+as\s+/),a=o?.trim()??i,c=(s??a.split("::").pop()??a).trim(),l=z(e,t,a)??z(e,t,a.split("::").slice(0,-1).join("::"));return[W(e,t,n,a,a.split("::").pop()??a,c,l)]}function ts(e,t,r){let n=B(e,t);if(n)return Hu(e,t,n);let i=[];for(let o of r.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let s=o[1]?.trim();s&&i.push(...zu(e,t,s))}return i}function Hu(e,t,r){let n=[];for(let i of r.rootNode.descendantsOfType("use_declaration")){if(!qu(i))continue;let o=i.namedChildren.find(s=>s.type!=="visibility_modifier");if(o)for(let s of lt(o,""))s.importedName&&n.push(bn(e,t,s.qualifiedName))}return n}function qu(e){for(let t of e.children)if(t.type==="visibility_modifier"&&t.text.startsWith("pub"))return!0;return!1}function zu(e,t,r){let n=r.trim();if(n.includes("{")&&n.includes("}")){let i=n.slice(0,n.indexOf("{")).replace(/::$/,"").trim(),o=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim();return k(o).flatMap(s=>{let a=s.trim();if(!a||a==="self")return[];let[c]=a.split(/\s+as\s+/),l=`${i}::${c?.trim()??a}`.replace(/::::/g,"::");return[bn(e,t,l)]})}return[bn(e,t,n)]}function bn(e,t,r){return{specifier:r,sourcePath:z(e,t,r)??z(e,t,r.split("::").slice(0,-1).join("::"))}}function se({language:e,extensions:t,imports:r,parseImports:n}){return{language:e,extensions:t,capabilities:{imports:r},parseImports:n}}function rs(e,t){let r=t.toLowerCase();for(let n of e)for(let i of n.extensions)if(r.endsWith(i))return n;return null}var Ju={language:"javascript",extensions:me,capabilities:{imports:"ast-with-regex-fallback",reExports:"ast-with-regex-fallback"},parseImports:hn,parseReExports:Sn},Xu=se({language:"python",extensions:At,imports:"ast-with-regex-fallback",parseImports:Ko}),Yu=se({language:"jvm",extensions:R,imports:"ast-dispatch-with-regex-fallback",parseImports:zo}),Ku={language:"rust",extensions:Ft,capabilities:{imports:"ast-with-regex-fallback",exports:"ast-with-regex-fallback"},parseImports:es,parseExports:ts},Qu=se({language:"ruby",extensions:Ot,imports:"ast-with-regex-fallback",parseImports:Qo}),Zu=se({language:"c/cpp",extensions:Lt,imports:"ast-with-regex-fallback",parseImports:$o}),ed=se({language:"dotnet",extensions:re,imports:"ast-dispatch-with-regex-fallback",parseImports:Uo}),td={language:"dart",extensions:jt,capabilities:{imports:"regex-only",exports:"regex-only"},parseImports:Vo,parseExports:Bo},rd=se({language:"php",extensions:ye,imports:"ast-with-regex-fallback",parseImports:Xo}),nd=se({language:"clojure",extensions:Ae,imports:"regex-only",parseImports:Wo}),id=[Ju,Xu,Yu,Ku,Qu,Zu,ed,td,rd,nd];function xn(e){return rs(id,e)}var In={clearGroups:["whole-project","source-file"]},od=x("source-imports",In),jh=x("source-exports",In),sd=x("source-reexports",In),ns=tt({kind:"source-imports",invalidation:rt("source-imports"),serialize:ad,deserialize:cd}),is=tt({kind:"source-reexports",invalidation:rt("source-reexports"),serialize:ld,deserialize:pd});function Mh(e,t){let r=T(t);return sd.get(e,r,()=>{let n=xn(r);if(!n?.parseReExports)return[];let i=N(e,r);if(!i)return[];let o=je(e,r,i),s=rn(e),a=is.read(e,r,o);if(a?.resolutionFingerprint===s)return a.reExports;let c=n.parseReExports(e,r,i);return is.write(e,r,o,{resolutionFingerprint:s,reExports:c}),c})}function $h(e,t){let r=T(t);return od.get(e,r,()=>{let n=xn(r);if(!n)return[];let i=N(e,r);if(!i)return[];let o=je(e,r,i),s=rn(e),a=ns.read(e,r,o);if(a?.resolutionFingerprint===s)return a.imports;let c=n.parseImports(e,r,i);return ns.write(e,r,o,{resolutionFingerprint:s,imports:c}),c})}function ad(e){return JSON.stringify(e)}function cd(e){try{let t=JSON.parse(e);return!mr(t)||typeof t.resolutionFingerprint!="string"||!Array.isArray(t.imports)?null:{resolutionFingerprint:t.resolutionFingerprint,imports:t.imports}}catch{return null}}function ld(e){return JSON.stringify(e)}function pd(e){try{let t=JSON.parse(e);return!mr(t)||typeof t.resolutionFingerprint!="string"||!Array.isArray(t.reExports)?null:{resolutionFingerprint:t.resolutionFingerprint,reExports:t.reExports}}catch{return null}}export{Pn as a,Gs as b,Ws as c,Od as d,dt as e,le as f,Mn as g,lr as h,Wn as i,yt as j,je as k,Bn as l,Xd as m,tt as n,Fm as o,rt as p,N as q,lg as r,B as s,Dp as t,Mp as u,jm as v,no as w,el as x,ne as y,mr as z,Kd as A,he as B,Mh as C,$h as D,fd as E,md as F,gd as G,yd as H,M as I,Wc as J,$m as K,Bc as L,Vm as M,Bm as N,Um as O,qm as P,rf as Q,cf as R,mf as S,gf as T,kn as U,ir as V,sr as W,Ed as X,wf as Y,kf as Z,Cf as _,Rf as $,Of as aa,Lf as ba,jf as ca,Mf as da,Ri as ea,Uf as fa,Pr as ga,hm as ha,Sm as ia,bm as ja,Ye as ka,xm as la,Im as ma,Em as na,xc as oa,Ic as pa,Cm as qa,Rm as ra,ws as sa,Cd as ta,Rd as ua,Nd as va};
120
- //# sourceMappingURL=chunk-IXORBCMR.js.map
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
- import{Bc as Y,Cc as Q,Pc as X,Qc as Z,V as y,W as k,Wc as ee,b as B,ca as F,da as H,fa as w,ga as T,ha as b,ic as C,ja as _,jc as J,ka as U,kc as K,la as z,oa as L}from"./chunk-GBB2RUDN.js";import{spawn as me}from"child_process";import{closeSync as ke,existsSync as we,mkdirSync as Ie,openSync as We,readFileSync as ie,rmSync as I,writeFileSync as Re}from"fs";import{dirname as be,resolve as E}from"path";import{fileURLToPath as Ce}from"url";var te=5e3,Ae=2e3,oe=10,Pe=new Set(["bench","config-validate","hook-context","hook-stop","init","reindex","setup","setup-agent","setup-ci","setup-hooks","uninstall","watch","work-audit"]);function ze(e){let t=e.classification;if(t.kind!=="live")return;let{state:r}=t;return r.watcher.state==="idle"&&r.lastError===void 0?r.indexGeneration:void 0}function Ee(e,t=process.env){return t.SCIP_QUERY_SKIP_WATCH_SERVICE!=="1"&&!e.startsWith("__")&&!Pe.has(e)}function Je(e){let t=e.env??process.env;if(t.SCIP_QUERY_SKIP_WATCH_SERVICE==="1")return{kind:"skipped",reason:"environment"};if(!Ee(e.commandName,t))return{kind:"skipped",reason:"excluded-command"};if(e.config.watch?.enabled!==!0)return{kind:"skipped",reason:"disabled"};try{let r=xe({projectRoot:e.projectRoot,cacheDir:e.cacheDir,cliVersion:e.cliVersion,gitContext:e.gitContext,runtime:e.runtime});return{kind:r.disposition,state:r.state}}catch(r){return{kind:"failed",message:r instanceof Error?r.message:String(r)}}}function se(e,t,r){let n=L(E(e));if(r&&L(r.projectRoot)===n)return{projectRoot:n,worktreeKind:"git",worktreeId:r.worktreeId,cliVersion:t};let i=U(n);if(i.kind==="error")throw new Error(`Could not establish Git worktree identity for ${n}: ${i.message}`);return i.kind==="non-git"?{projectRoot:n,worktreeKind:"non-git",cliVersion:t}:{projectRoot:n,worktreeKind:"git",worktreeId:i.identity.worktreeId,cliVersion:t}}function Ke(e){return P(e,se(e.projectRoot,e.cliVersion,e.gitContext))}function P(e,t){let r=e.runtime??O,n=w(e.cacheDir),i=T(n.statePath),s=m(n.lockPath);return{identity:t,classification:_e(i,t,r.now(),r.isProcessAlive),lock:s,lockIsLive:s!==null&&r.isProcessAlive(s.pid),paths:n}}function xe(e){let t=e.runtime??O,r=se(e.projectRoot,e.cliVersion,e.gitContext),n=P(e,r),i=G("ensure",n.classification);if(i.kind==="reuse")return A(n.paths.activityPath,t.now()),{disposition:"reused",state:i.state};if(i.kind==="replace")M(i.state.pid,e,t),W(n.paths,i.state.pid,t);else if(i.kind==="start"){if(n.lockIsLive){let o=re(e,r,t,Math.min(e.startupTimeoutMs??1e3,1e3));if(o)return A(n.paths.activityPath,t.now()),{disposition:"reused",state:o};throw new Error(`scip-query watch is already running for ${E(e.projectRoot)} (pid ${n.lock?.pid}; lock: ${n.paths.lockPath}) without compatible daemon state. Stop the foreground watcher before starting the service.`)}n.classification.kind==="stale"&&W(n.paths,n.classification.state.pid,t)}else throw new Error(`Unexpected ensure action: ${i.kind}`);if(n=P(e,r),i=G("ensure",n.classification),i.kind==="reuse")return A(n.paths.activityPath,t.now()),{disposition:"reused",state:i.state};let s=e.serverPath??Ce(new URL("./watch-server.js",import.meta.url));t.spawnServer(s,r.projectRoot,e.cliVersion,e.watchOverrides??{});let a=re(e,r,t,e.startupTimeoutMs??te);if(!a)throw new Error(`scip-query watch service did not become ready within ${e.startupTimeoutMs??te}ms.`);return A(n.paths.activityPath,t.now()),{disposition:"started",state:a}}function ae(e){let t=e.runtime??O,r=w(e.cacheDir),n=T(r.statePath),i=n?t.isProcessAlive(n.pid)?{kind:"live",state:n}:{kind:"stale",state:n,reason:"dead-process"}:{kind:"stopped"},s=G("stop",i);if(s.kind==="signal-stop")return M(s.state.pid,e,t),W(r,s.state.pid,t),{disposition:"stopped",pid:s.state.pid};if(s.kind==="clean-stale")return W(r,s.state.pid,t),{disposition:"stopped",pid:s.state.pid};let a=m(r.lockPath);return s.kind==="already-stopped"&&a&&t.isProcessAlive(a.pid)?(M(a.pid,e,t),W(r,a.pid,t),{disposition:"stopped",pid:a.pid}):{disposition:"already-stopped"}}function A(e,t=Date.now()){let r=Te(e);k(e,{version:1,at:new Date(t).toISOString(),...r?.refreshRequestedAtMs===void 0?{}:{refreshRequestedAt:new Date(r.refreshRequestedAtMs).toISOString(),...r.refreshDetail?{refreshDetail:r.refreshDetail}:{}}})}function Ye(e,t,r=Date.now()){k(e,{version:1,at:new Date(r).toISOString(),refreshRequestedAt:new Date(r).toISOString(),refreshDetail:t})}function Te(e){try{let t=JSON.parse(ie(e,"utf8"));return t.version!==1||!b(t.at)||t.refreshRequestedAt!==void 0&&!b(t.refreshRequestedAt)||t.refreshDetail!==void 0&&typeof t.refreshDetail!="string"?null:{atMs:Date.parse(t.at),...t.refreshRequestedAt===void 0?{}:{refreshRequestedAtMs:Date.parse(t.refreshRequestedAt)},...t.refreshDetail===void 0?{}:{refreshDetail:t.refreshDetail}}}catch{return null}}function Qe(e,t,r={}){let n=r.pid??process.pid,i=r.isProcessAlive??y,s=()=>{},a=m(e);if(a&&i(a.pid))return{acquired:!1,lockPath:e,message:ne(e,t,a),release:s};a&&I(e,{force:!0}),Ie(be(e),{recursive:!0});let o;try{o=We(e,"wx")}catch(d){if(Le(d)==="EEXIST")return{acquired:!1,lockPath:e,message:ne(e,t,m(e)),release:s};throw d}let l={version:1,pid:n,projectRoot:E(t),startedAt:(r.now??(()=>new Date))().toISOString()};Re(o,`${JSON.stringify(l)}
3
- `);let c=!1;return{acquired:!0,lockPath:e,message:"",release:()=>{if(c)return;c=!0,ke(o);let d=m(e);d?.pid===l.pid&&d.startedAt===l.startedAt&&I(e,{force:!0})}}}function m(e){try{let t=JSON.parse(ie(e,"utf-8"));return t.version!==1||typeof t.pid!="number"||!Number.isInteger(t.pid)||t.pid<=0||typeof t.projectRoot!="string"||!b(t.startedAt)?null:t}catch{return null}}function _e(e,t,r,n){if(!e)return{kind:"stopped"};if(e.protocolVersion!==F)return{kind:"incompatible",state:e,reason:"protocol"};if(e.projectRoot!==t.projectRoot)return{kind:"incompatible",state:e,reason:"project"};let i=t.worktreeKind==="git"?t.worktreeId:void 0;if(e.worktreeId!==i)return{kind:"incompatible",state:e,reason:"worktree"};if(e.cliVersion!==t.cliVersion)return{kind:"incompatible",state:e,reason:"cli-version"};if(!n(e.pid))return{kind:"stale",state:e,reason:"dead-process"};let s=Date.parse(e.heartbeatAt);return r-s>H?{kind:"stale",state:e,reason:"old-heartbeat"}:{kind:"live",state:e}}function G(e,t){switch(e){case"status":return{kind:"report",classification:t};case"ensure":switch(t.kind){case"stopped":return{kind:"start"};case"stale":return t.reason==="old-heartbeat"?{kind:"replace",state:t.state}:{kind:"start"};case"live":return{kind:"reuse",state:t.state};case"incompatible":return{kind:"replace",state:t.state};default:return D(t)}case"stop":switch(t.kind){case"stopped":return{kind:"already-stopped"};case"stale":return t.reason==="old-heartbeat"?{kind:"signal-stop",state:t.state}:{kind:"clean-stale",state:t.state};case"live":case"incompatible":return{kind:"signal-stop",state:t.state};default:return D(t)}default:return D(e)}}function re(e,t,r,n){let i=r.now()+n;for(;r.now()<=i;){let s=P(e,t).classification;if(s.kind==="live")return s.state;r.sleep(oe)}return null}function M(e,t,r){if(!r.isProcessAlive(e))return;r.signalProcess(e);let n=t.stopTimeoutMs??Ae,i=r.now()+n;for(;r.now()<=i;){if(!r.isProcessAlive(e))return;r.sleep(oe)}throw new Error(`scip-query watch service pid ${e} did not stop within ${n}ms.`)}function W(e,t,r){I(e.statePath,{force:!0}),I(e.activityPath,{force:!0}),m(e.lockPath)?.pid===t&&!r.isProcessAlive(t)&&I(e.lockPath,{force:!0})}function ne(e,t,r){return`error: scip-query watch is already running for ${E(t)}${r?` (pid ${r.pid}, started ${r.startedAt}; lock: ${e})`:` (lock: ${e})`}. Stop that watcher before starting another.`}function Le(e){return typeof e=="object"&&e&&"code"in e?e.code:void 0}var O={now:Date.now,isProcessAlive:y,spawnServer(e,t,r,n){if(!we(e))throw new Error(`Watch service helper was not found at ${e}. Run npm run build first.`);me(process.execPath,[e,t,r,JSON.stringify(n)],{detached:!0,stdio:"ignore",env:{...process.env,SCIP_QUERY_SKIP_WATCH_SERVICE:"1"}}).unref()},signalProcess(e){process.kill(e,"SIGTERM")},sleep(e){let t=new Int32Array(new SharedArrayBuffer(4));Atomics.wait(t,0,0,e)}};function D(e){throw new Error(`Unhandled watch service value: ${JSON.stringify(e)}`)}import{existsSync as ue,lstatSync as x,readFileSync as N,readdirSync as pe,realpathSync as ce,rmSync as R,statSync as he}from"fs";import{join as h,resolve as g,sep as de}from"path";var De=3600*1e3,Ge=2*1024*1024*1024,Me=300*1e3;function Oe(e){let t=e.leases.filter(o=>o.managed&&!o.live&&!o.busy),r=fe(e.leases,e.locks),n={};for(let o of e.generations)r.has(o.generationId)||(n[o.generationId]=o.unreferencedAt??e.nowMs);let i=e.generations.filter(o=>!r.has(o.generationId)).sort((o,l)=>n[o.generationId]-n[l.generationId]||o.generationId.localeCompare(l.generationId)),s=new Set;for(let o of i)e.nowMs-n[o.generationId]>=e.policy.generationTtlMs&&s.add(o.generationId);let a=e.generations.filter(o=>!s.has(o.generationId)).reduce((o,l)=>o+l.size,0);for(let o of i){if(a<=e.policy.budgetBytes)break;s.has(o.generationId)||(s.add(o.generationId),a-=o.size)}for(let o of s)delete n[o];return{deleteWorktrees:t,deleteGenerations:e.generations.filter(o=>s.has(o.generationId)),deleteLocks:e.locks.filter(o=>!o.live),deleteTemporaries:e.temporaries.filter(o=>!o.live),protectedGenerationIds:[...r].sort(),unreferencedSince:n}}function fe(e,t){let r=new Set(e.filter(n=>n.managed&&(n.live||n.busy)).flatMap(n=>[n.lease.baseGenerationId,n.lease.activeGenerationId]).filter(n=>n!==void 0));for(let n of t)n.live&&r.add(n.generationId);return r}function lt(e,t,r={}){if(!K())return{kind:"disabled"};let n=_(e);if(!n)return{kind:"unavailable"};let i=h(C(),"repositories",n.repositoryId);if(!ue(i))return{kind:"unavailable"};let s=(r.now??Date.now)(),a=h(i,"gc-state.json"),o=ge(a);if(!r.force&&o&&s-Date.parse(o.lastSweepAt)<Me)return{kind:"throttled",sweptAt:o.lastSweepAt};let l=Y(i,{now:()=>s});if(!l)return{kind:"busy"};try{let c=Se(e,i,n.repositoryId,o?.unreferencedSince??{}),d=Oe({nowMs:s,...c,policy:{generationTtlMs:r.policy?.generationTtlMs??De,budgetBytes:r.policy?.budgetBytes??Ge}}),u=0,f=0;for(let p of d.deleteWorktrees){if(!ve(p.lease))continue;let q=Q(h(p.lease.localCacheDir,"cache-lifecycle.lock"));if(q)try{if(V(p.lease,!0))continue;try{ae({projectRoot:p.lease.projectRoot,cacheDir:p.lease.localCacheDir,cliVersion:t})}catch{continue}if(V(p.lease,!0))continue;R(p.lease.localCacheDir,{recursive:!0,force:!0}),R(p.leasePath,{force:!0}),f+=1}finally{q.release()}}for(let p of d.deleteLocks)R(p.path,{force:!0});for(let p of d.deleteTemporaries)R(p.path,{recursive:!0,force:!0});for(let p of d.deleteGenerations)R(p.path,{recursive:!0,force:!0}),u+=p.size;B(h(i,"evidence.db"));let v={kind:"swept",sweptAt:new Date(s).toISOString(),deletedWorktrees:f,deletedGenerations:d.deleteGenerations.length,deletedBytes:u,protectedGenerations:d.protectedGenerationIds.length},S={version:1,lastSweepAt:v.sweptAt,unreferencedSince:d.unreferencedSince,lastResult:v};return k(a,S,{spacing:2,trailingNewline:!0}),v}catch(c){return{kind:"failed",error:c instanceof Error?c.message:String(c)}}finally{l.release()}}function ut(e,t,r){let n=X(e,r.dbPath,t);if(n)return{state:"bypassed",reason:n,localCacheDir:r.cacheDir,generations:0,generationBytes:0,protectedGenerations:0,unreferencedGenerations:0,unreferencedBytes:0,temporaryGenerations:0,sharedEvidence:{exists:!1,bytes:0}};let i=_(e);if(!i)return{state:"unavailable",reason:"Git worktree identity is unavailable",localCacheDir:r.cacheDir,generations:0,generationBytes:0,protectedGenerations:0,unreferencedGenerations:0,unreferencedBytes:0,temporaryGenerations:0,sharedEvidence:{exists:!1,bytes:0}};let s=h(C(),"repositories",i.repositoryId),a=ye(h(s,"worktrees",`${i.worktreeId}.json`)),o=ge(h(s,"gc-state.json")),l=Se(e,s,i.repositoryId,o?.unreferencedSince??{}),c=fe(l.leases,l.locks),d=l.generations.filter(S=>!c.has(S.generationId)),u=l.generations.reduce((S,p)=>S+p.size,0),f=Z(e,t),v=0;return f&&(v=je(f)),{state:"managed",repositoryId:i.repositoryId,worktreeId:i.worktreeId,localCacheDir:r.cacheDir,...a?{baseGenerationId:a.baseGenerationId,activeGenerationId:a.activeGenerationId,lastAction:a.lastAction,reason:a.lastReason,lastSeenAt:a.lastSeenAt}:{},generations:l.generations.length,generationBytes:u,protectedGenerations:l.generations.filter(S=>c.has(S.generationId)).length,unreferencedGenerations:d.length,unreferencedBytes:d.reduce((S,p)=>S+p.size,0),temporaryGenerations:l.temporaries.length,sharedEvidence:{path:f,exists:v>0,bytes:v},cleanup:o?.lastResult}}function je(e){return[e,`${e}-wal`,`${e}-shm`].reduce((t,r)=>{try{return t+he(r).size}catch{return t}},0)}function Se(e,t,r,n){let i=new Set(z(e).map(c=>g(c.path))),s=[];for(let c of j(h(t,"worktrees"))){if(!c.endsWith(".json"))continue;let d=h(t,"worktrees",c),u=ye(d);if(!u)continue;let f=g(u.projectRoot);s.push({leasePath:d,lease:u,managed:u.repositoryId===r&&ve(u),live:i.has(f)||ue(f),busy:V(u)})}let a=[];for(let c of j(h(t,"locks"))){let d=/^([a-f0-9]{64})\.lock$/.exec(c);if(!d)continue;let u=h(t,"locks",c),f=$(u),v=f!==void 0&&y(f),S=d[1];a.push({generationId:S,path:u,live:v})}let o=[],l=[];for(let c of j(h(t,"generations"))){let d=/^\.tmp-(\d+)-/.exec(c);if(d){let v=h(t,"generations",c),S=Number(d[1]);try{l.push({path:v,size:le(v),live:Number.isSafeInteger(S)&&y(S)})}catch{}continue}if(!/^[a-f0-9]{64}$/.test(c))continue;let u=h(t,"generations",c),f;try{f=x(u)}catch{continue}!f.isDirectory()||f.isSymbolicLink()||o.push({generationId:c,path:u,size:le(u),...n[c]===void 0?{}:{unreferencedAt:n[c]}})}return{leases:s,generations:o,locks:a,temporaries:l}}function ve(e){if(e.ownershipChecksum!==ee(e)||g(e.localCacheDir)!==g(J(e.projectRoot)))return!1;let t=g(C()),r=g(h(t,"projects")),n=g(e.localCacheDir);if(!n.startsWith(`${r}${de}`))return!1;try{let i=x(t),s=x(r),a=x(n);if(!i.isDirectory()||i.isSymbolicLink()||!s.isDirectory()||s.isSymbolicLink()||!a.isDirectory()||a.isSymbolicLink())return!1;let o=ce(r);return ce(n).startsWith(`${o}${de}`)}catch{return!1}}function V(e,t=!1){for(let n of t?["index.lock"]:["index.lock","cache-lifecycle.lock"]){let i=$(h(e.localCacheDir,n));if(i!==void 0&&y(i))return!0}let r=$(w(e.localCacheDir).lockPath);return r!==void 0&&y(r)}function ye(e){try{let t=JSON.parse(N(e,"utf8"));return t.version!==1||typeof t.repositoryId!="string"||typeof t.worktreeId!="string"||typeof t.projectRoot!="string"||t.treeOid!==void 0&&typeof t.treeOid!="string"||typeof t.localCacheDir!="string"||t.baseGenerationId!==void 0&&typeof t.baseGenerationId!="string"||t.activeGenerationId!==void 0&&typeof t.activeGenerationId!="string"||typeof t.ownershipChecksum!="string"||!/^[a-f0-9]{64}$/.test(t.ownershipChecksum)||typeof t.lastAction!="string"||t.lastReason!==void 0&&typeof t.lastReason!="string"||typeof t.lastSeenAt!="string"?null:t}catch{return null}}function $(e){try{let t=JSON.parse(N(e,"utf8"));return typeof t.pid=="number"&&Number.isSafeInteger(t.pid)&&t.pid>0?t.pid:void 0}catch{return}}function ge(e){try{let t=JSON.parse(N(e,"utf8"));return t.version!==1||typeof t.lastSweepAt!="string"||!Number.isFinite(Date.parse(t.lastSweepAt))||!t.unreferencedSince||typeof t.unreferencedSince!="object"||!t.lastResult?null:t}catch{return null}}function j(e){try{return pe(e)}catch{return[]}}function le(e){let t=0,r=[e];for(;r.length>0;){let n=r.pop();for(let i of pe(n,{withFileTypes:!0})){let s=h(n,i.name);i.isDirectory()?r.push(s):i.isFile()&&(t+=he(s).size)}}return t}export{ze as a,Ee as b,Je as c,Ke as d,xe as e,ae as f,Ye as g,Qe as h,lt as i,ut as j};
4
- //# sourceMappingURL=chunk-NEG77KKH.js.map
@@ -1,2 +0,0 @@
1
- import{b as r}from"./chunk-DV6B262O.js";import{x as e}from"./chunk-TDGCALH6.js";function l(t,s){let o=r(t,s);return e(t,o).map(({relativePath:n,...a})=>a)}export{l as a};
2
- //# sourceMappingURL=chunk-OYYZLJVT.js.map
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import{n as a}from"./chunk-MTFHE7ZO.js";import"./chunk-GBB2RUDN.js";export{a as directNavigationQueryCommandDescriptors};
3
- //# sourceMappingURL=direct-navigation-RKMPBXMI.js.map