@native-sdk/cli 0.4.4 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/build/app.zig +371 -5
  2. package/build/ts_run.mjs +102 -0
  3. package/build.zig +255 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +19 -10
  6. package/packages/core/package-lock.json +44 -0
  7. package/packages/core/package.json +38 -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 +546 -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/platform/windows/webview2_host.cpp +24 -0
  33. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  34. package/src/primitives/app_manifest/root.zig +5 -0
  35. package/src/primitives/canvas/commands.zig +14 -7
  36. package/src/primitives/canvas/layout_audit.zig +5 -5
  37. package/src/primitives/canvas/lazy_tls.zig +73 -0
  38. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  39. package/src/primitives/canvas/root.zig +11 -0
  40. package/src/primitives/canvas/tests.zig +1 -0
  41. package/src/primitives/canvas/text_atlas.zig +40 -32
  42. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  43. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  44. package/src/primitives/canvas/text_spans.zig +39 -26
  45. package/src/primitives/canvas/tokens.zig +69 -0
  46. package/src/primitives/canvas/ui.zig +125 -0
  47. package/src/primitives/canvas/ui_markup.zig +22 -3
  48. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  49. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  50. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  51. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  52. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  53. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  54. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  55. package/src/primitives/canvas/ui_schema.zig +8 -0
  56. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  57. package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
  58. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  59. package/src/primitives/canvas/widget_layout.zig +138 -2
  60. package/src/primitives/canvas/widget_metrics.zig +16 -8
  61. package/src/primitives/canvas/widget_render.zig +25 -15
  62. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  63. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  64. package/src/root.zig +7 -0
  65. package/src/runtime/canvas_frame.zig +57 -36
  66. package/src/runtime/canvas_images.zig +9 -3
  67. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  68. package/src/runtime/canvas_widget_runtime.zig +7 -4
  69. package/src/runtime/core.zig +16 -0
  70. package/src/runtime/effects.zig +1525 -133
  71. package/src/runtime/effects_fetch_tests.zig +42 -0
  72. package/src/runtime/effects_file_tests.zig +220 -0
  73. package/src/runtime/effects_host_tests.zig +594 -0
  74. package/src/runtime/effects_tests.zig +287 -0
  75. package/src/runtime/root.zig +18 -0
  76. package/src/runtime/session_replay.zig +7 -1
  77. package/src/runtime/tests.zig +2 -0
  78. package/src/runtime/ts_core_host.zig +1505 -0
  79. package/src/runtime/ts_core_host_tests.zig +1408 -0
  80. package/src/runtime/ts_ui_app.zig +469 -0
  81. package/src/runtime/ui_app.zig +189 -38
  82. package/src/runtime/ui_app_tests.zig +221 -0
  83. package/src/runtime/ui_app_window_tests.zig +182 -0
  84. package/src/runtime/view_canvas.zig +24 -17
  85. package/src/runtime/view_widget_tree.zig +2 -2
  86. package/src/tooling/codesign.zig +212 -105
  87. package/src/tooling/doctor.zig +78 -0
  88. package/src/tooling/manifest.zig +47 -0
  89. package/src/tooling/package.zig +435 -20
  90. package/src/tooling/raw_manifest.zig +15 -0
  91. package/src/tooling/root.zig +1 -0
  92. package/src/tooling/templates.zig +777 -34
  93. package/src/tooling/ts_core.zig +1099 -0
  94. package/src/tooling/verbs.zig +105 -2
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,54 @@ 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-ts-toolchain-twins", "Verify the CLI's toolchain-resolution gate and its direct-`zig build` twin stay in lockstep (both resolve the aliased real compiler @typescript/old from packages/core — the same origin runtime imports it from — hold its resolved version against the manifest-read pin, never probe the unused @typescript/typescript6 wrapper, and teach instead of panicking)", &.{
466
+ // The resolution twins probe the aliased REAL compiler
467
+ // (@typescript/old — the package typed_ast.ts and ts_run.mjs
468
+ // actually load) — manifest AND entrypoint, in lockstep. The
469
+ // @typescript/typescript6 wrapper is never probed: nothing
470
+ // imports it at run time, and validating it false-rejects
471
+ // healthy conflict trees.
472
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
473
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
474
+ .{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"package.json\"" },
475
+ .{ .path = "build/app.zig", .pattern = "\"node_modules\", \"@typescript\", \"old\", \"lib\", \"typescript.js\"" },
476
+ // The doctrine both twins document at their predicates: validate
477
+ // only what runtime loads, from runtime's own walk origin, and
478
+ // leave the declared-but-unimported wrapper out of the verdict.
479
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "Validation tracks ONLY what runtime loads" },
480
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "wrapper is deliberately NOT probed" },
481
+ .{ .path = "build/app.zig", .pattern = "Validation tracks ONLY what runtime loads" },
482
+ .{ .path = "build/app.zig", .pattern = "wrapper is deliberately NOT probed" },
483
+ // The reciprocal cross-references that keep the twins findable
484
+ // from each other.
485
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "build/app.zig's tsToolchainResolution" },
486
+ .{ .path = "build/app.zig", .pattern = "transpilerResolution, this predicate's deliberate twin" },
487
+ // The version pin: both twins read the alias's RESOLVED
488
+ // package.json version and hold it against the exact
489
+ // `npm:typescript@X.Y.Z` pin read from the SDK's own
490
+ // packages/core/package.json (never hardcoded), and both carry
491
+ // the mismatch outcome plus its teaching naming the two versions.
492
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "parseAliasedCompilerPin" },
493
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "version_mismatch" },
494
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "npm:typescript@{s}" },
495
+ .{ .path = "build/app.zig", .pattern = "tsPinnedCompilerVersion" },
496
+ .{ .path = "build/app.zig", .pattern = "version_mismatch" },
497
+ .{ .path = "build/app.zig", .pattern = "npm:typescript@{s}" },
498
+ // The teachings: the checkout's one production-config-safe npm ci
499
+ // command in both surfaces, the reinstall for npm layouts, and the
500
+ // build graph's clean configure-time failure (never a panic).
501
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "pub const npm_ci_teaching_command = \"npm ci --include=dev\";" },
502
+ .{ .path = "src/tooling/ts_core.zig", .pattern = "reinstall @native-sdk/cli" },
503
+ .{ .path = "build/app.zig", .pattern = "npm ci --include=dev" },
504
+ .{ .path = "build/app.zig", .pattern = "cannot resolve its TypeScript toolchain" },
505
+ .{ .path = "build/app.zig", .pattern = "std.process.exit(1);" },
506
+ });
507
+ 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`)", &.{
508
+ .{ .path = "build/app.zig", .pattern = "app_analysis.zig" },
509
+ .{ .path = "build/app.zig", .pattern = "if (@hasDecl(app, \"main\")) _ = &app.main;" },
510
+ .{ .path = "build/app.zig", .pattern = "test_step.dependOn(&analysis_obj.step);" },
511
+ .{ .path = "src/runtime/ui_app.zig", .pattern = "has no default value - give every Model field a default" },
512
+ });
429
513
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-bridge-view-selector-helpers", "Verify injected view helpers accept string selectors", &.{
430
514
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "viewSelectorPayload(options)" },
431
515
  .{ .path = "src/platform/macos/cef_host.mm", .pattern = "viewSelectorPayload(options)" },
@@ -793,6 +877,7 @@ pub fn build(b: *std.Build) void {
793
877
  }
794
878
  addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
795
879
  addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
880
+ addTestStep(b, "test-markup-cli", "Run native markup CLI tests", markup_cli_tests);
796
881
  addTestStep(b, "test-tooling", "Run Native SDK tooling tests", tooling_tests);
797
882
  addTestStep(b, "test-eject-components", "Run ejected-component widget-identity tests", eject_components_tests);
798
883
 
@@ -914,12 +999,14 @@ pub fn build(b: *std.Build) void {
914
999
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
915
1000
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
916
1001
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
1002
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed);
917
1003
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
918
1004
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
919
1005
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed);
920
1006
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
921
1007
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
922
1008
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
1009
+ 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
1010
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
924
1011
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
925
1012
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
@@ -2279,10 +2366,15 @@ pub fn build(b: *std.Build) void {
2279
2366
  // carries the CLI as its executable (packaging only needs a real
2280
2367
  // Mach-O to sign); the check skips loudly on hosts without codesign
2281
2368
  // (any non-macOS machine) instead of pretending to have verified.
2369
+ // Signing that claims to sign now fails the package on hosts that
2370
+ // cannot run codesign (that IS the fix this step gates), so only a
2371
+ // macOS host requests adhoc here; elsewhere the package stays
2372
+ // unsigned and the check script below skips loudly as before.
2373
+ const package_signing_mode: []const u8 = if (b.graph.host.result.os.tag == .macos) "adhoc" else "none";
2282
2374
  const package_signing_run = b.addRunArtifact(host_cli_exe);
2283
2375
  package_signing_run.addArgs(&.{ "package", "--target", "macos", "--output", "zig-out/package/native-sdk-signing-verify.app", "--binary" });
2284
2376
  package_signing_run.addFileArg(host_cli_exe.getEmittedBin());
2285
- package_signing_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", "adhoc" });
2377
+ package_signing_run.addArgs(&.{ "--manifest", "app.zon", "--assets", "assets", "--optimize", optimize_name, "--signing", package_signing_mode });
2286
2378
  package_signing_run.has_side_effects = true;
2287
2379
  const package_signing_check = b.addSystemCommand(&.{
2288
2380
  "sh", "-c",
@@ -2430,6 +2522,168 @@ fn testArtifact(b: *std.Build, mod: *std.Build.Module) *std.Build.Step.Compile {
2430
2522
  return filteredTestArtifact(b, mod, "test", &.{});
2431
2523
  }
2432
2524
 
2525
+ /// The two transpiled-core end-to-end test binaries: the host/markup
2526
+ /// fixture suite (tests/ts-core) and the soundboard-ts example suite —
2527
+ /// the launch-gate port driven as a REAL app (its committed core, its
2528
+ /// shipping markup). Each runs the @native-sdk/core transpiler (node)
2529
+ /// over the TS core at build time, pairs the emitted core with its rt
2530
+ /// kernel in one generated module, and compiles the Zig test root
2531
+ /// against it plus the framework. Returns null — the suites are
2532
+ /// skipped, not failed — when node or the transpiler package's
2533
+ /// installed dependency (`npm ci` in packages/core) is missing.
2534
+ const TsCoreE2eArtifacts = struct {
2535
+ host: *std.Build.Step.Compile,
2536
+ soundboard: *std.Build.Step.Compile,
2537
+ system_monitor: *std.Build.Step.Compile,
2538
+ /// The stock-IDE contract: a fresh scaffold (and the committed TS
2539
+ /// example ports) typecheck under the REAL tsc with zero injected
2540
+ /// paths, and builds keep working with node_modules deleted.
2541
+ scaffold_ide: *std.Build.Step.Compile,
2542
+ ai_chat: *std.Build.Step.Compile,
2543
+ };
2544
+
2545
+ fn tsCoreE2eArtifact(
2546
+ b: *std.Build,
2547
+ target: std.Build.ResolvedTarget,
2548
+ optimize: std.builtin.OptimizeMode,
2549
+ desktop_mod: *std.Build.Module,
2550
+ tooling_mod: *std.Build.Module,
2551
+ ) ?TsCoreE2eArtifacts {
2552
+ const node = b.findProgram(&.{"node"}, &.{}) catch return null;
2553
+ b.build_root.handle.access(
2554
+ b.graph.io,
2555
+ "packages/core/node_modules/@typescript/typescript6",
2556
+ .{},
2557
+ ) catch return null;
2558
+
2559
+ // Each fixture stages its own copy of rt.zig, so each emitted core
2560
+ // owns a distinct rt kernel instance — the process contract the
2561
+ // coexistence e2e test pins (two live cores, no shared arenas).
2562
+ const fixture_mod = tsCoreFixtureModule(b, target, optimize, node, "tests/ts-core/fixture.ts");
2563
+ const markup_fixture_mod = tsCoreFixtureModule(b, target, optimize, node, "tests/ts-core/markup_fixture.ts");
2564
+
2565
+ const e2e_mod = module(b, target, optimize, "tests/ts-core/host_e2e_tests.zig");
2566
+ e2e_mod.addImport("native_sdk", desktop_mod);
2567
+ e2e_mod.addImport("ts_core_fixture", fixture_mod);
2568
+ e2e_mod.addImport("ts_markup_fixture", markup_fixture_mod);
2569
+
2570
+ // The soundboard-ts example's core and markup, tested as one app:
2571
+ // the test root stages beside a copy of the example's app.native so
2572
+ // the compiled markup engine builds the SHIPPING view over the
2573
+ // emitted model.
2574
+ const soundboard_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/soundboard-ts/src/core.ts");
2575
+ const soundboard_stage = b.addWriteFiles();
2576
+ const soundboard_root = soundboard_stage.addCopyFile(b.path("tests/ts-core/soundboard_e2e_tests.zig"), "soundboard_e2e_tests.zig");
2577
+ _ = soundboard_stage.addCopyFile(b.path("examples/soundboard-ts/src/app.native"), "app.native");
2578
+ const soundboard_mod = b.createModule(.{
2579
+ .root_source_file = soundboard_root,
2580
+ .target = target,
2581
+ .optimize = optimize,
2582
+ });
2583
+ soundboard_mod.addImport("native_sdk", desktop_mod);
2584
+ soundboard_mod.addImport("ts_soundboard_core", soundboard_core_mod);
2585
+
2586
+ // The system-monitor-ts example's core and markup, tested the same
2587
+ // way — plus the ORIGINAL Zig example's committed sampler captures,
2588
+ // staged as fixtures so both ports parse the same recorded truth.
2589
+ const monitor_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/system-monitor-ts/src/core.ts");
2590
+ const monitor_stage = b.addWriteFiles();
2591
+ const monitor_root = monitor_stage.addCopyFile(b.path("tests/ts-core/system_monitor_e2e_tests.zig"), "system_monitor_e2e_tests.zig");
2592
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor-ts/src/app.native"), "app.native");
2593
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/sysctl.txt"), "fixtures/sysctl.txt");
2594
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/ps.txt"), "fixtures/ps.txt");
2595
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/vm_stat.txt"), "fixtures/vm_stat.txt");
2596
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/ps-edge.txt"), "fixtures/ps-edge.txt");
2597
+ const monitor_mod = b.createModule(.{
2598
+ .root_source_file = monitor_root,
2599
+ .target = target,
2600
+ .optimize = optimize,
2601
+ });
2602
+ monitor_mod.addImport("native_sdk", desktop_mod);
2603
+ monitor_mod.addImport("ts_system_monitor_core", monitor_core_mod);
2604
+
2605
+ // The stock-IDE suite runs the CLI's scaffold + editor-package plumbing
2606
+ // (the tooling module) and shells out to node for the real tsc.
2607
+ const scaffold_ide_mod = module(b, target, optimize, "tests/ts-core/scaffold_ide_e2e_tests.zig");
2608
+ scaffold_ide_mod.addImport("tooling", tooling_mod);
2609
+
2610
+ // The ai-chat-ts example's core and markup, tested the same way:
2611
+ // the chat client for an OpenAI-compatible endpoint, driven through
2612
+ // the fake fetch feed (no network) with its shipping markup.
2613
+ const ai_chat_core_mod = tsCoreFixtureModule(b, target, optimize, node, "examples/ai-chat-ts/src/core.ts");
2614
+ const ai_chat_stage = b.addWriteFiles();
2615
+ const ai_chat_root = ai_chat_stage.addCopyFile(b.path("tests/ts-core/ai_chat_e2e_tests.zig"), "ai_chat_e2e_tests.zig");
2616
+ _ = ai_chat_stage.addCopyFile(b.path("examples/ai-chat-ts/src/app.native"), "app.native");
2617
+ const ai_chat_mod = b.createModule(.{
2618
+ .root_source_file = ai_chat_root,
2619
+ .target = target,
2620
+ .optimize = optimize,
2621
+ });
2622
+ ai_chat_mod.addImport("native_sdk", desktop_mod);
2623
+ ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2624
+
2625
+ return .{
2626
+ .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
2627
+ .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
2628
+ .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
2629
+ .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
2630
+ .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
2631
+ };
2632
+ }
2633
+
2634
+ /// Transpile one TS fixture core at build time and pair the emitted
2635
+ /// Zig with its rt kernel in one generated module.
2636
+ fn tsCoreFixtureModule(
2637
+ b: *std.Build,
2638
+ target: std.Build.ResolvedTarget,
2639
+ optimize: std.builtin.OptimizeMode,
2640
+ node: []const u8,
2641
+ fixture_path: []const u8,
2642
+ ) *std.Build.Module {
2643
+ const transpile = b.addSystemCommand(&.{node});
2644
+ transpile.addFileArg(b.path("packages/core/src/cli.ts"));
2645
+ transpile.addFileArg(b.path(fixture_path));
2646
+ transpile.addArg("-o");
2647
+ const emitted_core = transpile.addOutputFileArg("core.zig");
2648
+ // The transpiler reads its own sources, the SDK modules, and the
2649
+ // core's WHOLE import graph at run time; declare them all so edits
2650
+ // re-emit the fixture. The graph is declared as every sibling .ts of
2651
+ // the entry (a superset of the reachable imports: over-approximation
2652
+ // only re-runs the transpile, never misses a stale input).
2653
+ tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
2654
+ tsCoreAddDirInputs(b, transpile, std.fs.path.dirname(fixture_path) orelse ".");
2655
+ const transpiler_sources = [_][]const u8{
2656
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
2657
+ };
2658
+ for (transpiler_sources) |source| {
2659
+ transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
2660
+ }
2661
+
2662
+ // The emitted core imports "rt.zig" relatively: stage both files
2663
+ // into one generated directory to root the fixture module there.
2664
+ const staged = b.addWriteFiles();
2665
+ const core_root = staged.addCopyFile(emitted_core, "core.zig");
2666
+ _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
2667
+ return b.createModule(.{
2668
+ .root_source_file = core_root,
2669
+ .target = target,
2670
+ .optimize = optimize,
2671
+ });
2672
+ }
2673
+
2674
+ /// Declare every .ts file in `dir_path` (relative to the build root) as a
2675
+ /// file input of the transpile step — the multi-file staleness set.
2676
+ fn tsCoreAddDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, dir_path: []const u8) void {
2677
+ var dir = b.build_root.handle.openDir(b.graph.io, dir_path, .{ .iterate = true }) catch return;
2678
+ defer dir.close(b.graph.io);
2679
+ var it = dir.iterate();
2680
+ while (it.next(b.graph.io) catch null) |entry| {
2681
+ if (entry.kind != .file) continue;
2682
+ if (!std.mem.endsWith(u8, entry.name, ".ts")) continue;
2683
+ transpile.addFileInput(b.path(b.fmt("{s}/{s}", .{ dir_path, entry.name })));
2684
+ }
2685
+ }
2686
+
2433
2687
  fn filteredTestArtifact(b: *std.Build, mod: *std.Build.Module, name: []const u8, filters: []const []const u8) *std.Build.Step.Compile {
2434
2688
  // use_llvm: Zig 0.16.0's self-hosted x86_64 backend miscompiles the
2435
2689
  // 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.1",
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,29 @@
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
  ],
30
+ "dependencies": {
31
+ "@typescript/old": "npm:typescript@6.0.3",
32
+ "@typescript/typescript6": "6.0.2"
33
+ },
25
34
  "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"
35
+ "@native-sdk/cli-darwin-arm64": "0.5.1",
36
+ "@native-sdk/cli-darwin-x64": "0.5.1",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.5.1",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.5.1",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.5.1",
40
+ "@native-sdk/cli-linux-x64-musl": "0.5.1",
41
+ "@native-sdk/cli-win32-arm64": "0.5.1",
42
+ "@native-sdk/cli-win32-x64": "0.5.1"
34
43
  },
35
44
  "repository": {
36
45
  "type": "git",
@@ -38,7 +47,7 @@
38
47
  },
39
48
  "homepage": "https://native-sdk.dev",
40
49
  "scripts": {
41
- "version": "npm run version:sync && git add ../../tools/native-sdk/main.zig npm/*/package.json package.json",
50
+ "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
51
  "version:sync": "node scripts/sync-version.js",
43
52
  "version:check": "node scripts/check-version-sync.js",
44
53
  "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",
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@native-sdk/core",
3
+ "version": "0.5.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@native-sdk/core",
9
+ "version": "0.5.1",
10
+ "devDependencies": {
11
+ "@typescript/old": "npm:typescript@6.0.3",
12
+ "@typescript/typescript6": "6.0.2"
13
+ }
14
+ },
15
+ "node_modules/@typescript/old": {
16
+ "name": "typescript",
17
+ "version": "6.0.3",
18
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz",
19
+ "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==",
20
+ "dev": true,
21
+ "license": "Apache-2.0",
22
+ "bin": {
23
+ "tsc": "bin/tsc",
24
+ "tsserver": "bin/tsserver"
25
+ },
26
+ "engines": {
27
+ "node": ">=14.17"
28
+ }
29
+ },
30
+ "node_modules/@typescript/typescript6": {
31
+ "version": "6.0.2",
32
+ "resolved": "https://registry.npmjs.org/@typescript/typescript6/-/typescript6-6.0.2.tgz",
33
+ "integrity": "sha512-mbCddXd+jm7hfx7w2YU64/Av4/NqqeG3GoRZgxPcgoTxYjhrcfJRw9ULch71SS4G+Q3bOXFhRvPqjguN0Hyp5w==",
34
+ "dev": true,
35
+ "license": "Apache-2.0",
36
+ "dependencies": {
37
+ "@typescript/old": "npm:typescript@^6"
38
+ },
39
+ "bin": {
40
+ "tsc6": "bin/tsc6"
41
+ }
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@native-sdk/core",
3
+ "version": "0.5.1",
4
+ "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/vercel-labs/native.git",
8
+ "directory": "packages/core"
9
+ },
10
+ "homepage": "https://native-sdk.dev",
11
+ "type": "module",
12
+ "types": "./sdk/core.ts",
13
+ "files": [
14
+ "sdk"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./sdk/core.ts",
19
+ "default": "./sdk/core.ts"
20
+ },
21
+ "./text": {
22
+ "types": "./sdk/text.ts",
23
+ "default": "./sdk/text.ts"
24
+ },
25
+ "./events": {
26
+ "types": "./sdk/events.ts",
27
+ "default": "./sdk/events.ts"
28
+ }
29
+ },
30
+ "scripts": {
31
+ "test": "node --test \"test/*.test.ts\"",
32
+ "gate": "node scripts/gate.mjs"
33
+ },
34
+ "devDependencies": {
35
+ "@typescript/old": "npm:typescript@6.0.3",
36
+ "@typescript/typescript6": "6.0.2"
37
+ }
38
+ }