@native-sdk/cli 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (465) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +1818 -87
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
  130. package/skill-data/native-ui/SKILL.md +76 -17
  131. package/skill-data/ts-core/SKILL.md +113 -9
  132. package/skill-data/ts-services/SKILL.md +1 -1
  133. package/skill-data/ts-services/references/service-surface.md +264 -144
  134. package/src/app_runner/root.zig +25 -12
  135. package/src/app_runner/ts_compiled_view.zig +1631 -0
  136. package/src/app_runner/ts_core_main.zig +143 -10
  137. package/src/app_runner/ts_core_mobile.zig +24 -12
  138. package/src/automation/server.zig +1 -3
  139. package/src/automation/snapshot.zig +9 -637
  140. package/src/automation/snapshot_reference.zig +656 -0
  141. package/src/automation/snapshot_serialization.zig +566 -0
  142. package/src/platform/linux/gtk_host.c +36 -24
  143. package/src/platform/linux/gtk_pixels.h +118 -0
  144. package/src/platform/linux/gtk_pixels_test.c +241 -0
  145. package/src/platform/linux/root.zig +2 -0
  146. package/src/platform/macos/appkit_host.m +188 -30
  147. package/src/platform/macos/pointer_motion_test.m +96 -0
  148. package/src/platform/macos/scroll_driver_test.m +105 -0
  149. package/src/platform/macos/spectrum_bins.h +34 -0
  150. package/src/platform/macos/spectrum_bins_test.c +56 -0
  151. package/src/platform/macos/text_keyboard_test.m +80 -0
  152. package/src/platform/macos/widget_focus_test.m +66 -0
  153. package/src/platform/null_platform.zig +26 -2
  154. package/src/platform/null_platform_tests.zig +13 -0
  155. package/src/platform/root.zig +1 -0
  156. package/src/platform/types.zig +13 -0
  157. package/src/platform/windows/root.zig +2 -0
  158. package/src/platform/windows/webview2_host.cpp +7 -2
  159. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  160. package/src/primitives/app_manifest/root.zig +2 -0
  161. package/src/primitives/app_manifest/tests.zig +4 -1
  162. package/src/primitives/app_manifest/validation.zig +2 -0
  163. package/src/primitives/canvas/a11y_audit.zig +3 -1
  164. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  165. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  166. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  167. package/src/primitives/canvas/code_content_policy.zig +162 -0
  168. package/src/primitives/canvas/commands.zig +29 -1
  169. package/src/primitives/canvas/component_composition.zig +125 -0
  170. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  171. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  172. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  173. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  174. package/src/primitives/canvas/control_command_policy.zig +75 -0
  175. package/src/primitives/canvas/control_content_policy.zig +90 -0
  176. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  177. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  178. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  179. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  180. package/src/primitives/canvas/events.zig +1027 -1
  181. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  182. package/src/primitives/canvas/frame.zig +92 -23
  183. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  184. package/src/primitives/canvas/gpu.zig +10 -0
  185. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  186. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  187. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  188. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  189. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  190. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  191. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  192. package/src/primitives/canvas/layout_audit.zig +5 -2
  193. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  194. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  195. package/src/primitives/canvas/markdown.zig +13 -3
  196. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  197. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  198. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  199. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  200. package/src/primitives/canvas/reference.zig +12 -6
  201. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  202. package/src/primitives/canvas/render.zig +48 -0
  203. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  204. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  205. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  206. package/src/primitives/canvas/render_effects.zig +14 -0
  207. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  208. package/src/primitives/canvas/render_images.zig +14 -0
  209. package/src/primitives/canvas/render_layers.zig +14 -0
  210. package/src/primitives/canvas/render_override_policy.zig +119 -0
  211. package/src/primitives/canvas/render_paths.zig +14 -0
  212. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  213. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  214. package/src/primitives/canvas/root.zig +100 -0
  215. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  216. package/src/primitives/canvas/serialization.zig +8 -1
  217. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  218. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  219. package/src/primitives/canvas/terminal_grid.zig +10 -696
  220. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  221. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  222. package/src/primitives/canvas/text.zig +1 -0
  223. package/src/primitives/canvas/text_atlas.zig +113 -0
  224. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  225. package/src/primitives/canvas/text_document_policy.zig +120 -0
  226. package/src/primitives/canvas/text_layout.zig +51 -2
  227. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  228. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  229. package/src/primitives/canvas/text_layout_types.zig +3 -0
  230. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  231. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  232. package/src/primitives/canvas/text_metrics.zig +23 -0
  233. package/src/primitives/canvas/text_query_policy.zig +156 -0
  234. package/src/primitives/canvas/text_run_policy.zig +252 -0
  235. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  236. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  237. package/src/primitives/canvas/text_spans.zig +280 -8
  238. package/src/primitives/canvas/text_tests.zig +10 -0
  239. package/src/primitives/canvas/tokens.zig +38 -0
  240. package/src/primitives/canvas/ui.zig +250 -83
  241. package/src/primitives/canvas/ui_markup.zig +139 -33
  242. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  243. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  244. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  245. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  246. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  247. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  248. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  249. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  250. package/src/primitives/canvas/ui_schema.zig +13 -1
  251. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  252. package/src/primitives/canvas/ui_tests.zig +1 -0
  253. package/src/primitives/canvas/vector.zig +36 -2
  254. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  255. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  256. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  257. package/src/primitives/canvas/virtual_extents.zig +99 -3
  258. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  259. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  260. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  261. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  262. package/src/primitives/canvas/widget_layout.zig +673 -128
  263. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  264. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  265. package/src/primitives/canvas/widget_metrics.zig +45 -6
  266. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  267. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  268. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  269. package/src/primitives/canvas/widget_render.zig +744 -74
  270. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  271. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  272. package/src/primitives/canvas/widget_render_style.zig +94 -0
  273. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  274. package/src/primitives/canvas/widget_routing.zig +75 -0
  275. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  276. package/src/primitives/canvas/widget_runtime.zig +20 -1
  277. package/src/primitives/canvas/widget_semantics.zig +25 -0
  278. package/src/primitives/canvas/widget_text_input.zig +86 -23
  279. package/src/primitives/canvas/widget_text_select.zig +1 -0
  280. package/src/primitives/canvas/widget_tree.zig +8 -1
  281. package/src/primitives/canvas/widgets.zig +42 -12
  282. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  283. package/src/root.zig +21 -0
  284. package/src/runtime/accessibility_policy.zig +122 -0
  285. package/src/runtime/api.zig +28 -0
  286. package/src/runtime/app_dispatch_policy.zig +68 -0
  287. package/src/runtime/authorization_policy.zig +150 -0
  288. package/src/runtime/automation_command_policy.zig +241 -0
  289. package/src/runtime/automation_interaction_policy.zig +107 -0
  290. package/src/runtime/automation_snapshot.zig +52 -22
  291. package/src/runtime/automation_snapshot_reference.zig +290 -0
  292. package/src/runtime/automation_widget_dispatch.zig +267 -355
  293. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  294. package/src/runtime/blob_policy.zig +58 -0
  295. package/src/runtime/blob_reference.zig +64 -0
  296. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  297. package/src/runtime/builtin_bridge.zig +180 -44
  298. package/src/runtime/builtin_coordination_policy.zig +121 -0
  299. package/src/runtime/callback_policy_test_reference.zig +97 -0
  300. package/src/runtime/canvas_drag_policy.zig +94 -0
  301. package/src/runtime/canvas_fonts.zig +38 -10
  302. package/src/runtime/canvas_frame.zig +590 -134
  303. package/src/runtime/canvas_frame_helpers.zig +1 -0
  304. package/src/runtime/canvas_hover_policy.zig +131 -0
  305. package/src/runtime/canvas_images.zig +59 -30
  306. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  307. package/src/runtime/canvas_limits.zig +1 -1
  308. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  309. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  310. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  311. package/src/runtime/canvas_widget_display.zig +110 -9
  312. package/src/runtime/canvas_widget_events.zig +718 -328
  313. package/src/runtime/canvas_widget_runtime.zig +437 -81
  314. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  315. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  316. package/src/runtime/canvas_widget_state.zig +93 -56
  317. package/src/runtime/channel_sources.zig +80 -0
  318. package/src/runtime/command_policy.zig +161 -0
  319. package/src/runtime/component_policy.zig +83 -0
  320. package/src/runtime/core.zig +156 -6
  321. package/src/runtime/desktop_files.zig +189 -0
  322. package/src/runtime/effects.zig +466 -29
  323. package/src/runtime/effects_tests.zig +28 -0
  324. package/src/runtime/file_policy_test_reference.zig +113 -0
  325. package/src/runtime/flow.zig +418 -341
  326. package/src/runtime/flow_reference.zig +1426 -0
  327. package/src/runtime/font_registry_policy.zig +72 -0
  328. package/src/runtime/frame_profile.zig +24 -33
  329. package/src/runtime/gpu_surface_events.zig +97 -35
  330. package/src/runtime/host_event_pump.zig +303 -0
  331. package/src/runtime/host_event_pump_reference.zig +268 -0
  332. package/src/runtime/host_flow_policy.zig +155 -0
  333. package/src/runtime/host_input_regions_policy.zig +156 -0
  334. package/src/runtime/image_registry_policy.zig +94 -0
  335. package/src/runtime/input_composition_policy.zig +138 -0
  336. package/src/runtime/journal_policy.zig +66 -0
  337. package/src/runtime/journal_reference.zig +53 -0
  338. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  339. package/src/runtime/markup_development_policy.zig +91 -0
  340. package/src/runtime/media_surface.zig +40 -1
  341. package/src/runtime/motion_sampling_policy.zig +159 -0
  342. package/src/runtime/recording_policy.zig +42 -0
  343. package/src/runtime/render_animation_policy.zig +206 -0
  344. package/src/runtime/replay_policy.zig +66 -0
  345. package/src/runtime/replay_policy_reference.zig +326 -0
  346. package/src/runtime/replay_progress_policy.zig +64 -0
  347. package/src/runtime/replay_progress_reference.zig +34 -0
  348. package/src/runtime/request_policy_test_reference.zig +188 -0
  349. package/src/runtime/root.zig +13 -0
  350. package/src/runtime/session_blobs.zig +157 -58
  351. package/src/runtime/session_blobs_reference.zig +692 -0
  352. package/src/runtime/session_codec.zig +361 -0
  353. package/src/runtime/session_codec_reference.zig +1027 -0
  354. package/src/runtime/session_journal.zig +246 -983
  355. package/src/runtime/session_record.zig +224 -45
  356. package/src/runtime/session_replay.zig +157 -415
  357. package/src/runtime/session_tests.zig +552 -0
  358. package/src/runtime/shell_admission_policy.zig +225 -0
  359. package/src/runtime/shell_coordination_policy.zig +138 -0
  360. package/src/runtime/shell_layout.zig +126 -1
  361. package/src/runtime/snapshot_policy.zig +60 -0
  362. package/src/runtime/snapshot_reference.zig +64 -0
  363. package/src/runtime/state.zig +16 -0
  364. package/src/runtime/status_validation.zig +190 -0
  365. package/src/runtime/system_admission_policy.zig +140 -0
  366. package/src/runtime/system_services.zig +46 -36
  367. package/src/runtime/tests.zig +1 -0
  368. package/src/runtime/ts_canvas_hooks.zig +261 -0
  369. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  370. package/src/runtime/ts_canvas_icons.zig +234 -0
  371. package/src/runtime/ts_core_host.zig +2325 -411
  372. package/src/runtime/ts_core_host_tests.zig +1982 -0
  373. package/src/runtime/ts_test_host.zig +699 -0
  374. package/src/runtime/ts_ui_app.zig +1087 -45
  375. package/src/runtime/ui_app.zig +1117 -629
  376. package/src/runtime/ui_app_provenance.zig +147 -5
  377. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  378. package/src/runtime/ui_app_tests.zig +619 -9
  379. package/src/runtime/ui_app_window_tests.zig +89 -0
  380. package/src/runtime/view.zig +25 -0
  381. package/src/runtime/view_canvas.zig +30 -6
  382. package/src/runtime/view_coordination_policy.zig +147 -0
  383. package/src/runtime/view_widget_control.zig +51 -14
  384. package/src/runtime/view_widget_scroll.zig +16 -5
  385. package/src/runtime/view_widget_text.zig +153 -68
  386. package/src/runtime/view_widget_tree.zig +460 -56
  387. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  388. package/src/runtime/widget_motion_policy.zig +238 -0
  389. package/src/runtime/window_command_bridge_tests.zig +63 -0
  390. package/src/runtime/window_lifecycle_policy.zig +127 -0
  391. package/src/runtime/window_storage.zig +74 -8
  392. package/src/runtime/window_view_runtime.zig +148 -33
  393. package/src/runtime/window_views.zig +163 -10
  394. package/src/tooling/codesign.zig +125 -74
  395. package/src/tooling/components/identity_tests.zig +62 -36
  396. package/src/tooling/components/stepper.native +24 -0
  397. package/src/tooling/components/stepper.zig +0 -19
  398. package/src/tooling/components/timeline-item.native +22 -0
  399. package/src/tooling/components/timeline.native +5 -3
  400. package/src/tooling/components/timeline_item.zig +0 -32
  401. package/src/tooling/eject_components.zig +76 -8
  402. package/src/tooling/ios.zig +66 -12
  403. package/src/tooling/manifest.zig +35 -0
  404. package/src/tooling/package.zig +85 -1
  405. package/src/tooling/raw_manifest.zig +6 -0
  406. package/src/tooling/templates.zig +15 -3
  407. package/src/tooling/ts_core.zig +13 -3
  408. package/src/tooling/verbs.zig +22 -0
  409. package/tools/corewire/build_profile.mjs +54 -0
  410. package/tools/corewire/contract_intake.ts +303 -0
  411. package/tools/corewire/contract_intake.zig +82 -0
  412. package/tools/corewire/core.test.ts +166 -0
  413. package/tools/corewire/core_abi.zig +51 -0
  414. package/tools/corewire/core_cases.ts +233 -0
  415. package/tools/corewire/core_contract.ts +407 -0
  416. package/tools/corewire/core_emission.ts +136 -0
  417. package/tools/corewire/core_emission.zig +69 -0
  418. package/tools/corewire/core_goldens.json +3110 -0
  419. package/tools/corewire/core_policy.ts +14 -0
  420. package/tools/corewire/core_policy.zig +48 -0
  421. package/tools/corewire/core_projection.ts +360 -0
  422. package/tools/corewire/core_vocabulary.ts +6 -0
  423. package/tools/corewire/emit.zig +19 -1590
  424. package/tools/corewire/emit_facade.ts +714 -0
  425. package/tools/corewire/emit_facade.zig +10 -3752
  426. package/tools/corewire/emit_mirror.ts +290 -0
  427. package/tools/corewire/emit_profile.ts +50 -0
  428. package/tools/corewire/emit_service.ts +331 -0
  429. package/tools/corewire/emit_service.zig +23 -842
  430. package/tools/corewire/entry.test.ts +95 -0
  431. package/tools/corewire/entry_coordination.ts +127 -0
  432. package/tools/corewire/entry_coordination.zig +190 -0
  433. package/tools/corewire/facade_templates.ts +85 -0
  434. package/tools/corewire/filesystem.test.ts +166 -0
  435. package/tools/corewire/filesystem_coordination.ts +213 -0
  436. package/tools/corewire/filesystem_coordination.zig +245 -0
  437. package/tools/corewire/intake.test.ts +35 -0
  438. package/tools/corewire/intake_cases.ts +55 -0
  439. package/tools/corewire/intake_goldens.json +12237 -0
  440. package/tools/corewire/invocation.test.ts +24 -0
  441. package/tools/corewire/invocation.ts +175 -0
  442. package/tools/corewire/invocation.zig +136 -0
  443. package/tools/corewire/invocation_cases.ts +60 -0
  444. package/tools/corewire/invocation_fixture.ts +33 -0
  445. package/tools/corewire/invocation_goldens.json +1143 -0
  446. package/tools/corewire/invocation_tests.zig +111 -0
  447. package/tools/corewire/invocation_usage.ts +2 -0
  448. package/tools/corewire/lossless_projection.ts +96 -0
  449. package/tools/corewire/main.zig +7 -680
  450. package/tools/corewire/main_reference.zig +415 -0
  451. package/tools/corewire/mirror_templates.ts +55 -0
  452. package/tools/corewire/profile.test.ts +248 -0
  453. package/tools/corewire/profile.zig +56 -0
  454. package/tools/corewire/profile_emission.ts +202 -0
  455. package/tools/corewire/profile_library.json +29 -0
  456. package/tools/corewire/profile_tests.zig +136 -0
  457. package/tools/corewire/service.test.ts +75 -0
  458. package/tools/corewire/service_cases.ts +61 -0
  459. package/tools/corewire/service_contract.zig +40 -146
  460. package/tools/corewire/service_goldens.json +650 -0
  461. package/tools/corewire/service_projection.zig +52 -0
  462. package/tools/corewire/service_templates.ts +14 -0
  463. package/tools/corewire/shim_rt.zig +9 -0
  464. package/tools/corewire/sidecar.zig +267 -1438
  465. package/tools/corewire/emit_profile.zig +0 -521
@@ -0,0 +1,14 @@
1
+ import { validateCore } from "./core_contract.ts";
2
+ import type { CoreInput, Diagnostic } from "./core_contract.ts";
3
+ import { projectionPlan, validateMirror, validateFacade } from "./core_projection.ts";
4
+
5
+ export function evaluateCorePolicy(input: string, phase: string): string {
6
+ const facts = JSON.parse(input) as CoreInput;
7
+ const plan = projectionPlan(facts.sidecar);
8
+ let diagnostics: Diagnostic[] = [];
9
+ if (phase === "core") diagnostics = validateCore(facts);
10
+ else if (phase === "mirror") diagnostics = validateMirror(facts.sidecar);
11
+ else if (phase === "facade") diagnostics = validateFacade(facts.sidecar, plan);
12
+ else if (phase !== "plan") throw new Error("unknown core policy phase");
13
+ return JSON.stringify({ diagnostics, inlined: plan.inlined, flattened: plan.flattened, node_stored: plan.node_stored });
14
+ }
@@ -0,0 +1,48 @@
1
+ //! Owned result boundary to the compiled core-contract policy.
2
+ const std = @import("std");
3
+ const PanicSink = *const fn (?*anyopaque, [*]const u8, usize, u64) callconv(.c) void;
4
+ extern fn nsc_profile_set_panic_sink(PanicSink, ?*anyopaque) void;
5
+ extern fn nsc_profile_init() void;
6
+ extern fn nsc_profile_collect() void;
7
+ extern fn nsc_profile_core_policy([*]const u8, usize, [*]const u8, usize, *[*]const u8, *usize) void;
8
+
9
+ pub const Result = struct {
10
+ diagnostics: []const struct { path: []const u8, message: []const u8 },
11
+ inlined: []const []const u8,
12
+ flattened: []const []const u8,
13
+ node_stored: []const []const u8,
14
+ };
15
+
16
+ fn panicSink(_: ?*anyopaque, message: [*]const u8, len: usize, _: u64) callconv(.c) void {
17
+ std.debug.print("corewire: core contract policy trapped: {s}\n", .{message[0..len]});
18
+ std.process.exit(1);
19
+ }
20
+
21
+ pub fn evaluate(arena: std.mem.Allocator, sidecar: anytype, phase: []const u8) error{OutOfMemory}!Result {
22
+ // A native i64 diagnostic must retain its exact spelling beyond 2^53.
23
+ // TypeRef/Payload serializers carry the decoder's complete shape.
24
+ const input = try std.json.Stringify.valueAlloc(arena, .{
25
+ .sidecar = sidecar,
26
+ .wire_text = try std.fmt.allocPrint(arena, "{d}", .{sidecar.wire_version}),
27
+ .abi_text = try std.fmt.allocPrint(arena, "{d}", .{sidecar.abi_version}),
28
+ .snapshot_text = try std.fmt.allocPrint(arena, "{d}", .{sidecar.abi.snapshot_format}),
29
+ }, .{});
30
+ nsc_profile_set_panic_sink(panicSink, null);
31
+ nsc_profile_init();
32
+ defer nsc_profile_collect();
33
+ var ptr: [*]const u8 = undefined;
34
+ var len: usize = 0;
35
+ nsc_profile_core_policy(input.ptr, input.len, phase.ptr, phase.len, &ptr, &len);
36
+ // Own every nested string before collect, including plan names and
37
+ // diagnostics retained by the caller across subsequent init cycles.
38
+ return std.json.parseFromSliceLeaky(Result, arena, ptr[0..len], .{ .allocate = .alloc_always }) catch |err| switch (err) {
39
+ error.OutOfMemory => return error.OutOfMemory,
40
+ else => @panic("corewire: malformed compiled core policy result"),
41
+ };
42
+ }
43
+
44
+ pub fn apply(arena: std.mem.Allocator, sidecar: anytype, phase: []const u8, diags: anytype) error{OutOfMemory}!Result {
45
+ const result = try evaluate(arena, sidecar, phase);
46
+ for (result.diagnostics) |diagnostic| diags.flag(diagnostic.path, "{s}", .{diagnostic.message});
47
+ return result;
48
+ }
@@ -0,0 +1,360 @@
1
+ // Shared layout planning and admission rules for the two core projections.
2
+ import { findRecord, findEnum, findUnion, findArm, flag, walkRefs, usesVirtualExtentHelpers } from "./core_contract.ts";
3
+ import type { CoreContract, TypeRef, Payload, RecordType, Diagnostic } from "./core_contract.ts";
4
+ import { tsReservedWords, fixedExports, ambientValues, zigKeywords, zigPrimitives } from "./core_vocabulary.ts";
5
+
6
+ export interface ProjectionPlan { inlined: string[]; flattened: string[]; node_stored: string[] }
7
+ function innermost(ref: TypeRef): TypeRef {
8
+ while (ref.kind === "optional" || ref.kind === "slice") ref = ref.kind === "optional" ? ref.inner! : ref.elem!;
9
+ return ref;
10
+ }
11
+ function synthesized(container: string, member: string, name: string): boolean { return name === container + "_" + member; }
12
+ function note(names: string[], name: string): void { if (!names.includes(name)) names.push(name); }
13
+ function refCount(ref: TypeRef, name: string): number {
14
+ const r = innermost(ref);
15
+ return ["node", "value", "enum", "union"].includes(r.kind) && r.name === name ? 1 : 0;
16
+ }
17
+ function referenceCount(s: CoreContract, name: string): number {
18
+ let count = s.model === name ? 1 : 0;
19
+ walkRefs(s, (ref) => { count += refCount(ref, name); });
20
+ for (const a of s.msg.arms) if (["record", "union_ref", "enum_ref"].includes(a.payload.kind) && a.payload.name === name) count++;
21
+ return count;
22
+ }
23
+ function candidate(candidates: string[], container: string, member: string, ref: TypeRef): void {
24
+ const r = innermost(ref);
25
+ if (r.kind === "value" && synthesized(container, member, r.name!)) candidates.push(r.name!);
26
+ }
27
+ function flattenedRecord(s: CoreContract, plan: ProjectionPlan, ref: TypeRef, container: string, member: string): RecordType | null {
28
+ if (ref.kind !== "value" || !synthesized(container, member, ref.name!) || !plan.inlined.includes(ref.name!)) return null;
29
+ const record = findRecord(s, ref.name!);
30
+ return record !== null && record.origin === null ? record : null;
31
+ }
32
+ function payloadRef(p: Payload): TypeRef { return { kind: "value", name: p.name! }; }
33
+ function storedNodes(s: CoreContract, scalarMessages: boolean): string[] {
34
+ const names: string[] = [s.model];
35
+ walkRefs(s, (ref, at) => {
36
+ if (!scalarMessages && at.startsWith("msg.arms[")) return;
37
+ const r = innermost(ref);
38
+ if (r.kind === "node") note(names, r.name!);
39
+ });
40
+ return names;
41
+ }
42
+ export function projectionPlan(s: CoreContract): ProjectionPlan {
43
+ const plan: ProjectionPlan = { inlined: [], flattened: [], node_stored: storedNodes(s, true) };
44
+ const candidates: string[] = [];
45
+ for (const r of s.types.structs) for (const f of r.fields) candidate(candidates, r.name, f.name, f.type);
46
+ for (const u of s.types.unions) for (const a of u.arms) candidate(candidates, u.name, a.name, a.payload);
47
+ for (const a of s.msg.arms) if (a.payload.kind === "record" && synthesized(s.msg.name, a.name, a.payload.name!)) candidates.push(a.payload.name!);
48
+ for (const name of candidates) {
49
+ const r = findRecord(s, name);
50
+ if (referenceCount(s, name) === 1 && r !== null && r.origin === null && r.fields.length >= 2) plan.inlined.push(name);
51
+ }
52
+ for (const a of s.msg.arms) if (a.payload.kind === "record") {
53
+ const r = flattenedRecord(s, plan, payloadRef(a.payload), s.msg.name, a.name);
54
+ if (r !== null) plan.flattened.push(r.name);
55
+ }
56
+ for (const u of s.types.unions) for (const a of u.arms) {
57
+ const r = flattenedRecord(s, plan, a.payload, u.name, a.name);
58
+ if (r !== null) plan.flattened.push(r.name);
59
+ }
60
+ return plan;
61
+ }
62
+ function tableNames(s: CoreContract): string[] {
63
+ const out: string[] = [];
64
+ for (const r of s.types.structs) out.push(r.name);
65
+ for (const e of s.types.enums) out.push(e.name);
66
+ for (const u of s.types.unions) out.push(u.name);
67
+ return out;
68
+ }
69
+ function numeric(ref: TypeRef): boolean { return ref.kind === "f64" || ref.kind === "i64"; }
70
+ function valueRecord(s: CoreContract, ref: TypeRef): RecordType | null { return ref.kind === "value" ? findRecord(s, ref.name!) : null; }
71
+ function numericRecord(s: CoreContract, ref: TypeRef, names: string[]): boolean {
72
+ const r = valueRecord(s, ref);
73
+ if (r === null || r.fields.length !== names.length) return false;
74
+ for (const name of names) if (!r.fields.some(f => f.name === name && numeric(f.type))) return false;
75
+ return true;
76
+ }
77
+ function channelRecord(s: CoreContract, name: string): RecordType | null {
78
+ const a = findArm(s, name);
79
+ return a !== null && a.payload.kind === "record" ? findRecord(s, a.payload.name!) : null;
80
+ }
81
+ function appearanceRecord(s: CoreContract, r: RecordType): boolean {
82
+ if (r.fields.length !== 3) return false;
83
+ let scheme = false, reduce = false, contrast = false;
84
+ for (const f of r.fields) {
85
+ if (f.name === "colorScheme") {
86
+ const e = f.type.kind === "enum" ? findEnum(s, f.type.name!) : null;
87
+ if (e === null || e.members.length !== 2) return false;
88
+ scheme = e.members.includes("light") && e.members.includes("dark");
89
+ } else if (f.name === "reduceMotion") reduce = f.type.kind === "bool";
90
+ else if (f.name === "highContrast") contrast = f.type.kind === "bool";
91
+ }
92
+ return scheme && reduce && contrast;
93
+ }
94
+ function chromeRecord(s: CoreContract, r: RecordType): boolean {
95
+ if (r.fields.length !== 3) return false;
96
+ let insets = false, buttons = false, tabs = false;
97
+ for (const f of r.fields) {
98
+ if (f.name === "insets") insets = numericRecord(s, f.type, ["top", "right", "bottom", "left"]);
99
+ else if (f.name === "buttons") buttons = numericRecord(s, f.type, ["x", "y", "width", "height"]);
100
+ else if (f.name === "tabsProjected") tabs = f.type.kind === "bool";
101
+ }
102
+ return insets && buttons && tabs;
103
+ }
104
+ function mirrorNames(s: CoreContract, out: Diagnostic[]): void {
105
+ const reserved = ["bootCommand", "decoded_model", "RuntimeModel", "RuntimeResult", "runtime_model", "initialRuntimeModel", "updateRuntimeModel", "commitRuntimeModel", "restoreRuntimeModel", "restoreCommittedModel", "runtimeSubscriptions", "runtimeFrameMsg", "dispatchMessage", "std", "shim_rt", "core_abi", "abi", "rt", "msg_tags", "boot", "initialModel", "update", "commitModelRoot", "sidecar_build_id", "sidecar_model_fingerprint", "sidecar_abi_version", "sidecar_snapshot_format", "deterministic", "async_free", "snapshotModel", "modelSnapshot", "persistenceSnapshot", "restoreModel", "referenceAttestedExports", "T", "n", "model", "msg", "payload", "encoded", "cmd_ptr", "cmd_len", "subs_ptr", "subs_len", "snap_ptr", "snap_len", "out", "out_ptr", "out_len", "tag", "tag_name", "name", "frame", "key", "pinch", "value", "self", "index", "args", "args_tuple", "allocator", "fields", "field", "next", "helper_args", "view_unbound"];
106
+ for (const h of s.model_helpers) for (let i = 0; i < h.params.length; i++) reserved.push(`p${i}`);
107
+ reserved.push("subscriptions", "commandMsg", "frameMsg", "keyMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs");
108
+ if (s.model !== "Model") reserved.push("Model");
109
+ if (s.msg.name !== "Msg") reserved.push("Msg");
110
+ if (s.abi.exports.includes("native_view")) reserved.push("nativeView", "nativeViewEvent", "ptr", "len", "arena");
111
+ if (s.abi.exports.includes("native_virtual_requests")) reserved.push("nativeVirtualRequests", "nativeVirtualView");
112
+ if (usesVirtualExtentHelpers(s)) reserved.push("virtualExtentHelper", "virtualExtentEstimate");
113
+ if (s.abi.exports.includes("native_media_view")) reserved.push("nativeMediaView");
114
+ if (s.abi.exports.includes("native_media_window_view")) reserved.push("nativeMediaWindowView");
115
+ if (s.abi.exports.includes("native_window_view")) reserved.push("nativeWindowView", "label", "ptr", "len", "arena");
116
+ const policies = ["radio", "tabs", "tree", "list", "menu", "toggle", "accordion", "slider", "split", "scroll", "resizable", "text", "timer", "db", "effect", "stream", "window", "theme", "status"];
117
+ const methods = ["nativeRadioPolicy", "nativeTabsPolicy", "nativeTreePolicy", "nativeListPolicy", "nativeMenuPolicy", "nativeTogglePolicy", "nativeAccordionPolicy", "nativeSliderPolicy", "nativeSplitPolicy", "nativeScrollPolicy", "nativeResizablePolicy", "nativeTextPolicy", "nativeTimerPolicy", "nativeDbPolicy", "nativeEffectPolicy", "nativeStreamPolicy", "nativeWindowPolicy", "nativeThemePolicy", "nativeStatusPolicy"];
118
+ for (let i = 0; i < policies.length; i++) if (s.abi.exports.includes("native_" + policies[i] + "_policy")) {
119
+ reserved.push(methods[i]);
120
+ if (policies[i] === "text") reserved.push("nativePressHoldPolicy", "nativeTabFocusPolicy", "nativeSurfaceScopePolicy", "nativeFocusReturnPolicy", "nativeTooltipPolicy");
121
+ if (policies[i] === "window") reserved.push("nativeMarkdownPolicy", "arena");
122
+ reserved.push("request", "output", "ptr", "len");
123
+ }
124
+ if (s.model_helpers.length > 0) reserved.push("callHelper");
125
+ const c = s.channels;
126
+ if (c.command_msg || c.frame_msg || c.key_msg || c.pinch_msg || c.drop_msg || s.abi.exports.includes("native_view")) reserved.push("msgFromEnvelope", "decodeMsgEnvelope", "envelope", "header", "arena");
127
+ if (s.init_returns_cmd) reserved.push("InitResult");
128
+ if (s.update_returns_cmd) reserved.push("UpdateResult");
129
+ if (c.frame_msg) reserved.push("FrameEvent");
130
+ if (c.key_msg) reserved.push("KeyEvent");
131
+ if (c.pinch_msg) reserved.push("PinchEvent", "PinchPhase");
132
+ if (c.drop_msg) reserved.push("FileDropEvent", "FileDropPoint");
133
+ const tables = tableNames(s);
134
+ for (const name of tables) if (reserved.includes(name)) flag(out, "types", `type name "${name}" collides with a declaration the generated shim itself must make; rename the type in the core source`);
135
+ if (reserved.includes(s.msg.name) || tables.includes(s.msg.name)) flag(out, "msg.name", `message union name "${s.msg.name}" collides with another declaration of the generated shim; rename the union in the core source`);
136
+ for (const h of s.model_helpers) {
137
+ if (reserved.includes(h.name)) flag(out, "model_helpers", `helper "${h.name}" collides with a declaration the generated shim itself must make (methods shadow file-scope names inside the model struct); rename the helper in the core source`);
138
+ if (tables.includes(h.name) || s.msg.name === h.name) flag(out, "model_helpers", `helper "${h.name}" shadows the type of the same name inside the model struct, where field types resolve; rename one in the core source`);
139
+ }
140
+ const model = findRecord(s, s.model);
141
+ if (model !== null) {
142
+ if (usesVirtualExtentHelpers(s)) for (const f of model.fields) {
143
+ if (f.name === "virtualExtentHelper" || f.name === "virtualExtentEstimate") flag(out, "types", `model field "${f.name}" collides with a declaration the generated shim itself must make; rename the field in the core source`);
144
+ }
145
+ for (const h of s.model_helpers) {
146
+ if (h.name === "view_unbound") flag(out, "model_helpers", 'helper "view_unbound" takes the unbound-list declaration\'s spelling — the contract reflection reads that name as the opt-out tuple; rename the helper in the core source');
147
+ for (const f of model.fields) if (f.name === h.name) flag(out, "model_helpers", `helper "${h.name}" collides with the model field of the same name — the mirror declares helpers as model methods, one member namespace; rename one in the core source`);
148
+ }
149
+ if (s.model_unbound.length > 0) for (const f of model.fields) if (f.name === "view_unbound") flag(out, "model_unbound", 'the model field "view_unbound" collides with the unbound-list declaration the mirror must make; rename the field in the core source');
150
+ }
151
+ if (s.msg.unbound.length > 0) for (const a of s.msg.arms) if (a.name === "view_unbound") flag(out, "msg.unbound", 'the message arm "view_unbound" collides with the unbound-list declaration the mirror must make; rename the arm in the core source');
152
+ }
153
+ function mirrorChannelShapes(s: CoreContract, out: Diagnostic[]): void {
154
+ if (s.channels.appearance_msg !== null) {
155
+ const r = channelRecord(s, s.channels.appearance_msg);
156
+ const teaching = "the appearance arm must carry exactly { colorScheme: a light/dark enum, reduceMotion: bool, highContrast: bool } — the host builds this record by field name";
157
+ if (r === null) { flag(out, "channels.appearance_msg", teaching); return; }
158
+ if (!appearanceRecord(s, r)) flag(out, "channels.appearance_msg", teaching);
159
+ }
160
+ if (s.channels.chrome_msg !== null) {
161
+ const r = channelRecord(s, s.channels.chrome_msg);
162
+ const teaching = "the chrome arm must carry exactly { insets: top/right/bottom/left numbers, buttons: x/y/width/height numbers, tabsProjected: bool } — the host builds this record by field name";
163
+ if (r === null) { flag(out, "channels.chrome_msg", teaching); return; }
164
+ if (!chromeRecord(s, r)) flag(out, "channels.chrome_msg", teaching);
165
+ }
166
+ }
167
+ function unsigned(s: CoreContract, slot: string): boolean { return s.integer_slots.some(p => p.slot === slot && p.class === "u64"); }
168
+ function scrollRecord(r: RecordType): boolean {
169
+ const spellings = [
170
+ ["offsetX", "offsetY", "velocityX", "velocityY", "viewportExtentX", "viewportExtentY", "contentExtentX", "contentExtentY"],
171
+ ["offset_x", "offset_y", "velocity_x", "velocity_y", "viewport_extent_x", "viewport_extent_y", "content_extent_x", "content_extent_y"],
172
+ ];
173
+ return r.fields.length === 8 && spellings.some(fields => fields.every(name => r.fields.some(f => f.name === name && numeric(f.type))));
174
+ }
175
+ function mirrorIntegers(s: CoreContract, out: Diagnostic[]): void {
176
+ for (const a of s.msg.arms) {
177
+ if (a.payload.kind !== "record") continue;
178
+ const r = findRecord(s, a.payload.name!);
179
+ if (r === null || !scrollRecord(r)) continue;
180
+ for (const f of r.fields) if (f.type.kind === "i64" && ["offsetX", "offsetY", "velocityX", "velocityY", "offset_x", "offset_y", "velocity_x", "velocity_y"].includes(f.name) && unsigned(s, r.name + "." + f.name))
181
+ flag(out, "integer_slots", `"${r.name}.${f.name}" is a signed scroll-state axis (offsets and velocities go negative during rubber-banding and upward flicks) — the u64 class cannot carry those values; keep offset and velocity fields i64 or f64`);
182
+ }
183
+ if (s.channels.chrome_msg !== null) {
184
+ const r = channelRecord(s, s.channels.chrome_msg);
185
+ if (r !== null) for (const f of r.fields) if (f.name === "buttons") {
186
+ const nested = valueRecord(s, f.type);
187
+ if (nested !== null) for (const g of nested.fields) if (g.type.kind === "i64" && (g.name === "x" || g.name === "y") && unsigned(s, nested.name + "." + g.name))
188
+ flag(out, "integer_slots", `"${nested.name}.${g.name}" is the window-control cluster's position, reported in signed content coordinates — the u64 class cannot carry it; keep buttons x and y i64 or f64`);
189
+ }
190
+ }
191
+ }
192
+ export function validateMirror(s: CoreContract): Diagnostic[] {
193
+ const out: Diagnostic[] = [];
194
+ mirrorNames(s, out); mirrorChannelShapes(s, out);
195
+ const nodes = storedNodes(s, false);
196
+ for (const a of s.msg.arms) if (a.payload.kind === "record" && nodes.includes(a.payload.name!)) flag(out, "msg.arms", `arm "${a.name}": record "${a.payload.name}" is stored by reference in the model graph, and the compiled core keeps that storage when the record doubles as an arm payload — a fact the record payload family cannot carry; keep the arm's payload a value-stored record`);
197
+ mirrorIntegers(s, out);
198
+ return out;
199
+ }
200
+
201
+ function identifier(name: string, dollar: boolean): boolean {
202
+ if (name.length === 0 || (name.charCodeAt(0) >= 48 && name.charCodeAt(0) <= 57)) return false;
203
+ for (let i = 0; i < name.length; i++) {
204
+ const c = name.charCodeAt(i);
205
+ if (!((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c === 95 || (dollar && c === 36))) return false;
206
+ }
207
+ return true;
208
+ }
209
+ function primitive(name: string): boolean {
210
+ if (zigPrimitives.includes(name)) return true;
211
+ if (name.length < 2 || (name[0] !== "i" && name[0] !== "u")) return false;
212
+ for (let i = 1; i < name.length; i++) if (name.charCodeAt(i) < 48 || name.charCodeAt(i) > 57) return false;
213
+ return true;
214
+ }
215
+ function identifierIssue(name: string, declaration: boolean): string | null {
216
+ if (name.length === 0) return "is empty";
217
+ if (name === "_") return "is the discard spelling in the compiled module";
218
+ if (name.charCodeAt(0) >= 48 && name.charCodeAt(0) <= 57) return "starts with a digit";
219
+ if (!identifier(name, false)) return "uses characters outside the compiled module's identifier set (letters, digits, underscore)";
220
+ if (zigKeywords.includes(name)) return "is a keyword in the compiled module";
221
+ if (primitive(name)) return "is a primitive type name in the compiled module";
222
+ if (declaration && tsReservedWords.includes(name)) return "is a reserved word in TypeScript";
223
+ return null;
224
+ }
225
+ function generatedType(s: CoreContract, name: string): boolean {
226
+ if (name === s.model || name === s.msg.name) return false;
227
+ const r = findRecord(s, name), e = findEnum(s, name), u = findUnion(s, name);
228
+ return r !== null ? r.origin === null : e !== null ? e.origin === null : u !== null ? u.origin === null : false;
229
+ }
230
+ function reservedNamespace(name: string): boolean { return name.startsWith("nsc_core_") || name.startsWith("nscf"); }
231
+ function facadeFacts(s: CoreContract, plan: ProjectionPlan, out: Diagnostic[]): void {
232
+ const model = findRecord(s, s.model);
233
+ if (model === null || model.origin === null) flag(out, "types", "the model declaration carries no authored type-origin fact — this sidecar predates facade metadata; regenerate it with the current compiler before requesting --facade, --profile, or --check");
234
+ for (const a of s.msg.arms) {
235
+ const p = a.payload;
236
+ const needs = p.kind !== "void" && p.kind !== "number_bytes" && (p.kind !== "record" || flattenedRecord(s, plan, payloadRef(p), s.msg.name, a.name) === null);
237
+ if (needs && a.member === null) flag(out, "msg.arms", `arm "${a.name}" carries one payload but no authored member-name fact — this sidecar predates facade metadata; regenerate it with the current compiler`);
238
+ }
239
+ for (const u of s.types.unions) for (const a of u.arms) {
240
+ if (a.payload.kind === "void" || flattenedRecord(s, plan, a.payload, u.name, a.name) !== null) continue;
241
+ if (a.member === null) flag(out, "types.unions", `arm "${a.name}" of "${u.name}" carries one payload but no authored member-name fact — this sidecar predates facade metadata; regenerate it with the current compiler`);
242
+ }
243
+ }
244
+ function modelValueRecords(s: CoreContract, out: Diagnostic[]): void {
245
+ const model = findRecord(s, s.model), visited: string[] = [];
246
+ if (model === null) return;
247
+ function visit(ref: TypeRef): void {
248
+ if (ref.kind === "value" || ref.kind === "node" || ref.kind === "union") {
249
+ const name = ref.name!;
250
+ if (visited.includes(name)) return;
251
+ visited.push(name);
252
+ if (ref.kind === "union") {
253
+ const u = findUnion(s, name);
254
+ if (u !== null) for (const a of u.arms) visit(a.payload);
255
+ return;
256
+ }
257
+ const r = findRecord(s, name);
258
+ if (r === null) return;
259
+ for (const f of r.fields) {
260
+ if (ref.kind === "node") visit(f.type);
261
+ else if (!["f64", "i64", "bool", "enum"].includes(f.type.kind)) {
262
+ flag(out, "types", `"${name}" is a value-stored record the model keeps, but field "${f.name}" is not a scalar — the compiled projection commits value records shallowly, so heap-backed fields would dangle across frames; store "${name}" by reference in the core source`);
263
+ break;
264
+ }
265
+ }
266
+ } else if (ref.kind === "slice") {
267
+ const elem = ref.elem!.kind === "optional" ? ref.elem!.inner! : ref.elem!;
268
+ if (elem.kind === "value") flag(out, "types", `a model sequence holds "${elem.name}" by value — sequences the model keeps carry reference-stored records (the compiled projection has no by-value sequence commit); store "${elem.name}" by reference in the core source`);
269
+ visit(ref.elem!);
270
+ } else if (ref.kind === "optional") visit(ref.inner!);
271
+ }
272
+ for (const f of model.fields) visit(f.type);
273
+ }
274
+ function facadeNames(s: CoreContract, plan: ProjectionPlan, out: Diagnostic[]): void {
275
+ const names = tableNames(s); names.push(s.msg.name, s.model);
276
+ for (const name of names) {
277
+ const issue = identifierIssue(name, true);
278
+ if (issue !== null) flag(out, "types", `type name "${name}" ${issue} — the facade must stay declarable end to end (TypeScript source, then the compiled module, which takes identifiers verbatim); rename it in the core source`);
279
+ if (name === "Uint8Array") flag(out, "types", '"Uint8Array" shadows the ambient byte type every encoder in the generated facade uses; rename the type in the core source');
280
+ if (name === "Buffer") flag(out, "types", '"Buffer" shadows the ambient buffer type the generated f64 codec uses; rename the type in the core source');
281
+ if (s.channels.pinch_msg && name === "PinchPhase") flag(out, "types", '"PinchPhase" collides with the SDK vocabulary the wired pinch channel imports; rename the type in the core source');
282
+ if (s.channels.drop_msg && name === "FileDropPoint") flag(out, "types", '"FileDropPoint" collides with the SDK vocabulary the wired file-drop channel imports; rename the type in the core source');
283
+ }
284
+ for (const a of s.msg.arms) {
285
+ const issue = identifierIssue(a.name, false);
286
+ if (issue !== null) flag(out, "msg.arms", `arm "${a.name}" ${issue} — the facade must stay declarable end to end; rename it in the core source`);
287
+ if (a.member === "kind") flag(out, "msg.arms", `arm "${a.name}" names its payload member "kind", the discriminator's own spelling — the constructed arm object would declare it twice; rename the member in the core source`);
288
+ }
289
+ for (const u of s.types.unions) for (const a of u.arms) {
290
+ const issue = identifierIssue(a.name, false);
291
+ if (issue !== null) flag(out, "types.unions", `arm "${a.name}" of "${u.name}" ${issue} — the facade must stay declarable end to end; rename it in the core source`);
292
+ if (a.member === "kind") flag(out, "types.unions", `arm "${a.name}" of "${u.name}" names its payload member "kind", the discriminator's own spelling; rename the member in the core source`);
293
+ }
294
+ for (const e of s.types.enums) {
295
+ for (const name of e.members) {
296
+ const issue = identifierIssue(name, false);
297
+ if (issue !== null) flag(out, "types.enums", `member "${name}" of "${e.name}" ${issue} — the facade must stay declarable end to end; rename it in the core source`);
298
+ }
299
+ if (e.members.length < 2) flag(out, "types", `enum "${e.name}" has one member — a single string literal is not a union in the projected subset, so no source can author it; give the state a second member or fold it away in the core source`);
300
+ }
301
+ for (const r of s.types.structs) for (const f of r.fields) {
302
+ const issue = identifierIssue(f.name, false);
303
+ if (issue !== null) flag(out, "types", `field "${f.name}" ${issue} — the facade must stay declarable end to end; rename it in the core source`);
304
+ if (reservedNamespace(f.name)) flag(out, "types", `field "${f.name}" takes the facade's reserved nsc name space; rename it in the core source`);
305
+ }
306
+ for (const a of s.msg.arms) {
307
+ const p = a.payload;
308
+ if (p.kind === "number_bytes") for (const name of [p.number_field!, p.bytes_field!]) {
309
+ const issue = identifierIssue(name, false);
310
+ if (issue !== null) flag(out, "msg.arms", `field "${name}" ${issue} — the facade must stay declarable end to end; rename it in the core source`);
311
+ if (name === "kind") flag(out, "msg.arms", `arm "${a.name}" flattens a field spelled "kind" beside the message discriminator of the same name; rename the field in the core source`);
312
+ if (reservedNamespace(name)) flag(out, "msg.arms", `field "${name}" takes the facade's reserved nsc name space; rename it in the core source`);
313
+ }
314
+ else if (p.kind === "record") {
315
+ const r = flattenedRecord(s, plan, payloadRef(p), s.msg.name, a.name);
316
+ if (r !== null) for (const f of r.fields) if (f.name === "kind") flag(out, "msg.arms", `arm "${a.name}" flattens a field spelled "kind" beside the message discriminator of the same name; rename the field in the core source`);
317
+ }
318
+ }
319
+ for (const u of s.types.unions) for (const a of u.arms) {
320
+ const r = flattenedRecord(s, plan, a.payload, u.name, a.name);
321
+ if (r !== null) for (const f of r.fields) if (f.name === "kind") flag(out, "types.unions", `arm "${a.name}" of "${u.name}" flattens a field spelled "kind" beside the arm discriminator of the same name; rename the field in the core source`);
322
+ }
323
+ for (const h of s.model_helpers) {
324
+ if (!identifier(h.name, true) || tsReservedWords.includes(h.name) || identifierIssue(h.name, true) !== null) { flag(out, "model_helpers", `helper "${h.name}" is not declarable as an exported function in both pipeline languages; rename it in the core source`); continue; }
325
+ if (reservedNamespace(h.name)) flag(out, "model_helpers", `helper "${h.name}" takes the facade's reserved nsc name space; rename it in the core source`);
326
+ for (const name of fixedExports) if (h.name === name) flag(out, "model_helpers", `helper "${h.name}" collides with a declaration the generated facade itself must export; rename it in the core source`);
327
+ for (const name of ambientValues) if (h.name === name) flag(out, "model_helpers", `helper "${h.name}" shadows an ambient value the generated facade calls; rename it in the core source`);
328
+ }
329
+ const declarations = tableNames(s); declarations.push(s.msg.name);
330
+ for (const name of declarations) {
331
+ if (name.length === 0) continue;
332
+ if (reservedNamespace(name)) { flag(out, "types", `"${name}" collides with the facade's reserved nsc name space; rename it in the core source`); continue; }
333
+ for (const fixed of fixedExports) if (name === fixed) flag(out, "types", `"${name}" collides with a declaration the generated facade itself must make; rename it in the core source`);
334
+ }
335
+ for (const r of s.types.structs) if (generatedType(s, r.name) && !plan.flattened.includes(r.name)) flag(out, "types", `compiler-generated table type "${r.name}" has no authored TypeScript declaration the facade can name — generic instantiations cannot cross the compiled-core contract surface yet; replace the contract-facing generic with an authored concrete record`);
336
+ for (const e of s.types.enums) if (generatedType(s, e.name)) flag(out, "types", `compiler-generated table type "${e.name}" has no authored TypeScript declaration the facade can name — generic instantiations cannot cross the compiled-core contract surface yet; replace the contract-facing generic with an authored concrete type`);
337
+ for (const u of s.types.unions) if (generatedType(s, u.name)) flag(out, "types", `compiler-generated table type "${u.name}" has no authored TypeScript declaration the facade can name — generic instantiations cannot cross the compiled-core contract surface yet; replace the contract-facing generic with an authored concrete union`);
338
+ const values: string[] = [];
339
+ walkRefs(s, (ref) => { const r = innermost(ref); if (r.kind === "value") note(values, r.name!); });
340
+ for (const name of values) if (plan.node_stored.includes(name)) flag(out, "types", `"${name}" is stored by reference at one site and by value at another — the projection states storage once per declaration, so one record cannot say both; split the type in the core source`);
341
+ modelValueRecords(s, out);
342
+ for (const channel of [{ name: "appearance_msg", arm: s.channels.appearance_msg }, { name: "chrome_msg", arm: s.channels.chrome_msg }]) {
343
+ const name = channel.arm;
344
+ if (name === null) continue;
345
+ const a = findArm(s, name);
346
+ if (a !== null && a.payload.kind === "record" && !plan.flattened.includes(a.payload.name!)) flag(out, `channels.${channel.name}`, `arm "${name}" carries the named record "${a.payload.name}", which the projection cannot flatten into the arm (the host fills the event's fields directly on the arm) — declare the event's fields inline on the arm in the core source`);
347
+ }
348
+ }
349
+ function nestedOptional(ref: TypeRef, inside: boolean, at: string, out: Diagnostic[]): void {
350
+ if (ref.kind === "optional") {
351
+ if (inside) { flag(out, at, "a nested optional has no TypeScript projection — one null carries one absence level, and the source language cannot author a second; flatten the state in the core source"); return; }
352
+ nestedOptional(ref.inner!, true, at, out);
353
+ } else if (ref.kind === "slice") nestedOptional(ref.elem!, false, at, out);
354
+ }
355
+ export function validateFacade(s: CoreContract, plan: ProjectionPlan): Diagnostic[] {
356
+ const out: Diagnostic[] = [];
357
+ facadeFacts(s, plan, out); facadeNames(s, plan, out);
358
+ walkRefs(s, (ref, at) => nestedOptional(ref, false, at, out));
359
+ return out;
360
+ }
@@ -0,0 +1,6 @@
1
+ // Identifier vocabularies of the pinned TypeScript/Zig projection pipeline.
2
+ export const tsReservedWords = ["break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "new", "null", "return", "super", "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", "with", "let", "static", "yield", "await", "interface", "type", "number", "boolean", "string", "object", "undefined", "any", "unknown", "never", "bigint", "symbol", "implements", "package", "private", "protected", "public", "arguments", "eval"];
3
+ export const fixedExports = ["init", "coreUpdate", "coreSubscriptions", "boot_cmd", "dispatch_void", "dispatch_bytes", "dispatch_number", "dispatch_number_bytes", "dispatch_bool", "dispatch_enum", "dispatch_record", "dispatch_text_input", "dispatch_scroll_state", "abi_subscriptions", "model_snapshot", "persist_snapshot", "restore_model", "migrate_model", "helper_call", "abi_command_msg", "abi_frame_msg", "abi_frame_msg_ns", "abi_key_msg", "abi_pinch_msg", "abi_drop_msg", "appearanceMsg", "chromeMsg", "envMsgs", "viewUnbound"];
4
+ export const ambientValues = ["Math", "Buffer", "Uint8Array", "Error", "String"];
5
+ export const zigKeywords = ["addrspace", "align", "allowzero", "and", "anyframe", "anytype", "asm", "break", "callconv", "catch", "comptime", "const", "continue", "defer", "else", "enum", "errdefer", "error", "export", "extern", "fn", "for", "if", "inline", "noalias", "noinline", "nosuspend", "opaque", "or", "orelse", "packed", "pub", "resume", "return", "linksection", "struct", "suspend", "switch", "test", "threadlocal", "try", "union", "unreachable", "var", "volatile", "while"];
6
+ export const zigPrimitives = ["anyerror", "anyframe", "anyopaque", "bool", "c_int", "c_long", "c_longdouble", "c_longlong", "c_char", "c_short", "c_uint", "c_ulong", "c_ulonglong", "c_ushort", "comptime_float", "comptime_int", "f128", "f16", "f32", "f64", "f80", "false", "isize", "noreturn", "null", "true", "type", "undefined", "usize", "void"];