Skip to content

Commit 0d5fa21

Browse files
committed
Resize file in screen toolkit
1 parent 71863a1 commit 0d5fa21

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/goose/toolkit/screen.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import subprocess
22
import uuid
3+
from typing import Optional
4+
5+
from rich.markdown import Markdown
6+
from rich.panel import Panel
37

48
from goose.toolkit.base import Toolkit, tool
59

@@ -8,17 +12,30 @@ class Screen(Toolkit):
812
"""Provides an instructions on when and how to work with screenshots"""
913

1014
@tool
11-
def take_screenshot(self) -> str:
15+
def take_screenshot(self, resize: Optional[int]=None) -> str:
1216
"""
1317
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.
18+
Optionally, resize the image using the `sips` cli tool. You may do this fs there is potential for error in the payload size.
1419
20+
Args:
21+
resize (Optional[int]): Optional argument to resize the image.
1522
Return:
1623
(str) a path to the screenshot file, in the format of image: followed by the path to the file.
1724
""" # noqa: E501
1825
# Generate a random tmp filename for screenshot
1926
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png"
27+
screen_capture_command = ["screencapture", "-x", filename]
28+
resize_command = []
29+
resize_command_str = ''
30+
31+
subprocess.run(screen_capture_command)
32+
33+
if resize:
34+
resize_command = ["sips", "-Z", resize, filename]
35+
subprocess.run(resize_command)
36+
resize_command_str = ' '.join(resize_command)
2037

21-
subprocess.run(["screencapture", "-x", filename])
38+
self.notifier.log(Panel.fit(Markdown(f"```bash\n{' '.join(screen_capture_command)}\n{resize_command_str}"), title="screen"))
2239

2340
return f"image:{filename}"
2441

0 commit comments

Comments
 (0)