Skip to content

Support pasted images in threads - #309

Merged
max-sixty merged 9 commits into
mainfrom
codex/thread-image-paste
Sep 5, 2026
Merged

max-sixty merged 9 commits into
mainfrom
codex/thread-image-paste

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

Thread text boxes could not carry screenshots without exposing raw Markdown and raw media URLs to the reader. This adds bounded raster uploads stored as content-addressed page media. Drafts and events retain portable Markdown references, while composers show removable thumbnails and sent images open in a focus-preserving Leaf modal.

The upload boundary accepts PNG, JPEG, GIF, and WebP files up to 10 MiB, verifies their signatures, serializes writes with other page transitions, reuses identical content, and refuses digest collisions. The browser uses the same route-scoping path for ordinary and MCP-served pages.

Tests cover upload validation, collision handling, paste and draft restoration, mixed text and image editing, MCP routes, modal focus, and preservation of the page URL. uv run pytest tests passes all 883 tests.

This was written by Codex on behalf of max-sixty

# Conflicts:
#	skills/leaf/assets/leaf.js
#	skills/leaf/assets/runtime/composing/input.js
#	skills/leaf/assets/runtime/composing/selection.js
#	skills/leaf/assets/runtime/conversation/box.js
#	skills/leaf/assets/runtime/conversation/replies.js
#	skills/leaf/assets/runtime/layer-client.js
#	skills/leaf/assets/runtime/markdown.js

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two observations that don't sit on a diff line, plus the inline notes.

midComposition() and the composer's Escape row still read textarea.value. This PR redefines a wired textarea's .value as a projection — the complete draft is sync.value(), as drafts.js's updated mirrorDraft comment now says. Two readers outside composing/input.js weren't moved with it. In runtime/keyboard/page.js, export function midComposition() tests active.value !== ""; the general comment box is a plain document.createElement("textarea") with no data-lf-offer and no reply draft context, so a general box holding only a pasted screenshot reads as empty and prepareActivation's activates() no longer defers the revision swap under the reader. In the same file, the composer.close row (id: "composer.close") picks its wording from fabInput.value.trim(), so an anchored composer holding only a pasted image says close on the key line while dismissFab in fact keeps the draft — the one case the row exists to distinguish. A WeakMap from textarea to its sync in input.js, exported as a draftOf(ta), would let both ask the complete value.

No focused specimen for the gallery. examples/CLAUDE.md states: "A change that adds or materially changes a core feature adds or updates its focused specimen in the same change; coverage in a public example does not substitute for the developer surface." Pasted thread images add a gesture on every text box and a new chrome part (lf-media-viewer in mountChrome), and no examples/ file is touched. A paste needs a live upload, but the rendered half doesn't: seeding a feature-gallery.jsonl message whose text carries ![…](/media/051bee487bfb5d13.png) exercises the message image, the lf-media-open control, and the viewer — which is also the "injected chrome whose state comes from outside one document" case that file asks to be named and exercised in the gallery's browser test.

The server-side door reads carefully: auth and layer gates ahead of the body, Content-Length bounded before the read with the connection closed on refusal, signature verification, and SVG kept out of the reader path where it would be same-origin stored script. The transaction around the content-addressed write is the right depth for the collision claim.

Comment thread skills/leaf/assets/runtime/media.js Resolved
Comment thread skills/leaf/assets/runtime/markdown.js Resolved
Comment thread skills/leaf/scripts/leaf/media.py Resolved
Comment thread skills/leaf/assets/runtime/chrome.css Resolved
max-sixty and others added 7 commits September 5, 2026 14:21
`compose_layer` copies every file under a layer root's `runtime`,
`widgets` and `vendor` into the page directory, and `mcp-page-app.html`
sat in `assets/vendor/`. Every page therefore carried 396KB it never
fetched — about 38% of its vendored bytes — because the MCP App resource
is not page payload at all. An MCP host reads it from the install over
the tool transport; no browser ever asks for it.

It moves to `skills/leaf/mcp-app/page-app.html`, outside the layer
roots, so nothing can vendor it. `scripts/vendor.py mcp-app` writes it
there and reproduces the tracked bytes exactly. `mcp_page.py` reads it
from a new `MCP_APP` constant, which sits beside `KERNEL` and
`BUNDLED_PACKAGES` saying why it is not one of them.

`BROWSER_DIRS` needs no split. It described `assets/vendor/` and a
package's `vendor/` as one kind and was wrong only about the one file
that was not browser payload; with that gone the tuple is accurate
again, and the page-shape check in `packages.py` is unaffected.

`test_init_does_not_vendor_the_mcp_app_resource` compares bytes rather
than names, so putting the file back under any layer root under any name
fails it. Verified by planting the copy back in `assets/vendor/` and
watching it fail.

A page initialized before this still holds the stale copy until its next
`page init`, which retires it along with anything else the layer
dropped.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 <[email protected]>
`assert_only_preview_restart_errors` held a set of accepted console strings for
the three tests that stop and replace a preview's server. Which of the start's
own fetches is in flight when the server goes decides the wording, so the set
gained a member every time a fetch moved, each time after a red main.

`restarting(page, errors)` brackets the span instead. What the page says inside a
block is the restart's by construction and is dropped, and everywhere else the
reading is now `errors == []` — stricter than the old filter, which excused a
transport error at any point in the test. A test that means to produce a
diagnostic asserts it inside the block that produces it, as
`test_a_service_that_goes_away_mid_start_says_only_that_and_comes_back` does for
both of the start's fetches. The helper's own self-test goes with the set it
bounded.

`tests/CLAUDE.md` states the rule beside the `refuse` case it already carried,
under **A test cannot assert over noise it makes itself**.
`.claude/skills/running-tend/SKILL.md` gains the matching class for reading a red
suite, which the bot has no other route to: a reading that has been widened
before is a fix PR against the test, not one more member.
`a` and `A` find the reader's place by comparing document positions against the
open Asks. The chrome is appended after the whole page, so a reader standing on
a thread in the conversation panel measured as behind every Ask there is. While
the walk wrapped around, that was invisible. Once it clamped at its edges both
keys landed on the last Ask instead of taking the reader to the first, which is
what left test_holding_a_key_repeats_only_where_the_press_is_a_walk red.

The layer was already half excluded — the banner by name, a caret in the chrome
by `inChrome` — and neither reached the panel. Refusing the layer outright is
wrong too: the route runs through it, since a widget frozen into a reply is an
Ask the walk visits and a reader working its controls is standing in the ordered
space. So `walkPlace` asks about membership of that space, and the focus and the
caret both read it.

The new test walks a page carrying two Asks and a third in a reply. It steps
from a panel thread to prove the layer is not a place, and back from the reply's
Ask after `landed` has moved off it, so a walk that could not read where the
reader is would answer from the walk's own memory and answer plausibly.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BT15hwVbBeys3JrTZ7jcEk
The everyday suite never asked whether a reader can see a key. A key
line with no rows in it is silent — the chrome paints, the console stays
clean, and every other everyday assertion holds — so the whole boot
cutover ran against a gate that would not have noticed. One assertion
closes that: at rest a page shows `c` and `r`, and a planted `lineRows`
returning nothing fails it while `errors` stays empty. The boot's own
failure to register a painter is loud and already covered.

This branch started much larger. It was fanning `tests/CLAUDE.md` out
into the helpers each rule describes, written before #304 rewrote that
document keeping the rules in place and its headings as addresses. Both
were the same job done opposite ways, and #304 landed first, so every
paragraph this branch added — the probe timeout, the traffic ledger,
`data-lf-applied`, the `aborted` refusal, autouse ordering,
`HOLD_MOTION`'s release, the ring reading — became a second copy of a
rule that now has a home. Those files are back at main's version.

`ring_faults` is also spelled here the way the code spells it.
`RING_FAULTS` appeared in the document and in a comment in
`test_render_conversations.py`, and is not a name in the tree.

Three citations named something that is not there. `## Layout and
motion` opens "The page must hold still under the reader's aim", and
#301 quoted a paraphrase of that sentence as though it were a heading,
from `chrome.css` and from `docs/site.css`. main has since deleted
`docs/site.css` outright, so that one is gone with the file.
`chrome.css` and `skills/leaf/assets/theme.css` now name the heading,
which is the address. Every quoted citation in the tree resolves against
a heading in the document it names, and the phrase itself appears
nowhere.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> _This was written by Claude Code on behalf of max-sixty_

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Static-hosted examples currently appear as drafts and their historical
version addresses return 404 because GitHub Pages cannot synthesize
Leaf's virtual `/versions/vN.html` routes.

This materializes the same runtime-document projections during the site
build and derives current and pinned document identity from the
event-backed version map before the Leaf runtime loads. The canonical
page source, immutable revisions, and events remain the record;
generated version files are disposable delivery output. The static
session also exposes revision-bounded comparison views, so the version
menu's comparison and navigation paths both work.

Verified with the complete published-site browser suite, the everyday
test suite, pre-commit, and a light/dark browser sweep of the
two-version example.

> _This was written by Codex on behalf of max-sixty_
@max-sixty
max-sixty merged commit 372a97c into main Sep 5, 2026
6 checks passed
@max-sixty
max-sixty deleted the codex/thread-image-paste branch September 5, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants