@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
@@ -70,7 +70,7 @@ pub fn layoutWidgetDepth(
70
70
  };
71
71
  len.* += 1;
72
72
 
73
- const content = frame.inset(widget.layout.padding);
73
+ const content = windowControlsClearedContent(frame.inset(widget.layout.padding), widget, tokens);
74
74
  switch (widget.kind) {
75
75
  .row, .breadcrumb, .pagination, .radio_group, .toggle_group => try layoutAxisChildren(widget.children, content, .horizontal, index, depth, output, len, widget.layout, tokens),
76
76
  // Button groups flow like rows but at their register's effective
@@ -152,11 +152,147 @@ pub fn layoutWidgetDepth(
152
152
  // widget's resolved frame and the window (the layout root's frame).
153
153
  // Leaf trigger kinds (select, button, ...) never lay out flow
154
154
  // children, but their anchored children float all the same.
155
- try layoutAnchoredChildren(widget.children, frame, index, depth, output, len, tokens);
155
+ // A drag header's anchor base is trimmed clear of the stamped
156
+ // window-control cluster exactly like its flow content box: the
157
+ // collision scan counts anchored descendants too, so the remedy must
158
+ // move them or the one retry is paid for nothing. Non-drag widgets
159
+ // pass through untouched (menus and popovers anchor everywhere).
160
+ try layoutAnchoredChildren(widget.children, windowControlsClearedContent(frame, widget, tokens), index, depth, output, len, tokens);
156
161
 
157
162
  return index;
158
163
  }
159
164
 
165
+ /// Lay a drag header's content out clear of the OS window-control
166
+ /// cluster. On hidden-titlebar windows the content extends under the
167
+ /// system's control band, and the cluster sits ON the content at one
168
+ /// end — macOS's traffic lights lead, Windows' min/max/close cluster
169
+ /// trails. A `window_drag` widget declares "this row IS the titlebar",
170
+ /// so when the runtime has stamped the cluster's frame into the tokens
171
+ /// (`DesignTokens.window_controls` — only after a build proved content
172
+ /// actually collided; see `windowDragContentUnderWindowControls`), the
173
+ /// row's content box is trimmed on the cluster's side: trailing content
174
+ /// (a right-aligned status line) stops at the cluster's leading edge
175
+ /// instead of rendering under the buttons. Rows whose own padding (or
176
+ /// an app-authored chrome spacer) already clears the cluster never
177
+ /// reach the stamping step, so they lay out byte-identically.
178
+ fn windowControlsClearedContent(content: geometry.RectF, widget: Widget, tokens: DesignTokens) geometry.RectF {
179
+ if (!widget.window_drag) return content;
180
+ const controls = (tokens.window_controls orelse return content).normalized();
181
+ if (controls.width <= 0 or controls.height <= 0) return content;
182
+ if (geometry.RectF.intersection(content, controls).isEmpty()) return content;
183
+ var cleared = content;
184
+ if (controls.x + controls.width / 2 >= content.x + content.width / 2) {
185
+ // Trailing cluster (Windows caption buttons): the content box
186
+ // ends where the cluster begins.
187
+ cleared.width = @max(0, @min(content.maxX(), controls.x) - content.x);
188
+ } else {
189
+ // Leading cluster (macOS traffic lights): the content box
190
+ // starts past the cluster.
191
+ const start = @min(content.maxX(), @max(content.x, controls.maxX()));
192
+ cleared.width = @max(0, content.maxX() - start);
193
+ cleared.x = start;
194
+ }
195
+ return cleared;
196
+ }
197
+
198
+ /// True when a laid-out tree left CONTENT of a drag header under the
199
+ /// window-control cluster (`controls`, canvas-local): the trigger for
200
+ /// the runtime's window-control reservation. Only nodes INSIDE a
201
+ /// visible `window_drag` region count — the drag row is the declared
202
+ /// titlebar, the one place the reservation can honestly re-flow — and
203
+ /// only content-bearing leaves count: text you must read, controls you
204
+ /// must see and press. Containers and full-bleed decoration (the row's
205
+ /// own background, separators, skeletons, progress strips, cover
206
+ /// images) are EXPECTED to run under the cluster, exactly like they do
207
+ /// under macOS traffic lights, so they never trigger. Text leaves are
208
+ /// judged by their PAINTED bounds, not their frame (`tokens` carries
209
+ /// the measurement seam the layout ran with), so a grow/stretch title
210
+ /// whose glyphs sit clear never pays a retry that would visibly shift
211
+ /// it — see `windowControlContentBounds`.
212
+ pub fn windowDragContentUnderWindowControls(nodes: []const WidgetLayoutNode, controls: geometry.RectF, tokens: DesignTokens) bool {
213
+ const cluster = controls.normalized();
214
+ if (cluster.width <= 0 or cluster.height <= 0) return false;
215
+ const layout = LayoutNodesView{ .nodes = nodes };
216
+ for (nodes, 0..) |node, index| {
217
+ if (!widget_access.isWindowDragRegion(node.widget)) continue;
218
+ if (widget_tree.isWidgetHiddenInAncestors(layout, index)) continue;
219
+ for (nodes, 0..) |candidate, candidate_index| {
220
+ if (candidate_index == index) continue;
221
+ if (!widgetIsWindowControlContent(candidate.widget)) continue;
222
+ const painted = windowControlContentBounds(candidate.widget, candidate.frame.normalized(), tokens);
223
+ if (geometry.RectF.intersection(painted, cluster).isEmpty()) continue;
224
+ if (widget_tree.isWidgetHiddenInAncestors(layout, candidate_index)) continue;
225
+ if (!layoutNodeHasAncestor(nodes, candidate_index, index)) continue;
226
+ return true;
227
+ }
228
+ }
229
+ return false;
230
+ }
231
+
232
+ /// The rect the cluster test judges for one content candidate. Controls
233
+ /// (buttons, inputs, ...) are judged by their full frame — the hit
234
+ /// surface is the control, glyphs or not. Single-line text leaves are
235
+ /// judged by their ALIGNED PAINTED BOUNDS instead: the measured line
236
+ /// width (capped at the frame — elision and clipping both keep painted
237
+ /// glyphs inside it), placed per the widget's text alignment, at the
238
+ /// frame's full height. A grow/stretch title spanning the header row
239
+ /// (the centered-title pattern) has a FRAME under the cluster while its
240
+ /// inked glyphs sit well clear; judging the frame would trigger the
241
+ /// clearance retry, and the remedy's trimmed content box would then
242
+ /// visibly shift the very title it exists to protect. Span paragraphs
243
+ /// wrap and explicit newlines stack lines with per-line extents; drag
244
+ /// headers are practically single-line, so anything that can break
245
+ /// keeps the conservative frame test.
246
+ fn windowControlContentBounds(widget: Widget, frame: geometry.RectF, tokens: DesignTokens) geometry.RectF {
247
+ if (widget.kind != .text) return frame;
248
+ if (widget.spans.len > 0) return frame;
249
+ if (std.mem.indexOfScalar(u8, widget.text, '\n') != null) return frame;
250
+ const measured = measuredTextWidth(tokens, widget.text, widgetBodyTextSize(widget, tokens));
251
+ const width = @min(measured, frame.width);
252
+ const dx: f32 = switch (widget.text_alignment) {
253
+ .start => 0,
254
+ .center => (frame.width - width) * 0.5,
255
+ .end => frame.width - width,
256
+ };
257
+ return geometry.RectF.init(frame.x + dx, frame.y, width, frame.height);
258
+ }
259
+
260
+ /// Adapter so the shared ancestor-hidden walk (which reads
261
+ /// `layout.nodes`) runs over a bare node slice.
262
+ const LayoutNodesView = struct {
263
+ nodes: []const WidgetLayoutNode,
264
+ };
265
+
266
+ fn layoutNodeHasAncestor(nodes: []const WidgetLayoutNode, node_index: usize, ancestor_index: usize) bool {
267
+ var current: ?usize = nodes[node_index].parent_index;
268
+ while (current) |index| {
269
+ if (index >= nodes.len) return false;
270
+ if (index == ancestor_index) return true;
271
+ current = nodes[index].parent_index;
272
+ }
273
+ return false;
274
+ }
275
+
276
+ /// Content the window-control cluster must never cover: readable leaves
277
+ /// and interactive controls. Deliberately exhaustive so a new widget
278
+ /// kind forces the honesty call here. Containers are transparent (their
279
+ /// CHILDREN are judged, not their frames), and decorative full-bleed
280
+ /// leaves — separators, skeletons, progress strips, images (header
281
+ /// cover art composites under the OS controls on every platform) — are
282
+ /// allowed under the cluster.
283
+ fn widgetIsWindowControlContent(widget: Widget) bool {
284
+ return switch (widget.kind) {
285
+ // Layout and surface containers: judged through their children.
286
+ .stack, .row, .column, .grid, .data_grid, .table, .scroll_view, .list, .breadcrumb, .button_group, .pagination, .radio_group, .tabs, .toggle_group, .accordion, .bubble, .resizable, .alert, .card, .dialog, .drawer, .sheet, .panel, .popover, .menu_surface, .dropdown_menu, .list_item, .data_row, .split, .tree, .input_group => false,
287
+ // Full-bleed decoration: expected under the cluster.
288
+ .separator, .skeleton, .progress, .image, .split_divider => false,
289
+ // A text leaf with no bytes and no spans is a hit/semantics
290
+ // overlay, not readable content.
291
+ .text => widget.text.len > 0 or widget.spans.len > 0,
292
+ .data_cell, .icon, .avatar, .badge, .button, .toggle_button, .icon_button, .select, .input, .text_field, .search_field, .combobox, .textarea, .tooltip, .menu_item, .status_bar, .segmented_control, .checkbox, .radio, .switch_control, .toggle, .slider, .spinner, .chart => true,
293
+ };
294
+ }
295
+
160
296
  fn layoutAnchoredChildren(
161
297
  children: []const Widget,
162
298
  anchor_rect: geometry.RectF,
@@ -1545,7 +1681,10 @@ fn intrinsicGridChildrenSize(widget: Widget, tokens: DesignTokens, depth: usize)
1545
1681
  cell_height = @max(cell_height, size.height);
1546
1682
  }
1547
1683
  const columns = gridColumnCount(widget.children.len, widget.layout.columns);
1548
- const rows = (widget.children.len + columns - 1) / columns;
1684
+ // `gridRowCount`, not the additive ceil-div: declared columns are
1685
+ // engine input, and `children.len + columns` overflows in safe
1686
+ // builds when a parent intrinsically measures a maxInt-columns grid.
1687
+ const rows = gridRowCount(widget.children.len, columns);
1549
1688
  const gap = nonNegative(widget.layout.gap);
1550
1689
  return paddedIntrinsicSize(widget, geometry.SizeF.init(
1551
1690
  cell_width * @as(f32, @floatFromInt(columns)) + gap * @as(f32, @floatFromInt(columns - 1)),
@@ -935,6 +935,88 @@ test "widget grid layout places children in deterministic cells" {
935
935
  try std.testing.expectEqual(@as(usize, 8), builder.displayList().commandCount());
936
936
  }
937
937
 
938
+ test "widget grid keeps declared column slots when children run short" {
939
+ // Fewer children than the declared columns (a filtered grid): each
940
+ // child keeps the column-slot width the declared count derives —
941
+ // never stretching across the freed row — filling the leading slots
942
+ // and leaving the trailing slots empty.
943
+ const children = [_]Widget{
944
+ .{ .id = 2, .kind = .text, .text = "One" },
945
+ .{ .id = 3, .kind = .text, .text = "Two" },
946
+ };
947
+ const grid = Widget{
948
+ .id = 1,
949
+ .kind = .grid,
950
+ .layout = .{ .gap = 8, .columns = 4 },
951
+ .children = &children,
952
+ };
953
+
954
+ var nodes: [4]WidgetLayoutNode = undefined;
955
+ const layout = try layoutWidgetTree(grid, geometry.RectF.init(0, 0, 424, 40), &nodes);
956
+ try std.testing.expectEqual(@as(usize, 3), layout.nodeCount());
957
+ // Slot width = (424 - 3 gaps of 8) / 4 declared columns = 100.
958
+ try expectLayoutFrame(layout, 2, geometry.RectF.init(0, 0, 100, 40));
959
+ try expectLayoutFrame(layout, 3, geometry.RectF.init(108, 0, 100, 40));
960
+ }
961
+
962
+ test "widget grid row count survives a huge declared column count" {
963
+ const widget_tree = @import("widget_tree.zig");
964
+ // Declared columns are engine input (never validator-bounded): the
965
+ // additive ceil-div `(count + columns - 1) / columns` would overflow
966
+ // in safe builds for a huge but valid usize. A few children under
967
+ // maxInt columns is one row, not a panic.
968
+ const huge = std.math.maxInt(usize);
969
+ try std.testing.expectEqual(@as(usize, 1), widget_tree.gridRowCount(3, huge));
970
+ try std.testing.expectEqual(@as(usize, 1), widget_tree.gridRowCount(1, huge));
971
+ // Zero children (or zero columns) is zero rows in both paths.
972
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(0, huge));
973
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(0, 4));
974
+ try std.testing.expectEqual(@as(usize, 0), widget_tree.gridRowCount(5, 0));
975
+ // The ordinary shape still ceil-divides: 5 children over 2 columns
976
+ // is 3 rows.
977
+ try std.testing.expectEqual(@as(usize, 3), widget_tree.gridRowCount(5, 2));
978
+ try std.testing.expectEqual(@as(usize, 2), widget_tree.gridRowCount(4, 2));
979
+ }
980
+
981
+ test "nested widget grid with a huge declared column count measures intrinsically" {
982
+ // The root-grid case above never runs the INTRINSIC path: only a
983
+ // parent that measures its children (a column sizing an unframed
984
+ // child) reaches intrinsicGridChildrenSize, where the row math must
985
+ // be the same overflow-safe helper — the additive ceil-div panicked
986
+ // here while the placement path was already fixed.
987
+ const tiles = [_]Widget{
988
+ .{ .id = 3, .kind = .text, .text = "One" },
989
+ .{ .id = 4, .kind = .text, .text = "Two" },
990
+ .{ .id = 5, .kind = .text, .text = "Three" },
991
+ };
992
+ const grid = Widget{
993
+ .id = 2,
994
+ .kind = .grid,
995
+ .layout = .{ .gap = 8, .columns = std.math.maxInt(usize) },
996
+ .children = &tiles,
997
+ };
998
+ const column = Widget{
999
+ .id = 1,
1000
+ .kind = .column,
1001
+ .children = &[_]Widget{grid},
1002
+ };
1003
+
1004
+ // The direct measurement: three children under maxInt columns is
1005
+ // ONE row, so the grid's intrinsic height is one cell (no row gap).
1006
+ const cell = support.intrinsicWidgetSize(tiles[0], .{});
1007
+ const intrinsic = support.intrinsicWidgetSize(grid, .{});
1008
+ try std.testing.expectEqual(cell.height, intrinsic.height);
1009
+
1010
+ // And the full pass: the column measures the unframed grid child
1011
+ // intrinsically while laying out — no panic, one grid row.
1012
+ var nodes: [8]WidgetLayoutNode = undefined;
1013
+ const layout = try layoutWidgetTree(column, geometry.RectF.init(0, 0, 400, 120), &nodes);
1014
+ try std.testing.expectEqual(@as(usize, 5), layout.nodeCount());
1015
+ const first = layout.findById(3).?;
1016
+ const last = layout.findById(5).?;
1017
+ try std.testing.expectEqual(first.frame.y, last.frame.y);
1018
+ }
1019
+
938
1020
  test "widget virtualized grid lays out visible cells by row" {
939
1021
  const children = [_]Widget{
940
1022
  .{ .id = 2, .kind = .button, .text = "Zero" },
@@ -70,18 +70,26 @@ pub fn widgetLineHeight(text_size: f32) f32 {
70
70
  }
71
71
 
72
72
  /// Wrap budget for text painted inside a pixel-snapped frame. Geometry
73
- /// snapping can shave up to half a device pixel off the layout frame
74
- /// that intrinsic sizing measured with the exact same metrics — enough
75
- /// to word-wrap an exact-fit line mid-word ("Sort" painting as
76
- /// "Sor"/"t"). Hand the shaved quantum back to the wrap so snapping
77
- /// never changes line breaks; glyph origins still snap independently.
78
- /// (Elision has its own exact-fit slack — `text_elision_slack` — so
79
- /// label budgets stay byte-identical for alignment.)
73
+ /// snapping rounds each frame EDGE to the device grid independently
74
+ /// (`pixelSnapGeometryRect`), so a frame at a fractional position can
75
+ /// lose up to a FULL device pixel of width — the left edge rounds up by
76
+ /// as much as half a pixel while the right edge rounds down by as much
77
+ /// as half — off the layout frame that intrinsic sizing measured with
78
+ /// the exact same metrics. That shave is enough to word-wrap an
79
+ /// exact-fit line mid-word ("Sort" painting as "Sor"/"t") or to elide a
80
+ /// hug-sized digit into "…" (the TS scaffold's centered counter on
81
+ /// Windows at scale 1, where the shave is coarsest). Hand the whole
82
+ /// snap quantum back to the budget so snapping never changes line
83
+ /// breaks or elision; glyph origins still snap independently. Epsilon
84
+ /// policy: a run's painted width may exceed its snapped frame by less
85
+ /// than `1/scale + text_elision_slack` before eliding — always below
86
+ /// the smallest real overflow (a glyph), so genuinely overflowing text
87
+ /// still elides and any admitted overhang stays sub-pixel-scale.
80
88
  pub fn textWrapMaxWidth(tokens: DesignTokens, width: f32) f32 {
81
89
  if (!tokens.pixel_snap.geometry) return width;
82
90
  const scale = tokens.pixel_snap.scale;
83
91
  if (!std.math.isFinite(scale) or scale <= 0) return width;
84
- return width + 0.5 / scale;
92
+ return width + 1.0 / scale;
85
93
  }
86
94
 
87
95
  /// The single source of truth for how a span paragraph (`.text` widget
@@ -217,14 +217,26 @@ pub fn isWidgetConcealedByDisclosure(layout: anytype, node_index: usize) bool {
217
217
  return false;
218
218
  }
219
219
 
220
+ /// The column count a grid lays out, measures, and reports: the DECLARED
221
+ /// count when one is set — even when fewer children remain (a filtered
222
+ /// grid keeps its column-slot geometry; children fill the leading slots
223
+ /// and the trailing slots stay empty, they never stretch to fill missing
224
+ /// columns) — and one column per child when unset (the single-row grid).
220
225
  pub fn gridColumnCount(child_count: usize, requested_columns: usize) usize {
221
226
  if (child_count == 0) return 0;
222
- return if (requested_columns > 0) @min(requested_columns, child_count) else child_count;
227
+ return if (requested_columns > 0) requested_columns else child_count;
223
228
  }
224
229
 
230
+ /// The row count those columns yield: ceil-division stated as
231
+ /// `1 + (count - 1) / columns` rather than the additive
232
+ /// `(count + columns - 1) / columns` — a declared column count is
233
+ /// engine input (never validator-bounded), so `columns` may be any
234
+ /// usize, including values where the additive form's sum overflows in
235
+ /// safe builds. Both the layout and intrinsic-size paths share this
236
+ /// helper.
225
237
  pub fn gridRowCount(child_count: usize, columns: usize) usize {
226
238
  if (child_count == 0 or columns == 0) return 0;
227
- return (child_count + columns - 1) / columns;
239
+ return 1 + (child_count - 1) / columns;
228
240
  }
229
241
 
230
242
  pub fn saturatingU32(value: usize) u32 {
@@ -841,6 +841,18 @@ pub const Widget = struct {
841
841
  /// origin: mounts land at their value, exactly as before. Ignored
842
842
  /// on splits that already have a retained fraction.
843
843
  resize_origin: f32 = -1,
844
+ /// Hover-intent show delay for an ANCHORED `.tooltip` widget
845
+ /// (`tooltip_delay:` in the builder, `tooltip-delay=` in markup),
846
+ /// in milliseconds. An anchored tooltip is runtime-owned hover
847
+ /// chrome: it stays hidden until its trigger (the anchor parent's
848
+ /// subtree) has been hovered this long on the recorded frame
849
+ /// clock, shows while the hover holds, and hides when the pointer
850
+ /// leaves — the model never hears hover. 0 shows the instant the
851
+ /// trigger is hovered. Negative (the default) follows the token
852
+ /// default (`ControlMetricTokens.tooltip_show_delay_ms`). Ignored
853
+ /// on every other kind, and on tooltips without an anchor (those
854
+ /// stay static leaves that paint whenever the view renders them).
855
+ tooltip_delay_ms: i32 = -1,
844
856
  /// Window-drag surface (`window-drag="true"` / `.window_drag`): a
845
857
  /// pointer press that lands here — or falls through plain text /
846
858
  /// icons / decorations onto it — moves the WINDOW instead of
@@ -16,7 +16,6 @@ const AutomationProvenanceTarget = automation_commands.AutomationProvenanceTarge
16
16
  const AutomationWidgetWheel = automation_commands.AutomationWidgetWheel;
17
17
  const AutomationWidgetKey = automation_commands.AutomationWidgetKey;
18
18
  const AutomationWidgetPointerDrag = automation_commands.AutomationWidgetPointerDrag;
19
- const automationWidgetActionSupported = automation_commands.automationWidgetActionSupported;
20
19
  const parseAutomationTextSelection = automation_commands.parseAutomationTextSelection;
21
20
  const parseAutomationDragDelta = automation_commands.parseAutomationDragDelta;
22
21
  const parseAutomationDropPaths = automation_commands.parseAutomationDropPaths;
@@ -27,24 +26,40 @@ const validateViewLabel = validation.validateViewLabel;
27
26
 
28
27
  pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
29
28
  return struct {
29
+ /// The automation `widget_action` command surface delegates to
30
+ /// the accessibility dispatch rather than switching over the
31
+ /// verbs itself: one choke point performs the verb AND stages
32
+ /// the outer-wins `widget_accessibility_action` journal record,
33
+ /// so a recorded session replays the verb — focus included —
34
+ /// instead of replaying its untargeted synthesized children
35
+ /// against whatever focus the session happened to hold.
30
36
  pub fn dispatchAutomationWidgetAction(self: *Runtime, app: runtime_api.App(Runtime), action: AutomationWidgetAction) anyerror!void {
31
- const view_index = try automationWidgetActionViewIndex(self, action);
32
- switch (action.action) {
33
- .focus => try focusAutomationCanvasWidget(self, view_index, action.id),
34
- .press => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "enter"),
35
- .toggle => try dispatchAutomationWidgetKey(self, app, view_index, action.id, "space"),
36
- .increment => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .increment)),
37
- .decrement => try dispatchAutomationWidgetKey(self, app, view_index, action.id, self.views[view_index].canvasWidgetStepKey(action.id, .decrement)),
38
- .set_text => try setAutomationCanvasWidgetText(self, app, view_index, action.id, action.value),
39
- .set_selection => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_selection = try parseAutomationTextSelection(action.value) }),
40
- .set_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .{ .set_composition = .{ .text = action.value } }),
41
- .commit_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .commit_composition),
42
- .cancel_composition => try editAutomationCanvasWidgetText(self, view_index, action.id, .cancel_composition),
43
- .select => try selectAutomationCanvasWidget(self, view_index, action.id),
44
- .drag => try dispatchAutomationCanvasWidgetDrag(self, app, view_index, action.id, action.value),
45
- .drop_files => try dispatchAutomationCanvasWidgetFileDrop(self, app, view_index, action.id, action.value),
46
- .dismiss => try dismissAutomationCanvasWidget(self, app, view_index, action.id),
47
- }
37
+ const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
38
+ _ = try self.dispatchCanvasWidgetAccessibilityAction(app, self.views[view_index].window_id, self.views[view_index].label, .{
39
+ .id = action.id,
40
+ .action = canvasWidgetActionKindFromAutomation(action.action),
41
+ .text = action.value,
42
+ .selection = if (action.action == .set_selection) try parseAutomationTextSelection(action.value) else null,
43
+ });
44
+ }
45
+
46
+ fn canvasWidgetActionKindFromAutomation(kind: automation_commands.AutomationWidgetActionKind) runtime_api.CanvasWidgetAccessibilityActionKind {
47
+ return switch (kind) {
48
+ .focus => .focus,
49
+ .press => .press,
50
+ .toggle => .toggle,
51
+ .increment => .increment,
52
+ .decrement => .decrement,
53
+ .set_text => .set_text,
54
+ .set_selection => .set_selection,
55
+ .set_composition => .set_composition,
56
+ .commit_composition => .commit_composition,
57
+ .cancel_composition => .cancel_composition,
58
+ .select => .select,
59
+ .drag => .drag,
60
+ .drop_files => .drop_files,
61
+ .dismiss => .dismiss,
62
+ };
48
63
  }
49
64
 
50
65
  pub fn dispatchAutomationWidgetClick(self: *Runtime, app: runtime_api.App(Runtime), target: AutomationWidgetTarget) anyerror!void {
@@ -349,6 +364,17 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
349
364
  const previous_state = self.views[view_index].canvasWidgetRenderState();
350
365
  self.views[view_index].canvas_widget_focused_id = target.id;
351
366
  self.views[view_index].canvas_widget_focus_visible_id = focus_visible_id;
367
+ // Pointer-contract provenance: a programmatic ring
368
+ // (editables only) never carries the keyboard's
369
+ // standing reveal intent into a layout adoption.
370
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
371
+ // The pointer contract extends to tooltips: this move
372
+ // hides a focus-owned tooltip and reveals nothing (see
373
+ // updateCanvasTooltipIntentForProgrammaticFocusMove).
374
+ // Inside the changed-guard on purpose — re-focusing the
375
+ // widget whose focus-shown tooltip is up with the ring
376
+ // intact is not a move, and leaves it alone.
377
+ try CanvasWidgetEventMethods().updateCanvasTooltipIntentForProgrammaticFocusMove(self, view_index);
352
378
  // A focus change repaints; record the automation input so
353
379
  // the completing frame publishes (same contract as select
354
380
  // and text edits). Callers that dispatch a follow-up input
@@ -367,12 +393,18 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
367
393
  // the way a Tab-then-key would: escalate exactly this target
368
394
  // kind to the ring register before dispatching. Every other
369
395
  // kind keeps the quiet programmatic focus it always had.
396
+ // The escalation deliberately skips the tooltip machine —
397
+ // it is still programmatic focus (no reveal), and the focus
398
+ // MOVE above already hid any focus-owned tooltip.
370
399
  if (self.views[view_index].canvasWidgetNodeIndexById(id)) |node_index| {
371
400
  const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
372
401
  const plain_list_row = widget.kind == .list_item and widget.semantics.role != .treeitem;
373
402
  if (plain_list_row and self.views[view_index].canvas_widget_focus_visible_id != id) {
374
403
  const previous_state = self.views[view_index].canvasWidgetRenderState();
375
404
  self.views[view_index].canvas_widget_focus_visible_id = id;
405
+ // Still programmatic (no reveal — see the comment
406
+ // above), so no keyboard provenance either.
407
+ self.views[view_index].canvas_widget_focus_visible_keyboard = false;
376
408
  try CanvasWidgetEventMethods().invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
377
409
  }
378
410
  }
@@ -450,15 +482,57 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
450
482
  } });
451
483
  }
452
484
 
453
- pub fn editAutomationCanvasWidgetText(self: *Runtime, view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
485
+ /// Composition edits ride the SAME ime input events a real IME
486
+ /// session produces (`setAutomationCanvasWidgetText`'s
487
+ /// philosophy): the dispatch applies the edit to the retained
488
+ /// editor, stamps it onto the routed keyboard event so the app's
489
+ /// `on_input` mirror hears it, and journals the input so a
490
+ /// recorded session replays the composition byte-identically.
491
+ /// Writing the editor directly (the previous shape) kept the
492
+ /// model out of the loop — the same divergence the keyboard
493
+ /// choke point closes for Escape's clear.
494
+ pub fn composeAutomationCanvasWidgetText(
495
+ self: *Runtime,
496
+ app: runtime_api.App(Runtime),
497
+ view_index: usize,
498
+ id: canvas.ObjectId,
499
+ kind: platform.GpuSurfaceInputKind,
500
+ text: []const u8,
501
+ ) anyerror!void {
454
502
  try focusAutomationCanvasWidget(self, view_index, id);
455
503
  if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
456
- const dirty = try self.views[view_index].applyCanvasWidgetTextEdit(id, edit) orelse return;
504
+ try self.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
505
+ .window_id = self.views[view_index].window_id,
506
+ .label = self.views[view_index].label,
507
+ .kind = kind,
508
+ .timestamp_ns = automationInputTimestampNs(),
509
+ .text = text,
510
+ } });
511
+ }
512
+
513
+ /// Selection edits have no platform input kind to ride, so the
514
+ /// verb synthesizes the routed keyboard event the clipboard and
515
+ /// context-menu edits use: the keyboard choke point applies the
516
+ /// stamped edit to the retained editor and the app dispatch
517
+ /// keeps the model's selection mirror honest. (The journal sees
518
+ /// this verb as the outer `widget_accessibility_action` record
519
+ /// its dispatch stages; replaying that record re-runs the verb.)
520
+ pub fn editAutomationCanvasWidgetText(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, edit: canvas.TextInputEvent) anyerror!void {
521
+ try focusAutomationCanvasWidget(self, view_index, id);
522
+ if (!self.views[view_index].canEditCanvasWidgetText(id)) return error.InvalidCommand;
523
+ const target = self.views[view_index].widgetLayoutTree().focusTargetById(id) orelse return error.InvalidCommand;
524
+ var keyboard_event: runtime_api.CanvasWidgetKeyboardEvent = .{
525
+ .window_id = self.views[view_index].window_id,
526
+ .view_label = self.views[view_index].label,
527
+ .keyboard = .{ .phase = .key_down, .focused_id = id, .edit = edit },
528
+ .target = target,
529
+ };
457
530
  // Same observability contract as selectAutomationCanvasWidget:
458
531
  // the repaint this edit triggers must publish its completing
459
532
  // frame, so record the automation input it resolves.
460
533
  self.views[view_index].recordGpuSurfaceInputTimestamp(automationInputTimestampNs());
461
- try CanvasWidgetEventMethods().invalidateForCanvasWidgetDirty(self, view_index, dirty);
534
+ try CanvasWidgetEventMethods().updateCanvasWidgetTextFromKeyboard(self, &keyboard_event);
535
+ try self.dispatchEvent(app, .{ .canvas_widget_keyboard = keyboard_event });
462
536
  }
463
537
 
464
538
  pub fn dispatchAutomationCanvasWidgetDrag(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId, value: []const u8) anyerror!void {
@@ -520,13 +594,6 @@ pub fn RuntimeAutomationWidgetDispatch(comptime Runtime: type) type {
520
594
  } });
521
595
  }
522
596
 
523
- fn automationWidgetActionViewIndex(self: *Runtime, action: AutomationWidgetAction) anyerror!usize {
524
- const view_index = try automationGpuSurfaceViewIndexByLabel(self, action.view_label);
525
- const actions = canvasWidgetActionsForId(self, view_index, action.id) orelse return error.InvalidCommand;
526
- if (!automationWidgetActionSupported(actions, action.action)) return error.InvalidCommand;
527
- return view_index;
528
- }
529
-
530
597
  fn automationWidgetTargetViewIndex(self: *Runtime, target: AutomationWidgetTarget) anyerror!usize {
531
598
  return automationGpuSurfaceViewIndexByLabel(self, target.view_label);
532
599
  }
@@ -1134,6 +1134,21 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1134
1134
  if (self.views[index].canvasRenderAnimationsActive(frame_options.timestamp_ns)) {
1135
1135
  self.invalidateFor(.state, self.views[index].frame);
1136
1136
  }
1137
+ // An armed tooltip show delay — and a running anchor-gap
1138
+ // transit grace — only fire on a presented frame's
1139
+ // timestamp, so frames must keep coming while either is
1140
+ // pending: the render-animation pump's policy. This
1141
+ // per-frame leg takes over from the FIRST invalidation,
1142
+ // which the intent choke point kicks the moment any
1143
+ // deadline arms (reconcileCanvasTooltipIntent step 5 —
1144
+ // a deadline armed by an event that repainted nothing
1145
+ // would otherwise wait forever for a frame nothing
1146
+ // requested). Settled shown tooltips and the warm
1147
+ // window need no pump: both step on journaled input
1148
+ // timestamps.
1149
+ if (self.views[index].canvasTooltipIntentArmed()) {
1150
+ self.invalidateFor(.state, self.views[index].frame);
1151
+ }
1137
1152
  } else {
1138
1153
  self.views[index].recordCanvasFrame(canvas_frame);
1139
1154
  }