refactor(agent): extract image budget helpers - #513
Merged
esokullu merged 2 commits intoJul 26, 2026
Conversation
|
@alectimison-maker is attempting to deploy a commit to the esokullu's projects Team on Vercel. A member of the Team first needs to authorize it. |
Object.freeze the module-level IMAGE_BUDGET so accidental mutation of the shared default throws (modules are strict mode) instead of silently changing every caller. Per-capture overrides already spread into fresh objects. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
esokullu
force-pushed
the
refactor/extract-image-budget
branch
from
July 26, 2026 18:01
efd4690 to
700aef9
Compare
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.
Summary
Agent.IMAGE_BUDGET,_estimateImageTokens, and_fitImageDimensionssurfaces as compatibility wrapperstest/run.jsimport the production sizing logic instead of maintaining a copied shimMotivation
TODOs.mdidentified image sizing as the next high-value case where tests duplicated pure logic because importingagent.jsbrings browser APIs with it. The copied implementation could drift from production while both appeared tested.This follows the same production-module pattern established for loop detection in #490.
Design
agent/image-budget.jsowns the complete default budget object plus the two browser-neutral sizing functions. Each Agent imports those exports and retains its static methods so existing capture paths and tests keep the same call surface.Only deterministic sizing moved. Chrome's OffscreenCanvas compression and Firefox's DOM canvas encoding remain platform-specific inside their Agent implementations.
The unit suite now imports
image-budget.jsdirectly for fast-path, token-cap, aspect-ratio, extreme-strip, and custom-budget cases. A parity assertion prevents the browser copies from drifting.Testing
node test/run.js— 1,329 passed; 1 inherited baseline failure (package.jsonis 25.9.7 while the newest changelog entry is 25.9.0)npm run test:security— 60/60 passednpm run test:fixtures— 125/125 passednpm run test:webmcp— passed against Chrome 150npm run test:ci— passednode --check src/{chrome,firefox}/src/agent/{agent,image-budget}.js— passedCompatibility and risks
The existing Agent static fields and methods are preserved. Default values and the binary-search algorithm are unchanged. This does not alter screenshot capture, compression, encoding, or provider behavior.
Scope
This intentionally leaves browser-dependent image compression in
agent.js. Other pure helper extraction and broader parser/context tests remain follow-ups inTODOs.md.