2929from .push import push_command
3030from .remove import remove_command
3131from .utils import CaptureLogger
32- from .eval import eval_command
3332
3433# Create the main Typer app
3534app = typer .Typer (
@@ -132,7 +131,7 @@ def analyze(
132131def debug (
133132 params : list [str ] = typer .Argument ( # type: ignore[arg-type] # noqa: B008
134133 None ,
135- help = "Docker image followed by optional Docker run arguments (e.g., 'hud-image:latest -e KEY=value') " , # noqa: E501
134+ help = "Docker image, environment directory, or config file followed by optional Docker arguments " , # noqa: E501
136135 ),
137136 config : Path = typer .Option ( # noqa: B008
138137 None ,
@@ -148,6 +147,12 @@ def debug(
148147 "--cursor" ,
149148 help = "Debug a server from Cursor config" ,
150149 ),
150+ build : bool = typer .Option (
151+ False ,
152+ "--build" ,
153+ "-b" ,
154+ help = "Build image before debugging (for directory mode)" ,
155+ ),
151156 max_phase : int = typer .Option (
152157 5 ,
153158 "--max-phase" ,
@@ -160,15 +165,24 @@ def debug(
160165 """🐛 Debug MCP environment - test initialization, tools, and readiness.
161166
162167 Examples:
163- hud debug hud-text-2048:latest
164- hud debug my-mcp-server:v1 -e API_KEY=xxx -p 8080:8080
168+ hud debug . # Debug current directory
169+ hud debug environments/browser # Debug specific directory
170+ hud debug . --build # Build then debug
171+ hud debug hud-text-2048:latest # Debug Docker image
172+ hud debug my-mcp-server:v1 -e API_KEY=xxx
165173 hud debug --config mcp-config.json
166174 hud debug --cursor text-2048-dev
167- hud debug hud-browser:dev --max-phase 3
175+ hud debug . --max-phase 3 # Stop after phase 3
168176 """
169-
177+ # Import here to avoid circular imports
178+ from .env_utils import get_image_name , is_environment_directory , build_environment , image_exists
179+ from hud .utils .design import HUDDesign
180+
181+ design = HUDDesign ()
182+
170183 # Determine the command to run
171184 command = None
185+ docker_args = []
172186
173187 if config :
174188 # Load config from JSON file
@@ -186,13 +200,44 @@ def debug(
186200 console .print (f"[red]❌ { error or 'Failed to parse cursor config' } [/red]" )
187201 raise typer .Exit (1 )
188202 elif params :
189- image , * docker_args = params
190- # Build Docker command
191- command = ["docker" , "run" , "--rm" , "-i" , * docker_args , image ]
203+ first_param = params [0 ]
204+ docker_args = params [1 :] if len (params ) > 1 else []
205+
206+ # Check if it's a directory
207+ if Path (first_param ).exists () and is_environment_directory (first_param ):
208+ # Directory mode - like hud dev
209+ directory = first_param
210+
211+ # Get or generate image name
212+ image_name , source = get_image_name (directory )
213+
214+ if source == "auto" :
215+ design .info (f"Auto-generated image name: { image_name } " )
216+
217+ # Build if requested or if image doesn't exist
218+ if build or not image_exists (image_name ):
219+ if not build and not image_exists (image_name ):
220+ if typer .confirm (f"Image { image_name } not found. Build it now?" ):
221+ build = True
222+ else :
223+ raise typer .Exit (1 )
224+
225+ if build :
226+ if not build_environment (directory , image_name ):
227+ raise typer .Exit (1 )
228+
229+ # Build Docker command
230+ command = ["docker" , "run" , "--rm" , "-i" , * docker_args , image_name ]
231+ else :
232+ # Assume it's an image name
233+ image = first_param
234+ command = ["docker" , "run" , "--rm" , "-i" , * docker_args , image ]
192235 else :
193- console .print ("[red]Error: Must specify either a Docker image, --config, or --cursor[/red]" )
236+ console .print ("[red]Error: Must specify a directory, Docker image, --config, or --cursor[/red]" )
194237 console .print ("\n Examples:" )
195- console .print (" hud debug hud-text-2048:latest" )
238+ console .print (" hud debug . # Debug current directory" )
239+ console .print (" hud debug environments/browser # Debug specific directory" )
240+ console .print (" hud debug hud-text-2048:latest # Debug Docker image" )
196241 console .print (" hud debug --config mcp-config.json" )
197242 console .print (" hud debug --cursor my-server" )
198243 raise typer .Exit (1 )
@@ -699,7 +744,19 @@ def eval(
699744 design .error (f"Invalid agent: { agent } . Must be one of: { ', ' .join (valid_agents )} " )
700745 raise typer .Exit (1 )
701746
702- # Import and run the command
747+ # Import eval_command lazily to avoid importing agent dependencies
748+ try :
749+ from .eval import eval_command
750+ except ImportError as e :
751+ from hud .utils .design import HUDDesign
752+ design = HUDDesign ()
753+ design .error (
754+ "Evaluation dependencies are not installed. "
755+ "Please install with: pip install 'hud-python[agent]'"
756+ )
757+ raise typer .Exit (1 ) from e
758+
759+ # Run the command
703760 eval_command (
704761 source = source ,
705762 full = full ,
0 commit comments