@native-sdk/cli 0.5.3 → 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 (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -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 +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  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 +3187 -264
  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 +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -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
@@ -40,9 +40,20 @@
40
40
  //! that consumes it. Nested dispatches (automation-driven events inside
41
41
  //! `frame_requested`) commit innermost-first for the same reason.
42
42
  //!
43
+ //! That feed-then-dispatch premise only holds if event boundaries are
44
+ //! CAUSAL: every result journaled ahead of an event must answer a
45
+ //! request issued by some EARLIER dispatch — otherwise the file-order
46
+ //! feed reaches a result whose request does not exist yet and replay
47
+ //! reports a false divergence. The live drain guarantees it: one drain
48
+ //! pass consumes only completions that existed when the pass began
49
+ //! (`Effects.DrainBoundary`), so a load spawned by an update handler
50
+ //! inside the pass — even one fast enough to finish before the pass
51
+ //! ends — delivers, and journals, under the NEXT wake's event record.
52
+ //!
43
53
  //! Enum payloads ride as their declaration-order integer values, so
44
- //! reordering any journaled enum is a format break: bump
45
- //! `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).
46
57
  //!
47
58
  //! Coverage note: automation driving is fully journaled. Verbs that
48
59
  //! synthesize PLATFORM events (widget-click/hold/context-press/drag/
@@ -60,6 +71,7 @@ const std = @import("std");
60
71
  const geometry = @import("geometry");
61
72
  const platform = @import("../platform/root.zig");
62
73
  const automation_protocol = @import("../automation/protocol.zig");
74
+ const layout_fingerprint = @import("../automation/layout_fingerprint.zig");
63
75
  const runtime_effects = @import("effects.zig");
64
76
 
65
77
  pub const EffectResultRecord = runtime_effects.EffectResultRecord;
@@ -67,19 +79,128 @@ pub const EffectResultRecord = runtime_effects.EffectResultRecord;
67
79
  /// File magic: first eight bytes of every session journal.
68
80
  pub const magic = "NSDKSJNL";
69
81
 
70
- /// Journal format version. Any change to record layouts or journaled
71
- /// enum orders bumps this; readers refuse other versions loudly rather
72
- /// than misreading yesterday's shape. v2 added the stream `buffering`
73
- /// flag to audio event and audio effect records; v3 added the spectrum
74
- /// band bytes to both (and the `.spectrum` audio kind); v4 added the
75
- /// composition verbs (`set_composition`/`commit_composition`/
76
- /// `cancel_composition`, codes 11-13) to the accessibility-action
77
- /// record's verb enum — a v3 reader hitting one of those codes would
78
- /// have reported the file corrupt instead of refusing the skew; v5
79
- /// added the pinch magnification `scale` field to gpu-surface input
80
- /// records (a layout change every v4 reader would misparse) plus the
81
- /// `pinch_begin`/`pinch_change`/`pinch_end` input kinds (codes 12-14).
82
- pub const format_version: u32 = 5;
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
104
+ /// `pinch_begin`/`pinch_change`/`pinch_end` input kinds (codes 12-14);
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
+ }
83
204
 
84
205
  // ------------------------------------------------------------- budgets
85
206
  //
@@ -116,9 +237,10 @@ pub const JournalError = error{
116
237
  /// The file does not start with the session-journal magic — it is
117
238
  /// not a journal (or the first bytes were destroyed).
118
239
  JournalBadMagic,
119
- /// The journal was written by a different format version; replaying
120
- /// it here would misread payloads. Re-record with this build.
121
- 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,
122
244
  /// The byte stream ends mid-record (or the end record is missing):
123
245
  /// the recording was cut off — replay would silently stop early, so
124
246
  /// it refuses instead.
@@ -145,10 +267,11 @@ pub const RecordKind = enum(u8) {
145
267
 
146
268
  /// Session identity, written once as the first record.
147
269
  pub const Header = struct {
148
- /// The automation protocol version baked into the recording build —
149
- /// the existing CLI/app handshake, reused so a journal from a stale
150
- /// build is refused with the same teaching shape.
151
- 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,
152
275
  /// Recording platform ("macos", "linux", ...). Replay is
153
276
  /// same-platform in v1; a cross-platform journal is refused loudly.
154
277
  platform_name: []const u8,
@@ -209,6 +332,13 @@ pub const EventDecodeStorage = struct {
209
332
  };
210
333
 
211
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.
212
342
 
213
343
  const WriteCursor = struct {
214
344
  buffer: []u8,
@@ -332,8 +462,13 @@ const EventTag = enum(u8) {
332
462
  context_menu_action = 22,
333
463
  widget_accessibility_action = 23,
334
464
  audio = 24,
465
+ video = 25,
466
+ view_focused = 26,
335
467
  };
336
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.
337
472
  fn writeModifiers(cursor: *WriteCursor, modifiers: platform.ShortcutModifiers) JournalError!void {
338
473
  var bits: u8 = 0;
339
474
  if (modifiers.primary) bits |= 1;
@@ -429,11 +564,18 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
429
564
  try cursor.writeBool(state.focused);
430
565
  try cursor.writeBool(state.maximized);
431
566
  try cursor.writeBool(state.fullscreen);
567
+ // v6: alive-but-policy-hidden (`close_policy = .hide`).
568
+ try cursor.writeBool(state.hidden);
432
569
  },
433
570
  .window_focused => |window_id| {
434
571
  try cursor.writeEnum(EventTag.window_focused);
435
572
  try cursor.writeInt(u64, window_id);
436
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
+ },
437
579
  .bridge_message => |message| {
438
580
  try cursor.writeEnum(EventTag.bridge_message);
439
581
  try cursor.writeStr(message.bytes);
@@ -480,6 +622,22 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
480
622
  try cursor.writeBool(audio.buffering);
481
623
  try cursor.writeBytes(&audio.bands);
482
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
+ },
483
641
  .files_dropped => |drop| {
484
642
  try cursor.writeEnum(EventTag.files_dropped);
485
643
  try cursor.writeInt(u64, drop.window_id);
@@ -493,6 +651,11 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
493
651
  try cursor.writeInt(u16, @intCast(drop.paths.len));
494
652
  for (drop.paths) |path| try cursor.writeStr(path);
495
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.
496
659
  .gpu_surface_frame => |frame| {
497
660
  try cursor.writeEnum(EventTag.gpu_surface_frame);
498
661
  try cursor.writeInt(u64, frame.window_id);
@@ -541,6 +704,7 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
541
704
  try cursor.writeInt(u64, driver.window_id);
542
705
  try cursor.writeStr(driver.label);
543
706
  try cursor.writeInt(u64, driver.driver_id);
707
+ try cursor.writeF32(driver.offset_x);
544
708
  try cursor.writeF32(driver.offset_y);
545
709
  try cursor.writeInt(u64, driver.timestamp_ns);
546
710
  },
@@ -556,6 +720,8 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
556
720
  try cursor.writeInt(u64, action.window_id);
557
721
  try cursor.writeStr(action.label);
558
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`.
559
725
  try cursor.writeInt(i32, @intFromEnum(action.action));
560
726
  try cursor.writeStr(action.text);
561
727
  try cursor.writeBool(action.selection != null);
@@ -616,9 +782,14 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
616
782
  .focused = try cursor.readBool(),
617
783
  .maximized = try cursor.readBool(),
618
784
  .fullscreen = try cursor.readBool(),
785
+ .hidden = try cursor.readBool(),
619
786
  } };
620
787
  },
621
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
+ } },
622
793
  .bridge_message => blk: {
623
794
  const message_bytes = try cursor.readStr();
624
795
  const origin = try cursor.readStr();
@@ -678,6 +849,19 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
678
849
  @memcpy(&decoded.bands, try cursor.readBytes(decoded.bands.len));
679
850
  break :blk .{ .audio = decoded };
680
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
+ },
681
865
  .files_dropped => blk: {
682
866
  const window_id = try cursor.readInt(u64);
683
867
  const view_label = try cursor.readStr();
@@ -745,35 +929,39 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
745
929
  if (try cursor.readBool()) {
746
930
  composition_cursor = std.math.cast(usize, try cursor.readInt(u64)) orelse return error.JournalCorrupt;
747
931
  }
748
- break :blk .{ .gpu_surface_input = .{
749
- .window_id = window_id,
750
- .label = label,
751
- .kind = kind,
752
- .timestamp_ns = timestamp_ns,
753
- .pointer_id = pointer_id,
754
- .x = x,
755
- .y = y,
756
- .button = button,
757
- .pressure = pressure,
758
- .delta_x = delta_x,
759
- .delta_y = delta_y,
760
- .key = key,
761
- .text = text,
762
- .composition_cursor = composition_cursor,
763
- .modifiers = try readModifiers(&cursor),
764
- // v5: the pinch magnification delta (0 on non-pinch kinds).
765
- .scale = try cursor.readF32(),
766
- } };
932
+ break :blk .{
933
+ .gpu_surface_input = .{
934
+ .window_id = window_id,
935
+ .label = label,
936
+ .kind = kind,
937
+ .timestamp_ns = timestamp_ns,
938
+ .pointer_id = pointer_id,
939
+ .x = x,
940
+ .y = y,
941
+ .button = button,
942
+ .pressure = pressure,
943
+ .delta_x = delta_x,
944
+ .delta_y = delta_y,
945
+ .key = key,
946
+ .text = text,
947
+ .composition_cursor = composition_cursor,
948
+ .modifiers = try readModifiers(&cursor),
949
+ // v5: the pinch magnification delta (0 on non-pinch kinds).
950
+ .scale = try cursor.readF32(),
951
+ },
952
+ };
767
953
  },
768
954
  .gpu_surface_scroll_driver => blk: {
769
955
  const window_id = try cursor.readInt(u64);
770
956
  const label = try cursor.readStr();
771
957
  const driver_id = try cursor.readInt(u64);
958
+ const offset_x = try cursor.readF32();
772
959
  const offset_y = try cursor.readF32();
773
960
  break :blk .{ .gpu_surface_scroll_driver = .{
774
961
  .window_id = window_id,
775
962
  .label = label,
776
963
  .driver_id = driver_id,
964
+ .offset_x = offset_x,
777
965
  .offset_y = offset_y,
778
966
  .timestamp_ns = try cursor.readInt(u64),
779
967
  } };
@@ -844,6 +1032,42 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
844
1032
  try cursor.writeBool(record.audio_playing);
845
1033
  try cursor.writeBool(record.audio_buffering);
846
1034
  try cursor.writeBytes(&record.audio_bands);
1035
+ // v7: image terminals — outcome, decoded dimensions, and the blob
1036
+ // store content address of the journaled source bytes.
1037
+ try cursor.writeEnum(record.image_outcome);
1038
+ try cursor.writeInt(u64, record.image_width);
1039
+ try cursor.writeInt(u64, record.image_height);
1040
+ try cursor.writeBytes(&record.image_blob_hash);
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);
847
1071
  return buffer[0..cursor.len];
848
1072
  }
849
1073
 
@@ -876,6 +1100,32 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
876
1100
  .audio_buffering = try cursor.readBool(),
877
1101
  };
878
1102
  @memcpy(&record.audio_bands, try cursor.readBytes(record.audio_bands.len));
1103
+ // v7: image terminals.
1104
+ record.image_outcome = try cursor.readEnum(runtime_effects.EffectImageOutcome);
1105
+ record.image_width = try cursor.readInt(u64);
1106
+ record.image_height = try cursor.readInt(u64);
1107
+ @memcpy(&record.image_blob_hash, try cursor.readBytes(record.image_blob_hash.len));
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);
879
1129
  if (!cursor.done()) return error.JournalCorrupt;
880
1130
  return record;
881
1131
  }
@@ -884,7 +1134,7 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
884
1134
 
885
1135
  pub fn encodeHeader(header: Header, buffer: []u8) JournalError![]const u8 {
886
1136
  var cursor = WriteCursor{ .buffer = buffer };
887
- try cursor.writeInt(u32, header.protocol_version);
1137
+ try cursor.writeInt(u64, header.protocol_fingerprint);
888
1138
  try cursor.writeStr(header.platform_name);
889
1139
  try cursor.writeStr(header.app_name);
890
1140
  try cursor.writeInt(i64, header.recorded_at_wall_ms);
@@ -896,7 +1146,7 @@ pub fn encodeHeader(header: Header, buffer: []u8) JournalError![]const u8 {
896
1146
  pub fn decodeHeader(bytes: []const u8) JournalError!Header {
897
1147
  var cursor = ReadCursor{ .bytes = bytes };
898
1148
  const header: Header = .{
899
- .protocol_version = try cursor.readInt(u32),
1149
+ .protocol_fingerprint = try cursor.readInt(u64),
900
1150
  .platform_name = try cursor.readStr(),
901
1151
  .app_name = try cursor.readStr(),
902
1152
  .recorded_at_wall_ms = try cursor.readInt(i64),
@@ -984,14 +1234,18 @@ pub fn frameRecord(kind: RecordKind, payload: []const u8, buffer: []u8) JournalE
984
1234
  return buffer[0 .. 5 + payload.len];
985
1235
  }
986
1236
 
987
- /// 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.
988
1242
  pub fn writePreamble(buffer: []u8) []const u8 {
989
1243
  @memcpy(buffer[0..magic.len], magic);
990
- std.mem.writeInt(u32, buffer[magic.len..][0..4], format_version, .little);
991
- 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];
992
1246
  }
993
1247
 
994
- pub const preamble_len: usize = magic.len + 4;
1248
+ pub const preamble_len: usize = magic.len + 8;
995
1249
 
996
1250
  /// Sequential journal reader over a whole in-memory journal. Validates
997
1251
  /// the preamble at init, enforces record budgets, and requires header
@@ -1012,8 +1266,8 @@ pub const Reader = struct {
1012
1266
  pub fn init(bytes: []const u8) JournalError!Reader {
1013
1267
  if (bytes.len < preamble_len) return error.JournalBadMagic;
1014
1268
  if (!std.mem.eql(u8, bytes[0..magic.len], magic)) return error.JournalBadMagic;
1015
- const version = std.mem.readInt(u32, bytes[magic.len..][0..4], .little);
1016
- 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;
1017
1271
  return .{ .bytes = bytes, .pos = preamble_len };
1018
1272
  }
1019
1273
 
@@ -1079,7 +1333,7 @@ pub const Reader = struct {
1079
1333
  pub fn describeError(err: JournalError) []const u8 {
1080
1334
  return switch (err) {
1081
1335
  error.JournalBadMagic => "not a session journal (bad magic) - record one with NATIVE_SDK_SESSION_RECORD=<path>",
1082
- 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",
1083
1337
  error.JournalTruncated => "journal ends mid-record (the recording was cut off) - re-record, and keep the app running until it exits cleanly",
1084
1338
  error.JournalCorrupt => "journal payload does not decode (damaged or hand-edited bytes)",
1085
1339
  error.JournalRecordOverBudget => "journal claims a record beyond max_session_record_bytes - the file is damaged or hostile",
@@ -1137,6 +1391,22 @@ test "event codec round-trips every payload variant" {
1137
1391
  } });
1138
1392
  try testing.expectEqualStrings("settings", decoded.window_frame_changed.label);
1139
1393
  try testing.expect(!decoded.window_frame_changed.open);
1394
+ try testing.expect(!decoded.window_frame_changed.hidden);
1395
+ }
1396
+ {
1397
+ // v6: a policy-hide keeps the window alive (`open` true) and
1398
+ // rides the `hidden` flag — both must survive the round trip.
1399
+ const decoded = try roundTripEvent(.{ .window_frame_changed = .{
1400
+ .id = 1,
1401
+ .label = "main",
1402
+ .title = "Player",
1403
+ .frame = geometry.RectF.init(0, 0, 480, 360),
1404
+ .open = true,
1405
+ .focused = false,
1406
+ .hidden = true,
1407
+ } });
1408
+ try testing.expect(decoded.window_frame_changed.open);
1409
+ try testing.expect(decoded.window_frame_changed.hidden);
1140
1410
  }
1141
1411
  {
1142
1412
  const decoded = try roundTripEvent(.{ .bridge_message = .{
@@ -1194,6 +1464,25 @@ test "event codec round-trips every payload variant" {
1194
1464
  try testing.expect(decoded.audio.playing);
1195
1465
  try testing.expectEqualSlices(u8, &bands, &decoded.audio.bands);
1196
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
+ }
1197
1486
  {
1198
1487
  const paths = [_][]const u8{ "/tmp/a.txt", "/tmp/b.txt" };
1199
1488
  const decoded = try roundTripEvent(.{ .files_dropped = .{
@@ -1273,10 +1562,12 @@ test "event codec round-trips every payload variant" {
1273
1562
  const decoded = try roundTripEvent(.{ .gpu_surface_scroll_driver = .{
1274
1563
  .label = "canvas",
1275
1564
  .driver_id = 88,
1565
+ .offset_x = 7.25,
1276
1566
  .offset_y = -12.5,
1277
1567
  .timestamp_ns = 4,
1278
1568
  } });
1279
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);
1280
1571
  }
1281
1572
  {
1282
1573
  const decoded = try roundTripEvent(.{ .context_menu_action = .{ .view_label = "canvas", .token = 5, .item_id = 2 } });
@@ -1298,6 +1589,11 @@ test "event codec round-trips every payload variant" {
1298
1589
  const decoded = try roundTripEvent(.{ .window_focused = 4 });
1299
1590
  try testing.expectEqual(@as(u64, 4), decoded.window_focused);
1300
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
+ }
1301
1597
  {
1302
1598
  const decoded = try roundTripEvent(.{ .gpu_surface_resized = .{
1303
1599
  .label = "canvas",
@@ -1375,6 +1671,59 @@ test "effect codec round-trips payloads and outcomes" {
1375
1671
  const spectrum_decoded = try decodeEffect(spectrum_encoded);
1376
1672
  try testing.expectEqual(runtime_effects.EffectAudioEventKind.spectrum, spectrum_decoded.audio_kind);
1377
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);
1378
1727
  }
1379
1728
 
1380
1729
  test "header, checkpoint, screenshot, and end codecs round-trip" {
@@ -1388,7 +1737,7 @@ test "header, checkpoint, screenshot, and end codecs round-trip" {
1388
1737
  }, &buffer));
1389
1738
  try testing.expectEqualStrings("macos", header.platform_name);
1390
1739
  try testing.expectEqualStrings("calculator", header.app_name);
1391
- try testing.expectEqual(automation_protocol.version, header.protocol_version);
1740
+ try testing.expectEqual(automation_protocol.fingerprint, header.protocol_fingerprint);
1392
1741
 
1393
1742
  const checkpoint = try decodeCheckpoint(try encodeCheckpoint(.{ .event_ordinal = 10, .frame_index = 4, .fingerprint = 0xdead }, &buffer));
1394
1743
  try testing.expectEqual(@as(u64, 0xdead), checkpoint.fingerprint);
@@ -1458,22 +1807,43 @@ test "reader walks a whole journal and stops at the end record" {
1458
1807
  try testing.expectEqual(@as(?Record, null), try reader.next());
1459
1808
  }
1460
1809
 
1461
- test "reader refuses bad magic and version skew" {
1810
+ test "reader refuses bad magic and format skew" {
1462
1811
  var buffer: [16384]u8 = undefined;
1463
1812
  const len = try buildTestJournal(&buffer);
1464
1813
  try testing.expectError(error.JournalBadMagic, Reader.init("not a journal at all"));
1465
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.
1466
1819
  var skewed: [16384]u8 = undefined;
1467
1820
  @memcpy(skewed[0..len], buffer[0..len]);
1468
- std.mem.writeInt(u32, skewed[magic.len..][0..4], format_version + 1, .little);
1469
- try testing.expectError(error.JournalUnsupportedVersion, Reader.init(skewed[0..len]));
1470
- // Older journals are refused the same way — and, symmetrically, a
1471
- // reader built before a version bump refuses a NEWER journal at the
1472
- // preamble instead of reporting an unknown payload code as
1473
- // corruption (the v4 bump's reason: v3 readers would have called a
1474
- // journaled composition verb code corrupt).
1475
- std.mem.writeInt(u32, skewed[magic.len..][0..4], format_version - 1, .little);
1476
- try testing.expectError(error.JournalUnsupportedVersion, Reader.init(skewed[0..len]));
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);
1838
+ try testing.expect(std.mem.indexOf(u8, teaching, "re-record") != null);
1839
+ }
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);
1477
1847
  }
1478
1848
 
1479
1849
  test "reader fails loudly on truncation at every boundary" {