cgraphx 2.0.2 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (754) hide show
  1. package/dist/.claude-template/FLOW-MAP.md +13 -3
  2. package/dist/.claude-template/agents/task-history.md +186 -0
  3. package/dist/.claude-template/commands/end.md +1 -0
  4. package/dist/.claude-template/skills/cgraphx-guide/SKILL.md +5 -3
  5. package/dist/.claude-template/skills/cgraphx-guide/how-to-use.html +8 -8
  6. package/dist/.claude-template/skills/cgraphx-guide/how-to-use.md +8 -8
  7. package/dist/.claude-template/skills/clarify-requirements/SKILL.md +13 -9
  8. package/dist/.claude-template/skills/db-query/SKILL.md +19 -2
  9. package/dist/.claude-template/skills/iboc-check/SKILL.md +51 -23
  10. package/dist/.claude-template/skills/iboc-check/filler-prompt.md +3 -4
  11. package/dist/.claude-template/skills/run-api-test/SKILL.md +15 -15
  12. package/dist/.claude-template/skills/run-api-test/assets/{template-test-report.md → template-/346/216/245/345/217/243/346/265/213/350/257/225/346/212/245/345/221/212.md} +4 -4
  13. package/dist/.claude-template/skills/run-api-test/references/bru-run.md +1 -1
  14. package/dist/.claude-template/skills/run-api-test/references/db-verification.md +2 -2
  15. package/dist/.claude-template/skills/run-api-test/references/report-format.md +6 -6
  16. package/dist/.claude-template/skills/run-api-test/references/service-readiness.md +1 -1
  17. package/dist/.claude-template/skills/run-api-test/references/test-scope.md +6 -6
  18. package/dist/.claude-template/skills/run-ui-test/SKILL.md +186 -0
  19. package/dist/.claude-template/skills/run-ui-test/references/report-format.md +77 -0
  20. package/dist/.claude-template/skills/subagent-implement/SKILL.md +3 -2
  21. package/dist/.claude-template/skills/write-api/SKILL.md +18 -18
  22. package/dist/.claude-template/skills/write-api/assets/{template-api-spec.md → template-/346/216/245/345/217/243/346/265/213/350/257/225-spec.md} +1 -1
  23. package/dist/.claude-template/skills/write-api/references/{api-spec-format.md → /346/216/245/345/217/243/346/265/213/350/257/225-spec-format.md} +3 -3
  24. package/dist/.claude-template/skills/write-plan/SKILL.md +4 -2
  25. package/dist/.claude-template/skills/write-ui-test/SKILL.md +125 -0
  26. package/dist/.claude-template/skills/write-ui-test/references//347/224/250/344/276/213/350/247/204/346/240/274-format.md +94 -0
  27. package/dist/core/code/engine/cli/analyze-config.js +320 -0
  28. package/dist/core/code/engine/cli/analyze.js +1086 -0
  29. package/dist/core/code/engine/cli/cli-message.js +83 -0
  30. package/dist/core/code/engine/cli/detect-changes-format.js +58 -0
  31. package/dist/core/code/engine/cli/embedding-dims.js +43 -0
  32. package/dist/core/code/engine/cli/format-elapsed.js +12 -0
  33. package/dist/core/code/engine/cli/help-i18n.js +144 -0
  34. package/dist/core/code/engine/cli/i18n/en.js +110 -0
  35. package/dist/core/code/engine/cli/i18n/index.js +47 -0
  36. package/dist/core/code/engine/cli/i18n/resources.js +9 -0
  37. package/dist/core/code/engine/cli/i18n/zh-CN.js +110 -0
  38. package/dist/core/code/engine/cli/lazy-action.js +67 -0
  39. package/dist/core/code/engine/cli/optional-grammars.js +136 -0
  40. package/dist/core/code/engine/cli/resolve-invocation.js +76 -0
  41. package/dist/core/code/engine/cli/status.js +156 -0
  42. package/dist/core/code/engine/cli/tool.js +384 -0
  43. package/dist/core/code/engine/config/ignore-service.js +511 -0
  44. package/dist/core/code/engine/config/supported-languages.js +17 -0
  45. package/dist/core/code/engine/core/analysis-features.js +64 -0
  46. package/dist/core/code/engine/core/analyzer-identity.js +2171 -0
  47. package/dist/core/code/engine/core/git-staleness.js +180 -0
  48. package/dist/core/code/engine/core/graph/graph.js +180 -0
  49. package/dist/core/code/engine/core/graph/import-cycles.js +106 -0
  50. package/dist/core/code/engine/core/graph/types.js +2 -0
  51. package/dist/core/code/engine/core/index-freshness.js +12 -0
  52. package/dist/core/code/engine/core/ingestion/binding-accumulator.js +341 -0
  53. package/dist/core/code/engine/core/ingestion/call-extractors/configs/c-cpp.js +168 -0
  54. package/dist/core/code/engine/core/ingestion/call-extractors/configs/csharp.js +9 -0
  55. package/dist/core/code/engine/core/ingestion/call-extractors/configs/dart.js +8 -0
  56. package/dist/core/code/engine/core/ingestion/call-extractors/configs/go.js +8 -0
  57. package/dist/core/code/engine/core/ingestion/call-extractors/configs/jvm.js +54 -0
  58. package/dist/core/code/engine/core/ingestion/call-extractors/configs/php.js +8 -0
  59. package/dist/core/code/engine/core/ingestion/call-extractors/configs/python.js +8 -0
  60. package/dist/core/code/engine/core/ingestion/call-extractors/configs/ruby.js +8 -0
  61. package/dist/core/code/engine/core/ingestion/call-extractors/configs/rust.js +8 -0
  62. package/dist/core/code/engine/core/ingestion/call-extractors/configs/swift.js +8 -0
  63. package/dist/core/code/engine/core/ingestion/call-extractors/configs/typescript-javascript.js +11 -0
  64. package/dist/core/code/engine/core/ingestion/call-extractors/generic.js +62 -0
  65. package/dist/core/code/engine/core/ingestion/call-processor.js +503 -0
  66. package/dist/core/code/engine/core/ingestion/call-routing.js +98 -0
  67. package/dist/core/code/engine/core/ingestion/call-types.js +3 -0
  68. package/dist/core/code/engine/core/ingestion/cfg/callee-cell-format.js +45 -0
  69. package/dist/core/code/engine/core/ingestion/cfg/cfg-builder.js +202 -0
  70. package/dist/core/code/engine/core/ingestion/cfg/collect.js +81 -0
  71. package/dist/core/code/engine/core/ingestion/cfg/control-dependence.js +185 -0
  72. package/dist/core/code/engine/core/ingestion/cfg/control-flow-context.js +130 -0
  73. package/dist/core/code/engine/core/ingestion/cfg/emit.js +646 -0
  74. package/dist/core/code/engine/core/ingestion/cfg/post-dominators.js +182 -0
  75. package/dist/core/code/engine/core/ingestion/cfg/reaching-def-reason-codec.js +139 -0
  76. package/dist/core/code/engine/core/ingestion/cfg/reaching-defs-graph.js +322 -0
  77. package/dist/core/code/engine/core/ingestion/cfg/reaching-defs.js +792 -0
  78. package/dist/core/code/engine/core/ingestion/cfg/synthetic-escape.js +305 -0
  79. package/dist/core/code/engine/core/ingestion/cfg/traversal-result.js +6 -0
  80. package/dist/core/code/engine/core/ingestion/cfg/types.js +14 -0
  81. package/dist/core/code/engine/core/ingestion/cfg/visitors/c-cpp-harvest.js +545 -0
  82. package/dist/core/code/engine/core/ingestion/cfg/visitors/c-cpp.js +590 -0
  83. package/dist/core/code/engine/core/ingestion/cfg/visitors/call-site-harvest.js +356 -0
  84. package/dist/core/code/engine/core/ingestion/cfg/visitors/csharp-harvest.js +593 -0
  85. package/dist/core/code/engine/core/ingestion/cfg/visitors/csharp.js +871 -0
  86. package/dist/core/code/engine/core/ingestion/cfg/visitors/dart-harvest.js +874 -0
  87. package/dist/core/code/engine/core/ingestion/cfg/visitors/dart.js +840 -0
  88. package/dist/core/code/engine/core/ingestion/cfg/visitors/go-harvest.js +625 -0
  89. package/dist/core/code/engine/core/ingestion/cfg/visitors/go.js +642 -0
  90. package/dist/core/code/engine/core/ingestion/cfg/visitors/java-harvest.js +517 -0
  91. package/dist/core/code/engine/core/ingestion/cfg/visitors/java.js +816 -0
  92. package/dist/core/code/engine/core/ingestion/cfg/visitors/kotlin-harvest.js +723 -0
  93. package/dist/core/code/engine/core/ingestion/cfg/visitors/kotlin.js +813 -0
  94. package/dist/core/code/engine/core/ingestion/cfg/visitors/php-harvest.js +630 -0
  95. package/dist/core/code/engine/core/ingestion/cfg/visitors/php.js +725 -0
  96. package/dist/core/code/engine/core/ingestion/cfg/visitors/python-harvest.js +776 -0
  97. package/dist/core/code/engine/core/ingestion/cfg/visitors/python.js +562 -0
  98. package/dist/core/code/engine/core/ingestion/cfg/visitors/ruby-harvest.js +591 -0
  99. package/dist/core/code/engine/core/ingestion/cfg/visitors/ruby.js +760 -0
  100. package/dist/core/code/engine/core/ingestion/cfg/visitors/rust-harvest.js +877 -0
  101. package/dist/core/code/engine/core/ingestion/cfg/visitors/rust.js +562 -0
  102. package/dist/core/code/engine/core/ingestion/cfg/visitors/scope-tree-harvest.js +120 -0
  103. package/dist/core/code/engine/core/ingestion/cfg/visitors/swift-harvest.js +683 -0
  104. package/dist/core/code/engine/core/ingestion/cfg/visitors/swift.js +791 -0
  105. package/dist/core/code/engine/core/ingestion/cfg/visitors/typescript-harvest.js +1060 -0
  106. package/dist/core/code/engine/core/ingestion/cfg/visitors/typescript.js +587 -0
  107. package/dist/core/code/engine/core/ingestion/class-extractors/configs/c-cpp.js +77 -0
  108. package/dist/core/code/engine/core/ingestion/class-extractors/configs/csharp.js +24 -0
  109. package/dist/core/code/engine/core/ingestion/class-extractors/configs/dart.js +10 -0
  110. package/dist/core/code/engine/core/ingestion/class-extractors/configs/go.js +28 -0
  111. package/dist/core/code/engine/core/ingestion/class-extractors/configs/jvm.js +67 -0
  112. package/dist/core/code/engine/core/ingestion/class-extractors/configs/php.js +10 -0
  113. package/dist/core/code/engine/core/ingestion/class-extractors/configs/python.js +10 -0
  114. package/dist/core/code/engine/core/ingestion/class-extractors/configs/ruby.js +13 -0
  115. package/dist/core/code/engine/core/ingestion/class-extractors/configs/rust.js +10 -0
  116. package/dist/core/code/engine/core/ingestion/class-extractors/configs/swift.js +21 -0
  117. package/dist/core/code/engine/core/ingestion/class-extractors/configs/typescript-javascript.js +31 -0
  118. package/dist/core/code/engine/core/ingestion/class-extractors/generic.js +144 -0
  119. package/dist/core/code/engine/core/ingestion/class-types.js +2 -0
  120. package/dist/core/code/engine/core/ingestion/cluster-enricher.js +174 -0
  121. package/dist/core/code/engine/core/ingestion/community-processor.js +604 -0
  122. package/dist/core/code/engine/core/ingestion/constants.js +26 -0
  123. package/dist/core/code/engine/core/ingestion/cpp-ue-preprocessor.js +263 -0
  124. package/dist/core/code/engine/core/ingestion/csharp-namespace-gate.js +133 -0
  125. package/dist/core/code/engine/core/ingestion/di-extractors/index.js +38 -0
  126. package/dist/core/code/engine/core/ingestion/di-extractors/spring.js +310 -0
  127. package/dist/core/code/engine/core/ingestion/emit-references.js +244 -0
  128. package/dist/core/code/engine/core/ingestion/entry-point-scoring.js +201 -0
  129. package/dist/core/code/engine/core/ingestion/export-detection.js +244 -0
  130. package/dist/core/code/engine/core/ingestion/field-extractor.js +29 -0
  131. package/dist/core/code/engine/core/ingestion/field-extractors/configs/c-cpp.js +107 -0
  132. package/dist/core/code/engine/core/ingestion/field-extractors/configs/csharp.js +124 -0
  133. package/dist/core/code/engine/core/ingestion/field-extractors/configs/dart.js +99 -0
  134. package/dist/core/code/engine/core/ingestion/field-extractors/configs/go.js +102 -0
  135. package/dist/core/code/engine/core/ingestion/field-extractors/configs/helpers.js +198 -0
  136. package/dist/core/code/engine/core/ingestion/field-extractors/configs/jvm.js +172 -0
  137. package/dist/core/code/engine/core/ingestion/field-extractors/configs/php.js +67 -0
  138. package/dist/core/code/engine/core/ingestion/field-extractors/configs/python.js +94 -0
  139. package/dist/core/code/engine/core/ingestion/field-extractors/configs/ruby.js +79 -0
  140. package/dist/core/code/engine/core/ingestion/field-extractors/configs/rust.js +55 -0
  141. package/dist/core/code/engine/core/ingestion/field-extractors/configs/swift.js +93 -0
  142. package/dist/core/code/engine/core/ingestion/field-extractors/configs/typescript-javascript.js +59 -0
  143. package/dist/core/code/engine/core/ingestion/field-extractors/generic.js +147 -0
  144. package/dist/core/code/engine/core/ingestion/field-extractors/typescript.js +266 -0
  145. package/dist/core/code/engine/core/ingestion/field-types.js +3 -0
  146. package/dist/core/code/engine/core/ingestion/filesystem-walker.js +136 -0
  147. package/dist/core/code/engine/core/ingestion/finalize-orchestrator.js +159 -0
  148. package/dist/core/code/engine/core/ingestion/framework-detection.js +432 -0
  149. package/dist/core/code/engine/core/ingestion/frameworks/spring/analysis-features.js +38 -0
  150. package/dist/core/code/engine/core/ingestion/frameworks/spring/annotation-arguments.js +234 -0
  151. package/dist/core/code/engine/core/ingestion/frameworks/spring/aop-candidates.js +88 -0
  152. package/dist/core/code/engine/core/ingestion/frameworks/spring/aop.js +487 -0
  153. package/dist/core/code/engine/core/ingestion/frameworks/spring/auto-configuration.js +21 -0
  154. package/dist/core/code/engine/core/ingestion/frameworks/spring/bean-candidates.js +189 -0
  155. package/dist/core/code/engine/core/ingestion/frameworks/spring/bean-catalog.js +32 -0
  156. package/dist/core/code/engine/core/ingestion/frameworks/spring/bean-factories.js +73 -0
  157. package/dist/core/code/engine/core/ingestion/frameworks/spring/conditionals.js +323 -0
  158. package/dist/core/code/engine/core/ingestion/frameworks/spring/config-bindings.js +119 -0
  159. package/dist/core/code/engine/core/ingestion/frameworks/spring/di-metadata.js +385 -0
  160. package/dist/core/code/engine/core/ingestion/frameworks/spring/resource-injection.js +96 -0
  161. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/c-cpp.js +17 -0
  162. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/csharp.js +46 -0
  163. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/dart.js +59 -0
  164. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/go.js +30 -0
  165. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/jvm.js +73 -0
  166. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/php.js +19 -0
  167. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/python.js +45 -0
  168. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/ruby.js +20 -0
  169. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/rust.js +58 -0
  170. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/swift.js +94 -0
  171. package/dist/core/code/engine/core/ingestion/import-resolvers/configs/typescript-javascript.js +26 -0
  172. package/dist/core/code/engine/core/ingestion/import-resolvers/csharp.js +128 -0
  173. package/dist/core/code/engine/core/ingestion/import-resolvers/go.js +50 -0
  174. package/dist/core/code/engine/core/ingestion/import-resolvers/jvm.js +112 -0
  175. package/dist/core/code/engine/core/ingestion/import-resolvers/php.js +80 -0
  176. package/dist/core/code/engine/core/ingestion/import-resolvers/python.js +75 -0
  177. package/dist/core/code/engine/core/ingestion/import-resolvers/resolver-factory.js +36 -0
  178. package/dist/core/code/engine/core/ingestion/import-resolvers/ruby.js +20 -0
  179. package/dist/core/code/engine/core/ingestion/import-resolvers/rust.js +79 -0
  180. package/dist/core/code/engine/core/ingestion/import-resolvers/standard.js +180 -0
  181. package/dist/core/code/engine/core/ingestion/import-resolvers/types.js +7 -0
  182. package/dist/core/code/engine/core/ingestion/import-resolvers/utils.js +153 -0
  183. package/dist/core/code/engine/core/ingestion/import-target-adapter.js +99 -0
  184. package/dist/core/code/engine/core/ingestion/language-config.js +391 -0
  185. package/dist/core/code/engine/core/ingestion/language-provider.js +25 -0
  186. package/dist/core/code/engine/core/ingestion/languages/c/arity-metadata.js +98 -0
  187. package/dist/core/code/engine/core/ingestion/languages/c/arity.js +21 -0
  188. package/dist/core/code/engine/core/ingestion/languages/c/capture-side-channel.js +69 -0
  189. package/dist/core/code/engine/core/ingestion/languages/c/captures.js +189 -0
  190. package/dist/core/code/engine/core/ingestion/languages/c/header-scan.js +58 -0
  191. package/dist/core/code/engine/core/ingestion/languages/c/import-decomposer.js +68 -0
  192. package/dist/core/code/engine/core/ingestion/languages/c/import-target.js +103 -0
  193. package/dist/core/code/engine/core/ingestion/languages/c/index.js +33 -0
  194. package/dist/core/code/engine/core/ingestion/languages/c/interpret.js +53 -0
  195. package/dist/core/code/engine/core/ingestion/languages/c/merge-bindings.js +26 -0
  196. package/dist/core/code/engine/core/ingestion/languages/c/query.js +210 -0
  197. package/dist/core/code/engine/core/ingestion/languages/c/scope-resolver.js +112 -0
  198. package/dist/core/code/engine/core/ingestion/languages/c/simple-hooks.js +24 -0
  199. package/dist/core/code/engine/core/ingestion/languages/c/static-linkage.js +109 -0
  200. package/dist/core/code/engine/core/ingestion/languages/c-cpp.js +506 -0
  201. package/dist/core/code/engine/core/ingestion/languages/cpp/adl.js +804 -0
  202. package/dist/core/code/engine/core/ingestion/languages/cpp/arity-metadata.js +258 -0
  203. package/dist/core/code/engine/core/ingestion/languages/cpp/arity.js +37 -0
  204. package/dist/core/code/engine/core/ingestion/languages/cpp/capture-side-channel.js +89 -0
  205. package/dist/core/code/engine/core/ingestion/languages/cpp/captures.js +1975 -0
  206. package/dist/core/code/engine/core/ingestion/languages/cpp/constraint-extractor.js +311 -0
  207. package/dist/core/code/engine/core/ingestion/languages/cpp/constraint-filter.js +210 -0
  208. package/dist/core/code/engine/core/ingestion/languages/cpp/conversion-rank.js +163 -0
  209. package/dist/core/code/engine/core/ingestion/languages/cpp/file-local-linkage.js +327 -0
  210. package/dist/core/code/engine/core/ingestion/languages/cpp/header-scan.js +53 -0
  211. package/dist/core/code/engine/core/ingestion/languages/cpp/import-decomposer.js +134 -0
  212. package/dist/core/code/engine/core/ingestion/languages/cpp/import-target.js +16 -0
  213. package/dist/core/code/engine/core/ingestion/languages/cpp/index.js +33 -0
  214. package/dist/core/code/engine/core/ingestion/languages/cpp/inline-namespaces.js +379 -0
  215. package/dist/core/code/engine/core/ingestion/languages/cpp/interpret.js +239 -0
  216. package/dist/core/code/engine/core/ingestion/languages/cpp/member-lookup.js +470 -0
  217. package/dist/core/code/engine/core/ingestion/languages/cpp/merge-bindings.js +32 -0
  218. package/dist/core/code/engine/core/ingestion/languages/cpp/query.js +763 -0
  219. package/dist/core/code/engine/core/ingestion/languages/cpp/range-bindings.js +230 -0
  220. package/dist/core/code/engine/core/ingestion/languages/cpp/scope-resolver.js +354 -0
  221. package/dist/core/code/engine/core/ingestion/languages/cpp/simple-hooks.js +67 -0
  222. package/dist/core/code/engine/core/ingestion/languages/cpp/two-phase-lookup.js +348 -0
  223. package/dist/core/code/engine/core/ingestion/languages/cpp/type-classifier.js +56 -0
  224. package/dist/core/code/engine/core/ingestion/languages/cpp/user-defined-conversions.js +128 -0
  225. package/dist/core/code/engine/core/ingestion/languages/csharp/accessor-unwrap.js +67 -0
  226. package/dist/core/code/engine/core/ingestion/languages/csharp/arity-metadata.js +49 -0
  227. package/dist/core/code/engine/core/ingestion/languages/csharp/arity.js +40 -0
  228. package/dist/core/code/engine/core/ingestion/languages/csharp/cache-stats.js +32 -0
  229. package/dist/core/code/engine/core/ingestion/languages/csharp/captures.js +557 -0
  230. package/dist/core/code/engine/core/ingestion/languages/csharp/import-decomposer.js +96 -0
  231. package/dist/core/code/engine/core/ingestion/languages/csharp/import-target.js +176 -0
  232. package/dist/core/code/engine/core/ingestion/languages/csharp/index.js +95 -0
  233. package/dist/core/code/engine/core/ingestion/languages/csharp/interpret.js +150 -0
  234. package/dist/core/code/engine/core/ingestion/languages/csharp/merge-bindings.js +58 -0
  235. package/dist/core/code/engine/core/ingestion/languages/csharp/namespace-siblings.js +708 -0
  236. package/dist/core/code/engine/core/ingestion/languages/csharp/qualified-type-names.js +62 -0
  237. package/dist/core/code/engine/core/ingestion/languages/csharp/query.js +578 -0
  238. package/dist/core/code/engine/core/ingestion/languages/csharp/receiver-binding.js +142 -0
  239. package/dist/core/code/engine/core/ingestion/languages/csharp/resolution-config.js +18 -0
  240. package/dist/core/code/engine/core/ingestion/languages/csharp/scope-resolver.js +84 -0
  241. package/dist/core/code/engine/core/ingestion/languages/csharp/simple-hooks.js +81 -0
  242. package/dist/core/code/engine/core/ingestion/languages/csharp.js +204 -0
  243. package/dist/core/code/engine/core/ingestion/languages/dart/arity-metadata.js +38 -0
  244. package/dist/core/code/engine/core/ingestion/languages/dart/arity.js +34 -0
  245. package/dist/core/code/engine/core/ingestion/languages/dart/built-ins.js +37 -0
  246. package/dist/core/code/engine/core/ingestion/languages/dart/cache-stats.js +30 -0
  247. package/dist/core/code/engine/core/ingestion/languages/dart/captures.js +1096 -0
  248. package/dist/core/code/engine/core/ingestion/languages/dart/expand-wildcards.js +34 -0
  249. package/dist/core/code/engine/core/ingestion/languages/dart/extension-type-preprocess.js +33 -0
  250. package/dist/core/code/engine/core/ingestion/languages/dart/import-target.js +68 -0
  251. package/dist/core/code/engine/core/ingestion/languages/dart/index.js +45 -0
  252. package/dist/core/code/engine/core/ingestion/languages/dart/interpret.js +101 -0
  253. package/dist/core/code/engine/core/ingestion/languages/dart/merge-bindings.js +42 -0
  254. package/dist/core/code/engine/core/ingestion/languages/dart/query.js +246 -0
  255. package/dist/core/code/engine/core/ingestion/languages/dart/receiver-binding.js +90 -0
  256. package/dist/core/code/engine/core/ingestion/languages/dart/scope-resolver.js +197 -0
  257. package/dist/core/code/engine/core/ingestion/languages/dart/signature-bindings.js +54 -0
  258. package/dist/core/code/engine/core/ingestion/languages/dart/simple-hooks.js +61 -0
  259. package/dist/core/code/engine/core/ingestion/languages/dart.js +138 -0
  260. package/dist/core/code/engine/core/ingestion/languages/go/arity-metadata.js +71 -0
  261. package/dist/core/code/engine/core/ingestion/languages/go/arity.js +17 -0
  262. package/dist/core/code/engine/core/ingestion/languages/go/cache-stats.js +21 -0
  263. package/dist/core/code/engine/core/ingestion/languages/go/captures.js +492 -0
  264. package/dist/core/code/engine/core/ingestion/languages/go/expand-wildcards.js +97 -0
  265. package/dist/core/code/engine/core/ingestion/languages/go/generic-type-parameters.js +146 -0
  266. package/dist/core/code/engine/core/ingestion/languages/go/import-decomposer.js +47 -0
  267. package/dist/core/code/engine/core/ingestion/languages/go/import-target.js +70 -0
  268. package/dist/core/code/engine/core/ingestion/languages/go/index.js +39 -0
  269. package/dist/core/code/engine/core/ingestion/languages/go/interface-impls.js +955 -0
  270. package/dist/core/code/engine/core/ingestion/languages/go/interpret.js +177 -0
  271. package/dist/core/code/engine/core/ingestion/languages/go/merge-bindings.js +21 -0
  272. package/dist/core/code/engine/core/ingestion/languages/go/method-owners.js +131 -0
  273. package/dist/core/code/engine/core/ingestion/languages/go/namespace-mirror.js +56 -0
  274. package/dist/core/code/engine/core/ingestion/languages/go/package-clause.js +79 -0
  275. package/dist/core/code/engine/core/ingestion/languages/go/package-siblings.js +83 -0
  276. package/dist/core/code/engine/core/ingestion/languages/go/query.js +298 -0
  277. package/dist/core/code/engine/core/ingestion/languages/go/range-binding.js +127 -0
  278. package/dist/core/code/engine/core/ingestion/languages/go/receiver-binding.js +24 -0
  279. package/dist/core/code/engine/core/ingestion/languages/go/scope-resolver.js +75 -0
  280. package/dist/core/code/engine/core/ingestion/languages/go/simple-hooks.js +31 -0
  281. package/dist/core/code/engine/core/ingestion/languages/go/type-binding.js +279 -0
  282. package/dist/core/code/engine/core/ingestion/languages/go.js +160 -0
  283. package/dist/core/code/engine/core/ingestion/languages/index.js +66 -0
  284. package/dist/core/code/engine/core/ingestion/languages/java/analysis-features.js +16 -0
  285. package/dist/core/code/engine/core/ingestion/languages/java/arity-metadata.js +43 -0
  286. package/dist/core/code/engine/core/ingestion/languages/java/arity.js +27 -0
  287. package/dist/core/code/engine/core/ingestion/languages/java/cache-stats.js +32 -0
  288. package/dist/core/code/engine/core/ingestion/languages/java/capture-side-channel.js +123 -0
  289. package/dist/core/code/engine/core/ingestion/languages/java/captures.js +791 -0
  290. package/dist/core/code/engine/core/ingestion/languages/java/import-decomposer.js +88 -0
  291. package/dist/core/code/engine/core/ingestion/languages/java/import-target.js +103 -0
  292. package/dist/core/code/engine/core/ingestion/languages/java/index.js +43 -0
  293. package/dist/core/code/engine/core/ingestion/languages/java/interpret.js +146 -0
  294. package/dist/core/code/engine/core/ingestion/languages/java/merge-bindings.js +43 -0
  295. package/dist/core/code/engine/core/ingestion/languages/java/package-facts.js +16 -0
  296. package/dist/core/code/engine/core/ingestion/languages/java/package-siblings.js +11 -0
  297. package/dist/core/code/engine/core/ingestion/languages/java/query.js +319 -0
  298. package/dist/core/code/engine/core/ingestion/languages/java/receiver-binding.js +98 -0
  299. package/dist/core/code/engine/core/ingestion/languages/java/scope-resolver.js +213 -0
  300. package/dist/core/code/engine/core/ingestion/languages/java/simple-hooks.js +39 -0
  301. package/dist/core/code/engine/core/ingestion/languages/java/spring-aop.js +53 -0
  302. package/dist/core/code/engine/core/ingestion/languages/java/spring-bean-metadata.js +11 -0
  303. package/dist/core/code/engine/core/ingestion/languages/java/spring-conditionals.js +52 -0
  304. package/dist/core/code/engine/core/ingestion/languages/java/spring-config-bindings.js +222 -0
  305. package/dist/core/code/engine/core/ingestion/languages/java/spring-di.js +165 -0
  306. package/dist/core/code/engine/core/ingestion/languages/java.js +192 -0
  307. package/dist/core/code/engine/core/ingestion/languages/javascript/arity.js +15 -0
  308. package/dist/core/code/engine/core/ingestion/languages/javascript/captures.js +1122 -0
  309. package/dist/core/code/engine/core/ingestion/languages/javascript/import-target.js +56 -0
  310. package/dist/core/code/engine/core/ingestion/languages/javascript/index.js +109 -0
  311. package/dist/core/code/engine/core/ingestion/languages/javascript/interpret.js +45 -0
  312. package/dist/core/code/engine/core/ingestion/languages/javascript/merge-bindings.js +21 -0
  313. package/dist/core/code/engine/core/ingestion/languages/javascript/query.js +659 -0
  314. package/dist/core/code/engine/core/ingestion/languages/javascript/scope-resolver.js +78 -0
  315. package/dist/core/code/engine/core/ingestion/languages/javascript/simple-hooks.js +44 -0
  316. package/dist/core/code/engine/core/ingestion/languages/jvm/package-facts.js +46 -0
  317. package/dist/core/code/engine/core/ingestion/languages/jvm/package-siblings.js +200 -0
  318. package/dist/core/code/engine/core/ingestion/languages/kotlin/arity-metadata.js +23 -0
  319. package/dist/core/code/engine/core/ingestion/languages/kotlin/arity.js +18 -0
  320. package/dist/core/code/engine/core/ingestion/languages/kotlin/cache-stats.js +21 -0
  321. package/dist/core/code/engine/core/ingestion/languages/kotlin/capture-side-channel.js +160 -0
  322. package/dist/core/code/engine/core/ingestion/languages/kotlin/captures.js +1262 -0
  323. package/dist/core/code/engine/core/ingestion/languages/kotlin/companion-scopes.js +72 -0
  324. package/dist/core/code/engine/core/ingestion/languages/kotlin/import-decomposer.js +40 -0
  325. package/dist/core/code/engine/core/ingestion/languages/kotlin/import-target.js +135 -0
  326. package/dist/core/code/engine/core/ingestion/languages/kotlin/index.js +26 -0
  327. package/dist/core/code/engine/core/ingestion/languages/kotlin/interpret.js +75 -0
  328. package/dist/core/code/engine/core/ingestion/languages/kotlin/merge-bindings.js +28 -0
  329. package/dist/core/code/engine/core/ingestion/languages/kotlin/owners.js +134 -0
  330. package/dist/core/code/engine/core/ingestion/languages/kotlin/package-facts.js +16 -0
  331. package/dist/core/code/engine/core/ingestion/languages/kotlin/package-siblings.js +11 -0
  332. package/dist/core/code/engine/core/ingestion/languages/kotlin/query.js +243 -0
  333. package/dist/core/code/engine/core/ingestion/languages/kotlin/receiver-binding.js +103 -0
  334. package/dist/core/code/engine/core/ingestion/languages/kotlin/scope-resolver.js +207 -0
  335. package/dist/core/code/engine/core/ingestion/languages/kotlin/simple-hooks.js +42 -0
  336. package/dist/core/code/engine/core/ingestion/languages/kotlin/spring-aop.js +68 -0
  337. package/dist/core/code/engine/core/ingestion/languages/kotlin/spring-bean-metadata.js +11 -0
  338. package/dist/core/code/engine/core/ingestion/languages/kotlin/spring-conditionals.js +53 -0
  339. package/dist/core/code/engine/core/ingestion/languages/kotlin/spring-di.js +304 -0
  340. package/dist/core/code/engine/core/ingestion/languages/kotlin.js +189 -0
  341. package/dist/core/code/engine/core/ingestion/languages/php/arity-metadata.js +66 -0
  342. package/dist/core/code/engine/core/ingestion/languages/php/arity.js +43 -0
  343. package/dist/core/code/engine/core/ingestion/languages/php/cache-stats.js +32 -0
  344. package/dist/core/code/engine/core/ingestion/languages/php/captures.js +1166 -0
  345. package/dist/core/code/engine/core/ingestion/languages/php/import-decomposer.js +238 -0
  346. package/dist/core/code/engine/core/ingestion/languages/php/import-target.js +213 -0
  347. package/dist/core/code/engine/core/ingestion/languages/php/index.js +85 -0
  348. package/dist/core/code/engine/core/ingestion/languages/php/interpret.js +256 -0
  349. package/dist/core/code/engine/core/ingestion/languages/php/merge-bindings.js +50 -0
  350. package/dist/core/code/engine/core/ingestion/languages/php/namespace-siblings.js +353 -0
  351. package/dist/core/code/engine/core/ingestion/languages/php/query.js +391 -0
  352. package/dist/core/code/engine/core/ingestion/languages/php/receiver-binding.js +135 -0
  353. package/dist/core/code/engine/core/ingestion/languages/php/scope-resolver.js +361 -0
  354. package/dist/core/code/engine/core/ingestion/languages/php/simple-hooks.js +116 -0
  355. package/dist/core/code/engine/core/ingestion/languages/php.js +302 -0
  356. package/dist/core/code/engine/core/ingestion/languages/python/arity-metadata.js +49 -0
  357. package/dist/core/code/engine/core/ingestion/languages/python/arity.js +41 -0
  358. package/dist/core/code/engine/core/ingestion/languages/python/cache-stats.js +34 -0
  359. package/dist/core/code/engine/core/ingestion/languages/python/captures.js +299 -0
  360. package/dist/core/code/engine/core/ingestion/languages/python/depends-references.js +68 -0
  361. package/dist/core/code/engine/core/ingestion/languages/python/import-decomposer.js +115 -0
  362. package/dist/core/code/engine/core/ingestion/languages/python/import-target.js +440 -0
  363. package/dist/core/code/engine/core/ingestion/languages/python/index-stats.js +30 -0
  364. package/dist/core/code/engine/core/ingestion/languages/python/index.js +96 -0
  365. package/dist/core/code/engine/core/ingestion/languages/python/interpret.js +430 -0
  366. package/dist/core/code/engine/core/ingestion/languages/python/merge-bindings.js +47 -0
  367. package/dist/core/code/engine/core/ingestion/languages/python/query.js +323 -0
  368. package/dist/core/code/engine/core/ingestion/languages/python/receiver-binding.js +310 -0
  369. package/dist/core/code/engine/core/ingestion/languages/python/scope-resolver.js +80 -0
  370. package/dist/core/code/engine/core/ingestion/languages/python/simple-hooks.js +53 -0
  371. package/dist/core/code/engine/core/ingestion/languages/python.js +140 -0
  372. package/dist/core/code/engine/core/ingestion/languages/ruby/arity.js +41 -0
  373. package/dist/core/code/engine/core/ingestion/languages/ruby/cache-stats.js +21 -0
  374. package/dist/core/code/engine/core/ingestion/languages/ruby/captures.js +864 -0
  375. package/dist/core/code/engine/core/ingestion/languages/ruby/import-target.js +88 -0
  376. package/dist/core/code/engine/core/ingestion/languages/ruby/index.js +29 -0
  377. package/dist/core/code/engine/core/ingestion/languages/ruby/interpret.js +115 -0
  378. package/dist/core/code/engine/core/ingestion/languages/ruby/merge-bindings.js +21 -0
  379. package/dist/core/code/engine/core/ingestion/languages/ruby/query.js +349 -0
  380. package/dist/core/code/engine/core/ingestion/languages/ruby/receiver-binding.js +70 -0
  381. package/dist/core/code/engine/core/ingestion/languages/ruby/scope-resolver.js +263 -0
  382. package/dist/core/code/engine/core/ingestion/languages/ruby/simple-hooks.js +68 -0
  383. package/dist/core/code/engine/core/ingestion/languages/ruby.js +215 -0
  384. package/dist/core/code/engine/core/ingestion/languages/rust/arity.js +16 -0
  385. package/dist/core/code/engine/core/ingestion/languages/rust/cache-stats.js +21 -0
  386. package/dist/core/code/engine/core/ingestion/languages/rust/captures.js +304 -0
  387. package/dist/core/code/engine/core/ingestion/languages/rust/import-decomposer.js +167 -0
  388. package/dist/core/code/engine/core/ingestion/languages/rust/import-target.js +108 -0
  389. package/dist/core/code/engine/core/ingestion/languages/rust/index.js +29 -0
  390. package/dist/core/code/engine/core/ingestion/languages/rust/interpret.js +201 -0
  391. package/dist/core/code/engine/core/ingestion/languages/rust/merge-bindings.js +21 -0
  392. package/dist/core/code/engine/core/ingestion/languages/rust/method-owners.js +76 -0
  393. package/dist/core/code/engine/core/ingestion/languages/rust/module-path.js +222 -0
  394. package/dist/core/code/engine/core/ingestion/languages/rust/qualified-call.js +482 -0
  395. package/dist/core/code/engine/core/ingestion/languages/rust/query.js +280 -0
  396. package/dist/core/code/engine/core/ingestion/languages/rust/range-binding.js +687 -0
  397. package/dist/core/code/engine/core/ingestion/languages/rust/receiver-binding.js +148 -0
  398. package/dist/core/code/engine/core/ingestion/languages/rust/scope-resolver.js +151 -0
  399. package/dist/core/code/engine/core/ingestion/languages/rust/simple-hooks.js +32 -0
  400. package/dist/core/code/engine/core/ingestion/languages/rust.js +183 -0
  401. package/dist/core/code/engine/core/ingestion/languages/swift/arity-metadata.js +44 -0
  402. package/dist/core/code/engine/core/ingestion/languages/swift/arity.js +45 -0
  403. package/dist/core/code/engine/core/ingestion/languages/swift/base-type.js +30 -0
  404. package/dist/core/code/engine/core/ingestion/languages/swift/cache-stats.js +32 -0
  405. package/dist/core/code/engine/core/ingestion/languages/swift/captures.js +594 -0
  406. package/dist/core/code/engine/core/ingestion/languages/swift/conditional-directive-preprocess.js +256 -0
  407. package/dist/core/code/engine/core/ingestion/languages/swift/implicit-imports.js +60 -0
  408. package/dist/core/code/engine/core/ingestion/languages/swift/import-decomposer.js +87 -0
  409. package/dist/core/code/engine/core/ingestion/languages/swift/import-target.js +84 -0
  410. package/dist/core/code/engine/core/ingestion/languages/swift/index.js +56 -0
  411. package/dist/core/code/engine/core/ingestion/languages/swift/interpret.js +93 -0
  412. package/dist/core/code/engine/core/ingestion/languages/swift/merge-bindings.js +51 -0
  413. package/dist/core/code/engine/core/ingestion/languages/swift/query.js +226 -0
  414. package/dist/core/code/engine/core/ingestion/languages/swift/receiver-binding.js +169 -0
  415. package/dist/core/code/engine/core/ingestion/languages/swift/scope-resolver.js +192 -0
  416. package/dist/core/code/engine/core/ingestion/languages/swift/sibling-type-bindings.js +68 -0
  417. package/dist/core/code/engine/core/ingestion/languages/swift/signature-bindings.js +69 -0
  418. package/dist/core/code/engine/core/ingestion/languages/swift/simple-hooks.js +65 -0
  419. package/dist/core/code/engine/core/ingestion/languages/swift/target-grouping.js +97 -0
  420. package/dist/core/code/engine/core/ingestion/languages/swift/target-siblings.js +74 -0
  421. package/dist/core/code/engine/core/ingestion/languages/swift.js +246 -0
  422. package/dist/core/code/engine/core/ingestion/languages/typescript/arity-metadata.js +106 -0
  423. package/dist/core/code/engine/core/ingestion/languages/typescript/arity.js +57 -0
  424. package/dist/core/code/engine/core/ingestion/languages/typescript/array-callback.js +58 -0
  425. package/dist/core/code/engine/core/ingestion/languages/typescript/cache-stats.js +34 -0
  426. package/dist/core/code/engine/core/ingestion/languages/typescript/captures.js +956 -0
  427. package/dist/core/code/engine/core/ingestion/languages/typescript/cjs-export-assignment.js +535 -0
  428. package/dist/core/code/engine/core/ingestion/languages/typescript/cjs-module-exports.js +196 -0
  429. package/dist/core/code/engine/core/ingestion/languages/typescript/import-decomposer.js +374 -0
  430. package/dist/core/code/engine/core/ingestion/languages/typescript/import-target.js +65 -0
  431. package/dist/core/code/engine/core/ingestion/languages/typescript/index.js +108 -0
  432. package/dist/core/code/engine/core/ingestion/languages/typescript/interpret.js +344 -0
  433. package/dist/core/code/engine/core/ingestion/languages/typescript/merge-bindings.js +161 -0
  434. package/dist/core/code/engine/core/ingestion/languages/typescript/nuxt-auto-imports.js +325 -0
  435. package/dist/core/code/engine/core/ingestion/languages/typescript/query.js +1328 -0
  436. package/dist/core/code/engine/core/ingestion/languages/typescript/receiver-binding.js +201 -0
  437. package/dist/core/code/engine/core/ingestion/languages/typescript/scope-resolver.js +293 -0
  438. package/dist/core/code/engine/core/ingestion/languages/typescript/simple-hooks.js +139 -0
  439. package/dist/core/code/engine/core/ingestion/languages/typescript.js +455 -0
  440. package/dist/core/code/engine/core/ingestion/languages/vue/captures.js +70 -0
  441. package/dist/core/code/engine/core/ingestion/languages/vue/import-target.js +61 -0
  442. package/dist/core/code/engine/core/ingestion/languages/vue/index.js +55 -0
  443. package/dist/core/code/engine/core/ingestion/languages/vue/scope-resolver.js +295 -0
  444. package/dist/core/code/engine/core/ingestion/languages/vue.js +96 -0
  445. package/dist/core/code/engine/core/ingestion/local-symbol-pruner.js +68 -0
  446. package/dist/core/code/engine/core/ingestion/method-extractors/configs/c-cpp.js +387 -0
  447. package/dist/core/code/engine/core/ingestion/method-extractors/configs/csharp.js +290 -0
  448. package/dist/core/code/engine/core/ingestion/method-extractors/configs/dart.js +392 -0
  449. package/dist/core/code/engine/core/ingestion/method-extractors/configs/go.js +179 -0
  450. package/dist/core/code/engine/core/ingestion/method-extractors/configs/jvm.js +350 -0
  451. package/dist/core/code/engine/core/ingestion/method-extractors/configs/php.js +306 -0
  452. package/dist/core/code/engine/core/ingestion/method-extractors/configs/python.js +312 -0
  453. package/dist/core/code/engine/core/ingestion/method-extractors/configs/ruby.js +289 -0
  454. package/dist/core/code/engine/core/ingestion/method-extractors/configs/rust.js +198 -0
  455. package/dist/core/code/engine/core/ingestion/method-extractors/configs/swift.js +286 -0
  456. package/dist/core/code/engine/core/ingestion/method-extractors/configs/typescript-javascript.js +341 -0
  457. package/dist/core/code/engine/core/ingestion/method-extractors/generic.js +209 -0
  458. package/dist/core/code/engine/core/ingestion/method-types.js +3 -0
  459. package/dist/core/code/engine/core/ingestion/model/field-registry.js +41 -0
  460. package/dist/core/code/engine/core/ingestion/model/index.js +52 -0
  461. package/dist/core/code/engine/core/ingestion/model/method-registry.js +138 -0
  462. package/dist/core/code/engine/core/ingestion/model/owned-members-lookup.js +46 -0
  463. package/dist/core/code/engine/core/ingestion/model/registration-table.js +234 -0
  464. package/dist/core/code/engine/core/ingestion/model/resolve.js +183 -0
  465. package/dist/core/code/engine/core/ingestion/model/scope-resolution-indexes.js +43 -0
  466. package/dist/core/code/engine/core/ingestion/model/semantic-model.js +179 -0
  467. package/dist/core/code/engine/core/ingestion/model/symbol-table.js +216 -0
  468. package/dist/core/code/engine/core/ingestion/model/type-registry.js +84 -0
  469. package/dist/core/code/engine/core/ingestion/mro-processor.js +709 -0
  470. package/dist/core/code/engine/core/ingestion/parsing-processor.js +312 -0
  471. package/dist/core/code/engine/core/ingestion/pipeline-phases/communities.js +69 -0
  472. package/dist/core/code/engine/core/ingestion/pipeline-phases/cross-file.js +71 -0
  473. package/dist/core/code/engine/core/ingestion/pipeline-phases/di.js +338 -0
  474. package/dist/core/code/engine/core/ingestion/pipeline-phases/http-api-calls.js +312 -0
  475. package/dist/core/code/engine/core/ingestion/pipeline-phases/index.js +54 -0
  476. package/dist/core/code/engine/core/ingestion/pipeline-phases/mro.js +40 -0
  477. package/dist/core/code/engine/core/ingestion/pipeline-phases/orm.js +78 -0
  478. package/dist/core/code/engine/core/ingestion/pipeline-phases/parse-impl.js +1286 -0
  479. package/dist/core/code/engine/core/ingestion/pipeline-phases/parse.js +41 -0
  480. package/dist/core/code/engine/core/ingestion/pipeline-phases/processes.js +193 -0
  481. package/dist/core/code/engine/core/ingestion/pipeline-phases/prune-local-symbols.js +29 -0
  482. package/dist/core/code/engine/core/ingestion/pipeline-phases/registry.js +52 -0
  483. package/dist/core/code/engine/core/ingestion/pipeline-phases/routes.js +409 -0
  484. package/dist/core/code/engine/core/ingestion/pipeline-phases/rpc-edges.js +301 -0
  485. package/dist/core/code/engine/core/ingestion/pipeline-phases/runner.js +207 -0
  486. package/dist/core/code/engine/core/ingestion/pipeline-phases/scan.js +49 -0
  487. package/dist/core/code/engine/core/ingestion/pipeline-phases/spring-aop.js +442 -0
  488. package/dist/core/code/engine/core/ingestion/pipeline-phases/spring-auto-configuration.js +264 -0
  489. package/dist/core/code/engine/core/ingestion/pipeline-phases/spring-config.js +440 -0
  490. package/dist/core/code/engine/core/ingestion/pipeline-phases/structure.js +38 -0
  491. package/dist/core/code/engine/core/ingestion/pipeline-phases/tools.js +89 -0
  492. package/dist/core/code/engine/core/ingestion/pipeline-phases/types.js +40 -0
  493. package/dist/core/code/engine/core/ingestion/pipeline.js +152 -0
  494. package/dist/core/code/engine/core/ingestion/process-processor.js +325 -0
  495. package/dist/core/code/engine/core/ingestion/resolve-references.js +205 -0
  496. package/dist/core/code/engine/core/ingestion/route-extractors/constant-resolver.js +135 -0
  497. package/dist/core/code/engine/core/ingestion/route-extractors/django-root-discovery.js +221 -0
  498. package/dist/core/code/engine/core/ingestion/route-extractors/django.js +428 -0
  499. package/dist/core/code/engine/core/ingestion/route-extractors/expo.js +39 -0
  500. package/dist/core/code/engine/core/ingestion/route-extractors/fastapi-router-bindings.js +264 -0
  501. package/dist/core/code/engine/core/ingestion/route-extractors/laravel.js +501 -0
  502. package/dist/core/code/engine/core/ingestion/route-extractors/middleware.js +175 -0
  503. package/dist/core/code/engine/core/ingestion/route-extractors/nextjs.js +81 -0
  504. package/dist/core/code/engine/core/ingestion/route-extractors/php.js +25 -0
  505. package/dist/core/code/engine/core/ingestion/route-extractors/python-const-resolver.js +307 -0
  506. package/dist/core/code/engine/core/ingestion/route-extractors/response-shapes.js +299 -0
  507. package/dist/core/code/engine/core/ingestion/route-extractors/route-path.js +71 -0
  508. package/dist/core/code/engine/core/ingestion/route-extractors/spring-shared.js +310 -0
  509. package/dist/core/code/engine/core/ingestion/route-extractors/spring.js +441 -0
  510. package/dist/core/code/engine/core/ingestion/scope-extractor-bridge.js +60 -0
  511. package/dist/core/code/engine/core/ingestion/scope-extractor.js +1373 -0
  512. package/dist/core/code/engine/core/ingestion/scope-resolution/contract/scope-resolver.js +282 -0
  513. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/callee-id-sink.js +72 -0
  514. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/edges.js +194 -0
  515. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/ids.js +472 -0
  516. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/imports-to-edges.js +49 -0
  517. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/method-dispatch.js +43 -0
  518. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/node-lookup.js +274 -0
  519. package/dist/core/code/engine/core/ingestion/scope-resolution/graph-bridge/references-to-edges.js +93 -0
  520. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/callable-value-flow.js +1240 -0
  521. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/compound-receiver.js +1174 -0
  522. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/free-call-fallback.js +873 -0
  523. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/imported-return-types.js +226 -0
  524. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/mro.js +107 -0
  525. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/overload-narrowing.js +441 -0
  526. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/property-dispatch.js +122 -0
  527. package/dist/core/code/engine/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +1720 -0
  528. package/dist/core/code/engine/core/ingestion/scope-resolution/pipeline/phase.js +395 -0
  529. package/dist/core/code/engine/core/ingestion/scope-resolution/pipeline/reconcile-ownership.js +208 -0
  530. package/dist/core/code/engine/core/ingestion/scope-resolution/pipeline/registry.js +49 -0
  531. package/dist/core/code/engine/core/ingestion/scope-resolution/pipeline/run.js +632 -0
  532. package/dist/core/code/engine/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.js +112 -0
  533. package/dist/core/code/engine/core/ingestion/scope-resolution/resolution-outcome.js +41 -0
  534. package/dist/core/code/engine/core/ingestion/scope-resolution/scope/namespace-targets.js +81 -0
  535. package/dist/core/code/engine/core/ingestion/scope-resolution/scope/walkers.js +1835 -0
  536. package/dist/core/code/engine/core/ingestion/scope-resolution/unresolved-receivers.js +242 -0
  537. package/dist/core/code/engine/core/ingestion/scope-resolution/utils/definition-id.js +22 -0
  538. package/dist/core/code/engine/core/ingestion/scope-resolution/workspace-index.js +151 -0
  539. package/dist/core/code/engine/core/ingestion/structure-processor.js +40 -0
  540. package/dist/core/code/engine/core/ingestion/tree-sitter-queries.js +2244 -0
  541. package/dist/core/code/engine/core/ingestion/ts-js-hoc-utils.js +115 -0
  542. package/dist/core/code/engine/core/ingestion/type-env.js +1136 -0
  543. package/dist/core/code/engine/core/ingestion/type-extractors/c-cpp.js +555 -0
  544. package/dist/core/code/engine/core/ingestion/type-extractors/csharp.js +570 -0
  545. package/dist/core/code/engine/core/ingestion/type-extractors/dart.js +372 -0
  546. package/dist/core/code/engine/core/ingestion/type-extractors/go.js +508 -0
  547. package/dist/core/code/engine/core/ingestion/type-extractors/jvm.js +875 -0
  548. package/dist/core/code/engine/core/ingestion/type-extractors/php.js +537 -0
  549. package/dist/core/code/engine/core/ingestion/type-extractors/python.js +477 -0
  550. package/dist/core/code/engine/core/ingestion/type-extractors/ruby.js +380 -0
  551. package/dist/core/code/engine/core/ingestion/type-extractors/rust.js +502 -0
  552. package/dist/core/code/engine/core/ingestion/type-extractors/shared.js +843 -0
  553. package/dist/core/code/engine/core/ingestion/type-extractors/swift.js +490 -0
  554. package/dist/core/code/engine/core/ingestion/type-extractors/types.js +2 -0
  555. package/dist/core/code/engine/core/ingestion/type-extractors/typescript.js +690 -0
  556. package/dist/core/code/engine/core/ingestion/utils/ast-helpers.js +1693 -0
  557. package/dist/core/code/engine/core/ingestion/utils/call-analysis.js +779 -0
  558. package/dist/core/code/engine/core/ingestion/utils/callable-flow-captures.js +932 -0
  559. package/dist/core/code/engine/core/ingestion/utils/callable-labels.js +49 -0
  560. package/dist/core/code/engine/core/ingestion/utils/deferred-resolution-profile.js +151 -0
  561. package/dist/core/code/engine/core/ingestion/utils/effective-ram.js +67 -0
  562. package/dist/core/code/engine/core/ingestion/utils/env.js +60 -0
  563. package/dist/core/code/engine/core/ingestion/utils/event-loop.js +9 -0
  564. package/dist/core/code/engine/core/ingestion/utils/graph-sort.js +103 -0
  565. package/dist/core/code/engine/core/ingestion/utils/heap-probe.js +45 -0
  566. package/dist/core/code/engine/core/ingestion/utils/heritage-marker.js +47 -0
  567. package/dist/core/code/engine/core/ingestion/utils/line-base.js +24 -0
  568. package/dist/core/code/engine/core/ingestion/utils/max-file-size.js +59 -0
  569. package/dist/core/code/engine/core/ingestion/utils/method-props.js +198 -0
  570. package/dist/core/code/engine/core/ingestion/utils/qualified-name.js +73 -0
  571. package/dist/core/code/engine/core/ingestion/utils/receiver-chain-captures.js +60 -0
  572. package/dist/core/code/engine/core/ingestion/utils/receiver-chain-codec.js +188 -0
  573. package/dist/core/code/engine/core/ingestion/utils/scope-tree-walk.js +36 -0
  574. package/dist/core/code/engine/core/ingestion/utils/symbol-labels.js +48 -0
  575. package/dist/core/code/engine/core/ingestion/utils/template-arguments.js +187 -0
  576. package/dist/core/code/engine/core/ingestion/utils/type-parameters.js +209 -0
  577. package/dist/core/code/engine/core/ingestion/utils/verbose.js +6 -0
  578. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/c-cpp.js +133 -0
  579. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/csharp.js +66 -0
  580. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/dart.js +111 -0
  581. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/go.js +153 -0
  582. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/jvm.js +145 -0
  583. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/php.js +61 -0
  584. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/python.js +104 -0
  585. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/ruby.js +55 -0
  586. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/rust.js +79 -0
  587. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/swift.js +91 -0
  588. package/dist/core/code/engine/core/ingestion/variable-extractors/configs/typescript-javascript.js +86 -0
  589. package/dist/core/code/engine/core/ingestion/variable-extractors/generic.js +111 -0
  590. package/dist/core/code/engine/core/ingestion/variable-types.js +3 -0
  591. package/dist/core/code/engine/core/ingestion/vue-sfc-extractor.js +544 -0
  592. package/dist/core/code/engine/core/ingestion/workers/callable-id.js +122 -0
  593. package/dist/core/code/engine/core/ingestion/workers/clone-safety.js +470 -0
  594. package/dist/core/code/engine/core/ingestion/workers/parse-worker.js +2456 -0
  595. package/dist/core/code/engine/core/ingestion/workers/post-result.js +90 -0
  596. package/dist/core/code/engine/core/ingestion/workers/quarantine.js +41 -0
  597. package/dist/core/code/engine/core/ingestion/workers/result-merge.js +59 -0
  598. package/dist/core/code/engine/core/ingestion/workers/worker-pool.js +1725 -0
  599. package/dist/core/code/engine/core/ingestion/workspace-config.js +139 -0
  600. package/dist/core/code/engine/core/lbug/conn-lock.js +72 -0
  601. package/dist/core/code/engine/core/lbug/csv-generator.js +710 -0
  602. package/dist/core/code/engine/core/lbug/cypher-escape.js +24 -0
  603. package/dist/core/code/engine/core/lbug/extension-load-error.js +339 -0
  604. package/dist/core/code/engine/core/lbug/extension-loader.js +261 -0
  605. package/dist/core/code/engine/core/lbug/graph-emit-sink.js +584 -0
  606. package/dist/core/code/engine/core/lbug/lbug-adapter.js +2703 -0
  607. package/dist/core/code/engine/core/lbug/lbug-config.js +1029 -0
  608. package/dist/core/code/engine/core/lbug/native-check.js +435 -0
  609. package/dist/core/code/engine/core/lbug/pool-adapter.js +973 -0
  610. package/dist/core/code/engine/core/lbug/query-params.js +25 -0
  611. package/dist/core/code/engine/core/lbug/query-result-utils.js +31 -0
  612. package/dist/core/code/engine/core/lbug/rel-pair-routing.js +373 -0
  613. package/dist/core/code/engine/core/lbug/schema.js +771 -0
  614. package/dist/core/code/engine/core/lbug/shutdown-helpers.js +40 -0
  615. package/dist/core/code/engine/core/lbug/sidecar-recovery.js +716 -0
  616. package/dist/core/code/engine/core/lbug/stdio-capture.js +49 -0
  617. package/dist/core/code/engine/core/lbug/sync-csv-writer.js +115 -0
  618. package/dist/core/code/engine/core/lbug/wal-checkpoint-driver.js +215 -0
  619. package/dist/core/code/engine/core/lbug/wal-driver-state.js +28 -0
  620. package/dist/core/code/engine/core/logger.js +339 -0
  621. package/dist/core/code/engine/core/platform/capabilities.js +91 -0
  622. package/dist/core/code/engine/core/run-analyze.js +1098 -0
  623. package/dist/core/code/engine/core/tree-sitter/parser-loader.js +281 -0
  624. package/dist/core/code/engine/core/tree-sitter/safe-parse.js +258 -0
  625. package/dist/core/code/engine/core/tree-sitter/vendored-grammars.js +64 -0
  626. package/dist/core/code/engine/lib/utils.js +121 -0
  627. package/dist/core/code/engine/mcp/core/lbug-adapter.js +27 -0
  628. package/dist/core/code/engine/mcp/local/aop-metadata.js +230 -0
  629. package/dist/core/code/engine/mcp/local/bean-metadata.js +49 -0
  630. package/dist/core/code/engine/mcp/local/limits.js +15 -0
  631. package/dist/core/code/engine/mcp/local/line-display.js +6 -0
  632. package/dist/core/code/engine/mcp/local/local-backend.js +4142 -0
  633. package/dist/core/code/engine/storage/branch-index.js +72 -0
  634. package/dist/core/code/engine/storage/file-hash.js +95 -0
  635. package/dist/core/code/engine/storage/fs-atomic.js +34 -0
  636. package/dist/core/code/engine/storage/git.js +555 -0
  637. package/dist/core/code/engine/storage/index-lock.js +664 -0
  638. package/dist/core/code/engine/storage/parse-cache.js +650 -0
  639. package/dist/core/code/engine/storage/parsedfile-store.js +620 -0
  640. package/dist/core/code/engine/storage/repo-manager.js +1061 -0
  641. package/dist/core/code/engine/storage/scope-index-store.js +247 -0
  642. package/dist/core/code/engine/types/pipeline.js +2 -0
  643. package/dist/core/code/scripts/install-duckdb-extension.mjs +125 -0
  644. package/dist/core/code/scripts/resolve-analyze-cmd.cjs +346 -0
  645. package/dist/core/code/shared/graph/types.js +8 -0
  646. package/dist/core/code/shared/index.js +105 -0
  647. package/dist/core/code/shared/integrations/circuit-breaker.js +242 -0
  648. package/dist/core/code/shared/integrations/resilient-fetch.js +224 -0
  649. package/dist/core/code/shared/integrations/retry.js +70 -0
  650. package/dist/core/code/shared/integrations/understand-quickly.js +145 -0
  651. package/dist/core/code/shared/language-detection.js +162 -0
  652. package/dist/core/code/shared/languages.js +27 -0
  653. package/dist/core/code/shared/lbug/schema-constants.js +98 -0
  654. package/dist/core/code/shared/mro-strategy.js +2 -0
  655. package/dist/core/code/shared/pipeline.js +5 -0
  656. package/dist/core/code/shared/scope-resolution/callable-flow-site.js +11 -0
  657. package/dist/core/code/shared/scope-resolution/def-index.js +53 -0
  658. package/dist/core/code/shared/scope-resolution/evidence-weights.js +87 -0
  659. package/dist/core/code/shared/scope-resolution/finalize-algorithm.js +807 -0
  660. package/dist/core/code/shared/scope-resolution/language-classification.js +46 -0
  661. package/dist/core/code/shared/scope-resolution/method-dispatch-index.js +100 -0
  662. package/dist/core/code/shared/scope-resolution/module-scope-index.js +59 -0
  663. package/dist/core/code/shared/scope-resolution/origin-priority.js +23 -0
  664. package/dist/core/code/shared/scope-resolution/parsed-file.js +54 -0
  665. package/dist/core/code/shared/scope-resolution/position-index.js +136 -0
  666. package/dist/core/code/shared/scope-resolution/qualified-name-index.js +77 -0
  667. package/dist/core/code/shared/scope-resolution/reference-site.js +24 -0
  668. package/dist/core/code/shared/scope-resolution/registries/class-registry.js +32 -0
  669. package/dist/core/code/shared/scope-resolution/registries/context.js +52 -0
  670. package/dist/core/code/shared/scope-resolution/registries/evidence.js +152 -0
  671. package/dist/core/code/shared/scope-resolution/registries/field-registry.js +33 -0
  672. package/dist/core/code/shared/scope-resolution/registries/lookup-core.js +392 -0
  673. package/dist/core/code/shared/scope-resolution/registries/lookup-qualified.js +58 -0
  674. package/dist/core/code/shared/scope-resolution/registries/macro-registry.js +34 -0
  675. package/dist/core/code/shared/scope-resolution/registries/method-registry.js +34 -0
  676. package/dist/core/code/shared/scope-resolution/registries/tie-breaks.js +63 -0
  677. package/dist/core/code/shared/scope-resolution/resolve-type-ref.js +128 -0
  678. package/dist/core/code/shared/scope-resolution/scope-id.js +49 -0
  679. package/dist/core/code/shared/scope-resolution/scope-tree.js +225 -0
  680. package/dist/core/code/shared/scope-resolution/symbol-definition.js +12 -0
  681. package/dist/core/code/shared/scope-resolution/types.js +25 -0
  682. package/dist/core/code/shared/test-helpers.js +17 -0
  683. package/dist/core/code/vendor/leiden/index.cjs +355 -0
  684. package/dist/core/code/vendor/leiden/utils.cjs +419 -0
  685. package/dist/core/dbquery/cli.d.ts.map +1 -1
  686. package/dist/core/dbquery/cli.js +5 -4
  687. package/dist/core/dbquery/cli.js.map +1 -1
  688. package/dist/core/dbquery/config.d.ts.map +1 -1
  689. package/dist/core/dbquery/config.js +39 -3
  690. package/dist/core/dbquery/config.js.map +1 -1
  691. package/dist/core/dbquery/drivers/http.d.ts +23 -0
  692. package/dist/core/dbquery/drivers/http.d.ts.map +1 -0
  693. package/dist/core/dbquery/drivers/http.js +125 -0
  694. package/dist/core/dbquery/drivers/http.js.map +1 -0
  695. package/dist/core/dbquery/drivers/mysql.js +1 -1
  696. package/dist/core/dbquery/drivers/mysql.js.map +1 -1
  697. package/dist/core/dbquery/drivers/postgres.js +1 -1
  698. package/dist/core/dbquery/drivers/postgres.js.map +1 -1
  699. package/dist/core/dbquery/executor.d.ts.map +1 -1
  700. package/dist/core/dbquery/executor.js +46 -12
  701. package/dist/core/dbquery/executor.js.map +1 -1
  702. package/dist/core/dbquery/format.d.ts.map +1 -1
  703. package/dist/core/dbquery/format.js +2 -1
  704. package/dist/core/dbquery/format.js.map +1 -1
  705. package/dist/core/dbquery/init.d.ts.map +1 -1
  706. package/dist/core/dbquery/init.js +7 -0
  707. package/dist/core/dbquery/init.js.map +1 -1
  708. package/dist/core/dbquery/types.d.ts +55 -7
  709. package/dist/core/dbquery/types.d.ts.map +1 -1
  710. package/dist/core/directory.d.ts +17 -0
  711. package/dist/core/directory.d.ts.map +1 -1
  712. package/dist/core/directory.js +37 -0
  713. package/dist/core/directory.js.map +1 -1
  714. package/dist/core/features/cli.d.ts.map +1 -1
  715. package/dist/core/features/cli.js +3 -2
  716. package/dist/core/features/cli.js.map +1 -1
  717. package/dist/core/features/scanner.d.ts +1 -1
  718. package/dist/core/features/scanner.d.ts.map +1 -1
  719. package/dist/core/features/scanner.js +20 -4
  720. package/dist/core/features/scanner.js.map +1 -1
  721. package/dist/core/markdown/cli.d.ts.map +1 -1
  722. package/dist/core/markdown/cli.js +9 -8
  723. package/dist/core/markdown/cli.js.map +1 -1
  724. package/dist/core/timeline/cli.d.ts.map +1 -1
  725. package/dist/core/timeline/cli.js +13 -6
  726. package/dist/core/timeline/cli.js.map +1 -1
  727. package/dist/core/timeline/debris.d.ts +20 -0
  728. package/dist/core/timeline/debris.d.ts.map +1 -0
  729. package/dist/core/timeline/debris.js +124 -0
  730. package/dist/core/timeline/debris.js.map +1 -0
  731. package/dist/core/timeline/hook-runner.d.ts.map +1 -1
  732. package/dist/core/timeline/hook-runner.js +3 -1
  733. package/dist/core/timeline/hook-runner.js.map +1 -1
  734. package/dist/core/timeline/hooks.d.ts.map +1 -1
  735. package/dist/core/timeline/hooks.js +13 -5
  736. package/dist/core/timeline/hooks.js.map +1 -1
  737. package/dist/core/timeline/installer.d.ts +2 -0
  738. package/dist/core/timeline/installer.d.ts.map +1 -1
  739. package/dist/core/timeline/installer.js +12 -0
  740. package/dist/core/timeline/installer.js.map +1 -1
  741. package/dist/core/timeline/project-root.d.ts +21 -0
  742. package/dist/core/timeline/project-root.d.ts.map +1 -0
  743. package/dist/core/timeline/project-root.js +83 -0
  744. package/dist/core/timeline/project-root.js.map +1 -0
  745. package/dist/web/register.d.ts.map +1 -1
  746. package/dist/web/register.js +2 -1
  747. package/dist/web/register.js.map +1 -1
  748. package/package.json +1 -1
  749. package/dist/.claude-template/.cgraphx/timeline-current-turn.json +0 -1
  750. package/dist/.claude-template/skills/.cgraphx/timeline-current-turn.json +0 -1
  751. package/dist/.claude-template/skills/handdrawn-deck/.cgraphx/timeline-current-turn.json +0 -1
  752. package/dist/.claude-template/skills/handdrawn-deck/references/.cgraphx/timeline-current-turn.json +0 -1
  753. package/dist/.claude-template/skills/handdrawn-sketch-engine/.cgraphx/timeline-current-turn.json +0 -1
  754. /package/dist/.claude-template/skills/run-api-test/assets/{template-test-verify.jsonl → template-/346/216/245/345/217/243/346/265/213/350/257/225/351/252/214/350/257/201.jsonl"} +0 -0
@@ -0,0 +1,1086 @@
1
+ "use strict";
2
+ /**
3
+ * Analyze Command
4
+ *
5
+ * Indexes a repository and stores the knowledge graph in .cgraphx/code/
6
+ *
7
+ * Delegates core analysis to the shared runFullAnalysis orchestrator.
8
+ * This CLI wrapper handles: heap management, progress bar, SIGINT,
9
+ * summary output, and process.exit().
10
+ */
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.analyzeCommandWithRunnerIdentity = exports.analyzeCommand = void 0;
16
+ exports.computeHeapCapMb = computeHeapCapMb;
17
+ exports.parseMaxOldSpaceMb = parseMaxOldSpaceMb;
18
+ const path_1 = __importDefault(require("path"));
19
+ const node_fs_1 = require("node:fs");
20
+ const os_1 = __importDefault(require("os"));
21
+ const child_process_1 = require("child_process");
22
+ const v8_1 = __importDefault(require("v8"));
23
+ const cli_progress_1 = __importDefault(require("cli-progress"));
24
+ const lbug_adapter_js_1 = require("../core/lbug/lbug-adapter.js");
25
+ const shutdown_helpers_js_1 = require("../core/lbug/shutdown-helpers.js");
26
+ const rel_pair_routing_js_1 = require("../core/lbug/rel-pair-routing.js");
27
+ const utils_js_1 = require("../lib/utils.js");
28
+ const lbug_config_js_1 = require("../core/lbug/lbug-config.js");
29
+ const repo_manager_js_1 = require("../storage/repo-manager.js");
30
+ const git_js_1 = require("../storage/git.js");
31
+ const index_lock_js_1 = require("../storage/index-lock.js");
32
+ const analyze_config_js_1 = require("./analyze-config.js");
33
+ const run_analyze_js_1 = require("../core/run-analyze.js");
34
+ const workspace_config_js_1 = require("../core/ingestion/workspace-config.js");
35
+ const capabilities_js_1 = require("../core/platform/capabilities.js");
36
+ const max_file_size_js_1 = require("../core/ingestion/utils/max-file-size.js");
37
+ const optional_grammars_js_1 = require("./optional-grammars.js");
38
+ const glob_1 = require("glob");
39
+ const cli_message_js_1 = require("./cli-message.js");
40
+ const effective_ram_js_1 = require("../core/ingestion/utils/effective-ram.js");
41
+ const format_elapsed_js_1 = require("./format-elapsed.js");
42
+ const resolve_invocation_js_1 = require("./resolve-invocation.js");
43
+ // Capture stderr.write at module load BEFORE anything (LadybugDB native
44
+ // init, progress bar, console redirection) can monkey-patch it. The
45
+ // fatal handlers below MUST reach the user even when the analyze path
46
+ // has redirected console.* through the progress bar's bar.log() — the
47
+ // previous behaviour silently swallowed stack traces and made #1169
48
+ // indistinguishable from a no-op success on Windows.
49
+ const realStderrWrite = process.stderr.write.bind(process.stderr);
50
+ const realStdoutWrite = process.stdout.write.bind(process.stdout);
51
+ const writeFatalToStderr = (label, err) => {
52
+ const isErr = err instanceof Error;
53
+ const message = isErr ? err.message : String(err);
54
+ realStderrWrite(`\n ${label}: ${message}\n`);
55
+ if (isErr && err.stack)
56
+ realStderrWrite(`${err.stack}\n`);
57
+ // Walk and print the `cause` chain. The phase runner wraps the underlying
58
+ // failure as `new Error("Phase 'X' failed: …", { cause })`, so the original
59
+ // error (e.g. a WorkerPoolDispatchError carrying the worker-side stack from
60
+ // #2068) is only reachable via `.cause`. Without this the user sees the
61
+ // wrapper's main-thread stack and never the real frame. `cause.stack` already
62
+ // begins with the cause's message, so we print the stack alone (not message +
63
+ // stack) to avoid repeating it. `causeChain` owns the traversal and the depth
64
+ // bound that stops a cyclic `cause` looping — this used to be one of four
65
+ // hand-rolled copies that had already drifted apart on both. Uses
66
+ // realStderrWrite so the redirected console.error's ANSI clear-line wrapping
67
+ // can't erase it (#1169). The head is skipped: it was just printed above.
68
+ for (const cause of (0, utils_js_1.causeChain)(isErr ? err.cause : undefined)) {
69
+ realStderrWrite(`\n Caused by: ${cause.stack ?? cause.message}\n`);
70
+ }
71
+ };
72
+ let fatalHandlersInstalled = false;
73
+ /**
74
+ * Install one-shot `unhandledRejection` / `uncaughtException` handlers
75
+ * that surface the failure to the real stderr (bypassing any console
76
+ * redirection installed by the progress bar) and force a non-zero exit
77
+ * code. Without these, an async error escaping {@link analyzeCommand}'s
78
+ * try/catch was reported as exit 0 with no diagnostic — the silent
79
+ * failure mode tracked in #1169.
80
+ */
81
+ const installFatalHandlers = () => {
82
+ if (fatalHandlersInstalled)
83
+ return;
84
+ fatalHandlersInstalled = true;
85
+ process.on('unhandledRejection', (err) => {
86
+ writeFatalToStderr('Analysis failed (unhandled rejection)', err);
87
+ process.exit(1);
88
+ });
89
+ process.on('uncaughtException', (err) => {
90
+ writeFatalToStderr('Analysis failed (uncaught exception)', err);
91
+ process.exit(1);
92
+ });
93
+ };
94
+ /**
95
+ * RAM-aware re-exec heap cap (MB) — the formula itself is single-sourced in
96
+ * `core/ingestion/utils/effective-ram.ts` (`heapCapMbFor`), shared with the
97
+ * server's analyze fork. `constrainedBytes` is the cgroup limit or `null`;
98
+ * it is honored only as a real, smaller-than-physical cap, because
99
+ * `process.constrainedMemory()` returns a huge sentinel when UNCONSTRAINED.
100
+ * (Observed rationale: a cap ≥ RAM made V8 collect lazily and swap-thrash —
101
+ * the #2649 worker-timeout cascade on 16 GB boxes.)
102
+ */
103
+ function computeHeapCapMb(totalBytes, constrainedBytes) {
104
+ const effectiveBytes = constrainedBytes !== null && constrainedBytes > 0 && constrainedBytes < totalBytes
105
+ ? constrainedBytes
106
+ : totalBytes;
107
+ return (0, effective_ram_js_1.heapCapMbFor)(effectiveBytes);
108
+ }
109
+ function readConstrainedBytes() {
110
+ if (typeof process.constrainedMemory !== 'function')
111
+ return null;
112
+ const c = process.constrainedMemory();
113
+ return typeof c === 'number' && c > 0 ? c : null;
114
+ }
115
+ const HEAP_MB = computeHeapCapMb(os_1.default.totalmem(), readConstrainedBytes());
116
+ const TEST_RESPAWN_HEAP_MB = Number(process.env.CGRAPH_TEST_RESPAWN_HEAP_MB);
117
+ const RESPAWN_HEAP_MB = Number.isFinite(TEST_RESPAWN_HEAP_MB) && TEST_RESPAWN_HEAP_MB > 0
118
+ ? Math.floor(TEST_RESPAWN_HEAP_MB)
119
+ : HEAP_MB;
120
+ const HEAP_FLAG = `--max-old-space-size=${RESPAWN_HEAP_MB}`;
121
+ /** Larger semi-space (young-gen) cuts minor-GC frequency + promotion churn during
122
+ * the multi-million-node graph build/emit. Allowed in NODE_OPTIONS (unlike
123
+ * --stack-size), so it propagates to the re-exec env cleanly. */
124
+ const SEMI_SPACE_MB = 128;
125
+ const SEMI_FLAG = `--max-semi-space-size=${SEMI_SPACE_MB}`;
126
+ /** Increase default stack size (KB) to prevent stack overflow on deep class hierarchies. */
127
+ const STACK_KB = 4096;
128
+ const STACK_FLAG = `--stack-size=${STACK_KB}`;
129
+ const RESPAWN_OUTPUT_TAIL_CHARS = 1024 * 1024;
130
+ const RESPAWN_PROGRESS_ENV = 'CGRAPH_RESPAWN_PROGRESS_TTY';
131
+ const terminalColumns = () => {
132
+ const parsed = Number(process.env.COLUMNS);
133
+ return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : 80;
134
+ };
135
+ const ANSI_ESCAPE_PATTERN = /\x1B(?:\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\)|[PX^_][\s\S]*?\x1B\\|[78]|[@-Z\\-_])/y;
136
+ const splitGraphemes = (text) => {
137
+ const Segmenter = Intl.Segmenter;
138
+ if (Segmenter) {
139
+ return Array.from(new Segmenter(undefined, { granularity: 'grapheme' }).segment(text), (s) => s.segment);
140
+ }
141
+ return Array.from(text);
142
+ };
143
+ const isZeroWidthCodePoint = (codePoint) => codePoint === 0x200d ||
144
+ (codePoint >= 0x0300 && codePoint <= 0x036f) ||
145
+ (codePoint >= 0x1ab0 && codePoint <= 0x1aff) ||
146
+ (codePoint >= 0x1dc0 && codePoint <= 0x1dff) ||
147
+ (codePoint >= 0x20d0 && codePoint <= 0x20ff) ||
148
+ (codePoint >= 0xfe00 && codePoint <= 0xfe0f) ||
149
+ (codePoint >= 0xfe20 && codePoint <= 0xfe2f);
150
+ const isWideCodePoint = (codePoint) => codePoint >= 0x1100 &&
151
+ (codePoint <= 0x115f ||
152
+ codePoint === 0x2329 ||
153
+ codePoint === 0x232a ||
154
+ (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
155
+ (codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
156
+ (codePoint >= 0xf900 && codePoint <= 0xfaff) ||
157
+ (codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
158
+ (codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
159
+ (codePoint >= 0xff00 && codePoint <= 0xff60) ||
160
+ (codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
161
+ (codePoint >= 0x1f300 && codePoint <= 0x1faff) ||
162
+ (codePoint >= 0x20000 && codePoint <= 0x3fffd));
163
+ const visibleColumns = (text) => {
164
+ let columns = 0;
165
+ for (const char of Array.from(text)) {
166
+ const codePoint = char.codePointAt(0);
167
+ if (codePoint === undefined || isZeroWidthCodePoint(codePoint))
168
+ continue;
169
+ columns += isWideCodePoint(codePoint) ? 2 : 1;
170
+ }
171
+ return columns;
172
+ };
173
+ const readAnsiEscapeAt = (text, index) => {
174
+ ANSI_ESCAPE_PATTERN.lastIndex = index;
175
+ return ANSI_ESCAPE_PATTERN.exec(text)?.[0];
176
+ };
177
+ const truncateAnsiToColumns = (text, maxColumns) => {
178
+ if (!Number.isFinite(maxColumns) || maxColumns <= 0)
179
+ return '';
180
+ let output = '';
181
+ let columns = 0;
182
+ let index = 0;
183
+ while (index < text.length) {
184
+ const escape = readAnsiEscapeAt(text, index);
185
+ if (escape) {
186
+ output += escape;
187
+ index += escape.length;
188
+ continue;
189
+ }
190
+ const nextEscapeIndex = text.indexOf('\x1B', index);
191
+ const plainEnd = nextEscapeIndex === -1 ? text.length : nextEscapeIndex;
192
+ const plainText = text.slice(index, plainEnd);
193
+ for (const segment of splitGraphemes(plainText)) {
194
+ const width = visibleColumns(segment);
195
+ if (width > 0 && columns + width > maxColumns)
196
+ return output;
197
+ output += segment;
198
+ columns += width;
199
+ }
200
+ index = plainEnd;
201
+ }
202
+ return output;
203
+ };
204
+ const createAnsiPipeTerminal = (stream) => {
205
+ let linewrap = true;
206
+ let dy = 0;
207
+ const write = (s) => {
208
+ stream.write(s);
209
+ };
210
+ const moveVertical = (delta) => {
211
+ if (delta > 0)
212
+ write(`\x1B[${delta}B`);
213
+ else if (delta < 0)
214
+ write(`\x1B[${Math.abs(delta)}A`);
215
+ };
216
+ return {
217
+ cursorSave: () => write('\x1B7'),
218
+ cursorRestore: () => write('\x1B8'),
219
+ cursor: (enabled) => write(enabled ? '\x1B[?25h' : '\x1B[?25l'),
220
+ lineWrapping: (enabled) => {
221
+ linewrap = enabled;
222
+ write(enabled ? '\x1B[?7h' : '\x1B[?7l');
223
+ },
224
+ cursorTo: (x = null, y = null) => {
225
+ if (typeof y === 'number' && typeof x === 'number') {
226
+ write(`\x1B[${y + 1};${x + 1}H`);
227
+ return;
228
+ }
229
+ if (typeof x === 'number') {
230
+ write(x === 0 ? '\r' : `\x1B[${x + 1}G`);
231
+ }
232
+ },
233
+ cursorRelative: (dx = null, nextDy = null) => {
234
+ if (typeof dx === 'number' && dx !== 0) {
235
+ write(dx > 0 ? `\x1B[${dx}C` : `\x1B[${Math.abs(dx)}D`);
236
+ }
237
+ if (typeof nextDy === 'number' && nextDy !== 0) {
238
+ dy += nextDy;
239
+ moveVertical(nextDy);
240
+ }
241
+ },
242
+ cursorRelativeReset: () => {
243
+ moveVertical(-dy);
244
+ write('\r');
245
+ dy = 0;
246
+ },
247
+ clearRight: () => write('\x1B[0K'),
248
+ clearLine: () => write('\x1B[2K'),
249
+ clearBottom: () => write('\x1B[0J'),
250
+ newline: () => {
251
+ write('\n');
252
+ dy++;
253
+ },
254
+ write: (s, rawWrite = false) => {
255
+ const width = terminalColumns();
256
+ write(linewrap && rawWrite === false ? truncateAnsiToColumns(s, width) : s);
257
+ },
258
+ isTTY: () => true,
259
+ getWidth: terminalColumns,
260
+ };
261
+ };
262
+ const shouldBridgeRespawnProgressTty = () => process.stderr.isTTY === true || process.stdout.isTTY === true;
263
+ const appendOutputTail = (tail, chunk) => {
264
+ const text = Buffer.isBuffer(chunk)
265
+ ? chunk.toString('utf8')
266
+ : typeof chunk === 'string'
267
+ ? chunk
268
+ : String(chunk ?? '');
269
+ if (!text)
270
+ return tail;
271
+ const next = tail + text;
272
+ return next.length > RESPAWN_OUTPUT_TAIL_CHARS ? next.slice(-RESPAWN_OUTPUT_TAIL_CHARS) : next;
273
+ };
274
+ /**
275
+ * Run the respawned analyzer while teeing child output through to the parent
276
+ * and keeping a bounded tail for crash classification.
277
+ *
278
+ * `execFileSync(..., { stdio: 'inherit' })` preserved live progress but hid
279
+ * stderr/stdout from the parent on abnormal exits. That made every
280
+ * SIGABRT/status-134 child look like an output-less V8 heap OOM, even when the
281
+ * terminal had already shown a native crash such as
282
+ * `libc++abi: ... Napi::Error`. Piped streams plus an explicit tee keeps the UX
283
+ * and gives `childProcessLikelyOom` the evidence it needs.
284
+ */
285
+ const runRespawnedAnalyze = (args, env) => new Promise((resolve) => {
286
+ let stdout = '';
287
+ let stderr = '';
288
+ let settled = false;
289
+ const finish = (exit) => {
290
+ if (settled)
291
+ return;
292
+ settled = true;
293
+ resolve(exit);
294
+ };
295
+ const child = (0, child_process_1.spawn)(process.execPath, [...args], {
296
+ stdio: ['inherit', 'pipe', 'pipe'],
297
+ windowsHide: true,
298
+ env,
299
+ });
300
+ child.stdout?.on('data', (chunk) => {
301
+ stdout = appendOutputTail(stdout, chunk);
302
+ realStdoutWrite(chunk);
303
+ });
304
+ child.stderr?.on('data', (chunk) => {
305
+ stderr = appendOutputTail(stderr, chunk);
306
+ realStderrWrite(chunk);
307
+ });
308
+ child.on('error', (err) => {
309
+ finish({
310
+ status: 1,
311
+ signal: null,
312
+ stdout,
313
+ stderr,
314
+ message: err instanceof Error ? err.message : String(err),
315
+ });
316
+ });
317
+ child.on('close', (status, signal) => {
318
+ finish({
319
+ status,
320
+ signal,
321
+ stdout,
322
+ stderr,
323
+ message: `Command failed: ${process.execPath} ${args.join(' ')}`,
324
+ });
325
+ });
326
+ });
327
+ /**
328
+ * Heuristic for "child re-exec likely died from V8 OOM".
329
+ *
330
+ * Platform-independent detection is best-effort: V8/Node usually emit stable
331
+ * heap-exhaustion phrases in stderr/message across Linux/macOS/Windows (for
332
+ * example "JavaScript heap out of memory" or "Reached heap limit"). When the
333
+ * child produced no output at all, we still treat status 134/SIGABRT as likely
334
+ * heap OOM. If stderr/stdout contains a native crash diagnostic, the output
335
+ * evidence wins and we do not print heap guidance.
336
+ */
337
+ const childProcessLikelyOom = (err) => {
338
+ if (!err || typeof err !== 'object')
339
+ return false;
340
+ const e = err;
341
+ const hasHeapOomSignature = (v) => {
342
+ const text = (Buffer.isBuffer(v) ? v.toString('utf8') : typeof v === 'string' ? v : '').toLowerCase();
343
+ if (!text)
344
+ return false;
345
+ return (text.includes('javascript heap out of memory') ||
346
+ text.includes('reached heap limit') ||
347
+ text.includes('allocation failed - javascript heap out of memory') ||
348
+ text.includes('fatalprocessoutofmemory'));
349
+ };
350
+ const fields = [e.message, e.stderr, e.stdout];
351
+ if (fields.some((v) => hasHeapOomSignature(v)))
352
+ return true;
353
+ const hasAnyChildOutput = [e.stderr, e.stdout].some((v) => (Buffer.isBuffer(v) && v.length > 0) || (typeof v === 'string' && v.length > 0));
354
+ if (hasAnyChildOutput)
355
+ return false;
356
+ return e.status === 134 || e.signal === 'SIGABRT';
357
+ };
358
+ const childProcessLikelyNativeAbort = (err) => {
359
+ if (!err || typeof err !== 'object')
360
+ return false;
361
+ const e = err;
362
+ const hasNativeAbortSignature = (v) => {
363
+ const text = (Buffer.isBuffer(v) ? v.toString('utf8') : typeof v === 'string' ? v : '').toLowerCase();
364
+ if (!text)
365
+ return false;
366
+ return (text.includes('napi::error') ||
367
+ text.includes('libc++abi: terminating') ||
368
+ text.includes('abort trap') ||
369
+ text.includes('native stack') ||
370
+ text.includes('native worker') ||
371
+ text.includes('native binding'));
372
+ };
373
+ return [e.message, e.stderr, e.stdout].some((v) => hasNativeAbortSignature(v));
374
+ };
375
+ const forceHeapOOMForTestIfEnabled = () => {
376
+ if (process.env.CGRAPH_TEST_FORCE_HEAP_OOM !== '1')
377
+ return;
378
+ // Allocate JS strings (not Buffers) so pressure lands on V8 heap itself.
379
+ // Buffers can allocate off-heap, which makes OOM triggering less reliable.
380
+ const chunks = [];
381
+ for (;;)
382
+ chunks.push('x'.repeat(1024 * 1024));
383
+ };
384
+ // 64 MiB keeps auto-checkpoint enabled but triggers less frequently than
385
+ // Ladybug's stock ~16 MiB threshold, reducing rename/remove churn on large
386
+ // runs. Also matches the GitNexus default in `lbug-config.ts`.
387
+ //
388
+ // IMPORTANT: keep README examples (`README.md`, `cgraph/README.md`) and
389
+ // the `DEFAULT_WAL_CHECKPOINT_THRESHOLD` constant in
390
+ // `cgraph/src/core/lbug/lbug-config.ts` in sync with this value.
391
+ const RECOMMENDED_WAL_CHECKPOINT_THRESHOLD = 64 * 1024 * 1024;
392
+ /**
393
+ * Last `--max-old-space-size` value (MB) in a NODE_OPTIONS string, or `null`
394
+ * when absent/unparseable. Last occurrence wins, matching V8's own
395
+ * later-flag-wins semantics when NODE_OPTIONS repeats a flag.
396
+ */
397
+ function parseMaxOldSpaceMb(nodeOptions) {
398
+ // V8 accepts `-` and `_` interchangeably in flag names, and Node accepts a
399
+ // space-separated value in NODE_OPTIONS — honor every spelling of the pin
400
+ // instead of silently overriding it (#2649 review).
401
+ const matches = [...nodeOptions.matchAll(/--max[-_]old[-_]space[-_]size(?:=|\s+)(\d+)/g)];
402
+ if (matches.length === 0)
403
+ return null;
404
+ const mb = Number(matches[matches.length - 1][1]);
405
+ return Number.isFinite(mb) && mb > 0 ? mb : null;
406
+ }
407
+ /** Re-exec the process with the RAM-aware auto heap cap + larger semi-space/stack
408
+ * if we're currently below that.
409
+ *
410
+ * Heap-source precedence (#2649):
411
+ * - an explicit per-invocation `--max-old-space-size` (execArgv) always wins;
412
+ * - `CGRAPH_MEMORY=off` declines the memory autopilot entirely;
413
+ * - an ambient NODE_OPTIONS heap >= the auto cap is honored as-is;
414
+ * - an ambient NODE_OPTIONS heap BELOW the auto cap is treated as an
415
+ * inherited environment default (devcontainers/CI export one for other
416
+ * tooling), not a deliberate per-run choice: warn and respawn with the
417
+ * auto cap. Pre-#2649 this returned early and large repos then OOM'd on
418
+ * whatever heap the environment happened to specify. */
419
+ async function ensureHeap() {
420
+ // Explicit opt-out disables auto-sizing ENTIRELY — both the ambient-pin
421
+ // override and the default v8-limit respawn — and is honored SILENTLY:
422
+ // the operator already made the call, and stderr-sensitive consumers
423
+ // (test harnesses, scripts, supervisors that track a single PID) rely on
424
+ // a quiet, single-process run.
425
+ if ((0, effective_ram_js_1.memoryAutopilotDisabled)())
426
+ return false;
427
+ const nodeOpts = process.env.NODE_OPTIONS || '';
428
+ if (process.execArgv.some((a) => a.startsWith('--max-old-space-size')))
429
+ return false;
430
+ const ambientHeapMb = parseMaxOldSpaceMb(nodeOpts);
431
+ if (ambientHeapMb !== null) {
432
+ if (ambientHeapMb >= RESPAWN_HEAP_MB)
433
+ return false;
434
+ (0, cli_message_js_1.cliWarn)(` NODE_OPTIONS pins the heap to ${ambientHeapMb}MB — below the ${RESPAWN_HEAP_MB}MB this machine's RAM supports.\n` +
435
+ ` Re-running analyze with the larger auto-sized cap (set CGRAPH_MEMORY=off to keep the NODE_OPTIONS value).\n`);
436
+ }
437
+ else {
438
+ const v8Heap = v8_1.default.getHeapStatistics().heap_size_limit;
439
+ if (v8Heap >= HEAP_MB * 1024 * 1024 * 0.9)
440
+ return false;
441
+ }
442
+ // --stack-size is a V8 flag not allowed in NODE_OPTIONS on Node 24+, so pass it
443
+ // only as a direct CLI argument. --max-semi-space-size IS allowed in NODE_OPTIONS.
444
+ const cliFlags = [HEAP_FLAG, SEMI_FLAG];
445
+ if (!nodeOpts.includes('--stack-size'))
446
+ cliFlags.push(STACK_FLAG);
447
+ // Preserve the parent's node flags (execArgv) — dropping them breaks any
448
+ // loader-launched CLI: `node --import tsx src/cli/index.ts` respawned
449
+ // without `--import tsx` cannot execute TypeScript and dies with a
450
+ // swallowed exit 1 (#2649 review). Our heap/semi/stack flags come AFTER
451
+ // execArgv so V8's later-flag-wins semantics resolve duplicates our way.
452
+ // Inspector flags are the one exception: replaying `--inspect[-brk]` makes
453
+ // the child fight the parent for the debug port and die with EADDRINUSE.
454
+ const preservedExecArgv = process.execArgv.filter((a) => !a.startsWith('--inspect'));
455
+ const childArgs = [...preservedExecArgv, ...cliFlags, ...process.argv.slice(1)];
456
+ const childEnv = {
457
+ ...process.env,
458
+ NODE_OPTIONS: `${nodeOpts} ${HEAP_FLAG} ${SEMI_FLAG}`.trim(),
459
+ };
460
+ if (shouldBridgeRespawnProgressTty())
461
+ childEnv[RESPAWN_PROGRESS_ENV] = '1';
462
+ const childExit = await runRespawnedAnalyze(childArgs, childEnv);
463
+ if (childExit.status !== 0 || childExit.signal) {
464
+ if (childProcessLikelyOom(childExit)) {
465
+ (0, cli_message_js_1.cliError)(` Analysis likely ran out of memory (heap cap auto-sized to ${RESPAWN_HEAP_MB}MB ≈ 0.75x RAM).\n` +
466
+ ` This repository's working set exceeds available RAM. Use a machine with more RAM,\n` +
467
+ ` or override the cap (a cap above physical RAM causes swap-thrash — use with care):\n` +
468
+ ` NODE_OPTIONS="--max-old-space-size=<MB>" cgraph analyze [your-args]\n` +
469
+ ` (Windows: set NODE_OPTIONS=--max-old-space-size=<MB> && cgraph analyze [your-args])\n` +
470
+ ` If this persists, it may be a native crash unrelated to heap size.\n`, { recoveryHint: 'heap-oom-respawn' });
471
+ }
472
+ else if (childProcessLikelyNativeAbort(childExit)) {
473
+ (0, cli_message_js_1.cliError)(` Analysis aborted in a native worker or native binding path.\n` +
474
+ ` Try one of these recovery paths:\n` +
475
+ ` npm uninstall -g cgraph && npm install -g cgraph@latest (rebuilds native bindings)\n` +
476
+ ` Use Node 22 LTS if you are on a newer non-LTS runtime.\n`, { recoveryHint: 'native-worker-abort' });
477
+ }
478
+ const status = typeof childExit.status === 'number' && childExit.status !== 0 ? childExit.status : 1;
479
+ process.exitCode = status;
480
+ }
481
+ return true;
482
+ }
483
+ /**
484
+ * CGRAPH_* env vars that `analyzeCommand` writes for backward-compatible
485
+ * downstream consumption. Snapshotted at function entry and restored in the
486
+ * finally block so that programmatic callers (tests, long-running hosts)
487
+ * don't see leaked state across invocations. `CGRAPH_WORKER_POOL_SIZE` is
488
+ * NOT in this list: that knob is threaded through `runFullAnalysis` options
489
+ * (see `workerPoolSize` plumbing) so the CLI never has to mutate `process.env`
490
+ * for it in the first place.
491
+ */
492
+ const ANALYZE_CLI_ENV_KEYS = [
493
+ 'CGRAPH_VERBOSE',
494
+ 'CGRAPH_PROFILE_DEFERRED',
495
+ 'CGRAPH_PROFILE_DEFERRED_SLOW_MS',
496
+ 'CGRAPH_DEBUG_HEAP',
497
+ 'CGRAPH_MAX_FILE_SIZE',
498
+ 'CGRAPH_WORKER_SUB_BATCH_TIMEOUT_MS',
499
+ 'CGRAPH_WAL_CHECKPOINT_THRESHOLD',
500
+ 'CGRAPH_WAL_MANUAL_CHECKPOINT',
501
+ 'CGRAPH_ANALYZE_PROGRESS_ACTIVE',
502
+ ];
503
+ const snapshotAnalyzeEnv = () => {
504
+ const snap = {};
505
+ for (const k of ANALYZE_CLI_ENV_KEYS)
506
+ snap[k] = process.env[k];
507
+ return snap;
508
+ };
509
+ const restoreAnalyzeEnv = (snap) => {
510
+ for (const k of ANALYZE_CLI_ENV_KEYS) {
511
+ const v = snap[k];
512
+ if (v === undefined)
513
+ delete process.env[k];
514
+ else
515
+ process.env[k] = v;
516
+ }
517
+ };
518
+ const analyzeCommand = async (inputPath, options, runnerIdentityAtBootstrap) => {
519
+ if (await ensureHeap())
520
+ return;
521
+ forceHeapOOMForTestIfEnabled();
522
+ // Install fatal handlers immediately after re-exec resolution so any
523
+ // async error that escapes the try/catch below (#1169) surfaces with
524
+ // a stack trace and a non-zero exit code instead of a silent exit 0.
525
+ installFatalHandlers();
526
+ // npm-11 npx-crash nudge (#1939). Runs here, after the heap re-exec guard,
527
+ // so it fires once in the working process and never on the lazy-startup path
528
+ // of other commands (e.g. `cgraph mcp`).
529
+ (0, resolve_invocation_js_1.warnIfNpm11NpxRisk)();
530
+ // Snapshot the CGRAPH_* env vars that the impl writes for downstream
531
+ // consumption, so they don't leak across `analyzeCommand` invocations in
532
+ // programmatic callers (tests, long-running hosts). `process.exit(0)` on
533
+ // the success path bypasses `finally` — intentional: when the process is
534
+ // exiting, restoration is moot. For early-return paths (validation
535
+ // errors) and the alreadyUpToDate fast path the finally restores the
536
+ // pre-call values.
537
+ const envSnap = snapshotAnalyzeEnv();
538
+ try {
539
+ await analyzeCommandImpl(inputPath, options, runnerIdentityAtBootstrap);
540
+ }
541
+ finally {
542
+ restoreAnalyzeEnv(envSnap);
543
+ }
544
+ // If analyzeCommandImpl returned via a soft `process.exitCode = 1` error path
545
+ // while LadybugDB native handles are still open, the event loop won't drain and
546
+ // the process would HANG (#2264 review P1). The full analyze paths skip-close the
547
+ // DB — handles are left open and reclaimed by process.exit — so a soft return
548
+ // after a real analyze must force the exit. The success path never reaches here
549
+ // (analyzeCommandImpl calls process.exit(0) itself); early-validation errors and
550
+ // unit tests that mock runFullAnalysis never open the DB, so isLbugReady() is
551
+ // false and the soft return is preserved.
552
+ if ((0, lbug_adapter_js_1.isLbugReady)()) {
553
+ process.exit(typeof process.exitCode === 'number' ? process.exitCode : 1);
554
+ }
555
+ };
556
+ exports.analyzeCommand = analyzeCommand;
557
+ /** Commander entrypoint used only by the capture-before-import lazy bootstrap. */
558
+ const analyzeCommandWithRunnerIdentity = async (runnerIdentityAtBootstrap, inputPath, options) => (0, exports.analyzeCommand)(inputPath, options, runnerIdentityAtBootstrap);
559
+ exports.analyzeCommandWithRunnerIdentity = analyzeCommandWithRunnerIdentity;
560
+ const analyzeCommandImpl = async (inputPath, cliOptions, runnerIdentityAtBootstrap) => {
561
+ console.log('\n GitNexus Analyzer\n');
562
+ // ── 解析索引根目录 ────────────────────────────────────────────────
563
+ // 最先解析:`.cgraphrc` 从索引根读取(而非调用方 cwd),配置可为下方校验设置默认值。
564
+ // 无 git 仓库时自动降级为纯目录索引(plain-folder)——给出警告但不报错退出,
565
+ // 支持「根非 git + 子工程各自 git」的聚合根(spec §4/§9)。
566
+ let repoPath;
567
+ if (inputPath) {
568
+ repoPath = path_1.default.resolve(inputPath);
569
+ // 显式指定的路径不存在 → 直接报错退出。plain-folder 降级仅适用于「存在但非 git」
570
+ // 的目录,不适用于不存在的路径(spec §4)。仅在显式 inputPath 时检查:
571
+ // 未指定时 repoPath 来自 getGitRoot(cwd) 或 cwd 本身,必然存在。
572
+ if (!(0, node_fs_1.existsSync)(repoPath)) {
573
+ (0, cli_message_js_1.cliError)(`[cgraph] 索引根目录不存在: ${repoPath}\n 请检查路径是否正确。\n`);
574
+ process.exitCode = 1;
575
+ return;
576
+ }
577
+ }
578
+ else {
579
+ const gitRoot = (0, git_js_1.getGitRoot)(process.cwd());
580
+ // 无 git root → 降级为 cwd 纯目录;显式 inputPath 同样不向上查找 git 根。
581
+ repoPath = gitRoot ?? path_1.default.resolve(process.cwd());
582
+ }
583
+ const repoHasGit = (0, git_js_1.hasGitDir)(repoPath);
584
+ if (!repoHasGit) {
585
+ // plain-folder 降级:commit 跟踪不可用,但索引正常构建。
586
+ // v1 无增量概念,警告不得提及 incremental(spec §4)。
587
+ (0, cli_message_js_1.cliWarn)('[cgraph] 未发现 .git——按纯目录分析(commit 跟踪不可用)');
588
+ }
589
+ // Validate the index-branch selector (#2106), so a malformed
590
+ // `--branch` exits before any expensive analysis starts. Capture the TRIMMED
591
+ // return so a whitespace-padded value (e.g. " feature" from shell completion)
592
+ // normalizes before the checked-out-branch mismatch guard and slug — otherwise
593
+ // it would false-reject on-branch or create a ghost index when detached.
594
+ if (cliOptions?.branch !== undefined) {
595
+ try {
596
+ cliOptions.branch = (0, analyze_config_js_1.validateBranchName)(cliOptions.branch, '--branch');
597
+ }
598
+ catch (err) {
599
+ (0, cli_message_js_1.cliError)(` ${err instanceof Error ? err.message : String(err)}\n`);
600
+ process.exitCode = 1;
601
+ return;
602
+ }
603
+ }
604
+ // ── Load .cgraphrc and merge: CLI flags override config (#243) ───
605
+ // Parse/validate before the progress bar so a malformed config produces an
606
+ // actionable error and exits before any expensive analysis starts.
607
+ let options;
608
+ try {
609
+ const fileConfig = (0, analyze_config_js_1.loadAnalyzeConfig)(repoPath);
610
+ options = (0, analyze_config_js_1.mergeAnalyzeOptions)(cliOptions ?? {}, fileConfig);
611
+ }
612
+ catch (err) {
613
+ const msg = err instanceof analyze_config_js_1.GitNexusRcError
614
+ ? err.message
615
+ : `Invalid .cgraphrc: ${err instanceof Error ? err.message : String(err)}`;
616
+ (0, cli_message_js_1.cliError)(` ${msg}\n`, { recoveryHint: 'cgraphrc-invalid' });
617
+ process.exitCode = 1;
618
+ return;
619
+ }
620
+ if (options.verbose) {
621
+ process.env.CGRAPH_VERBOSE = '1';
622
+ }
623
+ if (options.maxFileSize) {
624
+ process.env.CGRAPH_MAX_FILE_SIZE = options.maxFileSize;
625
+ }
626
+ if (options.workerTimeout) {
627
+ const workerTimeoutSeconds = Number(options.workerTimeout);
628
+ if (!Number.isFinite(workerTimeoutSeconds) || workerTimeoutSeconds < 1) {
629
+ (0, cli_message_js_1.cliError)(' --worker-timeout must be at least 1 second.\n');
630
+ process.exitCode = 1;
631
+ return;
632
+ }
633
+ process.env.CGRAPH_WORKER_SUB_BATCH_TIMEOUT_MS = String(Math.round(workerTimeoutSeconds * 1000));
634
+ }
635
+ if (options.walCheckpointThreshold !== undefined) {
636
+ const parsed = (0, lbug_config_js_1.parseWalCheckpointThreshold)(options.walCheckpointThreshold);
637
+ if (parsed === undefined) {
638
+ (0, cli_message_js_1.cliError)(' --wal-checkpoint-threshold must be an integer >= -1.\n');
639
+ process.exitCode = 1;
640
+ return;
641
+ }
642
+ process.env.CGRAPH_WAL_CHECKPOINT_THRESHOLD = String(parsed);
643
+ }
644
+ // `--workers` is threaded through `runFullAnalysis` options → PipelineOptions
645
+ // → createWorkerPool, intentionally bypassing the CGRAPH_WORKER_POOL_SIZE
646
+ // env channel so this CLI surface never mutates `process.env` for pool size.
647
+ // Tests can therefore re-invoke analyzeCommand with different --workers
648
+ // values back-to-back and observe the value they passed, not whatever the
649
+ // previous call leaked.
650
+ let workerPoolSize;
651
+ if (options.workers !== undefined) {
652
+ const parsedWorkers = Number(options.workers);
653
+ if (!Number.isInteger(parsedWorkers) || parsedWorkers < 1) {
654
+ (0, cli_message_js_1.cliError)(' --workers must be a positive integer (>= 1). ' +
655
+ 'GitNexus parses through a worker pool only — there is no sequential ' +
656
+ 'mode, so 0 is not allowed. Omit --workers for an auto-sized pool.\n');
657
+ process.exitCode = 1;
658
+ return;
659
+ }
660
+ workerPoolSize = parsedWorkers;
661
+ }
662
+ // If the target repo contains files an optional grammar would parse but
663
+ // that grammar's native binding is absent (or disabled via
664
+ // CGRAPH_SKIP_OPTIONAL_GRAMMARS), warn before analysis so users learn why
665
+ // those files end up unparsed instead of silently getting a degraded index.
666
+ // The extension set is derived from OPTIONAL_GRAMMARS so it can't drift.
667
+ try {
668
+ const optionalGlobs = (0, optional_grammars_js_1.getOptionalGrammarExtensions)().map((e) => `**/*${e}`);
669
+ const matches = await (0, glob_1.glob)(optionalGlobs, {
670
+ cwd: repoPath,
671
+ ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**'],
672
+ dot: false,
673
+ nodir: true,
674
+ absolute: false,
675
+ });
676
+ if (matches.length > 0) {
677
+ const present = new Set();
678
+ for (const m of matches) {
679
+ const ext = path_1.default.extname(m).toLowerCase();
680
+ if (ext)
681
+ present.add(ext);
682
+ }
683
+ (0, optional_grammars_js_1.warnMissingOptionalGrammars)({ context: 'analyze', relevantExtensions: present });
684
+ }
685
+ }
686
+ catch {
687
+ // Best-effort warning \u2014 never block analyze on the precheck.
688
+ }
689
+ // KuzuDB migration cleanup is handled by runFullAnalysis internally.
690
+ if (process.env.CGRAPH_NO_GITIGNORE) {
691
+ console.log(' CGRAPH_NO_GITIGNORE is set — skipping .gitignore (still reading .cgraphignore)\n');
692
+ }
693
+ const maxFileSizeBanner = (0, max_file_size_js_1.getMaxFileSizeBannerMessage)();
694
+ if (maxFileSizeBanner) {
695
+ console.log(`${maxFileSizeBanner}\n`);
696
+ }
697
+ // ── CLI progress bar setup ─────────────────────────────────────────
698
+ const barOptions = {
699
+ format: ' {bar} {percentage}% | {phase}',
700
+ barCompleteChar: '\u2588',
701
+ barIncompleteChar: '\u2591',
702
+ hideCursor: true,
703
+ barGlue: '',
704
+ autopadding: true,
705
+ clearOnComplete: false,
706
+ stopOnComplete: false,
707
+ };
708
+ if (process.env[RESPAWN_PROGRESS_ENV] === '1' && process.stderr.isTTY !== true) {
709
+ // Heap respawn pipes stderr so the parent can classify native/OOM crashes.
710
+ // The parent was a real TTY when it opted into this env var, so forward
711
+ // ANSI cursor controls through the pipe instead of cli-progress' non-TTY
712
+ // newline mode. That keeps one-line redraw UX while retaining stderr tail
713
+ // capture for diagnostics.
714
+ barOptions.terminal = createAnsiPipeTerminal(process.stderr);
715
+ }
716
+ const bar = new cli_progress_1.default.SingleBar(barOptions, cli_progress_1.default.Presets.shades_grey);
717
+ bar.start(100, 0, { phase: 'Initializing...' });
718
+ // Graceful SIGINT handling. Pino's default destination is `sync: false`
719
+ // (buffered) — flush before exit so in-flight records reach stderr.
720
+ // See `cgraph/src/core/logger.ts:flushLoggerSync`.
721
+ let aborted = false;
722
+ const sigintHandler = () => {
723
+ if (aborted)
724
+ process.exit(1);
725
+ aborted = true;
726
+ bar.stop();
727
+ console.log('\n Interrupted — cleaning up...');
728
+ // Bounded CHECKPOINT-then-exit (#2264 review P3): skip the native close (the
729
+ // LadybugDB destructor can double-free after --pdg writes), but don't hang
730
+ // behind a long --pdg COPY holding the connection lock — bound it so a single
731
+ // Ctrl-C stays responsive; the WAL replays on the next analyze. A second
732
+ // Ctrl-C (`if (aborted) process.exit(1)` above) remains the escape hatch.
733
+ void (0, shutdown_helpers_js_1.boundedCheckpointBeforeExit)({
734
+ exitCode: 130,
735
+ beforeExit: async () => {
736
+ const { flushLoggerSync } = await import('../core/logger.js');
737
+ flushLoggerSync();
738
+ },
739
+ });
740
+ };
741
+ process.on('SIGINT', sigintHandler);
742
+ // Route console output through bar.log() to prevent progress bar corruption.
743
+ // This is a deliberate UI pattern (not a logging concern): analyze runs a
744
+ // long-lived progress bar on stdout; any concurrent console.* write would
745
+ // overwrite the bar mid-render. We capture originals, swap to barLog for
746
+ // the lifetime of the run, and restore on completion/error/SIGINT.
747
+ const origLog = console.log.bind(console);
748
+ // eslint-disable-next-line no-console -- intentional console-routing for progress bar UX
749
+ const origWarn = console.warn.bind(console);
750
+ // eslint-disable-next-line no-console -- intentional console-routing for progress bar UX
751
+ const origError = console.error.bind(console);
752
+ let barCurrentValue = 0;
753
+ const barLog = (...args) => {
754
+ process.stdout.write('\x1b[2K\r');
755
+ origLog(args.map((a) => (typeof a === 'string' ? a : String(a))).join(' '));
756
+ bar.update(barCurrentValue);
757
+ };
758
+ console.log = barLog;
759
+ // eslint-disable-next-line no-console -- intentional console-routing for progress bar UX
760
+ console.warn = barLog;
761
+ // eslint-disable-next-line no-console -- intentional console-routing for progress bar UX
762
+ console.error = barLog;
763
+ process.env.CGRAPH_ANALYZE_PROGRESS_ACTIVE = '1';
764
+ // Track elapsed time per phase
765
+ let lastPhaseLabel = 'Initializing...';
766
+ let phaseStart = Date.now();
767
+ const updateBar = (value, phaseLabel) => {
768
+ barCurrentValue = value;
769
+ if (phaseLabel !== lastPhaseLabel) {
770
+ lastPhaseLabel = phaseLabel;
771
+ phaseStart = Date.now();
772
+ }
773
+ const elapsed = Math.round((Date.now() - phaseStart) / 1000);
774
+ const display = elapsed >= 3 ? `${phaseLabel} (${(0, format_elapsed_js_1.formatElapsed)(elapsed)})` : phaseLabel;
775
+ bar.update(value, { phase: display });
776
+ };
777
+ const elapsedTimer = setInterval(() => {
778
+ const elapsed = Math.round((Date.now() - phaseStart) / 1000);
779
+ if (elapsed >= 3) {
780
+ bar.update({ phase: `${lastPhaseLabel} (${(0, format_elapsed_js_1.formatElapsed)(elapsed)})` });
781
+ }
782
+ }, 1000);
783
+ const t0 = Date.now();
784
+ // ── Run shared analysis orchestrator ───────────────────────────────
785
+ try {
786
+ const runOptions = {
787
+ // Has no bearing on the registry collision guard (see
788
+ // allowDuplicateName below).
789
+ force: options.force,
790
+ verbose: options.verbose,
791
+ // CFG/PDG substrate opt-in (#2081 M1) — threaded to both sinks downstream.
792
+ pdg: options.pdg === true,
793
+ // Index-branch selector (#2106). Read straight from the CLI flag (not
794
+ // the .cgraphrc-merged options). Undefined → auto-detect in pipeline.
795
+ branch: cliOptions?.branch,
796
+ registryName: options.name,
797
+ // Registry-collision bypass — its own CLI flag, intentionally NOT
798
+ // overloading --force. A user who hits the collision guard should
799
+ // be able to accept the duplicate name without also paying the
800
+ // cost of a full pipeline re-index. See #829 review round 2.
801
+ allowDuplicateName: options.allowDuplicateName,
802
+ // Worker pool size threaded from --workers, replacing the previous
803
+ // CGRAPH_WORKER_POOL_SIZE env mutation. `undefined` defers to the
804
+ // env / auto-formula fallback inside the pipeline.
805
+ workerPoolSize,
806
+ // Extra fetch-wrapper names from `.cgraphrc` (#1589/#1852 residual);
807
+ // forwarded to the routes phase consumer scan.
808
+ fetchWrappers: options.fetchWrappers,
809
+ // The CLI always process.exit()s after this returns (success path at the
810
+ // end of analyzeCommandImpl, error/interrupt paths via process.exit too),
811
+ // so the finalize close skips the native conn/db close — it can double-free
812
+ // in LadybugDB's ClientContext destructor after --pdg writes (#2264). The
813
+ // CHECKPOINT keeps the index durable; process exit reclaims the handles.
814
+ skipNativeCloseOnExit: true,
815
+ };
816
+ const runCallbacks = {
817
+ onProgress: (_phase, percent, message) => {
818
+ updateBar(percent, message);
819
+ },
820
+ onLog: barLog,
821
+ };
822
+ const bootstrapArgs = runnerIdentityAtBootstrap
823
+ ? [runnerIdentityAtBootstrap]
824
+ : [];
825
+ const result = await (0, run_analyze_js_1.runFullAnalysis)(repoPath, runOptions, runCallbacks, ...bootstrapArgs);
826
+ if (result.alreadyUpToDate) {
827
+ // Even the fast path must prove the repo is discoverable. A prior
828
+ // run can write meta.json and then fail before registerRepo(); in
829
+ // that half-finalized state, runFullAnalysis returns alreadyUpToDate
830
+ // on the next invocation unless we check the registry here too.
831
+ await (0, repo_manager_js_1.assertAnalysisFinalized)(repoPath);
832
+ clearInterval(elapsedTimer);
833
+ process.removeListener('SIGINT', sigintHandler);
834
+ console.log = origLog;
835
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
836
+ console.warn = origWarn;
837
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
838
+ console.error = origError;
839
+ bar.stop();
840
+ console.log(' Already up to date\n');
841
+ // Safe to return without process.exit(0) — the early-return path in
842
+ // runFullAnalysis never opens LadybugDB, so no native handles prevent exit.
843
+ return;
844
+ }
845
+ // Post-finalize invariant (#1169): runFullAnalysis nominally writes
846
+ // meta.json and registers the repo, but on Windows it has been
847
+ // observed to return successfully with neither artifact present
848
+ // (banner-only output, exit 0). Verify both before declaring
849
+ // success so the silent-finalize state surfaces with a non-zero
850
+ // exit code and an actionable error instead of being mistaken for
851
+ // a healthy index.
852
+ await (0, repo_manager_js_1.assertAnalysisFinalized)(repoPath);
853
+ const totalTime = ((Date.now() - t0) / 1000).toFixed(1);
854
+ clearInterval(elapsedTimer);
855
+ process.removeListener('SIGINT', sigintHandler);
856
+ console.log = origLog;
857
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
858
+ console.warn = origWarn;
859
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
860
+ console.error = origError;
861
+ bar.update(100, { phase: 'Done' });
862
+ bar.stop();
863
+ // ── Summary ────────────────────────────────────────────────────
864
+ const s = result.stats;
865
+ console.log(`\n Repository indexed successfully (${totalTime}s)\n`);
866
+ console.log(` ${(s.nodes ?? 0).toLocaleString()} nodes | ${(s.edges ?? 0).toLocaleString()} edges | ${s.communities ?? 0} clusters | ${s.processes ?? 0} flows`);
867
+ console.log(` ${repoPath}`);
868
+ console.log('');
869
+ }
870
+ catch (err) {
871
+ clearInterval(elapsedTimer);
872
+ process.removeListener('SIGINT', sigintHandler);
873
+ console.log = origLog;
874
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
875
+ console.warn = origWarn;
876
+ // eslint-disable-next-line no-console -- restoring after intentional progress-bar routing
877
+ console.error = origError;
878
+ bar.stop();
879
+ const msg = err instanceof Error ? err.message : String(err);
880
+ // Registry name-collision from --name (#829) — surface as an
881
+ // actionable error rather than a generic stack-trace.
882
+ if (err instanceof repo_manager_js_1.RegistryNameCollisionError) {
883
+ (0, cli_message_js_1.cliError)(`\n Registry name collision:\n` +
884
+ ` "${err.registryName}" is already used by "${err.existingPath}".\n\n` +
885
+ ` Options:\n` +
886
+ ` • Pick a different alias: cgraph analyze --name <alias>\n` +
887
+ ` • Allow the duplicate: cgraph analyze --allow-duplicate-name (leaves "-r ${err.registryName}" ambiguous)\n`, { registryName: err.registryName, existingPath: err.existingPath });
888
+ process.exitCode = 1;
889
+ return;
890
+ }
891
+ // Another analyze held the index lock past the configured wait ceiling
892
+ // (#2658, CGRAPH_INDEX_LOCK_TIMEOUT_MS). The on-disk index is being
893
+ // refreshed by the holder — this is a clean, expected condition, not a
894
+ // crash, so render the message without a stack trace.
895
+ if (err instanceof index_lock_js_1.IndexLockTimeoutError) {
896
+ (0, cli_message_js_1.cliError)(` Another cgraph analyze (pid ${err.holder.pid} on ${err.holder.hostname}) is ` +
897
+ `already refreshing this index and did not finish within the wait window.\n` +
898
+ ` The on-disk index is being updated by that run. Retry later, or raise\n` +
899
+ ` CGRAPH_INDEX_LOCK_TIMEOUT_MS to wait longer.\n`, { recoveryHint: 'index-lock-timeout', holderPid: err.holder.pid });
900
+ process.exitCode = 1;
901
+ return;
902
+ }
903
+ // Finalize invariant failure (#1169) — keep the rich actionable
904
+ // message intact and write through realStderrWrite so it can't be
905
+ // erased by a leftover bar refresh on slow terminals.
906
+ if (err instanceof repo_manager_js_1.AnalysisNotFinalizedError) {
907
+ writeFatalToStderr('Analysis did not finalize', err);
908
+ realStderrWrite(`\n Diagnostic checklist:\n` +
909
+ ` 1. Re-run "cgraph analyze" - transient native errors often clear on retry.\n` +
910
+ ` 2. Inspect ${err.storagePath} - a leftover lbug.wal indicates an aborted write.\n` +
911
+ ` 3. If the failure persists, run with NODE_OPTIONS="--max-old-space-size=8192 --trace-exit"\n` +
912
+ ` and attach the trace to the GitNexus issue tracker.\n\n`);
913
+ process.exitCode = 1;
914
+ return;
915
+ }
916
+ // workspace 配置文件存在但解析失败/结构非法(spec §9):错误消息已自带
917
+ // 字段路径与修复提示,直接渲染消息(用户可修复错误,不带 stack trace 噪音)。
918
+ if (err instanceof workspace_config_js_1.WorkspaceConfigError) {
919
+ (0, cli_message_js_1.cliError)(` ${msg.replace(/\n/g, '\n ')}\n`, { recoveryHint: 'workspace-config' });
920
+ process.exitCode = 1;
921
+ return;
922
+ }
923
+ // An extracted edge whose FROM→TO label pair is missing from GitNexus's own
924
+ // relation DDL (#2789). `assertDeclaredPair` aborts the run rather than let
925
+ // the bulk COPY fail late and silently drop the edge, so the user sees a
926
+ // mid-run crash inside GitNexus internals with nothing to act on. Name the
927
+ // pair, the relationship and the file that produced it, and say plainly that
928
+ // a re-run cannot help — this is deterministic for the same input.
929
+ // Checked by TYPE (repo norm, #2385) BEFORE the message-text heuristics
930
+ // below, and through the `cause` chain because the ingestion phase runner
931
+ // rewraps every phase failure as `Phase 'X' failed: …`.
932
+ const undeclaredPair = (0, rel_pair_routing_js_1.findUndeclaredRelationPairError)(err);
933
+ if (undeclaredPair !== undefined) {
934
+ // Render the error's OWN message indented — same idiom as the
935
+ // `LbugWipeError` and page-size branches below. `UndeclaredRelationPairError`
936
+ // builds a fully self-contained message (pair, relationship type, both node
937
+ // ids, source file, issue URL, `.cgraphignore` workaround) precisely
938
+ // because `cgraph serve` forwards only `err.message` over worker IPC.
939
+ // Re-rendering those fields here would be a second copy of one string, free
940
+ // to drift from the first — and the actionable half would reach CLI users
941
+ // only. `undeclaredPair.message`, not the outer `msg`: the real error may be
942
+ // several `cause` levels below the phase wrapper `msg` came from.
943
+ (0, cli_message_js_1.cliError)(` ${undeclaredPair.message.replace(/\n/g, '\n ')}\n`, {
944
+ recoveryHint: 'undeclared-relation-pair',
945
+ labelPair: undeclaredPair.pairKey,
946
+ relationType: undeclaredPair.relationType,
947
+ sourceFile: undeclaredPair.sourceFile,
948
+ });
949
+ process.exitCode = 1;
950
+ return;
951
+ }
952
+ // WAL corruption — the index file is unreadable. Give a clear recovery
953
+ // path without a confusing stack trace (the native error message alone
954
+ // is enough signal).
955
+ if ((0, lbug_config_js_1.isWalCorruptionError)(err) || msg.includes('LadybugDB WAL corruption')) {
956
+ (0, cli_message_js_1.cliError)(` The GitNexus index has a corrupted WAL file.\n` +
957
+ ` This usually happens when a previous analysis was interrupted mid-write.\n` +
958
+ ` ${lbug_config_js_1.WAL_RECOVERY_SUGGESTION}\n`, { recoveryHint: 'wal-corruption' });
959
+ process.exitCode = 1;
960
+ return;
961
+ }
962
+ if ((0, lbug_config_js_1.isLbugCheckpointIoError)(err)) {
963
+ // #2599: when the checkpoint IO error also looks busy/locked, another
964
+ // handle holds the store open — name that actionable cause alongside the
965
+ // threshold hint (the original error is preserved so the hint still fires).
966
+ const heldOpen = (0, lbug_config_js_1.isLbugCheckpointBusyError)(err)
967
+ ? ` Another process may hold the store open (a running \`cgraph mcp\` server, or a\n` +
968
+ ` stale reader) — close other GitNexus processes on this repo, then retry.\n`
969
+ : '';
970
+ (0, cli_message_js_1.cliError)(` LadybugDB failed while rotating/removing WAL checkpoint files.\n` +
971
+ heldOpen +
972
+ ` This can happen when auto-checkpoint runs at the default threshold (~16MB).\n` +
973
+ ` Retry with a larger checkpoint threshold to reduce checkpoint frequency:\n` +
974
+ ` cgraph analyze --wal-checkpoint-threshold ${RECOMMENDED_WAL_CHECKPOINT_THRESHOLD}\n` +
975
+ ` (or set CGRAPH_WAL_CHECKPOINT_THRESHOLD=${RECOMMENDED_WAL_CHECKPOINT_THRESHOLD})\n` +
976
+ ` (Try 33554432 = 32 MiB on small-disk / CI runners.)\n`, { recoveryHint: 'wal-checkpoint-threshold' });
977
+ process.exitCode = 1;
978
+ return;
979
+ }
980
+ // DB-family wipe failure (#2409, tri-review 4669518496 P2-4): the rebuild
981
+ // could not verify the LadybugDB file family was removed — usually another
982
+ // process (MCP server, serve worker, antivirus) holding the index open.
983
+ // Keyed on the error *type* (repo norm from #2385), never message text.
984
+ // The message itself is fully self-contained (survivor paths + stop-MCP /
985
+ // AV-exclusion / re-run guidance) because the serve worker forwards only
986
+ // `err.message` over IPC — this branch just renders it without the
987
+ // raw-stack fallback below.
988
+ if (err instanceof lbug_adapter_js_1.LbugWipeError) {
989
+ (0, cli_message_js_1.cliError)(` ${msg.replace(/\n/g, '\n ')}\n`, {
990
+ recoveryHint: 'lbug-wipe-failed',
991
+ });
992
+ process.exitCode = 1;
993
+ return;
994
+ }
995
+ // Buffer-manager frame-release failure on non-4K-page kernels (#1231).
996
+ // LadybugDB <= 0.17.x assumed 4 KiB OS pages when releasing evicted
997
+ // frames; Raspberry Pi 5 (16 KiB kernel pages) and other arm64 systems
998
+ // crash mid-COPY with a raw native message. 0.18.0 detects the page size
999
+ // at runtime, so the actionable fix depends on which side of that
1000
+ // boundary the installed @ladybugdb/core is.
1001
+ if ((0, lbug_config_js_1.isLbugPageSizeFrameError)(err)) {
1002
+ const pageSize = (0, lbug_config_js_1.getOsPageSize)();
1003
+ const ladybug = (0, capabilities_js_1.getRuntimeFingerprint)().ladybugdb;
1004
+ const pageLine = pageSize !== undefined && pageSize !== 4096
1005
+ ? ` Detected OS page size: ${pageSize} bytes (non-4K — e.g. Raspberry Pi 5 16K kernel, Asahi Linux).\n`
1006
+ : '';
1007
+ // The upgrade variant must not assert version facts about an unknown
1008
+ // version — mirror the doctor-side wording rule (#2424 review R2).
1009
+ const upgradeIntro = ladybug === undefined
1010
+ ? ` The installed @ladybugdb/core version is unknown — it may predate the\n` +
1011
+ ` runtime OS-page-size detection added in 0.18.0.\n`
1012
+ : ` The installed @ladybugdb/core (${ladybug}) assumes 4 KiB pages in its buffer\n` +
1013
+ ` manager.\n`;
1014
+ const guidance = (0, lbug_config_js_1.isPageSizeAwareLadybug)(ladybug)
1015
+ ? ` The installed @ladybugdb/core (${ladybug}) already detects the OS page size at runtime,\n` +
1016
+ ` so this configuration was expected to work. Please report it:\n` +
1017
+ ` https://github.com/abhigyanpatwari/GitNexus/issues/1231\n` +
1018
+ ` and include: gitnexus --version, node --version, getconf PAGE_SIZE, uname -a,\n` +
1019
+ ` and the full error message above.\n`
1020
+ : upgradeIntro +
1021
+ ` Upgrade GitNexus to a release that bundles @ladybugdb/core >= 0.18.0\n` +
1022
+ ` (gitnexus >= 1.6.9), which detects the OS page size at runtime:\n` +
1023
+ ` npm install -g cgraph@latest\n` +
1024
+ ` Last-resort workaround on Raspberry Pi 5: boot the 4 KiB-page kernel\n` +
1025
+ ` (config.txt: kernel=kernel8.img), at the cost of Pi 5 optimizations.\n`;
1026
+ // Embed the raw native text (indented, no stack) so "the full error
1027
+ // message above" is fulfillable — same idiom as the LbugWipeError
1028
+ // branch. The errno suffix and the 0.18.0 guard's frame/granule numbers
1029
+ // are the discriminating triage content (#2424 review P2).
1030
+ (0, cli_message_js_1.cliError)(` LadybugDB's buffer manager failed to release frame memory.\n` +
1031
+ ` ${msg.replace(/\n/g, '\n ')}\n` +
1032
+ pageLine +
1033
+ guidance, { recoveryHint: 'lbug-page-size', pageSize, ladybugVersion: ladybug });
1034
+ process.exitCode = 1;
1035
+ return;
1036
+ }
1037
+ // Bypass the redirected console.error and write the full stack to
1038
+ // the real stderr captured at module load. The redirected
1039
+ // console.error wraps every line with `\\x1b[2K\\r` (ANSI clear-line)
1040
+ // and forces a bar.update() afterwards, which on some Windows
1041
+ // terminals visually erases the failure message — the canonical
1042
+ // shape of the silent-exit symptom in #1169.
1043
+ writeFatalToStderr('Analysis failed', err);
1044
+ // Provide helpful guidance for known failure modes
1045
+ if (msg.includes('Maximum call stack size exceeded') ||
1046
+ msg.includes('call stack') ||
1047
+ msg.includes('Map maximum size') ||
1048
+ msg.includes('Invalid array length') ||
1049
+ msg.includes('Invalid string length') ||
1050
+ msg.includes('allocation failed') ||
1051
+ msg.includes('heap out of memory') ||
1052
+ msg.includes('JavaScript heap')) {
1053
+ (0, cli_message_js_1.cliError)(` This error typically occurs on very large repositories.\n` +
1054
+ ` Suggestions:\n` +
1055
+ ` 1. Add large vendored/generated directories to .cgraphignore\n` +
1056
+ ` 2. Increase Node.js heap: NODE_OPTIONS="--max-old-space-size=16384"\n` +
1057
+ ` 3. Increase stack size: NODE_OPTIONS="--stack-size=4096"\n`, { recoveryHint: 'large-repo' });
1058
+ }
1059
+ else if (msg.includes('ERESOLVE') || msg.includes('Could not resolve dependency')) {
1060
+ // Note: the original arborist "Cannot destructure property 'package' of
1061
+ // 'node.target'" crash happens inside npm *before* gitnexus code runs,
1062
+ // so it can't be caught here. This branch handles dependency-resolution
1063
+ // errors that surface at runtime (e.g. dynamic require failures).
1064
+ (0, cli_message_js_1.cliError)(` This looks like an npm dependency resolution issue.\n` +
1065
+ ` Suggestions:\n` +
1066
+ ` 1. Clear the npm cache: npm cache clean --force\n` +
1067
+ ` 2. Update npm: npm install -g npm@latest\n` +
1068
+ ` 3. Reinstall cgraph: npm install -g cgraph@latest\n` +
1069
+ ` 4. Or try npx directly: npx cgraph@latest analyze\n`, { recoveryHint: 'npm-resolution' });
1070
+ }
1071
+ else if (msg.includes('MODULE_NOT_FOUND') ||
1072
+ msg.includes('Cannot find module') ||
1073
+ msg.includes('ERR_MODULE_NOT_FOUND')) {
1074
+ (0, cli_message_js_1.cliError)(` A required module could not be loaded. The installation may be corrupt.\n` +
1075
+ ` Suggestions:\n` +
1076
+ ` 1. Reinstall: npm install -g cgraph@latest\n` +
1077
+ ` 2. Clear cache: npm cache clean --force && npx cgraph@latest analyze\n`, { recoveryHint: 'module-not-found' });
1078
+ }
1079
+ process.exitCode = 1;
1080
+ return;
1081
+ }
1082
+ // LadybugDB's native module holds open handles that prevent Node from exiting.
1083
+ // ONNX Runtime also registers native atexit hooks that segfault on some
1084
+ // platforms (#38, #40). Force-exit to ensure clean termination.
1085
+ process.exit(0);
1086
+ };