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