@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,155 @@
1
+ //! Copied portable host-flow programs over native-owned facts and capabilities.
2
+ const std = @import("std");
3
+ const platform = @import("../platform/root.zig");
4
+ const api = @import("api.zig");
5
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
6
+ pub const Stage = enum(u8) { enqueue, take, enter, turn, error_selection, platform_event, gate, app_event, run, cleanup, journal_enter, journal_exit };
7
+ pub const Action = enum(u8) { end, install, lap_start, reserve, start, extensions_start, lifecycle_start, lap_started, scene, load, lap_loaded, startup_dirty, start_log, activate, deactivate, tooltip_reset, lifecycle_activate, lifecycle_deactivate, emit_activate, emit_deactivate, appearance, text_generation, appearance_event, surface, surface_window, surface_layout, surface_emit, surface_dirty, surface_log, capture_open, window_update, window_layout, window_save, window_log, window_close, focus_window, dirty, focus_view, frame, bridge, tray_log, shortcut_event, shortcut_emit, command_dirty, gpu_resize_log, drop_route, drop_widget, drop_event, drop_emit, lifecycle_stop, extensions_stop, mark_stop, stop, stop_log, command_tray_action, command_shortcut, command_native_command, command_menu_command, command_tray_command, command_notification_command, event_timer, event_audio, event_video, event_wake, capability_gpu_surface_frame, capability_gpu_surface_resized, capability_gpu_surface_input, capability_gpu_surface_scroll_driver, capability_context_menu_action, capability_widget_context_menu_action, capability_widget_accessibility_action };
8
+ pub const Facts = struct { kind: u8 = 0, a: u8 = 0, b: u8 = 0, count: usize = 0, used: usize = 0, cost: usize = 0, head: usize = 0, delivered: usize = 0 };
9
+ pub const Plan = [64]u8;
10
+ pub fn plan(callback: *const fn ([]const u8, []u8) usize, stage: Stage, f: Facts) Plan {
11
+ var input: [64]u8 = @splat(0);
12
+ input[0..6].* = .{ 31, 1, @intFromEnum(stage), f.kind, f.a, f.b };
13
+ inline for (.{ f.count, f.used, f.cost, f.head, f.delivered }, 0..) |value, i| std.mem.writeInt(u32, input[8 + i * 4 ..][0..4], @intCast(value), .little);
14
+ var result: Plan = undefined;
15
+ if (callback(&input, &result) != result.len) @panic("invalid compiled host flow size");
16
+ if (!validResult(stage, f, &result)) @panic("invalid compiled host flow result");
17
+ return result;
18
+ }
19
+ // Reject incompatible typed payload access, unterminated programs and bytes
20
+ // outside the response extent before executing any native capability.
21
+ pub fn validResult(stage: Stage, f: Facts, result: []const u8) bool {
22
+ if (result.len != 64) return false;
23
+ if (stage == .enqueue) {
24
+ const available = 4194304 - @min(f.used, 4194304);
25
+ const budget = available - @min(f.cost, available);
26
+ return result[0] >= 1 and result[0] <= 3 and std.mem.readInt(u32, result[8..12], .little) <= budget and std.mem.allEqual(u8, result[1..8], 0) and std.mem.allEqual(u8, result[12..], 0);
27
+ }
28
+ if (stage == .platform_event or stage == .app_event or stage == .run or stage == .cleanup or stage == .journal_enter or stage == .journal_exit) {
29
+ var ended = false;
30
+ for (result) |byte| {
31
+ if (byte == 0) {
32
+ ended = true;
33
+ continue;
34
+ }
35
+ if (ended) return false;
36
+ if (stage == .journal_enter and byte == 1 and f.a == 0 or stage == .journal_exit and f.a == 0 or stage == .cleanup and byte == 4 and f.b == 0) return false;
37
+ if (stage == .platform_event) {
38
+ if (byte >= std.meta.fields(Action).len) return false;
39
+ const kind: u8 = switch (@as(Action, @enumFromInt(byte))) {
40
+ .end => unreachable,
41
+ .install, .lap_start, .reserve, .start, .extensions_start, .lifecycle_start, .lap_started, .scene, .load, .lap_loaded, .startup_dirty, .start_log => 0,
42
+ .activate, .lifecycle_activate, .emit_activate => 1,
43
+ .deactivate, .tooltip_reset, .lifecycle_deactivate, .emit_deactivate => 2,
44
+ .appearance, .text_generation, .appearance_event => 3,
45
+ .frame => 4,
46
+ .lifecycle_stop, .extensions_stop, .mark_stop, .stop, .stop_log => 5,
47
+ .surface, .surface_window, .surface_layout, .surface_emit, .surface_dirty, .surface_log => 6,
48
+ .capture_open, .window_update, .window_layout, .window_save, .window_log, .window_close => 7,
49
+ .focus_window => 8,
50
+ .focus_view => 9,
51
+ .dirty => if (f.kind == 8) 8 else 9,
52
+ .bridge => 10,
53
+ .tray_log, .command_tray_action => 11,
54
+ .shortcut_event, .shortcut_emit, .command_shortcut => 12,
55
+ .command_native_command => 13,
56
+ .command_menu_command => 14,
57
+ .command_tray_command => 15,
58
+ .command_notification_command => 16,
59
+ .event_timer => 17,
60
+ .event_wake => 18,
61
+ .drop_route, .drop_widget, .drop_event, .drop_emit => 19,
62
+ .command_dirty => if (f.kind == 12) 12 else 19,
63
+ .capability_gpu_surface_frame => 20,
64
+ .capability_gpu_surface_resized, .gpu_resize_log => 21,
65
+ .capability_gpu_surface_input => 22,
66
+ .capability_gpu_surface_scroll_driver => 23,
67
+ .capability_context_menu_action => 24,
68
+ .capability_widget_accessibility_action => 25,
69
+ .capability_widget_context_menu_action => 26,
70
+ .event_audio => 27,
71
+ .event_video => 28,
72
+ };
73
+ if (kind != f.kind) return false;
74
+ } else if (stage == .app_event) {
75
+ if (byte > 5 or byte == 1 and f.kind != 2) return false;
76
+ } else if (byte > (switch (stage) {
77
+ .run => @as(u8, 7),
78
+ .cleanup => 4,
79
+ .journal_enter => 2,
80
+ .journal_exit => 3,
81
+ else => unreachable,
82
+ })) return false;
83
+ }
84
+ return ended;
85
+ }
86
+ const max: u8 = if (stage == .gate and f.kind != 4) 1 else 2;
87
+ return result[0] <= max and (stage != .enter or result[0] != 0) and std.mem.allEqual(u8, result[1..], 0);
88
+ }
89
+ pub fn gate(callback: *const fn ([]const u8, []u8) usize, kind: u8, a: u8, b: u8) u8 {
90
+ return plan(callback, .gate, .{ .kind = kind, .a = a, .b = b })[0];
91
+ }
92
+ pub fn eventKind(value: platform.Event) u8 {
93
+ return switch (value) {
94
+ .app_start => 0,
95
+ .app_activated => 1,
96
+ .app_deactivated => 2,
97
+ .appearance_changed => 3,
98
+ .frame_requested => 4,
99
+ .app_shutdown => 5,
100
+ .surface_resized => 6,
101
+ .window_frame_changed => 7,
102
+ .window_focused => 8,
103
+ .view_focused => 9,
104
+ .bridge_message => 10,
105
+ .tray_action => 11,
106
+ .shortcut => 12,
107
+ .native_command => 13,
108
+ .menu_command => 14,
109
+ .tray_command => 15,
110
+ .notification_command => 16,
111
+ .timer => 17,
112
+ .wake => 18,
113
+ .files_dropped => 19,
114
+ .gpu_surface_frame => 20,
115
+ .gpu_surface_resized => 21,
116
+ .gpu_surface_input => 22,
117
+ .gpu_surface_scroll_driver => 23,
118
+ .context_menu_action => 24,
119
+ .widget_accessibility_action => 25,
120
+ .widget_context_menu_action => 26,
121
+ .audio => 27,
122
+ .video => 28,
123
+ };
124
+ }
125
+ pub fn appKind(value: api.Event) u8 {
126
+ return switch (value) {
127
+ .lifecycle => 0,
128
+ .appearance_changed => 1,
129
+ .command => 2,
130
+ .shortcut => 3,
131
+ .timer => 4,
132
+ .effects_wake => 5,
133
+ .audio => 6,
134
+ .video => 7,
135
+ .files_dropped => 8,
136
+ .gpu_surface_frame => 9,
137
+ .gpu_surface_resized => 10,
138
+ .gpu_surface_input => 11,
139
+ .canvas_widget_pointer => 12,
140
+ .canvas_widget_keyboard => 13,
141
+ .canvas_widget_scroll => 14,
142
+ .canvas_widget_file_drop => 15,
143
+ .canvas_widget_drag => 16,
144
+ .canvas_widget_context_menu => 17,
145
+ .canvas_widget_context_menu_shown => 18,
146
+ .canvas_widget_context_menu_dismissed => 19,
147
+ .canvas_widget_context_menu_request => 20,
148
+ .canvas_widget_dismiss => 21,
149
+ .canvas_widget_context_press => 22,
150
+ .canvas_widget_resize => 23,
151
+ .canvas_widget_change => 24,
152
+ .window_closed => 25,
153
+ .automation_provenance => 26,
154
+ };
155
+ }
@@ -0,0 +1,156 @@
1
+ //! Copies layout and retained observations to the portable region owner.
2
+ //! Native retains all buffers, measurement capabilities and OS execution.
3
+ const std = @import("std");
4
+ const canvas = @import("canvas");
5
+ const geometry = @import("geometry");
6
+ const platform = @import("../platform/root.zig");
7
+ const limits = @import("canvas_limits.zig");
8
+ const RuntimeView = @import("view.zig").RuntimeView;
9
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
10
+ pub const Mode = enum(u8) { stamp, drivers, drag, record };
11
+ pub const Options = struct {
12
+ nodes: []const canvas.WidgetLayoutNode = &.{},
13
+ tokens: canvas.DesignTokens = .{},
14
+ frame: geometry.RectF = .zero(),
15
+ supported: bool = false,
16
+ drag_service: bool = false,
17
+ drag_pushed: bool = false,
18
+ drag_capacity: usize = limits.max_canvas_widget_window_drag_regions_per_view,
19
+ previous: []const platform.WindowDragRegion = &.{},
20
+ tracked_ids: []const u64 = &.{},
21
+ tracked_offsets: []const geometry.OffsetF = &.{},
22
+ measure_view: ?*const RuntimeView = null,
23
+ record_id: u64 = 0,
24
+ };
25
+ pub const Program = struct {
26
+ stamp_count: usize = 0,
27
+ stamps: [limits.max_canvas_widget_nodes_per_view]usize = undefined,
28
+ driver_count: usize = 0,
29
+ drivers: [platform.max_gpu_surface_scroll_drivers]platform.GpuSurfaceScrollDriver = undefined,
30
+ occluder_count: usize = 0,
31
+ occluders: [platform.max_gpu_surface_scroll_occluders]platform.GpuSurfaceScrollOccluder = undefined,
32
+ region_count: usize = 0,
33
+ regions: [limits.max_canvas_widget_window_drag_regions_per_view]platform.WindowDragRegion = undefined,
34
+ detail: u32 = 0,
35
+ pub fn stamp(self: *const Program, nodes: []canvas.WidgetLayoutNode) void {
36
+ for (self.stamps[0..self.stamp_count]) |index| nodes[index].widget.runtime_flags.native_scroll = true;
37
+ }
38
+ };
39
+ fn put(bytes: []u8, at: usize, value: u32) void {
40
+ std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
41
+ }
42
+ fn float(bytes: []u8, at: usize, value: f32) void {
43
+ put(bytes, at, @bitCast(value));
44
+ }
45
+ fn word(bytes: []const u8, at: usize) u32 {
46
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
47
+ }
48
+ fn wide(bytes: []const u8, at: usize) u64 {
49
+ return std.mem.readInt(u64, bytes[at..][0..8], .little);
50
+ }
51
+ fn scalar(bytes: []const u8, at: usize) f32 {
52
+ return @bitCast(word(bytes, at));
53
+ }
54
+ fn rect(bytes: []const u8, at: usize) geometry.RectF {
55
+ return .init(scalar(bytes, at), scalar(bytes, at + 4), scalar(bytes, at + 8), scalar(bytes, at + 12));
56
+ }
57
+ fn writeRect(bytes: []u8, at: usize, value: geometry.RectF) void {
58
+ for ([_]f32{ value.x, value.y, value.width, value.height }, 0..) |v, i| float(bytes, at + i * 4, v);
59
+ }
60
+ pub fn plan(policy: Policy, mode: Mode, options: Options) ?Program {
61
+ const callback = policy orelse return null;
62
+ const count = options.nodes.len;
63
+ if (count > limits.max_canvas_widget_nodes_per_view or options.tracked_ids.len > platform.max_gpu_surface_scroll_drivers or options.tracked_ids.len != options.tracked_offsets.len or options.previous.len > limits.max_canvas_widget_window_drag_regions_per_view or options.drag_capacity > limits.max_canvas_widget_window_drag_regions_per_view)
64
+ @panic("host input-region observation capacity");
65
+ const tracked_at = 64 + count * 128;
66
+ const previous_at = tracked_at + options.tracked_ids.len * 16;
67
+ const request = std.heap.page_allocator.alloc(u8, previous_at + options.previous.len * 20) catch @panic("host input-region observation allocation");
68
+ defer std.heap.page_allocator.free(request);
69
+ @memset(request, 0);
70
+ request[0..4].* = .{ 79, 1, @intFromEnum(mode), 0 };
71
+ put(request, 4, @intCast(count));
72
+ put(request, 8, @intCast(options.tracked_ids.len));
73
+ put(request, 12, @intCast(options.previous.len));
74
+ put(request, 20, @as(u32, @intFromBool(options.supported)) | (@as(u32, @intFromBool(options.drag_service)) << 1) | (@as(u32, @intFromBool(options.drag_pushed)) << 2));
75
+ put(request, 24, @intFromBool(options.tokens.scroll.overscroll == .rubber_band));
76
+ put(request, 28, @intCast(options.drag_capacity));
77
+ writeRect(request, 32, options.frame);
78
+ if (mode == .record) std.mem.writeInt(u64, request[40..48], options.record_id, .little);
79
+ for ([_]i32{ options.tokens.layer.base, options.tokens.layer.overlay, options.tokens.layer.modal, options.tokens.layer.floating }, 0..) |v, i| put(request, 48 + i * 4, @bitCast(v));
80
+ for (options.nodes, 0..) |node, i| {
81
+ const n = node.widget;
82
+ const bytes = request[64 + i * 128 ..][0..128];
83
+ put(bytes, 0, canvas.widgetKindCode(n.kind));
84
+ put(bytes, 8, if (node.parent_index) |p| @intCast(p) else std.math.maxInt(u32));
85
+ put(bytes, 12, @intCast(node.depth));
86
+ std.mem.writeInt(u64, bytes[16..24], n.id, .little);
87
+ put(bytes, 24, @as(u32, @intFromBool(n.semantics.hidden)) | (@as(u32, @intFromBool(n.state.disabled)) << 1) | (@as(u32, @intFromBool(n.state.selected)) << 2) | (@as(u32, @intFromBool(n.layout.anchor != null)) << 3) | (@as(u32, @intFromBool(n.layout.clip_content)) << 4) | (@as(u32, @intFromBool(n.window_drag)) << 6) | (@as(u32, @intFromBool(n.layer != null)) << 9));
88
+ put(bytes, 28, (@as(u32, @intFromBool(n.semantics.actions.press)) << 1) | (@as(u32, @intFromBool(n.semantics.actions.toggle)) << 2) | (@as(u32, @intFromBool(n.semantics.actions.drag)) << 8));
89
+ float(bytes, 32, n.value);
90
+ put(bytes, 36, @bitCast(n.layer orelse 0));
91
+ writeRect(bytes, 40, node.frame);
92
+ const values = [_]f32{ n.transform.a, n.transform.b, n.transform.c, n.transform.d, n.transform.tx, n.transform.ty, n.layout.padding.top, n.layout.padding.right, n.layout.padding.bottom, n.layout.padding.left, n.value_x };
93
+ for (values, 0..) |v, j| float(bytes, 56 + j * 4, v);
94
+ std.mem.writeInt(u64, bytes[100..108], n.layout.virtual_item_count, .little);
95
+ put(bytes, 108, @as(u32, @intFromBool(n.layout.virtualized)) | (@as(u32, @intFromBool(n.scrim)) << 1) | (@as(u32, @intFromEnum(n.scroll_axes)) << 2) | (@as(u32, @intFromEnum(n.overscroll)) << 4));
96
+ }
97
+ for (options.tracked_ids, options.tracked_offsets, 0..) |id, offset, i| {
98
+ const at = tracked_at + i * 16;
99
+ std.mem.writeInt(u64, request[at..][0..8], id, .little);
100
+ float(request, at + 8, offset.dx);
101
+ float(request, at + 12, offset.dy);
102
+ }
103
+ for (options.previous, 0..) |region, i| {
104
+ const at = previous_at + i * 20;
105
+ writeRect(request, at, region.frame);
106
+ put(request, at + 16, @intFromBool(region.exclusion));
107
+ }
108
+ var output: [32 + limits.max_canvas_widget_nodes_per_view * 4 + platform.max_gpu_surface_scroll_drivers * 64 + platform.max_gpu_surface_scroll_occluders * 16 + limits.max_canvas_widget_window_drag_regions_per_view * 20]u8 = undefined;
109
+ var observations: usize = 0;
110
+ var length: usize = undefined;
111
+ while (true) {
112
+ @memset(&output, 0xa5);
113
+ length = callback(request, &output);
114
+ if (length < 32 or length > output.len or word(&output, 0) != 1 or word(&output, 4) != @intFromEnum(mode)) @panic("invalid compiled host input-region header");
115
+ if (word(&output, 8) != 1) break;
116
+ const index = word(&output, 28);
117
+ const axes = word(&output, 12);
118
+ if (mode != .drivers or length != 48 or index >= count or (axes != 1 and axes != 3) or word(&output, 16) != 0 or word(&output, 20) != 0 or word(&output, 24) != 0 or observations >= platform.max_gpu_surface_scroll_drivers)
119
+ @panic("invalid compiled host input-region measurement");
120
+ const at = 64 + @as(usize, index) * 128;
121
+ if (word(request, at + 112) != 0) @panic("repeated compiled host input-region measurement");
122
+ const view = options.measure_view orelse @panic("missing host input-region measurement capability");
123
+ const viewport = rect(&output, 32);
124
+ float(request, at + 116, view.canvasWidgetScrollContentExtent(index, viewport));
125
+ if (axes & 2 != 0) float(request, at + 120, view.canvasWidgetScrollContentExtentX(index, viewport));
126
+ put(request, at + 112, 1);
127
+ observations += 1;
128
+ }
129
+ if (word(&output, 8) != 0) @panic("invalid compiled host input-region status");
130
+ var result = Program{ .stamp_count = word(&output, 12), .driver_count = word(&output, 16), .occluder_count = word(&output, 20), .region_count = word(&output, 24), .detail = word(&output, 28) };
131
+ if (result.stamp_count > count or result.driver_count > result.drivers.len or result.occluder_count > result.occluders.len or result.region_count > options.drag_capacity or length != 32 + result.stamp_count * 4 + result.driver_count * 64 + result.occluder_count * 16 + result.region_count * 20 or (mode != .stamp and mode != .drivers and result.stamp_count != 0) or (mode != .drivers and (result.driver_count != 0 or result.occluder_count != 0)) or (mode != .drag and result.region_count != 0) or (mode == .drag and result.detail > 1) or (mode == .record and result.detail != std.math.maxInt(u32) and (result.detail > options.tracked_ids.len or result.detail >= platform.max_gpu_surface_scroll_drivers)) or ((mode == .stamp or mode == .drivers) and result.detail != 0))
132
+ @panic("invalid compiled host input-region program");
133
+ var at: usize = 32;
134
+ for (result.stamps[0..result.stamp_count], 0..) |*index, i| {
135
+ index.* = word(&output, at);
136
+ if (index.* >= count or (i > 0 and result.stamps[i - 1] >= index.*)) @panic("invalid compiled host input-region stamp");
137
+ at += 4;
138
+ }
139
+ for (result.drivers[0..result.driver_count]) |*driver| {
140
+ const flags = word(&output, at + 20);
141
+ const mask = word(&output, at + 16);
142
+ if (flags > 31 or mask >= (@as(u32, 1) << @intCast(result.occluder_count)) or wide(&output, at) == 0 or wide(&output, at + 56) != 0) @panic("invalid compiled host input-region driver");
143
+ driver.* = .{ .id = wide(&output, at), .parent_id = wide(&output, at + 8), .occluder_mask = mask, .frame = rect(&output, at + 24), .content_size = .{ .width = scalar(&output, at + 40), .height = scalar(&output, at + 44) }, .offset_x = scalar(&output, at + 48), .offset_y = scalar(&output, at + 52), .set_offset_x = flags & 1 != 0, .set_offset_y = flags & 2 != 0, .rubber_band = flags & 4 != 0, .scrolls_x = flags & 8 != 0, .scrolls_y = flags & 16 != 0 };
144
+ at += 64;
145
+ }
146
+ for (result.occluders[0..result.occluder_count]) |*occluder| {
147
+ occluder.* = .{ .frame = rect(&output, at) };
148
+ at += 16;
149
+ }
150
+ for (result.regions[0..result.region_count]) |*region| {
151
+ if (word(&output, at + 16) > 1) @panic("invalid compiled host input-region exclusion");
152
+ region.* = .{ .frame = rect(&output, at), .exclusion = word(&output, at + 16) != 0 };
153
+ at += 20;
154
+ }
155
+ return result;
156
+ }
@@ -0,0 +1,94 @@
1
+ //! Copied metadata transport. Allocation, bytes and synchronization stay native.
2
+ const std = @import("std");
3
+ pub const Policy = *const fn ([]const u8, []u8) usize;
4
+ pub const Mode = enum(u8) { register, encoded, lookup, remove, repaint, media_entry, media_equal, media_lookup, media_purge };
5
+ pub const Record = struct { id: u64 = 0, fingerprint: u64 = 0, flags: u32 = 0 };
6
+ pub const Options = struct {
7
+ id: u64 = 0,
8
+ width: usize = 0,
9
+ height: usize = 0,
10
+ length: usize = 0,
11
+ budget: usize = 0,
12
+ source_limit: u32 = 8 * 1024 * 1024,
13
+ cursor: usize = 0,
14
+ facts: u32 = 0,
15
+ fingerprint: u64 = 0,
16
+ previous_fingerprint: u64 = 0,
17
+ };
18
+ pub const Program = struct {
19
+ status: u32,
20
+ selected: ?usize,
21
+ action: u32,
22
+ next: ?usize,
23
+ pub fn admit(self: Program) !void {
24
+ switch (self.status) {
25
+ 0 => {},
26
+ 1 => return error.InvalidImageId,
27
+ 2 => return error.InvalidImageDimensions,
28
+ 3 => return error.ImageTooLarge,
29
+ 4 => return error.ImageRegistryFull,
30
+ else => unreachable,
31
+ }
32
+ }
33
+ };
34
+ fn put(bytes: []u8, at: usize, value: u32) void {
35
+ std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
36
+ }
37
+ fn word(bytes: []const u8, at: usize) u32 {
38
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
39
+ }
40
+ fn wide(bytes: []u8, at: usize, value: u64) void {
41
+ std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
42
+ }
43
+ pub fn plan(policy: Policy, mode: Mode, records: []const Record, capacity: usize, options: Options) Program {
44
+ if (records.len > capacity or capacity > 32) @panic("image registry observation capacity");
45
+ var request: [96 + 32 * 32]u8 = @splat(0);
46
+ request[0..4].* = .{ 82, 1, @intFromEnum(mode), @bitSizeOf(usize) };
47
+ put(&request, 4, @intCast(records.len));
48
+ put(&request, 8, @intCast(capacity));
49
+ put(&request, 12, @intCast(options.cursor));
50
+ put(&request, 16, options.facts);
51
+ put(&request, 20, options.source_limit);
52
+ wide(&request, 24, options.id);
53
+ wide(&request, 32, options.width);
54
+ wide(&request, 40, options.height);
55
+ wide(&request, 48, options.length);
56
+ wide(&request, 56, if (mode == .media_equal) options.previous_fingerprint else options.budget);
57
+ wide(&request, 64, options.fingerprint);
58
+ for (records, 0..) |record, i| {
59
+ const at = 96 + i * 32;
60
+ wide(&request, at, record.id);
61
+ wide(&request, at + 8, record.fingerprint);
62
+ put(&request, at + 16, record.flags);
63
+ }
64
+ var output: [32]u8 = @splat(0xa5);
65
+ const length = policy(request[0 .. 96 + records.len * 32], &output);
66
+ const status = word(&output, 8);
67
+ const selected = word(&output, 12);
68
+ const action = word(&output, 16);
69
+ const next = word(&output, 20);
70
+ if (length != output.len or word(&output, 0) != 1 or word(&output, 4) != @intFromEnum(mode) or status > 4) @panic("invalid compiled image registry shape");
71
+ for (output[24..]) |byte| if (byte != 0) @panic("invalid compiled image registry padding");
72
+ const allowed: u32 = switch (mode) {
73
+ .register, .encoded => 1,
74
+ .lookup, .media_lookup => 0,
75
+ .remove => 2,
76
+ .repaint => 4,
77
+ .media_entry => 1 | 8 | 16 | 32,
78
+ .media_equal => 64,
79
+ .media_purge => 128,
80
+ };
81
+ if (action & ~allowed != 0 or (status != 0 and action != 0) or (status != 0 and mode != .register and mode != .encoded)) @panic("invalid compiled image registry admission");
82
+ if (selected != std.math.maxInt(u32) and (selected >= capacity or (selected >= records.len and !(selected == records.len and (mode == .register or (mode == .media_entry and action == 8)))))) @panic("invalid compiled image registry selection");
83
+ if (next != std.math.maxInt(u32) and (mode != .media_entry or action != 16 or next >= records.len)) @panic("invalid compiled image registry continuation");
84
+ if ((action == 2 or action == 4 or action == 32 or action == 128 or (mode == .register and status == 0)) and selected == std.math.maxInt(u32)) @panic("missing compiled image registry selection");
85
+ return .{ .status = status, .selected = if (selected == std.math.maxInt(u32)) null else selected, .action = action, .next = if (next == std.math.maxInt(u32)) null else next };
86
+ }
87
+ pub fn imageRecords(runtime: anytype, scratch: []Record) []const Record {
88
+ for (runtime.canvas_image_entries[0..runtime.canvas_image_count], 0..) |entry, i| scratch[i] = .{ .id = entry.id };
89
+ return scratch[0..runtime.canvas_image_count];
90
+ }
91
+ pub fn mediaRecords(runtime: anytype, scratch: []Record) []const Record {
92
+ for (runtime.media_surface_entries[0..runtime.media_surface_count], 0..) |entry, i| scratch[i] = .{ .id = entry.surface_id, .fingerprint = entry.fingerprint };
93
+ return scratch[0..runtime.media_surface_count];
94
+ }
@@ -0,0 +1,138 @@
1
+ //! Copies OS observations to the composition owner and installs its bounded
2
+ //! result. Raw event bytes and all retained storage remain native capabilities.
3
+ const std = @import("std");
4
+ const builtin = @import("builtin");
5
+ const platform = @import("../platform/root.zig");
6
+ const canvas = @import("canvas");
7
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
8
+ pub const Mode = enum(u8) { normalize, keys, resolve, routed, claim, fallback, buffer, retire, target, paste, escape, delivery, claim_probe, key_delivery };
9
+ pub const Facts = struct {
10
+ valid_view: bool = false,
11
+ owner_present: bool = false,
12
+ owner_kind: ?canvas.WidgetKind = null,
13
+ focused_kind: ?canvas.WidgetKind = null,
14
+ dismissed: bool = false,
15
+ composition_keys: bool = false,
16
+ claimed: bool = false,
17
+ focused: bool = false,
18
+ latch: bool = false,
19
+ grace: u8 = 0,
20
+ claim: u8 = 0,
21
+ owner: u64 = 0,
22
+ focused_id: u64 = 0,
23
+ routed_id: u64 = 0,
24
+ preedit_len: usize = 0,
25
+ preedit_window: u64 = 0,
26
+ preedit_label: []const u8 = "",
27
+ };
28
+ pub const Program = struct {
29
+ pointer: u32,
30
+ keyboard: u32,
31
+ edit: u32,
32
+ modifiers: u32,
33
+ decisions: u32,
34
+ owner: u64,
35
+ grace: u8,
36
+ claim: u8,
37
+ source: u32,
38
+ target: u64,
39
+ pub fn has(self: Program, bit: u32) bool {
40
+ return self.decisions & bit != 0;
41
+ }
42
+ pub fn keyboardModifiers(self: Program) canvas.WidgetKeyboardModifiers {
43
+ return .{ .shift = self.modifiers & 1 != 0, .control = self.modifiers & 2 != 0, .alt = self.modifiers & 4 != 0, .super = self.modifiers & 8 != 0 };
44
+ }
45
+ };
46
+ fn word(bytes: []const u8, at: usize) u32 {
47
+ return std.mem.readInt(u32, bytes[at..][0..4], .little);
48
+ }
49
+ fn wide(bytes: []const u8, at: usize) u64 {
50
+ return std.mem.readInt(u64, bytes[at..][0..8], .little);
51
+ }
52
+ pub fn resultValid(bytes: []const u8) bool {
53
+ return bytes.len == 64 and word(bytes, 0) == 1 and word(bytes, 4) <= 6 and word(bytes, 8) <= 2 and
54
+ word(bytes, 12) <= 4 and word(bytes, 16) <= 15 and word(bytes, 20) <= 32767 and
55
+ word(bytes, 32) <= 2 and word(bytes, 36) <= 2 and word(bytes, 40) <= 3 and
56
+ word(bytes, 44) == 0 and wide(bytes, 56) == 0;
57
+ }
58
+ pub fn plan(policy: Policy, mode: Mode, input: platform.GpuSurfaceInputEvent, facts: Facts) ?Program {
59
+ const callback = policy orelse return null;
60
+ var bytes: [256]u8 = @splat(0);
61
+ bytes[0..8].* = .{ 78, 1, @intFromEnum(mode), @intFromEnum(input.kind), modifiers(input.modifiers), @intFromBool(builtin.os.tag == .windows), facts.grace, facts.claim };
62
+ var flags: u32 = 0;
63
+ inline for (.{ "valid_view", "owner_present", "dismissed", "composition_keys", "claimed", "focused", "latch" }, 0..) |field, i|
64
+ flags |= @as(u32, @intFromBool(@field(facts, field))) << @intCast(i);
65
+ std.mem.writeInt(u32, bytes[8..12], flags, .little);
66
+ std.mem.writeInt(u32, bytes[12..16], if (facts.owner_kind) |kind| canvas.widgetKindCode(kind) else 63, .little);
67
+ std.mem.writeInt(u32, bytes[240..244], if (facts.focused_kind) |kind| canvas.widgetKindCode(kind) else 63, .little);
68
+ const fields = [_]u64{ input.key.len, input.text.len, input.window_id, facts.preedit_window, facts.owner, facts.focused_id, facts.routed_id, facts.preedit_len, input.label.len, facts.preedit_label.len };
69
+ for (fields, 0..) |value, i| std.mem.writeInt(u64, bytes[16 + i * 8 ..][0..8], value, .little);
70
+ const key_len = @min(input.key.len, 8);
71
+ @memcpy(bytes[96..][0..key_len], input.key[0..key_len]);
72
+ const text_len = @min(input.text.len, 2);
73
+ @memcpy(bytes[104..][0..text_len], input.text[0..text_len]);
74
+ const label_len = @min(input.label.len, 64);
75
+ @memcpy(bytes[112..][0..label_len], input.label[0..label_len]);
76
+ const pre_label_len = @min(facts.preedit_label.len, 64);
77
+ @memcpy(bytes[176..][0..pre_label_len], facts.preedit_label[0..pre_label_len]);
78
+ var output: [64]u8 = @splat(0xa5);
79
+ const length = callback(&bytes, &output);
80
+ if (length > output.len or !resultValid(output[0..length])) @panic("invalid compiled input composition result");
81
+ return .{ .pointer = word(&output, 4), .keyboard = word(&output, 8), .edit = word(&output, 12), .modifiers = word(&output, 16), .decisions = word(&output, 20), .owner = wide(&output, 24), .grace = @intCast(word(&output, 32)), .claim = @intCast(word(&output, 36)), .source = word(&output, 40), .target = wide(&output, 48) };
82
+ }
83
+ fn modifiers(m: platform.ShortcutModifiers) u8 {
84
+ return @as(u8, @intFromBool(m.shift)) | (@as(u8, @intFromBool(m.control)) << 1) | (@as(u8, @intFromBool(m.option)) << 2) | (@as(u8, @intFromBool(m.command)) << 3) | (@as(u8, @intFromBool(m.primary)) << 4);
85
+ }
86
+ pub fn observations(runtime: anytype, view: anytype) Facts {
87
+ const tree = view.widgetLayoutTree();
88
+ const owner = if (view.canvas_widget_ime_owner_id != 0) tree.findById(view.canvas_widget_ime_owner_id) else null;
89
+ const focused = if (view.canvas_widget_focused_id != 0) tree.findById(view.canvas_widget_focused_id) else null;
90
+ return .{ .valid_view = view.kind == .gpu_surface, .owner_present = owner != null, .owner_kind = if (owner) |node| node.widget.kind else null, .focused_kind = if (focused) |node| node.widget.kind else null, .owner = view.canvas_widget_ime_owner_id, .grace = @intFromEnum(view.canvas_widget_ime_commit_grace), .claim = @intFromEnum(view.canvas_widget_claimed_key_grace), .focused_id = view.canvas_widget_focused_id, .focused = view.focused, .preedit_len = runtime.targetless_ime_preedit_len, .preedit_window = runtime.targetless_ime_preedit_window, .preedit_label = runtime.targetless_ime_preedit_label[0..runtime.targetless_ime_preedit_label_len], .latch = runtime.targetless_ime_commit_grace };
91
+ }
92
+ pub fn installWidget(view: anytype, program: Program) void {
93
+ view.canvas_widget_ime_owner_id = program.owner;
94
+ view.canvas_widget_ime_commit_grace = @enumFromInt(program.grace);
95
+ view.canvas_widget_claimed_key_grace = @enumFromInt(program.claim);
96
+ }
97
+ pub fn pointerEvent(program: Program, input: platform.GpuSurfaceInputEvent) ?canvas.WidgetPointerEvent {
98
+ const phase: canvas.WidgetPointerPhase = switch (program.pointer) {
99
+ 0 => return null,
100
+ 1 => .down,
101
+ 2 => .up,
102
+ 3 => .cancel,
103
+ 4 => .hover,
104
+ 5 => .move,
105
+ 6 => .wheel,
106
+ else => unreachable,
107
+ };
108
+ return .{ .phase = phase, .point = .{ .x = input.x, .y = input.y }, .delta = .{ .dx = input.delta_x, .dy = input.delta_y }, .scroll_is_detented = input.scroll_is_detented, .pointer_id = input.pointer_id, .button = input.button, .modifiers = program.keyboardModifiers() };
109
+ }
110
+ pub fn keyboardEvent(program: Program, input: platform.GpuSurfaceInputEvent, focused_id: u64, text: bool) ?canvas.WidgetKeyboardEvent {
111
+ const edit: ?canvas.TextInputEvent = switch (program.edit) {
112
+ 0 => null,
113
+ 1 => .{ .insert_text = input.text },
114
+ 2 => .{ .set_composition = .{ .text = input.text, .cursor = input.composition_cursor } },
115
+ 3 => .commit_composition,
116
+ 4 => .cancel_composition,
117
+ else => unreachable,
118
+ };
119
+ const phase: canvas.WidgetKeyboardPhase = if (text) if (edit != null) .text_input else return null else switch (program.keyboard) {
120
+ 0 => return null,
121
+ 1 => .key_down,
122
+ 2 => .key_up,
123
+ else => unreachable,
124
+ };
125
+ return .{ .phase = phase, .focused_id = focused_id, .key = input.key, .text = input.text, .edit = if (text) edit else null, .modifiers = program.keyboardModifiers() };
126
+ }
127
+
128
+ test "input composition transport rejects incomplete results and unclaimed fields" {
129
+ var bytes: [64]u8 = @splat(0);
130
+ std.mem.writeInt(u32, bytes[0..4], 1, .little);
131
+ try std.testing.expect(resultValid(&bytes));
132
+ for (0..bytes.len) |len| try std.testing.expect(!resultValid(bytes[0..len]));
133
+ for ([_]usize{ 0, 4, 8, 12, 16, 20, 32, 36, 40, 44, 56, 60 }) |at| {
134
+ var bad = bytes;
135
+ std.mem.writeInt(u32, bad[at..][0..4], 0xffffffff, .little);
136
+ try std.testing.expect(!resultValid(&bad));
137
+ }
138
+ }
@@ -0,0 +1,66 @@
1
+ //! Copied journal framing and sequencing decisions. Payload codecs, borrowed
2
+ //! byte storage, and sink I/O remain native capabilities.
3
+ const std = @import("std");
4
+ pub const Policy = ?*const fn ([]const u8, []u8) usize;
5
+ pub const Stage = enum(u8) { init, frame, next, seal, preamble };
6
+ pub const Action = enum(u8) { proceed, bad_magic, format_mismatch, truncated, corrupt, over_budget, missing_header, count_mismatch, done };
7
+ pub const Facts = struct {
8
+ header: bool = false,
9
+ ended: bool = false,
10
+ kind: u8 = 0,
11
+ a: u64 = 0,
12
+ b: u64 = 0,
13
+ fingerprint: u64 = 0,
14
+ counts: [5]u64 = @splat(0),
15
+ sealed: [5]u64 = @splat(0),
16
+ sample: []const u8 = "",
17
+ limit: u64 = 0,
18
+ };
19
+ pub const Plan = struct {
20
+ action: Action = .proceed,
21
+ kind: u8 = 0,
22
+ length: u32 = 0,
23
+ pos: u64 = 0,
24
+ counts: [5]u64 = @splat(0),
25
+ frame: [5]u8 = @splat(0),
26
+ preamble: [16]u8 = @splat(0),
27
+ };
28
+ pub fn plan(policy: Policy, stage: Stage, facts: Facts) Plan {
29
+ const callback = policy orelse return @import("journal_reference.zig").plan(stage, facts);
30
+ std.debug.assert(facts.sample.len <= 16);
31
+ var input: [160]u8 = @splat(0);
32
+ input[0..4].* = .{ 26, @intFromEnum(stage), @as(u8, @intFromBool(facts.header)) | (@as(u8, @intFromBool(facts.ended)) << 1), facts.kind };
33
+ inline for (.{ facts.a, facts.b, facts.fingerprint }, 0..) |value, i| std.mem.writeInt(u64, input[8 + i * 8 ..][0..8], value, .little);
34
+ for (facts.counts, 0..) |value, i| std.mem.writeInt(u64, input[32 + i * 8 ..][0..8], value, .little);
35
+ for (facts.sealed, 0..) |value, i| std.mem.writeInt(u64, input[72 + i * 8 ..][0..8], value, .little);
36
+ @memcpy(input[112..][0..facts.sample.len], facts.sample);
37
+ std.mem.writeInt(u64, input[128..136], facts.limit, .little);
38
+ var output: [80]u8 = undefined;
39
+ if (callback(&input, &output) != output.len or output[0] > 8 or output[1] > 7 or
40
+ !std.mem.allEqual(u8, output[2..4], 0) or !std.mem.allEqual(u8, output[61..64], 0)) @panic("invalid compiled journal plan");
41
+ var result: Plan = .{
42
+ .action = @enumFromInt(output[0]),
43
+ .kind = output[1],
44
+ .length = std.mem.readInt(u32, output[4..8], .little),
45
+ .pos = std.mem.readInt(u64, output[8..16], .little),
46
+ .frame = output[56..61].*,
47
+ .preamble = output[64..80].*,
48
+ };
49
+ for (&result.counts, 0..) |*value, i| value.* = std.mem.readInt(u64, output[16 + i * 8 ..][0..8], .little);
50
+ const valid_action = switch (stage) {
51
+ .init => result.action == .proceed or result.action == .bad_magic or result.action == .format_mismatch,
52
+ .frame => result.action == .proceed or result.action == .over_budget,
53
+ .next => result.action == .proceed or result.action == .truncated or result.action == .corrupt or result.action == .over_budget or result.action == .missing_header or result.action == .done,
54
+ .seal => result.action == .proceed or result.action == .count_mismatch,
55
+ .preamble => result.action == .proceed,
56
+ };
57
+ if (!valid_action or (stage != .next and (result.kind != 0 or result.length != 0)) or
58
+ (stage != .frame and !std.mem.allEqual(u8, &result.frame, 0)) or
59
+ (stage != .preamble and !std.mem.allEqual(u8, &result.preamble, 0))) @panic("invalid compiled journal stage result");
60
+ if (stage == .next and (result.pos < facts.b or result.pos > facts.a or
61
+ (result.kind == 0 and result.action == .proceed) or
62
+ (result.kind != 0 and (result.length > facts.limit or result.pos - facts.b != 5 + @as(u64, result.length)))))
63
+ @panic("invalid compiled journal frame bounds");
64
+ if (stage == .init and result.action == .proceed and result.pos != 16) @panic("invalid compiled journal preamble bounds");
65
+ return result;
66
+ }