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-10 16:25:12 -07:00
. description ( 'Add data across multiple dimensions (vector, graph, facets)' )
. option ( '-m, --metadata <json>' , 'Metadata facets as JSON' )
2025-08-07 19:33:03 -07:00
. option ( '-i, --id <id>' , 'Custom ID' )
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
}
await cortex . add ( 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-10 16:25:12 -07:00
. description ( 'AI-powered chat with multi-dimensional context' )
2025-08-08 18:05:12 -07:00
. option ( '-l, --llm <model>' , 'LLM model to use' )
. action ( wrapInteractive ( async ( question , options ) => {
await cortex . chat ( question )
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-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:' ) )
console . log ( '\n1. Visit: ' + chalk . cyan ( 'https://soulcraft.com' ) )
console . log ( '2. Sign up for Brain Cloud' )
2025-08-09 18:27:21 -07:00
console . log ( '3. Run ' + chalk . green ( 'brainy connect' ) + ' again' )
}
} catch ( error ) {
console . log ( chalk . red ( '❌ Setup failed:' ) , error . message )
}
} ) )
2025-08-09 14:36:05 -07:00
program
. command ( 'cloud [action]' )
2025-08-10 16:25:12 -07:00
. description ( 'Manage Brain Cloud connection' )
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 ) => {
// 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
const healthUrl = ` https://brain-cloud.dpsifr.workers.dev/health `
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
const memoriesResponse = await fetch ( ` https://brain-cloud.dpsifr.workers.dev/memories ` , {
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 {
const response = await fetch ( ` https://brain-cloud.dpsifr.workers.dev/export ` , {
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 {
const response = await fetch ( ` https://brain-cloud.dpsifr.workers.dev/health ` , {
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
const memoriesResponse = await fetch ( ` https://brain-cloud.dpsifr.workers.dev/memories ` , {
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
program
2025-08-08 18:05:12 -07:00
. command ( 'install <augmentation>' )
2025-08-10 16:25:12 -07:00
. description ( 'Install augmentation' )
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 ) => {
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-10 16:25:12 -07:00
console . log ( chalk . cyan ( 'Available Augmentations:' ) )
2025-08-08 18:05:12 -07:00
console . log ( ' • brain-jar - AI coordination and collaboration' )
console . log ( ' • encryption - Data encryption and security' )
console . log ( ' • neural-import - AI-powered data analysis' )
console . log ( ' • performance-monitor - System monitoring' )
console . log ( '' )
console . log ( chalk . dim ( 'Install: brainy install <augmentation>' ) )
} 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
} ) )
// ========================================
// 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' )
console . log ( ' brainy chat # AI chat with full context' )
console . log ( '' )
console . log ( chalk . bold ( 'AI Memory:' ) )
console . log ( chalk . green ( ' brainy connect # Connect to Brain Cloud' ) )
console . log ( ' brainy cloud --status <id> # Check cloud status' )
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 {
const response = await fetch ( ` https://brain-cloud.dpsifr.workers.dev/health ` , {
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 ,
BRAIN _CLOUD _URL : "https://brain-cloud.dpsifr.workers.dev"
}
}
}
}
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 ,
brainCloudUrl : 'https://brain-cloud.dpsifr.workers.dev' ,
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-07 19:33:03 -07:00
}