2025-08-07 19:33:03 -07:00
#!/usr/bin/env node
/ * *
2025-08-08 18:05:12 -07:00
* Brainy CLI - Redesigned for Better UX
* Direct commands + Augmentation system
2025-08-07 19:33:03 -07:00
* /
// @ts-ignore
import { program } from 'commander'
import { Cortex } from '../dist/cortex/cortex.js'
// @ts-ignore
import chalk from 'chalk'
import { readFileSync } from 'fs'
import { dirname , join } from 'path'
import { fileURLToPath } from 'url'
2025-08-10 16:25:12 -07:00
import { createInterface } from 'readline'
2025-08-07 19:33:03 -07:00
2025-08-10 11:32:59 -07:00
// Use native fetch (available in Node.js 18+)
2025-08-09 18:27:21 -07:00
2025-08-07 19:33:03 -07:00
const _ _dirname = dirname ( fileURLToPath ( import . meta . url ) )
const packageJson = JSON . parse ( readFileSync ( join ( _ _dirname , '..' , 'package.json' ) , 'utf8' ) )
// Create Cortex instance
const cortex = new Cortex ( )
2025-08-08 18:05:12 -07:00
// Helper functions
2025-08-07 19:33:03 -07:00
const exitProcess = ( code = 0 ) => {
2025-08-08 18:05:12 -07:00
setTimeout ( ( ) => process . exit ( code ) , 100 )
2025-08-07 19:33:03 -07:00
}
const wrapAction = ( fn ) => {
return async ( ... args ) => {
try {
await fn ( ... args )
exitProcess ( 0 )
} catch ( error ) {
console . error ( chalk . red ( 'Error:' ) , error . message )
exitProcess ( 1 )
}
}
}
const wrapInteractive = ( fn ) => {
return async ( ... args ) => {
try {
await fn ( ... args )
exitProcess ( 0 )
} catch ( error ) {
console . error ( chalk . red ( 'Error:' ) , error . message )
exitProcess ( 1 )
}
}
}
2025-08-08 18:05:12 -07:00
// ========================================
// MAIN PROGRAM SETUP
// ========================================
2025-08-07 19:33:03 -07:00
program
2025-08-08 18:05:12 -07:00
. name ( 'brainy' )
2025-08-10 16:25:12 -07:00
. description ( '🧠 Brainy - Multi-Dimensional AI Database' )
2025-08-07 19:33:03 -07:00
. version ( packageJson . version )
2025-08-08 18:05:12 -07:00
// ========================================
// CORE DATABASE COMMANDS (Direct Access)
// ========================================
2025-08-07 19:33:03 -07:00
program
. command ( 'init' )
2025-08-10 16:25:12 -07:00
. description ( 'Initialize Brainy in your project' )
2025-08-07 19:33:03 -07:00
. option ( '-s, --storage <type>' , 'Storage type (filesystem, s3, r2, gcs, memory)' )
. option ( '-e, --encryption' , 'Enable encryption for secrets' )
. action ( wrapAction ( async ( options ) => {
await cortex . init ( options )
} ) )
program
. command ( 'add [data]' )
2025-08-12 11:49:38 -07:00
. description ( '🔒 Add data literally (safe, no AI processing)' )
2025-08-10 16:25:12 -07:00
. option ( '-m, --metadata <json>' , 'Metadata facets as JSON' )
2025-08-07 19:33:03 -07:00
. option ( '-i, --id <id>' , 'Custom ID' )
2025-08-12 11:49:38 -07:00
. option ( '--smart' , 'Enable AI processing (same as smart-add command)' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( data , options ) => {
2025-08-07 19:33:03 -07:00
let metadata = { }
if ( options . metadata ) {
try {
metadata = JSON . parse ( options . metadata )
} catch {
console . error ( chalk . red ( 'Invalid JSON metadata' ) )
process . exit ( 1 )
}
}
if ( options . id ) {
metadata . id = options . id
}
2025-08-12 11:49:38 -07:00
// Use smart processing if --smart flag is provided
if ( options . smart ) {
console . log ( chalk . dim ( '🧠 AI processing enabled' ) )
await cortex . addSmart ( data , metadata )
} else {
console . log ( chalk . dim ( '🔒 Literal storage (safe for secrets/API keys)' ) )
await cortex . add ( data , metadata )
}
} ) )
program
. command ( 'smart-add [data]' )
. description ( '🧠 Add data with AI processing (Neural Import, entity detection)' )
. option ( '-m, --metadata <json>' , 'Metadata facets as JSON' )
. option ( '-i, --id <id>' , 'Custom ID' )
. action ( wrapAction ( async ( data , options ) => {
let metadata = { }
if ( options . metadata ) {
try {
metadata = JSON . parse ( options . metadata )
} catch {
console . error ( chalk . red ( 'Invalid JSON metadata' ) )
process . exit ( 1 )
}
}
if ( options . id ) {
metadata . id = options . id
}
console . log ( chalk . dim ( '🧠 AI processing enabled (Neural Import + entity detection)' ) )
await cortex . addSmart ( data , metadata )
2025-08-08 18:05:12 -07:00
} ) )
2025-08-07 19:33:03 -07:00
program
. command ( 'search <query>' )
2025-08-10 16:25:12 -07:00
. description ( 'Multi-dimensional search across vector, graph, and facets' )
2025-08-07 19:33:03 -07:00
. option ( '-l, --limit <number>' , 'Number of results' , '10' )
2025-08-10 16:25:12 -07:00
. option ( '-f, --filter <json>' , 'Filter by metadata facets' )
. option ( '-v, --verbs <types>' , 'Include related data (comma-separated)' )
. option ( '-d, --depth <number>' , 'Relationship depth' , '1' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( query , options ) => {
2025-08-07 19:33:03 -07:00
const searchOptions = { limit : parseInt ( options . limit ) }
if ( options . filter ) {
try {
searchOptions . filter = JSON . parse ( options . filter )
} catch {
console . error ( chalk . red ( 'Invalid filter JSON' ) )
process . exit ( 1 )
}
}
if ( options . verbs ) {
searchOptions . verbs = options . verbs . split ( ',' ) . map ( v => v . trim ( ) )
searchOptions . depth = parseInt ( options . depth )
}
await cortex . search ( query , searchOptions )
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'chat [question]' )
2025-08-12 11:49:38 -07:00
. description ( '🧠 Beautiful AI chat with local memory' )
. option ( '-l, --list' , 'List all chat sessions' )
. option ( '-s, --search <query>' , 'Search all conversations' )
. option ( '-h, --history [limit]' , 'Show conversation history (default: 10)' )
. option ( '--session <id>' , 'Use specific chat session' )
. option ( '--new' , 'Start a new session' )
. option ( '--role <name>' , 'Agent role (premium feature preview)' , 'assistant' )
2025-08-08 18:05:12 -07:00
. action ( wrapInteractive ( async ( question , options ) => {
2025-08-12 11:49:38 -07:00
const { BrainyData } = await import ( '../dist/brainyData.js' )
const { ChatCLI } = await import ( '../dist/chat/ChatCLI.js' )
const brainy = new BrainyData ( )
await brainy . init ( )
const chatCLI = new ChatCLI ( brainy )
// Handle different modes
if ( options . list ) {
await chatCLI . listSessions ( )
} else if ( options . search ) {
await chatCLI . searchConversations ( options . search )
} else if ( options . history ) {
const limit = typeof options . history === 'string' ? parseInt ( options . history ) : 10
await chatCLI . showHistory ( limit )
} else if ( question ) {
// Single message mode
await chatCLI . sendMessage ( question , {
sessionId : options . session ,
speaker : options . role
} )
} else {
// Interactive chat mode
await chatCLI . startInteractiveChat ( {
sessionId : options . session ,
speaker : options . role ,
newSession : options . new
} )
}
2025-08-07 19:33:03 -07:00
} ) )
program
. command ( 'stats' )
2025-08-10 16:25:12 -07:00
. description ( 'Show database statistics and insights' )
2025-08-08 18:05:12 -07:00
. option ( '-d, --detailed' , 'Show detailed statistics' )
2025-08-07 19:33:03 -07:00
. action ( wrapAction ( async ( options ) => {
await cortex . stats ( options . detailed )
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'health' )
2025-08-10 16:25:12 -07:00
. description ( 'Check system health' )
2025-08-08 18:05:12 -07:00
. option ( '--auto-fix' , 'Automatically apply safe repairs' )
. action ( wrapAction ( async ( options ) => {
await cortex . health ( options )
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'find' )
2025-08-10 16:25:12 -07:00
. description ( 'Advanced intelligent search (interactive)' )
2025-08-08 18:05:12 -07:00
. action ( wrapInteractive ( async ( ) => {
await cortex . advancedSearch ( )
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'explore [nodeId]' )
2025-08-10 16:25:12 -07:00
. description ( 'Explore data relationships interactively' )
2025-08-08 18:05:12 -07:00
. action ( wrapInteractive ( async ( nodeId ) => {
await cortex . explore ( nodeId )
2025-08-07 19:33:03 -07:00
} ) )
program
. command ( 'backup' )
2025-08-10 16:25:12 -07:00
. description ( 'Create database backup' )
2025-08-07 19:33:03 -07:00
. option ( '-c, --compress' , 'Compress backup' )
. option ( '-o, --output <file>' , 'Output file' )
. action ( wrapAction ( async ( options ) => {
await cortex . backup ( options )
} ) )
program
. command ( 'restore <file>' )
2025-08-10 16:25:12 -07:00
. description ( 'Restore from backup' )
2025-08-07 19:33:03 -07:00
. action ( wrapInteractive ( async ( file ) => {
await cortex . restore ( file )
} ) )
2025-08-12 11:49:38 -07:00
// Chat commands moved to main chat command above
2025-08-09 14:36:05 -07:00
// ========================================
// BRAIN CLOUD INTEGRATION
// ========================================
2025-08-09 18:27:21 -07:00
program
. command ( 'connect' )
2025-08-10 16:25:12 -07:00
. description ( 'Connect to Brain Cloud for AI memory' )
2025-08-09 18:27:21 -07:00
. action ( wrapInteractive ( async ( ) => {
2025-08-10 16:25:12 -07:00
console . log ( chalk . cyan ( '\n🧠 Brain Cloud Setup' ) )
console . log ( chalk . gray ( '━' . repeat ( 40 ) ) )
2025-08-09 18:27:21 -07:00
try {
// Detect customer ID
const customerId = await detectCustomerId ( )
if ( customerId ) {
2025-08-10 16:25:12 -07:00
console . log ( chalk . green ( ` ✅ Found Brain Cloud: ${ customerId } ` ) )
console . log ( '\n🔧 Setting up AI memory:' )
console . log ( chalk . yellow ( ' • Update configuration' ) )
2025-08-09 18:27:21 -07:00
console . log ( chalk . yellow ( ' • Add memory instructions' ) )
console . log ( chalk . yellow ( ' • Enable cross-session memory' ) )
2025-08-10 16:25:12 -07:00
console . log ( chalk . cyan ( '\n🚀 Configuring...' ) )
await setupBrainCloudMemory ( customerId )
console . log ( chalk . green ( '\n✅ AI memory connected!' ) )
console . log ( chalk . cyan ( 'Restart Claude Code to activate memory.' ) )
2025-08-09 18:27:21 -07:00
} else {
2025-08-10 16:25:12 -07:00
console . log ( chalk . yellow ( 'No Brain Cloud found. Setting up:' ) )
2025-08-11 13:02:29 -07:00
console . log ( '\n1. Visit: ' + chalk . cyan ( 'https://soulcraft.com/brain-cloud' ) )
console . log ( '2. Get your Early Access license key' )
console . log ( '3. Run ' + chalk . green ( 'brainy cloud setup' ) + ' for auto-configuration' )
2025-08-09 18:27:21 -07:00
}
} catch ( error ) {
console . log ( chalk . red ( '❌ Setup failed:' ) , error . message )
}
} ) )
2025-08-11 13:02:29 -07:00
// Moved to brainy cloud setup command below for better separation
// ========================================
// BRAIN CLOUD COMMANDS (Premium Features)
// ========================================
const cloud = program
. command ( 'cloud' )
. description ( 'Brain Cloud premium features and management' )
cloud
. command ( 'setup' )
. description ( '🚀 Auto-setup Brain Cloud (provisions cloud instance + configures locally)' )
. option ( '--email <email>' , 'Your email address' )
. action ( wrapInteractive ( async ( options ) => {
console . log ( chalk . cyan ( '🧠☁️ Brain Cloud Auto-Setup' ) )
console . log ( chalk . gray ( '═' . repeat ( 50 ) ) )
console . log ( chalk . yellow ( 'Perfect for non-coders! One-click setup.\n' ) )
try {
// Step 1: Validate license
await validateLicense ( )
// Step 2: Check if Brainy is installed
await ensureBrainyInstalled ( )
// Step 3: Provision cloud instance
const instance = await provisionCloudInstance ( options . email )
// Step 4: Configure local Brainy
await configureBrainy ( instance )
// Step 5: Install Brain Cloud package
await installBrainCloudPackage ( )
// Step 6: Test connection
await testConnection ( instance )
console . log ( '\n✅ Setup Complete!' )
console . log ( chalk . gray ( '═' . repeat ( 30 ) ) )
console . log ( '\nYour Brain Cloud instance is ready:' )
console . log ( ` 📱 Dashboard: ${ chalk . cyan ( instance . endpoints . dashboard ) } ` )
console . log ( ` 🔗 API: ${ chalk . gray ( instance . endpoints . api ) } ` )
console . log ( '\n🚀 What\'s next?' )
console . log ( '• Your AI now has persistent memory across all conversations' )
console . log ( '• All devices sync automatically to your cloud instance' )
console . log ( '• Agents coordinate seamlessly through handoffs' )
console . log ( '\n💡 Try asking Claude: "Remember that I prefer TypeScript"' )
console . log ( ' Then in a new conversation: "What do you know about my preferences?"' )
} catch ( error ) {
console . error ( '\n❌ Setup failed:' , error . message )
console . log ( '\n🆘 Need help? Contact support@soulcraft.com' )
}
} ) )
cloud
. command ( 'connect [id]' )
. description ( 'Connect to existing Brain Cloud instance' )
. action ( wrapInteractive ( async ( id ) => {
if ( id ) {
console . log ( chalk . green ( ` ✅ Connecting to Brain Cloud instance: ${ id } ` ) )
// Connect to specific instance
} else {
// Show connection instructions
console . log ( chalk . cyan ( '\n🔗 Brain Cloud Connection' ) )
console . log ( chalk . gray ( '━' . repeat ( 40 ) ) )
console . log ( '\nOptions:' )
console . log ( '1. ' + chalk . green ( 'brainy cloud setup' ) + ' - Auto-setup with provisioning' )
console . log ( '2. ' + chalk . green ( 'brainy cloud connect <id>' ) + ' - Connect to existing instance' )
console . log ( '\nGet started: ' + chalk . cyan ( 'https://soulcraft.com/brain-cloud' ) )
}
} ) )
cloud
. command ( 'status [id]' )
. description ( 'Check Brain Cloud instance status' )
. action ( wrapInteractive ( async ( id ) => {
// Implementation moved from old cloud command
console . log ( 'Checking Brain Cloud status...' )
} ) )
cloud
. command ( 'dashboard [id]' )
. description ( 'Open Brain Cloud dashboard' )
. action ( wrapInteractive ( async ( id ) => {
const dashboardUrl = id
? ` https://brainy- ${ id } .soulcraft-brain.workers.dev/dashboard `
: 'https://app.soulcraft.com'
console . log ( chalk . cyan ( ` \n 🌐 Opening Brain Cloud Dashboard: ${ dashboardUrl } ` ) )
try {
const { exec } = await import ( 'child_process' )
const { promisify } = await import ( 'util' )
const execAsync = promisify ( exec )
const command = process . platform === 'win32' ? 'start' :
process . platform === 'darwin' ? 'open' : 'xdg-open'
await execAsync ( ` ${ command } " ${ dashboardUrl } " ` )
console . log ( chalk . green ( '✅ Dashboard opened!' ) )
} catch ( error ) {
console . log ( chalk . yellow ( '💡 Copy the URL above to open in your browser' ) )
}
} ) )
// Legacy cloud command (for backward compatibility)
2025-08-09 14:36:05 -07:00
program
2025-08-11 13:02:29 -07:00
. command ( 'cloud-legacy [action]' )
. description ( 'Legacy Brain Cloud connection (deprecated - use "brainy cloud")' )
2025-08-09 14:36:05 -07:00
. option ( '--connect <id>' , 'Connect to existing Brain Cloud instance' )
2025-08-09 18:27:21 -07:00
. option ( '--export <id>' , 'Export all data from Brain Cloud instance' )
. option ( '--status <id>' , 'Check status of Brain Cloud instance' )
. option ( '--dashboard <id>' , 'Open dashboard for Brain Cloud instance' )
2025-08-09 14:36:05 -07:00
. option ( '--migrate' , 'Migrate between local and cloud' )
. action ( wrapInteractive ( async ( action , options ) => {
2025-08-11 13:02:29 -07:00
console . log ( chalk . yellow ( '⚠️ Deprecated: Use "brainy cloud" commands instead' ) )
console . log ( chalk . cyan ( 'Examples:' ) )
console . log ( ' brainy cloud setup' )
console . log ( ' brainy cloud connect <id>' )
console . log ( ' brainy cloud dashboard' )
console . log ( '' )
2025-08-09 14:36:05 -07:00
// For now, show connection instructions
console . log ( chalk . cyan ( '\n⚛️ BRAIN CLOUD - AI Memory That Never Forgets' ) )
console . log ( chalk . gray ( '━' . repeat ( 50 ) ) )
if ( options . connect ) {
console . log ( chalk . green ( ` ✅ Connecting to Brain Cloud instance: ${ options . connect } ` ) )
2025-08-09 18:27:21 -07:00
try {
// Test connection to Brain Cloud worker
2025-08-12 07:52:11 -07:00
const healthUrl = ` https://api.soulcraft.com/brain-cloud/health `
2025-08-09 18:27:21 -07:00
const response = await fetch ( healthUrl , {
headers : { 'x-customer-id' : options . connect }
} )
if ( response . ok ) {
const data = await response . json ( )
console . log ( chalk . green ( ` 🧠 ${ data . status } ` ) )
console . log ( chalk . cyan ( ` 💫 Instance: ${ data . customerId } ` ) )
console . log ( chalk . gray ( ` ⏰ Connected at: ${ new Date ( data . timestamp ) . toLocaleString ( ) } ` ) )
// Test memories endpoint
2025-08-12 07:52:11 -07:00
const memoriesResponse = await fetch ( ` https://api.soulcraft.com/brain-cloud/memories ` , {
2025-08-09 18:27:21 -07:00
headers : { 'x-customer-id' : options . connect }
} )
if ( memoriesResponse . ok ) {
const memoriesData = await memoriesResponse . json ( )
console . log ( chalk . yellow ( ` \n ${ memoriesData . message } ` ) )
console . log ( chalk . gray ( '📊 Your atomic memories:' ) )
memoriesData . memories . forEach ( memory => {
const time = new Date ( memory . created ) . toLocaleString ( )
console . log ( chalk . gray ( ` • ${ memory . content } ( ${ time } ) ` ) )
} )
}
} else {
console . log ( chalk . red ( '❌ Could not connect to Brain Cloud' ) )
console . log ( chalk . yellow ( '💡 Make sure you have an active instance' ) )
2025-08-10 16:45:19 -07:00
console . log ( '\nSign up at: ' + chalk . cyan ( 'https://app.soulcraft.com' ) )
2025-08-09 18:27:21 -07:00
}
} catch ( error ) {
console . log ( chalk . red ( '❌ Connection failed:' ) , error . message )
2025-08-10 16:45:19 -07:00
console . log ( '\nSign up at: ' + chalk . cyan ( 'https://app.soulcraft.com' ) )
2025-08-09 18:27:21 -07:00
}
} else if ( options . export ) {
console . log ( chalk . green ( ` 📦 Exporting data from Brain Cloud instance: ${ options . export } ` ) )
try {
2025-08-12 07:52:11 -07:00
const response = await fetch ( ` https://api.soulcraft.com/brain-cloud/export ` , {
2025-08-09 18:27:21 -07:00
headers : { 'x-customer-id' : options . export }
} )
if ( response . ok ) {
const data = await response . json ( )
const filename = ` brainy-export- ${ options . export } - ${ Date . now ( ) } .json `
// Write to file
const fs = await import ( 'fs/promises' )
await fs . writeFile ( filename , JSON . stringify ( data , null , 2 ) )
console . log ( chalk . green ( ` ✅ Data exported to: ${ filename } ` ) )
console . log ( chalk . gray ( ` 📊 Exported ${ data . memories ? . length || 0 } memories ` ) )
} else {
console . log ( chalk . red ( '❌ Export failed - instance not found' ) )
}
} catch ( error ) {
console . log ( chalk . red ( '❌ Export error:' ) , error . message )
}
} else if ( options . status ) {
console . log ( chalk . green ( ` 🔍 Checking status of Brain Cloud instance: ${ options . status } ` ) )
try {
2025-08-12 07:52:11 -07:00
const response = await fetch ( ` https://api.soulcraft.com/brain-cloud/health ` , {
2025-08-09 18:27:21 -07:00
headers : { 'x-customer-id' : options . status }
} )
if ( response . ok ) {
const data = await response . json ( )
console . log ( chalk . green ( ` ✅ Instance Status: Active ` ) )
console . log ( chalk . cyan ( ` 🧠 ${ data . status } ` ) )
console . log ( chalk . gray ( ` ⏰ Last check: ${ new Date ( data . timestamp ) . toLocaleString ( ) } ` ) )
// Get memory count
2025-08-12 07:52:11 -07:00
const memoriesResponse = await fetch ( ` https://api.soulcraft.com/brain-cloud/memories ` , {
2025-08-09 18:27:21 -07:00
headers : { 'x-customer-id' : options . status }
} )
if ( memoriesResponse . ok ) {
const memoriesData = await memoriesResponse . json ( )
console . log ( chalk . yellow ( ` 📊 Total memories: ${ memoriesData . count } ` ) )
}
} else {
console . log ( chalk . red ( '❌ Instance not found or inactive' ) )
}
} catch ( error ) {
console . log ( chalk . red ( '❌ Status check failed:' ) , error . message )
}
} else if ( options . dashboard ) {
console . log ( chalk . green ( ` 🌐 Opening dashboard for Brain Cloud instance: ${ options . dashboard } ` ) )
2025-08-10 16:45:19 -07:00
const dashboardUrl = ` https://app.soulcraft.com/dashboard.html?customer_id= ${ options . dashboard } `
2025-08-09 18:27:21 -07:00
console . log ( chalk . cyan ( ` \n 🔗 Dashboard URL: ${ dashboardUrl } ` ) )
console . log ( chalk . gray ( 'Opening in your default browser...' ) )
try {
const { exec } = await import ( 'child_process' )
const { promisify } = await import ( 'util' )
const execAsync = promisify ( exec )
// Cross-platform browser opening
const command = process . platform === 'win32' ? 'start' :
process . platform === 'darwin' ? 'open' : 'xdg-open'
await execAsync ( ` ${ command } " ${ dashboardUrl } " ` )
console . log ( chalk . green ( '✅ Dashboard opened!' ) )
} catch ( error ) {
console . log ( chalk . yellow ( '💡 Copy the URL above to open in your browser' ) )
}
2025-08-09 14:36:05 -07:00
} else {
console . log ( chalk . yellow ( '📡 Brain Cloud Setup' ) )
2025-08-10 16:45:19 -07:00
console . log ( '\n1. Sign up at: ' + chalk . cyan ( 'https://app.soulcraft.com' ) )
2025-08-09 14:36:05 -07:00
console . log ( '2. Get your customer ID' )
console . log ( '3. Connect with: ' + chalk . green ( 'brainy cloud --connect YOUR_ID' ) )
console . log ( '\nBenefits:' )
console . log ( ' • ' + chalk . green ( 'Never lose AI context again' ) )
console . log ( ' • ' + chalk . green ( 'Sync across all devices' ) )
console . log ( ' • ' + chalk . green ( 'Unlimited memory storage' ) )
console . log ( ' • ' + chalk . green ( '$19/month or free trial' ) )
}
} ) )
2025-08-08 18:05:12 -07:00
// ========================================
// AUGMENTATION MANAGEMENT (Direct Commands)
// ========================================
2025-08-07 19:33:03 -07:00
2025-08-11 09:57:12 -07:00
const augment = program
. command ( 'augment' )
. description ( 'Manage brain augmentations' )
augment
. command ( 'list' )
. description ( 'List available and active augmentations' )
. action ( wrapAction ( async ( ) => {
console . log ( chalk . green ( '✅ Active (Built-in):' ) )
console . log ( ' • neural-import' )
console . log ( ' • basic-storage' )
console . log ( '' )
// Check for Brain Cloud
try {
await import ( '@soulcraft/brain-cloud' )
const hasLicense = process . env . BRAINY _LICENSE _KEY
if ( hasLicense ) {
console . log ( chalk . cyan ( '✅ Active (Premium):' ) )
console . log ( ' • ai-memory' )
console . log ( ' • agent-coordinator' )
console . log ( '' )
}
} catch { }
2025-08-11 13:02:29 -07:00
// Fetch from catalog API
try {
const response = await fetch ( 'http://localhost:3001/api/catalog/cli' )
if ( response . ok ) {
const catalog = await response . json ( )
// Show available augmentations
const available = catalog . augmentations . filter ( aug => aug . status === 'available' )
if ( available . length > 0 ) {
console . log ( chalk . cyan ( '🌟 Available (Brain Cloud):' ) )
available . forEach ( aug => {
const popular = aug . popular ? chalk . yellow ( ' ⭐ Popular' ) : ''
console . log ( ` • ${ aug . id } - ${ aug . description } ${ popular } ` )
} )
console . log ( '' )
}
// Show coming soon
const comingSoon = catalog . augmentations . filter ( aug => aug . status === 'coming-soon' )
if ( comingSoon . length > 0 ) {
console . log ( chalk . dim ( '📦 Coming Soon:' ) )
comingSoon . forEach ( aug => {
const eta = aug . eta ? ` ( ${ aug . eta } ) ` : ''
console . log ( chalk . dim ( ` • ${ aug . id } - ${ aug . description } ${ eta } ` ) )
} )
console . log ( '' )
}
} else {
throw new Error ( 'API unavailable' )
}
} catch ( error ) {
// Fallback to static list if API is unavailable
console . log ( chalk . cyan ( '🌟 Available (Brain Cloud):' ) )
console . log ( ' • ai-memory - ' + chalk . yellow ( '⭐ Popular' ) + ' - Persistent AI memory' )
console . log ( ' • agent-coordinator - ' + chalk . yellow ( '⭐ Popular' ) + ' - Multi-agent handoffs' )
console . log ( ' • notion-sync - Enterprise connector' )
console . log ( '' )
}
console . log ( chalk . dim ( '🚀 Join Early Access: https://soulcraft.com/brain-cloud' ) )
2025-08-12 09:03:36 -07:00
console . log ( chalk . dim ( '🌐 Authenticate: brainy cloud auth' ) )
2025-08-11 09:57:12 -07:00
} ) )
augment
. command ( 'activate' )
. description ( 'Activate Brain Cloud with license key' )
. action ( wrapAction ( async ( ) => {
const rl = createInterface ( {
input : process . stdin ,
output : process . stdout
} )
2025-08-12 08:27:26 -07:00
console . log ( chalk . cyan ( '☁️ Brain Cloud Activation (Optional Premium)' ) )
2025-08-11 09:57:12 -07:00
console . log ( '' )
2025-08-12 08:27:26 -07:00
console . log ( chalk . yellow ( 'Note: Brainy core is 100% free and fully functional!' ) )
console . log ( 'Brain Cloud adds optional team & sync features.' )
console . log ( '' )
console . log ( 'Get Brain Cloud at: ' + chalk . green ( 'app.soulcraft.com' ) )
2025-08-11 09:57:12 -07:00
console . log ( '(14-day free trial available)' )
console . log ( '' )
rl . question ( 'License key: ' , async ( key ) => {
if ( key . startsWith ( 'lic_' ) ) {
// Save to config
const fs = await import ( 'fs/promises' )
const os = await import ( 'os' )
const configPath = ` ${ os . homedir ( ) } /.brainy `
await fs . mkdir ( configPath , { recursive : true } )
await fs . writeFile ( ` ${ configPath } /license ` , key )
console . log ( chalk . green ( '✅ License saved!' ) )
console . log ( '' )
2025-08-12 08:37:10 -07:00
console . log ( '// Brain Cloud is NOT an npm package!' )
console . log ( '// Augmentations auto-load based on your subscription' )
2025-08-11 09:57:12 -07:00
console . log ( '' )
2025-08-12 08:37:10 -07:00
console . log ( 'Next steps:' )
console . log ( chalk . cyan ( ' brainy cloud auth' ) )
console . log ( chalk . gray ( ' # Your augmentations will auto-load' ) )
2025-08-11 09:57:12 -07:00
} else {
console . log ( chalk . red ( 'Invalid license key' ) )
}
rl . close ( )
} )
} ) )
augment
. command ( 'info <name>' )
. description ( 'Get info about an augmentation' )
. action ( wrapAction ( async ( name ) => {
const augmentations = {
'ai-memory' : {
name : 'AI Memory' ,
description : 'Persistent memory across all AI sessions' ,
category : 'Memory' ,
tier : 'Premium' ,
popular : true ,
example : `
2025-08-12 09:03:36 -07:00
// AI Memory auto-loads after 'brainy cloud auth' - no imports needed!
2025-08-11 09:57:12 -07:00
const cortex = new Cortex ( )
cortex . register ( new AIMemory ( ) )
// Now your AI remembers everything
await brain . add ( "User prefers dark mode" )
// This persists across sessions automatically`
} ,
'agent-coordinator' : {
name : 'Agent Coordinator' ,
description : 'Multi-agent handoffs and orchestration' ,
category : 'Coordination' ,
tier : 'Premium' ,
popular : true
} ,
'notion-sync' : {
name : 'Notion Sync' ,
description : 'Bidirectional Notion database sync' ,
category : 'Enterprise' ,
tier : 'Premium'
}
}
const aug = augmentations [ name ]
if ( aug ) {
console . log ( chalk . cyan ( ` 📦 ${ aug . name } ` ) + ( aug . popular ? chalk . yellow ( ' ⭐ Popular' ) : '' ) )
console . log ( '' )
console . log ( ` Category: ${ aug . category } ` )
console . log ( ` Tier: ${ aug . tier } ` )
console . log ( ` Description: ${ aug . description } ` )
if ( aug . example ) {
console . log ( '' )
console . log ( 'Example:' )
console . log ( chalk . gray ( aug . example ) )
}
} else {
console . log ( chalk . red ( ` Unknown augmentation: ${ name } ` ) )
}
} ) )
2025-08-07 19:33:03 -07:00
program
2025-08-08 18:05:12 -07:00
. command ( 'install <augmentation>' )
2025-08-11 09:57:12 -07:00
. description ( 'Install augmentation (legacy - use augment activate)' )
2025-08-08 18:05:12 -07:00
. option ( '-m, --mode <type>' , 'Installation mode (free|premium)' , 'free' )
. option ( '-c, --config <json>' , 'Configuration as JSON' )
. action ( wrapAction ( async ( augmentation , options ) => {
2025-08-11 09:57:12 -07:00
console . log ( chalk . yellow ( 'Note: Use "brainy augment activate" for Brain Cloud' ) )
2025-08-08 18:05:12 -07:00
if ( augmentation === 'brain-jar' ) {
await cortex . brainJarInstall ( options . mode )
} else {
// Generic augmentation install
let config = { }
if ( options . config ) {
try {
config = JSON . parse ( options . config )
} catch {
console . error ( chalk . red ( 'Invalid JSON configuration' ) )
process . exit ( 1 )
}
}
await cortex . addAugmentation ( augmentation , undefined , config )
}
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'run <augmentation>' )
2025-08-10 16:25:12 -07:00
. description ( 'Run augmentation' )
2025-08-08 18:05:12 -07:00
. option ( '-c, --config <json>' , 'Runtime configuration as JSON' )
. action ( wrapAction ( async ( augmentation , options ) => {
if ( augmentation === 'brain-jar' ) {
await cortex . brainJarStart ( options )
} else {
// Generic augmentation execution
const inputData = options . config ? JSON . parse ( options . config ) : { run : true }
await cortex . executePipelineStep ( augmentation , inputData )
}
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'status [augmentation]' )
2025-08-10 16:25:12 -07:00
. description ( 'Show augmentation status' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( augmentation ) => {
if ( augmentation === 'brain-jar' ) {
await cortex . brainJarStatus ( )
} else if ( augmentation ) {
// Show specific augmentation status
await cortex . listAugmentations ( )
} else {
// Show all augmentation status
await cortex . listAugmentations ( )
}
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'stop [augmentation]' )
2025-08-10 16:25:12 -07:00
. description ( 'Stop augmentation' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( augmentation ) => {
if ( augmentation === 'brain-jar' ) {
await cortex . brainJarStop ( )
} else {
console . log ( chalk . yellow ( 'Stop functionality for generic augmentations not yet implemented' ) )
}
2025-08-07 19:33:03 -07:00
} ) )
program
2025-08-08 18:05:12 -07:00
. command ( 'list' )
2025-08-10 16:25:12 -07:00
. description ( 'List installed augmentations' )
2025-08-08 18:05:12 -07:00
. option ( '-a, --available' , 'Show available augmentations' )
2025-08-07 19:33:03 -07:00
. action ( wrapAction ( async ( options ) => {
2025-08-08 18:05:12 -07:00
if ( options . available ) {
2025-08-11 09:57:12 -07:00
console . log ( chalk . green ( '✅ Built-in (Free):' ) )
console . log ( ' • neural-import - AI-powered data understanding' )
console . log ( ' • basic-storage - Local persistence' )
console . log ( '' )
console . log ( chalk . cyan ( '🌟 Premium (Brain Cloud):' ) )
console . log ( ' • ai-memory - ' + chalk . yellow ( '⭐ Most Popular' ) + ' - AI that remembers' )
console . log ( ' • agent-coordinator - ' + chalk . yellow ( '⭐ Most Popular' ) + ' - Multi-agent orchestration' )
console . log ( ' • notion-sync - Enterprise connector' )
console . log ( ' • More at app.soulcraft.com/augmentations' )
2025-08-08 18:05:12 -07:00
console . log ( '' )
2025-08-11 09:57:12 -07:00
console . log ( chalk . dim ( 'Sign up: app.soulcraft.com (14-day free trial)' ) )
2025-08-12 09:03:36 -07:00
console . log ( chalk . dim ( 'Authenticate: brainy cloud auth' ) )
2025-08-08 18:05:12 -07:00
} else {
await cortex . listAugmentations ( )
}
2025-08-07 19:33:03 -07:00
} ) )
2025-08-09 08:24:11 -07:00
2025-08-08 18:05:12 -07:00
// ========================================
// BRAIN JAR SPECIFIC COMMANDS (Rich UX)
// ========================================
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
const brainJar = program . command ( 'brain-jar' )
2025-08-10 16:25:12 -07:00
. description ( 'AI coordination and collaboration' )
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'install' )
2025-08-10 16:25:12 -07:00
. description ( 'Install Brain Jar coordination' )
2025-08-08 18:05:12 -07:00
. option ( '-m, --mode <type>' , 'Installation mode (free|premium)' , 'free' )
. action ( wrapAction ( async ( options ) => {
await cortex . brainJarInstall ( options . mode )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'start' )
2025-08-10 16:25:12 -07:00
. description ( 'Start Brain Jar coordination' )
2025-08-08 18:05:12 -07:00
. option ( '-s, --server <url>' , 'Custom server URL' )
. option ( '-n, --name <name>' , 'Agent name' )
. option ( '-r, --role <role>' , 'Agent role' )
. action ( wrapAction ( async ( options ) => {
await cortex . brainJarStart ( options )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'dashboard' )
2025-08-10 16:25:12 -07:00
. description ( 'Open Brain Jar dashboard' )
2025-08-08 18:05:12 -07:00
. option ( '-o, --open' , 'Auto-open in browser' , true )
. action ( wrapAction ( async ( options ) => {
await cortex . brainJarDashboard ( options . open )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'status' )
2025-08-10 16:25:12 -07:00
. description ( 'Show Brain Jar status' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( ) => {
await cortex . brainJarStatus ( )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'agents' )
2025-08-10 16:25:12 -07:00
. description ( 'List connected agents' )
2025-08-07 19:33:03 -07:00
. action ( wrapAction ( async ( ) => {
2025-08-08 18:05:12 -07:00
await cortex . brainJarAgents ( )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'message <text>' )
2025-08-10 16:25:12 -07:00
. description ( 'Send message to coordination channel' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( text ) => {
await cortex . brainJarMessage ( text )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
brainJar
. command ( 'search <query>' )
2025-08-10 16:25:12 -07:00
. description ( 'Search coordination history' )
2025-08-08 18:05:12 -07:00
. option ( '-l, --limit <number>' , 'Number of results' , '10' )
. action ( wrapAction ( async ( query , options ) => {
await cortex . brainJarSearch ( query , parseInt ( options . limit ) )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
// ========================================
// CONFIGURATION COMMANDS
// ========================================
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
const config = program . command ( 'config' )
2025-08-10 16:25:12 -07:00
. description ( 'Manage configuration' )
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
config
. command ( 'set <key> <value>' )
. description ( 'Set configuration value' )
. option ( '-e, --encrypt' , 'Encrypt this value' )
. action ( wrapAction ( async ( key , value , options ) => {
await cortex . configSet ( key , value , options )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
config
. command ( 'get <key>' )
. description ( 'Get configuration value' )
. action ( wrapAction ( async ( key ) => {
const value = await cortex . configGet ( key )
if ( value ) {
console . log ( chalk . green ( ` ${ key } : ${ value } ` ) )
} else {
console . log ( chalk . yellow ( ` Key not found: ${ key } ` ) )
2025-08-07 19:33:03 -07:00
}
} ) )
2025-08-08 18:05:12 -07:00
config
. command ( 'list' )
. description ( 'List all configuration' )
2025-08-07 19:33:03 -07:00
. action ( wrapAction ( async ( ) => {
2025-08-08 18:05:12 -07:00
await cortex . configList ( )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
// ========================================
// LEGACY CORTEX COMMANDS (Backward Compatibility)
// ========================================
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
const cortexCmd = program . command ( 'cortex' )
2025-08-10 16:25:12 -07:00
. description ( 'Legacy Cortex commands (deprecated - use direct commands)' )
2025-08-07 19:33:03 -07:00
2025-08-08 18:05:12 -07:00
cortexCmd
. command ( 'chat [question]' )
2025-08-10 16:25:12 -07:00
. description ( 'Chat with your data' )
2025-08-08 18:05:12 -07:00
. action ( wrapInteractive ( async ( question ) => {
console . log ( chalk . yellow ( '⚠️ Deprecated: Use "brainy chat" instead' ) )
await cortex . chat ( question )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
cortexCmd
. command ( 'add [data]' )
2025-08-10 16:25:12 -07:00
. description ( 'Add data' )
2025-08-08 18:05:12 -07:00
. action ( wrapAction ( async ( data ) => {
console . log ( chalk . yellow ( '⚠️ Deprecated: Use "brainy add" instead' ) )
await cortex . add ( data , { } )
2025-08-07 19:33:03 -07:00
} ) )
2025-08-08 18:05:12 -07:00
// ========================================
// INTERACTIVE SHELL
// ========================================
2025-08-07 19:33:03 -07:00
program
. command ( 'shell' )
2025-08-10 16:25:12 -07:00
. description ( 'Interactive Brainy shell' )
2025-08-08 18:05:12 -07:00
. action ( wrapInteractive ( async ( ) => {
console . log ( chalk . cyan ( '🧠 Brainy Interactive Shell' ) )
2025-08-07 19:33:03 -07:00
console . log ( chalk . dim ( 'Type "help" for commands, "exit" to quit\n' ) )
await cortex . chat ( )
2025-08-08 18:05:12 -07:00
} ) )
2025-08-12 11:49:38 -07:00
// ========================================
// AUGMENTATION CONTROL COMMANDS
// ========================================
program
. command ( 'augment' )
. description ( 'List all augmentations with their status' )
. action ( wrapAction ( async ( ) => {
const { BrainyData } = await import ( '../dist/brainyData.js' )
const brainy = new BrainyData ( )
await brainy . init ( )
const augmentations = brainy . listAugmentations ( )
if ( augmentations . length === 0 ) {
console . log ( chalk . yellow ( 'No augmentations registered' ) )
return
}
console . log ( chalk . cyan ( '🔧 Augmentations Status\n' ) )
const grouped = augmentations . reduce ( ( acc , aug ) => {
if ( ! acc [ aug . type ] ) acc [ aug . type ] = [ ]
acc [ aug . type ] . push ( aug )
return acc
} , { } )
for ( const [ type , augs ] of Object . entries ( grouped ) ) {
console . log ( chalk . bold ( ` ${ type . toUpperCase ( ) } : ` ) )
for ( const aug of augs ) {
const status = aug . enabled ? chalk . green ( '✅ enabled' ) : chalk . red ( '❌ disabled' )
console . log ( ` ${ aug . name } - ${ status } ` )
console . log ( chalk . dim ( ` ${ aug . description } ` ) )
}
console . log ( '' )
}
} ) )
program
. command ( 'augment enable <name>' )
. description ( 'Enable an augmentation by name' )
. action ( wrapAction ( async ( name ) => {
const { BrainyData } = await import ( '../dist/brainyData.js' )
const brainy = new BrainyData ( )
await brainy . init ( )
const success = brainy . enableAugmentation ( name )
if ( success ) {
console . log ( chalk . green ( ` ✅ Enabled augmentation: ${ name } ` ) )
} else {
console . log ( chalk . red ( ` ❌ Augmentation not found: ${ name } ` ) )
console . log ( chalk . dim ( 'Use "brainy augment" to see available augmentations' ) )
}
} ) )
program
. command ( 'augment disable <name>' )
. description ( 'Disable an augmentation by name' )
. action ( wrapAction ( async ( name ) => {
const { BrainyData } = await import ( '../dist/brainyData.js' )
const brainy = new BrainyData ( )
await brainy . init ( )
const success = brainy . disableAugmentation ( name )
if ( success ) {
console . log ( chalk . green ( ` ✅ Disabled augmentation: ${ name } ` ) )
} else {
console . log ( chalk . red ( ` ❌ Augmentation not found: ${ name } ` ) )
console . log ( chalk . dim ( 'Use "brainy augment" to see available augmentations' ) )
}
} ) )
program
. command ( 'augment status <name>' )
. description ( 'Check if an augmentation is enabled' )
. action ( wrapAction ( async ( name ) => {
const { BrainyData } = await import ( '../dist/brainyData.js' )
const brainy = new BrainyData ( )
await brainy . init ( )
const enabled = brainy . isAugmentationEnabled ( name )
if ( enabled !== undefined ) {
const status = enabled ? chalk . green ( '✅ enabled' ) : chalk . red ( '❌ disabled' )
console . log ( ` ${ name } : ${ status } ` )
} else {
console . log ( chalk . red ( ` ❌ Augmentation not found: ${ name } ` ) )
console . log ( chalk . dim ( 'Use "brainy augment" to see available augmentations' ) )
}
} ) )
2025-08-08 18:05:12 -07:00
// ========================================
// PARSE AND HANDLE
// ========================================
2025-08-07 19:33:03 -07:00
program . parse ( process . argv )
// Show help if no command
if ( ! process . argv . slice ( 2 ) . length ) {
2025-08-10 16:25:12 -07:00
console . log ( chalk . cyan ( '🧠 Brainy - Multi-Dimensional AI Database' ) )
console . log ( chalk . gray ( 'Vector similarity, graph relationships, metadata facets, and AI context.\n' ) )
2025-08-08 18:05:12 -07:00
console . log ( chalk . bold ( 'Quick Start:' ) )
console . log ( ' brainy init # Initialize project' )
2025-08-10 16:25:12 -07:00
console . log ( ' brainy add "some data" # Add multi-dimensional data' )
console . log ( ' brainy search "query" # Search across all dimensions' )
2025-08-12 11:49:38 -07:00
console . log ( ' brainy chat # 🧠 Magical AI chat with perfect memory' )
console . log ( '' )
console . log ( chalk . bold ( 'Chat & Memory:' ) )
console . log ( ' brainy chat # Interactive chat with local memory' )
console . log ( ' brainy chat "question" # Single question with context' )
console . log ( ' brainy chat --list # List all chat sessions' )
console . log ( ' brainy chat --search "query" # Search all conversations' )
console . log ( ' brainy chat --history # Show conversation history' )
2025-08-10 16:25:12 -07:00
console . log ( '' )
2025-08-11 13:02:29 -07:00
console . log ( chalk . bold ( 'Brain Cloud (Premium):' ) )
console . log ( chalk . green ( ' brainy cloud setup # Auto-setup with provisioning' ) )
console . log ( ' brainy cloud connect <id> # Connect to existing instance' )
console . log ( ' brainy cloud dashboard # Open Brain Cloud dashboard' )
2025-08-08 18:05:12 -07:00
console . log ( '' )
console . log ( chalk . bold ( 'AI Coordination:' ) )
2025-08-10 16:25:12 -07:00
console . log ( ' brainy install brain-jar # Install coordination' )
2025-08-08 18:05:12 -07:00
console . log ( ' brainy brain-jar start # Start coordination' )
2025-08-10 16:25:12 -07:00
console . log ( '' )
console . log ( chalk . dim ( 'Learn more: https://soulcraft.com' ) )
2025-08-08 18:05:12 -07:00
console . log ( '' )
2025-08-07 19:33:03 -07:00
program . outputHelp ( )
2025-08-09 18:27:21 -07:00
}
// ========================================
// BRAIN CLOUD MEMORY SETUP FUNCTIONS
// ========================================
async function detectCustomerId ( ) {
try {
// Method 1: Check for existing brainy config
const { readFile } = await import ( 'fs/promises' )
const { join } = await import ( 'path' )
try {
const configPath = join ( process . cwd ( ) , 'brainy-config.json' )
const config = JSON . parse ( await readFile ( configPath , 'utf8' ) )
if ( config . brainCloudCustomerId ) {
return config . brainCloudCustomerId
}
} catch { }
// Method 2: Check CLAUDE.md for existing customer ID
try {
const claudePath = join ( process . cwd ( ) , 'CLAUDE.md' )
const claudeContent = await readFile ( claudePath , 'utf8' )
const match = claudeContent . match ( /customer.*?([a-z0-9-]+)/i )
if ( match ) return match [ 1 ]
} catch { }
// Method 3: Test common demo IDs
const testIds = [ 'demo-test-auto' , 'demo-test123' ]
for ( const id of testIds ) {
try {
2025-08-12 07:52:11 -07:00
const response = await fetch ( ` https://api.soulcraft.com/brain-cloud/health ` , {
2025-08-09 18:27:21 -07:00
headers : { 'x-customer-id' : id }
} )
if ( response . ok ) {
return id
}
} catch { }
}
return null
} catch ( error ) {
return null
}
}
async function setupBrainCloudMemory ( customerId ) {
const { writeFile , mkdir } = await import ( 'fs/promises' )
const { join } = await import ( 'path' )
console . log ( chalk . gray ( '📝 Setting up AI memory configuration...' ) )
// 1. Create/update .claude directory and MCP config
try {
await mkdir ( '.claude' , { recursive : true } )
const mcpConfig = {
mcpServers : {
"brain-cloud" : {
command : "node" ,
args : [ "brainy-mcp-server.js" ] ,
env : {
CUSTOMER _ID : customerId ,
2025-08-12 07:52:11 -07:00
BRAIN _CLOUD _URL : "https://api.soulcraft.com/brain-cloud"
2025-08-09 18:27:21 -07:00
}
}
}
}
await writeFile ( '.claude/mcp_servers.json' , JSON . stringify ( mcpConfig , null , 2 ) )
console . log ( chalk . green ( '✅ MCP configuration updated' ) )
} catch ( error ) {
console . log ( chalk . yellow ( '⚠️ Could not update MCP config:' , error . message ) )
}
// 2. Create/update CLAUDE.md with natural language instructions
const claudeContent = ` # 🧠 I Remember Everything Now!
Hi ! I ' m connected to your Brain Cloud ( $ { customerId } ) so I actually remember our conversations across sessions .
# # Try Saying :
- "What did we build together?"
- "Remember that React project?"
- "Show me what we worked on yesterday"
- "Find my notes about APIs"
- "Search for that bug we fixed"
# # I Can Also :
- Remember context from weeks ago
- Work with other AI assistants who share the same memory
- Keep everything synced across your devices
- Search through all our conversations
# # Multi - AI Coordination :
When working with multiple AI assistants , we automatically coordinate :
- * * Jarvis * * ( Backend ) : APIs , databases , deployment
- * * Picasso * * ( Design ) : UI , themes , visual elements
- * * Claude * * ( Planning ) : Coordination , architecture , strategy
* * Just talk to me normally - no commands needed ! * *
-- -
* Brain Cloud Instance : $ { customerId } *
* Last Updated : $ { new Date ( ) . toLocaleDateString ( ) } *
`
try {
await writeFile ( 'CLAUDE.md' , claudeContent )
console . log ( chalk . green ( '✅ CLAUDE.md updated with memory instructions' ) )
} catch ( error ) {
console . log ( chalk . yellow ( '⚠️ Could not update CLAUDE.md:' , error . message ) )
}
// 3. Save customer ID to brainy config
try {
const brainyConfig = {
brainCloudCustomerId : customerId ,
2025-08-12 07:52:11 -07:00
brainCloudUrl : 'https://api.soulcraft.com/brain-cloud' ,
2025-08-09 18:27:21 -07:00
lastConnected : new Date ( ) . toISOString ( )
}
await writeFile ( 'brainy-config.json' , JSON . stringify ( brainyConfig , null , 2 ) )
console . log ( chalk . green ( '✅ Brainy configuration saved' ) )
} catch ( error ) {
console . log ( chalk . yellow ( '⚠️ Could not save brainy config:' , error . message ) )
}
2025-08-11 13:02:29 -07:00
}
// ========================================
// AUTO-SETUP HELPER FUNCTIONS
// ========================================
const PROVISIONING _API = 'https://provisioning.soulcraft.com'
let spinner = null
function startSpinner ( message ) {
stopSpinner ( )
process . stdout . write ( ` ${ message } ` )
const spinnerChars = [ '⠋' , '⠙' , '⠹' , '⠸' , '⠼' , '⠴' , '⠦' , '⠧' , '⠇' , '⠏' ]
let i = 0
spinner = setInterval ( ( ) => {
process . stdout . write ( ` \r ${ message } ${ spinnerChars [ i ] } ` )
i = ( i + 1 ) % spinnerChars . length
} , 100 )
}
function stopSpinner ( ) {
if ( spinner ) {
clearInterval ( spinner )
spinner = null
process . stdout . write ( '\r' )
}
}
async function validateLicense ( ) {
startSpinner ( 'Validating Early Access license...' )
const licenseKey = process . env . BRAINY _LICENSE _KEY
if ( ! licenseKey ) {
stopSpinner ( )
console . log ( '\n❌ No license key found' )
console . log ( '\n🔑 Please set your Early Access license key:' )
console . log ( ' export BRAINY_LICENSE_KEY="lic_early_access_your_key"' )
console . log ( '\n📝 Don\'t have a key? Get one free at: https://soulcraft.com/brain-cloud' )
throw new Error ( 'License key required' )
}
if ( ! licenseKey . startsWith ( 'lic_early_access_' ) ) {
stopSpinner ( )
throw new Error ( 'Invalid license key format. Early Access keys start with "lic_early_access_"' )
}
stopSpinner ( )
console . log ( '✅ License validated' )
}
async function ensureBrainyInstalled ( ) {
startSpinner ( 'Checking Brainy installation...' )
try {
const { exec } = await import ( 'child_process' )
const { promisify } = await import ( 'util' )
const execAsync = promisify ( exec )
await execAsync ( 'brainy --version' )
stopSpinner ( )
console . log ( '✅ Brainy CLI found' )
} catch ( error ) {
stopSpinner ( )
console . log ( '📦 Installing Brainy CLI...' )
try {
await execWithProgress ( 'npm install -g @soulcraft/brainy' )
console . log ( '✅ Brainy CLI installed' )
} catch ( installError ) {
throw new Error ( 'Failed to install Brainy CLI. Please install manually: npm install -g @soulcraft/brainy' )
}
}
}
async function provisionCloudInstance ( userEmail ) {
const licenseKey = process . env . BRAINY _LICENSE _KEY
startSpinner ( 'Provisioning your cloud Brainy instance...' )
try {
const response = await fetch ( ` ${ PROVISIONING _API } /provision ` , {
method : 'POST' ,
headers : {
'Content-Type' : 'application/json'
} ,
body : JSON . stringify ( {
licenseKey ,
userEmail : userEmail || 'user@example.com'
} )
} )
if ( ! response . ok ) {
const error = await response . json ( )
throw new Error ( error . message || 'Provisioning failed' )
}
const result = await response . json ( )
stopSpinner ( )
if ( result . instance . status === 'active' ) {
console . log ( '✅ Cloud instance already active' )
return result . instance
}
console . log ( '🚀 Provisioning started (2-3 minutes)' )
// Wait for provisioning to complete
return await waitForProvisioning ( licenseKey )
} catch ( error ) {
stopSpinner ( )
throw new Error ( ` Provisioning failed: ${ error . message } ` )
}
}
async function waitForProvisioning ( licenseKey ) {
const maxWaitTime = 5 * 60 * 1000 // 5 minutes
const checkInterval = 15 * 1000 // 15 seconds
const startTime = Date . now ( )
while ( Date . now ( ) - startTime < maxWaitTime ) {
startSpinner ( 'Waiting for cloud instance to be ready...' )
try {
const response = await fetch ( ` ${ PROVISIONING _API } /status?licenseKey= ${ encodeURIComponent ( licenseKey ) } ` )
if ( response . ok ) {
const result = await response . json ( )
if ( result . instance . status === 'active' ) {
stopSpinner ( )
console . log ( '✅ Cloud instance is ready' )
return result . instance
}
if ( result . instance . status === 'failed' ) {
stopSpinner ( )
throw new Error ( 'Instance provisioning failed' )
}
}
stopSpinner ( )
await new Promise ( resolve => setTimeout ( resolve , checkInterval ) )
} catch ( error ) {
stopSpinner ( )
console . log ( '⏳ Still provisioning...' )
await new Promise ( resolve => setTimeout ( resolve , checkInterval ) )
}
}
throw new Error ( 'Provisioning timeout. Please check your dashboard or contact support.' )
}
async function configureBrainy ( instance ) {
const { writeFile , mkdir } = await import ( 'fs/promises' )
const { join } = await import ( 'path' )
const { homedir } = await import ( 'os' )
const { existsSync } = await import ( 'fs' )
startSpinner ( 'Configuring local Brainy to use cloud instance...' )
// Ensure config directory exists
const BRAINY _CONFIG _DIR = join ( homedir ( ) , '.brainy' )
const BRAINY _CONFIG _FILE = join ( BRAINY _CONFIG _DIR , 'config.json' )
if ( ! existsSync ( BRAINY _CONFIG _DIR ) ) {
await mkdir ( BRAINY _CONFIG _DIR , { recursive : true } )
}
// Create or update Brainy config
let config = { }
if ( existsSync ( BRAINY _CONFIG _FILE ) ) {
try {
const { readFile } = await import ( 'fs/promises' )
const existing = await readFile ( BRAINY _CONFIG _FILE , 'utf8' )
config = JSON . parse ( existing )
} catch ( error ) {
console . log ( '⚠️ Could not read existing config, creating new one' )
}
}
// Update config with cloud instance details
config . cloudSync = {
enabled : true ,
endpoint : instance . endpoints . api ,
instanceId : instance . id ,
licenseKey : process . env . BRAINY _LICENSE _KEY
}
config . aiMemory = {
enabled : true ,
storage : 'cloud' ,
endpoint : instance . endpoints . api
}
config . agentCoordination = {
enabled : true ,
endpoint : instance . endpoints . api
}
await writeFile ( BRAINY _CONFIG _FILE , JSON . stringify ( config , null , 2 ) )
stopSpinner ( )
console . log ( '✅ Local Brainy configured for cloud sync' )
}
async function installBrainCloudPackage ( ) {
startSpinner ( 'Installing Brain Cloud augmentations...' )
try {
const { existsSync } = await import ( 'fs' )
// Check if we're in a project directory
const hasPackageJson = existsSync ( 'package.json' )
if ( hasPackageJson ) {
2025-08-12 09:03:36 -07:00
// Auto-configured with 'brainy cloud auth' - no package installation needed!
2025-08-11 13:02:29 -07:00
console . log ( '✅ Brain Cloud package installed in current project' )
} else {
// Install globally for non-project usage
2025-08-12 09:03:36 -07:00
console . log ( '✅ Run \'brainy cloud auth\' to authenticate and auto-configure' )
2025-08-11 13:02:29 -07:00
console . log ( '✅ Brain Cloud package installed globally' )
}
} catch ( error ) {
stopSpinner ( )
console . log ( '⚠️ Could not auto-install Brain Cloud package' )
2025-08-12 09:03:36 -07:00
console . log ( ' Authenticate manually: brainy cloud auth' )
2025-08-11 13:02:29 -07:00
// Don't throw error, this is optional
}
}
async function testConnection ( instance ) {
startSpinner ( 'Testing cloud connection...' )
try {
const response = await fetch ( ` ${ instance . endpoints . api } /health ` )
if ( response . ok ) {
const health = await response . json ( )
stopSpinner ( )
console . log ( '✅ Cloud instance connection verified' )
// Test memory storage
const testMemory = {
content : 'Test memory from auto-setup' ,
source : 'brain-cloud-setup' ,
importance : 'low' ,
tags : [ 'setup' , 'test' ]
}
const memoryResponse = await fetch ( ` ${ instance . endpoints . api } /api/memories ` , {
method : 'POST' ,
headers : { 'Content-Type' : 'application/json' } ,
body : JSON . stringify ( testMemory )
} )
if ( memoryResponse . ok ) {
console . log ( '✅ Memory storage working' )
}
} else {
stopSpinner ( )
console . log ( '⚠️ Cloud instance not responding yet (this is normal)' )
console . log ( ' Your instance may need a few more minutes to fully initialize' )
}
} catch ( error ) {
stopSpinner ( )
console . log ( '⚠️ Could not test connection (this is usually fine)' )
}
}
async function execWithProgress ( command ) {
const { spawn } = await import ( 'child_process' )
return new Promise ( ( resolve , reject ) => {
const child = spawn ( 'sh' , [ '-c' , command ] , {
stdio : [ 'inherit' , 'pipe' , 'pipe' ] ,
shell : true
} )
let stdout = ''
let stderr = ''
child . stdout ? . on ( 'data' , ( data ) => {
stdout += data . toString ( )
process . stdout . write ( '.' )
} )
child . stderr ? . on ( 'data' , ( data ) => {
stderr += data . toString ( )
} )
child . on ( 'close' , ( code ) => {
process . stdout . write ( '\n' )
if ( code === 0 ) {
resolve ( stdout )
} else {
reject ( new Error ( stderr || ` Command failed with code ${ code } ` ) )
}
} )
} )
2025-08-07 19:33:03 -07:00
}