@native-sdk/cli 0.5.3 → 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 (79) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +223 -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/src/emitter.ts +2586 -259
  10. package/skill-data/native-ui/SKILL.md +3 -2
  11. package/skill-data/ts-core/SKILL.md +9 -1
  12. package/src/app_runner/root.zig +81 -1
  13. package/src/app_runner/ts_core_main.zig +4 -0
  14. package/src/embed/tests.zig +119 -1
  15. package/src/platform/linux/gtk_host.c +112 -3
  16. package/src/platform/linux/root.zig +71 -0
  17. package/src/platform/macos/appkit_host.h +48 -2
  18. package/src/platform/macos/appkit_host.m +533 -34
  19. package/src/platform/macos/cef_host.mm +262 -10
  20. package/src/platform/macos/root.zig +92 -4
  21. package/src/platform/null_platform.zig +298 -5
  22. package/src/platform/root.zig +33 -0
  23. package/src/platform/types.zig +138 -4
  24. package/src/platform/windows/root.zig +134 -0
  25. package/src/platform/windows/webview2_host.cpp +152 -40
  26. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  27. package/src/primitives/app_manifest/root.zig +1 -0
  28. package/src/primitives/app_manifest/types.zig +32 -0
  29. package/src/primitives/canvas/tests.zig +1 -0
  30. package/src/primitives/canvas/ui.zig +11 -7
  31. package/src/primitives/canvas/ui_markup.zig +58 -34
  32. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  33. package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +1 -1
  36. package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
  37. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  38. package/src/primitives/canvas/ui_markup_tests.zig +29 -9
  39. package/src/primitives/canvas/ui_markup_view.zig +29 -11
  40. package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
  41. package/src/primitives/canvas/ui_schema.zig +13 -0
  42. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  43. package/src/root.zig +7 -0
  44. package/src/runtime/api.zig +6 -4
  45. package/src/runtime/bridge_payload.zig +7 -0
  46. package/src/runtime/bridge_responses.zig +5 -0
  47. package/src/runtime/builtin_bridge.zig +9 -4
  48. package/src/runtime/canvas_font_tests.zig +439 -2
  49. package/src/runtime/canvas_fonts.zig +61 -6
  50. package/src/runtime/canvas_image_tests.zig +195 -0
  51. package/src/runtime/canvas_images.zig +45 -12
  52. package/src/runtime/core.zig +58 -11
  53. package/src/runtime/effects.zig +1664 -43
  54. package/src/runtime/effects_fetch_tests.zig +89 -1
  55. package/src/runtime/effects_file_tests.zig +41 -1
  56. package/src/runtime/effects_image_tests.zig +1304 -0
  57. package/src/runtime/effects_tests.zig +153 -0
  58. package/src/runtime/flow.zig +17 -0
  59. package/src/runtime/root.zig +11 -0
  60. package/src/runtime/session_blobs.zig +689 -0
  61. package/src/runtime/session_journal.zig +85 -21
  62. package/src/runtime/session_record.zig +27 -2
  63. package/src/runtime/session_replay.zig +168 -16
  64. package/src/runtime/session_tests.zig +1992 -0
  65. package/src/runtime/shell_layout.zig +7 -0
  66. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  67. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +439 -4
  70. package/src/runtime/ts_core_host_tests.zig +41 -0
  71. package/src/runtime/ts_ui_app.zig +7 -0
  72. package/src/runtime/ui_app.zig +111 -6
  73. package/src/runtime/ui_app_window_tests.zig +468 -0
  74. package/src/runtime/window_command_bridge_tests.zig +117 -0
  75. package/src/runtime/window_storage.zig +32 -0
  76. package/src/runtime/window_views.zig +61 -1
  77. package/src/tooling/manifest.zig +75 -0
  78. package/src/tooling/raw_manifest.zig +2 -0
  79. package/src/tooling/templates.zig +219 -1
@@ -153,12 +153,88 @@ test "runtime handles built-in JavaScript window bridge commands" {
153
153
  } });
154
154
  try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
155
155
 
156
+ // The window JSON must expose alive-but-policy-hidden: open:true /
157
+ // focused:false alone cannot distinguish a close_policy = "hide"
158
+ // window from a visible unfocused one, so "hidden" rides every
159
+ // window response. Visible window first...
160
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"hidden\":false") != null);
161
+ // ...then the host reports the palette window policy-hidden (still
162
+ // open) and the bridge list reflects it.
163
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .window_frame_changed = .{
164
+ .id = 2,
165
+ .label = "palette",
166
+ .title = "Palette",
167
+ .frame = geometry.RectF.init(0, 0, 320, 240),
168
+ .scale_factor = 1,
169
+ .open = true,
170
+ .focused = false,
171
+ .hidden = true,
172
+ } });
173
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
174
+ .bytes = "{\"id\":\"hidden\",\"command\":\"native-sdk.window.list\",\"payload\":null}",
175
+ .origin = "zero://inline",
176
+ .window_id = 1,
177
+ } });
178
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"hidden\":true") != null);
179
+
180
+ // Focusing the policy-hidden window rides the runtime's ONE
181
+ // hidden-then-focus rule: the show verb runs first (the platform
182
+ // mirror counts it — the seam that clears the hosts' policy-hidden
183
+ // bookkeeping), so the response never reports a focused window
184
+ // that is still hidden.
185
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
186
+ .bytes = "{\"id\":\"5\",\"command\":\"native-sdk.window.focus\",\"payload\":{\"label\":\"palette\"}}",
187
+ .origin = "zero://inline",
188
+ .window_id = 1,
189
+ } });
190
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"focused\":true") != null);
191
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"hidden\":false") != null);
192
+ try std.testing.expectEqual(@as(u32, 1), harness.null_platform.showCountForWindow(2));
193
+
194
+ // The runtime's show verb (a tray "Open", Cmd.showWindow) is show
195
+ // AND activate: after showing a policy-hidden window, the bridge's
196
+ // window JSON — served from the same runtime table — reports it
197
+ // focused, not merely un-hidden.
198
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .window_frame_changed = .{
199
+ .id = 2,
200
+ .label = "palette",
201
+ .title = "Palette",
202
+ .frame = geometry.RectF.init(0, 0, 320, 240),
203
+ .scale_factor = 1,
204
+ .open = true,
205
+ .focused = false,
206
+ .hidden = true,
207
+ } });
208
+ try harness.runtime.showWindow(2);
209
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
210
+ .bytes = "{\"id\":\"shown\",\"command\":\"native-sdk.window.list\",\"payload\":null}",
211
+ .origin = "zero://inline",
212
+ .window_id = 1,
213
+ } });
214
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"label\":\"palette\",\"title\":\"Palette\",\"open\":true,\"focused\":true,\"hidden\":false") != null);
215
+
216
+ // Closing a POLICY-HIDDEN window through the bridge answers with
217
+ // the post-close table state: hidden clears with open (a closed
218
+ // window is gone, not "hidden"), so JS must never receive
219
+ // {open:false, hidden:true} — the shape a pre-close snapshot with
220
+ // hand-cleared fields would serialize.
221
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .window_frame_changed = .{
222
+ .id = 2,
223
+ .label = "palette",
224
+ .title = "Palette",
225
+ .frame = geometry.RectF.init(0, 0, 320, 240),
226
+ .scale_factor = 1,
227
+ .open = true,
228
+ .focused = false,
229
+ .hidden = true,
230
+ } });
156
231
  try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
157
232
  .bytes = "{\"id\":\"4\",\"command\":\"native-sdk.window.close\",\"payload\":{\"label\":\"palette\"}}",
158
233
  .origin = "zero://inline",
159
234
  .window_id = 1,
160
235
  } });
161
236
  try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"open\":false") != null);
237
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"hidden\":false") != null);
162
238
  }
163
239
 
164
240
  test "runtime handles built-in JavaScript command bridge commands" {
@@ -383,6 +459,47 @@ test "runtime handles built-in JavaScript platform support commands" {
383
459
  } });
384
460
  try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":false") != null);
385
461
 
462
+ // Both spellings of window_hide_on_close answer the same seam: the null
463
+ // platform models full hide-on-close support by default, and flipping the
464
+ // seam off (the GTK model) flips both spellings together.
465
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
466
+ .bytes = "{\"id\":\"hide-snake\",\"command\":\"native-sdk.platform.supports\",\"payload\":{\"feature\":\"window_hide_on_close\"}}",
467
+ .origin = "zero://inline",
468
+ .window_id = 1,
469
+ } });
470
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":true") != null);
471
+
472
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
473
+ .bytes = "{\"id\":\"hide-camel\",\"command\":\"native-sdk.platform.supports\",\"payload\":{\"feature\":\"windowHideOnClose\"}}",
474
+ .origin = "zero://inline",
475
+ .window_id = 1,
476
+ } });
477
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":true") != null);
478
+
479
+ harness.null_platform.window_hide_on_close = false;
480
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
481
+ .bytes = "{\"id\":\"hide-snake-off\",\"command\":\"native-sdk.platform.supports\",\"payload\":{\"feature\":\"window_hide_on_close\"}}",
482
+ .origin = "zero://inline",
483
+ .window_id = 1,
484
+ } });
485
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":false") != null);
486
+
487
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
488
+ .bytes = "{\"id\":\"hide-camel-off\",\"command\":\"native-sdk.platform.supports\",\"payload\":{\"feature\":\"windowHideOnClose\"}}",
489
+ .origin = "zero://inline",
490
+ .window_id = 1,
491
+ } });
492
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":false") != null);
493
+
494
+ // Camel-cohort spot check: the backfilled audioSpectrum alias resolves to
495
+ // audio_spectrum, which the default null platform supports.
496
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
497
+ .bytes = "{\"id\":\"spectrum-camel\",\"command\":\"native-sdk.platform.supports\",\"payload\":{\"feature\":\"audioSpectrum\"}}",
498
+ .origin = "zero://inline",
499
+ .window_id = 1,
500
+ } });
501
+ try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastBridgeResponse(), "\"result\":true") != null);
502
+
386
503
  var chromium_platform = platform.NullPlatform.initWithEngine(.{}, .chromium);
387
504
  harness.runtime.options.platform = chromium_platform.platform();
388
505
  try std.testing.expect(!harness.runtime.supports(.tray));
@@ -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