@native-sdk/cli 0.5.4 → 0.6.1

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 (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +588 -32
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -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 +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  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 +599 -3
  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 +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1368 -74
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +76 -6
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +268 -26
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +475 -15
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +114 -19
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2338 -67
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -63,8 +63,10 @@
63
63
  const std = @import("std");
64
64
  const builtin = @import("builtin");
65
65
  const canvas = @import("canvas");
66
+ const platform = @import("../platform/root.zig");
66
67
  const canvas_limits = @import("canvas_limits.zig");
67
68
  const runtime_canvas_images = @import("canvas_images.zig");
69
+ const effects_mod = @import("effects.zig");
68
70
 
69
71
  pub const max_media_surface_channels = canvas_limits.max_media_surface_channels;
70
72
  pub const max_media_surface_pixel_bytes = canvas_limits.max_media_surface_pixel_bytes;
@@ -289,17 +291,24 @@ pub const MediaSurfaceProducer = struct {
289
291
  defer slot.mutex.unlock();
290
292
  if (!slot.active or slot.generation != self.generation) return error.MediaSurfaceReleased;
291
293
  // Push-boundary damage short-circuit: same bytes as the last
292
- // push (adopted or still staged) change nothing downstream —
293
- // including the wake below: unchanged pixels never stir an
294
- // idle compositor.
295
- if (slot.last_push_fingerprint == fingerprint) return;
296
- @memcpy(slot.staging[0..byte_len], rgba8);
297
- slot.staged = true;
298
- slot.staged_width = width;
299
- slot.staged_height = height;
300
- slot.staged_byte_len = byte_len;
301
- slot.staged_fingerprint = fingerprint;
302
- slot.last_push_fingerprint = fingerprint;
294
+ // push change nothing downstream — an ADOPTED frame's repeat
295
+ // never stirs an idle compositor. But bytes still STAGED are
296
+ // owed a frame, and the wake that promised one may have been
297
+ // refused (`requestWake` leaves `pending` clear on refusal
298
+ // precisely so a retry can land): an identical push then
299
+ // falls through to the wake below instead of stranding a
300
+ // static frame unadopted forever.
301
+ if (slot.last_push_fingerprint == fingerprint) {
302
+ if (!slot.staged) return;
303
+ } else {
304
+ @memcpy(slot.staging[0..byte_len], rgba8);
305
+ slot.staged = true;
306
+ slot.staged_width = width;
307
+ slot.staged_height = height;
308
+ slot.staged_byte_len = byte_len;
309
+ slot.staged_fingerprint = fingerprint;
310
+ slot.last_push_fingerprint = fingerprint;
311
+ }
303
312
  }
304
313
  // NEW bytes are staged: make sure a frame is coming to adopt
305
314
  // them, even in an idle app whose demand-driven scheduler is
@@ -335,6 +344,22 @@ pub const MediaSurfaceProducer = struct {
335
344
  wake.pending = true;
336
345
  }
337
346
 
347
+ /// The claim as a type-erased `platform.VideoFrameSink` — what the
348
+ /// video effect hands the platform decoder. The sink carries only
349
+ /// the slot pointer (process-lived by construction) and the claim
350
+ /// generation, so it is copyable across the C ABI and safe from any
351
+ /// thread: a push through a released claim reports
352
+ /// `error.MediaSurfaceReleased` exactly like the handle itself.
353
+ pub fn frameSink(self: MediaSurfaceProducer) platform.VideoFrameSink {
354
+ return .{ .context = self.slot, .generation = self.generation, .push_fn = sinkPushFrame };
355
+ }
356
+
357
+ fn sinkPushFrame(context: ?*anyopaque, generation: u64, width: usize, height: usize, rgba8: []const u8) anyerror!void {
358
+ const slot: *MediaSurfaceSlot = @ptrCast(@alignCast(context orelse return error.MediaSurfaceReleased));
359
+ const producer = MediaSurfaceProducer{ .slot = slot, .generation = generation, .surface_id = 0 };
360
+ return producer.pushFrame(width, height, rgba8);
361
+ }
362
+
338
363
  /// End this claim: later pushes through this handle (or any copy)
339
364
  /// report `error.MediaSurfaceReleased`, and the slot becomes
340
365
  /// claimable again. The runtime keeps the last ADOPTED texture — a
@@ -448,6 +473,22 @@ pub fn RuntimeMediaSurfaces(comptime Runtime: type) type {
448
473
  return error.MediaSurfaceChannelsExhausted;
449
474
  }
450
475
 
476
+ /// Forget the retained (adopted) texture for `surface_id`, if
477
+ /// any: the runtime entry empties (the placeholder shows until
478
+ /// the next adoption), the host's copied side-channel texture is
479
+ /// removed best-effort (the unregister convention: unsupported
480
+ /// seams and never-uploaded ids are no-ops), and views repaint.
481
+ /// Loop-thread-only, like the entry table it edits.
482
+ fn purgeRetainedMediaSurfaceTexture(self: *Runtime, surface_id: u64) void {
483
+ for (self.media_surface_entries[0..self.media_surface_count]) |*entry| {
484
+ if (entry.surface_id != surface_id or entry.fingerprint == 0) continue;
485
+ entry.* = .{ .surface_id = surface_id };
486
+ self.options.platform.services.removeGpuSurfaceImage(canvas.mediaSurfaceTextureImageId(surface_id)) catch {};
487
+ runtime_canvas_images.RuntimeCanvasImages(Runtime).noteCanvasImagesChanged(self);
488
+ return;
489
+ }
490
+ }
491
+
451
492
  /// Adopt staged producer frames, paced by the compositor: the
452
493
  /// gpu-surface frame dispatch calls this once per frame event,
453
494
  /// so a burst of pushes between presents collapses to ONE
@@ -579,6 +620,70 @@ pub fn RuntimeMediaSurfaces(comptime Runtime: type) type {
579
620
  }
580
621
  }
581
622
 
623
+ /// Type-erased handle the effects channel's video tier uses to
624
+ /// claim and release texture channels without knowing the
625
+ /// runtime type (`Effects.bindMediaSurfaces`) — the
626
+ /// `canvasImageRegistryBinding` pattern. `acquire` claims the
627
+ /// channel and answers the copyable frame sink the platform
628
+ /// decoder pushes through; `release` ends the claim by sink
629
+ /// (the sink IS the claim: slot pointer + generation).
630
+ pub fn mediaSurfaceBinding(self: *Runtime) effects_mod.MediaSurfaceBinding {
631
+ return .{
632
+ .context = self,
633
+ .acquire_fn = mediaSurfaceBindingAcquire,
634
+ .release_fn = mediaSurfaceBindingRelease,
635
+ };
636
+ }
637
+
638
+ fn mediaSurfaceBindingAcquire(context: *anyopaque, surface_id: u64) anyerror!platform.VideoFrameSink {
639
+ const self: *Runtime = @ptrCast(@alignCast(context));
640
+ const producer = try acquireMediaSurfaceProducer(self, surface_id);
641
+ // A video claim starts from the placeholder: the PREVIOUS
642
+ // playback's retained last frame is a different stream's
643
+ // pixels, and compositing it under the new stream's fitted
644
+ // geometry mis-fits visibly (a portrait replacement's LOADED
645
+ // report rebuilds the quad while a stale landscape texture
646
+ // is still on the glass). VIDEO-CHANNEL-ONLY: generic
647
+ // producers (`acquireMediaSurfaceProducer` direct) keep the
648
+ // adoption-boundary dedup — a re-claim staging the SAME
649
+ // bytes stays free of copies and repaints. Presentation
650
+ // chrome only — display lists, goldens, and session
651
+ // fingerprints never see textures — so the purge cannot
652
+ // perturb replay identity.
653
+ purgeRetainedMediaSurfaceTexture(self, surface_id);
654
+ return producer.frameSink();
655
+ }
656
+
657
+ /// LOOP-THREAD-ONLY, like the acquire half (the binding's
658
+ /// documented contract — `effects_mod.MediaSurfaceBinding`):
659
+ /// the purge below edits the runtime's adopted-texture table
660
+ /// and calls the platform's image-removal service, both
661
+ /// loop-thread state. Every caller is the video channel on an
662
+ /// `update`-dispatch path (stop/replace/failure/teardown);
663
+ /// producer threads hold only the sink, never the binding.
664
+ fn mediaSurfaceBindingRelease(context: *anyopaque, sink: platform.VideoFrameSink) void {
665
+ const self: *Runtime = @ptrCast(@alignCast(context));
666
+ const slot: *MediaSurfaceSlot = @ptrCast(@alignCast(sink.context orelse return));
667
+ // The released claim's surface id, read while the claim is
668
+ // still ours (generation-checked under the data mutex): the
669
+ // purge below needs it after `release` clears the slot.
670
+ slot.mutex.lock();
671
+ const surface_id = if (slot.active and slot.generation == sink.generation) slot.surface_id else 0;
672
+ slot.mutex.unlock();
673
+ const producer = MediaSurfaceProducer{ .slot = slot, .generation = sink.generation, .surface_id = 0 };
674
+ producer.release();
675
+ // A video release ends the picture: the channel releases on
676
+ // stop, replace, and failure — states whose UI story is "no
677
+ // playback" — and a rebuild there also drops the surface's
678
+ // CONTAIN stamp, so a retained last frame would composite
679
+ // stretched-distorted over the placeholder geometry. Purge
680
+ // it (video-channel-only, like the acquire-side purge; the
681
+ // same presentation-only determinism argument applies). A
682
+ // paused or naturally-completed playback keeps its claim,
683
+ // so the freeze-frame stays for those.
684
+ if (surface_id != 0) purgeRetainedMediaSurfaceTexture(self, surface_id);
685
+ }
686
+
582
687
  /// Disarm every wake binding this runtime armed: after this
583
688
  /// returns, no producer push can call into the runtime's
584
689
  /// platform host — not even one already past its generation
@@ -99,6 +99,67 @@ test "burst pushes stage latest-wins and the frame clock adopts the newest" {
99
99
  try std.testing.expectEqualSlices(u8, &blue, resources[0].pixels);
100
100
  }
101
101
 
102
+ test "a video-channel claim purges the previous playback's retained texture" {
103
+ // Replacing a playback re-claims its surface through the video
104
+ // channel's binding. The old playback's retained last frame is a
105
+ // DIFFERENT stream's pixels: composited under the new stream's
106
+ // fitted geometry it mis-fits visibly (the stale-landscape-in-a-
107
+ // portrait-quad bug), so the VIDEO claim starts from the
108
+ // placeholder — entry emptied, host-side texture removed — until
109
+ // the new stream's first frame adopts. Generic producer re-claims
110
+ // (`acquireMediaSurfaceProducer` direct) deliberately keep the
111
+ // retained texture: the adoption-boundary dedup test below pins
112
+ // that contract.
113
+ const harness = try startedGpuHarness(std.testing.allocator);
114
+ defer harness.destroy(std.testing.allocator);
115
+ var app_state: ProbeApp = .{};
116
+ const app = app_state.app();
117
+ try harness.start(app);
118
+ _ = try harness.runtime.createView(.{
119
+ .window_id = 1,
120
+ .label = "canvas",
121
+ .kind = .gpu_surface,
122
+ .frame = geometry.RectF.init(0, 0, 240, 140),
123
+ });
124
+
125
+ const producer = try harness.runtime.acquireMediaSurfaceProducer(surface_id);
126
+ const amber = solidFrame(.{ 200, 160, 40, 255 });
127
+ try producer.pushFrame(2, 2, &amber);
128
+ try dispatchFrame(harness, app, 1);
129
+ try std.testing.expect(harness.runtime.adoptedMediaSurfaceTexture(surface_id) != null);
130
+
131
+ // Release retains the last frame (the reclaim-ordering contract) —
132
+ // it is the next VIDEO claim that must not inherit it.
133
+ producer.release();
134
+ try std.testing.expect(harness.runtime.adoptedMediaSurfaceTexture(surface_id) != null);
135
+
136
+ const binding = harness.runtime.mediaSurfaceBinding();
137
+ const sink = try binding.acquire_fn(binding.context, surface_id);
138
+ try std.testing.expect(harness.runtime.adoptedMediaSurfaceTexture(surface_id) == null);
139
+ try std.testing.expectEqual(@as(usize, 0), harness.runtime.registeredCanvasImages().len);
140
+ // The host's copied side-channel texture went with it (the
141
+ // unregister convention rides the same seam).
142
+ try std.testing.expectEqual(
143
+ canvas.mediaSurfaceTextureImageId(surface_id),
144
+ harness.null_platform.gpu_surface_image_remove_id,
145
+ );
146
+
147
+ // The replacement's first adopted frame repopulates the channel.
148
+ const teal = solidFrame(.{ 20, 140, 140, 255 });
149
+ try sink.push(2, 2, &teal);
150
+ try dispatchFrame(harness, app, 2);
151
+ const adopted = harness.runtime.adoptedMediaSurfaceTexture(surface_id).?;
152
+ try std.testing.expect(adopted.fingerprint != 0);
153
+
154
+ // The video RELEASE purges too: stop/replace/failure tell the UI
155
+ // "no playback" and the rebuild drops the surface's contain stamp,
156
+ // so a retained frame would composite stretched-distorted. The
157
+ // stopped surface returns to its placeholder.
158
+ binding.release_fn(binding.context, sink);
159
+ try std.testing.expect(harness.runtime.adoptedMediaSurfaceTexture(surface_id) == null);
160
+ try std.testing.expectEqual(@as(usize, 0), harness.runtime.registeredCanvasImages().len);
161
+ }
162
+
102
163
  test "unchanged frames short-circuit damage; changed frames invalidate and repaint" {
103
164
  const harness = try startedGpuHarness(std.testing.allocator);
104
165
  defer harness.destroy(std.testing.allocator);