beth-copilot 1.0.2 → 1.0.4
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/bin/cli.js +123 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { dirname, join, relative } from 'path';
|
|
5
5
|
import { existsSync, mkdirSync, readdirSync, statSync, copyFileSync, readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import { execSync, spawn } from 'child_process';
|
|
6
8
|
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
7
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
11
|
const __dirname = dirname(__filename);
|
|
9
12
|
const TEMPLATES_DIR = join(__dirname, '..', 'templates');
|
|
10
13
|
|
|
14
|
+
// Get current package version
|
|
15
|
+
const packageJson = require('../package.json');
|
|
16
|
+
const CURRENT_VERSION = packageJson.version;
|
|
17
|
+
|
|
11
18
|
const COLORS = {
|
|
12
19
|
reset: '\x1b[0m',
|
|
13
20
|
bright: '\x1b[1m',
|
|
@@ -37,6 +44,91 @@ function logInfo(message) {
|
|
|
37
44
|
log(` ${message}`, COLORS.cyan);
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
async function checkForUpdates() {
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch('https://registry.npmjs.org/beth-copilot/latest', {
|
|
50
|
+
signal: AbortSignal.timeout(3000) // 3 second timeout
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (!response.ok) return null;
|
|
54
|
+
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
const latestVersion = data.version;
|
|
57
|
+
|
|
58
|
+
if (latestVersion && latestVersion !== CURRENT_VERSION) {
|
|
59
|
+
// Compare versions (simple semver check)
|
|
60
|
+
const current = CURRENT_VERSION.split('.').map(Number);
|
|
61
|
+
const latest = latestVersion.split('.').map(Number);
|
|
62
|
+
|
|
63
|
+
for (let i = 0; i < 3; i++) {
|
|
64
|
+
if (latest[i] > current[i]) {
|
|
65
|
+
return latestVersion;
|
|
66
|
+
} else if (latest[i] < current[i]) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
} catch {
|
|
73
|
+
// Network error, timeout, etc. - silently continue
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isBacklogCliInstalled() {
|
|
79
|
+
try {
|
|
80
|
+
execSync('backlog --version', { stdio: 'ignore' });
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function promptYesNo(question) {
|
|
88
|
+
const readline = await import('readline');
|
|
89
|
+
const rl = readline.createInterface({
|
|
90
|
+
input: process.stdin,
|
|
91
|
+
output: process.stdout
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
rl.question(`${question} (y/N) `, (answer) => {
|
|
96
|
+
rl.close();
|
|
97
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function installBacklogCli() {
|
|
103
|
+
log('\nInstalling backlog.md CLI...', COLORS.cyan);
|
|
104
|
+
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const child = spawn('npm', ['install', '-g', 'backlog.md'], {
|
|
107
|
+
stdio: 'inherit',
|
|
108
|
+
shell: true
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
child.on('close', (code) => {
|
|
112
|
+
if (code === 0) {
|
|
113
|
+
logSuccess('backlog.md CLI installed successfully!');
|
|
114
|
+
resolve(true);
|
|
115
|
+
} else {
|
|
116
|
+
logWarning('Failed to install backlog.md CLI. You can install it manually:');
|
|
117
|
+
logInfo('npm i -g backlog.md');
|
|
118
|
+
logInfo(' or');
|
|
119
|
+
logInfo('bun i -g backlog.md');
|
|
120
|
+
resolve(false);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
child.on('error', () => {
|
|
125
|
+
logWarning('Failed to install backlog.md CLI. You can install it manually:');
|
|
126
|
+
logInfo('npm i -g backlog.md');
|
|
127
|
+
resolve(false);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
40
132
|
function showHelp() {
|
|
41
133
|
console.log(`
|
|
42
134
|
${COLORS.bright}Beth${COLORS.reset} - AI Orchestrator for GitHub Copilot
|
|
@@ -101,10 +193,21 @@ function copyDirRecursive(src, dest, options = {}) {
|
|
|
101
193
|
return copiedFiles;
|
|
102
194
|
}
|
|
103
195
|
|
|
104
|
-
function init(options = {}) {
|
|
196
|
+
async function init(options = {}) {
|
|
105
197
|
const { force = false, skipBacklog = false, skipMcp = false } = options;
|
|
106
198
|
const cwd = process.cwd();
|
|
107
199
|
|
|
200
|
+
// Check for updates
|
|
201
|
+
const latestVersion = await checkForUpdates();
|
|
202
|
+
if (latestVersion) {
|
|
203
|
+
console.log(`
|
|
204
|
+
${COLORS.yellow}╔════════════════════════════════════════════════════════════╗
|
|
205
|
+
║ ${COLORS.bright}Update available!${COLORS.reset}${COLORS.yellow} ${CURRENT_VERSION} → ${latestVersion} ║
|
|
206
|
+
║ Run: ${COLORS.cyan}npx beth-copilot@latest init${COLORS.yellow} to get the latest ║
|
|
207
|
+
╚════════════════════════════════════════════════════════════╝${COLORS.reset}
|
|
208
|
+
`);
|
|
209
|
+
}
|
|
210
|
+
|
|
108
211
|
console.log(`
|
|
109
212
|
${COLORS.bright}🤠 Beth is moving in.${COLORS.reset}
|
|
110
213
|
${COLORS.cyan}"I don't do excuses. I do results."${COLORS.reset}
|
|
@@ -179,6 +282,24 @@ ${COLORS.cyan}"I don't do excuses. I do results."${COLORS.reset}
|
|
|
179
282
|
logWarning('No files were copied. Use --force to overwrite existing files.');
|
|
180
283
|
}
|
|
181
284
|
|
|
285
|
+
// Check for backlog.md CLI
|
|
286
|
+
if (!skipBacklog && !isBacklogCliInstalled()) {
|
|
287
|
+
console.log('');
|
|
288
|
+
logWarning('backlog.md CLI is not installed.');
|
|
289
|
+
logInfo('The CLI provides TUI boards, web UI, and task management commands.');
|
|
290
|
+
logInfo('Learn more: https://github.com/MrLesk/Backlog.md');
|
|
291
|
+
console.log('');
|
|
292
|
+
|
|
293
|
+
const shouldInstall = await promptYesNo('Would you like to install the backlog.md CLI globally?');
|
|
294
|
+
if (shouldInstall) {
|
|
295
|
+
await installBacklogCli();
|
|
296
|
+
} else {
|
|
297
|
+
logInfo('Skipped. You can install it later with: npm i -g backlog.md');
|
|
298
|
+
}
|
|
299
|
+
} else if (!skipBacklog) {
|
|
300
|
+
logSuccess('backlog.md CLI is already installed');
|
|
301
|
+
}
|
|
302
|
+
|
|
182
303
|
// Next steps
|
|
183
304
|
console.log(`
|
|
184
305
|
${COLORS.bright}Next steps:${COLORS.reset}
|
|
@@ -237,7 +358,7 @@ if (unknownFlags.length > 0) {
|
|
|
237
358
|
|
|
238
359
|
switch (command) {
|
|
239
360
|
case 'init':
|
|
240
|
-
init(options);
|
|
361
|
+
await init(options);
|
|
241
362
|
break;
|
|
242
363
|
case 'help':
|
|
243
364
|
case '--help':
|