@stackmemoryai/stackmemory 0.5.59 → 0.5.61
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/README.md +105 -1
- package/dist/src/cli/claude-sm.js +130 -50
- package/dist/src/cli/claude-sm.js.map +2 -2
- package/dist/src/cli/index.js +18 -3
- package/dist/src/cli/index.js.map +3 -3
- package/dist/src/core/extensions/custom-tools.js +567 -0
- package/dist/src/core/extensions/custom-tools.js.map +7 -0
- package/dist/src/core/extensions/index.js +55 -0
- package/dist/src/core/extensions/index.js.map +7 -0
- package/dist/src/core/extensions/loader.js +709 -0
- package/dist/src/core/extensions/loader.js.map +7 -0
- package/dist/src/core/extensions/plugin-system.js +506 -0
- package/dist/src/core/extensions/plugin-system.js.map +7 -0
- package/dist/src/core/extensions/provider-adapter.js +617 -0
- package/dist/src/core/extensions/provider-adapter.js.map +7 -0
- package/dist/src/core/extensions/sandbox-runtime.js +664 -0
- package/dist/src/core/extensions/sandbox-runtime.js.map +7 -0
- package/dist/src/core/storage/chromadb-adapter.js +32 -6
- package/dist/src/core/storage/chromadb-adapter.js.map +2 -2
- package/dist/src/skills/repo-ingestion-skill.js +35 -12
- package/dist/src/skills/repo-ingestion-skill.js.map +2 -2
- package/package.json +11 -7
- package/scripts/background-sync-manager.js +145 -83
- package/scripts/claude-sm-autostart.js +17 -12
- package/scripts/gepa/README.md +275 -0
- package/scripts/gepa/config.json +53 -0
- package/scripts/gepa/evals/coding-tasks.jsonl +5 -0
- package/scripts/gepa/evals/fixtures/buggy-loop.js +18 -0
- package/scripts/gepa/evals/fixtures/callback-hell.js +53 -0
- package/scripts/gepa/generations/gen-000/baseline.md +124 -0
- package/scripts/gepa/hooks/auto-optimize.js +494 -0
- package/scripts/gepa/hooks/eval-tracker.js +203 -0
- package/scripts/gepa/hooks/reflect.js +311 -0
- package/scripts/gepa/optimize.js +611 -0
- package/scripts/gepa/state.json +14 -0
- package/scripts/test-pre-publish-quick.sh +1 -1
- package/dist/agents/core/agent-task-manager.js +0 -527
- package/dist/agents/core/agent-task-manager.js.map +0 -7
- package/dist/agents/testing-agent.js +0 -614
- package/dist/agents/testing-agent.js.map +0 -7
- package/dist/agents/verifiers/base-verifier.js +0 -133
- package/dist/agents/verifiers/base-verifier.js.map +0 -7
- package/dist/agents/verifiers/formatter-verifier.js +0 -130
- package/dist/agents/verifiers/formatter-verifier.js.map +0 -7
- package/dist/agents/verifiers/llm-judge.js +0 -252
- package/dist/agents/verifiers/llm-judge.js.map +0 -7
- package/dist/cli/auto-detect.js +0 -321
- package/dist/cli/auto-detect.js.map +0 -7
- package/dist/cli/browser-test.js +0 -33
- package/dist/cli/browser-test.js.map +0 -7
- package/dist/cli/claude-sm-danger.js +0 -21
- package/dist/cli/claude-sm-danger.js.map +0 -7
- package/dist/cli/claude-sm.js +0 -1156
- package/dist/cli/claude-sm.js.map +0 -7
- package/dist/cli/codex-sm-danger.js +0 -21
- package/dist/cli/codex-sm-danger.js.map +0 -7
- package/dist/cli/codex-sm.js +0 -349
- package/dist/cli/codex-sm.js.map +0 -7
- package/dist/cli/commands/api.js +0 -232
- package/dist/cli/commands/api.js.map +0 -7
- package/dist/cli/commands/auto-background.js +0 -180
- package/dist/cli/commands/auto-background.js.map +0 -7
- package/dist/cli/commands/cleanup-processes.js +0 -68
- package/dist/cli/commands/cleanup-processes.js.map +0 -7
- package/dist/cli/commands/clear.js +0 -202
- package/dist/cli/commands/clear.js.map +0 -7
- package/dist/cli/commands/config.js +0 -445
- package/dist/cli/commands/config.js.map +0 -7
- package/dist/cli/commands/context-rehydrate.js +0 -751
- package/dist/cli/commands/context-rehydrate.js.map +0 -7
- package/dist/cli/commands/context.js +0 -343
- package/dist/cli/commands/context.js.map +0 -7
- package/dist/cli/commands/daemon.js +0 -392
- package/dist/cli/commands/daemon.js.map +0 -7
- package/dist/cli/commands/dashboard.js +0 -210
- package/dist/cli/commands/dashboard.js.map +0 -7
- package/dist/cli/commands/db.js +0 -147
- package/dist/cli/commands/db.js.map +0 -7
- package/dist/cli/commands/decision.js +0 -266
- package/dist/cli/commands/decision.js.map +0 -7
- package/dist/cli/commands/discovery.js +0 -279
- package/dist/cli/commands/discovery.js.map +0 -7
- package/dist/cli/commands/handoff.js +0 -624
- package/dist/cli/commands/handoff.js.map +0 -7
- package/dist/cli/commands/hooks.js +0 -298
- package/dist/cli/commands/hooks.js.map +0 -7
- package/dist/cli/commands/linear-unified.js +0 -353
- package/dist/cli/commands/linear-unified.js.map +0 -7
- package/dist/cli/commands/linear.js +0 -529
- package/dist/cli/commands/linear.js.map +0 -7
- package/dist/cli/commands/log.js +0 -169
- package/dist/cli/commands/log.js.map +0 -7
- package/dist/cli/commands/login.js +0 -172
- package/dist/cli/commands/login.js.map +0 -7
- package/dist/cli/commands/migrate.js +0 -240
- package/dist/cli/commands/migrate.js.map +0 -7
- package/dist/cli/commands/model.js +0 -533
- package/dist/cli/commands/model.js.map +0 -7
- package/dist/cli/commands/monitor.js +0 -313
- package/dist/cli/commands/monitor.js.map +0 -7
- package/dist/cli/commands/onboard.js +0 -536
- package/dist/cli/commands/onboard.js.map +0 -7
- package/dist/cli/commands/projects.js +0 -199
- package/dist/cli/commands/projects.js.map +0 -7
- package/dist/cli/commands/quality.js +0 -413
- package/dist/cli/commands/quality.js.map +0 -7
- package/dist/cli/commands/ralph.js +0 -909
- package/dist/cli/commands/ralph.js.map +0 -7
- package/dist/cli/commands/retrieval.js +0 -248
- package/dist/cli/commands/retrieval.js.map +0 -7
- package/dist/cli/commands/search.js +0 -173
- package/dist/cli/commands/search.js.map +0 -7
- package/dist/cli/commands/service.js +0 -749
- package/dist/cli/commands/service.js.map +0 -7
- package/dist/cli/commands/session.js +0 -200
- package/dist/cli/commands/session.js.map +0 -7
- package/dist/cli/commands/settings.js +0 -306
- package/dist/cli/commands/settings.js.map +0 -7
- package/dist/cli/commands/setup.js +0 -701
- package/dist/cli/commands/setup.js.map +0 -7
- package/dist/cli/commands/shell.js +0 -249
- package/dist/cli/commands/shell.js.map +0 -7
- package/dist/cli/commands/signup.js +0 -50
- package/dist/cli/commands/signup.js.map +0 -7
- package/dist/cli/commands/skills.js +0 -470
- package/dist/cli/commands/skills.js.map +0 -7
- package/dist/cli/commands/sms-notify.js +0 -795
- package/dist/cli/commands/sms-notify.js.map +0 -7
- package/dist/cli/commands/storage-tier.js +0 -183
- package/dist/cli/commands/storage-tier.js.map +0 -7
- package/dist/cli/commands/storage.js +0 -360
- package/dist/cli/commands/storage.js.map +0 -7
- package/dist/cli/commands/sweep.js +0 -249
- package/dist/cli/commands/sweep.js.map +0 -7
- package/dist/cli/commands/tasks.js +0 -213
- package/dist/cli/commands/tasks.js.map +0 -7
- package/dist/cli/commands/test.js +0 -286
- package/dist/cli/commands/test.js.map +0 -7
- package/dist/cli/commands/workflow.js +0 -142
- package/dist/cli/commands/workflow.js.map +0 -7
- package/dist/cli/commands/worktree.js +0 -319
- package/dist/cli/commands/worktree.js.map +0 -7
- package/dist/cli/index.js +0 -594
- package/dist/cli/index.js.map +0 -7
- package/dist/cli/opencode-sm.js +0 -448
- package/dist/cli/opencode-sm.js.map +0 -7
- package/dist/cli/utils/viewer.js +0 -96
- package/dist/cli/utils/viewer.js.map +0 -7
- package/dist/core/analytics/team-analytics.js +0 -378
- package/dist/core/analytics/team-analytics.js.map +0 -7
- package/dist/core/config/config-manager.js +0 -398
- package/dist/core/config/config-manager.js.map +0 -7
- package/dist/core/config/feature-flags.js +0 -76
- package/dist/core/config/feature-flags.js.map +0 -7
- package/dist/core/config/storage-config.js +0 -115
- package/dist/core/config/storage-config.js.map +0 -7
- package/dist/core/config/types.js +0 -144
- package/dist/core/config/types.js.map +0 -7
- package/dist/core/context/auto-context.js +0 -80
- package/dist/core/context/auto-context.js.map +0 -7
- package/dist/core/context/dual-stack-manager.js +0 -870
- package/dist/core/context/dual-stack-manager.js.map +0 -7
- package/dist/core/context/enhanced-rehydration.js +0 -994
- package/dist/core/context/enhanced-rehydration.js.map +0 -7
- package/dist/core/context/frame-database.js +0 -479
- package/dist/core/context/frame-database.js.map +0 -7
- package/dist/core/context/frame-digest.js +0 -250
- package/dist/core/context/frame-digest.js.map +0 -7
- package/dist/core/context/frame-handoff-manager.js +0 -778
- package/dist/core/context/frame-handoff-manager.js.map +0 -7
- package/dist/core/context/frame-lifecycle-hooks.js +0 -119
- package/dist/core/context/frame-lifecycle-hooks.js.map +0 -7
- package/dist/core/context/frame-manager.js +0 -1069
- package/dist/core/context/frame-manager.js.map +0 -7
- package/dist/core/context/frame-recovery.js +0 -302
- package/dist/core/context/frame-recovery.js.map +0 -7
- package/dist/core/context/frame-stack.js +0 -314
- package/dist/core/context/frame-stack.js.map +0 -7
- package/dist/core/context/frame-types.js +0 -5
- package/dist/core/context/frame-types.js.map +0 -7
- package/dist/core/context/incremental-gc.js +0 -290
- package/dist/core/context/incremental-gc.js.map +0 -7
- package/dist/core/context/index.js +0 -25
- package/dist/core/context/index.js.map +0 -7
- package/dist/core/context/model-aware-compaction.js +0 -623
- package/dist/core/context/model-aware-compaction.js.map +0 -7
- package/dist/core/context/permission-manager.js +0 -185
- package/dist/core/context/permission-manager.js.map +0 -7
- package/dist/core/context/recursive-context-manager.js +0 -592
- package/dist/core/context/recursive-context-manager.js.map +0 -7
- package/dist/core/context/refactored-frame-manager.js +0 -754
- package/dist/core/context/refactored-frame-manager.js.map +0 -7
- package/dist/core/context/shared-context-layer.js +0 -621
- package/dist/core/context/shared-context-layer.js.map +0 -7
- package/dist/core/context/stack-merge-resolver.js +0 -749
- package/dist/core/context/stack-merge-resolver.js.map +0 -7
- package/dist/core/context/validation.js +0 -130
- package/dist/core/context/validation.js.map +0 -7
- package/dist/core/database/batch-operations.js +0 -384
- package/dist/core/database/batch-operations.js.map +0 -7
- package/dist/core/database/connection-pool.js +0 -330
- package/dist/core/database/connection-pool.js.map +0 -7
- package/dist/core/database/database-adapter.js +0 -60
- package/dist/core/database/database-adapter.js.map +0 -7
- package/dist/core/database/migration-manager.js +0 -614
- package/dist/core/database/migration-manager.js.map +0 -7
- package/dist/core/database/paradedb-adapter.js +0 -990
- package/dist/core/database/paradedb-adapter.js.map +0 -7
- package/dist/core/database/query-cache.js +0 -298
- package/dist/core/database/query-cache.js.map +0 -7
- package/dist/core/database/query-router.js +0 -430
- package/dist/core/database/query-router.js.map +0 -7
- package/dist/core/database/sqlite-adapter.js +0 -738
- package/dist/core/database/sqlite-adapter.js.map +0 -7
- package/dist/core/digest/enhanced-hybrid-digest.js +0 -277
- package/dist/core/digest/enhanced-hybrid-digest.js.map +0 -7
- package/dist/core/digest/frame-digest-integration.js +0 -176
- package/dist/core/digest/frame-digest-integration.js.map +0 -7
- package/dist/core/digest/hybrid-digest-generator.js +0 -553
- package/dist/core/digest/hybrid-digest-generator.js.map +0 -7
- package/dist/core/digest/index.js +0 -9
- package/dist/core/digest/index.js.map +0 -7
- package/dist/core/digest/types.js +0 -25
- package/dist/core/digest/types.js.map +0 -7
- package/dist/core/errors/error-utils.js +0 -208
- package/dist/core/errors/error-utils.js.map +0 -7
- package/dist/core/errors/index.js +0 -521
- package/dist/core/errors/index.js.map +0 -7
- package/dist/core/errors/recovery.js +0 -269
- package/dist/core/errors/recovery.js.map +0 -7
- package/dist/core/execution/parallel-executor.js +0 -258
- package/dist/core/execution/parallel-executor.js.map +0 -7
- package/dist/core/frame/workflow-templates.js +0 -319
- package/dist/core/frame/workflow-templates.js.map +0 -7
- package/dist/core/merge/conflict-detector.js +0 -431
- package/dist/core/merge/conflict-detector.js.map +0 -7
- package/dist/core/merge/index.js +0 -9
- package/dist/core/merge/index.js.map +0 -7
- package/dist/core/merge/resolution-engine.js +0 -558
- package/dist/core/merge/resolution-engine.js.map +0 -7
- package/dist/core/merge/stack-diff.js +0 -532
- package/dist/core/merge/stack-diff.js.map +0 -7
- package/dist/core/merge/unified-merge-resolver.js +0 -303
- package/dist/core/merge/unified-merge-resolver.js.map +0 -7
- package/dist/core/models/fallback-monitor.js +0 -232
- package/dist/core/models/fallback-monitor.js.map +0 -7
- package/dist/core/models/model-router.js +0 -340
- package/dist/core/models/model-router.js.map +0 -7
- package/dist/core/monitoring/error-handler.js +0 -49
- package/dist/core/monitoring/error-handler.js.map +0 -7
- package/dist/core/monitoring/logger.js +0 -202
- package/dist/core/monitoring/logger.js.map +0 -7
- package/dist/core/monitoring/metrics.js +0 -172
- package/dist/core/monitoring/metrics.js.map +0 -7
- package/dist/core/monitoring/progress-tracker.js +0 -189
- package/dist/core/monitoring/progress-tracker.js.map +0 -7
- package/dist/core/monitoring/session-monitor.js +0 -300
- package/dist/core/monitoring/session-monitor.js.map +0 -7
- package/dist/core/performance/context-cache.js +0 -273
- package/dist/core/performance/context-cache.js.map +0 -7
- package/dist/core/performance/index.js +0 -11
- package/dist/core/performance/index.js.map +0 -7
- package/dist/core/performance/lazy-context-loader.js +0 -327
- package/dist/core/performance/lazy-context-loader.js.map +0 -7
- package/dist/core/performance/monitor.js +0 -221
- package/dist/core/performance/monitor.js.map +0 -7
- package/dist/core/performance/optimized-frame-context.js +0 -345
- package/dist/core/performance/optimized-frame-context.js.map +0 -7
- package/dist/core/performance/performance-benchmark.js +0 -277
- package/dist/core/performance/performance-benchmark.js.map +0 -7
- package/dist/core/performance/performance-profiler.js +0 -370
- package/dist/core/performance/performance-profiler.js.map +0 -7
- package/dist/core/performance/streaming-jsonl-parser.js +0 -195
- package/dist/core/performance/streaming-jsonl-parser.js.map +0 -7
- package/dist/core/persistence/postgres-adapter.js +0 -349
- package/dist/core/persistence/postgres-adapter.js.map +0 -7
- package/dist/core/projects/project-isolation.js +0 -201
- package/dist/core/projects/project-isolation.js.map +0 -7
- package/dist/core/projects/project-manager.js +0 -697
- package/dist/core/projects/project-manager.js.map +0 -7
- package/dist/core/query/query-parser.js +0 -370
- package/dist/core/query/query-parser.js.map +0 -7
- package/dist/core/query/query-templates.js +0 -321
- package/dist/core/query/query-templates.js.map +0 -7
- package/dist/core/retrieval/context-retriever.js +0 -479
- package/dist/core/retrieval/context-retriever.js.map +0 -7
- package/dist/core/retrieval/graph-retrieval.js +0 -662
- package/dist/core/retrieval/graph-retrieval.js.map +0 -7
- package/dist/core/retrieval/hierarchical-retrieval.js +0 -656
- package/dist/core/retrieval/hierarchical-retrieval.js.map +0 -7
- package/dist/core/retrieval/index.js +0 -8
- package/dist/core/retrieval/index.js.map +0 -7
- package/dist/core/retrieval/llm-context-retrieval.js +0 -613
- package/dist/core/retrieval/llm-context-retrieval.js.map +0 -7
- package/dist/core/retrieval/llm-provider.js +0 -151
- package/dist/core/retrieval/llm-provider.js.map +0 -7
- package/dist/core/retrieval/retrieval-audit.js +0 -236
- package/dist/core/retrieval/retrieval-audit.js.map +0 -7
- package/dist/core/retrieval/retrieval-benchmarks.js +0 -521
- package/dist/core/retrieval/retrieval-benchmarks.js.map +0 -7
- package/dist/core/retrieval/summary-generator.js +0 -589
- package/dist/core/retrieval/summary-generator.js.map +0 -7
- package/dist/core/retrieval/types.js +0 -21
- package/dist/core/retrieval/types.js.map +0 -7
- package/dist/core/security/index.js +0 -35
- package/dist/core/security/index.js.map +0 -7
- package/dist/core/security/input-sanitizer.js +0 -321
- package/dist/core/security/input-sanitizer.js.map +0 -7
- package/dist/core/session/clear-survival.js +0 -465
- package/dist/core/session/clear-survival.js.map +0 -7
- package/dist/core/session/enhanced-handoff.js +0 -792
- package/dist/core/session/enhanced-handoff.js.map +0 -7
- package/dist/core/session/handoff-generator.js +0 -343
- package/dist/core/session/handoff-generator.js.map +0 -7
- package/dist/core/session/index.js +0 -15
- package/dist/core/session/index.js.map +0 -7
- package/dist/core/session/session-manager.js +0 -347
- package/dist/core/session/session-manager.js.map +0 -7
- package/dist/core/skills/index.js +0 -7
- package/dist/core/skills/index.js.map +0 -7
- package/dist/core/skills/skill-storage.js +0 -764
- package/dist/core/skills/skill-storage.js.map +0 -7
- package/dist/core/skills/types.js +0 -193
- package/dist/core/skills/types.js.map +0 -7
- package/dist/core/storage/chromadb-adapter.js +0 -354
- package/dist/core/storage/chromadb-adapter.js.map +0 -7
- package/dist/core/storage/infinite-storage.js +0 -510
- package/dist/core/storage/infinite-storage.js.map +0 -7
- package/dist/core/storage/railway-optimized-storage.js +0 -591
- package/dist/core/storage/railway-optimized-storage.js.map +0 -7
- package/dist/core/storage/remote-storage.js +0 -489
- package/dist/core/storage/remote-storage.js.map +0 -7
- package/dist/core/storage/two-tier-storage.js +0 -766
- package/dist/core/storage/two-tier-storage.js.map +0 -7
- package/dist/core/trace/cli-trace-wrapper.js +0 -132
- package/dist/core/trace/cli-trace-wrapper.js.map +0 -7
- package/dist/core/trace/db-trace-wrapper.js +0 -247
- package/dist/core/trace/db-trace-wrapper.js.map +0 -7
- package/dist/core/trace/debug-trace.js +0 -417
- package/dist/core/trace/debug-trace.js.map +0 -7
- package/dist/core/trace/index.js +0 -109
- package/dist/core/trace/index.js.map +0 -7
- package/dist/core/trace/linear-api-wrapper.js +0 -178
- package/dist/core/trace/linear-api-wrapper.js.map +0 -7
- package/dist/core/trace/trace-demo.js +0 -154
- package/dist/core/trace/trace-demo.js.map +0 -7
- package/dist/core/trace/trace-detector.demo.js +0 -142
- package/dist/core/trace/trace-detector.demo.js.map +0 -7
- package/dist/core/trace/trace-detector.js +0 -528
- package/dist/core/trace/trace-detector.js.map +0 -7
- package/dist/core/trace/trace-store.js +0 -345
- package/dist/core/trace/trace-store.js.map +0 -7
- package/dist/core/trace/types.js +0 -77
- package/dist/core/trace/types.js.map +0 -7
- package/dist/core/types.js +0 -5
- package/dist/core/types.js.map +0 -7
- package/dist/core/utils/async-mutex.js +0 -114
- package/dist/core/utils/async-mutex.js.map +0 -7
- package/dist/core/utils/compression.js +0 -83
- package/dist/core/utils/compression.js.map +0 -7
- package/dist/core/utils/update-checker.js +0 -218
- package/dist/core/utils/update-checker.js.map +0 -7
- package/dist/core/worktree/worktree-manager.js +0 -465
- package/dist/core/worktree/worktree-manager.js.map +0 -7
- package/dist/daemon/daemon-config.js +0 -149
- package/dist/daemon/daemon-config.js.map +0 -7
- package/dist/daemon/services/context-service.js +0 -122
- package/dist/daemon/services/context-service.js.map +0 -7
- package/dist/daemon/services/linear-service.js +0 -136
- package/dist/daemon/services/linear-service.js.map +0 -7
- package/dist/daemon/session-daemon.js +0 -312
- package/dist/daemon/session-daemon.js.map +0 -7
- package/dist/daemon/unified-daemon.js +0 -276
- package/dist/daemon/unified-daemon.js.map +0 -7
- package/dist/features/analytics/api/analytics-api.js +0 -287
- package/dist/features/analytics/api/analytics-api.js.map +0 -7
- package/dist/features/analytics/core/analytics-service.js +0 -282
- package/dist/features/analytics/core/analytics-service.js.map +0 -7
- package/dist/features/analytics/index.js +0 -18
- package/dist/features/analytics/index.js.map +0 -7
- package/dist/features/analytics/queries/metrics-queries.js +0 -277
- package/dist/features/analytics/queries/metrics-queries.js.map +0 -7
- package/dist/features/analytics/types/metrics.js +0 -5
- package/dist/features/analytics/types/metrics.js.map +0 -7
- package/dist/features/browser/browser-mcp.js +0 -492
- package/dist/features/browser/browser-mcp.js.map +0 -7
- package/dist/features/sweep/index.js +0 -20
- package/dist/features/sweep/index.js.map +0 -7
- package/dist/features/sweep/prediction-client.js +0 -155
- package/dist/features/sweep/prediction-client.js.map +0 -7
- package/dist/features/sweep/prompt-builder.js +0 -85
- package/dist/features/sweep/prompt-builder.js.map +0 -7
- package/dist/features/sweep/pty-wrapper.js +0 -171
- package/dist/features/sweep/pty-wrapper.js.map +0 -7
- package/dist/features/sweep/state-watcher.js +0 -87
- package/dist/features/sweep/state-watcher.js.map +0 -7
- package/dist/features/sweep/status-bar.js +0 -88
- package/dist/features/sweep/status-bar.js.map +0 -7
- package/dist/features/sweep/sweep-server-manager.js +0 -226
- package/dist/features/sweep/sweep-server-manager.js.map +0 -7
- package/dist/features/sweep/tab-interceptor.js +0 -38
- package/dist/features/sweep/tab-interceptor.js.map +0 -7
- package/dist/features/sweep/types.js +0 -18
- package/dist/features/sweep/types.js.map +0 -7
- package/dist/features/tasks/linear-task-manager.js +0 -487
- package/dist/features/tasks/linear-task-manager.js.map +0 -7
- package/dist/features/tasks/task-aware-context.js +0 -410
- package/dist/features/tasks/task-aware-context.js.map +0 -7
- package/dist/features/tui/simple-monitor.js +0 -116
- package/dist/features/tui/simple-monitor.js.map +0 -7
- package/dist/features/tui/swarm-monitor.js +0 -648
- package/dist/features/tui/swarm-monitor.js.map +0 -7
- package/dist/features/web/client/stores/task-store.js +0 -26
- package/dist/features/web/client/stores/task-store.js.map +0 -7
- package/dist/features/web/server/index.js +0 -194
- package/dist/features/web/server/index.js.map +0 -7
- package/dist/hooks/auto-background.js +0 -151
- package/dist/hooks/auto-background.js.map +0 -7
- package/dist/hooks/claude-code-whatsapp-hook.js +0 -197
- package/dist/hooks/claude-code-whatsapp-hook.js.map +0 -7
- package/dist/hooks/config.js +0 -150
- package/dist/hooks/config.js.map +0 -7
- package/dist/hooks/daemon.js +0 -364
- package/dist/hooks/daemon.js.map +0 -7
- package/dist/hooks/events.js +0 -58
- package/dist/hooks/events.js.map +0 -7
- package/dist/hooks/index.js +0 -12
- package/dist/hooks/index.js.map +0 -7
- package/dist/hooks/linear-task-picker.js +0 -186
- package/dist/hooks/linear-task-picker.js.map +0 -7
- package/dist/hooks/schemas.js +0 -197
- package/dist/hooks/schemas.js.map +0 -7
- package/dist/hooks/secure-fs.js +0 -49
- package/dist/hooks/secure-fs.js.map +0 -7
- package/dist/hooks/security-logger.js +0 -155
- package/dist/hooks/security-logger.js.map +0 -7
- package/dist/hooks/session-summary.js +0 -222
- package/dist/hooks/session-summary.js.map +0 -7
- package/dist/hooks/sms-action-runner.js +0 -371
- package/dist/hooks/sms-action-runner.js.map +0 -7
- package/dist/hooks/sms-notify.js +0 -506
- package/dist/hooks/sms-notify.js.map +0 -7
- package/dist/hooks/sms-watcher.js +0 -93
- package/dist/hooks/sms-watcher.js.map +0 -7
- package/dist/hooks/sms-webhook.js +0 -555
- package/dist/hooks/sms-webhook.js.map +0 -7
- package/dist/hooks/whatsapp-commands.js +0 -479
- package/dist/hooks/whatsapp-commands.js.map +0 -7
- package/dist/hooks/whatsapp-scheduler.js +0 -317
- package/dist/hooks/whatsapp-scheduler.js.map +0 -7
- package/dist/hooks/whatsapp-sync.js +0 -409
- package/dist/hooks/whatsapp-sync.js.map +0 -7
- package/dist/index.js +0 -25
- package/dist/index.js.map +0 -7
- package/dist/integrations/anthropic/client.js +0 -263
- package/dist/integrations/anthropic/client.js.map +0 -7
- package/dist/integrations/claude-code/agent-bridge.js +0 -768
- package/dist/integrations/claude-code/agent-bridge.js.map +0 -7
- package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js +0 -459
- package/dist/integrations/claude-code/enhanced-pre-clear-hooks.js.map +0 -7
- package/dist/integrations/claude-code/lifecycle-hooks.js +0 -254
- package/dist/integrations/claude-code/lifecycle-hooks.js.map +0 -7
- package/dist/integrations/claude-code/post-task-hooks.js +0 -545
- package/dist/integrations/claude-code/post-task-hooks.js.map +0 -7
- package/dist/integrations/claude-code/subagent-client-stub.js +0 -20
- package/dist/integrations/claude-code/subagent-client-stub.js.map +0 -7
- package/dist/integrations/claude-code/subagent-client.js +0 -511
- package/dist/integrations/claude-code/subagent-client.js.map +0 -7
- package/dist/integrations/claude-code/task-coordinator.js +0 -360
- package/dist/integrations/claude-code/task-coordinator.js.map +0 -7
- package/dist/integrations/linear/auth.js +0 -337
- package/dist/integrations/linear/auth.js.map +0 -7
- package/dist/integrations/linear/auto-sync.js +0 -258
- package/dist/integrations/linear/auto-sync.js.map +0 -7
- package/dist/integrations/linear/client.js +0 -634
- package/dist/integrations/linear/client.js.map +0 -7
- package/dist/integrations/linear/config.js +0 -130
- package/dist/integrations/linear/config.js.map +0 -7
- package/dist/integrations/linear/migration.js +0 -361
- package/dist/integrations/linear/migration.js.map +0 -7
- package/dist/integrations/linear/oauth-server.js +0 -454
- package/dist/integrations/linear/oauth-server.js.map +0 -7
- package/dist/integrations/linear/rest-client.js +0 -213
- package/dist/integrations/linear/rest-client.js.map +0 -7
- package/dist/integrations/linear/sync-manager.js +0 -236
- package/dist/integrations/linear/sync-manager.js.map +0 -7
- package/dist/integrations/linear/sync-service.js +0 -231
- package/dist/integrations/linear/sync-service.js.map +0 -7
- package/dist/integrations/linear/sync.js +0 -782
- package/dist/integrations/linear/sync.js.map +0 -7
- package/dist/integrations/linear/types.js +0 -5
- package/dist/integrations/linear/types.js.map +0 -7
- package/dist/integrations/linear/unified-sync.js +0 -589
- package/dist/integrations/linear/unified-sync.js.map +0 -7
- package/dist/integrations/linear/webhook-handler.js +0 -219
- package/dist/integrations/linear/webhook-handler.js.map +0 -7
- package/dist/integrations/linear/webhook-server.js +0 -218
- package/dist/integrations/linear/webhook-server.js.map +0 -7
- package/dist/integrations/linear/webhook.js +0 -291
- package/dist/integrations/linear/webhook.js.map +0 -7
- package/dist/integrations/mcp/handlers/code-execution-handlers.js +0 -266
- package/dist/integrations/mcp/handlers/code-execution-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/context-handlers.js +0 -257
- package/dist/integrations/mcp/handlers/context-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/discovery-handlers.js +0 -497
- package/dist/integrations/mcp/handlers/discovery-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/index.js +0 -166
- package/dist/integrations/mcp/handlers/index.js.map +0 -7
- package/dist/integrations/mcp/handlers/linear-handlers.js +0 -247
- package/dist/integrations/mcp/handlers/linear-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/skill-handlers.js +0 -529
- package/dist/integrations/mcp/handlers/skill-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/task-handlers.js +0 -239
- package/dist/integrations/mcp/handlers/task-handlers.js.map +0 -7
- package/dist/integrations/mcp/handlers/trace-handlers.js +0 -308
- package/dist/integrations/mcp/handlers/trace-handlers.js.map +0 -7
- package/dist/integrations/mcp/index.js +0 -23
- package/dist/integrations/mcp/index.js.map +0 -7
- package/dist/integrations/mcp/middleware/tool-scoring.js +0 -356
- package/dist/integrations/mcp/middleware/tool-scoring.js.map +0 -7
- package/dist/integrations/mcp/refactored-server.js +0 -374
- package/dist/integrations/mcp/refactored-server.js.map +0 -7
- package/dist/integrations/mcp/remote-server.js +0 -682
- package/dist/integrations/mcp/remote-server.js.map +0 -7
- package/dist/integrations/mcp/schemas.js +0 -147
- package/dist/integrations/mcp/schemas.js.map +0 -7
- package/dist/integrations/mcp/server.js +0 -1975
- package/dist/integrations/mcp/server.js.map +0 -7
- package/dist/integrations/mcp/tool-definitions-code.js +0 -125
- package/dist/integrations/mcp/tool-definitions-code.js.map +0 -7
- package/dist/integrations/mcp/tool-definitions.js +0 -702
- package/dist/integrations/mcp/tool-definitions.js.map +0 -7
- package/dist/integrations/mcp/trace-test.js +0 -48
- package/dist/integrations/mcp/trace-test.js.map +0 -7
- package/dist/integrations/pg-aiguide/embedding-provider.js +0 -189
- package/dist/integrations/pg-aiguide/embedding-provider.js.map +0 -7
- package/dist/integrations/pg-aiguide/semantic-search.js +0 -187
- package/dist/integrations/pg-aiguide/semantic-search.js.map +0 -7
- package/dist/integrations/pg-aiguide/timescale-analytics.js +0 -224
- package/dist/integrations/pg-aiguide/timescale-analytics.js.map +0 -7
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -860
- package/dist/integrations/ralph/bridge/ralph-stackmemory-bridge.js.map +0 -7
- package/dist/integrations/ralph/context/context-budget-manager.js +0 -301
- package/dist/integrations/ralph/context/context-budget-manager.js.map +0 -7
- package/dist/integrations/ralph/context/stackmemory-context-loader.js +0 -360
- package/dist/integrations/ralph/context/stackmemory-context-loader.js.map +0 -7
- package/dist/integrations/ralph/coordination/enhanced-coordination.js +0 -410
- package/dist/integrations/ralph/coordination/enhanced-coordination.js.map +0 -7
- package/dist/integrations/ralph/index.js +0 -18
- package/dist/integrations/ralph/index.js.map +0 -7
- package/dist/integrations/ralph/learning/pattern-learner.js +0 -401
- package/dist/integrations/ralph/learning/pattern-learner.js.map +0 -7
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
- package/dist/integrations/ralph/lifecycle/iteration-lifecycle.js.map +0 -7
- package/dist/integrations/ralph/monitoring/swarm-dashboard.js +0 -294
- package/dist/integrations/ralph/monitoring/swarm-dashboard.js.map +0 -7
- package/dist/integrations/ralph/monitoring/swarm-registry.js +0 -108
- package/dist/integrations/ralph/monitoring/swarm-registry.js.map +0 -7
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -463
- package/dist/integrations/ralph/orchestration/multi-loop-orchestrator.js.map +0 -7
- package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -400
- package/dist/integrations/ralph/patterns/compounding-engineering-pattern.js.map +0 -7
- package/dist/integrations/ralph/patterns/extended-coherence-sessions.js +0 -473
- package/dist/integrations/ralph/patterns/extended-coherence-sessions.js.map +0 -7
- package/dist/integrations/ralph/patterns/oracle-worker-pattern.js +0 -388
- package/dist/integrations/ralph/patterns/oracle-worker-pattern.js.map +0 -7
- package/dist/integrations/ralph/performance/performance-optimizer.js +0 -358
- package/dist/integrations/ralph/performance/performance-optimizer.js.map +0 -7
- package/dist/integrations/ralph/ralph-integration-demo.js +0 -182
- package/dist/integrations/ralph/ralph-integration-demo.js.map +0 -7
- package/dist/integrations/ralph/recovery/crash-recovery.js +0 -462
- package/dist/integrations/ralph/recovery/crash-recovery.js.map +0 -7
- package/dist/integrations/ralph/state/state-reconciler.js +0 -404
- package/dist/integrations/ralph/state/state-reconciler.js.map +0 -7
- package/dist/integrations/ralph/swarm/git-workflow-manager.js +0 -428
- package/dist/integrations/ralph/swarm/git-workflow-manager.js.map +0 -7
- package/dist/integrations/ralph/swarm/swarm-coordinator.js +0 -996
- package/dist/integrations/ralph/swarm/swarm-coordinator.js.map +0 -7
- package/dist/integrations/ralph/types.js +0 -5
- package/dist/integrations/ralph/types.js.map +0 -7
- package/dist/integrations/ralph/visualization/ralph-debugger.js +0 -585
- package/dist/integrations/ralph/visualization/ralph-debugger.js.map +0 -7
- package/dist/mcp/stackmemory-mcp-server.js +0 -554
- package/dist/mcp/stackmemory-mcp-server.js.map +0 -7
- package/dist/middleware/exponential-rate-limiter.js +0 -289
- package/dist/middleware/exponential-rate-limiter.js.map +0 -7
- package/dist/models/user.model.js +0 -358
- package/dist/models/user.model.js.map +0 -7
- package/dist/servers/production/auth-middleware.js +0 -528
- package/dist/servers/production/auth-middleware.js.map +0 -7
- package/dist/servers/railway/config.js +0 -55
- package/dist/servers/railway/config.js.map +0 -7
- package/dist/servers/railway/index-enhanced.js +0 -160
- package/dist/servers/railway/index-enhanced.js.map +0 -7
- package/dist/servers/railway/index.js +0 -1349
- package/dist/servers/railway/index.js.map +0 -7
- package/dist/servers/railway/simple.js +0 -64
- package/dist/servers/railway/simple.js.map +0 -7
- package/dist/servers/railway/storage-test.js +0 -459
- package/dist/servers/railway/storage-test.js.map +0 -7
- package/dist/services/config-service.js +0 -65
- package/dist/services/config-service.js.map +0 -7
- package/dist/services/context-service.js +0 -194
- package/dist/services/context-service.js.map +0 -7
- package/dist/skills/api-discovery.js +0 -354
- package/dist/skills/api-discovery.js.map +0 -7
- package/dist/skills/api-skill.js +0 -475
- package/dist/skills/api-skill.js.map +0 -7
- package/dist/skills/claude-skills.js +0 -1061
- package/dist/skills/claude-skills.js.map +0 -7
- package/dist/skills/dashboard-launcher.js +0 -216
- package/dist/skills/dashboard-launcher.js.map +0 -7
- package/dist/skills/recursive-agent-orchestrator.js +0 -575
- package/dist/skills/recursive-agent-orchestrator.js.map +0 -7
- package/dist/skills/repo-ingestion-skill.js +0 -609
- package/dist/skills/repo-ingestion-skill.js.map +0 -7
- package/dist/skills/security-secrets-scanner.js +0 -284
- package/dist/skills/security-secrets-scanner.js.map +0 -7
- package/dist/skills/unified-rlm-orchestrator.js +0 -404
- package/dist/skills/unified-rlm-orchestrator.js.map +0 -7
- package/dist/types/task.js +0 -5
- package/dist/types/task.js.map +0 -7
- package/dist/utils/env.js +0 -50
- package/dist/utils/env.js.map +0 -7
- package/dist/utils/formatting.js +0 -62
- package/dist/utils/formatting.js.map +0 -7
- package/dist/utils/process-cleanup.js +0 -136
- package/dist/utils/process-cleanup.js.map +0 -7
- package/dist/validation/schemas.js +0 -222
- package/dist/validation/schemas.js.map +0 -7
- /package/dist/{core/merge → src/core/extensions}/types.js +0 -0
- /package/dist/{core/merge → src/core/extensions}/types.js.map +0 -0
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
-
import { dirname as __pathDirname } from 'path';
|
|
3
|
-
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
-
const __dirname = __pathDirname(__filename);
|
|
5
|
-
import Database from "better-sqlite3";
|
|
6
|
-
import {
|
|
7
|
-
S3Client,
|
|
8
|
-
PutObjectCommand,
|
|
9
|
-
GetObjectCommand
|
|
10
|
-
} from "@aws-sdk/client-s3";
|
|
11
|
-
import { createClient as createRedisClient } from "redis";
|
|
12
|
-
import { Pool } from "pg";
|
|
13
|
-
import * as zlib from "zlib";
|
|
14
|
-
import { promisify } from "util";
|
|
15
|
-
import { v4 as uuidv4 } from "uuid";
|
|
16
|
-
import { Logger } from "../monitoring/logger.js";
|
|
17
|
-
const lz4 = {
|
|
18
|
-
encode: (data) => data,
|
|
19
|
-
// Placeholder
|
|
20
|
-
decode: (data) => data
|
|
21
|
-
// Placeholder
|
|
22
|
-
};
|
|
23
|
-
const gzip = promisify(zlib.gzip);
|
|
24
|
-
const gunzip = promisify(zlib.gunzip);
|
|
25
|
-
var StorageTier = /* @__PURE__ */ ((StorageTier2) => {
|
|
26
|
-
StorageTier2["YOUNG"] = "young";
|
|
27
|
-
StorageTier2["MATURE"] = "mature";
|
|
28
|
-
StorageTier2["OLD"] = "old";
|
|
29
|
-
StorageTier2["REMOTE"] = "remote";
|
|
30
|
-
return StorageTier2;
|
|
31
|
-
})(StorageTier || {});
|
|
32
|
-
class TwoTierStorageSystem {
|
|
33
|
-
db;
|
|
34
|
-
redisClient;
|
|
35
|
-
timeseriesPool;
|
|
36
|
-
s3Client;
|
|
37
|
-
logger;
|
|
38
|
-
config;
|
|
39
|
-
migrationTimer;
|
|
40
|
-
offlineQueue = [];
|
|
41
|
-
stats;
|
|
42
|
-
constructor(config) {
|
|
43
|
-
this.config = config;
|
|
44
|
-
this.logger = new Logger("TwoTierStorage");
|
|
45
|
-
this.db = new Database(config.local.dbPath);
|
|
46
|
-
this.initializeLocalStorage();
|
|
47
|
-
this.s3Client = new S3Client({
|
|
48
|
-
region: config.remote.s3.region,
|
|
49
|
-
credentials: config.remote.s3.accessKeyId && config.remote.s3.secretAccessKey ? {
|
|
50
|
-
accessKeyId: config.remote.s3.accessKeyId,
|
|
51
|
-
secretAccessKey: config.remote.s3.secretAccessKey
|
|
52
|
-
} : void 0
|
|
53
|
-
});
|
|
54
|
-
this.stats = {
|
|
55
|
-
localUsageMB: 0,
|
|
56
|
-
remoteUsageMB: 0,
|
|
57
|
-
tierDistribution: {
|
|
58
|
-
["young" /* YOUNG */]: 0,
|
|
59
|
-
["mature" /* MATURE */]: 0,
|
|
60
|
-
["old" /* OLD */]: 0,
|
|
61
|
-
["remote" /* REMOTE */]: 0
|
|
62
|
-
},
|
|
63
|
-
compressionRatio: 1,
|
|
64
|
-
migrationsPending: 0,
|
|
65
|
-
lastMigration: null
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
initializeLocalStorage() {
|
|
69
|
-
this.db.pragma("journal_mode = WAL");
|
|
70
|
-
this.db.pragma("synchronous = NORMAL");
|
|
71
|
-
this.db.exec(`
|
|
72
|
-
CREATE TABLE IF NOT EXISTS storage_items (
|
|
73
|
-
id TEXT PRIMARY KEY,
|
|
74
|
-
frame_id TEXT NOT NULL,
|
|
75
|
-
tier TEXT NOT NULL,
|
|
76
|
-
data BLOB NOT NULL,
|
|
77
|
-
metadata TEXT,
|
|
78
|
-
size_bytes INTEGER,
|
|
79
|
-
importance_score REAL DEFAULT 0.5,
|
|
80
|
-
access_count INTEGER DEFAULT 0,
|
|
81
|
-
last_accessed DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
82
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
83
|
-
compressed BOOLEAN DEFAULT FALSE,
|
|
84
|
-
compression_type TEXT
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
CREATE INDEX IF NOT EXISTS idx_tier_age ON storage_items (tier, created_at);
|
|
88
|
-
CREATE INDEX IF NOT EXISTS idx_frame ON storage_items (frame_id);
|
|
89
|
-
CREATE INDEX IF NOT EXISTS idx_importance ON storage_items (importance_score DESC);
|
|
90
|
-
|
|
91
|
-
CREATE TABLE IF NOT EXISTS migration_queue (
|
|
92
|
-
id TEXT PRIMARY KEY,
|
|
93
|
-
item_id TEXT NOT NULL,
|
|
94
|
-
source_tier TEXT NOT NULL,
|
|
95
|
-
target_tier TEXT NOT NULL,
|
|
96
|
-
priority INTEGER DEFAULT 5,
|
|
97
|
-
attempts INTEGER DEFAULT 0,
|
|
98
|
-
status TEXT DEFAULT 'pending',
|
|
99
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
CREATE INDEX IF NOT EXISTS idx_status_priority ON migration_queue (status, priority DESC);
|
|
103
|
-
|
|
104
|
-
CREATE TABLE IF NOT EXISTS storage_metrics (
|
|
105
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
106
|
-
tier TEXT NOT NULL,
|
|
107
|
-
item_count INTEGER,
|
|
108
|
-
total_size_mb REAL,
|
|
109
|
-
avg_compression_ratio REAL,
|
|
110
|
-
measured_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
111
|
-
);
|
|
112
|
-
`);
|
|
113
|
-
}
|
|
114
|
-
async initialize() {
|
|
115
|
-
try {
|
|
116
|
-
if (this.config.remote.redis?.url) {
|
|
117
|
-
this.redisClient = createRedisClient({
|
|
118
|
-
url: this.config.remote.redis.url
|
|
119
|
-
});
|
|
120
|
-
await this.redisClient.connect();
|
|
121
|
-
this.logger.info("Redis connected for hot cache");
|
|
122
|
-
}
|
|
123
|
-
if (this.config.remote.timeseries?.connectionString) {
|
|
124
|
-
this.timeseriesPool = new Pool({
|
|
125
|
-
connectionString: this.config.remote.timeseries.connectionString,
|
|
126
|
-
max: 5
|
|
127
|
-
});
|
|
128
|
-
await this.initializeTimeseriesSchema();
|
|
129
|
-
this.logger.info("TimeSeries DB connected");
|
|
130
|
-
}
|
|
131
|
-
this.startMigrationWorker();
|
|
132
|
-
await this.loadOfflineQueue();
|
|
133
|
-
await this.updateStats();
|
|
134
|
-
this.logger.info("Two-tier storage system initialized");
|
|
135
|
-
} catch (error) {
|
|
136
|
-
this.logger.error("Failed to initialize storage", { error });
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async initializeTimeseriesSchema() {
|
|
141
|
-
if (!this.timeseriesPool) return;
|
|
142
|
-
const client = await this.timeseriesPool.connect();
|
|
143
|
-
try {
|
|
144
|
-
await client.query(`
|
|
145
|
-
CREATE TABLE IF NOT EXISTS frame_timeseries (
|
|
146
|
-
time TIMESTAMPTZ NOT NULL,
|
|
147
|
-
frame_id TEXT NOT NULL,
|
|
148
|
-
project_id TEXT NOT NULL,
|
|
149
|
-
data JSONB,
|
|
150
|
-
metrics JSONB,
|
|
151
|
-
importance_score REAL
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
SELECT create_hypertable('frame_timeseries', 'time',
|
|
155
|
-
chunk_time_interval => INTERVAL '1 month',
|
|
156
|
-
if_not_exists => TRUE
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
CREATE INDEX IF NOT EXISTS idx_frame_time
|
|
160
|
-
ON frame_timeseries (frame_id, time DESC);
|
|
161
|
-
`);
|
|
162
|
-
} finally {
|
|
163
|
-
client.release();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Store a frame with automatic tier selection
|
|
168
|
-
*/
|
|
169
|
-
async storeFrame(frame, events, anchors) {
|
|
170
|
-
const storageId = uuidv4();
|
|
171
|
-
const data = { frame, events, anchors };
|
|
172
|
-
const tier = this.selectTier(frame);
|
|
173
|
-
const importanceScore = this.calculateImportance(frame, events, anchors);
|
|
174
|
-
const compressed = await this.compressData(data, tier);
|
|
175
|
-
const stmt = this.db.prepare(`
|
|
176
|
-
INSERT INTO storage_items (
|
|
177
|
-
id, frame_id, tier, data, metadata, size_bytes,
|
|
178
|
-
importance_score, compressed, compression_type
|
|
179
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
180
|
-
`);
|
|
181
|
-
stmt.run(
|
|
182
|
-
storageId,
|
|
183
|
-
frame.frame_id,
|
|
184
|
-
tier,
|
|
185
|
-
compressed.data,
|
|
186
|
-
JSON.stringify({
|
|
187
|
-
originalSize: compressed.originalSize,
|
|
188
|
-
compressedSize: compressed.compressedSize
|
|
189
|
-
}),
|
|
190
|
-
compressed.compressedSize,
|
|
191
|
-
importanceScore,
|
|
192
|
-
compressed.compressed ? 1 : 0,
|
|
193
|
-
compressed.compressionType
|
|
194
|
-
);
|
|
195
|
-
if (tier === "young" /* YOUNG */ && this.redisClient) {
|
|
196
|
-
await this.redisClient.setex(
|
|
197
|
-
`frame:${frame.frame_id}`,
|
|
198
|
-
this.config.remote.redis?.ttlSeconds || 300,
|
|
199
|
-
JSON.stringify(data)
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
if (importanceScore > 0.7) {
|
|
203
|
-
await this.queueRemoteUpload(storageId, data, "high");
|
|
204
|
-
}
|
|
205
|
-
return storageId;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Retrieve a frame from any tier
|
|
209
|
-
*/
|
|
210
|
-
async retrieveFrame(frameId) {
|
|
211
|
-
if (this.redisClient) {
|
|
212
|
-
try {
|
|
213
|
-
const cached = await this.redisClient.get(`frame:${frameId}`);
|
|
214
|
-
if (cached) {
|
|
215
|
-
this.updateAccessCount(frameId);
|
|
216
|
-
return JSON.parse(cached);
|
|
217
|
-
}
|
|
218
|
-
} catch (error) {
|
|
219
|
-
this.logger.warn("Redis retrieval failed", { frameId, error });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const local = this.db.prepare(
|
|
223
|
-
`
|
|
224
|
-
SELECT data, compressed, compression_type
|
|
225
|
-
FROM storage_items
|
|
226
|
-
WHERE frame_id = ?
|
|
227
|
-
ORDER BY created_at DESC
|
|
228
|
-
LIMIT 1
|
|
229
|
-
`
|
|
230
|
-
).get(frameId);
|
|
231
|
-
if (local) {
|
|
232
|
-
this.updateAccessCount(frameId);
|
|
233
|
-
const data = local.compressed ? await this.decompressData(local.data, local.compression_type) : JSON.parse(local.data);
|
|
234
|
-
if (this.redisClient) {
|
|
235
|
-
await this.redisClient.setex(
|
|
236
|
-
`frame:${frameId}`,
|
|
237
|
-
300,
|
|
238
|
-
// 5 minute cache
|
|
239
|
-
JSON.stringify(data)
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
return data;
|
|
243
|
-
}
|
|
244
|
-
return this.retrieveFromRemote(frameId);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Select appropriate tier based on frame age and characteristics
|
|
248
|
-
*/
|
|
249
|
-
selectTier(frame) {
|
|
250
|
-
if (!frame.created_at || isNaN(frame.created_at)) {
|
|
251
|
-
this.logger.warn("Invalid frame timestamp, defaulting to YOUNG tier");
|
|
252
|
-
return "young" /* YOUNG */;
|
|
253
|
-
}
|
|
254
|
-
const ageHours = (Date.now() - frame.created_at) / (1e3 * 60 * 60);
|
|
255
|
-
if (ageHours < 24) return "young" /* YOUNG */;
|
|
256
|
-
if (ageHours < 168) return "mature" /* MATURE */;
|
|
257
|
-
if (ageHours < 720) return "old" /* OLD */;
|
|
258
|
-
return "remote" /* REMOTE */;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Calculate importance score for migration decisions
|
|
262
|
-
*/
|
|
263
|
-
calculateImportance(frame, events, anchors) {
|
|
264
|
-
let score = 0.5;
|
|
265
|
-
const decisions = anchors.filter((a) => a.type === "DECISION");
|
|
266
|
-
score += decisions.length * 0.1;
|
|
267
|
-
score += Math.min(events.length * 0.01, 0.2);
|
|
268
|
-
const ageHours = (Date.now() - frame.created_at) / (1e3 * 60 * 60);
|
|
269
|
-
if (ageHours < 24) score += 0.2;
|
|
270
|
-
else if (ageHours < 168) score += 0.1;
|
|
271
|
-
const errors = events.filter((e) => e.event_type === "error");
|
|
272
|
-
if (errors.length > 0) score += 0.2;
|
|
273
|
-
return Math.min(score, 1);
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Compress data based on tier configuration
|
|
277
|
-
*/
|
|
278
|
-
async compressData(data, tier) {
|
|
279
|
-
const json = JSON.stringify(data);
|
|
280
|
-
const originalSize = Buffer.byteLength(json);
|
|
281
|
-
const tierConfig = this.config.local.tiers.find((t) => t.name === tier);
|
|
282
|
-
if (!tierConfig || tierConfig.compressionType === "none") {
|
|
283
|
-
return {
|
|
284
|
-
data: Buffer.from(json),
|
|
285
|
-
originalSize,
|
|
286
|
-
compressedSize: originalSize,
|
|
287
|
-
compressed: false,
|
|
288
|
-
compressionType: "none"
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
let compressed;
|
|
292
|
-
switch (tierConfig.compressionType) {
|
|
293
|
-
case "lz4":
|
|
294
|
-
compressed = lz4.encode(Buffer.from(json));
|
|
295
|
-
break;
|
|
296
|
-
case "zstd":
|
|
297
|
-
compressed = await gzip(json, { level: 9 });
|
|
298
|
-
break;
|
|
299
|
-
case "gzip":
|
|
300
|
-
compressed = await gzip(json);
|
|
301
|
-
break;
|
|
302
|
-
default:
|
|
303
|
-
compressed = Buffer.from(json);
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
data: compressed,
|
|
307
|
-
originalSize,
|
|
308
|
-
compressedSize: compressed.length,
|
|
309
|
-
compressed: true,
|
|
310
|
-
compressionType: tierConfig.compressionType
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Decompress data
|
|
315
|
-
*/
|
|
316
|
-
async decompressData(data, compressionType) {
|
|
317
|
-
let decompressed;
|
|
318
|
-
switch (compressionType) {
|
|
319
|
-
case "lz4":
|
|
320
|
-
decompressed = lz4.decode(data);
|
|
321
|
-
break;
|
|
322
|
-
case "zstd":
|
|
323
|
-
case "gzip":
|
|
324
|
-
decompressed = await gunzip(data);
|
|
325
|
-
break;
|
|
326
|
-
default:
|
|
327
|
-
decompressed = data;
|
|
328
|
-
}
|
|
329
|
-
return JSON.parse(decompressed.toString());
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Start background migration worker
|
|
333
|
-
*/
|
|
334
|
-
startMigrationWorker() {
|
|
335
|
-
this.migrationTimer = setInterval(async () => {
|
|
336
|
-
try {
|
|
337
|
-
await this.processMigrations();
|
|
338
|
-
await this.checkMigrationTriggers();
|
|
339
|
-
await this.processOfflineQueue();
|
|
340
|
-
} catch (error) {
|
|
341
|
-
this.logger.error("Migration worker error", { error });
|
|
342
|
-
}
|
|
343
|
-
}, this.config.migration.intervalMs);
|
|
344
|
-
this.logger.info("Migration worker started");
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Process pending migrations
|
|
348
|
-
*/
|
|
349
|
-
async processMigrations() {
|
|
350
|
-
const pending = this.db.prepare(
|
|
351
|
-
`
|
|
352
|
-
SELECT * FROM migration_queue
|
|
353
|
-
WHERE status = 'pending'
|
|
354
|
-
ORDER BY priority DESC, created_at ASC
|
|
355
|
-
LIMIT ?
|
|
356
|
-
`
|
|
357
|
-
).all(this.config.migration.batchSize);
|
|
358
|
-
for (const migration of pending) {
|
|
359
|
-
try {
|
|
360
|
-
await this.executeMigration(migration);
|
|
361
|
-
this.db.prepare(
|
|
362
|
-
`
|
|
363
|
-
UPDATE migration_queue
|
|
364
|
-
SET status = 'completed'
|
|
365
|
-
WHERE id = ?
|
|
366
|
-
`
|
|
367
|
-
).run(migration.id);
|
|
368
|
-
} catch (error) {
|
|
369
|
-
this.logger.error("Migration failed", { migration, error });
|
|
370
|
-
this.db.prepare(
|
|
371
|
-
`
|
|
372
|
-
UPDATE migration_queue
|
|
373
|
-
SET attempts = attempts + 1,
|
|
374
|
-
status = CASE WHEN attempts >= 3 THEN 'failed' ELSE 'pending' END
|
|
375
|
-
WHERE id = ?
|
|
376
|
-
`
|
|
377
|
-
).run(migration.id);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
this.stats.lastMigration = /* @__PURE__ */ new Date();
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Check and trigger migrations based on rules
|
|
384
|
-
*/
|
|
385
|
-
async checkMigrationTriggers() {
|
|
386
|
-
for (const trigger of this.config.migration.triggers) {
|
|
387
|
-
if (trigger.type === "age") {
|
|
388
|
-
const items = this.db.prepare(
|
|
389
|
-
`
|
|
390
|
-
SELECT id, frame_id, tier
|
|
391
|
-
FROM storage_items
|
|
392
|
-
WHERE julianday('now') - julianday(created_at) > ?
|
|
393
|
-
AND tier != ?
|
|
394
|
-
LIMIT 100
|
|
395
|
-
`
|
|
396
|
-
).all(trigger.threshold / 24, "remote" /* REMOTE */);
|
|
397
|
-
for (const item of items) {
|
|
398
|
-
this.queueMigration(item.id, item.tier, "remote" /* REMOTE */);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
if (trigger.type === "size") {
|
|
402
|
-
const stats = this.db.prepare(
|
|
403
|
-
`
|
|
404
|
-
SELECT SUM(size_bytes) as total_size
|
|
405
|
-
FROM storage_items
|
|
406
|
-
WHERE tier IN ('young', 'mature')
|
|
407
|
-
`
|
|
408
|
-
).get();
|
|
409
|
-
if (stats.total_size > trigger.threshold * 1024 * 1024) {
|
|
410
|
-
const items = this.db.prepare(
|
|
411
|
-
`
|
|
412
|
-
SELECT id, tier FROM storage_items
|
|
413
|
-
WHERE tier IN ('young', 'mature')
|
|
414
|
-
ORDER BY created_at ASC
|
|
415
|
-
LIMIT 50
|
|
416
|
-
`
|
|
417
|
-
).all();
|
|
418
|
-
for (const item of items) {
|
|
419
|
-
const targetTier = item.tier === "young" /* YOUNG */ ? "mature" /* MATURE */ : "old" /* OLD */;
|
|
420
|
-
this.queueMigration(item.id, item.tier, targetTier);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Queue a migration
|
|
428
|
-
*/
|
|
429
|
-
queueMigration(itemId, sourceTier, targetTier, priority = 5) {
|
|
430
|
-
const id = uuidv4();
|
|
431
|
-
this.db.prepare(
|
|
432
|
-
`
|
|
433
|
-
INSERT INTO migration_queue (id, item_id, source_tier, target_tier, priority)
|
|
434
|
-
VALUES (?, ?, ?, ?, ?)
|
|
435
|
-
`
|
|
436
|
-
).run(id, itemId, sourceTier, targetTier, priority);
|
|
437
|
-
this.stats.migrationsPending++;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Execute a single migration
|
|
441
|
-
*/
|
|
442
|
-
async executeMigration(migration) {
|
|
443
|
-
const item = this.db.prepare(
|
|
444
|
-
`
|
|
445
|
-
SELECT * FROM storage_items WHERE id = ?
|
|
446
|
-
`
|
|
447
|
-
).get(migration.item_id);
|
|
448
|
-
if (!item) {
|
|
449
|
-
throw new Error(`Item not found: ${migration.item_id}`);
|
|
450
|
-
}
|
|
451
|
-
const data = item.compressed ? await this.decompressData(item.data, item.compression_type) : JSON.parse(item.data);
|
|
452
|
-
if (migration.target_tier === "remote" /* REMOTE */) {
|
|
453
|
-
await this.uploadToS3(item.frame_id, data);
|
|
454
|
-
this.db.prepare(
|
|
455
|
-
`
|
|
456
|
-
DELETE FROM storage_items WHERE id = ?
|
|
457
|
-
`
|
|
458
|
-
).run(migration.item_id);
|
|
459
|
-
} else {
|
|
460
|
-
const compressed = await this.compressData(data, migration.target_tier);
|
|
461
|
-
this.db.prepare(
|
|
462
|
-
`
|
|
463
|
-
UPDATE storage_items
|
|
464
|
-
SET tier = ?, data = ?, size_bytes = ?,
|
|
465
|
-
compressed = ?, compression_type = ?
|
|
466
|
-
WHERE id = ?
|
|
467
|
-
`
|
|
468
|
-
).run(
|
|
469
|
-
migration.target_tier,
|
|
470
|
-
compressed.data,
|
|
471
|
-
compressed.compressedSize,
|
|
472
|
-
compressed.compressed ? 1 : 0,
|
|
473
|
-
compressed.compressionType,
|
|
474
|
-
migration.item_id
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
this.logger.info("Migration completed", {
|
|
478
|
-
itemId: migration.item_id,
|
|
479
|
-
from: migration.source_tier,
|
|
480
|
-
to: migration.target_tier
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Upload data to S3
|
|
485
|
-
*/
|
|
486
|
-
async uploadToS3(frameId, data) {
|
|
487
|
-
const date = /* @__PURE__ */ new Date();
|
|
488
|
-
const partition = `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, "0")}`;
|
|
489
|
-
const key = `frames/${partition}/${frameId}.json.gz`;
|
|
490
|
-
const compressed = await gzip(JSON.stringify(data));
|
|
491
|
-
const command = new PutObjectCommand({
|
|
492
|
-
Bucket: this.config.remote.s3.bucket,
|
|
493
|
-
Key: key,
|
|
494
|
-
Body: compressed,
|
|
495
|
-
ContentType: "application/json",
|
|
496
|
-
ContentEncoding: "gzip",
|
|
497
|
-
Metadata: {
|
|
498
|
-
frameId,
|
|
499
|
-
uploadedAt: date.toISOString()
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
await this.s3Client.send(command);
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Retrieve from remote storage
|
|
506
|
-
*/
|
|
507
|
-
async retrieveFromRemote(frameId) {
|
|
508
|
-
if (this.timeseriesPool) {
|
|
509
|
-
const client = await this.timeseriesPool.connect();
|
|
510
|
-
try {
|
|
511
|
-
const result = await client.query(
|
|
512
|
-
`
|
|
513
|
-
SELECT data FROM frame_timeseries
|
|
514
|
-
WHERE frame_id = $1
|
|
515
|
-
ORDER BY time DESC
|
|
516
|
-
LIMIT 1
|
|
517
|
-
`,
|
|
518
|
-
[frameId]
|
|
519
|
-
);
|
|
520
|
-
if (result.rows.length > 0) {
|
|
521
|
-
return result.rows[0].data;
|
|
522
|
-
}
|
|
523
|
-
} finally {
|
|
524
|
-
client.release();
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
const date = /* @__PURE__ */ new Date();
|
|
528
|
-
for (let i = 0; i < 3; i++) {
|
|
529
|
-
const checkDate = new Date(date);
|
|
530
|
-
checkDate.setMonth(checkDate.getMonth() - i);
|
|
531
|
-
const partition = `${checkDate.getFullYear()}/${String(checkDate.getMonth() + 1).padStart(2, "0")}`;
|
|
532
|
-
const key = `frames/${partition}/${frameId}.json.gz`;
|
|
533
|
-
try {
|
|
534
|
-
const command = new GetObjectCommand({
|
|
535
|
-
Bucket: this.config.remote.s3.bucket,
|
|
536
|
-
Key: key
|
|
537
|
-
});
|
|
538
|
-
const response = await this.s3Client.send(command);
|
|
539
|
-
if (!response.Body) continue;
|
|
540
|
-
const body = await response.Body.transformToByteArray();
|
|
541
|
-
const decompressed = await gunzip(Buffer.from(body));
|
|
542
|
-
return JSON.parse(decompressed.toString());
|
|
543
|
-
} catch {
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Queue for offline upload
|
|
550
|
-
*/
|
|
551
|
-
async queueRemoteUpload(id, data, priority) {
|
|
552
|
-
this.offlineQueue.push({
|
|
553
|
-
id,
|
|
554
|
-
data,
|
|
555
|
-
priority,
|
|
556
|
-
timestamp: Date.now()
|
|
557
|
-
});
|
|
558
|
-
if (this.config.migration.offlineQueuePath) {
|
|
559
|
-
await this.saveOfflineQueue();
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Process offline upload queue
|
|
564
|
-
*/
|
|
565
|
-
async processOfflineQueue() {
|
|
566
|
-
if (this.offlineQueue.length === 0) return;
|
|
567
|
-
const isOnline = await this.checkConnectivity();
|
|
568
|
-
if (!isOnline) return;
|
|
569
|
-
this.offlineQueue.sort((a, b) => {
|
|
570
|
-
if (a.priority !== b.priority) {
|
|
571
|
-
return a.priority === "high" ? -1 : 1;
|
|
572
|
-
}
|
|
573
|
-
return a.timestamp - b.timestamp;
|
|
574
|
-
});
|
|
575
|
-
const batch = this.offlineQueue.splice(0, 10);
|
|
576
|
-
for (const item of batch) {
|
|
577
|
-
try {
|
|
578
|
-
await this.uploadToS3(item.id, item.data);
|
|
579
|
-
} catch {
|
|
580
|
-
this.offlineQueue.push(item);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
await this.saveOfflineQueue();
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Check connectivity to remote services
|
|
587
|
-
*/
|
|
588
|
-
async checkConnectivity() {
|
|
589
|
-
try {
|
|
590
|
-
const response = await fetch("https://s3.amazonaws.com");
|
|
591
|
-
return response.ok;
|
|
592
|
-
} catch {
|
|
593
|
-
return false;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Update access count for cache promotion
|
|
598
|
-
*/
|
|
599
|
-
updateAccessCount(frameId) {
|
|
600
|
-
this.db.prepare(
|
|
601
|
-
`
|
|
602
|
-
UPDATE storage_items
|
|
603
|
-
SET access_count = access_count + 1,
|
|
604
|
-
last_accessed = CURRENT_TIMESTAMP
|
|
605
|
-
WHERE frame_id = ?
|
|
606
|
-
`
|
|
607
|
-
).run(frameId);
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Save offline queue to disk
|
|
611
|
-
*/
|
|
612
|
-
async saveOfflineQueue() {
|
|
613
|
-
if (!this.config.migration.offlineQueuePath) return;
|
|
614
|
-
const fs = await import("fs/promises");
|
|
615
|
-
await fs.writeFile(
|
|
616
|
-
this.config.migration.offlineQueuePath,
|
|
617
|
-
JSON.stringify(this.offlineQueue),
|
|
618
|
-
"utf-8"
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Load offline queue from disk
|
|
623
|
-
*/
|
|
624
|
-
async loadOfflineQueue() {
|
|
625
|
-
if (!this.config.migration.offlineQueuePath) return;
|
|
626
|
-
const fs = await import("fs/promises");
|
|
627
|
-
try {
|
|
628
|
-
const data = await fs.readFile(
|
|
629
|
-
this.config.migration.offlineQueuePath,
|
|
630
|
-
"utf-8"
|
|
631
|
-
);
|
|
632
|
-
this.offlineQueue = JSON.parse(data);
|
|
633
|
-
this.logger.info(
|
|
634
|
-
`Loaded ${this.offlineQueue.length} items from offline queue`
|
|
635
|
-
);
|
|
636
|
-
} catch {
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
* Update storage statistics
|
|
641
|
-
*/
|
|
642
|
-
async updateStats() {
|
|
643
|
-
const localStats = this.db.prepare(
|
|
644
|
-
`
|
|
645
|
-
SELECT
|
|
646
|
-
tier,
|
|
647
|
-
COUNT(*) as count,
|
|
648
|
-
SUM(size_bytes) / 1048576.0 as size_mb
|
|
649
|
-
FROM storage_items
|
|
650
|
-
GROUP BY tier
|
|
651
|
-
`
|
|
652
|
-
).all();
|
|
653
|
-
this.stats.localUsageMB = 0;
|
|
654
|
-
for (const stat of localStats) {
|
|
655
|
-
this.stats.tierDistribution[stat.tier] = stat.count;
|
|
656
|
-
this.stats.localUsageMB += stat.size_mb;
|
|
657
|
-
}
|
|
658
|
-
const compressionStats = this.db.prepare(
|
|
659
|
-
`
|
|
660
|
-
SELECT
|
|
661
|
-
AVG(CAST(json_extract(metadata, '$.originalSize') AS REAL) /
|
|
662
|
-
CAST(json_extract(metadata, '$.compressedSize') AS REAL)) as ratio
|
|
663
|
-
FROM storage_items
|
|
664
|
-
WHERE compressed = 1
|
|
665
|
-
`
|
|
666
|
-
).get();
|
|
667
|
-
this.stats.compressionRatio = compressionStats?.ratio || 1;
|
|
668
|
-
const pending = this.db.prepare(
|
|
669
|
-
`
|
|
670
|
-
SELECT COUNT(*) as count
|
|
671
|
-
FROM migration_queue
|
|
672
|
-
WHERE status = 'pending'
|
|
673
|
-
`
|
|
674
|
-
).get();
|
|
675
|
-
this.stats.migrationsPending = pending.count;
|
|
676
|
-
this.db.prepare(
|
|
677
|
-
`
|
|
678
|
-
INSERT INTO storage_metrics (tier, item_count, total_size_mb, avg_compression_ratio)
|
|
679
|
-
VALUES ('all', ?, ?, ?)
|
|
680
|
-
`
|
|
681
|
-
).run(
|
|
682
|
-
Object.values(this.stats.tierDistribution).reduce((a, b) => a + b, 0),
|
|
683
|
-
this.stats.localUsageMB,
|
|
684
|
-
this.stats.compressionRatio
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* Get current storage statistics
|
|
689
|
-
*/
|
|
690
|
-
async getStats() {
|
|
691
|
-
await this.updateStats();
|
|
692
|
-
return { ...this.stats };
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Cleanup and shutdown
|
|
696
|
-
*/
|
|
697
|
-
async shutdown() {
|
|
698
|
-
if (this.migrationTimer) {
|
|
699
|
-
clearInterval(this.migrationTimer);
|
|
700
|
-
}
|
|
701
|
-
await this.saveOfflineQueue();
|
|
702
|
-
if (this.redisClient) {
|
|
703
|
-
await this.redisClient.quit();
|
|
704
|
-
}
|
|
705
|
-
if (this.timeseriesPool) {
|
|
706
|
-
await this.timeseriesPool.end();
|
|
707
|
-
}
|
|
708
|
-
this.db.close();
|
|
709
|
-
this.logger.info("Two-tier storage system shut down");
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
const defaultTwoTierConfig = {
|
|
713
|
-
local: {
|
|
714
|
-
dbPath: "~/.stackmemory/two-tier.db",
|
|
715
|
-
maxSizeGB: 2,
|
|
716
|
-
tiers: [
|
|
717
|
-
{
|
|
718
|
-
name: "young" /* YOUNG */,
|
|
719
|
-
maxAgeHours: 24,
|
|
720
|
-
compressionType: "none",
|
|
721
|
-
retentionPolicy: "complete",
|
|
722
|
-
maxSizeMB: 500
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
name: "mature" /* MATURE */,
|
|
726
|
-
maxAgeHours: 168,
|
|
727
|
-
compressionType: "lz4",
|
|
728
|
-
retentionPolicy: "selective",
|
|
729
|
-
maxSizeMB: 1e3
|
|
730
|
-
},
|
|
731
|
-
{
|
|
732
|
-
name: "old" /* OLD */,
|
|
733
|
-
maxAgeHours: 720,
|
|
734
|
-
compressionType: "zstd",
|
|
735
|
-
retentionPolicy: "critical",
|
|
736
|
-
maxSizeMB: 500
|
|
737
|
-
}
|
|
738
|
-
]
|
|
739
|
-
},
|
|
740
|
-
remote: {
|
|
741
|
-
s3: {
|
|
742
|
-
bucket: process.env.S3_BUCKET || "stackmemory-storage",
|
|
743
|
-
region: process.env.AWS_REGION || "us-east-1"
|
|
744
|
-
}
|
|
745
|
-
},
|
|
746
|
-
migration: {
|
|
747
|
-
triggers: [
|
|
748
|
-
{ type: "age", threshold: 720, action: "migrate" },
|
|
749
|
-
// 30 days
|
|
750
|
-
{ type: "size", threshold: 1500, action: "migrate" },
|
|
751
|
-
// 1.5GB
|
|
752
|
-
{ type: "importance", threshold: 0.3, action: "delete" }
|
|
753
|
-
// Low importance
|
|
754
|
-
],
|
|
755
|
-
batchSize: 50,
|
|
756
|
-
intervalMs: 6e4,
|
|
757
|
-
// 1 minute
|
|
758
|
-
offlineQueuePath: "~/.stackmemory/offline-queue.json"
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
export {
|
|
762
|
-
StorageTier,
|
|
763
|
-
TwoTierStorageSystem,
|
|
764
|
-
defaultTwoTierConfig
|
|
765
|
-
};
|
|
766
|
-
//# sourceMappingURL=two-tier-storage.js.map
|