@soulcraft/brainy 3.19.1 β 3.20.1
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/bin/brainy-minimal.js +82 -0
- package/dist/cli/commands/conversation.js +10 -0
- package/dist/cli/commands/core.d.ts +14 -2
- package/dist/cli/commands/core.js +142 -26
- 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 +16 -5
- package/dist/cli/commands/utility.js +39 -97
- package/dist/cli/commands/vfs.d.ts +73 -0
- package/dist/cli/commands/vfs.js +372 -0
- package/dist/cli/index.js +201 -6
- package/dist/cli/interactive.d.ts +5 -0
- package/dist/cli/interactive.js +32 -8
- package/package.json +4 -1
|
@@ -8,8 +8,7 @@ import chalk from 'chalk';
|
|
|
8
8
|
import ora from 'ora';
|
|
9
9
|
import fs from 'node:fs';
|
|
10
10
|
import path from 'node:path';
|
|
11
|
-
import { Brainy } from '../../
|
|
12
|
-
import { NeuralAPI } from '../../neural/neuralAPI.js';
|
|
11
|
+
import { Brainy } from '../../brainy.js';
|
|
13
12
|
export const neuralCommand = {
|
|
14
13
|
command: 'neural [action]',
|
|
15
14
|
describe: 'π§ Neural similarity and clustering operations',
|
|
@@ -80,7 +79,7 @@ export const neuralCommand = {
|
|
|
80
79
|
console.log(chalk.gray('β'.repeat(50)));
|
|
81
80
|
// Initialize Brainy and Neural API
|
|
82
81
|
const brain = new Brainy();
|
|
83
|
-
const neural =
|
|
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,4 +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;
|
|
518
|
+
//# sourceMappingURL=neural.js.map
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import ora from 'ora';
|
|
8
8
|
import Table from 'cli-table3';
|
|
9
|
-
import { Brainy } from '../../
|
|
9
|
+
import { Brainy } from '../../brainy.js';
|
|
10
|
+
import { NounType } from '../../types/graphTypes.js';
|
|
10
11
|
let brainyInstance = null;
|
|
11
|
-
const getBrainy =
|
|
12
|
+
const getBrainy = () => {
|
|
12
13
|
if (!brainyInstance) {
|
|
13
14
|
brainyInstance = new Brainy();
|
|
14
|
-
await brainyInstance.init();
|
|
15
15
|
}
|
|
16
16
|
return brainyInstance;
|
|
17
17
|
};
|
|
@@ -35,10 +35,16 @@ export const utilityCommands = {
|
|
|
35
35
|
async stats(options) {
|
|
36
36
|
const spinner = ora('Gathering statistics...').start();
|
|
37
37
|
try {
|
|
38
|
-
const brain =
|
|
39
|
-
const
|
|
38
|
+
const brain = getBrainy();
|
|
39
|
+
const nounCount = await brain.getNounCount();
|
|
40
|
+
const verbCount = await brain.getVerbCount();
|
|
40
41
|
const memUsage = process.memoryUsage();
|
|
41
42
|
spinner.succeed('Statistics gathered');
|
|
43
|
+
const stats = {
|
|
44
|
+
nounCount,
|
|
45
|
+
verbCount,
|
|
46
|
+
totalItems: nounCount + verbCount
|
|
47
|
+
};
|
|
42
48
|
if (options.json) {
|
|
43
49
|
formatOutput(stats, options);
|
|
44
50
|
return;
|
|
@@ -49,53 +55,8 @@ export const utilityCommands = {
|
|
|
49
55
|
head: [chalk.cyan('Metric'), chalk.cyan('Value')],
|
|
50
56
|
style: { head: [], border: [] }
|
|
51
57
|
});
|
|
52
|
-
coreTable.push(['Total Items', chalk.green(stats.
|
|
58
|
+
coreTable.push(['Total Items', chalk.green(stats.totalItems)], ['Nouns', chalk.green(stats.nounCount)], ['Verbs (Relationships)', chalk.green(stats.verbCount)]);
|
|
53
59
|
console.log(coreTable.toString());
|
|
54
|
-
// Service breakdown if available
|
|
55
|
-
if (options.byService && stats.serviceBreakdown) {
|
|
56
|
-
console.log(chalk.cyan('\nπ§ Service Breakdown\n'));
|
|
57
|
-
const serviceTable = new Table({
|
|
58
|
-
head: [chalk.cyan('Service'), chalk.cyan('Nouns'), chalk.cyan('Verbs'), chalk.cyan('Metadata')],
|
|
59
|
-
style: { head: [], border: [] }
|
|
60
|
-
});
|
|
61
|
-
Object.entries(stats.serviceBreakdown).forEach(([service, serviceStats]) => {
|
|
62
|
-
serviceTable.push([
|
|
63
|
-
service,
|
|
64
|
-
serviceStats.nounCount || 0,
|
|
65
|
-
serviceStats.verbCount || 0,
|
|
66
|
-
serviceStats.metadataCount || 0
|
|
67
|
-
]);
|
|
68
|
-
});
|
|
69
|
-
console.log(serviceTable.toString());
|
|
70
|
-
}
|
|
71
|
-
// Storage info
|
|
72
|
-
if (stats.storage) {
|
|
73
|
-
console.log(chalk.cyan('\nπΎ Storage\n'));
|
|
74
|
-
const storageTable = new Table({
|
|
75
|
-
head: [chalk.cyan('Property'), chalk.cyan('Value')],
|
|
76
|
-
style: { head: [], border: [] }
|
|
77
|
-
});
|
|
78
|
-
storageTable.push(['Type', stats.storage.type || 'Unknown'], ['Size', stats.storage.size ? formatBytes(stats.storage.size) : 'N/A'], ['Location', stats.storage.location || 'N/A']);
|
|
79
|
-
console.log(storageTable.toString());
|
|
80
|
-
}
|
|
81
|
-
// Performance metrics
|
|
82
|
-
if (stats.performance && options.detailed) {
|
|
83
|
-
console.log(chalk.cyan('\nβ‘ Performance\n'));
|
|
84
|
-
const perfTable = new Table({
|
|
85
|
-
head: [chalk.cyan('Metric'), chalk.cyan('Value')],
|
|
86
|
-
style: { head: [], border: [] }
|
|
87
|
-
});
|
|
88
|
-
if (stats.performance.avgQueryTime) {
|
|
89
|
-
perfTable.push(['Avg Query Time', `${stats.performance.avgQueryTime.toFixed(2)} ms`]);
|
|
90
|
-
}
|
|
91
|
-
if (stats.performance.totalQueries) {
|
|
92
|
-
perfTable.push(['Total Queries', stats.performance.totalQueries]);
|
|
93
|
-
}
|
|
94
|
-
if (stats.performance.cacheHitRate) {
|
|
95
|
-
perfTable.push(['Cache Hit Rate', `${(stats.performance.cacheHitRate * 100).toFixed(1)}%`]);
|
|
96
|
-
}
|
|
97
|
-
console.log(perfTable.toString());
|
|
98
|
-
}
|
|
99
60
|
// Memory usage
|
|
100
61
|
console.log(chalk.cyan('\nπ§ Memory Usage\n'));
|
|
101
62
|
const memTable = new Table({
|
|
@@ -104,16 +65,6 @@ export const utilityCommands = {
|
|
|
104
65
|
});
|
|
105
66
|
memTable.push(['Heap Used', formatBytes(memUsage.heapUsed)], ['Heap Total', formatBytes(memUsage.heapTotal)], ['RSS', formatBytes(memUsage.rss)], ['External', formatBytes(memUsage.external)]);
|
|
106
67
|
console.log(memTable.toString());
|
|
107
|
-
// Index info
|
|
108
|
-
if (stats.index && options.detailed) {
|
|
109
|
-
console.log(chalk.cyan('\nπ― Vector Index\n'));
|
|
110
|
-
const indexTable = new Table({
|
|
111
|
-
head: [chalk.cyan('Property'), chalk.cyan('Value')],
|
|
112
|
-
style: { head: [], border: [] }
|
|
113
|
-
});
|
|
114
|
-
indexTable.push(['Dimensions', stats.index.dimensions || 'N/A'], ['Indexed Vectors', stats.index.vectorCount || 0], ['Index Size', stats.index.indexSize ? formatBytes(stats.index.indexSize) : 'N/A']);
|
|
115
|
-
console.log(indexTable.toString());
|
|
116
|
-
}
|
|
117
68
|
}
|
|
118
69
|
catch (error) {
|
|
119
70
|
spinner.fail('Failed to gather statistics');
|
|
@@ -127,40 +78,30 @@ export const utilityCommands = {
|
|
|
127
78
|
async clean(options) {
|
|
128
79
|
const spinner = ora('Cleaning database...').start();
|
|
129
80
|
try {
|
|
130
|
-
const brain =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
tasks.push('Rebuilt search index');
|
|
141
|
-
// Implementation would go here
|
|
142
|
-
await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate work
|
|
143
|
-
}
|
|
144
|
-
if (tasks.length === 0) {
|
|
145
|
-
spinner.text = 'Running general cleanup...';
|
|
146
|
-
tasks.push('General cleanup completed');
|
|
147
|
-
// Run general cleanup tasks
|
|
148
|
-
await new Promise(resolve => setTimeout(resolve, 500)); // Simulate work
|
|
81
|
+
const brain = getBrainy();
|
|
82
|
+
// For now, only support full clear
|
|
83
|
+
// removeOrphans and rebuildIndex would require new Brainy APIs
|
|
84
|
+
if (options.removeOrphans || options.rebuildIndex) {
|
|
85
|
+
spinner.warn('Advanced cleanup options not yet implemented');
|
|
86
|
+
console.log(chalk.yellow('\nβ οΈ Advanced cleanup features coming in v3.21.0:'));
|
|
87
|
+
console.log(chalk.dim(' β’ --remove-orphans: Remove disconnected items'));
|
|
88
|
+
console.log(chalk.dim(' β’ --rebuild-index: Rebuild vector index'));
|
|
89
|
+
console.log(chalk.dim('\nUse "brainy clean" without options to clear the database'));
|
|
90
|
+
return;
|
|
149
91
|
}
|
|
150
|
-
|
|
92
|
+
// Show warning before clearing
|
|
93
|
+
console.log(chalk.yellow('\nβ οΈ WARNING: This will permanently delete ALL data!'));
|
|
94
|
+
const dataApi = await brain.data();
|
|
95
|
+
// Clear all data
|
|
96
|
+
spinner.text = 'Clearing all data...';
|
|
97
|
+
await dataApi.clear({ entities: true, relations: true });
|
|
98
|
+
spinner.succeed('Database cleared');
|
|
151
99
|
if (!options.json) {
|
|
152
|
-
console.log(chalk.green('\nβ
|
|
153
|
-
|
|
154
|
-
console.log(chalk.dim(` β’ ${task}`));
|
|
155
|
-
});
|
|
156
|
-
// Get new stats
|
|
157
|
-
const stats = await brain.getStatistics();
|
|
158
|
-
console.log(chalk.cyan('\nDatabase Status:'));
|
|
159
|
-
console.log(` Total items: ${stats.nounCount + stats.verbCount}`);
|
|
160
|
-
console.log(` Index status: ${chalk.green('Healthy')}`);
|
|
100
|
+
console.log(chalk.green('\nβ Database cleared successfully'));
|
|
101
|
+
console.log(chalk.dim(' All nouns, verbs, and metadata have been removed'));
|
|
161
102
|
}
|
|
162
103
|
else {
|
|
163
|
-
formatOutput({
|
|
104
|
+
formatOutput({ cleared: true, success: true }, options);
|
|
164
105
|
}
|
|
165
106
|
}
|
|
166
107
|
catch (error) {
|
|
@@ -181,7 +122,7 @@ export const utilityCommands = {
|
|
|
181
122
|
summary: {}
|
|
182
123
|
};
|
|
183
124
|
try {
|
|
184
|
-
const brain =
|
|
125
|
+
const brain = getBrainy();
|
|
185
126
|
// Benchmark different operations
|
|
186
127
|
const benchmarks = [
|
|
187
128
|
{ name: 'add', enabled: operations === 'all' || operations.includes('add') },
|
|
@@ -198,17 +139,17 @@ export const utilityCommands = {
|
|
|
198
139
|
const start = Date.now();
|
|
199
140
|
switch (bench.name) {
|
|
200
141
|
case 'add':
|
|
201
|
-
await brain.add(`Test item ${i}`, { benchmark: true });
|
|
142
|
+
await brain.add({ data: `Test item ${i}`, type: NounType.Thing, metadata: { benchmark: true } });
|
|
202
143
|
break;
|
|
203
144
|
case 'search':
|
|
204
|
-
await brain.
|
|
145
|
+
await brain.find({ query: 'test', limit: 10 });
|
|
205
146
|
break;
|
|
206
147
|
case 'similarity':
|
|
207
|
-
const neural = brain.neural;
|
|
148
|
+
const neural = brain.neural();
|
|
208
149
|
await neural.similar('test1', 'test2');
|
|
209
150
|
break;
|
|
210
151
|
case 'cluster':
|
|
211
|
-
const neuralApi = brain.neural;
|
|
152
|
+
const neuralApi = brain.neural();
|
|
212
153
|
await neuralApi.clusters();
|
|
213
154
|
break;
|
|
214
155
|
}
|
|
@@ -232,7 +173,7 @@ export const utilityCommands = {
|
|
|
232
173
|
const totalOps = Object.values(results.operations).reduce((sum, op) => sum + parseFloat(op.ops), 0);
|
|
233
174
|
results.summary = {
|
|
234
175
|
totalOperations: Object.keys(results.operations).length,
|
|
235
|
-
averageOpsPerSec: (totalOps / Object.keys(results.operations).length).toFixed(2)
|
|
176
|
+
averageOpsPerSec: totalOps > 0 ? (totalOps / Object.keys(results.operations).length).toFixed(2) : '0'
|
|
236
177
|
};
|
|
237
178
|
if (!options.json) {
|
|
238
179
|
// Display results table
|
|
@@ -273,3 +214,4 @@ export const utilityCommands = {
|
|
|
273
214
|
}
|
|
274
215
|
}
|
|
275
216
|
};
|
|
217
|
+
//# sourceMappingURL=utility.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VFS CLI Commands - Virtual File System Operations
|
|
3
|
+
*
|
|
4
|
+
* Complete filesystem-like interface for Brainy's VFS
|
|
5
|
+
*/
|
|
6
|
+
interface VFSOptions {
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
pretty?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const vfsCommands: {
|
|
12
|
+
/**
|
|
13
|
+
* Read file from VFS
|
|
14
|
+
*/
|
|
15
|
+
read(path: string, options: VFSOptions & {
|
|
16
|
+
output?: string;
|
|
17
|
+
encoding?: string;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Write file to VFS
|
|
21
|
+
*/
|
|
22
|
+
write(path: string, options: VFSOptions & {
|
|
23
|
+
content?: string;
|
|
24
|
+
file?: string;
|
|
25
|
+
encoding?: string;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* List directory contents
|
|
29
|
+
*/
|
|
30
|
+
ls(path: string, options: VFSOptions & {
|
|
31
|
+
long?: boolean;
|
|
32
|
+
all?: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get file/directory stats
|
|
36
|
+
*/
|
|
37
|
+
stat(path: string, options: VFSOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Create directory
|
|
40
|
+
*/
|
|
41
|
+
mkdir(path: string, options: VFSOptions & {
|
|
42
|
+
parents?: boolean;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Remove file or directory
|
|
46
|
+
*/
|
|
47
|
+
rm(path: string, options: VFSOptions & {
|
|
48
|
+
recursive?: boolean;
|
|
49
|
+
force?: boolean;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Search files by content
|
|
53
|
+
*/
|
|
54
|
+
search(query: string, options: VFSOptions & {
|
|
55
|
+
path?: string;
|
|
56
|
+
limit?: string;
|
|
57
|
+
type?: string;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Find similar files
|
|
61
|
+
*/
|
|
62
|
+
similar(path: string, options: VFSOptions & {
|
|
63
|
+
limit?: string;
|
|
64
|
+
threshold?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Get directory tree structure
|
|
68
|
+
*/
|
|
69
|
+
tree(path: string, options: VFSOptions & {
|
|
70
|
+
depth?: string;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
export {};
|