diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 18:35:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-19 20:24:14 -0300 |
| commit | bf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (patch) | |
| tree | ed415f31749669a36d5df304af4101f56e9fdd23 /core/replica.zig | |
| parent | 78d94c4a62ec3f4039a475b637ff6a60649fde52 (diff) | |
| download | pardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.tar.gz pardes-bf351b62e8843a3d173cedeefa2dd0b8ef4b4392.zip | |
core, dev: what carries a slot across the core's edge carries its type (P21, pardes-ids change 3): `Pane.Id` in Event's six variants that carry a pane (output, eof, exited, file_changed, addon, job), in the fourteen effects that do (spawn, write, resize_pty, signal_pty, close_pty, start, save_file, save_text, lsp, watch, dump_themes, detach, addon, job), in the fourteen Host functions that take one (dev/Host.zig: adopt, upgrade, spawn, pty_write, pty_resize, pty_signal, close_pty, tty_taken, fg_name, kill_job, write_file, watch_file, dump_themes, job; tape.zig's Wrap follows with no edit), in the device messages that carry one into the core (the inbox's output and eof and the five reader functions that make them, dev/Lsp.zig's Request, host_io's Adoption and Adoptions.take, which hold what adoptShell answered); `View.Id` in abi/wire.zig's welcome.view (its bytes on the wire unchanged: one byte, hand-encoded, `.at(takeByte())`/`writeByte(view.index())`); every producer converts at its own line (`.pane = .at(id)`, a script that refuses any path outside the workspace, `fields.py`), every consumer where it indexes or compares (`o.pane.index()`), every Host implementer at its own first line (`fn spawn(ctx, id: pardes.Pane.Id, ..) { const pane = id.index(); ..}`: the terminal's 14, the window's 14, the Mac's 10, and the tests' hosts), and an id that went integer and back is passed through whole (`s.core.readerFailed(e.pane, err)`); the compiler caught no pane's slot passed as a view's or the reverse, only integers meeting the type; kept integers on purpose: KindJob.pane (core/Kind.zig, another agent's, reads it four times; converted at KindJob's and Effect's lines), the Watch table (file_watch: its last slot is the theme's, no pane), the hello's view and the replica's Peer/Joined/Replica views (core/replica.zig, another agent's), the C ABI's `pardes_watch_changed(uint8_t pane)` (abi/pardes.h unchanged; runtime/macos.zig converts at its Host functions); in files another agent is in, each conversion on the line that was there: core/Kind.zig 2 lines, core/Addon.zig 4, core/replica.zig 31 (the welcome's view, 3 test hosts, test literals), test/replicas.zig 12 (4 host functions with their first lines, 1 signature, the welcome's view, 5 literals); the tape's shape moves (Event is update's input), so the semantics word moves, c47ecf638b3f4b9f -> 38b5ae573b965550; test/perf.zig follows on 6 lines its Event and effect literals forced, so its harness id moves, be7cc504010471bc -> 1ed95030eb768eae (unit-test's perf check was BaselineHarnessMismatch already); 607 lines added, 562 deleted in 48 files. Gate (load 4 to 8): tui core-test 841/984 (143 skipped), shell-test 1020/1023, term-test 15/15, pane-test 183/184, kitty-test 45/45, behaviour-test 275/275 and --replay 20 seeds of 70 steps, 0 failures, process-test lspcomplete and lspcompletemoved (the base's; hscroll failed once and passed on the runner's retry), gui unit-test 1618/1622 (BaselineHarnessMismatch, the base's); replicas --clients 5 (TMPDIR /tmp/claude-1000/ids): diverged 0, unequal 0 at rtt 30, 80, 207, deltas checked/wrong 1811/0, 1838/0, 1660/0, quiet checks 567/0, 650/0, 655/0, stops not on may_wait 0 (corpus through a client fails at step 21 as on the base with that TMPDIR); daemon.py plain, --far, --games, --window-clients, --upgrade both ways against pardes-tree's base prefix pass (the semantics words differ: the upgrade carries the session by its dump); test/cross_replay.py (tui records, gui replays): 27 digests agree in each of three replicas; rollback-bench runs; the macOS library for Linux and aarch64-macos and the FreeBSD cross-build build; frames (gpu/ids-3 against tree1) 77/77 byte-identical in Debug, unit-test 1618/1622 there, perfab corpus2x -0.021% (session noise 0.036%, threshold 0.4%), pictures identical in all 10 runs, perfops 97 counts within 0.1% (largest image-frame on longline +0.0231%), key-down on medium 10,040,108 -> 10,039,990 an operation (-0.0012%), render on medium 11,455,765 -> 11,455,683 (-0.0007%), terminal on all +0.0030%
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/core/replica.zig b/core/replica.zig index 625153d1..3f04b3bc 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2278,7 +2278,7 @@ pub const Peers = struct { if (ps.next_id == 0) ps.next_id = 1; // The session's digest as dumped, for the joiner to check its load by. const digest = tape.digestOf(core); - peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; + peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null; if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null; if (ps.threads and (peer.writer == null or peer.reader == null)) { @@ -2591,7 +2591,7 @@ fn joinOn(gpa: Allocator, fd: c_int, session: []const u8, why: []u8, have: ?*Hav .welcome => |w| { r.j.pid = w.pid; r.j.client = w.client; - r.j.view = w.view; + r.j.view = w.view.index(); r.j.gmtoff = w.gmtoff; r.j.digest = w.digest; r.j.semantics = w.semantics; @@ -3292,7 +3292,7 @@ const TestHost = struct { /// A host with ptys whose pump polls for a frame, as a client's does. const PtyHost = struct { - fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {} + fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {} fn poll(_: ?*anyopaque) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll }; fn host() pardes.Host { @@ -3729,7 +3729,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st for (0..3) |round| { // The shell prints: its unit rolls the replica back and applies the // key again; then its delta lands, under the new copy. - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); r.confirm((try a.pending()).?); r.settle(); try std.testing.expect(r.copy.held); @@ -3751,7 +3751,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st r.confirm(try a.local(.{ .focus = false })); _ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); try key(r, 'x', &sent); - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -3875,7 +3875,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, // History the replica holds as holes, of lines a narrow grid wraps in // two, which a wider one unwraps. var line: [96]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); r.confirm((try a.pending()).?); // Out of terminal mode in the session's view, which sizes it; then a // client's own view (a copy of it), wider: its first key sizes the @@ -3954,7 +3954,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [64]u8 = undefined; - for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); + for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); r.settle(); @@ -3977,7 +3977,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves // The shell prints while they wait: its unit, then its delta, which // sets the view the authority's (at the bottom still): what was applied // goes on top of it again. - for (0..5) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); + for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4043,7 +4043,7 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [96]u8 = undefined; - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); // Out of the shell's tty mode, in the session's view: keys over its text. @@ -4061,8 +4061,8 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca r.settle(); } // The program redraws the screen: other rows where those keys read. - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[H\x1b[2J" } }); - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4174,7 +4174,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &zon } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &zon } }); const r = try joinedNow(a, 1, 0); defer r.deinit(); try std.testing.expectEqual(digestOf(a), r.digest()); @@ -4703,7 +4703,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli } else return error.NoShell; a.core.view().active = shell; var line: [64]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); const out = try gpa.dupe(u8, (try a.pending()).?); defer gpa.free(out); for ([_]*Replica{ r1, r2 }) |r| r.confirm(out); @@ -4733,7 +4733,7 @@ test "a replica with no code for a kind whose state is not plain shows its pane // replica's core takes the kind's words, never its code. var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } })); r.confirm(try a.local(.{ .command = "Counter" })); try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null); try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client")); @@ -4791,7 +4791,7 @@ test "a kind's place moved in a step of another view's: a replica's key that rea defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // The replica's view opens the kind's pane, and an Esc goes back to // the file (Last): view 0 has the file. const own = try a.openView(1); @@ -4845,7 +4845,7 @@ test "a client joined from a dump numbers a kind's next job as the session does" defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &jobber } }); _ = try a.local(.{ .command = "Jobber" }); for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } }); const id = a.core.view().active; @@ -4864,7 +4864,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // Its replica has no code for the kind: the open's outcome (its place, // `1:0 0`) is the authority's to say. const msg = try gpa.dupe(u8, try r.input(.{ .command = "Placed" })); @@ -4883,7 +4883,7 @@ test "a client joined from a dump tells a kind each view's facts as the session defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }); _ = try a.local(.{ .command = "Placed" }); // A message in its pane: a band over its body, in each view. _ = try a.local(.{ .command = "Placed x" }); @@ -4937,7 +4937,8 @@ const Asker = struct { const BusyHost = struct { var core: ?*Pardes = null; var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity }; - fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(_: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never); } fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void { @@ -4955,7 +4956,7 @@ test "a kind's job answered at once inside its host's call (no worker free) is t defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &asker } })); // The client has its code (as a library of its own found by its scan). r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops; r.confirm(try a.local(.{ .command = "Asker" })); @@ -4981,7 +4982,7 @@ test "a closed terminal with a kitty image brought back on a client: its image d } else return error.NoShell; // A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA // of its own (TerminalImages.converted). - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); r.confirm((try a.pending()).?); // Closed and brought back: the client loads the session's dump of it, // its image with it. @@ -5034,7 +5035,7 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } }); _ = try a.local(.{ .command = "Counter" }); // Joined from the dump: the kind's pane is a line here (no code), its // slot the dump's. @@ -5101,7 +5102,7 @@ const SeenHost = struct { of(ctx).linked += 1; } fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {} - fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {} + fn watchFile(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: bool, _: pardes.WatchMode) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile }; fn host(h: *SeenHost) pardes.Host { return .{ .ctx = h, .vtable = &vtable }; @@ -5256,7 +5257,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd))); var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); // The kind's pane, its +Search (a place a row, as a kind's `/` leaves // it), and a scratch whose words name files in the session's directory // (as a command's output would). @@ -5563,14 +5564,14 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' if (slot) |pane| if (pane.isTerminal()) break id; } else null; if (shell) |id| { - a.output(.{ .output = .{ .pane = @intCast(id), .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(id), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; } _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/mise.toml", .{dir}) }); const file = a.core.view().active; var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); _ = try a.local(.{ .command = "Still" }); const kind = a.core.view().active; try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null); @@ -5670,7 +5671,7 @@ test "a far client's click into a shell whose program asked for focus events is const Told = struct { var bytes: [64]u8 = undefined; var len: usize = 0; - fn write(_: ?*anyopaque, _: u8, b: []const u8) void { + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { @memcpy(bytes[len..][0..b.len], b); len += b.len; } @@ -5682,7 +5683,7 @@ test "a far client's click into a shell whose program asked for focus events is const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); } else return error.NoShell; - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; _ = try a.local(.{ .command = "New" }); var screens: Screens = .init(gpa); |
