@native-sdk/cli 0.10.1 → 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 (462) 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 +1796 -83
  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/native-ui/SKILL.md +76 -17
  130. package/skill-data/ts-core/SKILL.md +113 -9
  131. package/skill-data/ts-services/SKILL.md +1 -1
  132. package/skill-data/ts-services/references/service-surface.md +264 -144
  133. package/src/app_runner/root.zig +25 -12
  134. package/src/app_runner/ts_compiled_view.zig +1631 -0
  135. package/src/app_runner/ts_core_main.zig +143 -10
  136. package/src/app_runner/ts_core_mobile.zig +24 -12
  137. package/src/automation/server.zig +1 -3
  138. package/src/automation/snapshot.zig +9 -637
  139. package/src/automation/snapshot_reference.zig +656 -0
  140. package/src/automation/snapshot_serialization.zig +566 -0
  141. package/src/platform/linux/gtk_host.c +36 -24
  142. package/src/platform/linux/gtk_pixels.h +118 -0
  143. package/src/platform/linux/gtk_pixels_test.c +241 -0
  144. package/src/platform/linux/root.zig +2 -0
  145. package/src/platform/macos/appkit_host.m +188 -30
  146. package/src/platform/macos/pointer_motion_test.m +96 -0
  147. package/src/platform/macos/scroll_driver_test.m +105 -0
  148. package/src/platform/macos/spectrum_bins.h +34 -0
  149. package/src/platform/macos/spectrum_bins_test.c +56 -0
  150. package/src/platform/macos/text_keyboard_test.m +80 -0
  151. package/src/platform/macos/widget_focus_test.m +66 -0
  152. package/src/platform/null_platform.zig +26 -2
  153. package/src/platform/null_platform_tests.zig +13 -0
  154. package/src/platform/root.zig +1 -0
  155. package/src/platform/types.zig +13 -0
  156. package/src/platform/windows/root.zig +2 -0
  157. package/src/platform/windows/webview2_host.cpp +7 -2
  158. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  159. package/src/primitives/app_manifest/root.zig +2 -0
  160. package/src/primitives/app_manifest/tests.zig +4 -1
  161. package/src/primitives/app_manifest/validation.zig +2 -0
  162. package/src/primitives/canvas/a11y_audit.zig +3 -1
  163. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  164. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  165. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  166. package/src/primitives/canvas/code_content_policy.zig +162 -0
  167. package/src/primitives/canvas/commands.zig +29 -1
  168. package/src/primitives/canvas/component_composition.zig +125 -0
  169. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  170. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  171. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  172. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  173. package/src/primitives/canvas/control_command_policy.zig +75 -0
  174. package/src/primitives/canvas/control_content_policy.zig +90 -0
  175. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  176. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  177. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  178. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  179. package/src/primitives/canvas/events.zig +1027 -1
  180. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  181. package/src/primitives/canvas/frame.zig +92 -23
  182. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  183. package/src/primitives/canvas/gpu.zig +10 -0
  184. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  185. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  186. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  187. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  188. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  189. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  190. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  191. package/src/primitives/canvas/layout_audit.zig +5 -2
  192. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  193. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  194. package/src/primitives/canvas/markdown.zig +13 -3
  195. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  196. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  197. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  198. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  199. package/src/primitives/canvas/reference.zig +12 -6
  200. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  201. package/src/primitives/canvas/render.zig +48 -0
  202. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  203. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  204. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  205. package/src/primitives/canvas/render_effects.zig +14 -0
  206. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  207. package/src/primitives/canvas/render_images.zig +14 -0
  208. package/src/primitives/canvas/render_layers.zig +14 -0
  209. package/src/primitives/canvas/render_override_policy.zig +119 -0
  210. package/src/primitives/canvas/render_paths.zig +14 -0
  211. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  212. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  213. package/src/primitives/canvas/root.zig +100 -0
  214. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  215. package/src/primitives/canvas/serialization.zig +8 -1
  216. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  217. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  218. package/src/primitives/canvas/terminal_grid.zig +10 -696
  219. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  220. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  221. package/src/primitives/canvas/text.zig +1 -0
  222. package/src/primitives/canvas/text_atlas.zig +113 -0
  223. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  224. package/src/primitives/canvas/text_document_policy.zig +120 -0
  225. package/src/primitives/canvas/text_layout.zig +51 -2
  226. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  227. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  228. package/src/primitives/canvas/text_layout_types.zig +3 -0
  229. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  230. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  231. package/src/primitives/canvas/text_metrics.zig +23 -0
  232. package/src/primitives/canvas/text_query_policy.zig +156 -0
  233. package/src/primitives/canvas/text_run_policy.zig +252 -0
  234. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  235. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  236. package/src/primitives/canvas/text_spans.zig +280 -8
  237. package/src/primitives/canvas/text_tests.zig +10 -0
  238. package/src/primitives/canvas/tokens.zig +38 -0
  239. package/src/primitives/canvas/ui.zig +250 -83
  240. package/src/primitives/canvas/ui_markup.zig +139 -33
  241. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  242. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  243. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  244. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  245. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  246. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  247. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  248. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  249. package/src/primitives/canvas/ui_schema.zig +13 -1
  250. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  251. package/src/primitives/canvas/ui_tests.zig +1 -0
  252. package/src/primitives/canvas/vector.zig +36 -2
  253. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  254. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  255. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  256. package/src/primitives/canvas/virtual_extents.zig +99 -3
  257. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  258. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  259. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  260. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  261. package/src/primitives/canvas/widget_layout.zig +673 -128
  262. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  263. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  264. package/src/primitives/canvas/widget_metrics.zig +45 -6
  265. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  266. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  267. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  268. package/src/primitives/canvas/widget_render.zig +744 -74
  269. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  270. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  271. package/src/primitives/canvas/widget_render_style.zig +94 -0
  272. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  273. package/src/primitives/canvas/widget_routing.zig +75 -0
  274. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  275. package/src/primitives/canvas/widget_runtime.zig +20 -1
  276. package/src/primitives/canvas/widget_semantics.zig +25 -0
  277. package/src/primitives/canvas/widget_text_input.zig +86 -23
  278. package/src/primitives/canvas/widget_text_select.zig +1 -0
  279. package/src/primitives/canvas/widget_tree.zig +8 -1
  280. package/src/primitives/canvas/widgets.zig +42 -12
  281. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  282. package/src/root.zig +21 -0
  283. package/src/runtime/accessibility_policy.zig +122 -0
  284. package/src/runtime/api.zig +28 -0
  285. package/src/runtime/app_dispatch_policy.zig +68 -0
  286. package/src/runtime/authorization_policy.zig +150 -0
  287. package/src/runtime/automation_command_policy.zig +241 -0
  288. package/src/runtime/automation_interaction_policy.zig +107 -0
  289. package/src/runtime/automation_snapshot.zig +52 -22
  290. package/src/runtime/automation_snapshot_reference.zig +290 -0
  291. package/src/runtime/automation_widget_dispatch.zig +267 -355
  292. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  293. package/src/runtime/blob_policy.zig +58 -0
  294. package/src/runtime/blob_reference.zig +64 -0
  295. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  296. package/src/runtime/builtin_bridge.zig +180 -44
  297. package/src/runtime/builtin_coordination_policy.zig +121 -0
  298. package/src/runtime/callback_policy_test_reference.zig +97 -0
  299. package/src/runtime/canvas_drag_policy.zig +94 -0
  300. package/src/runtime/canvas_fonts.zig +38 -10
  301. package/src/runtime/canvas_frame.zig +590 -134
  302. package/src/runtime/canvas_frame_helpers.zig +1 -0
  303. package/src/runtime/canvas_hover_policy.zig +131 -0
  304. package/src/runtime/canvas_images.zig +59 -30
  305. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  306. package/src/runtime/canvas_limits.zig +1 -1
  307. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  308. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  309. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  310. package/src/runtime/canvas_widget_display.zig +110 -9
  311. package/src/runtime/canvas_widget_events.zig +718 -328
  312. package/src/runtime/canvas_widget_runtime.zig +437 -81
  313. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  314. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  315. package/src/runtime/canvas_widget_state.zig +93 -56
  316. package/src/runtime/channel_sources.zig +80 -0
  317. package/src/runtime/command_policy.zig +161 -0
  318. package/src/runtime/component_policy.zig +83 -0
  319. package/src/runtime/core.zig +156 -6
  320. package/src/runtime/desktop_files.zig +189 -0
  321. package/src/runtime/effects.zig +466 -29
  322. package/src/runtime/effects_tests.zig +28 -0
  323. package/src/runtime/file_policy_test_reference.zig +113 -0
  324. package/src/runtime/flow.zig +418 -341
  325. package/src/runtime/flow_reference.zig +1426 -0
  326. package/src/runtime/font_registry_policy.zig +72 -0
  327. package/src/runtime/frame_profile.zig +24 -33
  328. package/src/runtime/gpu_surface_events.zig +97 -35
  329. package/src/runtime/host_event_pump.zig +303 -0
  330. package/src/runtime/host_event_pump_reference.zig +268 -0
  331. package/src/runtime/host_flow_policy.zig +155 -0
  332. package/src/runtime/host_input_regions_policy.zig +156 -0
  333. package/src/runtime/image_registry_policy.zig +94 -0
  334. package/src/runtime/input_composition_policy.zig +138 -0
  335. package/src/runtime/journal_policy.zig +66 -0
  336. package/src/runtime/journal_reference.zig +53 -0
  337. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  338. package/src/runtime/markup_development_policy.zig +91 -0
  339. package/src/runtime/media_surface.zig +40 -1
  340. package/src/runtime/motion_sampling_policy.zig +159 -0
  341. package/src/runtime/recording_policy.zig +42 -0
  342. package/src/runtime/render_animation_policy.zig +206 -0
  343. package/src/runtime/replay_policy.zig +66 -0
  344. package/src/runtime/replay_policy_reference.zig +326 -0
  345. package/src/runtime/replay_progress_policy.zig +64 -0
  346. package/src/runtime/replay_progress_reference.zig +34 -0
  347. package/src/runtime/request_policy_test_reference.zig +188 -0
  348. package/src/runtime/root.zig +13 -0
  349. package/src/runtime/session_blobs.zig +157 -58
  350. package/src/runtime/session_blobs_reference.zig +692 -0
  351. package/src/runtime/session_codec.zig +361 -0
  352. package/src/runtime/session_codec_reference.zig +1027 -0
  353. package/src/runtime/session_journal.zig +246 -983
  354. package/src/runtime/session_record.zig +224 -45
  355. package/src/runtime/session_replay.zig +157 -415
  356. package/src/runtime/session_tests.zig +552 -0
  357. package/src/runtime/shell_admission_policy.zig +225 -0
  358. package/src/runtime/shell_coordination_policy.zig +138 -0
  359. package/src/runtime/shell_layout.zig +126 -1
  360. package/src/runtime/snapshot_policy.zig +60 -0
  361. package/src/runtime/snapshot_reference.zig +64 -0
  362. package/src/runtime/state.zig +16 -0
  363. package/src/runtime/status_validation.zig +190 -0
  364. package/src/runtime/system_admission_policy.zig +140 -0
  365. package/src/runtime/system_services.zig +46 -36
  366. package/src/runtime/tests.zig +1 -0
  367. package/src/runtime/ts_canvas_hooks.zig +261 -0
  368. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  369. package/src/runtime/ts_canvas_icons.zig +234 -0
  370. package/src/runtime/ts_core_host.zig +2325 -411
  371. package/src/runtime/ts_core_host_tests.zig +1982 -0
  372. package/src/runtime/ts_test_host.zig +699 -0
  373. package/src/runtime/ts_ui_app.zig +1087 -45
  374. package/src/runtime/ui_app.zig +1117 -629
  375. package/src/runtime/ui_app_provenance.zig +147 -5
  376. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  377. package/src/runtime/ui_app_tests.zig +619 -9
  378. package/src/runtime/ui_app_window_tests.zig +89 -0
  379. package/src/runtime/view.zig +25 -0
  380. package/src/runtime/view_canvas.zig +30 -6
  381. package/src/runtime/view_coordination_policy.zig +147 -0
  382. package/src/runtime/view_widget_control.zig +51 -14
  383. package/src/runtime/view_widget_scroll.zig +16 -5
  384. package/src/runtime/view_widget_text.zig +153 -68
  385. package/src/runtime/view_widget_tree.zig +460 -56
  386. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  387. package/src/runtime/widget_motion_policy.zig +238 -0
  388. package/src/runtime/window_command_bridge_tests.zig +63 -0
  389. package/src/runtime/window_lifecycle_policy.zig +127 -0
  390. package/src/runtime/window_storage.zig +74 -8
  391. package/src/runtime/window_view_runtime.zig +148 -33
  392. package/src/runtime/window_views.zig +163 -10
  393. package/src/tooling/components/identity_tests.zig +62 -36
  394. package/src/tooling/components/stepper.native +24 -0
  395. package/src/tooling/components/stepper.zig +0 -19
  396. package/src/tooling/components/timeline-item.native +22 -0
  397. package/src/tooling/components/timeline.native +5 -3
  398. package/src/tooling/components/timeline_item.zig +0 -32
  399. package/src/tooling/eject_components.zig +76 -8
  400. package/src/tooling/ios.zig +66 -12
  401. package/src/tooling/manifest.zig +35 -0
  402. package/src/tooling/raw_manifest.zig +6 -0
  403. package/src/tooling/templates.zig +15 -3
  404. package/src/tooling/ts_core.zig +13 -3
  405. package/src/tooling/verbs.zig +22 -0
  406. package/tools/corewire/build_profile.mjs +54 -0
  407. package/tools/corewire/contract_intake.ts +303 -0
  408. package/tools/corewire/contract_intake.zig +82 -0
  409. package/tools/corewire/core.test.ts +166 -0
  410. package/tools/corewire/core_abi.zig +51 -0
  411. package/tools/corewire/core_cases.ts +233 -0
  412. package/tools/corewire/core_contract.ts +407 -0
  413. package/tools/corewire/core_emission.ts +136 -0
  414. package/tools/corewire/core_emission.zig +69 -0
  415. package/tools/corewire/core_goldens.json +3110 -0
  416. package/tools/corewire/core_policy.ts +14 -0
  417. package/tools/corewire/core_policy.zig +48 -0
  418. package/tools/corewire/core_projection.ts +360 -0
  419. package/tools/corewire/core_vocabulary.ts +6 -0
  420. package/tools/corewire/emit.zig +19 -1590
  421. package/tools/corewire/emit_facade.ts +714 -0
  422. package/tools/corewire/emit_facade.zig +10 -3752
  423. package/tools/corewire/emit_mirror.ts +290 -0
  424. package/tools/corewire/emit_profile.ts +50 -0
  425. package/tools/corewire/emit_service.ts +331 -0
  426. package/tools/corewire/emit_service.zig +23 -842
  427. package/tools/corewire/entry.test.ts +95 -0
  428. package/tools/corewire/entry_coordination.ts +127 -0
  429. package/tools/corewire/entry_coordination.zig +190 -0
  430. package/tools/corewire/facade_templates.ts +85 -0
  431. package/tools/corewire/filesystem.test.ts +166 -0
  432. package/tools/corewire/filesystem_coordination.ts +213 -0
  433. package/tools/corewire/filesystem_coordination.zig +245 -0
  434. package/tools/corewire/intake.test.ts +35 -0
  435. package/tools/corewire/intake_cases.ts +55 -0
  436. package/tools/corewire/intake_goldens.json +12237 -0
  437. package/tools/corewire/invocation.test.ts +24 -0
  438. package/tools/corewire/invocation.ts +175 -0
  439. package/tools/corewire/invocation.zig +136 -0
  440. package/tools/corewire/invocation_cases.ts +60 -0
  441. package/tools/corewire/invocation_fixture.ts +33 -0
  442. package/tools/corewire/invocation_goldens.json +1143 -0
  443. package/tools/corewire/invocation_tests.zig +111 -0
  444. package/tools/corewire/invocation_usage.ts +2 -0
  445. package/tools/corewire/lossless_projection.ts +96 -0
  446. package/tools/corewire/main.zig +7 -680
  447. package/tools/corewire/main_reference.zig +415 -0
  448. package/tools/corewire/mirror_templates.ts +55 -0
  449. package/tools/corewire/profile.test.ts +248 -0
  450. package/tools/corewire/profile.zig +56 -0
  451. package/tools/corewire/profile_emission.ts +202 -0
  452. package/tools/corewire/profile_library.json +29 -0
  453. package/tools/corewire/profile_tests.zig +136 -0
  454. package/tools/corewire/service.test.ts +75 -0
  455. package/tools/corewire/service_cases.ts +61 -0
  456. package/tools/corewire/service_contract.zig +40 -146
  457. package/tools/corewire/service_goldens.json +650 -0
  458. package/tools/corewire/service_projection.zig +52 -0
  459. package/tools/corewire/service_templates.ts +14 -0
  460. package/tools/corewire/shim_rt.zig +9 -0
  461. package/tools/corewire/sidecar.zig +267 -1438
  462. package/tools/corewire/emit_profile.zig +0 -521
@@ -10,7 +10,7 @@
10
10
  //! mirror module the app wiring imports (see emit.zig for what the
11
11
  //! mirror carries). `--facade` writes the TypeScript projection,
12
12
  //! `--profile` the library-mode compiler profile that builds it
13
- //! (emit_profile.zig). `--check` validates and stops — the checker-tier
13
+ //! (scriptc-compiled emit_profile.ts). `--check` validates and stops — the checker-tier
14
14
  //! entry point.
15
15
  //!
16
16
  //! The build stages the output beside tools/corewire/shim_rt.zig and
@@ -18,685 +18,12 @@
18
18
  //! relatively, the way transpiler output imports its staged rt.zig.
19
19
 
20
20
  const std = @import("std");
21
- const sidecar_mod = @import("sidecar.zig");
22
- const emit_mod = @import("emit.zig");
23
- const emit_facade_mod = @import("emit_facade.zig");
24
- const emit_profile_mod = @import("emit_profile.zig");
25
- const service_contract_mod = @import("service_contract.zig");
26
- const emit_service_mod = @import("emit_service.zig");
27
-
28
- const usage =
29
- \\usage: corewire --sidecar <core.contract.json> (--out <core_shim.zig> | --facade <core_facade.ts> | --profile <core_profile.json> | --effective-sidecar <effective.contract.json> | --check) [--f64-slot <path>]...
30
- \\
31
- \\Generate the Zig mirror module (core_shim.zig), the TypeScript
32
- \\projection (core_facade.ts), the library-mode compiler profile
33
- \\(core_profile.json), and/or the effective sidecar after projection
34
- \\overrides for a compiled core, or validate the input sidecar alone
35
- \\(--check). Generation outputs combine; --check stands alone.
36
- \\
37
- \\--f64-slot <path> carries the named attested integer slot as f64 for
38
- \\this whole invocation (facade, profile, and mirror alike): a slot
39
- \\whose values reach the f64-exact boundary (2^53) has no honest i64
40
- \\declaration on the compiled side, so the caller states the demotion
41
- \\explicitly and every projection stays consistent. The path must name
42
- \\an attested slot — a misspelling would silently demote nothing.
43
- \\
44
- ;
21
+ const entry = @import("entry_coordination.zig");
45
22
 
46
23
  pub fn main(init: std.process.Init) !void {
47
- const arena = init.arena.allocator();
48
- const args = try init.minimal.args.toSlice(arena);
49
-
50
- var stderr_buffer: [4096]u8 = undefined;
51
- var stderr_writer = std.Io.File.stderr().writerStreaming(init.io, &stderr_buffer);
52
- const stderr = &stderr_writer.interface;
53
-
54
- if (try serviceProjection(init, args, stderr)) return;
55
-
56
- var sidecar_path: ?[]const u8 = null;
57
- var out_path: ?[]const u8 = null;
58
- var facade_path: ?[]const u8 = null;
59
- var profile_path: ?[]const u8 = null;
60
- var effective_sidecar_path: ?[]const u8 = null;
61
- var check_only = false;
62
- var optimization: ?[]const u8 = null;
63
- var f64_slots: std.ArrayListUnmanaged([]const u8) = .empty;
64
- var index: usize = 1;
65
- while (index < args.len) : (index += 1) {
66
- const arg = args[index];
67
- if (std.mem.eql(u8, arg, "--sidecar") and index + 1 < args.len) {
68
- index += 1;
69
- sidecar_path = args[index];
70
- } else if (std.mem.eql(u8, arg, "--out") and index + 1 < args.len) {
71
- index += 1;
72
- out_path = args[index];
73
- } else if (std.mem.eql(u8, arg, "--facade") and index + 1 < args.len) {
74
- index += 1;
75
- facade_path = args[index];
76
- } else if (std.mem.eql(u8, arg, "--profile") and index + 1 < args.len) {
77
- index += 1;
78
- profile_path = args[index];
79
- } else if (std.mem.eql(u8, arg, "--effective-sidecar") and index + 1 < args.len) {
80
- index += 1;
81
- effective_sidecar_path = args[index];
82
- } else if (std.mem.eql(u8, arg, "--f64-slot") and index + 1 < args.len) {
83
- index += 1;
84
- try f64_slots.append(arena, args[index]);
85
- } else if (std.mem.eql(u8, arg, "--check")) {
86
- check_only = true;
87
- } else if (std.mem.eql(u8, arg, "--optimization") and index + 1 < args.len) {
88
- index += 1;
89
- optimization = args[index];
90
- } else {
91
- try stderr.print("corewire: unknown argument \"{s}\"\n\n{s}", .{ arg, usage });
92
- try stderr.flush();
93
- std.process.exit(2);
94
- }
95
- }
96
- const input = sidecar_path orelse {
97
- try stderr.print("{s}", .{usage});
98
- try stderr.flush();
99
- std.process.exit(2);
100
- };
101
- // Either validate-only, or at least one generation target — never
102
- // both (a checker that writes files is not a checker).
103
- const generates = out_path != null or facade_path != null or profile_path != null or effective_sidecar_path != null;
104
- if (generates == check_only) {
105
- try stderr.print("{s}", .{usage});
106
- try stderr.flush();
107
- std.process.exit(2);
108
- }
109
- // Distinct paths only: the projections must not overwrite each
110
- // other, and no output may destroy the input contract. Compared
111
- // lexically normalized (cwd-resolved, `.`/`..` folded) — filesystem
112
- // identities beyond spelling (symlinks, hard links) stay the
113
- // caller's responsibility.
114
- const input_resolved = try canonicalSpelling(init.io, arena, input);
115
- // The staging PREFIX spellings join the checked set: outputs land
116
- // by rename from exclusively-created `<path>.corewire-tmp.<nonce>`
117
- // files, and a sidecar sitting on the prefix spelling is close
118
- // enough to a claimed name to refuse outright.
119
- const paths = [_]?[]const u8{
120
- out_path,
121
- facade_path,
122
- profile_path,
123
- effective_sidecar_path,
124
- if (out_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
125
- if (facade_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
126
- if (profile_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
127
- if (effective_sidecar_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
128
- };
129
- var resolved: [paths.len]?[]const u8 = @splat(null);
130
- for (paths, 0..) |maybe_path, path_index| {
131
- const path = maybe_path orelse continue;
132
- resolved[path_index] = try canonicalSpelling(init.io, arena, path);
133
- }
134
- for (resolved, 0..) |maybe_path, path_index| {
135
- const path = maybe_path orelse continue;
136
- // Case-insensitively: the default volumes on two of the three
137
- // desktop platforms fold case, so differently-cased spellings
138
- // of one file must count as aliases everywhere (refusing a
139
- // case-only distinction on a case-sensitive volume costs
140
- // nothing anyone wants).
141
- if (std.ascii.eqlIgnoreCase(path, input_resolved)) {
142
- try stderr.print("corewire: output {s} names the sidecar itself — generating would destroy the input contract\n", .{path});
143
- try stderr.flush();
144
- std.process.exit(2);
145
- }
146
- // Spelling checks cannot see every filesystem aliasing (Unicode
147
- // case folding, links), so ask the filesystem: an output whose
148
- // path already resolves to the sidecar's own file is the same
149
- // refusal, whatever the spelling.
150
- if (sameExistingFile(init.io, path, input_resolved)) {
151
- try stderr.print("corewire: output {s} resolves to the sidecar's own file — generating would destroy the input contract\n", .{path});
152
- try stderr.flush();
153
- std.process.exit(2);
154
- }
155
- for (resolved[path_index + 1 ..]) |maybe_other| {
156
- const other = maybe_other orelse continue;
157
- if (std.ascii.eqlIgnoreCase(path, other) or sameExistingFile(init.io, path, other)) {
158
- try stderr.print("corewire: two outputs name one file ({s}) — the later projection would overwrite the earlier\n", .{path});
159
- try stderr.flush();
160
- std.process.exit(2);
161
- }
162
- }
163
- }
164
-
165
- const source = std.Io.Dir.cwd().readFileAlloc(init.io, input, arena, .limited(sidecar_mod.max_sidecar_bytes)) catch |err| {
166
- try stderr.print("corewire: cannot read {s}: {t}\n", .{ input, err });
167
- try stderr.flush();
168
- std.process.exit(1);
169
- };
170
-
171
- var diags = sidecar_mod.Diagnostics{ .arena = arena };
172
- var parsed = sidecar_mod.read(arena, source, &diags) catch |err| switch (err) {
173
- error.Refused => {
174
- try diags.write(input, stderr);
175
- try stderr.flush();
176
- std.process.exit(1);
177
- },
178
- error.OutOfMemory => return err,
179
- };
180
-
181
- // Caller-stated f64 demotions apply to the parsed contract before
182
- // any projection, so the facade's encoders, the profile's
183
- // declarations, and the attestation list stay consistent by
184
- // construction: the slot's type-table spelling rewrites to f64 and
185
- // its attestation entry drops.
186
- if (f64_slots.items.len > 0) {
187
- var kept: std.ArrayListUnmanaged(sidecar_mod.IntegerSlot) = .empty;
188
- for (f64_slots.items) |slot_path| {
189
- const listed = for (parsed.integer_slots) |slot| {
190
- if (std.mem.eql(u8, slot.slot, slot_path)) break true;
191
- } else false;
192
- if (!listed) {
193
- try stderr.print("corewire: --f64-slot {s} names no attested integer slot of this contract — a misspelling would silently demote nothing; check the contract's integer_slots\n", .{slot_path});
194
- try stderr.flush();
195
- std.process.exit(2);
196
- }
197
- if (!demoteSlotToF64(parsed, slot_path)) {
198
- try stderr.print("corewire: --f64-slot {s} does not name a record field slot (Container.field) — only record-field slots demote today; a message-arm or helper slot demotion needs its own emitter support\n", .{slot_path});
199
- try stderr.flush();
200
- std.process.exit(2);
201
- }
202
- }
203
- for (parsed.integer_slots) |slot| {
204
- const demoted = for (f64_slots.items) |slot_path| {
205
- if (std.mem.eql(u8, slot.slot, slot_path)) break true;
206
- } else false;
207
- if (!demoted) try kept.append(arena, slot);
208
- }
209
- parsed.integer_slots = kept.items;
210
- }
211
-
212
- // `--check` runs the FULL pipeline (every projection) and discards
213
- // the text: a sidecar must never pass the checker and then refuse at
214
- // generate time (emitter-level rules — emission-name collisions
215
- // above all — are part of the contract's validity).
216
- const generated: []const u8 = emit_mod.emit(arena, parsed, &diags) catch |err| switch (err) {
217
- error.Refused => {
218
- try diags.write(input, stderr);
219
- try stderr.flush();
220
- std.process.exit(1);
221
- },
222
- error.OutOfMemory => return err,
223
- };
224
- // The profile targets the facade module as its entry, so emitting a
225
- // profile runs the facade emitter's own refusal checks even when no
226
- // facade file is written — a sidecar must never yield a profile
227
- // whose referenced facade then refuses to generate.
228
- const facade: ?[]const u8 = if (check_only or facade_path != null or profile_path != null)
229
- emit_facade_mod.emitFacade(arena, parsed, &diags) catch |err| switch (err) {
230
- error.Refused => {
231
- try diags.write(input, stderr);
232
- try stderr.flush();
233
- std.process.exit(1);
234
- },
235
- error.OutOfMemory => return err,
236
- }
237
- else
238
- null;
239
- // The profile names the facade module as its entry, resolved
240
- // against the profile file's own directory (the compilation root):
241
- // when both are generated in one invocation the emitted spelling is
242
- // the --facade path made profile-relative, and the conventional
243
- // name otherwise.
244
- const profile: ?[]const u8 = if (check_only or profile_path != null) blk: {
245
- const entry = if (facade_path != null and profile_path != null)
246
- profileRelativeEntry(init, stderr, profile_path.?, facade_path.?) catch |err| switch (err) {
247
- error.Unrelatable => std.process.exit(2),
248
- else => return err,
249
- }
250
- else if (facade_path) |path|
251
- std.fs.path.basename(path)
252
- else
253
- emit_profile_mod.default_entry;
254
- // The profile is a JSON document, and JSON text carries UTF-8
255
- // only: a filename with other bytes would not survive the trip
256
- // through any conforming consumer, so it refuses here instead
257
- // of naming a file nothing can find.
258
- if (!std.unicode.utf8ValidateSlice(entry)) {
259
- try stderr.print("corewire: the profile's entry spelling \"{s}\" is not valid UTF-8 — the profile is a JSON document and JSON text carries UTF-8 only; rename the facade file\n", .{entry});
260
- try stderr.flush();
261
- std.process.exit(2);
262
- }
263
- if (optimization != null and !std.mem.eql(u8, optimization.?, "dev") and !std.mem.eql(u8, optimization.?, "release")) {
264
- try stderr.print("corewire: --optimization must be dev or release\n", .{});
265
- try stderr.flush();
266
- std.process.exit(2);
267
- }
268
- break :blk emit_profile_mod.emitProfile(arena, parsed, entry, optimization, &diags) catch |err| switch (err) {
269
- error.Refused => {
270
- try diags.write(input, stderr);
271
- try stderr.flush();
272
- std.process.exit(1);
273
- },
274
- error.OutOfMemory => return err,
275
- };
276
- } else null;
277
-
278
- // The staged contract twin: preserve the input document's complete
279
- // additive vocabulary while applying the same explicit demotions the
280
- // typed projections above consumed. This is the sidecar that truthfully
281
- // belongs beside a generated facade/profile pair.
282
- const effective_sidecar: ?[]const u8 = if (effective_sidecar_path != null)
283
- try sidecar_mod.projectF64SlotsJson(arena, source, f64_slots.items)
284
- else
285
- null;
286
-
287
- // Warnings (unknown additive fields) surface even on success.
288
- try diags.write(input, stderr);
289
- try stderr.flush();
290
-
291
- // Stage-then-commit: ALL projections write completely into
292
- // exclusively-created staging files before any rename, so a write
293
- // failure can never leave a fresh shim beside a stale sibling. The
294
- // renames remain separate filesystem operations — a failure between
295
- // them reports the files as a possibly skewed set and the nonzero
296
- // exit makes the caller regenerate; concurrent invocations aimed at
297
- // ONE output path are the caller's serialization to provide (the
298
- // build graph never shares output directories between steps).
299
- const Output = struct {
300
- flag: []const u8,
301
- path: []const u8,
302
- data: []const u8,
303
- staged: []const u8 = "",
304
- };
305
- var outputs_buffer: [4]Output = undefined;
306
- var output_count: usize = 0;
307
- if (out_path) |path| {
308
- outputs_buffer[output_count] = .{ .flag = "--out", .path = path, .data = generated };
309
- output_count += 1;
310
- }
311
- if (facade_path) |path| {
312
- outputs_buffer[output_count] = .{ .flag = "--facade", .path = path, .data = facade.? };
313
- output_count += 1;
314
- }
315
- if (profile_path) |path| {
316
- outputs_buffer[output_count] = .{ .flag = "--profile", .path = path, .data = profile.? };
317
- output_count += 1;
318
- }
319
- if (effective_sidecar_path) |path| {
320
- outputs_buffer[output_count] = .{ .flag = "--effective-sidecar", .path = path, .data = effective_sidecar.? };
321
- output_count += 1;
322
- }
323
- const outputs = outputs_buffer[0..output_count];
324
-
325
- for (outputs, 0..) |*output, output_index| {
326
- // Earlier staging files exist now, so a filesystem-level alias
327
- // of two output paths (Unicode case folding, links) gets one
328
- // more net before any rename.
329
- for (outputs[0..output_index]) |earlier| {
330
- if (sameExistingFile(init.io, output.path, earlier.path)) {
331
- for (outputs[0..output_index]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
332
- try stderr.print("corewire: {s} {s} resolves to the {s} file — the later projection would overwrite the earlier\n", .{ output.flag, output.path, earlier.flag });
333
- try stderr.flush();
334
- std.process.exit(2);
335
- }
336
- }
337
- output.staged = stageOutput(init, stderr, output.path, output.data) catch |err| {
338
- // Sibling projections were already staged; leave no stray
339
- // staging file behind ANY failure shape.
340
- for (outputs[0..output_index]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
341
- switch (err) {
342
- error.Staging => std.process.exit(1),
343
- else => return err,
344
- }
345
- };
346
- }
347
-
348
- for (outputs, 0..) |output, output_index| {
349
- // Committed outputs now EXIST, so aliases no spelling check can
350
- // see (filesystem Unicode normalization above all) finally
351
- // resolve: a target that reaches a just-committed sibling
352
- // refuses instead of replacing it.
353
- for (outputs[0..output_index]) |earlier| {
354
- if (sameExistingFile(init.io, output.path, earlier.path)) {
355
- for (outputs[output_index..]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
356
- try stderr.print("corewire: {s} {s} resolves to the file {s} just wrote — the later projection would overwrite the earlier\n", .{ output.flag, output.path, earlier.flag });
357
- try stderr.flush();
358
- std.process.exit(2);
359
- }
360
- }
361
- std.Io.Dir.cwd().rename(output.staged, std.Io.Dir.cwd(), output.path, init.io) catch |err| {
362
- for (outputs[output_index..]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
363
- if (output_index > 0) {
364
- try stderr.print("corewire: cannot write {s}: {t} — earlier projections were already replaced, so the outputs on disk may be from different generations; re-run to restore the set\n", .{ output.path, err });
365
- } else {
366
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ output.path, err });
367
- }
368
- try stderr.flush();
369
- std.process.exit(1);
370
- };
371
- }
372
- }
373
-
374
- /// The service contract is a distinct schema from core.contract.json. Keep
375
- /// its projection mode explicit so neither reader can accidentally accept a
376
- /// document from the other class.
377
- fn serviceProjection(init: std.process.Init, args: []const []const u8, stderr: *std.Io.Writer) !bool {
378
- var input: ?[]const u8 = null;
379
- var host_out: ?[]const u8 = null;
380
- var registry_out: ?[]const u8 = null;
381
- var client_out: ?[]const u8 = null;
382
- var inproc_main_out: ?[]const u8 = null;
383
- var inproc_profile_out: ?[]const u8 = null;
384
- var saw_service_flag = false;
385
- var optimization: ?[]const u8 = null;
386
- var index: usize = 1;
387
- while (index < args.len) : (index += 1) {
388
- const arg = args[index];
389
- if (std.mem.eql(u8, arg, "--services-sidecar") and index + 1 < args.len) {
390
- saw_service_flag = true;
391
- index += 1;
392
- input = args[index];
393
- } else if (std.mem.eql(u8, arg, "--service-host-main") and index + 1 < args.len) {
394
- saw_service_flag = true;
395
- index += 1;
396
- host_out = args[index];
397
- } else if (std.mem.eql(u8, arg, "--service-registry") and index + 1 < args.len) {
398
- saw_service_flag = true;
399
- index += 1;
400
- registry_out = args[index];
401
- } else if (std.mem.eql(u8, arg, "--service-client") and index + 1 < args.len) {
402
- saw_service_flag = true;
403
- index += 1;
404
- client_out = args[index];
405
- } else if (std.mem.eql(u8, arg, "--service-inproc-main") and index + 1 < args.len) {
406
- saw_service_flag = true;
407
- index += 1;
408
- inproc_main_out = args[index];
409
- } else if (std.mem.eql(u8, arg, "--service-inproc-profile") and index + 1 < args.len) {
410
- saw_service_flag = true;
411
- index += 1;
412
- inproc_profile_out = args[index];
413
- } else if (saw_service_flag and std.mem.eql(u8, arg, "--optimization") and index + 1 < args.len) {
414
- saw_service_flag = true;
415
- index += 1;
416
- optimization = args[index];
417
- } else if (saw_service_flag) {
418
- try stderr.print("corewire: unknown service projection argument \"{s}\"\n", .{arg});
419
- try stderr.flush();
420
- std.process.exit(2);
421
- }
422
- }
423
- if (!saw_service_flag) return false;
424
- if (optimization != null and !std.mem.eql(u8, optimization.?, "dev") and !std.mem.eql(u8, optimization.?, "release")) {
425
- try stderr.print("corewire: --optimization must be dev or release\n", .{});
426
- try stderr.flush();
427
- std.process.exit(2);
428
- }
429
- const sidecar_path = input orelse {
430
- try stderr.print("usage: corewire --services-sidecar <services.contract.json> [--service-host-main <service_host_main.ts>] [--service-registry <services.zig>] [--service-client <services.gen.ts>] [--service-inproc-main <service_inproc_main.ts>] [--service-inproc-profile <service_profile.json>]\n", .{});
431
- try stderr.flush();
432
- std.process.exit(2);
433
- };
434
- if (host_out == null and registry_out == null and client_out == null and inproc_main_out == null and inproc_profile_out == null) {
435
- try stderr.print("corewire: the service projection needs at least one output\n", .{});
436
- try stderr.flush();
437
- std.process.exit(2);
438
- }
439
- if (host_out != null and registry_out != null and std.ascii.eqlIgnoreCase(host_out.?, registry_out.?)) {
440
- try stderr.print("corewire: the service host and registry outputs name one file\n", .{});
441
- try stderr.flush();
442
- std.process.exit(2);
443
- }
444
- const arena = init.arena.allocator();
445
- const source = std.Io.Dir.cwd().readFileAlloc(init.io, sidecar_path, arena, .limited(service_contract_mod.max_bytes)) catch |err| {
446
- try stderr.print("corewire: cannot read {s}: {t}\n", .{ sidecar_path, err });
447
- try stderr.flush();
448
- std.process.exit(1);
449
- };
450
- const contract = service_contract_mod.read(arena, source, stderr) catch |err| switch (err) {
451
- error.InvalidContract => {
452
- try stderr.flush();
453
- std.process.exit(1);
454
- },
455
- error.OutOfMemory => return error.OutOfMemory,
456
- error.WriteFailed => return error.WriteFailed,
457
- };
458
- if (host_out) |path| {
459
- const generated = try emit_service_mod.emitHost(arena, contract);
460
- std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
461
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
462
- try stderr.flush();
463
- std.process.exit(1);
464
- };
465
- }
466
- if (registry_out) |path| {
467
- const generated = try emit_service_mod.emitRegistry(arena, contract);
468
- std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
469
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
470
- try stderr.flush();
471
- std.process.exit(1);
472
- };
473
- }
474
- if (client_out) |path| {
475
- const generated = try emit_service_mod.emitClient(arena, contract);
476
- std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
477
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
478
- try stderr.flush();
479
- std.process.exit(1);
480
- };
481
- }
482
- if (inproc_main_out) |path| {
483
- const generated = try emit_service_mod.emitInprocMain(arena, contract);
484
- std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
485
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
486
- try stderr.flush();
487
- std.process.exit(1);
488
- };
489
- }
490
- if (inproc_profile_out) |path| {
491
- const generated = try emit_service_mod.emitInprocProfile(arena, optimization);
492
- std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
493
- try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
494
- try stderr.flush();
495
- std.process.exit(1);
496
- };
497
- }
498
- try stderr.flush();
499
- return true;
500
- }
501
-
502
- /// Rewrite one record-field slot's type-table spelling from i64 to f64
503
- /// (through one optional wrapper). Returns false when the path is not a
504
- /// `Container.field` record slot whose field spells i64.
505
- fn demoteSlotToF64(sidecar: sidecar_mod.Sidecar, slot_path: []const u8) bool {
506
- const dot = std.mem.indexOfScalar(u8, slot_path, '.') orelse return false;
507
- const container = slot_path[0..dot];
508
- const field_name = slot_path[dot + 1 ..];
509
- if (std.mem.indexOfScalar(u8, field_name, '.') != null) return false;
510
- for (sidecar.types.structs) |entry| {
511
- if (!std.mem.eql(u8, entry.name, container)) continue;
512
- for (entry.fields) |*field| {
513
- if (!std.mem.eql(u8, field.name, field_name)) continue;
514
- const mutable: *sidecar_mod.Field = @constCast(field);
515
- switch (field.type) {
516
- .i64 => {
517
- mutable.type = .f64;
518
- return true;
519
- },
520
- .optional => |inner| {
521
- if (inner.* != .i64) return false;
522
- const mutable_inner: *sidecar_mod.TypeRef = @constCast(inner);
523
- mutable_inner.* = .f64;
524
- return true;
525
- },
526
- else => return false,
527
- }
528
- }
529
- }
530
- return false;
531
- }
532
-
533
- /// The facade path as the profile's entry spelling: relative to the
534
- /// profile file's directory (the compilation root a profile consumer
535
- /// resolves against), POSIX separators. A pair that cannot relate
536
- /// (distinct roots) refuses with a teaching — a wrong spelling would
537
- /// point the consumer at a file that does not exist.
538
- fn profileRelativeEntry(init: std.process.Init, stderr: *std.Io.Writer, profile_path: []const u8, facade_path: []const u8) ![]const u8 {
539
- const arena = init.arena.allocator();
540
- const profile_dir = std.fs.path.dirname(profile_path) orelse ".";
541
- var buffer: [std.fs.max_path_bytes]u8 = undefined;
542
- const cwd_len = std.Io.Dir.cwd().realPath(init.io, &buffer) catch 0;
543
- const cwd: []const u8 = if (cwd_len == 0) "." else buffer[0..cwd_len];
544
- // The environment rides along for the Windows resolver: a
545
- // drive-RELATIVE spelling (C:foo) resolves against that drive's own
546
- // working directory, which lives in the environment.
547
- const related = try std.fs.path.relative(arena, cwd, init.environ_map, profile_dir, facade_path);
548
- // Paths on distinct roots have no relative spelling (the resolver
549
- // hands back an absolute path instead): a profile consumer resolves
550
- // the entry against the profile's directory, so an unreachable
551
- // facade refuses rather than emitting a spelling that names nothing.
552
- if (related.len == 0 or std.fs.path.isAbsolute(related)) {
553
- try stderr.print("corewire: --facade {s} has no path relative to the --profile directory {s} — the profile's entry must reach the facade from beside the profile; emit them under one root\n", .{ facade_path, profile_dir });
554
- try stderr.flush();
555
- return error.Unrelatable;
556
- }
557
- // Separator conversion is a WINDOWS translation only: on POSIX a
558
- // backslash is an ordinary filename byte and must ride verbatim.
559
- if (std.fs.path.sep != std.fs.path.sep_windows) return related;
560
- const posix = try arena.dupe(u8, related);
561
- for (posix) |*char| {
562
- if (char.* == std.fs.path.sep_windows) char.* = std.fs.path.sep_posix;
563
- }
564
- return posix;
565
- }
566
-
567
- /// A path spelling fit for alias comparison: components canonicalize
568
- /// one at a time against the filesystem, so `..` applies to the REAL
569
- /// parent (never lexically across a symlink), symlinked or case-folded
570
- /// ancestors land on one spelling, and a not-yet-existing tail rides
571
- /// verbatim — two spellings of one future file compare equal even
572
- /// before the file exists.
573
- fn canonicalSpelling(io: std.Io, arena: std.mem.Allocator, path: []const u8) ![]const u8 {
574
- var buffer: [std.fs.max_path_bytes]u8 = undefined;
575
- // Platform-aware parsing: the component iterator understands the
576
- // native roots and separators (drive and UNC spellings included),
577
- // so two spellings of one root land on one prefix.
578
- var components = std.fs.path.componentIterator(path);
579
- const root = components.root();
580
- if (root != null and !std.fs.path.isAbsolute(path)) {
581
- // A drive-RELATIVE spelling (C:foo) names a file under that
582
- // drive's own working directory, which this process cannot
583
- // resolve portably; folding it under the drive root would
584
- // manufacture false aliases against drive-absolute spellings.
585
- // Keep it lexical — the existence-based nets and rename landing
586
- // still guard the writes.
587
- return std.fs.path.resolve(arena, &.{path});
588
- }
589
- var base: []const u8 = if (root) |prefix|
590
- try arena.dupe(u8, prefix)
591
- else blk: {
592
- const len = std.Io.Dir.cwd().realPath(io, &buffer) catch break :blk try arena.dupe(u8, ".");
593
- break :blk try arena.dupe(u8, buffer[0..len]);
594
- };
595
- var exists = true;
596
- while (components.next()) |component| {
597
- if (std.mem.eql(u8, component.name, ".")) continue;
598
- if (std.mem.eql(u8, component.name, "..")) {
599
- // `base` carries no symlinks once canonical, so its lexical
600
- // parent IS its real parent; a `..` under a nonexistent
601
- // tail unwinds the tail it just added — and may land back
602
- // on EXISTING ground, so canonicalization must resume (a
603
- // symlink after the pop would otherwise ride unresolved).
604
- base = std.fs.path.dirname(base) orelse base;
605
- if (!exists) {
606
- if (std.Io.Dir.cwd().realPathFile(io, base, &buffer)) |len| {
607
- base = try arena.dupe(u8, buffer[0..len]);
608
- exists = true;
609
- } else |_| {}
610
- }
611
- continue;
612
- }
613
- const candidate = try std.fs.path.join(arena, &.{ base, component.name });
614
- if (exists) {
615
- if (std.Io.Dir.cwd().realPathFile(io, candidate, &buffer)) |len| {
616
- base = try arena.dupe(u8, buffer[0..len]);
617
- continue;
618
- } else |_| {
619
- exists = false;
620
- }
621
- }
622
- base = candidate;
623
- }
624
- return base;
625
- }
626
-
627
- /// Whether two paths currently resolve to one existing file, by asking
628
- /// the filesystem for canonical paths: the alias net behind the lexical
629
- /// checks (Unicode case folding, symlinks — a canonical path is unique
630
- /// per volume, so distinct files can never compare equal). Nonexistent
631
- /// paths are distinct. Hard links carry distinct canonical paths and
632
- /// pass this check — harmless by construction, because outputs land by
633
- /// rename (writeOutput), which replaces a directory entry and never
634
- /// writes through one.
635
- fn sameExistingFile(io: std.Io, a: []const u8, b: []const u8) bool {
636
- var buffer_a: [std.fs.max_path_bytes]u8 = undefined;
637
- var buffer_b: [std.fs.max_path_bytes]u8 = undefined;
638
- const len_a = std.Io.Dir.cwd().realPathFile(io, a, &buffer_a) catch return false;
639
- const len_b = std.Io.Dir.cwd().realPathFile(io, b, &buffer_b) catch return false;
640
- if (std.mem.eql(u8, buffer_a[0..len_a], buffer_b[0..len_b])) return true;
641
- // Distinct canonical paths can still name one DIRECTORY ENTRY where
642
- // a mount exposes a directory twice (bind mounts) — the case the
643
- // rename landing cannot save, because replacing the entry through
644
- // either spelling replaces it for both. A hard link is the
645
- // opposite: two entries for one file, and the rename replaces only
646
- // the named entry, so it must NOT trip this check. Same entry means
647
- // same parent directory and same on-disk basename; the portable
648
- // stat carries no device id, so parent identity is inferred from
649
- // full metadata agreement (a coincidental match across volumes
650
- // merely refuses a spelling nobody needs).
651
- const canon_a = buffer_a[0..len_a];
652
- const canon_b = buffer_b[0..len_b];
653
- if (!std.mem.eql(u8, std.fs.path.basename(canon_a), std.fs.path.basename(canon_b))) return false;
654
- const parent_a = std.fs.path.dirname(canon_a) orelse return false;
655
- const parent_b = std.fs.path.dirname(canon_b) orelse return false;
656
- const stat_a = std.Io.Dir.cwd().statFile(io, parent_a, .{}) catch return false;
657
- const stat_b = std.Io.Dir.cwd().statFile(io, parent_b, .{}) catch return false;
658
- return stat_a.inode == stat_b.inode and stat_a.kind == stat_b.kind and
659
- stat_a.size == stat_b.size and stat_a.nlink == stat_b.nlink and
660
- stat_a.mtime.nanoseconds == stat_b.mtime.nanoseconds and
661
- stat_a.ctime.nanoseconds == stat_b.ctime.nanoseconds;
662
- }
663
-
664
- /// Write `data` into an exclusively-created, uniquely-named staging
665
- /// file beside `out` and return its path; the caller commits by rename.
666
- /// Exclusive creation can never truncate an existing entry (whatever it
667
- /// links to), and the unique suffix keeps concurrent invocations off
668
- /// each other's bytes. Failures print their teaching and return
669
- /// error.Staging so the caller can delete sibling staging files.
670
- fn stageOutput(init: std.process.Init, stderr: *std.Io.Writer, out: []const u8, data: []const u8) ![]const u8 {
671
- if (std.fs.path.dirname(out)) |dir| {
672
- std.Io.Dir.cwd().createDirPath(init.io, dir) catch {};
673
- }
674
- const arena = init.arena.allocator();
675
- var nonce: [8]u8 = undefined;
676
- init.io.random(&nonce);
677
- const temp_path = try std.fmt.allocPrint(arena, "{s}.corewire-tmp.{x}", .{ out, &nonce });
678
- const staging = std.Io.Dir.cwd().createFile(init.io, temp_path, .{ .exclusive = true }) catch |err| {
679
- try stderr.print("corewire: cannot stage {s}: {t}\n", .{ temp_path, err });
680
- try stderr.flush();
681
- return error.Staging;
682
- };
683
- var write_failed = false;
684
- {
685
- defer staging.close(init.io);
686
- var buffer: [4096]u8 = undefined;
687
- var writer = staging.writerStreaming(init.io, &buffer);
688
- writer.interface.writeAll(data) catch {
689
- write_failed = true;
690
- };
691
- if (!write_failed) writer.interface.flush() catch {
692
- write_failed = true;
693
- };
694
- }
695
- if (write_failed) {
696
- std.Io.Dir.cwd().deleteFile(init.io, temp_path) catch {};
697
- try stderr.print("corewire: cannot write {s}\n", .{temp_path});
698
- try stderr.flush();
699
- return error.Staging;
700
- }
701
- return temp_path;
24
+ const args = try init.minimal.args.toSlice(init.arena.allocator());
25
+ var buffer: [4096]u8 = undefined;
26
+ var writer = std.Io.File.stderr().writerStreaming(init.io, &buffer);
27
+ const code = try entry.run(init, args, &writer.interface);
28
+ if (code != 0) std.process.exit(code);
702
29
  }