@soulcraft/brainy 6.2.1 → 6.2.2

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 (35) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/brainy.js +2 -3
  3. package/dist/hnsw/hnswIndex.d.ts +6 -0
  4. package/dist/hnsw/hnswIndex.js +81 -8
  5. package/dist/index.d.ts +2 -3
  6. package/dist/index.js +2 -3
  7. package/dist/storage/adapters/azureBlobStorage.js +9 -1
  8. package/dist/storage/adapters/gcsStorage.js +8 -1
  9. package/dist/storage/adapters/s3CompatibleStorage.js +7 -2
  10. package/dist/triple/TripleIntelligenceSystem.d.ts +1 -2
  11. package/package.json +1 -1
  12. package/dist/augmentations/KnowledgeAugmentation.d.ts +0 -40
  13. package/dist/augmentations/KnowledgeAugmentation.js +0 -251
  14. package/dist/importManager.d.ts +0 -78
  15. package/dist/importManager.js +0 -267
  16. package/dist/query/typeInference.d.ts +0 -158
  17. package/dist/query/typeInference.js +0 -760
  18. package/dist/storage/adapters/typeAwareStorageAdapter.d.ts +0 -252
  19. package/dist/storage/adapters/typeAwareStorageAdapter.js +0 -814
  20. package/dist/types/brainyDataInterface.d.ts +0 -52
  21. package/dist/types/brainyDataInterface.js +0 -10
  22. package/dist/vfs/ConceptSystem.d.ts +0 -203
  23. package/dist/vfs/ConceptSystem.js +0 -545
  24. package/dist/vfs/EntityManager.d.ts +0 -75
  25. package/dist/vfs/EntityManager.js +0 -216
  26. package/dist/vfs/EventRecorder.d.ts +0 -84
  27. package/dist/vfs/EventRecorder.js +0 -269
  28. package/dist/vfs/GitBridge.d.ts +0 -167
  29. package/dist/vfs/GitBridge.js +0 -537
  30. package/dist/vfs/KnowledgeLayer.d.ts +0 -35
  31. package/dist/vfs/KnowledgeLayer.js +0 -443
  32. package/dist/vfs/PersistentEntitySystem.d.ts +0 -165
  33. package/dist/vfs/PersistentEntitySystem.js +0 -503
  34. package/dist/vfs/SemanticVersioning.d.ts +0 -105
  35. package/dist/vfs/SemanticVersioning.js +0 -309
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [6.2.2](https://github.com/soulcraftlabs/brainy/compare/v6.2.1...v6.2.2) (2025-11-25)
6
+
7
+ - refactor: remove 3,700+ LOC of unused HNSW implementations (e3146ce)
8
+ - fix(hnsw): entry point recovery prevents import failures and log spam (52eae67)
9
+
10
+
5
11
  ## [6.2.0](https://github.com/soulcraftlabs/brainy/compare/v6.1.0...v6.2.0) (2025-11-20)
6
12
 
7
13
  ### ⚡ Critical Performance Fix
package/dist/brainy.js CHANGED
@@ -6,7 +6,6 @@
6
6
  */
7
7
  import { v4 as uuidv4 } from './universal/uuid.js';
8
8
  import { HNSWIndex } from './hnsw/hnswIndex.js';
9
- import { HNSWIndexOptimized } from './hnsw/hnswIndexOptimized.js';
10
9
  import { TypeAwareHNSWIndex } from './hnsw/typeAwareHNSWIndex.js';
11
10
  import { createStorage } from './storage/storageFactory.js';
12
11
  import { defaultEmbeddingFunction, cosineDistance } from './utils/index.js';
@@ -802,7 +801,7 @@ export class Brainy {
802
801
  if (this.index instanceof TypeAwareHNSWIndex && metadata.noun) {
803
802
  tx.addOperation(new RemoveFromTypeAwareHNSWOperation(this.index, id, noun.vector, metadata.noun));
804
803
  }
805
- else if (this.index instanceof HNSWIndex || this.index instanceof HNSWIndexOptimized) {
804
+ else if (this.index instanceof HNSWIndex) {
806
805
  tx.addOperation(new RemoveFromHNSWOperation(this.index, id, noun.vector));
807
806
  }
808
807
  }
@@ -1887,7 +1886,7 @@ export class Brainy {
1887
1886
  if (this.index instanceof TypeAwareHNSWIndex && metadata.noun) {
1888
1887
  tx.addOperation(new RemoveFromTypeAwareHNSWOperation(this.index, id, noun.vector, metadata.noun));
1889
1888
  }
1890
- else if (this.index instanceof HNSWIndex || this.index instanceof HNSWIndexOptimized) {
1889
+ else if (this.index instanceof HNSWIndex) {
1891
1890
  tx.addOperation(new RemoveFromHNSWOperation(this.index, id, noun.vector));
1892
1891
  }
1893
1892
  }
@@ -83,6 +83,12 @@ export declare class HNSWIndex {
83
83
  * Add a vector to the index
84
84
  */
85
85
  addItem(item: VectorDocument): Promise<string>;
86
+ /**
87
+ * O(1) entry point recovery using highLevelNodes index (v6.2.3).
88
+ * At any reasonable scale (1000+ nodes), level 2+ nodes are guaranteed to exist.
89
+ * For tiny indexes with only level 0-1 nodes, any node works as entry point.
90
+ */
91
+ private recoverEntryPointO1;
86
92
  /**
87
93
  * Search for nearest neighbors
88
94
  */
@@ -210,9 +210,8 @@ export class HNSWIndex {
210
210
  }
211
211
  // Find entry point
212
212
  if (!this.entryPointId) {
213
- console.error('Entry point ID is null');
214
- // If there's no entry point, this is the first noun, so we should have returned earlier
215
- // This is a safety check
213
+ // No entry point but nouns exist - corrupted state, recover by using this item
214
+ // This shouldn't normally happen as first item sets entry point above
216
215
  this.entryPointId = id;
217
216
  this.maxLevel = nounLevel;
218
217
  this.nouns.set(id, noun);
@@ -220,7 +219,7 @@ export class HNSWIndex {
220
219
  }
221
220
  const entryPoint = this.nouns.get(this.entryPointId);
222
221
  if (!entryPoint) {
223
- console.error(`Entry point with ID ${this.entryPointId} not found`);
222
+ // Entry point was deleted but ID not updated - recover by using new item
224
223
  // If the entry point doesn't exist, treat this as the first noun
225
224
  this.entryPointId = id;
226
225
  this.maxLevel = nounLevel;
@@ -383,6 +382,27 @@ export class HNSWIndex {
383
382
  }
384
383
  return id;
385
384
  }
385
+ /**
386
+ * O(1) entry point recovery using highLevelNodes index (v6.2.3).
387
+ * At any reasonable scale (1000+ nodes), level 2+ nodes are guaranteed to exist.
388
+ * For tiny indexes with only level 0-1 nodes, any node works as entry point.
389
+ */
390
+ recoverEntryPointO1() {
391
+ // O(1) recovery: check highLevelNodes from highest to lowest level
392
+ for (let level = this.MAX_TRACKED_LEVELS; level >= 2; level--) {
393
+ const nodesAtLevel = this.highLevelNodes.get(level);
394
+ if (nodesAtLevel && nodesAtLevel.size > 0) {
395
+ for (const nodeId of nodesAtLevel) {
396
+ if (this.nouns.has(nodeId)) {
397
+ return { id: nodeId, level };
398
+ }
399
+ }
400
+ }
401
+ }
402
+ // No high-level nodes - use any available node (works fine for HNSW)
403
+ const firstNode = this.nouns.keys().next().value;
404
+ return { id: firstNode ?? null, level: 0 };
405
+ }
386
406
  /**
387
407
  * Search for nearest neighbors
388
408
  */
@@ -398,14 +418,33 @@ export class HNSWIndex {
398
418
  throw new Error(`Query vector dimension mismatch: expected ${this.dimension}, got ${queryVector.length}`);
399
419
  }
400
420
  // Start from the entry point
421
+ // If entry point is null but nouns exist, attempt O(1) recovery (v6.2.3)
422
+ if (!this.entryPointId && this.nouns.size > 0) {
423
+ const { id: recoveredId, level: recoveredLevel } = this.recoverEntryPointO1();
424
+ if (recoveredId) {
425
+ this.entryPointId = recoveredId;
426
+ this.maxLevel = recoveredLevel;
427
+ }
428
+ }
401
429
  if (!this.entryPointId) {
402
- console.error('Entry point ID is null');
430
+ // Truly empty index - return empty results silently
403
431
  return [];
404
432
  }
405
- const entryPoint = this.nouns.get(this.entryPointId);
433
+ let entryPoint = this.nouns.get(this.entryPointId);
406
434
  if (!entryPoint) {
407
- console.error(`Entry point with ID ${this.entryPointId} not found`);
408
- return [];
435
+ // Entry point ID exists but noun was deleted - O(1) recovery (v6.2.3)
436
+ if (this.nouns.size > 0) {
437
+ const { id: recoveredId, level: recoveredLevel } = this.recoverEntryPointO1();
438
+ if (recoveredId) {
439
+ this.entryPointId = recoveredId;
440
+ this.maxLevel = recoveredLevel;
441
+ entryPoint = this.nouns.get(recoveredId);
442
+ }
443
+ }
444
+ // If still no entry point, return empty
445
+ if (!entryPoint) {
446
+ return [];
447
+ }
409
448
  }
410
449
  let currObj = entryPoint;
411
450
  // OPTIMIZATION: Preload entry point vector
@@ -915,6 +954,40 @@ export class HNSWIndex {
915
954
  offset += batchSize; // v5.7.11: Increment offset for next page
916
955
  }
917
956
  }
957
+ // Step 5: CRITICAL - Recover entry point if missing (v6.2.3 - O(1))
958
+ // This ensures consistency even if getHNSWSystem() returned null
959
+ if (this.nouns.size > 0 && this.entryPointId === null) {
960
+ prodLog.warn('HNSW rebuild: Entry point was null after loading nouns - recovering with O(1) lookup');
961
+ const { id: recoveredId, level: recoveredLevel } = this.recoverEntryPointO1();
962
+ this.entryPointId = recoveredId;
963
+ this.maxLevel = recoveredLevel;
964
+ prodLog.info(`HNSW entry point recovered: ${recoveredId} at level ${recoveredLevel}`);
965
+ // Persist recovered state to prevent future recovery
966
+ if (this.storage && recoveredId) {
967
+ await this.storage.saveHNSWSystem({
968
+ entryPointId: this.entryPointId,
969
+ maxLevel: this.maxLevel
970
+ }).catch((error) => {
971
+ prodLog.error('Failed to persist recovered HNSW system data:', error);
972
+ });
973
+ }
974
+ }
975
+ // Step 6: Validate entry point exists if set (handles stale/deleted entry point)
976
+ if (this.entryPointId && !this.nouns.has(this.entryPointId)) {
977
+ prodLog.warn(`HNSW: Entry point ${this.entryPointId} not found in loaded nouns - recovering with O(1) lookup`);
978
+ const { id: recoveredId, level: recoveredLevel } = this.recoverEntryPointO1();
979
+ this.entryPointId = recoveredId;
980
+ this.maxLevel = recoveredLevel;
981
+ // Persist corrected state
982
+ if (this.storage && recoveredId) {
983
+ await this.storage.saveHNSWSystem({
984
+ entryPointId: this.entryPointId,
985
+ maxLevel: this.maxLevel
986
+ }).catch((error) => {
987
+ prodLog.error('Failed to persist corrected HNSW system data:', error);
988
+ });
989
+ }
990
+ }
918
991
  const cacheInfo = shouldPreload
919
992
  ? ` (vectors preloaded)`
920
993
  : ` (adaptive caching - vectors loaded on-demand)`;
package/dist/index.d.ts CHANGED
@@ -51,9 +51,8 @@ export { StorageAugmentation, DynamicStorageAugmentation, MemoryStorageAugmentat
51
51
  export { WebSocketConduitAugmentation };
52
52
  import type { Vector, VectorDocument, SearchResult, DistanceFunction, EmbeddingFunction, EmbeddingModel, HNSWNoun, HNSWVerb, HNSWConfig, StorageAdapter } from './coreTypes.js';
53
53
  import { HNSWIndex } from './hnsw/hnswIndex.js';
54
- import { HNSWIndexOptimized, HNSWOptimizedConfig } from './hnsw/hnswIndexOptimized.js';
55
- export { HNSWIndex, HNSWIndexOptimized };
56
- export type { Vector, VectorDocument, SearchResult, DistanceFunction, EmbeddingFunction, EmbeddingModel, HNSWNoun, HNSWVerb, HNSWConfig, HNSWOptimizedConfig, StorageAdapter };
54
+ export { HNSWIndex };
55
+ export type { Vector, VectorDocument, SearchResult, DistanceFunction, EmbeddingFunction, EmbeddingModel, HNSWNoun, HNSWVerb, HNSWConfig, StorageAdapter };
57
56
  import type { AugmentationResponse, BrainyAugmentation, BaseAugmentation, AugmentationContext } from './types/augmentations.js';
58
57
  export { AugmentationManager, type AugmentationInfo } from './augmentationManager.js';
59
58
  export type { AugmentationResponse, BrainyAugmentation, BaseAugmentation, AugmentationContext };
package/dist/index.js CHANGED
@@ -111,10 +111,9 @@ MemoryStorageAugmentation, FileSystemStorageAugmentation, OPFSStorageAugmentatio
111
111
  createAutoStorageAugmentation, createStorageAugmentationFromConfig };
112
112
  // Other augmentation exports
113
113
  export { WebSocketConduitAugmentation };
114
- // Export HNSW index and optimized version
114
+ // Export HNSW index
115
115
  import { HNSWIndex } from './hnsw/hnswIndex.js';
116
- import { HNSWIndexOptimized } from './hnsw/hnswIndexOptimized.js';
117
- export { HNSWIndex, HNSWIndexOptimized };
116
+ export { HNSWIndex };
118
117
  // Export augmentation manager for type-safe augmentation management
119
118
  export { AugmentationManager } from './augmentationManager.js';
120
119
  import { NounType, VerbType } from './types/graphTypes.js';
@@ -1269,7 +1269,15 @@ export class AzureBlobStorage extends BaseStorage {
1269
1269
  return JSON.parse(downloaded.toString());
1270
1270
  }
1271
1271
  catch (error) {
1272
- if (error.statusCode === 404 || error.code === 'BlobNotFound') {
1272
+ // Azure may return not found errors in different formats
1273
+ const isNotFound = error.statusCode === 404 ||
1274
+ error.code === 'BlobNotFound' ||
1275
+ error.code === 404 ||
1276
+ error.details?.code === 'BlobNotFound' ||
1277
+ error.message?.includes('BlobNotFound') ||
1278
+ error.message?.includes('not found') ||
1279
+ error.message?.includes('404');
1280
+ if (isNotFound) {
1273
1281
  return null;
1274
1282
  }
1275
1283
  this.logger.error('Failed to get HNSW system data:', error);
@@ -1260,7 +1260,14 @@ export class GcsStorage extends BaseStorage {
1260
1260
  return JSON.parse(contents.toString());
1261
1261
  }
1262
1262
  catch (error) {
1263
- if (error.code === 404) {
1263
+ // GCS may return 404 in different formats depending on SDK version
1264
+ const is404 = error.code === 404 ||
1265
+ error.statusCode === 404 ||
1266
+ error.status === 404 ||
1267
+ error.message?.includes('No such object') ||
1268
+ error.message?.includes('not found') ||
1269
+ error.message?.includes('404');
1270
+ if (is404) {
1264
1271
  return null;
1265
1272
  }
1266
1273
  this.logger.error('Failed to get HNSW system data:', error);
@@ -2829,9 +2829,14 @@ export class S3CompatibleStorage extends BaseStorage {
2829
2829
  return JSON.parse(bodyContents);
2830
2830
  }
2831
2831
  catch (error) {
2832
- if (error.name === 'NoSuchKey' ||
2832
+ // S3 may return not found errors in different formats
2833
+ const isNotFound = error.name === 'NoSuchKey' ||
2834
+ error.code === 'NoSuchKey' ||
2835
+ error.$metadata?.httpStatusCode === 404 ||
2833
2836
  error.message?.includes('NoSuchKey') ||
2834
- error.message?.includes('not found')) {
2837
+ error.message?.includes('not found') ||
2838
+ error.message?.includes('404');
2839
+ if (isNotFound) {
2835
2840
  return null;
2836
2841
  }
2837
2842
  this.logger.error('Failed to get HNSW system data:', error);
@@ -13,7 +13,6 @@
13
13
  * - Fusion: O(k log k) where k = result count
14
14
  */
15
15
  import { HNSWIndex } from '../hnsw/hnswIndex.js';
16
- import { HNSWIndexOptimized } from '../hnsw/hnswIndexOptimized.js';
17
16
  import { TypeAwareHNSWIndex } from '../hnsw/typeAwareHNSWIndex.js';
18
17
  import { MetadataIndexManager } from '../utils/metadataIndex.js';
19
18
  import { Vector } from '../coreTypes.js';
@@ -68,7 +67,7 @@ export declare class TripleIntelligenceSystem {
68
67
  private planner;
69
68
  private embedder;
70
69
  private storage;
71
- constructor(metadataIndex: MetadataIndexManager, hnswIndex: HNSWIndex | HNSWIndexOptimized | TypeAwareHNSWIndex, graphIndex: GraphAdjacencyIndex, embedder: (text: string) => Promise<Vector>, storage: any);
70
+ constructor(metadataIndex: MetadataIndexManager, hnswIndex: HNSWIndex | TypeAwareHNSWIndex, graphIndex: GraphAdjacencyIndex, embedder: (text: string) => Promise<Vector>, storage: any);
72
71
  /**
73
72
  * Main find method - executes Triple Intelligence queries
74
73
  * Phase 3: Now with automatic type inference for 40% latency reduction
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "6.2.1",
3
+ "version": "6.2.2",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. Stage 3 CANONICAL: 42 nouns × 127 verbs covering 96-97% of all human knowledge.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -1,40 +0,0 @@
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
- }
@@ -1,251 +0,0 @@
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
@@ -1,78 +0,0 @@
1
- /**
2
- * Import Manager - Comprehensive data import with intelligent type detection
3
- *
4
- * Handles multiple data sources:
5
- * - Direct data (objects, arrays)
6
- * - Files (JSON, CSV, text)
7
- * - URLs (fetch and parse)
8
- * - Streams (for large files)
9
- *
10
- * Uses NeuralImportAugmentation for intelligent processing
11
- */
12
- import { NounType } from './types/graphTypes.js';
13
- export interface ImportOptions {
14
- source?: 'data' | 'file' | 'url' | 'auto';
15
- format?: 'json' | 'csv' | 'text' | 'yaml' | 'auto';
16
- batchSize?: number;
17
- autoDetect?: boolean;
18
- typeHint?: NounType;
19
- extractRelationships?: boolean;
20
- csvDelimiter?: string;
21
- csvHeaders?: boolean;
22
- parallel?: boolean;
23
- maxConcurrency?: number;
24
- }
25
- export interface ImportResult {
26
- success: boolean;
27
- nouns: string[];
28
- verbs: string[];
29
- errors: string[];
30
- stats: {
31
- total: number;
32
- imported: number;
33
- failed: number;
34
- relationships: number;
35
- };
36
- }
37
- export declare class ImportManager {
38
- private neuralImport;
39
- private typeMatcher;
40
- private brain;
41
- constructor(brain: any);
42
- /**
43
- * Initialize the import manager
44
- */
45
- init(): Promise<void>;
46
- /**
47
- * Main import method - handles all sources
48
- */
49
- import(source: string | Buffer | any[] | any, options?: ImportOptions): Promise<ImportResult>;
50
- /**
51
- * Import from file
52
- */
53
- importFile(filePath: string, options?: ImportOptions): Promise<ImportResult>;
54
- /**
55
- * Import from URL
56
- */
57
- importUrl(url: string, options?: ImportOptions): Promise<ImportResult>;
58
- /**
59
- * Detect source type
60
- */
61
- private detectSourceType;
62
- /**
63
- * Detect format from file path
64
- */
65
- private detectFormatFromPath;
66
- /**
67
- * Read file
68
- */
69
- private readFile;
70
- /**
71
- * Fetch from URL
72
- */
73
- private fetchFromUrl;
74
- }
75
- /**
76
- * Create an import manager instance
77
- */
78
- export declare function createImportManager(brain: any): ImportManager;