@native-sdk/cli 0.4.4 → 0.5.1

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 (94) hide show
  1. package/build/app.zig +371 -5
  2. package/build/ts_run.mjs +102 -0
  3. package/build.zig +255 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +19 -10
  6. package/packages/core/package-lock.json +44 -0
  7. package/packages/core/package.json +38 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +546 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/platform/windows/webview2_host.cpp +24 -0
  33. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  34. package/src/primitives/app_manifest/root.zig +5 -0
  35. package/src/primitives/canvas/commands.zig +14 -7
  36. package/src/primitives/canvas/layout_audit.zig +5 -5
  37. package/src/primitives/canvas/lazy_tls.zig +73 -0
  38. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  39. package/src/primitives/canvas/root.zig +11 -0
  40. package/src/primitives/canvas/tests.zig +1 -0
  41. package/src/primitives/canvas/text_atlas.zig +40 -32
  42. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  43. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  44. package/src/primitives/canvas/text_spans.zig +39 -26
  45. package/src/primitives/canvas/tokens.zig +69 -0
  46. package/src/primitives/canvas/ui.zig +125 -0
  47. package/src/primitives/canvas/ui_markup.zig +22 -3
  48. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  49. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  50. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  51. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  52. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  53. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  54. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  55. package/src/primitives/canvas/ui_schema.zig +8 -0
  56. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  57. package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
  58. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  59. package/src/primitives/canvas/widget_layout.zig +138 -2
  60. package/src/primitives/canvas/widget_metrics.zig +16 -8
  61. package/src/primitives/canvas/widget_render.zig +25 -15
  62. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  63. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  64. package/src/root.zig +7 -0
  65. package/src/runtime/canvas_frame.zig +57 -36
  66. package/src/runtime/canvas_images.zig +9 -3
  67. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  68. package/src/runtime/canvas_widget_runtime.zig +7 -4
  69. package/src/runtime/core.zig +16 -0
  70. package/src/runtime/effects.zig +1525 -133
  71. package/src/runtime/effects_fetch_tests.zig +42 -0
  72. package/src/runtime/effects_file_tests.zig +220 -0
  73. package/src/runtime/effects_host_tests.zig +594 -0
  74. package/src/runtime/effects_tests.zig +287 -0
  75. package/src/runtime/root.zig +18 -0
  76. package/src/runtime/session_replay.zig +7 -1
  77. package/src/runtime/tests.zig +2 -0
  78. package/src/runtime/ts_core_host.zig +1505 -0
  79. package/src/runtime/ts_core_host_tests.zig +1408 -0
  80. package/src/runtime/ts_ui_app.zig +469 -0
  81. package/src/runtime/ui_app.zig +189 -38
  82. package/src/runtime/ui_app_tests.zig +221 -0
  83. package/src/runtime/ui_app_window_tests.zig +182 -0
  84. package/src/runtime/view_canvas.zig +24 -17
  85. package/src/runtime/view_widget_tree.zig +2 -2
  86. package/src/tooling/codesign.zig +212 -105
  87. package/src/tooling/doctor.zig +78 -0
  88. package/src/tooling/manifest.zig +47 -0
  89. package/src/tooling/package.zig +435 -20
  90. package/src/tooling/raw_manifest.zig +15 -0
  91. package/src/tooling/root.zig +1 -0
  92. package/src/tooling/templates.zig +777 -34
  93. package/src/tooling/ts_core.zig +1099 -0
  94. package/src/tooling/verbs.zig +105 -2
@@ -390,6 +390,18 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
390
390
  /// The scaffold wires this to app.zon's `theme` field
391
391
  /// through `app_runner.manifestThemePack()`.
392
392
  theme: canvas.ThemePack = .house,
393
+ /// The app's ONE-accent brand statement over the stock
394
+ /// tokens: when set (and the app claims neither `tokens`
395
+ /// nor `tokens_fn` — apps that own their tokens own their
396
+ /// brand), the accent identity bundle
397
+ /// (`canvas.accentOverrides`: accent + derived knockout
398
+ /// ink, focus ring, slider active range) layers over the
399
+ /// resolved pack on every rebuild. High-contrast requests
400
+ /// skip it — accessibility beats brand, the same rule an
401
+ /// app-owned tokens_fn states by hand. The scaffold wires
402
+ /// this to app.zon's `theme_accent` field through
403
+ /// `app_runner.manifestThemeAccent()`.
404
+ theme_accent: ?canvas.Color = null,
393
405
  /// App font faces registered once, on the installing frame,
394
406
  /// BEFORE the first view build — so the very first layout
395
407
  /// already measures (and the first paint inks) with them.
@@ -1047,7 +1059,17 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1047
1059
  .response => try self.effects.feedResponseOutcome(record.key, record.fetch_outcome, record.status, record.payload),
1048
1060
  .file => try self.effects.feedFileResult(record.key, record.file_outcome, record.payload),
1049
1061
  .clipboard => try self.effects.feedClipboardResult(record.key, record.clipboard_outcome, record.payload),
1062
+ // `.host` records ride the route in `code` (0 ok / 1
1063
+ // err); rejections never reach here — they carry
1064
+ // `.rejected` and regenerate from the same
1065
+ // deterministic validation, like `.timer` records.
1066
+ .host => try self.effects.feedHostResult(record.key, record.code == 0, record.payload),
1050
1067
  .clock => try self.effects.pushReplayClock(record.clock_wall_ms),
1068
+ // `.env` records carry the arm name in `stderr_tail`
1069
+ // and the value in `payload`; the TS adapter's
1070
+ // envMsgs dispatch consumes the queue on the
1071
+ // replayed installing frame (zero env reads).
1072
+ .env => try self.effects.pushReplayEnv(record.stderr_tail, record.payload),
1051
1073
  // Spectrum records feed through the band-carrying
1052
1074
  // helper so replay repaints identical bars; every
1053
1075
  // other audio kind rides the plain shape.
@@ -1164,6 +1186,14 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1164
1186
  .reduce_motion = self.system_appearance.reduce_motion,
1165
1187
  .pack = self.options.theme,
1166
1188
  });
1189
+ if (self.options.theme_accent) |accent| {
1190
+ // The manifest accent layers over the resolved pack —
1191
+ // except under high contrast, where the pack's own loud
1192
+ // register wins untouched (accessibility beats brand).
1193
+ if (!self.system_appearance.high_contrast) {
1194
+ tokens = tokens.withOverrides(canvas.accentOverrides(accent));
1195
+ }
1196
+ }
1167
1197
  tokens.pixel_snap.scale = self.pixel_snap_scale;
1168
1198
  return tokens;
1169
1199
  }
@@ -1244,13 +1274,77 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1244
1274
  self.reloadMarkup(self.options.markup.?.source) catch {};
1245
1275
  }
1246
1276
  }
1247
- const tokens = runtime.tokensWithTextMeasure(self.effectiveTokens());
1277
+ var tokens = runtime.tokensWithTextMeasure(self.effectiveTokens());
1248
1278
  const next_index = self.arena_index ^ 1;
1249
1279
  // Widget layout is inset by the runtime's viewport chrome
1250
1280
  // (safe areas + keyboard on mobile, zero on desktop); the
1251
1281
  // canvas itself stays surface-sized so chrome and the clear
1252
1282
  // color still paint edge to edge under notches and bars.
1253
1283
  const bounds = geometry.RectF.fromSize(self.canvas_size).deflate(self.layoutViewportInsets(runtime, window_id));
1284
+ var built = try self.buildLayoutPass(runtime, window_id, bounds, tokens, next_index);
1285
+ // Window-control clearance is a one-retry pass like the
1286
+ // virtual-window coverage retry inside the build: only when
1287
+ // the finished layout left a drag header's CONTENT under the
1288
+ // OS window-control cluster (Windows caption buttons
1289
+ // trailing, macOS traffic lights leading) is the cluster
1290
+ // stamped into the tokens for one more build — drag rows
1291
+ // then lay their content out clear of it
1292
+ // (`canvas.windowControlsClearedContent` inside layout).
1293
+ // Apps whose headers already pad through the chrome
1294
+ // channel's insets never collide, never retry, and keep a
1295
+ // byte-identical layout.
1296
+ if (windowControlsReservation(runtime, window_id, self.options.canvas_label, built.layout, tokens)) |controls| {
1297
+ tokens.window_controls = controls;
1298
+ built = try self.buildLayoutPass(runtime, window_id, bounds, tokens, next_index);
1299
+ }
1300
+ const tree = built.tree;
1301
+ const layout = built.layout;
1302
+ launch_timing.lapOnce("first_view_built");
1303
+
1304
+ if (self.options.chrome) |chrome| {
1305
+ try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
1306
+ } else {
1307
+ _ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
1308
+ if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
1309
+ _ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
1310
+ }
1311
+ }
1312
+
1313
+ self.tree = tree;
1314
+ self.arena_index = next_index;
1315
+ // The fallback menu's target vanished from this build (the
1316
+ // model dropped the row, or its menu emptied): the open state
1317
+ // has nothing to present, so it closes.
1318
+ if (self.contextMenuFallbackTargetForLabel(self.options.canvas_label) != 0 and tree.context_menu_fallback == null) {
1319
+ self.clearContextMenuFallback();
1320
+ }
1321
+ try self.scheduleAnimations(runtime, window_id);
1322
+ try self.scheduleLayoutTweens(runtime, window_id);
1323
+ self.applyWebPanes(runtime, window_id, layout);
1324
+ self.applyStatusItem(runtime);
1325
+ self.applyWindows(runtime);
1326
+ self.applyChromeSelection();
1327
+ self.applyChromeNavigation();
1328
+ }
1329
+
1330
+ const BuiltLayout = struct {
1331
+ tree: Ui.Tree,
1332
+ layout: canvas.WidgetLayoutTree,
1333
+ };
1334
+
1335
+ /// One view-build + flex-layout pass of `rebuild`, including the
1336
+ /// windowed-virtual-list coverage retry: builds the tree into the
1337
+ /// next arena and lays it out against `bounds` with `tokens`.
1338
+ /// Extracted so rebuild can run it again with the window-control
1339
+ /// reservation stamped when the first pass proved a collision.
1340
+ fn buildLayoutPass(
1341
+ self: *Self,
1342
+ runtime: *Runtime,
1343
+ window_id: platform.WindowId,
1344
+ bounds: geometry.RectF,
1345
+ tokens: canvas.DesignTokens,
1346
+ next_index: usize,
1347
+ ) anyerror!BuiltLayout {
1254
1348
  var window_source = VirtualWindowResolver{
1255
1349
  .runtime = runtime,
1256
1350
  .window_id = window_id,
@@ -1312,32 +1406,32 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1312
1406
  if (pass >= 2 or (!corrected and !self.virtualWindowsUndercovered(layout))) break;
1313
1407
  window_source.fresh = layout;
1314
1408
  }
1315
- launch_timing.lapOnce("first_view_built");
1316
-
1317
- if (self.options.chrome) |chrome| {
1318
- try self.installChromeDisplayList(runtime, window_id, chrome, layout, tokens);
1319
- } else {
1320
- _ = try runtime.setCanvasWidgetLayout(window_id, self.options.canvas_label, layout);
1321
- if (self.installed and self.rebuildEmitsTokens(runtime, window_id, self.options.canvas_label, tokens)) {
1322
- _ = try runtime.emitCanvasWidgetDisplayList(window_id, self.options.canvas_label, tokens);
1409
+ return .{ .tree = tree, .layout = layout };
1410
+ }
1411
+
1412
+ /// The window-control cluster's canvas-local frame — but only
1413
+ /// when the just-built layout actually left drag-header content
1414
+ /// under it, so a rebuild (the main canvas's `rebuild` or a
1415
+ /// secondary window's `rebuildWindowSlot`) knows a clearance
1416
+ /// retry will change something. Cheap in the common case: a tree
1417
+ /// with no visible drag region never even polls the platform's
1418
+ /// chrome report, and standard-chrome windows report a zero
1419
+ /// cluster. `tokens` must be the tokens the layout was built
1420
+ /// with: the scan re-measures text through the same seam to
1421
+ /// judge painted bounds, not frames.
1422
+ fn windowControlsReservation(runtime: *Runtime, window_id: platform.WindowId, canvas_label: []const u8, layout: canvas.WidgetLayoutTree, tokens: canvas.DesignTokens) ?geometry.RectF {
1423
+ var has_drag_region = false;
1424
+ for (layout.nodes) |node| {
1425
+ if (canvas.widgetIsWindowDragRegion(node.widget)) {
1426
+ has_drag_region = true;
1427
+ break;
1323
1428
  }
1324
1429
  }
1325
-
1326
- self.tree = tree;
1327
- self.arena_index = next_index;
1328
- // The fallback menu's target vanished from this build (the
1329
- // model dropped the row, or its menu emptied): the open state
1330
- // has nothing to present, so it closes.
1331
- if (self.contextMenuFallbackTargetForLabel(self.options.canvas_label) != 0 and tree.context_menu_fallback == null) {
1332
- self.clearContextMenuFallback();
1333
- }
1334
- try self.scheduleAnimations(runtime, window_id);
1335
- try self.scheduleLayoutTweens(runtime, window_id);
1336
- self.applyWebPanes(runtime, window_id, layout);
1337
- self.applyStatusItem(runtime);
1338
- self.applyWindows(runtime);
1339
- self.applyChromeSelection();
1340
- self.applyChromeNavigation();
1430
+ if (!has_drag_region) return null;
1431
+ const controls = runtime.windowControlsForView(window_id, canvas_label);
1432
+ if (controls.width <= 0 or controls.height <= 0) return null;
1433
+ if (!canvas.windowDragContentUnderWindowControls(layout.nodes, controls, tokens)) return null;
1434
+ return controls;
1341
1435
  }
1342
1436
 
1343
1437
  /// Re-derive the model's selected chrome tab after a rebuild
@@ -1850,16 +1944,54 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1850
1944
  }
1851
1945
 
1852
1946
  fn rebuildWindowSlot(self: *Self, runtime: *Runtime, slot: *WindowSlot) anyerror!void {
1853
- const window_view = self.options.window_view orelse return;
1854
- const tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
1947
+ if (self.options.window_view == null) return;
1948
+ var tokens = runtime.tokensWithTextMeasure(self.slotEffectiveTokens(slot));
1855
1949
  const next_index = slot.arena_index ^ 1;
1950
+ const bounds = geometry.RectF.fromSize(slot.canvas_size).deflate(runtime.viewportInsetsForWindow(slot.window_id));
1951
+ var built = try self.buildWindowSlotPass(slot, bounds, tokens, next_index);
1952
+ // The same one-retry window-control clearance the main
1953
+ // rebuild runs (see `rebuild`): a secondary hidden-inset
1954
+ // window's drag header collides with the OS caption cluster
1955
+ // exactly like the main window's, so a proven collision
1956
+ // stamps the cluster into THIS slot's tokens (a local copy —
1957
+ // other windows keep their own layout) for one more pass.
1958
+ if (windowControlsReservation(runtime, slot.window_id, slot.canvasLabel(), built.layout, tokens)) |controls| {
1959
+ tokens.window_controls = controls;
1960
+ built = try self.buildWindowSlotPass(slot, bounds, tokens, next_index);
1961
+ }
1962
+ const tree = built.tree;
1963
+ const layout = built.layout;
1964
+ _ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
1965
+ if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
1966
+ _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
1967
+ }
1968
+ slot.tree = tree;
1969
+ slot.arena_index = next_index;
1970
+ // Same close-on-vanish rule as the main canvas rebuild.
1971
+ if (self.contextMenuFallbackTargetForLabel(slot.canvasLabel()) != 0 and tree.context_menu_fallback == null) {
1972
+ self.clearContextMenuFallback();
1973
+ }
1974
+ }
1975
+
1976
+ /// One view-build + flex-layout pass of `rebuildWindowSlot`,
1977
+ /// the slot-path sibling of `buildLayoutPass`: resets the slot's
1978
+ /// next arena (retaining capacity, so the clearance retry reuses
1979
+ /// the same pass's memory) and builds the window view against
1980
+ /// `bounds` with `tokens`.
1981
+ fn buildWindowSlotPass(
1982
+ self: *Self,
1983
+ slot: *WindowSlot,
1984
+ bounds: geometry.RectF,
1985
+ tokens: canvas.DesignTokens,
1986
+ next_index: usize,
1987
+ ) anyerror!BuiltLayout {
1988
+ const window_view = self.options.window_view.?;
1856
1989
  _ = slot.arenas[next_index].reset(.retain_capacity);
1857
1990
  var ui = Ui.init(slot.arenas[next_index].allocator());
1858
1991
  ui.context_menu_fallback_target = self.contextMenuFallbackTargetForLabel(slot.canvasLabel());
1859
1992
  self.armUiFragmentHost(&ui);
1860
1993
  const node = window_view(&ui, &self.model, slot.label());
1861
1994
  const tree = try ui.finalizeWithTokens(node, tokens);
1862
- const bounds = geometry.RectF.fromSize(slot.canvas_size).deflate(runtime.viewportInsetsForWindow(slot.window_id));
1863
1995
  const layout = canvas.layoutWidgetTreeWithTokens(tree.root, bounds, tokens, &self.layout_nodes) catch |err| {
1864
1996
  if (err == error.WidgetLayoutListFull) {
1865
1997
  ui_app_log.warn(
@@ -1869,16 +2001,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
1869
2001
  }
1870
2002
  return err;
1871
2003
  };
1872
- _ = try runtime.setCanvasWidgetLayout(slot.window_id, slot.canvasLabel(), layout);
1873
- if (slot.installed and self.rebuildEmitsTokens(runtime, slot.window_id, slot.canvasLabel(), tokens)) {
1874
- _ = try runtime.emitCanvasWidgetDisplayList(slot.window_id, slot.canvasLabel(), tokens);
1875
- }
1876
- slot.tree = tree;
1877
- slot.arena_index = next_index;
1878
- // Same close-on-vanish rule as the main canvas rebuild.
1879
- if (self.contextMenuFallbackTargetForLabel(slot.canvasLabel()) != 0 and tree.context_menu_fallback == null) {
1880
- self.clearContextMenuFallback();
1881
- }
2004
+ return .{ .tree = tree, .layout = layout };
1882
2005
  }
1883
2006
 
1884
2007
  /// Re-apply the model-derived webview panes against the freshly
@@ -2800,6 +2923,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2800
2923
  // against the new grid.
2801
2924
  self.pixel_snap_scale = scale;
2802
2925
  try self.rebuild(runtime, frame_event.window_id);
2926
+ } else if (frame_event.size.width != self.canvas_size.width or
2927
+ frame_event.size.height != self.canvas_size.height)
2928
+ {
2929
+ // The presented frame IS the drawable's honest size:
2930
+ // during a live resize the frames carry the new size
2931
+ // before the window-manager resize event lands, and
2932
+ // every dispatch-driven rebuild inside that gap (a
2933
+ // playback clock tick, a frame-channel Msg) would lay
2934
+ // out at the STALE bounds — content anchored to the old
2935
+ // bottom edge paints below (or short of) a window that
2936
+ // already shrank or grew. Adopt the size and rebuild,
2937
+ // exactly what `handleResize` does when the event
2938
+ // arrives; the resize event that follows becomes a
2939
+ // no-reflow confirmation (its rebuild lays out the same
2940
+ // bounds), and fullscreen chrome re-queries stay its
2941
+ // job.
2942
+ self.canvas_size = frame_event.size;
2943
+ try self.rebuild(runtime, frame_event.window_id);
2803
2944
  } else if (self.options.web_panes != null) {
2804
2945
  // Re-snap the webview panes each presented frame: a shell
2805
2946
  // relayout that stomped a pane frame also invalidated the
@@ -2844,6 +2985,16 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2844
2985
  // holds the stale scale (`rebuildEmitsTokens`).
2845
2986
  slot.pixel_snap_scale = scale;
2846
2987
  try self.rebuildWindowSlot(runtime, slot);
2988
+ } else if (frame_event.size.width != slot.canvas_size.width or
2989
+ frame_event.size.height != slot.canvas_size.height)
2990
+ {
2991
+ // The slot's drawable resized before its resize event
2992
+ // landed (the same live-resize gap the main canvas
2993
+ // closes above): adopt the presented size and rebuild so
2994
+ // dispatch-driven rebuilds never lay this window out at
2995
+ // stale bounds.
2996
+ slot.canvas_size = frame_event.size;
2997
+ try self.rebuildWindowSlot(runtime, slot);
2847
2998
  }
2848
2999
  try self.presentFrame(runtime, frame_event, slot.canvasLabel(), installing);
2849
3000
  }
@@ -3185,6 +3185,227 @@ test "ui app delivers chrome overlay geometry before install and on change" {
3185
3185
  try std.testing.expect(try retainedTextExists(&harness.runtime, "leading 0"));
3186
3186
  }
3187
3187
 
3188
+ // ---------------------------------- window-control clearance fixtures
3189
+
3190
+ const CaptionModel = struct {
3191
+ /// The trailing chrome reservation the CONTRACT app consumes (the
3192
+ /// soundboard pattern: a spacer sized to `insets.right`); the naive
3193
+ /// app leaves it unwired at 0, exactly like an app that never
3194
+ /// subscribed to the chrome channel.
3195
+ trailing: f32 = 0,
3196
+ };
3197
+
3198
+ const CaptionMsg = union(enum) {
3199
+ chrome: zero_platform.WindowChrome,
3200
+ };
3201
+
3202
+ const CaptionApp = ui_app_model.UiApp(CaptionModel, CaptionMsg);
3203
+
3204
+ fn captionUpdate(model: *CaptionModel, msg: CaptionMsg) void {
3205
+ switch (msg) {
3206
+ .chrome => |chrome| model.trailing = chrome.insets.right,
3207
+ }
3208
+ }
3209
+
3210
+ /// A hidden-titlebar header that never consumed the chrome channel:
3211
+ /// title leading, status text trailing — the system-monitor shape whose
3212
+ /// status line rendered UNDER the Windows caption buttons.
3213
+ fn captionNaiveView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3214
+ _ = model;
3215
+ return ui.column(.{}, .{
3216
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3217
+ ui.text(.{}, "Monitor"),
3218
+ ui.el(.stack, .{ .grow = 1 }, .{}),
3219
+ ui.text(.{}, "sampling"),
3220
+ }),
3221
+ ui.text(.{}, "body"),
3222
+ });
3223
+ }
3224
+
3225
+ /// The documented contract shape (the soundboard pattern): the header
3226
+ /// ends with a spacer sized to `insets.right`, so its own content
3227
+ /// already clears the caption cluster and the runtime reservation must
3228
+ /// stay out of the way.
3229
+ fn captionContractView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3230
+ return ui.column(.{}, .{
3231
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3232
+ ui.text(.{}, "Monitor"),
3233
+ ui.el(.stack, .{ .grow = 1 }, .{}),
3234
+ ui.text(.{}, "sampling"),
3235
+ ui.el(.stack, .{ .width = model.trailing }, .{}),
3236
+ }),
3237
+ ui.text(.{}, "body"),
3238
+ });
3239
+ }
3240
+
3241
+ /// The centered-title pattern: ONE grow text spanning the header row.
3242
+ /// Its FRAME runs under the caption cluster, but the centered glyphs
3243
+ /// sit well clear of it — nothing here needs (or may pay for) the
3244
+ /// clearance retry.
3245
+ fn captionCenteredView(ui: *CaptionApp.Ui, model: *const CaptionModel) CaptionApp.Ui.Node {
3246
+ _ = model;
3247
+ return ui.column(.{}, .{
3248
+ ui.row(.{ .window_drag = true, .height = 40 }, .{
3249
+ ui.text(.{ .grow = 1, .text_alignment = .center }, "Monitor"),
3250
+ }),
3251
+ ui.text(.{}, "body"),
3252
+ });
3253
+ }
3254
+
3255
+ fn captionChromeMap(chrome: zero_platform.WindowChrome) ?CaptionMsg {
3256
+ return .{ .chrome = chrome };
3257
+ }
3258
+
3259
+ fn captionTextFrame(runtime: *core.Runtime, text: []const u8) !geometry.RectF {
3260
+ const layout = try runtime.canvasWidgetLayout(1, canvas_label);
3261
+ for (layout.nodes) |node| {
3262
+ if (node.widget.kind == .text and std.mem.eql(u8, node.widget.text, text)) return node.frame;
3263
+ }
3264
+ return error.TestUnexpectedResult;
3265
+ }
3266
+
3267
+ test "drag header trailing content stays clear of the Windows caption cluster" {
3268
+ // Windows-shaped hidden-titlebar chrome on a 400pt window: the DWM
3269
+ // caption cluster overlays the trailing 138pt of the top band, and
3270
+ // the platform reports it through the same chrome channel macOS
3271
+ // reports the traffic lights on. The app never consumed the
3272
+ // channel, so its right-aligned header status would lay out flush
3273
+ // to the window edge — UNDER the min/max/close buttons. The runtime
3274
+ // detects the collision after layout and re-lays the drag header
3275
+ // with the cluster reserved, so the status text ends at the
3276
+ // cluster's leading edge instead.
3277
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3278
+ defer harness.destroy(std.testing.allocator);
3279
+ harness.null_platform.gpu_surfaces = true;
3280
+ harness.null_platform.window_chrome = .{
3281
+ .insets = .{ .top = 32, .right = 138 },
3282
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3283
+ };
3284
+
3285
+ const app_state = try std.testing.allocator.create(CaptionApp);
3286
+ defer std.testing.allocator.destroy(app_state);
3287
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3288
+ .name = "ui-app-caption-naive",
3289
+ .scene = counter_scene,
3290
+ .canvas_label = canvas_label,
3291
+ .update = captionUpdate,
3292
+ .view = captionNaiveView,
3293
+ });
3294
+ defer app_state.deinit();
3295
+ const app = app_state.app();
3296
+ try harness.start(app);
3297
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3298
+ .label = canvas_label,
3299
+ .size = geometry.SizeF.init(400, 300),
3300
+ .scale_factor = 1,
3301
+ .frame_index = 1,
3302
+ .timestamp_ns = 1_000_000,
3303
+ .nonblank = true,
3304
+ } });
3305
+ try std.testing.expect(app_state.installed);
3306
+
3307
+ // The trailing status text ends at (or before) the cluster's
3308
+ // leading edge; without the reservation it ended at the window's
3309
+ // right edge, inside the cluster.
3310
+ const status = try captionTextFrame(&harness.runtime, "sampling");
3311
+ try std.testing.expect(status.maxX() <= 262 + 0.01);
3312
+ // The leading title and the body below the band are untouched.
3313
+ const title = try captionTextFrame(&harness.runtime, "Monitor");
3314
+ try std.testing.expectEqual(@as(f32, 0), title.x);
3315
+ }
3316
+
3317
+ test "drag header that already pads the caption cluster keeps its layout" {
3318
+ // The contract app (the soundboard shape): its header ends with a
3319
+ // spacer consuming `insets.right`, so nothing collides and the
3320
+ // runtime reservation must NOT fire — a double reservation would
3321
+ // shove the status text a full cluster-width further left.
3322
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3323
+ defer harness.destroy(std.testing.allocator);
3324
+ harness.null_platform.gpu_surfaces = true;
3325
+ harness.null_platform.window_chrome = .{
3326
+ .insets = .{ .top = 32, .right = 138 },
3327
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3328
+ };
3329
+
3330
+ const app_state = try std.testing.allocator.create(CaptionApp);
3331
+ defer std.testing.allocator.destroy(app_state);
3332
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3333
+ .name = "ui-app-caption-contract",
3334
+ .scene = counter_scene,
3335
+ .canvas_label = canvas_label,
3336
+ .update = captionUpdate,
3337
+ .view = captionContractView,
3338
+ .on_chrome = captionChromeMap,
3339
+ });
3340
+ defer app_state.deinit();
3341
+ const app = app_state.app();
3342
+ try harness.start(app);
3343
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3344
+ .label = canvas_label,
3345
+ .size = geometry.SizeF.init(400, 300),
3346
+ .scale_factor = 1,
3347
+ .frame_index = 1,
3348
+ .timestamp_ns = 1_000_000,
3349
+ .nonblank = true,
3350
+ } });
3351
+ try std.testing.expect(app_state.installed);
3352
+ try std.testing.expectEqual(@as(f32, 138), app_state.model.trailing);
3353
+
3354
+ // The app's own spacer puts the status text at the cluster's edge;
3355
+ // the runtime must not reserve on top of it (a double reservation
3356
+ // would land it near 262 - 138 = 124).
3357
+ const status = try captionTextFrame(&harness.runtime, "sampling");
3358
+ try std.testing.expect(@abs(status.maxX() - 262) < 0.5);
3359
+ }
3360
+
3361
+ test "drag header centered title never pays the clearance retry" {
3362
+ // The false positive the painted-bounds scan removes: a grow text
3363
+ // spanning the header row with centered glyphs. Its FRAME runs
3364
+ // under the caption cluster, but nothing inked does — a frame-based
3365
+ // scan paid the one retry here, and the remedy's trimmed content
3366
+ // box then visibly shifted the centered title left. The scan judges
3367
+ // aligned painted bounds, so no retry fires and the layout is
3368
+ // byte-identical to an unstamped build: the title's grow frame
3369
+ // still spans the full row, cluster and all.
3370
+ const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
3371
+ defer harness.destroy(std.testing.allocator);
3372
+ harness.null_platform.gpu_surfaces = true;
3373
+ harness.null_platform.window_chrome = .{
3374
+ .insets = .{ .top = 32, .right = 138 },
3375
+ .buttons = geometry.RectF.init(262, 0, 138, 32),
3376
+ };
3377
+
3378
+ const app_state = try std.testing.allocator.create(CaptionApp);
3379
+ defer std.testing.allocator.destroy(app_state);
3380
+ app_state.* = CaptionApp.init(std.heap.page_allocator, .{}, .{
3381
+ .name = "ui-app-caption-centered",
3382
+ .scene = counter_scene,
3383
+ .canvas_label = canvas_label,
3384
+ .update = captionUpdate,
3385
+ .view = captionCenteredView,
3386
+ });
3387
+ defer app_state.deinit();
3388
+ const app = app_state.app();
3389
+ try harness.start(app);
3390
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
3391
+ .label = canvas_label,
3392
+ .size = geometry.SizeF.init(400, 300),
3393
+ .scale_factor = 1,
3394
+ .frame_index = 1,
3395
+ .timestamp_ns = 1_000_000,
3396
+ .nonblank = true,
3397
+ } });
3398
+ try std.testing.expect(app_state.installed);
3399
+
3400
+ // No reservation fired: the title's frame still spans the whole
3401
+ // row. A paid retry would have trimmed the drag row's content box
3402
+ // at the cluster's leading edge (262) and re-centered the glyphs
3403
+ // inside the trimmed frame — the visible title shift.
3404
+ const title = try captionTextFrame(&harness.runtime, "Monitor");
3405
+ try std.testing.expectEqual(@as(f32, 0), title.x);
3406
+ try std.testing.expectEqual(@as(f32, 400), title.maxX());
3407
+ }
3408
+
3188
3409
  // -------------------------------------- windowed virtual list fixture
3189
3410
 
3190
3411
  const VirtualFeedModel = struct {