Skip to content

CONTRACT: feat(ui-sdk,ui-server,ui-react,backends): request_image_markup for markup-guided image edits (#3975) - #4104

Merged
schlessera merged 1 commit into
mainfrom
feat/3975-request-image-markup
Nov 17, 2026
Merged

schlessera merged 1 commit into
mainfrom
feat/3975-request-image-markup

Conversation

@schlessera

@schlessera schlessera commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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, for brain image --ref <image> --markup <layer>.

Design

  • Host-owned end to end. 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.
  • Bounded transport. The layer travels over its own upload, POST /api/markup/:requestId (multipart: layer plus a summary of 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.
    • The cap is 52,428,800 bytes, inclusive, the same in the browser, the route and the application.
    • The body is counted as it streams.
    • Only the request's own principal, with its exact turnId, can answer it.
    • GET /api/markup/:requestId/source serves the bound source while the request is open, because the general file route stops at 10 MiB.
  • Application (ui-server/src/brain/markup-application.ts):
    • Source: binds its hash and displayed size, using the CLI's own header reader, which moves to brain-common/internal/image-header.
    • Layer validation: PNG with alpha, exact dimensions, a full structural decode, and not fully transparent.
    • Naming: <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.
    • Rechecks under the lock, immediately before the link: source hash and size, directory topology, protected paths, authority, cancellation, membership.
    • Recording: the effect is recorded the moment the layer exists.
  • Delivery. markup_request goes only to the turn principal's connections that declared the imageMarkup client capability. Losing the last of them rejects the request, as do cancellation and shutdown. markup_error declines, and only the request's own principal can send it.
  • Backends. Both register the tool in the stable interactive roster, after request_image_mask, and refuse it at call time on voice and no-grant turns.
    • The Claude SDK-options snapshot changes in the four interactive modes only: the roster names, the schema digest and the brief in the retained append. Autonomous modes are byte-identical.
    • The pi roster fixture gains a markup variant; no existing variant moves.
  • App. The kit's MarkupEditor opens 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 renders MarkupResultCard, or MarkupFallback in the result's own words.
  • Kit copy. Just over the cap, the over-cap message states exact bytes, since "50.0 MB; the limit is 50 MB" was ambiguous.

Contract: docs/integration-contract/mcp.md, wire.md, package-api.md and docs/http-api.md (191 routes, checked by http-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

  • Tests:
    • ui-server:
      • application, 30 tests: inclusive cap, EXIF-6, transparency/structure, staging swap, post-link directory move, links, policy, authority;
      • upload and source routes over real HTTP, 14: a 13.3 MB layer arrives intact; cap and cap+1; a streaming bound with Bun's ceiling 4× above it; principal and turn binding;
      • full-host bridge, 11, on both backend ids;
      • live-authority lists.
    • Backends: Claude MCP adapter, 4; pi tool execution; stable-roster refusals; the voice record.
    • SDK: inventories and frames.
    • React: renderer, upload, queue and lifecycle, 8.
    • Kit browser test in the pinned Playwright image (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.
    • Keyless CLI check: markupProblem(layer, source) returns null for the written layer and refuses a flattened copy.
  • Provider-history guard: provider-history.test.ts passes, Claude 18/18 and pi 15/15, with no expectation changes.
  • Full-repo typecheck is clean.
  • Mutations: each guard broken and restored; every one fails the named test.
# Mutation Killed by
M1/M2 layer cap >= / removed the byte cap is inclusive
M3 route cap >= exactly 52,428,800 bytes is accepted
M4 dimension check removed EXIF orientation 6; not a transparent PNG of the source's size
M5 alpha check removed not a transparent PNG of the source's size
M6 pre-link source hash recheck removed a source changed after the layer is staged
M7 pre-link authority recheck removed cancellation and revocation recheck
M8 link replaced by overwrite repeated submission takes the next name; planted link
M9 directory topology recheck removed markup directory swapped
M10/M11 route principal / turn check removed another principal, another turn
M12 voice live-authority removed a voice turn refuses before any editor opens
M13 client capability gate removed no editor opens without a browser that can draw
M14 decline principal check removed another principal's connection cannot decline
M15 source binding skipped rotated-source receipt; unbindable source
M16/M17 Claude / pi visual refusal removed voice and no-grant refuse request_image_markup
N1 published inode not bound staged layer replaced before it is linked
N2 post-link directory recheck removed directory moved after the link
N3/N4 PNG decode / ink check removed fabricated header or truncated data; fully transparent layer
N5 turnId optional again no or empty turn; source route
N6 broadcast to everyone only the principal's drawing connections see it
N7 disconnect drain removed losing the last of them rejects it
N8 source route ownership removed source served to own principal and turn
N9 source hash check on read removed a changed source is no longer served
N10 store replaces instead of queueing a second request waits behind the open one
N11 over-cap exact-byte copy removed the cap is the CLI's 50 MiB

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:

  • the temporary inode was not bound at publication;
  • a write that failed after linking was hidden;
  • the 10 MiB file-route read stopped large sources;
  • the runtime-roster test edits had no matching probes (reverted; the unit roster tests cover markup);
  • fabricated or empty PNGs were accepted;
  • a second request discarded the open editor;
  • disconnect handling and delivery were not principal-scoped;
  • an omitted turnId bypassed the turn check.

Two doc mismatches were also fixed: the 401 shape, and the backend package names.

Collisions

bun scripts/collisions.ts --json --pr 4104 at head adf4212, rebased onto 0ef4dff (a clean rebase; the regenerated api reports are byte-identical to the merged ones) (since 3324121: the MarkupState declaration 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

  • MarkupState is exported again, allowlisted like MaskState; declaration emit names it in createBrainStores and useMarkupStore. The full bun run build passes.
  • http-supported-mounts.test.ts, http-mount-lifetimes.ts and docs/http-api-coverage.md cover both markup routes.
  • installed-turn-surface.test.ts now counts 46 bridge tools and asserts the markup schema.
  • tool-observation.ts names request_image_markup a host write, with a test; scripts/turn-surface-fixture.ts adds 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.
  • Local full runs: the root ./tests suite 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

  • pi worker RPC. The request_image_markup branch in worker-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.
  • Layers over 10 MiB in the receipt. The receipt loads the layer through /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".
  • Editor host refusal. The kit's browser tests prove a rejected onSubmit keeps 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

@schlessera schlessera added this to the 0.45.0 milestone Nov 16, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. area: ui-react React chat/files/voice components, stores, WebSocket transport. area: backends AgentBackend implementations and the seam they share. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 16, 2026
@uploads-sh

uploads-sh Bot commented Nov 16, 2026

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-kit/tests/markup.test.tsx, packages/ui-kit/tests/visual/markup-editor.visual.tsx, packages/ui-react/src/components/chat/chat-page.tsx and 4 more). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4104
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

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 after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4104 and the same screen, state and caption fields.

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 uploads list --pr 4104. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

@schlessera
schlessera marked this pull request as ready for review November 16, 2026 21:04
@schlessera
schlessera force-pushed the feat/3975-request-image-markup branch from 3324121 to f2e7944 Compare November 16, 2026 21:15
@schlessera
schlessera marked this pull request as draft November 16, 2026 21:18
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 21:18
@schlessera
schlessera marked this pull request as draft November 16, 2026 21:32
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 21:32
@schlessera
schlessera force-pushed the feat/3975-request-image-markup branch 2 times, most recently from 8ce70a2 to 6931a71 Compare November 16, 2026 23:26
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backends AgentBackend implementations and the seam they share. area: ui-react React chat/files/voice components, stores, WebSocket transport. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: feat A new capability or a change in user-visible behaviour.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-react: a markup editor for markup-guided image edits

1 participant