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/host/Console.zig | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/host/Console.zig') diff --git a/src/host/Console.zig b/src/host/Console.zig index 0c44ea2..82911ad 100644 --- a/src/host/Console.zig +++ b/src/host/Console.zig @@ -16,7 +16,7 @@ const Line = struct { bytes: [118]u8 = @splat(0), len: usize = 0 }; const host_commands = [_][]const u8{ "help", "overlay memory", "overlay sound", "get", "set", "reset", "save", "load", "snapshot", "recording", "record", "stop", "play", "pause", "step", "seek start", "seek end", "diff", "quit", "exit", - "overlay timing", "timing on", "timing off", "timing frame", "timing work", "timing reset", "timing stats", + "overlay timing", "sessions", "timing on", "timing off", "timing frame", "timing work", "timing reset", "timing stats", }; visible: bool = false, @@ -205,6 +205,9 @@ pub fn execute(self: *Console, host: *Host, line: []const u8, now: u64) ![]const self.recording = index; self.print("{s} recording {d} from snapshot {d}.", .{ if (eq(command, "record")) "Started" else "Playing", index, h.bank.recording(index).snapshot }); if (eq(command, "play")) self.warnBuild(host, h.bank.recording(index)); + } else if (eq(command, "sessions")) { + if (arg != null) return error.UnexpectedArgument; + try self.listSessions(host); } else if (eq(command, "stop")) { h.stop(now); } else if (eq(command, "pause")) { @@ -251,8 +254,8 @@ pub fn draw(self: *const Console, host: *Host, out: *std.ArrayList(abi.Command), const width: f32 = @floatFromInt(host.canvas[0]); const h = &host.timeline; try out.append(arena, .{ .rect = .{ .dst = .{ .x = 0, .y = top, .w = width, .h = panel_height }, .color = .{ .r = 24, .g = 28, .b = 28 } } }); - const status = try std.fmt.allocPrint(arena, "{s} | {t} | snapshot {d} | recording {d} (active {d}) | event {d} | {d}ms", .{ - host.name, h.mode, self.snapshot, self.recording, h.selected, h.cursor, h.position / std.time.ns_per_ms, + const status = try std.fmt.allocPrint(arena, "{s} | {t} | snapshot {d} | recording {d} (active {d}) | event {d} | {d}ms | rec {t}", .{ + host.name, h.mode, self.snapshot, self.recording, h.selected, h.cursor, h.position / std.time.ns_per_ms, host.sessions.mode(), }); try out.append(arena, .{ .text = .{ .x = 12, .y = top + 8, .scale = 1, .color = hint, .bytes = status } }); for (&self.lines, 0..) |*line, i| { @@ -262,6 +265,32 @@ pub fn draw(self: *const Console, host: *Host, out: *std.ArrayList(abi.Command), try out.append(arena, .{ .rect = .{ .dst = .{ .x = @floatFromInt(28 + self.cursor * 8), .y = top + 120, .w = 1, .h = 12 }, .color = hint } }); } +/// Where this run records, then the last sessions: index, start, frames, +/// stretches (loads), and how it ended. +fn listSessions(self: *Console, host: *Host) !void { + const s = &host.sessions; + switch (s.mode()) { + .file => self.print("recording to {s}", .{s.path}), + .memory => self.log("recording in memory (scripted run)"), + .off => return self.log("not recording (release build: .record = true collects)"), + } + const n = try s.count(.sessions); + var i = n -| 4; + while (i < n) : (i += 1) { + const m = try s.summary(i); + const secs = std.time.epoch.EpochSeconds{ .secs = m.started / std.time.ns_per_s }; + const day = secs.getEpochDay().calculateYearDay(); + const md = day.calculateMonthDay(); + const ds = secs.getDaySeconds(); + var end_buf: [32]u8 = undefined; + const end = if (i == s.session) "(this run)" else if (m.ended == 0) "(crashed)" else blk: { + const d = (m.ended -| m.started) / std.time.ns_per_s; + break :blk std.fmt.bufPrint(&end_buf, "{d}:{d:0>2}", .{ d / 60, d % 60 }) catch ""; + }; + self.print("{d}: {d:0>4}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2} builds {d} frames {d} {s}", .{ i, day.year, md.month.numeric(), md.day_index + 1, ds.getHoursIntoDay(), ds.getMinutesIntoHour(), m.stretches, m.frames, end }); + } +} + /// A replay of a recording made by other code may diverge: say so. fn warnBuild(self: *Console, host: *const Host, r: *const timeline.Recording) void { if (r.build() != 0 and host.build != 0 and r.build() != host.build) self.log("Warning: recorded by another build of the sketch; the replay may differ."); -- cgit v1.3