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.
- package/dist/extensions/dashboard-server/api-contracts/cache-stripes.js +8 -0
- package/dist/extensions/dashboard-server/api-contracts/endpoints.js +32 -0
- package/dist/extensions/dashboard-server/api-contracts/memory-map.js +1 -0
- package/dist/extensions/dashboard-server/api-contracts/memory.js +8 -0
- package/dist/extensions/dashboard-server/api-contracts/provider-cache.js +1 -0
- package/dist/extensions/dashboard-server/api-contracts/setup.js +10 -0
- package/dist/extensions/dashboard-server/index-reader.js +6 -2
- package/dist/extensions/dashboard-server/routes-cache.js +135 -47
- package/dist/extensions/dashboard-server/routes-game.js +3 -0
- package/dist/extensions/dashboard-server/routes-memory-map.js +50 -0
- package/dist/extensions/dashboard-server/routes-memory.js +51 -0
- package/dist/extensions/dashboard-server/routes-repo.js +2 -2
- package/dist/extensions/dashboard-server/routes-setup.js +267 -0
- package/dist/extensions/dashboard-server/routes.js +4 -0
- package/dist/extensions/dashboard-server/server.js +13 -1
- package/dist/extensions/mega-commands.js +189 -1
- package/dist/extensions/mega-compact.js +5 -0
- package/dist/extensions/mega-config.js +7 -0
- package/dist/extensions/mega-events/agent-handlers.js +19 -4
- package/dist/extensions/mega-events/compact-handlers.js +1 -0
- package/dist/extensions/mega-events/context-handler.js +45 -92
- package/dist/extensions/mega-events/context-hwm.js +51 -0
- package/dist/extensions/mega-events/error-classifier.js +16 -5
- package/dist/extensions/mega-events/mirror-append.js +107 -0
- package/dist/extensions/mega-events/outage-advisor.js +7 -1
- package/dist/extensions/mega-events/perf-handler.js +134 -2
- package/dist/extensions/mega-events/recall-tail.js +59 -0
- package/dist/extensions/mega-events/separated-prompt.js +248 -0
- package/dist/extensions/mega-events/session-handlers.js +15 -8
- package/dist/extensions/mega-runtime/env-loader.js +56 -0
- package/dist/extensions/mega-runtime/reset-runtime.js +6 -0
- package/dist/extensions/mega-runtime/runtime-snapshot.js +1 -0
- package/dist/extensions/mega-runtime/runtime.js +7 -0
- package/dist/extensions/mega-runtime/snapshot.js +1 -0
- package/dist/extensions/mega-runtime/widget.js +5 -0
- package/dist/src/cache-stripe-impl.js +288 -0
- package/dist/src/cache-stripe.js +11 -0
- package/dist/src/config/stopwords.js +24 -0
- package/dist/src/config.js +17 -0
- package/dist/src/embedder.js +41 -2
- package/dist/src/memoryGraph.js +299 -0
- package/dist/src/memoryStats.js +75 -0
- package/dist/src/monitoring.js +13 -0
- package/dist/src/prefix-break.js +43 -0
- package/dist/src/pricing.js +1 -1
- package/dist/src/queryExpansion.js +163 -0
- package/dist/src/queryReformulation/cache.js +123 -0
- package/dist/src/queryReformulation/rrf.js +29 -0
- package/dist/src/queryReformulation/tfidf.js +61 -0
- package/dist/src/queryReformulation/vagueness.js +33 -0
- package/dist/src/queryReformulation.js +225 -0
- package/dist/src/recallMetrics.js +258 -0
- package/dist/src/store/sqlite/cache-stripes.js +133 -0
- package/dist/src/store/sqlite/fts5-search.js +68 -0
- package/dist/src/store/sqlite/perf-samples.js +145 -16
- package/dist/src/store/sqlite/schema.js +60 -1
- package/dist/src/store/sqlite.js +1 -0
- package/dist/src/store/turns/memory-store.js +8 -0
- package/dist/src/store/turns/sqlite-store.js +14 -3
- package/dist/src/store/turns/types.js +18 -1
- package/dist/src/store/vectorIndex.js +55 -10
- package/dist/src/tiered-router/types.js +18 -0
- package/dist/src/tieredRouter.js +421 -0
- package/dist/src/vectorStore.js +8 -6
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js → AchievementTiles-DR9cLGDL.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AchievementTiles-vEo2MtE2.js.map → AchievementTiles-DR9cLGDL.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/AchievementsTab-svNUgJ1e.js +2 -0
- package/extensions/dashboard-client/dist/assets/{AchievementsTab-DjxfYrDc.js.map → AchievementsTab-svNUgJ1e.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js +2 -0
- package/extensions/dashboard-client/dist/assets/CacheTab-ASwhOMjR.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js → ConfigTab-CmmWheuW.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ConfigTab-Cm6ymbmx.js.map → ConfigTab-CmmWheuW.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js → EventsTab-CFE7jLsa.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-DXWl_YzI.js.map → EventsTab-CFE7jLsa.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/GameTab-CJAX_th_.js +2 -0
- package/extensions/dashboard-client/dist/assets/{GameTab-BLDudcO5.js.map → GameTab-CJAX_th_.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js → MaintenanceTab-P4SUsvMf.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-DLkKCztn.js.map → MaintenanceTab-P4SUsvMf.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js +2 -0
- package/extensions/dashboard-client/dist/assets/MemoryMapTab-BBiH76eF.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js → MetricsTab-CHQscixy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-Cq4u-rZF.js.map → MetricsTab-CHQscixy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/OverviewTab-DBs4DJdd.js +2 -0
- package/extensions/dashboard-client/dist/assets/{OverviewTab-D4kGvsiQ.js.map → OverviewTab-DBs4DJdd.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js +2 -0
- package/extensions/dashboard-client/dist/assets/ReposTab-DeFz76L5.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js → SessionsTab-BWNsj1OB.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DZC2-GCn.js.map → SessionsTab-BWNsj1OB.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js +2 -0
- package/extensions/dashboard-client/dist/assets/SetupTab-uS6A0xmw.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js +2 -0
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-CiqCOQuL.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js → TopicsTab-BWWQxltv.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TopicsTab-01G71hv1.js.map → TopicsTab-BWWQxltv.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js → TurnsTab-CVz4f4-o.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-DLRg0LZT.js.map → TurnsTab-CVz4f4-o.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js +2 -0
- package/extensions/dashboard-client/dist/assets/format-COjDIVGj.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/index-CUNn22iV.css +1 -0
- package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js +42 -0
- package/extensions/dashboard-client/dist/assets/index-DrktNOoT.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js +2 -0
- package/extensions/dashboard-client/dist/assets/pricing-CvE4NllQ.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js → useSSE-Bf5LOLSi.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-BBYt5UPB.js.map → useSSE-Bf5LOLSi.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +2 -2
- package/extensions/dashboard-client/src/App.tsx +28 -8
- package/extensions/dashboard-client/src/api/client.ts +29 -0
- package/extensions/dashboard-client/src/components/ActiveReposTable.tsx +21 -12
- package/extensions/dashboard-client/src/components/CacheHitRateTrendCard.tsx +100 -0
- package/extensions/dashboard-client/src/components/ProviderCacheCard.tsx +56 -0
- package/extensions/dashboard-client/src/components/SavingsByModelTable.tsx +38 -57
- package/extensions/dashboard-client/src/components/StripeDistributionCard.tsx +110 -0
- package/extensions/dashboard-client/src/components/TabBar.tsx +49 -4
- package/extensions/dashboard-client/src/main.tsx +1 -0
- package/extensions/dashboard-client/src/styles/base.css +30 -0
- package/extensions/dashboard-client/src/styles/cache.css +167 -0
- package/extensions/dashboard-client/src/tabs/CacheTab.tsx +75 -12
- package/extensions/dashboard-client/src/tabs/MemoryMapTab.tsx +440 -0
- package/extensions/dashboard-client/src/tabs/SetupTab.tsx +418 -0
- package/extensions/dashboard-client/tsconfig.json +3 -2
- package/extensions/dashboard-client/vite.config.ts +2 -0
- package/extensions/dashboard-server/api-contracts/cache-stripes.ts +49 -0
- package/extensions/dashboard-server/api-contracts/endpoints.ts +66 -3
- package/extensions/dashboard-server/api-contracts/index.ts +22 -0
- package/extensions/dashboard-server/api-contracts/memory-map.ts +50 -0
- package/extensions/dashboard-server/api-contracts/memory.ts +27 -0
- package/extensions/dashboard-server/api-contracts/multi-repo.ts +231 -231
- package/extensions/dashboard-server/api-contracts/provider-cache.ts +37 -0
- package/extensions/dashboard-server/api-contracts/setup.ts +80 -0
- package/extensions/dashboard-server/index-reader.ts +138 -121
- package/extensions/dashboard-server/routes-cache.ts +186 -75
- package/extensions/dashboard-server/routes-game.ts +3 -0
- package/extensions/dashboard-server/routes-memory-map.ts +105 -0
- package/extensions/dashboard-server/routes-memory.ts +63 -0
- package/extensions/dashboard-server/routes-repo.ts +36 -36
- package/extensions/dashboard-server/routes-setup.ts +293 -0
- package/extensions/dashboard-server/routes.ts +4 -0
- package/extensions/dashboard-server/server.ts +12 -0
- package/extensions/mega-commands.ts +211 -1
- package/extensions/mega-compact.ts +5 -0
- package/extensions/mega-config.ts +27 -0
- package/extensions/mega-events/agent-handlers.ts +20 -4
- package/extensions/mega-events/compact-handlers.ts +1 -0
- package/extensions/mega-events/context-handler.ts +53 -110
- package/extensions/mega-events/context-hwm.ts +85 -0
- package/extensions/mega-events/error-classifier.ts +15 -4
- package/extensions/mega-events/mirror-append.ts +155 -0
- package/extensions/mega-events/outage-advisor.ts +11 -5
- package/extensions/mega-events/perf-handler.ts +190 -6
- package/extensions/mega-events/recall-tail.ts +88 -0
- package/extensions/mega-events/separated-prompt.ts +329 -0
- package/extensions/mega-events/session-handlers.ts +14 -7
- package/extensions/mega-runtime/env-loader.ts +55 -0
- package/extensions/mega-runtime/helpers.ts +14 -0
- package/extensions/mega-runtime/reset-runtime.ts +6 -0
- package/extensions/mega-runtime/runtime-snapshot.ts +1 -0
- package/extensions/mega-runtime/runtime.ts +7 -0
- package/extensions/mega-runtime/snapshot.ts +6 -0
- package/extensions/mega-runtime/widget-types.ts +3 -0
- package/extensions/mega-runtime/widget.ts +5 -0
- package/package.json +5 -2
- package/src/cache-stripe-impl.ts +385 -0
- package/src/cache-stripe.ts +18 -0
- package/src/config/stopwords.ts +25 -0
- package/src/config.ts +26 -0
- package/src/embedder.ts +42 -2
- package/src/memoryGraph.ts +438 -0
- package/src/memoryStats.ts +107 -0
- package/src/monitoring.ts +35 -0
- package/src/prefix-break.ts +83 -0
- package/src/pricing.ts +2 -2
- package/src/queryExpansion.ts +206 -0
- package/src/queryReformulation/cache.ts +169 -0
- package/src/queryReformulation/rrf.ts +51 -0
- package/src/queryReformulation/tfidf.ts +79 -0
- package/src/queryReformulation/vagueness.ts +38 -0
- package/src/queryReformulation.ts +355 -0
- package/src/recallMetrics.ts +388 -0
- package/src/store/sqlite/cache-stripes.ts +196 -0
- package/src/store/sqlite/fts5-search.ts +90 -0
- package/src/store/sqlite/perf-samples.ts +218 -23
- package/src/store/sqlite/schema.ts +60 -1
- package/src/store/sqlite.ts +1 -0
- package/src/store/turns/memory-store.ts +10 -1
- package/src/store/turns/sqlite-store.ts +27 -15
- package/src/store/turns/types.ts +21 -0
- package/src/store/vectorIndex.ts +71 -11
- package/src/tiered-router/types.ts +64 -0
- package/src/tieredRouter.ts +489 -0
- package/src/vectorStore.ts +9 -5
- package/dist/extensions/conflict-scan.test.js +0 -115
- package/dist/extensions/dashboard-server/api-contracts.test.js +0 -884
- package/dist/extensions/dashboard-server/html.test.js +0 -52
- package/dist/extensions/dashboard-server/perf-server.test.js +0 -80
- package/dist/extensions/dashboard-server/routes-cache.test.js +0 -248
- package/dist/extensions/dashboard-server/server.test.js +0 -120
- package/dist/extensions/dashboard-server-s32.test.js +0 -181
- package/dist/extensions/dashboard-server.test.js +0 -339
- package/dist/extensions/mega-cache-replay.test.js +0 -400
- package/dist/extensions/mega-compact-s38.test.js +0 -1383
- package/dist/extensions/mega-compact.test.js +0 -1112
- package/dist/extensions/mega-events.test.js +0 -47
- package/dist/extensions/mega-game-cmds.test.js +0 -163
- package/dist/extensions/mega-runtime/snapshot.test.js +0 -127
- package/dist/extensions/mega-runtime/state.test.js +0 -266
- package/dist/extensions/mega-runtime/widget.test.js +0 -343
- package/dist/extensions/mega-shutdown-widget.test.js +0 -121
- package/dist/extensions/mega-teamrun.test.js +0 -156
- package/dist/extensions/mega-trim.test.js +0 -58
- package/dist/extensions/mega-turn-store.test.js +0 -68
- package/dist/src/boundary.test.js +0 -170
- package/dist/src/compact.test.js +0 -78
- package/dist/src/config/themes.test.js +0 -94
- package/dist/src/dedup/dedup.test.js +0 -41
- package/dist/src/dedup/l1.test.js +0 -50
- package/dist/src/dedup/raptor/buildHistory.test.js +0 -292
- package/dist/src/dedup/raptor/multilevel-serve.test.js +0 -229
- package/dist/src/dedup/raptor/multilevel.test.js +0 -238
- package/dist/src/dedup/raptor/promote.test.js +0 -69
- package/dist/src/dedup/raptor/raptor.test.js +0 -248
- package/dist/src/dedup/raptor/retrieval.test.js +0 -95
- package/dist/src/dedup/raptor/serve-gate.test.js +0 -298
- package/dist/src/dedup/sprint12.test.js +0 -219
- package/dist/src/dedup-engine.test.js +0 -472
- package/dist/src/driftDetection.test.js +0 -87
- package/dist/src/e2e.test.js +0 -698
- package/dist/src/engine.test.js +0 -111
- package/dist/src/extractive.test.js +0 -147
- package/dist/src/fork.test.js +0 -81
- package/dist/src/game/scoring.test.js +0 -98
- package/dist/src/httpEmbedder.test.js +0 -277
- package/dist/src/importance.test.js +0 -372
- package/dist/src/intent.test.js +0 -78
- package/dist/src/log.test.js +0 -42
- package/dist/src/mechanical-fix.test.js +0 -65
- package/dist/src/memory.test.js +0 -70
- package/dist/src/memoryConsolidate.test.js +0 -38
- package/dist/src/memoryOps.test.js +0 -129
- package/dist/src/memoryRecall.test.js +0 -171
- package/dist/src/memoryRoundtrip.test.js +0 -137
- package/dist/src/metrics/turns.test.js +0 -152
- package/dist/src/mirror/mirror.test.js +0 -185
- package/dist/src/raptor-inject-summaries.test.js +0 -162
- package/dist/src/ratio.bench.test.js +0 -897
- package/dist/src/recall.integration.test.js +0 -77
- package/dist/src/recall.test.js +0 -379
- package/dist/src/sprint14.test.js +0 -219
- package/dist/src/sprint4x-rag-verification.test.js +0 -93
- package/dist/src/store/compression.test.js +0 -139
- package/dist/src/store/memoryIndex.test.js +0 -51
- package/dist/src/store/migrate.test.js +0 -139
- package/dist/src/store/pgOpenGuard.test.js +0 -74
- package/dist/src/store/phase01.test.js +0 -81
- package/dist/src/store/phase04.test.js +0 -54
- package/dist/src/store/sprint10.test.js +0 -186
- package/dist/src/store/sqlite/game-achievements.test.js +0 -67
- package/dist/src/store/sqlite/game-scores.test.js +0 -106
- package/dist/src/store/sqlite/game-state.test.js +0 -76
- package/dist/src/store/sqlite/global-index.test.js +0 -136
- package/dist/src/store/sqlite/mechanical-fix.test.js +0 -146
- package/dist/src/store/sqlite/perf-samples.test.js +0 -146
- package/dist/src/store/sqlite/raptor.test.js +0 -106
- package/dist/src/store/sqlite/turns.test.js +0 -183
- package/dist/src/store/sqlite.cachehit.test.js +0 -55
- package/dist/src/store/sqlite.dbmaint.test.js +0 -158
- package/dist/src/store/sqlite.dbmirror.test.js +0 -184
- package/dist/src/store/turns/contract-compliance.test.js +0 -428
- package/dist/src/store/turns/memory-store.test.js +0 -9
- package/dist/src/store/turns/migrations.test.js +0 -138
- package/dist/src/store/turns/sqlite-store.test.js +0 -144
- package/dist/src/store/vectorIndex.test.js +0 -123
- package/dist/src/store.test.js +0 -161
- package/dist/src/supersede.test.js +0 -36
- package/dist/src/topics/cluster.test.js +0 -150
- package/dist/src/topics/store.test.js +0 -117
- package/dist/src/types.test.js +0 -9
- package/dist/src/vector-search-cache.test.js +0 -157
- package/dist/src/vectorStore.test.js +0 -479
- package/dist/src/wiki.test.js +0 -171
- package/extensions/conflict-scan.test.ts +0 -129
- package/extensions/dashboard-client/dist/assets/AchievementsTab-DjxfYrDc.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js +0 -2
- package/extensions/dashboard-client/dist/assets/CacheTab-Dnpv94wq.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/GameTab-BLDudcO5.js +0 -2
- package/extensions/dashboard-client/dist/assets/OverviewTab-D4kGvsiQ.js +0 -2
- package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js +0 -2
- package/extensions/dashboard-client/dist/assets/ReposTab-C0Wnrf2u.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js +0 -2
- package/extensions/dashboard-client/dist/assets/TimeSavedCard-UqljSyP-.js.map +0 -1
- package/extensions/dashboard-client/dist/assets/index-BEdKlpAB.css +0 -1
- package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js +0 -42
- package/extensions/dashboard-client/dist/assets/index-BX0bcgLu.js.map +0 -1
- package/extensions/dashboard-server/api-contracts.test.ts +0 -1065
- package/extensions/dashboard-server/html.test.ts +0 -62
- package/extensions/dashboard-server/perf-server.test.ts +0 -101
- package/extensions/dashboard-server/routes-cache.test.ts +0 -302
- package/extensions/dashboard-server/server.test.ts +0 -131
- package/extensions/dashboard-server-s32.test.ts +0 -195
- package/extensions/dashboard-server.test.ts +0 -382
- package/extensions/mega-cache-replay.test.ts +0 -526
- package/extensions/mega-compact-s38.test.ts +0 -1433
- package/extensions/mega-compact.test.ts +0 -1509
- package/extensions/mega-events.test.ts +0 -55
- package/extensions/mega-game-cmds.test.ts +0 -197
- package/extensions/mega-runtime/snapshot.test.ts +0 -139
- package/extensions/mega-runtime/state.test.ts +0 -262
- package/extensions/mega-runtime/widget.test.ts +0 -468
- package/extensions/mega-shutdown-widget.test.ts +0 -141
- package/extensions/mega-teamrun.test.ts +0 -176
- package/extensions/mega-trim.test.ts +0 -64
- package/extensions/mega-turn-store.test.ts +0 -108
- package/src/boundary.test.ts +0 -187
- package/src/compact.test.ts +0 -99
- package/src/config/themes.test.ts +0 -116
- package/src/dedup/dedup.test.ts +0 -46
- package/src/dedup/l1.test.ts +0 -57
- package/src/dedup/raptor/buildHistory.test.ts +0 -353
- package/src/dedup/raptor/multilevel-serve.test.ts +0 -273
- package/src/dedup/raptor/multilevel.test.ts +0 -325
- package/src/dedup/raptor/promote.test.ts +0 -82
- package/src/dedup/raptor/raptor.test.ts +0 -297
- package/src/dedup/raptor/retrieval.test.ts +0 -118
- package/src/dedup/raptor/serve-gate.test.ts +0 -348
- package/src/dedup/sprint12.test.ts +0 -242
- package/src/dedup-engine.test.ts +0 -670
- package/src/driftDetection.test.ts +0 -100
- package/src/e2e.test.ts +0 -843
- package/src/engine.test.ts +0 -123
- package/src/extractive.test.ts +0 -174
- package/src/fork.test.ts +0 -94
- package/src/game/scoring.test.ts +0 -103
- package/src/httpEmbedder.test.ts +0 -286
- package/src/importance.test.ts +0 -538
- package/src/intent.test.ts +0 -87
- package/src/log.test.ts +0 -47
- package/src/mechanical-fix.test.ts +0 -70
- package/src/memory.test.ts +0 -92
- package/src/memoryConsolidate.test.ts +0 -47
- package/src/memoryOps.test.ts +0 -148
- package/src/memoryRecall.test.ts +0 -194
- package/src/memoryRoundtrip.test.ts +0 -155
- package/src/metrics/turns.test.ts +0 -165
- package/src/mirror/mirror.test.ts +0 -240
- package/src/raptor-inject-summaries.test.ts +0 -228
- package/src/ratio.bench.test.ts +0 -1316
- package/src/recall.integration.test.ts +0 -96
- package/src/recall.test.ts +0 -467
- package/src/sprint14.test.ts +0 -245
- package/src/sprint4x-rag-verification.test.ts +0 -119
- package/src/store/compression.test.ts +0 -168
- package/src/store/memoryIndex.test.ts +0 -61
- package/src/store/migrate.test.ts +0 -158
- package/src/store/pgOpenGuard.test.ts +0 -89
- package/src/store/phase01.test.ts +0 -88
- package/src/store/phase04.test.ts +0 -58
- package/src/store/sprint10.test.ts +0 -214
- package/src/store/sqlite/game-achievements.test.ts +0 -80
- package/src/store/sqlite/game-scores.test.ts +0 -132
- package/src/store/sqlite/game-state.test.ts +0 -89
- package/src/store/sqlite/global-index.test.ts +0 -222
- package/src/store/sqlite/mechanical-fix.test.ts +0 -162
- package/src/store/sqlite/perf-samples.test.ts +0 -169
- package/src/store/sqlite/raptor.test.ts +0 -139
- package/src/store/sqlite/turns.test.ts +0 -218
- package/src/store/sqlite.cachehit.test.ts +0 -68
- package/src/store/sqlite.dbmaint.test.ts +0 -193
- package/src/store/sqlite.dbmirror.test.ts +0 -229
- package/src/store/turns/contract-compliance.test.ts +0 -562
- package/src/store/turns/memory-store.test.ts +0 -15
- package/src/store/turns/migrations.test.ts +0 -161
- package/src/store/turns/sqlite-store.test.ts +0 -161
- package/src/store/vectorIndex.test.ts +0 -140
- package/src/store.test.ts +0 -191
- package/src/supersede.test.ts +0 -42
- package/src/topics/cluster.test.ts +0 -176
- package/src/topics/store.test.ts +0 -132
- package/src/types.test.ts +0 -10
- package/src/vector-search-cache.test.ts +0 -190
- package/src/vectorStore.test.ts +0 -533
- package/src/wiki.test.ts +0 -217
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for mega-events extension — DB-mirror event wiring.
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
5
|
-
import assert from "node:assert/strict";
|
|
6
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { tmpdir } from "node:os";
|
|
9
|
-
import { openStore, listCheckpointEpochs, countRawTranscript } from "../src/store/sqlite.js";
|
|
10
|
-
|
|
11
|
-
function makeTmp(): string {
|
|
12
|
-
return mkdtempSync(join(tmpdir(), "mega-events-test-"));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe("mega-events: DB-mirror integration", () => {
|
|
16
|
-
let dir: string;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
dir = makeTmp();
|
|
20
|
-
// openStore creates the tables as a side effect
|
|
21
|
-
openStore(dir);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
rmSync(dir, { recursive: true, force: true });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("openStore creates checkpoint_epochs and raw_transcript tables", () => {
|
|
29
|
-
const db = openStore(dir);
|
|
30
|
-
// Should not throw — tables exist
|
|
31
|
-
const epochs = listCheckpointEpochs(db);
|
|
32
|
-
assert.ok(Array.isArray(epochs));
|
|
33
|
-
const count = countRawTranscript(db);
|
|
34
|
-
assert.equal(count, 0);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("DB-mirror flag defaults to false when env is unset", () => {
|
|
38
|
-
delete process.env.MEGACOMPACT_DB_MIRROR;
|
|
39
|
-
// Re-import to pick up env
|
|
40
|
-
// The extension checks env at load time, so just verify the env is absent
|
|
41
|
-
assert.equal(process.env.MEGACOMPACT_DB_MIRROR, undefined);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("DB-mirror flag is enabled when env is '1'", () => {
|
|
45
|
-
process.env.MEGACOMPACT_DB_MIRROR = "1";
|
|
46
|
-
assert.equal(process.env.MEGACOMPACT_DB_MIRROR, "1");
|
|
47
|
-
delete process.env.MEGACOMPACT_DB_MIRROR;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("DB-mirror flag is enabled when env is 'true'", () => {
|
|
51
|
-
process.env.MEGACOMPACT_DB_MIRROR = "true";
|
|
52
|
-
assert.equal(process.env.MEGACOMPACT_DB_MIRROR, "true");
|
|
53
|
-
delete process.env.MEGACOMPACT_DB_MIRROR;
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mega-game-cmds.test.ts — /mega-game command parsing matrix (S30).
|
|
3
|
-
* Uses an isolated state dir + a fake pi harness (mirrors mega-compact.test.ts).
|
|
4
|
-
* Pi runtime is mocked; the src/ helpers under test are pi-agnostic.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, before, after } from "node:test";
|
|
7
|
-
import assert from "node:assert/strict";
|
|
8
|
-
import { tmpdir } from "node:os";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
11
|
-
import { createRequire } from "node:module";
|
|
12
|
-
import { closeStore, getGameState } from "../src/store/sqlite.js";
|
|
13
|
-
import { THEME_IDS } from "../src/config/themes.js";
|
|
14
|
-
|
|
15
|
-
// ESM bootstrap so `require()` works in this .test.ts (mirrors
|
|
16
|
-
// mega-compact.test.ts:20-24). Needed for the dynamic `require("./mega-game-cmds.js")`
|
|
17
|
-
// that wires the command against a fake pi without binding to the real pi
|
|
18
|
-
// module at load time.
|
|
19
|
-
const require = createRequire(import.meta.url);
|
|
20
|
-
|
|
21
|
-
type Cmd = { description?: string; handler: (args: string, ctx: any) => Promise<void> };
|
|
22
|
-
|
|
23
|
-
type Harness = {
|
|
24
|
-
commands: Record<string, Cmd>;
|
|
25
|
-
notifies: string[];
|
|
26
|
-
ctx: any;
|
|
27
|
-
snapshotCalls: number[];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function makeHarness(
|
|
31
|
-
stateDir: string,
|
|
32
|
-
select?: (title: string, options: string[]) => Promise<string | undefined>,
|
|
33
|
-
snapshotSpy?: () => void,
|
|
34
|
-
): Harness {
|
|
35
|
-
const commands: Record<string, Cmd> = {};
|
|
36
|
-
const notifies: string[] = [];
|
|
37
|
-
const snapshotCalls: number[] = [];
|
|
38
|
-
const runtime = {
|
|
39
|
-
bindRepo: () => {},
|
|
40
|
-
currentStateDir: stateDir,
|
|
41
|
-
bumpGameState: () => {},
|
|
42
|
-
snapshot: () => { snapshotCalls.push(1); snapshotSpy?.(); },
|
|
43
|
-
};
|
|
44
|
-
const ctx = {
|
|
45
|
-
cwd: stateDir,
|
|
46
|
-
ui: { notify: (s: string) => notifies.push(s), ...(select ? { select } : {}) },
|
|
47
|
-
};
|
|
48
|
-
const fakePi = {
|
|
49
|
-
registerCommand: (name: string, opts: Cmd) => {
|
|
50
|
-
commands[name] = opts;
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
// Import after env is set so stateDir resolves. Dynamic import keeps the
|
|
54
|
-
// test from binding to the real pi module at load time.
|
|
55
|
-
const mod = require("./mega-game-cmds.js") as {
|
|
56
|
-
registerGameCommands: (pi: unknown, runtime: unknown) => void;
|
|
57
|
-
};
|
|
58
|
-
mod.registerGameCommands(fakePi, runtime);
|
|
59
|
-
return { commands, notifies, ctx, snapshotCalls };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
describe("/mega-compact-settings (S30; /mega-game alias)", () => {
|
|
63
|
-
let dir: string;
|
|
64
|
-
before(() => {
|
|
65
|
-
dir = mkdtempSync(join(tmpdir(), "mc-megagame-"));
|
|
66
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
67
|
-
});
|
|
68
|
-
after(() => {
|
|
69
|
-
closeStore(dir);
|
|
70
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
71
|
-
rmSync(dir, { recursive: true, force: true });
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
async function run(args: string): Promise<string[]> {
|
|
75
|
-
const h = makeHarness(dir);
|
|
76
|
-
h.notifies.length = 0;
|
|
77
|
-
await h.commands["mega-game"].handler(args, h.ctx);
|
|
78
|
-
return h.notifies;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
it("registers /mega-compact-settings as primary + /mega-game as alias", async () => {
|
|
82
|
-
const h = makeHarness(dir);
|
|
83
|
-
assert.ok(h.commands["mega-compact-settings"], "primary registered");
|
|
84
|
-
assert.ok(h.commands["mega-game"], "alias registered");
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("bare command prints current (default) state", async () => {
|
|
88
|
-
const lines = await run("");
|
|
89
|
-
assert.ok(lines.some((l) => l.includes("game mode: off")));
|
|
90
|
-
assert.ok(lines.some((l) => l.includes("transparent")));
|
|
91
|
-
assert.ok(lines.some((l) => l.includes("tui:")));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("bare command opens interactive menu (select) and toggles game mode", async () => {
|
|
95
|
-
const seq = ["Turn game mode ON", "Done"];
|
|
96
|
-
let i = 0;
|
|
97
|
-
const h = makeHarness(dir, () => Promise.resolve(seq[i++] ?? undefined));
|
|
98
|
-
h.notifies.length = 0;
|
|
99
|
-
await h.commands["mega-compact-settings"].handler("", h.ctx);
|
|
100
|
-
assert.equal(getGameState().game_mode_on, true);
|
|
101
|
-
assert.ok(h.notifies.some((l) => l.includes("game mode ON")));
|
|
102
|
-
// toggle back off via the menu
|
|
103
|
-
const seq2 = ["Turn game mode OFF", "Done"];
|
|
104
|
-
let j = 0;
|
|
105
|
-
const h2 = makeHarness(dir, () => Promise.resolve(seq2[j++] ?? undefined));
|
|
106
|
-
await h2.commands["mega-compact-settings"].handler("", h2.ctx);
|
|
107
|
-
assert.equal(getGameState().game_mode_on, false);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("bare command falls back to status print when select is unavailable", async () => {
|
|
111
|
-
// default harness has no select — mimics RPC/print mode
|
|
112
|
-
const lines = await run("");
|
|
113
|
-
assert.ok(lines.some((l) => l.includes("game mode: off")));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("menu Theme… → picks a theme and persists", async () => {
|
|
117
|
-
const seq = ["Theme…", "retro Retro Terminal", "Done"];
|
|
118
|
-
let i = 0;
|
|
119
|
-
const h = makeHarness(dir, () => Promise.resolve(seq[i++] ?? undefined));
|
|
120
|
-
h.notifies.length = 0;
|
|
121
|
-
await h.commands["mega-compact-settings"].handler("", h.ctx);
|
|
122
|
-
assert.equal(getGameState().theme, "retro");
|
|
123
|
-
assert.ok(h.notifies.some((l) => l.includes("theme → retro")));
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("menu toggle calls runtime.snapshot() so the widget refreshes live", async () => {
|
|
127
|
-
const seq = ["Turn game mode ON", "Done"];
|
|
128
|
-
let i = 0;
|
|
129
|
-
const h = makeHarness(dir, () => Promise.resolve(seq[i++] ?? undefined));
|
|
130
|
-
h.notifies.length = 0;
|
|
131
|
-
h.snapshotCalls.length = 0;
|
|
132
|
-
await h.commands["mega-compact-settings"].handler("", h.ctx);
|
|
133
|
-
assert.equal(getGameState().game_mode_on, true);
|
|
134
|
-
assert.ok(h.snapshotCalls.length >= 1, "snapshot() called so widget refreshes live");
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("on enables game mode and persists", async () => {
|
|
138
|
-
await run("on");
|
|
139
|
-
assert.equal(getGameState().game_mode_on, true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("off disables game mode and persists", async () => {
|
|
143
|
-
await run("on");
|
|
144
|
-
await run("off");
|
|
145
|
-
assert.equal(getGameState().game_mode_on, false);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("theme <id> sets a valid theme and persists", async () => {
|
|
149
|
-
await run("theme retro");
|
|
150
|
-
assert.equal(getGameState().theme, "retro");
|
|
151
|
-
await run("theme cyan-neon");
|
|
152
|
-
assert.equal(getGameState().theme, "cyan-neon");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("theme <unknown> is rejected with a usage line and does not mutate", async () => {
|
|
156
|
-
await run("theme retro");
|
|
157
|
-
const lines = await run("theme bogus");
|
|
158
|
-
assert.ok(lines.some((l) => l.includes("unknown theme")));
|
|
159
|
-
assert.equal(getGameState().theme, "retro");
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("theme next cycles to the next theme and wraps", async () => {
|
|
163
|
-
await run(`theme ${THEME_IDS[0]}`);
|
|
164
|
-
await run("theme next");
|
|
165
|
-
assert.equal(getGameState().theme, THEME_IDS[1]);
|
|
166
|
-
// cycle to the end then wrap
|
|
167
|
-
await run(`theme ${THEME_IDS[THEME_IDS.length - 1]!}`);
|
|
168
|
-
await run("theme next");
|
|
169
|
-
assert.equal(getGameState().theme, THEME_IDS[0]);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("theme (bare) lists all themes", async () => {
|
|
173
|
-
const lines = await run("theme");
|
|
174
|
-
for (const id of THEME_IDS) {
|
|
175
|
-
assert.ok(lines.some((l) => l.includes(id)), `lists ${id}`);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("tui full|minimal sets display mode and persists", async () => {
|
|
180
|
-
await run("tui minimal");
|
|
181
|
-
assert.equal(getGameState().tui_display_mode, "minimal");
|
|
182
|
-
await run("tui full");
|
|
183
|
-
assert.equal(getGameState().tui_display_mode, "full");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("tui <bad> prints usage and does not mutate", async () => {
|
|
187
|
-
await run("tui minimal");
|
|
188
|
-
const lines = await run("tui huge");
|
|
189
|
-
assert.ok(lines.some((l) => l.includes("usage")));
|
|
190
|
-
assert.equal(getGameState().tui_display_mode, "minimal");
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("unknown subcommand prints usage", async () => {
|
|
194
|
-
const lines = await run("bogus");
|
|
195
|
-
assert.ok(lines.some((l) => l.includes("usage")));
|
|
196
|
-
});
|
|
197
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* snapshot.test.ts — C.4 computeMegaSnapshot tests for providerCachePct
|
|
3
|
-
* and megaCacheFlare fields.
|
|
4
|
-
*
|
|
5
|
-
* Uses MEGACOMPACT_STATE_DIR + mkdtemp (G7). No pi runtime.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, it, before, after } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { tmpdir } from "node:os";
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
12
|
-
import { computeMegaSnapshot, type SnapshotInput } from "./snapshot.js";
|
|
13
|
-
|
|
14
|
-
function baseInput(overrides: Partial<SnapshotInput> = {}): SnapshotInput {
|
|
15
|
-
return {
|
|
16
|
-
rtTokensSaved: 1000,
|
|
17
|
-
lastCtxPercent: null,
|
|
18
|
-
lastCtxTokens: 0,
|
|
19
|
-
lastCtxWindow: 0,
|
|
20
|
-
activeAgents: 0,
|
|
21
|
-
currentTurn: 0,
|
|
22
|
-
statusKey: undefined,
|
|
23
|
-
ready: false,
|
|
24
|
-
armed: false,
|
|
25
|
-
st: {
|
|
26
|
-
totalTokenEstimate: 800,
|
|
27
|
-
originalTokens: 1200,
|
|
28
|
-
storageDedupRate: 0.12,
|
|
29
|
-
checkpointCount: 3,
|
|
30
|
-
lastCheckpointId: undefined,
|
|
31
|
-
lastSummary: undefined,
|
|
32
|
-
injectedCount: 0,
|
|
33
|
-
dedupHitRate: 0.05,
|
|
34
|
-
tokensSaved: 200,
|
|
35
|
-
dedupAttempts: 40,
|
|
36
|
-
dedupCollapsed: 5,
|
|
37
|
-
},
|
|
38
|
-
repo: {
|
|
39
|
-
tokensSaved: 5000,
|
|
40
|
-
totalTokenEstimate: 4000,
|
|
41
|
-
checkpointCount: 9,
|
|
42
|
-
sessionCount: 2,
|
|
43
|
-
originalTokens: 6000,
|
|
44
|
-
dedupAttempts: 100,
|
|
45
|
-
dedupCollapsed: 30,
|
|
46
|
-
storageDedupRate: 0.3,
|
|
47
|
-
},
|
|
48
|
-
pressureBand: "low",
|
|
49
|
-
configTier: "default",
|
|
50
|
-
modelSnap: undefined,
|
|
51
|
-
lastCompactAt: null,
|
|
52
|
-
embedderName: () => "Trigram",
|
|
53
|
-
driftStatus: () => "ok" as const,
|
|
54
|
-
getCachedGameState: () => ({
|
|
55
|
-
game_mode_on: false,
|
|
56
|
-
theme: "transparent",
|
|
57
|
-
tui_display_mode: "full",
|
|
58
|
-
}),
|
|
59
|
-
getTurnLevel: () => 1,
|
|
60
|
-
providerCachePct: 56.2,
|
|
61
|
-
megaCacheFlare: false,
|
|
62
|
-
megaCacheFlarePct: 0,
|
|
63
|
-
levelUpFlare: false,
|
|
64
|
-
achievementFlare: false,
|
|
65
|
-
achievementFlareTitles: [],
|
|
66
|
-
activeEffect: null,
|
|
67
|
-
lastActivityAt: Date.now(),
|
|
68
|
-
ticker: [],
|
|
69
|
-
lastWhy: undefined,
|
|
70
|
-
tierTrace: undefined,
|
|
71
|
-
pulsing: false,
|
|
72
|
-
...overrides,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
describe("computeMegaSnapshot (C.4)", () => {
|
|
77
|
-
let dir: string;
|
|
78
|
-
before(() => {
|
|
79
|
-
dir = mkdtempSync(join(tmpdir(), "mc-snap-"));
|
|
80
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
81
|
-
});
|
|
82
|
-
after(() => {
|
|
83
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
84
|
-
rmSync(dir, { recursive: true, force: true });
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// ── C.1: providerCachePct flows into cachePct ─────────────────────────
|
|
88
|
-
it("cachePct equals providerCachePct (not dedup hit rate)", () => {
|
|
89
|
-
const res = computeMegaSnapshot(baseInput({ providerCachePct: 56.2 }));
|
|
90
|
-
assert.equal(res.widgetData.cachePct, 56.2, "cachePct is providerCachePct");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("cachePct is 0 when providerCachePct is 0", () => {
|
|
94
|
-
const res = computeMegaSnapshot(baseInput({ providerCachePct: 0 }));
|
|
95
|
-
assert.equal(res.widgetData.cachePct, 0, "cachePct is 0");
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("cachePct is independent of dedup hit rate", () => {
|
|
99
|
-
const res = computeMegaSnapshot(
|
|
100
|
-
baseInput({
|
|
101
|
-
providerCachePct: 12.5,
|
|
102
|
-
st: {
|
|
103
|
-
totalTokenEstimate: 99999,
|
|
104
|
-
originalTokens: 99999,
|
|
105
|
-
storageDedupRate: 0.99,
|
|
106
|
-
checkpointCount: 1,
|
|
107
|
-
lastCheckpointId: undefined,
|
|
108
|
-
lastSummary: undefined,
|
|
109
|
-
injectedCount: 0,
|
|
110
|
-
dedupHitRate: 0.05,
|
|
111
|
-
tokensSaved: 200,
|
|
112
|
-
dedupAttempts: 40,
|
|
113
|
-
dedupCollapsed: 5,
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
);
|
|
117
|
-
assert.equal(res.widgetData.cachePct, 12.5, "cachePct ignores dedup");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// ── megaCacheFlare fields pass through ────────────────────────────────
|
|
121
|
-
it("megaCacheFlare + megaCacheFlarePct pass through to widgetData", () => {
|
|
122
|
-
const res = computeMegaSnapshot(
|
|
123
|
-
baseInput({ megaCacheFlare: true, megaCacheFlarePct: 287 }),
|
|
124
|
-
);
|
|
125
|
-
assert.equal(res.widgetData.megaCacheFlare, true);
|
|
126
|
-
assert.equal(res.widgetData.megaCacheFlarePct, 287);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("megaCacheFlare is false by default", () => {
|
|
130
|
-
const res = computeMegaSnapshot(baseInput());
|
|
131
|
-
assert.equal(res.widgetData.megaCacheFlare, false);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// ── level pass-through ────────────────────────────────────────────────
|
|
135
|
-
it("level flows from getTurnLevel", () => {
|
|
136
|
-
const res = computeMegaSnapshot(baseInput({ getTurnLevel: () => 42 }));
|
|
137
|
-
assert.equal(res.curLevel, 42);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* state.test.ts — S31 MegaRuntime game-state cache round-trip.
|
|
3
|
-
*
|
|
4
|
-
* getCachedGameState() lazily reads the game_state row; bumpGameState()
|
|
5
|
-
* evicts so the next read re-queries. Uses MEGACOMPACT_STATE_DIR + mkdtemp
|
|
6
|
-
* (G7). A minimal MegaRuntime is constructed directly (no pi runtime).
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, after } from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
13
|
-
import { createRequire } from "node:module";
|
|
14
|
-
import { execSync } from "node:child_process";
|
|
15
|
-
import { closeStore, getGameState, setGameState } from "../../src/store/sqlite.js";
|
|
16
|
-
import { DEFAULT_GAME_STATE } from "../../src/store/sqlite/game-state.js";
|
|
17
|
-
|
|
18
|
-
const require = createRequire(import.meta.url);
|
|
19
|
-
// Require the compiled JS (build output) so ESM import of pi-tui etc. resolves.
|
|
20
|
-
const { MegaRuntime } = require("./state.js") as {
|
|
21
|
-
MegaRuntime: new (config: any) => any;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/** Minimal MegaConfig — enough fields for the constructor; the snapshot path
|
|
25
|
-
* isn't exercised here, only getCachedGameState/bumpGameState. */
|
|
26
|
-
function minimalConfig(stateDir: string): any {
|
|
27
|
-
return {
|
|
28
|
-
tier: "custom",
|
|
29
|
-
tierPct: null,
|
|
30
|
-
thresholdTokens: 100_000,
|
|
31
|
-
stateDir,
|
|
32
|
-
fastGatePct: 70,
|
|
33
|
-
anchorUserMessages: 3,
|
|
34
|
-
preserveRecent: 4,
|
|
35
|
-
preserveRecentMin: 2,
|
|
36
|
-
auto: false,
|
|
37
|
-
autoInline: false,
|
|
38
|
-
autoContinueLengthStop: false,
|
|
39
|
-
autoPctTrigger: null,
|
|
40
|
-
dedupSim: 0.9,
|
|
41
|
-
raptorEnabled: false,
|
|
42
|
-
legacyDurableTrim: false,
|
|
43
|
-
dbMirror: false,
|
|
44
|
-
crossRepoEnabled: false,
|
|
45
|
-
crossRepoCosine: 0.9,
|
|
46
|
-
memoryAutoReview: false,
|
|
47
|
-
memoryReviewInterval: 10,
|
|
48
|
-
recallMaxTokens: 1500,
|
|
49
|
-
windowDedupe: false,
|
|
50
|
-
debug: false,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Fresh isolated state dir per test — the game_state row is global and
|
|
55
|
-
* persists across cases in a shared dir, so each case gets its own mkdtemp to
|
|
56
|
-
* avoid cross-test contamination. */
|
|
57
|
-
function freshDir(): string {
|
|
58
|
-
return mkdtempSync(join(tmpdir(), "mc-state-"));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
describe("MegaRuntime setEffect lifecycle (v0.8.3)", () => {
|
|
62
|
-
const dirs: string[] = [];
|
|
63
|
-
after(() => {
|
|
64
|
-
for (const d of dirs) {
|
|
65
|
-
try { closeStore(d); } catch { /* */ }
|
|
66
|
-
}
|
|
67
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
68
|
-
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("activeEffect starts null and setEffect arms it with startedAt ~now", () => {
|
|
72
|
-
const dir = freshDir(); dirs.push(dir);
|
|
73
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
74
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
75
|
-
assert.equal(rt.activeEffect, null, "idle on construction");
|
|
76
|
-
const before = Date.now();
|
|
77
|
-
rt.setEffect("pulse", "accent", 2000);
|
|
78
|
-
const after = Date.now();
|
|
79
|
-
assert.equal(rt.activeEffect.type, "pulse");
|
|
80
|
-
assert.equal(rt.activeEffect.role, "accent");
|
|
81
|
-
assert.equal(rt.activeEffect.durationMs, 2000);
|
|
82
|
-
assert.ok(
|
|
83
|
-
rt.activeEffect.startedAt >= before && rt.activeEffect.startedAt <= after,
|
|
84
|
-
"startedAt within the call window",
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("setEffect replaces an in-flight effect (last call wins)", () => {
|
|
89
|
-
const dir = freshDir(); dirs.push(dir);
|
|
90
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
91
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
92
|
-
rt.setEffect("pulse", "accent", 2000);
|
|
93
|
-
const first = rt.activeEffect;
|
|
94
|
-
rt.setEffect("flash", "mega", 1200);
|
|
95
|
-
assert.notEqual(rt.activeEffect, first, "a fresh object replaced the prior");
|
|
96
|
-
assert.equal(rt.activeEffect.type, "flash");
|
|
97
|
-
assert.equal(rt.activeEffect.role, "mega");
|
|
98
|
-
assert.equal(rt.activeEffect.durationMs, 1200);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("a backdated effect is recognized as expired by the snapshot predicate", () => {
|
|
102
|
-
const dir = freshDir(); dirs.push(dir);
|
|
103
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
104
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
105
|
-
rt.setEffect("pulse", "accent", 2000);
|
|
106
|
-
// Backdate startedAt past the duration window (no snapshot/ctx needed —
|
|
107
|
-
// this mirrors the exact predicate snapshot() runs after the flare consume).
|
|
108
|
-
rt.activeEffect.startedAt = Date.now() - 3000;
|
|
109
|
-
const expired =
|
|
110
|
-
!!rt.activeEffect &&
|
|
111
|
-
Date.now() - rt.activeEffect.startedAt >= rt.activeEffect.durationMs;
|
|
112
|
-
assert.ok(expired, "backdated effect satisfies the expiry predicate");
|
|
113
|
-
// Clearing mirrors the snapshot() bookkeeping branch:
|
|
114
|
-
if (expired) rt.activeEffect = null;
|
|
115
|
-
assert.equal(rt.activeEffect, null, "cleared once expired");
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("MegaRuntime pushTicker dedupe (P1)", () => {
|
|
120
|
-
const dirs: string[] = [];
|
|
121
|
-
after(() => {
|
|
122
|
-
for (const d of dirs) {
|
|
123
|
-
try { closeStore(d); } catch { /* */ }
|
|
124
|
-
}
|
|
125
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
126
|
-
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("pushTicker skips consecutive identical entries (keeps ring at capacity for variety)", () => {
|
|
130
|
-
const dir = freshDir(); dirs.push(dir);
|
|
131
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
132
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
133
|
-
rt.pushTicker("compact");
|
|
134
|
-
rt.pushTicker("compact"); // dedup — skipped
|
|
135
|
-
rt.pushTicker("compact"); // dedup — skipped
|
|
136
|
-
rt.pushTicker("recall");
|
|
137
|
-
assert.equal(rt.ticker.length, 2, "only 2 unique entries kept");
|
|
138
|
-
assert.equal(rt.ticker[0].text, "compact");
|
|
139
|
-
assert.equal(rt.ticker[1].text, "recall");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("pushTicker keeps distinct entries and respects TICKER_MAX", () => {
|
|
143
|
-
const dir = freshDir(); dirs.push(dir);
|
|
144
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
145
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
146
|
-
for (let i = 0; i < rt.TICKER_MAX + 3; i++) rt.pushTicker(`t${i}`);
|
|
147
|
-
assert.equal(rt.ticker.length, rt.TICKER_MAX, "capped at TICKER_MAX");
|
|
148
|
-
assert.equal(rt.ticker[rt.TICKER_MAX - 1].text, `t${rt.TICKER_MAX + 2}`);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe("MegaRuntime game-state cache (S31)", () => {
|
|
153
|
-
const dirs: string[] = [];
|
|
154
|
-
after(() => {
|
|
155
|
-
for (const d of dirs) {
|
|
156
|
-
try { closeStore(d); } catch { /* */ }
|
|
157
|
-
}
|
|
158
|
-
delete process.env.MEGACOMPACT_STATE_DIR;
|
|
159
|
-
for (const d of dirs) rmSync(d, { recursive: true, force: true });
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("getCachedGameState returns defaults on a fresh install", () => {
|
|
163
|
-
const dir = freshDir(); dirs.push(dir);
|
|
164
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
165
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
166
|
-
const gs = rt.getCachedGameState();
|
|
167
|
-
assert.deepEqual(gs, { ...DEFAULT_GAME_STATE });
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("getCachedGameState memoizes (same ref across calls)", () => {
|
|
171
|
-
const dir = freshDir(); dirs.push(dir);
|
|
172
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
173
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
174
|
-
const a = rt.getCachedGameState();
|
|
175
|
-
const b = rt.getCachedGameState();
|
|
176
|
-
assert.equal(a, b, "memoized — same object ref");
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it("bumpGameState evicts so the next read reflects a setGameState write", () => {
|
|
180
|
-
const dir = freshDir(); dirs.push(dir);
|
|
181
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
182
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
183
|
-
const before = rt.getCachedGameState();
|
|
184
|
-
assert.equal(before.game_mode_on, false);
|
|
185
|
-
|
|
186
|
-
// Write out-of-band (as /mega-game would).
|
|
187
|
-
setGameState({ game_mode_on: true, theme: "retro", tui_display_mode: "minimal" }, dir);
|
|
188
|
-
|
|
189
|
-
// Without bump, the stale memo is returned.
|
|
190
|
-
const stale = rt.getCachedGameState();
|
|
191
|
-
assert.equal(stale.game_mode_on, false, "stale cache before bump");
|
|
192
|
-
|
|
193
|
-
// After bump, the next read re-queries and reflects the write.
|
|
194
|
-
rt.bumpGameState();
|
|
195
|
-
const fresh = rt.getCachedGameState();
|
|
196
|
-
assert.equal(fresh.game_mode_on, true);
|
|
197
|
-
assert.equal(fresh.theme, "retro");
|
|
198
|
-
assert.equal(fresh.tui_display_mode, "minimal");
|
|
199
|
-
// And matches the authoritative getGameState read.
|
|
200
|
-
assert.deepEqual(fresh, getGameState(dir));
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("bumpGameState is idempotent (safe to call when cache is empty)", () => {
|
|
204
|
-
const dir = freshDir(); dirs.push(dir);
|
|
205
|
-
process.env.MEGACOMPACT_STATE_DIR = dir;
|
|
206
|
-
const rt = new MegaRuntime(minimalConfig(dir));
|
|
207
|
-
rt.bumpGameState(); // no cached state yet — must not throw
|
|
208
|
-
const gs = rt.getCachedGameState();
|
|
209
|
-
assert.deepEqual(gs, { ...DEFAULT_GAME_STATE });
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("bindRepo evicts cachedGameState so a repo switch reflects the new repo's game_state", () => {
|
|
213
|
-
// Two fresh git repos A and B simulate a real repo switch. Each holds its
|
|
214
|
-
// own per-repo state dir at <root>/.pi/mega-compact (what repoStateDir
|
|
215
|
-
// returns for a git cwd), and each holds its own game_state row, so a repo
|
|
216
|
-
// switch (bindRepo) must evict the cached memo or the widget shows A's
|
|
217
|
-
// theme/mode/toggle after moving to B. Uses MEGACOMPACT_STATE_DIR + mkdtemp
|
|
218
|
-
// + closeStore (G7); the global state dir stays separate.
|
|
219
|
-
const globalDir = freshDir(); dirs.push(globalDir);
|
|
220
|
-
const repoA = freshDir(); dirs.push(repoA);
|
|
221
|
-
const repoB = freshDir(); dirs.push(repoB);
|
|
222
|
-
const stateA = join(repoA, ".pi", "mega-compact");
|
|
223
|
-
const stateB = join(repoB, ".pi", "mega-compact");
|
|
224
|
-
|
|
225
|
-
// Make A and B real git roots so resolveRepoRoot(cwd) returns the root and
|
|
226
|
-
// repoStateDir produces <root>/.pi/mega-compact (the per-repo store).
|
|
227
|
-
execSync("git init -q", { cwd: repoA });
|
|
228
|
-
execSync("git init -q", { cwd: repoB });
|
|
229
|
-
|
|
230
|
-
// Seed A and B with distinct game_state rows in their per-repo dirs.
|
|
231
|
-
setGameState({ game_mode_on: true, theme: "retro", tui_display_mode: "minimal" }, stateA);
|
|
232
|
-
setGameState({ game_mode_on: false, theme: "cyan-neon", tui_display_mode: "full" }, stateB);
|
|
233
|
-
|
|
234
|
-
// Construct the runtime against the GLOBAL dir (the non-git fallback so a
|
|
235
|
-
// real bindRepo switch occurs once we point it at a git root).
|
|
236
|
-
process.env.MEGACOMPACT_STATE_DIR = globalDir;
|
|
237
|
-
const rt = new MegaRuntime(minimalConfig(globalDir));
|
|
238
|
-
|
|
239
|
-
// Point the runtime at repo A and prime the cache.
|
|
240
|
-
rt.bindRepo(repoA);
|
|
241
|
-
assert.equal(rt.currentStateDir, stateA, "bindRepo(A) switched to A's per-repo dir");
|
|
242
|
-
const a = rt.getCachedGameState();
|
|
243
|
-
assert.equal(a.game_mode_on, true, "A: game_mode_on primed");
|
|
244
|
-
assert.equal(a.theme, "retro", "A: theme primed");
|
|
245
|
-
assert.equal(a.tui_display_mode, "minimal", "A: tui_display_mode primed");
|
|
246
|
-
|
|
247
|
-
// Switch to repo B: bindRepo must evict cachedGameState so the next read
|
|
248
|
-
// re-queries B's row instead of returning A's stale memo.
|
|
249
|
-
rt.bindRepo(repoB);
|
|
250
|
-
assert.equal(rt.currentStateDir, stateB, "bindRepo(B) switched to B's per-repo dir");
|
|
251
|
-
const b = rt.getCachedGameState();
|
|
252
|
-
assert.equal(b.game_mode_on, false, "B: game_mode_on after switch (not A's stale true)");
|
|
253
|
-
assert.equal(b.theme, "cyan-neon", "B: theme after switch (not A's stale retro)");
|
|
254
|
-
assert.equal(b.tui_display_mode, "full", "B: tui_display_mode after switch (not A's stale minimal)");
|
|
255
|
-
assert.deepEqual(b, getGameState(stateB), "B matches authoritative getGameState read");
|
|
256
|
-
|
|
257
|
-
// Cleanup the per-repo DB handles.
|
|
258
|
-
try { closeStore(globalDir); } catch { /* */ }
|
|
259
|
-
try { closeStore(stateA); } catch { /* */ }
|
|
260
|
-
try { closeStore(stateB); } catch { /* */ }
|
|
261
|
-
});
|
|
262
|
-
});
|