refactor(macos): dedupe inline-image content parsing between computer.py and preview.py - #372
Merged
Merged
Conversation
….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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
contentlist tofind the first inline image part:
computer.py::_decode_inline_frame(the capture pipeline) — raises on a missing framepreview.py::inline_image(the live-view streamer) — returnsNoneon a missing frameBoth 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.pyalready 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 sharedinline_image_data(result) -> str | Nonehelper. 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
_decode_inline_frameis private;inline_imageand the newinline_image_dataare internal helpers withinyutori/navigator/macos/, not part of the package's public API).isinstancechecks; only the "not found" signal moved from an inline generator expression to a small shared function.ruff check .andruff format --checkpass on the touched files.862 passed, 9 skipped(pytest -m "not slow"), including all existing coverage for_decode_inline_frame(tests/test_navigator_macos_computer.py) andinline_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_dataintransport.pyto return the base64datastring from the firsttype: imageentry in a driver tool-call result’scontentlist._decode_inline_frameincomputer.pyandinline_imageinpreview.pynow call that helper instead of each scanningresult["content"]on their own. Capture still raises when no frame is present; preview still decodes base64 and returnsNoneon 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.