Repository navigation
CONTRACT: feat(ui-sdk,ui-server,ui-react,backends): request_image_markup for markup-guided image edits (#3975) - #4104
Conversation
|
No uploads on this PR yet This PR changes UI files (
Tips for agentsLabel each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one uploads put after.png --pr 4104 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4104 --app ios --screen "Chat" --state afterNo CLI? With the Uploads MCP, call This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with Workspace admins can turn this comment off in Settings → GitHub · docs |
3324121 to
f2e7944
Compare
8ce70a2 to
6931a71
Compare
…kup for markup-guided image edits (#3975) Agents can ask the user to draw what an image edit should change: arrows, ellipses, freehand strokes and short notes. The host saves a transparent PNG layer at the source's displayed size (after EXIF orientation) under .brain/scratch/markup/ and returns its path, size, mark counts and notes for `brain image --ref <image> --markup <layer>`. - SDK: the request_image_markup contract, payload and brief; the markup_request and markup_error frames and the imageMarkup client capability; BackendBridge.requestImageMarkup, host-owned end to end, and handleRequestImageMarkup; the BRAIN_MARKUP_* bounds. - Server: a bounded multipart upload, POST /api/markup/:requestId, for layers up to 52,428,800 bytes, inclusive, far above the 12,000,000-byte frame. A server-owned application binds the source hash and size, refuses invalid, mismatched or opaque layers, links each layer onto a fresh server-derived name, and rechecks topology, protection, authority and membership under the lock. - Backends: both register the tool in their stable interactive roster after request_image_mask and refuse it on voice and no-grant turns. - App: the kit's MarkupEditor opens for a markup_request and uploads the layer. Closing it declines. The transcript renders the kit receipt or the refusal. - The CLI's image header reader moves to brain-common so the server and `markupProblem` read sizes with the same code. Contract: docs/integration-contract/mcp.md, wire.md, package-api.md and docs/http-api.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6931a71 to
adf4212
Compare
Closes #3975
Agents can now ask the user to draw what an image edit should change: arrows, ellipses, freehand strokes and short text notes. The host saves the drawing as a transparent PNG layer at the source's displayed size (after EXIF rotation) under
.brain/scratch/markup/. The tool returns the path, size, mark counts and note texts, forbrain image --ref <image> --markup <layer>.Design
BackendBridge.requestImageMarkup?(input)opens the editor, takes the layer, writes it and resolves with the receipt. This departs from the mask's two-step request-then-apply pattern: the worker never holds the bytes and never names a destination, so the "caller cannot forge bytes, turn or source" criterion holds by construction. A host without the callback refuses; there is no fallback writer.POST /api/markup/:requestId(multipart:layerplus asummaryof counts and notes), never the 12,000,000-byte socket frame. That frame limit, the mask's 8 MiB cap and all other limits are unchanged.turnId, can answer it.GET /api/markup/:requestId/sourceserves the bound source while the request is open, because the general file route stops at 10 MiB.ui-server/src/brain/markup-application.ts):brain-common/internal/image-header.<stem>.<sha8>.markup.png, then-2,-3. The layer is linked from a held temporary and never replaces an entry. The published entry must be that inode with exactly the validated bytes, in an unmoved directory.markup_requestgoes only to the turn principal's connections that declared theimageMarkupclient capability. Losing the last of them rejects the request, as do cancellation and shutdown.markup_errordeclines, and only the request's own principal can send it.request_image_mask, and refuse it at call time on voice and no-grant turns.markupvariant; no existing variant moves.MarkupEditoropens on the server's size and source, uploads the layer and stays open with the server's reason on refusal. Requests queue rather than discard an open drawing. The transcript rendersMarkupResultCard, orMarkupFallbackin the result's own words.Contract:
docs/integration-contract/mcp.md,wire.md,package-api.mdanddocs/http-api.md(191 routes, checked byhttp-inventory.test.ts). The changeset is minor for ui-sdk, ui-server, ui-react and both backends, and patch for common and module-images.Proof
node scripts/visual.mjs --project=visual --filter=markup-editor.visual, 15/15): a real Chromium JPEG with spliced EXIF 6. The shared header reader and the browser both read 240×320, and the drawn export is a 240×320 PNG with alpha.markupProblem(layer, source)returns null for the written layer and refuses a flattened copy.provider-history.test.tspasses, Claude 18/18 and pi 15/15, with no expectation changes.>=/ removed>=The redundant first stale-source check under the lock was not mutated: the pre-link recheck (M6) covers it.
Review
A gpt-6-astra adversarial review found eight issues; all are fixed with tests above:
turnIdbypassed the turn check.Two doc mismatches were also fixed: the 401 shape, and the backend package names.
Collisions
bun scripts/collisions.ts --json --pr 4104at headadf4212, rebased onto0ef4dff(a clean rebase; the regenerated api reports are byte-identical to the merged ones) (since3324121: theMarkupStatedeclaration export and the inventory fixes below): no path or unknown collisions; only test-closure overlap with open draft PRs.Inventories added after the first hosted run
MarkupStateis exported again, allowlisted likeMaskState; declaration emit names it increateBrainStoresanduseMarkupStore. The fullbun run buildpasses.http-supported-mounts.test.ts,http-mount-lifetimes.tsanddocs/http-api-coverage.mdcover both markup routes.installed-turn-surface.test.tsnow counts 46 bridge tools and asserts the markup schema.tool-observation.tsnamesrequest_image_markupa host write, with a test;scripts/turn-surface-fixture.tsadds it to the stable roster. The frozen experiments: the turn-surface live collector refuses every routed arm once the bridge roster passes the 64-entry catalogue bound #3886 measured classifier list is unchanged../testssuite passes, 2,280 tests. The ui-server suite passes from the repository root; its eight corpus-copying files fail only when run from the package directory.Known gaps
request_image_markupbranch inworker-rpc.ts(the pending-mutation wrap) is proven by reading only; the pi tool and host bridge are tested directly. Native worker execution is left to hosted proof./files/content, whose 10 MiB read bound is unchanged. A layer above it is saved and reported correctly, but the thumb honestly shows "markup not rendered".onSubmitkeeps the editor open. The React host is tested at the upload helper, not by drawing in happy-dom.{"version":1,"kind":"brain-check-pr-receipt","head":"adf42125f82f57eb39cabc22096a6f29825aa144","base":"origin/main","mode":"focused","startedAt":"2026-11-16T23:54:36.504Z","finishedAt":"2026-11-16T23:56:05.379Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":10975.887336},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":136.72487399999955},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":158.36472399999911},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.979381999999532},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":77551.98790800001}]}🤖 Generated with Claude Code