brain-memory 0.1.0-beta.3 → 0.1.0-beta.31

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 (66) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/README.md +400 -94
  3. package/SECURITY.md +61 -0
  4. package/assets/brand/README.md +28 -0
  5. package/assets/brand/icon-dark.svg +19 -0
  6. package/assets/brand/icon-light.svg +20 -0
  7. package/assets/brand/linkedin_cover.png +0 -0
  8. package/assets/brand/linkedin_cover_light.png +0 -0
  9. package/assets/brand/mark-dark.svg +19 -0
  10. package/assets/brand/mark-light.svg +20 -0
  11. package/assets/brand/png/icon-dark-1024.png +0 -0
  12. package/assets/brand/png/icon-dark-128.png +0 -0
  13. package/assets/brand/png/icon-dark-256.png +0 -0
  14. package/assets/brand/png/icon-dark-512.png +0 -0
  15. package/assets/brand/png/icon-dark-64.png +0 -0
  16. package/assets/brand/png/icon-light-1024.png +0 -0
  17. package/assets/brand/png/icon-light-128.png +0 -0
  18. package/assets/brand/png/icon-light-256.png +0 -0
  19. package/assets/brand/png/icon-light-512.png +0 -0
  20. package/assets/brand/png/icon-light-64.png +0 -0
  21. package/assets/brand/png/mark-dark-1024.png +0 -0
  22. package/assets/brand/png/mark-light-1024.png +0 -0
  23. package/assets/icon.png +0 -0
  24. package/assets/icon.svg +19 -0
  25. package/bin/brain.js +111 -0
  26. package/bin/cloud-sync.js +150 -0
  27. package/bin/forget.js +122 -0
  28. package/bin/install.js +229 -254
  29. package/bin/memorize.js +458 -0
  30. package/bin/pin.js +44 -0
  31. package/bin/recall.js +259 -0
  32. package/bin/reinforce.js +187 -0
  33. package/bin/session-start.js +298 -0
  34. package/bin/skill.js +67 -0
  35. package/bin/unpin.js +38 -0
  36. package/commands/brain/forget.md +245 -15
  37. package/commands/brain/memorize.md +76 -144
  38. package/commands/brain/pin.md +79 -0
  39. package/commands/brain/remember.md +48 -105
  40. package/commands/brain/skills.md +60 -0
  41. package/commands/brain/sleep.md +69 -28
  42. package/commands/brain/status.md +24 -10
  43. package/commands/brain/sync.md +386 -0
  44. package/package.json +22 -8
  45. package/prompts/antigravity.md +180 -0
  46. package/prompts/claude.md +124 -20
  47. package/prompts/openai.md +124 -20
  48. package/prompts/opencode.md +179 -0
  49. package/src/cloud-sync.js +534 -0
  50. package/src/crypto.js +130 -0
  51. package/src/export-import.js +200 -0
  52. package/src/git-sync.js +444 -0
  53. package/src/index-manager.js +219 -18
  54. package/src/installer.js +444 -0
  55. package/src/pinning.js +124 -0
  56. package/src/scorer.js +45 -11
  57. package/src/skills.js +208 -0
  58. package/src/tfidf.js +520 -0
  59. package/commands/brain/consolidate.md +0 -153
  60. package/commands/brain/explore.md +0 -79
  61. package/commands/brain/init.md +0 -157
  62. package/commands/brain/review.md +0 -130
  63. package/commands/brain/sunshine.md +0 -337
  64. package/hooks/session-end.md +0 -48
  65. package/hooks/session-start.md +0 -48
  66. package/prompts/gemini.md +0 -76
package/bin/install.js CHANGED
@@ -1,46 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const readline = require('readline');
3
4
  const fs = require('fs');
4
5
  const path = require('path');
5
- const readline = require('readline');
6
-
7
- const PACKAGE_ROOT = path.resolve(__dirname, '..');
8
-
9
- const RUNTIMES = {
10
- claude: {
11
- name: 'Claude Code',
12
- globalDir: path.join(require('os').homedir(), '.claude'),
13
- localDir: '.claude',
14
- commandsSubdir: 'commands',
15
- promptFile: 'CLAUDE.md',
16
- promptSource: 'claude.md',
17
- settingsFile: 'settings.json',
18
- commandStyle: 'flat',
19
- },
20
- gemini: {
21
- name: 'Gemini CLI',
22
- globalDir: path.join(require('os').homedir(), '.gemini'),
23
- localDir: '.gemini',
24
- commandsSubdir: 'commands',
25
- promptFile: 'GEMINI.md',
26
- promptSource: 'gemini.md',
27
- settingsFile: null,
28
- commandStyle: 'flat',
29
- },
30
- openai: {
31
- name: 'OpenAI Codex CLI',
32
- globalDir: path.join(require('os').homedir(), '.codex'),
33
- localDir: '.codex',
34
- commandsSubdir: 'skills',
35
- promptFile: 'AGENTS.md',
36
- promptSource: 'openai.md',
37
- settingsFile: null,
38
- commandStyle: 'skills',
39
- },
40
- };
41
-
42
- const BRAIN_MARKER_START = '<!-- BRAIN-MEMORY-START -->';
43
- const BRAIN_MARKER_END = '<!-- BRAIN-MEMORY-END -->';
6
+ const os = require('os');
7
+ const {
8
+ RUNTIMES,
9
+ installForRuntime,
10
+ initializeBrain,
11
+ detectInstallations,
12
+ uninstallForRuntime,
13
+ } = require('../src/installer');
44
14
 
45
15
  function createRL() {
46
16
  return readline.createInterface({
@@ -53,150 +23,98 @@ function ask(rl, question) {
53
23
  return new Promise((resolve) => rl.question(question, resolve));
54
24
  }
55
25
 
56
- function copyDir(src, dest) {
57
- fs.mkdirSync(dest, { recursive: true });
58
- const entries = fs.readdirSync(src, { withFileTypes: true });
59
- for (const entry of entries) {
60
- const srcPath = path.join(src, entry.name);
61
- const destPath = path.join(dest, entry.name);
62
- if (entry.isDirectory()) {
63
- copyDir(srcPath, destPath);
26
+ function parseArgs(argv) {
27
+ const args = argv.slice(2);
28
+ const subcommands = ['install', 'update', 'uninstall'];
29
+ let subcommand = 'install';
30
+ const flags = new Set();
31
+
32
+ for (const arg of args) {
33
+ const clean = arg.replace(/^--/, '');
34
+ if (subcommands.includes(clean) && arg === clean) {
35
+ // positional subcommand (no --)
36
+ subcommand = clean;
37
+ } else if (clean === 'update') {
38
+ subcommand = 'update';
39
+ } else if (clean === 'uninstall') {
40
+ subcommand = 'uninstall';
64
41
  } else {
65
- fs.copyFileSync(srcPath, destPath);
42
+ flags.add(clean);
66
43
  }
67
44
  }
68
- }
69
45
 
70
- function installSkills(commandsSrc, skillsDest) {
71
- const entries = fs.readdirSync(commandsSrc).filter((f) => f.endsWith('.md'));
72
- for (const file of entries) {
73
- const name = file.replace('.md', '');
74
- const skillDir = path.join(skillsDest, `brain-${name}`);
75
- fs.mkdirSync(skillDir, { recursive: true });
76
- fs.copyFileSync(
77
- path.join(commandsSrc, file),
78
- path.join(skillDir, 'SKILL.md')
79
- );
80
- }
46
+ return { subcommand, flags };
81
47
  }
82
48
 
83
- function injectPrompt(targetDir, promptFile, promptSource) {
84
- const promptContent = fs.readFileSync(
85
- path.join(PACKAGE_ROOT, 'prompts', promptSource),
86
- 'utf-8'
87
- );
88
- const targetPath = path.join(targetDir, promptFile);
89
-
90
- const wrappedContent = `\n${BRAIN_MARKER_START}\n${promptContent}\n${BRAIN_MARKER_END}\n`;
91
-
92
- if (fs.existsSync(targetPath)) {
93
- let existing = fs.readFileSync(targetPath, 'utf-8');
94
- // Remove old brain section if present
95
- const startIdx = existing.indexOf(BRAIN_MARKER_START);
96
- const endIdx = existing.indexOf(BRAIN_MARKER_END);
97
- if (startIdx !== -1 && endIdx !== -1) {
98
- existing =
99
- existing.substring(0, startIdx) +
100
- existing.substring(endIdx + BRAIN_MARKER_END.length);
101
- }
102
- fs.writeFileSync(targetPath, existing.trimEnd() + '\n' + wrappedContent);
103
- } else {
104
- fs.writeFileSync(targetPath, wrappedContent.trim() + '\n');
105
- }
49
+ function resolveRuntimesFromFlags(flags) {
50
+ const runtimes = [];
51
+ if (flags.has('claude')) runtimes.push('claude');
52
+ if (flags.has('openai') || flags.has('codex')) runtimes.push('openai');
53
+ if (flags.has('opencode')) runtimes.push('opencode');
54
+ if (flags.has('antigravity')) runtimes.push('antigravity');
55
+ // --all installs the verified CLIs. Antigravity stays opt-in (--antigravity)
56
+ // because its native paths are experimental / pending live verification.
57
+ if (flags.has('all')) return ['claude', 'openai', 'opencode'];
58
+ return runtimes;
106
59
  }
107
60
 
108
- function installForRuntime(runtime, scope) {
109
- const config = RUNTIMES[runtime];
110
- const targetDir = scope === 'global' ? config.globalDir : config.localDir;
111
- const commandsSrc = path.join(PACKAGE_ROOT, 'commands', 'brain');
112
-
113
- console.log(`\n Installing for ${config.name} (${scope})...`);
114
-
115
- if (config.commandStyle === 'skills') {
116
- // Codex: each command becomes a skill directory with SKILL.md
117
- const skillsDest = path.join(targetDir, config.commandsSubdir);
118
- console.log(` Installing skills to ${skillsDest}`);
119
- installSkills(commandsSrc, skillsDest);
120
- } else {
121
- // Claude / Gemini: flat copy into commands/brain/
122
- const commandsDest = path.join(targetDir, config.commandsSubdir, 'brain');
123
- console.log(` Copying commands to ${commandsDest}`);
124
- copyDir(commandsSrc, commandsDest);
125
- }
126
-
127
- // Inject prompt into CLAUDE.md / GEMINI.md / AGENTS.md
128
- const promptTarget = scope === 'global' ? config.globalDir : '.';
129
- console.log(` Injecting brain context into ${path.join(promptTarget, config.promptFile)}`);
130
- injectPrompt(promptTarget, config.promptFile, config.promptSource);
131
-
132
- console.log(` Done!`);
61
+ function resolveScopeFromFlags(flags) {
62
+ if (flags.has('global')) return 'global';
63
+ if (flags.has('local')) return 'local';
64
+ return null;
133
65
  }
134
66
 
135
- async function main() {
136
- console.log(`
137
- ╔══════════════════════════════════════════════════════╗
138
- ║ ║
139
- ║ 🧠 Brain Memory — Installer ║
140
- ║ ║
141
- ║ Hierarchical memory system for AI coding agents ║
142
- ║ ║
143
- ╚══════════════════════════════════════════════════════╝
144
- `);
145
-
146
- const args = process.argv.slice(2);
147
- const flags = new Set(args.map((a) => a.replace(/^--/, '')));
148
-
149
- let runtimes = [];
150
- let scope = null;
151
-
152
- // Check for non-interactive flags
153
- if (flags.has('claude')) runtimes.push('claude');
154
- if (flags.has('gemini')) runtimes.push('gemini');
155
- if (flags.has('openai') || flags.has('codex')) runtimes.push('openai');
156
- if (flags.has('all')) runtimes = ['claude', 'gemini', 'openai'];
157
- if (flags.has('global')) scope = 'global';
158
- if (flags.has('local')) scope = 'local';
67
+ // ---------------------------------------------------------------------------
68
+ // Install (original behavior, refactored from main)
69
+ // ---------------------------------------------------------------------------
70
+ async function runInstall(flags) {
71
+ let runtimes = resolveRuntimesFromFlags(flags);
72
+ let scope = resolveScopeFromFlags(flags);
159
73
 
160
74
  const rl = createRL();
161
75
 
162
76
  try {
163
77
  // Interactive runtime selection
164
78
  if (runtimes.length === 0) {
165
- console.log(' Which runtimes would you like to install for?\n');
166
- console.log(' 1) Claude Code');
167
- console.log(' 2) Gemini CLI');
168
- console.log(' 3) OpenAI Codex CLI');
169
- console.log(' 4) All');
79
+ console.log(' Which runtimes would you like to install for?\n');
80
+ console.log(' 1) Claude Code');
81
+ console.log(' 2) OpenAI Codex CLI');
82
+ console.log(' 3) OpenCode');
83
+ console.log(' 4) Google Antigravity (experimental)');
84
+ console.log(' 5) All current CLIs (Claude Code + Codex + OpenCode)');
170
85
  console.log('');
171
86
 
172
- const choice = await ask(rl, ' Select (1/2/3/4): ');
87
+ const choice = await ask(rl, ' Select (1/2/3/4/5): ');
173
88
  switch (choice.trim()) {
174
89
  case '1':
175
90
  runtimes = ['claude'];
176
91
  break;
177
92
  case '2':
178
- runtimes = ['gemini'];
93
+ runtimes = ['openai'];
179
94
  break;
180
95
  case '3':
181
- runtimes = ['openai'];
96
+ runtimes = ['opencode'];
182
97
  break;
183
98
  case '4':
184
- runtimes = ['claude', 'gemini', 'openai'];
99
+ runtimes = ['antigravity'];
100
+ break;
101
+ case '5':
102
+ runtimes = ['claude', 'openai', 'opencode'];
185
103
  break;
186
104
  default:
187
- console.log(' Invalid choice. Defaulting to Claude Code.');
105
+ console.log(' Invalid choice. Defaulting to Claude Code.');
188
106
  runtimes = ['claude'];
189
107
  }
190
108
  }
191
109
 
192
110
  // Interactive scope selection
193
111
  if (!scope) {
194
- console.log('\n Installation scope:\n');
195
- console.log(' 1) Global — Available in all projects (~/.claude/, ~/.gemini/, ~/.codex/)');
196
- console.log(' 2) Local — This project only (./.claude/, ./.gemini/, ./.codex/)');
112
+ console.log('\n Installation scope:\n');
113
+ console.log(' 1) Global — Available in all projects (~/.claude/, ~/.codex/, ~/.config/opencode/, ~/.agents/skills/)');
114
+ console.log(' 2) Local — This project only (./.claude/, ./.codex/, ./.opencode/, ./.agents/skills/)');
197
115
  console.log('');
198
116
 
199
- const choice = await ask(rl, ' Select (1/2): ');
117
+ const choice = await ask(rl, ' Select (1/2): ');
200
118
  scope = choice.trim() === '2' ? 'local' : 'global';
201
119
  }
202
120
 
@@ -204,158 +122,215 @@ async function main() {
204
122
  console.log('');
205
123
  const initBrain = await ask(
206
124
  rl,
207
- ' Initialize .brain/ directory in current project? (Y/n): '
125
+ ' Initialize ~/.brain/ directory? (Y/n): '
208
126
  );
209
127
 
210
128
  // Perform installation
211
129
  console.log('\n Installing...');
212
130
  for (const runtime of runtimes) {
131
+ const config = RUNTIMES[runtime];
132
+ console.log(`\n Installing for ${config.name} (${scope})...`);
213
133
  installForRuntime(runtime, scope);
134
+ console.log(` Done!`);
214
135
  }
215
136
 
216
137
  // Initialize .brain if requested
217
138
  if (initBrain.trim().toLowerCase() !== 'n') {
218
- initializeBrain();
139
+ const result = initializeBrain();
140
+ if (result.alreadyExists) {
141
+ console.log('\n ~/.brain/ already exists, skipping initialization.');
142
+ } else {
143
+ console.log('\n ~/.brain/ initialized successfully.');
144
+ console.log('');
145
+ console.log(' Use /brain:sync to set up portable sync across devices.');
146
+ }
219
147
  }
220
148
 
221
149
  console.log(`
222
150
  ✓ Installation complete!
223
151
 
224
152
  Available commands:
225
- /brain:init Initialize brain structure
226
- /brain:memorize Store a new memory
227
153
  /brain:remember Recall relevant memories
228
- /brain:review Spaced repetition review session
229
- /brain:explore Browse the brain hierarchy
230
- /brain:consolidate Merge related memories
231
- /brain:forget Decay or remove memories
232
- /brain:sunshine Deep forensic memory erasure
233
- /brain:sleep Full maintenance cycle
154
+ /brain:memorize Store a new memory
234
155
  /brain:status Brain overview dashboard
235
-
236
- Get started by running /brain:init in your agent session.
156
+ /brain:pin Pin (or unpin) a memory in the always-present tier
157
+ /brain:forget Decay, archive, or forensically erase (--deep) memories
158
+ /brain:sync Sync via Brain Cloud, Git remote, or export/import
159
+ /brain:skills Manage procedural skills
160
+ /brain:sleep Full maintenance cycle (usually automatic)
161
+
162
+ Your brain is ready — recall and memorize happen automatically. Just start working,
163
+ or run /brain:status to see an overview.
237
164
  `);
238
165
  } finally {
239
166
  rl.close();
240
167
  }
241
168
  }
242
169
 
243
- function initializeBrain() {
244
- const brainDir = path.join(process.cwd(), '.brain');
170
+ // ---------------------------------------------------------------------------
171
+ // Update
172
+ // ---------------------------------------------------------------------------
173
+ async function runUpdate(flags) {
174
+ const pkg = JSON.parse(
175
+ fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8')
176
+ );
177
+ const version = pkg.version;
245
178
 
246
- if (fs.existsSync(brainDir)) {
247
- console.log('\n .brain/ already exists, skipping initialization.');
248
- return;
179
+ console.log(' Detecting existing installations...\n');
180
+
181
+ let detections = detectInstallations();
182
+
183
+ // Filter by explicit flags if provided
184
+ const filterRuntimes = resolveRuntimesFromFlags(flags);
185
+ const filterScope = resolveScopeFromFlags(flags);
186
+ if (filterRuntimes.length > 0) {
187
+ detections = detections.filter((d) => filterRuntimes.includes(d.runtime));
188
+ }
189
+ if (filterScope) {
190
+ detections = detections.filter((d) => d.scope === filterScope);
249
191
  }
250
192
 
251
- console.log('\n Creating .brain/ directory structure...');
193
+ if (detections.length === 0) {
194
+ console.log(' No existing brain-memory installations found.\n');
195
+ console.log(' To install, run: npm install -g brain-memory@beta && brain-memory');
196
+ if (filterRuntimes.length > 0) {
197
+ console.log(` (Searched for: ${filterRuntimes.join(', ')})`);
198
+ }
199
+ return;
200
+ }
252
201
 
253
- const now = new Date().toISOString();
202
+ console.log(` Found ${detections.length} installation(s):\n`);
203
+ for (const d of detections) {
204
+ const parts = [];
205
+ if (d.commandsFound) parts.push('commands');
206
+ if (d.promptFound) parts.push('prompt');
207
+ console.log(` ${d.runtimeName} (${d.scope}) — ${parts.join(' + ')}`);
208
+ }
254
209
 
255
- // Create directories
256
- const categories = ['professional', 'personal', 'social', 'family', '_consolidated', '_archived'];
257
- for (const cat of categories) {
258
- fs.mkdirSync(path.join(brainDir, cat), { recursive: true });
210
+ console.log('\n Updating...');
211
+ for (const d of detections) {
212
+ console.log(`\n Updating ${d.runtimeName} (${d.scope})...`);
213
+ installForRuntime(d.runtime, d.scope);
214
+ console.log(' Done!');
259
215
  }
260
216
 
261
- // Create index.json
262
- const index = {
263
- version: 2,
264
- created: now,
265
- last_updated: now,
266
- memory_count: 0,
267
- memories: {},
268
- config: {
269
- max_depth: 6,
270
- consolidation_threshold: 0.3,
271
- decay_check_interval_days: 7,
272
- strength_boost_on_recall: 0.05,
273
- auto_consolidate: true,
274
- propagation_window_days: 7,
275
- association_config: {
276
- co_retrieval_boost: 0.10,
277
- link_decay_rate: 0.998,
278
- link_prune_threshold: 0.05,
279
- spreading_activation_depth: 2,
280
- spreading_activation_decay: 0.5,
281
- },
282
- },
283
- };
284
- fs.writeFileSync(
285
- path.join(brainDir, 'index.json'),
286
- JSON.stringify(index, null, 2) + '\n'
287
- );
217
+ console.log(`\n ✓ Updated to v${version}\n`);
218
+ }
288
219
 
289
- // Create associations.json
290
- fs.writeFileSync(
291
- path.join(brainDir, 'associations.json'),
292
- JSON.stringify({ version: 1, edges: {} }, null, 2) + '\n'
293
- );
220
+ // ---------------------------------------------------------------------------
221
+ // Uninstall
222
+ // ---------------------------------------------------------------------------
223
+ async function runUninstall(flags) {
224
+ console.log(' Detecting existing installations...\n');
294
225
 
295
- // Create contexts.json
296
- fs.writeFileSync(
297
- path.join(brainDir, 'contexts.json'),
298
- JSON.stringify({ version: 1, sessions: [] }, null, 2) + '\n'
299
- );
226
+ let detections = detectInstallations();
300
227
 
301
- // Create review-queue.json
302
- fs.writeFileSync(
303
- path.join(brainDir, 'review-queue.json'),
304
- JSON.stringify({ version: 1, items: [] }, null, 2) + '\n'
305
- );
228
+ // Filter by explicit flags if provided
229
+ const filterRuntimes = resolveRuntimesFromFlags(flags);
230
+ const filterScope = resolveScopeFromFlags(flags);
231
+ if (filterRuntimes.length > 0) {
232
+ detections = detections.filter((d) => filterRuntimes.includes(d.runtime));
233
+ }
234
+ if (filterScope) {
235
+ detections = detections.filter((d) => d.scope === filterScope);
236
+ }
306
237
 
307
- // Create _archived/index.json
308
- fs.writeFileSync(
309
- path.join(brainDir, '_archived', 'index.json'),
310
- JSON.stringify({ version: 1, archived_count: 0, memories: {} }, null, 2) + '\n'
311
- );
238
+ if (detections.length === 0) {
239
+ console.log(' No existing brain-memory installations found. Nothing to uninstall.\n');
240
+ return;
241
+ }
312
242
 
313
- // Load category descriptions from template
314
- const templatePath = path.join(PACKAGE_ROOT, 'templates', 'default-categories.json');
315
- let template = { top_categories: [] };
316
- if (fs.existsSync(templatePath)) {
317
- template = JSON.parse(fs.readFileSync(templatePath, 'utf-8'));
243
+ console.log(` Will remove ${detections.length} installation(s):\n`);
244
+ for (const d of detections) {
245
+ const parts = [];
246
+ if (d.commandsFound) parts.push('commands');
247
+ if (d.promptFound) parts.push('prompt section');
248
+ console.log(` ${d.runtimeName} (${d.scope}) — ${parts.join(' + ')}`);
318
249
  }
319
250
 
320
- // Create _meta.json for each category
321
- const mainCategories = ['professional', 'personal', 'social', 'family'];
322
- for (const cat of mainCategories) {
323
- const templateCat = template.top_categories.find((c) => c.name === cat) || {};
324
- const meta = {
325
- category: cat,
326
- description: templateCat.description || cat,
327
- created: now,
328
- memory_count: 0,
329
- subcategories: [],
330
- };
331
- fs.writeFileSync(
332
- path.join(brainDir, cat, '_meta.json'),
333
- JSON.stringify(meta, null, 2) + '\n'
334
- );
251
+ // Confirm unless --yes
252
+ if (!flags.has('yes') && !flags.has('y')) {
253
+ const rl = createRL();
254
+ try {
255
+ console.log('');
256
+ const answer = await ask(rl, ' Proceed? (y/N): ');
257
+ if (answer.trim().toLowerCase() !== 'y') {
258
+ console.log('\n Cancelled.\n');
259
+ return;
260
+ }
261
+ } finally {
262
+ rl.close();
263
+ }
335
264
  }
336
265
 
337
- // Create _meta.json for special directories
338
- for (const special of ['_consolidated', '_archived']) {
339
- const meta = {
340
- category: special,
341
- description:
342
- special === '_consolidated'
343
- ? 'Merged memories from consolidation operations'
344
- : 'Archived memories preserved for recovery',
345
- created: now,
346
- memory_count: 0,
347
- subcategories: [],
348
- };
349
- fs.writeFileSync(
350
- path.join(brainDir, special, '_meta.json'),
351
- JSON.stringify(meta, null, 2) + '\n'
352
- );
266
+ console.log('\n Uninstalling...');
267
+ for (const d of detections) {
268
+ console.log(`\n Removing ${d.runtimeName} (${d.scope})...`);
269
+ uninstallForRuntime(d.runtime, d.scope);
270
+ console.log(' Done!');
353
271
  }
354
272
 
355
- console.log(' .brain/ initialized successfully.');
273
+ // Handle .brain/ data
274
+ const brainDir = path.join(os.homedir(), '.brain');
275
+ if (fs.existsSync(brainDir)) {
276
+ if (flags.has('delete-data')) {
277
+ fs.rmSync(brainDir, { recursive: true, force: true });
278
+ console.log('\n Deleted ~/.brain/ directory.');
279
+ } else if (!flags.has('yes') && !flags.has('y')) {
280
+ const rl = createRL();
281
+ try {
282
+ console.log('');
283
+ const answer = await ask(
284
+ rl,
285
+ ' Delete ~/.brain/ data directory? This removes all memories. (y/N): '
286
+ );
287
+ if (answer.trim().toLowerCase() === 'y') {
288
+ fs.rmSync(brainDir, { recursive: true, force: true });
289
+ console.log(' Deleted ~/.brain/ directory.');
290
+ } else {
291
+ console.log(' Kept ~/.brain/ directory (your memories are preserved).');
292
+ }
293
+ } finally {
294
+ rl.close();
295
+ }
296
+ } else {
297
+ console.log('\n Kept ~/.brain/ directory (use --delete-data to remove memories).');
298
+ }
299
+ }
300
+
301
+ console.log('\n ✓ Uninstall complete.\n');
302
+ }
303
+
304
+ // ---------------------------------------------------------------------------
305
+ // Main
306
+ // ---------------------------------------------------------------------------
307
+ async function main() {
308
+ console.log(`
309
+ ╔══════════════════════════════════════════════════════╗
310
+ ║ ║
311
+ ║ ◉ Brain Memory — Installer ║
312
+ ║ ║
313
+ ║ Hierarchical memory system for AI coding agents ║
314
+ ║ ║
315
+ ╚══════════════════════════════════════════════════════╝
316
+ `);
317
+
318
+ const { subcommand, flags } = parseArgs(process.argv);
319
+
320
+ switch (subcommand) {
321
+ case 'update':
322
+ await runUpdate(flags);
323
+ break;
324
+ case 'uninstall':
325
+ await runUninstall(flags);
326
+ break;
327
+ default:
328
+ await runInstall(flags);
329
+ break;
330
+ }
356
331
  }
357
332
 
358
333
  main().catch((err) => {
359
- console.error('Installation failed:', err.message);
334
+ console.error('Operation failed:', err.message);
360
335
  process.exit(1);
361
336
  });