@nclamvn/vibecode-cli 2.0.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.
- package/.vibecode/learning/fixes.json +1 -0
- package/.vibecode/learning/preferences.json +1 -0
- package/README.md +310 -49
- package/SESSION_NOTES.md +154 -0
- package/bin/vibecode.js +212 -2
- package/package.json +5 -2
- package/src/agent/decomposition.js +476 -0
- package/src/agent/index.js +391 -0
- package/src/agent/memory.js +542 -0
- package/src/agent/orchestrator.js +917 -0
- package/src/agent/self-healing.js +516 -0
- package/src/commands/agent.js +349 -0
- package/src/commands/ask.js +230 -0
- package/src/commands/assist.js +413 -0
- package/src/commands/build.js +345 -4
- package/src/commands/debug.js +565 -0
- package/src/commands/docs.js +167 -0
- package/src/commands/git.js +1024 -0
- package/src/commands/go.js +387 -0
- package/src/commands/learn.js +294 -0
- package/src/commands/migrate.js +341 -0
- package/src/commands/plan.js +8 -2
- package/src/commands/refactor.js +205 -0
- package/src/commands/review.js +126 -1
- package/src/commands/security.js +229 -0
- package/src/commands/shell.js +486 -0
- package/src/commands/test.js +194 -0
- package/src/commands/undo.js +281 -0
- package/src/commands/watch.js +556 -0
- package/src/commands/wizard.js +322 -0
- package/src/config/constants.js +5 -1
- package/src/config/templates.js +146 -15
- package/src/core/backup.js +325 -0
- package/src/core/error-analyzer.js +237 -0
- package/src/core/fix-generator.js +195 -0
- package/src/core/iteration.js +226 -0
- package/src/core/learning.js +295 -0
- package/src/core/session.js +18 -2
- package/src/core/test-runner.js +281 -0
- package/src/debug/analyzer.js +329 -0
- package/src/debug/evidence.js +228 -0
- package/src/debug/fixer.js +348 -0
- package/src/debug/image-analyzer.js +304 -0
- package/src/debug/index.js +378 -0
- package/src/debug/verifier.js +346 -0
- package/src/index.js +89 -0
- package/src/providers/claude-code.js +12 -7
- package/src/ui/__tests__/error-translator.test.js +390 -0
- package/src/ui/dashboard.js +364 -0
- package/src/ui/error-translator.js +775 -0
- package/src/utils/image.js +222 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// VIBECODE CLI - Undo Command
|
|
3
|
+
// Phase H4: Revert last action with backup restore
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { BackupManager } from '../core/backup.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Undo Command - Revert to previous state
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* vibecode undo - Interactive restore menu
|
|
15
|
+
* vibecode undo --list - List available backups
|
|
16
|
+
* vibecode undo --step 2 - Restore to 2 steps ago
|
|
17
|
+
* vibecode undo --clear - Clear all backups
|
|
18
|
+
*/
|
|
19
|
+
export async function undoCommand(options = {}) {
|
|
20
|
+
const backup = new BackupManager();
|
|
21
|
+
|
|
22
|
+
// Clear all backups
|
|
23
|
+
if (options.clear) {
|
|
24
|
+
await clearBackups(backup, options);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// List backups
|
|
29
|
+
if (options.list) {
|
|
30
|
+
await listBackups(backup);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Restore specific step
|
|
35
|
+
if (options.step) {
|
|
36
|
+
await restoreStep(backup, parseInt(options.step), options.force);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Interactive undo
|
|
41
|
+
await interactiveUndo(backup);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* List all available backups
|
|
46
|
+
*/
|
|
47
|
+
async function listBackups(backup) {
|
|
48
|
+
const backups = await backup.listBackups();
|
|
49
|
+
|
|
50
|
+
if (backups.length === 0) {
|
|
51
|
+
console.log(chalk.yellow('\n📭 Chưa có backup nào.\n'));
|
|
52
|
+
console.log(chalk.gray('Backup sẽ được tạo tự động khi chạy:'));
|
|
53
|
+
console.log(chalk.gray(' • vibecode build --auto'));
|
|
54
|
+
console.log(chalk.gray(' • vibecode agent'));
|
|
55
|
+
console.log(chalk.gray(' • vibecode go'));
|
|
56
|
+
console.log();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(chalk.cyan(`
|
|
61
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
62
|
+
│ 📦 BACKUP HISTORY │
|
|
63
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
64
|
+
`));
|
|
65
|
+
|
|
66
|
+
backups.forEach((b, index) => {
|
|
67
|
+
const date = new Date(b.timestamp);
|
|
68
|
+
const timeAgo = getTimeAgo(date);
|
|
69
|
+
const filesCount = b.files?.length || 0;
|
|
70
|
+
|
|
71
|
+
console.log(chalk.white(` ${(index + 1).toString().padStart(2)}. ${chalk.bold(b.action)}`));
|
|
72
|
+
console.log(chalk.gray(` ${timeAgo} · ${filesCount} files`));
|
|
73
|
+
console.log('');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(chalk.gray(` Chạy ${chalk.cyan('vibecode undo')} để restore`));
|
|
77
|
+
console.log(chalk.gray(` Hoặc ${chalk.cyan('vibecode undo --step N')} để restore step cụ thể\n`));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Restore to specific step
|
|
82
|
+
*/
|
|
83
|
+
async function restoreStep(backup, step, force = false) {
|
|
84
|
+
const backups = await backup.listBackups();
|
|
85
|
+
|
|
86
|
+
if (backups.length === 0) {
|
|
87
|
+
console.log(chalk.yellow('\n📭 Chưa có backup nào để restore.\n'));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (step < 1 || step > backups.length) {
|
|
92
|
+
console.log(chalk.red(`\n❌ Step ${step} không tồn tại.`));
|
|
93
|
+
console.log(chalk.gray(` Có ${backups.length} backups (1-${backups.length}).\n`));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const targetBackup = backups[step - 1];
|
|
98
|
+
|
|
99
|
+
console.log(chalk.yellow(`\n⚠️ Sắp restore về: ${chalk.bold(targetBackup.action)}`));
|
|
100
|
+
console.log(chalk.gray(` Thời gian: ${new Date(targetBackup.timestamp).toLocaleString('vi-VN')}`));
|
|
101
|
+
console.log(chalk.gray(` Files: ${targetBackup.files?.length || 0}\n`));
|
|
102
|
+
|
|
103
|
+
if (!force) {
|
|
104
|
+
const { confirm } = await inquirer.prompt([
|
|
105
|
+
{
|
|
106
|
+
type: 'confirm',
|
|
107
|
+
name: 'confirm',
|
|
108
|
+
message: 'Xác nhận restore?',
|
|
109
|
+
default: false
|
|
110
|
+
}
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
if (!confirm) {
|
|
114
|
+
console.log(chalk.gray('\n👋 Đã huỷ.\n'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const result = await backup.restore(targetBackup.id);
|
|
120
|
+
showRestoreResult(result);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Interactive undo menu
|
|
125
|
+
*/
|
|
126
|
+
async function interactiveUndo(backup) {
|
|
127
|
+
const backups = await backup.listBackups();
|
|
128
|
+
|
|
129
|
+
if (backups.length === 0) {
|
|
130
|
+
console.log(chalk.yellow('\n📭 Chưa có backup nào để undo.\n'));
|
|
131
|
+
console.log(chalk.gray('Backup sẽ được tạo tự động khi chạy các lệnh build.'));
|
|
132
|
+
console.log();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log(chalk.cyan(`
|
|
137
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
138
|
+
│ ⏪ VIBECODE UNDO │
|
|
139
|
+
│ │
|
|
140
|
+
│ Chọn backup để restore files về trạng thái trước đó. │
|
|
141
|
+
│ │
|
|
142
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
143
|
+
`));
|
|
144
|
+
|
|
145
|
+
const choices = backups.map((b, index) => {
|
|
146
|
+
const timeAgo = getTimeAgo(new Date(b.timestamp));
|
|
147
|
+
const filesCount = b.files?.length || 0;
|
|
148
|
+
return {
|
|
149
|
+
name: `${b.action} (${timeAgo}, ${filesCount} files)`,
|
|
150
|
+
value: b.id,
|
|
151
|
+
short: b.action
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
choices.push(new inquirer.Separator());
|
|
156
|
+
choices.push({ name: '❌ Huỷ', value: 'cancel' });
|
|
157
|
+
|
|
158
|
+
const { backupId } = await inquirer.prompt([
|
|
159
|
+
{
|
|
160
|
+
type: 'list',
|
|
161
|
+
name: 'backupId',
|
|
162
|
+
message: 'Chọn backup để restore:',
|
|
163
|
+
choices,
|
|
164
|
+
pageSize: 10
|
|
165
|
+
}
|
|
166
|
+
]);
|
|
167
|
+
|
|
168
|
+
if (backupId === 'cancel') {
|
|
169
|
+
console.log(chalk.gray('\n👋 Đã huỷ.\n'));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const targetBackup = backups.find(b => b.id === backupId);
|
|
174
|
+
|
|
175
|
+
// Show files that will be restored
|
|
176
|
+
if (targetBackup.files && targetBackup.files.length > 0) {
|
|
177
|
+
console.log(chalk.gray('\n Files sẽ được restore:'));
|
|
178
|
+
const displayFiles = targetBackup.files.slice(0, 5);
|
|
179
|
+
for (const f of displayFiles) {
|
|
180
|
+
console.log(chalk.gray(` • ${f.path}`));
|
|
181
|
+
}
|
|
182
|
+
if (targetBackup.files.length > 5) {
|
|
183
|
+
console.log(chalk.gray(` ... và ${targetBackup.files.length - 5} files khác`));
|
|
184
|
+
}
|
|
185
|
+
console.log();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const { confirm } = await inquirer.prompt([
|
|
189
|
+
{
|
|
190
|
+
type: 'confirm',
|
|
191
|
+
name: 'confirm',
|
|
192
|
+
message: `Restore về "${targetBackup.action}"?`,
|
|
193
|
+
default: false
|
|
194
|
+
}
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
if (!confirm) {
|
|
198
|
+
console.log(chalk.gray('\n👋 Đã huỷ.\n'));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const result = await backup.restore(backupId);
|
|
203
|
+
showRestoreResult(result);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Clear all backups
|
|
208
|
+
*/
|
|
209
|
+
async function clearBackups(backup, options) {
|
|
210
|
+
const backups = await backup.listBackups();
|
|
211
|
+
|
|
212
|
+
if (backups.length === 0) {
|
|
213
|
+
console.log(chalk.yellow('\n📭 Không có backup nào để xoá.\n'));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (!options.force) {
|
|
218
|
+
console.log(chalk.yellow(`\n⚠️ Sắp xoá ${backups.length} backups.\n`));
|
|
219
|
+
|
|
220
|
+
const { confirm } = await inquirer.prompt([
|
|
221
|
+
{
|
|
222
|
+
type: 'confirm',
|
|
223
|
+
name: 'confirm',
|
|
224
|
+
message: 'Xác nhận xoá tất cả backups?',
|
|
225
|
+
default: false
|
|
226
|
+
}
|
|
227
|
+
]);
|
|
228
|
+
|
|
229
|
+
if (!confirm) {
|
|
230
|
+
console.log(chalk.gray('\n👋 Đã huỷ.\n'));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
await backup.clearAllBackups();
|
|
236
|
+
console.log(chalk.green(`\n✅ Đã xoá ${backups.length} backups.\n`));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Show restore result
|
|
241
|
+
*/
|
|
242
|
+
function showRestoreResult(result) {
|
|
243
|
+
if (result.success) {
|
|
244
|
+
console.log(chalk.green(`
|
|
245
|
+
╭────────────────────────────────────────────────────────────────────╮
|
|
246
|
+
│ ✅ RESTORE THÀNH CÔNG │
|
|
247
|
+
│ │
|
|
248
|
+
│ Action: ${result.action.substring(0, 54).padEnd(54)}│
|
|
249
|
+
│ Files restored: ${String(result.filesRestored).padEnd(46)}│
|
|
250
|
+
│ │
|
|
251
|
+
╰────────────────────────────────────────────────────────────────────╯
|
|
252
|
+
`));
|
|
253
|
+
|
|
254
|
+
// Show some restored files
|
|
255
|
+
if (result.files && result.files.length > 0) {
|
|
256
|
+
console.log(chalk.gray(' Files đã restore:'));
|
|
257
|
+
for (const f of result.files.slice(0, 5)) {
|
|
258
|
+
console.log(chalk.gray(` ✓ ${f}`));
|
|
259
|
+
}
|
|
260
|
+
if (result.files.length > 5) {
|
|
261
|
+
console.log(chalk.gray(` ... và ${result.files.length - 5} files khác`));
|
|
262
|
+
}
|
|
263
|
+
console.log();
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
console.log(chalk.red(`\n❌ Restore thất bại: ${result.error}\n`));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Get human-readable time ago string
|
|
272
|
+
*/
|
|
273
|
+
function getTimeAgo(date) {
|
|
274
|
+
const seconds = Math.floor((new Date() - date) / 1000);
|
|
275
|
+
|
|
276
|
+
if (seconds < 60) return 'vừa xong';
|
|
277
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)} phút trước`;
|
|
278
|
+
if (seconds < 86400) return `${Math.floor(seconds / 3600)} giờ trước`;
|
|
279
|
+
if (seconds < 604800) return `${Math.floor(seconds / 86400)} ngày trước`;
|
|
280
|
+
return `${Math.floor(seconds / 604800)} tuần trước`;
|
|
281
|
+
}
|