From 57e254470e11ab40b6bae31b2cbf62aebca27ce4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 23:24:29 -0300 Subject: Record every run's frames to a sessions database in xitdb Live play was recorded only after someone typed record N, into 16 fixed slots. Now every run is a session in one xitdb database per sketch, beside its state file (.xitdb): an append-only log of the frames live update was fed, one commit a second of session time, and keyframes of the State at start, every minute, on jumps, before and after reloads and at exit. A kill -9 loses at most the uncommitted second (test-kill). Whether a build records travels in the sketch: App.Options.record, null meaning Debug, reaching the host as Info.record. Scripted runs from fresh state record in memory, exports not at all. Each stretch of a session keeps its build, layout and Info.source: the repository revision (one jj or git call per build, build_info), zig version, backend and mode. Sessions.zig takes plain data (bytes, events, strings, a path, an Io), so a second host can drive it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/sketch/root.zig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/sketch/root.zig') diff --git a/src/sketch/root.zig b/src/sketch/root.zig index bc09add..c70b326 100644 --- a/src/sketch/root.zig +++ b/src/sketch/root.zig @@ -300,15 +300,24 @@ pub const Console = struct { } }; +/// What the build knows of a sketch and passes to `sketch` and +/// `exportSketch` (build.zig's generated roots fill it in). +pub const Build = struct { + /// The repository revision the sketch was built from, "" when unknown. + source: []const u8 = "", + /// Record sessions to a file (`abi.Info.record`). + record: bool = false, +}; + /// The entry points of `App`, for a host that links it statically. -pub fn sketch(comptime App: type) abi.Sketch { - const G = Glue(App); +pub fn sketch(comptime App: type, comptime made: Build) abi.Sketch { + const G = Glue(App, made); return .{ .info = G.info, .defaults = G.defaults, .init = G.init, .setup = G.setup, .update = G.update, .draw = G.draw, .command = G.command }; } /// Exports `App` under `abi.Sketch.symbols`, for a hot-reloaded library. -pub fn exportSketch(comptime App: type) void { - const G = Glue(App); +pub fn exportSketch(comptime App: type, comptime made: Build) void { + const G = Glue(App, made); const names = abi.Sketch.symbols; @export(&G.info, .{ .name = names.info }); @export(&G.defaults, .{ .name = names.defaults }); @@ -320,7 +329,7 @@ pub fn exportSketch(comptime App: type) void { @export(&G.build, .{ .name = "sketch_build" }); } -pub fn Glue(comptime App: type) type { +pub fn Glue(comptime App: type, comptime made: Build) type { return struct { pub const State = if (@hasDecl(App, "State")) App.State else struct {}; pub const Session = if (@hasDecl(App, "Session")) App.Session else struct {}; @@ -337,6 +346,8 @@ pub fn Glue(comptime App: type) type { .session = abi.layout.of(Session, .session), .store = abi.layout.of(Store, .store), .commands = if (@hasDecl(App, "commands")) &App.commands else &.{}, + .source = made.source ++ " " ++ abi.build, + .record = made.record, }; /// What a call can offer, by type. @@ -471,7 +482,7 @@ test "setup receives session resources without a Frame and reports errors" { ctx.session_root = std.mem.asBytes(&session); ctx.session = std.testing.allocator; ctx.store = std.testing.allocator; - const app = sketch(App); + const app = sketch(App, .{}); try std.testing.expect(!app.setup(&ctx)); defer std.testing.allocator.free(session.bytes); try std.testing.expectEqualStrings("ready", session.bytes); -- cgit v1.3