@soulcraft/brainy 0.61.1 → 0.61.3

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.
@@ -0,0 +1,209 @@
1
+ /**
2
+ * CLI Wrapper for Cortex
3
+ *
4
+ * Provides CLI-specific functionality that wraps the core Cortex orchestrator
5
+ * Following our philosophy: "Simple for beginners, powerful for experts"
6
+ */
7
+ import { BrainyData } from '../brainyData.js';
8
+ import { Cortex } from '../cortex.js';
9
+ import { NeuralImport } from './neuralImport.js';
10
+ // @ts-ignore
11
+ import chalk from 'chalk';
12
+ // @ts-ignore
13
+ import ora from 'ora';
14
+ // @ts-ignore
15
+ import prompts from 'prompts';
16
+ export class CortexCLI {
17
+ constructor() {
18
+ this.brainy = new BrainyData();
19
+ this.cortex = new Cortex();
20
+ }
21
+ /**
22
+ * Initialize the brain and cortex
23
+ */
24
+ async init(options = {}) {
25
+ const spinner = ora('Initializing brain...').start();
26
+ try {
27
+ // Initialize BrainyData
28
+ await this.brainy.init();
29
+ // Set up Neural Import as default augmentation
30
+ this.neuralImport = new NeuralImport(this.brainy);
31
+ this.cortex.register(this.neuralImport);
32
+ spinner.succeed('Brain initialized!');
33
+ return true;
34
+ }
35
+ catch (error) {
36
+ spinner.fail('Initialization failed');
37
+ throw error;
38
+ }
39
+ }
40
+ /**
41
+ * Add data - with Neural Import processing by default
42
+ */
43
+ async add(data, metadata) {
44
+ // If no data provided, go interactive
45
+ if (!data) {
46
+ const input = await prompts([
47
+ {
48
+ type: 'text',
49
+ name: 'data',
50
+ message: 'What would you like to add?',
51
+ validate: (value) => value.length > 0 || 'Please enter something'
52
+ }
53
+ ]);
54
+ if (!input.data)
55
+ return;
56
+ data = input.data;
57
+ }
58
+ // Check if it's a file path
59
+ const fs = await import('fs');
60
+ if (fs.existsSync(data)) {
61
+ // Use Neural Import for files
62
+ if (this.neuralImport) {
63
+ console.log(chalk.cyan('🧠 Using Neural Import to understand your data...'));
64
+ const result = await this.neuralImport.neuralImport(data, {
65
+ autoApply: true,
66
+ previewOnly: false
67
+ });
68
+ console.log(chalk.green(`āœ… Imported ${result.detectedEntities.length} entities`));
69
+ console.log(chalk.gray(` ${result.detectedRelationships.length} relationships detected`));
70
+ console.log(chalk.gray(` Confidence: ${(result.confidence * 100).toFixed(1)}%`));
71
+ if (result.insights.length > 0) {
72
+ console.log(chalk.cyan('\nšŸ’” Insights:'));
73
+ result.insights.forEach(insight => {
74
+ console.log(chalk.gray(` • ${insight.description}`));
75
+ });
76
+ }
77
+ }
78
+ }
79
+ else {
80
+ // Plain text - add directly
81
+ const id = await this.brainy.add(data, metadata);
82
+ console.log(chalk.green('āœ… Added!'));
83
+ console.log(chalk.gray(` ID: ${id}`));
84
+ }
85
+ }
86
+ /**
87
+ * Search with helpful display
88
+ */
89
+ async search(query, options = {}) {
90
+ // Interactive mode if no query
91
+ if (!query) {
92
+ const input = await prompts({
93
+ type: 'text',
94
+ name: 'query',
95
+ message: 'What are you looking for?',
96
+ validate: (value) => value.length > 0 || 'Please enter a search term'
97
+ });
98
+ if (!input.query)
99
+ return;
100
+ query = input.query;
101
+ }
102
+ const results = await this.brainy.search(query, options.limit || 5);
103
+ if (results.length === 0) {
104
+ console.log(chalk.yellow('No results found'));
105
+ console.log(chalk.gray('Try different keywords or add more data'));
106
+ }
107
+ else {
108
+ console.log(chalk.cyan(`\nFound ${results.length} results:\n`));
109
+ results.forEach((result, i) => {
110
+ const content = result.content || result.text || result.data;
111
+ console.log(chalk.white(`${i + 1}. ${content}`));
112
+ console.log(chalk.gray(` Score: ${(result.score * 100).toFixed(1)}%`));
113
+ if (result.metadata) {
114
+ const keys = Object.keys(result.metadata).slice(0, 3);
115
+ if (keys.length > 0) {
116
+ const preview = keys.map(k => `${k}: ${result.metadata[k]}`).join(', ');
117
+ console.log(chalk.gray(` ${preview}`));
118
+ }
119
+ }
120
+ console.log();
121
+ });
122
+ }
123
+ }
124
+ /**
125
+ * Show statistics
126
+ */
127
+ async stats(detailed = false) {
128
+ const stats = await this.brainy.getStats();
129
+ console.log(chalk.cyan('\n🧠 Brain Statistics\n'));
130
+ console.log(chalk.white('Capacity:'));
131
+ console.log(` Memories: ${stats.totalNouns || 0}`);
132
+ console.log(` Connections: ${stats.totalVerbs || 0}`);
133
+ if (detailed) {
134
+ console.log(chalk.white('\nBreakdown:'));
135
+ if (stats.nounTypes) {
136
+ console.log(' Entity Types:');
137
+ Object.entries(stats.nounTypes).forEach(([type, count]) => {
138
+ console.log(` ${type}: ${count}`);
139
+ });
140
+ }
141
+ if (stats.verbTypes) {
142
+ console.log(' Relationship Types:');
143
+ Object.entries(stats.verbTypes).forEach(([type, count]) => {
144
+ console.log(` ${type}: ${count}`);
145
+ });
146
+ }
147
+ }
148
+ console.log(chalk.white('\nAugmentations:'));
149
+ const augmentations = this.cortex.getAugmentationsByType('sense');
150
+ console.log(` Active: ${augmentations.length}`);
151
+ if (augmentations.length > 0) {
152
+ augmentations.forEach(aug => {
153
+ console.log(` • ${aug.name || 'unnamed'}`);
154
+ });
155
+ }
156
+ }
157
+ /**
158
+ * Interactive chat interface
159
+ */
160
+ async chat(initialMessage) {
161
+ console.log(chalk.cyan('\n🧠 Brain Chat'));
162
+ console.log(chalk.gray('I can help you explore your data. Type "exit" to quit.\n'));
163
+ // Note: Full chat would integrate with BrainyChat
164
+ // For now, we use search as a simple implementation
165
+ const readline = (await import('readline')).createInterface({
166
+ input: process.stdin,
167
+ output: process.stdout,
168
+ prompt: chalk.cyan('You: ')
169
+ });
170
+ if (initialMessage) {
171
+ console.log(chalk.cyan('You: ') + initialMessage);
172
+ const results = await this.brainy.search(initialMessage, 3);
173
+ if (results.length > 0) {
174
+ console.log(chalk.green('Brain: ') + 'Based on what I know:');
175
+ results.forEach(r => {
176
+ console.log(chalk.gray(` • ${r.content || r.text}`));
177
+ });
178
+ }
179
+ else {
180
+ console.log(chalk.green('Brain: ') + "I don't have information about that yet.");
181
+ }
182
+ console.log();
183
+ }
184
+ readline.prompt();
185
+ readline.on('line', async (line) => {
186
+ const input = line.trim();
187
+ if (input.toLowerCase() === 'exit') {
188
+ console.log(chalk.gray('\nGoodbye! šŸ‘‹'));
189
+ readline.close();
190
+ process.exit(0);
191
+ }
192
+ if (input) {
193
+ const results = await this.brainy.search(input, 3);
194
+ if (results.length > 0) {
195
+ console.log(chalk.green('Brain: ') + 'I found:');
196
+ results.forEach(r => {
197
+ console.log(chalk.gray(` • ${r.content || r.text}`));
198
+ });
199
+ }
200
+ else {
201
+ console.log(chalk.green('Brain: ') + "I don't know about that yet.");
202
+ }
203
+ console.log();
204
+ }
205
+ readline.prompt();
206
+ });
207
+ }
208
+ }
209
+ //# sourceMappingURL=cliWrapper.js.map
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Cortex - Beautiful CLI Command Center for Brainy
3
+ *
4
+ * Configuration, data management, search, and chat - all in one place!
5
+ */
6
+ export declare class Cortex {
7
+ private brainy?;
8
+ private chatInstance?;
9
+ private performanceMonitor?;
10
+ private healthCheck?;
11
+ private licensingSystem?;
12
+ private configPath;
13
+ private config;
14
+ private encryptionKey?;
15
+ private masterKeySource?;
16
+ private emojis;
17
+ private colors;
18
+ constructor();
19
+ /**
20
+ * Load configuration
21
+ */
22
+ private loadConfig;
23
+ /**
24
+ * Ensure Brainy is initialized
25
+ */
26
+ private ensureBrainy;
27
+ /**
28
+ * Master Key Management - Atomic Age Security Protocols
29
+ */
30
+ private initializeMasterKey;
31
+ /**
32
+ * Load master key from stored salt + passphrase
33
+ */
34
+ private loadPassphraseKey;
35
+ /**
36
+ * Reset master key - for key rotation
37
+ */
38
+ resetMasterKey(): Promise<void>;
39
+ /**
40
+ * Get all decrypted secrets (for key rotation)
41
+ */
42
+ private getAllSecrets;
43
+ /**
44
+ * Initialize Cortex with beautiful prompts
45
+ */
46
+ init(options?: InitOptions): Promise<void>;
47
+ /**
48
+ * Beautiful welcome message
49
+ */
50
+ private showWelcome;
51
+ /**
52
+ * Chat with your data - beautiful interactive mode
53
+ */
54
+ chat(question?: string): Promise<void>;
55
+ /**
56
+ * Add data with beautiful prompts
57
+ */
58
+ add(data?: string, metadata?: any): Promise<void>;
59
+ /**
60
+ * Search with beautiful results display and advanced options
61
+ */
62
+ search(query: string, options?: SearchOptions): Promise<void>;
63
+ /**
64
+ * Advanced search with interactive prompts
65
+ */
66
+ advancedSearch(): Promise<void>;
67
+ /**
68
+ * Add or update graph connections (verbs)
69
+ */
70
+ addVerb(subject: string, verb: string, object: string, metadata?: any): Promise<void>;
71
+ /**
72
+ * Interactive graph exploration
73
+ */
74
+ explore(startId?: string): Promise<void>;
75
+ /**
76
+ * Configuration management with encryption
77
+ */
78
+ configSet(key: string, value: string, options?: {
79
+ encrypt?: boolean;
80
+ }): Promise<void>;
81
+ /**
82
+ * Get configuration value
83
+ */
84
+ configGet(key: string): Promise<string | null>;
85
+ /**
86
+ * List all configuration
87
+ */
88
+ configList(): Promise<void>;
89
+ /**
90
+ * Storage migration with beautiful progress
91
+ */
92
+ migrate(options: MigrateOptions): Promise<void>;
93
+ /**
94
+ * Show comprehensive statistics and database info
95
+ */
96
+ stats(detailed?: boolean): Promise<void>;
97
+ /**
98
+ * List all searchable fields with statistics
99
+ */
100
+ listFields(): Promise<void>;
101
+ /**
102
+ * Setup LLM progressively with auto-download
103
+ */
104
+ setupLLM(provider?: string): Promise<void>;
105
+ private setupLocalLLM;
106
+ private setupClaudeLLM;
107
+ private setupOpenAILLM;
108
+ private setupOllamaLLM;
109
+ private setupClaudeDesktop;
110
+ /**
111
+ * Use the embedding model for other tasks
112
+ */
113
+ embed(text: string): Promise<void>;
114
+ /**
115
+ * Calculate similarity between two texts
116
+ */
117
+ similarity(text1: string, text2: string): Promise<void>;
118
+ private getSimilarityInterpretation;
119
+ /**
120
+ * Import .env file with automatic encryption of secrets
121
+ */
122
+ importEnv(filePath: string): Promise<void>;
123
+ /**
124
+ * Export configuration to .env file
125
+ */
126
+ exportEnv(filePath: string): Promise<void>;
127
+ /**
128
+ * Delete data by ID
129
+ */
130
+ delete(id: string): Promise<void>;
131
+ /**
132
+ * Update data by ID
133
+ */
134
+ update(id: string, data: string, metadata?: any): Promise<void>;
135
+ /**
136
+ * Helpers
137
+ */
138
+ private ensureInitialized;
139
+ /**
140
+ * Load master key from various sources
141
+ */
142
+ private loadMasterKey;
143
+ private isInitialized;
144
+ private initBrainy;
145
+ private saveConfig;
146
+ /**
147
+ * Configuration categories for enhanced secret management
148
+ */
149
+ static readonly CONFIG_CATEGORIES: {
150
+ readonly SECRET: "secret";
151
+ readonly SENSITIVE: "sensitive";
152
+ readonly CONFIG: "config";
153
+ readonly PUBLIC: "public";
154
+ };
155
+ private customSecretPatterns;
156
+ /**
157
+ * Enhanced secret detection with custom patterns and categories
158
+ */
159
+ private isSecret;
160
+ /**
161
+ * Add custom secret detection patterns
162
+ */
163
+ addSecretPattern(pattern: string): Promise<void>;
164
+ /**
165
+ * Remove custom secret detection pattern
166
+ */
167
+ removeSecretPattern(pattern: string): Promise<void>;
168
+ /**
169
+ * List all secret detection patterns
170
+ */
171
+ listSecretPatterns(): Promise<void>;
172
+ /**
173
+ * Save custom patterns to disk
174
+ */
175
+ private saveCustomPatterns;
176
+ /**
177
+ * Load custom patterns from disk
178
+ */
179
+ private loadCustomPatterns;
180
+ /**
181
+ * Determine config category for enhanced management
182
+ */
183
+ private getConfigCategory;
184
+ /**
185
+ * Cortex Augmentation System - AI-Powered Data Understanding
186
+ */
187
+ neuralImport(filePath: string, options?: any): Promise<void>;
188
+ neuralAnalyze(filePath: string): Promise<void>;
189
+ neuralValidate(filePath: string): Promise<void>;
190
+ neuralTypes(): Promise<void>;
191
+ /**
192
+ * Augmentation Pipeline Management - Control the Neural Enhancement System
193
+ */
194
+ listAugmentations(): Promise<void>;
195
+ addAugmentation(type: string, position?: number, config?: any): Promise<void>;
196
+ removeAugmentation(type: string): Promise<void>;
197
+ configureAugmentation(type: string, config: any): Promise<void>;
198
+ resetPipeline(): Promise<void>;
199
+ executePipelineStep(step: string, data: any): Promise<void>;
200
+ /**
201
+ * Backup & Restore System - Atomic Data Preservation
202
+ */
203
+ backup(options?: any): Promise<void>;
204
+ restore(file: string): Promise<void>;
205
+ listBackups(directory?: string): Promise<void>;
206
+ /**
207
+ * Show augmentation status and management
208
+ */
209
+ augmentations(options?: any): Promise<void>;
210
+ /**
211
+ * Performance Monitoring & Health Check System - Atomic Age Intelligence Observatory
212
+ */
213
+ monitor(options?: any): Promise<void>;
214
+ health(options?: any): Promise<void>;
215
+ performance(options?: any): Promise<void>;
216
+ /**
217
+ * Premium Features - Redirect to Brain Cloud
218
+ */
219
+ licenseCatalog(): Promise<void>;
220
+ licenseStatus(licenseId?: string): Promise<void>;
221
+ licenseTrial(featureId: string, customerName?: string, customerEmail?: string): Promise<void>;
222
+ licenseValidate(featureId: string): Promise<boolean>;
223
+ /**
224
+ * Check if a premium feature is available
225
+ */
226
+ requirePremiumFeature(featureId: string, silent?: boolean): Promise<boolean>;
227
+ /**
228
+ * Brain Jar AI Coordination Methods
229
+ */
230
+ brainJarInstall(mode: string): Promise<void>;
231
+ brainJarStart(options: any): Promise<void>;
232
+ brainJarDashboard(shouldOpen?: boolean): Promise<void>;
233
+ brainJarStatus(): Promise<void>;
234
+ brainJarStop(): Promise<void>;
235
+ brainJarAgents(): Promise<void>;
236
+ brainJarMessage(text: string): Promise<void>;
237
+ brainJarSearch(query: string, limit: number): Promise<void>;
238
+ /**
239
+ * Brain Cloud Super Command - One command to rule them all
240
+ */
241
+ setupBrainCloud(options: any): Promise<void>;
242
+ /**
243
+ * Helper method to determine data type from file path
244
+ */
245
+ private getDataTypeFromPath;
246
+ }
247
+ interface InitOptions {
248
+ storage?: string;
249
+ encryption?: boolean;
250
+ chat?: boolean;
251
+ llm?: string;
252
+ }
253
+ interface MigrateOptions {
254
+ to: string;
255
+ bucket?: string;
256
+ strategy?: 'immediate' | 'gradual';
257
+ }
258
+ interface SearchOptions {
259
+ limit?: number;
260
+ filter?: any;
261
+ verbs?: string[];
262
+ depth?: number;
263
+ }
264
+ export {};