@native-sdk/cli 0.9.1 → 0.9.3
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/build/app.zig +26 -9
- package/build.zig +124 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/packages/core/sdk/events.d.ts +7 -0
- package/packages/core/sdk/events.ts +26 -5
- package/packages/core/sdk/text.d.ts +4 -0
- package/packages/core/sdk/text.ts +51 -0
- package/packages/core/src/checker.ts +58 -1
- package/packages/core/src/contract.ts +5 -4
- package/packages/core/src/devhost_journal.mjs +2 -2
- package/packages/core/src/diagnostics.ts +2 -2
- package/packages/core/src/service_contract.ts +10 -0
- package/packages/core/src/typed_ast.ts +9 -7
- package/packages/core/src/types.ts +28 -8
- package/skill-data/automation/SKILL.md +4 -3
- package/skill-data/native-ui/SKILL.md +10 -8
- package/skill-data/ts-core/SKILL.md +8 -5
- package/src/app_runner/root.zig +301 -12
- package/src/app_runner/ts_core_main.zig +6 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +119 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +271 -52
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +222 -14
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +129 -1
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +14 -2
- package/src/primitives/canvas/text_interaction.zig +23 -0
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +65 -0
- package/src/primitives/canvas/ui.zig +66 -10
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +84 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +33 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/canvas_widget_text_tests.zig +124 -0
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +29 -0
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_journal.zig +21 -2
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ts_ui_app.zig +164 -1
- package/src/runtime/ui_app.zig +100 -21
- package/src/runtime/ui_app_tests.zig +351 -32
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_text.zig +1 -1
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/verbs.zig +1 -0
- package/src/tooling/web_engine.zig +1 -1
- package/tools/corewire/emit.zig +31 -12
- package/tools/corewire/emit_facade.zig +57 -2
- package/tools/corewire/shim_rt.zig +20 -0
|
@@ -670,7 +670,6 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
670
670
|
\\,
|
|
671
671
|
\\ .width = window_width,
|
|
672
672
|
\\ .height = window_height,
|
|
673
|
-
\\ .restore_state = false,
|
|
674
673
|
\\ .views = &shell_views,
|
|
675
674
|
\\}};
|
|
676
675
|
\\const shell_scene: native_sdk.ShellConfig = .{ .windows = &shell_windows };
|
|
@@ -798,7 +797,6 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
798
797
|
\\,
|
|
799
798
|
\\ .icon_path = "assets/icon.png",
|
|
800
799
|
\\ .default_frame = geometry.RectF.init(0, 0, window_width, window_height),
|
|
801
|
-
\\ .restore_state = false,
|
|
802
800
|
\\ .js_window_api = false,
|
|
803
801
|
\\ .security = .{
|
|
804
802
|
\\ .permissions = &app_permissions,
|
|
@@ -1066,8 +1064,6 @@ fn nativeAppZon(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
1066
1064
|
\\,
|
|
1067
1065
|
\\ .width = 480,
|
|
1068
1066
|
\\ .height = 320,
|
|
1069
|
-
\\ .restore_state = false,
|
|
1070
|
-
\\ .restore_policy = "center_on_primary",
|
|
1071
1067
|
\\ .views = .{
|
|
1072
1068
|
\\ .{ .label = "main-canvas", .kind = "gpu_surface", .fill = true, .role = "Counter canvas", .accessibility_label = "Counter", .gpu_backend = "metal", .gpu_pixel_format = "bgra8_unorm", .gpu_present_mode = "timer", .gpu_alpha_mode = "opaque", .gpu_color_space = "srgb", .gpu_vsync = true },
|
|
1073
1069
|
\\ },
|
|
@@ -1476,7 +1472,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1476
1472
|
\\ app_mod.addImport("native_sdk", native_sdk_mod);
|
|
1477
1473
|
\\ app_mod.addImport("runner", runner_mod);
|
|
1478
1474
|
\\ if (app_config.sqlite_capability) addSqliteEngine(b, app_mod, native_sdk_path);
|
|
1479
|
-
\\
|
|
1475
|
+
\\ addMacosInfoPlist(b, app_mod, target, app_config);
|
|
1480
1476
|
\\ const exe = b.addExecutable(.{
|
|
1481
1477
|
\\ .name = app_exe_name,
|
|
1482
1478
|
\\ .root_module = app_mod,
|
|
@@ -1542,7 +1538,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1542
1538
|
\\ package_app_mod.addImport("native_sdk", package_sdk_mod);
|
|
1543
1539
|
\\ package_app_mod.addImport("runner", package_runner_mod);
|
|
1544
1540
|
\\ if (app_config.sqlite_capability) addSqliteEngine(b, package_app_mod, native_sdk_path);
|
|
1545
|
-
\\
|
|
1541
|
+
\\ addMacosInfoPlist(b, package_app_mod, target, app_config);
|
|
1546
1542
|
\\ const built = b.addExecutable(.{
|
|
1547
1543
|
\\ .name = app_exe_name,
|
|
1548
1544
|
\\ .root_module = package_app_mod,
|
|
@@ -1614,14 +1610,18 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1614
1610
|
\\ return if (target.result.cpu.arch == .x86_64) true else null;
|
|
1615
1611
|
\\}
|
|
1616
1612
|
\\
|
|
1617
|
-
\\/// Bare Mach-O dev executables have no bundle Info.plist. Embed
|
|
1618
|
-
\\/// capture usage strings
|
|
1619
|
-
\\///
|
|
1620
|
-
\\/// receive the richer external plist from the package command.
|
|
1621
|
-
\\fn
|
|
1613
|
+
\\/// Bare Mach-O dev executables have no bundle Info.plist. Embed launch
|
|
1614
|
+
\\/// policy plus capture usage strings so LaunchServices starts accessory
|
|
1615
|
+
\\/// apps without a transient Dock tile and macOS can present consent.
|
|
1616
|
+
\\/// Packaged apps receive the richer external plist from the package command.
|
|
1617
|
+
\\fn addMacosInfoPlist(b: *std.Build, app_mod: *std.Build.Module, target: std.Build.ResolvedTarget, config: AppManifestBuildConfig) void {
|
|
1622
1618
|
\\ if (target.result.os.tag != .macos) return;
|
|
1623
|
-
\\ if (!config.microphone_permission and !config.system_audio_permission) return;
|
|
1619
|
+
\\ if (config.dock_visible and !config.microphone_permission and !config.system_audio_permission) return;
|
|
1624
1620
|
\\
|
|
1621
|
+
\\ const launch_policy = if (!config.dock_visible)
|
|
1622
|
+
\\ " <key>LSUIElement</key>\\n <true/>\\n"
|
|
1623
|
+
\\ else
|
|
1624
|
+
\\ "";
|
|
1625
1625
|
\\ const microphone = if (config.microphone_permission)
|
|
1626
1626
|
\\ " <key>NSMicrophoneUsageDescription</key>\\n <string>This app captures microphone audio when you start recording.</string>\\n"
|
|
1627
1627
|
\\ else
|
|
@@ -1632,11 +1632,11 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1632
1632
|
\\ else
|
|
1633
1633
|
\\ "";
|
|
1634
1634
|
\\ const source = b.fmt(
|
|
1635
|
-
\\ \\#define NATIVE_SDK_INFO_PLIST "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" "<plist version=\"1.0\">\n<dict>\n{s}{s}</dict>\n</plist>\n"
|
|
1635
|
+
\\ \\#define NATIVE_SDK_INFO_PLIST "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" "<plist version=\"1.0\">\n<dict>\n{s}{s}{s}</dict>\n</plist>\n"
|
|
1636
1636
|
\\ \\__attribute__((used, section("__TEXT,__info_plist")))
|
|
1637
1637
|
\\ \\static const unsigned char native_sdk_info_plist[sizeof(NATIVE_SDK_INFO_PLIST) - 1] = NATIVE_SDK_INFO_PLIST;
|
|
1638
1638
|
\\ \\
|
|
1639
|
-
\\ , .{ microphone, system_audio });
|
|
1639
|
+
\\ , .{ launch_policy, microphone, system_audio });
|
|
1640
1640
|
\\ const generated = b.addWriteFiles().add("native_sdk_macos_info_plist.c", source);
|
|
1641
1641
|
\\ app_mod.addCSourceFile(.{ .file = generated, .flags = &.{} });
|
|
1642
1642
|
\\}
|
|
@@ -2041,6 +2041,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
2041
2041
|
\\ cef_dir: []const u8 = "third_party/cef/macos",
|
|
2042
2042
|
\\ cef_auto_install: bool = false,
|
|
2043
2043
|
\\ webview_layer: WebLayerOption = .auto,
|
|
2044
|
+
\\ dock_visible: bool = true,
|
|
2044
2045
|
\\ microphone_permission: bool = false,
|
|
2045
2046
|
\\ system_audio_permission: bool = false,
|
|
2046
2047
|
\\ sqlite_capability: bool = false,
|
|
@@ -2058,6 +2059,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
2058
2059
|
\\const InferenceManifest = struct {
|
|
2059
2060
|
\\ capabilities: []const []const u8 = &.{},
|
|
2060
2061
|
\\ permissions: []const []const u8 = &.{},
|
|
2062
|
+
\\ dock_visible: bool = true,
|
|
2061
2063
|
\\ web_engine: []const u8 = "system",
|
|
2062
2064
|
\\ webview_layer: []const u8 = "auto",
|
|
2063
2065
|
\\ cef: struct {
|
|
@@ -2089,13 +2091,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
2089
2091
|
\\ // mismatch here is not proof the app declares no web use.
|
|
2090
2092
|
\\ const fallback: AppManifestBuildConfig = .{ .web_declaration = "an app.zon this build graph could not parse" };
|
|
2091
2093
|
\\ const source: [:0]const u8 = @embedFile("app.zon");
|
|
2092
|
-
\\ @setEvalBranchQuota(
|
|
2094
|
+
\\ @setEvalBranchQuota(4000);
|
|
2093
2095
|
\\ const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source, null, .{ .ignore_unknown_fields = true }) catch return fallback;
|
|
2094
2096
|
\\ var config: AppManifestBuildConfig = .{
|
|
2095
2097
|
\\ .web_engine = parseWebEngine(raw.web_engine) orelse .system,
|
|
2096
2098
|
\\ .cef_dir = raw.cef.dir,
|
|
2097
2099
|
\\ .cef_auto_install = raw.cef.auto_install,
|
|
2098
2100
|
\\ .webview_layer = parseWebLayer(raw.webview_layer) orelse @panic("app.zon .webview_layer must be \"auto\", \"include\", or \"exclude\""),
|
|
2101
|
+
\\ .dock_visible = raw.dock_visible,
|
|
2099
2102
|
\\ .microphone_permission = hasManifestPermission(raw.permissions, "microphone"),
|
|
2100
2103
|
\\ .system_audio_permission = hasManifestPermission(raw.permissions, "system_audio"),
|
|
2101
2104
|
\\ .sqlite_capability = hasManifestCapability(raw.capabilities, "store") or hasManifestCapability(raw.capabilities, "sqlite"),
|
|
@@ -2308,6 +2311,12 @@ fn runnerZig() []const u8 {
|
|
|
2308
2311
|
\\const manifest_menus = if (@hasField(@TypeOf(app_manifest), "menus")) app_manifest.menus else .{};
|
|
2309
2312
|
\\const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
|
|
2310
2313
|
\\
|
|
2314
|
+
\\fn manifestImagePixelBudget() usize {
|
|
2315
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest), "images")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
2316
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest.images), "max_image_pixel_bytes")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
2317
|
+
\\ return app_manifest.images.max_image_pixel_bytes;
|
|
2318
|
+
\\}
|
|
2319
|
+
\\
|
|
2311
2320
|
\\pub const StdoutTraceSink = struct {
|
|
2312
2321
|
\\ pub fn sink(self: *StdoutTraceSink) native_sdk.trace.Sink {
|
|
2313
2322
|
\\ return .{ .context = self, .write_fn = write };
|
|
@@ -2346,6 +2355,7 @@ fn runnerZig() []const u8 {
|
|
|
2346
2355
|
\\ .app_name = self.app_name,
|
|
2347
2356
|
\\ .has_web_content = manifestHasWebContent(),
|
|
2348
2357
|
\\ .declares_tray = manifestDeclaresTrayCapability(),
|
|
2358
|
+
\\ .dock_visible = manifestDockVisible(),
|
|
2349
2359
|
\\ .window_title = self.window_title,
|
|
2350
2360
|
\\ .bundle_id = self.bundle_id,
|
|
2351
2361
|
\\ .icon_path = self.icon_path,
|
|
@@ -2363,8 +2373,12 @@ fn runnerZig() []const u8 {
|
|
|
2363
2373
|
\\ // a canvas-first startup window is created ordered-out and
|
|
2364
2374
|
\\ // shown after its first canvas frame presents, so launch
|
|
2365
2375
|
\\ // never flashes a blank window.
|
|
2376
|
+
\\ info.main_window.default_frame = manifestShellStartupFrame(info.main_window.default_frame);
|
|
2377
|
+
\\ info.main_window.restore_state = manifestShellStartupRestoreState(info.main_window.restore_state);
|
|
2366
2378
|
\\ info.main_window.titlebar = manifestShellStartupTitlebar();
|
|
2367
2379
|
\\ info.main_window.resizable = manifestShellStartupResizable();
|
|
2380
|
+
\\ info.main_window.restore_policy = manifestShellStartupRestorePolicy(info.main_window.restore_policy);
|
|
2381
|
+
\\ info.main_window.initial_placement = manifestShellStartupInitialPlacement(info.main_window.initial_placement);
|
|
2368
2382
|
\\ info.main_window.show = manifestShellStartupShowMode();
|
|
2369
2383
|
\\ info.main_window.transparent = manifestShellStartupBool("transparent", false);
|
|
2370
2384
|
\\ info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
|
|
@@ -2502,6 +2516,7 @@ fn runnerZig() []const u8 {
|
|
|
2502
2516
|
\\ .resizable = windowBool(window, "resizable", true),
|
|
2503
2517
|
\\ .restore_state = windowBool(window, "restore_state", true),
|
|
2504
2518
|
\\ .restore_policy = windowRestorePolicy(window),
|
|
2519
|
+
\\ .initial_placement = if (windowHasExplicitOrigin(window)) .explicit else .default,
|
|
2505
2520
|
\\ .titlebar = windowTitlebarStyle(window),
|
|
2506
2521
|
\\ .show = if (windowBool(window, "initially_hidden", false)) .hidden else .immediate,
|
|
2507
2522
|
\\ .transparent = windowBool(window, "transparent", false),
|
|
@@ -2545,6 +2560,60 @@ fn runnerZig() []const u8 {
|
|
|
2545
2560
|
\\ @compileError("unknown app.zon window restore_policy");
|
|
2546
2561
|
\\}
|
|
2547
2562
|
\\
|
|
2563
|
+
\\fn windowHasExplicitOrigin(comptime window: anytype) bool {
|
|
2564
|
+
\\ return @hasField(@TypeOf(window), "x") or @hasField(@TypeOf(window), "y");
|
|
2565
|
+
\\}
|
|
2566
|
+
\\
|
|
2567
|
+
\\/// The host creates the first scene window before the scene loads, so its
|
|
2568
|
+
\\/// authored frame must ride AppInfo with the other creation-time options.
|
|
2569
|
+
\\/// Omitted fields preserve the direct runner fallback independently.
|
|
2570
|
+
\\fn manifestShellStartupFrame(fallback: native_sdk.geometry.RectF) native_sdk.geometry.RectF {
|
|
2571
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
2572
|
+
\\ const shell = app_manifest.shell;
|
|
2573
|
+
\\ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
2574
|
+
\\ if (comptime shell.windows.len == 0) return fallback;
|
|
2575
|
+
\\ const window = shell.windows[0];
|
|
2576
|
+
\\ return native_sdk.geometry.RectF.init(
|
|
2577
|
+
\\ windowFloatFallback(window, "x", fallback.x),
|
|
2578
|
+
\\ windowFloatFallback(window, "y", fallback.y),
|
|
2579
|
+
\\ windowFloatFallback(window, "width", fallback.width),
|
|
2580
|
+
\\ windowFloatFallback(window, "height", fallback.height),
|
|
2581
|
+
\\ );
|
|
2582
|
+
\\}
|
|
2583
|
+
\\
|
|
2584
|
+
\\fn windowFloatFallback(comptime window: anytype, comptime field: []const u8, fallback: f32) f32 {
|
|
2585
|
+
\\ if (comptime @hasField(@TypeOf(window), field)) return @field(window, field);
|
|
2586
|
+
\\ return fallback;
|
|
2587
|
+
\\}
|
|
2588
|
+
\\
|
|
2589
|
+
\\fn manifestShellStartupRestoreState(fallback: bool) bool {
|
|
2590
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
2591
|
+
\\ const shell = app_manifest.shell;
|
|
2592
|
+
\\ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
2593
|
+
\\ if (comptime shell.windows.len == 0) return fallback;
|
|
2594
|
+
\\ const window = shell.windows[0];
|
|
2595
|
+
\\ if (comptime @hasField(@TypeOf(window), "restore_state")) return window.restore_state;
|
|
2596
|
+
\\ return fallback;
|
|
2597
|
+
\\}
|
|
2598
|
+
\\
|
|
2599
|
+
\\fn manifestShellStartupRestorePolicy(fallback: native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
|
|
2600
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
2601
|
+
\\ const shell = app_manifest.shell;
|
|
2602
|
+
\\ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
2603
|
+
\\ if (comptime shell.windows.len == 0) return fallback;
|
|
2604
|
+
\\ const window = shell.windows[0];
|
|
2605
|
+
\\ if (comptime !@hasField(@TypeOf(window), "restore_policy")) return fallback;
|
|
2606
|
+
\\ return windowRestorePolicy(window);
|
|
2607
|
+
\\}
|
|
2608
|
+
\\
|
|
2609
|
+
\\fn manifestShellStartupInitialPlacement(fallback: native_sdk.WindowInitialPlacement) native_sdk.WindowInitialPlacement {
|
|
2610
|
+
\\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
2611
|
+
\\ const shell = app_manifest.shell;
|
|
2612
|
+
\\ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
2613
|
+
\\ if (comptime shell.windows.len == 0) return fallback;
|
|
2614
|
+
\\ return if (windowHasExplicitOrigin(shell.windows[0])) .explicit else fallback;
|
|
2615
|
+
\\}
|
|
2616
|
+
\\
|
|
2548
2617
|
\\/// Window-enforced content min-size floor from app.zon. Validated at
|
|
2549
2618
|
\\/// comptime like the titlebar style: a negative floor is an authoring
|
|
2550
2619
|
\\/// error, not a silent clamp.
|
|
@@ -2674,6 +2743,14 @@ fn runnerZig() []const u8 {
|
|
|
2674
2743
|
\\ return false;
|
|
2675
2744
|
\\}
|
|
2676
2745
|
\\
|
|
2746
|
+
\\fn manifestDockVisible() bool {
|
|
2747
|
+
\\ const visible = if (comptime @hasField(@TypeOf(app_manifest), "dock_visible")) app_manifest.dock_visible else true;
|
|
2748
|
+
\\ if (comptime !visible and !manifestDeclaresTrayCapability()) {
|
|
2749
|
+
\\ @compileError("app.zon dock_visible = false requires the \"tray\" capability: an accessory app has no Dock/app-switcher route back to hidden windows - add \"tray\" to .capabilities and install a status item, or keep dock_visible = true (the default)");
|
|
2750
|
+
\\ }
|
|
2751
|
+
\\ return visible;
|
|
2752
|
+
\\}
|
|
2753
|
+
\\
|
|
2677
2754
|
\\fn manifestDeclaresStore() bool {
|
|
2678
2755
|
\\ if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
|
|
2679
2756
|
\\ inline for (app_manifest.capabilities) |capability| {
|
|
@@ -2841,6 +2918,7 @@ fn runnerZig() []const u8 {
|
|
|
2841
2918
|
\\ defer std.heap.page_allocator.destroy(runtime);
|
|
2842
2919
|
\\ native_sdk.Runtime.initAt(runtime, .{
|
|
2843
2920
|
\\ .platform = null_platform.platform(),
|
|
2921
|
+
\\ .max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
2844
2922
|
\\ .trace_sink = runtime_trace_sink,
|
|
2845
2923
|
\\ .log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
2846
2924
|
\\ .bridge = options.bridge,
|
|
@@ -2898,6 +2976,7 @@ fn runnerZig() []const u8 {
|
|
|
2898
2976
|
\\ defer std.heap.page_allocator.destroy(runtime);
|
|
2899
2977
|
\\ native_sdk.Runtime.initAt(runtime, .{
|
|
2900
2978
|
\\ .platform = mac_platform.platform(),
|
|
2979
|
+
\\ .max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
2901
2980
|
\\ .trace_sink = runtime_trace_sink,
|
|
2902
2981
|
\\ .log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
2903
2982
|
\\ .bridge = options.bridge,
|
|
@@ -2955,6 +3034,7 @@ fn runnerZig() []const u8 {
|
|
|
2955
3034
|
\\ defer std.heap.page_allocator.destroy(runtime);
|
|
2956
3035
|
\\ native_sdk.Runtime.initAt(runtime, .{
|
|
2957
3036
|
\\ .platform = linux_platform.platform(),
|
|
3037
|
+
\\ .max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
2958
3038
|
\\ .trace_sink = runtime_trace_sink,
|
|
2959
3039
|
\\ .log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
2960
3040
|
\\ .bridge = options.bridge,
|
|
@@ -3012,6 +3092,7 @@ fn runnerZig() []const u8 {
|
|
|
3012
3092
|
\\ defer std.heap.page_allocator.destroy(runtime);
|
|
3013
3093
|
\\ native_sdk.Runtime.initAt(runtime, .{
|
|
3014
3094
|
\\ .platform = windows_platform.platform(),
|
|
3095
|
+
\\ .max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
3015
3096
|
\\ .trace_sink = runtime_trace_sink,
|
|
3016
3097
|
\\ .log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
3017
3098
|
\\ .bridge = options.bridge,
|
|
@@ -3103,12 +3184,17 @@ fn runnerZig() []const u8 {
|
|
|
3103
3184
|
\\ if (!window.restore_state) continue;
|
|
3104
3185
|
\\ if (store.loadWindow(window.label, &buffers.read) catch null) |saved| {
|
|
3105
3186
|
\\ window.default_frame = saved.frame;
|
|
3106
|
-
\\
|
|
3187
|
+
\\ window.initial_placement = .restored;
|
|
3188
|
+
\\ if (index == 0) {
|
|
3189
|
+
\\ app_info.main_window.default_frame = saved.frame;
|
|
3190
|
+
\\ app_info.main_window.initial_placement = .restored;
|
|
3191
|
+
\\ }
|
|
3107
3192
|
\\ }
|
|
3108
3193
|
\\ }
|
|
3109
3194
|
\\ } else if (app_info.main_window.restore_state) {
|
|
3110
3195
|
\\ if (store.loadWindow(app_info.main_window.label, &buffers.read) catch null) |saved| {
|
|
3111
3196
|
\\ app_info.main_window.default_frame = saved.frame;
|
|
3197
|
+
\\ app_info.main_window.initial_placement = .restored;
|
|
3112
3198
|
\\ }
|
|
3113
3199
|
\\ }
|
|
3114
3200
|
\\ return store;
|
|
@@ -4047,7 +4133,10 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4047
4133
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "runner_mod.addImport(\"relational_migrations\", migrations_mod)") != null);
|
|
4048
4134
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "NSMicrophoneUsageDescription") != null);
|
|
4049
4135
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "NSAudioCaptureUsageDescription") != null);
|
|
4050
|
-
try std.testing.expect(std.mem.
|
|
4136
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dock_visible: bool = true") != null);
|
|
4137
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, ".dock_visible = raw.dock_visible") != null);
|
|
4138
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "LSUIElement") != null);
|
|
4139
|
+
try std.testing.expect(std.mem.count(u8, build_zig_text, "addMacosInfoPlist(b, ") == 2);
|
|
4051
4140
|
// The generated graph carries the whole web-layer feature: the
|
|
4052
4141
|
// override option, the app.zon inference with its conflict panic,
|
|
4053
4142
|
// the option handed to the runner, and the conditional WebView2
|
|
@@ -4116,6 +4205,8 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4116
4205
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestWindowOptions") != null);
|
|
4117
4206
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.windows = windows") != null);
|
|
4118
4207
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "for (restored_windows, 0..)") != null);
|
|
4208
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "window.initial_placement = .restored") != null);
|
|
4209
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "app_info.main_window.initial_placement = .restored") != null);
|
|
4119
4210
|
// The generated manifestWindow must thread every declarable window
|
|
4120
4211
|
// option into WindowOptions — a dropped field is a silent no-op for
|
|
4121
4212
|
// every `native create` app (the manifest accepts the declaration,
|
|
@@ -4124,6 +4215,7 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4124
4215
|
// .hide window with no tray to bring it back must fail the build,
|
|
4125
4216
|
// not strand a hidden window at runtime).
|
|
4126
4217
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".restore_policy = windowRestorePolicy(window)") != null);
|
|
4218
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".initial_placement = if (windowHasExplicitOrigin(window)) .explicit else .default") != null);
|
|
4127
4219
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".titlebar = windowTitlebarStyle(window)") != null);
|
|
4128
4220
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_width = windowMinSize(window, \"min_width\")") != null);
|
|
4129
4221
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_height = windowMinSize(window, \"min_height\")") != null);
|
|
@@ -4132,10 +4224,14 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4132
4224
|
// The windows-conditional twin: `.hide` hides the taskbar entry and
|
|
4133
4225
|
// windows has no dock-reopen path, so the declaration requires the
|
|
4134
4226
|
// "tray" capability (the status item IS the re-show affordance).
|
|
4135
|
-
// macOS
|
|
4227
|
+
// macOS regular apps have the Dock reopen path; accessory apps are
|
|
4228
|
+
// separately required to declare a tray by manifestDockVisible.
|
|
4136
4229
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "close_policy \\\"hide\\\" on windows requires the \\\"tray\\\" capability") != null);
|
|
4137
4230
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestDeclaresTrayCapability()") != null);
|
|
4138
4231
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".declares_tray = manifestDeclaresTrayCapability()") != null);
|
|
4232
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestDockVisible()") != null);
|
|
4233
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".dock_visible = manifestDockVisible()") != null);
|
|
4234
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "dock_visible = false requires the \\\"tray\\\" capability") != null);
|
|
4139
4235
|
// The scene-first twin: an app.zon that declares its one window under
|
|
4140
4236
|
// `.shell.windows` (the default `native init` shape) hits the
|
|
4141
4237
|
// windows.len == 0 branch, and the startup window's host-create state
|
|
@@ -4147,6 +4243,14 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4147
4243
|
// shell path carries the same Linux comptime refusal pinned above.
|
|
4148
4244
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.titlebar = manifestShellStartupTitlebar()") != null);
|
|
4149
4245
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.resizable = manifestShellStartupResizable()") != null);
|
|
4246
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.default_frame = manifestShellStartupFrame(info.main_window.default_frame)") != null);
|
|
4247
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "windowFloatFallback(window, \"x\", fallback.x)") != null);
|
|
4248
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.restore_state = manifestShellStartupRestoreState(info.main_window.restore_state)") != null);
|
|
4249
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "if (comptime @hasField(@TypeOf(window), \"restore_state\")) return window.restore_state") != null);
|
|
4250
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.restore_policy = manifestShellStartupRestorePolicy(info.main_window.restore_policy)") != null);
|
|
4251
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.initial_placement = manifestShellStartupInitialPlacement(info.main_window.initial_placement)") != null);
|
|
4252
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "if (comptime !@hasField(@TypeOf(window), \"restore_policy\")) return fallback") != null);
|
|
4253
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "return if (windowHasExplicitOrigin(shell.windows[0])) .explicit else fallback") != null);
|
|
4150
4254
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.show = manifestShellStartupShowMode()") != null);
|
|
4151
4255
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_width = manifestShellStartupMinSize(\"min_width\")") != null);
|
|
4152
4256
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_height = manifestShellStartupMinSize(\"min_height\")") != null);
|
|
@@ -4158,6 +4262,12 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
4158
4262
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "defer std.heap.page_allocator.destroy(runtime)") != null);
|
|
4159
4263
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "native_sdk.Runtime.initAt(runtime, .{") != null);
|
|
4160
4264
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "Runtime.init(.{") == null);
|
|
4265
|
+
// Every generated desktop runner freezes the app.zon registered-image
|
|
4266
|
+
// budget into Runtime options, with a compatibility fallback for
|
|
4267
|
+
// manifests generated before the images block existed.
|
|
4268
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestImagePixelBudget() usize") != null);
|
|
4269
|
+
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@hasField(@TypeOf(app_manifest), \"images\")") != null);
|
|
4270
|
+
try std.testing.expectEqual(@as(usize, 4), std.mem.count(u8, runner_zig_text, ".max_image_pixel_bytes = manifestImagePixelBudget(),"));
|
|
4161
4271
|
// The generated runner consumes the same web-layer contract: the
|
|
4162
4272
|
// shared inference for honest menus, the build option threaded into
|
|
4163
4273
|
// every runtime init, and the comptime conflict guard.
|
package/src/tooling/verbs.zig
CHANGED
|
@@ -254,6 +254,7 @@ fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
|
|
|
254
254
|
// SDK builds with Zig 0.16, where std APIs moved, and those failures
|
|
255
255
|
// read "no member named 'cwd'/'init'/'io'" on std types.
|
|
256
256
|
std.debug.print("if the errors above name missing std members, the code may use pre-0.16 Zig idioms - run `native skills get zig` or see https://native-sdk.dev/zig\n", .{});
|
|
257
|
+
std.debug.print("if generated core wiring exceeds Zig's eval branch quota, do not regenerate the TypeScript contract or add an app-side quota - update or report the SDK-generated scan\n", .{});
|
|
257
258
|
return error.ZigBuildFailed;
|
|
258
259
|
}
|
|
259
260
|
|
|
@@ -80,7 +80,7 @@ pub fn parseManifestConfig(allocator: std.mem.Allocator, source: []const u8) !Ma
|
|
|
80
80
|
defer arena.deinit();
|
|
81
81
|
const scratch = arena.allocator();
|
|
82
82
|
const source_z = try scratch.dupeZ(u8, source);
|
|
83
|
-
@setEvalBranchQuota(
|
|
83
|
+
@setEvalBranchQuota(4000);
|
|
84
84
|
const raw = try std.zon.parse.fromSliceAlloc(raw_manifest.RawManifest, scratch, source_z, null, .{});
|
|
85
85
|
return .{
|
|
86
86
|
.web_engine = try allocator.dupe(u8, raw.web_engine),
|
package/tools/corewire/emit.zig
CHANGED
|
@@ -42,17 +42,31 @@ const Sidecar = sidecar_mod.Sidecar;
|
|
|
42
42
|
const TypeRef = sidecar_mod.TypeRef;
|
|
43
43
|
const Payload = sidecar_mod.Payload;
|
|
44
44
|
|
|
45
|
-
///
|
|
45
|
+
/// Comptime string scans pay for every arm and every byte in its name.
|
|
46
|
+
/// Keep the generated consistency fence independent of Zig's default
|
|
47
|
+
/// 1000-backwards-branch quota: the sidecar admits 256 arms, and long legal
|
|
48
|
+
/// TypeScript identifiers must remain legal here too. The fixed floor covers
|
|
49
|
+
/// the surrounding reflection; the linear terms leave generous headroom over
|
|
50
|
+
/// `std.mem.eql`'s scalar comptime path.
|
|
51
|
+
fn msgTagConsistencyQuota(arms: []const sidecar_mod.MsgArm) u32 {
|
|
52
|
+
var name_bytes: u64 = 0;
|
|
53
|
+
for (arms) |arm| name_bytes += arm.name.len;
|
|
54
|
+
const quota: u64 = 100_000 + @as(u64, arms.len) * 1_024 + name_bytes * 256;
|
|
55
|
+
return @intCast(@min(quota, std.math.maxInt(u32)));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// The thirteen text-input event tags the markup engines recognize
|
|
46
59
|
/// structurally; a union payload carrying exactly these dispatches
|
|
47
60
|
/// through the ABI's text_input entry.
|
|
48
61
|
const text_input_event_tags = [_][]const u8{
|
|
49
|
-
"insert_text", "delete_backward",
|
|
50
|
-
"delete_word_forward", "
|
|
51
|
-
"
|
|
62
|
+
"insert_text", "delete_backward", "delete_forward", "delete_word_backward",
|
|
63
|
+
"delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
|
|
64
|
+
"move_caret", "set_selection", "set_composition", "commit_composition",
|
|
65
|
+
"cancel_composition",
|
|
52
66
|
};
|
|
53
67
|
|
|
54
68
|
/// Whether a union payload declares the text-input event shape the markup
|
|
55
|
-
/// engines route through the dedicated ABI entry: exactly the
|
|
69
|
+
/// engines route through the dedicated ABI entry: exactly the thirteen tags,
|
|
56
70
|
/// with the same structural payload vocabulary. This is public because the
|
|
57
71
|
/// generated facade must make the identical decision when selecting the one
|
|
58
72
|
/// sentinel-saturating decoder; one contract cannot have two recognizers.
|
|
@@ -883,6 +897,7 @@ const Emitter = struct {
|
|
|
883
897
|
}
|
|
884
898
|
|
|
885
899
|
fn tagTable(self: *Emitter) Error!void {
|
|
900
|
+
const consistency_quota = msgTagConsistencyQuota(self.sidecar.msg.arms);
|
|
886
901
|
try self.raw(
|
|
887
902
|
\\
|
|
888
903
|
\\/// Declaration-order wire tags: the arm's index in this table IS
|
|
@@ -898,16 +913,17 @@ const Emitter = struct {
|
|
|
898
913
|
try self.print(
|
|
899
914
|
\\
|
|
900
915
|
\\comptime {{
|
|
916
|
+
\\ @setEvalBranchQuota({d});
|
|
901
917
|
\\ // The union and the tag table are emitted from one arm list;
|
|
902
918
|
\\ // hold them equal anyway so a hand edit cannot skew dispatch.
|
|
903
919
|
\\ const fields = @typeInfo({f}).@"union".fields;
|
|
904
|
-
\\ if (fields.len != msg_tags.len) @compileError("core_shim:
|
|
920
|
+
\\ if (fields.len != msg_tags.len) @compileError("core_shim: Msg arm count does not match msg_tags");
|
|
905
921
|
\\ for (fields, msg_tags) |field, tag_name| {{
|
|
906
|
-
\\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim:
|
|
922
|
+
\\ if (!std.mem.eql(u8, field.name, tag_name)) @compileError("core_shim: Msg arm names do not match msg_tags");
|
|
907
923
|
\\ }}
|
|
908
924
|
\\}}
|
|
909
925
|
\\
|
|
910
|
-
, .{ident(self.sidecar.msg.name)});
|
|
926
|
+
, .{ consistency_quota, ident(self.sidecar.msg.name) });
|
|
911
927
|
}
|
|
912
928
|
|
|
913
929
|
// --------------------------------------------------- entry points
|
|
@@ -1852,6 +1868,8 @@ test "u64 attestations on selection bounds are accepted (the host supplies unsig
|
|
|
1852
1868
|
\\ {"name": "delete_forward", "payload": {"kind": "void"}},
|
|
1853
1869
|
\\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
|
|
1854
1870
|
\\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
|
|
1871
|
+
\\ {"name": "delete_to_start", "payload": {"kind": "void"}},
|
|
1872
|
+
\\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
|
|
1855
1873
|
\\ {"name": "clear", "payload": {"kind": "void"}},
|
|
1856
1874
|
\\ {"name": "move_caret", "payload": {"kind": "value", "name": "Move"}},
|
|
1857
1875
|
\\ {"name": "set_selection", "payload": {"kind": "value", "name": "Sel"}},
|
|
@@ -2210,14 +2228,15 @@ test "a text-input-named union without the payload shapes rides the record entry
|
|
|
2210
2228
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
2211
2229
|
defer arena_state.deinit();
|
|
2212
2230
|
const arena = arena_state.allocator();
|
|
2213
|
-
//
|
|
2231
|
+
// Thirteen right names, wrong insert_text payload (void): the markup
|
|
2214
2232
|
// predicate would not bind this as text input, so dispatch must
|
|
2215
2233
|
// not route it to the text_input entry either.
|
|
2216
2234
|
var arms: std.ArrayListUnmanaged(u8) = .empty;
|
|
2217
2235
|
const tags = [_][]const u8{
|
|
2218
|
-
"insert_text", "delete_backward",
|
|
2219
|
-
"delete_word_forward", "
|
|
2220
|
-
"
|
|
2236
|
+
"insert_text", "delete_backward", "delete_forward", "delete_word_backward",
|
|
2237
|
+
"delete_word_forward", "delete_to_start", "delete_to_line_start", "clear",
|
|
2238
|
+
"move_caret", "set_selection", "set_composition", "commit_composition",
|
|
2239
|
+
"cancel_composition",
|
|
2221
2240
|
};
|
|
2222
2241
|
for (tags, 0..) |tag, index| {
|
|
2223
2242
|
if (index > 0) try arms.appendSlice(arena, ", ");
|
|
@@ -2101,14 +2101,24 @@ const FacadeEmitter = struct {
|
|
|
2101
2101
|
},
|
|
2102
2102
|
.bytes => {
|
|
2103
2103
|
self.use(.w_bytes);
|
|
2104
|
-
|
|
2104
|
+
if (self.isThemeStateAccent(container, member)) {
|
|
2105
|
+
// ThemeState.accent is author-facing `string` (the
|
|
2106
|
+
// ergonomic "#rrggbb" API) but the core ABI's one text
|
|
2107
|
+
// representation is bytes. The contract intentionally
|
|
2108
|
+
// reflects strings as bytes; bridge this one exact
|
|
2109
|
+
// launcher record at the generated boundary.
|
|
2110
|
+
self.use(.utf8_text);
|
|
2111
|
+
try self.print("{s}nscfWBytes(sink, nscfUtf8TextBytes({s}));\n", .{ pad, expr });
|
|
2112
|
+
} else {
|
|
2113
|
+
try self.print("{s}nscfWBytes(sink, {s});\n", .{ pad, expr });
|
|
2114
|
+
}
|
|
2105
2115
|
},
|
|
2106
2116
|
.void => {},
|
|
2107
2117
|
.optional => |inner| {
|
|
2108
2118
|
self.use(.w_bool);
|
|
2109
2119
|
const temp = try std.fmt.allocPrint(self.arena, "nscfOpt{d}", .{self.temp_counter});
|
|
2110
2120
|
self.temp_counter += 1;
|
|
2111
|
-
try self.print("{s}const {s} = {s};\n{s}if ({s} === null) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, pad, pad, pad });
|
|
2121
|
+
try self.print("{s}const {s} = {s};\n{s}if ({s} === null || {s} === undefined) {{\n{s} nscfWBool(sink, false);\n{s}}} else {{\n{s} nscfWBool(sink, true);\n", .{ pad, temp, expr, pad, temp, temp, pad, pad, pad });
|
|
2112
2122
|
try self.fieldWriteStatements(inner.*, temp, container, member, depth + 1);
|
|
2113
2123
|
try self.print("{s}}}\n", .{pad});
|
|
2114
2124
|
},
|
|
@@ -2145,6 +2155,18 @@ const FacadeEmitter = struct {
|
|
|
2145
2155
|
}
|
|
2146
2156
|
}
|
|
2147
2157
|
|
|
2158
|
+
fn isThemeStateAccent(self: *FacadeEmitter, container: []const u8, member: []const u8) bool {
|
|
2159
|
+
if (!std.mem.eql(u8, member, "accent")) return false;
|
|
2160
|
+
for (self.sidecar.model_helpers) |helper| {
|
|
2161
|
+
if (!std.mem.eql(u8, helper.name, "themeState")) continue;
|
|
2162
|
+
return switch (helper.returns) {
|
|
2163
|
+
.node, .value => |name| std.mem.eql(u8, name, container),
|
|
2164
|
+
else => false,
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2148
2170
|
fn recordWriter(self: *FacadeEmitter, name: []const u8) Error!void {
|
|
2149
2171
|
const entry = sidecar_mod.findStruct(self.sidecar.types, name).?;
|
|
2150
2172
|
self.use(.sink);
|
|
@@ -4004,6 +4026,37 @@ test "helpers wrap in declaration order with classed-return proofs" {
|
|
|
4004
4026
|
try testing.expect(std.mem.indexOf(u8, generated, "nscfWI64(sink, nscfValue);") != null);
|
|
4005
4027
|
}
|
|
4006
4028
|
|
|
4029
|
+
test "themeState helper encodes omitted fields and UTF-8 string accent" {
|
|
4030
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
4031
|
+
defer arena_state.deinit();
|
|
4032
|
+
const arena = arena_state.allocator();
|
|
4033
|
+
var source = try std.mem.replaceOwned(
|
|
4034
|
+
u8,
|
|
4035
|
+
arena,
|
|
4036
|
+
sidecar_mod.minimal_valid_json,
|
|
4037
|
+
"\"structs\": [",
|
|
4038
|
+
"\"structs\": [\n {\"name\": \"ThemeState\", \"origin\": \"sdk/events.ts\", \"fields\": [{\"name\": \"pack\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStatePack\"}}}, {\"name\": \"colorScheme\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"enum\", \"name\": \"ThemeStateColorScheme\"}}}, {\"name\": \"accent\", \"type\": {\"kind\": \"optional\", \"inner\": {\"kind\": \"bytes\"}}}] },",
|
|
4039
|
+
);
|
|
4040
|
+
source = try std.mem.replaceOwned(
|
|
4041
|
+
u8,
|
|
4042
|
+
arena,
|
|
4043
|
+
source,
|
|
4044
|
+
"\"enums\": []",
|
|
4045
|
+
"\"enums\": [{\"name\": \"ThemeStatePack\", \"origin\": \"sdk/events.ts\", \"members\": [\"house\", \"geist\"]}, {\"name\": \"ThemeStateColorScheme\", \"origin\": \"sdk/events.ts\", \"members\": [\"light\", \"dark\", \"system\"]}]",
|
|
4046
|
+
);
|
|
4047
|
+
source = try std.mem.replaceOwned(
|
|
4048
|
+
u8,
|
|
4049
|
+
arena,
|
|
4050
|
+
source,
|
|
4051
|
+
"\"model_helpers\": []",
|
|
4052
|
+
"\"model_helpers\": [{\"name\": \"themeState\", \"params\": [], \"returns\": {\"kind\": \"value\", \"name\": \"ThemeState\"}, \"arena\": false}]",
|
|
4053
|
+
);
|
|
4054
|
+
const generated = try facadeFromJson(arena, source);
|
|
4055
|
+
try testing.expect(std.mem.indexOf(u8, generated, "=== null ||") != null);
|
|
4056
|
+
try testing.expect(std.mem.indexOf(u8, generated, "=== undefined") != null);
|
|
4057
|
+
try testing.expect(std.mem.indexOf(u8, generated, "nscfWBytes(sink, nscfUtf8TextBytes(") != null);
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4007
4060
|
test "nullable integer helper returns prove their present branch" {
|
|
4008
4061
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
4009
4062
|
defer arena_state.deinit();
|
|
@@ -4424,6 +4477,8 @@ test "text-input selection saturates signed and unsigned select-all sentinels" {
|
|
|
4424
4477
|
\\ {"name": "delete_forward", "payload": {"kind": "void"}},
|
|
4425
4478
|
\\ {"name": "delete_word_backward", "payload": {"kind": "void"}},
|
|
4426
4479
|
\\ {"name": "delete_word_forward", "payload": {"kind": "void"}},
|
|
4480
|
+
\\ {"name": "delete_to_start", "payload": {"kind": "void"}},
|
|
4481
|
+
\\ {"name": "delete_to_line_start", "payload": {"kind": "void"}},
|
|
4427
4482
|
\\ {"name": "clear", "payload": {"kind": "void"}},
|
|
4428
4483
|
\\ {"name": "move_caret", "member": "move", "payload": {"kind": "value", "name": "Move"}},
|
|
4429
4484
|
\\ {"name": "set_selection", "member": "selection", "payload": {"kind": "value", "name": "Sel"}},
|
|
@@ -92,6 +92,24 @@ var model_arenas = [2]std.heap.ArenaAllocator{
|
|
|
92
92
|
};
|
|
93
93
|
var model_arena_index: u1 = 0;
|
|
94
94
|
|
|
95
|
+
/// Quota for one comptime reflection pass over a record/union/enum. Canonical
|
|
96
|
+
/// encoding specializes over sidecar-shaped types, whose legal 256-arm unions
|
|
97
|
+
/// and long authored names can outrun Zig's default quota while resolving an
|
|
98
|
+
/// arm index. Scale with both entries and identifier bytes so app code never
|
|
99
|
+
/// has to raise a quota for generated shim work.
|
|
100
|
+
fn typeScanQuota(comptime T: type) u32 {
|
|
101
|
+
const fields = switch (@typeInfo(T)) {
|
|
102
|
+
.@"struct" => |info| info.fields,
|
|
103
|
+
.@"union" => |info| info.fields,
|
|
104
|
+
.@"enum" => |info| info.fields,
|
|
105
|
+
else => return 2_000,
|
|
106
|
+
};
|
|
107
|
+
var name_bytes: u64 = 0;
|
|
108
|
+
for (fields) |field| name_bytes += field.name.len;
|
|
109
|
+
const quota: u64 = 100_000 + @as(u64, fields.len) * 1_024 + name_bytes * 256;
|
|
110
|
+
return @intCast(@min(quota, std.math.maxInt(u32)));
|
|
111
|
+
}
|
|
112
|
+
|
|
95
113
|
/// Decode a committed-model snapshot into a fresh mirror root. The
|
|
96
114
|
/// PREVIOUS decode's root stays valid until the decode after this one;
|
|
97
115
|
/// anything older is gone (the host holds exactly one committed root at
|
|
@@ -116,6 +134,7 @@ pub fn encodeAlloc(comptime T: type, value: T, allocator: std.mem.Allocator) []c
|
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
fn encodeInto(comptime T: type, value: T, allocator: std.mem.Allocator, out: *std.ArrayListUnmanaged(u8)) error{OutOfMemory}!void {
|
|
137
|
+
@setEvalBranchQuota(comptime typeScanQuota(T));
|
|
119
138
|
switch (@typeInfo(T)) {
|
|
120
139
|
.bool => try out.append(allocator, @intFromBool(value)),
|
|
121
140
|
.int => {
|
|
@@ -220,6 +239,7 @@ pub const Reader = struct {
|
|
|
220
239
|
/// records and slices into `allocator` (the shim frame arena in the
|
|
221
240
|
/// dispatch path).
|
|
222
241
|
pub fn decode(comptime T: type, reader: *Reader, allocator: std.mem.Allocator) T {
|
|
242
|
+
@setEvalBranchQuota(comptime typeScanQuota(T));
|
|
223
243
|
switch (@typeInfo(T)) {
|
|
224
244
|
.bool => {
|
|
225
245
|
const raw = reader.take(1)[0];
|