Skip to content

feat(module-images): markup-guided image edits with --markup - #3972

Merged
schlessera merged 8 commits into
mainfrom
feat/3785-image-markup
Nov 12, 2026
Merged

schlessera merged 8 commits into
mainfrom
feat/3785-image-markup

Conversation

@schlessera

@schlessera schlessera commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Closes #3785. Part of #3781.

What changed

brain image --ref <image> --markup <layer.png> sends an annotation layer with an edit. The layer is a transparent PNG, exactly the size of the first --ref, whose strokes and notes guide the change. It is posted as the multipart markup part on /v1/images/edits, next to image[] and never with a mask. The models are the GPT Image 2.6 and 2.5 pairs (a new markupGuidance capability), and the default stays gpt-image-2.6-sunburst.

Refused before any request:

  • Markup with no --ref.
  • Markup with --mask.
  • A layer that is not a PNG by signature, whatever its file name.
  • A PNG with no alpha channel: colour type 4 or 6, or a tRNS chunk, is required.
  • A layer whose width and height differ from the first reference. JPEG references are measured after their EXIF orientation, because OpenAI compares the sizes "after orientation".
  • A reference or layer over 16,777,216 pixels, or a layer file over 50 MB.
  • An unreadable first reference.
  • Markup on Gemini.

The checks read file headers only (src/markup.ts: PNG IHDR/tRNS, JPEG SOF plus EXIF Orientation, WebP VP8X/VP8L/VP8). The CLI runs them before routing, dry runs included. openaiProvider.generate runs them again for direct callers. geminiProvider.generate now refuses a markup layer instead of silently dropping it.

Help text, the README, the image-gen skill and a minor changeset document the above. Two citation ranges into the image module have moved with the new lines.

Why this shape

Markup is a model capability, like masks, so routing narrows on it the same way. It is exclusive with mask, needs a reference, and is refused when no capable model remains.

The size and alpha checks follow OpenAI's image-generation guide, re-read on 2026-11-11: "a separate transparent PNG", "must contain transparent pixels; do not flatten it", "the same width and height after orientation", "Do not combine markup with mask", and the 16,777,216-pixel and 50 MB limits. Requiring an alpha channel is the header-level form of "must contain transparent pixels". Decoding pixels to prove that some are actually transparent would need an image decoder, which this module does not carry. A first reference whose header cannot be read is refused rather than sent unchecked.

The guide says nothing about markup with GIF output, so this PR adds no rule for that combination. JSON-body edits (image_url/file_id) and any drawing UI stay out of scope, as the issue says.

Guard checklist (proportionate containment):

  • Scope: each guard refuses one request, with a reason that names the file and the fix.
  • State and recovery: nothing is recorded, and nothing else is restricted. Fixing the file and running again recovers.

Proof

bun run test packages/module-images: 246 pass, 0 fail. Root bun run typecheck passes on head 4e95e0d10. The first candidate run failed strict typecheck on a test byte comparison (Uint8Array<ArrayBufferLike> passed to toEqual); my earlier local typecheck predated the tests. The comparison now uses plain arrays. It needed NODE_OPTIONS=--max-old-space-size=12288 locally, because the default heap aborted. bun run lint is clean.

Failing-first. I put packages/module-images/src back to origin/main, deleting markup.ts, and kept the new tests. The 20 new tests failed and the existing 226 passed. Every failure was an assertion, not a load error:

  • On main, --markup is parsed and silently ignored. The edit therefore goes out with no markup part: IMAGE_MARKUP_PART expected a Blob and received null.
  • Each refusal case exited 0 where 1 was expected, after posting a request.
  • Routing resolved where impossible was expected, and its reason lacked /markup/.
  • markupGuidance was undefined.
  • The provider-level guards returned images where ImageProviderError was expected.

Mutations, each restored afterwards:

  1. The dimension check compared width only (if (layer.width !== base.width)). Two tests failed:
    • "markup with mismatched dimensions refuses before any request": expected exit 1, received 0.
    • "OpenAI refuses markup with mismatched dimensions without a request": expected ImageProviderError, received an image result.
  2. The EXIF orientation swap was disabled. Two tests failed:
    • "the size of a JPEG --ref is read after its EXIF orientation"
    • "markup with a JPEG --ref whose orientation swaps its edges refuses before any request"

After restoring, all 246 pass.

{"version":1,"kind":"brain-check-pr-receipt","head":"4e95e0d10dce1ef6a5af672b8c77b43afea70221","base":"origin/main","mode":"focused","startedAt":"2026-11-11T13:46:21.438Z","finishedAt":"2026-11-11T13:47:23.265Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12556.239324999999},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":102.82368200000201},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":78.70594600000186},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":17.277658999999403},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":49055.530439999995}]}

Collisions (bun scripts/collisions.ts --json --pr 3972 at head e65925c498b9103d84d48d1ab1d055ed58e71198): 0 path or unknown collisions. Two textual overlaps on docs/decisions/governed-writable-workers.md, with #3393 and #3464, come only from the one-line citation range. The rest are closure-level, through shared test consumers: #3056, #3059, #3116, #3437, #3581, #3622, #3662, #3726, #3806, #3968, #3971.

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Anything left open

Nothing. The --json envelopes are unchanged.

🤖 Generated with Claude Code

schlessera and others added 2 commits November 11, 2026 08:49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 11, 2026
@schlessera schlessera added type: feat A new capability or a change in user-visible behaviour. area: modules First-party content modules and the module seam. labels Nov 11, 2026
@schlessera
schlessera marked this pull request as ready for review November 11, 2026 13:24
…eck (#3785)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera
schlessera marked this pull request as draft November 11, 2026 13:48
@schlessera
schlessera marked this pull request as ready for review November 11, 2026 13:48
@schlessera
schlessera marked this pull request as draft November 11, 2026 14:08
@schlessera
schlessera marked this pull request as ready for review November 11, 2026 14:08
@schlessera

Copy link
Copy Markdown
Owner Author

Candidate confirmation is blocked by a CI runner outage, not by this change. Head 4e95e0d10dce1ef6a5af672b8c77b43afea70221, base 8ce26e65f3d6af77ebf679c4dbfdcd29172c8222.

Two consecutive confirmations of this head failed at the same step, before any test ran:

  • Runs 43032528423 and 43035585306/43035587724, all four unit shards, step "Real Chrome and offline Linux namespace prerequisites".
  • The step exited 100, or timed out after 12 minutes.
  • Every failing log shows Temporary failure resolving 'azure.archive.ubuntu.com' while apt fetched bubblewrap and poppler-utils.

The earlier strict-typecheck failure (run 43028828486) was real and is fixed in 4e95e0d10. verify passed on both later runs, and so did contract.

I am not retrying while the mirror lookup is failing. To resume: once a CI run passes that prerequisite step again, run bun scripts/integrate.ts confirm 3972 --issues schlessera/brain-kit#3785 on a fresh merge of main. No code change is expected.

@schlessera
schlessera marked this pull request as draft November 12, 2026 09:43
@schlessera
schlessera marked this pull request as ready for review November 12, 2026 09:43
@schlessera
schlessera merged commit 631bbae into main Nov 12, 2026
39 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: modules First-party content modules and the module seam. 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.

modules: markup-guided image edits (--markup)

1 participant