@soulcraft/brainy 1.5.0 → 2.0.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/CHANGELOG.md +188 -0
- package/LICENSE +2 -2
- package/README.md +200 -595
- package/bin/brainy-interactive.js +564 -0
- package/bin/brainy-ts.js +18 -0
- package/bin/brainy.js +672 -81
- package/dist/augmentationPipeline.d.ts +48 -220
- package/dist/augmentationPipeline.js +60 -508
- package/dist/augmentationRegistry.d.ts +22 -31
- package/dist/augmentationRegistry.js +28 -79
- package/dist/augmentations/apiServerAugmentation.d.ts +108 -0
- package/dist/augmentations/apiServerAugmentation.js +502 -0
- package/dist/augmentations/batchProcessingAugmentation.d.ts +95 -0
- package/dist/augmentations/batchProcessingAugmentation.js +567 -0
- package/dist/augmentations/brainyAugmentation.d.ts +153 -0
- package/dist/augmentations/brainyAugmentation.js +145 -0
- package/dist/augmentations/cacheAugmentation.d.ts +105 -0
- package/dist/augmentations/cacheAugmentation.js +238 -0
- package/dist/augmentations/conduitAugmentations.d.ts +54 -156
- package/dist/augmentations/conduitAugmentations.js +156 -1082
- package/dist/augmentations/connectionPoolAugmentation.d.ts +62 -0
- package/dist/augmentations/connectionPoolAugmentation.js +316 -0
- package/dist/augmentations/defaultAugmentations.d.ts +53 -0
- package/dist/augmentations/defaultAugmentations.js +88 -0
- package/dist/augmentations/entityRegistryAugmentation.d.ts +126 -0
- package/dist/augmentations/entityRegistryAugmentation.js +386 -0
- package/dist/augmentations/indexAugmentation.d.ts +117 -0
- package/dist/augmentations/indexAugmentation.js +284 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +152 -0
- package/dist/augmentations/intelligentVerbScoringAugmentation.js +554 -0
- package/dist/augmentations/metricsAugmentation.d.ts +202 -0
- package/dist/augmentations/metricsAugmentation.js +291 -0
- package/dist/augmentations/monitoringAugmentation.d.ts +94 -0
- package/dist/augmentations/monitoringAugmentation.js +227 -0
- package/dist/augmentations/neuralImport.d.ts +50 -117
- package/dist/augmentations/neuralImport.js +255 -629
- package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +52 -0
- package/dist/augmentations/requestDeduplicatorAugmentation.js +162 -0
- package/dist/augmentations/serverSearchAugmentations.d.ts +43 -22
- package/dist/augmentations/serverSearchAugmentations.js +125 -72
- package/dist/augmentations/storageAugmentation.d.ts +54 -0
- package/dist/augmentations/storageAugmentation.js +93 -0
- package/dist/augmentations/storageAugmentations.d.ts +96 -0
- package/dist/augmentations/storageAugmentations.js +182 -0
- package/dist/augmentations/synapseAugmentation.d.ts +156 -0
- package/dist/augmentations/synapseAugmentation.js +312 -0
- package/dist/augmentations/walAugmentation.d.ts +108 -0
- package/dist/augmentations/walAugmentation.js +515 -0
- package/dist/brainyData.d.ts +404 -130
- package/dist/brainyData.js +1331 -853
- package/dist/chat/BrainyChat.d.ts +16 -8
- package/dist/chat/BrainyChat.js +60 -32
- package/dist/chat/ChatCLI.d.ts +1 -1
- package/dist/chat/ChatCLI.js +6 -6
- package/dist/cli/catalog.d.ts +3 -3
- package/dist/cli/catalog.js +116 -70
- package/dist/cli/commands/core.d.ts +61 -0
- package/dist/cli/commands/core.js +348 -0
- package/dist/cli/commands/neural.d.ts +25 -0
- package/dist/cli/commands/neural.js +508 -0
- package/dist/cli/commands/utility.d.ts +37 -0
- package/dist/cli/commands/utility.js +276 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +167 -0
- package/dist/cli/interactive.d.ts +164 -0
- package/dist/cli/interactive.js +542 -0
- package/dist/cortex/neuralImport.js +5 -5
- package/dist/critical/model-guardian.js +11 -4
- package/dist/embeddings/lightweight-embedder.d.ts +23 -0
- package/dist/embeddings/lightweight-embedder.js +136 -0
- package/dist/embeddings/universal-memory-manager.d.ts +38 -0
- package/dist/embeddings/universal-memory-manager.js +206 -0
- package/dist/embeddings/worker-embedding.d.ts +7 -0
- package/dist/embeddings/worker-embedding.js +77 -0
- package/dist/embeddings/worker-manager.d.ts +28 -0
- package/dist/embeddings/worker-manager.js +162 -0
- package/dist/examples/basicUsage.js +7 -7
- package/dist/graph/pathfinding.d.ts +78 -0
- package/dist/graph/pathfinding.js +393 -0
- package/dist/hnsw/hnswIndex.d.ts +13 -0
- package/dist/hnsw/hnswIndex.js +35 -0
- package/dist/hnsw/hnswIndexOptimized.d.ts +1 -0
- package/dist/hnsw/hnswIndexOptimized.js +3 -0
- package/dist/index.d.ts +9 -11
- package/dist/index.js +21 -11
- package/dist/indices/fieldIndex.d.ts +76 -0
- package/dist/indices/fieldIndex.js +357 -0
- package/dist/mcp/brainyMCPAdapter.js +3 -2
- package/dist/mcp/mcpAugmentationToolset.js +11 -17
- package/dist/neural/embeddedPatterns.d.ts +41 -0
- package/dist/neural/embeddedPatterns.js +4044 -0
- package/dist/neural/naturalLanguageProcessor.d.ts +94 -0
- package/dist/neural/naturalLanguageProcessor.js +317 -0
- package/dist/neural/naturalLanguageProcessorStatic.d.ts +64 -0
- package/dist/neural/naturalLanguageProcessorStatic.js +151 -0
- package/dist/neural/neuralAPI.d.ts +255 -0
- package/dist/neural/neuralAPI.js +612 -0
- package/dist/neural/patternLibrary.d.ts +101 -0
- package/dist/neural/patternLibrary.js +313 -0
- package/dist/neural/patterns.d.ts +27 -0
- package/dist/neural/patterns.js +68 -0
- package/dist/neural/staticPatternMatcher.d.ts +35 -0
- package/dist/neural/staticPatternMatcher.js +153 -0
- package/dist/scripts/precomputePatternEmbeddings.d.ts +19 -0
- package/dist/scripts/precomputePatternEmbeddings.js +100 -0
- package/dist/storage/adapters/fileSystemStorage.d.ts +5 -0
- package/dist/storage/adapters/fileSystemStorage.js +20 -0
- package/dist/storage/adapters/s3CompatibleStorage.d.ts +5 -0
- package/dist/storage/adapters/s3CompatibleStorage.js +16 -0
- package/dist/storage/enhancedClearOperations.d.ts +83 -0
- package/dist/storage/enhancedClearOperations.js +345 -0
- package/dist/storage/storageFactory.js +31 -27
- package/dist/triple/TripleIntelligence.d.ts +134 -0
- package/dist/triple/TripleIntelligence.js +548 -0
- package/dist/types/augmentations.d.ts +45 -344
- package/dist/types/augmentations.js +5 -2
- package/dist/types/brainyDataInterface.d.ts +20 -10
- package/dist/types/graphTypes.d.ts +46 -0
- package/dist/types/graphTypes.js +16 -2
- package/dist/utils/BoundedRegistry.d.ts +29 -0
- package/dist/utils/BoundedRegistry.js +54 -0
- package/dist/utils/embedding.js +20 -3
- package/dist/utils/hybridModelManager.js +10 -5
- package/dist/utils/metadataFilter.d.ts +33 -19
- package/dist/utils/metadataFilter.js +58 -23
- package/dist/utils/metadataIndex.d.ts +37 -6
- package/dist/utils/metadataIndex.js +427 -64
- package/dist/utils/requestDeduplicator.d.ts +10 -0
- package/dist/utils/requestDeduplicator.js +24 -0
- package/dist/utils/unifiedCache.d.ts +103 -0
- package/dist/utils/unifiedCache.js +311 -0
- package/package.json +40 -125
- package/scripts/ensure-models.js +108 -0
- package/scripts/prepare-models.js +387 -0
- package/OFFLINE_MODELS.md +0 -56
- package/dist/intelligence/neuralEngine.d.ts +0 -207
- package/dist/intelligence/neuralEngine.js +0 -706
- package/dist/utils/modelLoader.d.ts +0 -32
- package/dist/utils/modelLoader.js +0 -219
- package/dist/utils/modelManager.d.ts +0 -77
- package/dist/utils/modelManager.js +0 -219
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility CLI Commands - TypeScript Implementation
|
|
3
|
+
*
|
|
4
|
+
* Database maintenance, statistics, and benchmarking
|
|
5
|
+
*/
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
import Table from 'cli-table3';
|
|
9
|
+
import { BrainyData } from '../../brainyData.js';
|
|
10
|
+
let brainyInstance = null;
|
|
11
|
+
const getBrainy = async () => {
|
|
12
|
+
if (!brainyInstance) {
|
|
13
|
+
brainyInstance = new BrainyData();
|
|
14
|
+
await brainyInstance.init();
|
|
15
|
+
}
|
|
16
|
+
return brainyInstance;
|
|
17
|
+
};
|
|
18
|
+
const formatBytes = (bytes) => {
|
|
19
|
+
if (bytes === 0)
|
|
20
|
+
return '0 B';
|
|
21
|
+
const k = 1024;
|
|
22
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
23
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
24
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
25
|
+
};
|
|
26
|
+
const formatOutput = (data, options) => {
|
|
27
|
+
if (options.json) {
|
|
28
|
+
console.log(options.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const utilityCommands = {
|
|
32
|
+
/**
|
|
33
|
+
* Show database statistics
|
|
34
|
+
*/
|
|
35
|
+
async stats(options) {
|
|
36
|
+
const spinner = ora('Gathering statistics...').start();
|
|
37
|
+
try {
|
|
38
|
+
const brain = await getBrainy();
|
|
39
|
+
const stats = await brain.getStatistics();
|
|
40
|
+
const memUsage = process.memoryUsage();
|
|
41
|
+
spinner.succeed('Statistics gathered');
|
|
42
|
+
if (options.json) {
|
|
43
|
+
formatOutput(stats, options);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
console.log(chalk.cyan('\n📊 Database Statistics\n'));
|
|
47
|
+
// Core stats table
|
|
48
|
+
const coreTable = new Table({
|
|
49
|
+
head: [chalk.cyan('Metric'), chalk.cyan('Value')],
|
|
50
|
+
style: { head: [], border: [] }
|
|
51
|
+
});
|
|
52
|
+
coreTable.push(['Total Items', chalk.green(stats.nounCount + stats.verbCount + stats.metadataCount || 0)], ['Nouns', chalk.green(stats.nounCount || 0)], ['Verbs (Relationships)', chalk.green(stats.verbCount || 0)], ['Metadata Records', chalk.green(stats.metadataCount || 0)]);
|
|
53
|
+
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
|
+
// Memory usage
|
|
100
|
+
console.log(chalk.cyan('\n🧠 Memory Usage\n'));
|
|
101
|
+
const memTable = new Table({
|
|
102
|
+
head: [chalk.cyan('Type'), chalk.cyan('Size')],
|
|
103
|
+
style: { head: [], border: [] }
|
|
104
|
+
});
|
|
105
|
+
memTable.push(['Heap Used', formatBytes(memUsage.heapUsed)], ['Heap Total', formatBytes(memUsage.heapTotal)], ['RSS', formatBytes(memUsage.rss)], ['External', formatBytes(memUsage.external)]);
|
|
106
|
+
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
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
spinner.fail('Failed to gather statistics');
|
|
120
|
+
console.error(chalk.red(error.message));
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Clean and optimize database
|
|
126
|
+
*/
|
|
127
|
+
async clean(options) {
|
|
128
|
+
const spinner = ora('Cleaning database...').start();
|
|
129
|
+
try {
|
|
130
|
+
const brain = await getBrainy();
|
|
131
|
+
const tasks = [];
|
|
132
|
+
if (options.removeOrphans) {
|
|
133
|
+
spinner.text = 'Removing orphaned items...';
|
|
134
|
+
tasks.push('Removed orphaned items');
|
|
135
|
+
// Implementation would go here
|
|
136
|
+
await new Promise(resolve => setTimeout(resolve, 500)); // Simulate work
|
|
137
|
+
}
|
|
138
|
+
if (options.rebuildIndex) {
|
|
139
|
+
spinner.text = 'Rebuilding search index...';
|
|
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
|
|
149
|
+
}
|
|
150
|
+
spinner.succeed('Database cleaned');
|
|
151
|
+
if (!options.json) {
|
|
152
|
+
console.log(chalk.green('\n✓ Cleanup completed:'));
|
|
153
|
+
tasks.forEach(task => {
|
|
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')}`);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
formatOutput({ tasks, success: true }, options);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
spinner.fail('Cleanup failed');
|
|
168
|
+
console.error(chalk.red(error.message));
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Run performance benchmarks
|
|
174
|
+
*/
|
|
175
|
+
async benchmark(options) {
|
|
176
|
+
const operations = options.operations || 'all';
|
|
177
|
+
const iterations = parseInt(options.iterations || '100');
|
|
178
|
+
console.log(chalk.cyan(`\n🚀 Running Benchmarks (${iterations} iterations)\n`));
|
|
179
|
+
const results = {
|
|
180
|
+
operations: {},
|
|
181
|
+
summary: {}
|
|
182
|
+
};
|
|
183
|
+
try {
|
|
184
|
+
const brain = await getBrainy();
|
|
185
|
+
// Benchmark different operations
|
|
186
|
+
const benchmarks = [
|
|
187
|
+
{ name: 'add', enabled: operations === 'all' || operations.includes('add') },
|
|
188
|
+
{ name: 'search', enabled: operations === 'all' || operations.includes('search') },
|
|
189
|
+
{ name: 'similarity', enabled: operations === 'all' || operations.includes('similarity') },
|
|
190
|
+
{ name: 'cluster', enabled: operations === 'all' || operations.includes('cluster') }
|
|
191
|
+
];
|
|
192
|
+
for (const bench of benchmarks) {
|
|
193
|
+
if (!bench.enabled)
|
|
194
|
+
continue;
|
|
195
|
+
const spinner = ora(`Benchmarking ${bench.name}...`).start();
|
|
196
|
+
const times = [];
|
|
197
|
+
for (let i = 0; i < iterations; i++) {
|
|
198
|
+
const start = Date.now();
|
|
199
|
+
switch (bench.name) {
|
|
200
|
+
case 'add':
|
|
201
|
+
await brain.add(`Test item ${i}`, { benchmark: true });
|
|
202
|
+
break;
|
|
203
|
+
case 'search':
|
|
204
|
+
await brain.search('test', 10);
|
|
205
|
+
break;
|
|
206
|
+
case 'similarity':
|
|
207
|
+
const neural = brain.neural;
|
|
208
|
+
await neural.similar('test1', 'test2');
|
|
209
|
+
break;
|
|
210
|
+
case 'cluster':
|
|
211
|
+
const neuralApi = brain.neural;
|
|
212
|
+
await neuralApi.clusters();
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
times.push(Date.now() - start);
|
|
216
|
+
}
|
|
217
|
+
// Calculate statistics
|
|
218
|
+
const avg = times.reduce((a, b) => a + b, 0) / times.length;
|
|
219
|
+
const min = Math.min(...times);
|
|
220
|
+
const max = Math.max(...times);
|
|
221
|
+
const median = times.sort((a, b) => a - b)[Math.floor(times.length / 2)];
|
|
222
|
+
results.operations[bench.name] = {
|
|
223
|
+
avg: avg.toFixed(2),
|
|
224
|
+
min,
|
|
225
|
+
max,
|
|
226
|
+
median,
|
|
227
|
+
ops: (1000 / avg).toFixed(2)
|
|
228
|
+
};
|
|
229
|
+
spinner.succeed(`${bench.name}: ${avg.toFixed(2)}ms avg (${(1000 / avg).toFixed(2)} ops/sec)`);
|
|
230
|
+
}
|
|
231
|
+
// Calculate summary
|
|
232
|
+
const totalOps = Object.values(results.operations).reduce((sum, op) => sum + parseFloat(op.ops), 0);
|
|
233
|
+
results.summary = {
|
|
234
|
+
totalOperations: Object.keys(results.operations).length,
|
|
235
|
+
averageOpsPerSec: (totalOps / Object.keys(results.operations).length).toFixed(2)
|
|
236
|
+
};
|
|
237
|
+
if (!options.json) {
|
|
238
|
+
// Display results table
|
|
239
|
+
console.log(chalk.cyan('\n📊 Benchmark Results\n'));
|
|
240
|
+
const table = new Table({
|
|
241
|
+
head: [
|
|
242
|
+
chalk.cyan('Operation'),
|
|
243
|
+
chalk.cyan('Avg (ms)'),
|
|
244
|
+
chalk.cyan('Min (ms)'),
|
|
245
|
+
chalk.cyan('Max (ms)'),
|
|
246
|
+
chalk.cyan('Median (ms)'),
|
|
247
|
+
chalk.cyan('Ops/sec')
|
|
248
|
+
],
|
|
249
|
+
style: { head: [], border: [] }
|
|
250
|
+
});
|
|
251
|
+
Object.entries(results.operations).forEach(([op, stats]) => {
|
|
252
|
+
table.push([
|
|
253
|
+
op,
|
|
254
|
+
stats.avg,
|
|
255
|
+
stats.min,
|
|
256
|
+
stats.max,
|
|
257
|
+
stats.median,
|
|
258
|
+
chalk.green(stats.ops)
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
console.log(table.toString());
|
|
262
|
+
console.log(chalk.cyan('\n📈 Summary'));
|
|
263
|
+
console.log(` Operations tested: ${results.summary.totalOperations}`);
|
|
264
|
+
console.log(` Average throughput: ${chalk.green(results.summary.averageOpsPerSec)} ops/sec`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
formatOutput(results, options);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
console.error(chalk.red('Benchmark failed:'), error.message);
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
//# sourceMappingURL=utility.js.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Brainy CLI - Enterprise Neural Intelligence System
|
|
4
|
+
*
|
|
5
|
+
* Full TypeScript implementation with type safety and shared code
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
import chalk from 'chalk';
|
|
9
|
+
import { neuralCommands } from './commands/neural.js';
|
|
10
|
+
import { coreCommands } from './commands/core.js';
|
|
11
|
+
import { utilityCommands } from './commands/utility.js';
|
|
12
|
+
import { version } from '../package.json';
|
|
13
|
+
// CLI Configuration
|
|
14
|
+
const program = new Command();
|
|
15
|
+
program
|
|
16
|
+
.name('brainy')
|
|
17
|
+
.description('🧠 Enterprise Neural Intelligence Database')
|
|
18
|
+
.version(version)
|
|
19
|
+
.option('-v, --verbose', 'Verbose output')
|
|
20
|
+
.option('--json', 'JSON output format')
|
|
21
|
+
.option('--pretty', 'Pretty JSON output')
|
|
22
|
+
.option('--no-color', 'Disable colored output');
|
|
23
|
+
// ===== Core Commands =====
|
|
24
|
+
program
|
|
25
|
+
.command('add <text>')
|
|
26
|
+
.description('Add text or JSON to the neural database')
|
|
27
|
+
.option('-i, --id <id>', 'Specify custom ID')
|
|
28
|
+
.option('-m, --metadata <json>', 'Add metadata')
|
|
29
|
+
.option('-t, --type <type>', 'Specify noun type')
|
|
30
|
+
.action(coreCommands.add);
|
|
31
|
+
program
|
|
32
|
+
.command('search <query>')
|
|
33
|
+
.description('Search the neural database')
|
|
34
|
+
.option('-k, --limit <number>', 'Number of results', '10')
|
|
35
|
+
.option('-t, --threshold <number>', 'Similarity threshold')
|
|
36
|
+
.option('--metadata <json>', 'Filter by metadata')
|
|
37
|
+
.action(coreCommands.search);
|
|
38
|
+
program
|
|
39
|
+
.command('get <id>')
|
|
40
|
+
.description('Get item by ID')
|
|
41
|
+
.option('--with-connections', 'Include connections')
|
|
42
|
+
.action(coreCommands.get);
|
|
43
|
+
program
|
|
44
|
+
.command('relate <source> <verb> <target>')
|
|
45
|
+
.description('Create a relationship between items')
|
|
46
|
+
.option('-w, --weight <number>', 'Relationship weight')
|
|
47
|
+
.option('-m, --metadata <json>', 'Relationship metadata')
|
|
48
|
+
.action(coreCommands.relate);
|
|
49
|
+
program
|
|
50
|
+
.command('import <file>')
|
|
51
|
+
.description('Import data from file')
|
|
52
|
+
.option('-f, --format <format>', 'Input format (json|csv|jsonl)', 'json')
|
|
53
|
+
.option('--batch-size <number>', 'Batch size for import', '100')
|
|
54
|
+
.action(coreCommands.import);
|
|
55
|
+
program
|
|
56
|
+
.command('export [file]')
|
|
57
|
+
.description('Export database')
|
|
58
|
+
.option('-f, --format <format>', 'Output format (json|csv|jsonl)', 'json')
|
|
59
|
+
.action(coreCommands.export);
|
|
60
|
+
// ===== Neural Commands =====
|
|
61
|
+
program
|
|
62
|
+
.command('similar <a> <b>')
|
|
63
|
+
.alias('sim')
|
|
64
|
+
.description('Calculate similarity between two items')
|
|
65
|
+
.option('--explain', 'Show detailed explanation')
|
|
66
|
+
.option('--breakdown', 'Show similarity breakdown')
|
|
67
|
+
.action(neuralCommands.similar);
|
|
68
|
+
program
|
|
69
|
+
.command('cluster')
|
|
70
|
+
.alias('clusters')
|
|
71
|
+
.description('Find semantic clusters in the data')
|
|
72
|
+
.option('--algorithm <type>', 'Clustering algorithm (hierarchical|kmeans|dbscan)', 'hierarchical')
|
|
73
|
+
.option('--threshold <number>', 'Similarity threshold', '0.7')
|
|
74
|
+
.option('--min-size <number>', 'Minimum cluster size', '2')
|
|
75
|
+
.option('--max-clusters <number>', 'Maximum number of clusters')
|
|
76
|
+
.option('--near <query>', 'Find clusters near a query')
|
|
77
|
+
.option('--show', 'Show visual representation')
|
|
78
|
+
.action(neuralCommands.cluster);
|
|
79
|
+
program
|
|
80
|
+
.command('related <id>')
|
|
81
|
+
.alias('neighbors')
|
|
82
|
+
.description('Find semantically related items')
|
|
83
|
+
.option('-l, --limit <number>', 'Number of results', '10')
|
|
84
|
+
.option('-r, --radius <number>', 'Semantic radius', '0.3')
|
|
85
|
+
.option('--with-scores', 'Include similarity scores')
|
|
86
|
+
.option('--with-edges', 'Include connections')
|
|
87
|
+
.action(neuralCommands.related);
|
|
88
|
+
program
|
|
89
|
+
.command('hierarchy <id>')
|
|
90
|
+
.alias('tree')
|
|
91
|
+
.description('Show semantic hierarchy for an item')
|
|
92
|
+
.option('-d, --depth <number>', 'Hierarchy depth', '3')
|
|
93
|
+
.option('--parents-only', 'Show only parent hierarchy')
|
|
94
|
+
.option('--children-only', 'Show only child hierarchy')
|
|
95
|
+
.action(neuralCommands.hierarchy);
|
|
96
|
+
program
|
|
97
|
+
.command('path <from> <to>')
|
|
98
|
+
.description('Find semantic path between items')
|
|
99
|
+
.option('--steps', 'Show step-by-step path')
|
|
100
|
+
.option('--max-hops <number>', 'Maximum path length', '5')
|
|
101
|
+
.action(neuralCommands.path);
|
|
102
|
+
program
|
|
103
|
+
.command('outliers')
|
|
104
|
+
.alias('anomalies')
|
|
105
|
+
.description('Detect semantic outliers')
|
|
106
|
+
.option('-t, --threshold <number>', 'Outlier threshold', '0.3')
|
|
107
|
+
.option('--explain', 'Explain why items are outliers')
|
|
108
|
+
.action(neuralCommands.outliers);
|
|
109
|
+
program
|
|
110
|
+
.command('visualize')
|
|
111
|
+
.alias('viz')
|
|
112
|
+
.description('Generate visualization data')
|
|
113
|
+
.option('-f, --format <format>', 'Output format (json|d3|graphml)', 'json')
|
|
114
|
+
.option('--max-nodes <number>', 'Maximum nodes', '500')
|
|
115
|
+
.option('--dimensions <number>', '2D or 3D', '2')
|
|
116
|
+
.option('-o, --output <file>', 'Output file')
|
|
117
|
+
.action(neuralCommands.visualize);
|
|
118
|
+
// ===== Utility Commands =====
|
|
119
|
+
program
|
|
120
|
+
.command('stats')
|
|
121
|
+
.alias('statistics')
|
|
122
|
+
.description('Show database statistics')
|
|
123
|
+
.option('--by-service', 'Group by service')
|
|
124
|
+
.option('--detailed', 'Show detailed stats')
|
|
125
|
+
.action(utilityCommands.stats);
|
|
126
|
+
program
|
|
127
|
+
.command('clean')
|
|
128
|
+
.description('Clean and optimize database')
|
|
129
|
+
.option('--remove-orphans', 'Remove orphaned items')
|
|
130
|
+
.option('--rebuild-index', 'Rebuild search index')
|
|
131
|
+
.action(utilityCommands.clean);
|
|
132
|
+
program
|
|
133
|
+
.command('benchmark')
|
|
134
|
+
.alias('bench')
|
|
135
|
+
.description('Run performance benchmarks')
|
|
136
|
+
.option('--operations <ops>', 'Operations to benchmark', 'all')
|
|
137
|
+
.option('--iterations <n>', 'Number of iterations', '100')
|
|
138
|
+
.action(utilityCommands.benchmark);
|
|
139
|
+
// ===== Interactive Mode =====
|
|
140
|
+
program
|
|
141
|
+
.command('interactive')
|
|
142
|
+
.alias('i')
|
|
143
|
+
.description('Start interactive REPL mode')
|
|
144
|
+
.action(async () => {
|
|
145
|
+
const { startInteractiveMode } = await import('./interactive.js');
|
|
146
|
+
await startInteractiveMode();
|
|
147
|
+
});
|
|
148
|
+
// ===== Error Handling =====
|
|
149
|
+
program.exitOverride();
|
|
150
|
+
try {
|
|
151
|
+
await program.parseAsync(process.argv);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error.code === 'commander.helpDisplayed') {
|
|
155
|
+
process.exit(0);
|
|
156
|
+
}
|
|
157
|
+
console.error(chalk.red('Error:'), error.message);
|
|
158
|
+
if (program.opts().verbose) {
|
|
159
|
+
console.error(chalk.gray(error.stack));
|
|
160
|
+
}
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
// Handle no command
|
|
164
|
+
if (!process.argv.slice(2).length) {
|
|
165
|
+
program.outputHelp();
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Professional Interactive CLI System
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent, delightful interactive prompts for all commands
|
|
5
|
+
* with smart defaults, validation, and helpful examples
|
|
6
|
+
*/
|
|
7
|
+
import { BrainyData } from '../brainyData.js';
|
|
8
|
+
export declare const colors: {
|
|
9
|
+
primary: import("chalk").ChalkInstance;
|
|
10
|
+
success: import("chalk").ChalkInstance;
|
|
11
|
+
info: import("chalk").ChalkInstance;
|
|
12
|
+
warning: import("chalk").ChalkInstance;
|
|
13
|
+
error: import("chalk").ChalkInstance;
|
|
14
|
+
brain: import("chalk").ChalkInstance;
|
|
15
|
+
cream: import("chalk").ChalkInstance;
|
|
16
|
+
dim: import("chalk").ChalkInstance;
|
|
17
|
+
bold: import("chalk").ChalkInstance;
|
|
18
|
+
cyan: import("chalk").ChalkInstance;
|
|
19
|
+
green: import("chalk").ChalkInstance;
|
|
20
|
+
yellow: import("chalk").ChalkInstance;
|
|
21
|
+
red: import("chalk").ChalkInstance;
|
|
22
|
+
};
|
|
23
|
+
export declare const icons: {
|
|
24
|
+
brain: string;
|
|
25
|
+
search: string;
|
|
26
|
+
add: string;
|
|
27
|
+
delete: string;
|
|
28
|
+
update: string;
|
|
29
|
+
import: string;
|
|
30
|
+
export: string;
|
|
31
|
+
connect: string;
|
|
32
|
+
question: string;
|
|
33
|
+
success: string;
|
|
34
|
+
error: string;
|
|
35
|
+
warning: string;
|
|
36
|
+
info: string;
|
|
37
|
+
sparkle: string;
|
|
38
|
+
rocket: string;
|
|
39
|
+
thinking: string;
|
|
40
|
+
chat: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Professional prompt wrapper with consistent styling
|
|
44
|
+
*/
|
|
45
|
+
export declare function prompt(config: any): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Interactive prompt for search query with smart features
|
|
48
|
+
*/
|
|
49
|
+
export declare function promptSearchQuery(previousSearches?: string[]): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Interactive prompt for item ID with fuzzy search
|
|
52
|
+
*/
|
|
53
|
+
export declare function promptItemId(action: string, brain?: BrainyData, allowMultiple?: boolean): Promise<string | string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Confirm destructive action with preview
|
|
56
|
+
*/
|
|
57
|
+
export declare function confirmDestructiveAction(action: string, items: any[], showPreview?: boolean): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Interactive data input with multiline support
|
|
60
|
+
*/
|
|
61
|
+
export declare function promptDataInput(action?: string, currentValue?: string): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Interactive metadata input with JSON validation
|
|
64
|
+
*/
|
|
65
|
+
export declare function promptMetadata(currentMetadata?: any, suggestions?: string[]): Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Interactive format selector
|
|
68
|
+
*/
|
|
69
|
+
export declare function promptFormat(availableFormats: string[], defaultFormat: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Interactive file/URL input with validation
|
|
72
|
+
*/
|
|
73
|
+
export declare function promptFileOrUrl(action?: string): Promise<string>;
|
|
74
|
+
/**
|
|
75
|
+
* Interactive relationship builder
|
|
76
|
+
*/
|
|
77
|
+
export declare function promptRelationship(brain?: BrainyData): Promise<{
|
|
78
|
+
source: string;
|
|
79
|
+
verb: string;
|
|
80
|
+
target: string;
|
|
81
|
+
metadata?: any;
|
|
82
|
+
}>;
|
|
83
|
+
/**
|
|
84
|
+
* Smart command suggestions when user types wrong command
|
|
85
|
+
*/
|
|
86
|
+
export declare function suggestCommand(input: string, availableCommands: string[]): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Beautiful error display with helpful context
|
|
89
|
+
*/
|
|
90
|
+
export declare function showError(error: Error, context?: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Progress indicator for long operations
|
|
93
|
+
*/
|
|
94
|
+
export declare class ProgressTracker {
|
|
95
|
+
private spinner;
|
|
96
|
+
private startTime;
|
|
97
|
+
constructor(message: string);
|
|
98
|
+
update(message: string, count?: number, total?: number): void;
|
|
99
|
+
succeed(message?: string): void;
|
|
100
|
+
fail(message?: string): void;
|
|
101
|
+
stop(): void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Welcome message for interactive mode
|
|
105
|
+
*/
|
|
106
|
+
export declare function showWelcome(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Interactive command selector for beginners
|
|
109
|
+
*/
|
|
110
|
+
export declare function promptCommand(): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Export all interactive components
|
|
113
|
+
*/
|
|
114
|
+
declare const _default: {
|
|
115
|
+
colors: {
|
|
116
|
+
primary: import("chalk").ChalkInstance;
|
|
117
|
+
success: import("chalk").ChalkInstance;
|
|
118
|
+
info: import("chalk").ChalkInstance;
|
|
119
|
+
warning: import("chalk").ChalkInstance;
|
|
120
|
+
error: import("chalk").ChalkInstance;
|
|
121
|
+
brain: import("chalk").ChalkInstance;
|
|
122
|
+
cream: import("chalk").ChalkInstance;
|
|
123
|
+
dim: import("chalk").ChalkInstance;
|
|
124
|
+
bold: import("chalk").ChalkInstance;
|
|
125
|
+
cyan: import("chalk").ChalkInstance;
|
|
126
|
+
green: import("chalk").ChalkInstance;
|
|
127
|
+
yellow: import("chalk").ChalkInstance;
|
|
128
|
+
red: import("chalk").ChalkInstance;
|
|
129
|
+
};
|
|
130
|
+
icons: {
|
|
131
|
+
brain: string;
|
|
132
|
+
search: string;
|
|
133
|
+
add: string;
|
|
134
|
+
delete: string;
|
|
135
|
+
update: string;
|
|
136
|
+
import: string;
|
|
137
|
+
export: string;
|
|
138
|
+
connect: string;
|
|
139
|
+
question: string;
|
|
140
|
+
success: string;
|
|
141
|
+
error: string;
|
|
142
|
+
warning: string;
|
|
143
|
+
info: string;
|
|
144
|
+
sparkle: string;
|
|
145
|
+
rocket: string;
|
|
146
|
+
thinking: string;
|
|
147
|
+
chat: string;
|
|
148
|
+
};
|
|
149
|
+
prompt: typeof prompt;
|
|
150
|
+
promptSearchQuery: typeof promptSearchQuery;
|
|
151
|
+
promptItemId: typeof promptItemId;
|
|
152
|
+
confirmDestructiveAction: typeof confirmDestructiveAction;
|
|
153
|
+
promptDataInput: typeof promptDataInput;
|
|
154
|
+
promptMetadata: typeof promptMetadata;
|
|
155
|
+
promptFormat: typeof promptFormat;
|
|
156
|
+
promptFileOrUrl: typeof promptFileOrUrl;
|
|
157
|
+
promptRelationship: typeof promptRelationship;
|
|
158
|
+
suggestCommand: typeof suggestCommand;
|
|
159
|
+
showError: typeof showError;
|
|
160
|
+
ProgressTracker: typeof ProgressTracker;
|
|
161
|
+
showWelcome: typeof showWelcome;
|
|
162
|
+
promptCommand: typeof promptCommand;
|
|
163
|
+
};
|
|
164
|
+
export default _default;
|