brainbank 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 +1059 -0
- package/assets/architecture.png +0 -0
- package/bin/brainbank +11 -0
- package/dist/chunk-2P3EGY6S.js +37 -0
- package/dist/chunk-2P3EGY6S.js.map +1 -0
- package/dist/chunk-3GAIDXRW.js +105 -0
- package/dist/chunk-3GAIDXRW.js.map +1 -0
- package/dist/chunk-4ZKBQ33J.js +56 -0
- package/dist/chunk-4ZKBQ33J.js.map +1 -0
- package/dist/chunk-7QVYU63E.js +7 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/chunk-EDKSKLX4.js +490 -0
- package/dist/chunk-EDKSKLX4.js.map +1 -0
- package/dist/chunk-GOUBW7UA.js +373 -0
- package/dist/chunk-GOUBW7UA.js.map +1 -0
- package/dist/chunk-MJ3Y24H6.js +185 -0
- package/dist/chunk-MJ3Y24H6.js.map +1 -0
- package/dist/chunk-N6ZMBFDE.js +224 -0
- package/dist/chunk-N6ZMBFDE.js.map +1 -0
- package/dist/chunk-YGSEUWLV.js +2053 -0
- package/dist/chunk-YGSEUWLV.js.map +1 -0
- package/dist/chunk-Z5SU54HP.js +171 -0
- package/dist/chunk-Z5SU54HP.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +731 -0
- package/dist/cli.js.map +1 -0
- package/dist/code.d.ts +31 -0
- package/dist/code.js +8 -0
- package/dist/code.js.map +1 -0
- package/dist/docs.d.ts +19 -0
- package/dist/docs.js +8 -0
- package/dist/docs.js.map +1 -0
- package/dist/git.d.ts +31 -0
- package/dist/git.js +8 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +845 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +19 -0
- package/dist/memory.js +146 -0
- package/dist/memory.js.map +1 -0
- package/dist/notes.d.ts +19 -0
- package/dist/notes.js +57 -0
- package/dist/notes.js.map +1 -0
- package/dist/openai-PCTYLOWI.js +8 -0
- package/dist/openai-PCTYLOWI.js.map +1 -0
- package/dist/types-Da_zLLOl.d.ts +474 -0
- package/package.json +91 -0
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
import BetterSqlite3 from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BrainBank — Database
|
|
5
|
+
*
|
|
6
|
+
* Thin wrapper over better-sqlite3.
|
|
7
|
+
* Handles WAL mode, directory creation, schema init, and transactions.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare class Database {
|
|
11
|
+
readonly db: BetterSqlite3.Database;
|
|
12
|
+
constructor(dbPath: string);
|
|
13
|
+
/**
|
|
14
|
+
* Run a function inside a transaction.
|
|
15
|
+
* Auto-commits on success, auto-rollbacks on error.
|
|
16
|
+
*/
|
|
17
|
+
transaction<T>(fn: () => T): T;
|
|
18
|
+
/**
|
|
19
|
+
* Run a prepared statement on multiple rows.
|
|
20
|
+
* Wraps in a single transaction for performance.
|
|
21
|
+
*/
|
|
22
|
+
batch<T extends any[]>(sql: string, rows: T[]): void;
|
|
23
|
+
/** Prepare a reusable statement. */
|
|
24
|
+
prepare(sql: string): BetterSqlite3.Statement;
|
|
25
|
+
/** Execute raw SQL (no results). */
|
|
26
|
+
exec(sql: string): void;
|
|
27
|
+
/** Close the database. */
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* BrainBank — Type Definitions
|
|
33
|
+
*
|
|
34
|
+
* All interfaces and types for the semantic knowledge bank.
|
|
35
|
+
*/
|
|
36
|
+
interface BrainBankConfig {
|
|
37
|
+
/** Root path of the repository to index. Default: '.' */
|
|
38
|
+
repoPath?: string;
|
|
39
|
+
/** SQLite database path. Default: '.brainbank/brainbank.db' */
|
|
40
|
+
dbPath?: string;
|
|
41
|
+
/** Max git commits to index. Default: 500 */
|
|
42
|
+
gitDepth?: number;
|
|
43
|
+
/** Max file size in bytes to index. Default: 512_000 (500KB) */
|
|
44
|
+
maxFileSize?: number;
|
|
45
|
+
/** Max diff bytes per commit. Default: 8192 */
|
|
46
|
+
maxDiffBytes?: number;
|
|
47
|
+
/** HNSW M parameter (connections per node). Default: 16 */
|
|
48
|
+
hnswM?: number;
|
|
49
|
+
/** HNSW efConstruction (build-time candidates). Default: 200 */
|
|
50
|
+
hnswEfConstruction?: number;
|
|
51
|
+
/** HNSW efSearch (query-time candidates). Default: 50 */
|
|
52
|
+
hnswEfSearch?: number;
|
|
53
|
+
/** Embedding dimensions. Default: 384 */
|
|
54
|
+
embeddingDims?: number;
|
|
55
|
+
/** Max HNSW elements. Default: 2_000_000 */
|
|
56
|
+
maxElements?: number;
|
|
57
|
+
/** Custom embedding provider (default: local WASM model) */
|
|
58
|
+
embeddingProvider?: EmbeddingProvider;
|
|
59
|
+
/** Optional reranker for improved search quality */
|
|
60
|
+
reranker?: Reranker;
|
|
61
|
+
}
|
|
62
|
+
interface ResolvedConfig {
|
|
63
|
+
repoPath: string;
|
|
64
|
+
dbPath: string;
|
|
65
|
+
gitDepth: number;
|
|
66
|
+
maxFileSize: number;
|
|
67
|
+
maxDiffBytes: number;
|
|
68
|
+
hnswM: number;
|
|
69
|
+
hnswEfConstruction: number;
|
|
70
|
+
hnswEfSearch: number;
|
|
71
|
+
embeddingDims: number;
|
|
72
|
+
maxElements: number;
|
|
73
|
+
embeddingProvider?: EmbeddingProvider;
|
|
74
|
+
reranker?: Reranker;
|
|
75
|
+
}
|
|
76
|
+
interface EmbeddingProvider {
|
|
77
|
+
/** Vector dimensions produced by this provider. */
|
|
78
|
+
readonly dims: number;
|
|
79
|
+
/** Embed a single text string. */
|
|
80
|
+
embed(text: string): Promise<Float32Array>;
|
|
81
|
+
/** Embed multiple texts (batch). */
|
|
82
|
+
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
83
|
+
/** Release resources. */
|
|
84
|
+
close(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
interface Reranker {
|
|
87
|
+
/**
|
|
88
|
+
* Score each document's relevance to the query.
|
|
89
|
+
* @param query - The search query
|
|
90
|
+
* @param documents - Document contents to rank
|
|
91
|
+
* @returns Relevance scores (0.0 - 1.0) in same order as documents
|
|
92
|
+
*/
|
|
93
|
+
rank(query: string, documents: string[]): Promise<number[]>;
|
|
94
|
+
/** Release resources (e.g. unload model). */
|
|
95
|
+
close?(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
interface SearchHit {
|
|
98
|
+
id: number;
|
|
99
|
+
score: number;
|
|
100
|
+
}
|
|
101
|
+
interface VectorIndex {
|
|
102
|
+
/** Initialize the index. Must be called before add/search. */
|
|
103
|
+
init(): Promise<this>;
|
|
104
|
+
/** Add a vector with an integer ID. */
|
|
105
|
+
add(vector: Float32Array, id: number): void;
|
|
106
|
+
/** Search for k nearest neighbors. */
|
|
107
|
+
search(query: Float32Array, k: number): SearchHit[];
|
|
108
|
+
/** Number of vectors in the index. */
|
|
109
|
+
readonly size: number;
|
|
110
|
+
}
|
|
111
|
+
interface CodeChunk {
|
|
112
|
+
/** Auto-incremented DB id (set after insert) */
|
|
113
|
+
id?: number;
|
|
114
|
+
/** Relative file path from repo root */
|
|
115
|
+
filePath: string;
|
|
116
|
+
/** Chunk type: 'file' | 'function' | 'class' | 'block' */
|
|
117
|
+
chunkType: string;
|
|
118
|
+
/** Function/class name (if detected) */
|
|
119
|
+
name?: string;
|
|
120
|
+
/** Start line (1-indexed) */
|
|
121
|
+
startLine: number;
|
|
122
|
+
/** End line (1-indexed, inclusive) */
|
|
123
|
+
endLine: number;
|
|
124
|
+
/** Raw content of the chunk */
|
|
125
|
+
content: string;
|
|
126
|
+
/** Language identifier */
|
|
127
|
+
language: string;
|
|
128
|
+
}
|
|
129
|
+
interface GitCommitRecord {
|
|
130
|
+
id?: number;
|
|
131
|
+
hash: string;
|
|
132
|
+
shortHash: string;
|
|
133
|
+
message: string;
|
|
134
|
+
author: string;
|
|
135
|
+
date: string;
|
|
136
|
+
timestamp: number;
|
|
137
|
+
filesChanged: string[];
|
|
138
|
+
diff?: string;
|
|
139
|
+
additions: number;
|
|
140
|
+
deletions: number;
|
|
141
|
+
isMerge: boolean;
|
|
142
|
+
}
|
|
143
|
+
interface MemoryPattern {
|
|
144
|
+
id?: number;
|
|
145
|
+
/** Category (e.g. 'api', 'refactor', 'debug') */
|
|
146
|
+
taskType: string;
|
|
147
|
+
/** What was the task */
|
|
148
|
+
task: string;
|
|
149
|
+
/** How it was approached */
|
|
150
|
+
approach: string;
|
|
151
|
+
/** What happened */
|
|
152
|
+
outcome?: string;
|
|
153
|
+
/** 0.0 – 1.0 */
|
|
154
|
+
successRate: number;
|
|
155
|
+
/** Lessons learned */
|
|
156
|
+
critique?: string;
|
|
157
|
+
/** Tokens consumed (optional tracking) */
|
|
158
|
+
tokensUsed?: number;
|
|
159
|
+
/** Latency in ms (optional tracking) */
|
|
160
|
+
latencyMs?: number;
|
|
161
|
+
}
|
|
162
|
+
interface DistilledStrategy {
|
|
163
|
+
taskType: string;
|
|
164
|
+
strategy: string;
|
|
165
|
+
confidence: number;
|
|
166
|
+
updatedAt: number;
|
|
167
|
+
}
|
|
168
|
+
type SearchResultType = 'code' | 'commit' | 'pattern' | 'document' | 'collection';
|
|
169
|
+
interface SearchResult {
|
|
170
|
+
type: SearchResultType;
|
|
171
|
+
score: number;
|
|
172
|
+
/** File path (for code results) or document path */
|
|
173
|
+
filePath?: string;
|
|
174
|
+
/** Content / text */
|
|
175
|
+
content: string;
|
|
176
|
+
/** Context description (for document results) */
|
|
177
|
+
context?: string;
|
|
178
|
+
/** Extra metadata depending on type */
|
|
179
|
+
metadata: Record<string, any>;
|
|
180
|
+
}
|
|
181
|
+
interface ContextOptions {
|
|
182
|
+
/** Max code chunks to include. Default: 6 */
|
|
183
|
+
codeResults?: number;
|
|
184
|
+
/** Max git commits to include. Default: 5 */
|
|
185
|
+
gitResults?: number;
|
|
186
|
+
/** Max memory patterns to include. Default: 4 */
|
|
187
|
+
memoryResults?: number;
|
|
188
|
+
/** Files the agent is about to modify (improves co-edit suggestions) */
|
|
189
|
+
affectedFiles?: string[];
|
|
190
|
+
/** Minimum similarity score threshold. Default: 0.25 */
|
|
191
|
+
minScore?: number;
|
|
192
|
+
/** Use MMR for diversity. Default: true */
|
|
193
|
+
useMMR?: boolean;
|
|
194
|
+
/** MMR lambda (0 = diversity, 1 = relevance). Default: 0.7 */
|
|
195
|
+
mmrLambda?: number;
|
|
196
|
+
}
|
|
197
|
+
interface DocumentCollection {
|
|
198
|
+
/** Collection name (e.g. 'notes', 'docs') */
|
|
199
|
+
name: string;
|
|
200
|
+
/** Directory path to index */
|
|
201
|
+
path: string;
|
|
202
|
+
/** Glob pattern for files (default: all markdown) */
|
|
203
|
+
pattern?: string;
|
|
204
|
+
/** Glob patterns to ignore */
|
|
205
|
+
ignore?: string[];
|
|
206
|
+
/** Context description for this collection */
|
|
207
|
+
context?: string;
|
|
208
|
+
}
|
|
209
|
+
interface DocChunk {
|
|
210
|
+
id?: number;
|
|
211
|
+
/** Collection name */
|
|
212
|
+
collection: string;
|
|
213
|
+
/** Relative file path within the collection */
|
|
214
|
+
filePath: string;
|
|
215
|
+
/** Document title (first heading or filename) */
|
|
216
|
+
title: string;
|
|
217
|
+
/** Chunk content */
|
|
218
|
+
content: string;
|
|
219
|
+
/** Chunk sequence within the document (0, 1, 2...) */
|
|
220
|
+
seq: number;
|
|
221
|
+
/** Character position in original document */
|
|
222
|
+
pos: number;
|
|
223
|
+
/** Content hash for incremental updates */
|
|
224
|
+
contentHash: string;
|
|
225
|
+
}
|
|
226
|
+
interface IndexStats {
|
|
227
|
+
code?: {
|
|
228
|
+
files: number;
|
|
229
|
+
chunks: number;
|
|
230
|
+
hnswSize: number;
|
|
231
|
+
};
|
|
232
|
+
git?: {
|
|
233
|
+
commits: number;
|
|
234
|
+
filesTracked: number;
|
|
235
|
+
coEdits: number;
|
|
236
|
+
hnswSize: number;
|
|
237
|
+
};
|
|
238
|
+
memory?: {
|
|
239
|
+
patterns: number;
|
|
240
|
+
avgSuccess: number;
|
|
241
|
+
hnswSize: number;
|
|
242
|
+
};
|
|
243
|
+
documents?: {
|
|
244
|
+
collections: number;
|
|
245
|
+
documents: number;
|
|
246
|
+
chunks: number;
|
|
247
|
+
hnswSize: number;
|
|
248
|
+
};
|
|
249
|
+
notes?: {
|
|
250
|
+
total: number;
|
|
251
|
+
short: number;
|
|
252
|
+
long: number;
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
type ProgressCallback = (file: string, current: number, total: number) => void;
|
|
256
|
+
interface IndexResult {
|
|
257
|
+
indexed: number;
|
|
258
|
+
skipped: number;
|
|
259
|
+
chunks?: number;
|
|
260
|
+
}
|
|
261
|
+
interface CoEditSuggestion {
|
|
262
|
+
file: string;
|
|
263
|
+
count: number;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* BrainBank — HNSW Vector Index
|
|
268
|
+
*
|
|
269
|
+
* Wraps hnswlib-node for O(log n) approximate nearest neighbor search.
|
|
270
|
+
* M=16 connections, ef=200 construction, ef=50 search by default.
|
|
271
|
+
* 150x faster than brute force at 1M vectors.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
declare class HNSWIndex implements VectorIndex {
|
|
275
|
+
private _dims;
|
|
276
|
+
private _maxElements;
|
|
277
|
+
private _M;
|
|
278
|
+
private _efConstruction;
|
|
279
|
+
private _efSearch;
|
|
280
|
+
private _index;
|
|
281
|
+
private _count;
|
|
282
|
+
constructor(_dims: number, _maxElements?: number, _M?: number, _efConstruction?: number, _efSearch?: number);
|
|
283
|
+
/**
|
|
284
|
+
* Initialize the HNSW index.
|
|
285
|
+
* Must be called before add/search.
|
|
286
|
+
*/
|
|
287
|
+
init(): Promise<this>;
|
|
288
|
+
/**
|
|
289
|
+
* Add a vector with an integer ID.
|
|
290
|
+
* The vector should be pre-normalized for cosine distance.
|
|
291
|
+
*/
|
|
292
|
+
add(vector: Float32Array, id: number): void;
|
|
293
|
+
/**
|
|
294
|
+
* Search for the k nearest neighbors.
|
|
295
|
+
* Returns results sorted by score (highest first).
|
|
296
|
+
* Score is 1 - cosine_distance (1.0 = identical).
|
|
297
|
+
*/
|
|
298
|
+
search(query: Float32Array, k: number): SearchHit[];
|
|
299
|
+
/** Number of vectors in the index. */
|
|
300
|
+
get size(): number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* BrainBank — Collection
|
|
305
|
+
*
|
|
306
|
+
* Universal key-value store with vector + BM25 hybrid search.
|
|
307
|
+
* The foundation primitive — store anything, search semantically.
|
|
308
|
+
*
|
|
309
|
+
* const errors = brain.collection('debug_errors');
|
|
310
|
+
* await errors.add('Fixed null check in api handler', { file: 'api.ts' });
|
|
311
|
+
* const hits = await errors.search('null pointer');
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
interface CollectionItem {
|
|
315
|
+
id: number;
|
|
316
|
+
collection: string;
|
|
317
|
+
content: string;
|
|
318
|
+
metadata: Record<string, any>;
|
|
319
|
+
tags: string[];
|
|
320
|
+
createdAt: number;
|
|
321
|
+
expiresAt?: number;
|
|
322
|
+
score?: number;
|
|
323
|
+
}
|
|
324
|
+
interface CollectionSearchOptions {
|
|
325
|
+
/** Max results. Default: 5 */
|
|
326
|
+
k?: number;
|
|
327
|
+
/** Search mode. Default: 'hybrid' */
|
|
328
|
+
mode?: 'hybrid' | 'vector' | 'keyword';
|
|
329
|
+
/** Minimum score threshold. Default: 0.15 */
|
|
330
|
+
minScore?: number;
|
|
331
|
+
/** Filter by tags (item must have ALL specified tags). */
|
|
332
|
+
tags?: string[];
|
|
333
|
+
}
|
|
334
|
+
interface CollectionAddOptions {
|
|
335
|
+
/** Metadata key-value pairs. */
|
|
336
|
+
metadata?: Record<string, any>;
|
|
337
|
+
/** Tags for filtering. */
|
|
338
|
+
tags?: string[];
|
|
339
|
+
/** Time-to-live duration string (e.g. '7d', '24h', '30m'). */
|
|
340
|
+
ttl?: string;
|
|
341
|
+
}
|
|
342
|
+
declare class Collection {
|
|
343
|
+
private _name;
|
|
344
|
+
private _db;
|
|
345
|
+
private _embedding;
|
|
346
|
+
private _hnsw;
|
|
347
|
+
private _vecs;
|
|
348
|
+
private _reranker?;
|
|
349
|
+
constructor(_name: string, _db: Database, _embedding: EmbeddingProvider, _hnsw: HNSWIndex, _vecs: Map<number, Float32Array>, _reranker?: Reranker | undefined);
|
|
350
|
+
/** Collection name. */
|
|
351
|
+
get name(): string;
|
|
352
|
+
/** Add an item. Returns its ID. */
|
|
353
|
+
add(content: string, options?: CollectionAddOptions | Record<string, any>): Promise<number>;
|
|
354
|
+
/** Add multiple items. Returns their IDs. */
|
|
355
|
+
addMany(items: {
|
|
356
|
+
content: string;
|
|
357
|
+
metadata?: Record<string, any>;
|
|
358
|
+
tags?: string[];
|
|
359
|
+
ttl?: string;
|
|
360
|
+
}[]): Promise<number[]>;
|
|
361
|
+
/** Search this collection. */
|
|
362
|
+
search(query: string, options?: CollectionSearchOptions): Promise<CollectionItem[]>;
|
|
363
|
+
/** List items (newest first). */
|
|
364
|
+
list(options?: {
|
|
365
|
+
limit?: number;
|
|
366
|
+
offset?: number;
|
|
367
|
+
tags?: string[];
|
|
368
|
+
}): CollectionItem[];
|
|
369
|
+
/** Count items in this collection. */
|
|
370
|
+
count(): number;
|
|
371
|
+
/** Keep only the N most recent items, remove the rest. */
|
|
372
|
+
trim(options: {
|
|
373
|
+
keep: number;
|
|
374
|
+
}): Promise<{
|
|
375
|
+
removed: number;
|
|
376
|
+
}>;
|
|
377
|
+
/** Remove items older than a duration string (e.g. '30d', '12h'). */
|
|
378
|
+
prune(options: {
|
|
379
|
+
olderThan: string;
|
|
380
|
+
}): Promise<{
|
|
381
|
+
removed: number;
|
|
382
|
+
}>;
|
|
383
|
+
/** Remove a specific item by ID. */
|
|
384
|
+
remove(id: number): void;
|
|
385
|
+
/** Clear all items in this collection. */
|
|
386
|
+
clear(): void;
|
|
387
|
+
private _removeById;
|
|
388
|
+
private _searchVector;
|
|
389
|
+
private _searchBM25;
|
|
390
|
+
private _rowToItem;
|
|
391
|
+
/** Filter results by tags (item must have ALL specified tags). */
|
|
392
|
+
private _filterByTags;
|
|
393
|
+
/** Remove expired items (TTL). Called automatically on search/list. */
|
|
394
|
+
private _pruneExpired;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* BrainBank — Indexer System
|
|
399
|
+
*
|
|
400
|
+
* Indexers are pluggable strategies that scan external data sources
|
|
401
|
+
* and push content into BrainBank. Built-in indexers handle code,
|
|
402
|
+
* git, and docs. Third-party frameworks (LangChain, etc.)
|
|
403
|
+
* can implement custom indexers.
|
|
404
|
+
*
|
|
405
|
+
* import { BrainBank } from 'brainbank';
|
|
406
|
+
* import { code } from 'brainbank/indexers/code';
|
|
407
|
+
*
|
|
408
|
+
* const brain = new BrainBank()
|
|
409
|
+
* .use(code({ repoPath: '.' }));
|
|
410
|
+
*/
|
|
411
|
+
|
|
412
|
+
interface IndexerContext {
|
|
413
|
+
/** SQLite database (shared across all indexers). */
|
|
414
|
+
db: Database;
|
|
415
|
+
/** Embedding provider (shared). */
|
|
416
|
+
embedding: EmbeddingProvider;
|
|
417
|
+
/** Resolved BrainBank config. */
|
|
418
|
+
config: ResolvedConfig;
|
|
419
|
+
/** Create and initialize an HNSW index. */
|
|
420
|
+
createHnsw(maxElements?: number): Promise<HNSWIndex>;
|
|
421
|
+
/** Load existing vectors from a SQLite vectors table into an HNSW index + cache. */
|
|
422
|
+
loadVectors(table: string, idCol: string, hnsw: HNSWIndex, cache: Map<number, Float32Array>): void;
|
|
423
|
+
/** Get or create a shared HNSW index by type (e.g. 'code', 'git'). For multi-repo support. */
|
|
424
|
+
getOrCreateSharedHnsw(type: string, maxElements?: number): Promise<{
|
|
425
|
+
hnsw: HNSWIndex;
|
|
426
|
+
vecCache: Map<number, Float32Array>;
|
|
427
|
+
isNew: boolean;
|
|
428
|
+
}>;
|
|
429
|
+
/** Get or create a dynamic collection. */
|
|
430
|
+
collection(name: string): Collection;
|
|
431
|
+
}
|
|
432
|
+
interface Indexer {
|
|
433
|
+
/** Unique indexer name (e.g. 'code', 'git', 'docs'). */
|
|
434
|
+
readonly name: string;
|
|
435
|
+
/** Initialize the indexer (create HNSW, load vectors, etc.). */
|
|
436
|
+
initialize(ctx: IndexerContext): Promise<void>;
|
|
437
|
+
/** Index content. Implemented by code and git indexers. */
|
|
438
|
+
index?(options?: any): Promise<any>;
|
|
439
|
+
/** Search indexed content. Implemented by docs indexer. */
|
|
440
|
+
search?(query: string, options?: any): Promise<any[]>;
|
|
441
|
+
/** Register a document collection. */
|
|
442
|
+
addCollection?(collection: any): void;
|
|
443
|
+
/** Remove a collection. */
|
|
444
|
+
removeCollection?(name: string): void;
|
|
445
|
+
/** List registered collections. */
|
|
446
|
+
listCollections?(): any[];
|
|
447
|
+
/** Index all or specific collections. */
|
|
448
|
+
indexCollections?(options?: any): Promise<any>;
|
|
449
|
+
/** Add context description for a collection path. */
|
|
450
|
+
addContext?(collection: string, path: string, context: string): void;
|
|
451
|
+
/** Remove context for a collection path. */
|
|
452
|
+
removeContext?(collection: string, path: string): void;
|
|
453
|
+
/** List all context entries. */
|
|
454
|
+
listContexts?(): any[];
|
|
455
|
+
/**
|
|
456
|
+
* Called by watch mode when a file changes.
|
|
457
|
+
* Return true if this indexer handled the change.
|
|
458
|
+
* If not implemented, watch will fall back to brain.index().
|
|
459
|
+
*/
|
|
460
|
+
onFileChange?(filePath: string, event: 'create' | 'update' | 'delete'): Promise<boolean>;
|
|
461
|
+
/**
|
|
462
|
+
* Glob patterns this indexer watches.
|
|
463
|
+
* If not set, defaults to all supported code extensions.
|
|
464
|
+
*/
|
|
465
|
+
watchPatterns?(): string[];
|
|
466
|
+
/** Return stats for this indexer. */
|
|
467
|
+
stats?(): Record<string, any>;
|
|
468
|
+
/** Clean up resources. */
|
|
469
|
+
close?(): void;
|
|
470
|
+
}
|
|
471
|
+
type BrainBankModule = Indexer;
|
|
472
|
+
type ModuleContext = IndexerContext;
|
|
473
|
+
|
|
474
|
+
export { type BrainBankModule as B, Collection as C, type DocumentCollection as D, type EmbeddingProvider as E, type GitCommitRecord as G, HNSWIndex as H, type Indexer as I, type MemoryPattern as M, type ProgressCallback as P, type ResolvedConfig as R, type SearchResult as S, type VectorIndex as V, type BrainBankConfig as a, type IndexResult as b, type ContextOptions as c, type CoEditSuggestion as d, type IndexStats as e, type SearchHit as f, type CodeChunk as g, Database as h, type Reranker as i, type CollectionAddOptions as j, type CollectionItem as k, type CollectionSearchOptions as l, type DistilledStrategy as m, type DocChunk as n, type IndexerContext as o, type ModuleContext as p, type SearchResultType as q };
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brainbank",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pluggable semantic memory for AI agents — hybrid search (vector + BM25) in a single SQLite file. Built-in code, git, and docs indexers. Bring your own.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"brainbank": "./dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./code": {
|
|
17
|
+
"import": "./dist/code.js",
|
|
18
|
+
"types": "./dist/code.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./git": {
|
|
21
|
+
"import": "./dist/git.js",
|
|
22
|
+
"types": "./dist/git.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./docs": {
|
|
25
|
+
"import": "./dist/docs.js",
|
|
26
|
+
"types": "./dist/docs.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./notes": {
|
|
29
|
+
"import": "./dist/notes.js",
|
|
30
|
+
"types": "./dist/notes.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./memory": {
|
|
33
|
+
"import": "./dist/memory.js",
|
|
34
|
+
"types": "./dist/memory.d.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/",
|
|
39
|
+
"bin/",
|
|
40
|
+
"LICENSE",
|
|
41
|
+
"README.md",
|
|
42
|
+
"assets/"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup && npm run build --workspaces --if-present",
|
|
46
|
+
"build:core": "tsup",
|
|
47
|
+
"prepublishOnly": "npm run build:core",
|
|
48
|
+
"test": "node --import tsx test/run.ts",
|
|
49
|
+
"test:integration": "node --import tsx test/run.ts --integration",
|
|
50
|
+
"test:verbose": "node --import tsx test/run.ts --verbose",
|
|
51
|
+
"dev": "tsx src/integrations/cli.ts"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18"
|
|
55
|
+
},
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "git+https://github.com/pinecall/brainbank.git"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"ai",
|
|
62
|
+
"agent",
|
|
63
|
+
"semantic-memory",
|
|
64
|
+
"vector-search",
|
|
65
|
+
"knowledge-base",
|
|
66
|
+
"embeddings",
|
|
67
|
+
"hnsw",
|
|
68
|
+
"typescript"
|
|
69
|
+
],
|
|
70
|
+
"author": "Bernardo Castro <bernardo@pinecall.io>",
|
|
71
|
+
"license": "MIT",
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"better-sqlite3": "^11.8.1",
|
|
74
|
+
"hnswlib-node": "^3.0.0"
|
|
75
|
+
},
|
|
76
|
+
"optionalDependencies": {
|
|
77
|
+
"@xenova/transformers": "^2.17.2",
|
|
78
|
+
"simple-git": "^3.27.0"
|
|
79
|
+
},
|
|
80
|
+
"devDependencies": {
|
|
81
|
+
"@ai-sdk/openai": "^3.0.47",
|
|
82
|
+
"@langchain/core": "^1.1.35",
|
|
83
|
+
"@langchain/openai": "^1.3.0",
|
|
84
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
85
|
+
"@types/node": "^22.0.0",
|
|
86
|
+
"ai": "^6.0.134",
|
|
87
|
+
"tsup": "^8.4.0",
|
|
88
|
+
"tsx": "^4.19.0",
|
|
89
|
+
"typescript": "^5.7.0"
|
|
90
|
+
}
|
|
91
|
+
}
|