brain-memory 0.1.0-beta.6 → 0.1.0-beta.7
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 +16 -0
- package/bin/install.js +208 -22
- package/package.json +1 -1
- package/src/git-sync.js +10 -0
- package/src/installer.js +108 -0
package/README.md
CHANGED
|
@@ -57,6 +57,22 @@ npx brain-memory --codex --global # OpenAI Codex CLI, global
|
|
|
57
57
|
npx brain-memory --all --global # All runtimes, global
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
### Update
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npx brain-memory@beta update
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Auto-detects installed runtimes and refreshes commands + prompt sections. Target specific runtimes with `--claude`, `--gemini`, `--openai`, or `--all`.
|
|
67
|
+
|
|
68
|
+
### Uninstall
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npx brain-memory@beta uninstall
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Removes commands and prompt sections. Your `.brain/` directory (memories) is preserved by default. Add `--delete-data` to remove it too. Use `--yes` to skip confirmation prompts.
|
|
75
|
+
|
|
60
76
|
### Manual Install
|
|
61
77
|
|
|
62
78
|
Copy the `commands/brain/` directory to your agent's commands folder:
|
package/bin/install.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const readline = require('readline');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
4
6
|
const {
|
|
5
7
|
RUNTIMES,
|
|
6
8
|
installForRuntime,
|
|
7
9
|
initializeBrain,
|
|
10
|
+
detectInstallations,
|
|
11
|
+
uninstallForRuntime,
|
|
8
12
|
} = require('../src/installer');
|
|
9
13
|
|
|
10
14
|
function createRL() {
|
|
@@ -18,30 +22,50 @@ function ask(rl, question) {
|
|
|
18
22
|
return new Promise((resolve) => rl.question(question, resolve));
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
║ ║
|
|
27
|
-
║ Hierarchical memory system for AI coding agents ║
|
|
28
|
-
║ ║
|
|
29
|
-
╚══════════════════════════════════════════════════════╝
|
|
30
|
-
`);
|
|
25
|
+
function parseArgs(argv) {
|
|
26
|
+
const args = argv.slice(2);
|
|
27
|
+
const subcommands = ['install', 'update', 'uninstall'];
|
|
28
|
+
let subcommand = 'install';
|
|
29
|
+
const flags = new Set();
|
|
31
30
|
|
|
32
|
-
const
|
|
33
|
-
|
|
31
|
+
for (const arg of args) {
|
|
32
|
+
const clean = arg.replace(/^--/, '');
|
|
33
|
+
if (subcommands.includes(clean) && arg === clean) {
|
|
34
|
+
// positional subcommand (no --)
|
|
35
|
+
subcommand = clean;
|
|
36
|
+
} else if (clean === 'update') {
|
|
37
|
+
subcommand = 'update';
|
|
38
|
+
} else if (clean === 'uninstall') {
|
|
39
|
+
subcommand = 'uninstall';
|
|
40
|
+
} else {
|
|
41
|
+
flags.add(clean);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
return { subcommand, flags };
|
|
46
|
+
}
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
function resolveRuntimesFromFlags(flags) {
|
|
49
|
+
const runtimes = [];
|
|
39
50
|
if (flags.has('claude')) runtimes.push('claude');
|
|
40
51
|
if (flags.has('gemini')) runtimes.push('gemini');
|
|
41
52
|
if (flags.has('openai') || flags.has('codex')) runtimes.push('openai');
|
|
42
|
-
if (flags.has('all'))
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
if (flags.has('all')) return ['claude', 'gemini', 'openai'];
|
|
54
|
+
return runtimes;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function resolveScopeFromFlags(flags) {
|
|
58
|
+
if (flags.has('global')) return 'global';
|
|
59
|
+
if (flags.has('local')) return 'local';
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Install (original behavior, refactored from main)
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
async function runInstall(flags) {
|
|
67
|
+
let runtimes = resolveRuntimesFromFlags(flags);
|
|
68
|
+
let scope = resolveScopeFromFlags(flags);
|
|
45
69
|
|
|
46
70
|
const rl = createRL();
|
|
47
71
|
|
|
@@ -110,8 +134,7 @@ async function main() {
|
|
|
110
134
|
} else {
|
|
111
135
|
console.log('\n .brain/ initialized successfully.');
|
|
112
136
|
console.log('');
|
|
113
|
-
console.log('
|
|
114
|
-
console.log(' Dropbox, Google Drive, or OneDrive for cross-device access.');
|
|
137
|
+
console.log(' Use /brain:sync to set up portable sync across devices.');
|
|
115
138
|
}
|
|
116
139
|
}
|
|
117
140
|
|
|
@@ -129,7 +152,7 @@ async function main() {
|
|
|
129
152
|
/brain:sunshine Deep forensic memory erasure
|
|
130
153
|
/brain:sleep Full maintenance cycle
|
|
131
154
|
/brain:status Brain overview dashboard
|
|
132
|
-
/brain:sync
|
|
155
|
+
/brain:sync Sync memories via Git remote or export/import
|
|
133
156
|
|
|
134
157
|
Get started by running /brain:init in your agent session.
|
|
135
158
|
`);
|
|
@@ -138,7 +161,170 @@ async function main() {
|
|
|
138
161
|
}
|
|
139
162
|
}
|
|
140
163
|
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// Update
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
async function runUpdate(flags) {
|
|
168
|
+
const pkg = JSON.parse(
|
|
169
|
+
fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8')
|
|
170
|
+
);
|
|
171
|
+
const version = pkg.version;
|
|
172
|
+
|
|
173
|
+
console.log(' Detecting existing installations...\n');
|
|
174
|
+
|
|
175
|
+
let detections = detectInstallations();
|
|
176
|
+
|
|
177
|
+
// Filter by explicit flags if provided
|
|
178
|
+
const filterRuntimes = resolveRuntimesFromFlags(flags);
|
|
179
|
+
const filterScope = resolveScopeFromFlags(flags);
|
|
180
|
+
if (filterRuntimes.length > 0) {
|
|
181
|
+
detections = detections.filter((d) => filterRuntimes.includes(d.runtime));
|
|
182
|
+
}
|
|
183
|
+
if (filterScope) {
|
|
184
|
+
detections = detections.filter((d) => d.scope === filterScope);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (detections.length === 0) {
|
|
188
|
+
console.log(' No existing brain-memory installations found.\n');
|
|
189
|
+
console.log(' To install, run: npx brain-memory@beta');
|
|
190
|
+
if (filterRuntimes.length > 0) {
|
|
191
|
+
console.log(` (Searched for: ${filterRuntimes.join(', ')})`);
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
console.log(` Found ${detections.length} installation(s):\n`);
|
|
197
|
+
for (const d of detections) {
|
|
198
|
+
const parts = [];
|
|
199
|
+
if (d.commandsFound) parts.push('commands');
|
|
200
|
+
if (d.promptFound) parts.push('prompt');
|
|
201
|
+
console.log(` ${d.runtimeName} (${d.scope}) — ${parts.join(' + ')}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
console.log('\n Updating...');
|
|
205
|
+
for (const d of detections) {
|
|
206
|
+
console.log(`\n Updating ${d.runtimeName} (${d.scope})...`);
|
|
207
|
+
installForRuntime(d.runtime, d.scope);
|
|
208
|
+
console.log(' Done!');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
console.log(`\n ✓ Updated to v${version}\n`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// Uninstall
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
async function runUninstall(flags) {
|
|
218
|
+
console.log(' Detecting existing installations...\n');
|
|
219
|
+
|
|
220
|
+
let detections = detectInstallations();
|
|
221
|
+
|
|
222
|
+
// Filter by explicit flags if provided
|
|
223
|
+
const filterRuntimes = resolveRuntimesFromFlags(flags);
|
|
224
|
+
const filterScope = resolveScopeFromFlags(flags);
|
|
225
|
+
if (filterRuntimes.length > 0) {
|
|
226
|
+
detections = detections.filter((d) => filterRuntimes.includes(d.runtime));
|
|
227
|
+
}
|
|
228
|
+
if (filterScope) {
|
|
229
|
+
detections = detections.filter((d) => d.scope === filterScope);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (detections.length === 0) {
|
|
233
|
+
console.log(' No existing brain-memory installations found. Nothing to uninstall.\n');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
console.log(` Will remove ${detections.length} installation(s):\n`);
|
|
238
|
+
for (const d of detections) {
|
|
239
|
+
const parts = [];
|
|
240
|
+
if (d.commandsFound) parts.push('commands');
|
|
241
|
+
if (d.promptFound) parts.push('prompt section');
|
|
242
|
+
console.log(` ${d.runtimeName} (${d.scope}) — ${parts.join(' + ')}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Confirm unless --yes
|
|
246
|
+
if (!flags.has('yes') && !flags.has('y')) {
|
|
247
|
+
const rl = createRL();
|
|
248
|
+
try {
|
|
249
|
+
console.log('');
|
|
250
|
+
const answer = await ask(rl, ' Proceed? (y/N): ');
|
|
251
|
+
if (answer.trim().toLowerCase() !== 'y') {
|
|
252
|
+
console.log('\n Cancelled.\n');
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
rl.close();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log('\n Uninstalling...');
|
|
261
|
+
for (const d of detections) {
|
|
262
|
+
console.log(`\n Removing ${d.runtimeName} (${d.scope})...`);
|
|
263
|
+
uninstallForRuntime(d.runtime, d.scope);
|
|
264
|
+
console.log(' Done!');
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Handle .brain/ data
|
|
268
|
+
const brainDir = path.join(process.cwd(), '.brain');
|
|
269
|
+
if (fs.existsSync(brainDir)) {
|
|
270
|
+
if (flags.has('delete-data')) {
|
|
271
|
+
fs.rmSync(brainDir, { recursive: true, force: true });
|
|
272
|
+
console.log('\n Deleted .brain/ directory.');
|
|
273
|
+
} else if (!flags.has('yes') && !flags.has('y')) {
|
|
274
|
+
const rl = createRL();
|
|
275
|
+
try {
|
|
276
|
+
console.log('');
|
|
277
|
+
const answer = await ask(
|
|
278
|
+
rl,
|
|
279
|
+
' Delete .brain/ data directory? This removes all memories. (y/N): '
|
|
280
|
+
);
|
|
281
|
+
if (answer.trim().toLowerCase() === 'y') {
|
|
282
|
+
fs.rmSync(brainDir, { recursive: true, force: true });
|
|
283
|
+
console.log(' Deleted .brain/ directory.');
|
|
284
|
+
} else {
|
|
285
|
+
console.log(' Kept .brain/ directory (your memories are preserved).');
|
|
286
|
+
}
|
|
287
|
+
} finally {
|
|
288
|
+
rl.close();
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
console.log('\n Kept .brain/ directory (use --delete-data to remove memories).');
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
console.log('\n ✓ Uninstall complete.\n');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
// Main
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
async function main() {
|
|
302
|
+
console.log(`
|
|
303
|
+
╔══════════════════════════════════════════════════════╗
|
|
304
|
+
║ ║
|
|
305
|
+
║ 🧠 Brain Memory — Installer ║
|
|
306
|
+
║ ║
|
|
307
|
+
║ Hierarchical memory system for AI coding agents ║
|
|
308
|
+
║ ║
|
|
309
|
+
╚══════════════════════════════════════════════════════╝
|
|
310
|
+
`);
|
|
311
|
+
|
|
312
|
+
const { subcommand, flags } = parseArgs(process.argv);
|
|
313
|
+
|
|
314
|
+
switch (subcommand) {
|
|
315
|
+
case 'update':
|
|
316
|
+
await runUpdate(flags);
|
|
317
|
+
break;
|
|
318
|
+
case 'uninstall':
|
|
319
|
+
await runUninstall(flags);
|
|
320
|
+
break;
|
|
321
|
+
default:
|
|
322
|
+
await runInstall(flags);
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
141
327
|
main().catch((err) => {
|
|
142
|
-
console.error('
|
|
328
|
+
console.error('Operation failed:', err.message);
|
|
143
329
|
process.exit(1);
|
|
144
330
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brain-memory",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.7",
|
|
4
4
|
"description": "A brain-inspired hierarchical memory system for AI coding agents. Deep nested file structure that mimics human memory with time-decay and strength-based recall.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
package/src/git-sync.js
CHANGED
|
@@ -43,10 +43,20 @@ function checkGitAvailable() {
|
|
|
43
43
|
* @returns {string} stdout (trimmed)
|
|
44
44
|
*/
|
|
45
45
|
function git(repoDir, args, opts = {}) {
|
|
46
|
+
// Explicitly set GIT_DIR and GIT_WORK_TREE to prevent git from walking up
|
|
47
|
+
// the directory tree and finding the parent project's .git directory.
|
|
48
|
+
// Without this, if .brain/.sync/repo/.git doesn't exist yet (first push or
|
|
49
|
+
// failed init), git operations would silently affect the parent project repo.
|
|
50
|
+
const env = {
|
|
51
|
+
...process.env,
|
|
52
|
+
GIT_DIR: path.join(repoDir, '.git'),
|
|
53
|
+
GIT_WORK_TREE: repoDir,
|
|
54
|
+
};
|
|
46
55
|
return execFileSync('git', args, {
|
|
47
56
|
cwd: repoDir,
|
|
48
57
|
stdio: 'pipe',
|
|
49
58
|
encoding: 'utf8',
|
|
59
|
+
env,
|
|
50
60
|
...opts,
|
|
51
61
|
}).trim();
|
|
52
62
|
}
|
package/src/installer.js
CHANGED
|
@@ -89,6 +89,110 @@ function injectPrompt(targetDir, promptFile, promptSource) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
function detectInstallations() {
|
|
93
|
+
const results = [];
|
|
94
|
+
for (const [runtime, config] of Object.entries(RUNTIMES)) {
|
|
95
|
+
for (const scope of ['global', 'local']) {
|
|
96
|
+
const targetDir = scope === 'global' ? config.globalDir : config.localDir;
|
|
97
|
+
const promptTarget = scope === 'global' ? config.globalDir : '.';
|
|
98
|
+
const promptPath = path.join(promptTarget, config.promptFile);
|
|
99
|
+
|
|
100
|
+
// Check for command files/dirs
|
|
101
|
+
let commandsFound = false;
|
|
102
|
+
if (config.commandStyle === 'skills') {
|
|
103
|
+
const skillsDir = path.join(targetDir, config.commandsSubdir);
|
|
104
|
+
commandsFound = fs.existsSync(path.join(skillsDir, 'brain-init', 'SKILL.md'));
|
|
105
|
+
} else {
|
|
106
|
+
const commandsDir = path.join(targetDir, config.commandsSubdir, 'brain');
|
|
107
|
+
commandsFound = fs.existsSync(commandsDir) &&
|
|
108
|
+
fs.readdirSync(commandsDir).some((f) => f.endsWith('.md'));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Check for prompt markers
|
|
112
|
+
let promptFound = false;
|
|
113
|
+
if (fs.existsSync(promptPath)) {
|
|
114
|
+
const content = fs.readFileSync(promptPath, 'utf-8');
|
|
115
|
+
promptFound = content.includes(BRAIN_MARKER_START) && content.includes(BRAIN_MARKER_END);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (commandsFound || promptFound) {
|
|
119
|
+
results.push({
|
|
120
|
+
runtime,
|
|
121
|
+
scope,
|
|
122
|
+
runtimeName: config.name,
|
|
123
|
+
commandsFound,
|
|
124
|
+
promptFound,
|
|
125
|
+
targetDir,
|
|
126
|
+
promptPath,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return results;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function removePromptSection(promptPath) {
|
|
135
|
+
if (!fs.existsSync(promptPath)) {
|
|
136
|
+
return { removed: false, reason: 'file-not-found' };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const content = fs.readFileSync(promptPath, 'utf-8');
|
|
140
|
+
const startIdx = content.indexOf(BRAIN_MARKER_START);
|
|
141
|
+
const endIdx = content.indexOf(BRAIN_MARKER_END);
|
|
142
|
+
|
|
143
|
+
if (startIdx === -1 || endIdx === -1) {
|
|
144
|
+
return { removed: false, reason: 'no-markers' };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const before = content.substring(0, startIdx);
|
|
148
|
+
const after = content.substring(endIdx + BRAIN_MARKER_END.length);
|
|
149
|
+
const remaining = (before + after).trim();
|
|
150
|
+
|
|
151
|
+
if (remaining.length === 0) {
|
|
152
|
+
fs.unlinkSync(promptPath);
|
|
153
|
+
return { removed: true, fileDeleted: true };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
fs.writeFileSync(promptPath, remaining + '\n');
|
|
157
|
+
return { removed: true, fileDeleted: false };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function removeCommands(targetDir, config) {
|
|
161
|
+
const removed = [];
|
|
162
|
+
|
|
163
|
+
if (config.commandStyle === 'skills') {
|
|
164
|
+
const skillsDir = path.join(targetDir, config.commandsSubdir);
|
|
165
|
+
if (fs.existsSync(skillsDir)) {
|
|
166
|
+
const entries = fs.readdirSync(skillsDir).filter((d) => d.startsWith('brain-'));
|
|
167
|
+
for (const entry of entries) {
|
|
168
|
+
const fullPath = path.join(skillsDir, entry);
|
|
169
|
+
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
170
|
+
removed.push(fullPath);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
const commandsDir = path.join(targetDir, config.commandsSubdir, 'brain');
|
|
175
|
+
if (fs.existsSync(commandsDir)) {
|
|
176
|
+
removed.push(commandsDir);
|
|
177
|
+
fs.rmSync(commandsDir, { recursive: true, force: true });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return removed;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function uninstallForRuntime(runtime, scope) {
|
|
185
|
+
const config = RUNTIMES[runtime];
|
|
186
|
+
const targetDir = scope === 'global' ? config.globalDir : config.localDir;
|
|
187
|
+
const promptTarget = scope === 'global' ? config.globalDir : '.';
|
|
188
|
+
const promptPath = path.join(promptTarget, config.promptFile);
|
|
189
|
+
|
|
190
|
+
const removedCommands = removeCommands(targetDir, config);
|
|
191
|
+
const promptResult = removePromptSection(promptPath);
|
|
192
|
+
|
|
193
|
+
return { removedCommands, promptResult };
|
|
194
|
+
}
|
|
195
|
+
|
|
92
196
|
function installForRuntime(runtime, scope) {
|
|
93
197
|
const config = RUNTIMES[runtime];
|
|
94
198
|
const targetDir = scope === 'global' ? config.globalDir : config.localDir;
|
|
@@ -228,4 +332,8 @@ module.exports = {
|
|
|
228
332
|
injectPrompt,
|
|
229
333
|
installForRuntime,
|
|
230
334
|
initializeBrain,
|
|
335
|
+
detectInstallations,
|
|
336
|
+
removePromptSection,
|
|
337
|
+
removeCommands,
|
|
338
|
+
uninstallForRuntime,
|
|
231
339
|
};
|