@native-sdk/cli 0.8.4 → 0.9.1

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 (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
@@ -61,6 +61,8 @@ pub const Error = error{
61
61
  InvalidCredentialOptions,
62
62
  CredentialFieldTooLarge,
63
63
  CredentialNotFound,
64
+ CredentialStoreLocked,
65
+ CredentialStoreFailed,
64
66
  InvalidTrayOptions,
65
67
  TrayFieldTooLarge,
66
68
  InvalidAudioOptions,
@@ -241,17 +243,29 @@ pub const max_recent_document_path_bytes: usize = 4096;
241
243
  pub const max_notification_title_bytes: usize = 128;
242
244
  pub const max_notification_subtitle_bytes: usize = 128;
243
245
  pub const max_notification_body_bytes: usize = 1024;
246
+ pub const max_notification_id_bytes: usize = 128;
247
+ pub const max_notification_action_label_bytes: usize = 128;
248
+ pub const max_notification_action_command_bytes: usize = 128;
244
249
  pub const max_clipboard_mime_type_bytes: usize = 128;
245
250
  pub const max_clipboard_data_bytes: usize = 65536;
246
251
  pub const max_credential_service_bytes: usize = 128;
247
252
  pub const max_credential_account_bytes: usize = 256;
248
- pub const max_credential_secret_bytes: usize = 4096;
253
+ /// One honest cross-platform bound: Windows Credential Manager's generic
254
+ /// credential blob is the narrowest first-party backend at 5 * 512 bytes.
255
+ /// Every host accepts this whole range; none silently truncates it.
256
+ pub const max_credential_secret_bytes: usize = 5 * 512;
257
+ pub const max_local_time_text_bytes: usize = 512;
258
+ /// A desktop app may own a small bounded set of independent status items.
259
+ /// macOS implements the whole set; hosts whose tray API is singular accept
260
+ /// only `primary_status_item_id` and reject additional identifiers.
261
+ pub const max_status_items: usize = 8;
249
262
  pub const max_tray_items: usize = 32;
250
263
  pub const max_tray_icon_path_bytes: usize = 4096;
251
264
  pub const max_tray_title_bytes: usize = 64;
252
265
  pub const max_tray_tooltip_bytes: usize = 256;
253
266
  pub const max_tray_item_label_bytes: usize = 256;
254
267
  pub const max_tray_item_command_bytes: usize = 128;
268
+ pub const max_tray_item_detail_bytes: usize = 256;
255
269
  pub const max_drop_paths_bytes: usize = 8192;
256
270
  pub const max_drop_paths: usize = max_drop_paths_bytes / 2 + 1;
257
271
  pub const max_window_event_name_bytes: usize = 64;
@@ -355,8 +369,7 @@ pub const MenuItem = struct {
355
369
 
356
370
  pub fn validateShortcut(shortcut: Shortcut) Error!void {
357
371
  if (!isValidCommandId(shortcut.id, max_shortcut_id_bytes)) return error.InvalidShortcut;
358
- if (!isValidShortcutKey(shortcut.key)) return error.InvalidShortcut;
359
- if (!shortcut.modifiers.hasAny() and shortcutRequiresModifier(shortcut.key)) return error.InvalidShortcut;
372
+ if (!isValidShortcutBinding(shortcut.key, shortcut.modifiers)) return error.InvalidShortcut;
360
373
  }
361
374
 
362
375
  pub fn validateMenus(menus: []const Menu) Error!void {
@@ -375,9 +388,8 @@ pub fn validateMenuItem(item: MenuItem) Error!void {
375
388
  if (item.label.len == 0 or item.label.len > max_menu_item_label_bytes) return error.InvalidMenuOptions;
376
389
  if (!isValidCommandId(item.command, max_menu_command_bytes)) return error.InvalidCommand;
377
390
  if (item.key.len > 0) {
378
- if (!isValidShortcutKey(item.key)) return error.InvalidShortcut;
379
391
  if (item.key.len > max_menu_key_bytes) return error.InvalidShortcut;
380
- if (!item.modifiers.hasAny() and shortcutRequiresModifier(item.key)) return error.InvalidShortcut;
392
+ if (!isValidShortcutBinding(item.key, item.modifiers)) return error.InvalidShortcut;
381
393
  }
382
394
  }
383
395
 
@@ -435,6 +447,10 @@ pub fn isValidShortcutKey(key: []const u8) bool {
435
447
  return false;
436
448
  }
437
449
 
450
+ pub fn isValidShortcutBinding(key: []const u8, modifiers: ShortcutModifiers) bool {
451
+ return isValidShortcutKey(key) and (modifiers.hasAny() or !shortcutRequiresModifier(key));
452
+ }
453
+
438
454
  fn shortcutRequiresModifier(key: []const u8) bool {
439
455
  if (key.len == 1) return true;
440
456
  return std.ascii.eqlIgnoreCase(key, "space") or
@@ -572,6 +588,11 @@ pub const WindowDragRegion = struct {
572
588
  pub const WindowShowMode = enum {
573
589
  immediate,
574
590
  on_first_present,
591
+ /// Create the native window ordered out and keep it that way until
592
+ /// an explicit `showWindow`/focus request. This is the launch shape
593
+ /// for a menu-bar app whose real surface is its status item: the
594
+ /// host window exists for runtime/view ownership but never flashes.
595
+ hidden,
575
596
  };
576
597
 
577
598
  /// What the user's close affordance (the red traffic light, cmd+W, the
@@ -618,6 +639,12 @@ pub const WindowOptions = struct {
618
639
  /// or `showWindow`) activates the app and takes keyboard focus.
619
640
  /// Explicit `focusWindow` remains an activation request either way.
620
641
  activate_on_show: bool = true,
642
+ /// Whether macOS may move the window into a native fullscreen
643
+ /// Space. False keeps ordinary resizing but removes the green
644
+ /// fullscreen affordance and rejects the fullscreen shortcut.
645
+ /// Other desktop hosts currently have no separate fullscreen mode
646
+ /// at this seam and keep their existing maximize behavior.
647
+ allows_fullscreen: bool = true,
621
648
  /// Content min-size floor the WINDOW enforces (macOS
622
649
  /// `contentMinSize`): the user cannot resize below it, so declared
623
650
  /// layout floors stop clamping/clipping panes instead of stopping
@@ -644,15 +671,14 @@ pub const WindowState = struct {
644
671
  focused: bool = true,
645
672
  maximized: bool = false,
646
673
  fullscreen: bool = false,
647
- /// True while the window is alive but off the glass because its
648
- /// `close_policy = .hide` intercepted a user close (the menu-bar-app
649
- /// shape): the window keeps its views and native identity, `open`
650
- /// stays true, and a show — `Effects.showWindow`, a tray action's
651
- /// consequence, the macOS Dock reopen — flips it back. Distinct from
652
- /// minimized (which keeps a Dock/taskbar affordance) and from
653
- /// closed (`open = false`, the window is gone). Session-transient:
654
- /// never persisted to the window-state store, so every launch
655
- /// starts shown.
674
+ /// True while the window is alive but ordered off the glass: an
675
+ /// explicitly hidden startup window, `Effects.hideWindow`, or a
676
+ /// `close_policy = .hide` user close. The window keeps its views and
677
+ /// native identity, `open` stays true, and show/focus flips it back.
678
+ /// Distinct from minimized (which keeps a Dock/taskbar affordance)
679
+ /// and closed (`open = false`, the window is gone). Session-transient:
680
+ /// it is never restored from the window-state store; each launch uses
681
+ /// the declaration's show policy again.
656
682
  hidden: bool = false,
657
683
  };
658
684
 
@@ -695,6 +721,7 @@ pub const WindowCreateOptions = struct {
695
721
  always_on_top: bool = false,
696
722
  click_through: bool = false,
697
723
  activate_on_show: bool = true,
724
+ allows_fullscreen: bool = true,
698
725
  /// Window-enforced content min-size floor (see
699
726
  /// `WindowOptions.min_width`/`min_height`); 0 = no floor.
700
727
  min_width: f32 = 0,
@@ -718,6 +745,7 @@ pub const WindowCreateOptions = struct {
718
745
  .always_on_top = self.always_on_top,
719
746
  .click_through = self.click_through,
720
747
  .activate_on_show = self.activate_on_show,
748
+ .allows_fullscreen = self.allows_fullscreen,
721
749
  .min_width = self.min_width,
722
750
  .min_height = self.min_height,
723
751
  .close_policy = self.close_policy,
@@ -725,6 +753,18 @@ pub const WindowCreateOptions = struct {
725
753
  }
726
754
  };
727
755
 
756
+ /// The operating system's registration state for launching this app at
757
+ /// user login. `requires_approval` is a successful query, not an I/O
758
+ /// failure: macOS knows the registration but the user must approve it
759
+ /// in System Settings. `not_found` means the current executable is not
760
+ /// an installed application bundle that SMAppService can register.
761
+ pub const LaunchAtLoginStatus = enum {
762
+ disabled,
763
+ enabled,
764
+ requires_approval,
765
+ not_found,
766
+ };
767
+
728
768
  pub const WebViewOptions = struct {
729
769
  window_id: WindowId = 1,
730
770
  label: []const u8,
@@ -967,6 +1007,10 @@ pub const ViewInfo = struct {
967
1007
  gpu_frame_index: u64 = 0,
968
1008
  gpu_timestamp_ns: u64 = 0,
969
1009
  gpu_frame_interval_ns: u64 = default_gpu_frame_interval_ns,
1010
+ /// GPU-surface input events accepted by the runtime for this view.
1011
+ /// Monotonic for the view lifetime; automation uses deltas to separate
1012
+ /// host/input-stack delivery from renderer frame coverage.
1013
+ gpu_input_event_count: u64 = 0,
970
1014
  gpu_input_timestamp_ns: u64 = 0,
971
1015
  gpu_input_latency_ns: u64 = 0,
972
1016
  gpu_input_latency_budget_ns: u64 = default_gpu_frame_interval_ns,
@@ -977,6 +1021,9 @@ pub const ViewInfo = struct {
977
1021
  gpu_first_frame_latency_budget_exceeded_count: usize = 0,
978
1022
  gpu_first_frame_latency_budget_ok: bool = true,
979
1023
  gpu_frame_nonblank: bool = false,
1024
+ /// Whether the most recent host completion was an occluded logical
1025
+ /// heartbeat rather than a presentation that reached the display.
1026
+ gpu_occluded: bool = false,
980
1027
  gpu_sample_color: u32 = 0,
981
1028
  gpu_backend: GpuSurfaceBackend = .none,
982
1029
  gpu_pixel_format: GpuSurfacePixelFormat = .none,
@@ -1332,9 +1379,17 @@ pub const MessageDialogOptions = struct {
1332
1379
  };
1333
1380
 
1334
1381
  pub const NotificationOptions = struct {
1382
+ /// Stable host identity. Reissuing a non-empty id replaces the
1383
+ /// notification with that id and its action binding.
1384
+ id: []const u8 = "",
1335
1385
  title: []const u8,
1336
1386
  subtitle: []const u8 = "",
1337
1387
  body: []const u8 = "",
1388
+ /// Action fields are paired: both empty means display-only; both
1389
+ /// non-empty presents the label and routes activation as an ordinary
1390
+ /// application command.
1391
+ action_label: []const u8 = "",
1392
+ action_command: []const u8 = "",
1338
1393
  };
1339
1394
 
1340
1395
  pub const CredentialKey = struct {
@@ -1348,15 +1403,92 @@ pub const Credential = struct {
1348
1403
  secret: []const u8,
1349
1404
  };
1350
1405
 
1406
+ /// Host-local, locale-aware timestamp presentation. This deliberately lives
1407
+ /// behind PlatformServices: the same epoch can format differently after a
1408
+ /// locale or time-zone change, so app cores must observe it as an effect.
1409
+ pub const LocalTimeStyle = enum(u8) {
1410
+ date,
1411
+ time,
1412
+ datetime,
1413
+ };
1414
+
1415
+ pub const StatusItemId = u32;
1416
+ pub const primary_status_item_id: StatusItemId = 1;
1351
1417
  pub const TrayItemId = u32;
1352
1418
 
1419
+ /// Visual emphasis for the menu-bar button's live presentation. Hosts
1420
+ /// without a colored-title seam may render every value as `normal`.
1421
+ pub const TrayTone = enum(u8) {
1422
+ normal,
1423
+ warning,
1424
+ critical,
1425
+ };
1426
+
1427
+ /// The model-derived part of a status item. Keeping this separate from
1428
+ /// icon/tooltip/activation options lets UiApp patch presentation without
1429
+ /// recreating the native item.
1430
+ pub const TrayPresentation = struct {
1431
+ title: []const u8 = "",
1432
+ /// Explicit status-item width in points; zero asks the host to choose
1433
+ /// variable width for a title and square width for icon-only state.
1434
+ width: f32 = 0,
1435
+ tone: TrayTone = .normal,
1436
+ icon_opacity: f32 = 1,
1437
+ monospaced: bool = false,
1438
+ };
1439
+
1353
1440
  pub const TrayOptions = struct {
1354
1441
  icon_path: []const u8 = "",
1355
1442
  /// Status-bar button title, shown when no icon resolves (macOS
1356
1443
  /// `NSStatusItem` menu-bar extras render it directly in the menu bar).
1357
1444
  title: []const u8 = "",
1358
1445
  tooltip: []const u8 = "",
1446
+ /// Whether the native item occupies the menu bar/tray. False preserves
1447
+ /// its native identity so making it visible again does not reshuffle it.
1448
+ visible: bool = true,
1359
1449
  items: []const TrayMenuItem = &.{},
1450
+ presentation: TrayPresentation = .{},
1451
+ /// Ordinary click, Option-click, and menu-open hooks. Each command
1452
+ /// enters the same on_command route as a selected menu row.
1453
+ activation_command: []const u8 = "",
1454
+ alternate_activation_command: []const u8 = "",
1455
+ open_command: []const u8 = "",
1456
+ };
1457
+
1458
+ /// The independently live shell fields of a status item. Presentation and
1459
+ /// menu have their own patch seams so changing this state never rebuilds a
1460
+ /// menu and changing a menu never recreates the native item.
1461
+ pub const TrayShell = struct {
1462
+ icon_path: []const u8 = "",
1463
+ tooltip: []const u8 = "",
1464
+ visible: bool = true,
1465
+ activation_command: []const u8 = "",
1466
+ alternate_activation_command: []const u8 = "",
1467
+ open_command: []const u8 = "",
1468
+ };
1469
+
1470
+ pub fn trayShell(options: TrayOptions) TrayShell {
1471
+ return .{
1472
+ .icon_path = options.icon_path,
1473
+ .tooltip = options.tooltip,
1474
+ .visible = options.visible,
1475
+ .activation_command = options.activation_command,
1476
+ .alternate_activation_command = options.alternate_activation_command,
1477
+ .open_command = options.open_command,
1478
+ };
1479
+ }
1480
+
1481
+ /// Semantic status-menu rows. `command` is the ordinary actionable row;
1482
+ /// the others let a capable host render readouts without presenting them
1483
+ /// as disabled actions. Hosts without rich-menu support may degrade them
1484
+ /// to non-actionable text rows.
1485
+ pub const TrayItemRole = enum(u8) {
1486
+ command,
1487
+ info,
1488
+ header,
1489
+ hero,
1490
+ agent,
1491
+ context,
1360
1492
  };
1361
1493
 
1362
1494
  pub const TrayMenuItem = struct {
@@ -1365,6 +1497,10 @@ pub const TrayMenuItem = struct {
1365
1497
  command: []const u8 = "",
1366
1498
  separator: bool = false,
1367
1499
  enabled: bool = true,
1500
+ detail: []const u8 = "",
1501
+ role: TrayItemRole = .command,
1502
+ key: []const u8 = "",
1503
+ modifiers: ShortcutModifiers = .{},
1368
1504
  };
1369
1505
 
1370
1506
  pub const NativeCommandEvent = struct {
@@ -1378,6 +1514,30 @@ pub const MenuCommandEvent = struct {
1378
1514
  window_id: WindowId = 1,
1379
1515
  };
1380
1516
 
1517
+ /// A named command emitted by status-item lifecycle hooks (activation,
1518
+ /// alternate activation, or menu open). Unlike `tray_action`, this command
1519
+ /// does not identify a menu row, but its source is still the tray.
1520
+ pub const TrayCommandEvent = struct {
1521
+ name: []const u8,
1522
+ window_id: WindowId = 1,
1523
+ status_item_id: StatusItemId = primary_status_item_id,
1524
+ };
1525
+
1526
+ /// A notification action activated while the app process is live. The
1527
+ /// platform keeps replacement identity private; only the validated command
1528
+ /// crosses into the runtime, where it follows the normal command path.
1529
+ pub const NotificationCommandEvent = struct {
1530
+ name: []const u8,
1531
+ window_id: WindowId = 1,
1532
+ };
1533
+
1534
+ /// A selected row is namespaced by its owning status item. Row ids only
1535
+ /// need to be unique inside one menu.
1536
+ pub const TrayActionEvent = struct {
1537
+ status_item_id: StatusItemId = primary_status_item_id,
1538
+ item_id: TrayItemId,
1539
+ };
1540
+
1381
1541
  /// Timer ids at or above this value are reserved for the framework's own
1382
1542
  /// internal timers (for example the ui-app markup watch poll). Application
1383
1543
  /// code must pick ids below this value when calling `startTimer`.
@@ -2319,10 +2479,12 @@ pub const Event = union(enum) {
2319
2479
  window_focused: WindowId,
2320
2480
  view_focused: ViewFocusEvent,
2321
2481
  bridge_message: BridgeMessage,
2322
- tray_action: TrayItemId,
2482
+ tray_action: TrayActionEvent,
2323
2483
  shortcut: ShortcutEvent,
2324
2484
  native_command: NativeCommandEvent,
2325
2485
  menu_command: MenuCommandEvent,
2486
+ tray_command: TrayCommandEvent,
2487
+ notification_command: NotificationCommandEvent,
2326
2488
  timer: TimerEvent,
2327
2489
  /// A cross-thread nudge posted through `PlatformServices.wake_fn`:
2328
2490
  /// worker threads (effect executors) ask the platform loop to deliver
@@ -2360,6 +2522,8 @@ pub const Event = union(enum) {
2360
2522
  .shortcut => "shortcut",
2361
2523
  .native_command => "native_command",
2362
2524
  .menu_command => "menu_command",
2525
+ .tray_command => "tray_command",
2526
+ .notification_command => "notification_command",
2363
2527
  .timer => "timer",
2364
2528
  .wake => "wake",
2365
2529
  .files_dropped => "files_dropped",
@@ -2414,12 +2578,26 @@ pub const PlatformServices = struct {
2414
2578
  /// controls — chromeless windows have no system button to click.
2415
2579
  /// Platforms without the concept leave this null.
2416
2580
  minimize_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
2581
+ /// Keep a live window and all of its views, but order it off the
2582
+ /// glass. The runtime marks `WindowInfo.hidden` while it is out;
2583
+ /// `show_window_fn` is the inverse. Platforms without a reliable
2584
+ /// re-show path leave this null.
2585
+ hide_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
2417
2586
  /// The real OS show verb: unhide + order front. It activates by
2418
2587
  /// default; windows created with `activate_on_show = false` use the
2419
2588
  /// platform's passive variant. This is the counterpart to a
2420
2589
  /// `close_policy = .hide` hide, and the tray "Open" consequence.
2421
2590
  /// Platforms without the concept leave this null.
2422
2591
  show_window_fn: ?*const fn (context: ?*anyopaque, window_id: WindowId) anyerror!void = null,
2592
+ /// Change whether the process appears in the Dock/app switcher.
2593
+ /// macOS maps true/false to the regular/accessory activation
2594
+ /// policies; other hosts leave this null.
2595
+ set_dock_presence_fn: ?*const fn (context: ?*anyopaque, visible: bool) anyerror!void = null,
2596
+ /// Query and update the installed app bundle's SMAppService login
2597
+ /// registration. Unbundled development executables and hosts
2598
+ /// without the service leave these null / return UnsupportedService.
2599
+ launch_at_login_status_fn: ?*const fn (context: ?*anyopaque) anyerror!LaunchAtLoginStatus = null,
2600
+ set_launch_at_login_fn: ?*const fn (context: ?*anyopaque, enabled: bool) anyerror!LaunchAtLoginStatus = null,
2423
2601
  /// The graceful app quit: terminate through the SAME shutdown path
2424
2602
  /// a last-window close takes — but the host QUEUES the emit, so
2425
2603
  /// `app_shutdown` dispatches on its NEXT loop turn, only after the
@@ -2485,14 +2663,23 @@ pub const PlatformServices = struct {
2485
2663
  set_credential_fn: ?*const fn (context: ?*anyopaque, credential: Credential) anyerror!void = null,
2486
2664
  get_credential_fn: ?*const fn (context: ?*anyopaque, key: CredentialKey, buffer: []u8) anyerror![]const u8 = null,
2487
2665
  delete_credential_fn: ?*const fn (context: ?*anyopaque, key: CredentialKey) anyerror!void = null,
2666
+ /// Teardown detached a synchronous platform operation which may still
2667
+ /// use `context` after the runtime is gone. The platform must latch this
2668
+ /// notification and skip destruction of everything the callback can
2669
+ /// reach. First-party hosts share the channel-wake abandon latch because
2670
+ /// its lifetime obligation is identical. Loop-thread, teardown-only.
2671
+ note_blocking_call_abandoned_fn: ?*const fn (context: ?*anyopaque) void = null,
2672
+ format_local_time_fn: ?*const fn (context: ?*anyopaque, timestamp_ms: i64, style: LocalTimeStyle, buffer: []u8) anyerror![]const u8 = null,
2488
2673
  open_external_url_fn: ?*const fn (context: ?*anyopaque, url: []const u8) anyerror!void = null,
2489
2674
  reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2490
2675
  add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2491
2676
  clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2492
- create_tray_fn: ?*const fn (context: ?*anyopaque, options: TrayOptions) anyerror!void = null,
2493
- update_tray_menu_fn: ?*const fn (context: ?*anyopaque, items: []const TrayMenuItem) anyerror!void = null,
2494
- update_tray_title_fn: ?*const fn (context: ?*anyopaque, title: []const u8) anyerror!void = null,
2495
- remove_tray_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2677
+ create_tray_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, options: TrayOptions) anyerror!void = null,
2678
+ update_tray_shell_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, shell: TrayShell) anyerror!void = null,
2679
+ update_tray_menu_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, items: []const TrayMenuItem) anyerror!void = null,
2680
+ update_tray_title_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, title: []const u8) anyerror!void = null,
2681
+ update_tray_presentation_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId, presentation: TrayPresentation) anyerror!void = null,
2682
+ remove_tray_fn: ?*const fn (context: ?*anyopaque, status_item_id: StatusItemId) anyerror!void = null,
2496
2683
  configure_security_policy_fn: ?*const fn (context: ?*anyopaque, policy: security.Policy) anyerror!void = null,
2497
2684
  configure_menus_fn: ?*const fn (context: ?*anyopaque, menus: []const Menu) anyerror!void = null,
2498
2685
  configure_shortcuts_fn: ?*const fn (context: ?*anyopaque, shortcuts: []const Shortcut) anyerror!void = null,
@@ -2842,11 +3029,31 @@ pub const PlatformServices = struct {
2842
3029
  return minimize_fn(self.context, window_id);
2843
3030
  }
2844
3031
 
3032
+ pub fn hideWindow(self: PlatformServices, window_id: WindowId) anyerror!void {
3033
+ const hide_fn = self.hide_window_fn orelse return error.UnsupportedService;
3034
+ return hide_fn(self.context, window_id);
3035
+ }
3036
+
2845
3037
  pub fn showWindow(self: PlatformServices, window_id: WindowId) anyerror!void {
2846
3038
  const show_fn = self.show_window_fn orelse return error.UnsupportedService;
2847
3039
  return show_fn(self.context, window_id);
2848
3040
  }
2849
3041
 
3042
+ pub fn setDockPresence(self: PlatformServices, visible: bool) anyerror!void {
3043
+ const set_fn = self.set_dock_presence_fn orelse return error.UnsupportedService;
3044
+ return set_fn(self.context, visible);
3045
+ }
3046
+
3047
+ pub fn launchAtLoginStatus(self: PlatformServices) anyerror!LaunchAtLoginStatus {
3048
+ const status_fn = self.launch_at_login_status_fn orelse return error.UnsupportedService;
3049
+ return status_fn(self.context);
3050
+ }
3051
+
3052
+ pub fn setLaunchAtLogin(self: PlatformServices, enabled: bool) anyerror!LaunchAtLoginStatus {
3053
+ const set_fn = self.set_launch_at_login_fn orelse return error.UnsupportedService;
3054
+ return set_fn(self.context, enabled);
3055
+ }
3056
+
2850
3057
  pub fn quitApp(self: PlatformServices) anyerror!void {
2851
3058
  const quit_fn = self.quit_app_fn orelse return error.UnsupportedService;
2852
3059
  return quit_fn(self.context);
@@ -3006,6 +3213,16 @@ pub const PlatformServices = struct {
3006
3213
  return delete_fn(self.context, key);
3007
3214
  }
3008
3215
 
3216
+ pub fn noteBlockingCallAbandoned(self: PlatformServices) void {
3217
+ const note_fn = self.note_blocking_call_abandoned_fn orelse return;
3218
+ note_fn(self.context);
3219
+ }
3220
+
3221
+ pub fn formatLocalTime(self: PlatformServices, timestamp_ms: i64, style: LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
3222
+ const format_fn = self.format_local_time_fn orelse return error.UnsupportedService;
3223
+ return format_fn(self.context, timestamp_ms, style, buffer);
3224
+ }
3225
+
3009
3226
  pub fn openExternalUrl(self: PlatformServices, url: []const u8) anyerror!void {
3010
3227
  const open_fn = self.open_external_url_fn orelse return error.UnsupportedService;
3011
3228
  return open_fn(self.context, url);
@@ -3026,28 +3243,63 @@ pub const PlatformServices = struct {
3026
3243
  return clear_fn(self.context);
3027
3244
  }
3028
3245
 
3029
- pub fn createTray(self: PlatformServices, options: TrayOptions) anyerror!void {
3246
+ pub fn createStatusItem(self: PlatformServices, status_item_id: StatusItemId, options: TrayOptions) anyerror!void {
3030
3247
  const tray_fn = self.create_tray_fn orelse return error.UnsupportedService;
3031
- return tray_fn(self.context, options);
3248
+ return tray_fn(self.context, status_item_id, options);
3032
3249
  }
3033
3250
 
3034
- pub fn updateTrayMenu(self: PlatformServices, items: []const TrayMenuItem) anyerror!void {
3251
+ pub fn updateStatusItemShell(self: PlatformServices, status_item_id: StatusItemId, shell: TrayShell) anyerror!void {
3252
+ const update_fn = self.update_tray_shell_fn orelse return error.UnsupportedService;
3253
+ return update_fn(self.context, status_item_id, shell);
3254
+ }
3255
+
3256
+ pub fn updateStatusItemMenu(self: PlatformServices, status_item_id: StatusItemId, items: []const TrayMenuItem) anyerror!void {
3035
3257
  const update_fn = self.update_tray_menu_fn orelse return error.UnsupportedService;
3036
- return update_fn(self.context, items);
3258
+ return update_fn(self.context, status_item_id, items);
3037
3259
  }
3038
3260
 
3039
3261
  /// Retitle the live status-bar button without re-creating the item
3040
3262
  /// (re-creating flickers and can reshuffle the macOS menu bar). Added
3041
3263
  /// for model-driven tray state (e.g. an open-count badge in the
3042
3264
  /// title).
3043
- pub fn updateTrayTitle(self: PlatformServices, title: []const u8) anyerror!void {
3265
+ pub fn updateStatusItemTitle(self: PlatformServices, status_item_id: StatusItemId, title: []const u8) anyerror!void {
3044
3266
  const title_fn = self.update_tray_title_fn orelse return error.UnsupportedService;
3045
- return title_fn(self.context, title);
3267
+ return title_fn(self.context, status_item_id, title);
3046
3268
  }
3047
3269
 
3048
- pub fn removeTray(self: PlatformServices) anyerror!void {
3270
+ /// Patch all live menu-bar presentation fields without recreating the
3271
+ /// native item. A host that only implements title updates still gets a
3272
+ /// correct title and intentionally degrades the richer styling.
3273
+ pub fn updateStatusItemPresentation(self: PlatformServices, status_item_id: StatusItemId, presentation: TrayPresentation) anyerror!void {
3274
+ if (self.update_tray_presentation_fn) |update_fn| return update_fn(self.context, status_item_id, presentation);
3275
+ return self.updateStatusItemTitle(status_item_id, presentation.title);
3276
+ }
3277
+
3278
+ pub fn removeStatusItem(self: PlatformServices, status_item_id: StatusItemId) anyerror!void {
3049
3279
  const remove_fn = self.remove_tray_fn orelse return error.UnsupportedService;
3050
- return remove_fn(self.context);
3280
+ return remove_fn(self.context, status_item_id);
3281
+ }
3282
+
3283
+ // Backward-compatible singular tray surface. The reserved primary id is
3284
+ // the exact item older apps have always addressed implicitly.
3285
+ pub fn createTray(self: PlatformServices, options: TrayOptions) anyerror!void {
3286
+ return self.createStatusItem(primary_status_item_id, options);
3287
+ }
3288
+
3289
+ pub fn updateTrayMenu(self: PlatformServices, items: []const TrayMenuItem) anyerror!void {
3290
+ return self.updateStatusItemMenu(primary_status_item_id, items);
3291
+ }
3292
+
3293
+ pub fn updateTrayTitle(self: PlatformServices, title: []const u8) anyerror!void {
3294
+ return self.updateStatusItemTitle(primary_status_item_id, title);
3295
+ }
3296
+
3297
+ pub fn updateTrayPresentation(self: PlatformServices, presentation: TrayPresentation) anyerror!void {
3298
+ return self.updateStatusItemPresentation(primary_status_item_id, presentation);
3299
+ }
3300
+
3301
+ pub fn removeTray(self: PlatformServices) anyerror!void {
3302
+ return self.removeStatusItem(primary_status_item_id);
3051
3303
  }
3052
3304
 
3053
3305
  pub fn configureSecurityPolicy(self: PlatformServices, policy: security.Policy) anyerror!void {
@@ -3392,7 +3644,8 @@ fn defaultSupportsFeature(services: PlatformServices, feature: PlatformFeature)
3392
3644
  .reveal_path => services.reveal_path_fn != null,
3393
3645
  .notifications => services.show_notification_fn != null,
3394
3646
  .recent_documents => services.add_recent_document_fn != null or services.clear_recent_documents_fn != null,
3395
- .credentials => services.set_credential_fn != null and services.get_credential_fn != null and services.delete_credential_fn != null,
3647
+ .credentials => services.set_credential_fn != null and services.get_credential_fn != null and services.delete_credential_fn != null and
3648
+ services.note_blocking_call_abandoned_fn != null,
3396
3649
  .file_drops => false,
3397
3650
  .app_activation_events => false,
3398
3651
  .gpu_surfaces => false,