@native-sdk/cli 0.5.0 → 0.5.2

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 (60) hide show
  1. package/build/app.zig +198 -13
  2. package/build/ts_run.mjs +58 -19
  3. package/build.zig +42 -0
  4. package/package.json +13 -9
  5. package/packages/core/package-lock.json +4 -3
  6. package/packages/core/package.json +3 -2
  7. package/packages/core/src/typed_ast.ts +11 -1
  8. package/skill-data/native-ui/SKILL.md +2 -2
  9. package/src/platform/types.zig +9 -0
  10. package/src/platform/windows/webview2_host.cpp +24 -0
  11. package/src/primitives/canvas/layout_audit.zig +5 -5
  12. package/src/primitives/canvas/root.zig +6 -0
  13. package/src/primitives/canvas/tokens.zig +185 -7
  14. package/src/primitives/canvas/ui.zig +27 -5
  15. package/src/primitives/canvas/ui_markup.zig +27 -4
  16. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  17. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  18. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  19. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  20. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  21. package/src/primitives/canvas/ui_schema.zig +15 -1
  22. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  23. package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
  24. package/src/primitives/canvas/widget_layout.zig +142 -3
  25. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  26. package/src/primitives/canvas/widget_metrics.zig +16 -8
  27. package/src/primitives/canvas/widget_tree.zig +14 -2
  28. package/src/primitives/canvas/widgets.zig +12 -0
  29. package/src/runtime/automation_widget_dispatch.zig +95 -28
  30. package/src/runtime/canvas_frame.zig +15 -0
  31. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  32. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  33. package/src/runtime/canvas_widget_events.zig +1271 -3
  34. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  35. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  36. package/src/runtime/canvas_widget_state.zig +82 -5
  37. package/src/runtime/core.zig +30 -0
  38. package/src/runtime/effects.zig +1037 -133
  39. package/src/runtime/effects_fetch_tests.zig +42 -0
  40. package/src/runtime/effects_file_tests.zig +220 -0
  41. package/src/runtime/effects_tests.zig +287 -0
  42. package/src/runtime/flow.zig +24 -1
  43. package/src/runtime/gpu_surface_events.zig +44 -5
  44. package/src/runtime/session_journal.zig +25 -13
  45. package/src/runtime/session_record.zig +166 -0
  46. package/src/runtime/session_tests.zig +453 -0
  47. package/src/runtime/ui_app.zig +137 -39
  48. package/src/runtime/ui_app_tests.zig +681 -0
  49. package/src/runtime/ui_app_window_tests.zig +182 -0
  50. package/src/runtime/view.zig +86 -0
  51. package/src/runtime/view_widget_text.zig +18 -1
  52. package/src/runtime/view_widget_tree.zig +339 -20
  53. package/src/runtime/widget_bridge.zig +26 -0
  54. package/src/runtime/window_storage.zig +61 -15
  55. package/src/runtime/window_view_runtime.zig +13 -0
  56. package/src/runtime/window_views.zig +6 -0
  57. package/src/tooling/package.zig +311 -8
  58. package/src/tooling/templates.zig +97 -9
  59. package/src/tooling/ts_core.zig +626 -13
  60. package/src/tooling/verbs.zig +88 -2
@@ -433,7 +433,15 @@ fn tsAppMarkup() []const u8 {
433
433
  \\ <text grow="1">ticks {tickCount}</text>
434
434
  \\ <button size="sm" on-press="stamp">Stamp</button>
435
435
  \\ </row>
436
- \\ <status-bar>total: {total} | stamped: {stampedMs}ms</status-bar>
436
+ \\ <!-- The empty state is markup, not model surgery: stampedMs starts
437
+ \\ at -1 (never stamped), and the view says what Stamp will do
438
+ \\ instead of printing "-1ms". -->
439
+ \\ <if test="{stampedMs < 0}">
440
+ \\ <status-bar>total: {total} | press Stamp for a timestamp</status-bar>
441
+ \\ </if>
442
+ \\ <else>
443
+ \\ <status-bar>total: {total} | stamped: {stampedMs}ms</status-bar>
444
+ \\ </else>
437
445
  \\</column>
438
446
  \\
439
447
  ;
@@ -491,8 +499,8 @@ fn tsSlimReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
491
499
  \\
492
500
  \\## Requirements
493
501
  \\
494
- \\Node.js 22+ on PATH (the TypeScript-to-native transpiler runs at build
495
- \\time; your shipped binary carries none of it).
502
+ \\Node.js 22.15+ (on the 23 line: 23.5+) on PATH (the TypeScript-to-native
503
+ \\transpiler runs at build time; your shipped binary carries none of it).
496
504
  \\
497
505
  );
498
506
  return out.toOwnedSlice(allocator);
@@ -1388,7 +1396,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1388
1396
  \\
1389
1397
  \\pub fn build(b: *std.Build) void {
1390
1398
  \\ const target = nativeSdkTarget(b);
1391
- \\ const optimize = b.standardOptimizeOption(.{});
1399
+ \\ // -Doptimize is registered by hand (not the std helper) so the
1400
+ \\ // graph can tell "unset" from "explicit": run/dev default to
1401
+ \\ // Debug for the edit loop, while `zig build package` wraps its own
1402
+ \\ // release-shaped exe — the same split `native dev`/`native build`
1403
+ \\ // apply. An explicit -Doptimize (or --release) pins both roles.
1404
+ \\ const optimize_request = b.option(std.builtin.OptimizeMode, "optimize", "Prioritize performance, safety, or binary size");
1405
+ \\ const optimize = optimizeMode(b, optimize_request, .Debug);
1406
+ \\ const package_optimize = optimizeMode(b, optimize_request, .ReleaseFast);
1392
1407
  \\ const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
1393
1408
  \\ const trace_option = b.option(TraceOption, "trace", "Trace output: off, events, runtime, all") orelse .events;
1394
1409
  \\ const debug_overlay = b.option(bool, "debug-overlay", "Enable debug overlay output") orelse false;
@@ -1400,7 +1415,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1400
1415
  \\ const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
1401
1416
  \\ const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux") orelse .macos;
1402
1417
  \\ const native_sdk_path = b.option([]const u8, "native-sdk-path", "Path to the Native SDK framework checkout") orelse default_native_sdk_path;
1403
- \\ const optimize_name = @tagName(optimize);
1418
+ \\ const package_optimize_name = @tagName(package_optimize);
1404
1419
  \\ const selected_platform: PlatformOption = switch (platform_option) {
1405
1420
  \\ .auto => if (target.result.os.tag == .macos) .macos else if (target.result.os.tag == .linux) .linux else if (target.result.os.tag == .windows) .windows else .@"null",
1406
1421
  \\ else => platform_option,
@@ -1452,6 +1467,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1452
1467
  \\ .name = app_exe_name,
1453
1468
  \\ .root_module = app_mod,
1454
1469
  \\ });
1470
+ \\ // Windows subsystem posture (mirrors the Native SDK build graph):
1471
+ \\ // release-shaped exes are GUI-subsystem so the app never flashes a
1472
+ \\ // console behind its window; Debug keeps the console for dev logs.
1473
+ \\ // Redirected logging still works on GUI exes - only console
1474
+ \\ // AUTO-allocation is subsystem-gated.
1475
+ \\ if (target.result.os.tag == .windows and optimize != .Debug) {
1476
+ \\ exe.subsystem = .windows;
1477
+ \\ }
1455
1478
  \\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, web_layer, native_sdk_path, cef_dir, cef_auto_install);
1456
1479
  \\ b.installArtifact(exe);
1457
1480
  \\
@@ -1479,6 +1502,33 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1479
1502
  \\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
1480
1503
  \\ dev_step.dependOn(&dev.step);
1481
1504
  \\
1505
+ \\ // `zig build package` wraps its own exe: release-shaped by default
1506
+ \\ // (ReleaseFast, GUI subsystem on Windows) so the packaged artifact
1507
+ \\ // is never a Debug console binary just because the dev loop
1508
+ \\ // defaults to Debug. When -Doptimize/--release pinned one mode for
1509
+ \\ // everything, the roles agree and the dev exe is reused as-is.
1510
+ \\ const package_exe = if (package_optimize == optimize) exe else pkg: {
1511
+ \\ const package_sdk_mod = nativeSdkModule(b, target, package_optimize, native_sdk_path);
1512
+ \\ const package_runner_mod = localModule(b, target, package_optimize, "src/runner.zig");
1513
+ \\ package_runner_mod.addImport("native_sdk", package_sdk_mod);
1514
+ \\ package_runner_mod.addImport("build_options", options_mod);
1515
+ \\ package_runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("app.zon") }));
1516
+ \\ const package_app_mod = localModule(b, target, package_optimize, "src/main.zig");
1517
+ \\ package_app_mod.addImport("native_sdk", package_sdk_mod);
1518
+ \\ package_app_mod.addImport("runner", package_runner_mod);
1519
+ \\ const built = b.addExecutable(.{
1520
+ \\ .name = app_exe_name,
1521
+ \\ .root_module = package_app_mod,
1522
+ \\ });
1523
+ \\ // Same subsystem posture as the dev exe above, keyed on this
1524
+ \\ // exe's own mode: release-shaped Windows exes are GUI-subsystem.
1525
+ \\ if (target.result.os.tag == .windows and package_optimize != .Debug) {
1526
+ \\ built.subsystem = .windows;
1527
+ \\ }
1528
+ \\ linkPlatform(b, target, package_app_mod, built, selected_platform, web_engine, web_layer, native_sdk_path, cef_dir, cef_auto_install);
1529
+ \\ break :pkg built;
1530
+ \\ };
1531
+ \\
1482
1532
  \\ const package = b.addSystemCommand(&.{
1483
1533
  \\ "native",
1484
1534
  \\ "package",
@@ -1492,9 +1542,9 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1492
1542
  try out.appendSlice(allocator,
1493
1543
  \\,
1494
1544
  \\ "--optimize",
1495
- \\ optimize_name,
1545
+ \\ package_optimize_name,
1496
1546
  \\ "--output",
1497
- \\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target), optimize_name, packageSuffix(package_target) }),
1547
+ \\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target), package_optimize_name, packageSuffix(package_target) }),
1498
1548
  \\ "--binary",
1499
1549
  \\ });
1500
1550
  \\ // The CLI resolves SDK-owned package inputs (the vendored WebView2
@@ -1502,7 +1552,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1502
1552
  \\ // belong to a different checkout than the one this build compiled
1503
1553
  \\ // against, so hand the same root over explicitly.
1504
1554
  \\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
1505
- \\ package.addFileArg(exe.getEmittedBin());
1555
+ \\ package.addFileArg(package_exe.getEmittedBin());
1506
1556
  \\ package.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
1507
1557
  \\ // Forward the RESOLVED web-layer decision, never the raw inputs:
1508
1558
  \\ // this graph already decided web vs native-only for the exe it is
@@ -1512,7 +1562,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1512
1562
  \\ // exe/package agreement structural.
1513
1563
  \\ package.addArgs(&.{ "--web-layer", if (web_layer) "include" else "exclude" });
1514
1564
  \\ if (cef_auto_install) package.addArg("--cef-auto-install");
1515
- \\ package.step.dependOn(&exe.step);
1565
+ \\ package.step.dependOn(&package_exe.step);
1516
1566
  \\ package.step.dependOn(&frontend_build.step);
1517
1567
  \\ const package_step = b.step("package", "Create a local package artifact");
1518
1568
  \\ package_step.dependOn(&package.step);
@@ -1522,6 +1572,21 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1522
1572
  \\ test_step.dependOn(&b.addRunArtifact(tests).step);
1523
1573
  \\}
1524
1574
  \\
1575
+ \\// Resolve the optimize mode for one exe role (mirrors the Native SDK
1576
+ \\// build graph): an explicit -Doptimize wins for every role, --release
1577
+ \\// resolves through zig's release_mode, and only when neither was
1578
+ \\// passed does the role keep its own default — Debug for the dev loop,
1579
+ \\// ReleaseFast for the exe `zig build package` wraps.
1580
+ \\fn optimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, default_mode: std.builtin.OptimizeMode) std.builtin.OptimizeMode {
1581
+ \\ if (requested) |mode| return mode;
1582
+ \\ return switch (b.release_mode) {
1583
+ \\ .off => default_mode,
1584
+ \\ .any, .fast => .ReleaseFast,
1585
+ \\ .safe => .ReleaseSafe,
1586
+ \\ .small => .ReleaseSmall,
1587
+ \\ };
1588
+ \\}
1589
+ \\
1525
1590
  \\fn nativeSdkTarget(b: *std.Build) std.Build.ResolvedTarget {
1526
1591
  \\ const target = b.standardTargetOptions(.{});
1527
1592
  \\ if (target.result.os.tag != .macos) return target;
@@ -3549,6 +3614,29 @@ test "writeDefaultApp emits Vite project files" {
3549
3614
  // stub define and webkitgtk-6.0 is not linked when native-only.
3550
3615
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"") != null);
3551
3616
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (!web_layer) return;") != null);
3617
+ // Release-shaped Windows exes must be GUI-subsystem (same posture as
3618
+ // the SDK build graph) so packaged scaffold apps never flash a console.
3619
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (target.result.os.tag == .windows and optimize != .Debug) {") != null);
3620
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "exe.subsystem = .windows;") != null);
3621
+ // The package step wraps its own release-shaped exe: Debug stays the
3622
+ // run/dev default, but `zig build package` must never ship a Debug
3623
+ // (console-subsystem) binary unless the user pinned the mode
3624
+ // explicitly. The --optimize arg and the artifact name follow the
3625
+ // package exe's actual mode, and the exe carries its own
3626
+ // subsystem-posture check keyed on that mode.
3627
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const optimize_request = b.option(std.builtin.OptimizeMode, \"optimize\"") != null);
3628
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const optimize = optimizeMode(b, optimize_request, .Debug);") != null);
3629
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const package_optimize = optimizeMode(b, optimize_request, .ReleaseFast);") != null);
3630
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const package_exe = if (package_optimize == optimize) exe else pkg: {") != null);
3631
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (target.result.os.tag == .windows and package_optimize != .Debug) {") != null);
3632
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "built.subsystem = .windows;") != null);
3633
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addFileArg(package_exe.getEmittedBin());") != null);
3634
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.step.dependOn(&package_exe.step);") != null);
3635
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package_optimize_name,") != null);
3636
+ // No stale wiring: the package step must not reference the dev exe
3637
+ // or the old single-mode name.
3638
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addFileArg(exe.getEmittedBin());") == null);
3639
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "standardOptimizeOption") == null);
3552
3640
  try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "frontend/dist") != null);
3553
3641
  try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "127.0.0.1:5173") != null);
3554
3642
  try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@import(\"app_manifest_zon\")") != null);