@native-sdk/cli 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +534 -3
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +599 -3
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1283 -66
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +70 -1
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +240 -24
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +473 -13
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +109 -15
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2333 -63
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -25,7 +25,7 @@
25
25
  //! Format (the wire-packet precedent: length-prefixed little-endian
26
26
  //! binary, explicit budgets, hostile input fails loudly):
27
27
  //!
28
- //! magic "NSDKSJNL" | u32 format version | records...
28
+ //! magic "NSDKSJNL" | u64 format fingerprint | records...
29
29
  //!
30
30
  //! Every record is `u8 kind | u32 payload_len | payload`. The first
31
31
  //! record must be the header; the last must be the end record, whose
@@ -51,8 +51,9 @@
51
51
  //! ends — delivers, and journals, under the NEXT wake's event record.
52
52
  //!
53
53
  //! Enum payloads ride as their declaration-order integer values, so
54
- //! reordering any journaled enum is a format break: bump
55
- //! `format_version` when one moves.
54
+ //! reordering any journaled enum is a format break — one
55
+ //! `format_fingerprint` sees on its own (the layout description
56
+ //! renders every journaled enum's names AND values).
56
57
  //!
57
58
  //! Coverage note: automation driving is fully journaled. Verbs that
58
59
  //! synthesize PLATFORM events (widget-click/hold/context-press/drag/
@@ -70,6 +71,7 @@ const std = @import("std");
70
71
  const geometry = @import("geometry");
71
72
  const platform = @import("../platform/root.zig");
72
73
  const automation_protocol = @import("../automation/protocol.zig");
74
+ const layout_fingerprint = @import("../automation/layout_fingerprint.zig");
73
75
  const runtime_effects = @import("effects.zig");
74
76
 
75
77
  pub const EffectResultRecord = runtime_effects.EffectResultRecord;
@@ -77,27 +79,128 @@ pub const EffectResultRecord = runtime_effects.EffectResultRecord;
77
79
  /// File magic: first eight bytes of every session journal.
78
80
  pub const magic = "NSDKSJNL";
79
81
 
80
- /// Journal format version. Any change to record layouts or journaled
81
- /// enum orders bumps this; readers refuse other versions loudly rather
82
- /// than misreading yesterday's shape. v2 added the stream `buffering`
83
- /// flag to audio event and audio effect records; v3 added the spectrum
84
- /// band bytes to both (and the `.spectrum` audio kind); v4 added the
85
- /// composition verbs (`set_composition`/`commit_composition`/
86
- /// `cancel_composition`, codes 11-13) to the accessibility-action
87
- /// record's verb enum — a v3 reader hitting one of those codes would
88
- /// have reported the file corrupt instead of refusing the skew; v5
89
- /// added the pinch magnification `scale` field to gpu-surface input
90
- /// records (a layout change every v4 reader would misparse) plus the
82
+ /// Journal format identity. Any change to record layouts or journaled
83
+ /// enum orders moves this fingerprint ON ITS OWN — the layout
84
+ /// description below reflects over the actual record and event types —
85
+ /// and readers refuse a journal whose fingerprint differs from their
86
+ /// own, loudly, rather than misreading yesterday's shape.
87
+ ///
88
+ /// This replaces the manually-bumped integer counter the preamble
89
+ /// carried through v8. No journal is ever migrated (replay refuses
90
+ /// every skew with the re-record teaching), so an ORDERED version
91
+ /// carried no information — "same or different" is the entire question
92
+ /// — while costing two recurring failures: parallel branches contending
93
+ /// for the next integer, and forgettable bumps.
94
+ ///
95
+ /// History of the retired counter, kept because it documents real
96
+ /// breaks: v2 added the stream `buffering` flag to audio event and
97
+ /// audio effect records; v3 added the spectrum band bytes to both (and
98
+ /// the `.spectrum` audio kind); v4 added the composition verbs
99
+ /// (`set_composition`/`commit_composition`/`cancel_composition`, codes
100
+ /// 11-13) to the accessibility-action record's verb enum — a v3 reader
101
+ /// hitting one of those codes would have reported the file corrupt
102
+ /// instead of refusing the skew; v5 added the pinch magnification
103
+ /// `scale` field to gpu-surface input records plus the
91
104
  /// `pinch_begin`/`pinch_change`/`pinch_end` input kinds (codes 12-14);
92
- /// v6 added the `hidden` flag to window-frame records (the
93
- /// `close_policy = .hide` window state — a layout change every v5
94
- /// reader would misparse); v7 added the `.image` effect-result kind
95
- /// (code 11) with its outcome/dimension fields and the blob-store
96
- /// content address (`image_blob_hash`/`image_blob_len`) appended to
97
- /// every effect record — a v6 reader would have called an image
98
- /// record's kind code corrupt and misparsed the longer layouts, so it
99
- /// refuses the skew at the preamble instead.
100
- pub const format_version: u32 = 7;
105
+ /// v6 added the `hidden` flag to window-frame records; v7 added the
106
+ /// `.image` effect-result kind (code 11) with its outcome/dimension
107
+ /// fields and the blob-store content address appended to every effect
108
+ /// record; v8 added the `.channel` effect-result kind (code 12) with
109
+ /// its event kind and cumulative drop total appended to every effect
110
+ /// record. Every one of those changes would now move the fingerprint
111
+ /// with no manual step.
112
+ pub const format_fingerprint: u64 = layout_fingerprint.hash(formatLayoutDescription(format_semantic_epoch));
113
+
114
+ /// The escape hatch for a change in MEANING that leaves the journal
115
+ /// bytes identical, which no layout description can see (the
116
+ /// automation-protocol side had exactly one: context-menu action tokens
117
+ /// becoming per-request generations — same bytes, values a stale build
118
+ /// could never match). Bump this ONLY for such semantics-only changes;
119
+ /// layout changes need NO action here — the fingerprint moves on its
120
+ /// own. Epoch 2: `.video_load` records became one-per-load (refused
121
+ /// cascades journal one too) and replay verifies the bijection — an
122
+ /// earlier journal's failed loads would replay as false divergence, so
123
+ /// the identical bytes must refuse. Epoch 3: the `video_kind` field on
124
+ /// `.video_load` records became the load's OUTCOME (`.loaded` or
125
+ /// `.failed`, steering the replayed fake's synchronous reset) where it
126
+ /// previously rode its default — same bytes, new meaning. Epoch 4:
127
+ /// `pointer_id` on gpu-surface input records reserved bit 63 as the
128
+ /// touch-source stamp (`platform.touch_pointer_id_bit`) — same bytes,
129
+ /// and an older recording whose host happened to emit ids with that
130
+ /// bit set would replay with hover-proof semantics it never had.
131
+ /// Epoch 5: audio positions and durations clamp into the exact-integer
132
+ /// window (below 2^53) at every delivery entry, and replay refuses an
133
+ /// out-of-window audio record as journal damage — an older recording
134
+ /// could journal a wider value the old feed paths accepted, which
135
+ /// would now be misreported as damage instead of refusing as a
136
+ /// different generation.
137
+ pub const format_semantic_epoch: u32 = 5;
138
+
139
+ /// The canonical description `format_fingerprint` hashes: everything
140
+ /// that defines the on-disk record layout. Reflection covers the record
141
+ /// kinds, the event-tag set, every record struct's field names/types/
142
+ /// order, the full effect record (including every journaled effect
143
+ /// enum's names and values), and each event variant's payload type.
144
+ /// Deliberate constants state what the hand-written codecs alone decide
145
+ /// — framing, string/optional/enum encodings, the modifier bit
146
+ /// assignments, the accessibility verb's i32 width, the
147
+ /// `gpu_surface_frame` journaled subset — each commented at its codec.
148
+ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
149
+ comptime {
150
+ @setEvalBranchQuota(2_000_000);
151
+ return "native-sdk session journal layout\n" ++
152
+ std.fmt.comptimePrint("semantic_epoch={d}\n", .{epoch}) ++
153
+ "magic=" ++ magic ++ "\n" ++
154
+ "preamble=magic|u64 format fingerprint le\n" ++
155
+ "framing=u8 kind|u32 payload_len le|payload\n" ++
156
+ // Hand-written codec facts reflection cannot see; the
157
+ // couplings are commented at WriteCursor, writeModifiers,
158
+ // and the widget_accessibility_action arm.
159
+ "codec=ints le;str=u32 len|bytes;bool=u8;enum=u8 of declaration value;optional=u8 presence|payload;" ++
160
+ "modifiers=u8 bits primary=1 command=2 control=4 option=8 shift=16;" ++
161
+ "accessibility action verb=i32;insets=top,right,bottom,left f32;rect=x,y,w,h f32\n" ++
162
+ std.fmt.comptimePrint("max_drop_paths={d} (u16 count)\n", .{max_session_drop_paths}) ++
163
+ "record_kinds=" ++ layout_fingerprint.describe(RecordKind) ++ "\n" ++
164
+ "header=" ++ layout_fingerprint.describe(Header) ++ "\n" ++
165
+ "checkpoint=" ++ layout_fingerprint.describe(Checkpoint) ++ "\n" ++
166
+ "screenshot=" ++ layout_fingerprint.describe(ScreenshotMark) ++ "\n" ++
167
+ "end=" ++ layout_fingerprint.describe(End) ++ "\n" ++
168
+ "effect=" ++ layout_fingerprint.describe(EffectResultRecord) ++ "\n" ++
169
+ "event_tags=" ++ layout_fingerprint.describe(EventTag) ++ "\n" ++
170
+ // Per-variant payload types, reflected. Payload-free tags
171
+ // (app_start, wake, ...) are covered by the tag set above; a
172
+ // NEW tag moves the fingerprint through the tag set even
173
+ // before its payload line lands here. `native_handle` never
174
+ // rides the wire but its type is fixed; describing the full
175
+ // Surface is the conservative direction (a false re-record
176
+ // is cheap, a silent misread is not).
177
+ "appearance_changed=" ++ layout_fingerprint.describe(platform.Appearance) ++ "\n" ++
178
+ "surface_resized=" ++ layout_fingerprint.describe(platform.Surface) ++ "\n" ++
179
+ "window_frame_changed=" ++ layout_fingerprint.describe(platform.WindowState) ++ "\n" ++
180
+ "window_focused=" ++ layout_fingerprint.describe(platform.WindowId) ++ "\n" ++
181
+ "view_focused=" ++ layout_fingerprint.describe(platform.ViewFocusEvent) ++ "\n" ++
182
+ "bridge_message=" ++ layout_fingerprint.describe(platform.BridgeMessage) ++ "\n" ++
183
+ "tray_action=" ++ layout_fingerprint.describe(platform.TrayItemId) ++ "\n" ++
184
+ "shortcut=" ++ layout_fingerprint.describe(platform.ShortcutEvent) ++ "\n" ++
185
+ "native_command=" ++ layout_fingerprint.describe(platform.NativeCommandEvent) ++ "\n" ++
186
+ "menu_command=" ++ layout_fingerprint.describe(platform.MenuCommandEvent) ++ "\n" ++
187
+ "timer=" ++ layout_fingerprint.describe(platform.TimerEvent) ++ "\n" ++
188
+ "audio=" ++ layout_fingerprint.describe(platform.AudioEvent) ++ "\n" ++
189
+ "video=" ++ layout_fingerprint.describe(platform.VideoEvent) ++ "\n" ++
190
+ "files_dropped=" ++ layout_fingerprint.describe(platform.FileDropEvent) ++ "\n" ++
191
+ // gpu_surface_frame journals a deliberate SUBSET of a
192
+ // telemetry-heavy struct (the rest is host render telemetry,
193
+ // meaningless under replay), so its wire layout is stated by
194
+ // hand — the coupling is commented at the encodeEvent arm.
195
+ "gpu_surface_frame=window_id:u64,label:str,width:f32,height:f32,scale_factor:f32," ++
196
+ "frame_index:u64,timestamp_ns:u64,frame_interval_ns:u64,input_timestamp_ns:u64,canvas_frame_full_repaint:bool\n" ++
197
+ "gpu_surface_resized=" ++ layout_fingerprint.describe(platform.GpuSurfaceResizeEvent) ++ "\n" ++
198
+ "gpu_surface_input=" ++ layout_fingerprint.describe(platform.GpuSurfaceInputEvent) ++ "\n" ++
199
+ "gpu_surface_scroll_driver=" ++ layout_fingerprint.describe(platform.GpuSurfaceScrollDriverEvent) ++ "\n" ++
200
+ "context_menu_action=" ++ layout_fingerprint.describe(platform.ContextMenuActionEvent) ++ "\n" ++
201
+ "widget_accessibility_action=" ++ layout_fingerprint.describe(platform.WidgetAccessibilityActionEvent) ++ "\n";
202
+ }
203
+ }
101
204
 
102
205
  // ------------------------------------------------------------- budgets
103
206
  //
@@ -134,9 +237,10 @@ pub const JournalError = error{
134
237
  /// The file does not start with the session-journal magic — it is
135
238
  /// not a journal (or the first bytes were destroyed).
136
239
  JournalBadMagic,
137
- /// The journal was written by a different format version; replaying
138
- /// it here would misread payloads. Re-record with this build.
139
- JournalUnsupportedVersion,
240
+ /// The journal was written by a build whose journal format
241
+ /// fingerprint differs from this one; replaying it here would
242
+ /// misread payloads. Re-record with this build.
243
+ JournalFormatMismatch,
140
244
  /// The byte stream ends mid-record (or the end record is missing):
141
245
  /// the recording was cut off — replay would silently stop early, so
142
246
  /// it refuses instead.
@@ -163,10 +267,11 @@ pub const RecordKind = enum(u8) {
163
267
 
164
268
  /// Session identity, written once as the first record.
165
269
  pub const Header = struct {
166
- /// The automation protocol version baked into the recording build —
167
- /// the existing CLI/app handshake, reused so a journal from a stale
168
- /// build is refused with the same teaching shape.
169
- protocol_version: u32 = automation_protocol.version,
270
+ /// The automation protocol fingerprint baked into the recording
271
+ /// build — the existing CLI/app handshake identity, reused so a
272
+ /// journal from a stale build is refused with the same teaching
273
+ /// shape.
274
+ protocol_fingerprint: u64 = automation_protocol.fingerprint,
170
275
  /// Recording platform ("macos", "linux", ...). Replay is
171
276
  /// same-platform in v1; a cross-platform journal is refused loudly.
172
277
  platform_name: []const u8,
@@ -227,6 +332,13 @@ pub const EventDecodeStorage = struct {
227
332
  };
228
333
 
229
334
  // ------------------------------------------------------------ cursors
335
+ //
336
+ // The primitive encodings these cursors hand-write (little-endian ints,
337
+ // u32-length-prefixed strings, u8 bools, enums as their u8 declaration
338
+ // value, bool-prefixed optionals) are stated as deliberate constants in
339
+ // `formatLayoutDescription` — reflection cannot see them, so changing
340
+ // one here means updating that description's `codec=` line in the same
341
+ // change.
230
342
 
231
343
  const WriteCursor = struct {
232
344
  buffer: []u8,
@@ -350,8 +462,13 @@ const EventTag = enum(u8) {
350
462
  context_menu_action = 22,
351
463
  widget_accessibility_action = 23,
352
464
  audio = 24,
465
+ video = 25,
466
+ view_focused = 26,
353
467
  };
354
468
 
469
+ // The bit assignments below are hand-written wire layout: they are
470
+ // stated in `formatLayoutDescription` (reflection sees the bool fields,
471
+ // not the bits), so changing a bit here means updating that line too.
355
472
  fn writeModifiers(cursor: *WriteCursor, modifiers: platform.ShortcutModifiers) JournalError!void {
356
473
  var bits: u8 = 0;
357
474
  if (modifiers.primary) bits |= 1;
@@ -454,6 +571,11 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
454
571
  try cursor.writeEnum(EventTag.window_focused);
455
572
  try cursor.writeInt(u64, window_id);
456
573
  },
574
+ .view_focused => |focus| {
575
+ try cursor.writeEnum(EventTag.view_focused);
576
+ try cursor.writeInt(u64, focus.window_id);
577
+ try cursor.writeStr(focus.label);
578
+ },
457
579
  .bridge_message => |message| {
458
580
  try cursor.writeEnum(EventTag.bridge_message);
459
581
  try cursor.writeStr(message.bytes);
@@ -500,6 +622,22 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
500
622
  try cursor.writeBool(audio.buffering);
501
623
  try cursor.writeBytes(&audio.bands);
502
624
  },
625
+ // Recorded for stream fidelity like `.audio`. On replay the
626
+ // journaled video EFFECT records are the Msg source; the
627
+ // platform events steer only the channel MIRRORS (the house
628
+ // chrome's render state for handler-less playbacks), gated by
629
+ // the load token exactly as live (`Effects.takeVideoMsg`).
630
+ .video => |video| {
631
+ try cursor.writeEnum(EventTag.video);
632
+ try cursor.writeEnum(video.kind);
633
+ try cursor.writeInt(u64, video.token);
634
+ try cursor.writeInt(u64, video.position_ms);
635
+ try cursor.writeInt(u64, video.duration_ms);
636
+ try cursor.writeBool(video.playing);
637
+ try cursor.writeBool(video.buffering);
638
+ try cursor.writeInt(u64, video.width);
639
+ try cursor.writeInt(u64, video.height);
640
+ },
503
641
  .files_dropped => |drop| {
504
642
  try cursor.writeEnum(EventTag.files_dropped);
505
643
  try cursor.writeInt(u64, drop.window_id);
@@ -513,6 +651,11 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
513
651
  try cursor.writeInt(u16, @intCast(drop.paths.len));
514
652
  for (drop.paths) |path| try cursor.writeStr(path);
515
653
  },
654
+ // This arm journals a deliberate SUBSET of the frame event (the
655
+ // fields dispatch semantics depend on — see the fn doc). The
656
+ // subset is stated by hand in `formatLayoutDescription`, so
657
+ // journaling another field here means adding it to that line in
658
+ // the same change.
516
659
  .gpu_surface_frame => |frame| {
517
660
  try cursor.writeEnum(EventTag.gpu_surface_frame);
518
661
  try cursor.writeInt(u64, frame.window_id);
@@ -561,6 +704,7 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
561
704
  try cursor.writeInt(u64, driver.window_id);
562
705
  try cursor.writeStr(driver.label);
563
706
  try cursor.writeInt(u64, driver.driver_id);
707
+ try cursor.writeF32(driver.offset_x);
564
708
  try cursor.writeF32(driver.offset_y);
565
709
  try cursor.writeInt(u64, driver.timestamp_ns);
566
710
  },
@@ -576,6 +720,8 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
576
720
  try cursor.writeInt(u64, action.window_id);
577
721
  try cursor.writeStr(action.label);
578
722
  try cursor.writeInt(u64, action.id);
723
+ // The verb rides i32, not the u8 every other enum takes — a
724
+ // hand-written width stated in `formatLayoutDescription`.
579
725
  try cursor.writeInt(i32, @intFromEnum(action.action));
580
726
  try cursor.writeStr(action.text);
581
727
  try cursor.writeBool(action.selection != null);
@@ -640,6 +786,10 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
640
786
  } };
641
787
  },
642
788
  .window_focused => .{ .window_focused = try cursor.readInt(u64) },
789
+ .view_focused => .{ .view_focused = .{
790
+ .window_id = try cursor.readInt(u64),
791
+ .label = try cursor.readStr(),
792
+ } },
643
793
  .bridge_message => blk: {
644
794
  const message_bytes = try cursor.readStr();
645
795
  const origin = try cursor.readStr();
@@ -699,6 +849,19 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
699
849
  @memcpy(&decoded.bands, try cursor.readBytes(decoded.bands.len));
700
850
  break :blk .{ .audio = decoded };
701
851
  },
852
+ .video => blk: {
853
+ const kind = try cursor.readEnum(platform.VideoEventKind);
854
+ break :blk .{ .video = .{
855
+ .kind = kind,
856
+ .token = try cursor.readInt(u64),
857
+ .position_ms = try cursor.readInt(u64),
858
+ .duration_ms = try cursor.readInt(u64),
859
+ .playing = try cursor.readBool(),
860
+ .buffering = try cursor.readBool(),
861
+ .width = try cursor.readInt(u64),
862
+ .height = try cursor.readInt(u64),
863
+ } };
864
+ },
702
865
  .files_dropped => blk: {
703
866
  const window_id = try cursor.readInt(u64);
704
867
  const view_label = try cursor.readStr();
@@ -792,11 +955,13 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
792
955
  const window_id = try cursor.readInt(u64);
793
956
  const label = try cursor.readStr();
794
957
  const driver_id = try cursor.readInt(u64);
958
+ const offset_x = try cursor.readF32();
795
959
  const offset_y = try cursor.readF32();
796
960
  break :blk .{ .gpu_surface_scroll_driver = .{
797
961
  .window_id = window_id,
798
962
  .label = label,
799
963
  .driver_id = driver_id,
964
+ .offset_x = offset_x,
800
965
  .offset_y = offset_y,
801
966
  .timestamp_ns = try cursor.readInt(u64),
802
967
  } };
@@ -874,6 +1039,35 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
874
1039
  try cursor.writeInt(u64, record.image_height);
875
1040
  try cursor.writeBytes(&record.image_blob_hash);
876
1041
  try cursor.writeInt(u64, record.image_blob_len);
1042
+ // v8: channel events — the event kind and the occupancy's
1043
+ // cumulative drop total (post bytes ride `payload` inline;
1044
+ // dropped_pending rides the shared `dropped` field).
1045
+ try cursor.writeEnum(record.channel_kind);
1046
+ try cursor.writeInt(u32, record.channel_dropped_total);
1047
+ // Video terminals — the delivered event, verbatim (fingerprint
1048
+ // era: these fields move the format identity through reflection).
1049
+ try cursor.writeEnum(record.video_kind);
1050
+ try cursor.writeInt(u64, record.video_position_ms);
1051
+ try cursor.writeInt(u64, record.video_duration_ms);
1052
+ try cursor.writeBool(record.video_playing);
1053
+ try cursor.writeBool(record.video_buffering);
1054
+ try cursor.writeInt(u64, record.video_width);
1055
+ try cursor.writeInt(u64, record.video_height);
1056
+ // The producing load's identity, how replay routes the record
1057
+ // (`EffectResultRecord.video_token`).
1058
+ try cursor.writeInt(u64, record.video_token);
1059
+ // `.video_load` records: the recording host's cascade resolution.
1060
+ try cursor.writeEnum(record.video_source);
1061
+ // `.video` records: whether the delivery dispatched a Msg.
1062
+ try cursor.writeBool(record.video_handled);
1063
+ // Pty events — the event kind, the terminating signal and refused
1064
+ // writes, and the blob store content address of a journaled output
1065
+ // batch (exit code and reason ride the shared fields).
1066
+ try cursor.writeEnum(record.pty_kind);
1067
+ try cursor.writeInt(i32, record.pty_signal);
1068
+ try cursor.writeInt(u32, record.pty_dropped_writes);
1069
+ try cursor.writeBytes(&record.pty_blob_hash);
1070
+ try cursor.writeInt(u64, record.pty_blob_len);
877
1071
  return buffer[0..cursor.len];
878
1072
  }
879
1073
 
@@ -912,6 +1106,26 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
912
1106
  record.image_height = try cursor.readInt(u64);
913
1107
  @memcpy(&record.image_blob_hash, try cursor.readBytes(record.image_blob_hash.len));
914
1108
  record.image_blob_len = try cursor.readInt(u64);
1109
+ // v8: channel events.
1110
+ record.channel_kind = try cursor.readEnum(runtime_effects.EffectChannelEventKind);
1111
+ record.channel_dropped_total = try cursor.readInt(u32);
1112
+ // Video terminals.
1113
+ record.video_kind = try cursor.readEnum(runtime_effects.EffectVideoEventKind);
1114
+ record.video_position_ms = try cursor.readInt(u64);
1115
+ record.video_duration_ms = try cursor.readInt(u64);
1116
+ record.video_playing = try cursor.readBool();
1117
+ record.video_buffering = try cursor.readBool();
1118
+ record.video_width = try cursor.readInt(u64);
1119
+ record.video_height = try cursor.readInt(u64);
1120
+ record.video_token = try cursor.readInt(u64);
1121
+ record.video_source = try cursor.readEnum(runtime_effects.EffectVideoSource);
1122
+ record.video_handled = try cursor.readBool();
1123
+ // Pty events.
1124
+ record.pty_kind = try cursor.readEnum(runtime_effects.EffectPtyEventKind);
1125
+ record.pty_signal = try cursor.readInt(i32);
1126
+ record.pty_dropped_writes = try cursor.readInt(u32);
1127
+ @memcpy(&record.pty_blob_hash, try cursor.readBytes(record.pty_blob_hash.len));
1128
+ record.pty_blob_len = try cursor.readInt(u64);
915
1129
  if (!cursor.done()) return error.JournalCorrupt;
916
1130
  return record;
917
1131
  }
@@ -920,7 +1134,7 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
920
1134
 
921
1135
  pub fn encodeHeader(header: Header, buffer: []u8) JournalError![]const u8 {
922
1136
  var cursor = WriteCursor{ .buffer = buffer };
923
- try cursor.writeInt(u32, header.protocol_version);
1137
+ try cursor.writeInt(u64, header.protocol_fingerprint);
924
1138
  try cursor.writeStr(header.platform_name);
925
1139
  try cursor.writeStr(header.app_name);
926
1140
  try cursor.writeInt(i64, header.recorded_at_wall_ms);
@@ -932,7 +1146,7 @@ pub fn encodeHeader(header: Header, buffer: []u8) JournalError![]const u8 {
932
1146
  pub fn decodeHeader(bytes: []const u8) JournalError!Header {
933
1147
  var cursor = ReadCursor{ .bytes = bytes };
934
1148
  const header: Header = .{
935
- .protocol_version = try cursor.readInt(u32),
1149
+ .protocol_fingerprint = try cursor.readInt(u64),
936
1150
  .platform_name = try cursor.readStr(),
937
1151
  .app_name = try cursor.readStr(),
938
1152
  .recorded_at_wall_ms = try cursor.readInt(i64),
@@ -1020,14 +1234,18 @@ pub fn frameRecord(kind: RecordKind, payload: []const u8, buffer: []u8) JournalE
1020
1234
  return buffer[0 .. 5 + payload.len];
1021
1235
  }
1022
1236
 
1023
- /// The journal preamble (magic + format version).
1237
+ /// The journal preamble (magic + format fingerprint). The fingerprint
1238
+ /// field widened from the retired u32 counter to the full u64 hash when
1239
+ /// identity replaced ordering — this change refuses every older journal
1240
+ /// anyway, and the full width keeps the refuse-on-mismatch tripwire's
1241
+ /// collision odds at 2^-64 instead of 2^-32 for free.
1024
1242
  pub fn writePreamble(buffer: []u8) []const u8 {
1025
1243
  @memcpy(buffer[0..magic.len], magic);
1026
- std.mem.writeInt(u32, buffer[magic.len..][0..4], format_version, .little);
1027
- return buffer[0 .. magic.len + 4];
1244
+ std.mem.writeInt(u64, buffer[magic.len..][0..8], format_fingerprint, .little);
1245
+ return buffer[0 .. magic.len + 8];
1028
1246
  }
1029
1247
 
1030
- pub const preamble_len: usize = magic.len + 4;
1248
+ pub const preamble_len: usize = magic.len + 8;
1031
1249
 
1032
1250
  /// Sequential journal reader over a whole in-memory journal. Validates
1033
1251
  /// the preamble at init, enforces record budgets, and requires header
@@ -1048,8 +1266,8 @@ pub const Reader = struct {
1048
1266
  pub fn init(bytes: []const u8) JournalError!Reader {
1049
1267
  if (bytes.len < preamble_len) return error.JournalBadMagic;
1050
1268
  if (!std.mem.eql(u8, bytes[0..magic.len], magic)) return error.JournalBadMagic;
1051
- const version = std.mem.readInt(u32, bytes[magic.len..][0..4], .little);
1052
- if (version != format_version) return error.JournalUnsupportedVersion;
1269
+ const recorded = std.mem.readInt(u64, bytes[magic.len..][0..8], .little);
1270
+ if (recorded != format_fingerprint) return error.JournalFormatMismatch;
1053
1271
  return .{ .bytes = bytes, .pos = preamble_len };
1054
1272
  }
1055
1273
 
@@ -1115,7 +1333,7 @@ pub const Reader = struct {
1115
1333
  pub fn describeError(err: JournalError) []const u8 {
1116
1334
  return switch (err) {
1117
1335
  error.JournalBadMagic => "not a session journal (bad magic) - record one with NATIVE_SDK_SESSION_RECORD=<path>",
1118
- error.JournalUnsupportedVersion => std.fmt.comptimePrint("journal format version differs from the v{d} this build reads and writes - re-record the session with the same build that replays it", .{format_version}),
1336
+ error.JournalFormatMismatch => "journal was recorded by a build whose journal format differs from this build's - re-record the session with the same build that replays it",
1119
1337
  error.JournalTruncated => "journal ends mid-record (the recording was cut off) - re-record, and keep the app running until it exits cleanly",
1120
1338
  error.JournalCorrupt => "journal payload does not decode (damaged or hand-edited bytes)",
1121
1339
  error.JournalRecordOverBudget => "journal claims a record beyond max_session_record_bytes - the file is damaged or hostile",
@@ -1246,6 +1464,25 @@ test "event codec round-trips every payload variant" {
1246
1464
  try testing.expect(decoded.audio.playing);
1247
1465
  try testing.expectEqualSlices(u8, &bands, &decoded.audio.bands);
1248
1466
  }
1467
+ {
1468
+ // Video events journal the whole shape including the stream
1469
+ // dimensions the `.loaded` acknowledgment carries.
1470
+ const decoded = try roundTripEvent(.{ .video = .{
1471
+ .kind = .loaded,
1472
+ .position_ms = 0,
1473
+ .duration_ms = 92_500,
1474
+ .playing = true,
1475
+ .buffering = true,
1476
+ .width = 1280,
1477
+ .height = 720,
1478
+ } });
1479
+ try testing.expectEqual(platform.VideoEventKind.loaded, decoded.video.kind);
1480
+ try testing.expectEqual(@as(u64, 92_500), decoded.video.duration_ms);
1481
+ try testing.expect(decoded.video.playing);
1482
+ try testing.expect(decoded.video.buffering);
1483
+ try testing.expectEqual(@as(u64, 1280), decoded.video.width);
1484
+ try testing.expectEqual(@as(u64, 720), decoded.video.height);
1485
+ }
1249
1486
  {
1250
1487
  const paths = [_][]const u8{ "/tmp/a.txt", "/tmp/b.txt" };
1251
1488
  const decoded = try roundTripEvent(.{ .files_dropped = .{
@@ -1325,10 +1562,12 @@ test "event codec round-trips every payload variant" {
1325
1562
  const decoded = try roundTripEvent(.{ .gpu_surface_scroll_driver = .{
1326
1563
  .label = "canvas",
1327
1564
  .driver_id = 88,
1565
+ .offset_x = 7.25,
1328
1566
  .offset_y = -12.5,
1329
1567
  .timestamp_ns = 4,
1330
1568
  } });
1331
1569
  try testing.expectEqual(@as(f32, -12.5), decoded.gpu_surface_scroll_driver.offset_y);
1570
+ try testing.expectEqual(@as(f32, 7.25), decoded.gpu_surface_scroll_driver.offset_x);
1332
1571
  }
1333
1572
  {
1334
1573
  const decoded = try roundTripEvent(.{ .context_menu_action = .{ .view_label = "canvas", .token = 5, .item_id = 2 } });
@@ -1350,6 +1589,11 @@ test "event codec round-trips every payload variant" {
1350
1589
  const decoded = try roundTripEvent(.{ .window_focused = 4 });
1351
1590
  try testing.expectEqual(@as(u64, 4), decoded.window_focused);
1352
1591
  }
1592
+ {
1593
+ const decoded = try roundTripEvent(.{ .view_focused = .{ .window_id = 4, .label = "preview" } });
1594
+ try testing.expectEqual(@as(u64, 4), decoded.view_focused.window_id);
1595
+ try testing.expectEqualStrings("preview", decoded.view_focused.label);
1596
+ }
1353
1597
  {
1354
1598
  const decoded = try roundTripEvent(.{ .gpu_surface_resized = .{
1355
1599
  .label = "canvas",
@@ -1427,6 +1671,59 @@ test "effect codec round-trips payloads and outcomes" {
1427
1671
  const spectrum_decoded = try decodeEffect(spectrum_encoded);
1428
1672
  try testing.expectEqual(runtime_effects.EffectAudioEventKind.spectrum, spectrum_decoded.audio_kind);
1429
1673
  try testing.expectEqualSlices(u8, &spectrum_bands, &spectrum_decoded.audio_bands);
1674
+
1675
+ // v8: channel records carry their event kind and the cumulative
1676
+ // drop total; the post bytes ride the shared payload field INLINE
1677
+ // (never the blob store).
1678
+ const channel_encoded = try encodeEffect(.{
1679
+ .kind = .channel,
1680
+ .key = 88,
1681
+ .payload = "cpu 12.5",
1682
+ .dropped = 2,
1683
+ .channel_kind = .data,
1684
+ .channel_dropped_total = 7,
1685
+ }, &buffer);
1686
+ const channel_decoded = try decodeEffect(channel_encoded);
1687
+ try testing.expectEqual(runtime_effects.EffectResultKind.channel, channel_decoded.kind);
1688
+ try testing.expectEqual(@as(u64, 88), channel_decoded.key);
1689
+ try testing.expectEqualStrings("cpu 12.5", channel_decoded.payload);
1690
+ try testing.expectEqual(runtime_effects.EffectChannelEventKind.data, channel_decoded.channel_kind);
1691
+ try testing.expectEqual(@as(u32, 2), channel_decoded.dropped);
1692
+ try testing.expectEqual(@as(u32, 7), channel_decoded.channel_dropped_total);
1693
+
1694
+ const closed_encoded = try encodeEffect(.{
1695
+ .kind = .channel,
1696
+ .key = 88,
1697
+ .channel_kind = .closed,
1698
+ .channel_dropped_total = 7,
1699
+ }, &buffer);
1700
+ const closed_decoded = try decodeEffect(closed_encoded);
1701
+ try testing.expectEqual(runtime_effects.EffectChannelEventKind.closed, closed_decoded.channel_kind);
1702
+ try testing.expectEqual(@as(usize, 0), closed_decoded.payload.len);
1703
+
1704
+ // Video effect records round-trip the whole delivered event —
1705
+ // including the dimensions the `.loaded` acknowledgment carries —
1706
+ // because the journaled record is replay's only Msg source.
1707
+ const video_encoded = try encodeEffect(.{
1708
+ .kind = .video,
1709
+ .key = 61,
1710
+ .video_kind = .loaded,
1711
+ .video_position_ms = 0,
1712
+ .video_duration_ms = 92_500,
1713
+ .video_playing = true,
1714
+ .video_buffering = true,
1715
+ .video_width = 1280,
1716
+ .video_height = 720,
1717
+ }, &buffer);
1718
+ const video_decoded = try decodeEffect(video_encoded);
1719
+ try testing.expectEqual(runtime_effects.EffectResultKind.video, video_decoded.kind);
1720
+ try testing.expectEqual(@as(u64, 61), video_decoded.key);
1721
+ try testing.expectEqual(runtime_effects.EffectVideoEventKind.loaded, video_decoded.video_kind);
1722
+ try testing.expectEqual(@as(u64, 92_500), video_decoded.video_duration_ms);
1723
+ try testing.expect(video_decoded.video_playing);
1724
+ try testing.expect(video_decoded.video_buffering);
1725
+ try testing.expectEqual(@as(u64, 1280), video_decoded.video_width);
1726
+ try testing.expectEqual(@as(u64, 720), video_decoded.video_height);
1430
1727
  }
1431
1728
 
1432
1729
  test "header, checkpoint, screenshot, and end codecs round-trip" {
@@ -1440,7 +1737,7 @@ test "header, checkpoint, screenshot, and end codecs round-trip" {
1440
1737
  }, &buffer));
1441
1738
  try testing.expectEqualStrings("macos", header.platform_name);
1442
1739
  try testing.expectEqualStrings("calculator", header.app_name);
1443
- try testing.expectEqual(automation_protocol.version, header.protocol_version);
1740
+ try testing.expectEqual(automation_protocol.fingerprint, header.protocol_fingerprint);
1444
1741
 
1445
1742
  const checkpoint = try decodeCheckpoint(try encodeCheckpoint(.{ .event_ordinal = 10, .frame_index = 4, .fingerprint = 0xdead }, &buffer));
1446
1743
  try testing.expectEqual(@as(u64, 0xdead), checkpoint.fingerprint);
@@ -1510,36 +1807,45 @@ test "reader walks a whole journal and stops at the end record" {
1510
1807
  try testing.expectEqual(@as(?Record, null), try reader.next());
1511
1808
  }
1512
1809
 
1513
- test "reader refuses bad magic and version skew" {
1810
+ test "reader refuses bad magic and format skew" {
1514
1811
  var buffer: [16384]u8 = undefined;
1515
1812
  const len = try buildTestJournal(&buffer);
1516
1813
  try testing.expectError(error.JournalBadMagic, Reader.init("not a journal at all"));
1517
1814
  try testing.expectError(error.JournalBadMagic, Reader.init(""));
1815
+ // A journal whose recorded fingerprint differs from this build's —
1816
+ // any other build's journal, in either direction — is refused at
1817
+ // the preamble, before any record layout is consulted, instead of
1818
+ // reporting an unknown payload code as corruption.
1518
1819
  var skewed: [16384]u8 = undefined;
1519
1820
  @memcpy(skewed[0..len], buffer[0..len]);
1520
- std.mem.writeInt(u32, skewed[magic.len..][0..4], format_version + 1, .little);
1521
- try testing.expectError(error.JournalUnsupportedVersion, Reader.init(skewed[0..len]));
1522
- // Older journals are refused the same way — and, symmetrically, a
1523
- // reader built before a version bump refuses a NEWER journal at the
1524
- // preamble instead of reporting an unknown payload code as
1525
- // corruption (the v4 bump's reason: v3 readers would have called a
1526
- // journaled composition verb code corrupt).
1527
- std.mem.writeInt(u32, skewed[magic.len..][0..4], format_version - 1, .little);
1528
- try testing.expectError(error.JournalUnsupportedVersion, Reader.init(skewed[0..len]));
1529
- // A concrete v6 journal (the version main ships, without the image
1530
- // fields on effect records) is version skew, never corruption: the
1531
- // preamble gate must fire before any record layout is consulted.
1532
- var v6_preamble: [preamble_len]u8 = undefined;
1533
- @memcpy(v6_preamble[0..magic.len], magic);
1534
- std.mem.writeInt(u32, v6_preamble[magic.len..][0..4], 6, .little);
1535
- try testing.expectError(error.JournalUnsupportedVersion, Reader.init(&v6_preamble));
1536
- // The teaching names the version this build speaks, so the reader of
1537
- // the error can see the skew rather than suspect file damage.
1538
- const teaching = describeError(error.JournalUnsupportedVersion);
1539
- try testing.expect(std.mem.indexOf(u8, teaching, "v7") != null);
1821
+ std.mem.writeInt(u64, skewed[magic.len..][0..8], format_fingerprint +% 1, .little);
1822
+ try testing.expectError(error.JournalFormatMismatch, Reader.init(skewed[0..len]));
1823
+ std.mem.writeInt(u64, skewed[magic.len..][0..8], format_fingerprint -% 1, .little);
1824
+ try testing.expectError(error.JournalFormatMismatch, Reader.init(skewed[0..len]));
1825
+ // A journal from the retired integer-counter era (u32 version after
1826
+ // the magic, so this reader's u64 read spans the counter plus the
1827
+ // first record's framing bytes) is the same honest mismatch.
1828
+ var legacy: [preamble_len]u8 = undefined;
1829
+ @memcpy(legacy[0..magic.len], magic);
1830
+ std.mem.writeInt(u32, legacy[magic.len..][0..4], 8, .little);
1831
+ legacy[magic.len + 4] = @intFromEnum(RecordKind.header);
1832
+ std.mem.writeInt(u24, legacy[magic.len + 5 ..][0..3], 42, .little);
1833
+ try testing.expectError(error.JournalFormatMismatch, Reader.init(&legacy));
1834
+ // The teaching says whose build differs and what to do about it,
1835
+ // so the reader of the error never suspects file damage.
1836
+ const teaching = describeError(error.JournalFormatMismatch);
1837
+ try testing.expect(std.mem.indexOf(u8, teaching, "journal format") != null);
1540
1838
  try testing.expect(std.mem.indexOf(u8, teaching, "re-record") != null);
1541
1839
  }
1542
1840
 
1841
+ test "layout description moves with the semantic epoch" {
1842
+ // Same layout, bumped epoch: the combined fingerprint must move, so
1843
+ // a meaning-only change (identical bytes) still refuses replay of
1844
+ // journals recorded before it.
1845
+ const bumped = layout_fingerprint.hash(comptime formatLayoutDescription(format_semantic_epoch + 1));
1846
+ try testing.expect(bumped != format_fingerprint);
1847
+ }
1848
+
1543
1849
  test "reader fails loudly on truncation at every boundary" {
1544
1850
  var buffer: [16384]u8 = undefined;
1545
1851
  const len = try buildTestJournal(&buffer);