@native-sdk/cli 0.7.1 → 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 (59) hide show
  1. package/build/app.zig +8 -0
  2. package/build.zig +49 -12
  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/skill-data/native-ui/SKILL.md +4 -2
  8. package/src/platform/macos/appkit_host.m +51 -3
  9. package/src/platform/types.zig +4 -0
  10. package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
  11. package/src/platform/windows/gpu_surface_renderer.h +86 -0
  12. package/src/platform/windows/root.zig +298 -20
  13. package/src/platform/windows/webview2_host.cpp +343 -33
  14. package/src/primitives/canvas/code.zig +50 -0
  15. package/src/primitives/canvas/code_tests.zig +174 -1
  16. package/src/primitives/canvas/frame.zig +45 -1
  17. package/src/primitives/canvas/gpu.zig +6 -0
  18. package/src/primitives/canvas/render_tests.zig +93 -0
  19. package/src/primitives/canvas/root.zig +2 -0
  20. package/src/primitives/canvas/serialization.zig +150 -21
  21. package/src/primitives/canvas/themes/geist.zig +51 -5
  22. package/src/primitives/canvas/tokens.zig +33 -4
  23. package/src/primitives/canvas/ui.zig +52 -7
  24. package/src/primitives/canvas/ui_markup.zig +38 -1
  25. package/src/primitives/canvas/ui_markup_compiled.zig +28 -0
  26. package/src/primitives/canvas/ui_markup_contract.zig +9 -0
  27. package/src/primitives/canvas/ui_markup_view.zig +28 -0
  28. package/src/primitives/canvas/ui_markup_view_tests.zig +10 -2
  29. package/src/primitives/canvas/ui_schema.zig +5 -0
  30. package/src/primitives/canvas/ui_schema_tests.zig +4 -3
  31. package/src/primitives/canvas/ui_tests.zig +14 -0
  32. package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
  33. package/src/primitives/canvas/widget_invalidation.zig +11 -1
  34. package/src/primitives/canvas/widget_layout.zig +260 -21
  35. package/src/primitives/canvas/widget_metrics.zig +45 -9
  36. package/src/primitives/canvas/widget_render.zig +220 -70
  37. package/src/primitives/canvas/widget_render_controls.zig +79 -21
  38. package/src/primitives/canvas/widget_render_style.zig +52 -8
  39. package/src/primitives/canvas/widget_text_input.zig +2 -0
  40. package/src/primitives/canvas/widgets.zig +53 -2
  41. package/src/runtime/canvas_frame.zig +60 -7
  42. package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
  43. package/src/runtime/canvas_frame_packet_tests.zig +83 -9
  44. package/src/runtime/canvas_frame_patch_tests.zig +16 -0
  45. package/src/runtime/canvas_images.zig +8 -2
  46. package/src/runtime/canvas_widget_clipboard_tests.zig +1 -1
  47. package/src/runtime/canvas_widget_runtime.zig +11 -8
  48. package/src/runtime/effects.zig +6 -0
  49. package/src/runtime/effects_tests.zig +30 -0
  50. package/src/runtime/gpu_surface_events.zig +38 -7
  51. package/src/runtime/media_surface_tests.zig +1 -1
  52. package/src/runtime/runtime_event_tests.zig +74 -0
  53. package/src/runtime/ui_app.zig +10 -8
  54. package/src/runtime/ui_app_tests.zig +67 -0
  55. package/src/runtime/view.zig +6 -0
  56. package/src/runtime/view_canvas.zig +15 -0
  57. package/src/runtime/view_widget_text.zig +6 -4
  58. package/src/runtime/window_view_runtime.zig +1 -0
  59. package/src/tooling/templates.zig +9 -6
@@ -477,6 +477,7 @@ fn widgetTextInputFontId(widget: Widget, tokens: DesignTokens) FontId {
477
477
  }
478
478
 
479
479
  fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32) bool {
480
+ if (widget.hasCodeDiff()) return false;
480
481
  return widget.code_content_width_generation == text_measure_cache.textMeasureGeneration() and
481
482
  widget.code_content_width_font_id == font_id and
482
483
  widget.code_content_width_size_bits == @as(u32, @bitCast(text_size)) and
@@ -489,6 +490,7 @@ fn codeContentWidthCacheCurrent(widget: Widget, font_id: FontId, text_size: f32)
489
490
  /// edits invalidate it before caret scrolling recomputes the new document.
490
491
  pub fn cacheTextInputContentWidthForWidget(widget: *Widget, tokens: DesignTokens) void {
491
492
  if (widget.kind != .textarea or !widget.code_editor or !widget.text_no_wrap) return;
493
+ if (widget.hasCodeDiff()) return;
492
494
  const text_size = widgetTextInputSize(widget.*, tokens);
493
495
  const font_id = widgetTextInputFontId(widget.*, tokens);
494
496
  if (codeContentWidthCacheCurrent(widget.*, font_id, text_size)) return;
@@ -264,6 +264,13 @@ pub const WidgetState = struct {
264
264
  invalid: bool = false,
265
265
  };
266
266
 
267
+ /// Two 128-line masks for code-only diff presentation. `Widget` packs them
268
+ /// into fields dormant on decorated code so ordinary widgets do not grow.
269
+ pub const CodeDiffLines = struct {
270
+ added: u128,
271
+ removed: u128,
272
+ };
273
+
267
274
  pub const WidgetRenderState = struct {
268
275
  /// Whether the app is active and this widget tree's window is key.
269
276
  /// Runtime focus ids stay retained while false so focus-visible
@@ -359,6 +366,11 @@ pub const WidgetAnchor = struct {
359
366
 
360
367
  pub const WidgetLayoutStyle = struct {
361
368
  padding: geometry.InsetsF = .{},
369
+ /// True when the widget-kind defaults supplied `padding`. Layout
370
+ /// resolution uses this provenance to translate a house default onto
371
+ /// another theme register without mistaking an equal author value for
372
+ /// the default. Author-created styles leave this false.
373
+ padding_is_kind_default: bool = false,
362
374
  gap: f32 = 0,
363
375
  grow: f32 = 0,
364
376
  main_alignment: WidgetMainAlignment = .start,
@@ -870,6 +882,8 @@ pub const Widget = struct {
870
882
  /// retained text, so selection/copy remains the exact source bytes.
871
883
  /// Stamped only by `Ui.code`; there is no generic builder/markup
872
884
  /// channel for turning arbitrary paragraphs into numbered code.
885
+ /// Bit 7 is an internal diff-metadata tag; `codeLineNumberDigits`
886
+ /// exposes only the authored digit count.
873
887
  code_line_number_digits: u8 = 0,
874
888
  /// Optional one-based logical depth for a flat sequence of tree rows.
875
889
  /// Zero keeps the structural nesting contract. A nonzero value lets a
@@ -898,9 +912,10 @@ pub const Widget = struct {
898
912
  /// Nonzero on bounded paragraph chunks that together present one
899
913
  /// selectable source-code document. The group id is the structural id
900
914
  /// of their internal parent; offsets order each chunk's exact source
901
- /// bytes without duplicating the full source in retained storage.
915
+ /// bytes without duplicating the full source in retained storage. Fixed
916
+ /// width keeps the code-diff metadata union intact on 32-bit targets.
902
917
  static_text_group_id: ObjectId = 0,
903
- static_text_group_offset: usize = 0,
918
+ static_text_group_offset: u64 = 0,
904
919
  /// What a single-line text run does with content that does not fit
905
920
  /// its frame (`ElementOptions.overflow` / markup `overflow=` on
906
921
  /// text leaves): `.ellipsis` (default) elides the tail behind a
@@ -1062,6 +1077,41 @@ pub const Widget = struct {
1062
1077
  /// serialization, or equality decisions.
1063
1078
  group_segment: WidgetGroupSegment = .none,
1064
1079
  children: []const Widget = &.{},
1080
+
1081
+ pub fn codeLineNumberDigits(self: Widget) u8 {
1082
+ return self.code_line_number_digits & 0x7f;
1083
+ }
1084
+
1085
+ pub fn hasCodeDiff(self: Widget) bool {
1086
+ return self.code_line_number_digits & 0x80 != 0;
1087
+ }
1088
+
1089
+ /// Code-only metadata occupies the otherwise unused no-wrap width-cache
1090
+ /// words plus the ungrouped static-text offset. The high bit above tags
1091
+ /// the union. This keeps Widget's common footprint unchanged; a diff
1092
+ /// editor simply measures its longest line on demand instead of caching.
1093
+ pub fn codeDiffLines(self: Widget) ?CodeDiffLines {
1094
+ if (!self.hasCodeDiff()) return null;
1095
+ const removed_low = @as(u64, @as(u32, @bitCast(self.code_content_width))) |
1096
+ (@as(u64, self.code_content_width_size_bits) << 32);
1097
+ return .{
1098
+ .added = @as(u128, self.code_content_width_generation) |
1099
+ (@as(u128, self.code_content_width_font_id) << 64),
1100
+ .removed = @as(u128, removed_low) |
1101
+ (@as(u128, self.static_text_group_offset) << 64),
1102
+ };
1103
+ }
1104
+
1105
+ pub fn setCodeDiffLines(self: *Widget, lines: CodeDiffLines) void {
1106
+ std.debug.assert(self.static_text_group_id == 0);
1107
+ self.code_line_number_digits |= 0x80;
1108
+ self.code_content_width_generation = @truncate(lines.added);
1109
+ self.code_content_width_font_id = @truncate(lines.added >> 64);
1110
+ const removed_low: u64 = @truncate(lines.removed);
1111
+ self.code_content_width = @bitCast(@as(u32, @truncate(removed_low)));
1112
+ self.code_content_width_size_bits = @truncate(removed_low >> 32);
1113
+ self.static_text_group_offset = @truncate(lines.removed >> 64);
1114
+ }
1065
1115
  };
1066
1116
 
1067
1117
  pub const BuiltinComponentOptions = struct {
@@ -1508,6 +1558,7 @@ fn mergeLayoutDefaults(explicit: WidgetLayoutStyle, defaults: WidgetLayoutStyle)
1508
1558
  explicit.padding.bottom == 0 and explicit.padding.left == 0)
1509
1559
  {
1510
1560
  merged.padding = defaults.padding;
1561
+ merged.padding_is_kind_default = true;
1511
1562
  }
1512
1563
  if (explicit.gap == 0) merged.gap = defaults.gap;
1513
1564
  if (explicit.cross_alignment == .stretch) merged.cross_alignment = defaults.cross_alignment;
@@ -33,6 +33,16 @@ pub const canvasRenderAnimationActive = canvas_frame_helpers.canvasRenderAnimati
33
33
  pub const platformCanvasFrameProfileRisk = canvas_frame_helpers.platformCanvasFrameProfileRisk;
34
34
  pub const gpuSurfaceFrameEventFromGpuFrame = canvas_frame_helpers.gpuSurfaceFrameEventFromGpuFrame;
35
35
 
36
+ /// Whether presentation for this view should use the GPU packet path. A
37
+ /// missing view stays eligible so the presentation entry point can report
38
+ /// its normal validation error instead of masking it as a backend choice.
39
+ pub fn canvasGpuPacketPresentationRequested(runtime: anytype, window_id: platform.WindowId, label: []const u8) bool {
40
+ return if (runtimeFindViewIndex(runtime, window_id, label)) |index|
41
+ runtime.views[index].gpu_requested_backend != .software
42
+ else
43
+ true;
44
+ }
45
+
36
46
  const runtime_api = @import("api.zig");
37
47
  const runtime_clock = @import("clock.zig");
38
48
  const validation = @import("validation.zig");
@@ -254,7 +264,16 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
254
264
  packet_json_buffer: []u8,
255
265
  packet_scale: ?f32,
256
266
  ) anyerror!canvas.CanvasGpuPacket {
257
- var canvas_frame = try self.nextCanvasFrame(window_id, label, options, storage);
267
+ // An explicit software request is a presentation policy, not a
268
+ // host refusal. Stop before planning or encoding a packet (and
269
+ // before uploading any packet image resources); callers that
270
+ // offer a pixel fallback handle UnsupportedService as usual.
271
+ try validateRuntimeViewParent(self, window_id);
272
+ try validateViewLabel(label);
273
+ const view_index = runtimeFindViewIndex(self, window_id, label) orelse return error.ViewNotFound;
274
+ if (self.views[view_index].kind != .gpu_surface) return error.InvalidViewOptions;
275
+ if (self.views[view_index].gpu_requested_backend == .software) return error.UnsupportedService;
276
+ var canvas_frame = try planCanvasFrameForView(self, view_index, options, storage, true);
258
277
  recordCanvasClearColor(self, window_id, label, clear_color);
259
278
  const presentation_scale = normalizedCanvasPresentationScale(packet_scale, canvas_frame.scale);
260
279
  // Widen BEFORE the packet build so the scissor-culled
@@ -318,9 +337,11 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
318
337
  widenCanvasFrameDirtyForPresentationScale(&canvas_frame, presentation_scale);
319
338
 
320
339
  const services = self.options.platform.services;
321
- const packet_service_available = services.present_gpu_surface_packet_fn != null or
322
- services.present_gpu_surface_packet_binary_fn != null;
323
- if (gpu_commands.len > 0 and packet_json_buffer.len > 0) {
340
+ const packet_requested = canvasGpuPacketPresentationRequested(self, window_id, label);
341
+ const packet_service_available = packet_requested and
342
+ (services.present_gpu_surface_packet_fn != null or
343
+ services.present_gpu_surface_packet_binary_fn != null);
344
+ if (packet_requested and gpu_commands.len > 0 and packet_json_buffer.len > 0) {
324
345
  if (packet_service_available) {
325
346
  var packet = try canvas_frame.gpuPacket(gpu_commands);
326
347
  packet.scale = presentation_scale;
@@ -1029,17 +1050,17 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1029
1050
  storage.text_layout_cache_actions,
1030
1051
  );
1031
1052
 
1032
- const full_repaint = frame_options.full_repaint or
1053
+ var full_repaint = frame_options.full_repaint or
1033
1054
  !self.views[index].presented_canvas_valid or
1034
1055
  canvas_surface_changed or
1035
1056
  (canvas_changed and (self.views[index].presented_canvas_has_unkeyed or self.views[index].currentCanvasHasUnkeyed()));
1036
- const changes = if (full_repaint)
1057
+ var changes: []const canvas.DiffChange = if (full_repaint)
1037
1058
  storage.changes[0..0]
1038
1059
  else
1039
1060
  try self.views[index].diffPresentedCanvasSummary(storage.changes);
1040
1061
  var dirty_rects: [canvas.max_canvas_frame_dirty_rects]geometry.RectF = undefined;
1041
1062
  var dirty_rect_count: usize = 0;
1042
- const dirty_bounds = if (full_repaint)
1063
+ var dirty_bounds: ?geometry.RectF = if (full_repaint)
1043
1064
  canvasFullRepaintBounds(frame_options.surface_size, render_plan.bounds)
1044
1065
  else dirty: {
1045
1066
  // Every incremental dirty rect leaves here through
@@ -1109,6 +1130,23 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1109
1130
  }
1110
1131
  break :dirty bleedAlignedCanvasDirtyBounds(unionRects(canvasDirtyBoundsFromChanges(changes), overrides_dirty), frame_options.scale, 1, frame_options.surface_size);
1111
1132
  };
1133
+ if (!full_repaint and incrementalCanvasDamageIntersectsBackdropBlur(
1134
+ render_plan.commands,
1135
+ dirty_bounds,
1136
+ dirty_rects[0..dirty_rect_count],
1137
+ )) {
1138
+ // A blur's apron must be reconstructed from the scene as
1139
+ // it existed before that command. Retained pixels beyond
1140
+ // an incremental scissor are already fully composited,
1141
+ // so widening only the output rect would still sample
1142
+ // stale blur/later-command pixels at its edge. Replay the
1143
+ // whole ordered list when damage reaches the blur's read
1144
+ // footprint; damage elsewhere remains incremental.
1145
+ full_repaint = true;
1146
+ changes = storage.changes[0..0];
1147
+ dirty_bounds = canvasFullRepaintBounds(frame_options.surface_size, render_plan.bounds);
1148
+ dirty_rect_count = 0;
1149
+ }
1112
1150
 
1113
1151
  const canvas_frame = canvas.CanvasFrame{
1114
1152
  .frame_index = frame_options.frame_index,
@@ -1271,6 +1309,21 @@ pub fn RuntimeCanvasFrames(comptime Runtime: type) type {
1271
1309
  };
1272
1310
  }
1273
1311
 
1312
+ /// Refined patch damage is a set, not its bounding box: two distant edits
1313
+ /// can straddle a blur without either edit reaching the blur's read apron.
1314
+ /// When refinement is unavailable, retain the conservative union check.
1315
+ fn incrementalCanvasDamageIntersectsBackdropBlur(
1316
+ commands: []const canvas.RenderCommand,
1317
+ dirty_bounds: ?geometry.RectF,
1318
+ dirty_rects: []const geometry.RectF,
1319
+ ) bool {
1320
+ if (dirty_rects.len == 0) return canvas.incrementalDamageIntersectsBackdropBlur(commands, dirty_bounds);
1321
+ for (dirty_rects) |dirty_rect| {
1322
+ if (canvas.incrementalDamageIntersectsBackdropBlur(commands, dirty_rect)) return true;
1323
+ }
1324
+ return false;
1325
+ }
1326
+
1274
1327
  /// Rework a planned frame's incremental damage for the present's
1275
1328
  /// EFFECTIVE scale. Two obligations when the scales differ:
1276
1329
  /// - A COARSER presentation scale carries a larger device pixel than
@@ -431,6 +431,86 @@ test "runtime invalidates canvas display list dirty regions" {
431
431
  try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
432
432
  }
433
433
 
434
+ test "backdrop blur promotes intersecting damage to a full repaint" {
435
+ const TestApp = struct {
436
+ fn app(self: *@This()) App {
437
+ return .{ .context = self, .name = "gpu-canvas-blur-damage", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
438
+ }
439
+ };
440
+
441
+ const surface = geometry.SizeF.init(100, 40);
442
+ const harness = try TestHarness().create(std.testing.allocator, .{});
443
+ defer harness.destroy(std.testing.allocator);
444
+ harness.null_platform.gpu_surfaces = true;
445
+ harness.runtime.options.pixel_present_retained_baseline = true;
446
+ var app_state: TestApp = .{};
447
+ try harness.start(app_state.app());
448
+
449
+ _ = try harness.runtime.createView(.{
450
+ .window_id = 1,
451
+ .label = "canvas",
452
+ .kind = .gpu_surface,
453
+ .frame = geometry.RectF.init(0, 0, surface.width, surface.height),
454
+ });
455
+ var pixels: [100 * 40 * 4]u8 = undefined;
456
+ var scratch: [100 * 40 * 4]u8 = undefined;
457
+ const clear = canvas.Color.rgb8(0, 0, 0);
458
+
459
+ const initial = [_]canvas.CanvasCommand{
460
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(4, 4, 4, 4), .fill = .{ .color = canvas.Color.rgb8(255, 0, 0) } } },
461
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(44, 15, 4, 4), .fill = .{ .color = canvas.Color.rgb8(255, 0, 0) } } },
462
+ .{ .fill_rect = .{ .id = 5, .rect = geometry.RectF.init(90, 4, 4, 4), .fill = .{ .color = canvas.Color.rgb8(255, 0, 0) } } },
463
+ .{ .push_clip = .{ .id = 3, .rect = geometry.RectF.init(50, 10, 20, 20) } },
464
+ .{ .blur = .{ .id = 4, .rect = geometry.RectF.init(50, 10, 20, 20), .radius = 8 } },
465
+ .pop_clip,
466
+ };
467
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &initial });
468
+ const first = try harness.runtime.presentNextCanvasFramePixels(1, "canvas", .{
469
+ .frame_index = 1,
470
+ .surface_size = surface,
471
+ }, canvasFrameScratchStorage(&harness.runtime), &pixels, &scratch, clear);
472
+ try std.testing.expect(first.full_repaint);
473
+
474
+ // Two damage islands well outside the blur's radius keep the retained
475
+ // path even though their bounding union crosses the blur apron.
476
+ const far_changed = [_]canvas.CanvasCommand{
477
+ .{ .fill_rect = .{ .id = 1, .rect = geometry.RectF.init(4, 4, 4, 4), .fill = .{ .color = canvas.Color.rgb8(0, 255, 0) } } },
478
+ initial[1],
479
+ .{ .fill_rect = .{ .id = 5, .rect = geometry.RectF.init(90, 4, 4, 4), .fill = .{ .color = canvas.Color.rgb8(0, 255, 0) } } },
480
+ initial[3],
481
+ initial[4],
482
+ initial[5],
483
+ };
484
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &far_changed });
485
+ const incremental = try harness.runtime.presentNextCanvasFramePixels(1, "canvas", .{
486
+ .frame_index = 2,
487
+ .surface_size = surface,
488
+ }, canvasFrameScratchStorage(&harness.runtime), &pixels, &scratch, clear);
489
+ try std.testing.expect(!incremental.full_repaint);
490
+ try std.testing.expect(incremental.dirty_bounds != null);
491
+ try std.testing.expectEqual(@as(usize, 2), incremental.dirtyRects().len);
492
+
493
+ // This changed rect stops two points before the blur output, but it
494
+ // lies inside the radius-8 sampling apron. A scissored replay would
495
+ // sample the prior composited frame outside its dirty boundary.
496
+ const apron_changed = [_]canvas.CanvasCommand{
497
+ far_changed[0],
498
+ .{ .fill_rect = .{ .id = 2, .rect = geometry.RectF.init(44, 15, 4, 4), .fill = .{ .color = canvas.Color.rgb8(0, 0, 255) } } },
499
+ far_changed[2],
500
+ initial[3],
501
+ initial[4],
502
+ initial[5],
503
+ };
504
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &apron_changed });
505
+ const promoted = try harness.runtime.presentNextCanvasFramePixels(1, "canvas", .{
506
+ .frame_index = 3,
507
+ .surface_size = surface,
508
+ }, canvasFrameScratchStorage(&harness.runtime), &pixels, &scratch, clear);
509
+ try std.testing.expect(promoted.full_repaint);
510
+ try std.testing.expectEqual(@as(usize, 0), promoted.changes.len);
511
+ try std.testing.expectEqualDeep(geometry.RectF.init(0, 0, surface.width, surface.height), promoted.dirty_bounds.?);
512
+ }
513
+
434
514
  test "runtime requests gpu surface frames for retained canvas changes" {
435
515
  const TestApp = struct {
436
516
  fn app(self: *@This()) App {
@@ -474,6 +474,68 @@ test "runtime presents next canvas frame through packet presenter when available
474
474
  try std.testing.expect(!presented_frame.canvas_frame_requires_render);
475
475
  }
476
476
 
477
+ test "runtime explicit software canvas bypasses packet encoding and image upload" {
478
+ const TestApp = struct {
479
+ fn app(self: *@This()) App {
480
+ return .{ .context = self, .name = "gpu-canvas-explicit-software", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
481
+ }
482
+ };
483
+
484
+ const harness = try TestHarness().create(std.testing.allocator, .{});
485
+ defer harness.destroy(std.testing.allocator);
486
+ harness.null_platform.gpu_surfaces = true;
487
+ var app_state: TestApp = .{};
488
+ try harness.start(app_state.app());
489
+
490
+ _ = try harness.runtime.createView(.{
491
+ .window_id = 1,
492
+ .label = "canvas",
493
+ .kind = .gpu_surface,
494
+ .frame = geometry.RectF.init(0, 0, 4, 4),
495
+ .gpu_surface = .{ .backend = .software },
496
+ });
497
+
498
+ const red = [4]u8{ 255, 0, 0, 255 };
499
+ try harness.runtime.registerCanvasImage(7, 1, 1, &red);
500
+ const commands = [_]canvas.CanvasCommand{.{ .draw_image = .{
501
+ .id = 1,
502
+ .image_id = 7,
503
+ .dst = geometry.RectF.init(0, 0, 4, 4),
504
+ } }};
505
+ _ = try harness.runtime.setCanvasDisplayList(1, "canvas", .{ .commands = &commands });
506
+
507
+ var gpu_commands: [max_canvas_commands_per_view]canvas.CanvasGpuCommand = undefined;
508
+ var packet_json_buffer: [16 * 1024]u8 = undefined;
509
+ var pixels: [4 * 4 * 4]u8 = undefined;
510
+ var scratch: [4 * 4 * 4]u8 = undefined;
511
+
512
+ // The direct packet-present entry point enforces the same policy as
513
+ // automatic presentation and exits before packet image upload.
514
+ try std.testing.expectError(error.UnsupportedService, harness.runtime.presentNextCanvasGpuPacket(1, "canvas", .{
515
+ .frame_index = 21,
516
+ .timestamp_ns = 88_000,
517
+ .surface_size = geometry.SizeF.init(4, 4),
518
+ .scale = 1,
519
+ }, canvasFrameScratchStorage(&harness.runtime), canvas.Color.rgb8(0, 0, 0), &gpu_commands, &packet_json_buffer));
520
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.gpu_surface_packet_present_count);
521
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.gpu_surface_image_upload_count);
522
+ try std.testing.expectEqual(platform.GpuPresentFallbackReason.none, harness.runtime.views[0].info().gpu_present_fallback_reason);
523
+
524
+ const result = try harness.runtime.presentNextCanvasFrame(1, "canvas", .{
525
+ .frame_index = 22,
526
+ .timestamp_ns = 89_000,
527
+ .surface_size = geometry.SizeF.init(4, 4),
528
+ .scale = 1,
529
+ }, canvasFrameScratchStorage(&harness.runtime), &gpu_commands, &packet_json_buffer, &pixels, &scratch, canvas.Color.rgb8(0, 0, 0), null);
530
+
531
+ try std.testing.expectEqual(platform.GpuSurfaceBackend.software, harness.runtime.views[0].gpu_requested_backend);
532
+ try std.testing.expectEqual(CanvasPresentationMode.pixels, result.mode);
533
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.gpu_surface_packet_present_count);
534
+ try std.testing.expectEqual(@as(usize, 0), harness.null_platform.gpu_surface_image_upload_count);
535
+ try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_present_count);
536
+ try std.testing.expectEqual(platform.GpuPresentFallbackReason.none, harness.runtime.views[0].info().gpu_present_fallback_reason);
537
+ }
538
+
477
539
  test "runtime auto-present packet honors presentation scale without invalidating retained frame" {
478
540
  const TestApp = struct {
479
541
  fn app(self: *@This()) App {
@@ -829,19 +891,31 @@ test "runtime re-registration and unregister drive the image upload side-channel
829
891
  try std.testing.expectEqual(@as(usize, 2), harness.null_platform.gpu_surface_image_upload_count);
830
892
  try std.testing.expectEqualDeep([4]u8{ 0, 0, 255, 255 }, harness.null_platform.gpuSurfaceImage(9).?.sample_rgba);
831
893
 
832
- // Unregister drops the platform-side entry; the next frame (stale
833
- // tree still referencing the id) stays on the packet path with the
834
- // absent-image skip and uploads nothing new.
894
+ // Unregister drops the platform-side entry. Re-registering the SAME
895
+ // content before another frame must still upload: the platform
896
+ // resource is gone even though the image fingerprint matches the
897
+ // last presented cache key.
835
898
  try std.testing.expect(harness.runtime.unregisterCanvasImage(9));
836
899
  try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_image_remove_count);
837
900
  try std.testing.expect(harness.null_platform.gpuSurfaceImage(9) == null);
838
- const after = try present.frame(harness, &gpu_commands, &packet_json_buffer, &pixels, &scratch, 43);
901
+ try harness.runtime.registerCanvasImage(9, 1, 1, &blue);
902
+ const restored = try present.frame(harness, &gpu_commands, &packet_json_buffer, &pixels, &scratch, 43);
903
+ try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, restored.mode);
904
+ try std.testing.expectEqual(@as(usize, 3), harness.null_platform.gpu_surface_image_upload_count);
905
+ try std.testing.expectEqualDeep([4]u8{ 0, 0, 255, 255 }, harness.null_platform.gpuSurfaceImage(9).?.sample_rgba);
906
+
907
+ // A later unregister with no replacement keeps the stale tree on
908
+ // the packet path with the absent-image skip and no new upload.
909
+ try std.testing.expect(harness.runtime.unregisterCanvasImage(9));
910
+ try std.testing.expectEqual(@as(usize, 2), harness.null_platform.gpu_surface_image_remove_count);
911
+ try std.testing.expect(harness.null_platform.gpuSurfaceImage(9) == null);
912
+ const after = try present.frame(harness, &gpu_commands, &packet_json_buffer, &pixels, &scratch, 44);
839
913
  try std.testing.expectEqual(CanvasPresentationMode.gpu_packet, after.mode);
840
- try std.testing.expectEqual(@as(usize, 2), harness.null_platform.gpu_surface_image_upload_count);
914
+ try std.testing.expectEqual(@as(usize, 3), harness.null_platform.gpu_surface_image_upload_count);
841
915
 
842
916
  // Unregistering an absent id never reaches the platform.
843
917
  try std.testing.expect(!harness.runtime.unregisterCanvasImage(9));
844
- try std.testing.expectEqual(@as(usize, 1), harness.null_platform.gpu_surface_image_remove_count);
918
+ try std.testing.expectEqual(@as(usize, 2), harness.null_platform.gpu_surface_image_remove_count);
845
919
  }
846
920
 
847
921
  test "runtime falls back to pixels when the platform lacks the image upload seam" {
@@ -1193,9 +1267,9 @@ test "chat-transcript-shaped heavy frame stays on the packet path through the bi
1193
1267
  const binary_len = harness.null_platform.gpu_surface_packet_present_binary_len;
1194
1268
  try std.testing.expect(binary_len > 0);
1195
1269
  try std.testing.expect(binary_len <= platform.max_gpu_surface_packet_binary_bytes);
1196
- // The size win that makes the ceiling real: >=5x denser than the
1197
- // JSON encoding on this text-heavy frame.
1198
- try std.testing.expect(binary_len * 5 <= json_needed_bytes);
1270
+ // Positioned glyphs now ride the correctness-preserving v5 wire, while
1271
+ // compact fields still keep it >=3x denser than JSON on this shaped frame.
1272
+ try std.testing.expect(binary_len * 3 <= json_needed_bytes);
1199
1273
  try std.testing.expectEqual(platform.GpuPresentPath.packet, harness.runtime.views[0].gpu_present_path);
1200
1274
  try std.testing.expectEqual(platform.GpuPresentFallbackReason.none, harness.runtime.views[0].info().gpu_present_fallback_reason);
1201
1275
 
@@ -228,6 +228,22 @@ const BinaryCursor = struct {
228
228
  try self.skip(8 + 4 + 8 + 16); // font + size + origin + color
229
229
  const text_len = try self.readU32();
230
230
  try self.skip(text_len);
231
+ const has_positioned_glyphs = try self.readU8();
232
+ if (has_positioned_glyphs != 0) {
233
+ const glyph_count = try self.readU32();
234
+ for (0..glyph_count) |_| {
235
+ try self.skip(2); // glyph id
236
+ const glyph_flags = try self.readU8();
237
+ if (glyph_flags & 0x01 != 0) try self.skip(8); // font override
238
+ try self.skip(12); // x + baseline + advance
239
+ }
240
+ const fragment_count = try self.readU32();
241
+ for (0..fragment_count) |_| {
242
+ try self.skip(8); // x + baseline
243
+ const fragment_len = try self.readU32();
244
+ try self.skip(fragment_len);
245
+ }
246
+ }
231
247
  const has_layout = try self.readU8();
232
248
  if (has_layout != 0) {
233
249
  try self.skip(4 + 4 + 1 + 1); // max width + line height + wrap + align
@@ -192,8 +192,14 @@ pub fn RuntimeCanvasImages(comptime Runtime: type) type {
192
192
  // Best-effort drop of the platform-side texture: platforms
193
193
  // without the upload seam report UnsupportedService, and a
194
194
  // failed removal only costs the host a stale (unreferenced)
195
- // texture until the id is re-uploaded — never a wrong frame,
196
- // since packets key uploads by content fingerprint.
195
+ // texture until the id is re-uploaded. Invalidate the
196
+ // planner's per-view mirror FIRST: the platform resource's
197
+ // lifetime is independent of the fingerprint key, so an
198
+ // unregister followed by an identical registration must
199
+ // plan `.upload`, never `.retain` against a removed texture.
200
+ for (self.views[0..self.view_count]) |*view| {
201
+ view.removeCanvasFrameImageCacheId(id);
202
+ }
197
203
  self.options.platform.services.removeGpuSurfaceImage(id) catch {};
198
204
  noteCanvasImagesChanged(self);
199
205
  return true;
@@ -540,7 +540,7 @@ test "grouped code paragraphs select and copy across chunk boundaries" {
540
540
  .text = second,
541
541
  .spans = &second_spans,
542
542
  .static_text_group_id = group_id,
543
- .static_text_group_offset = first.len,
543
+ .static_text_group_offset = @intCast(first.len),
544
544
  },
545
545
  .{
546
546
  .id = 4,
@@ -654,6 +654,7 @@ pub fn collectCanvasWidgetTextReconcileEntries(
654
654
  CanvasWidgetSourceTextFingerprint{ .len = entry.text_len, .hash = entry.text_hash }
655
655
  else
656
656
  canvasWidgetSourceTextFingerprint(node.widget.text);
657
+ const has_code_diff = node.widget.hasCodeDiff();
657
658
  output[len] = .{
658
659
  .id = node.widget.id,
659
660
  .kind = node.widget.kind,
@@ -666,10 +667,10 @@ pub fn collectCanvasWidgetTextReconcileEntries(
666
667
  .text_composition = node.widget.text_composition,
667
668
  .value = node.widget.value,
668
669
  .value_x = node.widget.value_x,
669
- .code_content_width = node.widget.code_content_width,
670
- .code_content_width_generation = node.widget.code_content_width_generation,
671
- .code_content_width_font_id = node.widget.code_content_width_font_id,
672
- .code_content_width_size_bits = node.widget.code_content_width_size_bits,
670
+ .code_content_width = if (!has_code_diff) node.widget.code_content_width else 0,
671
+ .code_content_width_generation = if (!has_code_diff) node.widget.code_content_width_generation else 0,
672
+ .code_content_width_font_id = if (!has_code_diff) node.widget.code_content_width_font_id else 0,
673
+ .code_content_width_size_bits = if (!has_code_diff) node.widget.code_content_width_size_bits else 0,
673
674
  };
674
675
  len += 1;
675
676
  }
@@ -879,10 +880,12 @@ pub fn canvasWidgetLayoutNodeWithTextReconcileState(
879
880
  if (canvasWidgetEditableTextKind(copy.widget.kind)) copy.widget.value = entry.value;
880
881
  if (copy.widget.code_editor) {
881
882
  copy.widget.value_x = entry.value_x;
882
- copy.widget.code_content_width = entry.code_content_width;
883
- copy.widget.code_content_width_generation = entry.code_content_width_generation;
884
- copy.widget.code_content_width_font_id = entry.code_content_width_font_id;
885
- copy.widget.code_content_width_size_bits = entry.code_content_width_size_bits;
883
+ if (!copy.widget.hasCodeDiff()) {
884
+ copy.widget.code_content_width = entry.code_content_width;
885
+ copy.widget.code_content_width_generation = entry.code_content_width_generation;
886
+ copy.widget.code_content_width_font_id = entry.code_content_width_font_id;
887
+ copy.widget.code_content_width_size_bits = entry.code_content_width_size_bits;
888
+ }
886
889
  }
887
890
  if (copy.widget.text_selection == null and copy.widget.text_composition == null) {
888
891
  copy.widget.text_selection = entry.text_selection;
@@ -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();