@soulcraft/brainy 3.19.0 → 3.20.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/CHANGELOG.md +2 -0
- package/bin/brainy-minimal.js +82 -0
- package/bin/brainy.js +9 -2335
- package/dist/api/DataAPI.d.ts +1 -1
- package/dist/augmentations/cacheAugmentation.d.ts +1 -1
- package/dist/augmentations/metricsAugmentation.d.ts +20 -20
- package/dist/brainy.d.ts +1 -1
- package/dist/brainyData.js +1 -2
- package/dist/cli/catalog.js +8 -12
- package/dist/cli/commands/conversation.d.ts +22 -0
- package/dist/cli/commands/conversation.js +528 -0
- package/dist/cli/commands/core.d.ts +14 -2
- package/dist/cli/commands/core.js +195 -35
- package/dist/cli/commands/data.d.ts +29 -0
- package/dist/cli/commands/data.js +139 -0
- package/dist/cli/commands/neural.d.ts +14 -0
- package/dist/cli/commands/neural.js +18 -8
- package/dist/cli/commands/types.d.ts +30 -0
- package/dist/cli/commands/types.js +194 -0
- package/dist/cli/commands/utility.js +39 -98
- package/dist/cli/commands/vfs.d.ts +73 -0
- package/dist/cli/commands/vfs.js +372 -0
- package/dist/cli/index.js +244 -7
- package/dist/cli/interactive.d.ts +8 -3
- package/dist/cli/interactive.js +35 -11
- package/dist/hnsw/hnswIndexOptimized.d.ts +1 -1
- package/dist/mcp/brainyMCPBroadcast.d.ts +2 -2
- package/dist/mcp/brainyMCPBroadcast.js +1 -1
- package/dist/mcp/brainyMCPClient.js +8 -4
- package/dist/neural/types.d.ts +2 -2
- package/dist/streaming/pipeline.d.ts +1 -1
- package/dist/universal/fs.d.ts +24 -66
- package/package.json +5 -2
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import ora from 'ora';
|
|
8
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
9
|
-
import {
|
|
8
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { Brainy } from '../../brainy.js';
|
|
10
|
+
import { BrainyTypes, NounType } from '../../index.js';
|
|
10
11
|
let brainyInstance = null;
|
|
11
|
-
const getBrainy =
|
|
12
|
+
const getBrainy = () => {
|
|
12
13
|
if (!brainyInstance) {
|
|
13
|
-
brainyInstance = new
|
|
14
|
-
await brainyInstance.init();
|
|
14
|
+
brainyInstance = new Brainy();
|
|
15
15
|
}
|
|
16
16
|
return brainyInstance;
|
|
17
17
|
};
|
|
@@ -27,7 +27,7 @@ export const coreCommands = {
|
|
|
27
27
|
async add(text, options) {
|
|
28
28
|
const spinner = ora('Adding to neural database...').start();
|
|
29
29
|
try {
|
|
30
|
-
const brain =
|
|
30
|
+
const brain = getBrainy();
|
|
31
31
|
let metadata = {};
|
|
32
32
|
if (options.metadata) {
|
|
33
33
|
try {
|
|
@@ -41,11 +41,36 @@ export const coreCommands = {
|
|
|
41
41
|
if (options.id) {
|
|
42
42
|
metadata.id = options.id;
|
|
43
43
|
}
|
|
44
|
+
// Determine noun type
|
|
45
|
+
let nounType;
|
|
44
46
|
if (options.type) {
|
|
45
|
-
|
|
47
|
+
// Validate provided type
|
|
48
|
+
if (!BrainyTypes.isValidNoun(options.type)) {
|
|
49
|
+
spinner.fail(`Invalid noun type: ${options.type}`);
|
|
50
|
+
console.log(chalk.dim('Run "brainy types --noun" to see valid types'));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
nounType = options.type;
|
|
46
54
|
}
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
else {
|
|
56
|
+
// Use AI to suggest type
|
|
57
|
+
spinner.text = 'Detecting type with AI...';
|
|
58
|
+
const suggestion = await BrainyTypes.suggestNoun(typeof text === 'string' ? { content: text, ...metadata } : text);
|
|
59
|
+
if (suggestion.confidence < 0.6) {
|
|
60
|
+
spinner.fail('Could not determine type with confidence');
|
|
61
|
+
console.log(chalk.yellow(`Suggestion: ${suggestion.type} (${(suggestion.confidence * 100).toFixed(1)}%)`));
|
|
62
|
+
console.log(chalk.dim('Use --type flag to specify explicitly'));
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
nounType = suggestion.type;
|
|
66
|
+
spinner.text = `Using detected type: ${nounType}`;
|
|
67
|
+
}
|
|
68
|
+
// Add with explicit type
|
|
69
|
+
const result = await brain.add({
|
|
70
|
+
data: text,
|
|
71
|
+
type: nounType,
|
|
72
|
+
metadata
|
|
73
|
+
});
|
|
49
74
|
spinner.succeed('Added successfully');
|
|
50
75
|
if (!options.json) {
|
|
51
76
|
console.log(chalk.green(`✓ Added with ID: ${result}`));
|
|
@@ -67,43 +92,157 @@ export const coreCommands = {
|
|
|
67
92
|
}
|
|
68
93
|
},
|
|
69
94
|
/**
|
|
70
|
-
* Search the neural database
|
|
95
|
+
* Search the neural database with Triple Intelligence™
|
|
71
96
|
*/
|
|
72
97
|
async search(query, options) {
|
|
73
|
-
const spinner = ora('Searching
|
|
98
|
+
const spinner = ora('Searching with Triple Intelligence™...').start();
|
|
74
99
|
try {
|
|
75
|
-
const brain =
|
|
76
|
-
|
|
100
|
+
const brain = getBrainy();
|
|
101
|
+
// Build comprehensive search params
|
|
102
|
+
const searchParams = {
|
|
103
|
+
query,
|
|
77
104
|
limit: options.limit ? parseInt(options.limit) : 10
|
|
78
105
|
};
|
|
106
|
+
// Pagination
|
|
107
|
+
if (options.offset) {
|
|
108
|
+
searchParams.offset = parseInt(options.offset);
|
|
109
|
+
}
|
|
110
|
+
// Vector Intelligence - similarity threshold
|
|
79
111
|
if (options.threshold) {
|
|
80
|
-
|
|
112
|
+
searchParams.near = { threshold: parseFloat(options.threshold) };
|
|
81
113
|
}
|
|
82
|
-
|
|
114
|
+
// Metadata Intelligence - type filtering
|
|
115
|
+
if (options.type) {
|
|
116
|
+
const types = options.type.split(',').map(t => t.trim());
|
|
117
|
+
searchParams.type = types.length === 1 ? types[0] : types;
|
|
118
|
+
}
|
|
119
|
+
// Metadata Intelligence - field filtering
|
|
120
|
+
if (options.where) {
|
|
83
121
|
try {
|
|
84
|
-
|
|
122
|
+
searchParams.where = JSON.parse(options.where);
|
|
85
123
|
}
|
|
86
124
|
catch {
|
|
87
|
-
spinner.fail('Invalid
|
|
125
|
+
spinner.fail('Invalid --where JSON');
|
|
126
|
+
console.log(chalk.dim('Example: --where \'{"status":"active","priority":{"$gte":5}}\''));
|
|
88
127
|
process.exit(1);
|
|
89
128
|
}
|
|
90
129
|
}
|
|
91
|
-
|
|
130
|
+
// Vector Intelligence - proximity search
|
|
131
|
+
if (options.near) {
|
|
132
|
+
searchParams.near = {
|
|
133
|
+
id: options.near,
|
|
134
|
+
threshold: options.threshold ? parseFloat(options.threshold) : 0.7
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// Graph Intelligence - connection constraints
|
|
138
|
+
if (options.connectedTo || options.connectedFrom || options.via) {
|
|
139
|
+
searchParams.connected = {};
|
|
140
|
+
if (options.connectedTo) {
|
|
141
|
+
searchParams.connected.to = options.connectedTo;
|
|
142
|
+
}
|
|
143
|
+
if (options.connectedFrom) {
|
|
144
|
+
searchParams.connected.from = options.connectedFrom;
|
|
145
|
+
}
|
|
146
|
+
if (options.via) {
|
|
147
|
+
const vias = options.via.split(',').map(v => v.trim());
|
|
148
|
+
searchParams.connected.via = vias.length === 1 ? vias[0] : vias;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Explanation
|
|
152
|
+
if (options.explain) {
|
|
153
|
+
searchParams.explain = true;
|
|
154
|
+
}
|
|
155
|
+
// Include relationships
|
|
156
|
+
if (options.includeRelations) {
|
|
157
|
+
searchParams.includeRelations = true;
|
|
158
|
+
}
|
|
159
|
+
// Triple Intelligence Fusion - custom weighting
|
|
160
|
+
if (options.fusion || options.vectorWeight || options.graphWeight || options.fieldWeight) {
|
|
161
|
+
searchParams.fusion = {
|
|
162
|
+
strategy: options.fusion || 'adaptive',
|
|
163
|
+
weights: {}
|
|
164
|
+
};
|
|
165
|
+
if (options.vectorWeight) {
|
|
166
|
+
searchParams.fusion.weights.vector = parseFloat(options.vectorWeight);
|
|
167
|
+
}
|
|
168
|
+
if (options.graphWeight) {
|
|
169
|
+
searchParams.fusion.weights.graph = parseFloat(options.graphWeight);
|
|
170
|
+
}
|
|
171
|
+
if (options.fieldWeight) {
|
|
172
|
+
searchParams.fusion.weights.field = parseFloat(options.fieldWeight);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const results = await brain.find(searchParams);
|
|
92
176
|
spinner.succeed(`Found ${results.length} results`);
|
|
93
177
|
if (!options.json) {
|
|
94
178
|
if (results.length === 0) {
|
|
95
|
-
console.log(chalk.yellow('
|
|
179
|
+
console.log(chalk.yellow('\nNo results found'));
|
|
180
|
+
// Show helpful hints
|
|
181
|
+
console.log(chalk.dim('\nTips:'));
|
|
182
|
+
console.log(chalk.dim(' • Try different search terms'));
|
|
183
|
+
console.log(chalk.dim(' • Remove filters (--type, --where, --connected-to)'));
|
|
184
|
+
console.log(chalk.dim(' • Lower the --threshold value'));
|
|
96
185
|
}
|
|
97
186
|
else {
|
|
187
|
+
console.log(chalk.cyan(`\n📊 Triple Intelligence Results:\n`));
|
|
98
188
|
results.forEach((result, i) => {
|
|
99
|
-
|
|
189
|
+
const entity = result.entity || result;
|
|
190
|
+
console.log(chalk.bold(`${i + 1}. ${entity.id}`));
|
|
191
|
+
// Show score with breakdown
|
|
100
192
|
if (result.score !== undefined) {
|
|
101
|
-
console.log(chalk.
|
|
193
|
+
console.log(chalk.green(` Score: ${(result.score * 100).toFixed(1)}%`));
|
|
194
|
+
if (options.explain && result.scores) {
|
|
195
|
+
const scores = result.scores;
|
|
196
|
+
if (scores.vector !== undefined) {
|
|
197
|
+
console.log(chalk.dim(` Vector: ${(scores.vector * 100).toFixed(1)}%`));
|
|
198
|
+
}
|
|
199
|
+
if (scores.graph !== undefined) {
|
|
200
|
+
console.log(chalk.dim(` Graph: ${(scores.graph * 100).toFixed(1)}%`));
|
|
201
|
+
}
|
|
202
|
+
if (scores.field !== undefined) {
|
|
203
|
+
console.log(chalk.dim(` Field: ${(scores.field * 100).toFixed(1)}%`));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Show type
|
|
208
|
+
if (entity.type) {
|
|
209
|
+
console.log(chalk.dim(` Type: ${entity.type}`));
|
|
210
|
+
}
|
|
211
|
+
// Show content preview
|
|
212
|
+
if (entity.content) {
|
|
213
|
+
const preview = entity.content.substring(0, 80);
|
|
214
|
+
console.log(chalk.dim(` Content: ${preview}${entity.content.length > 80 ? '...' : ''}`));
|
|
102
215
|
}
|
|
103
|
-
|
|
104
|
-
|
|
216
|
+
// Show metadata
|
|
217
|
+
if (entity.metadata && Object.keys(entity.metadata).length > 0) {
|
|
218
|
+
console.log(chalk.dim(` Metadata: ${JSON.stringify(entity.metadata)}`));
|
|
105
219
|
}
|
|
220
|
+
// Show relationships
|
|
221
|
+
if (options.includeRelations && result.relations) {
|
|
222
|
+
const relations = result.relations;
|
|
223
|
+
if (relations.length > 0) {
|
|
224
|
+
console.log(chalk.dim(` Relations: ${relations.length} connections`));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
console.log();
|
|
106
228
|
});
|
|
229
|
+
// Show search summary
|
|
230
|
+
console.log(chalk.cyan('Search Configuration:'));
|
|
231
|
+
if (searchParams.type) {
|
|
232
|
+
console.log(chalk.dim(` Type filter: ${Array.isArray(searchParams.type) ? searchParams.type.join(', ') : searchParams.type}`));
|
|
233
|
+
}
|
|
234
|
+
if (searchParams.where) {
|
|
235
|
+
console.log(chalk.dim(` Field filter: ${JSON.stringify(searchParams.where)}`));
|
|
236
|
+
}
|
|
237
|
+
if (searchParams.connected) {
|
|
238
|
+
console.log(chalk.dim(` Graph filter: ${JSON.stringify(searchParams.connected)}`));
|
|
239
|
+
}
|
|
240
|
+
if (searchParams.fusion) {
|
|
241
|
+
console.log(chalk.dim(` Fusion: ${searchParams.fusion.strategy}`));
|
|
242
|
+
if (searchParams.fusion.weights && Object.keys(searchParams.fusion.weights).length > 0) {
|
|
243
|
+
console.log(chalk.dim(` Weights: ${JSON.stringify(searchParams.fusion.weights)}`));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
107
246
|
}
|
|
108
247
|
}
|
|
109
248
|
else {
|
|
@@ -113,6 +252,9 @@ export const coreCommands = {
|
|
|
113
252
|
catch (error) {
|
|
114
253
|
spinner.fail('Search failed');
|
|
115
254
|
console.error(chalk.red(error.message));
|
|
255
|
+
if (options.verbose) {
|
|
256
|
+
console.error(chalk.dim(error.stack));
|
|
257
|
+
}
|
|
116
258
|
process.exit(1);
|
|
117
259
|
}
|
|
118
260
|
},
|
|
@@ -122,15 +264,14 @@ export const coreCommands = {
|
|
|
122
264
|
async get(id, options) {
|
|
123
265
|
const spinner = ora('Fetching item...').start();
|
|
124
266
|
try {
|
|
125
|
-
const brain =
|
|
267
|
+
const brain = getBrainy();
|
|
126
268
|
// Try to get the item
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
269
|
+
const item = await brain.get(id);
|
|
270
|
+
if (!item) {
|
|
129
271
|
spinner.fail('Item not found');
|
|
130
272
|
console.log(chalk.yellow(`No item found with ID: ${id}`));
|
|
131
273
|
process.exit(1);
|
|
132
274
|
}
|
|
133
|
-
const item = results[0];
|
|
134
275
|
spinner.succeed('Item found');
|
|
135
276
|
if (!options.json) {
|
|
136
277
|
console.log(chalk.cyan('\nItem Details:'));
|
|
@@ -167,7 +308,7 @@ export const coreCommands = {
|
|
|
167
308
|
async relate(source, verb, target, options) {
|
|
168
309
|
const spinner = ora('Creating relationship...').start();
|
|
169
310
|
try {
|
|
170
|
-
const brain =
|
|
311
|
+
const brain = getBrainy();
|
|
171
312
|
let metadata = {};
|
|
172
313
|
if (options.metadata) {
|
|
173
314
|
try {
|
|
@@ -182,7 +323,12 @@ export const coreCommands = {
|
|
|
182
323
|
metadata.weight = parseFloat(options.weight);
|
|
183
324
|
}
|
|
184
325
|
// Create the relationship
|
|
185
|
-
const result = await brain.
|
|
326
|
+
const result = await brain.relate({
|
|
327
|
+
from: source,
|
|
328
|
+
to: target,
|
|
329
|
+
type: verb,
|
|
330
|
+
metadata
|
|
331
|
+
});
|
|
186
332
|
spinner.succeed('Relationship created');
|
|
187
333
|
if (!options.json) {
|
|
188
334
|
console.log(chalk.green(`✓ Created relationship with ID: ${result}`));
|
|
@@ -207,7 +353,7 @@ export const coreCommands = {
|
|
|
207
353
|
async import(file, options) {
|
|
208
354
|
const spinner = ora('Importing data...').start();
|
|
209
355
|
try {
|
|
210
|
-
const brain =
|
|
356
|
+
const brain = getBrainy();
|
|
211
357
|
const format = options.format || 'json';
|
|
212
358
|
const batchSize = options.batchSize ? parseInt(options.batchSize) : 100;
|
|
213
359
|
// Read file content
|
|
@@ -245,15 +391,28 @@ export const coreCommands = {
|
|
|
245
391
|
for (let i = 0; i < items.length; i += batchSize) {
|
|
246
392
|
const batch = items.slice(i, i + batchSize);
|
|
247
393
|
for (const item of batch) {
|
|
394
|
+
let content;
|
|
395
|
+
let metadata = {};
|
|
248
396
|
if (typeof item === 'string') {
|
|
249
|
-
|
|
397
|
+
content = item;
|
|
250
398
|
}
|
|
251
399
|
else if (item.content || item.text) {
|
|
252
|
-
|
|
400
|
+
content = item.content || item.text;
|
|
401
|
+
metadata = item.metadata || item;
|
|
253
402
|
}
|
|
254
403
|
else {
|
|
255
|
-
|
|
404
|
+
content = JSON.stringify(item);
|
|
405
|
+
metadata = { originalData: item };
|
|
256
406
|
}
|
|
407
|
+
// Use AI to detect type for each item
|
|
408
|
+
const suggestion = await BrainyTypes.suggestNoun(typeof content === 'string' ? { content, ...metadata } : content);
|
|
409
|
+
// Use suggested type or default to Content if low confidence
|
|
410
|
+
const nounType = suggestion.confidence >= 0.5 ? suggestion.type : NounType.Content;
|
|
411
|
+
await brain.add({
|
|
412
|
+
data: content,
|
|
413
|
+
type: nounType,
|
|
414
|
+
metadata
|
|
415
|
+
});
|
|
257
416
|
imported++;
|
|
258
417
|
}
|
|
259
418
|
spinner.text = `Imported ${imported}/${items.length} items...`;
|
|
@@ -280,10 +439,11 @@ export const coreCommands = {
|
|
|
280
439
|
async export(file, options) {
|
|
281
440
|
const spinner = ora('Exporting database...').start();
|
|
282
441
|
try {
|
|
283
|
-
const brain =
|
|
442
|
+
const brain = getBrainy();
|
|
284
443
|
const format = options.format || 'json';
|
|
285
444
|
// Export all data
|
|
286
|
-
const
|
|
445
|
+
const dataApi = await brain.data();
|
|
446
|
+
const data = await dataApi.export({ format: 'json' });
|
|
287
447
|
let output = '';
|
|
288
448
|
switch (format) {
|
|
289
449
|
case 'json':
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Management Commands
|
|
3
|
+
*
|
|
4
|
+
* Backup, restore, import, export operations
|
|
5
|
+
*/
|
|
6
|
+
interface DataOptions {
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
pretty?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const dataCommands: {
|
|
12
|
+
/**
|
|
13
|
+
* Backup database
|
|
14
|
+
*/
|
|
15
|
+
backup(file: string, options: DataOptions & {
|
|
16
|
+
compress?: boolean;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Restore from backup
|
|
20
|
+
*/
|
|
21
|
+
restore(file: string, options: DataOptions & {
|
|
22
|
+
merge?: boolean;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Get database statistics
|
|
26
|
+
*/
|
|
27
|
+
stats(options: DataOptions): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Management Commands
|
|
3
|
+
*
|
|
4
|
+
* Backup, restore, import, export operations
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { Brainy } from '../../brainy.js';
|
|
10
|
+
let brainyInstance = null;
|
|
11
|
+
const getBrainy = () => {
|
|
12
|
+
if (!brainyInstance) {
|
|
13
|
+
brainyInstance = new Brainy();
|
|
14
|
+
}
|
|
15
|
+
return brainyInstance;
|
|
16
|
+
};
|
|
17
|
+
const formatOutput = (data, options) => {
|
|
18
|
+
if (options.json) {
|
|
19
|
+
console.log(options.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const dataCommands = {
|
|
23
|
+
/**
|
|
24
|
+
* Backup database
|
|
25
|
+
*/
|
|
26
|
+
async backup(file, options) {
|
|
27
|
+
const spinner = ora('Creating backup...').start();
|
|
28
|
+
try {
|
|
29
|
+
const brain = getBrainy();
|
|
30
|
+
const dataApi = await brain.data();
|
|
31
|
+
const backup = await dataApi.backup({
|
|
32
|
+
compress: options.compress
|
|
33
|
+
});
|
|
34
|
+
spinner.text = 'Writing backup file...';
|
|
35
|
+
// Write backup to file
|
|
36
|
+
const content = typeof backup === 'string'
|
|
37
|
+
? backup
|
|
38
|
+
: JSON.stringify(backup, null, options.pretty ? 2 : 0);
|
|
39
|
+
writeFileSync(file, content);
|
|
40
|
+
spinner.succeed('Backup created');
|
|
41
|
+
if (!options.json) {
|
|
42
|
+
console.log(chalk.green(`✓ Backup saved to: ${file}`));
|
|
43
|
+
if (backup.compressed) {
|
|
44
|
+
console.log(chalk.dim(` Original size: ${formatBytes(backup.originalSize)}`));
|
|
45
|
+
console.log(chalk.dim(` Compressed size: ${formatBytes(backup.compressedSize)}`));
|
|
46
|
+
console.log(chalk.dim(` Compression ratio: ${((backup.compressedSize / backup.originalSize) * 100).toFixed(1)}%`));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
formatOutput({ file, backup: true }, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
spinner.fail('Backup failed');
|
|
55
|
+
console.error(chalk.red(error.message));
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Restore from backup
|
|
61
|
+
*/
|
|
62
|
+
async restore(file, options) {
|
|
63
|
+
const spinner = ora('Restoring from backup...').start();
|
|
64
|
+
try {
|
|
65
|
+
const brain = getBrainy();
|
|
66
|
+
const dataApi = await brain.data();
|
|
67
|
+
// Read backup file
|
|
68
|
+
const content = readFileSync(file, 'utf-8');
|
|
69
|
+
const backup = JSON.parse(content);
|
|
70
|
+
// Restore
|
|
71
|
+
await dataApi.restore({
|
|
72
|
+
backup,
|
|
73
|
+
merge: options.merge || false
|
|
74
|
+
});
|
|
75
|
+
spinner.succeed('Restore complete');
|
|
76
|
+
if (!options.json) {
|
|
77
|
+
console.log(chalk.green(`✓ Restored from: ${file}`));
|
|
78
|
+
if (options.merge) {
|
|
79
|
+
console.log(chalk.dim(' Mode: Merged with existing data'));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.log(chalk.dim(' Mode: Replaced all data'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
formatOutput({ file, restored: true }, options);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
spinner.fail('Restore failed');
|
|
91
|
+
console.error(chalk.red(error.message));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Get database statistics
|
|
97
|
+
*/
|
|
98
|
+
async stats(options) {
|
|
99
|
+
const spinner = ora('Gathering statistics...').start();
|
|
100
|
+
try {
|
|
101
|
+
const brain = getBrainy();
|
|
102
|
+
const dataApi = await brain.data();
|
|
103
|
+
const stats = await dataApi.getStats();
|
|
104
|
+
spinner.succeed('Statistics gathered');
|
|
105
|
+
if (!options.json) {
|
|
106
|
+
console.log(chalk.cyan('\n📊 Database Statistics:\n'));
|
|
107
|
+
console.log(chalk.bold('Entities:'));
|
|
108
|
+
console.log(` Total: ${chalk.green(stats.entities)}`);
|
|
109
|
+
console.log(chalk.bold('\nRelationships:'));
|
|
110
|
+
console.log(` Total: ${chalk.green(stats.relations)}`);
|
|
111
|
+
if (stats.storageSize) {
|
|
112
|
+
console.log(chalk.bold('\nStorage:'));
|
|
113
|
+
console.log(` Size: ${chalk.green(formatBytes(stats.storageSize))}`);
|
|
114
|
+
}
|
|
115
|
+
if (stats.vectorDimensions) {
|
|
116
|
+
console.log(chalk.bold('\nVector Index:'));
|
|
117
|
+
console.log(` Dimensions: ${stats.vectorDimensions}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
formatOutput(stats, options);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
spinner.fail('Failed to get statistics');
|
|
126
|
+
console.error(chalk.red(error.message));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
function formatBytes(bytes) {
|
|
132
|
+
if (bytes === 0)
|
|
133
|
+
return '0 B';
|
|
134
|
+
const k = 1024;
|
|
135
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
136
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
137
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -22,4 +22,18 @@ export declare const neuralCommand: {
|
|
|
22
22
|
builder: (yargs: any) => any;
|
|
23
23
|
handler: (argv: CommandArguments) => Promise<void>;
|
|
24
24
|
};
|
|
25
|
+
declare function handleSimilarCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
26
|
+
declare function handleClustersCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
27
|
+
declare function handleHierarchyCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
28
|
+
declare function handleNeighborsCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
29
|
+
declare function handleOutliersCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
30
|
+
declare function handleVisualizeCommand(neural: any, argv: CommandArguments): Promise<void>;
|
|
31
|
+
export declare const neuralCommands: {
|
|
32
|
+
similar: typeof handleSimilarCommand;
|
|
33
|
+
cluster: typeof handleClustersCommand;
|
|
34
|
+
hierarchy: typeof handleHierarchyCommand;
|
|
35
|
+
related: typeof handleNeighborsCommand;
|
|
36
|
+
outliers: typeof handleOutliersCommand;
|
|
37
|
+
visualize: typeof handleVisualizeCommand;
|
|
38
|
+
};
|
|
25
39
|
export default neuralCommand;
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
import inquirer from 'inquirer';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import ora from 'ora';
|
|
9
|
-
import fs from 'fs';
|
|
10
|
-
import path from 'path';
|
|
11
|
-
import {
|
|
12
|
-
import { NeuralAPI } from '../../neural/neuralAPI.js';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { Brainy } from '../../brainy.js';
|
|
13
12
|
export const neuralCommand = {
|
|
14
13
|
command: 'neural [action]',
|
|
15
14
|
describe: '🧠 Neural similarity and clustering operations',
|
|
@@ -79,8 +78,8 @@ export const neuralCommand = {
|
|
|
79
78
|
console.log(chalk.cyan('\n🧠 NEURAL SIMILARITY API'));
|
|
80
79
|
console.log(chalk.gray('━'.repeat(50)));
|
|
81
80
|
// Initialize Brainy and Neural API
|
|
82
|
-
const brain = new
|
|
83
|
-
const neural =
|
|
81
|
+
const brain = new Brainy();
|
|
82
|
+
const neural = brain.neural();
|
|
84
83
|
try {
|
|
85
84
|
const action = argv.action || await promptForAction();
|
|
86
85
|
switch (action) {
|
|
@@ -97,7 +96,9 @@ export const neuralCommand = {
|
|
|
97
96
|
await handleNeighborsCommand(neural, argv);
|
|
98
97
|
break;
|
|
99
98
|
case 'path':
|
|
100
|
-
|
|
99
|
+
console.log(chalk.yellow('\n⚠️ Semantic path finding coming in v3.21.0'));
|
|
100
|
+
console.log(chalk.dim('This feature requires implementing graph traversal algorithms'));
|
|
101
|
+
console.log(chalk.dim('Use "neighbors" and "hierarchy" commands to explore connections'));
|
|
101
102
|
break;
|
|
102
103
|
case 'outliers':
|
|
103
104
|
await handleOutliersCommand(neural, argv);
|
|
@@ -126,7 +127,7 @@ async function promptForAction() {
|
|
|
126
127
|
{ name: '🎯 Find semantic clusters', value: 'clusters' },
|
|
127
128
|
{ name: '🌳 Show item hierarchy', value: 'hierarchy' },
|
|
128
129
|
{ name: '🕸️ Find semantic neighbors', value: 'neighbors' },
|
|
129
|
-
{ name: '🛣️ Find semantic path between items', value: 'path' },
|
|
130
|
+
{ name: '🛣️ Find semantic path between items (v3.21.0)', value: 'path', disabled: true },
|
|
130
131
|
{ name: '🚨 Detect outliers', value: 'outliers' },
|
|
131
132
|
{ name: '📊 Generate visualization data', value: 'visualize' }
|
|
132
133
|
]
|
|
@@ -504,5 +505,14 @@ function showHelp() {
|
|
|
504
505
|
console.log(' --explain, -e Include explanations');
|
|
505
506
|
console.log('');
|
|
506
507
|
}
|
|
508
|
+
export const neuralCommands = {
|
|
509
|
+
similar: handleSimilarCommand,
|
|
510
|
+
cluster: handleClustersCommand,
|
|
511
|
+
hierarchy: handleHierarchyCommand,
|
|
512
|
+
related: handleNeighborsCommand,
|
|
513
|
+
// path: handlePathCommand, // Coming in v3.21.0 - requires graph traversal implementation
|
|
514
|
+
outliers: handleOutliersCommand,
|
|
515
|
+
visualize: handleVisualizeCommand
|
|
516
|
+
};
|
|
507
517
|
export default neuralCommand;
|
|
508
518
|
//# sourceMappingURL=neural.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Commands for Type Management
|
|
3
|
+
* Consistent with BrainyTypes public API
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* List types - matches BrainyTypes.nouns and BrainyTypes.verbs
|
|
7
|
+
* Usage: brainy types
|
|
8
|
+
*/
|
|
9
|
+
export declare function types(options: {
|
|
10
|
+
json?: boolean;
|
|
11
|
+
noun?: boolean;
|
|
12
|
+
verb?: boolean;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Suggest type - matches BrainyTypes.suggestNoun() and suggestVerb()
|
|
16
|
+
* Usage: brainy suggest <data>
|
|
17
|
+
* Interactive if data not provided
|
|
18
|
+
*/
|
|
19
|
+
export declare function suggest(data?: string, options?: {
|
|
20
|
+
verb?: boolean;
|
|
21
|
+
json?: boolean;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Validate type - matches BrainyTypes.isValidNoun() and isValidVerb()
|
|
25
|
+
* Usage: brainy validate <type>
|
|
26
|
+
*/
|
|
27
|
+
export declare function validate(type?: string, options?: {
|
|
28
|
+
verb?: boolean;
|
|
29
|
+
json?: boolean;
|
|
30
|
+
}): Promise<void>;
|