remimem 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +213 -2
- package/dist/chunker/index.js +129 -0
- package/dist/cli/commands.js +256 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/program.js +206 -0
- package/dist/config/index.js +108 -0
- package/dist/embedder/index.js +196 -0
- package/dist/errors.js +15 -0
- package/dist/graph/describe.js +90 -0
- package/dist/graph/index.js +224 -0
- package/dist/indexer/index.js +183 -0
- package/dist/indexer/overview.js +75 -0
- package/dist/indexer/watch.js +55 -0
- package/dist/log.js +16 -0
- package/dist/mcp/server.js +68 -0
- package/dist/mcp/tools.js +272 -0
- package/dist/memory/index.js +259 -0
- package/dist/packer/index.js +149 -0
- package/dist/parser/index.js +294 -0
- package/dist/retriever/index.js +186 -0
- package/dist/scanner/index.js +129 -0
- package/dist/stats/index.js +32 -0
- package/dist/store/fts.js +26 -0
- package/dist/store/index.js +633 -0
- package/dist/tokens.js +8 -0
- package/grammars/README.md +15 -0
- package/grammars/ecma.scm +42 -0
- package/grammars/go.scm +37 -0
- package/grammars/go.wasm +0 -0
- package/grammars/javascript.scm +6 -0
- package/grammars/javascript.wasm +0 -0
- package/grammars/python.scm +21 -0
- package/grammars/python.wasm +0 -0
- package/grammars/tsx.wasm +0 -0
- package/grammars/typescript.scm +20 -0
- package/grammars/typescript.wasm +0 -0
- package/package.json +69 -4
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import * as sqliteVec from 'sqlite-vec';
|
|
3
|
+
import { StoreError } from '../errors.js';
|
|
4
|
+
import { expandForIndex } from './fts.js';
|
|
5
|
+
/** One entry per schema version. Never edit an entry that has shipped; append a new one. */
|
|
6
|
+
const MIGRATIONS = [
|
|
7
|
+
`
|
|
8
|
+
CREATE TABLE files (
|
|
9
|
+
id INTEGER PRIMARY KEY,
|
|
10
|
+
path TEXT NOT NULL UNIQUE,
|
|
11
|
+
language TEXT,
|
|
12
|
+
content_hash TEXT NOT NULL,
|
|
13
|
+
size_bytes INTEGER NOT NULL,
|
|
14
|
+
indexed_at INTEGER NOT NULL
|
|
15
|
+
);
|
|
16
|
+
CREATE TABLE symbols (
|
|
17
|
+
id INTEGER PRIMARY KEY,
|
|
18
|
+
file_id INTEGER NOT NULL REFERENCES files(id) ON DELETE CASCADE,
|
|
19
|
+
name TEXT NOT NULL,
|
|
20
|
+
qualified_name TEXT NOT NULL,
|
|
21
|
+
kind TEXT NOT NULL,
|
|
22
|
+
signature TEXT NOT NULL,
|
|
23
|
+
docstring TEXT NOT NULL,
|
|
24
|
+
start_line INTEGER NOT NULL,
|
|
25
|
+
end_line INTEGER NOT NULL,
|
|
26
|
+
parent_id INTEGER REFERENCES symbols(id) ON DELETE CASCADE
|
|
27
|
+
);
|
|
28
|
+
CREATE INDEX symbols_file ON symbols(file_id);
|
|
29
|
+
CREATE INDEX symbols_name ON symbols(name);
|
|
30
|
+
CREATE INDEX symbols_qualified_name ON symbols(qualified_name);
|
|
31
|
+
CREATE TABLE chunks (
|
|
32
|
+
id INTEGER PRIMARY KEY,
|
|
33
|
+
file_id INTEGER NOT NULL REFERENCES files(id) ON DELETE CASCADE,
|
|
34
|
+
symbol_id INTEGER REFERENCES symbols(id) ON DELETE CASCADE,
|
|
35
|
+
content TEXT NOT NULL,
|
|
36
|
+
content_hash TEXT NOT NULL,
|
|
37
|
+
token_count INTEGER NOT NULL,
|
|
38
|
+
start_line INTEGER NOT NULL,
|
|
39
|
+
end_line INTEGER NOT NULL
|
|
40
|
+
);
|
|
41
|
+
CREATE INDEX chunks_file ON chunks(file_id);
|
|
42
|
+
CREATE INDEX chunks_symbol ON chunks(symbol_id);
|
|
43
|
+
-- Contentless: the expanded text is only searched, never read back.
|
|
44
|
+
CREATE VIRTUAL TABLE chunks_fts USING fts5(
|
|
45
|
+
content, symbol, path,
|
|
46
|
+
content='', contentless_delete=1,
|
|
47
|
+
tokenize="unicode61 tokenchars '_$'"
|
|
48
|
+
);
|
|
49
|
+
`,
|
|
50
|
+
`
|
|
51
|
+
-- Vectors by hash of the embedded text, so unchanged chunks are never embedded twice.
|
|
52
|
+
CREATE TABLE embedding_cache (
|
|
53
|
+
text_hash TEXT NOT NULL,
|
|
54
|
+
model_id TEXT NOT NULL,
|
|
55
|
+
embedding BLOB NOT NULL,
|
|
56
|
+
PRIMARY KEY (text_hash, model_id)
|
|
57
|
+
) WITHOUT ROWID;
|
|
58
|
+
`,
|
|
59
|
+
`
|
|
60
|
+
-- Mentions of other symbols by name. The graph module fills in the target columns.
|
|
61
|
+
CREATE TABLE refs (
|
|
62
|
+
id INTEGER PRIMARY KEY,
|
|
63
|
+
file_id INTEGER NOT NULL REFERENCES files(id) ON DELETE CASCADE,
|
|
64
|
+
symbol_id INTEGER REFERENCES symbols(id) ON DELETE CASCADE,
|
|
65
|
+
kind TEXT NOT NULL,
|
|
66
|
+
name TEXT NOT NULL,
|
|
67
|
+
receiver TEXT,
|
|
68
|
+
line INTEGER NOT NULL,
|
|
69
|
+
target_symbol_id INTEGER REFERENCES symbols(id) ON DELETE SET NULL,
|
|
70
|
+
confidence TEXT
|
|
71
|
+
);
|
|
72
|
+
CREATE INDEX refs_file ON refs(file_id);
|
|
73
|
+
CREATE INDEX refs_symbol ON refs(symbol_id);
|
|
74
|
+
CREATE INDEX refs_target ON refs(target_symbol_id);
|
|
75
|
+
CREATE TABLE imports (
|
|
76
|
+
id INTEGER PRIMARY KEY,
|
|
77
|
+
file_id INTEGER NOT NULL REFERENCES files(id) ON DELETE CASCADE,
|
|
78
|
+
source TEXT NOT NULL,
|
|
79
|
+
name TEXT NOT NULL,
|
|
80
|
+
local TEXT NOT NULL,
|
|
81
|
+
line INTEGER NOT NULL,
|
|
82
|
+
target_symbol_id INTEGER REFERENCES symbols(id) ON DELETE SET NULL
|
|
83
|
+
);
|
|
84
|
+
CREATE INDEX imports_file ON imports(file_id);
|
|
85
|
+
CREATE INDEX imports_target ON imports(target_symbol_id);
|
|
86
|
+
-- One row per resolved relation between two symbols, derived from refs.
|
|
87
|
+
CREATE TABLE edges (
|
|
88
|
+
src_symbol_id INTEGER NOT NULL REFERENCES symbols(id) ON DELETE CASCADE,
|
|
89
|
+
dst_symbol_id INTEGER NOT NULL REFERENCES symbols(id) ON DELETE CASCADE,
|
|
90
|
+
kind TEXT NOT NULL,
|
|
91
|
+
confidence TEXT NOT NULL,
|
|
92
|
+
PRIMARY KEY (src_symbol_id, dst_symbol_id, kind)
|
|
93
|
+
) WITHOUT ROWID;
|
|
94
|
+
CREATE INDEX edges_dst ON edges(dst_symbol_id);
|
|
95
|
+
`,
|
|
96
|
+
`
|
|
97
|
+
-- Project memory. Text ids, so memories shared through git do not collide.
|
|
98
|
+
CREATE TABLE memories (
|
|
99
|
+
id TEXT PRIMARY KEY,
|
|
100
|
+
kind TEXT NOT NULL,
|
|
101
|
+
text TEXT NOT NULL,
|
|
102
|
+
tags TEXT NOT NULL,
|
|
103
|
+
created_at TEXT NOT NULL,
|
|
104
|
+
updated_at TEXT NOT NULL,
|
|
105
|
+
stale INTEGER NOT NULL DEFAULT 0,
|
|
106
|
+
embedding BLOB,
|
|
107
|
+
embedding_model TEXT
|
|
108
|
+
);
|
|
109
|
+
CREATE TABLE memory_links (
|
|
110
|
+
memory_id TEXT NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
|
|
111
|
+
file_path TEXT NOT NULL,
|
|
112
|
+
symbol_qualified_name TEXT,
|
|
113
|
+
content_hash_at_link TEXT NOT NULL
|
|
114
|
+
);
|
|
115
|
+
CREATE INDEX memory_links_memory ON memory_links(memory_id);
|
|
116
|
+
CREATE INDEX memory_links_path ON memory_links(file_path);
|
|
117
|
+
CREATE VIRTUAL TABLE memories_fts USING fts5(
|
|
118
|
+
text, tags,
|
|
119
|
+
content='', contentless_delete=1,
|
|
120
|
+
tokenize="unicode61 tokenchars '_$'"
|
|
121
|
+
);
|
|
122
|
+
`,
|
|
123
|
+
`
|
|
124
|
+
CREATE TABLE query_log (
|
|
125
|
+
id INTEGER PRIMARY KEY,
|
|
126
|
+
tool TEXT NOT NULL,
|
|
127
|
+
query TEXT NOT NULL,
|
|
128
|
+
tokens_returned INTEGER NOT NULL,
|
|
129
|
+
baseline_tokens_estimate INTEGER NOT NULL,
|
|
130
|
+
latency_ms INTEGER NOT NULL,
|
|
131
|
+
created_at TEXT NOT NULL
|
|
132
|
+
);
|
|
133
|
+
`,
|
|
134
|
+
];
|
|
135
|
+
const SYMBOL_ROW = `
|
|
136
|
+
SELECT s.id, f.path, s.name, s.qualified_name AS qualifiedName, s.kind, s.signature,
|
|
137
|
+
s.docstring, s.start_line AS startLine, s.end_line AS endLine
|
|
138
|
+
FROM symbols s JOIN files f ON f.id = s.file_id`;
|
|
139
|
+
const CHUNK_ROW = `
|
|
140
|
+
SELECT c.id, c.symbol_id AS symbolId, f.path, f.language, c.start_line AS startLine, c.end_line AS endLine,
|
|
141
|
+
c.content, c.token_count AS tokenCount, s.qualified_name AS symbol,
|
|
142
|
+
COALESCE(s.kind, 'window') AS kind, COALESCE(s.signature, '') AS signature,
|
|
143
|
+
COALESCE(s.docstring, '') AS docstring
|
|
144
|
+
FROM chunks c
|
|
145
|
+
JOIN files f ON f.id = c.file_id
|
|
146
|
+
LEFT JOIN symbols s ON s.id = c.symbol_id`;
|
|
147
|
+
/** All SQLite access. No other module writes SQL. */
|
|
148
|
+
export class Store {
|
|
149
|
+
db;
|
|
150
|
+
constructor(path) {
|
|
151
|
+
this.db = new Database(path);
|
|
152
|
+
try {
|
|
153
|
+
sqliteVec.load(this.db);
|
|
154
|
+
}
|
|
155
|
+
catch (cause) {
|
|
156
|
+
this.db.close();
|
|
157
|
+
throw new StoreError('The sqlite-vec extension failed to load; run `remimem doctor`', {
|
|
158
|
+
cause,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
this.db.pragma('journal_mode = WAL');
|
|
162
|
+
this.db.pragma('synchronous = NORMAL');
|
|
163
|
+
this.db.pragma('foreign_keys = ON');
|
|
164
|
+
// The MCP server, `watch`, and the CLI can write to the same index: wait instead of failing.
|
|
165
|
+
this.db.pragma('busy_timeout = 5000');
|
|
166
|
+
this.migrate();
|
|
167
|
+
}
|
|
168
|
+
migrate() {
|
|
169
|
+
this.db.exec('CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)');
|
|
170
|
+
const current = Number(this.getMeta('schema_version') ?? 0);
|
|
171
|
+
if (current > MIGRATIONS.length) {
|
|
172
|
+
throw new StoreError(`The index was written by a newer remimem (schema ${current}); upgrade remimem or delete .remimem/index.db and run \`remimem index\``);
|
|
173
|
+
}
|
|
174
|
+
for (let version = current; version < MIGRATIONS.length; version++) {
|
|
175
|
+
this.transaction(() => {
|
|
176
|
+
this.db.exec(MIGRATIONS[version]);
|
|
177
|
+
this.setMeta('schema_version', String(version + 1));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
close() {
|
|
182
|
+
this.db.close();
|
|
183
|
+
}
|
|
184
|
+
transaction(fn) {
|
|
185
|
+
return this.db.transaction(fn)();
|
|
186
|
+
}
|
|
187
|
+
getMeta(key) {
|
|
188
|
+
const row = this.db.prepare('SELECT value FROM meta WHERE key = ?').get(key);
|
|
189
|
+
return row?.value;
|
|
190
|
+
}
|
|
191
|
+
setMeta(key, value) {
|
|
192
|
+
this.db
|
|
193
|
+
.prepare('INSERT INTO meta (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value')
|
|
194
|
+
.run(key, value);
|
|
195
|
+
}
|
|
196
|
+
/** What is known about every indexed file, for deciding whether it changed. */
|
|
197
|
+
fileStates() {
|
|
198
|
+
const rows = this.db
|
|
199
|
+
.prepare('SELECT path, content_hash AS hash, size_bytes AS sizeBytes, indexed_at AS indexedAt FROM files')
|
|
200
|
+
.all();
|
|
201
|
+
return new Map(rows.map(({ path, ...state }) => [path, state]));
|
|
202
|
+
}
|
|
203
|
+
/** Records that a file was looked at and found unchanged. */
|
|
204
|
+
touchFile(path, indexedAt) {
|
|
205
|
+
this.db.prepare('UPDATE files SET indexed_at = ? WHERE path = ?').run(indexedAt, path);
|
|
206
|
+
}
|
|
207
|
+
/** Approximate tokens of each whole file, from its chunks. */
|
|
208
|
+
fileTokens(paths) {
|
|
209
|
+
if (paths.length === 0)
|
|
210
|
+
return 0;
|
|
211
|
+
const row = this.db
|
|
212
|
+
.prepare(`SELECT COALESCE(SUM(c.token_count), 0) AS n FROM chunks c JOIN files f ON f.id = c.file_id
|
|
213
|
+
WHERE f.path IN (${paths.map(() => '?').join(', ')})`)
|
|
214
|
+
.get(...paths);
|
|
215
|
+
return row.n;
|
|
216
|
+
}
|
|
217
|
+
logQuery(entry) {
|
|
218
|
+
this.db
|
|
219
|
+
.prepare('INSERT INTO query_log (tool, query, tokens_returned, baseline_tokens_estimate, latency_ms, created_at) VALUES (?, ?, ?, ?, ?, ?)')
|
|
220
|
+
.run(entry.tool, entry.query, entry.tokensReturned, entry.baselineTokens, entry.latencyMs, new Date().toISOString());
|
|
221
|
+
}
|
|
222
|
+
/** Totals per tool over the whole query log. */
|
|
223
|
+
queryLogSummary() {
|
|
224
|
+
return this.db
|
|
225
|
+
.prepare(`SELECT tool, COUNT(*) AS queries, SUM(tokens_returned) AS tokensReturned,
|
|
226
|
+
SUM(baseline_tokens_estimate) AS baselineTokens, CAST(AVG(latency_ms) AS INTEGER) AS meanLatencyMs,
|
|
227
|
+
MIN(created_at) AS since
|
|
228
|
+
FROM query_log GROUP BY tool ORDER BY queries DESC, tool`)
|
|
229
|
+
.all();
|
|
230
|
+
}
|
|
231
|
+
/** Path to content hash for every indexed file. */
|
|
232
|
+
fileHashes() {
|
|
233
|
+
const rows = this.db.prepare('SELECT path, content_hash AS hash FROM files').all();
|
|
234
|
+
return new Map(rows.map((row) => [row.path, row.hash]));
|
|
235
|
+
}
|
|
236
|
+
counts() {
|
|
237
|
+
return this.db
|
|
238
|
+
.prepare('SELECT (SELECT COUNT(*) FROM files) AS files, (SELECT COUNT(*) FROM symbols) AS symbols, (SELECT COUNT(*) FROM chunks) AS chunks')
|
|
239
|
+
.get();
|
|
240
|
+
}
|
|
241
|
+
/** Removes a file with its symbols, chunks, and search entries. Returns false if unknown. */
|
|
242
|
+
deleteFile(path) {
|
|
243
|
+
const file = this.db.prepare('SELECT id FROM files WHERE path = ?').get(path);
|
|
244
|
+
if (!file)
|
|
245
|
+
return false;
|
|
246
|
+
this.db
|
|
247
|
+
.prepare('DELETE FROM chunks_fts WHERE rowid IN (SELECT id FROM chunks WHERE file_id = ?)')
|
|
248
|
+
.run(file.id);
|
|
249
|
+
if (this.hasVectors()) {
|
|
250
|
+
this.db
|
|
251
|
+
.prepare('DELETE FROM chunk_vectors WHERE chunk_id IN (SELECT id FROM chunks WHERE file_id = ?)')
|
|
252
|
+
.run(file.id);
|
|
253
|
+
}
|
|
254
|
+
this.db.prepare('DELETE FROM files WHERE id = ?').run(file.id); // cascades
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
/** Replaces everything stored for one file. Call inside `transaction`. */
|
|
258
|
+
replaceFile(file, parsed, chunks) {
|
|
259
|
+
const symbols = parsed?.symbols ?? [];
|
|
260
|
+
this.deleteFile(file.path);
|
|
261
|
+
const fileId = this.db
|
|
262
|
+
.prepare('INSERT INTO files (path, language, content_hash, size_bytes, indexed_at) VALUES (?, ?, ?, ?, ?)')
|
|
263
|
+
.run(file.path, file.language, file.contentHash, file.sizeBytes, file.readAt).lastInsertRowid;
|
|
264
|
+
const insertSymbol = this.db.prepare('INSERT INTO symbols (file_id, name, qualified_name, kind, signature, docstring, start_line, end_line) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
|
|
265
|
+
const symbolIds = symbols.map((s) => insertSymbol.run(fileId, s.name, s.qualifiedName, s.kind, s.signature, s.docstring, s.startLine, s.endLine).lastInsertRowid);
|
|
266
|
+
// A parent can come after its child (a Go method declared above its type).
|
|
267
|
+
const setParent = this.db.prepare('UPDATE symbols SET parent_id = ? WHERE id = ?');
|
|
268
|
+
for (const [i, s] of symbols.entries()) {
|
|
269
|
+
if (s.parent !== null)
|
|
270
|
+
setParent.run(symbolIds[s.parent], symbolIds[i]);
|
|
271
|
+
}
|
|
272
|
+
const insertChunk = this.db.prepare('INSERT INTO chunks (file_id, symbol_id, content, content_hash, token_count, start_line, end_line) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
|
273
|
+
const insertFts = this.db.prepare('INSERT INTO chunks_fts (rowid, content, symbol, path) VALUES (?, ?, ?, ?)');
|
|
274
|
+
const pathTerms = expandForIndex(file.path);
|
|
275
|
+
for (const c of chunks) {
|
|
276
|
+
const chunkId = insertChunk.run(fileId, c.symbolIndex === null ? null : symbolIds[c.symbolIndex], c.content, c.contentHash, c.tokenCount, c.startLine, c.endLine).lastInsertRowid;
|
|
277
|
+
insertFts.run(chunkId, expandForIndex(c.content), expandForIndex(c.symbol ?? ''), pathTerms);
|
|
278
|
+
}
|
|
279
|
+
const insertRef = this.db.prepare('INSERT INTO refs (file_id, symbol_id, kind, name, receiver, line) VALUES (?, ?, ?, ?, ?, ?)');
|
|
280
|
+
for (const r of parsed?.refs ?? []) {
|
|
281
|
+
insertRef.run(fileId, r.from === null ? null : symbolIds[r.from], r.kind, r.name, r.receiver, r.line);
|
|
282
|
+
}
|
|
283
|
+
const insertImport = this.db.prepare('INSERT INTO imports (file_id, source, name, local, line) VALUES (?, ?, ?, ?, ?)');
|
|
284
|
+
for (const i of parsed?.imports ?? [])
|
|
285
|
+
insertImport.run(fileId, i.source, i.name, i.local, i.line);
|
|
286
|
+
}
|
|
287
|
+
/** BM25 keyword search. `match` is an FTS5 query; higher scores are better. */
|
|
288
|
+
keywordSearch(match, limit, weights) {
|
|
289
|
+
return this.db
|
|
290
|
+
.prepare('SELECT rowid AS id, -bm25(chunks_fts, ?, ?, ?) AS score FROM chunks_fts WHERE chunks_fts MATCH ? ORDER BY score DESC LIMIT ?')
|
|
291
|
+
.all(weights.content, weights.symbol, weights.path, match, limit);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Chunk ids for symbols whose name or qualified name is one of `names`. A symbol without
|
|
295
|
+
* its own chunk (a constant or a nested function) maps to the chunk that contains it.
|
|
296
|
+
*/
|
|
297
|
+
chunkIdsForSymbols(names) {
|
|
298
|
+
if (names.length === 0)
|
|
299
|
+
return [];
|
|
300
|
+
const marks = names.map(() => '?').join(', ');
|
|
301
|
+
const rows = this.db
|
|
302
|
+
.prepare(`SELECT (
|
|
303
|
+
SELECT c.id FROM chunks c
|
|
304
|
+
WHERE c.file_id = s.file_id AND c.start_line <= s.start_line AND c.end_line >= s.start_line
|
|
305
|
+
ORDER BY c.symbol_id IS s.id DESC, c.end_line - c.start_line, c.id LIMIT 1
|
|
306
|
+
) AS id
|
|
307
|
+
FROM symbols s JOIN files f ON f.id = s.file_id
|
|
308
|
+
WHERE s.name IN (${marks}) OR s.qualified_name IN (${marks})
|
|
309
|
+
ORDER BY f.path, s.start_line`)
|
|
310
|
+
.all(...names, ...names);
|
|
311
|
+
return [...new Set(rows.flatMap((row) => (row.id === null ? [] : [row.id])))];
|
|
312
|
+
}
|
|
313
|
+
/** Loads chunks by id, in the order given. */
|
|
314
|
+
getChunks(ids) {
|
|
315
|
+
if (ids.length === 0)
|
|
316
|
+
return [];
|
|
317
|
+
const rows = this.db
|
|
318
|
+
.prepare(`${CHUNK_ROW} WHERE c.id IN (${ids.map(() => '?').join(', ')})`)
|
|
319
|
+
.all(...ids);
|
|
320
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
321
|
+
return ids.flatMap((id) => byId.get(id) ?? []);
|
|
322
|
+
}
|
|
323
|
+
// Graph. `refs` and `imports` hold what the parser saw; the graph module resolves them
|
|
324
|
+
// and stores the result through `saveResolution`.
|
|
325
|
+
/** Everything the graph module needs to resolve references. */
|
|
326
|
+
graphInput() {
|
|
327
|
+
const all = (sql) => this.db.prepare(sql).all();
|
|
328
|
+
return {
|
|
329
|
+
files: all('SELECT id, path, language FROM files'),
|
|
330
|
+
symbols: all('SELECT id, file_id AS fileId, name, qualified_name AS qualifiedName, kind, parent_id AS parentId FROM symbols'),
|
|
331
|
+
refs: all('SELECT id, file_id AS fileId, symbol_id AS symbolId, kind, name, receiver FROM refs'),
|
|
332
|
+
imports: all('SELECT id, file_id AS fileId, source, name, local FROM imports'),
|
|
333
|
+
goModules: all("SELECT f.path, c.content FROM files f JOIN chunks c ON c.file_id = f.id WHERE (f.path = 'go.mod' OR f.path LIKE '%/go.mod') AND c.start_line = 1").flatMap(({ path, content }) => {
|
|
334
|
+
const module = /^module\s+(\S+)/m.exec(content)?.[1];
|
|
335
|
+
return module ? [{ dir: path.slice(0, -'go.mod'.length).replace(/\/$/, ''), module }] : [];
|
|
336
|
+
}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** Replaces every resolved target and rebuilds `edges` from them. */
|
|
340
|
+
saveResolution(refs, imports) {
|
|
341
|
+
this.transaction(() => {
|
|
342
|
+
this.db.exec('UPDATE refs SET target_symbol_id = NULL, confidence = NULL WHERE target_symbol_id IS NOT NULL');
|
|
343
|
+
this.db.exec('UPDATE imports SET target_symbol_id = NULL WHERE target_symbol_id IS NOT NULL');
|
|
344
|
+
const setRef = this.db.prepare('UPDATE refs SET target_symbol_id = ?, confidence = ? WHERE id = ?');
|
|
345
|
+
for (const r of refs)
|
|
346
|
+
setRef.run(r.target, r.confidence, r.id);
|
|
347
|
+
const setImport = this.db.prepare('UPDATE imports SET target_symbol_id = ? WHERE id = ?');
|
|
348
|
+
for (const i of imports)
|
|
349
|
+
setImport.run(i.target, i.id);
|
|
350
|
+
this.db.exec('DELETE FROM edges');
|
|
351
|
+
// When several references link the same pair, the most certain one names the edge.
|
|
352
|
+
this.db.exec(`
|
|
353
|
+
INSERT INTO edges (src_symbol_id, dst_symbol_id, kind, confidence)
|
|
354
|
+
SELECT symbol_id, target_symbol_id,
|
|
355
|
+
CASE kind WHEN 'call' THEN 'calls' WHEN 'type' THEN 'uses-type' ELSE kind END,
|
|
356
|
+
CASE MIN(CASE confidence WHEN 'exact' THEN 0 WHEN 'import' THEN 1 ELSE 2 END)
|
|
357
|
+
WHEN 0 THEN 'exact' WHEN 1 THEN 'import' ELSE 'name-match' END
|
|
358
|
+
FROM refs
|
|
359
|
+
WHERE symbol_id IS NOT NULL AND target_symbol_id IS NOT NULL AND symbol_id <> target_symbol_id
|
|
360
|
+
GROUP BY 1, 2, 3`);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
edgeCount() {
|
|
364
|
+
return this.db.prepare('SELECT COUNT(*) AS n FROM edges').get().n;
|
|
365
|
+
}
|
|
366
|
+
/** Symbols whose name or qualified name is `name`. */
|
|
367
|
+
symbolsNamed(name) {
|
|
368
|
+
return this.db
|
|
369
|
+
.prepare(`${SYMBOL_ROW} WHERE s.name = ? OR s.qualified_name = ? ORDER BY f.path, s.start_line`)
|
|
370
|
+
.all(name, name);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Direct neighbors of the given symbols: both directions of every edge, plus the
|
|
374
|
+
* enclosing symbol (`inside`) and the enclosed ones (`contains`).
|
|
375
|
+
*/
|
|
376
|
+
neighbors(symbolIds) {
|
|
377
|
+
if (symbolIds.length === 0)
|
|
378
|
+
return [];
|
|
379
|
+
const marks = symbolIds.map(() => '?').join(', ');
|
|
380
|
+
return this.db
|
|
381
|
+
.prepare(`SELECT n.of, n.relation, n.confidence, s.id, f.path, s.name, s.qualified_name AS qualifiedName,
|
|
382
|
+
s.kind, s.signature, s.docstring, s.start_line AS startLine, s.end_line AS endLine
|
|
383
|
+
FROM (
|
|
384
|
+
SELECT src_symbol_id AS of, dst_symbol_id AS other, kind AS relation, confidence
|
|
385
|
+
FROM edges WHERE src_symbol_id IN (${marks})
|
|
386
|
+
UNION ALL
|
|
387
|
+
SELECT dst_symbol_id, src_symbol_id, kind || ' by', confidence
|
|
388
|
+
FROM edges WHERE dst_symbol_id IN (${marks})
|
|
389
|
+
UNION ALL
|
|
390
|
+
SELECT id, parent_id, 'inside', 'exact' FROM symbols
|
|
391
|
+
WHERE id IN (${marks}) AND parent_id IS NOT NULL
|
|
392
|
+
UNION ALL
|
|
393
|
+
SELECT parent_id, id, 'contains', 'exact' FROM symbols WHERE parent_id IN (${marks})
|
|
394
|
+
) n
|
|
395
|
+
JOIN symbols s ON s.id = n.other JOIN files f ON f.id = s.file_id
|
|
396
|
+
ORDER BY n.of, n.relation, f.path, s.start_line`)
|
|
397
|
+
.all(...symbolIds, ...symbolIds, ...symbolIds, ...symbolIds);
|
|
398
|
+
}
|
|
399
|
+
/** The chunk that shows a symbol: its own, or the one containing it. */
|
|
400
|
+
chunkIdForSymbol(symbolId) {
|
|
401
|
+
const row = this.db
|
|
402
|
+
.prepare(`SELECT c.id FROM symbols s JOIN chunks c ON c.file_id = s.file_id
|
|
403
|
+
WHERE s.id = ? AND c.start_line <= s.start_line AND c.end_line >= s.start_line
|
|
404
|
+
ORDER BY c.symbol_id IS s.id DESC, c.end_line - c.start_line, c.id LIMIT 1`)
|
|
405
|
+
.get(symbolId);
|
|
406
|
+
return row?.id;
|
|
407
|
+
}
|
|
408
|
+
/** The symbols of one file in line order, with the id of each one's enclosing symbol. */
|
|
409
|
+
symbolsInFile(path) {
|
|
410
|
+
return this.db
|
|
411
|
+
.prepare(`SELECT s.id, f.path, s.name, s.qualified_name AS qualifiedName, s.kind, s.signature,
|
|
412
|
+
s.docstring, s.start_line AS startLine, s.end_line AS endLine, s.parent_id AS parentId
|
|
413
|
+
FROM symbols s JOIN files f ON f.id = s.file_id WHERE f.path = ? ORDER BY s.start_line, s.id`)
|
|
414
|
+
.all(path);
|
|
415
|
+
}
|
|
416
|
+
fileLanguage(path) {
|
|
417
|
+
const row = this.db.prepare('SELECT language FROM files WHERE path = ?').get(path);
|
|
418
|
+
return row ? row.language : undefined;
|
|
419
|
+
}
|
|
420
|
+
/** Every file path, and every top-level symbol that something refers to. */
|
|
421
|
+
overviewInput() {
|
|
422
|
+
return {
|
|
423
|
+
files: this.db.prepare('SELECT path FROM files').all().map((f) => f.path),
|
|
424
|
+
symbols: this.db
|
|
425
|
+
.prepare(`SELECT f.path, s.qualified_name AS name, COUNT(r.id) AS "references"
|
|
426
|
+
FROM symbols s JOIN files f ON f.id = s.file_id JOIN refs r ON r.target_symbol_id = s.id
|
|
427
|
+
WHERE s.parent_id IS NULL AND s.kind <> 'constant' GROUP BY s.id`)
|
|
428
|
+
.all(),
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
/** How many chunks have a vector. */
|
|
432
|
+
vectorCount() {
|
|
433
|
+
if (!this.hasVectors())
|
|
434
|
+
return 0;
|
|
435
|
+
return this.db.prepare('SELECT COUNT(*) AS n FROM chunk_vectors').get().n;
|
|
436
|
+
}
|
|
437
|
+
/** The chunks that make up a symbol, or the chunk containing it when it has none. */
|
|
438
|
+
chunksOfSymbol(symbolId) {
|
|
439
|
+
const own = this.db
|
|
440
|
+
.prepare(`${CHUNK_ROW} WHERE c.symbol_id = ? ORDER BY c.start_line`)
|
|
441
|
+
.all(symbolId);
|
|
442
|
+
if (own.length > 0)
|
|
443
|
+
return own;
|
|
444
|
+
const containing = this.chunkIdForSymbol(symbolId);
|
|
445
|
+
return containing === undefined ? [] : this.getChunks([containing]);
|
|
446
|
+
}
|
|
447
|
+
/** Every resolved mention of the given symbols, and every import of them. */
|
|
448
|
+
referencesTo(symbolIds) {
|
|
449
|
+
if (symbolIds.length === 0)
|
|
450
|
+
return [];
|
|
451
|
+
const marks = symbolIds.map(() => '?').join(', ');
|
|
452
|
+
return this.db
|
|
453
|
+
.prepare(`SELECT f.path, r.line, r.kind, r.confidence, s.qualified_name AS fromSymbol
|
|
454
|
+
FROM refs r JOIN files f ON f.id = r.file_id LEFT JOIN symbols s ON s.id = r.symbol_id
|
|
455
|
+
WHERE r.target_symbol_id IN (${marks})
|
|
456
|
+
UNION ALL
|
|
457
|
+
SELECT f.path, i.line, 'import', 'import', NULL
|
|
458
|
+
FROM imports i JOIN files f ON f.id = i.file_id WHERE i.target_symbol_id IN (${marks})
|
|
459
|
+
ORDER BY 1, 2`)
|
|
460
|
+
.all(...symbolIds, ...symbolIds);
|
|
461
|
+
}
|
|
462
|
+
// Memory. The memory module owns the rules; these are its storage operations.
|
|
463
|
+
/** Replaces one memory, or adds it. Call inside `transaction`. */
|
|
464
|
+
putMemory(memory) {
|
|
465
|
+
this.deleteMemory(memory.id);
|
|
466
|
+
const { lastInsertRowid } = this.db
|
|
467
|
+
.prepare('INSERT INTO memories (id, kind, text, tags, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)')
|
|
468
|
+
.run(memory.id, memory.kind, memory.text, JSON.stringify(memory.tags), memory.createdAt, memory.updatedAt);
|
|
469
|
+
this.db
|
|
470
|
+
.prepare('INSERT INTO memories_fts (rowid, text, tags) VALUES (?, ?, ?)')
|
|
471
|
+
.run(lastInsertRowid, expandForIndex(memory.text), expandForIndex(memory.tags.join(' ')));
|
|
472
|
+
const link = this.db.prepare('INSERT INTO memory_links (memory_id, file_path, symbol_qualified_name, content_hash_at_link) VALUES (?, ?, ?, ?)');
|
|
473
|
+
for (const l of memory.links)
|
|
474
|
+
link.run(memory.id, l.path, l.symbol, l.contentHash);
|
|
475
|
+
}
|
|
476
|
+
deleteMemory(id) {
|
|
477
|
+
const row = this.db.prepare('SELECT rowid FROM memories WHERE id = ?').get(id);
|
|
478
|
+
if (!row)
|
|
479
|
+
return false;
|
|
480
|
+
this.db.prepare('DELETE FROM memories_fts WHERE rowid = ?').run(row.rowid);
|
|
481
|
+
this.db.prepare('DELETE FROM memories WHERE id = ?').run(id); // links cascade
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
/** Every memory, oldest first (insertion order within a millisecond), optionally of one kind. */
|
|
485
|
+
listMemories(kind) {
|
|
486
|
+
const rows = this.db
|
|
487
|
+
.prepare(`SELECT id, kind, text, tags, created_at AS createdAt, updated_at AS updatedAt, stale
|
|
488
|
+
FROM memories ${kind ? 'WHERE kind = ?' : ''} ORDER BY created_at, rowid`)
|
|
489
|
+
.all(...(kind ? [kind] : []));
|
|
490
|
+
const links = this.db
|
|
491
|
+
.prepare('SELECT memory_id AS id, file_path AS path, symbol_qualified_name AS symbol, content_hash_at_link AS contentHash FROM memory_links ORDER BY rowid')
|
|
492
|
+
.all();
|
|
493
|
+
return rows.map((row) => ({
|
|
494
|
+
...row,
|
|
495
|
+
tags: JSON.parse(row.tags),
|
|
496
|
+
stale: row.stale === 1,
|
|
497
|
+
links: links
|
|
498
|
+
.filter((l) => l.id === row.id)
|
|
499
|
+
.map(({ path, symbol, contentHash }) => ({ path, symbol, contentHash })),
|
|
500
|
+
}));
|
|
501
|
+
}
|
|
502
|
+
setMemoryStale(id, stale) {
|
|
503
|
+
this.db.prepare('UPDATE memories SET stale = ? WHERE id = ?').run(stale ? 1 : 0, id);
|
|
504
|
+
}
|
|
505
|
+
/** Memory ids by BM25 keyword match, best first. */
|
|
506
|
+
memoryKeywordSearch(match, limit) {
|
|
507
|
+
const rows = this.db
|
|
508
|
+
.prepare(`SELECT m.id FROM memories_fts JOIN memories m ON m.rowid = memories_fts.rowid
|
|
509
|
+
WHERE memories_fts MATCH ? ORDER BY bm25(memories_fts) LIMIT ?`)
|
|
510
|
+
.all(match, limit);
|
|
511
|
+
return rows.map((row) => row.id);
|
|
512
|
+
}
|
|
513
|
+
/** The stored vector of every memory; null when it has none from `modelId`. */
|
|
514
|
+
memoryEmbeddings(modelId) {
|
|
515
|
+
const rows = this.db
|
|
516
|
+
.prepare('SELECT id, text, embedding, embedding_model AS model FROM memories')
|
|
517
|
+
.all();
|
|
518
|
+
return rows.map(({ id, text, embedding, model }) => ({
|
|
519
|
+
id,
|
|
520
|
+
text,
|
|
521
|
+
embedding: embedding && model === modelId
|
|
522
|
+
? new Float32Array(embedding.buffer.slice(embedding.byteOffset, embedding.byteOffset + embedding.byteLength))
|
|
523
|
+
: null,
|
|
524
|
+
}));
|
|
525
|
+
}
|
|
526
|
+
setMemoryEmbedding(id, modelId, embedding) {
|
|
527
|
+
this.db
|
|
528
|
+
.prepare('UPDATE memories SET embedding = ?, embedding_model = ? WHERE id = ?')
|
|
529
|
+
.run(Buffer.from(embedding.buffer, embedding.byteOffset, embedding.byteLength), modelId, id);
|
|
530
|
+
}
|
|
531
|
+
/** The symbol with this qualified name in this file. */
|
|
532
|
+
symbolAt(path, qualifiedName) {
|
|
533
|
+
return this.db
|
|
534
|
+
.prepare(`${SYMBOL_ROW} WHERE f.path = ? AND s.qualified_name = ? ORDER BY s.start_line LIMIT 1`)
|
|
535
|
+
.get(path, qualifiedName);
|
|
536
|
+
}
|
|
537
|
+
// Vectors. The `chunk_vectors` table is created on demand because its dimension depends
|
|
538
|
+
// on the embedding model; `meta` records which model filled it.
|
|
539
|
+
hasVectors() {
|
|
540
|
+
return this.getMeta('embedding_dim') !== undefined;
|
|
541
|
+
}
|
|
542
|
+
/** The model that produced the stored vectors, or undefined when there are none. */
|
|
543
|
+
embeddingModel() {
|
|
544
|
+
return this.hasVectors() ? this.getMeta('embedding_model') : undefined;
|
|
545
|
+
}
|
|
546
|
+
/** Forgets every stored vector, for a rebuild with a different model. */
|
|
547
|
+
clearVectors() {
|
|
548
|
+
this.transaction(() => {
|
|
549
|
+
this.db.exec('DROP TABLE IF EXISTS chunk_vectors');
|
|
550
|
+
this.db.prepare("DELETE FROM meta WHERE key IN ('embedding_model', 'embedding_dim')").run();
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
/** Drops every stored vector and prepares the table for `modelId` with `dim` dimensions. */
|
|
554
|
+
resetVectors(modelId, dim) {
|
|
555
|
+
if (!Number.isInteger(dim) || dim <= 0)
|
|
556
|
+
throw new StoreError(`Invalid embedding size: ${dim}`);
|
|
557
|
+
this.transaction(() => {
|
|
558
|
+
this.db.exec('DROP TABLE IF EXISTS chunk_vectors');
|
|
559
|
+
this.db.exec(`CREATE VIRTUAL TABLE chunk_vectors USING vec0(chunk_id INTEGER PRIMARY KEY, embedding float[${dim}] distance_metric=cosine)`);
|
|
560
|
+
this.setMeta('embedding_model', modelId);
|
|
561
|
+
this.setMeta('embedding_dim', String(dim));
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Chunks that have no vector yet, shortest first so batches pad less. `docLines` is how
|
|
566
|
+
* many leading lines of `content` are the doc comment above the symbol.
|
|
567
|
+
*/
|
|
568
|
+
chunksWithoutVectors() {
|
|
569
|
+
const missing = this.hasVectors()
|
|
570
|
+
? 'LEFT JOIN chunk_vectors v ON v.chunk_id = c.id WHERE v.chunk_id IS NULL'
|
|
571
|
+
: '';
|
|
572
|
+
return this.db
|
|
573
|
+
.prepare(`SELECT c.id, f.path, c.content, COALESCE(s.signature, '') AS signature,
|
|
574
|
+
COALESCE(s.docstring, '') AS docstring,
|
|
575
|
+
MAX(0, COALESCE(s.start_line - c.start_line, 0)) AS docLines
|
|
576
|
+
FROM chunks c JOIN files f ON f.id = c.file_id LEFT JOIN symbols s ON s.id = c.symbol_id
|
|
577
|
+
${missing} ORDER BY length(c.content)`)
|
|
578
|
+
.all();
|
|
579
|
+
}
|
|
580
|
+
setVector(chunkId, embedding) {
|
|
581
|
+
this.db
|
|
582
|
+
.prepare('INSERT OR REPLACE INTO chunk_vectors (chunk_id, embedding) VALUES (?, ?)')
|
|
583
|
+
.run(BigInt(chunkId), embedding);
|
|
584
|
+
}
|
|
585
|
+
cachedEmbedding(textHash, modelId) {
|
|
586
|
+
const row = this.db
|
|
587
|
+
.prepare('SELECT embedding FROM embedding_cache WHERE text_hash = ? AND model_id = ?')
|
|
588
|
+
.get(textHash, modelId);
|
|
589
|
+
if (!row)
|
|
590
|
+
return undefined;
|
|
591
|
+
const { buffer, byteOffset, byteLength } = row.embedding;
|
|
592
|
+
return new Float32Array(buffer.slice(byteOffset, byteOffset + byteLength));
|
|
593
|
+
}
|
|
594
|
+
cacheEmbedding(textHash, modelId, embedding) {
|
|
595
|
+
this.db
|
|
596
|
+
.prepare('INSERT OR REPLACE INTO embedding_cache (text_hash, model_id, embedding) VALUES (?, ?, ?)')
|
|
597
|
+
.run(textHash, modelId, Buffer.from(embedding.buffer, embedding.byteOffset, embedding.byteLength));
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Removes cached vectors of other models, and, when `keep` is given, every cached vector
|
|
601
|
+
* whose text hash is not in it. Returns how many rows were removed.
|
|
602
|
+
*/
|
|
603
|
+
pruneEmbeddingCache(modelId, keep) {
|
|
604
|
+
let removed = this.db
|
|
605
|
+
.prepare('DELETE FROM embedding_cache WHERE model_id <> ?')
|
|
606
|
+
.run(modelId).changes;
|
|
607
|
+
if (keep) {
|
|
608
|
+
this.transaction(() => {
|
|
609
|
+
this.db.exec('CREATE TEMP TABLE IF NOT EXISTS keep_hashes (text_hash TEXT PRIMARY KEY)');
|
|
610
|
+
this.db.exec('DELETE FROM keep_hashes');
|
|
611
|
+
const insert = this.db.prepare('INSERT OR IGNORE INTO keep_hashes (text_hash) VALUES (?)');
|
|
612
|
+
for (const hash of keep)
|
|
613
|
+
insert.run(hash);
|
|
614
|
+
removed += this.db
|
|
615
|
+
.prepare('DELETE FROM embedding_cache WHERE text_hash NOT IN (SELECT text_hash FROM keep_hashes)')
|
|
616
|
+
.run().changes;
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
return removed;
|
|
620
|
+
}
|
|
621
|
+
/** How many vectors the embedding cache holds. */
|
|
622
|
+
embeddingCacheSize() {
|
|
623
|
+
return this.db.prepare('SELECT COUNT(*) AS n FROM embedding_cache').get().n;
|
|
624
|
+
}
|
|
625
|
+
/** Nearest chunks by cosine similarity; higher scores are closer. */
|
|
626
|
+
vectorSearch(embedding, limit) {
|
|
627
|
+
if (!this.hasVectors())
|
|
628
|
+
return [];
|
|
629
|
+
return this.db
|
|
630
|
+
.prepare('SELECT chunk_id AS id, 1 - distance AS score FROM chunk_vectors WHERE embedding MATCH ? AND k = ? ORDER BY distance')
|
|
631
|
+
.all(embedding, limit);
|
|
632
|
+
}
|
|
633
|
+
}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tiktoken } from 'js-tiktoken/lite';
|
|
2
|
+
import o200k from 'js-tiktoken/ranks/o200k_base';
|
|
3
|
+
let encoder;
|
|
4
|
+
/** Approximate token count: real models tokenize differently, so treat it as an estimate. */
|
|
5
|
+
export function countTokens(text) {
|
|
6
|
+
encoder ??= new Tiktoken(o200k);
|
|
7
|
+
return encoder.encode(text).length;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Grammars
|
|
2
|
+
|
|
3
|
+
Prebuilt tree-sitter grammars (`.wasm`) and the symbol queries remimem runs on them (`.scm`).
|
|
4
|
+
|
|
5
|
+
| File | Source | Version |
|
|
6
|
+
| ----------------- | ------------------------------------------------------------------------------- | ------- |
|
|
7
|
+
| `typescript.wasm` | [tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript) | v0.23.2 |
|
|
8
|
+
| `tsx.wasm` | [tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript) | v0.23.2 |
|
|
9
|
+
| `javascript.wasm` | [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript) | v0.25.0 |
|
|
10
|
+
| `python.wasm` | [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python) | v0.25.0 |
|
|
11
|
+
| `go.wasm` | [tree-sitter-go](https://github.com/tree-sitter/tree-sitter-go) | v0.25.0 |
|
|
12
|
+
|
|
13
|
+
The `.wasm` files are the unmodified release assets of those projects, which are MIT licensed. To update one, download the `.wasm` asset from the project's GitHub release, replace the file here, update this table, and run `npm test`.
|
|
14
|
+
|
|
15
|
+
Query files: `ecma.scm` is shared by JavaScript, TypeScript, and TSX; `javascript.scm` and `typescript.scm` add the language-specific patterns; `python.scm` and `go.scm` stand alone. Capture names the parser understands: `@def.<kind>` with `@name` and optional `@body` and `@receiver`; `@call` with `@callee` and optional `@recv`; `@import` with `@source` and `@iname`.
|