forked from BeOnAuto/auto-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.ts
More file actions
189 lines (168 loc) · 6.44 KB
/
demo.ts
File metadata and controls
189 lines (168 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { Command } from 'commander';
import inquirer from 'inquirer';
import ora from 'ora';
import chalk from 'chalk';
import { Config } from '../utils/config.js';
import { createOutput } from '../utils/terminal.js';
import { handleError } from '../utils/errors.js';
import { Analytics } from '../utils/analytics.js';
import markedTerminal from 'marked-terminal';
import { marked } from 'marked';
// Color constants
const COLORS = {
SPECS_TEXT: chalk.hex('#A0A0A0'),
SPECS_LABEL: chalk.italic,
EVENTS: chalk.hex('#FFA500'),
COMMANDS: chalk.hex('#7FDBFF'),
STATE: chalk.green,
FLOW_TEXT: chalk.bold.blue,
STREAM_BRACKETS: chalk.yellow,
INTEGRATIONS_BRACKETS: chalk.magenta,
SOURCE_BRACKETS: chalk.gray,
SLICE_TEXT: chalk.white.bold,
CLIENT_SERVER: chalk.hex('#4ECDC4'),
};
// Configure marked to use marked-terminal with custom styles
marked.setOptions({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
renderer: new (markedTerminal as any)({
heading: chalk.hex('#00BFFF').bold, // h1
firstHeading: chalk.hex('#00BFFF').bold, // h1
strong: chalk.bold,
em: chalk.italic,
listitem: chalk.hex('#90EE90'), // bullets
codespan: chalk.yellow,
}),
});
export const createDemoCommand = (config: Config, analytics: Analytics) => {
const output = createOutput(config);
return new Command('demo').description('Start demo mode to build something').action(async () => {
try {
output.debug('Demo command initiated');
while (true) {
const { buildPrompt } = await inquirer.prompt<{ buildPrompt: string }>([
{
type: 'input',
name: 'buildPrompt',
message: 'What would you like to build?',
validate: (input: string) => {
if (input.trim().length === 0) {
return "Please enter something you'd like to build";
}
if (input.trim().length < 3) {
return 'Please provide a more detailed description (at least 3 characters)';
}
return true;
},
transformer: (input: string) => input.trim(),
},
]);
output.debug(`User wants to build: ${buildPrompt}`);
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
const spinnerColors = [
COLORS.EVENTS,
COLORS.COMMANDS,
COLORS.STATE,
COLORS.CLIENT_SERVER,
COLORS.STREAM_BRACKETS,
COLORS.INTEGRATIONS_BRACKETS,
];
const coloredFrames = spinnerFrames.map((frame, i) => {
const color = spinnerColors[i % spinnerColors.length];
return color(frame);
});
const spinner = ora({
text: chalk.gray('Thinking...'),
spinner: {
interval: 80,
frames: coloredFrames,
},
}).start();
// Simulate thinking time
await new Promise((resolve) => setTimeout(resolve, 100));
spinner.stop();
console.log();
const buildSummaryLines = [
'# **Flow: Guest books a listing** [source: <root>/src/flows/guest-booking-flow.ts]',
'* **Slice:** Search for available listings [stream: listing]',
' * **Client:** Listing Search Screen',
' should have location filter',
' should have price range slider',
' should have guest count filter',
' * **Server:** Search listings by location and price',
' Events.ListingCreated => State.AvailableListings',
'',
'* **Slice:** Book listing [stream: booking]',
' * **Client:** Booking Form',
' should have check-in & checkout date picker',
' should have guest count selector',
' * **Server:** Process booking request',
' Commands.BookListing => Events.BookingConfirmed',
'',
'* **Slice:** Host is notified',
' * **Server:** Host is notified when booking request is received',
' Events.BookingConfirmed => Commands.NotifyHost',
'',
'* **Slice:** Notify host [integrations: MailChimp, Twilio]',
' * **Server:** Send notification using the specified integrations',
' Commands.NotifyHost => Events.HostNotified',
'',
'⏱️ Time: ~2-3 min | 💰 Cost: ~$2',
];
console.log(buildSummaryLines.join('\\n'));
console.log(); // Add blank line
const { confirm } = await inquirer.prompt<{ confirm: boolean }>([
{
type: 'confirm',
name: 'confirm',
message: 'Do you want to proceed?',
},
]);
if (!confirm) {
console.log(chalk.yellow('Going back to build prompt...'));
continue;
}
// Second thinking phase
const spinner2 = ora({
text: chalk.gray('Building...'),
spinner: {
interval: 80,
frames: coloredFrames,
},
}).start();
await new Promise((resolve) => setTimeout(resolve, 2000));
spinner2.stop();
// Show deployment success message
console.log(chalk.green('✅ Your app has been deployed!'));
console.log(chalk.cyan('🌐 Access it at: http://localhost:3000'));
const { action } = await inquirer.prompt<{ action: string }>([
{
type: 'list',
name: 'action',
message: 'What would you like to do?',
choices: ['Accept', 'Reject', 'Retry'],
},
]);
if (action === 'Accept') {
console.log(chalk.green('Build accepted!'));
// Continue the loop to ask for help again
} else if (action === 'Reject') {
console.log(chalk.red('Build rejected.'));
// Continue the loop to ask for help again
} else if (action === 'Retry') {
console.log(chalk.blue('Retrying...'));
// Continue the loop to ask for help again
}
}
await analytics.trackCommand('demo', true);
output.debug('Demo command completed successfully');
} catch (error: unknown) {
await analytics.trackCommand('demo', false, error instanceof Error ? error.message : 'unknown');
if (error instanceof Error) {
handleError(error);
} else {
handleError(new Error(String(error)));
}
}
});
};