@native-sdk/cli 0.8.3 → 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 (188) hide show
  1. package/build/app.zig +905 -61
  2. package/build.zig +674 -373
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +6 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +455 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/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 +214 -2
  19. package/packages/core/sdk/core.ts +715 -42
  20. package/packages/core/sdk/events.d.ts +50 -0
  21. package/packages/core/sdk/events.ts +75 -0
  22. package/packages/core/src/checker.ts +528 -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 +1849 -18
  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 +84 -18
  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/SKILL.md +4 -2
  38. package/skill-data/core/references/project-anatomy.md +3 -2
  39. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  40. package/skill-data/native-ui/SKILL.md +55 -8
  41. package/skill-data/ts-core/SKILL.md +92 -40
  42. package/skill-data/ts-services/SKILL.md +126 -0
  43. package/skill-data/ts-services/references/service-surface.md +603 -0
  44. package/skill-data/zig/SKILL.md +1 -1
  45. package/skills/native-sdk/SKILL.md +1 -1
  46. package/src/app_runner/no_migrations.zig +3 -0
  47. package/src/app_runner/no_services.zig +20 -0
  48. package/src/app_runner/root.zig +104 -4
  49. package/src/app_runner/ts_core_main.zig +268 -4
  50. package/src/automation/snapshot.zig +23 -5
  51. package/src/embed/app_exports.zig +11 -1
  52. package/src/embed/c_api.zig +48 -2
  53. package/src/embed/conversions.zig +4 -5
  54. package/src/embed/host.zig +115 -1
  55. package/src/embed/root.zig +7 -0
  56. package/src/embed/tests.zig +213 -0
  57. package/src/embed/types.zig +51 -0
  58. package/src/embed/ui_host.zig +121 -5
  59. package/src/platform/android/NativeSdkActivity.java +131 -0
  60. package/src/platform/android/android_host.c +182 -1
  61. package/src/platform/android/native_sdk_app.h +17 -0
  62. package/src/platform/ios/native_sdk_app.h +17 -0
  63. package/src/platform/ios/uikit_host.m +115 -0
  64. package/src/platform/linux/cef_host.cpp +1 -1
  65. package/src/platform/linux/gtk_host.c +89 -17
  66. package/src/platform/linux/gtk_host.h +3 -0
  67. package/src/platform/linux/root.zig +41 -18
  68. package/src/platform/macos/appkit_host.h +26 -3
  69. package/src/platform/macos/appkit_host.m +1051 -129
  70. package/src/platform/macos/capture_info_plist.c +25 -0
  71. package/src/platform/macos/cef_host.mm +270 -36
  72. package/src/platform/macos/root.zig +312 -34
  73. package/src/platform/null_platform.zig +281 -19
  74. package/src/platform/null_platform_tests.zig +74 -0
  75. package/src/platform/root.zig +16 -0
  76. package/src/platform/types.zig +279 -15
  77. package/src/platform/windows/root.zig +243 -21
  78. package/src/platform/windows/webview2_host.cpp +464 -46
  79. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  80. package/src/primitives/app_manifest/root.zig +4 -0
  81. package/src/primitives/app_manifest/tests.zig +3 -0
  82. package/src/primitives/app_manifest/types.zig +34 -0
  83. package/src/primitives/app_manifest/validation.zig +19 -1
  84. package/src/primitives/canvas/code_tests.zig +9 -9
  85. package/src/primitives/canvas/events.zig +12 -11
  86. package/src/primitives/canvas/frame.zig +44 -9
  87. package/src/primitives/canvas/icons/mic.svg +1 -0
  88. package/src/primitives/canvas/icons.zig +2 -0
  89. package/src/primitives/canvas/root.zig +8 -0
  90. package/src/primitives/canvas/text_span_tests.zig +39 -0
  91. package/src/primitives/canvas/ui.zig +23 -4
  92. package/src/primitives/canvas/ui_markup.zig +15 -0
  93. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  94. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  95. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  96. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  97. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  98. package/src/primitives/canvas/ui_schema.zig +19 -10
  99. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  100. package/src/primitives/canvas/ui_tests.zig +18 -4
  101. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  102. package/src/primitives/canvas/widget_render.zig +296 -114
  103. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  104. package/src/primitives/canvas/widget_text_input.zig +10 -10
  105. package/src/primitives/canvas/widget_tree.zig +1 -1
  106. package/src/primitives/canvas/widgets.zig +29 -5
  107. package/src/root.zig +56 -0
  108. package/src/runtime/api.zig +11 -0
  109. package/src/runtime/automation_snapshot.zig +4 -0
  110. package/src/runtime/automation_widget_dispatch.zig +1 -0
  111. package/src/runtime/bridge_payload.zig +2 -0
  112. package/src/runtime/bridge_permission_tests.zig +23 -2
  113. package/src/runtime/bridge_responses.zig +3 -1
  114. package/src/runtime/canvas_frame.zig +31 -13
  115. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  116. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  117. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  118. package/src/runtime/canvas_widget_events.zig +69 -24
  119. package/src/runtime/canvas_widget_runtime.zig +101 -6
  120. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  121. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  122. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  123. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  124. package/src/runtime/canvas_widget_state.zig +6 -1
  125. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  126. package/src/runtime/clock.zig +13 -1
  127. package/src/runtime/core.zig +133 -1
  128. package/src/runtime/credentials_store.zig +115 -0
  129. package/src/runtime/effects.zig +2568 -75
  130. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  131. package/src/runtime/effects_credentials_tests.zig +332 -0
  132. package/src/runtime/effects_host_tests.zig +208 -1
  133. package/src/runtime/effects_relational_tests.zig +314 -0
  134. package/src/runtime/effects_store_tests.zig +211 -0
  135. package/src/runtime/flow.zig +14 -1
  136. package/src/runtime/gpu_surface_events.zig +6 -1
  137. package/src/runtime/native_command_event_tests.zig +42 -0
  138. package/src/runtime/persist_store.zig +666 -0
  139. package/src/runtime/record_store.zig +788 -0
  140. package/src/runtime/relational_store.zig +854 -0
  141. package/src/runtime/root.zig +52 -0
  142. package/src/runtime/runtime_event_tests.zig +70 -0
  143. package/src/runtime/service_host.zig +711 -0
  144. package/src/runtime/service_pool.zig +1314 -0
  145. package/src/runtime/session_blobs.zig +1 -1
  146. package/src/runtime/session_journal.zig +102 -0
  147. package/src/runtime/session_record.zig +177 -0
  148. package/src/runtime/session_replay.zig +109 -4
  149. package/src/runtime/shell_layout.zig +1 -0
  150. package/src/runtime/shell_layout_tests.zig +120 -0
  151. package/src/runtime/sqlite_engine.zig +474 -0
  152. package/src/runtime/state.zig +6 -0
  153. package/src/runtime/system_services.zig +49 -10
  154. package/src/runtime/tests.zig +5 -0
  155. package/src/runtime/ts_core_host.zig +1189 -118
  156. package/src/runtime/ts_core_host_tests.zig +638 -11
  157. package/src/runtime/ts_ui_app.zig +537 -1
  158. package/src/runtime/ui_app.zig +160 -19
  159. package/src/runtime/ui_app_tests.zig +203 -5
  160. package/src/runtime/validation.zig +22 -0
  161. package/src/runtime/view.zig +11 -0
  162. package/src/runtime/view_widget_scroll.zig +56 -5
  163. package/src/runtime/view_widget_text.zig +24 -5
  164. package/src/runtime/view_widget_tree.zig +1 -1
  165. package/src/runtime/window_storage.zig +1 -0
  166. package/src/runtime/window_view_runtime.zig +2 -3
  167. package/src/runtime/window_views.zig +19 -0
  168. package/src/tooling/android.zig +21 -16
  169. package/src/tooling/db.zig +160 -0
  170. package/src/tooling/ios.zig +7 -1
  171. package/src/tooling/manifest.zig +1248 -2
  172. package/src/tooling/package.zig +953 -6
  173. package/src/tooling/raw_manifest.zig +65 -0
  174. package/src/tooling/root.zig +1 -0
  175. package/src/tooling/templates.zig +216 -4
  176. package/src/tooling/ts_core.zig +283 -17
  177. package/src/tooling/verbs.zig +7 -0
  178. package/third_party/sqlite/README.md +13 -0
  179. package/third_party/sqlite/sqlite3.c +269649 -0
  180. package/third_party/sqlite/sqlite3.h +14349 -0
  181. package/tools/corewire/core_abi.zig +14 -2
  182. package/tools/corewire/emit.zig +98 -29
  183. package/tools/corewire/emit_facade.zig +414 -23
  184. package/tools/corewire/emit_profile.zig +6 -2
  185. package/tools/corewire/emit_service.zig +924 -0
  186. package/tools/corewire/main.zig +122 -0
  187. package/tools/corewire/service_contract.zig +250 -0
  188. package/tools/corewire/sidecar.zig +26 -15
@@ -223,6 +223,10 @@ pub const TrayItem = struct {
223
223
  command: []const u8 = "",
224
224
  separator: bool = false,
225
225
  enabled: bool = true,
226
+ detail: []const u8 = "",
227
+ role: platform.TrayItemRole = .command,
228
+ key: []const u8 = "",
229
+ modifiers: platform.ShortcutModifiers = .{},
226
230
  };
227
231
 
228
232
  /// The live status item (tray): current button title + dropdown items.
@@ -382,7 +386,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
382
386
  },
383
387
  );
384
388
  if (view.kind == .gpu_surface) {
385
- try writer.print(" gpu_size={d}x{d} gpu_scale={d} gpu_backend={s} gpu_pixel_format={s} gpu_present_mode={s} gpu_alpha_mode={s} gpu_color_space={s} gpu_vsync={any} gpu_status={s} gpu_present_path={s} gpu_frame={d} gpu_timestamp_ns={d} gpu_frame_interval_ns={d} gpu_input_timestamp_ns={d} gpu_input_latency_ns={d} gpu_input_latency_budget_ns={d} gpu_input_latency_budget_exceeded={d} gpu_input_latency_budget_ok={any} gpu_first_frame_latency_ns={d} gpu_first_frame_latency_budget_ns={d} gpu_first_frame_latency_budget_exceeded={d} gpu_first_frame_latency_budget_ok={any} gpu_nonblank={any} gpu_sample=0x{x:0>8}", .{
389
+ try writer.print(" gpu_size={d}x{d} gpu_scale={d} gpu_backend={s} gpu_pixel_format={s} gpu_present_mode={s} gpu_alpha_mode={s} gpu_color_space={s} gpu_vsync={any} gpu_status={s} gpu_present_path={s} gpu_frame={d} gpu_timestamp_ns={d} gpu_frame_interval_ns={d} gpu_input_count={d} gpu_input_timestamp_ns={d} gpu_input_latency_ns={d} gpu_input_latency_budget_ns={d} gpu_input_latency_budget_exceeded={d} gpu_input_latency_budget_ok={any} gpu_first_frame_latency_ns={d} gpu_first_frame_latency_budget_ns={d} gpu_first_frame_latency_budget_exceeded={d} gpu_first_frame_latency_budget_ok={any} gpu_nonblank={any} gpu_occluded={any} gpu_sample=0x{x:0>8}", .{
386
390
  view.gpu_size.width,
387
391
  view.gpu_size.height,
388
392
  view.gpu_scale_factor,
@@ -397,6 +401,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
397
401
  view.gpu_frame_index,
398
402
  view.gpu_timestamp_ns,
399
403
  view.gpu_frame_interval_ns,
404
+ view.gpu_input_event_count,
400
405
  view.gpu_input_timestamp_ns,
401
406
  view.gpu_input_latency_ns,
402
407
  view.gpu_input_latency_budget_ns,
@@ -407,6 +412,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
407
412
  view.gpu_first_frame_latency_budget_exceeded_count,
408
413
  view.gpu_first_frame_latency_budget_ok,
409
414
  view.gpu_frame_nonblank,
415
+ view.gpu_occluded,
410
416
  view.gpu_sample_color,
411
417
  });
412
418
  // Packet-fallback telemetry: WHY the last packet attempt
@@ -594,11 +600,19 @@ pub fn writeText(input: Input, writer: anytype) !void {
594
600
  try writer.writeAll(" tray-item separator\n");
595
601
  continue;
596
602
  }
597
- try writer.print(" tray-item #{d} label=\"{s}\" command=\"{s}\" enabled={any}\n", .{
603
+ try writer.print(" tray-item #{d} label=\"{s}\" command=\"{s}\" enabled={any} detail=\"{s}\" role={s} key=\"{s}\" modifiers=(primary={any},command={any},control={any},option={any},shift={any})\n", .{
598
604
  item.id,
599
605
  item.label,
600
606
  item.command,
601
607
  item.enabled,
608
+ item.detail,
609
+ @tagName(item.role),
610
+ item.key,
611
+ item.modifiers.primary,
612
+ item.modifiers.command,
613
+ item.modifiers.control,
614
+ item.modifiers.option,
615
+ item.modifiers.shift,
602
616
  });
603
617
  }
604
618
  }
@@ -907,7 +921,7 @@ test "snapshot emits tray title and dropdown items" {
907
921
  const items = [_]TrayItem{
908
922
  .{ .id = 1, .label = "Refresh", .command = "app.refresh" },
909
923
  .{ .separator = true },
910
- .{ .id = 10, .label = "Fix crash on resize", .command = "issue.select.0", .enabled = false },
924
+ .{ .id = 10, .label = "Fix crash on resize", .command = "issue.select.0", .enabled = false, .detail = "warning ⚠", .role = .agent, .key = "q", .modifiers = .{ .command = true } },
911
925
  };
912
926
  try writeText(.{
913
927
  .windows = &windows,
@@ -915,9 +929,9 @@ test "snapshot emits tray title and dropdown items" {
915
929
  }, &writer);
916
930
  const text = writer.buffered();
917
931
  try std.testing.expect(std.mem.indexOf(u8, text, "\ntray title=\"ZN 3\" items=3\n") != null);
918
- try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true\n") != null);
932
+ 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);
919
933
  try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
920
- 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);
934
+ try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false detail=\"warning ⚠\" role=agent key=\"q\" modifiers=(primary=false,command=true,control=false,option=false,shift=false)\n") != null);
921
935
 
922
936
  // No tray -> no tray lines.
923
937
  var empty_buffer: [512]u8 = undefined;
@@ -981,6 +995,7 @@ test "snapshot emits GPU surface frame proof" {
981
995
  .gpu_frame_index = 4,
982
996
  .gpu_timestamp_ns = 99,
983
997
  .gpu_frame_interval_ns = 8,
998
+ .gpu_input_event_count = 7,
984
999
  .gpu_input_timestamp_ns = 80,
985
1000
  .gpu_input_latency_ns = 19,
986
1001
  .gpu_input_latency_budget_ns = 16,
@@ -991,6 +1006,7 @@ test "snapshot emits GPU surface frame proof" {
991
1006
  .gpu_first_frame_latency_budget_exceeded_count = 0,
992
1007
  .gpu_first_frame_latency_budget_ok = true,
993
1008
  .gpu_frame_nonblank = true,
1009
+ .gpu_occluded = true,
994
1010
  .gpu_sample_color = 0xff336699,
995
1011
  .canvas_revision = 2,
996
1012
  .canvas_command_count = 5,
@@ -1088,6 +1104,7 @@ test "snapshot emits GPU surface frame proof" {
1088
1104
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_frame=4") != null);
1089
1105
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_timestamp_ns=99") != null);
1090
1106
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_frame_interval_ns=8") != null);
1107
+ try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_count=7") != null);
1091
1108
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_timestamp_ns=80") != null);
1092
1109
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_latency_ns=19") != null);
1093
1110
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_latency_budget_ns=16") != null);
@@ -1098,6 +1115,7 @@ test "snapshot emits GPU surface frame proof" {
1098
1115
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_first_frame_latency_budget_exceeded=0") != null);
1099
1116
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_first_frame_latency_budget_ok=true") != null);
1100
1117
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_nonblank=true") != null);
1118
+ try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_occluded=true") != null);
1101
1119
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_sample=0xff336699") != null);
1102
1120
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "canvas_revision=2") != null);
1103
1121
  try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "canvas_commands=5") != null);
@@ -5,7 +5,17 @@
5
5
  //! (window 1, label "mobile-surface").
6
6
 
7
7
  const native_sdk = @import("native_sdk");
8
+ const mobile_build_options = @import("mobile_build_options");
9
+ const relational_migrations = @import("relational_migrations");
8
10
 
9
11
  comptime {
10
- native_sdk.embed.exportMobileCApi(native_sdk.embed.UiAppHost(@import("app")));
12
+ native_sdk.embed.exportMobileCApi(native_sdk.embed.UiAppHostWithStorageAndCredentials(
13
+ @import("app"),
14
+ mobile_build_options.store_capability,
15
+ mobile_build_options.relational_capability,
16
+ &relational_migrations.migrations,
17
+ mobile_build_options.credentials_capability,
18
+ mobile_build_options.credentials_permission,
19
+ mobile_build_options.credentials_service,
20
+ ));
11
21
  }
@@ -4,7 +4,8 @@
4
4
  //! for a host type: the fixed WebView shell (`MobileHostApp`, this module's
5
5
  //! re-exported default) or a user-app canvas host
6
6
  //! (`ui_host.UiAppHost(AppDef)` in libs built via `addMobileLib`). A host
7
- //! must expose `create`/`destroy`/`start`/`frame`, an `embedded`
7
+ //! must expose `create`/`destroy`/`start`/`frame` (`destroy` reports whether
8
+ //! callback context must survive), an `embedded`
8
9
  //! `EmbeddedApp`, and the error/command/asset bookkeeping fields both
9
10
  //! hosts share. `exportMobileCApi(Host)` exports every function under its
10
11
  //! canonical symbol name for a static library root.
@@ -57,7 +58,16 @@ pub fn MobileCApi(comptime Host: type) type {
57
58
 
58
59
  pub fn native_sdk_app_destroy(app: ?*anyopaque) callconv(.c) void {
59
60
  const self = hostApp(Host, app) orelse return;
60
- self.destroy();
61
+ _ = self.destroy();
62
+ }
63
+
64
+ /// Destroy the app and report whether teardown had to preserve the
65
+ /// host because a detached platform callback may still be running.
66
+ /// A mobile shim that owns the callback context must preserve that
67
+ /// context too when this returns 1.
68
+ pub fn native_sdk_app_destroy_with_status(app: ?*anyopaque) callconv(.c) c_int {
69
+ const self = hostApp(Host, app) orelse return 0;
70
+ return if (self.destroy()) 1 else 0;
61
71
  }
62
72
 
63
73
  pub fn native_sdk_app_start(app: ?*anyopaque) callconv(.c) void {
@@ -195,6 +205,20 @@ pub fn MobileCApi(comptime Host: type) type {
195
205
  return 1;
196
206
  }
197
207
 
208
+ /// Register or clear the mobile host's OS-backed credential store.
209
+ /// This supplies platform backing only; app.zon capability and
210
+ /// permission gates are still enforced by the runtime.
211
+ pub fn native_sdk_app_set_credential_service(app: ?*anyopaque, service: ?*const types.MobileCredentialService, context: ?*anyopaque) callconv(.c) c_int {
212
+ const self = hostApp(Host, app) orelse return 0;
213
+ const table: types.MobileCredentialService = if (service) |value| value.* else .{};
214
+ host.setCredentialService(self, table, context) catch |err| {
215
+ recordError(self, err);
216
+ return 0;
217
+ };
218
+ self.last_error = null;
219
+ return 1;
220
+ }
221
+
198
222
  /// One report from the shim's audio player (kind ordinals: 0
199
223
  /// loaded, 1 position, 2 completed, 3 failed), dispatched into the
200
224
  /// embedded runtime exactly like a desktop platform's `.audio`
@@ -242,6 +266,25 @@ pub fn MobileCApi(comptime Host: type) type {
242
266
  return 1;
243
267
  }
244
268
 
269
+ /// Supply the OS-owned app-data directory before start. Hosts call
270
+ /// this for every app; non-store host types accept it as a no-op so
271
+ /// the mobile ABI does not vary with capability shedding.
272
+ pub fn native_sdk_app_set_data_root(app: ?*anyopaque, path: ?[*]const u8, len: usize) callconv(.c) c_int {
273
+ const self = hostApp(Host, app) orelse return 0;
274
+ const dir = inputSlice(path, len) catch |err| {
275
+ recordError(self, err);
276
+ return 0;
277
+ };
278
+ if (comptime @hasDecl(Host, "setDataRoot")) {
279
+ self.setDataRoot(dir) catch |err| {
280
+ recordError(self, err);
281
+ return 0;
282
+ };
283
+ }
284
+ self.last_error = null;
285
+ return 1;
286
+ }
287
+
245
288
  pub fn native_sdk_app_touch(app: ?*anyopaque, id: u64, phase: c_int, x: f32, y: f32, pressure: f32) callconv(.c) void {
246
289
  const self = hostApp(Host, app) orelse return;
247
290
  self.embedded.touch(id, phase, x, y, pressure) catch |err| {
@@ -748,6 +791,7 @@ const FixedShellApi = MobileCApi(MobileHostApp);
748
791
 
749
792
  pub const native_sdk_app_create = FixedShellApi.native_sdk_app_create;
750
793
  pub const native_sdk_app_destroy = FixedShellApi.native_sdk_app_destroy;
794
+ pub const native_sdk_app_destroy_with_status = FixedShellApi.native_sdk_app_destroy_with_status;
751
795
  pub const native_sdk_app_start = FixedShellApi.native_sdk_app_start;
752
796
  pub const native_sdk_app_activate = FixedShellApi.native_sdk_app_activate;
753
797
  pub const native_sdk_app_deactivate = FixedShellApi.native_sdk_app_deactivate;
@@ -759,9 +803,11 @@ pub const native_sdk_app_gpu_frame_state = FixedShellApi.native_sdk_app_gpu_fram
759
803
  pub const native_sdk_app_text_input_state = FixedShellApi.native_sdk_app_text_input_state;
760
804
  pub const native_sdk_app_set_text_measure = FixedShellApi.native_sdk_app_set_text_measure;
761
805
  pub const native_sdk_app_set_audio_service = FixedShellApi.native_sdk_app_set_audio_service;
806
+ pub const native_sdk_app_set_credential_service = FixedShellApi.native_sdk_app_set_credential_service;
762
807
  pub const native_sdk_app_audio_event = FixedShellApi.native_sdk_app_audio_event;
763
808
  pub const native_sdk_app_set_image_service = FixedShellApi.native_sdk_app_set_image_service;
764
809
  pub const native_sdk_app_set_automation_dir = FixedShellApi.native_sdk_app_set_automation_dir;
810
+ pub const native_sdk_app_set_data_root = FixedShellApi.native_sdk_app_set_data_root;
765
811
  pub const native_sdk_app_touch = FixedShellApi.native_sdk_app_touch;
766
812
  pub const native_sdk_app_scroll = FixedShellApi.native_sdk_app_scroll;
767
813
  pub const native_sdk_app_key = FixedShellApi.native_sdk_app_key;
@@ -350,10 +350,9 @@ pub fn mobileTextRangeEnd(range: ?canvas.TextRange) isize {
350
350
  const value = range orelse return -1;
351
351
  return mobileOptionalIndex(value.end);
352
352
  }
353
- /// Wall-clock nanoseconds for embed input timestamps, through the
354
- /// runtime clock seam (which covers Windows via the NT precise system
355
- /// time and degrades to 0 only on targets without a readable clock).
353
+ /// Monotonic nanoseconds for embed input and frame timestamps. These values
354
+ /// participate in GPU latency and frame-interval subtraction, so they must
355
+ /// share the duration clock used by desktop hosts and runtime presentation.
356
356
  pub fn nowNanoseconds() u64 {
357
- const ns = runtime.nowNanoseconds();
358
- return if (ns > 0) @intCast(ns) else 0;
357
+ return runtime.monotonicNanoseconds();
359
358
  }
@@ -163,6 +163,102 @@ pub fn setAudioService(self: anytype, service: types.MobileAudioService, context
163
163
  services.audio_set_volume_fn = if (playback) Bridge.audioSetVolume else null;
164
164
  self.null_platform.audio_playback = playback;
165
165
  self.null_platform.audio_streaming = streaming;
166
+ // The embed ABI has no capture producer callbacks yet; never inherit
167
+ // the null platform's deterministic capture fake as host capability.
168
+ self.null_platform.microphone_capture = false;
169
+ self.null_platform.system_audio_capture = false;
170
+ }
171
+
172
+ /// Host-owned callback table for the mobile OS credential store.
173
+ pub const MobileCredentials = struct {
174
+ service: types.MobileCredentialService = .{},
175
+ context: ?*anyopaque = null,
176
+ };
177
+
178
+ fn MobileCredentialBridge(comptime Host: type) type {
179
+ return struct {
180
+ fn hostFromContext(context: ?*anyopaque) *Host {
181
+ const null_platform: *platform.NullPlatform = @ptrCast(@alignCast(context.?));
182
+ return @alignCast(@fieldParentPtr("null_platform", null_platform));
183
+ }
184
+
185
+ fn setCredential(context: ?*anyopaque, credential: platform.Credential) anyerror!void {
186
+ const store = &hostFromContext(context).credentials;
187
+ const set_fn = store.service.set orelse return error.UnsupportedService;
188
+ return switch (set_fn(
189
+ store.context,
190
+ credential.service.ptr,
191
+ credential.service.len,
192
+ credential.account.ptr,
193
+ credential.account.len,
194
+ credential.secret.ptr,
195
+ credential.secret.len,
196
+ )) {
197
+ 1 => {},
198
+ -2 => error.CredentialStoreLocked,
199
+ -3 => error.AccessDenied,
200
+ else => error.CredentialStoreFailed,
201
+ };
202
+ }
203
+
204
+ fn getCredential(context: ?*anyopaque, key: platform.CredentialKey, output: []u8) anyerror![]const u8 {
205
+ const store = &hostFromContext(context).credentials;
206
+ const get_fn = store.service.get orelse return error.UnsupportedService;
207
+ const result = get_fn(
208
+ store.context,
209
+ key.service.ptr,
210
+ key.service.len,
211
+ key.account.ptr,
212
+ key.account.len,
213
+ output.ptr,
214
+ output.len,
215
+ );
216
+ return switch (result) {
217
+ -1 => error.CredentialNotFound,
218
+ -2 => error.CredentialStoreLocked,
219
+ -3 => error.AccessDenied,
220
+ -4 => error.NoSpaceLeft,
221
+ else => if (result < 0 or result > output.len)
222
+ error.CredentialStoreFailed
223
+ else
224
+ output[0..@intCast(result)],
225
+ };
226
+ }
227
+
228
+ fn deleteCredential(context: ?*anyopaque, key: platform.CredentialKey) anyerror!void {
229
+ const store = &hostFromContext(context).credentials;
230
+ const delete_fn = store.service.delete orelse return error.UnsupportedService;
231
+ return switch (delete_fn(
232
+ store.context,
233
+ key.service.ptr,
234
+ key.service.len,
235
+ key.account.ptr,
236
+ key.account.len,
237
+ )) {
238
+ 1 => {},
239
+ 0 => error.CredentialNotFound,
240
+ -2 => error.CredentialStoreLocked,
241
+ -3 => error.AccessDenied,
242
+ else => error.CredentialStoreFailed,
243
+ };
244
+ }
245
+ };
246
+ }
247
+
248
+ /// Install or clear the mobile OS credential service. Partial tables are
249
+ /// refused so a successful set can never be paired with an unavailable get
250
+ /// or delete. Registration only supplies the backing; the manifest
251
+ /// capability and permission remain independent runtime gates.
252
+ pub fn setCredentialService(self: anytype, service: types.MobileCredentialService, context: ?*anyopaque) anyerror!void {
253
+ const Host = std.meta.Child(@TypeOf(self));
254
+ const Bridge = MobileCredentialBridge(Host);
255
+ const complete = service.complete();
256
+ if (!complete and !service.empty()) return error.InvalidCommand;
257
+ self.credentials = .{ .service = service, .context = if (complete) context else null };
258
+ const services = &self.embedded.runtime.options.platform.services;
259
+ services.set_credential_fn = if (complete) Bridge.setCredential else null;
260
+ services.get_credential_fn = if (complete) Bridge.getCredential else null;
261
+ services.delete_credential_fn = if (complete) Bridge.deleteCredential else null;
166
262
  }
167
263
 
168
264
  /// Host-owned storage for the shim's registered image-decode service
@@ -692,6 +788,7 @@ pub const MobileHostApp = struct {
692
788
  automation_io: ?*std.Io.Threaded = null,
693
789
  text_measure: MobileTextMeasure = .{},
694
790
  audio: MobileAudio = .{},
791
+ credentials: MobileCredentials = .{},
695
792
  // Image decode stays declined until the shim registers a real codec
696
793
  // (`native_sdk_app_set_image_service`): the null platform's strict
697
794
  // test decoder is opt-in (`image_decode`, default off), so with no
@@ -725,6 +822,8 @@ pub const MobileHostApp = struct {
725
822
  // below so the runtime's service table starts without audio.
726
823
  self.null_platform.audio_playback = false;
727
824
  self.null_platform.audio_streaming = false;
825
+ self.null_platform.microphone_capture = false;
826
+ self.null_platform.system_audio_capture = false;
728
827
  // Video is declined the same way: no mobile shim registers a
729
828
  // decoder yet, and the null platform's fake player belongs to
730
829
  // hermetic tests — a load that "succeeds" but never decodes
@@ -765,6 +864,7 @@ pub const MobileHostApp = struct {
765
864
  self.automation_io = null;
766
865
  self.text_measure = .{};
767
866
  self.audio = .{};
867
+ self.credentials = .{};
768
868
  self.image = .{};
769
869
  self.form_factor = .unknown;
770
870
  self.chrome_tabs_projected = false;
@@ -777,10 +877,18 @@ pub const MobileHostApp = struct {
777
877
  .source_fn = mobileSource,
778
878
  .event_fn = handleEvent,
779
879
  }, self.null_platform.platform());
880
+ // A real mobile host must register Keychain/Keystore backing before
881
+ // start. Do not expose the NullPlatform's hermetic test map to an
882
+ // installed app while that registration is absent.
883
+ try setCredentialService(self, .{}, null);
780
884
  return self;
781
885
  }
782
886
 
783
- pub fn destroy(self: *MobileHostApp) void {
887
+ /// Returns true when teardown deliberately preserves the host because an
888
+ /// abandoned platform callback may still enter it. Mobile shims that own
889
+ /// callback context use the companion C ABI result to preserve that
890
+ /// context under the same condition.
891
+ pub fn destroy(self: *MobileHostApp) bool {
784
892
  disableAutomation(self);
785
893
  // One lifecycle owner: the embedded app's own deinit returns
786
894
  // the runtime's heap-owned storage (registered canvas font
@@ -789,7 +897,13 @@ pub const MobileHostApp = struct {
789
897
  // embedding app keeps past destroy can never wake the freed
790
898
  // host storage (the embedded null platform included).
791
899
  self.embedded.deinit();
900
+ // Effects reports any detached platform call through the null
901
+ // platform's abandon latch. Such a call still resolves this wrapper
902
+ // from the services context, so preserve the complete host block just
903
+ // as desktop platform destroy paths preserve theirs.
904
+ if (self.null_platform.channel_wake_abandoned.load(.seq_cst)) return true;
792
905
  std.heap.page_allocator.destroy(self);
906
+ return false;
793
907
  }
794
908
 
795
909
  pub fn start(self: *MobileHostApp) anyerror!void {
@@ -18,6 +18,7 @@ pub const MobileGpuFrameState = types.MobileGpuFrameState;
18
18
  pub const MobileCanvasPixels = types.MobileCanvasPixels;
19
19
  pub const MobileCanvasPixelsDamage = types.MobileCanvasPixelsDamage;
20
20
  pub const MobileAudioService = types.MobileAudioService;
21
+ pub const MobileCredentialService = types.MobileCredentialService;
21
22
  pub const MobileImageService = types.MobileImageService;
22
23
  pub const MobileChromeItem = chrome.MobileChromeItem;
23
24
  pub const renderChromeIconPixels = chrome.renderIconPixels;
@@ -26,12 +27,16 @@ pub const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
26
27
  pub const EmbeddedApp = host.EmbeddedApp;
27
28
  pub const MobileHostApp = host.MobileHostApp;
28
29
  pub const UiAppHost = ui_host.UiAppHost;
30
+ pub const UiAppHostWithRecordStore = ui_host.UiAppHostWithRecordStore;
31
+ pub const UiAppHostWithStorage = ui_host.UiAppHostWithStorage;
32
+ pub const UiAppHostWithStorageAndCredentials = ui_host.UiAppHostWithStorageAndCredentials;
29
33
  pub const mobile_shell_scene = ui_host.mobile_shell_scene;
30
34
  pub const MobileCApi = c_api.MobileCApi;
31
35
  pub const exportMobileCApi = c_api.exportMobileCApi;
32
36
 
33
37
  pub const native_sdk_app_create = c_api.native_sdk_app_create;
34
38
  pub const native_sdk_app_destroy = c_api.native_sdk_app_destroy;
39
+ pub const native_sdk_app_destroy_with_status = c_api.native_sdk_app_destroy_with_status;
35
40
  pub const native_sdk_app_start = c_api.native_sdk_app_start;
36
41
  pub const native_sdk_app_activate = c_api.native_sdk_app_activate;
37
42
  pub const native_sdk_app_deactivate = c_api.native_sdk_app_deactivate;
@@ -42,9 +47,11 @@ pub const native_sdk_app_viewport_state = c_api.native_sdk_app_viewport_state;
42
47
  pub const native_sdk_app_gpu_frame_state = c_api.native_sdk_app_gpu_frame_state;
43
48
  pub const native_sdk_app_text_input_state = c_api.native_sdk_app_text_input_state;
44
49
  pub const native_sdk_app_set_audio_service = c_api.native_sdk_app_set_audio_service;
50
+ pub const native_sdk_app_set_credential_service = c_api.native_sdk_app_set_credential_service;
45
51
  pub const native_sdk_app_audio_event = c_api.native_sdk_app_audio_event;
46
52
  pub const native_sdk_app_set_image_service = c_api.native_sdk_app_set_image_service;
47
53
  pub const native_sdk_app_set_automation_dir = c_api.native_sdk_app_set_automation_dir;
54
+ pub const native_sdk_app_set_data_root = c_api.native_sdk_app_set_data_root;
48
55
  pub const native_sdk_app_touch = c_api.native_sdk_app_touch;
49
56
  pub const native_sdk_app_scroll = c_api.native_sdk_app_scroll;
50
57
  pub const native_sdk_app_key = c_api.native_sdk_app_key;