@native-sdk/cli 0.8.4 → 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 (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -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/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
@@ -526,18 +526,18 @@ pub fn assembleApk(allocator: std.mem.Allocator, io: std.Io, options: ApkOptions
526
526
  const javac = try javaSiblingAlloc(allocator, options.java, "javac");
527
527
  defer allocator.free(javac);
528
528
  try runInherit(io, &.{
529
- javac, "--release", "17", "-encoding",
530
- "UTF-8", "-cp", options.toolchain.android_jar, "-d",
531
- classes_dir, activity_path,
529
+ javac, "--release", "17", "-encoding",
530
+ "UTF-8", "-cp", options.toolchain.android_jar, "-d",
531
+ classes_dir, activity_path,
532
532
  }, error.ApkAssemblyFailed);
533
533
 
534
534
  // Classes -> classes.dex at the APK root.
535
535
  var dex_argv: std.ArrayList([]const u8) = .empty;
536
536
  defer dex_argv.deinit(allocator);
537
537
  try dex_argv.appendSlice(allocator, &.{
538
- options.java, "-cp", options.toolchain.d8_jar, "com.android.tools.r8.D8",
539
- "--release", "--lib", options.toolchain.android_jar,
540
- "--min-api", min_sdk_version, "--output", root_dir,
538
+ options.java, "-cp", options.toolchain.d8_jar, "com.android.tools.r8.D8",
539
+ "--release", "--lib", options.toolchain.android_jar, "--min-api",
540
+ min_sdk_version, "--output", root_dir,
541
541
  });
542
542
  var class_files = try collectFilesAlloc(allocator, io, classes_dir, ".class");
543
543
  defer freePathList(allocator, &class_files);
@@ -603,11 +603,9 @@ pub fn assembleApk(allocator: std.mem.Allocator, io: std.Io, options: ApkOptions
603
603
 
604
604
  try ensureDebugKeystore(allocator, io, options.java, options.keystore_path);
605
605
  try runInherit(io, &.{
606
- options.java, "-jar", options.toolchain.apksigner_jar, "sign",
607
- "--ks", options.keystore_path,
608
- "--ks-pass", "pass:android",
609
- "--ks-key-alias", "native-sdk-debug",
610
- "--out", options.out_apk,
606
+ options.java, "-jar", options.toolchain.apksigner_jar, "sign",
607
+ "--ks", options.keystore_path, "--ks-pass", "pass:android",
608
+ "--ks-key-alias", "native-sdk-debug", "--out", options.out_apk,
611
609
  aligned,
612
610
  }, error.ApkAssemblyFailed);
613
611
  }
@@ -628,11 +626,11 @@ fn ensureDebugKeystore(allocator: std.mem.Allocator, io: std.Io, java: []const u
628
626
  defer allocator.free(keytool);
629
627
  std.debug.print("native (android): generating the debug signing keystore at {s}\n", .{keystore_path});
630
628
  try runInherit(io, &.{
631
- keytool, "-genkeypair", "-keystore", keystore_path,
632
- "-storepass", "android", "-keypass", "android",
633
- "-alias", "native-sdk-debug",
634
- "-keyalg", "RSA", "-keysize", "2048",
635
- "-validity", "10950", "-dname", "CN=Native SDK Debug",
629
+ keytool, "-genkeypair", "-keystore", keystore_path,
630
+ "-storepass", "android", "-keypass", "android",
631
+ "-alias", "native-sdk-debug", "-keyalg", "RSA",
632
+ "-keysize", "2048", "-validity", "10950",
633
+ "-dname", "CN=Native SDK Debug",
636
634
  }, error.ApkAssemblyFailed);
637
635
  }
638
636
 
@@ -1154,6 +1152,13 @@ test "the embedded host sources are the toolkit host" {
1154
1152
  try std.testing.expect(std.mem.indexOf(u8, host_bridge_source, "nativeAudioEvent") != null);
1155
1153
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_audio_service_t") != null);
1156
1154
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_app_audio_event") != null);
1155
+ // Tier-4 credentials: non-exportable AndroidKeyStore AES-GCM key,
1156
+ // ciphertext-only private preferences, and the shared embed ABI.
1157
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "nativeSetCredentialService") != null);
1158
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "AndroidKeyStore") != null);
1159
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "AES/GCM/NoPadding") != null);
1160
+ try std.testing.expect(std.mem.indexOf(u8, host_bridge_source, "native_sdk_app_set_credential_service") != null);
1161
+ try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_credential_service_t") != null);
1157
1162
  }
1158
1163
 
1159
1164
  test "adb device parsing prefers ready devices and honors requests" {
@@ -0,0 +1,160 @@
1
+ //! `native db`: append-only migration authoring and development database
2
+ //! inspection/reset. Paths are always resolved from app identity through
3
+ //! app_dirs; the CLI never accepts an arbitrary database path.
4
+
5
+ const std = @import("std");
6
+ const app_dirs = @import("app_dirs");
7
+ const debug = @import("debug");
8
+ const manifest_tool = @import("manifest.zig");
9
+ const sqlite = @import("sqlite_engine");
10
+
11
+ pub const Error = error{ InvalidArguments, InvalidMigrationName, MigrationLimitReached, ResetNeedsConfirmation };
12
+
13
+ pub fn run(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map, args: []const []const u8) !void {
14
+ if (args.len == 0 or std.mem.eql(u8, args[0], "--help") or std.mem.eql(u8, args[0], "-h")) {
15
+ usage();
16
+ return;
17
+ }
18
+ const verb = args[0];
19
+ if (std.mem.eql(u8, verb, "new-migration")) {
20
+ if (args.len != 2) return Error.InvalidArguments;
21
+ try newMigration(allocator, io, args[1]);
22
+ } else if (std.mem.eql(u8, verb, "status")) {
23
+ if (args.len != 1) return Error.InvalidArguments;
24
+ try status(allocator, io, env);
25
+ } else if (std.mem.eql(u8, verb, "reset")) {
26
+ if (args.len != 2 or !std.mem.eql(u8, args[1], "--yes")) return Error.ResetNeedsConfirmation;
27
+ try reset(allocator, io, env);
28
+ } else return Error.InvalidArguments;
29
+ }
30
+
31
+ fn usage() void {
32
+ std.debug.print(
33
+ \\usage: native db <command>
34
+ \\
35
+ \\commands:
36
+ \\ new-migration <name> append src/schema/NNNN_name.sql
37
+ \\ status show source and installed schema versions
38
+ \\ reset --yes delete this app's engine-owned development app.db
39
+ \\
40
+ , .{});
41
+ }
42
+
43
+ fn newMigration(allocator: std.mem.Allocator, io: std.Io, authored_name: []const u8) !void {
44
+ if (authored_name.len == 0 or authored_name.len > 64) return Error.InvalidMigrationName;
45
+ const safe = try allocator.alloc(u8, authored_name.len);
46
+ defer allocator.free(safe);
47
+ var previous_separator = false;
48
+ for (authored_name, 0..) |char, index| {
49
+ const lowered = std.ascii.toLower(char);
50
+ if ((lowered >= 'a' and lowered <= 'z') or (lowered >= '0' and lowered <= '9')) {
51
+ safe[index] = lowered;
52
+ previous_separator = false;
53
+ } else if ((char == '-' or char == '_' or char == ' ') and index > 0 and !previous_separator) {
54
+ safe[index] = '_';
55
+ previous_separator = true;
56
+ } else return Error.InvalidMigrationName;
57
+ }
58
+ if (safe[0] == '_' or safe[safe.len - 1] == '_') return Error.InvalidMigrationName;
59
+ try std.Io.Dir.cwd().createDirPath(io, "src/schema");
60
+ var dir = try std.Io.Dir.cwd().openDir(io, "src/schema", .{ .iterate = true });
61
+ defer dir.close(io);
62
+ var highest: u32 = 0;
63
+ var iterator = dir.iterate();
64
+ while (try iterator.next(io)) |entry| {
65
+ if (entry.kind != .file or entry.name.len < 9 or !std.mem.endsWith(u8, entry.name, ".sql")) continue;
66
+ const version = std.fmt.parseUnsigned(u32, entry.name[0..4], 10) catch continue;
67
+ if (entry.name[4] != '_') continue;
68
+ highest = @max(highest, version);
69
+ }
70
+ if (highest >= 9999) return Error.MigrationLimitReached;
71
+ const version = highest + 1;
72
+ const file_name = try std.fmt.allocPrint(allocator, "src/schema/{d:0>4}_{s}.sql", .{ version, safe });
73
+ defer allocator.free(file_name);
74
+ var file = try std.Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
75
+ defer file.close(io);
76
+ try file.writeStreamingAll(
77
+ io,
78
+ "-- Append-only SQLite migration. Use STRICT tables so generated types stay honest.\n" ++
79
+ "-- This version may never be edited after it is shipped.\n\n",
80
+ );
81
+ std.debug.print("created {s}\n", .{file_name});
82
+ }
83
+
84
+ fn status(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map) !void {
85
+ const target = try migrationSourceVersion(io);
86
+ var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
87
+ const db_path = try appDbPath(allocator, io, env, &path_buffer);
88
+ const installed = readUserVersion(allocator, io, db_path) catch |err| switch (err) {
89
+ error.FileNotFound => null,
90
+ else => return err,
91
+ };
92
+ if (installed) |version| {
93
+ const relation = if (version == target) "current" else if (version < target) "pending migrations" else "newer than this source (runtime will refuse it)";
94
+ std.debug.print("source schema: {d}\ninstalled schema: {d} ({s})\ndatabase: {s}\n", .{ target, version, relation, db_path });
95
+ } else {
96
+ std.debug.print("source schema: {d}\ninstalled schema: none (created on first launch)\ndatabase: {s}\n", .{ target, db_path });
97
+ }
98
+ }
99
+
100
+ fn reset(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map) !void {
101
+ var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
102
+ const db_path = try appDbPath(allocator, io, env, &path_buffer);
103
+ for ([_][]const u8{ "", "-wal", "-shm" }) |suffix| {
104
+ const path = try std.fmt.allocPrint(allocator, "{s}{s}", .{ db_path, suffix });
105
+ defer allocator.free(path);
106
+ std.Io.Dir.cwd().deleteFile(io, path) catch |err| switch (err) {
107
+ error.FileNotFound => {},
108
+ else => return err,
109
+ };
110
+ }
111
+ std.debug.print("reset relational database {s} (the next development launch reapplies every migration)\n", .{db_path});
112
+ }
113
+
114
+ fn migrationSourceVersion(io: std.Io) !u32 {
115
+ var dir = std.Io.Dir.cwd().openDir(io, "src/schema", .{ .iterate = true }) catch |err| switch (err) {
116
+ error.FileNotFound => return 0,
117
+ else => return err,
118
+ };
119
+ defer dir.close(io);
120
+ var count: u32 = 0;
121
+ var iterator = dir.iterate();
122
+ while (try iterator.next(io)) |entry| {
123
+ if (entry.kind == .file and entry.name.len >= 9 and entry.name[4] == '_' and std.mem.endsWith(u8, entry.name, ".sql")) count += 1;
124
+ }
125
+ return count;
126
+ }
127
+
128
+ fn appDbPath(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map, buffer: []u8) ![]const u8 {
129
+ const metadata = try manifest_tool.readMetadata(allocator, io, "app.zon");
130
+ var dir_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
131
+ const data_dir = try app_dirs.resolveOne(
132
+ .{ .name = metadata.id },
133
+ app_dirs.currentPlatform(),
134
+ debug.envFromMap(env),
135
+ .data,
136
+ &dir_buffer,
137
+ );
138
+ return std.fmt.bufPrint(buffer, "{s}/app.db", .{data_dir});
139
+ }
140
+
141
+ /// Read through SQLite rather than the file header: WAL may carry a newer
142
+ /// user_version than byte 60 in the main database until checkpoint.
143
+ fn readUserVersion(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !u32 {
144
+ var file = try std.Io.Dir.cwd().openFile(io, path, .{});
145
+ file.close(io);
146
+ const path_z = try allocator.dupeZ(u8, path);
147
+ defer allocator.free(path_z);
148
+ var connection = try sqlite.Connection.open(path_z);
149
+ defer connection.close();
150
+ var statement = try connection.prepareOne("PRAGMA user_version;");
151
+ defer statement.finalize();
152
+ if ((try statement.step()) != .row) return error.InvalidDatabaseHeader;
153
+ const version = statement.columnInt(0);
154
+ if (version < 0 or version > 9999) return error.InvalidDatabaseHeader;
155
+ return @intCast(version);
156
+ }
157
+
158
+ test "migration author names are bounded and normalized" {
159
+ try std.testing.expectError(Error.InvalidMigrationName, newMigration(std.testing.allocator, std.testing.io, "../escape"));
160
+ }
@@ -312,7 +312,8 @@ pub fn runDev(allocator: std.mem.Allocator, io: std.Io, options: DevOptions) !vo
312
312
  "QuartzCore", "-framework", "Foundation",
313
313
  "-framework", "CoreGraphics", "-framework",
314
314
  "AVFoundation", "-framework", "ImageIO",
315
- "-o", executable_path,
315
+ "-framework", "Security", "-o",
316
+ executable_path,
316
317
  }, error.HostCompileFailed);
317
318
  try runInherit(io, &.{ "codesign", "--force", "--sign", "-", bundle_path }, error.HostCompileFailed);
318
319
 
@@ -497,6 +498,11 @@ test "the embedded host sources are the toolkit host" {
497
498
  try std.testing.expect(std.mem.indexOf(u8, host_source, "handleSessionInterruption") != null);
498
499
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_audio_service_t") != null);
499
500
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_app_audio_event") != null);
501
+ // Tier-4 credentials: generic-password Keychain entries registered
502
+ // through the shared mobile credential service ABI.
503
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_app_set_credential_service") != null);
504
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "SecItemCopyMatching") != null);
505
+ try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_credential_service_t") != null);
500
506
  // Platform push/pop navigation: the depth projection poll, the REAL
501
507
  // interactive pop recognizer, and the completed gesture's exactly-once
502
508
  // back-command dispatch.
@@ -22,6 +22,13 @@ pub const Metadata = struct {
22
22
  platforms: []const []const u8 = &.{},
23
23
  permissions: []const []const u8 = &.{},
24
24
  capabilities: []const []const u8 = &.{},
25
+ persist: ?PersistMetadata = null,
26
+ service_packages: []const ServicePackageMetadata = &.{},
27
+ /// Which carrier runs src/services operations: "auto", "in_process",
28
+ /// or "child". Validated so a typo teaches at check time.
29
+ service_carrier: []const u8 = "auto",
30
+ /// In-process service pool width; null keeps the runtime default.
31
+ service_pool_size: ?u8 = null,
25
32
  bridge_commands: []const BridgeCommandMetadata = &.{},
26
33
  web_engine: []const u8 = "system",
27
34
  /// Whether the app ships the embedded web layer: "auto" (default,
@@ -70,6 +77,7 @@ pub const Metadata = struct {
70
77
  allocator.free(self.web_engine);
71
78
  allocator.free(self.webview_layer);
72
79
  allocator.free(self.core_compiler);
80
+ allocator.free(self.service_carrier);
73
81
  allocator.free(self.cef.dir);
74
82
  for (self.icons) |value| allocator.free(value);
75
83
  if (self.icons.len > 0) allocator.free(self.icons);
@@ -79,6 +87,17 @@ pub const Metadata = struct {
79
87
  if (self.permissions.len > 0) allocator.free(self.permissions);
80
88
  for (self.capabilities) |value| allocator.free(value);
81
89
  if (self.capabilities.len > 0) allocator.free(self.capabilities);
90
+ if (self.persist) |persist| {
91
+ allocator.free(persist.restore.ok);
92
+ allocator.free(persist.restore.none);
93
+ allocator.free(persist.restore.err);
94
+ }
95
+ for (self.service_packages) |package_entry| {
96
+ allocator.free(package_entry.name);
97
+ allocator.free(package_entry.version);
98
+ allocator.free(package_entry.content_hash);
99
+ }
100
+ if (self.service_packages.len > 0) allocator.free(self.service_packages);
82
101
  for (self.bridge_commands) |command| {
83
102
  allocator.free(command.name);
84
103
  for (command.permissions) |value| allocator.free(value);
@@ -197,6 +216,24 @@ pub const Metadata = struct {
197
216
  }
198
217
  };
199
218
 
219
+ pub const ServicePackageMetadata = struct {
220
+ name: []const u8,
221
+ version: []const u8,
222
+ content_hash: []const u8,
223
+ };
224
+
225
+ pub const PersistMetadata = struct {
226
+ version: u64,
227
+ debounce_ms: u32 = 500,
228
+ restore: PersistRestoreMetadata,
229
+ };
230
+
231
+ pub const PersistRestoreMetadata = struct {
232
+ ok: []const u8,
233
+ none: []const u8,
234
+ err: []const u8,
235
+ };
236
+
200
237
  pub const BridgeCommandMetadata = struct {
201
238
  name: []const u8,
202
239
  permissions: []const []const u8 = &.{},
@@ -217,6 +254,8 @@ pub const WindowMetadata = struct {
217
254
  always_on_top: bool = false,
218
255
  click_through: bool = false,
219
256
  activate_on_show: bool = true,
257
+ initially_hidden: bool = false,
258
+ allows_fullscreen: bool = true,
220
259
  min_width: f32 = 0,
221
260
  min_height: f32 = 0,
222
261
  close_policy: []const u8 = "quit",
@@ -259,6 +298,8 @@ pub const ShellWindowMetadata = struct {
259
298
  always_on_top: bool = false,
260
299
  click_through: bool = false,
261
300
  activate_on_show: bool = true,
301
+ initially_hidden: bool = false,
302
+ allows_fullscreen: bool = true,
262
303
  min_width: f32 = 0,
263
304
  min_height: f32 = 0,
264
305
  close_policy: []const u8 = "quit",
@@ -453,6 +494,21 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
453
494
  defer allocator.free(permissions);
454
495
  const capabilities = parseCapabilities(allocator, metadata.capabilities) catch return .{ .ok = false, .message = "app.zon capabilities are invalid" };
455
496
  defer allocator.free(capabilities);
497
+ const persist = convertPersist(metadata.persist);
498
+ if (!validServicePackages(metadata.service_packages)) return .{
499
+ .ok = false,
500
+ .message = "app.zon service_packages must use safe npm names, exact X.Y.Z versions, unique names, and lowercase SHA-256 content hashes",
501
+ };
502
+ if (!validServiceCarrier(metadata.service_carrier)) return .{
503
+ .ok = false,
504
+ .message = "app.zon service_carrier must be \"auto\", \"in_process\", or \"child\"",
505
+ };
506
+ if (metadata.service_pool_size) |pool_size| {
507
+ if (pool_size < 1 or pool_size > 16) return .{
508
+ .ok = false,
509
+ .message = "app.zon service_pool_size must be between 1 and 16",
510
+ };
511
+ }
456
512
  const bridge_commands = parseBridgeCommands(allocator, metadata.bridge_commands) catch return .{ .ok = false, .message = "app.zon bridge commands are invalid" };
457
513
  defer {
458
514
  for (bridge_commands) |command| allocator.free(command.permissions);
@@ -498,6 +554,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
498
554
  .version = parseVersion(metadata.version) catch return .{ .ok = false, .message = "app.zon version is invalid" },
499
555
  .permissions = permissions,
500
556
  .capabilities = capabilities,
557
+ .persist = persist,
501
558
  .bridge = .{ .commands = bridge_commands },
502
559
  .frontend = frontend,
503
560
  .security = security,
@@ -571,6 +628,10 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
571
628
  .platforms = try duplicateStringList(allocator, raw.platforms),
572
629
  .permissions = try duplicateStringList(allocator, raw.permissions),
573
630
  .capabilities = try duplicateStringList(allocator, raw.capabilities),
631
+ .persist = try duplicateRawPersist(allocator, raw.persist),
632
+ .service_packages = try duplicateRawServicePackages(allocator, raw.service_packages),
633
+ .service_carrier = try allocator.dupe(u8, raw.service_carrier),
634
+ .service_pool_size = if (raw.service_pool_size == 0) null else raw.service_pool_size,
574
635
  .bridge_commands = try convertRawBridgeCommands(allocator, raw.bridge.commands),
575
636
  .web_engine = try allocator.dupe(u8, raw.web_engine),
576
637
  .webview_layer = try allocator.dupe(u8, raw.webview_layer),
@@ -592,6 +653,57 @@ pub fn parseText(allocator: std.mem.Allocator, source: []const u8) !Metadata {
592
653
  };
593
654
  }
594
655
 
656
+ fn duplicateRawServicePackages(allocator: std.mem.Allocator, packages: []const raw_manifest.RawServicePackage) ![]const ServicePackageMetadata {
657
+ if (packages.len == 0) return &.{};
658
+ const out = try allocator.alloc(ServicePackageMetadata, packages.len);
659
+ for (packages, 0..) |package_entry, index| out[index] = .{
660
+ .name = try allocator.dupe(u8, package_entry.name),
661
+ .version = try allocator.dupe(u8, package_entry.version),
662
+ .content_hash = try allocator.dupe(u8, package_entry.content_hash),
663
+ };
664
+ return out;
665
+ }
666
+
667
+ fn validServicePackages(packages: []const ServicePackageMetadata) bool {
668
+ for (packages, 0..) |package_entry, index| {
669
+ if (!validNpmPackageName(package_entry.name) or !exactPackageVersion(package_entry.version) or package_entry.content_hash.len != 64) return false;
670
+ for (package_entry.content_hash) |byte| if (!(std.ascii.isDigit(byte) or (byte >= 'a' and byte <= 'f'))) return false;
671
+ for (packages[0..index]) |earlier| if (std.mem.eql(u8, earlier.name, package_entry.name)) return false;
672
+ }
673
+ return true;
674
+ }
675
+
676
+ fn validServiceCarrier(value: []const u8) bool {
677
+ return std.mem.eql(u8, value, "auto") or std.mem.eql(u8, value, "in_process") or std.mem.eql(u8, value, "child");
678
+ }
679
+
680
+ fn validNpmPackageName(name: []const u8) bool {
681
+ if (name.len == 0) return false;
682
+ const plain = struct {
683
+ fn valid(value: []const u8) bool {
684
+ if (value.len == 0) return false;
685
+ for (value) |byte| if (!(std.ascii.isAlphanumeric(byte) or byte == '.' or byte == '_' or byte == '-')) return false;
686
+ return true;
687
+ }
688
+ }.valid;
689
+ if (name[0] != '@') return plain(name);
690
+ const slash = std.mem.indexOfScalar(u8, name, '/') orelse return false;
691
+ return slash > 1 and slash + 1 < name.len and
692
+ std.mem.indexOfScalar(u8, name[slash + 1 ..], '/') == null and
693
+ plain(name[1..slash]) and plain(name[slash + 1 ..]);
694
+ }
695
+
696
+ fn exactPackageVersion(version: []const u8) bool {
697
+ var parts = std.mem.splitScalar(u8, version, '.');
698
+ var count: usize = 0;
699
+ while (parts.next()) |part| {
700
+ if (part.len == 0) return false;
701
+ for (part) |byte| if (!std.ascii.isDigit(byte)) return false;
702
+ count += 1;
703
+ }
704
+ return count == 3;
705
+ }
706
+
595
707
  fn convertRawDmg(allocator: std.mem.Allocator, dmg: RawDmg) !DmgMetadata {
596
708
  return .{
597
709
  .volume_name = try duplicateOptionalString(allocator, dmg.volume_name),
@@ -684,6 +796,33 @@ fn convertRawFrontend(allocator: std.mem.Allocator, frontend: ?RawFrontend) !?Fr
684
796
  };
685
797
  }
686
798
 
799
+ fn duplicateRawPersist(allocator: std.mem.Allocator, raw: ?raw_manifest.RawPersist) !?PersistMetadata {
800
+ const persist = raw orelse return null;
801
+ const ok = try allocator.dupe(u8, persist.restore.ok);
802
+ errdefer allocator.free(ok);
803
+ const none = try allocator.dupe(u8, persist.restore.none);
804
+ errdefer allocator.free(none);
805
+ const err = try allocator.dupe(u8, persist.restore.err);
806
+ return .{
807
+ .version = persist.version,
808
+ .debounce_ms = persist.debounce_ms,
809
+ .restore = .{ .ok = ok, .none = none, .err = err },
810
+ };
811
+ }
812
+
813
+ fn convertPersist(persist: ?PersistMetadata) ?app_manifest.PersistConfig {
814
+ const value = persist orelse return null;
815
+ return .{
816
+ .version = value.version,
817
+ .debounce_ms = value.debounce_ms,
818
+ .restore = .{
819
+ .ok = value.restore.ok,
820
+ .none = value.restore.none,
821
+ .err = value.restore.err,
822
+ },
823
+ };
824
+ }
825
+
687
826
  fn convertRawSecurity(allocator: std.mem.Allocator, security: RawSecurity) !SecurityMetadata {
688
827
  const external_action = if (security.navigation.external_links.allowed_urls.len == 0 and
689
828
  std.mem.eql(u8, security.navigation.external_links.action, "deny"))
@@ -719,6 +858,8 @@ fn convertRawWindows(allocator: std.mem.Allocator, windows: []const RawWindow) !
719
858
  .always_on_top = window.always_on_top,
720
859
  .click_through = window.click_through,
721
860
  .activate_on_show = window.activate_on_show,
861
+ .initially_hidden = window.initially_hidden,
862
+ .allows_fullscreen = window.allows_fullscreen,
722
863
  .min_width = window.min_width,
723
864
  .min_height = window.min_height,
724
865
  .close_policy = try allocator.dupe(u8, window.close_policy),
@@ -776,6 +917,8 @@ fn convertRawShellWindows(allocator: std.mem.Allocator, windows: []const RawShel
776
917
  .always_on_top = window.always_on_top,
777
918
  .click_through = window.click_through,
778
919
  .activate_on_show = window.activate_on_show,
920
+ .initially_hidden = window.initially_hidden,
921
+ .allows_fullscreen = window.allows_fullscreen,
779
922
  .min_width = window.min_width,
780
923
  .min_height = window.min_height,
781
924
  .close_policy = try allocator.dupe(u8, window.close_policy),
@@ -980,6 +1123,8 @@ fn convertWindows(allocator: std.mem.Allocator, windows: []const WindowMetadata)
980
1123
  .always_on_top = window.always_on_top,
981
1124
  .click_through = window.click_through,
982
1125
  .activate_on_show = window.activate_on_show,
1126
+ .initially_hidden = window.initially_hidden,
1127
+ .allows_fullscreen = window.allows_fullscreen,
983
1128
  .min_width = try parseWindowMinSize(window.min_width),
984
1129
  .min_height = try parseWindowMinSize(window.min_height),
985
1130
  .close_policy = try parseClosePolicy(window.close_policy),
@@ -1024,6 +1169,8 @@ fn parseShell(allocator: std.mem.Allocator, shell: ShellMetadata) !app_manifest.
1024
1169
  .always_on_top = window.always_on_top,
1025
1170
  .click_through = window.click_through,
1026
1171
  .activate_on_show = window.activate_on_show,
1172
+ .initially_hidden = window.initially_hidden,
1173
+ .allows_fullscreen = window.allows_fullscreen,
1027
1174
  .min_width = min_width,
1028
1175
  .min_height = min_height,
1029
1176
  .close_policy = close_policy,
@@ -1235,6 +1382,9 @@ fn parseCapability(value: []const u8) !app_manifest.Capability {
1235
1382
  if (std.mem.eql(u8, value, "dialog")) return .dialog;
1236
1383
  if (std.mem.eql(u8, value, "clipboard")) return .clipboard;
1237
1384
  if (std.mem.eql(u8, value, "credentials")) return .credentials;
1385
+ if (std.mem.eql(u8, value, "persist")) return .persist;
1386
+ if (std.mem.eql(u8, value, "store")) return .store;
1387
+ if (std.mem.eql(u8, value, "sqlite")) return .sqlite;
1238
1388
  if (std.mem.eql(u8, value, "open_url")) return .open_url;
1239
1389
  if (std.mem.eql(u8, value, "reveal_path")) return .reveal_path;
1240
1390
  if (std.mem.eql(u8, value, "recent_documents")) return .recent_documents;
@@ -2357,6 +2507,62 @@ test "manifest metadata parser reads identity version and lists" {
2357
2507
  });
2358
2508
  }
2359
2509
 
2510
+ test "manifest metadata parser carries model persistence configuration" {
2511
+ const metadata = try parseText(std.testing.allocator,
2512
+ \\.{
2513
+ \\ .id = "com.example.persisted",
2514
+ \\ .name = "persisted",
2515
+ \\ .version = "1.0.0",
2516
+ \\ .capabilities = .{ "persist" },
2517
+ \\ .persist = .{
2518
+ \\ .version = 3,
2519
+ \\ .debounce_ms = 250,
2520
+ \\ .restore = .{ .ok = "restored", .none = "fresh_boot", .err = "restore_failed" },
2521
+ \\ },
2522
+ \\}
2523
+ );
2524
+ defer metadata.deinit(std.testing.allocator);
2525
+ const persist = metadata.persist.?;
2526
+ try std.testing.expectEqual(@as(u64, 3), persist.version);
2527
+ try std.testing.expectEqual(@as(u32, 250), persist.debounce_ms);
2528
+ try std.testing.expectEqualStrings("restored", persist.restore.ok);
2529
+ try std.testing.expectEqualStrings("fresh_boot", persist.restore.none);
2530
+ try std.testing.expectEqualStrings("restore_failed", persist.restore.err);
2531
+
2532
+ const capabilities = try parseCapabilities(std.testing.allocator, metadata.capabilities);
2533
+ defer std.testing.allocator.free(capabilities);
2534
+ try app_manifest.validatePersist(convertPersist(metadata.persist), capabilities);
2535
+ try std.testing.expectError(error.MissingRequiredField, app_manifest.validatePersist(convertPersist(metadata.persist), &.{}));
2536
+ }
2537
+
2538
+ test "manifest metadata carries exact hash-pinned service packages" {
2539
+ const metadata = try parseText(std.testing.allocator,
2540
+ \\.{
2541
+ \\ .id = "com.example.services",
2542
+ \\ .name = "services",
2543
+ \\ .version = "1.0.0",
2544
+ \\ .service_packages = .{
2545
+ \\ .{ .name = "escape-string-regexp", .version = "5.0.0", .content_hash = "705f4bb4b92fd3469e264a93f2a2e4b24cf7e663d73a5318abaf29ee72674f6d" },
2546
+ \\ .{ .name = "@scope/parser", .version = "1.2.3", .content_hash = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" },
2547
+ \\ },
2548
+ \\}
2549
+ );
2550
+ defer metadata.deinit(std.testing.allocator);
2551
+ try std.testing.expect(validServicePackages(metadata.service_packages));
2552
+ try std.testing.expectEqual(@as(usize, 2), metadata.service_packages.len);
2553
+ try std.testing.expectEqualStrings("@scope/parser", metadata.service_packages[1].name);
2554
+ try std.testing.expect(!exactPackageVersion("1..2"));
2555
+ try std.testing.expect(!validNpmPackageName("package@range"));
2556
+ }
2557
+
2558
+ test "manifest capability parser recognizes both shared SQLite tiers" {
2559
+ const values = [_][]const u8{ "store", "sqlite" };
2560
+ const capabilities = try parseCapabilities(std.testing.allocator, &values);
2561
+ defer std.testing.allocator.free(capabilities);
2562
+ try std.testing.expectEqual(app_manifest.CapabilityKind.store, capabilities[0].kind());
2563
+ try std.testing.expectEqual(app_manifest.CapabilityKind.sqlite, capabilities[1].kind());
2564
+ }
2565
+
2360
2566
  test "manifest metadata parser reads structured security policy" {
2361
2567
  const metadata = try parseText(std.testing.allocator,
2362
2568
  \\.{
@@ -2529,13 +2735,13 @@ test "manifest parser reads window titlebar styles" {
2529
2735
  \\ .name = "example",
2530
2736
  \\ .version = "1.2.3",
2531
2737
  \\ .windows = .{
2532
- \\ .{ .label = "main", .resizable = false, .titlebar = "hidden_inset", .transparent = true, .always_on_top = true, .click_through = true, .activate_on_show = false },
2738
+ \\ .{ .label = "main", .resizable = false, .titlebar = "hidden_inset", .transparent = true, .always_on_top = true, .click_through = true, .activate_on_show = false, .initially_hidden = true, .allows_fullscreen = false },
2533
2739
  \\ .{ .label = "tall", .titlebar = "hidden_inset_tall" },
2534
2740
  \\ .{ .label = "skinned", .titlebar = "chromeless" },
2535
2741
  \\ },
2536
2742
  \\ .shell = .{
2537
2743
  \\ .windows = .{
2538
- \\ .{ .label = "scene", .titlebar = "hidden_inset_tall", .transparent = true, .always_on_top = true, .click_through = true, .activate_on_show = false, .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
2744
+ \\ .{ .label = "scene", .titlebar = "hidden_inset_tall", .transparent = true, .always_on_top = true, .click_through = true, .activate_on_show = false, .initially_hidden = true, .allows_fullscreen = false, .views = .{ .{ .label = "content", .kind = "webview", .url = "zero://app/index.html" } } },
2539
2745
  \\ },
2540
2746
  \\ },
2541
2747
  \\}
@@ -2548,6 +2754,8 @@ test "manifest parser reads window titlebar styles" {
2548
2754
  try std.testing.expect(metadata.windows[0].always_on_top);
2549
2755
  try std.testing.expect(metadata.windows[0].click_through);
2550
2756
  try std.testing.expect(!metadata.windows[0].activate_on_show);
2757
+ try std.testing.expect(metadata.windows[0].initially_hidden);
2758
+ try std.testing.expect(!metadata.windows[0].allows_fullscreen);
2551
2759
  try std.testing.expectEqualStrings("hidden_inset_tall", metadata.windows[1].titlebar);
2552
2760
  try std.testing.expectEqualStrings("chromeless", metadata.windows[2].titlebar);
2553
2761
  try std.testing.expectEqualStrings("hidden_inset_tall", metadata.shell.windows[0].titlebar);
@@ -2560,6 +2768,8 @@ test "manifest parser reads window titlebar styles" {
2560
2768
  try std.testing.expect(windows[0].always_on_top);
2561
2769
  try std.testing.expect(windows[0].click_through);
2562
2770
  try std.testing.expect(!windows[0].activate_on_show);
2771
+ try std.testing.expect(windows[0].initially_hidden);
2772
+ try std.testing.expect(!windows[0].allows_fullscreen);
2563
2773
  try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.hidden_inset_tall, windows[1].titlebar);
2564
2774
  try std.testing.expectEqual(app_manifest.WindowTitlebarStyle.chromeless, windows[2].titlebar);
2565
2775
 
@@ -2570,6 +2780,8 @@ test "manifest parser reads window titlebar styles" {
2570
2780
  try std.testing.expect(shell.windows[0].always_on_top);
2571
2781
  try std.testing.expect(shell.windows[0].click_through);
2572
2782
  try std.testing.expect(!shell.windows[0].activate_on_show);
2783
+ try std.testing.expect(shell.windows[0].initially_hidden);
2784
+ try std.testing.expect(!shell.windows[0].allows_fullscreen);
2573
2785
  }
2574
2786
 
2575
2787
  test "manifest parser reads window min sizes" {