squish-memory 1.2.0 → 1.2.1
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/bin/squish-mcp.mjs +40 -42
- package/core/scheduler/cron-scheduler.ts +10 -1
- package/core/worker.ts +10 -1
- package/package.json +119 -119
- package/packages/mcp/src/index.ts +99 -36
- package/dist/config.d.ts +0 -106
- package/dist/config.js +0 -194
- package/dist/core/adapters/config/claude-code.d.ts +0 -45
- package/dist/core/adapters/config/claude-code.js +0 -113
- package/dist/core/adapters/config/cursor.d.ts +0 -26
- package/dist/core/adapters/config/cursor.js +0 -74
- package/dist/core/adapters/config/opencode.d.ts +0 -23
- package/dist/core/adapters/config/opencode.js +0 -73
- package/dist/core/adapters/config/windsurf.d.ts +0 -26
- package/dist/core/adapters/config/windsurf.js +0 -74
- package/dist/core/adapters/index.d.ts +0 -45
- package/dist/core/adapters/index.js +0 -84
- package/dist/core/adapters/scripts/install-adapter.d.ts +0 -19
- package/dist/core/adapters/scripts/install-adapter.js +0 -149
- package/dist/core/adapters/timeline.d.ts +0 -23
- package/dist/core/adapters/timeline.js +0 -88
- package/dist/core/adapters/types.d.ts +0 -137
- package/dist/core/adapters/types.js +0 -50
- package/dist/core/agent-preferences.d.ts +0 -16
- package/dist/core/agent-preferences.js +0 -124
- package/dist/core/algorithms/analytics/token-estimator.d.ts +0 -50
- package/dist/core/algorithms/analytics/token-estimator.js +0 -154
- package/dist/core/algorithms/detection/hash-filters.d.ts +0 -47
- package/dist/core/algorithms/detection/hash-filters.js +0 -190
- package/dist/core/algorithms/detection/semantic-ranker.d.ts +0 -32
- package/dist/core/algorithms/detection/semantic-ranker.js +0 -118
- package/dist/core/algorithms/detection/two-stage-detector.d.ts +0 -52
- package/dist/core/algorithms/detection/two-stage-detector.js +0 -299
- package/dist/core/algorithms/handlers/approve-merge.d.ts +0 -22
- package/dist/core/algorithms/handlers/approve-merge.js +0 -179
- package/dist/core/algorithms/handlers/detect-duplicates.d.ts +0 -47
- package/dist/core/algorithms/handlers/detect-duplicates.js +0 -145
- package/dist/core/algorithms/handlers/get-stats.d.ts +0 -39
- package/dist/core/algorithms/handlers/get-stats.js +0 -88
- package/dist/core/algorithms/handlers/list-proposals.d.ts +0 -45
- package/dist/core/algorithms/handlers/list-proposals.js +0 -83
- package/dist/core/algorithms/handlers/preview-merge.d.ts +0 -39
- package/dist/core/algorithms/handlers/preview-merge.js +0 -93
- package/dist/core/algorithms/handlers/reject-merge.d.ts +0 -28
- package/dist/core/algorithms/handlers/reject-merge.js +0 -69
- package/dist/core/algorithms/handlers/reverse-merge.d.ts +0 -21
- package/dist/core/algorithms/handlers/reverse-merge.js +0 -121
- package/dist/core/algorithms/index.d.ts +0 -21
- package/dist/core/algorithms/index.js +0 -26
- package/dist/core/algorithms/operations/cache-maintenance.d.ts +0 -12
- package/dist/core/algorithms/operations/cache-maintenance.js +0 -157
- package/dist/core/algorithms/safety/safety-checks.d.ts +0 -18
- package/dist/core/algorithms/safety/safety-checks.js +0 -179
- package/dist/core/algorithms/strategies/merge-strategies.d.ts +0 -50
- package/dist/core/algorithms/strategies/merge-strategies.js +0 -288
- package/dist/core/algorithms/types.d.ts +0 -125
- package/dist/core/algorithms/types.js +0 -5
- package/dist/core/algorithms/utils/response-builder.d.ts +0 -28
- package/dist/core/algorithms/utils/response-builder.js +0 -37
- package/dist/core/associations.d.ts +0 -33
- package/dist/core/associations.js +0 -284
- package/dist/core/autosave.d.ts +0 -19
- package/dist/core/autosave.js +0 -16
- package/dist/core/beliefs/decay.d.ts +0 -27
- package/dist/core/beliefs/decay.js +0 -217
- package/dist/core/beliefs/extractor.d.ts +0 -9
- package/dist/core/beliefs/extractor.js +0 -113
- package/dist/core/beliefs/store.d.ts +0 -46
- package/dist/core/beliefs/store.js +0 -466
- package/dist/core/beliefs/types.d.ts +0 -28
- package/dist/core/beliefs/types.js +0 -2
- package/dist/core/commands/mcp-server.d.ts +0 -2
- package/dist/core/commands/mcp-server.js +0 -6
- package/dist/core/commands/remember.d.ts +0 -24
- package/dist/core/commands/remember.js +0 -144
- package/dist/core/compression.d.ts +0 -45
- package/dist/core/compression.js +0 -160
- package/dist/core/consolidation.d.ts +0 -37
- package/dist/core/consolidation.js +0 -248
- package/dist/core/context/agent-context.d.ts +0 -106
- package/dist/core/context/agent-context.js +0 -274
- package/dist/core/context/context-paging.d.ts +0 -80
- package/dist/core/context/context-paging.js +0 -328
- package/dist/core/context/context-window.d.ts +0 -40
- package/dist/core/context/context-window.js +0 -177
- package/dist/core/context/context.d.ts +0 -7
- package/dist/core/context/context.js +0 -22
- package/dist/core/embeddings/embeddings.d.ts +0 -29
- package/dist/core/embeddings/embeddings.js +0 -546
- package/dist/core/embeddings/google-multimodal.d.ts +0 -14
- package/dist/core/embeddings/google-multimodal.js +0 -146
- package/dist/core/embeddings/local-embeddings.d.ts +0 -11
- package/dist/core/embeddings/local-embeddings.js +0 -11
- package/dist/core/embeddings/qmd-client.d.ts +0 -136
- package/dist/core/embeddings/qmd-client.js +0 -403
- package/dist/core/embeddings/transformers-local.d.ts +0 -64
- package/dist/core/embeddings/transformers-local.js +0 -213
- package/dist/core/embeddings.d.ts +0 -2
- package/dist/core/embeddings.js +0 -3
- package/dist/core/error-handling.d.ts +0 -63
- package/dist/core/error-handling.js +0 -173
- package/dist/core/graph/entity-deduplicator.d.ts +0 -24
- package/dist/core/graph/entity-deduplicator.js +0 -183
- package/dist/core/graph/graph-builder.d.ts +0 -46
- package/dist/core/graph/graph-builder.js +0 -174
- package/dist/core/graph/graph-traversal.d.ts +0 -80
- package/dist/core/graph/graph-traversal.js +0 -315
- package/dist/core/graph/index.d.ts +0 -19
- package/dist/core/graph/index.js +0 -13
- package/dist/core/graph/llm-entity-extractor.d.ts +0 -49
- package/dist/core/graph/llm-entity-extractor.js +0 -313
- package/dist/core/graph/multi-hop-retrieval.d.ts +0 -48
- package/dist/core/graph/multi-hop-retrieval.js +0 -215
- package/dist/core/graph/relationship-extractor.d.ts +0 -48
- package/dist/core/graph/relationship-extractor.js +0 -351
- package/dist/core/hooks/agent-hooks.d.ts +0 -83
- package/dist/core/hooks/agent-hooks.js +0 -521
- package/dist/core/hooks/auto-tagger.d.ts +0 -19
- package/dist/core/hooks/auto-tagger.js +0 -155
- package/dist/core/hooks/capture-filter.d.ts +0 -41
- package/dist/core/hooks/capture-filter.js +0 -128
- package/dist/core/hot-cache.d.ts +0 -86
- package/dist/core/hot-cache.js +0 -285
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -11
- package/dist/core/ingestion/agent-memory.d.ts +0 -22
- package/dist/core/ingestion/agent-memory.js +0 -109
- package/dist/core/ingestion/core-memory.d.ts +0 -78
- package/dist/core/ingestion/core-memory.js +0 -226
- package/dist/core/ingestion/learnings.d.ts +0 -57
- package/dist/core/ingestion/learnings.js +0 -205
- package/dist/core/ingestion/signal-engine.d.ts +0 -41
- package/dist/core/ingestion/signal-engine.js +0 -201
- package/dist/core/integrations/obsidian-vault.d.ts +0 -31
- package/dist/core/integrations/obsidian-vault.js +0 -156
- package/dist/core/layers/generator.d.ts +0 -25
- package/dist/core/layers/generator.js +0 -76
- package/dist/core/lib/db-client.d.ts +0 -114
- package/dist/core/lib/db-client.js +0 -130
- package/dist/core/lib/parse-embedding.d.ts +0 -9
- package/dist/core/lib/parse-embedding.js +0 -58
- package/dist/core/lib/schemas.d.ts +0 -132
- package/dist/core/lib/schemas.js +0 -87
- package/dist/core/lib/types.d.ts +0 -45
- package/dist/core/lib/types.js +0 -6
- package/dist/core/lib/utils.d.ts +0 -18
- package/dist/core/lib/utils.js +0 -145
- package/dist/core/lib/validation.d.ts +0 -38
- package/dist/core/lib/validation.js +0 -151
- package/dist/core/lifecycle.d.ts +0 -25
- package/dist/core/lifecycle.js +0 -292
- package/dist/core/logger.d.ts +0 -17
- package/dist/core/logger.js +0 -46
- package/dist/core/mcp/client.d.ts +0 -17
- package/dist/core/mcp/client.js +0 -101
- package/dist/core/mcp/index.d.ts +0 -6
- package/dist/core/mcp/index.js +0 -6
- package/dist/core/mcp/server.d.ts +0 -18
- package/dist/core/mcp/server.js +0 -157
- package/dist/core/mcp/standalone-server.d.ts +0 -13
- package/dist/core/mcp/standalone-server.js +0 -46
- package/dist/core/mcp/tools.d.ts +0 -7
- package/dist/core/mcp/tools.js +0 -278
- package/dist/core/mcp/types.d.ts +0 -87
- package/dist/core/mcp/types.js +0 -48
- package/dist/core/memory/bridge-discovery.d.ts +0 -50
- package/dist/core/memory/bridge-discovery.js +0 -291
- package/dist/core/memory/categorizer.d.ts +0 -27
- package/dist/core/memory/categorizer.js +0 -306
- package/dist/core/memory/conflict-detector.d.ts +0 -7
- package/dist/core/memory/conflict-detector.js +0 -43
- package/dist/core/memory/consolidation.d.ts +0 -42
- package/dist/core/memory/consolidation.js +0 -277
- package/dist/core/memory/context-collector.d.ts +0 -10
- package/dist/core/memory/context-collector.js +0 -56
- package/dist/core/memory/contradiction-resolver.d.ts +0 -40
- package/dist/core/memory/contradiction-resolver.js +0 -368
- package/dist/core/memory/edit-workflow.d.ts +0 -19
- package/dist/core/memory/edit-workflow.js +0 -120
- package/dist/core/memory/entity-extractor.d.ts +0 -37
- package/dist/core/memory/entity-extractor.js +0 -350
- package/dist/core/memory/entity-resolver.d.ts +0 -23
- package/dist/core/memory/entity-resolver.js +0 -64
- package/dist/core/memory/explain.d.ts +0 -18
- package/dist/core/memory/explain.js +0 -92
- package/dist/core/memory/fact-deriver.d.ts +0 -31
- package/dist/core/memory/fact-deriver.js +0 -236
- package/dist/core/memory/fact-extractor.d.ts +0 -24
- package/dist/core/memory/fact-extractor.js +0 -89
- package/dist/core/memory/feedback-tracker.d.ts +0 -12
- package/dist/core/memory/feedback-tracker.js +0 -155
- package/dist/core/memory/hooks.d.ts +0 -88
- package/dist/core/memory/hooks.js +0 -174
- package/dist/core/memory/hybrid-retrieval.d.ts +0 -27
- package/dist/core/memory/hybrid-retrieval.js +0 -37
- package/dist/core/memory/hybrid-scorer.d.ts +0 -40
- package/dist/core/memory/hybrid-scorer.js +0 -267
- package/dist/core/memory/hybrid-search.d.ts +0 -23
- package/dist/core/memory/hybrid-search.js +0 -596
- package/dist/core/memory/importance.d.ts +0 -46
- package/dist/core/memory/importance.js +0 -241
- package/dist/core/memory/index.d.ts +0 -9
- package/dist/core/memory/index.js +0 -11
- package/dist/core/memory/loader.d.ts +0 -31
- package/dist/core/memory/loader.js +0 -141
- package/dist/core/memory/markdown/markdown-storage.d.ts +0 -72
- package/dist/core/memory/markdown/markdown-storage.js +0 -243
- package/dist/core/memory/memories.d.ts +0 -43
- package/dist/core/memory/memories.js +0 -452
- package/dist/core/memory/memory-lifecycle.d.ts +0 -8
- package/dist/core/memory/memory-lifecycle.js +0 -47
- package/dist/core/memory/memory-manager.d.ts +0 -15
- package/dist/core/memory/memory-manager.js +0 -46
- package/dist/core/memory/migrate.d.ts +0 -21
- package/dist/core/memory/migrate.js +0 -134
- package/dist/core/memory/normalization.d.ts +0 -7
- package/dist/core/memory/normalization.js +0 -26
- package/dist/core/memory/path-strengthener.d.ts +0 -39
- package/dist/core/memory/path-strengthener.js +0 -150
- package/dist/core/memory/progressive-disclosure.d.ts +0 -43
- package/dist/core/memory/progressive-disclosure.js +0 -280
- package/dist/core/memory/query-processor.d.ts +0 -21
- package/dist/core/memory/query-processor.js +0 -106
- package/dist/core/memory/query-rewriter.d.ts +0 -13
- package/dist/core/memory/query-rewriter.js +0 -118
- package/dist/core/memory/response-analyzer.d.ts +0 -9
- package/dist/core/memory/response-analyzer.js +0 -61
- package/dist/core/memory/retrieval-feedback.d.ts +0 -70
- package/dist/core/memory/retrieval-feedback.js +0 -213
- package/dist/core/memory/serialization.d.ts +0 -10
- package/dist/core/memory/serialization.js +0 -84
- package/dist/core/memory/stale-cleaner.d.ts +0 -26
- package/dist/core/memory/stale-cleaner.js +0 -97
- package/dist/core/memory/stats.d.ts +0 -32
- package/dist/core/memory/stats.js +0 -143
- package/dist/core/memory/telemetry.d.ts +0 -69
- package/dist/core/memory/telemetry.js +0 -313
- package/dist/core/memory/temporal-facts.d.ts +0 -41
- package/dist/core/memory/temporal-facts.js +0 -283
- package/dist/core/memory/temporal-parser.d.ts +0 -32
- package/dist/core/memory/temporal-parser.js +0 -385
- package/dist/core/memory/trigger-detector.d.ts +0 -21
- package/dist/core/memory/trigger-detector.js +0 -79
- package/dist/core/memory/write-gate.d.ts +0 -54
- package/dist/core/memory/write-gate.js +0 -210
- package/dist/core/places/index.d.ts +0 -14
- package/dist/core/places/index.js +0 -14
- package/dist/core/places/memory-places.d.ts +0 -68
- package/dist/core/places/memory-places.js +0 -261
- package/dist/core/places/places.d.ts +0 -88
- package/dist/core/places/places.js +0 -314
- package/dist/core/places/rules.d.ts +0 -74
- package/dist/core/places/rules.js +0 -240
- package/dist/core/places/walking.d.ts +0 -56
- package/dist/core/places/walking.js +0 -121
- package/dist/core/projects.d.ts +0 -17
- package/dist/core/projects.js +0 -116
- package/dist/core/redis.d.ts +0 -11
- package/dist/core/redis.js +0 -69
- package/dist/core/responses.d.ts +0 -96
- package/dist/core/responses.js +0 -122
- package/dist/core/runtime/trust-report.d.ts +0 -102
- package/dist/core/runtime/trust-report.js +0 -107
- package/dist/core/runtime/trust-state.d.ts +0 -12
- package/dist/core/runtime/trust-state.js +0 -309
- package/dist/core/scheduler/cron-scheduler.d.ts +0 -32
- package/dist/core/scheduler/cron-scheduler.js +0 -493
- package/dist/core/scheduler/heartbeat.d.ts +0 -11
- package/dist/core/scheduler/heartbeat.js +0 -73
- package/dist/core/scheduler/index.d.ts +0 -8
- package/dist/core/scheduler/index.js +0 -8
- package/dist/core/scheduler/job-runner.d.ts +0 -11
- package/dist/core/scheduler/job-runner.js +0 -164
- package/dist/core/search/conversations.d.ts +0 -25
- package/dist/core/search/conversations.js +0 -110
- package/dist/core/search/entities.d.ts +0 -12
- package/dist/core/search/entities.js +0 -31
- package/dist/core/search/folder-context.d.ts +0 -25
- package/dist/core/search/folder-context.js +0 -119
- package/dist/core/search/graph-boost.d.ts +0 -7
- package/dist/core/search/graph-boost.js +0 -23
- package/dist/core/search/index.d.ts +0 -4
- package/dist/core/search/index.js +0 -5
- package/dist/core/search/qmd-wrapper.d.ts +0 -36
- package/dist/core/search/qmd-wrapper.js +0 -58
- package/dist/core/security/encrypt.d.ts +0 -6
- package/dist/core/security/encrypt.js +0 -47
- package/dist/core/security/governance.d.ts +0 -26
- package/dist/core/security/governance.js +0 -79
- package/dist/core/security/privacy.d.ts +0 -23
- package/dist/core/security/privacy.js +0 -82
- package/dist/core/security/secret-detector.d.ts +0 -32
- package/dist/core/security/secret-detector.js +0 -88
- package/dist/core/session/auto-load.d.ts +0 -6
- package/dist/core/session/auto-load.js +0 -144
- package/dist/core/session/entity-tracker.d.ts +0 -62
- package/dist/core/session/entity-tracker.js +0 -287
- package/dist/core/session/index.d.ts +0 -7
- package/dist/core/session/index.js +0 -7
- package/dist/core/session/reference-resolver.d.ts +0 -26
- package/dist/core/session/reference-resolver.js +0 -121
- package/dist/core/session/self-iteration-job.d.ts +0 -35
- package/dist/core/session/self-iteration-job.js +0 -387
- package/dist/core/session/session-hooks.d.ts +0 -18
- package/dist/core/session/session-hooks.js +0 -58
- package/dist/core/session/types.d.ts +0 -26
- package/dist/core/session/types.js +0 -10
- package/dist/core/session/working-set.d.ts +0 -50
- package/dist/core/session/working-set.js +0 -212
- package/dist/core/snapshots/cleanup.d.ts +0 -9
- package/dist/core/snapshots/cleanup.js +0 -12
- package/dist/core/snapshots/comparison.d.ts +0 -19
- package/dist/core/snapshots/comparison.js +0 -43
- package/dist/core/snapshots/creation.d.ts +0 -13
- package/dist/core/snapshots/creation.js +0 -117
- package/dist/core/snapshots/retrieval.d.ts +0 -7
- package/dist/core/snapshots/retrieval.js +0 -41
- package/dist/core/snapshots/stats.d.ts +0 -11
- package/dist/core/snapshots/stats.js +0 -52
- package/dist/core/storage/cache.d.ts +0 -13
- package/dist/core/storage/cache.js +0 -202
- package/dist/core/storage/database.d.ts +0 -12
- package/dist/core/storage/database.js +0 -12
- package/dist/core/summarization/cleanup.d.ts +0 -9
- package/dist/core/summarization/cleanup.js +0 -12
- package/dist/core/summarization/queries.d.ts +0 -9
- package/dist/core/summarization/queries.js +0 -28
- package/dist/core/summarization/stats.d.ts +0 -14
- package/dist/core/summarization/stats.js +0 -52
- package/dist/core/summarization/strategies.d.ts +0 -24
- package/dist/core/summarization/strategies.js +0 -28
- package/dist/core/summarization.d.ts +0 -37
- package/dist/core/summarization.js +0 -188
- package/dist/core/temporal-facts.d.ts +0 -54
- package/dist/core/temporal-facts.js +0 -193
- package/dist/core/tracing/collector.d.ts +0 -111
- package/dist/core/tracing/collector.js +0 -350
- package/dist/core/tracing/visualizer.d.ts +0 -32
- package/dist/core/tracing/visualizer.js +0 -165
- package/dist/core/utils/cleanup-operations.d.ts +0 -13
- package/dist/core/utils/cleanup-operations.js +0 -44
- package/dist/core/utils/content-extraction.d.ts +0 -19
- package/dist/core/utils/content-extraction.js +0 -75
- package/dist/core/utils/filter-builder.d.ts +0 -13
- package/dist/core/utils/filter-builder.js +0 -44
- package/dist/core/utils/history-traversal.d.ts +0 -13
- package/dist/core/utils/history-traversal.js +0 -50
- package/dist/core/utils/memory-operations.d.ts +0 -17
- package/dist/core/utils/memory-operations.js +0 -43
- package/dist/core/utils/query-operations.d.ts +0 -18
- package/dist/core/utils/query-operations.js +0 -65
- package/dist/core/utils/summarization-helpers.d.ts +0 -17
- package/dist/core/utils/summarization-helpers.js +0 -33
- package/dist/core/utils/temporal-queries.d.ts +0 -13
- package/dist/core/utils/temporal-queries.js +0 -27
- package/dist/core/utils/vector-operations.d.ts +0 -71
- package/dist/core/utils/vector-operations.js +0 -129
- package/dist/core/utils/version-management.d.ts +0 -9
- package/dist/core/utils/version-management.js +0 -61
- package/dist/core/worker.d.ts +0 -82
- package/dist/core/worker.js +0 -272
- package/dist/db/adapter.d.ts +0 -7
- package/dist/db/adapter.js +0 -175
- package/dist/db/bootstrap.d.ts +0 -11
- package/dist/db/bootstrap.js +0 -1034
- package/dist/db/drizzle/schema-sqlite.d.ts +0 -5538
- package/dist/db/drizzle/schema-sqlite.js +0 -763
- package/dist/db/drizzle/schema.d.ts +0 -4734
- package/dist/db/drizzle/schema.js +0 -859
- package/dist/db/drizzle.config.d.ts +0 -3
- package/dist/db/drizzle.config.js +0 -12
- package/dist/db/index.d.ts +0 -7
- package/dist/db/index.js +0 -89
- package/dist/db/migrations/associations.d.ts +0 -6
- package/dist/db/migrations/associations.js +0 -29
- package/dist/db/migrations/beliefs.d.ts +0 -10
- package/dist/db/migrations/beliefs.js +0 -76
- package/dist/db/migrations/core-memory.d.ts +0 -6
- package/dist/db/migrations/core-memory.js +0 -29
- package/dist/db/migrations/fts.d.ts +0 -6
- package/dist/db/migrations/fts.js +0 -52
- package/dist/db/migrations/index.d.ts +0 -25
- package/dist/db/migrations/index.js +0 -51
- package/dist/db/migrations/indexes.d.ts +0 -6
- package/dist/db/migrations/indexes.js +0 -30
- package/dist/db/migrations/learnings.d.ts +0 -7
- package/dist/db/migrations/learnings.js +0 -26
- package/dist/db/migrations/maintenance.d.ts +0 -6
- package/dist/db/migrations/maintenance.js +0 -61
- package/dist/db/migrations/memories.d.ts +0 -7
- package/dist/db/migrations/memories.js +0 -16
- package/dist/db/migrations/memory-places.d.ts +0 -6
- package/dist/db/migrations/memory-places.js +0 -29
- package/dist/db/migrations/places.d.ts +0 -6
- package/dist/db/migrations/places.js +0 -43
- package/dist/db/migrations/projects.d.ts +0 -3
- package/dist/db/migrations/projects.js +0 -13
- package/dist/db/migrations/tier-conversion.d.ts +0 -7
- package/dist/db/migrations/tier-conversion.js +0 -20
- package/dist/db/neon.d.ts +0 -8
- package/dist/db/neon.js +0 -20
- package/dist/db/schema/beliefs.d.ts +0 -9
- package/dist/db/schema/beliefs.js +0 -46
- package/dist/db/schema/generator.d.ts +0 -38
- package/dist/db/schema/generator.js +0 -108
- package/dist/db/schema/index.d.ts +0 -39
- package/dist/db/schema/index.js +0 -51
- package/dist/db/schema/learnings.d.ts +0 -7
- package/dist/db/schema/learnings.js +0 -30
- package/dist/db/schema/memories.d.ts +0 -7
- package/dist/db/schema/memories.js +0 -81
- package/dist/db/schema/projects.d.ts +0 -4
- package/dist/db/schema/projects.js +0 -31
- package/dist/db/schema/tables/context-sessions.d.ts +0 -9
- package/dist/db/schema/tables/context-sessions.js +0 -37
- package/dist/db/schema/tables/conversations.d.ts +0 -9
- package/dist/db/schema/tables/conversations.js +0 -47
- package/dist/db/schema/tables/core-memory.d.ts +0 -9
- package/dist/db/schema/tables/core-memory.js +0 -41
- package/dist/db/schema/tables/entities.d.ts +0 -9
- package/dist/db/schema/tables/entities.js +0 -39
- package/dist/db/schema/tables/entity-relations.d.ts +0 -9
- package/dist/db/schema/tables/entity-relations.js +0 -31
- package/dist/db/schema/tables/learnings.d.ts +0 -9
- package/dist/db/schema/tables/learnings.js +0 -66
- package/dist/db/schema/tables/memories.d.ts +0 -9
- package/dist/db/schema/tables/memories.js +0 -161
- package/dist/db/schema/tables/memory-associations.d.ts +0 -9
- package/dist/db/schema/tables/memory-associations.js +0 -39
- package/dist/db/schema/tables/memory-hash-cache.d.ts +0 -9
- package/dist/db/schema/tables/memory-hash-cache.js +0 -29
- package/dist/db/schema/tables/memory-merge-history.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-history.js +0 -33
- package/dist/db/schema/tables/memory-merge-proposals.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-proposals.js +0 -39
- package/dist/db/schema/tables/messages.d.ts +0 -9
- package/dist/db/schema/tables/messages.js +0 -41
- package/dist/db/schema/tables/namespaces.d.ts +0 -9
- package/dist/db/schema/tables/namespaces.js +0 -37
- package/dist/db/schema/tables/projects.d.ts +0 -9
- package/dist/db/schema/tables/projects.js +0 -31
- package/dist/db/schema/tables/users.d.ts +0 -9
- package/dist/db/schema/tables/users.js +0 -27
- package/dist/db/schema.d.ts +0 -3
- package/dist/db/schema.js +0 -11
- package/dist/db/supabase.d.ts +0 -9
- package/dist/db/supabase.js +0 -24
- package/dist/packages/mcp/src/index.d.ts +0 -3
- package/dist/packages/mcp/src/index.js +0 -733
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
/** Cron Scheduler - Persistent cron-based job scheduling with fallback support */
|
|
2
|
-
import cron from 'node-cron';
|
|
3
|
-
import { selfIterationHandler } from '../session/self-iteration-job.js';
|
|
4
|
-
import { runLifecycleMaintenance } from '../lifecycle.js';
|
|
5
|
-
import { logger } from '../logger.js';
|
|
6
|
-
import { config } from '../../config.js';
|
|
7
|
-
import { getDb } from '../../db/index.js';
|
|
8
|
-
import { maintenanceJobs, maintenanceJobHistory } from '../../db/drizzle/schema-sqlite.js';
|
|
9
|
-
import { eq } from 'drizzle-orm';
|
|
10
|
-
const jobHandlers = new Map();
|
|
11
|
-
const activeTasks = new Map(); // node-cron ScheduledTask type
|
|
12
|
-
// Job interval by type (in ms) - used for catch-up detection
|
|
13
|
-
const JOB_INTERVALS = {
|
|
14
|
-
hourly: 60 * 60 * 1000, // 1 hour
|
|
15
|
-
daily: 24 * 60 * 60 * 1000, // 24 hours
|
|
16
|
-
nightly: 24 * 60 * 60 * 1000, // 24 hours (same as daily)
|
|
17
|
-
weekly: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
18
|
-
};
|
|
19
|
-
export function registerJobHandler(jobName, handler) {
|
|
20
|
-
jobHandlers.set(jobName, handler);
|
|
21
|
-
logger.info(`[Scheduler] Registered handler for job: ${jobName}`);
|
|
22
|
-
}
|
|
23
|
-
// Register self-iteration job handler
|
|
24
|
-
registerJobHandler('self_iteration', selfIterationHandler);
|
|
25
|
-
// Decay job handler - runs lifecycle maintenance (decay, tier updates, eviction)
|
|
26
|
-
const decayHandler = async (context) => {
|
|
27
|
-
const stats = await runLifecycleMaintenance();
|
|
28
|
-
return {
|
|
29
|
-
recordsProcessed: stats.decayed + stats.expired + stats.evicted,
|
|
30
|
-
summary: {
|
|
31
|
-
decayed: stats.decayed,
|
|
32
|
-
expired: stats.expired,
|
|
33
|
-
evicted: stats.evicted,
|
|
34
|
-
tierChanges: stats.tierChanges,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
registerJobHandler('decay_maintenance', decayHandler);
|
|
39
|
-
// Belief decay handler - applies confidence decay to beliefs
|
|
40
|
-
const beliefDecayHandler = async (context) => {
|
|
41
|
-
const { applyBeliefDecay } = await import('../beliefs/decay.js');
|
|
42
|
-
const stats = await applyBeliefDecay();
|
|
43
|
-
return {
|
|
44
|
-
recordsProcessed: stats.decayed + stats.sourceCountUpdated,
|
|
45
|
-
summary: {
|
|
46
|
-
beliefDecayed: stats.decayed,
|
|
47
|
-
sourceCountUpdated: stats.sourceCountUpdated,
|
|
48
|
-
errors: stats.errors,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
registerJobHandler('belief_decay', beliefDecayHandler);
|
|
53
|
-
// Auto-clean handler - deletes stale memories automatically
|
|
54
|
-
const autoCleanHandler = async (context) => {
|
|
55
|
-
const { getStaleMemories, deleteMemoryPermanently } = await import('../memory/stale-cleaner.js');
|
|
56
|
-
const { getAllProjects } = await import('../projects.js');
|
|
57
|
-
const jobConfig = context.config;
|
|
58
|
-
if (jobConfig.enabled === false) {
|
|
59
|
-
return { recordsProcessed: 0, summary: { skipped: true, reason: 'auto-clean disabled' } };
|
|
60
|
-
}
|
|
61
|
-
const olderThanDays = jobConfig.olderThanDays || 30;
|
|
62
|
-
const confidenceLevels = jobConfig.confidenceLevel || ['outdated', 'speculative'];
|
|
63
|
-
const minImportance = jobConfig.minImportance || 40;
|
|
64
|
-
const dryRun = jobConfig.dryRun !== undefined ? jobConfig.dryRun : false; // Default to actual delete for safety
|
|
65
|
-
const projects = await getAllProjects();
|
|
66
|
-
let totalStale = 0;
|
|
67
|
-
let totalDeleted = 0;
|
|
68
|
-
for (const project of projects) {
|
|
69
|
-
const stale = await getStaleMemories({
|
|
70
|
-
olderThanDays,
|
|
71
|
-
confidenceLevels,
|
|
72
|
-
minImportance,
|
|
73
|
-
projectId: project.id,
|
|
74
|
-
});
|
|
75
|
-
totalStale += stale.length;
|
|
76
|
-
if (dryRun) {
|
|
77
|
-
logger.info(`[AutoClean] Would delete ${stale.length} stale memories in ${project.path}`);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
for (const memory of stale) {
|
|
81
|
-
if (!memory.isPinned) {
|
|
82
|
-
await deleteMemoryPermanently(memory.id);
|
|
83
|
-
totalDeleted++;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
logger.info(`[AutoClean] Deleted ${stale.length} stale memories in ${project.path}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
recordsProcessed: dryRun ? totalStale : totalDeleted,
|
|
91
|
-
summary: {
|
|
92
|
-
mode: dryRun ? 'dry-run' : 'deleted',
|
|
93
|
-
projectsScanned: projects.length,
|
|
94
|
-
memoriesAffected: dryRun ? totalStale : totalDeleted,
|
|
95
|
-
criteria: { olderThanDays, confidenceLevels, minImportance },
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
registerJobHandler('auto_clean', autoCleanHandler);
|
|
100
|
-
export async function initializeScheduler() {
|
|
101
|
-
if (!config.cronEnabled) {
|
|
102
|
-
logger.info('[Scheduler] Cron scheduling disabled, using heartbeat fallback');
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const db = await getDb();
|
|
106
|
-
if (!db) {
|
|
107
|
-
logger.warn('[Scheduler] Database not available, scheduler disabled');
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
await ensureDefaultJobs(db);
|
|
112
|
-
// Check for missed jobs (catch-up after machine wake from sleep)
|
|
113
|
-
await checkMissedJobs();
|
|
114
|
-
const sqliteDb = db;
|
|
115
|
-
const jobs = await sqliteDb
|
|
116
|
-
.select()
|
|
117
|
-
.from(maintenanceJobs)
|
|
118
|
-
.where(eq(maintenanceJobs.enabled, true));
|
|
119
|
-
for (const job of jobs) {
|
|
120
|
-
await scheduleJob(job);
|
|
121
|
-
}
|
|
122
|
-
logger.info(`[Scheduler] Initialized with ${jobs.length} scheduled jobs`);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
logger.error('[Scheduler] Failed to initialize:', error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Check for missed jobs and execute catch-up if needed
|
|
130
|
-
* Called on scheduler initialization (including after machine wake from sleep)
|
|
131
|
-
*/
|
|
132
|
-
async function checkMissedJobs() {
|
|
133
|
-
try {
|
|
134
|
-
const db = await getDb();
|
|
135
|
-
if (!db)
|
|
136
|
-
return;
|
|
137
|
-
const sqliteDb = db;
|
|
138
|
-
const jobs = await sqliteDb
|
|
139
|
-
.select()
|
|
140
|
-
.from(maintenanceJobs)
|
|
141
|
-
.where(eq(maintenanceJobs.enabled, true));
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
for (const job of jobs) {
|
|
144
|
-
const intervalMs = JOB_INTERVALS[job.jobType];
|
|
145
|
-
if (!intervalMs)
|
|
146
|
-
continue;
|
|
147
|
-
const lastRun = job.lastRunAt ? new Date(job.lastRunAt).getTime() : 0;
|
|
148
|
-
const elapsed = lastRun > 0 ? now - lastRun : intervalMs * 2; // If never run, treat as overdue
|
|
149
|
-
const gracePeriod = intervalMs * 1.5; // 1.5x interval grace
|
|
150
|
-
if (elapsed > gracePeriod) {
|
|
151
|
-
logger.info(`[Scheduler] Catch-up needed for ${job.jobName}, elapsed ${Math.round(elapsed / (60 * 60 * 1000))}h (grace: ${Math.round(gracePeriod / (60 * 60 * 1000))}h)`);
|
|
152
|
-
// Execute catch-up
|
|
153
|
-
const handler = jobHandlers.get(job.jobName);
|
|
154
|
-
if (handler) {
|
|
155
|
-
try {
|
|
156
|
-
const startedAt = new Date();
|
|
157
|
-
const context = {
|
|
158
|
-
jobId: job.id,
|
|
159
|
-
jobName: job.jobName,
|
|
160
|
-
jobType: job.jobType,
|
|
161
|
-
config: typeof job.jobConfig === 'string'
|
|
162
|
-
? JSON.parse(job.jobConfig)
|
|
163
|
-
: job.jobConfig ?? {},
|
|
164
|
-
startedAt,
|
|
165
|
-
};
|
|
166
|
-
await handler(context);
|
|
167
|
-
// Record successful catch-up run
|
|
168
|
-
const completedAt = new Date();
|
|
169
|
-
await sqliteDb
|
|
170
|
-
.update(maintenanceJobs)
|
|
171
|
-
.set({
|
|
172
|
-
lastRunAt: completedAt,
|
|
173
|
-
lastRunStatus: 'success',
|
|
174
|
-
lastRunDuration: completedAt.getTime() - startedAt.getTime(),
|
|
175
|
-
})
|
|
176
|
-
.where(eq(maintenanceJobs.id, job.id));
|
|
177
|
-
logger.info(`[Scheduler] Catch-up completed for ${job.jobName}`);
|
|
178
|
-
}
|
|
179
|
-
catch (catchError) {
|
|
180
|
-
const msg = catchError instanceof Error ? catchError.message : String(catchError);
|
|
181
|
-
logger.error(`[Scheduler] Catch-up failed for ${job.jobName}:`, msg);
|
|
182
|
-
await sqliteDb
|
|
183
|
-
.update(maintenanceJobs)
|
|
184
|
-
.set({
|
|
185
|
-
lastRunAt: new Date(),
|
|
186
|
-
lastRunStatus: 'failed',
|
|
187
|
-
lastRunError: msg,
|
|
188
|
-
})
|
|
189
|
-
.where(eq(maintenanceJobs.id, job.id));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
197
|
-
logger.error('[Scheduler] Error checking missed jobs:', msg);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
async function ensureDefaultJobs(db) {
|
|
201
|
-
const defaultJobs = [
|
|
202
|
-
{
|
|
203
|
-
jobName: 'decay_maintenance',
|
|
204
|
-
jobType: 'hourly',
|
|
205
|
-
cronExpression: '0 * * * *', // Run every hour at :00
|
|
206
|
-
enabled: true,
|
|
207
|
-
jobConfig: { applyDecay: true, updateTiers: true, evictOld: true },
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
jobName: 'belief_decay',
|
|
211
|
-
jobType: 'daily',
|
|
212
|
-
cronExpression: '0 4 * * *', // Run daily at 4 AM
|
|
213
|
-
enabled: true,
|
|
214
|
-
jobConfig: { applyBeliefDecay: true },
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
jobName: 'nightly_maintenance',
|
|
218
|
-
jobType: 'nightly',
|
|
219
|
-
cronExpression: '0 2 * * *',
|
|
220
|
-
enabled: true,
|
|
221
|
-
jobConfig: { mergeDuplicates: true, boostAccessed: true, decayScores: true },
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
jobName: 'weekly_maintenance',
|
|
225
|
-
jobType: 'weekly',
|
|
226
|
-
cronExpression: '0 3 * * 0',
|
|
227
|
-
enabled: true,
|
|
228
|
-
jobConfig: { regenerateSummaries: true, archiveStale: true, cleanupOrphaned: true },
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
jobName: 'self_iteration',
|
|
232
|
-
jobType: 'hourly',
|
|
233
|
-
cronExpression: '30 * * * *', // Run every hour at :30
|
|
234
|
-
enabled: true,
|
|
235
|
-
jobConfig: { minMessageCount: 5, maxMessagesToProcess: 50 },
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
jobName: 'auto_clean',
|
|
239
|
-
jobType: 'daily',
|
|
240
|
-
cronExpression: '0 3 * * *', // Run daily at 3 AM
|
|
241
|
-
enabled: true,
|
|
242
|
-
jobConfig: {
|
|
243
|
-
enabled: true,
|
|
244
|
-
olderThanDays: 30,
|
|
245
|
-
confidenceLevel: ['outdated', 'speculative'],
|
|
246
|
-
minImportance: 40,
|
|
247
|
-
dryRun: true, // Start with dry-run for safety
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
];
|
|
251
|
-
for (const job of defaultJobs) {
|
|
252
|
-
let existing;
|
|
253
|
-
try {
|
|
254
|
-
existing = await db
|
|
255
|
-
.select()
|
|
256
|
-
.from(maintenanceJobs)
|
|
257
|
-
.where(eq(maintenanceJobs.jobName, job.jobName))
|
|
258
|
-
.limit(1);
|
|
259
|
-
}
|
|
260
|
-
catch (queryError) {
|
|
261
|
-
logger.error(`[Scheduler] Query failed for job ${job.jobName}:`, queryError.message);
|
|
262
|
-
// Try raw SQL fallback
|
|
263
|
-
try {
|
|
264
|
-
const rawDb = db.$client;
|
|
265
|
-
if (rawDb && typeof rawDb.prepare === 'function') {
|
|
266
|
-
existing = rawDb.prepare('SELECT * FROM maintenance_jobs WHERE job_name = ?').all(job.jobName);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
catch (fallbackError) {
|
|
270
|
-
logger.error(`[Scheduler] Fallback query also failed:`, fallbackError.message);
|
|
271
|
-
throw queryError;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (existing.length === 0) {
|
|
275
|
-
try {
|
|
276
|
-
await db.insert(maintenanceJobs).values({
|
|
277
|
-
jobName: job.jobName,
|
|
278
|
-
jobType: job.jobType,
|
|
279
|
-
cronExpression: job.cronExpression,
|
|
280
|
-
enabled: job.enabled,
|
|
281
|
-
jobConfig: job.jobConfig,
|
|
282
|
-
totalRuns: 0,
|
|
283
|
-
successCount: 0,
|
|
284
|
-
failureCount: 0,
|
|
285
|
-
lastRunAt: null,
|
|
286
|
-
nextRunAt: null,
|
|
287
|
-
lastRunDuration: null,
|
|
288
|
-
lastRunStatus: null,
|
|
289
|
-
lastRunError: null,
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
catch (insertError) {
|
|
293
|
-
// Fallback to raw SQL if drizzle insert fails
|
|
294
|
-
logger.warn(`[Scheduler] Drizzle insert failed, using raw SQL: ${insertError.message}`);
|
|
295
|
-
const rawDb = db.$client;
|
|
296
|
-
if (rawDb && typeof rawDb.prepare === 'function') {
|
|
297
|
-
const stmt = rawDb.prepare(`
|
|
298
|
-
INSERT INTO maintenance_jobs
|
|
299
|
-
(id, job_name, job_type, cron_expression, enabled, job_config,
|
|
300
|
-
total_runs, success_count, failure_count, last_run_at, next_run_at,
|
|
301
|
-
last_run_duration, last_run_status, last_run_error)
|
|
302
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
303
|
-
`);
|
|
304
|
-
stmt.run(crypto.randomUUID(), job.jobName, job.jobType, job.cronExpression, job.enabled ? 1 : 0, JSON.stringify(job.jobConfig), 0, 0, 0, null, null, null, null, null);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
logger.info(`[Scheduler] Created default job: ${job.jobName}`);
|
|
308
|
-
// Register self-iteration handler
|
|
309
|
-
if (job.jobName === 'self_iteration') {
|
|
310
|
-
registerJobHandler('self_iteration', selfIterationHandler);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
export async function scheduleJob(job) {
|
|
316
|
-
const existingTask = activeTasks.get(job.jobName);
|
|
317
|
-
if (existingTask) {
|
|
318
|
-
existingTask.stop();
|
|
319
|
-
activeTasks.delete(job.jobName);
|
|
320
|
-
}
|
|
321
|
-
if (!job.enabled || !job.cronExpression) {
|
|
322
|
-
logger.debug(`[Scheduler] Job ${job.jobName} is disabled or has no cron expression`);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
if (!cron.validate(job.cronExpression)) {
|
|
326
|
-
logger.error(`[Scheduler] Invalid cron expression for ${job.jobName}: ${job.cronExpression}`);
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
const task = cron.schedule(job.cronExpression, async () => {
|
|
330
|
-
await executeJob(job);
|
|
331
|
-
}, {
|
|
332
|
-
timezone: 'UTC',
|
|
333
|
-
});
|
|
334
|
-
activeTasks.set(job.jobName, task);
|
|
335
|
-
const nextRun = getNextRunTime(job.cronExpression);
|
|
336
|
-
const db = await getDb();
|
|
337
|
-
if (db) {
|
|
338
|
-
const sqliteDb = db;
|
|
339
|
-
await sqliteDb
|
|
340
|
-
.update(maintenanceJobs)
|
|
341
|
-
.set({ nextRunAt: nextRun })
|
|
342
|
-
.where(eq(maintenanceJobs.id, job.id));
|
|
343
|
-
}
|
|
344
|
-
logger.info(`[Scheduler] Scheduled ${job.jobName} with cron: ${job.cronExpression}${nextRun ? `, next run: ${nextRun.toISOString()}` : ''}`);
|
|
345
|
-
}
|
|
346
|
-
export async function executeJob(job) {
|
|
347
|
-
const db = await getDb();
|
|
348
|
-
const handler = jobHandlers.get(job.jobName);
|
|
349
|
-
if (!handler) {
|
|
350
|
-
logger.warn(`[Scheduler] No handler registered for job: ${job.jobName}`);
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
const startedAt = new Date();
|
|
354
|
-
let status = 'success';
|
|
355
|
-
let error = null;
|
|
356
|
-
let recordsProcessed = 0;
|
|
357
|
-
let summary = {};
|
|
358
|
-
try {
|
|
359
|
-
logger.info(`[Scheduler] Executing job: ${job.jobName}`);
|
|
360
|
-
const result = await handler({
|
|
361
|
-
jobId: job.id,
|
|
362
|
-
jobName: job.jobName,
|
|
363
|
-
jobType: job.jobType,
|
|
364
|
-
config: job.jobConfig || {},
|
|
365
|
-
startedAt,
|
|
366
|
-
});
|
|
367
|
-
recordsProcessed = result.recordsProcessed;
|
|
368
|
-
summary = result.summary;
|
|
369
|
-
logger.info(`[Scheduler] Job ${job.jobName} completed: ${recordsProcessed} records processed`);
|
|
370
|
-
}
|
|
371
|
-
catch (err) {
|
|
372
|
-
status = 'failed';
|
|
373
|
-
error = err instanceof Error ? err.message : String(err);
|
|
374
|
-
logger.error(`[Scheduler] Job ${job.jobName} failed:`, error);
|
|
375
|
-
}
|
|
376
|
-
const completedAt = new Date();
|
|
377
|
-
if (db) {
|
|
378
|
-
const sqliteDb = db;
|
|
379
|
-
const [currentJob] = await sqliteDb
|
|
380
|
-
.select()
|
|
381
|
-
.from(maintenanceJobs)
|
|
382
|
-
.where(eq(maintenanceJobs.id, job.id));
|
|
383
|
-
await sqliteDb
|
|
384
|
-
.update(maintenanceJobs)
|
|
385
|
-
.set({
|
|
386
|
-
lastRunAt: startedAt,
|
|
387
|
-
lastRunStatus: status,
|
|
388
|
-
lastRunError: error,
|
|
389
|
-
lastRunDuration: completedAt.getTime() - startedAt.getTime(),
|
|
390
|
-
totalRuns: (currentJob?.totalRuns ?? 0) + 1,
|
|
391
|
-
successCount: status === 'success' ? (currentJob?.successCount ?? 0) + 1 : currentJob?.successCount,
|
|
392
|
-
failureCount: status === 'failed' ? (currentJob?.failureCount ?? 0) + 1 : currentJob?.failureCount,
|
|
393
|
-
nextRunAt: job.cronExpression ? getNextRunTime(job.cronExpression) : null,
|
|
394
|
-
})
|
|
395
|
-
.where(eq(maintenanceJobs.id, job.id));
|
|
396
|
-
await sqliteDb.insert(maintenanceJobHistory).values({
|
|
397
|
-
jobId: job.id,
|
|
398
|
-
startedAt,
|
|
399
|
-
completedAt,
|
|
400
|
-
duration: completedAt.getTime() - startedAt.getTime(),
|
|
401
|
-
status,
|
|
402
|
-
error,
|
|
403
|
-
recordsProcessed,
|
|
404
|
-
resultSummary: summary,
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function getNextRunTime(cronExpression) {
|
|
409
|
-
try {
|
|
410
|
-
const now = new Date();
|
|
411
|
-
const parts = cronExpression.split(' ');
|
|
412
|
-
// Daily jobs: MM HH * * *
|
|
413
|
-
if (parts[2] === '*' && parts[3] === '*' && parts[4] === '*' && parts[1] !== '*') {
|
|
414
|
-
const next = new Date(now);
|
|
415
|
-
next.setHours(parseInt(parts[1]), parseInt(parts[0]), 0, 0);
|
|
416
|
-
if (next <= now)
|
|
417
|
-
next.setDate(next.getDate() + 1);
|
|
418
|
-
return next;
|
|
419
|
-
}
|
|
420
|
-
// Hourly jobs: MM * * * *
|
|
421
|
-
if (parts[1] === '*' && parts[2] === '*' && parts[3] === '*' && parts[4] === '*') {
|
|
422
|
-
const next = new Date(now);
|
|
423
|
-
next.setMinutes(parseInt(parts[0]), 0, 0);
|
|
424
|
-
if (next <= now)
|
|
425
|
-
next.setHours(next.getHours() + 1);
|
|
426
|
-
return next;
|
|
427
|
-
}
|
|
428
|
-
// Weekly jobs: MM HH * * D
|
|
429
|
-
if (parts[4] !== '*') {
|
|
430
|
-
const dayOfWeek = parseInt(parts[4]);
|
|
431
|
-
const next = new Date(now);
|
|
432
|
-
next.setHours(parseInt(parts[1]), parseInt(parts[0]), 0, 0);
|
|
433
|
-
const daysUntil = (dayOfWeek - next.getDay() + 7) % 7;
|
|
434
|
-
next.setDate(next.getDate() + (daysUntil === 0 && next > now ? 7 : daysUntil));
|
|
435
|
-
return next;
|
|
436
|
-
}
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
catch {
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
export async function getScheduledJobs() {
|
|
444
|
-
const db = await getDb();
|
|
445
|
-
if (!db)
|
|
446
|
-
return [];
|
|
447
|
-
const sqliteDb = db;
|
|
448
|
-
const jobs = await sqliteDb.select().from(maintenanceJobs);
|
|
449
|
-
return jobs.map((job) => ({
|
|
450
|
-
id: job.id,
|
|
451
|
-
jobName: job.jobName,
|
|
452
|
-
jobType: job.jobType,
|
|
453
|
-
cronExpression: job.cronExpression || '',
|
|
454
|
-
enabled: job.enabled ?? true,
|
|
455
|
-
lastRunAt: job.lastRunAt ? new Date(job.lastRunAt) : null,
|
|
456
|
-
nextRunAt: job.nextRunAt ? new Date(job.nextRunAt) : null,
|
|
457
|
-
jobConfig: job.jobConfig || {},
|
|
458
|
-
}));
|
|
459
|
-
}
|
|
460
|
-
export async function getOverdueJobs() {
|
|
461
|
-
const db = await getDb();
|
|
462
|
-
if (!db)
|
|
463
|
-
return [];
|
|
464
|
-
const now = new Date();
|
|
465
|
-
const sqliteDb = db;
|
|
466
|
-
const jobs = await sqliteDb.select().from(maintenanceJobs);
|
|
467
|
-
return jobs
|
|
468
|
-
.filter((job) => {
|
|
469
|
-
if (!job.enabled)
|
|
470
|
-
return false;
|
|
471
|
-
if (!job.nextRunAt)
|
|
472
|
-
return true;
|
|
473
|
-
return new Date(job.nextRunAt) < now;
|
|
474
|
-
})
|
|
475
|
-
.map((job) => ({
|
|
476
|
-
id: job.id,
|
|
477
|
-
jobName: job.jobName,
|
|
478
|
-
jobType: job.jobType,
|
|
479
|
-
cronExpression: job.cronExpression || '',
|
|
480
|
-
enabled: job.enabled ?? true,
|
|
481
|
-
lastRunAt: job.lastRunAt ? new Date(job.lastRunAt) : null,
|
|
482
|
-
nextRunAt: job.nextRunAt ? new Date(job.nextRunAt) : null,
|
|
483
|
-
jobConfig: job.jobConfig || {},
|
|
484
|
-
}));
|
|
485
|
-
}
|
|
486
|
-
export function stopAllJobs() {
|
|
487
|
-
for (const [name, task] of activeTasks) {
|
|
488
|
-
task.stop();
|
|
489
|
-
logger.info(`[Scheduler] Stopped job: ${name}`);
|
|
490
|
-
}
|
|
491
|
-
activeTasks.clear();
|
|
492
|
-
}
|
|
493
|
-
//# sourceMappingURL=cron-scheduler.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Heartbeat - Fallback job execution via heartbeat checking */
|
|
2
|
-
export declare function heartbeat(): Promise<{
|
|
3
|
-
checked: boolean;
|
|
4
|
-
overdueCount: number;
|
|
5
|
-
executedJobs: string[];
|
|
6
|
-
}>;
|
|
7
|
-
export declare function startHeartbeatChecking(): void;
|
|
8
|
-
export declare function stopHeartbeatChecking(): void;
|
|
9
|
-
export declare function getLastHeartbeat(): Date | null;
|
|
10
|
-
export declare function isHeartbeatDue(): boolean;
|
|
11
|
-
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/** Heartbeat - Fallback job execution via heartbeat checking */
|
|
2
|
-
import { logger } from '../logger.js';
|
|
3
|
-
import { config } from '../../config.js';
|
|
4
|
-
import { getOverdueJobs, executeJob } from './cron-scheduler.js';
|
|
5
|
-
let lastHeartbeat = null;
|
|
6
|
-
let heartbeatInterval = null;
|
|
7
|
-
export async function heartbeat() {
|
|
8
|
-
const result = {
|
|
9
|
-
checked: false,
|
|
10
|
-
overdueCount: 0,
|
|
11
|
-
executedJobs: [],
|
|
12
|
-
};
|
|
13
|
-
if (config.schedulerMode === 'cron' && config.cronEnabled) {
|
|
14
|
-
logger.debug('[Heartbeat] Cron mode active, skipping heartbeat check');
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
lastHeartbeat = new Date();
|
|
18
|
-
result.checked = true;
|
|
19
|
-
try {
|
|
20
|
-
const overdueJobs = await getOverdueJobs();
|
|
21
|
-
result.overdueCount = overdueJobs.length;
|
|
22
|
-
if (overdueJobs.length === 0) {
|
|
23
|
-
logger.debug('[Heartbeat] No overdue jobs');
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
logger.info(`[Heartbeat] Found ${overdueJobs.length} overdue jobs, executing...`);
|
|
27
|
-
for (const job of overdueJobs) {
|
|
28
|
-
try {
|
|
29
|
-
await executeJob(job);
|
|
30
|
-
result.executedJobs.push(job.jobName);
|
|
31
|
-
logger.info(`[Heartbeat] Executed overdue job: ${job.jobName}`);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
logger.error(`[Heartbeat] Failed to execute job ${job.jobName}:`, error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
logger.error('[Heartbeat] Failed to check overdue jobs:', error);
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function startHeartbeatChecking() {
|
|
45
|
-
if (config.schedulerMode === 'cron' && config.cronEnabled) {
|
|
46
|
-
logger.info('[Heartbeat] Cron mode active, heartbeat checking disabled');
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
stopHeartbeatChecking();
|
|
50
|
-
heartbeatInterval = setInterval(async () => {
|
|
51
|
-
await heartbeat();
|
|
52
|
-
}, config.heartbeatInterval);
|
|
53
|
-
logger.info(`[Heartbeat] Started periodic checking (interval: ${config.heartbeatInterval}ms)`);
|
|
54
|
-
heartbeat().catch(err => {
|
|
55
|
-
logger.error('[Heartbeat] Initial heartbeat failed:', err);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
export function stopHeartbeatChecking() {
|
|
59
|
-
if (heartbeatInterval) {
|
|
60
|
-
clearInterval(heartbeatInterval);
|
|
61
|
-
heartbeatInterval = null;
|
|
62
|
-
logger.info('[Heartbeat] Stopped periodic checking');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function getLastHeartbeat() {
|
|
66
|
-
return lastHeartbeat;
|
|
67
|
-
}
|
|
68
|
-
export function isHeartbeatDue() {
|
|
69
|
-
if (!lastHeartbeat)
|
|
70
|
-
return true;
|
|
71
|
-
return Date.now() - lastHeartbeat.getTime() > config.heartbeatInterval;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=heartbeat.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Job Runner - Maintenance job implementations */
|
|
2
|
-
import { type JobExecutionContext } from './cron-scheduler.js';
|
|
3
|
-
export declare function runNightlyJob(context: JobExecutionContext): Promise<{
|
|
4
|
-
recordsProcessed: number;
|
|
5
|
-
summary: Record<string, unknown>;
|
|
6
|
-
}>;
|
|
7
|
-
export declare function runWeeklyJob(context: JobExecutionContext): Promise<{
|
|
8
|
-
recordsProcessed: number;
|
|
9
|
-
summary: Record<string, unknown>;
|
|
10
|
-
}>;
|
|
11
|
-
//# sourceMappingURL=job-runner.d.ts.map
|