@codebakers/cli 2.6.0 → 2.6.1

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.
@@ -9,6 +9,7 @@ const ora_1 = __importDefault(require("ora"));
9
9
  const fs_1 = require("fs");
10
10
  const path_1 = require("path");
11
11
  const config_js_1 = require("../config.js");
12
+ const api_js_1 = require("../lib/api.js");
12
13
  async function install() {
13
14
  console.log(chalk_1.default.blue('\n CodeBakers Install\n'));
14
15
  const apiKey = (0, config_js_1.getApiKey)();
@@ -41,14 +42,22 @@ async function install() {
41
42
  (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'CLAUDE.md'), content.router);
42
43
  }
43
44
  // Write modules
45
+ const modulesDir = (0, path_1.join)(cwd, '.claude');
44
46
  if (content.modules && Object.keys(content.modules).length > 0) {
45
- const modulesDir = (0, path_1.join)(cwd, '.claude');
46
47
  if (!(0, fs_1.existsSync)(modulesDir)) {
47
48
  (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
48
49
  }
49
50
  for (const [name, data] of Object.entries(content.modules)) {
50
51
  (0, fs_1.writeFileSync)((0, path_1.join)(modulesDir, name), data);
51
52
  }
53
+ // Write version file for tracking
54
+ const versionInfo = {
55
+ version: content.version,
56
+ moduleCount: Object.keys(content.modules).length,
57
+ installedAt: new Date().toISOString(),
58
+ cliVersion: (0, api_js_1.getCliVersion)(),
59
+ };
60
+ (0, fs_1.writeFileSync)((0, path_1.join)(modulesDir, '.version.json'), JSON.stringify(versionInfo, null, 2));
52
61
  }
53
62
  // Add to .gitignore if not present
54
63
  const gitignorePath = (0, path_1.join)(cwd, '.gitignore');
@@ -74,6 +74,15 @@ async function upgrade() {
74
74
  }
75
75
  console.log(chalk_1.default.green(` ✓ Updated ${moduleCount} modules in .claude/`));
76
76
  }
77
+ // Write version file for tracking
78
+ const versionInfo = {
79
+ version: content.version,
80
+ moduleCount,
81
+ updatedAt: new Date().toISOString(),
82
+ cliVersion: (0, api_js_1.getCliVersion)(),
83
+ };
84
+ (0, fs_1.writeFileSync)((0, path_1.join)(claudeDir, '.version.json'), JSON.stringify(versionInfo, null, 2));
85
+ console.log(chalk_1.default.green(' ✓ Version info saved'));
77
86
  console.log(chalk_1.default.green(`\n ✅ Upgraded to patterns v${content.version}!\n`));
78
87
  // Show what's new if available
79
88
  console.log(chalk_1.default.gray(' Changes take effect in your next AI session.\n'));
@@ -41,6 +41,7 @@ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
41
41
  const config_js_1 = require("../config.js");
42
42
  const audit_js_1 = require("../commands/audit.js");
43
43
  const heal_js_1 = require("../commands/heal.js");
44
+ const api_js_1 = require("../lib/api.js");
44
45
  const fs = __importStar(require("fs"));
45
46
  const path = __importStar(require("path"));
46
47
  const child_process_1 = require("child_process");
@@ -239,6 +240,46 @@ class CodeBakersServer {
239
240
  }
240
241
  return context;
241
242
  }
243
+ async checkPatternVersion() {
244
+ const cwd = process.cwd();
245
+ const versionPath = path.join(cwd, '.claude', '.version.json');
246
+ // Read local version
247
+ let installed = null;
248
+ if (fs.existsSync(versionPath)) {
249
+ try {
250
+ installed = JSON.parse(fs.readFileSync(versionPath, 'utf-8'));
251
+ }
252
+ catch {
253
+ // Ignore parse errors
254
+ }
255
+ }
256
+ // Fetch latest version from API
257
+ let latest = null;
258
+ try {
259
+ const response = await fetch(`${this.apiUrl}/api/content/version`, {
260
+ headers: this.apiKey ? { 'Authorization': `Bearer ${this.apiKey}` } : {},
261
+ });
262
+ if (response.ok) {
263
+ latest = await response.json();
264
+ }
265
+ }
266
+ catch {
267
+ // Ignore fetch errors
268
+ }
269
+ // Compare versions
270
+ let updateAvailable = false;
271
+ let message = null;
272
+ if (installed && latest) {
273
+ if (installed.version !== latest.version) {
274
+ updateAvailable = true;
275
+ message = `⚠️ Pattern update available: v${installed.version} → v${latest.version} (${latest.moduleCount - installed.moduleCount} new modules)\n Run \`codebakers upgrade\` to update`;
276
+ }
277
+ }
278
+ else if (!installed && latest) {
279
+ message = `ℹ️ No version tracking found. Run \`codebakers upgrade\` to sync patterns`;
280
+ }
281
+ return { installed, latest, updateAvailable, message };
282
+ }
242
283
  formatContextForPrompt(context) {
243
284
  const lines = [];
244
285
  lines.push(`Project: ${context.projectName}`);
@@ -602,7 +643,7 @@ class CodeBakersServer {
602
643
  case 'get_experience_level':
603
644
  return this.handleGetExperienceLevel();
604
645
  case 'get_status':
605
- return this.handleGetStatus();
646
+ return await this.handleGetStatus();
606
647
  case 'run_audit':
607
648
  return this.handleRunAudit();
608
649
  case 'heal':
@@ -1400,16 +1441,28 @@ phase: development
1400
1441
  };
1401
1442
  }
1402
1443
  }
1403
- handleGetStatus() {
1444
+ async handleGetStatus() {
1404
1445
  const level = (0, config_js_1.getExperienceLevel)();
1405
1446
  const context = this.gatherProjectContext();
1447
+ const versionCheck = await this.checkPatternVersion();
1448
+ const cliVersion = (0, api_js_1.getCliVersion)();
1449
+ // Build version status section
1450
+ let versionSection = `- **CLI Version:** ${cliVersion}`;
1451
+ if (versionCheck.installed) {
1452
+ versionSection += `\n- **Patterns Version:** ${versionCheck.installed.version} (${versionCheck.installed.moduleCount} modules)`;
1453
+ }
1454
+ // Build update alert if needed
1455
+ let updateAlert = '';
1456
+ if (versionCheck.message) {
1457
+ updateAlert = `\n\n## ${versionCheck.updateAvailable ? '⚠️ Update Available' : 'ℹ️ Version Info'}\n${versionCheck.message}\n`;
1458
+ }
1406
1459
  const statusText = `# ✅ CodeBakers is Active!
1407
1460
 
1408
1461
  ## Connection Status
1409
1462
  - **MCP Server:** Running
1410
1463
  - **API Connected:** Yes
1411
- - **Version:** 2.2.0
1412
-
1464
+ ${versionSection}
1465
+ ${updateAlert}
1413
1466
  ## Current Settings
1414
1467
  - **Experience Level:** ${level.charAt(0).toUpperCase() + level.slice(1)}
1415
1468
  - **Project:** ${context.projectName}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebakers/cli",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "CodeBakers CLI - Production patterns for AI-assisted development",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -3,6 +3,7 @@ import ora from 'ora';
3
3
  import { writeFileSync, mkdirSync, existsSync } from 'fs';
4
4
  import { join } from 'path';
5
5
  import { getApiKey, getApiUrl } from '../config.js';
6
+ import { getCliVersion } from '../lib/api.js';
6
7
 
7
8
  interface ContentResponse {
8
9
  version: string;
@@ -51,8 +52,8 @@ export async function install(): Promise<void> {
51
52
  }
52
53
 
53
54
  // Write modules
55
+ const modulesDir = join(cwd, '.claude');
54
56
  if (content.modules && Object.keys(content.modules).length > 0) {
55
- const modulesDir = join(cwd, '.claude');
56
57
  if (!existsSync(modulesDir)) {
57
58
  mkdirSync(modulesDir, { recursive: true });
58
59
  }
@@ -60,6 +61,15 @@ export async function install(): Promise<void> {
60
61
  for (const [name, data] of Object.entries(content.modules)) {
61
62
  writeFileSync(join(modulesDir, name), data);
62
63
  }
64
+
65
+ // Write version file for tracking
66
+ const versionInfo = {
67
+ version: content.version,
68
+ moduleCount: Object.keys(content.modules).length,
69
+ installedAt: new Date().toISOString(),
70
+ cliVersion: getCliVersion(),
71
+ };
72
+ writeFileSync(join(modulesDir, '.version.json'), JSON.stringify(versionInfo, null, 2));
63
73
  }
64
74
 
65
75
  // Add to .gitignore if not present
@@ -91,6 +91,16 @@ export async function upgrade(): Promise<void> {
91
91
  console.log(chalk.green(` ✓ Updated ${moduleCount} modules in .claude/`));
92
92
  }
93
93
 
94
+ // Write version file for tracking
95
+ const versionInfo = {
96
+ version: content.version,
97
+ moduleCount,
98
+ updatedAt: new Date().toISOString(),
99
+ cliVersion: getCliVersion(),
100
+ };
101
+ writeFileSync(join(claudeDir, '.version.json'), JSON.stringify(versionInfo, null, 2));
102
+ console.log(chalk.green(' ✓ Version info saved'));
103
+
94
104
  console.log(chalk.green(`\n ✅ Upgraded to patterns v${content.version}!\n`));
95
105
 
96
106
  // Show what's new if available
package/src/mcp/server.ts CHANGED
@@ -11,11 +11,21 @@ import {
11
11
  import { getApiKey, getApiUrl, getExperienceLevel, setExperienceLevel, type ExperienceLevel } from '../config.js';
12
12
  import { audit as runAudit } from '../commands/audit.js';
13
13
  import { heal as runHeal } from '../commands/heal.js';
14
+ import { getCliVersion } from '../lib/api.js';
14
15
  import * as fs from 'fs';
15
16
  import * as path from 'path';
16
17
  import { execSync } from 'child_process';
17
18
  import * as templates from '../templates/nextjs-supabase.js';
18
19
 
20
+ // Version info type
21
+ interface VersionInfo {
22
+ version: string;
23
+ moduleCount: number;
24
+ installedAt?: string;
25
+ updatedAt?: string;
26
+ cliVersion: string;
27
+ }
28
+
19
29
  // Pattern cache to avoid repeated API calls
20
30
  const patternCache = new Map<string, { content: string; timestamp: number }>();
21
31
  const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
@@ -243,6 +253,54 @@ class CodeBakersServer {
243
253
  return context;
244
254
  }
245
255
 
256
+ private async checkPatternVersion(): Promise<{
257
+ installed: VersionInfo | null;
258
+ latest: { version: string; moduleCount: number } | null;
259
+ updateAvailable: boolean;
260
+ message: string | null;
261
+ }> {
262
+ const cwd = process.cwd();
263
+ const versionPath = path.join(cwd, '.claude', '.version.json');
264
+
265
+ // Read local version
266
+ let installed: VersionInfo | null = null;
267
+ if (fs.existsSync(versionPath)) {
268
+ try {
269
+ installed = JSON.parse(fs.readFileSync(versionPath, 'utf-8'));
270
+ } catch {
271
+ // Ignore parse errors
272
+ }
273
+ }
274
+
275
+ // Fetch latest version from API
276
+ let latest: { version: string; moduleCount: number } | null = null;
277
+ try {
278
+ const response = await fetch(`${this.apiUrl}/api/content/version`, {
279
+ headers: this.apiKey ? { 'Authorization': `Bearer ${this.apiKey}` } : {},
280
+ });
281
+ if (response.ok) {
282
+ latest = await response.json();
283
+ }
284
+ } catch {
285
+ // Ignore fetch errors
286
+ }
287
+
288
+ // Compare versions
289
+ let updateAvailable = false;
290
+ let message: string | null = null;
291
+
292
+ if (installed && latest) {
293
+ if (installed.version !== latest.version) {
294
+ updateAvailable = true;
295
+ message = `⚠️ Pattern update available: v${installed.version} → v${latest.version} (${latest.moduleCount - installed.moduleCount} new modules)\n Run \`codebakers upgrade\` to update`;
296
+ }
297
+ } else if (!installed && latest) {
298
+ message = `ℹ️ No version tracking found. Run \`codebakers upgrade\` to sync patterns`;
299
+ }
300
+
301
+ return { installed, latest, updateAvailable, message };
302
+ }
303
+
246
304
  private formatContextForPrompt(context: ProjectContext): string {
247
305
  const lines: string[] = [];
248
306
 
@@ -651,7 +709,7 @@ class CodeBakersServer {
651
709
  return this.handleGetExperienceLevel();
652
710
 
653
711
  case 'get_status':
654
- return this.handleGetStatus();
712
+ return await this.handleGetStatus();
655
713
 
656
714
  case 'run_audit':
657
715
  return this.handleRunAudit();
@@ -1579,17 +1637,31 @@ phase: development
1579
1637
  }
1580
1638
  }
1581
1639
 
1582
- private handleGetStatus() {
1640
+ private async handleGetStatus() {
1583
1641
  const level = getExperienceLevel();
1584
1642
  const context = this.gatherProjectContext();
1643
+ const versionCheck = await this.checkPatternVersion();
1644
+ const cliVersion = getCliVersion();
1645
+
1646
+ // Build version status section
1647
+ let versionSection = `- **CLI Version:** ${cliVersion}`;
1648
+ if (versionCheck.installed) {
1649
+ versionSection += `\n- **Patterns Version:** ${versionCheck.installed.version} (${versionCheck.installed.moduleCount} modules)`;
1650
+ }
1651
+
1652
+ // Build update alert if needed
1653
+ let updateAlert = '';
1654
+ if (versionCheck.message) {
1655
+ updateAlert = `\n\n## ${versionCheck.updateAvailable ? '⚠️ Update Available' : 'ℹ️ Version Info'}\n${versionCheck.message}\n`;
1656
+ }
1585
1657
 
1586
1658
  const statusText = `# ✅ CodeBakers is Active!
1587
1659
 
1588
1660
  ## Connection Status
1589
1661
  - **MCP Server:** Running
1590
1662
  - **API Connected:** Yes
1591
- - **Version:** 2.2.0
1592
-
1663
+ ${versionSection}
1664
+ ${updateAlert}
1593
1665
  ## Current Settings
1594
1666
  - **Experience Level:** ${level.charAt(0).toUpperCase() + level.slice(1)}
1595
1667
  - **Project:** ${context.projectName}