fix(screen): write captures to file instead of returning inline base64

Screenshots and session frames are now saved to ~/.hanzo/screen/ and
the tool returns the file path. Prevents blowing up context with ~52K
chars of base64 per capture.
This commit is contained in:
2026-03-06 04:18:32 -08:00
parent 279afc5ad0
commit 30fb202cf0
2 changed files with 29 additions and 6 deletions
@@ -193,15 +193,25 @@ def _process_recording_for_claude(
quality=quality,
)
# Convert to serializable format
# Write frames to files instead of returning inline base64
frames_dir = os.path.join(
os.environ.get("HOME", "/tmp"),
".hanzo", "screen", "frames",
)
os.makedirs(frames_dir, exist_ok=True)
session_id = int(time.time())
frames_data = []
for data, info in frames:
for i, (data, info) in enumerate(frames):
frame_path = os.path.join(frames_dir, f"session_{session_id}_f{i:03d}.jpg")
with open(frame_path, "wb") as f:
f.write(data)
frames_data.append(
{
"timestamp_sec": info["timestamp_sec"],
"timestamp_ms": info["timestamp_ms"],
"size": len(data),
"base64": base64.b64encode(data).decode(),
"path": frame_path,
}
)
@@ -301,7 +311,7 @@ OTHER ACTIONS:
capture: Single screenshot
- region: [x, y, width, height] (optional)
- optimize: Compress for Claude (default: true)
- Returns base64 image
- Returns file path (image saved to ~/.hanzo/screen/)
record: Start background recording
- duration: Recording duration in seconds (max {self.config.max_duration})
@@ -417,13 +427,26 @@ EXAMPLES:
format_type = "png"
info = {}
# Write to file instead of returning inline base64
capture_dir = os.path.join(
os.environ.get("HOME", "/tmp"),
".hanzo", "screen",
)
os.makedirs(capture_dir, exist_ok=True)
capture_path = os.path.join(
capture_dir,
f"capture_{int(time.time())}.{format_type}",
)
with open(capture_path, "wb") as f:
f.write(data)
return json.dumps(
{
"success": True,
"format": format_type,
"size": len(data),
"dimensions": info.get("new_dimensions"),
"base64": base64.b64encode(data).decode(),
"path": capture_path,
}
)
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "hanzo-tools-computer"
version = "0.5.2"
version = "0.5.3"
description = "Computer control tools for Hanzo AI - automation, screen recording, activity detection, session compression for Claude (100 images/32MB/2000px limits)"
readme = "README.md"
license = "MIT"