@soulcraft/brainy 3.9.0 → 3.10.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.
Files changed (43) hide show
  1. package/README.md +89 -33
  2. package/dist/augmentations/KnowledgeAugmentation.d.ts +40 -0
  3. package/dist/augmentations/KnowledgeAugmentation.js +251 -0
  4. package/dist/augmentations/defaultAugmentations.d.ts +1 -0
  5. package/dist/augmentations/defaultAugmentations.js +5 -0
  6. package/dist/brainy.d.ts +11 -0
  7. package/dist/brainy.js +87 -1
  8. package/dist/embeddings/EmbeddingManager.js +14 -2
  9. package/dist/utils/mutex.d.ts +2 -0
  10. package/dist/utils/mutex.js +14 -3
  11. package/dist/vfs/ConceptSystem.d.ts +202 -0
  12. package/dist/vfs/ConceptSystem.js +598 -0
  13. package/dist/vfs/EntityManager.d.ts +75 -0
  14. package/dist/vfs/EntityManager.js +216 -0
  15. package/dist/vfs/EventRecorder.d.ts +83 -0
  16. package/dist/vfs/EventRecorder.js +292 -0
  17. package/dist/vfs/FSCompat.d.ts +85 -0
  18. package/dist/vfs/FSCompat.js +257 -0
  19. package/dist/vfs/GitBridge.d.ts +167 -0
  20. package/dist/vfs/GitBridge.js +537 -0
  21. package/dist/vfs/KnowledgeAugmentation.d.ts +104 -0
  22. package/dist/vfs/KnowledgeAugmentation.js +146 -0
  23. package/dist/vfs/KnowledgeLayer.d.ts +35 -0
  24. package/dist/vfs/KnowledgeLayer.js +443 -0
  25. package/dist/vfs/PathResolver.d.ts +96 -0
  26. package/dist/vfs/PathResolver.js +362 -0
  27. package/dist/vfs/PersistentEntitySystem.d.ts +163 -0
  28. package/dist/vfs/PersistentEntitySystem.js +525 -0
  29. package/dist/vfs/SemanticVersioning.d.ts +105 -0
  30. package/dist/vfs/SemanticVersioning.js +318 -0
  31. package/dist/vfs/VirtualFileSystem.d.ts +246 -0
  32. package/dist/vfs/VirtualFileSystem.js +1927 -0
  33. package/dist/vfs/importers/DirectoryImporter.d.ts +86 -0
  34. package/dist/vfs/importers/DirectoryImporter.js +298 -0
  35. package/dist/vfs/index.d.ts +19 -0
  36. package/dist/vfs/index.js +26 -0
  37. package/dist/vfs/streams/VFSReadStream.d.ts +19 -0
  38. package/dist/vfs/streams/VFSReadStream.js +54 -0
  39. package/dist/vfs/streams/VFSWriteStream.d.ts +21 -0
  40. package/dist/vfs/streams/VFSWriteStream.js +70 -0
  41. package/dist/vfs/types.d.ts +330 -0
  42. package/dist/vfs/types.js +46 -0
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -9,15 +9,15 @@
9
9
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10
10
  [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
11
11
 
12
- **🧠 Brainy 3.0 - Universal Knowledge Protocol™**
12
+ **🧠 Brainy - The Knowledge Operating System**
13
13
 
14
- **World's first Triple Intelligence™ database** unifying vector similarity, graph relationships, and document filtering in one magical API. **Framework-friendly design** works seamlessly with Next.js, React, Vue, Angular, and any modern JavaScript framework.
14
+ **The world's first Knowledge Operating System** where every piece of knowledge - files, concepts, entities, ideas - exists as living information that understands itself, evolves over time, and connects to everything related. Built on revolutionary Triple Intelligence™ that unifies vector similarity, graph relationships, and document filtering in one magical API.
15
15
 
16
- **Why Brainy Leads**: We're the first to solve the impossible—combining three different database paradigms (vector, graph, document) into one unified query interface. This breakthrough enables us to be the Universal Knowledge Protocol where all tools, augmentations, and AI models speak the same language.
16
+ **Why Brainy Changes Everything**: Traditional systems trap knowledge in files or database rows. Brainy liberates it. Your characters exist across stories. Your concepts span projects. Your APIs remember their evolution. Every piece of knowledge - whether it's code, prose, or pure ideas - lives, breathes, and connects in a unified intelligence layer where everything understands its meaning, remembers its history, and relates to everything else.
17
17
 
18
18
  **Framework-first design.** Built for modern web development with zero configuration and automatic framework compatibility. O(log n) performance, <10ms search latency, production-ready.
19
19
 
20
- ## 🎉 What's New in 3.0
20
+ ## 🎉 Key Features
21
21
 
22
22
  ### 🧠 **Triple Intelligence™ Engine**
23
23
 
@@ -49,7 +49,7 @@ npm install @soulcraft/brainy
49
49
  ### 🎯 **True Zero Configuration**
50
50
 
51
51
  ```javascript
52
- import {Brainy} from '@soulcraft/brainy'
52
+ import { Brainy, NounType } from '@soulcraft/brainy'
53
53
 
54
54
  // Just this - auto-detects everything!
55
55
  const brain = new Brainy()
@@ -58,7 +58,7 @@ await brain.init()
58
58
  // Add entities with automatic embedding
59
59
  const jsId = await brain.add({
60
60
  data: "JavaScript is a programming language",
61
- type: "concept",
61
+ nounType: NounType.Concept,
62
62
  metadata: {
63
63
  type: "language",
64
64
  year: 1995,
@@ -68,7 +68,7 @@ const jsId = await brain.add({
68
68
 
69
69
  const nodeId = await brain.add({
70
70
  data: "Node.js runtime environment",
71
- type: "concept",
71
+ nounType: NounType.Concept,
72
72
  metadata: {
73
73
  type: "runtime",
74
74
  year: 2009,
@@ -100,7 +100,7 @@ const filtered = await brain.find({
100
100
 
101
101
  ## 🌐 Framework Integration
102
102
 
103
- **Brainy 3.0 is framework-first!** Works seamlessly with any modern JavaScript framework:
103
+ **Brainy is framework-first!** Works seamlessly with any modern JavaScript framework:
104
104
 
105
105
  ### ⚛️ **React & Next.js**
106
106
  ```javascript
@@ -182,7 +182,7 @@ If using nvm: `nvm use` (we provide a `.nvmrc` file)
182
182
 
183
183
  ### World's First Triple Intelligence™ Engine
184
184
 
185
- **The breakthrough that enables the Universal Knowledge Protocol:**
185
+ **The breakthrough that enables The Knowledge Operating System:**
186
186
 
187
187
  - **Vector Search**: Semantic similarity with HNSW indexing
188
188
  - **Graph Relationships**: Navigate connected knowledge like Neo4j
@@ -190,11 +190,11 @@ If using nvm: `nvm use` (we provide a `.nvmrc` file)
190
190
  - **Unified in ONE API**: No separate queries, no complex joins
191
191
  - **First to solve this**: Others do vector OR graph OR document—we do ALL
192
192
 
193
- ### Universal Knowledge Protocol with Infinite Expressiveness
193
+ ### The Knowledge Operating System with Infinite Expressiveness
194
194
 
195
195
  **Enabled by Triple Intelligence, standardized for everyone:**
196
196
 
197
- - **24 Noun Types × 40 Verb Types**: 960 base combinations
197
+ - **31 Noun Types × 40 Verb Types**: 1,240 base combinations
198
198
  - **∞ Expressiveness**: Unlimited metadata = model ANY data
199
199
  - **One Language**: All tools, augmentations, AI models speak the same types
200
200
  - **Perfect Interoperability**: Move data between any Brainy instance
@@ -209,12 +209,62 @@ await brain.find("Popular JavaScript libraries similar to Vue")
209
209
  await brain.find("Documentation about authentication from last month")
210
210
  ```
211
211
 
212
+ ### 🧠🌐 **Knowledge Graph + Virtual Filesystem - Where Ideas Come Alive**
213
+
214
+ **Store ANY knowledge. Connect EVERYTHING. Files are optional.**
215
+
216
+ - **Living Knowledge**: Characters, concepts, and systems that exist independently of files
217
+ - **Universal Connections**: Link files to entities, entities to concepts, anything to anything
218
+ - **Semantic Intelligence**: Find knowledge by meaning, not by where it's stored
219
+ - **Optional Files**: Use filesystem operations when helpful, pure knowledge when not
220
+ - **Perfect Memory**: Every piece of knowledge remembers its entire history
221
+ - **Knowledge Evolution**: Watch ideas grow and connect across time and projects
222
+
223
+ ```javascript
224
+ import { Brainy } from '@soulcraft/brainy'
225
+
226
+ const brain = new Brainy({ storage: { type: 'memory' } })
227
+ await brain.init()
228
+ const vfs = brain.vfs()
229
+ await vfs.init()
230
+
231
+ // Start with familiar files if you want
232
+ await vfs.writeFile('/story.txt', 'A tale of adventure...')
233
+
234
+ // But knowledge doesn't need files!
235
+ const alice = await vfs.createEntity({
236
+ name: 'Alice',
237
+ type: 'character',
238
+ description: 'Brave explorer discovering quantum worlds'
239
+ })
240
+
241
+ const quantumPhysics = await vfs.createConcept({
242
+ name: 'Quantum Entanglement',
243
+ domain: 'physics',
244
+ keywords: ['superposition', 'measurement', 'correlation']
245
+ })
246
+
247
+ // Connect EVERYTHING - files, entities, concepts
248
+ await vfs.linkEntities(alice, quantumPhysics, 'studies')
249
+ await vfs.addRelationship('/story.txt', alice.id, 'features')
250
+
251
+ // Find knowledge by meaning, not location
252
+ const physics = await vfs.search('quantum mechanics')
253
+ // Returns: files, entities, concepts, relationships - ALL knowledge
254
+
255
+ // Knowledge transcends boundaries
256
+ const aliceKnowledge = await vfs.getEntityGraph(alice)
257
+ // Her relationships, appearances, evolution - her entire existence
258
+ ```
259
+
260
+ **Your knowledge isn't trapped anymore.** Characters live beyond stories. APIs exist beyond code files. Concepts connect across domains. This is knowledge that happens to support files, not a filesystem that happens to store knowledge.
261
+
212
262
  ### 🎯 Zero Configuration Philosophy
213
263
 
214
- Brainy 3.0 automatically configures **everything**:
264
+ Brainy automatically configures **everything**:
215
265
 
216
266
  ```javascript
217
- import {Brainy} from '@soulcraft/brainy'
267
+ import { Brainy } from '@soulcraft/brainy'
218
268
 
219
269
  // 1. Pure zero-config - detects everything
220
270
  const brain = new Brainy()
@@ -368,6 +418,8 @@ const brain = new Brainy({
368
418
  ### Real-World Example: Social Media Firehose
369
419
 
370
420
  ```javascript
421
+ import { Brainy, NounType } from '@soulcraft/brainy'
422
+
371
423
  // Ingestion nodes (optimized for writes)
372
424
  const ingestionNode = new Brainy({
373
425
  storage: {type: 's3', options: {bucket: 'social-data'}},
@@ -378,7 +430,7 @@ const ingestionNode = new Brainy({
378
430
  // Process Bluesky firehose
379
431
  blueskyStream.on('post', async (post) => {
380
432
  await ingestionNode.add(post, {
381
- nounType: 'social-post',
433
+ nounType: NounType.Message,
382
434
  platform: 'bluesky',
383
435
  author: post.author,
384
436
  timestamp: post.createdAt
@@ -417,21 +469,19 @@ const trending = await searchNode.find('trending AI topics', {
417
469
  ```javascript
418
470
  // Store documentation with rich relationships
419
471
  const apiGuide = await brain.add("REST API Guide", {
420
- nounType: 'document',
472
+ nounType: NounType.Document,
421
473
  title: "API Guide",
422
474
  category: "documentation",
423
475
  version: "2.0"
424
476
  })
425
477
 
426
478
  const author = await brain.add("Jane Developer", {
427
- nounType: 'person',
428
- type: "person",
479
+ nounType: NounType.Person,
429
480
  role: "tech-lead"
430
481
  })
431
482
 
432
483
  const project = await brain.add("E-commerce Platform", {
433
- nounType: 'project',
434
- type: "project",
484
+ nounType: NounType.Project,
435
485
  status: "active"
436
486
  })
437
487
 
@@ -462,21 +512,18 @@ const similar = await brain.search(existingContent, {
462
512
  ```javascript
463
513
  // Store conversation with relationships
464
514
  const userId = await brain.add("User 123", {
465
- nounType: 'user',
466
- type: "user",
515
+ nounType: NounType.User,
467
516
  tier: "premium"
468
517
  })
469
518
 
470
519
  const messageId = await brain.add(userMessage, {
471
- nounType: 'message',
472
- type: "message",
520
+ nounType: NounType.Message,
473
521
  timestamp: Date.now(),
474
522
  session: "abc"
475
523
  })
476
524
 
477
525
  const topicId = await brain.add("Product Support", {
478
- nounType: 'topic',
479
- type: "topic",
526
+ nounType: NounType.Topic,
480
527
  category: "support"
481
528
  })
482
529
 
@@ -602,7 +649,7 @@ for (const cluster of feedbackClusters) {
602
649
  }
603
650
 
604
651
  // Find related documents
605
- const docId = await brain.add("Machine learning guide", { nounType: 'document' })
652
+ const docId = await brain.add("Machine learning guide", { nounType: NounType.Document })
606
653
  const similar = await neural.neighbors(docId, 5)
607
654
  // Returns 5 most similar documents
608
655
 
@@ -637,7 +684,7 @@ Brainy includes enterprise-grade capabilities at no extra cost. **No premium tie
637
684
  - **Built-in monitoring** with metrics and health checks
638
685
  - **Production ready** with circuit breakers and backpressure
639
686
 
640
- 📖 **Enterprise features coming in Brainy 3.1** - Stay tuned!
687
+ 📖 **More enterprise features coming soon** - Stay tuned!
641
688
 
642
689
  ## 📊 Benchmarks
643
690
 
@@ -651,19 +698,20 @@ Brainy includes enterprise-grade capabilities at no extra cost. **No premium tie
651
698
  | Bulk Import (1000 items) | 2.3s | +8MB |
652
699
  | **Production Scale (10M items)** | **5.8ms** | **12GB** |
653
700
 
654
- ## 🔄 Migration from 2.x
701
+ ## 🔄 Migration from Previous Versions
655
702
 
656
- Key changes for upgrading to 3.0:
703
+ Key changes in the latest version:
657
704
 
658
705
  - Search methods consolidated into `search()` and `find()`
659
706
  - Result format now includes full objects with metadata
660
- - New natural language capabilities
707
+ - Enhanced natural language capabilities
708
+ - Distributed architecture support
661
709
 
662
710
  ## 🤝 Contributing
663
711
 
664
712
  We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
665
713
 
666
- ## 🧠 The Universal Knowledge Protocol Explained
714
+ ## 🧠 The Knowledge Operating System Explained
667
715
 
668
716
  ### How We Achieved The Impossible
669
717
 
@@ -678,10 +726,10 @@ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
678
726
  ### The Math of Infinite Expressiveness
679
727
 
680
728
  ```
681
- 24 Nouns × 40 Verbs × ∞ Metadata × Triple Intelligence = Universal Protocol
729
+ 31 Nouns × 40 Verbs × ∞ Metadata × Triple Intelligence = Universal Protocol
682
730
  ```
683
731
 
684
- - **960 base combinations** from standardized types
732
+ - **1,240 base combinations** from standardized types
685
733
  - **∞ domain specificity** via unlimited metadata
686
734
  - **∞ relationship depth** via graph traversal
687
735
  - **= Model ANYTHING**: From quantum physics to social networks
@@ -708,6 +756,14 @@ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
708
756
  - [Next.js Integration](docs/guides/nextjs-integration.md) - **NEW!** React and Next.js examples
709
757
  - [Vue.js Integration](docs/guides/vue-integration.md) - **NEW!** Vue and Nuxt examples
710
758
 
759
+ ### Virtual Filesystem & Knowledge Layer 🧠📁
760
+ - [VFS Core Documentation](docs/vfs/VFS_CORE.md) - **NEW!** Complete filesystem architecture and API
761
+ - [VFS + Knowledge Layer](docs/vfs/VFS_KNOWLEDGE_LAYER.md) - **NEW!** Intelligent knowledge management features
762
+ - [Examples & Scenarios](docs/vfs/VFS_EXAMPLES_SCENARIOS.md) - **NEW!** Real-world use cases and code
763
+ - [VFS API Guide](docs/vfs/VFS_API_GUIDE.md) - Complete API reference
764
+ - [Knowledge Layer API](docs/vfs/KNOWLEDGE_LAYER_API.md) - Advanced knowledge features
765
+ - [Knowledge Layer Overview](docs/KNOWLEDGE_LAYER_OVERVIEW.md) - Non-technical guide
766
+
711
767
  ### Core Documentation
712
768
  - [Getting Started Guide](docs/guides/getting-started.md)
713
769
  - [API Reference](docs/api/README.md)
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Knowledge Layer Augmentation for VFS
3
+ *
4
+ * Adds intelligent features to VFS without modifying core functionality:
5
+ * - Event recording for all operations
6
+ * - Semantic versioning based on content changes
7
+ * - Entity and concept extraction
8
+ * - Git bridge for import/export
9
+ *
10
+ * This is a TRUE augmentation - VFS works perfectly without it
11
+ */
12
+ import { Brainy } from '../brainy.js';
13
+ import { BaseAugmentation } from './brainyAugmentation.js';
14
+ export declare class KnowledgeAugmentation extends BaseAugmentation {
15
+ name: string;
16
+ timing: 'after';
17
+ metadata: 'none';
18
+ operations: any;
19
+ priority: number;
20
+ constructor(config?: any);
21
+ execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
22
+ private eventRecorder?;
23
+ private semanticVersioning?;
24
+ private entitySystem?;
25
+ private conceptSystem?;
26
+ private gitBridge?;
27
+ private originalMethods;
28
+ initialize(context: any): Promise<void>;
29
+ augment(brain: Brainy): Promise<void>;
30
+ /**
31
+ * Wrap a VFS method to add Knowledge Layer functionality
32
+ */
33
+ private wrapMethod;
34
+ /**
35
+ * Add Knowledge Layer methods to VFS
36
+ */
37
+ private addKnowledgeMethods;
38
+ private isSemanticChange;
39
+ cleanup(brain: Brainy): Promise<void>;
40
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Knowledge Layer Augmentation for VFS
3
+ *
4
+ * Adds intelligent features to VFS without modifying core functionality:
5
+ * - Event recording for all operations
6
+ * - Semantic versioning based on content changes
7
+ * - Entity and concept extraction
8
+ * - Git bridge for import/export
9
+ *
10
+ * This is a TRUE augmentation - VFS works perfectly without it
11
+ */
12
+ import { BaseAugmentation } from './brainyAugmentation.js';
13
+ import { EventRecorder } from '../vfs/EventRecorder.js';
14
+ import { SemanticVersioning } from '../vfs/SemanticVersioning.js';
15
+ import { PersistentEntitySystem } from '../vfs/PersistentEntitySystem.js';
16
+ import { ConceptSystem } from '../vfs/ConceptSystem.js';
17
+ import { GitBridge } from '../vfs/GitBridge.js';
18
+ export class KnowledgeAugmentation extends BaseAugmentation {
19
+ constructor(config = {}) {
20
+ super(config);
21
+ this.name = 'knowledge';
22
+ this.timing = 'after'; // Process after VFS operations
23
+ this.metadata = 'none'; // No metadata access needed
24
+ this.operations = []; // VFS-specific augmentation, no operation interception
25
+ this.priority = 100; // Run last
26
+ this.originalMethods = new Map();
27
+ }
28
+ async execute(operation, params, next) {
29
+ // Pass through - this augmentation works at VFS level, not operation level
30
+ return await next();
31
+ }
32
+ async initialize(context) {
33
+ await this.augment(context.brain);
34
+ }
35
+ async augment(brain) {
36
+ // Only augment if VFS exists
37
+ const vfs = brain.vfs?.();
38
+ if (!vfs) {
39
+ console.warn('KnowledgeAugmentation: VFS not found, skipping');
40
+ return;
41
+ }
42
+ // Initialize Knowledge Layer components
43
+ this.eventRecorder = new EventRecorder(brain);
44
+ this.semanticVersioning = new SemanticVersioning(brain);
45
+ this.entitySystem = new PersistentEntitySystem(brain);
46
+ this.conceptSystem = new ConceptSystem(brain);
47
+ this.gitBridge = new GitBridge(vfs, brain);
48
+ // Wrap VFS methods to add intelligence WITHOUT slowing them down
49
+ this.wrapMethod(vfs, 'writeFile', async (original, path, data, options) => {
50
+ // Call original first (stays fast)
51
+ const result = await original.call(vfs, path, data, options);
52
+ // Knowledge processing in background (non-blocking)
53
+ setImmediate(async () => {
54
+ try {
55
+ // Record event
56
+ if (this.eventRecorder) {
57
+ await this.eventRecorder.recordEvent({
58
+ type: 'write',
59
+ path,
60
+ content: data,
61
+ size: data.length,
62
+ author: options?.author || 'system'
63
+ });
64
+ }
65
+ // Check for semantic versioning
66
+ if (this.semanticVersioning) {
67
+ const existingContent = await vfs.readFile(path).catch(() => null);
68
+ const shouldVersion = existingContent && this.isSemanticChange(existingContent, data);
69
+ if (shouldVersion) {
70
+ await this.semanticVersioning.createVersion(path, data, {
71
+ message: 'Automatic semantic version'
72
+ });
73
+ }
74
+ }
75
+ // Extract concepts
76
+ if (this.conceptSystem && options?.extractConcepts !== false) {
77
+ await this.conceptSystem.extractAndLinkConcepts(path, data);
78
+ }
79
+ // Extract entities
80
+ if (this.entitySystem && options?.extractEntities !== false) {
81
+ await this.entitySystem.extractEntities(data.toString('utf8'), data);
82
+ }
83
+ }
84
+ catch (error) {
85
+ // Knowledge Layer errors should not affect VFS operations
86
+ console.debug('KnowledgeLayer background processing error:', error);
87
+ }
88
+ });
89
+ return result;
90
+ });
91
+ this.wrapMethod(vfs, 'unlink', async (original, path) => {
92
+ const result = await original.call(vfs, path);
93
+ // Record deletion event
94
+ setImmediate(async () => {
95
+ if (this.eventRecorder) {
96
+ await this.eventRecorder.recordEvent({
97
+ type: 'delete',
98
+ path,
99
+ author: 'system'
100
+ });
101
+ }
102
+ });
103
+ return result;
104
+ });
105
+ this.wrapMethod(vfs, 'rename', async (original, oldPath, newPath) => {
106
+ const result = await original.call(vfs, oldPath, newPath);
107
+ // Record rename event
108
+ setImmediate(async () => {
109
+ if (this.eventRecorder) {
110
+ await this.eventRecorder.recordEvent({
111
+ type: 'rename',
112
+ path: oldPath,
113
+ metadata: { newPath },
114
+ author: 'system'
115
+ });
116
+ }
117
+ });
118
+ return result;
119
+ });
120
+ // Add Knowledge Layer methods to VFS
121
+ this.addKnowledgeMethods(vfs);
122
+ console.log('✨ Knowledge Layer augmentation enabled');
123
+ }
124
+ /**
125
+ * Wrap a VFS method to add Knowledge Layer functionality
126
+ */
127
+ wrapMethod(vfs, methodName, wrapper) {
128
+ const original = vfs[methodName];
129
+ if (!original)
130
+ return;
131
+ // Store original for cleanup
132
+ this.originalMethods.set(methodName, original);
133
+ // Replace with wrapped version
134
+ vfs[methodName] = async (...args) => {
135
+ return await wrapper(original, ...args);
136
+ };
137
+ }
138
+ /**
139
+ * Add Knowledge Layer methods to VFS
140
+ */
141
+ addKnowledgeMethods(vfs) {
142
+ // Event history
143
+ vfs.getHistory = async (path, options) => {
144
+ if (!this.eventRecorder)
145
+ throw new Error('Knowledge Layer not initialized');
146
+ return await this.eventRecorder.getHistory(path, options);
147
+ };
148
+ vfs.reconstructAtTime = async (path, timestamp) => {
149
+ if (!this.eventRecorder)
150
+ throw new Error('Knowledge Layer not initialized');
151
+ return await this.eventRecorder.reconstructFileAtTime(path, timestamp);
152
+ };
153
+ // Semantic versioning
154
+ vfs.getVersions = async (path) => {
155
+ if (!this.semanticVersioning)
156
+ throw new Error('Knowledge Layer not initialized');
157
+ return await this.semanticVersioning.getVersions(path);
158
+ };
159
+ vfs.restoreVersion = async (path, versionId) => {
160
+ if (!this.semanticVersioning)
161
+ throw new Error('Knowledge Layer not initialized');
162
+ const version = await this.semanticVersioning.getVersion(path, versionId);
163
+ if (version) {
164
+ await vfs.writeFile(path, version);
165
+ }
166
+ };
167
+ // Entities
168
+ vfs.findEntity = async (query) => {
169
+ if (!this.entitySystem)
170
+ throw new Error('Knowledge Layer not initialized');
171
+ return await this.entitySystem.findEntity(query);
172
+ };
173
+ vfs.getEntityAppearances = async (entityId) => {
174
+ if (!this.entitySystem)
175
+ throw new Error('Knowledge Layer not initialized');
176
+ return await this.entitySystem.getEvolution(entityId);
177
+ };
178
+ // Concepts
179
+ vfs.getConcepts = async (path) => {
180
+ if (!this.conceptSystem)
181
+ throw new Error('Knowledge Layer not initialized');
182
+ const concepts = await this.conceptSystem.findConcepts({ manifestedIn: path });
183
+ return concepts;
184
+ };
185
+ vfs.getConceptGraph = async (options) => {
186
+ if (!this.conceptSystem)
187
+ throw new Error('Knowledge Layer not initialized');
188
+ return await this.conceptSystem.getConceptGraph(options);
189
+ };
190
+ // Git bridge
191
+ vfs.exportToGit = async (vfsPath, gitPath) => {
192
+ if (!this.gitBridge)
193
+ throw new Error('Knowledge Layer not initialized');
194
+ return await this.gitBridge.exportToGit(vfsPath, gitPath);
195
+ };
196
+ vfs.importFromGit = async (gitPath, vfsPath) => {
197
+ if (!this.gitBridge)
198
+ throw new Error('Knowledge Layer not initialized');
199
+ return await this.gitBridge.importFromGit(gitPath, vfsPath);
200
+ };
201
+ // Temporal coupling
202
+ vfs.findTemporalCoupling = async (path, windowMs) => {
203
+ if (!this.eventRecorder)
204
+ throw new Error('Knowledge Layer not initialized');
205
+ return await this.eventRecorder.findTemporalCoupling(path, windowMs);
206
+ };
207
+ }
208
+ isSemanticChange(oldContent, newContent) {
209
+ // Simple heuristic - significant size change or different content
210
+ const oldStr = oldContent.toString('utf8');
211
+ const newStr = newContent.toString('utf8');
212
+ // Check for significant size change (>10%)
213
+ const sizeDiff = Math.abs(oldStr.length - newStr.length) / oldStr.length;
214
+ if (sizeDiff > 0.1)
215
+ return true;
216
+ // Check for structural changes (simplified)
217
+ const oldLines = oldStr.split('\n').filter(l => l.trim());
218
+ const newLines = newStr.split('\n').filter(l => l.trim());
219
+ // Different number of non-empty lines
220
+ return Math.abs(oldLines.length - newLines.length) > 5;
221
+ }
222
+ async cleanup(brain) {
223
+ const vfs = brain.vfs?.();
224
+ if (!vfs)
225
+ return;
226
+ // Restore original methods
227
+ for (const [methodName, original] of this.originalMethods) {
228
+ vfs[methodName] = original;
229
+ }
230
+ // Remove added methods
231
+ delete vfs.getHistory;
232
+ delete vfs.reconstructAtTime;
233
+ delete vfs.getVersions;
234
+ delete vfs.restoreVersion;
235
+ delete vfs.findEntity;
236
+ delete vfs.getEntityAppearances;
237
+ delete vfs.getConcepts;
238
+ delete vfs.getConceptGraph;
239
+ delete vfs.exportToGit;
240
+ delete vfs.importFromGit;
241
+ delete vfs.findTemporalCoupling;
242
+ // Clean up components
243
+ this.eventRecorder = undefined;
244
+ this.semanticVersioning = undefined;
245
+ this.entitySystem = undefined;
246
+ this.conceptSystem = undefined;
247
+ this.gitBridge = undefined;
248
+ console.log('Knowledge Layer augmentation removed');
249
+ }
250
+ }
251
+ //# sourceMappingURL=KnowledgeAugmentation.js.map
@@ -25,6 +25,7 @@ export declare function createDefaultAugmentations(config?: {
25
25
  metrics?: boolean | Record<string, any>;
26
26
  monitoring?: boolean | Record<string, any>;
27
27
  display?: boolean | Record<string, any>;
28
+ knowledge?: boolean | Record<string, any>;
28
29
  }): BaseAugmentation[];
29
30
  /**
30
31
  * Get augmentation by name with type safety
@@ -11,6 +11,7 @@ import { CacheAugmentation } from './cacheAugmentation.js';
11
11
  import { MetricsAugmentation } from './metricsAugmentation.js';
12
12
  import { MonitoringAugmentation } from './monitoringAugmentation.js';
13
13
  import { UniversalDisplayAugmentation } from './universalDisplayAugmentation.js';
14
+ import { KnowledgeAugmentation } from './KnowledgeAugmentation.js';
14
15
  /**
15
16
  * Create default augmentations for zero-config operation
16
17
  * Returns an array of augmentations to be registered
@@ -44,6 +45,10 @@ export function createDefaultAugmentations(config = {}) {
44
45
  const monitoringConfig = typeof config.monitoring === 'object' ? config.monitoring : {};
45
46
  augmentations.push(new MonitoringAugmentation(monitoringConfig));
46
47
  }
48
+ // Knowledge Layer augmentation for VFS intelligence
49
+ if (config.knowledge !== false) {
50
+ augmentations.push(new KnowledgeAugmentation());
51
+ }
47
52
  return augmentations;
48
53
  }
49
54
  /**
package/dist/brainy.d.ts CHANGED
@@ -8,6 +8,7 @@ import { Vector } from './coreTypes.js';
8
8
  import { ImprovedNeuralAPI } from './neural/improvedNeuralAPI.js';
9
9
  import { NaturalLanguageProcessor } from './neural/naturalLanguageProcessor.js';
10
10
  import { TripleIntelligenceSystem } from './triple/TripleIntelligenceSystem.js';
11
+ import { VirtualFileSystem } from './vfs/VirtualFileSystem.js';
11
12
  import { Entity, Relation, Result, AddParams, UpdateParams, RelateParams, FindParams, SimilarParams, GetRelationsParams, AddManyParams, DeleteManyParams, RelateManyParams, BatchResult, BrainyConfig } from './types/brainy.types.js';
12
13
  import { NounType } from './types/graphTypes.js';
13
14
  import { BrainyInterface } from './types/brainyDataInterface.js';
@@ -34,6 +35,7 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
34
35
  private _neural?;
35
36
  private _nlp?;
36
37
  private _tripleIntelligence?;
38
+ private _vfs?;
37
39
  private initialized;
38
40
  private dimensions?;
39
41
  constructor(config?: BrainyConfig);
@@ -48,6 +50,10 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
48
50
  * Ensure Brainy is initialized
49
51
  */
50
52
  private ensureInitialized;
53
+ /**
54
+ * Check if Brainy is initialized
55
+ */
56
+ get isInitialized(): boolean;
51
57
  /**
52
58
  * Add an entity to the database
53
59
  */
@@ -133,6 +139,10 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
133
139
  * Natural Language Processing API
134
140
  */
135
141
  nlp(): NaturalLanguageProcessor;
142
+ /**
143
+ * Virtual File System API - Knowledge Operating System
144
+ */
145
+ vfs(): VirtualFileSystem;
136
146
  /**
137
147
  * Data Management API - backup, restore, import, export
138
148
  */
@@ -333,6 +343,7 @@ export declare class Brainy<T = any> implements BrainyInterface<T> {
333
343
  private verbsToRelations;
334
344
  /**
335
345
  * Embed data into vector
346
+ * Handles any data type by converting to string representation
336
347
  */
337
348
  embed(data: any): Promise<Vector>;
338
349
  /**