@native-sdk/cli 0.7.0 → 0.7.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 (81) hide show
  1. package/build/app.zig +8 -0
  2. package/build.zig +114 -103
  3. package/native-sdk.d.ts +6 -3
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/text.ts +25 -14
  8. package/packages/core/src/checker.ts +39 -0
  9. package/packages/core/src/emitter.ts +125 -1
  10. package/skill-data/native-ui/SKILL.md +11 -7
  11. package/src/platform/macos/appkit_host.m +76 -4
  12. package/src/platform/macos/cef_host.mm +24 -2
  13. package/src/platform/macos/root.zig +13 -0
  14. package/src/platform/types.zig +4 -0
  15. package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
  16. package/src/platform/windows/gpu_surface_renderer.h +86 -0
  17. package/src/platform/windows/root.zig +298 -20
  18. package/src/platform/windows/webview2_host.cpp +343 -33
  19. package/src/primitives/canvas/code.zig +501 -33
  20. package/src/primitives/canvas/code_tests.zig +1029 -6
  21. package/src/primitives/canvas/events.zig +111 -1
  22. package/src/primitives/canvas/frame.zig +45 -1
  23. package/src/primitives/canvas/gpu.zig +6 -0
  24. package/src/primitives/canvas/markdown_tests.zig +17 -18
  25. package/src/primitives/canvas/render_tests.zig +93 -0
  26. package/src/primitives/canvas/root.zig +6 -0
  27. package/src/primitives/canvas/serialization.zig +150 -21
  28. package/src/primitives/canvas/text.zig +6 -0
  29. package/src/primitives/canvas/themes/geist.zig +51 -5
  30. package/src/primitives/canvas/tokens.zig +33 -4
  31. package/src/primitives/canvas/ui.zig +160 -36
  32. package/src/primitives/canvas/ui_markup.zig +60 -9
  33. package/src/primitives/canvas/ui_markup_compiled.zig +41 -0
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +12 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +17 -1
  36. package/src/primitives/canvas/ui_markup_view.zig +44 -0
  37. package/src/primitives/canvas/ui_markup_view_tests.zig +80 -6
  38. package/src/primitives/canvas/ui_schema.zig +18 -0
  39. package/src/primitives/canvas/ui_schema_tests.zig +10 -7
  40. package/src/primitives/canvas/ui_tests.zig +40 -0
  41. package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
  42. package/src/primitives/canvas/widget_invalidation.zig +12 -1
  43. package/src/primitives/canvas/widget_layout.zig +260 -21
  44. package/src/primitives/canvas/widget_metrics.zig +47 -6
  45. package/src/primitives/canvas/widget_render.zig +849 -78
  46. package/src/primitives/canvas/widget_render_controls.zig +83 -25
  47. package/src/primitives/canvas/widget_render_style.zig +52 -8
  48. package/src/primitives/canvas/widget_runtime.zig +2 -0
  49. package/src/primitives/canvas/widget_text_input.zig +167 -8
  50. package/src/primitives/canvas/widget_tree.zig +6 -5
  51. package/src/primitives/canvas/widgets.zig +78 -2
  52. package/src/runtime/canvas_budget_edge_tests.zig +3 -2
  53. package/src/runtime/canvas_frame.zig +60 -7
  54. package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
  55. package/src/runtime/canvas_frame_packet_tests.zig +83 -9
  56. package/src/runtime/canvas_frame_patch_tests.zig +16 -0
  57. package/src/runtime/canvas_images.zig +8 -2
  58. package/src/runtime/canvas_limits.zig +13 -6
  59. package/src/runtime/canvas_widget_clipboard_tests.zig +8 -5
  60. package/src/runtime/canvas_widget_context_menu.zig +7 -2
  61. package/src/runtime/canvas_widget_event_tests.zig +18 -14
  62. package/src/runtime/canvas_widget_events.zig +51 -20
  63. package/src/runtime/canvas_widget_runtime.zig +108 -4
  64. package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
  65. package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
  66. package/src/runtime/canvas_widget_state.zig +27 -0
  67. package/src/runtime/canvas_widget_text_tests.zig +326 -0
  68. package/src/runtime/core.zig +15 -5
  69. package/src/runtime/effects.zig +6 -0
  70. package/src/runtime/effects_tests.zig +30 -0
  71. package/src/runtime/gpu_surface_events.zig +50 -19
  72. package/src/runtime/media_surface_tests.zig +1 -1
  73. package/src/runtime/runtime_event_tests.zig +74 -0
  74. package/src/runtime/ui_app.zig +10 -8
  75. package/src/runtime/ui_app_tests.zig +67 -0
  76. package/src/runtime/view.zig +60 -16
  77. package/src/runtime/view_canvas.zig +15 -0
  78. package/src/runtime/view_widget_scroll.zig +48 -18
  79. package/src/runtime/view_widget_text.zig +59 -16
  80. package/src/runtime/window_view_runtime.zig +10 -0
  81. package/src/tooling/templates.zig +9 -6
@@ -78,6 +78,52 @@ test "the builder's presented-text store mirrors the per-view draw-text budget"
78
78
  );
79
79
  }
80
80
 
81
+ test "closing an earlier view transfers a later view's expanded text storage" {
82
+ const TestApp = struct {
83
+ fn app(self: *@This()) App {
84
+ return .{ .context = self, .name = "gpu-widget-expanded-storage-compaction", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
85
+ }
86
+ };
87
+
88
+ const harness = try TestHarness().create(std.testing.allocator, .{});
89
+ defer harness.destroy(std.testing.allocator);
90
+ harness.null_platform.gpu_surfaces = true;
91
+ var app_state: TestApp = .{};
92
+ try harness.start(app_state.app());
93
+
94
+ for ([_][]const u8{ "canvas-a", "canvas-b" }) |label| {
95
+ _ = try harness.runtime.createView(.{
96
+ .window_id = 1,
97
+ .label = label,
98
+ .kind = .gpu_surface,
99
+ .frame = geometry.RectF.init(0, 0, 240, 160),
100
+ });
101
+ }
102
+ const ordinary = canvas.Widget{ .id = 2, .kind = .text, .text = "ordinary" };
103
+ var ordinary_nodes: [1]canvas.WidgetLayoutNode = undefined;
104
+ const ordinary_layout = try canvas.layoutWidgetTree(ordinary, geometry.RectF.init(0, 0, 240, 160), &ordinary_nodes);
105
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas-a", ordinary_layout);
106
+
107
+ const editor = canvas.Widget{
108
+ .id = 3,
109
+ .kind = .textarea,
110
+ .text = "expanded",
111
+ .text_no_wrap = true,
112
+ .code_editor = true,
113
+ };
114
+ var editor_nodes: [1]canvas.WidgetLayoutNode = undefined;
115
+ const editor_layout = try canvas.layoutWidgetTree(editor, geometry.RectF.init(0, 0, 240, 160), &editor_nodes);
116
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas-b", editor_layout);
117
+ try std.testing.expect(harness.runtime.views[0].widget_text_bytes_heap_owned);
118
+ try std.testing.expect(harness.runtime.views[1].widget_text_bytes_heap_owned);
119
+
120
+ try harness.runtime.closeView(1, "canvas-a");
121
+ try std.testing.expectEqual(@as(usize, 1), harness.runtime.view_count);
122
+ try std.testing.expectEqualStrings("canvas-b", harness.runtime.views[0].label);
123
+ try std.testing.expect(harness.runtime.views[0].widget_text_bytes_heap_owned);
124
+ try std.testing.expectEqualStrings("expanded", harness.runtime.views[0].widgetLayoutTree().nodes[0].widget.text);
125
+ }
126
+
81
127
  test "runtime exposes retained canvas widget text geometry" {
82
128
  const TestApp = struct {
83
129
  fn app(self: *@This()) App {
@@ -3801,6 +3847,123 @@ test "maximal numbered code fits the retained text budget" {
3801
3847
  try std.testing.expect(found_source);
3802
3848
  }
3803
3849
 
3850
+ test "editable code owns plain Tab and stamps its inferred indentation edit" {
3851
+ const TestApp = struct {
3852
+ edit_count: usize = 0,
3853
+ insertion: [8]u8 = @splat(0),
3854
+ insertion_len: usize = 0,
3855
+
3856
+ fn app(self: *@This()) App {
3857
+ return .{
3858
+ .context = self,
3859
+ .name = "gpu-widget-code-tab",
3860
+ .source = platform.WebViewSource.html("<h1>Hello</h1>"),
3861
+ .event_fn = event,
3862
+ };
3863
+ }
3864
+
3865
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
3866
+ _ = runtime;
3867
+ const self: *@This() = @ptrCast(@alignCast(context));
3868
+ switch (event_value) {
3869
+ .canvas_widget_keyboard => |keyboard_event| {
3870
+ const edit = keyboard_event.keyboard.edit orelse return;
3871
+ switch (edit) {
3872
+ .insert_text => |text| {
3873
+ self.edit_count += 1;
3874
+ self.insertion_len = @min(text.len, self.insertion.len);
3875
+ @memcpy(self.insertion[0..self.insertion_len], text[0..self.insertion_len]);
3876
+ },
3877
+ else => {},
3878
+ }
3879
+ },
3880
+ else => {},
3881
+ }
3882
+ }
3883
+ };
3884
+
3885
+ const harness = try TestHarness().create(std.testing.allocator, .{});
3886
+ defer harness.destroy(std.testing.allocator);
3887
+ harness.null_platform.gpu_surfaces = true;
3888
+ var app_state: TestApp = .{};
3889
+ const app = app_state.app();
3890
+ try harness.start(app);
3891
+ _ = try harness.runtime.createView(.{
3892
+ .window_id = 1,
3893
+ .label = "canvas",
3894
+ .kind = .gpu_surface,
3895
+ .frame = geometry.RectF.init(0, 0, 320, 180),
3896
+ });
3897
+
3898
+ const source = "if (ready) {\n run();\n}\n";
3899
+ const children = [_]canvas.Widget{
3900
+ .{
3901
+ .id = 3,
3902
+ .kind = .button,
3903
+ .frame = geometry.RectF.init(240, 16, 68, 32),
3904
+ .text = "Run",
3905
+ },
3906
+ .{
3907
+ .id = 2,
3908
+ .kind = .textarea,
3909
+ .code_editor = true,
3910
+ .text_no_wrap = true,
3911
+ .frame = geometry.RectF.init(12, 16, 220, 100),
3912
+ .text = source,
3913
+ .text_selection = canvas.TextSelection.collapsed(source.len),
3914
+ },
3915
+ };
3916
+ var nodes: [3]canvas.WidgetLayoutNode = undefined;
3917
+ const layout = try canvas.layoutWidgetTree(
3918
+ .{ .id = 1, .kind = .stack, .children = &children },
3919
+ geometry.RectF.init(0, 0, 320, 180),
3920
+ &nodes,
3921
+ );
3922
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
3923
+
3924
+ // Tab from the preceding button enters the editor as focus
3925
+ // traversal and must not indent on that same physical gesture.
3926
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3927
+ .window_id = 1,
3928
+ .label = "canvas",
3929
+ .kind = .pointer_down,
3930
+ .x = 260,
3931
+ .y = 28,
3932
+ } });
3933
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3934
+ .window_id = 1,
3935
+ .label = "canvas",
3936
+ .kind = .key_down,
3937
+ .key = "tab",
3938
+ } });
3939
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
3940
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
3941
+ try std.testing.expectEqualStrings(source, retained.nodes[2].widget.text);
3942
+ try std.testing.expectEqual(@as(usize, 0), app_state.edit_count);
3943
+ try std.testing.expect(harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
3944
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3945
+ .window_id = 1,
3946
+ .label = "canvas",
3947
+ .kind = .key_up,
3948
+ .key = "tab",
3949
+ } });
3950
+ try std.testing.expect(!harness.runtime.views[0].canvas_widget_tab_input_focus_entry_held);
3951
+
3952
+ // Once focused, plain Tab is an ordinary stamped edit. Four-space
3953
+ // indentation wins from the source's existing leading whitespace.
3954
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
3955
+ .window_id = 1,
3956
+ .label = "canvas",
3957
+ .kind = .key_down,
3958
+ .key = "tab",
3959
+ } });
3960
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
3961
+ try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
3962
+ try std.testing.expectEqualStrings("if (ready) {\n run();\n}\n ", retained.nodes[2].widget.text);
3963
+ try std.testing.expectEqual(@as(usize, 1), app_state.edit_count);
3964
+ try std.testing.expectEqualStrings(" ", app_state.insertion[0..app_state.insertion_len]);
3965
+ }
3966
+
3804
3967
  /// Scan the widget's frame for a pointer location whose caret offset is
3805
3968
  /// exactly `target`, so multi-click tests aim at text offsets without
3806
3969
  /// hard-coding font metrics.
@@ -3833,6 +3996,93 @@ fn retainedTextSelection(harness: *TestHarness(), node_index: usize) !canvas.Tex
3833
3996
  return retained.nodes[node_index].widget.text_selection orelse error.TestExpectedSelection;
3834
3997
  }
3835
3998
 
3999
+ test "multi-click chains stay on one target and one physical pointer" {
4000
+ const TestApp = struct {
4001
+ fn app(self: *@This()) App {
4002
+ return .{ .context = self, .name = "gpu-widget-click-chain-identity", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
4003
+ }
4004
+ };
4005
+
4006
+ const harness = try TestHarness().create(std.testing.allocator, .{});
4007
+ defer harness.destroy(std.testing.allocator);
4008
+ harness.null_platform.gpu_surfaces = true;
4009
+ var app_state: TestApp = .{};
4010
+ const app = app_state.app();
4011
+ try harness.start(app);
4012
+
4013
+ _ = try harness.runtime.createView(.{
4014
+ .window_id = 1,
4015
+ .label = "canvas",
4016
+ .kind = .gpu_surface,
4017
+ .frame = geometry.RectF.init(0, 0, 320, 200),
4018
+ });
4019
+ const nodes = [_]canvas.WidgetLayoutNode{
4020
+ .{
4021
+ .widget = .{ .id = 2, .kind = .button, .text = "First" },
4022
+ .frame = geometry.RectF.init(0, 0, 20, 24),
4023
+ .depth = 0,
4024
+ },
4025
+ .{
4026
+ .widget = .{ .id = 3, .kind = .button, .text = "Second" },
4027
+ .frame = geometry.RectF.init(20, 0, 20, 24),
4028
+ .depth = 0,
4029
+ },
4030
+ };
4031
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", .{ .nodes = &nodes });
4032
+
4033
+ const ms = std.time.ns_per_ms;
4034
+ const clicks = [_]struct { kind: platform.GpuSurfaceInputKind, timestamp_ns: u64, x: f32, pointer_id: u64 }{
4035
+ .{ .kind = .pointer_down, .timestamp_ns = 1_000 * ms, .x = 19, .pointer_id = 11 },
4036
+ .{ .kind = .pointer_up, .timestamp_ns = 1_030 * ms, .x = 19, .pointer_id = 11 },
4037
+ .{ .kind = .pointer_down, .timestamp_ns = 1_100 * ms, .x = 21, .pointer_id = 11 },
4038
+ };
4039
+ for (clicks) |click| {
4040
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4041
+ .window_id = 1,
4042
+ .label = "canvas",
4043
+ .kind = click.kind,
4044
+ .timestamp_ns = click.timestamp_ns,
4045
+ .pointer_id = click.pointer_id,
4046
+ .x = click.x,
4047
+ .y = 12,
4048
+ } });
4049
+ }
4050
+ try std.testing.expectEqual(@as(u8, 1), harness.runtime.views[0].canvas_widget_click_count);
4051
+ try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_click_target_id);
4052
+
4053
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4054
+ .window_id = 1,
4055
+ .label = "canvas",
4056
+ .kind = .pointer_up,
4057
+ .timestamp_ns = 1_130 * ms,
4058
+ .pointer_id = 11,
4059
+ .x = 21,
4060
+ .y = 12,
4061
+ } });
4062
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4063
+ .window_id = 1,
4064
+ .label = "canvas",
4065
+ .kind = .pointer_down,
4066
+ .timestamp_ns = 1_200 * ms,
4067
+ .pointer_id = 11,
4068
+ .x = 22,
4069
+ .y = 12,
4070
+ } });
4071
+ try std.testing.expectEqual(@as(u8, 2), harness.runtime.views[0].canvas_widget_click_count);
4072
+
4073
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4074
+ .window_id = 1,
4075
+ .label = "canvas",
4076
+ .kind = .pointer_down,
4077
+ .timestamp_ns = 1_300 * ms,
4078
+ .pointer_id = 12,
4079
+ .x = 22,
4080
+ .y = 12,
4081
+ } });
4082
+ try std.testing.expectEqual(@as(u8, 1), harness.runtime.views[0].canvas_widget_click_count);
4083
+ try std.testing.expectEqual(@as(u64, 12), harness.runtime.views[0].canvas_widget_click_pointer_id);
4084
+ }
4085
+
3836
4086
  test "Shift-click extends a textarea selection from the placed caret" {
3837
4087
  const TestApp = struct {
3838
4088
  fn app(self: *@This()) App {
@@ -4345,3 +4595,79 @@ test "runtime scrolls single-line fields horizontally to keep the caret visible"
4345
4595
  try std.testing.expectEqualStrings("short", retained.nodes[1].widget.text);
4346
4596
  try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value);
4347
4597
  }
4598
+
4599
+ test "runtime scrolls editable no-wrap code horizontally and retains both axes" {
4600
+ const TestApp = struct {
4601
+ fn app(self: *@This()) App {
4602
+ return .{ .context = self, .name = "gpu-widget-code-editor-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
4603
+ }
4604
+ };
4605
+
4606
+ const harness = try TestHarness().create(std.testing.allocator, .{});
4607
+ defer harness.destroy(std.testing.allocator);
4608
+ harness.null_platform.gpu_surfaces = true;
4609
+ var app_state: TestApp = .{};
4610
+ const app = app_state.app();
4611
+ try harness.start(app);
4612
+
4613
+ _ = try harness.runtime.createView(.{
4614
+ .window_id = 1,
4615
+ .label = "canvas",
4616
+ .kind = .gpu_surface,
4617
+ .frame = geometry.RectF.init(0, 0, 260, 160),
4618
+ });
4619
+
4620
+ const editor = canvas.Widget{
4621
+ .id = 2,
4622
+ .kind = .textarea,
4623
+ .code_editor = true,
4624
+ .code_line_number_digits = 2,
4625
+ .text_no_wrap = true,
4626
+ .frame = geometry.RectF.init(12, 16, 120, 72),
4627
+ .semantics = .{ .label = "Source" },
4628
+ };
4629
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
4630
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{editor} }, geometry.RectF.init(0, 0, 260, 160), &nodes);
4631
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
4632
+
4633
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
4634
+ .window_id = 1,
4635
+ .label = "canvas",
4636
+ .kind = .pointer_down,
4637
+ .x = 20,
4638
+ .y = 30,
4639
+ } });
4640
+
4641
+ // The pinned line-number gutter is outside the source viewport and must
4642
+ // not manufacture a horizontal range of its own.
4643
+ try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 2 0 40");
4644
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4645
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value_x);
4646
+
4647
+ _ = try harness.runtime.editCanvasWidgetText(
4648
+ 1,
4649
+ "canvas",
4650
+ 2,
4651
+ .{ .insert_text = "const deliberately_long_identifier = another_deliberately_long_identifier;" },
4652
+ );
4653
+
4654
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4655
+ try std.testing.expect(retained.nodes[1].widget.value_x > 0);
4656
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value);
4657
+ const viewport = canvas.textInputViewportForWidget(retained.nodes[1].widget, .{}).?;
4658
+ const geometry_value = try harness.runtime.canvasWidgetTextGeometry(1, "canvas", 2);
4659
+ const caret = geometry_value.caret_bounds.?;
4660
+ try std.testing.expect(caret.x >= viewport.x - 0.001);
4661
+ try std.testing.expect(caret.maxX() <= viewport.maxX() + 0.001);
4662
+
4663
+ var rebuild_nodes: [2]canvas.WidgetLayoutNode = undefined;
4664
+ const rebuild = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{editor} }, geometry.RectF.init(0, 0, 260, 160), &rebuild_nodes);
4665
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", rebuild);
4666
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4667
+ try std.testing.expect(retained.nodes[1].widget.value_x > 0);
4668
+
4669
+ _ = try harness.runtime.editCanvasWidgetText(1, "canvas", 2, .{ .move_caret = .{ .direction = .start } });
4670
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
4671
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), retained.nodes[1].widget.text_selection.?);
4672
+ try std.testing.expectEqual(@as(f32, 0), retained.nodes[1].widget.value_x);
4673
+ }
@@ -183,7 +183,8 @@ pub const Runtime = struct {
183
183
  options: Options,
184
184
  /// The allocator that owns every runtime-lifetime heap allocation
185
185
  /// (registered canvas font bytes, registered canvas image slot
186
- /// buffers, adopted media-surface texture buffers). Captured from
186
+ /// buffers, adopted media-surface texture buffers, and expanded live-view
187
+ /// text/history pools). Captured from
187
188
  /// `Options.allocator` at init precisely
188
189
  /// because `options` is public and mutable: allocation and free of
189
190
  /// owned storage can be a whole runtime lifetime apart, and they
@@ -517,10 +518,10 @@ pub const Runtime = struct {
517
518
  canvas.bumpTextMeasureGeneration();
518
519
  }
519
520
 
520
- /// Release the runtime's heap-owned on-demand storage (registered
521
- /// canvas font bytes, registered canvas image slot buffers, and
522
- /// adopted media-surface texture buffers, allocated from the
523
- /// init-frozen `owned_allocator`), return each registered font's
521
+ /// Release the runtime's heap-owned on-demand storage (expanded live-view
522
+ /// text/history pools, registered canvas font bytes, registered canvas
523
+ /// image slot buffers, and adopted media-surface texture buffers,
524
+ /// allocated from the init-frozen `owned_allocator`), return each registered font's
524
525
  /// host-side registration (through the unregister owner captured
525
526
  /// into the entry at registration time — host font state is
526
527
  /// per-process, this runtime's ids are not, and live `options` may
@@ -537,6 +538,15 @@ pub const Runtime = struct {
537
538
  /// host) call it to return the storage.
538
539
  pub fn deinit(self: *Runtime) void {
539
540
  self.disarmMediaSurfaceWakes();
541
+ for (self.views[0..self.view_count]) |*view| {
542
+ if (view.widget_text_bytes_heap_owned) self.owned_allocator.free(view.widget_text_bytes);
543
+ if (view.canvas_widget_text_history_bytes_heap_owned) self.owned_allocator.free(view.canvas_widget_text_history_bytes);
544
+ view.widget_text_bytes = &.{};
545
+ view.widget_text_bytes_heap_owned = false;
546
+ view.canvas_widget_text_history_bytes = &.{};
547
+ view.canvas_widget_text_history_bytes_heap_owned = false;
548
+ }
549
+ self.view_count = 0;
540
550
  if (self.targetless_ime_preedit.len > 0) {
541
551
  self.owned_allocator.free(self.targetless_ime_preedit);
542
552
  self.targetless_ime_preedit = &.{};
@@ -12556,6 +12556,12 @@ pub fn Effects(comptime Msg: type) type {
12556
12556
  .stdin = if (ctx.stdin_len > 0) .pipe else .ignore,
12557
12557
  .stdout = .pipe,
12558
12558
  .stderr = if (ctx.output_mode == .collect) .pipe else .ignore,
12559
+ // A job spawn is a background transport, not a terminal:
12560
+ // release-shaped Windows hosts are GUI-subsystem processes,
12561
+ // so starting a console-subsystem helper without this flag
12562
+ // would allocate a visible console behind the app. Interactive
12563
+ // children belong to ptySpawn's separate ConPTY path.
12564
+ .create_no_window = builtin.os.tag == .windows,
12559
12565
  // POSIX: land the child in its OWN process group (id ==
12560
12566
  // its pid, set before exec) so `killPublishedChild` can
12561
12567
  // signal the whole descendant tree. Killing only the
@@ -805,6 +805,36 @@ fn sawLine(model: *const StreamModel) bool {
805
805
  return model.line_count > 0;
806
806
  }
807
807
 
808
+ test "Windows background spawns run without an attached console" {
809
+ if (builtin.os.tag != .windows) return error.SkipZigTest;
810
+ var h = try Harness.create();
811
+ defer h.destroy();
812
+
813
+ // Ask the spawned process itself, rather than inferring from window
814
+ // enumeration: a GUI-subsystem host used to omit CREATE_NO_WINDOW, so a
815
+ // console-subsystem helper received a console even though Effects.spawn
816
+ // exposes only pipes. PowerShell's redirected stdout still works with no
817
+ // console and carries the direct GetConsoleWindow verdict back to us.
818
+ test_argv = &.{
819
+ "powershell.exe",
820
+ "-NoLogo",
821
+ "-NoProfile",
822
+ "-NonInteractive",
823
+ "-Command",
824
+ "Add-Type -Namespace NativeSdk -Name ConsoleProbe -MemberDefinition '[System.Runtime.InteropServices.DllImport(\"kernel32.dll\")] public static extern System.IntPtr GetConsoleWindow();'; if ([NativeSdk.ConsoleProbe]::GetConsoleWindow() -eq [IntPtr]::Zero) { 'detached' } else { 'attached' }",
825
+ };
826
+ test_stdin = null;
827
+ try h.app_state.dispatch(&h.harness.runtime, 1, .start);
828
+ try waitForRealCompletion(&h, sawExit);
829
+
830
+ try std.testing.expectEqual(@as(usize, 1), h.app_state.model.line_count);
831
+ // Spawn line framing removes LF; a Windows child's CRLF leaves CR in the
832
+ // delivered bytes, matching the effect's byte-honest stream contract.
833
+ try std.testing.expectEqualStrings("detached\r", h.app_state.model.lineAt(0));
834
+ try std.testing.expectEqual(@as(i32, 0), h.app_state.model.exit_code);
835
+ try std.testing.expectEqual(effects_mod.EffectExitReason.exited, h.app_state.model.exit_reason.?);
836
+ }
837
+
808
838
  test "real executor streams a process's stdout lines into the model" {
809
839
  if (builtin.os.tag == .windows) return error.SkipZigTest;
810
840
  var h = try Harness.create();
@@ -86,19 +86,25 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
86
86
  // republish when the runtime is invalidated, and a frame
87
87
  // completion carrying a NEW discrete fact may have no
88
88
  // other invalidation source, leaving the published
89
- // snapshot stale forever. Two such facts invalidate here
90
- // (a third — a resolved input latency — is checked after
89
+ // snapshot stale forever. Three such facts invalidate here
90
+ // (a fourth — a resolved input latency — is checked after
91
91
  // the app dispatch below, where the responding present
92
92
  // stamps it):
93
93
  // - the host-reported nonblank verdict changed (the
94
94
  // first nonblank presentation on an idle boot has no
95
95
  // resize and no input to piggyback on);
96
+ // - the concrete presenter changed (for example a
97
+ // Direct2D packet refusal fell back to software, or a
98
+ // later packet recovered Direct2D);
96
99
  // - this frame recorded the first-frame latency.
97
100
  // Steady-state frames carry no new fact and stay quiet —
98
101
  // a timer-mode surface must not republish observable
99
102
  // state 60 times a second.
100
103
  const first_frame_latency_recorded = !first_frame_latency_was_recorded and self.views[index].gpu_first_frame_latency_recorded;
101
- if (self.views[index].gpu_frame_nonblank != frame_event.nonblank or first_frame_latency_recorded) {
104
+ if (self.views[index].gpu_frame_nonblank != frame_event.nonblank or
105
+ self.views[index].gpu_backend != frame_event.backend or
106
+ first_frame_latency_recorded)
107
+ {
102
108
  self.invalidateFor(.state, self.views[index].frame);
103
109
  }
104
110
  self.views[index].gpu_frame_nonblank = frame_event.nonblank;
@@ -113,11 +119,11 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
113
119
  try enrichGpuSurfaceFrameDiagnostics(self, index, &enriched_frame_event);
114
120
  } else if (self.views[index].info().gpuFrame()) |gpu_frame| {
115
121
  enriched_frame_event = gpuSurfaceFrameEventFromGpuFrame(gpu_frame);
116
- // GpuFrame is persistent surface state; the occluded
117
- // fact is per-completion metadata and must survive
118
- // the rebuild so the app sees it honestly.
119
- enriched_frame_event.occluded = frame_event.occluded;
120
122
  }
123
+ // Diagnostic enrichment and the low-cost persistent-frame
124
+ // rebuild can both replace fields. Reapply facts owned by
125
+ // this host completion, including device-loss recovery.
126
+ preserveGpuSurfaceCompletionFacts(frame_event, &enriched_frame_event);
121
127
  // Alpha mode is immutable surface configuration, not a
122
128
  // completion-time measurement. The desktop ABIs predate
123
129
  // premultiplied surfaces and stamp their legacy opaque
@@ -353,30 +359,30 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
353
359
  self.targetless_ime_preedit_label[0..self.targetless_ime_preedit_label_len],
354
360
  input_event.label,
355
361
  );
356
- // A Tab key-down that moved focus INTO a live terminal is a
357
- // focus gesture for its whole physical lifetime. Suppress
358
- // its auto-repeats and release before any widget pass can
359
- // reinterpret them against the newly focused terminal.
360
- const terminal_focus_entry_tab_suppressed =
361
- CanvasWidgetEventMethods().consumeCanvasWidgetTerminalFocusEntryTab(self, input_event);
362
+ // A Tab key-down that moved focus INTO a Tab-owning editor is
363
+ // a focus gesture for its whole physical lifetime. Suppress
364
+ // repeats and release before a live terminal or editable code
365
+ // can reinterpret them as input.
366
+ const tab_input_focus_entry_suppressed =
367
+ CanvasWidgetEventMethods().consumeCanvasWidgetTabInputFocusEntry(self, input_event);
362
368
  // Terminal Paste owns its matching physical V release even
363
369
  // when Command/Ctrl came up first. Classify it before focus,
364
370
  // routing, or app fallbacks can reinterpret the orphan.
365
371
  const terminal_paste_release_suppressed =
366
372
  CanvasWidgetEventMethods().consumeCanvasWidgetTerminalPasteKeyLifetime(self, input_event);
367
- const terminal_key_lifetime_suppressed =
368
- terminal_focus_entry_tab_suppressed or terminal_paste_release_suppressed;
369
- const keyboard_dismissed_id = if (targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
373
+ const widget_key_lifetime_suppressed =
374
+ tab_input_focus_entry_suppressed or terminal_paste_release_suppressed;
375
+ const keyboard_dismissed_id = if (targetless_composition_owns_keys or widget_key_lifetime_suppressed)
370
376
  0
371
377
  else
372
378
  try CanvasWidgetEventMethods().dismissCanvasWidgetSurfaceFromKeyboardInput(self, input_event);
373
379
  if (keyboard_dismissed_id != 0) dismissed_surface_id = keyboard_dismissed_id;
374
380
  const widget_surface_dismissed = keyboard_dismissed_id != 0;
375
- const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
381
+ const widget_focus_moved = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
376
382
  false
377
383
  else
378
384
  try CanvasWidgetEventMethods().updateCanvasWidgetFocusFromKeyboardInput(self, input_event);
379
- var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or terminal_key_lifetime_suppressed)
385
+ var widget_keyboard_event = if (widget_surface_dismissed or targetless_composition_owns_keys or widget_key_lifetime_suppressed)
380
386
  null
381
387
  else
382
388
  CanvasWidgetEventMethods().routeCanvasWidgetKeyboardInput(self, input_event, &self.widget_event_route_entries) catch |err| switch (err) {
@@ -676,7 +682,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
676
682
  try self.dispatchEvent(app, .{ .canvas_widget_keyboard = followup });
677
683
  }
678
684
  } else if ((input_event.kind == .key_down or input_event.kind == .key_up) and
679
- !widget_surface_dismissed and !terminal_key_lifetime_suppressed)
685
+ !widget_surface_dismissed and !widget_key_lifetime_suppressed)
680
686
  {
681
687
  // No focused widget routed this key (nothing is
682
688
  // focused, or the focused id is gone from the tree): the
@@ -1037,6 +1043,7 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
1037
1043
  .timestamp_ns = enriched_frame_event.timestamp_ns,
1038
1044
  .surface_size = enriched_frame_event.size,
1039
1045
  .scale = enriched_frame_event.scale_factor,
1046
+ .full_repaint = enriched_frame_event.canvas_frame_full_repaint,
1040
1047
  }, CanvasFrameMethods().canvasFrameScratchStorage(self), false);
1041
1048
  const preview_render_pass = preview_frame.renderPass();
1042
1049
  const preview_gpu_packet_summary = preview_frame.gpuPacketSummary();
@@ -1142,6 +1149,30 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
1142
1149
  };
1143
1150
  }
1144
1151
 
1152
+ fn preserveGpuSurfaceCompletionFacts(source: platform.GpuSurfaceFrameEvent, target: *platform.GpuSurfaceFrameEvent) void {
1153
+ target.occluded = source.occluded;
1154
+ if (source.canvas_frame_full_repaint) {
1155
+ target.canvas_frame_requires_render = true;
1156
+ target.canvas_frame_full_repaint = true;
1157
+ }
1158
+ }
1159
+
1160
+ test "GPU completion preserves host-forced full repaint" {
1161
+ var enriched: platform.GpuSurfaceFrameEvent = .{
1162
+ .label = "canvas",
1163
+ .size = geometry.SizeF.init(640, 360),
1164
+ };
1165
+ preserveGpuSurfaceCompletionFacts(.{
1166
+ .label = "canvas",
1167
+ .size = geometry.SizeF.init(640, 360),
1168
+ .occluded = true,
1169
+ .canvas_frame_full_repaint = true,
1170
+ }, &enriched);
1171
+ try std.testing.expect(enriched.occluded);
1172
+ try std.testing.expect(enriched.canvas_frame_requires_render);
1173
+ try std.testing.expect(enriched.canvas_frame_full_repaint);
1174
+ }
1175
+
1145
1176
  fn setFocusedView(self: anytype, window_id: platform.WindowId, label: []const u8) !void {
1146
1177
  if (runtimeFindWindowIndexById(self, window_id)) |window_index| {
1147
1178
  self.windows[window_index].main_focused = std.mem.eql(u8, label, "main");
@@ -877,7 +877,7 @@ test "a session recorded with a live producer replays fingerprint-identical with
877
877
  const media = @import("../root.zig");
878
878
 
879
879
  test "docs example: the typed producer callback is writable against the public exports" {
880
- // docs/src/app/media-producers/page.mdx, "The mpv shape": the docs
880
+ // docs/src/app/docs/media-producers/page.mdx, "The mpv shape": the docs
881
881
  // machinery checks prose patterns, not Zig fences (the
882
882
  // test-docs-media-producer-contracts step pins the signature in the
883
883
  // page AND in this file), so this test is the compile-shaped mirror
@@ -936,6 +936,80 @@ test "gpu surface nonblank transition invalidates the runtime" {
936
936
  try std.testing.expect(!harness.runtime.invalidated);
937
937
  }
938
938
 
939
+ test "gpu surface backend transition invalidates the runtime" {
940
+ const TestApp = struct {
941
+ fn app(self: *@This()) App {
942
+ return .{ .context = self, .name = "gpu-backend-transition", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
943
+ }
944
+
945
+ fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
946
+ _ = context;
947
+ _ = runtime;
948
+ _ = event_value;
949
+ }
950
+ };
951
+
952
+ const harness = try TestHarness().create(std.testing.allocator, .{});
953
+ defer harness.destroy(std.testing.allocator);
954
+ harness.null_platform.gpu_surfaces = true;
955
+ var app_state: TestApp = .{};
956
+ const app = app_state.app();
957
+ try harness.start(app);
958
+
959
+ _ = try harness.runtime.createView(.{
960
+ .window_id = 1,
961
+ .label = "canvas",
962
+ .kind = .gpu_surface,
963
+ .frame = geometry.RectF.init(0, 0, 640, 360),
964
+ });
965
+
966
+ // A fallback completion changes an observable snapshot fact even when
967
+ // nonblank and latency state stay unchanged.
968
+ harness.runtime.invalidated = false;
969
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
970
+ .window_id = 1,
971
+ .label = "canvas",
972
+ .size = geometry.SizeF.init(640, 360),
973
+ .scale_factor = 1,
974
+ .frame_index = 1,
975
+ .timestamp_ns = 16,
976
+ .nonblank = false,
977
+ .backend = .software,
978
+ } });
979
+ try std.testing.expect(harness.runtime.invalidated);
980
+ try std.testing.expectEqual(platform.GpuSurfaceBackend.software, (try harness.runtime.gpuSurfaceFrame(1, "canvas")).backend);
981
+
982
+ // The same presenter on the next timer completion is steady state and
983
+ // must not turn snapshot publication into a per-frame loop.
984
+ harness.runtime.invalidated = false;
985
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
986
+ .window_id = 1,
987
+ .label = "canvas",
988
+ .size = geometry.SizeF.init(640, 360),
989
+ .scale_factor = 1,
990
+ .frame_index = 2,
991
+ .timestamp_ns = 32,
992
+ .nonblank = false,
993
+ .backend = .software,
994
+ } });
995
+ try std.testing.expect(!harness.runtime.invalidated);
996
+
997
+ // Recovery to the packet presenter is the same observable transition
998
+ // in the opposite direction.
999
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
1000
+ .window_id = 1,
1001
+ .label = "canvas",
1002
+ .size = geometry.SizeF.init(640, 360),
1003
+ .scale_factor = 1,
1004
+ .frame_index = 3,
1005
+ .timestamp_ns = 48,
1006
+ .nonblank = false,
1007
+ .backend = .direct2d,
1008
+ } });
1009
+ try std.testing.expect(harness.runtime.invalidated);
1010
+ try std.testing.expectEqual(platform.GpuSurfaceBackend.direct2d, (try harness.runtime.gpuSurfaceFrame(1, "canvas")).backend);
1011
+ }
1012
+
939
1013
  test "a handler error degrades: dispatch continues, the error ring records it, snapshots publish it" {
940
1014
  // One erroring update arm used to exit the whole app
941
1015
  // (the platform callback saw the error, set `failed`, and stopped