Skip to content

refactor(macos): dedupe inline-image content parsing between computer.py and preview.py - #372

Merged
dhruvbatra merged 1 commit into
mainfrom
claude/cool-brahmagupta-a4lu2k
Sep 4, 2026
Merged

refactor(macos): dedupe inline-image content parsing between computer.py and preview.py#372
dhruvbatra merged 1 commit into
mainfrom
claude/cool-brahmagupta-a4lu2k

Conversation

@dhruvbatra

@dhruvbatra dhruvbatra commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What

The window-scope PR (#359) and the live-view PR (#369) landed back to back and each
independently wrote the same scan over a driver tool-call result's content list to
find the first inline image part:

  • computer.py::_decode_inline_frame (the capture pipeline) — raises on a missing frame
  • preview.py::inline_image (the live-view streamer) — returns None on a missing frame

Both scans are the identical for part in result.get("content") or []: if isinstance(part, dict) and part.get("type") == "image" and isinstance(part.get("data"), str): ... shape, just with different error handling wrapped around the same lookup.

Why

transport.py already owns similar content-part parsing for tool-call results (see _call_tool_once's text-part join for error details), so it's the natural home for a shared inline_image_data(result) -> str | None helper. Factoring the scan out there and having both call sites decode/validate on top of it removes the duplication without changing behavior at either call site.

Why it's safe

  • Both functions are internal (_decode_inline_frame is private; inline_image and the new inline_image_data are internal helpers within yutori/navigator/macos/, not part of the package's public API).
  • Behavior is preserved exactly: same field lookup, same isinstance checks; only the "not found" signal moved from an inline generator expression to a small shared function.
  • ruff check . and ruff format --check pass on the touched files.
  • Full test suite: 862 passed, 9 skipped (pytest -m "not slow"), including all existing coverage for _decode_inline_frame (tests/test_navigator_macos_computer.py) and inline_image (tests/test_navigator_macos_preview.py), unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LgNmemcBEhNYjkN8z2UGPf


Generated by Claude Code


Note

Low Risk
Internal refactor with no intended behavior change; both capture and live-preview paths keep their existing error handling.

Overview
Adds inline_image_data in transport.py to return the base64 data string from the first type: image entry in a driver tool-call result’s content list.

_decode_inline_frame in computer.py and inline_image in preview.py now call that helper instead of each scanning result["content"] on their own. Capture still raises when no frame is present; preview still decodes base64 and returns None on missing or invalid data—only the lookup is shared.

Reviewed by Cursor Bugbot for commit bc70dbe. Bugbot is set up for automated code reviews on this repo. Configure here.

….py and preview.py

The window-scope (#359) and live-view (#369) PRs landed back to back and each
independently wrote the same scan over a driver tool-call result's `content`
list for the first inline image part: computer.py's `_decode_inline_frame`
(capture pipeline) and preview.py's `inline_image` (live-view streamer).
Factor the shared scan into `transport.py::inline_image_data`, which already
owns similar content-part parsing for tool-call results, and have both call
sites decode/validate on top of it as before.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LgNmemcBEhNYjkN8z2UGPf
@dhruvbatra
dhruvbatra merged commit a5cb6a4 into main Sep 4, 2026
16 checks passed
@dhruvbatra
dhruvbatra deleted the claude/cool-brahmagupta-a4lu2k branch September 4, 2026 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants