@soulcraft/brainy 0.58.1 → 0.59.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/brainy.js +282 -2
  2. package/package.json +2 -2
package/bin/brainy.js CHANGED
@@ -14,6 +14,8 @@ import { readFileSync } from 'fs'
14
14
  import { dirname, join } from 'path'
15
15
  import { fileURLToPath } from 'url'
16
16
 
17
+ // Use native fetch (available in Node.js 18+)
18
+
17
19
  const __dirname = dirname(fileURLToPath(import.meta.url))
18
20
  const packageJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'))
19
21
 
@@ -177,10 +179,51 @@ program
177
179
  // BRAIN CLOUD INTEGRATION
178
180
  // ========================================
179
181
 
182
+ program
183
+ .command('connect')
184
+ .description('šŸ”— Connect me to your Brain Cloud so I remember everything')
185
+ .action(wrapInteractive(async () => {
186
+ console.log(chalk.cyan('\n🧠 Setting Up AI Memory...'))
187
+ console.log(chalk.gray('━'.repeat(50)))
188
+
189
+ try {
190
+ // Detect customer ID
191
+ const customerId = await detectCustomerId()
192
+
193
+ if (customerId) {
194
+ console.log(chalk.green(`āœ… Found your Brain Cloud: ${customerId}`))
195
+ console.log('\nšŸ”§ I can set up AI memory so I remember our conversations:')
196
+ console.log(chalk.yellow(' • Update Claude configuration'))
197
+ console.log(chalk.yellow(' • Add memory instructions'))
198
+ console.log(chalk.yellow(' • Enable cross-session memory'))
199
+
200
+ // For now, auto-proceed (in a real CLI environment, user could be prompted)
201
+ console.log(chalk.cyan('\nšŸš€ Setting up AI memory...'))
202
+ const proceed = true
203
+
204
+ if (proceed) {
205
+ await setupBrainCloudMemory(customerId)
206
+ console.log(chalk.green('\nšŸŽ‰ AI Memory Connected!'))
207
+ console.log(chalk.cyan('Restart Claude Code and I\'ll remember everything!'))
208
+ }
209
+ } else {
210
+ console.log(chalk.yellow('šŸ¤” No Brain Cloud found. Let me help you set one up:'))
211
+ console.log('\n1. Visit: ' + chalk.cyan('https://app.soulcraftlabs.com'))
212
+ console.log('2. Sign up for Brain Cloud ($19/month)')
213
+ console.log('3. Run ' + chalk.green('brainy connect') + ' again')
214
+ }
215
+ } catch (error) {
216
+ console.log(chalk.red('āŒ Setup failed:'), error.message)
217
+ }
218
+ }))
219
+
180
220
  program
181
221
  .command('cloud [action]')
182
222
  .description('ā˜ļø Connect to Brain Cloud - AI memory that never forgets')
183
223
  .option('--connect <id>', 'Connect to existing Brain Cloud instance')
224
+ .option('--export <id>', 'Export all data from Brain Cloud instance')
225
+ .option('--status <id>', 'Check status of Brain Cloud instance')
226
+ .option('--dashboard <id>', 'Open dashboard for Brain Cloud instance')
184
227
  .option('--migrate', 'Migrate between local and cloud')
185
228
  .action(wrapInteractive(async (action, options) => {
186
229
  // For now, show connection instructions
@@ -189,8 +232,118 @@ program
189
232
 
190
233
  if (options.connect) {
191
234
  console.log(chalk.green(`āœ… Connecting to Brain Cloud instance: ${options.connect}`))
192
- console.log(chalk.yellow('\nNote: Full cloud integration coming soon!'))
193
- console.log('\nFor now, visit: ' + chalk.cyan('https://app.soulcraftlabs.com'))
235
+
236
+ try {
237
+ // Test connection to Brain Cloud worker
238
+ const healthUrl = `https://brain-cloud.dpsifr.workers.dev/health`
239
+ const response = await fetch(healthUrl, {
240
+ headers: { 'x-customer-id': options.connect }
241
+ })
242
+
243
+ if (response.ok) {
244
+ const data = await response.json()
245
+ console.log(chalk.green(`🧠 ${data.status}`))
246
+ console.log(chalk.cyan(`šŸ’« Instance: ${data.customerId}`))
247
+ console.log(chalk.gray(`ā° Connected at: ${new Date(data.timestamp).toLocaleString()}`))
248
+
249
+ // Test memories endpoint
250
+ const memoriesResponse = await fetch(`https://brain-cloud.dpsifr.workers.dev/memories`, {
251
+ headers: { 'x-customer-id': options.connect }
252
+ })
253
+
254
+ if (memoriesResponse.ok) {
255
+ const memoriesData = await memoriesResponse.json()
256
+ console.log(chalk.yellow(`\n${memoriesData.message}`))
257
+ console.log(chalk.gray('šŸ“Š Your atomic memories:'))
258
+ memoriesData.memories.forEach(memory => {
259
+ const time = new Date(memory.created).toLocaleString()
260
+ console.log(chalk.gray(` • ${memory.content} (${time})`))
261
+ })
262
+ }
263
+
264
+ } else {
265
+ console.log(chalk.red('āŒ Could not connect to Brain Cloud'))
266
+ console.log(chalk.yellow('šŸ’” Make sure you have an active instance'))
267
+ console.log('\nSign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
268
+ }
269
+ } catch (error) {
270
+ console.log(chalk.red('āŒ Connection failed:'), error.message)
271
+ console.log('\nSign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
272
+ }
273
+ } else if (options.export) {
274
+ console.log(chalk.green(`šŸ“¦ Exporting data from Brain Cloud instance: ${options.export}`))
275
+
276
+ try {
277
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/export`, {
278
+ headers: { 'x-customer-id': options.export }
279
+ })
280
+
281
+ if (response.ok) {
282
+ const data = await response.json()
283
+ const filename = `brainy-export-${options.export}-${Date.now()}.json`
284
+
285
+ // Write to file
286
+ const fs = await import('fs/promises')
287
+ await fs.writeFile(filename, JSON.stringify(data, null, 2))
288
+
289
+ console.log(chalk.green(`āœ… Data exported to: ${filename}`))
290
+ console.log(chalk.gray(`šŸ“Š Exported ${data.memories?.length || 0} memories`))
291
+ } else {
292
+ console.log(chalk.red('āŒ Export failed - instance not found'))
293
+ }
294
+ } catch (error) {
295
+ console.log(chalk.red('āŒ Export error:'), error.message)
296
+ }
297
+ } else if (options.status) {
298
+ console.log(chalk.green(`šŸ” Checking status of Brain Cloud instance: ${options.status}`))
299
+
300
+ try {
301
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/health`, {
302
+ headers: { 'x-customer-id': options.status }
303
+ })
304
+
305
+ if (response.ok) {
306
+ const data = await response.json()
307
+ console.log(chalk.green(`āœ… Instance Status: Active`))
308
+ console.log(chalk.cyan(`🧠 ${data.status}`))
309
+ console.log(chalk.gray(`ā° Last check: ${new Date(data.timestamp).toLocaleString()}`))
310
+
311
+ // Get memory count
312
+ const memoriesResponse = await fetch(`https://brain-cloud.dpsifr.workers.dev/memories`, {
313
+ headers: { 'x-customer-id': options.status }
314
+ })
315
+
316
+ if (memoriesResponse.ok) {
317
+ const memoriesData = await memoriesResponse.json()
318
+ console.log(chalk.yellow(`šŸ“Š Total memories: ${memoriesData.count}`))
319
+ }
320
+ } else {
321
+ console.log(chalk.red('āŒ Instance not found or inactive'))
322
+ }
323
+ } catch (error) {
324
+ console.log(chalk.red('āŒ Status check failed:'), error.message)
325
+ }
326
+ } else if (options.dashboard) {
327
+ console.log(chalk.green(`🌐 Opening dashboard for Brain Cloud instance: ${options.dashboard}`))
328
+
329
+ const dashboardUrl = `https://app.soulcraftlabs.com/dashboard.html?customer_id=${options.dashboard}`
330
+ console.log(chalk.cyan(`\nšŸ”— Dashboard URL: ${dashboardUrl}`))
331
+ console.log(chalk.gray('Opening in your default browser...'))
332
+
333
+ try {
334
+ const { exec } = await import('child_process')
335
+ const { promisify } = await import('util')
336
+ const execAsync = promisify(exec)
337
+
338
+ // Cross-platform browser opening
339
+ const command = process.platform === 'win32' ? 'start' :
340
+ process.platform === 'darwin' ? 'open' : 'xdg-open'
341
+
342
+ await execAsync(`${command} "${dashboardUrl}"`)
343
+ console.log(chalk.green('āœ… Dashboard opened!'))
344
+ } catch (error) {
345
+ console.log(chalk.yellow('šŸ’” Copy the URL above to open in your browser'))
346
+ }
194
347
  } else {
195
348
  console.log(chalk.yellow('šŸ“” Brain Cloud Setup'))
196
349
  console.log('\n1. Sign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
@@ -460,4 +613,131 @@ if (!process.argv.slice(2).length) {
460
613
  console.log(' brainy brain-jar dashboard # View dashboard')
461
614
  console.log('')
462
615
  program.outputHelp()
616
+ }
617
+
618
+ // ========================================
619
+ // BRAIN CLOUD MEMORY SETUP FUNCTIONS
620
+ // ========================================
621
+
622
+ async function detectCustomerId() {
623
+ try {
624
+ // Method 1: Check for existing brainy config
625
+ const { readFile } = await import('fs/promises')
626
+ const { join } = await import('path')
627
+
628
+ try {
629
+ const configPath = join(process.cwd(), 'brainy-config.json')
630
+ const config = JSON.parse(await readFile(configPath, 'utf8'))
631
+ if (config.brainCloudCustomerId) {
632
+ return config.brainCloudCustomerId
633
+ }
634
+ } catch {}
635
+
636
+ // Method 2: Check CLAUDE.md for existing customer ID
637
+ try {
638
+ const claudePath = join(process.cwd(), 'CLAUDE.md')
639
+ const claudeContent = await readFile(claudePath, 'utf8')
640
+ const match = claudeContent.match(/customer.*?([a-z0-9-]+)/i)
641
+ if (match) return match[1]
642
+ } catch {}
643
+
644
+ // Method 3: Test common demo IDs
645
+ const testIds = ['demo-test-auto', 'demo-test123']
646
+ for (const id of testIds) {
647
+ try {
648
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/health`, {
649
+ headers: { 'x-customer-id': id }
650
+ })
651
+ if (response.ok) {
652
+ return id
653
+ }
654
+ } catch {}
655
+ }
656
+
657
+ return null
658
+ } catch (error) {
659
+ return null
660
+ }
661
+ }
662
+
663
+ async function setupBrainCloudMemory(customerId) {
664
+ const { writeFile, mkdir } = await import('fs/promises')
665
+ const { join } = await import('path')
666
+
667
+ console.log(chalk.gray('šŸ“ Setting up AI memory configuration...'))
668
+
669
+ // 1. Create/update .claude directory and MCP config
670
+ try {
671
+ await mkdir('.claude', { recursive: true })
672
+
673
+ const mcpConfig = {
674
+ mcpServers: {
675
+ "brain-cloud": {
676
+ command: "node",
677
+ args: ["brainy-mcp-server.js"],
678
+ env: {
679
+ CUSTOMER_ID: customerId,
680
+ BRAIN_CLOUD_URL: "https://brain-cloud.dpsifr.workers.dev"
681
+ }
682
+ }
683
+ }
684
+ }
685
+
686
+ await writeFile('.claude/mcp_servers.json', JSON.stringify(mcpConfig, null, 2))
687
+ console.log(chalk.green('āœ… MCP configuration updated'))
688
+ } catch (error) {
689
+ console.log(chalk.yellow('āš ļø Could not update MCP config:', error.message))
690
+ }
691
+
692
+ // 2. Create/update CLAUDE.md with natural language instructions
693
+ const claudeContent = `# 🧠 I Remember Everything Now!
694
+
695
+ Hi! I'm connected to your Brain Cloud (${customerId}) so I actually remember our conversations across sessions.
696
+
697
+ ## Try Saying:
698
+ - "What did we build together?"
699
+ - "Remember that React project?"
700
+ - "Show me what we worked on yesterday"
701
+ - "Find my notes about APIs"
702
+ - "Search for that bug we fixed"
703
+
704
+ ## I Can Also:
705
+ - Remember context from weeks ago
706
+ - Work with other AI assistants who share the same memory
707
+ - Keep everything synced across your devices
708
+ - Search through all our conversations
709
+
710
+ ## Multi-AI Coordination:
711
+ When working with multiple AI assistants, we automatically coordinate:
712
+ - **Jarvis** (Backend): APIs, databases, deployment
713
+ - **Picasso** (Design): UI, themes, visual elements
714
+ - **Claude** (Planning): Coordination, architecture, strategy
715
+
716
+ **Just talk to me normally - no commands needed!**
717
+
718
+ ---
719
+ *Brain Cloud Instance: ${customerId}*
720
+ *Last Updated: ${new Date().toLocaleDateString()}*
721
+ `
722
+
723
+ try {
724
+ await writeFile('CLAUDE.md', claudeContent)
725
+ console.log(chalk.green('āœ… CLAUDE.md updated with memory instructions'))
726
+ } catch (error) {
727
+ console.log(chalk.yellow('āš ļø Could not update CLAUDE.md:', error.message))
728
+ }
729
+
730
+ // 3. Save customer ID to brainy config
731
+ try {
732
+ const brainyConfig = {
733
+ brainCloudCustomerId: customerId,
734
+ brainCloudUrl: 'https://brain-cloud.dpsifr.workers.dev',
735
+ lastConnected: new Date().toISOString()
736
+ }
737
+
738
+ await writeFile('brainy-config.json', JSON.stringify(brainyConfig, null, 2))
739
+ console.log(chalk.green('āœ… Brainy configuration saved'))
740
+ } catch (error) {
741
+ console.log(chalk.yellow('āš ļø Could not save brainy config:', error.message))
742
+ }
463
743
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soulcraft/brainy",
3
- "version": "0.58.1",
3
+ "version": "0.59.3",
4
4
  "description": "A vector graph database using HNSW indexing with Origin Private File System storage",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -201,7 +201,6 @@
201
201
  "express": "^5.1.0",
202
202
  "happy-dom": "^18.0.1",
203
203
  "jsdom": "^26.1.0",
204
- "node-fetch": "^3.3.2",
205
204
  "process": "^0.11.10",
206
205
  "puppeteer": "^22.15.0",
207
206
  "standard-version": "^9.5.0",
@@ -219,6 +218,7 @@
219
218
  "cli-table3": "^0.6.3",
220
219
  "commander": "^11.1.0",
221
220
  "dotenv": "^16.4.5",
221
+ "inquirer": "^12.9.1",
222
222
  "ora": "^8.0.1",
223
223
  "prompts": "^2.4.2",
224
224
  "uuid": "^9.0.1"