From 41bdeb1b3fadc266823c43086de61913be8e60f6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 01:57:33 -0300 Subject: Dial by name, and fs in every sketch's binary, answering with the sketch closed A run a person watches (not headless, a script or an export) posts its tree as $XDG_RUNTIME_DIR/9p/sketchbook/, the sketch's Info.name; --9p NAME posts under another name, --9p /path listens at a socket path as before. A name a live run holds is refused, a stale one replaced; a default post that fails says so and the run goes on without one, an explicit --9p that fails ends it as before. (cloud9's post() takes names without a slash, so control.zig makes the sketchbook/ directory and binds there itself, with post.probe deciding live or stale.) `fs VERB [PATH [WORDS]]`, after the options, in the generic host (`sketchbook LIBRARY fs ...`) and in every executable built with sketchbook (`drat-meout fs read state/scene`), is cloud9.verbs.run on an Fsys: the running sketch's tree when one is posted (or at --9p), else the same tree served in this process over a socketpair, on a thread (Control.serveOffline, the same respond with `offline` set), from the save's newest State (--state's save, else the default one; read only: Sessions.openRead, no session started, restored into today's layout), else from the State's declared defaults (init is not run). README, commands, ctl's read and state/ answer; a write and status, log, screen.png and the traces answer in words, "drat-meout is not running: this is its save's newest State, frame 61 of ". No window, no SDL. sketchbook.init's modules gain cloud9, so an app's own tests can dial its executable with cloud9.Fsys. Tests: a new step, test-fs (in test): the replay fixture posted by name under a private runtime directory, driven with its own binary's fs: ls, a state write and read, a refused value in words, a live click, a screenshot read, help of state/dots and ctl, quit and the name gone; then closed: a state file read from the defaults, status refused in words. test-fs, test-control, test-paths, test-setup, test-sessions: 56/56 steps, 27/27 tests. drat-meout's copy builds unchanged and answers fs with the game closed: 94 leaves, 16,522 files, 17,608 values, 10,408 directories. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/host/Host.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/host/Host.zig') diff --git a/src/host/Host.zig b/src/host/Host.zig index 93c47c1..135f5c4 100644 --- a/src/host/Host.zig +++ b/src/host/Host.zig @@ -284,7 +284,15 @@ pub fn deinit(self: *Host) void { /// The interactive loop. An export runs it on a clock of its own, frame k /// at k/fps seconds (from 1 s, as scripts do), whatever the wall clock says. pub fn run(self: *Host) !void { - if (self.options.ninep) |path| self.control = try Control.init(self.gpa, path); + // A run a person watches posts its tree as sketchbook/; --9p + // names another, or a socket path. + const o = self.options; + const ninep = o.ninep orelse if (o.headless or o.script or o.export_to != null) null else self.name; + if (ninep) |where| self.control = Control.open(self.gpa, self.environ, where) catch |err| blk: { + if (o.ninep != null) return err; + self.print("not posted as sketchbook/{s}: {t}", .{ where, err }); + break :blk null; + }; while (!self.quit) { if (self.control) |control| control.poll(self); try self.poll(); @@ -1036,7 +1044,7 @@ fn fileId(io: std.Io, path: []const u8) u64 { return std.hash.Wyhash.hash(0, std.mem.asBytes(&id)) | 1; } -fn scratchDir(environ: *const std.process.Environ.Map) []const u8 { +pub fn scratchDir(environ: *const std.process.Environ.Map) []const u8 { return environ.get("XDG_RUNTIME_DIR") orelse "/tmp"; } -- cgit v1.3