Repository navigation
Description
The case
An agent built a Leaf page that plays an animated, scrubbable explainer of Worktrunk's wt merge. A page module draws each frame as one SVG. A "Save as video" button replays the frames into a canvas and records them with MediaRecorder, which produced a valid H.264 MP4 (1280×720, ~30 fps, 35.4 s, 4.5 MB).
The next step was to put that recording back into a page as a <video>, so the explainer could be shown without its page module (in a summary page, a neighbouring page, or an export). Leaf refused it:
leaf page media <page> wt-merge.mp4exits withnot an image leaf serves, becausecmd_mediainskills/leaf/scripts/leaf/media.pyadmits only the suffixes inMEDIA_TYPES(schema.py): png, jpg/jpeg, gif, webp, svg.- Copying the file into
media/by hand wouldn't help either. The server's path allowlist is built from the same table (schema.py, theMEDIA_DIRpattern inDIR_FILES→SERVED_PATH), andSERVED_PATH.fullmatch("/media/0123456789abcdef.mp4")isFalsewhile the.pngspelling isTrue, so the request 404s.
The page therefore had no supported way to show the video it had just made.
What video and audio in page media would take
I checked each of these in the code. Where I'm inferring rather than measuring, I say so.
- Admitted types. Add
.mp4(video/mp4),.webm(video/webm) and probably.mp3/.m4a/.oggfor audio toMEDIA_TYPES. That one table feedsleaf page media,CONTENT_TYPES,BINARY_TYPESandSERVED_PATH, so admission and serving move together. The error text and docstrings ("not an image leaf serves", "Copy images into…") would read as media rather than images. - Sniffing. The browser upload door (
store_uploaded_media) checks file signatures for four raster types. If uploads should accept video too, which is a separate decision, it needs signatures for ISO-BMFF (ftypat offset 4) and WebM/Matroska (1A 45 DF A3).MAX_MEDIA_UPLOAD_BYTES(10 MiB) is sized for screenshots and would need a second look for video. The author door (cmd_media) trusts the suffix and needs no sniffing. - CSP.
PAGE_CSP(structure.py) sets nomedia-src, so media falls back todefault-src 'self' <CDN origins>. By the CSP spec a same-origin/media/…mp4is already admitted, so I don't expect a policy change for served pages (inferred from the spec; not run, because the server refuses the path first). - Byte ranges.
http.pyserves a page file withread_bytes()and a single 200, with noAccept-Rangesor206. Browsers usually play a 200 response, but seeking a<video>before it has fully buffered relies on range requests (Safari needs them to play at all). For a scrubbable explainer this matters, so serving media should supportRange. I inferred this from browser behaviour and haven't measured it against Leaf's server. - Export.
version exportalready handles most of this.resource_attribute_urlstreatssrcandposteron any element exceptscript/iframeas resources (so<video src>,<source src>and<audio src>are covered), and_embedded_policyalready addsdata:tomedia-src. What's missing is a size decision: inlining the 4.5 MB file above as base64 adds ~6 MB to the HTML, and a longer recording grows it without limit. Options: set a size cap with a clear refusal, or leave oversized media out of the export with a visible placeholder. - Guidance.
references/authoring-evidence.md, "Source files and media", says to useleaf page media"for images". It would name video and audio, say when a recording is better than a live widget (a fixed demo, something for export, a screen capture of a real UI) and when it isn't (anything the user should manipulate or comment on frame by frame), and say to give a<video>controlsand aposter.
Why it matters beyond this page
Many of the things an agent wants to show a user are motion: a UI interaction, a before/after that only differs in behaviour, a terminal session, a screen recording of a bug. Today the only options are a sequence of stills or a bespoke page module, and a module can't be reused on a page that doesn't have it. Pages already carry content-addressed media and export it, so video is the same mechanism with more types, plus byte ranges and an export size decision.
This was written by Claude Code on behalf of max-sixty
Activity
leaf-agent commentedon Sep 24, 2026
This is a page-media feature request. The existing content-addressed path is the right place for authored recordings:
MEDIA_TYPEScontrols bothpage mediaadmission and the served-path allowlist, and captured page resources flow into export throughrevision_artifact.py. The current HTTP file response reads the complete file and returns 200, so seekable playback needs a range-response change in that same serving path.I would keep browser uploads a separate choice:
store_uploaded_mediacurrently accepts only signature-checked raster images with a 10 MiB limit, whilepage mediaaccepts an author's local file by suffix. Export'sinline_assetsembeds referenced bytes, so a recording also needs an explicit export size policy. This would make a reusable recording work across pages while preserving the existing page-media ownership model.