@soulcraft/brainy 0.61.0 → 0.61.2

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.
@@ -1,9 +1,13 @@
1
1
  /**
2
- * Augmentation Event Pipeline
2
+ * Cortex - The Brain's Orchestration System
3
3
  *
4
- * This module provides a pipeline for managing and executing multiple augmentations
5
- * of each type. It allows registering multiple augmentations and executing them
6
- * in sequence or in parallel.
4
+ * 🧠⚛️ The cerebral cortex that coordinates all augmentations
5
+ *
6
+ * This module provides the central coordination system for managing and executing
7
+ * augmentations across all categories. Like the brain's cortex, it orchestrates
8
+ * different capabilities (augmentations) in sequence or parallel.
9
+ *
10
+ * @deprecated AugmentationPipeline - Use Cortex instead
7
11
  */
8
12
  import { BrainyAugmentations, IAugmentation, IWebSocketSupport, AugmentationResponse, AugmentationType } from './types/augmentations.js';
9
13
  /**
@@ -27,26 +31,27 @@ export interface PipelineOptions {
27
31
  disableThreading?: boolean;
28
32
  }
29
33
  /**
30
- * AugmentationPipeline class
34
+ * Cortex class - The Brain's Orchestration Center
31
35
  *
32
- * Manages multiple augmentations of each type and provides methods to execute them.
36
+ * Manages all augmentations like the cerebral cortex coordinates different brain regions.
37
+ * This is the central pipeline that orchestrates all augmentation execution.
33
38
  */
34
- export declare class AugmentationPipeline {
39
+ export declare class Cortex {
35
40
  private registry;
36
41
  /**
37
- * Register an augmentation with the pipeline
42
+ * Register an augmentation with the cortex
38
43
  *
39
44
  * @param augmentation The augmentation to register
40
- * @returns The pipeline instance for chaining
45
+ * @returns The cortex instance for chaining
41
46
  */
42
- register<T extends IAugmentation>(augmentation: T): AugmentationPipeline;
47
+ register<T extends IAugmentation>(augmentation: T): Cortex;
43
48
  /**
44
49
  * Unregister an augmentation from the pipeline
45
50
  *
46
51
  * @param augmentationName The name of the augmentation to unregister
47
52
  * @returns The pipeline instance for chaining
48
53
  */
49
- unregister(augmentationName: string): AugmentationPipeline;
54
+ unregister(augmentationName: string): Cortex;
50
55
  /**
51
56
  * Initialize all registered augmentations
52
57
  *
@@ -201,4 +206,6 @@ export declare class AugmentationPipeline {
201
206
  */
202
207
  private executeTypedPipeline;
203
208
  }
204
- export declare const augmentationPipeline: AugmentationPipeline;
209
+ export declare const cortex: Cortex;
210
+ export declare const AugmentationPipeline: typeof Cortex;
211
+ export declare const augmentationPipeline: Cortex;
@@ -1,9 +1,13 @@
1
1
  /**
2
- * Augmentation Event Pipeline
2
+ * Cortex - The Brain's Orchestration System
3
3
  *
4
- * This module provides a pipeline for managing and executing multiple augmentations
5
- * of each type. It allows registering multiple augmentations and executing them
6
- * in sequence or in parallel.
4
+ * 🧠⚛️ The cerebral cortex that coordinates all augmentations
5
+ *
6
+ * This module provides the central coordination system for managing and executing
7
+ * augmentations across all categories. Like the brain's cortex, it orchestrates
8
+ * different capabilities (augmentations) in sequence or parallel.
9
+ *
10
+ * @deprecated AugmentationPipeline - Use Cortex instead
7
11
  */
8
12
  import { AugmentationType } from './types/augmentations.js';
9
13
  import { isThreadingAvailable } from './utils/environment.js';
@@ -30,11 +34,12 @@ const DEFAULT_PIPELINE_OPTIONS = {
30
34
  disableThreading: false
31
35
  };
32
36
  /**
33
- * AugmentationPipeline class
37
+ * Cortex class - The Brain's Orchestration Center
34
38
  *
35
- * Manages multiple augmentations of each type and provides methods to execute them.
39
+ * Manages all augmentations like the cerebral cortex coordinates different brain regions.
40
+ * This is the central pipeline that orchestrates all augmentation execution.
36
41
  */
37
- export class AugmentationPipeline {
42
+ export class Cortex {
38
43
  constructor() {
39
44
  this.registry = {
40
45
  sense: [],
@@ -48,10 +53,10 @@ export class AugmentationPipeline {
48
53
  };
49
54
  }
50
55
  /**
51
- * Register an augmentation with the pipeline
56
+ * Register an augmentation with the cortex
52
57
  *
53
58
  * @param augmentation The augmentation to register
54
- * @returns The pipeline instance for chaining
59
+ * @returns The cortex instance for chaining
55
60
  */
56
61
  register(augmentation) {
57
62
  let registered = false;
@@ -467,6 +472,9 @@ export class AugmentationPipeline {
467
472
  }
468
473
  }
469
474
  }
470
- // Create and export a default instance of the pipeline
471
- export const augmentationPipeline = new AugmentationPipeline();
475
+ // Create and export a default instance of the cortex
476
+ export const cortex = new Cortex();
477
+ // Backward compatibility exports
478
+ export const AugmentationPipeline = Cortex;
479
+ export const augmentationPipeline = cortex;
472
480
  //# sourceMappingURL=augmentationPipeline.js.map
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Brain Cloud Catalog Integration for CLI
3
+ *
4
+ * Fetches and displays augmentation catalog
5
+ * Falls back to local cache if API is unavailable
6
+ */
7
+ interface Augmentation {
8
+ id: string;
9
+ name: string;
10
+ description: string;
11
+ category: string;
12
+ status: 'available' | 'coming_soon' | 'deprecated';
13
+ popular?: boolean;
14
+ eta?: string;
15
+ }
16
+ interface Category {
17
+ id: string;
18
+ name: string;
19
+ icon: string;
20
+ description: string;
21
+ }
22
+ interface Catalog {
23
+ version: string;
24
+ categories: Category[];
25
+ augmentations: Augmentation[];
26
+ }
27
+ /**
28
+ * Fetch catalog from API with caching
29
+ */
30
+ export declare function fetchCatalog(): Promise<Catalog | null>;
31
+ /**
32
+ * Display catalog in CLI
33
+ */
34
+ export declare function showCatalog(options: {
35
+ category?: string;
36
+ search?: string;
37
+ detailed?: boolean;
38
+ }): Promise<void>;
39
+ /**
40
+ * Show detailed info about an augmentation
41
+ */
42
+ export declare function showAugmentationInfo(id: string): Promise<void>;
43
+ /**
44
+ * Show user's available augmentations
45
+ */
46
+ export declare function showAvailable(licenseKey?: string): Promise<void>;
47
+ export {};
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Brain Cloud Catalog Integration for CLI
3
+ *
4
+ * Fetches and displays augmentation catalog
5
+ * Falls back to local cache if API is unavailable
6
+ */
7
+ import chalk from 'chalk';
8
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
9
+ import { join } from 'path';
10
+ import { homedir } from 'os';
11
+ const CATALOG_API = process.env.BRAIN_CLOUD_CATALOG_URL || 'https://catalog.brain-cloud.soulcraft.com';
12
+ const CACHE_PATH = join(homedir(), '.brainy', 'catalog-cache.json');
13
+ const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours
14
+ /**
15
+ * Fetch catalog from API with caching
16
+ */
17
+ export async function fetchCatalog() {
18
+ try {
19
+ // Check cache first
20
+ const cached = loadCache();
21
+ if (cached)
22
+ return cached;
23
+ // Fetch from API
24
+ const response = await fetch(`${CATALOG_API}/api/catalog/cli`);
25
+ if (!response.ok)
26
+ throw new Error('API unavailable');
27
+ const catalog = await response.json();
28
+ // Save to cache
29
+ saveCache(catalog);
30
+ return catalog;
31
+ }
32
+ catch (error) {
33
+ // Try loading from cache even if expired
34
+ const cached = loadCache(true);
35
+ if (cached) {
36
+ console.log(chalk.yellow('📡 Using cached catalog (API unavailable)'));
37
+ return cached;
38
+ }
39
+ // Fall back to hardcoded catalog
40
+ return getDefaultCatalog();
41
+ }
42
+ }
43
+ /**
44
+ * Display catalog in CLI
45
+ */
46
+ export async function showCatalog(options) {
47
+ const catalog = await fetchCatalog();
48
+ if (!catalog) {
49
+ console.log(chalk.red('❌ Could not load augmentation catalog'));
50
+ return;
51
+ }
52
+ console.log(chalk.cyan.bold('🧠 Brain Cloud Augmentation Catalog'));
53
+ console.log(chalk.gray(`Version ${catalog.version}`));
54
+ console.log('');
55
+ // Filter augmentations
56
+ let augmentations = catalog.augmentations;
57
+ if (options.category) {
58
+ augmentations = augmentations.filter(a => a.category === options.category);
59
+ }
60
+ if (options.search) {
61
+ const query = options.search.toLowerCase();
62
+ augmentations = augmentations.filter(a => a.name.toLowerCase().includes(query) ||
63
+ a.description.toLowerCase().includes(query));
64
+ }
65
+ // Group by category
66
+ const grouped = groupByCategory(augmentations, catalog.categories);
67
+ // Display
68
+ for (const [category, augs] of Object.entries(grouped)) {
69
+ if (augs.length === 0)
70
+ continue;
71
+ const cat = catalog.categories.find(c => c.id === category);
72
+ console.log(chalk.bold(`${cat?.icon || '📦'} ${cat?.name || category}`));
73
+ for (const aug of augs) {
74
+ const status = getStatusIcon(aug.status);
75
+ const popular = aug.popular ? chalk.yellow(' ⭐') : '';
76
+ const eta = aug.eta ? chalk.gray(` (${aug.eta})`) : '';
77
+ console.log(` ${status} ${aug.name}${popular}${eta}`);
78
+ if (options.detailed) {
79
+ console.log(chalk.gray(` ${aug.description}`));
80
+ }
81
+ }
82
+ console.log('');
83
+ }
84
+ // Show summary
85
+ const available = augmentations.filter(a => a.status === 'available').length;
86
+ const coming = augmentations.filter(a => a.status === 'coming_soon').length;
87
+ console.log(chalk.gray('─'.repeat(50)));
88
+ console.log(chalk.green(`✅ ${available} available`) + chalk.gray(` • `) +
89
+ chalk.yellow(`🔜 ${coming} coming soon`));
90
+ console.log('');
91
+ console.log(chalk.dim('Sign up at app.soulcraft.com to activate'));
92
+ console.log(chalk.dim('Run "brainy augment info <name>" for details'));
93
+ }
94
+ /**
95
+ * Show detailed info about an augmentation
96
+ */
97
+ export async function showAugmentationInfo(id) {
98
+ const catalog = await fetchCatalog();
99
+ if (!catalog) {
100
+ console.log(chalk.red('❌ Could not load augmentation catalog'));
101
+ return;
102
+ }
103
+ const aug = catalog.augmentations.find(a => a.id === id);
104
+ if (!aug) {
105
+ console.log(chalk.red(`❌ Augmentation not found: ${id}`));
106
+ console.log('');
107
+ console.log('Available augmentations:');
108
+ catalog.augmentations.forEach(a => {
109
+ console.log(` • ${a.id}`);
110
+ });
111
+ return;
112
+ }
113
+ // Fetch full details from API
114
+ try {
115
+ const response = await fetch(`${CATALOG_API}/api/catalog/augmentation/${id}`);
116
+ const details = await response.json();
117
+ console.log(chalk.cyan.bold(`📦 ${details.name}`));
118
+ if (details.popular)
119
+ console.log(chalk.yellow('⭐ Popular'));
120
+ console.log('');
121
+ console.log(chalk.bold('Category:'), getCategoryName(details.category, catalog.categories));
122
+ console.log(chalk.bold('Status:'), getStatusText(details.status));
123
+ if (details.eta)
124
+ console.log(chalk.bold('Expected:'), details.eta);
125
+ console.log('');
126
+ console.log(chalk.bold('Description:'));
127
+ console.log(details.longDescription || details.description);
128
+ console.log('');
129
+ if (details.features) {
130
+ console.log(chalk.bold('Features:'));
131
+ details.features.forEach((f) => console.log(` ✓ ${f}`));
132
+ console.log('');
133
+ }
134
+ if (details.example) {
135
+ console.log(chalk.bold('Example:'));
136
+ console.log(chalk.gray('─'.repeat(50)));
137
+ console.log(details.example.code);
138
+ console.log(chalk.gray('─'.repeat(50)));
139
+ console.log('');
140
+ }
141
+ if (details.requirements?.config) {
142
+ console.log(chalk.bold('Required Configuration:'));
143
+ details.requirements.config.forEach((c) => console.log(` • ${c}`));
144
+ console.log('');
145
+ }
146
+ if (details.pricing) {
147
+ console.log(chalk.bold('Available in:'));
148
+ details.pricing.tiers.forEach((t) => console.log(` • ${t}`));
149
+ console.log('');
150
+ }
151
+ console.log(chalk.dim('To activate: brainy augment activate'));
152
+ }
153
+ catch (error) {
154
+ // Show basic info if API fails
155
+ console.log(chalk.cyan.bold(`📦 ${aug.name}`));
156
+ console.log(aug.description);
157
+ console.log('');
158
+ console.log(chalk.dim('Full details unavailable (API offline)'));
159
+ }
160
+ }
161
+ /**
162
+ * Show user's available augmentations
163
+ */
164
+ export async function showAvailable(licenseKey) {
165
+ const key = licenseKey || process.env.BRAINY_LICENSE_KEY || readLicenseFile();
166
+ if (!key) {
167
+ console.log(chalk.yellow('⚠️ No license key found'));
168
+ console.log('');
169
+ console.log('To see your available augmentations:');
170
+ console.log(' 1. Sign up at app.soulcraft.com');
171
+ console.log(' 2. Run: brainy augment activate');
172
+ return;
173
+ }
174
+ try {
175
+ const response = await fetch(`${CATALOG_API}/api/catalog/available`, {
176
+ headers: { 'x-license-key': key }
177
+ });
178
+ if (!response.ok) {
179
+ throw new Error('Invalid license');
180
+ }
181
+ const data = await response.json();
182
+ console.log(chalk.cyan.bold('🧠 Your Available Augmentations'));
183
+ console.log(chalk.gray(`Plan: ${data.plan}`));
184
+ console.log('');
185
+ const grouped = groupByCategory(data.augmentations, []);
186
+ for (const [category, augs] of Object.entries(grouped)) {
187
+ console.log(chalk.bold(category));
188
+ augs.forEach(aug => {
189
+ console.log(` ✅ ${aug.name}`);
190
+ });
191
+ console.log('');
192
+ }
193
+ if (data.operations) {
194
+ const used = data.operations.used || 0;
195
+ const limit = data.operations.limit;
196
+ const percent = limit === 'unlimited' ? 0 : Math.round((used / limit) * 100);
197
+ console.log(chalk.bold('Usage:'));
198
+ if (limit === 'unlimited') {
199
+ console.log(` Unlimited operations`);
200
+ }
201
+ else {
202
+ console.log(` ${used.toLocaleString()} / ${limit.toLocaleString()} operations (${percent}%)`);
203
+ }
204
+ }
205
+ }
206
+ catch (error) {
207
+ console.log(chalk.red('❌ Could not fetch available augmentations'));
208
+ console.log(chalk.gray(error.message));
209
+ }
210
+ }
211
+ // Helper functions
212
+ function loadCache(ignoreExpiry = false) {
213
+ try {
214
+ if (!existsSync(CACHE_PATH))
215
+ return null;
216
+ const data = JSON.parse(readFileSync(CACHE_PATH, 'utf8'));
217
+ if (!ignoreExpiry && Date.now() - data.timestamp > CACHE_TTL) {
218
+ return null;
219
+ }
220
+ return data.catalog;
221
+ }
222
+ catch {
223
+ return null;
224
+ }
225
+ }
226
+ function saveCache(catalog) {
227
+ try {
228
+ const dir = join(homedir(), '.brainy');
229
+ if (!existsSync(dir)) {
230
+ require('fs').mkdirSync(dir, { recursive: true });
231
+ }
232
+ writeFileSync(CACHE_PATH, JSON.stringify({
233
+ catalog,
234
+ timestamp: Date.now()
235
+ }));
236
+ }
237
+ catch {
238
+ // Ignore cache save errors
239
+ }
240
+ }
241
+ function groupByCategory(augmentations, categories) {
242
+ const grouped = {};
243
+ for (const aug of augmentations) {
244
+ if (!grouped[aug.category]) {
245
+ grouped[aug.category] = [];
246
+ }
247
+ grouped[aug.category].push(aug);
248
+ }
249
+ // Sort by category order
250
+ const ordered = {};
251
+ const categoryOrder = ['memory', 'coordination', 'enterprise', 'perception', 'dialog', 'activation', 'cognition', 'websocket'];
252
+ for (const cat of categoryOrder) {
253
+ if (grouped[cat]) {
254
+ ordered[cat] = grouped[cat];
255
+ }
256
+ }
257
+ return ordered;
258
+ }
259
+ function getStatusIcon(status) {
260
+ switch (status) {
261
+ case 'available': return chalk.green('✅');
262
+ case 'coming_soon': return chalk.yellow('🔜');
263
+ case 'deprecated': return chalk.red('⚠️');
264
+ default: return '❓';
265
+ }
266
+ }
267
+ function getStatusText(status) {
268
+ switch (status) {
269
+ case 'available': return chalk.green('Available');
270
+ case 'coming_soon': return chalk.yellow('Coming Soon');
271
+ case 'deprecated': return chalk.red('Deprecated');
272
+ default: return 'Unknown';
273
+ }
274
+ }
275
+ function getCategoryName(categoryId, categories) {
276
+ const cat = categories.find(c => c.id === categoryId);
277
+ return cat ? `${cat.icon} ${cat.name}` : categoryId;
278
+ }
279
+ function readLicenseFile() {
280
+ try {
281
+ const licensePath = join(homedir(), '.brainy', 'license');
282
+ if (existsSync(licensePath)) {
283
+ return readFileSync(licensePath, 'utf8').trim();
284
+ }
285
+ }
286
+ catch { }
287
+ return null;
288
+ }
289
+ function getDefaultCatalog() {
290
+ // Hardcoded fallback catalog
291
+ return {
292
+ version: '1.0.0',
293
+ categories: [
294
+ { id: 'memory', name: 'Memory', icon: '🧠', description: 'AI memory and persistence' },
295
+ { id: 'coordination', name: 'Coordination', icon: '🤝', description: 'Multi-agent orchestration' },
296
+ { id: 'enterprise', name: 'Enterprise', icon: '🏢', description: 'Business integrations' }
297
+ ],
298
+ augmentations: [
299
+ {
300
+ id: 'ai-memory',
301
+ name: 'AI Memory',
302
+ category: 'memory',
303
+ description: 'Persistent memory across all AI sessions',
304
+ status: 'available',
305
+ popular: true
306
+ },
307
+ {
308
+ id: 'agent-coordinator',
309
+ name: 'Agent Coordinator',
310
+ category: 'coordination',
311
+ description: 'Multi-agent handoffs and orchestration',
312
+ status: 'available',
313
+ popular: true
314
+ },
315
+ {
316
+ id: 'notion-sync',
317
+ name: 'Notion Sync',
318
+ category: 'enterprise',
319
+ description: 'Bidirectional Notion database sync',
320
+ status: 'available'
321
+ }
322
+ ]
323
+ };
324
+ }
325
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1,32 @@
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
+ export declare class CortexCLI {
8
+ private brainy;
9
+ private cortex;
10
+ private neuralImport?;
11
+ constructor();
12
+ /**
13
+ * Initialize the brain and cortex
14
+ */
15
+ init(options?: any): Promise<boolean>;
16
+ /**
17
+ * Add data - with Neural Import processing by default
18
+ */
19
+ add(data?: string, metadata?: any): Promise<void>;
20
+ /**
21
+ * Search with helpful display
22
+ */
23
+ search(query?: string, options?: any): Promise<void>;
24
+ /**
25
+ * Show statistics
26
+ */
27
+ stats(detailed?: boolean): Promise<void>;
28
+ /**
29
+ * Interactive chat interface
30
+ */
31
+ chat(initialMessage?: string): Promise<void>;
32
+ }