@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.
- package/README.md +89 -33
- package/dist/augmentations/KnowledgeAugmentation.d.ts +40 -0
- package/dist/augmentations/KnowledgeAugmentation.js +251 -0
- package/dist/augmentations/defaultAugmentations.d.ts +1 -0
- package/dist/augmentations/defaultAugmentations.js +5 -0
- package/dist/brainy.d.ts +11 -0
- package/dist/brainy.js +87 -1
- package/dist/embeddings/EmbeddingManager.js +14 -2
- package/dist/utils/mutex.d.ts +2 -0
- package/dist/utils/mutex.js +14 -3
- package/dist/vfs/ConceptSystem.d.ts +202 -0
- package/dist/vfs/ConceptSystem.js +598 -0
- package/dist/vfs/EntityManager.d.ts +75 -0
- package/dist/vfs/EntityManager.js +216 -0
- package/dist/vfs/EventRecorder.d.ts +83 -0
- package/dist/vfs/EventRecorder.js +292 -0
- package/dist/vfs/FSCompat.d.ts +85 -0
- package/dist/vfs/FSCompat.js +257 -0
- package/dist/vfs/GitBridge.d.ts +167 -0
- package/dist/vfs/GitBridge.js +537 -0
- package/dist/vfs/KnowledgeAugmentation.d.ts +104 -0
- package/dist/vfs/KnowledgeAugmentation.js +146 -0
- package/dist/vfs/KnowledgeLayer.d.ts +35 -0
- package/dist/vfs/KnowledgeLayer.js +443 -0
- package/dist/vfs/PathResolver.d.ts +96 -0
- package/dist/vfs/PathResolver.js +362 -0
- package/dist/vfs/PersistentEntitySystem.d.ts +163 -0
- package/dist/vfs/PersistentEntitySystem.js +525 -0
- package/dist/vfs/SemanticVersioning.d.ts +105 -0
- package/dist/vfs/SemanticVersioning.js +318 -0
- package/dist/vfs/VirtualFileSystem.d.ts +246 -0
- package/dist/vfs/VirtualFileSystem.js +1927 -0
- package/dist/vfs/importers/DirectoryImporter.d.ts +86 -0
- package/dist/vfs/importers/DirectoryImporter.js +298 -0
- package/dist/vfs/index.d.ts +19 -0
- package/dist/vfs/index.js +26 -0
- package/dist/vfs/streams/VFSReadStream.d.ts +19 -0
- package/dist/vfs/streams/VFSReadStream.js +54 -0
- package/dist/vfs/streams/VFSWriteStream.d.ts +21 -0
- package/dist/vfs/streams/VFSWriteStream.js +70 -0
- package/dist/vfs/types.d.ts +330 -0
- package/dist/vfs/types.js +46 -0
- package/package.json +1 -1
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Bridge for VFS
|
|
3
|
+
*
|
|
4
|
+
* Provides Git import/export capabilities without Git dependencies
|
|
5
|
+
* Enables migration to/from Git repositories while preserving VFS intelligence
|
|
6
|
+
* PRODUCTION-READY: Real implementation using filesystem operations
|
|
7
|
+
*/
|
|
8
|
+
import { NounType } from '../types/graphTypes.js';
|
|
9
|
+
import { v4 as uuidv4 } from '../universal/uuid.js';
|
|
10
|
+
import { createHash } from 'crypto';
|
|
11
|
+
import { promises as fs } from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
/**
|
|
14
|
+
* Git Bridge - Import/Export between VFS and Git repositories
|
|
15
|
+
*
|
|
16
|
+
* Capabilities:
|
|
17
|
+
* - Export VFS to standard Git repository structure
|
|
18
|
+
* - Import Git repository into VFS with intelligence
|
|
19
|
+
* - Preserve VFS metadata and relationships
|
|
20
|
+
* - Convert Git history to VFS events
|
|
21
|
+
* - No Git dependencies - pure filesystem operations
|
|
22
|
+
*/
|
|
23
|
+
export class GitBridge {
|
|
24
|
+
constructor(vfs, brain) {
|
|
25
|
+
this.vfs = vfs;
|
|
26
|
+
this.brain = brain;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Export VFS to Git repository structure
|
|
30
|
+
*/
|
|
31
|
+
async exportToGit(vfsPath, gitRepoPath, options) {
|
|
32
|
+
// Ensure target directory exists
|
|
33
|
+
await fs.mkdir(gitRepoPath, { recursive: true });
|
|
34
|
+
const exportId = uuidv4();
|
|
35
|
+
const timestamp = Date.now();
|
|
36
|
+
const files = [];
|
|
37
|
+
// Initialize Git repository metadata
|
|
38
|
+
const gitRepo = {
|
|
39
|
+
path: gitRepoPath,
|
|
40
|
+
branches: [{ name: options?.branch || 'main', commitHash: '', isActive: true }],
|
|
41
|
+
commits: [],
|
|
42
|
+
files: [],
|
|
43
|
+
metadata: {
|
|
44
|
+
name: path.basename(gitRepoPath),
|
|
45
|
+
description: `Exported from Brainy VFS on ${new Date().toISOString()}`,
|
|
46
|
+
lastImported: timestamp,
|
|
47
|
+
vfsMetadata: {
|
|
48
|
+
exportId,
|
|
49
|
+
sourcePath: vfsPath,
|
|
50
|
+
options
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
// Export files recursively
|
|
55
|
+
await this.exportDirectory(vfsPath, gitRepoPath, '', files, options);
|
|
56
|
+
// Create .vfs-metadata file if preserving metadata
|
|
57
|
+
if (options?.preserveMetadata) {
|
|
58
|
+
await this.exportMetadata(vfsPath, gitRepoPath, options);
|
|
59
|
+
}
|
|
60
|
+
// Create .vfs-relationships file if preserving relationships
|
|
61
|
+
if (options?.preserveRelationships) {
|
|
62
|
+
await this.exportRelationships(vfsPath, gitRepoPath, options);
|
|
63
|
+
}
|
|
64
|
+
// Create .vfs-history file if preserving history
|
|
65
|
+
if (options?.preserveHistory) {
|
|
66
|
+
await this.exportHistory(vfsPath, gitRepoPath, options);
|
|
67
|
+
}
|
|
68
|
+
// Create initial commit metadata
|
|
69
|
+
const commitHash = this.generateCommitHash(files);
|
|
70
|
+
const commit = {
|
|
71
|
+
hash: commitHash,
|
|
72
|
+
message: options?.commitMessage || `Export from Brainy VFS: ${vfsPath}`,
|
|
73
|
+
author: options?.author?.name || 'VFS Export',
|
|
74
|
+
email: options?.author?.email || 'vfs@brainy.local',
|
|
75
|
+
timestamp,
|
|
76
|
+
files: files.map(f => f.path)
|
|
77
|
+
};
|
|
78
|
+
gitRepo.commits = [commit];
|
|
79
|
+
gitRepo.branches[0].commitHash = commitHash;
|
|
80
|
+
gitRepo.files = files;
|
|
81
|
+
// Write repository metadata
|
|
82
|
+
await this.writeRepoMetadata(gitRepoPath, gitRepo);
|
|
83
|
+
// Record export event
|
|
84
|
+
await this.recordGitEvent('export', {
|
|
85
|
+
vfsPath,
|
|
86
|
+
gitRepoPath,
|
|
87
|
+
commitHash,
|
|
88
|
+
fileCount: files.length,
|
|
89
|
+
options
|
|
90
|
+
});
|
|
91
|
+
return gitRepo;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Import Git repository into VFS
|
|
95
|
+
*/
|
|
96
|
+
async importFromGit(gitRepoPath, vfsPath, options) {
|
|
97
|
+
const stats = {
|
|
98
|
+
filesImported: 0,
|
|
99
|
+
eventsCreated: 0,
|
|
100
|
+
entitiesCreated: 0,
|
|
101
|
+
relationshipsCreated: 0
|
|
102
|
+
};
|
|
103
|
+
// Read repository structure
|
|
104
|
+
const gitRepo = await this.readGitRepository(gitRepoPath);
|
|
105
|
+
// Import files
|
|
106
|
+
for (const gitFile of gitRepo.files) {
|
|
107
|
+
// Skip system files unless requested
|
|
108
|
+
if (!options?.includeSystemFiles && gitFile.path.startsWith('.vfs-')) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const targetPath = path.join(vfsPath, gitFile.path);
|
|
112
|
+
// Create directory structure
|
|
113
|
+
const dirPath = path.dirname(targetPath);
|
|
114
|
+
if (dirPath !== vfsPath) {
|
|
115
|
+
try {
|
|
116
|
+
await this.vfs.mkdir(dirPath, { recursive: true });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// Directory might already exist
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Write file
|
|
123
|
+
await this.vfs.writeFile(targetPath, gitFile.content, {
|
|
124
|
+
metadata: {
|
|
125
|
+
gitHash: gitFile.hash,
|
|
126
|
+
gitMode: gitFile.mode,
|
|
127
|
+
importedFrom: gitRepoPath,
|
|
128
|
+
importedAt: Date.now()
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
stats.filesImported++;
|
|
132
|
+
}
|
|
133
|
+
// Import metadata if available and requested
|
|
134
|
+
if (options?.extractMetadata) {
|
|
135
|
+
const metadataFile = path.join(gitRepoPath, '.vfs-metadata.json');
|
|
136
|
+
try {
|
|
137
|
+
const metadataContent = await fs.readFile(metadataFile, 'utf8');
|
|
138
|
+
const metadata = JSON.parse(metadataContent);
|
|
139
|
+
await this.importMetadata(vfsPath, metadata);
|
|
140
|
+
stats.entitiesCreated += Object.keys(metadata.entities || {}).length;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
// No metadata file or invalid format
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Import relationships if available and requested
|
|
147
|
+
if (options?.restoreRelationships) {
|
|
148
|
+
const relationshipsFile = path.join(gitRepoPath, '.vfs-relationships.json');
|
|
149
|
+
try {
|
|
150
|
+
const relationshipsContent = await fs.readFile(relationshipsFile, 'utf8');
|
|
151
|
+
const relationships = JSON.parse(relationshipsContent);
|
|
152
|
+
await this.importRelationships(relationships);
|
|
153
|
+
stats.relationshipsCreated += relationships.length || 0;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
// No relationships file or invalid format
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Import Git history as VFS events if requested
|
|
160
|
+
if (options?.preserveGitHistory) {
|
|
161
|
+
const historyFile = path.join(gitRepoPath, '.vfs-history.json');
|
|
162
|
+
try {
|
|
163
|
+
const historyContent = await fs.readFile(historyFile, 'utf8');
|
|
164
|
+
const history = JSON.parse(historyContent);
|
|
165
|
+
stats.eventsCreated = await this.importHistory(vfsPath, history);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
// Convert Git commits to VFS events
|
|
169
|
+
stats.eventsCreated = await this.convertCommitsToEvents(vfsPath, gitRepo.commits);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Record import event
|
|
173
|
+
await this.recordGitEvent('import', {
|
|
174
|
+
gitRepoPath,
|
|
175
|
+
vfsPath,
|
|
176
|
+
stats,
|
|
177
|
+
options
|
|
178
|
+
});
|
|
179
|
+
return stats;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Export directory recursively
|
|
183
|
+
*/
|
|
184
|
+
async exportDirectory(vfsPath, gitRepoPath, relativePath, files, options) {
|
|
185
|
+
const currentPath = relativePath ? path.join(vfsPath, relativePath) : vfsPath;
|
|
186
|
+
try {
|
|
187
|
+
// Check if path exists in VFS
|
|
188
|
+
const exists = await this.vfs.exists(currentPath);
|
|
189
|
+
if (!exists)
|
|
190
|
+
return;
|
|
191
|
+
// Get directory contents
|
|
192
|
+
const entries = await this.vfs.readdir(currentPath, { withFileTypes: true });
|
|
193
|
+
for (const entry of entries) {
|
|
194
|
+
const entryVfsPath = path.join(currentPath, entry.name);
|
|
195
|
+
const entryRelativePath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
196
|
+
const entryGitPath = path.join(gitRepoPath, entryRelativePath);
|
|
197
|
+
if (entry.type === 'directory') {
|
|
198
|
+
// Create directory in Git repo
|
|
199
|
+
await fs.mkdir(entryGitPath, { recursive: true });
|
|
200
|
+
// Recurse into subdirectory
|
|
201
|
+
await this.exportDirectory(vfsPath, gitRepoPath, entryRelativePath, files, options);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
// Export file
|
|
205
|
+
const content = await this.vfs.readFile(entryVfsPath);
|
|
206
|
+
const stats = await this.vfs.stat(entryVfsPath);
|
|
207
|
+
// Write file to Git repo
|
|
208
|
+
await fs.writeFile(entryGitPath, content);
|
|
209
|
+
// Add to files list
|
|
210
|
+
const gitFile = {
|
|
211
|
+
path: entryRelativePath,
|
|
212
|
+
content,
|
|
213
|
+
hash: createHash('sha1').update(content).digest('hex'),
|
|
214
|
+
mode: stats.mode?.toString(8) || '100644',
|
|
215
|
+
size: content.length,
|
|
216
|
+
lastModified: stats.mtime?.getTime() || Date.now()
|
|
217
|
+
};
|
|
218
|
+
files.push(gitFile);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.warn(`Failed to export directory ${currentPath}:`, error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Export VFS metadata to .vfs-metadata.json
|
|
228
|
+
*/
|
|
229
|
+
async exportMetadata(vfsPath, gitRepoPath, options) {
|
|
230
|
+
const metadata = {
|
|
231
|
+
exportedAt: Date.now(),
|
|
232
|
+
vfsPath,
|
|
233
|
+
version: '1.0',
|
|
234
|
+
entities: {},
|
|
235
|
+
files: {}
|
|
236
|
+
};
|
|
237
|
+
// Collect metadata for all files
|
|
238
|
+
await this.collectFileMetadata(vfsPath, '', metadata);
|
|
239
|
+
// Write metadata file
|
|
240
|
+
const metadataPath = path.join(gitRepoPath, '.vfs-metadata.json');
|
|
241
|
+
await fs.writeFile(metadataPath, JSON.stringify(metadata, null, 2));
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Export relationships to .vfs-relationships.json
|
|
245
|
+
*/
|
|
246
|
+
async exportRelationships(vfsPath, gitRepoPath, options) {
|
|
247
|
+
// Get all relationships for files in the VFS path
|
|
248
|
+
const relationships = [];
|
|
249
|
+
try {
|
|
250
|
+
// Get relationships for the specified path and its children
|
|
251
|
+
const related = await this.vfs.getRelated(vfsPath);
|
|
252
|
+
if (related && related.length > 0) {
|
|
253
|
+
relationships.push({
|
|
254
|
+
path: vfsPath,
|
|
255
|
+
relationships: related
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// If it's a directory, get relationships for all files within
|
|
259
|
+
const stats = await this.vfs.stat(vfsPath);
|
|
260
|
+
if (stats.isDirectory()) {
|
|
261
|
+
const files = await this.vfs.readdir(vfsPath, { recursive: true });
|
|
262
|
+
for (const file of files) {
|
|
263
|
+
const fileName = typeof file === 'string' ? file : file.name;
|
|
264
|
+
const fullPath = path.join(vfsPath, fileName);
|
|
265
|
+
try {
|
|
266
|
+
const fileRelated = await this.vfs.getRelated(fullPath);
|
|
267
|
+
if (fileRelated && fileRelated.length > 0) {
|
|
268
|
+
relationships.push({
|
|
269
|
+
path: fullPath,
|
|
270
|
+
relationships: fileRelated
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (err) {
|
|
275
|
+
// Skip files without relationships
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
catch (err) {
|
|
281
|
+
// Path might not have relationships
|
|
282
|
+
}
|
|
283
|
+
// Write relationships file
|
|
284
|
+
const relationshipsPath = path.join(gitRepoPath, '.vfs-relationships.json');
|
|
285
|
+
await fs.writeFile(relationshipsPath, JSON.stringify(relationships, null, 2));
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Export history to .vfs-history.json
|
|
289
|
+
*/
|
|
290
|
+
async exportHistory(vfsPath, gitRepoPath, options) {
|
|
291
|
+
// Get event history for the VFS path
|
|
292
|
+
const history = {
|
|
293
|
+
exportedAt: Date.now(),
|
|
294
|
+
vfsPath,
|
|
295
|
+
events: []
|
|
296
|
+
};
|
|
297
|
+
// Get history if Knowledge Layer is enabled
|
|
298
|
+
if ('getHistory' in this.vfs && typeof this.vfs.getHistory === 'function') {
|
|
299
|
+
try {
|
|
300
|
+
const events = await this.vfs.getHistory(vfsPath);
|
|
301
|
+
if (events) {
|
|
302
|
+
history.events = events;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
// Knowledge Layer might not be enabled
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// Write history file
|
|
310
|
+
const historyPath = path.join(gitRepoPath, '.vfs-history.json');
|
|
311
|
+
await fs.writeFile(historyPath, JSON.stringify(history, null, 2));
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Collect metadata recursively
|
|
315
|
+
*/
|
|
316
|
+
async collectFileMetadata(vfsPath, relativePath, metadata) {
|
|
317
|
+
const currentPath = relativePath ? path.join(vfsPath, relativePath) : vfsPath;
|
|
318
|
+
try {
|
|
319
|
+
const entries = await this.vfs.readdir(currentPath, { withFileTypes: true });
|
|
320
|
+
for (const entry of entries) {
|
|
321
|
+
const entryPath = path.join(currentPath, entry.name);
|
|
322
|
+
const entryRelativePath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
323
|
+
if (entry.type === 'directory') {
|
|
324
|
+
await this.collectFileMetadata(vfsPath, entryRelativePath, metadata);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
const stats = await this.vfs.stat(entryPath);
|
|
328
|
+
metadata.files[entryRelativePath] = {
|
|
329
|
+
size: stats.size,
|
|
330
|
+
mtime: stats.mtime,
|
|
331
|
+
ctime: stats.ctime,
|
|
332
|
+
mode: stats.mode,
|
|
333
|
+
metadata: stats.metadata || {}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
console.warn(`Failed to collect metadata for ${currentPath}:`, error);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Read Git repository structure
|
|
344
|
+
*/
|
|
345
|
+
async readGitRepository(gitRepoPath) {
|
|
346
|
+
// Read repository metadata if available
|
|
347
|
+
const metadataPath = path.join(gitRepoPath, '.vfs-repo-metadata.json');
|
|
348
|
+
let metadata = {
|
|
349
|
+
name: path.basename(gitRepoPath),
|
|
350
|
+
description: 'Imported Git repository',
|
|
351
|
+
branches: [{ name: 'main', commitHash: '', isActive: true }],
|
|
352
|
+
commits: []
|
|
353
|
+
};
|
|
354
|
+
try {
|
|
355
|
+
const metadataContent = await fs.readFile(metadataPath, 'utf8');
|
|
356
|
+
metadata = { ...metadata, ...JSON.parse(metadataContent) };
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
// No metadata file available
|
|
360
|
+
}
|
|
361
|
+
// Scan directory for files
|
|
362
|
+
const files = await this.scanGitFiles(gitRepoPath, '');
|
|
363
|
+
const gitRepo = {
|
|
364
|
+
path: gitRepoPath,
|
|
365
|
+
branches: metadata.branches,
|
|
366
|
+
commits: metadata.commits,
|
|
367
|
+
files,
|
|
368
|
+
metadata
|
|
369
|
+
};
|
|
370
|
+
return gitRepo;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Scan Git files recursively
|
|
374
|
+
*/
|
|
375
|
+
async scanGitFiles(gitRepoPath, relativePath) {
|
|
376
|
+
const files = [];
|
|
377
|
+
const currentPath = relativePath ? path.join(gitRepoPath, relativePath) : gitRepoPath;
|
|
378
|
+
try {
|
|
379
|
+
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
380
|
+
for (const entry of entries) {
|
|
381
|
+
// Skip Git metadata directories
|
|
382
|
+
if (entry.name === '.git')
|
|
383
|
+
continue;
|
|
384
|
+
const entryPath = path.join(currentPath, entry.name);
|
|
385
|
+
const entryRelativePath = relativePath ? path.join(relativePath, entry.name) : entry.name;
|
|
386
|
+
if (entry.isDirectory()) {
|
|
387
|
+
const subFiles = await this.scanGitFiles(gitRepoPath, entryRelativePath);
|
|
388
|
+
files.push(...subFiles);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
const content = await fs.readFile(entryPath);
|
|
392
|
+
const stats = await fs.stat(entryPath);
|
|
393
|
+
const gitFile = {
|
|
394
|
+
path: entryRelativePath,
|
|
395
|
+
content,
|
|
396
|
+
hash: createHash('sha1').update(content).digest('hex'),
|
|
397
|
+
mode: stats.mode.toString(8),
|
|
398
|
+
size: content.length,
|
|
399
|
+
lastModified: stats.mtime.getTime()
|
|
400
|
+
};
|
|
401
|
+
files.push(gitFile);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
console.warn(`Failed to scan Git files in ${currentPath}:`, error);
|
|
407
|
+
}
|
|
408
|
+
return files;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Import metadata from exported data
|
|
412
|
+
*/
|
|
413
|
+
async importMetadata(vfsPath, metadata) {
|
|
414
|
+
// Apply metadata to imported files
|
|
415
|
+
for (const [filePath, fileMetadata] of Object.entries(metadata.files || {})) {
|
|
416
|
+
const fullPath = path.join(vfsPath, filePath);
|
|
417
|
+
try {
|
|
418
|
+
// Update file metadata if it exists
|
|
419
|
+
const exists = await this.vfs.exists(fullPath);
|
|
420
|
+
if (exists) {
|
|
421
|
+
// Would update file metadata in VFS
|
|
422
|
+
// This depends on VFS implementation supporting metadata updates
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
console.warn(`Failed to import metadata for ${fullPath}:`, error);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Import relationships
|
|
432
|
+
*/
|
|
433
|
+
async importRelationships(relationships) {
|
|
434
|
+
for (const relationship of relationships) {
|
|
435
|
+
try {
|
|
436
|
+
await this.brain.relate({
|
|
437
|
+
from: relationship.from,
|
|
438
|
+
to: relationship.to,
|
|
439
|
+
type: relationship.type,
|
|
440
|
+
metadata: relationship.metadata
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
console.warn('Failed to import relationship:', error);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Import history from exported data
|
|
450
|
+
*/
|
|
451
|
+
async importHistory(vfsPath, history) {
|
|
452
|
+
let eventsCreated = 0;
|
|
453
|
+
for (const event of history.events || []) {
|
|
454
|
+
try {
|
|
455
|
+
await this.brain.add({
|
|
456
|
+
type: NounType.Event,
|
|
457
|
+
data: Buffer.from(JSON.stringify(event)),
|
|
458
|
+
metadata: {
|
|
459
|
+
...event,
|
|
460
|
+
importedFrom: 'git',
|
|
461
|
+
importedAt: Date.now()
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
eventsCreated++;
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
console.warn('Failed to import history event:', error);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return eventsCreated;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Convert Git commits to VFS events
|
|
474
|
+
*/
|
|
475
|
+
async convertCommitsToEvents(vfsPath, commits) {
|
|
476
|
+
let eventsCreated = 0;
|
|
477
|
+
for (const commit of commits) {
|
|
478
|
+
try {
|
|
479
|
+
await this.brain.add({
|
|
480
|
+
type: NounType.Event,
|
|
481
|
+
data: Buffer.from(commit.message),
|
|
482
|
+
metadata: {
|
|
483
|
+
eventType: 'git-commit',
|
|
484
|
+
gitHash: commit.hash,
|
|
485
|
+
author: commit.author,
|
|
486
|
+
email: commit.email,
|
|
487
|
+
timestamp: commit.timestamp,
|
|
488
|
+
files: commit.files,
|
|
489
|
+
vfsPath,
|
|
490
|
+
system: 'git-bridge'
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
eventsCreated++;
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
console.warn('Failed to convert commit to event:', error);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return eventsCreated;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Generate commit hash
|
|
503
|
+
*/
|
|
504
|
+
generateCommitHash(files) {
|
|
505
|
+
const content = files.map(f => f.path + ':' + f.hash).join('\n');
|
|
506
|
+
return createHash('sha1').update(content).digest('hex');
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Write repository metadata
|
|
510
|
+
*/
|
|
511
|
+
async writeRepoMetadata(gitRepoPath, gitRepo) {
|
|
512
|
+
const metadataPath = path.join(gitRepoPath, '.vfs-repo-metadata.json');
|
|
513
|
+
await fs.writeFile(metadataPath, JSON.stringify(gitRepo.metadata, null, 2));
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Record Git bridge event
|
|
517
|
+
*/
|
|
518
|
+
async recordGitEvent(operation, details) {
|
|
519
|
+
try {
|
|
520
|
+
await this.brain.add({
|
|
521
|
+
type: NounType.Event,
|
|
522
|
+
data: Buffer.from(JSON.stringify(details)),
|
|
523
|
+
metadata: {
|
|
524
|
+
eventType: 'git-bridge',
|
|
525
|
+
operation,
|
|
526
|
+
timestamp: Date.now(),
|
|
527
|
+
system: 'git-bridge',
|
|
528
|
+
...details
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
catch (error) {
|
|
533
|
+
console.warn('Failed to record Git bridge event:', error);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
//# sourceMappingURL=GitBridge.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge Augmentation
|
|
3
|
+
*
|
|
4
|
+
* Main orchestrator for the Knowledge Layer that coordinates all knowledge systems
|
|
5
|
+
* and enhances the VFS with intelligent capabilities
|
|
6
|
+
*/
|
|
7
|
+
import { Brainy } from '../brainy.js';
|
|
8
|
+
import { VirtualFileSystem } from './VirtualFileSystem.js';
|
|
9
|
+
import { EventRecorder } from './EventRecorder.js';
|
|
10
|
+
import { SemanticVersioning } from './SemanticVersioning.js';
|
|
11
|
+
import { PersistentEntitySystem } from './PersistentEntitySystem.js';
|
|
12
|
+
import { ConceptSystem } from './ConceptSystem.js';
|
|
13
|
+
import { GitBridge } from './GitBridge.js';
|
|
14
|
+
export interface KnowledgeAugmentationConfig {
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
eventRecording?: {
|
|
17
|
+
enabled: boolean;
|
|
18
|
+
maxEvents?: number;
|
|
19
|
+
};
|
|
20
|
+
semanticVersioning?: {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
maxVersions?: number;
|
|
23
|
+
};
|
|
24
|
+
entitySystem?: {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
autoExtract?: boolean;
|
|
27
|
+
};
|
|
28
|
+
conceptSystem?: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
autoExtract?: boolean;
|
|
31
|
+
};
|
|
32
|
+
gitBridge?: {
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
autoSync?: boolean;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare class KnowledgeAugmentation {
|
|
38
|
+
private brain;
|
|
39
|
+
private vfs;
|
|
40
|
+
private config;
|
|
41
|
+
private eventRecorder?;
|
|
42
|
+
private semanticVersioning?;
|
|
43
|
+
private entitySystem?;
|
|
44
|
+
private conceptSystem?;
|
|
45
|
+
private gitBridge?;
|
|
46
|
+
private enabled;
|
|
47
|
+
constructor(config: KnowledgeAugmentationConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Initialize the Knowledge Augmentation with Brainy instance
|
|
50
|
+
*/
|
|
51
|
+
init(brain: Brainy, vfs: VirtualFileSystem): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Enable the Knowledge Augmentation
|
|
54
|
+
*/
|
|
55
|
+
enable(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Disable the Knowledge Augmentation
|
|
58
|
+
*/
|
|
59
|
+
disable(): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Check if the knowledge augmentation is enabled
|
|
62
|
+
*/
|
|
63
|
+
isEnabled(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Get the EventRecorder instance
|
|
66
|
+
*/
|
|
67
|
+
getEventRecorder(): EventRecorder | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Get the SemanticVersioning instance
|
|
70
|
+
*/
|
|
71
|
+
getSemanticVersioning(): SemanticVersioning | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get the PersistentEntitySystem instance
|
|
74
|
+
*/
|
|
75
|
+
getEntitySystem(): PersistentEntitySystem | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Get the ConceptSystem instance
|
|
78
|
+
*/
|
|
79
|
+
getConceptSystem(): ConceptSystem | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get the GitBridge instance
|
|
82
|
+
*/
|
|
83
|
+
getGitBridge(): GitBridge | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Record a file event (called by VFS)
|
|
86
|
+
*/
|
|
87
|
+
recordEvent(type: string, path: string, metadata?: any): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Create a semantic version (called by VFS)
|
|
90
|
+
*/
|
|
91
|
+
createVersion(path: string, content: Buffer): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Extract entities from content (called by VFS)
|
|
94
|
+
*/
|
|
95
|
+
extractEntities(path: string, content: string): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Extract concepts from content (called by VFS)
|
|
98
|
+
*/
|
|
99
|
+
extractConcepts(path: string, content: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Enhance the VFS with knowledge methods
|
|
102
|
+
*/
|
|
103
|
+
private enhanceVFS;
|
|
104
|
+
}
|