@native-sdk/cli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/build/app.zig +331 -24
  2. package/build.zig +179 -11
  3. package/native-sdk.d.ts +8 -0
  4. package/package.json +10 -10
  5. package/packages/core/compile-surface/core.ts +70 -1
  6. package/packages/core/package-lock.json +11 -11
  7. package/packages/core/package.json +2 -2
  8. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  9. package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
  10. package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
  11. package/packages/core/scripts/stage_external_services.mjs +1 -1
  12. package/packages/core/sdk/core.d.ts +75 -0
  13. package/packages/core/sdk/core.ts +167 -12
  14. package/packages/core/sdk/events.d.ts +53 -0
  15. package/packages/core/sdk/events.ts +78 -7
  16. package/packages/core/src/checker.ts +470 -2
  17. package/packages/core/src/cli.ts +13 -0
  18. package/packages/core/src/contract.ts +3 -1
  19. package/packages/core/src/devhost.ts +30 -1
  20. package/packages/core/src/devhost_journal.mjs +10 -8
  21. package/packages/core/src/diagnostics.ts +99 -8
  22. package/packages/core/src/frontend.ts +6 -0
  23. package/packages/core/src/infer.ts +24 -0
  24. package/skill-data/automation/SKILL.md +1 -1
  25. package/skill-data/native-ui/SKILL.md +11 -5
  26. package/skill-data/ts-core/SKILL.md +53 -20
  27. package/skill-data/ts-services/SKILL.md +4 -4
  28. package/skill-data/ts-services/references/service-surface.md +2 -1
  29. package/skill-data/zig/SKILL.md +1 -1
  30. package/src/app_runner/root.zig +29 -0
  31. package/src/app_runner/ts_core_main.zig +5 -0
  32. package/src/app_runner/ts_core_mobile.zig +241 -0
  33. package/src/automation/protocol.zig +5 -1
  34. package/src/automation/snapshot.zig +8 -6
  35. package/src/embed/app_exports.zig +1 -0
  36. package/src/embed/root.zig +1 -0
  37. package/src/embed/tests.zig +28 -0
  38. package/src/embed/ui_host.zig +68 -2
  39. package/src/platform/linux/cef_host.cpp +7 -1
  40. package/src/platform/linux/gtk_host.c +200 -5
  41. package/src/platform/linux/gtk_host.h +2 -1
  42. package/src/platform/linux/root.zig +69 -4
  43. package/src/platform/macos/appkit_host.h +11 -7
  44. package/src/platform/macos/appkit_host.m +210 -88
  45. package/src/platform/macos/cef_host.mm +210 -88
  46. package/src/platform/macos/root.zig +77 -30
  47. package/src/platform/null_platform.zig +234 -51
  48. package/src/platform/null_platform_tests.zig +39 -0
  49. package/src/platform/root.zig +10 -0
  50. package/src/platform/types.zig +105 -16
  51. package/src/platform/windows/root.zig +20 -6
  52. package/src/platform/windows/webview2_host.cpp +41 -5
  53. package/src/root.zig +7 -0
  54. package/src/runtime/api.zig +8 -0
  55. package/src/runtime/automation_commands.zig +35 -2
  56. package/src/runtime/automation_snapshot.zig +32 -24
  57. package/src/runtime/bridge_permission_tests.zig +35 -1
  58. package/src/runtime/bridge_responses.zig +1 -1
  59. package/src/runtime/builtin_bridge.zig +11 -1
  60. package/src/runtime/core.zig +12 -6
  61. package/src/runtime/effects.zig +1323 -35
  62. package/src/runtime/effects_file_tests.zig +587 -0
  63. package/src/runtime/effects_notification_tests.zig +11 -0
  64. package/src/runtime/file_access.zig +400 -0
  65. package/src/runtime/file_effect_crash_helper.zig +28 -0
  66. package/src/runtime/file_effect_crash_tests.zig +37 -0
  67. package/src/runtime/flow.zig +21 -9
  68. package/src/runtime/native_command_event_tests.zig +44 -2
  69. package/src/runtime/pty.zig +5 -2
  70. package/src/runtime/root.zig +5 -0
  71. package/src/runtime/session_blobs.zig +4 -1
  72. package/src/runtime/session_journal.zig +56 -5
  73. package/src/runtime/session_record.zig +38 -0
  74. package/src/runtime/session_replay.zig +97 -7
  75. package/src/runtime/session_tests.zig +81 -0
  76. package/src/runtime/state.zig +10 -0
  77. package/src/runtime/system_services.zig +129 -36
  78. package/src/runtime/ts_core_host.zig +281 -11
  79. package/src/runtime/ts_core_host_tests.zig +95 -1
  80. package/src/runtime/ts_ui_app.zig +461 -8
  81. package/src/runtime/ui_app.zig +321 -109
  82. package/src/runtime/ui_app_tests.zig +132 -6
  83. package/src/runtime/ui_app_window_tests.zig +61 -7
  84. package/src/runtime/validation.zig +20 -0
  85. package/src/tooling/templates.zig +28 -0
  86. package/src/tooling/ts_core.zig +83 -0
  87. package/tools/corewire/emit.zig +3 -3
  88. package/tools/corewire/emit_facade.zig +65 -5
  89. package/tools/corewire/emit_profile.zig +2 -2
  90. package/tools/corewire/emit_service.zig +2 -2
  91. package/tools/corewire/service_contract.zig +4 -4
  92. package/tools/corewire/sidecar.zig +4 -4
@@ -0,0 +1,241 @@
1
+ //! The generated mobile wiring for a TypeScript app core — staged (never
2
+ //! written into the app) by the framework build beside the desktop entry
3
+ //! when the tree carries src/core.ts and the target is iOS or Android. The
4
+ //! embed static library's `app` module roots here: the file satisfies the
5
+ //! embed host's AppDef contract (`Model`, `Msg`, `initModel`,
6
+ //! `mobileOptions` — see `src/embed/ui_host.zig`) over the same staged
7
+ //! mirror (core.zig), markup (app.native), service registry (services.zig),
8
+ //! and carrier constant (service_carrier.zig) the desktop wiring uses.
9
+ //!
10
+ //! What differs from ts_core_main.zig is only the shell:
11
+ //!
12
+ //! scene the canonical single-surface mobile scene (window 1, one
13
+ //! gpu_surface labeled "mobile-surface") plus the app.zon
14
+ //! shell's declared platform chrome (tabs, primary action) —
15
+ //! the toolkit hosts project those as real system controls.
16
+ //! services the in-process pool is the ONLY carrier on mobile (no
17
+ //! child processes exist there); the build graph resolves
18
+ //! auto to in_process, and this file refuses a staged child
19
+ //! selection at comptime. The pool's marker/relay files live
20
+ //! in the OS app-data directory the shim installs through
21
+ //! `native_sdk_app_set_data_root` (the `serviceDataRoot`
22
+ //! hook below).
23
+ //! data dir a core exporting `envMsgs` with `NATIVE_SDK_APP_DATA_DIR`
24
+ //! receives the same shim-installed directory as a journaled
25
+ //! Msg right after the boot command.
26
+ //!
27
+ //! Model persistence (`persist`), boot images, and URL media caching are
28
+ //! not wired on mobile yet; the corresponding core commands degrade the
29
+ //! way the adapter documents (snapshots never write, views keep their
30
+ //! fallbacks, URL playback re-streams).
31
+ //!
32
+ //! Editing this file is never core-level work: it carries no app logic and
33
+ //! regenerates from the SDK on every build.
34
+
35
+ const std = @import("std");
36
+ const native_sdk = @import("native_sdk");
37
+ const manifest = @import("app_manifest_zon");
38
+ pub const core = @import("core.zig");
39
+ const services = @import("services.zig");
40
+ const service_carrier = @import("service_carrier.zig");
41
+
42
+ const Adapter = native_sdk.TsUiApp(core);
43
+
44
+ /// Re-exported for the embed host's AppDef contract (and any test that
45
+ /// reflects the core's real surface).
46
+ pub const Model = core.Model;
47
+ pub const Msg = core.Msg;
48
+
49
+ pub const app_markup = @embedFile("app.native");
50
+
51
+ comptime {
52
+ // The build graph resolves the carrier before staging this file; a
53
+ // staged child selection on a mobile target is a build-graph defect,
54
+ // not an app author's error.
55
+ if (services.enabled and service_carrier.kind == .child) {
56
+ @compileError("mobile TypeScript services run on the in-process pool; the child carrier cannot be staged here");
57
+ }
58
+ }
59
+
60
+ const use_pool = services.enabled and service_carrier.kind == .in_process;
61
+ const PoolTransport = native_sdk.ServicePool(services);
62
+
63
+ const app_data_dir_env = "NATIVE_SDK_APP_DATA_DIR";
64
+
65
+ const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
66
+
67
+ /// The canonical mobile surface plus the app's declared platform chrome.
68
+ const mobile_scene: native_sdk.app_manifest.ShellConfig = .{
69
+ .windows = native_sdk.embed.mobile_shell_scene.windows,
70
+ .chrome = shell_scene.chrome,
71
+ };
72
+
73
+ // Adapter-held mobile state (container-level, like the adapter's own
74
+ // install stores — one live app per core module is the v1 contract): the
75
+ // pool, its executor, and the shim-installed app-data directory.
76
+ var pool_io_state: std.Io.Threaded = undefined;
77
+ var pool_transport: PoolTransport = undefined;
78
+ var data_root_buffer: [native_sdk.embed.max_mobile_asset_root_bytes]u8 = undefined;
79
+ var env_entries: [envMsgsLen()]Adapter.EnvValue = undefined;
80
+ var env_entry_count: usize = 0;
81
+ var env_value_copies: [envMsgsLen()][]u8 = undefined;
82
+ var env_value_copy_count: usize = 0;
83
+ var data_root_env_indices: [envMsgsLen()]usize = undefined;
84
+ var data_root_env_count: usize = 0;
85
+
86
+ /// The embed host calls `mobileOptions()` first (UiAppHost.create), so the
87
+ /// boot model is committed by the time `initModel` reads it.
88
+ pub fn initModel() Model {
89
+ return Adapter.Host.model().*;
90
+ }
91
+
92
+ pub fn mobileOptions() Adapter.Options {
93
+ if (comptime @hasDecl(core.Model, "windows")) {
94
+ @compileError("model-declared secondary windows are a desktop shell capability; omit windows(model) from mobile targets");
95
+ }
96
+ var options: Adapter.Options = .{
97
+ .name = manifest.name,
98
+ .scene = mobile_scene,
99
+ .canvas_label = native_sdk.embed.mobile_gpu_surface_label,
100
+ .markup = .{ .source = app_markup },
101
+ // app.zon's theme pack and one-accent override, same as desktop.
102
+ .theme = comptime manifestThemePack(),
103
+ .theme_accent = comptime manifestThemeAccent(),
104
+ };
105
+ if (comptime @hasDecl(core, "commandMsg")) {
106
+ // Projected chrome (tabs, primary action) dispatches through the
107
+ // core's exported command mapper.
108
+ options.on_command = core.commandMsg;
109
+ }
110
+ return Adapter.mobileOptions(coreOptions(), options);
111
+ }
112
+
113
+ fn coreOptions() Adapter.CoreOptions {
114
+ freeEnvValueCopies();
115
+ var core_options: Adapter.CoreOptions = .{};
116
+ if (comptime use_pool) {
117
+ // The pool's own executor: mobile has no `std.process.Init` to
118
+ // thread an Io from. Nothing starts before the first real request,
119
+ // so constructing the pool here keeps replay semantics intact.
120
+ pool_io_state = std.Io.Threaded.init(std.heap.page_allocator, .{});
121
+ pool_transport = PoolTransport.init(
122
+ std.heap.page_allocator,
123
+ pool_io_state.io(),
124
+ "",
125
+ .{ .max_workers = service_carrier.pool_workers },
126
+ );
127
+ core_options.host_calls = pool_transport.binding();
128
+ }
129
+ if (comptime services.enabled) {
130
+ core_options.service_results = .{
131
+ .index_fn = services.indexOf,
132
+ .streaming_fn = services.isStreaming,
133
+ .decode_fn = services.resultDecoder(core),
134
+ };
135
+ }
136
+ env_entry_count = 0;
137
+ data_root_env_count = 0;
138
+ if (comptime @hasDecl(core, "envMsgs")) {
139
+ inline for (core.envMsgs) |entry| {
140
+ if (comptime std.mem.eql(u8, entry.env, app_data_dir_env)) {
141
+ // The embed host installs the authoritative app-data path
142
+ // after mobileOptions(), before start. Keep its compacted
143
+ // slot so serviceDataRoot can fill it without trusting an
144
+ // ambient value for this reserved variable.
145
+ data_root_env_indices[data_root_env_count] = env_entry_count;
146
+ data_root_env_count += 1;
147
+ env_entries[env_entry_count] = .{ .msg = entry.msg, .value = "" };
148
+ env_entry_count += 1;
149
+ } else if (std.c.getenv(entry.env)) |value| {
150
+ // Snapshot the process value at launch, matching the desktop
151
+ // runner. Keep an owned copy because later setenv calls may
152
+ // invalidate getenv storage before the first installing frame.
153
+ if (std.heap.page_allocator.dupe(u8, std.mem.span(value))) |copy| {
154
+ env_value_copies[env_value_copy_count] = copy;
155
+ env_value_copy_count += 1;
156
+ env_entries[env_entry_count] = .{ .msg = entry.msg, .value = copy };
157
+ env_entry_count += 1;
158
+ } else |_| {}
159
+ }
160
+ }
161
+ }
162
+ core_options.env_values = env_entries[0..env_entry_count];
163
+ return core_options;
164
+ }
165
+
166
+ /// Embed-host hook (`native_sdk_app_set_data_root`, before start): the
167
+ /// OS-owned app-data directory. The pool's cooperative-cancellation
168
+ /// markers and stream-relay files move here — the one writable directory
169
+ /// both mobile sandboxes guarantee — and a core's `envMsgs` request for
170
+ /// the data directory resolves to it.
171
+ pub fn serviceDataRoot(root: []const u8) void {
172
+ // UiAppHost validates this against the same exported ABI limit before
173
+ // invoking the hook, so every accepted path fits whole.
174
+ std.debug.assert(root.len <= data_root_buffer.len);
175
+ @memcpy(data_root_buffer[0..root.len], root);
176
+ const installed = data_root_buffer[0..root.len];
177
+ if (comptime use_pool) pool_transport.cwd = installed;
178
+ // Keep the whole projection out of a serviceDataRoot instantiation when
179
+ // this core exports no envMsgs. Zig still analyzes a runtime loop body
180
+ // over a zero-length array, so relying on data_root_env_count == 0 would
181
+ // leave `env_entries[index]` as an illegal index into [0]EnvValue.
182
+ if (comptime envMsgsLen() > 0) {
183
+ for (data_root_env_indices[0..data_root_env_count]) |index| {
184
+ env_entries[index].value = installed;
185
+ }
186
+ }
187
+ }
188
+
189
+ /// Embed-host hook (destroy): the pool's shutdown already ran through the
190
+ /// effects binding; this returns its queues and executor.
191
+ pub fn serviceTeardown() void {
192
+ if (comptime use_pool) {
193
+ pool_transport.deinit();
194
+ pool_io_state.deinit();
195
+ }
196
+ freeEnvValueCopies();
197
+ }
198
+
199
+ fn freeEnvValueCopies() void {
200
+ for (env_value_copies[0..env_value_copy_count]) |copy| {
201
+ std.heap.page_allocator.free(copy);
202
+ }
203
+ env_value_copy_count = 0;
204
+ }
205
+
206
+ fn envMsgsLen() usize {
207
+ comptime {
208
+ if (!@hasDecl(core, "envMsgs")) return 0;
209
+ return core.envMsgs.len;
210
+ }
211
+ }
212
+
213
+ /// app.zon's theme pack, resolved at comptime (the desktop runner's
214
+ /// `manifestThemePack`, restated here because the mobile module never
215
+ /// links the runner).
216
+ fn manifestThemePack() native_sdk.canvas.ThemePack {
217
+ if (comptime !@hasField(@TypeOf(manifest), "theme")) return .house;
218
+ const name: []const u8 = manifest.theme;
219
+ return comptime native_sdk.canvas.ThemePack.fromName(name) orelse
220
+ @compileError("unknown app.zon theme \"" ++ name ++ "\" — expected one of: house, geist");
221
+ }
222
+
223
+ /// app.zon's one-accent brand override, resolved at comptime (the desktop
224
+ /// runner's `manifestThemeAccent`).
225
+ fn manifestThemeAccent() ?native_sdk.canvas.Color {
226
+ if (comptime !@hasField(@TypeOf(manifest), "theme_accent")) return null;
227
+ const value: []const u8 = manifest.theme_accent;
228
+ return comptime parseHexColor(value) orelse
229
+ @compileError("invalid app.zon theme_accent \"" ++ value ++ "\" — expected a #rrggbb hex color");
230
+ }
231
+
232
+ fn parseHexColor(comptime value: []const u8) ?native_sdk.canvas.Color {
233
+ comptime {
234
+ if (value.len != 7 or value[0] != '#') return null;
235
+ var channels: [3]u8 = undefined;
236
+ for (&channels, 0..) |*channel, index| {
237
+ channel.* = std.fmt.parseInt(u8, value[1 + index * 2 .. 3 + index * 2], 16) catch return null;
238
+ }
239
+ return native_sdk.canvas.Color.rgb8(channels[0], channels[1], channels[2]);
240
+ }
241
+ }
@@ -51,7 +51,11 @@ pub const fingerprint: u64 = layout_fingerprint.hash(layoutDescription(semantic_
51
51
  /// enum). Declared-shape changes — new verbs, renamed actions, budget
52
52
  /// or naming changes — need NO action here: the fingerprint moves on
53
53
  /// its own.
54
- pub const semantic_epoch: u32 = 1;
54
+ /// Epoch 2: status-item snapshots gained stable item identifiers and
55
+ /// visibility, and `tray-action` gained the explicit
56
+ /// `<status-item-id> <menu-item-id>` form (the old one-id primary-item
57
+ /// shorthand remains valid).
58
+ pub const semantic_epoch: u32 = 2;
55
59
 
56
60
  /// The canonical description the protocol fingerprint hashes: the
57
61
  /// command vocabulary (the `Action` enum, reflected — names and values,
@@ -233,6 +233,8 @@ pub const TrayItem = struct {
233
233
  /// The macOS menu bar is outside every window capture, so this is the
234
234
  /// only automation-visible evidence a model-driven tray exists.
235
235
  pub const Tray = struct {
236
+ id: platform.StatusItemId = platform.primary_status_item_id,
237
+ visible: bool = true,
236
238
  title: []const u8 = "",
237
239
  items: []const TrayItem = &.{},
238
240
  };
@@ -304,8 +306,8 @@ pub const Input = struct {
304
306
  /// headroom.
305
307
  text_layout_plan_budget: usize = 0,
306
308
  text_layout_line_budget: usize = 0,
307
- /// The live status item, when the app created one.
308
- tray: ?Tray = null,
309
+ /// Every live status item, keyed by its stable identifier.
310
+ trays: []const Tray = &.{},
309
311
  /// Live audio playback, when the app started any (null once stopped
310
312
  /// or failed — an idle player is honest, not zeroed-out noise).
311
313
  audio: ?Audio = null,
@@ -593,8 +595,8 @@ pub fn writeText(input: Input, writer: anytype) !void {
593
595
  try writeWidgetContextMenu(widget, writer);
594
596
  try writer.writeByte('\n');
595
597
  }
596
- if (input.tray) |tray| {
597
- try writer.print("tray title=\"{s}\" items={d}\n", .{ tray.title, tray.items.len });
598
+ for (input.trays) |tray| {
599
+ try writer.print("tray #{d} title=\"{s}\" visible={any} items={d}\n", .{ tray.id, tray.title, tray.visible, tray.items.len });
598
600
  for (tray.items) |item| {
599
601
  if (item.separator) {
600
602
  try writer.writeAll(" tray-item separator\n");
@@ -925,10 +927,10 @@ test "snapshot emits tray title and dropdown items" {
925
927
  };
926
928
  try writeText(.{
927
929
  .windows = &windows,
928
- .tray = .{ .title = "ZN 3", .items = &items },
930
+ .trays = &.{.{ .id = 7, .title = "ZN 3", .visible = false, .items = &items }},
929
931
  }, &writer);
930
932
  const text = writer.buffered();
931
- try std.testing.expect(std.mem.indexOf(u8, text, "\ntray title=\"ZN 3\" items=3\n") != null);
933
+ try std.testing.expect(std.mem.indexOf(u8, text, "\ntray #7 title=\"ZN 3\" visible=false items=3\n") != null);
932
934
  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);
933
935
  try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
934
936
  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);
@@ -16,6 +16,7 @@ comptime {
16
16
  &relational_migrations.migrations,
17
17
  mobile_build_options.credentials_capability,
18
18
  mobile_build_options.credentials_permission,
19
+ mobile_build_options.filesystem_permission,
19
20
  mobile_build_options.credentials_service,
20
21
  ));
21
22
  }
@@ -23,6 +23,7 @@ pub const MobileImageService = types.MobileImageService;
23
23
  pub const MobileChromeItem = chrome.MobileChromeItem;
24
24
  pub const renderChromeIconPixels = chrome.renderIconPixels;
25
25
  pub const mobile_gpu_surface_label = types.mobile_gpu_surface_label;
26
+ pub const max_mobile_asset_root_bytes = types.max_mobile_asset_root_bytes;
26
27
 
27
28
  pub const EmbeddedApp = host.EmbeddedApp;
28
29
  pub const MobileHostApp = host.MobileHostApp;
@@ -982,6 +982,9 @@ test "mobile C ABI dispatches GPU widget accessibility actions" {
982
982
  // render pixels, touch that mutates the model, and IME text that lands in a
983
983
  // textbox — with NullPlatform standing in for the (M2) real surface.
984
984
 
985
+ var mobile_service_data_root: [types.max_mobile_asset_root_bytes]u8 = undefined;
986
+ var mobile_service_data_root_len: usize = 0;
987
+
985
988
  const MobileCounterDef = struct {
986
989
  pub const Model = struct {
987
990
  count: u32 = 0,
@@ -1009,6 +1012,11 @@ const MobileCounterDef = struct {
1009
1012
  };
1010
1013
  }
1011
1014
 
1015
+ pub fn serviceDataRoot(root: []const u8) void {
1016
+ @memcpy(mobile_service_data_root[0..root.len], root);
1017
+ mobile_service_data_root_len = root.len;
1018
+ }
1019
+
1012
1020
  fn update(model: *Model, msg: Msg) void {
1013
1021
  switch (msg) {
1014
1022
  .increment => model.count += 1,
@@ -1044,6 +1052,7 @@ const MobileCredentialHost = ui_host.UiAppHostWithStorageAndCredentials(
1044
1052
  &.{},
1045
1053
  true,
1046
1054
  true,
1055
+ false,
1047
1056
  "dev.native-sdk.mobile-credentials",
1048
1057
  );
1049
1058
  const MobileCredentialApi = c_api.MobileCApi(MobileCredentialHost);
@@ -1210,6 +1219,10 @@ test "mobile store capability requires and binds the OS app-data root before sta
1210
1219
  try std.testing.expectEqual(@as(c_int, 1), MobileStoreApi.native_sdk_app_set_data_root(app, path.ptr, path.len));
1211
1220
  try std.testing.expect(self.record_store_open);
1212
1221
  try std.testing.expect(self.embedded.runtime.options.record_store != null);
1222
+ try std.testing.expectEqual(@as(usize, 6), self.embedded.runtime.options.file_access.?.roots.len);
1223
+ for (self.embedded.runtime.options.file_access.?.roots) |root| {
1224
+ try std.testing.expectEqualStrings(path, root);
1225
+ }
1213
1226
 
1214
1227
  MobileStoreApi.native_sdk_app_start(app);
1215
1228
  try std.testing.expectEqualStrings("", std.mem.span(MobileStoreApi.native_sdk_app_last_error_name(app)));
@@ -1221,6 +1234,21 @@ test "mobile store capability requires and binds the OS app-data root before sta
1221
1234
  MobileStoreApi.native_sdk_app_stop(app);
1222
1235
  }
1223
1236
 
1237
+ test "mobile host passes the complete maximum-length data root to app wiring" {
1238
+ const app = MobileCounterApi.native_sdk_app_create() orelse return error.TestUnexpectedResult;
1239
+ defer MobileCounterApi.native_sdk_app_destroy(app);
1240
+
1241
+ var root: [types.max_mobile_asset_root_bytes]u8 = @splat('a');
1242
+ root[0] = '.';
1243
+ mobile_service_data_root_len = 0;
1244
+ try std.testing.expectEqual(
1245
+ @as(c_int, 1),
1246
+ MobileCounterApi.native_sdk_app_set_data_root(app, &root, root.len),
1247
+ );
1248
+ try std.testing.expectEqual(root.len, mobile_service_data_root_len);
1249
+ try std.testing.expectEqualSlices(u8, &root, mobile_service_data_root[0..mobile_service_data_root_len]);
1250
+ }
1251
+
1224
1252
  test "mobile relational capability opens app.db from the OS app-data root" {
1225
1253
  const app = MobileRelationalApi.native_sdk_app_create() orelse return error.TestUnexpectedResult;
1226
1254
  defer MobileRelationalApi.native_sdk_app_destroy(app);
@@ -14,6 +14,10 @@
14
14
  //! `canvas_label` must be `mobile-surface` (use `mobile_shell_scene` /
15
15
  //! `mobile_gpu_surface_label` for the canonical single-surface scene).
16
16
  //! - optional `pub const features: native_sdk.UiAppFeatures`
17
+ //! - optional `pub fn serviceDataRoot([]const u8) void` /
18
+ //! `pub fn serviceTeardown() void` — the generated TypeScript mobile
19
+ //! wiring's hooks: the host hands `setDataRoot`'s directory to the
20
+ //! in-process service pool and tears the pool down on destroy.
17
21
  //!
18
22
  //! The host owns a `NullPlatform` runtime (M1: no real surface — M2 adds
19
23
  //! presentation) and pumps the `UiApp` loop from the shim's frame callback:
@@ -24,10 +28,12 @@
24
28
  //! the ABI via `native_sdk_app_render_pixels`.
25
29
 
26
30
  const std = @import("std");
31
+ const builtin = @import("builtin");
27
32
  const app_manifest = @import("app_manifest");
28
33
  const canvas = @import("canvas");
29
34
  const runtime = @import("../runtime/root.zig");
30
35
  const platform = @import("../platform/root.zig");
36
+ const app_dirs = @import("app_dirs");
31
37
  const security = @import("../security/root.zig");
32
38
  const types = @import("types.zig");
33
39
  const host = @import("host.zig");
@@ -83,6 +89,7 @@ pub fn UiAppHostWithStorage(
83
89
  relational_migrations,
84
90
  false,
85
91
  false,
92
+ false,
86
93
  "dev.native_sdk.app",
87
94
  );
88
95
  }
@@ -96,6 +103,7 @@ pub fn UiAppHostWithStorageAndCredentials(
96
103
  comptime relational_migrations: []const runtime.relational_store.Migration,
97
104
  comptime credentials_enabled: bool,
98
105
  comptime credentials_permitted: bool,
106
+ comptime filesystem_permitted: bool,
99
107
  comptime credentials_service: []const u8,
100
108
  ) type {
101
109
  const features: runtime.UiAppFeatures = if (@hasDecl(AppDef, "features")) AppDef.features else .{};
@@ -125,6 +133,8 @@ pub fn UiAppHostWithStorageAndCredentials(
125
133
  asset_root_len: usize = 0,
126
134
  asset_entry: [max_mobile_asset_entry_bytes]u8 = undefined,
127
135
  asset_entry_len: usize = 0,
136
+ file_root_storage: [6][max_mobile_asset_root_bytes]u8 = undefined,
137
+ file_roots: [6][]const u8 = undefined,
128
138
  automation_dir: [max_mobile_asset_root_bytes]u8 = undefined,
129
139
  automation_dir_len: usize = 0,
130
140
  automation_io: ?*std.Io.Threaded = null,
@@ -191,6 +201,8 @@ pub fn UiAppHostWithStorageAndCredentials(
191
201
  self.asset_root_len = 0;
192
202
  self.asset_entry = undefined;
193
203
  self.asset_entry_len = 0;
204
+ self.file_root_storage = undefined;
205
+ self.file_roots = undefined;
194
206
  self.automation_dir = undefined;
195
207
  self.automation_dir_len = 0;
196
208
  self.automation_io = null;
@@ -221,10 +233,21 @@ pub fn UiAppHostWithStorageAndCredentials(
221
233
  // registers its OS credential service.
222
234
  try host.setCredentialService(self, .{}, null);
223
235
  self.embedded.runtime.options.credentials_enabled = credentials_enabled;
224
- self.embedded.runtime.options.security.permissions = if (credentials_permitted)
236
+ self.embedded.runtime.options.security.permissions = if (credentials_permitted and filesystem_permitted)
237
+ &.{ security.permission_credentials, security.permission_filesystem }
238
+ else if (credentials_permitted)
225
239
  &.{security.permission_credentials}
240
+ else if (filesystem_permitted)
241
+ &.{security.permission_filesystem}
226
242
  else
227
243
  &.{};
244
+ // Until the OS data root is installed, fail closed for ungranted
245
+ // raw paths. A filesystem grant is sufficient on its own.
246
+ self.embedded.runtime.options.file_access = .{
247
+ .roots = &.{},
248
+ .permitted = filesystem_permitted,
249
+ .enforce = true,
250
+ };
228
251
  // The damage seam: capture pixel presents (chained through
229
252
  // the null platform's recording present, so nonblank
230
253
  // sampling keeps working), drop the packet presenters no
@@ -247,6 +270,11 @@ pub fn UiAppHostWithStorageAndCredentials(
247
270
  // its heap-owned registrations (registered canvas font
248
271
  // bytes) before the host storage goes.
249
272
  self.embedded.deinit();
273
+ // An AppDef owning module-level service state (the generated
274
+ // TypeScript mobile wiring's in-process pool) tears it down
275
+ // after the effects channel is gone; the pool's own shutdown
276
+ // already ran through the binding.
277
+ if (comptime @hasDecl(AppDef, "serviceTeardown")) AppDef.serviceTeardown();
250
278
  if (comptime record_store_enabled) {
251
279
  if (self.record_store_open) self.record_store.deinit();
252
280
  }
@@ -284,10 +312,48 @@ pub fn UiAppHostWithStorageAndCredentials(
284
312
  /// Install the OS-owned app-data directory before start. iOS passes
285
313
  /// Library/Application Support and Android passes files/, exactly the
286
314
  /// `.data` directories resolved by `app_dirs` on those platforms.
315
+ /// An AppDef declaring `serviceDataRoot` (the generated TypeScript
316
+ /// mobile wiring) receives the directory too — the in-process
317
+ /// service pool keeps its cooperative-cancellation markers and
318
+ /// stream relays there, and cores reading `NATIVE_SDK_APP_DATA_DIR`
319
+ /// through `envMsgs` get this value.
287
320
  pub fn setDataRoot(self: *Self, data_root: []const u8) !void {
288
- if (comptime !record_store_enabled and !relational_store_enabled) return;
289
321
  if (self.started) return error.AppAlreadyStarted;
290
322
  if (data_root.len == 0 or data_root.len > max_mobile_asset_root_bytes) return error.InvalidStoreDataDir;
323
+ if (comptime @hasDecl(AppDef, "serviceDataRoot")) AppDef.serviceDataRoot(data_root);
324
+ const platform_value = app_dirs.currentPlatform();
325
+ if (builtin.is_test and platform_value != .ios and platform_value != .android) {
326
+ for (&self.file_root_storage, 0..) |*storage, index| {
327
+ @memcpy(storage[0..data_root.len], data_root);
328
+ self.file_roots[index] = storage[0..data_root.len];
329
+ }
330
+ self.embedded.runtime.options.file_access = .{
331
+ .roots = &self.file_roots,
332
+ .permitted = filesystem_permitted,
333
+ .enforce = true,
334
+ };
335
+ } else {
336
+ const home = switch (platform_value) {
337
+ // iOS data_root is HOME/Library/Application Support.
338
+ .ios => std.fs.path.dirname(std.fs.path.dirname(data_root) orelse return error.InvalidStoreDataDir) orelse return error.InvalidStoreDataDir,
339
+ // Android data_root is HOME/files.
340
+ .android => std.fs.path.dirname(data_root) orelse return error.InvalidStoreDataDir,
341
+ else => return error.InvalidStoreDataDir,
342
+ };
343
+ const dir_buffers = app_dirs.Buffers.fromArray(max_mobile_asset_root_bytes, &self.file_root_storage);
344
+ const dirs = try app_dirs.resolve(
345
+ .{ .name = credentials_service },
346
+ platform_value,
347
+ .{ .home = home },
348
+ dir_buffers,
349
+ );
350
+ self.file_roots = .{ dirs.config, dirs.cache, dirs.data, dirs.state, dirs.logs, dirs.temp };
351
+ self.embedded.runtime.options.file_access = .{
352
+ .roots = &self.file_roots,
353
+ .permitted = filesystem_permitted,
354
+ .enforce = true,
355
+ };
356
+ }
291
357
  if (comptime record_store_enabled) {
292
358
  if (self.record_store_open) {
293
359
  self.record_store.deinit();
@@ -484,7 +484,7 @@ int native_sdk_gtk_reveal_path(Host *host, const char *path, size_t path_len) {
484
484
  return 0;
485
485
  }
486
486
 
487
- int native_sdk_gtk_show_notification(Host *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len) {
487
+ int native_sdk_gtk_show_notification(Host *host, const char *title, size_t title_len, const char *subtitle, size_t subtitle_len, const char *body, size_t body_len, const char *notification_id, size_t notification_id_len, const char *action_label, size_t action_label_len, const char *action_command, size_t action_command_len) {
488
488
  (void)host;
489
489
  (void)title;
490
490
  (void)title_len;
@@ -492,6 +492,12 @@ int native_sdk_gtk_show_notification(Host *host, const char *title, size_t title
492
492
  (void)subtitle_len;
493
493
  (void)body;
494
494
  (void)body_len;
495
+ (void)notification_id;
496
+ (void)notification_id_len;
497
+ (void)action_label;
498
+ (void)action_label_len;
499
+ (void)action_command;
500
+ (void)action_command_len;
495
501
  return 0;
496
502
  }
497
503