@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
@@ -357,7 +357,7 @@ test "a cancel that races the natural exit still reports cancelled and drops lin
357
357
  try std.testing.expectEqual(effects_mod.EffectExitReason.cancelled, h.app_state.model.exit_reason.?);
358
358
  }
359
359
 
360
- test "queue overflow drops lines loudly and truncates over-long lines" {
360
+ test "queue overflow drops lines with a carried drop count and truncates over-long lines" {
361
361
  var h = try Harness.create();
362
362
  defer h.destroy();
363
363
  const fx = &h.app_state.effects;
@@ -367,22 +367,26 @@ test "queue overflow drops lines loudly and truncates over-long lines" {
367
367
  test_stdin = null;
368
368
  try h.app_state.dispatch(&h.harness.runtime, 1, .start);
369
369
 
370
- // Fill the queue, then push three more lines that must drop.
370
+ // Fill the queue, then push more: a FED line against a full queue
371
+ // reports `EffectQueueFull` — never the live drop accounting, which
372
+ // would silently convert a journaled delivery into a drop under
373
+ // session replay (the live worker path keeps its counted drops; the
374
+ // replay pump answers this error by draining and feeding again).
371
375
  var index: usize = 0;
372
376
  while (index < effects_mod.max_effect_queue_entries) : (index += 1) {
373
377
  try fx.feedLine(stream_key, "fits");
374
378
  }
375
- try fx.feedLine(stream_key, "dropped 1");
376
- try fx.feedLine(stream_key, "dropped 2");
377
- try fx.feedLine(stream_key, "dropped 3");
379
+ try std.testing.expectError(error.EffectQueueFull, fx.feedLine(stream_key, "refused 1"));
380
+ try std.testing.expectError(error.EffectQueueFull, fx.feedLine(stream_key, "refused 2"));
378
381
 
379
382
  try h.drainWakes();
380
383
  try std.testing.expectEqual(@as(u32, 0), h.app_state.model.dropped_before_total);
381
384
 
382
- // The next delivered line carries the drop count; nothing is silent.
385
+ // Refusals counted nothing: the next delivered line reports zero
386
+ // drops before it.
383
387
  try fx.feedLine(stream_key, "after the storm");
384
388
  try h.drainWakes();
385
- try std.testing.expectEqual(@as(u32, 3), h.app_state.model.dropped_before_total);
389
+ try std.testing.expectEqual(@as(u32, 0), h.app_state.model.dropped_before_total);
386
390
 
387
391
  // Over-long lines arrive truncated and flagged.
388
392
  const long_line = [_]u8{'x'} ** (effects_mod.max_effect_line_bytes + 100);
@@ -390,10 +394,11 @@ test "queue overflow drops lines loudly and truncates over-long lines" {
390
394
  try h.drainWakes();
391
395
  try std.testing.expectEqual(@as(usize, 1), h.app_state.model.truncated_count);
392
396
 
393
- // The exit reports the lifetime drop total.
397
+ // The exit's lifetime drop total stays zero — nothing was dropped,
398
+ // only refused.
394
399
  try fx.feedExit(stream_key, 0);
395
400
  try h.drainWakes();
396
- try std.testing.expectEqual(@as(u32, 3), h.app_state.model.exit_dropped_lines);
401
+ try std.testing.expectEqual(@as(u32, 0), h.app_state.model.exit_dropped_lines);
397
402
  }
398
403
 
399
404
  test "a raised per-spawn line bound delivers long lines intact and truncates at the override" {
@@ -1536,3 +1541,156 @@ test "real executor reports unspawnable binaries as spawn_failed" {
1536
1541
  try std.testing.expectEqual(effects_mod.EffectExitReason.spawn_failed, h.app_state.model.exit_reason.?);
1537
1542
  try std.testing.expectEqual(@as(usize, 0), h.app_state.model.line_count);
1538
1543
  }
1544
+
1545
+ test "a spawn exit still undelivered occupies its key against a respawn; delivery frees it" {
1546
+ var h = try Harness.create();
1547
+ defer h.destroy();
1548
+ const fx = &h.app_state.effects;
1549
+ fx.executor = .fake;
1550
+
1551
+ test_argv = &.{"worker"};
1552
+ test_stdin = null;
1553
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1554
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1555
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1556
+
1557
+ // The fed exit queues the terminal and parks the slot — posted but
1558
+ // undelivered. A respawn of the same key inside that window must
1559
+ // reject: under session replay the first spawn is still a parked
1560
+ // `.running` fake here (its journaled exit feeds at the recorded
1561
+ // delivery position), so a live accept would journal a Msg stream
1562
+ // replay rejects.
1563
+ try fx.feedExit(stream_key, 0);
1564
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1565
+ try std.testing.expectEqual(@as(usize, 0), fx.pendingSpawnCount());
1566
+
1567
+ // Delivery order: the staged rejection first (loop-side pending),
1568
+ // then the queued exit.
1569
+ try h.drainWakes();
1570
+ try std.testing.expectEqual(@as(usize, 2), h.app_state.model.exit_count);
1571
+ try std.testing.expectEqual(effects_mod.EffectExitReason.exited, h.app_state.model.exit_reason.?);
1572
+ try std.testing.expectEqual(@as(i32, 0), h.app_state.model.exit_code);
1573
+
1574
+ // The window ends at delivery: the same key spawns again.
1575
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1576
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1577
+ }
1578
+
1579
+ /// One-shot flag for the respawn-from-own-exit idiom test below.
1580
+ var test_respawn_on_exit: bool = false;
1581
+
1582
+ /// `streamUpdate` plus the restart idiom: the exit handler answers its
1583
+ /// own terminal by respawning the same key (one-shot).
1584
+ fn respawnUpdate(model: *StreamModel, msg: StreamMsg, fx: *StreamEffects) void {
1585
+ if (msg == .done and test_respawn_on_exit) {
1586
+ test_respawn_on_exit = false;
1587
+ model.recordExit(msg.done);
1588
+ fx.spawn(.{
1589
+ .key = stream_key,
1590
+ .argv = test_argv,
1591
+ .on_line = StreamEffects.lineMsg(.line),
1592
+ .on_exit = StreamEffects.exitMsg(.done),
1593
+ });
1594
+ return;
1595
+ }
1596
+ streamUpdate(model, msg, fx);
1597
+ }
1598
+
1599
+ test "an update that respawns the same key from its own exit parks instead of rejecting" {
1600
+ var h = try Harness.createWith(respawnUpdate);
1601
+ defer h.destroy();
1602
+ const fx = &h.app_state.effects;
1603
+ fx.executor = .fake;
1604
+
1605
+ test_argv = &.{"worker"};
1606
+ test_stdin = null;
1607
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1608
+ test_respawn_on_exit = true;
1609
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1610
+ try fx.feedExit(stream_key, 0);
1611
+
1612
+ // The drain clears the undelivered-exit marker AND retires the slot
1613
+ // BEFORE the terminal Msg reaches update, so the handler's respawn
1614
+ // of its own key is a fresh accepted spawn — the restart idiom must
1615
+ // not regress. (The retire is the loop-side half of the worker's
1616
+ // post-then-store epilogue; on this fed path the slot was already
1617
+ // `.draining`, so the drain's store is an idempotent re-store.)
1618
+ try h.drainWakes();
1619
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.exit_count);
1620
+ try std.testing.expectEqual(effects_mod.EffectExitReason.exited, h.app_state.model.exit_reason.?);
1621
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1622
+
1623
+ // The respawned occupancy is a full fresh effect, not a resurrected
1624
+ // slot: its own exit delivers and the cycle restarts cleanly.
1625
+ test_respawn_on_exit = true;
1626
+ try fx.feedExit(stream_key, 7);
1627
+ try h.drainWakes();
1628
+ try std.testing.expectEqual(@as(usize, 2), h.app_state.model.exit_count);
1629
+ try std.testing.expectEqual(@as(i32, 7), h.app_state.model.exit_code);
1630
+ try std.testing.expectEqual(@as(usize, 1), fx.pendingSpawnCount());
1631
+ test_respawn_on_exit = false;
1632
+ }
1633
+
1634
+ /// Spawn slots carrying a set undelivered-exit marker.
1635
+ fn markedExitSlotCount(fx: *StreamEffects) usize {
1636
+ var count: usize = 0;
1637
+ for (&fx.slots) |*slot| {
1638
+ if (slot.kind == .spawn and slot.exit_undelivered) count += 1;
1639
+ }
1640
+ return count;
1641
+ }
1642
+
1643
+ test "consuming a fed lines exit clears the undelivered-exit marker" {
1644
+ var h = try Harness.create();
1645
+ defer h.destroy();
1646
+ const fx = &h.app_state.effects;
1647
+ fx.executor = .fake;
1648
+
1649
+ test_argv = &.{"worker"};
1650
+ test_stdin = null;
1651
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1652
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1653
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(fx));
1654
+
1655
+ // Posted but undelivered: the marker holds the slot (and the key).
1656
+ try fx.feedExit(stream_key, 0);
1657
+ try std.testing.expectEqual(@as(usize, 1), markedExitSlotCount(fx));
1658
+
1659
+ // Dequeueing the exit IS its delivery: the drain must clear the
1660
+ // marker when it consumes the exit, or `reclaimSlots` holds the
1661
+ // slot out of `.idle` forever.
1662
+ try h.drainWakes();
1663
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.exit_count);
1664
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(fx));
1665
+ }
1666
+
1667
+ test "every delivered lines exit hands its slot back for reuse" {
1668
+ if (builtin.os.tag == .windows) return error.SkipZigTest;
1669
+ var h = try Harness.create();
1670
+ defer h.destroy();
1671
+
1672
+ test_argv = &.{"/nonexistent/native-sdk-effects-test-binary"};
1673
+ test_stdin = null;
1674
+ test_max_line_bytes = effects_mod.max_effect_line_bytes;
1675
+ // Each round runs the real worker epilogue end to end (an
1676
+ // unspawnable binary is still worker truth: the worker posts a
1677
+ // `.spawn_failed` exit through the same mark-then-post commit) and
1678
+ // must return its slot. More rounds than the pool has slots proves
1679
+ // delivery frees them: a marker the drain's consume ever missed
1680
+ // would strand its slot in `.draining`, exhaust the pool, and turn
1681
+ // a later round's reason into `.rejected`.
1682
+ const io = std.testing.io;
1683
+ var round: usize = 1;
1684
+ while (round <= effects_mod.max_effects + 1) : (round += 1) {
1685
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
1686
+ var waited_ms: usize = 0;
1687
+ while (h.app_state.model.exit_count < round) : (waited_ms += 10) {
1688
+ if (waited_ms >= 20_000) return error.TestTimedOut;
1689
+ try h.drainWakes();
1690
+ try std.Io.sleep(io, std.Io.Duration.fromMilliseconds(10), .awake);
1691
+ }
1692
+ try std.testing.expectEqual(round, h.app_state.model.exit_count);
1693
+ try std.testing.expectEqual(effects_mod.EffectExitReason.spawn_failed, h.app_state.model.exit_reason.?);
1694
+ try std.testing.expectEqual(@as(usize, 0), markedExitSlotCount(&h.app_state.effects));
1695
+ }
1696
+ }