@native-sdk/cli 0.5.2 → 0.5.4

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 (123) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +264 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/sdk/events.ts +39 -2
  10. package/packages/core/src/checker.ts +1 -1
  11. package/packages/core/src/emitter.ts +2625 -262
  12. package/packages/core/src/infer.ts +53 -7
  13. package/skill-data/automation/SKILL.md +7 -4
  14. package/skill-data/core/references/app-model-runtime.md +3 -0
  15. package/skill-data/native-ui/SKILL.md +4 -2
  16. package/skill-data/ts-core/SKILL.md +9 -1
  17. package/src/app_runner/root.zig +106 -1
  18. package/src/app_runner/ts_core_main.zig +4 -0
  19. package/src/automation/protocol.zig +20 -1
  20. package/src/embed/host.zig +27 -0
  21. package/src/embed/tests.zig +187 -0
  22. package/src/embed/ui_host.zig +4 -0
  23. package/src/platform/linux/gtk_host.c +112 -3
  24. package/src/platform/linux/root.zig +71 -0
  25. package/src/platform/macos/appkit_host.h +59 -2
  26. package/src/platform/macos/appkit_host.m +663 -34
  27. package/src/platform/macos/cef_host.mm +262 -10
  28. package/src/platform/macos/root.zig +126 -4
  29. package/src/platform/null_platform.zig +298 -5
  30. package/src/platform/null_platform_tests.zig +39 -0
  31. package/src/platform/root.zig +36 -0
  32. package/src/platform/types.zig +247 -8
  33. package/src/platform/windows/root.zig +134 -0
  34. package/src/platform/windows/webview2_host.cpp +152 -40
  35. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  36. package/src/primitives/app_manifest/root.zig +1 -0
  37. package/src/primitives/app_manifest/types.zig +32 -0
  38. package/src/primitives/canvas/chart.zig +7 -7
  39. package/src/primitives/canvas/chart_tests.zig +66 -0
  40. package/src/primitives/canvas/commands.zig +48 -0
  41. package/src/primitives/canvas/events.zig +161 -0
  42. package/src/primitives/canvas/font_ttf.zig +155 -8
  43. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  44. package/src/primitives/canvas/reference.zig +67 -8
  45. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  46. package/src/primitives/canvas/root.zig +25 -0
  47. package/src/primitives/canvas/tests.zig +1 -0
  48. package/src/primitives/canvas/ui.zig +46 -9
  49. package/src/primitives/canvas/ui_markup.zig +82 -34
  50. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  51. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  52. package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
  53. package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
  54. package/src/primitives/canvas/ui_markup_contract.zig +10 -1
  55. package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
  56. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  57. package/src/primitives/canvas/ui_markup_tests.zig +55 -9
  58. package/src/primitives/canvas/ui_markup_view.zig +81 -14
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
  60. package/src/primitives/canvas/ui_schema.zig +29 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  62. package/src/primitives/canvas/ui_tests.zig +31 -0
  63. package/src/primitives/canvas/vector.zig +258 -141
  64. package/src/primitives/canvas/widget_access.zig +1 -1
  65. package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
  66. package/src/primitives/canvas/widget_layout.zig +9 -4
  67. package/src/primitives/canvas/widget_render.zig +78 -40
  68. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  69. package/src/primitives/canvas/widget_semantics.zig +6 -1
  70. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  71. package/src/primitives/canvas/widget_text_input.zig +118 -10
  72. package/src/primitives/canvas/widgets.zig +16 -0
  73. package/src/root.zig +12 -0
  74. package/src/runtime/api.zig +15 -0
  75. package/src/runtime/automation_commands.zig +33 -0
  76. package/src/runtime/automation_widget_dispatch.zig +64 -0
  77. package/src/runtime/bridge_payload.zig +7 -0
  78. package/src/runtime/bridge_responses.zig +5 -0
  79. package/src/runtime/builtin_bridge.zig +9 -4
  80. package/src/runtime/canvas_font_tests.zig +711 -5
  81. package/src/runtime/canvas_fonts.zig +120 -25
  82. package/src/runtime/canvas_frame_helpers.zig +15 -0
  83. package/src/runtime/canvas_image_tests.zig +221 -0
  84. package/src/runtime/canvas_images.zig +78 -19
  85. package/src/runtime/canvas_limits.zig +44 -8
  86. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  87. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  88. package/src/runtime/canvas_widget_events.zig +24 -4
  89. package/src/runtime/canvas_widget_runtime.zig +24 -7
  90. package/src/runtime/canvas_widget_state.zig +6 -1
  91. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  92. package/src/runtime/core.zig +148 -9
  93. package/src/runtime/effects.zig +1664 -43
  94. package/src/runtime/effects_fetch_tests.zig +89 -1
  95. package/src/runtime/effects_file_tests.zig +41 -1
  96. package/src/runtime/effects_image_tests.zig +1304 -0
  97. package/src/runtime/effects_tests.zig +153 -0
  98. package/src/runtime/flow.zig +44 -0
  99. package/src/runtime/gpu_surface_events.zig +7 -0
  100. package/src/runtime/media_surface.zig +726 -0
  101. package/src/runtime/media_surface_tests.zig +1476 -0
  102. package/src/runtime/root.zig +20 -0
  103. package/src/runtime/session_blobs.zig +689 -0
  104. package/src/runtime/session_journal.zig +111 -20
  105. package/src/runtime/session_record.zig +27 -2
  106. package/src/runtime/session_replay.zig +168 -16
  107. package/src/runtime/session_tests.zig +2118 -4
  108. package/src/runtime/shell_layout.zig +7 -0
  109. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  110. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  111. package/src/runtime/tests.zig +3 -0
  112. package/src/runtime/ts_core_host.zig +439 -4
  113. package/src/runtime/ts_core_host_tests.zig +41 -0
  114. package/src/runtime/ts_ui_app.zig +63 -0
  115. package/src/runtime/ui_app.zig +169 -6
  116. package/src/runtime/ui_app_tests.zig +334 -0
  117. package/src/runtime/ui_app_window_tests.zig +468 -0
  118. package/src/runtime/window_command_bridge_tests.zig +117 -0
  119. package/src/runtime/window_storage.zig +32 -0
  120. package/src/runtime/window_views.zig +61 -1
  121. package/src/tooling/manifest.zig +75 -0
  122. package/src/tooling/raw_manifest.zig +2 -0
  123. package/src/tooling/templates.zig +219 -1
@@ -37,6 +37,29 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
37
37
 
38
38
  pub fn focusWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
39
39
  const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
40
+ // Liveness before the platform call, like showWindow: a
41
+ // closed window keeps its table slot until the id or label
42
+ // is re-created, and close clears `hidden` with `open`, so
43
+ // a dead slot would skip the hidden-routing below and reach
44
+ // the platform's focus verb directly — the CEF host retains
45
+ // browser-bearing windows past their close and would order
46
+ // the closed window back front. Dead slots answer
47
+ // WindowNotFound, the runtime's one answer for them.
48
+ if (!self.windows[index].info.open) return error.WindowNotFound;
49
+ // Focus implies visibility: a window hidden by its .hide
50
+ // close policy must leave the hidden state through the REAL
51
+ // show verb before it takes key. The hosts' focus paths
52
+ // order a window forward without touching their
53
+ // policy-hidden bookkeeping (macOS would report hidden=true
54
+ // on a window standing on the glass; Windows never shows an
55
+ // SW_HIDE'd window at all, leaving focused=true on an
56
+ // invisible one), while their show paths clear that
57
+ // bookkeeping and emit the state — and the runtime's
58
+ // showWindow flips its own hidden flag with rollback on
59
+ // platform failure. One rule, at this seam, so every focus
60
+ // ingress (the app verb, the JS bridge's window.focus)
61
+ // resolves hidden-then-focus the same way.
62
+ if (self.windows[index].info.hidden) try self.showWindow(window_id);
40
63
  try self.options.platform.services.focusWindow(window_id);
41
64
  try Self.setFocusedIndex(self, index);
42
65
  self.invalidated = true;
@@ -64,6 +87,14 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
64
87
  }
65
88
  const id = if (options.id != 0) options.id else Self.allocateWindowId(self);
66
89
  try validateWindowFrame(options.default_frame);
90
+ // `.hide` needs a host that can keep a closed-by-the-user
91
+ // window alive and re-show it; refusing here is the loud
92
+ // teaching (GTK: no status item exists to bring the window
93
+ // back, declare .quit — the default — instead). NEVER a
94
+ // silent no-op that strands a hidden window.
95
+ if (options.close_policy == .hide and !self.options.platform.supports(.window_hide_on_close)) {
96
+ return error.UnsupportedWindowClosePolicy;
97
+ }
67
98
  if (Self.findWindowIndexById(self, id) != null) return error.DuplicateWindowId;
68
99
  if (Self.findWindowIndexByLabel(self, label) != null) return error.DuplicateWindowLabel;
69
100
  const index = try Self.reserveWindow(self, id, label, options.title, source, source_reloads_from_app);
@@ -151,6 +182,7 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
151
182
  self.windows[index].info.frame = state.frame;
152
183
  self.windows[index].info.scale_factor = state.scale_factor;
153
184
  self.windows[index].info.open = state.open;
185
+ self.windows[index].info.hidden = state.hidden;
154
186
  if (!self.windows[index].main_frame_set) {
155
187
  self.windows[index].main_frame = geometry.RectF.init(0, 0, state.frame.width, state.frame.height);
156
188
  }
@@ -113,11 +113,19 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
113
113
  // a window that never lost key.
114
114
  const was_open = self.windows[index].info.open;
115
115
  const was_focused = self.windows[index].info.focused;
116
+ // `hidden` clears with `open`: an app-driven close of a
117
+ // policy-hidden window (a menu-bar app tearing down its
118
+ // hidden panel) must not leave {open=false, hidden=true}
119
+ // in the runtime table — the JS bridge exposes hidden, and
120
+ // a closed window is not "hidden", it is gone.
121
+ const was_hidden = self.windows[index].info.hidden;
116
122
  self.windows[index].info.open = false;
117
123
  self.windows[index].info.focused = false;
124
+ self.windows[index].info.hidden = false;
118
125
  self.options.platform.services.closeWindow(window_id) catch |err| {
119
126
  self.windows[index].info.open = was_open;
120
127
  self.windows[index].info.focused = was_focused;
128
+ self.windows[index].info.hidden = was_hidden;
121
129
  return err;
122
130
  };
123
131
  Self.removeWindowRuntimeViews(self, window_id);
@@ -129,10 +137,61 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
129
137
  /// bookkeeping moves: a minimized window stays open and keeps
130
138
  /// its views — it comes back from the Dock/taskbar.
131
139
  pub fn minimizeWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
132
- if (Self.findWindowIndexById(self, window_id) == null) return error.WindowNotFound;
140
+ const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
141
+ // The same liveness gate as showWindow below: a retained
142
+ // closed slot must not reach the platform (the CEF host
143
+ // would genie the retained closed window into the Dock).
144
+ if (!self.windows[index].info.open) return error.WindowNotFound;
133
145
  try self.options.platform.services.minimizeWindow(window_id);
134
146
  }
135
147
 
148
+ /// The real OS show verb: unhide + activate — the counterpart
149
+ /// to a `close_policy = .hide` hide, and what a tray "Open"
150
+ /// action resolves to. Like `closeWindow`, the runtime flag
151
+ /// flips BEFORE the platform call (hosts that emit the frame
152
+ /// event synchronously would echo the same state) and rolls
153
+ /// back on platform failure. A window that was never hidden
154
+ /// just comes to the front.
155
+ pub fn showWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
156
+ const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
157
+ // A closed window keeps its table slot (the id and label
158
+ // release lazily, at the next create), so resolving the id
159
+ // is not liveness: a dead slot must answer WindowNotFound —
160
+ // the same answer every not-open gate in the runtime gives —
161
+ // BEFORE the platform call. The null platform would accept
162
+ // the show and report {open:false, focused:true}; the CEF
163
+ // host retains browser-bearing windows past their close and
164
+ // would visibly re-order one onto the glass.
165
+ if (!self.windows[index].info.open) return error.WindowNotFound;
166
+ const was_hidden = self.windows[index].info.hidden;
167
+ self.windows[index].info.hidden = false;
168
+ self.options.platform.services.showWindow(window_id) catch |err| {
169
+ self.windows[index].info.hidden = was_hidden;
170
+ return err;
171
+ };
172
+ // The contract is show AND activate: every host's show verb
173
+ // makes the window key (makeKeyAndOrderFront / activate), so
174
+ // the runtime table must move focus with it or listWindows
175
+ // and the JS bridge report the shown window unfocused while
176
+ // it stands frontmost on the glass. Same post-success flow
177
+ // as focusWindow — through the setFocusedIndex seam, so the
178
+ // dethroned window's key-loss consequence fires — and only
179
+ // AFTER the platform accepted: a refused show rolls back
180
+ // hidden above and moves no focus.
181
+ try Self.setFocusedIndex(self, index);
182
+ self.invalidated = true;
183
+ }
184
+
185
+ /// The graceful app quit: ask the platform to terminate through
186
+ /// the SAME shutdown path a last-window close takes — the host
187
+ /// emits `app_shutdown` (journaled like any platform event),
188
+ /// `app.stop` runs exactly once, and a recording session seals
189
+ /// its journal. No runtime bookkeeping here: the shutdown event
190
+ /// owns the teardown.
191
+ pub fn quitApp(self: *Runtime) anyerror!void {
192
+ try self.options.platform.services.quitApp();
193
+ }
194
+
136
195
  pub fn updateWindowState(self: *Runtime, state: platform.WindowState) !void {
137
196
  try WindowStorageMethods.updateWindowState(self, state);
138
197
  if (!state.open) Self.removeWindowRuntimeViews(self, state.id);
@@ -173,6 +232,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
173
232
  .show = shell_layout.shellWindowShowMode(shell_window),
174
233
  .min_width = shell_window.min_width,
175
234
  .min_height = shell_window.min_height,
235
+ .close_policy = shell_layout.shellClosePolicy(shell_window.close_policy),
176
236
  .source = source,
177
237
  }, source_reloads_from_app, source_policy);
178
238
  errdefer Self.closeWindow(self, info.id) catch {};
@@ -102,6 +102,7 @@ pub const Metadata = struct {
102
102
  allocator.free(window.label);
103
103
  if (window.title) |title| allocator.free(title);
104
104
  allocator.free(window.titlebar);
105
+ allocator.free(window.close_policy);
105
106
  }
106
107
  if (self.windows.len > 0) allocator.free(self.windows);
107
108
  for (self.shell.windows) |window| {
@@ -109,6 +110,7 @@ pub const Metadata = struct {
109
110
  if (window.title) |title| allocator.free(title);
110
111
  allocator.free(window.restore_policy);
111
112
  allocator.free(window.titlebar);
113
+ allocator.free(window.close_policy);
112
114
  for (window.views) |view| {
113
115
  allocator.free(view.label);
114
116
  allocator.free(view.kind);
@@ -200,6 +202,7 @@ pub const WindowMetadata = struct {
200
202
  titlebar: []const u8 = "standard",
201
203
  min_width: f32 = 0,
202
204
  min_height: f32 = 0,
205
+ close_policy: []const u8 = "quit",
203
206
  };
204
207
 
205
208
  pub const ShellMetadata = struct {
@@ -237,6 +240,7 @@ pub const ShellWindowMetadata = struct {
237
240
  titlebar: []const u8 = "standard",
238
241
  min_width: f32 = 0,
239
242
  min_height: f32 = 0,
243
+ close_policy: []const u8 = "quit",
240
244
  views: []const ShellViewMetadata = &.{},
241
245
  };
242
246
 
@@ -592,6 +596,7 @@ fn convertRawWindows(allocator: std.mem.Allocator, windows: []const RawWindow) !
592
596
  .titlebar = try allocator.dupe(u8, window.titlebar),
593
597
  .min_width = window.min_width,
594
598
  .min_height = window.min_height,
599
+ .close_policy = try allocator.dupe(u8, window.close_policy),
595
600
  };
596
601
  }
597
602
  return converted;
@@ -644,6 +649,7 @@ fn convertRawShellWindows(allocator: std.mem.Allocator, windows: []const RawShel
644
649
  .titlebar = try allocator.dupe(u8, window.titlebar),
645
650
  .min_width = window.min_width,
646
651
  .min_height = window.min_height,
652
+ .close_policy = try allocator.dupe(u8, window.close_policy),
647
653
  .views = try convertRawShellViews(allocator, window.views),
648
654
  };
649
655
  }
@@ -843,6 +849,7 @@ fn convertWindows(allocator: std.mem.Allocator, windows: []const WindowMetadata)
843
849
  .titlebar = try parseTitlebarStyle(window.titlebar),
844
850
  .min_width = try parseWindowMinSize(window.min_width),
845
851
  .min_height = try parseWindowMinSize(window.min_height),
852
+ .close_policy = try parseClosePolicy(window.close_policy),
846
853
  };
847
854
  }
848
855
  return converted;
@@ -867,6 +874,7 @@ fn parseShell(allocator: std.mem.Allocator, shell: ShellMetadata) !app_manifest.
867
874
  const titlebar = try parseTitlebarStyle(window.titlebar);
868
875
  const min_width = try parseWindowMinSize(window.min_width);
869
876
  const min_height = try parseWindowMinSize(window.min_height);
877
+ const close_policy = try parseClosePolicy(window.close_policy);
870
878
  const views = try parseShellViews(allocator, window.views);
871
879
  windows[index] = .{
872
880
  .label = window.label,
@@ -881,6 +889,7 @@ fn parseShell(allocator: std.mem.Allocator, shell: ShellMetadata) !app_manifest.
881
889
  .titlebar = titlebar,
882
890
  .min_width = min_width,
883
891
  .min_height = min_height,
892
+ .close_policy = close_policy,
884
893
  .views = views,
885
894
  };
886
895
  initialized += 1;
@@ -1273,6 +1282,12 @@ fn parseTitlebarStyle(value: []const u8) !app_manifest.WindowTitlebarStyle {
1273
1282
  return error.InvalidWindowTitlebarStyle;
1274
1283
  }
1275
1284
 
1285
+ fn parseClosePolicy(value: []const u8) !app_manifest.WindowClosePolicy {
1286
+ if (std.mem.eql(u8, value, "quit")) return .quit;
1287
+ if (std.mem.eql(u8, value, "hide")) return .hide;
1288
+ return error.InvalidWindowClosePolicy;
1289
+ }
1290
+
1276
1291
  /// Same validation posture as the titlebar style: a min-size floor the
1277
1292
  /// host cannot honor (negative or non-finite) is a manifest error, not
1278
1293
  /// a silent clamp. 0 is the "no floor" sentinel.
@@ -1860,6 +1875,66 @@ test "manifest parser rejects negative window min sizes" {
1860
1875
  try std.testing.expectError(error.InvalidWindowMinSize, parseShell(std.testing.allocator, metadata.shell));
1861
1876
  }
1862
1877
 
1878
+ test "manifest parser reads window close policies" {
1879
+ const metadata = try parseText(std.testing.allocator,
1880
+ \\.{
1881
+ \\ .id = "com.example.app",
1882
+ \\ .name = "example",
1883
+ \\ .version = "1.2.3",
1884
+ \\ .windows = .{
1885
+ \\ .{ .label = "main", .close_policy = "hide" },
1886
+ \\ .{ .label = "doc" },
1887
+ \\ },
1888
+ \\ .shell = .{
1889
+ \\ .windows = .{
1890
+ \\ .{ .label = "scene", .close_policy = "hide", .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1891
+ \\ },
1892
+ \\ },
1893
+ \\}
1894
+ );
1895
+ defer metadata.deinit(std.testing.allocator);
1896
+
1897
+ try std.testing.expectEqualStrings("hide", metadata.windows[0].close_policy);
1898
+ try std.testing.expectEqualStrings("quit", metadata.windows[1].close_policy);
1899
+ try std.testing.expectEqualStrings("hide", metadata.shell.windows[0].close_policy);
1900
+
1901
+ const windows = try convertWindows(std.testing.allocator, metadata.windows);
1902
+ defer std.testing.allocator.free(windows);
1903
+ try std.testing.expectEqual(app_manifest.WindowClosePolicy.hide, windows[0].close_policy);
1904
+ // Undeclared stays the .quit default — behavior unchanged for
1905
+ // every existing app.
1906
+ try std.testing.expectEqual(app_manifest.WindowClosePolicy.quit, windows[1].close_policy);
1907
+
1908
+ const shell = try parseShell(std.testing.allocator, metadata.shell);
1909
+ defer deinitParsedShell(std.testing.allocator, shell);
1910
+ try std.testing.expectEqual(app_manifest.WindowClosePolicy.hide, shell.windows[0].close_policy);
1911
+ }
1912
+
1913
+ test "manifest parser rejects unknown window close policy" {
1914
+ const metadata = try parseText(std.testing.allocator,
1915
+ \\.{
1916
+ \\ .id = "com.example.app",
1917
+ \\ .name = "example",
1918
+ \\ .version = "1.2.3",
1919
+ \\ .windows = .{
1920
+ \\ .{ .label = "main", .close_policy = "minimize" },
1921
+ \\ },
1922
+ \\ .shell = .{
1923
+ \\ .windows = .{
1924
+ \\ .{ .label = "scene", .close_policy = "event", .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
1925
+ \\ },
1926
+ \\ },
1927
+ \\}
1928
+ );
1929
+ defer metadata.deinit(std.testing.allocator);
1930
+
1931
+ // "event" is the deliberately reserved future tier (model-decides
1932
+ // close); it parses as unknown until it ships — staged honestly,
1933
+ // never accepted early.
1934
+ try std.testing.expectError(error.InvalidWindowClosePolicy, convertWindows(std.testing.allocator, metadata.windows));
1935
+ try std.testing.expectError(error.InvalidWindowClosePolicy, parseShell(std.testing.allocator, metadata.shell));
1936
+ }
1937
+
1863
1938
  test "manifest parser rejects unknown window titlebar style" {
1864
1939
  const metadata = try parseText(std.testing.allocator,
1865
1940
  \\.{
@@ -96,6 +96,7 @@ pub const RawWindow = struct {
96
96
  titlebar: []const u8 = "standard",
97
97
  min_width: f32 = 0,
98
98
  min_height: f32 = 0,
99
+ close_policy: []const u8 = "quit",
99
100
  };
100
101
 
101
102
  pub const RawShell = struct {
@@ -133,6 +134,7 @@ pub const RawShellWindow = struct {
133
134
  titlebar: []const u8 = "standard",
134
135
  min_width: f32 = 0,
135
136
  min_height: f32 = 0,
137
+ close_policy: []const u8 = "quit",
136
138
  views: []const RawShellView = &.{},
137
139
  };
138
140
 
@@ -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
@@ -1728,7 +1751,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1728
1751
  \\ // the layer stays out even on machines where the
1729
1752
  \\ // development package is installed — libwebkitgtk is
1730
1753
  \\ // neither linked nor required at runtime, and the
1731
- \\ // executable carries no WebKit reference at all.
1754
+ \\ // executable carries no WebKit reference at all. This
1755
+ \\ // is the expected, configured state of every canvas
1756
+ \\ // app on Linux, so the stub compile is deliberately
1757
+ \\ // silent — no build note, no compiler diagnostic (the
1758
+ \\ // host's seam comment explains why even an
1759
+ \\ // informational pragma is dangerous); a stubbed host
1760
+ \\ // teaches at runtime by reporting WebViewNotFound the
1761
+ \\ // moment an app actually uses a WebView.
1732
1762
  \\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
1733
1763
  \\ app_mod.linkSystemLibrary("gtk4", .{});
1734
1764
  \\ app_mod.linkSystemLibrary("dl", .{});
@@ -1774,6 +1804,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1774
1804
  \\ // headers are reachable through the system include paths
1775
1805
  \\ // — no WebView2Loader.dll is installed or path-wired,
1776
1806
  \\ // and the executable carries no reference to it at all.
1807
+ \\ // This is the expected, configured state of every
1808
+ \\ // canvas app on Windows, so the stub compile is
1809
+ \\ // deliberately silent — no build note, no compiler
1810
+ \\ // diagnostic (the host's seam comment explains why
1811
+ \\ // even an informational pragma is dangerous); a
1812
+ \\ // stubbed host teaches at runtime by reporting
1813
+ \\ // WebViewNotFound the moment an app actually uses a
1814
+ \\ // WebView.
1777
1815
  \\ 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
1816
  \\ },
1779
1817
  \\ .chromium => {
@@ -2183,6 +2221,7 @@ fn runnerZig() []const u8 {
2183
2221
  \\ var info: native_sdk.AppInfo = .{
2184
2222
  \\ .app_name = self.app_name,
2185
2223
  \\ .has_web_content = manifestHasWebContent(),
2224
+ \\ .declares_tray = manifestDeclaresTrayCapability(),
2186
2225
  \\ .window_title = self.window_title,
2187
2226
  \\ .bundle_id = self.bundle_id,
2188
2227
  \\ .icon_path = self.icon_path,
@@ -2191,6 +2230,26 @@ fn runnerZig() []const u8 {
2191
2230
  \\ if (windows.len > 0) {
2192
2231
  \\ info.main_window = windows[0];
2193
2232
  \\ info.windows = windows;
2233
+ \\ } else {
2234
+ \\ // Scene-first apps declare their one window under
2235
+ \\ // `.shell.windows` — the startup window the host creates
2236
+ \\ // adopts that declaration when the scene loads, but its
2237
+ \\ // CHROME is fixed at create time, so the manifest's
2238
+ \\ // titlebar style threads through here. Same for visibility:
2239
+ \\ // a canvas-first startup window is created ordered-out and
2240
+ \\ // shown after its first canvas frame presents, so launch
2241
+ \\ // never flashes a blank window.
2242
+ \\ info.main_window.titlebar = manifestShellStartupTitlebar();
2243
+ \\ info.main_window.resizable = manifestShellStartupResizable();
2244
+ \\ info.main_window.show = manifestShellStartupShowMode();
2245
+ \\ // Min-size floors ride the create call like the titlebar:
2246
+ \\ // the scene re-applies size/title later, but the window's
2247
+ \\ // enforced floor is host state from the first frame on.
2248
+ \\ info.main_window.min_width = manifestShellStartupMinSize("min_width");
2249
+ \\ info.main_window.min_height = manifestShellStartupMinSize("min_height");
2250
+ \\ // Close handling is host window state like the titlebar:
2251
+ \\ // the manifest's declaration rides the host create.
2252
+ \\ info.main_window.close_policy = manifestShellStartupClosePolicy();
2194
2253
  \\ }
2195
2254
  \\ return info;
2196
2255
  \\ }
@@ -2314,6 +2373,10 @@ fn runnerZig() []const u8 {
2314
2373
  \\ .resizable = windowBool(window, "resizable", true),
2315
2374
  \\ .restore_state = windowBool(window, "restore_state", true),
2316
2375
  \\ .restore_policy = windowRestorePolicy(window),
2376
+ \\ .titlebar = windowTitlebarStyle(window),
2377
+ \\ .min_width = windowMinSize(window, "min_width"),
2378
+ \\ .min_height = windowMinSize(window, "min_height"),
2379
+ \\ .close_policy = windowClosePolicy(window),
2317
2380
  \\ };
2318
2381
  \\}
2319
2382
  \\
@@ -2347,6 +2410,125 @@ fn runnerZig() []const u8 {
2347
2410
  \\ @compileError("unknown app.zon window restore_policy");
2348
2411
  \\}
2349
2412
  \\
2413
+ \\/// Window-enforced content min-size floor from app.zon. Validated at
2414
+ \\/// comptime like the titlebar style: a negative floor is an authoring
2415
+ \\/// error, not a silent clamp.
2416
+ \\fn windowMinSize(comptime window: anytype, comptime field: []const u8) f32 {
2417
+ \\ const value: f32 = comptime windowFloat(window, field, 0);
2418
+ \\ comptime {
2419
+ \\ if (!(value >= 0)) @compileError("app.zon window " ++ field ++ " must be non-negative");
2420
+ \\ }
2421
+ \\ return value;
2422
+ \\}
2423
+ \\
2424
+ \\fn windowTitlebarStyle(comptime window: anytype) native_sdk.WindowTitlebarStyle {
2425
+ \\ if (comptime !@hasField(@TypeOf(window), "titlebar")) return .standard;
2426
+ \\ const value = window.titlebar;
2427
+ \\ if (comptime std.mem.eql(u8, value, "standard")) return .standard;
2428
+ \\ if (comptime std.mem.eql(u8, value, "hidden_inset")) return .hidden_inset;
2429
+ \\ if (comptime std.mem.eql(u8, value, "hidden_inset_tall")) return .hidden_inset_tall;
2430
+ \\ if (comptime std.mem.eql(u8, value, "chromeless")) return .chromeless;
2431
+ \\ @compileError("unknown app.zon window titlebar style");
2432
+ \\}
2433
+ \\
2434
+ \\/// The startup window's titlebar style for scene-first apps: app.zon's
2435
+ \\/// `.shell.windows[0].titlebar`. Chrome cannot change after the host
2436
+ \\/// creates the window, so it must ride the create call — unlike
2437
+ \\/// size/title, which the loading scene re-applies.
2438
+ \\fn manifestShellStartupTitlebar() native_sdk.WindowTitlebarStyle {
2439
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .standard;
2440
+ \\ const shell = app_manifest.shell;
2441
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .standard;
2442
+ \\ if (comptime shell.windows.len == 0) return .standard;
2443
+ \\ return windowTitlebarStyle(shell.windows[0]);
2444
+ \\}
2445
+ \\
2446
+ \\/// The startup window's resizability for scene-first apps: like the
2447
+ \\/// titlebar style, resizable is window chrome fixed at create time.
2448
+ \\fn manifestShellStartupResizable() bool {
2449
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return true;
2450
+ \\ const shell = app_manifest.shell;
2451
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return true;
2452
+ \\ if (comptime shell.windows.len == 0) return true;
2453
+ \\ return windowBool(shell.windows[0], "resizable", true);
2454
+ \\}
2455
+ \\
2456
+ \\/// The startup window's close policy for scene-first apps: app.zon's
2457
+ \\/// `.shell.windows[0].close_policy`. Like the titlebar, close handling
2458
+ \\/// is host window state fixed at create time.
2459
+ \\fn manifestShellStartupClosePolicy() native_sdk.WindowClosePolicy {
2460
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .quit;
2461
+ \\ const shell = app_manifest.shell;
2462
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .quit;
2463
+ \\ if (comptime shell.windows.len == 0) return .quit;
2464
+ \\ return windowClosePolicy(shell.windows[0]);
2465
+ \\}
2466
+ \\
2467
+ \\/// The startup window's content min-size floor for scene-first apps:
2468
+ \\/// app.zon's `.shell.windows[0].min_width`/`.min_height` (0 = none).
2469
+ \\fn manifestShellStartupMinSize(comptime field: []const u8) f32 {
2470
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return 0;
2471
+ \\ const shell = app_manifest.shell;
2472
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return 0;
2473
+ \\ if (comptime shell.windows.len == 0) return 0;
2474
+ \\ return windowMinSize(shell.windows[0], field);
2475
+ \\}
2476
+ \\
2477
+ \\/// Present-before-show for the STARTUP window: when app.zon's first
2478
+ \\/// shell window hosts a canvas (`gpu_surface` view), the host creates
2479
+ \\/// it ordered-out and it becomes visible after the first canvas frame
2480
+ \\/// presents. Webview-first startup windows keep immediate visibility.
2481
+ \\fn manifestShellStartupShowMode() native_sdk.WindowShowMode {
2482
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return .immediate;
2483
+ \\ const shell = app_manifest.shell;
2484
+ \\ if (comptime !@hasField(@TypeOf(shell), "windows")) return .immediate;
2485
+ \\ if (comptime shell.windows.len == 0) return .immediate;
2486
+ \\ const window = shell.windows[0];
2487
+ \\ if (comptime !@hasField(@TypeOf(window), "views")) return .immediate;
2488
+ \\ inline for (window.views) |view| {
2489
+ \\ if (comptime @hasField(@TypeOf(view), "kind")) {
2490
+ \\ if (comptime std.mem.eql(u8, view.kind, "gpu_surface")) return .on_first_present;
2491
+ \\ }
2492
+ \\ }
2493
+ \\ return .immediate;
2494
+ \\}
2495
+ \\
2496
+ \\/// What the window's close affordance does, from app.zon. `.hide` is
2497
+ \\/// validated against the TARGET platform at comptime: a host with no
2498
+ \\/// affordance to bring a hidden window back (GTK has no status item;
2499
+ \\/// windows without a declared tray, since hiding removes the taskbar
2500
+ \\/// entry and windows has no dock) refuses the declaration here, at
2501
+ \\/// build time, instead of stranding a hidden window at runtime.
2502
+ \\fn windowClosePolicy(comptime window: anytype) native_sdk.WindowClosePolicy {
2503
+ \\ if (comptime !@hasField(@TypeOf(window), "close_policy")) return .quit;
2504
+ \\ const value = window.close_policy;
2505
+ \\ if (comptime std.mem.eql(u8, value, "quit")) return .quit;
2506
+ \\ if (comptime std.mem.eql(u8, value, "hide")) {
2507
+ \\ if (comptime std.mem.eql(u8, build_options.platform, "linux")) {
2508
+ \\ @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");
2509
+ \\ }
2510
+ \\ if (comptime std.mem.eql(u8, build_options.platform, "windows")) {
2511
+ \\ if (comptime !manifestDeclaresTrayCapability()) {
2512
+ \\ @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");
2513
+ \\ }
2514
+ \\ }
2515
+ \\ return .hide;
2516
+ \\ }
2517
+ \\ @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)");
2518
+ \\}
2519
+ \\
2520
+ \\/// Whether app.zon declares the "tray" capability — the status item
2521
+ \\/// `.hide` leans on where the OS has no built-in re-show affordance.
2522
+ \\/// Evaluated at comptime over the manifest import, like the web scan.
2523
+ \\fn manifestDeclaresTrayCapability() bool {
2524
+ \\ if (comptime !@hasField(@TypeOf(app_manifest), "capabilities")) return false;
2525
+ \\ inline for (app_manifest.capabilities) |capability| {
2526
+ \\ const name: []const u8 = capability;
2527
+ \\ if (comptime std.mem.eql(u8, name, "tray")) return true;
2528
+ \\ }
2529
+ \\ return false;
2530
+ \\}
2531
+ \\
2350
2532
  \\fn menuItem(comptime item: anytype) native_sdk.MenuItem {
2351
2533
  \\ return .{
2352
2534
  \\ .label = if (@hasField(@TypeOf(item), "label")) item.label else "",
@@ -3651,6 +3833,42 @@ test "writeDefaultApp emits Vite project files" {
3651
3833
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestWindowOptions") != null);
3652
3834
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.windows = windows") != null);
3653
3835
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "for (restored_windows, 0..)") != null);
3836
+ // The generated manifestWindow must thread every declarable window
3837
+ // option into WindowOptions — a dropped field is a silent no-op for
3838
+ // every `native create` app (the manifest accepts the declaration,
3839
+ // the window ignores it). close_policy shipped with exactly that gap
3840
+ // once; these pins hold the field AND the Linux comptime refusal (a
3841
+ // .hide window with no tray to bring it back must fail the build,
3842
+ // not strand a hidden window at runtime).
3843
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".restore_policy = windowRestorePolicy(window)") != null);
3844
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".titlebar = windowTitlebarStyle(window)") != null);
3845
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_width = windowMinSize(window, \"min_width\")") != null);
3846
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".min_height = windowMinSize(window, \"min_height\")") != null);
3847
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".close_policy = windowClosePolicy(window)") != null);
3848
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "close_policy \\\"hide\\\" is not supported on linux") != null);
3849
+ // The windows-conditional twin: `.hide` hides the taskbar entry and
3850
+ // windows has no dock-reopen path, so the declaration requires the
3851
+ // "tray" capability (the status item IS the re-show affordance).
3852
+ // macOS stays exempt — the Dock reopen path always exists.
3853
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "close_policy \\\"hide\\\" on windows requires the \\\"tray\\\" capability") != null);
3854
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "fn manifestDeclaresTrayCapability()") != null);
3855
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, ".declares_tray = manifestDeclaresTrayCapability()") != null);
3856
+ // The scene-first twin: an app.zon that declares its one window under
3857
+ // `.shell.windows` (the default `native init` shape) hits the
3858
+ // windows.len == 0 branch, and the startup window's host-create state
3859
+ // (chrome, resizability, show mode, min-size floor, close policy)
3860
+ // must thread from the shell declaration exactly like the SDK runner
3861
+ // — a generated runner without this threading silently keeps
3862
+ // quit-on-close (and standard chrome) for every scene-first
3863
+ // manifest. The close-policy helper reuses windowClosePolicy, so the
3864
+ // shell path carries the same Linux comptime refusal pinned above.
3865
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.titlebar = manifestShellStartupTitlebar()") != null);
3866
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.resizable = manifestShellStartupResizable()") != null);
3867
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.show = manifestShellStartupShowMode()") != null);
3868
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_width = manifestShellStartupMinSize(\"min_width\")") != null);
3869
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.min_height = manifestShellStartupMinSize(\"min_height\")") != null);
3870
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "info.main_window.close_policy = manifestShellStartupClosePolicy()") != null);
3871
+ try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "return windowClosePolicy(shell.windows[0])") != null);
3654
3872
  // The Runtime is multi-megabyte; the generated runner must heap-allocate
3655
3873
  // it and construct in place, never build it by value on the stack.
3656
3874
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "std.heap.page_allocator.create(native_sdk.Runtime)") != null);