@soulcraft/brainy 0.58.0 → 0.59.0

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 (154) hide show
  1. package/bin/brainy.js +539 -387
  2. package/dist/augmentations/conduitAugmentations.js +1 -1
  3. package/dist/augmentations/conduitAugmentations.js.map +1 -1
  4. package/dist/augmentations/cortexSense.js +3 -3
  5. package/dist/augmentations/cortexSense.js.map +1 -1
  6. package/dist/brainyData.js +2 -1
  7. package/dist/brainyData.js.map +1 -1
  8. package/dist/browserFramework.minimal.d.ts +14 -0
  9. package/dist/browserFramework.minimal.js +31 -0
  10. package/dist/browserFramework.minimal.js.map +1 -0
  11. package/dist/cortex/backupRestore.js +2 -2
  12. package/dist/cortex/backupRestore.js.map +1 -1
  13. package/dist/cortex/cortex.d.ts +17 -2
  14. package/dist/cortex/cortex.js +262 -103
  15. package/dist/cortex/cortex.js.map +1 -1
  16. package/dist/cortex/neuralImport.js +2 -2
  17. package/dist/cortex/neuralImport.js.map +1 -1
  18. package/dist/cortex/serviceIntegration.js +2 -2
  19. package/dist/cortex/serviceIntegration.js.map +1 -1
  20. package/dist/distributed/configManager.js +1 -1
  21. package/dist/distributed/configManager.js.map +1 -1
  22. package/dist/index.d.ts +0 -1
  23. package/dist/index.js +2 -2
  24. package/dist/index.js.map +1 -1
  25. package/dist/mcp/brainyMCPAdapter.js +1 -1
  26. package/dist/mcp/brainyMCPAdapter.js.map +1 -1
  27. package/dist/mcp/brainyMCPBroadcast.d.ts +82 -0
  28. package/dist/mcp/brainyMCPBroadcast.js +303 -0
  29. package/dist/mcp/brainyMCPBroadcast.js.map +1 -0
  30. package/dist/mcp/brainyMCPClient.d.ts +92 -0
  31. package/dist/mcp/brainyMCPClient.js +254 -0
  32. package/dist/mcp/brainyMCPClient.js.map +1 -0
  33. package/dist/mcp/brainyMCPService.js +1 -1
  34. package/dist/mcp/brainyMCPService.js.map +1 -1
  35. package/dist/mcp/mcpAugmentationToolset.js +1 -1
  36. package/dist/mcp/mcpAugmentationToolset.js.map +1 -1
  37. package/dist/universal/crypto.d.ts +64 -0
  38. package/dist/universal/crypto.js +215 -0
  39. package/dist/universal/crypto.js.map +1 -0
  40. package/dist/universal/events.d.ts +31 -0
  41. package/dist/universal/events.js +156 -0
  42. package/dist/universal/events.js.map +1 -0
  43. package/dist/universal/fs.d.ts +102 -0
  44. package/dist/universal/fs.js +304 -0
  45. package/dist/universal/fs.js.map +1 -0
  46. package/dist/universal/index.d.ts +16 -0
  47. package/dist/universal/index.js +23 -0
  48. package/dist/universal/index.js.map +1 -0
  49. package/dist/universal/path.d.ts +51 -0
  50. package/dist/universal/path.js +161 -0
  51. package/dist/universal/path.js.map +1 -0
  52. package/dist/universal/uuid.d.ts +10 -0
  53. package/dist/universal/uuid.js +21 -0
  54. package/dist/universal/uuid.js.map +1 -0
  55. package/package.json +55 -2
  56. package/dist/augmentationFactory.d.ts.map +0 -1
  57. package/dist/augmentationPipeline.d.ts.map +0 -1
  58. package/dist/augmentationRegistry.d.ts.map +0 -1
  59. package/dist/augmentationRegistryLoader.d.ts.map +0 -1
  60. package/dist/augmentations/conduitAugmentations.d.ts.map +0 -1
  61. package/dist/augmentations/memoryAugmentations.d.ts.map +0 -1
  62. package/dist/augmentations/serverSearchAugmentations.d.ts.map +0 -1
  63. package/dist/brainyData.d.ts.map +0 -1
  64. package/dist/browserFramework.d.ts.map +0 -1
  65. package/dist/coreTypes.d.ts.map +0 -1
  66. package/dist/cortex/cli.d.ts +0 -8
  67. package/dist/cortex/cli.js +0 -207
  68. package/dist/cortex/cli.js.map +0 -1
  69. package/dist/cortex/commands/index.d.ts +0 -79
  70. package/dist/cortex/commands/index.js +0 -614
  71. package/dist/cortex/commands/index.js.map +0 -1
  72. package/dist/cortex/config.d.ts +0 -112
  73. package/dist/cortex/config.js +0 -312
  74. package/dist/cortex/config.js.map +0 -1
  75. package/dist/cortex/licensingSystem.d.ts +0 -126
  76. package/dist/cortex/licensingSystem.js +0 -474
  77. package/dist/cortex/licensingSystem.js.map +0 -1
  78. package/dist/cortex/webhookManager.d.ts +0 -39
  79. package/dist/cortex/webhookManager.js +0 -326
  80. package/dist/cortex/webhookManager.js.map +0 -1
  81. package/dist/demo.d.ts.map +0 -1
  82. package/dist/distributed/configManager.d.ts.map +0 -1
  83. package/dist/distributed/domainDetector.d.ts.map +0 -1
  84. package/dist/distributed/hashPartitioner.d.ts.map +0 -1
  85. package/dist/distributed/healthMonitor.d.ts.map +0 -1
  86. package/dist/distributed/index.d.ts.map +0 -1
  87. package/dist/distributed/operationalModes.d.ts.map +0 -1
  88. package/dist/errors/brainyError.d.ts.map +0 -1
  89. package/dist/examples/basicUsage.d.ts.map +0 -1
  90. package/dist/hnsw/distributedSearch.d.ts.map +0 -1
  91. package/dist/hnsw/hnswIndex.d.ts.map +0 -1
  92. package/dist/hnsw/hnswIndexOptimized.d.ts.map +0 -1
  93. package/dist/hnsw/optimizedHNSWIndex.d.ts.map +0 -1
  94. package/dist/hnsw/partitionedHNSWIndex.d.ts.map +0 -1
  95. package/dist/hnsw/scaledHNSWSystem.d.ts.map +0 -1
  96. package/dist/index.d.ts.map +0 -1
  97. package/dist/mcp/brainyMCPAdapter.d.ts.map +0 -1
  98. package/dist/mcp/brainyMCPService.d.ts.map +0 -1
  99. package/dist/mcp/index.d.ts.map +0 -1
  100. package/dist/mcp/mcpAugmentationToolset.d.ts.map +0 -1
  101. package/dist/pipeline.d.ts.map +0 -1
  102. package/dist/sequentialPipeline.d.ts.map +0 -1
  103. package/dist/setup.d.ts.map +0 -1
  104. package/dist/storage/adapters/baseStorageAdapter.d.ts.map +0 -1
  105. package/dist/storage/adapters/batchS3Operations.d.ts.map +0 -1
  106. package/dist/storage/adapters/fileSystemStorage.d.ts.map +0 -1
  107. package/dist/storage/adapters/memoryStorage.d.ts.map +0 -1
  108. package/dist/storage/adapters/opfsStorage.d.ts.map +0 -1
  109. package/dist/storage/adapters/optimizedS3Search.d.ts.map +0 -1
  110. package/dist/storage/adapters/s3CompatibleStorage.d.ts.map +0 -1
  111. package/dist/storage/baseStorage.d.ts.map +0 -1
  112. package/dist/storage/cacheManager.d.ts.map +0 -1
  113. package/dist/storage/enhancedCacheManager.d.ts.map +0 -1
  114. package/dist/storage/readOnlyOptimizations.d.ts.map +0 -1
  115. package/dist/storage/storageFactory.d.ts.map +0 -1
  116. package/dist/types/augmentations.d.ts.map +0 -1
  117. package/dist/types/brainyDataInterface.d.ts.map +0 -1
  118. package/dist/types/distributedTypes.d.ts.map +0 -1
  119. package/dist/types/fileSystemTypes.d.ts.map +0 -1
  120. package/dist/types/graphTypes.d.ts.map +0 -1
  121. package/dist/types/mcpTypes.d.ts.map +0 -1
  122. package/dist/types/paginationTypes.d.ts.map +0 -1
  123. package/dist/types/pipelineTypes.d.ts.map +0 -1
  124. package/dist/types/tensorflowTypes.d.ts +0 -26
  125. package/dist/types/tensorflowTypes.d.ts.map +0 -1
  126. package/dist/types/tensorflowTypes.js +0 -6
  127. package/dist/types/tensorflowTypes.js.map +0 -1
  128. package/dist/unified.d.ts.map +0 -1
  129. package/dist/utils/autoConfiguration.d.ts.map +0 -1
  130. package/dist/utils/cacheAutoConfig.d.ts.map +0 -1
  131. package/dist/utils/crypto.d.ts.map +0 -1
  132. package/dist/utils/distance.d.ts.map +0 -1
  133. package/dist/utils/embedding.d.ts.map +0 -1
  134. package/dist/utils/environment.d.ts.map +0 -1
  135. package/dist/utils/fieldNameTracking.d.ts.map +0 -1
  136. package/dist/utils/index.d.ts.map +0 -1
  137. package/dist/utils/jsonProcessing.d.ts.map +0 -1
  138. package/dist/utils/logger.d.ts.map +0 -1
  139. package/dist/utils/operationUtils.d.ts.map +0 -1
  140. package/dist/utils/robustModelLoader.d.ts +0 -112
  141. package/dist/utils/robustModelLoader.d.ts.map +0 -1
  142. package/dist/utils/robustModelLoader.js +0 -624
  143. package/dist/utils/robustModelLoader.js.map +0 -1
  144. package/dist/utils/searchCache.d.ts.map +0 -1
  145. package/dist/utils/statistics.d.ts.map +0 -1
  146. package/dist/utils/statisticsCollector.d.ts.map +0 -1
  147. package/dist/utils/textEncoding.d.ts.map +0 -1
  148. package/dist/utils/typeUtils.d.ts.map +0 -1
  149. package/dist/utils/version.d.ts.map +0 -1
  150. package/dist/utils/workerUtils.d.ts.map +0 -1
  151. package/dist/webhooks/webhookSystem.d.ts +0 -114
  152. package/dist/webhooks/webhookSystem.js +0 -321
  153. package/dist/webhooks/webhookSystem.js.map +0 -1
  154. package/dist/worker.d.ts.map +0 -1
package/bin/brainy.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * Brainy CLI - Beautiful command center for the vector + graph database
4
+ * Brainy CLI - Redesigned for Better UX
5
+ * Direct commands + Augmentation system
5
6
  */
6
7
 
7
8
  // @ts-ignore
@@ -13,25 +14,24 @@ import { readFileSync } from 'fs'
13
14
  import { dirname, join } from 'path'
14
15
  import { fileURLToPath } from 'url'
15
16
 
17
+ // Import fetch for API calls
18
+ import fetch from 'node-fetch'
19
+
16
20
  const __dirname = dirname(fileURLToPath(import.meta.url))
17
21
  const packageJson = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8'))
18
22
 
19
23
  // Create Cortex instance
20
24
  const cortex = new Cortex()
21
25
 
22
- // Helper to ensure proper process exit
26
+ // Helper functions
23
27
  const exitProcess = (code = 0) => {
24
- setTimeout(() => {
25
- process.exit(code)
26
- }, 100)
28
+ setTimeout(() => process.exit(code), 100)
27
29
  }
28
30
 
29
- // Wrap async actions to ensure proper exit
30
31
  const wrapAction = (fn) => {
31
32
  return async (...args) => {
32
33
  try {
33
34
  await fn(...args)
34
- // Always exit for non-interactive commands
35
35
  exitProcess(0)
36
36
  } catch (error) {
37
37
  console.error(chalk.red('Error:'), error.message)
@@ -40,7 +40,6 @@ const wrapAction = (fn) => {
40
40
  }
41
41
  }
42
42
 
43
- // Wrap interactive actions with explicit exit
44
43
  const wrapInteractive = (fn) => {
45
44
  return async (...args) => {
46
45
  try {
@@ -53,38 +52,34 @@ const wrapInteractive = (fn) => {
53
52
  }
54
53
  }
55
54
 
56
- // Setup program
55
+ // ========================================
56
+ // MAIN PROGRAM SETUP
57
+ // ========================================
58
+
57
59
  program
58
- .name('cortex')
59
- .description('🧠 Cortex - Command Center for Brainy')
60
+ .name('brainy')
61
+ .description('🧠 Brainy - Vector + Graph Database with AI Coordination')
60
62
  .version(packageJson.version)
61
63
 
62
- // Initialize command
64
+ // ========================================
65
+ // CORE DATABASE COMMANDS (Direct Access)
66
+ // ========================================
67
+
63
68
  program
64
69
  .command('init')
65
- .description('Initialize Cortex in your project')
70
+ .description('🚀 Initialize Brainy in your project')
66
71
  .option('-s, --storage <type>', 'Storage type (filesystem, s3, r2, gcs, memory)')
67
72
  .option('-e, --encryption', 'Enable encryption for secrets')
68
73
  .action(wrapAction(async (options) => {
69
74
  await cortex.init(options)
70
75
  }))
71
76
 
72
- // Chat commands (simplified - just 'chat', no alias)
73
- program
74
- .command('chat [question]')
75
- .description('💬 Chat with your data (interactive mode if no question)')
76
- .option('-l, --llm <model>', 'LLM model to use')
77
- .action(wrapInteractive(async (question, options) => {
78
- await cortex.chat(question)
79
- }))
80
-
81
- // Data management commands
82
77
  program
83
78
  .command('add [data]')
84
79
  .description('📊 Add data to Brainy')
85
80
  .option('-m, --metadata <json>', 'Metadata as JSON')
86
81
  .option('-i, --id <id>', 'Custom ID')
87
- .action(async (data, options) => {
82
+ .action(wrapAction(async (data, options) => {
88
83
  let metadata = {}
89
84
  if (options.metadata) {
90
85
  try {
@@ -98,17 +93,16 @@ program
98
93
  metadata.id = options.id
99
94
  }
100
95
  await cortex.add(data, metadata)
101
- exitProcess(0)
102
- })
96
+ }))
103
97
 
104
98
  program
105
99
  .command('search <query>')
106
- .description('🔍 Search your database with advanced options')
100
+ .description('🔍 Search your database')
107
101
  .option('-l, --limit <number>', 'Number of results', '10')
108
102
  .option('-f, --filter <json>', 'MongoDB-style metadata filters')
109
103
  .option('-v, --verbs <types>', 'Graph verb types to traverse (comma-separated)')
110
104
  .option('-d, --depth <number>', 'Graph traversal depth', '1')
111
- .action(async (query, options) => {
105
+ .action(wrapAction(async (query, options) => {
112
106
  const searchOptions = { limit: parseInt(options.limit) }
113
107
 
114
108
  if (options.filter) {
@@ -126,189 +120,44 @@ program
126
120
  }
127
121
 
128
122
  await cortex.search(query, searchOptions)
129
- exitProcess(0)
130
- })
131
-
132
- program
133
- .command('find')
134
- .description('🔍 Interactive advanced search with filters and graph traversal')
135
- .action(wrapInteractive(async () => {
136
- await cortex.advancedSearch()
137
123
  }))
138
124
 
139
125
  program
140
- .command('update <id> <data>')
141
- .description('✏️ Update existing data')
142
- .option('-m, --metadata <json>', 'New metadata as JSON')
143
- .action(async (id, data, options) => {
144
- let metadata = {}
145
- if (options.metadata) {
146
- try {
147
- metadata = JSON.parse(options.metadata)
148
- } catch {
149
- console.error(chalk.red('Invalid metadata JSON'))
150
- process.exit(1)
151
- }
152
- }
153
- await cortex.update(id, data, metadata)
154
- exitProcess(0)
155
- })
156
-
157
- program
158
- .command('delete <id>')
159
- .description('🗑️ Delete data by ID')
160
- .action(wrapAction(async (id) => {
161
- await cortex.delete(id)
162
- }))
163
-
164
- // Graph commands
165
- program
166
- .command('verb <subject> <verb> <object>')
167
- .description('🔗 Add graph relationship between nodes')
168
- .option('-m, --metadata <json>', 'Relationship metadata')
169
- .action(async (subject, verb, object, options) => {
170
- let metadata = {}
171
- if (options.metadata) {
172
- try {
173
- metadata = JSON.parse(options.metadata)
174
- } catch {
175
- console.error(chalk.red('Invalid metadata JSON'))
176
- process.exit(1)
177
- }
178
- }
179
- await cortex.addVerb(subject, verb, object, metadata)
180
- exitProcess(0)
181
- })
182
-
183
- program
184
- .command('explore [nodeId]')
185
- .description('🗺️ Interactively explore graph connections')
186
- .action(wrapInteractive(async (nodeId) => {
187
- await cortex.explore(nodeId)
188
- }))
189
-
190
- // Configuration commands
191
- const config = program.command('config')
192
- .description('⚙️ Manage configuration')
193
-
194
- config
195
- .command('set <key> <value>')
196
- .description('Set configuration value')
197
- .option('-e, --encrypt', 'Encrypt this value')
198
- .action(wrapAction(async (key, value, options) => {
199
- await cortex.configSet(key, value, options)
200
- }))
201
-
202
- config
203
- .command('get <key>')
204
- .description('Get configuration value')
205
- .action(async (key) => {
206
- const value = await cortex.configGet(key)
207
- if (value) {
208
- console.log(chalk.green(`${key}: ${value}`))
209
- } else {
210
- console.log(chalk.yellow(`Key not found: ${key}`))
211
- }
212
- exitProcess(0)
213
- })
214
-
215
- config
216
- .command('list')
217
- .description('List all configuration')
218
- .action(wrapAction(async () => {
219
- await cortex.configList()
220
- }))
221
-
222
- config
223
- .command('import <file>')
224
- .description('Import configuration from .env file')
225
- .action(wrapAction(async (file) => {
226
- await cortex.importEnv(file)
227
- }))
228
-
229
- config
230
- .command('export <file>')
231
- .description('Export configuration to .env file')
232
- .action(wrapAction(async (file) => {
233
- await cortex.exportEnv(file)
234
- }))
235
-
236
- config
237
- .command('key-rotate')
238
- .description('🔄 Rotate master encryption key')
239
- .action(wrapInteractive(async () => {
240
- await cortex.resetMasterKey()
241
- }))
242
-
243
- config
244
- .command('secrets-patterns')
245
- .description('🛡️ List secret detection patterns')
246
- .action(wrapAction(async () => {
247
- await cortex.listSecretPatterns()
248
- }))
249
-
250
- config
251
- .command('secrets-add <pattern>')
252
- .description('➕ Add custom secret detection pattern')
253
- .action(wrapAction(async (pattern) => {
254
- await cortex.addSecretPattern(pattern)
255
- }))
256
-
257
- config
258
- .command('secrets-remove <pattern>')
259
- .description('➖ Remove custom secret detection pattern')
260
- .action(wrapAction(async (pattern) => {
261
- await cortex.removeSecretPattern(pattern)
262
- }))
263
-
264
- // Migration commands
265
- program
266
- .command('migrate')
267
- .description('📦 Migrate to different storage')
268
- .requiredOption('-t, --to <type>', 'Target storage type (filesystem, s3, r2, gcs, memory)')
269
- .option('-b, --bucket <name>', 'Bucket name for cloud storage')
270
- .option('-s, --strategy <type>', 'Migration strategy', 'immediate')
271
- .action(wrapInteractive(async (options) => {
272
- await cortex.migrate(options)
126
+ .command('chat [question]')
127
+ .description('💬 Chat with your data (interactive mode if no question)')
128
+ .option('-l, --llm <model>', 'LLM model to use')
129
+ .action(wrapInteractive(async (question, options) => {
130
+ await cortex.chat(question)
273
131
  }))
274
132
 
275
- // Database operations
276
133
  program
277
134
  .command('stats')
278
135
  .description('📊 Show database statistics')
279
- .option('-d, --detailed', 'Show detailed field statistics')
136
+ .option('-d, --detailed', 'Show detailed statistics')
280
137
  .action(wrapAction(async (options) => {
281
138
  await cortex.stats(options.detailed)
282
139
  }))
283
140
 
284
141
  program
285
- .command('fields')
286
- .description('📋 List all searchable fields with samples')
287
- .action(wrapAction(async () => {
288
- await cortex.listFields()
289
- }))
290
-
291
- // LLM setup
292
- program
293
- .command('llm [provider]')
294
- .description('🤖 Setup or change LLM provider')
295
- .action(wrapInteractive(async (provider) => {
296
- await cortex.setupLLM(provider)
142
+ .command('health')
143
+ .description('🔋 Check system health')
144
+ .option('--auto-fix', 'Automatically apply safe repairs')
145
+ .action(wrapAction(async (options) => {
146
+ await cortex.health(options)
297
147
  }))
298
148
 
299
- // Embedding utilities
300
149
  program
301
- .command('embed <text>')
302
- .description(' Generate embedding vector for text')
303
- .action(wrapAction(async (text) => {
304
- await cortex.embed(text)
150
+ .command('find')
151
+ .description('🔍 Interactive advanced search')
152
+ .action(wrapInteractive(async () => {
153
+ await cortex.advancedSearch()
305
154
  }))
306
155
 
307
156
  program
308
- .command('similarity <text1> <text2>')
309
- .description('🔍 Calculate semantic similarity between texts')
310
- .action(wrapAction(async (text1, text2) => {
311
- await cortex.similarity(text1, text2)
157
+ .command('explore [nodeId]')
158
+ .description('🗺️ Interactively explore graph connections')
159
+ .action(wrapInteractive(async (nodeId) => {
160
+ await cortex.explore(nodeId)
312
161
  }))
313
162
 
314
163
  program
@@ -327,266 +176,569 @@ program
327
176
  await cortex.restore(file)
328
177
  }))
329
178
 
179
+ // ========================================
180
+ // BRAIN CLOUD INTEGRATION
181
+ // ========================================
182
+
330
183
  program
331
- .command('health')
332
- .description('🏥 Check database health')
333
- .action(wrapAction(async () => {
334
- await cortex.health()
184
+ .command('connect')
185
+ .description('🔗 Connect me to your Brain Cloud so I remember everything')
186
+ .action(wrapInteractive(async () => {
187
+ console.log(chalk.cyan('\n🧠 Setting Up AI Memory...'))
188
+ console.log(chalk.gray('━'.repeat(50)))
189
+
190
+ try {
191
+ // Detect customer ID
192
+ const customerId = await detectCustomerId()
193
+
194
+ if (customerId) {
195
+ console.log(chalk.green(`✅ Found your Brain Cloud: ${customerId}`))
196
+ console.log('\n🔧 I can set up AI memory so I remember our conversations:')
197
+ console.log(chalk.yellow(' • Update Claude configuration'))
198
+ console.log(chalk.yellow(' • Add memory instructions'))
199
+ console.log(chalk.yellow(' • Enable cross-session memory'))
200
+
201
+ // For now, auto-proceed (in a real CLI environment, user could be prompted)
202
+ console.log(chalk.cyan('\n🚀 Setting up AI memory...'))
203
+ const proceed = true
204
+
205
+ if (proceed) {
206
+ await setupBrainCloudMemory(customerId)
207
+ console.log(chalk.green('\n🎉 AI Memory Connected!'))
208
+ console.log(chalk.cyan('Restart Claude Code and I\'ll remember everything!'))
209
+ }
210
+ } else {
211
+ console.log(chalk.yellow('🤔 No Brain Cloud found. Let me help you set one up:'))
212
+ console.log('\n1. Visit: ' + chalk.cyan('https://app.soulcraftlabs.com'))
213
+ console.log('2. Sign up for Brain Cloud ($19/month)')
214
+ console.log('3. Run ' + chalk.green('brainy connect') + ' again')
215
+ }
216
+ } catch (error) {
217
+ console.log(chalk.red('❌ Setup failed:'), error.message)
218
+ }
335
219
  }))
336
220
 
337
- // Backup & Restore commands
338
221
  program
339
- .command('backup')
340
- .description('💾 Create atomic vault backup')
341
- .option('-c, --compress', 'Enable quantum compression')
342
- .option('-o, --output <file>', 'Output file path')
343
- .option('--password <password>', 'Encrypt backup with password')
344
- .action(wrapAction(async (options) => {
345
- await cortex.backup(options)
222
+ .command('cloud [action]')
223
+ .description('☁️ Connect to Brain Cloud - AI memory that never forgets')
224
+ .option('--connect <id>', 'Connect to existing Brain Cloud instance')
225
+ .option('--export <id>', 'Export all data from Brain Cloud instance')
226
+ .option('--status <id>', 'Check status of Brain Cloud instance')
227
+ .option('--dashboard <id>', 'Open dashboard for Brain Cloud instance')
228
+ .option('--migrate', 'Migrate between local and cloud')
229
+ .action(wrapInteractive(async (action, options) => {
230
+ // For now, show connection instructions
231
+ console.log(chalk.cyan('\n⚛️ BRAIN CLOUD - AI Memory That Never Forgets'))
232
+ console.log(chalk.gray('━'.repeat(50)))
233
+
234
+ if (options.connect) {
235
+ console.log(chalk.green(`✅ Connecting to Brain Cloud instance: ${options.connect}`))
236
+
237
+ try {
238
+ // Test connection to Brain Cloud worker
239
+ const healthUrl = `https://brain-cloud.dpsifr.workers.dev/health`
240
+ const response = await fetch(healthUrl, {
241
+ headers: { 'x-customer-id': options.connect }
242
+ })
243
+
244
+ if (response.ok) {
245
+ const data = await response.json()
246
+ console.log(chalk.green(`🧠 ${data.status}`))
247
+ console.log(chalk.cyan(`💫 Instance: ${data.customerId}`))
248
+ console.log(chalk.gray(`⏰ Connected at: ${new Date(data.timestamp).toLocaleString()}`))
249
+
250
+ // Test memories endpoint
251
+ const memoriesResponse = await fetch(`https://brain-cloud.dpsifr.workers.dev/memories`, {
252
+ headers: { 'x-customer-id': options.connect }
253
+ })
254
+
255
+ if (memoriesResponse.ok) {
256
+ const memoriesData = await memoriesResponse.json()
257
+ console.log(chalk.yellow(`\n${memoriesData.message}`))
258
+ console.log(chalk.gray('📊 Your atomic memories:'))
259
+ memoriesData.memories.forEach(memory => {
260
+ const time = new Date(memory.created).toLocaleString()
261
+ console.log(chalk.gray(` • ${memory.content} (${time})`))
262
+ })
263
+ }
264
+
265
+ } else {
266
+ console.log(chalk.red('❌ Could not connect to Brain Cloud'))
267
+ console.log(chalk.yellow('💡 Make sure you have an active instance'))
268
+ console.log('\nSign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
269
+ }
270
+ } catch (error) {
271
+ console.log(chalk.red('❌ Connection failed:'), error.message)
272
+ console.log('\nSign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
273
+ }
274
+ } else if (options.export) {
275
+ console.log(chalk.green(`📦 Exporting data from Brain Cloud instance: ${options.export}`))
276
+
277
+ try {
278
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/export`, {
279
+ headers: { 'x-customer-id': options.export }
280
+ })
281
+
282
+ if (response.ok) {
283
+ const data = await response.json()
284
+ const filename = `brainy-export-${options.export}-${Date.now()}.json`
285
+
286
+ // Write to file
287
+ const fs = await import('fs/promises')
288
+ await fs.writeFile(filename, JSON.stringify(data, null, 2))
289
+
290
+ console.log(chalk.green(`✅ Data exported to: ${filename}`))
291
+ console.log(chalk.gray(`📊 Exported ${data.memories?.length || 0} memories`))
292
+ } else {
293
+ console.log(chalk.red('❌ Export failed - instance not found'))
294
+ }
295
+ } catch (error) {
296
+ console.log(chalk.red('❌ Export error:'), error.message)
297
+ }
298
+ } else if (options.status) {
299
+ console.log(chalk.green(`🔍 Checking status of Brain Cloud instance: ${options.status}`))
300
+
301
+ try {
302
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/health`, {
303
+ headers: { 'x-customer-id': options.status }
304
+ })
305
+
306
+ if (response.ok) {
307
+ const data = await response.json()
308
+ console.log(chalk.green(`✅ Instance Status: Active`))
309
+ console.log(chalk.cyan(`🧠 ${data.status}`))
310
+ console.log(chalk.gray(`⏰ Last check: ${new Date(data.timestamp).toLocaleString()}`))
311
+
312
+ // Get memory count
313
+ const memoriesResponse = await fetch(`https://brain-cloud.dpsifr.workers.dev/memories`, {
314
+ headers: { 'x-customer-id': options.status }
315
+ })
316
+
317
+ if (memoriesResponse.ok) {
318
+ const memoriesData = await memoriesResponse.json()
319
+ console.log(chalk.yellow(`📊 Total memories: ${memoriesData.count}`))
320
+ }
321
+ } else {
322
+ console.log(chalk.red('❌ Instance not found or inactive'))
323
+ }
324
+ } catch (error) {
325
+ console.log(chalk.red('❌ Status check failed:'), error.message)
326
+ }
327
+ } else if (options.dashboard) {
328
+ console.log(chalk.green(`🌐 Opening dashboard for Brain Cloud instance: ${options.dashboard}`))
329
+
330
+ const dashboardUrl = `https://app.soulcraftlabs.com/dashboard.html?customer_id=${options.dashboard}`
331
+ console.log(chalk.cyan(`\n🔗 Dashboard URL: ${dashboardUrl}`))
332
+ console.log(chalk.gray('Opening in your default browser...'))
333
+
334
+ try {
335
+ const { exec } = await import('child_process')
336
+ const { promisify } = await import('util')
337
+ const execAsync = promisify(exec)
338
+
339
+ // Cross-platform browser opening
340
+ const command = process.platform === 'win32' ? 'start' :
341
+ process.platform === 'darwin' ? 'open' : 'xdg-open'
342
+
343
+ await execAsync(`${command} "${dashboardUrl}"`)
344
+ console.log(chalk.green('✅ Dashboard opened!'))
345
+ } catch (error) {
346
+ console.log(chalk.yellow('💡 Copy the URL above to open in your browser'))
347
+ }
348
+ } else {
349
+ console.log(chalk.yellow('📡 Brain Cloud Setup'))
350
+ console.log('\n1. Sign up at: ' + chalk.cyan('https://app.soulcraftlabs.com'))
351
+ console.log('2. Get your customer ID')
352
+ console.log('3. Connect with: ' + chalk.green('brainy cloud --connect YOUR_ID'))
353
+ console.log('\nBenefits:')
354
+ console.log(' • ' + chalk.green('Never lose AI context again'))
355
+ console.log(' • ' + chalk.green('Sync across all devices'))
356
+ console.log(' • ' + chalk.green('Unlimited memory storage'))
357
+ console.log(' • ' + chalk.green('$19/month or free trial'))
358
+ }
346
359
  }))
347
360
 
361
+ // ========================================
362
+ // AUGMENTATION MANAGEMENT (Direct Commands)
363
+ // ========================================
364
+
348
365
  program
349
- .command('restore <file>')
350
- .description('♻️ Restore from atomic vault')
351
- .option('--password <password>', 'Decrypt backup with password')
352
- .option('--dry-run', 'Simulate restore without making changes')
353
- .action(wrapInteractive(async (file, options) => {
354
- await cortex.restore(file, options)
366
+ .command('install <augmentation>')
367
+ .description('📦 Install augmentation')
368
+ .option('-m, --mode <type>', 'Installation mode (free|premium)', 'free')
369
+ .option('-c, --config <json>', 'Configuration as JSON')
370
+ .action(wrapAction(async (augmentation, options) => {
371
+ if (augmentation === 'brain-jar') {
372
+ await cortex.brainJarInstall(options.mode)
373
+ } else {
374
+ // Generic augmentation install
375
+ let config = {}
376
+ if (options.config) {
377
+ try {
378
+ config = JSON.parse(options.config)
379
+ } catch {
380
+ console.error(chalk.red('Invalid JSON configuration'))
381
+ process.exit(1)
382
+ }
383
+ }
384
+ await cortex.addAugmentation(augmentation, undefined, config)
385
+ }
355
386
  }))
356
387
 
357
388
  program
358
- .command('backups')
359
- .description('📋 List available atomic vault backups')
360
- .option('-d, --directory <path>', 'Backup directory', './backups')
361
- .action(wrapAction(async (options) => {
362
- await cortex.listBackups(options.directory)
389
+ .command('run <augmentation>')
390
+ .description(' Run augmentation')
391
+ .option('-c, --config <json>', 'Runtime configuration as JSON')
392
+ .action(wrapAction(async (augmentation, options) => {
393
+ if (augmentation === 'brain-jar') {
394
+ await cortex.brainJarStart(options)
395
+ } else {
396
+ // Generic augmentation execution
397
+ const inputData = options.config ? JSON.parse(options.config) : { run: true }
398
+ await cortex.executePipelineStep(augmentation, inputData)
399
+ }
363
400
  }))
364
401
 
365
- // Augmentation Management commands
366
402
  program
367
- .command('augmentations')
368
- .description('🧠 Show augmentation status and management')
369
- .option('-v, --verbose', 'Show detailed augmentation information')
370
- .action(wrapInteractive(async (options) => {
371
- await cortex.augmentations(options)
403
+ .command('status [augmentation]')
404
+ .description('📊 Show augmentation status')
405
+ .action(wrapAction(async (augmentation) => {
406
+ if (augmentation === 'brain-jar') {
407
+ await cortex.brainJarStatus()
408
+ } else if (augmentation) {
409
+ // Show specific augmentation status
410
+ await cortex.listAugmentations()
411
+ } else {
412
+ // Show all augmentation status
413
+ await cortex.listAugmentations()
414
+ }
372
415
  }))
373
416
 
374
- // Performance Monitoring & Health Check commands
375
417
  program
376
- .command('monitor')
377
- .description('📊 Monitor vector + graph database performance')
378
- .option('-d, --dashboard', 'Launch interactive performance dashboard')
379
- .action(wrapInteractive(async (options) => {
380
- await cortex.monitor(options)
418
+ .command('stop [augmentation]')
419
+ .description('⏹️ Stop augmentation')
420
+ .action(wrapAction(async (augmentation) => {
421
+ if (augmentation === 'brain-jar') {
422
+ await cortex.brainJarStop()
423
+ } else {
424
+ console.log(chalk.yellow('Stop functionality for generic augmentations not yet implemented'))
425
+ }
381
426
  }))
382
427
 
383
428
  program
384
- .command('health')
385
- .description('🔋 Check system health and diagnostics')
386
- .option('--auto-fix', 'Automatically apply safe repairs')
429
+ .command('list')
430
+ .description('📋 List installed augmentations')
431
+ .option('-a, --available', 'Show available augmentations')
387
432
  .action(wrapAction(async (options) => {
388
- await cortex.health(options)
433
+ if (options.available) {
434
+ console.log(chalk.cyan('🧩 Available Augmentations:'))
435
+ console.log(' • brain-jar - AI coordination and collaboration')
436
+ console.log(' • encryption - Data encryption and security')
437
+ console.log(' • neural-import - AI-powered data analysis')
438
+ console.log(' • performance-monitor - System monitoring')
439
+ console.log('')
440
+ console.log(chalk.dim('Install: brainy install <augmentation>'))
441
+ } else {
442
+ await cortex.listAugmentations()
443
+ }
389
444
  }))
390
445
 
446
+ // ========================================
447
+ // BRAIN CLOUD SUPER COMMAND (New!)
448
+ // ========================================
449
+
391
450
  program
392
- .command('performance')
393
- .description(' Analyze database performance metrics')
394
- .option('--analyze', 'Deep performance analysis with trends')
395
- .action(wrapAction(async (options) => {
396
- await cortex.performance(options)
451
+ .command('cloud')
452
+ .description('☁️ Setup Brain Cloud - AI coordination across all devices')
453
+ .option('-m, --mode <type>', 'Setup mode (free|premium)', 'interactive')
454
+ .option('-k, --key <key>', 'License key for premium features')
455
+ .option('-s, --skip-install', 'Skip Brain Jar installation')
456
+ .action(wrapInteractive(async (options) => {
457
+ await cortex.setupBrainCloud(options)
397
458
  }))
398
459
 
399
- // Premium Licensing commands
400
- const license = program.command('license')
401
- .description('👑 Manage premium licenses and features')
460
+ // ========================================
461
+ // BRAIN JAR SPECIFIC COMMANDS (Rich UX)
462
+ // ========================================
402
463
 
403
- license
404
- .command('catalog')
405
- .description('📋 Browse premium features catalog')
406
- .action(wrapAction(async () => {
407
- await cortex.licenseCatalog()
408
- }))
464
+ const brainJar = program.command('brain-jar')
465
+ .description('🧠🫙 AI coordination and collaboration')
409
466
 
410
- license
411
- .command('status [license-id]')
412
- .description('📊 Check license status and usage')
413
- .action(wrapAction(async (licenseId) => {
414
- await cortex.licenseStatus(licenseId)
467
+ brainJar
468
+ .command('install')
469
+ .description('📦 Install Brain Jar coordination')
470
+ .option('-m, --mode <type>', 'Installation mode (free|premium)', 'free')
471
+ .action(wrapAction(async (options) => {
472
+ await cortex.brainJarInstall(options.mode)
415
473
  }))
416
474
 
417
- license
418
- .command('trial <feature>')
419
- .description(' Start free trial for premium feature')
420
- .option('--name <name>', 'Your name')
421
- .option('--email <email>', 'Your email address')
422
- .action(wrapAction(async (feature, options) => {
423
- await cortex.licenseTrial(feature, options.name, options.email)
475
+ brainJar
476
+ .command('start')
477
+ .description('🚀 Start Brain Jar coordination')
478
+ .option('-s, --server <url>', 'Custom server URL')
479
+ .option('-n, --name <name>', 'Agent name')
480
+ .option('-r, --role <role>', 'Agent role')
481
+ .action(wrapAction(async (options) => {
482
+ await cortex.brainJarStart(options)
424
483
  }))
425
484
 
426
- license
427
- .command('validate <feature>')
428
- .description(' Validate feature license availability')
429
- .action(wrapAction(async (feature) => {
430
- await cortex.licenseValidate(feature)
485
+ brainJar
486
+ .command('dashboard')
487
+ .description('📊 Open Brain Jar dashboard')
488
+ .option('-o, --open', 'Auto-open in browser', true)
489
+ .action(wrapAction(async (options) => {
490
+ await cortex.brainJarDashboard(options.open)
431
491
  }))
432
492
 
433
- // Augmentation management commands
434
- const augment = program.command('augment')
435
- .description('🧩 Manage augmentation pipeline')
436
-
437
- augment
438
- .command('list')
439
- .description('📋 List all augmentations and pipeline status')
493
+ brainJar
494
+ .command('status')
495
+ .description('🔍 Show Brain Jar status')
440
496
  .action(wrapAction(async () => {
441
- await cortex.listAugmentations()
497
+ await cortex.brainJarStatus()
442
498
  }))
443
499
 
444
- augment
445
- .command('add <type>')
446
- .description(' Add augmentation to pipeline')
447
- .option('-p, --position <number>', 'Pipeline position')
448
- .option('-c, --config <json>', 'Configuration as JSON')
449
- .action(wrapAction(async (type, options) => {
450
- let config = {}
451
- if (options.config) {
452
- try {
453
- config = JSON.parse(options.config)
454
- } catch {
455
- console.error(chalk.red('Invalid JSON configuration'))
456
- process.exit(1)
457
- }
458
- }
459
- await cortex.addAugmentation(type, options.position ? parseInt(options.position) : undefined, config)
460
- }))
461
-
462
- augment
463
- .command('remove <type>')
464
- .description('➖ Remove augmentation from pipeline')
465
- .action(wrapAction(async (type) => {
466
- await cortex.removeAugmentation(type)
500
+ brainJar
501
+ .command('agents')
502
+ .description('👥 List connected agents')
503
+ .action(wrapAction(async () => {
504
+ await cortex.brainJarAgents()
467
505
  }))
468
506
 
469
- augment
470
- .command('configure <type> <config>')
471
- .description('⚙️ Configure existing augmentation')
472
- .action(wrapAction(async (type, configJson) => {
473
- let config = {}
474
- try {
475
- config = JSON.parse(configJson)
476
- } catch {
477
- console.error(chalk.red('Invalid JSON configuration'))
478
- process.exit(1)
479
- }
480
- await cortex.configureAugmentation(type, config)
507
+ brainJar
508
+ .command('message <text>')
509
+ .description('📨 Send message to coordination channel')
510
+ .action(wrapAction(async (text) => {
511
+ await cortex.brainJarMessage(text)
481
512
  }))
482
513
 
483
- augment
484
- .command('reset')
485
- .description('🔄 Reset pipeline to defaults')
486
- .action(wrapInteractive(async () => {
487
- await cortex.resetPipeline()
514
+ brainJar
515
+ .command('search <query>')
516
+ .description('🔍 Search coordination history')
517
+ .option('-l, --limit <number>', 'Number of results', '10')
518
+ .action(wrapAction(async (query, options) => {
519
+ await cortex.brainJarSearch(query, parseInt(options.limit))
488
520
  }))
489
521
 
490
- augment
491
- .command('execute <step> [data]')
492
- .description('⚡ Execute specific pipeline step')
493
- .action(wrapAction(async (step, data) => {
494
- const inputData = data ? JSON.parse(data) : { test: true }
495
- await cortex.executePipelineStep(step, inputData)
496
- }))
522
+ // ========================================
523
+ // CONFIGURATION COMMANDS
524
+ // ========================================
497
525
 
498
- // Neural Import commands - The AI-Powered Data Understanding System
499
- const neural = program.command('neural')
500
- .description('🧠 AI-powered data analysis and import')
501
-
502
- neural
503
- .command('import <file>')
504
- .description('🧠 Smart import with AI analysis')
505
- .option('-c, --confidence <threshold>', 'Confidence threshold (0-1)', '0.7')
506
- .option('-a, --auto-apply', 'Auto-apply without confirmation')
507
- .option('-w, --enable-weights', 'Enable relationship weights', true)
508
- .option('--skip-duplicates', 'Skip duplicate detection', true)
509
- .action(wrapInteractive(async (file, options) => {
510
- const importOptions = {
511
- confidenceThreshold: parseFloat(options.confidence),
512
- autoApply: options.autoApply,
513
- enableWeights: options.enableWeights,
514
- skipDuplicates: options.skipDuplicates
515
- }
516
- await cortex.neuralImport(file, importOptions)
517
- }))
526
+ const config = program.command('config')
527
+ .description('⚙️ Manage configuration')
518
528
 
519
- neural
520
- .command('analyze <file>')
521
- .description('🔬 Analyze data structure without importing')
522
- .action(wrapAction(async (file) => {
523
- await cortex.neuralAnalyze(file)
529
+ config
530
+ .command('set <key> <value>')
531
+ .description('Set configuration value')
532
+ .option('-e, --encrypt', 'Encrypt this value')
533
+ .action(wrapAction(async (key, value, options) => {
534
+ await cortex.configSet(key, value, options)
524
535
  }))
525
536
 
526
- neural
527
- .command('validate <file>')
528
- .description(' Validate data import compatibility')
529
- .action(wrapAction(async (file) => {
530
- await cortex.neuralValidate(file)
537
+ config
538
+ .command('get <key>')
539
+ .description('Get configuration value')
540
+ .action(wrapAction(async (key) => {
541
+ const value = await cortex.configGet(key)
542
+ if (value) {
543
+ console.log(chalk.green(`${key}: ${value}`))
544
+ } else {
545
+ console.log(chalk.yellow(`Key not found: ${key}`))
546
+ }
531
547
  }))
532
548
 
533
- neural
534
- .command('types')
535
- .description('📋 Show available noun and verb types')
549
+ config
550
+ .command('list')
551
+ .description('List all configuration')
536
552
  .action(wrapAction(async () => {
537
- await cortex.neuralTypes()
553
+ await cortex.configList()
538
554
  }))
539
555
 
540
- // Service integration commands
541
- const service = program.command('service')
542
- .description('🛠️ Service integration and management')
556
+ // ========================================
557
+ // LEGACY CORTEX COMMANDS (Backward Compatibility)
558
+ // ========================================
543
559
 
544
- service
545
- .command('discover')
546
- .description('🔍 Discover Brainy services in environment')
547
- .action(wrapAction(async () => {
548
- console.log('🔍 Discovering services...')
549
- // This would call CortexServiceIntegration.discoverBrainyInstances()
550
- console.log('📋 Service discovery complete (placeholder)')
551
- }))
560
+ const cortexCmd = program.command('cortex')
561
+ .description('🔧 Legacy Cortex commands (deprecated - use direct commands)')
552
562
 
553
- service
554
- .command('health-all')
555
- .description('🩺 Health check all discovered services')
556
- .action(wrapAction(async () => {
557
- console.log('🩺 Running health checks on all services...')
558
- // This would call CortexServiceIntegration.healthCheckAll()
559
- console.log('✅ Health checks complete (placeholder)')
563
+ cortexCmd
564
+ .command('chat [question]')
565
+ .description('💬 Chat with your data')
566
+ .action(wrapInteractive(async (question) => {
567
+ console.log(chalk.yellow('⚠️ Deprecated: Use "brainy chat" instead'))
568
+ await cortex.chat(question)
560
569
  }))
561
570
 
562
- service
563
- .command('migrate-all')
564
- .description('🚀 Migrate all services to new storage')
565
- .requiredOption('-t, --to <type>', 'Target storage type')
566
- .option('-s, --strategy <type>', 'Migration strategy', 'immediate')
567
- .action(wrapInteractive(async (options) => {
568
- console.log(`🚀 Planning migration to ${options.to}...`)
569
- // This would call CortexServiceIntegration.migrateAll()
570
- console.log('✅ Migration complete (placeholder)')
571
+ cortexCmd
572
+ .command('add [data]')
573
+ .description('📊 Add data')
574
+ .action(wrapAction(async (data) => {
575
+ console.log(chalk.yellow('⚠️ Deprecated: Use "brainy add" instead'))
576
+ await cortex.add(data, {})
571
577
  }))
572
578
 
573
- // Interactive shell
579
+ // ========================================
580
+ // INTERACTIVE SHELL
581
+ // ========================================
582
+
574
583
  program
575
584
  .command('shell')
576
- .description('🐚 Interactive Cortex shell')
577
- .action(async () => {
578
- console.log(chalk.cyan('🧠 Cortex Interactive Shell'))
585
+ .description('🐚 Interactive Brainy shell')
586
+ .action(wrapInteractive(async () => {
587
+ console.log(chalk.cyan('🧠 Brainy Interactive Shell'))
579
588
  console.log(chalk.dim('Type "help" for commands, "exit" to quit\n'))
580
-
581
- // Start interactive mode
582
589
  await cortex.chat()
583
- exitProcess(0)
584
- })
590
+ }))
591
+
592
+ // ========================================
593
+ // PARSE AND HANDLE
594
+ // ========================================
585
595
 
586
- // Parse arguments
587
596
  program.parse(process.argv)
588
597
 
589
598
  // Show help if no command
590
599
  if (!process.argv.slice(2).length) {
600
+ console.log(chalk.cyan('🧠☁️ Brainy - AI Coordination Service'))
601
+ console.log('')
602
+ console.log(chalk.bold('One-Command Setup:'))
603
+ console.log(chalk.green(' brainy cloud # Setup Brain Cloud (recommended!)'))
604
+ console.log('')
605
+ console.log(chalk.bold('Quick Start:'))
606
+ console.log(' brainy init # Initialize project')
607
+ console.log(' brainy add "some data" # Add data')
608
+ console.log(' brainy search "query" # Search data')
609
+ console.log(' brainy chat # Chat with data')
610
+ console.log('')
611
+ console.log(chalk.bold('AI Coordination:'))
612
+ console.log(' brainy install brain-jar # Install AI coordination')
613
+ console.log(' brainy brain-jar start # Start coordination')
614
+ console.log(' brainy brain-jar dashboard # View dashboard')
615
+ console.log('')
591
616
  program.outputHelp()
617
+ }
618
+
619
+ // ========================================
620
+ // BRAIN CLOUD MEMORY SETUP FUNCTIONS
621
+ // ========================================
622
+
623
+ async function detectCustomerId() {
624
+ try {
625
+ // Method 1: Check for existing brainy config
626
+ const { readFile } = await import('fs/promises')
627
+ const { join } = await import('path')
628
+
629
+ try {
630
+ const configPath = join(process.cwd(), 'brainy-config.json')
631
+ const config = JSON.parse(await readFile(configPath, 'utf8'))
632
+ if (config.brainCloudCustomerId) {
633
+ return config.brainCloudCustomerId
634
+ }
635
+ } catch {}
636
+
637
+ // Method 2: Check CLAUDE.md for existing customer ID
638
+ try {
639
+ const claudePath = join(process.cwd(), 'CLAUDE.md')
640
+ const claudeContent = await readFile(claudePath, 'utf8')
641
+ const match = claudeContent.match(/customer.*?([a-z0-9-]+)/i)
642
+ if (match) return match[1]
643
+ } catch {}
644
+
645
+ // Method 3: Test common demo IDs
646
+ const testIds = ['demo-test-auto', 'demo-test123']
647
+ for (const id of testIds) {
648
+ try {
649
+ const response = await fetch(`https://brain-cloud.dpsifr.workers.dev/health`, {
650
+ headers: { 'x-customer-id': id }
651
+ })
652
+ if (response.ok) {
653
+ return id
654
+ }
655
+ } catch {}
656
+ }
657
+
658
+ return null
659
+ } catch (error) {
660
+ return null
661
+ }
662
+ }
663
+
664
+ async function setupBrainCloudMemory(customerId) {
665
+ const { writeFile, mkdir } = await import('fs/promises')
666
+ const { join } = await import('path')
667
+
668
+ console.log(chalk.gray('📝 Setting up AI memory configuration...'))
669
+
670
+ // 1. Create/update .claude directory and MCP config
671
+ try {
672
+ await mkdir('.claude', { recursive: true })
673
+
674
+ const mcpConfig = {
675
+ mcpServers: {
676
+ "brain-cloud": {
677
+ command: "node",
678
+ args: ["brainy-mcp-server.js"],
679
+ env: {
680
+ CUSTOMER_ID: customerId,
681
+ BRAIN_CLOUD_URL: "https://brain-cloud.dpsifr.workers.dev"
682
+ }
683
+ }
684
+ }
685
+ }
686
+
687
+ await writeFile('.claude/mcp_servers.json', JSON.stringify(mcpConfig, null, 2))
688
+ console.log(chalk.green('✅ MCP configuration updated'))
689
+ } catch (error) {
690
+ console.log(chalk.yellow('⚠️ Could not update MCP config:', error.message))
691
+ }
692
+
693
+ // 2. Create/update CLAUDE.md with natural language instructions
694
+ const claudeContent = `# 🧠 I Remember Everything Now!
695
+
696
+ Hi! I'm connected to your Brain Cloud (${customerId}) so I actually remember our conversations across sessions.
697
+
698
+ ## Try Saying:
699
+ - "What did we build together?"
700
+ - "Remember that React project?"
701
+ - "Show me what we worked on yesterday"
702
+ - "Find my notes about APIs"
703
+ - "Search for that bug we fixed"
704
+
705
+ ## I Can Also:
706
+ - Remember context from weeks ago
707
+ - Work with other AI assistants who share the same memory
708
+ - Keep everything synced across your devices
709
+ - Search through all our conversations
710
+
711
+ ## Multi-AI Coordination:
712
+ When working with multiple AI assistants, we automatically coordinate:
713
+ - **Jarvis** (Backend): APIs, databases, deployment
714
+ - **Picasso** (Design): UI, themes, visual elements
715
+ - **Claude** (Planning): Coordination, architecture, strategy
716
+
717
+ **Just talk to me normally - no commands needed!**
718
+
719
+ ---
720
+ *Brain Cloud Instance: ${customerId}*
721
+ *Last Updated: ${new Date().toLocaleDateString()}*
722
+ `
723
+
724
+ try {
725
+ await writeFile('CLAUDE.md', claudeContent)
726
+ console.log(chalk.green('✅ CLAUDE.md updated with memory instructions'))
727
+ } catch (error) {
728
+ console.log(chalk.yellow('⚠️ Could not update CLAUDE.md:', error.message))
729
+ }
730
+
731
+ // 3. Save customer ID to brainy config
732
+ try {
733
+ const brainyConfig = {
734
+ brainCloudCustomerId: customerId,
735
+ brainCloudUrl: 'https://brain-cloud.dpsifr.workers.dev',
736
+ lastConnected: new Date().toISOString()
737
+ }
738
+
739
+ await writeFile('brainy-config.json', JSON.stringify(brainyConfig, null, 2))
740
+ console.log(chalk.green('✅ Brainy configuration saved'))
741
+ } catch (error) {
742
+ console.log(chalk.yellow('⚠️ Could not save brainy config:', error.message))
743
+ }
592
744
  }