@jungjaehoon/mama-core 1.1.1 → 1.1.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.
- package/dist/config-loader.d.ts +61 -0
- package/dist/config-loader.js +187 -0
- package/dist/db-adapter/base-adapter.d.ts +76 -0
- package/dist/db-adapter/base-adapter.js +11 -0
- package/dist/db-adapter/index.d.ts +24 -0
- package/dist/db-adapter/index.js +29 -0
- package/dist/db-adapter/sqlite-adapter.d.ts +73 -0
- package/dist/db-adapter/sqlite-adapter.js +330 -0
- package/dist/db-adapter/statement.d.ts +119 -0
- package/dist/db-adapter/statement.js +113 -0
- package/dist/db-manager.d.ts +252 -0
- package/dist/db-manager.js +622 -0
- package/dist/debug-logger.d.ts +32 -0
- package/dist/debug-logger.js +83 -0
- package/dist/decision-formatter.d.ts +172 -0
- package/dist/decision-formatter.js +894 -0
- package/dist/decision-tracker.d.ts +218 -0
- package/dist/decision-tracker.js +531 -0
- package/dist/embedding-cache.d.ts +83 -0
- package/dist/embedding-cache.js +182 -0
- package/dist/embedding-client.d.ts +43 -0
- package/dist/embedding-client.js +132 -0
- package/dist/embedding-server/index.d.ts +65 -0
- package/dist/embedding-server/index.js +397 -0
- package/dist/embedding-server/mobile/auth.d.ts +53 -0
- package/dist/embedding-server/mobile/auth.js +140 -0
- package/dist/embedding-server/mobile/daemon.d.ts +128 -0
- package/dist/embedding-server/mobile/daemon.js +303 -0
- package/dist/embedding-server/mobile/output-parser.d.ts +115 -0
- package/dist/embedding-server/mobile/output-parser.js +241 -0
- package/dist/embedding-server/mobile/session-api.d.ts +57 -0
- package/dist/embedding-server/mobile/session-api.js +261 -0
- package/dist/embedding-server/mobile/session-manager.d.ts +135 -0
- package/dist/embedding-server/mobile/session-manager.js +333 -0
- package/dist/embedding-server/mobile/websocket-handler.d.ts +127 -0
- package/dist/embedding-server/mobile/websocket-handler.js +435 -0
- package/dist/embeddings.d.ts +75 -0
- package/dist/embeddings.js +262 -0
- package/dist/errors.d.ts +131 -0
- package/dist/errors.js +225 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +193 -0
- package/dist/mama-api.d.ts +954 -0
- package/dist/mama-api.js +2210 -0
- package/dist/memory-inject.d.ts +24 -0
- package/dist/memory-inject.js +116 -0
- package/dist/memory-store.d.ts +103 -0
- package/dist/memory-store.js +129 -0
- package/dist/notification-manager.d.ts +7 -0
- package/dist/notification-manager.js +12 -0
- package/dist/ollama-client.d.ts +51 -0
- package/dist/ollama-client.js +308 -0
- package/dist/outcome-tracker.d.ts +165 -0
- package/dist/outcome-tracker.js +315 -0
- package/dist/progress-indicator.d.ts +48 -0
- package/dist/progress-indicator.js +82 -0
- package/dist/query-intent.d.ts +27 -0
- package/dist/query-intent.js +144 -0
- package/dist/relevance-scorer.d.ts +124 -0
- package/dist/relevance-scorer.js +243 -0
- package/dist/test-utils.d.ts +66 -0
- package/dist/test-utils.js +166 -0
- package/dist/tier-validator.d.ts +55 -0
- package/dist/tier-validator.js +216 -0
- package/dist/time-formatter.d.ts +25 -0
- package/dist/time-formatter.js +93 -0
- package/package.json +3 -2
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MAMA Database Manager (SQLite-only)
|
|
3
|
+
*
|
|
4
|
+
* SQLite-exclusive database interface for MAMA Plugin.
|
|
5
|
+
* Uses better-sqlite3 + sqlite-vec for local storage.
|
|
6
|
+
*
|
|
7
|
+
* PostgreSQL support is only available in the legacy mcp-server repository.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - WAL mode for better concurrency
|
|
11
|
+
* - synchronous=NORMAL for performance
|
|
12
|
+
* - Automatic migration management
|
|
13
|
+
* - Vector similarity search (when sqlite-vec available)
|
|
14
|
+
*
|
|
15
|
+
* @module db-manager
|
|
16
|
+
* @version 2.1 (Plugin - SQLite-only)
|
|
17
|
+
* @date 2026-02-01
|
|
18
|
+
* @source-of-truth packages/mama-core/src/db-manager.js (mama-core)
|
|
19
|
+
*/
|
|
20
|
+
import type { PreparedStatement } from './db-adapter/statement.js';
|
|
21
|
+
export type { PreparedStatement };
|
|
22
|
+
export interface DatabaseAdapter {
|
|
23
|
+
connect: () => unknown;
|
|
24
|
+
disconnect: () => void;
|
|
25
|
+
runMigrations: (dir: string) => void;
|
|
26
|
+
prepare: (sql: string) => PreparedStatement;
|
|
27
|
+
transaction: <T>(fn: () => T) => T;
|
|
28
|
+
insertEmbedding: (rowid: number, embedding: Float32Array | number[]) => void;
|
|
29
|
+
vectorSearch: (embedding: Float32Array | number[], limit: number) => Promise<VectorSearchResult[] | null>;
|
|
30
|
+
vectorSearchEnabled: boolean;
|
|
31
|
+
getDbPath?: () => string;
|
|
32
|
+
dbPath?: string;
|
|
33
|
+
constructor: {
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface VectorSearchResult {
|
|
38
|
+
rowid: number;
|
|
39
|
+
similarity?: number;
|
|
40
|
+
distance?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface DecisionRecord {
|
|
43
|
+
id: string;
|
|
44
|
+
topic: string;
|
|
45
|
+
decision: string;
|
|
46
|
+
reasoning?: string | null;
|
|
47
|
+
outcome?: string | null;
|
|
48
|
+
failure_reason?: string | null;
|
|
49
|
+
limitation?: string | null;
|
|
50
|
+
confidence?: number;
|
|
51
|
+
supersedes?: string | null;
|
|
52
|
+
superseded_by?: string | null;
|
|
53
|
+
refined_from?: string | string[] | null;
|
|
54
|
+
created_at: number;
|
|
55
|
+
updated_at?: number;
|
|
56
|
+
edges?: unknown[];
|
|
57
|
+
}
|
|
58
|
+
export interface OutcomeData {
|
|
59
|
+
outcome?: string | null;
|
|
60
|
+
failure_reason?: string | null;
|
|
61
|
+
limitation?: string | null;
|
|
62
|
+
duration_days?: number | null;
|
|
63
|
+
confidence?: number | null;
|
|
64
|
+
}
|
|
65
|
+
export interface VectorSearchParams {
|
|
66
|
+
query: string;
|
|
67
|
+
limit?: number;
|
|
68
|
+
threshold?: number;
|
|
69
|
+
timeWindow?: number;
|
|
70
|
+
}
|
|
71
|
+
export interface SemanticEdges {
|
|
72
|
+
refines: unknown[];
|
|
73
|
+
refined_by: unknown[];
|
|
74
|
+
contradicts: unknown[];
|
|
75
|
+
contradicted_by: unknown[];
|
|
76
|
+
builds_on: unknown[];
|
|
77
|
+
built_on_by: unknown[];
|
|
78
|
+
debates: unknown[];
|
|
79
|
+
debated_by: unknown[];
|
|
80
|
+
synthesizes: unknown[];
|
|
81
|
+
synthesized_by: unknown[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Initialize SQLite database adapter and connect
|
|
85
|
+
*
|
|
86
|
+
* Lazy initialization: Only connects when first accessed
|
|
87
|
+
* Creates database file at ~/.claude/mama-memory.db by default
|
|
88
|
+
*
|
|
89
|
+
* Single-flight guard: Concurrent callers await the same promise
|
|
90
|
+
* to prevent multiple adapters/migrations running simultaneously.
|
|
91
|
+
*
|
|
92
|
+
* @returns SQLite database connection
|
|
93
|
+
*/
|
|
94
|
+
export declare function initDB(): Promise<unknown>;
|
|
95
|
+
/**
|
|
96
|
+
* Get database connection (singleton pattern)
|
|
97
|
+
*
|
|
98
|
+
* Returns better-sqlite3 Database instance
|
|
99
|
+
*
|
|
100
|
+
* Note: Synchronous for backward compatibility with memory-store.js
|
|
101
|
+
* Will throw if database not initialized
|
|
102
|
+
*
|
|
103
|
+
* @returns SQLite database connection
|
|
104
|
+
*/
|
|
105
|
+
export declare function getDB(): unknown;
|
|
106
|
+
/**
|
|
107
|
+
* Get database adapter instance
|
|
108
|
+
*
|
|
109
|
+
* Used for advanced operations (vectorSearch, insertEmbedding, etc.)
|
|
110
|
+
*
|
|
111
|
+
* @returns Adapter instance
|
|
112
|
+
*/
|
|
113
|
+
export declare function getAdapter(): DatabaseAdapter;
|
|
114
|
+
/**
|
|
115
|
+
* Close database connection
|
|
116
|
+
*
|
|
117
|
+
* Call this on process exit
|
|
118
|
+
*/
|
|
119
|
+
export declare function closeDB(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Insert embedding into vector search table
|
|
122
|
+
*
|
|
123
|
+
* Uses sqlite-vec for vector similarity search
|
|
124
|
+
* Gracefully degrades if sqlite-vec is not available
|
|
125
|
+
*
|
|
126
|
+
* @param decisionRowid - SQLite rowid
|
|
127
|
+
* @param embedding - 384-dim embedding vector
|
|
128
|
+
*/
|
|
129
|
+
export declare function insertEmbedding(decisionRowid: number, embedding: Float32Array | number[]): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Perform vector similarity search
|
|
132
|
+
*
|
|
133
|
+
* Returns empty array if vector search not available (no keyword fallback)
|
|
134
|
+
*
|
|
135
|
+
* @param queryEmbedding - Query embedding (384-dim)
|
|
136
|
+
* @param limit - Max results to return (default: 5)
|
|
137
|
+
* @param threshold - Minimum similarity threshold (default: 0.7)
|
|
138
|
+
* @returns Array of decisions with similarity scores, or empty array
|
|
139
|
+
*/
|
|
140
|
+
export declare function vectorSearch(queryEmbedding: Float32Array | number[], limit?: number, threshold?: number): Promise<DecisionRecord[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Decision input for storage
|
|
143
|
+
*/
|
|
144
|
+
export interface DecisionInput {
|
|
145
|
+
id: string;
|
|
146
|
+
topic: string;
|
|
147
|
+
decision: string;
|
|
148
|
+
reasoning?: string | null;
|
|
149
|
+
outcome?: string | null;
|
|
150
|
+
failure_reason?: string | null;
|
|
151
|
+
limitation?: string | null;
|
|
152
|
+
user_involvement?: string | null;
|
|
153
|
+
session_id?: string | null;
|
|
154
|
+
supersedes?: string | null;
|
|
155
|
+
superseded_by?: string | null;
|
|
156
|
+
refined_from?: string[] | null;
|
|
157
|
+
confidence?: number;
|
|
158
|
+
created_at?: number;
|
|
159
|
+
updated_at?: number;
|
|
160
|
+
needs_validation?: number;
|
|
161
|
+
validation_attempts?: number;
|
|
162
|
+
last_validated_at?: number | null;
|
|
163
|
+
usage_count?: number;
|
|
164
|
+
trust_context?: string | null;
|
|
165
|
+
usage_success?: number;
|
|
166
|
+
usage_failure?: number;
|
|
167
|
+
time_saved?: number;
|
|
168
|
+
evidence?: string | null;
|
|
169
|
+
alternatives?: string | null;
|
|
170
|
+
risks?: string | null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Insert decision with embedding
|
|
174
|
+
*
|
|
175
|
+
* Combined operation: Insert decision + Generate embedding + Insert embedding
|
|
176
|
+
* SQLite-only implementation
|
|
177
|
+
*
|
|
178
|
+
* @param decision - Decision object
|
|
179
|
+
* @returns Decision ID
|
|
180
|
+
*/
|
|
181
|
+
export declare function insertDecisionWithEmbedding(decision: DecisionInput): Promise<string>;
|
|
182
|
+
/**
|
|
183
|
+
* Query decision graph for topic
|
|
184
|
+
*
|
|
185
|
+
* Recursive CTE to traverse supersedes chain
|
|
186
|
+
* SQLite implementation using WITH RECURSIVE
|
|
187
|
+
*
|
|
188
|
+
* @param topic - Decision topic to query
|
|
189
|
+
* @returns Array of decisions (ordered by recency)
|
|
190
|
+
*/
|
|
191
|
+
export declare function queryDecisionGraph(topic: string): Promise<DecisionRecord[]>;
|
|
192
|
+
/**
|
|
193
|
+
* Query semantic edges for a list of decisions
|
|
194
|
+
*
|
|
195
|
+
* Returns both outgoing (from_id) and incoming (to_id) edges
|
|
196
|
+
* for refines and contradicts relationships
|
|
197
|
+
*
|
|
198
|
+
* @param decisionIds - Decision IDs to query edges for
|
|
199
|
+
* @returns Categorized edges
|
|
200
|
+
*/
|
|
201
|
+
export declare function querySemanticEdges(decisionIds: string[]): Promise<SemanticEdges>;
|
|
202
|
+
/**
|
|
203
|
+
* Query vector search with time window and threshold
|
|
204
|
+
*
|
|
205
|
+
* Story 014.14: AC #1 - Vector Search for Related Decisions
|
|
206
|
+
*
|
|
207
|
+
* @param params - Search parameters
|
|
208
|
+
* @returns Results with similarity scores and decision data
|
|
209
|
+
*/
|
|
210
|
+
export declare function queryVectorSearch(params: VectorSearchParams): Promise<DecisionRecord[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Update decision outcome
|
|
213
|
+
*
|
|
214
|
+
* @param decisionId - Decision ID
|
|
215
|
+
* @param outcomeData - Outcome data
|
|
216
|
+
*/
|
|
217
|
+
export declare function updateDecisionOutcome(decisionId: string, outcomeData: OutcomeData): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Get prepared statement
|
|
220
|
+
*
|
|
221
|
+
* For backward compatibility with memory-store.js
|
|
222
|
+
* Returns a compatibility shim that proxies to adapter.prepare()
|
|
223
|
+
*
|
|
224
|
+
* @param sql - SQL statement
|
|
225
|
+
* @returns Statement-like object with run/get/all methods
|
|
226
|
+
*/
|
|
227
|
+
export declare function getPreparedStmt(sql: string): PreparedStatement;
|
|
228
|
+
/**
|
|
229
|
+
* Get database file path
|
|
230
|
+
*
|
|
231
|
+
* @returns Actual database path or 'Not initialized'
|
|
232
|
+
*/
|
|
233
|
+
export declare function getDbPath(): string;
|
|
234
|
+
/**
|
|
235
|
+
* Reset database state for testing
|
|
236
|
+
*
|
|
237
|
+
* Resets internal state without closing connection.
|
|
238
|
+
* Use this in test teardown to allow re-initialization with different DB path.
|
|
239
|
+
*
|
|
240
|
+
* @param options - Reset options
|
|
241
|
+
* @param options.disconnect - If true, also disconnect adapter (default: true)
|
|
242
|
+
*/
|
|
243
|
+
export declare function resetDBState(options?: {
|
|
244
|
+
disconnect?: boolean;
|
|
245
|
+
}): void;
|
|
246
|
+
/**
|
|
247
|
+
* Check if running in test mode
|
|
248
|
+
*
|
|
249
|
+
* Returns true if MAMA_TEST_MODE or VITEST env vars are set
|
|
250
|
+
*/
|
|
251
|
+
export declare function isTestMode(): boolean;
|
|
252
|
+
//# sourceMappingURL=db-manager.d.ts.map
|