@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 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(),