@velvetmonkey/flywheel-memory 2.0.55 → 2.0.56

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8964,13 +8964,20 @@ function runSweep(index) {
8964
8964
  cachedResults = results;
8965
8965
  return results;
8966
8966
  }
8967
- function startSweepTimer(getIndex, intervalMs) {
8967
+ function startSweepTimer(getIndex, intervalMs, maintenanceCallback) {
8968
8968
  const interval = Math.max(intervalMs ?? DEFAULT_SWEEP_INTERVAL_MS, MIN_SWEEP_INTERVAL_MS);
8969
8969
  setTimeout(() => {
8970
8970
  doSweep(getIndex);
8971
8971
  }, 5e3);
8972
8972
  sweepTimer = setInterval(() => {
8973
8973
  doSweep(getIndex);
8974
+ if (maintenanceCallback) {
8975
+ try {
8976
+ maintenanceCallback();
8977
+ } catch (err) {
8978
+ console.error("[Flywheel] Maintenance error:", err);
8979
+ }
8980
+ }
8974
8981
  }, interval);
8975
8982
  if (sweepTimer && typeof sweepTimer === "object" && "unref" in sweepTimer) {
8976
8983
  sweepTimer.unref();
@@ -8990,6 +8997,12 @@ function doSweep(getIndex) {
8990
8997
  sweepRunning = false;
8991
8998
  }
8992
8999
  }
9000
+ function stopSweepTimer() {
9001
+ if (sweepTimer) {
9002
+ clearInterval(sweepTimer);
9003
+ sweepTimer = null;
9004
+ }
9005
+ }
8993
9006
  function getSweepResults() {
8994
9007
  return cachedResults;
8995
9008
  }
@@ -19292,6 +19305,23 @@ async function buildStartupCatchupBatch(vaultPath2, sinceMs) {
19292
19305
  await scanDir(vaultPath2);
19293
19306
  return events;
19294
19307
  }
19308
+ var lastPurgeAt = Date.now();
19309
+ function runPeriodicMaintenance(db4) {
19310
+ sweepExpiredMemories(db4);
19311
+ decayMemoryConfidence(db4);
19312
+ pruneSupersededMemories(db4, 90);
19313
+ const now = Date.now();
19314
+ if (now - lastPurgeAt > 24 * 60 * 60 * 1e3) {
19315
+ purgeOldMetrics(db4, 90);
19316
+ purgeOldIndexEvents(db4, 90);
19317
+ purgeOldInvocations(db4, 90);
19318
+ purgeOldSuggestionEvents(db4, 30);
19319
+ purgeOldNoteLinkHistory(db4, 90);
19320
+ purgeOldSnapshots(db4, 90);
19321
+ lastPurgeAt = now;
19322
+ serverLog("server", "Daily purge complete");
19323
+ }
19324
+ }
19295
19325
  async function runPostIndexWork(index) {
19296
19326
  const postStart = Date.now();
19297
19327
  serverLog("index", "Scanning entities...");
@@ -20155,8 +20185,12 @@ async function runPostIndexWork(index) {
20155
20185
  watcher.start();
20156
20186
  serverLog("watcher", "File watcher started");
20157
20187
  }
20158
- startSweepTimer(() => vaultIndex);
20159
- serverLog("server", "Sweep timer started (5 min interval)");
20188
+ if (process.env.FLYWHEEL_WATCH !== "false") {
20189
+ startSweepTimer(() => vaultIndex, void 0, () => {
20190
+ if (stateDb) runPeriodicMaintenance(stateDb);
20191
+ });
20192
+ serverLog("server", "Sweep timer started (5 min interval)");
20193
+ }
20160
20194
  const postDuration = Date.now() - postStart;
20161
20195
  serverLog("server", `Post-index work complete in ${postDuration}ms`);
20162
20196
  }
@@ -20187,6 +20221,7 @@ if (process.argv.includes("--init-semantic")) {
20187
20221
  });
20188
20222
  }
20189
20223
  process.on("beforeExit", async () => {
20224
+ stopSweepTimer();
20190
20225
  await flushLogs();
20191
20226
  });
20192
20227
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velvetmonkey/flywheel-memory",
3
- "version": "2.0.55",
3
+ "version": "2.0.56",
4
4
  "description": "MCP server that gives Claude full read/write access to your Obsidian vault. Select from 42 tools for search, backlinks, graph queries, mutations, and hybrid semantic search.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",