@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
@@ -617,7 +617,10 @@ test "app id validation" {
617
617
  try validateAppId("com.example.app", .reverse_dns);
618
618
  try validateAppId("my-tool", .simple);
619
619
 
620
+ const oversized_id = [_]u8{'a'} ** (types.max_app_id_bytes + 1);
621
+
620
622
  try std.testing.expectError(error.InvalidId, validateAppId("", .reverse_dns));
623
+ try std.testing.expectError(error.InvalidId, validateAppId(&oversized_id, .simple));
621
624
  try std.testing.expectError(error.InvalidId, validateAppId("example", .reverse_dns));
622
625
  try std.testing.expectError(error.InvalidId, validateAppId("Com.example.app", .reverse_dns));
623
626
  try std.testing.expectError(error.InvalidId, validateAppId("com/example/app", .reverse_dns));
@@ -32,6 +32,9 @@ pub const ValidationError = error{
32
32
 
33
33
  pub const max_shortcuts: usize = 64;
34
34
  pub const max_shortcut_id_bytes: usize = 64;
35
+ /// App identities double as the credential-manager service namespace, whose
36
+ /// cross-platform ABI is bounded to this size.
37
+ pub const max_app_id_bytes: usize = 128;
35
38
  pub const max_shortcut_key_bytes: usize = 32;
36
39
  pub const max_shell_windows: usize = 16;
37
40
  pub const max_shell_views_per_window: usize = 128;
@@ -161,6 +164,9 @@ pub const CapabilityKind = enum {
161
164
  dialog,
162
165
  clipboard,
163
166
  credentials,
167
+ persist,
168
+ store,
169
+ sqlite,
164
170
  open_url,
165
171
  reveal_path,
166
172
  recent_documents,
@@ -186,6 +192,9 @@ pub const Capability = union(CapabilityKind) {
186
192
  dialog: void,
187
193
  clipboard: void,
188
194
  credentials: void,
195
+ persist: void,
196
+ store: void,
197
+ sqlite: void,
189
198
  open_url: void,
190
199
  reveal_path: void,
191
200
  recent_documents: void,
@@ -363,6 +372,8 @@ pub const Window = struct {
363
372
  /// Show without activating the app or taking keyboard focus when
364
373
  /// false. An explicit focus action can still activate the window.
365
374
  activate_on_show: bool = true,
375
+ initially_hidden: bool = false,
376
+ allows_fullscreen: bool = true,
366
377
  /// Content min-size floor the window itself enforces (macOS
367
378
  /// `contentMinSize`): the resize stops at the floor instead of the
368
379
  /// layout clamping/clipping panes below it. 0 = no floor.
@@ -496,6 +507,14 @@ pub const ShellWindow = struct {
496
507
  always_on_top: bool = false,
497
508
  click_through: bool = false,
498
509
  activate_on_show: bool = true,
510
+ /// Create the native window ordered out and keep it hidden until an
511
+ /// explicit show/focus request. Intended for retained menu-bar app
512
+ /// host windows that must never flash during launch.
513
+ initially_hidden: bool = false,
514
+ /// Whether macOS exposes native fullscreen for this window. False
515
+ /// keeps ordinary resizing but disables the green fullscreen button
516
+ /// and the fullscreen command.
517
+ allows_fullscreen: bool = true,
499
518
  /// Content min-size floor the window itself enforces (macOS
500
519
  /// `contentMinSize`): the resize stops at the floor instead of the
501
520
  /// layout clamping/clipping panes below it. 0 = no floor. Like
@@ -627,12 +646,25 @@ pub const UpdateConfig = struct {
627
646
  check_on_start: bool = false,
628
647
  };
629
648
 
649
+ pub const PersistRestore = struct {
650
+ ok: []const u8,
651
+ none: []const u8,
652
+ err: []const u8,
653
+ };
654
+
655
+ pub const PersistConfig = struct {
656
+ version: u64,
657
+ debounce_ms: u32 = 500,
658
+ restore: PersistRestore,
659
+ };
660
+
630
661
  pub const Manifest = struct {
631
662
  identity: AppIdentity,
632
663
  version: Version,
633
664
  icons: []const Icon = &.{},
634
665
  permissions: []const Permission = &.{},
635
666
  capabilities: []const Capability = &.{},
667
+ persist: ?PersistConfig = null,
636
668
  bridge: BridgeConfig = .{},
637
669
  frontend: ?FrontendConfig = null,
638
670
  security: SecurityConfig = .{},
@@ -74,6 +74,7 @@ pub fn validateManifest(manifest: Manifest) ValidationError!void {
74
74
  try validateIcons(manifest.icons);
75
75
  try validatePermissions(manifest.permissions);
76
76
  try validateCapabilities(manifest.capabilities);
77
+ try validatePersist(manifest.persist, manifest.capabilities);
77
78
  try validateBridge(manifest.bridge);
78
79
  if (manifest.frontend) |frontend| try validateFrontend(frontend);
79
80
  try validateSecurity(manifest.security);
@@ -403,7 +404,7 @@ pub const AppIdMode = enum {
403
404
  };
404
405
 
405
406
  pub fn validateAppId(id: []const u8, mode: AppIdMode) ValidationError!void {
406
- if (id.len == 0) return error.InvalidId;
407
+ if (id.len == 0 or id.len > types.max_app_id_bytes) return error.InvalidId;
407
408
  if (id[0] == '.' or id[id.len - 1] == '.') return error.InvalidId;
408
409
 
409
410
  var segments: usize = 0;
@@ -543,6 +544,23 @@ pub fn validateCapabilities(capabilities: []const Capability) ValidationError!vo
543
544
  }
544
545
  }
545
546
 
547
+ pub fn validatePersist(config: ?types.PersistConfig, capabilities: []const Capability) ValidationError!void {
548
+ var declared = false;
549
+ for (capabilities) |capability| {
550
+ if (capability == .persist) declared = true;
551
+ }
552
+ if (declared != (config != null)) return error.MissingRequiredField;
553
+ const persist = config orelse return;
554
+ if (persist.version == 0 or persist.version > 9_007_199_254_740_991) return error.InvalidVersion;
555
+ if (persist.debounce_ms > 60_000) return error.InvalidTimeout;
556
+ try validateName(persist.restore.ok);
557
+ try validateName(persist.restore.none);
558
+ try validateName(persist.restore.err);
559
+ if (std.mem.eql(u8, persist.restore.ok, persist.restore.none) or
560
+ std.mem.eql(u8, persist.restore.ok, persist.restore.err) or
561
+ std.mem.eql(u8, persist.restore.none, persist.restore.err)) return error.InvalidName;
562
+ }
563
+
546
564
  pub fn validateBridge(bridge: BridgeConfig) ValidationError!void {
547
565
  for (bridge.commands, 0..) |command, i| {
548
566
  try validateName(command.name);
package/src/root.zig CHANGED
@@ -46,6 +46,38 @@ pub const EffectFetchOutcome = runtime.EffectFetchOutcome;
46
46
  pub const EffectFileOp = runtime.EffectFileOp;
47
47
  pub const EffectFileOutcome = runtime.EffectFileOutcome;
48
48
  pub const EffectFileResult = runtime.EffectFileResult;
49
+ pub const EffectCredentialsOperation = runtime.EffectCredentialsOperation;
50
+ pub const EffectCredentialsOutcome = runtime.EffectCredentialsOutcome;
51
+ pub const EffectCredentialsResult = runtime.EffectCredentialsResult;
52
+ pub const EffectPersistOutcome = runtime.EffectPersistOutcome;
53
+ pub const EffectPersistResult = runtime.EffectPersistResult;
54
+ pub const max_effect_persist_snapshot_bytes = runtime.max_effect_persist_snapshot_bytes;
55
+ pub const EffectStoreOutcome = runtime.EffectStoreOutcome;
56
+ pub const EffectStoreOp = runtime.EffectStoreOp;
57
+ pub const RecordStoreBinding = runtime.RecordStoreBinding;
58
+ pub const EffectDbValue = runtime.EffectDbValue;
59
+ pub const EffectDbStatement = runtime.EffectDbStatement;
60
+ pub const EffectDbOutcome = runtime.EffectDbOutcome;
61
+ pub const EffectDbResultKind = runtime.EffectDbResultKind;
62
+ pub const EffectDbResult = runtime.EffectDbResult;
63
+ pub const RelationalStoreBinding = runtime.RelationalStoreBinding;
64
+ pub const max_db_effects = runtime.max_db_effects;
65
+ pub const max_effect_db_sql_bytes = runtime.max_effect_db_sql_bytes;
66
+ pub const max_effect_db_parameters = runtime.max_effect_db_parameters;
67
+ pub const max_effect_db_exec_statements = runtime.max_effect_db_exec_statements;
68
+ pub const max_effect_db_parameter_bytes = runtime.max_effect_db_parameter_bytes;
69
+ pub const max_effect_db_exec_parameter_bytes = runtime.max_effect_db_exec_parameter_bytes;
70
+ pub const default_effect_db_page_rows = runtime.default_effect_db_page_rows;
71
+ pub const max_effect_db_page_bytes = runtime.max_effect_db_page_bytes;
72
+ pub const max_effect_db_result_rows = runtime.max_effect_db_result_rows;
73
+ pub const max_effect_db_result_bytes = runtime.max_effect_db_result_bytes;
74
+ pub const max_effect_store_key_bytes = runtime.max_effect_store_key_bytes;
75
+ pub const max_effect_store_value_bytes = runtime.max_effect_store_value_bytes;
76
+ pub const max_effect_store_batch_entries = runtime.max_effect_store_batch_entries;
77
+ pub const max_effect_store_batch_bytes = runtime.max_effect_store_batch_bytes;
78
+ pub const max_effect_store_result_bytes = runtime.max_effect_store_result_bytes;
79
+ pub const default_effect_store_scan_limit = runtime.default_effect_store_scan_limit;
80
+ pub const max_effect_store_scan_limit = runtime.max_effect_store_scan_limit;
49
81
  pub const effect_error_exit_code = runtime.effect_error_exit_code;
50
82
  pub const max_effects = runtime.max_effects;
51
83
  pub const max_effect_argv = runtime.max_effect_argv;
@@ -64,6 +96,14 @@ pub const max_effect_body_bytes = runtime.max_effect_body_bytes;
64
96
  pub const default_effect_fetch_timeout_ms = runtime.default_effect_fetch_timeout_ms;
65
97
  pub const max_effect_file_path_bytes = runtime.max_effect_file_path_bytes;
66
98
  pub const max_effect_file_bytes = runtime.max_effect_file_bytes;
99
+ pub const persist_store = runtime.persist_store;
100
+ pub const PersistStore = runtime.PersistStore;
101
+ pub const PersistOutcome = runtime.PersistOutcome;
102
+ pub const max_persist_snapshot_bytes = runtime.max_persist_snapshot_bytes;
103
+ pub const record_store = runtime.record_store;
104
+ pub const RecordStore = runtime.RecordStore;
105
+ pub const relational_store = runtime.relational_store;
106
+ pub const RelationalStore = runtime.RelationalStore;
67
107
  pub const EffectClipboardOp = runtime.EffectClipboardOp;
68
108
  pub const EffectClipboardOutcome = runtime.EffectClipboardOutcome;
69
109
  pub const EffectClipboardResult = runtime.EffectClipboardResult;
@@ -104,6 +144,11 @@ pub const max_effect_pty_write_bytes = runtime.max_effect_pty_write_bytes;
104
144
  pub const max_effect_pty_term_bytes = runtime.max_effect_pty_term_bytes;
105
145
  pub const EffectHostResult = runtime.EffectHostResult;
106
146
  pub const HostCallBinding = runtime.HostCallBinding;
147
+ pub const HostCallCompletion = runtime.HostCallCompletion;
148
+ pub const ServiceHost = runtime.ServiceHost;
149
+ pub const serviceEnvironmentVariableAllowed = runtime.serviceEnvironmentVariableAllowed;
150
+ pub const ServicePool = runtime.ServicePool;
151
+ pub const service_pool = runtime.service_pool;
107
152
  pub const max_effect_host_name_bytes = runtime.max_effect_host_name_bytes;
108
153
  pub const max_effect_host_payload_bytes = runtime.max_effect_host_payload_bytes;
109
154
  pub const max_effect_host_result_bytes = runtime.max_effect_host_result_bytes;
@@ -171,6 +216,7 @@ pub const FormFactor = platform.FormFactor;
171
216
  pub const WindowDragRegion = platform.WindowDragRegion;
172
217
  pub const WindowShowMode = platform.WindowShowMode;
173
218
  pub const WindowClosePolicy = platform.WindowClosePolicy;
219
+ pub const LaunchAtLoginStatus = platform.LaunchAtLoginStatus;
174
220
  pub const Menu = platform.Menu;
175
221
  pub const MenuItem = platform.MenuItem;
176
222
  pub const Shortcut = platform.Shortcut;
@@ -489,6 +489,17 @@ pub const Options = struct {
489
489
  shortcuts: []const platform.Shortcut = &.{},
490
490
  automation: ?automation.Server = null,
491
491
  window_state_store: ?window_state.Store = null,
492
+ /// Engine-owned record-store service. The app runner sets this only
493
+ /// when app.zon declares the `store` capability; replay leaves it null
494
+ /// because journaled effect results are the whole external world.
495
+ record_store: ?runtime_effects.RecordStoreBinding = null,
496
+ /// Engine-owned relational database, installed only for the `sqlite`
497
+ /// capability. Replay keeps it null and feeds journaled DB results.
498
+ relational_store: ?runtime_effects.RelationalStoreBinding = null,
499
+ /// Whether the app declared the `credentials` capability. Permission is
500
+ /// checked separately; both gates must be open before core effects may
501
+ /// reach the platform keychain.
502
+ credentials_enabled: bool = false,
492
503
  js_window_api: bool = false,
493
504
  /// Whether this build ships the embedded web layer. The app runner
494
505
  /// sets it from the build graph's app.zon inference (declare-to-use:
@@ -93,6 +93,10 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
93
93
  .command = item.command,
94
94
  .separator = item.separator,
95
95
  .enabled = item.enabled,
96
+ .detail = item.detail,
97
+ .role = item.role,
98
+ .key = item.key,
99
+ .modifiers = item.modifiers,
96
100
  };
97
101
  }
98
102
  return .{
@@ -320,22 +320,43 @@ test "runtime validates native OS actions before platform dispatch" {
320
320
 
321
321
  try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.createTray(.{ .items = &.{.{ .label = "" }} }));
322
322
  try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .label = "" }}));
323
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.createTray(.{ .presentation = .{ .width = -1 } }));
324
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.createTray(.{ .presentation = .{ .icon_opacity = 1.1 } }));
325
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .id = 7, .label = "Readout", .command = "app.bad", .role = .info }}));
326
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .id = 7, .label = "Command", .detail = "not allowed" }}));
327
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .id = 7, .label = "No command", .key = "q" }}));
328
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .id = 7, .label = "Bad key", .command = "app.bad-key", .key = "not-a-key", .modifiers = .{ .command = true } }}));
329
+ try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .id = 7, .label = "Unsafe key", .command = "app.unsafe-key", .key = "q" }}));
323
330
  try harness.runtime.createTray(.{
324
331
  .icon_path = "/tmp/tray.png",
325
332
  .tooltip = "native-sdk",
333
+ .presentation = .{ .title = "LIVE", .width = 62, .tone = .warning, .icon_opacity = 0.5, .monospaced = true },
334
+ .activation_command = "app.refresh",
335
+ .alternate_activation_command = "app.mode",
336
+ .open_command = "app.opened",
326
337
  .items = &.{
327
- .{ .id = 1, .label = "Open" },
338
+ .{ .id = 1, .label = "Open", .detail = "ready", .role = .info },
328
339
  .{ .separator = true },
329
- .{ .id = 2, .label = "Quit", .enabled = false },
340
+ .{ .id = 2, .label = "Quit", .command = "app.quit", .enabled = false, .detail = "warning", .role = .agent, .key = "q", .modifiers = .{ .command = true } },
330
341
  },
331
342
  });
332
343
  try std.testing.expectEqual(@as(usize, 1), harness.null_platform.trayCreateCount());
333
344
  try std.testing.expectEqualStrings("/tmp/tray.png", harness.null_platform.lastTrayIconPath());
334
345
  try std.testing.expectEqualStrings("native-sdk", harness.null_platform.lastTrayTooltip());
346
+ try std.testing.expectEqualStrings("LIVE", harness.null_platform.lastTrayTitle());
347
+ try std.testing.expectEqualStrings("app.refresh", harness.null_platform.lastTrayActivationCommand());
348
+ try std.testing.expectEqualStrings("app.mode", harness.null_platform.lastTrayAlternateActivationCommand());
349
+ try std.testing.expectEqualStrings("app.opened", harness.null_platform.lastTrayOpenCommand());
350
+ try std.testing.expectEqual(platform.TrayTone.warning, harness.null_platform.lastTrayPresentation().tone);
351
+ try std.testing.expectEqual(@as(f32, 62), harness.null_platform.lastTrayPresentation().width);
335
352
  try std.testing.expectEqual(@as(usize, 3), harness.null_platform.trayItems().len);
336
353
  try std.testing.expectEqualStrings("Open", harness.null_platform.trayItems()[0].label);
337
354
  try std.testing.expect(harness.null_platform.trayItems()[1].separator);
338
355
  try std.testing.expect(!harness.null_platform.trayItems()[2].enabled);
356
+ try std.testing.expectEqual(platform.TrayItemRole.agent, harness.null_platform.trayItems()[2].role);
357
+ try std.testing.expectEqualStrings("warning", harness.null_platform.trayItems()[2].detail);
358
+ try std.testing.expectEqualStrings("q", harness.null_platform.trayItems()[2].key);
359
+ try std.testing.expect(harness.null_platform.trayItems()[2].modifiers.command);
339
360
  try harness.runtime.updateTrayMenu(&.{.{ .id = 3, .label = "Settings" }});
340
361
  try std.testing.expectEqual(@as(usize, 2), harness.null_platform.trayUpdateCount());
341
362
  try std.testing.expectEqualStrings("Settings", harness.null_platform.trayItems()[0].label);
@@ -83,7 +83,7 @@ pub fn writeViewJsonToWriter(view: platform.ViewInfo, writer: anytype) !void {
83
83
  try json.writeString(writer, view.command);
84
84
  try writer.writeAll(",\"url\":");
85
85
  try json.writeString(writer, view.url);
86
- try writer.print(",\"x\":{d},\"y\":{d},\"width\":{d},\"height\":{d},\"layer\":{d},\"visible\":{},\"enabled\":{},\"transparent\":{},\"bridge\":{},\"gpuWidth\":{d},\"gpuHeight\":{d},\"gpuScale\":{d},\"gpuFrame\":{d},\"gpuTimestampNs\":{d},\"gpuFrameIntervalNs\":{d},\"gpuInputTimestampNs\":{d},\"gpuInputLatencyNs\":{d},\"gpuInputLatencyBudgetNs\":{d},\"gpuInputLatencyBudgetExceededCount\":{d},\"gpuInputLatencyBudgetOk\":{},\"gpuFirstFrameLatencyNs\":{d},\"gpuFirstFrameLatencyBudgetNs\":{d},\"gpuFirstFrameLatencyBudgetExceededCount\":{d},\"gpuFirstFrameLatencyBudgetOk\":{},\"gpuNonblank\":{},\"gpuSampleColor\":{d},\"gpuBackend\":", .{
86
+ try writer.print(",\"x\":{d},\"y\":{d},\"width\":{d},\"height\":{d},\"layer\":{d},\"visible\":{},\"enabled\":{},\"transparent\":{},\"bridge\":{},\"gpuWidth\":{d},\"gpuHeight\":{d},\"gpuScale\":{d},\"gpuFrame\":{d},\"gpuTimestampNs\":{d},\"gpuFrameIntervalNs\":{d},\"gpuInputCount\":{d},\"gpuInputTimestampNs\":{d},\"gpuInputLatencyNs\":{d},\"gpuInputLatencyBudgetNs\":{d},\"gpuInputLatencyBudgetExceededCount\":{d},\"gpuInputLatencyBudgetOk\":{},\"gpuFirstFrameLatencyNs\":{d},\"gpuFirstFrameLatencyBudgetNs\":{d},\"gpuFirstFrameLatencyBudgetExceededCount\":{d},\"gpuFirstFrameLatencyBudgetOk\":{},\"gpuNonblank\":{},\"gpuOccluded\":{},\"gpuSampleColor\":{d},\"gpuBackend\":", .{
87
87
  view.frame.x,
88
88
  view.frame.y,
89
89
  view.frame.width,
@@ -99,6 +99,7 @@ pub fn writeViewJsonToWriter(view: platform.ViewInfo, writer: anytype) !void {
99
99
  view.gpu_frame_index,
100
100
  view.gpu_timestamp_ns,
101
101
  view.gpu_frame_interval_ns,
102
+ view.gpu_input_event_count,
102
103
  view.gpu_input_timestamp_ns,
103
104
  view.gpu_input_latency_ns,
104
105
  view.gpu_input_latency_budget_ns,
@@ -109,6 +110,7 @@ pub fn writeViewJsonToWriter(view: platform.ViewInfo, writer: anytype) !void {
109
110
  view.gpu_first_frame_latency_budget_exceeded_count,
110
111
  view.gpu_first_frame_latency_budget_ok,
111
112
  view.gpu_frame_nonblank,
113
+ view.gpu_occluded,
112
114
  view.gpu_sample_color,
113
115
  });
114
116
  try json.writeString(writer, @tagName(view.gpu_backend));
@@ -1198,9 +1198,7 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1198
1198
  if (self.views[index].pruneCompletedNoopCanvasRenderAnimations(frame_options.timestamp_ns)) {
1199
1199
  self.views[index].compactCanvasFrameRenderOverrideNoops();
1200
1200
  }
1201
- if (self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns)) {
1202
- self.invalidateFor(.state, self.views[index].frame);
1203
- }
1201
+ const render_animation_active = self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns);
1204
1202
  // An armed tooltip show delay — and a running anchor-gap
1205
1203
  // transit grace — only fire on a presented frame's
1206
1204
  // timestamp, so frames must keep coming while either is
@@ -1213,8 +1211,17 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1213
1211
  // requested). Settled shown tooltips and the warm
1214
1212
  // window need no pump: both step on journaled input
1215
1213
  // timestamps.
1216
- if (self.views[index].canvasTooltipIntentArmed()) {
1214
+ const tooltip_intent_armed = self.views[index].canvasTooltipIntentArmed();
1215
+ if (render_animation_active or tooltip_intent_armed) {
1217
1216
  self.invalidateFor(.state, self.views[index].frame);
1217
+ // Invalidation keeps snapshots/diagnostics honest but
1218
+ // does not itself wake an idle retained surface. The
1219
+ // current completion consumed its one-shot request, so
1220
+ // explicitly arm the next one while time-based pixels
1221
+ // still have work. Without this leg animations render
1222
+ // their click endpoints and then park until unrelated
1223
+ // input happens to wake the view.
1224
+ try requestCanvasFrameForView(self, index);
1218
1225
  }
1219
1226
  } else {
1220
1227
  self.views[index].recordCanvasFrame(canvas_frame);
@@ -1380,15 +1387,15 @@ const CanvasPacketPatchStats = struct {
1380
1387
  };
1381
1388
 
1382
1389
  /// Stamp `gpu_input_latency` at the RESPONDING present's completion:
1383
- /// the present call above just returned synchronously, so the wall
1384
- /// clock NOW (the domain every host and automation input timestamp
1385
- /// uses) is the moment the input's pixels reached the swapchain. The
1386
- /// paced completion event that used to stamp this arrives up to a
1387
- /// frame interval later and measured the pacing channel, not the
1388
- /// glass; it remains the fallback for inputs that present nothing.
1390
+ /// the present call above just returned synchronously, so monotonic NOW
1391
+ /// (the domain every host and automation input timestamp uses) is the
1392
+ /// moment the input's pixels reached the swapchain. The paced completion
1393
+ /// event that used to stamp this arrives up to a frame interval later and
1394
+ /// measured the pacing channel, not the glass; it remains the fallback for
1395
+ /// inputs that present nothing.
1389
1396
  fn recordCanvasPresentInputLatency(view: anytype) void {
1390
1397
  if (view.gpu_pending_input_timestamp_ns == 0) return;
1391
- view.recordGpuSurfaceInputLatencyForFrame(runtime_clock.timestampToU64(runtime_clock.nowNanoseconds()));
1398
+ view.recordGpuSurfaceInputLatencyForFrame(runtime_clock.monotonicNanoseconds());
1392
1399
  }
1393
1400
 
1394
1401
  /// Build the frame's CURRENT keyed command list — every supported render
@@ -237,6 +237,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
237
237
 
238
238
  harness.runtime.invalidated = false;
239
239
  harness.runtime.dirty_region_count = 0;
240
+ const frame_requests_before_mid = harness.null_platform.gpu_surface_frame_request_count;
240
241
  const mid_frame = try harness.runtime.nextCanvasFrame(1, "canvas", .{
241
242
  .frame_index = 2,
242
243
  .timestamp_ns = start_ns + 500_000_000,
@@ -249,9 +250,11 @@ test "runtime schedules canvas render animations without display list rebuild" {
249
250
  try std.testing.expectEqualDeep(canvas.Affine.translate(5, 0), mid_frame.render_plan.commands[0].transform);
250
251
  try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), mid_frame.dirty_bounds.?);
251
252
  try std.testing.expect(harness.runtime.invalidated);
253
+ try std.testing.expectEqual(frame_requests_before_mid + 1, harness.null_platform.gpu_surface_frame_request_count);
252
254
 
253
255
  harness.runtime.invalidated = false;
254
256
  harness.runtime.dirty_region_count = 0;
257
+ const frame_requests_before_final = harness.null_platform.gpu_surface_frame_request_count;
255
258
  const final_frame = try harness.runtime.nextCanvasFrame(1, "canvas", .{
256
259
  .frame_index = 3,
257
260
  .timestamp_ns = start_ns + 1_000_000_000,
@@ -261,6 +264,7 @@ test "runtime schedules canvas render animations without display list rebuild" {
261
264
  try std.testing.expectEqualDeep(canvas.Affine.identity(), final_frame.render_plan.commands[0].transform);
262
265
  try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, 16, 11), final_frame.dirty_bounds.?);
263
266
  try std.testing.expect(!harness.runtime.invalidated);
267
+ try std.testing.expectEqual(frame_requests_before_final, harness.null_platform.gpu_surface_frame_request_count);
264
268
  try std.testing.expectEqual(@as(usize, 0), (try harness.runtime.canvasRenderAnimations(1, "canvas")).len);
265
269
  try std.testing.expectEqual(@as(usize, 0), runtimeViewCanvasFrameRenderOverrides(&harness.runtime.views[0]).len);
266
270
 
@@ -187,7 +187,11 @@ pub fn timestampToU64(value: i128) u64 {
187
187
  }
188
188
 
189
189
  pub fn automationInputTimestampNs() u64 {
190
- return timestampToU64(nowNanoseconds());
190
+ // Automation input participates in the same duration math as native
191
+ // host input and presented-frame timestamps. Keep it in the monotonic
192
+ // domain: wall time can jump, and on Windows/Linux the hosts already
193
+ // stamp GPU events from QPC/CLOCK_MONOTONIC.
194
+ return monotonicNanoseconds();
191
195
  }
192
196
 
193
197
  test "the real clocks read plausible, ordered values" {
@@ -205,6 +209,14 @@ test "the real clocks read plausible, ordered values" {
205
209
  try std.testing.expect(second >= first);
206
210
  }
207
211
 
212
+ test "automation input timestamps share the monotonic clock domain" {
213
+ const before = monotonicNanoseconds();
214
+ const timestamp = automationInputTimestampNs();
215
+ const after = monotonicNanoseconds();
216
+ try std.testing.expect(timestamp >= before);
217
+ try std.testing.expect(timestamp <= after);
218
+ }
219
+
208
220
  test "Clock.system reads the real clocks and Clock{} is the same seam" {
209
221
  const clock: Clock = .system;
210
222
  try std.testing.expect(clock.wallMs() > 1_577_836_800_000);
@@ -40,6 +40,8 @@ const extensions = @import("../extensions/root.zig");
40
40
  const app_manifest = @import("app_manifest");
41
41
  const platform = @import("../platform/root.zig");
42
42
  const runtime_effects = @import("effects.zig");
43
+ const runtime_record_store = @import("record_store.zig");
44
+ const runtime_relational_store = @import("relational_store.zig");
43
45
  const security = @import("../security/root.zig");
44
46
 
45
47
  const max_async_bridge_responses = runtime_async_bridge.max_async_bridge_responses;
@@ -674,6 +676,7 @@ pub const Runtime = struct {
674
676
  pub const focusWindow = WindowViewMethods.focusWindow;
675
677
  pub const closeWindow = WindowViewMethods.closeWindow;
676
678
  pub const minimizeWindow = WindowViewMethods.minimizeWindow;
679
+ pub const hideWindow = WindowViewMethods.hideWindow;
677
680
  pub const showWindow = WindowViewMethods.showWindow;
678
681
  pub const quitApp = WindowViewMethods.quitApp;
679
682
  pub const createShellWindow = WindowViewMethods.createShellWindow;
@@ -772,9 +775,11 @@ pub const Runtime = struct {
772
775
  pub const setCredential = SystemServiceMethods.setCredential;
773
776
  pub const getCredential = SystemServiceMethods.getCredential;
774
777
  pub const deleteCredential = SystemServiceMethods.deleteCredential;
778
+ pub const formatLocalTime = SystemServiceMethods.formatLocalTime;
775
779
  pub const createTray = SystemServiceMethods.createTray;
776
780
  pub const updateTrayMenu = SystemServiceMethods.updateTrayMenu;
777
781
  pub const updateTrayTitle = SystemServiceMethods.updateTrayTitle;
782
+ pub const updateTrayPresentation = SystemServiceMethods.updateTrayPresentation;
778
783
  pub const removeTray = SystemServiceMethods.removeTray;
779
784
  const trayCommandNameForItem = SystemServiceMethods.trayCommandNameForItem;
780
785
  const supportsFeatureFromJson = SystemServiceMethods.supportsFeatureFromJson;
@@ -1038,7 +1043,6 @@ pub fn TestHarness() type {
1038
1043
  trace_records: [64]trace.Record = undefined,
1039
1044
  trace_sink: trace.BufferSink = undefined,
1040
1045
  runtime: Runtime = undefined,
1041
-
1042
1046
  /// The harness embeds the multi-megabyte Runtime, so stack
1043
1047
  /// instances overflow test threads; create on the heap.
1044
1048
  pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
@@ -1047,6 +1051,30 @@ pub fn TestHarness() type {
1047
1051
  return self;
1048
1052
  }
1049
1053
 
1054
+ /// Store-capability counterpart of `create`. The SQLite database is
1055
+ /// private to this harness and is automatically bound to every UiApp
1056
+ /// effect channel installed into its runtime.
1057
+ pub fn createWithRecordStore(gpa: std.mem.Allocator, surface: platform.Surface) !*RecordStoreTestHarness() {
1058
+ return RecordStoreTestHarness().create(gpa, surface);
1059
+ }
1060
+
1061
+ /// Relational-capability counterpart of `create`. `native test`
1062
+ /// receives a private in-memory SQLite database and never touches an
1063
+ /// app-data path.
1064
+ pub fn createWithRelationalStore(gpa: std.mem.Allocator, surface: platform.Surface) !*RelationalStoreTestHarness() {
1065
+ return RelationalStoreTestHarness().create(gpa, surface);
1066
+ }
1067
+
1068
+ /// Credential-capability counterpart of `create`. It enables both
1069
+ /// gates against the NullPlatform's process-local byte store, so
1070
+ /// `native test` never opens a real desktop keychain/keyring.
1071
+ pub fn createWithCredentials(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
1072
+ const self = try create(gpa, surface);
1073
+ self.runtime.options.credentials_enabled = true;
1074
+ self.runtime.options.security.permissions = &.{security.permission_credentials};
1075
+ return self;
1076
+ }
1077
+
1050
1078
  pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
1051
1079
  // The harness embeds the runtime's platform: deinit both
1052
1080
  // returns the runtime's heap-owned storage (registered font
@@ -1056,15 +1084,21 @@ pub fn TestHarness() type {
1056
1084
  // tests) can never wake the freed host — the run loop's exit
1057
1085
  // defer for real apps, this line for harness-driven ones.
1058
1086
  self.runtime.deinit();
1087
+ self.null_platform.deinit();
1059
1088
  gpa.destroy(self);
1060
1089
  }
1061
1090
 
1062
1091
  pub fn init(self: *Self, surface: platform.Surface) void {
1092
+ self.initRuntime(surface, null);
1093
+ }
1094
+
1095
+ fn initRuntime(self: *Self, surface: platform.Surface, record_store_binding: ?runtime_effects.RecordStoreBinding) void {
1063
1096
  self.null_platform = platform.NullPlatform.init(surface);
1064
1097
  self.trace_sink = trace.BufferSink.init(&self.trace_records);
1065
1098
  Runtime.initAt(&self.runtime, .{
1066
1099
  .platform = self.null_platform.platform(),
1067
1100
  .trace_sink = self.trace_sink.sink(),
1101
+ .record_store = record_store_binding,
1068
1102
  // On-demand runtime storage (registered font bytes,
1069
1103
  // registered image slot buffers, adopted media-surface
1070
1104
  // texture buffers) routes through
@@ -1095,6 +1129,104 @@ pub fn TestHarness() type {
1095
1129
  };
1096
1130
  }
1097
1131
 
1132
+ /// Capability-opted harness returned by `TestHarness().createWithRecordStore`.
1133
+ /// It is a separate concrete type so ordinary app tests that use
1134
+ /// `TestHarness().create` never analyze or link SQLite merely because Zig's
1135
+ /// test reflection visits the public SDK surface.
1136
+ pub fn RecordStoreTestHarness() type {
1137
+ return struct {
1138
+ const Self = @This();
1139
+
1140
+ null_platform: platform.NullPlatform = platform.NullPlatform.init(.{}),
1141
+ trace_records: [64]trace.Record = undefined,
1142
+ trace_sink: trace.BufferSink = undefined,
1143
+ runtime: Runtime = undefined,
1144
+ record_store: ?runtime_record_store.Store = null,
1145
+
1146
+ pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
1147
+ const self = try gpa.create(Self);
1148
+ errdefer gpa.destroy(self);
1149
+ self.record_store = try runtime_record_store.Store.openMemory(gpa);
1150
+ errdefer if (self.record_store) |*store| store.deinit();
1151
+ self.null_platform = platform.NullPlatform.init(surface);
1152
+ self.trace_sink = trace.BufferSink.init(&self.trace_records);
1153
+ Runtime.initAt(&self.runtime, .{
1154
+ .platform = self.null_platform.platform(),
1155
+ .trace_sink = self.trace_sink.sink(),
1156
+ .record_store = self.record_store.?.binding(),
1157
+ .allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
1158
+ .environ = if (builtin.is_test) std.testing.environ else null,
1159
+ });
1160
+ self.runtime.dispatch_error_policy = .propagate;
1161
+ return self;
1162
+ }
1163
+
1164
+ pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
1165
+ self.runtime.deinit();
1166
+ if (self.record_store) |*store| store.deinit();
1167
+ gpa.destroy(self);
1168
+ }
1169
+
1170
+ pub fn start(self: *Self, app: App) anyerror!void {
1171
+ try self.runtime.dispatchPlatformEvent(app, .app_start);
1172
+ try self.runtime.dispatchPlatformEvent(app, .{ .surface_resized = self.null_platform.surface_value });
1173
+ try self.runtime.dispatchPlatformEvent(app, .frame_requested);
1174
+ }
1175
+
1176
+ pub fn stop(self: *Self, app: App) anyerror!void {
1177
+ try self.runtime.dispatchPlatformEvent(app, .app_shutdown);
1178
+ }
1179
+ };
1180
+ }
1181
+
1182
+ /// Capability-opted harness returned by
1183
+ /// `TestHarness().createWithRelationalStore`.
1184
+ pub fn RelationalStoreTestHarness() type {
1185
+ return struct {
1186
+ const Self = @This();
1187
+
1188
+ null_platform: platform.NullPlatform = platform.NullPlatform.init(.{}),
1189
+ trace_records: [64]trace.Record = undefined,
1190
+ trace_sink: trace.BufferSink = undefined,
1191
+ runtime: Runtime = undefined,
1192
+ relational_store: ?runtime_relational_store.Database = null,
1193
+
1194
+ pub fn create(gpa: std.mem.Allocator, surface: platform.Surface) !*Self {
1195
+ const self = try gpa.create(Self);
1196
+ errdefer gpa.destroy(self);
1197
+ self.relational_store = try runtime_relational_store.Database.openMemory(gpa);
1198
+ errdefer if (self.relational_store) |*database| database.deinit();
1199
+ self.null_platform = platform.NullPlatform.init(surface);
1200
+ self.trace_sink = trace.BufferSink.init(&self.trace_records);
1201
+ Runtime.initAt(&self.runtime, .{
1202
+ .platform = self.null_platform.platform(),
1203
+ .trace_sink = self.trace_sink.sink(),
1204
+ .relational_store = self.relational_store.?.binding(),
1205
+ .allocator = if (builtin.is_test) std.testing.allocator else std.heap.page_allocator,
1206
+ .environ = if (builtin.is_test) std.testing.environ else null,
1207
+ });
1208
+ self.runtime.dispatch_error_policy = .propagate;
1209
+ return self;
1210
+ }
1211
+
1212
+ pub fn destroy(self: *Self, gpa: std.mem.Allocator) void {
1213
+ self.runtime.deinit();
1214
+ if (self.relational_store) |*database| database.deinit();
1215
+ gpa.destroy(self);
1216
+ }
1217
+
1218
+ pub fn start(self: *Self, app: App) anyerror!void {
1219
+ try self.runtime.dispatchPlatformEvent(app, .app_start);
1220
+ try self.runtime.dispatchPlatformEvent(app, .{ .surface_resized = self.null_platform.surface_value });
1221
+ try self.runtime.dispatchPlatformEvent(app, .frame_requested);
1222
+ }
1223
+
1224
+ pub fn stop(self: *Self, app: App) anyerror!void {
1225
+ try self.runtime.dispatchPlatformEvent(app, .app_shutdown);
1226
+ }
1227
+ };
1228
+ }
1229
+
1098
1230
  const testingWriteViewJson = writeViewJson;
1099
1231
  const testingCopyInto = copyInto;
1100
1232
  const testingCanvasWidgetSemanticsById = canvasWidgetSemanticsById;