@native-sdk/cli 0.5.2 → 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 (123) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +264 -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/sdk/events.ts +39 -2
  10. package/packages/core/src/checker.ts +1 -1
  11. package/packages/core/src/emitter.ts +2625 -262
  12. package/packages/core/src/infer.ts +53 -7
  13. package/skill-data/automation/SKILL.md +7 -4
  14. package/skill-data/core/references/app-model-runtime.md +3 -0
  15. package/skill-data/native-ui/SKILL.md +4 -2
  16. package/skill-data/ts-core/SKILL.md +9 -1
  17. package/src/app_runner/root.zig +106 -1
  18. package/src/app_runner/ts_core_main.zig +4 -0
  19. package/src/automation/protocol.zig +20 -1
  20. package/src/embed/host.zig +27 -0
  21. package/src/embed/tests.zig +187 -0
  22. package/src/embed/ui_host.zig +4 -0
  23. package/src/platform/linux/gtk_host.c +112 -3
  24. package/src/platform/linux/root.zig +71 -0
  25. package/src/platform/macos/appkit_host.h +59 -2
  26. package/src/platform/macos/appkit_host.m +663 -34
  27. package/src/platform/macos/cef_host.mm +262 -10
  28. package/src/platform/macos/root.zig +126 -4
  29. package/src/platform/null_platform.zig +298 -5
  30. package/src/platform/null_platform_tests.zig +39 -0
  31. package/src/platform/root.zig +36 -0
  32. package/src/platform/types.zig +247 -8
  33. package/src/platform/windows/root.zig +134 -0
  34. package/src/platform/windows/webview2_host.cpp +152 -40
  35. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  36. package/src/primitives/app_manifest/root.zig +1 -0
  37. package/src/primitives/app_manifest/types.zig +32 -0
  38. package/src/primitives/canvas/chart.zig +7 -7
  39. package/src/primitives/canvas/chart_tests.zig +66 -0
  40. package/src/primitives/canvas/commands.zig +48 -0
  41. package/src/primitives/canvas/events.zig +161 -0
  42. package/src/primitives/canvas/font_ttf.zig +155 -8
  43. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  44. package/src/primitives/canvas/reference.zig +67 -8
  45. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  46. package/src/primitives/canvas/root.zig +25 -0
  47. package/src/primitives/canvas/tests.zig +1 -0
  48. package/src/primitives/canvas/ui.zig +46 -9
  49. package/src/primitives/canvas/ui_markup.zig +82 -34
  50. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  51. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  52. package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
  53. package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
  54. package/src/primitives/canvas/ui_markup_contract.zig +10 -1
  55. package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
  56. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  57. package/src/primitives/canvas/ui_markup_tests.zig +55 -9
  58. package/src/primitives/canvas/ui_markup_view.zig +81 -14
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
  60. package/src/primitives/canvas/ui_schema.zig +29 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  62. package/src/primitives/canvas/ui_tests.zig +31 -0
  63. package/src/primitives/canvas/vector.zig +258 -141
  64. package/src/primitives/canvas/widget_access.zig +1 -1
  65. package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
  66. package/src/primitives/canvas/widget_layout.zig +9 -4
  67. package/src/primitives/canvas/widget_render.zig +78 -40
  68. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  69. package/src/primitives/canvas/widget_semantics.zig +6 -1
  70. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  71. package/src/primitives/canvas/widget_text_input.zig +118 -10
  72. package/src/primitives/canvas/widgets.zig +16 -0
  73. package/src/root.zig +12 -0
  74. package/src/runtime/api.zig +15 -0
  75. package/src/runtime/automation_commands.zig +33 -0
  76. package/src/runtime/automation_widget_dispatch.zig +64 -0
  77. package/src/runtime/bridge_payload.zig +7 -0
  78. package/src/runtime/bridge_responses.zig +5 -0
  79. package/src/runtime/builtin_bridge.zig +9 -4
  80. package/src/runtime/canvas_font_tests.zig +711 -5
  81. package/src/runtime/canvas_fonts.zig +120 -25
  82. package/src/runtime/canvas_frame_helpers.zig +15 -0
  83. package/src/runtime/canvas_image_tests.zig +221 -0
  84. package/src/runtime/canvas_images.zig +78 -19
  85. package/src/runtime/canvas_limits.zig +44 -8
  86. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  87. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  88. package/src/runtime/canvas_widget_events.zig +24 -4
  89. package/src/runtime/canvas_widget_runtime.zig +24 -7
  90. package/src/runtime/canvas_widget_state.zig +6 -1
  91. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  92. package/src/runtime/core.zig +148 -9
  93. package/src/runtime/effects.zig +1664 -43
  94. package/src/runtime/effects_fetch_tests.zig +89 -1
  95. package/src/runtime/effects_file_tests.zig +41 -1
  96. package/src/runtime/effects_image_tests.zig +1304 -0
  97. package/src/runtime/effects_tests.zig +153 -0
  98. package/src/runtime/flow.zig +44 -0
  99. package/src/runtime/gpu_surface_events.zig +7 -0
  100. package/src/runtime/media_surface.zig +726 -0
  101. package/src/runtime/media_surface_tests.zig +1476 -0
  102. package/src/runtime/root.zig +20 -0
  103. package/src/runtime/session_blobs.zig +689 -0
  104. package/src/runtime/session_journal.zig +111 -20
  105. package/src/runtime/session_record.zig +27 -2
  106. package/src/runtime/session_replay.zig +168 -16
  107. package/src/runtime/session_tests.zig +2118 -4
  108. package/src/runtime/shell_layout.zig +7 -0
  109. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  110. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  111. package/src/runtime/tests.zig +3 -0
  112. package/src/runtime/ts_core_host.zig +439 -4
  113. package/src/runtime/ts_core_host_tests.zig +41 -0
  114. package/src/runtime/ts_ui_app.zig +63 -0
  115. package/src/runtime/ui_app.zig +169 -6
  116. package/src/runtime/ui_app_tests.zig +334 -0
  117. package/src/runtime/ui_app_window_tests.zig +468 -0
  118. package/src/runtime/window_command_bridge_tests.zig +117 -0
  119. package/src/runtime/window_storage.zig +32 -0
  120. package/src/runtime/window_views.zig +61 -1
  121. package/src/tooling/manifest.zig +75 -0
  122. package/src/tooling/raw_manifest.zig +2 -0
  123. package/src/tooling/templates.zig +219 -1
@@ -1536,3 +1536,156 @@ test "real executor reports unspawnable binaries as spawn_failed" {
1536
1536
  try std.testing.expectEqual(effects_mod.EffectExitReason.spawn_failed, h.app_state.model.exit_reason.?);
1537
1537
  try std.testing.expectEqual(@as(usize, 0), h.app_state.model.line_count);
1538
1538
  }
1539
+
1540
+ test "a spawn exit still undelivered occupies its key against a respawn; delivery frees it" {
1541
+ var h = try Harness.create();
1542
+ defer h.destroy();
1543
+ const fx = &h.app_state.effects;
1544
+ fx.executor = .fake;
1545
+
1546
+ test_argv = &.{"worker"};
1547
+ test_stdin = null;
1548
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1549
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1550
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1551
+
1552
+ // The fed exit queues the terminal and parks the slot — posted but
1553
+ // undelivered. A respawn of the same key inside that window must
1554
+ // reject: under session replay the first spawn is still a parked
1555
+ // `.running` fake here (its journaled exit feeds at the recorded
1556
+ // delivery position), so a live accept would journal a Msg stream
1557
+ // replay rejects.
1558
+ try fx.feedExit(stream_key, 0);
1559
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1560
+ try std.testing.expectEqual(@as(usize, 0), fx.pendingSpawnCount());
1561
+
1562
+ // Delivery order: the staged rejection first (loop-side pending),
1563
+ // then the queued exit.
1564
+ try h.drainWakes();
1565
+ try std.testing.expectEqual(@as(usize, 2), h.app_state.model.exit_count);
1566
+ try std.testing.expectEqual(effects_mod.EffectExitReason.exited, h.app_state.model.exit_reason.?);
1567
+ try std.testing.expectEqual(@as(i32, 0), h.app_state.model.exit_code);
1568
+
1569
+ // The window ends at delivery: the same key spawns again.
1570
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1571
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1572
+ }
1573
+
1574
+ /// One-shot flag for the respawn-from-own-exit idiom test below.
1575
+ var test_respawn_on_exit: bool = false;
1576
+
1577
+ /// `streamUpdate` plus the restart idiom: the exit handler answers its
1578
+ /// own terminal by respawning the same key (one-shot).
1579
+ fn respawnUpdate(model: *StreamModel, msg: StreamMsg, fx: *StreamEffects) void {
1580
+ if (msg == .done and test_respawn_on_exit) {
1581
+ test_respawn_on_exit = false;
1582
+ model.recordExit(msg.done);
1583
+ fx.spawn(.{
1584
+ .key = stream_key,
1585
+ .argv = test_argv,
1586
+ .on_line = StreamEffects.lineMsg(.line),
1587
+ .on_exit = StreamEffects.exitMsg(.done),
1588
+ });
1589
+ return;
1590
+ }
1591
+ streamUpdate(model, msg, fx);
1592
+ }
1593
+
1594
+ test "an update that respawns the same key from its own exit parks instead of rejecting" {
1595
+ var h = try Harness.createWith(respawnUpdate);
1596
+ defer h.destroy();
1597
+ const fx = &h.app_state.effects;
1598
+ fx.executor = .fake;
1599
+
1600
+ test_argv = &.{"worker"};
1601
+ test_stdin = null;
1602
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1603
+ test_respawn_on_exit = true;
1604
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1605
+ try fx.feedExit(stream_key, 0);
1606
+
1607
+ // The drain clears the undelivered-exit marker AND retires the slot
1608
+ // BEFORE the terminal Msg reaches update, so the handler's respawn
1609
+ // of its own key is a fresh accepted spawn — the restart idiom must
1610
+ // not regress. (The retire is the loop-side half of the worker's
1611
+ // post-then-store epilogue; on this fed path the slot was already
1612
+ // `.draining`, so the drain's store is an idempotent re-store.)
1613
+ try h.drainWakes();
1614
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.exit_count);
1615
+ try std.testing.expectEqual(effects_mod.EffectExitReason.exited, h.app_state.model.exit_reason.?);
1616
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1617
+
1618
+ // The respawned occupancy is a full fresh effect, not a resurrected
1619
+ // slot: its own exit delivers and the cycle restarts cleanly.
1620
+ test_respawn_on_exit = true;
1621
+ try fx.feedExit(stream_key, 7);
1622
+ try h.drainWakes();
1623
+ try std.testing.expectEqual(@as(usize, 2), h.app_state.model.exit_count);
1624
+ try std.testing.expectEqual(@as(i32, 7), h.app_state.model.exit_code);
1625
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1626
+ test_respawn_on_exit = false;
1627
+ }
1628
+
1629
+ /// Spawn slots carrying a set undelivered-exit marker.
1630
+ fn markedExitSlotCount(fx: *StreamEffects) usize {
1631
+ var count: usize = 0;
1632
+ for (&fx.slots) |*slot| {
1633
+ if (slot.kind == .spawn and slot.exit_undelivered) count += 1;
1634
+ }
1635
+ return count;
1636
+ }
1637
+
1638
+ test "consuming a fed lines exit clears the undelivered-exit marker" {
1639
+ var h = try Harness.create();
1640
+ defer h.destroy();
1641
+ const fx = &h.app_state.effects;
1642
+ fx.executor = .fake;
1643
+
1644
+ test_argv = &.{"worker"};
1645
+ test_stdin = null;
1646
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1647
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1648
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(fx));
1649
+
1650
+ // Posted but undelivered: the marker holds the slot (and the key).
1651
+ try fx.feedExit(stream_key, 0);
1652
+ try std.testing.expectEqual(@as(usize, 1), markedExitSlotCount(fx));
1653
+
1654
+ // Dequeueing the exit IS its delivery: the drain must clear the
1655
+ // marker when it consumes the exit, or `reclaimSlots` holds the
1656
+ // slot out of `.idle` forever.
1657
+ try h.drainWakes();
1658
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.exit_count);
1659
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(fx));
1660
+ }
1661
+
1662
+ test "every delivered lines exit hands its slot back for reuse" {
1663
+ if (builtin.os.tag == .windows) return error.SkipZigTest;
1664
+ var h = try Harness.create();
1665
+ defer h.destroy();
1666
+
1667
+ test_argv = &.{"/nonexistent/native-sdk-effects-test-binary"};
1668
+ test_stdin = null;
1669
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1670
+ // Each round runs the real worker epilogue end to end (an
1671
+ // unspawnable binary is still worker truth: the worker posts a
1672
+ // `.spawn_failed` exit through the same mark-then-post commit) and
1673
+ // must return its slot. More rounds than the pool has slots proves
1674
+ // delivery frees them: a marker the drain's consume ever missed
1675
+ // would strand its slot in `.draining`, exhaust the pool, and turn
1676
+ // a later round's reason into `.rejected`.
1677
+ const io = std.testing.io;
1678
+ var round: usize = 1;
1679
+ while (round <= effects_mod.max_effects + 1) : (round += 1) {
1680
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1681
+ var waited_ms: usize = 0;
1682
+ while (h.app_state.model.exit_count < round) : (waited_ms += 10) {
1683
+ if (waited_ms >= 20_000) return error.TestTimedOut;
1684
+ try h.drainWakes();
1685
+ try std.Io.sleep(io, std.Io.Duration.fromMilliseconds(10), .awake);
1686
+ }
1687
+ try std.testing.expectEqual(round, h.app_state.model.exit_count);
1688
+ try std.testing.expectEqual(effects_mod.EffectExitReason.spawn_failed, h.app_state.model.exit_reason.?);
1689
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(&h.app_state.effects));
1690
+ }
1691
+ }
@@ -39,6 +39,7 @@ const parseAutomationProvenanceTarget = automation_commands.parseAutomationProve
39
39
  const parseAutomationWidgetWheel = automation_commands.parseAutomationWidgetWheel;
40
40
  const parseAutomationWidgetContextMenuItem = automation_commands.parseAutomationWidgetContextMenuItem;
41
41
  const parseAutomationWidgetKey = automation_commands.parseAutomationWidgetKey;
42
+ const parseAutomationWidgetPinch = automation_commands.parseAutomationWidgetPinch;
42
43
  const parseAutomationWidgetPointerDrag = automation_commands.parseAutomationWidgetPointerDrag;
43
44
  const parseAutomationResizeCommand = automation_commands.parseAutomationResizeCommand;
44
45
  const parseAutomationTrayItemId = automation_commands.parseAutomationTrayItemId;
@@ -135,6 +136,16 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
135
136
  // away, so the watcher can never call into a dead host.
136
137
  defer if (command_watcher_running) command_watcher.stop();
137
138
 
139
+ // Media-surface wake teardown: producers a slow app forgot
140
+ // to release may push (and try to wake this platform) at
141
+ // any later time from their own threads. Disarm their wake
142
+ // bindings before the caller's later-declared defers tear
143
+ // the host down — declared BEFORE the app-stop defer below
144
+ // so it runs AFTER the stop hook (LIFO), letting the hook
145
+ // join producer threads first. The same run-exit ordering
146
+ // that stops the automation arrival watcher.
147
+ defer self.disarmMediaSurfaceWakes();
148
+
138
149
  // Teardown ordering contract: everything the app must do
139
150
  // against the live platform — silencing an active audio
140
151
  // player, disarming platform timers, joining effect workers
@@ -523,6 +534,18 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
523
534
 
524
535
  pub fn frame(self: *Runtime, app: App) anyerror!void {
525
536
  const start_ns = nowNanoseconds();
537
+ // A media-surface producer's wake arrives as THIS event (the
538
+ // platform's cross-thread frame request): adopt staged
539
+ // frames here so an idle app's push reaches the runtime —
540
+ // adoption's invalidation then arms the prompt gpu-surface
541
+ // frame that composites it (`noteCanvasImagesChanged` ->
542
+ // `requestCanvasFrameForView`). Runs before the invalidation
543
+ // check below because adoption IS an invalidation source; a
544
+ // busy app pays one fenced flag check per idle channel, and
545
+ // the gpu-surface frame dispatch's own adoption call keeps
546
+ // pacing consumption for hosts whose frame events do not
547
+ // pass through here.
548
+ self.adoptMediaSurfaceFrames();
526
549
  try consumeAutomationCommand(self, app);
527
550
  if (!self.invalidated) return;
528
551
 
@@ -595,6 +618,23 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
595
618
  };
596
619
  self.windows[runtime_index].source_reloads_from_app = true;
597
620
  if (index > 0) {
621
+ // The same `.hide` gate as the runtime create path
622
+ // (window_storage): secondary startup windows reach
623
+ // the platform through this direct create, so the
624
+ // policy check must ride here too or a declared
625
+ // `.hide` is silently accepted on hosts that cannot
626
+ // re-show a closed window. `.hide` needs a host that
627
+ // can keep a closed-by-the-user window alive and
628
+ // re-show it; refusing here is the loud teaching
629
+ // (GTK: no status item exists to bring the window
630
+ // back, declare .quit — the default — instead).
631
+ // NEVER a silent no-op that strands a hidden window.
632
+ // The main window (index 0) is created by the host
633
+ // itself, which refuses the declaration at its own
634
+ // init.
635
+ if (window.close_policy == .hide and !self.options.platform.supports(.window_hide_on_close)) {
636
+ return error.UnsupportedWindowClosePolicy;
637
+ }
598
638
  _ = try self.options.platform.services.createWindow(window);
599
639
  }
600
640
  try self.options.platform.services.loadWindowWebView(window.id, self.windows[runtime_index].source.?);
@@ -816,6 +856,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
816
856
  .widget_drag => "automation.widget_drag",
817
857
  .widget_wheel => "automation.widget_wheel",
818
858
  .widget_key => "automation.widget_key",
859
+ .widget_pinch => "automation.widget_pinch",
819
860
  .tray_action => "automation.tray_action",
820
861
  .provenance => "automation.provenance",
821
862
  else => "automation.command",
@@ -877,6 +918,9 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
877
918
  .widget_key => {
878
919
  try AutomationWidgetMethods().dispatchAutomationWidgetKeyInput(self, app, try parseAutomationWidgetKey(command.value));
879
920
  },
921
+ .widget_pinch => {
922
+ try AutomationWidgetMethods().dispatchAutomationWidgetPinch(self, app, try parseAutomationWidgetPinch(command.value));
923
+ },
880
924
  .menu_command => {
881
925
  try dispatchPlatformEvent(self, app, .{ .menu_command = .{
882
926
  .name = try parseAutomationCommandName(command.value),
@@ -17,6 +17,13 @@ const sizesEqual = canvas_frame_helpers.sizesEqual;
17
17
  pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
18
18
  return struct {
19
19
  pub fn dispatchGpuSurfaceFrame(self: *Runtime, app: runtime_api.App(Runtime), frame_event: platform.GpuSurfaceFrameEvent) anyerror!void {
20
+ // Media-surface adoption rides the compositor's
21
+ // presented-frame clock: staged producer frames (latest
22
+ // wins) are sampled once per frame event, BEFORE view state
23
+ // and the app dispatch, so a changed texture invalidates
24
+ // the very frame this event is about to present. Idle
25
+ // channels cost one fenced flag check each.
26
+ self.adoptMediaSurfaceFrames();
20
27
  var enriched_frame_event = frame_event;
21
28
  var had_pending_input = false;
22
29
  if (runtimeFindViewIndex(self, frame_event.window_id, frame_event.label)) |index| {