@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,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fs-Compatible Interface for VFS
|
|
3
|
+
*
|
|
4
|
+
* Provides a drop-in replacement for Node's fs module
|
|
5
|
+
* that uses VFS for storage instead of the real filesystem.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { FSCompat } from '@soulcraft/brainy/vfs'
|
|
9
|
+
* const fs = new FSCompat(brain.vfs())
|
|
10
|
+
*
|
|
11
|
+
* // Now use like Node's fs
|
|
12
|
+
* await fs.promises.readFile('/path')
|
|
13
|
+
* fs.createReadStream('/path').pipe(output)
|
|
14
|
+
*/
|
|
15
|
+
export class FSCompat {
|
|
16
|
+
constructor(vfs) {
|
|
17
|
+
this.vfs = vfs;
|
|
18
|
+
this.promises = new FSPromises(vfs);
|
|
19
|
+
}
|
|
20
|
+
readFile(path, options, callback) {
|
|
21
|
+
if (typeof options === 'function') {
|
|
22
|
+
callback = options;
|
|
23
|
+
options = {};
|
|
24
|
+
}
|
|
25
|
+
this.vfs.readFile(path, options)
|
|
26
|
+
.then(data => {
|
|
27
|
+
if (options?.encoding) {
|
|
28
|
+
callback(null, data.toString(options.encoding));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
callback(null, data);
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
.catch(err => callback(err));
|
|
35
|
+
}
|
|
36
|
+
writeFile(path, data, options, callback) {
|
|
37
|
+
if (typeof options === 'function') {
|
|
38
|
+
callback = options;
|
|
39
|
+
options = {};
|
|
40
|
+
}
|
|
41
|
+
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data, options?.encoding || 'utf8');
|
|
42
|
+
this.vfs.writeFile(path, buffer, options)
|
|
43
|
+
.then(() => callback(null))
|
|
44
|
+
.catch(err => callback(err));
|
|
45
|
+
}
|
|
46
|
+
mkdir(path, options, callback) {
|
|
47
|
+
if (typeof options === 'function') {
|
|
48
|
+
callback = options;
|
|
49
|
+
options = {};
|
|
50
|
+
}
|
|
51
|
+
this.vfs.mkdir(path, options)
|
|
52
|
+
.then(() => callback(null))
|
|
53
|
+
.catch(err => callback(err));
|
|
54
|
+
}
|
|
55
|
+
rmdir(path, options, callback) {
|
|
56
|
+
if (typeof options === 'function') {
|
|
57
|
+
callback = options;
|
|
58
|
+
options = {};
|
|
59
|
+
}
|
|
60
|
+
this.vfs.rmdir(path, options)
|
|
61
|
+
.then(() => callback(null))
|
|
62
|
+
.catch(err => callback(err));
|
|
63
|
+
}
|
|
64
|
+
readdir(path, options, callback) {
|
|
65
|
+
if (typeof options === 'function') {
|
|
66
|
+
callback = options;
|
|
67
|
+
options = {};
|
|
68
|
+
}
|
|
69
|
+
this.vfs.readdir(path, options)
|
|
70
|
+
.then(files => callback(null, files))
|
|
71
|
+
.catch(err => callback(err));
|
|
72
|
+
}
|
|
73
|
+
stat(path, callback) {
|
|
74
|
+
this.vfs.stat(path)
|
|
75
|
+
.then(stats => callback(null, stats))
|
|
76
|
+
.catch(err => callback(err));
|
|
77
|
+
}
|
|
78
|
+
lstat(path, callback) {
|
|
79
|
+
this.vfs.lstat(path)
|
|
80
|
+
.then(stats => callback(null, stats))
|
|
81
|
+
.catch(err => callback(err));
|
|
82
|
+
}
|
|
83
|
+
unlink(path, callback) {
|
|
84
|
+
this.vfs.unlink(path)
|
|
85
|
+
.then(() => callback(null))
|
|
86
|
+
.catch(err => callback(err));
|
|
87
|
+
}
|
|
88
|
+
rename(oldPath, newPath, callback) {
|
|
89
|
+
this.vfs.rename(oldPath, newPath)
|
|
90
|
+
.then(() => callback(null))
|
|
91
|
+
.catch(err => callback(err));
|
|
92
|
+
}
|
|
93
|
+
copyFile(src, dest, flagsOrCallback, callback) {
|
|
94
|
+
if (typeof flagsOrCallback === 'function') {
|
|
95
|
+
callback = flagsOrCallback;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// flags provided but not used
|
|
99
|
+
}
|
|
100
|
+
this.vfs.copy(src, dest)
|
|
101
|
+
.then(() => callback(null))
|
|
102
|
+
.catch(err => callback(err));
|
|
103
|
+
}
|
|
104
|
+
exists(path, callback) {
|
|
105
|
+
this.vfs.exists(path)
|
|
106
|
+
.then(exists => callback(exists))
|
|
107
|
+
.catch(() => callback(false));
|
|
108
|
+
}
|
|
109
|
+
access(path, modeOrCallback, callback) {
|
|
110
|
+
if (typeof modeOrCallback === 'function') {
|
|
111
|
+
callback = modeOrCallback;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// mode provided but not used
|
|
115
|
+
}
|
|
116
|
+
this.vfs.exists(path)
|
|
117
|
+
.then(exists => {
|
|
118
|
+
if (exists) {
|
|
119
|
+
callback(null);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
const err = new Error('ENOENT: no such file or directory');
|
|
123
|
+
err.code = 'ENOENT';
|
|
124
|
+
callback(err);
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
.catch(err => callback(err));
|
|
128
|
+
}
|
|
129
|
+
appendFile(path, data, options, callback) {
|
|
130
|
+
if (typeof options === 'function') {
|
|
131
|
+
callback = options;
|
|
132
|
+
options = {};
|
|
133
|
+
}
|
|
134
|
+
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data, options?.encoding || 'utf8');
|
|
135
|
+
this.vfs.appendFile(path, buffer, options)
|
|
136
|
+
.then(() => callback(null))
|
|
137
|
+
.catch(err => callback(err));
|
|
138
|
+
}
|
|
139
|
+
// ============= Stream methods =============
|
|
140
|
+
createReadStream(path, options) {
|
|
141
|
+
return this.vfs.createReadStream(path, options);
|
|
142
|
+
}
|
|
143
|
+
createWriteStream(path, options) {
|
|
144
|
+
return this.vfs.createWriteStream(path, options);
|
|
145
|
+
}
|
|
146
|
+
// ============= Watch methods =============
|
|
147
|
+
watch(path, listener) {
|
|
148
|
+
return this.vfs.watch(path, listener);
|
|
149
|
+
}
|
|
150
|
+
watchFile(path, listener) {
|
|
151
|
+
return this.vfs.watchFile(path, listener);
|
|
152
|
+
}
|
|
153
|
+
unwatchFile(path) {
|
|
154
|
+
return this.vfs.unwatchFile(path);
|
|
155
|
+
}
|
|
156
|
+
// ============= Additional methods =============
|
|
157
|
+
/**
|
|
158
|
+
* Import a directory from real filesystem (VFS extension)
|
|
159
|
+
*/
|
|
160
|
+
async importDirectory(sourcePath, options) {
|
|
161
|
+
return this.vfs.importDirectory(sourcePath, options);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Search files semantically (VFS extension)
|
|
165
|
+
*/
|
|
166
|
+
async search(query, options) {
|
|
167
|
+
return this.vfs.search(query, options);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Promise-based fs API (like fs.promises)
|
|
172
|
+
*/
|
|
173
|
+
class FSPromises {
|
|
174
|
+
constructor(vfs) {
|
|
175
|
+
this.vfs = vfs;
|
|
176
|
+
}
|
|
177
|
+
async readFile(path, options) {
|
|
178
|
+
const buffer = await this.vfs.readFile(path, options);
|
|
179
|
+
if (options?.encoding) {
|
|
180
|
+
return buffer.toString(options.encoding);
|
|
181
|
+
}
|
|
182
|
+
return buffer;
|
|
183
|
+
}
|
|
184
|
+
async writeFile(path, data, options) {
|
|
185
|
+
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data, options?.encoding || 'utf8');
|
|
186
|
+
return this.vfs.writeFile(path, buffer, options);
|
|
187
|
+
}
|
|
188
|
+
async mkdir(path, options) {
|
|
189
|
+
return this.vfs.mkdir(path, options);
|
|
190
|
+
}
|
|
191
|
+
async rmdir(path, options) {
|
|
192
|
+
return this.vfs.rmdir(path, options);
|
|
193
|
+
}
|
|
194
|
+
async readdir(path, options) {
|
|
195
|
+
return this.vfs.readdir(path, options);
|
|
196
|
+
}
|
|
197
|
+
async stat(path) {
|
|
198
|
+
return this.vfs.stat(path);
|
|
199
|
+
}
|
|
200
|
+
async lstat(path) {
|
|
201
|
+
return this.vfs.lstat(path);
|
|
202
|
+
}
|
|
203
|
+
async unlink(path) {
|
|
204
|
+
return this.vfs.unlink(path);
|
|
205
|
+
}
|
|
206
|
+
async rename(oldPath, newPath) {
|
|
207
|
+
return this.vfs.rename(oldPath, newPath);
|
|
208
|
+
}
|
|
209
|
+
async copyFile(src, dest, flags) {
|
|
210
|
+
return this.vfs.copy(src, dest);
|
|
211
|
+
}
|
|
212
|
+
async access(path, mode) {
|
|
213
|
+
const exists = await this.vfs.exists(path);
|
|
214
|
+
if (!exists) {
|
|
215
|
+
const err = new Error('ENOENT: no such file or directory');
|
|
216
|
+
err.code = 'ENOENT';
|
|
217
|
+
throw err;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async appendFile(path, data, options) {
|
|
221
|
+
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data, options?.encoding || 'utf8');
|
|
222
|
+
return this.vfs.appendFile(path, buffer, options);
|
|
223
|
+
}
|
|
224
|
+
async realpath(path) {
|
|
225
|
+
return this.vfs.realpath(path);
|
|
226
|
+
}
|
|
227
|
+
async chmod(path, mode) {
|
|
228
|
+
return this.vfs.chmod(path, mode);
|
|
229
|
+
}
|
|
230
|
+
async chown(path, uid, gid) {
|
|
231
|
+
return this.vfs.chown(path, uid, gid);
|
|
232
|
+
}
|
|
233
|
+
async utimes(path, atime, mtime) {
|
|
234
|
+
return this.vfs.utimes(path, atime, mtime);
|
|
235
|
+
}
|
|
236
|
+
async symlink(target, path) {
|
|
237
|
+
return this.vfs.symlink(target, path);
|
|
238
|
+
}
|
|
239
|
+
async readlink(path) {
|
|
240
|
+
return this.vfs.readlink(path);
|
|
241
|
+
}
|
|
242
|
+
// VFS Extensions
|
|
243
|
+
async search(query, options) {
|
|
244
|
+
return this.vfs.search(query, options);
|
|
245
|
+
}
|
|
246
|
+
async findSimilar(path, options) {
|
|
247
|
+
return this.vfs.findSimilar(path, options);
|
|
248
|
+
}
|
|
249
|
+
async importDirectory(sourcePath, options) {
|
|
250
|
+
return this.vfs.importDirectory(sourcePath, options);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Export a convenience function to create fs replacement
|
|
254
|
+
export function createFS(vfs) {
|
|
255
|
+
return new FSCompat(vfs);
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=FSCompat.js.map
|
|
@@ -0,0 +1,167 @@
|
|
|
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 { VirtualFileSystem } from './VirtualFileSystem.js';
|
|
9
|
+
import { Brainy } from '../brainy.js';
|
|
10
|
+
/**
|
|
11
|
+
* Git repository representation
|
|
12
|
+
*/
|
|
13
|
+
export interface GitRepository {
|
|
14
|
+
path: string;
|
|
15
|
+
branches: GitBranch[];
|
|
16
|
+
commits: GitCommit[];
|
|
17
|
+
files: GitFile[];
|
|
18
|
+
metadata: {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
origin?: string;
|
|
22
|
+
lastImported?: number;
|
|
23
|
+
vfsMetadata?: Record<string, any>;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Git branch information
|
|
28
|
+
*/
|
|
29
|
+
export interface GitBranch {
|
|
30
|
+
name: string;
|
|
31
|
+
commitHash: string;
|
|
32
|
+
isActive: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Git commit information
|
|
36
|
+
*/
|
|
37
|
+
export interface GitCommit {
|
|
38
|
+
hash: string;
|
|
39
|
+
message: string;
|
|
40
|
+
author: string;
|
|
41
|
+
email: string;
|
|
42
|
+
timestamp: number;
|
|
43
|
+
parent?: string;
|
|
44
|
+
files: string[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Git file representation
|
|
48
|
+
*/
|
|
49
|
+
export interface GitFile {
|
|
50
|
+
path: string;
|
|
51
|
+
content: Buffer;
|
|
52
|
+
hash: string;
|
|
53
|
+
mode: string;
|
|
54
|
+
size: number;
|
|
55
|
+
lastModified: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Export options
|
|
59
|
+
*/
|
|
60
|
+
export interface ExportOptions {
|
|
61
|
+
preserveMetadata?: boolean;
|
|
62
|
+
preserveRelationships?: boolean;
|
|
63
|
+
preserveHistory?: boolean;
|
|
64
|
+
branch?: string;
|
|
65
|
+
commitMessage?: string;
|
|
66
|
+
author?: {
|
|
67
|
+
name: string;
|
|
68
|
+
email: string;
|
|
69
|
+
};
|
|
70
|
+
includeSystemFiles?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Import options
|
|
74
|
+
*/
|
|
75
|
+
export interface ImportOptions {
|
|
76
|
+
preserveGitHistory?: boolean;
|
|
77
|
+
extractMetadata?: boolean;
|
|
78
|
+
restoreRelationships?: boolean;
|
|
79
|
+
includeSystemFiles?: boolean;
|
|
80
|
+
branch?: string;
|
|
81
|
+
since?: number;
|
|
82
|
+
author?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Git Bridge - Import/Export between VFS and Git repositories
|
|
86
|
+
*
|
|
87
|
+
* Capabilities:
|
|
88
|
+
* - Export VFS to standard Git repository structure
|
|
89
|
+
* - Import Git repository into VFS with intelligence
|
|
90
|
+
* - Preserve VFS metadata and relationships
|
|
91
|
+
* - Convert Git history to VFS events
|
|
92
|
+
* - No Git dependencies - pure filesystem operations
|
|
93
|
+
*/
|
|
94
|
+
export declare class GitBridge {
|
|
95
|
+
private vfs;
|
|
96
|
+
private brain;
|
|
97
|
+
constructor(vfs: VirtualFileSystem, brain: Brainy);
|
|
98
|
+
/**
|
|
99
|
+
* Export VFS to Git repository structure
|
|
100
|
+
*/
|
|
101
|
+
exportToGit(vfsPath: string, gitRepoPath: string, options?: ExportOptions): Promise<GitRepository>;
|
|
102
|
+
/**
|
|
103
|
+
* Import Git repository into VFS
|
|
104
|
+
*/
|
|
105
|
+
importFromGit(gitRepoPath: string, vfsPath: string, options?: ImportOptions): Promise<{
|
|
106
|
+
filesImported: number;
|
|
107
|
+
eventsCreated: number;
|
|
108
|
+
entitiesCreated: number;
|
|
109
|
+
relationshipsCreated: number;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Export directory recursively
|
|
113
|
+
*/
|
|
114
|
+
private exportDirectory;
|
|
115
|
+
/**
|
|
116
|
+
* Export VFS metadata to .vfs-metadata.json
|
|
117
|
+
*/
|
|
118
|
+
private exportMetadata;
|
|
119
|
+
/**
|
|
120
|
+
* Export relationships to .vfs-relationships.json
|
|
121
|
+
*/
|
|
122
|
+
private exportRelationships;
|
|
123
|
+
/**
|
|
124
|
+
* Export history to .vfs-history.json
|
|
125
|
+
*/
|
|
126
|
+
private exportHistory;
|
|
127
|
+
/**
|
|
128
|
+
* Collect metadata recursively
|
|
129
|
+
*/
|
|
130
|
+
private collectFileMetadata;
|
|
131
|
+
/**
|
|
132
|
+
* Read Git repository structure
|
|
133
|
+
*/
|
|
134
|
+
private readGitRepository;
|
|
135
|
+
/**
|
|
136
|
+
* Scan Git files recursively
|
|
137
|
+
*/
|
|
138
|
+
private scanGitFiles;
|
|
139
|
+
/**
|
|
140
|
+
* Import metadata from exported data
|
|
141
|
+
*/
|
|
142
|
+
private importMetadata;
|
|
143
|
+
/**
|
|
144
|
+
* Import relationships
|
|
145
|
+
*/
|
|
146
|
+
private importRelationships;
|
|
147
|
+
/**
|
|
148
|
+
* Import history from exported data
|
|
149
|
+
*/
|
|
150
|
+
private importHistory;
|
|
151
|
+
/**
|
|
152
|
+
* Convert Git commits to VFS events
|
|
153
|
+
*/
|
|
154
|
+
private convertCommitsToEvents;
|
|
155
|
+
/**
|
|
156
|
+
* Generate commit hash
|
|
157
|
+
*/
|
|
158
|
+
private generateCommitHash;
|
|
159
|
+
/**
|
|
160
|
+
* Write repository metadata
|
|
161
|
+
*/
|
|
162
|
+
private writeRepoMetadata;
|
|
163
|
+
/**
|
|
164
|
+
* Record Git bridge event
|
|
165
|
+
*/
|
|
166
|
+
private recordGitEvent;
|
|
167
|
+
}
|