@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.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +320 -60
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +1818 -87
- package/package.json +19 -14
- package/packages/core/compile-surface/core.ts +134 -72
- package/packages/core/package-lock.json +75 -357
- package/packages/core/package.json +25 -4
- package/packages/core/scripts/compiler_command.mjs +17 -12
- package/packages/core/scripts/compiler_typecheck.mjs +1 -0
- package/packages/core/scripts/gen_declarations.mjs +3 -2
- package/packages/core/scripts/gen_service_surface.mjs +22 -10
- package/packages/core/scripts/install_scriptc.mjs +182 -0
- package/packages/core/scripts/invoke_scriptc.mjs +18 -0
- package/packages/core/scripts/merge_static_archives.mjs +6 -1
- package/packages/core/scripts/npm_static_spike.mjs +2 -2
- package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
- package/packages/core/scripts/run_library_compiler.mjs +51 -0
- package/packages/core/scripts/run_native_tests.mjs +22 -0
- package/packages/core/scripts/scriptc-toolchain.json +101 -0
- package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
- package/packages/core/scripts/stage_external_core.mjs +57 -1
- package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
- package/packages/core/sdk/bytes.d.ts +2 -0
- package/packages/core/sdk/bytes.ts +86 -0
- package/packages/core/sdk/core.d.ts +308 -4
- package/packages/core/sdk/core.ts +320 -84
- package/packages/core/sdk/events.d.ts +247 -0
- package/packages/core/sdk/events.ts +230 -2
- package/packages/core/sdk/internal/image_identity.d.ts +7 -0
- package/packages/core/sdk/internal/image_identity.ts +71 -0
- package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
- package/packages/core/sdk/internal/markdown_policy.ts +878 -0
- package/packages/core/sdk/text.d.ts +27 -0
- package/packages/core/sdk/text.ts +206 -15
- package/packages/core/sdk/theme.d.ts +251 -0
- package/packages/core/sdk/theme.ts +267 -0
- package/packages/core/src/authorization.ts +137 -0
- package/packages/core/src/automation_commands.ts +201 -0
- package/packages/core/src/automation_interactions.ts +92 -0
- package/packages/core/src/bridge_descriptors.ts +104 -0
- package/packages/core/src/builtin_coordination.ts +172 -0
- package/packages/core/src/canvas_frame_coordination.ts +81 -0
- package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
- package/packages/core/src/canvas_scene_observation.ts +145 -0
- package/packages/core/src/chart_content.ts +161 -0
- package/packages/core/src/chart_plans.ts +432 -0
- package/packages/core/src/checker.ts +166 -19
- package/packages/core/src/code_content.ts +580 -0
- package/packages/core/src/command_coordination.ts +140 -0
- package/packages/core/src/component_composition.ts +94 -0
- package/packages/core/src/component_construction.ts +149 -0
- package/packages/core/src/contract.ts +25 -7
- package/packages/core/src/control_appearance.ts +232 -0
- package/packages/core/src/control_commands.ts +115 -0
- package/packages/core/src/control_content.ts +105 -0
- package/packages/core/src/control_geometry.ts +107 -0
- package/packages/core/src/control_payloads.ts +119 -0
- package/packages/core/src/control_primitives.ts +134 -0
- package/packages/core/src/devhost.ts +82 -7
- package/packages/core/src/devhost_journal.mjs +30 -7
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/glyph_atlas.ts +86 -0
- package/packages/core/src/gpu_packet_preparation.ts +130 -0
- package/packages/core/src/gpu_planning.ts +123 -0
- package/packages/core/src/gpu_presentation.ts +55 -0
- package/packages/core/src/host_flow.ts +89 -0
- package/packages/core/src/host_input_regions.ts +165 -0
- package/packages/core/src/image_registry.ts +66 -0
- package/packages/core/src/indicator_plans.ts +132 -0
- package/packages/core/src/infer.ts +150 -8
- package/packages/core/src/input_composition.ts +116 -0
- package/packages/core/src/intrinsic_measure.ts +100 -0
- package/packages/core/src/layout_coordination.ts +207 -0
- package/packages/core/src/leaf_plans.ts +134 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/measurement_coordination.ts +185 -0
- package/packages/core/src/modules.ts +1 -1
- package/packages/core/src/motion_sampling.ts +100 -0
- package/packages/core/src/paragraph_layout.ts +192 -0
- package/packages/core/src/portable_sources.json +74 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +93 -0
- package/packages/core/src/render_animation_lifecycle.ts +128 -0
- package/packages/core/src/render_coordination.ts +170 -0
- package/packages/core/src/render_resources.ts +234 -0
- package/packages/core/src/runtime_policy.ts +3930 -0
- package/packages/core/src/scalar_text.ts +84 -0
- package/packages/core/src/service_contract.ts +2 -1
- package/packages/core/src/session_codecs.ts +309 -0
- package/packages/core/src/shell_admission.ts +126 -0
- package/packages/core/src/shell_coordination.ts +93 -0
- package/packages/core/src/sqlite_cli.ts +11 -0
- package/packages/core/src/status_validation.ts +232 -0
- package/packages/core/src/stream_policy.ts +63 -0
- package/packages/core/src/surface_recipes.ts +136 -0
- package/packages/core/src/system_admission.ts +60 -0
- package/packages/core/src/terminal_paint.ts +436 -0
- package/packages/core/src/text_document_width.ts +81 -0
- package/packages/core/src/text_measurement_cache.ts +69 -0
- package/packages/core/src/text_query_layout.ts +179 -0
- package/packages/core/src/text_run_layout.ts +410 -0
- package/packages/core/src/text_span_queries.ts +355 -0
- package/packages/core/src/typed_ast.ts +18 -1
- package/packages/core/src/types.ts +7 -5
- package/packages/core/src/vector_effects.ts +98 -0
- package/packages/core/src/vector_raster.ts +243 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_frontend.ts +980 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_metrics.ts +139 -0
- package/packages/core/src/widget_motion.ts +171 -0
- package/packages/core/src/widget_paint.ts +272 -0
- package/packages/core/src/widget_paint_walk.ts +203 -0
- package/packages/core/src/widget_presentation.ts +141 -0
- package/packages/core/src/widget_routing.ts +262 -0
- package/packages/core/src/window_lifecycle.ts +92 -0
- package/packages/core/testing/index.ts +430 -0
- package/schemas/app.schema.json +13 -0
- package/skill-data/core/SKILL.md +2 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
- package/skill-data/native-ui/SKILL.md +76 -17
- package/skill-data/ts-core/SKILL.md +113 -9
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +264 -144
- package/src/app_runner/root.zig +25 -12
- package/src/app_runner/ts_compiled_view.zig +1631 -0
- package/src/app_runner/ts_core_main.zig +143 -10
- package/src/app_runner/ts_core_mobile.zig +24 -12
- package/src/automation/server.zig +1 -3
- package/src/automation/snapshot.zig +9 -637
- package/src/automation/snapshot_reference.zig +656 -0
- package/src/automation/snapshot_serialization.zig +566 -0
- package/src/platform/linux/gtk_host.c +36 -24
- package/src/platform/linux/gtk_pixels.h +118 -0
- package/src/platform/linux/gtk_pixels_test.c +241 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.m +188 -30
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/scroll_driver_test.m +105 -0
- package/src/platform/macos/spectrum_bins.h +34 -0
- package/src/platform/macos/spectrum_bins_test.c +56 -0
- package/src/platform/macos/text_keyboard_test.m +80 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +26 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +1 -0
- package/src/platform/types.zig +13 -0
- package/src/platform/windows/root.zig +2 -0
- package/src/platform/windows/webview2_host.cpp +7 -2
- package/src/primitives/app_manifest/comptime_scene.zig +1 -1
- package/src/primitives/app_manifest/root.zig +2 -0
- package/src/primitives/app_manifest/tests.zig +4 -1
- package/src/primitives/app_manifest/validation.zig +2 -0
- package/src/primitives/canvas/a11y_audit.zig +3 -1
- package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
- package/src/primitives/canvas/chart_content_policy.zig +75 -0
- package/src/primitives/canvas/chart_plan_policy.zig +196 -0
- package/src/primitives/canvas/code_content_policy.zig +162 -0
- package/src/primitives/canvas/commands.zig +29 -1
- package/src/primitives/canvas/component_composition.zig +125 -0
- package/src/primitives/canvas/component_composition_policy.zig +44 -0
- package/src/primitives/canvas/component_construction_policy.zig +187 -0
- package/src/primitives/canvas/container_layout_policy.zig +87 -0
- package/src/primitives/canvas/control_appearance_policy.zig +142 -0
- package/src/primitives/canvas/control_command_policy.zig +75 -0
- package/src/primitives/canvas/control_content_policy.zig +90 -0
- package/src/primitives/canvas/control_geometry_policy.zig +165 -0
- package/src/primitives/canvas/control_payload_policy.zig +48 -0
- package/src/primitives/canvas/control_primitive_policy.zig +129 -0
- package/src/primitives/canvas/effect_plan_policy.zig +96 -0
- package/src/primitives/canvas/events.zig +1027 -1
- package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
- package/src/primitives/canvas/frame.zig +92 -23
- package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
- package/src/primitives/canvas/gpu.zig +10 -0
- package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
- package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
- package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
- package/src/primitives/canvas/grid_layout_policy.zig +51 -0
- package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
- package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
- package/src/primitives/canvas/layout_audit.zig +5 -2
- package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
- package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
- package/src/primitives/canvas/markdown.zig +13 -3
- package/src/primitives/canvas/markdown_content_policy.zig +227 -0
- package/src/primitives/canvas/markdown_image_binding.zig +81 -0
- package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
- package/src/primitives/canvas/numeric_capabilities.zig +14 -0
- package/src/primitives/canvas/reference.zig +12 -6
- package/src/primitives/canvas/registered_font_policy.zig +152 -0
- package/src/primitives/canvas/render.zig +48 -0
- package/src/primitives/canvas/render_cache_policy.zig +184 -0
- package/src/primitives/canvas/render_coordination_policy.zig +163 -0
- package/src/primitives/canvas/render_damage_policy.zig +160 -0
- package/src/primitives/canvas/render_effects.zig +14 -0
- package/src/primitives/canvas/render_generic_resources.zig +14 -0
- package/src/primitives/canvas/render_images.zig +14 -0
- package/src/primitives/canvas/render_layers.zig +14 -0
- package/src/primitives/canvas/render_override_policy.zig +119 -0
- package/src/primitives/canvas/render_paths.zig +14 -0
- package/src/primitives/canvas/render_plan_policy.zig +199 -0
- package/src/primitives/canvas/render_resource_policy.zig +476 -0
- package/src/primitives/canvas/root.zig +100 -0
- package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
- package/src/primitives/canvas/serialization.zig +8 -1
- package/src/primitives/canvas/surface_layout_policy.zig +36 -0
- package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
- package/src/primitives/canvas/terminal_grid.zig +10 -696
- package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
- package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +113 -0
- package/src/primitives/canvas/text_cache_policy.zig +94 -0
- package/src/primitives/canvas/text_document_policy.zig +120 -0
- package/src/primitives/canvas/text_layout.zig +51 -2
- package/src/primitives/canvas/text_layout_cache.zig +29 -0
- package/src/primitives/canvas/text_layout_hash.zig +1 -0
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_measure_cache.zig +46 -0
- package/src/primitives/canvas/text_measurement_policy.zig +124 -0
- package/src/primitives/canvas/text_metrics.zig +23 -0
- package/src/primitives/canvas/text_query_policy.zig +156 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +156 -0
- package/src/primitives/canvas/text_span_query_policy.zig +232 -0
- package/src/primitives/canvas/text_spans.zig +280 -8
- package/src/primitives/canvas/text_tests.zig +10 -0
- package/src/primitives/canvas/tokens.zig +38 -0
- package/src/primitives/canvas/ui.zig +250 -83
- package/src/primitives/canvas/ui_markup.zig +139 -33
- package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_contract.zig +146 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_view.zig +258 -32
- package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
- package/src/primitives/canvas/ui_schema.zig +13 -1
- package/src/primitives/canvas/ui_schema_tests.zig +11 -7
- package/src/primitives/canvas/ui_tests.zig +1 -0
- package/src/primitives/canvas/vector.zig +36 -2
- package/src/primitives/canvas/vector_effect_policy.zig +236 -0
- package/src/primitives/canvas/vector_raster_policy.zig +190 -0
- package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
- package/src/primitives/canvas/virtual_extents.zig +99 -3
- package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
- package/src/primitives/canvas/widget_audit_policy.zig +293 -0
- package/src/primitives/canvas/widget_change_policy.zig +298 -0
- package/src/primitives/canvas/widget_invalidation.zig +113 -2
- package/src/primitives/canvas/widget_layout.zig +673 -128
- package/src/primitives/canvas/widget_layout_tests.zig +4 -0
- package/src/primitives/canvas/widget_metric_policy.zig +126 -0
- package/src/primitives/canvas/widget_metrics.zig +45 -6
- package/src/primitives/canvas/widget_paint_policy.zig +166 -0
- package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
- package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
- package/src/primitives/canvas/widget_render.zig +744 -74
- package/src/primitives/canvas/widget_render_controls.zig +1217 -133
- package/src/primitives/canvas/widget_render_scroll.zig +11 -3
- package/src/primitives/canvas/widget_render_style.zig +94 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
- package/src/primitives/canvas/widget_routing.zig +75 -0
- package/src/primitives/canvas/widget_routing_policy.zig +135 -0
- package/src/primitives/canvas/widget_runtime.zig +20 -1
- package/src/primitives/canvas/widget_semantics.zig +25 -0
- package/src/primitives/canvas/widget_text_input.zig +86 -23
- package/src/primitives/canvas/widget_text_select.zig +1 -0
- package/src/primitives/canvas/widget_tree.zig +8 -1
- package/src/primitives/canvas/widgets.zig +42 -12
- package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
- package/src/root.zig +21 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +28 -0
- package/src/runtime/app_dispatch_policy.zig +68 -0
- package/src/runtime/authorization_policy.zig +150 -0
- package/src/runtime/automation_command_policy.zig +241 -0
- package/src/runtime/automation_interaction_policy.zig +107 -0
- package/src/runtime/automation_snapshot.zig +52 -22
- package/src/runtime/automation_snapshot_reference.zig +290 -0
- package/src/runtime/automation_widget_dispatch.zig +267 -355
- package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
- package/src/runtime/blob_policy.zig +58 -0
- package/src/runtime/blob_reference.zig +64 -0
- package/src/runtime/bridge_descriptor_policy.zig +206 -0
- package/src/runtime/builtin_bridge.zig +180 -44
- package/src/runtime/builtin_coordination_policy.zig +121 -0
- package/src/runtime/callback_policy_test_reference.zig +97 -0
- package/src/runtime/canvas_drag_policy.zig +94 -0
- package/src/runtime/canvas_fonts.zig +38 -10
- package/src/runtime/canvas_frame.zig +590 -134
- package/src/runtime/canvas_frame_helpers.zig +1 -0
- package/src/runtime/canvas_hover_policy.zig +131 -0
- package/src/runtime/canvas_images.zig +59 -30
- package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
- package/src/runtime/canvas_limits.zig +1 -1
- package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
- package/src/runtime/canvas_scene_observation_policy.zig +181 -0
- package/src/runtime/canvas_widget_context_menu.zig +4 -4
- package/src/runtime/canvas_widget_display.zig +110 -9
- package/src/runtime/canvas_widget_events.zig +718 -328
- package/src/runtime/canvas_widget_runtime.zig +437 -81
- package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
- package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
- package/src/runtime/canvas_widget_state.zig +93 -56
- package/src/runtime/channel_sources.zig +80 -0
- package/src/runtime/command_policy.zig +161 -0
- package/src/runtime/component_policy.zig +83 -0
- package/src/runtime/core.zig +156 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +466 -29
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +418 -341
- package/src/runtime/flow_reference.zig +1426 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/gpu_surface_events.zig +97 -35
- package/src/runtime/host_event_pump.zig +303 -0
- package/src/runtime/host_event_pump_reference.zig +268 -0
- package/src/runtime/host_flow_policy.zig +155 -0
- package/src/runtime/host_input_regions_policy.zig +156 -0
- package/src/runtime/image_registry_policy.zig +94 -0
- package/src/runtime/input_composition_policy.zig +138 -0
- package/src/runtime/journal_policy.zig +66 -0
- package/src/runtime/journal_reference.zig +53 -0
- package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
- package/src/runtime/markup_development_policy.zig +91 -0
- package/src/runtime/media_surface.zig +40 -1
- package/src/runtime/motion_sampling_policy.zig +159 -0
- package/src/runtime/recording_policy.zig +42 -0
- package/src/runtime/render_animation_policy.zig +206 -0
- package/src/runtime/replay_policy.zig +66 -0
- package/src/runtime/replay_policy_reference.zig +326 -0
- package/src/runtime/replay_progress_policy.zig +64 -0
- package/src/runtime/replay_progress_reference.zig +34 -0
- package/src/runtime/request_policy_test_reference.zig +188 -0
- package/src/runtime/root.zig +13 -0
- package/src/runtime/session_blobs.zig +157 -58
- package/src/runtime/session_blobs_reference.zig +692 -0
- package/src/runtime/session_codec.zig +361 -0
- package/src/runtime/session_codec_reference.zig +1027 -0
- package/src/runtime/session_journal.zig +246 -983
- package/src/runtime/session_record.zig +224 -45
- package/src/runtime/session_replay.zig +157 -415
- package/src/runtime/session_tests.zig +552 -0
- package/src/runtime/shell_admission_policy.zig +225 -0
- package/src/runtime/shell_coordination_policy.zig +138 -0
- package/src/runtime/shell_layout.zig +126 -1
- package/src/runtime/snapshot_policy.zig +60 -0
- package/src/runtime/snapshot_reference.zig +64 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/status_validation.zig +190 -0
- package/src/runtime/system_admission_policy.zig +140 -0
- package/src/runtime/system_services.zig +46 -36
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_canvas_hooks.zig +261 -0
- package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
- package/src/runtime/ts_canvas_icons.zig +234 -0
- package/src/runtime/ts_core_host.zig +2325 -411
- package/src/runtime/ts_core_host_tests.zig +1982 -0
- package/src/runtime/ts_test_host.zig +699 -0
- package/src/runtime/ts_ui_app.zig +1087 -45
- package/src/runtime/ui_app.zig +1117 -629
- package/src/runtime/ui_app_provenance.zig +147 -5
- package/src/runtime/ui_app_provenance_reference.zig +370 -0
- package/src/runtime/ui_app_tests.zig +619 -9
- package/src/runtime/ui_app_window_tests.zig +89 -0
- package/src/runtime/view.zig +25 -0
- package/src/runtime/view_canvas.zig +30 -6
- package/src/runtime/view_coordination_policy.zig +147 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +16 -5
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +460 -56
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/window_command_bridge_tests.zig +63 -0
- package/src/runtime/window_lifecycle_policy.zig +127 -0
- package/src/runtime/window_storage.zig +74 -8
- package/src/runtime/window_view_runtime.zig +148 -33
- package/src/runtime/window_views.zig +163 -10
- package/src/tooling/codesign.zig +125 -74
- package/src/tooling/components/identity_tests.zig +62 -36
- package/src/tooling/components/stepper.native +24 -0
- package/src/tooling/components/stepper.zig +0 -19
- package/src/tooling/components/timeline-item.native +22 -0
- package/src/tooling/components/timeline.native +5 -3
- package/src/tooling/components/timeline_item.zig +0 -32
- package/src/tooling/eject_components.zig +76 -8
- package/src/tooling/ios.zig +66 -12
- package/src/tooling/manifest.zig +35 -0
- package/src/tooling/package.zig +85 -1
- package/src/tooling/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +15 -3
- package/src/tooling/ts_core.zig +13 -3
- package/src/tooling/verbs.zig +22 -0
- package/tools/corewire/build_profile.mjs +54 -0
- package/tools/corewire/contract_intake.ts +303 -0
- package/tools/corewire/contract_intake.zig +82 -0
- package/tools/corewire/core.test.ts +166 -0
- package/tools/corewire/core_abi.zig +51 -0
- package/tools/corewire/core_cases.ts +233 -0
- package/tools/corewire/core_contract.ts +407 -0
- package/tools/corewire/core_emission.ts +136 -0
- package/tools/corewire/core_emission.zig +69 -0
- package/tools/corewire/core_goldens.json +3110 -0
- package/tools/corewire/core_policy.ts +14 -0
- package/tools/corewire/core_policy.zig +48 -0
- package/tools/corewire/core_projection.ts +360 -0
- package/tools/corewire/core_vocabulary.ts +6 -0
- package/tools/corewire/emit.zig +19 -1590
- package/tools/corewire/emit_facade.ts +714 -0
- package/tools/corewire/emit_facade.zig +10 -3752
- package/tools/corewire/emit_mirror.ts +290 -0
- package/tools/corewire/emit_profile.ts +50 -0
- package/tools/corewire/emit_service.ts +331 -0
- package/tools/corewire/emit_service.zig +23 -842
- package/tools/corewire/entry.test.ts +95 -0
- package/tools/corewire/entry_coordination.ts +127 -0
- package/tools/corewire/entry_coordination.zig +190 -0
- package/tools/corewire/facade_templates.ts +85 -0
- package/tools/corewire/filesystem.test.ts +166 -0
- package/tools/corewire/filesystem_coordination.ts +213 -0
- package/tools/corewire/filesystem_coordination.zig +245 -0
- package/tools/corewire/intake.test.ts +35 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +24 -0
- package/tools/corewire/invocation.ts +175 -0
- package/tools/corewire/invocation.zig +136 -0
- package/tools/corewire/invocation_cases.ts +60 -0
- package/tools/corewire/invocation_fixture.ts +33 -0
- package/tools/corewire/invocation_goldens.json +1143 -0
- package/tools/corewire/invocation_tests.zig +111 -0
- package/tools/corewire/invocation_usage.ts +2 -0
- package/tools/corewire/lossless_projection.ts +96 -0
- package/tools/corewire/main.zig +7 -680
- package/tools/corewire/main_reference.zig +415 -0
- package/tools/corewire/mirror_templates.ts +55 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +202 -0
- package/tools/corewire/profile_library.json +29 -0
- package/tools/corewire/profile_tests.zig +136 -0
- package/tools/corewire/service.test.ts +75 -0
- package/tools/corewire/service_cases.ts +61 -0
- package/tools/corewire/service_contract.zig +40 -146
- package/tools/corewire/service_goldens.json +650 -0
- package/tools/corewire/service_projection.zig +52 -0
- package/tools/corewire/service_templates.ts +14 -0
- package/tools/corewire/shim_rt.zig +9 -0
- package/tools/corewire/sidecar.zig +267 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
//! corewire — the contract-sidecar shim generator.
|
|
2
|
+
//!
|
|
3
|
+
//! corewire --sidecar core.contract.json --out core_shim.zig
|
|
4
|
+
//! corewire --sidecar core.contract.json --facade core_facade.ts --profile core_profile.json --effective-sidecar effective.contract.json
|
|
5
|
+
//! corewire --sidecar core.contract.json --check
|
|
6
|
+
//!
|
|
7
|
+
//! Reads the JSON contract sidecar a core-mode compile emits beside the
|
|
8
|
+
//! compiled object, validates it (schema rules V1-V14, teaching
|
|
9
|
+
//! refusals with exact field paths on stderr), and writes the Zig
|
|
10
|
+
//! mirror module the app wiring imports (see emit.zig for what the
|
|
11
|
+
//! mirror carries). `--facade` writes the TypeScript projection,
|
|
12
|
+
//! `--profile` the library-mode compiler profile that builds it
|
|
13
|
+
//! (scriptc-compiled emit_profile.ts). `--check` validates and stops — the checker-tier
|
|
14
|
+
//! entry point.
|
|
15
|
+
//!
|
|
16
|
+
//! The build stages the output beside tools/corewire/shim_rt.zig and
|
|
17
|
+
//! tools/corewire/core_abi.zig; the generated module imports both
|
|
18
|
+
//! relatively, the way transpiler output imports its staged rt.zig.
|
|
19
|
+
|
|
20
|
+
const std = @import("std");
|
|
21
|
+
const sidecar_mod = @import("sidecar.zig");
|
|
22
|
+
const invocation_mod = @import("invocation.zig");
|
|
23
|
+
const service_contract_mod = @import("service_contract.zig");
|
|
24
|
+
const emit_service_mod = @import("emit_service.zig");
|
|
25
|
+
|
|
26
|
+
pub fn main(init: std.process.Init) !void {
|
|
27
|
+
const arena = init.arena.allocator();
|
|
28
|
+
const args = try init.minimal.args.toSlice(arena);
|
|
29
|
+
|
|
30
|
+
var stderr_buffer: [4096]u8 = undefined;
|
|
31
|
+
var stderr_writer = std.Io.File.stderr().writerStreaming(init.io, &stderr_buffer);
|
|
32
|
+
const stderr = &stderr_writer.interface;
|
|
33
|
+
|
|
34
|
+
const invocation = try invocation_mod.plan(arena, args);
|
|
35
|
+
if (invocation.exit_code != 0) {
|
|
36
|
+
try stderr.writeAll(invocation.@"error");
|
|
37
|
+
try stderr.flush();
|
|
38
|
+
std.process.exit(invocation.exit_code);
|
|
39
|
+
}
|
|
40
|
+
if (invocation.mode == .service) return serviceProjection(init, args, invocation, stderr);
|
|
41
|
+
const input = args[invocation.input.?];
|
|
42
|
+
var out_path: ?[]const u8 = null;
|
|
43
|
+
var facade_path: ?[]const u8 = null;
|
|
44
|
+
var profile_path: ?[]const u8 = null;
|
|
45
|
+
var effective_sidecar_path: ?[]const u8 = null;
|
|
46
|
+
for (invocation.outputs) |out| switch (out.kind) {
|
|
47
|
+
.mirror => out_path = args[out.path_index],
|
|
48
|
+
.facade => facade_path = args[out.path_index],
|
|
49
|
+
.profile => profile_path = args[out.path_index],
|
|
50
|
+
.effective => effective_sidecar_path = args[out.path_index],
|
|
51
|
+
else => unreachable,
|
|
52
|
+
};
|
|
53
|
+
// Distinct paths only: the projections must not overwrite each
|
|
54
|
+
// other, and no output may destroy the input contract. Compared
|
|
55
|
+
// lexically normalized (cwd-resolved, `.`/`..` folded) — filesystem
|
|
56
|
+
// identities beyond spelling (symlinks, hard links) stay the
|
|
57
|
+
// caller's responsibility.
|
|
58
|
+
const input_resolved = try canonicalSpelling(init.io, arena, input);
|
|
59
|
+
// The staging PREFIX spellings join the checked set: outputs land
|
|
60
|
+
// by rename from exclusively-created `<path>.corewire-tmp.<nonce>`
|
|
61
|
+
// files, and a sidecar sitting on the prefix spelling is close
|
|
62
|
+
// enough to a claimed name to refuse outright.
|
|
63
|
+
const paths = [_]?[]const u8{
|
|
64
|
+
out_path,
|
|
65
|
+
facade_path,
|
|
66
|
+
profile_path,
|
|
67
|
+
effective_sidecar_path,
|
|
68
|
+
if (out_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
|
|
69
|
+
if (facade_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
|
|
70
|
+
if (profile_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
|
|
71
|
+
if (effective_sidecar_path) |path| try std.fmt.allocPrint(arena, "{s}.corewire-tmp", .{path}) else null,
|
|
72
|
+
};
|
|
73
|
+
var resolved: [paths.len]?[]const u8 = @splat(null);
|
|
74
|
+
for (paths, 0..) |maybe_path, path_index| {
|
|
75
|
+
const path = maybe_path orelse continue;
|
|
76
|
+
resolved[path_index] = try canonicalSpelling(init.io, arena, path);
|
|
77
|
+
}
|
|
78
|
+
var canonical_paths: std.ArrayList([]const u8) = .empty;
|
|
79
|
+
for (resolved) |path| if (path) |value| try canonical_paths.append(arena, value);
|
|
80
|
+
const identities = try arena.alloc([]const bool, canonical_paths.items.len);
|
|
81
|
+
for (canonical_paths.items, 0..) |path, i| {
|
|
82
|
+
const row = try arena.alloc(bool, canonical_paths.items.len + 1);
|
|
83
|
+
@memset(row, false);
|
|
84
|
+
row[0] = sameExistingFile(init.io, path, input_resolved);
|
|
85
|
+
for (canonical_paths.items[i + 1 ..], i + 1..) |other, j| row[j + 1] = sameExistingFile(init.io, path, other);
|
|
86
|
+
identities[i] = row;
|
|
87
|
+
}
|
|
88
|
+
const alias_diagnostic = try invocation_mod.aliases(arena, input_resolved, canonical_paths.items, identities);
|
|
89
|
+
if (alias_diagnostic.len != 0) {
|
|
90
|
+
try stderr.writeAll(alias_diagnostic);
|
|
91
|
+
try stderr.flush();
|
|
92
|
+
std.process.exit(2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const source = std.Io.Dir.cwd().readFileAlloc(init.io, input, arena, .limited(sidecar_mod.max_sidecar_bytes)) catch |err| {
|
|
96
|
+
try stderr.print("corewire: cannot read {s}: {t}\n", .{ input, err });
|
|
97
|
+
try stderr.flush();
|
|
98
|
+
std.process.exit(1);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var diags = sidecar_mod.Diagnostics{ .arena = arena };
|
|
102
|
+
const parsed = sidecar_mod.read(arena, source, &diags) catch |err| switch (err) {
|
|
103
|
+
error.Refused => {
|
|
104
|
+
try diags.write(input, stderr);
|
|
105
|
+
try stderr.flush();
|
|
106
|
+
std.process.exit(1);
|
|
107
|
+
},
|
|
108
|
+
error.OutOfMemory => return err,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// OS-relative entry facts are computed here; compiled coordination
|
|
112
|
+
// decides when to enforce them, after mirror/facade admission.
|
|
113
|
+
var entry: invocation_mod.Entry = .{};
|
|
114
|
+
if (facade_path != null and profile_path != null) {
|
|
115
|
+
const profile_dir = std.fs.path.dirname(profile_path.?) orelse ".";
|
|
116
|
+
entry = try profileRelativeEntry(init, profile_dir, facade_path.?);
|
|
117
|
+
} else if (facade_path) |path| {
|
|
118
|
+
const name = std.fs.path.basename(path);
|
|
119
|
+
entry = .{ .text = if (std.unicode.utf8ValidateSlice(name)) name else "", .utf8 = std.unicode.utf8ValidateSlice(name), .bytes = name };
|
|
120
|
+
}
|
|
121
|
+
const result = try invocation_mod.core(arena, parsed, invocation, args, entry, source);
|
|
122
|
+
for (result.diagnostics) |diagnostic| diags.flag(diagnostic.path, "{s}", .{diagnostic.message});
|
|
123
|
+
if (result.exit_code != 0) {
|
|
124
|
+
if (result.@"error".len != 0) try stderr.writeAll(result.@"error") else try diags.write(input, stderr);
|
|
125
|
+
try stderr.flush();
|
|
126
|
+
std.process.exit(result.exit_code);
|
|
127
|
+
}
|
|
128
|
+
const generated = result.mirror;
|
|
129
|
+
const facade = result.facade;
|
|
130
|
+
const profile = result.profile;
|
|
131
|
+
const effective_sidecar = result.effective;
|
|
132
|
+
|
|
133
|
+
// Warnings (unknown additive fields) surface even on success.
|
|
134
|
+
try diags.write(input, stderr);
|
|
135
|
+
try stderr.flush();
|
|
136
|
+
|
|
137
|
+
// Stage-then-commit: ALL projections write completely into
|
|
138
|
+
// exclusively-created staging files before any rename, so a write
|
|
139
|
+
// failure can never leave a fresh shim beside a stale sibling. The
|
|
140
|
+
// renames remain separate filesystem operations — a failure between
|
|
141
|
+
// them reports the files as a possibly skewed set and the nonzero
|
|
142
|
+
// exit makes the caller regenerate; concurrent invocations aimed at
|
|
143
|
+
// ONE output path are the caller's serialization to provide (the
|
|
144
|
+
// build graph never shares output directories between steps).
|
|
145
|
+
const Output = struct {
|
|
146
|
+
flag: []const u8,
|
|
147
|
+
path: []const u8,
|
|
148
|
+
data: []const u8,
|
|
149
|
+
staged: []const u8 = "",
|
|
150
|
+
};
|
|
151
|
+
var outputs_buffer: [4]Output = undefined;
|
|
152
|
+
var output_count: usize = 0;
|
|
153
|
+
if (out_path) |path| {
|
|
154
|
+
outputs_buffer[output_count] = .{ .flag = "--out", .path = path, .data = generated };
|
|
155
|
+
output_count += 1;
|
|
156
|
+
}
|
|
157
|
+
if (facade_path) |path| {
|
|
158
|
+
outputs_buffer[output_count] = .{ .flag = "--facade", .path = path, .data = facade };
|
|
159
|
+
output_count += 1;
|
|
160
|
+
}
|
|
161
|
+
if (profile_path) |path| {
|
|
162
|
+
outputs_buffer[output_count] = .{ .flag = "--profile", .path = path, .data = profile };
|
|
163
|
+
output_count += 1;
|
|
164
|
+
}
|
|
165
|
+
if (effective_sidecar_path) |path| {
|
|
166
|
+
outputs_buffer[output_count] = .{ .flag = "--effective-sidecar", .path = path, .data = effective_sidecar };
|
|
167
|
+
output_count += 1;
|
|
168
|
+
}
|
|
169
|
+
const outputs = outputs_buffer[0..output_count];
|
|
170
|
+
|
|
171
|
+
for (outputs, 0..) |*output, output_index| {
|
|
172
|
+
// Earlier staging files exist now, so a filesystem-level alias
|
|
173
|
+
// of two output paths (Unicode case folding, links) gets one
|
|
174
|
+
// more net before any rename.
|
|
175
|
+
for (outputs[0..output_index]) |earlier| {
|
|
176
|
+
if (sameExistingFile(init.io, output.path, earlier.path)) {
|
|
177
|
+
for (outputs[0..output_index]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
|
|
178
|
+
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 });
|
|
179
|
+
try stderr.flush();
|
|
180
|
+
std.process.exit(2);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
output.staged = stageOutput(init, stderr, output.path, output.data) catch |err| {
|
|
184
|
+
// Sibling projections were already staged; leave no stray
|
|
185
|
+
// staging file behind ANY failure shape.
|
|
186
|
+
for (outputs[0..output_index]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
|
|
187
|
+
switch (err) {
|
|
188
|
+
error.Staging => std.process.exit(1),
|
|
189
|
+
else => return err,
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
for (outputs, 0..) |output, output_index| {
|
|
195
|
+
// Committed outputs now EXIST, so aliases no spelling check can
|
|
196
|
+
// see (filesystem Unicode normalization above all) finally
|
|
197
|
+
// resolve: a target that reaches a just-committed sibling
|
|
198
|
+
// refuses instead of replacing it.
|
|
199
|
+
for (outputs[0..output_index]) |earlier| {
|
|
200
|
+
if (sameExistingFile(init.io, output.path, earlier.path)) {
|
|
201
|
+
for (outputs[output_index..]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
|
|
202
|
+
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 });
|
|
203
|
+
try stderr.flush();
|
|
204
|
+
std.process.exit(2);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
std.Io.Dir.cwd().rename(output.staged, std.Io.Dir.cwd(), output.path, init.io) catch |err| {
|
|
208
|
+
for (outputs[output_index..]) |staged| std.Io.Dir.cwd().deleteFile(init.io, staged.staged) catch {};
|
|
209
|
+
if (output_index > 0) {
|
|
210
|
+
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 });
|
|
211
|
+
} else {
|
|
212
|
+
try stderr.print("corewire: cannot write {s}: {t}\n", .{ output.path, err });
|
|
213
|
+
}
|
|
214
|
+
try stderr.flush();
|
|
215
|
+
std.process.exit(1);
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/// The service contract is a distinct schema from core.contract.json. Keep
|
|
221
|
+
/// its projection mode explicit so neither reader can accidentally accept a
|
|
222
|
+
/// document from the other class.
|
|
223
|
+
fn serviceProjection(init: std.process.Init, args: []const []const u8, invocation: invocation_mod.Plan, stderr: *std.Io.Writer) !void {
|
|
224
|
+
const sidecar_path = args[invocation.input.?];
|
|
225
|
+
const optimization = if (invocation.optimization) |index| args[index] else null;
|
|
226
|
+
const arena = init.arena.allocator();
|
|
227
|
+
const source = std.Io.Dir.cwd().readFileAlloc(init.io, sidecar_path, arena, .limited(service_contract_mod.max_bytes)) catch |err| {
|
|
228
|
+
try stderr.print("corewire: cannot read {s}: {t}\n", .{ sidecar_path, err });
|
|
229
|
+
try stderr.flush();
|
|
230
|
+
std.process.exit(1);
|
|
231
|
+
};
|
|
232
|
+
const contract = service_contract_mod.read(arena, source, stderr) catch |err| switch (err) {
|
|
233
|
+
error.InvalidContract => {
|
|
234
|
+
try stderr.flush();
|
|
235
|
+
std.process.exit(1);
|
|
236
|
+
},
|
|
237
|
+
error.OutOfMemory => return error.OutOfMemory,
|
|
238
|
+
error.WriteFailed => return error.WriteFailed,
|
|
239
|
+
};
|
|
240
|
+
// The planner owns output selection and order. Native keeps the
|
|
241
|
+
// original sequential write behavior, including partial service outputs.
|
|
242
|
+
for (invocation.outputs) |out| {
|
|
243
|
+
const path = args[out.path_index];
|
|
244
|
+
const generated = switch (out.kind) {
|
|
245
|
+
.host => try emit_service_mod.emitHost(arena, contract),
|
|
246
|
+
.registry => try emit_service_mod.emitRegistry(arena, contract),
|
|
247
|
+
.client => try emit_service_mod.emitClient(arena, contract),
|
|
248
|
+
.inproc_main => try emit_service_mod.emitInprocMain(arena, contract),
|
|
249
|
+
.inproc_profile => try emit_service_mod.emitInprocProfile(arena, optimization),
|
|
250
|
+
else => unreachable,
|
|
251
|
+
};
|
|
252
|
+
std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = path, .data = generated }) catch |err| {
|
|
253
|
+
try stderr.print("corewire: cannot write {s}: {t}\n", .{ path, err });
|
|
254
|
+
try stderr.flush();
|
|
255
|
+
std.process.exit(1);
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
try stderr.flush();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/// The facade path as the profile's entry spelling: relative to the
|
|
262
|
+
/// profile file's directory (the compilation root a profile consumer
|
|
263
|
+
/// resolves against), POSIX separators. A pair that cannot relate
|
|
264
|
+
/// (distinct roots) refuses with a teaching — a wrong spelling would
|
|
265
|
+
/// point the consumer at a file that does not exist.
|
|
266
|
+
fn profileRelativeEntry(init: std.process.Init, profile_dir: []const u8, facade_path: []const u8) !invocation_mod.Entry {
|
|
267
|
+
const arena = init.arena.allocator();
|
|
268
|
+
var buffer: [std.fs.max_path_bytes]u8 = undefined;
|
|
269
|
+
const cwd_len = std.Io.Dir.cwd().realPath(init.io, &buffer) catch 0;
|
|
270
|
+
const cwd: []const u8 = if (cwd_len == 0) "." else buffer[0..cwd_len];
|
|
271
|
+
const related = try std.fs.path.relative(arena, cwd, init.environ_map, profile_dir, facade_path);
|
|
272
|
+
const posix = try arena.dupe(u8, related);
|
|
273
|
+
if (std.fs.path.sep == std.fs.path.sep_windows) for (posix) |*char| {
|
|
274
|
+
if (char.* == std.fs.path.sep_windows) char.* = std.fs.path.sep_posix;
|
|
275
|
+
};
|
|
276
|
+
const valid = std.unicode.utf8ValidateSlice(posix);
|
|
277
|
+
return .{ .text = if (valid) posix else "", .bytes = posix, .utf8 = valid, .unrelated = related.len == 0 or std.fs.path.isAbsolute(related), .facade_path = facade_path, .profile_directory = profile_dir };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/// A path spelling fit for alias comparison: components canonicalize
|
|
281
|
+
/// one at a time against the filesystem, so `..` applies to the REAL
|
|
282
|
+
/// parent (never lexically across a symlink), symlinked or case-folded
|
|
283
|
+
/// ancestors land on one spelling, and a not-yet-existing tail rides
|
|
284
|
+
/// verbatim — two spellings of one future file compare equal even
|
|
285
|
+
/// before the file exists.
|
|
286
|
+
fn canonicalSpelling(io: std.Io, arena: std.mem.Allocator, path: []const u8) ![]const u8 {
|
|
287
|
+
var buffer: [std.fs.max_path_bytes]u8 = undefined;
|
|
288
|
+
// Platform-aware parsing: the component iterator understands the
|
|
289
|
+
// native roots and separators (drive and UNC spellings included),
|
|
290
|
+
// so two spellings of one root land on one prefix.
|
|
291
|
+
var components = std.fs.path.componentIterator(path);
|
|
292
|
+
const root = components.root();
|
|
293
|
+
if (root != null and !std.fs.path.isAbsolute(path)) {
|
|
294
|
+
// A drive-RELATIVE spelling (C:foo) names a file under that
|
|
295
|
+
// drive's own working directory, which this process cannot
|
|
296
|
+
// resolve portably; folding it under the drive root would
|
|
297
|
+
// manufacture false aliases against drive-absolute spellings.
|
|
298
|
+
// Keep it lexical — the existence-based nets and rename landing
|
|
299
|
+
// still guard the writes.
|
|
300
|
+
return std.fs.path.resolve(arena, &.{path});
|
|
301
|
+
}
|
|
302
|
+
var base: []const u8 = if (root) |prefix|
|
|
303
|
+
try arena.dupe(u8, prefix)
|
|
304
|
+
else blk: {
|
|
305
|
+
const len = std.Io.Dir.cwd().realPath(io, &buffer) catch break :blk try arena.dupe(u8, ".");
|
|
306
|
+
break :blk try arena.dupe(u8, buffer[0..len]);
|
|
307
|
+
};
|
|
308
|
+
var exists = true;
|
|
309
|
+
while (components.next()) |component| {
|
|
310
|
+
if (std.mem.eql(u8, component.name, ".")) continue;
|
|
311
|
+
if (std.mem.eql(u8, component.name, "..")) {
|
|
312
|
+
// `base` carries no symlinks once canonical, so its lexical
|
|
313
|
+
// parent IS its real parent; a `..` under a nonexistent
|
|
314
|
+
// tail unwinds the tail it just added — and may land back
|
|
315
|
+
// on EXISTING ground, so canonicalization must resume (a
|
|
316
|
+
// symlink after the pop would otherwise ride unresolved).
|
|
317
|
+
base = std.fs.path.dirname(base) orelse base;
|
|
318
|
+
if (!exists) {
|
|
319
|
+
if (std.Io.Dir.cwd().realPathFile(io, base, &buffer)) |len| {
|
|
320
|
+
base = try arena.dupe(u8, buffer[0..len]);
|
|
321
|
+
exists = true;
|
|
322
|
+
} else |_| {}
|
|
323
|
+
}
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const candidate = try std.fs.path.join(arena, &.{ base, component.name });
|
|
327
|
+
if (exists) {
|
|
328
|
+
if (std.Io.Dir.cwd().realPathFile(io, candidate, &buffer)) |len| {
|
|
329
|
+
base = try arena.dupe(u8, buffer[0..len]);
|
|
330
|
+
continue;
|
|
331
|
+
} else |_| {
|
|
332
|
+
exists = false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
base = candidate;
|
|
336
|
+
}
|
|
337
|
+
return base;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/// Whether two paths currently resolve to one existing file, by asking
|
|
341
|
+
/// the filesystem for canonical paths: the alias net behind the lexical
|
|
342
|
+
/// checks (Unicode case folding, symlinks — a canonical path is unique
|
|
343
|
+
/// per volume, so distinct files can never compare equal). Nonexistent
|
|
344
|
+
/// paths are distinct. Hard links carry distinct canonical paths and
|
|
345
|
+
/// pass this check — harmless by construction, because outputs land by
|
|
346
|
+
/// rename (writeOutput), which replaces a directory entry and never
|
|
347
|
+
/// writes through one.
|
|
348
|
+
fn sameExistingFile(io: std.Io, a: []const u8, b: []const u8) bool {
|
|
349
|
+
var buffer_a: [std.fs.max_path_bytes]u8 = undefined;
|
|
350
|
+
var buffer_b: [std.fs.max_path_bytes]u8 = undefined;
|
|
351
|
+
const len_a = std.Io.Dir.cwd().realPathFile(io, a, &buffer_a) catch return false;
|
|
352
|
+
const len_b = std.Io.Dir.cwd().realPathFile(io, b, &buffer_b) catch return false;
|
|
353
|
+
if (std.mem.eql(u8, buffer_a[0..len_a], buffer_b[0..len_b])) return true;
|
|
354
|
+
// Distinct canonical paths can still name one DIRECTORY ENTRY where
|
|
355
|
+
// a mount exposes a directory twice (bind mounts) — the case the
|
|
356
|
+
// rename landing cannot save, because replacing the entry through
|
|
357
|
+
// either spelling replaces it for both. A hard link is the
|
|
358
|
+
// opposite: two entries for one file, and the rename replaces only
|
|
359
|
+
// the named entry, so it must NOT trip this check. Same entry means
|
|
360
|
+
// same parent directory and same on-disk basename; the portable
|
|
361
|
+
// stat carries no device id, so parent identity is inferred from
|
|
362
|
+
// full metadata agreement (a coincidental match across volumes
|
|
363
|
+
// merely refuses a spelling nobody needs).
|
|
364
|
+
const canon_a = buffer_a[0..len_a];
|
|
365
|
+
const canon_b = buffer_b[0..len_b];
|
|
366
|
+
if (!std.mem.eql(u8, std.fs.path.basename(canon_a), std.fs.path.basename(canon_b))) return false;
|
|
367
|
+
const parent_a = std.fs.path.dirname(canon_a) orelse return false;
|
|
368
|
+
const parent_b = std.fs.path.dirname(canon_b) orelse return false;
|
|
369
|
+
const stat_a = std.Io.Dir.cwd().statFile(io, parent_a, .{}) catch return false;
|
|
370
|
+
const stat_b = std.Io.Dir.cwd().statFile(io, parent_b, .{}) catch return false;
|
|
371
|
+
return stat_a.inode == stat_b.inode and stat_a.kind == stat_b.kind and
|
|
372
|
+
stat_a.size == stat_b.size and stat_a.nlink == stat_b.nlink and
|
|
373
|
+
stat_a.mtime.nanoseconds == stat_b.mtime.nanoseconds and
|
|
374
|
+
stat_a.ctime.nanoseconds == stat_b.ctime.nanoseconds;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/// Write `data` into an exclusively-created, uniquely-named staging
|
|
378
|
+
/// file beside `out` and return its path; the caller commits by rename.
|
|
379
|
+
/// Exclusive creation can never truncate an existing entry (whatever it
|
|
380
|
+
/// links to), and the unique suffix keeps concurrent invocations off
|
|
381
|
+
/// each other's bytes. Failures print their teaching and return
|
|
382
|
+
/// error.Staging so the caller can delete sibling staging files.
|
|
383
|
+
fn stageOutput(init: std.process.Init, stderr: *std.Io.Writer, out: []const u8, data: []const u8) ![]const u8 {
|
|
384
|
+
if (std.fs.path.dirname(out)) |dir| {
|
|
385
|
+
std.Io.Dir.cwd().createDirPath(init.io, dir) catch {};
|
|
386
|
+
}
|
|
387
|
+
const arena = init.arena.allocator();
|
|
388
|
+
var nonce: [8]u8 = undefined;
|
|
389
|
+
init.io.random(&nonce);
|
|
390
|
+
const temp_path = try std.fmt.allocPrint(arena, "{s}.corewire-tmp.{x}", .{ out, &nonce });
|
|
391
|
+
const staging = std.Io.Dir.cwd().createFile(init.io, temp_path, .{ .exclusive = true }) catch |err| {
|
|
392
|
+
try stderr.print("corewire: cannot stage {s}: {t}\n", .{ temp_path, err });
|
|
393
|
+
try stderr.flush();
|
|
394
|
+
return error.Staging;
|
|
395
|
+
};
|
|
396
|
+
var write_failed = false;
|
|
397
|
+
{
|
|
398
|
+
defer staging.close(init.io);
|
|
399
|
+
var buffer: [4096]u8 = undefined;
|
|
400
|
+
var writer = staging.writerStreaming(init.io, &buffer);
|
|
401
|
+
writer.interface.writeAll(data) catch {
|
|
402
|
+
write_failed = true;
|
|
403
|
+
};
|
|
404
|
+
if (!write_failed) writer.interface.flush() catch {
|
|
405
|
+
write_failed = true;
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (write_failed) {
|
|
409
|
+
std.Io.Dir.cwd().deleteFile(init.io, temp_path) catch {};
|
|
410
|
+
try stderr.print("corewire: cannot write {s}\n", .{temp_path});
|
|
411
|
+
try stderr.flush();
|
|
412
|
+
return error.Staging;
|
|
413
|
+
}
|
|
414
|
+
return temp_path;
|
|
415
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Exact generated code text shared with the preserved projection fixtures.
|
|
2
|
+
export const header = "//! Generated by corewire from this app's core.contract.json — the\n//! host-side mirror of a compiled TypeScript core. The source types\n//! reproduce the compiled core's contract exactly (field names,\n//! declaration order, number classes), so the markup engines, the\n//! adapter, the bridge, and the model-contract step reflect over it\n//! the way they reflect over transpiler output. RuntimeModel is a\n//! stateless handle for compiled views and helpers. Do not edit;\n//! regenerate from the sidecar.\n//!\n//! Compiled core identity: entry {s}, compiler {s},\n//! build_id {x:0>16} (checked against the object's exported getter\n//! before the first dispatch).\n\nconst std = @import(\"std\");\nconst shim_rt = @import(\"shim_rt.zig\");\nconst core_abi = @import(\"core_abi.zig\");\nconst abi = core_abi.Bindings(\"{f}\");\n\n/// The sidecar's identity facts, restated for the boot-time pairing\n/// fence (the out-of-graph backstop: a cached or hand-copied core\n/// must never dispatch against another build's tag order).\npub const sidecar_build_id: u64 = 0x{x:0>16};\npub const sidecar_model_fingerprint: u64 = 0x{x:0>16};\npub const sidecar_abi_version: u32 = {d};\npub const sidecar_snapshot_format: u32 = {d};\n\n/// The compiler's module-graph attestations, restated so host\n/// policy can gate on them: record/replay arms only against a\n/// deterministic core, and loop-free-core policies read\n/// async_free. Computed facts of the compiled graph — the sidecar\n/// records verdicts, never hopes.\npub const deterministic: bool = {};\npub const async_free: bool = {};\n\n/// The kernel surface the host layer drives, forwarded to the shim\n/// arena and the core's own frame reset (one cycle boundary for\n/// both sides).\npub const rt = struct {{\n pub const Cmd = []const u8;\n pub const Sub = []const u8;\n pub const cmd_none: Cmd = &.{{}};\n pub const sub_none: Sub = &.{{}};\n pub fn frameAllocator() std.mem.Allocator {{\n return shim_rt.frameAllocator();\n }}\n pub fn frameAlloc(comptime T: type, n: usize) []T {{\n return shim_rt.frameAlloc(T, n);\n }}\n pub fn frameCreate(comptime T: type, value: T) *T {{\n return shim_rt.frameCreate(T, value);\n }}\n pub fn decodeExact(comptime T: type, bytes: []const u8) T {{\n return shim_rt.decodeExact(T, bytes, shim_rt.frameAllocator());\n }}\n pub fn copyServiceBytes(bytes: []const u8) []const u8 {{\n return shim_rt.frameAllocator().dupe(u8, bytes) catch @panic(\"service result allocation failed\");\n }}\n pub fn frameReset() void {{\n shim_rt.frameReset();\n abi.frame_reset();\n }}\n pub fn snapshotDecodeCount() usize {{\n return shim_rt.snapshotDecodeCount();\n }}\n pub fn resetAll() void {{\n decoded_model = null;\n shim_rt.resetAll();\n }}\n}};";
|
|
3
|
+
export const tagTablePrelude = "\n/// Declaration-order wire tags: the arm's index in this table IS\n/// its wire tag (dense, u8). The sidecar is the tag authority; the\n/// compiled object's lowering assigns the same order, and the\n/// boot-time build_id fence proves both came from one compile.\npub const msg_tags = [_][]const u8{";
|
|
4
|
+
export const tagTableFence = "\ncomptime {{\n @setEvalBranchQuota({d});\n // The union and the tag table are emitted from one arm list;\n // hold them equal anyway so a hand edit cannot skew dispatch.\n const fields = @typeInfo({f}).@\"union\".fields;\n if (fields.len != msg_tags.len) @compileError(\"core_shim: Msg arm count does not match msg_tags\");\n for (fields, msg_tags) |field, tag_name| {{\n if (!std.mem.eql(u8, field.name, tag_name)) @compileError(\"core_shim: Msg arm names do not match msg_tags\");\n }}\n}}\n";
|
|
5
|
+
export const exportAttestation = "\nfn boot() void {\n referenceAttestedExports();\n shim_rt.verifyIdentity(abi.abi_version_fn(), abi.build_id(), sidecar_abi_version, sidecar_build_id);\n abi.set_panic_sink(shim_rt.panicSink, null);\n decoded_model = null;\n abi.init();\n}\n\n/// The sidecar's abi.exports list is a biconditional attestation:\n/// every listed symbol exists in the object, and the object\n/// exports nothing else under the prefix. Referencing each listed\n/// symbol makes the LINKER prove the \"exists\" direction against\n/// the real binary. The \"nothing else\" direction is not provable\n/// from the consumer side — a linker ignores unreferenced extra\n/// exports, and this generator never opens the object — so it\n/// belongs to the producer's conformance suite, which probes the\n/// object's full symbol table at compile time.\nfn referenceAttestedExports() void {\n";
|
|
6
|
+
export const bootWithCommand = "\npub const InitResult = struct {{ model: *const {s}, cmd: rt.Cmd }};\n\npub fn initialModel() InitResult {{\n boot();\n return .{{ .model = snapshotModel(), .cmd = bootCommand() }};\n}}\n";
|
|
7
|
+
export const bootModel = "\npub fn initialModel() *const {s} {{\n boot();\n return snapshotModel();\n}}\n";
|
|
8
|
+
export const updateWithCommand = "\npub const UpdateResult = struct {{ model: *const {s}, cmd: rt.Cmd }};\n\npub fn update(model: *const {s}, msg: {f}) UpdateResult {{\n";
|
|
9
|
+
export const updateModel = "\npub fn update(model: *const {s}, msg: {f}) *const {s} {{\n";
|
|
10
|
+
export const dispatchPrelude = " decoded_model = null;\n // The compiled core owns the committed state; the mirror root\n // the host passes is a decoded copy, so only tag and payload\n // cross the boundary.\n _ = model;\n var cmd_ptr: [*]const u8 = undefined;\n var cmd_len: usize = 0;\n switch (msg) {\n";
|
|
11
|
+
export const subscriptions = "\npub fn subscriptions(model: *const {s}) rt.Sub {{\n // The core derives subscriptions from its own committed\n // model; the mirror root only satisfies the signature the\n // host layer expects.\n _ = model;\n var subs_ptr: [*]const u8 = undefined;\n var subs_len: usize = 0;\n abi.subscriptions(&subs_ptr, &subs_len);\n return subs_ptr[0..subs_len];\n}}\n";
|
|
12
|
+
export const commitModelRoot = "\n/// Commit happens inside every dispatch entry core-side; the\n/// decoded mirror is already the committed value, so the frame-end\n/// commit is identity here.\npub fn commitModelRoot(next: *const {s}) *const {s} {{\n return next;\n}}\n";
|
|
13
|
+
export const nativeView = "\n/// Copy view data into the native tree arena before resetting the\n/// compiler result arena. No model mirror is passed to this entry.\npub fn nativeView(arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_view(&ptr, &len);\n defer abi.frame_reset();\n if (len > 4 * 1024 * 1024) @panic(\"compiled view exceeds 4 MiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled view allocation failed\");\n}\n";
|
|
14
|
+
export const nativeWindowView = "\n/// Window label selects a view over the same committed model.\n/// Copy before resetting scriptc's shared result arena.\npub fn nativeWindowView(label: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_window_view(label.ptr, label.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > 4 * 1024 * 1024) @panic(\"compiled window view exceeds 4 MiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled window view allocation failed\");\n}\n";
|
|
15
|
+
export const nativeRadioPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeRadioPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_radio_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled radio policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
16
|
+
export const nativeTabsPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeTabsPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_tabs_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled tabs policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
17
|
+
export const nativeTreePolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeTreePolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_tree_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled tree policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
18
|
+
export const nativeListPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeListPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_list_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled list policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
19
|
+
export const nativeMenuPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeMenuPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_menu_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled menu policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
20
|
+
export const nativeTogglePolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeTogglePolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_toggle_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled toggle policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
21
|
+
export const nativeAccordionPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeAccordionPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_accordion_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled accordion policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
22
|
+
export const nativeSliderPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeSliderPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_slider_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled slider policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
23
|
+
export const nativeSplitPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeSplitPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_split_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled split policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
24
|
+
export const nativeScrollPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeScrollPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_scroll_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled scroll policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
25
|
+
export const nativeResizablePolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeResizablePolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_resizable_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled resizable policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
26
|
+
export const nativeTextPolicy = "\n/// Pure retained policy: copy the result before resetting the arena.\npub fn nativeTextPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > output.len) @panic(\"invalid compiled text policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativePressHoldPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled press hold policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Copy the focus plan; the owning cycle resets the frame.\npub fn nativeTabFocusPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled Tab focus policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Copy the surface plan; finishCycle owns the frame reset.\npub fn nativeSurfaceScopePolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled surface scope policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Copy the tooltip verdict; finishCycle owns the frame reset.\npub fn nativeTooltipPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled tooltip policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Copy the focus return; finishCycle owns the frame reset.\npub fn nativeFocusReturnPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_text_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled focus return policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
27
|
+
export const nativeTimerPolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeTimerPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_timer_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled timer policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
28
|
+
export const nativeDbPolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeDbPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_db_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled database policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
29
|
+
export const nativeEffectPolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeEffectPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_effect_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled effect policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
30
|
+
export const nativeStreamPolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeStreamPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_stream_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled stream policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
31
|
+
export const nativeWindowPolicy = "\n/// Rebuild policy: copy results; view/cycle consumers own frame resets.\npub fn nativeWindowPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_window_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled window policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n\n/// Copy the variable-size Markdown recipe; the consumer owns frame resets.\npub fn nativeMarkdownPolicy(request: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_window_policy(request.ptr, request.len, &ptr, &len);\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled Markdown recipe allocation failed\");\n}\n";
|
|
32
|
+
export const nativeThemePolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeThemePolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_theme_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled theme policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
33
|
+
export const nativeStatusPolicy = "\n/// Cycle policy: copy results; finishCycle owns the frame reset.\npub fn nativeStatusPolicy(request: []const u8, output: []u8) usize {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_status_policy(request.ptr, request.len, &ptr, &len);\n if (len > output.len) @panic(\"invalid compiled status policy result\");\n @memcpy(output[0..len], ptr[0..len]);\n return len;\n}\n";
|
|
34
|
+
export const commandChannel = "\n/// Menus, shortcuts, and chrome tabs dispatch through the core's\n/// exported command mapper.\npub fn commandMsg(name: []const u8) ?{f} {{\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.command_msg(name.ptr, name.len, &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|
|
35
|
+
export const frameChannel = "\n/// The presented-frame channel's record: canvas points plus the\n/// frame clock in fractional milliseconds. The adapter builds it\n/// by field name, exactly as for transpiler output.\npub const FrameEvent = struct {{\n width: f64,\n height: f64,\n timestampMs: f64,\n intervalMs: f64,\n}};\n\npub fn frameMsg(model: *const {f}, frame: FrameEvent) ?{f} {{\n _ = model;\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.frame_msg(frame.width, frame.height, frame.timestampMs, frame.intervalMs, &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|
|
36
|
+
export const keyChannel = "\n/// The key-fallback channel's record: the lowercased key name\n/// plus the four modifier booleans.\npub const KeyEvent = struct {{\n key: []const u8,\n shift: bool,\n control: bool,\n alt: bool,\n super: bool,\n}};\n\npub fn keyMsg(key: KeyEvent) ?{f} {{\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.key_msg(key.key.ptr, key.key.len, @intFromBool(key.shift), @intFromBool(key.control), @intFromBool(key.alt), @intFromBool(key.super), &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|
|
37
|
+
export const pinchChannel = "\npub const PinchPhase = enum(u8) {{ begin = 0, change = 1, end = 2 }};\n\n/// The pinch channel's record: window/view source identity, the\n/// multiplicative magnification delta, and the view-local anchor.\npub const PinchEvent = struct {{\n windowId: f64,\n label: []const u8,\n phase: PinchPhase,\n scale: f64,\n x: f64,\n y: f64,\n}};\n\npub fn pinchMsg(pinch: PinchEvent) ?{f} {{\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.pinch_msg(pinch.windowId, pinch.label.ptr, pinch.label.len, @intCast(@intFromEnum(pinch.phase)), pinch.scale, pinch.x, pinch.y, &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|
|
38
|
+
export const dropChannel = "\n/// A file drop's optional view-local point.\npub const FileDropPoint = struct {{\n x: f64,\n y: f64,\n}};\n\n/// The file-drop channel's source identity, optional point,\n/// and byte-text path list.\npub const FileDropEvent = struct {{\n windowId: f64,\n viewLabel: []const u8,\n point: ?FileDropPoint,\n paths: []const []const u8,\n}};\n\npub fn dropMsg(drop: FileDropEvent) ?{f} {{\n const encoded = shim_rt.encodeAlloc(FileDropEvent, drop, shim_rt.frameAllocator());\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.drop_msg(encoded.ptr, encoded.len, &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|
|
39
|
+
export const envMessageTypes = "\n/// The launch-time environment channel: each variable present at\n/// launch dispatches one journaled Msg on its bytes arm, right\n/// after the boot command. The core itself never reads the\n/// environment; replay carries the recorded values.\npub const envMsgs = .{\n";
|
|
40
|
+
export const decodeMessagePrelude = "\n/// Unpack a channel entry's bytes envelope — [produced u8][tag u8]\n/// [payload…]: the header says whether a message was produced, the\n/// wire tag picks the arm, and the payload rides the canonical\n/// value encoding of that arm's mirror payload type. Malformed\n/// framing panics with a teaching in shim_rt.channelEnvelope; a\n/// tag past the declared arms panics here.\nfn msgFromEnvelope(envelope: []const u8) ?{f} {{\n return decodeMsgEnvelope(envelope, shim_rt.frameAllocator());\n}}\nfn decodeMsgEnvelope(envelope: []const u8, arena: std.mem.Allocator) ?{f} {{\n _ = &arena;\n const header = shim_rt.channelEnvelope(envelope);\n if (!header.produced) return null;\n switch (header.tag) {{\n";
|
|
41
|
+
export const decodeMessageEnd = " else => @panic(\"the compiled core's channel envelope carries a message tag past the declared arms — the core and its contract sidecar disagree; rebuild the app so both come from one compile\"),\n }\n}\n";
|
|
42
|
+
export const helperPlumbing = "\n/// Call the compiled core's exported helper at `index` (the\n/// sidecar's model_helpers order IS the call index) and decode the\n/// result. An unknown index traps core-side through the panic\n/// sink; there is no status to check. Results are read-arena\n/// resident, the same until-next-dispatch lifetime view builds get\n/// from transpiler output.\nfn callHelper(comptime T: type, index: u32, args: []const u8, allocator: std.mem.Allocator) T {\n var out_ptr: [*]const u8 = undefined;\n var out_len: usize = 0;\n abi.helper_call(index, args.ptr, args.len, &out_ptr, &out_len);\n return shim_rt.decodeExact(T, out_ptr[0..out_len], allocator);\n}\n";
|
|
43
|
+
export const snapshotPlumbing = "\n/// Borrow the compiled core's positional model-mirror bytes.\n/// Valid until the next core ABI call.\npub fn modelSnapshot() []const u8 {{\n var snap_ptr: [*]const u8 = undefined;\n var snap_len: usize = 0;\n abi.model_snapshot(&snap_ptr, &snap_len);\n return snap_ptr[0..snap_len];\n}}\n\n/// Borrow the tagged, length-delimited durable snapshot\n/// (persistence snapshot format {d}). Valid until the next core\n/// ABI call.\npub fn persistenceSnapshot() []const u8 {{\n var snap_ptr: [*]const u8 = undefined;\n var snap_len: usize = 0;\n abi.persist_snapshot(&snap_ptr, &snap_len);\n return snap_ptr[0..snap_len];\n}}\n\n/// Decode the committed model into the shim read arena.\nvar decoded_model: ?*const {f} = null;\n\npub fn snapshotModel() *const {f} {{\n if (decoded_model == null) decoded_model = shim_rt.decodeSnapshot({f}, modelSnapshot());\n return decoded_model.?;\n}}\n\n/// Replace the compiled core's committed model, then refresh the\n/// read-arena mirror returned to the host.\npub fn restoreModel(snapshot: []const u8) *const {f} {{\n restoreCommittedModel(snapshot);\n return snapshotModel();\n}}\n\nfn restoreCommittedModel(snapshot: []const u8) void {{\n decoded_model = null;\n var out_ptr: [*]const u8 = undefined;\n var out_len: usize = 0;\n abi.restore_model(snapshot.ptr, snapshot.len, &out_ptr, &out_len);\n if (out_len != 0) @panic(\"core_shim: restore_model returned bytes; ABI version 2 requires an empty result\");\n}}\n\n\n/// Run the app's pure migration hook and copy the resulting\n/// current-format snapshot out of the core result arena. Null is\n/// the hook's closed failure result (including no hook).\npub fn migrateModel(snapshot: []const u8, from_version: u64, allocator: std.mem.Allocator) ?[]u8 {{\n var out_ptr: [*]const u8 = undefined;\n var out_len: usize = 0;\n abi.migrate_model(snapshot.ptr, snapshot.len, @floatFromInt(from_version), &out_ptr, &out_len);\n if (out_len < 1 or out_ptr[0] != 1) return null;\n return allocator.dupe(u8, out_ptr[1..out_len]) catch null;\n}}\n";
|
|
44
|
+
export const nativeMediaView = "\n/// Window label selects a view over the same committed model.\n/// Copy before resetting scriptc's shared result arena.\npub fn nativeMediaView(request: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_media_view(request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > 4 * 1024 * 1024) @panic(\"compiled window view exceeds 4 MiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled window view allocation failed\");\n}\n";
|
|
45
|
+
export const nativeMediaWindowView = "\n/// Window label selects a view over the same committed model.\n/// Copy before resetting scriptc's shared result arena.\npub fn nativeMediaWindowView(label: []const u8, request: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_media_window_view(label.ptr, label.len, request.ptr, request.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > 4 * 1024 * 1024) @panic(\"compiled window view exceeds 4 MiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled window view allocation failed\");\n}\n";
|
|
46
|
+
|
|
47
|
+
export const nativeVirtualRequests = "\n/// Copy descriptors before resetting the compiler result arena.\npub fn nativeVirtualRequests(label: []const u8, video: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_virtual_requests(label.ptr, label.len, video.ptr, video.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > 64 * 1024) @panic(\"compiled virtual descriptors exceed 64 KiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled descriptor allocation failed\");\n}\n";
|
|
48
|
+
export const nativeVirtualView = "\n/// Range facts flow into compiled row construction; results are tree-owned.\npub fn nativeVirtualView(label: []const u8, context: []const u8, video: []const u8, arena: std.mem.Allocator) []const u8 {\n var ptr: [*]const u8 = undefined;\n var len: usize = 0;\n abi.native_virtual_view(label.ptr, label.len, context.ptr, context.len, video.ptr, video.len, &ptr, &len);\n defer abi.frame_reset();\n if (len > 4 * 1024 * 1024) @panic(\"compiled virtual view exceeds 4 MiB\");\n return arena.dupe(u8, ptr[0..len]) catch @panic(\"compiled virtual view allocation failed\");\n}\n";
|
|
49
|
+
|
|
50
|
+
// Compiled views and model helpers observe committed TypeScript state directly.
|
|
51
|
+
export const runtimeEntries = "\npub fn bootCommand() rt.Cmd {{\n var cmd_ptr: [*]const u8 = undefined;\n var cmd_len: usize = 0;\n abi.boot_cmd(&cmd_ptr, &cmd_len);\n return cmd_ptr[0..cmd_len];\n}}\n\npub const RuntimeResult = struct {{ model: *const RuntimeModel, cmd: rt.Cmd }};\nconst runtime_model: RuntimeModel = .{{}};\n\n/// Boot without materializing the source model in native storage.\npub fn initialRuntimeModel() RuntimeResult {{\n boot();\n return .{{ .model = &runtime_model, .cmd = bootCommand() }};\n}}\n\npub fn updateRuntimeModel(model: *const RuntimeModel, msg: {f}) RuntimeResult {{\n _ = model;\n return .{{ .model = &runtime_model, .cmd = dispatchMessage(msg) }};\n}}\n\npub fn commitRuntimeModel(next: *const RuntimeModel) *const RuntimeModel {{\n return next;\n}}\n\npub fn restoreRuntimeModel(snapshot: []const u8) *const RuntimeModel {{\n restoreCommittedModel(snapshot);\n return &runtime_model;\n}}\n";
|
|
52
|
+
export const runtimeSubscriptions = "\npub fn runtimeSubscriptions(model: *const RuntimeModel) rt.Sub {\n _ = model;\n return subscriptions(undefined);\n}\n";
|
|
53
|
+
export const runtimeFrameChannel = "\npub fn runtimeFrameMsg(model: *const RuntimeModel, frame: FrameEvent) ?{f} {{\n _ = model;\n return frameMsg(undefined, frame);\n}}\n";
|
|
54
|
+
|
|
55
|
+
export const frameChannelNs = "\n/// The presented-frame channel's record: canvas points plus the\n/// frame clock in fractional milliseconds. The adapter builds it\n/// by field name, exactly as for transpiler output.\npub const FrameEvent = struct {{\n width: f64,\n height: f64,\n timestampMs: f64,\n intervalMs: f64,\n timestampNs: []const u8,\n intervalNs: []const u8,\n}};\n\npub fn frameMsg(model: *const {f}, frame: FrameEvent) ?{f} {{\n _ = model;\n var out_ptr: [*]const u8 = &shim_rt.channel_out_guard;\n var out_len: usize = 0;\n abi.frame_msg_ns(frame.width, frame.height, frame.timestampMs, frame.intervalMs, frame.timestampNs.ptr, frame.timestampNs.len, frame.intervalNs.ptr, frame.intervalNs.len, &out_ptr, &out_len);\n return msgFromEnvelope(shim_rt.channelEnvelopeBytes(out_ptr, out_len));\n}}\n";
|