@velvetmonkey/vault-core 2.0.136 → 2.0.138

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/schema.js ADDED
@@ -0,0 +1,451 @@
1
+ /**
2
+ * SQLite Schema Constants
3
+ *
4
+ * Contains the schema version, file path constants, and full SQL schema
5
+ * for the flywheel state database.
6
+ */
7
+ // =============================================================================
8
+ // Constants
9
+ // =============================================================================
10
+ /** Current schema version - bump when schema changes */
11
+ export const SCHEMA_VERSION = 31;
12
+ /** State database filename */
13
+ export const STATE_DB_FILENAME = 'state.db';
14
+ /** Directory for flywheel state */
15
+ export const FLYWHEEL_DIR = '.flywheel';
16
+ // =============================================================================
17
+ // Schema
18
+ // =============================================================================
19
+ export const SCHEMA_SQL = `
20
+ -- Schema version tracking
21
+ CREATE TABLE IF NOT EXISTS schema_version (
22
+ version INTEGER PRIMARY KEY,
23
+ applied_at TEXT DEFAULT (datetime('now'))
24
+ );
25
+
26
+ -- Metadata key-value store
27
+ CREATE TABLE IF NOT EXISTS metadata (
28
+ key TEXT PRIMARY KEY,
29
+ value TEXT NOT NULL,
30
+ updated_at TEXT DEFAULT (datetime('now'))
31
+ );
32
+
33
+ -- Entity index (replaces wikilink-entities.json)
34
+ CREATE TABLE IF NOT EXISTS entities (
35
+ id INTEGER PRIMARY KEY,
36
+ name TEXT NOT NULL,
37
+ name_lower TEXT NOT NULL,
38
+ path TEXT NOT NULL,
39
+ category TEXT NOT NULL,
40
+ aliases_json TEXT,
41
+ hub_score INTEGER DEFAULT 0,
42
+ description TEXT
43
+ );
44
+ CREATE INDEX IF NOT EXISTS idx_entities_name_lower ON entities(name_lower);
45
+ CREATE INDEX IF NOT EXISTS idx_entities_category ON entities(category);
46
+
47
+ -- FTS5 for entity search with porter stemmer
48
+ CREATE VIRTUAL TABLE IF NOT EXISTS entities_fts USING fts5(
49
+ name, aliases, category,
50
+ content='entities', content_rowid='id',
51
+ tokenize='porter unicode61'
52
+ );
53
+
54
+ -- Auto-sync triggers for entities_fts
55
+ CREATE TRIGGER IF NOT EXISTS entities_ai AFTER INSERT ON entities BEGIN
56
+ INSERT INTO entities_fts(rowid, name, aliases, category)
57
+ VALUES (
58
+ new.id,
59
+ new.name,
60
+ COALESCE((SELECT group_concat(value, ' ') FROM json_each(new.aliases_json)), ''),
61
+ new.category
62
+ );
63
+ END;
64
+
65
+ CREATE TRIGGER IF NOT EXISTS entities_ad AFTER DELETE ON entities BEGIN
66
+ INSERT INTO entities_fts(entities_fts, rowid, name, aliases, category)
67
+ VALUES (
68
+ 'delete',
69
+ old.id,
70
+ old.name,
71
+ COALESCE((SELECT group_concat(value, ' ') FROM json_each(old.aliases_json)), ''),
72
+ old.category
73
+ );
74
+ END;
75
+
76
+ CREATE TRIGGER IF NOT EXISTS entities_au AFTER UPDATE ON entities BEGIN
77
+ INSERT INTO entities_fts(entities_fts, rowid, name, aliases, category)
78
+ VALUES (
79
+ 'delete',
80
+ old.id,
81
+ old.name,
82
+ COALESCE((SELECT group_concat(value, ' ') FROM json_each(old.aliases_json)), ''),
83
+ old.category
84
+ );
85
+ INSERT INTO entities_fts(rowid, name, aliases, category)
86
+ VALUES (
87
+ new.id,
88
+ new.name,
89
+ COALESCE((SELECT group_concat(value, ' ') FROM json_each(new.aliases_json)), ''),
90
+ new.category
91
+ );
92
+ END;
93
+
94
+ -- Recency tracking (replaces entity-recency.json)
95
+ CREATE TABLE IF NOT EXISTS recency (
96
+ entity_name_lower TEXT PRIMARY KEY,
97
+ last_mentioned_at INTEGER NOT NULL,
98
+ mention_count INTEGER DEFAULT 1
99
+ );
100
+
101
+ -- Write state (replaces last-commit.json and other write state)
102
+ CREATE TABLE IF NOT EXISTS write_state (
103
+ key TEXT PRIMARY KEY,
104
+ value TEXT NOT NULL,
105
+ updated_at TEXT DEFAULT (datetime('now'))
106
+ );
107
+
108
+ -- Content search FTS5 (migrated from vault-search.db)
109
+ -- v11: Added frontmatter column for weighted search (path, title, frontmatter, content)
110
+ CREATE VIRTUAL TABLE IF NOT EXISTS notes_fts USING fts5(
111
+ path, title, frontmatter, content,
112
+ tokenize='porter'
113
+ );
114
+
115
+ -- FTS5 build metadata (consolidated from vault-search.db)
116
+ CREATE TABLE IF NOT EXISTS fts_metadata (
117
+ key TEXT PRIMARY KEY,
118
+ value TEXT
119
+ );
120
+
121
+ -- Vault index cache (for fast startup)
122
+ -- Stores serialized VaultIndex to avoid full rebuild on startup
123
+ CREATE TABLE IF NOT EXISTS vault_index_cache (
124
+ id INTEGER PRIMARY KEY CHECK (id = 1),
125
+ data BLOB NOT NULL,
126
+ built_at INTEGER NOT NULL,
127
+ note_count INTEGER NOT NULL,
128
+ version INTEGER DEFAULT 1
129
+ );
130
+
131
+ -- Flywheel configuration (replaces .flywheel.json)
132
+ CREATE TABLE IF NOT EXISTS flywheel_config (
133
+ key TEXT PRIMARY KEY,
134
+ value TEXT NOT NULL,
135
+ updated_at TEXT DEFAULT (datetime('now'))
136
+ );
137
+
138
+ -- Vault metrics (v4: growth tracking)
139
+ CREATE TABLE IF NOT EXISTS vault_metrics (
140
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
141
+ timestamp INTEGER NOT NULL,
142
+ metric TEXT NOT NULL,
143
+ value REAL NOT NULL
144
+ );
145
+ CREATE INDEX IF NOT EXISTS idx_vault_metrics_ts ON vault_metrics(timestamp);
146
+ CREATE INDEX IF NOT EXISTS idx_vault_metrics_m ON vault_metrics(metric, timestamp);
147
+
148
+ -- Wikilink feedback (v4: quality tracking)
149
+ CREATE TABLE IF NOT EXISTS wikilink_feedback (
150
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
151
+ entity TEXT NOT NULL,
152
+ context TEXT NOT NULL,
153
+ note_path TEXT NOT NULL,
154
+ correct INTEGER NOT NULL,
155
+ confidence REAL NOT NULL DEFAULT 1.0,
156
+ created_at TEXT DEFAULT (datetime('now'))
157
+ );
158
+ CREATE INDEX IF NOT EXISTS idx_wl_feedback_entity ON wikilink_feedback(entity);
159
+ CREATE INDEX IF NOT EXISTS idx_wl_feedback_note_path ON wikilink_feedback(note_path);
160
+
161
+ -- Wikilink suppressions (v4: auto-suppress false positives)
162
+ CREATE TABLE IF NOT EXISTS wikilink_suppressions (
163
+ entity TEXT PRIMARY KEY,
164
+ false_positive_rate REAL NOT NULL,
165
+ updated_at TEXT DEFAULT (datetime('now'))
166
+ );
167
+
168
+ -- Wikilink applications tracking (v5: implicit feedback)
169
+ CREATE TABLE IF NOT EXISTS wikilink_applications (
170
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
171
+ entity TEXT NOT NULL,
172
+ note_path TEXT NOT NULL,
173
+ applied_at TEXT DEFAULT (datetime('now')),
174
+ status TEXT DEFAULT 'applied'
175
+ );
176
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_wl_apps_unique ON wikilink_applications(entity COLLATE NOCASE, note_path);
177
+
178
+ -- Index events tracking (v6: index activity history)
179
+ CREATE TABLE IF NOT EXISTS index_events (
180
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
181
+ timestamp INTEGER NOT NULL,
182
+ trigger TEXT NOT NULL,
183
+ duration_ms INTEGER NOT NULL,
184
+ success INTEGER NOT NULL DEFAULT 1,
185
+ note_count INTEGER,
186
+ files_changed INTEGER,
187
+ changed_paths TEXT,
188
+ error TEXT,
189
+ steps TEXT
190
+ );
191
+ CREATE INDEX IF NOT EXISTS idx_index_events_ts ON index_events(timestamp);
192
+
193
+ -- Tool invocation tracking (v7: usage analytics)
194
+ CREATE TABLE IF NOT EXISTS tool_invocations (
195
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
196
+ timestamp INTEGER NOT NULL,
197
+ tool_name TEXT NOT NULL,
198
+ session_id TEXT,
199
+ note_paths TEXT,
200
+ duration_ms INTEGER,
201
+ success INTEGER NOT NULL DEFAULT 1,
202
+ response_tokens INTEGER,
203
+ baseline_tokens INTEGER
204
+ );
205
+ CREATE INDEX IF NOT EXISTS idx_tool_inv_ts ON tool_invocations(timestamp);
206
+ CREATE INDEX IF NOT EXISTS idx_tool_inv_tool ON tool_invocations(tool_name, timestamp);
207
+ CREATE INDEX IF NOT EXISTS idx_tool_inv_session ON tool_invocations(session_id, timestamp);
208
+
209
+ -- Graph topology snapshots (v8: structural evolution)
210
+ CREATE TABLE IF NOT EXISTS graph_snapshots (
211
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
212
+ timestamp INTEGER NOT NULL,
213
+ metric TEXT NOT NULL,
214
+ value REAL NOT NULL,
215
+ details TEXT
216
+ );
217
+ CREATE INDEX IF NOT EXISTS idx_graph_snap_ts ON graph_snapshots(timestamp);
218
+ CREATE INDEX IF NOT EXISTS idx_graph_snap_m ON graph_snapshots(metric, timestamp);
219
+
220
+ -- Note embeddings for semantic search (v9)
221
+ CREATE TABLE IF NOT EXISTS note_embeddings (
222
+ path TEXT PRIMARY KEY,
223
+ embedding BLOB NOT NULL,
224
+ content_hash TEXT NOT NULL,
225
+ model TEXT NOT NULL,
226
+ updated_at INTEGER NOT NULL
227
+ );
228
+
229
+ -- Entity embeddings for semantic entity search (v10)
230
+ CREATE TABLE IF NOT EXISTS entity_embeddings (
231
+ entity_name TEXT PRIMARY KEY,
232
+ embedding BLOB NOT NULL,
233
+ source_hash TEXT NOT NULL,
234
+ model TEXT NOT NULL,
235
+ updated_at INTEGER NOT NULL
236
+ );
237
+
238
+ -- Task cache for fast task queries (v12)
239
+ CREATE TABLE IF NOT EXISTS tasks (
240
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
241
+ path TEXT NOT NULL,
242
+ line INTEGER NOT NULL,
243
+ text TEXT NOT NULL,
244
+ status TEXT NOT NULL,
245
+ raw TEXT NOT NULL,
246
+ context TEXT,
247
+ tags_json TEXT,
248
+ due_date TEXT,
249
+ UNIQUE(path, line)
250
+ );
251
+ CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status);
252
+ CREATE INDEX IF NOT EXISTS idx_tasks_path ON tasks(path);
253
+ CREATE INDEX IF NOT EXISTS idx_tasks_due ON tasks(due_date);
254
+
255
+ -- Merge dismissals (v13: persistent merge pair suppression)
256
+ CREATE TABLE IF NOT EXISTS merge_dismissals (
257
+ pair_key TEXT PRIMARY KEY,
258
+ source_path TEXT NOT NULL,
259
+ target_path TEXT NOT NULL,
260
+ source_name TEXT NOT NULL,
261
+ target_name TEXT NOT NULL,
262
+ reason TEXT NOT NULL,
263
+ dismissed_at TEXT DEFAULT (datetime('now'))
264
+ );
265
+
266
+ -- Suggestion events audit log (v15: pipeline observability)
267
+ CREATE TABLE IF NOT EXISTS suggestion_events (
268
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
269
+ timestamp INTEGER NOT NULL,
270
+ note_path TEXT NOT NULL,
271
+ entity TEXT NOT NULL,
272
+ total_score REAL NOT NULL,
273
+ breakdown_json TEXT NOT NULL,
274
+ threshold REAL NOT NULL,
275
+ passed INTEGER NOT NULL,
276
+ strictness TEXT NOT NULL,
277
+ applied INTEGER DEFAULT 0,
278
+ pipeline_event_id INTEGER,
279
+ UNIQUE(timestamp, note_path, entity)
280
+ );
281
+ CREATE INDEX IF NOT EXISTS idx_suggestion_entity ON suggestion_events(entity);
282
+ CREATE INDEX IF NOT EXISTS idx_suggestion_note ON suggestion_events(note_path);
283
+
284
+ -- Forward-link persistence for diff-based feedback (v16), edge weights (v22)
285
+ CREATE TABLE IF NOT EXISTS note_links (
286
+ note_path TEXT NOT NULL,
287
+ target TEXT NOT NULL,
288
+ weight REAL NOT NULL DEFAULT 1.0,
289
+ weight_updated_at INTEGER,
290
+ PRIMARY KEY (note_path, target)
291
+ );
292
+
293
+ -- Entity field change audit log (v17)
294
+ CREATE TABLE IF NOT EXISTS entity_changes (
295
+ entity TEXT NOT NULL,
296
+ field TEXT NOT NULL,
297
+ old_value TEXT,
298
+ new_value TEXT,
299
+ changed_at TEXT NOT NULL DEFAULT (datetime('now')),
300
+ PRIMARY KEY (entity, field, changed_at)
301
+ );
302
+
303
+ -- Note tag persistence for diff-based feedback (v18)
304
+ CREATE TABLE IF NOT EXISTS note_tags (
305
+ note_path TEXT NOT NULL,
306
+ tag TEXT NOT NULL,
307
+ PRIMARY KEY (note_path, tag)
308
+ );
309
+
310
+ -- Wikilink survival tracking for positive feedback signals (v19)
311
+ CREATE TABLE IF NOT EXISTS note_link_history (
312
+ note_path TEXT NOT NULL,
313
+ target TEXT NOT NULL,
314
+ first_seen_at TEXT NOT NULL DEFAULT (datetime('now')),
315
+ edits_survived INTEGER NOT NULL DEFAULT 0,
316
+ last_positive_at TEXT,
317
+ PRIMARY KEY (note_path, target)
318
+ );
319
+
320
+ -- Note move history (v20): records when files are moved/renamed to a different folder
321
+ CREATE TABLE IF NOT EXISTS note_moves (
322
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
323
+ old_path TEXT NOT NULL,
324
+ new_path TEXT NOT NULL,
325
+ moved_at TEXT NOT NULL DEFAULT (datetime('now')),
326
+ old_folder TEXT,
327
+ new_folder TEXT
328
+ );
329
+ CREATE INDEX IF NOT EXISTS idx_note_moves_old_path ON note_moves(old_path);
330
+ CREATE INDEX IF NOT EXISTS idx_note_moves_new_path ON note_moves(new_path);
331
+ CREATE INDEX IF NOT EXISTS idx_note_moves_moved_at ON note_moves(moved_at);
332
+
333
+ -- Corrections (v24): persistent correction records from user/engine feedback
334
+ CREATE TABLE IF NOT EXISTS corrections (
335
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
336
+ entity TEXT,
337
+ note_path TEXT,
338
+ correction_type TEXT NOT NULL,
339
+ description TEXT NOT NULL,
340
+ source TEXT NOT NULL DEFAULT 'user',
341
+ status TEXT DEFAULT 'pending',
342
+ created_at TEXT DEFAULT (datetime('now')),
343
+ resolved_at TEXT
344
+ );
345
+ CREATE INDEX IF NOT EXISTS idx_corrections_status ON corrections(status);
346
+ CREATE INDEX IF NOT EXISTS idx_corrections_entity ON corrections(entity);
347
+
348
+ -- Memories (v26): lightweight key-value working memory for agents
349
+ CREATE TABLE IF NOT EXISTS memories (
350
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
351
+ key TEXT NOT NULL,
352
+ value TEXT NOT NULL,
353
+ memory_type TEXT NOT NULL,
354
+ entity TEXT,
355
+ entities_json TEXT,
356
+ source_agent_id TEXT,
357
+ source_session_id TEXT,
358
+ confidence REAL NOT NULL DEFAULT 1.0,
359
+ created_at INTEGER NOT NULL,
360
+ updated_at INTEGER NOT NULL,
361
+ accessed_at INTEGER NOT NULL,
362
+ ttl_days INTEGER,
363
+ superseded_by INTEGER REFERENCES memories(id),
364
+ visibility TEXT NOT NULL DEFAULT 'shared'
365
+ );
366
+ CREATE INDEX IF NOT EXISTS idx_memories_key ON memories(key);
367
+ CREATE INDEX IF NOT EXISTS idx_memories_entity ON memories(entity);
368
+ CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(memory_type);
369
+
370
+ CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
371
+ key, value,
372
+ content=memories, content_rowid=id,
373
+ tokenize='porter unicode61'
374
+ );
375
+
376
+ -- Auto-sync triggers for memories_fts
377
+ CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
378
+ INSERT INTO memories_fts(rowid, key, value)
379
+ VALUES (new.id, new.key, new.value);
380
+ END;
381
+
382
+ CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
383
+ INSERT INTO memories_fts(memories_fts, rowid, key, value)
384
+ VALUES ('delete', old.id, old.key, old.value);
385
+ END;
386
+
387
+ CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
388
+ INSERT INTO memories_fts(memories_fts, rowid, key, value)
389
+ VALUES ('delete', old.id, old.key, old.value);
390
+ INSERT INTO memories_fts(rowid, key, value)
391
+ VALUES (new.id, new.key, new.value);
392
+ END;
393
+
394
+ -- Co-occurrence cache (v27): persist co-occurrence index to avoid full vault scan on restart
395
+ CREATE TABLE IF NOT EXISTS cooccurrence_cache (
396
+ id INTEGER PRIMARY KEY CHECK (id = 1),
397
+ data TEXT NOT NULL,
398
+ built_at INTEGER NOT NULL,
399
+ entity_count INTEGER NOT NULL,
400
+ association_count INTEGER NOT NULL
401
+ );
402
+
403
+ -- Content hashes (v28): persist watcher content hashes across restarts
404
+ CREATE TABLE IF NOT EXISTS content_hashes (
405
+ path TEXT PRIMARY KEY,
406
+ hash TEXT NOT NULL,
407
+ updated_at INTEGER NOT NULL
408
+ );
409
+
410
+ -- Session summaries (v26): agent session tracking
411
+ CREATE TABLE IF NOT EXISTS session_summaries (
412
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
413
+ session_id TEXT NOT NULL UNIQUE,
414
+ summary TEXT NOT NULL,
415
+ topics_json TEXT,
416
+ notes_modified_json TEXT,
417
+ agent_id TEXT,
418
+ started_at INTEGER,
419
+ ended_at INTEGER NOT NULL,
420
+ tool_count INTEGER
421
+ );
422
+
423
+ -- Retrieval co-occurrence (v30): notes retrieved together build implicit edges
424
+ CREATE TABLE IF NOT EXISTS retrieval_cooccurrence (
425
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
426
+ note_a TEXT NOT NULL,
427
+ note_b TEXT NOT NULL,
428
+ session_id TEXT NOT NULL,
429
+ timestamp INTEGER NOT NULL,
430
+ weight REAL NOT NULL DEFAULT 1.0,
431
+ UNIQUE(note_a, note_b, session_id)
432
+ );
433
+ CREATE INDEX IF NOT EXISTS idx_retcooc_notes ON retrieval_cooccurrence(note_a, note_b);
434
+ CREATE INDEX IF NOT EXISTS idx_retcooc_ts ON retrieval_cooccurrence(timestamp);
435
+
436
+ -- Deferred proactive linking queue (v31)
437
+ CREATE TABLE IF NOT EXISTS proactive_queue (
438
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
439
+ note_path TEXT NOT NULL,
440
+ entity TEXT NOT NULL,
441
+ score REAL NOT NULL,
442
+ confidence TEXT NOT NULL,
443
+ queued_at INTEGER NOT NULL,
444
+ expires_at INTEGER NOT NULL,
445
+ status TEXT NOT NULL DEFAULT 'pending',
446
+ applied_at INTEGER,
447
+ UNIQUE(note_path, entity)
448
+ );
449
+ CREATE INDEX IF NOT EXISTS idx_pq_status ON proactive_queue(status, expires_at);
450
+ `;
451
+ //# sourceMappingURL=schema.js.map
package/dist/sqlite.d.ts CHANGED
@@ -12,6 +12,10 @@
12
12
  import Database from 'better-sqlite3';
13
13
  import type { Statement, Transaction } from 'better-sqlite3';
14
14
  import type { EntityCategory, EntityWithAliases, EntityIndex } from './types.js';
15
+ export { SCHEMA_VERSION, STATE_DB_FILENAME, FLYWHEEL_DIR, SCHEMA_SQL } from './schema.js';
16
+ export { getStateDbPath, initSchema, deleteStateDbFiles, backupStateDb, preserveCorruptedDb } from './migrations.js';
17
+ export { searchEntities, searchEntitiesPrefix, getEntityByName, getAllEntitiesFromDb, getEntityIndexFromDb, getEntitiesByAlias, recordEntityMention, getEntityRecency, getAllRecency, setWriteState, getWriteState, deleteWriteState, setFlywheelConfig, getFlywheelConfig, getAllFlywheelConfig, deleteFlywheelConfig, saveFlywheelConfigToDb, loadFlywheelConfigFromDb, recordMergeDismissal, getDismissedMergePairs, getStateDbMetadata, isEntityDataStale, escapeFts5Query, rebuildEntitiesFts, stateDbExists, deleteStateDb, saveVaultIndexCache, loadVaultIndexCache, getVaultIndexCacheInfo, clearVaultIndexCache, isVaultIndexCacheValid, loadContentHashes, saveContentHashBatch, renameContentHash, } from './queries.js';
18
+ export type { FlywheelConfigRow, VaultIndexCacheData, VaultIndexCacheInfo } from './queries.js';
15
19
  /** Search result from FTS5 entity search */
16
20
  export interface EntitySearchResult {
17
21
  id: number;
@@ -74,16 +78,6 @@ export interface StateDb {
74
78
  replaceAllEntities: Transaction<(index: EntityIndex) => number>;
75
79
  close: () => void;
76
80
  }
77
- /** Current schema version - bump when schema changes */
78
- export declare const SCHEMA_VERSION = 31;
79
- /** State database filename */
80
- export declare const STATE_DB_FILENAME = "state.db";
81
- /** Directory for flywheel state */
82
- export declare const FLYWHEEL_DIR = ".flywheel";
83
- /**
84
- * Get the database path for a vault
85
- */
86
- export declare function getStateDbPath(vaultPath: string): string;
87
81
  /**
88
82
  * Open or create the state database for a vault
89
83
  *
@@ -91,203 +85,4 @@ export declare function getStateDbPath(vaultPath: string): string;
91
85
  * @returns StateDb instance with prepared statements
92
86
  */
93
87
  export declare function openStateDb(vaultPath: string): StateDb;
94
- /**
95
- * Search entities using FTS5 with porter stemming
96
- *
97
- * @param stateDb - State database instance
98
- * @param query - Search query (supports FTS5 syntax)
99
- * @param limit - Maximum results to return
100
- * @returns Array of matching entities with relevance scores
101
- */
102
- export declare function searchEntities(stateDb: StateDb, query: string, limit?: number): EntitySearchResult[];
103
- /**
104
- * Search entities by prefix for autocomplete
105
- *
106
- * @param stateDb - State database instance
107
- * @param prefix - Prefix to search for
108
- * @param limit - Maximum results to return
109
- */
110
- export declare function searchEntitiesPrefix(stateDb: StateDb, prefix: string, limit?: number): EntitySearchResult[];
111
- /**
112
- * Get entity by exact name (case-insensitive)
113
- */
114
- export declare function getEntityByName(stateDb: StateDb, name: string): EntitySearchResult | null;
115
- /**
116
- * Get all entities from the database
117
- */
118
- export declare function getAllEntitiesFromDb(stateDb: StateDb): EntitySearchResult[];
119
- /**
120
- * Convert database entities back to EntityIndex format
121
- */
122
- export declare function getEntityIndexFromDb(stateDb: StateDb): EntityIndex;
123
- /**
124
- * Get entities that have a given alias (case-insensitive)
125
- *
126
- * @param stateDb - State database instance
127
- * @param alias - Alias to search for (case-insensitive)
128
- * @returns Array of matching entities
129
- */
130
- export declare function getEntitiesByAlias(stateDb: StateDb, alias: string): EntitySearchResult[];
131
- /**
132
- * Record a mention of an entity
133
- */
134
- export declare function recordEntityMention(stateDb: StateDb, entityName: string, mentionedAt?: Date): void;
135
- /**
136
- * Get recency info for an entity
137
- */
138
- export declare function getEntityRecency(stateDb: StateDb, entityName: string): RecencyRow | null;
139
- /**
140
- * Get all recency data ordered by most recent
141
- */
142
- export declare function getAllRecency(stateDb: StateDb): RecencyRow[];
143
- /**
144
- * Set a write state value
145
- */
146
- export declare function setWriteState(stateDb: StateDb, key: string, value: unknown): void;
147
- /**
148
- * Get a write state value
149
- */
150
- export declare function getWriteState<T>(stateDb: StateDb, key: string): T | null;
151
- /**
152
- * Delete a write state key
153
- */
154
- export declare function deleteWriteState(stateDb: StateDb, key: string): void;
155
- /** Flywheel config row from database */
156
- export interface FlywheelConfigRow {
157
- key: string;
158
- value: string;
159
- }
160
- /**
161
- * Set a flywheel config value
162
- */
163
- export declare function setFlywheelConfig(stateDb: StateDb, key: string, value: unknown): void;
164
- /**
165
- * Get a flywheel config value
166
- */
167
- export declare function getFlywheelConfig<T>(stateDb: StateDb, key: string): T | null;
168
- /**
169
- * Get all flywheel config values as an object
170
- */
171
- export declare function getAllFlywheelConfig(stateDb: StateDb): Record<string, unknown>;
172
- /**
173
- * Delete a flywheel config key
174
- */
175
- export declare function deleteFlywheelConfig(stateDb: StateDb, key: string): void;
176
- /**
177
- * Save entire Flywheel config object to database
178
- * Stores each top-level key as a separate row
179
- */
180
- export declare function saveFlywheelConfigToDb(stateDb: StateDb, config: Record<string, unknown>): void;
181
- /**
182
- * Load Flywheel config from database and reconstruct as typed object
183
- */
184
- export declare function loadFlywheelConfigFromDb(stateDb: StateDb): Record<string, unknown> | null;
185
- /**
186
- * Record a merge dismissal so the pair never reappears in suggestions.
187
- */
188
- export declare function recordMergeDismissal(db: StateDb, sourcePath: string, targetPath: string, sourceName: string, targetName: string, reason: string): void;
189
- /**
190
- * Get all dismissed merge pair keys for filtering.
191
- */
192
- export declare function getDismissedMergePairs(db: StateDb): Set<string>;
193
- /**
194
- * Get database metadata
195
- */
196
- export declare function getStateDbMetadata(stateDb: StateDb): StateDbMetadata;
197
- /**
198
- * Check if entity data is stale (older than threshold)
199
- */
200
- export declare function isEntityDataStale(stateDb: StateDb, thresholdMs?: number): boolean;
201
- /**
202
- * Escape special FTS5 characters in a query
203
- */
204
- export declare function escapeFts5Query(query: string): string;
205
- /**
206
- * Rebuild the entities_fts index from the entities table.
207
- * Uses FTS5's built-in 'rebuild' command to resynchronize.
208
- * Call this if the FTS index gets out of sync (e.g., T.aliases errors).
209
- */
210
- export declare function rebuildEntitiesFts(stateDb: StateDb): void;
211
- /**
212
- * Check if the state database exists for a vault
213
- */
214
- export declare function stateDbExists(vaultPath: string): boolean;
215
- /**
216
- * Delete the state database (for testing or reset)
217
- */
218
- export declare function deleteStateDb(vaultPath: string): void;
219
- /** Serializable VaultIndex for caching */
220
- export interface VaultIndexCacheData {
221
- notes: Array<{
222
- path: string;
223
- title: string;
224
- aliases: string[];
225
- frontmatter: Record<string, unknown>;
226
- outlinks: Array<{
227
- target: string;
228
- alias?: string;
229
- line: number;
230
- }>;
231
- tags: string[];
232
- modified: number;
233
- created?: number;
234
- }>;
235
- backlinks: Array<[string, Array<{
236
- source: string;
237
- line: number;
238
- context?: string;
239
- }>]>;
240
- entities: Array<[string, string]>;
241
- prospects?: Array<[string, {
242
- displayName: string;
243
- backlinkCount: number;
244
- }]>;
245
- tags: Array<[string, string[]]>;
246
- builtAt: number;
247
- }
248
- /** Cache metadata */
249
- export interface VaultIndexCacheInfo {
250
- builtAt: Date;
251
- noteCount: number;
252
- version: number;
253
- }
254
- /**
255
- * Save VaultIndex to cache
256
- *
257
- * @param stateDb - State database instance
258
- * @param indexData - Serialized VaultIndex data
259
- */
260
- export declare function saveVaultIndexCache(stateDb: StateDb, indexData: VaultIndexCacheData): void;
261
- /**
262
- * Load VaultIndex from cache
263
- *
264
- * @param stateDb - State database instance
265
- * @returns Cached VaultIndex data or null if not found
266
- */
267
- export declare function loadVaultIndexCache(stateDb: StateDb): VaultIndexCacheData | null;
268
- /**
269
- * Get cache metadata without loading full data
270
- */
271
- export declare function getVaultIndexCacheInfo(stateDb: StateDb): VaultIndexCacheInfo | null;
272
- /**
273
- * Clear the vault index cache
274
- */
275
- export declare function clearVaultIndexCache(stateDb: StateDb): void;
276
- /**
277
- * Check if cache is valid (not too old and note count matches)
278
- *
279
- * @param stateDb - State database instance
280
- * @param actualNoteCount - Current number of notes in vault
281
- * @param maxAgeMs - Maximum cache age in milliseconds (default 24 hours)
282
- */
283
- export declare function isVaultIndexCacheValid(stateDb: StateDb, actualNoteCount: number, maxAgeMs?: number): boolean;
284
- /** Load all persisted content hashes */
285
- export declare function loadContentHashes(stateDb: StateDb): Map<string, string>;
286
- /** Persist hash changes from a watcher batch (upserts + deletes in one transaction) */
287
- export declare function saveContentHashBatch(stateDb: StateDb, upserts: Array<{
288
- path: string;
289
- hash: string;
290
- }>, deletes: string[]): void;
291
- /** Rename a hash entry (for file renames) */
292
- export declare function renameContentHash(stateDb: StateDb, oldPath: string, newPath: string): void;
293
88
  //# sourceMappingURL=sqlite.d.ts.map