summaryrefslogtreecommitdiff
path: root/core/Core.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 05:01:46 -0300
committerGabriel Schneider <[email protected]>2026-11-19 05:54:00 -0300
commit5b857bb55fae0a220f54b140bc1b46c3efb991bb (patch)
treeb7dc6411697229b6e26486f6e306f1c5d599ea30 /core/Core.zig
parent0a9546f1d206f4ab55063e1c26c668e9626b3929 (diff)
downloadpardes-5b857bb55fae0a220f54b140bc1b46c3efb991bb.tar.gz
pardes-5b857bb55fae0a220f54b140bc1b46c3efb991bb.zip
core: the session's facts are the core's state, read once at its start (the reorganisation's 12b, the design round's step 3; the user's ruling P16 and the lean put with P17: a far client's `~`, default shell and "is this shell installed" are the session's): its home (`~`) and the shell its terminals run when no `Shell` is set ($SHELL if executable, else /bin/sh) are fields beside `session_dir`, `session_home` and `session_shell` (working names, the user's to rule), each read once with `session_dir` by Pardes.readSessionFacts (tape.value(.env): a replay of the boot reads the session's answers), at the session's start and after a load of a dump made before they were dumped, and carried by the dump; `sessionDir` no longer fills itself at first use (it was filled at the start already), and a client's step reads the session's, never its own machine's: Pardes.expandHome (`~` the session's home; `~user` a passwd read, taped, as before) at Save, a tag's name, Theme's path, Get, Incl, a Look of `~/x`, a 9P name and pager, Dump's path, sam's B, e, r and w (sam_edit.World.home) and DumpDir's check (config.Runtime.apply takes the home); bare `Shell`, the shell a terminal runs, the settings report and its 9P twins read `session_shell`; "is this shell installed" (Shell <bin>, Term <bin>, a 9P exec) is a question to the session's disk, tape.site, so far away it waits a round trip instead of answering from the client's machine and rolling back; deleted: the value reads at config.defaultShell (now the process's read, made at the start alone) and at Core.sessionDir, and the tape's `cwd` tag (the directory is read under `env` at the start); fs.expandHome stays for this process's own home, the launcher's (runtime/main.zig) and the state file's directory and a Restore's name (the session's side: a client's Restore waits, its replay reads the tape); the tape's shape changes (`cwd` gone, `shell` a site), so the semantics word moves (the tape's shape now hashes the sites too: it did not see a site gone or added, and this change alone left it as it was), adacca2db2b39264 -> 517cd1c276996a3c: an old build and a new refuse each other's clients, in words; a test at the end of core/replica.zig (a joined client's own `Look ~/x`, bare `Shell` and Tutor, a word run in the session's directory, record no `env` read; the client's shell and directory are the session's), shown failing on the change before (`Look ~/x` read the environment); not handled: a Restore of a dump carries that dump's facts (as `session_dir` did); tui core-test 833/976 (143 skipped), shell-test 1011/1014, pane-test 183/184, behaviour-test 275/275 and --replay 275/275, process-test 2 of 144 failed (lspcomplete, lspcompletemoved, the base's; hscroll flaked once), replicas --clients 5 diverged 0 unequal 0 deltas wrong 0 quiet differ 0 at 30/80/207 ms, stopped 89/73/108, gui unit-test 1609/1613 (its perf check's BaselineHarnessMismatch the base's), daemon.py plain, --far, --games, --window-clients pass; gate-w seam-b-3 against tree1: 77/77 frames byte-identical in Debug, its unit-test 1609/1613, perfab corpus2x +0.095% (pictures identical in all 10 runs), perfops 97 counts within 0.1% (largest +0.0198%, body-appends on longline)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Core.zig')
-rw-r--r--core/Core.zig60
1 files changed, 49 insertions, 11 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 2036fd77..398d5973 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -259,6 +259,14 @@ session_dir: [limits.host_path_cap]u8 = undefined,
/// slot: the effect then carries none, and perform gives the host this.
spawn_dirs: [MAX_PANES]?[]u8 = @splat(null),
session_dir_len: ?u16 = null,
+/// The session's home (`~`; null: it had none) and the shell its terminals
+/// run when no `Shell` is set ($SHELL if it is executable, else /bin/sh),
+/// read once at its start as `session_dir` is (initSession) and dumped with
+/// it: a client's step reads the session's, never its own machine's.
+session_home: [limits.host_path_cap]u8 = undefined,
+session_home_len: ?u16 = null,
+session_shell: [limits.host_path_cap]u8 = undefined,
+session_shell_len: u16 = 0,
settings: config.Runtime = .{ .font = .{ .tagline_percent = config.gui_tagline_font_percent } },
locations_config: locations.Config = .{},
locations_cache: locations.Cache = .{},
@@ -439,7 +447,7 @@ pub const replica = .{
// session's closed panes, and the files of a host with no file
// system of its own.
.authority = .{ "host", "fs", "store", "recent", "db", "fallback" },
- .len = .{ .{ "look_src", "n_look_src" }, .{ "session_dir", "session_dir_len" } },
+ .len = .{ .{ "look_src", "n_look_src" }, .{ "session_dir", "session_dir_len" }, .{ "session_home", "session_home_len" }, .{ "session_shell", "session_shell_len" } },
};
/// The message row's entry points, called from everywhere as
@@ -537,8 +545,7 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes {
const p = try create(gpa, opts);
errdefer p.deinit();
p.boot = Boot.of(opts);
- // Asked once, at the start, whoever asks first after.
- _ = p.sessionDir();
+ p.readSessionFacts();
// A core built without a terminal (a test configuration: core-test's)
// boots to a scratch pane where a shell would have been, and says why
// once.
@@ -982,7 +989,7 @@ pub fn setCwd(p: *Pardes, id: usize, cwd: []const u8) void {
pub fn shellBin(p: *const Pardes) []const u8 {
const selected = p.settings.shell.requested.get();
- return if (selected.len == 0) config.defaultShell() else selected;
+ return if (selected.len == 0) p.sessionShell() else selected;
}
/// A shell a dead session left, taken in (Adopt): a terminal pane made
@@ -1736,14 +1743,45 @@ fn fsReport(p: *Pardes) void {
}
}
+/// The session's facts it lacks, read now: at its start (a replay of the
+/// boot reads the session's answers), and after a load of a dump made
+/// before they were dumped. Its directory, its home, its shell.
+pub fn readSessionFacts(p: *Pardes) void {
+ // A dump made since carries them all: its shell is never empty.
+ if (p.session_shell_len != 0) return;
+ if (p.session_dir_len == null) if (tape.value(.env, processDir, .{&p.session_dir})) |dir| {
+ std.mem.copyForwards(u8, &p.session_dir, dir);
+ p.session_dir_len = @intCast(dir.len);
+ };
+ if (tape.value(.env, filesystem.processHome, .{})) |home| if (home.len <= p.session_home.len) {
+ @memcpy(p.session_home[0..home.len], home);
+ p.session_home_len = @intCast(home.len);
+ };
+ const shell = tape.value(.env, config.defaultShell, .{});
+ const kept = shell[0..@min(shell.len, p.session_shell.len)];
+ @memcpy(p.session_shell[0..kept.len], kept);
+ p.session_shell_len = @intCast(kept.len);
+}
+
/// Where pardes started: the directory of what runs from a header.
-pub fn sessionDir(p: *Pardes) []const u8 {
- if (p.session_dir_len) |n| return p.session_dir[0..n];
- // The directory the session that recorded was started in.
- const dir = tape.value(.cwd, processDir, .{&p.session_dir}) orelse return "/";
- std.mem.copyForwards(u8, &p.session_dir, dir);
- p.session_dir_len = @intCast(dir.len);
- return p.session_dir[0..dir.len];
+pub fn sessionDir(p: *const Pardes) []const u8 {
+ return if (p.session_dir_len) |n| p.session_dir[0..n] else "/";
+}
+
+/// The shell a terminal runs when no `Shell` is set: the session's.
+pub fn sessionShell(p: *const Pardes) []const u8 {
+ return p.session_shell[0..p.session_shell_len];
+}
+
+/// A path's leading `~` (alone, or before `/` or `:`) as the session's home;
+/// `~user` that user's (fs.expandHomeFrom).
+pub fn expandHome(p: *const Pardes, path: []const u8, out: *[4096]u8) []const u8 {
+ return filesystem.expandHomeFrom(path, out, p.sessionHome());
+}
+
+/// The session's home, null for none.
+pub fn sessionHome(p: *const Pardes) ?[]const u8 {
+ return if (p.session_home_len) |n| p.session_home[0..n] else null;
}
fn processDir(buf: *[limits.host_path_cap]u8) ?[]const u8 {