superlocalmemory 3.4.1 → 3.4.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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/pyproject.toml +11 -2
  3. package/scripts/postinstall.js +26 -7
  4. package/src/superlocalmemory/cli/commands.py +42 -60
  5. package/src/superlocalmemory/cli/daemon.py +107 -47
  6. package/src/superlocalmemory/cli/main.py +10 -0
  7. package/src/superlocalmemory/cli/setup_wizard.py +137 -9
  8. package/src/superlocalmemory/core/config.py +28 -0
  9. package/src/superlocalmemory/core/consolidation_engine.py +38 -1
  10. package/src/superlocalmemory/core/engine.py +9 -0
  11. package/src/superlocalmemory/core/health_monitor.py +313 -0
  12. package/src/superlocalmemory/core/reranker_worker.py +19 -5
  13. package/src/superlocalmemory/ingestion/__init__.py +13 -0
  14. package/src/superlocalmemory/ingestion/adapter_manager.py +234 -0
  15. package/src/superlocalmemory/ingestion/base_adapter.py +177 -0
  16. package/src/superlocalmemory/ingestion/calendar_adapter.py +340 -0
  17. package/src/superlocalmemory/ingestion/credentials.py +118 -0
  18. package/src/superlocalmemory/ingestion/gmail_adapter.py +369 -0
  19. package/src/superlocalmemory/ingestion/parsers.py +100 -0
  20. package/src/superlocalmemory/ingestion/transcript_adapter.py +156 -0
  21. package/src/superlocalmemory/learning/consolidation_worker.py +47 -1
  22. package/src/superlocalmemory/learning/entity_compiler.py +377 -0
  23. package/src/superlocalmemory/mesh/__init__.py +12 -0
  24. package/src/superlocalmemory/mesh/broker.py +344 -0
  25. package/src/superlocalmemory/retrieval/entity_channel.py +12 -6
  26. package/src/superlocalmemory/server/api.py +6 -7
  27. package/src/superlocalmemory/server/routes/entity.py +95 -0
  28. package/src/superlocalmemory/server/routes/ingest.py +110 -0
  29. package/src/superlocalmemory/server/routes/mesh.py +186 -0
  30. package/src/superlocalmemory/server/unified_daemon.py +691 -0
  31. package/src/superlocalmemory/storage/schema_v343.py +229 -0
  32. package/src/superlocalmemory.egg-info/PKG-INFO +0 -597
  33. package/src/superlocalmemory.egg-info/SOURCES.txt +0 -287
  34. package/src/superlocalmemory.egg-info/dependency_links.txt +0 -1
  35. package/src/superlocalmemory.egg-info/entry_points.txt +0 -2
  36. package/src/superlocalmemory.egg-info/requires.txt +0 -47
  37. package/src/superlocalmemory.egg-info/top_level.txt +0 -1
@@ -0,0 +1,229 @@
1
+ # Copyright (c) 2026 Varun Pratap Bhardwaj / Qualixar
2
+ # Licensed under the Elastic License 2.0 - see LICENSE file
3
+ # Part of SuperLocalMemory V3 | https://qualixar.com | https://varunpratap.com
4
+
5
+ """SuperLocalMemory V3.4.3 "The Unified Brain" — Schema Extensions.
6
+
7
+ All new tables for v3.4.3 features:
8
+ - Phase C: Mesh broker tables (mesh_peers, mesh_messages, mesh_state, mesh_locks, mesh_events)
9
+ - Phase D: Entity compilation (ALTER entity_profiles + new index)
10
+ - Phase E: Ingestion log (ingestion_log)
11
+
12
+ Design rules (inherited from schema_v32.py):
13
+ - CREATE IF NOT EXISTS for idempotency
14
+ - profile_id where applicable
15
+ - Never ALTER existing column types (add new columns only)
16
+
17
+ Part of Qualixar | Author: Varun Pratap Bhardwaj
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import logging
23
+ import sqlite3
24
+ from typing import Final
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+ # ---------------------------------------------------------------------------
29
+ # Table names (for reference and rollback)
30
+ # ---------------------------------------------------------------------------
31
+
32
+ V343_TABLES: Final[tuple[str, ...]] = (
33
+ "mesh_peers",
34
+ "mesh_messages",
35
+ "mesh_state",
36
+ "mesh_locks",
37
+ "mesh_events",
38
+ "ingestion_log",
39
+ )
40
+
41
+ # ---------------------------------------------------------------------------
42
+ # DDL — Phase C: Mesh Broker Tables
43
+ # ---------------------------------------------------------------------------
44
+
45
+ _MESH_DDL = """
46
+ -- Mesh Peers
47
+ CREATE TABLE IF NOT EXISTS mesh_peers (
48
+ peer_id TEXT PRIMARY KEY,
49
+ session_id TEXT NOT NULL,
50
+ summary TEXT DEFAULT '',
51
+ status TEXT DEFAULT 'active',
52
+ host TEXT DEFAULT '127.0.0.1',
53
+ port INTEGER DEFAULT 0,
54
+ registered_at TEXT NOT NULL,
55
+ last_heartbeat TEXT NOT NULL
56
+ );
57
+
58
+ -- Mesh Messages
59
+ CREATE TABLE IF NOT EXISTS mesh_messages (
60
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
61
+ from_peer TEXT NOT NULL,
62
+ to_peer TEXT NOT NULL,
63
+ msg_type TEXT DEFAULT 'text',
64
+ content TEXT NOT NULL,
65
+ read INTEGER DEFAULT 0,
66
+ created_at TEXT NOT NULL
67
+ );
68
+
69
+ -- Mesh State (shared key-value store)
70
+ CREATE TABLE IF NOT EXISTS mesh_state (
71
+ key TEXT PRIMARY KEY,
72
+ value TEXT NOT NULL,
73
+ set_by TEXT NOT NULL,
74
+ updated_at TEXT NOT NULL
75
+ );
76
+
77
+ -- Mesh Locks (file-level locks for coordination)
78
+ CREATE TABLE IF NOT EXISTS mesh_locks (
79
+ file_path TEXT PRIMARY KEY,
80
+ locked_by TEXT NOT NULL,
81
+ locked_at TEXT NOT NULL,
82
+ expires_at TEXT NOT NULL DEFAULT '9999-12-31T23:59:59Z'
83
+ );
84
+
85
+ -- Mesh Events (audit log)
86
+ CREATE TABLE IF NOT EXISTS mesh_events (
87
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
88
+ event_type TEXT NOT NULL,
89
+ payload TEXT DEFAULT '{}',
90
+ emitted_by TEXT NOT NULL,
91
+ created_at TEXT NOT NULL
92
+ );
93
+
94
+ CREATE INDEX IF NOT EXISTS idx_mesh_messages_to
95
+ ON mesh_messages(to_peer, read);
96
+ CREATE INDEX IF NOT EXISTS idx_mesh_events_type
97
+ ON mesh_events(event_type, created_at);
98
+ """
99
+
100
+ # ---------------------------------------------------------------------------
101
+ # DDL — Phase D: Entity Compilation (ALTER entity_profiles)
102
+ # ---------------------------------------------------------------------------
103
+
104
+ _ENTITY_COMPILATION_ALTERS = [
105
+ "ALTER TABLE entity_profiles ADD COLUMN project_name TEXT DEFAULT ''",
106
+ "ALTER TABLE entity_profiles ADD COLUMN compiled_truth TEXT DEFAULT ''",
107
+ "ALTER TABLE entity_profiles ADD COLUMN timeline TEXT DEFAULT '[]'",
108
+ "ALTER TABLE entity_profiles ADD COLUMN compilation_confidence REAL DEFAULT 0.5",
109
+ "ALTER TABLE entity_profiles ADD COLUMN last_compiled_at TEXT DEFAULT NULL",
110
+ ]
111
+
112
+ _ENTITY_COMPILATION_INDEX = """
113
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_entity_profiles_compilation
114
+ ON entity_profiles(entity_id, profile_id, project_name);
115
+ CREATE INDEX IF NOT EXISTS idx_entity_profiles_project
116
+ ON entity_profiles(profile_id, project_name);
117
+ """
118
+
119
+ # ---------------------------------------------------------------------------
120
+ # DDL — Phase E: Ingestion Log
121
+ # ---------------------------------------------------------------------------
122
+
123
+ _INGESTION_DDL = """
124
+ CREATE TABLE IF NOT EXISTS ingestion_log (
125
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
126
+ source_type TEXT NOT NULL,
127
+ dedup_key TEXT NOT NULL,
128
+ fact_ids TEXT DEFAULT '[]',
129
+ metadata TEXT DEFAULT '{}',
130
+ status TEXT DEFAULT 'ingested',
131
+ ingested_at TEXT NOT NULL,
132
+ UNIQUE(source_type, dedup_key)
133
+ );
134
+ CREATE INDEX IF NOT EXISTS idx_ingestion_dedup
135
+ ON ingestion_log(source_type, dedup_key);
136
+ """
137
+
138
+ # ---------------------------------------------------------------------------
139
+ # Version marker
140
+ # ---------------------------------------------------------------------------
141
+
142
+ _VERSION_DDL = """
143
+ CREATE TABLE IF NOT EXISTS schema_version (
144
+ version TEXT PRIMARY KEY,
145
+ applied_at TEXT NOT NULL
146
+ );
147
+ """
148
+
149
+
150
+ # ---------------------------------------------------------------------------
151
+ # Migration runner
152
+ # ---------------------------------------------------------------------------
153
+
154
+ def apply_v343_schema(db_path: str | sqlite3.Connection) -> dict:
155
+ """Apply all v3.4.3 schema changes. Idempotent — safe to call multiple times.
156
+
157
+ Returns dict with migration status and any errors.
158
+ """
159
+ result = {"applied": [], "skipped": [], "errors": []}
160
+
161
+ if isinstance(db_path, sqlite3.Connection):
162
+ conn = db_path
163
+ own_connection = False
164
+ else:
165
+ conn = sqlite3.connect(str(db_path))
166
+ own_connection = True
167
+
168
+ try:
169
+ # Check if already applied
170
+ try:
171
+ row = conn.execute(
172
+ "SELECT version FROM schema_version WHERE version = '3.4.3'"
173
+ ).fetchone()
174
+ if row:
175
+ result["skipped"].append("v3.4.3 already applied")
176
+ return result
177
+ except sqlite3.OperationalError:
178
+ pass # schema_version table doesn't exist yet
179
+
180
+ # Apply version table
181
+ conn.executescript(_VERSION_DDL)
182
+
183
+ # Phase C: Mesh tables
184
+ try:
185
+ conn.executescript(_MESH_DDL)
186
+ result["applied"].append("mesh tables (5 tables, 2 indexes)")
187
+ except sqlite3.OperationalError as e:
188
+ result["errors"].append(f"mesh: {e}")
189
+
190
+ # Phase D: Entity compilation ALTER TABLE
191
+ for alter_sql in _ENTITY_COMPILATION_ALTERS:
192
+ try:
193
+ conn.execute(alter_sql)
194
+ result["applied"].append(alter_sql.split("ADD COLUMN")[1].strip().split()[0])
195
+ except sqlite3.OperationalError:
196
+ # Column already exists — fine (idempotent)
197
+ pass
198
+
199
+ try:
200
+ conn.executescript(_ENTITY_COMPILATION_INDEX)
201
+ result["applied"].append("entity_profiles indexes")
202
+ except sqlite3.OperationalError as e:
203
+ result["errors"].append(f"entity indexes: {e}")
204
+
205
+ # Phase E: Ingestion log
206
+ try:
207
+ conn.executescript(_INGESTION_DDL)
208
+ result["applied"].append("ingestion_log table")
209
+ except sqlite3.OperationalError as e:
210
+ result["errors"].append(f"ingestion: {e}")
211
+
212
+ # Mark version
213
+ conn.execute(
214
+ "INSERT OR IGNORE INTO schema_version (version, applied_at) VALUES (?, ?)",
215
+ ("3.4.3", __import__("datetime").datetime.now().isoformat()),
216
+ )
217
+ conn.commit()
218
+
219
+ if result["applied"]:
220
+ logger.info("Schema v3.4.3 applied: %s", ", ".join(result["applied"]))
221
+
222
+ except Exception as e:
223
+ result["errors"].append(f"fatal: {e}")
224
+ logger.error("Schema v3.4.3 migration failed: %s", e)
225
+ finally:
226
+ if own_connection:
227
+ conn.close()
228
+
229
+ return result