@native-sdk/cli 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/bin/native.js +2 -1
- package/build/app.zig +393 -97
- package/build/corewire.zig +53 -0
- package/build/test_shards.zig +49 -0
- package/build/ts_run.mjs +3 -3
- package/build.zig +2030 -83
- package/native-sdk.d.ts +5 -1
- package/package.json +20 -14
- package/packages/core/compile-surface/core.ts +164 -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 +68 -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 +332 -5
- package/packages/core/sdk/core.ts +371 -85
- package/packages/core/sdk/events.d.ts +252 -0
- package/packages/core/sdk/events.ts +240 -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 +186 -19
- package/packages/core/src/cli.ts +2 -11
- 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/context_menus.ts +76 -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/diagnostics.ts +7 -0
- package/packages/core/src/effect_plans.ts +71 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/flow_measurement.ts +121 -0
- package/packages/core/src/font_registry.ts +37 -0
- package/packages/core/src/frontend.ts +12 -10
- 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_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_development.ts +160 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -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 +98 -0
- package/packages/core/src/portable_sources.ts +17 -0
- package/packages/core/src/registered_font.ts +92 -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 +3954 -0
- package/packages/core/src/scalar_text.ts +82 -0
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +55 -3
- 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 +14 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -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_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_components.ts +2415 -0
- package/packages/core/src/view_coordination.ts +198 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +1102 -0
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_audits.ts +202 -0
- package/packages/core/src/widget_changes.ts +258 -0
- package/packages/core/src/widget_continuity.ts +37 -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_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -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/native-ui/SKILL.md +77 -18
- package/skill-data/ts-core/SKILL.md +117 -11
- package/skill-data/ts-services/SKILL.md +1 -1
- package/skill-data/ts-services/references/service-surface.md +288 -144
- package/src/app_runner/root.zig +39 -12
- package/src/app_runner/ts_compiled_view.zig +1702 -0
- package/src/app_runner/ts_core_main.zig +185 -14
- package/src/app_runner/ts_core_mobile.zig +25 -13
- package/src/automation/server.zig +57 -6
- 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/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -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 +4 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +219 -39
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/pointer_motion_test.m +96 -0
- package/src/platform/macos/root.zig +25 -3
- 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/webview_inspection_test.m +106 -0
- package/src/platform/macos/widget_focus_test.m +66 -0
- package/src/platform/null_platform.zig +130 -2
- package/src/platform/null_platform_tests.zig +13 -0
- package/src/platform/root.zig +15 -0
- package/src/platform/types.zig +115 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +17 -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/decision_reuse.zig +133 -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/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -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 +131 -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/markdown_tests.zig +3 -3
- 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 +15 -11
- package/src/primitives/canvas/reference_tests.zig +58 -0
- 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 +107 -4
- 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 +53 -37
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +295 -0
- package/src/primitives/canvas/text_run_policy.zig +252 -0
- package/src/primitives/canvas/text_scalar_policy.zig +234 -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 +47 -0
- package/src/primitives/canvas/ui.zig +251 -83
- package/src/primitives/canvas/ui_markup.zig +207 -46
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -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_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_tests.zig +116 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +3026 -57
- 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 +350 -0
- package/src/primitives/canvas/virtual_extents.zig +113 -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 +129 -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 +21 -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 +26 -0
- package/src/runtime/accessibility_policy.zig +122 -0
- package/src/runtime/api.zig +29 -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/bridge_payload.zig +2 -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 +183 -4
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- 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 +720 -150
- 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/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +170 -6
- package/src/runtime/desktop_files.zig +189 -0
- package/src/runtime/effects.zig +638 -33
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/effects_tests.zig +28 -0
- package/src/runtime/file_policy_test_reference.zig +113 -0
- package/src/runtime/flow.zig +419 -341
- package/src/runtime/flow_reference.zig +1427 -0
- package/src/runtime/font_registry_policy.zig +72 -0
- package/src/runtime/frame_profile.zig +24 -33
- package/src/runtime/global_shortcuts.zig +75 -0
- 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/keyboard_input.zig +86 -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 +16 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -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 +231 -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/staged_rebuild_policy.zig +83 -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 +65 -36
- package/src/runtime/tests.zig +2 -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 +2451 -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 +1111 -45
- package/src/runtime/ui_app.zig +1381 -650
- 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 +667 -188
- package/src/runtime/ui_app_window_tests.zig +222 -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_reload.zig +226 -0
- package/src/runtime/view_widget_control.zig +51 -14
- package/src/runtime/view_widget_scroll.zig +46 -26
- package/src/runtime/view_widget_text.zig +153 -68
- package/src/runtime/view_widget_tree.zig +503 -69
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/webview_view_bridge_tests.zig +2 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_motion_policy.zig +238 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -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 +179 -11
- package/src/security/root.zig +1 -0
- 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/raw_manifest.zig +6 -0
- package/src/tooling/templates.zig +23 -3
- package/src/tooling/ts_core.zig +97 -4
- package/src/tooling/verbs.zig +87 -1
- 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 +188 -0
- package/tools/corewire/core_abi.zig +55 -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 +361 -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 +300 -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 +39 -0
- package/tools/corewire/intake_cases.ts +55 -0
- package/tools/corewire/intake_goldens.json +12237 -0
- package/tools/corewire/invocation.test.ts +28 -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 +59 -0
- package/tools/corewire/profile.test.ts +248 -0
- package/tools/corewire/profile.zig +56 -0
- package/tools/corewire/profile_emission.ts +204 -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 +269 -1438
- package/tools/corewire/emit_profile.zig +0 -521
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
//! Bounded copies for portable descriptor admission; native retains storage.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const manifest = @import("app_manifest");
|
|
4
|
+
const platform = @import("../platform/root.zig");
|
|
5
|
+
const geometry = @import("geometry");
|
|
6
|
+
const reference = @import("validation.zig");
|
|
7
|
+
const comparison = @import("shell_coordination_policy.zig");
|
|
8
|
+
pub const Policy = comparison.Policy;
|
|
9
|
+
pub const Mode = enum(u8) { field, window, view, hierarchy, scene, chrome, chrome_item, duplicate_window, runtime_view, runtime_patch, label, frame };
|
|
10
|
+
const Field = enum(u32) { name, view_label, role, accessibility, text, command, url, chrome_label, chrome_icon, runtime_command };
|
|
11
|
+
comptime {
|
|
12
|
+
if (manifest.max_shell_windows != 16 or manifest.max_shell_views_per_window != 128 or manifest.max_shell_tabs != 5 or manifest.max_view_label_bytes != 64 or manifest.max_view_role_bytes != 64 or manifest.max_view_accessibility_label_bytes != 256 or manifest.max_command_id_bytes != 128 or manifest.max_shell_chrome_label_bytes != 128 or manifest.max_shell_chrome_icon_bytes != 64 or platform.max_view_label_bytes != 64 or platform.max_webview_label_bytes != 64 or platform.max_view_role_bytes != 64 or platform.max_view_accessibility_label_bytes != 256 or platform.max_view_text_bytes != 1024 or @bitSizeOf(usize) > 64 or @intFromEnum(platform.ViewKind.gpu_surface) != 17 or @intFromEnum(platform.ViewKind.webview) != 0 or @intFromEnum(platform.GpuSurfaceBackend.metal) != 1 or @intFromEnum(platform.GpuSurfaceBackend.software) != 3 or @intFromEnum(platform.GpuSurfacePixelFormat.bgra8_unorm) != 1 or @intFromEnum(platform.GpuSurfacePresentMode.timer) != 1 or @intFromEnum(platform.GpuSurfaceAlphaMode.@"opaque") != 1 or @intFromEnum(platform.GpuSurfaceAlphaMode.premultiplied) != 2 or @intFromEnum(platform.GpuSurfaceColorSpace.srgb) != 1) @compileError("update shell admission wire constants");
|
|
13
|
+
}
|
|
14
|
+
pub const Program = struct {
|
|
15
|
+
status: u32,
|
|
16
|
+
state: u32,
|
|
17
|
+
pub fn admit(self: Program) !void {
|
|
18
|
+
switch (self.status) {
|
|
19
|
+
0 => {},
|
|
20
|
+
1 => return error.InvalidName,
|
|
21
|
+
2 => return error.InvalidLayout,
|
|
22
|
+
3 => return error.DuplicateView,
|
|
23
|
+
4 => return error.DuplicateWindow,
|
|
24
|
+
5 => return error.InvalidDimension,
|
|
25
|
+
6 => return error.InvalidCommand,
|
|
26
|
+
7 => return error.DuplicateCommand,
|
|
27
|
+
8 => return error.InvalidUrl,
|
|
28
|
+
9 => return error.MissingRequiredField,
|
|
29
|
+
10 => return error.InvalidViewKind,
|
|
30
|
+
11 => return error.InvalidViewOptions,
|
|
31
|
+
12 => return error.ViewLabelTooLarge,
|
|
32
|
+
13 => return error.ViewRoleTooLarge,
|
|
33
|
+
14 => return error.ViewAccessibilityLabelTooLarge,
|
|
34
|
+
15 => return error.ViewTextTooLarge,
|
|
35
|
+
16 => return error.UnsupportedViewKind,
|
|
36
|
+
17 => return error.InvalidWindowOptions,
|
|
37
|
+
18 => return error.InvalidWebViewOptions,
|
|
38
|
+
19 => return error.WebViewLabelTooLarge,
|
|
39
|
+
20 => return error.ReservedWebViewLabel,
|
|
40
|
+
else => unreachable,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
pub const put = comparison.put;
|
|
45
|
+
fn wide(bytes: []u8, at: usize, value: usize) void {
|
|
46
|
+
std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
|
|
47
|
+
}
|
|
48
|
+
fn scalar(bytes: []u8, at: usize, value: f32) void {
|
|
49
|
+
put(bytes, at, @bitCast(value));
|
|
50
|
+
}
|
|
51
|
+
pub fn request(mode: Mode) [64]u8 {
|
|
52
|
+
var bytes: [64]u8 = @splat(0);
|
|
53
|
+
bytes[0..3].* = .{ 85, 1, @intFromEnum(mode) };
|
|
54
|
+
return bytes;
|
|
55
|
+
}
|
|
56
|
+
pub fn plan(policy: Policy, bytes: []const u8) Program {
|
|
57
|
+
var output: [16]u8 = @splat(0xa5);
|
|
58
|
+
if (policy(bytes, &output) != output.len or std.mem.readInt(u32, output[0..4], .little) != 1 or std.mem.readInt(u32, output[4..8], .little) != bytes[2]) @panic("invalid compiled shell admission header");
|
|
59
|
+
const program = Program{ .status = std.mem.readInt(u32, output[8..12], .little), .state = std.mem.readInt(u32, output[12..16], .little) };
|
|
60
|
+
if (program.status > 20 or program.state > 15 or (bytes[2] != @intFromEnum(Mode.field) and program.state != 0)) @panic("invalid compiled shell admission result");
|
|
61
|
+
return program;
|
|
62
|
+
}
|
|
63
|
+
fn field(policy: Policy, kind: Field, value: []const u8) u32 {
|
|
64
|
+
var bytes: [320]u8 = @splat(0);
|
|
65
|
+
bytes[0..64].* = request(.field);
|
|
66
|
+
put(&bytes, 4, @intFromEnum(kind));
|
|
67
|
+
wide(&bytes, 16, value.len);
|
|
68
|
+
@memcpy(bytes[48..][0..@min(value.len, 8)], value[0..@min(value.len, 8)]);
|
|
69
|
+
var at: usize = 0;
|
|
70
|
+
while (true) {
|
|
71
|
+
const count: usize = @min(value.len - at, 256);
|
|
72
|
+
wide(&bytes, 24, at);
|
|
73
|
+
put(&bytes, 32, @intCast(count));
|
|
74
|
+
put(&bytes, 36, @intFromBool(at + count == value.len));
|
|
75
|
+
@memcpy(bytes[64..][0..count], value[at..][0..count]);
|
|
76
|
+
const program = plan(policy, bytes[0 .. 64 + count]);
|
|
77
|
+
if (at + count == value.len) return program.status;
|
|
78
|
+
put(&bytes, 12, program.state);
|
|
79
|
+
at += count;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
fn optionalField(policy: Policy, kind: Field, value: ?[]const u8) u32 {
|
|
83
|
+
return if (value) |bytes| field(policy, kind, bytes) else 0;
|
|
84
|
+
}
|
|
85
|
+
fn capacity(policy: Policy, mode: Mode, count: usize) !void {
|
|
86
|
+
var bytes = request(mode);
|
|
87
|
+
wide(&bytes, 16, count);
|
|
88
|
+
try plan(policy, &bytes).admit();
|
|
89
|
+
}
|
|
90
|
+
pub fn scene(policy: Policy, shell: manifest.ShellConfig, compatibility: []const manifest.Window) !void {
|
|
91
|
+
try capacity(policy, .scene, shell.windows.len);
|
|
92
|
+
for (shell.windows, 0..) |window, index| {
|
|
93
|
+
var bytes = request(.window);
|
|
94
|
+
put(&bytes, 4, field(policy, .name, window.label));
|
|
95
|
+
put(&bytes, 8, optionalField(policy, .name, window.title));
|
|
96
|
+
wide(&bytes, 16, window.views.len);
|
|
97
|
+
scalar(&bytes, 32, window.width);
|
|
98
|
+
scalar(&bytes, 36, window.height);
|
|
99
|
+
try plan(policy, &bytes).admit();
|
|
100
|
+
try views(policy, window.views);
|
|
101
|
+
var duplicate = false;
|
|
102
|
+
for (compatibility) |prior| if (comparison.equal(policy, prior.label, window.label)) {
|
|
103
|
+
duplicate = true;
|
|
104
|
+
};
|
|
105
|
+
for (shell.windows[0..index]) |prior| if (comparison.equal(policy, prior.label, window.label)) {
|
|
106
|
+
duplicate = true;
|
|
107
|
+
};
|
|
108
|
+
bytes = request(.duplicate_window);
|
|
109
|
+
put(&bytes, 4, @intFromBool(duplicate));
|
|
110
|
+
try plan(policy, &bytes).admit();
|
|
111
|
+
}
|
|
112
|
+
try chrome(policy, shell.chrome);
|
|
113
|
+
}
|
|
114
|
+
fn views(policy: Policy, descriptors: []const manifest.ShellView) !void {
|
|
115
|
+
var graph: [64 + 128 * 4]u8 = @splat(0);
|
|
116
|
+
graph[0..64].* = request(.hierarchy);
|
|
117
|
+
wide(&graph, 16, descriptors.len);
|
|
118
|
+
for (descriptors, 0..) |view, index| {
|
|
119
|
+
var bytes: [160]u8 = @splat(0);
|
|
120
|
+
bytes[0..64].* = request(.view);
|
|
121
|
+
put(&bytes, 16, field(policy, .view_label, view.label));
|
|
122
|
+
var duplicate = false;
|
|
123
|
+
for (descriptors[0..index]) |prior| if (comparison.equal(policy, prior.label, view.label)) {
|
|
124
|
+
duplicate = true;
|
|
125
|
+
};
|
|
126
|
+
put(&bytes, 8, @intFromBool(duplicate));
|
|
127
|
+
var flags: u32 = 0;
|
|
128
|
+
var parent_slot: u32 = std.math.maxInt(u32);
|
|
129
|
+
if (view.parent) |parent| {
|
|
130
|
+
flags |= 64;
|
|
131
|
+
put(&bytes, 20, field(policy, .name, parent));
|
|
132
|
+
for (descriptors, 0..) |candidate, slot| {
|
|
133
|
+
if (comparison.equal(policy, candidate.label, parent)) {
|
|
134
|
+
parent_slot = @intCast(slot);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
put(&bytes, 12, parent_slot);
|
|
140
|
+
put(&graph, 64 + index * 4, parent_slot);
|
|
141
|
+
for ([_]?f32{ view.width, view.height, view.min_width, view.min_height, view.max_width, view.max_height }, 0..) |value, slot| if (value) |number| {
|
|
142
|
+
flags |= @as(u32, 1) << @intCast(slot);
|
|
143
|
+
scalar(&bytes, 48 + slot * 4, number);
|
|
144
|
+
};
|
|
145
|
+
for ([_]u32{ optionalField(policy, .role, view.role), optionalField(policy, .accessibility, view.accessibility_label), optionalField(policy, .text, view.text), optionalField(policy, .command, view.command), optionalField(policy, .url, view.url) }, 0..) |status, slot| put(&bytes, 24 + slot * 4, status);
|
|
146
|
+
if (view.url != null) flags |= 128;
|
|
147
|
+
put(&bytes, 4, flags);
|
|
148
|
+
put(&bytes, 80, @intFromEnum(view.kind));
|
|
149
|
+
put(&bytes, 84, @as(u32, @intFromBool(view.gpu_backend != null)) | (@as(u32, @intFromBool(view.gpu_pixel_format != null)) << 1) | (@as(u32, @intFromBool(view.gpu_present_mode != null)) << 2) | (@as(u32, @intFromBool(view.gpu_alpha_mode != null)) << 3) | (@as(u32, @intFromBool(view.gpu_color_space != null)) << 4) | (@as(u32, @intFromBool(view.gpu_vsync != null)) << 5));
|
|
150
|
+
put(&bytes, 88, @intCast(index));
|
|
151
|
+
try plan(policy, &bytes).admit();
|
|
152
|
+
}
|
|
153
|
+
try plan(policy, graph[0 .. 64 + descriptors.len * 4]).admit();
|
|
154
|
+
}
|
|
155
|
+
fn chromeItem(policy: Policy, id: []const u8, caption: []const u8, icon: []const u8, duplicate: bool) !void {
|
|
156
|
+
var bytes = request(.chrome_item);
|
|
157
|
+
put(&bytes, 4, @intFromBool(duplicate));
|
|
158
|
+
put(&bytes, 16, field(policy, .command, id));
|
|
159
|
+
put(&bytes, 20, field(policy, .chrome_label, caption));
|
|
160
|
+
put(&bytes, 24, field(policy, .chrome_icon, icon));
|
|
161
|
+
try plan(policy, &bytes).admit();
|
|
162
|
+
}
|
|
163
|
+
fn chrome(policy: Policy, value: manifest.ShellChrome) !void {
|
|
164
|
+
try capacity(policy, .chrome, value.tabs.len);
|
|
165
|
+
for (value.tabs, 0..) |tab, index| {
|
|
166
|
+
var duplicate = false;
|
|
167
|
+
for (value.tabs[0..index]) |prior| if (comparison.equal(policy, prior.id, tab.id)) {
|
|
168
|
+
duplicate = true;
|
|
169
|
+
};
|
|
170
|
+
try chromeItem(policy, tab.id, tab.label, tab.icon, duplicate);
|
|
171
|
+
}
|
|
172
|
+
if (value.primary_action) |action| {
|
|
173
|
+
var duplicate = false;
|
|
174
|
+
for (value.tabs) |tab| if (comparison.equal(policy, tab.id, action.id)) {
|
|
175
|
+
duplicate = true;
|
|
176
|
+
};
|
|
177
|
+
try chromeItem(policy, action.id, action.label, action.icon, duplicate);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
pub fn label(policy: ?Policy, category: u32, value: []const u8) !void {
|
|
181
|
+
const compiled = policy orelse return switch (category) {
|
|
182
|
+
0 => reference.validateViewLabel(value),
|
|
183
|
+
1 => reference.validateWebViewLabel(value),
|
|
184
|
+
2 => reference.validateChildWebViewLabel(value),
|
|
185
|
+
else => unreachable,
|
|
186
|
+
};
|
|
187
|
+
var bytes = request(.label);
|
|
188
|
+
put(&bytes, 4, category);
|
|
189
|
+
wide(&bytes, 16, value.len);
|
|
190
|
+
@memcpy(bytes[40..][0..@min(value.len, 4)], value[0..@min(value.len, 4)]);
|
|
191
|
+
try plan(compiled, &bytes).admit();
|
|
192
|
+
}
|
|
193
|
+
pub fn frame(policy: ?Policy, category: u32, value: geometry.RectF) !void {
|
|
194
|
+
const compiled = policy orelse return switch (category) {
|
|
195
|
+
0 => reference.validateViewFrame(value),
|
|
196
|
+
1 => reference.validateWindowFrame(value),
|
|
197
|
+
2 => if (!reference.isValidWebViewFrame(value)) error.InvalidWebViewOptions else {},
|
|
198
|
+
else => unreachable,
|
|
199
|
+
};
|
|
200
|
+
var bytes = request(.frame);
|
|
201
|
+
put(&bytes, 4, category);
|
|
202
|
+
for ([_]f32{ value.x, value.y, value.width, value.height }, 0..) |number, i| scalar(&bytes, 16 + i * 4, number);
|
|
203
|
+
try plan(compiled, &bytes).admit();
|
|
204
|
+
}
|
|
205
|
+
pub fn runtimeView(policy: ?Policy, options: platform.ViewOptions) !void {
|
|
206
|
+
const compiled = policy orelse return reference.validateViewOptions(options);
|
|
207
|
+
var bytes: [160]u8 = @splat(0);
|
|
208
|
+
bytes[0..64].* = request(.runtime_view);
|
|
209
|
+
put(&bytes, 4, @intFromEnum(options.kind));
|
|
210
|
+
put(&bytes, 8, @intFromBool(options.parent != null));
|
|
211
|
+
bytes[16..22].* = .{ @intFromEnum(options.gpu_surface.backend), @intFromEnum(options.gpu_surface.pixel_format), @intFromEnum(options.gpu_surface.present_mode), @intFromEnum(options.gpu_surface.alpha_mode), @intFromEnum(options.gpu_surface.color_space), @intFromBool(options.gpu_surface.vsync) };
|
|
212
|
+
for ([_]f32{ options.frame.x, options.frame.y, options.frame.width, options.frame.height }, 0..) |number, i| scalar(&bytes, 32 + i * 4, number);
|
|
213
|
+
for ([_][]const u8{ options.label, options.parent orelse "", options.role, options.accessibility_label, options.text, options.command, options.url }, 0..) |value, i| wide(&bytes, 64 + i * 8, value.len);
|
|
214
|
+
put(&bytes, 120, field(compiled, .runtime_command, options.command));
|
|
215
|
+
try plan(compiled, &bytes).admit();
|
|
216
|
+
}
|
|
217
|
+
pub fn runtimePatch(policy: Policy, value: []const u8, patch: platform.ViewPatch) !void {
|
|
218
|
+
var bytes: [160]u8 = @splat(0);
|
|
219
|
+
bytes[0..64].* = request(.runtime_patch);
|
|
220
|
+
put(&bytes, 8, @intFromBool(patch.frame != null));
|
|
221
|
+
if (patch.frame) |rect| for ([_]f32{ rect.x, rect.y, rect.width, rect.height }, 0..) |number, i| scalar(&bytes, 32 + i * 4, number);
|
|
222
|
+
for ([_][]const u8{ value, "", patch.role orelse "", patch.accessibility_label orelse "", patch.text orelse "", patch.command orelse "", patch.url orelse "" }, 0..) |text, i| wide(&bytes, 64 + i * 8, text.len);
|
|
223
|
+
put(&bytes, 120, field(policy, .runtime_command, patch.command orelse ""));
|
|
224
|
+
try plan(policy, &bytes).admit();
|
|
225
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
//! Copied shell facts; native owns storage, borrowed descriptors and OS calls.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const platform = @import("../platform/root.zig");
|
|
4
|
+
const manifest = @import("app_manifest");
|
|
5
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
6
|
+
comptime {
|
|
7
|
+
if (manifest.max_shell_windows != 16 or manifest.max_shell_views_per_window != 128 or platform.max_windows != 16 or platform.max_views != 32 or platform.max_webviews != 16 or @typeInfo(platform.ViewKind).@"enum".fields.len != 19 or @intFromEnum(platform.ViewKind.webview) != 0 or @intFromEnum(platform.ViewKind.gpu_surface) != 17 or @intFromEnum(platform.ViewKind.progress_indicator) != 18 or @bitSizeOf(platform.WindowId) != 64 or @bitSizeOf(usize) > 64) @compileError("update shell coordination wire capacities");
|
|
8
|
+
}
|
|
9
|
+
pub const Mode = enum(u8) { scene, equal, apply, rollback, restore, bind, admission, presentation };
|
|
10
|
+
pub const Program = struct {
|
|
11
|
+
status: u32,
|
|
12
|
+
decisions: u32,
|
|
13
|
+
selected: ?usize,
|
|
14
|
+
count: usize,
|
|
15
|
+
choices: [16]u32 = @splat(0),
|
|
16
|
+
pub fn admit(self: Program) !void {
|
|
17
|
+
switch (self.status) {
|
|
18
|
+
0 => {},
|
|
19
|
+
1 => return error.WindowLimitReached,
|
|
20
|
+
2 => return error.DuplicateViewLabel,
|
|
21
|
+
3 => return error.ViewLimitReached,
|
|
22
|
+
4 => return error.WebViewLimitReached,
|
|
23
|
+
else => unreachable,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
pub fn put(bytes: []u8, at: usize, value: u32) void {
|
|
28
|
+
std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
|
|
29
|
+
}
|
|
30
|
+
fn word(bytes: []const u8, at: usize) u32 {
|
|
31
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
32
|
+
}
|
|
33
|
+
pub fn request(mode: Mode, facts: u32, count: u32, cursor: u32) [64]u8 {
|
|
34
|
+
var bytes: [64]u8 = @splat(0);
|
|
35
|
+
bytes[0..3].* = .{ 84, 1, @intFromEnum(mode) };
|
|
36
|
+
put(&bytes, 4, facts);
|
|
37
|
+
put(&bytes, 8, count);
|
|
38
|
+
put(&bytes, 12, cursor);
|
|
39
|
+
return bytes;
|
|
40
|
+
}
|
|
41
|
+
pub fn plan(policy: Policy, bytes: []const u8) Program {
|
|
42
|
+
const mode = std.enums.fromInt(Mode, bytes[2]) orelse @panic("invalid shell mode");
|
|
43
|
+
var output: [88]u8 = @splat(0xa5);
|
|
44
|
+
const length = policy(bytes, &output);
|
|
45
|
+
if (length < 24 or length > output.len or word(&output, 0) != 1 or word(&output, 4) != @intFromEnum(mode)) @panic("invalid compiled shell coordination header");
|
|
46
|
+
var p = Program{ .status = word(&output, 8), .decisions = word(&output, 12), .selected = if (word(&output, 16) == std.math.maxInt(u32)) null else word(&output, 16), .count = word(&output, 20) };
|
|
47
|
+
const allowed: u32 = switch (mode) {
|
|
48
|
+
.scene, .equal, .bind => 1,
|
|
49
|
+
.apply => 15,
|
|
50
|
+
.restore => 3,
|
|
51
|
+
.rollback, .admission => 0,
|
|
52
|
+
.presentation => 15,
|
|
53
|
+
};
|
|
54
|
+
if (mode == .admission) {
|
|
55
|
+
if (p.decisions > 2 or (p.status != 0 and p.status < 2) or p.status > 4) @panic("invalid shell admission result");
|
|
56
|
+
} else if (p.decisions & ~allowed != 0 or p.status > @as(u32, if (mode == .bind) 1 else 0)) @panic("invalid shell decisions");
|
|
57
|
+
if (p.count > 16 or length != 24 + p.count * 4 or (mode == .scene and p.count != word(bytes, 8)) or (mode != .scene and p.count != 0)) @panic("invalid shell choices");
|
|
58
|
+
for (p.choices[0..p.count], 0..) |*choice, i| {
|
|
59
|
+
choice.* = word(&output, 24 + i * 4);
|
|
60
|
+
if (choice.* > 127 or choice.* & 3 == 3) @panic("invalid shell window choice");
|
|
61
|
+
}
|
|
62
|
+
if (mode == .bind and (p.status == 1 and (p.selected != null or p.decisions != 0 or word(bytes, 8) != 16) or p.status == 0 and p.decisions == 0 and p.selected != null and p.selected.? >= word(bytes, 8))) @panic("invalid shell binding disposition");
|
|
63
|
+
if (p.selected) |slot| {
|
|
64
|
+
if (mode == .rollback) {
|
|
65
|
+
if (slot >= word(bytes, 8) or slot + 1 != word(bytes, 12)) @panic("invalid shell rollback slot");
|
|
66
|
+
} else if (mode == .bind) {
|
|
67
|
+
if (slot >= 16 or slot > word(bytes, 8) or (p.decisions != 0 and slot != word(bytes, 8))) @panic("invalid shell binding slot");
|
|
68
|
+
} else @panic("unexpected shell selection");
|
|
69
|
+
} else if (mode == .rollback and word(bytes, 12) != 0 or mode == .bind and p.status == 0) @panic("missing shell selection");
|
|
70
|
+
return p;
|
|
71
|
+
}
|
|
72
|
+
/// Exact opaque-byte comparison, including oversized invalid labels. Bounded
|
|
73
|
+
/// chunks preserve equality without truncating labels into stored identities.
|
|
74
|
+
pub fn equal(policy: Policy, left: []const u8, right: []const u8) bool {
|
|
75
|
+
var bytes = request(.equal, @intFromBool(left.len == right.len), 0, 0);
|
|
76
|
+
if (plan(policy, &bytes).decisions == 0) return false;
|
|
77
|
+
var at: usize = 0;
|
|
78
|
+
while (at < left.len) {
|
|
79
|
+
const n = @min(16, left.len - at);
|
|
80
|
+
bytes = request(.equal, 1, @intCast(n), 0);
|
|
81
|
+
@memcpy(bytes[16..][0..n], left[at..][0..n]);
|
|
82
|
+
@memcpy(bytes[32..][0..n], right[at..][0..n]);
|
|
83
|
+
if (plan(policy, &bytes).decisions == 0) return false;
|
|
84
|
+
at += n;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
/// Stream current borrowed descriptors in bounded chunks. Source callbacks may
|
|
89
|
+
/// replace a previously validated view slice; creation retains its own gate.
|
|
90
|
+
pub fn scene(policy: Policy, windows: []const manifest.ShellWindow, empty_source: bool) Program {
|
|
91
|
+
if (windows.len > 16) @panic("shell scene capacity");
|
|
92
|
+
var result = Program{ .status = 0, .decisions = 0, .selected = null, .count = windows.len };
|
|
93
|
+
var bytes: [64 + 4 + 128 * 13]u8 = @splat(0);
|
|
94
|
+
for (windows, 0..) |window, index| {
|
|
95
|
+
var at: usize = 0;
|
|
96
|
+
var observations: u32 = 0;
|
|
97
|
+
while (true) {
|
|
98
|
+
const count: usize = @min(window.views.len - at, 128);
|
|
99
|
+
bytes[0..64].* = request(.scene, @intFromBool(empty_source), 1, observations);
|
|
100
|
+
bytes[64] = @intFromBool(window.initially_hidden);
|
|
101
|
+
bytes[65] = @intFromBool(window.x != null or window.y != null);
|
|
102
|
+
std.mem.writeInt(u16, bytes[66..68], @intCast(count), .little);
|
|
103
|
+
for (window.views[at..][0..count], 0..) |view, i| {
|
|
104
|
+
const slot = 68 + i * 13;
|
|
105
|
+
bytes[slot] = @intFromEnum(view.kind);
|
|
106
|
+
std.mem.writeInt(u64, bytes[slot + 1 ..][0..8], view.label.len, .little);
|
|
107
|
+
@memset(bytes[slot + 9 ..][0..4], 0);
|
|
108
|
+
@memcpy(bytes[slot + 9 ..][0..@min(view.label.len, 4)], view.label[0..@min(view.label.len, 4)]);
|
|
109
|
+
}
|
|
110
|
+
const chunk = plan(policy, bytes[0 .. 68 + count * 13]);
|
|
111
|
+
observations = chunk.choices[0] >> 4;
|
|
112
|
+
result.choices[index] = chunk.choices[0] & 15;
|
|
113
|
+
result.decisions |= chunk.decisions;
|
|
114
|
+
at += count;
|
|
115
|
+
if (at == window.views.len) break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
pub fn presentation(policy: Policy, window: manifest.ShellWindow) struct { show: platform.WindowShowMode, placement: platform.WindowInitialPlacement } {
|
|
121
|
+
var bytes: [192]u8 = @splat(0);
|
|
122
|
+
var at: usize = 0;
|
|
123
|
+
var result: u32 = 0;
|
|
124
|
+
while (true) {
|
|
125
|
+
const count: usize = @min(window.views.len - at, 128);
|
|
126
|
+
bytes[0..64].* = request(.presentation, @as(u32, @intFromBool(window.initially_hidden)) | (@as(u32, @intFromBool(window.x != null or window.y != null)) << 2), @intCast(count), @intFromBool(result & 8 != 0));
|
|
127
|
+
for (window.views[at..][0..count], 0..) |view, i| bytes[64 + i] = @intFromEnum(view.kind);
|
|
128
|
+
result = plan(policy, bytes[0 .. 64 + count]).decisions;
|
|
129
|
+
at += count;
|
|
130
|
+
if (at == window.views.len) break;
|
|
131
|
+
}
|
|
132
|
+
return .{ .placement = if (result & 4 != 0) .explicit else .default, .show = switch (result & 3) {
|
|
133
|
+
0 => .immediate,
|
|
134
|
+
1 => .hidden,
|
|
135
|
+
2 => .on_first_present,
|
|
136
|
+
else => unreachable,
|
|
137
|
+
} };
|
|
138
|
+
}
|
|
@@ -21,6 +21,13 @@ pub const RuntimeShellLayout = struct {
|
|
|
21
21
|
return self.views[0..self.view_count];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
pub fn rebindStorage(self: *RuntimeShellLayout) void {
|
|
25
|
+
for (self.views[0..self.view_count], 0..) |*view, index| {
|
|
26
|
+
view.label = self.label_storage[index][0..view.label.len];
|
|
27
|
+
if (view.parent) |parent| view.parent = self.parent_storage[index][0..parent.len];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
pub fn copyViews(self: *RuntimeShellLayout, source: []const app_manifest.ShellView) !void {
|
|
25
32
|
if (source.len > self.views.len) return error.ViewLimitReached;
|
|
26
33
|
for (source, 0..) |view, index| {
|
|
@@ -275,12 +282,16 @@ pub fn shellViewOptions(window_id: platform.WindowId, view: app_manifest.ShellVi
|
|
|
275
282
|
const frame = try layout.frameFor(view);
|
|
276
283
|
const resolved = layout.findView(view.label) orelse return error.InvalidViewOptions;
|
|
277
284
|
const platform_frame = if (view.kind == .webview and view.parent != null and validation.isMainWebViewLabel(view.label)) resolved.absolute_frame else frame;
|
|
285
|
+
return shellViewOptionsWithFrame(window_id, view, platform_frame);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
pub fn shellViewOptionsWithFrame(window_id: platform.WindowId, view: app_manifest.ShellView, frame: geometry.RectF) platform.ViewOptions {
|
|
278
289
|
return .{
|
|
279
290
|
.window_id = window_id,
|
|
280
291
|
.label = view.label,
|
|
281
292
|
.kind = shellViewKind(view.kind),
|
|
282
293
|
.parent = view.parent,
|
|
283
|
-
.frame =
|
|
294
|
+
.frame = frame,
|
|
284
295
|
.layer = view.layer,
|
|
285
296
|
.visible = view.visible,
|
|
286
297
|
.enabled = view.enabled,
|
|
@@ -492,3 +503,117 @@ pub fn combinedViewportInsets(surface: platform.Surface) geometry.InsetsF {
|
|
|
492
503
|
.left = @max(surface.safe_area_insets.left, surface.keyboard_insets.left),
|
|
493
504
|
};
|
|
494
505
|
}
|
|
506
|
+
|
|
507
|
+
pub const ShellPlanItem = struct {
|
|
508
|
+
index: usize,
|
|
509
|
+
frame: geometry.RectF,
|
|
510
|
+
absolute_frame: geometry.RectF,
|
|
511
|
+
platform_frame: geometry.RectF,
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
pub const ShellPlan = struct {
|
|
515
|
+
items: [app_manifest.max_shell_views_per_window]ShellPlanItem = undefined,
|
|
516
|
+
count: usize = 0,
|
|
517
|
+
invalid_parents: bool = false,
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/// Encode exact native geometry and label bytes; copy the complete bounded
|
|
521
|
+
/// result before executing any OS calls. No reset is allowed here: model or
|
|
522
|
+
/// helper slices may still be borrowed by the installing/rebuilding cycle.
|
|
523
|
+
pub fn compiledShellPlan(policy: *const fn ([]const u8, []u8) usize, bounds: geometry.RectF, views: []const app_manifest.ShellView) ShellPlan {
|
|
524
|
+
if (views.len > app_manifest.max_shell_views_per_window) @panic("invalid shell declaration count");
|
|
525
|
+
var request: [19 + app_manifest.max_shell_views_per_window * (41 + 2 * app_manifest.max_view_label_bytes)]u8 = undefined;
|
|
526
|
+
const length = encodeShellPlanRequest(&request, bounds, views);
|
|
527
|
+
var output: [3 + app_manifest.max_shell_views_per_window * 50]u8 = undefined;
|
|
528
|
+
const result_length = policy(request[0..length], &output);
|
|
529
|
+
if (result_length < 3 or result_length > output.len or output[0] > 1) @panic("invalid compiled shell plan");
|
|
530
|
+
const count = std.mem.readInt(u16, output[1..3], .little);
|
|
531
|
+
if (count > views.len or result_length != 3 + @as(usize, count) * 50 or (output[0] == 0 and count != views.len)) @panic("invalid compiled shell plan count");
|
|
532
|
+
var plan = ShellPlan{ .count = count, .invalid_parents = output[0] == 1 };
|
|
533
|
+
var seen = [_]bool{false} ** app_manifest.max_shell_views_per_window;
|
|
534
|
+
for (plan.items[0..count], 0..) |*item, i| {
|
|
535
|
+
const at = 3 + i * 50;
|
|
536
|
+
const index = std.mem.readInt(u16, output[at..][0..2], .little);
|
|
537
|
+
if (index >= views.len or seen[index]) @panic("invalid compiled shell plan index");
|
|
538
|
+
seen[index] = true;
|
|
539
|
+
item.* = .{
|
|
540
|
+
.index = index,
|
|
541
|
+
.frame = shellReadRect(output[at + 2 ..][0..16]),
|
|
542
|
+
.absolute_frame = shellReadRect(output[at + 18 ..][0..16]),
|
|
543
|
+
.platform_frame = shellReadRect(output[at + 34 ..][0..16]),
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
return plan;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
pub fn encodeShellPlanRequest(output: []u8, bounds: geometry.RectF, views: []const app_manifest.ShellView) usize {
|
|
550
|
+
var writer = std.Io.Writer.fixed(output);
|
|
551
|
+
writer.writeByte(2) catch @panic("shell request capacity");
|
|
552
|
+
writer.writeInt(u16, @intCast(views.len), .little) catch @panic("shell request capacity");
|
|
553
|
+
for ([_]f32{ bounds.x, bounds.y, bounds.width, bounds.height }) |value| shellWriteFloat(&writer, value);
|
|
554
|
+
for (views) |view| {
|
|
555
|
+
const values = [_]?f32{ view.x, view.y, view.width, view.height, view.min_width, view.min_height, view.max_width, view.max_height };
|
|
556
|
+
var mask: u8 = 0;
|
|
557
|
+
for (values, 0..) |value, field| if (value != null) {
|
|
558
|
+
mask |= @as(u8, 1) << @intCast(field);
|
|
559
|
+
};
|
|
560
|
+
writer.writeAll(&.{ @intFromEnum(view.kind), if (view.edge) |edge| @intFromEnum(edge) else 255, @intFromEnum(view.axis orelse .row), @intFromBool(view.fill), mask }) catch @panic("shell request capacity");
|
|
561
|
+
for (values) |value| shellWriteFloat(&writer, value orelse 0);
|
|
562
|
+
shellWriteLabel(&writer, view.label);
|
|
563
|
+
if (view.parent) |parent| shellWriteLabel(&writer, parent) else writer.writeInt(u16, 65535, .little) catch @panic("shell request capacity");
|
|
564
|
+
}
|
|
565
|
+
return writer.buffered().len;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
fn shellWriteLabel(writer: *std.Io.Writer, label: []const u8) void {
|
|
569
|
+
if (label.len > app_manifest.max_view_label_bytes) @panic("invalid shell label length");
|
|
570
|
+
writer.writeInt(u16, @intCast(label.len), .little) catch @panic("shell request capacity");
|
|
571
|
+
writer.writeAll(label) catch @panic("shell request capacity");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
fn shellWriteFloat(writer: *std.Io.Writer, value: f32) void {
|
|
575
|
+
writer.writeInt(u32, @bitCast(value), .little) catch @panic("shell request capacity");
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
fn shellReadRect(bytes: *const [16]u8) geometry.RectF {
|
|
579
|
+
return .{
|
|
580
|
+
.x = @bitCast(std.mem.readInt(u32, bytes[0..4], .little)),
|
|
581
|
+
.y = @bitCast(std.mem.readInt(u32, bytes[4..8], .little)),
|
|
582
|
+
.width = @bitCast(std.mem.readInt(u32, bytes[8..12], .little)),
|
|
583
|
+
.height = @bitCast(std.mem.readInt(u32, bytes[12..16], .little)),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/// Test oracle using the original native stateful layout and traversal.
|
|
588
|
+
/// Production native apps apply each view as they resolve it above the OS seam.
|
|
589
|
+
pub fn referenceShellPlan(bounds: geometry.RectF, views: []const app_manifest.ShellView) ShellPlan {
|
|
590
|
+
var layout = ShellLayout.init(bounds, views);
|
|
591
|
+
var created = [_]bool{false} ** app_manifest.max_shell_views_per_window;
|
|
592
|
+
var plan: ShellPlan = .{};
|
|
593
|
+
while (plan.count < views.len) {
|
|
594
|
+
var progressed = false;
|
|
595
|
+
for (views, 0..) |view, index| {
|
|
596
|
+
if (created[index]) continue;
|
|
597
|
+
if (view.parent) |parent| if (!layout.containsView(parent)) continue;
|
|
598
|
+
const frame = layout.frameFor(view) catch {
|
|
599
|
+
plan.invalid_parents = true;
|
|
600
|
+
return plan;
|
|
601
|
+
};
|
|
602
|
+
const first = layout.findView(view.label).?;
|
|
603
|
+
plan.items[plan.count] = .{
|
|
604
|
+
.index = index,
|
|
605
|
+
.frame = frame,
|
|
606
|
+
.absolute_frame = layout.views[layout.view_count - 1].absolute_frame,
|
|
607
|
+
.platform_frame = if (view.kind == .webview and view.parent != null and validation.isMainWebViewLabel(view.label)) first.absolute_frame else frame,
|
|
608
|
+
};
|
|
609
|
+
plan.count += 1;
|
|
610
|
+
created[index] = true;
|
|
611
|
+
progressed = true;
|
|
612
|
+
}
|
|
613
|
+
if (!progressed) {
|
|
614
|
+
plan.invalid_parents = true;
|
|
615
|
+
return plan;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return plan;
|
|
619
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//! Copied snapshot projection and frame-profile decisions. Native code owns
|
|
2
|
+
//! borrowed storage, allocation and clock/process/GPU observations.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
pub const Policy = ?*const fn ([]const u8, []u8) usize;
|
|
5
|
+
pub const Mode = enum(u8) { bounded, view, widget, virtual_range, uptime, presence, record, stats, reset, has_samples, elapsed };
|
|
6
|
+
pub const Facts = struct {
|
|
7
|
+
flags: u32 = 0,
|
|
8
|
+
words: [8]u64 = @splat(0),
|
|
9
|
+
floats: [7]f32 = @splat(0),
|
|
10
|
+
samples: []const u32 = &.{},
|
|
11
|
+
};
|
|
12
|
+
pub const Plan = struct {
|
|
13
|
+
flags: u8 = 0,
|
|
14
|
+
words: [8]u64 = @splat(0),
|
|
15
|
+
floats: [7]f32 = @splat(0),
|
|
16
|
+
};
|
|
17
|
+
pub fn plan(policy: Policy, mode: Mode, facts: Facts) Plan {
|
|
18
|
+
const callback = policy orelse return @import("snapshot_reference.zig").plan(mode, facts);
|
|
19
|
+
if (facts.samples.len > 128) @panic("snapshot sample budget exceeded");
|
|
20
|
+
var input: [616]u8 = undefined;
|
|
21
|
+
const input_len = 104 + facts.samples.len * 4;
|
|
22
|
+
@memset(input[0..input_len], 0);
|
|
23
|
+
input[0..4].* = .{ 27, 1, @intFromEnum(mode), 0 };
|
|
24
|
+
std.mem.writeInt(u32, input[4..8], facts.flags, .little);
|
|
25
|
+
for (facts.words, 0..) |word, i| std.mem.writeInt(u64, input[8 + i * 8 ..][0..8], word, .little);
|
|
26
|
+
for (facts.floats, 0..) |value, i| std.mem.writeInt(u32, input[72 + i * 4 ..][0..4], @bitCast(value), .little);
|
|
27
|
+
for (facts.samples, 0..) |value, i| std.mem.writeInt(u32, input[104 + i * 4 ..][0..4], value, .little);
|
|
28
|
+
var output: [104]u8 = undefined;
|
|
29
|
+
if (callback(input[0..input_len], &output) != output.len or !std.mem.allEqual(u8, output[1..8], 0) or !std.mem.allEqual(u8, output[100..104], 0))
|
|
30
|
+
@panic("invalid compiled snapshot response");
|
|
31
|
+
const mask: u8 = switch (mode) {
|
|
32
|
+
.widget => 63,
|
|
33
|
+
.presence => 7,
|
|
34
|
+
else => 1,
|
|
35
|
+
};
|
|
36
|
+
if (output[0] & ~mask != 0) @panic("invalid compiled snapshot flags");
|
|
37
|
+
var result: Plan = .{ .flags = output[0] };
|
|
38
|
+
for (&result.words, 0..) |*word, i| word.* = std.mem.readInt(u64, output[8 + i * 8 ..][0..8], .little);
|
|
39
|
+
for (&result.floats, 0..) |*value, i| value.* = @bitCast(std.mem.readInt(u32, output[72 + i * 4 ..][0..4], .little));
|
|
40
|
+
const used: usize = switch (mode) {
|
|
41
|
+
.bounded, .uptime, .elapsed, .widget => 1,
|
|
42
|
+
.record => 4,
|
|
43
|
+
.stats, .virtual_range => 5,
|
|
44
|
+
else => 0,
|
|
45
|
+
};
|
|
46
|
+
for (result.words[used..]) |word| if (word != 0) @panic("invalid compiled snapshot reserved word");
|
|
47
|
+
if (mode == .widget and !std.mem.allEqual(u8, output[88..100], 0)) @panic("invalid compiled snapshot reserved geometry");
|
|
48
|
+
if (mode != .widget and !std.mem.allEqual(u8, output[72..100], 0)) @panic("invalid compiled snapshot reserved geometry");
|
|
49
|
+
switch (mode) {
|
|
50
|
+
.widget => if (result.flags & 32 != 0 and (result.words[0] >= facts.words[5] or facts.flags & 1024 == 0)) @panic("invalid compiled snapshot parent"),
|
|
51
|
+
.bounded => if (result.words[0] > facts.words[0] or result.words[0] > facts.words[1]) @panic("invalid compiled snapshot capacity"),
|
|
52
|
+
.record => if (result.words[0] > 128 or result.words[1] >= 128 or result.words[3] > std.math.maxInt(u32)) @panic("invalid compiled profile ring"),
|
|
53
|
+
.stats => if (result.words[0] > 128 or result.words[2] > result.words[3] or result.words[3] > result.words[4] or result.words[4] > std.math.maxInt(u32)) @panic("invalid compiled profile statistics"),
|
|
54
|
+
.virtual_range => for (result.words[0..5]) |word| {
|
|
55
|
+
if (word > std.math.maxInt(u32)) @panic("invalid compiled snapshot range");
|
|
56
|
+
},
|
|
57
|
+
else => {},
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//! Independent native reference for explicitly selected Zig-core apps.
|
|
2
|
+
const std = @import("std");
|
|
3
|
+
const p = @import("snapshot_policy.zig");
|
|
4
|
+
pub fn plan(mode: p.Mode, facts: p.Facts) p.Plan {
|
|
5
|
+
const w = facts.words;
|
|
6
|
+
const f = facts.floats;
|
|
7
|
+
const flags = facts.flags;
|
|
8
|
+
var result: p.Plan = .{};
|
|
9
|
+
switch (mode) {
|
|
10
|
+
.bounded => {
|
|
11
|
+
if (flags == 1) result.words[0] = @min(w[0], w[1]);
|
|
12
|
+
result.flags = @intFromBool(w[0] == 0 or w[1] == 0 or flags == 0);
|
|
13
|
+
},
|
|
14
|
+
.view => result.flags = @intFromBool(flags == 3 and w[0] == w[1]),
|
|
15
|
+
.widget => {
|
|
16
|
+
const selected = flags & 1 != 0 or (flags & 2 != 0 and !(f[0] < 0.5) and (w[6] == 12 or w[6] == 15 or w[6] == 16 or w[6] == 17 or w[6] == 18 or w[6] == 20));
|
|
17
|
+
result.flags = @intFromBool(selected);
|
|
18
|
+
if (flags & 8 != 0 or (flags & 16 != 0 and flags & 32 != 0 and w[0] == w[1])) result.flags |= 2;
|
|
19
|
+
if (flags & 64 == 0) result.flags |= 4;
|
|
20
|
+
if (flags & 128 != 0 or (w[0] != 0 and w[0] == w[2])) result.flags |= 8;
|
|
21
|
+
if (flags & 256 != 0 or (w[0] != 0 and w[0] == w[3])) result.flags |= 16;
|
|
22
|
+
if (flags & 1024 != 0 and w[4] < w[5]) {
|
|
23
|
+
result.flags |= 32;
|
|
24
|
+
result.words[0] = w[4];
|
|
25
|
+
}
|
|
26
|
+
result.floats[0..4].* = .{ f[1] + f[5], f[2] + f[6], f[3], f[4] };
|
|
27
|
+
},
|
|
28
|
+
.virtual_range => if (flags == 1) {
|
|
29
|
+
result.flags = 1;
|
|
30
|
+
for (0..4) |i| result.words[i] = @min(w[i], std.math.maxInt(u32));
|
|
31
|
+
result.words[4] = @min(w[1] - w[0], std.math.maxInt(u32));
|
|
32
|
+
},
|
|
33
|
+
.uptime => if (w[0] > 0 and w[1] >= w[0]) {
|
|
34
|
+
result.words[0] = w[1] - w[0];
|
|
35
|
+
},
|
|
36
|
+
.elapsed => result.words[0] = w[1] -| w[0],
|
|
37
|
+
.presence => result.flags = @intCast(flags),
|
|
38
|
+
.record => {
|
|
39
|
+
result.words[0..3].* = .{ w[1], w[2], w[3] };
|
|
40
|
+
if (flags == 1) {
|
|
41
|
+
result.flags = 1;
|
|
42
|
+
result.words[0] = @min(w[1] + 1, 128);
|
|
43
|
+
result.words[1] = (w[2] + 1) % 128;
|
|
44
|
+
result.words[2] = w[3] +% 1;
|
|
45
|
+
result.words[3] = @min(w[0] / 1000, std.math.maxInt(u32));
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
.stats => {
|
|
49
|
+
const len: usize = @intCast(w[0]);
|
|
50
|
+
result.words[0..2].* = .{ w[0], w[1] };
|
|
51
|
+
if (len > 0) {
|
|
52
|
+
var sorted: [128]u32 = undefined;
|
|
53
|
+
@memcpy(sorted[0..len], facts.samples[0..len]);
|
|
54
|
+
std.sort.pdq(u32, sorted[0..len], {}, std.sort.asc(u32));
|
|
55
|
+
result.words[2..5].* = .{ sorted[@max((len * 50 + 99) / 100, 1) - 1], sorted[@max((len * 90 + 99) / 100, 1) - 1], sorted[len - 1] };
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
.reset => {},
|
|
59
|
+
.has_samples => for (facts.samples) |sample| {
|
|
60
|
+
if (sample != 0) result.flags = 1;
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|