@vheins/local-memory-mcp 0.7.2 → 0.7.3

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.
@@ -1899,7 +1899,6 @@ function resolveDbPath() {
1899
1899
  return standardPath;
1900
1900
  }
1901
1901
  var DB_PATH = resolveDbPath();
1902
- var dbPathInstance = "";
1903
1902
  var sqlJsReady = null;
1904
1903
  var sqlJsModule = null;
1905
1904
  async function getSqlJs() {
@@ -1934,9 +1933,12 @@ var SQLiteStore = class _SQLiteStore {
1934
1933
  system;
1935
1934
  summaries;
1936
1935
  _ready;
1936
+ lastLoadedAt = 0;
1937
+ saveDbPtr;
1938
+ dbPathInstance;
1937
1939
  constructor(dbPath) {
1938
1940
  const finalPath = dbPath ?? DB_PATH;
1939
- dbPathInstance = finalPath;
1941
+ this.dbPathInstance = finalPath;
1940
1942
  warmUpSqlJs();
1941
1943
  this.db = {};
1942
1944
  this.memories = {};
@@ -1963,23 +1965,58 @@ var SQLiteStore = class _SQLiteStore {
1963
1965
  db = new SQL.Database();
1964
1966
  }
1965
1967
  }
1966
- const saveDb = createSaveFunction(db, finalPath);
1968
+ this.saveDbPtr = createSaveFunction(db, finalPath);
1969
+ const wrappedSaveDb = () => {
1970
+ if (this.saveDbPtr) {
1971
+ this.saveDbPtr();
1972
+ this.lastLoadedAt = Date.now();
1973
+ }
1974
+ };
1967
1975
  db.run("PRAGMA journal_mode = WAL");
1968
1976
  db.run("PRAGMA synchronous = NORMAL");
1969
1977
  db.run("PRAGMA busy_timeout = 5000");
1970
- const migrator = new MigrationManager(db, saveDb);
1978
+ const migrator = new MigrationManager(db, wrappedSaveDb);
1971
1979
  migrator.migrate();
1972
1980
  migrator.addMemoryCodeColumn();
1973
1981
  Object.assign(this, {
1974
1982
  db,
1975
- memories: new MemoryEntity(db, saveDb),
1976
- tasks: new TaskEntity(db, saveDb),
1977
- actions: new ActionEntity(db, saveDb),
1978
- system: new SystemEntity(db, saveDb),
1979
- summaries: new SummaryEntity(db, saveDb)
1983
+ memories: new MemoryEntity(db, wrappedSaveDb),
1984
+ tasks: new TaskEntity(db, wrappedSaveDb),
1985
+ actions: new ActionEntity(db, wrappedSaveDb),
1986
+ system: new SystemEntity(db, wrappedSaveDb),
1987
+ summaries: new SummaryEntity(db, wrappedSaveDb)
1980
1988
  });
1989
+ this.lastLoadedAt = Date.now();
1981
1990
  if (finalPath !== ":memory:") {
1982
- saveDb();
1991
+ wrappedSaveDb();
1992
+ }
1993
+ }
1994
+ async refresh(force = false) {
1995
+ const path5 = this.getDbPath();
1996
+ if (path5 === ":memory:") return;
1997
+ try {
1998
+ const stats = fs2.statSync(path5);
1999
+ const mtime = stats.mtimeMs;
2000
+ if (force || mtime > this.lastLoadedAt) {
2001
+ const SQL = await getSqlJs();
2002
+ const fileBuffer = fs2.readFileSync(path5);
2003
+ const newDb = new SQL.Database(fileBuffer);
2004
+ const wrappedSaveDb = () => {
2005
+ if (this.saveDbPtr) {
2006
+ this.saveDbPtr();
2007
+ this.lastLoadedAt = Date.now();
2008
+ }
2009
+ };
2010
+ this.db = newDb;
2011
+ this.memories = new MemoryEntity(newDb, wrappedSaveDb);
2012
+ this.tasks = new TaskEntity(newDb, wrappedSaveDb);
2013
+ this.actions = new ActionEntity(newDb, wrappedSaveDb);
2014
+ this.system = new SystemEntity(newDb, wrappedSaveDb);
2015
+ this.summaries = new SummaryEntity(newDb, wrappedSaveDb);
2016
+ this.lastLoadedAt = Date.now();
2017
+ }
2018
+ } catch (e) {
2019
+ console.error("Failed to refresh database from disk:", e);
1983
2020
  }
1984
2021
  }
1985
2022
  async ready() {
@@ -1991,7 +2028,7 @@ var SQLiteStore = class _SQLiteStore {
1991
2028
  return store;
1992
2029
  }
1993
2030
  getDbPath() {
1994
- return dbPathInstance;
2031
+ return this.dbPathInstance;
1995
2032
  }
1996
2033
  close() {
1997
2034
  if (this.db && this.db.close) {