-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdemo_cli_helpers_standalone.py
More file actions
372 lines (299 loc) · 12.2 KB
/
demo_cli_helpers_standalone.py
File metadata and controls
372 lines (299 loc) · 12.2 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/usr/bin/env python3
"""
Standalone demo for CLI helpers without full dependencies.
This demonstrates the CLI helper utilities in isolation.
"""
import json
import time
from datetime import datetime
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
from rich.progress import (
Progress,
SpinnerColumn,
TextColumn,
BarColumn,
TaskProgressColumn,
)
from rich.table import Table
from rich.text import Text
from rich.tree import Tree
console = Console()
def demo_output_formatting():
"""Demonstrate output formatting."""
console.print("\n" + "=" * 70, style="bold blue")
console.print("Output Formatting Demo", style="bold blue")
console.print("=" * 70 + "\n", style="bold blue")
# Success/Error/Warning/Info messages
console.print("✅ This is a success message", style="bold green")
console.print("❌ This is an error message", style="bold red")
console.print("⚠️ This is a warning message", style="bold yellow")
console.print("ℹ️ This is an info message", style="bold blue")
# Header
text = Text()
text.append("Task Planning", style="bold blue")
text.append("\nGoal: Add user authentication", style="dim")
console.print(Panel(text, border_style="blue"))
# Section
console.print("\n📊 Plan Summary", style="bold blue")
console.print("─" * 13, style="blue")
# Key-value pairs
data = {
"Description": "Add authentication system",
"Risk Level": "MEDIUM",
"Estimated Duration": "2 hours",
"Affected Files": "5",
"Total Steps": "12",
}
max_key_length = max(len(str(k)) for k in data.keys())
for key, value in data.items():
key_str = str(key).ljust(max_key_length)
console.print(f" {key_str} : {value}", style="white")
# Table
console.print("\n📋 Execution Steps", style="bold blue")
console.print("─" * 16, style="blue")
table = Table(title="12 Steps")
table.add_column("#", style="cyan", width=4)
table.add_column("Description", style="white", width=50)
table.add_column("Action", style="yellow", width=15)
table.add_column("Risk", style="red", width=8)
steps = [
("1", "Create user model with authentication fields", "CREATE_FILE", "LOW"),
("2", "Implement password hashing utilities", "CREATE_FILE", "MEDIUM"),
("3", "Add JWT token generation", "MODIFY_FILE", "MEDIUM"),
("4", "Create login endpoint", "CREATE_FILE", "LOW"),
("5", "Add authentication middleware", "CREATE_FILE", "HIGH"),
]
for step in steps:
table.add_row(*step)
console.print(table)
# List
console.print("\n📁 Affected Files", style="bold blue")
console.print("─" * 15, style="blue")
files = [
"src/models/user.py",
"src/auth/password.py",
"src/auth/jwt.py",
"src/api/auth.py",
"src/middleware/auth.py",
]
for file in files:
console.print(f" • {file}", style="cyan")
# Tree
console.print("\n📂 Project Structure", style="bold blue")
console.print("─" * 19, style="blue")
tree = Tree("src")
models = tree.add("📁 models")
models.add("📄 user.py")
models.add("📄 __init__.py")
auth = tree.add("📁 auth")
auth.add("📄 password.py")
auth.add("📄 jwt.py")
auth.add("📄 __init__.py")
api = tree.add("📁 api")
api.add("📄 auth.py")
api.add("📄 __init__.py")
console.print(tree)
def demo_progress_indicators():
"""Demonstrate progress indicators."""
console.print("\n" + "=" * 70, style="bold blue")
console.print("Progress Indicators Demo", style="bold blue")
console.print("=" * 70 + "\n", style="bold blue")
# Spinner
console.print("Spinner Progress:", style="bold")
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
console=console,
) as progress:
task = progress.add_task("Analyzing project context...", total=None)
time.sleep(1)
progress.update(task, description="Creating execution plan...")
time.sleep(1)
progress.update(task, description="Plan created!")
time.sleep(0.5)
# Progress bar
console.print("\nProgress Bar:", style="bold")
with Progress(
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
console=console,
) as progress:
task = progress.add_task("Executing steps...", total=100)
for i in range(100):
time.sleep(0.02)
progress.update(task, advance=1)
console.print("\n✅ Progress complete!", style="bold green")
def demo_command_history():
"""Demonstrate command history."""
console.print("\n" + "=" * 70, style="bold blue")
console.print("Command History Demo", style="bold blue")
console.print("=" * 70 + "\n", style="bold blue")
# Simulate command history
history = [
{
"command": "plan",
"args": {"goal": "Add user authentication"},
"timestamp": "2024-01-15T10:30:00",
"success": True,
"error": None,
},
{
"command": "scaffold",
"args": {"type": "python-fastapi", "name": "my-api"},
"timestamp": "2024-01-15T10:35:00",
"success": True,
"error": None,
},
{
"command": "refactor",
"args": {"target": "main.py", "operation": "rename"},
"timestamp": "2024-01-15T10:40:00",
"success": False,
"error": "File not found",
},
{
"command": "plan",
"args": {"goal": "Add database migrations"},
"timestamp": "2024-01-15T10:45:00",
"success": True,
"error": None,
},
]
# Recent commands
console.print("📜 Recent Commands", style="bold blue")
console.print("─" * 16, style="blue")
table = Table(title="Last 4 commands")
table.add_column("Timestamp", style="dim", width=20)
table.add_column("Command", style="cyan", width=15)
table.add_column("Status", style="green", width=10)
for entry in history:
status = "✅" if entry['success'] else "❌"
table.add_row(entry['timestamp'], entry['command'], status)
console.print(table)
# Statistics
console.print("\n📊 Command Statistics", style="bold blue")
console.print("─" * 20, style="blue")
total = len(history)
successful = sum(1 for e in history if e['success'])
success_rate = successful / total if total > 0 else 0.0
stats_data = {
"Total Commands": str(total),
"Success Rate": f"{success_rate:.1%}",
}
max_key_length = max(len(str(k)) for k in stats_data.keys())
for key, value in stats_data.items():
key_str = str(key).ljust(max_key_length)
console.print(f" {key_str} : {value}", style="white")
# Most used commands
console.print("\n🔝 Most Used Commands", style="bold blue")
console.print("─" * 20, style="blue")
command_counts = {}
for entry in history:
cmd = entry['command']
command_counts[cmd] = command_counts.get(cmd, 0) + 1
most_used = sorted(command_counts.items(), key=lambda x: x[1], reverse=True)
table = Table(title="Top Commands")
table.add_column("Command", style="cyan")
table.add_column("Count", style="green")
for cmd, count in most_used:
table.add_row(cmd, str(count))
console.print(table)
def demo_cli_commands():
"""Demonstrate new CLI commands."""
console.print("\n" + "=" * 70, style="bold blue")
console.print("New CLI Commands Demo", style="bold blue")
console.print("=" * 70 + "\n", style="bold blue")
# Header
text = Text()
text.append("Available Commands", style="bold blue")
text.append("\nNew commands added in Task 13", style="dim")
console.print(Panel(text, border_style="blue"))
# Commands
console.print("\n📝 Command Reference", style="bold blue")
console.print("─" * 18, style="blue")
commands = [
("codegenie plan", "Create a detailed execution plan for a task"),
("codegenie scaffold", "Scaffold a new project with proper structure"),
("codegenie refactor", "Refactor code across multiple files"),
("codegenie history", "Show command history and statistics"),
("codegenie interactive", "Start interactive mode with guided prompts"),
]
for cmd, description in commands:
console.print(f"\n[bold cyan]{cmd}[/bold cyan]")
console.print(f" {description}", style="dim")
# Examples
console.print("\n\n💡 Example Usage", style="bold blue")
console.print("─" * 15, style="blue")
examples = [
("Plan a task", "codegenie plan 'Add user authentication'"),
("Scaffold project", "codegenie scaffold python-fastapi my-api"),
("Refactor code", "codegenie refactor main.py rename --name new_main.py"),
("View history", "codegenie history --count 10"),
("Interactive mode", "codegenie interactive"),
]
for title, command in examples:
console.print(f"\n[bold]{title}:[/bold]")
console.print(f" $ {command}", style="green")
# Options
console.print("\n\n⚙️ Command Options", style="bold blue")
console.print("─" * 17, style="blue")
table = Table(title="Common Options")
table.add_column("Option", style="cyan", width=20)
table.add_column("Description", style="white", width=40)
options = [
("--path, -p", "Specify project path"),
("--save", "Save plan to file"),
("--execute, -e", "Execute plan after creation"),
("--preview", "Preview changes before applying"),
("--debug", "Enable debug mode"),
]
for option, desc in options:
table.add_row(option, desc)
console.print(table)
def main():
"""Run all demos."""
console.print("\n" + "=" * 70, style="bold magenta")
console.print("🧞 CodeGenie CLI Integration Demo (Task 13)", style="bold magenta")
console.print("=" * 70 + "\n", style="bold magenta")
try:
# Run demos
demo_output_formatting()
demo_progress_indicators()
demo_command_history()
demo_cli_commands()
# Summary
console.print("\n" + "=" * 70, style="bold green")
console.print("Demo Summary", style="bold green")
console.print("=" * 70 + "\n", style="bold green")
console.print("ℹ️ Task 13 Implementation Complete!", style="bold blue")
console.print("\n✅ Completed Features", style="bold green")
console.print("─" * 20, style="green")
features = [
"✅ Task 13.1: CLI commands (plan, scaffold, refactor)",
"✅ Task 13.2: Enhanced CLI UX",
" • Interactive prompts with validation",
" • Progress indicators (spinner, bar, multi-task)",
" • Colored and formatted output",
" • Command history management",
]
for feature in features:
console.print(f" {feature}", style="green")
console.print("\n\n🚀 Try It Out", style="bold blue")
console.print("─" * 11, style="blue")
console.print("\nRun these commands to test the new features:", style="bold")
console.print(" $ codegenie plan 'Create a REST API'", style="cyan")
console.print(" $ codegenie scaffold python-fastapi my-api", style="cyan")
console.print(" $ codegenie history --stats", style="cyan")
console.print(" $ codegenie interactive", style="cyan")
console.print("\n\n🎉 All demos completed successfully!", style="bold green")
except KeyboardInterrupt:
console.print("\n\n⚠️ Demo interrupted by user", style="yellow")
except Exception as e:
console.print(f"\n\n❌ Error: {e}", style="red")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()