codebakers 2.0.4 → 2.0.10

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.
@@ -7,6 +7,8 @@ import { execa } from 'execa';
7
7
  import { Config } from '../utils/config.js';
8
8
  import { loadPatterns } from '../patterns/loader.js';
9
9
  import { runPatternCheck } from './check.js';
10
+ import { textWithVoice, checkVoiceAvailability } from '../utils/voice.js';
11
+ import { readClipboard, readFile, formatFilesForContext, looksLikePaste, handlePastedContent } from '../utils/files.js';
10
12
 
11
13
  interface CodeOptions {
12
14
  watch?: boolean;
@@ -82,11 +84,22 @@ export async function codeCommand(prompt?: string, options: CodeOptions = {}): P
82
84
  await processUserInput(prompt, messages, anthropic, systemPrompt, projectContext, config);
83
85
  }
84
86
 
87
+ // Check for voice support
88
+ const hasVoice = await checkVoiceAvailability();
89
+
90
+ console.log(chalk.dim(' šŸ’” Tips:'));
91
+ if (hasVoice) {
92
+ console.log(chalk.dim(' • Type "v" for voice input'));
93
+ }
94
+ console.log(chalk.dim(' • Type "clip" to read from clipboard'));
95
+ console.log(chalk.dim(' • Drag & drop files or paste file paths'));
96
+ console.log(chalk.dim(' • Paste code directly and I\'ll detect it\n'));
97
+
85
98
  // Interactive loop
86
99
  while (true) {
87
- const input = await p.text({
100
+ const input = await textWithVoice({
88
101
  message: '',
89
- placeholder: 'What do you want to build?',
102
+ placeholder: 'What do you want to build? (or paste code/file path)',
90
103
  });
91
104
 
92
105
  if (p.isCancel(input)) {
@@ -94,7 +107,8 @@ export async function codeCommand(prompt?: string, options: CodeOptions = {}): P
94
107
  break;
95
108
  }
96
109
 
97
- const userInput = (input as string).trim();
110
+ let userInput = (input as string).trim();
111
+ let fileContext = '';
98
112
 
99
113
  if (!userInput) continue;
100
114
 
@@ -114,8 +128,91 @@ export async function codeCommand(prompt?: string, options: CodeOptions = {}): P
114
128
  continue;
115
129
  }
116
130
 
117
- // Process input with AI
118
- await processUserInput(userInput, messages, anthropic, systemPrompt, projectContext, config);
131
+ // Check for clipboard command
132
+ if (userInput.toLowerCase() === 'clip' || userInput.toLowerCase() === 'clipboard' || userInput.toLowerCase() === 'paste') {
133
+ const clipContent = await readClipboard();
134
+ if (clipContent) {
135
+ console.log(chalk.green(`\nšŸ“‹ Read ${clipContent.length} characters from clipboard\n`));
136
+
137
+ // Check if clipboard is a file path
138
+ if (await fs.pathExists(clipContent.trim())) {
139
+ const file = await readFile(clipContent.trim());
140
+ if (file) {
141
+ fileContext = formatFilesForContext([file]);
142
+ console.log(chalk.green(`šŸ“„ Loaded file: ${file.name}\n`));
143
+
144
+ const instruction = await p.text({
145
+ message: `What should I do with ${file.name}?`,
146
+ placeholder: 'Fix any issues in this code',
147
+ });
148
+ if (p.isCancel(instruction)) continue;
149
+ userInput = instruction as string;
150
+ }
151
+ } else {
152
+ // Clipboard contains code/text
153
+ fileContext = `\n\n--- CLIPBOARD CONTENT ---\n\`\`\`\n${clipContent}\n\`\`\`\n--- END ---\n\n`;
154
+
155
+ const action = await p.select({
156
+ message: 'What should I do with this?',
157
+ options: [
158
+ { value: 'analyze', label: 'šŸ” Analyze this' },
159
+ { value: 'fix', label: 'šŸ”§ Fix issues' },
160
+ { value: 'explain', label: 'šŸ“– Explain' },
161
+ { value: 'improve', label: '✨ Improve' },
162
+ { value: 'custom', label: 'āœļø Custom' },
163
+ ],
164
+ });
165
+
166
+ if (p.isCancel(action)) continue;
167
+
168
+ if (action === 'custom') {
169
+ const custom = await p.text({ message: 'What should I do?', placeholder: 'Add TypeScript types' });
170
+ if (p.isCancel(custom)) continue;
171
+ userInput = custom as string;
172
+ } else {
173
+ const actions: Record<string, string> = {
174
+ analyze: 'Analyze this code and explain what it does',
175
+ fix: 'Fix any bugs or issues in this code',
176
+ explain: 'Explain this code step by step',
177
+ improve: 'Improve and refactor this code',
178
+ };
179
+ userInput = actions[action as string];
180
+ }
181
+ }
182
+ } else {
183
+ console.log(chalk.yellow('Clipboard is empty'));
184
+ continue;
185
+ }
186
+ }
187
+
188
+ // Check if input is a file path
189
+ else if (await fs.pathExists(userInput)) {
190
+ const file = await readFile(userInput);
191
+ if (file) {
192
+ fileContext = formatFilesForContext([file]);
193
+ console.log(chalk.green(`\nšŸ“„ Loaded file: ${file.name}\n`));
194
+
195
+ const instruction = await p.text({
196
+ message: `What should I do with ${file.name}?`,
197
+ placeholder: 'Analyze and improve this code',
198
+ });
199
+ if (p.isCancel(instruction)) continue;
200
+ userInput = instruction as string;
201
+ }
202
+ }
203
+
204
+ // Check if input looks like pasted code
205
+ else if (looksLikePaste(userInput)) {
206
+ const result = await handlePastedContent(userInput);
207
+ if (result) {
208
+ userInput = result.prompt;
209
+ fileContext = result.context;
210
+ }
211
+ }
212
+
213
+ // Process input with AI (include file context if any)
214
+ const fullInput = fileContext ? userInput + fileContext : userInput;
215
+ await processUserInput(fullInput, messages, anthropic, systemPrompt, projectContext, config);
119
216
  }
120
217
  }
121
218