@native-sdk/cli 0.5.3 → 0.6.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 (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
package/build/app.zig CHANGED
@@ -40,6 +40,17 @@ pub const AppOptions = struct {
40
40
  /// "../.." so `src/`, `app.zon`, and `assets/` keep resolving in the
41
41
  /// app directory rather than the cache directory.
42
42
  app_root: []const u8 = ".",
43
+ /// Live `<terminal>` sessions: set true AND pin ghostty as a LAZY
44
+ /// dependency in the app's OWN build.zig.zon (the examples/workbench
45
+ /// pin) — the framework then resolves `ghostty-vt` with the app
46
+ /// module's target/optimize and the safe flags (simd off, no macOS
47
+ /// app or xcframework artifacts), and the runtime owns the emulator
48
+ /// behind every `<terminal pty={key}>` binding. Default false wires
49
+ /// the stub: `<terminal>` renders the honest empty surface, and the
50
+ /// build never traverses ghostty's dependency graph (whose configure
51
+ /// step walks wuffs/translate_c and whose full build pulls harfbuzz)
52
+ /// — the load-bearing property for scaffolded apps.
53
+ terminal_sessions: bool = false,
43
54
  };
44
55
 
45
56
  /// Which core the app tree carries. No flag and no config anywhere: the
@@ -560,6 +571,18 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
560
571
  const exe = b.addExecutable(.{
561
572
  .name = app_options.name,
562
573
  .root_module = app_mod,
574
+ // The app executable crosses the platform C seam on every host
575
+ // call (the GTK host's `native_sdk_gtk_create_view` is a
576
+ // 22-parameter mix of pointers, sizes, ints, and doubles), and
577
+ // Zig 0.16.0's self-hosted x86_64 backend miscompiles exactly
578
+ // that calling-convention shape (see useLlvmWorkaround below):
579
+ // a Debug `native dev` on x86_64 Linux placed the stack-passed
580
+ // string arguments one slot off, so the host read a garbage
581
+ // `role` pointer and crashed in `native_sdk_strndup` while the
582
+ // register-passed `label` arrived intact. Every other artifact
583
+ // in this graph already forces LLVM on x86_64; the app exe —
584
+ // the one binary users actually run — must too.
585
+ .use_llvm = useLlvmWorkaround(target),
563
586
  });
564
587
  // Windows subsystem posture: release-shaped exes (`native build`,
565
588
  // and therefore everything `native package --target windows` wraps)
@@ -723,6 +746,19 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
723
746
  /// t: f32, r: f32, bo: f32, l: f32, kt: f32, kr: f32, kb: f32,
724
747
  /// kl: f32) callconv(.c) void { ... }
725
748
  ///
749
+ /// The same backend also mis-places STACK-passed integer/pointer arguments
750
+ /// in long mixed signatures with interleaved doubles: calling the GTK
751
+ /// host's `native_sdk_gtk_create_view` (22 params: 6 register ints, 4
752
+ /// doubles, 12 stack ints/pointers/sizes) from self-hosted Debug code
753
+ /// hands the clang-compiled callee arguments shifted by one stack slot
754
+ /// from `visible` onward — the callee's `role` pointer reads as the
755
+ /// caller's `enabled` value (a 4-byte 1 under 0xAA undefined fill,
756
+ /// faulting at 0xaaaaaaaa00000001) and `role_len` reads as the role
757
+ /// pointer. Register-passed arguments (`label`) arrive intact, which is
758
+ /// why the crash appears only at the first stack-passed string. Verified
759
+ /// against zig 0.16.0 on x86_64-linux with a standalone caller/callee
760
+ /// pair: self-hosted Debug corrupts, `-fllvm` is correct.
761
+ ///
726
762
  /// Force the LLVM backend on x86_64 until the upstream backend is fixed;
727
763
  /// Release modes already default to LLVM, so this only changes Debug.
728
764
  pub fn useLlvmWorkaround(target: std.Build.ResolvedTarget) ?bool {
@@ -740,7 +776,7 @@ fn exampleOptimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, defa
740
776
  }
741
777
 
742
778
  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 {
743
- const native_sdk_mod = nativeSdkModule(b, dep, target, optimize);
779
+ const native_sdk_mod = nativeSdkModuleWithTerminal(b, dep, target, optimize, app_options.terminal_sessions);
744
780
  const runner_mod = b.createModule(.{
745
781
  .root_source_file = dep.path("src/app_runner/root.zig"),
746
782
  .target = target,
@@ -812,6 +848,10 @@ fn localModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu
812
848
  }
813
849
 
814
850
  fn nativeSdkModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
851
+ return nativeSdkModuleWithTerminal(b, dep, target, optimize, false);
852
+ }
853
+
854
+ fn nativeSdkModuleWithTerminal(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, terminal_sessions: bool) *std.Build.Module {
815
855
  const geometry_mod = externalModule(b, dep, target, optimize, "src/primitives/geometry/root.zig");
816
856
  const assets_mod = externalModule(b, dep, target, optimize, "src/primitives/assets/root.zig");
817
857
  const app_dirs_mod = externalModule(b, dep, target, optimize, "src/primitives/app_dirs/root.zig");
@@ -837,6 +877,36 @@ fn nativeSdkModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.
837
877
  native_sdk_mod.addImport("platform_info", platform_info_mod);
838
878
  native_sdk_mod.addImport("json", json_mod);
839
879
  native_sdk_mod.addImport("canvas", canvas_mod);
880
+ // The terminal-session emulator seam (see
881
+ // `AppOptions.terminal_sessions`): an opted-in app's OWN lazy
882
+ // ghostty pin resolves here with the app module's target/optimize;
883
+ // everything else gets the stub and never traverses ghostty's
884
+ // dependency graph. An opted-in build whose pin is still unfetched
885
+ // takes the stub for THIS configure pass — the build runner fetches
886
+ // the lazy dependency and re-runs, and the second pass wires the
887
+ // real module.
888
+ native_sdk_mod.addImport("terminal_vt", terminal_vt: {
889
+ if (terminal_sessions) {
890
+ if (b.lazyDependency("ghostty", .{
891
+ .target = target,
892
+ .optimize = optimize,
893
+ // Keep the vt module pure Zig: the SIMD paths pull
894
+ // vendored C++ dependencies the session store never uses.
895
+ .simd = false,
896
+ // Only the vt MODULE is consumed: ghostty's macOS app and
897
+ // xcframework artifacts default ON for Darwin hosts and
898
+ // their configure step resolves the iOS libc, which
899
+ // aborts on a machine with only the command-line tools.
900
+ .@"emit-xcframework" = false,
901
+ .@"emit-macos-app" = false,
902
+ })) |ghostty| {
903
+ const wrapper = externalModule(b, dep, target, optimize, "src/runtime/terminal_vt_ghostty.zig");
904
+ wrapper.addImport("ghostty-vt", ghostty.module("ghostty-vt"));
905
+ break :terminal_vt wrapper;
906
+ }
907
+ }
908
+ break :terminal_vt externalModule(b, dep, target, optimize, "src/runtime/terminal_vt_stub.zig");
909
+ });
840
910
  return native_sdk_mod;
841
911
  }
842
912
 
@@ -893,6 +963,10 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
893
963
  app_mod.linkFramework("AppKit", .{});
894
964
  // The audio playback service (the AppKit host's single AVPlayer).
895
965
  app_mod.linkFramework("AVFoundation", .{});
966
+ // CVPixelBuffer for the video frame path (the video player's
967
+ // AVPlayerItemVideoOutput frames). CoreMedia's CMTime use stays
968
+ // header-only, but the pixel-buffer calls are real symbols.
969
+ app_mod.linkFramework("CoreVideo", .{});
896
970
  // Spectrum analysis of the app's own playback: the MediaToolbox
897
971
  // audio tap hands the player's PCM to the host, and Accelerate
898
972
  // (vDSP) turns it into band magnitudes.
@@ -921,7 +995,14 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
921
995
  // the layer stays out even on machines where the
922
996
  // development package is installed — libwebkitgtk is
923
997
  // neither linked nor required at runtime, and the
924
- // executable carries no WebKit reference at all.
998
+ // executable carries no WebKit reference at all. This
999
+ // is the expected, configured state of every canvas
1000
+ // app on Linux, so the stub compile is deliberately
1001
+ // silent — no build note, no compiler diagnostic (the
1002
+ // host's seam comment explains why even an
1003
+ // informational pragma is dangerous); a stubbed host
1004
+ // teaches at runtime by reporting WebViewNotFound the
1005
+ // moment an app actually uses a WebView.
925
1006
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/linux/gtk_host.c"), .flags = &.{"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB"} });
926
1007
  app_mod.linkSystemLibrary("gtk4", .{});
927
1008
  app_mod.linkSystemLibrary("dl", .{});
@@ -974,6 +1055,14 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
974
1055
  // headers are reachable through the system include paths
975
1056
  // — no WebView2Loader.dll is installed or path-wired,
976
1057
  // and the executable carries no reference to it at all.
1058
+ // This is the expected, configured state of every
1059
+ // canvas app on Windows, so the stub compile is
1060
+ // deliberately silent — no build note, no compiler
1061
+ // diagnostic (the host's seam comment explains why
1062
+ // even an informational pragma is dangerous); a
1063
+ // stubbed host teaches at runtime by reporting
1064
+ // WebViewNotFound the moment an app actually uses a
1065
+ // WebView.
977
1066
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
978
1067
  },
979
1068
  .chromium => {