@native-sdk/cli 0.0.0 → 0.4.1

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 (373) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +50 -1
  3. package/app.zon +30 -0
  4. package/assets/icon.icns +0 -0
  5. package/assets/icon.ico +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +15 -0
  8. package/assets/native-sdk.entitlements +10 -0
  9. package/assets/native-sdk.manifest +12 -0
  10. package/bin/native.js +156 -0
  11. package/build/app.zig +716 -0
  12. package/build.zig +2593 -0
  13. package/build.zig.zon +24 -0
  14. package/native-sdk.d.ts +615 -0
  15. package/package.json +45 -8
  16. package/skill-data/automation/SKILL.md +248 -0
  17. package/skill-data/core/SKILL.md +249 -0
  18. package/skill-data/core/references/app-model-runtime.md +141 -0
  19. package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
  20. package/skill-data/core/references/frontend-assets.md +124 -0
  21. package/skill-data/core/references/project-anatomy.md +108 -0
  22. package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
  23. package/skill-data/native-ui/SKILL.md +1080 -0
  24. package/skills/native-sdk/SKILL.md +33 -0
  25. package/src/app_runner/root.zig +740 -0
  26. package/src/assets/root.zig +20 -0
  27. package/src/automation/protocol.zig +285 -0
  28. package/src/automation/root.zig +13 -0
  29. package/src/automation/server.zig +506 -0
  30. package/src/automation/snapshot.zig +1202 -0
  31. package/src/automation/watcher.zig +165 -0
  32. package/src/bridge/root.zig +507 -0
  33. package/src/debug/root.zig +246 -0
  34. package/src/embed/app_exports.zig +11 -0
  35. package/src/embed/c_api.zig +793 -0
  36. package/src/embed/c_exports.zig +10 -0
  37. package/src/embed/chrome.zig +168 -0
  38. package/src/embed/conversions.zig +359 -0
  39. package/src/embed/host.zig +960 -0
  40. package/src/embed/root.zig +81 -0
  41. package/src/embed/tests.zig +2552 -0
  42. package/src/embed/types.zig +382 -0
  43. package/src/embed/ui_host.zig +289 -0
  44. package/src/extensions/root.zig +197 -0
  45. package/src/frontend/root.zig +48 -0
  46. package/src/js/root.zig +65 -0
  47. package/src/platform/android/NativeSdkActivity.java +1370 -0
  48. package/src/platform/android/android_host.c +696 -0
  49. package/src/platform/android/files.zig +9 -0
  50. package/src/platform/android/native_sdk_app.h +237 -0
  51. package/src/platform/ios/files.zig +8 -0
  52. package/src/platform/ios/native_sdk_app.h +289 -0
  53. package/src/platform/ios/uikit_host.m +2739 -0
  54. package/src/platform/linux/cef_host.cpp +599 -0
  55. package/src/platform/linux/gtk_host.c +5362 -0
  56. package/src/platform/linux/gtk_host.h +265 -0
  57. package/src/platform/linux/root.zig +1519 -0
  58. package/src/platform/macos/appkit_host.h +604 -0
  59. package/src/platform/macos/appkit_host.m +10392 -0
  60. package/src/platform/macos/automation_host.h +14 -0
  61. package/src/platform/macos/automation_host.m +12 -0
  62. package/src/platform/macos/cef_host.mm +3028 -0
  63. package/src/platform/macos/root.zig +2260 -0
  64. package/src/platform/null_platform.zig +2232 -0
  65. package/src/platform/null_platform_tests.zig +670 -0
  66. package/src/platform/policy_values.zig +14 -0
  67. package/src/platform/root.zig +181 -0
  68. package/src/platform/types.zig +2681 -0
  69. package/src/platform/windows/cef_host.cpp +3 -0
  70. package/src/platform/windows/root.zig +1521 -0
  71. package/src/platform/windows/webview2_host.cpp +6230 -0
  72. package/src/primitives/app_dirs/root.zig +440 -0
  73. package/src/primitives/app_manifest/root.zig +109 -0
  74. package/src/primitives/app_manifest/tests.zig +758 -0
  75. package/src/primitives/app_manifest/types.zig +587 -0
  76. package/src/primitives/app_manifest/validation.zig +828 -0
  77. package/src/primitives/assets/root.zig +520 -0
  78. package/src/primitives/canvas/a11y_audit.zig +390 -0
  79. package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
  80. package/src/primitives/canvas/app_icon.zig +1590 -0
  81. package/src/primitives/canvas/chart.zig +392 -0
  82. package/src/primitives/canvas/chart_tests.zig +751 -0
  83. package/src/primitives/canvas/commands.zig +446 -0
  84. package/src/primitives/canvas/drawing.zig +309 -0
  85. package/src/primitives/canvas/equality.zig +316 -0
  86. package/src/primitives/canvas/events.zig +696 -0
  87. package/src/primitives/canvas/font_coverage.zig +118 -0
  88. package/src/primitives/canvas/font_ttf.zig +510 -0
  89. package/src/primitives/canvas/font_ttf_tests.zig +280 -0
  90. package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
  91. package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
  92. package/src/primitives/canvas/frame.zig +679 -0
  93. package/src/primitives/canvas/frame_metrics.zig +462 -0
  94. package/src/primitives/canvas/gpu.zig +639 -0
  95. package/src/primitives/canvas/hash.zig +112 -0
  96. package/src/primitives/canvas/icons/alert.svg +1 -0
  97. package/src/primitives/canvas/icons/archive.svg +1 -0
  98. package/src/primitives/canvas/icons/arrow-down.svg +1 -0
  99. package/src/primitives/canvas/icons/arrow-right.svg +1 -0
  100. package/src/primitives/canvas/icons/arrow-up.svg +1 -0
  101. package/src/primitives/canvas/icons/check-circle.svg +1 -0
  102. package/src/primitives/canvas/icons/check.svg +1 -0
  103. package/src/primitives/canvas/icons/chevron-down.svg +1 -0
  104. package/src/primitives/canvas/icons/chevron-left.svg +1 -0
  105. package/src/primitives/canvas/icons/chevron-right.svg +1 -0
  106. package/src/primitives/canvas/icons/chevron-up.svg +1 -0
  107. package/src/primitives/canvas/icons/circle-dot.svg +1 -0
  108. package/src/primitives/canvas/icons/clock.svg +1 -0
  109. package/src/primitives/canvas/icons/copy.svg +1 -0
  110. package/src/primitives/canvas/icons/download.svg +1 -0
  111. package/src/primitives/canvas/icons/edit.svg +1 -0
  112. package/src/primitives/canvas/icons/ellipsis.svg +1 -0
  113. package/src/primitives/canvas/icons/external-link.svg +1 -0
  114. package/src/primitives/canvas/icons/eye.svg +1 -0
  115. package/src/primitives/canvas/icons/file-text.svg +1 -0
  116. package/src/primitives/canvas/icons/folder-open.svg +1 -0
  117. package/src/primitives/canvas/icons/folder.svg +1 -0
  118. package/src/primitives/canvas/icons/git-branch.svg +1 -0
  119. package/src/primitives/canvas/icons/git-merge.svg +1 -0
  120. package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
  121. package/src/primitives/canvas/icons/info.svg +1 -0
  122. package/src/primitives/canvas/icons/menu.svg +1 -0
  123. package/src/primitives/canvas/icons/missing.svg +1 -0
  124. package/src/primitives/canvas/icons/moon.svg +1 -0
  125. package/src/primitives/canvas/icons/music.svg +1 -0
  126. package/src/primitives/canvas/icons/panel-left.svg +1 -0
  127. package/src/primitives/canvas/icons/panel-right.svg +1 -0
  128. package/src/primitives/canvas/icons/pause.svg +1 -0
  129. package/src/primitives/canvas/icons/play.svg +1 -0
  130. package/src/primitives/canvas/icons/plus.svg +1 -0
  131. package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
  132. package/src/primitives/canvas/icons/repeat.svg +1 -0
  133. package/src/primitives/canvas/icons/save.svg +1 -0
  134. package/src/primitives/canvas/icons/search.svg +1 -0
  135. package/src/primitives/canvas/icons/send.svg +1 -0
  136. package/src/primitives/canvas/icons/settings.svg +1 -0
  137. package/src/primitives/canvas/icons/shuffle.svg +1 -0
  138. package/src/primitives/canvas/icons/skip-back.svg +1 -0
  139. package/src/primitives/canvas/icons/skip-forward.svg +1 -0
  140. package/src/primitives/canvas/icons/sun.svg +1 -0
  141. package/src/primitives/canvas/icons/terminal.svg +1 -0
  142. package/src/primitives/canvas/icons/trash.svg +1 -0
  143. package/src/primitives/canvas/icons/volume.svg +1 -0
  144. package/src/primitives/canvas/icons/wrench.svg +1 -0
  145. package/src/primitives/canvas/icons/x-circle.svg +1 -0
  146. package/src/primitives/canvas/icons/x.svg +1 -0
  147. package/src/primitives/canvas/icons.zig +249 -0
  148. package/src/primitives/canvas/layout_audit.zig +744 -0
  149. package/src/primitives/canvas/layout_audit_tests.zig +426 -0
  150. package/src/primitives/canvas/markdown.zig +1031 -0
  151. package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
  152. package/src/primitives/canvas/markdown_tests.zig +538 -0
  153. package/src/primitives/canvas/plan_key_index.zig +120 -0
  154. package/src/primitives/canvas/png.zig +355 -0
  155. package/src/primitives/canvas/reference.zig +1457 -0
  156. package/src/primitives/canvas/reference_blur.zig +104 -0
  157. package/src/primitives/canvas/reference_memo.zig +322 -0
  158. package/src/primitives/canvas/reference_paths.zig +184 -0
  159. package/src/primitives/canvas/reference_tests.zig +1650 -0
  160. package/src/primitives/canvas/render.zig +747 -0
  161. package/src/primitives/canvas/render_effects.zig +255 -0
  162. package/src/primitives/canvas/render_fingerprints.zig +256 -0
  163. package/src/primitives/canvas/render_generic_resources.zig +376 -0
  164. package/src/primitives/canvas/render_images.zig +247 -0
  165. package/src/primitives/canvas/render_layers.zig +260 -0
  166. package/src/primitives/canvas/render_paths.zig +347 -0
  167. package/src/primitives/canvas/render_resources.zig +51 -0
  168. package/src/primitives/canvas/render_tests.zig +3186 -0
  169. package/src/primitives/canvas/root.zig +744 -0
  170. package/src/primitives/canvas/serialization.zig +1528 -0
  171. package/src/primitives/canvas/svg_icon.zig +636 -0
  172. package/src/primitives/canvas/svg_icon_tests.zig +312 -0
  173. package/src/primitives/canvas/test_support.zig +422 -0
  174. package/src/primitives/canvas/testdata/markdown_document.md +83 -0
  175. package/src/primitives/canvas/tests.zig +30 -0
  176. package/src/primitives/canvas/text.zig +82 -0
  177. package/src/primitives/canvas/text_atlas.zig +408 -0
  178. package/src/primitives/canvas/text_batch_tests.zig +431 -0
  179. package/src/primitives/canvas/text_interaction.zig +615 -0
  180. package/src/primitives/canvas/text_layout.zig +1069 -0
  181. package/src/primitives/canvas/text_layout_cache.zig +281 -0
  182. package/src/primitives/canvas/text_layout_hash.zig +113 -0
  183. package/src/primitives/canvas/text_layout_types.zig +128 -0
  184. package/src/primitives/canvas/text_measure_cache.zig +279 -0
  185. package/src/primitives/canvas/text_metrics.zig +309 -0
  186. package/src/primitives/canvas/text_metrics_tests.zig +262 -0
  187. package/src/primitives/canvas/text_span_tests.zig +608 -0
  188. package/src/primitives/canvas/text_spans.zig +1010 -0
  189. package/src/primitives/canvas/text_tests.zig +1949 -0
  190. package/src/primitives/canvas/themes/geist.zig +470 -0
  191. package/src/primitives/canvas/tokens.zig +1522 -0
  192. package/src/primitives/canvas/ui.zig +2686 -0
  193. package/src/primitives/canvas/ui_markup.zig +3791 -0
  194. package/src/primitives/canvas/ui_markup_binary.zig +522 -0
  195. package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
  196. package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
  197. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
  198. package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
  199. package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
  200. package/src/primitives/canvas/ui_markup_edit.zig +416 -0
  201. package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
  202. package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
  203. package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
  204. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
  205. package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
  206. package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
  207. package/src/primitives/canvas/ui_markup_view.zig +2352 -0
  208. package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
  209. package/src/primitives/canvas/ui_provenance.zig +96 -0
  210. package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
  211. package/src/primitives/canvas/ui_schema.zig +825 -0
  212. package/src/primitives/canvas/ui_schema_tests.zig +128 -0
  213. package/src/primitives/canvas/ui_tests.zig +1432 -0
  214. package/src/primitives/canvas/vector.zig +919 -0
  215. package/src/primitives/canvas/vector_tests.zig +547 -0
  216. package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
  217. package/src/primitives/canvas/virtual_extents.zig +540 -0
  218. package/src/primitives/canvas/widget_access.zig +208 -0
  219. package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
  220. package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
  221. package/src/primitives/canvas/widget_invalidation.zig +748 -0
  222. package/src/primitives/canvas/widget_layout.zig +2055 -0
  223. package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
  224. package/src/primitives/canvas/widget_metrics.zig +228 -0
  225. package/src/primitives/canvas/widget_render.zig +2534 -0
  226. package/src/primitives/canvas/widget_render_controls.zig +1563 -0
  227. package/src/primitives/canvas/widget_render_scroll.zig +136 -0
  228. package/src/primitives/canvas/widget_render_style.zig +626 -0
  229. package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
  230. package/src/primitives/canvas/widget_routing.zig +475 -0
  231. package/src/primitives/canvas/widget_runtime.zig +307 -0
  232. package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
  233. package/src/primitives/canvas/widget_semantics.zig +480 -0
  234. package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
  235. package/src/primitives/canvas/widget_tests.zig +8 -0
  236. package/src/primitives/canvas/widget_text_input.zig +351 -0
  237. package/src/primitives/canvas/widget_text_select.zig +147 -0
  238. package/src/primitives/canvas/widget_tree.zig +232 -0
  239. package/src/primitives/canvas/widgets.zig +1319 -0
  240. package/src/primitives/diagnostics/root.zig +445 -0
  241. package/src/primitives/geometry/root.zig +889 -0
  242. package/src/primitives/json/root.zig +272 -0
  243. package/src/primitives/platform_info/root.zig +450 -0
  244. package/src/primitives/trace/root.zig +569 -0
  245. package/src/root.zig +165 -0
  246. package/src/runtime/api.zig +431 -0
  247. package/src/runtime/async_bridge.zig +49 -0
  248. package/src/runtime/automation_commands.zig +686 -0
  249. package/src/runtime/automation_liveness_tests.zig +140 -0
  250. package/src/runtime/automation_snapshot.zig +246 -0
  251. package/src/runtime/automation_widget_dispatch.zig +617 -0
  252. package/src/runtime/bridge_dispatch_tests.zig +202 -0
  253. package/src/runtime/bridge_payload.zig +194 -0
  254. package/src/runtime/bridge_permission_tests.zig +551 -0
  255. package/src/runtime/bridge_responses.zig +414 -0
  256. package/src/runtime/builtin_bridge.zig +554 -0
  257. package/src/runtime/canvas_budget_edge_tests.zig +415 -0
  258. package/src/runtime/canvas_font_tests.zig +410 -0
  259. package/src/runtime/canvas_fonts.zig +229 -0
  260. package/src/runtime/canvas_frame.zig +1734 -0
  261. package/src/runtime/canvas_frame_animation_tests.zig +609 -0
  262. package/src/runtime/canvas_frame_cache_tests.zig +333 -0
  263. package/src/runtime/canvas_frame_helpers.zig +414 -0
  264. package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
  265. package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
  266. package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
  267. package/src/runtime/canvas_frame_retained_tests.zig +753 -0
  268. package/src/runtime/canvas_frame_tests.zig +9 -0
  269. package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
  270. package/src/runtime/canvas_image_tests.zig +362 -0
  271. package/src/runtime/canvas_images.zig +224 -0
  272. package/src/runtime/canvas_limits.zig +317 -0
  273. package/src/runtime/canvas_screenshot_tests.zig +289 -0
  274. package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
  275. package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
  276. package/src/runtime/canvas_widget_chart_tests.zig +249 -0
  277. package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
  278. package/src/runtime/canvas_widget_context_menu.zig +318 -0
  279. package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
  280. package/src/runtime/canvas_widget_control_tests.zig +2164 -0
  281. package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
  282. package/src/runtime/canvas_widget_display.zig +677 -0
  283. package/src/runtime/canvas_widget_event_tests.zig +1779 -0
  284. package/src/runtime/canvas_widget_events.zig +1098 -0
  285. package/src/runtime/canvas_widget_floating_tests.zig +695 -0
  286. package/src/runtime/canvas_widget_layout_tests.zig +26 -0
  287. package/src/runtime/canvas_widget_runtime.zig +1335 -0
  288. package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
  289. package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
  290. package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
  291. package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
  292. package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
  293. package/src/runtime/canvas_widget_state.zig +798 -0
  294. package/src/runtime/canvas_widget_text_tests.zig +2104 -0
  295. package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
  296. package/src/runtime/clock.zig +231 -0
  297. package/src/runtime/core.zig +927 -0
  298. package/src/runtime/effects.zig +4197 -0
  299. package/src/runtime/effects_audio_tests.zig +690 -0
  300. package/src/runtime/effects_clipboard_tests.zig +317 -0
  301. package/src/runtime/effects_fetch_tests.zig +1031 -0
  302. package/src/runtime/effects_file_tests.zig +407 -0
  303. package/src/runtime/effects_tests.zig +1251 -0
  304. package/src/runtime/flow.zig +1175 -0
  305. package/src/runtime/frame_profile.zig +221 -0
  306. package/src/runtime/gpu_surface_events.zig +639 -0
  307. package/src/runtime/launch_timing.zig +59 -0
  308. package/src/runtime/markdown_app_tests.zig +224 -0
  309. package/src/runtime/native_command_event_tests.zig +431 -0
  310. package/src/runtime/platform_bridge_tests.zig +8 -0
  311. package/src/runtime/platform_config_tests.zig +392 -0
  312. package/src/runtime/root.zig +150 -0
  313. package/src/runtime/runtime_event_tests.zig +1079 -0
  314. package/src/runtime/session_journal.zig +1522 -0
  315. package/src/runtime/session_record.zig +332 -0
  316. package/src/runtime/session_replay.zig +274 -0
  317. package/src/runtime/session_state.zig +30 -0
  318. package/src/runtime/session_tests.zig +399 -0
  319. package/src/runtime/shell_layout.zig +472 -0
  320. package/src/runtime/shell_layout_tests.zig +1246 -0
  321. package/src/runtime/shell_view_tests.zig +604 -0
  322. package/src/runtime/state.zig +110 -0
  323. package/src/runtime/system_services.zig +392 -0
  324. package/src/runtime/test_support.zig +79 -0
  325. package/src/runtime/tests.zig +30 -0
  326. package/src/runtime/ui_app.zig +3290 -0
  327. package/src/runtime/ui_app_huge_model_tests.zig +351 -0
  328. package/src/runtime/ui_app_provenance.zig +370 -0
  329. package/src/runtime/ui_app_tests.zig +3254 -0
  330. package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
  331. package/src/runtime/ui_app_window_tests.zig +442 -0
  332. package/src/runtime/validation.zig +206 -0
  333. package/src/runtime/view.zig +908 -0
  334. package/src/runtime/view_canvas.zig +850 -0
  335. package/src/runtime/view_widget_control.zig +433 -0
  336. package/src/runtime/view_widget_scroll.zig +360 -0
  337. package/src/runtime/view_widget_text.zig +275 -0
  338. package/src/runtime/view_widget_tree.zig +843 -0
  339. package/src/runtime/webview_view_bridge_tests.zig +664 -0
  340. package/src/runtime/widget_bridge.zig +231 -0
  341. package/src/runtime/window_command_bridge_tests.zig +403 -0
  342. package/src/runtime/window_storage.zig +255 -0
  343. package/src/runtime/window_view_runtime.zig +727 -0
  344. package/src/runtime/window_views.zig +334 -0
  345. package/src/security/root.zig +118 -0
  346. package/src/tooling/android.zig +1172 -0
  347. package/src/tooling/assets.zig +128 -0
  348. package/src/tooling/buildgraph.zig +379 -0
  349. package/src/tooling/cef.zig +671 -0
  350. package/src/tooling/codesign.zig +172 -0
  351. package/src/tooling/components/identity_tests.zig +185 -0
  352. package/src/tooling/components/stepper.zig +113 -0
  353. package/src/tooling/components/timeline.native +27 -0
  354. package/src/tooling/components/timeline_item.zig +131 -0
  355. package/src/tooling/default_icon.icns +0 -0
  356. package/src/tooling/default_icon.png +0 -0
  357. package/src/tooling/dev.zig +172 -0
  358. package/src/tooling/doctor.zig +349 -0
  359. package/src/tooling/eject_components.zig +170 -0
  360. package/src/tooling/embedlib.zig +290 -0
  361. package/src/tooling/ios.zig +528 -0
  362. package/src/tooling/manifest.zig +1939 -0
  363. package/src/tooling/package.zig +2388 -0
  364. package/src/tooling/process_tree.zig +114 -0
  365. package/src/tooling/raw_manifest.zig +193 -0
  366. package/src/tooling/root.zig +22 -0
  367. package/src/tooling/templates.zig +3191 -0
  368. package/src/tooling/toolchain.zig +371 -0
  369. package/src/tooling/verbs.zig +204 -0
  370. package/src/tooling/web_engine.zig +135 -0
  371. package/src/tooling/xcodeproj.zig +462 -0
  372. package/src/window_state/root.zig +507 -0
  373. package/index.js +0 -2
@@ -0,0 +1,332 @@
1
+ //! Session recorder: streams a live session into the journal format.
2
+ //!
3
+ //! Wired through `Runtime.Options.session_recorder`, the dispatch choke
4
+ //! point stages every platform event on entry and commits it on exit, so
5
+ //! effect results drained DURING an event's dispatch land in the stream
6
+ //! BEFORE the event record — the ordering replay depends on (feed the
7
+ //! stub executor, then dispatch). Nested dispatches (automation commands
8
+ //! inside `frame_requested`) commit innermost-first for the same reason.
9
+ //!
10
+ //! Recording must never take the app down: any failure — a sink write
11
+ //! error, an over-budget event, a journal past its size budget — flips
12
+ //! the recorder into a failed state that says so loudly on stderr ONCE
13
+ //! and drops everything after. A failed recording has no end record, so
14
+ //! replay refuses it as truncated instead of silently replaying a
15
+ //! prefix.
16
+ //!
17
+ //! The struct embeds multi-megabyte staging buffers — construct it on
18
+ //! the heap (the Runtime precedent).
19
+
20
+ const std = @import("std");
21
+ const platform = @import("../platform/root.zig");
22
+ const runtime_clock = @import("clock.zig");
23
+ const runtime_effects = @import("effects.zig");
24
+ const journal = @import("session_journal.zig");
25
+
26
+ pub const Header = journal.Header;
27
+
28
+ /// Where journal bytes go. The app runner backs this with a file opened
29
+ /// at launch; tests back it with a growable buffer.
30
+ pub const RecorderSink = struct {
31
+ context: *anyopaque,
32
+ write_fn: *const fn (context: *anyopaque, bytes: []const u8) anyerror!void,
33
+ };
34
+
35
+ pub const SessionRecorder = struct {
36
+ sink: RecorderSink,
37
+ began: bool = false,
38
+ finished: bool = false,
39
+ failed: bool = false,
40
+ bytes_written: u64 = 0,
41
+ event_count: u64 = 0,
42
+ effect_count: u64 = 0,
43
+ checkpoint_count: u64 = 0,
44
+ screenshot_count: u64 = 0,
45
+ /// Frame index of the last recorded checkpoint, so exactly one
46
+ /// checkpoint follows each published frame.
47
+ last_checkpoint_frame: u64 = 0,
48
+ depth: usize = 0,
49
+ staged_lens: [journal.max_session_event_depth]usize = [_]usize{0} ** journal.max_session_event_depth,
50
+ staged: [journal.max_session_event_depth][journal.max_session_event_bytes]u8 = undefined,
51
+ /// Encode scratch for effect payloads (up to a whole file read).
52
+ effect_buffer: [journal.max_session_record_bytes]u8 = undefined,
53
+ small_buffer: [1024]u8 = undefined,
54
+
55
+ pub fn init(sink: RecorderSink) SessionRecorder {
56
+ return .{ .sink = sink };
57
+ }
58
+
59
+ /// Write the preamble and session header. Must run before the first
60
+ /// dispatched event.
61
+ pub fn begin(self: *SessionRecorder, header: Header) void {
62
+ if (self.began or self.failed) return;
63
+ self.began = true;
64
+ var preamble_buffer: [journal.preamble_len]u8 = undefined;
65
+ self.write(journal.writePreamble(&preamble_buffer));
66
+ const payload = journal.encodeHeader(header, &self.small_buffer) catch {
67
+ return self.fail("session header does not fit its record budget");
68
+ };
69
+ self.writeRecord(.header, payload);
70
+ }
71
+
72
+ /// Serialize `event` into the staging stack. Effect results drained
73
+ /// during its dispatch write directly to the stream; `commitEvent`
74
+ /// then appends the event record after them.
75
+ pub fn stageEvent(self: *SessionRecorder, event: platform.Event) void {
76
+ if (!self.began or self.failed or self.finished) return;
77
+ if (self.depth >= journal.max_session_event_depth) {
78
+ return self.fail("dispatch nesting exceeded max_session_event_depth - this is a runtime bug, not a session shape");
79
+ }
80
+ const encoded = journal.encodeEvent(event, &self.staged[self.depth]) catch {
81
+ return self.fail("a platform event exceeded max_session_event_bytes");
82
+ };
83
+ self.staged_lens[self.depth] = encoded.len;
84
+ self.depth += 1;
85
+ }
86
+
87
+ /// Append the innermost staged event record. Call exactly once per
88
+ /// successful `stageEvent`, on dispatch exit.
89
+ pub fn commitEvent(self: *SessionRecorder) void {
90
+ if (!self.began or self.failed or self.finished) return;
91
+ if (self.depth == 0) return;
92
+ self.depth -= 1;
93
+ self.writeRecord(.event, self.staged[self.depth][0..self.staged_lens[self.depth]]);
94
+ if (!self.failed) self.event_count += 1;
95
+ }
96
+
97
+ /// True when dispatch just returned to the top level and the frame
98
+ /// index moved — the once-per-published-frame checkpoint gate.
99
+ pub fn wantsCheckpoint(self: *const SessionRecorder, frame_index: u64) bool {
100
+ return self.began and !self.failed and !self.finished and
101
+ self.depth == 0 and frame_index != self.last_checkpoint_frame;
102
+ }
103
+
104
+ pub fn recordCheckpoint(self: *SessionRecorder, frame_index: u64, fingerprint: u64) void {
105
+ if (!self.began or self.failed or self.finished) return;
106
+ self.last_checkpoint_frame = frame_index;
107
+ const payload = journal.encodeCheckpoint(.{
108
+ .event_ordinal = self.event_count,
109
+ .frame_index = frame_index,
110
+ .fingerprint = fingerprint,
111
+ }, &self.small_buffer) catch return self.fail("checkpoint record over budget");
112
+ self.writeRecord(.checkpoint, payload);
113
+ if (!self.failed) self.checkpoint_count += 1;
114
+ }
115
+
116
+ /// Mark the session with a pixel checkpoint (an automation
117
+ /// `screenshot` during recording): replay re-renders the same view
118
+ /// at the same scale through the deterministic reference renderer
119
+ /// and compares hashes.
120
+ pub fn recordScreenshot(self: *SessionRecorder, view_label: []const u8, scale: f32, png_hash: u64, png_len: u64) void {
121
+ if (!self.began or self.failed or self.finished) return;
122
+ const payload = journal.encodeScreenshot(.{
123
+ .event_ordinal = self.event_count,
124
+ .view_label = view_label,
125
+ .scale = scale,
126
+ .png_hash = png_hash,
127
+ .png_len = png_len,
128
+ }, &self.small_buffer) catch return self.fail("screenshot record over budget");
129
+ self.writeRecord(.screenshot, payload);
130
+ if (!self.failed) self.screenshot_count += 1;
131
+ }
132
+
133
+ /// Record one drained effect result (the `Effects.bindJournal`
134
+ /// callback target).
135
+ pub fn recordEffect(self: *SessionRecorder, record: runtime_effects.EffectResultRecord) void {
136
+ if (!self.began or self.failed or self.finished) return;
137
+ const payload = journal.encodeEffect(record, &self.effect_buffer) catch {
138
+ return self.fail("an effect result exceeded max_session_record_bytes");
139
+ };
140
+ self.writeRecord(.effect, payload);
141
+ if (!self.failed) self.effect_count += 1;
142
+ }
143
+
144
+ /// The type-erased binding `Effects.bindJournal` takes.
145
+ pub fn effectJournal(self: *SessionRecorder) runtime_effects.EffectJournal {
146
+ return .{ .context = self, .record_fn = recordEffectErased };
147
+ }
148
+
149
+ fn recordEffectErased(context: *anyopaque, record: runtime_effects.EffectResultRecord) void {
150
+ const self: *SessionRecorder = @ptrCast(@alignCast(context));
151
+ self.recordEffect(record);
152
+ }
153
+
154
+ /// Write the end record, sealing the journal. A failed recording
155
+ /// seals nothing: without the end record, replay refuses the file
156
+ /// as truncated rather than silently replaying a prefix.
157
+ pub fn finish(self: *SessionRecorder) void {
158
+ if (!self.began or self.failed or self.finished) return;
159
+ self.finished = true;
160
+ const payload = journal.encodeEnd(.{
161
+ .event_count = self.event_count,
162
+ .effect_count = self.effect_count,
163
+ .checkpoint_count = self.checkpoint_count,
164
+ .screenshot_count = self.screenshot_count,
165
+ }, &self.small_buffer) catch return self.fail("end record over budget");
166
+ self.writeRecord(.end, payload);
167
+ }
168
+
169
+ fn writeRecord(self: *SessionRecorder, kind: journal.RecordKind, payload: []const u8) void {
170
+ if (self.failed) return;
171
+ if (payload.len > journal.max_session_record_bytes) {
172
+ return self.fail("a record exceeded max_session_record_bytes");
173
+ }
174
+ const total = self.bytes_written + 5 + payload.len;
175
+ if (total > journal.max_session_journal_bytes) {
176
+ return self.fail("the journal exceeded max_session_journal_bytes - recording stopped");
177
+ }
178
+ var record_header: [5]u8 = undefined;
179
+ record_header[0] = @intFromEnum(kind);
180
+ std.mem.writeInt(u32, record_header[1..5], @intCast(payload.len), .little);
181
+ self.write(&record_header);
182
+ self.write(payload);
183
+ if (!self.failed) self.bytes_written = total;
184
+ }
185
+
186
+ fn write(self: *SessionRecorder, bytes: []const u8) void {
187
+ if (self.failed) return;
188
+ self.sink.write_fn(self.sink.context, bytes) catch |err| {
189
+ self.fail(@errorName(err));
190
+ };
191
+ }
192
+
193
+ /// Flip into the failed state, loudly, once. Recording failures
194
+ /// degrade — the app keeps running; only the journal dies.
195
+ fn fail(self: *SessionRecorder, reason: []const u8) void {
196
+ if (self.failed) return;
197
+ self.failed = true;
198
+ // No stderr on freestanding targets (the docs' wasm preview
199
+ // host): analyzing the print would drag `std.Io.Threaded` in.
200
+ if (comptime @import("builtin").os.tag != .freestanding) {
201
+ std.debug.print("session recording failed and stopped: {s} (the partial journal has no end record; replay will refuse it)\n", .{reason});
202
+ }
203
+ }
204
+ };
205
+
206
+ /// A convenience header for the app runner: identity plus the recording
207
+ /// wall-clock stamp.
208
+ pub fn headerNow(platform_name: []const u8, app_name: []const u8, window_width: f32, window_height: f32) Header {
209
+ return .{
210
+ .platform_name = platform_name,
211
+ .app_name = app_name,
212
+ .recorded_at_wall_ms = runtime_clock.nowMs(),
213
+ .window_width = window_width,
214
+ .window_height = window_height,
215
+ };
216
+ }
217
+
218
+ // -------------------------------------------------------------- tests
219
+
220
+ const testing = std.testing;
221
+
222
+ const BufferSink = struct {
223
+ buffer: [1 << 16]u8 = undefined,
224
+ len: usize = 0,
225
+ fail_after: ?usize = null,
226
+
227
+ fn sink(self: *BufferSink) RecorderSink {
228
+ return .{ .context = self, .write_fn = write };
229
+ }
230
+
231
+ fn write(context: *anyopaque, chunk: []const u8) anyerror!void {
232
+ const self: *BufferSink = @ptrCast(@alignCast(context));
233
+ if (self.fail_after) |limit| {
234
+ if (self.len + chunk.len > limit) return error.NoSpaceLeft;
235
+ }
236
+ @memcpy(self.buffer[self.len .. self.len + chunk.len], chunk);
237
+ self.len += chunk.len;
238
+ }
239
+
240
+ fn bytes(self: *const BufferSink) []const u8 {
241
+ return self.buffer[0..self.len];
242
+ }
243
+ };
244
+
245
+ test "recorder orders effect results before their consuming event" {
246
+ var buffer_sink = BufferSink{};
247
+ const recorder = try testing.allocator.create(SessionRecorder);
248
+ defer testing.allocator.destroy(recorder);
249
+ recorder.* = SessionRecorder.init(buffer_sink.sink());
250
+
251
+ recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
252
+ recorder.stageEvent(.app_start);
253
+ recorder.commitEvent();
254
+ recorder.stageEvent(.wake);
255
+ // Drained during the wake dispatch:
256
+ recorder.recordEffect(.{ .kind = .line, .key = 1, .payload = "hello" });
257
+ recorder.commitEvent();
258
+ recorder.recordCheckpoint(1, 0xabc);
259
+ recorder.finish();
260
+ try testing.expect(!recorder.failed);
261
+
262
+ var reader = try journal.Reader.init(buffer_sink.bytes());
263
+ _ = (try reader.next()).?; // header
264
+ try testing.expect((try reader.next()).?.event == .app_start);
265
+ const effect = (try reader.next()).?;
266
+ try testing.expectEqualStrings("hello", effect.effect.payload);
267
+ const event = (try reader.next()).?;
268
+ try testing.expect(event.event == .wake);
269
+ const checkpoint = (try reader.next()).?;
270
+ try testing.expectEqual(@as(u64, 0xabc), checkpoint.checkpoint.fingerprint);
271
+ try testing.expectEqual(@as(u64, 2), checkpoint.checkpoint.event_ordinal);
272
+ const end = (try reader.next()).?;
273
+ try testing.expectEqual(@as(u64, 2), end.end.event_count);
274
+ try testing.expectEqual(@as(u64, 1), end.end.effect_count);
275
+ }
276
+
277
+ test "recorder commits nested events innermost-first" {
278
+ var buffer_sink = BufferSink{};
279
+ const recorder = try testing.allocator.create(SessionRecorder);
280
+ defer testing.allocator.destroy(recorder);
281
+ recorder.* = SessionRecorder.init(buffer_sink.sink());
282
+ recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
283
+ recorder.stageEvent(.frame_requested);
284
+ recorder.stageEvent(.{ .menu_command = .{ .name = "app.about", .window_id = 1 } });
285
+ recorder.commitEvent();
286
+ recorder.commitEvent();
287
+ recorder.finish();
288
+
289
+ var reader = try journal.Reader.init(buffer_sink.bytes());
290
+ _ = (try reader.next()).?;
291
+ const inner = (try reader.next()).?;
292
+ try testing.expectEqualStrings("app.about", inner.event.menu_command.name);
293
+ const outer = (try reader.next()).?;
294
+ try testing.expect(outer.event == .frame_requested);
295
+ }
296
+
297
+ test "recorder fails loudly once and seals nothing after a sink error" {
298
+ var buffer_sink = BufferSink{ .fail_after = 32 };
299
+ const recorder = try testing.allocator.create(SessionRecorder);
300
+ defer testing.allocator.destroy(recorder);
301
+ recorder.* = SessionRecorder.init(buffer_sink.sink());
302
+ recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
303
+ var index: usize = 0;
304
+ while (index < 8) : (index += 1) {
305
+ recorder.stageEvent(.frame_requested);
306
+ recorder.commitEvent();
307
+ }
308
+ try testing.expect(recorder.failed);
309
+ recorder.finish();
310
+ // Whatever landed before the failure has no end record: replay
311
+ // refuses the file as truncated.
312
+ if (journal.Reader.init(buffer_sink.bytes())) |reader_value| {
313
+ var reader = reader_value;
314
+ const failed = while (true) {
315
+ const record = reader.next() catch break true;
316
+ if (record == null) break false;
317
+ };
318
+ try testing.expect(failed);
319
+ } else |_| {}
320
+ }
321
+
322
+ test "checkpoint gate fires once per frame index" {
323
+ var buffer_sink = BufferSink{};
324
+ const recorder = try testing.allocator.create(SessionRecorder);
325
+ defer testing.allocator.destroy(recorder);
326
+ recorder.* = SessionRecorder.init(buffer_sink.sink());
327
+ recorder.begin(.{ .platform_name = "test", .app_name = "demo" });
328
+ try testing.expect(recorder.wantsCheckpoint(1));
329
+ recorder.recordCheckpoint(1, 5);
330
+ try testing.expect(!recorder.wantsCheckpoint(1));
331
+ try testing.expect(recorder.wantsCheckpoint(2));
332
+ }
@@ -0,0 +1,274 @@
1
+ //! Session replay: drive a recorded journal back through the dispatch
2
+ //! choke point, deterministically, and verify equivalence.
3
+ //!
4
+ //! The journal is the world: the app's effects channel is armed into
5
+ //! replay mode FIRST (fake executor — `fx.spawn`/`fx.fetch`/file/
6
+ //! clipboard requests park in their slots; no process, network, file, or
7
+ //! pasteboard is ever touched), then records replay in file order —
8
+ //! effect results feed the parked requests, events dispatch through
9
+ //! `Runtime.dispatchPlatformEvent` exactly as the platform once did, and
10
+ //! checkpoints compare the live state fingerprint (and screenshot pixel
11
+ //! hashes) against what the recording saw.
12
+ //!
13
+ //! Replay hosts on the null platform: window creates, presents, and
14
+ //! timers are inert there, and every input that matters arrives from the
15
+ //! journal (timer fires and effect wakes are platform events, so they
16
+ //! ride the event stream like everything else).
17
+ //!
18
+ //! THE INIT CONTRACT (see session_journal.zig): replay re-runs the app's
19
+ //! own model init and `init_fx` rather than restoring a serialized
20
+ //! model, so both must be deterministic. A violation shows up here as
21
+ //! the first mismatching checkpoint.
22
+ //!
23
+ //! Divergence is loud and specific: a fed effect result whose key has no
24
+ //! parked request (`ReplayEffectDivergence`) means update spawned
25
+ //! different effects than the recording — usually nondeterminism outside
26
+ //! the effect boundary; a fingerprint mismatch names the event ordinal
27
+ //! and frame where state first differed.
28
+
29
+ const std = @import("std");
30
+ const canvas = @import("canvas");
31
+ const automation_protocol = @import("../automation/protocol.zig");
32
+ const core = @import("core.zig");
33
+ const journal = @import("session_journal.zig");
34
+
35
+ pub const ReplayError = error{
36
+ /// The journal was recorded on a different platform; v1 replay is
37
+ /// same-platform only (font metrics and scale behavior differ).
38
+ ReplayPlatformMismatch,
39
+ /// The journal's automation protocol version differs from this
40
+ /// build's — the recording binary and this one are skewed.
41
+ ReplayProtocolMismatch,
42
+ /// A journaled effect result found no parked request with its key:
43
+ /// the replayed updates issued different effects than the recorded
44
+ /// ones did.
45
+ ReplayEffectDivergence,
46
+ /// The app registered no replay hook (`App.replay_fn`), but the
47
+ /// journal carries effect results that need one.
48
+ ReplayUnsupportedApp,
49
+ };
50
+
51
+ /// Bounded mismatch detail (first N are kept; the count keeps counting).
52
+ pub const max_replay_mismatches: usize = 16;
53
+
54
+ pub const ReplayMismatchKind = enum { fingerprint, screenshot };
55
+
56
+ pub const ReplayMismatch = struct {
57
+ kind: ReplayMismatchKind,
58
+ event_ordinal: u64,
59
+ frame_index: u64 = 0,
60
+ expected: u64,
61
+ actual: u64,
62
+ };
63
+
64
+ pub const ReplayOptions = struct {
65
+ /// Compare fingerprint checkpoints and screenshot marks. Off, replay
66
+ /// only proves the journal drives cleanly end to end.
67
+ verify: bool = true,
68
+ /// Refuse a journal recorded on another platform (the v1 bar).
69
+ /// Tests recording under the null platform disable this.
70
+ require_same_platform: bool = true,
71
+ };
72
+
73
+ pub const ReplayReport = struct {
74
+ protocol_version: u32 = 0,
75
+ events_replayed: u64 = 0,
76
+ effects_fed: u64 = 0,
77
+ effects_skipped: u64 = 0,
78
+ checkpoints_verified: u64 = 0,
79
+ screenshots_verified: u64 = 0,
80
+ mismatch_count: u64 = 0,
81
+ mismatches: [max_replay_mismatches]ReplayMismatch = undefined,
82
+
83
+ pub fn ok(self: *const ReplayReport) bool {
84
+ return self.mismatch_count == 0;
85
+ }
86
+
87
+ fn recordMismatch(self: *ReplayReport, mismatch: ReplayMismatch) void {
88
+ if (self.mismatch_count < max_replay_mismatches) {
89
+ self.mismatches[self.mismatch_count] = mismatch;
90
+ }
91
+ self.mismatch_count += 1;
92
+ }
93
+ };
94
+
95
+ /// The platform name this build records into headers and replay
96
+ /// compares against — the OS, not the hosting platform value (replay
97
+ /// hosts on the null platform on purpose).
98
+ pub fn currentPlatformName() []const u8 {
99
+ const builtin = @import("builtin");
100
+ return switch (builtin.os.tag) {
101
+ .macos => "macos",
102
+ .linux => "linux",
103
+ .windows => "windows",
104
+ .ios => "ios",
105
+ else => "other",
106
+ };
107
+ }
108
+
109
+ /// Replay `journal_bytes` into `runtime`/`app`. The runtime must be
110
+ /// freshly initialized (no events dispatched yet) over the null
111
+ /// platform, with no automation server (live automation commands would
112
+ /// interleave with the journal). The journal bytes must outlive the
113
+ /// call — decoded event payloads reference them.
114
+ pub fn replaySession(
115
+ runtime: *core.Runtime,
116
+ app: core.App,
117
+ journal_bytes: []const u8,
118
+ options: ReplayOptions,
119
+ ) anyerror!ReplayReport {
120
+ var reader = try journal.Reader.init(journal_bytes);
121
+ var report: ReplayReport = .{};
122
+ var armed = false;
123
+
124
+ while (try reader.next()) |record| {
125
+ switch (record) {
126
+ .header => |header| {
127
+ report.protocol_version = header.protocol_version;
128
+ if (header.protocol_version != automation_protocol.version) {
129
+ std.debug.print(
130
+ "replay refused: the journal was recorded at automation protocol v{d} but this build speaks v{d} - re-record with this build\n",
131
+ .{ header.protocol_version, automation_protocol.version },
132
+ );
133
+ return error.ReplayProtocolMismatch;
134
+ }
135
+ if (options.require_same_platform and !std.mem.eql(u8, header.platform_name, currentPlatformName())) {
136
+ std.debug.print(
137
+ "replay refused: the journal was recorded on \"{s}\" but this host is \"{s}\" - v1 replay is same-platform only (font metrics and scale behavior differ across platforms)\n",
138
+ .{ header.platform_name, currentPlatformName() },
139
+ );
140
+ return error.ReplayPlatformMismatch;
141
+ }
142
+ },
143
+ .event => |event| {
144
+ if (!armed) {
145
+ armed = true;
146
+ app.replayControl(.arm) catch {
147
+ // Apps without the hook still replay when the
148
+ // journal carries no effect results; a feed
149
+ // below fails loudly instead.
150
+ };
151
+ }
152
+ try runtime.dispatchPlatformEvent(app, event);
153
+ report.events_replayed += 1;
154
+ },
155
+ .effect => |effect| {
156
+ if (effectRegeneratesUnderReplay(effect)) {
157
+ report.effects_skipped += 1;
158
+ continue;
159
+ }
160
+ app.replayControl(.{ .feed = effect }) catch |err| switch (err) {
161
+ error.EffectNotFound => {
162
+ std.debug.print(
163
+ "replay diverged after event {d}: journaled {s} result for effect key {d} has no matching pending request - the replayed updates issued different effects than the recording (nondeterminism outside the effect boundary?)\n",
164
+ .{ report.events_replayed, @tagName(effect.kind), effect.key },
165
+ );
166
+ return error.ReplayEffectDivergence;
167
+ },
168
+ error.ReplayUnsupported => {
169
+ std.debug.print(
170
+ "replay refused: the journal carries effect results but this app registered no replay hook (App.replay_fn - UiApp wires it automatically)\n",
171
+ .{},
172
+ );
173
+ return error.ReplayUnsupportedApp;
174
+ },
175
+ else => return err,
176
+ };
177
+ report.effects_fed += 1;
178
+ },
179
+ .checkpoint => |checkpoint| {
180
+ if (!options.verify) continue;
181
+ const actual = runtime.sessionStateFingerprint();
182
+ report.checkpoints_verified += 1;
183
+ if (actual != checkpoint.fingerprint) {
184
+ report.recordMismatch(.{
185
+ .kind = .fingerprint,
186
+ .event_ordinal = checkpoint.event_ordinal,
187
+ .frame_index = checkpoint.frame_index,
188
+ .expected = checkpoint.fingerprint,
189
+ .actual = actual,
190
+ });
191
+ }
192
+ },
193
+ .screenshot => |mark| {
194
+ if (!options.verify) continue;
195
+ report.screenshots_verified += 1;
196
+ const actual = renderScreenshotHash(runtime, mark.view_label, mark.scale) catch 0;
197
+ if (actual != mark.png_hash) {
198
+ report.recordMismatch(.{
199
+ .kind = .screenshot,
200
+ .event_ordinal = mark.event_ordinal,
201
+ .expected = mark.png_hash,
202
+ .actual = actual,
203
+ });
204
+ }
205
+ },
206
+ .end => {},
207
+ }
208
+ }
209
+ return report;
210
+ }
211
+
212
+ /// Journaled results that regenerate deterministically from the
213
+ /// replayed updates themselves — feeding them would double-deliver:
214
+ /// rejections (the same over-capacity/duplicate-key validation refuses
215
+ /// again, loop-side) and fx-timer Msgs (real fires replay through the
216
+ /// journaled platform `.timer` events; rejections regenerate).
217
+ fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
218
+ return switch (record.kind) {
219
+ .timer => true,
220
+ .exit => record.exit_reason == .rejected,
221
+ .response => record.fetch_outcome == .rejected,
222
+ .file => record.file_outcome == .rejected,
223
+ .clipboard => record.clipboard_outcome == .rejected,
224
+ // Audio rejections are loop-side validation (path bounds) that
225
+ // refuses again; everything else — loaded acknowledgments,
226
+ // position ticks, completions, platform failures — is an
227
+ // external input and must be fed.
228
+ .audio => record.audio_kind == .rejected,
229
+ .line, .clock => false,
230
+ };
231
+ }
232
+
233
+ /// Re-render a journaled screenshot mark through the same deterministic
234
+ /// reference renderer the automation `screenshot` verb used at record
235
+ /// time, and hash the PNG.
236
+ fn renderScreenshotHash(runtime: *core.Runtime, view_label: []const u8, scale: f32) anyerror!u64 {
237
+ const window_id = blk: {
238
+ for (runtime.views[0..runtime.view_count]) |*view| {
239
+ if (view.open and view.kind == .gpu_surface and std.mem.eql(u8, view.label, view_label)) {
240
+ break :blk view.window_id;
241
+ }
242
+ }
243
+ return error.ViewNotFound;
244
+ };
245
+ const allocator = std.heap.page_allocator;
246
+ const pixel_size = try runtime.canvasScreenshotPixelSize(window_id, view_label, scale);
247
+ const pixels = try allocator.alloc(u8, pixel_size.byte_len);
248
+ defer allocator.free(pixels);
249
+ const scratch = try allocator.alloc(u8, pixel_size.byte_len);
250
+ defer allocator.free(scratch);
251
+ const screenshot = try runtime.renderCanvasScreenshot(window_id, view_label, scale, pixels, scratch);
252
+ var writer = try std.Io.Writer.Allocating.initCapacity(
253
+ allocator,
254
+ try canvas.png.encodedRgba8ByteLen(screenshot.width, screenshot.height),
255
+ );
256
+ defer writer.deinit();
257
+ try canvas.png.writeRgba8(&writer.writer, screenshot.width, screenshot.height, screenshot.rgba8);
258
+ dumpReplayScreenshot(view_label, writer.written());
259
+ return std.hash.Wyhash.hash(0, writer.written());
260
+ }
261
+
262
+ /// Debug aid: `NATIVE_SDK_SESSION_REPLAY_DUMP=<dir>` writes each
263
+ /// replay-rendered screenshot PNG so a mismatching pixel mark can be
264
+ /// diffed against the recording's artifact.
265
+ fn dumpReplayScreenshot(view_label: []const u8, png_bytes: []const u8) void {
266
+ const builtin = @import("builtin");
267
+ if (!builtin.link_libc) return;
268
+ const dir = std.c.getenv("NATIVE_SDK_SESSION_REPLAY_DUMP") orelse return;
269
+ var path_buffer: [1024]u8 = undefined;
270
+ const path = std.fmt.bufPrintSentinel(&path_buffer, "{s}/replay-screenshot-{s}.png", .{ std.mem.span(dir), view_label }, 0) catch return;
271
+ const file = std.c.fopen(path, "wb") orelse return;
272
+ defer _ = std.c.fclose(file);
273
+ _ = std.c.fwrite(png_bytes.ptr, 1, png_bytes.len, file);
274
+ }
@@ -0,0 +1,30 @@
1
+ //! Session state fingerprinting: the record/replay verification hash.
2
+ //!
3
+ //! The fingerprint is the Wyhash of the runtime's ACCESSIBILITY snapshot
4
+ //! text — every window, view, and widget's semantic state (roles, names,
5
+ //! text values, control values, scroll offsets, bounds, focus/hover/
6
+ //! pressed flags) — deliberately NOT the full automation snapshot, whose
7
+ //! header carries wall-clock uptime, pids, and per-present GPU telemetry
8
+ //! that legitimately differ between a live run and its replay. Anything
9
+ //! that changes what the a11y tree says the app IS changes the hash;
10
+ //! anything that only says how fast the host drew does not.
11
+
12
+ const std = @import("std");
13
+ const automation = @import("../automation/root.zig");
14
+
15
+ pub fn RuntimeSessionState(comptime Runtime: type) type {
16
+ return struct {
17
+ /// Hash of the current semantic state. A formatting failure
18
+ /// cannot happen with a draining hash writer, but the seam stays
19
+ /// honest: 0 means "no fingerprint", and replay treats a 0-0
20
+ /// comparison as a match of unknowns, never silently as proof.
21
+ pub fn sessionStateFingerprint(self: *Runtime) u64 {
22
+ const input = self.automationSnapshot("session");
23
+ var buffer: [512]u8 = undefined;
24
+ var hashing = std.Io.Writer.Hashing(std.hash.Wyhash).initHasher(std.hash.Wyhash.init(0), &buffer);
25
+ automation.snapshot.writeA11yText(input, &hashing.writer) catch return 0;
26
+ hashing.writer.flush() catch return 0;
27
+ return hashing.hasher.final();
28
+ }
29
+ };
30
+ }