@native-sdk/cli 0.5.3 → 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 (79) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +223 -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/src/emitter.ts +2586 -259
  10. package/skill-data/native-ui/SKILL.md +3 -2
  11. package/skill-data/ts-core/SKILL.md +9 -1
  12. package/src/app_runner/root.zig +81 -1
  13. package/src/app_runner/ts_core_main.zig +4 -0
  14. package/src/embed/tests.zig +119 -1
  15. package/src/platform/linux/gtk_host.c +112 -3
  16. package/src/platform/linux/root.zig +71 -0
  17. package/src/platform/macos/appkit_host.h +48 -2
  18. package/src/platform/macos/appkit_host.m +533 -34
  19. package/src/platform/macos/cef_host.mm +262 -10
  20. package/src/platform/macos/root.zig +92 -4
  21. package/src/platform/null_platform.zig +298 -5
  22. package/src/platform/root.zig +33 -0
  23. package/src/platform/types.zig +138 -4
  24. package/src/platform/windows/root.zig +134 -0
  25. package/src/platform/windows/webview2_host.cpp +152 -40
  26. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  27. package/src/primitives/app_manifest/root.zig +1 -0
  28. package/src/primitives/app_manifest/types.zig +32 -0
  29. package/src/primitives/canvas/tests.zig +1 -0
  30. package/src/primitives/canvas/ui.zig +11 -7
  31. package/src/primitives/canvas/ui_markup.zig +58 -34
  32. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  33. package/src/primitives/canvas/ui_markup_compiled.zig +23 -8
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +1 -1
  36. package/src/primitives/canvas/ui_markup_contract_tests.zig +26 -0
  37. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  38. package/src/primitives/canvas/ui_markup_tests.zig +29 -9
  39. package/src/primitives/canvas/ui_markup_view.zig +29 -11
  40. package/src/primitives/canvas/ui_markup_view_tests.zig +150 -9
  41. package/src/primitives/canvas/ui_schema.zig +13 -0
  42. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  43. package/src/root.zig +7 -0
  44. package/src/runtime/api.zig +6 -4
  45. package/src/runtime/bridge_payload.zig +7 -0
  46. package/src/runtime/bridge_responses.zig +5 -0
  47. package/src/runtime/builtin_bridge.zig +9 -4
  48. package/src/runtime/canvas_font_tests.zig +439 -2
  49. package/src/runtime/canvas_fonts.zig +61 -6
  50. package/src/runtime/canvas_image_tests.zig +195 -0
  51. package/src/runtime/canvas_images.zig +45 -12
  52. package/src/runtime/core.zig +58 -11
  53. package/src/runtime/effects.zig +1664 -43
  54. package/src/runtime/effects_fetch_tests.zig +89 -1
  55. package/src/runtime/effects_file_tests.zig +41 -1
  56. package/src/runtime/effects_image_tests.zig +1304 -0
  57. package/src/runtime/effects_tests.zig +153 -0
  58. package/src/runtime/flow.zig +17 -0
  59. package/src/runtime/root.zig +11 -0
  60. package/src/runtime/session_blobs.zig +689 -0
  61. package/src/runtime/session_journal.zig +85 -21
  62. package/src/runtime/session_record.zig +27 -2
  63. package/src/runtime/session_replay.zig +168 -16
  64. package/src/runtime/session_tests.zig +1992 -0
  65. package/src/runtime/shell_layout.zig +7 -0
  66. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  67. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +439 -4
  70. package/src/runtime/ts_core_host_tests.zig +41 -0
  71. package/src/runtime/ts_ui_app.zig +7 -0
  72. package/src/runtime/ui_app.zig +111 -6
  73. package/src/runtime/ui_app_window_tests.zig +468 -0
  74. package/src/runtime/window_command_bridge_tests.zig +117 -0
  75. package/src/runtime/window_storage.zig +32 -0
  76. package/src/runtime/window_views.zig +61 -1
  77. package/src/tooling/manifest.zig +75 -0
  78. package/src/tooling/raw_manifest.zig +2 -0
  79. 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
+ }
@@ -618,6 +618,23 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
618
618
  };
619
619
  self.windows[runtime_index].source_reloads_from_app = true;
620
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
+ }
621
638
  _ = try self.options.platform.services.createWindow(window);
622
639
  }
623
640
  try self.options.platform.services.loadWindowWebView(window.id, self.windows[runtime_index].source.?);
@@ -98,6 +98,12 @@ pub const EffectAudioEventKind = runtime_effects.EffectAudioEventKind;
98
98
  pub const EffectAudioSource = runtime_effects.EffectAudioSource;
99
99
  pub const audioCachePath = runtime_effects.audioCachePath;
100
100
  pub const max_effect_audio_path_bytes = runtime_effects.max_effect_audio_path_bytes;
101
+ pub const EffectImageResult = runtime_effects.EffectImageResult;
102
+ pub const EffectImageOutcome = runtime_effects.EffectImageOutcome;
103
+ pub const imageCachePath = runtime_effects.imageCachePath;
104
+ pub const max_effect_image_path_bytes = runtime_effects.max_effect_image_path_bytes;
105
+ pub const max_effect_image_bytes = runtime_effects.max_effect_image_bytes;
106
+ pub const effect_image_blob_hash_len = runtime_effects.effect_image_blob_hash_len;
101
107
  pub const EffectHostResult = runtime_effects.EffectHostResult;
102
108
  pub const HostCallBinding = runtime_effects.HostCallBinding;
103
109
  pub const max_effect_host_name_bytes = runtime_effects.max_effect_host_name_bytes;
@@ -120,9 +126,14 @@ pub const TsUiApp = runtime_ts_ui_app.TsUiApp;
120
126
  const runtime_session_journal = @import("session_journal.zig");
121
127
  const runtime_session_record = @import("session_record.zig");
122
128
  const runtime_session_replay = @import("session_replay.zig");
129
+ const runtime_session_blobs = @import("session_blobs.zig");
123
130
  pub const session_journal = runtime_session_journal;
131
+ pub const session_blobs = runtime_session_blobs;
124
132
  pub const SessionRecorder = runtime_session_record.SessionRecorder;
125
133
  pub const SessionRecorderSink = runtime_session_record.RecorderSink;
134
+ pub const SessionBlobSink = runtime_session_blobs.SessionBlobSink;
135
+ pub const SessionBlobSource = runtime_session_blobs.SessionBlobSource;
136
+ pub const SessionBlobDirStore = runtime_session_blobs.DirBlobStore;
126
137
  pub const SessionHeader = runtime_session_journal.Header;
127
138
  pub const sessionHeaderNow = runtime_session_record.headerNow;
128
139
  pub const sessionPlatformName = runtime_session_replay.currentPlatformName;