@codebakers/cli 3.7.0 → 3.7.2
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/commands/go.js +87 -72
- package/dist/mcp/server.js +19 -125
- package/package.json +1 -1
- package/src/commands/go.ts +101 -83
- package/src/mcp/server.ts +19 -130
package/dist/commands/go.js
CHANGED
|
@@ -129,93 +129,108 @@ async function go(options = {}) {
|
|
|
129
129
|
}
|
|
130
130
|
// New user - ask how they want to proceed
|
|
131
131
|
console.log(chalk_1.default.white(' How would you like to get started?\n'));
|
|
132
|
-
console.log(chalk_1.default.cyan(' [1] Start free 7-day trial') + chalk_1.default.gray(' (
|
|
132
|
+
console.log(chalk_1.default.cyan(' [1] Start free 7-day trial') + chalk_1.default.gray(' (GitHub login required)'));
|
|
133
133
|
console.log(chalk_1.default.cyan(' [2] Login with API key') + chalk_1.default.gray(' (I have an account)\n'));
|
|
134
134
|
const choice = await prompt(chalk_1.default.gray(' Enter 1 or 2: '));
|
|
135
135
|
if (choice === '2') {
|
|
136
136
|
await handleApiKeyLogin(options);
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
|
-
// Start new trial
|
|
140
|
-
|
|
139
|
+
// Start new trial via GitHub OAuth
|
|
140
|
+
await startTrialWithGitHub(options);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Open a URL in the default browser
|
|
144
|
+
*/
|
|
145
|
+
function openBrowser(url) {
|
|
146
|
+
const platform = process.platform;
|
|
141
147
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const response = await fetch(`${apiUrl}/api/trial/start`, {
|
|
145
|
-
method: 'POST',
|
|
146
|
-
headers: { 'Content-Type': 'application/json' },
|
|
147
|
-
body: JSON.stringify({
|
|
148
|
-
deviceHash: fingerprint.deviceHash,
|
|
149
|
-
machineId: fingerprint.machineId,
|
|
150
|
-
platform: fingerprint.platform,
|
|
151
|
-
hostname: fingerprint.hostname,
|
|
152
|
-
}),
|
|
153
|
-
});
|
|
154
|
-
const data = await response.json();
|
|
155
|
-
if (data.error === 'trial_not_available') {
|
|
156
|
-
spinner.fail('Trial not available');
|
|
157
|
-
console.log(chalk_1.default.yellow(`
|
|
158
|
-
It looks like you've already used a CodeBakers trial.
|
|
159
|
-
|
|
160
|
-
Ready to upgrade? $49/month for unlimited access.
|
|
161
|
-
|
|
162
|
-
${chalk_1.default.cyan('codebakers upgrade')} or visit ${chalk_1.default.underline('https://codebakers.ai/pricing')}
|
|
163
|
-
`));
|
|
164
|
-
return;
|
|
148
|
+
if (platform === 'win32') {
|
|
149
|
+
(0, child_process_1.execSync)(`start "" "${url}"`, { stdio: 'ignore', shell: 'cmd.exe' });
|
|
165
150
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
151
|
+
else if (platform === 'darwin') {
|
|
152
|
+
(0, child_process_1.execSync)(`open "${url}"`, { stdio: 'ignore' });
|
|
168
153
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
console.log(chalk_1.default.cyan(' codebakers extend\n'));
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
console.log(chalk_1.default.white(' Ready to upgrade? $49/month for unlimited access:\n'));
|
|
179
|
-
console.log(chalk_1.default.cyan(' codebakers upgrade\n'));
|
|
180
|
-
}
|
|
181
|
-
return;
|
|
154
|
+
else {
|
|
155
|
+
// Linux - try common browsers
|
|
156
|
+
(0, child_process_1.execSync)(`xdg-open "${url}" || sensible-browser "${url}" || x-www-browser "${url}"`, {
|
|
157
|
+
stdio: 'ignore',
|
|
158
|
+
shell: '/bin/sh',
|
|
159
|
+
});
|
|
182
160
|
}
|
|
183
|
-
// Save trial state
|
|
184
|
-
const trialState = {
|
|
185
|
-
trialId: data.trialId,
|
|
186
|
-
stage: data.stage,
|
|
187
|
-
deviceHash: fingerprint.deviceHash,
|
|
188
|
-
expiresAt: data.expiresAt,
|
|
189
|
-
startedAt: data.startedAt,
|
|
190
|
-
...(data.githubUsername && { githubUsername: data.githubUsername }),
|
|
191
|
-
...(data.projectId && { projectId: data.projectId }),
|
|
192
|
-
...(data.projectName && { projectName: data.projectName }),
|
|
193
|
-
};
|
|
194
|
-
(0, config_js_1.setTrialState)(trialState);
|
|
195
|
-
spinner.succeed(`Trial started (${data.daysRemaining} days free)`);
|
|
196
|
-
console.log('');
|
|
197
|
-
// Install v6.0 bootstrap files (CLAUDE.md and .cursorrules only)
|
|
198
|
-
await installPatterns(data.trialId, options);
|
|
199
|
-
// Configure MCP
|
|
200
|
-
await configureMCP(options);
|
|
201
|
-
// Show success and restart
|
|
202
|
-
await showSuccessAndRestart();
|
|
203
161
|
}
|
|
204
|
-
catch
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
162
|
+
catch {
|
|
163
|
+
console.log(chalk_1.default.yellow(`\n Could not open browser automatically.`));
|
|
164
|
+
console.log(chalk_1.default.gray(` Please open this URL manually:\n`));
|
|
165
|
+
console.log(chalk_1.default.cyan(` ${url}\n`));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Sleep for a specified number of milliseconds
|
|
170
|
+
*/
|
|
171
|
+
function sleep(ms) {
|
|
172
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Start a new trial via GitHub OAuth
|
|
176
|
+
* This ensures one trial per GitHub account
|
|
177
|
+
*/
|
|
178
|
+
async function startTrialWithGitHub(options = {}) {
|
|
179
|
+
const fingerprint = (0, fingerprint_js_1.getDeviceFingerprint)();
|
|
180
|
+
const apiUrl = (0, config_js_1.getApiUrl)();
|
|
181
|
+
const authUrl = `${apiUrl}/api/auth/github/trial?device_hash=${fingerprint.deviceHash}`;
|
|
182
|
+
console.log(chalk_1.default.white('\n Opening browser for GitHub authorization...\n'));
|
|
183
|
+
console.log(chalk_1.default.gray(' This links your trial to your GitHub account to prevent abuse.\n'));
|
|
184
|
+
openBrowser(authUrl);
|
|
185
|
+
console.log(chalk_1.default.gray(' Waiting for authorization...'));
|
|
186
|
+
console.log(chalk_1.default.gray(' (This may take a moment)\n'));
|
|
187
|
+
// Poll for trial creation
|
|
188
|
+
const spinner = (0, ora_1.default)('Checking authorization status...').start();
|
|
189
|
+
let trialCreated = false;
|
|
190
|
+
let pollCount = 0;
|
|
191
|
+
const maxPolls = 60; // 2 minutes max
|
|
192
|
+
while (pollCount < maxPolls && !trialCreated) {
|
|
193
|
+
await sleep(2000);
|
|
194
|
+
pollCount++;
|
|
195
|
+
try {
|
|
196
|
+
const response = await fetch(`${apiUrl}/api/trial/status?deviceHash=${fingerprint.deviceHash}`);
|
|
197
|
+
const data = await response.json();
|
|
198
|
+
if (response.ok && data.trialId) {
|
|
199
|
+
trialCreated = true;
|
|
200
|
+
// Save trial state
|
|
201
|
+
const trialState = {
|
|
202
|
+
trialId: data.trialId,
|
|
203
|
+
stage: data.stage,
|
|
204
|
+
deviceHash: fingerprint.deviceHash,
|
|
205
|
+
expiresAt: data.expiresAt,
|
|
206
|
+
startedAt: data.startedAt,
|
|
207
|
+
...(data.githubUsername && { githubUsername: data.githubUsername }),
|
|
208
|
+
...(data.projectId && { projectId: data.projectId }),
|
|
209
|
+
...(data.projectName && { projectName: data.projectName }),
|
|
210
|
+
};
|
|
211
|
+
(0, config_js_1.setTrialState)(trialState);
|
|
212
|
+
const username = data.githubUsername ? ` Welcome, @${data.githubUsername}!` : '';
|
|
213
|
+
spinner.succeed(`Trial started (${data.daysRemaining} days free)${username}`);
|
|
214
|
+
console.log('');
|
|
215
|
+
// Install v6.0 bootstrap files
|
|
216
|
+
await installPatterns(data.trialId, options);
|
|
217
|
+
// Configure MCP
|
|
218
|
+
await configureMCP(options);
|
|
219
|
+
// Show success and restart
|
|
220
|
+
await showSuccessAndRestart();
|
|
221
|
+
return;
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
|
-
|
|
216
|
-
|
|
224
|
+
catch {
|
|
225
|
+
// Ignore polling errors - continue waiting
|
|
226
|
+
log(`Poll ${pollCount} failed, retrying...`, options);
|
|
217
227
|
}
|
|
218
228
|
}
|
|
229
|
+
if (!trialCreated) {
|
|
230
|
+
spinner.warn('Authorization timed out');
|
|
231
|
+
console.log(chalk_1.default.yellow('\n Please try again or authorize manually:\n'));
|
|
232
|
+
console.log(chalk_1.default.cyan(` ${authUrl}\n`));
|
|
233
|
+
}
|
|
219
234
|
}
|
|
220
235
|
async function configureMCP(options = {}) {
|
|
221
236
|
log('Configuring MCP integration...', options);
|
package/dist/mcp/server.js
CHANGED
|
@@ -1075,13 +1075,13 @@ class CodeBakersServer {
|
|
|
1075
1075
|
},
|
|
1076
1076
|
{
|
|
1077
1077
|
name: 'detect_intent',
|
|
1078
|
-
description: '
|
|
1078
|
+
description: 'Lists all available CodeBakers MCP tools. Only use this when user explicitly asks "what tools are available" or "help". Do NOT use for normal requests - just call the appropriate tool directly.',
|
|
1079
1079
|
inputSchema: {
|
|
1080
1080
|
type: 'object',
|
|
1081
1081
|
properties: {
|
|
1082
1082
|
userMessage: {
|
|
1083
1083
|
type: 'string',
|
|
1084
|
-
description: 'The user\'s message
|
|
1084
|
+
description: 'The user\'s message (for context only)',
|
|
1085
1085
|
},
|
|
1086
1086
|
},
|
|
1087
1087
|
required: ['userMessage'],
|
|
@@ -5934,130 +5934,24 @@ You cannot write code without calling this tool first.
|
|
|
5934
5934
|
*/
|
|
5935
5935
|
handleDetectIntent(args) {
|
|
5936
5936
|
const { userMessage } = args;
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
const intentPatterns = [
|
|
5940
|
-
{
|
|
5941
|
-
keywords: ['upgrade codebakers', 'update patterns', 'sync patterns', 'download patterns', 'get latest patterns'],
|
|
5942
|
-
tool: 'update_patterns',
|
|
5943
|
-
description: 'Download latest CLAUDE.md and all .claude/ modules from the CodeBakers server',
|
|
5944
|
-
action: 'WRITE - Will overwrite local pattern files with server versions',
|
|
5945
|
-
isDestructive: true,
|
|
5946
|
-
},
|
|
5947
|
-
{
|
|
5948
|
-
keywords: ['upgrade', 'improve code', 'make production ready', 'code quality'],
|
|
5949
|
-
tool: 'upgrade',
|
|
5950
|
-
description: 'Analyze your code for quality improvements (does NOT download patterns)',
|
|
5951
|
-
action: 'READ-ONLY - Analyzes code and suggests improvements',
|
|
5952
|
-
isDestructive: false,
|
|
5953
|
-
},
|
|
5954
|
-
{
|
|
5955
|
-
keywords: ['build', 'create project', 'new project', 'scaffold', 'start fresh'],
|
|
5956
|
-
tool: 'scaffold_project',
|
|
5957
|
-
description: 'Create a new project from scratch with CodeBakers patterns',
|
|
5958
|
-
action: 'WRITE - Will create new files and folders',
|
|
5959
|
-
isDestructive: true,
|
|
5960
|
-
},
|
|
5961
|
-
{
|
|
5962
|
-
keywords: ['add feature', 'implement', 'build feature', 'create feature'],
|
|
5963
|
-
tool: 'optimize_and_build',
|
|
5964
|
-
description: 'Optimize your feature request with AI and fetch relevant patterns',
|
|
5965
|
-
action: 'READ + ASSIST - Fetches patterns and guides implementation',
|
|
5966
|
-
isDestructive: false,
|
|
5967
|
-
},
|
|
5968
|
-
{
|
|
5969
|
-
keywords: ['audit', 'review code', 'check code', 'code review'],
|
|
5970
|
-
tool: 'run_audit',
|
|
5971
|
-
description: 'Run comprehensive code quality audit',
|
|
5972
|
-
action: 'READ-ONLY - Analyzes code and reports issues',
|
|
5973
|
-
isDestructive: false,
|
|
5974
|
-
},
|
|
5975
|
-
{
|
|
5976
|
-
keywords: ['heal', 'fix errors', 'auto-fix', 'fix bugs'],
|
|
5977
|
-
tool: 'heal',
|
|
5978
|
-
description: 'AI-powered error detection and automatic fixing',
|
|
5979
|
-
action: 'WRITE - May modify files to fix errors',
|
|
5980
|
-
isDestructive: true,
|
|
5981
|
-
},
|
|
5982
|
-
{
|
|
5983
|
-
keywords: ['design', 'clone design', 'copy design', 'match design'],
|
|
5984
|
-
tool: 'design',
|
|
5985
|
-
description: 'Clone a design from mockups, screenshots, or websites',
|
|
5986
|
-
action: 'WRITE - Will generate component files',
|
|
5987
|
-
isDestructive: true,
|
|
5988
|
-
},
|
|
5989
|
-
{
|
|
5990
|
-
keywords: ['status', 'progress', "what's built", 'where am i'],
|
|
5991
|
-
tool: 'project_status',
|
|
5992
|
-
description: 'Show current project build progress and stats',
|
|
5993
|
-
action: 'READ-ONLY - Shows project state',
|
|
5994
|
-
isDestructive: false,
|
|
5995
|
-
},
|
|
5996
|
-
{
|
|
5997
|
-
keywords: ['run tests', 'test', 'check tests'],
|
|
5998
|
-
tool: 'run_tests',
|
|
5999
|
-
description: 'Execute the project test suite',
|
|
6000
|
-
action: 'READ-ONLY - Runs tests and reports results',
|
|
6001
|
-
isDestructive: false,
|
|
6002
|
-
},
|
|
6003
|
-
{
|
|
6004
|
-
keywords: ['list patterns', 'show patterns', 'what patterns'],
|
|
6005
|
-
tool: 'list_patterns',
|
|
6006
|
-
description: 'List all available CodeBakers patterns',
|
|
6007
|
-
action: 'READ-ONLY - Shows available patterns',
|
|
6008
|
-
isDestructive: false,
|
|
6009
|
-
},
|
|
6010
|
-
{
|
|
6011
|
-
keywords: ['init', 'initialize', 'add patterns to existing'],
|
|
6012
|
-
tool: 'init_project',
|
|
6013
|
-
description: 'Add CodeBakers patterns to an existing project',
|
|
6014
|
-
action: 'WRITE - Will add CLAUDE.md and .claude/ folder',
|
|
6015
|
-
isDestructive: true,
|
|
6016
|
-
},
|
|
6017
|
-
];
|
|
6018
|
-
// Find matching intents
|
|
6019
|
-
const matches = intentPatterns.filter(pattern => pattern.keywords.some(keyword => msg.includes(keyword)));
|
|
6020
|
-
let response = `# 🔍 Intent Detection\n\n`;
|
|
5937
|
+
// Simple tool list - no keyword guessing. Let the AI figure it out from context.
|
|
5938
|
+
let response = `# Available CodeBakers MCP Tools\n\n`;
|
|
6021
5939
|
response += `**Your message:** "${userMessage}"\n\n`;
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
response += `| **Description** | ${match.description} |\n`;
|
|
6038
|
-
response += `| **Action Type** | ${match.action} |\n`;
|
|
6039
|
-
response += `| **Destructive?** | ${match.isDestructive ? '⚠️ YES - modifies files' : '✅ NO - read-only'} |\n\n`;
|
|
6040
|
-
if (match.isDestructive) {
|
|
6041
|
-
response += `### ⚠️ Confirmation Required\n\n`;
|
|
6042
|
-
response += `This action will modify files. Do you want to proceed?\n\n`;
|
|
6043
|
-
response += `**Reply "yes" or "proceed" to execute, or describe what you actually want.**\n`;
|
|
6044
|
-
}
|
|
6045
|
-
else {
|
|
6046
|
-
response += `This is a read-only operation. Safe to proceed.\n\n`;
|
|
6047
|
-
response += `**Reply "yes" to execute, or clarify your request.**\n`;
|
|
6048
|
-
}
|
|
6049
|
-
}
|
|
6050
|
-
else {
|
|
6051
|
-
response += `## Multiple Possible Intents\n\n`;
|
|
6052
|
-
response += `Your request could match several tools:\n\n`;
|
|
6053
|
-
matches.forEach((match, i) => {
|
|
6054
|
-
response += `### Option ${i + 1}: \`${match.tool}\`\n`;
|
|
6055
|
-
response += `- **What it does:** ${match.description}\n`;
|
|
6056
|
-
response += `- **Action:** ${match.action}\n`;
|
|
6057
|
-
response += `- **Destructive:** ${match.isDestructive ? '⚠️ Yes' : '✅ No'}\n\n`;
|
|
6058
|
-
});
|
|
6059
|
-
response += `**Which option do you want?** Reply with the tool name or option number.\n`;
|
|
6060
|
-
}
|
|
5940
|
+
response += `## Tools\n\n`;
|
|
5941
|
+
response += `| Tool | Description |\n`;
|
|
5942
|
+
response += `|------|-------------|\n`;
|
|
5943
|
+
response += `| \`update_patterns\` | Download latest CLAUDE.md from server |\n`;
|
|
5944
|
+
response += `| \`discover_patterns\` | Find patterns for a feature request |\n`;
|
|
5945
|
+
response += `| \`optimize_and_build\` | AI-optimize a feature request |\n`;
|
|
5946
|
+
response += `| \`run_audit\` | Code quality audit |\n`;
|
|
5947
|
+
response += `| \`heal\` | Auto-fix errors |\n`;
|
|
5948
|
+
response += `| \`project_status\` | Show build progress |\n`;
|
|
5949
|
+
response += `| \`run_tests\` | Run test suite |\n`;
|
|
5950
|
+
response += `| \`scaffold_project\` | Create new project |\n`;
|
|
5951
|
+
response += `| \`init_project\` | Add patterns to existing project |\n`;
|
|
5952
|
+
response += `| \`list_patterns\` | List all available patterns |\n`;
|
|
5953
|
+
response += `| \`billing_action\` | Manage subscription |\n\n`;
|
|
5954
|
+
response += `**Pick the tool that matches what you want to do.**\n`;
|
|
6061
5955
|
return {
|
|
6062
5956
|
content: [{
|
|
6063
5957
|
type: 'text',
|
package/package.json
CHANGED
package/src/commands/go.ts
CHANGED
|
@@ -165,7 +165,7 @@ export async function go(options: GoOptions = {}): Promise<void> {
|
|
|
165
165
|
|
|
166
166
|
// New user - ask how they want to proceed
|
|
167
167
|
console.log(chalk.white(' How would you like to get started?\n'));
|
|
168
|
-
console.log(chalk.cyan(' [1] Start free 7-day trial') + chalk.gray(' (
|
|
168
|
+
console.log(chalk.cyan(' [1] Start free 7-day trial') + chalk.gray(' (GitHub login required)'));
|
|
169
169
|
console.log(chalk.cyan(' [2] Login with API key') + chalk.gray(' (I have an account)\n'));
|
|
170
170
|
|
|
171
171
|
const choice = await prompt(chalk.gray(' Enter 1 or 2: '));
|
|
@@ -175,96 +175,114 @@ export async function go(options: GoOptions = {}): Promise<void> {
|
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
// Start new trial
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
const fingerprint = getDeviceFingerprint();
|
|
183
|
-
const apiUrl = getApiUrl();
|
|
184
|
-
|
|
185
|
-
const response = await fetch(`${apiUrl}/api/trial/start`, {
|
|
186
|
-
method: 'POST',
|
|
187
|
-
headers: { 'Content-Type': 'application/json' },
|
|
188
|
-
body: JSON.stringify({
|
|
189
|
-
deviceHash: fingerprint.deviceHash,
|
|
190
|
-
machineId: fingerprint.machineId,
|
|
191
|
-
platform: fingerprint.platform,
|
|
192
|
-
hostname: fingerprint.hostname,
|
|
193
|
-
}),
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
const data = await response.json();
|
|
197
|
-
|
|
198
|
-
if (data.error === 'trial_not_available') {
|
|
199
|
-
spinner.fail('Trial not available');
|
|
200
|
-
console.log(chalk.yellow(`
|
|
201
|
-
It looks like you've already used a CodeBakers trial.
|
|
178
|
+
// Start new trial via GitHub OAuth
|
|
179
|
+
await startTrialWithGitHub(options);
|
|
180
|
+
}
|
|
202
181
|
|
|
203
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Open a URL in the default browser
|
|
184
|
+
*/
|
|
185
|
+
function openBrowser(url: string): void {
|
|
186
|
+
const platform = process.platform;
|
|
204
187
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
188
|
+
try {
|
|
189
|
+
if (platform === 'win32') {
|
|
190
|
+
execSync(`start "" "${url}"`, { stdio: 'ignore', shell: 'cmd.exe' });
|
|
191
|
+
} else if (platform === 'darwin') {
|
|
192
|
+
execSync(`open "${url}"`, { stdio: 'ignore' });
|
|
193
|
+
} else {
|
|
194
|
+
// Linux - try common browsers
|
|
195
|
+
execSync(`xdg-open "${url}" || sensible-browser "${url}" || x-www-browser "${url}"`, {
|
|
196
|
+
stdio: 'ignore',
|
|
197
|
+
shell: '/bin/sh',
|
|
198
|
+
});
|
|
208
199
|
}
|
|
200
|
+
} catch {
|
|
201
|
+
console.log(chalk.yellow(`\n Could not open browser automatically.`));
|
|
202
|
+
console.log(chalk.gray(` Please open this URL manually:\n`));
|
|
203
|
+
console.log(chalk.cyan(` ${url}\n`));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
209
206
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Sleep for a specified number of milliseconds
|
|
209
|
+
*/
|
|
210
|
+
function sleep(ms: number): Promise<void> {
|
|
211
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
212
|
+
}
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Start a new trial via GitHub OAuth
|
|
216
|
+
* This ensures one trial per GitHub account
|
|
217
|
+
*/
|
|
218
|
+
async function startTrialWithGitHub(options: GoOptions = {}): Promise<void> {
|
|
219
|
+
const fingerprint = getDeviceFingerprint();
|
|
220
|
+
const apiUrl = getApiUrl();
|
|
221
|
+
const authUrl = `${apiUrl}/api/auth/github/trial?device_hash=${fingerprint.deviceHash}`;
|
|
222
|
+
|
|
223
|
+
console.log(chalk.white('\n Opening browser for GitHub authorization...\n'));
|
|
224
|
+
console.log(chalk.gray(' This links your trial to your GitHub account to prevent abuse.\n'));
|
|
225
|
+
|
|
226
|
+
openBrowser(authUrl);
|
|
227
|
+
|
|
228
|
+
console.log(chalk.gray(' Waiting for authorization...'));
|
|
229
|
+
console.log(chalk.gray(' (This may take a moment)\n'));
|
|
230
|
+
|
|
231
|
+
// Poll for trial creation
|
|
232
|
+
const spinner = ora('Checking authorization status...').start();
|
|
233
|
+
let trialCreated = false;
|
|
234
|
+
let pollCount = 0;
|
|
235
|
+
const maxPolls = 60; // 2 minutes max
|
|
236
|
+
|
|
237
|
+
while (pollCount < maxPolls && !trialCreated) {
|
|
238
|
+
await sleep(2000);
|
|
239
|
+
pollCount++;
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
const response = await fetch(`${apiUrl}/api/trial/status?deviceHash=${fingerprint.deviceHash}`);
|
|
243
|
+
const data = await response.json();
|
|
244
|
+
|
|
245
|
+
if (response.ok && data.trialId) {
|
|
246
|
+
trialCreated = true;
|
|
247
|
+
|
|
248
|
+
// Save trial state
|
|
249
|
+
const trialState: TrialState = {
|
|
250
|
+
trialId: data.trialId,
|
|
251
|
+
stage: data.stage,
|
|
252
|
+
deviceHash: fingerprint.deviceHash,
|
|
253
|
+
expiresAt: data.expiresAt,
|
|
254
|
+
startedAt: data.startedAt,
|
|
255
|
+
...(data.githubUsername && { githubUsername: data.githubUsername }),
|
|
256
|
+
...(data.projectId && { projectId: data.projectId }),
|
|
257
|
+
...(data.projectName && { projectName: data.projectName }),
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
setTrialState(trialState);
|
|
261
|
+
|
|
262
|
+
const username = data.githubUsername ? ` Welcome, @${data.githubUsername}!` : '';
|
|
263
|
+
spinner.succeed(`Trial started (${data.daysRemaining} days free)${username}`);
|
|
264
|
+
console.log('');
|
|
265
|
+
|
|
266
|
+
// Install v6.0 bootstrap files
|
|
267
|
+
await installPatterns(data.trialId, options);
|
|
268
|
+
|
|
269
|
+
// Configure MCP
|
|
270
|
+
await configureMCP(options);
|
|
271
|
+
|
|
272
|
+
// Show success and restart
|
|
273
|
+
await showSuccessAndRestart();
|
|
274
|
+
return;
|
|
225
275
|
}
|
|
226
|
-
|
|
276
|
+
} catch {
|
|
277
|
+
// Ignore polling errors - continue waiting
|
|
278
|
+
log(`Poll ${pollCount} failed, retrying...`, options);
|
|
227
279
|
}
|
|
280
|
+
}
|
|
228
281
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
deviceHash: fingerprint.deviceHash,
|
|
234
|
-
expiresAt: data.expiresAt,
|
|
235
|
-
startedAt: data.startedAt,
|
|
236
|
-
...(data.githubUsername && { githubUsername: data.githubUsername }),
|
|
237
|
-
...(data.projectId && { projectId: data.projectId }),
|
|
238
|
-
...(data.projectName && { projectName: data.projectName }),
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
setTrialState(trialState);
|
|
242
|
-
|
|
243
|
-
spinner.succeed(`Trial started (${data.daysRemaining} days free)`);
|
|
244
|
-
console.log('');
|
|
245
|
-
|
|
246
|
-
// Install v6.0 bootstrap files (CLAUDE.md and .cursorrules only)
|
|
247
|
-
await installPatterns(data.trialId, options);
|
|
248
|
-
|
|
249
|
-
// Configure MCP
|
|
250
|
-
await configureMCP(options);
|
|
251
|
-
|
|
252
|
-
// Show success and restart
|
|
253
|
-
await showSuccessAndRestart();
|
|
254
|
-
|
|
255
|
-
} catch (error) {
|
|
256
|
-
spinner.fail('Failed to start trial');
|
|
257
|
-
|
|
258
|
-
if (error instanceof Error) {
|
|
259
|
-
if (error.message.includes('fetch') || error.message.includes('network')) {
|
|
260
|
-
console.log(chalk.red('\n Could not connect to CodeBakers server.'));
|
|
261
|
-
console.log(chalk.gray(' Check your internet connection and try again.\n'));
|
|
262
|
-
} else {
|
|
263
|
-
console.log(chalk.red(`\n ${error.message}\n`));
|
|
264
|
-
}
|
|
265
|
-
} else {
|
|
266
|
-
console.log(chalk.red('\n An unexpected error occurred.\n'));
|
|
267
|
-
}
|
|
282
|
+
if (!trialCreated) {
|
|
283
|
+
spinner.warn('Authorization timed out');
|
|
284
|
+
console.log(chalk.yellow('\n Please try again or authorize manually:\n'));
|
|
285
|
+
console.log(chalk.cyan(` ${authUrl}\n`));
|
|
268
286
|
}
|
|
269
287
|
}
|
|
270
288
|
|
package/src/mcp/server.ts
CHANGED
|
@@ -1172,13 +1172,13 @@ class CodeBakersServer {
|
|
|
1172
1172
|
{
|
|
1173
1173
|
name: 'detect_intent',
|
|
1174
1174
|
description:
|
|
1175
|
-
'
|
|
1175
|
+
'Lists all available CodeBakers MCP tools. Only use this when user explicitly asks "what tools are available" or "help". Do NOT use for normal requests - just call the appropriate tool directly.',
|
|
1176
1176
|
inputSchema: {
|
|
1177
1177
|
type: 'object' as const,
|
|
1178
1178
|
properties: {
|
|
1179
1179
|
userMessage: {
|
|
1180
1180
|
type: 'string',
|
|
1181
|
-
description: 'The user\'s message
|
|
1181
|
+
description: 'The user\'s message (for context only)',
|
|
1182
1182
|
},
|
|
1183
1183
|
},
|
|
1184
1184
|
required: ['userMessage'],
|
|
@@ -6673,136 +6673,25 @@ You cannot write code without calling this tool first.
|
|
|
6673
6673
|
*/
|
|
6674
6674
|
private handleDetectIntent(args: { userMessage: string }) {
|
|
6675
6675
|
const { userMessage } = args;
|
|
6676
|
-
const msg = userMessage.toLowerCase();
|
|
6677
6676
|
|
|
6678
|
-
//
|
|
6679
|
-
|
|
6680
|
-
{
|
|
6681
|
-
keywords: ['upgrade codebakers', 'update patterns', 'sync patterns', 'download patterns', 'get latest patterns'],
|
|
6682
|
-
tool: 'update_patterns',
|
|
6683
|
-
description: 'Download latest CLAUDE.md and all .claude/ modules from the CodeBakers server',
|
|
6684
|
-
action: 'WRITE - Will overwrite local pattern files with server versions',
|
|
6685
|
-
isDestructive: true,
|
|
6686
|
-
},
|
|
6687
|
-
{
|
|
6688
|
-
keywords: ['upgrade', 'improve code', 'make production ready', 'code quality'],
|
|
6689
|
-
tool: 'upgrade',
|
|
6690
|
-
description: 'Analyze your code for quality improvements (does NOT download patterns)',
|
|
6691
|
-
action: 'READ-ONLY - Analyzes code and suggests improvements',
|
|
6692
|
-
isDestructive: false,
|
|
6693
|
-
},
|
|
6694
|
-
{
|
|
6695
|
-
keywords: ['build', 'create project', 'new project', 'scaffold', 'start fresh'],
|
|
6696
|
-
tool: 'scaffold_project',
|
|
6697
|
-
description: 'Create a new project from scratch with CodeBakers patterns',
|
|
6698
|
-
action: 'WRITE - Will create new files and folders',
|
|
6699
|
-
isDestructive: true,
|
|
6700
|
-
},
|
|
6701
|
-
{
|
|
6702
|
-
keywords: ['add feature', 'implement', 'build feature', 'create feature'],
|
|
6703
|
-
tool: 'optimize_and_build',
|
|
6704
|
-
description: 'Optimize your feature request with AI and fetch relevant patterns',
|
|
6705
|
-
action: 'READ + ASSIST - Fetches patterns and guides implementation',
|
|
6706
|
-
isDestructive: false,
|
|
6707
|
-
},
|
|
6708
|
-
{
|
|
6709
|
-
keywords: ['audit', 'review code', 'check code', 'code review'],
|
|
6710
|
-
tool: 'run_audit',
|
|
6711
|
-
description: 'Run comprehensive code quality audit',
|
|
6712
|
-
action: 'READ-ONLY - Analyzes code and reports issues',
|
|
6713
|
-
isDestructive: false,
|
|
6714
|
-
},
|
|
6715
|
-
{
|
|
6716
|
-
keywords: ['heal', 'fix errors', 'auto-fix', 'fix bugs'],
|
|
6717
|
-
tool: 'heal',
|
|
6718
|
-
description: 'AI-powered error detection and automatic fixing',
|
|
6719
|
-
action: 'WRITE - May modify files to fix errors',
|
|
6720
|
-
isDestructive: true,
|
|
6721
|
-
},
|
|
6722
|
-
{
|
|
6723
|
-
keywords: ['design', 'clone design', 'copy design', 'match design'],
|
|
6724
|
-
tool: 'design',
|
|
6725
|
-
description: 'Clone a design from mockups, screenshots, or websites',
|
|
6726
|
-
action: 'WRITE - Will generate component files',
|
|
6727
|
-
isDestructive: true,
|
|
6728
|
-
},
|
|
6729
|
-
{
|
|
6730
|
-
keywords: ['status', 'progress', "what's built", 'where am i'],
|
|
6731
|
-
tool: 'project_status',
|
|
6732
|
-
description: 'Show current project build progress and stats',
|
|
6733
|
-
action: 'READ-ONLY - Shows project state',
|
|
6734
|
-
isDestructive: false,
|
|
6735
|
-
},
|
|
6736
|
-
{
|
|
6737
|
-
keywords: ['run tests', 'test', 'check tests'],
|
|
6738
|
-
tool: 'run_tests',
|
|
6739
|
-
description: 'Execute the project test suite',
|
|
6740
|
-
action: 'READ-ONLY - Runs tests and reports results',
|
|
6741
|
-
isDestructive: false,
|
|
6742
|
-
},
|
|
6743
|
-
{
|
|
6744
|
-
keywords: ['list patterns', 'show patterns', 'what patterns'],
|
|
6745
|
-
tool: 'list_patterns',
|
|
6746
|
-
description: 'List all available CodeBakers patterns',
|
|
6747
|
-
action: 'READ-ONLY - Shows available patterns',
|
|
6748
|
-
isDestructive: false,
|
|
6749
|
-
},
|
|
6750
|
-
{
|
|
6751
|
-
keywords: ['init', 'initialize', 'add patterns to existing'],
|
|
6752
|
-
tool: 'init_project',
|
|
6753
|
-
description: 'Add CodeBakers patterns to an existing project',
|
|
6754
|
-
action: 'WRITE - Will add CLAUDE.md and .claude/ folder',
|
|
6755
|
-
isDestructive: true,
|
|
6756
|
-
},
|
|
6757
|
-
];
|
|
6758
|
-
|
|
6759
|
-
// Find matching intents
|
|
6760
|
-
const matches = intentPatterns.filter(pattern =>
|
|
6761
|
-
pattern.keywords.some(keyword => msg.includes(keyword))
|
|
6762
|
-
);
|
|
6763
|
-
|
|
6764
|
-
let response = `# 🔍 Intent Detection\n\n`;
|
|
6677
|
+
// Simple tool list - no keyword guessing. Let the AI figure it out from context.
|
|
6678
|
+
let response = `# Available CodeBakers MCP Tools\n\n`;
|
|
6765
6679
|
response += `**Your message:** "${userMessage}"\n\n`;
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
response += `| **Description** | ${match.description} |\n`;
|
|
6782
|
-
response += `| **Action Type** | ${match.action} |\n`;
|
|
6783
|
-
response += `| **Destructive?** | ${match.isDestructive ? '⚠️ YES - modifies files' : '✅ NO - read-only'} |\n\n`;
|
|
6784
|
-
|
|
6785
|
-
if (match.isDestructive) {
|
|
6786
|
-
response += `### ⚠️ Confirmation Required\n\n`;
|
|
6787
|
-
response += `This action will modify files. Do you want to proceed?\n\n`;
|
|
6788
|
-
response += `**Reply "yes" or "proceed" to execute, or describe what you actually want.**\n`;
|
|
6789
|
-
} else {
|
|
6790
|
-
response += `This is a read-only operation. Safe to proceed.\n\n`;
|
|
6791
|
-
response += `**Reply "yes" to execute, or clarify your request.**\n`;
|
|
6792
|
-
}
|
|
6793
|
-
} else {
|
|
6794
|
-
response += `## Multiple Possible Intents\n\n`;
|
|
6795
|
-
response += `Your request could match several tools:\n\n`;
|
|
6796
|
-
|
|
6797
|
-
matches.forEach((match, i) => {
|
|
6798
|
-
response += `### Option ${i + 1}: \`${match.tool}\`\n`;
|
|
6799
|
-
response += `- **What it does:** ${match.description}\n`;
|
|
6800
|
-
response += `- **Action:** ${match.action}\n`;
|
|
6801
|
-
response += `- **Destructive:** ${match.isDestructive ? '⚠️ Yes' : '✅ No'}\n\n`;
|
|
6802
|
-
});
|
|
6803
|
-
|
|
6804
|
-
response += `**Which option do you want?** Reply with the tool name or option number.\n`;
|
|
6805
|
-
}
|
|
6680
|
+
response += `## Tools\n\n`;
|
|
6681
|
+
response += `| Tool | Description |\n`;
|
|
6682
|
+
response += `|------|-------------|\n`;
|
|
6683
|
+
response += `| \`update_patterns\` | Download latest CLAUDE.md from server |\n`;
|
|
6684
|
+
response += `| \`discover_patterns\` | Find patterns for a feature request |\n`;
|
|
6685
|
+
response += `| \`optimize_and_build\` | AI-optimize a feature request |\n`;
|
|
6686
|
+
response += `| \`run_audit\` | Code quality audit |\n`;
|
|
6687
|
+
response += `| \`heal\` | Auto-fix errors |\n`;
|
|
6688
|
+
response += `| \`project_status\` | Show build progress |\n`;
|
|
6689
|
+
response += `| \`run_tests\` | Run test suite |\n`;
|
|
6690
|
+
response += `| \`scaffold_project\` | Create new project |\n`;
|
|
6691
|
+
response += `| \`init_project\` | Add patterns to existing project |\n`;
|
|
6692
|
+
response += `| \`list_patterns\` | List all available patterns |\n`;
|
|
6693
|
+
response += `| \`billing_action\` | Manage subscription |\n\n`;
|
|
6694
|
+
response += `**Pick the tool that matches what you want to do.**\n`;
|
|
6806
6695
|
|
|
6807
6696
|
return {
|
|
6808
6697
|
content: [{
|