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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/cache-stripes.ts — Cache stripe API contract (A3, PLAN_V2 Phase 4).
|
|
3
|
+
*
|
|
4
|
+
* Response shape for GET /api/cache-stripes: per-stripe distribution counts,
|
|
5
|
+
* average stability, and a top-level health score. Loopback-only data;
|
|
6
|
+
* zero network (PREVENT-PI-004).
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -196,4 +196,36 @@ export const ENDPOINTS = {
|
|
|
196
196
|
path: "/api/provider-cache",
|
|
197
197
|
description: "Lifetime provider prompt cache hit-rate aggregates + dollar savings estimate.",
|
|
198
198
|
},
|
|
199
|
+
// ─── A3 Cache Stripes (PLAN_V2 Phase 4) ───────────────────────────
|
|
200
|
+
/** GET /api/cache-stripes — Per-stripe distribution + health score. */
|
|
201
|
+
cacheStripes: {
|
|
202
|
+
method: "GET",
|
|
203
|
+
path: "/api/cache-stripes",
|
|
204
|
+
description: "Per-stripe distribution counts, average stability scores, and composite cache health.",
|
|
205
|
+
},
|
|
206
|
+
// ─── Memory Effectiveness (S53B) ───────────────────────────────────────
|
|
207
|
+
/** GET /api/memory-status — Memory store aggregate statistics. */
|
|
208
|
+
memoryStatus: {
|
|
209
|
+
method: "GET",
|
|
210
|
+
path: "/api/memory-status",
|
|
211
|
+
description: "Memory store statistics: total count, 30-day window, top-N stable memories, avg recall score.",
|
|
212
|
+
},
|
|
213
|
+
/** GET /api/setup-status — Current embedder configuration. */
|
|
214
|
+
setupStatus: {
|
|
215
|
+
method: "GET",
|
|
216
|
+
path: "/api/setup-status",
|
|
217
|
+
description: "Current embedder configuration (which embedder is active, embedding URL, cache, MiniLM flag).",
|
|
218
|
+
},
|
|
219
|
+
/** GET /api/setup-detect — Detect available local embedder backends. */
|
|
220
|
+
setupDetect: {
|
|
221
|
+
method: "GET",
|
|
222
|
+
path: "/api/setup-detect",
|
|
223
|
+
description: "Best-effort detection of local embedder backends (ollama, llama.cpp, ONNX) available on the machine.",
|
|
224
|
+
},
|
|
225
|
+
/** POST /api/setup-configure — Write embedder config to .mega-compact.env. */
|
|
226
|
+
setupConfigure: {
|
|
227
|
+
method: "POST",
|
|
228
|
+
path: "/api/setup-configure",
|
|
229
|
+
description: "Write the chosen embedder configuration to .mega-compact.env (loaded at next startup). Returns whether a restart is required.",
|
|
230
|
+
},
|
|
199
231
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/memory.ts — Memory effectiveness stats contract (S53B).
|
|
3
|
+
*
|
|
4
|
+
* Response shape for GET /api/memory-status: aggregate memory-store statistics
|
|
5
|
+
* including total count, 30-day window, top-N stable memories by recall, and
|
|
6
|
+
* average recall score.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* api-contracts/setup.ts — Setup wizard API response types.
|
|
3
|
+
*
|
|
4
|
+
* Types for the /api/setup-status and /api/setup-detect endpoints used
|
|
5
|
+
* by the /megasetup command and dashboard Setup tab.
|
|
6
|
+
*
|
|
7
|
+
* PREVENT-PI-004: type definitions only, no network code.
|
|
8
|
+
* PREVENT-011: no `any` type — all types are explicit.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -123,7 +123,9 @@ export function readIndex() {
|
|
|
123
123
|
// paths that should never have been real repos, and collapse duplicate
|
|
124
124
|
// display names to the most-recently-seen row (rows are last_seen DESC, so
|
|
125
125
|
// the first occurrence wins). Keeps the All-repos list readable.
|
|
126
|
-
const isTransient = (p) => /^\/tmp\//.test(p) ||
|
|
126
|
+
const isTransient = (p) => /^\/tmp\//.test(p) ||
|
|
127
|
+
/^\/private\/tmp\//.test(p) ||
|
|
128
|
+
/^\/var\/folders\//.test(p) ||
|
|
127
129
|
/\/mc-(ext|e2e|resume|recall)-/.test(p);
|
|
128
130
|
const seenName = new Set();
|
|
129
131
|
const repos = [];
|
|
@@ -150,6 +152,8 @@ export function readIndex() {
|
|
|
150
152
|
try {
|
|
151
153
|
db?.close();
|
|
152
154
|
}
|
|
153
|
-
catch {
|
|
155
|
+
catch {
|
|
156
|
+
/* ignore */
|
|
157
|
+
}
|
|
154
158
|
}
|
|
155
159
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* GET /api/provider-cache — Lifetime provider prompt cache hit-rate aggregates
|
|
5
5
|
* plus dollar savings estimate (priced from latest model snapshot).
|
|
6
|
+
* Accepts optional ?minutes=N, ?since=<epoch-ms>, ?until=<epoch-ms> (S53A).
|
|
6
7
|
*
|
|
7
8
|
* Guardrails: PREVENT-PI-004 (loopback-only), PREVENT-001 (null-safe JSON parse),
|
|
8
9
|
* PREVENT-002 (parameterized SQL). Loopback-only localhost dashboard endpoint.
|
|
@@ -15,64 +16,151 @@ import { computeCacheSavings } from "../../src/pricing.js";
|
|
|
15
16
|
export function handleProviderCache(req, res, ctx) {
|
|
16
17
|
if (!req.url?.startsWith("/api/provider-cache"))
|
|
17
18
|
return false;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
try {
|
|
20
|
+
const stateDir = ctx.stateDir;
|
|
21
|
+
// PREVENT-PI-004: loopback.
|
|
22
|
+
const pfReq = createRequire(import.meta.url);
|
|
23
|
+
const { readProviderCacheLifetime, readProviderCacheWindow, latestModelSnapshot } = pfReq("../../src/store/sqlite.js");
|
|
24
|
+
if (req.method !== "GET") {
|
|
25
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
26
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
27
|
+
res.end(JSON.stringify({ error: "method_not_allowed" }));
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
// Parse query params: ?minutes=N | ?since=&until= (mutually exclusive).
|
|
31
|
+
let windowMinutes = null;
|
|
32
|
+
let sinceTs = 0;
|
|
33
|
+
let untilTs = 0;
|
|
34
|
+
if (req.url) {
|
|
35
|
+
const qIdx = req.url.indexOf("?");
|
|
36
|
+
if (qIdx !== -1) {
|
|
37
|
+
const params = new URLSearchParams(req.url.slice(qIdx));
|
|
38
|
+
const m = params.get("minutes");
|
|
39
|
+
if (m != null) {
|
|
40
|
+
const n = parseInt(m, 10);
|
|
41
|
+
if (Number.isFinite(n) && n > 0 && String(n) === m.trim()) {
|
|
42
|
+
windowMinutes = n;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// S53A: ?since=&until= epoch-ms timestamps.
|
|
46
|
+
const s = params.get("since");
|
|
47
|
+
const u = params.get("until");
|
|
48
|
+
if (s != null) {
|
|
49
|
+
const sn = Number(s);
|
|
50
|
+
if (Number.isFinite(sn) && sn >= 0)
|
|
51
|
+
sinceTs = sn;
|
|
52
|
+
}
|
|
53
|
+
if (u != null) {
|
|
54
|
+
const un = Number(u);
|
|
55
|
+
if (Number.isFinite(un) && un > 0)
|
|
56
|
+
untilTs = un;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// S53A: read prefix_break samples in the same window as the aggregates.
|
|
61
|
+
// Import lazily to avoid a circular dependency in the test harness.
|
|
62
|
+
let prefixBreaks = [];
|
|
63
|
+
try {
|
|
64
|
+
// guardrails-allow PREVENT-PI-004: local SQLite read (loopback dashboard)
|
|
65
|
+
const { readPrefixBreaks } = pfReq("../../src/store/sqlite/perf-samples.js");
|
|
66
|
+
// When ?since=&until= is used, pass those directly; otherwise derive
|
|
67
|
+
// from windowMinutes or 0 (no bounds = lifetime).
|
|
68
|
+
const pSince = sinceTs > 0 ? sinceTs : (windowMinutes != null ? Date.now() - windowMinutes * 60_000 : 0);
|
|
69
|
+
const pUntil = untilTs > 0 ? untilTs : (windowMinutes != null ? Date.now() : 0);
|
|
70
|
+
const rows = readPrefixBreaks(stateDir, pSince, pUntil);
|
|
71
|
+
prefixBreaks = rows.map((r) => ({
|
|
72
|
+
id: r.id,
|
|
73
|
+
ts: r.ts,
|
|
74
|
+
cause: r.meta.cause,
|
|
75
|
+
confidence: r.meta.confidence,
|
|
76
|
+
prevHitPct: r.meta.prevHitPct,
|
|
77
|
+
currHitPct: r.meta.currHitPct,
|
|
78
|
+
breakAt: r.meta.breakAt,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* prefix-break read unavailable — response still returns empty array */
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const lifetime = windowMinutes != null
|
|
86
|
+
? readProviderCacheWindow(stateDir, windowMinutes)
|
|
87
|
+
: readProviderCacheLifetime(stateDir); // guardrails-allow PREVENT-PI-004: local SQLite read (loopback dashboard)
|
|
88
|
+
// D3: compute dollar savings from the latest model snapshot. Null-safe:
|
|
89
|
+
// when no snapshot or zero input rate, savings stays null (UI shows "—").
|
|
90
|
+
let savings = null;
|
|
91
|
+
try {
|
|
92
|
+
const snap = latestModelSnapshot(stateDir); // guardrails-allow PREVENT-PI-004: local SQLite read (loopback dashboard)
|
|
93
|
+
if (snap && snap.inputRate > 0) {
|
|
94
|
+
const s = computeCacheSavings(lifetime.totalCacheRead, lifetime.totalCacheWrite, snap.inputRate);
|
|
95
|
+
savings = {
|
|
96
|
+
cacheReadSaved: s.cacheReadSaved,
|
|
97
|
+
cacheWriteCost: s.cacheWriteCost,
|
|
98
|
+
netSaved: s.netSaved,
|
|
99
|
+
model: snap.modelName ?? snap.modelId ?? "unknown",
|
|
100
|
+
inputRate: snap.inputRate,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
/* pricing unavailable — savings stays null */
|
|
106
|
+
}
|
|
107
|
+
const body = {
|
|
108
|
+
cache: {
|
|
109
|
+
avgHitPct: lifetime.avgHitPct,
|
|
110
|
+
turnCount: lifetime.sampleCount,
|
|
111
|
+
totalCacheRead: lifetime.totalCacheRead,
|
|
112
|
+
totalCacheWrite: lifetime.totalCacheWrite,
|
|
113
|
+
totalInput: lifetime.totalInput,
|
|
114
|
+
firstTurnAt: lifetime.firstSampleAt,
|
|
115
|
+
latestTurnAt: lifetime.latestSampleAt,
|
|
116
|
+
byModel: lifetime.byModel,
|
|
117
|
+
},
|
|
118
|
+
savings,
|
|
119
|
+
updatedAt: new Date().toISOString(),
|
|
120
|
+
windowMinutes,
|
|
121
|
+
prefixBreaks,
|
|
122
|
+
};
|
|
123
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
124
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
125
|
+
res.end(JSON.stringify(body));
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
129
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
130
|
+
res.end(JSON.stringify({
|
|
131
|
+
error: "provider_cache_unavailable",
|
|
132
|
+
detail: String(e),
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// handleCacheStripes — "GET /api/cache-stripes"
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
export function handleCacheStripes(req, res, ctx) {
|
|
145
|
+
if (!req.url?.startsWith("/api/cache-stripes"))
|
|
146
|
+
return false;
|
|
27
147
|
if (req.method !== "GET") {
|
|
28
|
-
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
29
148
|
res.writeHead(405, { "Content-Type": "application/json" });
|
|
30
149
|
res.end(JSON.stringify({ error: "method_not_allowed" }));
|
|
31
150
|
return true;
|
|
32
151
|
}
|
|
33
152
|
try {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const snap = latestModelSnapshot(stateDir); // guardrails-allow PREVENT-PI-004: local SQLite read (loopback dashboard)
|
|
40
|
-
if (snap && snap.inputRate > 0) {
|
|
41
|
-
const s = computeCacheSavings(lifetime.totalCacheRead, lifetime.totalCacheWrite, snap.inputRate);
|
|
42
|
-
savings = {
|
|
43
|
-
cacheReadSaved: s.cacheReadSaved,
|
|
44
|
-
cacheWriteCost: s.cacheWriteCost,
|
|
45
|
-
netSaved: s.netSaved,
|
|
46
|
-
model: snap.modelName ?? snap.modelId ?? "unknown",
|
|
47
|
-
inputRate: snap.inputRate,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
/* pricing unavailable — savings stays null */
|
|
53
|
-
}
|
|
54
|
-
const body = {
|
|
55
|
-
cache: {
|
|
56
|
-
avgHitPct: lifetime.avgHitPct,
|
|
57
|
-
turnCount: lifetime.sampleCount,
|
|
58
|
-
totalCacheRead: lifetime.totalCacheRead,
|
|
59
|
-
totalCacheWrite: lifetime.totalCacheWrite,
|
|
60
|
-
totalInput: lifetime.totalInput,
|
|
61
|
-
firstTurnAt: lifetime.firstSampleAt,
|
|
62
|
-
latestTurnAt: lifetime.latestSampleAt,
|
|
63
|
-
},
|
|
64
|
-
savings,
|
|
65
|
-
updatedAt: new Date().toISOString(),
|
|
66
|
-
};
|
|
67
|
-
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
153
|
+
const stateDir = ctx.stateDir;
|
|
154
|
+
const pfReq = createRequire(import.meta.url);
|
|
155
|
+
const { readCacheStripes } = pfReq("../../src/store/sqlite/cache-stripes.js");
|
|
156
|
+
const result = readCacheStripes(stateDir);
|
|
68
157
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
69
|
-
res.end(JSON.stringify(
|
|
158
|
+
res.end(JSON.stringify(result));
|
|
70
159
|
}
|
|
71
160
|
catch (e) {
|
|
72
|
-
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
73
161
|
res.writeHead(500, { "Content-Type": "application/json" });
|
|
74
162
|
res.end(JSON.stringify({
|
|
75
|
-
error: "
|
|
163
|
+
error: "cache_stripes_unavailable",
|
|
76
164
|
detail: String(e),
|
|
77
165
|
}));
|
|
78
166
|
}
|
|
@@ -256,6 +256,9 @@ export function handlePerf(req, res, ctx) {
|
|
|
256
256
|
avg: avg(get("cache_hit_pct")),
|
|
257
257
|
latest: latest(get("cache_hit_pct")),
|
|
258
258
|
n: get("cache_hit_pct").length,
|
|
259
|
+
samples: rows
|
|
260
|
+
.filter((r) => r.kind === "cache_hit_pct")
|
|
261
|
+
.map((r) => ({ pct: r.value, ts: r.ts })),
|
|
259
262
|
},
|
|
260
263
|
db_recompute_ms: {
|
|
261
264
|
p50: pct(get("db_recompute_ms"), 50),
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* routes-memory-map.ts — GET /api/memory-map route handler (S46).
|
|
3
|
+
*
|
|
4
|
+
* Builds a memory graph from the local SQLite store and returns it as JSON.
|
|
5
|
+
* Uses an inline require to the pi-agnostic src/memoryGraph.ts builder.
|
|
6
|
+
*/
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { parse as parseUrl } from "node:url";
|
|
9
|
+
const _req = createRequire(import.meta.url);
|
|
10
|
+
// guardrails-allow PREVENT-PI-004: localhost-only dashboard API endpoint that reads from the local SQLite store — zero remote network calls.
|
|
11
|
+
export function handleMemoryMap(req, res, ctx) {
|
|
12
|
+
if (req.method !== "GET")
|
|
13
|
+
return false;
|
|
14
|
+
const parsed = parseUrl(req.url ?? "", true);
|
|
15
|
+
if (parsed.pathname !== "/api/memory-map")
|
|
16
|
+
return false;
|
|
17
|
+
// guardrails-allow PREVENT-PI-004: local loopback-only dashboard server — reads the local SQLite store for graph data.
|
|
18
|
+
const { buildMemoryGraph } = _req("../../src/memoryGraph.js");
|
|
19
|
+
const sessionId = typeof parsed.query.sessionId === "string" ? parsed.query.sessionId : undefined;
|
|
20
|
+
const threshold = typeof parsed.query.threshold === "string" ? Number.parseFloat(parsed.query.threshold) : undefined;
|
|
21
|
+
const maxEdges = typeof parsed.query.maxEdgesPerNode === "string" ? Number.parseInt(parsed.query.maxEdgesPerNode, 10) : undefined;
|
|
22
|
+
const raptorEdges = parsed.query.includeRaptorEdges === "false" ? false : true;
|
|
23
|
+
const temporalEdges = parsed.query.includeTemporalEdges === "false" ? false : true;
|
|
24
|
+
const graph = buildMemoryGraph({
|
|
25
|
+
sessionId,
|
|
26
|
+
similarityThreshold: threshold,
|
|
27
|
+
maxEdgesPerNode: maxEdges,
|
|
28
|
+
stateDir: ctx.stateDir,
|
|
29
|
+
includeRaptorEdges: raptorEdges,
|
|
30
|
+
includeTemporalEdges: temporalEdges,
|
|
31
|
+
});
|
|
32
|
+
const nodes = graph.nodes.map((n) => ({
|
|
33
|
+
id: n.id,
|
|
34
|
+
sessionId: n.sessionId,
|
|
35
|
+
label: n.label,
|
|
36
|
+
summaryTruncated: n.summaryTruncated,
|
|
37
|
+
tokenEstimate: n.tokenEstimate,
|
|
38
|
+
timestamp: n.timestamp,
|
|
39
|
+
dedupStatus: n.dedupStatus,
|
|
40
|
+
raptorLevel: n.raptorLevel,
|
|
41
|
+
topicSummary: n.topicSummary,
|
|
42
|
+
decisionCount: n.decisionCount,
|
|
43
|
+
textSnippet: n.textSnippet,
|
|
44
|
+
}));
|
|
45
|
+
const edges = graph.edges;
|
|
46
|
+
const response = { nodes, edges, metadata: graph.metadata };
|
|
47
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
48
|
+
res.end(JSON.stringify(response));
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dashboard-server/routes-memory.ts — Memory effectiveness stats route handler (S53B).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/memory-status — Returns memoryStats() aggregated data:
|
|
5
|
+
* totalMemories, memoriesInLast30Days, topStableMemories, avgRecallScore.
|
|
6
|
+
*
|
|
7
|
+
* Guardrails: PREVENT-PI-004 (loopback-only), PREVENT-001 (null-safe JSON),
|
|
8
|
+
* PREVENT-002 (parameterized SQL — memoryStats uses openStore internally).
|
|
9
|
+
* Loopback-only localhost dashboard endpoint.
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
// PREVENT-PI-004: memoryStats is a pure local module (no network, no side-effects at import time).
|
|
13
|
+
// guardrails-allow PREVENT-PI-004: local TypeScript module import (loopback-only).
|
|
14
|
+
const { memoryStats } = createRequire(import.meta.url)("../../src/memoryStats.js");
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// handleMemoryStatus — "/api/memory-status"
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
export function handleMemoryStatus(req, res, ctx) {
|
|
19
|
+
if (!req.url?.startsWith("/api/memory-status"))
|
|
20
|
+
return false;
|
|
21
|
+
if (req.method !== "GET") {
|
|
22
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
23
|
+
res.writeHead(405, { "Content-Type": "application/json" });
|
|
24
|
+
res.end(JSON.stringify({ error: "method_not_allowed" }));
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
// PREVENT-PI-004: loopback-only — memoryStats reads from local SQLite store.
|
|
28
|
+
memoryStats(ctx.stateDir)
|
|
29
|
+
.then((stats) => {
|
|
30
|
+
const body = {
|
|
31
|
+
totalMemories: stats.totalMemories,
|
|
32
|
+
memoriesInLast30Days: stats.memoriesInLast30Days,
|
|
33
|
+
topStableMemories: stats.topStableMemories.map((m) => ({
|
|
34
|
+
id: m.id,
|
|
35
|
+
text: m.text,
|
|
36
|
+
recallCount: m.recallCount,
|
|
37
|
+
lastRecalledAt: m.lastRecalledAt,
|
|
38
|
+
})),
|
|
39
|
+
avgRecallScore: stats.avgRecallScore,
|
|
40
|
+
};
|
|
41
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
42
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
43
|
+
res.end(JSON.stringify(body));
|
|
44
|
+
})
|
|
45
|
+
.catch(() => {
|
|
46
|
+
// guardrails-allow PREVENT-PI-004: loopback dashboard response (local)
|
|
47
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
48
|
+
res.end(JSON.stringify({ error: "memory_stats_unavailable" }));
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
@@ -8,7 +8,7 @@ import { dashboardHtml } from "./html.js";
|
|
|
8
8
|
import { readIndex, getIndexDir } from "./index-reader.js";
|
|
9
9
|
import { ACTIVE_WINDOW_SEC } from "./types.js";
|
|
10
10
|
import { readProviderCacheForRepo } from "../../src/store/sqlite/perf-samples.js";
|
|
11
|
-
import { computeCacheSavings, lookupModelInputRate } from "../../src/pricing.js";
|
|
11
|
+
import { computeCacheSavings, lookupModelInputRate, } from "../../src/pricing.js";
|
|
12
12
|
import { latestModelSnapshot } from "../../src/store/sqlite/model-snapshots.js";
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
// handleIndex — "/" | "/index.html" | "/api/snapshot" | "/api/version"
|
|
@@ -142,7 +142,7 @@ export function handleRepoIndex(req, res, ctx) {
|
|
|
142
142
|
const modelSnap = latestModelSnapshot(r.stateDir);
|
|
143
143
|
const inputRate = modelSnap
|
|
144
144
|
? modelSnap.inputRate
|
|
145
|
-
: lookupModelInputRate(r.modelName ?? "") ?? 0;
|
|
145
|
+
: (lookupModelInputRate(r.modelName ?? "") ?? 0);
|
|
146
146
|
const savings = computeCacheSavings(pc.totalCacheRead, pc.totalCacheWrite, inputRate);
|
|
147
147
|
out.providerCache = {
|
|
148
148
|
avgHitPct: pc.avgHitPct,
|