summaryrefslogtreecommitdiff
path: root/core
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
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')
-rw-r--r--core/Core.zig60
-rw-r--r--core/Output.zig2
-rw-r--r--core/builtins.zig10
-rw-r--r--core/config.zig43
-rw-r--r--core/dump.zig4
-rw-r--r--core/edit_cmd.zig2
-rw-r--r--core/exec.zig12
-rw-r--r--core/fs.zig18
-rw-r--r--core/look.zig2
-rw-r--r--core/ninep/ctl.zig8
-rw-r--r--core/ninep/pane.zig2
-rw-r--r--core/ninep/pty.zig2
-rw-r--r--core/replica.zig28
-rw-r--r--core/sam_edit.zig6
-rw-r--r--core/tagline.zig2
-rw-r--r--core/tape.zig8
16 files changed, 142 insertions, 67 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 {
diff --git a/core/Output.zig b/core/Output.zig
index 600ab085..1335d8e9 100644
--- a/core/Output.zig
+++ b/core/Output.zig
@@ -854,7 +854,7 @@ pub fn openConfig(p: *Pardes, id: usize) !void {
.platform = builtins.viewPlatform(p),
.theme_name = p.theme().name,
.theme_file = pardes.colors.loadedThemeFile(p),
- .compiled_default_shell = config.defaultShell(),
+ .compiled_default_shell = p.sessionShell(),
.hover_delay_frames = config.look_preview_delay_frames,
.native_images = p.view().frontend.native_images,
.capabilities = builtins.viewCapabilities(p),
diff --git a/core/builtins.zig b/core/builtins.zig
index 0d2e4c20..6b291628 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -664,7 +664,7 @@ pub const ThemeFile = struct {
pub const requires_arg = true;
pub fn run(c: Ctx) void {
var home_buf: [4096]u8 = undefined;
- const arg = pardes.filesystem.expandHome(std.mem.trim(u8, c.arg orelse return, " \t\r\n"), &home_buf);
+ const arg = c.p.expandHome(std.mem.trim(u8, c.arg orelse return, " \t\r\n"), &home_buf);
// Said with why, not "invalid theme path".
if (!std.mem.endsWith(u8, arg, ".zon")) {
var said: pardes.Kind.Buf(320) = .{};
@@ -845,7 +845,7 @@ pub const Get = struct {
}
if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it");
var home_buf: [4096]u8 = undefined;
- const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(c.id, "Get", err);
+ const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), c.p.expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(c.id, "Get", err);
// A file that is not there, or a directory, is said before unsaved
// edits are asked about: there would be nothing to load over them.
if (typed.len > 0) if (@import("fs.zig").localPath(path)) |local| {
@@ -908,7 +908,7 @@ pub const Incl = struct {
if (dir_word[0] != '/' and dir_word[0] != '~')
return p.reportFailure(c.id, said.print("Incl: invalid directory: {s} is relative", .{shown}));
var home_buf: [4096]u8 = undefined;
- const expanded = @import("fs.zig").expandHome(dir_word, &home_buf);
+ const expanded = p.expandHome(dir_word, &home_buf);
if (@import("fs.zig").localPath(expanded)) |local| if (exec.kindOf(local) != .directory)
return p.reportFailure(c.id, if (exec.kindOf(local) != null)
said.print("Incl: not a directory: {s}", .{shown})
@@ -918,7 +918,7 @@ pub const Incl = struct {
var words = std.mem.tokenizeAny(u8, typed, " \t");
while (words.next()) |dir_word| {
var home_buf: [4096]u8 = undefined;
- const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(dir_word, &home_buf) }) catch |err| return p.reportError(c.id, "Incl", err);
+ const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), p.expandHome(dir_word, &home_buf) }) catch |err| return p.reportError(c.id, "Incl", err);
if (!std.Io.Dir.path.isAbsolute(full)) return p.reportFailure(c.id, "Incl: invalid directory");
for (p.incl.items) |dir| {
if (std.mem.eql(u8, dir, full)) break;
@@ -1182,7 +1182,7 @@ pub const Term = struct {
if (arg.len > 0) {
var why: [320]u8 = undefined;
// The authority's lookup, taped, as Shell's (exec.zig).
- if (pardes.tape.value(.shell, @import("dev").host_io.Shell.refusal, .{ arg[0..@min(arg.len, 200)], &why })) |refused| {
+ if (pardes.tape.site(.shell, null, @import("dev").host_io.Shell.refusal, .{ arg[0..@min(arg.len, 200)], &why })) |refused| {
var said: pardes.Kind.Buf(340) = .{};
return c.p.reportFailure(c.id, said.print("Term: {s}", .{refused}));
}
diff --git a/core/config.zig b/core/config.zig
index 5f63268e..5bbe1886 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -330,12 +330,8 @@ pub fn wheelTick(guard: *u8, vertical: bool) bool {
/// The shell when no `Shell` is set: the user's login shell ($SHELL), as a
/// terminal would start, else /bin/sh. An explicit `Shell` overrides it.
+/// This process's: read once, at the session's start (Pardes.session_shell).
pub fn defaultShell() []const u8 {
- // As the session that recorded found it (core/tape.zig).
- return pardes.tape.value(.env, defaultShellHost, .{});
-}
-
-fn defaultShellHost() []const u8 {
if (std.c.getenv("SHELL")) |s| {
const shell = std.mem.span(s);
// One that is not there, or not executable, is no shell: /bin/sh.
@@ -837,7 +833,8 @@ pub const Runtime = struct {
@compileError("Shell, Theme, Font, TaglineSize and WindowOpacity actions must each occur exactly once");
}
- pub fn apply(state: *Runtime, setting: Setting, argument: ?[]const u8) bool {
+ /// `home`: what `~` is (the session's: Pardes.session_home).
+ pub fn apply(state: *Runtime, setting: Setting, argument: ?[]const u8, home: ?[]const u8) bool {
switch (setting.action) {
// Every toggle names a bool field of its own, so one line covers
// all of them and a new toggle needs no arm here. Bare, a toggle
@@ -869,7 +866,7 @@ pub const Runtime = struct {
if (text.len > 0) {
if (text[0] != '/' and text[0] != '~') return false;
var home_buf: [4096]u8 = undefined;
- if (pardes.filesystem.deniedAbove(pardes.filesystem.expandHome(text, &home_buf))) return false;
+ if (pardes.filesystem.deniedAbove(pardes.filesystem.expandHomeFrom(text, &home_buf, home))) return false;
}
if (!state.dump_dir.set(text)) return false;
},
@@ -1073,28 +1070,28 @@ pub const Runtime = struct {
const verbose = find("Verbose").?;
try std.testing.expect(state.verbose);
// Bare, it flips: that is what a tagline word does.
- try std.testing.expect(apply(&state, verbose, null));
+ try std.testing.expect(apply(&state, verbose, null, null));
try std.testing.expect(!state.verbose);
// Told, it SETS -- twice over, so the second call proves it is not
// flipping past the value it was given.
- try std.testing.expect(apply(&state, verbose, "on"));
+ try std.testing.expect(apply(&state, verbose, "on", null));
try std.testing.expect(state.verbose);
- try std.testing.expect(apply(&state, verbose, " on\n"));
+ try std.testing.expect(apply(&state, verbose, " on\n", null));
try std.testing.expect(state.verbose);
- try std.testing.expect(apply(&state, verbose, "off"));
+ try std.testing.expect(apply(&state, verbose, "off", null));
try std.testing.expect(!state.verbose);
- try std.testing.expect(apply(&state, verbose, "off"));
+ try std.testing.expect(apply(&state, verbose, "off", null));
try std.testing.expect(!state.verbose);
// And anything else is refused rather than silently flipping.
- try std.testing.expect(!apply(&state, verbose, "maybe"));
+ try std.testing.expect(!apply(&state, verbose, "maybe", null));
try std.testing.expect(!state.verbose);
}
test "simple setting application mutates only its plain field" {
var state: Runtime = .{};
- try std.testing.expect(apply(&state, find("Wrap").?, null));
+ try std.testing.expect(apply(&state, find("Wrap").?, null, null));
try std.testing.expect(!state.wrap);
- try std.testing.expect(apply(&state, find("Shell").?, " fish\n"));
+ try std.testing.expect(apply(&state, find("Shell").?, " fish\n", null));
try std.testing.expectEqualStrings("fish", state.shell.requested.get());
try std.testing.expect(state.shell.pending);
}
@@ -1104,13 +1101,13 @@ pub const Runtime = struct {
var state: Runtime = .{};
for ([_][]const u8{ "1", " 82\n", "100" }) |argument| {
- try std.testing.expect(apply(&state, setting, argument));
+ try std.testing.expect(apply(&state, setting, argument, null));
try std.testing.expectEqual(try std.fmt.parseInt(u8, std.mem.trim(u8, argument, " \t\r\n"), 10), state.font.tagline_percent);
}
state.font.tagline_percent = 67;
for ([_]?[]const u8{ null, "", "0", "101", "-1", "50%", "999999999999999999999" }) |argument| {
- try std.testing.expect(!apply(&state, setting, argument));
+ try std.testing.expect(!apply(&state, setting, argument, null));
try std.testing.expectEqual(@as(u8, 67), state.font.tagline_percent);
}
}
@@ -1124,7 +1121,7 @@ pub const Runtime = struct {
for ([_][]const u8{ "0", " 85\n", "100" }, [_]u8{ 0, 85, 100 }) |argument, expected| {
state.window_opacity_pending = false;
- try std.testing.expect(apply(&state, setting, argument));
+ try std.testing.expect(apply(&state, setting, argument, null));
try std.testing.expectEqual(expected, state.window_opacity);
try std.testing.expect(state.window_opacity_pending);
}
@@ -1132,12 +1129,12 @@ pub const Runtime = struct {
state.window_opacity = 85;
state.window_opacity_pending = false;
for ([_]?[]const u8{ null, "", " \t\n", "101", "-1", "+85", "85%", "0.5", "85.0", "85 20", "8_5", "0x55", "999999999999999999999" }) |argument| {
- try std.testing.expect(!apply(&state, setting, argument));
+ try std.testing.expect(!apply(&state, setting, argument, null));
try std.testing.expectEqual(@as(u8, 85), state.window_opacity);
try std.testing.expect(!state.window_opacity_pending);
}
// Reissuing the same request still asks the host to apply it again.
- try std.testing.expect(apply(&state, setting, "85"));
+ try std.testing.expect(apply(&state, setting, "85", null));
try std.testing.expect(state.window_opacity_pending);
}
@@ -1193,7 +1190,7 @@ pub const Runtime = struct {
.{ "GripWidth", "200" }, .{ "InactiveDim", "35" },
.{ "CallstackDepth", "16" }, .{ "Tab", "8" },
};
- for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1]));
+ for (values) |v| try std.testing.expect(apply(&state, find(v[0]).?, v[1], null));
try std.testing.expect(state.font.requested_name.set("Wanted Mono"));
try std.testing.expect(state.font.requested_path.set("/fonts/wanted.ttf"));
state.font.requested_size_hundredths = 1850;
@@ -1842,11 +1839,11 @@ test "CallstackDepth is bounded and keeps the last valid runtime limit" {
var state: Runtime = .{};
try std.testing.expectEqual(@as(u8, 8), state.callstack_depth);
for ([_][]const u8{ "1", "8", "16", "64" }) |value| {
- try std.testing.expect(Runtime.apply(&state, Runtime.find("CallstackDepth").?, value));
+ try std.testing.expect(Runtime.apply(&state, Runtime.find("CallstackDepth").?, value, null));
try std.testing.expectEqual(try std.fmt.parseInt(u8, value, 10), state.callstack_depth);
}
for ([_][]const u8{ "0", "65", "256", "-1", "+8", "1_6", "eight", "" }) |value| {
- try std.testing.expect(!Runtime.apply(&state, Runtime.find("CallstackDepth").?, value));
+ try std.testing.expect(!Runtime.apply(&state, Runtime.find("CallstackDepth").?, value, null));
try std.testing.expectEqual(@as(u8, 64), state.callstack_depth);
}
}
diff --git a/core/dump.zig b/core/dump.zig
index 58560645..d8d87fc6 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -168,7 +168,7 @@ pub fn dumpTo(p: *Pardes, to: ?[]const u8) !void {
p.dump_export = null;
if (to) |path| {
var home_buf: [4096]u8 = undefined;
- p.dump_export = try p.gpa.dupe(u8, filesystem.expandHome(path, &home_buf));
+ p.dump_export = try p.gpa.dupe(u8, p.expandHome(path, &home_buf));
}
try dumpState(p);
}
@@ -403,6 +403,7 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
for (others) |o| gpa.free(o.panes);
gpa.free(others);
l.shared.shrinkRetainingCapacity(at);
+ p.readSessionFacts();
return p;
}
@@ -487,6 +488,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?*
try views.undumpedOld(p, others, gpa);
}
l.made.shrinkRetainingCapacity(at);
+ p.readSessionFacts();
return p;
}
diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig
index 6cd7788d..a87fdfa2 100644
--- a/core/edit_cmd.zig
+++ b/core/edit_cmd.zig
@@ -177,7 +177,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
var world: World = .{ .p = p, .from = id, .arena = arena };
var why: sam.Why = .{};
var text: pardes.Kind.Buf(260) = .{};
- const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet }, &why) catch |err| switch (err) {
+ const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet, .home = p.sessionHome() }, &why) catch |err| switch (err) {
error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})),
error.OutOfMemory => return p.reportError(id, "Edit", err),
};
diff --git a/core/exec.zig b/core/exec.zig
index 6804a22e..5a9bf192 100644
--- a/core/exec.zig
+++ b/core/exec.zig
@@ -333,7 +333,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void {
var home_buf: [4096]u8 = undefined;
const full = std.Io.Dir.path.resolvePosix(
p.scratch.allocator(),
- &.{ Pardes.paneDir(pane), @import("fs.zig").expandHome(path, &home_buf) },
+ &.{ Pardes.paneDir(pane), p.expandHome(path, &home_buf) },
) catch |err| return p.reportError(id, "save", err);
if (!std.Io.Dir.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory);
if (full.len > Pardes.SavePath.cap) return p.reportError(id, "save", error.PathTooLong);
@@ -1022,25 +1022,25 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
p.settings.shell.pending = true;
if (!p.announce) return;
var said: pardes.Kind.Buf(320) = .{};
- return p.setMessage(v.active, said.print("Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()[0..@min(config.defaultShell().len, 256)]}));
+ return p.setMessage(v.active, said.print("Shell: the default again, {s} ($SHELL, else /bin/sh)", .{p.sessionShell()[0..@min(p.sessionShell().len, 256)]}));
}
var why: [320]u8 = undefined;
- if (pardes.tape.value(.shell, @import("dev").host_io.Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| {
+ if (pardes.tape.site(.shell, null, @import("dev").host_io.Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| {
var text: pardes.Kind.Buf(340) = .{};
return p.reportFailure(v.active, text.print("Shell: {s}", .{refused}));
}
- if (!p.settings.apply(setting, want)) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
+ if (!p.settings.apply(setting, want, p.sessionHome())) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
},
// Bare, each says its value, as acme's Tab says the width.
inline .tab, .callstack_depth => |_, tag| if (arg == null) {
var said: pardes.Kind.Buf(40) = .{};
return p.setMessage(v.active, said.print("{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }));
- } else if (!p.settings.apply(setting, arg)) {
+ } else if (!p.settings.apply(setting, arg, p.sessionHome())) {
var said: pardes.Kind.Buf(96) = .{};
p.reportFailure(v.active, said.print("{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }));
},
// Said with what it takes: its words, its range.
- else => if (!p.settings.apply(setting, arg)) {
+ else => if (!p.settings.apply(setting, arg, p.sessionHome())) {
var buf: [160]u8 = undefined;
var text: std.Io.Writer = .fixed(&buf);
// A list of values too long for the row is cut.
diff --git a/core/fs.zig b/core/fs.zig
index 333588ce..f58e108b 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -405,15 +405,21 @@ pub fn expandHome(path: []const u8, out: *[4096]u8) []const u8 {
}
fn expandHomeHost(path: []const u8, out: *[4096]u8) []const u8 {
- return expandHomeFrom(path, out, std.c.getenv("HOME"));
+ return expandHomeFrom(path, out, processHome());
}
-/// expandHome with HOME given (null: unset), so a test need not change the
-/// process's environment, which a child spawned later reads.
-fn expandHomeFrom(path: []const u8, out: *[4096]u8, env_home: ?[*:0]const u8) []const u8 {
+/// This process's home: $HOME, else its passwd entry's; null for none.
+pub fn processHome() ?[]const u8 {
+ return homeDir(std.c.getenv("HOME"));
+}
+
+/// expandHome with the home given (null: none, `~` left as typed): a
+/// session's (Pardes.expandHome), or this process's. `~user` is that
+/// user's passwd entry, as the session that recorded found it.
+pub fn expandHomeFrom(path: []const u8, out: *[4096]u8, given: ?[]const u8) []const u8 {
if (path.len == 0 or path[0] != '~') return path;
const end = std.mem.indexOfAny(u8, path, "/:") orelse path.len;
- const home = (if (end == 1) homeDir(env_home) else userHome(path[1..end])) orelse return path;
+ const home = (if (end == 1) given else pardes.tape.value(.env, userHome, .{path[1..end]})) orelse return path;
const trimmed = std.mem.trimEnd(u8, home, "/");
const rest = path[end..];
if (trimmed.len == 0 and (rest.len == 0 or rest[0] != '/')) return std.fmt.bufPrint(out, "/{s}", .{rest}) catch path;
@@ -1468,7 +1474,7 @@ test "a leading ~ is home, from HOME or else the passwd entry" {
// HOME unset: the passwd entry's home.
const pw = std.c.getpwuid(std.c.getuid()) orelse return error.SkipZigTest;
var from_passwd: [4096]u8 = undefined;
- try std.testing.expectEqualStrings(try std.fmt.bufPrint(&from_passwd, "{s}/y", .{std.mem.trimEnd(u8, std.mem.span(pw.dir.?), "/")}), expandHomeFrom("~/y", &out, null));
+ try std.testing.expectEqualStrings(try std.fmt.bufPrint(&from_passwd, "{s}/y", .{std.mem.trimEnd(u8, std.mem.span(pw.dir.?), "/")}), expandHomeFrom("~/y", &out, homeDir(null)));
}
test "Restore prefers default directory then falls back to original path" {
diff --git a/core/look.zig b/core/look.zig
index 7ca8914f..170e5ea9 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1435,7 +1435,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// themselves).
var home_buf: [4096]u8 = undefined;
const stripped = std.mem.trim(u8, operand_raw, " \t\r\n");
- const operand = if (stripped.len > 0 and stripped[0] == '~') filesystem.expandHome(stripped, &home_buf) else std.mem.trimEnd(u8, operand_raw, "\r\n");
+ const operand = if (stripped.len > 0 and stripped[0] == '~') p.expandHome(stripped, &home_buf) else std.mem.trimEnd(u8, operand_raw, "\r\n");
// A +History line names a dump of the state file's (`Restore <label>`;
// its date, size and panes are the indented line under it): a look at
// it is a Restore of that dump; other words are looked as any (a path
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 2b26c3e2..81600582 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -571,7 +571,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
.callstack_depth => arg.len == 0 or (std.fmt.parseInt(u8, arg, 10) catch 0) -% 1 < pardes.lsp.callstack_max_depth,
else => probe: {
var probe = p.settings;
- break :probe probe.apply(setting, if (arg.len > 0) arg else null);
+ break :probe probe.apply(setting, if (arg.len > 0) arg else null, p.sessionHome());
},
};
if (takes) return null;
@@ -638,7 +638,7 @@ fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, cap
.locations = located.buffered(),
.theme_name = p.theme().name,
.theme_file = pardes.colors.loadedThemeFile(p),
- .compiled_default_shell = config.defaultShell(),
+ .compiled_default_shell = p.sessionShell(),
.default_dump_dir = pardes.dump.defaultDirectory(&dump_dir) orelse "",
.capabilities = caps,
.state = s,
@@ -669,7 +669,7 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
// `~` is home, and `/tmp/../etc` is `/etc`: the +Pager is named in the
// directory it is, as any other pane's name is.
var home_buf: [4096]u8 = undefined;
- const typed = pardes.filesystem.expandHome(std.mem.trim(u8, line, " \t"), &home_buf);
+ const typed = p.expandHome(std.mem.trim(u8, line, " \t"), &home_buf);
const dir = if (typed.len > 0 and typed[0] == '/') std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{typed}) catch typed else typed;
// A directory that is there, or none (the session's): never a +Pager
// named into one missing, nor a relative one quietly taken for none.
@@ -1771,7 +1771,7 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path,
.platform = @tagName(pardes.platform),
.theme_name = p.theme().name,
.theme_file = pardes.colors.loadedThemeFile(p),
- .compiled_default_shell = config.defaultShell(),
+ .compiled_default_shell = p.sessionShell(),
.hover_delay_frames = config.look_preview_delay_frames,
.native_images = false,
.capabilities = builtins.capabilities,
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index b940bdd6..16d7762a 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -894,7 +894,7 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
// Words 9ns maps to EINVAL, as every refusal of a name here.
if (fileOf(pane) == null) return tree.failText(req.tag, E.INVAL, unnamed(pane));
var home_buf: [4096]u8 = undefined;
- const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ pardes.Pardes.paneDir(pane), fs.expandHome(name, &home_buf) }) catch
+ const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ pardes.Pardes.paneDir(pane), p.expandHome(name, &home_buf) }) catch
return Reply.fail(req.tag, E.NOMEM);
if (!std.Io.Dir.path.isAbsolute(full) or full.len >= 4096) return tree.failText(req.tag, E.INVAL, "invalid file name: longer than a path may be");
// A directory (`~`, `/`, `foo/`) is no file to name a pane after: a
diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig
index a66d9f23..0fd75aa2 100644
--- a/core/ninep/pty.zig
+++ b/core/ninep/pty.zig
@@ -66,7 +66,7 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
// interpreter is not: refused, and the running shell kept.
const bin = pane.shell orelse p.shellBin();
var why: [320]u8 = undefined;
- if (pardes.tape.value(.shell, @import("dev").host_io.Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
+ if (pardes.tape.site(.shell, null, @import("dev").host_io.Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused[0..@min(refused.len, 300)]}) catch &p.fs.ename); // cut to ename's 320
};
if (verb(p, id, line, apply)) |why| return tree.failText(req.tag, E.INVAL, why);
diff --git a/core/replica.zig b/core/replica.zig
index ab805cda..80b3ab10 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -5645,3 +5645,31 @@ test "a far client's click into a shell whose program asked for focus events is
try std.testing.expectEqual(@as(u32, 2), r.stats.fast);
try agrees(a, r);
}
+
+test "a far client's own Look of ~/x, bare Shell and a word that runs in the session's directory read the session's facts: its speculation asks its own machine's environment nothing" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false);
+ defer a.deinit();
+ const r = try joinedFresh(a);
+ defer r.deinit();
+ try std.testing.expectEqualStrings(a.core.sessionShell(), r.core().sessionShell());
+ try std.testing.expectEqualStrings(a.core.sessionDir(), r.core().sessionDir());
+ for ([_][]const u8{ "Look ~/x", "Shell", "Tutor" }) |cmd| {
+ _ = try r.input(.{ .command = cmd });
+ // What it recorded: applied, its speculation's; stopped, the tape's
+ // last (a speculation runs to its end, stopped or not).
+ const records = if (r.applied > 0) r.pending.items[0].spec.? else r.t.buf.items;
+ var records_text: std.Io.Writer.Allocating = .init(gpa);
+ defer records_text.deinit();
+ tape.describe(records, &records_text.writer);
+ if (std.mem.indexOf(u8, records_text.written(), "host env\n") != null) {
+ std.debug.print("{s} read the environment:\n{s}", .{ cmd, records_text.written() });
+ return error.ReadTheEnvironment;
+ }
+ r.toConfirmed();
+ for (r.pending.items) |p| r.freePending(p);
+ r.pending.clearRetainingCapacity();
+ r.blocked = null;
+ r.dirty = false;
+ }
+}
diff --git a/core/sam_edit.zig b/core/sam_edit.zig
index 39f667f9..4d7d6a27 100644
--- a/core/sam_edit.zig
+++ b/core/sam_edit.zig
@@ -83,6 +83,8 @@ pub const World = struct {
/// `e` over unsaved edits in the pane `id`: asked once, as Get asks;
/// true, and `why` set, when it is refused this time.
refuseGet: *const fn (ctx: *anyopaque, id: usize, why: *Why) bool,
+ /// What `~` is: the session's home (null: none).
+ home: ?[]const u8 = null,
};
/// What an Edit came to: every file (those `B` opened after the ones it
@@ -668,7 +670,7 @@ const Exec = struct {
fn pathIn(ex: *Exec, fi: usize, name_in: []const u8) Failure![]const u8 {
// `~` and `~user` as Get, Incl and Save read them.
var home: [4096]u8 = undefined;
- const name = try ex.arena.dupe(u8, @import("fs.zig").expandHome(name_in, &home));
+ const name = try ex.arena.dupe(u8, @import("fs.zig").expandHomeFrom(name_in, &home, if (ex.world) |w| w.home else null));
if (name.len > 0 and name[0] == '/') return name;
const dir = std.Io.Dir.path.dirnamePosix(ex.files.items[fi].name) orelse "/";
return std.Io.Dir.path.resolvePosix(ex.arena, &.{ dir, name });
@@ -1126,7 +1128,7 @@ const Fixture = struct {
fn edit(fx: *Fixture, from: usize, command: []const u8) !Result {
var ctx: u8 = 0;
- const world: World = .{ .ctx = &ctx, .check = check, .open = open, .read = read, .refuseGet = refuseGet };
+ const world: World = .{ .ctx = &ctx, .check = check, .open = open, .read = read, .refuseGet = refuseGet, .home = "/home/u" };
return run(fx.arena_state.allocator(), &files, from, command, world, &fx.why);
}
diff --git a/core/tagline.zig b/core/tagline.zig
index e8819eb1..d0525a84 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -396,7 +396,7 @@ pub fn commitTagName(p: *Pardes, pane: *Pane) bool {
return false;
};
var home_buf: [4096]u8 = undefined;
- const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(pane), pardes.filesystem.expandHome(name, &home_buf) }) catch |err| {
+ const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(pane), p.expandHome(name, &home_buf) }) catch |err| {
p.reportError(id, "name", err);
return false;
};
diff --git a/core/tape.zig b/core/tape.zig
index 0f0678d0..ce94f4ae 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -98,6 +98,9 @@ pub const Site = enum(u16) {
search,
/// The daemon's registry, as /sessions reads it (daemon.ask "list").
sessions,
+ /// Whether a shell is installed (host_io.Shell.refusal): the session's
+ /// disk, asked as any file is.
+ shell,
// Read in place (`value`).
clock,
budget,
@@ -105,9 +108,7 @@ pub const Site = enum(u16) {
env,
interpreter,
denied,
- shell,
mtime,
- cwd,
/// What a terminal's ingest told the positions pardes keeps over it.
positions,
/// Whether a terminal is at its prompt, as a step reads it after its
@@ -163,8 +164,9 @@ fn ErrorOf(comptime f: anytype) type {
}
/// Every type the tape carries, as walk.shape says it: wire.semantics's.
+/// The sites too: a record names one by its number.
pub const shape = blk: {
- var types: []const type = &.{ Input, []const u64, struct { u8, u64 } };
+ var types: []const type = &.{ Input, Site, []const u64, struct { u8, u64 } };
for (results) |R| types = types ++ .{R};
for (host_fns) |f| types = types ++ .{@typeInfo(@typeInfo(@typeInfo(@FieldType(VTable, f)).optional.child).pointer.child).@"fn".return_type.?};
for (watched) |name| types = types ++ .{Watched(name)};