@coreyuan/vector-mind 1.0.49 → 1.0.52
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 -60
- package/dist/activity-log.d.ts +19 -0
- package/dist/activity-log.js +106 -0
- package/dist/activity-log.js.map +1 -0
- package/dist/builtin-conventions.d.ts +2 -1
- package/dist/builtin-conventions.js +5 -0
- package/dist/builtin-conventions.js.map +1 -1
- package/dist/config.d.ts +28 -0
- package/dist/config.js +189 -0
- package/dist/config.js.map +1 -0
- package/dist/database-runtime.d.ts +54 -0
- package/dist/database-runtime.js +512 -0
- package/dist/database-runtime.js.map +1 -0
- package/dist/development-warnings.d.ts +93 -0
- package/dist/development-warnings.js +589 -0
- package/dist/development-warnings.js.map +1 -0
- package/dist/file-indexing.d.ts +22 -0
- package/dist/file-indexing.js +243 -0
- package/dist/file-indexing.js.map +1 -0
- package/dist/grep.d.ts +64 -0
- package/dist/grep.js +475 -0
- package/dist/grep.js.map +1 -0
- package/dist/index.js +167 -7279
- package/dist/index.js.map +1 -1
- package/dist/large-file-split.d.ts +29 -0
- package/dist/large-file-split.js +146 -0
- package/dist/large-file-split.js.map +1 -0
- package/dist/memory-maintenance.d.ts +80 -0
- package/dist/memory-maintenance.js +537 -0
- package/dist/memory-maintenance.js.map +1 -0
- package/dist/memory-mutations.d.ts +23 -0
- package/dist/memory-mutations.js +83 -0
- package/dist/memory-mutations.js.map +1 -0
- package/dist/memory-recall.d.ts +93 -0
- package/dist/memory-recall.js +796 -0
- package/dist/memory-recall.js.map +1 -0
- package/dist/path-filters.d.ts +1 -0
- package/dist/path-filters.js +27 -0
- package/dist/path-filters.js.map +1 -0
- package/dist/path-rules.d.ts +12 -0
- package/dist/path-rules.js +208 -0
- package/dist/path-rules.js.map +1 -0
- package/dist/pending-changes.d.ts +22 -0
- package/dist/pending-changes.js +166 -0
- package/dist/pending-changes.js.map +1 -0
- package/dist/project-files.d.ts +66 -0
- package/dist/project-files.js +215 -0
- package/dist/project-files.js.map +1 -0
- package/dist/root.d.ts +15 -0
- package/dist/root.js +191 -0
- package/dist/root.js.map +1 -0
- package/dist/rtk-tools.d.ts +20 -0
- package/dist/rtk-tools.js +318 -0
- package/dist/rtk-tools.js.map +1 -0
- package/dist/server-instructions.d.ts +1 -0
- package/dist/server-instructions.js +88 -0
- package/dist/server-instructions.js.map +1 -0
- package/dist/symbols.d.ts +2 -0
- package/dist/symbols.js +159 -0
- package/dist/symbols.js.map +1 -0
- package/dist/token-savings.d.ts +40 -0
- package/dist/token-savings.js +50 -0
- package/dist/token-savings.js.map +1 -0
- package/dist/tool-catalog.d.ts +18 -0
- package/dist/tool-catalog.js +243 -0
- package/dist/tool-catalog.js.map +1 -0
- package/dist/tool-handlers/context-recovery.d.ts +6 -0
- package/dist/tool-handlers/context-recovery.js +319 -0
- package/dist/tool-handlers/context-recovery.js.map +1 -0
- package/dist/tool-handlers/context.d.ts +34 -0
- package/dist/tool-handlers/context.js +2 -0
- package/dist/tool-handlers/context.js.map +1 -0
- package/dist/tool-handlers/diagnostics.d.ts +8 -0
- package/dist/tool-handlers/diagnostics.js +114 -0
- package/dist/tool-handlers/diagnostics.js.map +1 -0
- package/dist/tool-handlers/files.d.ts +8 -0
- package/dist/tool-handlers/files.js +493 -0
- package/dist/tool-handlers/files.js.map +1 -0
- package/dist/tool-handlers/large-files.d.ts +4 -0
- package/dist/tool-handlers/large-files.js +139 -0
- package/dist/tool-handlers/large-files.js.map +1 -0
- package/dist/tool-handlers/maintenance.d.ts +4 -0
- package/dist/tool-handlers/maintenance.js +160 -0
- package/dist/tool-handlers/maintenance.js.map +1 -0
- package/dist/tool-handlers/memory-diagnostics.d.ts +5 -0
- package/dist/tool-handlers/memory-diagnostics.js +509 -0
- package/dist/tool-handlers/memory-diagnostics.js.map +1 -0
- package/dist/tool-handlers/memory.d.ts +6 -0
- package/dist/tool-handlers/memory.js +334 -0
- package/dist/tool-handlers/memory.js.map +1 -0
- package/dist/tool-handlers/notes-decisions.d.ts +7 -0
- package/dist/tool-handlers/notes-decisions.js +169 -0
- package/dist/tool-handlers/notes-decisions.js.map +1 -0
- package/dist/tool-handlers/requirements.d.ts +7 -0
- package/dist/tool-handlers/requirements.js +357 -0
- package/dist/tool-handlers/requirements.js.map +1 -0
- package/dist/tool-handlers.d.ts +4 -0
- package/dist/tool-handlers.js +105 -0
- package/dist/tool-handlers.js.map +1 -0
- package/dist/tool-output.d.ts +213 -0
- package/dist/tool-output.js +278 -0
- package/dist/tool-output.js.map +1 -0
- package/dist/tool-schemas.d.ts +434 -0
- package/dist/tool-schemas.js +328 -0
- package/dist/tool-schemas.js.map +1 -0
- package/dist/types.d.ts +61 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/docs/capability-matrix.md +43 -0
- package/package.json +11 -10
- package/skills/vector-mind-autopilot/SKILL.md +149 -0
- package/skills/vector-mind-autopilot/references/claude-desktop-mcp-config.json +9 -0
- package/skills/vector-mind-autopilot/references/claude-project-instructions.md +47 -0
- package/skills/vector-mind-autopilot/references/universal-system-prompt.md +78 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import Database from "better-sqlite3";
|
|
4
|
+
import { MEMORY_ITEMS_FTS_TABLE } from "./memory-recall.js";
|
|
5
|
+
export const FTS_TABLE_NAME = MEMORY_ITEMS_FTS_TABLE;
|
|
6
|
+
let db;
|
|
7
|
+
let dbPath = "";
|
|
8
|
+
let ftsAvailable = false;
|
|
9
|
+
let insertRequirementStmt;
|
|
10
|
+
let getActiveRequirementStmt;
|
|
11
|
+
let listActiveRequirementsStmt;
|
|
12
|
+
let listRecentRequirementsStmt;
|
|
13
|
+
let completeAllActiveRequirementsStmt;
|
|
14
|
+
let completeRequirementByIdStmt;
|
|
15
|
+
let completeAllActiveRequirementMemoryItemsStmt;
|
|
16
|
+
let completeRequirementMemoryItemByReqIdStmt;
|
|
17
|
+
let listChangeLogsForRequirementStmt;
|
|
18
|
+
let insertChangeLogStmt;
|
|
19
|
+
let insertMemoryItemStmt;
|
|
20
|
+
let getMemoryItemByIdStmt;
|
|
21
|
+
let getRequirementMemoryItemIdStmt;
|
|
22
|
+
let getConventionByKeyStmt;
|
|
23
|
+
let insertConventionStmt;
|
|
24
|
+
let updateConventionByIdStmt;
|
|
25
|
+
let listConventionsStmt;
|
|
26
|
+
let upsertDecisionStmt;
|
|
27
|
+
let getDecisionByKeyStmt;
|
|
28
|
+
let listCurrentDecisionsStmt;
|
|
29
|
+
let upsertProjectSummaryStmt;
|
|
30
|
+
let getProjectSummaryStmt;
|
|
31
|
+
let getLatestChangeIntentForFileStmt;
|
|
32
|
+
let deleteFileChunkItemsStmt;
|
|
33
|
+
let upsertPendingChangeStmt;
|
|
34
|
+
let listPendingChangesStmt;
|
|
35
|
+
let countPendingChangesStmt;
|
|
36
|
+
let deletePendingChangeStmt;
|
|
37
|
+
let deleteAllPendingChangesStmt;
|
|
38
|
+
let deleteOldPendingChangesStmt = null;
|
|
39
|
+
let deleteOldestPendingChangesStmt = null;
|
|
40
|
+
let deleteSymbolsForFileStmt;
|
|
41
|
+
let upsertSymbolStmt;
|
|
42
|
+
let searchSymbolsStmt;
|
|
43
|
+
let insertTokenSavingsStmt;
|
|
44
|
+
let summarizeTokenSavingsStmt;
|
|
45
|
+
let summarizeTokenSavingsByToolStmt;
|
|
46
|
+
let listRecentTokenSavingsStmt;
|
|
47
|
+
let getKvStmt;
|
|
48
|
+
let setKvStmt;
|
|
49
|
+
let indexFileSymbolsTx = null;
|
|
50
|
+
function initMemoryItemsFts() {
|
|
51
|
+
ftsAvailable = false;
|
|
52
|
+
try {
|
|
53
|
+
const existed = db
|
|
54
|
+
.prepare(`SELECT 1 FROM sqlite_master WHERE type='table' AND name=?`)
|
|
55
|
+
.get(FTS_TABLE_NAME);
|
|
56
|
+
const alreadyExists = !!existed;
|
|
57
|
+
if (!alreadyExists) {
|
|
58
|
+
try {
|
|
59
|
+
db.exec(`
|
|
60
|
+
CREATE VIRTUAL TABLE ${FTS_TABLE_NAME} USING fts5(
|
|
61
|
+
kind,
|
|
62
|
+
title,
|
|
63
|
+
content,
|
|
64
|
+
file_path,
|
|
65
|
+
metadata_json,
|
|
66
|
+
content='memory_items',
|
|
67
|
+
content_rowid='id',
|
|
68
|
+
tokenize='trigram'
|
|
69
|
+
);
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
db.exec(`
|
|
74
|
+
CREATE VIRTUAL TABLE ${FTS_TABLE_NAME} USING fts5(
|
|
75
|
+
kind,
|
|
76
|
+
title,
|
|
77
|
+
content,
|
|
78
|
+
file_path,
|
|
79
|
+
metadata_json,
|
|
80
|
+
content='memory_items',
|
|
81
|
+
content_rowid='id'
|
|
82
|
+
);
|
|
83
|
+
`);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
db.exec(`INSERT INTO ${FTS_TABLE_NAME}(${FTS_TABLE_NAME}) VALUES('rebuild');`);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
console.error("[vectormind] fts rebuild failed:", err);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
db.exec(`
|
|
93
|
+
CREATE TRIGGER IF NOT EXISTS vectormind_memory_items_fts_ai
|
|
94
|
+
AFTER INSERT ON memory_items BEGIN
|
|
95
|
+
INSERT INTO ${FTS_TABLE_NAME}(rowid, kind, title, content, file_path, metadata_json)
|
|
96
|
+
VALUES (new.id, new.kind, new.title, new.content, new.file_path, new.metadata_json);
|
|
97
|
+
END;
|
|
98
|
+
|
|
99
|
+
CREATE TRIGGER IF NOT EXISTS vectormind_memory_items_fts_ad
|
|
100
|
+
AFTER DELETE ON memory_items BEGIN
|
|
101
|
+
INSERT INTO ${FTS_TABLE_NAME}(${FTS_TABLE_NAME}, rowid, kind, title, content, file_path, metadata_json)
|
|
102
|
+
VALUES ('delete', old.id, old.kind, old.title, old.content, old.file_path, old.metadata_json);
|
|
103
|
+
END;
|
|
104
|
+
|
|
105
|
+
CREATE TRIGGER IF NOT EXISTS vectormind_memory_items_fts_au
|
|
106
|
+
AFTER UPDATE ON memory_items BEGIN
|
|
107
|
+
INSERT INTO ${FTS_TABLE_NAME}(${FTS_TABLE_NAME}, rowid, kind, title, content, file_path, metadata_json)
|
|
108
|
+
VALUES ('delete', old.id, old.kind, old.title, old.content, old.file_path, old.metadata_json);
|
|
109
|
+
INSERT INTO ${FTS_TABLE_NAME}(rowid, kind, title, content, file_path, metadata_json)
|
|
110
|
+
VALUES (new.id, new.kind, new.title, new.content, new.file_path, new.metadata_json);
|
|
111
|
+
END;
|
|
112
|
+
`);
|
|
113
|
+
db.prepare(`SELECT rowid FROM ${FTS_TABLE_NAME} LIMIT 1`).get();
|
|
114
|
+
ftsAvailable = true;
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
ftsAvailable = false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function columnExists(table, column) {
|
|
121
|
+
try {
|
|
122
|
+
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
123
|
+
return rows.some((row) => row.name === column);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function openDatabaseRuntime(projectRoot) {
|
|
130
|
+
const vmDir = path.join(projectRoot, ".vectormind");
|
|
131
|
+
try {
|
|
132
|
+
fs.mkdirSync(vmDir, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// ignore
|
|
136
|
+
}
|
|
137
|
+
dbPath = path.join(vmDir, "vectormind.db");
|
|
138
|
+
db = new Database(dbPath);
|
|
139
|
+
db.pragma("journal_mode = WAL");
|
|
140
|
+
db.pragma("foreign_keys = ON");
|
|
141
|
+
db.exec(`
|
|
142
|
+
CREATE TABLE IF NOT EXISTS requirements (
|
|
143
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
144
|
+
title TEXT NOT NULL,
|
|
145
|
+
status TEXT DEFAULT 'active',
|
|
146
|
+
context_data TEXT,
|
|
147
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
148
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
CREATE TABLE IF NOT EXISTS change_logs (
|
|
152
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
153
|
+
req_id INTEGER,
|
|
154
|
+
file_path TEXT,
|
|
155
|
+
intent_summary TEXT,
|
|
156
|
+
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
157
|
+
FOREIGN KEY(req_id) REFERENCES requirements(id)
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
CREATE TABLE IF NOT EXISTS symbols (
|
|
161
|
+
name TEXT,
|
|
162
|
+
type TEXT,
|
|
163
|
+
file_path TEXT,
|
|
164
|
+
signature TEXT,
|
|
165
|
+
PRIMARY KEY(name, file_path)
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
CREATE INDEX IF NOT EXISTS idx_change_logs_req_id_timestamp
|
|
169
|
+
ON change_logs(req_id, timestamp DESC);
|
|
170
|
+
|
|
171
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_name
|
|
172
|
+
ON symbols(name);
|
|
173
|
+
|
|
174
|
+
CREATE TABLE IF NOT EXISTS memory_items (
|
|
175
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
176
|
+
kind TEXT NOT NULL,
|
|
177
|
+
title TEXT,
|
|
178
|
+
content TEXT NOT NULL,
|
|
179
|
+
file_path TEXT,
|
|
180
|
+
start_line INTEGER,
|
|
181
|
+
end_line INTEGER,
|
|
182
|
+
req_id INTEGER,
|
|
183
|
+
metadata_json TEXT,
|
|
184
|
+
content_hash TEXT,
|
|
185
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
186
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_items_chunk_locator
|
|
190
|
+
ON memory_items(kind, file_path, start_line, end_line);
|
|
191
|
+
|
|
192
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_items_project_summary
|
|
193
|
+
ON memory_items(kind) WHERE kind = 'project_summary';
|
|
194
|
+
|
|
195
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_items_convention_key
|
|
196
|
+
ON memory_items(kind, title) WHERE kind = 'convention';
|
|
197
|
+
|
|
198
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_memory_items_decision_key
|
|
199
|
+
ON memory_items(kind, title) WHERE kind = 'decision';
|
|
200
|
+
|
|
201
|
+
CREATE INDEX IF NOT EXISTS idx_memory_items_kind_updated_at
|
|
202
|
+
ON memory_items(kind, updated_at DESC);
|
|
203
|
+
|
|
204
|
+
CREATE INDEX IF NOT EXISTS idx_memory_items_file_path
|
|
205
|
+
ON memory_items(file_path);
|
|
206
|
+
|
|
207
|
+
CREATE INDEX IF NOT EXISTS idx_memory_items_req_id
|
|
208
|
+
ON memory_items(req_id);
|
|
209
|
+
|
|
210
|
+
CREATE TABLE IF NOT EXISTS pending_changes (
|
|
211
|
+
file_path TEXT PRIMARY KEY,
|
|
212
|
+
last_event TEXT NOT NULL,
|
|
213
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
CREATE INDEX IF NOT EXISTS idx_pending_changes_updated_at
|
|
217
|
+
ON pending_changes(updated_at DESC);
|
|
218
|
+
|
|
219
|
+
CREATE TABLE IF NOT EXISTS token_savings (
|
|
220
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
221
|
+
tool TEXT NOT NULL,
|
|
222
|
+
raw_tokens INTEGER NOT NULL,
|
|
223
|
+
output_tokens INTEGER NOT NULL,
|
|
224
|
+
saved_tokens INTEGER NOT NULL,
|
|
225
|
+
savings_pct REAL NOT NULL,
|
|
226
|
+
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
CREATE INDEX IF NOT EXISTS idx_token_savings_created_at
|
|
230
|
+
ON token_savings(created_at DESC);
|
|
231
|
+
|
|
232
|
+
CREATE INDEX IF NOT EXISTS idx_token_savings_tool
|
|
233
|
+
ON token_savings(tool);
|
|
234
|
+
|
|
235
|
+
CREATE TABLE IF NOT EXISTS memory_item_archive (
|
|
236
|
+
memory_id INTEGER PRIMARY KEY,
|
|
237
|
+
original_kind TEXT NOT NULL,
|
|
238
|
+
original_title TEXT,
|
|
239
|
+
original_content TEXT NOT NULL,
|
|
240
|
+
original_file_path TEXT,
|
|
241
|
+
original_start_line INTEGER,
|
|
242
|
+
original_end_line INTEGER,
|
|
243
|
+
original_req_id INTEGER,
|
|
244
|
+
original_metadata_json TEXT,
|
|
245
|
+
original_content_hash TEXT,
|
|
246
|
+
original_created_at DATETIME,
|
|
247
|
+
original_updated_at DATETIME,
|
|
248
|
+
archive_reason TEXT NOT NULL,
|
|
249
|
+
compacted_into_id INTEGER,
|
|
250
|
+
archived_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
CREATE INDEX IF NOT EXISTS idx_memory_item_archive_compacted_into
|
|
254
|
+
ON memory_item_archive(compacted_into_id);
|
|
255
|
+
|
|
256
|
+
CREATE TABLE IF NOT EXISTS meta_kv (
|
|
257
|
+
key TEXT PRIMARY KEY,
|
|
258
|
+
value TEXT NOT NULL,
|
|
259
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
260
|
+
);
|
|
261
|
+
`);
|
|
262
|
+
if (!columnExists("requirements", "updated_at")) {
|
|
263
|
+
db.exec(`ALTER TABLE requirements ADD COLUMN updated_at DATETIME`);
|
|
264
|
+
db.exec(`UPDATE requirements SET updated_at = COALESCE(created_at, CURRENT_TIMESTAMP) WHERE updated_at IS NULL`);
|
|
265
|
+
}
|
|
266
|
+
db.exec(`
|
|
267
|
+
UPDATE requirements SET updated_at = COALESCE(updated_at, created_at, CURRENT_TIMESTAMP) WHERE updated_at IS NULL;
|
|
268
|
+
CREATE INDEX IF NOT EXISTS idx_requirements_status_updated_at
|
|
269
|
+
ON requirements(status, updated_at DESC, id DESC);
|
|
270
|
+
CREATE TRIGGER IF NOT EXISTS vectormind_requirements_touch_updated_at
|
|
271
|
+
AFTER UPDATE ON requirements
|
|
272
|
+
FOR EACH ROW
|
|
273
|
+
WHEN NEW.updated_at = OLD.updated_at
|
|
274
|
+
BEGIN
|
|
275
|
+
UPDATE requirements SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
276
|
+
END;
|
|
277
|
+
`);
|
|
278
|
+
initMemoryItemsFts();
|
|
279
|
+
insertRequirementStmt = db.prepare(`INSERT INTO requirements (title, context_data, status) VALUES (?, ?, 'active')`);
|
|
280
|
+
completeAllActiveRequirementsStmt = db.prepare(`UPDATE requirements SET status = 'completed' WHERE status = 'active'`);
|
|
281
|
+
completeRequirementByIdStmt = db.prepare(`UPDATE requirements SET status = 'completed' WHERE id = ?`);
|
|
282
|
+
getActiveRequirementStmt = db.prepare(`SELECT id, title, status, context_data, created_at
|
|
283
|
+
FROM requirements
|
|
284
|
+
WHERE status = 'active'
|
|
285
|
+
ORDER BY updated_at DESC, created_at DESC, id DESC
|
|
286
|
+
LIMIT 1`);
|
|
287
|
+
listActiveRequirementsStmt = db.prepare(`SELECT id, title, status, context_data, created_at
|
|
288
|
+
FROM requirements
|
|
289
|
+
WHERE status = 'active'
|
|
290
|
+
ORDER BY updated_at DESC, created_at DESC, id DESC
|
|
291
|
+
LIMIT ?`);
|
|
292
|
+
listRecentRequirementsStmt = db.prepare(`SELECT id, title, status, context_data, created_at
|
|
293
|
+
FROM requirements
|
|
294
|
+
ORDER BY updated_at DESC, created_at DESC, id DESC
|
|
295
|
+
LIMIT ?`);
|
|
296
|
+
completeAllActiveRequirementMemoryItemsStmt = db.prepare(`UPDATE memory_items
|
|
297
|
+
SET metadata_json = json_set(
|
|
298
|
+
CASE
|
|
299
|
+
WHEN json_valid(COALESCE(metadata_json, '{}')) THEN COALESCE(metadata_json, '{}')
|
|
300
|
+
ELSE '{}'
|
|
301
|
+
END,
|
|
302
|
+
'$.status',
|
|
303
|
+
?
|
|
304
|
+
),
|
|
305
|
+
updated_at = CURRENT_TIMESTAMP
|
|
306
|
+
WHERE kind = 'requirement'
|
|
307
|
+
AND json_extract(
|
|
308
|
+
CASE
|
|
309
|
+
WHEN json_valid(COALESCE(metadata_json, '{}')) THEN COALESCE(metadata_json, '{}')
|
|
310
|
+
ELSE '{}'
|
|
311
|
+
END,
|
|
312
|
+
'$.status'
|
|
313
|
+
) = ?`);
|
|
314
|
+
completeRequirementMemoryItemByReqIdStmt = db.prepare(`UPDATE memory_items
|
|
315
|
+
SET metadata_json = json_set(
|
|
316
|
+
CASE
|
|
317
|
+
WHEN json_valid(COALESCE(metadata_json, '{}')) THEN COALESCE(metadata_json, '{}')
|
|
318
|
+
ELSE '{}'
|
|
319
|
+
END,
|
|
320
|
+
'$.status',
|
|
321
|
+
?
|
|
322
|
+
),
|
|
323
|
+
updated_at = CURRENT_TIMESTAMP
|
|
324
|
+
WHERE kind = 'requirement'
|
|
325
|
+
AND req_id = ?`);
|
|
326
|
+
listChangeLogsForRequirementStmt = db.prepare(`SELECT id, req_id, file_path, intent_summary, timestamp
|
|
327
|
+
FROM change_logs
|
|
328
|
+
WHERE req_id = ?
|
|
329
|
+
ORDER BY timestamp DESC, id DESC
|
|
330
|
+
LIMIT ?`);
|
|
331
|
+
insertChangeLogStmt = db.prepare(`INSERT INTO change_logs (req_id, file_path, intent_summary) VALUES (?, ?, ?)`);
|
|
332
|
+
insertMemoryItemStmt = db.prepare(`INSERT INTO memory_items
|
|
333
|
+
(kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash)
|
|
334
|
+
VALUES
|
|
335
|
+
(?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
336
|
+
getMemoryItemByIdStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
337
|
+
FROM memory_items
|
|
338
|
+
WHERE id = ?`);
|
|
339
|
+
getConventionByKeyStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
340
|
+
FROM memory_items
|
|
341
|
+
WHERE kind = 'convention' AND title = ?
|
|
342
|
+
ORDER BY updated_at DESC, id DESC
|
|
343
|
+
LIMIT 1`);
|
|
344
|
+
insertConventionStmt = db.prepare(`INSERT INTO memory_items (kind, title, content, metadata_json, content_hash)
|
|
345
|
+
VALUES ('convention', ?, ?, ?, ?)`);
|
|
346
|
+
updateConventionByIdStmt = db.prepare(`UPDATE memory_items
|
|
347
|
+
SET content = ?, metadata_json = ?, content_hash = ?, updated_at = CURRENT_TIMESTAMP
|
|
348
|
+
WHERE id = ?`);
|
|
349
|
+
listConventionsStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
350
|
+
FROM memory_items
|
|
351
|
+
WHERE kind = 'convention'
|
|
352
|
+
ORDER BY updated_at DESC, id DESC
|
|
353
|
+
LIMIT ?`);
|
|
354
|
+
upsertDecisionStmt = db.prepare(`INSERT INTO memory_items (kind, title, content, metadata_json, content_hash)
|
|
355
|
+
VALUES ('decision', ?, ?, ?, ?)
|
|
356
|
+
ON CONFLICT DO UPDATE SET
|
|
357
|
+
content = excluded.content,
|
|
358
|
+
metadata_json = excluded.metadata_json,
|
|
359
|
+
content_hash = excluded.content_hash,
|
|
360
|
+
updated_at = CURRENT_TIMESTAMP`);
|
|
361
|
+
getDecisionByKeyStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
362
|
+
FROM memory_items
|
|
363
|
+
WHERE kind = 'decision' AND title = ?
|
|
364
|
+
ORDER BY updated_at DESC, id DESC
|
|
365
|
+
LIMIT 1`);
|
|
366
|
+
listCurrentDecisionsStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
367
|
+
FROM memory_items
|
|
368
|
+
WHERE kind = 'decision'
|
|
369
|
+
ORDER BY updated_at DESC, id DESC
|
|
370
|
+
LIMIT ?`);
|
|
371
|
+
getRequirementMemoryItemIdStmt = db.prepare(`SELECT id
|
|
372
|
+
FROM memory_items
|
|
373
|
+
WHERE kind = 'requirement' AND req_id = ?
|
|
374
|
+
ORDER BY id DESC
|
|
375
|
+
LIMIT 1`);
|
|
376
|
+
upsertProjectSummaryStmt = db.prepare(`INSERT INTO memory_items (kind, title, content, metadata_json, content_hash)
|
|
377
|
+
VALUES ('project_summary', 'Project Summary', ?, ?, ?)
|
|
378
|
+
ON CONFLICT DO UPDATE SET
|
|
379
|
+
title = excluded.title,
|
|
380
|
+
content = excluded.content,
|
|
381
|
+
metadata_json = excluded.metadata_json,
|
|
382
|
+
content_hash = excluded.content_hash,
|
|
383
|
+
updated_at = CURRENT_TIMESTAMP`);
|
|
384
|
+
getProjectSummaryStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
385
|
+
FROM memory_items
|
|
386
|
+
WHERE kind = 'project_summary'
|
|
387
|
+
LIMIT 1`);
|
|
388
|
+
getLatestChangeIntentForFileStmt = db.prepare(`SELECT id, kind, title, content, file_path, start_line, end_line, req_id, metadata_json, content_hash, created_at, updated_at
|
|
389
|
+
FROM memory_items
|
|
390
|
+
WHERE kind = 'change_intent' AND file_path = ?
|
|
391
|
+
ORDER BY updated_at DESC, id DESC
|
|
392
|
+
LIMIT 1`);
|
|
393
|
+
deleteFileChunkItemsStmt = db.prepare(`DELETE FROM memory_items
|
|
394
|
+
WHERE file_path = ?
|
|
395
|
+
AND (kind = 'code_chunk' OR kind = 'doc_chunk')`);
|
|
396
|
+
upsertPendingChangeStmt = db.prepare(`INSERT INTO pending_changes (file_path, last_event)
|
|
397
|
+
VALUES (?, ?)
|
|
398
|
+
ON CONFLICT(file_path) DO UPDATE SET
|
|
399
|
+
last_event = excluded.last_event,
|
|
400
|
+
updated_at = CURRENT_TIMESTAMP`);
|
|
401
|
+
listPendingChangesStmt = db.prepare(`SELECT file_path, last_event, updated_at
|
|
402
|
+
FROM pending_changes
|
|
403
|
+
ORDER BY updated_at DESC`);
|
|
404
|
+
countPendingChangesStmt = db.prepare(`SELECT COUNT(*) as total FROM pending_changes`);
|
|
405
|
+
deletePendingChangeStmt = db.prepare(`DELETE FROM pending_changes WHERE file_path = ?`);
|
|
406
|
+
deleteAllPendingChangesStmt = db.prepare(`DELETE FROM pending_changes`);
|
|
407
|
+
deleteOldPendingChangesStmt = db.prepare(`DELETE FROM pending_changes WHERE updated_at < datetime('now', ?)`);
|
|
408
|
+
deleteOldestPendingChangesStmt = db.prepare(`DELETE FROM pending_changes
|
|
409
|
+
WHERE file_path IN (
|
|
410
|
+
SELECT file_path FROM pending_changes
|
|
411
|
+
ORDER BY updated_at ASC
|
|
412
|
+
LIMIT ?
|
|
413
|
+
)`);
|
|
414
|
+
deleteSymbolsForFileStmt = db.prepare(`DELETE FROM symbols WHERE file_path = ?`);
|
|
415
|
+
upsertSymbolStmt = db.prepare(`INSERT OR REPLACE INTO symbols (name, type, file_path, signature) VALUES (?, ?, ?, ?)`);
|
|
416
|
+
searchSymbolsStmt = db.prepare(`SELECT name, type, file_path, signature
|
|
417
|
+
FROM symbols
|
|
418
|
+
WHERE name LIKE ? ESCAPE '\\'
|
|
419
|
+
OR signature LIKE ? ESCAPE '\\'
|
|
420
|
+
ORDER BY
|
|
421
|
+
CASE
|
|
422
|
+
WHEN name = ? THEN 0
|
|
423
|
+
WHEN name LIKE ? ESCAPE '\\' THEN 1
|
|
424
|
+
ELSE 2
|
|
425
|
+
END,
|
|
426
|
+
name
|
|
427
|
+
LIMIT ?`);
|
|
428
|
+
insertTokenSavingsStmt = db.prepare(`INSERT INTO token_savings (tool, raw_tokens, output_tokens, saved_tokens, savings_pct)
|
|
429
|
+
VALUES (?, ?, ?, ?, ?)`);
|
|
430
|
+
summarizeTokenSavingsStmt = db.prepare(`SELECT
|
|
431
|
+
COUNT(*) as calls,
|
|
432
|
+
COALESCE(SUM(raw_tokens), 0) as raw_tokens,
|
|
433
|
+
COALESCE(SUM(output_tokens), 0) as output_tokens,
|
|
434
|
+
COALESCE(SUM(saved_tokens), 0) as saved_tokens,
|
|
435
|
+
COALESCE(AVG(savings_pct), 0) as avg_savings_pct
|
|
436
|
+
FROM token_savings`);
|
|
437
|
+
summarizeTokenSavingsByToolStmt = db.prepare(`SELECT
|
|
438
|
+
tool,
|
|
439
|
+
COUNT(*) as calls,
|
|
440
|
+
COALESCE(SUM(raw_tokens), 0) as raw_tokens,
|
|
441
|
+
COALESCE(SUM(output_tokens), 0) as output_tokens,
|
|
442
|
+
COALESCE(SUM(saved_tokens), 0) as saved_tokens,
|
|
443
|
+
COALESCE(AVG(savings_pct), 0) as avg_savings_pct
|
|
444
|
+
FROM token_savings
|
|
445
|
+
GROUP BY tool
|
|
446
|
+
ORDER BY saved_tokens DESC, calls DESC
|
|
447
|
+
LIMIT ?`);
|
|
448
|
+
listRecentTokenSavingsStmt = db.prepare(`SELECT id, tool, raw_tokens, output_tokens, saved_tokens, savings_pct, created_at
|
|
449
|
+
FROM token_savings
|
|
450
|
+
ORDER BY created_at DESC, id DESC
|
|
451
|
+
LIMIT ?`);
|
|
452
|
+
getKvStmt = db.prepare(`SELECT value FROM meta_kv WHERE key = ?`);
|
|
453
|
+
setKvStmt = db.prepare(`INSERT INTO meta_kv (key, value)
|
|
454
|
+
VALUES (?, ?)
|
|
455
|
+
ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP`);
|
|
456
|
+
indexFileSymbolsTx = db.transaction((filePath, symbols) => {
|
|
457
|
+
deleteSymbolsForFileStmt.run(filePath);
|
|
458
|
+
for (const s of symbols) {
|
|
459
|
+
upsertSymbolStmt.run(s.name, s.type, filePath, s.signature);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return {
|
|
463
|
+
db,
|
|
464
|
+
dbPath,
|
|
465
|
+
ftsAvailable,
|
|
466
|
+
ftsTableName: FTS_TABLE_NAME,
|
|
467
|
+
indexFileSymbolsTx,
|
|
468
|
+
statements: {
|
|
469
|
+
insertRequirementStmt,
|
|
470
|
+
getActiveRequirementStmt,
|
|
471
|
+
listActiveRequirementsStmt,
|
|
472
|
+
listRecentRequirementsStmt,
|
|
473
|
+
completeAllActiveRequirementsStmt,
|
|
474
|
+
completeRequirementByIdStmt,
|
|
475
|
+
completeAllActiveRequirementMemoryItemsStmt,
|
|
476
|
+
completeRequirementMemoryItemByReqIdStmt,
|
|
477
|
+
listChangeLogsForRequirementStmt,
|
|
478
|
+
insertChangeLogStmt,
|
|
479
|
+
insertMemoryItemStmt,
|
|
480
|
+
getMemoryItemByIdStmt,
|
|
481
|
+
getRequirementMemoryItemIdStmt,
|
|
482
|
+
getConventionByKeyStmt,
|
|
483
|
+
insertConventionStmt,
|
|
484
|
+
updateConventionByIdStmt,
|
|
485
|
+
listConventionsStmt,
|
|
486
|
+
upsertDecisionStmt,
|
|
487
|
+
getDecisionByKeyStmt,
|
|
488
|
+
listCurrentDecisionsStmt,
|
|
489
|
+
upsertProjectSummaryStmt,
|
|
490
|
+
getProjectSummaryStmt,
|
|
491
|
+
getLatestChangeIntentForFileStmt,
|
|
492
|
+
deleteFileChunkItemsStmt,
|
|
493
|
+
upsertPendingChangeStmt,
|
|
494
|
+
listPendingChangesStmt,
|
|
495
|
+
countPendingChangesStmt,
|
|
496
|
+
deletePendingChangeStmt,
|
|
497
|
+
deleteAllPendingChangesStmt,
|
|
498
|
+
deleteOldPendingChangesStmt,
|
|
499
|
+
deleteOldestPendingChangesStmt,
|
|
500
|
+
deleteSymbolsForFileStmt,
|
|
501
|
+
upsertSymbolStmt,
|
|
502
|
+
searchSymbolsStmt,
|
|
503
|
+
insertTokenSavingsStmt,
|
|
504
|
+
summarizeTokenSavingsStmt,
|
|
505
|
+
summarizeTokenSavingsByToolStmt,
|
|
506
|
+
listRecentTokenSavingsStmt,
|
|
507
|
+
getKvStmt,
|
|
508
|
+
setKvStmt,
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
//# sourceMappingURL=database-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-runtime.js","sourceRoot":"","sources":["../src/database-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAsDrD,IAAI,EAAqB,CAAC;AAC1B,IAAI,MAAM,GAAG,EAAE,CAAC;AAChB,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,IAAI,qBAAyC,CAAC;AAC9C,IAAI,wBAA4C,CAAC;AACjD,IAAI,0BAA8C,CAAC;AACnD,IAAI,0BAA8C,CAAC;AACnD,IAAI,iCAAqD,CAAC;AAC1D,IAAI,2BAA+C,CAAC;AACpD,IAAI,2CAA+D,CAAC;AACpE,IAAI,wCAA4D,CAAC;AACjE,IAAI,gCAAoD,CAAC;AACzD,IAAI,mBAAuC,CAAC;AAC5C,IAAI,oBAAwC,CAAC;AAC7C,IAAI,qBAAyC,CAAC;AAC9C,IAAI,8BAAkD,CAAC;AACvD,IAAI,sBAA0C,CAAC;AAC/C,IAAI,oBAAwC,CAAC;AAC7C,IAAI,wBAA4C,CAAC;AACjD,IAAI,mBAA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C1B,iCAAiC;YACjC,2BAA2B;YAC3B,2CAA2C;YAC3C,wCAAwC;YACxC,gCAAgC;YAChC,mBAAmB;YACnB,oBAAoB;YACpB,qBAAqB;YACrB,8BAA8B;YAC9B,sBAAsB;YACtB,oBAAoB;YACpB,wBAAwB;YACxB,mBAAmB;YACnB,kBAAkB;YAClB,oBAAoB;YACpB,wBAAwB;YACxB,wBAAwB;YACxB,qBAAqB;YACrB,gCAAgC;YAChC,wBAAwB;YACxB,uBAAuB;YACvB,sBAAsB;YACtB,uBAAuB;YACvB,uBAAuB;YACvB,2BAA2B;YAC3B,2BAA2B;YAC3B,8BAA8B;YAC9B,wBAAwB;YACxB,gBAAgB;YAChB,iBAAiB;YACjB,sBAAsB;YACtB,yBAAyB;YACzB,+BAA+B;YAC/B,0BAA0B;YAC1B,SAAS;YACT,SAAS;SACR;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import type { MemoryItemRow, RequirementRow } from "./types.js";
|
|
3
|
+
type DevelopmentWarningsContext = {
|
|
4
|
+
getProjectRoot: () => string;
|
|
5
|
+
normalizeToDbPath: (inputPath: string) => string;
|
|
6
|
+
listActiveRequirements: (limit: number) => RequirementRow[];
|
|
7
|
+
getRequirementMemoryItemId: (reqId: number) => {
|
|
8
|
+
id: number;
|
|
9
|
+
} | undefined;
|
|
10
|
+
getMemoryItemById: (id: number) => MemoryItemRow | undefined;
|
|
11
|
+
parseMetadataJson: (raw: string | null | undefined) => Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
export declare function configureDevelopmentWarnings(context: DevelopmentWarningsContext): void;
|
|
14
|
+
type DevelopmentWarning = {
|
|
15
|
+
code: "large_file" | "very_large_file" | "huge_file_modularization_required" | "many_pending_files" | "broad_change_surface" | "unspecified_change_target" | "large_file_read" | "cross_project_path" | "multiple_active_requirements" | "broad_requirement_scope" | "scope_drift" | "scope_contract_missing" | "requirement_mapping_missing";
|
|
16
|
+
severity: "info" | "warning" | "blocker";
|
|
17
|
+
message: string;
|
|
18
|
+
files?: string[];
|
|
19
|
+
details?: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
export type ChangeMode = "feature" | "bugfix" | "refactor" | "mechanical_modularization" | "emergency_hotfix";
|
|
22
|
+
type DevelopmentWarningFileInput = {
|
|
23
|
+
file_path: string;
|
|
24
|
+
last_event?: string;
|
|
25
|
+
event?: string;
|
|
26
|
+
updated_at?: string;
|
|
27
|
+
};
|
|
28
|
+
type RequirementScopeContract = {
|
|
29
|
+
allow_terms: string[];
|
|
30
|
+
deny_terms: string[];
|
|
31
|
+
allowed_paths: string[];
|
|
32
|
+
denied_paths: string[];
|
|
33
|
+
inferred_from: string[];
|
|
34
|
+
};
|
|
35
|
+
type RequirementItem = {
|
|
36
|
+
id: string;
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
type PlannedRequirementChange = {
|
|
40
|
+
file?: string;
|
|
41
|
+
change: string;
|
|
42
|
+
requirement_refs?: string[];
|
|
43
|
+
supporting_change?: boolean;
|
|
44
|
+
change_type?: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function isLikelySourceImplementationFile(filePath: string): boolean;
|
|
47
|
+
export declare function countFileLinesBounded(absPath: string, maxBytes: number): {
|
|
48
|
+
lines: number;
|
|
49
|
+
truncated: boolean;
|
|
50
|
+
} | null;
|
|
51
|
+
export declare function buildCrossProjectPathWarnings(paths: string[] | null | undefined): DevelopmentWarning[];
|
|
52
|
+
export declare function buildFileReadDevelopmentWarnings(filePath: string, absPath: string, stat?: fs.Stats): DevelopmentWarning[];
|
|
53
|
+
export declare function buildMatchedFileDevelopmentWarnings(filePaths: Array<string | null | undefined>): DevelopmentWarning[];
|
|
54
|
+
export declare function buildRequirementStartWarnings(args: {
|
|
55
|
+
title: string;
|
|
56
|
+
background: string;
|
|
57
|
+
close_previous: boolean;
|
|
58
|
+
}): DevelopmentWarning[];
|
|
59
|
+
export declare function normalizeRequirementItems(values: string[] | undefined): RequirementItem[];
|
|
60
|
+
export declare function getRequirementItems(reqId: number): RequirementItem[];
|
|
61
|
+
export declare function buildRequirementMappingWarnings(args: {
|
|
62
|
+
requirement?: RequirementRow;
|
|
63
|
+
requirement_items?: RequirementItem[];
|
|
64
|
+
planned_changes?: PlannedRequirementChange[];
|
|
65
|
+
files: Array<{
|
|
66
|
+
file_path: string;
|
|
67
|
+
}>;
|
|
68
|
+
change_mode: ChangeMode;
|
|
69
|
+
}): DevelopmentWarning[];
|
|
70
|
+
export declare function buildRequirementScopeContract(args: {
|
|
71
|
+
title: string;
|
|
72
|
+
background: string;
|
|
73
|
+
scope_allow?: string[];
|
|
74
|
+
scope_deny?: string[];
|
|
75
|
+
allowed_paths?: string[];
|
|
76
|
+
denied_paths?: string[];
|
|
77
|
+
}): RequirementScopeContract;
|
|
78
|
+
export declare function getRequirementScopeContract(reqId: number): RequirementScopeContract | null;
|
|
79
|
+
export declare function mergeScopeContracts(base: RequirementScopeContract | null | undefined, extra: RequirementScopeContract | null | undefined): RequirementScopeContract | null;
|
|
80
|
+
export declare function buildScopeDriftWarnings(args: {
|
|
81
|
+
requirement?: RequirementRow;
|
|
82
|
+
contract?: RequirementScopeContract | null;
|
|
83
|
+
intent?: string;
|
|
84
|
+
files: Array<{
|
|
85
|
+
file_path: string;
|
|
86
|
+
}>;
|
|
87
|
+
includeMissingContractHint?: boolean;
|
|
88
|
+
}): DevelopmentWarning[];
|
|
89
|
+
export declare function buildDevelopmentWarnings(files: DevelopmentWarningFileInput[], opts?: {
|
|
90
|
+
includeUnspecified?: boolean;
|
|
91
|
+
}): DevelopmentWarning[];
|
|
92
|
+
export declare function isDevelopmentWarningBlockingForChangeMode(warning: DevelopmentWarning, changeMode: ChangeMode): boolean;
|
|
93
|
+
export {};
|