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
package/src/vectorStore.test.ts
DELETED
|
@@ -1,533 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
6
|
-
import { VectorStore, computeRegionHash, vectorStats, vectorDedupe, vectorWasInjected, vectorMarkInjected, vectorList, vectorTopSimilar, vectorRepoStats, vectorSearch } from "./vectorStore.js";
|
|
7
|
-
import {
|
|
8
|
-
TrigramEmbedder,
|
|
9
|
-
cosineSimilarity,
|
|
10
|
-
l2Normalize,
|
|
11
|
-
defaultEmbedder,
|
|
12
|
-
} from "./embedder.js";
|
|
13
|
-
import { normalizeSessionId, decompressSmart } from "./store.js";
|
|
14
|
-
|
|
15
|
-
const baseTmp = mkdtempSync(join(tmpdir(), "mc-test-"));
|
|
16
|
-
|
|
17
|
-
// Each store() gets its own isolated state dir passed explicitly (no global
|
|
18
|
-
// env var) so parallel/concurrent tests never share on-disk checkpoints.
|
|
19
|
-
let counter = 0;
|
|
20
|
-
function store(opts: { dedupSim?: number } = {}) {
|
|
21
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
22
|
-
return new VectorStore({ dedupSim: opts.dedupSim ?? 0.9, stateDir: dir });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test("cleanup temp dir", () => {
|
|
26
|
-
assert.ok(baseTmp.startsWith(tmpdir()));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("embedder is deterministic and normalized", () => {
|
|
30
|
-
const e = defaultEmbedder();
|
|
31
|
-
const a = e.embed("compact the session context");
|
|
32
|
-
const b = e.embed("compact the session context");
|
|
33
|
-
assert.deepEqual(a, b);
|
|
34
|
-
const n = l2Normalize(a);
|
|
35
|
-
const mag = Math.sqrt(n.reduce((s, x) => s + x * x, 0));
|
|
36
|
-
assert.ok(Math.abs(mag - 1) < 1e-9);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("cosine similarity is 1 for identical, <1 for different", () => {
|
|
40
|
-
const e = new TrigramEmbedder();
|
|
41
|
-
const a = e.embed("read src/server.ts and fix the bug");
|
|
42
|
-
const b = e.embed("read src/server.ts and fix the bug");
|
|
43
|
-
const c = e.embed("play a song on the guitar");
|
|
44
|
-
assert.ok(Math.abs(cosineSimilarity(a, b) - 1) < 1e-9);
|
|
45
|
-
assert.ok(cosineSimilarity(a, c) < 1);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("add then search returns the planted checkpoint top-1", () => {
|
|
49
|
-
const s = store();
|
|
50
|
-
s.add({
|
|
51
|
-
sessionId: "sess_abc",
|
|
52
|
-
summary: "Investigated src/compact.ts and added truncation.",
|
|
53
|
-
regionText:
|
|
54
|
-
"user asked to investigate src/compact.ts assistant added truncate helper",
|
|
55
|
-
keyDecisions: ["add truncate helper"],
|
|
56
|
-
filesModified: ["src/compact.ts"],
|
|
57
|
-
tokenEstimate: 1200,
|
|
58
|
-
timestamp: 1000,
|
|
59
|
-
});
|
|
60
|
-
const hits = vectorSearch(s, "sess_abc", "src/compact.ts truncate helper", 3);
|
|
61
|
-
assert.equal(hits.length, 1);
|
|
62
|
-
assert.ok(hits[0].score > 0.5);
|
|
63
|
-
assert.equal(hits[0].checkpoint.summary.includes("src/compact.ts"), true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("dedup by regionHash: identical region is not double-stored", () => {
|
|
67
|
-
const s = store();
|
|
68
|
-
const region = "the same conversation region text";
|
|
69
|
-
const r1 = s.add({
|
|
70
|
-
sessionId: "sess_dup",
|
|
71
|
-
summary: "first",
|
|
72
|
-
regionText: region,
|
|
73
|
-
timestamp: 1,
|
|
74
|
-
});
|
|
75
|
-
const r2 = s.add({
|
|
76
|
-
sessionId: "sess_dup",
|
|
77
|
-
summary: "second",
|
|
78
|
-
regionText: region,
|
|
79
|
-
timestamp: 2,
|
|
80
|
-
});
|
|
81
|
-
assert.equal(r1.deduped, false);
|
|
82
|
-
assert.equal(r2.deduped, true);
|
|
83
|
-
assert.equal(r1.checkpoint.checkpointId, r2.checkpoint.checkpointId);
|
|
84
|
-
assert.equal(vectorSearch(s, "sess_dup", "anything", 10).length, 1);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("dedup cascade: summaryHash catches same-topic incremental compactions", () => {
|
|
88
|
-
const s = store();
|
|
89
|
-
const r1 = s.add({
|
|
90
|
-
sessionId: "sess_sh",
|
|
91
|
-
summary: "step 1",
|
|
92
|
-
topicSummary: "User working on auth module refactor in src/auth.ts.",
|
|
93
|
-
regionText: "first region text for step 1",
|
|
94
|
-
timestamp: 100,
|
|
95
|
-
});
|
|
96
|
-
// Different regionText (incremental compaction adds messages), same topicSummary
|
|
97
|
-
const r2 = s.add({
|
|
98
|
-
sessionId: "sess_sh",
|
|
99
|
-
summary: "step 2",
|
|
100
|
-
topicSummary: "User working on auth module refactor in src/auth.ts.",
|
|
101
|
-
regionText: "second region text for step 2 with additional messages",
|
|
102
|
-
timestamp: 200,
|
|
103
|
-
});
|
|
104
|
-
assert.equal(r1.deduped, false);
|
|
105
|
-
assert.equal(r2.deduped, true);
|
|
106
|
-
assert.equal(r2.reason, "summaryHash");
|
|
107
|
-
assert.equal(r1.checkpoint.checkpointId, r2.checkpoint.checkpointId);
|
|
108
|
-
// Timestamp should be updated to the newer one
|
|
109
|
-
assert.equal(r2.checkpoint.timestamp, 200);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("dedup cascade: summaryHash dedup still stores only one checkpoint", () => {
|
|
113
|
-
const s = store();
|
|
114
|
-
const summary = "same summary for both adds";
|
|
115
|
-
const ts = "some topic summary that is identical";
|
|
116
|
-
s.add({ sessionId: "sess_sh2", summary, topicSummary: ts, regionText: "region a", timestamp: 1 });
|
|
117
|
-
s.add({ sessionId: "sess_sh2", summary, topicSummary: ts, regionText: "region b", timestamp: 2 });
|
|
118
|
-
assert.equal(vectorStats(s,"sess_sh2").checkpointCount, 1);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("dedupe() sentinel returns true for a stored region", () => {
|
|
122
|
-
const s = store();
|
|
123
|
-
const region = "region for sentinel test";
|
|
124
|
-
const hash = computeRegionHash(region);
|
|
125
|
-
s.add({
|
|
126
|
-
sessionId: "sess_sent",
|
|
127
|
-
summary: "x",
|
|
128
|
-
regionText: region,
|
|
129
|
-
timestamp: 1,
|
|
130
|
-
});
|
|
131
|
-
assert.equal(vectorDedupe(s,"sess_sent", hash), true);
|
|
132
|
-
assert.equal(vectorDedupe(s,"sess_sent", "deadbeef"), false);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test("near-duplicate collapse keeps only the top of a near-identical pair", () => {
|
|
136
|
-
const s = store();
|
|
137
|
-
s.add({
|
|
138
|
-
sessionId: "sess_nd",
|
|
139
|
-
summary: "alpha",
|
|
140
|
-
regionText:
|
|
141
|
-
"user investigated src/compact.ts and added a truncate helper for summaries",
|
|
142
|
-
timestamp: 1,
|
|
143
|
-
});
|
|
144
|
-
s.add({
|
|
145
|
-
sessionId: "sess_nd",
|
|
146
|
-
summary: "beta",
|
|
147
|
-
regionText:
|
|
148
|
-
"user investigated src/compact.ts and added a truncate helper for the summaries",
|
|
149
|
-
timestamp: 2,
|
|
150
|
-
});
|
|
151
|
-
const hits = vectorSearch(s,
|
|
152
|
-
"sess_nd",
|
|
153
|
-
"user investigated src/compact.ts and added a truncate helper for summaries",
|
|
154
|
-
5,
|
|
155
|
-
);
|
|
156
|
-
assert.equal(hits.length, 1);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test("markInjected / wasInjected track injection", () => {
|
|
160
|
-
const s = store();
|
|
161
|
-
const r = s.add({
|
|
162
|
-
sessionId: "sess_inj",
|
|
163
|
-
summary: "y",
|
|
164
|
-
regionText: "inject region",
|
|
165
|
-
timestamp: 1,
|
|
166
|
-
});
|
|
167
|
-
assert.equal(vectorWasInjected(s,"sess_inj", r.checkpoint.checkpointId), false);
|
|
168
|
-
vectorMarkInjected(s,"sess_inj", r.checkpoint.checkpointId);
|
|
169
|
-
assert.equal(vectorWasInjected(s,"sess_inj", r.checkpoint.checkpointId), true);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test("normalizeSessionId handles null, prefixed, and uuid forms", () => {
|
|
173
|
-
assert.match(normalizeSessionId("sess_abc"), /^sess_/);
|
|
174
|
-
assert.equal(normalizeSessionId("sess_abc"), "sess_abc");
|
|
175
|
-
assert.match(
|
|
176
|
-
normalizeSessionId("550e8400-e29b-41d4-a716-446655440000"),
|
|
177
|
-
/^sess_[0-9a-f]{16}$/,
|
|
178
|
-
);
|
|
179
|
-
assert.match(normalizeSessionId(undefined), /^sess_[0-9a-f]{16}$/);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test("nextCheckpointId is sequential per session", () => {
|
|
183
|
-
const s = store();
|
|
184
|
-
const a = s.add({
|
|
185
|
-
sessionId: "sess_seq",
|
|
186
|
-
summary: "1",
|
|
187
|
-
regionText: "r1",
|
|
188
|
-
timestamp: 1,
|
|
189
|
-
});
|
|
190
|
-
const b = s.add({
|
|
191
|
-
sessionId: "sess_seq",
|
|
192
|
-
summary: "2",
|
|
193
|
-
regionText: "r2",
|
|
194
|
-
timestamp: 2,
|
|
195
|
-
});
|
|
196
|
-
assert.equal(a.checkpoint.checkpointId, "chkpt_001");
|
|
197
|
-
assert.equal(b.checkpoint.checkpointId, "chkpt_002");
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
test("checkpoints survive a fresh store instance (on-disk)", () => {
|
|
201
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
202
|
-
const s1 = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
203
|
-
s1.add({
|
|
204
|
-
sessionId: "sess_persist",
|
|
205
|
-
summary: "persisted",
|
|
206
|
-
regionText: "persist region text",
|
|
207
|
-
timestamp: 1,
|
|
208
|
-
});
|
|
209
|
-
const s2 = new VectorStore({ dedupSim: 0.9, stateDir: dir }); // new instance, same disk state
|
|
210
|
-
const hits = vectorSearch(s2, "sess_persist", "persist region text", 3);
|
|
211
|
-
assert.equal(hits.length, 1);
|
|
212
|
-
assert.equal(hits[0].checkpoint.summary, "persisted");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("corrupt checkpoint file falls back to empty (no throw)", () => {
|
|
216
|
-
const dir = join(baseTmp, `run-${counter++}`);
|
|
217
|
-
mkdirSync(dir, { recursive: true });
|
|
218
|
-
const file = join(dir, "sess_corrupt.checkpoints.json.gz");
|
|
219
|
-
writeFileSync(file, Buffer.from("not a gzip"));
|
|
220
|
-
const s = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
221
|
-
assert.equal(vectorSearch(s, "sess_corrupt", "q", 3).length, 0);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test("stats reports counts, last checkpoint, and dedup rate", () => {
|
|
225
|
-
const s = store();
|
|
226
|
-
s.add({
|
|
227
|
-
sessionId: "sess_stats",
|
|
228
|
-
summary: "alpha",
|
|
229
|
-
regionText: "region alpha text",
|
|
230
|
-
tokenEstimate: 500,
|
|
231
|
-
timestamp: 1,
|
|
232
|
-
});
|
|
233
|
-
s.add({
|
|
234
|
-
sessionId: "sess_stats",
|
|
235
|
-
summary: "beta",
|
|
236
|
-
regionText: "region beta text",
|
|
237
|
-
tokenEstimate: 700,
|
|
238
|
-
timestamp: 2,
|
|
239
|
-
});
|
|
240
|
-
const st1 = vectorStats(s,"sess_stats");
|
|
241
|
-
assert.equal(st1.checkpointCount, 2);
|
|
242
|
-
assert.equal(st1.lastCheckpointId, "chkpt_002");
|
|
243
|
-
assert.equal(st1.totalTokenEstimate, 1200);
|
|
244
|
-
assert.equal(st1.injectedCount, 0);
|
|
245
|
-
assert.equal(st1.dedupHitRate, 0);
|
|
246
|
-
|
|
247
|
-
vectorMarkInjected(s,"sess_stats", "chkpt_001");
|
|
248
|
-
const st2 = vectorStats(s,"sess_stats");
|
|
249
|
-
assert.equal(st2.injectedCount, 1);
|
|
250
|
-
assert.ok(Math.abs(st2.dedupHitRate - 0.5) < 1e-9);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("tokensSaved = original − stored per session; deduped add saves the whole region", () => {
|
|
254
|
-
const s = store();
|
|
255
|
-
// Two genuinely new checkpoints. saved = original − stored.
|
|
256
|
-
// cp1: orig 2000, stored 500 → saved 1500
|
|
257
|
-
// cp2: orig 3000, stored 700 → saved 2300
|
|
258
|
-
s.add({ sessionId: "sess_saved", summary: "alpha", regionText: "region alpha text", tokenEstimate: 500, originalTokenEstimate: 2000, timestamp: 1 });
|
|
259
|
-
s.add({ sessionId: "sess_saved", summary: "beta", regionText: "region beta text", tokenEstimate: 700, originalTokenEstimate: 3000, timestamp: 2 });
|
|
260
|
-
const st = vectorStats(s,"sess_saved");
|
|
261
|
-
assert.equal(st.totalTokenEstimate, 1200, "Σ stored summaries");
|
|
262
|
-
assert.equal(st.originalTokens, 5000, "Σ original region tokens");
|
|
263
|
-
assert.equal(st.tokensSaved, 3800, "per-session saved = Σ(original − stored) = 1500 + 2300");
|
|
264
|
-
assert.equal(st.dedupCollapsed, 0);
|
|
265
|
-
assert.equal(st.dedupAttempts, 2);
|
|
266
|
-
|
|
267
|
-
// A third add that dedups onto an existing region: whole original region (2000)
|
|
268
|
-
// is discarded (nothing new stored) → repo saved grows by the full original,
|
|
269
|
-
// dedupCollapsed bumps, and no new checkpoint row is created.
|
|
270
|
-
const deduped = s.add({ sessionId: "sess_saved", summary: "alpha", regionText: "region alpha text", tokenEstimate: 500, originalTokenEstimate: 2000, timestamp: 3 });
|
|
271
|
-
assert.ok(deduped.deduped, "identical region should dedup");
|
|
272
|
-
const st3 = vectorStats(s,"sess_saved");
|
|
273
|
-
// Per-session DB sum only covers stored rows (deduped adds create no row), so
|
|
274
|
-
// the per-session figure is unchanged; the deduped save lands in the repo meta.
|
|
275
|
-
assert.equal(st3.tokensSaved, 3800, "per-session DB sum unchanged by deduped add");
|
|
276
|
-
assert.equal(st3.dedupCollapsed, 1, "deduped collapse counted");
|
|
277
|
-
assert.equal(st3.dedupAttempts, 3);
|
|
278
|
-
// Repo cumulative counter DID capture the deduped region's full original size.
|
|
279
|
-
assert.equal(vectorRepoStats(s).tokensSaved, 3800 + 2000, "repo saved includes deduped original");
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test("repoStats aggregates every session + counts deduped original tokens", () => {
|
|
283
|
-
const dir = join(baseTmp, `repo-${counter++}`);
|
|
284
|
-
const a = new VectorStore({ dedupSim: 0.9, stateDir: dir });
|
|
285
|
-
const b = new VectorStore({ dedupSim: 0.9, stateDir: dir }); // same disk store, diff instance
|
|
286
|
-
a.add({ sessionId: "sess_a", summary: "alpha", regionText: "region alpha text", tokenEstimate: 500, originalTokenEstimate: 2000, timestamp: 1 });
|
|
287
|
-
b.add({ sessionId: "sess_b", summary: "beta", regionText: "region beta text", tokenEstimate: 700, originalTokenEstimate: 3000, timestamp: 2 });
|
|
288
|
-
|
|
289
|
-
const repo = vectorRepoStats(a);
|
|
290
|
-
assert.equal(repo.checkpointCount, 2, "checkpoints across both sessions");
|
|
291
|
-
assert.equal(repo.sessionCount, 2, "two distinct sessions");
|
|
292
|
-
assert.equal(repo.totalTokenEstimate, 1200, "Σ stored");
|
|
293
|
-
assert.equal(repo.originalTokens, 5000, "Σ original");
|
|
294
|
-
assert.equal(repo.tokensSaved, 3800, "repo saved = Σ(original − stored) = 1500 + 2300");
|
|
295
|
-
assert.equal(repo.dedupCollapsed, 0);
|
|
296
|
-
|
|
297
|
-
// A deduped add into sess_a: whole original region saved, no new row.
|
|
298
|
-
const deduped = a.add({ sessionId: "sess_a", summary: "alpha", regionText: "region alpha text", tokenEstimate: 500, originalTokenEstimate: 2000, timestamp: 3 });
|
|
299
|
-
assert.ok(deduped.deduped);
|
|
300
|
-
const repo2 = vectorRepoStats(a);
|
|
301
|
-
assert.equal(repo2.tokensSaved, 3800 + 2000, "deduped collapse adds full original region to repo saved");
|
|
302
|
-
assert.equal(repo2.dedupCollapsed, 1);
|
|
303
|
-
assert.equal(repo2.checkpointCount, 2, "still two stored checkpoints");
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test("computeRegionHash normalizes whitespace before hashing", () => {
|
|
307
|
-
const h1 = computeRegionHash("foo bar");
|
|
308
|
-
const h2 = computeRegionHash("foo bar");
|
|
309
|
-
const h3 = computeRegionHash(" foo bar ");
|
|
310
|
-
assert.equal(h1, h2, "double space and single space should hash the same");
|
|
311
|
-
assert.equal(h2, h3, "leading/trailing spaces should hash the same");
|
|
312
|
-
// Sanity: different content still hashes differently.
|
|
313
|
-
assert.notEqual(h1, computeRegionHash("foo baz"));
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
test("whitespace-variant region is deduplicated", () => {
|
|
317
|
-
const s = store();
|
|
318
|
-
const r1 = s.add({
|
|
319
|
-
sessionId: "sess_ws",
|
|
320
|
-
summary: "first",
|
|
321
|
-
regionText: "user changed config.ts",
|
|
322
|
-
timestamp: 1,
|
|
323
|
-
});
|
|
324
|
-
assert.equal(r1.deduped, false);
|
|
325
|
-
const r2 = s.add({
|
|
326
|
-
sessionId: "sess_ws",
|
|
327
|
-
summary: "second",
|
|
328
|
-
regionText: "user changed config.ts",
|
|
329
|
-
timestamp: 2,
|
|
330
|
-
});
|
|
331
|
-
assert.equal(r2.deduped, true, "whitespace-variant should be deduplicated");
|
|
332
|
-
assert.equal(vectorStats(s,"sess_ws").checkpointCount, 1, "only one checkpoint stored");
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
test("topSimilar returns n most similar checkpoints to the current (most recent)", () => {
|
|
336
|
-
const s = store();
|
|
337
|
-
s.add({
|
|
338
|
-
sessionId: "sess_top",
|
|
339
|
-
summary: "guitar",
|
|
340
|
-
regionText: "play a song on the guitar",
|
|
341
|
-
timestamp: 1,
|
|
342
|
-
});
|
|
343
|
-
s.add({
|
|
344
|
-
sessionId: "sess_top",
|
|
345
|
-
summary: "compact",
|
|
346
|
-
regionText: "fix bug in src/compact.ts truncation",
|
|
347
|
-
timestamp: 2,
|
|
348
|
-
});
|
|
349
|
-
// most recent (current) is chkpt_003, also about compact.ts but clearly
|
|
350
|
-
// distinct content so L1 near-dup dedup does not collapse it.
|
|
351
|
-
s.add({
|
|
352
|
-
sessionId: "sess_top",
|
|
353
|
-
summary: "current",
|
|
354
|
-
regionText: "fix the buffer overflow in src/compact.ts by adding a bounds check before truncate",
|
|
355
|
-
timestamp: 3,
|
|
356
|
-
});
|
|
357
|
-
const hits = vectorTopSimilar(s,"sess_top", 10);
|
|
358
|
-
assert.equal(hits.length, 2); // two other checkpoints
|
|
359
|
-
// The compact.ts checkpoint should rank above the guitar checkpoint
|
|
360
|
-
assert.equal(hits[0].checkpoint.summary, "compact");
|
|
361
|
-
assert.equal(hits[1].checkpoint.summary, "guitar");
|
|
362
|
-
assert.ok(hits[0].score >= hits[1].score);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
test("topSimilar excludes the current checkpoint itself", () => {
|
|
366
|
-
const s = store();
|
|
367
|
-
s.add({
|
|
368
|
-
sessionId: "sess_self",
|
|
369
|
-
summary: "a",
|
|
370
|
-
regionText: "alpha region text one",
|
|
371
|
-
timestamp: 1,
|
|
372
|
-
});
|
|
373
|
-
s.add({
|
|
374
|
-
sessionId: "sess_self",
|
|
375
|
-
summary: "b",
|
|
376
|
-
regionText: "alpha region text two",
|
|
377
|
-
timestamp: 2,
|
|
378
|
-
});
|
|
379
|
-
const hits = vectorTopSimilar(s,"sess_self", 5);
|
|
380
|
-
assert.equal(hits.length, 1);
|
|
381
|
-
assert.notEqual(hits[0].checkpoint.checkpointId, "chkpt_002"); // not the current
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
test("topSimilar returns empty for sessions with 0 or 1 checkpoints", () => {
|
|
385
|
-
const s = store();
|
|
386
|
-
assert.deepEqual(vectorTopSimilar(s,"sess_none", 5), []);
|
|
387
|
-
s.add({
|
|
388
|
-
sessionId: "sess_one",
|
|
389
|
-
summary: "solo",
|
|
390
|
-
regionText: "only checkpoint",
|
|
391
|
-
timestamp: 1,
|
|
392
|
-
});
|
|
393
|
-
assert.deepEqual(vectorTopSimilar(s,"sess_one", 5), []);
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
test("topSimilar respects the n limit", () => {
|
|
397
|
-
const s = store();
|
|
398
|
-
const regions = [
|
|
399
|
-
"the compiler optimized the hot loop with loop unrolling",
|
|
400
|
-
"the database added a covering index to speed up queries",
|
|
401
|
-
"the frontend introduced a virtualized list for large tables",
|
|
402
|
-
"the api added rate limiting using a token bucket algorithm",
|
|
403
|
-
"the worker pool now backpressures when the queue is overloaded",
|
|
404
|
-
];
|
|
405
|
-
for (let i = 0; i < regions.length; i++) {
|
|
406
|
-
s.add({
|
|
407
|
-
sessionId: "sess_limit",
|
|
408
|
-
summary: `c${i + 1}`,
|
|
409
|
-
regionText: regions[i],
|
|
410
|
-
timestamp: i + 1,
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
const hits = vectorTopSimilar(s,"sess_limit", 2);
|
|
414
|
-
assert.equal(hits.length, 2);
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
test("stats on empty session returns zeros and nulls", () => {
|
|
418
|
-
const s = store();
|
|
419
|
-
const st = vectorStats(s,"sess_empty");
|
|
420
|
-
assert.equal(st.checkpointCount, 0);
|
|
421
|
-
assert.equal(st.lastCheckpointId, undefined);
|
|
422
|
-
assert.equal(st.totalTokenEstimate, 0);
|
|
423
|
-
assert.equal(st.dedupHitRate, 0);
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
// --- Sprint 9: L0 content-addressable dedup -------------------------------
|
|
427
|
-
|
|
428
|
-
test("L0 content-hash dedup: identical content under different regionText collapses to one row", () => {
|
|
429
|
-
const s = store();
|
|
430
|
-
const r1 = s.add({
|
|
431
|
-
sessionId: "sess_l0",
|
|
432
|
-
summary: "fix the parser",
|
|
433
|
-
regionText: "user asked to fix the parser assistant patched src/parse.ts",
|
|
434
|
-
timestamp: 1,
|
|
435
|
-
});
|
|
436
|
-
const r2 = s.add({
|
|
437
|
-
sessionId: "sess_l0",
|
|
438
|
-
summary: "fix the parser",
|
|
439
|
-
regionText: " user asked to fix the parser assistant patched src/parse.ts ",
|
|
440
|
-
timestamp: 2,
|
|
441
|
-
});
|
|
442
|
-
assert.equal(r1.deduped, false);
|
|
443
|
-
assert.equal(r2.deduped, true);
|
|
444
|
-
assert.equal(r2.reason, "contentHash");
|
|
445
|
-
assert.equal(vectorList(s,"sess_l0").length, 1);
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
test("L0 content-hash dedup stores both hash fields and bumps timestamp on hit", () => {
|
|
449
|
-
const s = store();
|
|
450
|
-
const region = "the quick brown fox jumps over the lazy dog";
|
|
451
|
-
s.add({ sessionId: "sess_l0ts", summary: "first", regionText: region, timestamp: 10 });
|
|
452
|
-
const r2 = s.add({
|
|
453
|
-
sessionId: "sess_l0ts",
|
|
454
|
-
summary: "second",
|
|
455
|
-
regionText: region,
|
|
456
|
-
timestamp: 99,
|
|
457
|
-
});
|
|
458
|
-
assert.equal(r2.deduped, true);
|
|
459
|
-
assert.equal(r2.reason, "contentHash");
|
|
460
|
-
const cp = vectorList(s,"sess_l0ts")[0];
|
|
461
|
-
assert.equal(cp.contentHash?.length, 64);
|
|
462
|
-
assert.equal(cp.contentHash2?.length, 64);
|
|
463
|
-
assert.equal(cp.contentHashVersion, 1);
|
|
464
|
-
assert.equal(cp.timestamp, 99);
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
test("compressed_original roundtrips through versioned compression", () => {
|
|
468
|
-
const s = store();
|
|
469
|
-
const raw = "raw region text preserved for audit and replay";
|
|
470
|
-
s.add({ sessionId: "sess_co", summary: "x", regionText: raw, timestamp: 1 });
|
|
471
|
-
const cp = vectorList(s,"sess_co")[0];
|
|
472
|
-
assert.ok(cp.compressedOriginal instanceof Buffer);
|
|
473
|
-
const restored = decompressSmart(cp.compressedOriginal as Buffer).toString("utf-8");
|
|
474
|
-
assert.equal(restored, raw);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test("summaryHash is now full 64-hex SHA-256", () => {
|
|
478
|
-
const s = store();
|
|
479
|
-
const ts = "topic summary for same-topic incremental compaction";
|
|
480
|
-
const r1 = s.add({
|
|
481
|
-
sessionId: "sess_sh64",
|
|
482
|
-
summary: "a",
|
|
483
|
-
topicSummary: ts,
|
|
484
|
-
regionText: "region alpha",
|
|
485
|
-
timestamp: 1,
|
|
486
|
-
});
|
|
487
|
-
assert.equal(r1.checkpoint.summaryHash?.length, 64);
|
|
488
|
-
const r2 = s.add({
|
|
489
|
-
sessionId: "sess_sh64",
|
|
490
|
-
summary: "b",
|
|
491
|
-
topicSummary: ts,
|
|
492
|
-
regionText: "region bravo",
|
|
493
|
-
timestamp: 2,
|
|
494
|
-
});
|
|
495
|
-
assert.equal(r2.deduped, true);
|
|
496
|
-
assert.equal(r2.reason, "summaryHash");
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
// --- Sprint 11: L1 MinHash/LSH near-duplicate dedup ------------------------
|
|
500
|
-
|
|
501
|
-
test("L1 catches a one-word-diff near-duplicate that L0 misses", () => {
|
|
502
|
-
const s = store();
|
|
503
|
-
const r1 = s.add({
|
|
504
|
-
sessionId: "sess_l1",
|
|
505
|
-
summary: "user reviewed the auth module and merged the pull request",
|
|
506
|
-
regionText: "user reviewed the authentication module and merged the pull request",
|
|
507
|
-
timestamp: 1,
|
|
508
|
-
});
|
|
509
|
-
// One word inserted + different case/whitespace → L0 content-hash differs,
|
|
510
|
-
// but the text is a near-duplicate caught by the L1 trigram verify.
|
|
511
|
-
const r2 = s.add({
|
|
512
|
-
sessionId: "sess_l1",
|
|
513
|
-
summary: "user reviewed the auth module and merged the pull request",
|
|
514
|
-
regionText: " USER reviewed the authentication module and merged the pull request now ",
|
|
515
|
-
timestamp: 2,
|
|
516
|
-
});
|
|
517
|
-
assert.equal(r1.deduped, false);
|
|
518
|
-
assert.equal(r2.deduped, true);
|
|
519
|
-
assert.equal(r2.reason, "l1MinHash");
|
|
520
|
-
assert.equal(vectorList(s,"sess_l1").length, 1);
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
test("L1 does NOT falsely dedup genuinely different content", () => {
|
|
524
|
-
const s = store();
|
|
525
|
-
s.add({ sessionId: "sess_l1b", summary: "a", regionText: "the database migration added three indexes", timestamp: 1 });
|
|
526
|
-
const r2 = s.add({ sessionId: "sess_l1b", summary: "b", regionText: "the frontend added a dark mode toggle", timestamp: 2 });
|
|
527
|
-
assert.equal(r2.deduped, false);
|
|
528
|
-
assert.equal(vectorList(s,"sess_l1b").length, 2);
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
test("cleanup", () => {
|
|
532
|
-
rmSync(baseTmp, { recursive: true, force: true });
|
|
533
|
-
});
|