mnemosyne-core 2.0.0 → 2.0.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.
@@ -4533,7 +4533,7 @@ var require_filesystem = __commonJS({
4533
4533
  var LDD_PATH = "/usr/bin/ldd";
4534
4534
  var SELF_PATH = "/proc/self/exe";
4535
4535
  var MAX_LENGTH = 2048;
4536
- var readFileSync6 = (path) => {
4536
+ var readFileSync5 = (path) => {
4537
4537
  const fd = fs.openSync(path, "r");
4538
4538
  const buffer = Buffer.alloc(MAX_LENGTH);
4539
4539
  const bytesRead = fs.readSync(fd, buffer, 0, MAX_LENGTH, 0);
@@ -4558,7 +4558,7 @@ var require_filesystem = __commonJS({
4558
4558
  module2.exports = {
4559
4559
  LDD_PATH,
4560
4560
  SELF_PATH,
4561
- readFileSync: readFileSync6,
4561
+ readFileSync: readFileSync5,
4562
4562
  readFile
4563
4563
  };
4564
4564
  }
@@ -4607,7 +4607,7 @@ var require_detect_libc = __commonJS({
4607
4607
  "use strict";
4608
4608
  var childProcess = require("child_process");
4609
4609
  var { isLinux, getReport } = require_process();
4610
- var { LDD_PATH, SELF_PATH, readFile, readFileSync: readFileSync6 } = require_filesystem();
4610
+ var { LDD_PATH, SELF_PATH, readFile, readFileSync: readFileSync5 } = require_filesystem();
4611
4611
  var { interpreterPath } = require_elf();
4612
4612
  var cachedFamilyInterpreter;
4613
4613
  var cachedFamilyFilesystem;
@@ -4699,7 +4699,7 @@ var require_detect_libc = __commonJS({
4699
4699
  }
4700
4700
  cachedFamilyFilesystem = null;
4701
4701
  try {
4702
- const lddContent = readFileSync6(LDD_PATH);
4702
+ const lddContent = readFileSync5(LDD_PATH);
4703
4703
  cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
4704
4704
  } catch (e) {
4705
4705
  }
@@ -4724,7 +4724,7 @@ var require_detect_libc = __commonJS({
4724
4724
  }
4725
4725
  cachedFamilyInterpreter = null;
4726
4726
  try {
4727
- const selfContent = readFileSync6(SELF_PATH);
4727
+ const selfContent = readFileSync5(SELF_PATH);
4728
4728
  const path = interpreterPath(selfContent);
4729
4729
  cachedFamilyInterpreter = familyFromInterpreterPath(path);
4730
4730
  } catch (e) {
@@ -4788,7 +4788,7 @@ var require_detect_libc = __commonJS({
4788
4788
  }
4789
4789
  cachedVersionFilesystem = null;
4790
4790
  try {
4791
- const lddContent = readFileSync6(LDD_PATH);
4791
+ const lddContent = readFileSync5(LDD_PATH);
4792
4792
  const versionMatch = lddContent.match(RE_GLIBC_VERSION);
4793
4793
  if (versionMatch) {
4794
4794
  cachedVersionFilesystem = versionMatch[1];
@@ -9605,7 +9605,7 @@ module.exports = __toCommonJS(server_exports);
9605
9605
 
9606
9606
  // src/server/MnemosyneServer.ts
9607
9607
  var import_http = require("http");
9608
- var import_fs6 = require("fs");
9608
+ var import_fs5 = require("fs");
9609
9609
  var import_path6 = require("path");
9610
9610
 
9611
9611
  // node_modules/ws/wrapper.mjs
@@ -12300,9 +12300,219 @@ ${JSON.stringify(analysis.metadata, null, 2)}
12300
12300
 
12301
12301
  // src/db/connection.ts
12302
12302
  var import_better_sqlite32 = __toESM(require("better-sqlite3"));
12303
- var import_fs5 = require("fs");
12304
12303
  var import_path5 = require("path");
12305
12304
  init_config();
12305
+
12306
+ // src/db/schema.ts
12307
+ var SCHEMA_SQL = `-- Mnemosyne v1.1 Database Schema
12308
+ -- SQLite with sqlite-vec extension for semantic search
12309
+
12310
+ -- PROJECTS (Spaces)
12311
+ CREATE TABLE IF NOT EXISTS projects (
12312
+ id TEXT PRIMARY KEY,
12313
+ name TEXT NOT NULL UNIQUE,
12314
+ description TEXT,
12315
+ icon TEXT DEFAULT '\u25C9',
12316
+ color TEXT DEFAULT '#6366f1',
12317
+ created_at INTEGER DEFAULT (unixepoch()),
12318
+ updated_at INTEGER DEFAULT (unixepoch()),
12319
+ owner TEXT DEFAULT 'human',
12320
+ metadata TEXT DEFAULT '{}'
12321
+ );
12322
+
12323
+ -- ATOMS (Ideas/Nodes)
12324
+ CREATE TABLE IF NOT EXISTS atoms (
12325
+ id TEXT PRIMARY KEY,
12326
+ project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
12327
+ parent_id TEXT REFERENCES atoms(id) ON DELETE CASCADE,
12328
+ title TEXT NOT NULL,
12329
+ summary TEXT,
12330
+ icon TEXT DEFAULT '\u25CF',
12331
+ color TEXT,
12332
+ x REAL,
12333
+ y REAL,
12334
+ auto_path TEXT,
12335
+ path_overridden INTEGER DEFAULT 0,
12336
+ status TEXT DEFAULT 'draft',
12337
+ status_updated_at INTEGER DEFAULT (unixepoch()),
12338
+ embedding_status TEXT DEFAULT 'pending',
12339
+ embedding_error TEXT,
12340
+ block_count INTEGER DEFAULT 0,
12341
+ bond_count INTEGER DEFAULT 0,
12342
+ template_id TEXT,
12343
+ created_at INTEGER DEFAULT (unixepoch()),
12344
+ updated_at INTEGER DEFAULT (unixepoch()),
12345
+ version INTEGER DEFAULT 1,
12346
+ locked_by TEXT,
12347
+ locked_at INTEGER,
12348
+ locked_reason TEXT,
12349
+ owner TEXT DEFAULT 'human',
12350
+ metadata TEXT DEFAULT '{}'
12351
+ );
12352
+
12353
+ -- BLOCKS (Content pieces inside atoms)
12354
+ CREATE TABLE IF NOT EXISTS blocks (
12355
+ id TEXT PRIMARY KEY,
12356
+ atom_id TEXT NOT NULL REFERENCES atoms(id) ON DELETE CASCADE,
12357
+ type TEXT NOT NULL DEFAULT 'text',
12358
+ content TEXT,
12359
+ order_index INTEGER DEFAULT 0,
12360
+ created_at INTEGER DEFAULT (unixepoch()),
12361
+ updated_at INTEGER DEFAULT (unixepoch()),
12362
+ metadata TEXT DEFAULT '{}'
12363
+ );
12364
+
12365
+ -- BONDS (Graph connections between atoms)
12366
+ CREATE TABLE IF NOT EXISTS bonds (
12367
+ id TEXT PRIMARY KEY,
12368
+ source_id TEXT NOT NULL REFERENCES atoms(id) ON DELETE CASCADE,
12369
+ target_id TEXT NOT NULL REFERENCES atoms(id) ON DELETE CASCADE,
12370
+ label TEXT DEFAULT 'connects',
12371
+ color TEXT,
12372
+ created_at INTEGER DEFAULT (unixepoch()),
12373
+ UNIQUE(source_id, target_id)
12374
+ );
12375
+
12376
+ -- ATTACHMENTS (Files in CAS)
12377
+ CREATE TABLE IF NOT EXISTS attachments (
12378
+ id TEXT PRIMARY KEY,
12379
+ block_id TEXT REFERENCES blocks(id) ON DELETE CASCADE,
12380
+ file_name TEXT NOT NULL,
12381
+ file_hash TEXT NOT NULL,
12382
+ file_size INTEGER,
12383
+ mime_type TEXT,
12384
+ created_at INTEGER DEFAULT (unixepoch()),
12385
+ UNIQUE(file_hash)
12386
+ );
12387
+
12388
+ -- EVENT LOG (Immutable audit trail)
12389
+ CREATE TABLE IF NOT EXISTS event_log (
12390
+ id TEXT PRIMARY KEY,
12391
+ timestamp INTEGER DEFAULT (unixepoch()),
12392
+ event_type TEXT NOT NULL,
12393
+ project_id TEXT,
12394
+ atom_id TEXT,
12395
+ block_id TEXT,
12396
+ bond_id TEXT,
12397
+ actor TEXT NOT NULL DEFAULT 'system',
12398
+ actor_type TEXT DEFAULT 'system',
12399
+ diff TEXT,
12400
+ trigger TEXT,
12401
+ metadata TEXT DEFAULT '{}'
12402
+ );
12403
+
12404
+ -- ASSISTANTS (AI Agents)
12405
+ CREATE TABLE IF NOT EXISTS assistants (
12406
+ id TEXT PRIMARY KEY,
12407
+ name TEXT NOT NULL,
12408
+ role TEXT DEFAULT 'worker',
12409
+ permissions TEXT DEFAULT '{"read":["*"],"write":[],"delete":false}',
12410
+ status TEXT DEFAULT 'active',
12411
+ provider TEXT,
12412
+ connected_at INTEGER DEFAULT (unixepoch()),
12413
+ last_seen INTEGER DEFAULT (unixepoch()),
12414
+ metadata TEXT DEFAULT '{}'
12415
+ );
12416
+
12417
+ -- QUEUE (Agent waitlist for locked atoms)
12418
+ CREATE TABLE IF NOT EXISTS queue (
12419
+ id TEXT PRIMARY KEY,
12420
+ atom_id TEXT NOT NULL REFERENCES atoms(id) ON DELETE CASCADE,
12421
+ assistant_id TEXT NOT NULL REFERENCES assistants(id) ON DELETE CASCADE,
12422
+ requested_at INTEGER DEFAULT (unixepoch()),
12423
+ priority INTEGER DEFAULT 5,
12424
+ status TEXT DEFAULT 'waiting',
12425
+ reason TEXT
12426
+ );
12427
+
12428
+ -- INDICES
12429
+ CREATE INDEX IF NOT EXISTS idx_atoms_project ON atoms(project_id);
12430
+ CREATE INDEX IF NOT EXISTS idx_atoms_parent ON atoms(parent_id);
12431
+ CREATE INDEX IF NOT EXISTS idx_atoms_locked ON atoms(locked_by) WHERE locked_by IS NOT NULL;
12432
+ -- idx_atoms_path_project is created by migration after auto_path column is added
12433
+ CREATE INDEX IF NOT EXISTS idx_blocks_atom ON blocks(atom_id);
12434
+ CREATE INDEX IF NOT EXISTS idx_bonds_source ON bonds(source_id);
12435
+ CREATE INDEX IF NOT EXISTS idx_bonds_target ON bonds(target_id);
12436
+ CREATE INDEX IF NOT EXISTS idx_event_log_time ON event_log(timestamp);
12437
+ CREATE INDEX IF NOT EXISTS idx_event_log_atom ON event_log(atom_id);
12438
+ CREATE INDEX IF NOT EXISTS idx_queue_atom ON queue(atom_id);
12439
+ CREATE INDEX IF NOT EXISTS idx_attachments_hash ON attachments(file_hash);
12440
+
12441
+ -- Auto-update block_count and bond_count triggers
12442
+ CREATE TRIGGER IF NOT EXISTS update_block_count_insert AFTER INSERT ON blocks BEGIN
12443
+ UPDATE atoms SET block_count = block_count + 1 WHERE id = NEW.atom_id;
12444
+ END;
12445
+
12446
+ CREATE TRIGGER IF NOT EXISTS update_block_count_delete AFTER DELETE ON blocks BEGIN
12447
+ UPDATE atoms SET block_count = block_count - 1 WHERE id = OLD.atom_id;
12448
+ END;
12449
+
12450
+ CREATE TRIGGER IF NOT EXISTS update_bond_count_insert AFTER INSERT ON bonds BEGIN
12451
+ UPDATE atoms SET bond_count = bond_count + 1 WHERE id = NEW.source_id OR id = NEW.target_id;
12452
+ END;
12453
+
12454
+ CREATE TRIGGER IF NOT EXISTS update_bond_count_delete AFTER DELETE ON bonds BEGIN
12455
+ UPDATE atoms SET bond_count = bond_count - 1 WHERE id = OLD.source_id OR id = OLD.target_id;
12456
+ END;
12457
+
12458
+ -- FTS5 FULL-TEXT SEARCH
12459
+ -- Separate tables to avoid rowid collisions between atoms and blocks
12460
+
12461
+ CREATE VIRTUAL TABLE IF NOT EXISTS search_atoms USING fts5(
12462
+ title, summary,
12463
+ content='atoms', content_rowid='rowid'
12464
+ );
12465
+
12466
+ CREATE VIRTUAL TABLE IF NOT EXISTS search_blocks USING fts5(
12467
+ content,
12468
+ content='blocks', content_rowid='rowid'
12469
+ );
12470
+
12471
+ -- Triggers to keep search_atoms in sync
12472
+ CREATE TRIGGER IF NOT EXISTS trig_search_atoms_insert AFTER INSERT ON atoms BEGIN
12473
+ INSERT INTO search_atoms(rowid, title, summary) VALUES (new.rowid, new.title, COALESCE(new.summary, ''));
12474
+ END;
12475
+
12476
+ CREATE TRIGGER IF NOT EXISTS trig_search_atoms_update AFTER UPDATE ON atoms BEGIN
12477
+ UPDATE search_atoms SET title = new.title, summary = COALESCE(new.summary, '') WHERE rowid = new.rowid;
12478
+ END;
12479
+
12480
+ CREATE TRIGGER IF NOT EXISTS trig_search_atoms_delete AFTER DELETE ON atoms BEGIN
12481
+ DELETE FROM search_atoms WHERE rowid = old.rowid;
12482
+ END;
12483
+
12484
+ -- Triggers to keep search_blocks in sync
12485
+ CREATE TRIGGER IF NOT EXISTS trig_search_blocks_insert AFTER INSERT ON blocks BEGIN
12486
+ INSERT INTO search_blocks(rowid, content) VALUES (new.rowid, COALESCE(new.content, ''));
12487
+ END;
12488
+
12489
+ CREATE TRIGGER IF NOT EXISTS trig_search_blocks_update AFTER UPDATE ON blocks BEGIN
12490
+ UPDATE search_blocks SET content = COALESCE(new.content, '') WHERE rowid = new.rowid;
12491
+ END;
12492
+
12493
+ CREATE TRIGGER IF NOT EXISTS trig_search_blocks_delete AFTER DELETE ON blocks BEGIN
12494
+ DELETE FROM search_blocks WHERE rowid = old.rowid;
12495
+ END;
12496
+
12497
+
12498
+ -- PER-ATOM PERMISSIONS (Granular access control)
12499
+ CREATE TABLE IF NOT EXISTS atom_permissions (
12500
+ id TEXT PRIMARY KEY,
12501
+ atom_id TEXT NOT NULL REFERENCES atoms(id) ON DELETE CASCADE,
12502
+ assistant_id TEXT NOT NULL REFERENCES assistants(id) ON DELETE CASCADE,
12503
+ level TEXT NOT NULL DEFAULT 'view',
12504
+ granted_by TEXT,
12505
+ granted_at INTEGER DEFAULT (unixepoch()),
12506
+ metadata TEXT DEFAULT '{}',
12507
+ UNIQUE(atom_id, assistant_id)
12508
+ );
12509
+
12510
+ -- sqlite-vec virtual table for semantic embeddings
12511
+ -- Created dynamically by connection.ts after loading the extension
12512
+ -- CREATE VIRTUAL TABLE IF NOT EXISTS atom_vectors USING vec0(atom_id TEXT PRIMARY KEY, embedding float[384]);
12513
+ `;
12514
+
12515
+ // src/db/connection.ts
12306
12516
  var DB_PATH2 = process.env.MNEMOSYNE_DB_PATH || (0, import_path5.resolve)(process.cwd(), CONFIG.database.path);
12307
12517
  var db = null;
12308
12518
  var vecEnabled = false;
@@ -12321,8 +12531,7 @@ function getDb() {
12321
12531
  console.warn("[DB] sqlite-vec not available:", err.message);
12322
12532
  vecEnabled = false;
12323
12533
  }
12324
- const schema = (0, import_fs5.readFileSync)((0, import_path5.resolve)(process.cwd(), "src", "db", "schema.sql"), "utf-8");
12325
- db.exec(schema);
12534
+ db.exec(SCHEMA_SQL);
12326
12535
  if (vecEnabled) {
12327
12536
  try {
12328
12537
  db.exec(`CREATE VIRTUAL TABLE IF NOT EXISTS atom_vectors USING vec0(atom_id TEXT PRIMARY KEY, embedding float[${CONFIG.embeddings.dimension}])`);
@@ -12421,8 +12630,8 @@ var MnemosyneServer = class {
12421
12630
  ];
12422
12631
  for (const dir of dirs) {
12423
12632
  const filePath = (0, import_path6.resolve)(dir, urlPath);
12424
- if ((0, import_fs6.existsSync)(filePath)) {
12425
- const data = (0, import_fs6.readFileSync)(filePath);
12633
+ if ((0, import_fs5.existsSync)(filePath)) {
12634
+ const data = (0, import_fs5.readFileSync)(filePath);
12426
12635
  res.writeHead(200, { "Content-Type": mime[ext] || "application/octet-stream" });
12427
12636
  res.end(data);
12428
12637
  return;