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/src/git-sync.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brain Memory — Git Sync Engine
|
|
3
|
+
*
|
|
4
|
+
* Push/pull ~/.brain/ memories via any Git remote (GitHub, GitLab, Codeberg, etc.).
|
|
5
|
+
* A hidden git repo lives at ~/.brain/.sync/repo/ — the project's own git history
|
|
6
|
+
* is never touched.
|
|
7
|
+
*
|
|
8
|
+
* Zero external dependencies — uses child_process.execFileSync to call the git binary.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { execFileSync } = require('child_process');
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { encrypt, decrypt } = require('./crypto');
|
|
15
|
+
|
|
16
|
+
const SYNC_DIR = '.sync';
|
|
17
|
+
const REPO_DIR = 'repo';
|
|
18
|
+
const CONFIG_FILE = 'config.json';
|
|
19
|
+
|
|
20
|
+
// Files/dirs inside ~/.brain/ that should NOT be synced
|
|
21
|
+
const EXCLUDED = new Set(['.sync', '.DS_Store']);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check whether `git` is available on PATH.
|
|
25
|
+
*
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
function checkGitAvailable() {
|
|
29
|
+
try {
|
|
30
|
+
execFileSync('git', ['--version'], { stdio: 'pipe' });
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Run a git command inside the sync repo.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} repoDir - Absolute path to ~/.brain/.sync/repo/
|
|
41
|
+
* @param {string[]} args - Git arguments
|
|
42
|
+
* @param {Object} [opts] - Extra execFileSync options
|
|
43
|
+
* @returns {string} stdout (trimmed)
|
|
44
|
+
*/
|
|
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
|
+
};
|
|
55
|
+
return execFileSync('git', args, {
|
|
56
|
+
cwd: repoDir,
|
|
57
|
+
stdio: 'pipe',
|
|
58
|
+
encoding: 'utf8',
|
|
59
|
+
env,
|
|
60
|
+
...opts,
|
|
61
|
+
}).trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Resolve paths for sync infrastructure.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
68
|
+
* @returns {{ syncDir: string, repoDir: string, configPath: string }}
|
|
69
|
+
*/
|
|
70
|
+
function resolvePaths(brainDir) {
|
|
71
|
+
const syncDir = path.join(brainDir, SYNC_DIR);
|
|
72
|
+
const repoDir = path.join(syncDir, REPO_DIR);
|
|
73
|
+
const configPath = path.join(syncDir, CONFIG_FILE);
|
|
74
|
+
return { syncDir, repoDir, configPath };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Initialize a git repo inside ~/.brain/.sync/repo/.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
81
|
+
* @returns {{ repoDir: string }} Created repo path
|
|
82
|
+
*/
|
|
83
|
+
function initSyncRepo(brainDir) {
|
|
84
|
+
const { repoDir } = resolvePaths(brainDir);
|
|
85
|
+
fs.mkdirSync(repoDir, { recursive: true });
|
|
86
|
+
|
|
87
|
+
git(repoDir, ['init', '-b', 'main']);
|
|
88
|
+
git(repoDir, ['config', 'user.email', 'brain-memory@local']);
|
|
89
|
+
git(repoDir, ['config', 'user.name', 'Brain Memory']);
|
|
90
|
+
|
|
91
|
+
return { repoDir };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Configure (or update) the remote URL for the sync repo.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
98
|
+
* @param {string} remoteUrl - Git remote URL (SSH or HTTPS)
|
|
99
|
+
*/
|
|
100
|
+
function configureRemote(brainDir, remoteUrl) {
|
|
101
|
+
const { repoDir } = resolvePaths(brainDir);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
git(repoDir, ['remote', 'get-url', 'origin']);
|
|
105
|
+
// Remote exists — update it
|
|
106
|
+
git(repoDir, ['remote', 'set-url', 'origin', remoteUrl]);
|
|
107
|
+
} catch {
|
|
108
|
+
// Remote doesn't exist — add it
|
|
109
|
+
git(repoDir, ['remote', 'add', 'origin', remoteUrl]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Copy ~/.brain/ files into the sync repo, excluding .sync/.
|
|
115
|
+
* If encryption is enabled, files are encrypted before writing.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
118
|
+
* @param {string} repoDir - Absolute path to ~/.brain/.sync/repo/
|
|
119
|
+
* @param {string|null} passphrase - Encryption passphrase or null
|
|
120
|
+
*/
|
|
121
|
+
function copyBrainToRepo(brainDir, repoDir, passphrase) {
|
|
122
|
+
// Clean existing tracked files in repo (except .git)
|
|
123
|
+
const entries = fs.readdirSync(repoDir);
|
|
124
|
+
for (const entry of entries) {
|
|
125
|
+
if (entry === '.git') continue;
|
|
126
|
+
fs.rmSync(path.join(repoDir, entry), { recursive: true, force: true });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Recursively copy ~/.brain/ → repo/
|
|
130
|
+
copyDir(brainDir, repoDir, brainDir, passphrase);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Recursively copy a directory, excluding EXCLUDED entries.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} srcDir - Source directory
|
|
137
|
+
* @param {string} destDir - Destination directory
|
|
138
|
+
* @param {string} brainDir - Root brain dir (for relative path calculation)
|
|
139
|
+
* @param {string|null} passphrase - Encryption passphrase or null
|
|
140
|
+
*/
|
|
141
|
+
function copyDir(srcDir, destDir, brainDir, passphrase) {
|
|
142
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true });
|
|
143
|
+
for (const entry of entries) {
|
|
144
|
+
const rel = path.relative(brainDir, path.join(srcDir, entry.name));
|
|
145
|
+
const topLevel = rel.split(path.sep)[0];
|
|
146
|
+
if (EXCLUDED.has(topLevel)) continue;
|
|
147
|
+
|
|
148
|
+
const srcPath = path.join(srcDir, entry.name);
|
|
149
|
+
const destPath = path.join(destDir, entry.name);
|
|
150
|
+
|
|
151
|
+
if (entry.isDirectory()) {
|
|
152
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
153
|
+
copyDir(srcPath, destPath, brainDir, passphrase);
|
|
154
|
+
} else {
|
|
155
|
+
const content = fs.readFileSync(srcPath);
|
|
156
|
+
if (passphrase) {
|
|
157
|
+
fs.writeFileSync(destPath, encrypt(content.toString('utf8'), passphrase));
|
|
158
|
+
} else {
|
|
159
|
+
fs.writeFileSync(destPath, content);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Copy files from the sync repo back into ~/.brain/.
|
|
167
|
+
* If encryption is enabled, files are decrypted after reading.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} repoDir - Absolute path to ~/.brain/.sync/repo/
|
|
170
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
171
|
+
* @param {string|null} passphrase - Decryption passphrase or null
|
|
172
|
+
*/
|
|
173
|
+
function copyRepoToBrain(repoDir, brainDir, passphrase) {
|
|
174
|
+
copyRepoDir(repoDir, brainDir, repoDir, passphrase);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Recursively copy repo files back to brain.
|
|
179
|
+
*/
|
|
180
|
+
function copyRepoDir(srcDir, destDir, repoDir, passphrase) {
|
|
181
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true });
|
|
182
|
+
for (const entry of entries) {
|
|
183
|
+
if (entry.name === '.git') continue;
|
|
184
|
+
|
|
185
|
+
const srcPath = path.join(srcDir, entry.name);
|
|
186
|
+
const destPath = path.join(destDir, entry.name);
|
|
187
|
+
|
|
188
|
+
if (entry.isDirectory()) {
|
|
189
|
+
fs.mkdirSync(destPath, { recursive: true });
|
|
190
|
+
copyRepoDir(srcPath, destPath, repoDir, passphrase);
|
|
191
|
+
} else {
|
|
192
|
+
const content = fs.readFileSync(srcPath);
|
|
193
|
+
if (passphrase) {
|
|
194
|
+
fs.writeFileSync(destPath, decrypt(content, passphrase));
|
|
195
|
+
} else {
|
|
196
|
+
fs.writeFileSync(destPath, content);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get a summary of local vs remote sync status.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
206
|
+
* @returns {{ configured: boolean, remote: string|null, branch: string|null, ahead: number, behind: number, lastPush: string|null }}
|
|
207
|
+
*/
|
|
208
|
+
function getStatus(brainDir) {
|
|
209
|
+
const { repoDir, configPath } = resolvePaths(brainDir);
|
|
210
|
+
const config = readConfig(configPath);
|
|
211
|
+
|
|
212
|
+
if (!config) {
|
|
213
|
+
return { configured: false, remote: null, branch: null, ahead: 0, behind: 0, lastPush: null };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let ahead = 0;
|
|
217
|
+
let behind = 0;
|
|
218
|
+
|
|
219
|
+
if (fs.existsSync(path.join(repoDir, '.git'))) {
|
|
220
|
+
try {
|
|
221
|
+
git(repoDir, ['fetch', 'origin'], { timeout: 15000 });
|
|
222
|
+
} catch {
|
|
223
|
+
// Offline or remote not reachable — use cached state
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
const counts = git(repoDir, ['rev-list', '--left-right', '--count', 'main...origin/main']);
|
|
228
|
+
const parts = counts.split(/\s+/);
|
|
229
|
+
ahead = parseInt(parts[0], 10) || 0;
|
|
230
|
+
behind = parseInt(parts[1], 10) || 0;
|
|
231
|
+
} catch {
|
|
232
|
+
// No remote tracking yet (first push not done)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
configured: true,
|
|
238
|
+
remote: config.remote || null,
|
|
239
|
+
branch: config.branch || 'main',
|
|
240
|
+
ahead,
|
|
241
|
+
behind,
|
|
242
|
+
lastPush: config.lastPush || null,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Push ~/.brain/ contents to the remote.
|
|
248
|
+
*
|
|
249
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
250
|
+
* @param {string} [message] - Commit message (defaults to timestamp)
|
|
251
|
+
* @param {string} [passphrase] - Encryption passphrase (if configured)
|
|
252
|
+
* @returns {{ committed: boolean, pushed: boolean, message: string }}
|
|
253
|
+
*/
|
|
254
|
+
function push(brainDir, message, passphrase) {
|
|
255
|
+
const { repoDir, configPath } = resolvePaths(brainDir);
|
|
256
|
+
const config = readConfig(configPath);
|
|
257
|
+
if (!config) throw new Error('Sync not configured. Run /brain:sync setup first.');
|
|
258
|
+
|
|
259
|
+
const pass = config.encrypt ? passphrase : null;
|
|
260
|
+
if (config.encrypt && !passphrase) {
|
|
261
|
+
throw new Error('Encryption is enabled but no passphrase provided.');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Ensure repo exists
|
|
265
|
+
if (!fs.existsSync(path.join(repoDir, '.git'))) {
|
|
266
|
+
initSyncRepo(brainDir);
|
|
267
|
+
if (config.remote) configureRemote(brainDir, config.remote);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Copy brain files into repo
|
|
271
|
+
copyBrainToRepo(brainDir, repoDir, pass);
|
|
272
|
+
|
|
273
|
+
// Stage all changes
|
|
274
|
+
git(repoDir, ['add', '-A']);
|
|
275
|
+
|
|
276
|
+
// Check if there's anything to commit
|
|
277
|
+
const status = git(repoDir, ['status', '--porcelain']);
|
|
278
|
+
if (!status) {
|
|
279
|
+
return { committed: false, pushed: false, message: 'Nothing to push — no changes.' };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Commit
|
|
283
|
+
const commitMsg = message || `brain sync ${new Date().toISOString()}`;
|
|
284
|
+
git(repoDir, ['commit', '-m', commitMsg]);
|
|
285
|
+
|
|
286
|
+
// Push
|
|
287
|
+
let pushed = false;
|
|
288
|
+
if (config.remote) {
|
|
289
|
+
try {
|
|
290
|
+
git(repoDir, ['push', '-u', 'origin', 'main'], { timeout: 30000 });
|
|
291
|
+
pushed = true;
|
|
292
|
+
} catch (err) {
|
|
293
|
+
return { committed: true, pushed: false, message: `Committed locally but push failed: ${err.message}` };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Update lastPush
|
|
298
|
+
config.lastPush = new Date().toISOString();
|
|
299
|
+
writeConfig(configPath, config);
|
|
300
|
+
|
|
301
|
+
return { committed: true, pushed, message: `Pushed successfully at ${config.lastPush}` };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Pull remote changes into ~/.brain/.
|
|
306
|
+
*
|
|
307
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
308
|
+
* @param {string} [passphrase] - Decryption passphrase (if configured)
|
|
309
|
+
* @returns {{ pulled: boolean, message: string }}
|
|
310
|
+
*/
|
|
311
|
+
function pull(brainDir, passphrase) {
|
|
312
|
+
const { repoDir, configPath } = resolvePaths(brainDir);
|
|
313
|
+
const config = readConfig(configPath);
|
|
314
|
+
if (!config) throw new Error('Sync not configured. Run /brain:sync setup first.');
|
|
315
|
+
|
|
316
|
+
const pass = config.encrypt ? passphrase : null;
|
|
317
|
+
if (config.encrypt && !passphrase) {
|
|
318
|
+
throw new Error('Encryption is enabled but no passphrase provided.');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (!fs.existsSync(path.join(repoDir, '.git'))) {
|
|
322
|
+
initSyncRepo(brainDir);
|
|
323
|
+
if (config.remote) configureRemote(brainDir, config.remote);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Try fast-forward pull first
|
|
327
|
+
let pulled = false;
|
|
328
|
+
let hasConflicts = false;
|
|
329
|
+
let conflictFiles = [];
|
|
330
|
+
|
|
331
|
+
try {
|
|
332
|
+
git(repoDir, ['pull', 'origin', 'main', '--ff-only'], { timeout: 30000 });
|
|
333
|
+
pulled = true;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
// Fast-forward failed — try fetch + merge
|
|
336
|
+
try {
|
|
337
|
+
git(repoDir, ['fetch', 'origin'], { timeout: 15000 });
|
|
338
|
+
} catch {
|
|
339
|
+
return { pulled: false, hasConflicts: false, message: 'Remote is unreachable.' };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
git(repoDir, ['merge', 'origin/main']);
|
|
344
|
+
pulled = true;
|
|
345
|
+
} catch {
|
|
346
|
+
// Check for unmerged paths
|
|
347
|
+
try {
|
|
348
|
+
const status = git(repoDir, ['status', '--porcelain']);
|
|
349
|
+
conflictFiles = status
|
|
350
|
+
.split('\n')
|
|
351
|
+
.filter((line) => line.startsWith('U') || line.startsWith('AA') || line.startsWith('DD'))
|
|
352
|
+
.map((line) => line.slice(3));
|
|
353
|
+
hasConflicts = conflictFiles.length > 0;
|
|
354
|
+
} catch { /* ignore status errors */ }
|
|
355
|
+
|
|
356
|
+
// Abort the failed merge to leave repo clean
|
|
357
|
+
try {
|
|
358
|
+
git(repoDir, ['merge', '--abort']);
|
|
359
|
+
} catch { /* ignore if nothing to abort */ }
|
|
360
|
+
|
|
361
|
+
if (hasConflicts) {
|
|
362
|
+
return {
|
|
363
|
+
pulled: false,
|
|
364
|
+
hasConflicts: true,
|
|
365
|
+
conflictFiles,
|
|
366
|
+
message: `Merge conflict in ${conflictFiles.length} file(s). Push your local changes first or manually resolve.`,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return { pulled: false, hasConflicts: false, message: 'Remote has no commits yet or merge failed.' };
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Copy repo files back to brain
|
|
375
|
+
copyRepoToBrain(repoDir, brainDir, pass);
|
|
376
|
+
|
|
377
|
+
// Update config
|
|
378
|
+
config.lastPull = new Date().toISOString();
|
|
379
|
+
writeConfig(configPath, config);
|
|
380
|
+
|
|
381
|
+
return { pulled: true, hasConflicts: false, message: `Pulled successfully at ${config.lastPull}` };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Read sync config from ~/.brain/.sync/config.json.
|
|
386
|
+
*
|
|
387
|
+
* @param {string} configPath - Absolute path to config.json
|
|
388
|
+
* @returns {Object|null}
|
|
389
|
+
*/
|
|
390
|
+
function readConfig(configPath) {
|
|
391
|
+
try {
|
|
392
|
+
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
393
|
+
} catch {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Write sync config to ~/.brain/.sync/config.json.
|
|
400
|
+
*
|
|
401
|
+
* @param {string} configPath - Absolute path to config.json
|
|
402
|
+
* @param {Object} config
|
|
403
|
+
*/
|
|
404
|
+
function writeConfig(configPath, config) {
|
|
405
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
406
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Read the sync config for a brain directory.
|
|
411
|
+
*
|
|
412
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
413
|
+
* @returns {Object|null}
|
|
414
|
+
*/
|
|
415
|
+
function getSyncConfig(brainDir) {
|
|
416
|
+
const { configPath } = resolvePaths(brainDir);
|
|
417
|
+
return readConfig(configPath);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Write the sync config for a brain directory.
|
|
422
|
+
*
|
|
423
|
+
* @param {string} brainDir - Absolute path to ~/.brain/
|
|
424
|
+
* @param {Object} config
|
|
425
|
+
*/
|
|
426
|
+
function writeSyncConfig(brainDir, config) {
|
|
427
|
+
const { configPath } = resolvePaths(brainDir);
|
|
428
|
+
writeConfig(configPath, config);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
module.exports = {
|
|
432
|
+
checkGitAvailable,
|
|
433
|
+
initSyncRepo,
|
|
434
|
+
configureRemote,
|
|
435
|
+
getStatus,
|
|
436
|
+
push,
|
|
437
|
+
pull,
|
|
438
|
+
getSyncConfig,
|
|
439
|
+
writeSyncConfig,
|
|
440
|
+
// Internal — exported for testing
|
|
441
|
+
copyBrainToRepo,
|
|
442
|
+
copyRepoToBrain,
|
|
443
|
+
resolvePaths,
|
|
444
|
+
};
|