claude-ex 1.2.0 → 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 +175 -31
- package/dist/claude/claudemd.js +94 -33
- package/dist/claude/claudemd.js.map +1 -1
- package/dist/claude/mcp.js +162 -139
- package/dist/claude/mcp.js.map +1 -1
- package/dist/db/schema.js +101 -22
- package/dist/db/schema.js.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer/index.js +39 -24
- package/dist/indexer/index.js.map +1 -1
- package/dist/query/engine.d.ts +2 -0
- package/dist/query/engine.js +740 -137
- package/dist/query/engine.js.map +1 -1
- package/dist/watcher/daemon.js +19 -12
- package/dist/watcher/daemon.js.map +1 -1
- package/package.json +36 -18
package/dist/claude/mcp.js
CHANGED
|
@@ -32,175 +32,190 @@ async function runMcpServer() {
|
|
|
32
32
|
catch (err) {
|
|
33
33
|
process.stderr.write(`[codex-mcp] Watcher failed to start: ${err}\n`);
|
|
34
34
|
}
|
|
35
|
+
// Pre-warm statement cache + SQLite page cache
|
|
36
|
+
try {
|
|
37
|
+
(0, engine_1.getStats)(db);
|
|
38
|
+
(0, engine_1.search)(db, 'a', 1);
|
|
39
|
+
}
|
|
40
|
+
catch { /* warm-up, ignore errors */ }
|
|
35
41
|
const server = new index_js_1.Server({ name: 'claude-ex', version: '1.0.0' }, { capabilities: { tools: {} } });
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
limit: { type: 'number', description: 'Max results (default 15)' },
|
|
47
|
-
},
|
|
48
|
-
required: ['query'],
|
|
42
|
+
// Memoized tool list (allocated once, not per request)
|
|
43
|
+
const TOOL_LIST = [
|
|
44
|
+
{
|
|
45
|
+
name: 'search_code',
|
|
46
|
+
description: 'Search codebase for symbols by name, description, or content. Results ranked by structural importance (PageRank). Faster and more precise than grep for finding the right code.',
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
query: { type: 'string', description: 'Search query (natural language or symbol name)' },
|
|
51
|
+
limit: { type: 'number', description: 'Max results (default 15)' },
|
|
49
52
|
},
|
|
53
|
+
required: ['query'],
|
|
50
54
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
required: ['name'],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'get_symbol',
|
|
58
|
+
description: 'Get complete context for a symbol: its code, what it depends on, what depends on it, co-located symbols. Use before modifying any symbol.',
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: 'object',
|
|
61
|
+
properties: {
|
|
62
|
+
name: { type: 'string', description: 'Symbol name or qualified name (e.g., processPayment or PaymentService.processPayment)' },
|
|
60
63
|
},
|
|
64
|
+
required: ['name'],
|
|
61
65
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
required: ['name'],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'get_callers',
|
|
69
|
+
description: 'Find all callers of a function or method. Use before renaming, changing signatures, or removing functions.',
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
name: { type: 'string', description: 'Function or method name' },
|
|
71
74
|
},
|
|
75
|
+
required: ['name'],
|
|
72
76
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
required: ['file'],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'get_dependents',
|
|
80
|
+
description: 'Find all files transitively affected if a file changes. Use before refactors that change exports or file structure.',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
file: { type: 'string', description: 'File path relative to project root' },
|
|
85
|
+
maxDepth: { type: 'number', description: 'Max traversal depth (default 10)' },
|
|
83
86
|
},
|
|
87
|
+
required: ['file'],
|
|
84
88
|
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
required: ['name'],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'get_dependencies',
|
|
92
|
+
description: 'Find what a symbol depends on (imports, inherited classes, referenced types).',
|
|
93
|
+
inputSchema: {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
name: { type: 'string', description: 'Symbol name' },
|
|
94
97
|
},
|
|
98
|
+
required: ['name'],
|
|
95
99
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'get_architecture',
|
|
103
|
+
description: 'Get project architecture overview: top symbols by importance, module dependency map, language breakdown.',
|
|
104
|
+
inputSchema: {
|
|
105
|
+
type: 'object',
|
|
106
|
+
properties: {
|
|
107
|
+
top: { type: 'number', description: 'Number of top symbols to include (default 20)' },
|
|
104
108
|
},
|
|
105
109
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'get_file_map',
|
|
113
|
+
description: 'Get a map of every file in the project with its exported symbols. Use to understand where things live without searching. Returns file paths with their key exports.',
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'find_files',
|
|
121
|
+
description: 'Find files by path pattern using glob syntax (e.g. "**/*.test.ts", "src/components/*", "*.json"). Faster than shell find/ls commands. Searches indexed files only.',
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: 'object',
|
|
124
|
+
properties: {
|
|
125
|
+
pattern: { type: 'string', description: 'Glob pattern to match file paths (e.g. "**/*.ts", "src/**/*.test.*", "*.json")' },
|
|
126
|
+
limit: { type: 'number', description: 'Max results (default 50)' },
|
|
112
127
|
},
|
|
128
|
+
required: ['pattern'],
|
|
113
129
|
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
required: ['pattern'],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'get_file_symbols',
|
|
133
|
+
description: 'Get all symbols (functions, classes, variables, etc.) in a specific file. Shows every definition with its kind, line range, signature, and parameters.',
|
|
134
|
+
inputSchema: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
file: { type: 'string', description: 'File path relative to project root' },
|
|
124
138
|
},
|
|
139
|
+
required: ['file'],
|
|
125
140
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
},
|
|
134
|
-
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'find_by_kind',
|
|
144
|
+
description: 'Find all symbols of a specific kind (class, function, interface, type, enum, method, variable). Ranked by structural importance.',
|
|
145
|
+
inputSchema: {
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: {
|
|
148
|
+
kind: { type: 'string', description: 'Symbol kind: class, function, interface, type, enum, method, variable, reexport' },
|
|
149
|
+
limit: { type: 'number', description: 'Max results (default 50)' },
|
|
135
150
|
},
|
|
151
|
+
required: ['kind'],
|
|
136
152
|
},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
},
|
|
146
|
-
required: ['kind'],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'get_type_hierarchy',
|
|
156
|
+
description: 'Find all classes that extend or implement a given class/interface. Use before changing a base class or interface to find all affected subclasses/implementors.',
|
|
157
|
+
inputSchema: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: {
|
|
160
|
+
name: { type: 'string', description: 'Class or interface name to find subclasses/implementors of' },
|
|
147
161
|
},
|
|
162
|
+
required: ['name'],
|
|
148
163
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
},
|
|
157
|
-
required: ['name'],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'find_dead_exports',
|
|
167
|
+
description: 'Find exported symbols that nothing imports or references. Useful for dead code detection and cleanup.',
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: 'object',
|
|
170
|
+
properties: {
|
|
171
|
+
limit: { type: 'number', description: 'Max results (default 50)' },
|
|
158
172
|
},
|
|
159
173
|
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'get_pkg_usages',
|
|
177
|
+
description: 'Find all files that import from a given npm/pip/cargo package. Use before swapping a library to find every usage point. Example: "react", "lodash", "express".',
|
|
178
|
+
inputSchema: {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: {
|
|
181
|
+
package: { type: 'string', description: 'Package name (e.g., "react", "lodash", "express")' },
|
|
168
182
|
},
|
|
183
|
+
required: ['package'],
|
|
169
184
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
},
|
|
178
|
-
required: ['package'],
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'reindex_file',
|
|
188
|
+
description: 'Re-index a single file immediately.',
|
|
189
|
+
inputSchema: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: {
|
|
192
|
+
file: { type: 'string', description: 'File path relative to project root' },
|
|
179
193
|
},
|
|
194
|
+
required: ['file'],
|
|
180
195
|
},
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
},
|
|
189
|
-
required: ['file'],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: 'review_diff',
|
|
199
|
+
description: 'Gather graph-aware review context for a git diff. Parses the diff, maps changed lines to symbols, finds callers/dependents of changed code, computes cross-file impact, and flags risks. Returns structured context for writing a codebase-aware code review.',
|
|
200
|
+
inputSchema: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
properties: {
|
|
203
|
+
target: { type: 'string', description: 'What to review: "last_commit" (default), "staged", "branch" (diff vs main/master), or a commit SHA' },
|
|
190
204
|
},
|
|
191
205
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
},
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: 'transparent_review',
|
|
209
|
+
description: 'Zero-black-box code review. Shows EXACT before/after code for every changed symbol, plain-English explanation of what each change does (parameter changes, new branches, error handling, async changes), who calls the changed code and how they are affected, full blast radius grouped by depth, and risk assessment. Returns a readable narrative — not raw JSON. Use this when you want to truly understand a diff, not just see metadata about it.',
|
|
210
|
+
inputSchema: {
|
|
211
|
+
type: 'object',
|
|
212
|
+
properties: {
|
|
213
|
+
target: { type: 'string', description: 'What to review: "last_commit" (default), "staged", "branch" (diff vs main/master), or a commit SHA' },
|
|
200
214
|
},
|
|
201
215
|
},
|
|
202
|
-
|
|
203
|
-
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({ tools: TOOL_LIST }));
|
|
204
219
|
// Handle tool calls
|
|
205
220
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
206
221
|
const { name, arguments: args } = request.params;
|
|
@@ -263,6 +278,14 @@ async function runMcpServer() {
|
|
|
263
278
|
case 'review_diff':
|
|
264
279
|
result = (0, engine_1.reviewDiff)(db, rootDir, args?.target || 'last_commit');
|
|
265
280
|
break;
|
|
281
|
+
case 'transparent_review': {
|
|
282
|
+
const narrative = (0, engine_1.transparentReview)(db, rootDir, args?.target || 'last_commit');
|
|
283
|
+
const elapsed2 = (performance.now() - callStart).toFixed(1);
|
|
284
|
+
process.stderr.write(`[codex-mcp] transparent_review completed in ${elapsed2}ms\n`);
|
|
285
|
+
return {
|
|
286
|
+
content: [{ type: 'text', text: narrative }],
|
|
287
|
+
};
|
|
288
|
+
}
|
|
266
289
|
default:
|
|
267
290
|
return {
|
|
268
291
|
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
|
@@ -274,7 +297,7 @@ async function runMcpServer() {
|
|
|
274
297
|
return {
|
|
275
298
|
content: [{
|
|
276
299
|
type: 'text',
|
|
277
|
-
text: JSON.stringify(result
|
|
300
|
+
text: JSON.stringify(result),
|
|
278
301
|
}],
|
|
279
302
|
};
|
|
280
303
|
}
|
package/dist/claude/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/claude/mcp.ts"],"names":[],"mappings":";;AAiBA,
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/claude/mcp.ts"],"names":[],"mappings":";;AAiBA,oCAqUC;AAtVD,wEAAmE;AACnE,wEAAiF;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;QAClB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACvD,IAAI,OAAO;YAAE,OAAO,CAAC,KAAK,EAAE,CAAC;QAC7B,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/db/schema.js
CHANGED
|
@@ -48,6 +48,7 @@ exports.removeStaleFiles = removeStaleFiles;
|
|
|
48
48
|
exports.removeFile = removeFile;
|
|
49
49
|
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
50
50
|
const path = __importStar(require("path"));
|
|
51
|
+
const fs = __importStar(require("fs"));
|
|
51
52
|
const utils_1 = require("../utils");
|
|
52
53
|
const SCHEMA_SQL = `
|
|
53
54
|
CREATE TABLE IF NOT EXISTS files (
|
|
@@ -116,18 +117,31 @@ const FTS_SQL = `
|
|
|
116
117
|
CREATE VIRTUAL TABLE IF NOT EXISTS symbols_fts USING fts5(
|
|
117
118
|
name, qualified_name, signature, docstring, content,
|
|
118
119
|
content='symbols', content_rowid='id',
|
|
119
|
-
tokenize='porter unicode61'
|
|
120
|
+
tokenize='porter unicode61',
|
|
121
|
+
prefix='2 4'
|
|
122
|
+
);
|
|
123
|
+
`;
|
|
124
|
+
const TRIGRAM_SQL = `
|
|
125
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS symbols_trigram USING fts5(
|
|
126
|
+
name, qualified_name, signature,
|
|
127
|
+
content='symbols', content_rowid='id',
|
|
128
|
+
tokenize='trigram',
|
|
129
|
+
detail='none'
|
|
120
130
|
);
|
|
121
131
|
`;
|
|
122
132
|
const TRIGGERS_SQL = `
|
|
123
133
|
CREATE TRIGGER IF NOT EXISTS symbols_ai AFTER INSERT ON symbols BEGIN
|
|
124
134
|
INSERT INTO symbols_fts(rowid, name, qualified_name, signature, docstring, content)
|
|
125
135
|
VALUES (new.id, new.name, new.qualified_name, new.signature, new.docstring, new.content);
|
|
136
|
+
INSERT INTO symbols_trigram(rowid, name, qualified_name, signature)
|
|
137
|
+
VALUES (new.id, new.name, new.qualified_name, new.signature);
|
|
126
138
|
END;
|
|
127
139
|
|
|
128
140
|
CREATE TRIGGER IF NOT EXISTS symbols_ad AFTER DELETE ON symbols BEGIN
|
|
129
141
|
INSERT INTO symbols_fts(symbols_fts, rowid, name, qualified_name, signature, docstring, content)
|
|
130
142
|
VALUES('delete', old.id, old.name, old.qualified_name, old.signature, old.docstring, old.content);
|
|
143
|
+
INSERT INTO symbols_trigram(symbols_trigram, rowid, name, qualified_name, signature)
|
|
144
|
+
VALUES('delete', old.id, old.name, old.qualified_name, old.signature);
|
|
131
145
|
END;
|
|
132
146
|
|
|
133
147
|
CREATE TRIGGER IF NOT EXISTS symbols_au AFTER UPDATE ON symbols BEGIN
|
|
@@ -135,6 +149,10 @@ CREATE TRIGGER IF NOT EXISTS symbols_au AFTER UPDATE ON symbols BEGIN
|
|
|
135
149
|
VALUES('delete', old.id, old.name, old.qualified_name, old.signature, old.docstring, old.content);
|
|
136
150
|
INSERT INTO symbols_fts(rowid, name, qualified_name, signature, docstring, content)
|
|
137
151
|
VALUES (new.id, new.name, new.qualified_name, new.signature, new.docstring, new.content);
|
|
152
|
+
INSERT INTO symbols_trigram(symbols_trigram, rowid, name, qualified_name, signature)
|
|
153
|
+
VALUES('delete', old.id, old.name, old.qualified_name, old.signature);
|
|
154
|
+
INSERT INTO symbols_trigram(rowid, name, qualified_name, signature)
|
|
155
|
+
VALUES (new.id, new.name, new.qualified_name, new.signature);
|
|
138
156
|
END;
|
|
139
157
|
`;
|
|
140
158
|
const INDEXES_SQL = `
|
|
@@ -152,6 +170,11 @@ CREATE INDEX IF NOT EXISTS idx_pkg_deps_package ON pkg_deps(package);
|
|
|
152
170
|
CREATE INDEX IF NOT EXISTS idx_pkg_deps_file ON pkg_deps(file_id);
|
|
153
171
|
CREATE INDEX IF NOT EXISTS idx_type_relations_parent ON type_relations(parent_name);
|
|
154
172
|
CREATE INDEX IF NOT EXISTS idx_type_relations_child ON type_relations(child_id);
|
|
173
|
+
CREATE INDEX IF NOT EXISTS idx_files_path ON files(path);
|
|
174
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_file_line ON symbols(file_id, line_start);
|
|
175
|
+
CREATE INDEX IF NOT EXISTS idx_file_deps_to_from ON file_deps(to_file, from_file);
|
|
176
|
+
CREATE INDEX IF NOT EXISTS idx_symbols_exported_kind ON symbols(exported, kind);
|
|
177
|
+
CREATE INDEX IF NOT EXISTS idx_rankings_pagerank ON rankings(pagerank DESC);
|
|
155
178
|
`;
|
|
156
179
|
const PRAGMAS = [
|
|
157
180
|
'PRAGMA journal_mode = WAL',
|
|
@@ -164,17 +187,55 @@ const PRAGMAS = [
|
|
|
164
187
|
function openDatabase(projectRoot, work) {
|
|
165
188
|
const codexDir = work !== undefined ? (0, utils_1.ensureCodexDir)(projectRoot, work) : (0, utils_1.ensureCodexDir)(projectRoot);
|
|
166
189
|
const dbPath = path.join(codexDir, 'index.db');
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
190
|
+
function initDb() {
|
|
191
|
+
const db = new better_sqlite3_1.default(dbPath);
|
|
192
|
+
for (const pragma of PRAGMAS) {
|
|
193
|
+
db.pragma(pragma.replace('PRAGMA ', ''));
|
|
194
|
+
}
|
|
195
|
+
db.exec(SCHEMA_SQL);
|
|
196
|
+
db.exec(FTS_SQL);
|
|
197
|
+
db.exec(INDEXES_SQL);
|
|
198
|
+
// Trigram table — may fail on older SQLite without trigram tokenizer
|
|
199
|
+
try {
|
|
200
|
+
db.exec(TRIGRAM_SQL);
|
|
201
|
+
}
|
|
202
|
+
catch { /* trigram tokenizer not available */ }
|
|
203
|
+
// Recreate triggers to include trigram sync (DROP + CREATE is safe)
|
|
204
|
+
db.exec(`
|
|
205
|
+
DROP TRIGGER IF EXISTS symbols_ai;
|
|
206
|
+
DROP TRIGGER IF EXISTS symbols_ad;
|
|
207
|
+
DROP TRIGGER IF EXISTS symbols_au;
|
|
208
|
+
`);
|
|
209
|
+
db.exec(TRIGGERS_SQL);
|
|
210
|
+
// Migrations for existing databases
|
|
211
|
+
migrateSchema(db);
|
|
212
|
+
return db;
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
return initDb();
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
const code = err.code ?? '';
|
|
219
|
+
if (code.startsWith('SQLITE_CORRUPT')) {
|
|
220
|
+
// Database is corrupted — delete and recreate from scratch
|
|
221
|
+
try {
|
|
222
|
+
fs.unlinkSync(dbPath);
|
|
223
|
+
}
|
|
224
|
+
catch { /* already gone */ }
|
|
225
|
+
// Also remove WAL/SHM sidecar files
|
|
226
|
+
try {
|
|
227
|
+
fs.unlinkSync(dbPath + '-wal');
|
|
228
|
+
}
|
|
229
|
+
catch { /* ok */ }
|
|
230
|
+
try {
|
|
231
|
+
fs.unlinkSync(dbPath + '-shm');
|
|
232
|
+
}
|
|
233
|
+
catch { /* ok */ }
|
|
234
|
+
process.stderr.write(`Warning: corrupted index database deleted, rebuilding...\n`);
|
|
235
|
+
return initDb();
|
|
236
|
+
}
|
|
237
|
+
throw err;
|
|
170
238
|
}
|
|
171
|
-
db.exec(SCHEMA_SQL);
|
|
172
|
-
db.exec(FTS_SQL);
|
|
173
|
-
db.exec(TRIGGERS_SQL);
|
|
174
|
-
db.exec(INDEXES_SQL);
|
|
175
|
-
// Migrations for existing databases
|
|
176
|
-
migrateSchema(db);
|
|
177
|
-
return db;
|
|
178
239
|
}
|
|
179
240
|
function migrateSchema(db) {
|
|
180
241
|
// Add columns that may not exist in older databases
|
|
@@ -215,31 +276,49 @@ function getOrCreateFile(db, filePath, hash, language, lineCount, lastModified)
|
|
|
215
276
|
const result = insert.run(filePath, hash, language, lineCount, lastModified || Date.now(), Date.now());
|
|
216
277
|
return { id: Number(result.lastInsertRowid), changed: true };
|
|
217
278
|
}
|
|
279
|
+
const clearStmts = new WeakMap();
|
|
218
280
|
function clearFileData(db, fileId) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
281
|
+
let stmts = clearStmts.get(db);
|
|
282
|
+
if (!stmts) {
|
|
283
|
+
stmts = [
|
|
284
|
+
db.prepare('DELETE FROM rankings WHERE symbol_id IN (SELECT id FROM symbols WHERE file_id = ?)'),
|
|
285
|
+
db.prepare('DELETE FROM type_relations WHERE child_id IN (SELECT id FROM symbols WHERE file_id = ?)'),
|
|
286
|
+
db.prepare('DELETE FROM edges WHERE from_id IN (SELECT id FROM symbols WHERE file_id = ?) OR to_id IN (SELECT id FROM symbols WHERE file_id = ?)'),
|
|
287
|
+
db.prepare('DELETE FROM symbols WHERE file_id = ?'),
|
|
288
|
+
db.prepare('DELETE FROM file_deps WHERE from_file = ?'),
|
|
289
|
+
db.prepare('DELETE FROM pkg_deps WHERE file_id = ?'),
|
|
290
|
+
];
|
|
291
|
+
clearStmts.set(db, stmts);
|
|
292
|
+
}
|
|
293
|
+
stmts[0].run(fileId);
|
|
294
|
+
stmts[1].run(fileId);
|
|
295
|
+
stmts[2].run(fileId, fileId);
|
|
296
|
+
stmts[3].run(fileId);
|
|
297
|
+
stmts[4].run(fileId);
|
|
298
|
+
stmts[5].run(fileId);
|
|
225
299
|
}
|
|
300
|
+
const insertSymbolStmt = new WeakMap();
|
|
226
301
|
function insertSymbol(db, fileId, sym) {
|
|
227
|
-
const stmt = db
|
|
302
|
+
const stmt = getOrPrepare(insertSymbolStmt, db, `INSERT INTO symbols (name, qualified_name, kind, file_id, line_start, line_end, signature, docstring, content, content_hash, exported, parameters)
|
|
228
303
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
229
304
|
const result = stmt.run(sym.name, sym.qualifiedName || null, sym.kind, fileId, sym.lineStart, sym.lineEnd, sym.signature || null, sym.docstring || null, sym.content || null, sym.contentHash || null, sym.exported ? 1 : 0, sym.parameters || null);
|
|
230
305
|
return Number(result.lastInsertRowid);
|
|
231
306
|
}
|
|
307
|
+
const insertEdgeStmt = new WeakMap();
|
|
232
308
|
function insertEdge(db, fromId, toId, kind, line) {
|
|
233
|
-
db
|
|
309
|
+
getOrPrepare(insertEdgeStmt, db, 'INSERT OR IGNORE INTO edges (from_id, to_id, kind, line) VALUES (?, ?, ?, ?)').run(fromId, toId, kind, line || null);
|
|
234
310
|
}
|
|
311
|
+
const insertPkgDepStmt = new WeakMap();
|
|
235
312
|
function insertPkgDep(db, fileId, packageName, importedNames) {
|
|
236
|
-
db
|
|
313
|
+
getOrPrepare(insertPkgDepStmt, db, 'INSERT OR IGNORE INTO pkg_deps (file_id, package, imported_names) VALUES (?, ?, ?)').run(fileId, packageName, importedNames);
|
|
237
314
|
}
|
|
315
|
+
const insertTypeRelationStmt = new WeakMap();
|
|
238
316
|
function insertTypeRelation(db, childId, parentName, kind) {
|
|
239
|
-
db
|
|
317
|
+
getOrPrepare(insertTypeRelationStmt, db, 'INSERT OR IGNORE INTO type_relations (child_id, parent_name, kind) VALUES (?, ?, ?)').run(childId, parentName, kind);
|
|
240
318
|
}
|
|
319
|
+
const insertFileDepStmt = new WeakMap();
|
|
241
320
|
function insertFileDep(db, fromFile, toFile, kind, importName) {
|
|
242
|
-
db
|
|
321
|
+
getOrPrepare(insertFileDepStmt, db, 'INSERT OR IGNORE INTO file_deps (from_file, to_file, kind, import_name) VALUES (?, ?, ?, ?)').run(fromFile, toFile, kind, importName);
|
|
243
322
|
}
|
|
244
323
|
function removeStaleFiles(db, validPaths) {
|
|
245
324
|
const allFiles = db.prepare('SELECT id, path FROM files').all();
|
package/dist/db/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/sch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