diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 00:51:28 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 01:04:49 -0300 |
| commit | 4bcf2055cb97d0c69fc94643b3e43b579d6fa30c (patch) | |
| tree | cc845bdc25436aca800fb4791a9709ad913f3d32 /docs/ghostty-kitty-medium.md | |
| parent | 8e04bc6370916ac328f61ad0df6e3babeb9789b4 (diff) | |
| download | pardes-4bcf2055cb97d0c69fc94643b3e43b579d6fa30c.tar.gz pardes-4bcf2055cb97d0c69fc94643b3e43b579d6fa30c.zip | |
term: a kitty image's medium (a file, a temporary file, shared memory) is the session's read and a recorded answer on the tape, so every replica's emulator is handed the bytes the session read, or its failure, and never reads its own machine: ghostty's loader gets the bytes through `LoadingImage.read_medium` (an Edit in build/patches.zig, ghostty's own read handed to it, the report in docs/ghostty-kitty-medium.md), which the terminal module sets to the core's `Term.media`, a `tape.valueIn(.medium, ...)` site (a new Site; `valueIn` is `value` with the answer's slices in the loader's allocator, no yield inside a feed), so a read crosses to a client as a file read does (inline under 1 MiB, by hash at or over it), a temporary file is deleted and shared memory unlinked once, on the session, and the program is answered by the session alone; a replica no longer loads by direct data only: `Term.direct`, `State.direct` and the `direct` entry go (`media` in their place); under screen state the read stays the authority's (a screen-state replica feeds no emulator); FIRST the test through the replica's surface (a session and a bytes replica, four images shown, by a file, a temporary file, shared memory and a missing file): on the base the digests parted (expected 8810391091473565423, found 2236913079067993401: the replica's loader said "unsupported medium" and did not move its cursor), now they agree, the terminals dump the same bytes, the temporary file and the object are gone and the replica read nothing (ghostty's FileNotFound warned once); tui term-test 17/17, kitty-test 45/45, core-test 856/1007 (151 skipped), shell-test 1043/1046, unit-test -Dtest-filter=bytes: 23/23 (the perf check's BaselineHarnessMismatch, as on the base)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'docs/ghostty-kitty-medium.md')
| -rw-r--r-- | docs/ghostty-kitty-medium.md | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/docs/ghostty-kitty-medium.md b/docs/ghostty-kitty-medium.md new file mode 100644 index 00000000..c990ea6d --- /dev/null +++ b/docs/ghostty-kitty-medium.md @@ -0,0 +1,57 @@ +# ghostty: a host cannot be the one that reads a kitty image's medium + +A note for upstream (https://github.com/ghostty-org/ghostty), against the +commit pardes pins (83fb95624b04, 1.4.0, `build.zig.zon`). pardes patches +its fetched copy at build time (build/patches.zig, `ghostty_kitty`, and +build/patches/ghostty_kitty.zig) until upstream has a way, if it wants one. + +## What a host cannot do + +A kitty graphics transmission by file (`t=f`), temporary file (`t=t`) or +shared memory (`t=s`) is read inside `LoadingImage.init` +(`src/terminal/kitty/graphics_image.zig`): `readFile` opens, checks and +reads the path, and deletes a temporary file; `readSharedMemory` opens, +maps, copies and unlinks the object. A host of libghostty-vt can allow or +refuse each medium (`LoadingImage.Limits`), and nothing else: it cannot +be the one that has the bytes. + +pardes needs to. A session's terminal is parsed by its own emulator and, +the same bytes in the same order, by the emulator of every client of the +session, each on its own machine. A file or a shared memory object names +something on the session's machine, and a temporary file or an object is +gone once its first reader has read it. So a client must not read the +medium: it must be handed the bytes the session read, or the failure the +session met, and the program must be answered once, by the session. If a +client refuses the medium instead, a shown image (`a=T`) moves the +session's cursor past it and not the client's, and the two terminals part. + +## The patch + +`LoadingImage.read_medium`, a hook a host may set (null: ghostty's read +as it is). When set, `init` hands it ghostty's own read as a function and +a context, and the allocator the bytes are to be in; what it returns +becomes the image's data: + +```zig +pub var read_medium: ?*const fn (ctx: *const anyopaque, read: *const fn (ctx: *const anyopaque) MediumError![]u8, alloc: Allocator) MediumError![]u8 = null; +``` + +The read itself is ghostty's, unchanged (`readFile`, `readSharedMemory`, +their checks, the deletion and the unlink), behind a small struct appended +to the file (`PardesMedium.read`). pardes's hook calls it on the session +and records what it returned; a client's hook returns the recorded bytes +(or error) without calling it. Everything before the read (the limits, +the PNG check, the path's NUL check) and after it (decompression, +decoding, the size checks of `complete`, the answer) runs on every side +alike. + +## Why not rewrite the transmission instead + +The other way is to turn `t=f`, `t=t` and `t=s` into direct data before +the emulator sees it. That parses the APC outside ghostty, repeats its +rules (the temporary directory and the name a temporary file must have, +the `/proc`, `/sys` and device refusals, the shared memory range by +format, offset and size, `S` meaning an exact length), and re-encodes the +bytes as base64 a third larger, chunked to the protocol's limits. It also +changes what the emulator sees, so its answer to the program has to be +checked to match. The hook keeps all of that in ghostty. |
