@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
@@ -0,0 +1,206 @@
1
+ //! Copied render-animation lifecycle decisions. Native owns retained records,
2
+ //! command-bound providers, storage writes, and invalidation execution.
3
+ const std = @import("std");
4
+ const canvas = @import("canvas");
5
+ const geometry = @import("geometry");
6
+ pub const Policy = *const fn ([]const u8, []u8) usize;
7
+ const allocator = std.heap.page_allocator;
8
+ const word = readWord;
9
+
10
+ fn readWord(bytes: []const u8, at: usize) u32 {
11
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
12
+ }
13
+ fn put(bytes: []u8, at: usize, value: usize) void {
14
+ std.mem.writeInt(u32, bytes[at..][0..4], std.math.cast(u32, value) orelse @panic("animation fact exceeds wire range"), .little);
15
+ }
16
+ fn wide(bytes: []u8, at: usize, value: u64) void {
17
+ std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
18
+ }
19
+ fn float(bytes: []u8, at: usize, value: f32) void {
20
+ std.mem.writeInt(u32, bytes[at..][0..4], @bitCast(value), .little);
21
+ }
22
+ fn readFloat(bytes: []const u8, at: usize) f32 {
23
+ return @bitCast(word(bytes, at));
24
+ }
25
+ fn affine(bytes: []u8, at: usize, value: canvas.Affine) void {
26
+ inline for (.{ "a", "b", "c", "d", "tx", "ty" }, 0..) |field, i| float(bytes, at + i * 4, @field(value, field));
27
+ }
28
+ fn rect(bytes: []u8, at: usize, value: geometry.RectF) void {
29
+ inline for (.{ "x", "y", "width", "height" }, 0..) |field, i| float(bytes, at + i * 4, @field(value, field));
30
+ }
31
+ fn optionalRect(bytes: []const u8, at: usize) ?geometry.RectF {
32
+ if (word(bytes, at) == 0) return null;
33
+ return .{ .x = readFloat(bytes, at + 4), .y = readFloat(bytes, at + 8), .width = readFloat(bytes, at + 12), .height = readFloat(bytes, at + 16) };
34
+ }
35
+ fn add(a: usize, b: usize) usize {
36
+ return std.math.add(usize, a, b) catch @panic("animation transport size overflow");
37
+ }
38
+ fn mul(a: usize, b: usize) usize {
39
+ return std.math.mul(usize, a, b) catch @panic("animation transport size overflow");
40
+ }
41
+ fn alloc(len: usize) []u8 {
42
+ const result = allocator.alloc(u8, len) catch @panic("animation transport allocation failed");
43
+ @memset(result, 0);
44
+ return result;
45
+ }
46
+ fn header(bytes: []u8, mode: u8, animations: usize, overrides: usize, commands: usize) void {
47
+ bytes[0..4].* = .{ 72, 1, mode, 0 };
48
+ put(bytes, 4, animations);
49
+ put(bytes, 8, overrides);
50
+ put(bytes, 12, commands);
51
+ }
52
+ fn animation(bytes: []u8, at: usize, value: canvas.CanvasRenderAnimation) void {
53
+ wide(bytes, at, value.id);
54
+ wide(bytes, at + 8, value.start_ns);
55
+ put(bytes, at + 16, value.duration_ms);
56
+ put(bytes, at + 20, @intFromEnum(value.loop));
57
+ put(bytes, at + 24, @as(u32, @intFromBool(value.to_opacity != null)) |
58
+ (@as(u32, @intFromBool(value.from_transform != null)) << 1) |
59
+ (@as(u32, @intFromBool(value.to_transform != null)) << 2) |
60
+ (@as(u32, @intFromBool(value.from_rotation != null or value.to_rotation != null)) << 3));
61
+ float(bytes, at + 28, value.to_opacity orelse 0);
62
+ affine(bytes, at + 32, value.from_transform orelse .{});
63
+ affine(bytes, at + 56, value.to_transform orelse .{});
64
+ float(bytes, at + 80, value.rotation_center.x);
65
+ float(bytes, at + 84, value.rotation_center.y);
66
+ }
67
+ fn override(bytes: []u8, at: usize, value: canvas.CanvasRenderOverride) void {
68
+ wide(bytes, at, value.id);
69
+ put(bytes, at + 8, @as(u32, @intFromBool(value.opacity != null)) | (@as(u32, @intFromBool(value.transform != null)) << 1));
70
+ float(bytes, at + 12, value.opacity orelse 0);
71
+ affine(bytes, at + 16, value.transform orelse .{});
72
+ }
73
+ fn invoke(policy: Policy, request: []const u8, output: []u8) []const u8 {
74
+ @memset(output, 0xa5);
75
+ const len = policy(request, output);
76
+ if (len > output.len or !resultValid(request, output[0..len])) @panic("invalid render animation decision");
77
+ return output[0..len];
78
+ }
79
+
80
+ /// Validate copied selectors and write extents, without rerunning admission,
81
+ /// activity, retirement, target selection, or geometry policy natively.
82
+ pub fn resultValid(request: []const u8, result: []const u8) bool {
83
+ if (request.len < 80 or request[0] != 72 or request[1] != 1 or request[2] > 3 or result.len < 32 or word(result, 0) != 1) return false;
84
+ const mode = request[2];
85
+ if (mode == 3) return result.len == 32 and word(result, 4) <= 2 and word(result, 8) <= 1 and
86
+ (word(result, 4) == 0 or word(result, 8) == 0) and std.mem.allEqual(u8, result[12..], 0);
87
+ if (mode == 2) {
88
+ const count = @as(u64, word(request, 4)) + word(request, 8);
89
+ const cursor = word(result, 8);
90
+ const answer = word(request, 56) != 0xffffffff;
91
+ if (result.len != 64 or word(result, 4) > 1 or cursor > count or cursor < word(request, 32) or
92
+ word(result, 16) > 1 or !std.mem.allEqual(u8, result[36..], 0)) return false;
93
+ if (word(result, 4) == 0) return cursor == count and word(result, 12) == 0xffffffff;
94
+ return cursor < count and word(result, 12) < word(request, 12) and (!answer or cursor > word(request, 32));
95
+ }
96
+ const count = word(request, if (mode == 0) 4 else 8);
97
+ if (word(result, 4) != count or word(result, 8) > 1 or word(result, 12) > 1 or
98
+ !std.mem.allEqual(u8, result[16..32], 0) or result.len != 32 + @as(usize, count)) return false;
99
+ var active = false;
100
+ var pruned = false;
101
+ for (result[32..]) |flags| {
102
+ if (flags > 3 or flags == 2 or (mode == 1 and flags > 1)) return false;
103
+ active = active or flags & 2 != 0;
104
+ pruned = pruned or flags & 1 == 0;
105
+ }
106
+ return (word(result, 8) != 0) == active and (word(result, 12) != 0) == pruned;
107
+ }
108
+
109
+ /// Returns true only when replacing an entirely empty, unapplied set is inert.
110
+ /// The capacity verdict precedes invalid identities, matching the reference.
111
+ pub fn admit(animations: []const canvas.CanvasRenderAnimation, old_count: usize, old_overrides: usize, capacity: usize, policy: Policy) !bool {
112
+ const request = alloc(add(80, if (animations.len > capacity) 0 else mul(animations.len, 8)));
113
+ defer allocator.free(request);
114
+ header(request, 3, animations.len, old_overrides, old_count);
115
+ put(request, 16, capacity);
116
+ if (animations.len <= capacity) for (animations, 0..) |value, i| wide(request, 80 + i * 8, value.id);
117
+ var output: [32]u8 = undefined;
118
+ const result = invoke(policy, request, &output);
119
+ switch (word(result, 4)) {
120
+ 1 => return error.RenderAnimationListFull,
121
+ 2 => return error.InvalidViewOptions,
122
+ else => return word(result, 8) != 0,
123
+ }
124
+ }
125
+
126
+ /// In-place storage mutation follows the copied per-slot decisions. Duplicate
127
+ /// identities and untouched tail slots behave exactly like the reference.
128
+ pub fn finishFrame(view: anytype, timestamp_ns: u64, policy: Policy) bool {
129
+ const count = view.canvas_render_animation_count;
130
+ const request = alloc(add(80, mul(count, 112)));
131
+ defer allocator.free(request);
132
+ header(request, 0, count, 0, 0);
133
+ wide(request, 20, timestamp_ns);
134
+ for (view.canvasRenderAnimations(), 0..) |value, i| animation(request, 80 + i * 112, value);
135
+ const output = alloc(add(32, count));
136
+ defer allocator.free(output);
137
+ const result = invoke(policy, request, output);
138
+ var retained: usize = 0;
139
+ for (0..count) |i| {
140
+ const value = view.canvas_render_animations[i];
141
+ if (result[32 + i] & 1 == 0) {
142
+ view.removeCanvasRenderAnimationDirtyBounds(value.id);
143
+ } else {
144
+ view.canvas_render_animations[retained] = value;
145
+ retained += 1;
146
+ }
147
+ }
148
+ view.canvas_render_animation_count = retained;
149
+ if (word(result, 12) != 0) compactOverrides(view, policy);
150
+ return word(result, 8) != 0;
151
+ }
152
+ fn compactOverrides(view: anytype, policy: Policy) void {
153
+ const count = view.canvas_frame_render_override_count;
154
+ const request = alloc(add(80, mul(count, 40)));
155
+ defer allocator.free(request);
156
+ header(request, 1, 0, count, 0);
157
+ for (view.canvasFrameRenderOverrides(), 0..) |value, i| override(request, 80 + i * 40, value);
158
+ const output = alloc(add(32, count));
159
+ defer allocator.free(output);
160
+ const result = invoke(policy, request, output);
161
+ var retained: usize = 0;
162
+ for (0..count) |i| if (result[32 + i] & 1 != 0) {
163
+ view.canvas_frame_render_overrides[retained] = view.canvas_frame_render_overrides[i];
164
+ retained += 1;
165
+ };
166
+ view.canvas_frame_render_override_count = retained;
167
+ }
168
+
169
+ /// Request each selected native bounds provider in reference order, including
170
+ /// duplicate identities. No eager measurements or memoized callback results.
171
+ pub fn schedule(view: anytype, animations: []const canvas.CanvasRenderAnimation, policy: Policy) ?geometry.RectF {
172
+ const list = view.canvasDisplayList();
173
+ const overrides = view.canvasFrameRenderOverrides();
174
+ const override_at = add(80, mul(animations.len, 112));
175
+ const command_at = add(override_at, mul(overrides.len, 40));
176
+ const request = alloc(add(command_at, mul(list.commands.len, 16)));
177
+ defer allocator.free(request);
178
+ header(request, 2, animations.len, overrides.len, list.commands.len);
179
+ request[3] = canvas.renderNumericFlags();
180
+ put(request, 56, 0xffffffff);
181
+ for (animations, 0..) |value, i| animation(request, 80 + i * 112, value);
182
+ for (overrides, 0..) |value, i| override(request, override_at + i * 40, value);
183
+ for (list.commands, 0..) |command, i| {
184
+ const at = command_at + i * 16;
185
+ wide(request, at, command.objectId() orelse 0);
186
+ put(request, at + 8, @intFromBool(command.objectId() != null));
187
+ }
188
+ var output: [64]u8 = undefined;
189
+ while (true) {
190
+ const result = invoke(policy, request, &output);
191
+ if (word(result, 4) == 0) return optionalRect(result, 16);
192
+ const source = word(result, 12);
193
+ const cursor = word(result, 8);
194
+ const target_at = if (cursor < overrides.len) override_at + @as(usize, cursor) * 40 else 80 + (@as(usize, cursor) - overrides.len) * 112;
195
+ if (!std.mem.eql(u8, request[target_at..][0..8], request[command_at + @as(usize, source) * 16 ..][0..8]) or
196
+ word(request, command_at + @as(usize, source) * 16 + 8) == 0) @panic("invalid animation bounds selector");
197
+ // Publish the accepted continuation before invoking an observable
198
+ // provider; it is never called for an unselected command.
199
+ put(request, 32, cursor);
200
+ @memcpy(request[36..56], result[16..36]);
201
+ put(request, 56, source);
202
+ const bounds = list.commands[source].bounds();
203
+ put(request, 60, @intFromBool(bounds != null));
204
+ rect(request, 64, bounds orelse .{});
205
+ }
206
+ }
@@ -0,0 +1,66 @@
1
+ //! Copied replay admission plans. Native retains exact record storage and blobs.
2
+ const std = @import("std");
3
+ const effects = @import("effects.zig");
4
+ const platform = @import("../platform/root.zig");
5
+ const limits = @import("canvas_limits.zig");
6
+ const reference = @import("replay_policy_reference.zig");
7
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
8
+ pub const Blob = enum(u8) { none, pty, file, image, persist, db };
9
+ pub const Plan = struct {
10
+ damage: u16,
11
+ regenerates: bool,
12
+ blob: Blob,
13
+ pub fn damaged(self: Plan, bit: u4) bool {
14
+ return self.damage & (@as(u16, 1) << bit) != 0;
15
+ }
16
+ };
17
+ pub fn request(record: effects.EffectResultRecord) [256]u8 {
18
+ var bytes: [256]u8 = @splat(0);
19
+ bytes[0..16].* = .{ 20, @intFromEnum(record.kind), @intFromEnum(record.exit_reason), @intFromEnum(record.file_op), @intFromEnum(record.file_event), @intFromEnum(record.file_outcome), @intFromEnum(record.image_outcome), @intFromEnum(record.channel_kind), @intFromEnum(record.video_kind), @intFromEnum(record.audio_kind), @intFromEnum(record.pty_kind), @intFromEnum(record.persist_outcome), @intFromEnum(record.credentials_operation), @intFromEnum(record.credentials_outcome), @intFromEnum(record.fetch_outcome), @intFromEnum(record.clipboard_outcome) };
20
+ std.mem.writeInt(i32, bytes[16..20], record.code, .little);
21
+ std.mem.writeInt(i32, bytes[20..24], record.pty_signal, .little);
22
+ const words = [_]u64{ record.payload.len, record.file_blob_len, record.file_total, @as(u64, @bitCast(record.file_mtime_ms)), record.image_blob_len, record.image_width, record.image_height, record.video_position_ms, record.video_duration_ms, record.video_width, record.video_height, record.video_token, record.audio_position_ms, record.audio_duration_ms, record.pty_blob_len, record.pty_dropped_writes, record.persist_blob_len, record.db_blob_len, record.credentials_secret_len, effects.effect_file_stream_chunk_bytes, effects.max_effect_channel_bytes, platform.max_decoded_image_dimension, limits.max_registered_canvas_image_pixel_bytes_ceiling, effects.max_effect_pty_chunk_bytes, effects.max_effect_persist_snapshot_bytes, effects.max_effect_db_page_bytes, effects.max_effect_credentials_secret_bytes };
23
+ for (words, 0..) |word, i| std.mem.writeInt(u64, bytes[24 + i * 8 ..][0..8], word, .little);
24
+ bytes[240..248].* = .{ @intFromBool(record.file_rejected_admission), @intFromBool(record.file_exists), @intFromBool(record.video_playing), @intFromBool(record.video_buffering), @intFromBool(record.truncated), @intFromBool(std.mem.allEqual(u8, &record.credentials_salt, 0)), @intFromBool(std.mem.allEqual(u8, &record.credentials_digest, 0)), 0 };
25
+ // Closed relational outcome count is a schema fact, not an admission verdict.
26
+ bytes[248] = @intCast(@typeInfo(effects.EffectDbOutcome).@"enum".fields.len);
27
+ return bytes;
28
+ }
29
+ // The native branch is retained for explicit Zig-core applications.
30
+ pub fn plan(policy: Policy, record: effects.EffectResultRecord) Plan {
31
+ if (policy) |callback| {
32
+ const input = request(record);
33
+ var output: [8]u8 = undefined;
34
+ if (callback(&input, &output) != output.len) @panic("invalid compiled replay plan size");
35
+ if (output[2] > 1 or output[3] > 5 or !std.mem.allEqual(u8, output[4..], 0) or output[1] & 128 != 0) @panic("invalid compiled replay plan");
36
+ return .{ .damage = std.mem.readInt(u16, output[0..2], .little), .regenerates = output[2] != 0, .blob = @enumFromInt(output[3]) };
37
+ }
38
+ return .{ .damage = reference.damage(record), .regenerates = reference.effectRegeneratesUnderReplay(record), .blob = switch (record.kind) {
39
+ .pty => if (record.pty_blob_len > 0) .pty else .none,
40
+ .file => if (record.file_blob_len > 0) .file else .none,
41
+ .image => if (record.image_blob_len > 0) .image else .none,
42
+ .persist => if (record.persist_blob_len > 0) .persist else .none,
43
+ .db => if (record.db_blob_len > 0) .db else .none,
44
+ else => .none,
45
+ } };
46
+ }
47
+
48
+ pub const Stage = enum(u8) { header, chrome_admission, arm, chrome_consumed, feed_error, verify, end };
49
+ pub const Action = enum(u8) { proceed, protocol_refusal, platform_refusal, damage, arm, chrome_divergence, propagate, drain, effect_divergence, unsupported, verify };
50
+ pub fn coordinate(policy: Policy, stage: Stage, a: u8, b: bool, c: bool) Action {
51
+ const bytes = [_]u8{ 21, @intFromEnum(stage), a, @intFromBool(b), @intFromBool(c), 0, 0, 0 };
52
+ if (policy) |callback| {
53
+ var output: [4]u8 = undefined;
54
+ if (callback(&bytes, &output) != output.len or output[0] > 10 or !std.mem.allEqual(u8, output[1..], 0)) @panic("invalid compiled replay coordination plan");
55
+ return @enumFromInt(output[0]);
56
+ }
57
+ return switch (stage) {
58
+ .header => if (a == 0) .protocol_refusal else if (b and !c) .platform_refusal else .proceed,
59
+ .chrome_admission => if (a != 0 or b) .damage else .proceed,
60
+ .arm => if (a == 0) .arm else .proceed,
61
+ .chrome_consumed => if (a != 0 or b) .chrome_divergence else .proceed,
62
+ .feed_error => if (a == 0) (if (b) .propagate else .drain) else if (a == 1) .effect_divergence else .unsupported,
63
+ .verify => if (a != 0) .verify else .proceed,
64
+ .end => if (a != 0) .chrome_divergence else .proceed,
65
+ };
66
+ }
@@ -0,0 +1,326 @@
1
+ //! Native replay oracle retained for legacy Zig apps and parity tests.
2
+ const std = @import("std");
3
+ const runtime_effects = @import("effects.zig");
4
+ const journal = @import("session_journal.zig");
5
+ const platform = @import("../platform/root.zig");
6
+ const canvas_limits = @import("canvas_limits.zig");
7
+
8
+ pub fn ptyRecordDamaged(record: journal.EffectResultRecord) bool {
9
+ if (record.payload.len > 0) return true;
10
+ if (record.pty_blob_len > runtime_effects.max_effect_pty_chunk_bytes) return true;
11
+ switch (record.pty_kind) {
12
+ // The recorder journals output ONLY for a non-empty batch, so
13
+ // its blob is always non-empty — a zero-length output blob is
14
+ // damage that would otherwise replay a synthetic empty output
15
+ // event and diverge the fingerprint. The scalar fields are
16
+ // canonical (-1 code sentinel, no signal, no drops): replay
17
+ // delivers those exact defaults regardless, so a record claiming
18
+ // anything else would be silently rewritten — refuse it instead.
19
+ .output => {
20
+ if (record.pty_blob_len == 0) return true;
21
+ if (record.code != runtime_effects.effect_error_exit_code) return true;
22
+ if (record.pty_signal != 0 or record.pty_dropped_writes != 0) return true;
23
+ },
24
+ // Exits carry neither payload nor blob, and their code/signal
25
+ // must obey the delivered contract (`signal != 0` iff the reason
26
+ // is `.signaled`; `code == -1` for every reason but `.exited`).
27
+ // A hand-edited `.cancelled` with code 0 or signal 9 would
28
+ // otherwise dispatch an event violating that contract. The
29
+ // values are also RANGE-gated to what the transport can produce:
30
+ // `waitpid`'s status word yields exit codes 0..255 (plus the
31
+ // documented -1 for a child reaped outside the toolkit) and
32
+ // signals 1..127 — anything else is hand-editing, refused
33
+ // rather than replayed into an event no live run can emit.
34
+ .exit => {
35
+ if (record.pty_blob_len > 0) return true;
36
+ const signaled = record.exit_reason == .signaled;
37
+ if (signaled != (record.pty_signal != 0)) return true;
38
+ if (record.exit_reason != .exited and record.code != runtime_effects.effect_error_exit_code) return true;
39
+ if (record.exit_reason == .exited and
40
+ record.code != runtime_effects.effect_error_exit_code and
41
+ (record.code < 0 or record.code > 255)) return true;
42
+ if (signaled and (record.pty_signal < 1 or record.pty_signal > 127)) return true;
43
+ },
44
+ // A write-admission verdict carries only the accepted bit in
45
+ // `code` (1/0) — no blob, no signal, no drop count.
46
+ .write => {
47
+ if (record.pty_blob_len > 0) return true;
48
+ if (record.code != 0 and record.code != 1) return true;
49
+ if (record.pty_signal != 0 or record.pty_dropped_writes != 0) return true;
50
+ },
51
+ }
52
+ return false;
53
+ }
54
+
55
+ pub fn persistRecordDamaged(record: journal.EffectResultRecord) bool {
56
+ if (record.payload.len > 0) return true;
57
+ if (record.persist_blob_len > runtime_effects.max_effect_persist_snapshot_bytes) return true;
58
+ return record.persist_outcome != .ok and record.persist_blob_len > 0;
59
+ }
60
+
61
+ pub fn dbRecordDamaged(record: journal.EffectResultRecord) bool {
62
+ const kind = runtime_effects.dbKindFromJournalCode(record.code) orelse return true;
63
+ const outcome = runtime_effects.dbOutcomeFromJournalCode(record.code) orelse return true;
64
+ if (record.code != runtime_effects.dbJournalCode(kind, outcome)) return true;
65
+ // `.rejected` provenance identifies an admission refusal that replay
66
+ // regenerates. An executor may also return the closed `.rejected`
67
+ // outcome (for example when a result crosses its total bound); that
68
+ // terminal is external truth and correctly keeps `.exited` provenance.
69
+ if (record.exit_reason != .exited and record.exit_reason != .rejected) return true;
70
+ if (record.exit_reason == .rejected and outcome != .rejected) return true;
71
+ if (record.db_blob_len > runtime_effects.max_effect_db_page_bytes) return true;
72
+ return switch (kind) {
73
+ .page => outcome != .ok or
74
+ (record.payload.len == 0) == (record.db_blob_len == 0) or
75
+ record.payload.len > runtime_effects.max_effect_db_page_bytes,
76
+ .done, .exec => record.payload.len > 0 or record.db_blob_len > 0,
77
+ };
78
+ }
79
+
80
+ pub fn fileRecordDamaged(record: journal.EffectResultRecord) bool {
81
+ if (record.file_rejected_admission) switch (record.file_outcome) {
82
+ .rejected => {},
83
+ .sink_missing, .out_of_order => if (record.file_op != .write_stream_chunk and record.file_op != .write_stream_close) return true,
84
+ else => return true,
85
+ };
86
+ if (record.file_blob_len > runtime_effects.effect_file_stream_chunk_bytes) return true;
87
+ if (record.file_event == .chunk) {
88
+ return record.file_op != .read_stream or record.file_outcome != .ok or
89
+ record.payload.len != 0 or record.file_blob_len == 0;
90
+ }
91
+ if (record.file_blob_len != 0) return true;
92
+ if (record.file_event == .done) {
93
+ return record.file_op != .read_stream or record.file_outcome != .ok or record.payload.len != 0;
94
+ }
95
+ if (record.file_op == .stat and record.file_outcome == .ok) return record.payload.len != 0;
96
+ return record.file_total != 0 or record.file_mtime_ms != 0 or record.file_exists;
97
+ }
98
+
99
+ pub fn credentialsRecordDamaged(record: journal.EffectResultRecord) bool {
100
+ if (record.payload.len != 0 or record.exit_reason != .exited) return true;
101
+ const redacted_get = record.credentials_operation == .get and record.credentials_outcome == .ok;
102
+ if (redacted_get) return record.credentials_secret_len > runtime_effects.max_effect_credentials_secret_bytes or
103
+ std.mem.allEqual(u8, &record.credentials_salt, 0) or
104
+ std.mem.allEqual(u8, &record.credentials_digest, 0);
105
+ if (record.credentials_secret_len != 0) return true;
106
+ return !std.mem.allEqual(u8, &record.credentials_salt, 0) or
107
+ !std.mem.allEqual(u8, &record.credentials_digest, 0);
108
+ }
109
+
110
+ /// Recorder truth for pty provenance: output records always carry
111
+ /// `.exited` (the live drain never touches the exit reason on an
112
+ /// output); every reason is legal on an `.exit` record (`.rejected` =
113
+ /// regenerating admission refusal, `.spawn_failed` = executor-truth
114
+ /// start failure, the rest = real endings).
115
+ pub fn ptyRecordProvenanceDamaged(record: journal.EffectResultRecord) bool {
116
+ // Output and write-verdict records always carry `.exited` (neither
117
+ // journal site ever touches the reason).
118
+ if (record.pty_kind != .exit and record.exit_reason != .exited) return true;
119
+ // The regenerating-provenance bit only ever rides an admission
120
+ // refusal — an `.exit` record whose reason is `.rejected`.
121
+ if (record.truncated and (record.pty_kind != .exit or record.exit_reason != .rejected)) return true;
122
+ return false;
123
+ }
124
+
125
+ pub fn channelRecordDamaged(record: journal.EffectResultRecord) bool {
126
+ if (record.payload.len > runtime_effects.max_effect_channel_bytes) return true;
127
+ return record.channel_kind != .data and record.payload.len > 0;
128
+ }
129
+
130
+ /// Whether a channel record's provenance stamp contradicts its event
131
+ /// kind — RECORDER TRUTH: channel records journal from exactly two
132
+ /// sites. The live drain (staged posts and the close marker) journals
133
+ /// `.data` and `.closed` events and never touches `exit_reason`, so
134
+ /// they always carry `.exited`; the pending-terminal ring journals only
135
+ /// `.rejected` events, stamped `.rejected` when the refusal is
136
+ /// regenerating loop-side admission validation and left `.exited` when
137
+ /// it is executor truth (an open that could not stage its channel). The
138
+ /// legal pairs are therefore exactly (.data, .exited),
139
+ /// (.closed, .exited), (.rejected, .exited), (.rejected, .rejected).
140
+ /// The forward mismatch is the dangerous one: a `.data` or `.closed`
141
+ /// record stamped `.rejected` sails into the regeneration skip and is
142
+ /// silently OMITTED — with verification disabled, replay succeeds with
143
+ /// a different Msg stream. The reverse direction needs no twin gate
144
+ /// beyond the range check: `.rejected` with `.exited` is exactly the
145
+ /// executor-truth rejection and must feed; and no recorder site can
146
+ /// write any other exit reason on a channel record, so a decoded
147
+ /// `.signaled`/`.cancelled`/`.spawn_failed` (valid members for SPAWN
148
+ /// records) is hand-editing.
149
+ pub fn channelRecordProvenanceDamaged(record: journal.EffectResultRecord) bool {
150
+ if (record.exit_reason == .rejected) return record.channel_kind != .rejected;
151
+ return record.exit_reason != .exited;
152
+ }
153
+
154
+ /// A structurally valid u64 in a video record is not automatically an
155
+ /// HONEST one: the engine clamps every video scalar into the
156
+ /// exact-integer delivery window at the delivery boundary
157
+ /// (`Effects.takeVideoMsg`, `max_effect_video_scalar_exclusive`), so no
158
+ /// recorder can write a position, duration, or dimension at or past
159
+ /// 2^53 whatever a host or embedder reports — and the TS delivery tier
160
+ /// carries these scalars through the subset's exact-integer number
161
+ /// window, where feeding a larger value would trap in the bridge's
162
+ /// numeric widening instead of refusing the hostile file at the gate.
163
+ pub fn videoScalarsDamaged(record: journal.EffectResultRecord) bool {
164
+ const max_exact: u64 = runtime_effects.max_effect_video_scalar_exclusive;
165
+ return record.video_position_ms >= max_exact or
166
+ record.video_duration_ms >= max_exact or
167
+ record.video_width >= max_exact or
168
+ record.video_height >= max_exact;
169
+ }
170
+
171
+ /// The audio twin: positions and durations clamp into the exact-integer
172
+ /// window at every delivery entry before they journal, so a recorded
173
+ /// value at or past 2^53 can only be a damaged or hand-edited journal.
174
+ pub fn audioScalarsDamaged(record: journal.EffectResultRecord) bool {
175
+ const max_exact: u64 = runtime_effects.max_effect_video_scalar_exclusive;
176
+ return record.audio_position_ms >= max_exact or
177
+ record.audio_duration_ms >= max_exact;
178
+ }
179
+
180
+ /// A `.video_load` record's `video_kind` is the load's OUTCOME, and the
181
+ /// recorder writes exactly two values: `.loaded` on a resolved cascade
182
+ /// and `.failed` on a synchronous refusal. Any other kind steers
183
+ /// nothing honestly (a `.position` would leave the replayed fake load
184
+ /// active where nothing is known), so it refuses at the gate.
185
+ /// A `.video` record's kind and token are recorder-coupled: loop-side
186
+ /// rejections never minted a token (they stamp 0) and every DELIVERY —
187
+ /// position ticks, terminals, acknowledgments — carries the minted
188
+ /// token of the load that produced it. A `.rejected` with a nonzero
189
+ /// token would silently skip a real delivery through the regeneration
190
+ /// gate; a delivery with token 0 could never have routed. Both are
191
+ /// damage.
192
+ pub fn videoRecordProvenanceDamaged(record: journal.EffectResultRecord) bool {
193
+ if (record.video_kind == .rejected) return record.video_token != 0;
194
+ return record.video_token == 0;
195
+ }
196
+
197
+ /// Recorder truth for a `.video` record's payload SHAPE, per kind:
198
+ /// `.failed` and `.rejected` deliver with playing and buffering false
199
+ /// (the terminal resolution forces the flags) and no dimensions (no
200
+ /// failure path ever measured a frame); `.completed` pins position to
201
+ /// the duration with the flags false. A record violating these can
202
+ /// only be hand-edited — and a synchronously failed load's record has
203
+ /// no platform event behind it to cross-check at the pairing, so the
204
+ /// gate is where the impossible payload refuses.
205
+ pub fn videoRecordShapeDamaged(record: journal.EffectResultRecord) bool {
206
+ return switch (record.video_kind) {
207
+ .failed, .rejected => record.video_playing or record.video_buffering or
208
+ record.video_width != 0 or record.video_height != 0,
209
+ .completed => record.video_playing or record.video_buffering or
210
+ record.video_position_ms != record.video_duration_ms,
211
+ .loaded, .position => false,
212
+ };
213
+ }
214
+
215
+ pub fn videoLoadOutcomeDamaged(record: journal.EffectResultRecord) bool {
216
+ return record.video_kind != .loaded and record.video_kind != .failed;
217
+ }
218
+
219
+ pub fn imageDimsDamaged(record: journal.EffectResultRecord) bool {
220
+ if (record.image_outcome != .loaded) {
221
+ return record.image_width != 0 or record.image_height != 0;
222
+ }
223
+ if (record.image_width == 0 or record.image_height == 0) return true;
224
+ if (record.image_width > platform.max_decoded_image_dimension or record.image_height > platform.max_decoded_image_dimension) return true;
225
+ const pixels = std.math.mul(u64, record.image_width, record.image_height) catch return true;
226
+ const pixel_bytes = std.math.mul(u64, pixels, 4) catch return true;
227
+ // The journal does not carry the recording's manifest budget. Validate
228
+ // against the SDK-wide ceiling: a result above the replay runtime's
229
+ // current (possibly lowered) budget is still valid recorder truth. Its
230
+ // Msg feeds verbatim; best-effort pixel re-registration may fit smaller.
231
+ return pixel_bytes > canvas_limits.max_registered_canvas_image_pixel_bytes_ceiling;
232
+ }
233
+
234
+ /// Journaled results that regenerate deterministically from the
235
+ /// replayed updates themselves — feeding them would double-deliver:
236
+ /// rejections (the same over-capacity/duplicate-key validation refuses
237
+ /// again, loop-side) and fx-timer Msgs (real fires replay through the
238
+ /// journaled platform `.timer` events; rejections regenerate).
239
+ pub fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
240
+ return switch (record.kind) {
241
+ .timer => true,
242
+ .exit => record.exit_reason == .rejected,
243
+ // Only DETERMINISTIC admission/protocol results regenerate — marked
244
+ // by each effect family's provenance bit. Executor-truth terminals —
245
+ // start failures, platform refusals, output, and real exits — are
246
+ // external inputs and must be fed, even when their reason is rejected.
247
+ .pty => record.pty_kind == .exit and record.truncated,
248
+ .response => record.fetch_outcome == .rejected,
249
+ .file => record.file_rejected_admission,
250
+ .clipboard => record.clipboard_outcome == .rejected,
251
+ // Audio rejections are loop-side validation (path bounds) that
252
+ // refuses again; everything else — loaded acknowledgments,
253
+ // position ticks, completions, platform failures — is an
254
+ // external input and must be fed.
255
+ .audio => record.audio_kind == .rejected,
256
+ // Video rejections are the same loop-side validation (source
257
+ // bounds, scheme, surface-id shape) and regenerate; failures —
258
+ // including a claim or platform load the recording host
259
+ // refused — are executor truth the replayed fake never
260
+ // reproduces, so they feed like every other kind.
261
+ .video => record.video_kind == .rejected,
262
+ // The cascade resolution is the recording host's filesystem
263
+ // truth — the replayed fake load cannot re-run the local
264
+ // probe, so the record must feed.
265
+ .video_load => false,
266
+ // Host-request rejections mark themselves with the exit reason
267
+ // (the `.host` record encoding); host answers must be fed.
268
+ .host => record.exit_reason == .rejected,
269
+ .db => record.exit_reason == .rejected,
270
+ .credentials => false,
271
+ .window_execution => false,
272
+ .channel_source => false,
273
+ // Image `.rejected` terminals journal from BOTH sides of the
274
+ // executor seam, so the outcome alone is not provenance: only
275
+ // loop-side validation refusals — which the replayed
276
+ // `loadImage` regenerates — mark themselves with the exit
277
+ // reason (the `.host` records' convention, above). Worker-side
278
+ // rejections (a URL that passes the loop's scheme check but
279
+ // cannot become a request, an executor that could not start a
280
+ // cancelable load) keep `.exited`: the fake executor parks
281
+ // those requests, so the journaled record is the ONLY terminal
282
+ // and must be fed like every other worker truth.
283
+ .image => record.exit_reason == .rejected,
284
+ // Channel `.rejected` terminals follow the image convention
285
+ // exactly: admission refusals (occupied key, full channel
286
+ // table) mark themselves with the exit reason and regenerate —
287
+ // the replayed `openChannel` re-runs the same deterministic
288
+ // gates against re-derived occupancy windows and stages its
289
+ // own. An executor-truth rejection (the open that could not
290
+ // stage its channel) keeps `.exited` and FEEDS, retiring the
291
+ // slot the replayed open parked. `.data` and `.closed` are
292
+ // executor truth by definition — the source thread never
293
+ // re-runs at replay, so the journaled events are the ONLY
294
+ // delivery.
295
+ .channel => record.exit_reason == .rejected,
296
+ // Launch-env deliveries are exactly what must NOT regenerate:
297
+ // the recorded values feed the replayed envMsgs dispatch so the
298
+ // replay launch's environment is never consulted.
299
+ .line, .clock, .env, .persist => false,
300
+ };
301
+ }
302
+
303
+ pub fn damage(record: journal.EffectResultRecord) u16 {
304
+ var bits: u16 = 0;
305
+ const checks = [_]bool{
306
+ record.kind == .file and fileRecordDamaged(record),
307
+ record.kind == .image and record.image_outcome == .loaded and record.image_blob_len == 0,
308
+ record.kind == .channel and channelRecordDamaged(record),
309
+ record.kind == .channel and channelRecordProvenanceDamaged(record),
310
+ record.kind == .image and imageDimsDamaged(record),
311
+ record.kind == .video and videoScalarsDamaged(record),
312
+ record.kind == .audio and audioScalarsDamaged(record),
313
+ record.kind == .video and videoRecordProvenanceDamaged(record),
314
+ record.kind == .video and videoRecordShapeDamaged(record),
315
+ record.kind == .video_load and videoLoadOutcomeDamaged(record),
316
+ record.kind == .pty and ptyRecordDamaged(record),
317
+ record.kind == .pty and ptyRecordProvenanceDamaged(record),
318
+ record.kind == .persist and persistRecordDamaged(record),
319
+ record.kind == .db and dbRecordDamaged(record),
320
+ record.kind == .credentials and credentialsRecordDamaged(record),
321
+ };
322
+ for (checks, 0..) |value, i| if (value) {
323
+ bits |= @as(u16, 1) << @intCast(i);
324
+ };
325
+ return bits;
326
+ }
@@ -0,0 +1,64 @@
1
+ //! Copied replay progress plans. Storage, source reads, rendering and OS calls
2
+ //! remain native; portable comparisons receive exact words and raw labels.
3
+ const std = @import("std");
4
+ const platform = @import("../platform/root.zig");
5
+ comptime {
6
+ if (platform.max_windows != 16 or platform.max_views != 32 or platform.max_view_label_bytes != 64 or
7
+ @intFromEnum(platform.ViewKind.gpu_surface) != 17 or @typeInfo(platform.ViewKind).@"enum".fields.len != 19)
8
+ @compileError("update the portable replay target schema with the platform bounds");
9
+ }
10
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
11
+ pub const Stage = enum(u8) { count, compare, blob_admission, blob_result, finish, window, view };
12
+ pub const Action = enum(u8) { proceed, missing, over_budget, corrupt, divergence };
13
+ pub const Slot = struct { open: bool, kind: platform.ViewKind = .webview, id: u64, label: []const u8 = "" };
14
+ pub const Facts = struct {
15
+ code: u8 = 0,
16
+ a: u64 = 0,
17
+ b: u64 = 0,
18
+ c: u64 = 0,
19
+ d: u64 = 0,
20
+ label: []const u8 = "",
21
+ slots: []const Slot = &.{},
22
+ };
23
+ pub const Plan = struct {
24
+ action: Action = .proceed,
25
+ mismatch: bool = false,
26
+ mismatch_slot: ?usize = null,
27
+ index: ?usize = null,
28
+ counter: u64 = 0,
29
+ mismatch_count: u64 = 0,
30
+ };
31
+ pub fn plan(policy: Policy, stage: Stage, facts: Facts) Plan {
32
+ const callback = policy orelse return @import("replay_progress_reference.zig").plan(stage, facts);
33
+ std.debug.assert(facts.slots.len <= (if (stage == .window) platform.max_windows else platform.max_views));
34
+ var input: [96 + platform.max_views * 80]u8 = @splat(0);
35
+ input[0..4].* = .{ 25, @intFromEnum(stage), facts.code, @intCast(facts.slots.len) };
36
+ inline for (.{ facts.a, facts.b, facts.c, facts.d }, 0..) |value, i| std.mem.writeInt(u64, input[8 + i * 8 ..][0..8], value, .little);
37
+ if (stage == .view) {
38
+ std.mem.writeInt(u64, input[8..16], facts.label.len, .little);
39
+ const len = @min(facts.label.len, platform.max_view_label_bytes);
40
+ @memcpy(input[32..][0..len], facts.label[0..len]);
41
+ }
42
+ for (facts.slots, 0..) |slot, i| {
43
+ const at = 96 + i * 80;
44
+ std.debug.assert(slot.label.len <= platform.max_view_label_bytes);
45
+ input[at] = @intFromBool(slot.open);
46
+ input[at + 1] = @intFromEnum(slot.kind);
47
+ input[at + 2] = @intCast(slot.label.len);
48
+ std.mem.writeInt(u64, input[at + 8 ..][0..8], slot.id, .little);
49
+ @memcpy(input[at + 16 ..][0..slot.label.len], slot.label);
50
+ }
51
+ var output: [32]u8 = undefined;
52
+ if (callback(input[0 .. 96 + facts.slots.len * 80], &output) != output.len or output[0] > 4 or output[1] > 1 or
53
+ (output[2] != 255 and output[2] >= 16) or output[3] != 0 or !std.mem.allEqual(u8, output[24..], 0)) @panic("invalid compiled replay progress plan");
54
+ const index = std.mem.readInt(u32, output[4..8], .little);
55
+ if (index != std.math.maxInt(u32) and index >= facts.slots.len) @panic("invalid compiled replay selection");
56
+ return .{
57
+ .action = @enumFromInt(output[0]),
58
+ .mismatch = output[1] != 0,
59
+ .mismatch_slot = if (output[2] == 255) null else output[2],
60
+ .index = if (index == std.math.maxInt(u32)) null else index,
61
+ .counter = std.mem.readInt(u64, output[8..16], .little),
62
+ .mismatch_count = std.mem.readInt(u64, output[16..24], .little),
63
+ };
64
+ }