@native-sdk/cli 0.5.2 → 0.5.3

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 (82) hide show
  1. package/build.zig +41 -0
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.ts +39 -2
  6. package/packages/core/src/checker.ts +1 -1
  7. package/packages/core/src/emitter.ts +39 -3
  8. package/packages/core/src/infer.ts +53 -7
  9. package/skill-data/automation/SKILL.md +7 -4
  10. package/skill-data/core/references/app-model-runtime.md +3 -0
  11. package/skill-data/native-ui/SKILL.md +1 -0
  12. package/src/app_runner/root.zig +25 -0
  13. package/src/automation/protocol.zig +20 -1
  14. package/src/embed/host.zig +27 -0
  15. package/src/embed/tests.zig +69 -0
  16. package/src/embed/ui_host.zig +4 -0
  17. package/src/platform/macos/appkit_host.h +11 -0
  18. package/src/platform/macos/appkit_host.m +130 -0
  19. package/src/platform/macos/root.zig +34 -0
  20. package/src/platform/null_platform_tests.zig +39 -0
  21. package/src/platform/root.zig +3 -0
  22. package/src/platform/types.zig +109 -4
  23. package/src/primitives/canvas/chart.zig +7 -7
  24. package/src/primitives/canvas/chart_tests.zig +66 -0
  25. package/src/primitives/canvas/commands.zig +48 -0
  26. package/src/primitives/canvas/events.zig +161 -0
  27. package/src/primitives/canvas/font_ttf.zig +155 -8
  28. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  29. package/src/primitives/canvas/reference.zig +67 -8
  30. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  31. package/src/primitives/canvas/root.zig +25 -0
  32. package/src/primitives/canvas/ui.zig +35 -2
  33. package/src/primitives/canvas/ui_markup.zig +24 -0
  34. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  35. package/src/primitives/canvas/ui_markup_compiled.zig +40 -3
  36. package/src/primitives/canvas/ui_markup_compiled_tests.zig +33 -0
  37. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  38. package/src/primitives/canvas/ui_markup_contract_tests.zig +24 -0
  39. package/src/primitives/canvas/ui_markup_tests.zig +26 -0
  40. package/src/primitives/canvas/ui_markup_view.zig +53 -4
  41. package/src/primitives/canvas/ui_markup_view_tests.zig +73 -2
  42. package/src/primitives/canvas/ui_schema.zig +16 -0
  43. package/src/primitives/canvas/ui_schema_tests.zig +10 -11
  44. package/src/primitives/canvas/ui_tests.zig +31 -0
  45. package/src/primitives/canvas/vector.zig +258 -141
  46. package/src/primitives/canvas/widget_access.zig +1 -1
  47. package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
  48. package/src/primitives/canvas/widget_layout.zig +9 -4
  49. package/src/primitives/canvas/widget_render.zig +78 -40
  50. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  51. package/src/primitives/canvas/widget_semantics.zig +6 -1
  52. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  53. package/src/primitives/canvas/widget_text_input.zig +118 -10
  54. package/src/primitives/canvas/widgets.zig +16 -0
  55. package/src/root.zig +5 -0
  56. package/src/runtime/api.zig +13 -0
  57. package/src/runtime/automation_commands.zig +33 -0
  58. package/src/runtime/automation_widget_dispatch.zig +64 -0
  59. package/src/runtime/canvas_font_tests.zig +272 -3
  60. package/src/runtime/canvas_fonts.zig +60 -20
  61. package/src/runtime/canvas_frame_helpers.zig +15 -0
  62. package/src/runtime/canvas_image_tests.zig +26 -0
  63. package/src/runtime/canvas_images.zig +33 -7
  64. package/src/runtime/canvas_limits.zig +44 -8
  65. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  66. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  67. package/src/runtime/canvas_widget_events.zig +24 -4
  68. package/src/runtime/canvas_widget_runtime.zig +24 -7
  69. package/src/runtime/canvas_widget_state.zig +6 -1
  70. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  71. package/src/runtime/core.zig +98 -6
  72. package/src/runtime/flow.zig +27 -0
  73. package/src/runtime/gpu_surface_events.zig +7 -0
  74. package/src/runtime/media_surface.zig +726 -0
  75. package/src/runtime/media_surface_tests.zig +1476 -0
  76. package/src/runtime/root.zig +9 -0
  77. package/src/runtime/session_journal.zig +30 -3
  78. package/src/runtime/session_tests.zig +126 -4
  79. package/src/runtime/tests.zig +1 -0
  80. package/src/runtime/ts_ui_app.zig +56 -0
  81. package/src/runtime/ui_app.zig +58 -0
  82. package/src/runtime/ui_app_tests.zig +334 -0
@@ -1321,9 +1321,11 @@ test "the registry's a11y name classes match the engine's control predicates" {
1321
1321
  try testing.expect(canvas.widgetKindHitTarget(kind));
1322
1322
  try testing.expect(canvas.widgetKindClaimsPress(kind));
1323
1323
  }
1324
- // Image-class elements are announced under the image role.
1324
+ // Image-class elements are announced under the image role:
1325
+ // avatar and the media surface (pictorial content whose missing
1326
+ // label degrades but never blocks).
1325
1327
  if (entry.a11y_name == .image) {
1326
- try testing.expectEqual(canvas.WidgetKind.avatar, kind);
1328
+ try testing.expect(kind == .avatar or kind == .media_surface);
1327
1329
  }
1328
1330
  }
1329
1331
  }
@@ -2367,6 +2369,9 @@ pub const AvatarModel = struct {
2367
2369
  /// `fx.registerImageBytes`.
2368
2370
  user_image: canvas.ImageId = 0,
2369
2371
  user_name: []const u8 = "Casey Torres",
2372
+ /// A signed id field: bindings evaluate as i64, so a negative must
2373
+ /// reach the image seam as a value, never trap in the u64 cast.
2374
+ stale_image: i64 = -1,
2370
2375
 
2371
2376
  /// A pub fn producing an ImageId binds like a field.
2372
2377
  pub fn teammateImage(model: *const AvatarModel) canvas.ImageId {
@@ -2381,6 +2386,14 @@ pub const avatar_markup_source =
2381
2386
  \\</row>
2382
2387
  ;
2383
2388
 
2389
+ /// A negative model value into avatar's u64 image seam: both engines
2390
+ /// must fail the build with the avatar teaching, never trap.
2391
+ pub const avatar_negative_markup_source =
2392
+ \\<row>
2393
+ \\ <avatar image="{stale_image}">CT</avatar>
2394
+ \\</row>
2395
+ ;
2396
+
2384
2397
  pub const AvatarUi = canvas.Ui(AvatarMsg);
2385
2398
 
2386
2399
  /// The hand-written equivalent of the avatar markup: `ui.avatar` with
@@ -2451,6 +2464,12 @@ test "avatar image misuse fails the build with the teaching messages" {
2451
2464
  .source = "<row>\n <avatar image=\"{user_name}\">CT</avatar>\n</row>",
2452
2465
  .message = canvas.ui_markup.avatar_image_message,
2453
2466
  },
2467
+ .{
2468
+ // A negative integer can never be a u64 ImageId: the
2469
+ // teaching failure, not an @intCast trap.
2470
+ .source = avatar_negative_markup_source,
2471
+ .message = canvas.ui_markup.avatar_image_message,
2472
+ },
2454
2473
  .{
2455
2474
  // Scoped to avatar: the other image elements stay Zig views.
2456
2475
  .source = "<row>\n <badge image=\"{user_image}\">3</badge>\n</row>",
@@ -2466,6 +2485,58 @@ test "avatar image misuse fails the build with the teaching messages" {
2466
2485
  }
2467
2486
  }
2468
2487
 
2488
+ // -------------------------------------------- media-surface id binding
2489
+
2490
+ pub const SurfaceMsg = union(enum) { refresh };
2491
+
2492
+ pub const SurfaceModel = struct {
2493
+ preview: u64 = 5,
2494
+ /// A signed id field: bindings evaluate as i64, so a negative must
2495
+ /// reach the surface seam as a value, never trap in the u64 cast.
2496
+ stale_surface: i64 = -3,
2497
+ };
2498
+
2499
+ pub const surface_markup_source =
2500
+ \\<column>
2501
+ \\ <media-surface surface="{preview}" label="Preview" />
2502
+ \\</column>
2503
+ ;
2504
+
2505
+ /// A negative model value into media-surface's u64 surface seam: both
2506
+ /// engines must fail the build with the surface teaching, never trap.
2507
+ pub const surface_negative_markup_source =
2508
+ \\<column>
2509
+ \\ <media-surface surface="{stale_surface}" label="Preview" />
2510
+ \\</column>
2511
+ ;
2512
+
2513
+ pub const SurfaceUi = canvas.Ui(SurfaceMsg);
2514
+
2515
+ test "the media-surface surface binding resolves the model id; negatives fail the build" {
2516
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
2517
+ defer arena_state.deinit();
2518
+ const arena = arena_state.allocator();
2519
+ const SurfaceMarkup = markup_view.MarkupView(SurfaceModel, SurfaceMsg);
2520
+ const model = SurfaceModel{};
2521
+
2522
+ // The u64 model id rides options.image into the widget's image_id
2523
+ // (the media surface's surface-id channel).
2524
+ var view = try SurfaceMarkup.init(arena, surface_markup_source);
2525
+ var ui = SurfaceUi.init(arena);
2526
+ const tree = try ui.finalize(try view.build(&ui, &model));
2527
+ const surface = tree.root.children[0];
2528
+ try testing.expectEqual(canvas.WidgetKind.media_surface, surface.kind);
2529
+ try testing.expectEqual(@as(canvas.ImageId, 5), surface.image_id);
2530
+
2531
+ // A negative integer can never be a u64 surface id: the teaching
2532
+ // failure, not an @intCast trap.
2533
+ var negative_view = try SurfaceMarkup.init(arena, surface_negative_markup_source);
2534
+ var negative_ui = SurfaceUi.init(arena);
2535
+ try testing.expectError(error.MarkupBuild, negative_view.build(&negative_ui, &model));
2536
+ try testing.expectEqualStrings(canvas.ui_markup.media_surface_surface_message, negative_view.diagnostic.message);
2537
+ try testing.expect(negative_view.diagnostic.line > 0);
2538
+ }
2539
+
2469
2540
  // ------------------------------------- text alignment and grid columns
2470
2541
 
2471
2542
  pub const AlignMsg = union(enum) { refresh };
@@ -312,6 +312,14 @@ pub const elements = [_]ElementInfo{
312
312
  // end, the reference's trailing dock), so the element mints ONE
313
313
  // code and no attribute codes at all.
314
314
  .{ .code = 65, .name = "reactions", .rule_hook = "reactions" },
315
+ // The media surface: a leaf compositing a texture PRODUCED OUTSIDE
316
+ // the widget tree (video decoder, camera preview, an external
317
+ // renderer like mpv) into the layout like any widget. Its `surface`
318
+ // attribute binds the model-owned u64 surface id a producer targets
319
+ // (`Runtime.acquireMediaSurfaceProducer`) — the runtime-image-id
320
+ // binding shape, never a markup literal. Display-only like image
321
+ // and chart (presses fall through); pictorial for the a11y lint.
322
+ .{ .code = 66, .name = "media-surface", .widget_kind = "media_surface", .hit_target = false, .a11y_name = .image },
315
323
  };
316
324
 
317
325
  // ------------------------------------------------------------- attributes
@@ -464,6 +472,14 @@ pub const attrs = [_]AttrInfo{
464
472
  // unreachable from markup; absent keeps the token default
465
473
  // (`ControlMetricTokens.tooltip_show_delay_ms`).
466
474
  .{ .code = 80, .name = "tooltip-delay", .class = .whole, .group = .option, .field = "tooltip_delay" },
475
+ // The media-surface producer rendezvous (media-surface only; the
476
+ // validator scopes it): one {binding} to the model-owned u64 surface
477
+ // id a producer targets (`Runtime.acquireMediaSurfaceProducer`) —
478
+ // ids are model data in the runtime-image-id spirit, never markup
479
+ // literals; 0 is the unbound sentinel (the surface draws nothing,
480
+ // like an image leaf with id 0), and usable ids stay below the
481
+ // reserved namespace bit (bit 63), which acquire refuses.
482
+ .{ .code = 81, .name = "surface", .class = .binding_only, .group = .element },
467
483
  };
468
484
 
469
485
  // ----------------------------------------------------------------- events
@@ -21,15 +21,13 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
21
21
  // (append or slot them anywhere — order carries no meaning) and pin
22
22
  // the new fingerprint ONLY for additions; renames/renumbers are
23
23
  // schema-version-bump events, not silent edits.
24
- try testing.expectEqual(@as(usize, 65), schema.elements.len);
25
- try testing.expectEqual(@as(usize, 80), schema.attrs.len);
24
+ try testing.expectEqual(@as(usize, 66), schema.elements.len);
25
+ try testing.expectEqual(@as(usize, 81), schema.attrs.len);
26
26
  try testing.expectEqual(@as(usize, 10), schema.events.len);
27
- // The element table runs through the span composite (64) and the
28
- // bubble-reactions composite (65); the reaction pill's dock rides
29
- // the existing text-alignment attribute, so element additions can
30
- // leave the attr table untouched.
27
+ // The element table runs through the span composite (64), the
28
+ // bubble-reactions composite (65), and the media surface (66).
31
29
  try testing.expectEqual(
32
- @as(u64, 0x961be186c9929e4c),
30
+ @as(u64, 0x65ed870d5b6e279e),
33
31
  tableFingerprint(schema.ElementInfo, &schema.elements),
34
32
  );
35
33
  // The attr table runs through the split layout-tween attributes
@@ -37,10 +35,11 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
37
35
  // attributes x-labels (73), y-labels (74), and hover-details (75),
38
36
  // the later span additions scale (76) and underline (77), the
39
37
  // split enter-from attribute resize-origin (78), the quiet-surface
40
- // hover knob quiet-hover (79), and the anchored-tooltip hover-intent
41
- // delay tooltip-delay (80).
38
+ // hover knob quiet-hover (79), the anchored-tooltip hover-intent
39
+ // delay tooltip-delay (80), and the media-surface producer
40
+ // rendezvous surface (81).
42
41
  try testing.expectEqual(
43
- @as(u64, 0x5348b0f92c314d2a),
42
+ @as(u64, 0x046479d29c4f0c5e),
44
43
  tableFingerprint(schema.AttrInfo, &schema.attrs),
45
44
  );
46
45
  try testing.expectEqual(
@@ -91,7 +90,7 @@ test "registry event scoping names registry elements" {
91
90
  test "derived name lists mirror the registry" {
92
91
  // The derivations are the vocabulary every consumer reads; hold them
93
92
  // to the registry's own predicates.
94
- try testing.expectEqual(@as(usize, 53), schema.element_names.len);
93
+ try testing.expectEqual(@as(usize, 54), schema.element_names.len);
95
94
  for (schema.element_names) |name| {
96
95
  try testing.expect(schema.elementByName(name).?.rule_hook == null);
97
96
  }
@@ -354,6 +354,36 @@ test "textarea keyboard: enter edits a newline, submit rides the primary chord"
354
354
  try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(textarea.id, alt_enter));
355
355
  }
356
356
 
357
+ test "single-line keyboard fallback derivation sanitizes line breaks like the runtime seam" {
358
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
359
+ defer arena_state.deinit();
360
+
361
+ var ui = InboxUi.init(arena_state.allocator());
362
+ const tree = try ui.finalize(ui.column(.{ .gap = 8 }, .{
363
+ ui.el(.text_field, .{ .on_input = InboxUi.inputMsg(.draft) }, .{}),
364
+ ui.el(.textarea, .{ .on_input = InboxUi.inputMsg(.draft) }, .{}),
365
+ }));
366
+ const field = findByKind(tree.root, .text_field).?;
367
+ const textarea = findByKind(tree.root, .textarea).?;
368
+
369
+ // An un-stamped text_input event (a direct Tree consumer — nothing
370
+ // crossed the runtime) derives its insert locally, and the local
371
+ // derivation applies the SAME single-line sanitize rule the runtime
372
+ // seam stamps with: line breaks strip, so a model mirror can never
373
+ // hear bytes the retained editor would refuse.
374
+ const multi_line = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "a\nb\r\nc" };
375
+ try testing.expectEqualStrings("abc", tree.msgForKeyboard(field.id, multi_line).?.draft.insert_text);
376
+ try testing.expectEqualStrings("a\nb\r\nc", tree.msgForKeyboard(textarea.id, multi_line).?.draft.insert_text);
377
+
378
+ // An insert that is ONLY breaks suppresses outright.
379
+ const bare_breaks = canvas.WidgetKeyboardEvent{ .phase = .text_input, .text = "\r\n" };
380
+ try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(field.id, bare_breaks));
381
+
382
+ // A STAMPED edit (the runtime already sanitized it) passes through.
383
+ const stamped = canvas.WidgetKeyboardEvent{ .phase = .key_down, .edit = .{ .insert_text = "clean" } };
384
+ try testing.expectEqualStrings("clean", tree.msgForKeyboard(field.id, stamped).?.draft.insert_text);
385
+ }
386
+
357
387
  test "typed handlers imply accessibility actions" {
358
388
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
359
389
  defer arena_state.deinit();
@@ -1402,6 +1432,7 @@ test "widget kind codes are pinned: assigned at birth, declaration-order-indepen
1402
1432
  .{ .kind = .split_divider, .code = 58 },
1403
1433
  .{ .kind = .tree, .code = 59 },
1404
1434
  .{ .kind = .input_group, .code = 60 },
1435
+ .{ .kind = .media_surface, .code = 61 },
1405
1436
  };
1406
1437
  try testing.expectEqual(std.enums.values(canvas.WidgetKind).len, expected.len);
1407
1438
  for (expected) |entry| {