@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,166 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { test } from "node:test";
|
|
8
|
+
import { aliasPaths, identityPlan, metadataIdentity, outputBegin, outputStep, pathBegin, pathComponent, pathObserved, stagingPath } from "./filesystem_coordination.ts";
|
|
9
|
+
import type { FileOutput, Observation, OutputAction } from "./filesystem_coordination.ts";
|
|
10
|
+
import { textBytes } from "./invocation.ts";
|
|
11
|
+
import { invocationCases } from "./invocation_cases.ts";
|
|
12
|
+
import { invoke } from "./invocation_fixture.ts";
|
|
13
|
+
import { baseContract as coreContract } from "./core_cases.ts";
|
|
14
|
+
import { baseContract as serviceContract } from "./service_cases.ts";
|
|
15
|
+
|
|
16
|
+
const bytes = textBytes;
|
|
17
|
+
const text = (raw: number[]) => Buffer.from(raw).toString("utf8");
|
|
18
|
+
const output = (kind: string, name: string): FileOutput => ({ kind, flag: "--" + kind, path: bytes(name), parent: bytes("."), staged: [] });
|
|
19
|
+
const ok = (): Observation => ({ ok: true, error: [], bytes: [0, 1, 2, 3, 4, 5, 6, 255], identity: false });
|
|
20
|
+
function trace(mode: string, outputs: FileOutput[], observe: (action: OutputAction) => Observation = ok) {
|
|
21
|
+
let state = outputBegin(mode, structuredClone(outputs)), observation = ok();
|
|
22
|
+
const actions: OutputAction[] = [];
|
|
23
|
+
for (let i = 0; i < 200; i++) {
|
|
24
|
+
const step = outputStep(state, observation); state = step.state; actions.push(step.action);
|
|
25
|
+
if (step.action.kind === "done") return { state, actions };
|
|
26
|
+
observation = observe(step.action);
|
|
27
|
+
}
|
|
28
|
+
throw new Error("output coordinator failed to finish");
|
|
29
|
+
}
|
|
30
|
+
test("path traversal resumes canonicalization after a nonexistent tail is popped", () => {
|
|
31
|
+
assert.deepEqual(pathBegin(null, false, null), { state: { base: bytes("."), exists: true }, resolve: false });
|
|
32
|
+
assert.equal(pathBegin(bytes("C:"), false, bytes("unused")).resolve, true);
|
|
33
|
+
let state = pathBegin(bytes("/"), true, null).state;
|
|
34
|
+
assert.deepEqual(pathComponent(state, bytes(".")), { action: "keep", probe: false });
|
|
35
|
+
state = pathObserved(state, "join", bytes("/missing"), null);
|
|
36
|
+
assert.equal(state.exists, false);
|
|
37
|
+
assert.deepEqual(pathComponent(state, bytes("child")), { action: "join", probe: false });
|
|
38
|
+
assert.deepEqual(pathComponent(state, bytes("..")), { action: "parent", probe: true });
|
|
39
|
+
state = pathObserved(state, "parent", bytes("/"), bytes("/real"));
|
|
40
|
+
assert.deepEqual(state, { base: bytes("/real"), exists: true });
|
|
41
|
+
assert.deepEqual(pathComponent(state, bytes("link")), { action: "join", probe: true });
|
|
42
|
+
assert.deepEqual(pathObserved(state, "parent", bytes("/"), null), { base: bytes("/"), exists: true });
|
|
43
|
+
});
|
|
44
|
+
test("identity decisions compare full exact metadata and preserve observation precedence", () => {
|
|
45
|
+
const a = { canonical: bytes("/a/file"), basename: bytes("file"), parent: bytes("/a"), metadata: null };
|
|
46
|
+
assert.deepEqual(identityPlan(a, a), { same: true, stat: false });
|
|
47
|
+
assert.deepEqual(identityPlan(a, { ...a, canonical: bytes("/b/file"), parent: bytes("/b") }), { same: false, stat: true });
|
|
48
|
+
assert.deepEqual(identityPlan(a, { ...a, canonical: null }), { same: false, stat: false });
|
|
49
|
+
assert.deepEqual(identityPlan(a, { ...a, canonical: bytes("/a/other"), basename: bytes("other") }), { same: false, stat: false });
|
|
50
|
+
const values = ["18446744073709551615", "directory", "9007199254740993", "18446744073709551615", "-170141183460469231731687303715884105728", "170141183460469231731687303715884105727"];
|
|
51
|
+
assert.equal(metadataIdentity(values, values.slice()), true);
|
|
52
|
+
for (let i = 0; i < 6; i++) { const changed = values.slice(); changed[i] += "0"; assert.equal(metadataIdentity(values, changed), false); }
|
|
53
|
+
assert.equal(metadataIdentity(null, values), false);
|
|
54
|
+
});
|
|
55
|
+
test("raw staging names preserve every entropy bit and every path byte", () => {
|
|
56
|
+
const raw = [0xff, 0x80, 0, 0x5c];
|
|
57
|
+
const out = stagingPath(raw, [0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xff]);
|
|
58
|
+
assert.deepEqual(out.slice(0, 4), raw);
|
|
59
|
+
assert.equal(text(out.slice(4)), ".corewire-tmp.00123456789abcff");
|
|
60
|
+
assert.deepEqual(aliasPaths([output("out", "a"), output("facade", "b")]).map(text), ["a", "b", "a.corewire-tmp", "b.corewire-tmp"]);
|
|
61
|
+
});
|
|
62
|
+
test("all core outputs stage before any commit, with a fresh alias net at each phase", () => {
|
|
63
|
+
const result = trace("core", [output("mirror", "a"), output("facade", "b")]);
|
|
64
|
+
assert.equal(result.state.exit_code, 0);
|
|
65
|
+
assert.deepEqual(result.actions.map(a => a.kind), ["mkdir", "entropy", "create", "write", "flush", "close", "identity", "mkdir", "entropy", "create", "write", "flush", "close", "rename", "identity", "rename", "done"]);
|
|
66
|
+
});
|
|
67
|
+
for (const failure of ["create", "write", "flush", "rename"]) for (const index of [0, 1]) {
|
|
68
|
+
test(`complete ${failure} failure cleanup at output ${index}`, () => {
|
|
69
|
+
const result = trace("core", [output("mirror", "a"), output("facade", "b")], a => ({ ...ok(), ok: !(a.kind === failure && a.index === index), error: bytes("Denied") }));
|
|
70
|
+
assert.equal(result.state.exit_code, 1);
|
|
71
|
+
const deleted = result.actions.filter(a => a.kind === "delete").map(a => text(a.path));
|
|
72
|
+
const suffix = ".corewire-tmp.00010203040506ff";
|
|
73
|
+
assert.deepEqual(deleted, failure === "rename" ? ["a", "b"].slice(index).map(p => p + suffix)
|
|
74
|
+
: [...(failure === "create" ? [] : [(index ? "b" : "a") + suffix]), ...["a", "b"].slice(0, index).map(p => p + suffix)]);
|
|
75
|
+
const kinds = result.actions.map(a => a.kind);
|
|
76
|
+
if (failure === "write") assert.equal(result.actions.some(a => a.kind === "flush" && a.index === index), false);
|
|
77
|
+
assert.equal(kinds.filter(k => k === "diagnostic").length, 1);
|
|
78
|
+
assert.equal(kinds.at(-1), "done");
|
|
79
|
+
assert.equal(text(result.state.error).includes("earlier projections were already replaced"), failure === "rename" && index === 1);
|
|
80
|
+
if (failure !== "rename" && index === 1) assert.ok(kinds.indexOf("diagnostic") < kinds.lastIndexOf("delete"));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
for (const commit of [false, true]) test(`late identity refusal at ${commit ? "commit" : "staging"} cleans only remaining owned files`, () => {
|
|
84
|
+
let seen = 0;
|
|
85
|
+
const result = trace("core", [output("mirror", "a"), output("facade", "b")], a => ({ ...ok(), identity: a.kind === "identity" && ++seen === (commit ? 2 : 1) }));
|
|
86
|
+
assert.equal(result.state.exit_code, 2);
|
|
87
|
+
assert.deepEqual(result.actions.filter(a => a.kind === "delete").map(a => text(a.path)), [(commit ? "b" : "a") + ".corewire-tmp.00010203040506ff"]);
|
|
88
|
+
assert.equal(text(result.state.error).includes("just wrote"), commit);
|
|
89
|
+
});
|
|
90
|
+
test("service projection remains sequential, including overlapping outputs and a later refusal", () => {
|
|
91
|
+
const outputs = [output("registry", "same"), output("client", "same"), output("inproc_profile", "profile")];
|
|
92
|
+
const result = trace("service", outputs, a => ({ ...ok(), ok: !(a.kind === "service_write" && a.index === 1), error: bytes("Denied") }));
|
|
93
|
+
assert.equal(result.state.exit_code, 1);
|
|
94
|
+
assert.deepEqual(result.actions.map(a => a.kind), ["generate", "service_write", "generate", "service_write", "diagnostic", "done"]);
|
|
95
|
+
assert.deepEqual(result.actions.filter(a => a.kind === "generate").map(a => a.projection), ["registry", "client"]);
|
|
96
|
+
const success = trace("service", outputs);
|
|
97
|
+
assert.deepEqual(success.actions.filter(a => a.kind === "generate").map(a => a.projection), ["registry", "client", "profile"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (process.argv[2] && process.argv[3]) {
|
|
101
|
+
const candidate = path.resolve(process.argv[2]), reference = path.resolve(process.argv[3]);
|
|
102
|
+
for (const item of invocationCases()) test("full native-reference invocation: " + item.name, () => {
|
|
103
|
+
assert.deepEqual(invoke(candidate, item), invoke(reference, item));
|
|
104
|
+
});
|
|
105
|
+
type Scenario = { name: string; args: string[]; setup: (dir: string) => void; malformed?: boolean };
|
|
106
|
+
const scenarios: Scenario[] = [
|
|
107
|
+
{ name: "all core projections with missing parents", args: ["--sidecar", "input.json", "--out", "missing/a", "--facade", "missing/b", "--profile", "missing/c", "--effective-sidecar", "missing/d"], setup: () => {} },
|
|
108
|
+
{ name: "earlier output unchanged after second staging refuses", args: ["--sidecar", "input.json", "--out", "a", "--facade", "blocked/b"], setup: dir => { fs.writeFileSync(path.join(dir, "a"), "retain"); fs.writeFileSync(path.join(dir, "blocked"), "file"); } },
|
|
109
|
+
{ name: "second rename refuses after first commit", args: ["--sidecar", "input.json", "--out", "a", "--facade", "directory"], setup: dir => { fs.writeFileSync(path.join(dir, "a"), "retain"); fs.mkdirSync(path.join(dir, "directory")); } },
|
|
110
|
+
{ name: "first rename refuses and all stages are removed", args: ["--sidecar", "input.json", "--out", "directory", "--facade", "b"], setup: dir => { fs.mkdirSync(path.join(dir, "directory")); fs.writeFileSync(path.join(dir, "b"), "retain"); } },
|
|
111
|
+
{ name: "case folded future spelling alias", args: ["--sidecar", "input.json", "--out", "a", "--facade", "A"], setup: () => {} },
|
|
112
|
+
{ name: "service partial outputs after write failure", args: ["--services-sidecar", "services.json", "--service-registry", "registry", "--service-client", "missing/client"], setup: () => {} },
|
|
113
|
+
{ name: "service sequential overlapping outputs", args: ["--services-sidecar", "services.json", "--service-registry", "same", "--service-client", "same", "--service-inproc-main", "inproc", "--service-inproc-profile", "inproc"], setup: () => {} },
|
|
114
|
+
];
|
|
115
|
+
if (process.platform !== "win32") scenarios.push(
|
|
116
|
+
{ name: "symlink input refusal precedes malformed decode", args: ["--sidecar", "input.json", "--out", "alias"], malformed: true, setup: dir => fs.symlinkSync("input.json", path.join(dir, "alias")) },
|
|
117
|
+
{ name: "dot-dot applies after symlink resolution", args: ["--sidecar", "input.json", "--out", "link/../b"], setup: dir => { fs.mkdirSync(path.join(dir, "real/sub"), { recursive: true }); fs.symlinkSync("real/sub", path.join(dir, "link")); fs.symlinkSync("../input.json", path.join(dir, "real/b")); } },
|
|
118
|
+
{ name: "canonical traversal resumes after nonexistent tail", args: ["--sidecar", "input.json", "--out", "missing/../alias"], malformed: true, setup: dir => fs.symlinkSync("input.json", path.join(dir, "alias")) },
|
|
119
|
+
{ name: "hard link output replaces entry without overwriting input", args: ["--sidecar", "input.json", "--out", "hard"], setup: dir => fs.linkSync(path.join(dir, "input.json"), path.join(dir, "hard")) },
|
|
120
|
+
{ name: "symlink ancestors produce one future output", args: ["--sidecar", "input.json", "--out", "real/new", "--facade", "link/new"], setup: dir => { fs.mkdirSync(path.join(dir, "real")); fs.symlinkSync("real", path.join(dir, "link")); } },
|
|
121
|
+
{ name: "decomposed and composed unicode names retain OS behavior", args: ["--sidecar", "input.json", "--out", "é", "--facade", "e\u0301"], setup: () => {} },
|
|
122
|
+
);
|
|
123
|
+
function outcome(binary: string, scenario: Scenario) {
|
|
124
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "native-filesystem-conformance-"));
|
|
125
|
+
try {
|
|
126
|
+
fs.writeFileSync(path.join(dir, "input.json"), scenario.malformed ? "{" : JSON.stringify(coreContract(), (key, value) => (key === "origin" || key === "member") && value === null ? undefined : value));
|
|
127
|
+
fs.writeFileSync(path.join(dir, "services.json"), JSON.stringify(serviceContract())); scenario.setup(dir);
|
|
128
|
+
const result = spawnSync(binary, scenario.args, { cwd: dir, encoding: "utf8", maxBuffer: 32 * 1024 * 1024 });
|
|
129
|
+
assert.ifError(result.error); assert.equal(result.signal, null, result.stderr);
|
|
130
|
+
const entries: Record<string, string> = {};
|
|
131
|
+
function collect(relative: string) {
|
|
132
|
+
for (const item of fs.readdirSync(path.join(dir, relative), { withFileTypes: true })) {
|
|
133
|
+
const name = relative ? relative + "/" + item.name : item.name, p = path.join(dir, name);
|
|
134
|
+
entries[name] = item.isSymbolicLink() ? "link:" + fs.readlinkSync(p) : item.isDirectory() ? "directory" : createHash("sha256").update(fs.readFileSync(p)).digest("hex");
|
|
135
|
+
if (item.isDirectory()) collect(name);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
collect("");
|
|
139
|
+
return { status: result.status, stdout: result.stdout, diagnostics: result.stderr.replaceAll(fs.realpathSync(dir), ".").replaceAll(dir, ".").replace(/\.corewire-tmp\.[0-9a-f]{16}/g, ".corewire-tmp.NONCE"), entries };
|
|
140
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
141
|
+
}
|
|
142
|
+
for (const scenario of scenarios) test("full filesystem reference: " + scenario.name, () => {
|
|
143
|
+
assert.deepEqual(outcome(candidate, scenario), outcome(reference, scenario));
|
|
144
|
+
});
|
|
145
|
+
if (fs.existsSync("/dev/full")) test("diagnostic write failure still removes every earlier stage", () => {
|
|
146
|
+
function failedDiagnostic(binary: string) {
|
|
147
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "native-filesystem-diagnostic-"));
|
|
148
|
+
try {
|
|
149
|
+
fs.writeFileSync(path.join(dir, "input.json"), JSON.stringify(coreContract(), (key, value) => (key === "origin" || key === "member") && value === null ? undefined : value));
|
|
150
|
+
fs.writeFileSync(path.join(dir, "blocked"), "file");
|
|
151
|
+
const descriptor = fs.openSync("/dev/full", "w");
|
|
152
|
+
let result;
|
|
153
|
+
try {
|
|
154
|
+
result = spawnSync(binary, ["--sidecar", "input.json", "--out", "a", "--facade", "blocked/b"], { cwd: dir, stdio: ["ignore", "pipe", descriptor] });
|
|
155
|
+
} finally { fs.closeSync(descriptor); }
|
|
156
|
+
assert.ifError(result.error);
|
|
157
|
+
assert.equal(result.signal, null);
|
|
158
|
+
assert.equal(result.status, 1);
|
|
159
|
+
const entries = fs.readdirSync(dir).sort();
|
|
160
|
+
assert.deepEqual(entries, ["blocked", "input.json"]);
|
|
161
|
+
return { status: result.status, stdout: result.stdout, entries };
|
|
162
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
163
|
+
}
|
|
164
|
+
assert.deepEqual(failedDiagnostic(candidate), failedDiagnostic(reference));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Portable filesystem coordination for the build-host corewire tool. Native
|
|
2
|
+
// capabilities supply OS path operations, exact metadata, entropy and I/O.
|
|
3
|
+
import { diagnostic, textBytes } from "./invocation.ts";
|
|
4
|
+
|
|
5
|
+
export interface PathState { base: number[]; exists: boolean }
|
|
6
|
+
export interface FileIdentity {
|
|
7
|
+
canonical: number[] | null;
|
|
8
|
+
basename: number[];
|
|
9
|
+
parent: number[] | null;
|
|
10
|
+
metadata: string[] | null;
|
|
11
|
+
}
|
|
12
|
+
export interface FileOutput {
|
|
13
|
+
kind: string; flag: string; path: number[]; parent: number[] | null;
|
|
14
|
+
staged: number[];
|
|
15
|
+
}
|
|
16
|
+
export interface OutputState {
|
|
17
|
+
mode: string; outputs: FileOutput[]; phase: string; index: number; prior: number;
|
|
18
|
+
temporary: number[]; write_failed: boolean; cleanup_at: number; cleanup_end: number;
|
|
19
|
+
after_diagnostic: string; error: number[]; exit_code: number;
|
|
20
|
+
}
|
|
21
|
+
export interface Observation { ok: boolean; error: number[]; bytes: number[]; identity: boolean }
|
|
22
|
+
export interface OutputAction { kind: string; index: number; prior: number; path: number[]; projection: string; message: number[] }
|
|
23
|
+
export interface OutputStep { state: OutputState; action: OutputAction }
|
|
24
|
+
function same(a: number[], b: number[]): boolean {
|
|
25
|
+
if (a.length !== b.length) return false;
|
|
26
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function join(a: number[], b: number[]): number[] {
|
|
30
|
+
const out = a.slice();
|
|
31
|
+
for (const byte of b) out.push(byte);
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
export function pathBegin(root: number[] | null, absolute: boolean, cwd: number[] | null): { state: PathState; resolve: boolean } {
|
|
35
|
+
return { state: { base: root ?? cwd ?? textBytes("."), exists: true }, resolve: root !== null && !absolute };
|
|
36
|
+
}
|
|
37
|
+
export function pathComponent(state: PathState, component: number[]): { action: string; probe: boolean } {
|
|
38
|
+
if (same(component, textBytes("."))) return { action: "keep", probe: false };
|
|
39
|
+
if (same(component, textBytes(".."))) return { action: "parent", probe: !state.exists };
|
|
40
|
+
return { action: "join", probe: state.exists };
|
|
41
|
+
}
|
|
42
|
+
export function pathObserved(state: PathState, action: string, candidate: number[], canonical: number[] | null): PathState {
|
|
43
|
+
if (action === "keep") return state;
|
|
44
|
+
if (canonical !== null) return { base: canonical, exists: true };
|
|
45
|
+
return { base: candidate, exists: action === "parent" && state.exists };
|
|
46
|
+
}
|
|
47
|
+
export function identityPlan(a: FileIdentity, b: FileIdentity): { same: boolean; stat: boolean } {
|
|
48
|
+
if (a.canonical === null || b.canonical === null) return { same: false, stat: false };
|
|
49
|
+
if (same(a.canonical, b.canonical)) return { same: true, stat: false };
|
|
50
|
+
return { same: false, stat: same(a.basename, b.basename) && a.parent !== null && b.parent !== null };
|
|
51
|
+
}
|
|
52
|
+
export function metadataIdentity(a: string[] | null, b: string[] | null): boolean {
|
|
53
|
+
if (a === null || b === null || a.length !== 6 || b.length !== 6) return false;
|
|
54
|
+
for (let i = 0; i < 6; i++) if (a[i] !== b[i]) return false;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
export function aliasPaths(outputs: FileOutput[]): number[][] {
|
|
58
|
+
const paths = outputs.map(output => output.path);
|
|
59
|
+
for (const output of outputs) paths.push(join(output.path, textBytes(".corewire-tmp")));
|
|
60
|
+
return paths;
|
|
61
|
+
}
|
|
62
|
+
export function outputBegin(mode: string, outputs: FileOutput[]): OutputState {
|
|
63
|
+
return { mode, outputs, phase: mode === "service" ? "service_generate" : "stage_alias", index: 0, prior: 0,
|
|
64
|
+
temporary: [], write_failed: false, cleanup_at: 0, cleanup_end: 0, after_diagnostic: "done", error: [], exit_code: 0 };
|
|
65
|
+
}
|
|
66
|
+
function errorMessage(prefix: string, path: number[], error: number[], suffix: string): number[] {
|
|
67
|
+
return join(join(diagnostic(prefix, path, ": "), error), textBytes(suffix));
|
|
68
|
+
}
|
|
69
|
+
function aliasMessage(output: FileOutput, earlier: FileOutput, commit: boolean): number[] {
|
|
70
|
+
return diagnostic("corewire: " + output.flag + " ", output.path, commit
|
|
71
|
+
? " resolves to the file " + earlier.flag + " just wrote — the later projection would overwrite the earlier\n"
|
|
72
|
+
: " resolves to the " + earlier.flag + " file — the later projection would overwrite the earlier\n");
|
|
73
|
+
}
|
|
74
|
+
function fail(state: OutputState, message: number[], code: number, first: number, end: number, diagnosticFirst: boolean): void {
|
|
75
|
+
state.error = message; state.exit_code = code; state.cleanup_at = first; state.cleanup_end = end;
|
|
76
|
+
state.after_diagnostic = diagnosticFirst ? "cleanup" : "done";
|
|
77
|
+
state.phase = diagnosticFirst ? "diagnostic" : "cleanup";
|
|
78
|
+
}
|
|
79
|
+
function action(state: OutputState, kind: string, path: number[] = [], projection = "", message: number[] = []): OutputStep {
|
|
80
|
+
return { state, action: { kind, index: state.index, prior: state.prior, path, projection, message } };
|
|
81
|
+
}
|
|
82
|
+
export function stagingPath(path: number[], nonce: number[]): number[] {
|
|
83
|
+
if (nonce.length !== 8) throw new Error("invalid corewire entropy extent");
|
|
84
|
+
const out = join(path, textBytes(".corewire-tmp."));
|
|
85
|
+
for (const byte of nonce) {
|
|
86
|
+
const high = byte >>> 4, low = byte & 15;
|
|
87
|
+
out.push(high < 10 ? 48 + high : 87 + high, low < 10 ? 48 + low : 87 + low);
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
export function outputStep(state: OutputState, observed: Observation): OutputStep {
|
|
92
|
+
// Only transitions without a capability loop here. Every external action is
|
|
93
|
+
// returned to the native executor, including ignored cleanup failures.
|
|
94
|
+
while (true) {
|
|
95
|
+
const output = state.outputs[state.index];
|
|
96
|
+
switch (state.phase) {
|
|
97
|
+
case "stage_alias":
|
|
98
|
+
case "commit_alias": {
|
|
99
|
+
const commit = state.phase === "commit_alias";
|
|
100
|
+
if (state.index === state.outputs.length) {
|
|
101
|
+
if (commit) { state.phase = "done"; continue; }
|
|
102
|
+
state.index = 0; state.prior = 0; state.phase = "commit_alias"; continue;
|
|
103
|
+
}
|
|
104
|
+
if (state.prior < state.index) {
|
|
105
|
+
state.phase = commit ? "commit_alias_result" : "stage_alias_result";
|
|
106
|
+
return action(state, "identity", output.path);
|
|
107
|
+
}
|
|
108
|
+
if (commit) { state.phase = "rename_result"; return action(state, "rename", output.path); }
|
|
109
|
+
state.phase = "entropy";
|
|
110
|
+
if (output.parent !== null) return action(state, "mkdir", output.parent);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
case "stage_alias_result":
|
|
114
|
+
case "commit_alias_result": {
|
|
115
|
+
const commit = state.phase === "commit_alias_result";
|
|
116
|
+
if (observed.identity) {
|
|
117
|
+
fail(state, aliasMessage(output, state.outputs[state.prior], commit), 2,
|
|
118
|
+
commit ? state.index : 0, commit ? state.outputs.length : state.index, false);
|
|
119
|
+
} else { state.prior++; state.phase = commit ? "commit_alias" : "stage_alias"; }
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
case "entropy": state.phase = "entropy_result"; return action(state, "entropy");
|
|
123
|
+
case "entropy_result":
|
|
124
|
+
state.temporary = stagingPath(output.path, observed.bytes); state.write_failed = false;
|
|
125
|
+
state.phase = "create_result"; return action(state, "create", state.temporary);
|
|
126
|
+
case "create_result":
|
|
127
|
+
if (!observed.ok) {
|
|
128
|
+
fail(state, errorMessage("corewire: cannot stage ", state.temporary, observed.error, "\n"), 1, 0, state.index, true);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
state.phase = "write_result"; return action(state, "write");
|
|
132
|
+
case "write_result":
|
|
133
|
+
state.write_failed = !observed.ok;
|
|
134
|
+
if (state.write_failed) { state.phase = "close_result"; return action(state, "close"); }
|
|
135
|
+
state.phase = "flush_result"; return action(state, "flush");
|
|
136
|
+
case "flush_result":
|
|
137
|
+
state.write_failed = !observed.ok; state.phase = "close_result"; return action(state, "close");
|
|
138
|
+
case "close_result":
|
|
139
|
+
if (state.write_failed) { state.phase = "write_failure"; return action(state, "delete", state.temporary); }
|
|
140
|
+
output.staged = state.temporary; state.index++; state.prior = 0; state.phase = "stage_alias"; continue;
|
|
141
|
+
case "write_failure":
|
|
142
|
+
fail(state, diagnostic("corewire: cannot write ", state.temporary, "\n"), 1, 0, state.index, true); continue;
|
|
143
|
+
case "rename_result":
|
|
144
|
+
if (!observed.ok) {
|
|
145
|
+
fail(state, errorMessage("corewire: cannot write ", output.path, observed.error, state.index > 0
|
|
146
|
+
? " — earlier projections were already replaced, so the outputs on disk may be from different generations; re-run to restore the set\n" : "\n"),
|
|
147
|
+
1, state.index, state.outputs.length, false);
|
|
148
|
+
} else { state.index++; state.prior = 0; state.phase = "commit_alias"; }
|
|
149
|
+
continue;
|
|
150
|
+
case "service_generate":
|
|
151
|
+
if (state.index === state.outputs.length) { state.phase = "done"; continue; }
|
|
152
|
+
state.phase = "service_write";
|
|
153
|
+
return action(state, "generate", [], output.kind === "inproc_main" ? "inproc" : output.kind === "inproc_profile" ? "profile" : output.kind);
|
|
154
|
+
case "service_write": state.phase = "service_write_result"; return action(state, "service_write", output.path);
|
|
155
|
+
case "service_write_result":
|
|
156
|
+
if (!observed.ok) fail(state, errorMessage("corewire: cannot write ", output.path, observed.error, "\n"), 1, 0, 0, true);
|
|
157
|
+
else { state.index++; state.phase = "service_generate"; }
|
|
158
|
+
continue;
|
|
159
|
+
case "cleanup":
|
|
160
|
+
if (state.cleanup_at < state.cleanup_end) {
|
|
161
|
+
const path = state.outputs[state.cleanup_at++].staged;
|
|
162
|
+
return action(state, "delete", path);
|
|
163
|
+
}
|
|
164
|
+
state.phase = state.after_diagnostic === "cleanup" ? "done" : "diagnostic"; continue;
|
|
165
|
+
case "diagnostic":
|
|
166
|
+
state.phase = state.after_diagnostic;
|
|
167
|
+
return action(state, "diagnostic", [], "", state.error);
|
|
168
|
+
case "done": return action(state, "done");
|
|
169
|
+
default: throw new Error("invalid corewire output phase");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// This ABI transports raw paths as bytes and metadata as exact decimal text.
|
|
175
|
+
// JSON strings never convert paths or native integers through a JS number.
|
|
176
|
+
export function filesystemPolicy(input: string): string {
|
|
177
|
+
const value = JSON.parse(input) as { operation: string; payload: string };
|
|
178
|
+
switch (value.operation) {
|
|
179
|
+
case "path_begin": {
|
|
180
|
+
const v = JSON.parse(value.payload) as { root: number[] | null; absolute: boolean; cwd: number[] | null };
|
|
181
|
+
return JSON.stringify(pathBegin(v.root, v.absolute, v.cwd));
|
|
182
|
+
}
|
|
183
|
+
case "path_component": {
|
|
184
|
+
const v = JSON.parse(value.payload) as { state: PathState; component: number[] };
|
|
185
|
+
return JSON.stringify(pathComponent(v.state, v.component));
|
|
186
|
+
}
|
|
187
|
+
case "path_observed": {
|
|
188
|
+
const v = JSON.parse(value.payload) as { state: PathState; action: string; candidate: number[]; canonical: number[] | null };
|
|
189
|
+
return JSON.stringify(pathObserved(v.state, v.action, v.candidate, v.canonical));
|
|
190
|
+
}
|
|
191
|
+
case "identity_plan": {
|
|
192
|
+
const v = JSON.parse(value.payload) as { left: FileIdentity; right: FileIdentity };
|
|
193
|
+
return JSON.stringify(identityPlan(v.left, v.right));
|
|
194
|
+
}
|
|
195
|
+
case "metadata_identity": {
|
|
196
|
+
const v = JSON.parse(value.payload) as { left: FileIdentity; right: FileIdentity };
|
|
197
|
+
return JSON.stringify(metadataIdentity(v.left.metadata, v.right.metadata));
|
|
198
|
+
}
|
|
199
|
+
case "alias_paths": {
|
|
200
|
+
const v = JSON.parse(value.payload) as { outputs: FileOutput[] };
|
|
201
|
+
return JSON.stringify(aliasPaths(v.outputs));
|
|
202
|
+
}
|
|
203
|
+
case "output_begin": {
|
|
204
|
+
const v = JSON.parse(value.payload) as { mode: string; outputs: FileOutput[] };
|
|
205
|
+
return JSON.stringify(outputBegin(v.mode, v.outputs));
|
|
206
|
+
}
|
|
207
|
+
case "output_step": {
|
|
208
|
+
const v = JSON.parse(value.payload) as { output_state: OutputState; observation: Observation };
|
|
209
|
+
return JSON.stringify(outputStep(v.output_state, v.observation));
|
|
210
|
+
}
|
|
211
|
+
default: throw new Error("unknown corewire filesystem operation");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
//! Explicit OS capabilities and owned-byte transport for compiled filesystem
|
|
2
|
+
//! coordination. Portable decisions live in filesystem_coordination.ts.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const invocation = @import("invocation.zig");
|
|
5
|
+
const service = @import("service_contract.zig");
|
|
6
|
+
const projection = @import("service_projection.zig");
|
|
7
|
+
const PanicSink = *const fn (?*anyopaque, [*]const u8, usize, u64) callconv(.c) void;
|
|
8
|
+
extern fn nsc_profile_set_panic_sink(PanicSink, ?*anyopaque) void;
|
|
9
|
+
extern fn nsc_profile_init() void;
|
|
10
|
+
extern fn nsc_profile_collect() void;
|
|
11
|
+
extern fn nsc_profile_filesystem_policy([*]const u8, usize, *[*]const u8, *usize) void;
|
|
12
|
+
|
|
13
|
+
fn panicSink(_: ?*anyopaque, message: [*]const u8, len: usize, _: u64) callconv(.c) void {
|
|
14
|
+
std.debug.print("corewire: filesystem coordination trapped: {s}\n", .{message[0..len]});
|
|
15
|
+
std.process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
fn call(comptime T: type, arena: std.mem.Allocator, facts: anytype) !T {
|
|
18
|
+
const payload = try std.json.Stringify.valueAlloc(arena, facts, .{});
|
|
19
|
+
const input = try std.json.Stringify.valueAlloc(arena, .{ .operation = facts.operation, .payload = payload }, .{});
|
|
20
|
+
nsc_profile_set_panic_sink(panicSink, null);
|
|
21
|
+
nsc_profile_init();
|
|
22
|
+
defer nsc_profile_collect();
|
|
23
|
+
var ptr: [*]const u8 = undefined;
|
|
24
|
+
var len: usize = 0;
|
|
25
|
+
nsc_profile_filesystem_policy(input.ptr, input.len, &ptr, &len);
|
|
26
|
+
return std.json.parseFromSliceLeaky(T, arena, ptr[0..len], .{ .allocate = .alloc_always }) catch |err| switch (err) {
|
|
27
|
+
error.OutOfMemory => return error.OutOfMemory,
|
|
28
|
+
else => @panic("corewire: malformed compiled filesystem response"),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
fn raw(arena: std.mem.Allocator, bytes: []const u8) !std.json.Value {
|
|
32
|
+
var array: std.json.Array = .init(arena);
|
|
33
|
+
for (bytes) |byte| try array.append(.{ .integer = byte });
|
|
34
|
+
return .{ .array = array };
|
|
35
|
+
}
|
|
36
|
+
fn optionalRaw(arena: std.mem.Allocator, bytes: ?[]const u8) !std.json.Value {
|
|
37
|
+
return if (bytes) |value| raw(arena, value) else .null;
|
|
38
|
+
}
|
|
39
|
+
fn stateBase(arena: std.mem.Allocator, state: std.json.Value) ![]const u8 {
|
|
40
|
+
const items = state.object.get("base").?.array.items;
|
|
41
|
+
const bytes = try arena.alloc(u8, items.len);
|
|
42
|
+
for (items, 0..) |item, i| bytes[i] = @intCast(item.integer);
|
|
43
|
+
return bytes;
|
|
44
|
+
}
|
|
45
|
+
pub fn canonicalSpelling(io: std.Io, arena: std.mem.Allocator, path: []const u8) ![]const u8 {
|
|
46
|
+
var buffer: [std.fs.max_path_bytes]u8 = undefined;
|
|
47
|
+
var components = std.fs.path.componentIterator(path);
|
|
48
|
+
const root = components.root();
|
|
49
|
+
var cwd: ?[]const u8 = null;
|
|
50
|
+
if (root == null) {
|
|
51
|
+
if (std.Io.Dir.cwd().realPath(io, &buffer)) |len| cwd = try arena.dupe(u8, buffer[0..len]) else |_| {}
|
|
52
|
+
}
|
|
53
|
+
const begin = try call(struct { state: std.json.Value, resolve: bool }, arena, .{
|
|
54
|
+
.operation = "path_begin",
|
|
55
|
+
.root = try optionalRaw(arena, root),
|
|
56
|
+
.absolute = std.fs.path.isAbsolute(path),
|
|
57
|
+
.cwd = try optionalRaw(arena, cwd),
|
|
58
|
+
});
|
|
59
|
+
if (begin.resolve) return std.fs.path.resolve(arena, &.{path});
|
|
60
|
+
var state = begin.state;
|
|
61
|
+
while (components.next()) |component| {
|
|
62
|
+
const plan = try call(struct { action: enum { keep, parent, join }, probe: bool }, arena, .{
|
|
63
|
+
.operation = "path_component",
|
|
64
|
+
.state = state,
|
|
65
|
+
.component = try raw(arena, component.name),
|
|
66
|
+
});
|
|
67
|
+
if (plan.action == .keep) continue;
|
|
68
|
+
const base = try stateBase(arena, state);
|
|
69
|
+
const candidate = switch (plan.action) {
|
|
70
|
+
.parent => std.fs.path.dirname(base) orelse base,
|
|
71
|
+
.join => try std.fs.path.join(arena, &.{ base, component.name }),
|
|
72
|
+
.keep => unreachable,
|
|
73
|
+
};
|
|
74
|
+
var canonical: ?[]const u8 = null;
|
|
75
|
+
if (plan.probe) {
|
|
76
|
+
if (std.Io.Dir.cwd().realPathFile(io, candidate, &buffer)) |len| canonical = try arena.dupe(u8, buffer[0..len]) else |_| {}
|
|
77
|
+
}
|
|
78
|
+
state = try call(std.json.Value, arena, .{
|
|
79
|
+
.operation = "path_observed",
|
|
80
|
+
.state = state,
|
|
81
|
+
.action = @tagName(plan.action),
|
|
82
|
+
.candidate = try raw(arena, candidate),
|
|
83
|
+
.canonical = try optionalRaw(arena, canonical),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return stateBase(arena, state);
|
|
87
|
+
}
|
|
88
|
+
const Identity = struct {
|
|
89
|
+
canonical: std.json.Value,
|
|
90
|
+
basename: std.json.Value,
|
|
91
|
+
parent: std.json.Value,
|
|
92
|
+
metadata: ?[]const []const u8 = null,
|
|
93
|
+
};
|
|
94
|
+
fn identity(arena: std.mem.Allocator, canonical: ?[]const u8) !Identity {
|
|
95
|
+
return .{
|
|
96
|
+
.canonical = try optionalRaw(arena, canonical),
|
|
97
|
+
.basename = try raw(arena, if (canonical) |path| std.fs.path.basename(path) else ""),
|
|
98
|
+
.parent = try optionalRaw(arena, if (canonical) |path| std.fs.path.dirname(path) else null),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
fn metadata(io: std.Io, arena: std.mem.Allocator, canonical: []const u8) !?[]const []const u8 {
|
|
102
|
+
const stat = std.Io.Dir.cwd().statFile(io, std.fs.path.dirname(canonical).?, .{}) catch return null;
|
|
103
|
+
const fields = try arena.alloc([]const u8, 6);
|
|
104
|
+
fields[0] = try std.fmt.allocPrint(arena, "{d}", .{stat.inode});
|
|
105
|
+
fields[1] = @tagName(stat.kind);
|
|
106
|
+
fields[2] = try std.fmt.allocPrint(arena, "{d}", .{stat.size});
|
|
107
|
+
fields[3] = try std.fmt.allocPrint(arena, "{d}", .{stat.nlink});
|
|
108
|
+
fields[4] = try std.fmt.allocPrint(arena, "{d}", .{stat.mtime.nanoseconds});
|
|
109
|
+
fields[5] = try std.fmt.allocPrint(arena, "{d}", .{stat.ctime.nanoseconds});
|
|
110
|
+
return fields;
|
|
111
|
+
}
|
|
112
|
+
pub fn sameExistingFile(io: std.Io, arena: std.mem.Allocator, a: []const u8, b: []const u8) !bool {
|
|
113
|
+
var buffer_a: [std.fs.max_path_bytes]u8 = undefined;
|
|
114
|
+
var buffer_b: [std.fs.max_path_bytes]u8 = undefined;
|
|
115
|
+
const len_a = std.Io.Dir.cwd().realPathFile(io, a, &buffer_a) catch return false;
|
|
116
|
+
const len_b = std.Io.Dir.cwd().realPathFile(io, b, &buffer_b) catch return false;
|
|
117
|
+
const canon_a = buffer_a[0..len_a];
|
|
118
|
+
const canon_b = buffer_b[0..len_b];
|
|
119
|
+
var left = try identity(arena, canon_a);
|
|
120
|
+
var right = try identity(arena, canon_b);
|
|
121
|
+
const plan = try call(struct { same: bool, stat: bool }, arena, .{ .operation = "identity_plan", .left = left, .right = right });
|
|
122
|
+
if (!plan.stat) return plan.same;
|
|
123
|
+
left.metadata = try metadata(io, arena, canon_a);
|
|
124
|
+
// Preserve original early refusal before observing the second parent.
|
|
125
|
+
if (left.metadata == null) return false;
|
|
126
|
+
right.metadata = try metadata(io, arena, canon_b);
|
|
127
|
+
return call(bool, arena, .{ .operation = "metadata_identity", .left = left, .right = right });
|
|
128
|
+
}
|
|
129
|
+
const Output = struct { kind: []const u8, flag: []const u8, path: std.json.Value, parent: std.json.Value, staged: std.json.Value };
|
|
130
|
+
fn outputs(arena: std.mem.Allocator, plan: invocation.Plan, args: []const []const u8) ![]const Output {
|
|
131
|
+
const values = try arena.alloc(Output, plan.outputs.len);
|
|
132
|
+
for (plan.outputs, 0..) |output, i| {
|
|
133
|
+
const path = args[output.path_index];
|
|
134
|
+
values[i] = .{ .kind = @tagName(output.kind), .flag = output.flag, .path = try raw(arena, path), .parent = try optionalRaw(arena, std.fs.path.dirname(path)), .staged = try raw(arena, "") };
|
|
135
|
+
}
|
|
136
|
+
return values;
|
|
137
|
+
}
|
|
138
|
+
pub fn aliasPaths(arena: std.mem.Allocator, plan: invocation.Plan, args: []const []const u8) ![]const []const u8 {
|
|
139
|
+
return call([]const []const u8, arena, .{ .operation = "alias_paths", .outputs = try outputs(arena, plan, args) });
|
|
140
|
+
}
|
|
141
|
+
const Observation = struct { ok: bool = true, @"error": std.json.Value = .null, bytes: std.json.Value = .null, identity: bool = false };
|
|
142
|
+
const Action = struct { kind: enum { identity, mkdir, entropy, create, write, flush, close, delete, rename, generate, service_write, diagnostic, done }, index: usize, prior: usize, path: []const u8, projection: []const u8, message: []const u8 };
|
|
143
|
+
fn cleanupAfterDiagnosticFailure(init: std.process.Init, state_at_failure: std.json.Value) !void {
|
|
144
|
+
const arena = init.arena.allocator();
|
|
145
|
+
var state = state_at_failure;
|
|
146
|
+
const observed = Observation{ .@"error" = try raw(arena, ""), .bytes = try raw(arena, "") };
|
|
147
|
+
while (true) {
|
|
148
|
+
const step = try call(struct { state: std.json.Value, action: Action }, arena, .{
|
|
149
|
+
.operation = "output_step",
|
|
150
|
+
.output_state = state,
|
|
151
|
+
.observation = observed,
|
|
152
|
+
});
|
|
153
|
+
state = step.state;
|
|
154
|
+
switch (step.action.kind) {
|
|
155
|
+
.delete => std.Io.Dir.cwd().deleteFile(init.io, step.action.path) catch {},
|
|
156
|
+
.done => return,
|
|
157
|
+
else => unreachable,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
pub fn execute(init: std.process.Init, stderr: *std.Io.Writer, plan: invocation.Plan, args: []const []const u8, core: ?invocation.CoreResult, contract: ?service.Contract) !u8 {
|
|
162
|
+
const arena = init.arena.allocator();
|
|
163
|
+
var state = try call(std.json.Value, arena, .{ .operation = "output_begin", .mode = @tagName(plan.mode), .outputs = try outputs(arena, plan, args) });
|
|
164
|
+
var observed = Observation{ .@"error" = try raw(arena, ""), .bytes = try raw(arena, "") };
|
|
165
|
+
var staging: ?std.Io.File = null;
|
|
166
|
+
defer if (staging) |file| file.close(init.io);
|
|
167
|
+
var buffer: [4096]u8 = undefined;
|
|
168
|
+
var writer: std.Io.File.Writer = undefined;
|
|
169
|
+
const staged = try arena.alloc([]const u8, plan.outputs.len);
|
|
170
|
+
var current: []const u8 = "";
|
|
171
|
+
while (true) {
|
|
172
|
+
const step = try call(struct { state: std.json.Value, action: Action }, arena, .{
|
|
173
|
+
.operation = "output_step",
|
|
174
|
+
.output_state = state,
|
|
175
|
+
.observation = observed,
|
|
176
|
+
});
|
|
177
|
+
state = step.state;
|
|
178
|
+
const action = step.action;
|
|
179
|
+
observed = .{ .@"error" = try raw(arena, ""), .bytes = try raw(arena, "") };
|
|
180
|
+
switch (action.kind) {
|
|
181
|
+
.identity => observed.identity = try sameExistingFile(init.io, arena, action.path, args[plan.outputs[action.prior].path_index]),
|
|
182
|
+
.mkdir => std.Io.Dir.cwd().createDirPath(init.io, action.path) catch {},
|
|
183
|
+
.entropy => {
|
|
184
|
+
var nonce: [8]u8 = undefined;
|
|
185
|
+
init.io.random(&nonce);
|
|
186
|
+
observed.bytes = try raw(arena, &nonce);
|
|
187
|
+
},
|
|
188
|
+
.create => {
|
|
189
|
+
staging = std.Io.Dir.cwd().createFile(init.io, action.path, .{ .exclusive = true }) catch |err| blk: {
|
|
190
|
+
observed.ok = false;
|
|
191
|
+
observed.@"error" = try raw(arena, @errorName(err));
|
|
192
|
+
break :blk null;
|
|
193
|
+
};
|
|
194
|
+
if (staging) |file| {
|
|
195
|
+
staged[action.index] = action.path;
|
|
196
|
+
writer = file.writerStreaming(init.io, &buffer);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
.write => {
|
|
200
|
+
const data = switch (plan.outputs[action.index].kind) {
|
|
201
|
+
.mirror => core.?.mirror,
|
|
202
|
+
.facade => core.?.facade,
|
|
203
|
+
.profile => core.?.profile,
|
|
204
|
+
.effective => core.?.effective,
|
|
205
|
+
else => unreachable,
|
|
206
|
+
};
|
|
207
|
+
writer.interface.writeAll(data) catch {
|
|
208
|
+
observed.ok = false;
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
.flush => writer.interface.flush() catch {
|
|
212
|
+
observed.ok = false;
|
|
213
|
+
},
|
|
214
|
+
.close => {
|
|
215
|
+
staging.?.close(init.io);
|
|
216
|
+
staging = null;
|
|
217
|
+
},
|
|
218
|
+
.delete => std.Io.Dir.cwd().deleteFile(init.io, action.path) catch {},
|
|
219
|
+
.rename => std.Io.Dir.cwd().rename(staged[action.index], std.Io.Dir.cwd(), action.path, init.io) catch |err| {
|
|
220
|
+
observed.ok = false;
|
|
221
|
+
observed.@"error" = try raw(arena, @errorName(err));
|
|
222
|
+
},
|
|
223
|
+
.generate => {
|
|
224
|
+
const input = try std.json.Stringify.valueAlloc(arena, contract.?, .{});
|
|
225
|
+
const optimization = if (plan.optimization) |index| args[index] else "";
|
|
226
|
+
current = try projection.generate(arena, input, action.projection, optimization);
|
|
227
|
+
},
|
|
228
|
+
.service_write => std.Io.Dir.cwd().writeFile(init.io, .{ .sub_path = action.path, .data = current }) catch |err| {
|
|
229
|
+
observed.ok = false;
|
|
230
|
+
observed.@"error" = try raw(arena, @errorName(err));
|
|
231
|
+
},
|
|
232
|
+
.diagnostic => {
|
|
233
|
+
stderr.writeAll(action.message) catch |err| {
|
|
234
|
+
try cleanupAfterDiagnosticFailure(init, state);
|
|
235
|
+
return err;
|
|
236
|
+
};
|
|
237
|
+
stderr.flush() catch |err| {
|
|
238
|
+
try cleanupAfterDiagnosticFailure(init, state);
|
|
239
|
+
return err;
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
.done => return @intCast(state.object.get("exit_code").?.integer),
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|