@native-sdk/cli 0.9.0 → 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 (92) hide show
  1. package/build/app.zig +331 -24
  2. package/build.zig +179 -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 +167 -12
  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 +11 -5
  26. package/skill-data/ts-core/SKILL.md +53 -20
  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 +29 -0
  31. package/src/app_runner/ts_core_main.zig +5 -0
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/automation/protocol.zig +5 -1
  34. package/src/automation/snapshot.zig +8 -6
  35. package/src/embed/app_exports.zig +1 -0
  36. package/src/embed/root.zig +1 -0
  37. package/src/embed/tests.zig +28 -0
  38. package/src/embed/ui_host.zig +68 -2
  39. package/src/platform/linux/cef_host.cpp +7 -1
  40. package/src/platform/linux/gtk_host.c +200 -5
  41. package/src/platform/linux/gtk_host.h +2 -1
  42. package/src/platform/linux/root.zig +69 -4
  43. package/src/platform/macos/appkit_host.h +11 -7
  44. package/src/platform/macos/appkit_host.m +210 -88
  45. package/src/platform/macos/cef_host.mm +210 -88
  46. package/src/platform/macos/root.zig +77 -30
  47. package/src/platform/null_platform.zig +234 -51
  48. package/src/platform/null_platform_tests.zig +39 -0
  49. package/src/platform/root.zig +10 -0
  50. package/src/platform/types.zig +105 -16
  51. package/src/platform/windows/root.zig +20 -6
  52. package/src/platform/windows/webview2_host.cpp +41 -5
  53. package/src/root.zig +7 -0
  54. package/src/runtime/api.zig +8 -0
  55. package/src/runtime/automation_commands.zig +35 -2
  56. package/src/runtime/automation_snapshot.zig +32 -24
  57. package/src/runtime/bridge_permission_tests.zig +35 -1
  58. package/src/runtime/bridge_responses.zig +1 -1
  59. package/src/runtime/builtin_bridge.zig +11 -1
  60. package/src/runtime/core.zig +12 -6
  61. package/src/runtime/effects.zig +1323 -35
  62. package/src/runtime/effects_file_tests.zig +587 -0
  63. package/src/runtime/effects_notification_tests.zig +11 -0
  64. package/src/runtime/file_access.zig +400 -0
  65. package/src/runtime/file_effect_crash_helper.zig +28 -0
  66. package/src/runtime/file_effect_crash_tests.zig +37 -0
  67. package/src/runtime/flow.zig +21 -9
  68. package/src/runtime/native_command_event_tests.zig +44 -2
  69. package/src/runtime/pty.zig +5 -2
  70. package/src/runtime/root.zig +5 -0
  71. package/src/runtime/session_blobs.zig +4 -1
  72. package/src/runtime/session_journal.zig +56 -5
  73. package/src/runtime/session_record.zig +38 -0
  74. package/src/runtime/session_replay.zig +97 -7
  75. package/src/runtime/session_tests.zig +81 -0
  76. package/src/runtime/state.zig +10 -0
  77. package/src/runtime/system_services.zig +129 -36
  78. package/src/runtime/ts_core_host.zig +281 -11
  79. package/src/runtime/ts_core_host_tests.zig +95 -1
  80. package/src/runtime/ts_ui_app.zig +461 -8
  81. package/src/runtime/ui_app.zig +321 -109
  82. package/src/runtime/ui_app_tests.zig +132 -6
  83. package/src/runtime/ui_app_window_tests.zig +61 -7
  84. package/src/runtime/validation.zig +20 -0
  85. package/src/tooling/templates.zig +28 -0
  86. package/src/tooling/ts_core.zig +83 -0
  87. package/tools/corewire/emit.zig +3 -3
  88. package/tools/corewire/emit_facade.zig +65 -5
  89. package/tools/corewire/emit_profile.zig +2 -2
  90. package/tools/corewire/emit_service.zig +2 -2
  91. package/tools/corewire/service_contract.zig +4 -4
  92. package/tools/corewire/sidecar.zig +4 -4
@@ -243,6 +243,9 @@ pub const max_recent_document_path_bytes: usize = 4096;
243
243
  pub const max_notification_title_bytes: usize = 128;
244
244
  pub const max_notification_subtitle_bytes: usize = 128;
245
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;
246
249
  pub const max_clipboard_mime_type_bytes: usize = 128;
247
250
  pub const max_clipboard_data_bytes: usize = 65536;
248
251
  pub const max_credential_service_bytes: usize = 128;
@@ -252,6 +255,10 @@ pub const max_credential_account_bytes: usize = 256;
252
255
  /// Every host accepts this whole range; none silently truncates it.
253
256
  pub const max_credential_secret_bytes: usize = 5 * 512;
254
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;
255
262
  pub const max_tray_items: usize = 32;
256
263
  pub const max_tray_icon_path_bytes: usize = 4096;
257
264
  pub const max_tray_title_bytes: usize = 64;
@@ -1372,9 +1379,17 @@ pub const MessageDialogOptions = struct {
1372
1379
  };
1373
1380
 
1374
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 = "",
1375
1385
  title: []const u8,
1376
1386
  subtitle: []const u8 = "",
1377
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 = "",
1378
1393
  };
1379
1394
 
1380
1395
  pub const CredentialKey = struct {
@@ -1397,6 +1412,8 @@ pub const LocalTimeStyle = enum(u8) {
1397
1412
  datetime,
1398
1413
  };
1399
1414
 
1415
+ pub const StatusItemId = u32;
1416
+ pub const primary_status_item_id: StatusItemId = 1;
1400
1417
  pub const TrayItemId = u32;
1401
1418
 
1402
1419
  /// Visual emphasis for the menu-bar button's live presentation. Hosts
@@ -1426,6 +1443,9 @@ pub const TrayOptions = struct {
1426
1443
  /// `NSStatusItem` menu-bar extras render it directly in the menu bar).
1427
1444
  title: []const u8 = "",
1428
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,
1429
1449
  items: []const TrayMenuItem = &.{},
1430
1450
  presentation: TrayPresentation = .{},
1431
1451
  /// Ordinary click, Option-click, and menu-open hooks. Each command
@@ -1435,6 +1455,29 @@ pub const TrayOptions = struct {
1435
1455
  open_command: []const u8 = "",
1436
1456
  };
1437
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
+
1438
1481
  /// Semantic status-menu rows. `command` is the ordinary actionable row;
1439
1482
  /// the others let a capable host render readouts without presenting them
1440
1483
  /// as disabled actions. Hosts without rich-menu support may degrade them
@@ -1477,6 +1520,22 @@ pub const MenuCommandEvent = struct {
1477
1520
  pub const TrayCommandEvent = struct {
1478
1521
  name: []const u8,
1479
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,
1480
1539
  };
1481
1540
 
1482
1541
  /// Timer ids at or above this value are reserved for the framework's own
@@ -2420,11 +2479,12 @@ pub const Event = union(enum) {
2420
2479
  window_focused: WindowId,
2421
2480
  view_focused: ViewFocusEvent,
2422
2481
  bridge_message: BridgeMessage,
2423
- tray_action: TrayItemId,
2482
+ tray_action: TrayActionEvent,
2424
2483
  shortcut: ShortcutEvent,
2425
2484
  native_command: NativeCommandEvent,
2426
2485
  menu_command: MenuCommandEvent,
2427
2486
  tray_command: TrayCommandEvent,
2487
+ notification_command: NotificationCommandEvent,
2428
2488
  timer: TimerEvent,
2429
2489
  /// A cross-thread nudge posted through `PlatformServices.wake_fn`:
2430
2490
  /// worker threads (effect executors) ask the platform loop to deliver
@@ -2463,6 +2523,7 @@ pub const Event = union(enum) {
2463
2523
  .native_command => "native_command",
2464
2524
  .menu_command => "menu_command",
2465
2525
  .tray_command => "tray_command",
2526
+ .notification_command => "notification_command",
2466
2527
  .timer => "timer",
2467
2528
  .wake => "wake",
2468
2529
  .files_dropped => "files_dropped",
@@ -2613,11 +2674,12 @@ pub const PlatformServices = struct {
2613
2674
  reveal_path_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2614
2675
  add_recent_document_fn: ?*const fn (context: ?*anyopaque, path: []const u8) anyerror!void = null,
2615
2676
  clear_recent_documents_fn: ?*const fn (context: ?*anyopaque) anyerror!void = null,
2616
- create_tray_fn: ?*const fn (context: ?*anyopaque, options: TrayOptions) anyerror!void = null,
2617
- update_tray_menu_fn: ?*const fn (context: ?*anyopaque, items: []const TrayMenuItem) anyerror!void = null,
2618
- update_tray_title_fn: ?*const fn (context: ?*anyopaque, title: []const u8) anyerror!void = null,
2619
- update_tray_presentation_fn: ?*const fn (context: ?*anyopaque, presentation: TrayPresentation) anyerror!void = null,
2620
- 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,
2621
2683
  configure_security_policy_fn: ?*const fn (context: ?*anyopaque, policy: security.Policy) anyerror!void = null,
2622
2684
  configure_menus_fn: ?*const fn (context: ?*anyopaque, menus: []const Menu) anyerror!void = null,
2623
2685
  configure_shortcuts_fn: ?*const fn (context: ?*anyopaque, shortcuts: []const Shortcut) anyerror!void = null,
@@ -3181,36 +3243,63 @@ pub const PlatformServices = struct {
3181
3243
  return clear_fn(self.context);
3182
3244
  }
3183
3245
 
3184
- pub fn createTray(self: PlatformServices, options: TrayOptions) anyerror!void {
3246
+ pub fn createStatusItem(self: PlatformServices, status_item_id: StatusItemId, options: TrayOptions) anyerror!void {
3185
3247
  const tray_fn = self.create_tray_fn orelse return error.UnsupportedService;
3186
- return tray_fn(self.context, options);
3248
+ return tray_fn(self.context, status_item_id, options);
3187
3249
  }
3188
3250
 
3189
- 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 {
3190
3257
  const update_fn = self.update_tray_menu_fn orelse return error.UnsupportedService;
3191
- return update_fn(self.context, items);
3258
+ return update_fn(self.context, status_item_id, items);
3192
3259
  }
3193
3260
 
3194
3261
  /// Retitle the live status-bar button without re-creating the item
3195
3262
  /// (re-creating flickers and can reshuffle the macOS menu bar). Added
3196
3263
  /// for model-driven tray state (e.g. an open-count badge in the
3197
3264
  /// title).
3198
- 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 {
3199
3266
  const title_fn = self.update_tray_title_fn orelse return error.UnsupportedService;
3200
- return title_fn(self.context, title);
3267
+ return title_fn(self.context, status_item_id, title);
3201
3268
  }
3202
3269
 
3203
3270
  /// Patch all live menu-bar presentation fields without recreating the
3204
3271
  /// native item. A host that only implements title updates still gets a
3205
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 {
3279
+ const remove_fn = self.remove_tray_fn orelse return error.UnsupportedService;
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
+
3206
3297
  pub fn updateTrayPresentation(self: PlatformServices, presentation: TrayPresentation) anyerror!void {
3207
- if (self.update_tray_presentation_fn) |update_fn| return update_fn(self.context, presentation);
3208
- return self.updateTrayTitle(presentation.title);
3298
+ return self.updateStatusItemPresentation(primary_status_item_id, presentation);
3209
3299
  }
3210
3300
 
3211
3301
  pub fn removeTray(self: PlatformServices) anyerror!void {
3212
- const remove_fn = self.remove_tray_fn orelse return error.UnsupportedService;
3213
- return remove_fn(self.context);
3302
+ return self.removeStatusItem(primary_status_item_id);
3214
3303
  }
3215
3304
 
3216
3305
  pub fn configureSecurityPolicy(self: PlatformServices, policy: security.Policy) anyerror!void {
@@ -41,6 +41,7 @@ const WindowsEventKind = enum(c_int) {
41
41
  context_menu_action = 19,
42
42
  view_focused = 20,
43
43
  tray_command = 21,
44
+ notification_command = 22,
44
45
  };
45
46
 
46
47
  const WindowsEvent = extern struct {
@@ -188,7 +189,7 @@ extern fn native_sdk_windows_reveal_path(host: *WindowsHost, path: [*]const u8,
188
189
  extern fn native_sdk_windows_show_open_dialog(host: *WindowsHost, opts: *const WindowsOpenDialogOpts, buffer: [*]u8, buffer_len: usize) WindowsOpenDialogResult;
189
190
  extern fn native_sdk_windows_show_save_dialog(host: *WindowsHost, opts: *const WindowsSaveDialogOpts, buffer: [*]u8, buffer_len: usize) usize;
190
191
  extern fn native_sdk_windows_show_message_dialog(host: *WindowsHost, opts: *const WindowsMessageDialogOpts) c_int;
191
- extern fn native_sdk_windows_show_notification(host: *WindowsHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize) c_int;
192
+ extern fn native_sdk_windows_show_notification(host: *WindowsHost, title: [*]const u8, title_len: usize, subtitle: [*]const u8, subtitle_len: usize, body: [*]const u8, body_len: usize, notification_id: [*]const u8, notification_id_len: usize, action_label: [*]const u8, action_label_len: usize, action_command: [*]const u8, action_command_len: usize) c_int;
192
193
  extern fn native_sdk_windows_create_tray(host: *WindowsHost, icon_path: [*]const u8, icon_path_len: usize, tooltip: [*]const u8, tooltip_len: usize, activation_command: [*]const u8, activation_command_len: usize, alternate_activation_command: [*]const u8, alternate_activation_command_len: usize, open_command: [*]const u8, open_command_len: usize) c_int;
193
194
  extern fn native_sdk_windows_update_tray_menu(host: *WindowsHost, item_ids: [*]const u32, labels: [*]const [*]const u8, label_lens: [*]const usize, separators: [*]const c_int, enabled_flags: [*]const c_int, details: [*]const [*]const u8, detail_lens: [*]const usize, roles: [*]const c_int, keys: [*]const [*]const u8, key_lens: [*]const usize, modifiers: [*]const u32, count: usize) c_int;
194
195
  extern fn native_sdk_windows_remove_tray(host: *WindowsHost) void;
@@ -675,11 +676,15 @@ fn windowsCallback(context: ?*anyopaque, event: *const WindowsEvent) callconv(.c
675
676
  .name = event.command_name[0..event.command_name_len],
676
677
  .window_id = event.window_id,
677
678
  } }),
678
- .tray_action => state.emit(.{ .tray_action = event.tray_item_id }),
679
+ .tray_action => state.emit(.{ .tray_action = .{ .item_id = event.tray_item_id } }),
679
680
  .tray_command => state.emit(.{ .tray_command = .{
680
681
  .name = event.command_name[0..event.command_name_len],
681
682
  .window_id = event.window_id,
682
683
  } }),
684
+ .notification_command => state.emit(.{ .notification_command = .{
685
+ .name = event.command_name[0..event.command_name_len],
686
+ .window_id = event.window_id,
687
+ } }),
683
688
  .gpu_surface_frame => state.emit(.{ .gpu_surface_frame = gpuSurfaceFrameEventFromWindowsEvent(event) }),
684
689
  .gpu_surface_resize => state.emit(.{ .gpu_surface_resized = .{
685
690
  .window_id = event.window_id,
@@ -1488,13 +1493,20 @@ fn showNotification(context: ?*anyopaque, options: platform_mod.NotificationOpti
1488
1493
  options.subtitle.len,
1489
1494
  options.body.ptr,
1490
1495
  options.body.len,
1496
+ options.id.ptr,
1497
+ options.id.len,
1498
+ options.action_label.ptr,
1499
+ options.action_label.len,
1500
+ options.action_command.ptr,
1501
+ options.action_command.len,
1491
1502
  ) == 0) return error.UnsupportedService;
1492
1503
  }
1493
1504
 
1494
1505
  const max_tray_items: usize = 32;
1495
1506
 
1496
- fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!void {
1507
+ fn createTray(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId, options: platform_mod.TrayOptions) anyerror!void {
1497
1508
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1509
+ if (status_item_id != platform_mod.primary_status_item_id) return error.UnsupportedService;
1498
1510
  if (self.web_engine != .system) return error.UnsupportedService;
1499
1511
  if (native_sdk_windows_create_tray(
1500
1512
  self.host,
@@ -1510,12 +1522,13 @@ fn createTray(context: ?*anyopaque, options: platform_mod.TrayOptions) anyerror!
1510
1522
  options.open_command.len,
1511
1523
  ) == 0) return error.UnsupportedService;
1512
1524
  if (options.items.len > 0) {
1513
- try updateTrayMenu(context, options.items);
1525
+ try updateTrayMenu(context, status_item_id, options.items);
1514
1526
  }
1515
1527
  }
1516
1528
 
1517
- fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem) anyerror!void {
1529
+ fn updateTrayMenu(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId, items: []const platform_mod.TrayMenuItem) anyerror!void {
1518
1530
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1531
+ if (status_item_id != platform_mod.primary_status_item_id) return error.UnsupportedService;
1519
1532
  if (self.web_engine != .system) return error.UnsupportedService;
1520
1533
  const count = @min(items.len, max_tray_items);
1521
1534
  var ids: [max_tray_items]u32 = undefined;
@@ -1556,8 +1569,9 @@ fn updateTrayMenu(context: ?*anyopaque, items: []const platform_mod.TrayMenuItem
1556
1569
  if (native_sdk_windows_update_tray_menu(self.host, &ids, &labels, &label_lens, &separators, &enabled_flags, &details, &detail_lens, &roles, &keys, &key_lens, &modifiers, count) == 0) return error.UnsupportedService;
1557
1570
  }
1558
1571
 
1559
- fn removeTray(context: ?*anyopaque) anyerror!void {
1572
+ fn removeTray(context: ?*anyopaque, status_item_id: platform_mod.StatusItemId) anyerror!void {
1560
1573
  const self: *WindowsPlatform = @ptrCast(@alignCast(context.?));
1574
+ if (status_item_id != platform_mod.primary_status_item_id) return error.UnsupportedService;
1561
1575
  if (self.web_engine != .system) return error.UnsupportedService;
1562
1576
  native_sdk_windows_remove_tray(self.host);
1563
1577
  }
@@ -139,6 +139,7 @@ enum EventKind {
139
139
  kContextMenuAction = 19,
140
140
  kViewFocused = 20,
141
141
  kTrayCommand = 21,
142
+ kNotificationCommand = 22,
142
143
  };
143
144
 
144
145
  constexpr uint32_t kShortcutModifierPrimary = 1u << 0;
@@ -718,6 +719,9 @@ struct Host {
718
719
  int external_link_action = 0;
719
720
  bool app_active = false;
720
721
  bool notification_icon_added = false;
722
+ std::string notification_id;
723
+ std::string notification_action_label;
724
+ std::string notification_action_command;
721
725
  bool tray_active = false;
722
726
  AppTimer app_timers[kMaxAppTimers];
723
727
  /* Last emitted appearance values; -1 = nothing emitted yet, so the
@@ -1593,6 +1597,22 @@ static bool emitStatusCommand(Host *host, HWND hwnd, const std::string &command)
1593
1597
  return true;
1594
1598
  }
1595
1599
 
1600
+ static bool emitNotificationCommand(Host *host, HWND hwnd) {
1601
+ if (!host || !host->callback || host->notification_action_command.empty()) return false;
1602
+ std::string command = host->notification_action_command;
1603
+ host->notification_id.clear();
1604
+ host->notification_action_label.clear();
1605
+ host->notification_action_command.clear();
1606
+ const Window *window = windowForHwnd(host, hwnd);
1607
+ WindowsEvent event = {};
1608
+ event.kind = kNotificationCommand;
1609
+ event.window_id = window ? window->id : 1;
1610
+ event.command_name = command.c_str();
1611
+ event.command_name_len = command.size();
1612
+ host->callback(host->callback_context, &event);
1613
+ return true;
1614
+ }
1615
+
1596
1616
  static void showTrayMenu(Host *host, HWND hwnd) {
1597
1617
  if (!host || !host->tray_active || !hwnd) return;
1598
1618
  emitStatusCommand(host, hwnd, host->tray_open_command);
@@ -5095,7 +5115,7 @@ static const wchar_t *nativeSdkBridgeScript() {
5095
5115
  });
5096
5116
  var os=Object.freeze({
5097
5117
  openUrl:function(value){var options=typeof value==='string'?{url:value}:(value||{});return invoke('native-sdk.os.openUrl',{url:ensureString(options.url,'url')});},
5098
- showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}return invoke('native-sdk.os.showNotification',payload);},
5118
+ showNotification:function(value){var options=typeof value==='string'?{title:value}:(value||{});var payload={title:ensureString(options.title,'title')};if(options.id!=null){payload.id=ensureString(options.id,'id');}if(options.subtitle!=null){payload.subtitle=ensureString(options.subtitle,'subtitle');}if(options.body!=null){payload.body=ensureString(options.body,'body');}if(options.actionLabel!=null){payload.actionLabel=ensureString(options.actionLabel,'actionLabel');}if(options.actionCommand!=null){payload.actionCommand=ensureString(options.actionCommand,'actionCommand');}return invoke('native-sdk.os.showNotification',payload);},
5099
5119
  revealPath:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.revealPath',{path:ensureString(options.path,'path')});},
5100
5120
  addRecentDocument:function(value){var options=typeof value==='string'?{path:value}:(value||{});return invoke('native-sdk.os.addRecentDocument',{path:ensureString(options.path,'path')});},
5101
5121
  clearRecentDocuments:function(){return invoke('native-sdk.os.clearRecentDocuments',{});}
@@ -5688,8 +5708,12 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
5688
5708
  if (host) showAppContextMenu(host, hwnd);
5689
5709
  return 0;
5690
5710
  case kNotificationCallbackMessage:
5691
- if (host && host->tray_active) {
5711
+ if (host) {
5692
5712
  UINT tray_event = LOWORD(lparam);
5713
+ if (tray_event == NIN_BALLOONUSERCLICK && emitNotificationCommand(host, hwnd)) {
5714
+ return 0;
5715
+ }
5716
+ if (!host->tray_active) break;
5693
5717
  if (tray_event == NIN_SELECT || tray_event == NIN_KEYSELECT || tray_event == WM_LBUTTONUP) {
5694
5718
  if (keyDown(VK_MENU) && !host->tray_alternate_activation_command.empty()) {
5695
5719
  emitStatusCommand(host, hwnd, host->tray_alternate_activation_command);
@@ -7452,9 +7476,13 @@ int native_sdk_windows_show_message_dialog(Host *host, const WindowsMessageDialo
7452
7476
  return 0;
7453
7477
  }
7454
7478
 
7455
- int native_sdk_windows_show_notification(Host *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len) {
7479
+ int native_sdk_windows_show_notification(Host *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len) {
7456
7480
  if (!host || !title || title_len == 0) return 0;
7457
- if ((subtitle_len > 0 && !subtitle) || (body_len > 0 && !body)) return 0;
7481
+ if ((subtitle_len > 0 && !subtitle) || (body_len > 0 && !body) ||
7482
+ (notification_id_len > 0 && !notification_id) ||
7483
+ (action_label_len > 0 && !action_label) ||
7484
+ (action_command_len > 0 && !action_command) ||
7485
+ ((action_label_len == 0) != (action_command_len == 0))) return 0;
7458
7486
  if (!ensureNotificationIcon(host)) return 0;
7459
7487
 
7460
7488
  std::wstring title_wide = widen(slice(title, title_len));
@@ -7462,6 +7490,10 @@ int native_sdk_windows_show_notification(Host *host, const char *title, size_t t
7462
7490
  if (subtitle && subtitle_len > 0) body_wide += widen(slice(subtitle, subtitle_len));
7463
7491
  if (subtitle_len > 0 && body_len > 0) body_wide += L"\n";
7464
7492
  if (body && body_len > 0) body_wide += widen(slice(body, body_len));
7493
+ if (action_label_len > 0) {
7494
+ if (!body_wide.empty()) body_wide += L"\n\n";
7495
+ body_wide += L"[" + widen(slice(action_label, action_label_len)) + L"]";
7496
+ }
7465
7497
 
7466
7498
  NOTIFYICONDATAW data = notificationIconData(host);
7467
7499
  if (!data.hWnd) return 0;
@@ -7469,7 +7501,11 @@ int native_sdk_windows_show_notification(Host *host, const char *title, size_t t
7469
7501
  data.dwInfoFlags = NIIF_INFO;
7470
7502
  copyWideField(data.szInfoTitle, ARRAYSIZE(data.szInfoTitle), title_wide);
7471
7503
  copyWideField(data.szInfo, ARRAYSIZE(data.szInfo), body_wide);
7472
- return Shell_NotifyIconW(NIM_MODIFY, &data) ? 1 : 0;
7504
+ if (!Shell_NotifyIconW(NIM_MODIFY, &data)) return 0;
7505
+ host->notification_id = slice(notification_id, notification_id_len);
7506
+ host->notification_action_label = slice(action_label, action_label_len);
7507
+ host->notification_action_command = slice(action_command, action_command_len);
7508
+ return 1;
7473
7509
  }
7474
7510
 
7475
7511
  int native_sdk_windows_create_tray(Host *host, const char *icon_path, size_t icon_path_len, const char *tooltip, size_t tooltip_len, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len) {
package/src/root.zig CHANGED
@@ -44,8 +44,12 @@ pub const FetchResponseMode = runtime.FetchResponseMode;
44
44
  pub const EffectResponse = runtime.EffectResponse;
45
45
  pub const EffectFetchOutcome = runtime.EffectFetchOutcome;
46
46
  pub const EffectFileOp = runtime.EffectFileOp;
47
+ pub const EffectFileEvent = runtime.EffectFileEvent;
47
48
  pub const EffectFileOutcome = runtime.EffectFileOutcome;
48
49
  pub const EffectFileResult = runtime.EffectFileResult;
50
+ pub const FileAccessBinding = runtime.FileAccessBinding;
51
+ pub const effect_file_stream_chunk_bytes = runtime.effect_file_stream_chunk_bytes;
52
+ pub const max_effect_file_streams = runtime.max_effect_file_streams;
49
53
  pub const EffectCredentialsOperation = runtime.EffectCredentialsOperation;
50
54
  pub const EffectCredentialsOutcome = runtime.EffectCredentialsOutcome;
51
55
  pub const EffectCredentialsResult = runtime.EffectCredentialsResult;
@@ -240,8 +244,11 @@ pub const MessageDialogStyle = platform.MessageDialogStyle;
240
244
  pub const MessageDialogResult = platform.MessageDialogResult;
241
245
  pub const MessageDialogOptions = platform.MessageDialogOptions;
242
246
  pub const NotificationOptions = platform.NotificationOptions;
247
+ pub const StatusItemId = platform.StatusItemId;
248
+ pub const primary_status_item_id = platform.primary_status_item_id;
243
249
  pub const TrayItemId = platform.TrayItemId;
244
250
  pub const TrayOptions = platform.TrayOptions;
251
+ pub const TrayShell = platform.TrayShell;
245
252
  pub const TrayMenuItem = platform.TrayMenuItem;
246
253
  pub const BridgeDispatcher = bridge.Dispatcher;
247
254
  pub const BridgePolicy = bridge.Policy;
@@ -27,6 +27,7 @@ pub const CommandEvent = struct {
27
27
  source: CommandSource = .runtime,
28
28
  window_id: platform.WindowId = 0,
29
29
  view_label: []const u8 = "",
30
+ status_item_id: platform.StatusItemId = 0,
30
31
  tray_item_id: platform.TrayItemId = 0,
31
32
  };
32
33
 
@@ -38,6 +39,7 @@ pub const CommandSource = enum {
38
39
  shortcut,
39
40
  toolbar,
40
41
  tray,
42
+ notification,
41
43
  native_view,
42
44
  bridge,
43
45
  };
@@ -500,6 +502,12 @@ pub const Options = struct {
500
502
  /// checked separately; both gates must be open before core effects may
501
503
  /// reach the platform keychain.
502
504
  credentials_enabled: bool = false,
505
+ /// Raw-file policy resolved by the app runner. Six app-owned roots are
506
+ /// allowed without a grant; `filesystem` opens arbitrary paths.
507
+ /// Standard runners install the six resolved app-owned roots here. If a
508
+ /// custom runner omits the binding, UiApp fails closed with no exempt roots
509
+ /// while still honoring an explicit `filesystem` permission.
510
+ file_access: ?runtime_effects.FileAccessBinding = null,
503
511
  js_window_api: bool = false,
504
512
  /// Whether this build ships the embedded web layer. The app runner
505
513
  /// sets it from the build graph's app.zon inference (declare-to-use:
@@ -153,8 +153,8 @@ pub fn parseAutomationCommandName(value: []const u8) ![]const u8 {
153
153
  return trimmed[0..separator];
154
154
  }
155
155
 
156
- /// `tray-action <item-id>`: the numeric dropdown item id printed by the
157
- /// snapshot's `tray-item #N` lines (bare number, like widget ids).
156
+ /// Parses the one-id `tray-action <item-id>` compatibility form: the
157
+ /// numeric dropdown row id printed by a primary item's `tray-item #N` line.
158
158
  pub fn parseAutomationTrayItemId(value: []const u8) !platform.TrayItemId {
159
159
  const trimmed = std.mem.trim(u8, value, " \n\r\t");
160
160
  if (trimmed.len == 0) return error.InvalidCommand;
@@ -164,6 +164,27 @@ pub fn parseAutomationTrayItemId(value: []const u8) !platform.TrayItemId {
164
164
  return id;
165
165
  }
166
166
 
167
+ pub const AutomationTrayTarget = struct {
168
+ status_item_id: platform.StatusItemId = platform.primary_status_item_id,
169
+ item_id: platform.TrayItemId,
170
+ };
171
+
172
+ /// `tray-action <item-id>` targets the reserved primary status item;
173
+ /// `tray-action <status-item-id> <item-id>` addresses any live item.
174
+ pub fn parseAutomationTrayTarget(value: []const u8) !AutomationTrayTarget {
175
+ var tokens = std.mem.tokenizeAny(u8, value, " \t\r\n");
176
+ const first = tokens.next() orelse return error.InvalidCommand;
177
+ const second = tokens.next();
178
+ if (tokens.next() != null) return error.InvalidCommand;
179
+ if (second) |item_text| {
180
+ const status_item_id = std.fmt.parseUnsigned(platform.StatusItemId, first, 10) catch return error.InvalidCommand;
181
+ const item_id = std.fmt.parseUnsigned(platform.TrayItemId, item_text, 10) catch return error.InvalidCommand;
182
+ if (status_item_id == 0 or item_id == 0) return error.InvalidCommand;
183
+ return .{ .status_item_id = status_item_id, .item_id = item_id };
184
+ }
185
+ return .{ .item_id = try parseAutomationTrayItemId(first) };
186
+ }
187
+
167
188
  pub fn parseAutomationViewLabel(value: []const u8) ![]const u8 {
168
189
  const trimmed = std.mem.trim(u8, value, " \n\r\t");
169
190
  if (trimmed.len == 0) return error.InvalidCommand;
@@ -601,6 +622,18 @@ test "runtime parses automation tray item ids" {
601
622
  try std.testing.expectError(error.InvalidCommand, parseAutomationTrayItemId("4 5"));
602
623
  }
603
624
 
625
+ test "runtime parses primary and explicit automation tray targets" {
626
+ const primary = try parseAutomationTrayTarget("4");
627
+ try std.testing.expectEqual(platform.primary_status_item_id, primary.status_item_id);
628
+ try std.testing.expectEqual(@as(platform.TrayItemId, 4), primary.item_id);
629
+ const explicit = try parseAutomationTrayTarget("23 12");
630
+ try std.testing.expectEqual(@as(platform.StatusItemId, 23), explicit.status_item_id);
631
+ try std.testing.expectEqual(@as(platform.TrayItemId, 12), explicit.item_id);
632
+ try std.testing.expectError(error.InvalidCommand, parseAutomationTrayTarget("0 2"));
633
+ try std.testing.expectError(error.InvalidCommand, parseAutomationTrayTarget("2 0"));
634
+ try std.testing.expectError(error.InvalidCommand, parseAutomationTrayTarget("1 2 3"));
635
+ }
636
+
604
637
  test "runtime parses automation widget click targets" {
605
638
  const target = try parseAutomationWidgetTarget("canvas 42");
606
639
  try std.testing.expectEqualStrings("canvas", target.view_label);
@@ -32,7 +32,7 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
32
32
  .widgets = &.{},
33
33
  .diagnostics = automationDiagnostics(self),
34
34
  .frame_profile = automationFrameProfile(self),
35
- .tray = automationTray(self),
35
+ .trays = automationTrays(self),
36
36
  .audio = automationAudio(self),
37
37
  .video = automationVideo(self),
38
38
  .errors = self.dispatchErrors(),
@@ -66,7 +66,7 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
66
66
  .widgets = self.automation_widgets[0..widget_count],
67
67
  .diagnostics = automationDiagnostics(self),
68
68
  .frame_profile = automationFrameProfile(self),
69
- .tray = automationTray(self),
69
+ .trays = automationTrays(self),
70
70
  .audio = automationAudio(self),
71
71
  .video = automationVideo(self),
72
72
  .errors = self.dispatchErrors(),
@@ -79,30 +79,38 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
79
79
  };
80
80
  }
81
81
 
82
- /// The live tray as the runtime last applied it: title +
83
- /// dropdown rows, or null when no status item exists. The menu
84
- /// bar is outside every window capture, so the snapshot is the
85
- /// only automation-visible evidence of the model-driven tray.
86
- fn automationTray(self: *Runtime) ?automation.snapshot.Tray {
87
- if (!self.tray_created) return null;
88
- const count = @min(self.tray_item_count, self.automation_tray_items.len);
89
- for (self.tray_items[0..count], 0..) |item, index| {
90
- self.automation_tray_items[index] = .{
91
- .id = item.id,
92
- .label = item.label,
93
- .command = item.command,
94
- .separator = item.separator,
95
- .enabled = item.enabled,
96
- .detail = item.detail,
97
- .role = item.role,
98
- .key = item.key,
99
- .modifiers = item.modifiers,
82
+ /// Every live status item as the runtime last applied it. Menu
83
+ /// bar contents live outside window captures, so identifiers
84
+ /// are explicit in both snapshots and automation commands.
85
+ fn automationTrays(self: *Runtime) []const automation.snapshot.Tray {
86
+ var tray_count: usize = 0;
87
+ var item_offset: usize = 0;
88
+ for (self.status_items) |status_item| {
89
+ if (!status_item.active or tray_count >= self.automation_trays.len) continue;
90
+ const count = @min(status_item.item_count, self.automation_tray_items.len - item_offset);
91
+ for (status_item.items[0..count], 0..) |item, index| {
92
+ self.automation_tray_items[item_offset + index] = .{
93
+ .id = item.id,
94
+ .label = item.label,
95
+ .command = item.command,
96
+ .separator = item.separator,
97
+ .enabled = item.enabled,
98
+ .detail = item.detail,
99
+ .role = item.role,
100
+ .key = item.key,
101
+ .modifiers = item.modifiers,
102
+ };
103
+ }
104
+ self.automation_trays[tray_count] = .{
105
+ .id = status_item.id,
106
+ .visible = status_item.visible,
107
+ .title = status_item.title,
108
+ .items = self.automation_tray_items[item_offset .. item_offset + count],
100
109
  };
110
+ tray_count += 1;
111
+ item_offset += count;
101
112
  }
102
- return .{
103
- .title = self.tray_title,
104
- .items = self.automation_tray_items[0..count],
105
- };
113
+ return self.automation_trays[0..tray_count];
106
114
  }
107
115
 
108
116
  /// Live audio playback as the ui-app layer last mirrored it