@codebakers/cli 3.3.4 → 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 CHANGED
@@ -139,4 +139,21 @@ export declare function setCachedPatternInfo(latestVersion: string): void;
139
139
  * Clear pattern cache to force a fresh check
140
140
  */
141
141
  export declare function clearPatternCache(): void;
142
+ /**
143
+ * Check if we should attempt CLI auto-update
144
+ * Returns false if we recently attempted and failed
145
+ */
146
+ export declare function shouldAttemptCliUpdate(): boolean;
147
+ /**
148
+ * Record a CLI update attempt
149
+ */
150
+ export declare function setCliUpdateAttempt(targetVersion: string, success: boolean): void;
151
+ /**
152
+ * Check if CLI auto-update is disabled
153
+ */
154
+ export declare function isCliAutoUpdateDisabled(): boolean;
155
+ /**
156
+ * Disable/enable CLI auto-update
157
+ */
158
+ export declare function setCliAutoUpdateDisabled(disabled: boolean): void;
142
159
  export {};
package/dist/config.js CHANGED
@@ -38,6 +38,10 @@ exports.getCliVersion = getCliVersion;
38
38
  exports.getCachedPatternInfo = getCachedPatternInfo;
39
39
  exports.setCachedPatternInfo = setCachedPatternInfo;
40
40
  exports.clearPatternCache = clearPatternCache;
41
+ exports.shouldAttemptCliUpdate = shouldAttemptCliUpdate;
42
+ exports.setCliUpdateAttempt = setCliUpdateAttempt;
43
+ exports.isCliAutoUpdateDisabled = isCliAutoUpdateDisabled;
44
+ exports.setCliAutoUpdateDisabled = setCliAutoUpdateDisabled;
41
45
  const conf_1 = __importDefault(require("conf"));
42
46
  const fs_1 = require("fs");
43
47
  const path_1 = require("path");
@@ -458,7 +462,7 @@ function setCachedUpdateInfo(latestVersion) {
458
462
  * Get the current CLI version from package.json
459
463
  */
460
464
  function getCliVersion() {
461
- return '3.3.0'; // Keep in sync with package.json
465
+ return '3.3.5'; // Keep in sync with package.json
462
466
  }
463
467
  // ============================================
464
468
  // Pattern Auto-Update Cache
@@ -491,3 +495,46 @@ function clearPatternCache() {
491
495
  config.set('lastPatternCheck', null);
492
496
  config.set('latestPatternVersion', null);
493
497
  }
498
+ // ============================================
499
+ // CLI Auto-Update Tracking
500
+ // ============================================
501
+ const CLI_UPDATE_COOLDOWN_HOURS = 24; // Don't retry auto-update for 24 hours after failure
502
+ /**
503
+ * Check if we should attempt CLI auto-update
504
+ * Returns false if we recently attempted and failed
505
+ */
506
+ function shouldAttemptCliUpdate() {
507
+ const lastAttempt = config.get('lastCliUpdateAttempt');
508
+ const lastAttemptVersion = config.get('lastCliUpdateAttemptVersion');
509
+ if (!lastAttempt || typeof lastAttempt !== 'string')
510
+ return true;
511
+ const hoursSinceAttempt = (Date.now() - new Date(lastAttempt).getTime()) / (1000 * 60 * 60);
512
+ // If we already successfully updated to this version, don't retry
513
+ const currentVersion = getCliVersion();
514
+ if (lastAttemptVersion === currentVersion)
515
+ return false;
516
+ // If cooldown hasn't passed, don't retry
517
+ if (hoursSinceAttempt < CLI_UPDATE_COOLDOWN_HOURS)
518
+ return false;
519
+ return true;
520
+ }
521
+ /**
522
+ * Record a CLI update attempt
523
+ */
524
+ function setCliUpdateAttempt(targetVersion, success) {
525
+ config.set('lastCliUpdateAttempt', new Date().toISOString());
526
+ config.set('lastCliUpdateAttemptVersion', targetVersion);
527
+ config.set('lastCliUpdateSuccess', success);
528
+ }
529
+ /**
530
+ * Check if CLI auto-update is disabled
531
+ */
532
+ function isCliAutoUpdateDisabled() {
533
+ return config.get('disableCliAutoUpdate') === true;
534
+ }
535
+ /**
536
+ * Disable/enable CLI auto-update
537
+ */
538
+ function setCliAutoUpdateDisabled(disabled) {
539
+ config.set('disableCliAutoUpdate', disabled);
540
+ }
package/dist/index.js CHANGED
@@ -27,13 +27,14 @@ const go_js_1 = require("./commands/go.js");
27
27
  const extend_js_1 = require("./commands/extend.js");
28
28
  const billing_js_1 = require("./commands/billing.js");
29
29
  const config_js_2 = require("./config.js");
30
+ const child_process_1 = require("child_process");
30
31
  const api_js_1 = require("./lib/api.js");
31
32
  const fs_1 = require("fs");
32
33
  const path_1 = require("path");
33
34
  // ============================================
34
35
  // Automatic Update Notification
35
36
  // ============================================
36
- const CURRENT_VERSION = '3.3.1';
37
+ const CURRENT_VERSION = '3.3.5';
37
38
  async function checkForUpdatesInBackground() {
38
39
  // Check if we have a valid cached result first (fast path)
39
40
  const cached = (0, config_js_2.getCachedUpdateInfo)();
@@ -93,6 +94,65 @@ function showUpdateBanner(currentVersion, latestVersion, isRecommended) {
93
94
  ╰─────────────────────────────────────────────────────────╯
94
95
  `));
95
96
  }
97
+ // ============================================
98
+ // CLI Auto-Update
99
+ // ============================================
100
+ async function autoUpdateCli() {
101
+ // Check if auto-update is disabled
102
+ if ((0, config_js_2.isCliAutoUpdateDisabled)())
103
+ return;
104
+ // Check if we should attempt update (cooldown, etc.)
105
+ if (!(0, config_js_2.shouldAttemptCliUpdate)())
106
+ return;
107
+ // Check for available updates
108
+ try {
109
+ const updateInfo = await (0, api_js_1.checkForUpdates)();
110
+ if (!updateInfo || !updateInfo.updateAvailable)
111
+ return;
112
+ // Don't auto-update blocked versions - show warning instead
113
+ if (updateInfo.isBlocked)
114
+ return;
115
+ const targetVersion = updateInfo.latestVersion;
116
+ const currentVersion = CURRENT_VERSION;
117
+ // Only auto-update if the version has auto-update enabled from server
118
+ if (!updateInfo.autoUpdateEnabled)
119
+ return;
120
+ console.log(chalk_1.default.blue(`\n 🔄 Auto-updating CLI: ${chalk_1.default.gray(currentVersion)} → ${chalk_1.default.green(targetVersion)}...\n`));
121
+ try {
122
+ // Run npm install globally
123
+ (0, child_process_1.execSync)('npm install -g @codebakers/cli@latest', {
124
+ stdio: 'inherit',
125
+ timeout: 60000, // 60 second timeout
126
+ });
127
+ (0, config_js_2.setCliUpdateAttempt)(targetVersion, true);
128
+ console.log(chalk_1.default.green(`\n ✓ CLI updated to v${targetVersion}!\n`));
129
+ console.log(chalk_1.default.gray(' The update will take effect on your next command.\n'));
130
+ }
131
+ catch (installError) {
132
+ (0, config_js_2.setCliUpdateAttempt)(targetVersion, false);
133
+ // Check if it's a permission error
134
+ const errorMessage = installError instanceof Error ? installError.message : String(installError);
135
+ if (errorMessage.includes('EACCES') || errorMessage.includes('permission')) {
136
+ console.log(chalk_1.default.yellow(`
137
+ ⚠️ Auto-update failed (permission denied)
138
+
139
+ Run manually with: ${chalk_1.default.cyan('sudo npm i -g @codebakers/cli@latest')}
140
+ Or disable auto-update: ${chalk_1.default.cyan('codebakers config set disableCliAutoUpdate true')}
141
+ `));
142
+ }
143
+ else {
144
+ console.log(chalk_1.default.yellow(`
145
+ ⚠️ Auto-update failed
146
+
147
+ Run manually: ${chalk_1.default.cyan('npm i -g @codebakers/cli@latest')}
148
+ `));
149
+ }
150
+ }
151
+ }
152
+ catch {
153
+ // Silently fail - don't block CLI for update check
154
+ }
155
+ }
96
156
  function getLocalPatternVersion() {
97
157
  const cwd = process.cwd();
98
158
  const versionFile = (0, path_1.join)(cwd, '.claude', '.version.json');
@@ -406,7 +466,10 @@ program
406
466
  .action(mcp_config_js_1.mcpUninstall);
407
467
  // Add update check hook (runs before every command)
408
468
  program.hook('preAction', async () => {
409
- // Run CLI update check and pattern auto-update in parallel
469
+ // Run CLI auto-update first (if enabled and conditions met)
470
+ // Then run pattern auto-update in parallel with update banner check
471
+ await autoUpdateCli();
472
+ // Run pattern auto-update and update banner check in parallel
410
473
  await Promise.all([
411
474
  checkForUpdatesInBackground(),
412
475
  autoUpdatePatterns(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebakers/cli",
3
- "version": "3.3.4",
3
+ "version": "3.3.5",
4
4
  "description": "CodeBakers CLI - Production patterns for AI-assisted development",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/config.ts CHANGED
@@ -542,7 +542,7 @@ export function setCachedUpdateInfo(latestVersion: string): void {
542
542
  * Get the current CLI version from package.json
543
543
  */
544
544
  export function getCliVersion(): string {
545
- return '3.3.0'; // Keep in sync with package.json
545
+ return '3.3.5'; // Keep in sync with package.json
546
546
  }
547
547
 
548
548
  // ============================================
@@ -581,3 +581,54 @@ export function clearPatternCache(): void {
581
581
  config.set('lastPatternCheck', null);
582
582
  config.set('latestPatternVersion', null);
583
583
  }
584
+
585
+ // ============================================
586
+ // CLI Auto-Update Tracking
587
+ // ============================================
588
+
589
+ const CLI_UPDATE_COOLDOWN_HOURS = 24; // Don't retry auto-update for 24 hours after failure
590
+
591
+ /**
592
+ * Check if we should attempt CLI auto-update
593
+ * Returns false if we recently attempted and failed
594
+ */
595
+ export function shouldAttemptCliUpdate(): boolean {
596
+ const lastAttempt = config.get('lastCliUpdateAttempt') as string | undefined;
597
+ const lastAttemptVersion = config.get('lastCliUpdateAttemptVersion') as string | undefined;
598
+
599
+ if (!lastAttempt || typeof lastAttempt !== 'string') return true;
600
+
601
+ const hoursSinceAttempt = (Date.now() - new Date(lastAttempt).getTime()) / (1000 * 60 * 60);
602
+
603
+ // If we already successfully updated to this version, don't retry
604
+ const currentVersion = getCliVersion();
605
+ if (lastAttemptVersion === currentVersion) return false;
606
+
607
+ // If cooldown hasn't passed, don't retry
608
+ if (hoursSinceAttempt < CLI_UPDATE_COOLDOWN_HOURS) return false;
609
+
610
+ return true;
611
+ }
612
+
613
+ /**
614
+ * Record a CLI update attempt
615
+ */
616
+ export function setCliUpdateAttempt(targetVersion: string, success: boolean): void {
617
+ config.set('lastCliUpdateAttempt', new Date().toISOString());
618
+ config.set('lastCliUpdateAttemptVersion', targetVersion);
619
+ config.set('lastCliUpdateSuccess', success);
620
+ }
621
+
622
+ /**
623
+ * Check if CLI auto-update is disabled
624
+ */
625
+ export function isCliAutoUpdateDisabled(): boolean {
626
+ return config.get('disableCliAutoUpdate') === true;
627
+ }
628
+
629
+ /**
630
+ * Disable/enable CLI auto-update
631
+ */
632
+ export function setCliAutoUpdateDisabled(disabled: boolean): void {
633
+ config.set('disableCliAutoUpdate', disabled);
634
+ }
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.1';
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 check and pattern auto-update in parallel
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(),