@codebakers/cli 3.3.3 → 3.3.5
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/dist/config.d.ts +17 -0
- package/dist/config.js +48 -1
- package/dist/index.js +65 -2
- package/dist/mcp/server.js +579 -0
- package/package.json +1 -1
- package/src/config.ts +52 -1
- package/src/index.ts +73 -3
- package/src/mcp/server.ts +660 -0
package/src/index.ts
CHANGED
|
@@ -22,7 +22,8 @@ import { pushPatterns, pushPatternsInteractive } from './commands/push-patterns.
|
|
|
22
22
|
import { go } from './commands/go.js';
|
|
23
23
|
import { extend } from './commands/extend.js';
|
|
24
24
|
import { billing } from './commands/billing.js';
|
|
25
|
-
import { getCachedUpdateInfo, setCachedUpdateInfo, getCliVersion, getCachedPatternInfo, setCachedPatternInfo, getApiKey, getApiUrl, getTrialState, hasValidAccess } from './config.js';
|
|
25
|
+
import { getCachedUpdateInfo, setCachedUpdateInfo, getCliVersion, getCachedPatternInfo, setCachedPatternInfo, getApiKey, getApiUrl, getTrialState, hasValidAccess, shouldAttemptCliUpdate, setCliUpdateAttempt, isCliAutoUpdateDisabled } from './config.js';
|
|
26
|
+
import { execSync } from 'child_process';
|
|
26
27
|
import { checkForUpdates } from './lib/api.js';
|
|
27
28
|
import { existsSync, writeFileSync, readFileSync, mkdirSync } from 'fs';
|
|
28
29
|
import { join } from 'path';
|
|
@@ -31,7 +32,7 @@ import { join } from 'path';
|
|
|
31
32
|
// Automatic Update Notification
|
|
32
33
|
// ============================================
|
|
33
34
|
|
|
34
|
-
const CURRENT_VERSION = '3.3.
|
|
35
|
+
const CURRENT_VERSION = '3.3.5';
|
|
35
36
|
|
|
36
37
|
async function checkForUpdatesInBackground(): Promise<void> {
|
|
37
38
|
// Check if we have a valid cached result first (fast path)
|
|
@@ -97,6 +98,71 @@ function showUpdateBanner(currentVersion: string, latestVersion: string, isRecom
|
|
|
97
98
|
`));
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// ============================================
|
|
102
|
+
// CLI Auto-Update
|
|
103
|
+
// ============================================
|
|
104
|
+
|
|
105
|
+
async function autoUpdateCli(): Promise<void> {
|
|
106
|
+
// Check if auto-update is disabled
|
|
107
|
+
if (isCliAutoUpdateDisabled()) return;
|
|
108
|
+
|
|
109
|
+
// Check if we should attempt update (cooldown, etc.)
|
|
110
|
+
if (!shouldAttemptCliUpdate()) return;
|
|
111
|
+
|
|
112
|
+
// Check for available updates
|
|
113
|
+
try {
|
|
114
|
+
const updateInfo = await checkForUpdates();
|
|
115
|
+
|
|
116
|
+
if (!updateInfo || !updateInfo.updateAvailable) return;
|
|
117
|
+
|
|
118
|
+
// Don't auto-update blocked versions - show warning instead
|
|
119
|
+
if (updateInfo.isBlocked) return;
|
|
120
|
+
|
|
121
|
+
const targetVersion = updateInfo.latestVersion;
|
|
122
|
+
const currentVersion = CURRENT_VERSION;
|
|
123
|
+
|
|
124
|
+
// Only auto-update if the version has auto-update enabled from server
|
|
125
|
+
if (!updateInfo.autoUpdateEnabled) return;
|
|
126
|
+
|
|
127
|
+
console.log(chalk.blue(`\n 🔄 Auto-updating CLI: ${chalk.gray(currentVersion)} → ${chalk.green(targetVersion)}...\n`));
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
// Run npm install globally
|
|
131
|
+
execSync('npm install -g @codebakers/cli@latest', {
|
|
132
|
+
stdio: 'inherit',
|
|
133
|
+
timeout: 60000, // 60 second timeout
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
setCliUpdateAttempt(targetVersion, true);
|
|
137
|
+
|
|
138
|
+
console.log(chalk.green(`\n ✓ CLI updated to v${targetVersion}!\n`));
|
|
139
|
+
console.log(chalk.gray(' The update will take effect on your next command.\n'));
|
|
140
|
+
|
|
141
|
+
} catch (installError) {
|
|
142
|
+
setCliUpdateAttempt(targetVersion, false);
|
|
143
|
+
|
|
144
|
+
// Check if it's a permission error
|
|
145
|
+
const errorMessage = installError instanceof Error ? installError.message : String(installError);
|
|
146
|
+
if (errorMessage.includes('EACCES') || errorMessage.includes('permission')) {
|
|
147
|
+
console.log(chalk.yellow(`
|
|
148
|
+
⚠️ Auto-update failed (permission denied)
|
|
149
|
+
|
|
150
|
+
Run manually with: ${chalk.cyan('sudo npm i -g @codebakers/cli@latest')}
|
|
151
|
+
Or disable auto-update: ${chalk.cyan('codebakers config set disableCliAutoUpdate true')}
|
|
152
|
+
`));
|
|
153
|
+
} else {
|
|
154
|
+
console.log(chalk.yellow(`
|
|
155
|
+
⚠️ Auto-update failed
|
|
156
|
+
|
|
157
|
+
Run manually: ${chalk.cyan('npm i -g @codebakers/cli@latest')}
|
|
158
|
+
`));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
// Silently fail - don't block CLI for update check
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
100
166
|
// ============================================
|
|
101
167
|
// Automatic Pattern Updates
|
|
102
168
|
// ============================================
|
|
@@ -476,7 +542,11 @@ program
|
|
|
476
542
|
|
|
477
543
|
// Add update check hook (runs before every command)
|
|
478
544
|
program.hook('preAction', async () => {
|
|
479
|
-
// Run CLI update
|
|
545
|
+
// Run CLI auto-update first (if enabled and conditions met)
|
|
546
|
+
// Then run pattern auto-update in parallel with update banner check
|
|
547
|
+
await autoUpdateCli();
|
|
548
|
+
|
|
549
|
+
// Run pattern auto-update and update banner check in parallel
|
|
480
550
|
await Promise.all([
|
|
481
551
|
checkForUpdatesInBackground(),
|
|
482
552
|
autoUpdatePatterns(),
|