@soulcraft/brainy 3.20.2 → 3.20.4

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 (90) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/bin/brainy-interactive.js +2 -2
  3. package/dist/brainy.d.ts +1 -1
  4. package/dist/mcp/brainyMCPAdapter.d.ts +1 -1
  5. package/dist/mcp/brainyMCPService.d.ts +1 -1
  6. package/dist/neural/embeddedPatterns.d.ts +1 -1
  7. package/dist/neural/embeddedPatterns.js +1 -1
  8. package/dist/shared/default-augmentations.d.ts +1 -1
  9. package/dist/storage/adapters/fileSystemStorage.js +30 -17
  10. package/dist/types/{brainyDataInterface.js → brainyInterface.js} +1 -1
  11. package/package.json +1 -1
  12. package/dist/augmentationFactory.d.ts +0 -86
  13. package/dist/augmentationFactory.js +0 -342
  14. package/dist/augmentationRegistry.d.ts +0 -38
  15. package/dist/augmentationRegistry.js +0 -54
  16. package/dist/augmentationRegistryLoader.d.ts +0 -146
  17. package/dist/augmentationRegistryLoader.js +0 -213
  18. package/dist/augmentations/KnowledgeAugmentation.d.ts +0 -40
  19. package/dist/augmentations/KnowledgeAugmentation.js +0 -251
  20. package/dist/augmentations/intelligentVerbScoring.d.ts +0 -158
  21. package/dist/augmentations/intelligentVerbScoring.js +0 -377
  22. package/dist/augmentations/marketplace/AugmentationMarketplace.d.ts +0 -168
  23. package/dist/augmentations/marketplace/AugmentationMarketplace.js +0 -329
  24. package/dist/augmentations/marketplace/cli.d.ts +0 -47
  25. package/dist/augmentations/marketplace/cli.js +0 -265
  26. package/dist/augmentations/memoryAugmentations.d.ts +0 -72
  27. package/dist/augmentations/memoryAugmentations.js +0 -280
  28. package/dist/augmentations/serverSearchAugmentations.d.ts +0 -190
  29. package/dist/augmentations/serverSearchAugmentations.js +0 -586
  30. package/dist/brainy-unified.d.ts +0 -106
  31. package/dist/brainy-unified.js +0 -327
  32. package/dist/brainyData.d.ts +0 -1832
  33. package/dist/brainyData.js +0 -6443
  34. package/dist/brainyDataV3.d.ts +0 -186
  35. package/dist/brainyDataV3.js +0 -337
  36. package/dist/config/distributedPresets-new.d.ts +0 -118
  37. package/dist/config/distributedPresets-new.js +0 -318
  38. package/dist/config/modelPrecisionManager.d.ts +0 -42
  39. package/dist/config/modelPrecisionManager.js +0 -98
  40. package/dist/connectors/interfaces/IConnector.d.ts +0 -143
  41. package/dist/connectors/interfaces/IConnector.js +0 -8
  42. package/dist/demo.d.ts +0 -106
  43. package/dist/demo.js +0 -201
  44. package/dist/embeddings/SingletonModelManager.d.ts +0 -95
  45. package/dist/embeddings/SingletonModelManager.js +0 -220
  46. package/dist/embeddings/lightweight-embedder.d.ts +0 -22
  47. package/dist/embeddings/lightweight-embedder.js +0 -128
  48. package/dist/embeddings/model-manager.d.ts +0 -39
  49. package/dist/embeddings/model-manager.js +0 -245
  50. package/dist/embeddings/universal-memory-manager.d.ts +0 -38
  51. package/dist/embeddings/universal-memory-manager.js +0 -166
  52. package/dist/embeddings/worker-embedding.d.ts +0 -7
  53. package/dist/embeddings/worker-embedding.js +0 -73
  54. package/dist/embeddings/worker-manager.d.ts +0 -28
  55. package/dist/embeddings/worker-manager.js +0 -162
  56. package/dist/examples/basicUsage.d.ts +0 -4
  57. package/dist/examples/basicUsage.js +0 -121
  58. package/dist/indices/fieldIndex.d.ts +0 -76
  59. package/dist/indices/fieldIndex.js +0 -357
  60. package/dist/mcp/brainyMCPBroadcast.d.ts +0 -82
  61. package/dist/mcp/brainyMCPBroadcast.js +0 -303
  62. package/dist/mcp/brainyMCPClient.d.ts +0 -92
  63. package/dist/mcp/brainyMCPClient.js +0 -258
  64. package/dist/scripts/precomputePatternEmbeddings.d.ts +0 -19
  65. package/dist/scripts/precomputePatternEmbeddings.js +0 -100
  66. package/dist/utils/cacheAutoConfig.d.ts +0 -63
  67. package/dist/utils/cacheAutoConfig.js +0 -261
  68. package/dist/utils/hybridModelManager.d.ts +0 -64
  69. package/dist/utils/hybridModelManager.js +0 -95
  70. package/dist/utils/statistics.d.ts +0 -28
  71. package/dist/utils/statistics.js +0 -25
  72. package/dist/vfs/ConceptSystem.d.ts +0 -203
  73. package/dist/vfs/ConceptSystem.js +0 -545
  74. package/dist/vfs/EntityManager.d.ts +0 -75
  75. package/dist/vfs/EntityManager.js +0 -216
  76. package/dist/vfs/EventRecorder.d.ts +0 -84
  77. package/dist/vfs/EventRecorder.js +0 -269
  78. package/dist/vfs/GitBridge.d.ts +0 -167
  79. package/dist/vfs/GitBridge.js +0 -537
  80. package/dist/vfs/KnowledgeAugmentation.d.ts +0 -104
  81. package/dist/vfs/KnowledgeAugmentation.js +0 -146
  82. package/dist/vfs/KnowledgeLayer.d.ts +0 -35
  83. package/dist/vfs/KnowledgeLayer.js +0 -443
  84. package/dist/vfs/PersistentEntitySystem.d.ts +0 -165
  85. package/dist/vfs/PersistentEntitySystem.js +0 -503
  86. package/dist/vfs/SemanticVersioning.d.ts +0 -105
  87. package/dist/vfs/SemanticVersioning.js +0 -309
  88. package/dist/vfs/VFSHealthCheck.d.ts +0 -78
  89. package/dist/vfs/VFSHealthCheck.js +0 -299
  90. /package/dist/types/{brainyDataInterface.d.ts → brainyInterface.d.ts} +0 -0
@@ -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,158 +0,0 @@
1
- import { ICognitionAugmentation, AugmentationResponse } from '../types/augmentations.js';
2
- /**
3
- * Configuration options for the Intelligent Verb Scoring augmentation
4
- */
5
- export interface IVerbScoringConfig {
6
- /** Enable semantic proximity scoring based on entity embeddings */
7
- enableSemanticScoring: boolean;
8
- /** Enable frequency-based weight amplification */
9
- enableFrequencyAmplification: boolean;
10
- /** Enable temporal decay for weights */
11
- enableTemporalDecay: boolean;
12
- /** Decay rate per day for temporal scoring (0-1) */
13
- temporalDecayRate: number;
14
- /** Minimum weight threshold */
15
- minWeight: number;
16
- /** Maximum weight threshold */
17
- maxWeight: number;
18
- /** Base confidence score for new relationships */
19
- baseConfidence: number;
20
- /** Learning rate for adaptive scoring (0-1) */
21
- learningRate: number;
22
- }
23
- /**
24
- * Default configuration for the Intelligent Verb Scoring augmentation
25
- */
26
- export declare const DEFAULT_VERB_SCORING_CONFIG: IVerbScoringConfig;
27
- /**
28
- * Relationship statistics for learning and adaptation
29
- */
30
- interface RelationshipStats {
31
- count: number;
32
- totalWeight: number;
33
- averageWeight: number;
34
- lastSeen: Date;
35
- firstSeen: Date;
36
- semanticSimilarity?: number;
37
- }
38
- /**
39
- * Intelligent Verb Scoring Cognition Augmentation
40
- *
41
- * Automatically generates intelligent weight and confidence scores for verb relationships
42
- * using semantic analysis, frequency patterns, and temporal factors.
43
- */
44
- export declare class IntelligentVerbScoring implements ICognitionAugmentation {
45
- readonly name = "intelligent-verb-scoring";
46
- readonly description = "Automatically generates intelligent weight and confidence scores for verb relationships";
47
- enabled: boolean;
48
- private config;
49
- private relationshipStats;
50
- private brainyInstance;
51
- private isInitialized;
52
- constructor(config?: Partial<IVerbScoringConfig>);
53
- initialize(): Promise<void>;
54
- shutDown(): Promise<void>;
55
- getStatus(): Promise<'active' | 'inactive' | 'error'>;
56
- /**
57
- * Set reference to the BrainyData instance for accessing graph data
58
- */
59
- setBrainyInstance(instance: any): void;
60
- /**
61
- * Main reasoning method for generating intelligent verb scores
62
- */
63
- reason(query: string, context?: Record<string, unknown>): AugmentationResponse<{
64
- inference: string;
65
- confidence: number;
66
- }>;
67
- infer(dataSubset: Record<string, unknown>): AugmentationResponse<Record<string, unknown>>;
68
- executeLogic(ruleId: string, input: Record<string, unknown>): AugmentationResponse<boolean>;
69
- /**
70
- * Generate intelligent weight and confidence scores for a verb relationship
71
- *
72
- * @param sourceId - ID of the source entity
73
- * @param targetId - ID of the target entity
74
- * @param verbType - Type of the relationship
75
- * @param existingWeight - Existing weight if any
76
- * @param metadata - Additional metadata about the relationship
77
- * @returns Computed weight and confidence scores
78
- */
79
- computeVerbScores(sourceId: string, targetId: string, verbType: string, existingWeight?: number, metadata?: any): Promise<{
80
- weight: number;
81
- confidence: number;
82
- reasoning: string[];
83
- }>;
84
- /**
85
- * Calculate semantic similarity between two entities using their embeddings
86
- */
87
- private calculateSemanticScore;
88
- /**
89
- * Calculate frequency-based boost for repeated relationships
90
- */
91
- private calculateFrequencyBoost;
92
- /**
93
- * Calculate temporal decay factor based on recency
94
- */
95
- private calculateTemporalFactor;
96
- /**
97
- * Calculate learning-based adjustment using historical patterns
98
- */
99
- private calculateLearningAdjustment;
100
- /**
101
- * Update relationship statistics for learning
102
- */
103
- private updateRelationshipStats;
104
- /**
105
- * Blend two scores using a weighted average
106
- */
107
- private blendScores;
108
- /**
109
- * Get current configuration
110
- */
111
- getConfig(): IVerbScoringConfig;
112
- /**
113
- * Update configuration
114
- */
115
- updateConfig(newConfig: Partial<IVerbScoringConfig>): void;
116
- /**
117
- * Get relationship statistics (for debugging/monitoring)
118
- */
119
- getRelationshipStats(): Map<string, RelationshipStats>;
120
- /**
121
- * Clear relationship statistics
122
- */
123
- clearStats(): void;
124
- /**
125
- * Provide feedback to improve future scoring
126
- * This allows the system to learn from user corrections or validation
127
- *
128
- * @param sourceId - Source entity ID
129
- * @param targetId - Target entity ID
130
- * @param verbType - Relationship type
131
- * @param feedbackWeight - The corrected/validated weight (0-1)
132
- * @param feedbackConfidence - The corrected/validated confidence (0-1)
133
- * @param feedbackType - Type of feedback ('correction', 'validation', 'enhancement')
134
- */
135
- provideFeedback(sourceId: string, targetId: string, verbType: string, feedbackWeight: number, feedbackConfidence?: number, feedbackType?: 'correction' | 'validation' | 'enhancement'): Promise<void>;
136
- /**
137
- * Get learning statistics for monitoring and debugging
138
- */
139
- getLearningStats(): {
140
- totalRelationships: number;
141
- averageConfidence: number;
142
- feedbackCount: number;
143
- topRelationships: Array<{
144
- relationship: string;
145
- count: number;
146
- averageWeight: number;
147
- }>;
148
- };
149
- /**
150
- * Export learning data for backup or analysis
151
- */
152
- exportLearningData(): string;
153
- /**
154
- * Import learning data from backup
155
- */
156
- importLearningData(jsonData: string): void;
157
- }
158
- export {};