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
@@ -1,343 +0,0 @@
1
- /**
2
- * widget.test.ts — S31 buildWidgetLines render snapshot matrix.
3
- *
4
- * buildWidgetLines is a free function (no pi runtime needed), so we drive it
5
- * directly with a fake WidgetData across the full matrix:
6
- * 6 themes × {full,minimal} × {gameMode on/off} × {cachePct<100, >=100}
7
- * and assert the S31 invariants:
8
- * (a) transparent theme → no '\x1b[48;' bg fill on any line
9
- * (b) non-transparent themes → at least one line carries '\x1b[48;'
10
- * (c) minimal mode → exactly one content line (between the two panel bars)
11
- * (d) gameMode off → no 'LVL' + no 'MEGA CACHE'
12
- * (e) megaCacheFlare + gameMode on + cachePct>=100 → 'MEGA CACHE' text present
13
- * (f) every line visibleWidth <= the terminal width passed in
14
- *
15
- * Uses MEGACOMPACT_STATE_DIR + mkdtemp (G7). No pi runtime.
16
- */
17
- import { describe, it, before, after } from "node:test";
18
- import assert from "node:assert/strict";
19
- import { tmpdir } from "node:os";
20
- import { join } from "node:path";
21
- import { mkdtempSync, rmSync } from "node:fs";
22
- import { visibleWidth } from "@earendil-works/pi-tui";
23
- import { buildWidgetLines } from "./widget.js";
24
- import { THEME_IDS, DEFAULT_THEME, getTheme } from "../../src/config/themes.js";
25
- /** A minimal but complete WidgetData (all required fields populated). The S31
26
- * game-mode fields are overridden per-case. */
27
- function baseWd(overrides = {}) {
28
- return {
29
- version: "0.0.0-test",
30
- tierLabel: "low",
31
- triggerLabel: "idle",
32
- pctStr: "42%",
33
- tokStr: "10k",
34
- maxStr: "200k",
35
- ctxPct: 0.42,
36
- chk: 3,
37
- agentStr: "",
38
- turnStr: "",
39
- dedupStr: "12%",
40
- sessIn: 1000,
41
- sessKept: 800,
42
- sTxt: "20",
43
- repoIn: 5000,
44
- repoKept: 4000,
45
- rTxt: "20",
46
- repoChk: 9,
47
- repoSess: 2,
48
- modelStr: "test-model",
49
- sinceCompact: null,
50
- embedderName: "Trigram",
51
- compStr: "1.2x",
52
- driftStatus: "ok",
53
- agentsActive: false,
54
- fresh: false,
55
- ticker: [],
56
- lastWhy: undefined,
57
- tierTrace: undefined,
58
- pulsing: false,
59
- ...overrides,
60
- };
61
- }
62
- const WIDTH = 120;
63
- function contentLines(lines) {
64
- // Strip the top + bottom panel bars; what's left is the content body.
65
- return lines.slice(1, lines.length - 1);
66
- }
67
- describe("buildWidgetLines (S31)", () => {
68
- let dir;
69
- before(() => {
70
- dir = mkdtempSync(join(tmpdir(), "mc-widget-"));
71
- process.env.MEGACOMPACT_STATE_DIR = dir;
72
- });
73
- after(() => {
74
- delete process.env.MEGACOMPACT_STATE_DIR;
75
- rmSync(dir, { recursive: true, force: true });
76
- });
77
- it("null wd → warm-up panel (3 lines, all width-safe)", () => {
78
- const lines = buildWidgetLines(null, WIDTH, 0);
79
- assert.equal(lines.length, 3);
80
- for (const l of lines)
81
- assert.ok(visibleWidth(l) <= WIDTH, "width safe");
82
- });
83
- for (const theme of THEME_IDS) {
84
- for (const tuiMode of ["full", "minimal"]) {
85
- for (const gameMode of [false, true]) {
86
- for (const cachePct of [42, 150]) {
87
- const flare = cachePct >= 100;
88
- const label = `theme=${theme} tui=${tuiMode} game=${gameMode} cache=${cachePct}`;
89
- it(label, () => {
90
- const wd = baseWd({
91
- theme,
92
- tuiMode,
93
- gameMode,
94
- level: 1,
95
- cachePct,
96
- megaCacheFlare: flare,
97
- // C.3: flare gate reads megaCacheFlarePct, not cachePct
98
- ...(flare ? { megaCacheFlarePct: cachePct } : {}),
99
- });
100
- const lines = buildWidgetLines(wd, WIDTH, 0);
101
- const body = contentLines(lines);
102
- const joined = lines.join("\n");
103
- // (f) every line width <= terminal (truncateToWidth respected)
104
- for (const l of lines) {
105
- assert.ok(visibleWidth(l) <= WIDTH, `width safe: ${visibleWidth(l)} > ${WIDTH}`);
106
- }
107
- // (a) transparent theme → no '\x1b[48;' bg fill anywhere
108
- if (theme === DEFAULT_THEME) {
109
- assert.ok(!joined.includes("\x1b[48;"), `transparent has no 48; bg fill: ${label}`);
110
- }
111
- else {
112
- // (b) non-transparent themes → their bg SGR appears on some line.
113
- // (Themes may use 3-bit bg like \x1b[40m, not just 48;5; form.)
114
- const bgParams = getTheme(theme).ansi.bg;
115
- const bgEsc = `\x1b[${bgParams}m`;
116
- assert.ok(joined.includes(bgEsc), `themed has bg fill ${bgEsc}: ${label}`);
117
- }
118
- // (c) minimal mode → exactly one content line
119
- if (tuiMode === "minimal") {
120
- assert.equal(body.length, 1, `minimal one line: ${label}`);
121
- }
122
- // (d) gameMode off → no LVL + no MEGA CACHE
123
- if (!gameMode) {
124
- assert.ok(!joined.includes("LVL"), `no LVL when off: ${label}`);
125
- assert.ok(!joined.includes("MEGA CACHE"), `no MEGA CACHE when off: ${label}`);
126
- }
127
- else {
128
- // gameMode on → LVL shown (in full mode header, or minimal line)
129
- assert.ok(joined.includes("LVL"), `LVL shown when on: ${label}`);
130
- }
131
- // (e) MEGA CACHE flare text appears only when flare + gameMode on
132
- const expectMega = flare && gameMode;
133
- const hasMega = joined.includes("MEGA CACHE");
134
- assert.equal(hasMega, expectMega, `MEGA CACHE flare: ${label} (got ${hasMega}, want ${expectMega})`);
135
- });
136
- }
137
- }
138
- }
139
- }
140
- });
141
- describe("buildWidgetLines ambient border effect (v0.8.3)", () => {
142
- const effBase = (overrides = {}) => baseWd({
143
- theme: DEFAULT_THEME,
144
- tuiMode: "full",
145
- gameMode: true,
146
- level: 1,
147
- cachePct: 42,
148
- ...overrides,
149
- });
150
- const isBorder = (l) => l.includes("─");
151
- it("activeEffect (pulse, mid-window) -> border lines carry a 256-color fg SGR", () => {
152
- const ae = {
153
- type: "pulse",
154
- role: "accent",
155
- startedAt: Date.now() - 250,
156
- durationMs: 2000,
157
- };
158
- const lines = buildWidgetLines(effBase({ activeEffect: ae }), WIDTH, 0);
159
- const borders = lines.filter(isBorder);
160
- assert.ok(borders.length >= 2, "has top + bottom borders");
161
- for (const b of borders) {
162
- assert.ok(b.includes("\x1b[38;5;"), `border carries 256-color fg: ${JSON.stringify(b)}`);
163
- }
164
- });
165
- it("activeEffect null -> plain borders, no 38;5 fg SGR on border lines", () => {
166
- const lines = buildWidgetLines(effBase({ activeEffect: null }), WIDTH, 0);
167
- const borders = lines.filter(isBorder);
168
- for (const b of borders) {
169
- assert.ok(!b.includes("\x1b[38;5;"), `no effect SGR on plain border: ${JSON.stringify(b)}`);
170
- }
171
- });
172
- it("expired activeEffect -> plain borders (per-frame expiry enforced)", () => {
173
- const ae = {
174
- type: "pulse",
175
- role: "accent",
176
- startedAt: Date.now() - 5000,
177
- durationMs: 1000,
178
- };
179
- const lines = buildWidgetLines(effBase({ activeEffect: ae }), WIDTH, 0);
180
- const borders = lines.filter(isBorder);
181
- for (const b of borders) {
182
- assert.ok(!b.includes("\x1b[38;5;"), `expired effect -> plain border: ${JSON.stringify(b)}`);
183
- }
184
- });
185
- it("activeEffect border lines are width-safe (pulse, minimal + full)", () => {
186
- for (const tuiMode of ["minimal", "full"]) {
187
- const ae = {
188
- type: "pulse",
189
- role: "mega",
190
- startedAt: Date.now() - 100,
191
- durationMs: 2000,
192
- };
193
- const lines = buildWidgetLines(effBase({ activeEffect: ae, tuiMode }), 60, 0);
194
- for (const l of lines)
195
- assert.ok(visibleWidth(l) <= 60, `width safe (${tuiMode}): ${visibleWidth(l)}`);
196
- }
197
- });
198
- it("flash effect mid-window border carries the full base index SGR", () => {
199
- // Force an 'on' phase of the 120ms alternate by starting just now.
200
- const ae = {
201
- type: "flash",
202
- role: "red",
203
- startedAt: Date.now(),
204
- durationMs: 1200,
205
- };
206
- const lines = buildWidgetLines(effBase({ activeEffect: ae }), WIDTH, 0);
207
- const borders = lines.filter(isBorder);
208
- assert.ok(borders.some((b) => b.includes("\x1b[38;5;203m")), `flash-on phase uses red base 203`);
209
- });
210
- });
211
- describe("buildWidgetLines C.3 flare gate regression", () => {
212
- const flareBase = (overrides = {}) => baseWd({
213
- theme: DEFAULT_THEME,
214
- tuiMode: "full",
215
- gameMode: true,
216
- level: 1,
217
- cachePct: 42,
218
- ...overrides,
219
- });
220
- it("flare fires when megaCacheFlarePct >= 100 even when cachePct < 100", () => {
221
- // Regression: the old code read (wd.cachePct ?? 0) >= 100, so when
222
- // cachePct was 56 (provider hit rate) the flare silently broke.
223
- const lines = buildWidgetLines(flareBase({
224
- cachePct: 56,
225
- megaCacheFlare: true,
226
- megaCacheFlarePct: 287,
227
- }), WIDTH, 0);
228
- assert.ok(lines.join("\n").includes("MEGA CACHE"), "flare fires from megaCacheFlarePct");
229
- });
230
- it("flare suppressed when megaCacheFlarePct < 100 even when cachePct >= 100", () => {
231
- // Symmetric regression: high cachePct should NOT alone trigger flare.
232
- const lines = buildWidgetLines(flareBase({
233
- cachePct: 150,
234
- megaCacheFlare: true,
235
- megaCacheFlarePct: 42,
236
- }), WIDTH, 0);
237
- assert.ok(!lines.join("\n").includes("MEGA CACHE"), "no flare when megaCacheFlarePct below threshold");
238
- });
239
- it("flare suppressed when megaCacheFlarePct is missing (undefined)", () => {
240
- const lines = buildWidgetLines(flareBase({
241
- cachePct: 150,
242
- megaCacheFlare: true,
243
- }), WIDTH, 0);
244
- assert.ok(!lines.join("\n").includes("MEGA CACHE"), "no flare without megaCacheFlarePct");
245
- });
246
- });
247
- describe("buildWidgetLines footer stability (P1 — no 250ms rotation)", () => {
248
- // P1: the L5 ticker branch used to re-pick the head text every 250ms via
249
- // `step = floor(Date.now()/250)`, flipping the footer line on a 250·N ms
250
- // cycle. After the fix it pins to the most-recent entry, so two renders of
251
- // the SAME WidgetData at t and t+500ms (well past one rotation slot) must
252
- // produce byte-identical footer lines. Proves the metronome is gone.
253
- const stabBase = (overrides = {}) => baseWd({
254
- theme: DEFAULT_THEME,
255
- tuiMode: "full",
256
- gameMode: false,
257
- level: 1,
258
- cachePct: 42,
259
- ...overrides,
260
- });
261
- it("ticker footer is byte-identical across simulated frames 500ms apart", () => {
262
- const wd = stabBase({
263
- ticker: [
264
- { text: "first", at: 1000 },
265
- { text: "second", at: 2000 },
266
- { text: "third", at: 3000 },
267
- ],
268
- lastWhy: "because",
269
- });
270
- const realNow = Date.now;
271
- try {
272
- Date.now = () => 1_000_000; // t
273
- const a = buildWidgetLines(wd, WIDTH, 0);
274
- Date.now = () => 1_000_500; // t+500ms (would have rotated twice under the old code)
275
- const b = buildWidgetLines(wd, WIDTH, 0);
276
- assert.deepEqual(a, b, "footer byte-identical across 500ms with no state change");
277
- // And the pinned head is the most-recent entry (third), not a rotation:
278
- assert.ok(a.some((l) => l.includes("third")), "shows most-recent ticker entry");
279
- assert.ok(a.some((l) => l.includes("(+2 more)")), "(+N more) suffix preserved");
280
- assert.ok(a.some((l) => l.includes("because")), "lastWhy preserved");
281
- }
282
- finally {
283
- Date.now = realNow;
284
- }
285
- });
286
- it("footer still flips when the ticker actually changes (new pushTicker)", () => {
287
- const realNow = Date.now;
288
- try {
289
- Date.now = () => 1_000_000;
290
- const before = buildWidgetLines(stabBase({ ticker: [{ text: "a", at: 1 }] }), WIDTH, 0);
291
- const after = buildWidgetLines(stabBase({
292
- ticker: [
293
- { text: "a", at: 1 },
294
- { text: "b", at: 2 },
295
- ],
296
- }), WIDTH, 0);
297
- assert.notDeepEqual(before, after, "footer changes when ticker grows");
298
- }
299
- finally {
300
- Date.now = realNow;
301
- }
302
- });
303
- });
304
- describe("buildWidgetLines achievement flare (S35)", () => {
305
- const achBase = (overrides = {}) => baseWd({
306
- theme: DEFAULT_THEME,
307
- tuiMode: "full",
308
- gameMode: true,
309
- level: 1,
310
- cachePct: 42,
311
- ...overrides,
312
- });
313
- it("achievementFlare + titles -> renders the unlock toast line", () => {
314
- const lines = buildWidgetLines(achBase({
315
- achievementFlare: true,
316
- achievementFlareTitles: ["First Compact"],
317
- }), WIDTH, 0);
318
- assert.ok(lines.some((l) => l.includes("Achievement unlocked: First Compact")), "toast line present");
319
- });
320
- it("achievementFlare off -> no toast line", () => {
321
- const lines = buildWidgetLines(achBase({
322
- achievementFlare: false,
323
- achievementFlareTitles: ["First Compact"],
324
- }), WIDTH, 0);
325
- assert.ok(!lines.some((l) => l.includes("Achievement unlocked")), "no toast when flare off");
326
- });
327
- it("gameMode off -> no toast even if flare set", () => {
328
- const lines = buildWidgetLines(achBase({
329
- gameMode: false,
330
- achievementFlare: true,
331
- achievementFlareTitles: ["X"],
332
- }), WIDTH, 0);
333
- assert.ok(!lines.some((l) => l.includes("Achievement unlocked")), "no toast when game off");
334
- });
335
- it("achievement toast is width-safe", () => {
336
- const lines = buildWidgetLines(achBase({
337
- achievementFlare: true,
338
- achievementFlareTitles: ["First Compact", "Turn Veteran"],
339
- }), 60, 0);
340
- for (const l of lines)
341
- assert.ok(visibleWidth(l) <= 60, "width safe");
342
- });
343
- });
@@ -1,121 +0,0 @@
1
- /**
2
- * mega-shutdown-widget.test.ts — regression cover for two host-integration
3
- * fixes that the rest of the suite cannot see, because both are about what
4
- * happens at the boundary with pi rather than inside the compaction engine:
5
- *
6
- * 1. session_shutdown must close the PGlite indexes. They are lazily-opened
7
- * module singletons whose handles keep node's event loop alive, so leaving
8
- * them open made `pi -p` produce its answer and then hang instead of
9
- * exiting. closeVectorIndex()/closeMemoryIndex() existed but had no
10
- * non-test callers.
11
- *
12
- * 2. The above-editor widget must be suppressible. It is a persistent,
13
- * animated, full-width panel that repaints on its own cadence, which fights
14
- * terminals where the user drives scrollback (pi inside a Neovim
15
- * `:terminal`). MEGACOMPACT_TUI_WIDGET=0 turns it off without touching
16
- * compaction.
17
- */
18
- import { test } from "node:test";
19
- import assert from "node:assert/strict";
20
- import { mkdtempSync, rmSync } from "node:fs";
21
- import { tmpdir } from "node:os";
22
- import { join } from "node:path";
23
- import { closeVectorIndex, initVectorIndex, isVectorIndexDisabled, } from "../src/store/vectorIndex.js";
24
- import { closeMemoryIndex } from "../src/store/memoryIndex.js";
25
- import { loadConfig } from "./mega-config.js";
26
- import { MegaRuntime } from "./mega-runtime.js";
27
- const baseTmp = mkdtempSync(join(tmpdir(), "mc-shutdown-"));
28
- process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index");
29
- let counter = 0;
30
- /** Fresh per-test state dir so concurrent runs never collide on disk. */
31
- function isolate() {
32
- process.env.MEGACOMPACT_STATE_DIR = join(baseTmp, `run-${counter++}`);
33
- }
34
- /** Minimal ExtensionContext slice: renderWidget only reaches ctx.ui.setWidget. */
35
- function widgetCtx(calls) {
36
- return {
37
- ui: {
38
- setWidget: (key) => calls.push(key),
39
- },
40
- };
41
- }
42
- test.after(async () => {
43
- // This file is itself a demonstration of the bug under test: without these
44
- // closes the PGlite handles opened above keep the event loop alive and the
45
- // test process never exits.
46
- await Promise.all([closeVectorIndex(), closeMemoryIndex()]);
47
- rmSync(baseTmp, { recursive: true, force: true });
48
- });
49
- test("MEGACOMPACT_TUI_WIDGET defaults on and is disabled by 0", () => {
50
- isolate();
51
- delete process.env.MEGACOMPACT_TUI_WIDGET;
52
- assert.equal(loadConfig().tuiWidget, true, "widget should default to on");
53
- process.env.MEGACOMPACT_TUI_WIDGET = "0";
54
- assert.equal(loadConfig().tuiWidget, false);
55
- process.env.MEGACOMPACT_TUI_WIDGET = "1";
56
- assert.equal(loadConfig().tuiWidget, true);
57
- delete process.env.MEGACOMPACT_TUI_WIDGET;
58
- });
59
- test("renderWidget registers the panel when tuiWidget is on", () => {
60
- isolate();
61
- delete process.env.MEGACOMPACT_TUI_WIDGET;
62
- const runtime = new MegaRuntime(loadConfig());
63
- try {
64
- const calls = [];
65
- runtime.renderWidget(widgetCtx(calls));
66
- assert.equal(calls.length, 1, "expected one setWidget registration");
67
- }
68
- finally {
69
- runtime.dispose();
70
- }
71
- });
72
- test("renderWidget registers nothing when tuiWidget is off", () => {
73
- isolate();
74
- process.env.MEGACOMPACT_TUI_WIDGET = "0";
75
- const runtime = new MegaRuntime(loadConfig());
76
- try {
77
- const calls = [];
78
- // Repeated calls, because the panel is re-registered on every snapshot
79
- // and every game-state change — one guarded path is not enough.
80
- runtime.renderWidget(widgetCtx(calls));
81
- runtime.renderWidget(widgetCtx(calls));
82
- assert.deepEqual(calls, [], "widget must never be registered when disabled");
83
- }
84
- finally {
85
- runtime.dispose();
86
- delete process.env.MEGACOMPACT_TUI_WIDGET;
87
- }
88
- });
89
- test("the extension's session_shutdown handler awaits index teardown", async () => {
90
- isolate();
91
- const handlers = {};
92
- const pi = {
93
- on(event, handler) {
94
- (handlers[event] ??= []).push(handler);
95
- },
96
- registerCommand() { },
97
- registerProvider() { },
98
- };
99
- const { default: extension } = await import("./mega-compact.js");
100
- extension(pi);
101
- const shutdown = handlers["session_shutdown"] ?? [];
102
- assert.ok(shutdown.length, "extension must register a session_shutdown handler");
103
- const event = { type: "session_shutdown" };
104
- const ctx = {
105
- ui: { setStatus: () => { }, notify: () => { }, setWidget: () => { } },
106
- cwd: process.env.MEGACOMPACT_STATE_DIR,
107
- };
108
- // Assert the close by identity rather than by "some handler returned a
109
- // promise": several modules register on session_shutdown and at least one
110
- // other is already async, so a promise proves nothing about teardown. The
111
- // index is a module singleton, so if shutdown really closed it, re-init
112
- // hands back a *different* instance.
113
- const before = await initVectorIndex();
114
- if (isVectorIndexDisabled() || !before)
115
- return; // PGlite unavailable — nothing to close
116
- await Promise.all(shutdown.map((handler) => handler(event, ctx)));
117
- const after = await initVectorIndex();
118
- assert.notEqual(after, before, "session_shutdown must close the PGlite vector index");
119
- // Idempotent: a second shutdown (reload, double-fire) must not throw.
120
- await Promise.all(shutdown.map((handler) => handler(event, ctx)));
121
- });
@@ -1,156 +0,0 @@
1
- /**
2
- * mega-teamrun.test.ts — regression test for the "auto-compact runs but context
3
- * never relieves during a team run (sub-agents)" bug.
4
- *
5
- * Loads the REAL compiled extension (extensions/mega-compact.js) through a
6
- * faithful mock pi (mirrors mega-compact.test.ts's harness) and drives the
7
- * exact event sequence a long team run produces:
8
- *
9
- * agent_start -> context (over threshold) xN -> agent_end (repeat x3)
10
- *
11
- * Asserts the TWO fixes:
12
- * 1. live trim FIRES per-call (computeLiveTrimCut no longer returns null on
13
- * the anchor floor — was `cutNull`, liveTrimFires===0 before the fix).
14
- * 2. the DURABLE trim fires at agent_end while idle + over threshold
15
- * (mid-run durable trigger), not only at parent settle.
16
- *
17
- * The mock ctx.compact() drives session_before_compact so we observe the
18
- * durable truncation. Counters come from MegaRuntime.diag* (set behind the
19
- * real handler code, inert in production).
20
- *
21
- * MEGACOMPACT_PGLITE_DISABLED keeps the run fast (no WASM index init).
22
- */
23
- import { test } from "node:test";
24
- import assert from "node:assert/strict";
25
- import { mkdtempSync, rmSync } from "node:fs";
26
- import { tmpdir } from "node:os";
27
- import { join } from "node:path";
28
- import { createRequire } from "node:module";
29
- import { closeVectorIndex } from "../src/store/vectorIndex.js";
30
- const require = createRequire(import.meta.url);
31
- const baseTmp = mkdtempSync(join(tmpdir(), "mc-team-"));
32
- process.env.MEGACOMPACT_INDEX_DIR = join(baseTmp, "index");
33
- process.env.MEGACOMPACT_PGLITE_DISABLED = "true"; // fast: skip WASM index
34
- let counter = 0;
35
- function harness() {
36
- const stateDir = join(baseTmp, `run-${counter++}`);
37
- process.env.MEGACOMPACT_STATE_DIR = stateDir;
38
- process.env.MEGACOMPACT_DEBUG = "true";
39
- process.env.MEGACOMPACT_THRESHOLD_TOKENS = "50";
40
- process.env.MEGACOMPACT_FAST_GATE_PCT = "1";
41
- // Strict race-guard mode double-counts diagAgentEndDurable (sync++ at branch
42
- // entry + deferred++ in the setTimeout(500) callback = 6, not 3), lands
43
- // compactCalls after the synchronous assertions, and leaks timers that hang
44
- // `node --test`. The strict deferred path is covered by the two S38.5 tests
45
- // in mega-compact.test.ts. Use the synchronous v0.7.4 path here.
46
- process.env.MEGACOMPACT_RACE_GUARD_STRICT = "false";
47
- process.env.MEGACOMPACT_ANCHOR_USER_MESSAGES = "1";
48
- process.env.MEGACOMPACT_DURABLE_TRIM_FLOOR = "0"; // piCompactWouldNoop must not skip
49
- process.env.MEGACOMPACT_MEMORY_AUTO_REVIEW = "false";
50
- process.env.MEGACOMPACT_RAPTOR_ENABLED = "false";
51
- delete process.env.MEGACOMPACT_LEGACY_DURABLE_TRIM;
52
- const handlers = {};
53
- const compactCalls = [];
54
- function msg(role, text, toolName) {
55
- if (role === "assistant" && toolName) {
56
- return { role: "assistant", content: [{ type: "toolCall", name: toolName, id: "c1", arguments: {} }], api: "anthropic-messages", provider: "anthropic", model: "m", usage: { inputTokens: 1, outputTokens: 1, cacheReadTokens: 0, cacheWriteTokens: 0 }, stopReason: "tool_use", timestamp: 0 };
57
- }
58
- if (role === "toolResult" && toolName) {
59
- return { role: "toolResult", content: [{ type: "text", text }], toolCallId: "c1", toolName, isError: false, timestamp: 0 };
60
- }
61
- return { role: "user", content: text, timestamp: 0 };
62
- }
63
- const session = [];
64
- for (let i = 0; i < 14; i++) {
65
- session.push(msg("user", `actually we decided to use approach ${i} for module ${i}`));
66
- session.push(msg("assistant", `edited module ${i}`, "Edit"));
67
- session.push(msg("toolResult", `edited module ${i}`, "Edit"));
68
- }
69
- const toEntry = (m, i) => ({ type: "message", id: `e${i}`, parentId: null, timestamp: String(i), message: m });
70
- const sessionManager = {
71
- getSessionId: () => "sess_team_001",
72
- getEntries: () => session.map(toEntry),
73
- getBranch: () => session.map(toEntry),
74
- };
75
- function makeCtx(over = {}) {
76
- return {
77
- ui: { setStatus: () => { }, notify: () => { }, select: () => { }, confirm: async () => true, input: async () => "", setWidget: () => { } },
78
- mode: "tui", hasUI: true, cwd: stateDir, sessionManager,
79
- modelRegistry: {}, model: undefined, isIdle: () => true, isProjectTrusted: () => true,
80
- signal: undefined, abort: () => { }, hasPendingMessages: () => false, shutdown: () => { },
81
- getContextUsage: () => ({ tokens: 200000, contextWindow: 200000, percent: 100 }),
82
- // Mock ctx.compact() runs pi's flow and fires session_before_compact.
83
- compact: (opts) => {
84
- compactCalls.push(opts);
85
- if (handlers["session_before_compact"]) {
86
- return handlers["session_before_compact"]({ type: "session_before_compact", reason: "threshold", willRetry: false, signal: undefined, preparation: { firstKeptEntryId: "e2", messagesToSummarize: session.slice(0, 2), tokensBefore: 500 } }, makeCtx());
87
- }
88
- return undefined;
89
- },
90
- getSystemPrompt: () => "system base",
91
- ...over,
92
- };
93
- }
94
- const pi = {
95
- on: (ev, h) => { handlers[ev] = h; },
96
- registerCommand: () => { }, registerTool: () => { }, registerShortcut: () => { },
97
- registerFlag: () => { }, getFlag: () => undefined, registerMessageRenderer: () => { },
98
- registerEntryRenderer: () => { }, sendMessage: () => { }, sendUserMessage: () => { },
99
- appendEntry: () => { }, setSessionName: () => { }, getSessionName: () => undefined,
100
- setLabel: () => { }, exec: async () => ({ stdout: "", stderr: "", code: 0 }),
101
- getActiveTools: () => [], getAllTools: () => [], setActiveTools: () => { },
102
- getCommands: () => [], setModel: async () => false, getThinkingLevel: () => "off",
103
- setThinkingLevel: () => { },
104
- };
105
- const mod = require("./mega-compact.js");
106
- mod.default(pi);
107
- const { lastRuntime } = require("./mega-events.js");
108
- const fire = (ev, event, ctx) => handlers[ev](event, ctx);
109
- return {
110
- stateDir, handlers, compactCalls, fire, ctx: makeCtx, session,
111
- runtime: lastRuntime, // MegaRuntime with diag* counters
112
- // Advance the debounce so agent_end (same instant) can trigger durable trim.
113
- clearDebounce: () => { if (lastRuntime)
114
- lastRuntime.debounceUntil = 0; },
115
- };
116
- }
117
- test("team run: live trim fires AND durable trim fires per sub-agent (relieves context)", async () => {
118
- const h = harness();
119
- const ctx = h.ctx();
120
- for (let a = 0; a < 3; a++) {
121
- await h.fire("agent_start", { type: "agent_start", messages: [] }, ctx);
122
- for (let i = 0; i < 4; i++) {
123
- await h.fire("context", { type: "context", messages: h.session }, ctx);
124
- }
125
- // Real team runs settle seconds after the last context event; mimic that
126
- // so the 2s debounce has elapsed and the durable trigger can fire.
127
- await new Promise((r) => setTimeout(r, 2100));
128
- h.clearDebounce();
129
- await h.fire("agent_end", { type: "agent_end", messages: [] }, ctx);
130
- }
131
- const rt = h.runtime;
132
- // FIX 1: live trim must actually fire (was 0 — computeLiveTrimCut returned null).
133
- assert.ok(rt.diagLiveTrimFires > 0, "live trim fires during the team run (anchor-floor fix)");
134
- assert.equal(rt.diagCtxCutNull, 0, "no live-trim cut skipped on anchor floor");
135
- // FIX 2: durable trim must fire at each agent_end (was 0 — only at parent settle).
136
- assert.equal(rt.diagAgentEndDurable, 3, "mid-run durable trigger fired at each agent_end");
137
- assert.equal(rt.diagBeforeCompactSupplied, 3, "our durable trim supplied 3x (context relieved)");
138
- assert.ok(h.compactCalls.length >= 3, "ctx.compact() invoked for durable trim between sub-agents");
139
- });
140
- test("control: session_before_compact supplies a durable compaction (parent settles)", async () => {
141
- const h = harness();
142
- const res = await h.fire("session_before_compact", { type: "session_before_compact", reason: "threshold", willRetry: false, signal: undefined, preparation: { firstKeptEntryId: "e2", messagesToSummarize: h.session.slice(0, 4), tokensBefore: 500 } }, h.ctx());
143
- assert.ok(res?.compaction, "compaction result returned to pi");
144
- assert.equal(res.compaction.firstKeptEntryId, "e2", "reuses pi's boundary (PREVENT-PI-002)");
145
- });
146
- test("cleanup", async () => {
147
- // Race closeVectorIndex with a timeout to prevent 40-min hangs.
148
- try {
149
- await Promise.race([
150
- closeVectorIndex(),
151
- new Promise((r) => setTimeout(r, 3000)),
152
- ]);
153
- }
154
- catch { /* ignore */ }
155
- rmSync(baseTmp, { recursive: true, force: true });
156
- });
@@ -1,58 +0,0 @@
1
- /**
2
- * mega-trim.test.ts — tests for the live compaction view builder (S16).
3
- */
4
- import { test } from "node:test";
5
- import assert from "node:assert/strict";
6
- import { buildLiveTrimmedView } from "./mega-trim.js";
7
- function m(role, text, extra = {}) {
8
- return { role, text, toolName: undefined, input: undefined, output: undefined, ...extra };
9
- }
10
- test("buildLiveTrimmedView: prepends a compacted summary and keeps the recent anchor", () => {
11
- const view = [
12
- m("user", "old request one"), m("assistant", "old answer one"),
13
- m("user", "old request two"), m("assistant", "old answer two"),
14
- m("user", "recent keep me"), m("assistant", "recent keep me too"),
15
- ];
16
- // Compacted region = first 4; recent anchor = last 2.
17
- const result = buildLiveTrimmedView(view, {
18
- compactedFrom: 4, // index where the compacted region ends
19
- summary: "<summary>earlier work on old requests</summary>",
20
- anchorUserMessages: 1,
21
- });
22
- // First element is the injected compacted summary as a user-role message.
23
- assert.equal(result[0].role, "user");
24
- assert.ok(String(result[0].text).includes("earlier work on old requests"));
25
- // Recent anchor preserved in order, no older messages leak through.
26
- assert.equal(result.length, 1 + 2, "summary + 2 recent");
27
- assert.ok(result.slice(1).some((x) => String(x.text).includes("recent keep me")));
28
- });
29
- test("buildLiveTrimmedView: empty summary returns the original view unchanged", () => {
30
- const view = [m("user", "x"), m("assistant", "y")];
31
- const result = buildLiveTrimmedView(view, { compactedFrom: 0, summary: "", anchorUserMessages: 1 });
32
- assert.deepEqual(result, view);
33
- });
34
- test("buildLiveTrimmedView: never splits a toolCall/toolResult pair (PREVENT-PI-002)", () => {
35
- const view = [
36
- m("user", "q"), m("assistant", "calls tool", { toolName: "read" }), m("tool", "result"),
37
- m("user", "keep"), m("assistant", "ok"),
38
- ];
39
- // cut=3 would start the preserved run on the orphaned tool result at index 2 —
40
- // the builder must snap back so the toolCall/toolResult pair is not split.
41
- const result = buildLiveTrimmedView(view, { compactedFrom: 3, summary: "<summary>s</summary>", anchorUserMessages: 1 });
42
- // The tool result must never appear preserved WITHOUT its preceding toolCall.
43
- const preserved = result.slice(1);
44
- const hasToolResult = preserved.some((x) => x.role === "tool");
45
- const hasToolCall = preserved.some((x) => x.role === "assistant" && x.toolName);
46
- // Either the tool pair is kept together, or the tool result is dropped into
47
- // the compacted region — it is never left orphaned.
48
- assert.ok(!(hasToolResult && !hasToolCall), "no orphaned tool result in the preserved run");
49
- });
50
- test("buildLiveTrimmedView: honors the anchor floor (PREVENT-PI-001)", () => {
51
- // cut would leave zero user messages in the anchor — must skip the trim.
52
- const view = [
53
- m("user", "old q"), m("assistant", "old a"),
54
- m("assistant", "only assistant kept"),
55
- ];
56
- const result = buildLiveTrimmedView(view, { compactedFrom: 2, summary: "<summary>s</summary>", anchorUserMessages: 1 });
57
- assert.deepEqual(result, view, "below anchor floor → no trim this call");
58
- });