@native-sdk/cli 0.8.2 → 0.8.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 (92) hide show
  1. package/build/app.zig +50 -3
  2. package/build.zig +134 -360
  3. package/native-sdk.d.ts +4 -0
  4. package/package.json +9 -9
  5. package/packages/core/compile-surface/core.ts +90 -1
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/sdk/core.d.ts +65 -2
  9. package/packages/core/sdk/core.ts +189 -33
  10. package/packages/core/sdk/events.d.ts +14 -0
  11. package/packages/core/sdk/events.ts +18 -0
  12. package/packages/core/src/checker.ts +61 -1
  13. package/packages/core/src/devhost.ts +3 -3
  14. package/packages/core/src/diagnostics.ts +4 -4
  15. package/skill-data/core/SKILL.md +4 -2
  16. package/skill-data/core/references/project-anatomy.md +2 -1
  17. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  18. package/skill-data/native-ui/SKILL.md +8 -8
  19. package/skill-data/ts-core/SKILL.md +16 -13
  20. package/src/app_runner/app_assets.zig +138 -0
  21. package/src/app_runner/root.zig +2 -0
  22. package/src/app_runner/ts_core_main.zig +27 -3
  23. package/src/embed/host.zig +6 -0
  24. package/src/embed/ui_host.zig +2 -0
  25. package/src/platform/linux/root.zig +1 -0
  26. package/src/platform/macos/appkit_host.h +10 -0
  27. package/src/platform/macos/appkit_host.m +515 -93
  28. package/src/platform/macos/capture_info_plist.c +25 -0
  29. package/src/platform/macos/cef_host.mm +22 -0
  30. package/src/platform/macos/root.zig +68 -0
  31. package/src/platform/null_platform.zig +58 -0
  32. package/src/platform/root.zig +7 -0
  33. package/src/platform/types.zig +100 -0
  34. package/src/platform/windows/root.zig +56 -0
  35. package/src/platform/windows/webview2_host.cpp +171 -0
  36. package/src/primitives/app_manifest/types.zig +2 -0
  37. package/src/primitives/canvas/code_tests.zig +9 -9
  38. package/src/primitives/canvas/events.zig +12 -11
  39. package/src/primitives/canvas/frame.zig +44 -9
  40. package/src/primitives/canvas/icons/mic.svg +1 -0
  41. package/src/primitives/canvas/icons.zig +2 -0
  42. package/src/primitives/canvas/root.zig +8 -0
  43. package/src/primitives/canvas/text_span_tests.zig +39 -0
  44. package/src/primitives/canvas/ui.zig +23 -4
  45. package/src/primitives/canvas/ui_markup.zig +15 -0
  46. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  47. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  48. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  49. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  50. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  51. package/src/primitives/canvas/ui_schema.zig +19 -10
  52. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  53. package/src/primitives/canvas/ui_tests.zig +18 -4
  54. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  55. package/src/primitives/canvas/widget_render.zig +321 -115
  56. package/src/primitives/canvas/widget_runtime_tests.zig +173 -0
  57. package/src/primitives/canvas/widget_text_input.zig +10 -10
  58. package/src/primitives/canvas/widget_tree.zig +1 -1
  59. package/src/primitives/canvas/widgets.zig +41 -5
  60. package/src/root.zig +10 -0
  61. package/src/runtime/automation_widget_dispatch.zig +1 -0
  62. package/src/runtime/bridge_payload.zig +2 -0
  63. package/src/runtime/canvas_frame.zig +13 -2
  64. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  65. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  66. package/src/runtime/canvas_widget_event_tests.zig +1 -0
  67. package/src/runtime/canvas_widget_events.zig +69 -24
  68. package/src/runtime/canvas_widget_runtime.zig +101 -6
  69. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  70. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  71. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  72. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  73. package/src/runtime/canvas_widget_state.zig +10 -1
  74. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  75. package/src/runtime/effects.zig +313 -2
  76. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  77. package/src/runtime/root.zig +3 -0
  78. package/src/runtime/tests.zig +1 -0
  79. package/src/runtime/ts_core_host.zig +401 -32
  80. package/src/runtime/ts_core_host_tests.zig +407 -0
  81. package/src/runtime/ts_ui_app.zig +39 -1
  82. package/src/runtime/ui_app.zig +18 -3
  83. package/src/runtime/ui_app_tests.zig +48 -0
  84. package/src/runtime/view.zig +2 -0
  85. package/src/runtime/view_widget_scroll.zig +56 -5
  86. package/src/runtime/view_widget_text.zig +24 -5
  87. package/src/runtime/view_widget_tree.zig +1 -1
  88. package/src/tooling/manifest.zig +1034 -0
  89. package/src/tooling/package.zig +841 -10
  90. package/src/tooling/raw_manifest.zig +35 -0
  91. package/src/tooling/templates.zig +55 -0
  92. package/tools/corewire/emit_facade.zig +36 -0
@@ -0,0 +1,138 @@
1
+ //! Startup asset reads shared by generated app runners.
2
+ //!
3
+ //! Relative paths keep their app-directory meaning during development. In a
4
+ //! packaged macOS app, the same tree lives below `Contents/Resources`; Finder
5
+ //! and `open` do not preserve a useful working directory, so resolve that tree
6
+ //! from the executable's bundle layout before reading it.
7
+
8
+ const std = @import("std");
9
+ const builtin = @import("builtin");
10
+
11
+ pub fn readFileAlloc(
12
+ io: std.Io,
13
+ path: []const u8,
14
+ allocator: std.mem.Allocator,
15
+ limit: std.Io.Limit,
16
+ ) std.Io.Dir.ReadFileAllocError![]u8 {
17
+ if (comptime builtin.os.tag == .macos) {
18
+ var executable_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
19
+ const executable_len = std.process.executablePath(io, &executable_buffer) catch
20
+ return std.Io.Dir.cwd().readFileAlloc(io, path, allocator, limit);
21
+ return readFileAllocFromMacosExecutable(
22
+ io,
23
+ executable_buffer[0..executable_len],
24
+ path,
25
+ allocator,
26
+ limit,
27
+ );
28
+ }
29
+
30
+ return std.Io.Dir.cwd().readFileAlloc(io, path, allocator, limit);
31
+ }
32
+
33
+ pub fn readFileAllocFromMacosExecutable(
34
+ io: std.Io,
35
+ executable_path: []const u8,
36
+ path: []const u8,
37
+ allocator: std.mem.Allocator,
38
+ limit: std.Io.Limit,
39
+ ) std.Io.Dir.ReadFileAllocError![]u8 {
40
+ var bundled_path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
41
+ if (macosBundleResourcePath(executable_path, path, &bundled_path_buffer) catch null) |bundled_path| {
42
+ return std.Io.Dir.cwd().readFileAlloc(io, bundled_path, allocator, limit) catch |err| switch (err) {
43
+ // Match the platform host's asset resolver: a package miss keeps
44
+ // the old cwd-relative behavior, while a real read failure is not
45
+ // hidden by a second lookup.
46
+ error.FileNotFound => std.Io.Dir.cwd().readFileAlloc(io, path, allocator, limit),
47
+ else => |read_err| read_err,
48
+ };
49
+ }
50
+ return std.Io.Dir.cwd().readFileAlloc(io, path, allocator, limit);
51
+ }
52
+
53
+ pub fn macosBundleResourcePath(
54
+ executable_path: []const u8,
55
+ asset_path: []const u8,
56
+ output: []u8,
57
+ ) error{NoSpaceLeft}!?[]const u8 {
58
+ if (asset_path.len == 0 or std.fs.path.isAbsolutePosix(asset_path)) return null;
59
+
60
+ const executable_dir = std.fs.path.dirnamePosix(executable_path) orelse return null;
61
+ if (!std.mem.eql(u8, std.fs.path.basenamePosix(executable_dir), "MacOS")) return null;
62
+
63
+ const contents_dir = std.fs.path.dirnamePosix(executable_dir) orelse return null;
64
+ if (!std.mem.eql(u8, std.fs.path.basenamePosix(contents_dir), "Contents")) return null;
65
+
66
+ const bundle_dir = std.fs.path.dirnamePosix(contents_dir) orelse return null;
67
+ if (!std.ascii.eqlIgnoreCase(std.fs.path.extension(bundle_dir), ".app")) return null;
68
+
69
+ return std.fmt.bufPrint(output, "{s}/Resources/{s}", .{ contents_dir, asset_path }) catch
70
+ error.NoSpaceLeft;
71
+ }
72
+
73
+ test "macOS bundle resource path mirrors the app-relative asset tree" {
74
+ var buffer: [256]u8 = undefined;
75
+ const resolved = (try macosBundleResourcePath(
76
+ "/Applications/Kanban.app/Contents/MacOS/kanban",
77
+ "assets/logos/openai-svgl.png",
78
+ &buffer,
79
+ )).?;
80
+ try std.testing.expectEqualStrings(
81
+ "/Applications/Kanban.app/Contents/Resources/assets/logos/openai-svgl.png",
82
+ resolved,
83
+ );
84
+
85
+ const uppercase = (try macosBundleResourcePath(
86
+ "/Applications/Kanban.APP/Contents/MacOS/kanban",
87
+ "assets/logo.png",
88
+ &buffer,
89
+ )).?;
90
+ try std.testing.expectEqualStrings(
91
+ "/Applications/Kanban.APP/Contents/Resources/assets/logo.png",
92
+ uppercase,
93
+ );
94
+
95
+ try std.testing.expectEqual(null, try macosBundleResourcePath(
96
+ "/tmp/kanban",
97
+ "assets/logo.png",
98
+ &buffer,
99
+ ));
100
+ try std.testing.expectEqual(null, try macosBundleResourcePath(
101
+ "/Applications/Kanban.app/Contents/Helpers/kanban",
102
+ "assets/logo.png",
103
+ &buffer,
104
+ ));
105
+ try std.testing.expectEqual(null, try macosBundleResourcePath(
106
+ "/Applications/Kanban.app/Contents/MacOS/kanban",
107
+ "/tmp/logo.png",
108
+ &buffer,
109
+ ));
110
+ }
111
+
112
+ test "packaged macOS startup assets read from Contents Resources" {
113
+ var tmp = std.testing.tmpDir(.{});
114
+ defer tmp.cleanup();
115
+
116
+ const resource_dir = "Kanban.app/Contents/Resources/assets/logos";
117
+ try tmp.dir.createDirPath(std.testing.io, resource_dir);
118
+ try tmp.dir.writeFile(std.testing.io, .{
119
+ .sub_path = resource_dir ++ "/openai.png",
120
+ .data = "packaged-avatar",
121
+ });
122
+
123
+ var executable_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
124
+ const executable_path = try std.fmt.bufPrint(
125
+ &executable_buffer,
126
+ ".zig-cache/tmp/{s}/Kanban.app/Contents/MacOS/kanban",
127
+ .{tmp.sub_path[0..]},
128
+ );
129
+ const bytes = try readFileAllocFromMacosExecutable(
130
+ std.testing.io,
131
+ executable_path,
132
+ "assets/logos/openai.png",
133
+ std.testing.allocator,
134
+ .limited(1024),
135
+ );
136
+ defer std.testing.allocator.free(bytes);
137
+ try std.testing.expectEqualStrings("packaged-avatar", bytes);
138
+ }
@@ -5,6 +5,8 @@ const app_manifest = @import("app_manifest_zon");
5
5
  const manifest_shortcuts = if (@hasField(@TypeOf(app_manifest), "shortcuts")) app_manifest.shortcuts else .{};
6
6
  const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
7
7
 
8
+ pub const app_assets = @import("app_assets.zig");
9
+
8
10
  pub const StdoutTraceSink = struct {
9
11
  pub fn sink(self: *StdoutTraceSink) native_sdk.trace.Sink {
10
12
  return .{ .context = self, .write_fn = write };
@@ -35,6 +35,7 @@
35
35
  //! (native file drops with source, point, and paths).
36
36
  //! images app.zon's `.assets.images` entries (`.{ .id = 1,
37
37
  //! .path = "assets/..." }`) are read once at launch
38
+ //! (from `Contents/Resources` in a packaged macOS app)
38
39
  //! and registered on the installing frame — the ids
39
40
  //! are the `ImageId`s markup avatar bindings use. A
40
41
  //! missing file or failed decode skips the entry
@@ -43,7 +44,11 @@
43
44
  //! variable present at launch as one journaled Msg on
44
45
  //! its bytes arm, right after the boot command — the
45
46
  //! core itself never reads the environment (NS1005),
46
- //! and replay carries the recorded values.
47
+ //! and replay carries the recorded values. The runner
48
+ //! synthesizes `NATIVE_SDK_APP_DATA_DIR` from app_dirs
49
+ //! when a core requests it, so packaged apps never
50
+ //! depend on their process working directory for
51
+ //! durable files.
47
52
  //!
48
53
  //! Editing this file is never core-level work: it carries no app logic and
49
54
  //! regenerates from the SDK on every build.
@@ -70,6 +75,7 @@ pub const app_markup = @embedFile("app.native");
70
75
 
71
76
  const app_permissions = manifestStringList(manifest, "permissions");
72
77
  const allowed_origins = manifestAllowedOrigins();
78
+ const app_data_dir_env = "NATIVE_SDK_APP_DATA_DIR";
73
79
 
74
80
  pub fn main(init: std.process.Init) !void {
75
81
  var options: Adapter.Options = .{
@@ -105,6 +111,19 @@ pub fn main(init: std.process.Init) !void {
105
111
  .cache,
106
112
  &cache_dir_buffer,
107
113
  ) catch "";
114
+ // The durable per-app data directory, resolved by the same platform
115
+ // convention as Zig-core apps. TS cores request it through the
116
+ // ordinary journaled envMsgs boundary under `app_data_dir_env`; it
117
+ // is framework-provided rather than trusted from the ambient
118
+ // environment, so package launch cwd and env differences disappear.
119
+ var data_dir_buffer: [512]u8 = undefined;
120
+ const app_data_dir = native_sdk.app_dirs.resolveOne(
121
+ .{ .name = manifest.name },
122
+ native_sdk.app_dirs.currentPlatform(),
123
+ native_sdk.debug.envFromMap(init.environ_map),
124
+ .data,
125
+ &data_dir_buffer,
126
+ ) catch "";
108
127
  // app.zon-declared images, read once at launch (bounded; a missing or
109
128
  // over-bound file skips its entry and the views keep their fallback)
110
129
  // and registered by the adapter on the installing frame.
@@ -112,7 +131,7 @@ pub fn main(init: std.process.Init) !void {
112
131
  var boot_images_buffer: [manifest_images.len]Adapter.BootImage = undefined;
113
132
  var boot_image_count: usize = 0;
114
133
  inline for (manifest_images) |asset| {
115
- if (std.Io.Dir.cwd().readFileAlloc(init.io, asset.path, std.heap.page_allocator, .limited(max_boot_image_bytes))) |bytes| {
134
+ if (runner.app_assets.readFileAlloc(init.io, asset.path, std.heap.page_allocator, .limited(max_boot_image_bytes))) |bytes| {
116
135
  boot_images_buffer[boot_image_count] = .{ .id = asset.id, .bytes = bytes };
117
136
  boot_image_count += 1;
118
137
  } else |_| {}
@@ -126,7 +145,12 @@ pub fn main(init: std.process.Init) !void {
126
145
  var env_value_count: usize = 0;
127
146
  if (comptime @hasDecl(core, "envMsgs")) {
128
147
  inline for (core.envMsgs) |entry| {
129
- if (init.environ_map.get(entry.env)) |value| {
148
+ if (std.mem.eql(u8, entry.env, app_data_dir_env)) {
149
+ if (app_data_dir.len > 0) {
150
+ env_values_buffer[env_value_count] = .{ .msg = entry.msg, .value = app_data_dir };
151
+ env_value_count += 1;
152
+ }
153
+ } else if (init.environ_map.get(entry.env)) |value| {
130
154
  env_values_buffer[env_value_count] = .{ .msg = entry.msg, .value = value };
131
155
  env_value_count += 1;
132
156
  }
@@ -163,6 +163,10 @@ pub fn setAudioService(self: anytype, service: types.MobileAudioService, context
163
163
  services.audio_set_volume_fn = if (playback) Bridge.audioSetVolume else null;
164
164
  self.null_platform.audio_playback = playback;
165
165
  self.null_platform.audio_streaming = streaming;
166
+ // The embed ABI has no capture producer callbacks yet; never inherit
167
+ // the null platform's deterministic capture fake as host capability.
168
+ self.null_platform.microphone_capture = false;
169
+ self.null_platform.system_audio_capture = false;
166
170
  }
167
171
 
168
172
  /// Host-owned storage for the shim's registered image-decode service
@@ -725,6 +729,8 @@ pub const MobileHostApp = struct {
725
729
  // below so the runtime's service table starts without audio.
726
730
  self.null_platform.audio_playback = false;
727
731
  self.null_platform.audio_streaming = false;
732
+ self.null_platform.microphone_capture = false;
733
+ self.null_platform.system_audio_capture = false;
728
734
  // Video is declined the same way: no mobile shim registers a
729
735
  // decoder yet, and the null platform's fake player belongs to
730
736
  // hermetic tests — a load that "succeeds" but never decodes
@@ -123,6 +123,8 @@ pub fn UiAppHost(comptime AppDef: type) type {
123
123
  // snapshotted below.
124
124
  self.null_platform.audio_playback = false;
125
125
  self.null_platform.audio_streaming = false;
126
+ self.null_platform.microphone_capture = false;
127
+ self.null_platform.system_audio_capture = false;
126
128
  // The null packet presenter records only counts; disabling it
127
129
  // routes presentation through the CPU pixel path so frames
128
130
  // produce real pixels (the buffer M2's surface blit consumes).
@@ -456,6 +456,7 @@ pub const LinuxPlatform = struct {
456
456
  // a host whose plugin set lacks it answers false and the
457
457
  // deck's glass rests honestly instead of dancing on fakes.
458
458
  .audio_spectrum => self.web_engine == .system and audioSpectrumAvailable(self.host),
459
+ .microphone_capture, .system_audio_capture => false,
459
460
  .tray => false,
460
461
  // No tray means no affordance to bring a policy-hidden
461
462
  // window back — reporting support would strand windows, so
@@ -531,6 +531,16 @@ int native_sdk_appkit_audio_stop(native_sdk_appkit_host_t *host);
531
531
  int native_sdk_appkit_audio_seek(native_sdk_appkit_host_t *host, uint64_t position_ms);
532
532
  int native_sdk_appkit_audio_set_volume(native_sdk_appkit_host_t *host, double volume);
533
533
 
534
+ /* Microphone/system-output capture. Source: 0 microphone, 1 system;
535
+ * event kind: 0 started, 1 PCM data, 2 failed. PCM is interleaved signed
536
+ * 16-bit little-endian in the exact requested format. The callback returns
537
+ * 0 accepted, 1 closed (the producer must exit), or a drop code. Stop is a
538
+ * synchronous quiescence fence: the callback is never entered afterward. */
539
+ typedef int (*native_sdk_appkit_audio_capture_push_t)(void *context, int kind, int source, uint32_t sample_rate, uint8_t channels, uint64_t timestamp_ns, uint32_t frames, const uint8_t *pcm, size_t pcm_len);
540
+ int native_sdk_appkit_audio_capture_start(native_sdk_appkit_host_t *host, int source, uint32_t sample_rate, uint8_t channels, native_sdk_appkit_audio_capture_push_t push_fn, void *push_context);
541
+ int native_sdk_appkit_audio_capture_stop(native_sdk_appkit_host_t *host, int source);
542
+ int native_sdk_appkit_audio_capture_supported(native_sdk_appkit_host_t *host, int source);
543
+
534
544
  /* Where the video player delivers decoded frames: one tightly packed,
535
545
  * row-major, straight-alpha RGBA8 frame per call (len = width * height
536
546
  * * 4), copied before return. Returns 0 when the frame was accepted, 1