diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 16:50:34 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 16:53:19 -0300 |
| commit | 9863a63b614d200852853825031189364dcacfdc (patch) | |
| tree | d235648a2ac14b3e311746ced3433ed6865e2061 /abi | |
| parent | 6544f73a6b50e5ba68564beea7784593bb54348e (diff) | |
| parent | bad506bd45846e012246a33b5d3097b3e92f02bc (diff) | |
| download | pardes-9863a63b614d200852853825031189364dcacfdc.tar.gz pardes-9863a63b614d200852853825031189364dcacfdc.zip | |
integration: the old road deleted and the emulator's boundary on the gathered line: pardes-merge56 (`qvwrwxtu`: the installed tree and the source view's changes to their last slice) and pardes-term-join-9 (`twssqzqw`, fourteen changes on pardes-merge55: every client's terminals by the pty's bytes and nothing else: the delta protocol, its flow control and core/term/screen_state.zig deleted (-3,605 +504 lines), the wire at 30, one soak; S1: abi/term.zig's Ops in replicated and local, the terminal's digest covering what a step reads, every call of the core's into a terminal listed with its rule as a test; a client's own join again judged after its goodbye; a pty's size one fact the core hands its host for every fork, adopt and resize; a closed view sizes no terminal); no textual conflict; one semantic one, resolved here: core/jj.zig's Churn test (the layers' last round) called Authority.init and Replica.init with the road's flag the deletion took away: the argument removed; core-test 916/1073 (157 skipped), shell-test 1115/1118; its gate: .scratch/sketch/reorg/merge57, the numbers in PARDES.md (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'abi')
| -rw-r--r-- | abi/term.zig | 114 | ||||
| -rw-r--r-- | abi/wire.zig | 38 |
2 files changed, 48 insertions, 104 deletions
diff --git a/abi/term.zig b/abi/term.zig index 187b99e5..d6c48f96 100644 --- a/abi/term.zig +++ b/abi/term.zig @@ -1,8 +1,8 @@ //! The terminal as the core sees it (docs/next-terminal.md, Phase 1): the //! entries (`Ops`) a terminal module gives the core, and the records they -//! take and give. A terminal's state, its replicas' encoder and tracks are -//! handles the core holds and never looks into; what it knows of them it is -//! told here, as numbers, bytes, text and cells. core/term/term.zig is the +//! take and give. A terminal's state is a handle the core holds and never +//! looks into; what it knows of it it is told here, as numbers, bytes, text +//! and cells. core/term/term.zig is the //! one implementation (ghostty-vt behind it); core/Term.zig is the core's //! side of it. const std = @import("std"); @@ -12,12 +12,6 @@ const CellStyle = plain.CellStyle; /// A terminal: its emulator, its parse and what is kept beside it. pub const State = opaque {}; -/// What a session's authority keeps to encode its terminals for its peers -/// (one for all of them), and what it keeps of one terminal for them. -pub const Encoder = opaque {}; -pub const Track = opaque {}; -/// A replica's side of one terminal: what it was sent. -pub const Replica = opaque {}; /// Where the view and the cursor are, in rows counted from the top of the /// history: `total` rows, the view's top at `offset`, `len` of them shown. @@ -35,7 +29,7 @@ pub const Grid = struct { /// The view's top row while it is scrolled to one, null while it /// follows the output. view: ?usize = null, - /// Its grid's width (a pane's may differ while a resize is deferred). + /// Its grid's width. cols: u16 = 0, }; @@ -240,50 +234,6 @@ pub const ImagesAt = struct { /// marked it input, and its style's identity. pub const EchoCell = struct { cp: u21, input: bool, style: u32 }; -// ---- its replicas ---- - -/// Deltas a peer may have in flight. At 207 ms and 60 frames a second about -/// 13 are; past the bound a peer gets nothing until an acknowledgement, and -/// then the newest state, the ones between skipped. -pub const flight_bound = 32; - -/// What the authority knows of one peer of one terminal. -pub const Peer = struct { - /// The version last sent, which the next delta is against; 0: none, so - /// the next starts the replica afresh. - sent: u32 = 0, - /// The versions in flight, oldest first. - flight: [flight_bound]u32 = undefined, - n: u8 = 0, - /// The history rows its replica holds as holes, absolute, as the - /// replica keeps them (Replica.apply's rule, from what it was sent): - /// what `fill` sends before a step reads them. - top: u64 = 0, - holes: std.ArrayListUnmanaged([2]u64) = .empty, - - pub fn deinit(peer: *Peer, gpa: std.mem.Allocator) void { - peer.holes.deinit(gpa); - } - - /// Every version up to `seq` has landed. - pub fn ack(peer: *Peer, seq: u32) void { - var i: u8 = 0; - while (i < peer.n and peer.flight[i] <= seq) i += 1; - std.mem.copyForwards(u32, peer.flight[0 .. peer.n - i], peer.flight[i..peer.n]); - peer.n -= i; - } - - /// Start the peer afresh: it lost its state, or never had one. - pub fn reset(peer: *Peer) void { - var holes = peer.holes; - holes.clearRetainingCapacity(); - peer.* = .{ .holes = holes }; - } -}; - -/// A delta applied: its version, and what its authority sent beside it. -pub const Applied = struct { seq: u32, extra: []const u8 }; - /// What the dump keeps of a terminal beside its emulator, by name as every /// dump is (core/walk.zig, through the core's `Term.State`). pub const Parts = struct { @@ -368,8 +318,7 @@ pub const Ops = struct { viewTo: *const fn (s: *State, at: ?usize) void, scroll: *const fn (s: *State, delta: i32) void, follow: *const fn (s: *State) void, - resize: *const fn (s: *State, cols: u16, rows: u16, later: bool) void, - resizeDeferred: *const fn (s: *State) bool, + resize: *const fn (s: *State, cols: u16, rows: u16) void, cellPixels: *const fn (s: *State, w: u32, h: u32) void, replies: *const fn (s: *State) []const u8, @@ -397,7 +346,6 @@ pub const Ops = struct { /// How much of its row `row` (from the top of its history) the prompt /// it starts with is; null for a row no prompt starts. promptCut: *const fn (s: *State, row: i32) ?PromptCut, - markRead: *const fn (s: *State) void, /// What a predicted echo reads of cell `x`, `y` of its active area. echoCell: *const fn (s: *const State, x: u16, y: u16) ?EchoCell, @@ -419,28 +367,34 @@ pub const Ops = struct { /// placeholder cells blanked in `frame` (`frame_cols` wide). images: *const fn (s: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.ArrayList(plain.Placement), frame: []plain.Cell, frame_cols: u16) void, hasImages: *const fn (s: ?*const State) bool, +}; - // ---- its replicas ---- - encoder: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Encoder, - encoderFree: *const fn (e: *Encoder) void, - track: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Track, - /// A peer's track of it let go (`s` null: it is gone). - untrack: *const fn (t: *Track, gpa: std.mem.Allocator, s: ?*State) void, - /// What a peer is owed of it, a delta against what the peer was sent. - encode: *const fn (s: *State, e: *Encoder, t: *Track, peer: *Peer, out: *std.Io.Writer) anyerror!bool, - /// Rows of it a replica holds as holes. - encodeRows: *const fn (s: *State, e: *Encoder, t: *Track, lo: u64, hi: u64, out: *std.Io.Writer) anyerror!void, - wasRead: *const fn (s: *const State) bool, - clearRead: *const fn (s: *State) void, - replica: *const fn (gpa: std.mem.Allocator) error{OutOfMemory}!*Replica, - replicaFree: *const fn (r: *Replica, gpa: std.mem.Allocator) void, - /// The absolute row its replica's active area begins at. - replicaTop: *const fn (r: *const Replica) u64, - /// History rows `lo..hi` it does not hold. - missing: *const fn (r: *const Replica, lo: u64, hi: u64, out: *std.ArrayList([2]u64), gpa: std.mem.Allocator) error{OutOfMemory}!void, - apply: *const fn (s: *State, r: *Replica, bytes: []const u8) anyerror!Applied, - applyRows: *const fn (s: *State, r: *Replica, bytes: []const u8) anyerror!void, - shown: *const fn (s: *State, r: *const Replica) [2]u64, - blank: *const fn (s: *State, r: *const Replica, lo: u64, hi: u64) void, - dumpScreen: *const fn (s: *State, w: *std.Io.Writer) error{WriteFailed}!void, +/// `Ops` in its two groups (S1: the emulator's boundary). REPLICATED: what +/// every side agrees on by construction, each side's emulator fed the same +/// bytes in the tape's order: written only by a step or a load, read by a +/// step as the terminal's digest covers it (core/term/terminal.zig +/// `digest`), or by a draw. LOCAL: this process's own (its frontend's cell +/// size, the pixels and images it draws, its next wake, the module's start +/// and its allocator), never what a step's digested state is computed from. +/// core/Term.zig's `calls` lists every call of the core's into either, by +/// file, with its rule: a new one fails its test until it is listed. +pub const replicated = [_][]const u8{ + "open", "close", "revive", "digest", "parts", "snapshot", "load", "reload", + "media", "feed", "grid", "viewTo", "scroll", "follow", "resize", "replies", + "key", "mouse", "wheel", "paste", "modes", "promptMoves", "prompt", "commandOutput", + "endOutputHere", "scrollback", "scrollbackLen", "textRows", "viewport", "editRows", "promptCut", "page", + "filter", "spanColor", "hasImages", }; +pub const local = [_][]const u8{ "start", "stop", "gpa", "due", "cellPixels", "echoCell", "paint", "images" }; + +comptime { + @setEvalBranchQuota(100_000); + for (@typeInfo(Ops).@"struct".field_names) |fname| { + var n = 0; + for (replicated ++ local) |name| { + if (std.mem.eql(u8, name, fname)) n += 1; + } + if (n != 1) @compileError("term.Ops." ++ fname ++ ": in neither group or in both (abi/term.zig `replicated`, `local`): say which, and why"); + } + for (replicated ++ local) |name| if (!@hasField(Ops, name)) @compileError("term.Ops has no " ++ name); +} diff --git a/abi/wire.zig b/abi/wire.zig index f87131bf..8f7a7bdb 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -10,6 +10,11 @@ const pardes = @import("core"); 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), +/// 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 @@ -54,7 +59,7 @@ const build_info = @import("build_info"); /// part B); 14: the hello names a session and /// carries the semantics hash, and a ping is answered (phase 5's /// groundwork); 13: the frames went (phase 3). -pub const version: u16 = 29; +pub const version: u16 = 30; /// The terminal's build and the window's step alike (`semantics`). const family = switch (config.platform) { @@ -113,9 +118,6 @@ pub const ClientTag = enum(u8) { hello = 0x01, bye = 0x02, ping = 0x03, - /// A replica's word about a terminal's state (core/term/screen_state.zig): the - /// delta it holds, or rows it asks for. Opaque here. - screen_ack = 0x04, /// What is the session's digest, in stream order (a replica checks /// itself against it once quiet). check = 0x05, @@ -201,9 +203,6 @@ pub const ServerTag = enum(u8) { /// A unit of the authority's stream (core/replica.zig): its origin, seq, /// clocks and tape. unit = 0x05, - /// A terminal's delta, or rows asked for (core/term/screen_state.zig), applied - /// before the next unit. Opaque here. - screen = 0x06, /// The session's digest (u64le), after every unit before it. check = 0x07, /// Part of the join's list of blobs, to a far client: each one's place @@ -227,12 +226,11 @@ pub const ServerMsg = union(ServerTag) { /// dump that follows is, and the session's offset from UTC (a replica /// guesses the session's time of day). A far client is told how many /// blobs the dump holds (`blobs`). - welcome: struct { pid: u32, session: []const u8, client: u16 = 0, view: pardes.Pardes.View.Id = .at(0), dump_len: u64 = 0, gmtoff: i32 = 0, digest: u64 = 0, semantics: u64 = 0, bytes: bool = false, blobs: u32 = 0 }, + welcome: struct { pid: u32, session: []const u8, client: u16 = 0, view: pardes.Pardes.View.Id = .at(0), dump_len: u64 = 0, gmtoff: i32 = 0, digest: u64 = 0, semantics: u64 = 0, blobs: u32 = 0 }, refused: []const u8, pong: u64, dump: []const u8, unit: []const u8, - screen: []const u8, check: u64, blobs: []const u8, zstd: []const u8, @@ -263,14 +261,12 @@ pub fn decodeServer(tag: u8, payload: []const u8) Error!ServerMsg { .gmtoff = try r.takeInt(i32, .little), .digest = try r.takeInt(u64, .little), .semantics = try r.takeInt(u64, .little), - .bytes = try r.takeByte() != 0, .blobs = try r.takeInt(u32, .little), } }, .refused => .{ .refused = try r.take(try r.takeInt(u16, .little)) }, .pong => .{ .pong = try r.takeInt(u64, .little) }, .dump => return .{ .dump = payload }, .unit => return .{ .unit = payload }, - .screen => return .{ .screen = payload }, .check => .{ .check = try r.takeInt(u64, .little) }, .blobs => return .{ .blobs = payload }, .zstd => return .{ .zstd = payload }, @@ -295,12 +291,11 @@ pub fn encodeServer(out: []u8, msg: ServerMsg) Error![]const u8 { try w.writeInt(i32, h.gmtoff, .little); try w.writeInt(u64, h.digest, .little); try w.writeInt(u64, h.semantics, .little); - try w.writeByte(@intFromBool(h.bytes)); try w.writeInt(u32, h.blobs, .little); }, .refused => |words| try putSlice16(&w, words), .pong => |v| try w.writeInt(u64, v, .little), - .dump, .unit, .screen, .blobs, .zstd, .blob => |bytes| try w.writeAll(bytes), + .dump, .unit, .blobs, .zstd, .blob => |bytes| try w.writeAll(bytes), .check => |v| try w.writeInt(u64, v, .little), .ended => |code| try w.writeByte(code), .left => |name| try putSlice16(&w, name), @@ -327,7 +322,6 @@ pub const ClientMsg = union(enum) { bye: struct { again: bool = false, close: bool = false }, /// A round trip's probe, answered `pong` with the same value. ping: u64, - screen_ack: []const u8, check, far: bool, want: []const u8, @@ -545,7 +539,7 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 { // 0 it leaves, 1 it joins again, 2 its window was closed. .bye => |b| try w.writeByte(if (b.close) 2 else @intFromBool(b.again)), .ping, .boot => |v| try w.writeInt(u64, v, .little), - .screen_ack, .want => |bytes| try w.writeAll(bytes), + .want => |bytes| try w.writeAll(bytes), .check => {}, .far => |far| try w.writeByte(@intFromBool(far)), .stamp => |s| for (s) |v| try w.writeInt(i64, v, .little), @@ -620,7 +614,6 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg { else => return error.BadValue, } }, .ping => .{ .ping = try r.takeInt(u64, .little) }, - .screen_ack => return .{ .screen_ack = payload }, .check => .check, .far => .{ .far = try getBool(&r) }, .want => return .{ .want = payload }, @@ -683,7 +676,7 @@ pub fn clientBound(msg: ClientMsg) usize { return msg_slack + switch (msg) { .hello => |h| h.session.len, .bye, .ping, .check, .far, .stamp, .boot => 0, - .screen_ack, .want => |bytes| bytes.len, + .want => |bytes| bytes.len, .event => |ev| switch (ev) { // Its hits' places (14 bytes each) past the slack. .mouse => 32, @@ -739,14 +732,13 @@ test "detached wire: every Event variant round-trips" { try testing.expectEqual(@as(u64, 0xfeed_beef_0000_0001), (try roundClient(&buf, .{ .ping = 0xfeed_beef_0000_0001 })).ping); { // The other way: framed the same, its tag the ServerTag's number. - const bytes = try encodeServer(&buf, .{ .welcome = .{ .pid = 42, .session = "work", .bytes = true } }); + const bytes = try encodeServer(&buf, .{ .welcome = .{ .pid = 42, .session = "work" } }); const f = (try framed(bytes)).?; try testing.expectEqual(@as(u8, 0x01), f.tag); - try testing.expectEqualSlices(u8, &.{ 42, 0, 0, 0, 4, 0, 'w', 'o', 'r', 'k', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, f.payload); + try testing.expectEqualSlices(u8, &.{ 42, 0, 0, 0, 4, 0, 'w', 'o', 'r', 'k', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, f.payload); const back = (try decodeServer(f.tag, f.payload)).welcome; try testing.expectEqualStrings("work", back.session); try testing.expectEqual(@as(u32, 42), back.pid); - try testing.expect(back.bytes); try testing.expectEqual(@as(u8, 0x03), (try framed(try encodeServer(&buf, .{ .pong = 7 }))).?.tag); } @@ -804,10 +796,8 @@ test "detached wire: a session is never told to do a frontend's remembering" { // them, and the machine that reports them is the one already holding the // core. const allowed = [_][]const u8{ - // Who this connection is, its round trip, and that it is finished, - // and which terminal state its replica holds (a protocol's word, - // as a ping is). - "hello", "bye", "ping", "screen_ack", "check", + // Who this connection is, its round trip, and that it is finished. + "hello", "bye", "ping", "check", // ...and how far it is, and which of the join's blobs it lacks. "far", "want", // ...and the digest of the core it made itself (a pair's). |
