@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
package/README.md CHANGED
@@ -20,7 +20,7 @@ cd my_app
20
20
  native dev
21
21
  ```
22
22
 
23
- A native window opens with a working counter. The primary scaffold is three files of truth and no build config: `src/core.ts` (`Model`, `Msg`, `update`), `src/app.native` (the UI), and `app.zon` (the manifest). `native dev|build|test` own the generated build; `src/app.native` hot-reloads while the app runs, keeping your state; `native dev --core` runs the TypeScript logic loop under node; and `native check` validates the core and every view in milliseconds without building. Prefer a Zig core? Use `native init my_app --template zig-core`.
23
+ A native window opens with a working counter. The primary scaffold is three files of truth and no build config: `src/core.ts` (`Model`, `Msg`, `update`), `src/app.native` (the UI), and `app.json` (the manifest, with JSON Schema completion). Existing `app.zon` manifests remain supported. `native dev|build|test` own the generated build; `src/app.native` hot-reloads while the app runs, keeping your state; `native dev --core` runs the TypeScript logic loop under node; and `native check` validates the core and every view in milliseconds without building. Prefer a Zig core? Use `native init my_app --template zig-core`.
24
24
 
25
25
  When part of your product is the web, WebView surfaces coexist with the native canvas; web-frontend scaffolds (`--frontend next`, `--frontend vite`, and more) install their generated frontend dependencies automatically on first run.
26
26
 
@@ -34,11 +34,11 @@ Read the full guide at [native-sdk.dev/quick-start](https://native-sdk.dev/quick
34
34
  | `native dev [dir]` | Build and run the app (markup hot reload; managed frontend dev server when configured) |
35
35
  | `native build [dir]` | Build a ReleaseFast binary into `zig-out/bin/` |
36
36
  | `native test [dir]` | Run the app's test suite |
37
- | `native check [dir]` | Validate `src/**.native` markup and `app.zon` against the model contract |
37
+ | `native check [dir]` | Validate `src/**.native` markup and `app.json`/`app.zon` against the model contract |
38
38
  | `native markup check\|lsp` | Check individual markup files, or serve diagnostics, completion, and hover to your editor |
39
39
  | `native eject [dir]` | Write an owned build.zig/build.zig.zon into the app |
40
40
  | `native doctor` | Check host environment, WebView, manifest, and CEF |
41
- | `native validate` | Validate `app.zon` against the manifest schema |
41
+ | `native validate` | Validate `app.json` (or `app.zon`) against the manifest schema |
42
42
  | `native package` | Package the app for distribution |
43
43
  | `native bundle-assets` | Copy frontend assets into the build output |
44
44
  | `native automate` | Drive a running app: snapshots, widgets, assertions, screenshots, record/replay |
package/build/app.zig CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  const std = @import("std");
7
7
  const builtin = @import("builtin");
8
+ const json_to_zon = @import("../src/tooling/json_to_zon.zig");
8
9
 
9
10
  /// Canonicalize a generated file by its CONTENT before another build step
10
11
  /// consumes it. `std.Build.Step.Run` normally places outputs under a cache
@@ -121,6 +122,9 @@ const WebLayerOption = web_layer_contract.WebViewLayer;
121
122
 
122
123
  pub const AppOptions = struct {
123
124
  name: []const u8,
125
+ /// Explicit manifest path. Null auto-detects app.json first, then app.zon,
126
+ /// so older owned build.zig files can adopt JSON without a build edit.
127
+ manifest: ?[]const u8 = null,
124
128
  /// App entry point; defaults to src/main.zig (relative to `app_root`).
125
129
  main: []const u8 = "src/main.zig",
126
130
  /// Root of the app source tree, relative to the build root. "." for a
@@ -163,6 +167,34 @@ fn appFileExists(b: *std.Build, app_root: []const u8, sub_path: []const u8) bool
163
167
  return true;
164
168
  }
165
169
 
170
+ fn appManifestName(b: *std.Build, app_root: []const u8, requested: ?[]const u8) []const u8 {
171
+ if (requested) |name| return name;
172
+ if (appFileExists(b, app_root, "app.json")) return "app.json";
173
+ return "app.zon";
174
+ }
175
+
176
+ fn appManifestPath(b: *std.Build, app_root: []const u8, manifest_name: []const u8) []const u8 {
177
+ return appPath(b, app_root, manifest_name);
178
+ }
179
+
180
+ /// Produce the Zig module consumed by the existing comptime manifest wiring.
181
+ /// ZON manifests are already modules; JSON manifests are converted losslessly
182
+ /// into a generated module, keeping one runtime feature path for both formats.
183
+ fn appManifestModule(b: *std.Build, app_root: []const u8, manifest_name: []const u8) *std.Build.Module {
184
+ const path = appManifestPath(b, app_root, manifest_name);
185
+ if (!json_to_zon.isJsonPath(path)) {
186
+ return b.createModule(.{ .root_source_file = b.path(path) });
187
+ }
188
+ const source = b.build_root.handle.readFileAlloc(b.graph.io, path, b.allocator, .limited(1024 * 1024)) catch
189
+ @panic("cannot read app.json");
190
+ const zon = json_to_zon.convertAlloc(b.allocator, source) catch |err| switch (err) {
191
+ error.NullNotAllowed => @panic("app.json cannot contain null values; omit optional fields instead"),
192
+ else => @panic("cannot convert app.json into the build-time manifest module; run `native check` for a precise diagnostic"),
193
+ };
194
+ const generated = b.addWriteFiles().add("app_manifest.zon", zon);
195
+ return b.createModule(.{ .root_source_file = generated });
196
+ }
197
+
166
198
  const TsWindowView = struct {
167
199
  label: []const u8,
168
200
  source_path: []const u8,
@@ -676,48 +708,6 @@ fn tsParseQuotedManifestValue(manifest_json: []const u8, comptime key: []const u
676
708
  return suffix;
677
709
  }
678
710
 
679
- /// The external compiler's published `scriptc` binary entrypoint,
680
- /// resolved by node's ancestor node_modules walk from the SDK's
681
- /// packages/core — the same origin the frontend toolchain resolves from
682
- /// (tsAliasedCompilerVersion's walk, kept in lockstep). Repo checkouts
683
- /// install it there with `npm ci`; the npm-installed CLI carries the
684
- /// compiler as a regular dependency, nested under the package on global
685
- /// prefixes and hoisted to the project root on local ones.
686
- fn tsExternalCompilerBin(b: *std.Build, dep: *std.Build.Dependency) ?[]const u8 {
687
- const io = b.graph.io;
688
- const sdk_root = tsSdkRoot(b.allocator, io, dep);
689
- var dir: []const u8 = b.pathJoin(&.{ sdk_root, "packages", "core" });
690
- while (true) {
691
- if (!std.mem.eql(u8, std.fs.path.basename(dir), "node_modules")) {
692
- const candidate = b.pathJoin(&.{ dir, "node_modules", ".bin", if (builtin.os.tag == .windows) "scriptc.cmd" else "scriptc" });
693
- found: {
694
- std.Io.Dir.cwd().access(io, candidate, .{}) catch break :found;
695
- return candidate;
696
- }
697
- }
698
- dir = std.fs.path.dirname(dir) orelse return null;
699
- }
700
- }
701
-
702
- fn requireTsExternalCompilerBin(b: *std.Build, dep: *std.Build.Dependency) []const u8 {
703
- return tsExternalCompilerBin(b, dep) orelse {
704
- const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
705
- std.debug.print(
706
- \\
707
- \\error: the external TypeScript compiler is not installed (cores and services
708
- \\compile through it). It ships as an exact-pinned dependency of the SDK's
709
- \\packages/core — install it once with:
710
- \\ cd {s}/packages/core && npm ci
711
- \\(or point NATIVE_SDK_CORE_COMPILER at the pinned release's command; an
712
- \\npm-installed @native-sdk/cli carries the compiler automatically — if it is
713
- \\missing there, the install is broken: reinstall @native-sdk/cli).
714
- \\
715
- \\
716
- , .{sdk_root});
717
- std.process.exit(1);
718
- };
719
- }
720
-
721
711
  /// PR 166 adds both the published compile-cache bootstrap and the optional
722
712
  /// library-profile optimization field. The installed bootstrap is therefore
723
713
  /// the capability marker: keep older exact pins byte-for-byte compatible;
@@ -902,6 +892,16 @@ fn tsCoreStage(
902
892
  sqlite_check.addFileArg(dep.path("packages/core/compile-surface/core.ts"));
903
893
  sqlite_check.addArg("--sdk-out");
904
894
  checked_sdk_core = sqlite_check.addOutputFileArg("core.ts");
895
+ sqlite_check.addArg("--sdk-events-out");
896
+ _ = sqlite_check.addOutputFileArg("events.ts");
897
+ sqlite_check.addArg("--sdk-text-out");
898
+ _ = sqlite_check.addOutputFileArg("text.ts");
899
+ sqlite_check.addArg("--sdk-bytes-text-methods-out");
900
+ _ = sqlite_check.addOutputFileArg("bytes_text_methods.d.ts");
901
+ sqlite_check.addArg("--sdk-events-dts-out");
902
+ _ = sqlite_check.addOutputFileArg("events.d.ts");
903
+ sqlite_check.addArg("--sdk-text-dts-out");
904
+ _ = sqlite_check.addOutputFileArg("text.d.ts");
905
905
  sqlite_check.addArg("--static-out");
906
906
  checked_static_core = sqlite_check.addOutputFileArg("core_static.ts");
907
907
  sqlite_check.addArg("--zig-out");
@@ -914,6 +914,9 @@ fn tsCoreStage(
914
914
  }
915
915
  sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_codegen.ts"));
916
916
  sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_runtime_policy.ts"));
917
+ for ([_][]const u8{ "events.ts", "text.ts", "bytes_text_methods.d.ts", "events.d.ts", "text.d.ts" }) |source| {
918
+ sqlite_check.addFileInput(dep.path(b.fmt("packages/core/sdk/{s}", .{source})));
919
+ }
917
920
  addAppSqlDirInputs(b, sqlite_check, appPath(b, app_root, "src"));
918
921
  }
919
922
 
@@ -1087,8 +1090,11 @@ fn tsCoreStage(
1087
1090
  if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
1088
1091
  service_compile.addArgs(&.{ "--compiler", override });
1089
1092
  } else {
1090
- const compiler_bin = requireTsExternalCompilerBin(b, dep);
1091
- service_compile.addArgs(&.{ "--compiler", compiler_bin });
1093
+ // Let Node resolve the dependency from the SDK package origin:
1094
+ // this is npm's own nested/hoisted/global-sibling walk, and the
1095
+ // driver follows scriptc's published `bin` declaration.
1096
+ service_compile.addArg("--compiler-package-origin");
1097
+ service_compile.addFileArg(dep.path("packages/core/package.json"));
1092
1098
  }
1093
1099
  }
1094
1100
 
@@ -1158,8 +1164,8 @@ fn tsCoreStage(
1158
1164
  // driver still refuses a release other than the SDK's pin.
1159
1165
  compile.addArgs(&.{ "--compiler", override });
1160
1166
  } else {
1161
- const compiler_bin = requireTsExternalCompilerBin(b, dep);
1162
- compile.addArgs(&.{ "--compiler", compiler_bin });
1167
+ compile.addArg("--compiler-package-origin");
1168
+ compile.addFileArg(dep.path("packages/core/package.json"));
1163
1169
  }
1164
1170
 
1165
1171
  // The mirror, generated from the archive's OWN co-emitted contract.
@@ -1627,7 +1633,8 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1627
1633
  " src/main.zig,\nor keep src/main.zig and delete src/core.ts. (Other Zig files under" ++
1628
1634
  " src/ are fine either way.)\n");
1629
1635
  }
1630
- const app_config = appManifestBuildConfig(b, app_options.app_root);
1636
+ const manifest_name = appManifestName(b, app_options.app_root, app_options.manifest);
1637
+ const app_config = appManifestBuildConfig(b, app_options.app_root, manifest_name);
1631
1638
  // The core-compiler setting names the one lane there is; the flag
1632
1639
  // overrides app.zon's `.core_compiler` and both exist so a stated
1633
1640
  // choice stays stateable (and so the removed lane's spelling teaches
@@ -1708,7 +1715,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1708
1715
  .archive = stage.archive,
1709
1716
  .service_archive = stage.service_archive,
1710
1717
  .markup_c = stage.markup_c,
1711
- .manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) }),
1718
+ .manifest_mod = appManifestModule(b, app_options.app_root, manifest_name),
1712
1719
  } else null,
1713
1720
  });
1714
1721
  }
@@ -1758,7 +1765,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1758
1765
  options.addOption(bool, "web_layer", web_layer);
1759
1766
  const options_mod = options.createModule();
1760
1767
 
1761
- const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod, ts_stage, relational_migrations, app_config);
1768
+ const app_mod = appModule(b, dep, target, app_optimize, app_options, manifest_name, options_mod, ts_stage, relational_migrations, app_config);
1762
1769
  // TypeScript app code and platform hosts are expensive Zig/Clang semantic
1763
1770
  // work but do not depend on primary markup bytes. Compile them once into
1764
1771
  // an object, then make the executable a link-only artifact over that
@@ -1839,7 +1846,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1839
1846
  // the production app module feeds the cached app-code object and must not
1840
1847
  // absorb the separately linked markup data object.
1841
1848
  const test_app_mod = if (ts_stage != null or app_optimize != optimize)
1842
- appModule(b, dep, target, optimize, app_options, options_mod, ts_stage, relational_migrations, app_config)
1849
+ appModule(b, dep, target, optimize, app_options, manifest_name, options_mod, ts_stage, relational_migrations, app_config)
1843
1850
  else
1844
1851
  app_mod;
1845
1852
  if (ts_stage) |stage| test_app_mod.addObject(markupDataObject(b, target, optimize, stage.markup_c));
@@ -1938,7 +1945,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
1938
1945
  // WebView2 loader) from the framework root; the cached artifact's
1939
1946
  // own location cannot derive it, so hand it over explicitly.
1940
1947
  package_run.setEnvironmentVariable("NATIVE_SDK_PATH", dep.builder.pathFromRoot("."));
1941
- package_run.addArgs(&.{ "package", "--target", package_target_name, "--manifest", "app.zon", "--output" });
1948
+ package_run.addArgs(&.{ "package", "--target", package_target_name, "--manifest", manifest_name, "--output" });
1942
1949
  package_run.addArg(if (host_os == .macos)
1943
1950
  b.fmt("zig-out/package/{s}.app", .{app_options.name})
1944
1951
  else
@@ -2015,14 +2022,14 @@ fn exampleOptimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, defa
2015
2022
  };
2016
2023
  }
2017
2024
 
2018
- fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage, relational_migrations: std.Build.LazyPath, app_config: AppManifestBuildConfig) *std.Build.Module {
2025
+ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, manifest_name: []const u8, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage, relational_migrations: std.Build.LazyPath, app_config: AppManifestBuildConfig) *std.Build.Module {
2019
2026
  const native_sdk_mod = nativeSdkModuleWithTerminal(b, dep, target, optimize, app_options.terminal_sessions);
2020
2027
  const runner_mod = b.createModule(.{
2021
2028
  .root_source_file = dep.path("src/app_runner/root.zig"),
2022
2029
  .target = target,
2023
2030
  .optimize = optimize,
2024
2031
  });
2025
- const manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) });
2032
+ const manifest_mod = appManifestModule(b, app_options.app_root, manifest_name);
2026
2033
  runner_mod.addImport("native_sdk", native_sdk_mod);
2027
2034
  runner_mod.addImport("build_options", options_mod);
2028
2035
  runner_mod.addImport("app_manifest_zon", manifest_mod);
@@ -2805,15 +2812,19 @@ fn appPath(b: *std.Build, app_root: []const u8, sub_path: []const u8) []const u8
2805
2812
  return b.pathJoin(&.{ app_root, sub_path });
2806
2813
  }
2807
2814
 
2808
- fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildConfig {
2815
+ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8, manifest_name: []const u8) AppManifestBuildConfig {
2809
2816
  // The fallback for a manifest this lenient parse cannot read keeps
2810
2817
  // the web layer (see AppManifestBuildConfig): a shape mismatch here
2811
2818
  // is not proof the app declares no web use.
2812
2819
  const fallback: AppManifestBuildConfig = .{ .web_declaration = .unreadable_manifest };
2813
- const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, "app.zon"), b.allocator, .limited(1024 * 1024)) catch return fallback;
2814
- const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
2820
+ const source = b.build_root.handle.readFileAlloc(b.graph.io, appPath(b, app_root, manifest_name), b.allocator, .limited(1024 * 1024)) catch return fallback;
2815
2821
  @setEvalBranchQuota(2000);
2816
- const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
2822
+ const raw = if (std.ascii.eqlIgnoreCase(std.fs.path.extension(manifest_name), ".json"))
2823
+ std.json.parseFromSliceLeaky(InferenceManifest, b.allocator, source, .{ .ignore_unknown_fields = true }) catch return fallback
2824
+ else zon: {
2825
+ const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
2826
+ break :zon std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
2827
+ };
2817
2828
  // `.core_compiler` names the one lane there is; validated here so
2818
2829
  // the removed transpiled lane's spelling teaches at configure time.
2819
2830
  if (!std.mem.eql(u8, raw.core_compiler, "external")) {
package/build.zig CHANGED
@@ -859,7 +859,10 @@ pub fn build(b: *std.Build) void {
859
859
  .{ .path = "packages/core/scripts/embed_markup_c.mjs", .pattern = "const unsigned char native_sdk_app_markup[]" },
860
860
  .{ .path = "build/app.zig", .pattern = "node_modules\", \"scriptc\", \"dist\", \"bootstrap.js\"" },
861
861
  .{ .path = "build/app.zig", .pattern = "setEnvironmentVariable(\"SCRIPTC_TIMING\", \"1\")" },
862
- .{ .path = "build/app.zig", .pattern = "node_modules\", \".bin\", if (builtin.os.tag == .windows) \"scriptc.cmd\" else \"scriptc\"" },
862
+ .{ .path = "build/app.zig", .pattern = "service_compile.addArg(\"--compiler-package-origin\")" },
863
+ .{ .path = "build/app.zig", .pattern = "compile.addArg(\"--compiler-package-origin\")" },
864
+ .{ .path = "packages/core/scripts/run_external_core_compiler.mjs", .pattern = "publishedScriptcArgv(args[\"compiler-package-origin\"])" },
865
+ .{ .path = "packages/core/scripts/run_external_service_compiler.mjs", .pattern = "publishedScriptcArgv(args[\"compiler-package-origin\"])" },
863
866
  .{ .path = "build/app.zig", .pattern = "addFileInput(dep.path(\"packages/core/scripts/compiler_command.mjs\"))" },
864
867
  .{ .path = "packages/core/scripts/run_external_core_compiler.mjs", .pattern = "compilerArgv(args.compiler)" },
865
868
  .{ .path = "packages/core/scripts/run_external_service_compiler.mjs", .pattern = "compilerArgv(args.compiler)" },
@@ -1573,6 +1576,14 @@ pub fn build(b: *std.Build) void {
1573
1576
  .{ .path = "src/platform/macos/root.zig", .pattern = ".high_contrast = event.high_contrast != 0" },
1574
1577
  .{ .path = "src/platform/macos/root.zig", .pattern = ".appearance_changed => state.emit" },
1575
1578
  });
1579
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-tray-segment-source-selection", "Verify both macOS tray hosts keep segmented selection model-owned", &.{
1580
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@property(nonatomic, assign) NSInteger sourceSelectedSegment;" },
1581
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (options[i].selected != 0) control.sourceSelectedSegment = (NSInteger)i;" },
1582
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "for (NSInteger index = 0; index < control.segmentCount; index++) {\n [control setSelected:index == sourceSelected forSegment:index];\n }\n self.trayCallback" },
1583
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "@property(nonatomic, assign) NSInteger sourceSelectedSegment;" },
1584
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (options[i].selected != 0) control.sourceSelectedSegment = (NSInteger)i;" },
1585
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "for (NSInteger index = 0; index < control.segmentCount; index++) {\n [control setSelected:index == sourceSelected forSegment:index];\n }\n self.trayCallback" },
1586
+ });
1576
1587
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-builtin-bridge-policy", "Verify bridge policy docs include guarded dialog commands", &.{
1577
1588
  .{ .path = "docs/src/app/docs/security/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
1578
1589
  .{ .path = "docs/src/app/docs/bridge/builtin-commands/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "engines": {
@@ -14,6 +14,7 @@
14
14
  "bin/native.js",
15
15
  "assets",
16
16
  "skill-data",
17
+ "schemas",
17
18
  "skills",
18
19
  "src",
19
20
  "build",
@@ -38,14 +39,14 @@
38
39
  "scriptc": "0.0.33"
39
40
  },
40
41
  "optionalDependencies": {
41
- "@native-sdk/cli-darwin-arm64": "0.9.4",
42
- "@native-sdk/cli-darwin-x64": "0.9.4",
43
- "@native-sdk/cli-linux-arm64-gnu": "0.9.4",
44
- "@native-sdk/cli-linux-arm64-musl": "0.9.4",
45
- "@native-sdk/cli-linux-x64-gnu": "0.9.4",
46
- "@native-sdk/cli-linux-x64-musl": "0.9.4",
47
- "@native-sdk/cli-win32-arm64": "0.9.4",
48
- "@native-sdk/cli-win32-x64": "0.9.4"
42
+ "@native-sdk/cli-darwin-arm64": "0.9.5",
43
+ "@native-sdk/cli-darwin-x64": "0.9.5",
44
+ "@native-sdk/cli-linux-arm64-gnu": "0.9.5",
45
+ "@native-sdk/cli-linux-arm64-musl": "0.9.5",
46
+ "@native-sdk/cli-linux-x64-gnu": "0.9.5",
47
+ "@native-sdk/cli-linux-x64-musl": "0.9.5",
48
+ "@native-sdk/cli-win32-arm64": "0.9.5",
49
+ "@native-sdk/cli-win32-x64": "0.9.5"
49
50
  },
50
51
  "repository": {
51
52
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.9.4",
9
+ "version": "0.9.5",
10
10
  "dependencies": {
11
11
  "scriptc": "0.0.33"
12
12
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its checker and contract frontend, the exact-pinned core compiler dependency, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,13 +14,14 @@
14
14
  // --out-sidecar <file>
15
15
  // [--host-platform <arch-os-abi> --target-platform <arch-os-abi>
16
16
  // --zig-exe <path>] [--android-ndk <dir>]
17
- // (--compiler <cmd> | --compiler-js <main.js>)
17
+ // (--compiler <cmd> | --compiler-js <main.js> |
18
+ // --compiler-package-origin <packages/core/package.json>)
18
19
 
19
20
  import { spawnSync } from "node:child_process";
20
21
  import fs from "node:fs";
21
22
  import os from "node:os";
22
23
  import path from "node:path";
23
- import { compilerArgv } from "./compiler_command.mjs";
24
+ import { compilerArgv, publishedScriptcArgv } from "./compiler_command.mjs";
24
25
 
25
26
  function parseArgs(argv) {
26
27
  const args = {};
@@ -28,7 +29,7 @@ function parseArgs(argv) {
28
29
  const key = argv[i];
29
30
  const value = argv[i + 1];
30
31
  if (!key.startsWith("--") || value === undefined) {
31
- console.error("usage: run_external_core_compiler.mjs --stage <dir> --name <n> --manifest <package.json> --frontend-sidecar <file> --out-archive <file> --out-sidecar <file> [--host-platform <arch-os-abi> --target-platform <arch-os-abi> --zig-exe <path>] (--compiler <cmd> | --compiler-js <main.js>)");
32
+ console.error("usage: run_external_core_compiler.mjs --stage <dir> --name <n> --manifest <package.json> --frontend-sidecar <file> --out-archive <file> --out-sidecar <file> [--host-platform <arch-os-abi> --target-platform <arch-os-abi> --zig-exe <path>] (--compiler <cmd> | --compiler-js <main.js> | --compiler-package-origin <package.json>)");
32
33
  process.exit(2);
33
34
  }
34
35
  args[key.slice(2)] = value;
@@ -39,8 +40,9 @@ function parseArgs(argv) {
39
40
  process.exit(2);
40
41
  }
41
42
  }
42
- if (!args.compiler && !args["compiler-js"]) {
43
- console.error("run_external_core_compiler.mjs: supply --compiler <cmd> or --compiler-js <main.js>");
43
+ const compilerModes = [args.compiler, args["compiler-js"], args["compiler-package-origin"]].filter(Boolean);
44
+ if (compilerModes.length !== 1) {
45
+ console.error("run_external_core_compiler.mjs: supply exactly one of --compiler <cmd>, --compiler-js <main.js>, or --compiler-package-origin <package.json>");
44
46
  process.exit(2);
45
47
  }
46
48
  if (Boolean(args["host-platform"]) !== Boolean(args["target-platform"])) {
@@ -53,15 +55,23 @@ function parseArgs(argv) {
53
55
  const args = parseArgs(process.argv);
54
56
  // Every path argument resolves against the INVOCATION's cwd up front:
55
57
  // the compile itself runs from a scratch directory.
56
- for (const key of ["stage", "manifest", "frontend-sidecar", "out-archive", "out-sidecar", "compiler-js", "zig-exe", "android-ndk"]) {
58
+ for (const key of ["stage", "manifest", "frontend-sidecar", "out-archive", "out-sidecar", "compiler-js", "compiler-package-origin", "zig-exe", "android-ndk"]) {
57
59
  if (key in args) args[key] = path.resolve(args[key]);
58
60
  }
59
61
  // --compiler is a COMMAND: a bare executable path (possibly containing
60
62
  // spaces) or an interpreter plus script ("node .../main.js"). The shared
61
63
  // resolver also unwraps npm's Windows .cmd shim to its declared JS bin.
62
- const argv0 = args.compiler
63
- ? compilerArgv(args.compiler)
64
- : [process.execPath, args["compiler-js"]];
64
+ let argv0;
65
+ try {
66
+ argv0 = args.compiler
67
+ ? compilerArgv(args.compiler)
68
+ : args["compiler-js"]
69
+ ? [process.execPath, args["compiler-js"]]
70
+ : publishedScriptcArgv(args["compiler-package-origin"]);
71
+ } catch (error) {
72
+ console.error(`the external TypeScript compiler is not installed or has no valid published bin: ${error instanceof Error ? error.message : String(error)} — reinstall @native-sdk/cli, or point NATIVE_SDK_CORE_COMPILER at the pinned release's command`);
73
+ process.exit(2);
74
+ }
65
75
 
66
76
  // App and fixture build graphs state the host and target explicitly. A
67
77
  // differing target must compile the core archive through the same ScriptC
@@ -17,7 +17,7 @@ import { spawnSync } from "node:child_process";
17
17
  import fs from "node:fs";
18
18
  import os from "node:os";
19
19
  import path from "node:path";
20
- import { compilerArgv } from "./compiler_command.mjs";
20
+ import { compilerArgv, publishedScriptcArgv } from "./compiler_command.mjs";
21
21
 
22
22
  function parseArgs(argv) {
23
23
  const args = {};
@@ -25,7 +25,7 @@ function parseArgs(argv) {
25
25
  const key = argv[i];
26
26
  const value = argv[i + 1];
27
27
  if (!key?.startsWith("--") || value === undefined) {
28
- console.error("usage: run_external_service_compiler.mjs --stage <dir> --manifest <package.json> --contract <services.contract.json> (--out-exe <file> | --out-archive <file>) --host-platform <arch-os-abi> --target-platform <arch-os-abi> [--zig-exe <path>] [--android-ndk <dir>] (--compiler <cmd> | --compiler-js <main.js>)");
28
+ console.error("usage: run_external_service_compiler.mjs --stage <dir> --manifest <package.json> --contract <services.contract.json> (--out-exe <file> | --out-archive <file>) --host-platform <arch-os-abi> --target-platform <arch-os-abi> [--zig-exe <path>] [--android-ndk <dir>] (--compiler <cmd> | --compiler-js <main.js> | --compiler-package-origin <package.json>)");
29
29
  process.exit(2);
30
30
  }
31
31
  args[key.slice(2)] = value;
@@ -40,8 +40,9 @@ function parseArgs(argv) {
40
40
  console.error("run_external_service_compiler.mjs: supply --out-exe, --out-archive, or both");
41
41
  process.exit(2);
42
42
  }
43
- if (!args.compiler && !args["compiler-js"]) {
44
- console.error("run_external_service_compiler.mjs: supply --compiler or --compiler-js");
43
+ const compilerModes = [args.compiler, args["compiler-js"], args["compiler-package-origin"]].filter(Boolean);
44
+ if (compilerModes.length !== 1) {
45
+ console.error("run_external_service_compiler.mjs: supply exactly one of --compiler, --compiler-js, or --compiler-package-origin");
45
46
  process.exit(2);
46
47
  }
47
48
  return args;
@@ -140,12 +141,20 @@ if (args["out-archive"]) {
140
141
  process.exit(2);
141
142
  }
142
143
  }
143
- for (const key of ["stage", "manifest", "contract", "out-exe", "out-archive", "compiler-js", "zig-exe", "android-ndk"]) {
144
+ for (const key of ["stage", "manifest", "contract", "out-exe", "out-archive", "compiler-js", "compiler-package-origin", "zig-exe", "android-ndk"]) {
144
145
  if (args[key]) args[key] = path.resolve(args[key]);
145
146
  }
146
- const argv0 = args.compiler
147
- ? compilerArgv(args.compiler)
148
- : [process.execPath, args["compiler-js"]];
147
+ let argv0;
148
+ try {
149
+ argv0 = args.compiler
150
+ ? compilerArgv(args.compiler)
151
+ : args["compiler-js"]
152
+ ? [process.execPath, args["compiler-js"]]
153
+ : publishedScriptcArgv(args["compiler-package-origin"]);
154
+ } catch (error) {
155
+ console.error(`the external TypeScript compiler is not installed or has no valid published bin: ${error instanceof Error ? error.message : String(error)} — reinstall @native-sdk/cli, or point NATIVE_SDK_CORE_COMPILER at the pinned release's command`);
156
+ process.exit(2);
157
+ }
149
158
 
150
159
  // Cross compiles hand the compiler its zig-cc lane: the target triple as
151
160
  // SCRIPTC_TARGET (the compiler's own mobile spellings for iOS/Android), and
@@ -80,7 +80,106 @@ function servicePackagesField(source) {
80
80
  throw new Error("app.zon service_packages field is not balanced");
81
81
  }
82
82
 
83
- export function readServicePackages(source) {
83
+ function parseJsonManifest(source) {
84
+ const manifest = JSON.parse(source);
85
+ if (manifest === null || Array.isArray(manifest) || typeof manifest !== "object") throw new Error("app.json must contain one object");
86
+ return manifest;
87
+ }
88
+
89
+ function skipJsonWhitespace(source, start) {
90
+ let at = start;
91
+ while (/\s/.test(source[at] ?? "")) at++;
92
+ return at;
93
+ }
94
+
95
+ function scanJsonString(source, start) {
96
+ let escaped = false;
97
+ for (let at = start + 1; at < source.length; at++) {
98
+ const char = source[at];
99
+ if (escaped) escaped = false;
100
+ else if (char === "\\") escaped = true;
101
+ else if (char === '"') return at + 1;
102
+ }
103
+ throw new Error("app.json contains an unterminated string");
104
+ }
105
+
106
+ function scanJsonValue(source, start) {
107
+ const first = source[start];
108
+ if (first === '"') return scanJsonString(source, start);
109
+ if (first === "{" || first === "[") {
110
+ const close = first === "{" ? "}" : "]";
111
+ let depth = 1;
112
+ let string = false;
113
+ let escaped = false;
114
+ for (let at = start + 1; at < source.length; at++) {
115
+ const char = source[at];
116
+ if (string) {
117
+ if (escaped) escaped = false;
118
+ else if (char === "\\") escaped = true;
119
+ else if (char === '"') string = false;
120
+ continue;
121
+ }
122
+ if (char === '"') string = true;
123
+ else if (char === first) depth++;
124
+ else if (char === close && --depth === 0) return at + 1;
125
+ }
126
+ throw new Error("app.json contains an unterminated value");
127
+ }
128
+ let at = start;
129
+ while (at < source.length && !/[\s,}\]]/.test(source[at])) at++;
130
+ return at;
131
+ }
132
+
133
+ function jsonObjectField(source, fieldName) {
134
+ let at = skipJsonWhitespace(source, 0);
135
+ if (source[at] !== "{") throw new Error("app.json must contain one object");
136
+ at = skipJsonWhitespace(source, at + 1);
137
+ let memberCount = 0;
138
+ let match = null;
139
+ while (source[at] !== "}") {
140
+ if (source[at] !== '"') throw new Error("app.json contains an invalid object key");
141
+ const keyStart = at;
142
+ const keyEnd = scanJsonString(source, keyStart);
143
+ const key = JSON.parse(source.slice(keyStart, keyEnd));
144
+ at = skipJsonWhitespace(source, keyEnd);
145
+ if (source[at] !== ":") throw new Error("app.json contains an invalid object field");
146
+ const valueStart = skipJsonWhitespace(source, at + 1);
147
+ const valueEnd = scanJsonValue(source, valueStart);
148
+ memberCount++;
149
+ if (key === fieldName) {
150
+ if (match !== null) throw new Error(`app.json contains duplicate ${fieldName} fields`);
151
+ match = { valueStart, valueEnd };
152
+ }
153
+ at = skipJsonWhitespace(source, valueEnd);
154
+ if (source[at] === ",") at = skipJsonWhitespace(source, at + 1);
155
+ else if (source[at] !== "}") throw new Error("app.json contains an invalid object separator");
156
+ }
157
+ return { match, close: at, memberCount };
158
+ }
159
+
160
+ function jsonTopLevelIndent(source, close) {
161
+ const firstKey = source.indexOf('"', source.indexOf("{") + 1);
162
+ const key = firstKey >= 0 && firstKey < close ? firstKey : close;
163
+ const lineStart = source.lastIndexOf("\n", key - 1) + 1;
164
+ const indent = source.slice(lineStart, key);
165
+ return /^[ \t]+$/.test(indent) ? indent : " ";
166
+ }
167
+
168
+ function renderJsonValue(value, indent) {
169
+ return JSON.stringify(value, null, 2).replaceAll("\n", `\n${indent}`);
170
+ }
171
+
172
+ export function readServicePackages(source, format = "zon") {
173
+ if (format === "json") {
174
+ const entries = parseJsonManifest(source).service_packages ?? [];
175
+ if (!Array.isArray(entries)) throw new Error("app.json service_packages must be an array");
176
+ return entries.map((entry) => {
177
+ if (entry === null || typeof entry !== "object" || typeof entry.name !== "string" || typeof entry.version !== "string" || typeof entry.content_hash !== "string") {
178
+ throw new Error("app.json service_packages contains an invalid package fact");
179
+ }
180
+ return { name: entry.name, version: entry.version, content_hash: entry.content_hash };
181
+ });
182
+ }
84
183
  const field = servicePackagesField(source);
85
184
  if (!field) return [];
86
185
  const body = source.slice(field.open + 1, field.close);
@@ -104,13 +203,24 @@ function packageNameFromSpec(spec) {
104
203
  return spec.slice(0, spec.lastIndexOf("@"));
105
204
  }
106
205
 
107
- export function mergePackageSpecs(source, requested) {
108
- const specs = new Map(readServicePackages(source).map((entry) => [entry.name, `${entry.name}@${entry.version}`]));
206
+ export function mergePackageSpecs(source, requested, format = "zon") {
207
+ const specs = new Map(readServicePackages(source, format).map((entry) => [entry.name, `${entry.name}@${entry.version}`]));
109
208
  for (const spec of requested) specs.set(packageNameFromSpec(spec), spec);
110
209
  return [...specs].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, spec]) => spec);
111
210
  }
112
211
 
113
- export function replaceServicePackages(source, entries) {
212
+ export function replaceServicePackages(source, entries, format = "zon") {
213
+ if (format === "json") {
214
+ parseJsonManifest(source);
215
+ const field = jsonObjectField(source, "service_packages");
216
+ const indent = jsonTopLevelIndent(source, field.close);
217
+ const rendered = renderJsonValue(entries, indent);
218
+ if (field.match) {
219
+ return source.slice(0, field.match.valueStart) + rendered + source.slice(field.match.valueEnd);
220
+ }
221
+ const comma = field.memberCount === 0 ? "" : ",";
222
+ return `${source.slice(0, field.close).trimEnd()}${comma}\n${indent}"service_packages": ${rendered}\n${source.slice(field.close)}`;
223
+ }
114
224
  const rendered = [
115
225
  " .service_packages = .{",
116
226
  ...entries.map((entry) => ` .{ .name = ${JSON.stringify(entry.name)}, .version = ${JSON.stringify(entry.version)}, .content_hash = ${JSON.stringify(entry.content_hash)} },`),
@@ -139,10 +249,13 @@ function main(argv) {
139
249
  return 2;
140
250
  }
141
251
 
142
- const manifestPath = path.join(appRoot, "app.zon");
252
+ const jsonPath = path.join(appRoot, "app.json");
253
+ const zonPath = path.join(appRoot, "app.zon");
254
+ const manifestPath = fs.existsSync(jsonPath) ? jsonPath : zonPath;
143
255
  if (!fs.existsSync(manifestPath)) throw new Error(`${manifestPath} does not exist`);
256
+ const format = manifestPath.endsWith(".json") ? "json" : "zon";
144
257
  const current = fs.readFileSync(manifestPath, "utf8");
145
- const installSpecs = mergePackageSpecs(current, requested);
258
+ const installSpecs = mergePackageSpecs(current, requested, format);
146
259
  const work = fs.mkdtempSync(path.join(os.tmpdir(), "native-service-vendor-"));
147
260
  const servicesRoot = path.join(appRoot, "src", "services");
148
261
  const stageRoot = path.join(appRoot, ".native", `.service-vendor-stage-${process.pid}-${Date.now()}`);
@@ -169,8 +282,8 @@ function main(argv) {
169
282
  entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
170
283
  const vendorRoot = path.join(servicesRoot, "vendor");
171
284
  replaceVendorTree(vendorRoot, stageRoot);
172
- fs.writeFileSync(manifestPath, replaceServicePackages(current, entries));
173
- console.log(`vendored ${entries.length} package${entries.length === 1 ? "" : "s"} into src/services/vendor and updated app.zon`);
285
+ fs.writeFileSync(manifestPath, replaceServicePackages(current, entries, format));
286
+ console.log(`vendored ${entries.length} package${entries.length === 1 ? "" : "s"} into src/services/vendor and updated ${path.basename(manifestPath)}`);
174
287
  for (const entry of entries) console.log(` ${entry.name}@${entry.version} ${entry.content_hash}`);
175
288
  return 0;
176
289
  } finally {