@native-sdk/cli 0.8.4 → 0.9.0

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 (146) hide show
  1. package/build/app.zig +859 -62
  2. package/build.zig +543 -13
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +2 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +365 -2
  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/npm_static_spike.mjs +64 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
  13. package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
  14. package/packages/core/scripts/stage_external_core.mjs +9 -1
  15. package/packages/core/scripts/stage_external_services.mjs +172 -0
  16. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  17. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  18. package/packages/core/sdk/core.d.ts +149 -0
  19. package/packages/core/sdk/core.ts +529 -12
  20. package/packages/core/sdk/events.d.ts +36 -0
  21. package/packages/core/sdk/events.ts +57 -0
  22. package/packages/core/src/checker.ts +468 -15
  23. package/packages/core/src/cli.ts +143 -3
  24. package/packages/core/src/contract.ts +26 -5
  25. package/packages/core/src/devhost.ts +1847 -16
  26. package/packages/core/src/devhost_journal.mjs +181 -0
  27. package/packages/core/src/devhost_resolver.mjs +17 -1
  28. package/packages/core/src/devhost_service_worker.mjs +90 -0
  29. package/packages/core/src/diagnostics.ts +82 -16
  30. package/packages/core/src/frontend.ts +204 -34
  31. package/packages/core/src/modules.ts +129 -80
  32. package/packages/core/src/service_contract.ts +597 -0
  33. package/packages/core/src/sqlite_cli.ts +93 -0
  34. package/packages/core/src/sqlite_codegen.ts +806 -0
  35. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  36. package/packages/core/src/typed_ast.ts +36 -8
  37. package/skill-data/core/references/project-anatomy.md +1 -1
  38. package/skill-data/native-ui/SKILL.md +47 -0
  39. package/skill-data/ts-core/SKILL.md +80 -31
  40. package/skill-data/ts-services/SKILL.md +126 -0
  41. package/skill-data/ts-services/references/service-surface.md +603 -0
  42. package/skill-data/zig/SKILL.md +1 -1
  43. package/skills/native-sdk/SKILL.md +1 -1
  44. package/src/app_runner/no_migrations.zig +3 -0
  45. package/src/app_runner/no_services.zig +20 -0
  46. package/src/app_runner/root.zig +104 -4
  47. package/src/app_runner/ts_core_main.zig +249 -8
  48. package/src/automation/snapshot.zig +23 -5
  49. package/src/embed/app_exports.zig +11 -1
  50. package/src/embed/c_api.zig +48 -2
  51. package/src/embed/conversions.zig +4 -5
  52. package/src/embed/host.zig +109 -1
  53. package/src/embed/root.zig +7 -0
  54. package/src/embed/tests.zig +213 -0
  55. package/src/embed/types.zig +51 -0
  56. package/src/embed/ui_host.zig +119 -5
  57. package/src/platform/android/NativeSdkActivity.java +131 -0
  58. package/src/platform/android/android_host.c +182 -1
  59. package/src/platform/android/native_sdk_app.h +17 -0
  60. package/src/platform/ios/native_sdk_app.h +17 -0
  61. package/src/platform/ios/uikit_host.m +115 -0
  62. package/src/platform/linux/cef_host.cpp +1 -1
  63. package/src/platform/linux/gtk_host.c +89 -17
  64. package/src/platform/linux/gtk_host.h +3 -0
  65. package/src/platform/linux/root.zig +40 -18
  66. package/src/platform/macos/appkit_host.h +16 -3
  67. package/src/platform/macos/appkit_host.m +536 -36
  68. package/src/platform/macos/cef_host.mm +248 -36
  69. package/src/platform/macos/root.zig +244 -34
  70. package/src/platform/null_platform.zig +223 -19
  71. package/src/platform/null_platform_tests.zig +74 -0
  72. package/src/platform/root.zig +9 -0
  73. package/src/platform/types.zig +179 -15
  74. package/src/platform/windows/root.zig +187 -21
  75. package/src/platform/windows/webview2_host.cpp +293 -46
  76. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  77. package/src/primitives/app_manifest/root.zig +4 -0
  78. package/src/primitives/app_manifest/tests.zig +3 -0
  79. package/src/primitives/app_manifest/types.zig +32 -0
  80. package/src/primitives/app_manifest/validation.zig +19 -1
  81. package/src/root.zig +46 -0
  82. package/src/runtime/api.zig +11 -0
  83. package/src/runtime/automation_snapshot.zig +4 -0
  84. package/src/runtime/bridge_permission_tests.zig +23 -2
  85. package/src/runtime/bridge_responses.zig +3 -1
  86. package/src/runtime/canvas_frame.zig +18 -11
  87. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  88. package/src/runtime/clock.zig +13 -1
  89. package/src/runtime/core.zig +133 -1
  90. package/src/runtime/credentials_store.zig +115 -0
  91. package/src/runtime/effects.zig +2295 -113
  92. package/src/runtime/effects_credentials_tests.zig +332 -0
  93. package/src/runtime/effects_host_tests.zig +208 -1
  94. package/src/runtime/effects_relational_tests.zig +314 -0
  95. package/src/runtime/effects_store_tests.zig +211 -0
  96. package/src/runtime/flow.zig +14 -1
  97. package/src/runtime/gpu_surface_events.zig +6 -1
  98. package/src/runtime/native_command_event_tests.zig +42 -0
  99. package/src/runtime/persist_store.zig +666 -0
  100. package/src/runtime/record_store.zig +788 -0
  101. package/src/runtime/relational_store.zig +854 -0
  102. package/src/runtime/root.zig +49 -0
  103. package/src/runtime/runtime_event_tests.zig +70 -0
  104. package/src/runtime/service_host.zig +711 -0
  105. package/src/runtime/service_pool.zig +1314 -0
  106. package/src/runtime/session_blobs.zig +1 -1
  107. package/src/runtime/session_journal.zig +102 -0
  108. package/src/runtime/session_record.zig +177 -0
  109. package/src/runtime/session_replay.zig +109 -4
  110. package/src/runtime/shell_layout.zig +1 -0
  111. package/src/runtime/shell_layout_tests.zig +120 -0
  112. package/src/runtime/sqlite_engine.zig +474 -0
  113. package/src/runtime/state.zig +6 -0
  114. package/src/runtime/system_services.zig +49 -10
  115. package/src/runtime/tests.zig +4 -0
  116. package/src/runtime/ts_core_host.zig +788 -86
  117. package/src/runtime/ts_core_host_tests.zig +231 -11
  118. package/src/runtime/ts_ui_app.zig +499 -1
  119. package/src/runtime/ui_app.zig +142 -16
  120. package/src/runtime/ui_app_tests.zig +155 -5
  121. package/src/runtime/validation.zig +22 -0
  122. package/src/runtime/view.zig +9 -0
  123. package/src/runtime/window_storage.zig +1 -0
  124. package/src/runtime/window_view_runtime.zig +2 -3
  125. package/src/runtime/window_views.zig +19 -0
  126. package/src/tooling/android.zig +21 -16
  127. package/src/tooling/db.zig +160 -0
  128. package/src/tooling/ios.zig +7 -1
  129. package/src/tooling/manifest.zig +214 -2
  130. package/src/tooling/package.zig +116 -0
  131. package/src/tooling/raw_manifest.zig +30 -0
  132. package/src/tooling/root.zig +1 -0
  133. package/src/tooling/templates.zig +161 -4
  134. package/src/tooling/ts_core.zig +283 -17
  135. package/src/tooling/verbs.zig +7 -0
  136. package/third_party/sqlite/README.md +13 -0
  137. package/third_party/sqlite/sqlite3.c +269649 -0
  138. package/third_party/sqlite/sqlite3.h +14349 -0
  139. package/tools/corewire/core_abi.zig +14 -2
  140. package/tools/corewire/emit.zig +98 -29
  141. package/tools/corewire/emit_facade.zig +378 -23
  142. package/tools/corewire/emit_profile.zig +6 -2
  143. package/tools/corewire/emit_service.zig +924 -0
  144. package/tools/corewire/main.zig +122 -0
  145. package/tools/corewire/service_contract.zig +250 -0
  146. package/tools/corewire/sidecar.zig +26 -15
@@ -34,6 +34,7 @@ const max_clipboard_data_bytes = types.max_clipboard_data_bytes;
34
34
  const max_credential_service_bytes = types.max_credential_service_bytes;
35
35
  const max_credential_account_bytes = types.max_credential_account_bytes;
36
36
  const max_credential_secret_bytes = types.max_credential_secret_bytes;
37
+ const max_local_time_text_bytes = types.max_local_time_text_bytes;
37
38
  const max_tray_items = types.max_tray_items;
38
39
  const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
39
40
  const max_tray_title_bytes = types.max_tray_title_bytes;
@@ -110,11 +111,14 @@ const MessageDialogOptions = types.MessageDialogOptions;
110
111
  const NotificationOptions = types.NotificationOptions;
111
112
  const CredentialKey = types.CredentialKey;
112
113
  const Credential = types.Credential;
114
+ const LocalTimeStyle = types.LocalTimeStyle;
113
115
  const TrayItemId = types.TrayItemId;
114
116
  const TrayOptions = types.TrayOptions;
117
+ const TrayPresentation = types.TrayPresentation;
115
118
  const TrayMenuItem = types.TrayMenuItem;
116
119
  const NativeCommandEvent = types.NativeCommandEvent;
117
120
  const MenuCommandEvent = types.MenuCommandEvent;
121
+ const TrayCommandEvent = types.TrayCommandEvent;
118
122
  const TimerEvent = types.TimerEvent;
119
123
  const FileDropEvent = types.FileDropEvent;
120
124
  const GpuFrame = types.GpuFrame;
@@ -340,11 +344,13 @@ pub const NullPlatform = struct {
340
344
  window_always_on_top: [max_windows]bool = [_]bool{false} ** max_windows,
341
345
  window_click_through: [max_windows]bool = [_]bool{false} ** max_windows,
342
346
  window_activate_on_show: [max_windows]bool = [_]bool{true} ** max_windows,
347
+ window_allows_fullscreen: [max_windows]bool = [_]bool{true} ** max_windows,
343
348
  /// Minimize calls per window (`minimize_window_fn`), indexed like
344
349
  /// `windows`: the observable seam for app-drawn minimize controls —
345
350
  /// the null platform has no Dock to genie into, so the count IS the
346
351
  /// behavior tests pin.
347
352
  window_minimize_count: [max_windows]u32 = [_]u32{0} ** max_windows,
353
+ window_hide_count: [max_windows]u32 = [_]u32{0} ** max_windows,
348
354
  /// Show calls per window (`show_window_fn`), indexed like `windows`
349
355
  /// — the counterpart seam (tray "Open", the un-hide verb).
350
356
  window_show_count: [max_windows]u32 = [_]u32{0} ** max_windows,
@@ -391,6 +397,11 @@ pub const NullPlatform = struct {
391
397
  /// runtime's `showWindow` rollback test uses to assert a refused
392
398
  /// show restores hidden and moves no focus.
393
399
  fail_next_show_window: bool = false,
400
+ fail_next_hide_window: bool = false,
401
+ dock_visible: bool = true,
402
+ dock_presence_count: u32 = 0,
403
+ launch_at_login_status: types.LaunchAtLoginStatus = .disabled,
404
+ launch_at_login_set_count: u32 = 0,
394
405
  /// Captured `WindowOptions.min_width`/`min_height` per created
395
406
  /// window — the content min-size floor that must survive to the
396
407
  /// create seam (macOS applies it as `contentMinSize`); same
@@ -463,10 +474,18 @@ pub const NullPlatform = struct {
463
474
  credential_service_len: usize = 0,
464
475
  credential_account: [max_credential_account_bytes]u8 = undefined,
465
476
  credential_account_len: usize = 0,
466
- credential_secret: [max_credential_secret_bytes]u8 = undefined,
467
- credential_secret_len: usize = 0,
477
+ /// Hermetic process-local keychain. Real credential effects use four
478
+ /// worker threads, so the fake must be synchronized too; one old
479
+ /// bridge-era "last secret" buffer silently lost distinct keys.
480
+ credential_mutex: std.atomic.Mutex = .unlocked,
481
+ credential_entries: std.StringHashMapUnmanaged([]u8) = .empty,
482
+ credential_last_secret: ?[]const u8 = null,
468
483
  credential_set_count: usize = 0,
469
484
  credential_delete_count: usize = 0,
485
+ /// Deterministic local-zone model for tests. Real hosts consult the OS
486
+ /// zone (including DST at the requested instant); the null host uses this
487
+ /// fixed offset so suites can pin exact output without ambient state.
488
+ local_time_offset_minutes: i16 = 0,
470
489
  webview_navigate_count: usize = 0,
471
490
  tray_icon_path: [max_tray_icon_path_bytes]u8 = undefined,
472
491
  tray_icon_path_len: usize = 0,
@@ -474,6 +493,13 @@ pub const NullPlatform = struct {
474
493
  tray_title_len: usize = 0,
475
494
  tray_tooltip: [max_tray_tooltip_bytes]u8 = undefined,
476
495
  tray_tooltip_len: usize = 0,
496
+ tray_activation_command: [max_tray_item_command_bytes]u8 = undefined,
497
+ tray_activation_command_len: usize = 0,
498
+ tray_alternate_activation_command: [max_tray_item_command_bytes]u8 = undefined,
499
+ tray_alternate_activation_command_len: usize = 0,
500
+ tray_open_command: [max_tray_item_command_bytes]u8 = undefined,
501
+ tray_open_command_len: usize = 0,
502
+ tray_presentation: TrayPresentation = .{},
477
503
  tray_items: [max_tray_items]TrayMenuItem = undefined,
478
504
  tray_item_count: usize = 0,
479
505
  tray_create_count: usize = 0,
@@ -671,9 +697,8 @@ pub const NullPlatform = struct {
671
697
  /// embed host drain it on their own thread via `takeWake` and then
672
698
  /// dispatch the `.wake` platform event themselves.
673
699
  wake_count: std.atomic.Value(usize) = std.atomic.Value(usize).init(0),
674
- /// Latched when the runtime's effects teardown abandons an in-flight
675
- /// channel `wake_fn` call (see
676
- /// `PlatformServices.note_channel_wake_abandoned_fn`): the stale call
700
+ /// Latched when effects teardown abandons an in-flight platform call
701
+ /// (a channel wake or blocking credential operation): the stale call
677
702
  /// still holds this platform as its context, so `deinit` must skip
678
703
  /// destruction and leak the host, process-lived — the reference model
679
704
  /// of the real hosts' destroy gate, and the seam channel teardown
@@ -788,9 +813,21 @@ pub const NullPlatform = struct {
788
813
  /// which is exactly what makes the gate observable in tests.
789
814
  pub fn deinit(self: *NullPlatform) void {
790
815
  if (self.channel_wake_abandoned.load(.seq_cst)) {
791
- std.debug.print("null platform teardown: an abandoned channel wake call may still enter this host; skipping destruction and leaking it, process-lived, so the stale call stays safe\n", .{});
816
+ std.debug.print("null platform teardown: an abandoned platform call may still enter this host; skipping destruction and leaking it, process-lived, so the stale call stays safe\n", .{});
792
817
  return;
793
818
  }
819
+ if (self.destroyed) return;
820
+ self.lockCredentials();
821
+ var credentials = self.credential_entries.iterator();
822
+ while (credentials.next()) |entry| {
823
+ @memset(entry.value_ptr.*, 0);
824
+ std.heap.page_allocator.free(entry.value_ptr.*);
825
+ std.heap.page_allocator.free(entry.key_ptr.*);
826
+ }
827
+ self.credential_entries.deinit(std.heap.page_allocator);
828
+ self.credential_entries = .empty;
829
+ self.credential_last_secret = null;
830
+ self.credential_mutex.unlock();
794
831
  self.destroyed = true;
795
832
  }
796
833
 
@@ -816,7 +853,11 @@ pub const NullPlatform = struct {
816
853
  .focus_window_fn = focusWindow,
817
854
  .close_window_fn = closeWindow,
818
855
  .minimize_window_fn = minimizeWindow,
856
+ .hide_window_fn = hideWindow,
819
857
  .show_window_fn = showWindow,
858
+ .set_dock_presence_fn = setDockPresence,
859
+ .launch_at_login_status_fn = launchAtLoginStatus,
860
+ .set_launch_at_login_fn = setLaunchAtLogin,
820
861
  .quit_app_fn = quitApp,
821
862
  .start_window_drag_fn = startWindowDrag,
822
863
  .window_chrome_fn = windowChrome,
@@ -841,9 +882,12 @@ pub const NullPlatform = struct {
841
882
  .set_credential_fn = setCredential,
842
883
  .get_credential_fn = getCredential,
843
884
  .delete_credential_fn = deleteCredential,
885
+ .note_blocking_call_abandoned_fn = noteChannelWakeAbandoned,
886
+ .format_local_time_fn = formatLocalTime,
844
887
  .create_tray_fn = createTray,
845
888
  .update_tray_menu_fn = updateTrayMenu,
846
889
  .update_tray_title_fn = updateTrayTitle,
890
+ .update_tray_presentation_fn = updateTrayPresentation,
847
891
  .remove_tray_fn = removeTray,
848
892
  .open_external_url_fn = openExternalUrl,
849
893
  .reveal_path_fn = revealPath,
@@ -957,6 +1001,7 @@ pub const NullPlatform = struct {
957
1001
  .scale_factor = self.surface_value.scale_factor,
958
1002
  .open = true,
959
1003
  .focused = index == 0 and window.activate_on_show and window.show == .immediate,
1004
+ .hidden = window.show == .hidden,
960
1005
  } });
961
1006
  }
962
1007
  var frame: u32 = 0;
@@ -1068,6 +1113,7 @@ pub const NullPlatform = struct {
1068
1113
  .scale_factor = self.surface_value.scale_factor,
1069
1114
  .open = true,
1070
1115
  .focused = focused,
1116
+ .hidden = options.show == .hidden,
1071
1117
  };
1072
1118
  self.windows[self.window_count] = info;
1073
1119
  self.window_resizable[self.window_count] = options.resizable;
@@ -1076,6 +1122,7 @@ pub const NullPlatform = struct {
1076
1122
  self.window_always_on_top[self.window_count] = options.always_on_top;
1077
1123
  self.window_click_through[self.window_count] = options.click_through;
1078
1124
  self.window_activate_on_show[self.window_count] = options.activate_on_show;
1125
+ self.window_allows_fullscreen[self.window_count] = options.allows_fullscreen;
1079
1126
  self.window_show[self.window_count] = options.show;
1080
1127
  self.window_close_policy[self.window_count] = options.close_policy;
1081
1128
  self.window_min_width[self.window_count] = options.min_width;
@@ -1104,7 +1151,10 @@ pub const NullPlatform = struct {
1104
1151
  self.show_op_seq += 1;
1105
1152
  self.window_first_present_seq[index] = self.show_op_seq;
1106
1153
  }
1107
- if (!self.window_visible[index] and self.window_show[index] == .on_first_present) {
1154
+ if (!self.windows[index].hidden and
1155
+ !self.window_visible[index] and
1156
+ self.window_show[index] == .on_first_present)
1157
+ {
1108
1158
  self.window_visible[index] = true;
1109
1159
  self.show_op_seq += 1;
1110
1160
  self.window_shown_seq[index] = self.show_op_seq;
@@ -1151,6 +1201,7 @@ pub const NullPlatform = struct {
1151
1201
  }
1152
1202
  // An explicit focus shows a still-deferred window (the macOS
1153
1203
  // host's makeKeyAndOrderFront override of present-before-show).
1204
+ self.windows[focused_index].hidden = false;
1154
1205
  if (!self.window_visible[focused_index]) {
1155
1206
  self.window_visible[focused_index] = true;
1156
1207
  self.show_op_seq += 1;
@@ -1220,6 +1271,37 @@ pub const NullPlatform = struct {
1220
1271
  self.window_show_count[index] += 1;
1221
1272
  }
1222
1273
 
1274
+ fn hideWindow(context: ?*anyopaque, window_id: WindowId) anyerror!void {
1275
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1276
+ if (self.fail_next_hide_window) {
1277
+ self.fail_next_hide_window = false;
1278
+ return error.HideFailed;
1279
+ }
1280
+ const index = self.findWindowIndex(window_id) orelse return error.WindowNotFound;
1281
+ self.windows[index].hidden = true;
1282
+ self.windows[index].focused = false;
1283
+ self.window_visible[index] = false;
1284
+ self.window_hide_count[index] += 1;
1285
+ }
1286
+
1287
+ fn setDockPresence(context: ?*anyopaque, visible: bool) anyerror!void {
1288
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1289
+ self.dock_visible = visible;
1290
+ self.dock_presence_count += 1;
1291
+ }
1292
+
1293
+ fn launchAtLoginStatus(context: ?*anyopaque) anyerror!types.LaunchAtLoginStatus {
1294
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1295
+ return self.launch_at_login_status;
1296
+ }
1297
+
1298
+ fn setLaunchAtLogin(context: ?*anyopaque, enabled: bool) anyerror!types.LaunchAtLoginStatus {
1299
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1300
+ self.launch_at_login_set_count += 1;
1301
+ self.launch_at_login_status = if (enabled) .enabled else .disabled;
1302
+ return self.launch_at_login_status;
1303
+ }
1304
+
1223
1305
  fn quitApp(context: ?*anyopaque) anyerror!void {
1224
1306
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1225
1307
  self.quit_request_count += 1;
@@ -1465,40 +1547,131 @@ pub const NullPlatform = struct {
1465
1547
  self.notification_count += 1;
1466
1548
  }
1467
1549
 
1550
+ const max_credential_identity_bytes = max_credential_service_bytes + 1 + max_credential_account_bytes;
1551
+
1552
+ fn lockCredentials(self: *NullPlatform) void {
1553
+ while (!self.credential_mutex.tryLock()) std.atomic.spinLoopHint();
1554
+ }
1555
+
1556
+ fn credentialIdentity(buffer: *[max_credential_identity_bytes]u8, key: CredentialKey) anyerror![]const u8 {
1557
+ if (key.service.len == 0 or key.service.len > max_credential_service_bytes or
1558
+ key.account.len == 0 or key.account.len > max_credential_account_bytes)
1559
+ {
1560
+ return error.CredentialFieldTooLarge;
1561
+ }
1562
+ @memcpy(buffer[0..key.service.len], key.service);
1563
+ buffer[key.service.len] = 0;
1564
+ @memcpy(buffer[key.service.len + 1 ..][0..key.account.len], key.account);
1565
+ return buffer[0 .. key.service.len + 1 + key.account.len];
1566
+ }
1567
+
1468
1568
  fn setCredential(context: ?*anyopaque, credential: Credential) anyerror!void {
1469
1569
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1570
+ if (credential.secret.len > max_credential_secret_bytes) return error.CredentialFieldTooLarge;
1571
+ var identity_storage: [max_credential_identity_bytes]u8 = undefined;
1572
+ const identity = try credentialIdentity(&identity_storage, .{
1573
+ .service = credential.service,
1574
+ .account = credential.account,
1575
+ });
1576
+
1577
+ self.lockCredentials();
1578
+ defer self.credential_mutex.unlock();
1579
+ const secret = try std.heap.page_allocator.dupe(u8, credential.secret);
1580
+ errdefer std.heap.page_allocator.free(secret);
1581
+ if (self.credential_entries.getPtr(identity)) |existing| {
1582
+ @memset(existing.*, 0);
1583
+ std.heap.page_allocator.free(existing.*);
1584
+ existing.* = secret;
1585
+ } else {
1586
+ const owned_identity = try std.heap.page_allocator.dupe(u8, identity);
1587
+ errdefer std.heap.page_allocator.free(owned_identity);
1588
+ try self.credential_entries.put(std.heap.page_allocator, owned_identity, secret);
1589
+ }
1590
+
1470
1591
  self.credential_service = undefined;
1471
1592
  self.credential_account = undefined;
1472
- self.credential_secret = undefined;
1473
- self.credential_service_len = (try copyInto(&self.credential_service, credential.service)).len;
1474
- self.credential_account_len = (try copyInto(&self.credential_account, credential.account)).len;
1475
- self.credential_secret_len = (try copyInto(&self.credential_secret, credential.secret)).len;
1593
+ @memcpy(self.credential_service[0..credential.service.len], credential.service);
1594
+ @memcpy(self.credential_account[0..credential.account.len], credential.account);
1595
+ self.credential_service_len = credential.service.len;
1596
+ self.credential_account_len = credential.account.len;
1597
+ self.credential_last_secret = secret;
1476
1598
  self.credential_set_count += 1;
1477
1599
  }
1478
1600
 
1479
1601
  fn getCredential(context: ?*anyopaque, key: CredentialKey, buffer: []u8) anyerror![]const u8 {
1480
1602
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1481
- if (self.credential_secret_len == 0) return error.CredentialNotFound;
1482
- if (!std.mem.eql(u8, key.service, self.lastCredentialService()) or !std.mem.eql(u8, key.account, self.lastCredentialAccount())) return error.CredentialNotFound;
1483
- return try copyInto(buffer, self.lastCredentialSecret());
1603
+ var identity_storage: [max_credential_identity_bytes]u8 = undefined;
1604
+ const identity = try credentialIdentity(&identity_storage, key);
1605
+ self.lockCredentials();
1606
+ defer self.credential_mutex.unlock();
1607
+ const secret = self.credential_entries.get(identity) orelse return error.CredentialNotFound;
1608
+ return try copyInto(buffer, secret);
1484
1609
  }
1485
1610
 
1486
1611
  fn deleteCredential(context: ?*anyopaque, key: CredentialKey) anyerror!void {
1487
1612
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1488
- if (self.credential_secret_len == 0) return error.CredentialNotFound;
1489
- if (!std.mem.eql(u8, key.service, self.lastCredentialService()) or !std.mem.eql(u8, key.account, self.lastCredentialAccount())) return error.CredentialNotFound;
1490
- self.credential_secret_len = 0;
1613
+ var identity_storage: [max_credential_identity_bytes]u8 = undefined;
1614
+ const identity = try credentialIdentity(&identity_storage, key);
1615
+ self.lockCredentials();
1616
+ defer self.credential_mutex.unlock();
1617
+ const removed = self.credential_entries.fetchRemove(identity) orelse return error.CredentialNotFound;
1618
+ if (self.credential_last_secret) |last| {
1619
+ if (last.ptr == removed.value.ptr) self.credential_last_secret = null;
1620
+ }
1621
+ @memset(removed.value, 0);
1622
+ std.heap.page_allocator.free(removed.value);
1623
+ std.heap.page_allocator.free(removed.key);
1491
1624
  self.credential_delete_count += 1;
1492
1625
  }
1493
1626
 
1627
+ fn formatLocalTime(context: ?*anyopaque, timestamp_ms: i64, style: LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
1628
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1629
+ const seconds = @divFloor(timestamp_ms, 1000) + @as(i64, self.local_time_offset_minutes) * 60;
1630
+ const days = @divFloor(seconds, 86_400);
1631
+ const second_of_day: u32 = @intCast(@mod(seconds, 86_400));
1632
+ const parts = localCivilFromDays(days) orelse return error.InvalidTimestamp;
1633
+ const hour = second_of_day / 3600;
1634
+ const minute = (second_of_day % 3600) / 60;
1635
+ const second = second_of_day % 60;
1636
+ return switch (style) {
1637
+ .date => try std.fmt.bufPrint(buffer, "{d:0>4}-{d:0>2}-{d:0>2}", .{ parts.year, parts.month, parts.day }),
1638
+ .time => try std.fmt.bufPrint(buffer, "{d:0>2}:{d:0>2}:{d:0>2}", .{ hour, minute, second }),
1639
+ .datetime => try std.fmt.bufPrint(buffer, "{d:0>4}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2}:{d:0>2}", .{ parts.year, parts.month, parts.day, hour, minute, second }),
1640
+ };
1641
+ }
1642
+
1643
+ const LocalCivilDate = struct { year: u32, month: u32, day: u32 };
1644
+
1645
+ fn localCivilFromDays(days: i64) ?LocalCivilDate {
1646
+ const shifted = days + 719_468;
1647
+ const era = @divFloor(shifted, 146_097);
1648
+ const day_of_era: u32 = @intCast(shifted - era * 146_097);
1649
+ const year_of_era = (day_of_era - day_of_era / 1460 + day_of_era / 36_524 - day_of_era / 146_096) / 365;
1650
+ const year = @as(i64, year_of_era) + era * 400;
1651
+ const day_of_year = day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100);
1652
+ const month_index = (5 * day_of_year + 2) / 153;
1653
+ const day = day_of_year - (153 * month_index + 2) / 5 + 1;
1654
+ const month = if (month_index < 10) month_index + 3 else month_index - 9;
1655
+ const civil_year = if (month <= 2) year + 1 else year;
1656
+ if (civil_year < 1 or civil_year > 9999) return null;
1657
+ return .{ .year = @intCast(civil_year), .month = month, .day = day };
1658
+ }
1659
+
1494
1660
  fn createTray(context: ?*anyopaque, options: TrayOptions) anyerror!void {
1495
1661
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1496
1662
  self.tray_icon_path = undefined;
1497
1663
  self.tray_title = undefined;
1498
1664
  self.tray_tooltip = undefined;
1499
1665
  self.tray_icon_path_len = (try copyInto(&self.tray_icon_path, options.icon_path)).len;
1500
- self.tray_title_len = (try copyInto(&self.tray_title, options.title)).len;
1666
+ var presentation = options.presentation;
1667
+ if (presentation.title.len == 0) presentation.title = options.title;
1668
+ self.tray_title_len = (try copyInto(&self.tray_title, presentation.title)).len;
1501
1669
  self.tray_tooltip_len = (try copyInto(&self.tray_tooltip, options.tooltip)).len;
1670
+ self.tray_activation_command_len = (try copyInto(&self.tray_activation_command, options.activation_command)).len;
1671
+ self.tray_alternate_activation_command_len = (try copyInto(&self.tray_alternate_activation_command, options.alternate_activation_command)).len;
1672
+ self.tray_open_command_len = (try copyInto(&self.tray_open_command, options.open_command)).len;
1673
+ self.tray_presentation = presentation;
1674
+ self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1502
1675
  try updateTrayMenu(context, options.items);
1503
1676
  self.tray_create_count += 1;
1504
1677
  }
@@ -1515,9 +1688,17 @@ pub const NullPlatform = struct {
1515
1688
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1516
1689
  self.tray_title = undefined;
1517
1690
  self.tray_title_len = (try copyInto(&self.tray_title, title)).len;
1691
+ self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1518
1692
  self.tray_title_update_count += 1;
1519
1693
  }
1520
1694
 
1695
+ fn updateTrayPresentation(context: ?*anyopaque, presentation: TrayPresentation) anyerror!void {
1696
+ const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1697
+ try updateTrayTitle(context, presentation.title);
1698
+ self.tray_presentation = presentation;
1699
+ self.tray_presentation.title = self.tray_title[0..self.tray_title_len];
1700
+ }
1701
+
1521
1702
  fn removeTray(context: ?*anyopaque) anyerror!void {
1522
1703
  const self: *NullPlatform = @ptrCast(@alignCast(context.?));
1523
1704
  self.tray_item_count = 0;
@@ -2632,6 +2813,11 @@ pub const NullPlatform = struct {
2632
2813
  return self.window_minimize_count[index];
2633
2814
  }
2634
2815
 
2816
+ pub fn hideCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
2817
+ const index = self.findWindowIndex(window_id) orelse return 0;
2818
+ return self.window_hide_count[index];
2819
+ }
2820
+
2635
2821
  /// Test seam: show calls observed for a window (the un-hide verb's
2636
2822
  /// pinned observable, like `minimizeCountForWindow`).
2637
2823
  pub fn showCountForWindow(self: *const NullPlatform, window_id: WindowId) u32 {
@@ -2673,6 +2859,7 @@ pub const NullPlatform = struct {
2673
2859
  self.window_always_on_top[cursor] = self.window_always_on_top[cursor + 1];
2674
2860
  self.window_click_through[cursor] = self.window_click_through[cursor + 1];
2675
2861
  self.window_activate_on_show[cursor] = self.window_activate_on_show[cursor + 1];
2862
+ self.window_allows_fullscreen[cursor] = self.window_allows_fullscreen[cursor + 1];
2676
2863
  self.window_show[cursor] = self.window_show[cursor + 1];
2677
2864
  self.window_visible[cursor] = self.window_visible[cursor + 1];
2678
2865
  self.window_first_present_seq[cursor] = self.window_first_present_seq[cursor + 1];
@@ -2680,6 +2867,7 @@ pub const NullPlatform = struct {
2680
2867
  self.window_min_width[cursor] = self.window_min_width[cursor + 1];
2681
2868
  self.window_min_height[cursor] = self.window_min_height[cursor + 1];
2682
2869
  self.window_minimize_count[cursor] = self.window_minimize_count[cursor + 1];
2870
+ self.window_hide_count[cursor] = self.window_hide_count[cursor + 1];
2683
2871
  self.window_show_count[cursor] = self.window_show_count[cursor + 1];
2684
2872
  self.window_occluded[cursor] = self.window_occluded[cursor + 1];
2685
2873
  self.window_close_policy[cursor] = self.window_close_policy[cursor + 1];
@@ -2816,7 +3004,7 @@ pub const NullPlatform = struct {
2816
3004
  }
2817
3005
 
2818
3006
  pub fn lastCredentialSecret(self: *const NullPlatform) []const u8 {
2819
- return self.credential_secret[0..self.credential_secret_len];
3007
+ return self.credential_last_secret orelse "";
2820
3008
  }
2821
3009
 
2822
3010
  pub fn credentialSetCount(self: *const NullPlatform) usize {
@@ -2839,6 +3027,22 @@ pub const NullPlatform = struct {
2839
3027
  return self.tray_tooltip[0..self.tray_tooltip_len];
2840
3028
  }
2841
3029
 
3030
+ pub fn lastTrayActivationCommand(self: *const NullPlatform) []const u8 {
3031
+ return self.tray_activation_command[0..self.tray_activation_command_len];
3032
+ }
3033
+
3034
+ pub fn lastTrayAlternateActivationCommand(self: *const NullPlatform) []const u8 {
3035
+ return self.tray_alternate_activation_command[0..self.tray_alternate_activation_command_len];
3036
+ }
3037
+
3038
+ pub fn lastTrayOpenCommand(self: *const NullPlatform) []const u8 {
3039
+ return self.tray_open_command[0..self.tray_open_command_len];
3040
+ }
3041
+
3042
+ pub fn lastTrayPresentation(self: *const NullPlatform) TrayPresentation {
3043
+ return self.tray_presentation;
3044
+ }
3045
+
2842
3046
  pub fn trayItems(self: *const NullPlatform) []const TrayMenuItem {
2843
3047
  return self.tray_items[0..self.tray_item_count];
2844
3048
  }
@@ -31,6 +31,7 @@ const max_clipboard_data_bytes = types.max_clipboard_data_bytes;
31
31
  const max_credential_service_bytes = types.max_credential_service_bytes;
32
32
  const max_credential_account_bytes = types.max_credential_account_bytes;
33
33
  const max_credential_secret_bytes = types.max_credential_secret_bytes;
34
+ const max_local_time_text_bytes = types.max_local_time_text_bytes;
34
35
  const max_tray_items = types.max_tray_items;
35
36
  const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
36
37
  const max_tray_tooltip_bytes = types.max_tray_tooltip_bytes;
@@ -111,6 +112,7 @@ const TrayOptions = types.TrayOptions;
111
112
  const TrayMenuItem = types.TrayMenuItem;
112
113
  const NativeCommandEvent = types.NativeCommandEvent;
113
114
  const MenuCommandEvent = types.MenuCommandEvent;
115
+ const TrayCommandEvent = types.TrayCommandEvent;
114
116
  const FileDropEvent = types.FileDropEvent;
115
117
  const GpuFrame = types.GpuFrame;
116
118
  const GpuSurfaceFrameEvent = types.GpuSurfaceFrameEvent;
@@ -162,6 +164,46 @@ test "null platform emits deterministic lifecycle events" {
162
164
  try std.testing.expectEqualStrings("app_shutdown", recorder.names[5]);
163
165
  }
164
166
 
167
+ test "null platform reports hidden startup state" {
168
+ const Recorder = struct {
169
+ startup_hidden: ?bool = null,
170
+
171
+ fn handle(context: *anyopaque, event: Event) anyerror!void {
172
+ const self: *@This() = @ptrCast(@alignCast(context));
173
+ switch (event) {
174
+ .window_frame_changed => |window| self.startup_hidden = window.hidden,
175
+ else => {},
176
+ }
177
+ }
178
+ };
179
+
180
+ var null_platform = NullPlatform.initWithOptions(.{}, .system, .{
181
+ .app_name = "Hidden",
182
+ .main_window = .{ .show = .hidden },
183
+ });
184
+ var recorder: Recorder = .{};
185
+ try null_platform.platform().run(Recorder.handle, &recorder);
186
+
187
+ try std.testing.expectEqual(true, recorder.startup_hidden.?);
188
+ }
189
+
190
+ test "null platform focus reveals a hidden window" {
191
+ var null_platform = NullPlatform.init(.{});
192
+ const services = null_platform.platform().services;
193
+ const window = try services.createWindow(.{
194
+ .id = 7,
195
+ .label = "panel",
196
+ .show = .hidden,
197
+ });
198
+
199
+ try std.testing.expect(window.hidden);
200
+ try std.testing.expect(!null_platform.window_visible[0]);
201
+ try services.focusWindow(window.id);
202
+ try std.testing.expect(!null_platform.windows[0].hidden);
203
+ try std.testing.expect(null_platform.windows[0].focused);
204
+ try std.testing.expect(null_platform.window_visible[0]);
205
+ }
206
+
165
207
  test "the videoLoadUrl seam refuses non-http(s) schemes for every caller" {
166
208
  // The streaming contract holds at the seam, not just behind the
167
209
  // engine's own gated loads: hosts hand the URL to their media
@@ -215,8 +257,29 @@ test "null platform records bridge response window routing" {
215
257
  try std.testing.expectEqualStrings("{\"ok\":true}", null_platform.lastBridgeResponse());
216
258
  }
217
259
 
260
+ test "null platform preserves the tray title when presentation styles are set" {
261
+ var null_platform = NullPlatform.init(.{});
262
+ try null_platform.platform().services.createTray(.{
263
+ .title = "Jobs",
264
+ .presentation = .{ .width = 60, .tone = .warning },
265
+ });
266
+
267
+ try std.testing.expectEqualStrings("Jobs", null_platform.lastTrayTitle());
268
+ const presentation = null_platform.lastTrayPresentation();
269
+ try std.testing.expectEqualStrings("Jobs", presentation.title);
270
+ try std.testing.expectEqual(@as(f32, 60), presentation.width);
271
+ try std.testing.expectEqual(types.TrayTone.warning, presentation.tone);
272
+
273
+ try null_platform.platform().services.updateTrayTitle("Builds");
274
+ const retitled = null_platform.lastTrayPresentation();
275
+ try std.testing.expectEqualStrings("Builds", retitled.title);
276
+ try std.testing.expectEqual(@as(f32, 60), retitled.width);
277
+ try std.testing.expectEqual(types.TrayTone.warning, retitled.tone);
278
+ }
279
+
218
280
  test "null platform records OS actions" {
219
281
  var null_platform = NullPlatform.init(.{});
282
+ defer null_platform.deinit();
220
283
  const services = null_platform.platform().services;
221
284
 
222
285
  try services.showNotification(.{
@@ -276,9 +339,19 @@ test "null platform records OS actions" {
276
339
  const secret = try services.getCredential(.{ .service = "dev.native-sdk.test", .account = "alice" }, &credential_buffer);
277
340
  try std.testing.expectEqualStrings("secret-token", secret);
278
341
  try std.testing.expectError(error.CredentialNotFound, services.getCredential(.{ .service = "dev.native-sdk.test", .account = "bob" }, &credential_buffer));
342
+ try services.setCredential(.{ .service = "dev.native-sdk.test", .account = "bob", .secret = "second-token" });
343
+ try std.testing.expectEqualStrings("secret-token", try services.getCredential(.{ .service = "dev.native-sdk.test", .account = "alice" }, &credential_buffer));
344
+ try std.testing.expectEqualStrings("second-token", try services.getCredential(.{ .service = "dev.native-sdk.test", .account = "bob" }, &credential_buffer));
279
345
  try services.deleteCredential(.{ .service = "dev.native-sdk.test", .account = "alice" });
280
346
  try std.testing.expectEqual(@as(usize, 1), null_platform.credentialDeleteCount());
281
347
  try std.testing.expectError(error.CredentialNotFound, services.getCredential(.{ .service = "dev.native-sdk.test", .account = "alice" }, &credential_buffer));
348
+ try std.testing.expectEqualStrings("second-token", try services.getCredential(.{ .service = "dev.native-sdk.test", .account = "bob" }, &credential_buffer));
349
+
350
+ null_platform.local_time_offset_minutes = -360;
351
+ var local_time_buffer: [max_local_time_text_bytes]u8 = undefined;
352
+ try std.testing.expectEqualStrings("2024-01-01 21:04:05", try services.formatLocalTime(1_704_164_645_000, .datetime, &local_time_buffer));
353
+ try std.testing.expectEqualStrings("2024-01-01", try services.formatLocalTime(1_704_164_645_000, .date, &local_time_buffer));
354
+ try std.testing.expectEqualStrings("21:04:05", try services.formatLocalTime(1_704_164_645_000, .time, &local_time_buffer));
282
355
 
283
356
  try services.clearRecentDocuments();
284
357
  try std.testing.expectEqual(@as(usize, 1), null_platform.recentDocumentsClearedCount());
@@ -391,6 +464,7 @@ test "OS actions require backend support" {
391
464
  try std.testing.expectError(error.UnsupportedService, services.setCredential(.{ .service = "service", .account = "account", .secret = "secret" }));
392
465
  try std.testing.expectError(error.UnsupportedService, services.getCredential(.{ .service = "service", .account = "account" }, &buffer));
393
466
  try std.testing.expectError(error.UnsupportedService, services.deleteCredential(.{ .service = "service", .account = "account" }));
467
+ try std.testing.expectError(error.UnsupportedService, services.formatLocalTime(0, .datetime, &buffer));
394
468
  }
395
469
 
396
470
  test "null platform records webview lifecycle" {
@@ -31,12 +31,14 @@ pub const max_clipboard_data_bytes = types.max_clipboard_data_bytes;
31
31
  pub const max_credential_service_bytes = types.max_credential_service_bytes;
32
32
  pub const max_credential_account_bytes = types.max_credential_account_bytes;
33
33
  pub const max_credential_secret_bytes = types.max_credential_secret_bytes;
34
+ pub const max_local_time_text_bytes = types.max_local_time_text_bytes;
34
35
  pub const max_tray_items = types.max_tray_items;
35
36
  pub const max_tray_icon_path_bytes = types.max_tray_icon_path_bytes;
36
37
  pub const max_tray_title_bytes = types.max_tray_title_bytes;
37
38
  pub const max_tray_tooltip_bytes = types.max_tray_tooltip_bytes;
38
39
  pub const max_tray_item_label_bytes = types.max_tray_item_label_bytes;
39
40
  pub const max_tray_item_command_bytes = types.max_tray_item_command_bytes;
41
+ pub const max_tray_item_detail_bytes = types.max_tray_item_detail_bytes;
40
42
  pub const max_drop_paths_bytes = types.max_drop_paths_bytes;
41
43
  pub const max_drop_paths = types.max_drop_paths;
42
44
  pub const max_window_event_name_bytes = types.max_window_event_name_bytes;
@@ -72,6 +74,7 @@ pub const validateShortcut = types.validateShortcut;
72
74
  pub const validateMenus = types.validateMenus;
73
75
  pub const validateMenuItem = types.validateMenuItem;
74
76
  pub const isValidShortcutKey = types.isValidShortcutKey;
77
+ pub const isValidShortcutBinding = types.isValidShortcutBinding;
75
78
  pub const WindowRestorePolicy = types.WindowRestorePolicy;
76
79
  pub const WindowTitlebarStyle = types.WindowTitlebarStyle;
77
80
  pub const WindowChrome = types.WindowChrome;
@@ -79,6 +82,7 @@ pub const FormFactor = types.FormFactor;
79
82
  pub const WindowDragRegion = types.WindowDragRegion;
80
83
  pub const WindowShowMode = types.WindowShowMode;
81
84
  pub const WindowClosePolicy = types.WindowClosePolicy;
85
+ pub const LaunchAtLoginStatus = types.LaunchAtLoginStatus;
82
86
  pub const WindowOptions = types.WindowOptions;
83
87
  pub const WindowState = types.WindowState;
84
88
  pub const WindowInfo = types.WindowInfo;
@@ -122,11 +126,16 @@ pub const MessageDialogOptions = types.MessageDialogOptions;
122
126
  pub const NotificationOptions = types.NotificationOptions;
123
127
  pub const CredentialKey = types.CredentialKey;
124
128
  pub const Credential = types.Credential;
129
+ pub const LocalTimeStyle = types.LocalTimeStyle;
125
130
  pub const TrayItemId = types.TrayItemId;
126
131
  pub const TrayOptions = types.TrayOptions;
132
+ pub const TrayTone = types.TrayTone;
133
+ pub const TrayPresentation = types.TrayPresentation;
127
134
  pub const TrayMenuItem = types.TrayMenuItem;
135
+ pub const TrayItemRole = types.TrayItemRole;
128
136
  pub const NativeCommandEvent = types.NativeCommandEvent;
129
137
  pub const MenuCommandEvent = types.MenuCommandEvent;
138
+ pub const TrayCommandEvent = types.TrayCommandEvent;
130
139
  pub const reserved_timer_id_base = types.reserved_timer_id_base;
131
140
  pub const press_hold_timer_id = types.press_hold_timer_id;
132
141
  pub const TimerEvent = types.TimerEvent;