crbro-memory 1.1.0 → 1.2.1

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.
package/bin/crbro.js CHANGED
@@ -2,98 +2,337 @@
2
2
 
3
3
  // ─── CRBRO CLI ───────────────────────────────────────────────────
4
4
  // Command-line interface for CRBRO memory system
5
+ // Supports: init, status, activate, mine, setup-miner, miner-status,
6
+ // remove-miner, and MCP server mode (default)
7
+
8
+ import { platform, homedir } from 'os';
9
+ import { join } from 'path';
10
+ import { existsSync } from 'fs';
5
11
 
6
12
  const args = process.argv.slice(2);
7
13
  const command = args[0];
8
14
 
15
+ // ─── IDE Detection ──────────────────────────────────────────────
16
+ const IDE_CONFIGS = [
17
+ {
18
+ name: 'Antigravity (Google Gemini)',
19
+ id: 'antigravity',
20
+ configPath: () => join(homedir(), '.gemini', 'antigravity', 'mcp_config.json'),
21
+ configFormat: 'mcpServers',
22
+ },
23
+ {
24
+ name: 'Cursor',
25
+ id: 'cursor',
26
+ configPath: () => join(homedir(), '.cursor', 'mcp.json'),
27
+ configFormat: 'mcpServers',
28
+ },
29
+ {
30
+ name: 'Windsurf',
31
+ id: 'windsurf',
32
+ configPath: () => join(homedir(), '.windsurf', 'mcp.json'),
33
+ configFormat: 'mcpServers',
34
+ },
35
+ {
36
+ name: 'Claude Desktop',
37
+ id: 'claude-desktop',
38
+ configPath: () => {
39
+ if (platform() === 'win32') {
40
+ return join(process.env.APPDATA || '', 'Claude', 'claude_desktop_config.json');
41
+ }
42
+ return join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
43
+ },
44
+ configFormat: 'mcpServers',
45
+ },
46
+ {
47
+ name: 'Claude Code (user scope)',
48
+ id: 'claude-code',
49
+ configPath: () => join(homedir(), '.claude.json'),
50
+ configFormat: 'mcpServers',
51
+ },
52
+ {
53
+ name: 'VS Code + Continue',
54
+ id: 'continue',
55
+ configPath: () => join(homedir(), '.continue', 'config.json'),
56
+ configFormat: 'mcpServers',
57
+ },
58
+ {
59
+ name: 'ChatGPT Desktop',
60
+ id: 'chatgpt',
61
+ configPath: () => {
62
+ if (platform() === 'win32') {
63
+ return join(process.env.APPDATA || '', 'ChatGPT', 'mcp_config.json');
64
+ }
65
+ return join(homedir(), 'Library', 'Application Support', 'ChatGPT', 'mcp_config.json');
66
+ },
67
+ configFormat: 'mcpServers',
68
+ },
69
+ ];
70
+
71
+ function detectIDEs() {
72
+ const detected = [];
73
+ for (const ide of IDE_CONFIGS) {
74
+ try {
75
+ const configPath = ide.configPath();
76
+ if (existsSync(configPath)) {
77
+ detected.push({ ...ide, configPath: configPath, exists: true });
78
+ } else {
79
+ // Check if the parent directory exists (IDE installed but no config yet)
80
+ const parentDir = configPath.split(/[/\\]/).slice(0, -1).join(platform() === 'win32' ? '\\' : '/');
81
+ if (existsSync(parentDir)) {
82
+ detected.push({ ...ide, configPath: configPath, exists: false });
83
+ }
84
+ }
85
+ } catch { /* skip */ }
86
+ }
87
+ return detected;
88
+ }
89
+
90
+ function generateMCPSnippet(envVars) {
91
+ return JSON.stringify({
92
+ "crbro": {
93
+ "command": "npx",
94
+ "args": ["-y", "crbro-memory"],
95
+ ...(envVars ? { "env": envVars } : {})
96
+ }
97
+ }, null, 2);
98
+ }
99
+
100
+ // ─── Commands ───────────────────────────────────────────────────
101
+
9
102
  if (command === 'init') {
10
- // Initialize brain
103
+ // ─── Initialize brain + IDE detection ──────────────────────────
11
104
  import('../dist/engine/brain.js').then(async ({ Brain }) => {
12
105
  const brain = new Brain();
13
106
  const manifest = await brain.initialize();
14
- console.log('🧠 CRBRO brain initialized!');
15
- console.log(` Path: ${manifest.brain_path}`);
107
+
16
108
  console.log('');
17
- console.log('Add CRBRO to your MCP config:');
109
+ console.log(' 🧠 CRBRO brain initialized!');
110
+ console.log(` Path: ${manifest.brain_path}`);
18
111
  console.log('');
19
- console.log(JSON.stringify({
20
- "mcpServers": {
21
- "crbro": {
22
- "command": "npx",
23
- "args": ["-y", "crbro-memory"]
24
- }
112
+
113
+ // Detect IDEs
114
+ const ides = detectIDEs();
115
+
116
+ if (ides.length > 0) {
117
+ console.log(' 📡 Detected IDEs:');
118
+ console.log('');
119
+ for (const ide of ides) {
120
+ const status = ide.exists ? '✅ config exists' : '📝 needs config';
121
+ console.log(` ${ide.name}: ${status}`);
122
+ console.log(` → ${ide.configPath}`);
25
123
  }
26
- }, null, 2));
124
+ console.log('');
125
+ console.log(' Add this to your MCP config (inside "mcpServers"):');
126
+ } else {
127
+ console.log(' ⚠️ No IDE detected. Add this to your MCP config manually:');
128
+ }
129
+
130
+ console.log('');
131
+ console.log(' ' + generateMCPSnippet().split('\n').join('\n '));
132
+ console.log('');
133
+ console.log(' Next steps:');
134
+ console.log(' 1. Add the config above to your IDE\'s MCP settings');
135
+ console.log(' 2. npx crbro-memory activate YOUR-LICENSE-KEY');
136
+ console.log(' 3. (Optional) npx crbro-memory setup-miner');
137
+ console.log(' 4. Restart your IDE — CRBRO boots automatically!');
138
+ console.log('');
27
139
  }).catch(console.error);
28
140
 
29
141
  } else if (command === 'status') {
30
- // Show brain status
142
+ // ─── Show brain status ─────────────────────────────────────────
31
143
  import('../dist/engine/brain.js').then(async ({ Brain }) => {
32
144
  const brain = new Brain();
33
145
  try {
34
146
  const manifest = await brain.getManifest();
35
- console.log('🧠 CRBRO Brain Status');
36
- console.log(` Version: ${manifest.version}`);
37
- console.log(` Path: ${manifest.brain_path}`);
38
- console.log(` Neurons: ${manifest.total_neurons}`);
39
- console.log(` Synapses: ${manifest.total_synapses}`);
40
- console.log(` Sessions: ${manifest.total_sessions}`);
41
- console.log(` Last Boot: ${manifest.last_boot || 'never'}`);
147
+ console.log('');
148
+ console.log(' 🧠 CRBRO Brain Status');
149
+ console.log(' ─────────────────────');
150
+ console.log(` Version: ${manifest.version}`);
151
+ console.log(` Path: ${manifest.brain_path}`);
152
+ console.log(` Neurons: ${manifest.total_neurons}`);
153
+ console.log(` Synapses: ${manifest.total_synapses}`);
154
+ console.log(` Sessions: ${manifest.total_sessions}`);
155
+ console.log(` Last Boot: ${manifest.last_boot || 'never'}`);
156
+ console.log(` Last Consolidate: ${manifest.last_consolidation || 'never'}`);
157
+ console.log(` License: ${manifest.license_key ? '✅ Active' : '❌ Not activated'}`);
158
+ console.log('');
159
+
160
+ // Show detected IDEs
161
+ const ides = detectIDEs();
162
+ if (ides.length > 0) {
163
+ console.log(' 📡 Connected IDEs:');
164
+ for (const ide of ides) {
165
+ console.log(` ${ide.exists ? '✅' : '⚠️ '} ${ide.name}`);
166
+ }
167
+ console.log('');
168
+ }
42
169
  } catch {
43
- console.log('🧠 CRBRO brain not initialized. Run: npx crbro-memory init');
170
+ console.log('');
171
+ console.log(' 🧠 CRBRO brain not initialized.');
172
+ console.log(' Run: npx crbro-memory init');
173
+ console.log('');
44
174
  }
45
175
  }).catch(console.error);
46
176
 
47
177
  } else if (command === 'activate') {
48
- // Activate license key
178
+ // ─── Activate license key ──────────────────────────────────────
49
179
  const key = args[1];
50
180
  if (!key) {
51
- console.log('❌ Usage: npx crbro-memory activate SYNTH-ZERO-XXXX-XXXX-XXXX');
52
181
  console.log('');
53
- console.log('Get your license key at https://synthetica-decks.web.app');
182
+ console.log(' Usage: npx crbro-memory activate SYNTH-ZERO-XXXX-XXXX-XXXX');
183
+ console.log('');
184
+ console.log(' Get your license key at https://synthetica-decks.web.app');
185
+ console.log('');
54
186
  process.exit(1);
55
187
  }
56
188
 
57
189
  import('../dist/engine/brain.js').then(async ({ Brain }) => {
58
190
  const brain = new Brain();
59
191
  try {
60
- await brain.getManifest(); // Ensure brain exists
192
+ await brain.getManifest();
61
193
  } catch {
62
- console.log('🧠 Brain not initialized. Initializing now...');
194
+ console.log(' 🧠 Brain not initialized. Initializing now...');
63
195
  await brain.initialize();
64
196
  }
65
197
 
66
198
  // Validate key format
67
199
  if (!key.startsWith('SYNTH-ZERO-') || key.length < 20) {
68
- console.log('❌ Invalid license key format.');
69
- console.log(' Keys start with SYNTH-ZERO- and are at least 20 characters.');
200
+ console.log(' ❌ Invalid license key format.');
201
+ console.log(' Keys start with SYNTH-ZERO- and are at least 20 characters.');
70
202
  process.exit(1);
71
203
  }
72
204
 
73
205
  // Persist key in manifest
74
206
  await brain.updateManifest({ license_key: key });
75
- console.log('✅ License key activated!');
76
207
  console.log('');
77
- console.log(' 🔓 Premium features unlocked:');
78
- console.log(' • crbro_global_map — Neural cluster visualization');
79
- console.log(' crbro_maintenance Automated brain optimization');
208
+ console.log(' License key activated!');
209
+ console.log('');
210
+ console.log(' 🔓 Premium features unlocked:');
211
+ console.log(' • crbro_global_map — Neural cluster visualization');
212
+ console.log(' • crbro_maintenance — Automated brain optimization');
213
+ console.log('');
214
+ console.log(' Restart your IDE to apply changes.');
215
+ console.log('');
216
+ }).catch(console.error);
217
+
218
+ } else if (command === 'mine') {
219
+ // ─── One-shot mining ───────────────────────────────────────────
220
+ const targetDir = args[1];
221
+
222
+ import('../dist/miner/index.js').then(async ({ Miner }) => {
223
+ console.log('');
224
+ console.log(' ⛏️ CRBRO Miner — Scanning for knowledge...');
225
+ console.log('');
226
+
227
+ const miner = new Miner();
228
+ const result = await miner.mine(targetDir);
229
+
230
+ console.log(' ────────────────────────────────');
231
+ console.log(` Files scanned: ${result.scanned}`);
232
+ console.log(` New files mined: ${result.new_files}`);
233
+ console.log(` Neurons created: ${result.neurons_created}`);
234
+ console.log(` Neurons updated: ${result.neurons_updated}`);
235
+ console.log(` Facts added: ${result.facts_added}`);
236
+ console.log(` Decisions found: ${result.decisions_added}`);
237
+
238
+ if (result.technologies_found.length > 0) {
239
+ console.log(` Technologies: ${result.technologies_found.slice(0, 10).join(', ')}`);
240
+ }
241
+
242
+ if (result.errors.length > 0) {
243
+ console.log('');
244
+ console.log(' ⚠️ Errors:');
245
+ for (const err of result.errors.slice(0, 5)) {
246
+ console.log(` ${err}`);
247
+ }
248
+ }
249
+
250
+ console.log('');
251
+ }).catch(console.error);
252
+
253
+ } else if (command === 'setup-miner') {
254
+ // ─── Setup automatic mining ────────────────────────────────────
255
+ import('../dist/miner/scheduler.js').then(async ({ setupScheduler }) => {
256
+ console.log('');
257
+ console.log(' ⏰ Setting up CRBRO Auto-Miner...');
258
+ console.log('');
259
+
260
+ const result = await setupScheduler();
261
+ console.log(result.message);
262
+ console.log('');
263
+ }).catch(console.error);
264
+
265
+ } else if (command === 'miner-status') {
266
+ // ─── Check miner status ────────────────────────────────────────
267
+ Promise.all([
268
+ import('../dist/miner/scheduler.js'),
269
+ import('../dist/miner/index.js'),
270
+ ]).then(async ([{ getSchedulerStatus }, { Miner }]) => {
271
+ console.log('');
272
+ console.log(' ⛏️ CRBRO Miner Status');
273
+ console.log(' ─────────────────────');
274
+
275
+ // Scheduler status
276
+ const schedStatus = await getSchedulerStatus();
277
+ console.log(` Scheduler: ${schedStatus.installed ? '✅ Installed' : '❌ Not installed'}`);
278
+ console.log(` Platform: ${schedStatus.platform}`);
279
+ if (schedStatus.details) {
280
+ console.log(` Details: ${schedStatus.details}`);
281
+ }
282
+
283
+ // Miner state
284
+ const miner = new Miner();
285
+ const status = await miner.getStatus();
286
+ console.log('');
287
+ console.log(` Last run: ${status.state.last_run || 'never'}`);
288
+ console.log(` Total mined: ${status.state.total_mined} files`);
289
+ console.log(` Tracked: ${Object.keys(status.state.mined_files).length} files`);
290
+ console.log('');
291
+
292
+ if (status.detected_dirs.length > 0) {
293
+ console.log(' 📂 Scan directories:');
294
+ for (const dir of status.detected_dirs) {
295
+ console.log(` ${dir}`);
296
+ }
297
+ } else {
298
+ console.log(' ⚠️ No IDE directories detected.');
299
+ }
300
+ console.log('');
301
+ }).catch(console.error);
302
+
303
+ } else if (command === 'remove-miner') {
304
+ // ─── Remove automatic mining ───────────────────────────────────
305
+ import('../dist/miner/scheduler.js').then(async ({ removeScheduler }) => {
306
+ const result = await removeScheduler();
307
+ console.log('');
308
+ console.log(result.success ? ` ✅ ${result.message}` : ` ❌ ${result.message}`);
80
309
  console.log('');
81
- console.log(' Restart your IDE to apply changes.');
82
310
  }).catch(console.error);
83
311
 
84
312
  } else if (command === '--help' || command === '-h') {
85
- console.log('🧠 CRBRO Persistent Neural Memory for AI');
313
+ // ─── Help ──────────────────────────────────────────────────────
314
+ console.log('');
315
+ console.log(' 🧠 CRBRO — Persistent Neural Memory for AI');
316
+ console.log(' ═══════════════════════════════════════════');
317
+ console.log('');
318
+ console.log(' Setup:');
319
+ console.log(' npx crbro-memory init Initialize brain + detect IDEs');
320
+ console.log(' npx crbro-memory activate KEY Activate premium license');
321
+ console.log(' npx crbro-memory status Show brain status');
322
+ console.log('');
323
+ console.log(' Auto-Mining:');
324
+ console.log(' npx crbro-memory mine [dir] One-shot mining of artifacts');
325
+ console.log(' npx crbro-memory setup-miner Install scheduled auto-miner');
326
+ console.log(' npx crbro-memory miner-status Check auto-miner status');
327
+ console.log(' npx crbro-memory remove-miner Remove auto-miner');
328
+ console.log('');
329
+ console.log(' Server:');
330
+ console.log(' npx crbro-memory Start MCP server (stdio)');
86
331
  console.log('');
87
- console.log('Usage:');
88
- console.log(' npx crbro-memory Start MCP server (stdio)');
89
- console.log(' npx crbro-memory init Initialize brain directory');
90
- console.log(' npx crbro-memory status Show brain status');
91
- console.log(' npx crbro-memory activate KEY Activate premium license');
92
- console.log(' npx crbro-memory --help Show this help');
332
+ console.log(' Part of Synthetica Decks — https://synthetica-decks.web.app');
93
333
  console.log('');
94
- console.log('Part of Synthetica Decks — https://synthetica-decks.web.app');
95
334
 
96
335
  } else {
97
- // Default: start MCP server
336
+ // ─── Default: start MCP server ─────────────────────────────────
98
337
  import('../dist/index.js').catch(console.error);
99
338
  }
@@ -3,34 +3,50 @@ import type { LicenseInfo } from '../types/index.js';
3
3
  export declare class LicenseEngine {
4
4
  private brain;
5
5
  private cacheFile;
6
+ private deviceId;
6
7
  constructor(brain: Brain);
7
8
  /**
8
- * Check if the license is valid (server-verified).
9
+ * Check if the license is valid (server-verified + device limit).
9
10
  * Uses local cache if verified within 7 days.
10
11
  */
11
12
  isPremium(): Promise<boolean>;
13
+ /**
14
+ * Get the rejection reason (for error messages).
15
+ */
16
+ getRejectionReason(): Promise<string | null>;
12
17
  /**
13
18
  * Get current license info.
14
19
  */
15
20
  getLicenseInfo(): Promise<LicenseInfo>;
16
21
  /**
17
- * Legacy compatibility — canUse now just checks isPremium for everything.
22
+ * Legacy compatibility.
18
23
  */
19
24
  canUse(_toolName: string): Promise<boolean>;
25
+ /**
26
+ * Generate a unique device fingerprint from hardware characteristics.
27
+ */
28
+ private generateDeviceFingerprint;
20
29
  /**
21
30
  * Resolve the license key — env var takes priority over manifest.
22
31
  */
23
32
  private resolveKey;
24
33
  /**
25
34
  * Basic format validation — prefix + length + characters.
26
- * Does NOT verify the key is real. Use verifyWithServer() for that.
27
35
  */
28
36
  private validateFormat;
29
37
  /**
30
- * Verify license key against Firestore REST API.
31
- * Checks if document exists in license-checks/{key} with status 'active'.
38
+ * Verify license AND register this device.
39
+ * Returns { valid, status } where status explains why if invalid.
40
+ */
41
+ private verifyAndRegisterDevice;
42
+ /**
43
+ * Fetch license document from Firestore REST API.
44
+ */
45
+ private fetchLicenseDoc;
46
+ /**
47
+ * Update the devices array in Firestore via REST API PATCH.
32
48
  */
33
- private verifyWithServer;
49
+ private updateDevices;
34
50
  private readCache;
35
51
  private writeCache;
36
52
  private getInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../src/engine/license.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsBrD,qBAAa,aAAa;IAGZ,OAAO,CAAC,KAAK;IAFzB,OAAO,CAAC,SAAS,CAAS;gBAEN,KAAK,EAAE,KAAK;IAIhC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IA8BnC;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAM5C;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMjD;;OAEG;YACW,UAAU;IAUxB;;;OAGG;IACH,OAAO,CAAC,cAAc;IAStB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;YAuDV,SAAS;YAUT,UAAU;IAQxB,OAAO,CAAC,OAAO;CAUhB"}
1
+ {"version":3,"file":"license.d.ts","sourceRoot":"","sources":["../../src/engine/license.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmCrD,qBAAa,aAAa;IAIZ,OAAO,CAAC,KAAK;IAHzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;gBAEL,KAAK,EAAE,KAAK;IAKhC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IA+BnC;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAYlD;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAM5C;;OAEG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMjD;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAYjC;;OAEG;YACW,UAAU;IAYxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;;OAGG;YACW,uBAAuB;IAsCrC;;OAEG;IACH,OAAO,CAAC,eAAe;IA0BvB;;OAEG;IACH,OAAO,CAAC,aAAa;YA6CP,SAAS;YAUT,UAAU;IAQxB,OAAO,CAAC,OAAO;CAUhB"}