@jungjaehoon/mama-core 1.3.3 → 1.4.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.
- package/README.md +67 -19
- package/db/migrations/001-initial-decision-graph.sql +6 -1
- package/db/migrations/002-add-error-patterns.sql +1 -1
- package/db/migrations/014-add-is-static-column.sql +5 -0
- package/db/migrations/015-add-fts5-search.sql +34 -0
- package/db/migrations/016-add-memory-v2-columns.sql +14 -0
- package/db/migrations/017-create-memory-scopes.sql +10 -0
- package/db/migrations/018-create-memory-scope-bindings.sql +15 -0
- package/db/migrations/019-create-memory-events.sql +18 -0
- package/db/migrations/020-create-audit-findings.sql +18 -0
- package/db/migrations/021-create-memory-truth.sql +20 -0
- package/db/migrations/022-create-channel-summaries.sql +9 -0
- package/db/migrations/023-create-channel-summary-state.sql +9 -0
- package/db/migrations/024-add-event-date.sql +9 -0
- package/db/migrations/025-extend-kind-check.sql +59 -0
- package/dist/config-loader.d.ts +1 -1
- package/dist/config-loader.js +3 -3
- package/dist/db-adapter/base-adapter.d.ts +2 -2
- package/dist/db-adapter/index.js +2 -8
- package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -1
- package/dist/db-adapter/node-sqlite-adapter.js +99 -45
- package/dist/db-manager.d.ts +32 -4
- package/dist/db-manager.js +133 -8
- package/dist/decision-formatter.d.ts +2 -0
- package/dist/embedding-server/mobile/session-manager.js +22 -7
- package/dist/embeddings.d.ts +2 -2
- package/dist/embeddings.js +2 -2
- package/dist/index.d.ts +5 -1
- package/dist/index.js +31 -3
- package/dist/mama-api.d.ts +67 -2
- package/dist/mama-api.js +295 -80
- package/dist/memory/api.d.ts +81 -0
- package/dist/memory/api.js +972 -0
- package/dist/memory/bootstrap-builder.d.ts +10 -0
- package/dist/memory/bootstrap-builder.js +66 -0
- package/dist/memory/channel-summary-state-store.d.ts +19 -0
- package/dist/memory/channel-summary-state-store.js +223 -0
- package/dist/memory/channel-summary-store.d.ts +8 -0
- package/dist/memory/channel-summary-store.js +41 -0
- package/dist/memory/event-store.d.ts +5 -0
- package/dist/memory/event-store.js +72 -0
- package/dist/memory/evolution-engine.d.ts +22 -0
- package/dist/memory/evolution-engine.js +133 -0
- package/dist/memory/extraction-prompt.d.ts +4 -0
- package/dist/memory/extraction-prompt.js +89 -0
- package/dist/memory/finding-store.d.ts +5 -0
- package/dist/memory/finding-store.js +75 -0
- package/dist/memory/profile-builder.d.ts +3 -0
- package/dist/memory/profile-builder.js +23 -0
- package/dist/memory/scope-store.d.ts +5 -0
- package/dist/memory/scope-store.js +13 -0
- package/dist/memory/truth-store.d.ts +11 -0
- package/dist/memory/truth-store.js +102 -0
- package/dist/memory/types.d.ts +267 -0
- package/dist/memory/types.js +83 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -74,12 +74,40 @@ const mamaApi = require('@jungjaehoon/mama-core/mama-api');
|
|
|
74
74
|
- CRUD operations for decisions
|
|
75
75
|
- Vector similarity search
|
|
76
76
|
|
|
77
|
-
###
|
|
77
|
+
### Memory API
|
|
78
78
|
|
|
79
|
-
- **
|
|
79
|
+
- **memory/api** - Scoped memory operations
|
|
80
|
+
- `saveMemory(input)` - Save typed memory with scopes and optional event_date (preference, fact, decision, lesson, constraint)
|
|
81
|
+
- `recallMemory(query, options)` - Truth-aware recall with scope filtering
|
|
82
|
+
- `buildProfile(scopes)` - Build memory profile (static/dynamic/evidence)
|
|
83
|
+
- `ingestMemory(input)` - Ingest raw content as memory
|
|
84
|
+
- `ingestConversation(input)` - Decompose conversations into typed memory units via optional LLM extraction
|
|
85
|
+
- `evolveMemory(input)` - Resolve graph edges between memories
|
|
86
|
+
- `buildMemoryBootstrap(params)` - Build memory agent bootstrap context
|
|
87
|
+
- `createAuditAck(input)` - Create audit acknowledgment
|
|
88
|
+
- `recordMemoryAudit(input)` - Record channel audit with state management
|
|
89
|
+
|
|
90
|
+
- **memory/truth-store** - Truth projection layer
|
|
91
|
+
- `projectMemoryTruth(row)` - Write truth projection
|
|
92
|
+
- `queryRelevantTruth(params)` - Query current truth with scope/query filtering
|
|
93
|
+
- `queryTruthByTopic(topic)` - Get truth rows for a topic
|
|
94
|
+
|
|
95
|
+
- **memory/evolution-engine** - Graph edge resolution
|
|
96
|
+
- `resolveMemoryEvolution(input)` - Determine supersedes/builds_on edges
|
|
97
|
+
|
|
98
|
+
- **memory/extraction-prompt** - LLM extraction for conversation ingestion
|
|
99
|
+
- `buildExtractionPrompt(messages)` - Build structured prompt for memory extraction
|
|
100
|
+
- `parseExtractionResponse(response)` - Parse LLM JSON response into typed units
|
|
101
|
+
|
|
102
|
+
- **memory/channel-summary-state-store** - Channel state management
|
|
103
|
+
- `recordChannelAudit(input)` - Accumulate audit outcomes into channel state
|
|
104
|
+
|
|
105
|
+
### Core API (Legacy)
|
|
106
|
+
|
|
107
|
+
- **mama-api** - High-level API interface (wraps memory API)
|
|
80
108
|
- `save(decision)` - Save decision
|
|
81
109
|
- `recall(topic)` - Retrieve decision history
|
|
82
|
-
- `suggest(query)` - Semantic search
|
|
110
|
+
- `suggest(query)` - Semantic search with hybrid FTS5 + vector + recency
|
|
83
111
|
- `updateOutcome(id, outcome)` - Update decision outcome
|
|
84
112
|
|
|
85
113
|
- **decision-tracker** - Decision graph management
|
|
@@ -125,12 +153,15 @@ pnpm test:watch
|
|
|
125
153
|
|
|
126
154
|
## Test Coverage
|
|
127
155
|
|
|
128
|
-
-
|
|
156
|
+
- 72 unit tests across 17 test files
|
|
129
157
|
- 100% passing
|
|
130
158
|
- Tests cover:
|
|
131
|
-
- Config loader
|
|
132
|
-
-
|
|
133
|
-
-
|
|
159
|
+
- Config loader, database initialization, module exports
|
|
160
|
+
- Memory API (save, recall, profile)
|
|
161
|
+
- Truth store, evolution engine, scope schema
|
|
162
|
+
- Channel summary, channel summary state
|
|
163
|
+
- Event store, finding store, bootstrap builder
|
|
164
|
+
- Legacy shim compatibility
|
|
134
165
|
|
|
135
166
|
## Architecture
|
|
136
167
|
|
|
@@ -139,23 +170,40 @@ MAMA Core uses CommonJS modules and is designed to be shared across multiple pac
|
|
|
139
170
|
```
|
|
140
171
|
packages/mama-core/
|
|
141
172
|
├── src/
|
|
142
|
-
│ ├── index.
|
|
143
|
-
│ ├── embeddings.
|
|
144
|
-
│ ├── db-manager.
|
|
145
|
-
│ ├── mama-api.
|
|
146
|
-
│
|
|
147
|
-
|
|
148
|
-
|
|
173
|
+
│ ├── index.ts # Main exports
|
|
174
|
+
│ ├── embeddings.ts # Embedding generation
|
|
175
|
+
│ ├── db-manager.ts # Database management
|
|
176
|
+
│ ├── mama-api.ts # High-level API (wraps memory API)
|
|
177
|
+
│ ├── db-adapter/ # Database adapter (SQLite)
|
|
178
|
+
│ └── memory/ # Memory infrastructure
|
|
179
|
+
│ ├── types.ts # MemoryRecord, MemoryScopeRef, RecallBundle, etc.
|
|
180
|
+
│ ├── api.ts # saveMemory, recallMemory, buildProfile, etc.
|
|
181
|
+
│ ├── truth-store.ts # Truth projection layer
|
|
182
|
+
│ ├── extraction-prompt.ts # LLM extraction prompt + parser
|
|
183
|
+
│ ├── evolution-engine.ts # Graph edge resolution
|
|
184
|
+
│ ├── scope-store.ts # Scope management
|
|
185
|
+
│ ├── event-store.ts # Audit event persistence
|
|
186
|
+
│ ├── finding-store.ts # Audit finding persistence
|
|
187
|
+
│ ├── channel-summary-store.ts # Channel summaries
|
|
188
|
+
│ ├── channel-summary-state-store.ts # Channel state reducer
|
|
189
|
+
│ ├── bootstrap-builder.ts # Memory agent bootstrap
|
|
190
|
+
│ └── profile-builder.ts # Profile classification
|
|
191
|
+
├── db/migrations/ # SQLite migrations (001-023)
|
|
192
|
+
└── tests/ # 16 test files, 59 tests
|
|
149
193
|
```
|
|
150
194
|
|
|
151
195
|
## Migration Files
|
|
152
196
|
|
|
153
|
-
Database migrations are included in `db/migrations
|
|
197
|
+
Database migrations are included in `db/migrations/` (001-023):
|
|
154
198
|
|
|
155
|
-
- 001-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
199
|
+
- 001-013: Core schema (decisions, embeddings, graph edges)
|
|
200
|
+
- 014: Add is_static column
|
|
201
|
+
- 015: FTS5 full-text search index
|
|
202
|
+
- 016: Memory kind/status/summary columns
|
|
203
|
+
- 017-018: Memory scopes and scope bindings
|
|
204
|
+
- 019-020: Memory events and audit findings
|
|
205
|
+
- 021: Memory truth projection
|
|
206
|
+
- 022-023: Channel summaries and state
|
|
159
207
|
|
|
160
208
|
## License
|
|
161
209
|
|
|
@@ -100,7 +100,12 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|
|
100
100
|
-- Timestamps
|
|
101
101
|
started_at INTEGER DEFAULT (unixepoch() * 1000),
|
|
102
102
|
last_active_at INTEGER DEFAULT (unixepoch() * 1000),
|
|
103
|
+
last_active TEXT,
|
|
104
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
103
105
|
ended_at INTEGER,
|
|
106
|
+
status TEXT DEFAULT 'active',
|
|
107
|
+
pid INTEGER,
|
|
108
|
+
client_id TEXT,
|
|
104
109
|
|
|
105
110
|
CHECK (action_count >= 0),
|
|
106
111
|
CHECK (decision_count >= 0)
|
|
@@ -119,7 +124,7 @@ CREATE INDEX IF NOT EXISTS idx_sessions_last_active ON sessions(last_active_at);
|
|
|
119
124
|
-- because sqlite-vss requires extension loading first
|
|
120
125
|
--
|
|
121
126
|
-- CREATE VIRTUAL TABLE vss_memories USING vss0(
|
|
122
|
-
-- embedding(
|
|
127
|
+
-- embedding(1024) -- multilingual-e5-large embeddings
|
|
123
128
|
-- );
|
|
124
129
|
|
|
125
130
|
-- ══════════════════════════════════════════════════════════════
|
|
@@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS error_patterns (
|
|
|
33
33
|
first_seen INTEGER NOT NULL, -- First occurrence timestamp
|
|
34
34
|
|
|
35
35
|
-- Vector Embedding (for semantic matching)
|
|
36
|
-
embedding BLOB, --
|
|
36
|
+
embedding BLOB, -- 1024-dim embedding (multilingual-e5-large)
|
|
37
37
|
|
|
38
38
|
-- Metadata
|
|
39
39
|
created_at INTEGER DEFAULT (unixepoch() * 1000),
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Add is_static column for user profile (long-term preferences vs current work)
|
|
2
|
+
ALTER TABLE decisions ADD COLUMN is_static INTEGER DEFAULT 0;
|
|
3
|
+
|
|
4
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
5
|
+
VALUES (14, 'Add is_static column for user profile preferences');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
-- FTS5 virtual table for keyword search
|
|
2
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS decisions_fts USING fts5(
|
|
3
|
+
topic, decision, reasoning,
|
|
4
|
+
content='decisions',
|
|
5
|
+
content_rowid='rowid'
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
-- Sync triggers for external content table
|
|
9
|
+
CREATE TRIGGER IF NOT EXISTS decisions_ai AFTER INSERT ON decisions BEGIN
|
|
10
|
+
INSERT INTO decisions_fts(rowid, topic, decision, reasoning)
|
|
11
|
+
VALUES (new.rowid, new.topic, new.decision, new.reasoning);
|
|
12
|
+
END;
|
|
13
|
+
|
|
14
|
+
CREATE TRIGGER IF NOT EXISTS decisions_ad BEFORE DELETE ON decisions BEGIN
|
|
15
|
+
INSERT INTO decisions_fts(decisions_fts, rowid, topic, decision, reasoning)
|
|
16
|
+
VALUES('delete', old.rowid, old.topic, old.decision, old.reasoning);
|
|
17
|
+
END;
|
|
18
|
+
|
|
19
|
+
CREATE TRIGGER IF NOT EXISTS decisions_au BEFORE UPDATE ON decisions BEGIN
|
|
20
|
+
INSERT INTO decisions_fts(decisions_fts, rowid, topic, decision, reasoning)
|
|
21
|
+
VALUES('delete', old.rowid, old.topic, old.decision, old.reasoning);
|
|
22
|
+
END;
|
|
23
|
+
|
|
24
|
+
CREATE TRIGGER IF NOT EXISTS decisions_au2 AFTER UPDATE ON decisions BEGIN
|
|
25
|
+
INSERT INTO decisions_fts(rowid, topic, decision, reasoning)
|
|
26
|
+
VALUES (new.rowid, new.topic, new.decision, new.reasoning);
|
|
27
|
+
END;
|
|
28
|
+
|
|
29
|
+
-- Backfill existing decisions into FTS index
|
|
30
|
+
INSERT INTO decisions_fts(rowid, topic, decision, reasoning)
|
|
31
|
+
SELECT rowid, topic, decision, reasoning FROM decisions;
|
|
32
|
+
|
|
33
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
34
|
+
VALUES (15, 'Add FTS5 keyword search with sync triggers');
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ALTER TABLE decisions ADD COLUMN kind TEXT DEFAULT 'decision'
|
|
2
|
+
CHECK (kind IN ('decision', 'preference', 'constraint', 'lesson', 'fact'));
|
|
3
|
+
|
|
4
|
+
ALTER TABLE decisions ADD COLUMN status TEXT DEFAULT 'active'
|
|
5
|
+
CHECK (status IN ('active', 'superseded', 'contradicted', 'stale'));
|
|
6
|
+
|
|
7
|
+
ALTER TABLE decisions ADD COLUMN summary TEXT;
|
|
8
|
+
|
|
9
|
+
UPDATE decisions
|
|
10
|
+
SET summary = decision
|
|
11
|
+
WHERE summary IS NULL;
|
|
12
|
+
|
|
13
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
14
|
+
VALUES (16, 'Add memory v2 kind/status/summary columns');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS memory_scopes (
|
|
2
|
+
id TEXT PRIMARY KEY,
|
|
3
|
+
kind TEXT NOT NULL CHECK (kind IN ('global', 'user', 'channel', 'project')),
|
|
4
|
+
external_id TEXT NOT NULL,
|
|
5
|
+
created_at INTEGER DEFAULT (unixepoch() * 1000),
|
|
6
|
+
UNIQUE(kind, external_id)
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
10
|
+
VALUES (17, 'Create memory scopes table');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS memory_scope_bindings (
|
|
2
|
+
memory_id TEXT NOT NULL,
|
|
3
|
+
scope_id TEXT NOT NULL,
|
|
4
|
+
is_primary INTEGER DEFAULT 0 CHECK (is_primary IN (0, 1)),
|
|
5
|
+
created_at INTEGER DEFAULT (unixepoch() * 1000),
|
|
6
|
+
PRIMARY KEY (memory_id, scope_id),
|
|
7
|
+
FOREIGN KEY (memory_id) REFERENCES decisions(id) ON DELETE CASCADE,
|
|
8
|
+
FOREIGN KEY (scope_id) REFERENCES memory_scopes(id) ON DELETE CASCADE
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
CREATE INDEX IF NOT EXISTS idx_memory_scope_bindings_scope_id
|
|
12
|
+
ON memory_scope_bindings(scope_id);
|
|
13
|
+
|
|
14
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
15
|
+
VALUES (18, 'Create memory scope bindings table');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS memory_events (
|
|
2
|
+
event_id TEXT PRIMARY KEY,
|
|
3
|
+
event_type TEXT NOT NULL,
|
|
4
|
+
actor TEXT NOT NULL,
|
|
5
|
+
source_turn_id TEXT,
|
|
6
|
+
memory_id TEXT,
|
|
7
|
+
topic TEXT,
|
|
8
|
+
scope_refs TEXT NOT NULL,
|
|
9
|
+
evidence_refs TEXT,
|
|
10
|
+
reason TEXT,
|
|
11
|
+
created_at INTEGER NOT NULL
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_memory_events_topic_created_at
|
|
15
|
+
ON memory_events(topic, created_at DESC);
|
|
16
|
+
|
|
17
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
18
|
+
VALUES (19, 'Create memory events table');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS audit_findings (
|
|
2
|
+
finding_id TEXT PRIMARY KEY,
|
|
3
|
+
kind TEXT NOT NULL,
|
|
4
|
+
severity TEXT NOT NULL,
|
|
5
|
+
summary TEXT NOT NULL,
|
|
6
|
+
evidence_refs TEXT NOT NULL,
|
|
7
|
+
affected_memory_ids TEXT NOT NULL,
|
|
8
|
+
recommended_action TEXT NOT NULL,
|
|
9
|
+
status TEXT NOT NULL DEFAULT 'open',
|
|
10
|
+
created_at INTEGER NOT NULL,
|
|
11
|
+
resolved_at INTEGER
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
CREATE INDEX IF NOT EXISTS idx_audit_findings_status_created_at
|
|
15
|
+
ON audit_findings(status, created_at DESC);
|
|
16
|
+
|
|
17
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
18
|
+
VALUES (20, 'Create audit findings table');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS memory_truth (
|
|
2
|
+
memory_id TEXT PRIMARY KEY,
|
|
3
|
+
topic TEXT NOT NULL,
|
|
4
|
+
truth_status TEXT NOT NULL,
|
|
5
|
+
effective_summary TEXT NOT NULL,
|
|
6
|
+
effective_details TEXT NOT NULL,
|
|
7
|
+
trust_score REAL NOT NULL,
|
|
8
|
+
scope_refs TEXT NOT NULL,
|
|
9
|
+
supporting_event_ids TEXT NOT NULL,
|
|
10
|
+
superseded_by TEXT,
|
|
11
|
+
contradicted_by TEXT,
|
|
12
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
13
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE INDEX IF NOT EXISTS idx_memory_truth_topic_updated_at
|
|
17
|
+
ON memory_truth(topic, updated_at DESC);
|
|
18
|
+
|
|
19
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
20
|
+
VALUES (21, 'Create memory truth projection table');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS channel_summaries (
|
|
2
|
+
channel_key TEXT PRIMARY KEY,
|
|
3
|
+
summary_markdown TEXT NOT NULL,
|
|
4
|
+
delta_hash TEXT,
|
|
5
|
+
updated_at INTEGER NOT NULL
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
9
|
+
VALUES (22, 'Create channel summaries table');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CREATE TABLE IF NOT EXISTS channel_summary_state (
|
|
2
|
+
channel_key TEXT PRIMARY KEY,
|
|
3
|
+
state_json TEXT NOT NULL,
|
|
4
|
+
state_hash TEXT NOT NULL,
|
|
5
|
+
updated_at INTEGER NOT NULL
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
9
|
+
VALUES (23, 'Create channel summary state table');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Migration 024: Add event_date column to decisions table
|
|
2
|
+
-- event_date stores the ISO 8601 date when the event actually occurred
|
|
3
|
+
-- (distinct from created_at which is ingestion time)
|
|
4
|
+
ALTER TABLE decisions ADD COLUMN event_date TEXT;
|
|
5
|
+
|
|
6
|
+
CREATE INDEX IF NOT EXISTS idx_decisions_event_date ON decisions(event_date);
|
|
7
|
+
|
|
8
|
+
INSERT OR IGNORE INTO schema_version (version, description)
|
|
9
|
+
VALUES (24, 'Add event_date column for temporal tracking');
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
-- v0.17: Extend kind CHECK constraint to include 'task' and 'schedule'.
|
|
2
|
+
-- Only runs if the old CHECK exists (idempotent).
|
|
3
|
+
-- Uses a temp table approach since SQLite cannot ALTER CHECK constraints.
|
|
4
|
+
|
|
5
|
+
-- Drop the old column constraint by recreating the table
|
|
6
|
+
-- This is safe because we explicitly list all columns
|
|
7
|
+
|
|
8
|
+
CREATE TABLE IF NOT EXISTS decisions_v17 (
|
|
9
|
+
id TEXT PRIMARY KEY,
|
|
10
|
+
topic TEXT NOT NULL,
|
|
11
|
+
decision TEXT NOT NULL,
|
|
12
|
+
reasoning TEXT,
|
|
13
|
+
outcome TEXT,
|
|
14
|
+
failure_reason TEXT,
|
|
15
|
+
limitation TEXT,
|
|
16
|
+
user_involvement TEXT,
|
|
17
|
+
session_id TEXT,
|
|
18
|
+
supersedes TEXT,
|
|
19
|
+
superseded_by TEXT,
|
|
20
|
+
refined_from TEXT,
|
|
21
|
+
confidence REAL DEFAULT 0.5 CHECK (confidence >= 0.0 AND confidence <= 1.0),
|
|
22
|
+
created_at INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000),
|
|
23
|
+
updated_at INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000),
|
|
24
|
+
needs_validation INTEGER DEFAULT 0 CHECK (needs_validation IN (0, 1)),
|
|
25
|
+
validation_attempts INTEGER DEFAULT 0,
|
|
26
|
+
last_validated_at INTEGER,
|
|
27
|
+
usage_count INTEGER DEFAULT 0,
|
|
28
|
+
trust_context TEXT,
|
|
29
|
+
usage_success INTEGER DEFAULT 0,
|
|
30
|
+
usage_failure INTEGER DEFAULT 0,
|
|
31
|
+
time_saved INTEGER DEFAULT 0,
|
|
32
|
+
evidence TEXT,
|
|
33
|
+
alternatives TEXT,
|
|
34
|
+
risks TEXT,
|
|
35
|
+
event_date TEXT,
|
|
36
|
+
kind TEXT DEFAULT 'decision'
|
|
37
|
+
CHECK (kind IN ('decision', 'preference', 'constraint', 'lesson', 'fact', 'task', 'schedule')),
|
|
38
|
+
status TEXT DEFAULT 'active'
|
|
39
|
+
CHECK (status IN ('active', 'superseded', 'contradicted', 'stale')),
|
|
40
|
+
summary TEXT,
|
|
41
|
+
is_static INTEGER DEFAULT 0
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
INSERT OR IGNORE INTO decisions_v17 (
|
|
45
|
+
id, topic, decision, reasoning, outcome, failure_reason, limitation,
|
|
46
|
+
user_involvement, session_id, supersedes, superseded_by, refined_from,
|
|
47
|
+
confidence, created_at, updated_at, needs_validation, validation_attempts,
|
|
48
|
+
last_validated_at, usage_count, trust_context, usage_success, usage_failure,
|
|
49
|
+
time_saved, evidence, alternatives, risks, event_date, kind, status, summary, is_static
|
|
50
|
+
) SELECT
|
|
51
|
+
id, topic, decision, reasoning, outcome, failure_reason, limitation,
|
|
52
|
+
user_involvement, session_id, supersedes, superseded_by, refined_from,
|
|
53
|
+
confidence, created_at, updated_at, needs_validation, validation_attempts,
|
|
54
|
+
last_validated_at, usage_count, trust_context, usage_success, usage_failure,
|
|
55
|
+
time_saved, evidence, alternatives, risks, event_date, kind, status, summary, is_static
|
|
56
|
+
FROM decisions;
|
|
57
|
+
|
|
58
|
+
DROP TABLE decisions;
|
|
59
|
+
ALTER TABLE decisions_v17 RENAME TO decisions;
|
package/dist/config-loader.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Loads user configuration from ~/.mama/config.json with sensible defaults.
|
|
8
8
|
* Supports:
|
|
9
|
-
* - Model selection (default: multilingual-e5-
|
|
9
|
+
* - Model selection (default: multilingual-e5-large)
|
|
10
10
|
* - Embedding dimensions
|
|
11
11
|
* - Cache directory configuration
|
|
12
12
|
*
|
package/dist/config-loader.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Loads user configuration from ~/.mama/config.json with sensible defaults.
|
|
9
9
|
* Supports:
|
|
10
|
-
* - Model selection (default: multilingual-e5-
|
|
10
|
+
* - Model selection (default: multilingual-e5-large)
|
|
11
11
|
* - Embedding dimensions
|
|
12
12
|
* - Cache directory configuration
|
|
13
13
|
*
|
|
@@ -31,8 +31,8 @@ const os_1 = __importDefault(require("os"));
|
|
|
31
31
|
const debug_logger_js_1 = require("./debug-logger.js");
|
|
32
32
|
// Default configuration
|
|
33
33
|
exports.DEFAULT_CONFIG = {
|
|
34
|
-
modelName: 'Xenova/multilingual-e5-
|
|
35
|
-
embeddingDim:
|
|
34
|
+
modelName: 'Xenova/multilingual-e5-large',
|
|
35
|
+
embeddingDim: 1024,
|
|
36
36
|
quantized: true,
|
|
37
37
|
cacheDir: path_1.default.join(os_1.default.homedir(), '.cache', 'huggingface', 'transformers'),
|
|
38
38
|
};
|
|
@@ -43,11 +43,11 @@ export declare abstract class DatabaseAdapter {
|
|
|
43
43
|
abstract transaction<T>(fn: () => T): T;
|
|
44
44
|
/**
|
|
45
45
|
* Vector similarity search
|
|
46
|
-
* @param embedding - Query embedding (
|
|
46
|
+
* @param embedding - Query embedding (1024-dim)
|
|
47
47
|
* @param limit - Max results
|
|
48
48
|
* @returns Search results with distance
|
|
49
49
|
*/
|
|
50
|
-
abstract vectorSearch(embedding: Float32Array | number[], limit: number): VectorSearchResult[] | null;
|
|
50
|
+
abstract vectorSearch(embedding: Float32Array | number[], limit: number, topicPrefix?: string): VectorSearchResult[] | null;
|
|
51
51
|
/**
|
|
52
52
|
* Insert vector embedding
|
|
53
53
|
* @param rowid - Decision rowid
|
package/dist/db-adapter/index.js
CHANGED
|
@@ -24,14 +24,8 @@ Object.defineProperty(exports, "DatabaseAdapter", { enumerable: true, get: funct
|
|
|
24
24
|
* @returns Configured SQLite adapter instance
|
|
25
25
|
*/
|
|
26
26
|
function createAdapter(config = {}) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
configuredDriver !== 'node-sqlite' &&
|
|
30
|
-
configuredDriver !== 'node:sqlite' &&
|
|
31
|
-
configuredDriver !== 'auto') {
|
|
32
|
-
throw new Error(`Unsupported SQLite driver "${configuredDriver}". MAMA now requires node:sqlite.`);
|
|
33
|
-
}
|
|
34
|
-
(0, debug_logger_js_1.info)('[db-adapter] Using node:sqlite adapter');
|
|
27
|
+
// SQLiteAdapter (extends NodeSQLiteAdapter) auto-detects: better-sqlite3 (preferred, FTS5) → node:sqlite (fallback)
|
|
28
|
+
(0, debug_logger_js_1.info)('[db-adapter] Creating SQLite adapter (auto-detect driver)');
|
|
35
29
|
const dbPath = config.dbPath || process.env.MAMA_DB_PATH;
|
|
36
30
|
return new sqlite_adapter_js_1.SQLiteAdapter({ dbPath });
|
|
37
31
|
}
|
|
@@ -24,6 +24,7 @@ interface NodeSQLiteStatementLike {
|
|
|
24
24
|
declare class NodeSQLiteConnection {
|
|
25
25
|
private db;
|
|
26
26
|
private connected;
|
|
27
|
+
private isBetterSQLite3;
|
|
27
28
|
constructor(db: NodeSQLiteDatabaseLike);
|
|
28
29
|
prepare(sql: string): NodeSQLiteStatementLike;
|
|
29
30
|
exec(sql: string): void;
|
|
@@ -37,16 +38,20 @@ export declare class NodeSQLiteAdapter extends DatabaseAdapter {
|
|
|
37
38
|
private config;
|
|
38
39
|
private db;
|
|
39
40
|
private _vectorSearchEnabled;
|
|
41
|
+
private vectorCache;
|
|
42
|
+
private topicCache;
|
|
40
43
|
constructor(config?: SQLiteAdapterConfig);
|
|
41
44
|
get vectorSearchEnabled(): boolean;
|
|
42
45
|
getDbPath(): string;
|
|
43
46
|
connect(): NodeSQLiteConnection;
|
|
47
|
+
reloadVectorCache(): void;
|
|
48
|
+
private loadVectorCache;
|
|
44
49
|
disconnect(): void;
|
|
45
50
|
isConnected(): boolean;
|
|
46
51
|
prepare(sql: string): Statement;
|
|
47
52
|
exec(sql: string): void;
|
|
48
53
|
transaction<T>(fn: () => T): T;
|
|
49
|
-
vectorSearch(embedding: Float32Array | number[], limit?: number): VectorSearchResult[] | null;
|
|
54
|
+
vectorSearch(embedding: Float32Array | number[], limit?: number, topicPrefix?: string): VectorSearchResult[] | null;
|
|
50
55
|
insertEmbedding(rowid: number, embedding: Float32Array | number[]): RunResult | null;
|
|
51
56
|
getLastInsertRowid(): number;
|
|
52
57
|
runMigrations(migrationsDir: string): void;
|