@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
@@ -5,6 +5,8 @@ const platform = @import("../platform/root.zig");
5
5
  const validation = @import("validation.zig");
6
6
  const runtime_api = @import("api.zig");
7
7
  const automation_commands = @import("automation_commands.zig");
8
+ const interactions = @import("automation_interaction_policy.zig");
9
+ const reference_dispatch = @import("automation_widget_dispatch_reference.zig");
8
10
  const runtime_clock = @import("clock.zig");
9
11
  const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
10
12
  const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
@@ -17,13 +19,12 @@ const AutomationProvenanceTarget = automation_commands.AutomationProvenanceTarge
17
19
  const AutomationWidgetWheel = automation_commands.AutomationWidgetWheel;
18
20
  const AutomationWidgetKey = automation_commands.AutomationWidgetKey;
19
21
  const AutomationWidgetPointerDrag = automation_commands.AutomationWidgetPointerDrag;
20
- const parseAutomationTextSelection = automation_commands.parseAutomationTextSelection;
21
- const parseAutomationDragDelta = automation_commands.parseAutomationDragDelta;
22
- const parseAutomationDropPaths = automation_commands.parseAutomationDropPaths;
22
+ const parseAutomationTextSelection = @import("automation_command_policy.zig").parseAutomationTextSelection;
23
+ const parseAutomationDragDelta = @import("automation_command_policy.zig").parseAutomationDragDelta;
24
+ const parseAutomationDropPaths = @import("automation_command_policy.zig").parseAutomationDropPaths;
23
25
  const automationInputTimestampNs = runtime_clock.automationInputTimestampNs;
24
26
  const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
25
27
  const canvasWidgetSelectableTargetExists = canvas_widget_runtime.canvasWidgetSelectableTargetExists;
26
- const validateViewLabel = validation.validateViewLabel;
27
28
 
28
29
  pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
29
30
  return struct {
@@ -40,7 +41,7 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
40
41
  .id = action.id,
41
42
  .action = canvasWidgetActionKindFromAutomation(action.action),
42
43
  .text = action.value,
43
- .selection = if (action.action == .set_selection) try parseAutomationTextSelection(action.value) else null,
44
+ .selection = if (action.action == .set_selection) try parseAutomationTextSelection(self.automation_command_policy, action.value) else null,
44
45
  });
45
46
  }
46
47
 
@@ -64,48 +65,16 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
64
65
  }
65
66
 
66
67
  pub fn dispatchAutomationWidgetClick(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
67
- const view_index = try automationWidgetTargetViewIndex(self, target);
68
- const point = try automationWidgetAimPoint(self, view_index, target.id);
69
- const window_id = self.views[view_index].window_id;
70
- const label = self.views[view_index].label;
71
- const timestamp_ns = automationInputTimestampNs();
72
-
73
- // One synthetic click is one atomic gesture: the down and up
74
- // land in the same automation dispatch with no present in
75
- // between, so an outer refresh batch (the per-input batches
76
- // nest inside it) coalesces the whole click — press state,
77
- // release state, and the Msg-driven rebuild — into a single
78
- // display-list emission with the same final content.
79
- CanvasWidgetDisplayMethods().beginCanvasWidgetDisplayListRefreshBatch(self);
80
- var click_batch_active = true;
81
- errdefer if (click_batch_active) {
82
- // Flush, not drop: half a click may already have changed
83
- // widget state that must reach the retained display list.
84
- CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self) catch {
85
- CanvasWidgetDisplayMethods().cancelCanvasWidgetDisplayListRefreshBatch(self);
86
- };
87
- };
88
-
89
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
90
- .window_id = window_id,
91
- .label = label,
92
- .kind = .pointer_down,
93
- .timestamp_ns = timestamp_ns,
94
- .x = point.x,
95
- .y = point.y,
96
- .button = 0,
97
- } });
98
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
99
- .window_id = window_id,
100
- .label = label,
101
- .kind = .pointer_up,
102
- .timestamp_ns = timestamp_ns,
103
- .x = point.x,
104
- .y = point.y,
105
- .button = 0,
106
- } });
107
- try CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self);
108
- click_batch_active = false;
68
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetClick(self, app, target);
69
+ const index = try automationWidgetTargetViewIndex(self, target);
70
+ var options = interactionTarget(self, index, target.id);
71
+ options.phase = 1;
72
+ try interactions.plan(self.automation_interaction_policy.?, .click, options).admit();
73
+ options.phase = 0;
74
+ options.point = try automationWidgetAimPoint(self, index, target.id);
75
+ const program = interactions.plan(self.automation_interaction_policy.?, .click, options);
76
+ try program.admit();
77
+ try dispatchInteractionSteps(self, app, index, program, .{});
109
78
  }
110
79
 
111
80
  /// Drive a press-and-hold gesture through the real pointer+timer
@@ -119,40 +88,16 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
119
88
  /// nothing arms, the fire no-ops, and the release presses — the
120
89
  /// same click a real user's long-press-and-release produces.
121
90
  pub fn dispatchAutomationWidgetHold(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
122
- const view_index = try automationWidgetTargetViewIndex(self, target);
123
- const point = try automationWidgetAimPoint(self, view_index, target.id);
124
- const window_id = self.views[view_index].window_id;
125
- const label = self.views[view_index].label;
126
- const timestamp_ns = automationInputTimestampNs();
127
-
128
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
129
- .window_id = window_id,
130
- .label = label,
131
- .kind = .pointer_down,
132
- .timestamp_ns = timestamp_ns,
133
- .x = point.x,
134
- .y = point.y,
135
- .button = 0,
136
- } });
137
- try self.dispatchPlatformEvent(app, .{ .timer = .{
138
- .id = platform.press_hold_timer_id,
139
- .timestamp_ns = timestamp_ns,
140
- } });
141
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
142
- .window_id = window_id,
143
- .label = label,
144
- .kind = .pointer_up,
145
- .timestamp_ns = timestamp_ns,
146
- .x = point.x,
147
- .y = point.y,
148
- .button = 0,
149
- } });
150
- // A fired hold's release deliberately does not cancel the
151
- // platform timer the down armed (the app never cancels a
152
- // timer that already fired); the wall-clock fire would be a
153
- // harmless no-op, but cancel it so a live run leaves no
154
- // pending one-shot behind.
155
- self.cancelTimer(platform.press_hold_timer_id) catch {};
91
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetHold(self, app, target);
92
+ const index = try automationWidgetTargetViewIndex(self, target);
93
+ var options = interactionTarget(self, index, target.id);
94
+ options.phase = 1;
95
+ try interactions.plan(self.automation_interaction_policy.?, .hold, options).admit();
96
+ options.phase = 0;
97
+ options.point = try automationWidgetAimPoint(self, index, target.id);
98
+ const program = interactions.plan(self.automation_interaction_policy.?, .hold, options);
99
+ try program.admit();
100
+ try dispatchInteractionSteps(self, app, index, program, .{});
156
101
  }
157
102
 
158
103
  /// Drive a secondary click (right/ctrl-click) as the full
@@ -162,30 +107,16 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
162
107
  /// context-press event — the desktop press-and-hold alternative
163
108
  /// whose press target's `on_hold` Msg dispatches immediately.
164
109
  pub fn dispatchAutomationWidgetContextPress(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
165
- const view_index = try automationWidgetTargetViewIndex(self, target);
166
- const point = try automationWidgetAimPoint(self, view_index, target.id);
167
- const window_id = self.views[view_index].window_id;
168
- const label = self.views[view_index].label;
169
- const timestamp_ns = automationInputTimestampNs();
170
-
171
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
172
- .window_id = window_id,
173
- .label = label,
174
- .kind = .pointer_down,
175
- .timestamp_ns = timestamp_ns,
176
- .x = point.x,
177
- .y = point.y,
178
- .button = 1,
179
- } });
180
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
181
- .window_id = window_id,
182
- .label = label,
183
- .kind = .pointer_up,
184
- .timestamp_ns = timestamp_ns,
185
- .x = point.x,
186
- .y = point.y,
187
- .button = 1,
188
- } });
110
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetContextPress(self, app, target);
111
+ const index = try automationWidgetTargetViewIndex(self, target);
112
+ var options = interactionTarget(self, index, target.id);
113
+ options.phase = 1;
114
+ try interactions.plan(self.automation_interaction_policy.?, .context_press, options).admit();
115
+ options.phase = 0;
116
+ options.point = try automationWidgetAimPoint(self, index, target.id);
117
+ const program = interactions.plan(self.automation_interaction_policy.?, .context_press, options);
118
+ try program.admit();
119
+ try dispatchInteractionSteps(self, app, index, program, .{});
189
120
  }
190
121
 
191
122
  /// Invoke one of the target widget's DECLARED context-menu items
@@ -194,8 +125,9 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
194
125
  /// the verb skips presentation and dispatches the SELECTION on
195
126
  /// the same path a real pick takes: it arms the pending request
196
127
  /// exactly as presenting would, then delivers a
197
- /// `context_menu_action` platform event — which journals,
198
- /// replays, and resolves through `dispatchContextMenuAction`
128
+ /// `context_menu_action` platform event. The journal owns the
129
+ /// complete invocation so replay also reconstructs its pending
130
+ /// request before resolving through `dispatchContextMenuAction`
199
131
  /// into the widget's `.context_menu` handler. Named errors say
200
132
  /// why an invocation cannot happen: no declared menu, an index
201
133
  /// past the declared items, a separator slot, a disabled item —
@@ -204,13 +136,71 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
204
136
  /// target's view, mid-verb.
205
137
  pub fn dispatchAutomationWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: automation_commands.AutomationWidgetContextMenuItem) anyerror!void {
206
138
  const view_index = try automationWidgetTargetViewIndex(self, item.target);
207
- const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.target.id) orelse return error.InvalidCommand;
139
+ const invocation: platform.WidgetContextMenuActionEvent = .{
140
+ .window_id = self.views[view_index].window_id,
141
+ .label = self.views[view_index].label,
142
+ .id = item.target.id,
143
+ .item_index = std.math.cast(u32, item.item_index) orelse return error.ContextMenuItemOutOfRange,
144
+ };
145
+ // Driver misuse must fail before staging a journal event.
146
+ // The platform handler also validates replayed invocations.
147
+ _ = try widgetContextMenuTargetViewIndex(self, invocation);
148
+ try self.dispatchPlatformEvent(app, .{ .widget_context_menu_action = invocation });
149
+ }
150
+
151
+ fn widgetContextMenuTargetViewIndex(self: *Runtime, item: platform.WidgetContextMenuActionEvent) anyerror!usize {
152
+ if (self.automation_interaction_policy) |policy| {
153
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, item.label);
154
+ const window_index = runtimeFindWindowIndexById(self, item.window_id);
155
+ const window_open = if (window_index) |index| self.windows[index].info.open else false;
156
+ var facts: u32 = if (window_open) interactions.Fact.window else 0;
157
+ var selected: ?usize = null;
158
+ if (window_open) for (self.views[0..self.view_count], 0..) |*view, index| {
159
+ if (view.open and view.kind == .gpu_surface and view.window_id == item.window_id and std.mem.eql(u8, view.label, item.label)) {
160
+ selected = index;
161
+ break;
162
+ }
163
+ };
164
+ if (selected) |index| {
165
+ facts |= interactions.Fact.view;
166
+ if (self.views[index].canvasWidgetNodeIndexById(item.id)) |node_index| {
167
+ facts |= interactions.Fact.node;
168
+ const widget = self.views[index].widget_layout_nodes[node_index].widget;
169
+ if (widget.context_menu.len != 0) facts |= interactions.Fact.menu;
170
+ if (item.item_index < widget.context_menu.len) {
171
+ facts |= interactions.Fact.item;
172
+ const declared = widget.context_menu[item.item_index];
173
+ if (declared.separator) facts |= interactions.Fact.separator;
174
+ if (declared.enabled) facts |= interactions.Fact.enabled;
175
+ }
176
+ }
177
+ }
178
+ try interactions.plan(policy, .menu_admission, .{ .facts = facts }).admit();
179
+ return selected.?;
180
+ }
181
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, item.label);
182
+ const window_index = runtimeFindWindowIndexById(self, item.window_id) orelse return error.WindowNotFound;
183
+ if (!self.windows[window_index].info.open) return error.WindowNotFound;
184
+ const view_index = find: {
185
+ for (self.views[0..self.view_count], 0..) |*view, index| {
186
+ 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;
187
+ }
188
+ return error.ViewNotFound;
189
+ };
190
+ const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.id) orelse return error.InvalidCommand;
208
191
  const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
209
192
  if (widget.context_menu.len == 0) return error.ContextMenuUndeclared;
210
193
  if (item.item_index >= widget.context_menu.len) return error.ContextMenuItemOutOfRange;
211
194
  const declared = widget.context_menu[item.item_index];
212
195
  if (declared.separator) return error.ContextMenuItemSeparator;
213
196
  if (!declared.enabled) return error.ContextMenuItemDisabled;
197
+ return view_index;
198
+ }
199
+
200
+ pub fn dispatchWidgetContextMenuItem(self: *Runtime, app: runtime_api.App(Runtime), item: platform.WidgetContextMenuActionEvent) anyerror!void {
201
+ const view_index = try widgetContextMenuTargetViewIndex(self, item);
202
+ const node_index = self.views[view_index].canvasWidgetNodeIndexById(item.id) orelse return error.InvalidCommand;
203
+ const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
214
204
 
215
205
  // This direct dispatch supersedes any pending presentation:
216
206
  // the replacement request commits first (bookkeeping must
@@ -247,26 +237,42 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
247
237
  // dispatching its item. Refuse by name instead — the
248
238
  // handler's successor menu is on the glass with its own
249
239
  // pending request, so nothing is orphaned.
250
- const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == token else false;
251
- if (!still_armed) {
252
- try notice;
253
- return error.ContextMenuSuperseded;
254
- }
255
- // The notice may instead have CLOSED the verb's target view:
256
- // the armed request can never resolve (the action dispatch
257
- // would clear the token, fail its view lookup, and silently
258
- // drop the selection). Disarm it and refuse by name — never
259
- // a silent success, never an orphaned token.
260
- const view_open = view_check: {
261
- for (self.views[0..self.view_count]) |*view| {
262
- if (view.open and view.window_id == pending.window_id and std.mem.eql(u8, view.label, pending.viewLabel())) break :view_check true;
240
+ if (self.automation_interaction_policy) |policy| {
241
+ const current = self.canvas_widget_context_menu_pending;
242
+ const view_open = view_check: {
243
+ for (self.views[0..self.view_count]) |*view| {
244
+ if (view.open and view.window_id == pending.window_id and std.mem.eql(u8, view.label, pending.viewLabel())) break :view_check true;
245
+ }
246
+ break :view_check false;
247
+ };
248
+ const program = interactions.plan(policy, .menu_completion, .{ .facts = (if (current != null) @as(u32, interactions.Fact.pending) else 0) | (if (view_open) @as(u32, interactions.Fact.view) else 0), .expected_token = token, .current_token = if (current) |value| value.token else 0 });
249
+ if (program.flags & 32 != 0) self.canvas_widget_context_menu_pending = null;
250
+ if (program.status != 0) {
251
+ try notice;
252
+ try program.admit();
253
+ }
254
+ } else {
255
+ const still_armed = if (self.canvas_widget_context_menu_pending) |current| current.token == token else false;
256
+ if (!still_armed) {
257
+ try notice;
258
+ return error.ContextMenuSuperseded;
259
+ }
260
+ // The notice may instead have CLOSED the verb's target view:
261
+ // the armed request can never resolve (the action dispatch
262
+ // would clear the token, fail its view lookup, and silently
263
+ // drop the selection). Disarm it and refuse by name — never
264
+ // a silent success, never an orphaned token.
265
+ const view_open = view_check: {
266
+ for (self.views[0..self.view_count]) |*view| {
267
+ if (view.open and view.window_id == pending.window_id and std.mem.eql(u8, view.label, pending.viewLabel())) break :view_check true;
268
+ }
269
+ break :view_check false;
270
+ };
271
+ if (!view_open) {
272
+ self.canvas_widget_context_menu_pending = null;
273
+ try notice;
274
+ return error.ContextMenuViewClosed;
263
275
  }
264
- break :view_check false;
265
- };
266
- if (!view_open) {
267
- self.canvas_widget_context_menu_pending = null;
268
- try notice;
269
- return error.ContextMenuViewClosed;
270
276
  }
271
277
  // The synthetic event names its view from the request's own
272
278
  // bounded copy, never `self.views[view_index]` re-read here:
@@ -301,49 +307,22 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
301
307
  }
302
308
 
303
309
  pub fn dispatchAutomationWidgetWheel(self: *Runtime, app: runtime_api.App(Runtime), wheel: AutomationWidgetWheel) anyerror!void {
304
- const view_index = try automationWidgetTargetViewIndex(self, wheel.target);
305
- const layout = self.views[view_index].widgetLayoutTree();
306
- // Named reasons, not a blanket InvalidCommand: the snapshot's
307
- // degraded error line carries the error NAME (plus the command
308
- // arguments as detail), so a failed wheel says WHY. The common
309
- // trap is aiming at a plain layout node — wheel the scrollable
310
- // widget (scroll/list/grid id from the snapshot) instead.
311
- const node = layout.findById(wheel.target.id) orelse return error.WheelTargetUnknown;
312
- if (!canvasWidgetInteractionTargetExists(layout, wheel.target.id)) return error.WheelTargetNotInteractive;
313
- const bounds = node.frame.normalized();
314
- if (bounds.isEmpty()) return error.WheelTargetHasEmptyBounds;
315
- const point = bounds.center();
316
- const timestamp_ns = automationInputTimestampNs();
317
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
318
- .window_id = self.views[view_index].window_id,
319
- .label = self.views[view_index].label,
320
- .kind = .scroll,
321
- .timestamp_ns = timestamp_ns,
322
- .x = point.x,
323
- .y = point.y,
324
- .delta_x = wheel.delta_x,
325
- .delta_y = wheel.delta_y,
326
- } });
310
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetWheel(self, app, wheel);
311
+ const index = try automationWidgetTargetViewIndex(self, wheel.target);
312
+ var options = interactionTarget(self, index, wheel.target.id);
313
+ options.delta = .{ .dx = wheel.delta_x, .dy = wheel.delta_y };
314
+ const program = interactions.plan(self.automation_interaction_policy.?, .wheel, options);
315
+ try program.admit();
316
+ try dispatchInteractionSteps(self, app, index, program, .{});
327
317
  }
328
318
 
329
319
  pub fn dispatchAutomationWidgetKeyInput(self: *Runtime, app: runtime_api.App(Runtime), key: AutomationWidgetKey) anyerror!void {
330
- const view_index = try automationGpuSurfaceViewIndexByLabel(self, key.view_label);
331
- try self.focusView(self.views[view_index].window_id, self.views[view_index].label);
332
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
333
- .window_id = self.views[view_index].window_id,
334
- .label = self.views[view_index].label,
335
- .kind = .key_down,
336
- .timestamp_ns = automationInputTimestampNs(),
337
- .key = key.key,
338
- .text = key.text,
339
- .modifiers = .{
340
- .shift = key.modifiers.shift,
341
- .control = key.modifiers.control,
342
- .option = key.modifiers.option,
343
- .command = key.modifiers.command,
344
- .primary = key.modifiers.primary,
345
- },
346
- } });
320
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetKeyInput(self, app, key);
321
+ const index = try automationGpuSurfaceViewIndexByLabel(self, key.view_label);
322
+ try self.focusView(self.views[index].window_id, self.views[index].label);
323
+ const program = interactions.plan(self.automation_interaction_policy.?, .key, .{});
324
+ try program.admit();
325
+ try dispatchInteractionSteps(self, app, index, program, .{ .key = key.key, .text = key.text, .modifiers = .{ .shift = key.modifiers.shift, .control = key.modifiers.control, .option = key.modifiers.option, .command = key.modifiers.command, .primary = key.modifiers.primary } });
347
326
  }
348
327
 
349
328
  /// Drive a trackpad pinch through the real platform-event path:
@@ -360,102 +339,22 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
360
339
  /// not a widget verb (it never routes into the widget tree; the
361
340
  /// app hears it through the pinch channel).
362
341
  pub fn dispatchAutomationWidgetPinch(self: *Runtime, app: runtime_api.App(Runtime), pinch: automation_commands.AutomationWidgetPinch) anyerror!void {
363
- const view_index = try automationGpuSurfaceViewIndexByLabel(self, pinch.view_label);
364
- const window_id = self.views[view_index].window_id;
365
- const label = self.views[view_index].label;
366
- const point = pinch.point orelse geometry.PointF.init(
367
- self.views[view_index].gpu_size.width / 2,
368
- self.views[view_index].gpu_size.height / 2,
369
- );
370
- // The wire delta is `scale - 1` in f32, and f32 rounding can
371
- // betray the parser's `scale > 0` guard: any scale at or
372
- // below 2^-25 rounds the difference to exactly -1
373
- // (ties-to-even at the halfway point), which would put the
374
- // factor `1 + delta = 0` on the wire — a zoom through zero
375
- // scale, which no gesture can perform and no downstream
376
- // product can recover from. The invariant is the WIRE's
377
- // (every emitted factor stays > 0), so validate the computed
378
- // delta, not the input; the minimum accepted scale is the
379
- // smallest f32 above 2^-25 (~2.9802326e-8), whose delta
380
- // rounds to -1 + 2^-24 — the smallest positive factor the
381
- // wire can carry. Refused before anything dispatches, so no
382
- // partial gesture reaches the journal.
383
- const delta = pinch.scale - 1;
384
- if (1 + delta <= 0) return error.PinchScaleBelowWireMinimum;
385
- const timestamp_ns = automationInputTimestampNs();
386
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
387
- .window_id = window_id,
388
- .label = label,
389
- .kind = .pinch_begin,
390
- .timestamp_ns = timestamp_ns,
391
- .x = point.x,
392
- .y = point.y,
393
- } });
394
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
395
- .window_id = window_id,
396
- .label = label,
397
- .kind = .pinch_change,
398
- .timestamp_ns = timestamp_ns,
399
- .x = point.x,
400
- .y = point.y,
401
- .scale = delta,
402
- } });
403
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
404
- .window_id = window_id,
405
- .label = label,
406
- .kind = .pinch_end,
407
- .timestamp_ns = timestamp_ns,
408
- .x = point.x,
409
- .y = point.y,
410
- } });
342
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetPinch(self, app, pinch);
343
+ const index = try automationGpuSurfaceViewIndexByLabel(self, pinch.view_label);
344
+ const options: interactions.Options = .{ .frame = .init(0, 0, self.views[index].gpu_size.width, self.views[index].gpu_size.height), .point = pinch.point orelse .zero(), .facts = if (pinch.point != null) interactions.Fact.point else 0, .delta = .{ .dx = pinch.scale, .dy = 0 } };
345
+ const program = interactions.plan(self.automation_interaction_policy.?, .pinch, options);
346
+ try program.admit();
347
+ try dispatchInteractionSteps(self, app, index, program, .{});
411
348
  }
412
349
 
413
350
  pub fn dispatchAutomationWidgetPointerDrag(self: *Runtime, app: runtime_api.App(Runtime), drag: AutomationWidgetPointerDrag) anyerror!void {
414
- const view_index = try automationWidgetTargetViewIndex(self, drag.target);
415
- const layout = self.views[view_index].widgetLayoutTree();
416
- if (!canvasWidgetInteractionTargetExists(layout, drag.target.id)) return error.InvalidCommand;
417
- const node = layout.findById(drag.target.id) orelse return error.InvalidCommand;
418
- const bounds = node.frame.normalized();
419
- if (bounds.isEmpty()) return error.InvalidCommand;
420
- const start = geometry.PointF.init(
421
- bounds.x + bounds.width * drag.start_x_ratio,
422
- bounds.y + bounds.height * drag.start_y_ratio,
423
- );
424
- const end = geometry.PointF.init(
425
- bounds.x + bounds.width * drag.end_x_ratio,
426
- bounds.y + bounds.height * drag.end_y_ratio,
427
- );
428
- const timestamp_ns = automationInputTimestampNs();
429
-
430
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
431
- .window_id = self.views[view_index].window_id,
432
- .label = self.views[view_index].label,
433
- .kind = .pointer_down,
434
- .timestamp_ns = timestamp_ns,
435
- .x = start.x,
436
- .y = start.y,
437
- .button = 0,
438
- } });
439
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
440
- .window_id = self.views[view_index].window_id,
441
- .label = self.views[view_index].label,
442
- .kind = .pointer_drag,
443
- .timestamp_ns = timestamp_ns,
444
- .x = end.x,
445
- .y = end.y,
446
- .delta_x = end.x - start.x,
447
- .delta_y = end.y - start.y,
448
- .button = 0,
449
- } });
450
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
451
- .window_id = self.views[view_index].window_id,
452
- .label = self.views[view_index].label,
453
- .kind = .pointer_up,
454
- .timestamp_ns = timestamp_ns,
455
- .x = end.x,
456
- .y = end.y,
457
- .button = 0,
458
- } });
351
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationWidgetPointerDrag(self, app, drag);
352
+ const index = try automationWidgetTargetViewIndex(self, drag.target);
353
+ var options = interactionTarget(self, index, drag.target.id);
354
+ options.ratios = .{ drag.start_x_ratio, drag.start_y_ratio, drag.end_x_ratio, drag.end_y_ratio };
355
+ const program = interactions.plan(self.automation_interaction_policy.?, .pointer_drag, options);
356
+ try program.admit();
357
+ try dispatchInteractionSteps(self, app, index, program, .{});
459
358
  }
460
359
 
461
360
  pub fn canvasWidgetActionsForId(self: *const Runtime, view_index: usize, id: canvas.ObjectId) ?canvas.WidgetActions {
@@ -565,17 +464,13 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
565
464
  // The escalation deliberately skips the tooltip machine —
566
465
  // it is still programmatic focus (no reveal), and the focus
567
466
  // MOVE above already hid any focus-owned tooltip.
568
- if (self.views[view_index].canvasWidgetNodeIndexById(id)) |node_index| {
569
- const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
570
- const plain_list_row = widget.kind == .list_item and widget.semantics.role != .treeitem;
571
- if (plain_list_row and self.views[view_index].canvas_widget_focus_visible_id != id) {
572
- const previous_state = self.views[view_index].canvasWidgetRenderState();
573
- self.views[view_index].canvas_widget_focus_visible_id = id;
574
- // Still programmatic (no reveal — see the comment
575
- // above), so no keyboard provenance either.
576
- self.views[view_index].canvas_widget_focus_visible_keyboard = false;
577
- try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
578
- }
467
+ if (self.canvasWidgetKeyboardFocusParticipation(view_index, id, 1)) {
468
+ const previous_state = self.views[view_index].canvasWidgetRenderState();
469
+ self.views[view_index].canvas_widget_focus_visible_id = id;
470
+ // Still programmatic (no reveal — see the comment
471
+ // above), so no keyboard provenance either.
472
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
473
+ try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
579
474
  }
580
475
  try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
581
476
  .window_id = self.views[view_index].window_id,
@@ -615,40 +510,12 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
615
510
  /// editor — writing the editor state directly produced on-screen
616
511
  /// state no real user could reach.
617
512
  pub fn setAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, text: []const u8) anyerror!void {
513
+ if (self.automation_interaction_policy == null) return ReferenceMethods().setAutomationCanvasWidgetText(self, app, view_index, id, text);
618
514
  try focusAutomationCanvasWidget(self, view_index, id);
619
- if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
620
- const window_id = self.views[view_index].window_id;
621
- const label = self.views[view_index].label;
622
- const timestamp_ns = automationInputTimestampNs();
623
-
624
- // Select all (the platform primary shortcut), exactly like a
625
- // user pressing cmd/ctrl+a in the focused field.
626
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
627
- .window_id = window_id,
628
- .label = label,
629
- .kind = .key_down,
630
- .timestamp_ns = timestamp_ns,
631
- .key = "a",
632
- .modifiers = .{ .primary = true },
633
- } });
634
- if (text.len == 0) {
635
- // Empty replacement: delete the selection.
636
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
637
- .window_id = window_id,
638
- .label = label,
639
- .kind = .key_down,
640
- .timestamp_ns = timestamp_ns,
641
- .key = "backspace",
642
- } });
643
- return;
644
- }
645
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
646
- .window_id = window_id,
647
- .label = label,
648
- .kind = .text_input,
649
- .timestamp_ns = timestamp_ns,
650
- .text = text,
651
- } });
515
+ const facts: u32 = (if (self.views[view_index].canEditCanvasWidgetText(id)) @as(u32, interactions.Fact.editable) else 0) | (if (text.len != 0) @as(u32, interactions.Fact.text) else 0);
516
+ const program = interactions.plan(self.automation_interaction_policy.?, .replace_text, .{ .facts = facts });
517
+ try program.admit();
518
+ try dispatchInteractionSteps(self, app, view_index, program, .{ .text = text });
652
519
  }
653
520
 
654
521
  /// Composition edits ride the SAME ime input events a real IME
@@ -668,15 +535,11 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
668
535
  kind: platform.GpuSurfaceInputKind,
669
536
  text: []const u8,
670
537
  ) anyerror!void {
538
+ if (self.automation_interaction_policy == null) return ReferenceMethods().composeAutomationCanvasWidgetText(self, app, view_index, id, kind, text);
671
539
  try focusAutomationCanvasWidget(self, view_index, id);
672
- if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
673
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
674
- .window_id = self.views[view_index].window_id,
675
- .label = self.views[view_index].label,
676
- .kind = kind,
677
- .timestamp_ns = automationInputTimestampNs(),
678
- .text = text,
679
- } });
540
+ const program = interactions.plan(self.automation_interaction_policy.?, .composition, .{ .facts = if (self.views[view_index].canEditCanvasWidgetText(id)) interactions.Fact.editable else 0 });
541
+ try program.admit();
542
+ try dispatchInteractionSteps(self, app, view_index, program, .{ .text = text, .composition = kind });
680
543
  }
681
544
 
682
545
  /// Selection edits have no platform input kind to ride, so the
@@ -708,17 +571,17 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
708
571
  }
709
572
 
710
573
  pub fn dispatchAutomationCanvasWidgetDrag(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
574
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationCanvasWidgetDrag(self, app, view_index, id, value);
711
575
  if (view_index >= self.view_count) return error.ViewNotFound;
712
- const delta = try parseAutomationDragDelta(value);
713
- const layout = self.views[view_index].widgetLayoutTree();
714
- if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
715
- const node = layout.findById(id) orelse return error.InvalidCommand;
716
- const bounds = node.frame.normalized();
717
- if (bounds.isEmpty()) return error.InvalidCommand;
576
+ const delta = try parseAutomationDragDelta(self.automation_command_policy, value);
577
+ var options = interactionTarget(self, view_index, id);
578
+ options.delta = delta;
579
+ const program = interactions.plan(self.automation_interaction_policy.?, .drag, options);
580
+ try program.admit();
718
581
 
719
582
  const window_id = self.views[view_index].window_id;
720
583
  const label = self.views[view_index].label;
721
- const origin = bounds.center();
584
+ const origin = program.origin;
722
585
  const previous_pressed_id = self.views[view_index].canvas_widget_pressed_id;
723
586
  const previous_state = self.views[view_index].canvasWidgetRenderState();
724
587
  self.views[view_index].canvas_widget_pressed_id = id;
@@ -737,26 +600,7 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
737
600
  }
738
601
  }
739
602
 
740
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
741
- .window_id = window_id,
742
- .label = label,
743
- .kind = .pointer_drag,
744
- .x = origin.x + delta.dx,
745
- .y = origin.y + delta.dy,
746
- .delta_x = delta.dx,
747
- .delta_y = delta.dy,
748
- } });
749
-
750
- // Complete the gesture through the same release path as a
751
- // physical pointer so markup `on-drag` handlers receive their
752
- // release position instead of automation stopping mid-drag.
753
- try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
754
- .window_id = window_id,
755
- .label = label,
756
- .kind = .pointer_up,
757
- .x = origin.x + delta.dx,
758
- .y = origin.y + delta.dy,
759
- } });
603
+ try dispatchInteractionSteps(self, app, view_index, program, .{});
760
604
 
761
605
  if (runtimeFindViewIndex(self, window_id, label)) |current_index| {
762
606
  if (self.views[current_index].canvas_widget_pressed_id == id) {
@@ -768,21 +612,16 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
768
612
  }
769
613
 
770
614
  pub fn dispatchAutomationCanvasWidgetFileDrop(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
771
- if (view_index >= self.view_count) return error.ViewNotFound;
772
- const layout = self.views[view_index].widgetLayoutTree();
773
- if (!canvasWidgetInteractionTargetExists(layout, id)) return error.InvalidCommand;
774
- var paths_buffer: [platform.max_drop_paths][]const u8 = undefined;
775
- const paths = try parseAutomationDropPaths(value, paths_buffer[0..]);
776
- const node = layout.findById(id) orelse return error.InvalidCommand;
777
- const bounds = node.frame.normalized();
778
- if (bounds.isEmpty()) return error.InvalidCommand;
779
-
780
- try self.dispatchPlatformEvent(app, .{ .files_dropped = .{
781
- .window_id = self.views[view_index].window_id,
782
- .view_label = self.views[view_index].label,
783
- .point = bounds.center(),
784
- .paths = paths,
785
- } });
615
+ if (self.automation_interaction_policy == null) return ReferenceMethods().dispatchAutomationCanvasWidgetFileDrop(self, app, view_index, id, value);
616
+ var options = interactionTarget(self, view_index, id);
617
+ options.phase = 1;
618
+ try interactions.plan(self.automation_interaction_policy.?, .drop, options).admit();
619
+ var buffer: [platform.max_drop_paths][]const u8 = undefined;
620
+ const paths = try parseAutomationDropPaths(self.automation_command_policy, value, &buffer);
621
+ options = interactionTarget(self, view_index, id);
622
+ const program = interactions.plan(self.automation_interaction_policy.?, .drop, options);
623
+ try program.admit();
624
+ try dispatchInteractionSteps(self, app, view_index, program, .{ .paths = paths });
786
625
  }
787
626
 
788
627
  fn automationWidgetTargetViewIndex(self: *Runtime, target: AutomationWidgetTarget) anyerror!usize {
@@ -832,7 +671,7 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
832
671
  /// per window, and for hand-rolled duplicates the first open
833
672
  /// match in window order wins, deterministically.
834
673
  pub fn automationGpuSurfaceViewIndexByLabel(self: *Runtime, view_label: []const u8) anyerror!usize {
835
- try validateViewLabel(view_label);
674
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, view_label);
836
675
  for (self.views[0..self.view_count], 0..) |*view, index| {
837
676
  if (!view.open or view.kind != .gpu_surface) continue;
838
677
  if (!std.mem.eql(u8, view.label, view_label)) continue;
@@ -843,6 +682,79 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
843
682
  return error.ViewNotFound;
844
683
  }
845
684
 
685
+ fn ReferenceMethods() type {
686
+ return reference_dispatch.RuntimeAutomationWidgetDispatch(Runtime);
687
+ }
688
+ fn interactionTarget(self: *Runtime, index: usize, id: canvas.ObjectId) interactions.Options {
689
+ if (index >= self.view_count) return .{};
690
+ const layout = self.views[index].widgetLayoutTree();
691
+ const node = layout.findById(id);
692
+ return .{ .facts = interactions.Fact.view | (if (node != null) @as(u32, interactions.Fact.node) else 0) | (if (canvasWidgetInteractionTargetExists(layout, id)) @as(u32, interactions.Fact.interactive) else 0), .frame = if (node) |value| value.frame else .zero() };
693
+ }
694
+ const InteractionPayload = struct {
695
+ key: []const u8 = "",
696
+ text: []const u8 = "",
697
+ modifiers: platform.ShortcutModifiers = .{},
698
+ composition: platform.GpuSurfaceInputKind = .ime_set_composition,
699
+ paths: []const []const u8 = &.{},
700
+ };
701
+ fn dispatchInteractionSteps(self: *Runtime, app: runtime_api.App(Runtime), index: usize, program: interactions.Program, payload: InteractionPayload) anyerror!void {
702
+ const window_id = self.views[index].window_id;
703
+ const label = self.views[index].label;
704
+ const timestamp = if (program.flags & 4 != 0) automationInputTimestampNs() else 0;
705
+ var batch_active = program.flags & 1 != 0;
706
+ if (batch_active) CanvasWidgetDisplayMethods().beginCanvasWidgetDisplayListRefreshBatch(self);
707
+ errdefer if (batch_active) {
708
+ CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self) catch CanvasWidgetDisplayMethods().cancelCanvasWidgetDisplayListRefreshBatch(self);
709
+ };
710
+ for (program.steps[0..program.count]) |step| {
711
+ const current_window = if (program.flags & 2 != 0) self.views[index].window_id else window_id;
712
+ const current_label = if (program.flags & 2 != 0) self.views[index].label else label;
713
+ if (step.event == .hold_timer) {
714
+ try self.dispatchPlatformEvent(app, .{ .timer = .{ .id = platform.press_hold_timer_id, .timestamp_ns = timestamp } });
715
+ } else if (step.event == .drop) {
716
+ try self.dispatchPlatformEvent(app, .{ .files_dropped = .{ .window_id = current_window, .view_label = current_label, .point = step.point, .paths = payload.paths } });
717
+ } else {
718
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
719
+ .window_id = current_window,
720
+ .label = current_label,
721
+ .kind = switch (step.event) {
722
+ .down => .pointer_down,
723
+ .up => .pointer_up,
724
+ .drag => .pointer_drag,
725
+ .scroll => .scroll,
726
+ .key => .key_down,
727
+ .text => .text_input,
728
+ .pinch_begin => .pinch_begin,
729
+ .pinch_change => .pinch_change,
730
+ .pinch_end => .pinch_end,
731
+ .composition => payload.composition,
732
+ else => unreachable,
733
+ },
734
+ .timestamp_ns = timestamp,
735
+ .x = step.point.x,
736
+ .y = step.point.y,
737
+ .delta_x = step.delta.dx,
738
+ .delta_y = step.delta.dy,
739
+ .scale = step.scale,
740
+ .button = step.button,
741
+ .key = switch (step.key) {
742
+ .borrowed => if (step.event == .key) payload.key else "",
743
+ .select_all => "a",
744
+ .backspace => "backspace",
745
+ },
746
+ .text = if (step.text) payload.text else "",
747
+ .modifiers = if (step.key == .select_all) .{ .primary = true } else if (step.event == .key) payload.modifiers else .{},
748
+ } });
749
+ }
750
+ }
751
+ if (program.flags & 16 != 0) self.cancelTimer(platform.press_hold_timer_id) catch {};
752
+ if (batch_active) {
753
+ try CanvasWidgetDisplayMethods().endCanvasWidgetDisplayListRefreshBatch(self);
754
+ batch_active = false;
755
+ }
756
+ }
757
+
846
758
  fn CanvasWidgetDisplayMethods() type {
847
759
  return runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime);
848
760
  }