66import os
77
88from .bash import open , run_bash
9- from .computer import computer
109from .edit import edit
1110from .filesystem import (
1211 create_directory ,
2423 search_files ,
2524 write_file ,
2625)
27- from .platform import get_display_num , get_screen_resolution
2826
29- width , height = get_screen_resolution ()
30- # set enviroment variables
31- os .environ ["WIDTH" ] = str (width )
32- os .environ ["HEIGHT" ] = str (height )
33- os .environ ["DISPLAY_NUM" ] = str (get_display_num ())
27+ # Try to detect screen resolution - may fail in headless environments (Docker, etc.)
28+ _has_display = False
29+ try :
30+ from .platform import get_display_num , get_screen_resolution
31+ width , height = get_screen_resolution ()
32+ # set environment variables
33+ os .environ ["WIDTH" ] = str (width )
34+ os .environ ["HEIGHT" ] = str (height )
35+ os .environ ["DISPLAY_NUM" ] = str (get_display_num ())
36+ _has_display = True
37+ from .computer import computer
38+ except RuntimeError :
39+ # No display server available - computer tool will not be registered
40+ computer = None
3441
3542
3643def install (ctx ):
@@ -39,7 +46,8 @@ def install(ctx):
3946 ctx .register_tool (run_bash , group = "computer" )
4047 ctx .register_tool (open , group = "computer" )
4148 ctx .register_tool (edit , group = "computer" )
42- ctx .register_tool (computer , group = "computer" )
49+ if _has_display and computer is not None :
50+ ctx .register_tool (computer , group = "computer" )
4351
4452 ctx .register_tool (read_text_file , group = "filesystem" )
4553 ctx .register_tool (read_media_file , group = "filesystem" )
0 commit comments