@codebakers/cli 1.6.0 → 2.1.0

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.
@@ -0,0 +1,4 @@
1
+ /**
2
+ * View or modify CLI configuration
3
+ */
4
+ export declare function config(action?: string): Promise<void>;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.config = config;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const readline_1 = require("readline");
9
+ const config_js_1 = require("../config.js");
10
+ function prompt(question) {
11
+ const rl = (0, readline_1.createInterface)({
12
+ input: process.stdin,
13
+ output: process.stdout,
14
+ });
15
+ return new Promise((resolve) => {
16
+ rl.question(question, (answer) => {
17
+ rl.close();
18
+ resolve(answer.trim());
19
+ });
20
+ });
21
+ }
22
+ /**
23
+ * View or modify CLI configuration
24
+ */
25
+ async function config(action) {
26
+ console.log(chalk_1.default.blue('\n CodeBakers Configuration\n'));
27
+ switch (action) {
28
+ case 'show':
29
+ case undefined:
30
+ showConfig();
31
+ break;
32
+ case 'path':
33
+ showConfigPath();
34
+ break;
35
+ case 'reset':
36
+ await resetConfig();
37
+ break;
38
+ case 'keys':
39
+ showServiceKeys();
40
+ break;
41
+ case 'clear-keys':
42
+ await clearKeys();
43
+ break;
44
+ case 'set-url':
45
+ await setUrl();
46
+ break;
47
+ default:
48
+ showHelp();
49
+ }
50
+ }
51
+ function showConfig() {
52
+ const apiKey = (0, config_js_1.getApiKey)();
53
+ const apiUrl = (0, config_js_1.getApiUrl)();
54
+ const configPath = (0, config_js_1.getConfigPath)();
55
+ const configuredKeys = (0, config_js_1.getConfiguredServiceKeys)();
56
+ const lastSync = (0, config_js_1.getLastKeySync)();
57
+ console.log(chalk_1.default.white(' Current Configuration:\n'));
58
+ // API Key
59
+ if (apiKey) {
60
+ const masked = `${apiKey.slice(0, 7)}...${apiKey.slice(-4)}`;
61
+ console.log(chalk_1.default.gray(' API Key: ') + chalk_1.default.green(masked));
62
+ }
63
+ else {
64
+ console.log(chalk_1.default.gray(' API Key: ') + chalk_1.default.yellow('Not configured'));
65
+ }
66
+ // API URL
67
+ console.log(chalk_1.default.gray(' API URL: ') + chalk_1.default.cyan(apiUrl));
68
+ // Service Keys
69
+ console.log(chalk_1.default.gray(' Service Keys: ') + chalk_1.default.cyan(`${configuredKeys.length} configured`));
70
+ // Last Sync
71
+ if (lastSync) {
72
+ const syncDate = lastSync.toLocaleDateString();
73
+ const syncTime = lastSync.toLocaleTimeString();
74
+ console.log(chalk_1.default.gray(' Last Sync: ') + chalk_1.default.cyan(`${syncDate} ${syncTime}`));
75
+ }
76
+ else {
77
+ console.log(chalk_1.default.gray(' Last Sync: ') + chalk_1.default.yellow('Never'));
78
+ }
79
+ // Config Path
80
+ console.log(chalk_1.default.gray(' Config File: ') + chalk_1.default.dim(configPath));
81
+ console.log('');
82
+ // Show available actions
83
+ console.log(chalk_1.default.white(' Available Actions:\n'));
84
+ console.log(chalk_1.default.gray(' codebakers config path ') + chalk_1.default.dim('Show config file location'));
85
+ console.log(chalk_1.default.gray(' codebakers config keys ') + chalk_1.default.dim('Show configured service keys'));
86
+ console.log(chalk_1.default.gray(' codebakers config clear-keys ') + chalk_1.default.dim('Clear all service keys'));
87
+ console.log(chalk_1.default.gray(' codebakers config set-url ') + chalk_1.default.dim('Change API URL (advanced)'));
88
+ console.log(chalk_1.default.gray(' codebakers config reset ') + chalk_1.default.dim('Reset all configuration'));
89
+ console.log('');
90
+ }
91
+ function showConfigPath() {
92
+ const configPath = (0, config_js_1.getConfigPath)();
93
+ console.log(chalk_1.default.white(' Config file location:\n'));
94
+ console.log(chalk_1.default.cyan(` ${configPath}\n`));
95
+ }
96
+ function showServiceKeys() {
97
+ const configuredKeys = (0, config_js_1.getConfiguredServiceKeys)();
98
+ if (configuredKeys.length === 0) {
99
+ console.log(chalk_1.default.yellow(' No service keys configured.\n'));
100
+ console.log(chalk_1.default.gray(' Add keys in your CodeBakers dashboard, then run `codebakers setup` to sync.\n'));
101
+ return;
102
+ }
103
+ console.log(chalk_1.default.white(` Configured Service Keys (${configuredKeys.length}):\n`));
104
+ // Group by category
105
+ for (const [category, keyNames] of Object.entries(config_js_1.SERVICE_KEY_CATEGORIES)) {
106
+ const categoryKeys = keyNames.filter(k => configuredKeys.includes(k));
107
+ if (categoryKeys.length > 0) {
108
+ console.log(chalk_1.default.gray(` ${category.charAt(0).toUpperCase() + category.slice(1)}:`));
109
+ for (const keyName of categoryKeys) {
110
+ console.log(chalk_1.default.green(` ✓ ${config_js_1.SERVICE_KEY_LABELS[keyName]}`));
111
+ }
112
+ }
113
+ }
114
+ console.log('');
115
+ const lastSync = (0, config_js_1.getLastKeySync)();
116
+ if (lastSync) {
117
+ console.log(chalk_1.default.gray(` Last synced: ${lastSync.toLocaleString()}\n`));
118
+ }
119
+ }
120
+ async function clearKeys() {
121
+ console.log(chalk_1.default.yellow(' This will clear all locally stored service keys.\n'));
122
+ const confirm = await prompt(chalk_1.default.gray(' Are you sure? (y/N): '));
123
+ if (confirm.toLowerCase() !== 'y') {
124
+ console.log(chalk_1.default.gray('\n Cancelled.\n'));
125
+ return;
126
+ }
127
+ (0, config_js_1.clearAllServiceKeys)();
128
+ console.log(chalk_1.default.green('\n ✓ All service keys cleared.\n'));
129
+ console.log(chalk_1.default.gray(' Run `codebakers setup` to sync keys from your account.\n'));
130
+ }
131
+ async function setUrl() {
132
+ console.log(chalk_1.default.yellow(' ⚠️ This is an advanced setting. Only change if instructed.\n'));
133
+ const currentUrl = (0, config_js_1.getApiUrl)();
134
+ console.log(chalk_1.default.gray(` Current URL: ${currentUrl}\n`));
135
+ const newUrl = await prompt(chalk_1.default.cyan(' New API URL (or press Enter to cancel): '));
136
+ if (!newUrl) {
137
+ console.log(chalk_1.default.gray('\n Cancelled.\n'));
138
+ return;
139
+ }
140
+ // Basic validation
141
+ try {
142
+ new URL(newUrl);
143
+ }
144
+ catch {
145
+ console.log(chalk_1.default.red('\n Invalid URL format.\n'));
146
+ return;
147
+ }
148
+ (0, config_js_1.setApiUrl)(newUrl);
149
+ console.log(chalk_1.default.green(`\n ✓ API URL updated to: ${newUrl}\n`));
150
+ }
151
+ async function resetConfig() {
152
+ console.log(chalk_1.default.yellow(' ⚠️ This will clear ALL configuration:\n'));
153
+ console.log(chalk_1.default.gray(' • API key'));
154
+ console.log(chalk_1.default.gray(' • Service keys'));
155
+ console.log(chalk_1.default.gray(' • All settings\n'));
156
+ const confirm = await prompt(chalk_1.default.red(' Type "RESET" to confirm: '));
157
+ if (confirm !== 'RESET') {
158
+ console.log(chalk_1.default.gray('\n Cancelled.\n'));
159
+ return;
160
+ }
161
+ (0, config_js_1.clearApiKey)();
162
+ (0, config_js_1.clearAllServiceKeys)();
163
+ console.log(chalk_1.default.green('\n ✓ Configuration reset.\n'));
164
+ console.log(chalk_1.default.gray(' Run `codebakers setup` to reconfigure.\n'));
165
+ }
166
+ function showHelp() {
167
+ console.log(chalk_1.default.white(' Usage: codebakers config [action]\n'));
168
+ console.log(chalk_1.default.white(' Actions:'));
169
+ console.log(chalk_1.default.gray(' (none) Show current configuration'));
170
+ console.log(chalk_1.default.gray(' path Show config file location'));
171
+ console.log(chalk_1.default.gray(' keys Show configured service keys'));
172
+ console.log(chalk_1.default.gray(' clear-keys Clear all service keys'));
173
+ console.log(chalk_1.default.gray(' set-url Change API URL (advanced)'));
174
+ console.log(chalk_1.default.gray(' reset Reset all configuration'));
175
+ console.log('');
176
+ }
@@ -10,14 +10,20 @@ const fs_1 = require("fs");
10
10
  const path_1 = require("path");
11
11
  const os_1 = require("os");
12
12
  const install_hook_js_1 = require("./install-hook.js");
13
+ const config_js_1 = require("../config.js");
14
+ const api_js_1 = require("../lib/api.js");
13
15
  /**
14
16
  * Run all health checks for CodeBakers setup
15
17
  */
16
18
  async function doctor() {
17
19
  console.log(chalk_1.default.blue('\n CodeBakers Doctor\n'));
18
- console.log(chalk_1.default.gray(' Checking your setup...\n'));
20
+ // Show version
21
+ const version = (0, api_js_1.getCliVersion)();
22
+ console.log(chalk_1.default.gray(` CLI Version: ${version}\n`));
23
+ console.log(chalk_1.default.gray(' Running health checks...\n'));
19
24
  const projectChecks = checkProject();
20
25
  const systemChecks = checkSystem();
26
+ const authChecks = await checkAuth();
21
27
  // Display project checks
22
28
  console.log(chalk_1.default.white(' Project:'));
23
29
  for (const check of projectChecks) {
@@ -35,8 +41,16 @@ async function doctor() {
35
41
  console.log(chalk_1.default.gray(` └─ ${check.details}`));
36
42
  }
37
43
  }
44
+ console.log(chalk_1.default.white('\n Authentication:'));
45
+ for (const check of authChecks) {
46
+ const icon = check.ok ? chalk_1.default.green('✓') : chalk_1.default.red('✗');
47
+ console.log(` ${icon} ${check.message}`);
48
+ if (check.details && !check.ok) {
49
+ console.log(chalk_1.default.gray(` └─ ${check.details}`));
50
+ }
51
+ }
38
52
  // Summary
39
- const allChecks = [...projectChecks, ...systemChecks];
53
+ const allChecks = [...projectChecks, ...systemChecks, ...authChecks];
40
54
  const passed = allChecks.filter(c => c.ok).length;
41
55
  const total = allChecks.length;
42
56
  console.log('');
@@ -55,8 +69,18 @@ async function doctor() {
55
69
  if (hookCheck && !hookCheck.ok) {
56
70
  console.log(chalk_1.default.gray(' • Run: codebakers install-hook'));
57
71
  }
72
+ const apiKeyCheck = authChecks.find(c => c.message.includes('API key'));
73
+ if (apiKeyCheck && !apiKeyCheck.ok) {
74
+ console.log(chalk_1.default.gray(' • Run: codebakers setup'));
75
+ }
58
76
  console.log('');
59
77
  }
78
+ // Check for updates
79
+ const updateInfo = await (0, api_js_1.checkForUpdates)();
80
+ if (updateInfo?.updateAvailable) {
81
+ console.log(chalk_1.default.yellow(` ⚠️ Update available: ${updateInfo.currentVersion} → ${updateInfo.latestVersion}`));
82
+ console.log(chalk_1.default.gray(' Run: npm install -g @codebakers/cli@latest\n'));
83
+ }
60
84
  }
61
85
  /**
62
86
  * Check project-level setup
@@ -101,7 +125,7 @@ function checkProject() {
101
125
  results.push({
102
126
  ok: false,
103
127
  message: `Only ${moduleCount} modules found (expected 10+)`,
104
- details: 'Run: codebakers install to add missing modules'
128
+ details: 'Run: codebakers upgrade to get all modules'
105
129
  });
106
130
  }
107
131
  else {
@@ -206,6 +230,36 @@ function checkSystem() {
206
230
  }
207
231
  return results;
208
232
  }
233
+ /**
234
+ * Check authentication status
235
+ */
236
+ async function checkAuth() {
237
+ const results = [];
238
+ // Check if API key is configured
239
+ const apiKey = (0, config_js_1.getApiKey)();
240
+ if (!apiKey) {
241
+ results.push({
242
+ ok: false,
243
+ message: 'API key not configured',
244
+ details: 'Run: codebakers setup'
245
+ });
246
+ return results;
247
+ }
248
+ results.push({ ok: true, message: 'API key configured' });
249
+ // Validate API key against server
250
+ const validity = await (0, api_js_1.checkApiKeyValidity)();
251
+ if (validity.valid) {
252
+ results.push({ ok: true, message: 'API key is valid' });
253
+ }
254
+ else {
255
+ results.push({
256
+ ok: false,
257
+ message: 'API key is invalid or expired',
258
+ details: validity.error?.recoverySteps?.[0] || 'Run: codebakers setup'
259
+ });
260
+ }
261
+ return results;
262
+ }
209
263
  /**
210
264
  * Quick check - returns true if basic setup is complete
211
265
  */
@@ -214,5 +268,6 @@ function isSetupComplete() {
214
268
  const hasClaudeMd = (0, fs_1.existsSync)((0, path_1.join)(cwd, 'CLAUDE.md'));
215
269
  const hasClaudeDir = (0, fs_1.existsSync)((0, path_1.join)(cwd, '.claude'));
216
270
  const hasHook = (0, install_hook_js_1.isHookInstalled)();
217
- return hasClaudeMd && hasClaudeDir && hasHook;
271
+ const hasApiKey = !!(0, config_js_1.getApiKey)();
272
+ return hasClaudeMd && hasClaudeDir && hasHook && hasApiKey;
218
273
  }
@@ -0,0 +1,41 @@
1
+ type ErrorSeverity = 'critical' | 'high' | 'medium' | 'low' | 'info';
2
+ type ErrorCategory = 'typescript' | 'runtime' | 'build' | 'dependency' | 'database' | 'auth' | 'api' | 'performance' | 'security' | 'configuration' | 'network' | 'unknown';
3
+ interface ClassifiedError {
4
+ id: string;
5
+ timestamp: Date;
6
+ category: ErrorCategory;
7
+ severity: ErrorSeverity;
8
+ message: string;
9
+ stack?: string;
10
+ file?: string;
11
+ line?: number;
12
+ column?: number;
13
+ autoFixable: boolean;
14
+ confidence: number;
15
+ suggestedFixes: SuggestedFix[];
16
+ fixed?: boolean;
17
+ }
18
+ interface SuggestedFix {
19
+ id: string;
20
+ description: string;
21
+ code?: string;
22
+ file?: string;
23
+ confidence: number;
24
+ risk: 'safe' | 'moderate' | 'risky';
25
+ requiresReview: boolean;
26
+ command?: string;
27
+ }
28
+ interface HealOptions {
29
+ auto?: boolean;
30
+ watch?: boolean;
31
+ severity?: string;
32
+ dryRun?: boolean;
33
+ }
34
+ interface HealResult {
35
+ errors: ClassifiedError[];
36
+ fixed: number;
37
+ remaining: number;
38
+ }
39
+ export declare function heal(options?: HealOptions): Promise<HealResult>;
40
+ export declare function healWatch(): Promise<void>;
41
+ export {};