@native-sdk/cli 0.10.1 → 0.11.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 (462) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +1796 -83
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/native-ui/SKILL.md +76 -17
  130. package/skill-data/ts-core/SKILL.md +113 -9
  131. package/skill-data/ts-services/SKILL.md +1 -1
  132. package/skill-data/ts-services/references/service-surface.md +264 -144
  133. package/src/app_runner/root.zig +25 -12
  134. package/src/app_runner/ts_compiled_view.zig +1631 -0
  135. package/src/app_runner/ts_core_main.zig +143 -10
  136. package/src/app_runner/ts_core_mobile.zig +24 -12
  137. package/src/automation/server.zig +1 -3
  138. package/src/automation/snapshot.zig +9 -637
  139. package/src/automation/snapshot_reference.zig +656 -0
  140. package/src/automation/snapshot_serialization.zig +566 -0
  141. package/src/platform/linux/gtk_host.c +36 -24
  142. package/src/platform/linux/gtk_pixels.h +118 -0
  143. package/src/platform/linux/gtk_pixels_test.c +241 -0
  144. package/src/platform/linux/root.zig +2 -0
  145. package/src/platform/macos/appkit_host.m +188 -30
  146. package/src/platform/macos/pointer_motion_test.m +96 -0
  147. package/src/platform/macos/scroll_driver_test.m +105 -0
  148. package/src/platform/macos/spectrum_bins.h +34 -0
  149. package/src/platform/macos/spectrum_bins_test.c +56 -0
  150. package/src/platform/macos/text_keyboard_test.m +80 -0
  151. package/src/platform/macos/widget_focus_test.m +66 -0
  152. package/src/platform/null_platform.zig +26 -2
  153. package/src/platform/null_platform_tests.zig +13 -0
  154. package/src/platform/root.zig +1 -0
  155. package/src/platform/types.zig +13 -0
  156. package/src/platform/windows/root.zig +2 -0
  157. package/src/platform/windows/webview2_host.cpp +7 -2
  158. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  159. package/src/primitives/app_manifest/root.zig +2 -0
  160. package/src/primitives/app_manifest/tests.zig +4 -1
  161. package/src/primitives/app_manifest/validation.zig +2 -0
  162. package/src/primitives/canvas/a11y_audit.zig +3 -1
  163. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  164. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  165. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  166. package/src/primitives/canvas/code_content_policy.zig +162 -0
  167. package/src/primitives/canvas/commands.zig +29 -1
  168. package/src/primitives/canvas/component_composition.zig +125 -0
  169. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  170. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  171. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  172. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  173. package/src/primitives/canvas/control_command_policy.zig +75 -0
  174. package/src/primitives/canvas/control_content_policy.zig +90 -0
  175. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  176. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  177. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  178. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  179. package/src/primitives/canvas/events.zig +1027 -1
  180. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  181. package/src/primitives/canvas/frame.zig +92 -23
  182. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  183. package/src/primitives/canvas/gpu.zig +10 -0
  184. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  185. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  186. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  187. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  188. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  189. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  190. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  191. package/src/primitives/canvas/layout_audit.zig +5 -2
  192. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  193. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  194. package/src/primitives/canvas/markdown.zig +13 -3
  195. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  196. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  197. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  198. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  199. package/src/primitives/canvas/reference.zig +12 -6
  200. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  201. package/src/primitives/canvas/render.zig +48 -0
  202. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  203. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  204. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  205. package/src/primitives/canvas/render_effects.zig +14 -0
  206. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  207. package/src/primitives/canvas/render_images.zig +14 -0
  208. package/src/primitives/canvas/render_layers.zig +14 -0
  209. package/src/primitives/canvas/render_override_policy.zig +119 -0
  210. package/src/primitives/canvas/render_paths.zig +14 -0
  211. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  212. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  213. package/src/primitives/canvas/root.zig +100 -0
  214. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  215. package/src/primitives/canvas/serialization.zig +8 -1
  216. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  217. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  218. package/src/primitives/canvas/terminal_grid.zig +10 -696
  219. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  220. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  221. package/src/primitives/canvas/text.zig +1 -0
  222. package/src/primitives/canvas/text_atlas.zig +113 -0
  223. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  224. package/src/primitives/canvas/text_document_policy.zig +120 -0
  225. package/src/primitives/canvas/text_layout.zig +51 -2
  226. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  227. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  228. package/src/primitives/canvas/text_layout_types.zig +3 -0
  229. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  230. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  231. package/src/primitives/canvas/text_metrics.zig +23 -0
  232. package/src/primitives/canvas/text_query_policy.zig +156 -0
  233. package/src/primitives/canvas/text_run_policy.zig +252 -0
  234. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  235. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  236. package/src/primitives/canvas/text_spans.zig +280 -8
  237. package/src/primitives/canvas/text_tests.zig +10 -0
  238. package/src/primitives/canvas/tokens.zig +38 -0
  239. package/src/primitives/canvas/ui.zig +250 -83
  240. package/src/primitives/canvas/ui_markup.zig +139 -33
  241. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  242. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  243. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  244. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  245. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  246. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  247. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  248. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  249. package/src/primitives/canvas/ui_schema.zig +13 -1
  250. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  251. package/src/primitives/canvas/ui_tests.zig +1 -0
  252. package/src/primitives/canvas/vector.zig +36 -2
  253. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  254. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  255. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  256. package/src/primitives/canvas/virtual_extents.zig +99 -3
  257. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  258. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  259. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  260. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  261. package/src/primitives/canvas/widget_layout.zig +673 -128
  262. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  263. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  264. package/src/primitives/canvas/widget_metrics.zig +45 -6
  265. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  266. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  267. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  268. package/src/primitives/canvas/widget_render.zig +744 -74
  269. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  270. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  271. package/src/primitives/canvas/widget_render_style.zig +94 -0
  272. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  273. package/src/primitives/canvas/widget_routing.zig +75 -0
  274. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  275. package/src/primitives/canvas/widget_runtime.zig +20 -1
  276. package/src/primitives/canvas/widget_semantics.zig +25 -0
  277. package/src/primitives/canvas/widget_text_input.zig +86 -23
  278. package/src/primitives/canvas/widget_text_select.zig +1 -0
  279. package/src/primitives/canvas/widget_tree.zig +8 -1
  280. package/src/primitives/canvas/widgets.zig +42 -12
  281. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  282. package/src/root.zig +21 -0
  283. package/src/runtime/accessibility_policy.zig +122 -0
  284. package/src/runtime/api.zig +28 -0
  285. package/src/runtime/app_dispatch_policy.zig +68 -0
  286. package/src/runtime/authorization_policy.zig +150 -0
  287. package/src/runtime/automation_command_policy.zig +241 -0
  288. package/src/runtime/automation_interaction_policy.zig +107 -0
  289. package/src/runtime/automation_snapshot.zig +52 -22
  290. package/src/runtime/automation_snapshot_reference.zig +290 -0
  291. package/src/runtime/automation_widget_dispatch.zig +267 -355
  292. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  293. package/src/runtime/blob_policy.zig +58 -0
  294. package/src/runtime/blob_reference.zig +64 -0
  295. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  296. package/src/runtime/builtin_bridge.zig +180 -44
  297. package/src/runtime/builtin_coordination_policy.zig +121 -0
  298. package/src/runtime/callback_policy_test_reference.zig +97 -0
  299. package/src/runtime/canvas_drag_policy.zig +94 -0
  300. package/src/runtime/canvas_fonts.zig +38 -10
  301. package/src/runtime/canvas_frame.zig +590 -134
  302. package/src/runtime/canvas_frame_helpers.zig +1 -0
  303. package/src/runtime/canvas_hover_policy.zig +131 -0
  304. package/src/runtime/canvas_images.zig +59 -30
  305. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  306. package/src/runtime/canvas_limits.zig +1 -1
  307. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  308. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  309. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  310. package/src/runtime/canvas_widget_display.zig +110 -9
  311. package/src/runtime/canvas_widget_events.zig +718 -328
  312. package/src/runtime/canvas_widget_runtime.zig +437 -81
  313. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  314. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  315. package/src/runtime/canvas_widget_state.zig +93 -56
  316. package/src/runtime/channel_sources.zig +80 -0
  317. package/src/runtime/command_policy.zig +161 -0
  318. package/src/runtime/component_policy.zig +83 -0
  319. package/src/runtime/core.zig +156 -6
  320. package/src/runtime/desktop_files.zig +189 -0
  321. package/src/runtime/effects.zig +466 -29
  322. package/src/runtime/effects_tests.zig +28 -0
  323. package/src/runtime/file_policy_test_reference.zig +113 -0
  324. package/src/runtime/flow.zig +418 -341
  325. package/src/runtime/flow_reference.zig +1426 -0
  326. package/src/runtime/font_registry_policy.zig +72 -0
  327. package/src/runtime/frame_profile.zig +24 -33
  328. package/src/runtime/gpu_surface_events.zig +97 -35
  329. package/src/runtime/host_event_pump.zig +303 -0
  330. package/src/runtime/host_event_pump_reference.zig +268 -0
  331. package/src/runtime/host_flow_policy.zig +155 -0
  332. package/src/runtime/host_input_regions_policy.zig +156 -0
  333. package/src/runtime/image_registry_policy.zig +94 -0
  334. package/src/runtime/input_composition_policy.zig +138 -0
  335. package/src/runtime/journal_policy.zig +66 -0
  336. package/src/runtime/journal_reference.zig +53 -0
  337. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  338. package/src/runtime/markup_development_policy.zig +91 -0
  339. package/src/runtime/media_surface.zig +40 -1
  340. package/src/runtime/motion_sampling_policy.zig +159 -0
  341. package/src/runtime/recording_policy.zig +42 -0
  342. package/src/runtime/render_animation_policy.zig +206 -0
  343. package/src/runtime/replay_policy.zig +66 -0
  344. package/src/runtime/replay_policy_reference.zig +326 -0
  345. package/src/runtime/replay_progress_policy.zig +64 -0
  346. package/src/runtime/replay_progress_reference.zig +34 -0
  347. package/src/runtime/request_policy_test_reference.zig +188 -0
  348. package/src/runtime/root.zig +13 -0
  349. package/src/runtime/session_blobs.zig +157 -58
  350. package/src/runtime/session_blobs_reference.zig +692 -0
  351. package/src/runtime/session_codec.zig +361 -0
  352. package/src/runtime/session_codec_reference.zig +1027 -0
  353. package/src/runtime/session_journal.zig +246 -983
  354. package/src/runtime/session_record.zig +224 -45
  355. package/src/runtime/session_replay.zig +157 -415
  356. package/src/runtime/session_tests.zig +552 -0
  357. package/src/runtime/shell_admission_policy.zig +225 -0
  358. package/src/runtime/shell_coordination_policy.zig +138 -0
  359. package/src/runtime/shell_layout.zig +126 -1
  360. package/src/runtime/snapshot_policy.zig +60 -0
  361. package/src/runtime/snapshot_reference.zig +64 -0
  362. package/src/runtime/state.zig +16 -0
  363. package/src/runtime/status_validation.zig +190 -0
  364. package/src/runtime/system_admission_policy.zig +140 -0
  365. package/src/runtime/system_services.zig +46 -36
  366. package/src/runtime/tests.zig +1 -0
  367. package/src/runtime/ts_canvas_hooks.zig +261 -0
  368. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  369. package/src/runtime/ts_canvas_icons.zig +234 -0
  370. package/src/runtime/ts_core_host.zig +2325 -411
  371. package/src/runtime/ts_core_host_tests.zig +1982 -0
  372. package/src/runtime/ts_test_host.zig +699 -0
  373. package/src/runtime/ts_ui_app.zig +1087 -45
  374. package/src/runtime/ui_app.zig +1117 -629
  375. package/src/runtime/ui_app_provenance.zig +147 -5
  376. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  377. package/src/runtime/ui_app_tests.zig +619 -9
  378. package/src/runtime/ui_app_window_tests.zig +89 -0
  379. package/src/runtime/view.zig +25 -0
  380. package/src/runtime/view_canvas.zig +30 -6
  381. package/src/runtime/view_coordination_policy.zig +147 -0
  382. package/src/runtime/view_widget_control.zig +51 -14
  383. package/src/runtime/view_widget_scroll.zig +16 -5
  384. package/src/runtime/view_widget_text.zig +153 -68
  385. package/src/runtime/view_widget_tree.zig +460 -56
  386. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  387. package/src/runtime/widget_motion_policy.zig +238 -0
  388. package/src/runtime/window_command_bridge_tests.zig +63 -0
  389. package/src/runtime/window_lifecycle_policy.zig +127 -0
  390. package/src/runtime/window_storage.zig +74 -8
  391. package/src/runtime/window_view_runtime.zig +148 -33
  392. package/src/runtime/window_views.zig +163 -10
  393. package/src/tooling/components/identity_tests.zig +62 -36
  394. package/src/tooling/components/stepper.native +24 -0
  395. package/src/tooling/components/stepper.zig +0 -19
  396. package/src/tooling/components/timeline-item.native +22 -0
  397. package/src/tooling/components/timeline.native +5 -3
  398. package/src/tooling/components/timeline_item.zig +0 -32
  399. package/src/tooling/eject_components.zig +76 -8
  400. package/src/tooling/ios.zig +66 -12
  401. package/src/tooling/manifest.zig +35 -0
  402. package/src/tooling/raw_manifest.zig +6 -0
  403. package/src/tooling/templates.zig +15 -3
  404. package/src/tooling/ts_core.zig +13 -3
  405. package/src/tooling/verbs.zig +22 -0
  406. package/tools/corewire/build_profile.mjs +54 -0
  407. package/tools/corewire/contract_intake.ts +303 -0
  408. package/tools/corewire/contract_intake.zig +82 -0
  409. package/tools/corewire/core.test.ts +166 -0
  410. package/tools/corewire/core_abi.zig +51 -0
  411. package/tools/corewire/core_cases.ts +233 -0
  412. package/tools/corewire/core_contract.ts +407 -0
  413. package/tools/corewire/core_emission.ts +136 -0
  414. package/tools/corewire/core_emission.zig +69 -0
  415. package/tools/corewire/core_goldens.json +3110 -0
  416. package/tools/corewire/core_policy.ts +14 -0
  417. package/tools/corewire/core_policy.zig +48 -0
  418. package/tools/corewire/core_projection.ts +360 -0
  419. package/tools/corewire/core_vocabulary.ts +6 -0
  420. package/tools/corewire/emit.zig +19 -1590
  421. package/tools/corewire/emit_facade.ts +714 -0
  422. package/tools/corewire/emit_facade.zig +10 -3752
  423. package/tools/corewire/emit_mirror.ts +290 -0
  424. package/tools/corewire/emit_profile.ts +50 -0
  425. package/tools/corewire/emit_service.ts +331 -0
  426. package/tools/corewire/emit_service.zig +23 -842
  427. package/tools/corewire/entry.test.ts +95 -0
  428. package/tools/corewire/entry_coordination.ts +127 -0
  429. package/tools/corewire/entry_coordination.zig +190 -0
  430. package/tools/corewire/facade_templates.ts +85 -0
  431. package/tools/corewire/filesystem.test.ts +166 -0
  432. package/tools/corewire/filesystem_coordination.ts +213 -0
  433. package/tools/corewire/filesystem_coordination.zig +245 -0
  434. package/tools/corewire/intake.test.ts +35 -0
  435. package/tools/corewire/intake_cases.ts +55 -0
  436. package/tools/corewire/intake_goldens.json +12237 -0
  437. package/tools/corewire/invocation.test.ts +24 -0
  438. package/tools/corewire/invocation.ts +175 -0
  439. package/tools/corewire/invocation.zig +136 -0
  440. package/tools/corewire/invocation_cases.ts +60 -0
  441. package/tools/corewire/invocation_fixture.ts +33 -0
  442. package/tools/corewire/invocation_goldens.json +1143 -0
  443. package/tools/corewire/invocation_tests.zig +111 -0
  444. package/tools/corewire/invocation_usage.ts +2 -0
  445. package/tools/corewire/lossless_projection.ts +96 -0
  446. package/tools/corewire/main.zig +7 -680
  447. package/tools/corewire/main_reference.zig +415 -0
  448. package/tools/corewire/mirror_templates.ts +55 -0
  449. package/tools/corewire/profile.test.ts +248 -0
  450. package/tools/corewire/profile.zig +56 -0
  451. package/tools/corewire/profile_emission.ts +202 -0
  452. package/tools/corewire/profile_library.json +29 -0
  453. package/tools/corewire/profile_tests.zig +136 -0
  454. package/tools/corewire/service.test.ts +75 -0
  455. package/tools/corewire/service_cases.ts +61 -0
  456. package/tools/corewire/service_contract.zig +40 -146
  457. package/tools/corewire/service_goldens.json +650 -0
  458. package/tools/corewire/service_projection.zig +52 -0
  459. package/tools/corewire/service_templates.ts +14 -0
  460. package/tools/corewire/shim_rt.zig +9 -0
  461. package/tools/corewire/sidecar.zig +267 -1438
  462. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,8 +1,8 @@
1
1
  //! Deterministic session journal: the on-disk format for record/replay.
2
2
  //!
3
- //! A Native SDK session IS three things — the app's deterministic init,
4
- //! the platform-event sequence, and the effect results that crossed the
5
- //! effect boundary. This module makes that literal: a journal file holds
3
+ //! A Native SDK session consists of deterministic app init, platform
4
+ //! events, effect results, and synchronous OS chrome query results.
5
+ //! A journal file holds
6
6
  //! a session header, every dispatched platform event (payload + implicit
7
7
  //! ordinal), every effect RESULT the drain delivered to `update` (fetch
8
8
  //! response bytes, subprocess lines and exits, file reads, clipboard
@@ -73,9 +73,43 @@ const platform = @import("../platform/root.zig");
73
73
  const automation_protocol = @import("../automation/protocol.zig");
74
74
  const layout_fingerprint = @import("../automation/layout_fingerprint.zig");
75
75
  const runtime_effects = @import("effects.zig");
76
+ const journal_policy = @import("journal_policy.zig");
77
+ const codec = @import("session_codec.zig");
76
78
 
77
79
  pub const EffectResultRecord = runtime_effects.EffectResultRecord;
78
80
 
81
+ const EventTag = enum(u8) {
82
+ app_start = 1,
83
+ app_activated = 2,
84
+ app_deactivated = 3,
85
+ appearance_changed = 4,
86
+ frame_requested = 5,
87
+ app_shutdown = 6,
88
+ surface_resized = 7,
89
+ window_frame_changed = 8,
90
+ window_focused = 9,
91
+ bridge_message = 10,
92
+ tray_action = 11,
93
+ shortcut = 12,
94
+ native_command = 13,
95
+ menu_command = 14,
96
+ timer = 15,
97
+ wake = 16,
98
+ files_dropped = 17,
99
+ gpu_surface_frame = 18,
100
+ gpu_surface_resized = 19,
101
+ gpu_surface_input = 20,
102
+ gpu_surface_scroll_driver = 21,
103
+ context_menu_action = 22,
104
+ widget_accessibility_action = 23,
105
+ audio = 24,
106
+ video = 25,
107
+ view_focused = 26,
108
+ tray_command = 27,
109
+ notification_command = 28,
110
+ widget_context_menu_action = 29,
111
+ };
112
+
79
113
  /// File magic: first eight bytes of every session journal.
80
114
  pub const magic = "NSDKSJNL";
81
115
 
@@ -169,6 +203,7 @@ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
169
203
  "checkpoint=" ++ layout_fingerprint.describe(Checkpoint) ++ "\n" ++
170
204
  "screenshot=" ++ layout_fingerprint.describe(ScreenshotMark) ++ "\n" ++
171
205
  "end=" ++ layout_fingerprint.describe(End) ++ "\n" ++
206
+ "window_chrome=" ++ layout_fingerprint.describe(WindowChromeRecord) ++ "\n" ++
172
207
  "effect=" ++ layout_fingerprint.describe(EffectResultRecord) ++ "\n" ++
173
208
  "event_tags=" ++ layout_fingerprint.describe(EventTag) ++ "\n" ++
174
209
  // Per-variant payload types, reflected. Payload-free tags
@@ -204,7 +239,8 @@ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
204
239
  "gpu_surface_input=" ++ layout_fingerprint.describe(platform.GpuSurfaceInputEvent) ++ "\n" ++
205
240
  "gpu_surface_scroll_driver=" ++ layout_fingerprint.describe(platform.GpuSurfaceScrollDriverEvent) ++ "\n" ++
206
241
  "context_menu_action=" ++ layout_fingerprint.describe(platform.ContextMenuActionEvent) ++ "\n" ++
207
- "widget_accessibility_action=" ++ layout_fingerprint.describe(platform.WidgetAccessibilityActionEvent) ++ "\n";
242
+ "widget_accessibility_action=" ++ layout_fingerprint.describe(platform.WidgetAccessibilityActionEvent) ++ "\n" ++
243
+ "widget_context_menu_action=" ++ layout_fingerprint.describe(platform.WidgetContextMenuActionEvent) ++ "\n";
208
244
  }
209
245
  }
210
246
 
@@ -269,8 +305,24 @@ pub const RecordKind = enum(u8) {
269
305
  checkpoint = 4,
270
306
  screenshot = 5,
271
307
  end = 6,
308
+ window_chrome = 7,
309
+ };
310
+
311
+ /// Maximum synchronous chrome queries consumed by one recorded event.
312
+ /// Per-event staging preserves nested dispatch and accessibility ownership.
313
+ pub const max_session_window_chrome_queries: usize = 256;
314
+
315
+ /// One OS capability result, consumed in query order by the following event.
316
+ /// Values are copied; no native window or borrowed storage crosses replay.
317
+ pub const WindowChromeRecord = struct {
318
+ window_id: platform.WindowId,
319
+ chrome: platform.WindowChrome,
272
320
  };
273
321
 
322
+ /// A logic-only host has no window chrome capability. Its explicit
323
+ /// absence replays as zero geometry; native sessions capture every query.
324
+ pub const WindowChromeSource = enum(u8) { native_queries, unavailable };
325
+
274
326
  /// Session identity, written once as the first record.
275
327
  pub const Header = struct {
276
328
  /// The automation protocol fingerprint baked into the recording
@@ -288,6 +340,7 @@ pub const Header = struct {
288
340
  /// Initial main-window geometry, for provenance and sanity checks.
289
341
  window_width: f32 = 0,
290
342
  window_height: f32 = 0,
343
+ window_chrome_source: WindowChromeSource = .native_queries,
291
344
  };
292
345
 
293
346
  /// A model-state fingerprint taken after the event with `event_ordinal`
@@ -319,6 +372,7 @@ pub const End = struct {
319
372
  effect_count: u64,
320
373
  checkpoint_count: u64,
321
374
  screenshot_count: u64,
375
+ window_chrome_count: u64 = 0,
322
376
  };
323
377
 
324
378
  pub const Record = union(RecordKind) {
@@ -328,6 +382,7 @@ pub const Record = union(RecordKind) {
328
382
  checkpoint: Checkpoint,
329
383
  screenshot: ScreenshotMark,
330
384
  end: End,
385
+ window_chrome: WindowChromeRecord,
331
386
  };
332
387
 
333
388
  /// Decode scratch for payloads that need an outer slice (dropped-file
@@ -346,990 +401,146 @@ pub const EventDecodeStorage = struct {
346
401
  // one here means updating that description's `codec=` line in the same
347
402
  // change.
348
403
 
349
- const WriteCursor = struct {
350
- buffer: []u8,
351
- len: usize = 0,
352
-
353
- fn remaining(self: *const WriteCursor) usize {
354
- return self.buffer.len - self.len;
355
- }
356
-
357
- fn writeBytes(self: *WriteCursor, bytes: []const u8) JournalError!void {
358
- if (bytes.len > self.remaining()) return error.JournalRecordOverBudget;
359
- @memcpy(self.buffer[self.len .. self.len + bytes.len], bytes);
360
- self.len += bytes.len;
361
- }
362
-
363
- fn writeByte(self: *WriteCursor, value: u8) JournalError!void {
364
- try self.writeBytes(&.{value});
365
- }
366
-
367
- fn writeBool(self: *WriteCursor, value: bool) JournalError!void {
368
- try self.writeByte(@intFromBool(value));
369
- }
370
-
371
- fn writeInt(self: *WriteCursor, comptime T: type, value: T) JournalError!void {
372
- var bytes: [@divExact(@typeInfo(T).int.bits, 8)]u8 = undefined;
373
- std.mem.writeInt(T, &bytes, value, .little);
374
- try self.writeBytes(&bytes);
375
- }
376
-
377
- fn writeF32(self: *WriteCursor, value: f32) JournalError!void {
378
- try self.writeInt(u32, @bitCast(value));
379
- }
380
-
381
- fn writeEnum(self: *WriteCursor, value: anytype) JournalError!void {
382
- const int_value = @intFromEnum(value);
383
- if (int_value < 0 or int_value > std.math.maxInt(u8)) return error.JournalRecordOverBudget;
384
- try self.writeByte(@intCast(int_value));
385
- }
386
-
387
- fn writeStr(self: *WriteCursor, bytes: []const u8) JournalError!void {
388
- if (bytes.len > std.math.maxInt(u32)) return error.JournalRecordOverBudget;
389
- try self.writeInt(u32, @intCast(bytes.len));
390
- try self.writeBytes(bytes);
391
- }
392
- };
393
-
394
- const ReadCursor = struct {
395
- bytes: []const u8,
396
- pos: usize = 0,
397
-
398
- fn readBytes(self: *ReadCursor, len: usize) JournalError![]const u8 {
399
- if (len > self.bytes.len - self.pos) return error.JournalCorrupt;
400
- const slice = self.bytes[self.pos .. self.pos + len];
401
- self.pos += len;
402
- return slice;
403
- }
404
-
405
- fn readByte(self: *ReadCursor) JournalError!u8 {
406
- return (try self.readBytes(1))[0];
407
- }
408
-
409
- fn readBool(self: *ReadCursor) JournalError!bool {
410
- return switch (try self.readByte()) {
411
- 0 => false,
412
- 1 => true,
413
- else => error.JournalCorrupt,
414
- };
415
- }
416
-
417
- fn readInt(self: *ReadCursor, comptime T: type) JournalError!T {
418
- const size = @divExact(@typeInfo(T).int.bits, 8);
419
- const bytes = try self.readBytes(size);
420
- return std.mem.readInt(T, bytes[0..size], .little);
421
- }
422
-
423
- fn readF32(self: *ReadCursor) JournalError!f32 {
424
- return @bitCast(try self.readInt(u32));
425
- }
426
-
427
- fn readEnum(self: *ReadCursor, comptime T: type) JournalError!T {
428
- return std.enums.fromInt(T, try self.readByte()) orelse error.JournalCorrupt;
429
- }
430
-
431
- fn readStr(self: *ReadCursor) JournalError![]const u8 {
432
- const len = try self.readInt(u32);
433
- return self.readBytes(len);
434
- }
435
-
436
- fn done(self: *const ReadCursor) bool {
437
- return self.pos == self.bytes.len;
438
- }
439
- };
440
-
441
- // ------------------------------------------------------- event codec
442
- //
443
- // Explicit stable tags per event variant (never `@intFromEnum` of the
444
- // union tag, whose order is free to change).
445
-
446
- const EventTag = enum(u8) {
447
- app_start = 1,
448
- app_activated = 2,
449
- app_deactivated = 3,
450
- appearance_changed = 4,
451
- frame_requested = 5,
452
- app_shutdown = 6,
453
- surface_resized = 7,
454
- window_frame_changed = 8,
455
- window_focused = 9,
456
- bridge_message = 10,
457
- tray_action = 11,
458
- shortcut = 12,
459
- native_command = 13,
460
- menu_command = 14,
461
- timer = 15,
462
- wake = 16,
463
- files_dropped = 17,
464
- gpu_surface_frame = 18,
465
- gpu_surface_resized = 19,
466
- gpu_surface_input = 20,
467
- gpu_surface_scroll_driver = 21,
468
- context_menu_action = 22,
469
- widget_accessibility_action = 23,
470
- audio = 24,
471
- video = 25,
472
- view_focused = 26,
473
- tray_command = 27,
474
- notification_command = 28,
475
- };
476
-
477
- // The bit assignments below are hand-written wire layout: they are
478
- // stated in `formatLayoutDescription` (reflection sees the bool fields,
479
- // not the bits), so changing a bit here means updating that line too.
480
- fn writeModifiers(cursor: *WriteCursor, modifiers: platform.ShortcutModifiers) JournalError!void {
481
- var bits: u8 = 0;
482
- if (modifiers.primary) bits |= 1;
483
- if (modifiers.command) bits |= 2;
484
- if (modifiers.control) bits |= 4;
485
- if (modifiers.option) bits |= 8;
486
- if (modifiers.shift) bits |= 16;
487
- try cursor.writeByte(bits);
404
+ pub fn encodeEvent(value: platform.Event, buffer: []u8) JournalError![]const u8 {
405
+ return encodeEventWithPolicy(null, value, buffer);
488
406
  }
489
-
490
- fn readModifiers(cursor: *ReadCursor) JournalError!platform.ShortcutModifiers {
491
- const bits = try cursor.readByte();
492
- if (bits > 31) return error.JournalCorrupt;
493
- return .{
494
- .primary = bits & 1 != 0,
495
- .command = bits & 2 != 0,
496
- .control = bits & 4 != 0,
497
- .option = bits & 8 != 0,
498
- .shift = bits & 16 != 0,
499
- };
500
- }
501
-
502
- fn writeInsets(cursor: *WriteCursor, insets: geometry.InsetsF) JournalError!void {
503
- try cursor.writeF32(insets.top);
504
- try cursor.writeF32(insets.right);
505
- try cursor.writeF32(insets.bottom);
506
- try cursor.writeF32(insets.left);
407
+ pub fn encodeEventWithPolicy(policy: journal_policy.Policy, value: platform.Event, buffer: []u8) JournalError![]const u8 {
408
+ return codec.encodeEvent(policy, value, buffer);
507
409
  }
508
-
509
- fn readInsets(cursor: *ReadCursor) JournalError!geometry.InsetsF {
510
- return .{
511
- .top = try cursor.readF32(),
512
- .right = try cursor.readF32(),
513
- .bottom = try cursor.readF32(),
514
- .left = try cursor.readF32(),
515
- };
410
+ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError!platform.Event {
411
+ return decodeEventWithPolicy(null, bytes, storage);
516
412
  }
517
-
518
- fn writeRect(cursor: *WriteCursor, rect: geometry.RectF) JournalError!void {
519
- try cursor.writeF32(rect.x);
520
- try cursor.writeF32(rect.y);
521
- try cursor.writeF32(rect.width);
522
- try cursor.writeF32(rect.height);
413
+ pub fn decodeEventWithPolicy(policy: journal_policy.Policy, bytes: []const u8, storage: *EventDecodeStorage) JournalError!platform.Event {
414
+ return codec.decodeEvent(policy, bytes, storage);
523
415
  }
524
416
 
525
- fn readRect(cursor: *ReadCursor) JournalError!geometry.RectF {
526
- const x = try cursor.readF32();
527
- const y = try cursor.readF32();
528
- const width = try cursor.readF32();
529
- const height = try cursor.readF32();
530
- return geometry.RectF.init(x, y, width, height);
417
+ pub fn encodeEffect(value: EffectResultRecord, buffer: []u8) JournalError![]const u8 {
418
+ return encodeEffectWithPolicy(null, value, buffer);
531
419
  }
532
-
533
- /// Encode one platform event into `buffer`, returning the encoded
534
- /// payload. `gpu_surface_frame` deliberately journals only the fields
535
- /// dispatch semantics depend on (identity, geometry, frame index and
536
- /// timestamps, full-repaint) — the rest of that struct is host render
537
- /// telemetry about the PREVIOUS present, meaningless under replay's
538
- /// null host; decode fills those with defaults.
539
- pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8 {
540
- var cursor = WriteCursor{ .buffer = buffer };
541
- switch (event) {
542
- .app_start => try cursor.writeEnum(EventTag.app_start),
543
- .app_activated => try cursor.writeEnum(EventTag.app_activated),
544
- .app_deactivated => try cursor.writeEnum(EventTag.app_deactivated),
545
- .frame_requested => try cursor.writeEnum(EventTag.frame_requested),
546
- .app_shutdown => try cursor.writeEnum(EventTag.app_shutdown),
547
- .wake => try cursor.writeEnum(EventTag.wake),
548
- .appearance_changed => |appearance| {
549
- try cursor.writeEnum(EventTag.appearance_changed);
550
- try cursor.writeEnum(appearance.color_scheme);
551
- try cursor.writeBool(appearance.reduce_motion);
552
- try cursor.writeBool(appearance.high_contrast);
553
- },
554
- .surface_resized => |surface| {
555
- try cursor.writeEnum(EventTag.surface_resized);
556
- try cursor.writeInt(u64, surface.id);
557
- try cursor.writeF32(surface.size.width);
558
- try cursor.writeF32(surface.size.height);
559
- try cursor.writeF32(surface.scale_factor);
560
- try writeInsets(&cursor, surface.safe_area_insets);
561
- try writeInsets(&cursor, surface.keyboard_insets);
562
- // `native_handle` is process-local and never journaled.
563
- },
564
- .window_frame_changed => |state| {
565
- try cursor.writeEnum(EventTag.window_frame_changed);
566
- try cursor.writeInt(u64, state.id);
567
- try cursor.writeStr(state.label);
568
- try cursor.writeStr(state.title);
569
- try writeRect(&cursor, state.frame);
570
- try cursor.writeF32(state.scale_factor);
571
- try cursor.writeBool(state.open);
572
- try cursor.writeBool(state.focused);
573
- try cursor.writeBool(state.maximized);
574
- try cursor.writeBool(state.fullscreen);
575
- // v6: alive-but-policy-hidden (`close_policy = .hide`).
576
- try cursor.writeBool(state.hidden);
577
- },
578
- .window_focused => |window_id| {
579
- try cursor.writeEnum(EventTag.window_focused);
580
- try cursor.writeInt(u64, window_id);
581
- },
582
- .view_focused => |focus| {
583
- try cursor.writeEnum(EventTag.view_focused);
584
- try cursor.writeInt(u64, focus.window_id);
585
- try cursor.writeStr(focus.label);
586
- },
587
- .bridge_message => |message| {
588
- try cursor.writeEnum(EventTag.bridge_message);
589
- try cursor.writeStr(message.bytes);
590
- try cursor.writeStr(message.origin);
591
- try cursor.writeInt(u64, message.window_id);
592
- try cursor.writeStr(message.webview_label);
593
- },
594
- .tray_action => |action| {
595
- try cursor.writeEnum(EventTag.tray_action);
596
- try cursor.writeInt(u32, action.status_item_id);
597
- try cursor.writeInt(u32, action.item_id);
598
- },
599
- .shortcut => |shortcut| {
600
- try cursor.writeEnum(EventTag.shortcut);
601
- try cursor.writeStr(shortcut.id);
602
- try cursor.writeStr(shortcut.key);
603
- try writeModifiers(&cursor, shortcut.modifiers);
604
- try cursor.writeInt(u64, shortcut.window_id);
605
- },
606
- .native_command => |command| {
607
- try cursor.writeEnum(EventTag.native_command);
608
- try cursor.writeStr(command.name);
609
- try cursor.writeInt(u64, command.window_id);
610
- try cursor.writeStr(command.view_label);
611
- },
612
- .menu_command => |command| {
613
- try cursor.writeEnum(EventTag.menu_command);
614
- try cursor.writeStr(command.name);
615
- try cursor.writeInt(u64, command.window_id);
616
- },
617
- .tray_command => |command| {
618
- try cursor.writeEnum(EventTag.tray_command);
619
- try cursor.writeStr(command.name);
620
- try cursor.writeInt(u64, command.window_id);
621
- try cursor.writeInt(u32, command.status_item_id);
622
- },
623
- .notification_command => |command| {
624
- try cursor.writeEnum(EventTag.notification_command);
625
- try cursor.writeStr(command.name);
626
- try cursor.writeInt(u64, command.window_id);
627
- },
628
- .timer => |timer| {
629
- try cursor.writeEnum(EventTag.timer);
630
- try cursor.writeInt(u64, timer.id);
631
- try cursor.writeInt(u64, timer.timestamp_ns);
632
- },
633
- // Recorded for stream fidelity; inert on replay (the journaled
634
- // audio EFFECT records are the Msg source — `takeAudioMsg`
635
- // ignores platform audio events under replay).
636
- .audio => |audio| {
637
- try cursor.writeEnum(EventTag.audio);
638
- try cursor.writeEnum(audio.kind);
639
- try cursor.writeInt(u64, audio.position_ms);
640
- try cursor.writeInt(u64, audio.duration_ms);
641
- try cursor.writeBool(audio.playing);
642
- try cursor.writeBool(audio.buffering);
643
- try cursor.writeBytes(&audio.bands);
644
- },
645
- // Recorded for stream fidelity like `.audio`. On replay the
646
- // journaled video EFFECT records are the Msg source; the
647
- // platform events steer only the channel MIRRORS (the house
648
- // chrome's render state for handler-less playbacks), gated by
649
- // the load token exactly as live (`Effects.takeVideoMsg`).
650
- .video => |video| {
651
- try cursor.writeEnum(EventTag.video);
652
- try cursor.writeEnum(video.kind);
653
- try cursor.writeInt(u64, video.token);
654
- try cursor.writeInt(u64, video.position_ms);
655
- try cursor.writeInt(u64, video.duration_ms);
656
- try cursor.writeBool(video.playing);
657
- try cursor.writeBool(video.buffering);
658
- try cursor.writeInt(u64, video.width);
659
- try cursor.writeInt(u64, video.height);
660
- },
661
- .files_dropped => |drop| {
662
- try cursor.writeEnum(EventTag.files_dropped);
663
- try cursor.writeInt(u64, drop.window_id);
664
- try cursor.writeStr(drop.view_label);
665
- try cursor.writeBool(drop.point != null);
666
- if (drop.point) |point| {
667
- try cursor.writeF32(point.x);
668
- try cursor.writeF32(point.y);
669
- }
670
- if (drop.paths.len > max_session_drop_paths) return error.JournalRecordOverBudget;
671
- try cursor.writeInt(u16, @intCast(drop.paths.len));
672
- for (drop.paths) |path| try cursor.writeStr(path);
673
- },
674
- // This arm journals a deliberate SUBSET of the frame event (the
675
- // fields dispatch semantics depend on — see the fn doc). The
676
- // subset is stated by hand in `formatLayoutDescription`, so
677
- // journaling another field here means adding it to that line in
678
- // the same change.
679
- .gpu_surface_frame => |frame| {
680
- try cursor.writeEnum(EventTag.gpu_surface_frame);
681
- try cursor.writeInt(u64, frame.window_id);
682
- try cursor.writeStr(frame.label);
683
- try cursor.writeF32(frame.size.width);
684
- try cursor.writeF32(frame.size.height);
685
- try cursor.writeF32(frame.scale_factor);
686
- try cursor.writeInt(u64, frame.frame_index);
687
- try cursor.writeInt(u64, frame.timestamp_ns);
688
- try cursor.writeInt(u64, frame.frame_interval_ns);
689
- try cursor.writeInt(u64, frame.input_timestamp_ns);
690
- try cursor.writeBool(frame.canvas_frame_full_repaint);
691
- },
692
- .gpu_surface_resized => |resize| {
693
- try cursor.writeEnum(EventTag.gpu_surface_resized);
694
- try cursor.writeInt(u64, resize.window_id);
695
- try cursor.writeStr(resize.label);
696
- try writeRect(&cursor, resize.frame);
697
- try cursor.writeF32(resize.scale_factor);
698
- },
699
- .gpu_surface_input => |input| {
700
- try cursor.writeEnum(EventTag.gpu_surface_input);
701
- try cursor.writeInt(u64, input.window_id);
702
- try cursor.writeStr(input.label);
703
- try cursor.writeEnum(input.kind);
704
- try cursor.writeInt(u64, input.timestamp_ns);
705
- try cursor.writeInt(u64, input.pointer_id);
706
- try cursor.writeF32(input.x);
707
- try cursor.writeF32(input.y);
708
- try cursor.writeInt(i32, input.button);
709
- try cursor.writeF32(input.pressure);
710
- try cursor.writeF32(input.delta_x);
711
- try cursor.writeF32(input.delta_y);
712
- try cursor.writeStr(input.key);
713
- try cursor.writeStr(input.text);
714
- try cursor.writeBool(input.composition_cursor != null);
715
- if (input.composition_cursor) |composition_cursor| {
716
- try cursor.writeInt(u64, @intCast(composition_cursor));
717
- }
718
- try writeModifiers(&cursor, input.modifiers);
719
- // v5: the pinch magnification delta (0 on non-pinch kinds).
720
- try cursor.writeF32(input.scale);
721
- },
722
- .gpu_surface_scroll_driver => |driver| {
723
- try cursor.writeEnum(EventTag.gpu_surface_scroll_driver);
724
- try cursor.writeInt(u64, driver.window_id);
725
- try cursor.writeStr(driver.label);
726
- try cursor.writeInt(u64, driver.driver_id);
727
- try cursor.writeF32(driver.offset_x);
728
- try cursor.writeF32(driver.offset_y);
729
- try cursor.writeInt(u64, driver.timestamp_ns);
730
- },
731
- .context_menu_action => |action| {
732
- try cursor.writeEnum(EventTag.context_menu_action);
733
- try cursor.writeInt(u64, action.window_id);
734
- try cursor.writeStr(action.view_label);
735
- try cursor.writeInt(u64, action.token);
736
- try cursor.writeInt(u32, action.item_id);
737
- },
738
- .widget_accessibility_action => |action| {
739
- try cursor.writeEnum(EventTag.widget_accessibility_action);
740
- try cursor.writeInt(u64, action.window_id);
741
- try cursor.writeStr(action.label);
742
- try cursor.writeInt(u64, action.id);
743
- // The verb rides i32, not the u8 every other enum takes — a
744
- // hand-written width stated in `formatLayoutDescription`.
745
- try cursor.writeInt(i32, @intFromEnum(action.action));
746
- try cursor.writeStr(action.text);
747
- try cursor.writeBool(action.selection != null);
748
- if (action.selection) |selection| {
749
- try cursor.writeInt(u64, @intCast(selection.start));
750
- try cursor.writeInt(u64, @intCast(selection.end));
751
- }
752
- },
753
- }
754
- return buffer[0..cursor.len];
420
+ pub fn encodeEffectWithPolicy(policy: journal_policy.Policy, value: EffectResultRecord, buffer: []u8) JournalError![]const u8 {
421
+ return codec.encodeEffect(policy, value, buffer);
755
422
  }
756
-
757
- /// Decode one event payload. Returned slices reference `bytes` (and
758
- /// `storage` for path lists) — valid until the caller's buffers move.
759
- pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError!platform.Event {
760
- var cursor = ReadCursor{ .bytes = bytes };
761
- const tag = try cursor.readEnum(EventTag);
762
- const event: platform.Event = switch (tag) {
763
- .app_start => .app_start,
764
- .app_activated => .app_activated,
765
- .app_deactivated => .app_deactivated,
766
- .frame_requested => .frame_requested,
767
- .app_shutdown => .app_shutdown,
768
- .wake => .wake,
769
- .appearance_changed => .{ .appearance_changed = .{
770
- .color_scheme = try cursor.readEnum(platform.ColorScheme),
771
- .reduce_motion = try cursor.readBool(),
772
- .high_contrast = try cursor.readBool(),
773
- } },
774
- .surface_resized => blk: {
775
- const id = try cursor.readInt(u64);
776
- const width = try cursor.readF32();
777
- const height = try cursor.readF32();
778
- const scale_factor = try cursor.readF32();
779
- const safe_area = try readInsets(&cursor);
780
- const keyboard = try readInsets(&cursor);
781
- break :blk .{ .surface_resized = .{
782
- .id = id,
783
- .size = geometry.SizeF.init(width, height),
784
- .scale_factor = scale_factor,
785
- .safe_area_insets = safe_area,
786
- .keyboard_insets = keyboard,
787
- } };
788
- },
789
- .window_frame_changed => blk: {
790
- const id = try cursor.readInt(u64);
791
- const label = try cursor.readStr();
792
- const title = try cursor.readStr();
793
- const frame = try readRect(&cursor);
794
- const scale_factor = try cursor.readF32();
795
- break :blk .{ .window_frame_changed = .{
796
- .id = id,
797
- .label = label,
798
- .title = title,
799
- .frame = frame,
800
- .scale_factor = scale_factor,
801
- .open = try cursor.readBool(),
802
- .focused = try cursor.readBool(),
803
- .maximized = try cursor.readBool(),
804
- .fullscreen = try cursor.readBool(),
805
- .hidden = try cursor.readBool(),
806
- } };
807
- },
808
- .window_focused => .{ .window_focused = try cursor.readInt(u64) },
809
- .view_focused => .{ .view_focused = .{
810
- .window_id = try cursor.readInt(u64),
811
- .label = try cursor.readStr(),
812
- } },
813
- .bridge_message => blk: {
814
- const message_bytes = try cursor.readStr();
815
- const origin = try cursor.readStr();
816
- const window_id = try cursor.readInt(u64);
817
- const webview_label = try cursor.readStr();
818
- break :blk .{ .bridge_message = .{
819
- .bytes = message_bytes,
820
- .origin = origin,
821
- .window_id = window_id,
822
- .webview_label = webview_label,
823
- } };
824
- },
825
- .tray_action => .{ .tray_action = .{
826
- .status_item_id = try cursor.readInt(u32),
827
- .item_id = try cursor.readInt(u32),
828
- } },
829
- .shortcut => blk: {
830
- const id = try cursor.readStr();
831
- const key = try cursor.readStr();
832
- const modifiers = try readModifiers(&cursor);
833
- break :blk .{ .shortcut = .{
834
- .id = id,
835
- .key = key,
836
- .modifiers = modifiers,
837
- .window_id = try cursor.readInt(u64),
838
- } };
839
- },
840
- .native_command => blk: {
841
- const name = try cursor.readStr();
842
- const window_id = try cursor.readInt(u64);
843
- break :blk .{ .native_command = .{
844
- .name = name,
845
- .window_id = window_id,
846
- .view_label = try cursor.readStr(),
847
- } };
848
- },
849
- .menu_command => blk: {
850
- const name = try cursor.readStr();
851
- break :blk .{ .menu_command = .{
852
- .name = name,
853
- .window_id = try cursor.readInt(u64),
854
- } };
855
- },
856
- .tray_command => blk: {
857
- const name = try cursor.readStr();
858
- break :blk .{ .tray_command = .{
859
- .name = name,
860
- .window_id = try cursor.readInt(u64),
861
- .status_item_id = try cursor.readInt(u32),
862
- } };
863
- },
864
- .notification_command => blk: {
865
- const name = try cursor.readStr();
866
- break :blk .{ .notification_command = .{
867
- .name = name,
868
- .window_id = try cursor.readInt(u64),
869
- } };
870
- },
871
- .timer => blk: {
872
- const id = try cursor.readInt(u64);
873
- break :blk .{ .timer = .{
874
- .id = id,
875
- .timestamp_ns = try cursor.readInt(u64),
876
- } };
877
- },
878
- .audio => blk: {
879
- const kind = try cursor.readEnum(platform.AudioEventKind);
880
- var decoded: platform.AudioEvent = .{
881
- .kind = kind,
882
- .position_ms = try cursor.readInt(u64),
883
- .duration_ms = try cursor.readInt(u64),
884
- .playing = try cursor.readBool(),
885
- .buffering = try cursor.readBool(),
886
- };
887
- @memcpy(&decoded.bands, try cursor.readBytes(decoded.bands.len));
888
- break :blk .{ .audio = decoded };
889
- },
890
- .video => blk: {
891
- const kind = try cursor.readEnum(platform.VideoEventKind);
892
- break :blk .{ .video = .{
893
- .kind = kind,
894
- .token = try cursor.readInt(u64),
895
- .position_ms = try cursor.readInt(u64),
896
- .duration_ms = try cursor.readInt(u64),
897
- .playing = try cursor.readBool(),
898
- .buffering = try cursor.readBool(),
899
- .width = try cursor.readInt(u64),
900
- .height = try cursor.readInt(u64),
901
- } };
902
- },
903
- .files_dropped => blk: {
904
- const window_id = try cursor.readInt(u64);
905
- const view_label = try cursor.readStr();
906
- var point: ?geometry.PointF = null;
907
- if (try cursor.readBool()) {
908
- const x = try cursor.readF32();
909
- const y = try cursor.readF32();
910
- point = geometry.PointF.init(x, y);
911
- }
912
- const count = try cursor.readInt(u16);
913
- if (count > max_session_drop_paths) return error.JournalCorrupt;
914
- for (0..count) |index| {
915
- storage.drop_paths[index] = try cursor.readStr();
916
- }
917
- break :blk .{ .files_dropped = .{
918
- .window_id = window_id,
919
- .view_label = view_label,
920
- .point = point,
921
- .paths = storage.drop_paths[0..count],
922
- } };
923
- },
924
- .gpu_surface_frame => blk: {
925
- const window_id = try cursor.readInt(u64);
926
- const label = try cursor.readStr();
927
- const width = try cursor.readF32();
928
- const height = try cursor.readF32();
929
- break :blk .{ .gpu_surface_frame = .{
930
- .window_id = window_id,
931
- .label = label,
932
- .size = geometry.SizeF.init(width, height),
933
- .scale_factor = try cursor.readF32(),
934
- .frame_index = try cursor.readInt(u64),
935
- .timestamp_ns = try cursor.readInt(u64),
936
- .frame_interval_ns = try cursor.readInt(u64),
937
- .input_timestamp_ns = try cursor.readInt(u64),
938
- .canvas_frame_full_repaint = try cursor.readBool(),
939
- } };
940
- },
941
- .gpu_surface_resized => blk: {
942
- const window_id = try cursor.readInt(u64);
943
- const label = try cursor.readStr();
944
- const frame = try readRect(&cursor);
945
- break :blk .{ .gpu_surface_resized = .{
946
- .window_id = window_id,
947
- .label = label,
948
- .frame = frame,
949
- .scale_factor = try cursor.readF32(),
950
- } };
951
- },
952
- .gpu_surface_input => blk: {
953
- const window_id = try cursor.readInt(u64);
954
- const label = try cursor.readStr();
955
- const kind = try cursor.readEnum(platform.GpuSurfaceInputKind);
956
- const timestamp_ns = try cursor.readInt(u64);
957
- const pointer_id = try cursor.readInt(u64);
958
- const x = try cursor.readF32();
959
- const y = try cursor.readF32();
960
- const button = try cursor.readInt(i32);
961
- const pressure = try cursor.readF32();
962
- const delta_x = try cursor.readF32();
963
- const delta_y = try cursor.readF32();
964
- const key = try cursor.readStr();
965
- const text = try cursor.readStr();
966
- var composition_cursor: ?usize = null;
967
- if (try cursor.readBool()) {
968
- composition_cursor = std.math.cast(usize, try cursor.readInt(u64)) orelse return error.JournalCorrupt;
969
- }
970
- break :blk .{
971
- .gpu_surface_input = .{
972
- .window_id = window_id,
973
- .label = label,
974
- .kind = kind,
975
- .timestamp_ns = timestamp_ns,
976
- .pointer_id = pointer_id,
977
- .x = x,
978
- .y = y,
979
- .button = button,
980
- .pressure = pressure,
981
- .delta_x = delta_x,
982
- .delta_y = delta_y,
983
- .key = key,
984
- .text = text,
985
- .composition_cursor = composition_cursor,
986
- .modifiers = try readModifiers(&cursor),
987
- // v5: the pinch magnification delta (0 on non-pinch kinds).
988
- .scale = try cursor.readF32(),
989
- },
990
- };
991
- },
992
- .gpu_surface_scroll_driver => blk: {
993
- const window_id = try cursor.readInt(u64);
994
- const label = try cursor.readStr();
995
- const driver_id = try cursor.readInt(u64);
996
- const offset_x = try cursor.readF32();
997
- const offset_y = try cursor.readF32();
998
- break :blk .{ .gpu_surface_scroll_driver = .{
999
- .window_id = window_id,
1000
- .label = label,
1001
- .driver_id = driver_id,
1002
- .offset_x = offset_x,
1003
- .offset_y = offset_y,
1004
- .timestamp_ns = try cursor.readInt(u64),
1005
- } };
1006
- },
1007
- .context_menu_action => blk: {
1008
- const window_id = try cursor.readInt(u64);
1009
- const view_label = try cursor.readStr();
1010
- const token = try cursor.readInt(u64);
1011
- break :blk .{ .context_menu_action = .{
1012
- .window_id = window_id,
1013
- .view_label = view_label,
1014
- .token = token,
1015
- .item_id = try cursor.readInt(u32),
1016
- } };
1017
- },
1018
- .widget_accessibility_action => blk: {
1019
- const window_id = try cursor.readInt(u64);
1020
- const label = try cursor.readStr();
1021
- const id = try cursor.readInt(u64);
1022
- const action = std.enums.fromInt(platform.WidgetAccessibilityActionKind, try cursor.readInt(i32)) orelse return error.JournalCorrupt;
1023
- const text = try cursor.readStr();
1024
- var selection: ?platform.WidgetAccessibilityTextRange = null;
1025
- if (try cursor.readBool()) {
1026
- const start = std.math.cast(usize, try cursor.readInt(u64)) orelse return error.JournalCorrupt;
1027
- const end = std.math.cast(usize, try cursor.readInt(u64)) orelse return error.JournalCorrupt;
1028
- selection = .{ .start = start, .end = end };
1029
- }
1030
- break :blk .{ .widget_accessibility_action = .{
1031
- .window_id = window_id,
1032
- .label = label,
1033
- .id = id,
1034
- .action = action,
1035
- .text = text,
1036
- .selection = selection,
1037
- } };
1038
- },
1039
- };
1040
- if (!cursor.done()) return error.JournalCorrupt;
1041
- return event;
423
+ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
424
+ return decodeEffectWithPolicy(null, bytes);
1042
425
  }
1043
-
1044
- // ------------------------------------------------------ effect codec
1045
-
1046
- pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]const u8 {
1047
- var cursor = WriteCursor{ .buffer = buffer };
1048
- try cursor.writeEnum(record.kind);
1049
- try cursor.writeInt(u64, record.key);
1050
- try cursor.writeStr(record.payload);
1051
- try cursor.writeStr(record.stderr_tail);
1052
- try cursor.writeBool(record.truncated);
1053
- try cursor.writeInt(u32, record.dropped);
1054
- try cursor.writeInt(i32, record.code);
1055
- try cursor.writeEnum(record.exit_reason);
1056
- try cursor.writeBool(record.output_truncated);
1057
- try cursor.writeBool(record.stderr_truncated);
1058
- try cursor.writeInt(u16, record.status);
1059
- try cursor.writeEnum(record.fetch_outcome);
1060
- try cursor.writeEnum(record.file_op);
1061
- try cursor.writeEnum(record.file_event);
1062
- try cursor.writeEnum(record.file_outcome);
1063
- try cursor.writeInt(u64, record.file_total);
1064
- try cursor.writeInt(i64, record.file_mtime_ms);
1065
- try cursor.writeBool(record.file_exists);
1066
- try cursor.writeBool(record.file_rejected_admission);
1067
- try cursor.writeEnum(record.clipboard_op);
1068
- try cursor.writeEnum(record.clipboard_outcome);
1069
- try cursor.writeInt(u64, record.timer_timestamp_ns);
1070
- try cursor.writeEnum(record.timer_outcome);
1071
- try cursor.writeInt(i64, record.clock_wall_ms);
1072
- try cursor.writeEnum(record.audio_kind);
1073
- try cursor.writeInt(u64, record.audio_position_ms);
1074
- try cursor.writeInt(u64, record.audio_duration_ms);
1075
- try cursor.writeBool(record.audio_playing);
1076
- try cursor.writeBool(record.audio_buffering);
1077
- try cursor.writeBytes(&record.file_blob_hash);
1078
- try cursor.writeInt(u64, record.file_blob_len);
1079
- try cursor.writeBytes(&record.audio_bands);
1080
- // v7: image terminals — outcome, decoded dimensions, and the blob
1081
- // store content address of the journaled source bytes.
1082
- try cursor.writeEnum(record.image_outcome);
1083
- try cursor.writeInt(u64, record.image_width);
1084
- try cursor.writeInt(u64, record.image_height);
1085
- try cursor.writeBytes(&record.image_blob_hash);
1086
- try cursor.writeInt(u64, record.image_blob_len);
1087
- // v8: channel events — the event kind and the occupancy's
1088
- // cumulative drop total (post bytes ride `payload` inline;
1089
- // dropped_pending rides the shared `dropped` field).
1090
- try cursor.writeEnum(record.channel_kind);
1091
- try cursor.writeInt(u32, record.channel_dropped_total);
1092
- // Video terminals — the delivered event, verbatim (fingerprint
1093
- // era: these fields move the format identity through reflection).
1094
- try cursor.writeEnum(record.video_kind);
1095
- try cursor.writeInt(u64, record.video_position_ms);
1096
- try cursor.writeInt(u64, record.video_duration_ms);
1097
- try cursor.writeBool(record.video_playing);
1098
- try cursor.writeBool(record.video_buffering);
1099
- try cursor.writeInt(u64, record.video_width);
1100
- try cursor.writeInt(u64, record.video_height);
1101
- // The producing load's identity, how replay routes the record
1102
- // (`EffectResultRecord.video_token`).
1103
- try cursor.writeInt(u64, record.video_token);
1104
- // `.video_load` records: the recording host's cascade resolution.
1105
- try cursor.writeEnum(record.video_source);
1106
- // `.video` records: whether the delivery dispatched a Msg.
1107
- try cursor.writeBool(record.video_handled);
1108
- // Pty events — the event kind, the terminating signal and refused
1109
- // writes, and the blob store content address of a journaled output
1110
- // batch (exit code and reason ride the shared fields).
1111
- try cursor.writeEnum(record.pty_kind);
1112
- try cursor.writeInt(i32, record.pty_signal);
1113
- try cursor.writeInt(u32, record.pty_dropped_writes);
1114
- try cursor.writeBytes(&record.pty_blob_hash);
1115
- try cursor.writeInt(u64, record.pty_blob_len);
1116
- // Model restore is the first kind-local suffix. Keeping it conditional
1117
- // preserves every established effect record's byte layout (tests and
1118
- // tooling deliberately patch those records at known offsets).
1119
- if (record.kind == .persist) {
1120
- try cursor.writeEnum(record.persist_outcome);
1121
- try cursor.writeBytes(&record.persist_blob_hash);
1122
- try cursor.writeInt(u64, record.persist_blob_len);
1123
- }
1124
- if (record.kind == .db) {
1125
- try cursor.writeBytes(&record.db_blob_hash);
1126
- try cursor.writeInt(u64, record.db_blob_len);
1127
- }
1128
- if (record.kind == .credentials) {
1129
- try cursor.writeEnum(record.credentials_operation);
1130
- try cursor.writeEnum(record.credentials_outcome);
1131
- try cursor.writeInt(u64, record.credentials_secret_len);
1132
- try cursor.writeBytes(&record.credentials_salt);
1133
- try cursor.writeBytes(&record.credentials_digest);
1134
- }
1135
- return buffer[0..cursor.len];
426
+ pub fn decodeEffectWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!EffectResultRecord {
427
+ return codec.decodeEffect(policy, bytes);
1136
428
  }
1137
429
 
1138
- pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
1139
- var cursor = ReadCursor{ .bytes = bytes };
1140
- var record: EffectResultRecord = .{
1141
- .kind = try cursor.readEnum(runtime_effects.EffectResultKind),
1142
- .key = try cursor.readInt(u64),
1143
- .payload = try cursor.readStr(),
1144
- .stderr_tail = try cursor.readStr(),
1145
- .truncated = try cursor.readBool(),
1146
- .dropped = try cursor.readInt(u32),
1147
- .code = try cursor.readInt(i32),
1148
- .exit_reason = try cursor.readEnum(runtime_effects.EffectExitReason),
1149
- .output_truncated = try cursor.readBool(),
1150
- .stderr_truncated = try cursor.readBool(),
1151
- .status = try cursor.readInt(u16),
1152
- .fetch_outcome = try cursor.readEnum(runtime_effects.EffectFetchOutcome),
1153
- .file_op = try cursor.readEnum(runtime_effects.EffectFileOp),
1154
- .file_event = try cursor.readEnum(runtime_effects.EffectFileEvent),
1155
- .file_outcome = try cursor.readEnum(runtime_effects.EffectFileOutcome),
1156
- .file_total = try cursor.readInt(u64),
1157
- .file_mtime_ms = try cursor.readInt(i64),
1158
- .file_exists = try cursor.readBool(),
1159
- .file_rejected_admission = try cursor.readBool(),
1160
- .clipboard_op = try cursor.readEnum(runtime_effects.EffectClipboardOp),
1161
- .clipboard_outcome = try cursor.readEnum(runtime_effects.EffectClipboardOutcome),
1162
- .timer_timestamp_ns = try cursor.readInt(u64),
1163
- .timer_outcome = try cursor.readEnum(runtime_effects.EffectTimerOutcome),
1164
- .clock_wall_ms = try cursor.readInt(i64),
1165
- .audio_kind = try cursor.readEnum(runtime_effects.EffectAudioEventKind),
1166
- .audio_position_ms = try cursor.readInt(u64),
1167
- .audio_duration_ms = try cursor.readInt(u64),
1168
- .audio_playing = try cursor.readBool(),
1169
- .audio_buffering = try cursor.readBool(),
1170
- };
1171
- @memcpy(&record.file_blob_hash, try cursor.readBytes(record.file_blob_hash.len));
1172
- record.file_blob_len = try cursor.readInt(u64);
1173
- @memcpy(&record.audio_bands, try cursor.readBytes(record.audio_bands.len));
1174
- // v7: image terminals.
1175
- record.image_outcome = try cursor.readEnum(runtime_effects.EffectImageOutcome);
1176
- record.image_width = try cursor.readInt(u64);
1177
- record.image_height = try cursor.readInt(u64);
1178
- @memcpy(&record.image_blob_hash, try cursor.readBytes(record.image_blob_hash.len));
1179
- record.image_blob_len = try cursor.readInt(u64);
1180
- // v8: channel events.
1181
- record.channel_kind = try cursor.readEnum(runtime_effects.EffectChannelEventKind);
1182
- record.channel_dropped_total = try cursor.readInt(u32);
1183
- // Video terminals.
1184
- record.video_kind = try cursor.readEnum(runtime_effects.EffectVideoEventKind);
1185
- record.video_position_ms = try cursor.readInt(u64);
1186
- record.video_duration_ms = try cursor.readInt(u64);
1187
- record.video_playing = try cursor.readBool();
1188
- record.video_buffering = try cursor.readBool();
1189
- record.video_width = try cursor.readInt(u64);
1190
- record.video_height = try cursor.readInt(u64);
1191
- record.video_token = try cursor.readInt(u64);
1192
- record.video_source = try cursor.readEnum(runtime_effects.EffectVideoSource);
1193
- record.video_handled = try cursor.readBool();
1194
- // Pty events.
1195
- record.pty_kind = try cursor.readEnum(runtime_effects.EffectPtyEventKind);
1196
- record.pty_signal = try cursor.readInt(i32);
1197
- record.pty_dropped_writes = try cursor.readInt(u32);
1198
- @memcpy(&record.pty_blob_hash, try cursor.readBytes(record.pty_blob_hash.len));
1199
- record.pty_blob_len = try cursor.readInt(u64);
1200
- if (record.kind == .persist) {
1201
- record.persist_outcome = try cursor.readEnum(runtime_effects.EffectPersistOutcome);
1202
- @memcpy(&record.persist_blob_hash, try cursor.readBytes(record.persist_blob_hash.len));
1203
- record.persist_blob_len = try cursor.readInt(u64);
1204
- }
1205
- if (record.kind == .db) {
1206
- @memcpy(&record.db_blob_hash, try cursor.readBytes(record.db_blob_hash.len));
1207
- record.db_blob_len = try cursor.readInt(u64);
1208
- }
1209
- if (record.kind == .credentials) {
1210
- record.credentials_operation = try cursor.readEnum(runtime_effects.EffectCredentialsOperation);
1211
- record.credentials_outcome = try cursor.readEnum(runtime_effects.EffectCredentialsOutcome);
1212
- record.credentials_secret_len = try cursor.readInt(u64);
1213
- @memcpy(&record.credentials_salt, try cursor.readBytes(record.credentials_salt.len));
1214
- @memcpy(&record.credentials_digest, try cursor.readBytes(record.credentials_digest.len));
1215
- }
1216
- if (!cursor.done()) return error.JournalCorrupt;
1217
- return record;
430
+ pub fn encodeHeader(value: Header, buffer: []u8) JournalError![]const u8 {
431
+ return encodeHeaderWithPolicy(null, value, buffer);
1218
432
  }
1219
-
1220
- // ----------------------------------------------------- other codecs
1221
-
1222
- pub fn encodeHeader(header: Header, buffer: []u8) JournalError![]const u8 {
1223
- var cursor = WriteCursor{ .buffer = buffer };
1224
- try cursor.writeInt(u64, header.protocol_fingerprint);
1225
- try cursor.writeStr(header.platform_name);
1226
- try cursor.writeStr(header.app_name);
1227
- try cursor.writeInt(i64, header.recorded_at_wall_ms);
1228
- try cursor.writeF32(header.window_width);
1229
- try cursor.writeF32(header.window_height);
1230
- return buffer[0..cursor.len];
433
+ pub fn encodeHeaderWithPolicy(policy: journal_policy.Policy, value: Header, buffer: []u8) JournalError![]const u8 {
434
+ return codec.encodeHeader(policy, value, buffer);
1231
435
  }
1232
-
1233
436
  pub fn decodeHeader(bytes: []const u8) JournalError!Header {
1234
- var cursor = ReadCursor{ .bytes = bytes };
1235
- const header: Header = .{
1236
- .protocol_fingerprint = try cursor.readInt(u64),
1237
- .platform_name = try cursor.readStr(),
1238
- .app_name = try cursor.readStr(),
1239
- .recorded_at_wall_ms = try cursor.readInt(i64),
1240
- .window_width = try cursor.readF32(),
1241
- .window_height = try cursor.readF32(),
1242
- };
1243
- if (!cursor.done()) return error.JournalCorrupt;
1244
- return header;
437
+ return decodeHeaderWithPolicy(null, bytes);
1245
438
  }
1246
-
1247
- pub fn encodeCheckpoint(checkpoint: Checkpoint, buffer: []u8) JournalError![]const u8 {
1248
- var cursor = WriteCursor{ .buffer = buffer };
1249
- try cursor.writeInt(u64, checkpoint.event_ordinal);
1250
- try cursor.writeInt(u64, checkpoint.frame_index);
1251
- try cursor.writeInt(u64, checkpoint.fingerprint);
1252
- return buffer[0..cursor.len];
439
+ pub fn decodeHeaderWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!Header {
440
+ return codec.decodeHeader(policy, bytes);
1253
441
  }
1254
442
 
443
+ pub fn encodeCheckpoint(value: Checkpoint, buffer: []u8) JournalError![]const u8 {
444
+ return encodeCheckpointWithPolicy(null, value, buffer);
445
+ }
446
+ pub fn encodeCheckpointWithPolicy(policy: journal_policy.Policy, value: Checkpoint, buffer: []u8) JournalError![]const u8 {
447
+ return codec.encodeCheckpoint(policy, value, buffer);
448
+ }
1255
449
  pub fn decodeCheckpoint(bytes: []const u8) JournalError!Checkpoint {
1256
- var cursor = ReadCursor{ .bytes = bytes };
1257
- const checkpoint: Checkpoint = .{
1258
- .event_ordinal = try cursor.readInt(u64),
1259
- .frame_index = try cursor.readInt(u64),
1260
- .fingerprint = try cursor.readInt(u64),
1261
- };
1262
- if (!cursor.done()) return error.JournalCorrupt;
1263
- return checkpoint;
450
+ return decodeCheckpointWithPolicy(null, bytes);
1264
451
  }
1265
-
1266
- pub fn encodeScreenshot(mark: ScreenshotMark, buffer: []u8) JournalError![]const u8 {
1267
- var cursor = WriteCursor{ .buffer = buffer };
1268
- try cursor.writeInt(u64, mark.event_ordinal);
1269
- try cursor.writeStr(mark.view_label);
1270
- try cursor.writeF32(mark.scale);
1271
- try cursor.writeInt(u64, mark.png_hash);
1272
- try cursor.writeInt(u64, mark.png_len);
1273
- return buffer[0..cursor.len];
452
+ pub fn decodeCheckpointWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!Checkpoint {
453
+ return codec.decodeCheckpoint(policy, bytes);
1274
454
  }
1275
455
 
456
+ pub fn encodeScreenshot(value: ScreenshotMark, buffer: []u8) JournalError![]const u8 {
457
+ return encodeScreenshotWithPolicy(null, value, buffer);
458
+ }
459
+ pub fn encodeScreenshotWithPolicy(policy: journal_policy.Policy, value: ScreenshotMark, buffer: []u8) JournalError![]const u8 {
460
+ return codec.encodeScreenshot(policy, value, buffer);
461
+ }
1276
462
  pub fn decodeScreenshot(bytes: []const u8) JournalError!ScreenshotMark {
1277
- var cursor = ReadCursor{ .bytes = bytes };
1278
- const ordinal = try cursor.readInt(u64);
1279
- const label = try cursor.readStr();
1280
- const mark: ScreenshotMark = .{
1281
- .event_ordinal = ordinal,
1282
- .view_label = label,
1283
- .scale = try cursor.readF32(),
1284
- .png_hash = try cursor.readInt(u64),
1285
- .png_len = try cursor.readInt(u64),
1286
- };
1287
- if (!cursor.done()) return error.JournalCorrupt;
1288
- return mark;
463
+ return decodeScreenshotWithPolicy(null, bytes);
464
+ }
465
+ pub fn decodeScreenshotWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!ScreenshotMark {
466
+ return codec.decodeScreenshot(policy, bytes);
1289
467
  }
1290
468
 
1291
- pub fn encodeEnd(end: End, buffer: []u8) JournalError![]const u8 {
1292
- var cursor = WriteCursor{ .buffer = buffer };
1293
- try cursor.writeInt(u64, end.event_count);
1294
- try cursor.writeInt(u64, end.effect_count);
1295
- try cursor.writeInt(u64, end.checkpoint_count);
1296
- try cursor.writeInt(u64, end.screenshot_count);
1297
- return buffer[0..cursor.len];
469
+ pub fn encodeWindowChrome(value: WindowChromeRecord, buffer: []u8) JournalError![]const u8 {
470
+ return encodeWindowChromeWithPolicy(null, value, buffer);
471
+ }
472
+ pub fn encodeWindowChromeWithPolicy(policy: journal_policy.Policy, value: WindowChromeRecord, buffer: []u8) JournalError![]const u8 {
473
+ return codec.encodeWindowChrome(policy, value, buffer);
474
+ }
475
+ pub fn decodeWindowChrome(bytes: []const u8) JournalError!WindowChromeRecord {
476
+ return decodeWindowChromeWithPolicy(null, bytes);
477
+ }
478
+ pub fn decodeWindowChromeWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!WindowChromeRecord {
479
+ return codec.decodeWindowChrome(policy, bytes);
1298
480
  }
1299
481
 
482
+ pub fn encodeEnd(value: End, buffer: []u8) JournalError![]const u8 {
483
+ return encodeEndWithPolicy(null, value, buffer);
484
+ }
485
+ pub fn encodeEndWithPolicy(policy: journal_policy.Policy, value: End, buffer: []u8) JournalError![]const u8 {
486
+ return codec.encodeEnd(policy, value, buffer);
487
+ }
1300
488
  pub fn decodeEnd(bytes: []const u8) JournalError!End {
1301
- var cursor = ReadCursor{ .bytes = bytes };
1302
- const end: End = .{
1303
- .event_count = try cursor.readInt(u64),
1304
- .effect_count = try cursor.readInt(u64),
1305
- .checkpoint_count = try cursor.readInt(u64),
1306
- .screenshot_count = try cursor.readInt(u64),
1307
- };
1308
- if (!cursor.done()) return error.JournalCorrupt;
1309
- return end;
489
+ return decodeEndWithPolicy(null, bytes);
490
+ }
491
+ pub fn decodeEndWithPolicy(policy: journal_policy.Policy, bytes: []const u8) JournalError!End {
492
+ return codec.decodeEnd(policy, bytes);
1310
493
  }
1311
494
 
1312
495
  // ------------------------------------------------------------ framing
1313
496
 
1314
497
  /// Frame one record (kind + u32 length prefix + payload) into `buffer`.
1315
498
  pub fn frameRecord(kind: RecordKind, payload: []const u8, buffer: []u8) JournalError![]const u8 {
1316
- if (payload.len > max_session_record_bytes) return error.JournalRecordOverBudget;
1317
- if (buffer.len < 5 + payload.len) return error.JournalRecordOverBudget;
1318
- buffer[0] = @intFromEnum(kind);
1319
- std.mem.writeInt(u32, buffer[1..5], @intCast(payload.len), .little);
499
+ return frameRecordWithPolicy(null, kind, payload, buffer);
500
+ }
501
+
502
+ pub fn frameRecordWithPolicy(policy: journal_policy.Policy, kind: RecordKind, payload: []const u8, buffer: []u8) JournalError![]const u8 {
503
+ const frame = try frameHeader(policy, kind, payload.len, buffer.len);
504
+ @memcpy(buffer[0..5], &frame);
1320
505
  @memcpy(buffer[5 .. 5 + payload.len], payload);
1321
506
  return buffer[0 .. 5 + payload.len];
1322
507
  }
1323
508
 
509
+ /// A copied frame header; the caller still owns the payload and sink writes.
510
+ pub fn frameHeader(policy: journal_policy.Policy, kind: RecordKind, length: usize, capacity: usize) JournalError![5]u8 {
511
+ const decision = journal_policy.plan(policy, .frame, .{ .kind = @intFromEnum(kind), .a = length, .b = capacity, .limit = max_session_record_bytes });
512
+ try checkPlan(decision);
513
+ return decision.frame;
514
+ }
515
+
516
+ fn checkPlan(decision: journal_policy.Plan) JournalError!void {
517
+ switch (decision.action) {
518
+ .proceed, .done => {},
519
+ .bad_magic => return error.JournalBadMagic,
520
+ .format_mismatch => return error.JournalFormatMismatch,
521
+ .truncated => return error.JournalTruncated,
522
+ .corrupt => return error.JournalCorrupt,
523
+ .over_budget => return error.JournalRecordOverBudget,
524
+ .missing_header => return error.JournalMissingHeader,
525
+ .count_mismatch => return error.JournalCountMismatch,
526
+ }
527
+ }
528
+
1324
529
  /// The journal preamble (magic + format fingerprint). The fingerprint
1325
530
  /// field widened from the retired u32 counter to the full u64 hash when
1326
531
  /// identity replaced ordering — this change refuses every older journal
1327
532
  /// anyway, and the full width keeps the refuse-on-mismatch tripwire's
1328
533
  /// collision odds at 2^-64 instead of 2^-32 for free.
1329
534
  pub fn writePreamble(buffer: []u8) []const u8 {
1330
- @memcpy(buffer[0..magic.len], magic);
1331
- std.mem.writeInt(u64, buffer[magic.len..][0..8], format_fingerprint, .little);
1332
- return buffer[0 .. magic.len + 8];
535
+ return writePreambleWithPolicy(null, buffer);
536
+ }
537
+
538
+ pub fn writePreambleWithPolicy(policy: journal_policy.Policy, buffer: []u8) []const u8 {
539
+ std.debug.assert(buffer.len >= preamble_len);
540
+ const decision = journal_policy.plan(policy, .preamble, .{ .fingerprint = format_fingerprint });
541
+ if (decision.action != .proceed) @panic("invalid compiled journal preamble");
542
+ @memcpy(buffer[0..preamble_len], &decision.preamble);
543
+ return buffer[0..preamble_len];
1333
544
  }
1334
545
 
1335
546
  pub const preamble_len: usize = magic.len + 8;
@@ -1342,6 +553,7 @@ pub const preamble_len: usize = magic.len + 8;
1342
553
  pub const Reader = struct {
1343
554
  bytes: []const u8,
1344
555
  pos: usize,
556
+ policy: journal_policy.Policy = null,
1345
557
  storage: EventDecodeStorage = .{},
1346
558
  header: ?Header = null,
1347
559
  end: ?End = null,
@@ -1349,65 +561,73 @@ pub const Reader = struct {
1349
561
  effect_count: u64 = 0,
1350
562
  checkpoint_count: u64 = 0,
1351
563
  screenshot_count: u64 = 0,
564
+ window_chrome_count: u64 = 0,
1352
565
 
1353
566
  pub fn init(bytes: []const u8) JournalError!Reader {
1354
- if (bytes.len < preamble_len) return error.JournalBadMagic;
1355
- if (!std.mem.eql(u8, bytes[0..magic.len], magic)) return error.JournalBadMagic;
1356
- const recorded = std.mem.readInt(u64, bytes[magic.len..][0..8], .little);
1357
- if (recorded != format_fingerprint) return error.JournalFormatMismatch;
1358
- return .{ .bytes = bytes, .pos = preamble_len };
567
+ return initWithPolicy(bytes, null);
568
+ }
569
+
570
+ pub fn initWithPolicy(bytes: []const u8, policy: journal_policy.Policy) JournalError!Reader {
571
+ const decision = journal_policy.plan(policy, .init, .{ .a = bytes.len, .fingerprint = format_fingerprint, .sample = bytes[0..@min(bytes.len, preamble_len)] });
572
+ try checkPlan(decision);
573
+ return .{ .bytes = bytes, .pos = @intCast(decision.pos), .policy = policy };
574
+ }
575
+
576
+ fn counts(self: *const Reader) [5]u64 {
577
+ return .{ self.event_count, self.effect_count, self.checkpoint_count, self.screenshot_count, self.window_chrome_count };
1359
578
  }
1360
579
 
1361
580
  /// The next record, or null after the end record. Records after the
1362
581
  /// end record, a missing end record, and count mismatches are all
1363
582
  /// refused.
1364
583
  pub fn next(self: *Reader) JournalError!?Record {
1365
- if (self.end != null) {
1366
- if (self.pos != self.bytes.len) return error.JournalCorrupt;
1367
- return null;
1368
- }
1369
- if (self.pos == self.bytes.len) return error.JournalTruncated;
1370
- if (self.bytes.len - self.pos < 5) return error.JournalTruncated;
1371
- const kind = std.enums.fromInt(RecordKind, self.bytes[self.pos]) orelse return error.JournalCorrupt;
1372
- const len = std.mem.readInt(u32, self.bytes[self.pos + 1 ..][0..4], .little);
1373
- if (len > max_session_record_bytes) return error.JournalRecordOverBudget;
1374
- if (self.bytes.len - self.pos - 5 < len) return error.JournalTruncated;
1375
- const payload = self.bytes[self.pos + 5 .. self.pos + 5 + len];
1376
- self.pos += 5 + len;
1377
-
1378
- if (self.header == null and kind != .header) return error.JournalMissingHeader;
584
+ const old_pos = self.pos;
585
+ const decision = journal_policy.plan(self.policy, .next, .{
586
+ .a = self.bytes.len,
587
+ .b = self.pos,
588
+ .header = self.header != null,
589
+ .ended = self.end != null,
590
+ .counts = self.counts(),
591
+ .sample = self.bytes[self.pos..][0..@min(self.bytes.len - self.pos, 5)],
592
+ .limit = max_session_record_bytes,
593
+ });
594
+ // The admitted frame advances position and counters before payload
595
+ // decoding. Even failed decodes retain those mutations.
596
+ self.pos = @intCast(decision.pos);
597
+ self.event_count = decision.counts[0];
598
+ self.effect_count = decision.counts[1];
599
+ self.checkpoint_count = decision.counts[2];
600
+ self.screenshot_count = decision.counts[3];
601
+ self.window_chrome_count = decision.counts[4];
602
+ try checkPlan(decision);
603
+ if (decision.action == .done) return null;
604
+ const kind = std.enums.fromInt(RecordKind, decision.kind) orelse @panic("invalid compiled journal record kind");
605
+ const payload = self.bytes[old_pos + 5 .. self.pos];
606
+
1379
607
  switch (kind) {
1380
608
  .header => {
1381
- if (self.header != null) return error.JournalCorrupt;
1382
- const header = try decodeHeader(payload);
609
+ const header = try decodeHeaderWithPolicy(self.policy, payload);
1383
610
  self.header = header;
1384
611
  return .{ .header = header };
1385
612
  },
1386
613
  .event => {
1387
- self.event_count += 1;
1388
- return .{ .event = try decodeEvent(payload, &self.storage) };
614
+ return .{ .event = try decodeEventWithPolicy(self.policy, payload, &self.storage) };
1389
615
  },
1390
616
  .effect => {
1391
- self.effect_count += 1;
1392
- return .{ .effect = try decodeEffect(payload) };
617
+ return .{ .effect = try decodeEffectWithPolicy(self.policy, payload) };
1393
618
  },
1394
619
  .checkpoint => {
1395
- self.checkpoint_count += 1;
1396
- return .{ .checkpoint = try decodeCheckpoint(payload) };
620
+ return .{ .checkpoint = try decodeCheckpointWithPolicy(self.policy, payload) };
1397
621
  },
1398
622
  .screenshot => {
1399
- self.screenshot_count += 1;
1400
- return .{ .screenshot = try decodeScreenshot(payload) };
623
+ return .{ .screenshot = try decodeScreenshotWithPolicy(self.policy, payload) };
624
+ },
625
+ .window_chrome => {
626
+ return .{ .window_chrome = try decodeWindowChromeWithPolicy(self.policy, payload) };
1401
627
  },
1402
628
  .end => {
1403
- const end = try decodeEnd(payload);
1404
- if (end.event_count != self.event_count or
1405
- end.effect_count != self.effect_count or
1406
- end.checkpoint_count != self.checkpoint_count or
1407
- end.screenshot_count != self.screenshot_count)
1408
- {
1409
- return error.JournalCountMismatch;
1410
- }
629
+ const end = try decodeEndWithPolicy(self.policy, payload);
630
+ try checkPlan(journal_policy.plan(self.policy, .seal, .{ .counts = self.counts(), .sealed = .{ end.event_count, end.effect_count, end.checkpoint_count, end.screenshot_count, end.window_chrome_count } }));
1411
631
  self.end = end;
1412
632
  return .{ .end = end };
1413
633
  },
@@ -1614,6 +834,18 @@ test "event codec round-trips every payload variant" {
1614
834
  try testing.expectEqual(@as(?usize, 3), decoded.gpu_surface_input.composition_cursor);
1615
835
  try testing.expect(decoded.gpu_surface_input.modifiers.control);
1616
836
  try testing.expectEqual(@as(f32, 0), decoded.gpu_surface_input.scale);
837
+ try testing.expect(!decoded.gpu_surface_input.scroll_is_detented);
838
+ }
839
+ {
840
+ const decoded = try roundTripEvent(.{ .gpu_surface_input = .{
841
+ .label = "feed-canvas",
842
+ .kind = .scroll,
843
+ .delta_y = 40,
844
+ .scroll_is_detented = true,
845
+ } });
846
+ try testing.expectEqual(platform.GpuSurfaceInputKind.scroll, decoded.gpu_surface_input.kind);
847
+ try testing.expectEqual(@as(f32, 40), decoded.gpu_surface_input.delta_y);
848
+ try testing.expect(decoded.gpu_surface_input.scroll_is_detented);
1617
849
  }
1618
850
  {
1619
851
  // Command+Backspace journals as the raw platform key chord; replay
@@ -1671,6 +903,10 @@ test "event codec round-trips every payload variant" {
1671
903
  try testing.expectEqual(@as(f32, -12.5), decoded.gpu_surface_scroll_driver.offset_y);
1672
904
  try testing.expectEqual(@as(f32, 7.25), decoded.gpu_surface_scroll_driver.offset_x);
1673
905
  }
906
+ {
907
+ const decoded = try roundTripEvent(.{ .widget_context_menu_action = .{ .window_id = 7, .label = "secondary", .id = 0xffffffffffffffff, .item_index = 31 } });
908
+ try testing.expectEqualDeep(platform.WidgetContextMenuActionEvent{ .window_id = 7, .label = "secondary", .id = 0xffffffffffffffff, .item_index = 31 }, decoded.widget_context_menu_action);
909
+ }
1674
910
  {
1675
911
  const decoded = try roundTripEvent(.{ .context_menu_action = .{ .view_label = "canvas", .token = 5, .item_id = 2 } });
1676
912
  try testing.expectEqual(@as(u32, 2), decoded.context_menu_action.item_id);
@@ -2101,3 +1337,30 @@ test "reader requires the header first" {
2101
1337
  var reader = try Reader.init(buffer[0..len]);
2102
1338
  try testing.expectError(error.JournalMissingHeader, reader.next());
2103
1339
  }
1340
+
1341
+ test "window chrome codec preserves every OS field and refuses damaged payloads" {
1342
+ const expected: WindowChromeRecord = .{
1343
+ .window_id = 18446744073709551615,
1344
+ .chrome = .{ .insets = .{ .top = 66, .right = 7.25, .bottom = 3.5, .left = 98 }, .buttons = .init(20, 26, 68, 14), .form_factor = .compact, .tabs_projected = true },
1345
+ };
1346
+ var buffer: [64]u8 = undefined;
1347
+ const bytes = try encodeWindowChrome(expected, &buffer);
1348
+ try testing.expectEqualDeep(expected, try decodeWindowChrome(bytes));
1349
+ for (0..bytes.len) |len| try testing.expectError(error.JournalCorrupt, decodeWindowChrome(bytes[0..len]));
1350
+ buffer[bytes.len] = 0;
1351
+ try testing.expectError(error.JournalCorrupt, decodeWindowChrome(buffer[0 .. bytes.len + 1]));
1352
+ buffer[40] = 255;
1353
+ try testing.expectError(error.JournalCorrupt, decodeWindowChrome(bytes));
1354
+ buffer[40] = 1;
1355
+ buffer[41] = 2;
1356
+ try testing.expectError(error.JournalCorrupt, decodeWindowChrome(bytes));
1357
+ }
1358
+
1359
+ comptime {
1360
+ if (!std.mem.eql(u8, magic, "NSDKSJNL") or preamble_len != 16 or max_session_record_bytes != 1114112 or
1361
+ @typeInfo(RecordKind).@"enum".fields.len != 7 or @intFromEnum(RecordKind.header) != 1 or
1362
+ @intFromEnum(RecordKind.event) != 2 or @intFromEnum(RecordKind.effect) != 3 or
1363
+ @intFromEnum(RecordKind.checkpoint) != 4 or @intFromEnum(RecordKind.screenshot) != 5 or
1364
+ @intFromEnum(RecordKind.end) != 6 or @intFromEnum(RecordKind.window_chrome) != 7)
1365
+ @compileError("update the portable journal framing schema with the journal format");
1366
+ }