From 94561bf0e13d034384eae01d2cb9d48a8fe0a502 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 22 Nov 2026 10:39:52 -0300 Subject: tape: no screen-state branch left, and a terminal's kitty images are each side's own emulator's again (the old road's deletion, piece 6 of 8): core/tape.zig loses `Tape.screen_state` and every branch on it (a terminal's output recorded without its bytes, the positions and prompt checks skipped, `screenReplica`, `screenAuthority`, `screenState`, `viewOnly`, which on the one road did nothing), and the tape site `images`; core/panes.zig its replica branches (a feed skipped and the session's positions taken, a view's scroll or follow noted, a resize left to the authority, the reloads at a join skipped); core/Term.zig a terminal's digest that returned early under screen state, and the medium read that went past the tape; core/dump.zig a join's dump always holds each terminal whole (`slim_terminals` stays for the exit dump); the tests' `t.screen_state = false` lines (4 in core/replica.zig, 3 in test/replicas.zig); THE IMAGES (the brief's choice): `Pane.term_images` and its taped read after each output (pardes-image-loop's cure for a screen-state client, whose emulator never held an image) go, the tag reads `Term.hasImages` again (core/tagline.zig), and a terminal's digest holds whether it has an image (core/term/terminal.zig `digest`: one bool among its facts), so the fact the tag shows is covered by the digest it is computed from (S1's rule) rather than by a pane field copied after each output, and a parting over it is named at the terminal; abi/wire.zig's line for 30 says so (the dump's shape changed with it); the image-loop's test runs on the one road (the client's emulator has the image, its tag says what the session's does); core-test 911/1068 (157 skipped), shell-test 1110/1113, term-test 15/15, pane-test 181/182, kitty-test 45/45, the soak's small run and `--echo` rc 0 (diverged 0, unequal 0, corpus 22) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 6 ++++-- core/Core.zig | 1 - core/Term.zig | 8 +------ core/dump.zig | 17 ++++++--------- core/echo.zig | 2 +- core/panes.zig | 30 +++----------------------- core/replica.zig | 4 ---- core/tagline.zig | 2 +- core/tape.zig | 57 +++----------------------------------------------- core/term/terminal.zig | 3 ++- test/replicas.zig | 3 --- 11 files changed, 21 insertions(+), 112 deletions(-) diff --git a/abi/wire.zig b/abi/wire.zig index 48b3ae51..8f7a7bdb 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -11,8 +11,10 @@ const config = @import("pardes_options"); const build_info = @import("build_info"); /// 30: the terminals' one road: the screen-state messages are retired (a -/// replica's `screen_ack`, 0x04, and the session's `screen`, 0x06: gaps) -/// and a welcome says no road (its `bytes` byte gone); +/// replica's `screen_ack`, 0x04, and the session's `screen`, 0x06: gaps), +/// a welcome says no road (its `bytes` byte gone), and a pane's +/// `term_images` and its tape site leave the dump (each side's emulator +/// answers; a terminal's digest holds whether it has an image); /// 29: a session's terminals reach its clients as the pty's bytes in its /// units, each client's emulator its own; a welcome says the road (`bytes`; /// screen state under PARDES_TERM_SCREEN), which the client loads its dump diff --git a/core/Core.zig b/core/Core.zig index 4c8c98dd..91f647d4 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1685,7 +1685,6 @@ fn updateInner(p: *Pardes, ev: Event) void { pane.shell_spoke = true; ctlfs.events.notePtyOutput(p, o.pane.index(), o.bytes); pane.feedOutput(p, o.bytes); - pane.term_images = if (p.tape.screen_state) p.tape.value(.images, pardes.Term.hasImages, .{pane.terminal}) else pardes.Term.hasImages(pane.terminal); ctlfs.pty.noteMarks(p, o.pane.index(), pane); exec.flushReplEnter(p, o.pane.index(), true); }, diff --git a/core/Term.zig b/core/Term.zig index 86c7518b..968a8d68 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -68,11 +68,7 @@ pub const State = struct { written: bool = true, /// The emulator as its program has made it, for the replay digest. - /// Under screen-state terminals the emulator is the authority's, and a - /// replica's is what the last delta made it: compared as screens - /// (test/replicas.zig), not step by step. pub fn digest(s: *const State, h: *walk.Hasher) void { - if (tape.screenState()) return; s.digestScreen(h, true); } @@ -135,10 +131,8 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State { /// session's machine's) as its emulator reads it, made the tape's answer /// (P30: the device's answer as it was, as a file's bytes are): the session /// reads it, a temporary file deleted and shared memory unlinked there once, -/// and every replica is handed the same bytes, or the same failure. Under -/// screen state a replica feeds no emulator: the read is the session's. +/// and every replica is handed the same bytes, or the same failure. fn media(ctx: *const anyopaque, read: *const fn (*const anyopaque) iface.MediumError![]u8, gpa: std.mem.Allocator) iface.MediumError![]u8 { - if (tape.screenState()) return read(ctx); return tape.valueIn(.medium, gpa, readMedium, .{ read, ctx }); } diff --git a/core/dump.zig b/core/dump.zig index 18ac28f7..c3742a21 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -255,16 +255,12 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { return pardes.Db.image(gpa, name, buf.written(), w.blobs.items, panes, names.written()); } -/// A dump for a screen-state replica's join (core/replica.zig): its blobs' -/// bytes left out and noted in `deferred` (they are the session's, alive -/// while pinned: memory.zig `pin`), its terminals' emulators left out (the -/// first delta brings each afresh). What is left is the session's mutable -/// state, made in its step. +/// A dump for a replica's join (core/replica.zig): its blobs' bytes left +/// out and noted in `deferred` (they are the session's, alive while pinned: +/// memory.zig `pin`), each terminal whole (as the join's step reloaded it +/// on every side: panes.reloadTerminals), its sequence in flight with it. +/// What is left is the session's mutable state, made in its step. pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![]u8 { - // Under bytes, each terminal whole (as the join's step reloaded it on - // every side: panes.reloadTerminals), its sequence in flight with it. - slim_terminals = p.tape.screen_state; - defer slim_terminals = false; // The join's file reads are the session's host's, between its steps: // with its io, which the core's tape holds (a walk's hook takes no more). join_files = p.tape.io; @@ -272,8 +268,7 @@ pub fn dumpJoin(p: *Pardes, deferred: *std.ArrayListUnmanaged(walk.Deferred)) ![ return dumpWith(p, deferred); } -/// `dumpJoin`'s under screen state and `dumpExit`'s: a terminal dumps its -/// size, not its emulator. +/// `dumpExit`'s: a terminal dumps its size, not its emulator. pub var slim_terminals = false; /// `dumpJoin`'s: a plain kind's pane carries its file (SlotRecord.file), /// read with this io. diff --git a/core/echo.zig b/core/echo.zig index e2a6521c..3b59788d 100644 --- a/core/echo.zig +++ b/core/echo.zig @@ -49,7 +49,7 @@ const never = std.math.maxInt(u64); const max = 64; /// A cell predicted: `cp` at column `x` of absolute row `row` (the -/// authority's numbering, screen_state's), a space for a cell backspace +/// authority's numbering), a space for a cell backspace /// cleared; `was` what the screen showed there before; `seq` the key's. pub const Cell = struct { x: u16, row: u64, cp: u21, was: u21, seq: u32, due: u64 = never }; pub const Cursor = struct { x: u16, row: u64, seq: u32, due: u64 = never }; diff --git a/core/panes.zig b/core/panes.zig index d58bf30b..a2e383c1 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -134,11 +134,6 @@ pub const Pane = struct { /// cell), and its kitty graphics drawn as glyph art (Petscii). term_mouse: ?Term.Coordinate = null, term_petscii: bool = false, - /// Whether its terminal holds a kitty image, as the session's emulator - /// said after its program's last output (taped under screen state: a - /// client's emulator is fed the session's cells, never an image). Its - /// tag says so (tagline.zig), on every side. - term_images: bool = false, gpa: std.mem.Allocator, serial: u32 = 0, /// What the control filesystem keeps of this pane -- addr and limit, the @@ -642,7 +637,6 @@ pub const Pane = struct { } } else if (pane.addon == null) { // the vt scrolls in SHELL rows; convert through the edit buffer - if (tape.viewOnly("scroll a terminal")) return; const state = pane.terminal orelse return; const off: i32 = @intCast(Term.grid(state).offset); Term.scroll(state, pane.gridRow(pane.surfRow(off) + delta) - off); @@ -743,12 +737,6 @@ pub const Pane = struct { const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.active or pane.body.nsel > 0 or pane.body.last_edit != null or pane.look_at != null or pane.body.ed_undo_len > 0 or pane.body.ed_redo_len > 0 or pane.pointerRowCount() > 0; - // A replica's emulator is what the authority's deltas make it; what - // pardes keeps over it moves as the authority's feed told it. - if (tape.screenReplica()) { - if (has_positions and pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost); - return; - } // Sticky bottom, as every other terminal does it: output drags the // viewport down only when the viewport was already on the last row, // so a reader scrolled back into the scrollback stays where they @@ -768,7 +756,6 @@ pub const Pane = struct { /// pointer's rows) moved as the rows move (`Term.Told`). True when one /// could not be kept (no memory for its pin). fn followRows(pane: *Pane, state: *Term.State, bytes: []const u8) bool { - const on_replica = tape.screenReplica(); const Group = struct { overlay: ?*Text.EditBuffer, cursor: *i32, selection: *Text.CharSel }; var groups: [Text.history_max * 2 + 1]Group = undefined; groups[0] = .{ @@ -879,13 +866,7 @@ pub const Pane = struct { track[k] = at.grid; k += 1; }; - // A replica's emulator is fed by its authority's deltas: it is told - // what the authority's feed told. - const fed: Term.Told = if (on_replica) told: { - @memset(rows_after, 0); - @memset(erased_after, false); - break :told .{ .rows = rows_after, .erased = erased_after, .cleared = false, .alive = false, .failed = false }; - } else Term.feed(state, bytes, track, rows_after, erased_after); + const fed = Term.feed(state, bytes, track, rows_after, erased_after); const after = tape.value(.positions, keepTold, .{Term.Told{ .rows = fed.rows, .erased = fed.erased, .cleared = fed.cleared, .alive = fed.alive, .failed = failed or fed.failed }}); if (after.rows.len != n or after.erased.len != n) return false; // a replica its authority's states apart (diverged) failed = after.failed; @@ -967,7 +948,7 @@ pub const Pane = struct { } fn feedLost(state: *Term.State, bytes: []const u8) bool { - if (!tape.screenReplica()) _ = Term.feed(state, bytes, &.{}, &.{}, &.{}); + _ = Term.feed(state, bytes, &.{}, &.{}, &.{}); return true; } @@ -981,14 +962,11 @@ pub const Pane = struct { /// Its terminal's view snapped back onto live output. pub fn followOutput(pane: *Pane) void { - if (tape.viewOnly("follow a terminal")) return; const state = pane.terminal orelse return; Term.follow(state); } - /// Its terminal's grid reflowed to `cols` by `rows`: on a screen-state - /// replica by its authority (the next delta says), on such an authority - /// once the step's unit is out (`resizeDeferred`). + /// Its terminal's grid reflowed to `cols` by `rows`. pub fn resizeGrid(pane: *Pane, cols: u16, rows: u16) void { // A client's speculation does what its replay does (its // selections) but the grid: it waits for no round trip. Under bytes @@ -999,7 +977,6 @@ pub const Pane = struct { pane.clearPointerSelection(button); pane.sel[button].state = .none; }; - if (tape.screenReplica()) return; if (tape.speculating()) return tape.touchTerminal(); Term.resize(state, cols, rows); } @@ -1152,7 +1129,6 @@ pub const positions_lost = "terminal edit position reset: out of memory"; /// session's snapshot's hash is taped, and each replica's own compared /// with it: a check of the whole emulator at every join. pub fn reloadTerminals(p: *Pardes) void { - if (tape.screenState()) return; for (p.panes) |slot| if (slot) |pane| if (pane.terminal) |state| { if (!tape.value(.reload, written, .{state})) continue; // Its cells' size in pixels as a feed sets it (`feedOutput`): a diff --git a/core/replica.zig b/core/replica.zig index 55e7a1f7..e9e29de0 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -4053,7 +4053,6 @@ test "bytes: a client joins from a dump with its terminals whole, and every side try std.testing.expect(pardes.Term.writes != reloads); const late = try Replica.initDump(gpa, 2, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); defer late.deinit(); - late.t.screen_state = false; late.core().echo = null; try std.testing.expectEqual(joined.digest, late.digest()); b.a.output(.{ .output = .{ .pane = b.shell, .bytes = ";30mthe rest of it\x1b[0m\r\n" } }); @@ -4377,7 +4376,6 @@ test "bytes: a join reloads only the terminals written since their last reload: try std.testing.expectEqual(2, pardes.Term.reloads.n - before); const late = try Replica.initDump(gpa, 3, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); defer late.deinit(); - late.t.screen_state = false; late.core().echo = null; try std.testing.expectEqual(joined.digest, late.digest()); // Output into both until each has pruned its history (whole pages, by @@ -7190,7 +7188,6 @@ test "a client joined from a dump takes a 9P pty/run in a shell as the session d r.confirm(joined.unit); const late = try Replica.initDump(gpa, 2, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); defer late.deinit(); - late.t.screen_state = false; late.core().echo = null; try std.testing.expectEqual(joined.digest, late.digest()); const node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_run); @@ -7376,7 +7373,6 @@ const NinepJoin = struct { const joined = (try n.a.join(1, null)).?; defer std.testing.allocator.free(joined.dump); const r = try Replica.initDump(std.testing.allocator, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); - r.t.screen_state = false; r.core().echo = null; n.late = r; try std.testing.expectEqual(joined.digest, r.digest()); diff --git a/core/tagline.zig b/core/tagline.zig index 26f83fba..02d1b277 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -160,7 +160,7 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co if (pane.terminal != null) { const chosen = pane.term_petscii; const on = chosen or !p.view().frontend.native_images; - if (chosen or pane.term_images) + if (chosen or pardes.Term.hasImages(pane.terminal)) return std.fmt.allocPrint(arena, "{s} petscii:{s}", .{ (try shownDir(arena, pane)), if (on) "on" else "off" }); } return (try shownDir(arena, pane)); diff --git a/core/tape.zig b/core/tape.zig index 5056f225..1cbf8aed 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -140,9 +140,6 @@ pub const Site = enum(u16) { /// A kitty image's medium as a terminal's emulator read it (a file, a /// temporary file, shared memory: Term.media), its bytes or its failure. medium, - /// Whether a terminal holds a kitty image after its program's output - /// (Pane.term_images): a screen-state replica's emulator never has one. - images, }; /// What the sites return. wire.semantics hashes their shape with the @@ -311,13 +308,6 @@ pub const Tape = struct { dump_check: bool = false, dumps: usize = 0, dump_bytes: usize = 0, - /// Screen-state terminals (core/term/screen_state.zig, docs/next-daemon.md - /// phase 5): an authority recording for replicas, or a replica. A - /// terminal's emulator is the authority's alone: its output is recorded - /// without its bytes (they cross as screen state), its pty writes are - /// not recorded, and no digest covers it. A replica's core never writes - /// one but by `apply`. - screen_state: bool = false, /// The session's (replica.Peers): called between two of its inputs once /// what it recorded since its last unit passes `unit_max`, to send that /// as a unit: a pump of a flood's reads is cut into units under it. @@ -423,12 +413,7 @@ pub const Tape = struct { t.noteWrites(); t.noteHost(core); } - // A terminal's output crosses as screen state, not as its bytes. - if (t.screen_state and input.* == .update and input.update.args[0] == .output) { - var bare = input.*; - bare.update.args[0].output.bytes = &.{}; - t.record(.input, Input, &bare); - } else t.record(.input, Input, input); + t.record(.input, Input, input); return .{ .tape = t }; } @@ -806,12 +791,12 @@ pub const Tape = struct { // output) is the session's answer, kept, and a replica whose // emulators are fed the same bytes asks its own and compares: a // check a unit, for nothing (P30: a digest, not state). - if (comptime s == .positions or s == .prompt) if (!t.screen_state) { + if (comptime s == .positions or s == .prompt) { const mine = @call(.auto, f, full); t.scratch.clearRetainingCapacity(); walk.encode(R, &mine, &t.scratch.writer) catch @panic("tape: out of memory"); if (!std.mem.eql(u8, t.scratch.written(), t.last_ret.bytes[t.last_ret.at..])) t.diverge("what this replica's terminal told ({t}) is not what the session's did", .{s}); - }; + } var ret = t.last_ret; return walk.decode(R, &ret, a orelse t.arena.allocator()) catch { t.diverge("the tape's answer to {t} is short", .{s}); @@ -885,17 +870,6 @@ pub const Tape = struct { return t.depth > 0 or t.replay or t.speculating; } - /// A replica's core under screen-state terminals: its emulators are - /// written by `apply` alone, never by its own steps. - pub fn screenReplica(t: *const Tape) bool { - return t.screen_state and (t.replay or t.speculating); - } - - /// An authority recording for screen-state replicas. - pub fn screenAuthority(t: *const Tape) bool { - return t.screen_state and !t.replay and !t.speculating; - } - /// What a speculation reached is the authority's (`why`): the input is /// undone and waits for the authority's order. pub fn poison(t: *Tape, why: []const u8) void { @@ -913,14 +887,6 @@ pub const Tape = struct { return true; } - /// A speculation that moves a terminal's view: it may (its rollback - /// puts the view back, replica.zig `views`); a screen-state replica's - /// says it did (a delta sets the view again). - pub fn viewOnly(t: *Tape, comptime _: []const u8) bool { - if (t.speculating and t.screen_state) t.touched = true; - return false; - } - /// A speculation read a terminal's rows or moved its view (`Tape.touched`). pub fn touchTerminal(t: *Tape) void { if (t.speculating) t.touched = true; @@ -1356,19 +1322,6 @@ pub fn stepping() bool { return (on orelse &none).stepping(); } -/// Screen-state terminals, on either side (`Tape.screen_state`). -pub fn screenState() bool { - return (on orelse &none).screen_state; -} - -pub fn screenReplica() bool { - return (on orelse &none).screenReplica(); -} - -pub fn screenAuthority() bool { - return (on orelse &none).screenAuthority(); -} - pub fn poison(why: []const u8) void { (on orelse &none).poison(why); } @@ -1383,10 +1336,6 @@ pub fn authorityOnly(comptime why: []const u8) bool { return (on orelse &none).authorityOnly(why); } -pub fn viewOnly(comptime why: []const u8) bool { - return (on orelse &none).viewOnly(why); -} - pub fn touchTerminal() void { (on orelse &none).touchTerminal(); } diff --git a/core/term/terminal.zig b/core/term/terminal.zig index 1c54f2ac..f130d7b9 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -211,7 +211,8 @@ pub fn digest(s: *const State, h: *std.hash.Wyhash, view: bool) void { const sb = screen.pages.scrollbar(); const cur = screen.cursor; const offset = if (view) sb.offset else 0; - const facts = .{ sb.total, offset, sb.len, cur.x, cur.y, s.vt.modes.get(.cursor_visible), s.vt.screens.active_key, s.reply_dropped }; + // Whether it holds a kitty image: the tag says so (tagline.zig). + const facts = .{ sb.total, offset, sb.len, cur.x, cur.y, s.vt.modes.get(.cursor_visible), s.vt.screens.active_key, s.reply_dropped, hasImages(s) }; inline for (facts) |fact| h.update(std.mem.asBytes(&fact)); h.update(s.reply[0..s.reply_len]); var buf: [4096]u8 = undefined; diff --git a/test/replicas.zig b/test/replicas.zig index f4d8d450..90f7c10d 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -984,7 +984,6 @@ const Witness = struct { // No client's id: every unit is another's. const rp = try replica.Replica.initDump(gpa, std.math.maxInt(u16), d.view, d.bytes, .{ .cols = d.cols, .rows = d.rows, .distrusted = &distrusted }); rp.guess = false; - rp.t.screen_state = false; rp.core().echo = null; rp.t.local_files = true; return rp; @@ -1950,7 +1949,6 @@ const Soak = struct { } } // Its terminals its own emulators, fed what the units carry. - rp.t.screen_state = false; rp.core().echo = null; rp.stats.samples = true; rp.t.local_files = true; @@ -3533,7 +3531,6 @@ fn corpusCase(dir: []const u8) !bool { defer gpa.free(j.dump); const rp = try replica.Replica.initDump(gpa, 1, j.view, j.dump, .{ .cols = 100, .rows = 22 }); defer rp.deinit(); - rp.t.screen_state = false; var fds: [2]c_int = undefined; if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket; defer for (fds) |fd| { -- cgit v1.3