@native-sdk/cli 0.8.0 → 0.8.2

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 (75) hide show
  1. package/README.md +4 -4
  2. package/build.zig +49 -23
  3. package/package.json +10 -10
  4. package/packages/core/compile-surface/core.ts +16 -0
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/core.d.ts +11 -0
  8. package/packages/core/sdk/core.ts +29 -2
  9. package/packages/core/sdk/events.d.ts +10 -0
  10. package/packages/core/sdk/events.ts +24 -4
  11. package/packages/core/src/checker.ts +1 -1
  12. package/packages/core/src/contract.ts +4 -1
  13. package/packages/core/src/devhost.ts +10 -1
  14. package/packages/core/src/diagnostics.ts +1 -1
  15. package/skill-data/core/SKILL.md +48 -20
  16. package/skill-data/core/references/app-model-runtime.md +2 -2
  17. package/skill-data/core/references/project-anatomy.md +22 -6
  18. package/skill-data/native-ui/SKILL.md +71 -29
  19. package/skill-data/ts-core/SKILL.md +13 -8
  20. package/skill-data/zig/SKILL.md +1 -1
  21. package/skills/native-sdk/SKILL.md +6 -5
  22. package/src/app_runner/ts_core_main.zig +2 -1
  23. package/src/embed/tests.zig +3 -1
  24. package/src/platform/macos/appkit_host.h +4 -4
  25. package/src/platform/macos/appkit_host.m +24 -4
  26. package/src/platform/macos/cef_host.mm +22 -6
  27. package/src/platform/macos/root.zig +2 -2
  28. package/src/primitives/canvas/events.zig +8 -0
  29. package/src/primitives/canvas/markdown.zig +2010 -57
  30. package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
  31. package/src/primitives/canvas/markdown_tests.zig +778 -3
  32. package/src/primitives/canvas/root.zig +2 -0
  33. package/src/primitives/canvas/test_support.zig +1 -0
  34. package/src/primitives/canvas/ui.zig +53 -8
  35. package/src/primitives/canvas/ui_markup.zig +10 -1
  36. package/src/primitives/canvas/ui_markup_compiled.zig +61 -3
  37. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  38. package/src/primitives/canvas/ui_markup_contract.zig +31 -3
  39. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  40. package/src/primitives/canvas/ui_markup_view.zig +49 -3
  41. package/src/primitives/canvas/ui_markup_view_tests.zig +61 -2
  42. package/src/primitives/canvas/ui_schema.zig +8 -1
  43. package/src/primitives/canvas/ui_schema_tests.zig +7 -6
  44. package/src/primitives/canvas/ui_tests.zig +14 -0
  45. package/src/primitives/canvas/widget_access.zig +4 -3
  46. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  47. package/src/primitives/canvas/widget_layout.zig +26 -3
  48. package/src/primitives/canvas/widget_metrics.zig +21 -3
  49. package/src/primitives/canvas/widget_render.zig +87 -1
  50. package/src/primitives/canvas/widget_routing.zig +12 -7
  51. package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
  52. package/src/primitives/canvas/widgets.zig +40 -0
  53. package/src/root.zig +1 -0
  54. package/src/runtime/automation_widget_dispatch.zig +19 -0
  55. package/src/runtime/canvas_limits.zig +5 -0
  56. package/src/runtime/canvas_widget_event_tests.zig +424 -8
  57. package/src/runtime/canvas_widget_events.zig +254 -7
  58. package/src/runtime/canvas_widget_state.zig +123 -1
  59. package/src/runtime/core.zig +6 -0
  60. package/src/runtime/effects.zig +36 -1
  61. package/src/runtime/effects_fetch_tests.zig +21 -0
  62. package/src/runtime/effects_notification_tests.zig +65 -0
  63. package/src/runtime/gpu_surface_events.zig +60 -14
  64. package/src/runtime/tests.zig +1 -0
  65. package/src/runtime/ts_core_host.zig +16 -0
  66. package/src/runtime/ts_ui_app.zig +55 -2
  67. package/src/runtime/ui_app.zig +112 -0
  68. package/src/runtime/ui_app_tests.zig +356 -0
  69. package/src/runtime/view.zig +35 -0
  70. package/src/runtime/view_widget_tree.zig +12 -0
  71. package/tools/corewire/core_abi.zig +1 -0
  72. package/tools/corewire/emit.zig +55 -8
  73. package/tools/corewire/emit_facade.zig +63 -2
  74. package/tools/corewire/emit_profile.zig +4 -1
  75. package/tools/corewire/sidecar.zig +36 -6
@@ -111,7 +111,8 @@ const fixed_exports = [_][]const u8{
111
111
  "dispatch_bool", "dispatch_enum", "dispatch_record", "dispatch_text_input",
112
112
  "dispatch_scroll_state", "abi_subscriptions", "model_snapshot", "helper_call",
113
113
  "abi_command_msg", "abi_frame_msg", "abi_key_msg", "abi_pinch_msg",
114
- "appearanceMsg", "chromeMsg", "envMsgs", "viewUnbound",
114
+ "abi_drop_msg", "appearanceMsg", "chromeMsg", "envMsgs",
115
+ "viewUnbound",
115
116
  };
116
117
 
117
118
  /// Ambient VALUE bindings generated code calls directly. A model helper is
@@ -419,6 +420,9 @@ const FacadeEmitter = struct {
419
420
  if (self.sidecar.channels.pinch_msg and std.mem.eql(u8, name, "PinchPhase")) {
420
421
  self.diags.flag("types", "\"PinchPhase\" collides with the SDK vocabulary the wired pinch channel imports; rename the type in the core source", .{});
421
422
  }
423
+ if (self.sidecar.channels.drop_msg and std.mem.eql(u8, name, "FileDropPoint")) {
424
+ self.diags.flag("types", "\"FileDropPoint\" collides with the SDK vocabulary the wired file-drop channel imports; rename the type in the core source", .{});
425
+ }
422
426
  }
423
427
  // Arm, member, and field names become the compiled module's
424
428
  // union members and struct fields verbatim.
@@ -764,6 +768,7 @@ const FacadeEmitter = struct {
764
768
  if (self.sidecar.channels.frame_msg) try values.append(self.arena, "frameMsg as nscfChanFrameMsg");
765
769
  if (self.sidecar.channels.key_msg) try values.append(self.arena, "keyMsg as nscfChanKeyMsg");
766
770
  if (self.sidecar.channels.pinch_msg) try values.append(self.arena, "pinchMsg as nscfChanPinchMsg");
771
+ if (self.sidecar.channels.drop_msg) try values.append(self.arena, "dropMsg as nscfChanDropMsg");
767
772
  for (self.sidecar.model_helpers) |helper| {
768
773
  try values.append(self.arena, try std.fmt.allocPrint(self.arena, "{s} as nscfH_{s}", .{ helper.name, helper.name }));
769
774
  }
@@ -812,6 +817,9 @@ const FacadeEmitter = struct {
812
817
  if (body.needs_pinch_phase) {
813
818
  try self.raw("import type { PinchPhase } from \"./sdk/events.ts\";\n");
814
819
  }
820
+ if (self.sidecar.channels.drop_msg) {
821
+ try self.raw("import type { FileDropPoint } from \"./sdk/events.ts\";\n");
822
+ }
815
823
  self.needs_pinch_phase = body.needs_pinch_phase;
816
824
  }
817
825
 
@@ -1542,7 +1550,7 @@ const FacadeEmitter = struct {
1542
1550
 
1543
1551
  fn channelEntries(self: *FacadeEmitter) Error!void {
1544
1552
  const chan = self.sidecar.channels;
1545
- if (!(chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg)) return;
1553
+ if (!(chan.command_msg or chan.frame_msg or chan.key_msg or chan.pinch_msg or chan.drop_msg)) return;
1546
1554
  self.use(.sink);
1547
1555
  self.use(.trap);
1548
1556
  try self.print(
@@ -1644,6 +1652,53 @@ const FacadeEmitter = struct {
1644
1652
  );
1645
1653
  self.needs_member_trap = true;
1646
1654
  }
1655
+ if (chan.drop_msg) {
1656
+ self.use(.read_f64);
1657
+ self.use(.read_u32);
1658
+ self.use(.read_bool);
1659
+ self.use(.read_bytes_body);
1660
+ self.use(.assert_consumed);
1661
+ self.use(.ascii_string);
1662
+ try self.raw(
1663
+ \\
1664
+ \\export function abi_drop_msg(event: Uint8Array): Uint8Array {
1665
+ \\ let at = 0;
1666
+ \\ const windowId = nscfReadF64(event, at);
1667
+ \\ at += 8;
1668
+ \\ const viewLabelLen = nscfReadU32(event, at);
1669
+ \\ at += 4;
1670
+ \\ const viewLabel = nscfReadBytesBody(event, at, viewLabelLen);
1671
+ \\ at += viewLabelLen;
1672
+ \\ const pointPresent = nscfReadBool(event, at);
1673
+ \\ at += 1;
1674
+ \\ let point: FileDropPoint | null = null;
1675
+ \\ if (pointPresent) {
1676
+ \\ const x = nscfReadF64(event, at);
1677
+ \\ at += 8;
1678
+ \\ const y = nscfReadF64(event, at);
1679
+ \\ at += 8;
1680
+ \\ point = { x: x, y: y };
1681
+ \\ }
1682
+ \\ const pathCount = nscfReadU32(event, at);
1683
+ \\ at += 4;
1684
+ \\ const paths: Uint8Array[] = [];
1685
+ \\ for (let i = 0; i < pathCount; i++) {
1686
+ \\ const pathLen = nscfReadU32(event, at);
1687
+ \\ at += 4;
1688
+ \\ paths.push(nscfReadBytesBody(event, at, pathLen));
1689
+ \\ at += pathLen;
1690
+ \\ }
1691
+ \\ nscfAssertConsumed(event, at);
1692
+ \\ return nscfPackMsg(nscfChanDropMsg({
1693
+ \\ windowId: windowId,
1694
+ \\ viewLabel: nscfAsciiString(viewLabel),
1695
+ \\ point: point,
1696
+ \\ paths: paths,
1697
+ \\ }));
1698
+ \\}
1699
+ \\
1700
+ );
1701
+ }
1647
1702
  }
1648
1703
 
1649
1704
  /// The canonical payload encoding of any produced message, off the
@@ -2658,6 +2713,12 @@ const FacadeEmitter = struct {
2658
2713
  \\ nscfWU8(sink, 0x1c);
2659
2714
  \\ nscfWShortText(sink, cmd.key);
2660
2715
  \\ return;
2716
+ \\ case "show_notification":
2717
+ \\ nscfWU8(sink, 0x1d);
2718
+ \\ nscfWBytes(sink, cmd.title);
2719
+ \\ nscfWBytes(sink, cmd.subtitle);
2720
+ \\ nscfWBytes(sink, cmd.body);
2721
+ \\ return;
2661
2722
  \\ case "batch":
2662
2723
  \\ for (let i = 0; i < cmd.cmds.length; i++) {
2663
2724
  \\ nscfEncodeCmd(sink, cmd.cmds[i]!);
@@ -74,6 +74,7 @@ const export_signatures = [_]ExportSignature{
74
74
  .{ .suffix = "frame_msg", .export_name = "abi_frame_msg", .params = &.{ "f64", "f64", "f64", "f64" }, .returns = "bytes" },
75
75
  .{ .suffix = "key_msg", .export_name = "abi_key_msg", .params = &.{ "bytes", "u8", "u8", "u8", "u8" }, .returns = "bytes" },
76
76
  .{ .suffix = "pinch_msg", .export_name = "abi_pinch_msg", .params = &.{ "f64", "bytes", "u32", "f64", "f64", "f64" }, .returns = "bytes" },
77
+ .{ .suffix = "drop_msg", .export_name = "abi_drop_msg", .params = &.{"bytes"}, .returns = "bytes" },
77
78
  };
78
79
 
79
80
  /// Suffixes that never enter the export map: the mode-provided symbols
@@ -417,7 +418,8 @@ test "wired channels join the export map with their wire shapes" {
417
418
  const arena = arena_state.allocator();
418
419
  var source = try std.mem.replaceOwned(u8, arena, sidecar_mod.minimal_valid_json, "\"key_msg\": false", "\"key_msg\": true");
419
420
  source = try std.mem.replaceOwned(u8, arena, source, "\"pinch_msg\": false", "\"pinch_msg\": true");
420
- source = try std.mem.replaceOwned(u8, arena, source, "\"helper_call\"]", "\"helper_call\", \"key_msg\", \"pinch_msg\"]");
421
+ source = try std.mem.replaceOwned(u8, arena, source, "\"drop_msg\": false", "\"drop_msg\": true");
422
+ source = try std.mem.replaceOwned(u8, arena, source, "\"helper_call\"]", "\"helper_call\", \"key_msg\", \"pinch_msg\", \"drop_msg\"]");
421
423
  const generated = try profileFromJson(arena, source, default_entry);
422
424
  // The wire-shaped signatures: bytes as buffers, u8 modifier
423
425
  // booleans, the pinch phase a u32 member index. The export names
@@ -425,6 +427,7 @@ test "wired channels join the export map with their wire shapes" {
425
427
  // prefix.
426
428
  try testing.expect(std.mem.indexOf(u8, generated, "{ \"export\": \"abi_key_msg\", \"symbol\": \"nsc_core_key_msg\", \"params\": [\"bytes\", \"u8\", \"u8\", \"u8\", \"u8\"], \"returns\": \"bytes\" }") != null);
427
429
  try testing.expect(std.mem.indexOf(u8, generated, "{ \"export\": \"abi_pinch_msg\", \"symbol\": \"nsc_core_pinch_msg\", \"params\": [\"f64\", \"bytes\", \"u32\", \"f64\", \"f64\", \"f64\"], \"returns\": \"bytes\" }") != null);
430
+ try testing.expect(std.mem.indexOf(u8, generated, "{ \"export\": \"abi_drop_msg\", \"symbol\": \"nsc_core_drop_msg\", \"params\": [\"bytes\"], \"returns\": \"bytes\" }") != null);
428
431
  try testing.expect(std.mem.indexOf(u8, generated, "abi_command_msg") == null);
429
432
  try testing.expect(std.mem.indexOf(u8, generated, "abi_frame_msg") == null);
430
433
  }
@@ -158,6 +158,7 @@ pub const Channels = struct {
158
158
  frame_msg: bool,
159
159
  key_msg: bool,
160
160
  pinch_msg: bool,
161
+ drop_msg: bool,
161
162
  appearance_msg: ?[]const u8,
162
163
  chrome_msg: ?[]const u8,
163
164
  env_msgs: []const EnvMsg,
@@ -217,7 +218,7 @@ pub const Sidecar = struct {
217
218
  /// canonical order the sidecar's `abi.exports` must list them: the two
218
219
  /// identity getters, then the mode-provided entries (sink registration,
219
220
  /// init, collect, result reset), then the program's entry-point map
220
- /// (core_abi.zig binds the matching extern signatures). The four
221
+ /// (core_abi.zig binds the matching extern signatures). The five
221
222
  /// conditional channel-entry suffixes follow, present exactly when the
222
223
  /// matching channel is wired.
223
224
  pub const unconditional_exports = [_][]const u8{
@@ -247,6 +248,7 @@ pub const conditional_exports = [_][]const u8{
247
248
  "frame_msg",
248
249
  "key_msg",
249
250
  "pinch_msg",
251
+ "drop_msg",
250
252
  };
251
253
 
252
254
  // ------------------------------------------------------------ reading
@@ -489,6 +491,8 @@ const Mapper = struct {
489
491
  return self.diags.fail("format", "this reader implements sidecar format {d}, found {d} — upgrade the SDK tooling or pin the compiler release that matches it", .{ supported_format, format });
490
492
  }
491
493
 
494
+ const abi = try self.mapAbi(try top.get("abi"));
495
+ const channels = try self.mapChannels(try top.get("channels"), abiHasExport(abi, "drop_msg"));
492
496
  return .{
493
497
  .format = format,
494
498
  .wire_version = try self.integer(try top.get("wire_version"), "wire_version"),
@@ -507,8 +511,8 @@ const Mapper = struct {
507
511
  .init_returns_bare = try self.optionalBoolean(top.map, "init_returns_bare", "", false),
508
512
  .update_returns_bare = try self.optionalBoolean(top.map, "update_returns_bare", "", false),
509
513
  .has_subscriptions = try self.boolean(try top.get("has_subscriptions"), "has_subscriptions"),
510
- .channels = try self.mapChannels(try top.get("channels")),
511
- .abi = try self.mapAbi(try top.get("abi")),
514
+ .channels = channels,
515
+ .abi = abi,
512
516
  .integer_slots = try self.mapIntegerSlots(try top.get("integer_slots")),
513
517
  .deterministic = try self.boolean(try top.get("deterministic"), "deterministic"),
514
518
  .async_free = try self.boolean(try top.get("async_free"), "async_free"),
@@ -777,9 +781,9 @@ const Mapper = struct {
777
781
  return self.diags.fail(self.path("{s}.kind", .{at}), "unknown payload descriptor kind \"{s}\" — this reader is too old for this sidecar; upgrade the SDK tooling or pin the compiler release it was built for (half-understanding a message arm is how wrong dispatch ships)", .{kind});
778
782
  }
779
783
 
780
- fn mapChannels(self: *Mapper, value: std.json.Value) error{ Refused, OutOfMemory }!Channels {
784
+ fn mapChannels(self: *Mapper, value: std.json.Value, drop_default: bool) error{ Refused, OutOfMemory }!Channels {
781
785
  const entry = try self.members(value, "channels", &.{
782
- "command_msg", "frame_msg", "key_msg", "pinch_msg", "appearance_msg", "chrome_msg", "env_msgs",
786
+ "command_msg", "frame_msg", "key_msg", "pinch_msg", "drop_msg", "appearance_msg", "chrome_msg", "env_msgs",
783
787
  });
784
788
  entry.warnUnknown();
785
789
  const env_value = try self.array(try entry.get("env_msgs"), "channels.env_msgs");
@@ -798,6 +802,11 @@ const Mapper = struct {
798
802
  .frame_msg = try self.boolean(try entry.get("frame_msg"), "channels.frame_msg"),
799
803
  .key_msg = try self.boolean(try entry.get("key_msg"), "channels.key_msg"),
800
804
  .pinch_msg = try self.boolean(try entry.get("pinch_msg"), "channels.pinch_msg"),
805
+ // Additive over the pinned compiler's format-1 emitter: older
806
+ // compilers preserve the profile-declared ABI export but do not
807
+ // know this channel fact yet, so the export list is its honest
808
+ // compatibility default. New frontend sidecars state it directly.
809
+ .drop_msg = try self.optionalBoolean(entry.map, "drop_msg", "channels", drop_default),
801
810
  .appearance_msg = try self.armNameOrNull(try entry.get("appearance_msg"), "channels.appearance_msg"),
802
811
  .chrome_msg = try self.armNameOrNull(try entry.get("chrome_msg"), "channels.chrome_msg"),
803
812
  .env_msgs = env_msgs,
@@ -1391,7 +1400,11 @@ pub fn findArm(msg: Msg, name: []const u8) ?*const MsgArm {
1391
1400
  }
1392
1401
 
1393
1402
  fn exportListed(sidecar: Sidecar, suffix: []const u8) bool {
1394
- for (sidecar.abi.exports) |entry| {
1403
+ return abiHasExport(sidecar.abi, suffix);
1404
+ }
1405
+
1406
+ fn abiHasExport(abi: Abi, suffix: []const u8) bool {
1407
+ for (abi.exports) |entry| {
1395
1408
  if (std.mem.eql(u8, entry, suffix)) return true;
1396
1409
  }
1397
1410
  return false;
@@ -1431,6 +1444,7 @@ fn validateChannels(sidecar: Sidecar, diags: *Diagnostics) void {
1431
1444
  .{ .name = "frame_msg", .wired = sidecar.channels.frame_msg },
1432
1445
  .{ .name = "key_msg", .wired = sidecar.channels.key_msg },
1433
1446
  .{ .name = "pinch_msg", .wired = sidecar.channels.pinch_msg },
1447
+ .{ .name = "drop_msg", .wired = sidecar.channels.drop_msg },
1434
1448
  };
1435
1449
  for (function_channels) |channel| {
1436
1450
  const listed = exportListed(sidecar, channel.name);
@@ -1844,6 +1858,7 @@ pub const minimal_valid_json =
1844
1858
  \\ "frame_msg": false,
1845
1859
  \\ "key_msg": false,
1846
1860
  \\ "pinch_msg": false,
1861
+ \\ "drop_msg": false,
1847
1862
  \\ "appearance_msg": null,
1848
1863
  \\ "chrome_msg": null,
1849
1864
  \\ "env_msgs": []
@@ -1865,6 +1880,21 @@ pub const minimal_valid_json =
1865
1880
  \\}
1866
1881
  ;
1867
1882
 
1883
+ test "drop_msg infers from the ABI export for older format-1 emitters" {
1884
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
1885
+ defer arena_state.deinit();
1886
+ const arena = arena_state.allocator();
1887
+
1888
+ // The pinned external compiler predates the additive channel flag but
1889
+ // preserves profile-declared exports in the authoritative ABI list.
1890
+ var source = try std.mem.replaceOwned(u8, arena, minimal_valid_json, " \"drop_msg\": false,\n", "");
1891
+ source = try std.mem.replaceOwned(u8, arena, source, " \"helper_call\"]", " \"helper_call\", \"drop_msg\"]");
1892
+ var diags = Diagnostics{ .arena = arena };
1893
+ const parsed = try read(arena, source, &diags);
1894
+ try std.testing.expect(parsed.channels.drop_msg);
1895
+ try std.testing.expectEqual(@as(usize, 0), diags.list.items.len);
1896
+ }
1897
+
1868
1898
  test "effective sidecar carries f64 demotions into its type table and attestations" {
1869
1899
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
1870
1900
  defer arena_state.deinit();