@native-sdk/cli 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
@@ -1466,6 +1466,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1466
1466
  \\ const exe = b.addExecutable(.{
1467
1467
  \\ .name = app_exe_name,
1468
1468
  \\ .root_module = app_mod,
1469
+ \\ // Zig 0.16.0's self-hosted x86_64 backend (the Debug default)
1470
+ \\ // miscompiles the SysV C calling convention for the long
1471
+ \\ // mixed-argument signatures the platform hosts use, shifting
1472
+ \\ // stack-passed pointers by one slot (a Debug dev run on
1473
+ \\ // x86_64 Linux crashes creating its first shell view). Force
1474
+ \\ // LLVM there, mirroring the Native SDK build graph; Release
1475
+ \\ // modes already use LLVM, so only Debug changes.
1476
+ \\ .use_llvm = useLlvmWorkaround(target),
1469
1477
  \\ });
1470
1478
  \\ // Windows subsystem posture (mirrors the Native SDK build graph):
1471
1479
  \\ // release-shaped exes are GUI-subsystem so the app never flashes a
@@ -1519,6 +1527,9 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1519
1527
  \\ const built = b.addExecutable(.{
1520
1528
  \\ .name = app_exe_name,
1521
1529
  \\ .root_module = package_app_mod,
1530
+ \\ // Same self-hosted x86_64 workaround as the dev exe above
1531
+ \\ // (only reachable when -Doptimize pins Debug for both roles).
1532
+ \\ .use_llvm = useLlvmWorkaround(target),
1522
1533
  \\ });
1523
1534
  \\ // Same subsystem posture as the dev exe above, keyed on this
1524
1535
  \\ // exe's own mode: release-shaped Windows exes are GUI-subsystem.
@@ -1572,6 +1583,18 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1572
1583
  \\ test_step.dependOn(&b.addRunArtifact(tests).step);
1573
1584
  \\}
1574
1585
  \\
1586
+ \\// Zig 0.16.0's self-hosted x86_64 backend miscompiles the SysV C
1587
+ \\// calling convention for long mixed int/pointer/double signatures
1588
+ \\// (the platform hosts' view-create calls) and f32-heavy ones (the
1589
+ \\// embed viewport ABI): stack-passed arguments arrive shifted, so a
1590
+ \\// Debug x86_64 build crashes at the first platform call that passes
1591
+ \\// strings on the stack. Force the LLVM backend on x86_64 until the
1592
+ \\// upstream backend is fixed; Release modes already default to LLVM,
1593
+ \\// so this only changes Debug builds.
1594
+ \\fn useLlvmWorkaround(target: std.Build.ResolvedTarget) ?bool {
1595
+ \\ return if (target.result.cpu.arch == .x86_64) true else null;
1596
+ \\}
1597
+ \\
1575
1598
  \\// Resolve the optimize mode for one exe role (mirrors the Native SDK
1576
1599
  \\// build graph): an explicit -Doptimize wins for every role, --release
1577
1600
  \\// resolves through zig's release_mode, and only when neither was
@@ -1703,6 +1726,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1703
1726
  \\ }
1704
1727
  \\ app_mod.linkFramework("AppKit", .{});
1705
1728
  \\ app_mod.linkFramework("AVFoundation", .{});
1729
+ \\ app_mod.linkFramework("CoreVideo", .{});
1706
1730
  \\ app_mod.linkFramework("MediaToolbox", .{});
1707
1731
  \\ app_mod.linkFramework("Accelerate", .{});
1708
1732
  \\ app_mod.linkFramework("Foundation", .{});
@@ -1728,7 +1752,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1728
1752
  \\ // the layer stays out even on machines where the
1729
1753
  \\ // development package is installed — libwebkitgtk is
1730
1754
  \\ // neither linked nor required at runtime, and the
1731
- \\ // executable carries no WebKit reference at all.
1755
+ \\ // executable carries no WebKit reference at all. This
1756
+ \\ // is the expected, configured state of every canvas
1757
+ \\ // app on Linux, so the stub compile is deliberately
1758
+ \\ // silent — no build note, no compiler diagnostic (the
1759
+ \\ // host's seam comment explains why even an
1760
+ \\ // informational pragma is dangerous); a stubbed host
1761
+ \\ // teaches at runtime by reporting WebViewNotFound the
1762
+ \\ // moment an app actually uses a WebView.
1732
1763
  \\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
1733
1764
  \\ app_mod.linkSystemLibrary("gtk4", .{});
1734
1765
  \\ app_mod.linkSystemLibrary("dl", .{});
@@ -1774,6 +1805,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1774
1805
  \\ // headers are reachable through the system include paths
1775
1806
  \\ // — no WebView2Loader.dll is installed or path-wired,
1776
1807
  \\ // and the executable carries no reference to it at all.
1808
+ \\ // This is the expected, configured state of every
1809
+ \\ // canvas app on Windows, so the stub compile is
1810
+ \\ // deliberately silent — no build note, no compiler
1811
+ \\ // diagnostic (the host's seam comment explains why
1812
+ \\ // even an informational pragma is dangerous); a
1813
+ \\ // stubbed host teaches at runtime by reporting
1814
+ \\ // WebViewNotFound the moment an app actually uses a
1815
+ \\ // WebView.
1777
1816
  \\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
1778
1817
  \\ },
1779
1818
  \\ .chromium => {
@@ -2183,6 +2222,7 @@ fn runnerZig() []const u8 {
2183
2222
  \\ var info: native_sdk.AppInfo = .{
2184
2223
  \\ .app_name = self.app_name,
2185
2224
  \\ .has_web_content = manifestHasWebContent(),
2225
+ \\ .declares_tray = manifestDeclaresTrayCapability(),
2186
2226
  \\ .window_title = self.window_title,
2187
2227
  \\ .bundle_id = self.bundle_id,
2188
2228
  \\ .icon_path = self.icon_path,
@@ -2191,6 +2231,26 @@ fn runnerZig() []const u8 {
2191
2231
  \\ if (windows.len > 0) {
2192
2232
  \\ info.main_window = windows[0];
2193
2233
  \\ info.windows = windows;
2234
+ \\ } else {
2235
+ \\ // Scene-first apps declare their one window under
2236
+ \\ // `.shell.windows` — the startup window the host creates
2237
+ \\ // adopts that declaration when the scene loads, but its
2238
+ \\ // CHROME is fixed at create time, so the manifest's
2239
+ \\ // titlebar style threads through here. Same for visibility:
2240
+ \\ // a canvas-first startup window is created ordered-out and
2241
+ \\ // shown after its first canvas frame presents, so launch
2242
+ \\ // never flashes a blank window.
2243
+ \\ info.main_window.titlebar = manifestShellStartupTitlebar();
2244
+ \\ info.main_window.resizable = manifestShellStartupResizable();
2245
+ \\ info.main_window.show = manifestShellStartupShowMode();
2246
+ \\ // Min-size floors ride the create call like the titlebar:
2247
+ \\ // the scene re-applies size/title later, but the window's
2248
+ \\ // enforced floor is host state from the first frame on.
2249
+ \\ info.main_window.min_width = manifestShellStartupMinSize("min_width");
2250
+ \\ info.main_window.min_height = manifestShellStartupMinSize("min_height");
2251
+ \\ // Close handling is host window state like the titlebar:
2252
+ \\ // the manifest's declaration rides the host create.
2253
+ \\ info.main_window.close_policy = manifestShellStartupClosePolicy();
2194
2254
  \\ }
2195
2255
  \\ return info;
2196
2256
  \\ }
@@ -2314,6 +2374,10 @@ fn runnerZig() []const u8 {
2314
2374
  \\ .resizable = windowBool(window, "resizable", true),
2315
2375
  \\ .restore_state = windowBool(window, "restore_state", true),
2316
2376
  \\ .restore_policy = windowRestorePolicy(window),
2377
+ \\ .titlebar = windowTitlebarStyle(window),
2378
+ \\ .min_width = windowMinSize(window, "min_width"),
2379
+ \\ .min_height = windowMinSize(window, "min_height"),
2380
+ \\ .close_policy = windowClosePolicy(window),
2317
2381
  \\ };
2318
2382
  \\}
2319
2383
  \\
@@ -2347,6 +2411,125 @@ fn runnerZig() []const u8 {
2347
2411
  \\ @compileError("unknown app.zon window restore_policy");
2348
2412
  \\}
2349
2413
  \\
2414
+ \\/// Window-enforced content min-size floor from app.zon. Validated at
2415
+ \\/// comptime like the titlebar style: a negative floor is an authoring
2416
+ \\/// error, not a silent clamp.
2417
+ \\fn windowMinSize(comptime window: anytype, comptime field: []const u8) f32 {
2418
+ \\ const value: f32 = comptime windowFloat(window, field, 0);
2419
+ \\ comptime {
2420
+ \\ if (!(value >= 0)) @compileError("app.zon window " ++ field ++ " must be non-negative");
2421
+ \\ }
2422
+ \\ return value;
2423
+ \\}
2424
+ \\
2425
+ \\fn windowTitlebarStyle(comptime window: anytype) native_sdk.WindowTitlebarStyle {
2426
+ \\ if (comptime !@hasField(@TypeOf(window), "titlebar")) return .standard;
2427
+ \\ const value = window.titlebar;
2428
+ \\ if (comptime std.mem.eql(u8, value, "standard")) return .standard;
2429
+ \\ if (comptime std.mem.eql(u8, value, "hidden_inset")) return .hidden_inset;
2430
+ \\ if (comptime std.mem.eql(u8, value, "hidden_inset_tall")) return .hidden_inset_tall;
2431
+ \\ if (comptime std.mem.eql(u8, value, "chromeless")) return .chromeless;
2432
+ \\ @compileError("unknown app.zon window titlebar style");
2433
+ \\}
2434
+ \\
2435
+ \\/// The startup window's titlebar style for scene-first apps: app.zon's
2436
+ \\/// `.shell.windows[0].titlebar`. Chrome cannot change after the host
2437
+ \\/// creates the window, so it must ride the create call — unlike
2438
+ \\/// size/title, which the loading scene re-applies.
2439
+ \\fn manifestShellStartupTitlebar() native_sdk.WindowTitlebarStyle {
2440
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .standard;
2441
+ \\ const shell = app_manifest.shell;
2442
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .standard;
2443
+ \\ if (comptime shell.windows.len == 0) return .standard;
2444
+ \\ return windowTitlebarStyle(shell.windows[0]);
2445
+ \\}
2446
+ \\
2447
+ \\/// The startup window's resizability for scene-first apps: like the
2448
+ \\/// titlebar style, resizable is window chrome fixed at create time.
2449
+ \\fn manifestShellStartupResizable() bool {
2450
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return true;
2451
+ \\ const shell = app_manifest.shell;
2452
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return true;
2453
+ \\ if (comptime shell.windows.len == 0) return true;
2454
+ \\ return windowBool(shell.windows[0], "resizable", true);
2455
+ \\}
2456
+ \\
2457
+ \\/// The startup window's close policy for scene-first apps: app.zon's
2458
+ \\/// `.shell.windows[0].close_policy`. Like the titlebar, close handling
2459
+ \\/// is host window state fixed at create time.
2460
+ \\fn manifestShellStartupClosePolicy() native_sdk.WindowClosePolicy {
2461
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .quit;
2462
+ \\ const shell = app_manifest.shell;
2463
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .quit;
2464
+ \\ if (comptime shell.windows.len == 0) return .quit;
2465
+ \\ return windowClosePolicy(shell.windows[0]);
2466
+ \\}
2467
+ \\
2468
+ \\/// The startup window's content min-size floor for scene-first apps:
2469
+ \\/// app.zon's `.shell.windows[0].min_width`/`.min_height` (0 = none).
2470
+ \\fn manifestShellStartupMinSize(comptime field: []const u8) f32 {
2471
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return 0;
2472
+ \\ const shell = app_manifest.shell;
2473
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return 0;
2474
+ \\ if (comptime shell.windows.len == 0) return 0;
2475
+ \\ return windowMinSize(shell.windows[0], field);
2476
+ \\}
2477
+ \\
2478
+ \\/// Present-before-show for the STARTUP window: when app.zon's first
2479
+ \\/// shell window hosts a canvas (`gpu_surface` view), the host creates
2480
+ \\/// it ordered-out and it becomes visible after the first canvas frame
2481
+ \\/// presents. Webview-first startup windows keep immediate visibility.
2482
+ \\fn manifestShellStartupShowMode() native_sdk.WindowShowMode {
2483
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .immediate;
2484
+ \\ const shell = app_manifest.shell;
2485
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .immediate;
2486
+ \\ if (comptime shell.windows.len == 0) return .immediate;
2487
+ \\ const window = shell.windows[0];
2488
+ \\ if (comptime !@hasField(@TypeOf(window), "views")) return .immediate;
2489
+ \\ inline for (window.views) |view| {
2490
+ \\ if (comptime @hasField(@TypeOf(view), "kind")) {
2491
+ \\ if (comptime std.mem.eql(u8, view.kind, "gpu_surface")) return .on_first_present;
2492
+ \\ }
2493
+ \\ }
2494
+ \\ return .immediate;
2495
+ \\}
2496
+ \\
2497
+ \\/// What the window's close affordance does, from app.zon. `.hide` is
2498
+ \\/// validated against the TARGET platform at comptime: a host with no
2499
+ \\/// affordance to bring a hidden window back (GTK has no status item;
2500
+ \\/// windows without a declared tray, since hiding removes the taskbar
2501
+ \\/// entry and windows has no dock) refuses the declaration here, at
2502
+ \\/// build time, instead of stranding a hidden window at runtime.
2503
+ \\fn windowClosePolicy(comptime window: anytype) native_sdk.WindowClosePolicy {
2504
+ \\ if (comptime !@hasField(@TypeOf(window), "close_policy")) return .quit;
2505
+ \\ const value = window.close_policy;
2506
+ \\ if (comptime std.mem.eql(u8, value, "quit")) return .quit;
2507
+ \\ if (comptime std.mem.eql(u8, value, "hide")) {
2508
+ \\ if (comptime std.mem.eql(u8, build_options.platform, "linux")) {
2509
+ \\ @compileError("app.zon window close_policy \"hide\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \"quit\" (the default), or scope the .hide declaration to macos/windows builds");
2510
+ \\ }
2511
+ \\ if (comptime std.mem.eql(u8, build_options.platform, "windows")) {
2512
+ \\ if (comptime !manifestDeclaresTrayCapability()) {
2513
+ \\ @compileError("app.zon window close_policy \"hide\" on windows requires the \"tray\" capability: hiding removes the taskbar entry and windows has no dock-reopen path, so only a status item (tray) could bring the hidden window back - add \"tray\" to .capabilities and install a status item, or declare \"quit\" (the default); macos needs no capability because the dock reopen path always exists");
2514
+ \\ }
2515
+ \\ }
2516
+ \\ return .hide;
2517
+ \\ }
2518
+ \\ @compileError("unknown app.zon window close_policy - supported values: \"quit\" (close really closes; the default) and \"hide\" (the menu-bar-app shape: close hides the window and the app keeps running)");
2519
+ \\}
2520
+ \\
2521
+ \\/// Whether app.zon declares the "tray" capability — the status item
2522
+ \\/// `.hide` leans on where the OS has no built-in re-show affordance.
2523
+ \\/// Evaluated at comptime over the manifest import, like the web scan.
2524
+ \\fn manifestDeclaresTrayCapability() bool {
2525
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
2526
+ \\ inline for (app_manifest.capabilities) |capability| {
2527
+ \\ const name: []const u8 = capability;
2528
+ \\ if (comptime std.mem.eql(u8, name, "tray")) return true;
2529
+ \\ }
2530
+ \\ return false;
2531
+ \\}
2532
+ \\
2350
2533
  \\fn menuItem(comptime item: anytype) native_sdk.MenuItem {
2351
2534
  \\ return .{
2352
2535
  \\ .label = if (@hasField(@TypeOf(item), "label")) item.label else "",
@@ -2400,7 +2583,12 @@ fn runnerZig() []const u8 {
2400
2583
  \\ var buffers: StateBuffers = undefined;
2401
2584
  \\ var app_info = options.appInfo(&buffers);
2402
2585
  \\ const store = prepareStateStore(init.io, init.environ_map, &app_info, &buffers);
2403
- \\ var null_platform = native_sdk.NullPlatform.initWithOptions(.{}, webEngine(), app_info);
2586
+ \\ // Heap wrapper, latch-gated free: worker threads hold this address
2587
+ \\ // as the channel wake context and an abandoned wake call may
2588
+ \\ // dereference it after this frame unwinds (see
2589
+ \\ // `NullPlatform.createWithOptions`/`destroy`).
2590
+ \\ const null_platform = try native_sdk.NullPlatform.createWithOptions(.{}, webEngine(), app_info);
2591
+ \\ defer null_platform.destroy();
2404
2592
  \\ var trace_sink = StdoutTraceSink{};
2405
2593
  \\ var log_buffers: native_sdk.debug.LogPathBuffers = .{};
2406
2594
  \\ const log_setup = native_sdk.debug.setupLogging(init.io, init.environ_map, app_info.bundle_id, &log_buffers) catch null;
@@ -2449,8 +2637,12 @@ fn runnerZig() []const u8 {
2449
2637
  \\ var buffers: StateBuffers = undefined;
2450
2638
  \\ var app_info = options.appInfo(&buffers);
2451
2639
  \\ const store = prepareStateStore(init.io, init.environ_map, &app_info, &buffers);
2452
- \\ var mac_platform = try native_sdk.platform.macos.MacPlatform.initWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2453
- \\ defer mac_platform.deinit();
2640
+ \\ // Heap wrapper, latch-gated free: worker threads hold this address
2641
+ \\ // as the channel wake context and an abandoned wake call may
2642
+ \\ // dereference it after this frame unwinds (see
2643
+ \\ // `MacPlatform.createWithOptions`/`destroy`).
2644
+ \\ const mac_platform = try native_sdk.platform.macos.MacPlatform.createWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2645
+ \\ defer mac_platform.destroy();
2454
2646
  \\ var trace_sink = StdoutTraceSink{};
2455
2647
  \\ var log_buffers: native_sdk.debug.LogPathBuffers = .{};
2456
2648
  \\ const log_setup = native_sdk.debug.setupLogging(init.io, init.environ_map, app_info.bundle_id, &log_buffers) catch null;
@@ -2499,8 +2691,12 @@ fn runnerZig() []const u8 {
2499
2691
  \\ var buffers: StateBuffers = undefined;
2500
2692
  \\ var app_info = options.appInfo(&buffers);
2501
2693
  \\ const store = prepareStateStore(init.io, init.environ_map, &app_info, &buffers);
2502
- \\ var linux_platform = try native_sdk.platform.linux.LinuxPlatform.initWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2503
- \\ defer linux_platform.deinit();
2694
+ \\ // Heap wrapper, latch-gated free: worker threads hold this address
2695
+ \\ // as the channel wake context and an abandoned wake call may
2696
+ \\ // dereference it after this frame unwinds (see
2697
+ \\ // `LinuxPlatform.createWithOptions`/`destroy`).
2698
+ \\ const linux_platform = try native_sdk.platform.linux.LinuxPlatform.createWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2699
+ \\ defer linux_platform.destroy();
2504
2700
  \\ var trace_sink = StdoutTraceSink{};
2505
2701
  \\ var log_buffers: native_sdk.debug.LogPathBuffers = .{};
2506
2702
  \\ const log_setup = native_sdk.debug.setupLogging(init.io, init.environ_map, app_info.bundle_id, &log_buffers) catch null;
@@ -2549,8 +2745,12 @@ fn runnerZig() []const u8 {
2549
2745
  \\ var buffers: StateBuffers = undefined;
2550
2746
  \\ var app_info = options.appInfo(&buffers);
2551
2747
  \\ const store = prepareStateStore(init.io, init.environ_map, &app_info, &buffers);
2552
- \\ var windows_platform = try native_sdk.platform.windows.WindowsPlatform.initWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2553
- \\ defer windows_platform.deinit();
2748
+ \\ // Heap wrapper, latch-gated free: worker threads hold this address
2749
+ \\ // as the channel wake context and an abandoned wake call may
2750
+ \\ // dereference it after this frame unwinds (see
2751
+ \\ // `WindowsPlatform.createWithOptions`/`destroy`).
2752
+ \\ const windows_platform = try native_sdk.platform.windows.WindowsPlatform.createWithOptions(native_sdk.geometry.SizeF.init(720, 480), webEngine(), app_info);
2753
+ \\ defer windows_platform.destroy();
2554
2754
  \\ var trace_sink = StdoutTraceSink{};
2555
2755
  \\ var log_buffers: native_sdk.debug.LogPathBuffers = .{};
2556
2756
  \\ const log_setup = native_sdk.debug.setupLogging(init.io, init.environ_map, app_info.bundle_id, &log_buffers) catch null;
@@ -3651,6 +3851,42 @@ test "writeDefaultApp emits Vite project files" {
3651
3851
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestWindowOptions") != null);
3652
3852
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.windows = windows") != null);
3653
3853
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "for (restored_windows, 0..)") != null);
3854
+ // The generated manifestWindow must thread every declarable window
3855
+ // option into WindowOptions — a dropped field is a silent no-op for
3856
+ // every `native create` app (the manifest accepts the declaration,
3857
+ // the window ignores it). close_policy shipped with exactly that gap
3858
+ // once; these pins hold the field AND the Linux comptime refusal (a
3859
+ // .hide window with no tray to bring it back must fail the build,
3860
+ // not strand a hidden window at runtime).
3861
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".restore_policy = windowRestorePolicy(window)") != null);
3862
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".titlebar = windowTitlebarStyle(window)") != null);
3863
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_width = windowMinSize(window, \"min_width\")") != null);
3864
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_height = windowMinSize(window, \"min_height\")") != null);
3865
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".close_policy = windowClosePolicy(window)") != null);
3866
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "close_policy \\\"hide\\\" is not supported on linux") != null);
3867
+ // The windows-conditional twin: `.hide` hides the taskbar entry and
3868
+ // windows has no dock-reopen path, so the declaration requires the
3869
+ // "tray" capability (the status item IS the re-show affordance).
3870
+ // macOS stays exempt — the Dock reopen path always exists.
3871
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "close_policy \\\"hide\\\" on windows requires the \\\"tray\\\" capability") != null);
3872
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestDeclaresTrayCapability()") != null);
3873
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".declares_tray = manifestDeclaresTrayCapability()") != null);
3874
+ // The scene-first twin: an app.zon that declares its one window under
3875
+ // `.shell.windows` (the default `native init` shape) hits the
3876
+ // windows.len == 0 branch, and the startup window's host-create state
3877
+ // (chrome, resizability, show mode, min-size floor, close policy)
3878
+ // must thread from the shell declaration exactly like the SDK runner
3879
+ // — a generated runner without this threading silently keeps
3880
+ // quit-on-close (and standard chrome) for every scene-first
3881
+ // manifest. The close-policy helper reuses windowClosePolicy, so the
3882
+ // shell path carries the same Linux comptime refusal pinned above.
3883
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.titlebar = manifestShellStartupTitlebar()") != null);
3884
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.resizable = manifestShellStartupResizable()") != null);
3885
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.show = manifestShellStartupShowMode()") != null);
3886
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_width = manifestShellStartupMinSize(\"min_width\")") != null);
3887
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_height = manifestShellStartupMinSize(\"min_height\")") != null);
3888
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.close_policy = manifestShellStartupClosePolicy()") != null);
3889
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "return windowClosePolicy(shell.windows[0])") != null);
3654
3890
  // The Runtime is multi-megabyte; the generated runner must heap-allocate
3655
3891
  // it and construct in place, never build it by value on the stack.
3656
3892
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "std.heap.page_allocator.create(native_sdk.Runtime)") != null);