@soulcraft/brainy 4.3.2 → 4.5.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.
@@ -89,15 +89,29 @@ export class VirtualFileSystem {
89
89
  }
90
90
  }
91
91
  async initializeRoot() {
92
- // Check if root already exists - search using where clause
92
+ // FIXED (v4.3.3): Use correct field names in where clause
93
+ // Metadata index stores flat fields: path, vfsType, name
94
+ // NOT nested: 'metadata.path', 'metadata.vfsType'
93
95
  const existing = await this.brain.find({
96
+ type: NounType.Collection,
94
97
  where: {
95
- 'metadata.path': '/',
96
- 'metadata.vfsType': 'directory'
98
+ path: '/', // ✅ Correct field name
99
+ vfsType: 'directory' // ✅ Correct field name
97
100
  },
98
- limit: 1
101
+ limit: 10,
102
+ includeVFS: true // v4.4.0: CRITICAL - Must find VFS root entity!
99
103
  });
100
104
  if (existing.length > 0) {
105
+ // Handle duplicate roots (Workshop team reported ~10 duplicates!)
106
+ if (existing.length > 1) {
107
+ console.warn(`⚠️ Found ${existing.length} root entities! Using first one, consider cleanup.`);
108
+ // Sort by creation time - use oldest root (most likely to have children)
109
+ existing.sort((a, b) => {
110
+ const aTime = a.metadata?.createdAt || a.metadata?.modified || 0;
111
+ const bTime = b.metadata?.createdAt || b.metadata?.modified || 0;
112
+ return aTime - bTime;
113
+ });
114
+ }
101
115
  const rootEntity = existing[0];
102
116
  // Ensure the root entity has proper metadata structure
103
117
  const entityMetadata = rootEntity.metadata || rootEntity;
@@ -109,6 +123,7 @@ export class VirtualFileSystem {
109
123
  path: '/',
110
124
  name: '',
111
125
  vfsType: 'directory',
126
+ isVFS: true, // v4.3.3: Mark as VFS entity
112
127
  size: 0,
113
128
  permissions: 0o755,
114
129
  owner: 'root',
@@ -121,7 +136,7 @@ export class VirtualFileSystem {
121
136
  }
122
137
  return rootEntity.id;
123
138
  }
124
- // Create root directory
139
+ // Create root directory (only if truly doesn't exist)
125
140
  const root = await this.brain.add({
126
141
  data: '/', // Root directory content as string
127
142
  type: NounType.Collection,
@@ -129,12 +144,14 @@ export class VirtualFileSystem {
129
144
  path: '/',
130
145
  name: '',
131
146
  vfsType: 'directory',
147
+ isVFS: true, // v4.3.3: Mark as VFS entity
132
148
  size: 0,
133
149
  permissions: 0o755,
134
150
  owner: 'root',
135
151
  group: 'root',
136
152
  accessed: Date.now(),
137
- modified: Date.now()
153
+ modified: Date.now(),
154
+ createdAt: Date.now() // Track creation time for duplicate detection
138
155
  }
139
156
  });
140
157
  return root;
@@ -278,6 +295,7 @@ export class VirtualFileSystem {
278
295
  name,
279
296
  parent: parentId,
280
297
  vfsType: 'file',
298
+ isVFS: true, // v4.3.3: Mark as VFS entity
281
299
  size: buffer.length,
282
300
  mimeType,
283
301
  extension: this.getExtension(name),
@@ -575,6 +593,7 @@ export class VirtualFileSystem {
575
593
  name,
576
594
  parent: parentId,
577
595
  vfsType: 'directory',
596
+ isVFS: true, // v4.3.3: Mark as VFS entity
578
597
  size: 0,
579
598
  permissions: options?.mode || this.config.permissions?.defaultDirectory || 0o755,
580
599
  owner: 'user',
@@ -755,7 +774,11 @@ export class VirtualFileSystem {
755
774
  type: [NounType.File, NounType.Document, NounType.Media],
756
775
  limit: options?.limit || 10,
757
776
  offset: options?.offset,
758
- explain: options?.explain
777
+ explain: options?.explain,
778
+ includeVFS: true, // v4.4.0: VFS search must include VFS entities!
779
+ where: {
780
+ vfsType: 'file' // v4.4.0: Only search VFS files, not knowledge documents
781
+ }
759
782
  };
760
783
  // Add path filter if specified
761
784
  if (options?.path) {
@@ -795,7 +818,11 @@ export class VirtualFileSystem {
795
818
  to: entityId,
796
819
  limit: options?.limit || 10,
797
820
  threshold: options?.threshold || 0.7,
798
- type: [NounType.File, NounType.Document, NounType.Media]
821
+ type: [NounType.File, NounType.Document, NounType.Media],
822
+ includeVFS: true, // v4.4.0: VFS similarity search must include VFS entities!
823
+ where: {
824
+ vfsType: 'file' // v4.4.0: Only find similar VFS files, not knowledge documents
825
+ }
799
826
  });
800
827
  return results.map(r => {
801
828
  const entity = r.entity;
@@ -1925,7 +1952,8 @@ export class VirtualFileSystem {
1925
1952
  ...query.where,
1926
1953
  vfsType: 'entity'
1927
1954
  },
1928
- limit: query.limit || 100
1955
+ limit: query.limit || 100,
1956
+ includeVFS: true // v4.4.0: VFS entity search must include VFS entities!
1929
1957
  };
1930
1958
  if (query.type) {
1931
1959
  searchQuery.where.entityType = query.type;
@@ -27,7 +27,8 @@ export class AuthorProjection extends BaseProjectionStrategy {
27
27
  vfsType: 'file',
28
28
  owner: authorName
29
29
  },
30
- limit: 1000
30
+ limit: 1000,
31
+ includeVFS: true // v4.4.0: Must include VFS entities!
31
32
  };
32
33
  // Filter by filename if subpath specified
33
34
  if (subpath) {
@@ -51,7 +52,8 @@ export class AuthorProjection extends BaseProjectionStrategy {
51
52
  vfsType: 'file',
52
53
  owner: authorName
53
54
  },
54
- limit: 1000
55
+ limit: 1000,
56
+ includeVFS: true // v4.4.0: Must include VFS entities!
55
57
  });
56
58
  return this.extractIds(results);
57
59
  }
@@ -66,7 +68,8 @@ export class AuthorProjection extends BaseProjectionStrategy {
66
68
  vfsType: 'file',
67
69
  owner: { $exists: true }
68
70
  },
69
- limit
71
+ limit,
72
+ includeVFS: true // v4.4.0: Must include VFS entities!
70
73
  });
71
74
  return results.map(r => r.entity);
72
75
  }
@@ -27,7 +27,8 @@ export class TagProjection extends BaseProjectionStrategy {
27
27
  vfsType: 'file',
28
28
  tags: { contains: tagName } // BFO operator for array contains
29
29
  },
30
- limit: 1000
30
+ limit: 1000,
31
+ includeVFS: true // v4.4.0: Must include VFS entities!
31
32
  };
32
33
  // Filter by filename if subpath specified
33
34
  if (subpath) {
@@ -51,7 +52,8 @@ export class TagProjection extends BaseProjectionStrategy {
51
52
  vfsType: 'file',
52
53
  tags: { contains: tagName } // BFO operator
53
54
  },
54
- limit: 1000
55
+ limit: 1000,
56
+ includeVFS: true // v4.4.0: Must include VFS entities!
55
57
  });
56
58
  return this.extractIds(results);
57
59
  }
@@ -65,7 +67,8 @@ export class TagProjection extends BaseProjectionStrategy {
65
67
  vfsType: 'file',
66
68
  tags: { exists: true } // BFO operator
67
69
  },
68
- limit
70
+ limit,
71
+ includeVFS: true // v4.4.0: Must include VFS entities!
69
72
  });
70
73
  return results.map(r => r.entity);
71
74
  }
@@ -67,7 +67,8 @@ export class TemporalProjection extends BaseProjectionStrategy {
67
67
  lessEqual: endOfDay.getTime() // BFO operator
68
68
  }
69
69
  },
70
- limit: 1000
70
+ limit: 1000,
71
+ includeVFS: true // v4.4.0: Must include VFS entities!
71
72
  });
72
73
  return this.extractIds(results);
73
74
  }
@@ -81,7 +82,8 @@ export class TemporalProjection extends BaseProjectionStrategy {
81
82
  vfsType: 'file',
82
83
  modified: { greaterEqual: oneDayAgo } // BFO operator
83
84
  },
84
- limit
85
+ limit,
86
+ includeVFS: true // v4.4.0: Must include VFS entities!
85
87
  });
86
88
  return results.map(r => r.entity);
87
89
  }
@@ -27,6 +27,7 @@ export interface VFSMetadata {
27
27
  name: string;
28
28
  parent?: string;
29
29
  vfsType: 'file' | 'directory' | 'symlink';
30
+ isVFS?: boolean;
30
31
  size: number;
31
32
  mimeType?: string;
32
33
  extension?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "4.3.2",
3
+ "version": "4.5.0",
4
4
  "description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",