@native-sdk/cli 0.4.3 → 0.5.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 (100) hide show
  1. package/build/app.zig +308 -72
  2. package/build/ts_run.mjs +63 -0
  3. package/build.zig +336 -7
  4. package/build.zig.zon +1 -0
  5. package/package.json +15 -10
  6. package/packages/core/package-lock.json +43 -0
  7. package/packages/core/package.json +37 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +536 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/core/SKILL.md +3 -0
  28. package/skill-data/native-ui/SKILL.md +30 -0
  29. package/skill-data/ts-core/SKILL.md +493 -0
  30. package/skill-data/zig/SKILL.md +208 -0
  31. package/skills/native-sdk/SKILL.md +1 -1
  32. package/src/app_runner/root.zig +75 -9
  33. package/src/app_runner/ts_core_main.zig +231 -0
  34. package/src/platform/linux/gtk_host.c +226 -21
  35. package/src/platform/windows/webview2_host.cpp +16 -10
  36. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  37. package/src/primitives/app_manifest/root.zig +13 -0
  38. package/src/primitives/app_manifest/types.zig +14 -0
  39. package/src/primitives/app_manifest/validation.zig +18 -0
  40. package/src/primitives/app_manifest/web_layer.zig +366 -0
  41. package/src/primitives/canvas/commands.zig +14 -7
  42. package/src/primitives/canvas/lazy_tls.zig +73 -0
  43. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  44. package/src/primitives/canvas/root.zig +6 -0
  45. package/src/primitives/canvas/tests.zig +1 -0
  46. package/src/primitives/canvas/text_atlas.zig +40 -32
  47. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  48. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  49. package/src/primitives/canvas/text_spans.zig +39 -26
  50. package/src/primitives/canvas/tokens.zig +54 -0
  51. package/src/primitives/canvas/ui.zig +125 -0
  52. package/src/primitives/canvas/ui_markup.zig +22 -3
  53. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  54. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  55. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  56. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  57. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  58. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  60. package/src/primitives/canvas/ui_schema.zig +8 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  62. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  63. package/src/primitives/canvas/widget_render.zig +25 -15
  64. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  65. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  66. package/src/root.zig +7 -0
  67. package/src/runtime/api.zig +7 -0
  68. package/src/runtime/bridge_responses.zig +2 -0
  69. package/src/runtime/builtin_bridge.zig +6 -0
  70. package/src/runtime/canvas_frame.zig +57 -36
  71. package/src/runtime/canvas_images.zig +9 -3
  72. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  73. package/src/runtime/canvas_widget_runtime.zig +7 -4
  74. package/src/runtime/effects.zig +490 -2
  75. package/src/runtime/effects_host_tests.zig +594 -0
  76. package/src/runtime/flow.zig +8 -0
  77. package/src/runtime/platform_bridge_tests.zig +1 -0
  78. package/src/runtime/root.zig +18 -0
  79. package/src/runtime/session_replay.zig +7 -1
  80. package/src/runtime/session_tests.zig +35 -8
  81. package/src/runtime/tests.zig +2 -0
  82. package/src/runtime/ts_core_host.zig +1505 -0
  83. package/src/runtime/ts_core_host_tests.zig +1408 -0
  84. package/src/runtime/ts_ui_app.zig +469 -0
  85. package/src/runtime/ui_app.zig +58 -0
  86. package/src/runtime/view_canvas.zig +24 -17
  87. package/src/runtime/view_widget_tree.zig +2 -2
  88. package/src/runtime/web_layer_gate_tests.zig +242 -0
  89. package/src/runtime/window_storage.zig +5 -0
  90. package/src/runtime/window_view_runtime.zig +1 -0
  91. package/src/tooling/buildgraph.zig +7 -1
  92. package/src/tooling/codesign.zig +212 -105
  93. package/src/tooling/doctor.zig +78 -0
  94. package/src/tooling/manifest.zig +314 -1
  95. package/src/tooling/package.zig +722 -18
  96. package/src/tooling/raw_manifest.zig +16 -0
  97. package/src/tooling/root.zig +1 -0
  98. package/src/tooling/templates.zig +911 -88
  99. package/src/tooling/ts_core.zig +486 -0
  100. package/src/tooling/verbs.zig +22 -0
@@ -226,10 +226,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
226
226
  );
227
227
 
228
228
  // Per-pass probe-table indices over the collected entry lists
229
- // (shared threadlocal scratch; see the reconcile-id-index note
229
+ // (shared per-thread scratch; see the reconcile-id-index note
230
230
  // in canvas_widget_runtime.zig). Lookups return exactly what
231
231
  // the linear scans returned; only the search cost changes.
232
- const index_scratch = &canvas_widget_runtime.canvas_widget_reconcile_index_scratch;
232
+ const index_scratch = canvas_widget_runtime.canvas_widget_reconcile_index_scratch.get();
233
233
  index_scratch.controls.build(previous_control_states);
234
234
  index_scratch.source_controls.build(self.widgetSourceControlEntries());
235
235
  index_scratch.texts.build(previous_text_states);
@@ -0,0 +1,242 @@
1
+ //! The runtime half of the native-only-host contract: a build whose
2
+ //! app.zon declared no web use ships without the embedded web layer
3
+ //! (`Options.web_layer = false`), and every path that would create a
4
+ //! webview fails fast with `error.WebViewLayerNotBuilt` and its teaching
5
+ //! message — never a platform call into a host whose web layer was
6
+ //! compiled out, and never a misleading not-found.
7
+
8
+ const support = @import("test_support.zig");
9
+ const std = support.std;
10
+ const geometry = support.geometry;
11
+ const app_manifest = support.app_manifest;
12
+ const automation = support.automation;
13
+ const platform = support.platform;
14
+ const App = support.App;
15
+ const Event = support.Event;
16
+ const Runtime = support.Runtime;
17
+ const TestHarness = support.TestHarness;
18
+
19
+ const teaching_needle = "built without the web layer";
20
+
21
+ /// A native-only app shape: default empty source, one canvas scene.
22
+ const canvas_scene_views = [_]app_manifest.ShellView{
23
+ .{ .label = "canvas", .kind = .gpu_surface, .fill = true },
24
+ };
25
+ const canvas_scene_windows = [_]app_manifest.ShellWindow{
26
+ .{ .label = "main", .views = &canvas_scene_views },
27
+ };
28
+
29
+ const CanvasApp = struct {
30
+ fn app(self: *@This()) App {
31
+ return .{ .context = self, .name = "native-only", .scene_fn = scene };
32
+ }
33
+
34
+ fn scene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
35
+ _ = context;
36
+ return .{ .windows = &canvas_scene_windows };
37
+ }
38
+ };
39
+
40
+ test "native-only runtime starts a canvas scene and refuses webview creation with the teaching error" {
41
+ const harness = try TestHarness().create(std.testing.allocator, .{});
42
+ defer harness.destroy(std.testing.allocator);
43
+ // The null platform's gpu_surface support is opt-in; the fixture
44
+ // scene is a canvas window, so switch it on like a real host.
45
+ harness.null_platform.gpu_surfaces = true;
46
+ harness.runtime.options.web_layer = false;
47
+ var app_state: CanvasApp = .{};
48
+ try harness.start(app_state.app());
49
+
50
+ // The canvas scene booted without touching the web layer.
51
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.webview_count);
52
+
53
+ // Direct webview view creation (the shell/bridge choke point).
54
+ try std.testing.expectError(error.WebViewLayerNotBuilt, harness.runtime.createView(.{
55
+ .window_id = 1,
56
+ .label = "preview",
57
+ .kind = .webview,
58
+ .frame = geometry.RectF.init(0, 0, 320, 240),
59
+ .url = "https://example.com",
60
+ }));
61
+
62
+ // A window whose source would materialize a main webview.
63
+ try std.testing.expectError(error.WebViewLayerNotBuilt, harness.runtime.createWindow(.{
64
+ .label = "second",
65
+ .title = "Second",
66
+ .default_frame = geometry.RectF.init(0, 0, 400, 300),
67
+ .source = platform.WebViewSource.url("https://example.com"),
68
+ }));
69
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.webview_count);
70
+ }
71
+
72
+ test "native-only runtime answers webview bridge verbs with the teaching error" {
73
+ const harness = try TestHarness().create(std.testing.allocator, .{});
74
+ defer harness.destroy(std.testing.allocator);
75
+ harness.null_platform.gpu_surfaces = true;
76
+ harness.runtime.options.web_layer = false;
77
+ harness.runtime.options.js_window_api = true;
78
+ const origins = [_][]const u8{"zero://inline"};
79
+ harness.runtime.options.security.navigation.allowed_origins = &origins;
80
+ var app_state: CanvasApp = .{};
81
+ try harness.start(app_state.app());
82
+
83
+ try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .bridge_message = .{
84
+ .bytes = "{\"id\":\"1\",\"command\":\"native-sdk.webview.create\",\"payload\":{\"label\":\"preview\",\"url\":\"https://example.com\",\"frame\":{\"width\":300,\"height\":200}}}",
85
+ .origin = "zero://inline",
86
+ .window_id = 1,
87
+ } });
88
+ const response = harness.null_platform.lastBridgeResponse();
89
+ try std.testing.expect(std.mem.indexOf(u8, response, "\"ok\":false") != null);
90
+ try std.testing.expect(std.mem.indexOf(u8, response, teaching_needle) != null);
91
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.webview_count);
92
+ }
93
+
94
+ test "native-only runtime fails fast when a source app reaches webview startup" {
95
+ const SourceApp = struct {
96
+ fn app(self: *@This()) App {
97
+ return .{ .context = self, .name = "source-app", .source = platform.WebViewSource.html("<p>web</p>") };
98
+ }
99
+ };
100
+
101
+ const harness = try TestHarness().create(std.testing.allocator, .{});
102
+ defer harness.destroy(std.testing.allocator);
103
+ harness.runtime.options.web_layer = false;
104
+ var app_state: SourceApp = .{};
105
+ try std.testing.expectError(error.WebViewLayerNotBuilt, harness.start(app_state.app()));
106
+ }
107
+
108
+ /// The scripted platform loop for the automation-driven session below:
109
+ /// startup, one frame, then two dropbox commands written from the loop's
110
+ /// own thread (like a driver writing while the app runs) and drained by
111
+ /// the following frames — deterministic, no watcher timing involved.
112
+ const NativeOnlyAutomationLoop = struct {
113
+ null_platform: *platform.NullPlatform,
114
+ automation_dir: []const u8,
115
+
116
+ fn run(context: *anyopaque, handler: platform.EventHandler, handler_context: *anyopaque) anyerror!void {
117
+ const self: *NativeOnlyAutomationLoop = @ptrCast(@alignCast(context));
118
+ try handler(handler_context, .app_start);
119
+ try handler(handler_context, .{ .surface_resized = self.null_platform.surface_value });
120
+ try handler(handler_context, .frame_requested);
121
+
122
+ var path_buffer: [160]u8 = undefined;
123
+ try std.Io.Dir.cwd().writeFile(std.testing.io, .{
124
+ .sub_path = try std.fmt.bufPrint(&path_buffer, "{s}/command-1.txt", .{self.automation_dir}),
125
+ .data = "menu-command probe.normal\n",
126
+ });
127
+ try std.Io.Dir.cwd().writeFile(std.testing.io, .{
128
+ .sub_path = try std.fmt.bufPrint(&path_buffer, "{s}/command-2.txt", .{self.automation_dir}),
129
+ .data = "menu-command probe.webview\n",
130
+ });
131
+ try handler(handler_context, .frame_requested);
132
+ try handler(handler_context, .frame_requested);
133
+ try handler(handler_context, .app_shutdown);
134
+ }
135
+ };
136
+
137
+ /// A native-only canvas app driven entirely through automation: a
138
+ /// normal command mutates state, and a command that tries to create a
139
+ /// webview records the gate's answer.
140
+ const NativeOnlyAutomationApp = struct {
141
+ normal_commands: usize = 0,
142
+ webview_error: ?anyerror = null,
143
+
144
+ fn scene(context: *anyopaque) anyerror!app_manifest.ShellConfig {
145
+ _ = context;
146
+ return .{ .windows = &canvas_scene_windows };
147
+ }
148
+
149
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
150
+ const self: *NativeOnlyAutomationApp = @ptrCast(@alignCast(context));
151
+ if (event_value != .command) return;
152
+ if (std.mem.eql(u8, event_value.command.name, "probe.normal")) {
153
+ self.normal_commands += 1;
154
+ return;
155
+ }
156
+ if (std.mem.eql(u8, event_value.command.name, "probe.webview")) {
157
+ _ = runtime.createView(.{
158
+ .window_id = 1,
159
+ .label = "preview",
160
+ .kind = .webview,
161
+ .frame = geometry.RectF.init(0, 0, 320, 240),
162
+ .url = "https://example.com",
163
+ }) catch |err| {
164
+ self.webview_error = err;
165
+ return;
166
+ };
167
+ self.webview_error = null;
168
+ }
169
+ }
170
+
171
+ fn app(self: *NativeOnlyAutomationApp) App {
172
+ return .{
173
+ .context = self,
174
+ .name = "native-only-automation",
175
+ .scene_fn = scene,
176
+ .event_fn = event,
177
+ };
178
+ }
179
+ };
180
+
181
+ test "automation drives a native-only session: commands work, webview creation teaches" {
182
+ // Pid-suffixed dropbox (this test compiles into more than one test
183
+ // binary; parallel copies must not share a directory).
184
+ var dir_buffer: [64]u8 = undefined;
185
+ const automation_dir = try automation.watcher.testDirectory(&dir_buffer, ".zig-cache/test-automation-web-layer");
186
+ var cwd = std.Io.Dir.cwd();
187
+ cwd.deleteTree(std.testing.io, automation_dir) catch {};
188
+ try cwd.createDirPath(std.testing.io, automation_dir);
189
+ defer cwd.deleteTree(std.testing.io, automation_dir) catch {};
190
+
191
+ // Heap-hosted: NullPlatform and Runtime are both multi-megabyte.
192
+ const null_platform = try std.heap.page_allocator.create(platform.NullPlatform);
193
+ defer std.heap.page_allocator.destroy(null_platform);
194
+ null_platform.* = platform.NullPlatform.init(.{});
195
+ null_platform.gpu_surfaces = true;
196
+ var loop: NativeOnlyAutomationLoop = .{ .null_platform = null_platform, .automation_dir = automation_dir };
197
+
198
+ var platform_value = null_platform.platform();
199
+ platform_value.run_fn = NativeOnlyAutomationLoop.run;
200
+ platform_value.context = &loop;
201
+
202
+ const runtime = try std.heap.page_allocator.create(Runtime);
203
+ defer std.heap.page_allocator.destroy(runtime);
204
+ Runtime.initAt(runtime, .{
205
+ .platform = platform_value,
206
+ .automation = automation.Server.init(std.testing.io, automation_dir, "WebLayerGate"),
207
+ .web_layer = false,
208
+ });
209
+
210
+ var app_state: NativeOnlyAutomationApp = .{};
211
+ try runtime.run(app_state.app());
212
+
213
+ // Normal operation: the automation-driven command reached the app.
214
+ try std.testing.expectEqual(@as(usize, 1), app_state.normal_commands);
215
+ // The automation-driven webview attempt got the teaching error, and
216
+ // no webview ever reached the platform host.
217
+ try std.testing.expectEqual(@as(?anyerror, error.WebViewLayerNotBuilt), app_state.webview_error);
218
+ try std.testing.expectEqual(@as(usize, 0), null_platform.webview_count);
219
+ }
220
+
221
+ test "web-layer builds keep every webview path working (control)" {
222
+ const SourceApp = struct {
223
+ fn app(self: *@This()) App {
224
+ return .{ .context = self, .name = "source-app", .source = platform.WebViewSource.html("<p>web</p>") };
225
+ }
226
+ };
227
+
228
+ const harness = try TestHarness().create(std.testing.allocator, .{});
229
+ defer harness.destroy(std.testing.allocator);
230
+ var app_state: SourceApp = .{};
231
+ try harness.start(app_state.app());
232
+ const webview_origins = [_][]const u8{"https://example.com"};
233
+ harness.runtime.options.security.navigation.allowed_origins = &webview_origins;
234
+ _ = try harness.runtime.createView(.{
235
+ .window_id = 1,
236
+ .label = "preview",
237
+ .kind = .webview,
238
+ .frame = geometry.RectF.init(0, 0, 320, 240),
239
+ .url = "https://example.com",
240
+ });
241
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.webview_count);
242
+ }
@@ -70,6 +70,11 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
70
70
  errdefer Self.removeWindowAt(self, index);
71
71
  errdefer if (native_created) self.options.platform.services.closeWindow(id) catch {};
72
72
 
73
+ // Materializing a window source means creating its main
74
+ // webview — refused before the native window exists when the
75
+ // build has no web layer, so the error names the real cause.
76
+ if (self.windows[index].source != null and !self.options.web_layer) return error.WebViewLayerNotBuilt;
77
+
73
78
  const window_options = options.windowOptions(id, self.windows[index].info.label);
74
79
  const native_info = try self.options.platform.services.createWindow(window_options);
75
80
  native_created = true;
@@ -321,6 +321,7 @@ pub fn RuntimeWindowViewRuntime(comptime Runtime: type) type {
321
321
  }
322
322
 
323
323
  pub fn createWebViewView(self: *Runtime, options: platform.ViewOptions) !platform.ViewInfo {
324
+ if (!self.options.web_layer) return error.WebViewLayerNotBuilt;
324
325
  try validateChildWebViewLabel(options.label);
325
326
  try Self.validateWebViewUrl(self, options.url);
326
327
  if (!isValidWebViewFrame(options.frame)) return error.InvalidWebViewOptions;
@@ -67,7 +67,13 @@ pub fn resolveFrameworkRoot(allocator: std.mem.Allocator, io: std.Io, env_map: *
67
67
  if (env_map.get("NATIVE_SDK_PATH")) |path| {
68
68
  if (path.len > 0 and hasFrameworkRoot(allocator, io, path)) {
69
69
  if (std.fs.path.isAbsolute(path)) return try allocator.dupe(u8, path);
70
- return try std.Io.Dir.cwd().realPathFileAlloc(io, path, allocator);
70
+ // realPathFileAlloc returns a sentinel-terminated allocation
71
+ // (length + 1 bytes); this function's contract is a plain
72
+ // slice the caller frees, so re-dupe without the sentinel or
73
+ // that free is off by one byte.
74
+ const real_path = try std.Io.Dir.cwd().realPathFileAlloc(io, path, allocator);
75
+ defer allocator.free(real_path);
76
+ return try allocator.dupe(u8, real_path);
71
77
  }
72
78
  }
73
79