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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memoir-cli",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Your AI remembers everything. Sync it everywhere.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -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? This will overwrite existing configuration files!`,
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 back to their original locations
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.copy(path.join(backupDir, file), dest, { overwrite: true });
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
- await fs.copy(backupDir, adapter.source, { overwrite: true });
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 {
@@ -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 configure where your AI knowledge will be safely stored.\\n"));
20
+ console.log(chalk.gray("Let's get your AI memory set up.\\n"));
19
21
 
20
- const answers = await inquirer.prompt([
22
+ const { direction } = await inquirer.prompt([
21
23
  {
22
24
  type: 'list',
23
- name: 'provider',
24
- message: 'Choose your storage provider:',
25
+ name: 'direction',
26
+ message: 'What do you want to do?',
25
27
  choices: [
26
- { name: '☁️ Git Repository ' + chalk.gray('(GitHub, GitLab - Best for syncing across computers)'), value: 'git' },
27
- { name: '📂 Local Directory ' + chalk.gray('(Dropbox, iCloud - Best for local backups)'), value: 'local' }
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
- type: 'input',
32
- name: 'localPath',
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: 'confirm',
39
- name: 'openBrowser',
40
- message: 'Need to create an empty GitHub repository right now?',
41
- when: (answers) => answers.provider === 'git',
42
- default: false
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
- if (answers.openBrowser) {
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
- const finalAnswers = await inquirer.prompt([
52
- {
53
- type: 'input',
54
- name: 'gitRepo',
55
- message: 'Repository URL ' + chalk.gray('(e.g., git@github.com:username/ai-memory.git):'),
56
- when: () => answers.provider === 'git',
57
- validate: (input) => {
58
- if (input.trim() === '') return chalk.red('✖ Repo URL is required');
59
- if (!input.includes('github.com') && !input.includes('gitlab.com')) {
60
- return chalk.yellow('⚠ Warning: This does not look like a standard GitHub/GitLab URL. Please verify.');
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
- const config = {
68
- provider: answers.provider,
69
- localPath: answers.localPath,
70
- gitRepo: finalAnswers.gitRepo
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' + boxen(
76
- chalk.green('✔ Configuration saved successfully!') + '\\n\\n' +
77
- chalk.white('To backup your memory, run:') + '\\n' +
78
- chalk.cyan.bold('memoir push'),
79
- { padding: 1, borderStyle: 'single', borderColor: 'green' }
80
- ) + '\\n');
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
  }