brainbank 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +19 -9
  2. package/dist/{base-9vfWRHCV.d.ts → base-4SUgeRWT.d.ts} +25 -2
  3. package/dist/{chunk-ZJ5LLMGM.js → chunk-2BEWWQL2.js} +432 -415
  4. package/dist/chunk-2BEWWQL2.js.map +1 -0
  5. package/dist/{chunk-OPQ3ZIPV.js → chunk-5VUYPNH3.js} +47 -3
  6. package/dist/chunk-5VUYPNH3.js.map +1 -0
  7. package/dist/chunk-CCXVL56V.js +120 -0
  8. package/dist/chunk-CCXVL56V.js.map +1 -0
  9. package/dist/{chunk-FEAMUZGJ.js → chunk-E6WQM4DN.js} +3 -3
  10. package/dist/chunk-E6WQM4DN.js.map +1 -0
  11. package/dist/chunk-FI7GWG4W.js +309 -0
  12. package/dist/chunk-FI7GWG4W.js.map +1 -0
  13. package/dist/{chunk-X6645UVR.js → chunk-FINIFKAY.js} +136 -4
  14. package/dist/chunk-FINIFKAY.js.map +1 -0
  15. package/dist/{chunk-4DM3XWO6.js → chunk-MGIFEPYZ.js} +54 -42
  16. package/dist/chunk-MGIFEPYZ.js.map +1 -0
  17. package/dist/{chunk-T2VXF5S5.js → chunk-Y3JKI6QN.js} +152 -137
  18. package/dist/chunk-Y3JKI6QN.js.map +1 -0
  19. package/dist/cli.js +52 -43
  20. package/dist/cli.js.map +1 -1
  21. package/dist/code.d.ts +1 -1
  22. package/dist/code.js +1 -1
  23. package/dist/docs.d.ts +1 -1
  24. package/dist/docs.js +1 -1
  25. package/dist/git.d.ts +1 -1
  26. package/dist/git.js +1 -1
  27. package/dist/index.d.ts +121 -82
  28. package/dist/index.js +66 -15
  29. package/dist/index.js.map +1 -1
  30. package/dist/memory.d.ts +1 -1
  31. package/dist/memory.js +3 -137
  32. package/dist/memory.js.map +1 -1
  33. package/dist/notes.d.ts +1 -1
  34. package/dist/notes.js +4 -49
  35. package/dist/notes.js.map +1 -1
  36. package/dist/{openai-CYDMYX7X.js → openai-embedding-VQZCZQYT.js} +2 -2
  37. package/package.json +1 -1
  38. package/dist/chunk-4DM3XWO6.js.map +0 -1
  39. package/dist/chunk-7JCEW7LT.js +0 -266
  40. package/dist/chunk-7JCEW7LT.js.map +0 -1
  41. package/dist/chunk-FEAMUZGJ.js.map +0 -1
  42. package/dist/chunk-GUT5MSJT.js +0 -99
  43. package/dist/chunk-GUT5MSJT.js.map +0 -1
  44. package/dist/chunk-OPQ3ZIPV.js.map +0 -1
  45. package/dist/chunk-T2VXF5S5.js.map +0 -1
  46. package/dist/chunk-X6645UVR.js.map +0 -1
  47. package/dist/chunk-ZJ5LLMGM.js.map +0 -1
  48. /package/dist/{openai-CYDMYX7X.js.map → openai-embedding-VQZCZQYT.js.map} +0 -0
package/README.md CHANGED
@@ -120,7 +120,7 @@ await brain.index(); // indexes code + git history (incremental)
120
120
 
121
121
  // Search across everything
122
122
  const results = await brain.hybridSearch('authentication middleware');
123
- console.log(results.map(r => `${r.filePath}:${r.line} (${r.score.toFixed(2)})`));
123
+ console.log(results.map(r => `${r.filePath}:L${r.metadata?.startLine} (${r.score.toFixed(2)})`));
124
124
 
125
125
  // Store agent memory
126
126
  const log = brain.collection('decisions');
@@ -134,7 +134,7 @@ await log.add(
134
134
  // Recall later: "what did we decide about password hashing?"
135
135
  const hits = await log.search('password hashing decision');
136
136
 
137
- await brain.close();
137
+ brain.close();
138
138
  ```
139
139
 
140
140
  Or use the CLI — zero code:
@@ -569,7 +569,7 @@ export default {
569
569
  name: 'conversations',
570
570
  async initialize(ctx: IndexerContext) {
571
571
  const conversations = ctx.collection('conversations');
572
- const logsDir = path.join(ctx.repoPath, '.gemini/antigravity/brain');
572
+ const logsDir = path.join(ctx.config.repoPath, '.gemini/antigravity/brain');
573
573
  if (!fs.existsSync(logsDir)) return;
574
574
 
575
575
  for (const dir of fs.readdirSync(logsDir)) {
@@ -632,6 +632,18 @@ The agent passes the `repo` parameter on each tool call based on the active work
632
632
 
633
633
  > Optionally set `BRAINBANK_REPO` as a default fallback repo. If omitted, every tool call must include the `repo` parameter (recommended for multi-workspace setups).
634
634
 
635
+ > [!CAUTION]
636
+ > **Embedding Provider Consistency is Critical**
637
+ >
638
+ > The embedding provider used by the MCP server **must match** the one used during indexing. Mismatched dimensions cause `initialize()` to throw or search to return empty results.
639
+ >
640
+ > **Common failure scenario:**
641
+ > 1. You index via CLI with `BRAINBANK_EMBEDDING=openai` (1536 dims)
642
+ > 2. MCP server starts without `BRAINBANK_EMBEDDING` env var → defaults to local (384 dims)
643
+ > 3. **Result:** BrainBank throws `Embedding dimension mismatch` on every search
644
+ >
645
+ > **Fix:** Always set `BRAINBANK_EMBEDDING` consistently in your MCP config, CLI, and API usage. If you indexed with OpenAI, your MCP config **must** include `"BRAINBANK_EMBEDDING": "openai"`. If you switch providers, run `brainbank reembed` to regenerate all vectors.
646
+
635
647
  ### Available Tools
636
648
 
637
649
  | Tool | Description |
@@ -690,7 +702,8 @@ new OpenAIEmbedding({
690
702
  });
691
703
  ```
692
704
 
693
- > ⚠️ Switching embedding provider requires re-indexing — vectors are not cross-compatible.
705
+ > [!WARNING]
706
+ > Switching embedding provider (e.g. local → OpenAI) changes the vector dimensions. BrainBank will **refuse to initialize** if the stored dimensions don't match the current provider. Use `initialize({ force: true })` and then `reembed()` to migrate, or switch back to the original provider.
694
707
 
695
708
  ### Reranker
696
709
 
@@ -830,7 +843,6 @@ The `LLMProvider` interface works with any framework:
830
843
  |----------|-------------|
831
844
  | `BRAINBANK_REPO` | Default repository path (optional — auto-detected from `.git/` or passed per tool call) |
832
845
  | `BRAINBANK_EMBEDDING` | Embedding provider: `local` (default), `openai` |
833
- | `BRAINBANK_RERANKER` | Reranker: `none` (default), `qwen3` to enable |
834
846
  | `BRAINBANK_DEBUG` | Show full stack traces |
835
847
  | `OPENAI_API_KEY` | Required when using `BRAINBANK_EMBEDDING=openai` |
836
848
 
@@ -976,11 +988,9 @@ import { BrainBank, OpenAIEmbedding } from 'brainbank';
976
988
  const brain = new BrainBank({
977
989
  embeddingProvider: new OpenAIEmbedding(),
978
990
  });
979
- await brain.initialize();
980
991
 
981
- // BrainBank emits 'warning' event if provider changed.
982
- brain.on('warning', (w) => console.warn(w.message));
983
- // → "Embedding provider changed (LocalEmbedding/384 → OpenAIEmbedding/1536). Run brain.reembed()"
992
+ // force: true bypasses the dimension mismatch check for recovery
993
+ await brain.initialize({ force: true });
984
994
 
985
995
  const result = await brain.reembed({
986
996
  onProgress: (table, current, total) => {
@@ -231,7 +231,7 @@ interface PatternResult {
231
231
  interface DocumentResult {
232
232
  type: 'document';
233
233
  score: number;
234
- filePath?: string;
234
+ filePath: string;
235
235
  content: string;
236
236
  context?: string;
237
237
  metadata: DocumentResultMetadata;
@@ -245,6 +245,29 @@ interface CollectionResult {
245
245
  metadata: Record<string, any>;
246
246
  }
247
247
  type SearchResult = CodeResult | CommitResult | PatternResult | DocumentResult | CollectionResult;
248
+ /** Narrow a SearchResult to CodeResult. */
249
+ declare function isCodeResult(r: SearchResult): r is CodeResult;
250
+ /** Narrow a SearchResult to CommitResult. */
251
+ declare function isCommitResult(r: SearchResult): r is CommitResult;
252
+ /** Narrow a SearchResult to DocumentResult. */
253
+ declare function isDocumentResult(r: SearchResult): r is DocumentResult;
254
+ /** Narrow a SearchResult to PatternResult. */
255
+ declare function isPatternResult(r: SearchResult): r is PatternResult;
256
+ /** Narrow a SearchResult to CollectionResult. */
257
+ declare function isCollectionResult(r: SearchResult): r is CollectionResult;
258
+ type MatchHandlers<T> = {
259
+ code?: (r: CodeResult) => T;
260
+ commit?: (r: CommitResult) => T;
261
+ pattern?: (r: PatternResult) => T;
262
+ document?: (r: DocumentResult) => T;
263
+ collection?: (r: CollectionResult) => T;
264
+ _?: (r: SearchResult) => T;
265
+ };
266
+ /**
267
+ * Pattern-match on SearchResult type. Calls the matching handler
268
+ * or the `_` fallback. Returns undefined if no handler matches.
269
+ */
270
+ declare function matchResult<T>(result: SearchResult, handlers: MatchHandlers<T>): T | undefined;
248
271
  interface ContextOptions {
249
272
  /** Max code chunks to include. Default: 6 */
250
273
  codeResults?: number;
@@ -571,4 +594,4 @@ interface CollectionPlugin extends Indexer {
571
594
  listContexts?(): any[];
572
595
  }
573
596
 
574
- export { type SearchResultType as A, type BrainBankConfig as B, Collection as C, type DocumentCollection as D, type EmbeddingProvider as E, type SearchablePlugin as F, type GitCommitRecord as G, HNSWIndex as H, type Indexer as I, type LearningPattern as L, type ProgressCallback as P, type ResolvedConfig as R, type StageProgressCallback as S, type VectorIndex as V, type WatchablePlugin as W, type IndexResult as a, type SearchResult 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 CodeResult as j, type CodeResultMetadata as k, type CollectionAddOptions as l, type CollectionItem as m, type CollectionPlugin as n, type CollectionResult as o, type CollectionSearchOptions as p, type CommitResult as q, type CommitResultMetadata as r, type DistilledStrategy as s, type DocChunk as t, type DocumentResult as u, type DocumentResultMetadata as v, type IndexablePlugin as w, type IndexerContext as x, type PatternResult as y, type PatternResultMetadata as z };
597
+ export { type SearchResultType as A, type BrainBankConfig as B, Collection as C, type DocumentCollection as D, type EmbeddingProvider as E, type SearchablePlugin as F, type GitCommitRecord as G, HNSWIndex as H, type Indexer as I, isCodeResult as J, isCollectionResult as K, type LearningPattern as L, isCommitResult as M, isDocumentResult as N, isPatternResult as O, type ProgressCallback as P, matchResult as Q, type ResolvedConfig as R, type StageProgressCallback as S, type VectorIndex as V, type WatchablePlugin as W, type IndexResult as a, type SearchResult 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 CodeResult as j, type CodeResultMetadata as k, type CollectionAddOptions as l, type CollectionItem as m, type CollectionPlugin as n, type CollectionResult as o, type CollectionSearchOptions as p, type CommitResult as q, type CommitResultMetadata as r, type DistilledStrategy as s, type DocChunk as t, type DocumentResult as u, type DocumentResultMetadata as v, type IndexablePlugin as w, type IndexerContext as x, type PatternResult as y, type PatternResultMetadata as z };