pi-mega-compact 0.11.4 → 0.11.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 (381) hide show
  1. package/dist/extensions/dashboard-server/api-contracts/cache-stripes.js +8 -0
  2. package/dist/extensions/dashboard-server/api-contracts/endpoints.js +32 -0
  3. package/dist/extensions/dashboard-server/api-contracts/memory-map.js +1 -0
  4. package/dist/extensions/dashboard-server/api-contracts/memory.js +8 -0
  5. package/dist/extensions/dashboard-server/api-contracts/provider-cache.js +1 -0
  6. package/dist/extensions/dashboard-server/api-contracts/setup.js +10 -0
  7. package/dist/extensions/dashboard-server/index-reader.js +6 -2
  8. package/dist/extensions/dashboard-server/routes-cache.js +135 -47
  9. package/dist/extensions/dashboard-server/routes-game.js +3 -0
  10. package/dist/extensions/dashboard-server/routes-memory-map.js +50 -0
  11. package/dist/extensions/dashboard-server/routes-memory.js +51 -0
  12. package/dist/extensions/dashboard-server/routes-repo.js +2 -2
  13. package/dist/extensions/dashboard-server/routes-setup.js +267 -0
  14. package/dist/extensions/dashboard-server/routes.js +4 -0
  15. package/dist/extensions/dashboard-server/server.js +13 -1
  16. package/dist/extensions/mega-commands.js +189 -1
  17. package/dist/extensions/mega-compact.js +5 -0
  18. package/dist/extensions/mega-config.js +7 -0
  19. package/dist/extensions/mega-events/agent-handlers.js +19 -4
  20. package/dist/extensions/mega-events/compact-handlers.js +1 -0
  21. package/dist/extensions/mega-events/context-handler.js +45 -92
  22. package/dist/extensions/mega-events/context-hwm.js +51 -0
  23. package/dist/extensions/mega-events/error-classifier.js +16 -5
  24. package/dist/extensions/mega-events/mirror-append.js +107 -0
  25. package/dist/extensions/mega-events/outage-advisor.js +7 -1
  26. package/dist/extensions/mega-events/perf-handler.js +134 -2
  27. package/dist/extensions/mega-events/recall-tail.js +59 -0
  28. package/dist/extensions/mega-events/separated-prompt.js +248 -0
  29. package/dist/extensions/mega-events/session-handlers.js +15 -8
  30. package/dist/extensions/mega-runtime/env-loader.js +56 -0
  31. package/dist/extensions/mega-runtime/reset-runtime.js +6 -0
  32. package/dist/extensions/mega-runtime/runtime-snapshot.js +1 -0
  33. package/dist/extensions/mega-runtime/runtime.js +7 -0
  34. package/dist/extensions/mega-runtime/snapshot.js +1 -0
  35. package/dist/extensions/mega-runtime/widget.js +5 -0
  36. package/dist/src/cache-stripe-impl.js +288 -0
  37. package/dist/src/cache-stripe.js +11 -0
  38. package/dist/src/config/stopwords.js +24 -0
  39. package/dist/src/config.js +17 -0
  40. package/dist/src/embedder.js +41 -2
  41. package/dist/src/memoryGraph.js +299 -0
  42. package/dist/src/memoryStats.js +75 -0
  43. package/dist/src/monitoring.js +13 -0
  44. package/dist/src/prefix-break.js +43 -0
  45. package/dist/src/pricing.js +1 -1
  46. package/dist/src/queryExpansion.js +163 -0
  47. package/dist/src/queryReformulation/cache.js +123 -0
  48. package/dist/src/queryReformulation/rrf.js +29 -0
  49. package/dist/src/queryReformulation/tfidf.js +61 -0
  50. package/dist/src/queryReformulation/vagueness.js +33 -0
  51. package/dist/src/queryReformulation.js +225 -0
  52. package/dist/src/recallMetrics.js +258 -0
  53. package/dist/src/store/sqlite/cache-stripes.js +133 -0
  54. package/dist/src/store/sqlite/fts5-search.js +68 -0
  55. package/dist/src/store/sqlite/perf-samples.js +145 -16
  56. package/dist/src/store/sqlite/schema.js +60 -1
  57. package/dist/src/store/sqlite.js +1 -0
  58. package/dist/src/store/turns/memory-store.js +8 -0
  59. package/dist/src/store/turns/sqlite-store.js +14 -3
  60. package/dist/src/store/turns/types.js +18 -1
  61. package/dist/src/store/vectorIndex.js +55 -10
  62. package/dist/src/tiered-router/types.js +18 -0
  63. package/dist/src/tieredRouter.js +421 -0
  64. package/dist/src/vectorStore.js +8 -6
  65. package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js → AchievementTiles-DR9cLGDL.js} +2 -2
  66. package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js.map → AchievementTiles-DR9cLGDL.js.map} +1 -1
  67. package/extensions/dashboard-client/dist/assets/AchievementsTab-svNUgJ1e.js +2 -0
  68. package/extensions/dashboard-client/dist/assets/{AchievementsTab-DjxfYrDc.js.map → AchievementsTab-svNUgJ1e.js.map} +1 -1
  69. package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js +2 -0
  70. package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js.map +1 -0
  71. package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js → ConfigTab-CmmWheuW.js} +2 -2
  72. package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js.map → ConfigTab-CmmWheuW.js.map} +1 -1
  73. package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js → EventsTab-CFE7jLsa.js} +2 -2
  74. package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js.map → EventsTab-CFE7jLsa.js.map} +1 -1
  75. package/extensions/dashboard-client/dist/assets/GameTab-CJAX_th_.js +2 -0
  76. package/extensions/dashboard-client/dist/assets/{GameTab-BLDudcO5.js.map → GameTab-CJAX_th_.js.map} +1 -1
  77. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js → MaintenanceTab-P4SUsvMf.js} +2 -2
  78. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js.map → MaintenanceTab-P4SUsvMf.js.map} +1 -1
  79. package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js +2 -0
  80. package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js.map +1 -0
  81. package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js → MetricsTab-CHQscixy.js} +2 -2
  82. package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js.map → MetricsTab-CHQscixy.js.map} +1 -1
  83. package/extensions/dashboard-client/dist/assets/OverviewTab-DBs4DJdd.js +2 -0
  84. package/extensions/dashboard-client/dist/assets/{OverviewTab-D4kGvsiQ.js.map → OverviewTab-DBs4DJdd.js.map} +1 -1
  85. package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js +2 -0
  86. package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js.map +1 -0
  87. package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js → SessionsTab-BWNsj1OB.js} +2 -2
  88. package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js.map → SessionsTab-BWNsj1OB.js.map} +1 -1
  89. package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js +2 -0
  90. package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js.map +1 -0
  91. package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js +2 -0
  92. package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js.map +1 -0
  93. package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js → TopicsTab-BWWQxltv.js} +2 -2
  94. package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js.map → TopicsTab-BWWQxltv.js.map} +1 -1
  95. package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js → TurnsTab-CVz4f4-o.js} +2 -2
  96. package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js.map → TurnsTab-CVz4f4-o.js.map} +1 -1
  97. package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js +2 -0
  98. package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js.map +1 -0
  99. package/extensions/dashboard-client/dist/assets/index-CUNn22iV.css +1 -0
  100. package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js +42 -0
  101. package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js.map +1 -0
  102. package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js +2 -0
  103. package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js.map +1 -0
  104. package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js → useSSE-Bf5LOLSi.js} +2 -2
  105. package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js.map → useSSE-Bf5LOLSi.js.map} +1 -1
  106. package/extensions/dashboard-client/dist/index.html +2 -2
  107. package/extensions/dashboard-client/src/App.tsx +28 -8
  108. package/extensions/dashboard-client/src/api/client.ts +29 -0
  109. package/extensions/dashboard-client/src/components/ActiveReposTable.tsx +21 -12
  110. package/extensions/dashboard-client/src/components/CacheHitRateTrendCard.tsx +100 -0
  111. package/extensions/dashboard-client/src/components/ProviderCacheCard.tsx +56 -0
  112. package/extensions/dashboard-client/src/components/SavingsByModelTable.tsx +38 -57
  113. package/extensions/dashboard-client/src/components/StripeDistributionCard.tsx +110 -0
  114. package/extensions/dashboard-client/src/components/TabBar.tsx +49 -4
  115. package/extensions/dashboard-client/src/main.tsx +1 -0
  116. package/extensions/dashboard-client/src/styles/base.css +30 -0
  117. package/extensions/dashboard-client/src/styles/cache.css +167 -0
  118. package/extensions/dashboard-client/src/tabs/CacheTab.tsx +75 -12
  119. package/extensions/dashboard-client/src/tabs/MemoryMapTab.tsx +440 -0
  120. package/extensions/dashboard-client/src/tabs/SetupTab.tsx +418 -0
  121. package/extensions/dashboard-client/tsconfig.json +3 -2
  122. package/extensions/dashboard-client/vite.config.ts +2 -0
  123. package/extensions/dashboard-server/api-contracts/cache-stripes.ts +49 -0
  124. package/extensions/dashboard-server/api-contracts/endpoints.ts +66 -3
  125. package/extensions/dashboard-server/api-contracts/index.ts +22 -0
  126. package/extensions/dashboard-server/api-contracts/memory-map.ts +50 -0
  127. package/extensions/dashboard-server/api-contracts/memory.ts +27 -0
  128. package/extensions/dashboard-server/api-contracts/multi-repo.ts +231 -231
  129. package/extensions/dashboard-server/api-contracts/provider-cache.ts +37 -0
  130. package/extensions/dashboard-server/api-contracts/setup.ts +80 -0
  131. package/extensions/dashboard-server/index-reader.ts +138 -121
  132. package/extensions/dashboard-server/routes-cache.ts +186 -75
  133. package/extensions/dashboard-server/routes-game.ts +3 -0
  134. package/extensions/dashboard-server/routes-memory-map.ts +105 -0
  135. package/extensions/dashboard-server/routes-memory.ts +63 -0
  136. package/extensions/dashboard-server/routes-repo.ts +36 -36
  137. package/extensions/dashboard-server/routes-setup.ts +293 -0
  138. package/extensions/dashboard-server/routes.ts +4 -0
  139. package/extensions/dashboard-server/server.ts +12 -0
  140. package/extensions/mega-commands.ts +211 -1
  141. package/extensions/mega-compact.ts +5 -0
  142. package/extensions/mega-config.ts +27 -0
  143. package/extensions/mega-events/agent-handlers.ts +20 -4
  144. package/extensions/mega-events/compact-handlers.ts +1 -0
  145. package/extensions/mega-events/context-handler.ts +53 -110
  146. package/extensions/mega-events/context-hwm.ts +85 -0
  147. package/extensions/mega-events/error-classifier.ts +15 -4
  148. package/extensions/mega-events/mirror-append.ts +155 -0
  149. package/extensions/mega-events/outage-advisor.ts +11 -5
  150. package/extensions/mega-events/perf-handler.ts +190 -6
  151. package/extensions/mega-events/recall-tail.ts +88 -0
  152. package/extensions/mega-events/separated-prompt.ts +329 -0
  153. package/extensions/mega-events/session-handlers.ts +14 -7
  154. package/extensions/mega-runtime/env-loader.ts +55 -0
  155. package/extensions/mega-runtime/helpers.ts +14 -0
  156. package/extensions/mega-runtime/reset-runtime.ts +6 -0
  157. package/extensions/mega-runtime/runtime-snapshot.ts +1 -0
  158. package/extensions/mega-runtime/runtime.ts +7 -0
  159. package/extensions/mega-runtime/snapshot.ts +6 -0
  160. package/extensions/mega-runtime/widget-types.ts +3 -0
  161. package/extensions/mega-runtime/widget.ts +5 -0
  162. package/package.json +5 -2
  163. package/src/cache-stripe-impl.ts +385 -0
  164. package/src/cache-stripe.ts +18 -0
  165. package/src/config/stopwords.ts +25 -0
  166. package/src/config.ts +26 -0
  167. package/src/embedder.ts +42 -2
  168. package/src/memoryGraph.ts +438 -0
  169. package/src/memoryStats.ts +107 -0
  170. package/src/monitoring.ts +35 -0
  171. package/src/prefix-break.ts +83 -0
  172. package/src/pricing.ts +2 -2
  173. package/src/queryExpansion.ts +206 -0
  174. package/src/queryReformulation/cache.ts +169 -0
  175. package/src/queryReformulation/rrf.ts +51 -0
  176. package/src/queryReformulation/tfidf.ts +79 -0
  177. package/src/queryReformulation/vagueness.ts +38 -0
  178. package/src/queryReformulation.ts +355 -0
  179. package/src/recallMetrics.ts +388 -0
  180. package/src/store/sqlite/cache-stripes.ts +196 -0
  181. package/src/store/sqlite/fts5-search.ts +90 -0
  182. package/src/store/sqlite/perf-samples.ts +218 -23
  183. package/src/store/sqlite/schema.ts +60 -1
  184. package/src/store/sqlite.ts +1 -0
  185. package/src/store/turns/memory-store.ts +10 -1
  186. package/src/store/turns/sqlite-store.ts +27 -15
  187. package/src/store/turns/types.ts +21 -0
  188. package/src/store/vectorIndex.ts +71 -11
  189. package/src/tiered-router/types.ts +64 -0
  190. package/src/tieredRouter.ts +489 -0
  191. package/src/vectorStore.ts +9 -5
  192. package/dist/extensions/conflict-scan.test.js +0 -115
  193. package/dist/extensions/dashboard-server/api-contracts.test.js +0 -884
  194. package/dist/extensions/dashboard-server/html.test.js +0 -52
  195. package/dist/extensions/dashboard-server/perf-server.test.js +0 -80
  196. package/dist/extensions/dashboard-server/routes-cache.test.js +0 -248
  197. package/dist/extensions/dashboard-server/server.test.js +0 -120
  198. package/dist/extensions/dashboard-server-s32.test.js +0 -181
  199. package/dist/extensions/dashboard-server.test.js +0 -339
  200. package/dist/extensions/mega-cache-replay.test.js +0 -400
  201. package/dist/extensions/mega-compact-s38.test.js +0 -1383
  202. package/dist/extensions/mega-compact.test.js +0 -1112
  203. package/dist/extensions/mega-events.test.js +0 -47
  204. package/dist/extensions/mega-game-cmds.test.js +0 -163
  205. package/dist/extensions/mega-runtime/snapshot.test.js +0 -127
  206. package/dist/extensions/mega-runtime/state.test.js +0 -266
  207. package/dist/extensions/mega-runtime/widget.test.js +0 -343
  208. package/dist/extensions/mega-shutdown-widget.test.js +0 -121
  209. package/dist/extensions/mega-teamrun.test.js +0 -156
  210. package/dist/extensions/mega-trim.test.js +0 -58
  211. package/dist/extensions/mega-turn-store.test.js +0 -68
  212. package/dist/src/boundary.test.js +0 -170
  213. package/dist/src/compact.test.js +0 -78
  214. package/dist/src/config/themes.test.js +0 -94
  215. package/dist/src/dedup/dedup.test.js +0 -41
  216. package/dist/src/dedup/l1.test.js +0 -50
  217. package/dist/src/dedup/raptor/buildHistory.test.js +0 -292
  218. package/dist/src/dedup/raptor/multilevel-serve.test.js +0 -229
  219. package/dist/src/dedup/raptor/multilevel.test.js +0 -238
  220. package/dist/src/dedup/raptor/promote.test.js +0 -69
  221. package/dist/src/dedup/raptor/raptor.test.js +0 -248
  222. package/dist/src/dedup/raptor/retrieval.test.js +0 -95
  223. package/dist/src/dedup/raptor/serve-gate.test.js +0 -298
  224. package/dist/src/dedup/sprint12.test.js +0 -219
  225. package/dist/src/dedup-engine.test.js +0 -472
  226. package/dist/src/driftDetection.test.js +0 -87
  227. package/dist/src/e2e.test.js +0 -698
  228. package/dist/src/engine.test.js +0 -111
  229. package/dist/src/extractive.test.js +0 -147
  230. package/dist/src/fork.test.js +0 -81
  231. package/dist/src/game/scoring.test.js +0 -98
  232. package/dist/src/httpEmbedder.test.js +0 -277
  233. package/dist/src/importance.test.js +0 -372
  234. package/dist/src/intent.test.js +0 -78
  235. package/dist/src/log.test.js +0 -42
  236. package/dist/src/mechanical-fix.test.js +0 -65
  237. package/dist/src/memory.test.js +0 -70
  238. package/dist/src/memoryConsolidate.test.js +0 -38
  239. package/dist/src/memoryOps.test.js +0 -129
  240. package/dist/src/memoryRecall.test.js +0 -171
  241. package/dist/src/memoryRoundtrip.test.js +0 -137
  242. package/dist/src/metrics/turns.test.js +0 -152
  243. package/dist/src/mirror/mirror.test.js +0 -185
  244. package/dist/src/raptor-inject-summaries.test.js +0 -162
  245. package/dist/src/ratio.bench.test.js +0 -897
  246. package/dist/src/recall.integration.test.js +0 -77
  247. package/dist/src/recall.test.js +0 -379
  248. package/dist/src/sprint14.test.js +0 -219
  249. package/dist/src/sprint4x-rag-verification.test.js +0 -93
  250. package/dist/src/store/compression.test.js +0 -139
  251. package/dist/src/store/memoryIndex.test.js +0 -51
  252. package/dist/src/store/migrate.test.js +0 -139
  253. package/dist/src/store/pgOpenGuard.test.js +0 -74
  254. package/dist/src/store/phase01.test.js +0 -81
  255. package/dist/src/store/phase04.test.js +0 -54
  256. package/dist/src/store/sprint10.test.js +0 -186
  257. package/dist/src/store/sqlite/game-achievements.test.js +0 -67
  258. package/dist/src/store/sqlite/game-scores.test.js +0 -106
  259. package/dist/src/store/sqlite/game-state.test.js +0 -76
  260. package/dist/src/store/sqlite/global-index.test.js +0 -136
  261. package/dist/src/store/sqlite/mechanical-fix.test.js +0 -146
  262. package/dist/src/store/sqlite/perf-samples.test.js +0 -146
  263. package/dist/src/store/sqlite/raptor.test.js +0 -106
  264. package/dist/src/store/sqlite/turns.test.js +0 -183
  265. package/dist/src/store/sqlite.cachehit.test.js +0 -55
  266. package/dist/src/store/sqlite.dbmaint.test.js +0 -158
  267. package/dist/src/store/sqlite.dbmirror.test.js +0 -184
  268. package/dist/src/store/turns/contract-compliance.test.js +0 -428
  269. package/dist/src/store/turns/memory-store.test.js +0 -9
  270. package/dist/src/store/turns/migrations.test.js +0 -138
  271. package/dist/src/store/turns/sqlite-store.test.js +0 -144
  272. package/dist/src/store/vectorIndex.test.js +0 -123
  273. package/dist/src/store.test.js +0 -161
  274. package/dist/src/supersede.test.js +0 -36
  275. package/dist/src/topics/cluster.test.js +0 -150
  276. package/dist/src/topics/store.test.js +0 -117
  277. package/dist/src/types.test.js +0 -9
  278. package/dist/src/vector-search-cache.test.js +0 -157
  279. package/dist/src/vectorStore.test.js +0 -479
  280. package/dist/src/wiki.test.js +0 -171
  281. package/extensions/conflict-scan.test.ts +0 -129
  282. package/extensions/dashboard-client/dist/assets/AchievementsTab-DjxfYrDc.js +0 -2
  283. package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js +0 -2
  284. package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js.map +0 -1
  285. package/extensions/dashboard-client/dist/assets/GameTab-BLDudcO5.js +0 -2
  286. package/extensions/dashboard-client/dist/assets/OverviewTab-D4kGvsiQ.js +0 -2
  287. package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js +0 -2
  288. package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js.map +0 -1
  289. package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js +0 -2
  290. package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js.map +0 -1
  291. package/extensions/dashboard-client/dist/assets/index-BEdKlpAB.css +0 -1
  292. package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js +0 -42
  293. package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js.map +0 -1
  294. package/extensions/dashboard-server/api-contracts.test.ts +0 -1065
  295. package/extensions/dashboard-server/html.test.ts +0 -62
  296. package/extensions/dashboard-server/perf-server.test.ts +0 -101
  297. package/extensions/dashboard-server/routes-cache.test.ts +0 -302
  298. package/extensions/dashboard-server/server.test.ts +0 -131
  299. package/extensions/dashboard-server-s32.test.ts +0 -195
  300. package/extensions/dashboard-server.test.ts +0 -382
  301. package/extensions/mega-cache-replay.test.ts +0 -526
  302. package/extensions/mega-compact-s38.test.ts +0 -1433
  303. package/extensions/mega-compact.test.ts +0 -1509
  304. package/extensions/mega-events.test.ts +0 -55
  305. package/extensions/mega-game-cmds.test.ts +0 -197
  306. package/extensions/mega-runtime/snapshot.test.ts +0 -139
  307. package/extensions/mega-runtime/state.test.ts +0 -262
  308. package/extensions/mega-runtime/widget.test.ts +0 -468
  309. package/extensions/mega-shutdown-widget.test.ts +0 -141
  310. package/extensions/mega-teamrun.test.ts +0 -176
  311. package/extensions/mega-trim.test.ts +0 -64
  312. package/extensions/mega-turn-store.test.ts +0 -108
  313. package/src/boundary.test.ts +0 -187
  314. package/src/compact.test.ts +0 -99
  315. package/src/config/themes.test.ts +0 -116
  316. package/src/dedup/dedup.test.ts +0 -46
  317. package/src/dedup/l1.test.ts +0 -57
  318. package/src/dedup/raptor/buildHistory.test.ts +0 -353
  319. package/src/dedup/raptor/multilevel-serve.test.ts +0 -273
  320. package/src/dedup/raptor/multilevel.test.ts +0 -325
  321. package/src/dedup/raptor/promote.test.ts +0 -82
  322. package/src/dedup/raptor/raptor.test.ts +0 -297
  323. package/src/dedup/raptor/retrieval.test.ts +0 -118
  324. package/src/dedup/raptor/serve-gate.test.ts +0 -348
  325. package/src/dedup/sprint12.test.ts +0 -242
  326. package/src/dedup-engine.test.ts +0 -670
  327. package/src/driftDetection.test.ts +0 -100
  328. package/src/e2e.test.ts +0 -843
  329. package/src/engine.test.ts +0 -123
  330. package/src/extractive.test.ts +0 -174
  331. package/src/fork.test.ts +0 -94
  332. package/src/game/scoring.test.ts +0 -103
  333. package/src/httpEmbedder.test.ts +0 -286
  334. package/src/importance.test.ts +0 -538
  335. package/src/intent.test.ts +0 -87
  336. package/src/log.test.ts +0 -47
  337. package/src/mechanical-fix.test.ts +0 -70
  338. package/src/memory.test.ts +0 -92
  339. package/src/memoryConsolidate.test.ts +0 -47
  340. package/src/memoryOps.test.ts +0 -148
  341. package/src/memoryRecall.test.ts +0 -194
  342. package/src/memoryRoundtrip.test.ts +0 -155
  343. package/src/metrics/turns.test.ts +0 -165
  344. package/src/mirror/mirror.test.ts +0 -240
  345. package/src/raptor-inject-summaries.test.ts +0 -228
  346. package/src/ratio.bench.test.ts +0 -1316
  347. package/src/recall.integration.test.ts +0 -96
  348. package/src/recall.test.ts +0 -467
  349. package/src/sprint14.test.ts +0 -245
  350. package/src/sprint4x-rag-verification.test.ts +0 -119
  351. package/src/store/compression.test.ts +0 -168
  352. package/src/store/memoryIndex.test.ts +0 -61
  353. package/src/store/migrate.test.ts +0 -158
  354. package/src/store/pgOpenGuard.test.ts +0 -89
  355. package/src/store/phase01.test.ts +0 -88
  356. package/src/store/phase04.test.ts +0 -58
  357. package/src/store/sprint10.test.ts +0 -214
  358. package/src/store/sqlite/game-achievements.test.ts +0 -80
  359. package/src/store/sqlite/game-scores.test.ts +0 -132
  360. package/src/store/sqlite/game-state.test.ts +0 -89
  361. package/src/store/sqlite/global-index.test.ts +0 -222
  362. package/src/store/sqlite/mechanical-fix.test.ts +0 -162
  363. package/src/store/sqlite/perf-samples.test.ts +0 -169
  364. package/src/store/sqlite/raptor.test.ts +0 -139
  365. package/src/store/sqlite/turns.test.ts +0 -218
  366. package/src/store/sqlite.cachehit.test.ts +0 -68
  367. package/src/store/sqlite.dbmaint.test.ts +0 -193
  368. package/src/store/sqlite.dbmirror.test.ts +0 -229
  369. package/src/store/turns/contract-compliance.test.ts +0 -562
  370. package/src/store/turns/memory-store.test.ts +0 -15
  371. package/src/store/turns/migrations.test.ts +0 -161
  372. package/src/store/turns/sqlite-store.test.ts +0 -161
  373. package/src/store/vectorIndex.test.ts +0 -140
  374. package/src/store.test.ts +0 -191
  375. package/src/supersede.test.ts +0 -42
  376. package/src/topics/cluster.test.ts +0 -176
  377. package/src/topics/store.test.ts +0 -132
  378. package/src/types.test.ts +0 -10
  379. package/src/vector-search-cache.test.ts +0 -190
  380. package/src/vectorStore.test.ts +0 -533
  381. package/src/wiki.test.ts +0 -217
@@ -0,0 +1,288 @@
1
+ /**
2
+ * cache-stripe-impl.ts — Vector-Aware Cache Striping implementation.
3
+ *
4
+ * Computes a stability score for each context chunk and assigns it to a
5
+ * cache stripe / prompt-cache layer. Stable chunks (high recency + frequency +
6
+ * semantic density) go to early layers (cached prefix); volatile chunks append
7
+ * at Layer 4 (tail). Runs entirely offline — no network, no LLM (PREVENT-PI-004).
8
+ *
9
+ * The stability score is a weighted composite:
10
+ * stability = 0.5 * semanticSimilarity + 0.3 * recency + 0.2 * frequency
11
+ *
12
+ * - semanticSimilarity: cosine similarity of the chunk's embedding against the
13
+ * running session embedding (from TrigramEmbedder). High similarity means the
14
+ * chunk is topically relevant to current work.
15
+ * - recency: how recently the chunk appeared (normalized to 0.0-1.0 across all
16
+ * chunks in the epoch). Recent chunks are more likely to benefit from caching.
17
+ * - frequency: how often the chunk's content has been referenced (0.0-1.0,
18
+ * estimated from a simple access counter stored alongside).
19
+ *
20
+ * Reassignment happens at epoch boundaries via refreshStripeAssignments.
21
+ * All SQL is parameterized (PREVENT-002). No pi runtime types are imported,
22
+ * keeping this module pi-agnostic.
23
+ */
24
+ import { randomBytes } from "node:crypto";
25
+ import { openStore, withTx } from "./store/sqlite/utils.js";
26
+ // ─── Constants ───────────────────────────────────────────────────────────────
27
+ /** Semantic similarity weight in the composite score. */
28
+ const WEIGHT_SEMANTIC = 0.5;
29
+ /** Recency weight in the composite score. */
30
+ const WEIGHT_RECENCY = 0.3;
31
+ /** Frequency weight in the composite score. */
32
+ const WEIGHT_FREQUENCY = 0.2;
33
+ /** Stripes a chunk lands in based on its stability score. Thresholds define
34
+ * the boundary between adjacent layers. */
35
+ const STRIPE_THRESHOLDS = [
36
+ { minStability: 0.90, stripe: 0 },
37
+ { minStability: 0.70, stripe: 1 },
38
+ { minStability: 0.50, stripe: 2 },
39
+ { minStability: 0.30, stripe: 3 },
40
+ { minStability: -Infinity, stripe: 4 },
41
+ ];
42
+ // ─── Embedding helpers (no external dep) ─────────────────────────────────────
43
+ /**
44
+ * FNV-1a 32-bit hash for the content-based embedding fallback. The production
45
+ * path uses TrigramEmbedder from embedder.ts but we keep a self-contained hash
46
+ * for the case where no embedder is passed in.
47
+ */
48
+ function fnv1a(text) {
49
+ let hash = 0x811c9dc5;
50
+ for (let i = 0; i < text.length; i++) {
51
+ hash ^= text.charCodeAt(i);
52
+ hash = Math.imul(hash, 0x01000193);
53
+ }
54
+ return (hash >>> 0) / 0x100000000;
55
+ }
56
+ /**
57
+ * Produce a crude 128-dim pseudorandom embedding from text using hashed n-gram
58
+ * bins. Matches the approach in TrigramEmbedder._embedRaw conceptually. Used
59
+ * only as a fallback / test path; the caller should prefer TrigramEmbedder.
60
+ */
61
+ function fallbackEmbed(text) {
62
+ const dim = 128;
63
+ const vec = new Array(dim).fill(0);
64
+ const norm = text.toLowerCase().replace(/\s+/g, " ");
65
+ if (norm.length === 0)
66
+ return vec;
67
+ vec[Math.floor(fnv1a(norm) * dim)] += 1;
68
+ for (const word of norm.split(" ")) {
69
+ if (word.length === 0)
70
+ continue;
71
+ vec[Math.floor(fnv1a(word) * dim)] += 0.5;
72
+ for (let i = 0; i < Math.max(1, word.length - 1); i++) {
73
+ const trigram = word.slice(i, i + 3);
74
+ if (trigram.length === 3) {
75
+ vec[Math.floor(fnv1a(trigram) * dim)] += 0.25;
76
+ }
77
+ }
78
+ }
79
+ return l2Normalize(vec);
80
+ }
81
+ function l2Normalize(v) {
82
+ let sumSq = 0;
83
+ for (let i = 0; i < v.length; i++)
84
+ sumSq += v[i] * v[i];
85
+ if (sumSq === 0)
86
+ return v;
87
+ const norm = Math.sqrt(sumSq);
88
+ for (let i = 0; i < v.length; i++)
89
+ v[i] /= norm;
90
+ return v;
91
+ }
92
+ /** Compute cosine similarity between two vectors of equal length. */
93
+ function cosineSimilarity(a, b) {
94
+ if (a.length !== b.length || a.length === 0)
95
+ return 0;
96
+ let dot = 0;
97
+ let na = 0;
98
+ let nb = 0;
99
+ for (let i = 0; i < a.length; i++) {
100
+ dot += a[i] * b[i];
101
+ na += a[i] * a[i];
102
+ nb += b[i] * b[i];
103
+ }
104
+ const denom = Math.sqrt(na) * Math.sqrt(nb);
105
+ return denom === 0 ? 0 : dot / denom;
106
+ }
107
+ // ─── Stability Scoring ───────────────────────────────────────────────────────
108
+ /**
109
+ * Compute a composite stability score for a single chunk.
110
+ *
111
+ * @param chunk The chunk metadata + content to score.
112
+ * @param allChunks All chunks in this epoch (used to compute relative recency).
113
+ * @param embedder Optional embedder instance. If omitted, uses the
114
+ * self-contained fallback (128-dim hashed n-gram).
115
+ * @param sessionEmbed Pre-computed embedding for the current session (the
116
+ * "query" vector). If omitted, computed on the fly from
117
+ * the chunk content alone, which degrades semantic scoring
118
+ * to a self-similarity baseline.
119
+ * @returns A number in [0.0, 1.0] where 1.0 = most stable.
120
+ */
121
+ export function computeStabilityScore(chunk, allChunks, embedder, sessionEmbed) {
122
+ // ── Semantic similarity (0.5 weight) ────────────────────────────────────
123
+ const emb = embedder
124
+ ? embedder.embed(chunk.content)
125
+ : fallbackEmbed(chunk.content);
126
+ // If no session embedding is provided, use the chunk's own embedding as
127
+ // a self-similarity — this produces a baseline score based on content
128
+ // density (chunks with more meaningful content get higher internal
129
+ // similarity). Real deployments should pass the session embedding.
130
+ const sem = cosineSimilarity(emb, sessionEmbed ?? emb);
131
+ const semanticScore = isNaN(sem) ? 0 : sem;
132
+ // ── Recency (0.3 weight) ────────────────────────────────────────────────
133
+ // Relative recency: lastAccessedAt of this chunk vs. min/max across epoch.
134
+ // Falls back to 0.5 if there's only one chunk or no timestamp data.
135
+ let recencyScore = 0.5;
136
+ const accessed = allChunks
137
+ .map((c) => c.lastAccessedAt)
138
+ .filter((t) => t > 0);
139
+ if (accessed.length > 1) {
140
+ const minT = Math.min(...accessed);
141
+ const maxT = Math.max(...accessed);
142
+ const range = maxT - minT;
143
+ if (range > 0) {
144
+ recencyScore = (chunk.lastAccessedAt - minT) / range;
145
+ }
146
+ else {
147
+ recencyScore = 1.0;
148
+ }
149
+ }
150
+ // ── Frequency (0.2 weight) ──────────────────────────────────────────────
151
+ // Access count relative to the max across the epoch.
152
+ const counts = allChunks.map((c) => c.accessCount);
153
+ const maxCount = Math.max(...counts, 1);
154
+ const freqScore = maxCount > 0 ? chunk.accessCount / maxCount : 0;
155
+ // ── Composite ───────────────────────────────────────────────────────────
156
+ const stability = WEIGHT_SEMANTIC * semanticScore +
157
+ WEIGHT_RECENCY * recencyScore +
158
+ WEIGHT_FREQUENCY * freqScore;
159
+ // Clamp to [0.0, 1.0] as a safety net.
160
+ return Math.max(0, Math.min(1, stability));
161
+ }
162
+ /**
163
+ * Determine the cache stripe (layer) for a given stability score.
164
+ *
165
+ * @param stability Composite stability score in [0.0, 1.0].
166
+ * @returns Stripe number 0-4.
167
+ */
168
+ export function stabilityToStripe(stability) {
169
+ for (const t of STRIPE_THRESHOLDS) {
170
+ if (stability >= t.minStability)
171
+ return t.stripe;
172
+ }
173
+ return 4;
174
+ }
175
+ // ─── Stripe Reassignment ─────────────────────────────────────────────────────
176
+ /**
177
+ * Refresh stripe assignments for all chunks in the current epoch.
178
+ *
179
+ * Steps:
180
+ * 1. Read all context_chunks from the SQLite store that belong to the
181
+ * current epoch (or all chunks if no epoch filter).
182
+ * 2. For each chunk, compute a stability score via computeStabilityScore.
183
+ * 3. Map stability -> stripe via stabilityToStripe.
184
+ * 4. UPSERT into cache_stripes.
185
+ * 5. (Stale entries for this epoch are implicitly overwritten by the UPSERT.)
186
+ *
187
+ * The optional embedder parameter allows injecting the production
188
+ * TrigramEmbedder. If omitted, the fallback hashed n-gram embedder is used
189
+ * (works offline in all scenarios).
190
+ *
191
+ * Non-fatal: failures are logged via a provided logger callback and never
192
+ * thrown. Returns the count of chunks reassigned.
193
+ *
194
+ * @param store An open SQLite DatabaseSync handle (or a stateDir string
195
+ * to open lazily). Accepts either to match the caller's
196
+ * convenience. When a string is passed, opens the store for
197
+ * this call only (does not cache the connection).
198
+ * @param epochId The epoch to reassign. If omitted, generates a new epoch
199
+ * ID (random hex). Pass '' to reassign all chunks without
200
+ * filtering by epoch.
201
+ * @param embedder Optional TrigramEmbedder instance. When provided, uses it
202
+ * for semantic similarity; otherwise uses the fallback.
203
+ * @param logFn Optional logging callback (defaults to no-op).
204
+ * @returns The number of chunks that were reassigned.
205
+ */
206
+ export function refreshStripeAssignments(store, epochId, embedder, logFn) {
207
+ const db = typeof store === "string" ? openStore(store) : store;
208
+ const log = logFn ?? (() => { });
209
+ const actualEpochId = epochId ?? nextEpochId();
210
+ const now = Math.floor(Date.now() / 1000);
211
+ try {
212
+ // 1. Read all relevant context_chunks, using the summary as text content.
213
+ // The summary field holds the compressed checkpoint content; for fresh
214
+ // chunks that have no summary yet, fall back to normalized_text or
215
+ // concatenated key_decisions.
216
+ const rows = db
217
+ .prepare(`SELECT c.rowid AS chunk_id,
218
+ COALESCE(c.summary, c.normalized_text, c.key_decisions, '') AS content,
219
+ COALESCE(s.access_count, 0) AS access_count,
220
+ COALESCE(s.last_accessed_at, 0) AS last_accessed_at
221
+ FROM context_chunks c
222
+ LEFT JOIN cache_stripes s ON s.chunk_id = CAST(c.rowid AS TEXT)
223
+ WHERE (? = '' OR s.epoch_id = ? OR s.epoch_id IS NULL)`)
224
+ .all(actualEpochId, actualEpochId);
225
+ if (rows.length === 0) {
226
+ log("cache-stripe: no chunks to reassign");
227
+ return 0;
228
+ }
229
+ // Build the allChunks array for relative scoring.
230
+ const allChunks = rows.map((r) => ({
231
+ chunkId: String(r.chunk_id),
232
+ content: r.content,
233
+ accessCount: r.access_count,
234
+ lastAccessedAt: r.last_accessed_at,
235
+ }));
236
+ // Compute a session embedding (mean of all chunk embeddings) for semantic
237
+ // similarity comparison.
238
+ let sessionEmbed;
239
+ try {
240
+ const dim = embedder ? embedder.embed("").length : 128;
241
+ const sumEmb = new Array(dim).fill(0);
242
+ let count = 0;
243
+ for (const chunk of allChunks) {
244
+ const vec = embedder
245
+ ? embedder.embed(chunk.content)
246
+ : fallbackEmbed(chunk.content);
247
+ for (let i = 0; i < sumEmb.length; i++)
248
+ sumEmb[i] += vec[i];
249
+ count++;
250
+ }
251
+ if (count > 0) {
252
+ for (let i = 0; i < sumEmb.length; i++)
253
+ sumEmb[i] /= count;
254
+ sessionEmbed = l2Normalize(sumEmb);
255
+ }
256
+ }
257
+ catch {
258
+ log("cache-stripe: session embedding failed, skipping semantic weight");
259
+ }
260
+ // 2. Compute stability for each chunk.
261
+ const results = [];
262
+ for (const chunk of allChunks) {
263
+ const stability = computeStabilityScore(chunk, allChunks, embedder, sessionEmbed);
264
+ const stripe = stabilityToStripe(stability);
265
+ results.push({ chunkId: chunk.chunkId, stripe, stability });
266
+ }
267
+ // 3. UPSERT into cache_stripes using a savepoint for atomicity.
268
+ const upsert = db.prepare(`INSERT OR REPLACE INTO cache_stripes(chunk_id, stripe, stability, assigned_at, epoch_id)
269
+ VALUES (?, ?, ?, ?, ?)`);
270
+ withTx(db, () => {
271
+ for (const r of results) {
272
+ upsert.run(r.chunkId, r.stripe, r.stability, now, actualEpochId);
273
+ }
274
+ });
275
+ log(`cache-stripe: reassigned ${results.length} chunks to epoch ${actualEpochId}`);
276
+ return results.length;
277
+ }
278
+ catch (err) {
279
+ log(`cache-stripe: refresh failed: ${err instanceof Error ? err.message : String(err)}`);
280
+ return 0;
281
+ }
282
+ }
283
+ /**
284
+ * Generate a random epoch ID (16 hex chars) for tokenizing stripe cohorts.
285
+ */
286
+ function nextEpochId() {
287
+ return randomBytes(8).toString("hex");
288
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * cache-stripe.ts — Vector-Aware Cache Striping shell (PLAN_V2 Phase 3).
3
+ *
4
+ * Shell: re-exports types and function signatures from the implementation.
5
+ * The heavy logic lives in cache-stripe-impl.ts. This keeps the public API
6
+ * surface clean and respects the src/ 300-line soft limit.
7
+ *
8
+ * Pi-agnostic: no pi runtime types, no network (PREVENT-PI-004).
9
+ * All SQL is parameterized (PREVENT-002).
10
+ */
11
+ export { computeStabilityScore, stabilityToStripe, refreshStripeAssignments, } from "./cache-stripe-impl.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * config/stopwords.ts — shared stopword set for query expansion, coverage
3
+ * metrics, and term tokenization (S45, PREREQUISITE P2).
4
+ *
5
+ * Single source of truth: both `src/queryExpansion.ts` and `src/recallMetrics.ts`
6
+ * import from here instead of duplicating inline sets.
7
+ *
8
+ * Pi-agnostic, zero deps, tree-shake safe.
9
+ */
10
+ /** Default English stopwords. */
11
+ export const STOP_WORDS = new Set([
12
+ "a", "an", "the", "and", "or", "but", "in", "on", "at", "to", "for",
13
+ "of", "with", "by", "from", "as", "is", "was", "are", "were", "be",
14
+ "been", "has", "have", "had", "do", "does", "did", "will", "would",
15
+ "could", "should", "may", "might", "shall", "can", "not", "no", "nor",
16
+ "so", "if", "then", "than", "that", "this", "these", "those", "it",
17
+ "its", "i", "me", "my", "we", "our", "you", "your", "he", "she",
18
+ "they", "them", "their", "what", "which", "who", "whom", "when",
19
+ "where", "why", "how", "all", "each", "every", "both", "few", "more",
20
+ "most", "other", "some", "such", "only", "own", "same", "so", "than",
21
+ "too", "very", "just", "about", "above", "after", "again", "against",
22
+ "because", "before", "between", "down", "during", "out", "over",
23
+ "through", "under", "up", "also", "into", "off", "onto", "upon",
24
+ ]);
@@ -81,3 +81,20 @@ export function memoryReviewCadence(band, baseInterval) {
81
81
  default: return base;
82
82
  }
83
83
  }
84
+ // ---------------------------------------------------------------------------
85
+ // S57 RAG Suite feature flags — each maps to MEGACOMPACT_* env var, default OFF
86
+ // ---------------------------------------------------------------------------
87
+ function ragFlag(name) {
88
+ const v = process.env[name];
89
+ if (v === undefined)
90
+ return false;
91
+ return v === "true" || v === "1";
92
+ }
93
+ /** B1: Query reformulation (keyword expansion via embedding neighbors). */
94
+ export const RAG_QUERY_REFORMULATION = () => ragFlag("MEGACOMPACT_QUERY_REFORMULATION");
95
+ /** B2: Tiered recall router (L0 cache → L1 FTS5 → L2 HNSW). */
96
+ export const RAG_TIERED_ROUTER = () => ragFlag("MEGACOMPACT_TIERED_ROUTER");
97
+ /** B3: Recall quality metrics (precision/recall scoring + logging). */
98
+ export const RAG_RECALL_METRICS = () => ragFlag("MEGACOMPACT_RECALL_METRICS");
99
+ /** B4: Memory graph traversal (dashboard-oriented). */
100
+ export const RAG_MEMORY_GRAPH = () => ragFlag("MEGACOMPACT_MEMORY_GRAPH");
@@ -49,20 +49,60 @@ function fnv1a(str) {
49
49
  * Default embedder: character 3-gram bag-of-counts, hashed into a fixed-dim
50
50
  * vector, L2-normalized. Captures local lexical/structure overlap well enough
51
51
  * for checkpoint relevance ranking.
52
+ *
53
+ * S53B: includes a 256-entry (configurable) FIFO cache keyed by FNV-1a(text).
54
+ * Each cache entry holds a DEFENSIVE COPY of the embedding to prevent mutation
55
+ * from corrupting stored vectors. Set MEGACOMPACT_EMBED_CACHE=0 to disable.
52
56
  */
53
57
  export class TrigramEmbedder {
54
58
  dim;
55
59
  seed;
60
+ /** @type {Map<string, Vector>} */
61
+ _cache;
62
+ _cacheSize;
63
+ _hits = 0;
64
+ _misses = 0;
56
65
  constructor(dim = 512, seed = 0x9e3779b9) {
57
66
  this.dim = dim;
58
67
  this.seed = seed >>> 0;
68
+ const cap = Number(process.env.MEGACOMPACT_EMBED_CACHE ?? "256");
69
+ this._cacheSize = cap > 0 ? Math.floor(cap) : 0;
70
+ this._cache = new Map();
71
+ }
72
+ /** Cache statistics — always { hits: 0, misses: 0 } when cache is disabled. */
73
+ getEmbedCacheStats() {
74
+ return { hits: this._hits, misses: this._misses };
59
75
  }
60
76
  embed(text) {
77
+ if (this._cacheSize === 0) {
78
+ return this._embedRaw(text);
79
+ }
80
+ const key = fnv1a(text).toString(36);
81
+ const cached = this._cache.get(key);
82
+ if (cached !== undefined) {
83
+ this._hits++;
84
+ // Defensive copy: caller mutating the returned vector must not corrupt cache.
85
+ return cached.slice();
86
+ }
87
+ this._misses++;
88
+ const vec = this._embedRaw(text);
89
+ // Store a defensive copy (slice) so caller mutation cannot corrupt stored value.
90
+ this._cache.set(key, vec.slice());
91
+ // FIFO eviction: remove the oldest entry when at capacity.
92
+ if (this._cache.size > this._cacheSize) {
93
+ // Map insertion order is guaranteed — first key is the oldest.
94
+ const firstKey = this._cache.keys().next().value;
95
+ if (firstKey !== undefined)
96
+ this._cache.delete(firstKey);
97
+ }
98
+ return vec;
99
+ }
100
+ /** Raw embed computation (no cache logic). Public so tests can bypass cache. */
101
+ _embedRaw(text) {
61
102
  const vec = new Array(this.dim).fill(0);
62
103
  const norm = text.toLowerCase().replace(/\s+/g, " ");
63
104
  if (norm.length === 0)
64
105
  return l2Normalize(vec);
65
- // Whole-string + word + char-trigram signals.
66
106
  vec[fnv1a(norm) % this.dim] += 1;
67
107
  for (const word of norm.split(" ")) {
68
108
  if (word.length === 0)
@@ -74,7 +114,6 @@ export class TrigramEmbedder {
74
114
  vec[idx] += 1;
75
115
  }
76
116
  }
77
- // Edge: very short tokens still get a slot.
78
117
  if (norm.length < 3)
79
118
  vec[fnv1a(norm) % this.dim] += 1;
80
119
  return l2Normalize(vec);