@native-sdk/cli 0.9.0 → 0.9.2

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 (181) hide show
  1. package/build/app.zig +357 -33
  2. package/build.zig +234 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +170 -13
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +18 -12
  26. package/skill-data/ts-core/SKILL.md +54 -21
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +122 -6
  31. package/src/app_runner/ts_core_main.zig +9 -4
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/app_runner/window_placement.zig +63 -0
  34. package/src/automation/protocol.zig +5 -1
  35. package/src/automation/snapshot.zig +8 -6
  36. package/src/embed/app_exports.zig +3 -1
  37. package/src/embed/conversions.zig +1 -0
  38. package/src/embed/host.zig +10 -3
  39. package/src/embed/root.zig +2 -0
  40. package/src/embed/tests.zig +41 -1
  41. package/src/embed/types.zig +2 -0
  42. package/src/embed/ui_host.zig +94 -4
  43. package/src/platform/android/NativeSdkActivity.java +49 -4
  44. package/src/platform/android/android_host.c +3 -3
  45. package/src/platform/android/native_sdk_app.h +1 -1
  46. package/src/platform/ios/apple_image_fit.h +38 -0
  47. package/src/platform/ios/files.zig +1 -0
  48. package/src/platform/ios/native_sdk_app.h +1 -1
  49. package/src/platform/ios/uikit_host.m +28 -5
  50. package/src/platform/linux/cef_host.cpp +17 -3
  51. package/src/platform/linux/gtk_host.c +243 -15
  52. package/src/platform/linux/gtk_host.h +5 -4
  53. package/src/platform/linux/root.zig +91 -11
  54. package/src/platform/macos/appkit_host.h +18 -11
  55. package/src/platform/macos/appkit_host.m +402 -128
  56. package/src/platform/macos/cef_host.mm +342 -122
  57. package/src/platform/macos/image_fit_test.m +44 -0
  58. package/src/platform/macos/root.zig +231 -39
  59. package/src/platform/null_platform.zig +251 -54
  60. package/src/platform/null_platform_tests.zig +97 -4
  61. package/src/platform/root.zig +12 -0
  62. package/src/platform/types.zig +174 -35
  63. package/src/platform/windows/root.zig +42 -13
  64. package/src/platform/windows/webview2_host.cpp +72 -11
  65. package/src/primitives/app_manifest/root.zig +3 -0
  66. package/src/primitives/app_manifest/tests.zig +24 -0
  67. package/src/primitives/app_manifest/types.zig +13 -0
  68. package/src/primitives/app_manifest/validation.zig +24 -0
  69. package/src/primitives/canvas/a11y_audit.zig +9 -7
  70. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  71. package/src/primitives/canvas/events.zig +50 -0
  72. package/src/primitives/canvas/layout_audit.zig +6 -6
  73. package/src/primitives/canvas/markdown.zig +4 -0
  74. package/src/primitives/canvas/markdown_tests.zig +1 -0
  75. package/src/primitives/canvas/png.zig +138 -0
  76. package/src/primitives/canvas/root.zig +13 -2
  77. package/src/primitives/canvas/text_span_tests.zig +5 -3
  78. package/src/primitives/canvas/text_spans.zig +2 -0
  79. package/src/primitives/canvas/text_tests.zig +20 -0
  80. package/src/primitives/canvas/ui.zig +55 -2
  81. package/src/primitives/canvas/ui_markup.zig +40 -13
  82. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  83. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  84. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  85. package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
  86. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  87. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  88. package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
  89. package/src/primitives/canvas/ui_schema.zig +17 -13
  90. package/src/primitives/canvas/ui_tests.zig +47 -0
  91. package/src/primitives/canvas/widget_access.zig +3 -3
  92. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  93. package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
  94. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  95. package/src/primitives/canvas/widget_layout.zig +333 -126
  96. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  97. package/src/primitives/canvas/widget_metrics.zig +7 -8
  98. package/src/primitives/canvas/widget_render.zig +76 -44
  99. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  100. package/src/primitives/canvas/widget_render_style.zig +58 -18
  101. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  102. package/src/primitives/canvas/widget_routing.zig +40 -34
  103. package/src/primitives/canvas/widget_runtime.zig +11 -2
  104. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  105. package/src/primitives/canvas/widget_semantics.zig +8 -3
  106. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  107. package/src/primitives/canvas/widget_tree.zig +99 -5
  108. package/src/primitives/canvas/widgets.zig +20 -7
  109. package/src/root.zig +10 -0
  110. package/src/runtime/api.zig +14 -0
  111. package/src/runtime/automation_commands.zig +35 -2
  112. package/src/runtime/automation_snapshot.zig +32 -24
  113. package/src/runtime/automation_widget_dispatch.zig +48 -6
  114. package/src/runtime/bridge_permission_tests.zig +35 -1
  115. package/src/runtime/bridge_responses.zig +1 -1
  116. package/src/runtime/builtin_bridge.zig +16 -3
  117. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  118. package/src/runtime/canvas_image_tests.zig +146 -2
  119. package/src/runtime/canvas_images.zig +35 -16
  120. package/src/runtime/canvas_limits.zig +13 -3
  121. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  122. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  123. package/src/runtime/canvas_widget_control_tests.zig +31 -1
  124. package/src/runtime/canvas_widget_events.zig +151 -26
  125. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  126. package/src/runtime/canvas_widget_runtime.zig +322 -102
  127. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  128. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  129. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  130. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  131. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  132. package/src/runtime/canvas_widget_state.zig +33 -7
  133. package/src/runtime/core.zig +28 -6
  134. package/src/runtime/effects.zig +1337 -49
  135. package/src/runtime/effects_file_tests.zig +587 -0
  136. package/src/runtime/effects_image_tests.zig +91 -0
  137. package/src/runtime/effects_notification_tests.zig +11 -0
  138. package/src/runtime/file_access.zig +400 -0
  139. package/src/runtime/file_effect_crash_helper.zig +28 -0
  140. package/src/runtime/file_effect_crash_tests.zig +37 -0
  141. package/src/runtime/flow.zig +21 -9
  142. package/src/runtime/gpu_surface_events.zig +25 -2
  143. package/src/runtime/native_command_event_tests.zig +44 -2
  144. package/src/runtime/pty.zig +5 -2
  145. package/src/runtime/root.zig +7 -0
  146. package/src/runtime/session_blobs.zig +4 -1
  147. package/src/runtime/session_journal.zig +56 -5
  148. package/src/runtime/session_record.zig +38 -0
  149. package/src/runtime/session_replay.zig +110 -15
  150. package/src/runtime/session_tests.zig +192 -4
  151. package/src/runtime/shell_layout_tests.zig +12 -0
  152. package/src/runtime/state.zig +10 -0
  153. package/src/runtime/system_services.zig +129 -36
  154. package/src/runtime/ts_core_host.zig +281 -11
  155. package/src/runtime/ts_core_host_tests.zig +142 -1
  156. package/src/runtime/ts_ui_app.zig +461 -8
  157. package/src/runtime/ui_app.zig +330 -112
  158. package/src/runtime/ui_app_tests.zig +251 -25
  159. package/src/runtime/ui_app_window_tests.zig +74 -8
  160. package/src/runtime/validation.zig +20 -0
  161. package/src/runtime/view.zig +3 -0
  162. package/src/runtime/view_widget_control.zig +18 -0
  163. package/src/runtime/view_widget_scroll.zig +112 -18
  164. package/src/runtime/view_widget_tree.zig +110 -13
  165. package/src/runtime/widget_bridge.zig +2 -0
  166. package/src/runtime/window_command_bridge_tests.zig +86 -0
  167. package/src/runtime/window_storage.zig +16 -1
  168. package/src/runtime/window_views.zig +1 -0
  169. package/src/tooling/ios.zig +3 -0
  170. package/src/tooling/manifest.zig +90 -2
  171. package/src/tooling/package.zig +67 -2
  172. package/src/tooling/raw_manifest.zig +10 -0
  173. package/src/tooling/templates.zig +156 -18
  174. package/src/tooling/ts_core.zig +83 -0
  175. package/src/tooling/web_engine.zig +1 -1
  176. package/tools/corewire/emit.zig +3 -3
  177. package/tools/corewire/emit_facade.zig +65 -5
  178. package/tools/corewire/emit_profile.zig +2 -2
  179. package/tools/corewire/emit_service.zig +2 -2
  180. package/tools/corewire/service_contract.zig +4 -4
  181. package/tools/corewire/sidecar.zig +4 -4
@@ -12,12 +12,14 @@
12
12
  //! view. Shell command events can map into messages through `on_command`.
13
13
  //!
14
14
  //! Secondary windows are model-declared: `Options.windows_fn` returns the
15
- //! window descriptors that should exist right now (presence IS
16
- //! visibility), `Options.window_view` builds each declared window's
15
+ //! window descriptors that should exist right now (presence IS liveness;
16
+ //! a `.hide` close policy may temporarily hide one),
17
+ //! `Options.window_view` builds each declared window's
17
18
  //! canvas tree, the runtime reconciles declared against live windows
18
19
  //! after every rebuild, input from any window dispatches Msgs with its
19
- //! window identity, and a user close dispatches the descriptor's
20
- //! `on_close` Msg — the dismissal precedent, applied to windows.
20
+ //! window identity, and a `.quit` user close dispatches the descriptor's
21
+ //! `on_close` Msg while `.hide` retains it — the platform close-policy
22
+ //! contract applied to model-declared windows.
21
23
  //!
22
24
  //! Markup apps choose an engine per build: `Options.markup` runs the
23
25
  //! runtime parser/interpreter (dev, hot reload), while
@@ -279,6 +281,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
279
281
  items: []const platform.TrayMenuItem = &.{},
280
282
  };
281
283
 
284
+ /// One entry in the model-declared status-item collection.
285
+ /// `id` is stable identity; dropping the entry removes that
286
+ /// native status item, while every other field patches in place.
287
+ pub const StatusItemDescriptor = struct {
288
+ id: platform.StatusItemId,
289
+ visible: bool = true,
290
+ state: StatusItemState = .{},
291
+ };
292
+
282
293
  /// Scratch handed to `status_item_fn` so a derived title
283
294
  /// (`std.fmt.bufPrint(&scratch.title_buffer, "{d} open", ...)`)
284
295
  /// and a built-up item list need no model-side storage. Lives on
@@ -290,20 +301,39 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
290
301
  items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
291
302
  };
292
303
 
304
+ /// Scratch for `status_items_fn`. The flat row store gives each
305
+ /// of the eight status items its full 32-row budget without heap
306
+ /// allocation; TypeScript adapters partition it by descriptor.
307
+ pub const StatusItemsScratch = struct {
308
+ status_items: [platform.max_status_items]StatusItemDescriptor = undefined,
309
+ title_buffers: [platform.max_status_items][platform.max_tray_title_bytes]u8 = undefined,
310
+ arena_buffer: [platform.max_status_items * 2048]u8 = undefined,
311
+ items: [platform.max_status_items * platform.max_tray_items]platform.TrayMenuItem = undefined,
312
+ };
313
+
314
+ const AppliedStatusItem = struct {
315
+ id: platform.StatusItemId = 0,
316
+ active: bool = false,
317
+ shell_hash: u64 = 0,
318
+ presentation_hash: u64 = 0,
319
+ menu_hash: u64 = 0,
320
+ shell_unsupported: bool = false,
321
+ presentation_unsupported: bool = false,
322
+ };
323
+
293
324
  /// Budget for model-declared secondary windows (see
294
325
  /// `canvas_limits.max_ui_app_windows` for the sizing rationale).
295
326
  pub const max_ui_windows: usize = canvas_limits.max_ui_app_windows;
296
327
 
297
328
  /// A model-declared secondary window (`Options.windows_fn`):
298
329
  /// settings, about, inspectors. Identity is `label`; PRESENCE in
299
- /// the returned slice is visibility — the runtime reconciles the
330
+ /// the returned slice is liveness — the runtime reconciles the
300
331
  /// declared set against live windows after every rebuild,
301
332
  /// creating the missing and closing the no-longer-declared.
302
- /// There is deliberately no `visible` flag: the platform window
303
- /// channel is create/focus/close with no hide, so a
304
- /// hidden-but-open descriptor would lie about what exists. The
305
- /// model bool that `windows_fn` consults IS the visibility
306
- /// channel, exactly like a dismissible surface's open flag.
333
+ /// There is deliberately no `visible` flag: transient visibility
334
+ /// is host state, changed through `hideWindow`/`showWindow` or a
335
+ /// `.hide` close policy. Stop declaring the window to close it and
336
+ /// release its retained views.
307
337
  pub const WindowDescriptor = struct {
308
338
  /// Window label: the stable identity across rebuilds, and
309
339
  /// the label automation snapshots print for the window.
@@ -351,8 +381,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
351
381
  /// False leaves the window resizable but disables the green
352
382
  /// fullscreen affordance and fullscreen command.
353
383
  allows_fullscreen: bool = true,
384
+ /// What the USER'S close affordance does. `.quit` (the
385
+ /// default) really closes the window; `.hide` retains its
386
+ /// native identity and views for a later `showWindow`. Fixed
387
+ /// at create like the titlebar. Unsupported hosts refuse
388
+ /// `.hide` rather than strand an unreachable hidden window.
389
+ close_policy: app_manifest.WindowClosePolicy = .quit,
354
390
  /// Msg dispatched when the USER closes the window (never for
355
- /// a reconcile close the model itself initiated). The
391
+ /// a `.hide` policy hide or a reconcile close the model itself
392
+ /// initiated). The
356
393
  /// dismissal precedent: the window is already gone as an
357
394
  /// optimistic echo; the model clears its open flag in
358
395
  /// `update` — or keeps declaring the window and the next
@@ -731,17 +768,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
731
768
  /// tray title seam keep the menu updates and log the title
732
769
  /// gap once.
733
770
  status_item_fn: ?*const fn (model: *const ModelT, scratch: *StatusItemScratch) StatusItemState = null,
771
+ /// Model-declared status-item collection. Stable non-zero
772
+ /// identifiers own native identity; presence creates,
773
+ /// absence removes, and changed shell/presentation/menu
774
+ /// fields patch the existing item independently. Mutually
775
+ /// exclusive with `status_item` and `status_item_fn`.
776
+ status_items_fn: ?*const fn (model: *const ModelT, scratch: *StatusItemsScratch) []const StatusItemDescriptor = null,
734
777
  /// Model-declared secondary windows, reconciled after every
735
778
  /// rebuild (and on the installing frame): windows the model
736
779
  /// declares exist, windows it stops declaring close — the
737
780
  /// `status_item_fn` shape applied to the window set, so a
738
781
  /// settings window is `if (model.settings_open)` declaring a
739
782
  /// descriptor, opened by a Msg and closed by one. Requires
740
- /// `window_view`. A user close dispatches the descriptor's
741
- /// `on_close` Msg (the dismissal precedent: the engine
742
- /// already closed it; the model's next declared set is
743
- /// truth). Reconcile failures degrade to logged warnings —
744
- /// a failed create never takes the render loop down.
783
+ /// `window_view`. A `.quit` user close dispatches the
784
+ /// descriptor's `on_close` Msg (the dismissal precedent: the
785
+ /// engine already closed it; the model's next declared set is
786
+ /// truth); `.hide` retains the declared window and dispatches
787
+ /// no close Msg. Reconcile failures degrade to logged warnings
788
+ /// — a failed create never takes the render loop down.
745
789
  windows_fn: ?*const fn (model: *const ModelT, scratch: *WindowsScratch) []const WindowDescriptor = null,
746
790
  /// Per-window view for declared secondary windows, keyed by
747
791
  /// the descriptor's window label — the `view` seam with the
@@ -786,6 +830,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
786
830
  canvas_label_storage: [app_manifest.max_view_label_bytes]u8 = undefined,
787
831
  canvas_label_len: usize = 0,
788
832
  window_id: platform.WindowId = 0,
833
+ /// Owned copy of `on_close`: windows outlive the callback pass
834
+ /// that declared them, and TypeScript channel messages in
835
+ /// particular may point into a per-cycle decode arena. Keep the
836
+ /// payload alive until the user closes the window (or the model
837
+ /// replaces the declaration).
838
+ on_close_arena: std.heap.ArenaAllocator,
789
839
  on_close: ?MsgT = null,
790
840
  /// The descriptor's top-level alpha contract also controls
791
841
  /// this slot's gpu alpha mode and frame clear. Without both,
@@ -822,10 +872,27 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
822
872
  arenas: [2]std.heap.ArenaAllocator,
823
873
 
824
874
  fn init(backing: std.mem.Allocator) WindowSlot {
825
- return .{ .arenas = .{
826
- std.heap.ArenaAllocator.init(backing),
827
- std.heap.ArenaAllocator.init(backing),
828
- } };
875
+ return .{
876
+ .on_close_arena = std.heap.ArenaAllocator.init(backing),
877
+ .arenas = .{
878
+ std.heap.ArenaAllocator.init(backing),
879
+ std.heap.ArenaAllocator.init(backing),
880
+ },
881
+ };
882
+ }
883
+
884
+ fn setOnClose(self: *WindowSlot, msg: ?MsgT) error{ OutOfMemory, HoverCapturePayloadUnsupported }!void {
885
+ _ = self.on_close_arena.reset(.retain_capacity);
886
+ self.on_close = null;
887
+ if (msg) |value| {
888
+ self.on_close = try Self.deepCopyMsgValue(MsgT, value, self.on_close_arena.allocator(), 0);
889
+ }
890
+ }
891
+
892
+ fn deinit(self: *WindowSlot) void {
893
+ self.on_close_arena.deinit();
894
+ self.arenas[0].deinit();
895
+ self.arenas[1].deinit();
829
896
  }
830
897
 
831
898
  fn label(self: *const WindowSlot) []const u8 {
@@ -961,19 +1028,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
961
1028
  web_pane_state_count: usize = 0,
962
1029
  /// Exactly-once guard for `Options.status_item`/`status_item_fn`.
963
1030
  status_item_installed: bool = false,
964
- /// True once `createTray` succeeded — the gate for model-driven
965
- /// tray updates (`status_item_fn`).
966
- tray_created: bool = false,
967
- /// The platform reported no tray-title seam; stop retrying (menu
968
- /// updates keep flowing).
969
- tray_title_unsupported: bool = false,
970
- /// Hashes of the last APPLIED model-derived tray state, so
971
- /// rebuilds only touch the platform when the output changed.
972
- tray_title_hash: u64 = 0,
973
- tray_menu_hash: u64 = 0,
1031
+ /// Last successfully created status-item identities and their
1032
+ /// applied channel hashes. Each channel patches independently;
1033
+ /// menu changes never replace the native item.
1034
+ applied_status_items: [platform.max_status_items]AppliedStatusItem = [_]AppliedStatusItem{.{}} ** platform.max_status_items,
1035
+ applied_status_item_count: usize = 0,
974
1036
  /// Scratch handed to `status_item_fn`; on the app struct so the
975
1037
  /// returned slices outlive the apply.
976
1038
  tray_scratch: StatusItemScratch = .{},
1039
+ status_items_scratch: StatusItemsScratch = .{},
977
1040
  /// Press-and-hold gesture state (`ElementOptions.on_hold`): the
978
1041
  /// widget id whose press armed the hold timer, and whether the
979
1042
  /// timer fired for the current gesture (a fired hold suppresses
@@ -1358,8 +1421,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1358
1421
  }
1359
1422
  }
1360
1423
  for (&self.window_slots) |*slot| {
1361
- slot.arenas[0].deinit();
1362
- slot.arenas[1].deinit();
1424
+ slot.deinit();
1363
1425
  }
1364
1426
  for (&self.hover_msg_leave_arenas) |*arena| arena.deinit();
1365
1427
  self.drag_msg_template_arena.deinit();
@@ -1417,6 +1479,18 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1417
1479
  .permitted = runtime.options.credentials_enabled and
1418
1480
  security.hasPermission(runtime.options.security.permissions, security.permission_credentials),
1419
1481
  });
1482
+ if (runtime.options.file_access) |binding| {
1483
+ self.effects.bindFileAccess(binding);
1484
+ } else if (!builtin.is_test and !self.effects.replayArmed()) {
1485
+ // Fail closed for custom/older runners that omit the new path
1486
+ // policy. Replay is exempt: the journal is the whole world and
1487
+ // fake file requests must park without consulting live paths.
1488
+ self.effects.bindFileAccess(.{
1489
+ .roots = &.{},
1490
+ .permitted = security.hasPermission(runtime.options.security.permissions, security.permission_filesystem),
1491
+ .enforce = true,
1492
+ });
1493
+ }
1420
1494
  self.effects.bindImages(runtime.canvasImageRegistryBinding());
1421
1495
  self.effects.bindMediaSurfaces(runtime.mediaSurfaceBinding());
1422
1496
  self.effects.bindWindowActions(.{
@@ -1492,7 +1566,16 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1492
1566
  record.truncated,
1493
1567
  record.dropped,
1494
1568
  ),
1495
- .file => try self.effects.feedFileResult(record.key, record.file_outcome, record.payload),
1569
+ .file => try self.effects.feedFileResultDetailed(.{
1570
+ .key = record.key,
1571
+ .op = record.file_op,
1572
+ .event = record.file_event,
1573
+ .outcome = record.file_outcome,
1574
+ .bytes = record.payload,
1575
+ .total = record.file_total,
1576
+ .mtime_ms = record.file_mtime_ms,
1577
+ .exists = record.file_exists,
1578
+ }),
1496
1579
  .clipboard => try self.effects.feedClipboardResult(record.key, record.clipboard_outcome, record.payload),
1497
1580
  // `.host` records ride the route in `code` (0 ok / 1
1498
1581
  // err); rejections never reach here — they carry
@@ -2667,7 +2750,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2667
2750
  for (declared) |descriptor| {
2668
2751
  if (self.windowSlotIndexByLabel(descriptor.label)) |slot_index| {
2669
2752
  // Already live: the close Msg follows the model.
2670
- self.window_slots[slot_index].on_close = descriptor.on_close;
2753
+ self.setWindowSlotOnClose(&self.window_slots[slot_index], descriptor.on_close);
2671
2754
  continue;
2672
2755
  }
2673
2756
  self.createWindowSlot(runtime, descriptor);
@@ -2741,6 +2824,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2741
2824
  .allows_fullscreen = descriptor.allows_fullscreen,
2742
2825
  .min_width = descriptor.min_width,
2743
2826
  .min_height = descriptor.min_height,
2827
+ .close_policy = descriptor.close_policy,
2744
2828
  // Deterministic reopen: the descriptor is the geometry
2745
2829
  // channel, not a persisted frame store.
2746
2830
  .restore_state = false,
@@ -2756,7 +2840,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2756
2840
  slot.canvas_label_len = descriptor.canvas_label.len;
2757
2841
  @memcpy(slot.canvas_label_storage[0..descriptor.canvas_label.len], descriptor.canvas_label);
2758
2842
  slot.window_id = info.id;
2759
- slot.on_close = descriptor.on_close;
2843
+ self.setWindowSlotOnClose(slot, descriptor.on_close);
2760
2844
  slot.transparent = descriptor.transparent;
2761
2845
  slot.installed = false;
2762
2846
  slot.canvas_size = .{ .width = descriptor.width, .height = descriptor.height };
@@ -2769,6 +2853,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2769
2853
  self.window_slot_count += 1;
2770
2854
  }
2771
2855
 
2856
+ fn setWindowSlotOnClose(self: *Self, slot: *WindowSlot, msg: ?MsgT) void {
2857
+ _ = self;
2858
+ slot.setOnClose(msg) catch |err| {
2859
+ slot.on_close = null;
2860
+ _ = slot.on_close_arena.reset(.free_all);
2861
+ switch (err) {
2862
+ error.OutOfMemory => ui_app_log.warn(
2863
+ "declared window '{s}' could not retain its on_close message: out of memory; user close will not dispatch it",
2864
+ .{slot.label()},
2865
+ ),
2866
+ error.HoverCapturePayloadUnsupported => ui_app_log.warn(
2867
+ "declared window '{s}' has an on_close payload that cannot be owned; bind scalar, record, union, array, optional, or slice data",
2868
+ .{slot.label()},
2869
+ ),
2870
+ }
2871
+ };
2872
+ }
2873
+
2772
2874
  /// The gpu_surface shell view for a declared window: the
2773
2875
  /// descriptor's canvas label wearing the MAIN canvas's declared
2774
2876
  /// gpu options (backend, pixel format, present mode...), so a
@@ -2815,8 +2917,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2815
2917
  self.window_slots[index] = self.window_slots[last];
2816
2918
  self.window_slots[last] = WindowSlot.init(self.backing);
2817
2919
  self.window_slot_count = last;
2818
- removed.arenas[0].deinit();
2819
- removed.arenas[1].deinit();
2920
+ removed.deinit();
2820
2921
  runtime.closeWindow(window_id) catch |err| {
2821
2922
  ui_app_log.warn("declared window close failed: {s}", .{@errorName(err)});
2822
2923
  };
@@ -2824,17 +2925,19 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2824
2925
 
2825
2926
  /// Drop a slot whose runtime window is ALREADY gone (the user
2826
2927
  /// closed it): bookkeeping only, no platform call.
2827
- fn forgetWindowSlot(self: *Self, index: usize) ?MsgT {
2928
+ fn forgetWindowSlot(self: *Self, index: usize) WindowSlot {
2828
2929
  self.releaseContextMenuSnapshotForWindow(self.window_slots[index].window_id);
2829
- const on_close = self.window_slots[index].on_close;
2830
2930
  const last = self.window_slot_count - 1;
2831
2931
  var removed = self.window_slots[index];
2832
2932
  self.window_slots[index] = self.window_slots[last];
2833
2933
  self.window_slots[last] = WindowSlot.init(self.backing);
2834
2934
  self.window_slot_count = last;
2935
+ // The retained tree is dead with the native window. Keep only
2936
+ // the on-close arena alive through the synchronous dispatch
2937
+ // below, then release it there as well.
2835
2938
  removed.arenas[0].deinit();
2836
2939
  removed.arenas[1].deinit();
2837
- return on_close;
2940
+ return removed;
2838
2941
  }
2839
2942
 
2840
2943
  /// Rebuild every installed secondary window's tree from the
@@ -3671,86 +3774,177 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
3671
3774
  /// menu): ~350 ms press-and-hold.
3672
3775
  pub const press_hold_duration_ns: u64 = 350 * std.time.ns_per_ms;
3673
3776
 
3674
- /// Install the menu-bar extra once, on the installing frame.
3675
- /// Selecting one of its items dispatches the item's `command`
3676
- /// through the ordinary `on_command` path (source `.tray`).
3677
- /// Unsupported platforms degrade to a logged warning. With a
3678
- /// `status_item_fn`, the model's derived presentation/items win from
3679
- /// the very first frame (the static options keep icon+tooltip).
3777
+ /// Install the declarative status-item surface on the installing
3778
+ /// frame. Collection entries reconcile by stable id; the legacy
3779
+ /// singular channel occupies the reserved primary id.
3680
3780
  fn installStatusItem(self: *Self, runtime: *Runtime) void {
3681
3781
  if (self.status_item_installed) return;
3682
- if (self.options.status_item == null and self.options.status_item_fn == null) return;
3782
+ if (self.options.status_item == null and self.options.status_item_fn == null and self.options.status_items_fn == null) return;
3783
+ if (self.options.status_items_fn != null and (self.options.status_item != null or self.options.status_item_fn != null)) {
3784
+ @panic("UiApp status_items_fn is mutually exclusive with status_item/status_item_fn");
3785
+ }
3683
3786
  self.status_item_installed = true;
3787
+ self.reconcileStatusItems(runtime, self.desiredStatusItems());
3788
+ }
3789
+
3790
+ /// Re-derive the status-item collection after every committed
3791
+ /// rebuild and patch shell, presentation, and menu independently.
3792
+ fn applyStatusItem(self: *Self, runtime: *Runtime) void {
3793
+ if (!self.status_item_installed) return;
3794
+ if (self.options.status_item_fn == null and self.options.status_items_fn == null) return;
3795
+ self.reconcileStatusItems(runtime, self.desiredStatusItems());
3796
+ }
3797
+
3798
+ fn desiredStatusItems(self: *Self) []const StatusItemDescriptor {
3799
+ if (self.options.status_items_fn) |items_fn| {
3800
+ return items_fn(&self.model, &self.status_items_scratch);
3801
+ }
3684
3802
  const static = self.options.status_item orelse StatusItemOptions{};
3685
- var presentation = platform.TrayPresentation{ .title = static.title };
3686
- var icon_path = static.icon_path;
3687
- var tooltip = static.tooltip;
3688
- var activation_command = static.activation_command;
3689
- var alternate_activation_command = static.alternate_activation_command;
3690
- var open_command = static.open_command;
3691
- var items = static.items;
3803
+ var state: StatusItemState = .{
3804
+ .title = static.title,
3805
+ .presentation = .{ .title = static.title },
3806
+ .icon_path = static.icon_path,
3807
+ .tooltip = static.tooltip,
3808
+ .activation_command = static.activation_command,
3809
+ .alternate_activation_command = static.alternate_activation_command,
3810
+ .open_command = static.open_command,
3811
+ .items = static.items,
3812
+ };
3692
3813
  if (self.options.status_item_fn) |state_fn| {
3693
- const state = state_fn(&self.model, &self.tray_scratch);
3694
- presentation = state.presentation;
3695
- if (presentation.title.len == 0) presentation.title = state.title;
3696
- if (state.icon_path.len > 0) icon_path = state.icon_path;
3697
- if (state.tooltip.len > 0) tooltip = state.tooltip;
3698
- if (state.activation_command.len > 0) activation_command = state.activation_command;
3699
- if (state.alternate_activation_command.len > 0) alternate_activation_command = state.alternate_activation_command;
3700
- if (state.open_command.len > 0) open_command = state.open_command;
3701
- items = state.items;
3702
- }
3703
- runtime.createTray(.{
3704
- .title = presentation.title,
3705
- .icon_path = icon_path,
3706
- .tooltip = tooltip,
3707
- .items = items,
3708
- .presentation = presentation,
3709
- .activation_command = activation_command,
3710
- .alternate_activation_command = alternate_activation_command,
3711
- .open_command = open_command,
3712
- }) catch |err| {
3713
- ui_app_log.warn("status item install failed: {s}", .{@errorName(err)});
3714
- return;
3814
+ state = state_fn(&self.model, &self.tray_scratch);
3815
+ if (state.presentation.title.len == 0) state.presentation.title = state.title;
3816
+ if (state.icon_path.len == 0) state.icon_path = static.icon_path;
3817
+ if (state.tooltip.len == 0) state.tooltip = static.tooltip;
3818
+ if (state.activation_command.len == 0) state.activation_command = static.activation_command;
3819
+ if (state.alternate_activation_command.len == 0) state.alternate_activation_command = static.alternate_activation_command;
3820
+ if (state.open_command.len == 0) state.open_command = static.open_command;
3821
+ }
3822
+ self.status_items_scratch.status_items[0] = .{
3823
+ .id = platform.primary_status_item_id,
3824
+ .state = state,
3715
3825
  };
3716
- self.tray_created = true;
3717
- self.tray_title_hash = hashTrayPresentation(presentation);
3718
- self.tray_menu_hash = hashTrayMenu(items);
3826
+ return self.status_items_scratch.status_items[0..1];
3719
3827
  }
3720
3828
 
3721
- /// Re-derive the tray state from the model after a rebuild and
3722
- /// patch only what changed — the `web_panes` shape for the menu
3723
- /// bar. Failures degrade to a logged warning; a rejected
3724
- /// state is remembered so a static model does not warn per frame.
3725
- fn applyStatusItem(self: *Self, runtime: *Runtime) void {
3726
- const state_fn = self.options.status_item_fn orelse return;
3727
- if (!self.tray_created) return;
3728
- const state = state_fn(&self.model, &self.tray_scratch);
3729
- var presentation = state.presentation;
3730
- if (presentation.title.len == 0) presentation.title = state.title;
3731
-
3732
- const title_hash = hashTrayPresentation(presentation);
3733
- if (title_hash != self.tray_title_hash) {
3734
- self.tray_title_hash = title_hash;
3735
- if (!self.tray_title_unsupported) {
3736
- runtime.updateTrayPresentation(presentation) catch |err| {
3737
- if (err == error.UnsupportedService) {
3738
- self.tray_title_unsupported = true;
3739
- ui_app_log.warn("status item presentation updates unsupported on this platform: the menu keeps updating", .{});
3740
- } else {
3741
- ui_app_log.warn("status item presentation update failed: {s}", .{@errorName(err)});
3742
- }
3829
+ fn reconcileStatusItems(self: *Self, runtime: *Runtime, declared: []const StatusItemDescriptor) void {
3830
+ if (declared.len > platform.max_status_items) {
3831
+ ui_app_log.warn("status item collection has {d} entries; at most {d} are supported", .{ declared.len, platform.max_status_items });
3832
+ }
3833
+ const desired = declared[0..@min(declared.len, platform.max_status_items)];
3834
+
3835
+ for (&self.applied_status_items) |*applied| {
3836
+ if (!applied.active or statusItemDeclared(desired, applied.id)) continue;
3837
+ runtime.removeStatusItem(applied.id) catch |err| {
3838
+ ui_app_log.warn("status item #{d} remove failed: {s}", .{ applied.id, @errorName(err) });
3839
+ continue;
3840
+ };
3841
+ applied.* = .{};
3842
+ self.applied_status_item_count -= 1;
3843
+ }
3844
+
3845
+ for (desired, 0..) |raw_descriptor, index| {
3846
+ if (raw_descriptor.id == 0 or statusItemIdAppearedEarlier(desired, index, raw_descriptor.id)) {
3847
+ ui_app_log.warn("status item declaration ignored: identifiers must be unique and non-zero (got {d})", .{raw_descriptor.id});
3848
+ continue;
3849
+ }
3850
+ var descriptor = raw_descriptor;
3851
+ if (descriptor.state.presentation.title.len == 0) descriptor.state.presentation.title = descriptor.state.title;
3852
+ const shell = platform.TrayShell{
3853
+ .icon_path = descriptor.state.icon_path,
3854
+ .tooltip = descriptor.state.tooltip,
3855
+ .visible = descriptor.visible,
3856
+ .activation_command = descriptor.state.activation_command,
3857
+ .alternate_activation_command = descriptor.state.alternate_activation_command,
3858
+ .open_command = descriptor.state.open_command,
3859
+ };
3860
+ const shell_hash = hashTrayShell(shell);
3861
+ const presentation_hash = hashTrayPresentation(descriptor.state.presentation);
3862
+ const menu_hash = hashTrayMenu(descriptor.state.items);
3863
+
3864
+ const applied = self.findAppliedStatusItem(descriptor.id) orelse self.emptyAppliedStatusItem() orelse {
3865
+ ui_app_log.warn("status item #{d} ignored: status-item capacity is full", .{descriptor.id});
3866
+ continue;
3867
+ };
3868
+ if (!applied.active) {
3869
+ runtime.createStatusItem(descriptor.id, .{
3870
+ .title = descriptor.state.presentation.title,
3871
+ .icon_path = shell.icon_path,
3872
+ .tooltip = shell.tooltip,
3873
+ .visible = shell.visible,
3874
+ .items = descriptor.state.items,
3875
+ .presentation = descriptor.state.presentation,
3876
+ .activation_command = shell.activation_command,
3877
+ .alternate_activation_command = shell.alternate_activation_command,
3878
+ .open_command = shell.open_command,
3879
+ }) catch |err| {
3880
+ ui_app_log.warn("status item #{d} install failed: {s}", .{ descriptor.id, @errorName(err) });
3881
+ continue;
3882
+ };
3883
+ applied.* = .{
3884
+ .id = descriptor.id,
3885
+ .active = true,
3886
+ .shell_hash = shell_hash,
3887
+ .presentation_hash = presentation_hash,
3888
+ .menu_hash = menu_hash,
3889
+ };
3890
+ self.applied_status_item_count += 1;
3891
+ continue;
3892
+ }
3893
+
3894
+ if (shell_hash != applied.shell_hash) {
3895
+ applied.shell_hash = shell_hash;
3896
+ if (!applied.shell_unsupported) {
3897
+ runtime.updateStatusItemShell(descriptor.id, shell) catch |err| {
3898
+ if (err == error.UnsupportedService) applied.shell_unsupported = true;
3899
+ ui_app_log.warn("status item #{d} shell update failed: {s}", .{ descriptor.id, @errorName(err) });
3900
+ };
3901
+ }
3902
+ }
3903
+ if (presentation_hash != applied.presentation_hash) {
3904
+ applied.presentation_hash = presentation_hash;
3905
+ if (!applied.presentation_unsupported) {
3906
+ runtime.updateStatusItemPresentation(descriptor.id, descriptor.state.presentation) catch |err| {
3907
+ if (err == error.UnsupportedService) applied.presentation_unsupported = true;
3908
+ ui_app_log.warn("status item #{d} presentation update failed: {s}", .{ descriptor.id, @errorName(err) });
3909
+ };
3910
+ }
3911
+ }
3912
+ if (menu_hash != applied.menu_hash) {
3913
+ applied.menu_hash = menu_hash;
3914
+ runtime.updateStatusItemMenu(descriptor.id, descriptor.state.items) catch |err| {
3915
+ ui_app_log.warn("status item #{d} menu update failed: {s}", .{ descriptor.id, @errorName(err) });
3743
3916
  };
3744
3917
  }
3745
3918
  }
3919
+ }
3746
3920
 
3747
- const menu_hash = hashTrayMenu(state.items);
3748
- if (menu_hash != self.tray_menu_hash) {
3749
- self.tray_menu_hash = menu_hash;
3750
- runtime.updateTrayMenu(state.items) catch |err| {
3751
- ui_app_log.warn("status item menu update failed: {s} (items must carry unique non-zero ids and validated command names)", .{@errorName(err)});
3752
- };
3921
+ fn findAppliedStatusItem(self: *Self, id: platform.StatusItemId) ?*AppliedStatusItem {
3922
+ for (&self.applied_status_items) |*applied| {
3923
+ if (applied.active and applied.id == id) return applied;
3924
+ }
3925
+ return null;
3926
+ }
3927
+
3928
+ fn emptyAppliedStatusItem(self: *Self) ?*AppliedStatusItem {
3929
+ if (self.applied_status_item_count >= self.applied_status_items.len) return null;
3930
+ for (&self.applied_status_items) |*applied| {
3931
+ if (!applied.active) return applied;
3932
+ }
3933
+ return null;
3934
+ }
3935
+
3936
+ fn statusItemDeclared(declared: []const StatusItemDescriptor, id: platform.StatusItemId) bool {
3937
+ for (declared) |descriptor| {
3938
+ if (descriptor.id == id) return true;
3753
3939
  }
3940
+ return false;
3941
+ }
3942
+
3943
+ fn statusItemIdAppearedEarlier(declared: []const StatusItemDescriptor, index: usize, id: platform.StatusItemId) bool {
3944
+ for (declared[0..index]) |descriptor| {
3945
+ if (descriptor.id == id) return true;
3946
+ }
3947
+ return false;
3754
3948
  }
3755
3949
 
3756
3950
  /// The video channel snapshot in the builder's chrome shape
@@ -4150,8 +4344,9 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4150
4344
  // in its place), a non-owner just drops out of the table.
4151
4345
  self.captureSlotVideoDeclaration(closed.window_id, null);
4152
4346
  self.applyVideoDeclaration(runtime);
4153
- const on_close = self.forgetWindowSlot(index);
4154
- if (on_close) |msg| {
4347
+ var removed = self.forgetWindowSlot(index);
4348
+ defer removed.on_close_arena.deinit();
4349
+ if (removed.on_close) |msg| {
4155
4350
  try self.dispatch(runtime, self.canvas_window_id, msg);
4156
4351
  }
4157
4352
  }
@@ -4546,6 +4741,23 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4546
4741
  /// Change-detection hashes for the model-derived tray state:
4547
4742
  /// field lengths are folded in so adjacent slices can
4548
4743
  /// never alias across boundaries.
4744
+ fn hashTrayShell(shell: platform.TrayShell) u64 {
4745
+ var hasher = std.hash.Wyhash.init(0x7261795f7368656c); // "ray_shel"
4746
+ const fields = [_][]const u8{
4747
+ shell.icon_path,
4748
+ shell.tooltip,
4749
+ shell.activation_command,
4750
+ shell.alternate_activation_command,
4751
+ shell.open_command,
4752
+ };
4753
+ for (fields) |field| {
4754
+ hasher.update(std.mem.asBytes(&field.len));
4755
+ hasher.update(field);
4756
+ }
4757
+ hasher.update(&.{@intFromBool(shell.visible)});
4758
+ return hasher.final();
4759
+ }
4760
+
4549
4761
  fn hashTrayPresentation(presentation: platform.TrayPresentation) u64 {
4550
4762
  var hasher = std.hash.Wyhash.init(0x7261795f70726573); // "ray_pres"
4551
4763
  hasher.update(presentation.title);
@@ -4771,7 +4983,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4771
4983
  // `on_double_press` handler (falling back to the ordinary
4772
4984
  // press), while its first release already dispatched the
4773
4985
  // single press — select-then-act, the list convention.
4774
- if (tree.msgForPointerClick(target.id, pointer_event.pointer.phase, pointer_event.pointer.click_count)) |msg| {
4986
+ if (tree.msgForPointerEvent(target.id, pointer_event.pointer)) |msg| {
4775
4987
  try self.dispatch(runtime, pointer_event.window_id, msg);
4776
4988
  }
4777
4989
  }
@@ -5617,6 +5829,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
5617
5829
  }
5618
5830
  return;
5619
5831
  }
5832
+ // A radio group owns Arrow/Home/End even when the
5833
+ // requested target is already focused and selected.
5834
+ // That in-place case deliberately has no selection
5835
+ // intent (and therefore no duplicate on-change), but
5836
+ // it must still stop before the app-level key map.
5837
+ if (keyboard_event.keyboard.radio_group_navigation) return;
5620
5838
  }
5621
5839
  }
5622
5840
  }
@@ -5810,8 +6028,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
5810
6028
  const tree = self.treeForViewLabel(drag_event.view_label);
5811
6029
  const live_template = if (tree) |value| value.msgFor(source.id, .drag) else null;
5812
6030
  const layout: ?canvas.WidgetLayoutTree = runtime.canvasWidgetLayout(drag_event.window_id, drag_event.view_label) catch null;
5813
- const live_view_size: ?geometry.SizeF = if (layout) |value| if (value.nodes.len > 0) blk: {
5814
- const root = value.nodes[0].frame.normalized();
6031
+ const live_view_size: ?geometry.SizeF = if (layout) |value| if (canvas.widgetLayoutRootBounds(value)) |root_value| blk: {
6032
+ const root = root_value.normalized();
5815
6033
  break :blk geometry.SizeF.init(root.width, root.height);
5816
6034
  } else null else null;
5817
6035