brainbank 0.1.3 → 0.2.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/README.md +26 -12
- package/dist/{types-Da_zLLOl.d.ts → base-9vfWRHCV.d.ts} +131 -31
- package/dist/{chunk-TW5NTYYZ.js → chunk-6MFTQV3O.js} +909 -685
- package/dist/chunk-6MFTQV3O.js.map +1 -0
- package/dist/chunk-7JCEW7LT.js +266 -0
- package/dist/chunk-7JCEW7LT.js.map +1 -0
- package/dist/{chunk-GOUBW7UA.js → chunk-F6SJ3U4H.js} +98 -34
- package/dist/chunk-F6SJ3U4H.js.map +1 -0
- package/dist/{chunk-MJ3Y24H6.js → chunk-FJJY4H2Y.js} +11 -11
- package/dist/chunk-FJJY4H2Y.js.map +1 -0
- package/dist/{chunk-3GAIDXRW.js → chunk-GUT5MSJT.js} +5 -11
- package/dist/chunk-GUT5MSJT.js.map +1 -0
- package/dist/{chunk-2P3EGY6S.js → chunk-QNHBCOKB.js} +2 -2
- package/dist/chunk-QNHBCOKB.js.map +1 -0
- package/dist/{chunk-4ZKBQ33J.js → chunk-V4UJKXPK.js} +23 -5
- package/dist/chunk-V4UJKXPK.js.map +1 -0
- package/dist/{chunk-RAEBYV75.js → chunk-WR4WXKJT.js} +37 -23
- package/dist/chunk-WR4WXKJT.js.map +1 -0
- package/dist/{chunk-Z5SU54HP.js → chunk-X6645UVR.js} +3 -3
- package/dist/chunk-X6645UVR.js.map +1 -0
- package/dist/cli.js +122 -102
- package/dist/cli.js.map +1 -1
- package/dist/code.d.ts +5 -5
- package/dist/code.js +1 -1
- package/dist/docs.d.ts +4 -6
- package/dist/docs.js +1 -1
- package/dist/git.d.ts +5 -5
- package/dist/git.js +1 -1
- package/dist/index.d.ts +54 -90
- package/dist/index.js +13 -13
- package/dist/memory.d.ts +5 -7
- package/dist/memory.js +9 -12
- package/dist/memory.js.map +1 -1
- package/dist/notes.d.ts +4 -6
- package/dist/notes.js +7 -10
- package/dist/notes.js.map +1 -1
- package/dist/{openai-PCTYLOWI.js → openai-CYDMYX7X.js} +2 -2
- package/package.json +3 -3
- package/dist/chunk-2P3EGY6S.js.map +0 -1
- package/dist/chunk-3GAIDXRW.js.map +0 -1
- package/dist/chunk-4ZKBQ33J.js.map +0 -1
- package/dist/chunk-GOUBW7UA.js.map +0 -1
- package/dist/chunk-MJ3Y24H6.js.map +0 -1
- package/dist/chunk-N6ZMBFDE.js +0 -224
- package/dist/chunk-N6ZMBFDE.js.map +0 -1
- package/dist/chunk-RAEBYV75.js.map +0 -1
- package/dist/chunk-TW5NTYYZ.js.map +0 -1
- package/dist/chunk-Z5SU54HP.js.map +0 -1
- /package/dist/{openai-PCTYLOWI.js.map → openai-CYDMYX7X.js.map} +0 -0
package/dist/code.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as Indexer } from './base-9vfWRHCV.js';
|
|
2
2
|
import 'better-sqlite3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -17,7 +17,7 @@ import 'better-sqlite3';
|
|
|
17
17
|
* .use(code({ repoPath: './backend', name: 'code:backend' }));
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
interface
|
|
20
|
+
interface CodePluginOptions {
|
|
21
21
|
/** Repository path to index. Default: '.' */
|
|
22
22
|
repoPath?: string;
|
|
23
23
|
/** Maximum file size in bytes. Default: from config */
|
|
@@ -25,7 +25,7 @@ interface CodeModuleOptions {
|
|
|
25
25
|
/** Custom indexer name for multi-repo (e.g. 'code:frontend'). Default: 'code' */
|
|
26
26
|
name?: string;
|
|
27
27
|
}
|
|
28
|
-
/** Create a code indexing
|
|
29
|
-
declare function code(opts?:
|
|
28
|
+
/** Create a code indexing plugin. */
|
|
29
|
+
declare function code(opts?: CodePluginOptions): Indexer;
|
|
30
30
|
|
|
31
|
-
export { type
|
|
31
|
+
export { type CodePluginOptions, code };
|
package/dist/code.js
CHANGED
package/dist/docs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as Indexer } from './base-9vfWRHCV.js';
|
|
2
2
|
import 'better-sqlite3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -11,9 +11,7 @@ import 'better-sqlite3';
|
|
|
11
11
|
* brain.use(docs());
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Create a document collections module. */
|
|
17
|
-
declare function docs(opts?: DocsModuleOptions): BrainBankModule;
|
|
14
|
+
/** Create a document collections plugin. */
|
|
15
|
+
declare function docs(): Indexer;
|
|
18
16
|
|
|
19
|
-
export {
|
|
17
|
+
export { docs };
|
package/dist/docs.js
CHANGED
package/dist/git.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as Indexer } from './base-9vfWRHCV.js';
|
|
2
2
|
import 'better-sqlite3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -15,7 +15,7 @@ import 'better-sqlite3';
|
|
|
15
15
|
* .use(git({ repoPath: './backend', name: 'git:backend' }));
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
interface
|
|
18
|
+
interface GitPluginOptions {
|
|
19
19
|
/** Repository path. Default: from config */
|
|
20
20
|
repoPath?: string;
|
|
21
21
|
/** Max commits to index. Default: from config */
|
|
@@ -25,7 +25,7 @@ interface GitModuleOptions {
|
|
|
25
25
|
/** Custom indexer name for multi-repo (e.g. 'git:frontend'). Default: 'git' */
|
|
26
26
|
name?: string;
|
|
27
27
|
}
|
|
28
|
-
/** Create a git history
|
|
29
|
-
declare function git(opts?:
|
|
28
|
+
/** Create a git history plugin. */
|
|
29
|
+
declare function git(opts?: GitPluginOptions): Indexer;
|
|
30
30
|
|
|
31
|
-
export { type
|
|
31
|
+
export { type GitPluginOptions, git };
|
package/dist/git.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import { P as ProgressCallback,
|
|
3
|
-
export {
|
|
2
|
+
import { P as ProgressCallback, B as BrainBankConfig, I as Indexer, C as Collection, S as StageProgressCallback, a as IndexResult, D as DocumentCollection, b as SearchResult, c as ContextOptions, d as CoEditSuggestion, e as IndexStats, R as ResolvedConfig, E as EmbeddingProvider, V as VectorIndex, f as SearchHit, g as CodeChunk, h as Database, H as HNSWIndex, L as LearningPattern, i as Reranker } from './base-9vfWRHCV.js';
|
|
3
|
+
export { j as CodeResult, k as CodeResultMetadata, l as CollectionAddOptions, m as CollectionItem, n as CollectionPlugin, o as CollectionResult, p as CollectionSearchOptions, q as CommitResult, r as CommitResultMetadata, s as DistilledStrategy, t as DocChunk, u as DocumentResult, v as DocumentResultMetadata, G as GitCommitRecord, w as IndexablePlugin, x as IndexerContext, y as PatternResult, z as PatternResultMetadata, A as SearchResultType, F as SearchablePlugin, W as WatchablePlugin } from './base-9vfWRHCV.js';
|
|
4
4
|
export { code } from './code.js';
|
|
5
5
|
export { git } from './git.js';
|
|
6
6
|
export { docs } from './docs.js';
|
|
@@ -73,31 +73,25 @@ interface ReembedOptions {
|
|
|
73
73
|
/**
|
|
74
74
|
* BrainBank — Main Orchestrator
|
|
75
75
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
76
|
+
* Thin facade that composes four services:
|
|
77
|
+
* IndexerRegistry — registration + lookup
|
|
78
|
+
* Initializer — two-phase startup (earlyInit / lateInit)
|
|
79
|
+
* SearchAPI — all search + context logic
|
|
80
|
+
* IndexAPI — code / git / docs indexing orchestration
|
|
78
81
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* import { docs } from 'brainbank/docs';
|
|
82
|
-
* import { notes } from 'brainbank/notes';
|
|
83
|
-
* import { memory } from 'brainbank/memory';
|
|
84
|
-
*
|
|
85
|
-
* const brain = new BrainBank()
|
|
86
|
-
* .use(code({ repoPath: '.' }))
|
|
87
|
-
* .use(docs())
|
|
88
|
-
* .use(notes())
|
|
89
|
-
* .use(memory());
|
|
82
|
+
* All heavy logic lives in those modules; BrainBank owns state,
|
|
83
|
+
* guards (requireInit / initialize()), and public API shape.
|
|
90
84
|
*/
|
|
91
85
|
|
|
92
86
|
declare class BrainBank extends EventEmitter {
|
|
93
87
|
private _config;
|
|
94
88
|
private _db;
|
|
95
89
|
private _embedding;
|
|
96
|
-
private
|
|
97
|
-
private
|
|
98
|
-
private
|
|
99
|
-
private _contextBuilder?;
|
|
90
|
+
private _registry;
|
|
91
|
+
private _searchAPI?;
|
|
92
|
+
private _indexAPI?;
|
|
100
93
|
private _initialized;
|
|
94
|
+
private _initPromise;
|
|
101
95
|
private _watcher?;
|
|
102
96
|
private _collections;
|
|
103
97
|
private _kvHnsw?;
|
|
@@ -112,24 +106,17 @@ declare class BrainBank extends EventEmitter {
|
|
|
112
106
|
use(indexer: Indexer): this;
|
|
113
107
|
/** Get the list of registered indexer names. */
|
|
114
108
|
get indexers(): string[];
|
|
115
|
-
/** @deprecated Use .indexers instead. */
|
|
116
|
-
get modules(): string[];
|
|
117
109
|
/** Check if an indexer is loaded. Also matches type prefix (e.g. 'code' matches 'code:frontend'). */
|
|
118
110
|
has(name: string): boolean;
|
|
119
111
|
/** Get an indexer instance. Throws if not loaded. */
|
|
120
|
-
indexer<T extends Indexer = Indexer>(
|
|
121
|
-
/** @deprecated Use .indexer() instead. */
|
|
122
|
-
module(name: string): Indexer;
|
|
123
|
-
/** Find all indexers whose name equals or starts with the type prefix. */
|
|
124
|
-
private _findAllByType;
|
|
125
|
-
/** Find the first indexer that matches the type. */
|
|
126
|
-
private _findFirstByType;
|
|
112
|
+
indexer<T extends Indexer = Indexer>(n: string): T;
|
|
127
113
|
/**
|
|
128
114
|
* Initialize database, HNSW indices, and load existing vectors.
|
|
129
115
|
* Only initializes registered modules.
|
|
130
116
|
* Automatically called by index/search methods if not yet initialized.
|
|
131
117
|
*/
|
|
132
118
|
initialize(): Promise<void>;
|
|
119
|
+
private _runInitialize;
|
|
133
120
|
/**
|
|
134
121
|
* Get or create a dynamic collection.
|
|
135
122
|
* Collections are the universal data primitive — store anything, search semantically.
|
|
@@ -141,16 +128,11 @@ declare class BrainBank extends EventEmitter {
|
|
|
141
128
|
collection(name: string): Collection;
|
|
142
129
|
/** List all collection names that have data. */
|
|
143
130
|
listCollectionNames(): string[];
|
|
144
|
-
/**
|
|
145
|
-
* Index code, git, and/or docs in one call.
|
|
146
|
-
* Incremental — only processes changes since last run.
|
|
147
|
-
* @param modules - Which modules to index. Default: all available (['code', 'git', 'docs'])
|
|
148
|
-
*/
|
|
149
131
|
index(options?: {
|
|
150
132
|
modules?: ('code' | 'git' | 'docs')[];
|
|
151
133
|
gitDepth?: number;
|
|
152
134
|
forceReindex?: boolean;
|
|
153
|
-
onProgress?:
|
|
135
|
+
onProgress?: StageProgressCallback;
|
|
154
136
|
}): Promise<{
|
|
155
137
|
code?: IndexResult;
|
|
156
138
|
git?: IndexResult;
|
|
@@ -160,12 +142,12 @@ declare class BrainBank extends EventEmitter {
|
|
|
160
142
|
chunks: number;
|
|
161
143
|
}>;
|
|
162
144
|
}>;
|
|
163
|
-
/** Index only code files. */
|
|
145
|
+
/** Index only code files (all repos in multi-repo mode). */
|
|
164
146
|
indexCode(options?: {
|
|
165
147
|
forceReindex?: boolean;
|
|
166
148
|
onProgress?: ProgressCallback;
|
|
167
149
|
}): Promise<IndexResult>;
|
|
168
|
-
/** Index only git history. */
|
|
150
|
+
/** Index only git history (all repos in multi-repo mode). */
|
|
169
151
|
indexGit(options?: {
|
|
170
152
|
depth?: number;
|
|
171
153
|
onProgress?: ProgressCallback;
|
|
@@ -210,7 +192,7 @@ declare class BrainBank extends EventEmitter {
|
|
|
210
192
|
search(query: string, options?: {
|
|
211
193
|
codeK?: number;
|
|
212
194
|
gitK?: number;
|
|
213
|
-
|
|
195
|
+
patternK?: number;
|
|
214
196
|
minScore?: number;
|
|
215
197
|
useMMR?: boolean;
|
|
216
198
|
}): Promise<SearchResult[]>;
|
|
@@ -223,26 +205,18 @@ declare class BrainBank extends EventEmitter {
|
|
|
223
205
|
* Best quality — catches both exact keyword matches and conceptual similarities.
|
|
224
206
|
*/
|
|
225
207
|
hybridSearch(query: string, options?: {
|
|
226
|
-
/** @deprecated Use collections: { code: N } instead */
|
|
227
208
|
codeK?: number;
|
|
228
|
-
/** @deprecated Use collections: { git: N } instead */
|
|
229
209
|
gitK?: number;
|
|
230
|
-
|
|
210
|
+
patternK?: number;
|
|
231
211
|
minScore?: number;
|
|
232
212
|
useMMR?: boolean;
|
|
233
|
-
/**
|
|
234
|
-
* Sources to include and max results per source.
|
|
235
|
-
* Reserved keys: "code", "git", "docs" control built-in indexers.
|
|
236
|
-
* Any other key is treated as a KV collection name.
|
|
237
|
-
* Example: { code: 8, git: 5, docs: 4, errors: 3, slack: 2 }
|
|
238
|
-
*/
|
|
239
213
|
collections?: Record<string, number>;
|
|
240
214
|
}): Promise<SearchResult[]>;
|
|
241
215
|
/** BM25 keyword search only (no embeddings needed). */
|
|
242
216
|
searchBM25(query: string, options?: {
|
|
243
217
|
codeK?: number;
|
|
244
218
|
gitK?: number;
|
|
245
|
-
|
|
219
|
+
patternK?: number;
|
|
246
220
|
}): SearchResult[];
|
|
247
221
|
/** Rebuild FTS5 indices. */
|
|
248
222
|
rebuildFTS(): void;
|
|
@@ -255,23 +229,11 @@ declare class BrainBank extends EventEmitter {
|
|
|
255
229
|
/**
|
|
256
230
|
* Start watching for file changes and auto-re-index.
|
|
257
231
|
* Works with built-in and custom indexers.
|
|
258
|
-
*
|
|
259
|
-
* const watcher = brain.watch({
|
|
260
|
-
* onIndex: (file, indexer) => console.log(`${indexer}: ${file}`),
|
|
261
|
-
* });
|
|
262
|
-
* // later: watcher.close();
|
|
263
232
|
*/
|
|
264
233
|
watch(options?: WatchOptions): Watcher;
|
|
265
234
|
/**
|
|
266
235
|
* Re-embed all existing text with the current embedding provider.
|
|
267
236
|
* Use this when switching providers (e.g. Local → OpenAI).
|
|
268
|
-
* Does NOT re-parse files, git history, or documents — only regenerates vectors.
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* const brain = new BrainBank({ embeddingProvider: new OpenAIEmbedding() });
|
|
272
|
-
* await brain.initialize();
|
|
273
|
-
* const result = await brain.reembed();
|
|
274
|
-
* // → { code: 1200, git: 500, docs: 80, kv: 45, notes: 12, total: 1837 }
|
|
275
237
|
*/
|
|
276
238
|
reembed(options?: ReembedOptions): Promise<ReembedResult>;
|
|
277
239
|
/** Close database and release resources. */
|
|
@@ -280,8 +242,7 @@ declare class BrainBank extends EventEmitter {
|
|
|
280
242
|
get isInitialized(): boolean;
|
|
281
243
|
/** The resolved configuration. */
|
|
282
244
|
get config(): Readonly<ResolvedConfig>;
|
|
283
|
-
|
|
284
|
-
private _loadVectors;
|
|
245
|
+
private _requireInit;
|
|
285
246
|
}
|
|
286
247
|
|
|
287
248
|
/**
|
|
@@ -301,9 +262,11 @@ declare class LocalEmbedding implements EmbeddingProvider {
|
|
|
301
262
|
model?: string;
|
|
302
263
|
cacheDir?: string;
|
|
303
264
|
});
|
|
265
|
+
private _pipelinePromise;
|
|
304
266
|
/**
|
|
305
267
|
* Lazy-load the transformer pipeline.
|
|
306
268
|
* Singleton — created once and reused.
|
|
269
|
+
* Promise-deduped to prevent concurrent downloads.
|
|
307
270
|
*/
|
|
308
271
|
private _getPipeline;
|
|
309
272
|
/**
|
|
@@ -347,7 +310,6 @@ declare class OpenAIEmbedding implements EmbeddingProvider {
|
|
|
347
310
|
private _model;
|
|
348
311
|
private _baseUrl;
|
|
349
312
|
private _requestDims;
|
|
350
|
-
private _retrying;
|
|
351
313
|
constructor(options?: OpenAIEmbeddingOptions);
|
|
352
314
|
embed(text: string): Promise<Float32Array>;
|
|
353
315
|
embedBatch(texts: string[]): Promise<Float32Array[]>;
|
|
@@ -374,6 +336,14 @@ declare function cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
|
374
336
|
*/
|
|
375
337
|
declare function normalize(vec: Float32Array): Float32Array;
|
|
376
338
|
|
|
339
|
+
declare const DEFAULTS: ResolvedConfig;
|
|
340
|
+
/**
|
|
341
|
+
* Merge partial config with defaults.
|
|
342
|
+
* All fields become required.
|
|
343
|
+
* Relative dbPath is resolved against repoPath.
|
|
344
|
+
*/
|
|
345
|
+
declare function resolveConfig(partial?: BrainBankConfig): ResolvedConfig;
|
|
346
|
+
|
|
377
347
|
/**
|
|
378
348
|
* BrainBank — Maximum Marginal Relevance (MMR)
|
|
379
349
|
*
|
|
@@ -520,11 +490,11 @@ declare class GitIndexer {
|
|
|
520
490
|
* Indexes generic document collections (markdown, text, etc.)
|
|
521
491
|
* with heading-aware smart chunking, inspired by qmd.
|
|
522
492
|
*
|
|
523
|
-
* const indexer = new
|
|
493
|
+
* const indexer = new DocsIndexer(db, embedding, hnsw, vecCache);
|
|
524
494
|
* await indexer.indexCollection('notes', '/path/to/notes', '**\/*.md');
|
|
525
495
|
*/
|
|
526
496
|
|
|
527
|
-
declare class
|
|
497
|
+
declare class DocsIndexer {
|
|
528
498
|
private _db;
|
|
529
499
|
private _embedding;
|
|
530
500
|
private _hnsw;
|
|
@@ -559,6 +529,8 @@ declare class DocIndexer {
|
|
|
559
529
|
* Extract document title from first heading or filename.
|
|
560
530
|
*/
|
|
561
531
|
private _extractTitle;
|
|
532
|
+
/** Skip well-known output/vendor directories when walking docs. */
|
|
533
|
+
private _isIgnoredDocDir;
|
|
562
534
|
}
|
|
563
535
|
|
|
564
536
|
/**
|
|
@@ -595,18 +567,18 @@ declare class PatternStore {
|
|
|
595
567
|
* Store a learned pattern.
|
|
596
568
|
* Returns the pattern ID.
|
|
597
569
|
*/
|
|
598
|
-
learn(pattern:
|
|
570
|
+
learn(pattern: LearningPattern): Promise<number>;
|
|
599
571
|
/**
|
|
600
572
|
* Search for similar successful patterns.
|
|
601
573
|
* Filters by minimum success rate.
|
|
602
574
|
*/
|
|
603
|
-
search(query: string, k?: number, minSuccess?: number): Promise<(
|
|
575
|
+
search(query: string, k?: number, minSuccess?: number): Promise<(LearningPattern & {
|
|
604
576
|
score: number;
|
|
605
577
|
})[]>;
|
|
606
578
|
/**
|
|
607
579
|
* Get all patterns for a specific task type.
|
|
608
580
|
*/
|
|
609
|
-
getByTaskType(taskType: string, limit?: number):
|
|
581
|
+
getByTaskType(taskType: string, limit?: number): LearningPattern[];
|
|
610
582
|
/** Total number of stored patterns. */
|
|
611
583
|
get count(): number;
|
|
612
584
|
}
|
|
@@ -722,20 +694,20 @@ declare class NoteStore {
|
|
|
722
694
|
}
|
|
723
695
|
|
|
724
696
|
/**
|
|
725
|
-
* BrainBank —
|
|
697
|
+
* BrainBank — Multi-Index Search
|
|
726
698
|
*
|
|
727
|
-
* Searches across all three indices (code, git, memory)
|
|
699
|
+
* Searches across all three indices (code, git, memory patterns)
|
|
728
700
|
* and returns typed results sorted by relevance.
|
|
729
701
|
*/
|
|
730
702
|
|
|
731
|
-
interface
|
|
703
|
+
interface SearchConfig {
|
|
732
704
|
db: Database;
|
|
733
705
|
codeHnsw?: HNSWIndex;
|
|
734
706
|
gitHnsw?: HNSWIndex;
|
|
735
|
-
|
|
707
|
+
patternHnsw?: HNSWIndex;
|
|
736
708
|
codeVecs: Map<number, Float32Array>;
|
|
737
709
|
gitVecs: Map<number, Float32Array>;
|
|
738
|
-
|
|
710
|
+
patternVecs: Map<number, Float32Array>;
|
|
739
711
|
embedding: EmbeddingProvider;
|
|
740
712
|
reranker?: Reranker;
|
|
741
713
|
}
|
|
@@ -744,8 +716,8 @@ interface SearchOptions {
|
|
|
744
716
|
codeK?: number;
|
|
745
717
|
/** Max git results. Default: 5 */
|
|
746
718
|
gitK?: number;
|
|
747
|
-
/** Max
|
|
748
|
-
|
|
719
|
+
/** Max pattern results. Default: 4 */
|
|
720
|
+
patternK?: number;
|
|
749
721
|
/** Minimum similarity score. Default: 0.25 */
|
|
750
722
|
minScore?: number;
|
|
751
723
|
/** Use MMR for diversity. Default: true */
|
|
@@ -753,9 +725,9 @@ interface SearchOptions {
|
|
|
753
725
|
/** MMR lambda. Default: 0.7 */
|
|
754
726
|
mmrLambda?: number;
|
|
755
727
|
}
|
|
756
|
-
declare class
|
|
757
|
-
private
|
|
758
|
-
constructor(
|
|
728
|
+
declare class MultiIndexSearch {
|
|
729
|
+
private _config;
|
|
730
|
+
constructor(config: SearchConfig);
|
|
759
731
|
/**
|
|
760
732
|
* Search across all indices.
|
|
761
733
|
* Returns combined results sorted by score.
|
|
@@ -798,8 +770,8 @@ declare class CoEditAnalyzer {
|
|
|
798
770
|
|
|
799
771
|
declare class ContextBuilder {
|
|
800
772
|
private _search;
|
|
801
|
-
private _coEdits
|
|
802
|
-
constructor(_search:
|
|
773
|
+
private _coEdits?;
|
|
774
|
+
constructor(_search: MultiIndexSearch, _coEdits?: CoEditAnalyzer | undefined);
|
|
803
775
|
/**
|
|
804
776
|
* Build a full context block for a task.
|
|
805
777
|
* Returns clean markdown ready for system prompt injection.
|
|
@@ -820,8 +792,8 @@ interface BM25Options {
|
|
|
820
792
|
codeK?: number;
|
|
821
793
|
/** Max git results. Default: 5 */
|
|
822
794
|
gitK?: number;
|
|
823
|
-
/** Max
|
|
824
|
-
|
|
795
|
+
/** Max pattern results. Default: 4 */
|
|
796
|
+
patternK?: number;
|
|
825
797
|
}
|
|
826
798
|
declare class BM25Search {
|
|
827
799
|
private _db;
|
|
@@ -861,12 +833,4 @@ declare class BM25Search {
|
|
|
861
833
|
*/
|
|
862
834
|
declare function reciprocalRankFusion(resultSets: SearchResult[][], k?: number, maxResults?: number): SearchResult[];
|
|
863
835
|
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Merge partial config with defaults.
|
|
867
|
-
* All fields become required.
|
|
868
|
-
* Relative dbPath is resolved against repoPath.
|
|
869
|
-
*/
|
|
870
|
-
declare function resolveConfig(partial?: BrainBankConfig): ResolvedConfig;
|
|
871
|
-
|
|
872
|
-
export { BM25Search, BrainBank, BrainBankConfig, CoEditAnalyzer, CoEditSuggestion, CodeChunk, CodeChunker, CodeIndexer, Collection, Consolidator, ContextBuilder, ContextOptions, DEFAULTS, DocIndexer, DocumentCollection, EmbeddingProvider, GitIndexer, HNSWIndex, IGNORE_DIRS, IndexResult, IndexStats, Indexer, LocalEmbedding, MemoryPattern, type NoteDigest, NoteStore, OpenAIEmbedding, type OpenAIEmbeddingOptions, PatternStore, ProgressCallback, type RecallOptions, type ReembedOptions, type ReembedResult, Reranker, ResolvedConfig, SUPPORTED_EXTENSIONS, SearchHit, SearchResult, type StoredNote, UnifiedSearch, VectorIndex, type WatchOptions, type Watcher, cosineSimilarity, getLanguage, isSupported, normalize, reciprocalRankFusion, resolveConfig, searchMMR };
|
|
836
|
+
export { BM25Search, BrainBank, BrainBankConfig, CoEditAnalyzer, CoEditSuggestion, CodeChunk, CodeChunker, CodeIndexer, Collection, Consolidator, ContextBuilder, ContextOptions, DEFAULTS, DocsIndexer, DocumentCollection, EmbeddingProvider, GitIndexer, HNSWIndex, IGNORE_DIRS, IndexResult, IndexStats, Indexer, LearningPattern, LocalEmbedding, MultiIndexSearch, type NoteDigest, NoteStore, OpenAIEmbedding, type OpenAIEmbeddingOptions, PatternStore, ProgressCallback, type RecallOptions, type ReembedOptions, type ReembedResult, Reranker, ResolvedConfig, SUPPORTED_EXTENSIONS, SearchHit, SearchResult, StageProgressCallback, type StoredNote, VectorIndex, type WatchOptions, type Watcher, cosineSimilarity, getLanguage, isSupported, normalize, reciprocalRankFusion, resolveConfig, searchMMR };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoteStore
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FJJY4H2Y.js";
|
|
4
4
|
import {
|
|
5
5
|
Consolidator,
|
|
6
6
|
PatternStore
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-X6645UVR.js";
|
|
8
8
|
import {
|
|
9
9
|
BM25Search,
|
|
10
10
|
BrainBank,
|
|
@@ -13,10 +13,10 @@ import {
|
|
|
13
13
|
DEFAULTS,
|
|
14
14
|
HNSWIndex,
|
|
15
15
|
LocalEmbedding,
|
|
16
|
-
|
|
16
|
+
MultiIndexSearch,
|
|
17
17
|
resolveConfig,
|
|
18
18
|
searchMMR
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-6MFTQV3O.js";
|
|
20
20
|
import {
|
|
21
21
|
CodeChunker,
|
|
22
22
|
CodeIndexer,
|
|
@@ -25,26 +25,26 @@ import {
|
|
|
25
25
|
code,
|
|
26
26
|
getLanguage,
|
|
27
27
|
isSupported
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-WR4WXKJT.js";
|
|
29
29
|
import {
|
|
30
30
|
CoEditAnalyzer,
|
|
31
31
|
GitIndexer,
|
|
32
32
|
git
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-7JCEW7LT.js";
|
|
34
34
|
import {
|
|
35
|
-
|
|
35
|
+
DocsIndexer,
|
|
36
36
|
docs
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-F6SJ3U4H.js";
|
|
38
38
|
import {
|
|
39
39
|
reciprocalRankFusion
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-V4UJKXPK.js";
|
|
41
41
|
import {
|
|
42
42
|
cosineSimilarity,
|
|
43
43
|
normalize
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-QNHBCOKB.js";
|
|
45
45
|
import {
|
|
46
46
|
OpenAIEmbedding
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-GUT5MSJT.js";
|
|
48
48
|
import "./chunk-7QVYU63E.js";
|
|
49
49
|
export {
|
|
50
50
|
BM25Search,
|
|
@@ -56,16 +56,16 @@ export {
|
|
|
56
56
|
Consolidator,
|
|
57
57
|
ContextBuilder,
|
|
58
58
|
DEFAULTS,
|
|
59
|
-
|
|
59
|
+
DocsIndexer,
|
|
60
60
|
GitIndexer,
|
|
61
61
|
HNSWIndex,
|
|
62
62
|
IGNORE_DIRS,
|
|
63
63
|
LocalEmbedding,
|
|
64
|
+
MultiIndexSearch,
|
|
64
65
|
NoteStore,
|
|
65
66
|
OpenAIEmbedding,
|
|
66
67
|
PatternStore,
|
|
67
68
|
SUPPORTED_EXTENSIONS,
|
|
68
|
-
UnifiedSearch,
|
|
69
69
|
code,
|
|
70
70
|
cosineSimilarity,
|
|
71
71
|
docs,
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as Indexer } from './base-9vfWRHCV.js';
|
|
2
2
|
import 'better-sqlite3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* BrainBank — Memory
|
|
5
|
+
* BrainBank — Memory Plugin
|
|
6
6
|
*
|
|
7
7
|
* Agent learns from completed tasks — stores patterns,
|
|
8
8
|
* consolidates failures, distills strategies.
|
|
@@ -11,9 +11,7 @@ import 'better-sqlite3';
|
|
|
11
11
|
* brain.use(memory());
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Create an agent memory (learning) module. */
|
|
17
|
-
declare function memory(opts?: MemoryModuleOptions): BrainBankModule;
|
|
14
|
+
/** Create an agent memory plugin. */
|
|
15
|
+
declare function memory(): Indexer;
|
|
18
16
|
|
|
19
|
-
export {
|
|
17
|
+
export { memory };
|
package/dist/memory.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Consolidator,
|
|
3
3
|
PatternStore
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-X6645UVR.js";
|
|
5
|
+
import "./chunk-QNHBCOKB.js";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-7QVYU63E.js";
|
|
9
9
|
|
|
10
|
-
// src/memory/
|
|
10
|
+
// src/memory/distiller.ts
|
|
11
11
|
var StrategyDistiller = class {
|
|
12
12
|
constructor(_db) {
|
|
13
13
|
this._db = _db;
|
|
@@ -80,13 +80,10 @@ var StrategyDistiller = class {
|
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
-
// src/
|
|
84
|
-
var
|
|
85
|
-
constructor(opts = {}) {
|
|
86
|
-
this.opts = opts;
|
|
87
|
-
}
|
|
83
|
+
// src/indexers/memory/memory-plugin.ts
|
|
84
|
+
var MemoryPlugin = class {
|
|
88
85
|
static {
|
|
89
|
-
__name(this, "
|
|
86
|
+
__name(this, "MemoryPlugin");
|
|
90
87
|
}
|
|
91
88
|
name = "memory";
|
|
92
89
|
hnsw;
|
|
@@ -111,7 +108,7 @@ var MemoryModuleImpl = class {
|
|
|
111
108
|
/** Store a learned pattern. */
|
|
112
109
|
async learn(pattern) {
|
|
113
110
|
const id = await this.patternStore.learn(pattern);
|
|
114
|
-
if (this.patternStore.count % 50 === 0) {
|
|
111
|
+
if (this.patternStore.count > 0 && this.patternStore.count % 50 === 0) {
|
|
115
112
|
this.consolidator.consolidate();
|
|
116
113
|
}
|
|
117
114
|
return id;
|
|
@@ -136,8 +133,8 @@ var MemoryModuleImpl = class {
|
|
|
136
133
|
};
|
|
137
134
|
}
|
|
138
135
|
};
|
|
139
|
-
function memory(
|
|
140
|
-
return new
|
|
136
|
+
function memory() {
|
|
137
|
+
return new MemoryPlugin();
|
|
141
138
|
}
|
|
142
139
|
__name(memory, "memory");
|
|
143
140
|
export {
|
package/dist/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/memory/
|
|
1
|
+
{"version":3,"sources":["../src/memory/distiller.ts","../src/indexers/memory/memory-plugin.ts"],"sourcesContent":["/**\n * BrainBank — Strategy Distiller\n * \n * Aggregates top patterns for a task type into a single strategy text.\n * Analogous to SONA's Deep Loop — periodic knowledge distillation.\n */\n\nimport type { Database } from '../db/database.ts';\nimport type { DistilledStrategy } from '../types.ts';\n\nexport class StrategyDistiller {\n constructor(private _db: Database) {}\n\n /**\n * Distill top patterns for a task type into a strategy.\n * Updates the distilled_strategies table.\n */\n distill(taskType: string, topK: number = 10): DistilledStrategy | null {\n const patterns = this._db.prepare(`\n SELECT task, approach, outcome, critique, success_rate\n FROM memory_patterns\n WHERE task_type = ? AND success_rate >= 0.7\n ORDER BY success_rate DESC, created_at DESC\n LIMIT ?\n `).all(taskType, topK) as any[];\n\n if (patterns.length === 0) return null;\n\n // Build strategy text from top patterns\n const lines: string[] = [];\n const avgSuccess = patterns.reduce((sum: number, p: any) => sum + p.success_rate, 0) / patterns.length;\n\n lines.push(`Strategy for \"${taskType}\" (${patterns.length} patterns, avg success ${Math.round(avgSuccess * 100)}%):`);\n lines.push('');\n\n for (const p of patterns) {\n lines.push(`• ${p.approach} (${Math.round(p.success_rate * 100)}%)`);\n if (p.critique) lines.push(` └ ${p.critique}`);\n }\n\n const strategy = lines.join('\\n');\n const confidence = avgSuccess;\n const now = Math.floor(Date.now() / 1000);\n\n this._db.prepare(`\n INSERT INTO distilled_strategies (task_type, strategy, confidence, updated_at)\n VALUES (?, ?, ?, ?)\n ON CONFLICT(task_type) DO UPDATE SET\n strategy = excluded.strategy,\n confidence = excluded.confidence,\n updated_at = excluded.updated_at\n `).run(taskType, strategy, confidence, now);\n\n return { taskType, strategy, confidence, updatedAt: now };\n }\n\n /**\n * Get a distilled strategy for a task type.\n */\n get(taskType: string): DistilledStrategy | null {\n const row = this._db.prepare(\n 'SELECT * FROM distilled_strategies WHERE task_type = ?'\n ).get(taskType) as any;\n\n if (!row) return null;\n return {\n taskType: row.task_type,\n strategy: row.strategy,\n confidence: row.confidence,\n updatedAt: row.updated_at,\n };\n }\n\n /**\n * List all distilled strategies.\n */\n list(): DistilledStrategy[] {\n const rows = this._db.prepare(\n 'SELECT * FROM distilled_strategies ORDER BY confidence DESC'\n ).all() as any[];\n\n return rows.map(r => ({\n taskType: r.task_type,\n strategy: r.strategy,\n confidence: r.confidence,\n updatedAt: r.updated_at,\n }));\n }\n}\n","/**\n * BrainBank — Memory Plugin\n * \n * Agent learns from completed tasks — stores patterns,\n * consolidates failures, distills strategies.\n * \n * import { memory } from 'brainbank/memory';\n * brain.use(memory());\n */\n\nimport type { Indexer, IndexerContext } from '../base.ts';\nimport type { HNSWIndex } from '../../providers/vector/hnsw.ts';\nimport type { Database } from '../../db/database.ts';\nimport { PatternStore } from '../../memory/store.ts';\nimport { Consolidator } from '../../memory/consolidator.ts';\nimport { StrategyDistiller } from '../../memory/distiller.ts';\nimport type { LearningPattern, DistilledStrategy } from '../../types.ts';\n\nclass MemoryPlugin implements Indexer {\n readonly name = 'memory';\n hnsw!: HNSWIndex;\n patternStore!: PatternStore;\n consolidator!: Consolidator;\n distiller!: StrategyDistiller;\n vecCache = new Map<number, Float32Array>();\n private _db!: Database;\n\n async initialize(ctx: IndexerContext): Promise<void> {\n this._db = ctx.db;\n this.hnsw = await ctx.createHnsw(100_000);\n ctx.loadVectors('memory_vectors', 'pattern_id', this.hnsw, this.vecCache);\n\n this.patternStore = new PatternStore({\n db: ctx.db,\n hnsw: this.hnsw,\n vectorCache: this.vecCache,\n embedding: ctx.embedding,\n });\n\n this.consolidator = new Consolidator(ctx.db, this.vecCache);\n this.distiller = new StrategyDistiller(ctx.db);\n }\n\n /** Store a learned pattern. */\n async learn(pattern: LearningPattern): Promise<number> {\n const id = await this.patternStore.learn(pattern);\n\n // Auto-consolidate every 50 patterns (guard against count=0)\n if (this.patternStore.count > 0 && this.patternStore.count % 50 === 0) {\n this.consolidator.consolidate();\n }\n\n return id;\n }\n\n /** Search for similar patterns. */\n async search(query: string, k: number = 4): Promise<(LearningPattern & { score: number })[]> {\n return this.patternStore.search(query, k);\n }\n\n /** Consolidate: prune old failures + deduplicate. */\n consolidate(): { pruned: number; deduped: number } {\n return this.consolidator.consolidate();\n }\n\n /** Distill patterns into a strategy. */\n distill(taskType: string): DistilledStrategy | null {\n return this.distiller.distill(taskType);\n }\n\n stats(): Record<string, any> {\n return {\n patterns: this.patternStore.count,\n avgSuccess: (this._db.prepare('SELECT AVG(success_rate) as a FROM memory_patterns').get() as any).a ?? 0,\n hnswSize: this.hnsw.size,\n };\n }\n}\n\n/** Create an agent memory plugin. */\nexport function memory(): Indexer {\n return new MemoryPlugin();\n}\n"],"mappings":"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","names":[]}
|
package/dist/notes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as Indexer } from './base-9vfWRHCV.js';
|
|
2
2
|
import 'better-sqlite3';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -11,9 +11,7 @@ import 'better-sqlite3';
|
|
|
11
11
|
* brain.use(notes());
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/** Create a notes memory module. */
|
|
17
|
-
declare function notes(opts?: NotesModuleOptions): BrainBankModule;
|
|
14
|
+
/** Create a notes plugin. */
|
|
15
|
+
declare function notes(): Indexer;
|
|
18
16
|
|
|
19
|
-
export {
|
|
17
|
+
export { notes };
|