@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
@@ -32,6 +32,7 @@ const builtin = @import("builtin");
32
32
  const geometry = @import("geometry");
33
33
  const canvas = @import("canvas");
34
34
  const app_manifest = @import("app_manifest");
35
+ const security = @import("../security/root.zig");
35
36
  const platform = @import("../platform/root.zig");
36
37
  const core = @import("core.zig");
37
38
  const canvas_frame = @import("canvas_frame.zig");
@@ -250,15 +251,31 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
250
251
  /// Menu items: `label` is the visible title, `command` the
251
252
  /// name handed to `on_command`, `id` a unique non-zero id.
252
253
  items: []const platform.TrayMenuItem = &.{},
254
+ /// Optional lifecycle commands: ordinary click (then open),
255
+ /// Option-click (without opening), and every menu-open. All
256
+ /// enter the same `on_command` route as menu rows.
257
+ activation_command: []const u8 = "",
258
+ alternate_activation_command: []const u8 = "",
259
+ open_command: []const u8 = "",
253
260
  };
254
261
 
255
262
  /// Model-derived status-item state returned by
256
- /// `Options.status_item_fn`: the live button title and menu.
263
+ /// `Options.status_item_fn`: install-time shell fields plus the
264
+ /// live button presentation and menu.
257
265
  /// Slices may point at the scratch the fn received, the model, or
258
266
  /// static strings — they only need to outlive the apply (the
259
267
  /// runtime and platform copy what they keep).
260
268
  pub const StatusItemState = struct {
261
269
  title: []const u8 = "",
270
+ presentation: platform.TrayPresentation = .{},
271
+ /// Install-time shell fields. A TypeScript core has no Zig
272
+ /// options block, so its statusItem record supplies these on
273
+ /// the first frame. Empty fields inherit StatusItemOptions.
274
+ icon_path: []const u8 = "",
275
+ tooltip: []const u8 = "",
276
+ activation_command: []const u8 = "",
277
+ alternate_activation_command: []const u8 = "",
278
+ open_command: []const u8 = "",
262
279
  items: []const platform.TrayMenuItem = &.{},
263
280
  };
264
281
 
@@ -269,6 +286,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
269
286
  /// apply.
270
287
  pub const StatusItemScratch = struct {
271
288
  title_buffer: [platform.max_tray_title_bytes]u8 = undefined,
289
+ arena_buffer: [2048]u8 = undefined,
272
290
  items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
273
291
  };
274
292
 
@@ -329,6 +347,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
329
347
  always_on_top: bool = false,
330
348
  click_through: bool = false,
331
349
  activate_on_show: bool = true,
350
+ /// Whether macOS offers native fullscreen for this window.
351
+ /// False leaves the window resizable but disables the green
352
+ /// fullscreen affordance and fullscreen command.
353
+ allows_fullscreen: bool = true,
332
354
  /// Msg dispatched when the USER closes the window (never for
333
355
  /// a reconcile close the model itself initiated). The
334
356
  /// dismissal precedent: the window is already gone as an
@@ -1383,15 +1405,35 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1383
1405
  fn bindEffectsChannel(self: *Self, runtime: *Runtime) void {
1384
1406
  self.effects.bindServices(&runtime.options.platform.services);
1385
1407
  self.effects.bindEnviron(runtime.options.environ);
1408
+ if (runtime.options.record_store) |binding| {
1409
+ self.effects.bindRecordStore(binding);
1410
+ }
1411
+ if (runtime.options.relational_store) |binding| {
1412
+ self.effects.bindRelationalStore(binding);
1413
+ }
1414
+ self.effects.bindCredentialsStore(.{
1415
+ .services = &runtime.options.platform.services,
1416
+ .service = runtime.options.platform.app_info.bundle_id,
1417
+ .permitted = runtime.options.credentials_enabled and
1418
+ security.hasPermission(runtime.options.security.permissions, security.permission_credentials),
1419
+ });
1386
1420
  self.effects.bindImages(runtime.canvasImageRegistryBinding());
1387
1421
  self.effects.bindMediaSurfaces(runtime.mediaSurfaceBinding());
1388
1422
  self.effects.bindWindowActions(.{
1389
1423
  .context = runtime,
1390
1424
  .close_fn = effectsCloseWindowByLabel,
1391
1425
  .minimize_fn = effectsMinimizeWindowByLabel,
1426
+ .hide_fn = effectsHideWindowByLabel,
1392
1427
  .show_fn = effectsShowWindowByLabel,
1428
+ .dock_presence_fn = effectsSetDockPresence,
1393
1429
  .quit_fn = effectsQuitApp,
1394
1430
  });
1431
+ self.effects.bindSystemServices(.{
1432
+ .context = runtime,
1433
+ .open_external_url_fn = effectsOpenExternalUrl,
1434
+ .reveal_path_fn = effectsRevealPath,
1435
+ .format_local_time_fn = effectsFormatLocalTime,
1436
+ });
1395
1437
  if (runtime.options.session_recorder) |recorder| {
1396
1438
  self.effects.bindJournal(recorder.effectJournal());
1397
1439
  }
@@ -1457,12 +1499,26 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1457
1499
  // `.rejected` and regenerate from the same
1458
1500
  // deterministic validation, like `.timer` records.
1459
1501
  .host => try self.effects.feedHostResult(record.key, record.code == 0, record.payload),
1502
+ .credentials => try self.effects.feedCredentialsResult(
1503
+ record.key,
1504
+ record.credentials_operation,
1505
+ record.credentials_outcome,
1506
+ record.credentials_secret_len,
1507
+ record.credentials_digest,
1508
+ ),
1509
+ .db => try self.effects.feedDbResult(
1510
+ record.key,
1511
+ runtime_effects.dbKindFromJournalCode(record.code) orelse return error.ReplayDamagedRecord,
1512
+ runtime_effects.dbOutcomeFromJournalCode(record.code) orelse return error.ReplayDamagedRecord,
1513
+ record.payload,
1514
+ ),
1460
1515
  .clock => try self.effects.pushReplayClock(record.clock_wall_ms),
1461
1516
  // `.env` records carry the arm name in `stderr_tail`
1462
1517
  // and the value in `payload`; the TS adapter's
1463
1518
  // envMsgs dispatch consumes the queue on the
1464
1519
  // replayed installing frame (zero env reads).
1465
1520
  .env => try self.effects.pushReplayEnv(record.stderr_tail, record.payload),
1521
+ .persist => try self.effects.pushReplayPersist(record.persist_outcome, record.payload),
1466
1522
  // `.image` records deliver the RECORDED terminal
1467
1523
  // verbatim (byte-identical Msg stream on any host)
1468
1524
  // and re-register the journaled source bytes —
@@ -1619,6 +1675,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1619
1675
  } else {
1620
1676
  self.options.update.?(&self.model, msg);
1621
1677
  }
1678
+ // One update call is one complete command batch. Re-run live
1679
+ // relational reads only after the batch has walked so several
1680
+ // writes touching the same table still coalesce into one result.
1681
+ self.effects.flushDbSubscriptions();
1622
1682
  }
1623
1683
 
1624
1684
  /// Drain the effect completion queue on the loop thread: every
@@ -2678,6 +2738,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2678
2738
  .always_on_top = descriptor.always_on_top,
2679
2739
  .click_through = descriptor.click_through,
2680
2740
  .activate_on_show = descriptor.activate_on_show,
2741
+ .allows_fullscreen = descriptor.allows_fullscreen,
2681
2742
  .min_width = descriptor.min_width,
2682
2743
  .min_height = descriptor.min_height,
2683
2744
  // Deterministic reopen: the descriptor is the geometry
@@ -3614,31 +3675,46 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
3614
3675
  /// Selecting one of its items dispatches the item's `command`
3615
3676
  /// through the ordinary `on_command` path (source `.tray`).
3616
3677
  /// Unsupported platforms degrade to a logged warning. With a
3617
- /// `status_item_fn`, the model's derived title/items win from
3678
+ /// `status_item_fn`, the model's derived presentation/items win from
3618
3679
  /// the very first frame (the static options keep icon+tooltip).
3619
3680
  fn installStatusItem(self: *Self, runtime: *Runtime) void {
3620
3681
  if (self.status_item_installed) return;
3621
3682
  if (self.options.status_item == null and self.options.status_item_fn == null) return;
3622
3683
  self.status_item_installed = true;
3623
3684
  const static = self.options.status_item orelse StatusItemOptions{};
3624
- var title = static.title;
3685
+ var presentation = platform.TrayPresentation{ .title = static.title };
3686
+ var icon_path = static.icon_path;
3687
+ var tooltip = static.tooltip;
3688
+ var activation_command = static.activation_command;
3689
+ var alternate_activation_command = static.alternate_activation_command;
3690
+ var open_command = static.open_command;
3625
3691
  var items = static.items;
3626
3692
  if (self.options.status_item_fn) |state_fn| {
3627
3693
  const state = state_fn(&self.model, &self.tray_scratch);
3628
- title = state.title;
3694
+ presentation = state.presentation;
3695
+ if (presentation.title.len == 0) presentation.title = state.title;
3696
+ if (state.icon_path.len > 0) icon_path = state.icon_path;
3697
+ if (state.tooltip.len > 0) tooltip = state.tooltip;
3698
+ if (state.activation_command.len > 0) activation_command = state.activation_command;
3699
+ if (state.alternate_activation_command.len > 0) alternate_activation_command = state.alternate_activation_command;
3700
+ if (state.open_command.len > 0) open_command = state.open_command;
3629
3701
  items = state.items;
3630
3702
  }
3631
3703
  runtime.createTray(.{
3632
- .title = title,
3633
- .icon_path = static.icon_path,
3634
- .tooltip = static.tooltip,
3704
+ .title = presentation.title,
3705
+ .icon_path = icon_path,
3706
+ .tooltip = tooltip,
3635
3707
  .items = items,
3708
+ .presentation = presentation,
3709
+ .activation_command = activation_command,
3710
+ .alternate_activation_command = alternate_activation_command,
3711
+ .open_command = open_command,
3636
3712
  }) catch |err| {
3637
3713
  ui_app_log.warn("status item install failed: {s}", .{@errorName(err)});
3638
3714
  return;
3639
3715
  };
3640
3716
  self.tray_created = true;
3641
- self.tray_title_hash = hashTrayTitle(title);
3717
+ self.tray_title_hash = hashTrayPresentation(presentation);
3642
3718
  self.tray_menu_hash = hashTrayMenu(items);
3643
3719
  }
3644
3720
 
@@ -3650,17 +3726,19 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
3650
3726
  const state_fn = self.options.status_item_fn orelse return;
3651
3727
  if (!self.tray_created) return;
3652
3728
  const state = state_fn(&self.model, &self.tray_scratch);
3729
+ var presentation = state.presentation;
3730
+ if (presentation.title.len == 0) presentation.title = state.title;
3653
3731
 
3654
- const title_hash = hashTrayTitle(state.title);
3732
+ const title_hash = hashTrayPresentation(presentation);
3655
3733
  if (title_hash != self.tray_title_hash) {
3656
3734
  self.tray_title_hash = title_hash;
3657
3735
  if (!self.tray_title_unsupported) {
3658
- runtime.updateTrayTitle(state.title) catch |err| {
3736
+ runtime.updateTrayPresentation(presentation) catch |err| {
3659
3737
  if (err == error.UnsupportedService) {
3660
3738
  self.tray_title_unsupported = true;
3661
- ui_app_log.warn("status item title updates unsupported on this platform: the menu keeps updating, the button title stays \"{s}\"-era static", .{state.title});
3739
+ ui_app_log.warn("status item presentation updates unsupported on this platform: the menu keeps updating", .{});
3662
3740
  } else {
3663
- ui_app_log.warn("status item title update failed: {s}", .{@errorName(err)});
3741
+ ui_app_log.warn("status item presentation update failed: {s}", .{@errorName(err)});
3664
3742
  }
3665
3743
  };
3666
3744
  }
@@ -4195,6 +4273,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4195
4273
  self.init_fx_ran = true;
4196
4274
  self.bindEffectsChannel(runtime);
4197
4275
  init_fx(&self.model, &self.effects);
4276
+ // init_fx has the same batch contract as update_fx;
4277
+ // subscriptions dirtied by boot transactions must be
4278
+ // current before their staged results are drained.
4279
+ self.effects.flushDbSubscriptions();
4198
4280
  self.publishAudioState(runtime);
4199
4281
  // Launch lap (env-gated): boot-effect cost (asset
4200
4282
  // decode/registration) splits out of the
@@ -4464,9 +4546,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4464
4546
  /// Change-detection hashes for the model-derived tray state:
4465
4547
  /// field lengths are folded in so adjacent slices can
4466
4548
  /// never alias across boundaries.
4467
- fn hashTrayTitle(title: []const u8) u64 {
4468
- var hasher = std.hash.Wyhash.init(0x7261795f7469746c); // "ray_titl"
4469
- hasher.update(title);
4549
+ fn hashTrayPresentation(presentation: platform.TrayPresentation) u64 {
4550
+ var hasher = std.hash.Wyhash.init(0x7261795f70726573); // "ray_pres"
4551
+ hasher.update(presentation.title);
4552
+ hasher.update(std.mem.asBytes(&presentation.width));
4553
+ hasher.update(std.mem.asBytes(&presentation.icon_opacity));
4554
+ hasher.update(&.{ @intFromEnum(presentation.tone), @intFromBool(presentation.monospaced) });
4470
4555
  return hasher.final();
4471
4556
  }
4472
4557
 
@@ -4479,7 +4564,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
4479
4564
  hasher.update(item.label);
4480
4565
  hasher.update(std.mem.asBytes(&item.command.len));
4481
4566
  hasher.update(item.command);
4482
- hasher.update(&.{ @intFromBool(item.separator), @intFromBool(item.enabled) });
4567
+ hasher.update(std.mem.asBytes(&item.detail.len));
4568
+ hasher.update(item.detail);
4569
+ hasher.update(std.mem.asBytes(&item.key.len));
4570
+ hasher.update(item.key);
4571
+ hasher.update(&.{
4572
+ @intFromBool(item.separator),
4573
+ @intFromBool(item.enabled),
4574
+ @intFromEnum(item.role),
4575
+ @intFromBool(item.modifiers.primary),
4576
+ @intFromBool(item.modifiers.command),
4577
+ @intFromBool(item.modifiers.control),
4578
+ @intFromBool(item.modifiers.option),
4579
+ @intFromBool(item.modifiers.shift),
4580
+ });
4483
4581
  }
4484
4582
  return hasher.final();
4485
4583
  }
@@ -6091,6 +6189,13 @@ fn effectsMinimizeWindowByLabel(context: *anyopaque, window_label: []const u8) b
6091
6189
  return true;
6092
6190
  }
6093
6191
 
6192
+ fn effectsHideWindowByLabel(context: *anyopaque, window_label: []const u8) bool {
6193
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
6194
+ const window_id = effectsWindowIdByLabel(runtime, window_label) orelse return false;
6195
+ runtime.hideWindow(window_id) catch return false;
6196
+ return true;
6197
+ }
6198
+
6094
6199
  fn effectsShowWindowByLabel(context: *anyopaque, window_label: []const u8) bool {
6095
6200
  const runtime: *Runtime = @ptrCast(@alignCast(context));
6096
6201
  // A policy-hidden window keeps `open` true, so the same live-window
@@ -6100,12 +6205,33 @@ fn effectsShowWindowByLabel(context: *anyopaque, window_label: []const u8) bool
6100
6205
  return true;
6101
6206
  }
6102
6207
 
6208
+ fn effectsSetDockPresence(context: *anyopaque, visible: bool) bool {
6209
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
6210
+ runtime.options.platform.services.setDockPresence(visible) catch return false;
6211
+ return true;
6212
+ }
6213
+
6103
6214
  fn effectsQuitApp(context: *anyopaque) bool {
6104
6215
  const runtime: *Runtime = @ptrCast(@alignCast(context));
6105
6216
  runtime.quitApp() catch return false;
6106
6217
  return true;
6107
6218
  }
6108
6219
 
6220
+ fn effectsOpenExternalUrl(context: *anyopaque, url: []const u8) anyerror!void {
6221
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
6222
+ return runtime.openExternalUrl(url);
6223
+ }
6224
+
6225
+ fn effectsRevealPath(context: *anyopaque, path: []const u8) anyerror!void {
6226
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
6227
+ return runtime.revealPath(path);
6228
+ }
6229
+
6230
+ fn effectsFormatLocalTime(context: *anyopaque, timestamp_ms: i64, style: platform.LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
6231
+ const runtime: *Runtime = @ptrCast(@alignCast(context));
6232
+ return runtime.formatLocalTime(timestamp_ms, style, buffer);
6233
+ }
6234
+
6109
6235
  /// The build storage pinned under a presented native context menu:
6110
6236
  /// which canvas's arena pair and which generation (index) of that pair
6111
6237
  /// built the presented tree. The canvas is named by STABLE window
@@ -109,6 +109,156 @@ fn retainedTextExists(runtime: *core.Runtime, text: []const u8) !bool {
109
109
  return false;
110
110
  }
111
111
 
112
+ const RelationalUiModel = struct {
113
+ pages: u32 = 0,
114
+ rows: u32 = 0,
115
+ done: u32 = 0,
116
+ execs: u32 = 0,
117
+ };
118
+
119
+ const RelationalUiMsg = union(enum) {
120
+ add,
121
+ db: effects_mod.EffectDbResult,
122
+ };
123
+
124
+ const RelationalUiApp = ui_app_model.UiApp(RelationalUiModel, RelationalUiMsg);
125
+ const RelationalUiEffects = RelationalUiApp.Effects;
126
+
127
+ fn relationalUiInit(_: *RelationalUiModel, fx: *RelationalUiEffects) void {
128
+ fx.dbExec(.{
129
+ .key = 101,
130
+ .statements = &.{.{ .sql = "CREATE TABLE note(id INTEGER PRIMARY KEY) STRICT;" }},
131
+ .on_result = RelationalUiEffects.dbMsg(.db),
132
+ });
133
+ fx.dbSubscribe(.{
134
+ .key = 102,
135
+ .sql = "SELECT id FROM note ORDER BY id;",
136
+ .tables = &.{"note"},
137
+ .on_result = RelationalUiEffects.dbMsg(.db),
138
+ });
139
+ fx.dbExec(.{
140
+ .key = 103,
141
+ .statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(1);" }},
142
+ .on_result = RelationalUiEffects.dbMsg(.db),
143
+ });
144
+ }
145
+
146
+ fn relationalUiUpdate(model: *RelationalUiModel, msg: RelationalUiMsg, fx: *RelationalUiEffects) void {
147
+ switch (msg) {
148
+ .add => fx.dbExec(.{
149
+ .key = 104,
150
+ .statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(2);" }},
151
+ .on_result = RelationalUiEffects.dbMsg(.db),
152
+ }),
153
+ .db => |result| {
154
+ if (result.outcome != .ok) return;
155
+ switch (result.kind) {
156
+ .page => {
157
+ model.pages += 1;
158
+ model.rows += std.mem.readInt(u32, result.bytes[4..8], .little);
159
+ },
160
+ .done => model.done += 1,
161
+ .exec => model.execs += 1,
162
+ }
163
+ },
164
+ }
165
+ }
166
+
167
+ fn relationalUiView(ui: *RelationalUiApp.Ui, model: *const RelationalUiModel) RelationalUiApp.Ui.Node {
168
+ return ui.text(.{}, ui.fmt("{d} relational pages", .{model.pages}));
169
+ }
170
+
171
+ test "record-store test harness binds one hermetic in-memory database" {
172
+ const harness = try core.TestHarness().createWithRecordStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
173
+ defer harness.destroy(std.testing.allocator);
174
+ try std.testing.expect(harness.record_store != null);
175
+ try std.testing.expect(harness.runtime.options.record_store != null);
176
+ harness.null_platform.gpu_surfaces = true;
177
+
178
+ const app_state = try std.testing.allocator.create(CounterApp);
179
+ defer std.testing.allocator.destroy(app_state);
180
+ app_state.* = CounterApp.init(std.heap.page_allocator, .{}, counterOptions());
181
+ defer app_state.deinit();
182
+ const app = app_state.app();
183
+ try harness.start(app);
184
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
185
+ .label = canvas_label,
186
+ .size = geometry.SizeF.init(400, 300),
187
+ .scale_factor = 1,
188
+ .frame_index = 1,
189
+ .timestamp_ns = 1_000_000,
190
+ .nonblank = true,
191
+ } });
192
+ try app_state.dispatch(&harness.runtime, 1, .increment);
193
+ try std.testing.expect(app_state.effects.record_store_binding != null);
194
+ try harness.stop(app);
195
+ }
196
+
197
+ test "relational test harness binds one hermetic in-memory database" {
198
+ const harness = try core.TestHarness().createWithRelationalStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
199
+ defer harness.destroy(std.testing.allocator);
200
+ try std.testing.expect(harness.relational_store != null);
201
+ try std.testing.expect(harness.runtime.options.relational_store != null);
202
+ harness.null_platform.gpu_surfaces = true;
203
+
204
+ const app_state = try std.testing.allocator.create(CounterApp);
205
+ defer std.testing.allocator.destroy(app_state);
206
+ app_state.* = CounterApp.init(std.heap.page_allocator, .{}, counterOptions());
207
+ defer app_state.deinit();
208
+ const app = app_state.app();
209
+ try harness.start(app);
210
+ try app_state.dispatch(&harness.runtime, 1, .increment);
211
+ try std.testing.expect(app_state.effects.relational_store_binding != null);
212
+ try harness.stop(app);
213
+ }
214
+
215
+ test "ui app flushes relational live queries after init and update command batches" {
216
+ const harness = try core.TestHarness().createWithRelationalStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
217
+ defer harness.destroy(std.testing.allocator);
218
+ harness.null_platform.gpu_surfaces = true;
219
+
220
+ const app_state = try std.testing.allocator.create(RelationalUiApp);
221
+ defer std.testing.allocator.destroy(app_state);
222
+ app_state.* = RelationalUiApp.init(std.heap.page_allocator, .{}, .{
223
+ .name = "ui-app-relational-live",
224
+ .scene = counter_scene,
225
+ .canvas_label = canvas_label,
226
+ .update_fx = relationalUiUpdate,
227
+ .init_fx = relationalUiInit,
228
+ .view = relationalUiView,
229
+ });
230
+ defer app_state.deinit();
231
+ const app = app_state.app();
232
+ try harness.start(app);
233
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
234
+ .label = canvas_label,
235
+ .size = geometry.SizeF.init(400, 300),
236
+ .scale_factor = 1,
237
+ .frame_index = 1,
238
+ .timestamp_ns = 1_000_000,
239
+ .nonblank = true,
240
+ } });
241
+
242
+ // init_fx creates the table, subscribes while it is empty, then inserts.
243
+ // Its one flush therefore delivers the initial empty page and one
244
+ // refreshed one-row page.
245
+ try app_state.drainEffects(&harness.runtime);
246
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.pages);
247
+ try std.testing.expectEqual(@as(u32, 1), app_state.model.rows);
248
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.done);
249
+ try std.testing.expectEqual(@as(u32, 2), app_state.model.execs);
250
+
251
+ // A later update_fx transaction must invalidate and rerun the same live
252
+ // query without the Zig app manually reaching into the effects host.
253
+ try app_state.dispatch(&harness.runtime, 1, .add);
254
+ try app_state.drainEffects(&harness.runtime);
255
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.pages);
256
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.rows);
257
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.done);
258
+ try std.testing.expectEqual(@as(u32, 3), app_state.model.execs);
259
+ try harness.stop(app);
260
+ }
261
+
112
262
  test "ui app owns install, dispatch, and rebuild end to end" {
113
263
  // The runtime and the app are both large structs; keep them off the
114
264
  // test thread's stack.
@@ -3914,7 +4064,7 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
3914
4064
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = frame_event });
3915
4065
 
3916
4066
  // The snapshot exposes the applied tray: model-derived title, every
3917
- // dropdown row with id/label/command/enabled, and separators —
4067
+ // dropdown row with its action and rich presentation fields, and separators —
3918
4068
  // the menu bar is outside every window capture, so this is the only
3919
4069
  // automation-visible evidence the model-driven tray exists.
3920
4070
  {
@@ -3923,10 +4073,10 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
3923
4073
  try automation.snapshot.writeText(harness.runtime.automationSnapshot("Tray"), &writer);
3924
4074
  const text = writer.buffered();
3925
4075
  try std.testing.expect(std.mem.indexOf(u8, text, "tray title=\"ZN 3\" items=4\n") != null);
3926
- try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true\n") != null);
4076
+ try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
3927
4077
  try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
3928
4078
  // The fixture disables the SELECTED row (initially issue 0).
3929
- try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false\n") != null);
4079
+ try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
3930
4080
  }
3931
4081
 
3932
4082
  // `tray-action <id>` drives a dropdown row through the same platform
@@ -3939,8 +4089,8 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
3939
4089
  var writer = std.Io.Writer.fixed(&buffer);
3940
4090
  try automation.snapshot.writeText(harness.runtime.automationSnapshot("Tray"), &writer);
3941
4091
  const text = writer.buffered();
3942
- try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #11 label=\"Adopt the tray seam\" command=\"issue.select.1\" enabled=false\n") != null);
3943
- try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=true\n") != null);
4092
+ try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #11 label=\"Adopt the tray seam\" command=\"issue.select.1\" enabled=false detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
4093
+ try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
3944
4094
  }
3945
4095
 
3946
4096
  // Unknown or malformed item ids are loud driver misuse, never a
@@ -119,7 +119,14 @@ fn validateCredentialField(value: []const u8, max_len: usize) !void {
119
119
  pub fn validateTrayOptions(options: platform.TrayOptions) !void {
120
120
  try validateTrayField(options.icon_path, platform.max_tray_icon_path_bytes);
121
121
  try validateTrayField(options.title, platform.max_tray_title_bytes);
122
+ try validateTrayPresentation(options.presentation);
122
123
  try validateTrayField(options.tooltip, platform.max_tray_tooltip_bytes);
124
+ try validateTrayField(options.activation_command, platform.max_tray_item_command_bytes);
125
+ try validateTrayField(options.alternate_activation_command, platform.max_tray_item_command_bytes);
126
+ try validateTrayField(options.open_command, platform.max_tray_item_command_bytes);
127
+ if (options.activation_command.len > 0) try validateCommandName(options.activation_command);
128
+ if (options.alternate_activation_command.len > 0) try validateCommandName(options.alternate_activation_command);
129
+ if (options.open_command.len > 0) try validateCommandName(options.open_command);
123
130
  try validateTrayMenuItems(options.items);
124
131
  }
125
132
 
@@ -127,11 +134,22 @@ pub fn validateTrayTitle(title: []const u8) !void {
127
134
  try validateTrayField(title, platform.max_tray_title_bytes);
128
135
  }
129
136
 
137
+ pub fn validateTrayPresentation(presentation: platform.TrayPresentation) !void {
138
+ try validateTrayTitle(presentation.title);
139
+ if (!std.math.isFinite(presentation.width) or presentation.width < 0) return error.InvalidTrayOptions;
140
+ if (!std.math.isFinite(presentation.icon_opacity) or presentation.icon_opacity < 0 or presentation.icon_opacity > 1) return error.InvalidTrayOptions;
141
+ }
142
+
130
143
  pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
131
144
  if (items.len > platform.max_tray_items) return error.InvalidTrayOptions;
132
145
  for (items, 0..) |item, index| {
133
146
  try validateTrayField(item.label, platform.max_tray_item_label_bytes);
134
147
  try validateTrayField(item.command, platform.max_tray_item_command_bytes);
148
+ try validateTrayField(item.detail, platform.max_tray_item_detail_bytes);
149
+ try validateTrayField(item.key, platform.max_menu_key_bytes);
150
+ if (item.role != .command and item.role != .agent and item.command.len > 0) return error.InvalidTrayOptions;
151
+ if (item.detail.len > 0 and item.role != .info and item.role != .hero and item.role != .agent and item.role != .context) return error.InvalidTrayOptions;
152
+ if (item.separator and (item.detail.len > 0 or item.role != .command)) return error.InvalidTrayOptions;
135
153
  if (item.id != 0) {
136
154
  for (items[0..index]) |previous| {
137
155
  if (previous.id == item.id) return error.InvalidTrayOptions;
@@ -142,6 +160,10 @@ pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
142
160
  try validateCommandName(item.command);
143
161
  }
144
162
  if (!item.separator and item.label.len == 0) return error.InvalidTrayOptions;
163
+ if (item.key.len > 0) {
164
+ if (item.separator or item.command.len == 0) return error.InvalidTrayOptions;
165
+ if (!platform.isValidShortcutBinding(item.key, item.modifiers)) return error.InvalidTrayOptions;
166
+ }
145
167
  }
146
168
  }
147
169
 
@@ -203,7 +203,12 @@ pub const RuntimeView = struct {
203
203
  gpu_scale_factor: f32 = 1,
204
204
  gpu_frame_index: u64 = 0,
205
205
  gpu_timestamp_ns: u64 = 0,
206
+ /// Profiling-only completion stamp. Kept separate from gpu_timestamp_ns
207
+ /// so `profile on` can start an honest interval window without erasing
208
+ /// the live frame clock used by animation and diagnostics.
209
+ gpu_frame_profile_timestamp_ns: u64 = 0,
206
210
  gpu_frame_interval_ns: u64 = platform.default_gpu_frame_interval_ns,
211
+ gpu_input_event_count: u64 = 0,
207
212
  gpu_pending_input_timestamp_ns: u64 = 0,
208
213
  gpu_input_timestamp_ns: u64 = 0,
209
214
  gpu_input_latency_ns: u64 = 0,
@@ -218,6 +223,7 @@ pub const RuntimeView = struct {
218
223
  gpu_first_frame_latency_budget_ok: bool = true,
219
224
  gpu_first_frame_latency_recorded: bool = false,
220
225
  gpu_frame_nonblank: bool = false,
226
+ gpu_occluded: bool = false,
221
227
  gpu_sample_color: u32 = 0,
222
228
  /// Immutable creation-time backend request. `gpu_backend` below is
223
229
  /// completion state and changes to the concrete presenter reported by
@@ -1089,6 +1095,7 @@ pub const RuntimeView = struct {
1089
1095
  .gpu_frame_index = self.gpu_frame_index,
1090
1096
  .gpu_timestamp_ns = self.gpu_timestamp_ns,
1091
1097
  .gpu_frame_interval_ns = self.gpu_frame_interval_ns,
1098
+ .gpu_input_event_count = self.gpu_input_event_count,
1092
1099
  .gpu_input_timestamp_ns = self.gpu_input_timestamp_ns,
1093
1100
  .gpu_input_latency_ns = self.gpu_input_latency_ns,
1094
1101
  .gpu_input_latency_budget_ns = self.gpu_input_latency_budget_ns,
@@ -1099,6 +1106,7 @@ pub const RuntimeView = struct {
1099
1106
  .gpu_first_frame_latency_budget_exceeded_count = self.gpu_first_frame_latency_budget_exceeded_count,
1100
1107
  .gpu_first_frame_latency_budget_ok = self.gpu_first_frame_latency_budget_ok,
1101
1108
  .gpu_frame_nonblank = self.gpu_frame_nonblank,
1109
+ .gpu_occluded = self.gpu_occluded,
1102
1110
  .gpu_sample_color = self.gpu_sample_color,
1103
1111
  .gpu_backend = self.gpu_backend,
1104
1112
  .gpu_pixel_format = self.gpu_pixel_format,
@@ -1192,6 +1200,7 @@ pub const RuntimeView = struct {
1192
1200
  }
1193
1201
 
1194
1202
  pub fn recordGpuSurfaceInputTimestamp(self: *RuntimeView, timestamp_ns: u64) void {
1203
+ self.gpu_input_event_count +|= 1;
1195
1204
  if (timestamp_ns == 0) return;
1196
1205
  self.gpu_pending_input_timestamp_ns = timestamp_ns;
1197
1206
  self.gpu_input_timestamp_ns = timestamp_ns;
@@ -178,6 +178,7 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
178
178
  self.windows[index].info.frame = native_info.frame;
179
179
  self.windows[index].info.scale_factor = native_info.scale_factor;
180
180
  self.windows[index].info.open = native_info.open;
181
+ self.windows[index].info.hidden = native_info.hidden;
181
182
  if (!self.windows[index].main_frame_set) {
182
183
  self.windows[index].main_frame = geometry.RectF.init(0, 0, native_info.frame.width, native_info.frame.height);
183
184
  }
@@ -26,8 +26,7 @@ const viewInfoFromWebView = bridge_responses.viewInfoFromWebView;
26
26
  const RuntimeWebView = runtime_state.RuntimeWebView;
27
27
  const FocusTraversalDirection = runtime_state.FocusTraversalDirection;
28
28
  const sourceWebViewUrl = runtime_state.sourceWebViewUrl;
29
- const nowNanoseconds = runtime_clock.nowNanoseconds;
30
- const timestampToU64 = runtime_clock.timestampToU64;
29
+ const monotonicNanoseconds = runtime_clock.monotonicNanoseconds;
31
30
  const CommandSource = runtime_api.CommandSource;
32
31
 
33
32
  fn copyInto(buffer: []u8, value: []const u8) ![]const u8 {
@@ -492,7 +491,7 @@ pub fn RuntimeWindowViewRuntime(comptime Runtime: type) type {
492
491
  .gpu_color_space = if (options.kind == .gpu_surface) options.gpu_surface.color_space else .none,
493
492
  .gpu_vsync = options.kind == .gpu_surface and options.gpu_surface.vsync,
494
493
  .gpu_status = if (options.kind == .gpu_surface) .ready else .unavailable,
495
- .gpu_surface_created_timestamp_ns = if (options.kind == .gpu_surface) timestampToU64(nowNanoseconds()) else 0,
494
+ .gpu_surface_created_timestamp_ns = if (options.kind == .gpu_surface) monotonicNanoseconds() else 0,
496
495
  .focused = false,
497
496
  .keyboard_active = windowKeyboardActive(self, options.window_id),
498
497
  .open = true,
@@ -146,6 +146,24 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
146
146
  try self.options.platform.services.minimizeWindow(window_id);
147
147
  }
148
148
 
149
+ /// Keep a live window and its views, but order it offscreen until
150
+ /// `showWindow` brings it back. This is an app-driven hide, not a
151
+ /// close, so identity and rendered state are retained.
152
+ pub fn hideWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
153
+ const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
154
+ if (!self.windows[index].info.open) return error.WindowNotFound;
155
+ const was_hidden = self.windows[index].info.hidden;
156
+ const was_focused = self.windows[index].info.focused;
157
+ self.windows[index].info.hidden = true;
158
+ self.windows[index].info.focused = false;
159
+ self.options.platform.services.hideWindow(window_id) catch |err| {
160
+ self.windows[index].info.hidden = was_hidden;
161
+ self.windows[index].info.focused = was_focused;
162
+ return err;
163
+ };
164
+ self.invalidated = true;
165
+ }
166
+
149
167
  /// The real OS show verb: unhide and order front — the counterpart
150
168
  /// to a `close_policy = .hide` hide, and what a tray "Open"
151
169
  /// action resolves to. Like `closeWindow`, the runtime flag
@@ -232,6 +250,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
232
250
  .always_on_top = shell_window.always_on_top,
233
251
  .click_through = shell_window.click_through,
234
252
  .activate_on_show = shell_window.activate_on_show,
253
+ .allows_fullscreen = shell_window.allows_fullscreen,
235
254
  .min_width = shell_window.min_width,
236
255
  .min_height = shell_window.min_height,
237
256
  .close_policy = shell_layout.shellClosePolicy(shell_window.close_policy),