@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,248 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { test } from "node:test";
7
+ import { emitProfile, type ProfileInput } from "./emit_profile.ts";
8
+
9
+ assert.ok(process.argv[2], "run with the compiled corewire path (zig build test-corewire-profile)");
10
+ const corewire = path.resolve(process.argv[2]);
11
+ const fixtures = new URL("../../tests/sidecar/", import.meta.url);
12
+ function fixture(name: string) {
13
+ return JSON.parse(fs.readFileSync(new URL(`${name}_fixture.contract.json`, fixtures), "utf8"));
14
+ }
15
+ function withWork(run: (dir: string) => void) {
16
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "native-profile-test-"));
17
+ try { run(dir); } finally { fs.rmSync(dir, { recursive: true, force: true }); }
18
+ }
19
+ function currentContract(name: string) {
20
+ const input = fixture(name);
21
+ // The mirror fixtures predate facade metadata. Supply those independent
22
+ // facts for CLI tests; they do not affect the profile projection.
23
+ for (const table of [input.types.structs, input.types.enums, input.types.unions]) {
24
+ for (const type of table) {
25
+ if (!type.name.startsWith("Msg_") && !type.name.startsWith("TextInputEvent_")) type.origin ??= path.basename(input.entry);
26
+ }
27
+ }
28
+ for (const arm of input.msg.arms) {
29
+ if (["bytes", "number", "bool", "enum", "text_input"].includes(arm.payload.kind)) arm.member ??= "value";
30
+ }
31
+ for (const type of input.types.unions) {
32
+ for (const arm of type.arms) {
33
+ if (arm.payload.kind !== "void") arm.member ??= "value";
34
+ }
35
+ }
36
+ return input;
37
+ }
38
+ function invoke(dir: string, input: ProfileInput, extra: string[] = []) {
39
+ fs.writeFileSync(path.join(dir, "contract.json"), JSON.stringify(input));
40
+ const result = spawnSync(corewire, ["--sidecar", "contract.json", ...extra], { cwd: dir, encoding: "utf8" });
41
+ assert.ifError(result.error);
42
+ assert.equal(result.signal, null, result.stderr);
43
+ return result;
44
+ }
45
+
46
+ // Captured from the Zig emitter before its removal. These files pin export
47
+ // ordering, ABI signatures, integer classes, policy text, and JSON spelling.
48
+ for (const name of ["integer", "markup", "wide_msg"]) {
49
+ test(`${name}: Node and the compiled generator match the original profile bytes`, () => withWork(dir => {
50
+ const expected = fs.readFileSync(new URL(`profiles/${name}.json`, fixtures), "utf8");
51
+ assert.equal(emitProfile(fixture(name), "core_facade.ts", "release").output, expected);
52
+ const result = invoke(dir, currentContract(name), ["--profile", "profile.json", "--optimization", "release"]);
53
+ assert.equal(result.status, 0, result.stderr);
54
+ assert.equal(fs.readFileSync(path.join(dir, "profile.json"), "utf8"), expected);
55
+ }));
56
+ }
57
+
58
+ test("relative entries, Unicode, escaping, optimization, and empty integer slots agree", () => withWork(dir => {
59
+ const input = currentContract("wide_msg");
60
+ input.abi.prefix = "other_";
61
+ input.has_subscriptions = true;
62
+ input.types.structs[0].fields[0].type.kind = "f64";
63
+ input.integer_slots = [];
64
+ // Quotes/control characters are legal filenames on POSIX, not Windows.
65
+ const entry = process.platform === "win32" ? "café-🧪.ts" : 'café-🧪-"-\t-\b-\f.ts';
66
+ for (const optimization of ["", "dev", "release"]) {
67
+ const extra = ["--profile", path.join(dir, "profile.json"), "--facade", path.join(dir, entry)];
68
+ if (optimization) extra.push("--optimization", optimization);
69
+ const result = invoke(dir, input, extra);
70
+ assert.equal(result.status, 0, result.stderr);
71
+ const output = fs.readFileSync(path.join(dir, "profile.json"), "utf8");
72
+ assert.equal(output, emitProfile(input, entry, optimization).output);
73
+ const profile = JSON.parse(output);
74
+ assert.equal(profile.entry, entry);
75
+ assert.equal(profile.optimization, optimization || undefined);
76
+ assert.equal(profile.sidecar.subscriptions_export, "coreSubscriptions");
77
+ assert.deepEqual(profile.sidecar.integer_slots, []);
78
+ assert.equal(profile.abi.init_symbol, "other_init");
79
+ }
80
+ }));
81
+
82
+ test("f64 projection reaches both the compiled profile and effective sidecar", () => withWork(dir => {
83
+ const input = currentContract("integer");
84
+ const result = invoke(dir, input, ["--profile", "profile.json", "--effective-sidecar", "effective.json", "--f64-slot", "Model.count"]);
85
+ assert.equal(result.status, 0, result.stderr);
86
+ const effective = JSON.parse(fs.readFileSync(path.join(dir, "effective.json"), "utf8"));
87
+ const output = fs.readFileSync(path.join(dir, "profile.json"), "utf8");
88
+ assert.equal(output, emitProfile(effective, "core_facade.ts", "").output);
89
+ assert.ok(!JSON.parse(output).sidecar.integer_slots.some((slot: { slot: string }) => slot.slot === "Model.count"));
90
+ }));
91
+
92
+ test("both attestation refusals preserve existing outputs and appear in check mode", () => withWork(dir => {
93
+ const input = currentContract("wide_msg");
94
+ input.deterministic = false;
95
+ input.async_free = false;
96
+ const expected = emitProfile(input, "core_facade.ts", "");
97
+ assert.deepEqual(expected.diagnostics.map(d => d.path), ["deterministic", "async_free"]);
98
+ assert.equal(expected.output, "");
99
+ for (const file of ["profile.json", "core_facade.ts", "mirror.zig", "effective.json"]) fs.writeFileSync(path.join(dir, file), "keep");
100
+ for (const extra of [
101
+ ["--check"],
102
+ ["--profile", "profile.json", "--facade", "core_facade.ts", "--out", "mirror.zig", "--effective-sidecar", "effective.json"],
103
+ ]) {
104
+ const result = invoke(dir, input, extra);
105
+ assert.equal(result.status, 1, result.stderr);
106
+ for (const diagnostic of expected.diagnostics) assert.ok(result.stderr.includes(diagnostic.message));
107
+ }
108
+ for (const file of ["profile.json", "core_facade.ts", "mirror.zig", "effective.json"]) assert.equal(fs.readFileSync(path.join(dir, file), "utf8"), "keep");
109
+ assert.ok(!fs.readdirSync(dir).some(file => file.endsWith(".corewire-tmp")));
110
+ }));
111
+
112
+ test("policy text obeys compiler limits and conditional channel signatures are complete", () => {
113
+ const input = fixture("wide_msg");
114
+ input.abi.exports.push("command_msg", "frame_msg", "key_msg", "pinch_msg", "drop_msg");
115
+ const profile = JSON.parse(emitProfile(input, "core_facade.ts", "release").output);
116
+ const channels = profile.exports.filter((entry: { export: string }) => entry.export.endsWith("_msg"));
117
+ assert.deepEqual(channels.map((entry: { export: string; params: string[] }) => [entry.export, entry.params]), [
118
+ ["abi_command_msg", ["bytes"]],
119
+ ["abi_frame_msg", ["f64", "f64", "f64", "f64"]],
120
+ ["abi_key_msg", ["bytes", "u8", "u8", "u8", "u8"]],
121
+ ["abi_pinch_msg", ["f64", "bytes", "u32", "f64", "f64", "f64"]],
122
+ ["abi_drop_msg", ["bytes"]],
123
+ ]);
124
+ const texts = [
125
+ ...Object.values(profile.determinism.teachings), ...Object.values(profile.determinism.remediations),
126
+ ...profile.determinism.fences.map((f: { teaching: string }) => f.teaching),
127
+ ] as string[];
128
+ assert.equal(profile.determinism.fences.length, 13);
129
+ for (const text of texts) {
130
+ assert.ok(Buffer.byteLength(text) <= 512);
131
+ assert.doesNotMatch(text, /[\x00-\x09\x0b-\x1f]/);
132
+ }
133
+ });
134
+
135
+ test("exact frame ABI adds borrowed decimal clocks and preserves legacy profiles", () => withWork(dir => {
136
+ const input = currentContract("wide_msg");
137
+ input.channels.frame_msg = true;
138
+ input.abi.exports.push("frame_msg", "frame_msg_ns");
139
+ const result = invoke(dir, input, ["--profile", path.join(dir, "profile.json"), "--out", "mirror.zig", "--facade", path.join(dir, "facade.ts")]);
140
+ assert.equal(result.status, 0, result.stderr);
141
+ const output = fs.readFileSync(path.join(dir, "profile.json"), "utf8");
142
+ assert.equal(output, emitProfile(input, "facade.ts", "").output);
143
+ assert.deepEqual(JSON.parse(output).exports.at(-1), {
144
+ export: "abi_frame_msg_ns", symbol: input.abi.prefix + "frame_msg_ns",
145
+ params: ["f64", "f64", "f64", "f64", "bytes", "bytes"], returns: "bytes",
146
+ });
147
+ const mirror = fs.readFileSync(path.join(dir, "mirror.zig"), "utf8");
148
+ assert.match(mirror, /timestampNs: \[\]const u8/);
149
+ assert.match(mirror, /abi\.frame_msg_ns\(frame\.width/);
150
+ assert.doesNotMatch(mirror.match(/pub fn frameMsg\([\s\S]*?\n}/)![0], /frame_reset/);
151
+ input.channels.frame_msg = false;
152
+ const refused = invoke(dir, input, ["--check"]);
153
+ assert.equal(refused.status, 1);
154
+ assert.match(refused.stderr, /frame_msg_ns.*requires a wired frame_msg/);
155
+ }));
156
+
157
+ test("compiled profiles preserve the optional Native primary and window view signatures", () => withWork(dir => {
158
+ const input = currentContract("wide_msg");
159
+ input.abi.exports.push("native_view", "native_window_view", "native_radio_policy", "native_tabs_policy", "native_tree_policy", "native_list_policy", "native_menu_policy", "native_toggle_policy", "native_accordion_policy", "native_slider_policy", "native_split_policy", "native_scroll_policy", "native_resizable_policy", "native_text_policy", "native_timer_policy", "native_db_policy", "native_effect_policy", "native_stream_policy", "native_window_policy", "native_theme_policy", "native_status_policy");
160
+ const result = invoke(dir, input, ["--profile", "profile.json", "--out", "mirror.zig"]);
161
+ assert.equal(result.status, 0, result.stderr);
162
+ const output = fs.readFileSync(path.join(dir, "profile.json"), "utf8");
163
+ assert.equal(output, emitProfile(input, "core_facade.ts", "").output);
164
+ const profile = JSON.parse(output);
165
+ assert.deepEqual(profile.exports.at(-21), { export: "native_view", symbol: input.abi.prefix + "native_view", params: [], returns: "bytes" });
166
+ assert.deepEqual(profile.exports.at(-20), { export: "native_window_view", symbol: input.abi.prefix + "native_window_view", params: ["bytes"], returns: "bytes" });
167
+ assert.deepEqual(profile.exports.at(-19), { export: "native_radio_policy", symbol: input.abi.prefix + "native_radio_policy", params: ["bytes"], returns: "bytes" });
168
+ assert.deepEqual(profile.exports.at(-18), { export: "native_tabs_policy", symbol: input.abi.prefix + "native_tabs_policy", params: ["bytes"], returns: "bytes" });
169
+ assert.deepEqual(profile.exports.at(-17), { export: "native_tree_policy", symbol: input.abi.prefix + "native_tree_policy", params: ["bytes"], returns: "bytes" });
170
+ assert.deepEqual(profile.exports.at(-16), { export: "native_list_policy", symbol: input.abi.prefix + "native_list_policy", params: ["bytes"], returns: "bytes" });
171
+ assert.deepEqual(profile.exports.at(-15), { export: "native_menu_policy", symbol: input.abi.prefix + "native_menu_policy", params: ["bytes"], returns: "bytes" });
172
+ assert.deepEqual(profile.exports.at(-14), { export: "native_toggle_policy", symbol: input.abi.prefix + "native_toggle_policy", params: ["bytes"], returns: "bytes" });
173
+ assert.deepEqual(profile.exports.at(-13), { export: "native_accordion_policy", symbol: input.abi.prefix + "native_accordion_policy", params: ["bytes"], returns: "bytes" });
174
+ assert.deepEqual(profile.exports.at(-12), { export: "native_slider_policy", symbol: input.abi.prefix + "native_slider_policy", params: ["bytes"], returns: "bytes" });
175
+ assert.deepEqual(profile.exports.at(-11), { export: "native_split_policy", symbol: input.abi.prefix + "native_split_policy", params: ["bytes"], returns: "bytes" });
176
+ assert.deepEqual(profile.exports.at(-10), { export: "native_scroll_policy", symbol: input.abi.prefix + "native_scroll_policy", params: ["bytes"], returns: "bytes" });
177
+ assert.deepEqual(profile.exports.at(-9), { export: "native_resizable_policy", symbol: input.abi.prefix + "native_resizable_policy", params: ["bytes"], returns: "bytes" });
178
+ assert.deepEqual(profile.exports.at(-8), { export: "native_text_policy", symbol: input.abi.prefix + "native_text_policy", params: ["bytes"], returns: "bytes" });
179
+ assert.deepEqual(profile.exports.at(-7), { export: "native_timer_policy", symbol: input.abi.prefix + "native_timer_policy", params: ["bytes"], returns: "bytes" });
180
+ assert.deepEqual(profile.exports.at(-6), { export: "native_db_policy", symbol: input.abi.prefix + "native_db_policy", params: ["bytes"], returns: "bytes" });
181
+ assert.deepEqual(profile.exports.at(-5), { export: "native_effect_policy", symbol: input.abi.prefix + "native_effect_policy", params: ["bytes"], returns: "bytes" });
182
+ assert.deepEqual(profile.exports.at(-4), { export: "native_stream_policy", symbol: input.abi.prefix + "native_stream_policy", params: ["bytes"], returns: "bytes" });
183
+ assert.deepEqual(profile.exports.at(-3), { export: "native_window_policy", symbol: input.abi.prefix + "native_window_policy", params: ["bytes"], returns: "bytes" });
184
+ assert.deepEqual(profile.exports.at(-2), { export: "native_theme_policy", symbol: input.abi.prefix + "native_theme_policy", params: ["bytes"], returns: "bytes" });
185
+ assert.deepEqual(profile.exports.at(-1), { export: "native_status_policy", symbol: input.abi.prefix + "native_status_policy", params: ["bytes"], returns: "bytes" });
186
+ const mirror = fs.readFileSync(path.join(dir, "mirror.zig"), "utf8");
187
+ assert.match(mirror, /pub fn nativeStreamPolicy\(request:/);
188
+ assert.doesNotMatch(mirror.match(/pub fn nativeStreamPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
189
+ assert.match(mirror, /pub fn nativeTextPolicy\(request:/);
190
+ assert.match(mirror.match(/pub fn nativeTextPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
191
+ const holdWrapper = mirror.match(/pub fn nativePressHoldPolicy\([\s\S]*?\n}/)![0];
192
+ assert.match(holdWrapper, /abi.native_text_policy\(/);
193
+ assert.doesNotMatch(holdWrapper, /abi.frame_reset/);
194
+ const focusWrapper = mirror.match(/pub fn nativeTabFocusPolicy\([\s\S]*?\n}/)![0];
195
+ assert.match(focusWrapper, /abi.native_text_policy\(/);
196
+ assert.doesNotMatch(focusWrapper, /abi.frame_reset/);
197
+ const surfaceWrapper = mirror.match(/pub fn nativeSurfaceScopePolicy\([\s\S]*?\n}/)![0];
198
+ assert.match(surfaceWrapper, /abi.native_text_policy\(/);
199
+ assert.doesNotMatch(surfaceWrapper, /abi.frame_reset/);
200
+ const tooltipWrapper = mirror.match(/pub fn nativeTooltipPolicy\([\s\S]*?\n}/)![0];
201
+ assert.match(tooltipWrapper, /abi.native_text_policy\(/);
202
+ assert.doesNotMatch(tooltipWrapper, /abi.frame_reset/);
203
+ const returnWrapper = mirror.match(/pub fn nativeFocusReturnPolicy\([\s\S]*?\n}/)![0];
204
+ assert.match(returnWrapper, /abi.native_text_policy\(/);
205
+ assert.doesNotMatch(returnWrapper, /abi.frame_reset/);
206
+ assert.match(mirror, /pub fn nativeTimerPolicy\(request:/);
207
+ assert.match(mirror, /pub fn nativeDbPolicy\(request:/);
208
+ assert.match(mirror, /pub fn nativeEffectPolicy\(request:/);
209
+ assert.doesNotMatch(mirror.match(/pub fn nativeEffectPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
210
+ assert.match(mirror, /pub fn nativeWindowPolicy\(request:/);
211
+ assert.doesNotMatch(mirror.match(/pub fn nativeWindowPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
212
+ assert.match(mirror, /pub fn nativeThemePolicy\(request:/);
213
+ assert.doesNotMatch(mirror.match(/pub fn nativeThemePolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
214
+ assert.match(mirror, /pub fn nativeStatusPolicy\(request:/);
215
+ assert.doesNotMatch(mirror.match(/pub fn nativeDbPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
216
+ assert.doesNotMatch(mirror.match(/pub fn nativeTimerPolicy\([\s\S]*?\n}/)![0], /defer abi.frame_reset/);
217
+ assert.match(mirror, /pub fn nativeResizablePolicy\(request:/);
218
+ assert.match(mirror, /pub fn nativeScrollPolicy\(request:/);
219
+ assert.match(mirror, /pub fn nativeSplitPolicy\(request:/);
220
+ assert.match(mirror, /pub fn nativeSliderPolicy\(request:/);
221
+ assert.match(mirror, /pub fn nativeAccordionPolicy\(request:/);
222
+ assert.match(mirror, /pub fn nativeTogglePolicy\(request:/);
223
+ assert.match(mirror, /pub fn nativeMenuPolicy\(request:/);
224
+ assert.match(mirror, /pub fn nativeListPolicy\(request:/);
225
+ assert.match(mirror, /pub fn nativeTreePolicy\(request:/);
226
+ assert.match(mirror, /pub fn nativeTabsPolicy\(request:/);
227
+ assert.match(mirror, /pub fn nativeRadioPolicy\(request:/);
228
+ assert.match(mirror, /pub fn nativeView\(arena:/);
229
+ assert.match(mirror, /pub fn nativeViewEvent\(envelope: \[\]const u8, arena: std.mem.Allocator\)/);
230
+ assert.match(mirror, /pub fn nativeWindowView\(label: \[\]const u8, arena: std.mem.Allocator\)/);
231
+ assert.match(mirror, /abi\.native_window_view\(label.ptr, label.len, &ptr, &len\)/);
232
+ assert.ok(!mirror.includes('const nscfCommitted'));
233
+ }));
234
+
235
+ test("media view exports carry explicit playback context and copy results before frame reset", () => withWork(dir => {
236
+ const input = currentContract("wide_msg");
237
+ input.abi.exports.push("native_view", "native_window_view", "native_media_view", "native_media_window_view");
238
+ const result = invoke(dir, input, ["--profile", "profile.json", "--out", "mirror.zig"]);
239
+ assert.equal(result.status, 0, result.stderr);
240
+ const profile = JSON.parse(fs.readFileSync(path.join(dir, "profile.json"), "utf8"));
241
+ const entries = profile.exports.filter((item: { export: string }) => item.export.startsWith("native_media"));
242
+ assert.deepEqual(entries.map((item: { export: string; params: string[]; returns: string }) => [item.export, item.params, item.returns]), [["native_media_view", ["bytes"], "bytes"], ["native_media_window_view", ["bytes", "bytes"], "bytes"]]);
243
+ const mirror = fs.readFileSync(path.join(dir, "mirror.zig"), "utf8");
244
+ for (const name of ["nativeMediaView", "nativeMediaWindowView"]) {
245
+ const wrapper = mirror.match(new RegExp(`pub fn ${name}\\([\\s\\S]*?\\n}`))![0];
246
+ assert.match(wrapper, /defer abi.frame_reset/); assert.match(wrapper, /allocator.dupe|arena.dupe/);
247
+ }
248
+ }));
@@ -0,0 +1,56 @@
1
+ //! C ABI adapter for the scriptc-compiled profile generator. Policy, export
2
+ //! signatures, validation of attestations, and JSON emission live in TypeScript.
3
+ const std = @import("std");
4
+ const sidecar_mod = @import("sidecar.zig");
5
+
6
+ pub const Error = error{ Refused, OutOfMemory };
7
+ pub const default_entry = "core_facade.ts";
8
+
9
+ const PanicSink = *const fn (?*anyopaque, [*]const u8, usize, u64) callconv(.c) void;
10
+ extern fn nsc_profile_set_panic_sink(PanicSink, ?*anyopaque) void;
11
+ extern fn nsc_profile_init() void;
12
+ extern fn nsc_profile_collect() void;
13
+ extern fn nsc_profile_generate([*]const u8, usize, [*]const u8, usize, [*]const u8, usize, *[*]const u8, *usize) void;
14
+
15
+ fn panicSink(_: ?*anyopaque, message: [*]const u8, len: usize, _: u64) callconv(.c) void {
16
+ std.debug.print("corewire: profile generator trapped: {s}\n", .{message[0..len]});
17
+ std.process.exit(1);
18
+ }
19
+
20
+ pub fn emitProfile(arena: std.mem.Allocator, sidecar: sidecar_mod.Sidecar, entry: []const u8, optimization: ?[]const u8, diags: *sidecar_mod.Diagnostics) Error![]const u8 {
21
+ if (!std.unicode.utf8ValidateSlice(entry)) return error.Refused;
22
+ if (diags.hasErrors()) return error.Refused;
23
+ // Use the already validated and projected facts, including --f64-slot
24
+ // demotions. Never reread the original sidecar across this boundary.
25
+ const input = try std.json.Stringify.valueAlloc(arena, .{
26
+ .deterministic = sidecar.deterministic,
27
+ .async_free = sidecar.async_free,
28
+ .wire_version = sidecar.wire_version,
29
+ .abi_version = sidecar.abi_version,
30
+ .model = sidecar.model,
31
+ .msg = .{ .name = sidecar.msg.name },
32
+ .has_subscriptions = sidecar.has_subscriptions,
33
+ .abi = sidecar.abi,
34
+ .integer_slots = sidecar.integer_slots,
35
+ }, .{});
36
+ const opt = optimization orelse "";
37
+ nsc_profile_set_panic_sink(panicSink, null);
38
+ nsc_profile_init();
39
+ defer nsc_profile_collect();
40
+ var ptr: [*]const u8 = undefined;
41
+ var len: usize = 0;
42
+ nsc_profile_generate(input.ptr, input.len, entry.ptr, entry.len, opt.ptr, opt.len, &ptr, &len);
43
+ const Result = struct {
44
+ output: []const u8,
45
+ diagnostics: []const struct { path: []const u8, message: []const u8 },
46
+ };
47
+ // The result arena belongs to scriptc. Copy all strings before collect
48
+ // invalidates it, so callers can retain results across repeated calls.
49
+ const result = std.json.parseFromSliceLeaky(Result, arena, ptr[0..len], .{ .allocate = .alloc_always }) catch |err| switch (err) {
50
+ error.OutOfMemory => return error.OutOfMemory,
51
+ else => @panic("corewire: invalid response from the compiled profile generator"),
52
+ };
53
+ for (result.diagnostics) |diag| diags.flag(diag.path, "{s}", .{diag.message});
54
+ if (diags.hasErrors()) return error.Refused;
55
+ return result.output;
56
+ }
@@ -0,0 +1,202 @@
1
+ // Portable compiler-profile emission with exact native-reference formatting.
2
+ export interface ProfileInput {
3
+ deterministic: boolean;
4
+ async_free: boolean;
5
+ wire_version: number;
6
+ abi_version: number;
7
+ model: string;
8
+ msg: { name: string };
9
+ has_subscriptions: boolean;
10
+ abi: { prefix: string; exports: string[]; snapshot_format: number };
11
+ integer_slots: { slot: string; class: string }[];
12
+ }
13
+
14
+ export interface Diagnostic { path: string; message: string }
15
+ export interface ProfileResult { output: string; diagnostics: Diagnostic[] }
16
+ interface Signature { suffix: string; name: string; params: string[] }
17
+ interface Fence { selector: string; value: string; teaching: string }
18
+
19
+ // Match corewire's JSON spelling, including control bytes that JSON.stringify
20
+ // normally shortens to \b and \f. Non-ASCII text stays literal UTF-8.
21
+ function quote(text: string): string {
22
+ let out = '"';
23
+ let start = 0;
24
+ for (let i = 0; i < text.length; i++) {
25
+ const code = text.charCodeAt(i);
26
+ let escaped = "";
27
+ if (code === 34) escaped = '\\"';
28
+ else if (code === 92) escaped = "\\\\";
29
+ else if (code === 10) escaped = "\\n";
30
+ else if (code === 13) escaped = "\\r";
31
+ else if (code === 9) escaped = "\\t";
32
+ else if (code < 32) escaped = "\\u00" + "0123456789abcdef".charAt(code >> 4) + "0123456789abcdef".charAt(code & 15);
33
+ else continue;
34
+ // Copy whole Unicode spans, never isolated UTF-16 surrogate halves.
35
+ out += text.slice(start, i) + escaped;
36
+ start = i + 1;
37
+ }
38
+ return out + text.slice(start) + '"';
39
+ }
40
+
41
+ export function emitProfile(sidecar: ProfileInput, entry: string, optimization: string): ProfileResult {
42
+ const diagnostics: Diagnostic[] = [];
43
+ if (!sidecar.deterministic) diagnostics.push({
44
+ path: "deterministic",
45
+ message: "the contract attests deterministic: false, but this profile enforces the determinism fences and a core that compiles under them attests true by construction — build the core under this profile and regenerate from the contract it co-emits",
46
+ });
47
+ if (!sidecar.async_free) diagnostics.push({
48
+ path: "async_free",
49
+ message: "the contract attests async_free: false, but this profile's compilation mode is structurally async-free — a core reaching async surface refuses under it, so this contract cannot have come from the profile it asks for; remove the async surface and regenerate the contract",
50
+ });
51
+ if (diagnostics.length > 0) return { output: "", diagnostics };
52
+
53
+ const prefix = sidecar.abi.prefix;
54
+ let out = '{\n "profile_format": 1,\n "name": "native-sdk-core",\n "entry": ' + quote(entry) + ',\n "emission": "llvm",';
55
+ // The original projection places the optional optimization on this line.
56
+ if (optimization !== "") out += ' "optimization": ' + quote(optimization) + ',\n';
57
+ out += ' "abi": {\n "prefix": ' + quote(prefix)
58
+ + ',\n "init_symbol": ' + quote(prefix + "init")
59
+ + ',\n "sink_register_symbol": ' + quote(prefix + "set_panic_sink")
60
+ + ',\n "collect_symbol": ' + quote(prefix + "collect")
61
+ + ',\n "result_reset_symbol": ' + quote(prefix + "frame_reset")
62
+ + '\n },\n "exports": [\n';
63
+ let first = true;
64
+ for (const suffix of sidecar.abi.exports) {
65
+ for (const signature of signatures) {
66
+ if (signature.suffix !== suffix) continue;
67
+ if (!first) out += ',\n';
68
+ first = false;
69
+ out += ' { "export": ' + quote(signature.name) + ', "symbol": ' + quote(prefix + suffix) + ', "params": [';
70
+ for (let i = 0; i < signature.params.length; i++) {
71
+ if (i !== 0) out += ', ';
72
+ out += quote(signature.params[i]);
73
+ }
74
+ out += '], "returns": "bytes" }';
75
+ break;
76
+ }
77
+ }
78
+ out += '\n ],\n "sidecar": {\n "path": "core.contract.json",\n "wire_version": ' + sidecar.wire_version
79
+ + ',\n "abi_version": ' + sidecar.abi_version
80
+ + ',\n "snapshot_format": ' + sidecar.abi.snapshot_format
81
+ + ',\n "build_id_symbol": ' + quote(prefix + "build_id")
82
+ + ',\n "abi_version_symbol": ' + quote(prefix + "abi_version")
83
+ + ',\n "model": ' + quote(sidecar.model)
84
+ + ',\n "msg": ' + quote(sidecar.msg.name)
85
+ + ',\n "init_export": "init",\n "update_export": "coreUpdate",\n';
86
+ if (sidecar.has_subscriptions) out += ' "subscriptions_export": "coreSubscriptions",\n';
87
+ if (sidecar.integer_slots.length === 0) out += ' "integer_slots": []\n },\n';
88
+ else {
89
+ out += ' "integer_slots": [\n';
90
+ for (let i = 0; i < sidecar.integer_slots.length; i++) {
91
+ const slot = sidecar.integer_slots[i];
92
+ out += ' { "slot": ' + quote(slot.slot) + ', "class": ' + quote(slot.class) + ' }';
93
+ if (i + 1 !== sidecar.integer_slots.length) out += ',';
94
+ out += '\n';
95
+ }
96
+ out += ' ]\n },\n';
97
+ }
98
+ out += ' "determinism": {\n "teachings": {\n';
99
+ for (let i = 0; i < teachings.length; i++) {
100
+ out += ' ' + quote(teachings[i].code) + ': ' + quote(teachings[i].text);
101
+ if (i + 1 !== teachings.length) out += ',';
102
+ out += '\n';
103
+ }
104
+ out += ' },\n "remediations": {\n';
105
+ for (let i = 0; i < remediations.length; i++) {
106
+ out += ' ' + quote(remediations[i].code) + ': ' + quote(remediations[i].text);
107
+ if (i + 1 !== remediations.length) out += ',';
108
+ out += '\n';
109
+ }
110
+ out += ' },\n "fences": [\n';
111
+ for (let i = 0; i < fences.length; i++) {
112
+ const fence = fences[i];
113
+ out += ' { ' + quote(fence.selector) + ': ' + quote(fence.value) + ', "teaching": ' + quote(fence.teaching) + ' }';
114
+ if (i + 1 !== fences.length) out += ',';
115
+ out += '\n';
116
+ }
117
+ out += ' ]\n }\n}\n';
118
+ return { output: out, diagnostics };
119
+ }
120
+
121
+ const signatures: Signature[] = [
122
+ { suffix: "boot_cmd", name: "boot_cmd", params: [] },
123
+ { suffix: "dispatch_void", name: "dispatch_void", params: ["u8"] },
124
+ { suffix: "dispatch_bytes", name: "dispatch_bytes", params: ["u8", "bytes"] },
125
+ { suffix: "dispatch_number", name: "dispatch_number", params: ["u8", "f64"] },
126
+ { suffix: "dispatch_number_bytes", name: "dispatch_number_bytes", params: ["u8", "f64", "bytes"] },
127
+ { suffix: "dispatch_bool", name: "dispatch_bool", params: ["u8", "u8"] },
128
+ { suffix: "dispatch_enum", name: "dispatch_enum", params: ["u8", "u32"] },
129
+ { suffix: "dispatch_record", name: "dispatch_record", params: ["u8", "bytes"] },
130
+ { suffix: "dispatch_text_input", name: "dispatch_text_input", params: ["u8", "bytes"] },
131
+ { suffix: "dispatch_scroll_state", name: "dispatch_scroll_state", params: ["u8", "f64", "f64", "f64", "f64", "f64", "f64", "f64", "f64"] },
132
+ { suffix: "subscriptions", name: "abi_subscriptions", params: [] },
133
+ { suffix: "model_snapshot", name: "model_snapshot", params: [] },
134
+ { suffix: "persist_snapshot", name: "persist_snapshot", params: [] },
135
+ { suffix: "restore_model", name: "restore_model", params: ["bytes"] },
136
+ { suffix: "migrate_model", name: "migrate_model", params: ["bytes", "f64"] },
137
+ { suffix: "helper_call", name: "helper_call", params: ["u32", "bytes"] },
138
+ { suffix: "command_msg", name: "abi_command_msg", params: ["bytes"] },
139
+ { suffix: "frame_msg", name: "abi_frame_msg", params: ["f64", "f64", "f64", "f64"] },
140
+ { suffix: "frame_msg_ns", name: "abi_frame_msg_ns", params: ["f64", "f64", "f64", "f64", "bytes", "bytes"] },
141
+ { suffix: "key_msg", name: "abi_key_msg", params: ["bytes", "u8", "u8", "u8", "u8"] },
142
+ { suffix: "pinch_msg", name: "abi_pinch_msg", params: ["f64", "bytes", "u32", "f64", "f64", "f64"] },
143
+ { suffix: "drop_msg", name: "abi_drop_msg", params: ["bytes"] },
144
+ { suffix: "native_view", name: "native_view", params: [] },
145
+ { suffix: "native_media_view", name: "native_media_view", params: ["bytes"] },
146
+ { suffix: "native_media_window_view", name: "native_media_window_view", params: ["bytes", "bytes"] },
147
+ { suffix: "native_window_view", name: "native_window_view", params: ["bytes"] },
148
+ { suffix: "native_radio_policy", name: "native_radio_policy", params: ["bytes"] },
149
+ { suffix: "native_tabs_policy", name: "native_tabs_policy", params: ["bytes"] },
150
+ { suffix: "native_tree_policy", name: "native_tree_policy", params: ["bytes"] },
151
+ { suffix: "native_list_policy", name: "native_list_policy", params: ["bytes"] },
152
+ { suffix: "native_menu_policy", name: "native_menu_policy", params: ["bytes"] },
153
+ { suffix: "native_toggle_policy", name: "native_toggle_policy", params: ["bytes"] },
154
+ { suffix: "native_accordion_policy", name: "native_accordion_policy", params: ["bytes"] },
155
+ { suffix: "native_slider_policy", name: "native_slider_policy", params: ["bytes"] },
156
+ { suffix: "native_split_policy", name: "native_split_policy", params: ["bytes"] },
157
+ { suffix: "native_scroll_policy", name: "native_scroll_policy", params: ["bytes"] },
158
+ { suffix: "native_resizable_policy", name: "native_resizable_policy", params: ["bytes"] },
159
+ { suffix: "native_text_policy", name: "native_text_policy", params: ["bytes"] },
160
+ { suffix: "native_timer_policy", name: "native_timer_policy", params: ["bytes"] },
161
+ { suffix: "native_db_policy", name: "native_db_policy", params: ["bytes"] },
162
+ { suffix: "native_effect_policy", name: "native_effect_policy", params: ["bytes"] },
163
+ { suffix: "native_stream_policy", name: "native_stream_policy", params: ["bytes"] },
164
+ { suffix: "native_window_policy", name: "native_window_policy", params: ["bytes"] },
165
+ { suffix: "native_theme_policy", name: "native_theme_policy", params: ["bytes"] },
166
+ { suffix: "native_status_policy", name: "native_status_policy", params: ["bytes"] },
167
+ { suffix: "native_virtual_requests", name: "native_virtual_requests", params: ["bytes", "bytes"] },
168
+ { suffix: "native_virtual_view", name: "native_virtual_view", params: ["bytes", "bytes", "bytes"] },
169
+ ];
170
+
171
+ const randomness_teaching = "randomness is an effect: the core requests it through a command and the value arrives as a Msg, so a recorded session replays it exactly.";
172
+ const network_teaching = "network is an effect: declare requests as commands (Cmd.fetch, Cmd.request) and responses arrive as Msgs.";
173
+ const clock_teaching = "the wall clock is an effect: read it through the host's journaled clock — Cmd.now, Cmd.delay, and Sub.timer deliver fire times as Msgs, so a recorded session replays them exactly.";
174
+
175
+ // RELEASE-PINNED DATA: these selectors must resolve to runtime-deniable
176
+ // entries in the pinned scriptc surface manifest. Folded constants remain
177
+ // available. Module-only http/https/dgram/dns and folded worker/cluster
178
+ // members cannot be fenced by this release.
179
+ const fences: Fence[] = [
180
+ { selector: "id", value: "stdlib.math.random", teaching: randomness_teaching },
181
+ { selector: "id", value: "node-builtin.crypto.randomBytes", teaching: randomness_teaching },
182
+ { selector: "id", value: "node-builtin.crypto.randomUUID", teaching: randomness_teaching },
183
+ { selector: "prefix", value: "stdlib.date.", teaching: clock_teaching },
184
+ { selector: "prefix", value: "node-builtin.perf_hooks.", teaching: clock_teaching },
185
+ { selector: "prefix", value: "node-builtin.fs.", teaching: "files are effects: declare reads and writes as commands (Cmd.readFile, Cmd.writeFile) and results arrive as Msgs." },
186
+ { selector: "prefix", value: "node-builtin.net.", teaching: network_teaching },
187
+ { selector: "prefix", value: "node-builtin.http2.", teaching: network_teaching },
188
+ { selector: "prefix", value: "node-builtin.tls.", teaching: network_teaching },
189
+ { selector: "prefix", value: "node-builtin.child_process.", teaching: "processes are effects: run them through Cmd.spawn and their output arrives as Msgs." },
190
+ { selector: "prefix", value: "node-builtin.timers.", teaching: "timers are effects: schedule Cmd.delay or Sub.timer and fire times arrive as Msgs through the host's journaled clock." },
191
+ { selector: "prefix", value: "node-builtin.os.", teaching: "machine and session facts are host inputs: they reach a core as journaled Msgs, never as ambient reads." },
192
+ { selector: "prefix", value: "node-builtin.process.", teaching: "process and environment facts are host inputs: environment values arrive as journaled Msgs through the env channel, and every other session fact reaches a core only as a host-delivered Msg." },
193
+ ];
194
+
195
+ const teachings: { code: string; text: string }[] = [
196
+ { code: "async", text: "async, promises, and timer callbacks are unavailable in an app core: the host executes effects — declare a command (Cmd.fetch, Cmd.delay) or a subscription (Sub.timer) and results arrive as Msgs." },
197
+ ];
198
+
199
+ const remediations: { code: string; text: string }[] = [
200
+ { code: "SC4013", text: "rebuild the app: an exception escaping a core entry is contract skew between the compiled core and its host bindings, and one build regenerates both from one contract." },
201
+ { code: "SC4017", text: "restart the app process: a trapped core is poisoned and never resumes in place, and the recorded session replays deterministically." },
202
+ ];
@@ -0,0 +1,29 @@
1
+ {
2
+ "profile_format": 1,
3
+ "name": "native-sdk-profile-generator",
4
+ "entry": "emit_profile.ts",
5
+ "emission": "llvm",
6
+ "optimization": "release",
7
+ "abi": {
8
+ "prefix": "nsc_profile_",
9
+ "init_symbol": "nsc_profile_init",
10
+ "sink_register_symbol": "nsc_profile_set_panic_sink",
11
+ "collect_symbol": "nsc_profile_collect",
12
+ "result_reset_symbol": "nsc_profile_reset"
13
+ },
14
+ "exports": [
15
+ { "export": "generate", "symbol": "nsc_profile_generate", "params": ["string", "string", "string"], "returns": "string" },
16
+ { "export": "generateServices", "symbol": "nsc_profile_generate_services", "params": ["string", "string", "string"], "returns": "string" },
17
+ { "export": "validateServices", "symbol": "nsc_profile_validate_services", "params": ["string"], "returns": "string" },
18
+ { "export": "corePolicy", "symbol": "nsc_profile_core_policy", "params": ["string", "string"], "returns": "string" },
19
+ { "export": "generateMirror", "symbol": "nsc_profile_generate_mirror", "params": ["string"], "returns": "string" },
20
+ { "export": "generateFacade", "symbol": "nsc_profile_generate_facade", "params": ["string"], "returns": "string" },
21
+ { "export": "invocationPlan", "symbol": "nsc_profile_invocation_plan", "params": ["string"], "returns": "string" },
22
+ { "export": "invocationAliases", "symbol": "nsc_profile_invocation_aliases", "params": ["string"], "returns": "string" },
23
+ { "export": "coreInvocation", "symbol": "nsc_profile_core_invocation", "params": ["string"], "returns": "string" },
24
+ { "export": "effectiveSidecar", "symbol": "nsc_profile_effective_sidecar", "params": ["string"], "returns": "string" },
25
+ { "export": "contractIntake", "symbol": "nsc_profile_contract_intake", "params": ["string", "string"], "returns": "string" },
26
+ { "export": "entryPolicy", "symbol": "nsc_profile_entry_policy", "params": ["string"], "returns": "string" },
27
+ { "export": "filesystemPolicy", "symbol": "nsc_profile_filesystem_policy", "params": ["string"], "returns": "string" }
28
+ ]
29
+ }