brain-memory 0.1.0-beta.2 → 0.1.0-beta.20
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/README.md +270 -72
- package/assets/icon.png +0 -0
- package/assets/icon.svg +27 -0
- package/bin/brain.js +111 -0
- package/bin/cloud-sync.js +149 -0
- package/bin/install.js +217 -242
- package/bin/memorize.js +433 -0
- package/bin/pin.js +44 -0
- package/bin/recall.js +237 -0
- package/bin/reinforce.js +187 -0
- package/bin/session-start.js +292 -0
- package/bin/skill.js +67 -0
- package/bin/unpin.js +38 -0
- package/commands/brain/consolidate.md +7 -2
- package/commands/brain/explore.md +7 -2
- package/commands/brain/forget.md +7 -2
- package/commands/brain/init.md +8 -12
- package/commands/brain/memorize.md +76 -144
- package/commands/brain/pin.md +37 -0
- package/commands/brain/remember.md +48 -105
- package/commands/brain/review.md +7 -2
- package/commands/brain/skills.md +60 -0
- package/commands/brain/sleep.md +68 -27
- package/commands/brain/status.md +19 -5
- package/commands/brain/sunshine.md +18 -13
- package/commands/brain/sync.md +360 -0
- package/commands/brain/unpin.md +26 -0
- package/package.json +18 -8
- package/prompts/claude.md +115 -12
- package/prompts/gemini.md +115 -12
- package/prompts/openai.md +113 -10
- package/prompts/opencode.md +178 -0
- package/src/cloud-sync.js +524 -0
- package/src/crypto.js +130 -0
- package/src/export-import.js +185 -0
- package/src/git-sync.js +444 -0
- package/src/index-manager.js +205 -18
- package/src/installer.js +384 -0
- package/src/pinning.js +124 -0
- package/src/scorer.js +6 -2
- package/src/skills.js +208 -0
- package/src/tfidf.js +408 -0
- package/hooks/session-end.md +0 -48
- package/hooks/session-start.md +0 -48
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,123 +23,66 @@ 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
|
-
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('gemini')) runtimes.push('gemini');
|
|
53
|
+
if (flags.has('openai') || flags.has('codex')) runtimes.push('openai');
|
|
54
|
+
if (flags.has('opencode')) runtimes.push('opencode');
|
|
55
|
+
if (flags.has('all')) return ['claude', 'gemini', 'openai', 'opencode'];
|
|
56
|
+
return runtimes;
|
|
106
57
|
}
|
|
107
58
|
|
|
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!`);
|
|
59
|
+
function resolveScopeFromFlags(flags) {
|
|
60
|
+
if (flags.has('global')) return 'global';
|
|
61
|
+
if (flags.has('local')) return 'local';
|
|
62
|
+
return null;
|
|
133
63
|
}
|
|
134
64
|
|
|
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';
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Install (original behavior, refactored from main)
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
async function runInstall(flags) {
|
|
69
|
+
let runtimes = resolveRuntimesFromFlags(flags);
|
|
70
|
+
let scope = resolveScopeFromFlags(flags);
|
|
159
71
|
|
|
160
72
|
const rl = createRL();
|
|
161
73
|
|
|
162
74
|
try {
|
|
163
75
|
// Interactive runtime selection
|
|
164
76
|
if (runtimes.length === 0) {
|
|
165
|
-
console.log('
|
|
166
|
-
console.log('
|
|
167
|
-
console.log('
|
|
168
|
-
console.log('
|
|
169
|
-
console.log('
|
|
77
|
+
console.log(' Which runtimes would you like to install for?\n');
|
|
78
|
+
console.log(' 1) Claude Code');
|
|
79
|
+
console.log(' 2) Gemini CLI');
|
|
80
|
+
console.log(' 3) OpenAI Codex CLI');
|
|
81
|
+
console.log(' 4) OpenCode');
|
|
82
|
+
console.log(' 5) All');
|
|
170
83
|
console.log('');
|
|
171
84
|
|
|
172
|
-
const choice = await ask(rl, '
|
|
85
|
+
const choice = await ask(rl, ' Select (1/2/3/4/5): ');
|
|
173
86
|
switch (choice.trim()) {
|
|
174
87
|
case '1':
|
|
175
88
|
runtimes = ['claude'];
|
|
@@ -181,22 +94,25 @@ async function main() {
|
|
|
181
94
|
runtimes = ['openai'];
|
|
182
95
|
break;
|
|
183
96
|
case '4':
|
|
184
|
-
runtimes = ['
|
|
97
|
+
runtimes = ['opencode'];
|
|
98
|
+
break;
|
|
99
|
+
case '5':
|
|
100
|
+
runtimes = ['claude', 'gemini', 'openai', 'opencode'];
|
|
185
101
|
break;
|
|
186
102
|
default:
|
|
187
|
-
console.log('
|
|
103
|
+
console.log(' Invalid choice. Defaulting to Claude Code.');
|
|
188
104
|
runtimes = ['claude'];
|
|
189
105
|
}
|
|
190
106
|
}
|
|
191
107
|
|
|
192
108
|
// Interactive scope selection
|
|
193
109
|
if (!scope) {
|
|
194
|
-
console.log('\n
|
|
195
|
-
console.log('
|
|
196
|
-
console.log('
|
|
110
|
+
console.log('\n Installation scope:\n');
|
|
111
|
+
console.log(' 1) Global — Available in all projects (~/.claude/, ~/.gemini/, ~/.codex/, ~/.config/opencode/)');
|
|
112
|
+
console.log(' 2) Local — This project only (./.claude/, ./.gemini/, ./.codex/, ./.opencode/)');
|
|
197
113
|
console.log('');
|
|
198
114
|
|
|
199
|
-
const choice = await ask(rl, '
|
|
115
|
+
const choice = await ask(rl, ' Select (1/2): ');
|
|
200
116
|
scope = choice.trim() === '2' ? 'local' : 'global';
|
|
201
117
|
}
|
|
202
118
|
|
|
@@ -204,18 +120,28 @@ async function main() {
|
|
|
204
120
|
console.log('');
|
|
205
121
|
const initBrain = await ask(
|
|
206
122
|
rl,
|
|
207
|
-
' Initialize
|
|
123
|
+
' Initialize ~/.brain/ directory? (Y/n): '
|
|
208
124
|
);
|
|
209
125
|
|
|
210
126
|
// Perform installation
|
|
211
127
|
console.log('\n Installing...');
|
|
212
128
|
for (const runtime of runtimes) {
|
|
129
|
+
const config = RUNTIMES[runtime];
|
|
130
|
+
console.log(`\n Installing for ${config.name} (${scope})...`);
|
|
213
131
|
installForRuntime(runtime, scope);
|
|
132
|
+
console.log(` Done!`);
|
|
214
133
|
}
|
|
215
134
|
|
|
216
135
|
// Initialize .brain if requested
|
|
217
136
|
if (initBrain.trim().toLowerCase() !== 'n') {
|
|
218
|
-
initializeBrain();
|
|
137
|
+
const result = initializeBrain();
|
|
138
|
+
if (result.alreadyExists) {
|
|
139
|
+
console.log('\n ~/.brain/ already exists, skipping initialization.');
|
|
140
|
+
} else {
|
|
141
|
+
console.log('\n ~/.brain/ initialized successfully.');
|
|
142
|
+
console.log('');
|
|
143
|
+
console.log(' Use /brain:sync to set up portable sync across devices.');
|
|
144
|
+
}
|
|
219
145
|
}
|
|
220
146
|
|
|
221
147
|
console.log(`
|
|
@@ -232,6 +158,7 @@ async function main() {
|
|
|
232
158
|
/brain:sunshine Deep forensic memory erasure
|
|
233
159
|
/brain:sleep Full maintenance cycle
|
|
234
160
|
/brain:status Brain overview dashboard
|
|
161
|
+
/brain:sync Sync memories via Git remote or export/import
|
|
235
162
|
|
|
236
163
|
Get started by running /brain:init in your agent session.
|
|
237
164
|
`);
|
|
@@ -240,122 +167,170 @@ async function main() {
|
|
|
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
|
});
|