@codebakers/cli 1.4.1 → 1.4.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.
@@ -44,6 +44,230 @@ const fs_1 = require("fs");
44
44
  const path_1 = require("path");
45
45
  const child_process_1 = require("child_process");
46
46
  const templates = __importStar(require("../templates/nextjs-supabase.js"));
47
+ const config_js_1 = require("../config.js");
48
+ // Cursor IDE configuration templates
49
+ const CURSORRULES_TEMPLATE = `# CODEBAKERS CURSOR RULES
50
+ # Zero-friction AI assistance - everything is automatic
51
+
52
+ ## ON EVERY MESSAGE - AUTOMATIC WORKFLOW
53
+
54
+ ### PHASE 1: CONTEXT LOAD (automatic)
55
+ 1. Read CLAUDE.md → Load router
56
+ 2. Read PRD.md → Understand what we're building
57
+ 3. Read PROJECT-CONTEXT.md → Understand codebase
58
+ 4. Read PROJECT-STATE.md → Check what's in progress
59
+ 5. Read DECISIONS.md → Know past decisions
60
+
61
+ ### PHASE 2: PRE-FLIGHT CHECK (before writing code)
62
+ Ask yourself silently:
63
+ - [ ] What existing code does this touch? (check PROJECT-CONTEXT.md)
64
+ - [ ] Is similar code already in the codebase? (copy that pattern)
65
+ - [ ] What's the data model involved?
66
+ - [ ] What are the error cases?
67
+ - [ ] Is someone else working on this? (check PROJECT-STATE.md)
68
+
69
+ ### PHASE 3: EXECUTE
70
+ - State: \`📋 CodeBakers | [Type] | Modules: [list]\`
71
+ - Load required modules from .claude/
72
+ - Follow patterns EXACTLY
73
+
74
+ ### PHASE 4: SELF-REVIEW (before saying "done")
75
+ - [ ] TypeScript compiles? (npx tsc --noEmit)
76
+ - [ ] Imports resolve correctly?
77
+ - [ ] Error handling exists?
78
+ - [ ] Matches existing patterns in codebase?
79
+ - [ ] Tests written?
80
+ - [ ] PROJECT-STATE.md updated?
81
+
82
+ If ANY check fails, fix it before responding.
83
+
84
+ ## REMEMBER
85
+ - You are a full product team, not just a code assistant
86
+ - The modules contain production-tested patterns — USE THEM
87
+ - When in doubt, check existing code first
88
+ `;
89
+ const CURSORIGNORE_TEMPLATE = `# CodeBakers - Files to ignore in Cursor context
90
+
91
+ # Dependencies
92
+ node_modules/
93
+ .pnpm-store/
94
+
95
+ # Build outputs
96
+ dist/
97
+ build/
98
+ .next/
99
+ .nuxt/
100
+ out/
101
+
102
+ # Cache
103
+ .cache/
104
+ .turbo/
105
+ .eslintcache
106
+ *.tsbuildinfo
107
+
108
+ # Logs
109
+ logs/
110
+ *.log
111
+
112
+ # Environment files
113
+ .env
114
+ .env.local
115
+ .env.*.local
116
+
117
+ # IDE
118
+ .idea/
119
+ *.swp
120
+
121
+ # OS
122
+ .DS_Store
123
+ Thumbs.db
124
+
125
+ # Test coverage
126
+ coverage/
127
+
128
+ # Package locks
129
+ package-lock.json
130
+ yarn.lock
131
+ pnpm-lock.yaml
132
+
133
+ # Generated files
134
+ *.min.js
135
+ *.min.css
136
+ *.map
137
+ `;
138
+ function createPrdTemplate(projectName) {
139
+ const date = new Date().toISOString().split('T')[0];
140
+ return `# Product Requirements Document
141
+ # Project: ${projectName}
142
+ # Created: ${date}
143
+
144
+ ## Overview
145
+ **One-liner:** [Describe this project in one sentence]
146
+
147
+ **Problem:** [What problem does this solve?]
148
+
149
+ **Solution:** [How does this solve it?]
150
+
151
+ ## Target Users
152
+ - **Primary:** [Who is the main user?]
153
+ - **Secondary:** [Other users?]
154
+
155
+ ## Core Features (MVP)
156
+ <!-- List the MINIMUM features needed to launch -->
157
+
158
+ 1. [ ] **Feature 1:** [Description]
159
+ - Acceptance criteria: [How do we know it's done?]
160
+
161
+ 2. [ ] **Feature 2:** [Description]
162
+ - Acceptance criteria: [How do we know it's done?]
163
+
164
+ 3. [ ] **Feature 3:** [Description]
165
+ - Acceptance criteria: [How do we know it's done?]
166
+
167
+ ## Nice-to-Have Features (Post-MVP)
168
+
169
+ 1. [ ] [Feature description]
170
+ 2. [ ] [Feature description]
171
+
172
+ ## Technical Requirements
173
+
174
+ - **Must use:** [Required technologies, APIs, etc.]
175
+ - **Must avoid:** [Things you don't want]
176
+ - **Performance:** [Any speed/scale requirements?]
177
+ - **Security:** [Auth requirements, data sensitivity?]
178
+
179
+ ## Success Metrics
180
+ - [ ] [How will you measure success?]
181
+ - [ ] [What does "done" look like?]
182
+
183
+ ---
184
+ <!-- AI INSTRUCTIONS -->
185
+ <!-- When building features, reference this PRD -->
186
+ <!-- Check off features as they're completed -->
187
+ `;
188
+ }
189
+ function createProjectState(projectName) {
190
+ const date = new Date().toISOString().split('T')[0];
191
+ return `# PROJECT STATE
192
+ # Last Updated: ${date}
193
+ # Auto-maintained by AI - update when starting/completing tasks
194
+
195
+ ## Project Info
196
+ name: ${projectName}
197
+ phase: setup
198
+
199
+ ## In Progress
200
+ <!-- AI: Add tasks here when you START working on them -->
201
+
202
+ ## Completed
203
+ <!-- AI: Move tasks here when DONE -->
204
+
205
+ ## Next Up
206
+ <!-- AI: Queue of upcoming tasks -->
207
+ `;
208
+ }
209
+ function createProjectContext(projectName) {
210
+ const date = new Date().toISOString().split('T')[0];
211
+ return `# PROJECT CONTEXT
212
+ # Last Scanned: ${date}
213
+ # AI: Update this when you first analyze the project
214
+
215
+ ## Overview
216
+ name: ${projectName}
217
+ description: [AI will fill after scanning]
218
+
219
+ ## Tech Stack
220
+ framework: Next.js 14
221
+ language: TypeScript
222
+ database: Drizzle ORM + Supabase
223
+ auth: Supabase Auth
224
+ styling: Tailwind CSS
225
+
226
+ ## Project Structure
227
+ \`\`\`
228
+ src/
229
+ ├── app/ ← Pages & layouts
230
+ ├── components/ ← React components
231
+ ├── lib/ ← Utilities & clients
232
+ │ └── supabase/ ← Supabase clients
233
+ ├── db/ ← Database schema & queries
234
+ ├── services/ ← Business logic
235
+ └── types/ ← TypeScript types
236
+ \`\`\`
237
+
238
+ ## Key Files
239
+ - Entry point: src/app/page.tsx
240
+ - Database schema: src/db/schema.ts
241
+ - API routes: src/app/api/
242
+
243
+ ## Notes
244
+ <!-- AI: Any important context about this specific project -->
245
+ `;
246
+ }
247
+ function createDecisionsLog(projectName) {
248
+ const date = new Date().toISOString().split('T')[0];
249
+ return `# ARCHITECTURAL DECISIONS
250
+ # Project: ${projectName}
251
+ # AI: Add entries here when making significant technical choices
252
+
253
+ ## How to Use This File
254
+ When you make a decision that affects architecture, add an entry:
255
+ - Date
256
+ - Decision
257
+ - Reason
258
+ - Alternatives considered
259
+
260
+ ---
261
+
262
+ ## ${date}: Project Initialized
263
+ **Decision:** Using CodeBakers pattern system with Next.js + Supabase + Drizzle
264
+ **Reason:** Production-ready stack with type safety and excellent DX
265
+
266
+ ---
267
+
268
+ <!-- AI: Add new decisions above this line -->
269
+ `;
270
+ }
47
271
  async function prompt(question) {
48
272
  const rl = (0, readline_1.createInterface)({
49
273
  input: process.stdin,
@@ -94,7 +318,6 @@ async function scaffold() {
94
318
  experienceLevel = await prompt(' Enter 1, 2, or 3: ');
95
319
  }
96
320
  const isBeginnerMode = experienceLevel === '1';
97
- const showBriefExplanations = experienceLevel === '2';
98
321
  // Select stack with explanations for beginners
99
322
  console.log(chalk_1.default.white('\n Select your stack:\n'));
100
323
  if (isBeginnerMode) {
@@ -208,15 +431,85 @@ async function scaffold() {
208
431
  console.log(chalk_1.default.gray(' Run `npm install` manually.\n'));
209
432
  }
210
433
  }
434
+ spinner.succeed('Project structure created!');
435
+ // Auto-install CodeBakers patterns
436
+ console.log(chalk_1.default.white('\n Installing CodeBakers patterns...\n'));
437
+ const apiKey = (0, config_js_1.getApiKey)();
438
+ let patternsInstalled = false;
439
+ if (apiKey) {
440
+ const patternSpinner = (0, ora_1.default)(' Downloading patterns...').start();
441
+ try {
442
+ const apiUrl = (0, config_js_1.getApiUrl)();
443
+ const response = await fetch(`${apiUrl}/api/content`, {
444
+ method: 'GET',
445
+ headers: {
446
+ Authorization: `Bearer ${apiKey}`,
447
+ },
448
+ });
449
+ if (response.ok) {
450
+ const content = await response.json();
451
+ // Write CLAUDE.md (main router)
452
+ if (content.router) {
453
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'CLAUDE.md'), content.router);
454
+ }
455
+ // Write pattern modules to .claude/
456
+ if (content.modules && Object.keys(content.modules).length > 0) {
457
+ const modulesDir = (0, path_1.join)(cwd, '.claude');
458
+ if (!(0, fs_1.existsSync)(modulesDir)) {
459
+ (0, fs_1.mkdirSync)(modulesDir, { recursive: true });
460
+ }
461
+ for (const [name, data] of Object.entries(content.modules)) {
462
+ (0, fs_1.writeFileSync)((0, path_1.join)(modulesDir, name), data);
463
+ }
464
+ }
465
+ // Write project management files
466
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'PRD.md'), createPrdTemplate(projectName));
467
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'PROJECT-STATE.md'), createProjectState(projectName));
468
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'PROJECT-CONTEXT.md'), createProjectContext(projectName));
469
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, 'DECISIONS.md'), createDecisionsLog(projectName));
470
+ // Write Cursor IDE files
471
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, '.cursorrules'), CURSORRULES_TEMPLATE);
472
+ (0, fs_1.writeFileSync)((0, path_1.join)(cwd, '.cursorignore'), CURSORIGNORE_TEMPLATE);
473
+ // Create .vscode settings
474
+ const vscodeDir = (0, path_1.join)(cwd, '.vscode');
475
+ if (!(0, fs_1.existsSync)(vscodeDir)) {
476
+ (0, fs_1.mkdirSync)(vscodeDir, { recursive: true });
477
+ }
478
+ (0, fs_1.writeFileSync)((0, path_1.join)(vscodeDir, 'settings.json'), JSON.stringify({
479
+ "cursor.chat.defaultContext": ["CLAUDE.md", "PRD.md", "PROJECT-CONTEXT.md"],
480
+ "cursor.chat.alwaysIncludeRules": true
481
+ }, null, 2));
482
+ // Update .gitignore
483
+ const gitignorePath = (0, path_1.join)(cwd, '.gitignore');
484
+ if ((0, fs_1.existsSync)(gitignorePath)) {
485
+ const gitignore = (0, fs_1.readFileSync)(gitignorePath, 'utf-8');
486
+ if (!gitignore.includes('.cursorrules')) {
487
+ (0, fs_1.writeFileSync)(gitignorePath, gitignore + '\n# CodeBakers\n.cursorrules\n.claude/\n');
488
+ }
489
+ }
490
+ patternSpinner.succeed(`Patterns installed! (v${content.version})`);
491
+ patternsInstalled = true;
492
+ }
493
+ else {
494
+ patternSpinner.warn('Could not download patterns (will need to run codebakers init later)');
495
+ }
496
+ }
497
+ catch {
498
+ patternSpinner.warn('Could not download patterns (will need to run codebakers init later)');
499
+ }
500
+ }
501
+ else {
502
+ console.log(chalk_1.default.yellow(' ⚠️ Not logged in - run `codebakers setup` first to get patterns\n'));
503
+ }
211
504
  // Success message
212
505
  console.log(chalk_1.default.green(`
213
506
  ╔═══════════════════════════════════════════════════════════╗
214
507
  ║ ║
215
- ║ ${chalk_1.default.bold('✓ Project scaffolded successfully!')}
508
+ ║ ${chalk_1.default.bold('✓ Project created successfully!')}
216
509
  ║ ║
217
510
  ╚═══════════════════════════════════════════════════════════╝
218
511
  `));
219
- console.log(chalk_1.default.white(' Project structure:\n'));
512
+ console.log(chalk_1.default.white(' What was created:\n'));
220
513
  if (isBeginnerMode) {
221
514
  console.log(chalk_1.default.gray(' src/'));
222
515
  console.log(chalk_1.default.gray(' ├── app/ ') + chalk_1.default.cyan('← Your pages (what users see)'));
@@ -237,6 +530,12 @@ async function scaffold() {
237
530
  console.log(chalk_1.default.gray(' ├── services/ ') + chalk_1.default.cyan('← Business logic'));
238
531
  console.log(chalk_1.default.gray(' └── types/ ') + chalk_1.default.cyan('← TypeScript types'));
239
532
  }
533
+ if (patternsInstalled) {
534
+ console.log('');
535
+ console.log(chalk_1.default.gray(' CLAUDE.md ') + chalk_1.default.cyan('← AI instructions (reads automatically!)'));
536
+ console.log(chalk_1.default.gray(' PRD.md ') + chalk_1.default.cyan('← Your product requirements'));
537
+ console.log(chalk_1.default.gray(' .claude/ ') + chalk_1.default.cyan('← 34 production patterns'));
538
+ }
240
539
  console.log('');
241
540
  console.log(chalk_1.default.white(' Next steps:\n'));
242
541
  if (isBeginnerMode) {
@@ -251,15 +550,14 @@ async function scaffold() {
251
550
  console.log(chalk_1.default.gray(' Run: npm run dev'));
252
551
  console.log(chalk_1.default.gray(' Open: http://localhost:3000 in your browser'));
253
552
  console.log('');
254
- console.log(chalk_1.default.cyan(' 4. ') + chalk_1.default.white('Add AI superpowers:'));
255
- console.log(chalk_1.default.gray(' Run: codebakers init'));
256
- console.log(chalk_1.default.gray(' Now AI will follow professional coding patterns!\n'));
553
+ console.log(chalk_1.default.cyan(' 4. ') + chalk_1.default.white('Start building!'));
554
+ console.log(chalk_1.default.gray(' Tell your AI: "Build me a [feature]"'));
555
+ console.log(chalk_1.default.gray(' The AI already has all the patterns loaded!\n'));
257
556
  }
258
557
  else {
259
558
  console.log(chalk_1.default.cyan(' 1. ') + chalk_1.default.gray('Update .env.local with your Supabase credentials'));
260
559
  console.log(chalk_1.default.cyan(' 2. ') + chalk_1.default.gray('Run `npm run dev` to start development'));
261
- console.log(chalk_1.default.cyan(' 3. ') + chalk_1.default.gray('Run `codebakers init` to add CodeBakers patterns'));
262
- console.log(chalk_1.default.cyan(' 4. ') + chalk_1.default.gray('Start building with AI assistance!\n'));
560
+ console.log(chalk_1.default.cyan(' 3. ') + chalk_1.default.gray('Tell your AI what to build - patterns are already loaded!\n'));
263
561
  console.log(chalk_1.default.white(' Supabase setup:\n'));
264
562
  console.log(chalk_1.default.gray(' 1. Create a project at https://supabase.com'));
265
563
  console.log(chalk_1.default.gray(' 2. Go to Settings → API'));
@@ -17,9 +17,12 @@ async function serve() {
17
17
  console.error(chalk_1.default.green(' Starting MCP server on stdio...'));
18
18
  console.error(chalk_1.default.gray(' This server provides pattern tools to Claude Code.\n'));
19
19
  console.error(chalk_1.default.gray(' Available tools:'));
20
- console.error(chalk_1.default.gray(' - get_pattern: Fetch a single pattern'));
21
- console.error(chalk_1.default.gray(' - list_patterns: List all available patterns'));
22
- console.error(chalk_1.default.gray(' - get_patterns: Fetch multiple patterns\n'));
20
+ console.error(chalk_1.default.gray(' - scaffold_project: Create a new project from AI chat'));
21
+ console.error(chalk_1.default.gray(' - init_project: Add patterns to existing project'));
22
+ console.error(chalk_1.default.gray(' - set_experience_level: Set beginner/intermediate/advanced mode'));
23
+ console.error(chalk_1.default.gray(' - get_experience_level: Check current experience mode'));
24
+ console.error(chalk_1.default.gray(' - optimize_and_build: AI-powered prompt optimization'));
25
+ console.error(chalk_1.default.gray(' - get_pattern, list_patterns, search_patterns\n'));
23
26
  // Dynamically import and run the MCP server
24
27
  const { runServer } = await import('../mcp/server.js');
25
28
  await runServer();
@@ -103,8 +103,11 @@ function showFinalInstructions() {
103
103
  console.log(chalk_1.default.blue(' ══════════════════════════════════════════════════════════'));
104
104
  console.log(chalk_1.default.white.bold('\n 🎉 Setup Complete!\n'));
105
105
  console.log(chalk_1.default.blue(' ══════════════════════════════════════════════════════════\n'));
106
- console.log(chalk_1.default.white(' CodeBakers is now ready. Try this prompt:\n'));
107
- console.log(chalk_1.default.cyan(' "Build a login form with email validation"\n'));
108
- console.log(chalk_1.default.gray(' Claude will now use CodeBakers patterns automatically.\n'));
106
+ console.log(chalk_1.default.white.bold(' 👉 NEXT: Close this terminal and open your AI:\n'));
107
+ console.log(chalk_1.default.cyan(' Claude Code') + chalk_1.default.gray(' - Open any project folder'));
108
+ console.log(chalk_1.default.cyan(' • Cursor') + chalk_1.default.gray(' - Open Composer (Cmd+I / Ctrl+I)\n'));
109
+ console.log(chalk_1.default.white(' Then just describe what you want to build:\n'));
110
+ console.log(chalk_1.default.green(' "Build me a todo app with user authentication"\n'));
111
+ console.log(chalk_1.default.gray(' The AI will use CodeBakers patterns automatically.'));
109
112
  console.log(chalk_1.default.gray(' Need help? https://codebakers.ai/docs\n'));
110
113
  }
package/dist/config.d.ts CHANGED
@@ -1,5 +1,8 @@
1
+ export type ExperienceLevel = 'beginner' | 'intermediate' | 'advanced';
1
2
  export declare function getApiKey(): string | null;
2
3
  export declare function setApiKey(key: string): void;
3
4
  export declare function clearApiKey(): void;
4
5
  export declare function getApiUrl(): string;
5
6
  export declare function setApiUrl(url: string): void;
7
+ export declare function getExperienceLevel(): ExperienceLevel;
8
+ export declare function setExperienceLevel(level: ExperienceLevel): void;
package/dist/config.js CHANGED
@@ -8,12 +8,15 @@ exports.setApiKey = setApiKey;
8
8
  exports.clearApiKey = clearApiKey;
9
9
  exports.getApiUrl = getApiUrl;
10
10
  exports.setApiUrl = setApiUrl;
11
+ exports.getExperienceLevel = getExperienceLevel;
12
+ exports.setExperienceLevel = setExperienceLevel;
11
13
  const conf_1 = __importDefault(require("conf"));
12
14
  const config = new conf_1.default({
13
15
  projectName: 'codebakers',
14
16
  defaults: {
15
17
  apiKey: null,
16
18
  apiUrl: 'https://codebakers.ai',
19
+ experienceLevel: 'intermediate',
17
20
  },
18
21
  });
19
22
  function getApiKey() {
@@ -31,3 +34,9 @@ function getApiUrl() {
31
34
  function setApiUrl(url) {
32
35
  config.set('apiUrl', url);
33
36
  }
37
+ function getExperienceLevel() {
38
+ return config.get('experienceLevel');
39
+ }
40
+ function setExperienceLevel(level) {
41
+ config.set('experienceLevel', level);
42
+ }