diff --git a/src/goose/toolkit/screen.py b/src/goose/toolkit/screen.py index ce552488..f0cc5722 100644 --- a/src/goose/toolkit/screen.py +++ b/src/goose/toolkit/screen.py @@ -1,6 +1,9 @@ import subprocess import uuid +from rich.markdown import Markdown +from rich.panel import Panel + from goose.toolkit.base import Toolkit, tool @@ -8,17 +11,30 @@ class Screen(Toolkit): """Provides an instructions on when and how to work with screenshots""" @tool - def take_screenshot(self) -> str: + def take_screenshot(self, display: int = 1) -> str: """ - Take a screenshot to assist the user in debugging or designing an app. They may need help with moving a screen element, or interacting in some way where you could do with seeing the screen. + Take a screenshot to assist the user in debugging or designing an app. They may need + help with moving a screen element, or interacting in some way where you could do with + seeing the screen. - Return: - (str) a path to the screenshot file, in the format of image: followed by the path to the file. + Args: + display (int): Display to take the screen shot in. Default is the main display (1). Must be a value greater than 1. """ # noqa: E501 # Generate a random tmp filename for screenshot - filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png" + filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.jpg" + screen_capture_command = ["screencapture", "-x", "-D", str(display), filename, "-f", "jpg"] + + subprocess.run(screen_capture_command, check=True, capture_output=True) + + resize_command = ["sips", "--resampleWidth", "768", filename, "-s", "format", "jpeg"] + subprocess.run(resize_command, check=True, capture_output=True) - subprocess.run(["screencapture", "-x", filename]) + self.notifier.log( + Panel.fit( + Markdown(f"```bash\n{' '.join(screen_capture_command)}"), + title="screen", + ) + ) return f"image:{filename}"