memoir-cli 1.2.1 → 1.3.0
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/package.json +1 -1
- package/src/adapters/restore.js +29 -4
- package/src/commands/init.js +61 -51
package/package.json
CHANGED
package/src/adapters/restore.js
CHANGED
|
@@ -5,6 +5,25 @@ import os from 'os';
|
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import { adapters } from '../adapters/index.js';
|
|
7
7
|
|
|
8
|
+
async function copyMissing(src, dest, spinner) {
|
|
9
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
10
|
+
for (const entry of entries) {
|
|
11
|
+
const srcPath = path.join(src, entry.name);
|
|
12
|
+
const destPath = path.join(dest, entry.name);
|
|
13
|
+
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
await fs.ensureDir(destPath);
|
|
16
|
+
await copyMissing(srcPath, destPath, spinner);
|
|
17
|
+
} else {
|
|
18
|
+
if (await fs.pathExists(destPath)) {
|
|
19
|
+
// skip existing files
|
|
20
|
+
} else {
|
|
21
|
+
await fs.copy(srcPath, destPath);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
8
27
|
export async function restoreMemories(sourceDir, spinner) {
|
|
9
28
|
let restoredAny = false;
|
|
10
29
|
|
|
@@ -19,7 +38,7 @@ export async function restoreMemories(sourceDir, spinner) {
|
|
|
19
38
|
{
|
|
20
39
|
type: 'confirm',
|
|
21
40
|
name: 'confirm',
|
|
22
|
-
message: `Restore ${adapter.name} memory?
|
|
41
|
+
message: `Restore ${adapter.name} memory? (only adds missing files, won't overwrite)`,
|
|
23
42
|
default: false
|
|
24
43
|
}
|
|
25
44
|
]);
|
|
@@ -28,16 +47,22 @@ export async function restoreMemories(sourceDir, spinner) {
|
|
|
28
47
|
|
|
29
48
|
if (confirm) {
|
|
30
49
|
if (adapter.customExtract) {
|
|
31
|
-
// Restore individual files
|
|
50
|
+
// Restore individual files — only add missing ones
|
|
32
51
|
const files = await fs.readdir(backupDir);
|
|
33
52
|
for (const file of files) {
|
|
34
53
|
const dest = path.join(adapter.source, file);
|
|
35
|
-
await fs.
|
|
54
|
+
if (await fs.pathExists(dest)) {
|
|
55
|
+
spinner.info(chalk.gray(` Skipped ${file} (already exists)`));
|
|
56
|
+
spinner.start();
|
|
57
|
+
} else {
|
|
58
|
+
await fs.copy(path.join(backupDir, file), dest);
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
} else {
|
|
38
62
|
spinner.text = `Restoring ${chalk.cyan(adapter.name)} memory to ${adapter.source}...`;
|
|
39
63
|
await fs.ensureDir(adapter.source);
|
|
40
|
-
|
|
64
|
+
// Merge — only copy files that don't already exist
|
|
65
|
+
await copyMissing(backupDir, adapter.source, spinner);
|
|
41
66
|
}
|
|
42
67
|
restoredAny = true;
|
|
43
68
|
} else {
|
package/src/commands/init.js
CHANGED
|
@@ -4,78 +4,88 @@ import open from 'open';
|
|
|
4
4
|
import boxen from 'boxen';
|
|
5
5
|
import gradient from 'gradient-string';
|
|
6
6
|
import { saveConfig } from '../config.js';
|
|
7
|
+
import { pushCommand } from './push.js';
|
|
8
|
+
import { restoreCommand } from './restore.js';
|
|
7
9
|
|
|
8
10
|
export async function initCommand() {
|
|
9
11
|
const title = gradient.pastel.multiline('memoir \\nYour AI Remembers Everything');
|
|
10
|
-
console.log('\\n' + boxen(title, {
|
|
11
|
-
padding: 1,
|
|
12
|
-
margin: 1,
|
|
13
|
-
borderStyle: 'round',
|
|
12
|
+
console.log('\\n' + boxen(title, {
|
|
13
|
+
padding: 1,
|
|
14
|
+
margin: 1,
|
|
15
|
+
borderStyle: 'round',
|
|
14
16
|
borderColor: 'cyan',
|
|
15
17
|
align: 'center'
|
|
16
18
|
}));
|
|
17
19
|
|
|
18
|
-
console.log(chalk.gray("Let's
|
|
20
|
+
console.log(chalk.gray("Let's get your AI memory set up.\\n"));
|
|
19
21
|
|
|
20
|
-
const
|
|
22
|
+
const { direction } = await inquirer.prompt([
|
|
21
23
|
{
|
|
22
24
|
type: 'list',
|
|
23
|
-
name: '
|
|
24
|
-
message: '
|
|
25
|
+
name: 'direction',
|
|
26
|
+
message: 'What do you want to do?',
|
|
25
27
|
choices: [
|
|
26
|
-
{ name: '
|
|
27
|
-
{ name: '
|
|
28
|
+
{ name: '⬆️ Upload ' + chalk.gray('(backup this machine\'s AI memory)'), value: 'upload' },
|
|
29
|
+
{ name: '⬇️ Download ' + chalk.gray('(restore AI memory to this machine)'), value: 'download' }
|
|
28
30
|
]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
message: 'Enter the full path to your sync directory ' + chalk.gray('(e.g., ~/Dropbox/memoir):'),
|
|
34
|
-
when: (answers) => answers.provider === 'local',
|
|
35
|
-
validate: (input) => input.trim() !== '' ? true : chalk.red('✖ Path is required')
|
|
36
|
-
},
|
|
31
|
+
}
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
const { provider } = await inquirer.prompt([
|
|
37
35
|
{
|
|
38
|
-
type: '
|
|
39
|
-
name: '
|
|
40
|
-
message: '
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
type: 'list',
|
|
37
|
+
name: 'provider',
|
|
38
|
+
message: 'Where do you want to store it?',
|
|
39
|
+
choices: [
|
|
40
|
+
{ name: '☁️ GitHub ' + chalk.gray('(sync across computers)'), value: 'git' },
|
|
41
|
+
{ name: '📂 Local Directory ' + chalk.gray('(Dropbox, iCloud, etc.)'), value: 'local' }
|
|
42
|
+
]
|
|
43
43
|
}
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
console.log(chalk.cyan('\\n↗ Opening GitHub... Create an empty private repository, then return here.\\n'));
|
|
48
|
-
await open('https://github.com/new');
|
|
49
|
-
}
|
|
46
|
+
let config = { provider };
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
if (provider === 'local') {
|
|
49
|
+
const { localPath } = await inquirer.prompt([
|
|
50
|
+
{
|
|
51
|
+
type: 'input',
|
|
52
|
+
name: 'localPath',
|
|
53
|
+
message: 'Path to sync directory ' + chalk.gray('(e.g., ~/Dropbox/memoir):'),
|
|
54
|
+
validate: (input) => input.trim() !== '' ? true : chalk.red('✖ Path is required')
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
config.localPath = localPath;
|
|
58
|
+
} else {
|
|
59
|
+
const { repoInput } = await inquirer.prompt([
|
|
60
|
+
{
|
|
61
|
+
type: 'input',
|
|
62
|
+
name: 'repoInput',
|
|
63
|
+
message: 'GitHub repo ' + chalk.gray('(e.g., camgitt/brain):'),
|
|
64
|
+
validate: (input) => {
|
|
65
|
+
if (input.trim() === '') return chalk.red('✖ Repo is required');
|
|
66
|
+
return true;
|
|
61
67
|
}
|
|
62
|
-
return true;
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
]);
|
|
69
|
+
]);
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
// Accept shorthand like "camgitt/brain" or full URLs
|
|
72
|
+
let gitRepo = repoInput.trim();
|
|
73
|
+
if (!gitRepo.includes('github.com') && !gitRepo.includes('gitlab.com')) {
|
|
74
|
+
gitRepo = `https://github.com/${gitRepo}.git`;
|
|
75
|
+
}
|
|
76
|
+
config.gitRepo = gitRepo;
|
|
77
|
+
}
|
|
72
78
|
|
|
73
79
|
await saveConfig(config);
|
|
74
80
|
|
|
75
|
-
console.log('\\n' +
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
console.log('\\n' + chalk.green('✔ Configuration saved!'));
|
|
82
|
+
|
|
83
|
+
// Immediately run the chosen action
|
|
84
|
+
if (direction === 'upload') {
|
|
85
|
+
console.log(chalk.cyan('\\n↗ Uploading your AI memory...\\n'));
|
|
86
|
+
await pushCommand();
|
|
87
|
+
} else {
|
|
88
|
+
console.log(chalk.cyan('\\n↙ Downloading your AI memory...\\n'));
|
|
89
|
+
await restoreCommand();
|
|
90
|
+
}
|
|
81
91
|
}
|