@native-sdk/cli 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build/app.zig +187 -6
  2. package/build/ts_run.mjs +63 -0
  3. package/build.zig +213 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +15 -10
  6. package/packages/core/package-lock.json +43 -0
  7. package/packages/core/package.json +37 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +536 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  33. package/src/primitives/app_manifest/root.zig +5 -0
  34. package/src/primitives/canvas/commands.zig +14 -7
  35. package/src/primitives/canvas/lazy_tls.zig +73 -0
  36. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  37. package/src/primitives/canvas/root.zig +6 -0
  38. package/src/primitives/canvas/tests.zig +1 -0
  39. package/src/primitives/canvas/text_atlas.zig +40 -32
  40. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  41. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  42. package/src/primitives/canvas/text_spans.zig +39 -26
  43. package/src/primitives/canvas/tokens.zig +54 -0
  44. package/src/primitives/canvas/ui.zig +125 -0
  45. package/src/primitives/canvas/ui_markup.zig +22 -3
  46. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  47. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  48. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  49. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  50. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  51. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  52. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  53. package/src/primitives/canvas/ui_schema.zig +8 -0
  54. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  55. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  56. package/src/primitives/canvas/widget_render.zig +25 -15
  57. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  58. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  59. package/src/root.zig +7 -0
  60. package/src/runtime/canvas_frame.zig +57 -36
  61. package/src/runtime/canvas_images.zig +9 -3
  62. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  63. package/src/runtime/canvas_widget_runtime.zig +7 -4
  64. package/src/runtime/effects.zig +490 -2
  65. package/src/runtime/effects_host_tests.zig +594 -0
  66. package/src/runtime/root.zig +18 -0
  67. package/src/runtime/session_replay.zig +7 -1
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +1505 -0
  70. package/src/runtime/ts_core_host_tests.zig +1408 -0
  71. package/src/runtime/ts_ui_app.zig +469 -0
  72. package/src/runtime/ui_app.zig +58 -0
  73. package/src/runtime/view_canvas.zig +24 -17
  74. package/src/runtime/view_widget_tree.zig +2 -2
  75. package/src/tooling/codesign.zig +212 -105
  76. package/src/tooling/doctor.zig +78 -0
  77. package/src/tooling/manifest.zig +47 -0
  78. package/src/tooling/package.zig +124 -12
  79. package/src/tooling/raw_manifest.zig +15 -0
  80. package/src/tooling/root.zig +1 -0
  81. package/src/tooling/templates.zig +683 -28
  82. package/src/tooling/ts_core.zig +486 -0
  83. package/src/tooling/verbs.zig +17 -0
package/build/app.zig CHANGED
@@ -42,6 +42,121 @@ pub const AppOptions = struct {
42
42
  app_root: []const u8 = ".",
43
43
  };
44
44
 
45
+ /// Which core the app tree carries. No flag and no config anywhere: the
46
+ /// tree IS the truth — `src/core.ts` is a TypeScript core (transpiled at
47
+ /// build time, run through generated wiring), `src/main.zig` a Zig one,
48
+ /// and both at once is a teaching error naming the two files.
49
+ const CoreTree = enum { zig, ts, both, neither };
50
+
51
+ fn detectCoreTree(b: *std.Build, app_root: []const u8) CoreTree {
52
+ const has_ts = appFileExists(b, app_root, "src/core.ts");
53
+ const has_zig = appFileExists(b, app_root, "src/main.zig");
54
+ if (has_ts and has_zig) return .both;
55
+ if (has_ts) return .ts;
56
+ if (has_zig) return .zig;
57
+ return .neither;
58
+ }
59
+
60
+ fn appFileExists(b: *std.Build, app_root: []const u8, sub_path: []const u8) bool {
61
+ b.build_root.handle.access(b.graph.io, appPath(b, app_root, sub_path), .{}) catch return false;
62
+ return true;
63
+ }
64
+
65
+ /// The staged TypeScript-core wiring: one generated directory holding the
66
+ /// transpiled core (core.zig), its rt kernel, the app's markup, and the
67
+ /// SDK's generated-wiring entry (ts_core_main.zig as main.zig). Built once
68
+ /// per app build and shared by the exe and test modules.
69
+ const TsCoreStage = struct {
70
+ main_root: std.Build.LazyPath,
71
+ };
72
+
73
+ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8) TsCoreStage {
74
+ if (!appFileExists(b, app_root, "src/app.native")) {
75
+ @panic("\nthis app has a TypeScript core (src/core.ts) but no view: TS apps render markup," ++
76
+ " so add src/app.native (the whole view tier binds the core's emitted model)\n");
77
+ }
78
+ const node = b.findProgram(&.{"node"}, &.{}) catch {
79
+ @panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core transpiler runs at" ++
80
+ " build time; the binary it emits ships no JS runtime).\nInstall Node.js 22+ — https://nodejs.org" ++
81
+ " or `brew install node` — and re-run.\n");
82
+ };
83
+ dep.builder.build_root.handle.access(
84
+ dep.builder.graph.io,
85
+ "packages/core/node_modules/@typescript/typescript6",
86
+ .{},
87
+ ) catch {
88
+ // Name the SDK dependency's real location (a checkout or the
89
+ // npm-installed @native-sdk/cli package — both carry
90
+ // packages/core with its lockfile, so `npm ci` works in place).
91
+ std.debug.panic("\nthe SDK's @native-sdk/core transpiler is missing its installed dependency.\nFix with:" ++
92
+ " cd {s}/packages/core && npm ci\n", .{dep.builder.build_root.path orelse "<sdk>"});
93
+ };
94
+
95
+ // The transpiler runs through build/ts_run.mjs, not as `node cli.ts`:
96
+ // on the npm-installed layout the transpiler's .ts sources live inside
97
+ // node_modules, where node refuses its builtin type stripping — the
98
+ // runner strips those modules with the transpiler's own installed
99
+ // TypeScript and is a pass-through on a repo checkout.
100
+ const transpile = b.addSystemCommand(&.{node});
101
+ transpile.addFileArg(dep.path("build/ts_run.mjs"));
102
+ transpile.addFileArg(dep.path("packages/core/src/cli.ts"));
103
+ transpile.addFileArg(b.path(appPath(b, app_root, "src/core.ts")));
104
+ transpile.addArg("-o");
105
+ const emitted_core = transpile.addOutputFileArg("core.zig");
106
+ // The transpiler reads its own sources, the SDK modules, and the core's
107
+ // WHOLE import graph at run time; declare them so a transpiler upgrade
108
+ // or an edit to ANY module of a multi-file core re-emits it. The graph
109
+ // is declared as every .ts under the app's src/ (a superset of the
110
+ // reachable imports: over-approximation only re-runs the transpile,
111
+ // never misses a stale input). Failure mode: the checker's NS
112
+ // diagnostics stream to stderr verbatim — they are the teaching layer,
113
+ // nothing wraps them.
114
+ addTsDirInputs(b, dep.builder, transpile, "packages/core/sdk");
115
+ addAppTsDirInputs(b, transpile, appPath(b, app_root, "src"));
116
+ const transpiler_sources = [_][]const u8{
117
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
118
+ };
119
+ for (transpiler_sources) |source| {
120
+ transpile.addFileInput(dep.path(b.fmt("packages/core/src/{s}", .{source})));
121
+ }
122
+
123
+ // The wiring imports core.zig and app.native relatively; the emitted
124
+ // core imports rt.zig relatively: stage all four into one directory.
125
+ const staged = b.addWriteFiles();
126
+ _ = staged.addCopyFile(emitted_core, "core.zig");
127
+ _ = staged.addCopyFile(dep.path("packages/core/rt/rt.zig"), "rt.zig");
128
+ _ = staged.addCopyFile(b.path(appPath(b, app_root, "src/app.native")), "app.native");
129
+ const main_root = staged.addCopyFile(dep.path("src/app_runner/ts_core_main.zig"), "main.zig");
130
+ return .{ .main_root = main_root };
131
+ }
132
+
133
+ /// Declare every .ts file in an SDK-relative directory as a file input of
134
+ /// the transpile step (the SDK library modules an app may import).
135
+ fn addTsDirInputs(b: *std.Build, sdk_builder: *std.Build, transpile: *std.Build.Step.Run, dir_path: []const u8) void {
136
+ var dir = sdk_builder.build_root.handle.openDir(b.graph.io, dir_path, .{ .iterate = true }) catch return;
137
+ defer dir.close(b.graph.io);
138
+ var it = dir.iterate();
139
+ while (it.next(b.graph.io) catch null) |entry| {
140
+ if (entry.kind != .file) continue;
141
+ if (!std.mem.endsWith(u8, entry.name, ".ts")) continue;
142
+ transpile.addFileInput(sdk_builder.path(b.fmt("{s}/{s}", .{ dir_path, entry.name })));
143
+ }
144
+ }
145
+
146
+ /// Declare every .ts file under the app's src/ (recursively — a core may
147
+ /// split into subdirectories) as a file input of the transpile step.
148
+ fn addAppTsDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, src_path: []const u8) void {
149
+ var dir = b.build_root.handle.openDir(b.graph.io, src_path, .{ .iterate = true }) catch return;
150
+ defer dir.close(b.graph.io);
151
+ var walker = dir.walk(b.allocator) catch return;
152
+ defer walker.deinit();
153
+ while (walker.next(b.graph.io) catch null) |entry| {
154
+ if (entry.kind != .file) continue;
155
+ if (!std.mem.endsWith(u8, entry.basename, ".ts")) continue;
156
+ transpile.addFileInput(b.path(b.fmt("{s}/{s}", .{ src_path, entry.path })));
157
+ }
158
+ }
159
+
45
160
  /// The `native_sdk_app_*` C ABI every embed static library exports.
46
161
  pub const mobile_export_symbol_names = [_][]const u8{
47
162
  "native_sdk_app_create",
@@ -190,11 +305,31 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
190
305
  const optimize = exampleOptimizeMode(b, optimize_request, .Debug);
191
306
  const app_optimize = exampleOptimizeMode(b, optimize_request, .ReleaseFast);
192
307
 
308
+ // The core role is detected from the tree (never a flag or config):
309
+ // builds with a custom `main` entry declared their core explicitly and
310
+ // skip detection.
311
+ const core_tree: CoreTree = if (std.mem.eql(u8, app_options.main, "src/main.zig"))
312
+ detectCoreTree(b, app_options.app_root)
313
+ else
314
+ .zig;
315
+ if (core_tree == .both) {
316
+ @panic("\nthis app declares two cores: src/core.ts (TypeScript) and src/main.zig (Zig)." ++
317
+ "\nAn app has exactly one core - the tree is the truth. Keep src/core.ts and delete" ++
318
+ " src/main.zig,\nor keep src/main.zig and delete src/core.ts. (Other Zig files under" ++
319
+ " src/ are fine either way.)\n");
320
+ }
321
+ const ts_stage: ?TsCoreStage = if (core_tree == .ts) tsCoreStage(b, dep, app_options.app_root) else null;
322
+
193
323
  // Mobile targets get the embed static library as a `lib` step: the
194
324
  // artifact the toolkit-owned iOS host (and any hand-written shim)
195
325
  // links, so `native dev|package --target ios` works against every
196
326
  // standard app build — generated graph or ejected — with nothing but
197
327
  // `-Dtarget`. Desktop targets keep the step absent.
328
+ if (ts_stage != null and (target.result.os.tag == .ios or target.result.abi.isAndroid())) {
329
+ @panic("\nTypeScript app cores build desktop apps today; the mobile embed library for TS" ++
330
+ " cores lands with the mobile host tier.\nBuild for a desktop target, or port the core" ++
331
+ " to a Zig `mobileOptions` app for mobile.\n");
332
+ }
198
333
  if (target.result.os.tag == .ios or target.result.abi.isAndroid()) {
199
334
  addMobileLibWithTarget(b, dep, target, optimize, .{
200
335
  .name = app_options.name,
@@ -248,7 +383,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
248
383
  options.addOption(bool, "web_layer", web_layer);
249
384
  const options_mod = options.createModule();
250
385
 
251
- const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod);
386
+ const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod, ts_stage);
252
387
  const exe = b.addExecutable(.{
253
388
  .name = app_options.name,
254
389
  .root_module = app_mod,
@@ -263,11 +398,42 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
263
398
  const run_step = b.step("run", "Run the app");
264
399
  run_step.dependOn(&run.step);
265
400
 
266
- const test_app_mod = if (app_optimize == optimize) app_mod else appModule(b, dep, target, optimize, app_options, options_mod);
401
+ const test_app_mod = if (app_optimize == optimize) app_mod else appModule(b, dep, target, optimize, app_options, options_mod, ts_stage);
267
402
  const tests = b.addTest(.{ .root_module = test_app_mod, .use_llvm = useLlvmWorkaround(target) });
268
403
  const test_step = b.step("test", "Run tests");
269
404
  test_step.dependOn(&b.addRunArtifact(tests).step);
270
405
 
406
+ // `native test` must surface the app's compile-time teaching errors,
407
+ // not just its test failures. Test builds never analyze `main` (the
408
+ // test runner replaces the entry point), so rules that fire inside it
409
+ // — UiApp.create's Model-defaults rule above all — used to ambush at
410
+ // `native build`, the LAST step in the loop. Compiling this object
411
+ // forces full semantic analysis of the app module, entry point
412
+ // included; nothing links or runs.
413
+ const analysis_root = b.addWriteFiles().add("app_analysis.zig",
414
+ \\//! Generated by the app build: force semantic analysis of the
415
+ \\//! app's entry point at test time. Exactly `main`, transitively —
416
+ \\//! the same surface `native build` analyzes — so test-time can
417
+ \\//! never be stricter than the build it fronts.
418
+ \\comptime {
419
+ \\ const app = @import("app");
420
+ \\ if (@hasDecl(app, "main")) _ = &app.main;
421
+ \\}
422
+ \\
423
+ );
424
+ const analysis_mod = b.createModule(.{
425
+ .root_source_file = analysis_root,
426
+ .target = target,
427
+ .optimize = optimize,
428
+ });
429
+ analysis_mod.addImport("app", test_app_mod);
430
+ const analysis_obj = b.addObject(.{
431
+ .name = b.fmt("{s}-analysis", .{app_options.name}),
432
+ .root_module = analysis_mod,
433
+ .use_llvm = useLlvmWorkaround(target),
434
+ });
435
+ test_step.dependOn(&analysis_obj.step);
436
+
271
437
  // `zig build model-contract`: reflect the app's Model/Msg into
272
438
  // zig-out/model-contract.zon so `native check` can verify markup
273
439
  // bindings against the app's real surface without compiling the app.
@@ -388,20 +554,35 @@ fn exampleOptimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, defa
388
554
  };
389
555
  }
390
556
 
391
- 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) *std.Build.Module {
557
+ 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) *std.Build.Module {
392
558
  const native_sdk_mod = nativeSdkModule(b, dep, target, optimize);
393
559
  const runner_mod = b.createModule(.{
394
560
  .root_source_file = dep.path("src/app_runner/root.zig"),
395
561
  .target = target,
396
562
  .optimize = optimize,
397
563
  });
564
+ const manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) });
398
565
  runner_mod.addImport("native_sdk", native_sdk_mod);
399
566
  runner_mod.addImport("build_options", options_mod);
400
- runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) }));
401
-
402
- const app_mod = localModule(b, target, optimize, appPath(b, app_options.app_root, app_options.main));
567
+ runner_mod.addImport("app_manifest_zon", manifest_mod);
568
+
569
+ const app_mod = if (ts_stage) |stage|
570
+ // TypeScript core: the app module roots at the staged generated
571
+ // wiring (ts_core_main.zig beside the transpiled core.zig, its rt
572
+ // kernel, and the app's markup).
573
+ b.createModule(.{
574
+ .root_source_file = stage.main_root,
575
+ .target = target,
576
+ .optimize = optimize,
577
+ })
578
+ else
579
+ localModule(b, target, optimize, appPath(b, app_options.app_root, app_options.main));
403
580
  app_mod.addImport("native_sdk", native_sdk_mod);
404
581
  app_mod.addImport("runner", runner_mod);
582
+ if (ts_stage != null) {
583
+ // The wiring derives scene/identity/security from app.zon itself.
584
+ app_mod.addImport("app_manifest_zon", manifest_mod);
585
+ }
405
586
  return app_mod;
406
587
  }
407
588
 
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Run a TypeScript module of the @native-sdk/core transpiler tier under
4
+ // node from ANY SDK layout:
5
+ //
6
+ // node ts_run.mjs <module.ts> [args...]
7
+ //
8
+ // From a repo checkout `node packages/core/src/cli.ts` works directly —
9
+ // node strips types natively. From the npm-installed @native-sdk/cli the
10
+ // SAME file sits inside node_modules, where node refuses its builtin type
11
+ // stripping by design (ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING). This
12
+ // runner closes that gap without forking the layouts: it registers a load
13
+ // hook that strips ONLY node_modules-resident .ts modules, using the
14
+ // transpiler's own installed TypeScript (the `npm ci` dependency inside
15
+ // packages/core, resolved from the target module's location), and leaves
16
+ // every other module to node's native handling. Then it imports the
17
+ // requested module with argv respliced so the target sees its usual shape
18
+ // (its own path at argv[1], its arguments from argv[2]).
19
+ //
20
+ // On node builds without module.registerHooks (< 22.15) the hook is
21
+ // skipped: repo checkouts keep working natively and the npm layout fails
22
+ // with node's own teaching error naming the unsupported stripping.
23
+
24
+ import module, { createRequire } from 'node:module';
25
+ import { readFileSync } from 'node:fs';
26
+ import { resolve } from 'node:path';
27
+ import { pathToFileURL, fileURLToPath } from 'node:url';
28
+
29
+ const target = process.argv[2];
30
+ if (!target) {
31
+ console.error('usage: node ts_run.mjs <module.ts> [args...]');
32
+ process.exit(2);
33
+ }
34
+ const targetPath = resolve(target);
35
+ // Drop the runner from argv so the target module parses its own argv
36
+ // exactly as when node runs it directly.
37
+ process.argv.splice(1, 1);
38
+
39
+ if (typeof module.registerHooks === 'function') {
40
+ let ts = null;
41
+ module.registerHooks({
42
+ load(url, context, nextLoad) {
43
+ if (url.startsWith('file:') && url.endsWith('.ts') && url.includes('node_modules')) {
44
+ const filePath = fileURLToPath(url);
45
+ // The transpiler's own dependency, resolved from the transpiler's
46
+ // location (packages/core/node_modules after the taught `npm ci`).
47
+ ts ??= createRequire(targetPath)('@typescript/typescript6');
48
+ const { outputText } = ts.transpileModule(readFileSync(filePath, 'utf8'), {
49
+ fileName: filePath,
50
+ compilerOptions: {
51
+ target: ts.ScriptTarget.ESNext,
52
+ module: ts.ModuleKind.ESNext,
53
+ verbatimModuleSyntax: true,
54
+ },
55
+ });
56
+ return { format: 'module', source: outputText, shortCircuit: true };
57
+ }
58
+ return nextLoad(url, context);
59
+ },
60
+ });
61
+ }
62
+
63
+ await import(pathToFileURL(targetPath).href);
package/build.zig CHANGED
@@ -195,6 +195,15 @@ pub fn build(b: *std.Build) void {
195
195
  eject_components_mod.addImport("native_sdk", desktop_mod);
196
196
  const eject_components_tests = testArtifact(b, eject_components_mod);
197
197
 
198
+ // Transpiled-core end-to-end suite: tests/ts-core/fixture.ts is
199
+ // emitted by the repo's own transpiler AT BUILD TIME (never a
200
+ // committed Zig snapshot) and driven through the real runtime via
201
+ // `TsCoreHost`. Gated on node plus the transpiler package's
202
+ // installed dependency: absent either, the suite is skipped (the
203
+ // bridge itself stays covered by src/runtime/ts_core_host_tests.zig
204
+ // against a hand-written emitted-ABI core).
205
+ const ts_core_e2e_tests = tsCoreE2eArtifact(b, target, optimize, desktop_mod, tooling_mod);
206
+
198
207
  const ui_markup_mod = module(b, target, optimize, "src/primitives/canvas/ui_markup.zig");
199
208
  const markup_lsp_mod = module(b, target, optimize, "tools/native-sdk/markup_lsp.zig");
200
209
  markup_lsp_mod.addImport("ui_markup", ui_markup_mod);
@@ -205,6 +214,11 @@ pub fn build(b: *std.Build) void {
205
214
  automation_cli_mod.addImport("ui_markup", ui_markup_mod);
206
215
  const automation_cli_tests = testArtifact(b, automation_cli_mod);
207
216
 
217
+ const markup_cli_mod = module(b, target, optimize, "tools/native-sdk/markup.zig");
218
+ markup_cli_mod.addImport("ui_markup", ui_markup_mod);
219
+ markup_cli_mod.addImport("markup_lsp", markup_lsp_mod);
220
+ const markup_cli_tests = testArtifact(b, markup_cli_mod);
221
+
208
222
  // `native version` names the commit the binary was built from, so
209
223
  // binary/framework skew ("your native binary may be stale") is a
210
224
  // one-command check. Falls back to "unknown" outside a git checkout.
@@ -400,8 +414,30 @@ pub fn build(b: *std.Build) void {
400
414
  test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
401
415
  test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
402
416
  test_step.dependOn(&b.addRunArtifact(eject_components_tests).step);
417
+ if (ts_core_e2e_tests) |ts_core_artifacts| {
418
+ const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the transpiled-core end-to-end suites (requires node)");
419
+ const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
420
+ const soundboard_e2e_run = b.addRunArtifact(ts_core_artifacts.soundboard);
421
+ const monitor_e2e_run = b.addRunArtifact(ts_core_artifacts.system_monitor);
422
+ const scaffold_ide_e2e_run = b.addRunArtifact(ts_core_artifacts.scaffold_ide);
423
+ // The suite scaffolds and typechecks real trees under .zig-cache;
424
+ // no build inputs/outputs to hash, so always run it.
425
+ scaffold_ide_e2e_run.has_side_effects = true;
426
+ const ai_chat_e2e_run = b.addRunArtifact(ts_core_artifacts.ai_chat);
427
+ ts_core_e2e_step.dependOn(&host_e2e_run.step);
428
+ ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
429
+ ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
430
+ ts_core_e2e_step.dependOn(&scaffold_ide_e2e_run.step);
431
+ ts_core_e2e_step.dependOn(&ai_chat_e2e_run.step);
432
+ test_step.dependOn(&host_e2e_run.step);
433
+ test_step.dependOn(&soundboard_e2e_run.step);
434
+ test_step.dependOn(&monitor_e2e_run.step);
435
+ test_step.dependOn(&scaffold_ide_e2e_run.step);
436
+ test_step.dependOn(&ai_chat_e2e_run.step);
437
+ }
403
438
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
404
439
  test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
440
+ test_step.dependOn(&b.addRunArtifact(markup_cli_tests).step);
405
441
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-package-types", "Verify package TypeScript platform feature names", &.{
406
442
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCommandInfo" },
407
443
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "list(): Promise<NativeSdkCommandInfo[]>" },
@@ -426,6 +462,12 @@ pub fn build(b: *std.Build) void {
426
462
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpuSurfaces\"" },
427
463
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuFirstFrameLatencyNs: number" },
428
464
  });
465
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-app-test-entry-analysis", "Verify the managed app test step force-analyzes the entry point (UiApp.create's Model-defaults rule must teach at `native test`, not ambush at `native build`)", &.{
466
+ .{ .path = "build/app.zig", .pattern = "app_analysis.zig" },
467
+ .{ .path = "build/app.zig", .pattern = "if (@hasDecl(app, \"main\")) _ = &app.main;" },
468
+ .{ .path = "build/app.zig", .pattern = "test_step.dependOn(&analysis_obj.step);" },
469
+ .{ .path = "src/runtime/ui_app.zig", .pattern = "has no default value - give every Model field a default" },
470
+ });
429
471
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-bridge-view-selector-helpers", "Verify injected view helpers accept string selectors", &.{
430
472
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "viewSelectorPayload(options)" },
431
473
  .{ .path = "src/platform/macos/cef_host.mm", .pattern = "viewSelectorPayload(options)" },
@@ -793,6 +835,7 @@ pub fn build(b: *std.Build) void {
793
835
  }
794
836
  addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
795
837
  addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
838
+ addTestStep(b, "test-markup-cli", "Run native markup CLI tests", markup_cli_tests);
796
839
  addTestStep(b, "test-tooling", "Run Native SDK tooling tests", tooling_tests);
797
840
  addTestStep(b, "test-eject-components", "Run ejected-component widget-identity tests", eject_components_tests);
798
841
 
@@ -914,12 +957,14 @@ pub fn build(b: *std.Build) void {
914
957
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
915
958
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
916
959
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
960
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed);
917
961
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
918
962
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
919
963
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed);
920
964
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
921
965
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
922
966
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
967
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed);
923
968
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
924
969
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
925
970
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
@@ -2279,10 +2324,15 @@ pub fn build(b: *std.Build) void {
2279
2324
  // carries the CLI as its executable (packaging only needs a real
2280
2325
  // Mach-O to sign); the check skips loudly on hosts without codesign
2281
2326
  // (any non-macOS machine) instead of pretending to have verified.
2327
+ // Signing that claims to sign now fails the package on hosts that
2328
+ // cannot run codesign (that IS the fix this step gates), so only a
2329
+ // macOS host requests adhoc here; elsewhere the package stays
2330
+ // unsigned and the check script below skips loudly as before.
2331
+ const package_signing_mode: []const u8 = if (b.graph.host.result.os.tag == .macos) "adhoc" else "none";
2282
2332
  const package_signing_run = b.addRunArtifact(host_cli_exe);
2283
2333
  package_signing_run.addArgs(&.{ "package", "--target", "macos", "--output", "zig-out/package/native-sdk-signing-verify.app", "--binary" });
2284
2334
  package_signing_run.addFileArg(host_cli_exe.getEmittedBin());
2285
- package_signing_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", "adhoc" });
2335
+ package_signing_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", package_signing_mode });
2286
2336
  package_signing_run.has_side_effects = true;
2287
2337
  const package_signing_check = b.addSystemCommand(&.{
2288
2338
  "sh", "-c",
@@ -2430,6 +2480,168 @@ fn testArtifact(b: *std.Build, mod: *std.Build.Module) *std.Build.Step.Compile {
2430
2480
  return filteredTestArtifact(b, mod, "test", &.{});
2431
2481
  }
2432
2482
 
2483
+ /// The two transpiled-core end-to-end test binaries: the host/markup
2484
+ /// fixture suite (tests/ts-core) and the soundboard-ts example suite —
2485
+ /// the launch-gate port driven as a REAL app (its committed core, its
2486
+ /// shipping markup). Each runs the @native-sdk/core transpiler (node)
2487
+ /// over the TS core at build time, pairs the emitted core with its rt
2488
+ /// kernel in one generated module, and compiles the Zig test root
2489
+ /// against it plus the framework. Returns null — the suites are
2490
+ /// skipped, not failed — when node or the transpiler package's
2491
+ /// installed dependency (`npm ci` in packages/core) is missing.
2492
+ const TsCoreE2eArtifacts = struct {
2493
+ host: *std.Build.Step.Compile,
2494
+ soundboard: *std.Build.Step.Compile,
2495
+ system_monitor: *std.Build.Step.Compile,
2496
+ /// The stock-IDE contract: a fresh scaffold (and the committed TS
2497
+ /// example ports) typecheck under the REAL tsc with zero injected
2498
+ /// paths, and builds keep working with node_modules deleted.
2499
+ scaffold_ide: *std.Build.Step.Compile,
2500
+ ai_chat: *std.Build.Step.Compile,
2501
+ };
2502
+
2503
+ fn tsCoreE2eArtifact(
2504
+ b: *std.Build,
2505
+ target: std.Build.ResolvedTarget,
2506
+ optimize: std.builtin.OptimizeMode,
2507
+ desktop_mod: *std.Build.Module,
2508
+ tooling_mod: *std.Build.Module,
2509
+ ) ?TsCoreE2eArtifacts {
2510
+ const node = b.findProgram(&.{"node"}, &.{}) catch return null;
2511
+ b.build_root.handle.access(
2512
+ b.graph.io,
2513
+ "packages/core/node_modules/@typescript/typescript6",
2514
+ .{},
2515
+ ) catch return null;
2516
+
2517
+ // Each fixture stages its own copy of rt.zig, so each emitted core
2518
+ // owns a distinct rt kernel instance — the process contract the
2519
+ // coexistence e2e test pins (two live cores, no shared arenas).
2520
+ const fixture_mod = tsCoreFixtureModule(b, target, optimize, node, "tests/ts-core/fixture.ts");
2521
+ const markup_fixture_mod = tsCoreFixtureModule(b, target, optimize, node, "tests/ts-core/markup_fixture.ts");
2522
+
2523
+ const e2e_mod = module(b, target, optimize, "tests/ts-core/host_e2e_tests.zig");
2524
+ e2e_mod.addImport("native_sdk", desktop_mod);
2525
+ e2e_mod.addImport("ts_core_fixture", fixture_mod);
2526
+ e2e_mod.addImport("ts_markup_fixture", markup_fixture_mod);
2527
+
2528
+ // The soundboard-ts example's core and markup, tested as one app:
2529
+ // the test root stages beside a copy of the example's app.native so
2530
+ // the compiled markup engine builds the SHIPPING view over the
2531
+ // emitted model.
2532
+ const soundboard_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/soundboard-ts/src/core.ts");
2533
+ const soundboard_stage = b.addWriteFiles();
2534
+ const soundboard_root = soundboard_stage.addCopyFile(b.path("tests/ts-core/soundboard_e2e_tests.zig"), "soundboard_e2e_tests.zig");
2535
+ _ = soundboard_stage.addCopyFile(b.path("examples/soundboard-ts/src/app.native"), "app.native");
2536
+ const soundboard_mod = b.createModule(.{
2537
+ .root_source_file = soundboard_root,
2538
+ .target = target,
2539
+ .optimize = optimize,
2540
+ });
2541
+ soundboard_mod.addImport("native_sdk", desktop_mod);
2542
+ soundboard_mod.addImport("ts_soundboard_core", soundboard_core_mod);
2543
+
2544
+ // The system-monitor-ts example's core and markup, tested the same
2545
+ // way — plus the ORIGINAL Zig example's committed sampler captures,
2546
+ // staged as fixtures so both ports parse the same recorded truth.
2547
+ const monitor_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/system-monitor-ts/src/core.ts");
2548
+ const monitor_stage = b.addWriteFiles();
2549
+ const monitor_root = monitor_stage.addCopyFile(b.path("tests/ts-core/system_monitor_e2e_tests.zig"), "system_monitor_e2e_tests.zig");
2550
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor-ts/src/app.native"), "app.native");
2551
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/sysctl.txt"), "fixtures/sysctl.txt");
2552
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/ps.txt"), "fixtures/ps.txt");
2553
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/vm_stat.txt"), "fixtures/vm_stat.txt");
2554
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/ps-edge.txt"), "fixtures/ps-edge.txt");
2555
+ const monitor_mod = b.createModule(.{
2556
+ .root_source_file = monitor_root,
2557
+ .target = target,
2558
+ .optimize = optimize,
2559
+ });
2560
+ monitor_mod.addImport("native_sdk", desktop_mod);
2561
+ monitor_mod.addImport("ts_system_monitor_core", monitor_core_mod);
2562
+
2563
+ // The stock-IDE suite runs the CLI's scaffold + editor-package plumbing
2564
+ // (the tooling module) and shells out to node for the real tsc.
2565
+ const scaffold_ide_mod = module(b, target, optimize, "tests/ts-core/scaffold_ide_e2e_tests.zig");
2566
+ scaffold_ide_mod.addImport("tooling", tooling_mod);
2567
+
2568
+ // The ai-chat-ts example's core and markup, tested the same way:
2569
+ // the chat client for an OpenAI-compatible endpoint, driven through
2570
+ // the fake fetch feed (no network) with its shipping markup.
2571
+ const ai_chat_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/ai-chat-ts/src/core.ts");
2572
+ const ai_chat_stage = b.addWriteFiles();
2573
+ const ai_chat_root = ai_chat_stage.addCopyFile(b.path("tests/ts-core/ai_chat_e2e_tests.zig"), "ai_chat_e2e_tests.zig");
2574
+ _ = ai_chat_stage.addCopyFile(b.path("examples/ai-chat-ts/src/app.native"), "app.native");
2575
+ const ai_chat_mod = b.createModule(.{
2576
+ .root_source_file = ai_chat_root,
2577
+ .target = target,
2578
+ .optimize = optimize,
2579
+ });
2580
+ ai_chat_mod.addImport("native_sdk", desktop_mod);
2581
+ ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2582
+
2583
+ return .{
2584
+ .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
2585
+ .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
2586
+ .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
2587
+ .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
2588
+ .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
2589
+ };
2590
+ }
2591
+
2592
+ /// Transpile one TS fixture core at build time and pair the emitted
2593
+ /// Zig with its rt kernel in one generated module.
2594
+ fn tsCoreFixtureModule(
2595
+ b: *std.Build,
2596
+ target: std.Build.ResolvedTarget,
2597
+ optimize: std.builtin.OptimizeMode,
2598
+ node: []const u8,
2599
+ fixture_path: []const u8,
2600
+ ) *std.Build.Module {
2601
+ const transpile = b.addSystemCommand(&.{node});
2602
+ transpile.addFileArg(b.path("packages/core/src/cli.ts"));
2603
+ transpile.addFileArg(b.path(fixture_path));
2604
+ transpile.addArg("-o");
2605
+ const emitted_core = transpile.addOutputFileArg("core.zig");
2606
+ // The transpiler reads its own sources, the SDK modules, and the
2607
+ // core's WHOLE import graph at run time; declare them all so edits
2608
+ // re-emit the fixture. The graph is declared as every sibling .ts of
2609
+ // the entry (a superset of the reachable imports: over-approximation
2610
+ // only re-runs the transpile, never misses a stale input).
2611
+ tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
2612
+ tsCoreAddDirInputs(b, transpile, std.fs.path.dirname(fixture_path) orelse ".");
2613
+ const transpiler_sources = [_][]const u8{
2614
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
2615
+ };
2616
+ for (transpiler_sources) |source| {
2617
+ transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
2618
+ }
2619
+
2620
+ // The emitted core imports "rt.zig" relatively: stage both files
2621
+ // into one generated directory to root the fixture module there.
2622
+ const staged = b.addWriteFiles();
2623
+ const core_root = staged.addCopyFile(emitted_core, "core.zig");
2624
+ _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
2625
+ return b.createModule(.{
2626
+ .root_source_file = core_root,
2627
+ .target = target,
2628
+ .optimize = optimize,
2629
+ });
2630
+ }
2631
+
2632
+ /// Declare every .ts file in `dir_path` (relative to the build root) as a
2633
+ /// file input of the transpile step — the multi-file staleness set.
2634
+ fn tsCoreAddDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, dir_path: []const u8) void {
2635
+ var dir = b.build_root.handle.openDir(b.graph.io, dir_path, .{ .iterate = true }) catch return;
2636
+ defer dir.close(b.graph.io);
2637
+ var it = dir.iterate();
2638
+ while (it.next(b.graph.io) catch null) |entry| {
2639
+ if (entry.kind != .file) continue;
2640
+ if (!std.mem.endsWith(u8, entry.name, ".ts")) continue;
2641
+ transpile.addFileInput(b.path(b.fmt("{s}/{s}", .{ dir_path, entry.name })));
2642
+ }
2643
+ }
2644
+
2433
2645
  fn filteredTestArtifact(b: *std.Build, mod: *std.Build.Module, name: []const u8, filters: []const []const u8) *std.Build.Step.Compile {
2434
2646
  // use_llvm: Zig 0.16.0's self-hosted x86_64 backend miscompiles the
2435
2647
  // SysV C ABI for f32-heavy signatures (native_sdk_app_viewport); see
package/build.zig.zon CHANGED
@@ -16,6 +16,7 @@
16
16
  "build.zig.zon",
17
17
  "docs",
18
18
  "examples",
19
+ "packages",
19
20
  "src",
20
21
  "templates",
21
22
  "tests",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
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
  "bin": {
@@ -17,20 +17,25 @@
17
17
  "build.zig",
18
18
  "build.zig.zon",
19
19
  "app.zon",
20
+ "packages/core/src",
21
+ "packages/core/sdk",
22
+ "packages/core/rt",
23
+ "packages/core/package.json",
24
+ "packages/core/package-lock.json",
20
25
  "third_party/webview2",
21
26
  "native-sdk.d.ts",
22
27
  "README.md",
23
28
  "LICENSE"
24
29
  ],
25
30
  "optionalDependencies": {
26
- "@native-sdk/cli-darwin-arm64": "0.4.4",
27
- "@native-sdk/cli-darwin-x64": "0.4.4",
28
- "@native-sdk/cli-linux-arm64-gnu": "0.4.4",
29
- "@native-sdk/cli-linux-arm64-musl": "0.4.4",
30
- "@native-sdk/cli-linux-x64-gnu": "0.4.4",
31
- "@native-sdk/cli-linux-x64-musl": "0.4.4",
32
- "@native-sdk/cli-win32-arm64": "0.4.4",
33
- "@native-sdk/cli-win32-x64": "0.4.4"
31
+ "@native-sdk/cli-darwin-arm64": "0.5.0",
32
+ "@native-sdk/cli-darwin-x64": "0.5.0",
33
+ "@native-sdk/cli-linux-arm64-gnu": "0.5.0",
34
+ "@native-sdk/cli-linux-arm64-musl": "0.5.0",
35
+ "@native-sdk/cli-linux-x64-gnu": "0.5.0",
36
+ "@native-sdk/cli-linux-x64-musl": "0.5.0",
37
+ "@native-sdk/cli-win32-arm64": "0.5.0",
38
+ "@native-sdk/cli-win32-x64": "0.5.0"
34
39
  },
35
40
  "repository": {
36
41
  "type": "git",
@@ -38,7 +43,7 @@
38
43
  },
39
44
  "homepage": "https://native-sdk.dev",
40
45
  "scripts": {
41
- "version": "npm run version:sync && git add ../../tools/native-sdk/main.zig npm/*/package.json package.json",
46
+ "version": "npm run version:sync && git add ../../tools/native-sdk/main.zig ../../packages/core/package.json ../../packages/core/package-lock.json ../../examples/soundboard-ts/package.json ../../examples/system-monitor-ts/package.json npm/*/package.json package.json",
42
47
  "version:sync": "node scripts/sync-version.js",
43
48
  "version:check": "node scripts/check-version-sync.js",
44
49
  "scripts:check": "node --check bin/native.js && node --check scripts/copy-native.js && node --check scripts/copy-framework.js && node --check scripts/sync-version.js && node --check scripts/check-version-sync.js && node --check scripts/check-framework-sync.js && node --check scripts/check-runtime-types.js && node scripts/copy-framework.js && node scripts/check-framework-sync.js && node scripts/check-runtime-types.js",