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,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* themes.test.ts — S30 theme palette source-of-truth tests.
|
|
3
|
-
* Pi-agnostic: no pi runtime imports.
|
|
4
|
-
*/
|
|
5
|
-
import { describe, it } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import {
|
|
8
|
-
THEMES,
|
|
9
|
-
THEME_IDS,
|
|
10
|
-
DEFAULT_THEME,
|
|
11
|
-
getTheme,
|
|
12
|
-
isValidTheme,
|
|
13
|
-
nextTheme,
|
|
14
|
-
themeCssVars,
|
|
15
|
-
themeDataBlock,
|
|
16
|
-
} from "./themes.js";
|
|
17
|
-
|
|
18
|
-
describe("themes (S30)", () => {
|
|
19
|
-
it("defines exactly 6 themes", () => {
|
|
20
|
-
assert.equal(THEMES.length, 6);
|
|
21
|
-
assert.equal(THEME_IDS.length, 6);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("has unique ids", () => {
|
|
25
|
-
assert.equal(new Set(THEME_IDS).size, 6);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("default theme is transparent", () => {
|
|
29
|
-
assert.equal(DEFAULT_THEME, "transparent");
|
|
30
|
-
assert.ok(isValidTheme(DEFAULT_THEME));
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("includes retro, orange-bold, cyan-neon, amber-mono, grayscale", () => {
|
|
34
|
-
for (const id of ["retro", "orange-bold", "cyan-neon", "amber-mono", "grayscale"]) {
|
|
35
|
-
assert.ok(isValidTheme(id), `missing ${id}`);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("transparent theme has null bg (CSS + ANSI)", () => {
|
|
40
|
-
const t = getTheme("transparent");
|
|
41
|
-
assert.ok(t);
|
|
42
|
-
assert.equal(t!.css.bg, null);
|
|
43
|
-
assert.equal(t!.ansi.bg, null);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("every non-transparent theme has a non-null bg", () => {
|
|
47
|
-
for (const t of THEMES) {
|
|
48
|
-
if (t.id === "transparent") continue;
|
|
49
|
-
assert.ok(t.css.bg, `${t.id} css.bg`);
|
|
50
|
-
assert.ok(t.ansi.bg, `${t.id} ansi.bg`);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("every theme has css + ansi {fg,accent,mega} strings", () => {
|
|
55
|
-
for (const t of THEMES) {
|
|
56
|
-
assert.ok(typeof t.css.fg === "string" && t.css.fg.startsWith("#"));
|
|
57
|
-
assert.ok(typeof t.css.accent === "string");
|
|
58
|
-
assert.ok(typeof t.css.mega === "string");
|
|
59
|
-
assert.ok(typeof t.ansi.fg === "string");
|
|
60
|
-
assert.ok(typeof t.ansi.accent === "string");
|
|
61
|
-
assert.ok(typeof t.ansi.mega === "string");
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("getTheme returns undefined for unknown id", () => {
|
|
66
|
-
assert.equal(getTheme("nope"), undefined);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("isValidTheme is false for unknown", () => {
|
|
70
|
-
assert.equal(isValidTheme("nope"), false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("nextTheme cycles through all themes and wraps", () => {
|
|
74
|
-
const seen: string[] = [];
|
|
75
|
-
let cur = DEFAULT_THEME;
|
|
76
|
-
for (let i = 0; i < THEME_IDS.length; i++) {
|
|
77
|
-
cur = nextTheme(cur);
|
|
78
|
-
seen.push(cur);
|
|
79
|
-
}
|
|
80
|
-
// after N steps we've visited every theme once
|
|
81
|
-
assert.equal(new Set(seen).size, THEME_IDS.length);
|
|
82
|
-
// wraps: one more step from the last returns to the first
|
|
83
|
-
const first = nextTheme(THEME_IDS[THEME_IDS.length - 1]!);
|
|
84
|
-
assert.equal(first, THEME_IDS[0]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("nextTheme falls back to DEFAULT_THEME for unknown current", () => {
|
|
88
|
-
assert.equal(nextTheme("garbage"), DEFAULT_THEME);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
describe("themeCssVars / themeDataBlock (S32)", () => {
|
|
93
|
-
it("themeCssVars emits --bg/--fg/--accent/--mega for a normal theme", () => {
|
|
94
|
-
const t = getTheme("retro")!;
|
|
95
|
-
const vars = themeCssVars(t);
|
|
96
|
-
assert.match(vars, /--bg: #003300;/);
|
|
97
|
-
assert.match(vars, /--fg: #33ff33;/);
|
|
98
|
-
assert.match(vars, /--accent: #00ff41;/);
|
|
99
|
-
assert.match(vars, /--mega: #39ff14;/);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("themeCssVars maps null bg to 'transparent'", () => {
|
|
103
|
-
const t = getTheme("transparent")!;
|
|
104
|
-
const vars = themeCssVars(t);
|
|
105
|
-
assert.match(vars, /--bg: transparent;/);
|
|
106
|
-
assert.match(vars, /--fg: #c9d1d9;/);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("themeDataBlock wraps vars in a :root[data-theme=\"<id\"] selector", () => {
|
|
110
|
-
const t = getTheme("cyan-neon")!;
|
|
111
|
-
const block = themeDataBlock(t);
|
|
112
|
-
assert.equal(block.startsWith(':root[data-theme="cyan-neon"]{ '), true);
|
|
113
|
-
assert.equal(block.endsWith(" }"), true);
|
|
114
|
-
assert.ok(block.includes("--accent: #22d3ee;"));
|
|
115
|
-
});
|
|
116
|
-
});
|
package/src/dedup/dedup.test.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { normalize, stripAnsi } from "./normalize.js";
|
|
4
|
-
import { computeContentDigest, CONTENT_HASH_VERSION } from "./digest.js";
|
|
5
|
-
|
|
6
|
-
test("normalize collapses whitespace/newline variants to one form (Sprint 9)", () => {
|
|
7
|
-
// Sprint 9 normalizes whitespace/newlines/ANSI (not case — that is Sprint 10).
|
|
8
|
-
const variants = [
|
|
9
|
-
"foo bar",
|
|
10
|
-
"foo bar",
|
|
11
|
-
"foo\tbar",
|
|
12
|
-
"foo\nbar",
|
|
13
|
-
" foo bar ",
|
|
14
|
-
"foo\r\nbar",
|
|
15
|
-
];
|
|
16
|
-
const digests = variants.map((v) => computeContentDigest(v).contentHash);
|
|
17
|
-
const unique = new Set(digests);
|
|
18
|
-
assert.equal(unique.size, 1, "all whitespace/newline variants must collapse to one digest");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("normalize is idempotent", () => {
|
|
22
|
-
const input = " Hello World \n";
|
|
23
|
-
assert.equal(normalize(normalize(input)), normalize(input));
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test("stripAnsi removes terminal color codes", () => {
|
|
27
|
-
const colored = "err\x1b[31m fatal\x1b[0m boom";
|
|
28
|
-
assert.equal(stripAnsi(colored), "err fatal boom");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test("computeContentDigest emits full 64-hex dual hashes + version", () => {
|
|
32
|
-
const d = computeContentDigest("the same region text");
|
|
33
|
-
assert.equal(d.contentHash.length, 64);
|
|
34
|
-
assert.equal(d.contentHash2.length, 64);
|
|
35
|
-
assert.equal(d.contentHashVersion, CONTENT_HASH_VERSION);
|
|
36
|
-
assert.equal(d.normalizedText, "the same region text");
|
|
37
|
-
// Secondary is an independent view (reversed) so it differs from primary.
|
|
38
|
-
assert.notEqual(d.contentHash, d.contentHash2);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("dual-hash: distinct content yields a distinct pair (both must agree to dedup)", () => {
|
|
42
|
-
const a = computeContentDigest("region about authentication");
|
|
43
|
-
const b = computeContentDigest("region about authorization");
|
|
44
|
-
assert.notEqual(a.contentHash, b.contentHash);
|
|
45
|
-
assert.notEqual(a.contentHash2, b.contentHash2);
|
|
46
|
-
});
|
package/src/dedup/l1.test.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { minhashSignature, shingles, signatureSimilarity, NUM_HASHES } from "./l1-minhash.js";
|
|
4
|
-
import { lshBands, BANDS, ROWS_PER_BAND } from "./l1-lsh.js";
|
|
5
|
-
import { trigramSimilarity, isNearDuplicate, L1_VERIFY_THRESHOLD } from "./l1-verify.js";
|
|
6
|
-
|
|
7
|
-
test("minhashSignature is deterministic across calls (same input → same sig)", () => {
|
|
8
|
-
const a = minhashSignature("the authentication module handles login securely");
|
|
9
|
-
const b = minhashSignature("the authentication module handles login securely");
|
|
10
|
-
assert.deepEqual(a, b);
|
|
11
|
-
assert.equal(a.length, NUM_HASHES);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("minhashSignature of near-identical text is more similar than of unrelated text", () => {
|
|
15
|
-
const s1 = minhashSignature("user logged in and viewed the dashboard");
|
|
16
|
-
const s2 = minhashSignature("user logged in and viewed the dashboard page"); // one word added
|
|
17
|
-
const s3 = minhashSignature("the compiler optimized the hot loop aggressively");
|
|
18
|
-
assert.ok(signatureSimilarity(s1, s2) > signatureSimilarity(s1, s3));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("lshBands produces BANDS keys and is stable per session", () => {
|
|
22
|
-
const sig = minhashSignature("some text to band");
|
|
23
|
-
const k1 = lshBands(sig, "sess_a", 1);
|
|
24
|
-
const k2 = lshBands(sig, "sess_a", 1);
|
|
25
|
-
assert.equal(k1.length, BANDS);
|
|
26
|
-
assert.equal(BANDS * ROWS_PER_BAND, NUM_HASHES);
|
|
27
|
-
assert.deepEqual(k1, k2);
|
|
28
|
-
// Different session → different bucket keys (scoped, deterministic).
|
|
29
|
-
const k3 = lshBands(sig, "sess_b", 1);
|
|
30
|
-
assert.notDeepEqual(k1, k3);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("lshBands keys are stable across restarts (no entropy source)", () => {
|
|
34
|
-
// Recomputed in a fresh call path — determinism is structural, not time-based.
|
|
35
|
-
const sig = minhashSignature("deterministic bucket key check");
|
|
36
|
-
const first = lshBands(sig, "sess_x", 1);
|
|
37
|
-
const again = lshBands(sig, "sess_x", 1);
|
|
38
|
-
assert.deepEqual(first, again);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("trigramSimilarity is 1 for identical, high for one-word-edit, low for unrelated", () => {
|
|
42
|
-
const a = "the quick brown fox jumps";
|
|
43
|
-
assert.equal(trigramSimilarity(a, a), 1);
|
|
44
|
-
assert.ok(trigramSimilarity(a, "the quick brown fox jumps over") >= L1_VERIFY_THRESHOLD);
|
|
45
|
-
assert.ok(trigramSimilarity(a, "a completely different sentence about databases") < 0.5);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test("isNearDuplicate thresholds at 0.85", () => {
|
|
49
|
-
assert.equal(isNearDuplicate("user fixed the parser bug", "user fixed the parser bug today"), true);
|
|
50
|
-
assert.equal(isNearDuplicate("alpha beta gamma", "totally different words here"), false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test("shingles are capped at 50K (complexity guard)", () => {
|
|
54
|
-
const huge = "x".repeat(200_000);
|
|
55
|
-
const sh = shingles(huge);
|
|
56
|
-
assert.ok(sh.length <= 50_000);
|
|
57
|
-
});
|
|
@@ -1,353 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* buildHistory.test.ts — S42D RAPTOR build history + freshness tests.
|
|
3
|
-
*
|
|
4
|
-
* No network. Real stores with temp state dirs.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { test, beforeEach, afterEach } from "node:test";
|
|
8
|
-
import assert from "node:assert/strict";
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { openStore } from "../../store/sqlite/utils.js";
|
|
13
|
-
import {
|
|
14
|
-
insertBuildHistory,
|
|
15
|
-
getLatestBuild,
|
|
16
|
-
listBuildHistory,
|
|
17
|
-
computeCoherenceScore,
|
|
18
|
-
isRaptorTreeFresh,
|
|
19
|
-
clearBuildHistory,
|
|
20
|
-
} from "./buildHistory.js";
|
|
21
|
-
import { runRaptor } from "./index.js";
|
|
22
|
-
import { VectorStore, vectorList } from "../../vectorStore.js";
|
|
23
|
-
import { compactSession } from "../../engine.js";
|
|
24
|
-
import { loadDedupConfig } from "../../config/dedup.js";
|
|
25
|
-
import { normalizeSessionId } from "../../store.js";
|
|
26
|
-
import { Logger } from "../../log.js";
|
|
27
|
-
import type { RaptorTree } from "./tree.js";
|
|
28
|
-
import type { DedupConfigShape } from "../../config/dedup.js";
|
|
29
|
-
import type { EngineMessage } from "../../types.js";
|
|
30
|
-
|
|
31
|
-
let tmpDir: string;
|
|
32
|
-
let counter = 0;
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
tmpDir = mkdtempSync(join(tmpdir(), "mc-bh-"));
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
function stateDir(): string {
|
|
43
|
-
return join(tmpDir, `run-${counter++}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function cfg(overrides?: Record<string, unknown>): DedupConfigShape {
|
|
47
|
-
return {
|
|
48
|
-
...loadDedupConfig(),
|
|
49
|
-
RAPTOR_ENABLED: true,
|
|
50
|
-
L0_ENABLED: false,
|
|
51
|
-
L1_ENABLED: false,
|
|
52
|
-
L2_ENABLED: false,
|
|
53
|
-
...overrides,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function msg(text: string, toolName?: string): EngineMessage {
|
|
58
|
-
return toolName
|
|
59
|
-
? { role: "assistant", text, toolName, input: text, output: text }
|
|
60
|
-
: { role: "user", text };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ─── 1. Build-history rows are created with correct metadata ──────────────
|
|
64
|
-
|
|
65
|
-
test("S42D-1: insertBuildHistory + getLatestBuild round-trip", () => {
|
|
66
|
-
const sd = stateDir();
|
|
67
|
-
openStore(sd); // initialize schema
|
|
68
|
-
const ts = Date.now();
|
|
69
|
-
const id = insertBuildHistory(
|
|
70
|
-
{
|
|
71
|
-
sessionId: "sess-foo",
|
|
72
|
-
stateDir: sd,
|
|
73
|
-
startedAt: ts - 500,
|
|
74
|
-
completedAt: ts,
|
|
75
|
-
nodeCount: 6,
|
|
76
|
-
leafCount: 10,
|
|
77
|
-
depth: 3,
|
|
78
|
-
configJson: '{"budgetMs":5000}',
|
|
79
|
-
coherenceScore: 0.82,
|
|
80
|
-
timedOut: false,
|
|
81
|
-
},
|
|
82
|
-
sd,
|
|
83
|
-
);
|
|
84
|
-
assert.ok(id, "build id returned");
|
|
85
|
-
const latest = getLatestBuild("sess-foo", sd);
|
|
86
|
-
assert.ok(latest, "latest build found");
|
|
87
|
-
assert.equal(latest!.sessionId, normalizeSessionId("sess-foo"));
|
|
88
|
-
assert.equal(latest!.nodeCount, 6);
|
|
89
|
-
assert.equal(latest!.leafCount, 10);
|
|
90
|
-
assert.equal(latest!.depth, 3);
|
|
91
|
-
assert.equal(latest!.coherenceScore, 0.82);
|
|
92
|
-
assert.equal(latest!.timedOut, false);
|
|
93
|
-
assert.equal(latest!.configJson, '{"budgetMs":5000}');
|
|
94
|
-
// getLatest returns the newest by completed_at
|
|
95
|
-
insertBuildHistory(
|
|
96
|
-
{
|
|
97
|
-
sessionId: "sess-foo",
|
|
98
|
-
stateDir: sd,
|
|
99
|
-
startedAt: ts + 1000,
|
|
100
|
-
completedAt: ts + 2000,
|
|
101
|
-
nodeCount: 7,
|
|
102
|
-
leafCount: 11,
|
|
103
|
-
depth: 3,
|
|
104
|
-
configJson: "{}",
|
|
105
|
-
coherenceScore: null,
|
|
106
|
-
timedOut: true,
|
|
107
|
-
},
|
|
108
|
-
sd,
|
|
109
|
-
);
|
|
110
|
-
const newest = getLatestBuild("sess-foo", sd);
|
|
111
|
-
assert.equal(newest!.nodeCount, 7);
|
|
112
|
-
assert.equal(newest!.timedOut, true);
|
|
113
|
-
assert.equal(newest!.coherenceScore, null);
|
|
114
|
-
// listBuildHistory returns all, newest first
|
|
115
|
-
const all = listBuildHistory("sess-foo", sd);
|
|
116
|
-
assert.equal(all.length, 2);
|
|
117
|
-
assert.equal(all[0].nodeCount, 7); // newest first
|
|
118
|
-
// No history for an unknown session
|
|
119
|
-
assert.equal(getLatestBuild("sess-none", sd), null);
|
|
120
|
-
assert.deepEqual(listBuildHistory("sess-none", sd), []);
|
|
121
|
-
// clearBuildHistory removes rows
|
|
122
|
-
clearBuildHistory("sess-foo", sd);
|
|
123
|
-
assert.equal(getLatestBuild("sess-foo", sd), null);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// ─── 2. Coherence score: 1.0 for identical, lower for diverse ───────────────
|
|
127
|
-
|
|
128
|
-
test("S42D-2: computeCoherenceScore is 1.0 for identical embeddings, lower for diverse", () => {
|
|
129
|
-
const identical: RaptorTree = {
|
|
130
|
-
rootId: "root",
|
|
131
|
-
nodes: new Map([
|
|
132
|
-
["root", { id: "root", level: 0, parentId: null, children: ["c1", "c2"], summary: "r", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 2 }],
|
|
133
|
-
["c1", { id: "c1", level: 1, parentId: "root", children: [], summary: "c1", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 1 }],
|
|
134
|
-
["c2", { id: "c2", level: 1, parentId: "root", children: [], summary: "c2", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 1 }],
|
|
135
|
-
]),
|
|
136
|
-
levels: 2,
|
|
137
|
-
timedOut: false,
|
|
138
|
-
};
|
|
139
|
-
assert.equal(computeCoherenceScore(identical), 1.0);
|
|
140
|
-
// Diverse: orthogonal children → cosine 0
|
|
141
|
-
const diverse: RaptorTree = {
|
|
142
|
-
rootId: "root",
|
|
143
|
-
nodes: new Map([
|
|
144
|
-
["root", { id: "root", level: 0, parentId: null, children: ["c1", "c2"], summary: "r", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 2 }],
|
|
145
|
-
["c1", { id: "c1", level: 1, parentId: "root", children: [], summary: "c1", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 1 }],
|
|
146
|
-
["c2", { id: "c2", level: 1, parentId: "root", children: [], summary: "c2", embedding: [0, 1], qualityMarker: "low", tokenEstimate: 1 }],
|
|
147
|
-
]),
|
|
148
|
-
levels: 2,
|
|
149
|
-
timedOut: false,
|
|
150
|
-
};
|
|
151
|
-
const diverseScore = computeCoherenceScore(diverse);
|
|
152
|
-
assert.ok(diverseScore < 1.0, `diverse score < 1.0 (got ${diverseScore})`);
|
|
153
|
-
assert.ok(diverseScore >= 0, "score is non-negative");
|
|
154
|
-
// No internal nodes with >=2 children → 0
|
|
155
|
-
const single: RaptorTree = {
|
|
156
|
-
rootId: "root",
|
|
157
|
-
nodes: new Map([
|
|
158
|
-
["root", { id: "root", level: 0, parentId: null, children: ["c1"], summary: "r", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 1 }],
|
|
159
|
-
["c1", { id: "c1", level: 1, parentId: "root", children: [], summary: "c1", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 1 }],
|
|
160
|
-
]),
|
|
161
|
-
levels: 2,
|
|
162
|
-
timedOut: false,
|
|
163
|
-
};
|
|
164
|
-
assert.equal(computeCoherenceScore(single), 0);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// ─── 2b. Coherence with leaf embeddings (the real-tree shape) ──────────────
|
|
168
|
-
|
|
169
|
-
test("S42D-2b: computeCoherenceScore uses leafEmbeddings for leaf children (real-tree shape)", () => {
|
|
170
|
-
// Root whose children are raw leaves (the common collapse-path shape).
|
|
171
|
-
// Without leafEmbeddings, leaves fall back to the root centroid → score 1.0
|
|
172
|
-
// (degenerate). With true leaf embeddings, diverse leaves score < 1.0.
|
|
173
|
-
const tree: RaptorTree = {
|
|
174
|
-
rootId: "root",
|
|
175
|
-
nodes: new Map([
|
|
176
|
-
["root", { id: "root", level: 0, parentId: null, children: ["l1", "l2"], summary: "r", embedding: [1, 0], qualityMarker: "low", tokenEstimate: 2 }],
|
|
177
|
-
]),
|
|
178
|
-
levels: 1,
|
|
179
|
-
timedOut: false,
|
|
180
|
-
};
|
|
181
|
-
// No leaf map → both leaves use root centroid [1,0] → cosine 1.0 (degenerate).
|
|
182
|
-
assert.equal(computeCoherenceScore(tree), 1.0);
|
|
183
|
-
// Leaf map with orthogonal leaves → cosine 0 (truly diverse).
|
|
184
|
-
const leafMap = new Map([
|
|
185
|
-
["l1", [1, 0]],
|
|
186
|
-
["l2", [0, 1]],
|
|
187
|
-
]);
|
|
188
|
-
const score = computeCoherenceScore(tree, leafMap);
|
|
189
|
-
assert.ok(score < 1.0, `diverse leaves score < 1.0 (got ${score})`);
|
|
190
|
-
assert.ok(score >= 0, "score non-negative");
|
|
191
|
-
// Identical leaves via the map → 1.0
|
|
192
|
-
const leafMapIdentical = new Map([
|
|
193
|
-
["l1", [1, 0]],
|
|
194
|
-
["l2", [1, 0]],
|
|
195
|
-
]);
|
|
196
|
-
assert.equal(computeCoherenceScore(tree, leafMapIdentical), 1.0);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// ─── 3. Freshness check: recent + stable → fresh ────────────────────────────
|
|
200
|
-
|
|
201
|
-
test("S42D-3: isRaptorTreeFresh true for recent build + stable count", () => {
|
|
202
|
-
const sd = stateDir();
|
|
203
|
-
openStore(sd);
|
|
204
|
-
insertBuildHistory(
|
|
205
|
-
{
|
|
206
|
-
sessionId: "sess-fresh",
|
|
207
|
-
stateDir: sd,
|
|
208
|
-
startedAt: Date.now() - 1000,
|
|
209
|
-
completedAt: Date.now() - 500, // < 4h old
|
|
210
|
-
nodeCount: 6,
|
|
211
|
-
leafCount: 10,
|
|
212
|
-
depth: 3,
|
|
213
|
-
configJson: "{}",
|
|
214
|
-
coherenceScore: 0.5,
|
|
215
|
-
timedOut: false,
|
|
216
|
-
},
|
|
217
|
-
sd,
|
|
218
|
-
);
|
|
219
|
-
// 10 checkpoints, latest had 10 → within 20% → fresh
|
|
220
|
-
assert.equal(isRaptorTreeFresh("sess-fresh", sd, 4, 10), true);
|
|
221
|
-
// 11 checkpoints → 10% change → still fresh
|
|
222
|
-
assert.equal(isRaptorTreeFresh("sess-fresh", sd, 4, 11), true);
|
|
223
|
-
// 9 checkpoints → 10% change → fresh
|
|
224
|
-
assert.equal(isRaptorTreeFresh("sess-fresh", sd, 4, 9), true);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// ─── 4. Freshness check: stale build → not fresh ────────────────────────────
|
|
228
|
-
|
|
229
|
-
test("S42D-4: isRaptorTreeFresh false for stale build (>4h old)", () => {
|
|
230
|
-
const sd = stateDir();
|
|
231
|
-
openStore(sd);
|
|
232
|
-
const oldTs = Date.now() - 5 * 3_600_000; // 5h ago
|
|
233
|
-
insertBuildHistory(
|
|
234
|
-
{
|
|
235
|
-
sessionId: "sess-stale",
|
|
236
|
-
stateDir: sd,
|
|
237
|
-
startedAt: oldTs - 1000,
|
|
238
|
-
completedAt: oldTs,
|
|
239
|
-
nodeCount: 6,
|
|
240
|
-
leafCount: 10,
|
|
241
|
-
depth: 3,
|
|
242
|
-
configJson: "{}",
|
|
243
|
-
coherenceScore: 0.5,
|
|
244
|
-
timedOut: false,
|
|
245
|
-
},
|
|
246
|
-
sd,
|
|
247
|
-
);
|
|
248
|
-
assert.equal(isRaptorTreeFresh("sess-stale", sd, 4, 10), false);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
// ─── 5. Freshness check: count drift > 20% → not fresh ──────────────────────
|
|
252
|
-
|
|
253
|
-
test("S42D-5: isRaptorTreeFresh false when checkpoint count changed by >20%", () => {
|
|
254
|
-
const sd = stateDir();
|
|
255
|
-
openStore(sd);
|
|
256
|
-
insertBuildHistory(
|
|
257
|
-
{
|
|
258
|
-
sessionId: "sess-drift",
|
|
259
|
-
stateDir: sd,
|
|
260
|
-
startedAt: Date.now() - 1000,
|
|
261
|
-
completedAt: Date.now() - 500,
|
|
262
|
-
nodeCount: 6,
|
|
263
|
-
leafCount: 10,
|
|
264
|
-
depth: 3,
|
|
265
|
-
configJson: "{}",
|
|
266
|
-
coherenceScore: 0.5,
|
|
267
|
-
timedOut: false,
|
|
268
|
-
},
|
|
269
|
-
sd,
|
|
270
|
-
);
|
|
271
|
-
// 13 checkpoints vs 10 → 30% increase → not fresh
|
|
272
|
-
assert.equal(isRaptorTreeFresh("sess-drift", sd, 4, 13), false);
|
|
273
|
-
// 7 checkpoints vs 10 → 30% decrease → not fresh
|
|
274
|
-
assert.equal(isRaptorTreeFresh("sess-drift", sd, 4, 7), false);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// ─── 6. No build history → freshness false (forces build) ───────────────────
|
|
278
|
-
|
|
279
|
-
test("S42D-6: isRaptorTreeFresh false when no build history exists", () => {
|
|
280
|
-
const sd = stateDir();
|
|
281
|
-
openStore(sd);
|
|
282
|
-
assert.equal(isRaptorTreeFresh("sess-none", sd, 4, 50), false);
|
|
283
|
-
// freshnessHours=0 always false (disables the gate → always rebuild)
|
|
284
|
-
insertBuildHistory(
|
|
285
|
-
{
|
|
286
|
-
sessionId: "sess-zero",
|
|
287
|
-
stateDir: sd,
|
|
288
|
-
startedAt: Date.now() - 100,
|
|
289
|
-
completedAt: Date.now() - 50,
|
|
290
|
-
nodeCount: 1,
|
|
291
|
-
leafCount: 5,
|
|
292
|
-
depth: 1,
|
|
293
|
-
configJson: "{}",
|
|
294
|
-
coherenceScore: 0.5,
|
|
295
|
-
timedOut: false,
|
|
296
|
-
},
|
|
297
|
-
sd,
|
|
298
|
-
);
|
|
299
|
-
assert.equal(isRaptorTreeFresh("sess-zero", sd, 0, 5), false);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// ─── 7. runRaptor records build history end-to-end ──────────────────────────
|
|
303
|
-
|
|
304
|
-
test("S42D-7: runRaptor records a build-history row on real build", () => {
|
|
305
|
-
const sd = stateDir();
|
|
306
|
-
const s = new VectorStore({ dedupSim: 0.9, stateDir: sd, config: cfg() });
|
|
307
|
-
const sid = "bh-e2e";
|
|
308
|
-
// Seed 12 checkpoints and build a tree.
|
|
309
|
-
for (let i = 1; i <= 12; i++) {
|
|
310
|
-
compactSession(
|
|
311
|
-
{
|
|
312
|
-
sessionId: sid,
|
|
313
|
-
messages: [
|
|
314
|
-
msg(`build-history test checkpoint ${i} alpha beta`),
|
|
315
|
-
msg(`ack ${i}`, "Edit"),
|
|
316
|
-
],
|
|
317
|
-
keepFrom: 2,
|
|
318
|
-
timestamp: i + 1,
|
|
319
|
-
},
|
|
320
|
-
s,
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
const nsid = normalizeSessionId(sid);
|
|
324
|
-
const all = vectorList(s, nsid);
|
|
325
|
-
const leaves = all.map((cp) => ({
|
|
326
|
-
id: cp.checkpointId,
|
|
327
|
-
messages: [],
|
|
328
|
-
sourceText: cp.normalizedText ?? cp.summary ?? cp.regionHash,
|
|
329
|
-
embedding: cp.embedding,
|
|
330
|
-
}));
|
|
331
|
-
const tree = runRaptor(leaves, {
|
|
332
|
-
stateDir: sd,
|
|
333
|
-
sessionId: nsid,
|
|
334
|
-
logger: new Logger(),
|
|
335
|
-
});
|
|
336
|
-
assert.ok(tree, "tree built");
|
|
337
|
-
const latest = getLatestBuild(nsid, sd);
|
|
338
|
-
assert.ok(latest, "build history recorded by runRaptor");
|
|
339
|
-
assert.equal(latest!.leafCount, leaves.length);
|
|
340
|
-
assert.equal(latest!.depth, tree!.levels);
|
|
341
|
-
assert.equal(latest!.timedOut, tree!.timedOut);
|
|
342
|
-
assert.equal(latest!.nodeCount, tree!.nodes.size);
|
|
343
|
-
assert.ok(
|
|
344
|
-
latest!.coherenceScore !== null && latest!.coherenceScore >= 0,
|
|
345
|
-
"coherence score recorded",
|
|
346
|
-
);
|
|
347
|
-
// The freshness gate should now report fresh for the same checkpoint count.
|
|
348
|
-
assert.equal(
|
|
349
|
-
isRaptorTreeFresh(nsid, sd, 4, all.length),
|
|
350
|
-
true,
|
|
351
|
-
"tree is fresh immediately after build",
|
|
352
|
-
);
|
|
353
|
-
});
|