@native-sdk/cli 0.5.3 → 0.5.4

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 (79) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +223 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/src/emitter.ts +2586 -259
  10. package/skill-data/native-ui/SKILL.md +3 -2
  11. package/skill-data/ts-core/SKILL.md +9 -1
  12. package/src/app_runner/root.zig +81 -1
  13. package/src/app_runner/ts_core_main.zig +4 -0
  14. package/src/embed/tests.zig +119 -1
  15. package/src/platform/linux/gtk_host.c +112 -3
  16. package/src/platform/linux/root.zig +71 -0
  17. package/src/platform/macos/appkit_host.h +48 -2
  18. package/src/platform/macos/appkit_host.m +533 -34
  19. package/src/platform/macos/cef_host.mm +262 -10
  20. package/src/platform/macos/root.zig +92 -4
  21. package/src/platform/null_platform.zig +298 -5
  22. package/src/platform/root.zig +33 -0
  23. package/src/platform/types.zig +138 -4
  24. package/src/platform/windows/root.zig +134 -0
  25. package/src/platform/windows/webview2_host.cpp +152 -40
  26. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  27. package/src/primitives/app_manifest/root.zig +1 -0
  28. package/src/primitives/app_manifest/types.zig +32 -0
  29. package/src/primitives/canvas/tests.zig +1 -0
  30. package/src/primitives/canvas/ui.zig +11 -7
  31. package/src/primitives/canvas/ui_markup.zig +58 -34
  32. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  33. package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +1 -1
  36. package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
  37. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  38. package/src/primitives/canvas/ui_markup_tests.zig +29 -9
  39. package/src/primitives/canvas/ui_markup_view.zig +29 -11
  40. package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
  41. package/src/primitives/canvas/ui_schema.zig +13 -0
  42. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  43. package/src/root.zig +7 -0
  44. package/src/runtime/api.zig +6 -4
  45. package/src/runtime/bridge_payload.zig +7 -0
  46. package/src/runtime/bridge_responses.zig +5 -0
  47. package/src/runtime/builtin_bridge.zig +9 -4
  48. package/src/runtime/canvas_font_tests.zig +439 -2
  49. package/src/runtime/canvas_fonts.zig +61 -6
  50. package/src/runtime/canvas_image_tests.zig +195 -0
  51. package/src/runtime/canvas_images.zig +45 -12
  52. package/src/runtime/core.zig +58 -11
  53. package/src/runtime/effects.zig +1664 -43
  54. package/src/runtime/effects_fetch_tests.zig +89 -1
  55. package/src/runtime/effects_file_tests.zig +41 -1
  56. package/src/runtime/effects_image_tests.zig +1304 -0
  57. package/src/runtime/effects_tests.zig +153 -0
  58. package/src/runtime/flow.zig +17 -0
  59. package/src/runtime/root.zig +11 -0
  60. package/src/runtime/session_blobs.zig +689 -0
  61. package/src/runtime/session_journal.zig +85 -21
  62. package/src/runtime/session_record.zig +27 -2
  63. package/src/runtime/session_replay.zig +168 -16
  64. package/src/runtime/session_tests.zig +1992 -0
  65. package/src/runtime/shell_layout.zig +7 -0
  66. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  67. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +439 -4
  70. package/src/runtime/ts_core_host_tests.zig +41 -0
  71. package/src/runtime/ts_ui_app.zig +7 -0
  72. package/src/runtime/ui_app.zig +111 -6
  73. package/src/runtime/ui_app_window_tests.zig +468 -0
  74. package/src/runtime/window_command_bridge_tests.zig +117 -0
  75. package/src/runtime/window_storage.zig +32 -0
  76. package/src/runtime/window_views.zig +61 -1
  77. package/src/tooling/manifest.zig +75 -0
  78. package/src/tooling/raw_manifest.zig +2 -0
  79. package/src/tooling/templates.zig +219 -1
package/build/app.zig CHANGED
@@ -560,6 +560,18 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
560
560
  const exe = b.addExecutable(.{
561
561
  .name = app_options.name,
562
562
  .root_module = app_mod,
563
+ // The app executable crosses the platform C seam on every host
564
+ // call (the GTK host's `native_sdk_gtk_create_view` is a
565
+ // 22-parameter mix of pointers, sizes, ints, and doubles), and
566
+ // Zig 0.16.0's self-hosted x86_64 backend miscompiles exactly
567
+ // that calling-convention shape (see useLlvmWorkaround below):
568
+ // a Debug `native dev` on x86_64 Linux placed the stack-passed
569
+ // string arguments one slot off, so the host read a garbage
570
+ // `role` pointer and crashed in `native_sdk_strndup` while the
571
+ // register-passed `label` arrived intact. Every other artifact
572
+ // in this graph already forces LLVM on x86_64; the app exe —
573
+ // the one binary users actually run — must too.
574
+ .use_llvm = useLlvmWorkaround(target),
563
575
  });
564
576
  // Windows subsystem posture: release-shaped exes (`native build`,
565
577
  // and therefore everything `native package --target windows` wraps)
@@ -723,6 +735,19 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
723
735
  /// t: f32, r: f32, bo: f32, l: f32, kt: f32, kr: f32, kb: f32,
724
736
  /// kl: f32) callconv(.c) void { ... }
725
737
  ///
738
+ /// The same backend also mis-places STACK-passed integer/pointer arguments
739
+ /// in long mixed signatures with interleaved doubles: calling the GTK
740
+ /// host's `native_sdk_gtk_create_view` (22 params: 6 register ints, 4
741
+ /// doubles, 12 stack ints/pointers/sizes) from self-hosted Debug code
742
+ /// hands the clang-compiled callee arguments shifted by one stack slot
743
+ /// from `visible` onward — the callee's `role` pointer reads as the
744
+ /// caller's `enabled` value (a 4-byte 1 under 0xAA undefined fill,
745
+ /// faulting at 0xaaaaaaaa00000001) and `role_len` reads as the role
746
+ /// pointer. Register-passed arguments (`label`) arrive intact, which is
747
+ /// why the crash appears only at the first stack-passed string. Verified
748
+ /// against zig 0.16.0 on x86_64-linux with a standalone caller/callee
749
+ /// pair: self-hosted Debug corrupts, `-fllvm` is correct.
750
+ ///
726
751
  /// Force the LLVM backend on x86_64 until the upstream backend is fixed;
727
752
  /// Release modes already default to LLVM, so this only changes Debug.
728
753
  pub fn useLlvmWorkaround(target: std.Build.ResolvedTarget) ?bool {
@@ -921,7 +946,14 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
921
946
  // the layer stays out even on machines where the
922
947
  // development package is installed — libwebkitgtk is
923
948
  // neither linked nor required at runtime, and the
924
- // executable carries no WebKit reference at all.
949
+ // executable carries no WebKit reference at all. This
950
+ // is the expected, configured state of every canvas
951
+ // app on Linux, so the stub compile is deliberately
952
+ // silent — no build note, no compiler diagnostic (the
953
+ // host's seam comment explains why even an
954
+ // informational pragma is dangerous); a stubbed host
955
+ // teaches at runtime by reporting WebViewNotFound the
956
+ // moment an app actually uses a WebView.
925
957
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
926
958
  app_mod.linkSystemLibrary("gtk4", .{});
927
959
  app_mod.linkSystemLibrary("dl", .{});
@@ -974,6 +1006,14 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
974
1006
  // headers are reachable through the system include paths
975
1007
  // — no WebView2Loader.dll is installed or path-wired,
976
1008
  // and the executable carries no reference to it at all.
1009
+ // This is the expected, configured state of every
1010
+ // canvas app on Windows, so the stub compile is
1011
+ // deliberately silent — no build note, no compiler
1012
+ // diagnostic (the host's seam comment explains why
1013
+ // even an informational pragma is dangerous); a
1014
+ // stubbed host teaches at runtime by reporting
1015
+ // WebViewNotFound the moment an app actually uses a
1016
+ // WebView.
977
1017
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
978
1018
  },
979
1019
  .chromium => {
package/build.zig CHANGED
@@ -219,6 +219,14 @@ pub fn build(b: *std.Build) void {
219
219
  markup_cli_mod.addImport("markup_lsp", markup_lsp_mod);
220
220
  const markup_cli_tests = testArtifact(b, markup_cli_mod);
221
221
 
222
+ // The evals harness's Cmd wire-format decoder (copied next to every
223
+ // ts-track case harness at grading time). Its own tests run here —
224
+ // NOT at eval time — because a decoder that lags a
225
+ // cmd_format_version bump panics mid-eval inside case harnesses,
226
+ // where the failure reads as the graded app's, not the tooling's.
227
+ const evals_cmdview_mod = module(b, target, optimize, "evals/harness-lib/cmdview.zig");
228
+ const evals_cmdview_tests = testArtifact(b, evals_cmdview_mod);
229
+
222
230
  // `native version` names the commit the binary was built from, so
223
231
  // binary/framework skew ("your native binary may be stale") is a
224
232
  // one-command check. Falls back to "unknown" outside a git checkout.
@@ -438,6 +446,7 @@ pub fn build(b: *std.Build) void {
438
446
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
439
447
  test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
440
448
  test_step.dependOn(&b.addRunArtifact(markup_cli_tests).step);
449
+ test_step.dependOn(&b.addRunArtifact(evals_cmdview_tests).step);
441
450
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-package-types", "Verify package TypeScript platform feature names", &.{
442
451
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "NativeSdkCommandInfo" },
443
452
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "list(): Promise<NativeSdkCommandInfo[]>" },
@@ -540,6 +549,12 @@ pub fn build(b: *std.Build) void {
540
549
  .{ .path = "docs/src/app/media-producers/page.mdx", .pattern = "producer: media.MediaSurfaceProducer" },
541
550
  .{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
542
551
  });
552
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-session-replay-image-codec", "Verify the replay runner installs the host image codec headlessly (the desktop arms cannot link in unit tests; the null-fallback arm is covered in session_tests.zig)", &.{
553
+ .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, &null_platform, &replay_platform.services);" },
554
+ .{ .path = "src/platform/macos/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
555
+ .{ .path = "src/platform/linux/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
556
+ .{ .path = "src/platform/windows/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
557
+ });
543
558
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-js-view-helper-contracts", "Verify injected view helpers support label-first updates", &.{
544
559
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "update:function(options,patch)" },
545
560
  .{ .path = "src/platform/macos/cef_host.mm", .pattern = "update:function(options,patch)" },
@@ -570,6 +585,46 @@ pub fn build(b: *std.Build) void {
570
585
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "change != NATIVE_SDK_GST_STATE_CHANGE_ASYNC" },
571
586
  .{ .path = "src/platform/linux/gtk_host.c", .pattern = "#define NATIVE_SDK_GST_STATE_CHANGE_ASYNC 2" },
572
587
  });
588
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-linux-init-close-policy-refusal", "Verify the Linux platform init refuses a .hide main window with the one shared teaching (the pre-created startup window never passes the runtime's create gate, so a silent drop here meant quit-on-close for direct-SDK users)", &.{
589
+ // The gate itself is unit-tested cross-host (it is extern-free);
590
+ // this pins its WIRING into initWithOptions, which only a Linux
591
+ // link can execute.
592
+ .{ .path = "src/platform/linux/root.zig", .pattern = "try refuseUnsupportedMainWindowClosePolicy(window_options);" },
593
+ // One message, all seams: the platform-init refusal and the
594
+ // generated runner's comptime refusal teach with the same text.
595
+ .{ .path = "src/platform/linux/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
596
+ .{ .path = "src/app_runner/root.zig", .pattern = "close_policy \\\"hide\\\" is not supported on linux: the GTK host has no status item (tray), so nothing could bring the hidden window back - declare \\\"quit\\\" (the default), or scope the .hide declaration to macos/windows builds" },
597
+ .{ .path = "src/tooling/templates.zig", .pattern = "close_policy \\\\\\\"hide\\\\\\\" is not supported on linux" },
598
+ });
599
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-close-clears-policy-hidden", "Verify every macOS close exit leaves the policy-hidden set before its open=false emit (both hosts derive the frame event's hidden flag from set membership, and the Dock reopen re-shows every member — a close exit that skips the cleanup emits {open=false, hidden=true} and lets the reopen resurrect an app-closed window)", &.{
600
+ // AppKit: every close routes through NSWindow close/performClose,
601
+ // so the delegate's windowWillClose is the one cleanup site.
602
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
603
+ // CEF: the delegate cleanup covers the [window close] fallback,
604
+ // and the app-driven close of a browser-bearing window exits
605
+ // through orderOut WITHOUT reaching windowWillClose — that
606
+ // branch must do the set cleanup itself, before its emit.
607
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.host.policyHiddenWindows removeObject:@(self.windowId)];\n [self.host emitWindowFrameForWindowId:self.windowId open:NO];" },
608
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self.policyHiddenWindows removeObject:@(windowId)];\n [window orderOut:nil];\n [self emitWindowFrameForWindowId:windowId open:NO];" },
609
+ });
610
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-macos-cef-window-verbs-synchronous", "Verify the CEF host's show and minimize verbs run synchronously on the main thread, the close verb's discipline (a dispatch_async show returns success while the window is still in policyHiddenWindows — the runtime's post-success focus flip then emits {focused:true, hidden:true} until the queued block lands — and a show-then-close in one dispatch re-orders: the queued show lands AFTER the synchronous close and puts a retained ordered-out closed window back on the glass)", &.{
611
+ // The show verb: direct on main, dispatch_sync hop otherwise,
612
+ // with the window lookup INSIDE the block so a window closed
613
+ // before an off-main hop lands is a no-op, not a resurrection.
614
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n showBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), showBlock);\n }" },
615
+ // The minimize twin (a queued miniaturize captured past a
616
+ // synchronous close genies an app-closed window into the Dock).
617
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([NSThread isMainThread]) {\n miniaturizeBlock();\n } else {\n dispatch_sync(dispatch_get_main_queue(), miniaturizeBlock);\n }" },
618
+ // The C shims return success only after the synchronous verb —
619
+ // no dispatch_async between the lookup and the method call.
620
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!object.windows[@(window_id)]) return 0;\n [object miniaturizeWindowWithId:window_id];\n return 1;" },
621
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
622
+ // The AppKit host's twins are already synchronous direct calls
623
+ // (its runtime callbacks arrive on the main thread); these pins
624
+ // hold that symmetry.
625
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object showWindowWithId:window_id];\n return 1;" },
626
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[object miniaturizeWindowWithId:window_id];\n return 1;" },
627
+ });
573
628
  // The embedded-WebView layer must stay real AND declare-to-use: the
574
629
  // standard build graph puts the vendored WebView2 SDK header on the
575
630
  // include path exactly when app.zon declares web use (`if
@@ -693,6 +748,59 @@ pub fn build(b: *std.Build) void {
693
748
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)scheduleFrameEventEmission" },
694
749
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)emitScheduledFrameEvent" },
695
750
  });
751
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-stop-queued", "Verify the quit verb's stop is queued to the next loop turn on every synchronous-emit host (a synchronous emitShutdown nests the shutdown dispatch inside the requesting command's dispatch, seals the session journal before the command commits, and replay diverges)", &.{
752
+ // macOS (AppKit and CEF hosts): the main-queue hop, with the
753
+ // pre-run-loop inline fallback the failed-START precedent needs.
754
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!NSApp.running) {" },
755
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if (!NSApp.running) {" },
756
+ // Linux: the idle hop — the same seam the wake and
757
+ // frame-request paths ride.
758
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "static gboolean native_sdk_stop_idle(gpointer data)" },
759
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "g_idle_add(native_sdk_stop_idle, host);" },
760
+ // Windows was queued from the start: stop posts, the loop
761
+ // exits, and the shutdown emits after the loop at top level.
762
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "void native_sdk_windows_stop(Host *host) {" },
763
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "PostQuitMessage(0);" },
764
+ // The runtime ordering the queue protects: the recorder seals
765
+ // on the shutdown dispatch's exit, and the modeled host's
766
+ // queued seam keeps the runtime suites honest about it.
767
+ .{ .path = "src/runtime/flow.zig", .pattern = "if (event_value == .app_shutdown) recorder.finish();" },
768
+ .{ .path = "src/platform/null_platform.zig", .pattern = "pub fn takeQueuedQuit" },
769
+ });
770
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-quit-pre-run-pending", "Verify a PRE-RUN quit verb on the macOS hosts parks as a pending flag drained at top level, never the inline emit (an inline pre-run emit nests the shutdown inside the boot dispatch that requested it — the recorder seals the journal before that dispatch commits, the same bug the running-path queue fixes)", &.{
771
+ // The quit verb's own landing point: pre-run it PARKS — the
772
+ // inline emitShutdown+stop stays exclusive to
773
+ // native_sdk_appkit_stop, the host-side failure request the
774
+ // failed-START precedent rides (runWithCallback's didShutdown
775
+ // check).
776
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
777
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "object.pendingPreRunStop = YES;" },
778
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "void native_sdk_appkit_request_stop(native_sdk_appkit_host_t *host) {" },
779
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "object.pendingPreRunStop = YES;" },
780
+ // The drains: after the START dispatch (at the didShutdown
781
+ // decision point) and after the remaining pre-run dispatches
782
+ // (appearance/resize/window-frame, and AppKit's synchronous
783
+ // first canvas frame) — emitShutdown + stop at TOP LEVEL, once.
784
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
785
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
786
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([self drainPendingPreRunStop]) return;" },
787
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "- (BOOL)drainPendingPreRunStop {\n if (!self.pendingPreRunStop) return NO;\n self.pendingPreRunStop = NO;\n if (self.didShutdown) return NO;\n [self emitShutdown];\n [self stop];\n return YES;\n}" },
788
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "[self drainPendingPreRunStop];\n // A failed START handler requests shutdown synchronously" },
789
+ .{ .path = "src/platform/macos/cef_host.mm", .pattern = "if ([self drainPendingPreRunStop]) {\n shutdownCefIfNeeded();\n return;\n }" },
790
+ // The Zig split: the quit verb rides request_stop; the failed
791
+ // emit keeps the byte-for-byte host-side stop.
792
+ .{ .path = "src/platform/macos/root.zig", .pattern = "native_sdk_appkit_request_stop(self.host);" },
793
+ .{ .path = "src/platform/macos/root.zig", .pattern = "if (self.self) |mac| native_sdk_appkit_stop(mac.host);" },
794
+ });
795
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gtk-stop-idle-tracked", "Verify the GTK quit-stop idle source is tracked on the host, coalesced while pending, skipped after shutdown, and removed at destroy (an untracked second g_idle_add leaves a source holding a freed host after the loop quits)", &.{
796
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "guint stop_idle_source;" },
797
+ // The idle retires its own tracking before it emits.
798
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "host->stop_idle_source = 0;\n if (!host->did_shutdown) {" },
799
+ // Coalesce + post-shutdown skip, then the tracked add.
800
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->did_shutdown || host->stop_idle_source) return;\n host->stop_idle_source = g_idle_add(native_sdk_stop_idle, host);" },
801
+ // Destroy removes a still-pending stop turn.
802
+ .{ .path = "src/platform/linux/gtk_host.c", .pattern = "if (host->stop_idle_source) {\n g_source_remove(host->stop_idle_source);\n host->stop_idle_source = 0;\n }" },
803
+ });
696
804
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-gpu-occluded-frame-heartbeat", "Verify occluded windows throttle frame completions to a heartbeat and restore full cadence on reveal", &.{
697
805
  // macOS: occluded surfaces pace logical completions on the ~1 Hz
698
806
  // heartbeat (never stopping — on_frame-driven models stay gently
@@ -709,13 +817,20 @@ pub fn build(b: *std.Build) void {
709
817
  // sustain a spin.
710
818
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "scheduleFrameEventEmissionForPresentCompletion:YES" },
711
819
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)noteGpuSurfaceInputActivity" },
712
- // Windows: the same throttle keyed on the one reliable Win32
713
- // occlusion signal (minimize); restore re-arms the pending
714
- // one-shot timer at the frame-grid delay, and the input /
820
+ // Windows: the same throttle keyed on the two reliable
821
+ // occlusion facts — minimize (IsIconic) and the close_policy
822
+ // .hide hide (policy_hidden: a hidden menu-bar app must not
823
+ // spin its frame loop or its spectrum emissions full-rate for
824
+ // days). Restore re-arms the pending one-shot timer at the
825
+ // frame-grid delay through WM_SIZE, re-show through the show
826
+ // verb (SW_SHOW dispatches no WM_SIZE), and the input /
715
827
  // first-present exemptions ride one prompt-frame flag.
716
828
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "kGpuOccludedHeartbeatNs = 1000000000ull" },
717
829
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuSurfaceOccludedPacingActive" },
830
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "owner->second.policy_hidden) return true;" },
718
831
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "IsIconic(root)" },
832
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "!IsIconic(entry.second.hwnd) && !entry.second.policy_hidden" },
833
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "Re-show returns full frame cadence without dropping a beat" },
719
834
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpu_prompt_frame_pending" },
720
835
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "native_sdk_windows_note_gpu_surface_input" },
721
836
  // The runtime side of the measurement honesty: occluded logical
@@ -809,6 +924,100 @@ pub fn build(b: *std.Build) void {
809
924
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(base)" },
810
925
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkItalicSansFont(NativeSdkWeightedSansFont(@[ @\"Geist-Bold\", @\"Geist Bold\" ], base, NSFontWeightBold, YES, size))" },
811
926
  });
927
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-registered-font-cache-eviction", "Verify the AppKit host invalidates BOTH per-process registered-font caches at registration (the caches are per-process while font-id permanence is per-runtime, so a new runtime re-registering an id must never resolve the previous runtime's face or its measured widths): the NSFont size cache by prefix eviction and the measured-width NSCache by a process-global registration token in its key", &.{
928
+ // No SDK test tier links appkit_host.m (only managed app builds
929
+ // compile it), so the eviction wiring is pinned textually like
930
+ // the other AppKit host contracts: the shared accessor both the
931
+ // resolve and registration paths use, the prefix eviction inside
932
+ // register_font, and the honest lifetime comment.
933
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSString *, NSFont *> *NativeSdkRegisteredFontSizeCache(void)" },
934
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSString *stalePrefix = [NSString stringWithFormat:@\"%llu/\", (unsigned long long)font_id];" },
935
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if ([cachedKey hasPrefix:stalePrefix]) [sizeCache removeObjectForKey:cachedKey];" },
936
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "an id is only permanent within" },
937
+ // The width-cache half: NSCache cannot enumerate keys, so the
938
+ // measured-width cache is invalidated by a registration token
939
+ // drawn from one process-global monotonic counter (tokens never
940
+ // repeat, which is what lets unregister DELETE an id's record
941
+ // instead of retaining a bumped one per retired id) — the token
942
+ // table, the fresh stamp inside register_font, and the
943
+ // token-carrying key inside measure_text.
944
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSMutableDictionary<NSNumber *, NSNumber *> *NativeSdkRegisteredFontTokens(void)" },
945
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "unsigned long long token = ++NativeSdkRegisteredFontTokenCounter;" },
946
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkRegisteredFontTokens()[@(font_id)] = @(token);" },
947
+ // The stamp is also the registration's OWNERSHIP token: register
948
+ // reports it to the caller (`*out_token`), the runtime stores it
949
+ // beside the captured unregister owner, and unregister removes
950
+ // the id's state only while the id's current registration still
951
+ // carries it — an older runtime's deinit must never tear down a
952
+ // newer runtime's live face under a shared id (ids are
953
+ // per-runtime, host font state is per-process, last wins).
954
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "*out_token = token;" },
955
+ // The token and the registered face reach measure_text from ONE
956
+ // critical section (the snapshot helper): separate acquisitions
957
+ // let a registration land between the token read and the face
958
+ // resolution, pairing token 0 with the new registered face and
959
+ // caching registered widths under the reusable token-0 key —
960
+ // stale registered widths served after teardown. The snapshot
961
+ // signature and its measure_text call site are pinned so the
962
+ // two-acquisition shape cannot quietly return.
963
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSFont *NativeSdkRegisteredFontSnapshot(unsigned long long value, CGFloat size, unsigned long long *out_token)" },
964
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *registered = NativeSdkRegisteredFontSnapshot((unsigned long long)font_id, clamped, &token);" },
965
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSFont *font = registered ?: NativeSdkBuiltInFontForFontId(font_id, clamped);" },
966
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NSString stringWithFormat:@\"%llu/%llu/%.3f/%@\", (unsigned long long)font_id, token, (double)clamped, value]" },
967
+ // The width-cache WRITE is token-rechecked. Shaping runs outside
968
+ // the guard, so an unregister can land inside the shaping window:
969
+ // it clears the whole width cache (its only possible eviction),
970
+ // and an unconditional post-shape write would then repopulate the
971
+ // cleared cache with a retired-token entry — unreachable for
972
+ // serving (tokens never repeat) but resident until memory
973
+ // pressure, breaking the zero-retained-state teardown the clear
974
+ // exists to guarantee. measure_text therefore re-enters the
975
+ // descriptor guard after shaping and writes only while the id's
976
+ // current token still equals the snapshotted one; token 0
977
+ // (built-in resolution — never registered, so never cleared)
978
+ // caches without the recheck. Both branches are pinned so the
979
+ // unconditional-write shape cannot quietly return.
980
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (token == 0) {" },
981
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSNumber *currentToken = NativeSdkRegisteredFontTokens()[@(font_id)];" },
982
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (currentToken && currentToken.unsignedLongLongValue == token) {" },
983
+ // The teardown half: Runtime.deinit returns the host-side
984
+ // registration through the unregister owner each font entry
985
+ // captured at registration time (never live `options.platform`,
986
+ // which is publicly mutable), and the ObjC removal drops the
987
+ // descriptor, the size-cache entries, AND the token record —
988
+ // zero retained state per retired id. Pinned like the
989
+ // registration half (appkit_host.m has no SDK test tier); the
990
+ // capture and the deinit call site are pinned too so the seam
991
+ // can never silently lose its one caller or regress to the live
992
+ // read, and the embed cycle and platform-swap tests assert both
993
+ // behaviorally against null platform recorders.
994
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "int native_sdk_appkit_unregister_font(uint64_t font_id, uint64_t token) {" },
995
+ // The token-match guard itself: reverting removal to id-keyed
996
+ // (deleting whatever the id currently holds, whoever registered
997
+ // it) must fail here — the embed suite's survives-teardown test
998
+ // pins the same guard behaviorally against the null platform's
999
+ // host-font mirror.
1000
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "if (!current || current.unsignedLongLongValue != token) return 1;" },
1001
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NativeSdkRegisteredFontTokens() removeObjectForKey:@(font_id)];" },
1002
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[table removeObjectForKey:@(font_id)];" },
1003
+ // Teardown must also CLEAR the measured-width NSCache: a
1004
+ // retiring token's entries can never be served again (tokens
1005
+ // never repeat) but they stay resident until memory pressure,
1006
+ // and NSCache cannot enumerate keys, so the whole-cache clear on
1007
+ // the token-matched path is the only release. Pinned textually
1008
+ // because no behavioral tier can observe it — only managed app
1009
+ // builds compile appkit_host.m, so no SDK test can watch the
1010
+ // ObjC cache empty. The shared accessor and its measure_text
1011
+ // call site are pinned with the clear so the cache cannot
1012
+ // quietly retreat to a function-local static the unregister
1013
+ // path has no way to reach.
1014
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "static NSCache<NSString *, NSNumber *> *NativeSdkMeasuredWidthCache(void)" },
1015
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "[NativeSdkMeasuredWidthCache() removeAllObjects];" },
1016
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSCache<NSString *, NSNumber *> *widthCache = NativeSdkMeasuredWidthCache();" },
1017
+ .{ .path = "src/runtime/canvas_fonts.zig", .pattern = ".host_unregister_fn = services.unregister_gpu_surface_font_fn," },
1018
+ .{ .path = "src/runtime/canvas_fonts.zig", .pattern = ".host_registration_token = host_token," },
1019
+ .{ .path = "src/runtime/core.zig", .pattern = "host_unregister_fn(entry.host_unregister_context, entry.id, entry.host_registration_token) catch {};" },
1020
+ });
812
1021
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-widget-cursor-bridge", "Verify AppKit GPU widgets apply retained cursor intent", &.{
813
1022
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "native_sdk_appkit_set_view_cursor" },
814
1023
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "resetCursorRects" },
@@ -916,9 +1125,19 @@ pub fn build(b: *std.Build) void {
916
1125
  for (desktop_test_shard_specs, desktop_test_shards) |spec, shard_tests| {
917
1126
  addTestStep(b, b.fmt("test-desktop-{s}", .{spec.name}), spec.description, shard_tests);
918
1127
  }
1128
+ // The font-registry suite as its own step so CI lanes on real
1129
+ // Windows hardware can run it natively: the whole font pipeline
1130
+ // (TrueType parsing, glyph rasterization, the reference renderer)
1131
+ // is platform-neutral Zig, and this suite's Chinese-receipt test
1132
+ // registers a committed CJK face through the app-fonts seam and
1133
+ // proves the rendered string is real glyphs, not tofu — running it
1134
+ // on a Windows runner makes that a Windows-native receipt. The same
1135
+ // tests also run inside `zig build test` via the canvas-frame shard.
1136
+ addTestStep(b, "test-canvas-fonts", "Run the runtime font-registry tests (includes the registered-CJK Chinese receipt)", filteredTestArtifact(b, desktop_mod, "canvas-fonts-tests", &.{"runtime.canvas_font_tests.test"}));
919
1137
  addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
920
1138
  addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
921
1139
  addTestStep(b, "test-markup-cli", "Run native markup CLI tests", markup_cli_tests);
1140
+ addTestStep(b, "test-evals-cmdview", "Run the evals harness Cmd wire decoder tests", evals_cmdview_tests);
922
1141
  addTestStep(b, "test-tooling", "Run Native SDK tooling tests", tooling_tests);
923
1142
  addTestStep(b, "test-eject-components", "Run ejected-component widget-identity tests", eject_components_tests);
924
1143
 
@@ -1049,6 +1268,7 @@ pub fn build(b: *std.Build) void {
1049
1268
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
1050
1269
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed);
1051
1270
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
1271
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed);
1052
1272
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
1053
1273
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
1054
1274
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned);
package/native-sdk.d.ts CHANGED
@@ -25,6 +25,8 @@ export interface NativeSdkWindowInfo {
25
25
  title: string;
26
26
  open: boolean;
27
27
  focused: boolean;
28
+ /** Alive but hidden by `close_policy = "hide"` — still open, not focused, invisible until re-shown. */
29
+ hidden: boolean;
28
30
  x: number;
29
31
  y: number;
30
32
  width: number;
@@ -419,7 +421,21 @@ export type NativeSdkPlatformFeature =
419
421
  | "app_activation_events"
420
422
  | "appActivationEvents"
421
423
  | "gpu_surfaces"
422
- | "gpuSurfaces";
424
+ | "gpuSurfaces"
425
+ | "gpu_surface_scroll_drivers"
426
+ | "gpuSurfaceScrollDrivers"
427
+ | "context_menus"
428
+ | "contextMenus"
429
+ | "view_surface_adoption"
430
+ | "viewSurfaceAdoption"
431
+ | "audio_playback"
432
+ | "audioPlayback"
433
+ | "audio_streaming"
434
+ | "audioStreaming"
435
+ | "audio_spectrum"
436
+ | "audioSpectrum"
437
+ | "window_hide_on_close"
438
+ | "windowHideOnClose";
423
439
 
424
440
  export type NativeSdkPlatformFeatureSelector =
425
441
  | { feature: NativeSdkPlatformFeature; name?: never }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
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": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.5.3",
36
- "@native-sdk/cli-darwin-x64": "0.5.3",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.5.3",
38
- "@native-sdk/cli-linux-arm64-musl": "0.5.3",
39
- "@native-sdk/cli-linux-x64-gnu": "0.5.3",
40
- "@native-sdk/cli-linux-x64-musl": "0.5.3",
41
- "@native-sdk/cli-win32-arm64": "0.5.3",
42
- "@native-sdk/cli-win32-x64": "0.5.3"
35
+ "@native-sdk/cli-darwin-arm64": "0.5.4",
36
+ "@native-sdk/cli-darwin-x64": "0.5.4",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.5.4",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.5.4",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.5.4",
40
+ "@native-sdk/cli-linux-x64-musl": "0.5.4",
41
+ "@native-sdk/cli-win32-arm64": "0.5.4",
42
+ "@native-sdk/cli-win32-x64": "0.5.4"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.5.3",
9
+ "version": "0.5.4",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
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
5
  "repository": {
6
6
  "type": "git",