@backbencher/brain 0.0.0-stage → 0.1.0

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 (319) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/EMBEDDINGS.md +355 -0
  3. package/LICENSE +21 -0
  4. package/README.md +415 -2
  5. package/bin/bb +13 -0
  6. package/dist/analysis-exclusions-7ZJDXOVZ.js +35 -0
  7. package/dist/brain-index-health-KY7K552E.js +17 -0
  8. package/dist/brain-relationship-enrichment-QH7OOHUF.js +558 -0
  9. package/dist/brain.sql-EIM4WS4D.js +29 -0
  10. package/dist/chunk-2BSKD7O3.js +40 -0
  11. package/dist/chunk-2DE27DVC.js +1314 -0
  12. package/dist/chunk-2RRBMNBQ.js +322 -0
  13. package/dist/chunk-2RTN2DFU.js +711 -0
  14. package/dist/chunk-2WXYNLBA.js +29 -0
  15. package/dist/chunk-3CTFIJJB.js +17 -0
  16. package/dist/chunk-3LFTSMIV.js +174 -0
  17. package/dist/chunk-47HKX4AJ.js +930 -0
  18. package/dist/chunk-4H22TLOT.js +543 -0
  19. package/dist/chunk-5SD45FLC.js +818 -0
  20. package/dist/chunk-66A5ZFYA.js +1758 -0
  21. package/dist/chunk-6AIRWAO2.js +247 -0
  22. package/dist/chunk-6WNGD3NN.js +196 -0
  23. package/dist/chunk-7AN7U5IZ.js +371 -0
  24. package/dist/chunk-BHB7BYYI.js +626 -0
  25. package/dist/chunk-BQ3OVQ3P.js +125 -0
  26. package/dist/chunk-CW4XXSNN.js +1479 -0
  27. package/dist/chunk-D2Q4Y47A.js +53 -0
  28. package/dist/chunk-DIYAGQJL.js +34 -0
  29. package/dist/chunk-DYM4FQEE.js +90 -0
  30. package/dist/chunk-EWMWK7WN.js +75 -0
  31. package/dist/chunk-FVVQTSIM.js +3427 -0
  32. package/dist/chunk-FWSL4VG6.js +1290 -0
  33. package/dist/chunk-GBI7V7KY.js +69 -0
  34. package/dist/chunk-GEFFO6O2.js +152 -0
  35. package/dist/chunk-HOWAQXJO.js +236 -0
  36. package/dist/chunk-HQSPJDHI.js +613 -0
  37. package/dist/chunk-IFZNR5UJ.js +2863 -0
  38. package/dist/chunk-J4PMBXQQ.js +336 -0
  39. package/dist/chunk-KAET47ZL.js +125 -0
  40. package/dist/chunk-KCDECRJY.js +440 -0
  41. package/dist/chunk-KLK3PBTO.js +1119 -0
  42. package/dist/chunk-L5TDYKYK.js +76 -0
  43. package/dist/chunk-MLKGABMK.js +9 -0
  44. package/dist/chunk-OWISBAOF.js +61 -0
  45. package/dist/chunk-PJTNGD3Z.js +6924 -0
  46. package/dist/chunk-QLK6ED4Q.js +235 -0
  47. package/dist/chunk-R2GW4F6R.js +19 -0
  48. package/dist/chunk-RCMTFSEF.js +87 -0
  49. package/dist/chunk-RH7KC5HU.js +12050 -0
  50. package/dist/chunk-RM3PY6TG.js +376 -0
  51. package/dist/chunk-ROMM6KMC.js +433 -0
  52. package/dist/chunk-SK6YVHFZ.js +211 -0
  53. package/dist/chunk-SM7RFQRO.js +214 -0
  54. package/dist/chunk-UFE77L67.js +782 -0
  55. package/dist/chunk-UGR4QIGS.js +67 -0
  56. package/dist/chunk-UUNHHX4M.js +13 -0
  57. package/dist/chunk-V44PGPA6.js +2104 -0
  58. package/dist/chunk-VL52PL2T.js +71 -0
  59. package/dist/chunk-VURYFIHW.js +201 -0
  60. package/dist/chunk-XJKJYIPP.js +7436 -0
  61. package/dist/chunk-YI6FF2ZR.js +340 -0
  62. package/dist/cli/index.js +37 -0
  63. package/dist/config-HZAAYDP3.js +10 -0
  64. package/dist/content-search-642F7E5V.js +593 -0
  65. package/dist/database-TCTZDLE5.js +9 -0
  66. package/dist/doctor-GXCKSJOX.js +395 -0
  67. package/dist/edit-engine-KM7MPFEC.js +51 -0
  68. package/dist/engine-42TZFNIZ.js +11 -0
  69. package/dist/engine-LO6L4JLQ.js +18 -0
  70. package/dist/fingerprint-XDXFRWO6.js +33 -0
  71. package/dist/framework-intelligence-DWFCKV44.js +860 -0
  72. package/dist/freshness-3K6VU5OT.js +174 -0
  73. package/dist/graph-engine-PL5YA7BA.js +21 -0
  74. package/dist/graph_request-MM4REP6H.js +350 -0
  75. package/dist/impact_request-WDE47IZ5.js +68 -0
  76. package/dist/index-space-IUUN5WYV.js +15 -0
  77. package/dist/index-status-6BD7UBHR.js +34 -0
  78. package/dist/index.js +159 -0
  79. package/dist/instance-FO6QZRLH.js +19 -0
  80. package/dist/language-detection-DFCAU5DZ.js +11 -0
  81. package/dist/lsp/server.js +4301 -0
  82. package/dist/mcp/server.js +132 -0
  83. package/dist/onboard-DIQZV2NW.js +161 -0
  84. package/dist/override-companion-pass-XR7MHTP7.js +117 -0
  85. package/dist/parallel-indexer-4PW3AFXP.js +88 -0
  86. package/dist/pool-worker.js +1153 -0
  87. package/dist/project-health-ZS5TS2Z6.js +94 -0
  88. package/dist/project-index-5SDPHITE.js +57 -0
  89. package/dist/project-registry-DGZBIZS7.js +355 -0
  90. package/dist/real-bash-analyzer-SXSV67E2.js +2201 -0
  91. package/dist/real-c-analyzer-SY7FTZ6W.js +5942 -0
  92. package/dist/real-clean-analyzer-IGDHHLZK.js +3470 -0
  93. package/dist/real-clojure-analyzer-4OH7IWLB.js +2818 -0
  94. package/dist/real-cpp-analyzer-7LTDRJRJ.js +4101 -0
  95. package/dist/real-csharp-analyzer-KICU3TLH.js +3298 -0
  96. package/dist/real-css-analyzer-HPU277Q6.js +15 -0
  97. package/dist/real-dart-analyzer-7LZ5LCMW.js +3944 -0
  98. package/dist/real-elixir-analyzer-BE3MEVZO.js +2192 -0
  99. package/dist/real-erlang-analyzer-BZMAKYBK.js +1731 -0
  100. package/dist/real-fsharp-analyzer-5QLTOV3E.js +2390 -0
  101. package/dist/real-go-analyzer-POD7MZQR.js +4126 -0
  102. package/dist/real-graphql-analyzer-MAQRZ6QW.js +1442 -0
  103. package/dist/real-groovy-analyzer-MEWSUPMJ.js +2285 -0
  104. package/dist/real-haskell-analyzer-I5L2GR3Y.js +2533 -0
  105. package/dist/real-hcl-analyzer-DBOPXSWJ.js +725 -0
  106. package/dist/real-html-analyzer-O63XZLZD.js +1759 -0
  107. package/dist/real-java-analyzer-CHCW3EKA.js +4677 -0
  108. package/dist/real-javascript-analyzer-QAAJQYZE.js +14 -0
  109. package/dist/real-json-analyzer-UGBR7YQN.js +1640 -0
  110. package/dist/real-julia-analyzer-35Q4GHOZ.js +2085 -0
  111. package/dist/real-kotlin-analyzer-GRAYCWW2.js +3956 -0
  112. package/dist/real-lua-analyzer-5BAPDZDF.js +1957 -0
  113. package/dist/real-makefile-analyzer-YJKAHNAS.js +920 -0
  114. package/dist/real-markdown-analyzer-UKUQZO4F.js +1215 -0
  115. package/dist/real-matlab-analyzer-FVIKQZKG.js +480 -0
  116. package/dist/real-nim-analyzer-M7FAIABG.js +3603 -0
  117. package/dist/real-objective-c-analyzer-XMYQIGQI.js +1518 -0
  118. package/dist/real-perl-analyzer-ZLY6M2DZ.js +1865 -0
  119. package/dist/real-php-analyzer-KI2ZAM7X.js +9368 -0
  120. package/dist/real-powershell-analyzer-B3T5ZP6U.js +2915 -0
  121. package/dist/real-protobuf-analyzer-23OZ75XV.js +867 -0
  122. package/dist/real-python-analyzer-I4TIUB6D.js +4880 -0
  123. package/dist/real-r-analyzer-FJZJXXS6.js +2596 -0
  124. package/dist/real-ruby-analyzer-M3UFIVTQ.js +2429 -0
  125. package/dist/real-rust-analyzer-LVSONPAN.js +3359 -0
  126. package/dist/real-scala-analyzer-CWPI33Q2.js +3293 -0
  127. package/dist/real-scss-analyzer-TGRJQ7TH.js +1515 -0
  128. package/dist/real-solidity-analyzer-4P2VBVWA.js +2608 -0
  129. package/dist/real-sql-analyzer-J7DYZOZR.js +3840 -0
  130. package/dist/real-svelte-analyzer-NHEN2SX5.js +2532 -0
  131. package/dist/real-swift-analyzer-2NSYULWI.js +2311 -0
  132. package/dist/real-toml-analyzer-L3C66L7Q.js +929 -0
  133. package/dist/real-typescript-analyzer-FTC6ETRQ.js +14 -0
  134. package/dist/real-vb-analyzer-ORY7LAQS.js +3145 -0
  135. package/dist/real-vba-analyzer-JH2TTUFI.js +466 -0
  136. package/dist/real-vue-analyzer-OO4FUGBV.js +2680 -0
  137. package/dist/real-xml-analyzer-6CQVR477.js +2405 -0
  138. package/dist/real-yaml-analyzer-J6MQG3YX.js +3528 -0
  139. package/dist/real-zig-analyzer-EFKCPJNU.js +2430 -0
  140. package/dist/regex-search-OPTLKUN5.js +239 -0
  141. package/dist/rules-I453JTRC.js +152 -0
  142. package/dist/scoped-path-MJYWJZQX.js +11 -0
  143. package/dist/setup-show-Y5GB5KXA.js +15 -0
  144. package/dist/setup-wizard-G5YYR5T6.js +24 -0
  145. package/dist/symbol-search-KB4MU4SI.js +16 -0
  146. package/dist/taint-YOTN5X55.js +202 -0
  147. package/dist/taint-analyzer-N7YLZU3N.js +163 -0
  148. package/dist/tool-handlers-G4NAGJIH.js +72 -0
  149. package/dist/tool-registry-BPEJNSZG.js +17 -0
  150. package/dist/tool-validation-RF675A3C.js +32 -0
  151. package/dist/type-inference-4Y7WTMFE.js +13 -0
  152. package/dist/vector-binary-LMY4QGAN.js +19 -0
  153. package/dist/version-LXGNFO37.js +9 -0
  154. package/dist/wasm-NMWO3WXY.js +16 -0
  155. package/docs/EMBEDDINGS.md +132 -0
  156. package/docs/README.md +178 -0
  157. package/docs/data/m10-baseline.json +602 -0
  158. package/docs/data/m10-benchmark-baseline.json +57 -0
  159. package/docs/data/m10-benchmark-last-run.json +127 -0
  160. package/docs/data/m10-final-audit.json +215 -0
  161. package/docs/data/m12-final-audit.json +138 -0
  162. package/docs/data/m12-surface-matrix.json +50 -0
  163. package/docs/data/public-tools.json +1902 -0
  164. package/docs/indexing/DEAD-ASSETS.md +88 -0
  165. package/docs/indexing/INDEXER-REVIEW.md +634 -0
  166. package/docs/indexing/PERFORMANCE-FINDINGS.md +106 -0
  167. package/docs/indexing/README.md +427 -0
  168. package/docs/indexing/discovery-matrix.md +41 -0
  169. package/docs/indexing/embeddings.md +325 -0
  170. package/docs/indexing/environment-variables.md +77 -0
  171. package/docs/indexing/performance.md +323 -0
  172. package/docs/indexing/resume.md +345 -0
  173. package/docs/indexing/troubleshooting.md +391 -0
  174. package/docs/man/bb.1 +190 -0
  175. package/docs/tools/bb_analyze.md +147 -0
  176. package/docs/tools/bb_annotate.md +110 -0
  177. package/docs/tools/bb_annotations.md +106 -0
  178. package/docs/tools/bb_ask.md +101 -0
  179. package/docs/tools/bb_cross_language.md +103 -0
  180. package/docs/tools/bb_doc.md +169 -0
  181. package/docs/tools/bb_edit.md +185 -0
  182. package/docs/tools/bb_graph.md +169 -0
  183. package/docs/tools/bb_health.md +156 -0
  184. package/docs/tools/bb_impact.md +117 -0
  185. package/docs/tools/bb_index.md +108 -0
  186. package/docs/tools/bb_migrate.md +135 -0
  187. package/docs/tools/bb_patterns.md +140 -0
  188. package/docs/tools/bb_search.md +150 -0
  189. package/docs/tools/bb_security.md +100 -0
  190. package/docs/tools/bb_visualize.md +184 -0
  191. package/grammars/README.md +57 -0
  192. package/grammars/THIRD-PARTY-NOTICES.md +50 -0
  193. package/grammars/tree-sitter-c/LICENSE +21 -0
  194. package/grammars/tree-sitter-clojure/LICENSE.md +21 -0
  195. package/grammars/tree-sitter-cpp/LICENSE +21 -0
  196. package/grammars/tree-sitter-csharp/LICENSE +21 -0
  197. package/grammars/tree-sitter-css/LICENSE +21 -0
  198. package/grammars/tree-sitter-css/README.md +21 -0
  199. package/grammars/tree-sitter-dart/LICENSE +20 -0
  200. package/grammars/tree-sitter-dart-upstream/LICENSE +20 -0
  201. package/grammars/tree-sitter-dart-upstream/README.md +18 -0
  202. package/grammars/tree-sitter-elixir/LICENSE +176 -0
  203. package/grammars/tree-sitter-elixir/README.md +11 -0
  204. package/grammars/tree-sitter-fsharp/LICENSE +21 -0
  205. package/grammars/tree-sitter-fsharp/README.md +45 -0
  206. package/grammars/tree-sitter-graphql/LICENSE +21 -0
  207. package/grammars/tree-sitter-graphql/README.md +106 -0
  208. package/grammars/tree-sitter-groovy/LICENSE +21 -0
  209. package/grammars/tree-sitter-groovy/README.md +4 -0
  210. package/grammars/tree-sitter-haskell/LICENSE +21 -0
  211. package/grammars/tree-sitter-haskell/README.md +394 -0
  212. package/grammars/tree-sitter-hcl/CHANGELOG.md +102 -0
  213. package/grammars/tree-sitter-hcl/LICENSE +201 -0
  214. package/grammars/tree-sitter-hcl/README.md +39 -0
  215. package/grammars/tree-sitter-html/LICENSE +21 -0
  216. package/grammars/tree-sitter-html/README.md +21 -0
  217. package/grammars/tree-sitter-julia/LICENSE +21 -0
  218. package/grammars/tree-sitter-julia/README.md +24 -0
  219. package/grammars/tree-sitter-kotlin/LICENSE +9 -0
  220. package/grammars/tree-sitter-lua/LICENSE.md +21 -0
  221. package/grammars/tree-sitter-lua/README.md +29 -0
  222. package/grammars/tree-sitter-make/LICENSE +21 -0
  223. package/grammars/tree-sitter-matlab/LICENSE +19 -0
  224. package/grammars/tree-sitter-matlab/README.md +99 -0
  225. package/grammars/tree-sitter-nim/LICENSE +373 -0
  226. package/grammars/tree-sitter-nim/README.md +46 -0
  227. package/grammars/tree-sitter-objc/LICENSE +21 -0
  228. package/grammars/tree-sitter-objc/README.md +20 -0
  229. package/grammars/tree-sitter-perl/LICENSE +7 -0
  230. package/grammars/tree-sitter-perl/README.md +100 -0
  231. package/grammars/tree-sitter-powershell/LICENSE +21 -0
  232. package/grammars/tree-sitter-powershell/README.md +7 -0
  233. package/grammars/tree-sitter-proto/LICENSE +21 -0
  234. package/grammars/tree-sitter-proto/README.md +105 -0
  235. package/grammars/tree-sitter-r/LICENSE +9 -0
  236. package/grammars/tree-sitter-r/README.md +66 -0
  237. package/grammars/tree-sitter-ruby/LICENSE +22 -0
  238. package/grammars/tree-sitter-scss/LICENSE +21 -0
  239. package/grammars/tree-sitter-scss/README.md +17 -0
  240. package/grammars/tree-sitter-solidity/LICENSE +7 -0
  241. package/grammars/tree-sitter-sql/LICENSE +21 -0
  242. package/grammars/tree-sitter-typescript/LICENSE +21 -0
  243. package/grammars/tree-sitter-vba/LICENSE +21 -0
  244. package/grammars/tree-sitter-vba/README.md +738 -0
  245. package/grammars/tree-sitter-vbnet/LICENSE +21 -0
  246. package/grammars/tree-sitter-vbnet/README.md +322 -0
  247. package/grammars/tree-sitter-xml/LICENSE +19 -0
  248. package/grammars/tree-sitter-yaml/LICENSE +20 -0
  249. package/grammars/tree-sitter-yaml/README.md +21 -0
  250. package/package.json +184 -4
  251. package/wasm/dart.wasm +0 -0
  252. package/wasm/tree-sitter-bash.wasm +0 -0
  253. package/wasm/tree-sitter-c.wasm +0 -0
  254. package/wasm/tree-sitter-c_sharp.wasm +0 -0
  255. package/wasm/tree-sitter-clean.wasm +0 -0
  256. package/wasm/tree-sitter-clojure.wasm +0 -0
  257. package/wasm/tree-sitter-core_schema.wasm +0 -0
  258. package/wasm/tree-sitter-cpp.wasm +0 -0
  259. package/wasm/tree-sitter-css.wasm +0 -0
  260. package/wasm/tree-sitter-dart.wasm +0 -0
  261. package/wasm/tree-sitter-elisp.wasm +0 -0
  262. package/wasm/tree-sitter-elixir.wasm +0 -0
  263. package/wasm/tree-sitter-elm.wasm +0 -0
  264. package/wasm/tree-sitter-embedded_template.wasm +0 -0
  265. package/wasm/tree-sitter-erlang.wasm +0 -0
  266. package/wasm/tree-sitter-fsharp.wasm +0 -0
  267. package/wasm/tree-sitter-fsharp_signature.wasm +0 -0
  268. package/wasm/tree-sitter-go.wasm +0 -0
  269. package/wasm/tree-sitter-graphql.wasm +0 -0
  270. package/wasm/tree-sitter-groovy.wasm +0 -0
  271. package/wasm/tree-sitter-haskell.wasm +0 -0
  272. package/wasm/tree-sitter-hcl.wasm +0 -0
  273. package/wasm/tree-sitter-html.wasm +0 -0
  274. package/wasm/tree-sitter-java.wasm +0 -0
  275. package/wasm/tree-sitter-javascript.wasm +0 -0
  276. package/wasm/tree-sitter-json.wasm +0 -0
  277. package/wasm/tree-sitter-json_schema.wasm +0 -0
  278. package/wasm/tree-sitter-julia.wasm +0 -0
  279. package/wasm/tree-sitter-kotlin.wasm +0 -0
  280. package/wasm/tree-sitter-lua.wasm +0 -0
  281. package/wasm/tree-sitter-make.wasm +0 -0
  282. package/wasm/tree-sitter-markdown.wasm +0 -0
  283. package/wasm/tree-sitter-markdown_inline.wasm +0 -0
  284. package/wasm/tree-sitter-matlab.wasm +0 -0
  285. package/wasm/tree-sitter-nim.wasm +0 -0
  286. package/wasm/tree-sitter-objc.wasm +0 -0
  287. package/wasm/tree-sitter-ocaml.wasm +0 -0
  288. package/wasm/tree-sitter-perl.wasm +0 -0
  289. package/wasm/tree-sitter-php.wasm +0 -0
  290. package/wasm/tree-sitter-php_only.wasm +0 -0
  291. package/wasm/tree-sitter-powershell.wasm +0 -0
  292. package/wasm/tree-sitter-protobuf.wasm +0 -0
  293. package/wasm/tree-sitter-python.wasm +0 -0
  294. package/wasm/tree-sitter-ql.wasm +0 -0
  295. package/wasm/tree-sitter-r.wasm +0 -0
  296. package/wasm/tree-sitter-rescript.wasm +0 -0
  297. package/wasm/tree-sitter-ruby.wasm +0 -0
  298. package/wasm/tree-sitter-rust.wasm +0 -0
  299. package/wasm/tree-sitter-scala.wasm +0 -0
  300. package/wasm/tree-sitter-scss.wasm +0 -0
  301. package/wasm/tree-sitter-solidity.wasm +0 -0
  302. package/wasm/tree-sitter-sql.wasm +0 -0
  303. package/wasm/tree-sitter-svelte.wasm +0 -0
  304. package/wasm/tree-sitter-swift.wasm +0 -0
  305. package/wasm/tree-sitter-systemrdl.wasm +0 -0
  306. package/wasm/tree-sitter-terraform.wasm +0 -0
  307. package/wasm/tree-sitter-tlaplus.wasm +0 -0
  308. package/wasm/tree-sitter-toml.wasm +0 -0
  309. package/wasm/tree-sitter-tsx.wasm +0 -0
  310. package/wasm/tree-sitter-typescript.wasm +0 -0
  311. package/wasm/tree-sitter-vba.wasm +0 -0
  312. package/wasm/tree-sitter-vbnet.wasm +0 -0
  313. package/wasm/tree-sitter-vue.wasm +0 -0
  314. package/wasm/tree-sitter-xml.wasm +0 -0
  315. package/wasm/tree-sitter-yaml.wasm +0 -0
  316. package/wasm/tree-sitter-zig.wasm +0 -0
  317. package/wasm/tree-sitter.wasm +0 -0
  318. package/wasm/tsx.wasm +0 -0
  319. package/wasm/typescript.wasm +0 -0
@@ -0,0 +1,336 @@
1
+ import {
2
+ fingerprintKey
3
+ } from "./chunk-2RRBMNBQ.js";
4
+ import {
5
+ SemanticEngine,
6
+ assessEndpoint,
7
+ classifyStatus,
8
+ describeEmbeddingSetup,
9
+ isEmbeddingDisabled,
10
+ observedEmbeddingFailures,
11
+ parseEndpoint,
12
+ probeEmbeddingEndpoint,
13
+ readRuntimeOptions
14
+ } from "./chunk-5SD45FLC.js";
15
+ import {
16
+ LOCAL_VECTOR_DIMENSION
17
+ } from "./chunk-7AN7U5IZ.js";
18
+ import {
19
+ bbDataDir
20
+ } from "./chunk-2BSKD7O3.js";
21
+ import {
22
+ __export
23
+ } from "./chunk-MLKGABMK.js";
24
+
25
+ // src/setup/setup-show.ts
26
+ import { existsSync, readFileSync, statSync } from "fs";
27
+ import path from "path";
28
+
29
+ // src/brain/semantic/embedding-diagnosis.ts
30
+ var embedding_diagnosis_exports = {};
31
+ __export(embedding_diagnosis_exports, {
32
+ LOCAL_DIMENSION: () => LOCAL_DIMENSION,
33
+ buildEmbeddingChain: () => buildEmbeddingChain,
34
+ buildEmbeddingDiagnosis: () => buildEmbeddingDiagnosis,
35
+ embeddingChainVerdict: () => embeddingChainVerdict,
36
+ probeEmbeddingDiagnosis: () => probeEmbeddingDiagnosis,
37
+ renderChainSummary: () => renderChainSummary,
38
+ severityOf: () => severityOf
39
+ });
40
+ var LOCAL_LABEL_HINT = SemanticEngine.LOCAL_MODEL_LABEL;
41
+ function sourceLabel(tier, field) {
42
+ return tier === "env" ? `env:BB_EMBEDDING_${field}` : `file:${tier}`;
43
+ }
44
+ function buildEmbeddingChain(state, env = process.env) {
45
+ const options = readRuntimeOptions(env);
46
+ const layers = [];
47
+ const winner = state.tiers.find((t) => t.tier === state.winner && t.complete);
48
+ if (isEmbeddingDisabled(env)) {
49
+ layers.push({
50
+ order: 0,
51
+ role: "disabled",
52
+ label: "embeddings disabled",
53
+ endpoint: "none",
54
+ model: "none",
55
+ keyState: "not-required",
56
+ source: "env:BB_EMBEDDING_DISABLED",
57
+ active: true,
58
+ problems: []
59
+ });
60
+ }
61
+ if (state.configured && winner) {
62
+ const hasKey = typeof winner.keyFingerprint === "string" && winner.keyFingerprint.length > 0;
63
+ const readiness = assessEndpoint(
64
+ winner.baseURL ?? "",
65
+ hasKey ? sourceLabel(winner.tier, "API_KEY") : "none",
66
+ hasKey ? sourceLabel(winner.tier, "API_KEY") : "none"
67
+ );
68
+ layers.push({
69
+ order: layers.length,
70
+ role: "primary",
71
+ label: `primary provider (${winner.tier})`,
72
+ endpoint: winner.baseURL ?? "",
73
+ model: winner.model ?? "",
74
+ keyState: readiness.hasKey ? "present" : readiness.loopback ? "not-required" : "absent",
75
+ source: `url ${sourceLabel(winner.tier, "BASE_URL")} \xB7 model ${sourceLabel(winner.tier, "MODEL")} \xB7 key ${hasKey ? sourceLabel(winner.tier, "API_KEY") : "none"}`,
76
+ active: !options.disabled,
77
+ problems: readiness.problems
78
+ });
79
+ }
80
+ if (options.fallback) {
81
+ const fbKeySource = options.fallback.apiKey ? "env:BB_EMBEDDING_API_KEY" : "none";
82
+ const readiness = assessEndpoint(options.fallback.baseURL, fbKeySource, "env:BB_EMBEDDING_FALLBACK_API_KEY");
83
+ layers.push({
84
+ order: layers.length,
85
+ role: "fallback",
86
+ label: "fallback provider",
87
+ endpoint: options.fallback.baseURL,
88
+ model: options.fallback.model,
89
+ keyState: readiness.hasKey ? "present" : readiness.loopback ? "not-required" : "absent",
90
+ source: `url env:BB_EMBEDDING_FALLBACK_BASE_URL \xB7 model env:BB_EMBEDDING_FALLBACK_MODEL \xB7 key ${options.fallback.apiKey ? "env:BB_EMBEDDING_FALLBACK_API_KEY" : "none"}`,
91
+ active: !options.disabled && state.configured,
92
+ problems: readiness.problems
93
+ });
94
+ }
95
+ layers.push({
96
+ order: layers.length,
97
+ role: "local",
98
+ label: "local word vectors",
99
+ endpoint: "offline",
100
+ model: LOCAL_LABEL_HINT,
101
+ keyState: "not-required",
102
+ source: "built in",
103
+ active: true,
104
+ problems: []
105
+ });
106
+ return layers;
107
+ }
108
+ function detectTierOrderDisagreement(state, env) {
109
+ if (state.winner !== "global") return null;
110
+ const project = state.tiers.find((t) => t.tier === "project");
111
+ if (!project?.complete) return null;
112
+ const explicit = (env.BB_CONFIG_FILE ?? "").trim();
113
+ return {
114
+ reported: state.winner,
115
+ actual: explicit ? "BB_CONFIG_FILE" : "project",
116
+ detail: `bb setup show and bb doctor report the global tier as the winner, but the runtime merges the file tiers project-last (bb.json overrides ~/.bb/config.json), so indexing actually uses ${explicit ? "BB_CONFIG_FILE" : "the project's bb.json"}` + (project.model ? ` (model ${project.model})` : "") + `.`
117
+ };
118
+ }
119
+ function reconstructSources(state) {
120
+ const firstWith = (field, pick, fallback) => {
121
+ for (const tier of state.tiers) {
122
+ const value = pick(tier);
123
+ if (typeof value === "string" && value.length > 0) return sourceLabel(tier.tier, field);
124
+ }
125
+ return fallback;
126
+ };
127
+ return {
128
+ baseURL: firstWith("BASE_URL", (t) => t.baseURL, "default"),
129
+ model: firstWith("MODEL", (t) => t.model, "default"),
130
+ apiKey: firstWith("API_KEY", (t) => t.keyFingerprint, "none")
131
+ };
132
+ }
133
+ function buildEmbeddingDiagnosis(opts) {
134
+ const env = opts.env ?? process.env;
135
+ const state = opts.state;
136
+ const chain = buildEmbeddingChain(state, env);
137
+ const winner = state.tiers.find((t) => t.tier === state.winner && t.complete);
138
+ const sources = reconstructSources(state);
139
+ const setup = describeEmbeddingSetup(
140
+ { baseURL: winner?.baseURL ?? "", model: winner?.model ?? "", configured: state.configured, sources },
141
+ env
142
+ );
143
+ const observed = opts.observedFailures ?? observedEmbeddingFailures().map((f) => ({ ...f, latched: true }));
144
+ return {
145
+ disabled: isEmbeddingDisabled(env),
146
+ configured: state.configured,
147
+ remoteReady: setup.remoteReady && !isEmbeddingDisabled(env),
148
+ fallbackConfigured: chain.some((l) => l.role === "fallback"),
149
+ primaryLayer: chain.find((l) => l.role === "primary") ?? null,
150
+ chain,
151
+ problems: setup.problems,
152
+ observedFailures: observed,
153
+ probe: null,
154
+ tierOrderDisagreement: detectTierOrderDisagreement(state, env)
155
+ };
156
+ }
157
+ async function probeEmbeddingDiagnosis(diagnosis, env = process.env) {
158
+ const layer = diagnosis.primaryLayer;
159
+ if (!layer || diagnosis.disabled) return { ...diagnosis, probe: null };
160
+ const endpoint = parseEndpoint(layer.endpoint);
161
+ const key = readApiKeyForProbe(layer, env);
162
+ const result = await probeEmbeddingEndpoint(
163
+ { baseURL: layer.endpoint, apiKey: key, model: layer.model },
164
+ { timeoutMs: Math.min(readRuntimeOptions(env).timeoutMs, 15e3) }
165
+ );
166
+ return {
167
+ ...diagnosis,
168
+ probe: {
169
+ ok: result.ok,
170
+ elapsedMs: result.elapsedMs,
171
+ endpoint: layer.endpoint,
172
+ model: layer.model,
173
+ dimension: result.dimension,
174
+ status: result.status,
175
+ kind: result.kind ?? (result.ok ? void 0 : classifyStatus(result.status ?? 0)),
176
+ advice: result.advice,
177
+ message: result.message
178
+ }
179
+ };
180
+ }
181
+ function readApiKeyForProbe(layer, env) {
182
+ if (layer.keyState === "absent") return "";
183
+ if (layer.source.startsWith("env:")) return env.BB_EMBEDDING_API_KEY ?? "";
184
+ return "";
185
+ }
186
+ function severityOf(problem) {
187
+ return problem.severity;
188
+ }
189
+ function renderChainSummary(diagnosis) {
190
+ return diagnosis.chain.map((l) => {
191
+ const mark = l.active ? "\u2192" : " ";
192
+ const target = l.role === "local" ? `${l.endpoint} \xB7 ${LOCAL_VECTOR_DIMENSION}-dim` : `${l.endpoint} \xB7 ${l.model}`;
193
+ const key = l.role === "local" || l.role === "disabled" ? "" : ` \xB7 key ${l.keyState}`;
194
+ return ` ${mark} ${l.order + 1}. ${l.label}: ${target}${key} [${l.source}]`;
195
+ });
196
+ }
197
+ function embeddingChainVerdict(diagnosis) {
198
+ if (diagnosis.disabled) return "disabled (BB_EMBEDDING_DISABLED) \u2014 local word vectors only";
199
+ if (diagnosis.remoteReady) return diagnosis.fallbackConfigured ? "remote ready (primary + fallback)" : "remote ready";
200
+ return "remote NOT usable \u2014 semantic search degrades to local word vectors";
201
+ }
202
+ var LOCAL_DIMENSION = LOCAL_VECTOR_DIMENSION;
203
+
204
+ // src/setup/setup-show.ts
205
+ function readJsonSafe(p) {
206
+ try {
207
+ if (!existsSync(p)) return null;
208
+ return JSON.parse(readFileSync(p, "utf8"));
209
+ } catch {
210
+ return null;
211
+ }
212
+ }
213
+ function fileMode(p) {
214
+ try {
215
+ return statSync(p).mode & 511;
216
+ } catch {
217
+ return void 0;
218
+ }
219
+ }
220
+ function completeTier(tier, baseURL, model, key, file, skippedMarker) {
221
+ const present = baseURL !== void 0 || model !== void 0 || key !== void 0 || skippedMarker === true;
222
+ const complete = typeof baseURL === "string" && baseURL.length > 0 && typeof model === "string" && model.length > 0;
223
+ const missing = [];
224
+ if (!baseURL) missing.push("base URL");
225
+ if (!model) missing.push("model");
226
+ return {
227
+ tier,
228
+ present,
229
+ complete,
230
+ baseURL: typeof baseURL === "string" ? baseURL : void 0,
231
+ model: typeof model === "string" ? model : void 0,
232
+ keyFingerprint: typeof key === "string" && key.length > 0 ? fingerprintKey(key) : void 0,
233
+ file,
234
+ fileMode: file ? fileMode(file) : void 0,
235
+ incompleteReason: present && !complete ? `missing: ${missing.join(" + ")}` : void 0
236
+ };
237
+ }
238
+ function describeEmbeddingConfig(cwd = process.cwd(), env = process.env, dataDir = bbDataDir()) {
239
+ const globalFile = path.join(dataDir, "config.json");
240
+ const global = readJsonSafe(globalFile);
241
+ const projectFile = path.join(cwd, "bb.json");
242
+ const project = readJsonSafe(projectFile);
243
+ const envTier = completeTier(
244
+ "env",
245
+ env.BB_EMBEDDING_BASE_URL,
246
+ env.BB_EMBEDDING_MODEL,
247
+ env.BB_EMBEDDING_API_KEY
248
+ );
249
+ const globalTier = completeTier(
250
+ "global",
251
+ global?.embedding_base_url,
252
+ global?.embedding_model,
253
+ global?.embedding_api_key,
254
+ globalFile,
255
+ global?.setup_skipped === true
256
+ );
257
+ if (global && global.setup_skipped === true) globalTier.skippedMarker = true;
258
+ const projectTier = completeTier(
259
+ "project",
260
+ project?.embedding_base_url,
261
+ project?.embedding_model,
262
+ project?.embedding_api_key,
263
+ projectFile
264
+ );
265
+ const tiers = [envTier, globalTier, projectTier];
266
+ const winningTier = tiers.find((t) => t.complete);
267
+ const state = {
268
+ winner: winningTier?.tier ?? "none",
269
+ configured: Boolean(winningTier),
270
+ tiers
271
+ };
272
+ state.diagnosis = buildEmbeddingDiagnosis({ state, env });
273
+ return state;
274
+ }
275
+ function renderSetupShow(state) {
276
+ const lines = [];
277
+ lines.push("bb \u2014 embedding configuration");
278
+ lines.push("Precedence: env > ~/.bb/config.json > bb.json");
279
+ lines.push("");
280
+ const tierLabel = { env: "env", global: "global", project: "project" };
281
+ for (const t of state.tiers) {
282
+ const label = tierLabel[t.tier].padEnd(7);
283
+ if (!t.present) {
284
+ lines.push(`${label}: \u2014 (not set)`);
285
+ continue;
286
+ }
287
+ if (!t.complete) {
288
+ const key2 = t.keyFingerprint ? ` (key: \u2022\u2022\u2022\u2022${t.keyFingerprint})` : "";
289
+ const skipped = t.skippedMarker ? " \xB7 wizard skipped" : "";
290
+ lines.push(`${label}: \u2717 ${t.incompleteReason ?? "incomplete"}${key2}${skipped}`);
291
+ continue;
292
+ }
293
+ const key = t.keyFingerprint ? `key: \u2022\u2022\u2022\u2022${t.keyFingerprint}` : "key: none";
294
+ let line = `${label}: \u2713 ${t.baseURL} \xB7 ${t.model} \xB7 ${key}`;
295
+ if (t.fileMode !== void 0 && t.fileMode !== 384) {
296
+ line += ` \xB7 mode: ${t.fileMode.toString(8)} (expected: 600 \u2014 fix with bb doctor)`;
297
+ } else if (t.fileMode !== void 0) {
298
+ line += ` \xB7 mode: 600`;
299
+ }
300
+ if (t.skippedMarker) line += " \xB7 wizard skipped";
301
+ lines.push(line);
302
+ }
303
+ lines.push("");
304
+ if (state.configured) {
305
+ const w = state.winner;
306
+ lines.push(`Winner: ${tierLabel[w]}`);
307
+ } else {
308
+ lines.push("Winner: none \u2014 semantic search will use local vectors (weaker). Setup: bb setup");
309
+ }
310
+ const diagnosis = state.diagnosis;
311
+ if (diagnosis) {
312
+ lines.push("");
313
+ lines.push(`Chain: ${embeddingChainVerdict(diagnosis)}`);
314
+ for (const line of renderChainSummary(diagnosis)) lines.push(line);
315
+ const problems = diagnosis.problems.filter((p) => !/^No embedding provider is configured/.test(p.message));
316
+ for (const p of problems) {
317
+ const varName = p.envVar ? `${p.envVar}: ` : "";
318
+ lines.push(` ! ${varName}${p.message}`);
319
+ }
320
+ for (const f of diagnosis.observedFailures) {
321
+ lines.push(` \u2717 ${f.status} ${f.kind} from ${f.baseURL} \u2014 ${f.advice}`);
322
+ }
323
+ if (diagnosis.tierOrderDisagreement) {
324
+ lines.push(` ! ${diagnosis.tierOrderDisagreement.detail}`);
325
+ }
326
+ }
327
+ return lines.join("\n") + "\n";
328
+ }
329
+
330
+ export {
331
+ buildEmbeddingDiagnosis,
332
+ renderChainSummary,
333
+ embedding_diagnosis_exports,
334
+ describeEmbeddingConfig,
335
+ renderSetupShow
336
+ };
@@ -0,0 +1,125 @@
1
+ // src/ast/types.ts
2
+ var RelationshipType = /* @__PURE__ */ ((RelationshipType2) => {
3
+ RelationshipType2["Calls"] = "calls";
4
+ RelationshipType2["Extends"] = "extends";
5
+ RelationshipType2["Implements"] = "implements";
6
+ RelationshipType2["Uses"] = "uses";
7
+ RelationshipType2["Imports"] = "imports";
8
+ RelationshipType2["Exports"] = "exports";
9
+ RelationshipType2["Contains"] = "contains";
10
+ RelationshipType2["References"] = "references";
11
+ RelationshipType2["Overrides"] = "overrides";
12
+ RelationshipType2["Instantiates"] = "instantiates";
13
+ RelationshipType2["Decorates"] = "decorates";
14
+ RelationshipType2["Renders"] = "renders";
15
+ RelationshipType2["MixesIn"] = "mixes_in";
16
+ RelationshipType2["PartOf"] = "part_of";
17
+ RelationshipType2["Call"] = "calls";
18
+ RelationshipType2["Inheritance"] = "extends";
19
+ RelationshipType2["Implementation"] = "implements";
20
+ RelationshipType2["Dependency"] = "uses";
21
+ RelationshipType2["Override"] = "overrides";
22
+ RelationshipType2["Composition"] = "contains";
23
+ RelationshipType2["Provides"] = "exports";
24
+ RelationshipType2["Related"] = "references";
25
+ return RelationshipType2;
26
+ })(RelationshipType || {});
27
+ var BINDING_SEP = "\0";
28
+
29
+ // src/util/source-text.ts
30
+ var BOMS = [
31
+ { bytes: [0, 0, 254, 255], encoding: "utf32be", bomLength: 4 },
32
+ { bytes: [255, 254, 0, 0], encoding: "utf32le", bomLength: 4 },
33
+ { bytes: [239, 187, 191], encoding: "utf8-bom", bomLength: 3 },
34
+ { bytes: [254, 255], encoding: "utf16be", bomLength: 2 },
35
+ { bytes: [255, 254], encoding: "utf16le", bomLength: 2 }
36
+ ];
37
+ function decodeUtf32le(buf) {
38
+ const groups = Math.floor(buf.length / 4);
39
+ if (groups === 0) return "";
40
+ const units = new Array(groups * 2);
41
+ let n = 0;
42
+ for (let i = 0; i < groups; i++) {
43
+ const o = i * 4;
44
+ const cp = (buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16 | buf[o + 3] << 24) >>> 0;
45
+ if (cp > 65535) {
46
+ const v = cp - 65536;
47
+ units[n++] = 55296 + (v >> 10);
48
+ units[n++] = 56320 + (v & 1023);
49
+ } else {
50
+ units[n++] = cp;
51
+ }
52
+ }
53
+ let out = "";
54
+ const CHUNK = 4096;
55
+ for (let i = 0; i < n; i += CHUNK) {
56
+ out += String.fromCharCode(...units.slice(i, Math.min(i + CHUNK, n)));
57
+ }
58
+ return out;
59
+ }
60
+ function swapGroups(buf, width) {
61
+ const out = Buffer.from(buf);
62
+ for (let i = 0; i + width <= out.length; i += width) {
63
+ for (let a = 0, b = width - 1; a < b; a++, b--) {
64
+ const t = out[i + a];
65
+ out[i + a] = out[i + b];
66
+ out[i + b] = t;
67
+ }
68
+ }
69
+ return out;
70
+ }
71
+ function startsWith(buf, bytes) {
72
+ if (buf.length < bytes.length) return false;
73
+ for (let i = 0; i < bytes.length; i++) if (buf[i] !== bytes[i]) return false;
74
+ return true;
75
+ }
76
+ function sniffUtf16(buf) {
77
+ const limit = Math.min(buf.length, 512);
78
+ if (limit < 4) return null;
79
+ let evenNuls = 0;
80
+ let oddNuls = 0;
81
+ let pairs = 0;
82
+ for (let i = 0; i + 1 < limit; i += 2) {
83
+ pairs++;
84
+ if (buf[i] === 0) evenNuls++;
85
+ if (buf[i + 1] === 0) oddNuls++;
86
+ }
87
+ if (pairs === 0) return null;
88
+ if (oddNuls / pairs > 0.7 && evenNuls / pairs < 0.1) return "utf16le";
89
+ if (evenNuls / pairs > 0.7 && oddNuls / pairs < 0.1) return "utf16be";
90
+ return null;
91
+ }
92
+ function decodeSourceText(buf) {
93
+ for (const bom of BOMS) {
94
+ if (!startsWith(buf, bom.bytes)) continue;
95
+ const body = buf.subarray(bom.bomLength);
96
+ switch (bom.encoding) {
97
+ case "utf8-bom":
98
+ return { text: body.toString("utf8"), encoding: "utf8-bom", hadBom: true, inferred: false };
99
+ case "utf16be":
100
+ return { text: swapGroups(body, 2).toString("utf16le"), encoding: "utf16be", hadBom: true, inferred: false };
101
+ case "utf32be":
102
+ return { text: decodeUtf32le(swapGroups(body, 4)), encoding: "utf32be", hadBom: true, inferred: false };
103
+ case "utf32le":
104
+ return { text: decodeUtf32le(body), encoding: "utf32le", hadBom: true, inferred: false };
105
+ default:
106
+ return { text: body.toString("utf16le"), encoding: "utf16le", hadBom: true, inferred: false };
107
+ }
108
+ }
109
+ const sniffed = sniffUtf16(buf);
110
+ if (sniffed) {
111
+ return {
112
+ text: sniffed === "utf16le" ? buf.toString("utf16le") : swapGroups(buf, 2).toString("utf16le"),
113
+ encoding: sniffed,
114
+ hadBom: false,
115
+ inferred: true
116
+ };
117
+ }
118
+ return { text: buf.toString("utf8"), encoding: "utf8", hadBom: false, inferred: false };
119
+ }
120
+
121
+ export {
122
+ RelationshipType,
123
+ BINDING_SEP,
124
+ decodeSourceText
125
+ };