feat: window screenshot (PrintWindow), name-based window resolution

This commit is contained in:
Helios Agent 2026-03-03 16:39:23 +01:00
parent 27b1ffc55b
commit efc9cab2c3
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
6 changed files with 164 additions and 10 deletions

View file

@ -80,6 +80,24 @@ def resolve_session(session_id: str) -> str:
raise SystemExit(f"[helios-remote] No session found with label '{session_id}'")
def resolve_window(sid: str, window_id_or_name: str) -> int:
"""If window_id_or_name is a number, return it. Otherwise search by title substring."""
if window_id_or_name.lstrip('-').isdigit():
return int(window_id_or_name)
# Search by title
resp = _req("GET", f"/sessions/{sid}/windows")
windows = resp.json().get("windows", [])
query = window_id_or_name.lower()
matches = [w for w in windows if w.get("visible") and query in w.get("title", "").lower()]
if not matches:
raise SystemExit(f"[helios-remote] No visible window matching '{window_id_or_name}'")
if len(matches) > 1:
print(f"[helios-remote] Multiple matches for '{window_id_or_name}', using first:")
for w in matches:
print(f" {w['id']} {w['title']}")
return int(matches[0]["id"])
def cmd_sessions(_args):
"""List all connected sessions."""
resp = _req("GET", "/sessions")
@ -203,17 +221,36 @@ def cmd_minimize_all(args):
def cmd_focus(args):
"""Bring a window to the foreground on the remote session."""
"""Bring a window to the foreground (by ID or title substring)."""
sid = resolve_session(args.session_id)
_req("POST", f"/sessions/{sid}/windows/{args.window_id}/focus")
print(f"Window {args.window_id} focused on session {sid!r}.")
wid = resolve_window(sid, args.window_id)
_req("POST", f"/sessions/{sid}/windows/{wid}/focus")
print(f"Window {wid} focused on session {sid!r}.")
def cmd_maximize(args):
"""Maximize and focus a window on the remote session."""
"""Maximize and focus a window (by ID or title substring)."""
sid = resolve_session(args.session_id)
_req("POST", f"/sessions/{sid}/windows/{args.window_id}/maximize")
print(f"Window {args.window_id} maximized and focused on session {sid!r}.")
wid = resolve_window(sid, args.window_id)
_req("POST", f"/sessions/{sid}/windows/{wid}/maximize")
print(f"Window {wid} maximized on session {sid!r}.")
def cmd_screenshot_window(args):
"""Capture a specific window by ID or title substring → /tmp/helios-remote-screenshot.png"""
sid = resolve_session(args.session_id)
wid = resolve_window(sid, args.window_id)
resp = _req("POST", f"/sessions/{sid}/windows/{wid}/screenshot")
data = resp.json()
if "error" in data:
sys.exit(f"[helios-remote] {data['error']}")
import base64, os
out_path = args.output or "/tmp/helios-remote-screenshot.png"
img_bytes = base64.b64decode(data["image_base64"])
with open(out_path, "wb") as f:
f.write(img_bytes)
print(out_path)
return out_path
def cmd_server_version(_args):
@ -364,6 +401,12 @@ def build_parser() -> argparse.ArgumentParser:
sp = sub.add_parser("screenshot", help="Capture screenshot → /tmp/helios-remote-screenshot.png")
sp.add_argument("session_id")
swp = sub.add_parser("screenshot-window", help="Capture a specific window (by ID or title)")
swp.add_argument("session_id")
swp.add_argument("window_id", help="Window ID (number) or title substring")
swp.add_argument("--output", default=None, help="Output path (default: /tmp/helios-remote-screenshot.png)")
swp.set_defaults(func=cmd_screenshot_window)
ep = sub.add_parser("exec", help="Run a shell command on the remote session")
ep.add_argument("session_id")
ep.add_argument("parts", nargs=argparse.REMAINDER, metavar="command",
@ -459,10 +502,13 @@ def main():
"version": cmd_version,
"upload": cmd_upload,
"download": cmd_download,
"find-window": cmd_find_window,
"run": cmd_run,
"clipboard-get": cmd_clipboard_get,
"clipboard-set": cmd_clipboard_set,
"screenshot-window": cmd_screenshot_window,
"find-window": cmd_find_window,
"wait-for-window": cmd_wait_for_window,
"run": cmd_run,
"prompt": cmd_prompt,
"clipboard-get": cmd_clipboard_get,
"clipboard-set": cmd_clipboard_set,
}[args.subcmd](args)