From 4bcf2055cb97d0c69fc94643b3e43b579d6fa30c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 00:51:28 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- build/patches.zig | 37 +++++++++++++++++++++++++++++++++++++ build/patches/ghostty_kitty.zig | 21 +++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'build') diff --git a/build/patches.zig b/build/patches.zig index 3d956d26..7c7b2d60 100644 --- a/build/patches.zig +++ b/build/patches.zig @@ -213,7 +213,44 @@ pub fn zstbi(b: *std.Build, patch: *std.Build.Step.Compile, zstbi_dep: *std.Buil /// - an image may be no larger than a screen's storage /// (TerminalImages.storage_limit) rather than ghostty's 400 MB, which a /// program could make pardes read and hold before refusing it. +/// - a medium's bytes (t=f, t=t, t=s) are had through `read_medium` when +/// the host sets one, which is handed ghostty's own read: pardes makes +/// that read a recorded answer, so a session reads a file once (deletes +/// a temporary file, unlinks shared memory, once) and every replica of +/// it is handed the same bytes or the same failure, never reading its +/// own machine (core/Term.zig `media`; docs/ghostty-kitty-medium.md). const ghostty_kitty = [_]Edit{ + .{ + .old = " /// Initialize a chunked immage from the first image transmission.\n", + .new = + \\ /// pardes (build/patches.zig): how a file's, a temporary file's or + \\ /// shared memory's bytes are had: `read(ctx)` is ghostty's own read + \\ /// (which deletes a temporary file and unlinks shared memory), its + \\ /// bytes `alloc`'s; null, it is made as it is. + \\ pub var read_medium: ?*const fn (ctx: *const anyopaque, read: *const fn (ctx: *const anyopaque) MediumError![]u8, alloc: Allocator) MediumError![]u8 = null; + \\ pub const MediumError = error{ OutOfMemory, InvalidData, UnsupportedMedium, DimensionsTooLarge, TemporaryFileNotInTempDir, TemporaryFileNotNamedCorrectly }; + \\ + \\ /// Initialize a chunked immage from the first image transmission. + \\ + , + }, + .{ + .old = + \\ switch (t.medium) { + \\ .direct => unreachable, // handled above + \\ .file => try result.readFile(.file, io, alloc, t, cmd.data), + \\ .temporary_file => try result.readFile(.temporary_file, io, alloc, t, cmd.data), + \\ .shared_memory => try result.readSharedMemory(io, alloc, t, cmd.data), + \\ } + \\ + , + .new = + \\ // pardes (build/patches.zig): through the host's `read_medium`. + \\ const medium: PardesMedium = .{ .loading = &result, .io = io, .alloc = alloc, .t = t, .path = cmd.data }; + \\ result.data = .fromOwnedSlice(if (read_medium) |read| try read(&medium, PardesMedium.read, alloc) else try PardesMedium.read(&medium)); + \\ + , + }, .{ .old = "const max_size = 400 * 1024 * 1024; // 400MB", .new = "const max_size = 64 * 1024 * 1024; // pardes (build.zig): a screen's storage, TerminalImages.storage_limit", diff --git a/build/patches/ghostty_kitty.zig b/build/patches/ghostty_kitty.zig index a86d62d3..870c51e1 100644 --- a/build/patches/ghostty_kitty.zig +++ b/build/patches/ghostty_kitty.zig @@ -13,3 +13,24 @@ fn pardesOpenRegular(io: std.Io, path: []const u8) !std.Io.File { const same = std.fmt.bufPrint(&buf, "/proc/self/fd/{d}", .{probe.handle}) catch unreachable; return std.Io.Dir.cwd().openFile(io, same, .{}); } + +/// pardes (build.zig): a medium's read as ghostty makes it, handed to the +/// host's `LoadingImage.read_medium`: its bytes, the caller's. +const PardesMedium = struct { + loading: *LoadingImage, + io: std.Io, + alloc: Allocator, + t: command.Transmission, + path: []const u8, + + fn read(ctx: *const anyopaque) LoadingImage.MediumError![]u8 { + const m: *const PardesMedium = @ptrCast(@alignCast(ctx)); + switch (m.t.medium) { + .direct => unreachable, // read by the caller + .file => try m.loading.readFile(.file, m.io, m.alloc, m.t, m.path), + .temporary_file => try m.loading.readFile(.temporary_file, m.io, m.alloc, m.t, m.path), + .shared_memory => try m.loading.readSharedMemory(m.io, m.alloc, m.t, m.path), + } + return m.loading.data.toOwnedSlice(m.alloc); + } +}; -- cgit v1.3