memoir-cli 1.4.0 → 1.4.2
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/commands/init.js +40 -51
- package/src/commands/view.js +2 -2
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import open from 'open';
|
|
4
3
|
import boxen from 'boxen';
|
|
5
4
|
import gradient from 'gradient-string';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
6
|
import { saveConfig } from '../config.js';
|
|
7
7
|
import { pushCommand } from './push.js';
|
|
8
8
|
import { restoreCommand } from './restore.js';
|
|
9
9
|
|
|
10
|
+
function getGitUsername() {
|
|
11
|
+
try {
|
|
12
|
+
return execSync('git config --global user.name', { encoding: 'utf8' }).trim();
|
|
13
|
+
} catch { return ''; }
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export async function initCommand() {
|
|
11
|
-
|
|
12
|
-
console.log(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
borderStyle: 'round',
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}));
|
|
17
|
+
console.log('');
|
|
18
|
+
console.log(boxen(
|
|
19
|
+
gradient.pastel('memoir') + '\n' +
|
|
20
|
+
chalk.gray('Your AI remembers everything.'),
|
|
21
|
+
{ padding: 1, margin: 0, borderStyle: 'round', borderColor: 'cyan', align: 'center' }
|
|
22
|
+
));
|
|
23
|
+
console.log('');
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
const gitUser = getGitUsername();
|
|
21
26
|
|
|
22
|
-
const { direction } = await inquirer.prompt([
|
|
27
|
+
const { direction, provider } = await inquirer.prompt([
|
|
23
28
|
{
|
|
24
29
|
type: 'list',
|
|
25
30
|
name: 'direction',
|
|
26
|
-
message: '
|
|
31
|
+
message: 'Upload or download?',
|
|
27
32
|
choices: [
|
|
28
|
-
{ name: '
|
|
29
|
-
{ name: '
|
|
33
|
+
{ name: 'Upload — back up this machine', value: 'upload' },
|
|
34
|
+
{ name: 'Download — restore from backup', value: 'download' }
|
|
30
35
|
]
|
|
31
|
-
}
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
const { provider } = await inquirer.prompt([
|
|
36
|
+
},
|
|
35
37
|
{
|
|
36
38
|
type: 'list',
|
|
37
39
|
name: 'provider',
|
|
38
|
-
message: '
|
|
40
|
+
message: (answers) => answers.direction === 'upload' ? 'Back up to?' : 'Restore from?',
|
|
39
41
|
choices: [
|
|
40
|
-
{ name: '
|
|
41
|
-
{ name: '
|
|
42
|
+
{ name: 'GitHub', value: 'git' },
|
|
43
|
+
{ name: 'Local folder', value: 'local' }
|
|
42
44
|
]
|
|
43
45
|
}
|
|
44
46
|
]);
|
|
@@ -46,46 +48,33 @@ export async function initCommand() {
|
|
|
46
48
|
let config = { provider };
|
|
47
49
|
|
|
48
50
|
if (provider === 'local') {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]);
|
|
51
|
+
const msg = direction === 'upload' ? 'Save to:' : 'Backup folder:';
|
|
52
|
+
const { localPath } = await inquirer.prompt([{
|
|
53
|
+
type: 'input',
|
|
54
|
+
name: 'localPath',
|
|
55
|
+
message: msg,
|
|
56
|
+
validate: (input) => input.trim() ? true : 'Required'
|
|
57
|
+
}]);
|
|
57
58
|
config.localPath = localPath;
|
|
58
59
|
} else {
|
|
59
|
-
const {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
]);
|
|
60
|
+
const { username } = await inquirer.prompt([{
|
|
61
|
+
type: 'input',
|
|
62
|
+
name: 'username',
|
|
63
|
+
message: 'GitHub username:',
|
|
64
|
+
default: gitUser || undefined,
|
|
65
|
+
validate: (input) => input.trim() ? true : 'Required'
|
|
66
|
+
}]);
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!gitRepo.includes('github.com') && !gitRepo.includes('gitlab.com')) {
|
|
74
|
-
gitRepo = `https://github.com/${gitRepo}.git`;
|
|
75
|
-
}
|
|
76
|
-
config.gitRepo = gitRepo;
|
|
68
|
+
config.gitRepo = `https://github.com/${username.trim()}/ai-memory.git`;
|
|
69
|
+
console.log(chalk.gray(` Using repo: ${config.gitRepo}`));
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
await saveConfig(config);
|
|
73
|
+
console.log(chalk.green('Saved!\n'));
|
|
80
74
|
|
|
81
|
-
console.log('\\n' + chalk.green('✔ Configuration saved!'));
|
|
82
|
-
|
|
83
|
-
// Immediately run the chosen action
|
|
84
75
|
if (direction === 'upload') {
|
|
85
|
-
console.log(chalk.cyan('\\n↗ Uploading your AI memory...\\n'));
|
|
86
76
|
await pushCommand();
|
|
87
77
|
} else {
|
|
88
|
-
console.log(chalk.cyan('\\n↙ Downloading your AI memory...\\n'));
|
|
89
78
|
await restoreCommand();
|
|
90
79
|
}
|
|
91
80
|
}
|
package/src/commands/view.js
CHANGED
|
@@ -6,7 +6,7 @@ import ora from 'ora';
|
|
|
6
6
|
import boxen from 'boxen';
|
|
7
7
|
import inquirer from 'inquirer';
|
|
8
8
|
import { execSync } from 'child_process';
|
|
9
|
-
import {
|
|
9
|
+
import { getConfig } from '../config.js';
|
|
10
10
|
import { adapters } from '../adapters/index.js';
|
|
11
11
|
|
|
12
12
|
async function listFiles(dir, prefix = '') {
|
|
@@ -37,7 +37,7 @@ function isBinaryFile(filePath) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export async function viewCommand() {
|
|
40
|
-
const config = await
|
|
40
|
+
const config = await getConfig();
|
|
41
41
|
if (!config) {
|
|
42
42
|
console.log(chalk.red('\n✖ Not configured yet. Run: memoir init\n'));
|
|
43
43
|
return;
|