gitnexus 1.6.10-rc.21 → 1.6.10-rc.211

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 (870) hide show
  1. package/README.md +212 -22
  2. package/dist/_shared/graph/types.d.ts +27 -8
  3. package/dist/_shared/graph/types.d.ts.map +1 -1
  4. package/dist/_shared/index.d.ts +4 -3
  5. package/dist/_shared/index.d.ts.map +1 -1
  6. package/dist/_shared/index.js +1 -1
  7. package/dist/_shared/index.js.map +1 -1
  8. package/dist/_shared/integrations/circuit-breaker.d.ts.map +1 -1
  9. package/dist/_shared/integrations/circuit-breaker.js.map +1 -1
  10. package/dist/_shared/integrations/resilient-fetch.d.ts +19 -1
  11. package/dist/_shared/integrations/resilient-fetch.d.ts.map +1 -1
  12. package/dist/_shared/integrations/resilient-fetch.js +23 -10
  13. package/dist/_shared/integrations/resilient-fetch.js.map +1 -1
  14. package/dist/_shared/language-detection.d.ts.map +1 -1
  15. package/dist/_shared/lbug/schema-constants.d.ts +2 -2
  16. package/dist/_shared/lbug/schema-constants.d.ts.map +1 -1
  17. package/dist/_shared/lbug/schema-constants.js +3 -0
  18. package/dist/_shared/lbug/schema-constants.js.map +1 -1
  19. package/dist/_shared/scope-resolution/callable-flow-site.d.ts +110 -0
  20. package/dist/_shared/scope-resolution/callable-flow-site.d.ts.map +1 -0
  21. package/dist/_shared/scope-resolution/callable-flow-site.js +11 -0
  22. package/dist/_shared/scope-resolution/callable-flow-site.js.map +1 -0
  23. package/dist/_shared/scope-resolution/evidence-weights.d.ts.map +1 -1
  24. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +6 -1
  25. package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -1
  26. package/dist/_shared/scope-resolution/finalize-algorithm.js +316 -37
  27. package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -1
  28. package/dist/_shared/scope-resolution/parsed-file.d.ts +7 -0
  29. package/dist/_shared/scope-resolution/parsed-file.d.ts.map +1 -1
  30. package/dist/_shared/scope-resolution/reference-site.d.ts +124 -1
  31. package/dist/_shared/scope-resolution/reference-site.d.ts.map +1 -1
  32. package/dist/_shared/scope-resolution/registries/field-registry.js.map +1 -1
  33. package/dist/_shared/scope-resolution/registries/lookup-core.d.ts.map +1 -1
  34. package/dist/_shared/scope-resolution/registries/lookup-core.js +58 -2
  35. package/dist/_shared/scope-resolution/registries/lookup-core.js.map +1 -1
  36. package/dist/_shared/scope-resolution/registries/method-registry.js.map +1 -1
  37. package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -1
  38. package/dist/_shared/scope-resolution/scope-tree.js.map +1 -1
  39. package/dist/_shared/scope-resolution/symbol-definition.d.ts +47 -0
  40. package/dist/_shared/scope-resolution/symbol-definition.d.ts.map +1 -1
  41. package/dist/_shared/scope-resolution/types.d.ts +297 -5
  42. package/dist/_shared/scope-resolution/types.d.ts.map +1 -1
  43. package/dist/cli/ai-context.d.ts +10 -2
  44. package/dist/cli/ai-context.js +128 -61
  45. package/dist/cli/analyze-config.d.ts +1 -1
  46. package/dist/cli/analyze-options.d.ts +131 -0
  47. package/dist/cli/analyze-options.js +1 -0
  48. package/dist/cli/analyze.d.ts +25 -114
  49. package/dist/cli/analyze.js +194 -36
  50. package/dist/cli/cli-message.d.ts +1 -1
  51. package/dist/cli/detect-changes-format.js +19 -2
  52. package/dist/cli/doctor.d.ts +23 -0
  53. package/dist/cli/doctor.js +72 -9
  54. package/dist/cli/editor-targets.js +6 -0
  55. package/dist/cli/eval-server.d.ts +23 -1
  56. package/dist/cli/eval-server.js +128 -9
  57. package/dist/cli/format-symbol.d.ts +15 -0
  58. package/dist/cli/format-symbol.js +17 -0
  59. package/dist/cli/generated-skill.d.ts +17 -0
  60. package/dist/cli/generated-skill.js +1 -0
  61. package/dist/cli/group.js +23 -2
  62. package/dist/cli/help-i18n.js +3 -0
  63. package/dist/cli/i18n/en.d.ts +17 -8
  64. package/dist/cli/i18n/en.js +19 -8
  65. package/dist/cli/i18n/resources.d.ts +26 -8
  66. package/dist/cli/i18n/zh-CN.d.ts +9 -0
  67. package/dist/cli/i18n/zh-CN.js +17 -8
  68. package/dist/cli/index.js +16 -9
  69. package/dist/cli/lazy-action.d.ts +7 -0
  70. package/dist/cli/lazy-action.js +27 -0
  71. package/dist/cli/mcp.js +6 -3
  72. package/dist/cli/resolve-invocation.d.ts +7 -3
  73. package/dist/cli/resolve-invocation.js +7 -3
  74. package/dist/cli/setup.d.ts +8 -0
  75. package/dist/cli/setup.js +30 -7
  76. package/dist/cli/skill-gen.d.ts +1 -6
  77. package/dist/cli/skill-gen.js +88 -18
  78. package/dist/cli/standard-skills.d.ts +76 -0
  79. package/dist/cli/standard-skills.js +45 -0
  80. package/dist/cli/status.d.ts +4 -1
  81. package/dist/cli/status.js +57 -4
  82. package/dist/cli/tool.d.ts +1 -0
  83. package/dist/cli/tool.js +75 -7
  84. package/dist/cli/uninstall.js +7 -2
  85. package/dist/cli/wiki.d.ts +1 -0
  86. package/dist/cli/wiki.js +59 -10
  87. package/dist/config/ignore-service.d.ts +2 -0
  88. package/dist/config/ignore-service.js +31 -4
  89. package/dist/core/analysis-features.d.ts +21 -0
  90. package/dist/core/analysis-features.js +59 -0
  91. package/dist/core/analyzer-identity.d.ts +154 -0
  92. package/dist/core/analyzer-identity.js +2158 -0
  93. package/dist/core/augmentation/engine.js +95 -76
  94. package/dist/core/embedding-checkpoint.d.ts +143 -0
  95. package/dist/core/embedding-checkpoint.js +221 -0
  96. package/dist/core/embedding-count.d.ts +61 -0
  97. package/dist/core/embedding-count.js +69 -0
  98. package/dist/core/embeddings/ast-utils.js +9 -1
  99. package/dist/core/embeddings/embedder.d.ts +3 -2
  100. package/dist/core/embeddings/embedder.js +8 -5
  101. package/dist/core/embeddings/embedding-identity.d.ts +11 -0
  102. package/dist/core/embeddings/embedding-identity.js +24 -0
  103. package/dist/core/embeddings/embedding-pipeline.d.ts +24 -1
  104. package/dist/core/embeddings/embedding-pipeline.js +341 -19
  105. package/dist/core/embeddings/http-client.d.ts +10 -2
  106. package/dist/core/embeddings/http-client.js +282 -47
  107. package/dist/core/embeddings/node-module-compat.d.ts +4 -2
  108. package/dist/core/embeddings/node-module-compat.js +4 -2
  109. package/dist/core/embeddings/onnxruntime-common-resolver.js +5 -5
  110. package/dist/core/embeddings/onnxruntime-node-resolver.js +2 -2
  111. package/dist/core/embeddings/runtime-install.js +1 -1
  112. package/dist/core/git-staleness.js +1 -1
  113. package/dist/core/graph/graph.js +3 -0
  114. package/dist/core/graph/import-cycles.d.ts +194 -3
  115. package/dist/core/graph/import-cycles.js +522 -73
  116. package/dist/core/graph/types.d.ts +18 -0
  117. package/dist/core/group/bridge-db.js +5 -27
  118. package/dist/core/group/cross-impact.d.ts +21 -0
  119. package/dist/core/group/cross-impact.js +128 -15
  120. package/dist/core/group/cross-trace.js +27 -16
  121. package/dist/core/group/extractors/http-patterns/java.js +91 -14
  122. package/dist/core/group/extractors/http-patterns/node.js +19 -0
  123. package/dist/core/group/extractors/http-patterns/types.d.ts +8 -0
  124. package/dist/core/group/extractors/http-route-extractor.d.ts +1 -0
  125. package/dist/core/group/extractors/http-route-extractor.js +122 -48
  126. package/dist/core/group/extractors/include-extractor.js +20 -2
  127. package/dist/core/group/extractors/manifest-extractor.d.ts +1 -1
  128. package/dist/core/group/extractors/manifest-extractor.js +7 -7
  129. package/dist/core/group/service.js +10 -1
  130. package/dist/core/group/storage.js +2 -33
  131. package/dist/core/group/types.d.ts +18 -0
  132. package/dist/core/incremental/subgraph-extract.d.ts +9 -6
  133. package/dist/core/incremental/subgraph-extract.js +33 -10
  134. package/dist/core/index-freshness.d.ts +80 -0
  135. package/dist/core/index-freshness.js +120 -0
  136. package/dist/core/ingestion/call-processor.d.ts +13 -1
  137. package/dist/core/ingestion/call-processor.js +110 -3
  138. package/dist/core/ingestion/cfg/callee-cell-format.d.ts +42 -0
  139. package/dist/core/ingestion/cfg/callee-cell-format.js +42 -0
  140. package/dist/core/ingestion/cfg/emit.d.ts +8 -23
  141. package/dist/core/ingestion/cfg/emit.js +9 -23
  142. package/dist/core/ingestion/class-extractors/configs/go.js +10 -5
  143. package/dist/core/ingestion/class-extractors/configs/jvm.js +29 -0
  144. package/dist/core/ingestion/cluster-enricher.js +8 -4
  145. package/dist/core/ingestion/cobol/cobol-preprocessor.js +1 -1
  146. package/dist/core/ingestion/community-processor.d.ts +21 -3
  147. package/dist/core/ingestion/community-processor.js +88 -83
  148. package/dist/core/ingestion/di-extractors/index.d.ts +22 -34
  149. package/dist/core/ingestion/di-extractors/index.js +17 -18
  150. package/dist/core/ingestion/di-extractors/spring.d.ts +27 -5
  151. package/dist/core/ingestion/di-extractors/spring.js +87 -3
  152. package/dist/core/ingestion/di-extractors/types.d.ts +60 -0
  153. package/dist/core/ingestion/di-extractors/types.js +15 -0
  154. package/dist/core/ingestion/emit-references.js +4 -0
  155. package/dist/core/ingestion/filesystem-walker.js +16 -12
  156. package/dist/core/ingestion/finalize-orchestrator.js +1 -0
  157. package/dist/core/ingestion/frameworks/spring/analysis-features.d.ts +9 -0
  158. package/dist/core/ingestion/frameworks/spring/analysis-features.js +41 -0
  159. package/dist/core/ingestion/frameworks/spring/annotation-arguments.d.ts +13 -0
  160. package/dist/core/ingestion/frameworks/spring/annotation-arguments.js +227 -0
  161. package/dist/core/ingestion/frameworks/spring/aop-candidates.d.ts +15 -0
  162. package/dist/core/ingestion/frameworks/spring/aop-candidates.js +85 -0
  163. package/dist/core/ingestion/frameworks/spring/aop.d.ts +118 -0
  164. package/dist/core/ingestion/frameworks/spring/aop.js +476 -0
  165. package/dist/core/ingestion/frameworks/spring/auto-configuration.d.ts +8 -0
  166. package/dist/core/ingestion/frameworks/spring/auto-configuration.js +16 -0
  167. package/dist/core/ingestion/frameworks/spring/bean-candidates.d.ts +30 -0
  168. package/dist/core/ingestion/frameworks/spring/bean-candidates.js +182 -0
  169. package/dist/core/ingestion/frameworks/spring/bean-catalog.d.ts +12 -0
  170. package/dist/core/ingestion/frameworks/spring/bean-catalog.js +27 -0
  171. package/dist/core/ingestion/frameworks/spring/bean-factories.d.ts +33 -0
  172. package/dist/core/ingestion/frameworks/spring/bean-factories.js +65 -0
  173. package/dist/core/ingestion/frameworks/spring/conditionals.d.ts +25 -0
  174. package/dist/core/ingestion/frameworks/spring/conditionals.js +319 -0
  175. package/dist/core/ingestion/frameworks/spring/config-bindings.d.ts +24 -0
  176. package/dist/core/ingestion/frameworks/spring/config-bindings.js +115 -0
  177. package/dist/core/ingestion/frameworks/spring/di-metadata.d.ts +48 -0
  178. package/dist/core/ingestion/frameworks/spring/di-metadata.js +379 -0
  179. package/dist/core/ingestion/frameworks/spring/non-http-handlers.d.ts +28 -0
  180. package/dist/core/ingestion/frameworks/spring/non-http-handlers.js +152 -0
  181. package/dist/core/ingestion/frameworks/spring/resource-injection.d.ts +5 -0
  182. package/dist/core/ingestion/frameworks/spring/resource-injection.js +91 -0
  183. package/dist/core/ingestion/import-resolvers/configs/csharp.js +5 -1
  184. package/dist/core/ingestion/import-resolvers/configs/swift.js +13 -0
  185. package/dist/core/ingestion/import-resolvers/csharp.d.ts +9 -1
  186. package/dist/core/ingestion/import-resolvers/csharp.js +234 -27
  187. package/dist/core/ingestion/import-resolvers/go.d.ts +11 -1
  188. package/dist/core/ingestion/import-resolvers/go.js +44 -17
  189. package/dist/core/ingestion/import-resolvers/jvm.d.ts +2 -2
  190. package/dist/core/ingestion/import-resolvers/node-workspace-packages.d.ts +90 -0
  191. package/dist/core/ingestion/import-resolvers/node-workspace-packages.js +428 -0
  192. package/dist/core/ingestion/import-resolvers/package-dir-index.d.ts +124 -0
  193. package/dist/core/ingestion/import-resolvers/package-dir-index.js +223 -0
  194. package/dist/core/ingestion/import-resolvers/pass-cache.d.ts +50 -0
  195. package/dist/core/ingestion/import-resolvers/pass-cache.js +60 -0
  196. package/dist/core/ingestion/import-resolvers/per-file-set.d.ts +71 -0
  197. package/dist/core/ingestion/import-resolvers/per-file-set.js +11 -0
  198. package/dist/core/ingestion/import-resolvers/php.d.ts +1 -1
  199. package/dist/core/ingestion/import-resolvers/php.js +27 -8
  200. package/dist/core/ingestion/import-resolvers/python-file-index.d.ts +201 -0
  201. package/dist/core/ingestion/import-resolvers/python-file-index.js +302 -0
  202. package/dist/core/ingestion/import-resolvers/python.js +25 -6
  203. package/dist/core/ingestion/import-resolvers/ruby.d.ts +1 -1
  204. package/dist/core/ingestion/import-resolvers/rust.d.ts +2 -2
  205. package/dist/core/ingestion/import-resolvers/standard.d.ts +1 -1
  206. package/dist/core/ingestion/import-resolvers/types.d.ts +1 -12
  207. package/dist/core/ingestion/import-resolvers/utils.d.ts +65 -6
  208. package/dist/core/ingestion/import-resolvers/utils.js +215 -36
  209. package/dist/core/ingestion/import-resolvers/workspace-file-index.d.ts +72 -0
  210. package/dist/core/ingestion/import-resolvers/workspace-file-index.js +58 -0
  211. package/dist/core/ingestion/language-config.d.ts +20 -1
  212. package/dist/core/ingestion/language-config.js +18 -23
  213. package/dist/core/ingestion/language-provider.d.ts +133 -7
  214. package/dist/core/ingestion/languages/c/captures.js +63 -0
  215. package/dist/core/ingestion/languages/c/import-target.js +12 -16
  216. package/dist/core/ingestion/languages/c/query.js +17 -0
  217. package/dist/core/ingestion/languages/c/scope-resolver.js +26 -19
  218. package/dist/core/ingestion/languages/c/static-linkage.js +12 -16
  219. package/dist/core/ingestion/languages/c-cpp.js +13 -0
  220. package/dist/core/ingestion/languages/cobol/captures.js +93 -0
  221. package/dist/core/ingestion/languages/cobol/scope-resolver.js +34 -20
  222. package/dist/core/ingestion/languages/cobol.js +13 -0
  223. package/dist/core/ingestion/languages/cpp/adl.d.ts +2 -2
  224. package/dist/core/ingestion/languages/cpp/adl.js +67 -44
  225. package/dist/core/ingestion/languages/cpp/captures.js +222 -3
  226. package/dist/core/ingestion/languages/cpp/file-local-linkage.js +11 -15
  227. package/dist/core/ingestion/languages/cpp/inline-namespaces.d.ts +28 -8
  228. package/dist/core/ingestion/languages/cpp/inline-namespaces.js +242 -68
  229. package/dist/core/ingestion/languages/cpp/interpret.d.ts +2 -0
  230. package/dist/core/ingestion/languages/cpp/interpret.js +126 -6
  231. package/dist/core/ingestion/languages/cpp/query.js +106 -0
  232. package/dist/core/ingestion/languages/cpp/scope-resolver.js +62 -20
  233. package/dist/core/ingestion/languages/csharp/accessor-unwrap.d.ts +2 -15
  234. package/dist/core/ingestion/languages/csharp/accessor-unwrap.js +18 -10
  235. package/dist/core/ingestion/languages/csharp/captures.js +44 -0
  236. package/dist/core/ingestion/languages/csharp/import-target.js +46 -72
  237. package/dist/core/ingestion/languages/csharp/namespace-siblings.js +5 -1
  238. package/dist/core/ingestion/languages/csharp/query.js +25 -5
  239. package/dist/core/ingestion/languages/csharp/scope-resolver.js +75 -2
  240. package/dist/core/ingestion/languages/dart/captures.d.ts +10 -0
  241. package/dist/core/ingestion/languages/dart/captures.js +686 -16
  242. package/dist/core/ingestion/languages/dart/extension-type-preprocess.d.ts +7 -0
  243. package/dist/core/ingestion/languages/dart/extension-type-preprocess.js +30 -0
  244. package/dist/core/ingestion/languages/dart/import-target.js +32 -9
  245. package/dist/core/ingestion/languages/dart/index.d.ts +1 -1
  246. package/dist/core/ingestion/languages/dart/index.js +1 -1
  247. package/dist/core/ingestion/languages/dart/query.js +98 -1
  248. package/dist/core/ingestion/languages/dart/scope-resolver.js +14 -3
  249. package/dist/core/ingestion/languages/dart/simple-hooks.js +9 -0
  250. package/dist/core/ingestion/languages/dart.js +8 -1
  251. package/dist/core/ingestion/languages/go/captures.js +142 -3
  252. package/dist/core/ingestion/languages/go/generic-type-parameters.d.ts +31 -0
  253. package/dist/core/ingestion/languages/go/generic-type-parameters.js +140 -0
  254. package/dist/core/ingestion/languages/go/import-target.d.ts +3 -10
  255. package/dist/core/ingestion/languages/go/import-target.js +34 -30
  256. package/dist/core/ingestion/languages/go/index.d.ts +1 -1
  257. package/dist/core/ingestion/languages/go/interface-impls.d.ts +9 -1
  258. package/dist/core/ingestion/languages/go/interface-impls.js +693 -87
  259. package/dist/core/ingestion/languages/go/interpret.d.ts +2 -0
  260. package/dist/core/ingestion/languages/go/interpret.js +22 -8
  261. package/dist/core/ingestion/languages/go/method-owners.js +31 -12
  262. package/dist/core/ingestion/languages/go/package-clause.d.ts +46 -0
  263. package/dist/core/ingestion/languages/go/package-clause.js +75 -0
  264. package/dist/core/ingestion/languages/go/package-siblings.js +7 -11
  265. package/dist/core/ingestion/languages/go/query.js +56 -3
  266. package/dist/core/ingestion/languages/go/scope-resolver.js +39 -0
  267. package/dist/core/ingestion/languages/go.js +9 -0
  268. package/dist/core/ingestion/languages/java/analysis-features.d.ts +7 -0
  269. package/dist/core/ingestion/languages/java/analysis-features.js +25 -0
  270. package/dist/core/ingestion/languages/java/capture-side-channel.d.ts +38 -0
  271. package/dist/core/ingestion/languages/java/capture-side-channel.js +124 -0
  272. package/dist/core/ingestion/languages/java/captures.d.ts +4 -3
  273. package/dist/core/ingestion/languages/java/captures.js +321 -49
  274. package/dist/core/ingestion/languages/java/import-target.d.ts +49 -9
  275. package/dist/core/ingestion/languages/java/import-target.js +68 -88
  276. package/dist/core/ingestion/languages/java/interpret.js +3 -2
  277. package/dist/core/ingestion/languages/java/module-resolution.d.ts +62 -0
  278. package/dist/core/ingestion/languages/java/module-resolution.js +142 -0
  279. package/dist/core/ingestion/languages/java/package-facts.d.ts +5 -0
  280. package/dist/core/ingestion/languages/java/package-facts.js +9 -0
  281. package/dist/core/ingestion/languages/java/package-siblings.d.ts +3 -16
  282. package/dist/core/ingestion/languages/java/package-siblings.js +8 -147
  283. package/dist/core/ingestion/languages/java/query.js +39 -3
  284. package/dist/core/ingestion/languages/java/record-components.d.ts +14 -0
  285. package/dist/core/ingestion/languages/java/record-components.js +185 -0
  286. package/dist/core/ingestion/languages/java/scope-resolver.js +35 -2
  287. package/dist/core/ingestion/languages/java/spring-aop.d.ts +12 -0
  288. package/dist/core/ingestion/languages/java/spring-aop.js +49 -0
  289. package/dist/core/ingestion/languages/java/spring-bean-metadata.d.ts +2 -0
  290. package/dist/core/ingestion/languages/java/spring-bean-metadata.js +8 -0
  291. package/dist/core/ingestion/languages/java/spring-conditionals.d.ts +11 -0
  292. package/dist/core/ingestion/languages/java/spring-conditionals.js +48 -0
  293. package/dist/core/ingestion/languages/java/spring-config-bindings.d.ts +23 -0
  294. package/dist/core/ingestion/languages/java/spring-config-bindings.js +215 -0
  295. package/dist/core/ingestion/languages/java/spring-di.d.ts +20 -0
  296. package/dist/core/ingestion/languages/java/spring-di.js +160 -0
  297. package/dist/core/ingestion/languages/java/spring-non-http-handlers.d.ts +7 -0
  298. package/dist/core/ingestion/languages/java/spring-non-http-handlers.js +32 -0
  299. package/dist/core/ingestion/languages/java.js +76 -3
  300. package/dist/core/ingestion/languages/javascript/captures.d.ts +6 -1
  301. package/dist/core/ingestion/languages/javascript/captures.js +278 -4
  302. package/dist/core/ingestion/languages/javascript/import-target.d.ts +17 -21
  303. package/dist/core/ingestion/languages/javascript/import-target.js +24 -41
  304. package/dist/core/ingestion/languages/javascript/index.d.ts +54 -5
  305. package/dist/core/ingestion/languages/javascript/index.js +54 -5
  306. package/dist/core/ingestion/languages/javascript/query.d.ts +1 -0
  307. package/dist/core/ingestion/languages/javascript/query.js +232 -5
  308. package/dist/core/ingestion/languages/javascript/scope-resolver.js +12 -0
  309. package/dist/core/ingestion/languages/javascript/simple-hooks.js +2 -1
  310. package/dist/core/ingestion/languages/jvm/package-facts.d.ts +35 -0
  311. package/dist/core/ingestion/languages/jvm/package-facts.js +40 -0
  312. package/dist/core/ingestion/languages/jvm/package-siblings.d.ts +14 -0
  313. package/dist/core/ingestion/languages/jvm/package-siblings.js +197 -0
  314. package/dist/core/ingestion/languages/kotlin/capture-side-channel.d.ts +40 -3
  315. package/dist/core/ingestion/languages/kotlin/capture-side-channel.js +111 -8
  316. package/dist/core/ingestion/languages/kotlin/captures.js +112 -0
  317. package/dist/core/ingestion/languages/kotlin/import-target.d.ts +8 -1
  318. package/dist/core/ingestion/languages/kotlin/import-target.js +20 -123
  319. package/dist/core/ingestion/languages/kotlin/index.d.ts +1 -0
  320. package/dist/core/ingestion/languages/kotlin/index.js +1 -0
  321. package/dist/core/ingestion/languages/kotlin/module-resolution.d.ts +22 -0
  322. package/dist/core/ingestion/languages/kotlin/module-resolution.js +108 -0
  323. package/dist/core/ingestion/languages/kotlin/package-facts.d.ts +5 -0
  324. package/dist/core/ingestion/languages/kotlin/package-facts.js +9 -0
  325. package/dist/core/ingestion/languages/kotlin/package-siblings.d.ts +4 -0
  326. package/dist/core/ingestion/languages/kotlin/package-siblings.js +8 -0
  327. package/dist/core/ingestion/languages/kotlin/query.js +47 -2
  328. package/dist/core/ingestion/languages/kotlin/scope-resolver.js +36 -3
  329. package/dist/core/ingestion/languages/kotlin/spring-aop.d.ts +12 -0
  330. package/dist/core/ingestion/languages/kotlin/spring-aop.js +64 -0
  331. package/dist/core/ingestion/languages/kotlin/spring-bean-metadata.d.ts +2 -0
  332. package/dist/core/ingestion/languages/kotlin/spring-bean-metadata.js +8 -0
  333. package/dist/core/ingestion/languages/kotlin/spring-conditionals.d.ts +12 -0
  334. package/dist/core/ingestion/languages/kotlin/spring-conditionals.js +49 -0
  335. package/dist/core/ingestion/languages/kotlin/spring-di.d.ts +20 -0
  336. package/dist/core/ingestion/languages/kotlin/spring-di.js +299 -0
  337. package/dist/core/ingestion/languages/kotlin/spring-non-http-handlers.d.ts +10 -0
  338. package/dist/core/ingestion/languages/kotlin/spring-non-http-handlers.js +41 -0
  339. package/dist/core/ingestion/languages/kotlin.js +5 -6
  340. package/dist/core/ingestion/languages/php/captures.d.ts +5 -0
  341. package/dist/core/ingestion/languages/php/captures.js +359 -51
  342. package/dist/core/ingestion/languages/php/import-decomposer.js +12 -0
  343. package/dist/core/ingestion/languages/php/import-target.d.ts +2 -1
  344. package/dist/core/ingestion/languages/php/import-target.js +229 -7
  345. package/dist/core/ingestion/languages/php/interpret.js +10 -0
  346. package/dist/core/ingestion/languages/php/query.js +31 -0
  347. package/dist/core/ingestion/languages/php/scope-resolver.js +1 -1
  348. package/dist/core/ingestion/languages/python/arity-metadata.d.ts +1 -0
  349. package/dist/core/ingestion/languages/python/arity-metadata.js +1 -0
  350. package/dist/core/ingestion/languages/python/captures.d.ts +3 -4
  351. package/dist/core/ingestion/languages/python/captures.js +53 -5
  352. package/dist/core/ingestion/languages/python/import-decomposer.js +22 -1
  353. package/dist/core/ingestion/languages/python/import-target.d.ts +42 -1
  354. package/dist/core/ingestion/languages/python/import-target.js +277 -91
  355. package/dist/core/ingestion/languages/python/index.d.ts +1 -1
  356. package/dist/core/ingestion/languages/python/index.js +1 -1
  357. package/dist/core/ingestion/languages/python/interpret.d.ts +52 -0
  358. package/dist/core/ingestion/languages/python/interpret.js +249 -3
  359. package/dist/core/ingestion/languages/python/query.js +9 -0
  360. package/dist/core/ingestion/languages/python/receiver-binding.d.ts +17 -2
  361. package/dist/core/ingestion/languages/python/receiver-binding.js +192 -2
  362. package/dist/core/ingestion/languages/python/scope-resolver.js +27 -4
  363. package/dist/core/ingestion/languages/python/simple-hooks.d.ts +5 -5
  364. package/dist/core/ingestion/languages/python/simple-hooks.js +9 -5
  365. package/dist/core/ingestion/languages/ruby/captures.js +200 -0
  366. package/dist/core/ingestion/languages/ruby/import-target.js +7 -5
  367. package/dist/core/ingestion/languages/ruby/query.js +93 -0
  368. package/dist/core/ingestion/languages/ruby/scope-resolver.js +2 -0
  369. package/dist/core/ingestion/languages/ruby/simple-hooks.d.ts +1 -1
  370. package/dist/core/ingestion/languages/ruby/simple-hooks.js +22 -1
  371. package/dist/core/ingestion/languages/rust/captures.js +52 -1
  372. package/dist/core/ingestion/languages/rust/interpret.js +18 -0
  373. package/dist/core/ingestion/languages/rust/method-owners.js +11 -1
  374. package/dist/core/ingestion/languages/rust/module-path.d.ts +126 -0
  375. package/dist/core/ingestion/languages/rust/module-path.js +214 -0
  376. package/dist/core/ingestion/languages/rust/qualified-call.d.ts +41 -0
  377. package/dist/core/ingestion/languages/rust/qualified-call.js +481 -0
  378. package/dist/core/ingestion/languages/rust/query.js +48 -6
  379. package/dist/core/ingestion/languages/rust/range-binding.d.ts +1 -11
  380. package/dist/core/ingestion/languages/rust/range-binding.js +149 -63
  381. package/dist/core/ingestion/languages/rust/scope-resolver.js +21 -2
  382. package/dist/core/ingestion/languages/rust.js +17 -0
  383. package/dist/core/ingestion/languages/swift/captures.js +99 -3
  384. package/dist/core/ingestion/languages/swift/conditional-directive-preprocess.d.ts +48 -0
  385. package/dist/core/ingestion/languages/swift/conditional-directive-preprocess.js +253 -0
  386. package/dist/core/ingestion/languages/swift/import-target.js +4 -9
  387. package/dist/core/ingestion/languages/swift/query.js +17 -0
  388. package/dist/core/ingestion/languages/swift/receiver-binding.d.ts +8 -0
  389. package/dist/core/ingestion/languages/swift/receiver-binding.js +6 -2
  390. package/dist/core/ingestion/languages/swift.js +2 -0
  391. package/dist/core/ingestion/languages/typescript/captures.d.ts +90 -1
  392. package/dist/core/ingestion/languages/typescript/captures.js +288 -5
  393. package/dist/core/ingestion/languages/typescript/cjs-export-assignment.d.ts +134 -0
  394. package/dist/core/ingestion/languages/typescript/cjs-export-assignment.js +523 -0
  395. package/dist/core/ingestion/languages/typescript/cjs-module-exports.d.ts +54 -0
  396. package/dist/core/ingestion/languages/typescript/cjs-module-exports.js +191 -0
  397. package/dist/core/ingestion/languages/typescript/file-candidates.d.ts +29 -0
  398. package/dist/core/ingestion/languages/typescript/file-candidates.js +70 -0
  399. package/dist/core/ingestion/languages/typescript/import-decomposer.d.ts +28 -1
  400. package/dist/core/ingestion/languages/typescript/import-decomposer.js +125 -10
  401. package/dist/core/ingestion/languages/typescript/import-target.d.ts +25 -37
  402. package/dist/core/ingestion/languages/typescript/import-target.js +24 -26
  403. package/dist/core/ingestion/languages/typescript/interpret.d.ts +21 -1
  404. package/dist/core/ingestion/languages/typescript/interpret.js +45 -5
  405. package/dist/core/ingestion/languages/typescript/module-resolution.d.ts +48 -0
  406. package/dist/core/ingestion/languages/typescript/module-resolution.js +171 -0
  407. package/dist/core/ingestion/languages/typescript/nuxt-auto-imports.js +2 -1
  408. package/dist/core/ingestion/languages/typescript/query.d.ts +1 -0
  409. package/dist/core/ingestion/languages/typescript/query.js +340 -14
  410. package/dist/core/ingestion/languages/typescript/receiver-binding.d.ts +17 -0
  411. package/dist/core/ingestion/languages/typescript/receiver-binding.js +27 -0
  412. package/dist/core/ingestion/languages/typescript/scope-resolver.js +27 -40
  413. package/dist/core/ingestion/languages/typescript/simple-hooks.d.ts +0 -10
  414. package/dist/core/ingestion/languages/typescript/simple-hooks.js +22 -22
  415. package/dist/core/ingestion/languages/typescript/tsconfig.d.ts +59 -0
  416. package/dist/core/ingestion/languages/typescript/tsconfig.js +291 -0
  417. package/dist/core/ingestion/languages/typescript.js +87 -1
  418. package/dist/core/ingestion/languages/vue/import-target.d.ts +6 -22
  419. package/dist/core/ingestion/languages/vue/import-target.js +11 -47
  420. package/dist/core/ingestion/languages/vue/scope-resolver.js +4 -2
  421. package/dist/core/ingestion/local-symbol-pruner.js +11 -11
  422. package/dist/core/ingestion/method-extractors/configs/csharp.js +1 -0
  423. package/dist/core/ingestion/method-extractors/generic.js +1 -0
  424. package/dist/core/ingestion/method-types.d.ts +16 -0
  425. package/dist/core/ingestion/parsing-processor.js +32 -1
  426. package/dist/core/ingestion/pipeline-phases/di.d.ts +8 -33
  427. package/dist/core/ingestion/pipeline-phases/di.js +275 -157
  428. package/dist/core/ingestion/pipeline-phases/index.d.ts +3 -0
  429. package/dist/core/ingestion/pipeline-phases/index.js +3 -0
  430. package/dist/core/ingestion/pipeline-phases/parse-impl.d.ts +15 -0
  431. package/dist/core/ingestion/pipeline-phases/parse-impl.js +158 -3
  432. package/dist/core/ingestion/pipeline-phases/parse.js +5 -0
  433. package/dist/core/ingestion/pipeline-phases/processes.d.ts +11 -2
  434. package/dist/core/ingestion/pipeline-phases/processes.js +102 -7
  435. package/dist/core/ingestion/pipeline-phases/routes.js +56 -10
  436. package/dist/core/ingestion/pipeline-phases/spring-aop.d.ts +34 -0
  437. package/dist/core/ingestion/pipeline-phases/spring-aop.js +439 -0
  438. package/dist/core/ingestion/pipeline-phases/spring-auto-configuration.d.ts +34 -0
  439. package/dist/core/ingestion/pipeline-phases/spring-auto-configuration.js +255 -0
  440. package/dist/core/ingestion/pipeline-phases/spring-config.d.ts +37 -0
  441. package/dist/core/ingestion/pipeline-phases/spring-config.js +433 -0
  442. package/dist/core/ingestion/pipeline-phases/types.d.ts +7 -0
  443. package/dist/core/ingestion/pipeline.d.ts +27 -3
  444. package/dist/core/ingestion/pipeline.js +62 -12
  445. package/dist/core/ingestion/process-processor.d.ts +109 -2
  446. package/dist/core/ingestion/process-processor.js +464 -52
  447. package/dist/core/ingestion/resolve-references.d.ts +6 -1
  448. package/dist/core/ingestion/resolve-references.js +78 -6
  449. package/dist/core/ingestion/route-extractors/data-route-table.d.ts +25 -0
  450. package/dist/core/ingestion/route-extractors/data-route-table.js +864 -0
  451. package/dist/core/ingestion/route-extractors/dispatch-guard.d.ts +96 -0
  452. package/dist/core/ingestion/route-extractors/dispatch-guard.js +1184 -0
  453. package/dist/core/ingestion/route-extractors/spring-shared.d.ts +11 -0
  454. package/dist/core/ingestion/route-extractors/spring-shared.js +89 -0
  455. package/dist/core/ingestion/route-extractors/spring.js +109 -24
  456. package/dist/core/ingestion/scope-extractor-bridge.js +9 -1
  457. package/dist/core/ingestion/scope-extractor.d.ts +22 -7
  458. package/dist/core/ingestion/scope-extractor.js +617 -59
  459. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.d.ts +381 -22
  460. package/dist/core/ingestion/scope-resolution/contract/scope-resolver.js +16 -5
  461. package/dist/core/ingestion/scope-resolution/graph-bridge/callee-id-sink.d.ts +7 -7
  462. package/dist/core/ingestion/scope-resolution/graph-bridge/callee-id-sink.js +8 -7
  463. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.d.ts +15 -1
  464. package/dist/core/ingestion/scope-resolution/graph-bridge/edges.js +53 -0
  465. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.d.ts +20 -15
  466. package/dist/core/ingestion/scope-resolution/graph-bridge/ids.js +275 -41
  467. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.d.ts +123 -0
  468. package/dist/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.js +171 -17
  469. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.d.ts +56 -1
  470. package/dist/core/ingestion/scope-resolution/graph-bridge/node-lookup.js +130 -32
  471. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.d.ts +30 -1
  472. package/dist/core/ingestion/scope-resolution/graph-bridge/references-to-edges.js +46 -3
  473. package/dist/core/ingestion/scope-resolution/passes/callable-value-flow.d.ts +64 -0
  474. package/dist/core/ingestion/scope-resolution/passes/callable-value-flow.js +1233 -0
  475. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.d.ts +107 -5
  476. package/dist/core/ingestion/scope-resolution/passes/compound-receiver.js +590 -33
  477. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.d.ts +19 -4
  478. package/dist/core/ingestion/scope-resolution/passes/free-call-fallback.js +160 -4
  479. package/dist/core/ingestion/scope-resolution/passes/imported-value-refs.d.ts +34 -0
  480. package/dist/core/ingestion/scope-resolution/passes/imported-value-refs.js +62 -0
  481. package/dist/core/ingestion/scope-resolution/passes/property-dispatch.d.ts +64 -0
  482. package/dist/core/ingestion/scope-resolution/passes/property-dispatch.js +118 -0
  483. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.d.ts +109 -8
  484. package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +931 -92
  485. package/dist/core/ingestion/scope-resolution/passes/return-shape-members.d.ts +58 -0
  486. package/dist/core/ingestion/scope-resolution/passes/return-shape-members.js +458 -0
  487. package/dist/core/ingestion/scope-resolution/passes/unique-name-properties.d.ts +180 -0
  488. package/dist/core/ingestion/scope-resolution/passes/unique-name-properties.js +418 -0
  489. package/dist/core/ingestion/scope-resolution/pipeline/phase.d.ts +34 -0
  490. package/dist/core/ingestion/scope-resolution/pipeline/phase.js +82 -38
  491. package/dist/core/ingestion/scope-resolution/pipeline/run.d.ts +61 -1
  492. package/dist/core/ingestion/scope-resolution/pipeline/run.js +384 -48
  493. package/dist/core/ingestion/scope-resolution/resolution-outcome.d.ts +112 -2
  494. package/dist/core/ingestion/scope-resolution/resolution-outcome.js +38 -1
  495. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.d.ts +25 -3
  496. package/dist/core/ingestion/scope-resolution/scope/namespace-targets.js +36 -16
  497. package/dist/core/ingestion/scope-resolution/scope/walkers.d.ts +210 -9
  498. package/dist/core/ingestion/scope-resolution/scope/walkers.js +968 -56
  499. package/dist/core/ingestion/scope-resolution/summary-maps.d.ts +28 -0
  500. package/dist/core/ingestion/scope-resolution/summary-maps.js +50 -0
  501. package/dist/core/ingestion/scope-resolution/undecided-satisfaction.d.ts +55 -0
  502. package/dist/core/ingestion/scope-resolution/undecided-satisfaction.js +37 -0
  503. package/dist/core/ingestion/scope-resolution/unresolved-receivers.d.ts +109 -0
  504. package/dist/core/ingestion/scope-resolution/unresolved-receivers.js +204 -0
  505. package/dist/core/ingestion/scope-resolution/utils/definition-id.d.ts +13 -0
  506. package/dist/core/ingestion/scope-resolution/utils/definition-id.js +19 -0
  507. package/dist/core/ingestion/scope-resolution/utils/generic-instantiation.d.ts +171 -0
  508. package/dist/core/ingestion/scope-resolution/utils/generic-instantiation.js +218 -0
  509. package/dist/core/ingestion/scope-resolution/workspace-index-types.d.ts +34 -0
  510. package/dist/core/ingestion/scope-resolution/workspace-index-types.js +15 -0
  511. package/dist/core/ingestion/scope-resolution/workspace-index.d.ts +7 -20
  512. package/dist/core/ingestion/taint/typescript-model.js +34 -2
  513. package/dist/core/ingestion/tree-sitter-queries.d.ts +11 -11
  514. package/dist/core/ingestion/tree-sitter-queries.js +688 -5
  515. package/dist/core/ingestion/type-env.js +11 -7
  516. package/dist/core/ingestion/type-extractors/jvm.js +17 -2
  517. package/dist/core/ingestion/type-extractors/shared.d.ts +17 -0
  518. package/dist/core/ingestion/type-extractors/shared.js +16 -0
  519. package/dist/core/ingestion/type-extractors/types.d.ts +12 -0
  520. package/dist/core/ingestion/type-extractors/typescript.d.ts +20 -0
  521. package/dist/core/ingestion/type-extractors/typescript.js +26 -0
  522. package/dist/core/ingestion/utils/ast-helpers.d.ts +311 -14
  523. package/dist/core/ingestion/utils/ast-helpers.js +745 -48
  524. package/dist/core/ingestion/utils/call-analysis.d.ts +27 -22
  525. package/dist/core/ingestion/utils/call-analysis.js +202 -7
  526. package/dist/core/ingestion/utils/callable-flow-captures.d.ts +153 -0
  527. package/dist/core/ingestion/utils/callable-flow-captures.js +928 -0
  528. package/dist/core/ingestion/utils/callable-labels.d.ts +25 -0
  529. package/dist/core/ingestion/utils/callable-labels.js +31 -0
  530. package/dist/core/ingestion/utils/effective-ram.d.ts +40 -0
  531. package/dist/core/ingestion/utils/effective-ram.js +58 -0
  532. package/dist/core/ingestion/utils/line-base.d.ts +14 -0
  533. package/dist/core/ingestion/utils/line-base.js +14 -0
  534. package/dist/core/ingestion/utils/method-props.d.ts +27 -4
  535. package/dist/core/ingestion/utils/method-props.js +29 -4
  536. package/dist/core/ingestion/utils/receiver-chain-captures.d.ts +31 -0
  537. package/dist/core/ingestion/utils/receiver-chain-captures.js +57 -0
  538. package/dist/core/ingestion/utils/receiver-chain-codec.d.ts +89 -0
  539. package/dist/core/ingestion/utils/receiver-chain-codec.js +182 -0
  540. package/dist/core/ingestion/utils/scope-tree-walk.d.ts +22 -0
  541. package/dist/core/ingestion/utils/scope-tree-walk.js +33 -0
  542. package/dist/core/ingestion/utils/template-arguments.d.ts +96 -0
  543. package/dist/core/ingestion/utils/template-arguments.js +196 -0
  544. package/dist/core/ingestion/utils/type-parameters.d.ts +49 -0
  545. package/dist/core/ingestion/utils/type-parameters.js +206 -0
  546. package/dist/core/ingestion/workers/callable-id.d.ts +72 -0
  547. package/dist/core/ingestion/workers/callable-id.js +116 -0
  548. package/dist/core/ingestion/workers/parse-worker.d.ts +14 -1
  549. package/dist/core/ingestion/workers/parse-worker.js +409 -39
  550. package/dist/core/ingestion/workers/worker-pool.d.ts +34 -27
  551. package/dist/core/ingestion/workers/worker-pool.js +133 -25
  552. package/dist/core/lbug/csv-generator.d.ts +27 -0
  553. package/dist/core/lbug/csv-generator.js +80 -17
  554. package/dist/core/lbug/extension-load-error.d.ts +2 -2
  555. package/dist/core/lbug/extension-load-error.js +44 -27
  556. package/dist/core/lbug/extension-loader.d.ts +29 -0
  557. package/dist/core/lbug/extension-loader.js +32 -7
  558. package/dist/core/lbug/graph-emit-sink.d.ts +264 -0
  559. package/dist/core/lbug/graph-emit-sink.js +581 -0
  560. package/dist/core/lbug/lbug-adapter.d.ts +337 -3
  561. package/dist/core/lbug/lbug-adapter.js +772 -67
  562. package/dist/core/lbug/lbug-config.d.ts +93 -6
  563. package/dist/core/lbug/lbug-config.js +269 -9
  564. package/dist/core/lbug/native-check.d.ts +39 -0
  565. package/dist/core/lbug/native-check.js +323 -46
  566. package/dist/core/lbug/pdg-emit-sink.d.ts +13 -4
  567. package/dist/core/lbug/pdg-emit-sink.js +21 -111
  568. package/dist/core/lbug/pool-adapter.d.ts +23 -1
  569. package/dist/core/lbug/pool-adapter.js +115 -7
  570. package/dist/core/lbug/query-batch.d.ts +75 -0
  571. package/dist/core/lbug/query-batch.js +102 -0
  572. package/dist/core/lbug/rel-pair-routing.d.ts +160 -2
  573. package/dist/core/lbug/rel-pair-routing.js +228 -10
  574. package/dist/core/lbug/schema.d.ts +162 -3
  575. package/dist/core/lbug/schema.js +392 -157
  576. package/dist/core/lbug/sidecar-recovery.d.ts +1 -0
  577. package/dist/core/lbug/sidecar-recovery.js +1 -1
  578. package/dist/core/lbug/sync-csv-writer.d.ts +47 -0
  579. package/dist/core/lbug/sync-csv-writer.js +108 -0
  580. package/dist/core/lbug/wal-checkpoint-driver.js +3 -0
  581. package/dist/core/platform/capabilities.d.ts +0 -1
  582. package/dist/core/platform/capabilities.js +12 -7
  583. package/dist/core/run-analyze.d.ts +150 -3
  584. package/dist/core/run-analyze.js +1562 -151
  585. package/dist/core/search/bm25-index.d.ts +11 -0
  586. package/dist/core/search/bm25-index.js +60 -26
  587. package/dist/core/search/fts-indexes.d.ts +167 -2
  588. package/dist/core/search/fts-indexes.js +264 -10
  589. package/dist/core/wiki/graph-queries.js +145 -112
  590. package/dist/core/wiki/llm-client.d.ts +37 -5
  591. package/dist/core/wiki/llm-client.js +88 -17
  592. package/dist/core/wiki/prompts.d.ts +19 -0
  593. package/dist/core/wiki/prompts.js +20 -1
  594. package/dist/lib/utils.d.ts +113 -0
  595. package/dist/lib/utils.js +185 -0
  596. package/dist/mcp/http-transport.d.ts +5 -0
  597. package/dist/mcp/http-transport.js +19 -5
  598. package/dist/mcp/local/aop-metadata.d.ts +77 -0
  599. package/dist/mcp/local/aop-metadata.js +227 -0
  600. package/dist/mcp/local/bean-metadata.d.ts +3 -0
  601. package/dist/mcp/local/bean-metadata.js +46 -0
  602. package/dist/mcp/local/local-backend.d.ts +167 -6
  603. package/dist/mcp/local/local-backend.js +1756 -405
  604. package/dist/mcp/local/path-predicate.d.ts +19 -0
  605. package/dist/mcp/local/path-predicate.js +21 -0
  606. package/dist/mcp/local/pdg-impact.d.ts +132 -10
  607. package/dist/mcp/local/pdg-impact.js +391 -98
  608. package/dist/mcp/output-budget.d.ts +5 -0
  609. package/dist/mcp/output-budget.js +52 -0
  610. package/dist/mcp/read-only-policy.d.ts +12 -0
  611. package/dist/mcp/read-only-policy.js +102 -0
  612. package/dist/mcp/repository-policy.d.ts +35 -0
  613. package/dist/mcp/repository-policy.js +333 -0
  614. package/dist/mcp/resources.js +34 -7
  615. package/dist/mcp/server.d.ts +5 -2
  616. package/dist/mcp/server.js +48 -18
  617. package/dist/mcp/tools.d.ts +8 -8
  618. package/dist/mcp/tools.js +91 -20
  619. package/dist/server/analyze-job.d.ts +40 -2
  620. package/dist/server/analyze-job.js +30 -2
  621. package/dist/server/analyze-launch.d.ts +1 -1
  622. package/dist/server/analyze-launch.js +79 -10
  623. package/dist/server/analyze-worker-core.d.ts +3 -2
  624. package/dist/server/analyze-worker-core.js +15 -3
  625. package/dist/server/analyze-worker-ipc.d.ts +1 -1
  626. package/dist/server/analyze-worker-ipc.js +4 -0
  627. package/dist/server/analyze-worker-protocol.d.ts +59 -0
  628. package/dist/server/analyze-worker-protocol.js +1 -0
  629. package/dist/server/analyze-worker.d.ts +1 -17
  630. package/dist/server/analyze-worker.js +29 -6
  631. package/dist/server/api.d.ts +2 -11
  632. package/dist/server/api.js +200 -155
  633. package/dist/server/embed-run-outcome.d.ts +89 -0
  634. package/dist/server/embed-run-outcome.js +88 -0
  635. package/dist/server/git-clone.js +6 -2
  636. package/dist/server/mcp-http.d.ts +1 -1
  637. package/dist/server/mcp-http.js +4 -2
  638. package/dist/server/middleware.d.ts +116 -9
  639. package/dist/server/middleware.js +291 -22
  640. package/dist/server/sse-progress.d.ts +41 -0
  641. package/dist/server/sse-progress.js +125 -0
  642. package/dist/server/upload-ingest.js +2 -1
  643. package/dist/server/validation.js +2 -1
  644. package/dist/storage/branch-index.d.ts +11 -6
  645. package/dist/storage/branch-index.js +15 -7
  646. package/dist/storage/file-hash.js +2 -2
  647. package/dist/storage/fs-atomic.d.ts +25 -0
  648. package/dist/storage/fs-atomic.js +42 -0
  649. package/dist/storage/git.d.ts +165 -0
  650. package/dist/storage/git.js +352 -3
  651. package/dist/storage/index-lock.d.ts +83 -0
  652. package/dist/storage/index-lock.js +654 -0
  653. package/dist/storage/parse-cache.js +482 -1
  654. package/dist/storage/parsedfile-store.d.ts +8 -0
  655. package/dist/storage/parsedfile-store.js +235 -1
  656. package/dist/storage/repo-manager.d.ts +29 -309
  657. package/dist/storage/repo-manager.js +187 -165
  658. package/dist/storage/repo-meta.d.ts +530 -0
  659. package/dist/storage/repo-meta.js +100 -0
  660. package/dist/types/pipeline.d.ts +37 -0
  661. package/hooks/antigravity/gitnexus-antigravity-hook.cjs +1 -1
  662. package/hooks/claude/gitnexus-hook.cjs +1 -1
  663. package/hooks/claude/resolve-analyze-cmd.cjs +80 -13
  664. package/package.json +20 -12
  665. package/scripts/cross-platform-shard.ts +143 -0
  666. package/scripts/cross-platform-tests.ts +94 -0
  667. package/scripts/ensure-fts.ts +14 -3
  668. package/scripts/run-cross-platform.ts +36 -10
  669. package/scripts/sync-plugin-manifests.mjs +192 -0
  670. package/skills/gitnexus-cli.md +3 -3
  671. package/skills/gitnexus-debugging.md +37 -7
  672. package/skills/gitnexus-exploring.md +26 -4
  673. package/skills/gitnexus-impact-analysis.md +71 -10
  674. package/skills/gitnexus-lfg/README.md +55 -0
  675. package/skills/gitnexus-lfg/SKILL.md +86 -0
  676. package/skills/gitnexus-plan/README.md +147 -0
  677. package/skills/gitnexus-plan/SKILL.md +348 -0
  678. package/skills/gitnexus-plan/references/context-ledger.md +137 -0
  679. package/skills/gitnexus-plan/references/context-pack.md +126 -0
  680. package/skills/gitnexus-plan/references/evidence-provenance.md +309 -0
  681. package/skills/gitnexus-plan/references/pdg-slice.md +109 -0
  682. package/skills/gitnexus-plan/references/plan-template.md +201 -0
  683. package/skills/gitnexus-plan/scripts/evidence-provenance.mjs +2366 -0
  684. package/skills/gitnexus-refactoring.md +48 -5
  685. package/skills/gitnexus-review/SKILL.md +279 -0
  686. package/skills/gitnexus-review/ci-personas/ci-adversarial-lens.md +42 -0
  687. package/skills/gitnexus-review/ci-personas/ci-blast-radius-lens.md +39 -0
  688. package/skills/gitnexus-review/ci-personas/ci-correctness-lens.md +37 -0
  689. package/skills/gitnexus-review/ci-personas/ci-coverage-lens.md +40 -0
  690. package/skills/gitnexus-review/ci-personas/ci-critic-lens.md +42 -0
  691. package/skills/gitnexus-review/ci-personas/ci-security-lens.md +39 -0
  692. package/skills/gitnexus-taint-analysis.md +13 -7
  693. package/skills/gitnexus-work/README.md +71 -0
  694. package/skills/gitnexus-work/SKILL.md +272 -0
  695. package/skills/gitnexus-work/references/evidence-provenance.md +309 -0
  696. package/skills/gitnexus-work/scripts/evidence-provenance.mjs +2366 -0
  697. package/vendor/leiden/utils.cjs +28 -1
  698. package/web/assets/ProcessFlowModal-Badh2Pbg.js +24 -0
  699. package/web/assets/__vite-browser-external-bMKyYQkO.js +1 -0
  700. package/web/assets/abnfDiagram-QNN2D4NM-Cq2djWWe.js +1 -0
  701. package/web/assets/agent-DIzEQ1JJ.js +626 -0
  702. package/web/assets/architecture-TIHT7OUA-V6N4J3SY-fTePvLoe.js +1 -0
  703. package/web/assets/architectureDiagram-OT7VKSJ7-mKEXxkeF.js +36 -0
  704. package/web/assets/blockDiagram-54WLDVWM-Dg_hrRWE.js +132 -0
  705. package/web/assets/{c4Diagram-Y2BXMSZH-DOXVs7-C.js → c4Diagram-X2LASM7V-CnhoT4aV.js} +6 -6
  706. package/web/assets/chunk-224SPVON-B8gxtXpy.js +1 -0
  707. package/web/assets/chunk-2AEHWXPW-CV4r6-1I.js +127 -0
  708. package/web/assets/chunk-2SREHG4O-Dip42xOq.js +1 -0
  709. package/web/assets/chunk-4RFN2BYJ-DHHWuC-n.js +1 -0
  710. package/web/assets/chunk-66DQ2XMT-CM0xjFAN.js +1 -0
  711. package/web/assets/chunk-6BELYETK-ChsYtfHW.js +1 -0
  712. package/web/assets/chunk-6L755F7B-CMhLBxi2.js +1 -0
  713. package/web/assets/chunk-7CWYLC5S-DRgGkkpF.js +2 -0
  714. package/web/assets/chunk-A7VWPJGB-B4O3oQdQ.js +1 -0
  715. package/web/assets/chunk-BI6VK774-D0oaWk8V.js +1 -0
  716. package/web/assets/chunk-D6VWDJW2-BxcBdZ9c.js +2 -0
  717. package/web/assets/chunk-DMV4VAQV-Bn6WXDSX.js +4 -0
  718. package/web/assets/chunk-E5QJAATJ-dh-5CtIV.js +2 -0
  719. package/web/assets/chunk-EQFTRU2I-1ix7TzW9.js +2 -0
  720. package/web/assets/chunk-FWYVLQTC-BgDItRzJ.js +1 -0
  721. package/web/assets/chunk-HNC4WDU7-DoU3KnA7.js +1 -0
  722. package/web/assets/chunk-L5GCOVLC-CE2w8Nm_.js +161 -0
  723. package/web/assets/chunk-LAHSG3N2-Bz4hcn0N.js +321 -0
  724. package/web/assets/chunk-LORZLZWG-B57uGw2N.js +88 -0
  725. package/web/assets/chunk-NLANEA3F-XpH_NPA5.js +62 -0
  726. package/web/assets/chunk-NV3KIAZN-5yvcpMiu.js +1 -0
  727. package/web/assets/chunk-OIYT25JQ-CQ6KOZGX.js +1 -0
  728. package/web/assets/chunk-PE7DX7ZZ-CCvRVj43.js +10 -0
  729. package/web/assets/chunk-Q67WD55A-BWCH2SVz.js +156 -0
  730. package/web/assets/chunk-RRFMTAIC-CMN0wcYA.js +1 -0
  731. package/web/assets/{chunk-RLI5ZMPA-CkXZ0y0U.js → chunk-SATU7PGQ-B1zhgOvc.js} +1 -1
  732. package/web/assets/chunk-STOV2HOB-GnExfzIX.js +1 -0
  733. package/web/assets/chunk-SZD42YQK-ijyKKVr1.js +70 -0
  734. package/web/assets/chunk-TFPGFQPA-Dj6a-0pC.js +231 -0
  735. package/web/assets/chunk-TGVD4F4B-BMc31Gj2.js +2 -0
  736. package/web/assets/chunk-TZUXEDM2-B7p9AcTw.js +1 -0
  737. package/web/assets/chunk-UAT7B5JY-DW-A_fpI.js +1 -0
  738. package/web/assets/{chunk-6764PJDD-C7xxk063.js → chunk-VE5CLXGZ-C1vB7wpY.js} +1 -1
  739. package/web/assets/chunk-VJFVEZTB-CX66F2ep.js +206 -0
  740. package/web/assets/chunk-VY5UBI4V-yxPQAWxw.js +1 -0
  741. package/web/assets/chunk-WJBAP47W-BckNkuEN.js +1 -0
  742. package/web/assets/chunk-XNMVGMAZ-Cg_LnPtj.js +1 -0
  743. package/web/assets/classDiagram-VPOSVPXH-BjOiXA_C.js +1 -0
  744. package/web/assets/classDiagram-v2-5VFNUXQA-BjOiXA_C.js +1 -0
  745. package/web/assets/{cose-bilkent-UX7MHV2Q-BmnZ7Mvj.js → cose-bilkent-RZA4XIPR-BHpK4Crp.js} +1 -1
  746. package/web/assets/cynefin-VYW2F7L2-2VAHYKR6-DAsF6GZv.js +1 -0
  747. package/web/assets/cynefinDiagram-TR7LZUCG-C3Iar9lZ.js +62 -0
  748. package/web/assets/dagre-K64A6Z3X-CUwi79mA.js +4 -0
  749. package/web/assets/diagram-2TLGJV2N-C2F5Nfym.js +30 -0
  750. package/web/assets/diagram-JCD7PQ7C-DC5-9FRr.js +24 -0
  751. package/web/assets/diagram-KFBZAVDW-Dfmf_4ti.js +3 -0
  752. package/web/assets/diagram-L7DVE3PN-GIRyVUtt.js +41 -0
  753. package/web/assets/diagram-YP3FGXHI-CyNFYtkd.js +24 -0
  754. package/web/assets/ebnfDiagram-DRHRQJWO-D8_CI4ZF.js +1 -0
  755. package/web/assets/erDiagram-SZLJLQMB-CohQjznC.js +85 -0
  756. package/web/assets/eventmodeling-45OFAUF4-AOUJWSLX-BvTc6iQi.js +1 -0
  757. package/web/assets/flowDiagram-BWE6NHOH-B6RnEvD9.js +1 -0
  758. package/web/assets/ganttDiagram-2QTCJSNI-Cks_mEcF.js +292 -0
  759. package/web/assets/gitGraph-TEB2WS4Q-U5VWYIBC-Dy7CCSZ5.js +1 -0
  760. package/web/assets/gitGraphDiagram-VVZAVV5G-CG41cIVc.js +106 -0
  761. package/web/assets/{index-B4eB4dNZ.js → index-BBNl0qfX.js} +51 -51
  762. package/web/assets/index-CJDpyH-n.css +2 -0
  763. package/web/assets/info-DKCQHKI2-DX6KST54-BLJg1ikX.js +1 -0
  764. package/web/assets/infoDiagram-FY4PZKRE-BJ3vPVwW.js +2 -0
  765. package/web/assets/{ishikawaDiagram-BNXS4ZKH-BLjivjXL.js → ishikawaDiagram-4JDSWWDM-DmqWtjkl.js} +6 -6
  766. package/web/assets/{journeyDiagram-M6C3CM3L-Cetgs3NH.js → journeyDiagram-QUS3FAKT-XAzVzrQW.js} +6 -6
  767. package/web/assets/{kanban-definition-75IXJCU3-DMlCaIpf.js → kanban-definition-D4L7SQKK-YurRnmYn.js} +27 -27
  768. package/web/assets/katex-C5OPUE3Q-Bnbavtmu.js +257 -0
  769. package/web/assets/{mindmap-definition-2TDM6QVE-B4GbXQBc.js → mindmap-definition-66QP5TD6-ChrWWnil.js} +29 -29
  770. package/web/assets/node-Ct_zna8U.js +8 -0
  771. package/web/assets/packet-7NZHBO7P-5WG45QPS-KUxcuvaA.js +1 -0
  772. package/web/assets/pegDiagram-YKIO5C6U-QGeQLEq2.js +1 -0
  773. package/web/assets/pie-RZYD4A2V-2OCZ2VTD-DPs08kJY.js +1 -0
  774. package/web/assets/pieDiagram-YPY3TKG5-BuT3MYzm.js +39 -0
  775. package/web/assets/preload-helper-Czpn1I53.js +1 -0
  776. package/web/assets/{quadrantDiagram-VICAPDV7-B1TQnlm0.js → quadrantDiagram-VO5QLCXA-B7098wSc.js} +6 -6
  777. package/web/assets/radar-I7S5WNFK-EPLSA35B-w5F0K3a7.js +1 -0
  778. package/web/assets/railroad-3IZDKUUU-PWFQV6Y6-Bu668yqY.js +1 -0
  779. package/web/assets/railroad-abnf-AHOZXSZD-JYYJX3BS-B6ghpETS.js +1 -0
  780. package/web/assets/railroad-ebnf-EBAXGLYW-RBZ4ONAP-D-XmHh3M.js +1 -0
  781. package/web/assets/railroad-peg-LSFZ7HO6-KHNPXGPG-mhkrhzEn.js +1 -0
  782. package/web/assets/railroadDiagram-M77LTMSB-AXu4vxk_.js +1 -0
  783. package/web/assets/requirementDiagram-RASO5HTO-B-l8InpK.js +84 -0
  784. package/web/assets/sankeyDiagram-F32LOJ6L-Kd7zjJgX.js +40 -0
  785. package/web/assets/sdk-CzHHH8tD.js +37 -0
  786. package/web/assets/sequenceDiagram-URATNSBD-BlcdY9DS.js +162 -0
  787. package/web/assets/sizeCapture-5GORAGP4-BEqQzsxs.js +1 -0
  788. package/web/assets/src-C5sx_gMp.js +1 -0
  789. package/web/assets/stateDiagram-DODFXNG5-DTdHc-fF.js +1 -0
  790. package/web/assets/stateDiagram-v2-JNMM5JRA-DioNLDDo.js +1 -0
  791. package/web/assets/swimlanes-OSWOYLSK-CA0ofdwY.js +2 -0
  792. package/web/assets/swimlanesDiagram-RHGX2RDE-PkwUdckC.js +8 -0
  793. package/web/assets/timeline-definition-WJXWRH4I-DUfp1R3E.js +120 -0
  794. package/web/assets/treeView-QDETBFTQ-EHYTSQNO-C5lpBgPm.js +1 -0
  795. package/web/assets/treemap-6X3UGDF4-CCWCF7EK-BB0ZyO-B.js +1 -0
  796. package/web/assets/vennDiagram-K3VCMQLI-Bj-FN-XS.js +34 -0
  797. package/web/assets/wardley-OPB4EBWU-6OWERDVT-CEA3Nq0j.js +1 -0
  798. package/web/assets/wardleyDiagram-XK6FUAWV-CVV0dHFr.js +78 -0
  799. package/web/assets/xychartDiagram-5VRUVLCW-CK_rbSWE.js +7 -0
  800. package/web/index.html +17 -15
  801. package/dist/core/ingestion/languages/python/index-stats.d.ts +0 -18
  802. package/dist/core/ingestion/languages/python/index-stats.js +0 -25
  803. package/skills/gitnexus-pr-review.md +0 -163
  804. package/web/assets/ProcessFlowModal-Dna7GkwO.js +0 -22
  805. package/web/assets/agent-DNYDy-KA.js +0 -660
  806. package/web/assets/architecture-7EHR7CIX-6QZW5X65-BVWFvYz2.js +0 -1
  807. package/web/assets/architectureDiagram-UL44E2DR-BU5ZRITg.js +0 -36
  808. package/web/assets/blockDiagram-7IZFK4PR-Dut1BpTV.js +0 -132
  809. package/web/assets/chunk-2T2R6R2M-pkw2oXHH.js +0 -4
  810. package/web/assets/chunk-2UTLFMKG-CXlhF3Pt.js +0 -1
  811. package/web/assets/chunk-3SSMPTDK-rPsRM1x0.js +0 -321
  812. package/web/assets/chunk-4R4BOZG6-Be_F0JoX.js +0 -159
  813. package/web/assets/chunk-67TQ5CYL-zxhDWgyF.js +0 -124
  814. package/web/assets/chunk-7J6CGLKN-AmkN8jJN.js +0 -10
  815. package/web/assets/chunk-C62D2QBJ-3gdL8EKc.js +0 -1
  816. package/web/assets/chunk-CEXFNPSA-CjwtMDkc.js +0 -1
  817. package/web/assets/chunk-INKRHTLW-D9BM9HWZ.js +0 -70
  818. package/web/assets/chunk-J5EP6P6S-L19oz55R.js +0 -1
  819. package/web/assets/chunk-KGFNY3KK-tD2F6wxK.js +0 -62
  820. package/web/assets/chunk-KGYTTC2M-zm6n242I.js +0 -1
  821. package/web/assets/chunk-KNLZD3CH-BGlP6X9R.js +0 -1
  822. package/web/assets/chunk-LCXTWHL2-Ba9JK-6F.js +0 -231
  823. package/web/assets/chunk-LII3EMHJ-EGx-eBIu.js +0 -1
  824. package/web/assets/chunk-LRIF4GLE-C3_PqUBq.js +0 -1
  825. package/web/assets/chunk-QA3QBVWF-D4cSJBf6.js +0 -2
  826. package/web/assets/chunk-RERM46MO-B5dAdWpP.js +0 -1
  827. package/web/assets/chunk-RG4AUYOV-OqBBMwuQ.js +0 -206
  828. package/web/assets/chunk-RKZBBQEN-MyIQbGgD.js +0 -1
  829. package/web/assets/chunk-T2UQINTJ-BJusEiGe.js +0 -1
  830. package/web/assets/chunk-UP6H54XL-BG-n7qDp.js +0 -1
  831. package/web/assets/chunk-UXSXWOXI-CW1_r5cS.js +0 -1
  832. package/web/assets/chunk-UY5QBCOK-BCpUlARQ.js +0 -1
  833. package/web/assets/chunk-VU6ZFW4Y-BeXVk45_.js +0 -2
  834. package/web/assets/chunk-ZXARS5L4-BI_qR2Nm.js +0 -1
  835. package/web/assets/classDiagram-KGZ6W3CR-D9zSIg0x.js +0 -1
  836. package/web/assets/classDiagram-v2-72OJOZXJ-D9zSIg0x.js +0 -1
  837. package/web/assets/dagre-ND4H6XIP-CpcV5kbl.js +0 -4
  838. package/web/assets/diagram-3NCE3AQN-6SMxBRpj.js +0 -43
  839. package/web/assets/diagram-GF46GFSD-BZEdNcRZ.js +0 -24
  840. package/web/assets/diagram-HNR7UZ2L-DxKW2a2Y.js +0 -3
  841. package/web/assets/diagram-QXG6HAR7-HfTHcXX_.js +0 -24
  842. package/web/assets/diagram-WEQXMOUZ-CyijUS8r.js +0 -10
  843. package/web/assets/erDiagram-L5TCEMPS-D0fvpWEX.js +0 -85
  844. package/web/assets/eventmodeling-FCH6USID-MREXMVOE-CgFBM7e-.js +0 -1
  845. package/web/assets/flowDiagram-H6V6AXG4-Bvr9bbhk.js +0 -162
  846. package/web/assets/ganttDiagram-JCBTUEKG-TzODrLzv.js +0 -292
  847. package/web/assets/gitGraph-WXDBUCRP-R675I2BI-DCJv7SII.js +0 -1
  848. package/web/assets/gitGraphDiagram-S2ZK5IYY-ONQSwJIY.js +0 -106
  849. package/web/assets/index-CX_fADmQ.css +0 -2
  850. package/web/assets/info-J43DQDTF-KCYPFFUO-BfNy-9Nd.js +0 -1
  851. package/web/assets/infoDiagram-3YFTVSEB-DIPVUIQ6.js +0 -2
  852. package/web/assets/katex-K3KEBU37-qRQBy-EZ.js +0 -261
  853. package/web/assets/packet-YPE3B663-LP52Z2RK-D4qkeG9k.js +0 -1
  854. package/web/assets/pie-LRSECV5Y-TCRJHUBD-B_yMKyQa.js +0 -1
  855. package/web/assets/pieDiagram-CU6KROY3-D3YC_xyg.js +0 -30
  856. package/web/assets/radar-GUYGQ44K-RDLRG3WG-DeD6yN_0.js +0 -1
  857. package/web/assets/requirementDiagram-JXO7QTGE-f8wczLQf.js +0 -84
  858. package/web/assets/sankeyDiagram-URQDO5SZ-BTxzG5j0.js +0 -40
  859. package/web/assets/sequenceDiagram-VS2MUI6T-DuamM-IR.js +0 -162
  860. package/web/assets/src-BNCXICdA.js +0 -1
  861. package/web/assets/stateDiagram-7D4R322I-Ch2pEUcw.js +0 -1
  862. package/web/assets/stateDiagram-v2-36443NZ5-7ANuoZLL.js +0 -1
  863. package/web/assets/timeline-definition-O6YCAMPW-07BR8R8G.js +0 -120
  864. package/web/assets/treeView-BLDUP644-QA4HXRO3-CDuSYnd4.js +0 -1
  865. package/web/assets/treemap-LRROVOQU-LLAWBHMP-imazucyJ.js +0 -1
  866. package/web/assets/vennDiagram-MWXL3ELB-BQX2ossk.js +0 -34
  867. package/web/assets/wardley-L42UT6IY-5TKZOOLJ-DqrT9tB8.js +0 -1
  868. package/web/assets/wardleyDiagram-CUQ6CDDI-CGIJBBiK.js +0 -78
  869. package/web/assets/xychartDiagram-N2JHSOCM-B3HNMuWp.js +0 -7
  870. /package/web/assets/{chunk-7W6UQGC5-pyKGssV3.js → chunk-LIEV3EAG-pyKGssV3.js} +0 -0
@@ -0,0 +1,654 @@
1
+ /**
2
+ * Cross-process single-writer lock for a GitNexus index directory (#2658).
3
+ *
4
+ * `analyze` is the only writer of a `.gitnexus/` (or `branches/<slug>/`) slot,
5
+ * but nothing stopped two `analyze` runs — e.g. two editor/agent SessionStart
6
+ * hooks firing on the same repo at once — from wiping and rebuilding the same
7
+ * store concurrently. They raced on `lbug` and its sidecars, wasted N× CPU
8
+ * producing one index, and left orphaned WAL fragments (#2637). This module
9
+ * gives the write path an exclusive, index-directory-scoped lock so a second
10
+ * writer waits for the first instead of colliding; after acquiring, the caller
11
+ * re-runs its normal freshness check, so a run whose work the holder already
12
+ * did exits up-to-date rather than rebuilding (single-flight coalescing).
13
+ *
14
+ * Ownership lives with the process that runs the pipeline (the heap-respawn
15
+ * child when a respawn happens, the original otherwise) — NOT a supervising
16
+ * parent — so the entity the OS tracks for liveness is always the real writer.
17
+ * See run-analyze.ts for the acquire site.
18
+ *
19
+ * TWO BACKENDS behind the {@link acquireIndexLock} seam:
20
+ *
21
+ * - **socket** (Windows named pipe / Linux abstract socket, via `net`) — the
22
+ * preferred, KERNEL-OWNED lock. Holding it = holding a listening endpoint the
23
+ * kernel binds to this process; `EADDRINUSE` therefore means a *live* holder,
24
+ * and the kernel drops the binding the instant the holder exits for ANY reason
25
+ * (clean exit, crash, OOM, SIGKILL). That makes it provably race-free: no
26
+ * stale detection, no pid-reuse guess, no takeover, and — since the endpoint
27
+ * lives outside the index dir — no filesystem write, so it works unchanged on
28
+ * a read-only index mount. This is the same class of kernel object as the
29
+ * Windows named mutex the issue's reporter used as an external workaround, but
30
+ * built from Node's stdlib `net`, so it adds NO native dependency and cannot
31
+ * break `npx gitnexus` install anywhere.
32
+ *
33
+ * - **file** (`O_EXCL` pidfile) — the portable fallback for macOS/BSD (no
34
+ * abstract sockets; filesystem sockets don't release cleanly on death) and
35
+ * for any environment where the socket backend can't bind. It uses pid-
36
+ * liveness staleness, an atomic rename-steal reclaim, bounded malformed-file
37
+ * handling, read-only tolerance, and a finite wait timeout (a reused pid can
38
+ * masquerade as live where process start-time isn't verifiable, so waiting is
39
+ * bounded rather than a hang). Its stale-takeover has an irreducible narrow
40
+ * race — inherent to file-based advisory locks — which is precisely why the
41
+ * socket backend is preferred; only a kernel primitive closes it.
42
+ *
43
+ * Scope: cross-process, same logical index dir. The file backend never steals a
44
+ * foreign-host lock (pid liveness is meaningless across hosts); the socket
45
+ * backend is single-host by nature. The motivating case (local hook-driven
46
+ * re-index) is single-host. See AcquireOptions.timeoutMs for the wait ceiling.
47
+ */
48
+ import { openSync, writeSync, closeSync, readFileSync, unlinkSync, renameSync, existsSync, mkdirSync, readdirSync, realpathSync, } from 'node:fs';
49
+ import net from 'node:net';
50
+ import path from 'node:path';
51
+ import os from 'node:os';
52
+ import { randomBytes, randomUUID, createHash } from 'node:crypto';
53
+ const LOCK_FILENAME = 'analyze.lock';
54
+ const LOCK_RECORD_VERSION = 1;
55
+ /** Base poll interval while waiting for a live holder; jittered per attempt. */
56
+ const DEFAULT_POLL_MS = 250;
57
+ /** How often to re-emit the "still waiting for pid N" diagnostic. */
58
+ const DIAGNOSTIC_INTERVAL_MS = 15_000;
59
+ /**
60
+ * Default wait ceiling (10 min). Generous enough to sit behind a normal
61
+ * analyze, finite so a pid-reuse ghost on a platform without start-time
62
+ * verification can't wedge acquisition forever (see AcquireOptions.timeoutMs).
63
+ * A repo whose analyze legitimately runs longer can raise
64
+ * GITNEXUS_INDEX_LOCK_TIMEOUT_MS (or set it ≤ 0 for unbounded).
65
+ */
66
+ const DEFAULT_TIMEOUT_MS = 600_000;
67
+ /**
68
+ * How long a lock file must stay unreadable (empty/partial JSON) before we
69
+ * treat it as a crash orphan and reclaim it. Tolerates the microsecond
70
+ * create→write→close window of a *live* owner (see acquireIndexLock), so we
71
+ * never steal a lock that is a poll-interval away from being written. Scaled
72
+ * off the poll interval, floored at 1s.
73
+ */
74
+ const malformedGraceMs = (pollMs) => Math.max(1000, pollMs * 2);
75
+ export class IndexLockTimeoutError extends Error {
76
+ holder;
77
+ /**
78
+ * Whether `holder` carries a real, identifiable owner. False on the socket
79
+ * backend (and the file backend's malformed/vanished-lock timeouts), where the
80
+ * holder is a placeholder (`pid -1`) — the OS socket lock exposes no owner
81
+ * metadata (#2658 review M3). Consumers must not present `holder.pid` as a real
82
+ * pid when this is false.
83
+ */
84
+ holderKnown;
85
+ constructor(holder, waitedMs, holderKnown = true) {
86
+ super(holderKnown
87
+ ? `Timed out after ${waitedMs}ms waiting for another gitnexus analyze ` +
88
+ `(pid ${holder.pid} on ${holder.hostname}, invocation ${holder.invocationId}) ` +
89
+ `to release the index lock.`
90
+ : `Timed out after ${waitedMs}ms waiting for another gitnexus analyze ` +
91
+ `(holder identity unknown) to release the index lock.`);
92
+ this.name = 'IndexLockTimeoutError';
93
+ this.holder = holder;
94
+ this.holderKnown = holderKnown;
95
+ }
96
+ }
97
+ const HOSTNAME = os.hostname();
98
+ /** Linux: field 22 of /proc/<pid>/stat (starttime). null elsewhere / on error. */
99
+ const readProcStartTime = (pid) => {
100
+ if (process.platform !== 'linux')
101
+ return null;
102
+ try {
103
+ const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
104
+ // comm (field 2) is parenthesized and may contain spaces/')' — split after
105
+ // the last ')' so the remaining fields align to their documented numbers.
106
+ const afterComm = stat
107
+ .slice(stat.lastIndexOf(') ') + 2)
108
+ .trim()
109
+ .split(' ');
110
+ // afterComm[0] is field 3 (state); starttime is field 22 → index 19.
111
+ return afterComm[19] ?? null;
112
+ }
113
+ catch {
114
+ return null;
115
+ }
116
+ };
117
+ /** true if the pid exists (signal 0). EPERM means it exists but isn't ours. */
118
+ const pidAlive = (pid) => {
119
+ try {
120
+ process.kill(pid, 0);
121
+ return true;
122
+ }
123
+ catch (err) {
124
+ return err.code === 'EPERM';
125
+ }
126
+ };
127
+ const buildRecord = () => ({
128
+ v: LOCK_RECORD_VERSION,
129
+ pid: process.pid,
130
+ hostname: HOSTNAME,
131
+ startTime: readProcStartTime(process.pid),
132
+ token: randomBytes(16).toString('hex'),
133
+ invocationId: randomUUID(),
134
+ acquiredAt: new Date().toISOString(),
135
+ });
136
+ const readRecord = (lockPath) => {
137
+ try {
138
+ const raw = readFileSync(lockPath, 'utf8');
139
+ const parsed = JSON.parse(raw);
140
+ // `typeof NaN === 'number'`, so a bare number check lets NaN/0/-1/Infinity/
141
+ // fractional pids reach process.kill (#2658 review L4): a garbled or crafted
142
+ // lock file with `{"pid":0}` reads as a live holder and wedges a real analyze
143
+ // for the full wait timeout. A real pid is a positive integer.
144
+ if (!Number.isInteger(parsed.pid) || parsed.pid <= 0)
145
+ return null;
146
+ if (typeof parsed.token !== 'string')
147
+ return null;
148
+ return parsed;
149
+ }
150
+ catch {
151
+ // Missing (won the race, file gone) or malformed/half-written → treat as
152
+ // "no readable holder"; the caller retries the O_EXCL create.
153
+ return null;
154
+ }
155
+ };
156
+ /**
157
+ * A same-host holder is stale iff its process is gone, or (Linux) its pid is
158
+ * alive but was reused — a different start time. A live holder is never stolen
159
+ * on age alone (a large repo legitimately analyzes for many minutes), and a
160
+ * foreign-host holder is never stale (its liveness is unknowable here). Where
161
+ * start-time verification is unavailable (non-Linux), a reused pid cannot be
162
+ * distinguished from a genuine live holder, so it is NOT stolen — the finite
163
+ * acquire timeout is what bounds that case instead (see AcquireOptions).
164
+ */
165
+ const isStale = (holder) => {
166
+ if (holder.hostname !== HOSTNAME)
167
+ return false;
168
+ if (!pidAlive(holder.pid))
169
+ return true;
170
+ const now = readProcStartTime(holder.pid);
171
+ if (holder.startTime && now && holder.startTime !== now)
172
+ return true; // pid reused
173
+ return false;
174
+ };
175
+ /**
176
+ * Reclaim a lock file we judged reclaimable — a dead holder (`expected` = its
177
+ * record) or a malformed/unreadable crash-orphan (`expected` = null) — moving
178
+ * the exact inode aside in ONE `rename` syscall to a token-unique name so two
179
+ * waiters reclaiming the same orphan can't both win (the loser's rename ENOENTs).
180
+ *
181
+ * CRITICAL (#2658 review): the reclaim must not act on a STALE judgment. The
182
+ * staleness decision (`isStale` / malformed-grace) happened a few syscalls ago;
183
+ * a live writer may have O_EXCL-created its own lock at `lockPath` since. Blindly
184
+ * renaming that live lock aside would delete it and admit a SECOND writer — the
185
+ * exact double-writer this lock exists to prevent (reproduced: ~18%/round under
186
+ * 4-way reclaim contention on the file backend). So:
187
+ * 1. re-read `lockPath` immediately BEFORE the rename and confirm it still holds
188
+ * exactly what we judged (same token, or still-unreadable) — shrinking the
189
+ * window to the single gap between this read and the rename;
190
+ * 2. after the rename, confirm what we ACTUALLY moved matches the judgment; if a
191
+ * live lock slipped into that residual gap, RESTORE it (rename back) so its
192
+ * holder is never displaced, and lose the reclaim.
193
+ * A concurrent creator whose fresh lock the restore overwrites is caught by the
194
+ * acquire loop's post-write read-back verify (see acquireViaFile), so it backs
195
+ * off rather than proceeding as a second writer.
196
+ *
197
+ * Returns true if we won the reclaim (caller retries the create), false if we
198
+ * lost the race or the judgment went stale (caller re-loops and re-reads).
199
+ */
200
+ const matchesJudgment = (record, expected) => expected === null ? record === null : record?.token === expected.token;
201
+ const stealLock = (lockPath, me, expected) => {
202
+ // (1) Re-verify the judgment still holds right before we move anything.
203
+ if (!matchesJudgment(readRecord(lockPath), expected))
204
+ return false;
205
+ if (expected === null && !existsSync(lockPath))
206
+ return false; // malformed → but now vanished
207
+ const aside = `${lockPath}.dead.${me.token}`;
208
+ try {
209
+ renameSync(lockPath, aside);
210
+ }
211
+ catch (err) {
212
+ if (err.code === 'ENOENT')
213
+ return false; // another stealer won
214
+ throw err;
215
+ }
216
+ // (2) Confirm what we moved is what we judged; if a live lock slipped into the
217
+ // read→rename gap, put it back — a live holder must never be displaced.
218
+ if (!matchesJudgment(readRecord(aside), expected)) {
219
+ try {
220
+ renameSync(aside, lockPath); // restore; an overwritten concurrent creator's read-back backs it off
221
+ }
222
+ catch {
223
+ /* slot re-taken between our move and restore — leave it; we lost the reclaim */
224
+ }
225
+ return false;
226
+ }
227
+ try {
228
+ unlinkSync(aside); // uniquely ours by token → safe; best-effort
229
+ }
230
+ catch {
231
+ /* leftover .dead.<token> is inert (not analyze.lock, not swept) — harmless */
232
+ }
233
+ return true;
234
+ };
235
+ /**
236
+ * Placeholder holder for an {@link IndexLockTimeoutError} thrown while the lock
237
+ * file exists but no valid record can be read (malformed/partial), or it keeps
238
+ * vanishing — there is no real holder to name, but the error still needs one so
239
+ * the CLI's `err.holder.pid` stays defined. This path is a rare backstop:
240
+ * malformed files are reclaimed within {@link MALFORMED_GRACE_MS}.
241
+ */
242
+ const unknownHolder = () => ({
243
+ v: LOCK_RECORD_VERSION,
244
+ pid: -1,
245
+ hostname: HOSTNAME,
246
+ startTime: null,
247
+ token: '',
248
+ invocationId: '<unreadable>',
249
+ acquiredAt: '',
250
+ });
251
+ /**
252
+ * Filesystem-create error codes we tolerate by proceeding lock-free: a
253
+ * read-only mount (EROFS) or a denied create (EACCES/EPERM). Such a filesystem
254
+ * rejects every index WRITE in the same directory too, so no concurrent writer
255
+ * can exist and the lock is moot — an already-indexed repo on a `:ro` mount
256
+ * must still reach its `alreadyUpToDate` fast path (#2658). A genuinely-needed
257
+ * write fails later exactly as it would have without the lock.
258
+ */
259
+ export const LOCK_UNWRITABLE_CODES = new Set(['EROFS', 'EACCES', 'EPERM']);
260
+ export const isLockUnwritableCode = (code) => code !== undefined && LOCK_UNWRITABLE_CODES.has(code);
261
+ /** A lock handle that owns nothing — returned when the filesystem refuses to
262
+ * create the lock file (see {@link LOCK_UNWRITABLE_CODES}). Release is a no-op. */
263
+ const noopHandle = (record) => ({ record, release: () => { } });
264
+ /**
265
+ * Delete orphaned build/staging artifacts left in the lock directory by a
266
+ * crashed prior writer. Safe precisely because we hold the exclusive lock: no
267
+ * other writer can be creating these here right now, so anything present is a
268
+ * crash orphan. Matches this slot's staging files ONLY — never `lbug` itself,
269
+ * never `lbug.wal`/`lbug.shadow` (the LIVE index's own sidecars), and never a
270
+ * `branches/<slug>/` sub-slot (which owns its own lock + sweep). Non-recursive.
271
+ */
272
+ export const sweepStagingArtifacts = (lockDir, log) => {
273
+ // Matches `lbug.new`, `lbug.new.wal`, `lbug.staging.<id>`, `lbug.staging.<id>.wal`, …
274
+ // Does NOT match `lbug`, `lbug.wal`, `lbug.shadow`.
275
+ const stagingRe = /^lbug\.(staging\..+|new(\..+)?)$/;
276
+ let removed = 0;
277
+ let entries;
278
+ try {
279
+ entries = readdirSync(lockDir);
280
+ }
281
+ catch {
282
+ return;
283
+ }
284
+ for (const name of entries) {
285
+ if (!stagingRe.test(name))
286
+ continue;
287
+ try {
288
+ unlinkSync(path.join(lockDir, name));
289
+ removed++;
290
+ }
291
+ catch {
292
+ /* best-effort */
293
+ }
294
+ }
295
+ if (removed > 0) {
296
+ log?.(`Cleared ${removed} orphaned index-staging file(s) from a prior interrupted analyze.`);
297
+ }
298
+ };
299
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
300
+ /** Poll delay with jitter (avoids two waiters lock-stepping), clamped so it
301
+ * never overshoots the remaining timeout budget. Callers guarantee
302
+ * `waited < timeoutMs`, so the result is ≥ 1. */
303
+ const jitteredDelay = (pollMs, timeoutMs, waited) => {
304
+ const jitter = Math.floor(Math.random() * pollMs);
305
+ const remaining = timeoutMs - waited;
306
+ return Math.max(1, Math.min(pollMs + jitter, remaining));
307
+ };
308
+ /**
309
+ * Resolve the wait ceiling. Explicit `opt` wins; else
310
+ * GITNEXUS_INDEX_LOCK_TIMEOUT_MS; else {@link DEFAULT_TIMEOUT_MS}. A value ≤ 0
311
+ * (from either source) means unbounded.
312
+ */
313
+ const resolveTimeoutMs = (opt) => {
314
+ const raw = typeof opt === 'number'
315
+ ? opt
316
+ : (() => {
317
+ const env = process.env.GITNEXUS_INDEX_LOCK_TIMEOUT_MS;
318
+ if (env === undefined || env === '')
319
+ return DEFAULT_TIMEOUT_MS;
320
+ const n = Number(env);
321
+ return Number.isFinite(n) ? n : DEFAULT_TIMEOUT_MS;
322
+ })();
323
+ return raw <= 0 ? Number.POSITIVE_INFINITY : raw;
324
+ };
325
+ /**
326
+ * Acquire the exclusive write lock for `lockDir` (the resolved index slot
327
+ * directory, e.g. `<repo>/.gitnexus` or `<repo>/.gitnexus/branches/<slug>`).
328
+ *
329
+ * Blocks until the lock is held (waiting only on live holders, stealing dead
330
+ * ones immediately), then sweeps orphaned staging files under the lock and
331
+ * returns a handle. Rejects with `IndexLockTimeoutError` if `timeoutMs` is
332
+ * exceeded while a live holder still holds the lock.
333
+ */
334
+ /**
335
+ * File-based (O_EXCL pidfile) backend. The portable fallback used on platforms
336
+ * without the socket backend (macOS/BSD) or when the OS socket lock is
337
+ * unavailable. Carries the pid-liveness staleness, atomic rename-steal reclaim,
338
+ * bounded malformed-file handling, and read-only tolerance. Its stale-takeover
339
+ * has an irreducible (narrow) race — see the module header — which is why the
340
+ * socket backend is preferred where available.
341
+ */
342
+ const acquireViaFile = async (lockDir, me, opts) => {
343
+ try {
344
+ mkdirSync(lockDir, { recursive: true });
345
+ }
346
+ catch (err) {
347
+ // Read-only / denied filesystem → proceed lock-free (see LOCK_UNWRITABLE_CODES).
348
+ if (isLockUnwritableCode(err.code))
349
+ return noopHandle(me);
350
+ throw err;
351
+ }
352
+ const lockPath = path.join(lockDir, LOCK_FILENAME);
353
+ const pollMs = opts.pollMs ?? DEFAULT_POLL_MS;
354
+ const timeoutMs = resolveTimeoutMs(opts.timeoutMs);
355
+ const startedAt = Date.now();
356
+ let announcedWait = false;
357
+ let lastDiagnosticAt = 0;
358
+ // When the lock file exists but has no readable record, the timestamp we
359
+ // first observed it unreadable — used to reclaim a crash-orphan after a grace.
360
+ let malformedSince = null;
361
+ for (;;) {
362
+ try {
363
+ // O_WRONLY | O_CREAT | O_EXCL — the atomic arbiter of ownership.
364
+ const fd = openSync(lockPath, 'wx');
365
+ try {
366
+ writeSync(fd, JSON.stringify(me));
367
+ }
368
+ finally {
369
+ closeSync(fd);
370
+ }
371
+ // Read-back verify (#2658 review L5): if this process stalled (a >graceMs
372
+ // GC pause) between the O_EXCL create of the *empty* file and the write
373
+ // above, a waiter could have reclaimed the empty file (renamed it aside)
374
+ // and O_EXCL-created its own lock at `lockPath`. Our write then landed on
375
+ // the renamed-aside inode, not `lockPath`. Confirm `lockPath` still carries
376
+ // our token before claiming ownership; if it was stolen, contend normally.
377
+ const confirmed = readRecord(lockPath);
378
+ if (!confirmed || confirmed.token !== me.token)
379
+ continue;
380
+ return {
381
+ record: me,
382
+ release: () => {
383
+ const current = readRecord(lockPath);
384
+ if (current && current.token !== me.token)
385
+ return; // no longer ours
386
+ try {
387
+ unlinkSync(lockPath);
388
+ }
389
+ catch {
390
+ /* already gone */
391
+ }
392
+ },
393
+ };
394
+ }
395
+ catch (err) {
396
+ const code = err.code;
397
+ if (code === 'EEXIST') {
398
+ // fall through to holder inspection / wait / reclaim below
399
+ }
400
+ else if (isLockUnwritableCode(code)) {
401
+ return noopHandle(me); // read-only / denied → proceed lock-free
402
+ }
403
+ else {
404
+ throw err;
405
+ }
406
+ }
407
+ const holder = readRecord(lockPath);
408
+ const waited = Date.now() - startedAt;
409
+ if (holder) {
410
+ malformedSince = null;
411
+ if (isStale(holder)) {
412
+ opts.log?.(`Reclaiming stale index lock from dead analyze (pid ${holder.pid}, ` +
413
+ `invocation ${holder.invocationId}).`);
414
+ stealLock(lockPath, me, holder); // reclaim ONLY this dead record; live locks are never stolen
415
+ continue;
416
+ }
417
+ // Live holder → wait.
418
+ if (!announcedWait) {
419
+ announcedWait = true;
420
+ opts.onWaitStart?.(holder);
421
+ opts.log?.(`Another gitnexus analyze (pid ${holder.pid} on ${holder.hostname}) is ` +
422
+ `refreshing this index — waiting for it to finish.`);
423
+ }
424
+ if (waited >= timeoutMs)
425
+ throw new IndexLockTimeoutError(holder, waited);
426
+ if (Date.now() - lastDiagnosticAt >= DIAGNOSTIC_INTERVAL_MS) {
427
+ lastDiagnosticAt = Date.now();
428
+ if (waited >= DIAGNOSTIC_INTERVAL_MS) {
429
+ opts.log?.(`Still waiting for analyze pid ${holder.pid} (${Math.round(waited / 1000)}s elapsed).`);
430
+ }
431
+ }
432
+ await sleep(jitteredDelay(pollMs, timeoutMs, waited));
433
+ continue;
434
+ }
435
+ // holder === null: the lock file is either gone (vanished between the failed
436
+ // create and our read) or present-but-unreadable (a crash between the
437
+ // O_EXCL create and the record write, or a partial write). NEVER hot-loop
438
+ // here — both branches are bounded by sleep + timeout.
439
+ if (!existsSync(lockPath)) {
440
+ malformedSince = null; // genuinely vanished → the next create likely wins
441
+ if (waited >= timeoutMs)
442
+ throw new IndexLockTimeoutError(unknownHolder(), waited, false);
443
+ await sleep(jitteredDelay(pollMs, timeoutMs, waited));
444
+ continue;
445
+ }
446
+ // Malformed orphan present. Reclaim only after a grace, so a live owner's
447
+ // microsecond create→write window is never mistaken for a crash.
448
+ if (malformedSince === null)
449
+ malformedSince = Date.now();
450
+ if (Date.now() - malformedSince >= malformedGraceMs(pollMs)) {
451
+ opts.log?.('Reclaiming a malformed/partial index lock file (no readable owner record).');
452
+ stealLock(lockPath, me, null); // reclaim ONLY while still unreadable; a live lock written since is left
453
+ malformedSince = null;
454
+ continue;
455
+ }
456
+ if (waited >= timeoutMs)
457
+ throw new IndexLockTimeoutError(unknownHolder(), waited, false);
458
+ await sleep(jitteredDelay(pollMs, timeoutMs, waited));
459
+ }
460
+ };
461
+ /** Signals that the OS socket backend can't be used here (e.g. abstract
462
+ * namespace disabled, sandbox, or an unexpected bind error) so the caller
463
+ * should fall back to the file backend. NOT thrown for EADDRINUSE (that is a
464
+ * live holder → wait) or timeouts (those propagate as IndexLockTimeoutError). */
465
+ class SocketLockUnavailable extends Error {
466
+ cause;
467
+ constructor(cause) {
468
+ super(`OS socket lock unavailable: ${cause.code ?? cause.message}`);
469
+ this.cause = cause;
470
+ this.name = 'SocketLockUnavailable';
471
+ }
472
+ }
473
+ /**
474
+ * Canonicalize a path to its real filesystem identity so lexical aliases of the
475
+ * same directory (a symlink, a bind-mount path, a Windows junction, a `\\?\`
476
+ * prefix) map to ONE name (#2658 review H1). `lockDir` (the index slot) often
477
+ * does not exist yet, so `realpathSync` the deepest existing ancestor and
478
+ * re-append the not-yet-created remainder. A path with no symlink components
479
+ * realpaths to itself, so the common (non-aliased) case is unchanged — a holder
480
+ * that used the old resolved name is never orphaned.
481
+ */
482
+ const canonicalizeDir = (p) => {
483
+ const resolved = path.resolve(p);
484
+ const tail = [];
485
+ let dir = resolved;
486
+ for (;;) {
487
+ try {
488
+ const real = realpathSync(dir);
489
+ return tail.length ? path.join(real, ...tail.reverse()) : real;
490
+ }
491
+ catch {
492
+ const parent = path.dirname(dir);
493
+ if (parent === dir)
494
+ return resolved; // reached the root with nothing to resolve
495
+ tail.push(path.basename(dir));
496
+ dir = parent;
497
+ }
498
+ }
499
+ };
500
+ /**
501
+ * Stable OS-IPC endpoint name for an index directory. The name is derived from
502
+ * the REAL path (case-folded on Windows), so two processes targeting the same
503
+ * physical slot — even via different lexical aliases — collide, and separate
504
+ * worktrees/branches never do. The endpoint lives OUTSIDE the index directory
505
+ * (abstract namespace / pipe namespace), so the lock needs no filesystem write
506
+ * and is unaffected by a read-only index mount.
507
+ */
508
+ const socketLockName = (lockDir) => {
509
+ const resolved = canonicalizeDir(lockDir);
510
+ const key = createHash('sha256')
511
+ .update(process.platform === 'win32' ? resolved.toLowerCase() : resolved)
512
+ .digest('hex')
513
+ .slice(0, 32);
514
+ return process.platform === 'win32'
515
+ ? `\\\\.\\pipe\\gitnexus-idx-${key}`
516
+ : `\0gitnexus-idx-${key}`; // Linux abstract socket (no filesystem entry)
517
+ };
518
+ /** Attempt to listen; resolve to null on success or the error on failure. */
519
+ const tryListen = (server, name) => new Promise((resolve) => {
520
+ const onError = (err) => {
521
+ server.removeListener('listening', onListening);
522
+ resolve(err);
523
+ };
524
+ const onListening = () => {
525
+ server.removeListener('error', onError);
526
+ resolve(null);
527
+ };
528
+ server.once('error', onError);
529
+ server.once('listening', onListening);
530
+ server.listen(name);
531
+ });
532
+ /**
533
+ * OS-owned socket/pipe backend (Windows named pipe, Linux abstract socket).
534
+ * Holding the lock = holding a listening endpoint the kernel binds to this
535
+ * process; `EADDRINUSE` therefore means a *live* holder, and the kernel drops
536
+ * the binding the instant the holder exits (clean exit, crash, OOM, SIGKILL) —
537
+ * so there is no stale detection, no reclaim, and no takeover race. See the
538
+ * module header for why this is preferred over the file backend.
539
+ */
540
+ const acquireViaSocket = async (lockDir, me, opts) => {
541
+ const name = socketLockName(lockDir);
542
+ const pollMs = opts.pollMs ?? DEFAULT_POLL_MS;
543
+ const timeoutMs = resolveTimeoutMs(opts.timeoutMs);
544
+ const startedAt = Date.now();
545
+ let announcedWait = false;
546
+ let lastDiagnosticAt = 0;
547
+ for (;;) {
548
+ const server = net.createServer();
549
+ // Never keep the process alive on the lock's account, and never hold an
550
+ // incoming connection (nothing should connect; drop any stray peer).
551
+ server.unref();
552
+ server.on('connection', (sock) => sock.destroy());
553
+ const listenErr = await tryListen(server, name);
554
+ if (!listenErr) {
555
+ return {
556
+ record: me,
557
+ release: () => {
558
+ try {
559
+ server.close();
560
+ }
561
+ catch {
562
+ /* already closed / releasing on exit */
563
+ }
564
+ },
565
+ };
566
+ }
567
+ // This server never bound (listen failed); release its handle before the
568
+ // next poll or the fallback, so a long contended wait doesn't churn one
569
+ // unclosed net.Server per iteration (#2658 review L3).
570
+ try {
571
+ server.close();
572
+ }
573
+ catch {
574
+ /* never listened */
575
+ }
576
+ // Only EADDRINUSE means "held by a live holder → wait". Anything else means
577
+ // this environment can't use the socket backend → fall back to the file one.
578
+ if (listenErr.code !== 'EADDRINUSE')
579
+ throw new SocketLockUnavailable(listenErr);
580
+ if (!announcedWait) {
581
+ announcedWait = true;
582
+ opts.onWaitStart?.(me);
583
+ opts.log?.('Another gitnexus analyze is refreshing this index — waiting for it to finish.');
584
+ }
585
+ const waited = Date.now() - startedAt;
586
+ // Socket backend exposes no owner metadata → holder identity is unknown (M3).
587
+ if (waited >= timeoutMs)
588
+ throw new IndexLockTimeoutError(unknownHolder(), waited, false);
589
+ if (Date.now() - lastDiagnosticAt >= DIAGNOSTIC_INTERVAL_MS) {
590
+ lastDiagnosticAt = Date.now();
591
+ if (waited >= DIAGNOSTIC_INTERVAL_MS) {
592
+ opts.log?.(`Still waiting for another analyze (${Math.round(waited / 1000)}s elapsed).`);
593
+ }
594
+ }
595
+ await sleep(jitteredDelay(pollMs, timeoutMs, waited));
596
+ }
597
+ };
598
+ /** Platforms whose OS IPC namespace gives a clean, auto-releasing lock via
599
+ * `net`: Windows named pipes and Linux abstract sockets. Elsewhere (macOS/BSD)
600
+ * the file backend is used (no abstract namespace; filesystem sockets don't
601
+ * release cleanly on death). Override for tests via GITNEXUS_INDEX_LOCK_BACKEND
602
+ * = 'socket' | 'file'.
603
+ *
604
+ * Scope caveat: the socket backend's mutual-exclusion domain is NOT uniform.
605
+ * Windows `\\.\pipe\` names are machine-wide (all sessions); Linux abstract
606
+ * sockets are network-namespace-scoped (network_namespaces(7)). So two writers
607
+ * that share a bind-mounted index dir but sit in separate netns (e.g. two
608
+ * containers, Docker's default) do NOT collide on Linux — "single-host" is
609
+ * really "single-netns" here. That cross-netns-shared-mount case is the one
610
+ * the file backend (shared-filesystem O_EXCL) would cover; set
611
+ * GITNEXUS_INDEX_LOCK_BACKEND=file there. The motivating case (local hook-
612
+ * driven re-index) is single-netns, so the default socket backend covers it. */
613
+ const selectBackend = () => {
614
+ const override = process.env.GITNEXUS_INDEX_LOCK_BACKEND;
615
+ if (override === 'socket' || override === 'file')
616
+ return override;
617
+ return process.platform === 'win32' || process.platform === 'linux' ? 'socket' : 'file';
618
+ };
619
+ /**
620
+ * Acquire the exclusive write lock for `lockDir` (the resolved index slot
621
+ * directory). Uses the OS socket/pipe backend where available (Windows/Linux),
622
+ * falling back to the file backend otherwise or if the socket backend is
623
+ * unusable in this environment. After acquiring, sweeps orphaned staging files
624
+ * under the lock (best-effort; a no-op on a read-only mount). Rejects with
625
+ * `IndexLockTimeoutError` if `timeoutMs` elapses while another live holder holds
626
+ * the lock.
627
+ */
628
+ export const acquireIndexLock = async (lockDir, opts = {}) => {
629
+ const me = buildRecord();
630
+ let handle;
631
+ if (selectBackend() === 'socket') {
632
+ try {
633
+ handle = await acquireViaSocket(lockDir, me, opts);
634
+ }
635
+ catch (err) {
636
+ if (!(err instanceof SocketLockUnavailable))
637
+ throw err; // timeout etc. propagate
638
+ opts.log?.('Index lock: OS socket lock unavailable here — using the file lock.');
639
+ handle = await acquireViaFile(lockDir, me, opts);
640
+ }
641
+ }
642
+ else {
643
+ handle = await acquireViaFile(lockDir, me, opts);
644
+ }
645
+ // Reclaim crashed-build staging orphans while we hold the lock. Best-effort:
646
+ // a read-only mount (no orphans reachable) just no-ops.
647
+ try {
648
+ sweepStagingArtifacts(lockDir, opts.log);
649
+ }
650
+ catch {
651
+ /* best-effort */
652
+ }
653
+ return handle;
654
+ };