brain-memory 0.1.0-beta.3 → 0.1.0-beta.30
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/CHANGELOG.md +319 -0
- package/README.md +379 -95
- package/SECURITY.md +61 -0
- package/assets/brand/README.md +28 -0
- package/assets/brand/icon-dark.svg +19 -0
- package/assets/brand/icon-light.svg +20 -0
- package/assets/brand/linkedin_cover.png +0 -0
- package/assets/brand/linkedin_cover_light.png +0 -0
- package/assets/brand/mark-dark.svg +19 -0
- package/assets/brand/mark-light.svg +20 -0
- package/assets/brand/png/icon-dark-1024.png +0 -0
- package/assets/brand/png/icon-dark-128.png +0 -0
- package/assets/brand/png/icon-dark-256.png +0 -0
- package/assets/brand/png/icon-dark-512.png +0 -0
- package/assets/brand/png/icon-dark-64.png +0 -0
- package/assets/brand/png/icon-light-1024.png +0 -0
- package/assets/brand/png/icon-light-128.png +0 -0
- package/assets/brand/png/icon-light-256.png +0 -0
- package/assets/brand/png/icon-light-512.png +0 -0
- package/assets/brand/png/icon-light-64.png +0 -0
- package/assets/brand/png/mark-dark-1024.png +0 -0
- package/assets/brand/png/mark-light-1024.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +19 -0
- package/bin/brain.js +111 -0
- package/bin/cloud-sync.js +150 -0
- package/bin/forget.js +122 -0
- package/bin/install.js +229 -254
- package/bin/memorize.js +458 -0
- package/bin/pin.js +44 -0
- package/bin/recall.js +251 -0
- package/bin/reinforce.js +187 -0
- package/bin/session-start.js +298 -0
- package/bin/skill.js +67 -0
- package/bin/unpin.js +38 -0
- package/commands/brain/forget.md +245 -15
- package/commands/brain/memorize.md +76 -144
- package/commands/brain/pin.md +79 -0
- package/commands/brain/remember.md +48 -105
- package/commands/brain/skills.md +60 -0
- package/commands/brain/sleep.md +69 -28
- package/commands/brain/status.md +24 -10
- package/commands/brain/sync.md +386 -0
- package/package.json +22 -8
- package/prompts/antigravity.md +180 -0
- package/prompts/claude.md +124 -20
- package/prompts/openai.md +124 -20
- package/prompts/opencode.md +179 -0
- package/src/cloud-sync.js +534 -0
- package/src/crypto.js +130 -0
- package/src/export-import.js +200 -0
- package/src/git-sync.js +444 -0
- package/src/index-manager.js +219 -18
- package/src/installer.js +444 -0
- package/src/pinning.js +124 -0
- package/src/scorer.js +22 -9
- package/src/skills.js +208 -0
- package/src/tfidf.js +501 -0
- package/commands/brain/consolidate.md +0 -153
- package/commands/brain/explore.md +0 -79
- package/commands/brain/init.md +0 -157
- package/commands/brain/review.md +0 -130
- package/commands/brain/sunshine.md +0 -337
- package/hooks/session-end.md +0 -48
- package/hooks/session-start.md +0 -48
- 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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
42
|
+
flags.add(clean);
|
|
66
43
|
}
|
|
67
44
|
}
|
|
68
|
-
}
|
|
69
45
|
|
|
70
|
-
|
|
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
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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('
|
|
166
|
-
console.log('
|
|
167
|
-
console.log('
|
|
168
|
-
console.log('
|
|
169
|
-
console.log('
|
|
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, '
|
|
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 = ['
|
|
93
|
+
runtimes = ['openai'];
|
|
179
94
|
break;
|
|
180
95
|
case '3':
|
|
181
|
-
runtimes = ['
|
|
96
|
+
runtimes = ['opencode'];
|
|
182
97
|
break;
|
|
183
98
|
case '4':
|
|
184
|
-
runtimes = ['
|
|
99
|
+
runtimes = ['antigravity'];
|
|
100
|
+
break;
|
|
101
|
+
case '5':
|
|
102
|
+
runtimes = ['claude', 'openai', 'opencode'];
|
|
185
103
|
break;
|
|
186
104
|
default:
|
|
187
|
-
console.log('
|
|
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
|
|
195
|
-
console.log('
|
|
196
|
-
console.log('
|
|
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, '
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
244
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
262
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
);
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
// Uninstall
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
async function runUninstall(flags) {
|
|
224
|
+
console.log(' Detecting existing installations...\n');
|
|
294
225
|
|
|
295
|
-
|
|
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
|
-
//
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
//
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
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
|
-
|
|
338
|
-
for (const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
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('
|
|
334
|
+
console.error('Operation failed:', err.message);
|
|
360
335
|
process.exit(1);
|
|
361
336
|
});
|