22
33import sys
44from pathlib import Path
5- from typing import Optional , Dict
5+ from typing import Dict , Optional
66
77import click
88from rich .console import Console
99from rich .panel import Panel
1010from rich .progress import Progress , SpinnerColumn , TextColumn
11- from rich .syntax import Syntax
1211
1312from .core .detector import ErrorDetector
1413from .core .generator import PromptGenerator
1514from .utils .clipboard import copy_to_clipboard , paste_from_clipboard
1615
16+ # from rich.syntax import Syntax # Unused import
17+
18+
1719console = Console ()
1820
1921
2022@click .command ()
21- @click .argument ('error' , required = False )
22- @click .option ('-f' , '--file' , type = click .Path (exists = True ), help = 'Read error from file' )
23- @click .option ('-t' , '--type' , 'error_type' , help = 'Error type (auto-detect if not specified)' )
24- @click .option ('-c' , '--copy' , is_flag = True , help = 'Copy to clipboard' )
25- @click .option ('-o' , '--output' , type = click .Path (), help = 'Save to file' )
26- @click .option ('-i' , '--interactive' , is_flag = True , help = 'Interactive mode' )
27- @click .option ('--history' , is_flag = True , help = 'Show history' )
28- @click .option ('--list-templates' , is_flag = True , help = 'List available templates' )
29- @click .option ('--agent' , help = 'Override default agent selection' )
30- @click .option ('-v' , '--verbose' , is_flag = True , help = 'Verbose output' )
31- def main (error : Optional [str ], file : Optional [str ], error_type : Optional [str ],
32- copy : bool , output : Optional [str ], interactive : bool ,
33- history : bool , list_templates : bool , agent : Optional [str ],
34- verbose : bool ):
23+ @click .argument ("error" , required = False )
24+ @click .option ("-f" , "--file" , type = click .Path (exists = True ), help = "Read error from file" )
25+ @click .option (
26+ "-t" , "--type" , "error_type" , help = "Error type (auto-detect if not specified)"
27+ )
28+ @click .option ("-c" , "--copy" , is_flag = True , help = "Copy to clipboard" )
29+ @click .option ("-o" , "--output" , type = click .Path (), help = "Save to file" )
30+ @click .option ("-i" , "--interactive" , is_flag = True , help = "Interactive mode" )
31+ @click .option ("--history" , is_flag = True , help = "Show history" )
32+ @click .option ("--list-templates" , is_flag = True , help = "List available templates" )
33+ @click .option ("--agent" , help = "Override default agent selection" )
34+ @click .option ("-v" , "--verbose" , is_flag = True , help = "Verbose output" )
35+ def main (
36+ error : Optional [str ],
37+ file : Optional [str ],
38+ error_type : Optional [str ],
39+ copy : bool ,
40+ output : Optional [str ],
41+ interactive : bool ,
42+ history : bool ,
43+ list_templates : bool ,
44+ agent : Optional [str ],
45+ verbose : bool ,
46+ ):
3547 """
3648 ClaudeCode-Debugger: Smart debug prompt generator for Claude Code.
37-
49+
3850 Transform error messages into actionable debug prompts with AI-powered analysis.
39-
51+
4052 Examples:
41-
53+
4254 ccdebug "TypeError: Cannot read property"
43-
55+
4456 ccdebug -f error.log -c
45-
57+
4658 ccdebug --interactive
4759 """
48-
60+
4961 # Handle special commands
5062 if list_templates :
5163 _list_templates ()
5264 return
53-
65+
5466 if history :
5567 console .print ("[yellow]History feature coming soon![/yellow]" )
5668 return
57-
69+
5870 if interactive :
5971 _interactive_mode ()
6072 return
61-
73+
6274 # Get error content
6375 error_content = _get_error_content (error , file )
6476 if not error_content :
6577 console .print ("[red]Error: No error content provided.[/red]" )
6678 console .print ("Use --help for usage information." )
6779 sys .exit (1 )
68-
80+
6981 # Process error
7082 with Progress (
7183 SpinnerColumn (),
@@ -79,32 +91,29 @@ def main(error: Optional[str], file: Optional[str], error_type: Optional[str],
7991 detected_type = error_type or detector .detect (error_content )
8092 error_info = detector .extract_key_info (error_content , detected_type )
8193 severity = detector .get_severity (error_content , detected_type )
82-
94+
8395 # Generate prompt
8496 progress .update (task , description = "Generating debug prompt..." )
8597 generator = PromptGenerator ()
8698 prompt = generator .generate (
87- error_content ,
88- detected_type ,
89- error_info ,
90- custom_agent = agent
99+ error_content , detected_type , error_info , custom_agent = agent
91100 )
92-
101+
93102 progress .stop ()
94-
103+
95104 # Display results
96105 _display_results (prompt , detected_type , severity , error_info , verbose )
97-
106+
98107 # Handle output options
99108 if copy :
100109 if copy_to_clipboard (prompt ):
101110 console .print ("\n [bold green]✓[/bold green] Copied to clipboard!" )
102111 else :
103112 console .print ("\n [bold red]✗[/bold red] Failed to copy to clipboard." )
104-
113+
105114 if output :
106115 try :
107- Path (output ).write_text (prompt , encoding = ' utf-8' )
116+ Path (output ).write_text (prompt , encoding = " utf-8" )
108117 console .print (f"\n [bold green]✓[/bold green] Saved to { output } " )
109118 except Exception as e :
110119 console .print (f"\n [bold red]✗[/bold red] Failed to save: { e } " )
@@ -114,7 +123,7 @@ def _get_error_content(error: Optional[str], file: Optional[str]) -> str:
114123 """Get error content from various sources."""
115124 if file :
116125 try :
117- return Path (file ).read_text (encoding = ' utf-8' )
126+ return Path (file ).read_text (encoding = " utf-8" )
118127 except Exception as e :
119128 console .print (f"[red]Error reading file: { e } [/red]" )
120129 sys .exit (1 )
@@ -129,78 +138,81 @@ def _get_error_content(error: Optional[str], file: Optional[str]) -> str:
129138 return ""
130139
131140
132- def _display_results (prompt : str , error_type : str , severity : str ,
133- error_info : Dict , verbose : bool ):
141+ def _display_results (
142+ prompt : str , error_type : str , severity : str , error_info : Dict , verbose : bool
143+ ):
134144 """Display analysis results."""
135145 # Severity colors
136146 severity_colors = {
137- ' critical' : ' bold red' ,
138- ' high' : ' red' ,
139- ' medium' : ' yellow' ,
140- ' low' : ' green' ,
147+ " critical" : " bold red" ,
148+ " high" : " red" ,
149+ " medium" : " yellow" ,
150+ " low" : " green" ,
141151 }
142-
143- severity_color = severity_colors .get (severity , ' white' )
144-
152+
153+ severity_color = severity_colors .get (severity , " white" )
154+
145155 # Create title
146156 title = f"[{ severity_color } ]🚨 { error_type .title ()} Error - { severity .upper ()} Priority[/{ severity_color } ]"
147-
157+
148158 # Display prompt in panel
149- console .print (Panel (
150- prompt ,
151- title = title ,
152- border_style = severity_color .split ()[- 1 ],
153- padding = (1 , 2 ),
154- ))
155-
159+ console .print (
160+ Panel (
161+ prompt ,
162+ title = title ,
163+ border_style = severity_color .split ()[- 1 ],
164+ padding = (1 , 2 ),
165+ )
166+ )
167+
156168 # Show additional info in verbose mode
157169 if verbose :
158170 console .print ("\n [bold]Analysis Details:[/bold]" )
159171 console .print (f" Error Type: { error_type } " )
160172 console .print (f" Severity: { severity } " )
161-
162- if error_info .get (' files' ):
173+
174+ if error_info .get (" files" ):
163175 console .print (f" Files: { ', ' .join (error_info ['files' ])} " )
164-
165- if error_info .get (' error_codes' ):
176+
177+ if error_info .get (" error_codes" ):
166178 console .print (f" Error Codes: { ', ' .join (error_info ['error_codes' ])} " )
167-
168- if error_info .get (' line_numbers' ):
179+
180+ if error_info .get (" line_numbers" ):
169181 console .print (f" Lines: { ', ' .join (map (str , error_info ['line_numbers' ]))} " )
170182
171183
172184def _interactive_mode ():
173185 """Run in interactive mode."""
174186 console .print ("[bold cyan]ClaudeCode-Debugger Interactive Mode[/bold cyan]" )
175187 console .print ("Enter your error message (Ctrl+D to finish):\n " )
176-
188+
177189 try :
178190 lines = []
179191 while True :
180192 line = input ()
181193 lines .append (line )
182194 except EOFError :
183195 pass
184-
185- error_content = ' \n ' .join (lines )
186-
196+
197+ error_content = " \n " .join (lines )
198+
187199 if not error_content .strip ():
188200 console .print ("\n [red]No error content provided.[/red]" )
189201 return
190-
202+
191203 # Process the error
192204 console .print ("\n " + "─" * 50 + "\n " )
193-
205+
194206 detector = ErrorDetector ()
195207 error_type = detector .detect (error_content )
196208 error_info = detector .extract_key_info (error_content , error_type )
197209 severity = detector .get_severity (error_content , error_type )
198-
210+
199211 generator = PromptGenerator ()
200212 prompt = generator .generate (error_content , error_type , error_info )
201-
213+
202214 _display_results (prompt , error_type , severity , error_info , verbose = True )
203-
215+
204216 # Ask if user wants to copy
205217 if click .confirm ("\n Copy to clipboard?" , default = True ):
206218 if copy_to_clipboard (prompt ):
@@ -211,17 +223,17 @@ def _list_templates():
211223 """List available templates."""
212224 generator = PromptGenerator ()
213225 templates = generator .list_templates ()
214-
226+
215227 console .print ("[bold cyan]Available Templates:[/bold cyan]\n " )
216-
228+
217229 for template in sorted (templates ):
218- if template .startswith (' user_' ):
230+ if template .startswith (" user_" ):
219231 console .print (f" • { template [5 :]} [dim](user)[/dim]" )
220232 else :
221233 console .print (f" • { template } " )
222-
234+
223235 console .print (f"\n Total: { len (templates )} templates" )
224236
225237
226- if __name__ == ' __main__' :
227- main ()
238+ if __name__ == " __main__" :
239+ main ()
0 commit comments