@native-sdk/cli 0.9.4 → 0.9.5

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 (70) hide show
  1. package/README.md +3 -3
  2. package/build/app.zig +68 -57
  3. package/build.zig +12 -1
  4. package/package.json +10 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
  8. package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
  9. package/packages/core/scripts/vendor_service_packages.mjs +121 -8
  10. package/packages/core/sdk/events.d.ts +33 -4
  11. package/packages/core/sdk/events.ts +45 -6
  12. package/packages/core/src/checker.ts +103 -8
  13. package/packages/core/src/modules.ts +6 -2
  14. package/packages/core/src/sqlite_cli.ts +22 -2
  15. package/packages/core/src/typed_ast.ts +4 -2
  16. package/packages/core/src/types.ts +8 -8
  17. package/schemas/app.schema.json +435 -0
  18. package/skill-data/core/SKILL.md +53 -15
  19. package/skill-data/core/references/project-anatomy.md +6 -6
  20. package/skill-data/native-ui/SKILL.md +26 -5
  21. package/skill-data/ts-core/SKILL.md +6 -6
  22. package/skills/native-sdk/SKILL.md +2 -2
  23. package/src/automation/snapshot.zig +91 -3
  24. package/src/platform/macos/appkit_host.h +41 -2
  25. package/src/platform/macos/appkit_host.m +198 -9
  26. package/src/platform/macos/cef_host.mm +191 -9
  27. package/src/platform/macos/root.zig +110 -3
  28. package/src/platform/null_platform.zig +50 -1
  29. package/src/platform/null_platform_tests.zig +53 -0
  30. package/src/platform/root.zig +9 -0
  31. package/src/platform/types.zig +58 -0
  32. package/src/platform/windows/root.zig +88 -15
  33. package/src/primitives/canvas/reference.zig +37 -15
  34. package/src/primitives/canvas/reference_tests.zig +63 -0
  35. package/src/primitives/canvas/ui.zig +9 -0
  36. package/src/primitives/canvas/ui_markup.zig +29 -0
  37. package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
  38. package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
  39. package/src/primitives/canvas/ui_markup_contract.zig +7 -0
  40. package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
  41. package/src/primitives/canvas/ui_markup_tests.zig +6 -0
  42. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  43. package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
  44. package/src/primitives/canvas/ui_schema.zig +9 -0
  45. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  46. package/src/primitives/canvas/ui_tests.zig +4 -2
  47. package/src/primitives/canvas/widget_render.zig +7 -2
  48. package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
  49. package/src/root.zig +4 -0
  50. package/src/runtime/automation_snapshot.zig +3 -0
  51. package/src/runtime/flow.zig +1 -1
  52. package/src/runtime/state.zig +14 -0
  53. package/src/runtime/system_services.zig +62 -0
  54. package/src/runtime/ts_ui_app.zig +161 -33
  55. package/src/runtime/ui_app.zig +33 -1
  56. package/src/runtime/ui_app_tests.zig +63 -0
  57. package/src/runtime/validation.zig +87 -1
  58. package/src/tooling/android.zig +5 -4
  59. package/src/tooling/buildgraph.zig +24 -8
  60. package/src/tooling/db.zig +1 -1
  61. package/src/tooling/doctor.zig +1 -1
  62. package/src/tooling/ios.zig +5 -4
  63. package/src/tooling/json_to_zon.zig +136 -0
  64. package/src/tooling/manifest.zig +120 -33
  65. package/src/tooling/raw_manifest.zig +4 -0
  66. package/src/tooling/root.zig +1 -0
  67. package/src/tooling/templates.zig +165 -116
  68. package/src/tooling/ts_core.zig +11 -7
  69. package/src/tooling/verbs.zig +7 -6
  70. package/src/tooling/web_engine.zig +17 -1
@@ -54,7 +54,7 @@ pub const Frontend = enum {
54
54
  };
55
55
 
56
56
  /// Scaffold shape for the native frontend. `slim` is the zero-config
57
- /// default: app.zon + src/ + assets + README only — the `native` CLI owns
57
+ /// default: app.json + src/ + assets + README only — the `native` CLI owns
58
58
  /// the build graph (`native dev|build|test`) and `native eject` writes an
59
59
  /// owned build.zig later. `full` keeps the pre-zero-config shape
60
60
  /// (build.zig, build.zig.zon, .vscode, CI workflow) for users who want to
@@ -132,8 +132,8 @@ pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []
132
132
  defer allocator.free(build_zon);
133
133
  const main_zig = try mainZig(allocator, names, options.frontend);
134
134
  defer allocator.free(main_zig);
135
- const app_zon = try appZon(allocator, names, options.frontend);
136
- defer allocator.free(app_zon);
135
+ const app_json = try appJson(allocator, names, options.frontend);
136
+ defer allocator.free(app_json);
137
137
  const readme_md = try readme(allocator, names, framework_path, options.frontend);
138
138
  defer allocator.free(readme_md);
139
139
  const ci_yaml = try frontendCiYaml(allocator, names);
@@ -144,7 +144,7 @@ pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []
144
144
  try writeFile(app_dir, io, "build.zig.zon", build_zon);
145
145
  try writeFile(app_dir, io, "src/main.zig", main_zig);
146
146
  try writeFile(app_dir, io, "src/runner.zig", runnerZig());
147
- try writeFile(app_dir, io, "app.zon", app_zon);
147
+ try writeFile(app_dir, io, "app.json", app_json);
148
148
  try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
149
149
  try writeFile(app_dir, io, ".github/workflows/ci.yml", ci_yaml);
150
150
  try writeFile(app_dir, io, "README.md", readme_md);
@@ -159,15 +159,15 @@ fn writeNativeAppSlim(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.
159
159
  defer allocator.free(main_zig);
160
160
  const tests_zig = try nativeTestsZig(allocator, names);
161
161
  defer allocator.free(tests_zig);
162
- const app_zon = try nativeAppZon(allocator, names);
163
- defer allocator.free(app_zon);
162
+ const app_json = try nativeAppJson(allocator, names);
163
+ defer allocator.free(app_json);
164
164
  const readme_md = try slimNativeReadme(allocator, names);
165
165
  defer allocator.free(readme_md);
166
166
 
167
167
  try writeFile(app_dir, io, "src/main.zig", main_zig);
168
168
  try writeFile(app_dir, io, "src/app.native", nativeAppMarkup());
169
169
  try writeFile(app_dir, io, "src/tests.zig", tests_zig);
170
- try writeFile(app_dir, io, "app.zon", app_zon);
170
+ try writeFile(app_dir, io, "app.json", app_json);
171
171
  try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
172
172
  try writeFile(app_dir, io, ".gitignore", slimGitignore());
173
173
  try writeFile(app_dir, io, "README.md", readme_md);
@@ -183,7 +183,7 @@ fn slimGitignore() []const u8 {
183
183
  }
184
184
 
185
185
  /// The TypeScript-core zero-config scaffold - the `native init` default:
186
- /// core.ts (logic), app.native (view), app.zon (manifest). ZERO Zig in the
186
+ /// core.ts (logic), app.native (view), app.json (manifest). ZERO Zig in the
187
187
  /// tree; the build graph detects src/core.ts, compiles it through the
188
188
  /// external core compiler, and stages the generated wiring outside the app
189
189
  /// on every build.
@@ -195,14 +195,14 @@ fn slimGitignore() []const u8 {
195
195
  /// detection above keys on src/core.ts alone, and every `native` verb
196
196
  /// works with node_modules deleted.
197
197
  fn writeTsAppSlim(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, destination: []const u8, sdk_source: []const u8) !void {
198
- const app_zon = try nativeAppZon(allocator, names);
199
- defer allocator.free(app_zon);
198
+ const app_json = try nativeAppJson(allocator, names);
199
+ defer allocator.free(app_json);
200
200
  const readme_md = try tsSlimReadme(allocator, names);
201
201
  defer allocator.free(readme_md);
202
202
 
203
203
  try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
204
204
  try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
205
- try writeFile(app_dir, io, "app.zon", app_zon);
205
+ try writeFile(app_dir, io, "app.json", app_json);
206
206
  try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
207
207
  try writeFile(app_dir, io, ".gitignore", tsGitignore());
208
208
  try writeFile(app_dir, io, "README.md", readme_md);
@@ -218,8 +218,8 @@ fn writeTsApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, nam
218
218
  defer allocator.free(build_zig);
219
219
  const build_zon = try nativeBuildZon(allocator, names, framework_path);
220
220
  defer allocator.free(build_zon);
221
- const app_zon = try nativeAppZon(allocator, names);
222
- defer allocator.free(app_zon);
221
+ const app_json = try nativeAppJson(allocator, names);
222
+ defer allocator.free(app_json);
223
223
  const readme_md = try tsSlimReadme(allocator, names);
224
224
  defer allocator.free(readme_md);
225
225
  const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .ts);
@@ -231,7 +231,7 @@ fn writeTsApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, nam
231
231
  try writeFile(app_dir, io, "build.zig.zon", build_zon);
232
232
  try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
233
233
  try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
234
- try writeFile(app_dir, io, "app.zon", app_zon);
234
+ try writeFile(app_dir, io, "app.json", app_json);
235
235
  try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
236
236
  try writeFile(app_dir, io, ".gitignore", tsGitignore());
237
237
  try writeFile(app_dir, io, "README.md", readme_md);
@@ -472,13 +472,13 @@ fn tsSlimReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
472
472
  \\ # dispatch messages as JSON lines, watch the model
473
473
  \\ # and effect transcript (not a renderer)
474
474
  \\native dev # build and run the real app (markup hot reload)
475
- \\native check # verify core.ts (subset checker) + markup + app.zon
475
+ \\native check # verify core.ts (subset checker) + markup + app.json
476
476
  \\native build # ReleaseFast binary in zig-out/bin/
477
477
  \\native test # the app's test suite
478
478
  \\```
479
479
  \\
480
480
  \\Edit `src/core.ts` for behavior, `src/app.native` for the view, and
481
- \\`app.zon` for windows/identity/permissions. Markup binds the model's
481
+ \\`app.json` for windows/identity/permissions. Markup binds the model's
482
482
  \\field names exactly as core.ts wrote them (`tickCount` -> `{tickCount}`),
483
483
  \\and exported single-model helpers bind as derived values (`{total}`).
484
484
  \\
@@ -530,7 +530,7 @@ fn slimNativeReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const
530
530
  \\native dev # build and run the app with hot reload
531
531
  \\native test # run the app's test suite
532
532
  \\native build # produce a ReleaseFast binary in zig-out/bin/
533
- \\native check # validate src/*.native markup and app.zon
533
+ \\native check # validate src/*.native markup and app.json
534
534
  \\```
535
535
  \\
536
536
  \\## Hot reload
@@ -561,8 +561,8 @@ fn writeNativeApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir,
561
561
  defer allocator.free(main_zig);
562
562
  const tests_zig = try nativeTestsZig(allocator, names);
563
563
  defer allocator.free(tests_zig);
564
- const app_zon = try nativeAppZon(allocator, names);
565
- defer allocator.free(app_zon);
564
+ const app_json = try nativeAppJson(allocator, names);
565
+ defer allocator.free(app_json);
566
566
  const readme_md = try nativeReadme(allocator, names, framework_path);
567
567
  defer allocator.free(readme_md);
568
568
  const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .zig);
@@ -573,7 +573,7 @@ fn writeNativeApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir,
573
573
  try writeFile(app_dir, io, "src/main.zig", main_zig);
574
574
  try writeFile(app_dir, io, "src/app.native", nativeAppMarkup());
575
575
  try writeFile(app_dir, io, "src/tests.zig", tests_zig);
576
- try writeFile(app_dir, io, "app.zon", app_zon);
576
+ try writeFile(app_dir, io, "app.json", app_json);
577
577
  try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
578
578
  try writeFile(app_dir, io, ".vscode/settings.json", nativeVscodeSettings());
579
579
  try writeFile(app_dir, io, ".github/workflows/ci.yml", ci_yaml);
@@ -594,7 +594,7 @@ fn nativeBuildZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
594
594
  try out.appendSlice(allocator, " ");
595
595
  try appendZigString(&out, allocator, names.package_name);
596
596
  try out.appendSlice(allocator,
597
- \\ });
597
+ \\, .manifest = "app.json" });
598
598
  \\}
599
599
  \\
600
600
  );
@@ -626,7 +626,7 @@ fn nativeBuildZon(allocator: std.mem.Allocator, names: TemplateNames, framework_
626
626
  try appendZigString(&out, allocator, framework_path);
627
627
  try out.appendSlice(allocator,
628
628
  \\ } },
629
- \\ .paths = .{ "build.zig", "build.zig.zon", "src", "assets", "app.zon", "README.md" },
629
+ \\ .paths = .{ "build.zig", "build.zig.zon", "src", "assets", "app.json", "README.md" },
630
630
  \\}
631
631
  \\
632
632
  );
@@ -1023,61 +1023,62 @@ fn nativeTestsZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
1023
1023
  return out.toOwnedSlice(allocator);
1024
1024
  }
1025
1025
 
1026
- fn nativeAppZon(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
1026
+ fn nativeAppJson(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
1027
1027
  var out: std.ArrayList(u8) = .empty;
1028
1028
  errdefer out.deinit(allocator);
1029
1029
  try out.appendSlice(allocator,
1030
- \\.{
1031
- \\ .id =
1030
+ \\{
1031
+ \\ "$schema": "https://schema.native-sdk.dev/app/v1.json",
1032
+ \\ "id":
1032
1033
  );
1033
1034
  try out.appendSlice(allocator, " ");
1034
- try appendZigString(&out, allocator, names.app_id);
1035
+ try appendJsonString(&out, allocator, names.app_id);
1035
1036
  try out.appendSlice(allocator,
1036
1037
  \\,
1037
- \\ .name =
1038
+ \\ "name":
1038
1039
  );
1039
1040
  try out.appendSlice(allocator, " ");
1040
- try appendZigString(&out, allocator, names.package_name);
1041
+ try appendJsonString(&out, allocator, names.package_name);
1041
1042
  try out.appendSlice(allocator,
1042
1043
  \\,
1043
- \\ .display_name =
1044
+ \\ "display_name":
1044
1045
  );
1045
1046
  try out.appendSlice(allocator, " ");
1046
- try appendZigString(&out, allocator, names.display_name);
1047
+ try appendJsonString(&out, allocator, names.display_name);
1047
1048
  try out.appendSlice(allocator,
1048
1049
  \\,
1049
- \\ .description = "A counter that lives in one native window.",
1050
- \\ .version = "0.1.0",
1051
- \\ .icons = .{"assets/icon.png"},
1052
- \\ .platforms = .{"macos"},
1053
- \\ .permissions = .{ "view", "command" },
1054
- \\ .capabilities = .{ "native_views", "gpu_surfaces" },
1055
- \\ .shell = .{
1056
- \\ .windows = .{
1057
- \\ .{
1058
- \\ .label = "main",
1059
- \\ .title =
1050
+ \\ "description": "A counter that lives in one native window.",
1051
+ \\ "version": "0.1.0",
1052
+ \\ "icons": ["assets/icon.png"],
1053
+ \\ "platforms": ["macos"],
1054
+ \\ "permissions": ["view", "command"],
1055
+ \\ "capabilities": ["native_views", "gpu_surfaces"],
1056
+ \\ "shell": {
1057
+ \\ "windows": [
1058
+ \\ {
1059
+ \\ "label": "main",
1060
+ \\ "title":
1060
1061
  );
1061
1062
  try out.appendSlice(allocator, " ");
1062
- try appendZigString(&out, allocator, names.display_name);
1063
+ try appendJsonString(&out, allocator, names.display_name);
1063
1064
  try out.appendSlice(allocator,
1064
1065
  \\,
1065
- \\ .width = 480,
1066
- \\ .height = 320,
1067
- \\ .views = .{
1068
- \\ .{ .label = "main-canvas", .kind = "gpu_surface", .fill = true, .role = "Counter canvas", .accessibility_label = "Counter", .gpu_backend = "metal", .gpu_pixel_format = "bgra8_unorm", .gpu_present_mode = "timer", .gpu_alpha_mode = "opaque", .gpu_color_space = "srgb", .gpu_vsync = true },
1069
- \\ },
1070
- \\ },
1071
- \\ },
1066
+ \\ "width": 480,
1067
+ \\ "height": 320,
1068
+ \\ "views": [
1069
+ \\ { "label": "main-canvas", "kind": "gpu_surface", "fill": true, "role": "Counter canvas", "accessibility_label": "Counter", "gpu_backend": "metal", "gpu_pixel_format": "bgra8_unorm", "gpu_present_mode": "timer", "gpu_alpha_mode": "opaque", "gpu_color_space": "srgb", "gpu_vsync": true }
1070
+ \\ ]
1071
+ \\ }
1072
+ \\ ]
1072
1073
  \\ },
1073
- \\ .security = .{
1074
- \\ .navigation = .{
1075
- \\ .allowed_origins = .{ "zero://app", "zero://inline" },
1076
- \\ .external_links = .{ .action = "deny" },
1077
- \\ },
1074
+ \\ "security": {
1075
+ \\ "navigation": {
1076
+ \\ "allowed_origins": ["zero://app", "zero://inline"],
1077
+ \\ "external_links": { "action": "deny" }
1078
+ \\ }
1078
1079
  \\ },
1079
- \\ .web_engine = "system",
1080
- \\ .cef = .{ .dir = "third_party/cef/macos", .auto_install = false },
1080
+ \\ "web_engine": "system",
1081
+ \\ "cef": { "dir": "third_party/cef/macos", "auto_install": false }
1081
1082
  \\}
1082
1083
  \\
1083
1084
  );
@@ -1463,7 +1464,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1463
1464
  \\ const runner_mod = localModule(b, target, optimize, "src/runner.zig");
1464
1465
  \\ runner_mod.addImport("native_sdk", native_sdk_mod);
1465
1466
  \\ runner_mod.addImport("build_options", options_mod);
1466
- \\ runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("app.zon") }));
1467
+ \\ runner_mod.addImport("app_manifest_zon", appManifestModule(b));
1467
1468
  \\ const migrations_mod = b.createModule(.{ .root_source_file = relational_migrations_source, .target = target, .optimize = optimize });
1468
1469
  \\ migrations_mod.addImport("native_sdk", native_sdk_mod);
1469
1470
  \\ runner_mod.addImport("relational_migrations", migrations_mod);
@@ -1512,7 +1513,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1512
1513
  \\ const run_step = b.step("run", "Run the app");
1513
1514
  \\ run_step.dependOn(&run.step);
1514
1515
  \\
1515
- \\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.zon", "--binary" });
1516
+ \\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.json", "--binary" });
1516
1517
  \\ dev.addFileArg(exe.getEmittedBin());
1517
1518
  \\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, web_layer, native_sdk_path);
1518
1519
  \\ dev.step.dependOn(&exe.step);
@@ -1530,7 +1531,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1530
1531
  \\ const package_runner_mod = localModule(b, target, package_optimize, "src/runner.zig");
1531
1532
  \\ package_runner_mod.addImport("native_sdk", package_sdk_mod);
1532
1533
  \\ package_runner_mod.addImport("build_options", options_mod);
1533
- \\ package_runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("app.zon") }));
1534
+ \\ package_runner_mod.addImport("app_manifest_zon", appManifestModule(b));
1534
1535
  \\ const package_migrations_mod = b.createModule(.{ .root_source_file = relational_migrations_source, .target = target, .optimize = package_optimize });
1535
1536
  \\ package_migrations_mod.addImport("native_sdk", package_sdk_mod);
1536
1537
  \\ package_runner_mod.addImport("relational_migrations", package_migrations_mod);
@@ -1561,7 +1562,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1561
1562
  \\ "--target",
1562
1563
  \\ @tagName(package_target),
1563
1564
  \\ "--manifest",
1564
- \\ "app.zon",
1565
+ \\ "app.json",
1565
1566
  \\ "--assets",
1566
1567
  );
1567
1568
  try appendZigString(&out, allocator, frontend.distDir());
@@ -2089,10 +2090,10 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
2089
2090
  \\ // The fallback for a manifest this lenient parse cannot read
2090
2091
  \\ // keeps the web layer (see AppManifestBuildConfig): a shape
2091
2092
  \\ // mismatch here is not proof the app declares no web use.
2092
- \\ const fallback: AppManifestBuildConfig = .{ .web_declaration = "an app.zon this build graph could not parse" };
2093
- \\ const source: [:0]const u8 = @embedFile("app.zon");
2093
+ \\ const fallback: AppManifestBuildConfig = .{ .web_declaration = "an app.json this build graph could not parse" };
2094
+ \\ const source = @embedFile("app.json");
2094
2095
  \\ @setEvalBranchQuota(4000);
2095
- \\ const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source, null, .{ .ignore_unknown_fields = true }) catch return fallback;
2096
+ \\ const raw = std.json.parseFromSliceLeaky(InferenceManifest, b.allocator, source, .{ .ignore_unknown_fields = true }) catch return fallback;
2096
2097
  \\ var config: AppManifestBuildConfig = .{
2097
2098
  \\ .web_engine = parseWebEngine(raw.web_engine) orelse .system,
2098
2099
  \\ .cef_dir = raw.cef.dir,
@@ -2119,6 +2120,49 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
2119
2120
  \\ return config;
2120
2121
  \\}
2121
2122
  \\
2123
+ \\fn appManifestModule(b: *std.Build) *std.Build.Module {
2124
+ \\ const root = std.json.parseFromSliceLeaky(std.json.Value, b.allocator, @embedFile("app.json"), .{ .parse_numbers = false }) catch
2125
+ \\ @panic("cannot parse app.json; run `native check` for a precise diagnostic");
2126
+ \\ if (root != .object) @panic("app.json must contain one object");
2127
+ \\ var out = std.Io.Writer.Allocating.init(b.allocator);
2128
+ \\ writeManifestValue(&out.writer, root, 0) catch |err| switch (err) {
2129
+ \\ error.NullNotAllowed => @panic("app.json cannot contain null values; omit optional fields instead"),
2130
+ \\ else => @panic("out of memory converting app.json"),
2131
+ \\ };
2132
+ \\ const generated = b.addWriteFiles().add("app_manifest.zon", out.written());
2133
+ \\ return b.createModule(.{ .root_source_file = generated });
2134
+ \\}
2135
+ \\
2136
+ \\fn writeManifestValue(writer: *std.Io.Writer, value: std.json.Value, depth: usize) !void {
2137
+ \\ switch (value) {
2138
+ \\ .null => return error.NullNotAllowed,
2139
+ \\ .bool => |v| try writer.writeAll(if (v) "true" else "false"),
2140
+ \\ .integer => |v| try writer.print("{d}", .{v}),
2141
+ \\ .float => |v| try writer.print("{d}", .{v}),
2142
+ \\ .number_string => |v| try writer.writeAll(v),
2143
+ \\ .string => |v| try writer.print("\"{f}\"", .{std.zig.fmtString(v)}),
2144
+ \\ .array => |array| {
2145
+ \\ try writer.writeAll(".{");
2146
+ \\ for (array.items) |item| {
2147
+ \\ try writeManifestValue(writer, item, depth + 1);
2148
+ \\ try writer.writeByte(',');
2149
+ \\ }
2150
+ \\ try writer.writeByte('}');
2151
+ \\ },
2152
+ \\ .object => |object| {
2153
+ \\ try writer.writeAll(".{");
2154
+ \\ var iterator = object.iterator();
2155
+ \\ while (iterator.next()) |entry| {
2156
+ \\ if (depth == 0 and std.mem.eql(u8, entry.key_ptr.*, "$schema")) continue;
2157
+ \\ try writer.print(".{f}=", .{std.zig.fmtId(entry.key_ptr.*)});
2158
+ \\ try writeManifestValue(writer, entry.value_ptr.*, depth + 1);
2159
+ \\ try writer.writeByte(',');
2160
+ \\ }
2161
+ \\ try writer.writeByte('}');
2162
+ \\ },
2163
+ \\ }
2164
+ \\}
2165
+ \\
2122
2166
  \\fn hasManifestPermission(permissions: []const []const u8, name: []const u8) bool {
2123
2167
  \\ for (permissions) |permission| {
2124
2168
  \\ if (std.mem.eql(u8, permission, name)) return true;
@@ -2199,7 +2243,7 @@ fn buildZon(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
2199
2243
  \\ .version = "0.1.0",
2200
2244
  \\ .minimum_zig_version = "0.16.0",
2201
2245
  \\ .dependencies = .{},
2202
- \\ .paths = .{ "build.zig", "build.zig.zon", "src", "assets", "frontend", "app.zon", "README.md" },
2246
+ \\ .paths = .{ "build.zig", "build.zig.zon", "src", "assets", "frontend", "app.json", "README.md" },
2203
2247
  \\}
2204
2248
  \\
2205
2249
  );
@@ -3203,46 +3247,47 @@ fn runnerZig() []const u8 {
3203
3247
  ;
3204
3248
  }
3205
3249
 
3206
- fn appZon(allocator: std.mem.Allocator, names: TemplateNames, frontend: Frontend) ![]const u8 {
3250
+ fn appJson(allocator: std.mem.Allocator, names: TemplateNames, frontend: Frontend) ![]const u8 {
3207
3251
  var out: std.ArrayList(u8) = .empty;
3208
3252
  errdefer out.deinit(allocator);
3209
3253
  try out.appendSlice(allocator,
3210
- \\.{
3211
- \\ .id =
3254
+ \\{
3255
+ \\ "$schema": "https://schema.native-sdk.dev/app/v1.json",
3256
+ \\ "id":
3212
3257
  );
3213
- try appendZigString(&out, allocator, names.app_id);
3258
+ try appendJsonString(&out, allocator, names.app_id);
3214
3259
  try out.appendSlice(allocator,
3215
3260
  \\,
3216
- \\ .name =
3261
+ \\ "name":
3217
3262
  );
3218
- try appendZigString(&out, allocator, names.package_name);
3263
+ try appendJsonString(&out, allocator, names.package_name);
3219
3264
  try out.appendSlice(allocator,
3220
3265
  \\,
3221
- \\ .display_name =
3266
+ \\ "display_name":
3222
3267
  );
3223
- try appendZigString(&out, allocator, names.display_name);
3268
+ try appendJsonString(&out, allocator, names.display_name);
3224
3269
  try out.appendSlice(allocator,
3225
3270
  \\,
3226
- \\ .version = "0.1.0",
3227
- \\ .icons = .{ "assets/icon.png" },
3228
- \\ .platforms = .{ "macos", "linux" },
3229
- \\ .permissions = .{},
3230
- \\ .capabilities = .{ "webview" },
3231
- \\ .frontend = .{
3232
- \\ .dist =
3271
+ \\ "version": "0.1.0",
3272
+ \\ "icons": ["assets/icon.png"],
3273
+ \\ "platforms": ["macos", "linux"],
3274
+ \\ "permissions": [],
3275
+ \\ "capabilities": ["webview"],
3276
+ \\ "frontend": {
3277
+ \\ "dist":
3233
3278
  );
3234
- try appendZigString(&out, allocator, frontend.distDir());
3279
+ try appendJsonString(&out, allocator, frontend.distDir());
3235
3280
  try out.appendSlice(allocator,
3236
3281
  \\,
3237
- \\ .entry = "index.html",
3238
- \\ .spa_fallback = true,
3239
- \\ .dev = .{
3240
- \\ .url =
3282
+ \\ "entry": "index.html",
3283
+ \\ "spa_fallback": true,
3284
+ \\ "dev": {
3285
+ \\ "url":
3241
3286
  );
3242
- try appendZigString(&out, allocator, frontend.devUrl());
3287
+ try appendJsonString(&out, allocator, frontend.devUrl());
3243
3288
  try out.appendSlice(allocator,
3244
3289
  \\,
3245
- \\ .command = .{ "npm", "--prefix", "frontend", "run", "dev"
3290
+ \\ "command": ["npm", "--prefix", "frontend", "run", "dev"
3246
3291
  );
3247
3292
  if (frontend != .next) {
3248
3293
  try out.appendSlice(allocator,
@@ -3250,33 +3295,33 @@ fn appZon(allocator: std.mem.Allocator, names: TemplateNames, frontend: Frontend
3250
3295
  );
3251
3296
  }
3252
3297
  try out.appendSlice(allocator,
3253
- \\ },
3254
- \\ .ready_path = "/",
3255
- \\ .timeout_ms = 30000,
3256
- \\ },
3298
+ \\],
3299
+ \\ "ready_path": "/",
3300
+ \\ "timeout_ms": 30000
3301
+ \\ }
3257
3302
  \\ },
3258
- \\ .security = .{
3259
- \\ .navigation = .{
3260
- \\ .allowed_origins = .{ "zero://app", "zero://inline",
3303
+ \\ "security": {
3304
+ \\ "navigation": {
3305
+ \\ "allowed_origins": ["zero://app", "zero://inline",
3261
3306
  );
3262
3307
  try out.appendSlice(allocator, " ");
3263
3308
  const dev_origin = try std.fmt.allocPrint(allocator, "http://127.0.0.1:{s}", .{frontend.devPort()});
3264
3309
  defer allocator.free(dev_origin);
3265
- try appendZigString(&out, allocator, dev_origin);
3310
+ try appendJsonString(&out, allocator, dev_origin);
3266
3311
  try out.appendSlice(allocator,
3267
- \\ },
3268
- \\ .external_links = .{ .action = "deny" },
3269
- \\ },
3312
+ \\],
3313
+ \\ "external_links": { "action": "deny" }
3314
+ \\ }
3270
3315
  \\ },
3271
- \\ .web_engine = "system",
3272
- \\ .cef = .{ .dir = "third_party/cef/macos", .auto_install = false },
3273
- \\ .windows = .{
3274
- \\ .{ .label = "main", .title =
3316
+ \\ "web_engine": "system",
3317
+ \\ "cef": { "dir": "third_party/cef/macos", "auto_install": false },
3318
+ \\ "windows": [
3319
+ \\ { "label": "main", "title":
3275
3320
  );
3276
- try appendZigString(&out, allocator, names.display_name);
3321
+ try appendJsonString(&out, allocator, names.display_name);
3277
3322
  try out.appendSlice(allocator,
3278
- \\, .width = 720, .height = 480, .restore_state = true },
3279
- \\ },
3323
+ \\, "width": 720, "height": 480, "restore_state": true }
3324
+ \\ ]
3280
3325
  \\}
3281
3326
  \\
3282
3327
  );
@@ -4004,10 +4049,10 @@ fn readme(allocator: std.mem.Allocator, names: TemplateNames, framework_path: []
4004
4049
  \\zig build run
4005
4050
  \\zig build test
4006
4051
  \\zig build package
4007
- \\native doctor --manifest app.zon
4052
+ \\native doctor --manifest app.json
4008
4053
  \\```
4009
4054
  \\
4010
- \\`zig build dev` starts the frontend dev server from `app.zon`, waits for it, and launches the native shell with `NATIVE_SDK_FRONTEND_URL`.
4055
+ \\`zig build dev` starts the frontend dev server from `app.json`, waits for it, and launches the native shell with `NATIVE_SDK_FRONTEND_URL`.
4011
4056
  \\
4012
4057
  \\Frontend:
4013
4058
  \\
@@ -4089,7 +4134,7 @@ test "writeDefaultApp emits Vite project files" {
4089
4134
  const destination = ".zig-cache/test-vite-init-template";
4090
4135
  try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .vite });
4091
4136
 
4092
- const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
4137
+ const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.json");
4093
4138
  defer std.testing.allocator.free(app_zon_text);
4094
4139
  const build_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig");
4095
4140
  defer std.testing.allocator.free(build_zig_text);
@@ -4102,10 +4147,11 @@ test "writeDefaultApp emits Vite project files" {
4102
4147
  const main_js_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "frontend/src/main.js");
4103
4148
  defer std.testing.allocator.free(main_js_text);
4104
4149
 
4105
- try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".frontend") != null);
4150
+ try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"frontend\"") != null);
4106
4151
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "frontend/dist") != null);
4107
4152
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "npm") != null);
4108
- try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".windows") != null);
4153
+ try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"windows\"") != null);
4154
+ try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"$schema\": \"https://schema.native-sdk.dev/app/v1.json\"") != null);
4109
4155
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-install") != null);
4110
4156
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"install\", \"--prefix\", \"frontend\"") != null);
4111
4157
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-build") != null);
@@ -4148,7 +4194,10 @@ test "writeDefaultApp emits Vite project files" {
4148
4194
  // the packaged artifact structurally agrees with the compiled exe.
4149
4195
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addArgs(&.{ \"--web-layer\", if (web_layer) \"include\" else \"exclude\" })") != null);
4150
4196
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "options.addOption(bool, \"web_layer\", web_layer)") != null);
4151
- try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "std.zon.parse.fromSliceAlloc(InferenceManifest") != null);
4197
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "std.json.parseFromSliceLeaky(InferenceManifest") != null);
4198
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "fn appManifestModule") != null);
4199
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, ".{ .parse_numbers = false }") != null);
4200
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, ".null => return error.NullNotAllowed") != null);
4152
4201
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "the web layer is excluded ({s}) but the app declares web use ({s})") != null);
4153
4202
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, ".system => if (web_layer) {") != null);
4154
4203
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB\"") != null);
@@ -4292,7 +4341,7 @@ test "writeDefaultApp emits frontend-specific Next paths" {
4292
4341
  const destination = ".zig-cache/test-next-init-template";
4293
4342
  try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "Next App", .framework_path = ".", .frontend = .next });
4294
4343
 
4295
- const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
4344
+ const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.json");
4296
4345
  defer std.testing.allocator.free(app_zon_text);
4297
4346
  const build_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig");
4298
4347
  defer std.testing.allocator.free(build_zig_text);
@@ -4317,7 +4366,7 @@ test "writeDefaultApp emits the TS-core scaffold by default: three files of trut
4317
4366
  defer std.testing.allocator.free(core_text);
4318
4367
  const markup_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/app.native");
4319
4368
  defer std.testing.allocator.free(markup_text);
4320
- const ts_app_zon = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
4369
+ const ts_app_zon = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.json");
4321
4370
  defer std.testing.allocator.free(ts_app_zon);
4322
4371
  const ts_readme = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
4323
4372
  defer std.testing.allocator.free(ts_readme);
@@ -4410,7 +4459,7 @@ test "writeDefaultApp --template zig-core emits the slim Zig scaffold at ts-core
4410
4459
  const destination = ".zig-cache/test-native-slim-template";
4411
4460
  try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .core = .zig });
4412
4461
 
4413
- const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
4462
+ const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.json");
4414
4463
  defer std.testing.allocator.free(app_zon_text);
4415
4464
  const main_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/main.zig");
4416
4465
  defer std.testing.allocator.free(main_zig_text);
@@ -4467,7 +4516,7 @@ test "writeDefaultApp emits native project files" {
4467
4516
  const destination = ".zig-cache/test-native-init-template";
4468
4517
  try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full, .core = .zig });
4469
4518
 
4470
- const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
4519
+ const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.json");
4471
4520
  defer std.testing.allocator.free(app_zon_text);
4472
4521
  const build_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig");
4473
4522
  defer std.testing.allocator.free(build_zig_text);
@@ -4493,8 +4542,8 @@ test "writeDefaultApp emits native project files" {
4493
4542
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "gpu_surface") != null);
4494
4543
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"native_views\", \"gpu_surfaces\"") != null);
4495
4544
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "dev.native_sdk.my-app") != null);
4496
- try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".frontend") == null);
4497
- try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "native_sdk.addApp(b, b.dependency(\"native_sdk\", .{}), .{ .name = \"my-app\" })") != null);
4545
+ try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "\"frontend\"") == null);
4546
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "native_sdk.addApp(b, b.dependency(\"native_sdk\", .{}), .{ .name = \"my-app\", .manifest = \"app.json\" })") != null);
4498
4547
  try std.testing.expect(std.mem.indexOf(u8, build_zon_text, ".native_sdk = .{ .path = ") != null);
4499
4548
  try std.testing.expect(std.mem.indexOf(u8, build_zon_text, ".name = .my_app") != null);
4500
4549
  try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "native_sdk.UiApp(Model, Msg)") != null);
@@ -480,13 +480,17 @@ pub fn generateSqliteSurface(
480
480
  errdefer allocator.free(sdk_out);
481
481
  var child = std.process.spawn(io, .{
482
482
  .argv = &.{
483
- "node", runner, sqlite_cli,
484
- "--src", "src", "--sdk-in",
485
- sdk_in, "--static-in", static_in,
486
- "--sdk-out", sdk_out, "--dts-out",
487
- ".native/cache/sqlite/core.d.ts", "--static-out", ".native/cache/sqlite/core_static.ts",
488
- "--zig-out", ".native/cache/sqlite/migrations.zig", "--metadata-out",
489
- ".native/cache/sqlite/metadata.json", "--state", "src/schema/migrations.lock.json",
483
+ "node", runner, sqlite_cli,
484
+ "--src", "src", "--sdk-in",
485
+ sdk_in, "--static-in", static_in,
486
+ "--sdk-out", sdk_out, "--dts-out",
487
+ ".native/cache/sqlite/core.d.ts", "--static-out", ".native/cache/sqlite/core_static.ts",
488
+ "--sdk-events-out", ".native/cache/sqlite/events.ts", "--sdk-text-out",
489
+ ".native/cache/sqlite/text.ts", "--sdk-bytes-text-methods-out", ".native/cache/sqlite/bytes_text_methods.d.ts",
490
+ "--sdk-events-dts-out", ".native/cache/sqlite/events.d.ts", "--sdk-text-dts-out",
491
+ ".native/cache/sqlite/text.d.ts", "--zig-out", ".native/cache/sqlite/migrations.zig",
492
+ "--metadata-out", ".native/cache/sqlite/metadata.json", "--state",
493
+ "src/schema/migrations.lock.json",
490
494
  },
491
495
  .stdin = .ignore,
492
496
  .stdout = .inherit,