@native-sdk/cli 0.10.1 → 0.11.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 (555) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +393 -97
  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 +2030 -83
  8. package/native-sdk.d.ts +5 -1
  9. package/package.json +20 -14
  10. package/packages/core/compile-surface/core.ts +164 -72
  11. package/packages/core/package-lock.json +75 -357
  12. package/packages/core/package.json +25 -4
  13. package/packages/core/scripts/compiler_command.mjs +17 -12
  14. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  15. package/packages/core/scripts/gen_declarations.mjs +3 -2
  16. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  17. package/packages/core/scripts/install_scriptc.mjs +182 -0
  18. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  19. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  20. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  21. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  22. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  23. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  24. package/packages/core/scripts/run_native_tests.mjs +22 -0
  25. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  26. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  27. package/packages/core/scripts/stage_external_core.mjs +68 -1
  28. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  29. package/packages/core/sdk/bytes.d.ts +2 -0
  30. package/packages/core/sdk/bytes.ts +86 -0
  31. package/packages/core/sdk/core.d.ts +332 -5
  32. package/packages/core/sdk/core.ts +371 -85
  33. package/packages/core/sdk/events.d.ts +252 -0
  34. package/packages/core/sdk/events.ts +240 -2
  35. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  36. package/packages/core/sdk/internal/image_identity.ts +71 -0
  37. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  38. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  39. package/packages/core/sdk/text.d.ts +27 -0
  40. package/packages/core/sdk/text.ts +206 -15
  41. package/packages/core/sdk/theme.d.ts +251 -0
  42. package/packages/core/sdk/theme.ts +267 -0
  43. package/packages/core/src/authorization.ts +137 -0
  44. package/packages/core/src/automation_commands.ts +201 -0
  45. package/packages/core/src/automation_interactions.ts +92 -0
  46. package/packages/core/src/bridge_descriptors.ts +104 -0
  47. package/packages/core/src/builtin_coordination.ts +172 -0
  48. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  49. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  50. package/packages/core/src/canvas_scene_observation.ts +145 -0
  51. package/packages/core/src/chart_content.ts +161 -0
  52. package/packages/core/src/chart_plans.ts +432 -0
  53. package/packages/core/src/checker.ts +186 -19
  54. package/packages/core/src/cli.ts +2 -11
  55. package/packages/core/src/code_content.ts +580 -0
  56. package/packages/core/src/command_coordination.ts +140 -0
  57. package/packages/core/src/component_composition.ts +94 -0
  58. package/packages/core/src/component_construction.ts +149 -0
  59. package/packages/core/src/context_menus.ts +76 -0
  60. package/packages/core/src/contract.ts +25 -7
  61. package/packages/core/src/control_appearance.ts +232 -0
  62. package/packages/core/src/control_commands.ts +115 -0
  63. package/packages/core/src/control_content.ts +105 -0
  64. package/packages/core/src/control_geometry.ts +107 -0
  65. package/packages/core/src/control_payloads.ts +119 -0
  66. package/packages/core/src/control_primitives.ts +134 -0
  67. package/packages/core/src/devhost.ts +82 -7
  68. package/packages/core/src/devhost_journal.mjs +30 -7
  69. package/packages/core/src/diagnostics.ts +7 -0
  70. package/packages/core/src/effect_plans.ts +71 -0
  71. package/packages/core/src/extent_program.ts +53 -0
  72. package/packages/core/src/flow_measurement.ts +121 -0
  73. package/packages/core/src/font_registry.ts +37 -0
  74. package/packages/core/src/frontend.ts +12 -10
  75. package/packages/core/src/glyph_atlas.ts +86 -0
  76. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  77. package/packages/core/src/gpu_planning.ts +123 -0
  78. package/packages/core/src/gpu_presentation.ts +55 -0
  79. package/packages/core/src/host_flow.ts +89 -0
  80. package/packages/core/src/host_input_regions.ts +165 -0
  81. package/packages/core/src/image_registry.ts +66 -0
  82. package/packages/core/src/indicator_plans.ts +132 -0
  83. package/packages/core/src/infer.ts +150 -8
  84. package/packages/core/src/input_composition.ts +116 -0
  85. package/packages/core/src/intrinsic_measure.ts +100 -0
  86. package/packages/core/src/layout_coordination.ts +207 -0
  87. package/packages/core/src/leaf_plans.ts +134 -0
  88. package/packages/core/src/markup_canonical.ts +140 -0
  89. package/packages/core/src/markup_construction.ts +189 -0
  90. package/packages/core/src/markup_development.ts +160 -0
  91. package/packages/core/src/markup_display.ts +43 -0
  92. package/packages/core/src/markup_document.ts +226 -0
  93. package/packages/core/src/markup_elements.ts +225 -0
  94. package/packages/core/src/markup_expressions.ts +79 -0
  95. package/packages/core/src/markup_imports.ts +146 -0
  96. package/packages/core/src/markup_parser.ts +228 -0
  97. package/packages/core/src/markup_runtime.ts +93 -0
  98. package/packages/core/src/markup_scalars.ts +143 -0
  99. package/packages/core/src/markup_shapes.ts +243 -0
  100. package/packages/core/src/markup_specialized.ts +242 -0
  101. package/packages/core/src/markup_text.ts +86 -0
  102. package/packages/core/src/markup_values.ts +336 -0
  103. package/packages/core/src/measurement_coordination.ts +185 -0
  104. package/packages/core/src/modules.ts +1 -1
  105. package/packages/core/src/motion_sampling.ts +100 -0
  106. package/packages/core/src/paragraph_layout.ts +192 -0
  107. package/packages/core/src/portable_sources.json +98 -0
  108. package/packages/core/src/portable_sources.ts +17 -0
  109. package/packages/core/src/registered_font.ts +92 -0
  110. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  111. package/packages/core/src/render_coordination.ts +170 -0
  112. package/packages/core/src/render_resources.ts +234 -0
  113. package/packages/core/src/runtime_policy.ts +3954 -0
  114. package/packages/core/src/scalar_text.ts +82 -0
  115. package/packages/core/src/scroll_mutation.ts +86 -0
  116. package/packages/core/src/scroll_tree.ts +86 -0
  117. package/packages/core/src/service_contract.ts +55 -3
  118. package/packages/core/src/session_codecs.ts +309 -0
  119. package/packages/core/src/shell_admission.ts +126 -0
  120. package/packages/core/src/shell_coordination.ts +93 -0
  121. package/packages/core/src/sqlite_cli.ts +14 -46
  122. package/packages/core/src/sqlite_codegen.ts +84 -0
  123. package/packages/core/src/staged_rebuild.ts +60 -0
  124. package/packages/core/src/status_validation.ts +232 -0
  125. package/packages/core/src/stream_policy.ts +63 -0
  126. package/packages/core/src/surface_recipes.ts +136 -0
  127. package/packages/core/src/system_admission.ts +60 -0
  128. package/packages/core/src/terminal_paint.ts +436 -0
  129. package/packages/core/src/text_document_width.ts +81 -0
  130. package/packages/core/src/text_measurement_cache.ts +69 -0
  131. package/packages/core/src/text_query_layout.ts +179 -0
  132. package/packages/core/src/text_run_layout.ts +410 -0
  133. package/packages/core/src/text_span_queries.ts +355 -0
  134. package/packages/core/src/typed_ast.ts +18 -1
  135. package/packages/core/src/types.ts +7 -5
  136. package/packages/core/src/vector_effects.ts +98 -0
  137. package/packages/core/src/vector_raster.ts +243 -0
  138. package/packages/core/src/view_bridge.ts +161 -0
  139. package/packages/core/src/view_check.ts +145 -0
  140. package/packages/core/src/view_components.ts +2415 -0
  141. package/packages/core/src/view_coordination.ts +198 -0
  142. package/packages/core/src/view_evaluator.ts +823 -0
  143. package/packages/core/src/view_frontend.ts +1102 -0
  144. package/packages/core/src/view_program.ts +221 -0
  145. package/packages/core/src/view_reload.ts +166 -0
  146. package/packages/core/src/view_reload_watch.ts +98 -0
  147. package/packages/core/src/view_sources.ts +34 -0
  148. package/packages/core/src/virtual_windows.ts +88 -0
  149. package/packages/core/src/web_panes.ts +67 -0
  150. package/packages/core/src/widget_audits.ts +202 -0
  151. package/packages/core/src/widget_changes.ts +258 -0
  152. package/packages/core/src/widget_continuity.ts +37 -0
  153. package/packages/core/src/widget_metrics.ts +139 -0
  154. package/packages/core/src/widget_motion.ts +171 -0
  155. package/packages/core/src/widget_paint.ts +272 -0
  156. package/packages/core/src/widget_paint_walk.ts +203 -0
  157. package/packages/core/src/widget_presentation.ts +141 -0
  158. package/packages/core/src/widget_reconcile.ts +63 -0
  159. package/packages/core/src/widget_retention.ts +62 -0
  160. package/packages/core/src/widget_routing.ts +262 -0
  161. package/packages/core/src/window_lifecycle.ts +92 -0
  162. package/packages/core/testing/index.ts +430 -0
  163. package/schemas/app.schema.json +13 -0
  164. package/skill-data/core/SKILL.md +2 -2
  165. package/skill-data/native-ui/SKILL.md +77 -18
  166. package/skill-data/ts-core/SKILL.md +117 -11
  167. package/skill-data/ts-services/SKILL.md +1 -1
  168. package/skill-data/ts-services/references/service-surface.md +288 -144
  169. package/src/app_runner/root.zig +39 -12
  170. package/src/app_runner/ts_compiled_view.zig +1702 -0
  171. package/src/app_runner/ts_core_main.zig +185 -14
  172. package/src/app_runner/ts_core_mobile.zig +25 -13
  173. package/src/automation/server.zig +57 -6
  174. package/src/automation/snapshot.zig +9 -637
  175. package/src/automation/snapshot_reference.zig +656 -0
  176. package/src/automation/snapshot_serialization.zig +566 -0
  177. package/src/embed/host.zig +2 -0
  178. package/src/embed/tests.zig +2 -0
  179. package/src/embed/ui_host.zig +2 -0
  180. package/src/platform/keyboard_input.zig +32 -0
  181. package/src/platform/linux/gtk_host.c +36 -24
  182. package/src/platform/linux/gtk_pixels.h +118 -0
  183. package/src/platform/linux/gtk_pixels_test.c +241 -0
  184. package/src/platform/linux/root.zig +4 -0
  185. package/src/platform/macos/appkit_host.h +7 -2
  186. package/src/platform/macos/appkit_host.m +219 -39
  187. package/src/platform/macos/cef_host.mm +15 -1
  188. package/src/platform/macos/global_shortcuts.zig +138 -0
  189. package/src/platform/macos/key_codes.zig +102 -0
  190. package/src/platform/macos/keyboard_input.zig +81 -0
  191. package/src/platform/macos/pointer_motion_test.m +96 -0
  192. package/src/platform/macos/root.zig +25 -3
  193. package/src/platform/macos/scroll_driver_test.m +105 -0
  194. package/src/platform/macos/spectrum_bins.h +34 -0
  195. package/src/platform/macos/spectrum_bins_test.c +56 -0
  196. package/src/platform/macos/text_keyboard_test.m +80 -0
  197. package/src/platform/macos/webview_inspection_test.m +106 -0
  198. package/src/platform/macos/widget_focus_test.m +66 -0
  199. package/src/platform/null_platform.zig +130 -2
  200. package/src/platform/null_platform_tests.zig +13 -0
  201. package/src/platform/root.zig +15 -0
  202. package/src/platform/types.zig +115 -0
  203. package/src/platform/windows/global_shortcuts.zig +157 -0
  204. package/src/platform/windows/key_codes.zig +63 -0
  205. package/src/platform/windows/keyboard_input.zig +136 -0
  206. package/src/platform/windows/root.zig +17 -0
  207. package/src/platform/windows/webview2_host.cpp +7 -2
  208. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  209. package/src/primitives/app_manifest/root.zig +2 -0
  210. package/src/primitives/app_manifest/tests.zig +4 -1
  211. package/src/primitives/app_manifest/validation.zig +2 -0
  212. package/src/primitives/canvas/a11y_audit.zig +3 -1
  213. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  214. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  215. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  216. package/src/primitives/canvas/code_content_policy.zig +162 -0
  217. package/src/primitives/canvas/commands.zig +29 -1
  218. package/src/primitives/canvas/component_composition.zig +125 -0
  219. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  220. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  221. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  222. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  223. package/src/primitives/canvas/control_command_policy.zig +75 -0
  224. package/src/primitives/canvas/control_content_policy.zig +90 -0
  225. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  226. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  227. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  228. package/src/primitives/canvas/decision_reuse.zig +133 -0
  229. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  230. package/src/primitives/canvas/events.zig +1027 -1
  231. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  232. package/src/primitives/canvas/font_ttf.zig +27 -3
  233. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  234. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  235. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  236. package/src/primitives/canvas/fonts/README.md +15 -0
  237. package/src/primitives/canvas/frame.zig +92 -23
  238. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  239. package/src/primitives/canvas/gpu.zig +10 -0
  240. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  241. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  242. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  243. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  244. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  245. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  246. package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
  247. package/src/primitives/canvas/layout_audit.zig +5 -2
  248. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  249. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  250. package/src/primitives/canvas/markdown.zig +13 -3
  251. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  252. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  253. package/src/primitives/canvas/markdown_tests.zig +3 -3
  254. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  255. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  256. package/src/primitives/canvas/reference.zig +15 -11
  257. package/src/primitives/canvas/reference_tests.zig +58 -0
  258. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  259. package/src/primitives/canvas/render.zig +48 -0
  260. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  261. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  262. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  263. package/src/primitives/canvas/render_effects.zig +14 -0
  264. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  265. package/src/primitives/canvas/render_images.zig +14 -0
  266. package/src/primitives/canvas/render_layers.zig +14 -0
  267. package/src/primitives/canvas/render_override_policy.zig +119 -0
  268. package/src/primitives/canvas/render_paths.zig +14 -0
  269. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  270. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  271. package/src/primitives/canvas/root.zig +107 -4
  272. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  273. package/src/primitives/canvas/serialization.zig +8 -1
  274. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  275. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  276. package/src/primitives/canvas/terminal_grid.zig +10 -696
  277. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  278. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  279. package/src/primitives/canvas/text.zig +1 -0
  280. package/src/primitives/canvas/text_atlas.zig +113 -0
  281. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  282. package/src/primitives/canvas/text_document_policy.zig +120 -0
  283. package/src/primitives/canvas/text_layout.zig +51 -2
  284. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  285. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  286. package/src/primitives/canvas/text_layout_types.zig +3 -0
  287. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  288. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  289. package/src/primitives/canvas/text_metrics.zig +53 -37
  290. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  291. package/src/primitives/canvas/text_query_policy.zig +295 -0
  292. package/src/primitives/canvas/text_run_policy.zig +252 -0
  293. package/src/primitives/canvas/text_scalar_policy.zig +234 -0
  294. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  295. package/src/primitives/canvas/text_spans.zig +280 -8
  296. package/src/primitives/canvas/text_tests.zig +10 -0
  297. package/src/primitives/canvas/tokens.zig +47 -0
  298. package/src/primitives/canvas/ui.zig +251 -83
  299. package/src/primitives/canvas/ui_markup.zig +207 -46
  300. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  301. package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
  302. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  303. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  304. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  305. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  306. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  307. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  308. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  309. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  310. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  311. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  312. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  313. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  314. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  315. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  316. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  317. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  318. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  319. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  320. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  321. package/src/primitives/canvas/ui_markup_view.zig +3026 -57
  322. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  323. package/src/primitives/canvas/ui_schema.zig +13 -1
  324. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  325. package/src/primitives/canvas/ui_tests.zig +1 -0
  326. package/src/primitives/canvas/vector.zig +36 -2
  327. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  328. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  329. package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
  330. package/src/primitives/canvas/virtual_extents.zig +113 -3
  331. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  332. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  333. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  334. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  335. package/src/primitives/canvas/widget_layout.zig +673 -128
  336. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  337. package/src/primitives/canvas/widget_metric_policy.zig +129 -0
  338. package/src/primitives/canvas/widget_metrics.zig +45 -6
  339. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  340. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  341. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  342. package/src/primitives/canvas/widget_render.zig +744 -74
  343. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  344. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  345. package/src/primitives/canvas/widget_render_style.zig +94 -0
  346. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  347. package/src/primitives/canvas/widget_routing.zig +75 -0
  348. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  349. package/src/primitives/canvas/widget_runtime.zig +21 -1
  350. package/src/primitives/canvas/widget_semantics.zig +25 -0
  351. package/src/primitives/canvas/widget_text_input.zig +86 -23
  352. package/src/primitives/canvas/widget_text_select.zig +1 -0
  353. package/src/primitives/canvas/widget_tree.zig +8 -1
  354. package/src/primitives/canvas/widgets.zig +42 -12
  355. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  356. package/src/root.zig +26 -0
  357. package/src/runtime/accessibility_policy.zig +122 -0
  358. package/src/runtime/api.zig +29 -0
  359. package/src/runtime/app_dispatch_policy.zig +68 -0
  360. package/src/runtime/authorization_policy.zig +150 -0
  361. package/src/runtime/automation_command_policy.zig +241 -0
  362. package/src/runtime/automation_interaction_policy.zig +107 -0
  363. package/src/runtime/automation_snapshot.zig +52 -22
  364. package/src/runtime/automation_snapshot_reference.zig +290 -0
  365. package/src/runtime/automation_widget_dispatch.zig +267 -355
  366. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  367. package/src/runtime/blob_policy.zig +58 -0
  368. package/src/runtime/blob_reference.zig +64 -0
  369. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  370. package/src/runtime/bridge_payload.zig +2 -0
  371. package/src/runtime/builtin_bridge.zig +180 -44
  372. package/src/runtime/builtin_coordination_policy.zig +121 -0
  373. package/src/runtime/callback_policy_test_reference.zig +97 -0
  374. package/src/runtime/canvas_drag_policy.zig +94 -0
  375. package/src/runtime/canvas_fonts.zig +38 -10
  376. package/src/runtime/canvas_frame.zig +590 -134
  377. package/src/runtime/canvas_frame_helpers.zig +1 -0
  378. package/src/runtime/canvas_hover_policy.zig +131 -0
  379. package/src/runtime/canvas_images.zig +59 -30
  380. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  381. package/src/runtime/canvas_limits.zig +1 -1
  382. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  383. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  384. package/src/runtime/canvas_widget_context_menu.zig +183 -4
  385. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  386. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  387. package/src/runtime/canvas_widget_display.zig +110 -9
  388. package/src/runtime/canvas_widget_events.zig +718 -328
  389. package/src/runtime/canvas_widget_runtime.zig +720 -150
  390. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  391. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  392. package/src/runtime/canvas_widget_state.zig +93 -56
  393. package/src/runtime/channel_sources.zig +80 -0
  394. package/src/runtime/command_policy.zig +161 -0
  395. package/src/runtime/component_policy.zig +83 -0
  396. package/src/runtime/context_menu_policy.zig +112 -0
  397. package/src/runtime/core.zig +170 -6
  398. package/src/runtime/desktop_files.zig +189 -0
  399. package/src/runtime/effects.zig +638 -33
  400. package/src/runtime/effects_host_tests.zig +25 -0
  401. package/src/runtime/effects_tests.zig +28 -0
  402. package/src/runtime/file_policy_test_reference.zig +113 -0
  403. package/src/runtime/flow.zig +419 -341
  404. package/src/runtime/flow_reference.zig +1427 -0
  405. package/src/runtime/font_registry_policy.zig +72 -0
  406. package/src/runtime/frame_profile.zig +24 -33
  407. package/src/runtime/global_shortcuts.zig +75 -0
  408. package/src/runtime/gpu_surface_events.zig +97 -35
  409. package/src/runtime/host_event_pump.zig +303 -0
  410. package/src/runtime/host_event_pump_reference.zig +268 -0
  411. package/src/runtime/host_flow_policy.zig +155 -0
  412. package/src/runtime/host_input_regions_policy.zig +156 -0
  413. package/src/runtime/image_registry_policy.zig +94 -0
  414. package/src/runtime/input_composition_policy.zig +138 -0
  415. package/src/runtime/journal_policy.zig +66 -0
  416. package/src/runtime/journal_reference.zig +53 -0
  417. package/src/runtime/keyboard_input.zig +86 -0
  418. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  419. package/src/runtime/markup_development_policy.zig +91 -0
  420. package/src/runtime/media_surface.zig +40 -1
  421. package/src/runtime/motion_sampling_policy.zig +159 -0
  422. package/src/runtime/recording_policy.zig +42 -0
  423. package/src/runtime/render_animation_policy.zig +206 -0
  424. package/src/runtime/replay_policy.zig +66 -0
  425. package/src/runtime/replay_policy_reference.zig +326 -0
  426. package/src/runtime/replay_progress_policy.zig +64 -0
  427. package/src/runtime/replay_progress_reference.zig +34 -0
  428. package/src/runtime/request_policy_test_reference.zig +188 -0
  429. package/src/runtime/root.zig +16 -0
  430. package/src/runtime/scroll_mutation_policy.zig +130 -0
  431. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  432. package/src/runtime/scroll_tree_policy.zig +99 -0
  433. package/src/runtime/session_blobs.zig +157 -58
  434. package/src/runtime/session_blobs_reference.zig +692 -0
  435. package/src/runtime/session_codec.zig +361 -0
  436. package/src/runtime/session_codec_reference.zig +1027 -0
  437. package/src/runtime/session_journal.zig +246 -983
  438. package/src/runtime/session_record.zig +231 -45
  439. package/src/runtime/session_replay.zig +157 -415
  440. package/src/runtime/session_tests.zig +552 -0
  441. package/src/runtime/shell_admission_policy.zig +225 -0
  442. package/src/runtime/shell_coordination_policy.zig +138 -0
  443. package/src/runtime/shell_layout.zig +126 -1
  444. package/src/runtime/snapshot_policy.zig +60 -0
  445. package/src/runtime/snapshot_reference.zig +64 -0
  446. package/src/runtime/staged_rebuild_policy.zig +83 -0
  447. package/src/runtime/state.zig +16 -0
  448. package/src/runtime/status_validation.zig +190 -0
  449. package/src/runtime/system_admission_policy.zig +140 -0
  450. package/src/runtime/system_services.zig +65 -36
  451. package/src/runtime/tests.zig +2 -0
  452. package/src/runtime/ts_canvas_hooks.zig +261 -0
  453. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  454. package/src/runtime/ts_canvas_icons.zig +234 -0
  455. package/src/runtime/ts_core_host.zig +2451 -411
  456. package/src/runtime/ts_core_host_tests.zig +1982 -0
  457. package/src/runtime/ts_test_host.zig +699 -0
  458. package/src/runtime/ts_ui_app.zig +1111 -45
  459. package/src/runtime/ui_app.zig +1381 -650
  460. package/src/runtime/ui_app_provenance.zig +147 -5
  461. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  462. package/src/runtime/ui_app_tests.zig +667 -188
  463. package/src/runtime/ui_app_window_tests.zig +222 -0
  464. package/src/runtime/view.zig +25 -0
  465. package/src/runtime/view_canvas.zig +30 -6
  466. package/src/runtime/view_coordination_policy.zig +147 -0
  467. package/src/runtime/view_reload.zig +226 -0
  468. package/src/runtime/view_widget_control.zig +51 -14
  469. package/src/runtime/view_widget_scroll.zig +46 -26
  470. package/src/runtime/view_widget_text.zig +153 -68
  471. package/src/runtime/view_widget_tree.zig +503 -69
  472. package/src/runtime/virtual_window_policy.zig +128 -0
  473. package/src/runtime/web_pane_policy.zig +111 -0
  474. package/src/runtime/web_pane_test_cases.zig +204 -0
  475. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  476. package/src/runtime/widget_continuity_policy.zig +73 -0
  477. package/src/runtime/widget_motion_policy.zig +238 -0
  478. package/src/runtime/widget_reconcile_policy.zig +81 -0
  479. package/src/runtime/widget_retention_policy.zig +75 -0
  480. package/src/runtime/window_command_bridge_tests.zig +63 -0
  481. package/src/runtime/window_lifecycle_policy.zig +127 -0
  482. package/src/runtime/window_storage.zig +74 -8
  483. package/src/runtime/window_view_runtime.zig +148 -33
  484. package/src/runtime/window_views.zig +179 -11
  485. package/src/security/root.zig +1 -0
  486. package/src/tooling/components/identity_tests.zig +62 -36
  487. package/src/tooling/components/stepper.native +24 -0
  488. package/src/tooling/components/stepper.zig +0 -19
  489. package/src/tooling/components/timeline-item.native +22 -0
  490. package/src/tooling/components/timeline.native +5 -3
  491. package/src/tooling/components/timeline_item.zig +0 -32
  492. package/src/tooling/eject_components.zig +76 -8
  493. package/src/tooling/ios.zig +66 -12
  494. package/src/tooling/manifest.zig +35 -0
  495. package/src/tooling/raw_manifest.zig +6 -0
  496. package/src/tooling/templates.zig +23 -3
  497. package/src/tooling/ts_core.zig +97 -4
  498. package/src/tooling/verbs.zig +87 -1
  499. package/tools/corewire/build_profile.mjs +54 -0
  500. package/tools/corewire/contract_intake.ts +303 -0
  501. package/tools/corewire/contract_intake.zig +82 -0
  502. package/tools/corewire/core.test.ts +188 -0
  503. package/tools/corewire/core_abi.zig +55 -0
  504. package/tools/corewire/core_cases.ts +233 -0
  505. package/tools/corewire/core_contract.ts +407 -0
  506. package/tools/corewire/core_emission.ts +136 -0
  507. package/tools/corewire/core_emission.zig +69 -0
  508. package/tools/corewire/core_goldens.json +3110 -0
  509. package/tools/corewire/core_policy.ts +14 -0
  510. package/tools/corewire/core_policy.zig +48 -0
  511. package/tools/corewire/core_projection.ts +361 -0
  512. package/tools/corewire/core_vocabulary.ts +6 -0
  513. package/tools/corewire/emit.zig +19 -1590
  514. package/tools/corewire/emit_facade.ts +714 -0
  515. package/tools/corewire/emit_facade.zig +10 -3752
  516. package/tools/corewire/emit_mirror.ts +300 -0
  517. package/tools/corewire/emit_profile.ts +50 -0
  518. package/tools/corewire/emit_service.ts +331 -0
  519. package/tools/corewire/emit_service.zig +23 -842
  520. package/tools/corewire/entry.test.ts +95 -0
  521. package/tools/corewire/entry_coordination.ts +127 -0
  522. package/tools/corewire/entry_coordination.zig +190 -0
  523. package/tools/corewire/facade_templates.ts +85 -0
  524. package/tools/corewire/filesystem.test.ts +166 -0
  525. package/tools/corewire/filesystem_coordination.ts +213 -0
  526. package/tools/corewire/filesystem_coordination.zig +245 -0
  527. package/tools/corewire/intake.test.ts +39 -0
  528. package/tools/corewire/intake_cases.ts +55 -0
  529. package/tools/corewire/intake_goldens.json +12237 -0
  530. package/tools/corewire/invocation.test.ts +28 -0
  531. package/tools/corewire/invocation.ts +175 -0
  532. package/tools/corewire/invocation.zig +136 -0
  533. package/tools/corewire/invocation_cases.ts +60 -0
  534. package/tools/corewire/invocation_fixture.ts +33 -0
  535. package/tools/corewire/invocation_goldens.json +1143 -0
  536. package/tools/corewire/invocation_tests.zig +111 -0
  537. package/tools/corewire/invocation_usage.ts +2 -0
  538. package/tools/corewire/lossless_projection.ts +96 -0
  539. package/tools/corewire/main.zig +7 -680
  540. package/tools/corewire/main_reference.zig +415 -0
  541. package/tools/corewire/mirror_templates.ts +59 -0
  542. package/tools/corewire/profile.test.ts +248 -0
  543. package/tools/corewire/profile.zig +56 -0
  544. package/tools/corewire/profile_emission.ts +204 -0
  545. package/tools/corewire/profile_library.json +29 -0
  546. package/tools/corewire/profile_tests.zig +136 -0
  547. package/tools/corewire/service.test.ts +75 -0
  548. package/tools/corewire/service_cases.ts +61 -0
  549. package/tools/corewire/service_contract.zig +40 -146
  550. package/tools/corewire/service_goldens.json +650 -0
  551. package/tools/corewire/service_projection.zig +52 -0
  552. package/tools/corewire/service_templates.ts +14 -0
  553. package/tools/corewire/shim_rt.zig +9 -0
  554. package/tools/corewire/sidecar.zig +269 -1438
  555. package/tools/corewire/emit_profile.zig +0 -521
@@ -0,0 +1,900 @@
1
+ const std = @import("std");
2
+ const geometry = @import("geometry");
3
+ const canvas = @import("canvas");
4
+ const platform = @import("../platform/root.zig");
5
+ const validation = @import("validation.zig");
6
+ const runtime_api = @import("api.zig");
7
+ const automation_commands = @import("automation_commands.zig");
8
+ const runtime_clock = @import("clock.zig");
9
+ const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
10
+ const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
11
+ const runtime_canvas_widget_events = @import("canvas_widget_events.zig");
12
+ const runtime_canvas_widget_context_menu = @import("canvas_widget_context_menu.zig");
13
+
14
+ const AutomationWidgetAction = automation_commands.AutomationWidgetAction;
15
+ const AutomationWidgetTarget = automation_commands.AutomationWidgetTarget;
16
+ const AutomationProvenanceTarget = automation_commands.AutomationProvenanceTarget;
17
+ const AutomationWidgetWheel = automation_commands.AutomationWidgetWheel;
18
+ const AutomationWidgetKey = automation_commands.AutomationWidgetKey;
19
+ const AutomationWidgetPointerDrag = automation_commands.AutomationWidgetPointerDrag;
20
+ const parseAutomationTextSelection = @import("automation_command_policy.zig").parseAutomationTextSelection;
21
+ const parseAutomationDragDelta = @import("automation_command_policy.zig").parseAutomationDragDelta;
22
+ const parseAutomationDropPaths = @import("automation_command_policy.zig").parseAutomationDropPaths;
23
+ const automationInputTimestampNs = runtime_clock.automationInputTimestampNs;
24
+ const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
25
+ const canvasWidgetSelectableTargetExists = canvas_widget_runtime.canvasWidgetSelectableTargetExists;
26
+
27
+ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
28
+ return struct {
29
+ /// The automation `widget_action` command surface delegates to
30
+ /// the accessibility dispatch rather than switching over the
31
+ /// verbs itself: one choke point performs the verb AND stages
32
+ /// the outer-wins `widget_accessibility_action` journal record,
33
+ /// so a recorded session replays the verb — focus included —
34
+ /// instead of replaying its untargeted synthesized children
35
+ /// against whatever focus the session happened to hold.
36
+ pub fn dispatchAutomationWidgetAction(self: *Runtime, app: runtime_api.App(Runtime), action: AutomationWidgetAction) anyerror!void {
37
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
38
+ _ = try self.dispatchCanvasWidgetAccessibilityAction(app, self.views[view_index].window_id, self.views[view_index].label, .{
39
+ .id = action.id,
40
+ .action = canvasWidgetActionKindFromAutomation(action.action),
41
+ .text = action.value,
42
+ .selection = if (action.action == .set_selection) try parseAutomationTextSelection(self.automation_command_policy, action.value) else null,
43
+ });
44
+ }
45
+
46
+ fn canvasWidgetActionKindFromAutomation(kind: automation_commands.AutomationWidgetActionKind) runtime_api.CanvasWidgetAccessibilityActionKind {
47
+ return switch (kind) {
48
+ .focus => .focus,
49
+ .press => .press,
50
+ .toggle => .toggle,
51
+ .increment => .increment,
52
+ .decrement => .decrement,
53
+ .set_text => .set_text,
54
+ .set_selection => .set_selection,
55
+ .set_composition => .set_composition,
56
+ .commit_composition => .commit_composition,
57
+ .cancel_composition => .cancel_composition,
58
+ .select => .select,
59
+ .drag => .drag,
60
+ .drop_files => .drop_files,
61
+ .dismiss => .dismiss,
62
+ };
63
+ }
64
+
65
+ pub fn dispatchAutomationWidgetClick(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
66
+ const view_index = try automationWidgetTargetViewIndex(self, target);
67
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
68
+ const window_id = self.views[view_index].window_id;
69
+ const label = self.views[view_index].label;
70
+ const timestamp_ns = automationInputTimestampNs();
71
+
72
+ // One synthetic click is one atomic gesture: the down and up
73
+ // land in the same automation dispatch with no present in
74
+ // between, so an outer refresh batch (the per-input batches
75
+ // nest inside it) coalesces the whole click — press state,
76
+ // release state, and the Msg-driven rebuild — into a single
77
+ // display-list emission with the same final content.
78
+ CanvasWidgetDisplayMethods().beginCanvasWidgetDisplayListRefreshBatch(self);
79
+ var click_batch_active = true;
80
+ errdefer if (click_batch_active) {
81
+ // Flush, not drop: half a click may already have changed
82
+ // widget state that must reach the retained display list.
83
+ CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self) catch {
84
+ CanvasWidgetDisplayMethods().cancelCanvasWidgetDisplayListRefreshBatch(self);
85
+ };
86
+ };
87
+
88
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
89
+ .window_id = window_id,
90
+ .label = label,
91
+ .kind = .pointer_down,
92
+ .timestamp_ns = timestamp_ns,
93
+ .x = point.x,
94
+ .y = point.y,
95
+ .button = 0,
96
+ } });
97
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
98
+ .window_id = window_id,
99
+ .label = label,
100
+ .kind = .pointer_up,
101
+ .timestamp_ns = timestamp_ns,
102
+ .x = point.x,
103
+ .y = point.y,
104
+ .button = 0,
105
+ } });
106
+ try CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self);
107
+ click_batch_active = false;
108
+ }
109
+
110
+ /// Drive a press-and-hold gesture through the real pointer+timer
111
+ /// path: pointer-down at the control's aim point (the routed
112
+ /// pointer event arms the app's hold timer exactly as a live
113
+ /// press does), the reserved hold timer fired as the platform
114
+ /// would fire it at ~350 ms, then the release — which the fired
115
+ /// hold suppresses, one gesture one Msg. Automation is
116
+ /// time-warped, never path-warped: every step is the event a
117
+ /// live run dispatches. On a target without a hold handler
118
+ /// nothing arms, the fire no-ops, and the release presses — the
119
+ /// same click a real user's long-press-and-release produces.
120
+ pub fn dispatchAutomationWidgetHold(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
121
+ const view_index = try automationWidgetTargetViewIndex(self, target);
122
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
123
+ const window_id = self.views[view_index].window_id;
124
+ const label = self.views[view_index].label;
125
+ const timestamp_ns = automationInputTimestampNs();
126
+
127
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
128
+ .window_id = window_id,
129
+ .label = label,
130
+ .kind = .pointer_down,
131
+ .timestamp_ns = timestamp_ns,
132
+ .x = point.x,
133
+ .y = point.y,
134
+ .button = 0,
135
+ } });
136
+ try self.dispatchPlatformEvent(app, .{ .timer = .{
137
+ .id = platform.press_hold_timer_id,
138
+ .timestamp_ns = timestamp_ns,
139
+ } });
140
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
141
+ .window_id = window_id,
142
+ .label = label,
143
+ .kind = .pointer_up,
144
+ .timestamp_ns = timestamp_ns,
145
+ .x = point.x,
146
+ .y = point.y,
147
+ .button = 0,
148
+ } });
149
+ // A fired hold's release deliberately does not cancel the
150
+ // platform timer the down armed (the app never cancels a
151
+ // timer that already fired); the wall-clock fire would be a
152
+ // harmless no-op, but cancel it so a live run leaves no
153
+ // pending one-shot behind.
154
+ self.cancelTimer(platform.press_hold_timer_id) catch {};
155
+ }
156
+
157
+ /// Drive a secondary click (right/ctrl-click) as the full
158
+ /// button-1 stream a real one produces: the runtime resolves a
159
+ /// context menu on the down (app-declared items, editable-text
160
+ /// and selected-text defaults) and otherwise dispatches the
161
+ /// context-press event — the desktop press-and-hold alternative
162
+ /// whose press target's `on_hold` Msg dispatches immediately.
163
+ pub fn dispatchAutomationWidgetContextPress(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
164
+ const view_index = try automationWidgetTargetViewIndex(self, target);
165
+ const point = try automationWidgetAimPoint(self, view_index, target.id);
166
+ const window_id = self.views[view_index].window_id;
167
+ const label = self.views[view_index].label;
168
+ const timestamp_ns = automationInputTimestampNs();
169
+
170
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
171
+ .window_id = window_id,
172
+ .label = label,
173
+ .kind = .pointer_down,
174
+ .timestamp_ns = timestamp_ns,
175
+ .x = point.x,
176
+ .y = point.y,
177
+ .button = 1,
178
+ } });
179
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
180
+ .window_id = window_id,
181
+ .label = label,
182
+ .kind = .pointer_up,
183
+ .timestamp_ns = timestamp_ns,
184
+ .x = point.x,
185
+ .y = point.y,
186
+ .button = 1,
187
+ } });
188
+ }
189
+
190
+ /// Invoke one of the target widget's DECLARED context-menu items
191
+ /// (`widget-context-menu <view> <id> <item-index>`). The OS
192
+ /// menu's tracking loop cannot be driven programmatically, so
193
+ /// the verb skips presentation and dispatches the SELECTION on
194
+ /// the same path a real pick takes: it arms the pending request
195
+ /// exactly as presenting would, then delivers a
196
+ /// `context_menu_action` platform event. The journal owns the
197
+ /// complete invocation so replay also reconstructs its pending
198
+ /// request before resolving through `dispatchContextMenuAction`
199
+ /// into the widget's `.context_menu` handler. Named errors say
200
+ /// why an invocation cannot happen: no declared menu, an index
201
+ /// past the declared items, a separator slot, a disabled item —
202
+ /// the same items the snapshot lists per widget — or a dismissal
203
+ /// handler that presented a superseding menu, or closed the
204
+ /// target's view, mid-verb.
205
+ pub fn dispatchAutomationWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: automation_commands.AutomationWidgetContextMenuItem) anyerror!void {
206
+ const view_index = try automationWidgetTargetViewIndex(self, item.target);
207
+ const invocation: platform.WidgetContextMenuActionEvent = .{
208
+ .window_id = self.views[view_index].window_id,
209
+ .label = self.views[view_index].label,
210
+ .id = item.target.id,
211
+ .item_index = std.math.cast(u32, item.item_index) orelse return error.ContextMenuItemOutOfRange,
212
+ };
213
+ // Driver misuse must fail before staging a journal event.
214
+ // The platform handler also validates replayed invocations.
215
+ _ = try widgetContextMenuTargetViewIndex(self, invocation);
216
+ try self.dispatchPlatformEvent(app, .{ .widget_context_menu_action = invocation });
217
+ }
218
+
219
+ fn widgetContextMenuTargetViewIndex(self: *Runtime, item: platform.WidgetContextMenuActionEvent) anyerror!usize {
220
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, item.label);
221
+ const window_index = runtimeFindWindowIndexById(self, item.window_id) orelse return error.WindowNotFound;
222
+ if (!self.windows[window_index].info.open) return error.WindowNotFound;
223
+ const view_index = find: {
224
+ for (self.views[0..self.view_count], 0..) |*view, index| {
225
+ if (view.open and view.kind == .gpu_surface and view.window_id == item.window_id and std.mem.eql(u8, view.label, item.label)) break :find index;
226
+ }
227
+ return error.ViewNotFound;
228
+ };
229
+ const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.id) orelse return error.InvalidCommand;
230
+ const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
231
+ if (widget.context_menu.len == 0) return error.ContextMenuUndeclared;
232
+ if (item.item_index >= widget.context_menu.len) return error.ContextMenuItemOutOfRange;
233
+ const declared = widget.context_menu[item.item_index];
234
+ if (declared.separator) return error.ContextMenuItemSeparator;
235
+ if (!declared.enabled) return error.ContextMenuItemDisabled;
236
+ return view_index;
237
+ }
238
+
239
+ pub fn dispatchWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: platform.WidgetContextMenuActionEvent) anyerror!void {
240
+ const view_index = try widgetContextMenuTargetViewIndex(self, item);
241
+ const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.id) orelse return error.InvalidCommand;
242
+ const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
243
+
244
+ // This direct dispatch supersedes any pending presentation:
245
+ // the replacement request commits first (bookkeeping must
246
+ // match the state the events describe), then the superseded
247
+ // app menu's snapshot/pin release through the fallible
248
+ // dismissed notice.
249
+ const superseded = self.canvas_widget_context_menu_pending;
250
+ const token = runtime_canvas_widget_context_menu.RuntimeCanvasWidgetContextMenu(Runtime).nextContextMenuToken(self);
251
+ var pending: runtime_canvas_widget_context_menu.PendingCanvasWidgetContextMenu = .{
252
+ .window_id = self.views[view_index].window_id,
253
+ .token = token,
254
+ .target_id = widget.id,
255
+ .kind = .app,
256
+ };
257
+ pending.setViewLabel(self.views[view_index].label);
258
+ self.canvas_widget_context_menu_pending = pending;
259
+ // The notice keeps its place in the event order (the old
260
+ // menu's dismissal before the successor's outcome, like
261
+ // every superseding path), but its error must not skip the
262
+ // synthetic selection below: unlike a presented menu, whose
263
+ // outcome the platform delivers later regardless, this
264
+ // dispatch is the armed request's ONLY outcome. No error
265
+ // path may leave a pending token with no presented menu and
266
+ // no delivered outcome — so capture the notice's error,
267
+ // dispatch the selection, and re-raise after (the dispatch
268
+ // ring already recorded it, matching `.propagate` semantics
269
+ // elsewhere: bookkeeping settles first, the error still
270
+ // surfaces).
271
+ const notice = runtime_canvas_widget_context_menu.RuntimeCanvasWidgetContextMenu(Runtime).notifySupersededPending(self, app, superseded);
272
+ // The notice ran arbitrary app code that may itself have
273
+ // PRESENTED a menu, superseding this verb's freshly armed
274
+ // request: the synthetic action below would fail the token
275
+ // gate and the command would report success without ever
276
+ // dispatching its item. Refuse by name instead — the
277
+ // handler's successor menu is on the glass with its own
278
+ // pending request, so nothing is orphaned.
279
+ const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == token else false;
280
+ if (!still_armed) {
281
+ try notice;
282
+ return error.ContextMenuSuperseded;
283
+ }
284
+ // The notice may instead have CLOSED the verb's target view:
285
+ // the armed request can never resolve (the action dispatch
286
+ // would clear the token, fail its view lookup, and silently
287
+ // drop the selection). Disarm it and refuse by name — never
288
+ // a silent success, never an orphaned token.
289
+ const view_open = view_check: {
290
+ for (self.views[0..self.view_count]) |*view| {
291
+ if (view.open and view.window_id == pending.window_id and std.mem.eql(u8, view.label, pending.viewLabel())) break :view_check true;
292
+ }
293
+ break :view_check false;
294
+ };
295
+ if (!view_open) {
296
+ self.canvas_widget_context_menu_pending = null;
297
+ try notice;
298
+ return error.ContextMenuViewClosed;
299
+ }
300
+ // The synthetic event names its view from the request's own
301
+ // bounded copy, never `self.views[view_index]` re-read here:
302
+ // the notice above ran arbitrary app code that may have
303
+ // closed views and compacted their indices — a stale index
304
+ // would dispatch this target against another view, or strand
305
+ // the pending token behind the action gate's window check.
306
+ try self.dispatchPlatformEvent(app, .{ .context_menu_action = .{
307
+ .window_id = pending.window_id,
308
+ .view_label = pending.viewLabel(),
309
+ .token = token,
310
+ .item_id = @intCast(item.item_index + 1),
311
+ } });
312
+ try notice;
313
+ }
314
+
315
+ /// Where a pointer verb lands on a widget: the control's aim
316
+ /// point, not the geometric center — a stretched selection
317
+ /// control (switch as a bare column child) draws its glyph at
318
+ /// the left edge of a wide frame, and the frame's center can sit
319
+ /// under an overlapping later-painted sibling. A real user
320
+ /// clicks the knob.
321
+ fn automationWidgetAimPoint(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!geometry.PointF {
322
+ const layout = self.views[view_index].widgetLayoutTree();
323
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
324
+ const node = layout.findById(id) orelse return error.InvalidCommand;
325
+ const bounds = node.frame.normalized();
326
+ if (bounds.isEmpty()) return error.InvalidCommand;
327
+ var aim_widget = node.widget;
328
+ aim_widget.frame = node.frame;
329
+ return canvas.widgetControlAimPoint(aim_widget, self.views[view_index].widget_tokens);
330
+ }
331
+
332
+ pub fn dispatchAutomationWidgetWheel(self: *Runtime, app: runtime_api.App(Runtime), wheel: AutomationWidgetWheel) anyerror!void {
333
+ const view_index = try automationWidgetTargetViewIndex(self, wheel.target);
334
+ const layout = self.views[view_index].widgetLayoutTree();
335
+ // Named reasons, not a blanket InvalidCommand: the snapshot's
336
+ // degraded error line carries the error NAME (plus the command
337
+ // arguments as detail), so a failed wheel says WHY. The common
338
+ // trap is aiming at a plain layout node — wheel the scrollable
339
+ // widget (scroll/list/grid id from the snapshot) instead.
340
+ const node = layout.findById(wheel.target.id) orelse return error.WheelTargetUnknown;
341
+ if (!canvasWidgetInteractionTargetExists(layout, wheel.target.id)) return error.WheelTargetNotInteractive;
342
+ const bounds = node.frame.normalized();
343
+ if (bounds.isEmpty()) return error.WheelTargetHasEmptyBounds;
344
+ const point = bounds.center();
345
+ const timestamp_ns = automationInputTimestampNs();
346
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
347
+ .window_id = self.views[view_index].window_id,
348
+ .label = self.views[view_index].label,
349
+ .kind = .scroll,
350
+ .timestamp_ns = timestamp_ns,
351
+ .x = point.x,
352
+ .y = point.y,
353
+ .delta_x = wheel.delta_x,
354
+ .delta_y = wheel.delta_y,
355
+ } });
356
+ }
357
+
358
+ pub fn dispatchAutomationWidgetKeyInput(self: *Runtime, app: runtime_api.App(Runtime), key: AutomationWidgetKey) anyerror!void {
359
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, key.view_label);
360
+ try self.focusView(self.views[view_index].window_id, self.views[view_index].label);
361
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
362
+ .window_id = self.views[view_index].window_id,
363
+ .label = self.views[view_index].label,
364
+ .kind = .key_down,
365
+ .timestamp_ns = automationInputTimestampNs(),
366
+ .key = key.key,
367
+ .text = key.text,
368
+ .modifiers = .{
369
+ .shift = key.modifiers.shift,
370
+ .control = key.modifiers.control,
371
+ .option = key.modifiers.option,
372
+ .command = key.modifiers.command,
373
+ .primary = key.modifiers.primary,
374
+ },
375
+ } });
376
+ }
377
+
378
+ /// Drive a trackpad pinch through the real platform-event path:
379
+ /// `pinch_begin`, one `pinch_change` carrying `scale - 1` (so
380
+ /// the cumulative product of `1 + delta` lands exactly on the
381
+ /// commanded scale — the gesture's FINAL multiplicative zoom),
382
+ /// and `pinch_end`, all at the same anchor point. A scale so
383
+ /// small its f32 delta rounds to -1 (factor 0 on the wire) is
384
+ /// refused as `PinchScaleBelowWireMinimum` — see the guard
385
+ /// below for the named minimum.
386
+ /// Plain input synthesis, the `widget-key` discipline: every
387
+ /// event journals as itself and replays through the same
388
+ /// dispatch — no accessibility-action record, because pinch is
389
+ /// not a widget verb (it never routes into the widget tree; the
390
+ /// app hears it through the pinch channel).
391
+ pub fn dispatchAutomationWidgetPinch(self: *Runtime, app: runtime_api.App(Runtime), pinch: automation_commands.AutomationWidgetPinch) anyerror!void {
392
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, pinch.view_label);
393
+ const window_id = self.views[view_index].window_id;
394
+ const label = self.views[view_index].label;
395
+ const point = pinch.point orelse geometry.PointF.init(
396
+ self.views[view_index].gpu_size.width / 2,
397
+ self.views[view_index].gpu_size.height / 2,
398
+ );
399
+ // The wire delta is `scale - 1` in f32, and f32 rounding can
400
+ // betray the parser's `scale > 0` guard: any scale at or
401
+ // below 2^-25 rounds the difference to exactly -1
402
+ // (ties-to-even at the halfway point), which would put the
403
+ // factor `1 + delta = 0` on the wire — a zoom through zero
404
+ // scale, which no gesture can perform and no downstream
405
+ // product can recover from. The invariant is the WIRE's
406
+ // (every emitted factor stays > 0), so validate the computed
407
+ // delta, not the input; the minimum accepted scale is the
408
+ // smallest f32 above 2^-25 (~2.9802326e-8), whose delta
409
+ // rounds to -1 + 2^-24 — the smallest positive factor the
410
+ // wire can carry. Refused before anything dispatches, so no
411
+ // partial gesture reaches the journal.
412
+ const delta = pinch.scale - 1;
413
+ if (1 + delta <= 0) return error.PinchScaleBelowWireMinimum;
414
+ const timestamp_ns = automationInputTimestampNs();
415
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
416
+ .window_id = window_id,
417
+ .label = label,
418
+ .kind = .pinch_begin,
419
+ .timestamp_ns = timestamp_ns,
420
+ .x = point.x,
421
+ .y = point.y,
422
+ } });
423
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
424
+ .window_id = window_id,
425
+ .label = label,
426
+ .kind = .pinch_change,
427
+ .timestamp_ns = timestamp_ns,
428
+ .x = point.x,
429
+ .y = point.y,
430
+ .scale = delta,
431
+ } });
432
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
433
+ .window_id = window_id,
434
+ .label = label,
435
+ .kind = .pinch_end,
436
+ .timestamp_ns = timestamp_ns,
437
+ .x = point.x,
438
+ .y = point.y,
439
+ } });
440
+ }
441
+
442
+ pub fn dispatchAutomationWidgetPointerDrag(self: *Runtime, app: runtime_api.App(Runtime), drag: AutomationWidgetPointerDrag) anyerror!void {
443
+ const view_index = try automationWidgetTargetViewIndex(self, drag.target);
444
+ const layout = self.views[view_index].widgetLayoutTree();
445
+ if (!canvasWidgetInteractionTargetExists(layout, drag.target.id)) return error.InvalidCommand;
446
+ const node = layout.findById(drag.target.id) orelse return error.InvalidCommand;
447
+ const bounds = node.frame.normalized();
448
+ if (bounds.isEmpty()) return error.InvalidCommand;
449
+ const start = geometry.PointF.init(
450
+ bounds.x + bounds.width * drag.start_x_ratio,
451
+ bounds.y + bounds.height * drag.start_y_ratio,
452
+ );
453
+ const end = geometry.PointF.init(
454
+ bounds.x + bounds.width * drag.end_x_ratio,
455
+ bounds.y + bounds.height * drag.end_y_ratio,
456
+ );
457
+ const timestamp_ns = automationInputTimestampNs();
458
+
459
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
460
+ .window_id = self.views[view_index].window_id,
461
+ .label = self.views[view_index].label,
462
+ .kind = .pointer_down,
463
+ .timestamp_ns = timestamp_ns,
464
+ .x = start.x,
465
+ .y = start.y,
466
+ .button = 0,
467
+ } });
468
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
469
+ .window_id = self.views[view_index].window_id,
470
+ .label = self.views[view_index].label,
471
+ .kind = .pointer_drag,
472
+ .timestamp_ns = timestamp_ns,
473
+ .x = end.x,
474
+ .y = end.y,
475
+ .delta_x = end.x - start.x,
476
+ .delta_y = end.y - start.y,
477
+ .button = 0,
478
+ } });
479
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
480
+ .window_id = self.views[view_index].window_id,
481
+ .label = self.views[view_index].label,
482
+ .kind = .pointer_up,
483
+ .timestamp_ns = timestamp_ns,
484
+ .x = end.x,
485
+ .y = end.y,
486
+ .button = 0,
487
+ } });
488
+ }
489
+
490
+ pub fn canvasWidgetActionsForId(self: *const Runtime, view_index: usize, id: canvas.ObjectId) ?canvas.WidgetActions {
491
+ if (view_index >= self.view_count or id == 0) return null;
492
+ for (self.views[view_index].widgetSemantics()) |node| {
493
+ if (node.id == id) return node.actions;
494
+ }
495
+ return null;
496
+ }
497
+
498
+ pub fn dismissAutomationCanvasWidget(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId) anyerror!void {
499
+ if (view_index >= self.view_count) return error.ViewNotFound;
500
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
501
+ const dismissal = try self.views[view_index].dismissCanvasWidgetSurfaceForTarget(id) orelse return error.InvalidCommand;
502
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dismissal.dirty);
503
+ try CanvasWidgetEventMethods().dispatchCanvasWidgetDismissEvent(self, app, view_index, dismissal.id);
504
+ }
505
+
506
+ pub fn focusAutomationCanvasWidget(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!void {
507
+ if (view_index >= self.view_count) return error.ViewNotFound;
508
+ // Programmatic focus names logical targets before applying the
509
+ // pointer path's geometry clip. The shared keyboard/autofocus
510
+ // reveal seam scrolls every runtime-owned ancestor. Preflight
511
+ // the reveal before platform focus, then focus the view before
512
+ // committing any retained scroll mutation: a rejected platform
513
+ // focus leaves the canvas byte-for-byte where it was.
514
+ if (!CanvasWidgetEventMethods().canRevealCanvasWidgetFocusTarget(self, view_index, id)) return error.InvalidCommand;
515
+ try self.focusView(self.views[view_index].window_id, self.views[view_index].label);
516
+ const reveal = try CanvasWidgetEventMethods().revealCanvasWidgetFocusTarget(self, view_index, id) orelse return error.InvalidCommand;
517
+ const target = reveal.target;
518
+ // Programmatic focus (autofocus, automation `focus`) follows
519
+ // the pointer contract, not the keyboard one: buttons and
520
+ // rows take focus QUIETLY (no ring), editable text kinds show
521
+ // their affordances however focus arrived. A later Tab still
522
+ // moves focus with the visible ring. Without this gate, a
523
+ // window-level default focus landing on a button dressed an
524
+ // idle control in the focus ring.
525
+ const focus_visible_id: canvas.ObjectId = if (canvas_widget_runtime.canvasWidgetShowsPointerFocusRing(target.kind)) target.id else 0;
526
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
527
+ const focus_changed = self.views[view_index].canvas_widget_focused_id != target.id or self.views[view_index].canvas_widget_focus_visible_id != focus_visible_id;
528
+ if (focus_changed) {
529
+ self.views[view_index].canvas_widget_focused_id = target.id;
530
+ self.views[view_index].canvas_widget_focus_visible_id = focus_visible_id;
531
+ // Pointer-contract provenance: a programmatic ring
532
+ // (editables only) never carries the keyboard's
533
+ // standing reveal intent into a layout adoption.
534
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
535
+ // The pointer contract extends to tooltips: this move
536
+ // hides a focus-owned tooltip and reveals nothing (see
537
+ // updateCanvasTooltipIntentForProgrammaticFocusMove).
538
+ // Inside the changed-guard on purpose — re-focusing the
539
+ // widget whose focus-shown tooltip is up with the ring
540
+ // intact is not a move, and leaves it alone.
541
+ try CanvasWidgetEventMethods().updateCanvasTooltipIntentForProgrammaticFocusMove(self, view_index);
542
+ }
543
+
544
+ // The established programmatic-selection contract is a collapsed
545
+ // caret at text.len when no source/retained selection exists.
546
+ // Preserve an existing selection, then reveal its focus endpoint
547
+ // inside the editor after the outer ancestor reveal has made the
548
+ // editability/visibility gate truthful.
549
+ const caret_initialized = try self.views[view_index].ensureCanvasWidgetFocusedTextCaret();
550
+ var inner_scroll_changed = false;
551
+ if (self.views[view_index].canEditCanvasWidgetText(target.id)) {
552
+ if (self.views[view_index].canvasWidgetNodeIndexById(target.id)) |node_index| {
553
+ const before = self.views[view_index].widget_layout_nodes[node_index].widget;
554
+ self.views[view_index].scrollCanvasTextInputCaretIntoView(node_index);
555
+ const after = self.views[view_index].widget_layout_nodes[node_index].widget;
556
+ inner_scroll_changed = before.value != after.value or before.value_x != after.value_x;
557
+ }
558
+ }
559
+ if (inner_scroll_changed) {
560
+ try self.views[view_index].refreshCanvasWidgetSemantics();
561
+ if (!caret_initialized) self.views[view_index].widget_revision += 1;
562
+ }
563
+
564
+ if (focus_changed or caret_initialized or inner_scroll_changed or reveal.scroll_dirty != null) {
565
+ // A focus/reveal change repaints; record the automation input
566
+ // so the completing frame publishes (same contract as select
567
+ // and text edits). Callers that dispatch a follow-up input
568
+ // event simply overwrite this with their own timestamp.
569
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
570
+ }
571
+ if (focus_changed) {
572
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
573
+ } else if (caret_initialized or inner_scroll_changed) {
574
+ if (self.views[view_index].canvasWidgetNodeIndexById(target.id)) |node_index| {
575
+ if (self.views[view_index].canvasWidgetDirtyBounds(node_index, self.views[view_index].widget_layout_nodes[node_index].frame)) |dirty| {
576
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
577
+ }
578
+ }
579
+ }
580
+ if (reveal.scroll_dirty != null) {
581
+ _ = try CanvasWidgetDisplayMethods().refreshCanvasWidgetDisplayListIfOwned(self, view_index);
582
+ }
583
+ }
584
+
585
+ pub fn dispatchAutomationWidgetKey(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, key: []const u8) anyerror!void {
586
+ try focusAutomationCanvasWidget(self, view_index, id);
587
+ // An automation KEY action emulates the KEYBOARD contract on
588
+ // its target. Plain list rows are transparent to keys under
589
+ // QUIET focus (the quiet-list-row rule in the keyboard
590
+ // routing), so the synthesized activation must reach the row
591
+ // the way a Tab-then-key would: escalate exactly this target
592
+ // kind to the ring register before dispatching. Every other
593
+ // kind keeps the quiet programmatic focus it always had.
594
+ // The escalation deliberately skips the tooltip machine —
595
+ // it is still programmatic focus (no reveal), and the focus
596
+ // MOVE above already hid any focus-owned tooltip.
597
+ if (self.canvasWidgetKeyboardFocusParticipation(view_index, id, 1)) {
598
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
599
+ self.views[view_index].canvas_widget_focus_visible_id = id;
600
+ // Still programmatic (no reveal — see the comment
601
+ // above), so no keyboard provenance either.
602
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
603
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
604
+ }
605
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
606
+ .window_id = self.views[view_index].window_id,
607
+ .label = self.views[view_index].label,
608
+ .kind = .key_down,
609
+ .timestamp_ns = automationInputTimestampNs(),
610
+ .key = key,
611
+ } });
612
+ }
613
+
614
+ pub fn selectAutomationCanvasWidget(self: *Runtime, view_index: usize, id: canvas.ObjectId) anyerror!void {
615
+ const layout = self.views[view_index].widgetLayoutTree();
616
+ if (!canvasWidgetSelectableTargetExists(layout, id)) return error.InvalidCommand;
617
+ if (layout.focusTargetById(id) != null) {
618
+ try focusAutomationCanvasWidget(self, view_index, id);
619
+ }
620
+ const dirty = try self.views[view_index].setCanvasWidgetSelected(id, true) orelse return;
621
+ // Record the automation input so the frame this repaint
622
+ // presents resolves it into an input latency and republishes
623
+ // observable state (dispatchGpuSurfaceFrame invalidates on a
624
+ // recorded latency; steady-state completions stay quiet).
625
+ // Without this, the snapshot's gpu_frame only advanced when a
626
+ // PREVIOUS interaction happened to leave a dangling pending
627
+ // input for this frame to resolve — a timing accident that a
628
+ // loaded CI runner loses ("menu item automation select did
629
+ // not request a GPU frame").
630
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
631
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
632
+ }
633
+
634
+ /// Replace an editable widget's text through the SAME input-event
635
+ /// path real typing uses: focus, a select-all key, then the
636
+ /// replacement text as a text-input event. Each step routes
637
+ /// through `dispatchGpuSurfaceInput`, so the app receives the
638
+ /// matching `.canvas_widget_keyboard` events and an elm-style
639
+ /// model's `on_input` mirror stays consistent with the runtime
640
+ /// editor — writing the editor state directly produced on-screen
641
+ /// state no real user could reach.
642
+ pub fn setAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, text: []const u8) anyerror!void {
643
+ try focusAutomationCanvasWidget(self, view_index, id);
644
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
645
+ const window_id = self.views[view_index].window_id;
646
+ const label = self.views[view_index].label;
647
+ const timestamp_ns = automationInputTimestampNs();
648
+
649
+ // Select all (the platform primary shortcut), exactly like a
650
+ // user pressing cmd/ctrl+a in the focused field.
651
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
652
+ .window_id = window_id,
653
+ .label = label,
654
+ .kind = .key_down,
655
+ .timestamp_ns = timestamp_ns,
656
+ .key = "a",
657
+ .modifiers = .{ .primary = true },
658
+ } });
659
+ if (text.len == 0) {
660
+ // Empty replacement: delete the selection.
661
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
662
+ .window_id = window_id,
663
+ .label = label,
664
+ .kind = .key_down,
665
+ .timestamp_ns = timestamp_ns,
666
+ .key = "backspace",
667
+ } });
668
+ return;
669
+ }
670
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
671
+ .window_id = window_id,
672
+ .label = label,
673
+ .kind = .text_input,
674
+ .timestamp_ns = timestamp_ns,
675
+ .text = text,
676
+ } });
677
+ }
678
+
679
+ /// Composition edits ride the SAME ime input events a real IME
680
+ /// session produces (`setAutomationCanvasWidgetText`'s
681
+ /// philosophy): the dispatch applies the edit to the retained
682
+ /// editor, stamps it onto the routed keyboard event so the app's
683
+ /// `on_input` mirror hears it, and journals the input so a
684
+ /// recorded session replays the composition byte-identically.
685
+ /// Writing the editor directly (the previous shape) kept the
686
+ /// model out of the loop — the same divergence the keyboard
687
+ /// choke point closes for Escape's clear.
688
+ pub fn composeAutomationCanvasWidgetText(
689
+ self: *Runtime,
690
+ app: runtime_api.App(Runtime),
691
+ view_index: usize,
692
+ id: canvas.ObjectId,
693
+ kind: platform.GpuSurfaceInputKind,
694
+ text: []const u8,
695
+ ) anyerror!void {
696
+ try focusAutomationCanvasWidget(self, view_index, id);
697
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
698
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
699
+ .window_id = self.views[view_index].window_id,
700
+ .label = self.views[view_index].label,
701
+ .kind = kind,
702
+ .timestamp_ns = automationInputTimestampNs(),
703
+ .text = text,
704
+ } });
705
+ }
706
+
707
+ /// Selection edits have no platform input kind to ride, so the
708
+ /// verb synthesizes the routed keyboard event the clipboard and
709
+ /// context-menu edits use: the keyboard choke point applies the
710
+ /// stamped edit to the retained editor and the app dispatch
711
+ /// keeps the model's selection mirror honest. (The journal sees
712
+ /// this verb as the outer `widget_accessibility_action` record
713
+ /// its dispatch stages; replaying that record re-runs the verb.)
714
+ pub fn editAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
715
+ try focusAutomationCanvasWidget(self, view_index, id);
716
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
717
+ const target = self.views[view_index].widgetLayoutTree().focusTargetById(id) orelse return error.InvalidCommand;
718
+ var keyboard_event: runtime_api.CanvasWidgetKeyboardEvent = .{
719
+ .window_id = self.views[view_index].window_id,
720
+ .view_label = self.views[view_index].label,
721
+ .keyboard = .{ .phase = .key_down, .focused_id = id, .edit = edit },
722
+ .target = target,
723
+ // No gpu-surface input cycle wraps this selection edit:
724
+ // the ui-app hover drain runs at its own tail.
725
+ .standalone = true,
726
+ };
727
+ // Same observability contract as selectAutomationCanvasWidget:
728
+ // the repaint this edit triggers must publish its completing
729
+ // frame, so record the automation input it resolves.
730
+ self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
731
+ try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &keyboard_event);
732
+ try self.dispatchEvent(app, .{ .canvas_widget_keyboard = keyboard_event });
733
+ }
734
+
735
+ pub fn dispatchAutomationCanvasWidgetDrag(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
736
+ if (view_index >= self.view_count) return error.ViewNotFound;
737
+ const delta = try parseAutomationDragDelta(self.automation_command_policy, value);
738
+ const layout = self.views[view_index].widgetLayoutTree();
739
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
740
+ const node = layout.findById(id) orelse return error.InvalidCommand;
741
+ const bounds = node.frame.normalized();
742
+ if (bounds.isEmpty()) return error.InvalidCommand;
743
+
744
+ const window_id = self.views[view_index].window_id;
745
+ const label = self.views[view_index].label;
746
+ const origin = bounds.center();
747
+ const previous_pressed_id = self.views[view_index].canvas_widget_pressed_id;
748
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
749
+ self.views[view_index].canvas_widget_pressed_id = id;
750
+ // Accessibility owns the outer action record and therefore seeds
751
+ // the press directly instead of journaling a synthetic down. Give
752
+ // the shared physical drag path the same origin a down would have
753
+ // recorded; platform pointer-drag deltas are not cumulative (and
754
+ // are zero on several hosts), so reconstruction from the event's
755
+ // delta cannot recover this point.
756
+ self.views[view_index].canvas_widget_drag_start_point = origin;
757
+ self.views[view_index].canvas_widget_drag_pointer_id = 0;
758
+ if (previous_pressed_id != id) try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
759
+ errdefer {
760
+ if (view_index < self.view_count and self.views[view_index].canvas_widget_pressed_id == id) {
761
+ self.views[view_index].canvas_widget_pressed_id = previous_pressed_id;
762
+ }
763
+ }
764
+
765
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
766
+ .window_id = window_id,
767
+ .label = label,
768
+ .kind = .pointer_drag,
769
+ .x = origin.x + delta.dx,
770
+ .y = origin.y + delta.dy,
771
+ .delta_x = delta.dx,
772
+ .delta_y = delta.dy,
773
+ } });
774
+
775
+ // Complete the gesture through the same release path as a
776
+ // physical pointer so markup `on-drag` handlers receive their
777
+ // release position instead of automation stopping mid-drag.
778
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
779
+ .window_id = window_id,
780
+ .label = label,
781
+ .kind = .pointer_up,
782
+ .x = origin.x + delta.dx,
783
+ .y = origin.y + delta.dy,
784
+ } });
785
+
786
+ if (runtimeFindViewIndex(self, window_id, label)) |current_index| {
787
+ if (self.views[current_index].canvas_widget_pressed_id == id) {
788
+ const release_previous_state = self.views[current_index].canvasWidgetRenderState();
789
+ self.views[current_index].canvas_widget_pressed_id = 0;
790
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, current_index, release_previous_state, self.views[current_index].canvasWidgetRenderState());
791
+ }
792
+ }
793
+ }
794
+
795
+ pub fn dispatchAutomationCanvasWidgetFileDrop(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
796
+ if (view_index >= self.view_count) return error.ViewNotFound;
797
+ const layout = self.views[view_index].widgetLayoutTree();
798
+ if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
799
+ var paths_buffer: [platform.max_drop_paths][]const u8 = undefined;
800
+ const paths = try parseAutomationDropPaths(self.automation_command_policy, value, paths_buffer[0..]);
801
+ const node = layout.findById(id) orelse return error.InvalidCommand;
802
+ const bounds = node.frame.normalized();
803
+ if (bounds.isEmpty()) return error.InvalidCommand;
804
+
805
+ try self.dispatchPlatformEvent(app, .{ .files_dropped = .{
806
+ .window_id = self.views[view_index].window_id,
807
+ .view_label = self.views[view_index].label,
808
+ .point = bounds.center(),
809
+ .paths = paths,
810
+ } });
811
+ }
812
+
813
+ fn automationWidgetTargetViewIndex(self: *Runtime, target: AutomationWidgetTarget) anyerror!usize {
814
+ return automationGpuSurfaceViewIndexByLabel(self, target.view_label);
815
+ }
816
+
817
+ /// The `provenance` verb: resolve the view (and, for point
818
+ /// queries, hit-test the widget id), then ask the app that
819
+ /// authored the view to answer from its retained provenance
820
+ /// table. Every path writes `provenance.txt` — the CLI polls the
821
+ /// artifact, so silence would be a hang, and errors teach.
822
+ pub fn dispatchAutomationProvenance(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationProvenanceTarget) anyerror!void {
823
+ const server = self.options.automation orelse return;
824
+ self.command_count += 1;
825
+ const view_index = automationGpuSurfaceViewIndexByLabel(self, target.view_label) catch {
826
+ try publishAutomationProvenanceError(server, target.view_label, target.id, "no open gpu_surface view with this label - `native automate list` names the open views");
827
+ return error.ViewNotFound;
828
+ };
829
+ const layout = self.views[view_index].widgetLayoutTree();
830
+ var id = target.id;
831
+ if (target.point) |point| {
832
+ const hit = layout.hitTest(point) orelse {
833
+ try publishAutomationProvenanceError(server, target.view_label, 0, "no widget at the given point (view-local points; the snapshot's bounds= fields name each widget's rectangle)");
834
+ return error.InvalidCommand;
835
+ };
836
+ id = hit.id;
837
+ } else if (layout.findById(id) == null) {
838
+ try publishAutomationProvenanceError(server, target.view_label, id, "no widget with this id in the view - ids go stale across rebuilds, re-read the snapshot");
839
+ return error.InvalidCommand;
840
+ }
841
+ self.automation_provenance_published = false;
842
+ try app.event(self, .{ .automation_provenance = .{
843
+ .window_id = self.views[view_index].window_id,
844
+ .view_label = self.views[view_index].label,
845
+ .widget_id = id,
846
+ } });
847
+ if (!self.automation_provenance_published) {
848
+ try publishAutomationProvenanceError(server, target.view_label, id, "the app exposes no widget provenance - it needs the markup interpreter (UiAppFeatures.runtime_markup) running under automation; compiled-only (release) views report none");
849
+ }
850
+ }
851
+
852
+ /// Resolve a widget verb's gpu_surface view by label across ALL
853
+ /// open windows — snapshots enumerate every window's views, so
854
+ /// the verbs must reach them too (a model-declared settings
855
+ /// window's canvas is as drivable as the main one). Labels are
856
+ /// the verb's whole address; `UiApp` keeps canvas labels unique
857
+ /// per window, and for hand-rolled duplicates the first open
858
+ /// match in window order wins, deterministically.
859
+ pub fn automationGpuSurfaceViewIndexByLabel(self: *Runtime, view_label: []const u8) anyerror!usize {
860
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, view_label);
861
+ for (self.views[0..self.view_count], 0..) |*view, index| {
862
+ if (!view.open or view.kind != .gpu_surface) continue;
863
+ if (!std.mem.eql(u8, view.label, view_label)) continue;
864
+ const window_index = runtimeFindWindowIndexById(self, view.window_id) orelse continue;
865
+ if (!self.windows[window_index].info.open) continue;
866
+ return index;
867
+ }
868
+ return error.ViewNotFound;
869
+ }
870
+
871
+ fn CanvasWidgetDisplayMethods() type {
872
+ return runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime);
873
+ }
874
+
875
+ fn CanvasWidgetEventMethods() type {
876
+ return runtime_canvas_widget_events.RuntimeCanvasWidgetEvents(Runtime);
877
+ }
878
+ };
879
+ }
880
+
881
+ fn publishAutomationProvenanceError(server: anytype, view_label: []const u8, id: u64, message: []const u8) !void {
882
+ var buffer: [1024]u8 = undefined;
883
+ var writer = std.Io.Writer.fixed(&buffer);
884
+ try writer.print("provenance error view={s} id={d} message=\"{s}\"\n", .{ view_label, id, message });
885
+ try server.publishProvenanceResponse(writer.buffered());
886
+ }
887
+
888
+ fn runtimeFindWindowIndexById(self: anytype, id: platform.WindowId) ?usize {
889
+ for (self.windows[0..self.window_count], 0..) |window, index| {
890
+ if (window.info.id == id) return index;
891
+ }
892
+ return null;
893
+ }
894
+
895
+ fn runtimeFindViewIndex(self: anytype, window_id: platform.WindowId, label: []const u8) ?usize {
896
+ for (self.views[0..self.view_count], 0..) |*view, index| {
897
+ if (view.open and view.window_id == window_id and std.mem.eql(u8, view.label, label)) return index;
898
+ }
899
+ return null;
900
+ }