@native-sdk/cli 0.5.4 → 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 (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +534 -3
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -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 +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  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 +599 -3
  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 +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1283 -66
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +70 -1
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +240 -24
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +473 -13
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +109 -15
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2333 -63
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
@@ -58,6 +58,19 @@ const SessionModel = struct {
58
58
  zoom: f32 = 1,
59
59
  pinch_begins: u32 = 0,
60
60
  pinch_ends: u32 = 0,
61
+ /// Hover-Msg counters: the reference session moves the pointer onto
62
+ /// the increment button (a hover listener) and off again, so the
63
+ /// journal records only the raw pointer moves and replay must
64
+ /// re-derive the same enter/leave containment edges.
65
+ hover_enters: u32 = 0,
66
+ hover_leaves: u32 = 0,
67
+ /// The two-axis shelf's `on_scroll` mirror: a recorded diagonal
68
+ /// wheel must replay to the identical per-axis offsets — the
69
+ /// journal records only the raw scroll input event (both deltas),
70
+ /// and replay re-derives the same per-axis routing and physics.
71
+ shelf_offset_x: f32 = 0,
72
+ shelf_offset_y: f32 = 0,
73
+ shelf_scrolls: u32 = 0,
61
74
 
62
75
  fn bodyText(self: *const SessionModel) []const u8 {
63
76
  return self.body[0..self.body_len];
@@ -82,11 +95,14 @@ const SessionMsg = union(enum) {
82
95
  query_edit: canvas.TextInputEvent,
83
96
  name_edit: canvas.TextInputEvent,
84
97
  pinch: platform.PinchEvent,
98
+ hover_enter,
99
+ hover_leave,
85
100
  fetched: effects_mod.EffectResponse,
86
101
  line: effects_mod.EffectLine,
87
102
  exited: effects_mod.EffectExit,
88
103
  tick: effects_mod.EffectTimer,
89
104
  audio_event: effects_mod.EffectAudio,
105
+ shelf_scrolled: canvas.ScrollState,
90
106
  };
91
107
 
92
108
  const SessionApp = ui_app_mod.UiApp(SessionModel, SessionMsg);
@@ -114,6 +130,11 @@ fn sessionUpdate(model: *SessionModel, msg: SessionMsg, fx: *SessionApp.Effects)
114
130
  .on_fire = SessionApp.Effects.timerMsg(.tick),
115
131
  });
116
132
  },
133
+ .shelf_scrolled => |scroll_state| {
134
+ model.shelf_offset_x = scroll_state.offset_x;
135
+ model.shelf_offset_y = scroll_state.offset_y;
136
+ model.shelf_scrolls += 1;
137
+ },
117
138
  .start_audio => fx.playAudio(.{
118
139
  .key = 9,
119
140
  .path = "assets/session-track.mp3",
@@ -133,6 +154,8 @@ fn sessionUpdate(model: *SessionModel, msg: SessionMsg, fx: *SessionApp.Effects)
133
154
  },
134
155
  .query_edit => |edit| applyMirrorEdit(&model.query, &model.query_len, &model.query_anchor, &model.query_focus, &model.query_edits, edit),
135
156
  .name_edit => |edit| applyMirrorEdit(&model.name, &model.name_len, &model.name_anchor, &model.name_focus, &model.name_edits, edit),
157
+ .hover_enter => model.hover_enters += 1,
158
+ .hover_leave => model.hover_leaves += 1,
136
159
  .pinch => |pinch| switch (pinch.phase) {
137
160
  .begin => model.pinch_begins += 1,
138
161
  .change => model.zoom *= (1 + pinch.scale),
@@ -184,7 +207,12 @@ fn sessionView(ui: *SessionApp.Ui, model: *const SessionModel) SessionApp.Ui.Nod
184
207
  ui.el(.textarea, .{ .text = "line one\nline two" }, .{}),
185
208
  ui.text(.{}, ui.fmt("Query {s} ({d}) Name {s} ({d})", .{ model.queryText(), model.query_edits, model.nameText(), model.name_edits })),
186
209
  ui.text(.{}, ui.fmt("Zoom {d:.4} ({d}/{d})", .{ model.zoom, model.pinch_begins, model.pinch_ends })),
187
- ui.button(.{ .on_press = .increment }, "Increment"),
210
+ ui.text(.{}, ui.fmt("Hover {d}/{d}", .{ model.hover_enters, model.hover_leaves })),
211
+ // A BOTH-axes scroll region wider and taller than its viewport:
212
+ // the recorded diagonal wheel below scrolls it on both axes.
213
+ ui.scroll(.{ .height = 60, .axis = .both, .on_scroll = SessionApp.Ui.scrollMsg(.shelf_scrolled) }, ui.el(.panel, .{ .width = 600, .height = 200 }, .{})),
214
+ ui.text(.{}, ui.fmt("Shelf {d:.1},{d:.1} ({d})", .{ model.shelf_offset_x, model.shelf_offset_y, model.shelf_scrolls })),
215
+ ui.button(.{ .on_press = .increment, .on_hover_enter = .hover_enter, .on_hover_leave = .hover_leave }, "Increment"),
188
216
  });
189
217
  }
190
218
 
@@ -456,6 +484,52 @@ fn recordReferenceSession(gpa: std.mem.Allocator, buffer: *JournalBuffer, web_la
456
484
  try harness.runtime.dispatchAutomationCommand(app, pinch_command);
457
485
  try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
458
486
 
487
+ // Hover containment edges from raw journaled moves: onto the
488
+ // increment button (a hover listener), then off — replay re-derives
489
+ // the same enter/leave Msgs from the pointer events alone.
490
+ var button_frame: ?geometry.RectF = null;
491
+ for ((try harness.runtime.canvasWidgetLayout(1, canvas_label)).nodes) |node| {
492
+ if (node.widget.kind == .button) button_frame = node.frame;
493
+ }
494
+ const hover_frame = button_frame.?;
495
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
496
+ .window_id = 1,
497
+ .label = canvas_label,
498
+ .kind = .pointer_move,
499
+ .x = hover_frame.x + hover_frame.width * 0.5,
500
+ .y = hover_frame.y + hover_frame.height * 0.5,
501
+ } });
502
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
503
+ .window_id = 1,
504
+ .label = canvas_label,
505
+ .kind = .pointer_move,
506
+ .x = 2,
507
+ .y = 2,
508
+ } });
509
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
510
+ // A DIAGONAL wheel over the both-axes shelf: one recorded scroll
511
+ // input event carrying both deltas. Per-axis routing applies both
512
+ // (the shelf grants both axes), and the on_scroll observation
513
+ // mirrors the applied offsets into the model — replay must land on
514
+ // the identical pair from the raw journaled event alone.
515
+ var shelf_frame: ?geometry.RectF = null;
516
+ for ((try harness.runtime.canvasWidgetLayout(1, canvas_label)).nodes) |node| {
517
+ if (node.widget.kind == .scroll_view) shelf_frame = node.frame;
518
+ }
519
+ const shelf = shelf_frame.?;
520
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
521
+ .window_id = 1,
522
+ .label = canvas_label,
523
+ .kind = .scroll,
524
+ .x = shelf.x + shelf.width * 0.5,
525
+ .y = shelf.y + shelf.height * 0.5,
526
+ .delta_x = 30,
527
+ .delta_y = 24,
528
+ } });
529
+ try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
530
+ try std.testing.expectEqual(@as(f32, 30), app_state.model.shelf_offset_x);
531
+ try std.testing.expectEqual(@as(f32, 24), app_state.model.shelf_offset_y);
532
+
459
533
  recorder.finish();
460
534
  try std.testing.expect(!recorder.failed);
461
535
 
@@ -518,6 +592,13 @@ test "a recorded session replays to identical model state and fingerprints" {
518
592
  try std.testing.expectEqual(@as(u32, 2), recorded.model.pinch_begins);
519
593
  try std.testing.expectEqual(@as(u32, 2), recorded.model.pinch_ends);
520
594
  try std.testing.expectEqual(@as(f32, 1.40625), recorded.model.zoom);
595
+ // The hover moves dispatched exactly one containment pair.
596
+ try std.testing.expectEqual(@as(u32, 1), recorded.model.hover_enters);
597
+ try std.testing.expectEqual(@as(u32, 1), recorded.model.hover_leaves);
598
+ // The diagonal wheel reached both axes of the shelf.
599
+ try std.testing.expectEqual(@as(f32, 30), recorded.model.shelf_offset_x);
600
+ try std.testing.expectEqual(@as(f32, 24), recorded.model.shelf_offset_y);
601
+ try std.testing.expect(recorded.model.shelf_scrolls > 0);
521
602
 
522
603
  const replayed = try replayIntoFreshApp(gpa, buffer.journalBytes(), true);
523
604
  try std.testing.expect(replayed.report.ok());
@@ -2812,12 +2893,23 @@ test "a journal referencing blobs refuses to replay without its blob store" {
2812
2893
  try std.testing.expectError(error.ReplayMissingBlob, result);
2813
2894
  }
2814
2895
 
2815
- /// Zero the `image_blob_len` field — the LAST eight bytes of the effect
2816
- /// payload, see `journal.encodeEffect` — of the first journaled
2817
- /// `.loaded` image record, in place. Framing and every other field stay
2818
- /// valid, so the journal reader decodes the record fine: only replay's
2819
- /// record-consistency gate can catch the damage. Returns whether a
2820
- /// record was damaged.
2896
+ /// Bytes of the trailer at the END of every effect payload after the
2897
+ /// image fields (see `journal.encodeEffect`): the v8 channel fields —
2898
+ /// channel_kind (1), channel_dropped_total (4) — then the video
2899
+ /// fields — video_kind (1), position (8), duration (8), playing (1),
2900
+ /// buffering (1), width (8), height (8), token (8), source (1),
2901
+ /// handled (1) — then the pty fields — pty_kind (1), pty_signal (4),
2902
+ /// pty_dropped_writes (4), pty_blob_hash (16), pty_blob_len (8). The
2903
+ /// image fields the damage helpers below patch sit immediately before
2904
+ /// it.
2905
+ const effect_post_image_trailer_len: usize = 83;
2906
+
2907
+ /// Zero the `image_blob_len` field — the last eight bytes before the
2908
+ /// post-image trailer of the effect payload, see `journal.encodeEffect`
2909
+ /// — of the first journaled `.loaded` image record, in place. Framing
2910
+ /// and every other field stay valid, so the journal reader decodes the
2911
+ /// record fine: only replay's record-consistency gate can catch the
2912
+ /// damage. Returns whether a record was damaged.
2821
2913
  fn zeroFirstLoadedImageBlobLen(bytes: []u8) bool {
2822
2914
  var pos: usize = journal.preamble_len;
2823
2915
  while (bytes.len - pos >= 5) {
@@ -2828,7 +2920,8 @@ fn zeroFirstLoadedImageBlobLen(bytes: []u8) bool {
2828
2920
  if (kind != @intFromEnum(journal.RecordKind.effect)) continue;
2829
2921
  const record = journal.decodeEffect(payload) catch continue;
2830
2922
  if (record.kind != .image or record.image_outcome != .loaded or record.image_blob_len == 0) continue;
2831
- @memset(payload[payload.len - 8 ..], 0);
2923
+ const end = payload.len - effect_post_image_trailer_len;
2924
+ @memset(payload[end - 8 .. end], 0);
2832
2925
  return true;
2833
2926
  }
2834
2927
  return false;
@@ -2836,12 +2929,12 @@ fn zeroFirstLoadedImageBlobLen(bytes: []u8) bool {
2836
2929
 
2837
2930
  /// Overwrite the decoded-dimension fields of the first journaled image
2838
2931
  /// record whose outcome matches, in place — `zeroFirstLoadedImageBlobLen`'s
2839
- /// sibling. Per `journal.encodeEffect`, the effect payload ends with
2932
+ /// sibling. Per `journal.encodeEffect`, the image fields end with
2840
2933
  /// image_width (u64), image_height (u64), image_blob_hash (16 bytes),
2841
- /// image_blob_len (u64), so the dims live 40 and 32 bytes from the end.
2842
- /// Framing and every other field stay valid: only replay's
2843
- /// record-consistency gate can catch the damage. Returns whether a
2844
- /// record was damaged.
2934
+ /// image_blob_len (u64) followed by the post-image trailer, so the dims
2935
+ /// live 40 and 32 bytes from the trailer's start. Framing and every
2936
+ /// other field stay valid: only replay's record-consistency gate can
2937
+ /// catch the damage. Returns whether a record was damaged.
2845
2938
  fn patchFirstImageDims(bytes: []u8, outcome: effects_mod.EffectImageOutcome, width: u64, height: u64) bool {
2846
2939
  var pos: usize = journal.preamble_len;
2847
2940
  while (bytes.len - pos >= 5) {
@@ -2852,8 +2945,9 @@ fn patchFirstImageDims(bytes: []u8, outcome: effects_mod.EffectImageOutcome, wid
2852
2945
  if (kind != @intFromEnum(journal.RecordKind.effect)) continue;
2853
2946
  const record = journal.decodeEffect(payload) catch continue;
2854
2947
  if (record.kind != .image or record.image_outcome != outcome) continue;
2855
- std.mem.writeInt(u64, payload[payload.len - 40 ..][0..8], width, .little);
2856
- std.mem.writeInt(u64, payload[payload.len - 32 ..][0..8], height, .little);
2948
+ const end = payload.len - effect_post_image_trailer_len;
2949
+ std.mem.writeInt(u64, payload[end - 40 ..][0..8], width, .little);
2950
+ std.mem.writeInt(u64, payload[end - 32 ..][0..8], height, .little);
2857
2951
  return true;
2858
2952
  }
2859
2953
  return false;