@nclamvn/vibecode-cli 1.7.0 → 1.8.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.
- package/bin/vibecode.js +53 -0
- package/package.json +1 -1
- package/src/commands/ask.js +230 -0
- package/src/commands/docs.js +167 -0
- package/src/commands/git.js +103 -2
- package/src/commands/migrate.js +341 -0
- package/src/commands/refactor.js +205 -0
- package/src/commands/review.js +126 -1
- package/src/commands/security.js +229 -0
- package/src/commands/test.js +194 -0
- package/src/index.js +8 -0
package/bin/vibecode.js
CHANGED
|
@@ -26,6 +26,13 @@ import {
|
|
|
26
26
|
gitCommand,
|
|
27
27
|
watchCommand,
|
|
28
28
|
shellCommand,
|
|
29
|
+
// Phase K Commands
|
|
30
|
+
testCommand,
|
|
31
|
+
docsCommand,
|
|
32
|
+
refactorCommand,
|
|
33
|
+
securityCommand,
|
|
34
|
+
askCommand,
|
|
35
|
+
migrateCommand,
|
|
29
36
|
VERSION
|
|
30
37
|
} from '../src/index.js';
|
|
31
38
|
|
|
@@ -98,6 +105,8 @@ program
|
|
|
98
105
|
.command('review')
|
|
99
106
|
.description('Review build against acceptance criteria')
|
|
100
107
|
.option('--skip-manual', 'Skip manual verification prompts')
|
|
108
|
+
.option('--ai', 'AI-powered code review')
|
|
109
|
+
.option('-p, --path <dir>', 'Specific path to review')
|
|
101
110
|
.action(reviewCommand);
|
|
102
111
|
|
|
103
112
|
program
|
|
@@ -217,6 +226,7 @@ program
|
|
|
217
226
|
.option('-a, --auto', 'Auto-stage all changes before commit')
|
|
218
227
|
.option('-m, --message <msg>', 'Commit message')
|
|
219
228
|
.option('--staged', 'Show only staged changes (for diff)')
|
|
229
|
+
.option('--review', 'AI-powered diff review')
|
|
220
230
|
.option('--count <n>', 'Number of commits to show (for log)', parseInt)
|
|
221
231
|
.option('--all', 'Include all files (for add)')
|
|
222
232
|
.action((subcommand, args, options) => {
|
|
@@ -250,6 +260,49 @@ program
|
|
|
250
260
|
.description('Interactive shell with vibecode context and AI assistance')
|
|
251
261
|
.action(shellCommand);
|
|
252
262
|
|
|
263
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
264
|
+
// Phase K Commands - Maximize Claude Code
|
|
265
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
program
|
|
268
|
+
.command('test [path]')
|
|
269
|
+
.description('🧪 Test generation and running')
|
|
270
|
+
.option('-g, --generate', 'Generate tests with AI')
|
|
271
|
+
.option('-r, --run', 'Run tests')
|
|
272
|
+
.option('-c, --coverage', 'Show coverage')
|
|
273
|
+
.action(testCommand);
|
|
274
|
+
|
|
275
|
+
program
|
|
276
|
+
.command('docs')
|
|
277
|
+
.description('📚 Generate documentation with AI')
|
|
278
|
+
.option('-g, --generate', 'Generate docs')
|
|
279
|
+
.option('-t, --type <type>', 'Doc type: readme, api, architecture, jsdoc, all')
|
|
280
|
+
.action(docsCommand);
|
|
281
|
+
|
|
282
|
+
program
|
|
283
|
+
.command('refactor [path]')
|
|
284
|
+
.description('🔄 AI-powered code refactoring')
|
|
285
|
+
.option('-t, --type <type>', 'Type: clean, dry, performance, architecture, modularize, modernize')
|
|
286
|
+
.option('-d, --description <desc>', 'Custom refactoring description')
|
|
287
|
+
.action(refactorCommand);
|
|
288
|
+
|
|
289
|
+
program
|
|
290
|
+
.command('security')
|
|
291
|
+
.description('🔒 Security audit with AI analysis')
|
|
292
|
+
.option('-f, --fix', 'Auto-fix security issues')
|
|
293
|
+
.action(securityCommand);
|
|
294
|
+
|
|
295
|
+
program
|
|
296
|
+
.command('ask [question...]')
|
|
297
|
+
.description('💬 Ask questions about your codebase')
|
|
298
|
+
.action(askCommand);
|
|
299
|
+
|
|
300
|
+
program
|
|
301
|
+
.command('migrate [description...]')
|
|
302
|
+
.description('🔄 AI-powered code migration')
|
|
303
|
+
.option('-p, --path <path>', 'Specific path to migrate')
|
|
304
|
+
.action(migrateCommand);
|
|
305
|
+
|
|
253
306
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
254
307
|
// Parse - If no command provided, show interactive wizard
|
|
255
308
|
// ─────────────────────────────────────────────────────────────────────────────
|
package/package.json
CHANGED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// VIBECODE CLI - Ask Command
|
|
3
|
+
// Phase K6: Codebase Q&A
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import readline from 'readline';
|
|
11
|
+
|
|
12
|
+
export async function askCommand(question, options = {}) {
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
|
|
15
|
+
// If no question, enter interactive mode
|
|
16
|
+
if (!question || question.length === 0) {
|
|
17
|
+
return interactiveAsk(cwd);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const questionText = Array.isArray(question) ? question.join(' ') : question;
|
|
21
|
+
return answerQuestion(cwd, questionText);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function interactiveAsk(cwd) {
|
|
25
|
+
console.log(chalk.cyan(`
|
|
26
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
27
|
+
│ 💬 CODEBASE Q&A │
|
|
28
|
+
│ │
|
|
29
|
+
│ Ask anything about your codebase. │
|
|
30
|
+
│ Type 'exit' to quit. │
|
|
31
|
+
│ │
|
|
32
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
33
|
+
`));
|
|
34
|
+
|
|
35
|
+
const rl = readline.createInterface({
|
|
36
|
+
input: process.stdin,
|
|
37
|
+
output: process.stdout,
|
|
38
|
+
prompt: chalk.green('ask> ')
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
rl.prompt();
|
|
42
|
+
|
|
43
|
+
rl.on('line', async (line) => {
|
|
44
|
+
const input = line.trim();
|
|
45
|
+
|
|
46
|
+
if (!input) {
|
|
47
|
+
rl.prompt();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (input === 'exit' || input === 'quit' || input === 'q') {
|
|
52
|
+
console.log(chalk.cyan('\n👋 Goodbye!\n'));
|
|
53
|
+
rl.close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
await answerQuestion(cwd, input);
|
|
58
|
+
console.log('');
|
|
59
|
+
rl.prompt();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
rl.on('close', () => process.exit(0));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function answerQuestion(cwd, question) {
|
|
66
|
+
console.log(chalk.gray('\n Analyzing codebase...\n'));
|
|
67
|
+
|
|
68
|
+
// Build context
|
|
69
|
+
const projectInfo = await getProjectContext(cwd);
|
|
70
|
+
|
|
71
|
+
const prompt = `
|
|
72
|
+
# Codebase Question
|
|
73
|
+
|
|
74
|
+
## Project: ${path.basename(cwd)}
|
|
75
|
+
## Type: ${projectInfo.type}
|
|
76
|
+
|
|
77
|
+
## Project Structure:
|
|
78
|
+
${projectInfo.structure}
|
|
79
|
+
|
|
80
|
+
## Key Files:
|
|
81
|
+
${projectInfo.keyFiles.join('\n')}
|
|
82
|
+
|
|
83
|
+
## Question:
|
|
84
|
+
${question}
|
|
85
|
+
|
|
86
|
+
## Instructions:
|
|
87
|
+
1. Analyze the codebase to answer the question
|
|
88
|
+
2. Reference specific files and line numbers when applicable
|
|
89
|
+
3. Provide code examples if helpful
|
|
90
|
+
4. Be concise but thorough
|
|
91
|
+
5. If you need to look at specific files, do so
|
|
92
|
+
|
|
93
|
+
Answer the question now.
|
|
94
|
+
`;
|
|
95
|
+
|
|
96
|
+
await runClaudeCode(prompt, cwd);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function getProjectContext(cwd) {
|
|
100
|
+
const context = {
|
|
101
|
+
type: 'unknown',
|
|
102
|
+
structure: '',
|
|
103
|
+
keyFiles: []
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Detect project type
|
|
107
|
+
try {
|
|
108
|
+
const pkgPath = path.join(cwd, 'package.json');
|
|
109
|
+
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
|
|
110
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
111
|
+
|
|
112
|
+
if (deps.next) context.type = 'Next.js';
|
|
113
|
+
else if (deps.nuxt) context.type = 'Nuxt';
|
|
114
|
+
else if (deps['@angular/core']) context.type = 'Angular';
|
|
115
|
+
else if (deps.react) context.type = 'React';
|
|
116
|
+
else if (deps.vue) context.type = 'Vue';
|
|
117
|
+
else if (deps.svelte) context.type = 'Svelte';
|
|
118
|
+
else if (deps.express) context.type = 'Express';
|
|
119
|
+
else if (deps.fastify) context.type = 'Fastify';
|
|
120
|
+
else if (deps.koa) context.type = 'Koa';
|
|
121
|
+
else if (deps.nestjs || deps['@nestjs/core']) context.type = 'NestJS';
|
|
122
|
+
else context.type = 'Node.js';
|
|
123
|
+
} catch {
|
|
124
|
+
// Check for other project types
|
|
125
|
+
try {
|
|
126
|
+
await fs.access(path.join(cwd, 'Cargo.toml'));
|
|
127
|
+
context.type = 'Rust';
|
|
128
|
+
} catch {}
|
|
129
|
+
try {
|
|
130
|
+
await fs.access(path.join(cwd, 'go.mod'));
|
|
131
|
+
context.type = 'Go';
|
|
132
|
+
} catch {}
|
|
133
|
+
try {
|
|
134
|
+
await fs.access(path.join(cwd, 'requirements.txt'));
|
|
135
|
+
context.type = 'Python';
|
|
136
|
+
} catch {}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Get directory structure
|
|
140
|
+
context.structure = await getDirectoryTree(cwd, 3);
|
|
141
|
+
|
|
142
|
+
// Get key files
|
|
143
|
+
context.keyFiles = await findKeyFiles(cwd);
|
|
144
|
+
|
|
145
|
+
return context;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function getDirectoryTree(dir, depth, prefix = '') {
|
|
149
|
+
if (depth === 0) return '';
|
|
150
|
+
|
|
151
|
+
let result = '';
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
155
|
+
const filtered = entries.filter(e =>
|
|
156
|
+
!e.name.startsWith('.') &&
|
|
157
|
+
e.name !== 'node_modules' &&
|
|
158
|
+
e.name !== 'dist' &&
|
|
159
|
+
e.name !== 'build' &&
|
|
160
|
+
e.name !== '.next' &&
|
|
161
|
+
e.name !== 'coverage' &&
|
|
162
|
+
e.name !== '__pycache__'
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
for (const entry of filtered.slice(0, 15)) {
|
|
166
|
+
const icon = entry.isDirectory() ? '📁' : '📄';
|
|
167
|
+
result += `${prefix}${icon} ${entry.name}\n`;
|
|
168
|
+
|
|
169
|
+
if (entry.isDirectory() && depth > 1) {
|
|
170
|
+
result += await getDirectoryTree(
|
|
171
|
+
path.join(dir, entry.name),
|
|
172
|
+
depth - 1,
|
|
173
|
+
prefix + ' '
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (filtered.length > 15) {
|
|
179
|
+
result += `${prefix}... and ${filtered.length - 15} more\n`;
|
|
180
|
+
}
|
|
181
|
+
} catch {}
|
|
182
|
+
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function findKeyFiles(cwd) {
|
|
187
|
+
const keyFiles = [];
|
|
188
|
+
const importantFiles = [
|
|
189
|
+
'package.json',
|
|
190
|
+
'tsconfig.json',
|
|
191
|
+
'README.md',
|
|
192
|
+
'CLAUDE.md',
|
|
193
|
+
'.env.example',
|
|
194
|
+
'src/index.ts',
|
|
195
|
+
'src/index.js',
|
|
196
|
+
'src/main.ts',
|
|
197
|
+
'src/main.js',
|
|
198
|
+
'src/app.ts',
|
|
199
|
+
'src/app.js',
|
|
200
|
+
'app/page.tsx',
|
|
201
|
+
'app/layout.tsx',
|
|
202
|
+
'pages/index.tsx',
|
|
203
|
+
'pages/_app.tsx',
|
|
204
|
+
'prisma/schema.prisma',
|
|
205
|
+
'drizzle.config.ts',
|
|
206
|
+
'Dockerfile',
|
|
207
|
+
'docker-compose.yml'
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
for (const file of importantFiles) {
|
|
211
|
+
try {
|
|
212
|
+
await fs.access(path.join(cwd, file));
|
|
213
|
+
keyFiles.push(file);
|
|
214
|
+
} catch {}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return keyFiles;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function runClaudeCode(prompt, cwd) {
|
|
221
|
+
return new Promise((resolve) => {
|
|
222
|
+
const child = spawn('claude', ['-p', prompt, '--dangerously-skip-permissions'], {
|
|
223
|
+
cwd,
|
|
224
|
+
stdio: 'inherit'
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
child.on('close', resolve);
|
|
228
|
+
child.on('error', () => resolve());
|
|
229
|
+
});
|
|
230
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// VIBECODE CLI - Docs Command
|
|
3
|
+
// Phase K3: AI Documentation Generation
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
import { spawn } from 'child_process';
|
|
7
|
+
import fs from 'fs/promises';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import inquirer from 'inquirer';
|
|
11
|
+
|
|
12
|
+
export async function docsCommand(options = {}) {
|
|
13
|
+
const cwd = process.cwd();
|
|
14
|
+
|
|
15
|
+
if (options.generate || options.type) {
|
|
16
|
+
return generateDocs(cwd, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Interactive menu
|
|
20
|
+
const { action } = await inquirer.prompt([{
|
|
21
|
+
type: 'list',
|
|
22
|
+
name: 'action',
|
|
23
|
+
message: 'Documentation options:',
|
|
24
|
+
choices: [
|
|
25
|
+
{ name: '📝 Generate README.md', value: 'readme' },
|
|
26
|
+
{ name: '📚 Generate API docs', value: 'api' },
|
|
27
|
+
{ name: '🏗️ Generate Architecture docs', value: 'architecture' },
|
|
28
|
+
{ name: '💬 Add JSDoc comments', value: 'jsdoc' },
|
|
29
|
+
{ name: '📦 Generate all docs', value: 'all' },
|
|
30
|
+
{ name: '👋 Exit', value: 'exit' }
|
|
31
|
+
]
|
|
32
|
+
}]);
|
|
33
|
+
|
|
34
|
+
if (action === 'exit') return;
|
|
35
|
+
|
|
36
|
+
return generateDocs(cwd, { ...options, type: action });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function generateDocs(cwd, options) {
|
|
40
|
+
const docType = options.type || 'all';
|
|
41
|
+
|
|
42
|
+
console.log(chalk.cyan(`
|
|
43
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
44
|
+
│ 📚 DOCUMENTATION GENERATION │
|
|
45
|
+
│ │
|
|
46
|
+
│ Type: ${docType.padEnd(56)}│
|
|
47
|
+
│ │
|
|
48
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
49
|
+
`));
|
|
50
|
+
|
|
51
|
+
const prompts = {
|
|
52
|
+
readme: `
|
|
53
|
+
# Generate README.md
|
|
54
|
+
|
|
55
|
+
Analyze this project and generate a comprehensive README.md:
|
|
56
|
+
|
|
57
|
+
1. **Project Title & Description**: What does this project do?
|
|
58
|
+
2. **Features**: Key features list with brief descriptions
|
|
59
|
+
3. **Installation**: Step-by-step installation guide
|
|
60
|
+
4. **Usage**: Basic usage examples with code snippets
|
|
61
|
+
5. **API Reference**: Main functions/endpoints (brief overview)
|
|
62
|
+
6. **Configuration**: Environment variables, config files
|
|
63
|
+
7. **Contributing**: How to contribute
|
|
64
|
+
8. **License**: MIT or detected license
|
|
65
|
+
|
|
66
|
+
Make it professional, clear, and helpful. Include badges if appropriate.
|
|
67
|
+
`,
|
|
68
|
+
api: `
|
|
69
|
+
# Generate API Documentation
|
|
70
|
+
|
|
71
|
+
Analyze the codebase and generate API documentation:
|
|
72
|
+
|
|
73
|
+
1. For each public function/method:
|
|
74
|
+
- Name, description
|
|
75
|
+
- Parameters with types
|
|
76
|
+
- Return value
|
|
77
|
+
- Example usage
|
|
78
|
+
- Throws/errors
|
|
79
|
+
|
|
80
|
+
2. For REST endpoints (if any):
|
|
81
|
+
- Method, path
|
|
82
|
+
- Request body
|
|
83
|
+
- Response format
|
|
84
|
+
- Status codes
|
|
85
|
+
- Example requests/responses
|
|
86
|
+
|
|
87
|
+
3. For React components (if any):
|
|
88
|
+
- Props with types
|
|
89
|
+
- Usage examples
|
|
90
|
+
|
|
91
|
+
Output in Markdown format suitable for docs site.
|
|
92
|
+
Create docs/API.md
|
|
93
|
+
`,
|
|
94
|
+
architecture: `
|
|
95
|
+
# Generate Architecture Documentation
|
|
96
|
+
|
|
97
|
+
Analyze and document the architecture:
|
|
98
|
+
|
|
99
|
+
1. **System Overview**: High-level description
|
|
100
|
+
2. **Directory Structure**: Explain each folder's purpose
|
|
101
|
+
3. **Core Components**: Main modules and their responsibilities
|
|
102
|
+
4. **Data Flow**: How data moves through the system
|
|
103
|
+
5. **Dependencies**: Key dependencies and why they're used
|
|
104
|
+
6. **Diagrams**: Generate Mermaid diagrams for:
|
|
105
|
+
- Component diagram
|
|
106
|
+
- Sequence diagram for main flows
|
|
107
|
+
- Data model (if applicable)
|
|
108
|
+
|
|
109
|
+
Output in Markdown with Mermaid blocks.
|
|
110
|
+
Create docs/ARCHITECTURE.md
|
|
111
|
+
`,
|
|
112
|
+
jsdoc: `
|
|
113
|
+
# Add JSDoc Comments
|
|
114
|
+
|
|
115
|
+
For each function, class, and method in the codebase:
|
|
116
|
+
|
|
117
|
+
1. Add JSDoc comments with:
|
|
118
|
+
- @description - What it does
|
|
119
|
+
- @param for each parameter with type and description
|
|
120
|
+
- @returns - Return value with type
|
|
121
|
+
- @throws (if applicable)
|
|
122
|
+
- @example - Usage example
|
|
123
|
+
|
|
124
|
+
2. Add type annotations where missing
|
|
125
|
+
3. Don't modify function logic, only add comments
|
|
126
|
+
4. Use TypeScript types in JSDoc if .ts files
|
|
127
|
+
|
|
128
|
+
Apply to all .js/.ts files in src/
|
|
129
|
+
`,
|
|
130
|
+
all: `
|
|
131
|
+
# Generate Complete Documentation
|
|
132
|
+
|
|
133
|
+
Create comprehensive documentation:
|
|
134
|
+
|
|
135
|
+
1. **README.md** - Project overview, installation, usage
|
|
136
|
+
2. **docs/API.md** - API reference
|
|
137
|
+
3. **docs/ARCHITECTURE.md** - System architecture with diagrams
|
|
138
|
+
4. Add JSDoc comments to key source files
|
|
139
|
+
|
|
140
|
+
Make documentation professional and thorough.
|
|
141
|
+
`
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const prompt = prompts[docType] || prompts.all;
|
|
145
|
+
|
|
146
|
+
const promptFile = path.join(cwd, '.vibecode', 'docs-prompt.md');
|
|
147
|
+
await fs.mkdir(path.dirname(promptFile), { recursive: true });
|
|
148
|
+
await fs.writeFile(promptFile, prompt);
|
|
149
|
+
|
|
150
|
+
console.log(chalk.gray(' Generating documentation with Claude Code...\n'));
|
|
151
|
+
|
|
152
|
+
await runClaudeCode(prompt, cwd);
|
|
153
|
+
|
|
154
|
+
console.log(chalk.green('\n✅ Documentation generated!\n'));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function runClaudeCode(prompt, cwd) {
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
const child = spawn('claude', ['-p', prompt, '--dangerously-skip-permissions'], {
|
|
160
|
+
cwd,
|
|
161
|
+
stdio: 'inherit'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
child.on('close', resolve);
|
|
165
|
+
child.on('error', () => resolve());
|
|
166
|
+
});
|
|
167
|
+
}
|
package/src/commands/git.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Git Integration for Vibecode CLI
|
|
3
3
|
* Native git commands with enhanced UI and AI-powered commit messages
|
|
4
|
+
* Phase K7: AI Diff Review
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
|
-
import { exec } from 'child_process';
|
|
7
|
+
import { exec, spawn } from 'child_process';
|
|
7
8
|
import { promisify } from 'util';
|
|
9
|
+
import fs from 'fs/promises';
|
|
10
|
+
import path from 'path';
|
|
8
11
|
import chalk from 'chalk';
|
|
9
12
|
import inquirer from 'inquirer';
|
|
10
13
|
|
|
@@ -435,11 +438,16 @@ async function generateCommitMessage(files) {
|
|
|
435
438
|
* Show diff with syntax highlighting
|
|
436
439
|
*/
|
|
437
440
|
async function gitDiff(args, options) {
|
|
441
|
+
// K7: AI diff review
|
|
442
|
+
if (options.review || args.includes('--review')) {
|
|
443
|
+
return aiDiffReview();
|
|
444
|
+
}
|
|
445
|
+
|
|
438
446
|
try {
|
|
439
447
|
const file = args[0];
|
|
440
448
|
let cmd = 'git diff';
|
|
441
449
|
|
|
442
|
-
if (file) {
|
|
450
|
+
if (file && file !== '--review') {
|
|
443
451
|
cmd = `git diff -- "${file}"`;
|
|
444
452
|
} else if (options.staged) {
|
|
445
453
|
cmd = 'git diff --cached';
|
|
@@ -480,6 +488,99 @@ async function gitDiff(args, options) {
|
|
|
480
488
|
}
|
|
481
489
|
}
|
|
482
490
|
|
|
491
|
+
/**
|
|
492
|
+
* K7: AI Diff Review
|
|
493
|
+
*/
|
|
494
|
+
async function aiDiffReview() {
|
|
495
|
+
const cwd = process.cwd();
|
|
496
|
+
|
|
497
|
+
console.log(chalk.cyan(`
|
|
498
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
499
|
+
│ 🔍 AI DIFF REVIEW │
|
|
500
|
+
│ │
|
|
501
|
+
│ Reviewing staged changes... │
|
|
502
|
+
│ │
|
|
503
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
504
|
+
`));
|
|
505
|
+
|
|
506
|
+
// Get diff
|
|
507
|
+
let diff = '';
|
|
508
|
+
try {
|
|
509
|
+
const { stdout: stagedDiff } = await execAsync('git diff --staged', { cwd });
|
|
510
|
+
diff = stagedDiff;
|
|
511
|
+
} catch {}
|
|
512
|
+
|
|
513
|
+
if (!diff.trim()) {
|
|
514
|
+
// Try unstaged
|
|
515
|
+
try {
|
|
516
|
+
const { stdout: unstagedDiff } = await execAsync('git diff', { cwd });
|
|
517
|
+
diff = unstagedDiff;
|
|
518
|
+
} catch {}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (!diff.trim()) {
|
|
522
|
+
console.log(chalk.yellow('\n No changes to review.\n'));
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Truncate diff if too long
|
|
527
|
+
const maxDiffLength = 8000;
|
|
528
|
+
const truncatedDiff = diff.length > maxDiffLength
|
|
529
|
+
? diff.substring(0, maxDiffLength) + '\n... (truncated)'
|
|
530
|
+
: diff;
|
|
531
|
+
|
|
532
|
+
const prompt = `
|
|
533
|
+
# Git Diff Review
|
|
534
|
+
|
|
535
|
+
Review these code changes:
|
|
536
|
+
|
|
537
|
+
\`\`\`diff
|
|
538
|
+
${truncatedDiff}
|
|
539
|
+
\`\`\`
|
|
540
|
+
|
|
541
|
+
## Review Criteria:
|
|
542
|
+
1. **Correctness**: Are there any bugs or logic errors?
|
|
543
|
+
2. **Best Practices**: Does it follow conventions and patterns?
|
|
544
|
+
3. **Security**: Any security concerns introduced?
|
|
545
|
+
4. **Performance**: Any performance issues?
|
|
546
|
+
5. **Tests**: Should tests be added/updated?
|
|
547
|
+
6. **Edge Cases**: Any edge cases not handled?
|
|
548
|
+
|
|
549
|
+
## Output Format:
|
|
550
|
+
1. **Overall Assessment**: (Good / Concerns / Issues)
|
|
551
|
+
2. **Specific Feedback**: Per file/change feedback
|
|
552
|
+
3. **Suggested Improvements**: What could be better
|
|
553
|
+
4. **Recommended Commit Message**: A conventional commit message for these changes
|
|
554
|
+
|
|
555
|
+
Review the diff now.
|
|
556
|
+
`;
|
|
557
|
+
|
|
558
|
+
const promptFile = path.join(cwd, '.vibecode', 'diff-review-prompt.md');
|
|
559
|
+
await fs.mkdir(path.dirname(promptFile), { recursive: true });
|
|
560
|
+
await fs.writeFile(promptFile, prompt);
|
|
561
|
+
|
|
562
|
+
console.log(chalk.gray(' Reviewing with Claude Code...\n'));
|
|
563
|
+
|
|
564
|
+
await runClaudeCode(prompt, cwd);
|
|
565
|
+
|
|
566
|
+
console.log(chalk.green('\n✅ Diff review complete!\n'));
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Run Claude Code with prompt
|
|
571
|
+
*/
|
|
572
|
+
async function runClaudeCode(prompt, cwd) {
|
|
573
|
+
return new Promise((resolve) => {
|
|
574
|
+
const child = spawn('claude', ['-p', prompt, '--dangerously-skip-permissions'], {
|
|
575
|
+
cwd,
|
|
576
|
+
stdio: 'inherit'
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
child.on('close', resolve);
|
|
580
|
+
child.on('error', () => resolve());
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
483
584
|
/**
|
|
484
585
|
* Branch management
|
|
485
586
|
*/
|