@native-sdk/cli 0.5.0 → 0.5.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 (60) hide show
  1. package/build/app.zig +198 -13
  2. package/build/ts_run.mjs +58 -19
  3. package/build.zig +42 -0
  4. package/package.json +13 -9
  5. package/packages/core/package-lock.json +4 -3
  6. package/packages/core/package.json +3 -2
  7. package/packages/core/src/typed_ast.ts +11 -1
  8. package/skill-data/native-ui/SKILL.md +2 -2
  9. package/src/platform/types.zig +9 -0
  10. package/src/platform/windows/webview2_host.cpp +24 -0
  11. package/src/primitives/canvas/layout_audit.zig +5 -5
  12. package/src/primitives/canvas/root.zig +6 -0
  13. package/src/primitives/canvas/tokens.zig +185 -7
  14. package/src/primitives/canvas/ui.zig +27 -5
  15. package/src/primitives/canvas/ui_markup.zig +27 -4
  16. package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
  17. package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
  18. package/src/primitives/canvas/ui_markup_tests.zig +47 -0
  19. package/src/primitives/canvas/ui_markup_view.zig +10 -1
  20. package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
  21. package/src/primitives/canvas/ui_schema.zig +15 -1
  22. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  23. package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
  24. package/src/primitives/canvas/widget_layout.zig +142 -3
  25. package/src/primitives/canvas/widget_layout_tests.zig +82 -0
  26. package/src/primitives/canvas/widget_metrics.zig +16 -8
  27. package/src/primitives/canvas/widget_tree.zig +14 -2
  28. package/src/primitives/canvas/widgets.zig +12 -0
  29. package/src/runtime/automation_widget_dispatch.zig +95 -28
  30. package/src/runtime/canvas_frame.zig +15 -0
  31. package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
  32. package/src/runtime/canvas_widget_context_menu.zig +3 -2
  33. package/src/runtime/canvas_widget_events.zig +1271 -3
  34. package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
  35. package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
  36. package/src/runtime/canvas_widget_state.zig +82 -5
  37. package/src/runtime/core.zig +30 -0
  38. package/src/runtime/effects.zig +1037 -133
  39. package/src/runtime/effects_fetch_tests.zig +42 -0
  40. package/src/runtime/effects_file_tests.zig +220 -0
  41. package/src/runtime/effects_tests.zig +287 -0
  42. package/src/runtime/flow.zig +24 -1
  43. package/src/runtime/gpu_surface_events.zig +44 -5
  44. package/src/runtime/session_journal.zig +25 -13
  45. package/src/runtime/session_record.zig +166 -0
  46. package/src/runtime/session_tests.zig +453 -0
  47. package/src/runtime/ui_app.zig +137 -39
  48. package/src/runtime/ui_app_tests.zig +681 -0
  49. package/src/runtime/ui_app_window_tests.zig +182 -0
  50. package/src/runtime/view.zig +86 -0
  51. package/src/runtime/view_widget_text.zig +18 -1
  52. package/src/runtime/view_widget_tree.zig +339 -20
  53. package/src/runtime/widget_bridge.zig +26 -0
  54. package/src/runtime/window_storage.zig +61 -15
  55. package/src/runtime/window_view_runtime.zig +13 -0
  56. package/src/runtime/window_views.zig +6 -0
  57. package/src/tooling/package.zig +311 -8
  58. package/src/tooling/templates.zig +97 -9
  59. package/src/tooling/ts_core.zig +626 -13
  60. package/src/tooling/verbs.zig +88 -2
@@ -402,6 +402,188 @@ test "each window's tokens carry its own surface density, not the main canvas's"
402
402
  try std.testing.expectEqual(@as(f32, 1), main_after.pixel_snap.scale);
403
403
  }
404
404
 
405
+ // ------------------- window-control clearance in secondary windows
406
+
407
+ const CaptionWinModel = struct {
408
+ settings_open: bool = true,
409
+ /// The padded variant appends the contract spacer (the soundboard
410
+ /// pattern) so its header already clears the caption cluster.
411
+ padded: bool = false,
412
+ };
413
+
414
+ const CaptionWinMsg = union(enum) {
415
+ settings_closed,
416
+ };
417
+
418
+ const CaptionWinApp = ui_app_model.UiApp(CaptionWinModel, CaptionWinMsg);
419
+
420
+ fn captionWinUpdate(model: *CaptionWinModel, msg: CaptionWinMsg) void {
421
+ switch (msg) {
422
+ .settings_closed => model.settings_open = false,
423
+ }
424
+ }
425
+
426
+ fn captionWinView(ui: *CaptionWinApp.Ui, model: *const CaptionWinModel) CaptionWinApp.Ui.Node {
427
+ _ = model;
428
+ return ui.column(.{ .gap = 8, .padding = 12 }, .{
429
+ ui.text(.{}, "main body"),
430
+ });
431
+ }
432
+
433
+ fn captionWinWindows(model: *const CaptionWinModel, scratch: *CaptionWinApp.WindowsScratch) []const CaptionWinApp.WindowDescriptor {
434
+ var count: usize = 0;
435
+ if (model.settings_open) {
436
+ scratch.windows[count] = .{
437
+ .label = settings_window_label,
438
+ .canvas_label = settings_canvas_label,
439
+ .title = "Tools",
440
+ .width = 320,
441
+ .height = 240,
442
+ .on_close = .settings_closed,
443
+ };
444
+ count += 1;
445
+ }
446
+ return scratch.windows[0..count];
447
+ }
448
+
449
+ /// A hidden-inset SECONDARY window's titlebar: a drag row with a
450
+ /// leading title and a right-aligned status text — the same
451
+ /// system-monitor shape the main-canvas caption tests use, but built
452
+ /// through `window_view` and `rebuildWindowSlot`.
453
+ fn captionWinWindowView(ui: *CaptionWinApp.Ui, model: *const CaptionWinModel, window_label: []const u8) CaptionWinApp.Ui.Node {
454
+ std.debug.assert(std.mem.eql(u8, window_label, settings_window_label));
455
+ if (model.padded) {
456
+ return ui.column(.{}, .{
457
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
458
+ ui.text(.{}, "Tools"),
459
+ ui.el(.stack, .{ .grow = 1 }, .{}),
460
+ ui.text(.{}, "recording"),
461
+ ui.el(.stack, .{ .width = 138 }, .{}),
462
+ }),
463
+ ui.text(.{}, "body"),
464
+ });
465
+ }
466
+ return ui.column(.{}, .{
467
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
468
+ ui.text(.{}, "Tools"),
469
+ ui.el(.stack, .{ .grow = 1 }, .{}),
470
+ ui.text(.{}, "recording"),
471
+ }),
472
+ ui.text(.{}, "body"),
473
+ });
474
+ }
475
+
476
+ const CaptionWinFixture = struct {
477
+ harness: *core.TestHarness(),
478
+ app_state: *CaptionWinApp,
479
+ app: core.App,
480
+ settings_id: support.platform.WindowId,
481
+
482
+ /// Start the app with Windows-shaped hidden-titlebar chrome (the
483
+ /// DWM caption cluster overlays the trailing 138pt of the 320pt
484
+ /// secondary window's top band) and install both canvases.
485
+ fn create(padded: bool) !CaptionWinFixture {
486
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
487
+ errdefer harness.destroy(std.testing.allocator);
488
+ harness.null_platform.gpu_surfaces = true;
489
+ harness.null_platform.window_chrome = .{
490
+ .insets = .{ .top = 32, .right = 138 },
491
+ .buttons = geometry.RectF.init(182, 0, 138, 32),
492
+ };
493
+ const app_state = try CaptionWinApp.create(std.heap.page_allocator, .{
494
+ .name = "ui-app-caption-window",
495
+ .scene = panel_scene,
496
+ .canvas_label = canvas_label,
497
+ .update = captionWinUpdate,
498
+ .view = captionWinView,
499
+ .windows_fn = captionWinWindows,
500
+ .window_view = captionWinWindowView,
501
+ });
502
+ errdefer app_state.destroy();
503
+ app_state.model.padded = padded;
504
+ const app = app_state.app();
505
+ try harness.start(app);
506
+ // The model declares the settings window from the start, so the
507
+ // main canvas's installing rebuild creates it.
508
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
509
+ .label = canvas_label,
510
+ .size = geometry.SizeF.init(400, 300),
511
+ .scale_factor = 1,
512
+ .frame_index = 1,
513
+ .timestamp_ns = 1_000_000,
514
+ .nonblank = true,
515
+ } });
516
+ var buffer: [support.platform.max_windows]support.platform.WindowInfo = undefined;
517
+ var settings_id: support.platform.WindowId = 0;
518
+ for (harness.runtime.listWindows(&buffer)) |info| {
519
+ if (std.mem.eql(u8, info.label, settings_window_label)) settings_id = info.id;
520
+ }
521
+ if (settings_id == 0) return error.TestUnexpectedResult;
522
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
523
+ .window_id = settings_id,
524
+ .label = settings_canvas_label,
525
+ .size = geometry.SizeF.init(320, 240),
526
+ .scale_factor = 1,
527
+ .frame_index = 1,
528
+ .timestamp_ns = 2_000_000,
529
+ .nonblank = true,
530
+ } });
531
+ return .{ .harness = harness, .app_state = app_state, .app = app, .settings_id = settings_id };
532
+ }
533
+
534
+ fn destroy(self: CaptionWinFixture) void {
535
+ self.app_state.destroy();
536
+ self.harness.destroy(std.testing.allocator);
537
+ }
538
+
539
+ fn textFrame(self: CaptionWinFixture, window_id: support.platform.WindowId, label: []const u8, text: []const u8) !geometry.RectF {
540
+ const layout = try self.harness.runtime.canvasWidgetLayout(window_id, label);
541
+ for (layout.nodes) |node| {
542
+ if (node.widget.kind == .text and std.mem.eql(u8, node.widget.text, text)) return node.frame;
543
+ }
544
+ return error.TestUnexpectedResult;
545
+ }
546
+ };
547
+
548
+ test "a secondary window's drag header content stays clear of the Windows caption cluster" {
549
+ // The naive shape: the window view never consumed the chrome
550
+ // channel, so its right-aligned status would lay out flush to the
551
+ // window edge — UNDER the min/max/close buttons. `rebuildWindowSlot`
552
+ // must run the same collision scan + one-retry clearance the main
553
+ // rebuild runs, with the cluster stamped into the SLOT's tokens.
554
+ const fixture = try CaptionWinFixture.create(false);
555
+ defer fixture.destroy();
556
+
557
+ // The trailing status text ends at (or before) the cluster's
558
+ // leading edge (182 = 320 - 138); without the reservation it ended
559
+ // at the window's right edge, inside the cluster.
560
+ const status = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "recording");
561
+ try std.testing.expect(status.maxX() <= 182 + 0.01);
562
+ // The leading title and the body below the band are untouched.
563
+ const title = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "Tools");
564
+ try std.testing.expectEqual(@as(f32, 0), title.x);
565
+
566
+ // The stamp lived in a LOCAL copy of the slot's tokens: the main
567
+ // canvas (no drag header, no collision) keeps an unstamped stored
568
+ // set and its own layout.
569
+ const main_stored = try fixture.harness.runtime.canvasWidgetDesignTokens(1, canvas_label);
570
+ try std.testing.expect(main_stored.window_controls == null);
571
+ const main_body = try fixture.textFrame(1, canvas_label, "main body");
572
+ try std.testing.expectEqual(@as(f32, 12), main_body.x);
573
+ }
574
+
575
+ test "a padded secondary drag header keeps its layout (no double reservation)" {
576
+ // The contract shape: the header's own trailing spacer already
577
+ // clears the cluster, so nothing collides and the slot retry must
578
+ // NOT fire — a double reservation would shove the status text a
579
+ // full cluster-width further left (near 182 - 138 = 44).
580
+ const fixture = try CaptionWinFixture.create(true);
581
+ defer fixture.destroy();
582
+
583
+ const status = try fixture.textFrame(fixture.settings_id, settings_canvas_label, "recording");
584
+ try std.testing.expect(@abs(status.maxX() - 182) < 0.5);
585
+ }
586
+
405
587
  // ------------------------------------------------- window-action effects
406
588
 
407
589
  const VerbModel = struct {
@@ -425,8 +425,85 @@ pub const RuntimeView = struct {
425
425
  scroll_driver_count: usize = 0,
426
426
  canvas_widget_focused_id: canvas.ObjectId = 0,
427
427
  canvas_widget_focus_visible_id: canvas.ObjectId = 0,
428
+ /// True when `canvas_widget_focus_visible_id` was written by the
429
+ /// KEYBOARD focus contract (`setCanvasWidgetFocusFromKeyboard`) —
430
+ /// the one focus path that reveals tooltips. Every other
431
+ /// focus-visible writer stamps false: pointer focus on editables
432
+ /// (the caret contract), programmatic/automation focus, the
433
+ /// automation key escalation on plain list rows, and the rebuild
434
+ /// and dismissal focus-return seams — all of which deliberately
435
+ /// skip the reveal (Base UI's focus-visible guard against
436
+ /// click-focus opens, and the reveals-are-transition-edges rule).
437
+ /// The layout-adoption reconcile reads this to decide whether a
438
+ /// tooltip newly bound beneath the standing focus-visible owner
439
+ /// inherits the keyboard's immediate reveal or must wait for the
440
+ /// next real focus arrival.
441
+ canvas_widget_focus_visible_keyboard: bool = false,
428
442
  canvas_widget_hovered_id: canvas.ObjectId = 0,
429
443
  canvas_widget_pressed_id: canvas.ObjectId = 0,
444
+ /// Hover-intent state for ANCHORED tooltips — runtime-owned
445
+ /// presentation chrome; the model never hears hover. `armed` is
446
+ /// the tooltip whose trigger is hovered while its show delay runs;
447
+ /// `shown` is the tooltip currently painted; `warm_until` is the
448
+ /// shared warm window after a pointer-hovered tooltip hides on
449
+ /// pointer leave (reaching another
450
+ /// trigger before it passes shows that tooltip immediately, the
451
+ /// dense-toolbar polish). Every timestamp lives on the RECORDED
452
+ /// input/frame clock (`canvasRenderAnimationStartNsForView` at
453
+ /// pointer dispatch, `GpuSurfaceFrameEvent.timestamp_ns` at frame
454
+ /// advance — never a wall clock), so a recorded hover-dwell
455
+ /// session replays its tooltip show/hide frames byte-identically.
456
+ canvas_tooltip_armed_id: canvas.ObjectId = 0,
457
+ canvas_tooltip_deadline_ns: u64 = 0,
458
+ canvas_tooltip_shown_id: canvas.ObjectId = 0,
459
+ canvas_tooltip_warm_until_ns: u64 = 0,
460
+ /// The TRIGGER each intent slot was earned through (the hover
461
+ /// target that armed the delay / the widget whose hover or
462
+ /// focus-visible showed the tooltip). Ownership is a live claim,
463
+ /// not a memento: a rebuild that removes, rekeys, disables, or
464
+ /// re-parents the owner invalidates the slot in
465
+ /// `pruneCanvasTooltipIntent` — the tooltip node alone surviving
466
+ /// is not enough to keep explaining a control that no longer
467
+ /// exists.
468
+ canvas_tooltip_armed_owner_id: canvas.ObjectId = 0,
469
+ canvas_tooltip_shown_owner_id: canvas.ObjectId = 0,
470
+ /// The pointer's last position while it held the shown tooltip —
471
+ /// on the owning trigger (seeded at arm/show) or inside the shown
472
+ /// tooltip's own frame. It is the apex of the transit corridor
473
+ /// (`canvasTooltipTravelRegionContains`) a leave-move is judged
474
+ /// against, so the corridor always fans out from where the pointer
475
+ /// actually left. Meaningful only while a pointer-shown tooltip is
476
+ /// up; every value it is compared against comes from journaled
477
+ /// pointer events, so replay sees identical corridors.
478
+ canvas_tooltip_pointer_from: geometry.PointF = geometry.PointF.zero(),
479
+ /// Nonzero while the pointer has left both the trigger and the
480
+ /// shown tooltip's frame but is still inside the transit corridor
481
+ /// between them: the deadline (recorded clock) by which it must
482
+ /// arrive. Each in-corridor move re-arms it, so slow deliberate
483
+ /// transits stay open (WCAG 1.4.13 hoverable content) while a
484
+ /// pointer that parks in the gap resolves deterministically on the
485
+ /// frame clock. 0 means no transit is in flight.
486
+ canvas_tooltip_transit_deadline_ns: u64 = 0,
487
+ /// True when the shown tooltip was revealed by keyboard
488
+ /// focus-visible rather than pointer hover. Focus-shown tooltips
489
+ /// follow shadcn's Base UI-backed defaults: they open instantly on
490
+ /// focus-visible, hide on blur, ignore pointer hover leaving OTHER
491
+ /// triggers, and never open the pointer's warm window when they
492
+ /// hide (deliberate keyboard motion is not a pointer sweep).
493
+ canvas_tooltip_shown_from_focus: bool = false,
494
+ /// The pointer's last JOURNALED position over this view — every
495
+ /// phase that carries a trustworthy point (hover, move, down, up,
496
+ /// wheel) updates it; null before the first pointer event and after
497
+ /// a `.cancel` (the pointer-exit AppKit/GTK/Win32 hosts emit, and
498
+ /// gesture cancels). Point-blind scroll reconciliation (kinetic
499
+ /// steps, native drivers, keyboard scrolling) re-hit-tests this
500
+ /// position against the post-scroll tree — the pointer did not
501
+ /// move, so where it last stood is where it still is — and a null
502
+ /// here means those paths must CLOSE pointer tooltip intent rather
503
+ /// than guess (see
504
+ /// reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent).
505
+ /// Journaled input only, so replay sees identical positions.
506
+ canvas_last_pointer_position: ?geometry.PointF = null,
430
507
  /// Pointer position while the hovered widget draws hover-detail
431
508
  /// chrome (a `.chart` with hover details opted in); null everywhere
432
509
  /// else. Feeds `WidgetRenderState.hover_point`, so the display list
@@ -612,6 +689,15 @@ pub const RuntimeView = struct {
612
689
  pub const canvasWidgetDismissibleSurfaceIndexForTarget = CanvasWidgetTreeMethods.canvasWidgetDismissibleSurfaceIndexForTarget;
613
690
  pub const canvasWidgetAnchoredDismissibleChildIndex = CanvasWidgetTreeMethods.canvasWidgetAnchoredDismissibleChildIndex;
614
691
  pub const canvasWidgetOwnedMenuSurfaceIndex = CanvasWidgetTreeMethods.canvasWidgetOwnedMenuSurfaceIndex;
692
+ pub const canvasWidgetOwnedTooltipIndex = CanvasWidgetTreeMethods.canvasWidgetOwnedTooltipIndex;
693
+ pub const canvasWidgetOwnedTooltipIdForOwner = CanvasWidgetTreeMethods.canvasWidgetOwnedTooltipIdForOwner;
694
+ pub const applyCanvasTooltipVisibility = CanvasWidgetTreeMethods.applyCanvasTooltipVisibility;
695
+ pub const applyCanvasTooltipVisibilityToNodes = CanvasWidgetTreeMethods.applyCanvasTooltipVisibilityToNodes;
696
+ pub const applyCanvasTooltipVisibilityToNodesForShownId = CanvasWidgetTreeMethods.applyCanvasTooltipVisibilityToNodesForShownId;
697
+ pub const pruneCanvasTooltipIntent = CanvasWidgetTreeMethods.pruneCanvasTooltipIntent;
698
+ pub const pruneCanvasTooltipIntentForLayout = CanvasWidgetTreeMethods.pruneCanvasTooltipIntentForLayout;
699
+ pub const canvasTooltipShownIdSurvivingLayout = CanvasWidgetTreeMethods.canvasTooltipShownIdSurvivingLayout;
700
+ pub const canvasTooltipIntentArmed = CanvasWidgetTreeMethods.canvasTooltipIntentArmed;
615
701
  pub const canvasWidgetMenuSurfaceEntryId = CanvasWidgetTreeMethods.canvasWidgetMenuSurfaceEntryId;
616
702
  pub const canvasWidgetAnchorTriggerFocusId = CanvasWidgetTreeMethods.canvasWidgetAnchorTriggerFocusId;
617
703
  pub const canvasWidgetTopmostAnchoredDismissibleIndex = CanvasWidgetTreeMethods.canvasWidgetTopmostAnchoredDismissibleIndex;
@@ -63,7 +63,24 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
63
63
  return newline_edit;
64
64
  }
65
65
 
66
- if (canvasWidgetSingleLineTextKind(widget.kind) and keyboard.phase == .key_down and keyboard.text.len == 0 and !keyboard.modifiers.hasNavigationModifier()) {
66
+ // On a CLOSED combobox these same arrows are the trigger's
67
+ // OPEN keys (`widgetKeyboardControlIntent`'s menu-open
68
+ // mapping, which the app dispatch resolves BEFORE any
69
+ // stamped edit): platform convention is that opening wins
70
+ // and the caret does not move, so the derivation yields no
71
+ // edit and the retained editor agrees with the model's "no
72
+ // edit" verdict. The app-side fallback derivation for
73
+ // events that never crossed the runtime
74
+ // (`textEditEvent()`'s generic keymap) has no ArrowUp/Down
75
+ // arm at all, so both derivations stay in agreement. Once
76
+ // the picker is OPEN the focus step walks the arrows into
77
+ // the mounted menu before routing reaches the trigger; an
78
+ // arrow that still lands on an EXPANDED trigger (no
79
+ // focusable menu entry mounted) keeps the caret jump — the
80
+ // control resolver ignores it there, so both sides hear
81
+ // the same move.
82
+ const arrow_opens_combobox = widget.kind == .combobox and !(widget.state.expanded orelse false);
83
+ if (!arrow_opens_combobox and canvasWidgetSingleLineTextKind(widget.kind) and keyboard.phase == .key_down and keyboard.text.len == 0 and !keyboard.modifiers.hasNavigationModifier()) {
67
84
  if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowup")) return .{ .move_caret = .{ .direction = .start, .extend = keyboard.modifiers.shift } };
68
85
  if (std.ascii.eqlIgnoreCase(keyboard.key, "arrowdown")) return .{ .move_caret = .{ .direction = .end, .extend = keyboard.modifiers.shift } };
69
86
  }