@native-sdk/cli 0.9.2 → 0.9.3

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 (47) hide show
  1. package/build.zig +69 -1
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.d.ts +7 -0
  6. package/packages/core/sdk/events.ts +26 -5
  7. package/packages/core/sdk/text.d.ts +4 -0
  8. package/packages/core/sdk/text.ts +51 -0
  9. package/packages/core/src/checker.ts +58 -1
  10. package/packages/core/src/contract.ts +5 -4
  11. package/packages/core/src/devhost_journal.mjs +2 -2
  12. package/packages/core/src/diagnostics.ts +2 -2
  13. package/packages/core/src/service_contract.ts +10 -0
  14. package/packages/core/src/typed_ast.ts +9 -7
  15. package/packages/core/src/types.ts +28 -8
  16. package/skill-data/automation/SKILL.md +4 -3
  17. package/skill-data/native-ui/SKILL.md +3 -1
  18. package/skill-data/ts-core/SKILL.md +7 -4
  19. package/src/app_runner/root.zig +208 -6
  20. package/src/app_runner/ts_core_main.zig +2 -0
  21. package/src/automation/protocol.zig +5 -1
  22. package/src/automation/snapshot.zig +119 -0
  23. package/src/platform/macos/appkit_host.m +79 -12
  24. package/src/platform/macos/root.zig +68 -5
  25. package/src/primitives/canvas/events.zig +79 -1
  26. package/src/primitives/canvas/root.zig +1 -0
  27. package/src/primitives/canvas/text_interaction.zig +23 -0
  28. package/src/primitives/canvas/text_tests.zig +45 -0
  29. package/src/primitives/canvas/ui.zig +11 -8
  30. package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
  31. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  32. package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
  33. package/src/primitives/canvas/ui_tests.zig +37 -0
  34. package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
  35. package/src/runtime/automation_snapshot.zig +4 -0
  36. package/src/runtime/canvas_widget_control_tests.zig +2 -0
  37. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  38. package/src/runtime/native_command_event_tests.zig +29 -0
  39. package/src/runtime/session_journal.zig +21 -2
  40. package/src/runtime/ts_ui_app.zig +164 -1
  41. package/src/runtime/ui_app.zig +91 -18
  42. package/src/runtime/ui_app_tests.zig +232 -13
  43. package/src/runtime/view_widget_text.zig +1 -1
  44. package/src/tooling/verbs.zig +1 -0
  45. package/tools/corewire/emit.zig +31 -12
  46. package/tools/corewire/emit_facade.zig +57 -2
  47. package/tools/corewire/shim_rt.zig +20 -0
@@ -2214,7 +2214,7 @@ pub const catalog_markup_source =
2214
2214
  \\ </row>
2215
2215
  \\ <row gap="8">
2216
2216
  \\ <input text="{query}" placeholder="Name" autofocus="true" on-input="query_edit" on-submit="submit_query" grow="1" />
2217
- \\ <combobox text="{query}" placeholder="Search fruit" on-input="query_edit" />
2217
+ \\ <combobox text="{query}" placeholder="Search fruit" on-input="query_edit" on-press="open_picker" on-submit="submit_query" />
2218
2218
  \\ </row>
2219
2219
  \\ <radio-group gap="4" label="Formatting">
2220
2220
  \\ <radio checked="{bold}" on-change="toggle_bold" label="Bold" />
@@ -2344,7 +2344,7 @@ pub fn handCatalogView(ui: *CatalogUi, model: *const CatalogModel) CatalogUi.Nod
2344
2344
  }),
2345
2345
  ui.row(.{ .gap = 8 }, .{
2346
2346
  ui.el(.input, .{ .text = model.query, .placeholder = "Name", .autofocus = true, .on_input = CatalogUi.inputMsg(.query_edit), .on_submit = .submit_query, .grow = 1 }, .{}),
2347
- ui.el(.combobox, .{ .text = model.query, .placeholder = "Search fruit", .on_input = CatalogUi.inputMsg(.query_edit) }, .{}),
2347
+ ui.el(.combobox, .{ .text = model.query, .placeholder = "Search fruit", .on_input = CatalogUi.inputMsg(.query_edit), .on_press = .open_picker, .on_submit = .submit_query }, .{}),
2348
2348
  }),
2349
2349
  ui.el(.radio_group, .{ .gap = 4, .semantics = .{ .label = "Formatting" } }, .{
2350
2350
  ui.el(.radio, .{ .checked = model.bold, .on_change = .toggle_bold }, .{}),
@@ -2489,6 +2489,10 @@ test "catalog elements build the hand-written tree and dispatch typed messages"
2489
2489
  try testing.expectEqualStrings("q", markup_tree.msgForKeyboard(input.id, typed).?.query_edit.insert_text);
2490
2490
  const submit = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
2491
2491
  try testing.expectEqual(CatalogMsg.submit_query, markup_tree.msgForKeyboard(input.id, submit).?);
2492
+ const combobox = findByKind(markup_tree.root, .combobox).?;
2493
+ try testing.expectEqual(CatalogMsg.submit_query, markup_tree.msgForKeyboard(combobox.id, submit).?);
2494
+ try testing.expectEqual(CatalogMsg.open_picker, markup_tree.msgForKeyboard(combobox.id, .{ .phase = .key_down, .key = "space" }).?);
2495
+ try testing.expectEqual(CatalogMsg.open_picker, markup_tree.msgForKeyboard(combobox.id, .{ .phase = .key_down, .key = "arrowdown" }).?);
2492
2496
 
2493
2497
  // The whole catalog lays out through the canvas engine.
2494
2498
  var nodes: [256]canvas.WidgetLayoutNode = undefined;
@@ -4660,6 +4664,8 @@ pub const MirrorTextInputEvent = union(enum) {
4660
4664
  delete_forward,
4661
4665
  delete_word_backward,
4662
4666
  delete_word_forward,
4667
+ delete_to_start,
4668
+ delete_to_line_start,
4663
4669
  clear,
4664
4670
  move_caret: MirrorCaretMove,
4665
4671
  set_selection: MirrorSelection,
@@ -4687,6 +4693,8 @@ test "declaredTextInputUnion accepts the emitted mirror shape and rejects near-m
4687
4693
  delete_forward,
4688
4694
  delete_word_backward,
4689
4695
  delete_word_forward,
4696
+ delete_to_start,
4697
+ delete_to_line_start,
4690
4698
  clear,
4691
4699
  move_caret: MirrorCaretMove,
4692
4700
  set_selection: MirrorSelectionWithAffinity,
@@ -4703,6 +4711,8 @@ test "declaredTextInputUnion accepts the emitted mirror shape and rejects near-m
4703
4711
  delete_forward,
4704
4712
  delete_word_backward,
4705
4713
  delete_word_forward,
4714
+ delete_to_start,
4715
+ delete_to_line_start,
4706
4716
  clear,
4707
4717
  move_caret: MirrorCaretMove,
4708
4718
  set_selection: MirrorSelection,
@@ -4716,6 +4726,8 @@ test "declaredTextInputUnion accepts the emitted mirror shape and rejects near-m
4716
4726
  delete_forward,
4717
4727
  delete_word_backward,
4718
4728
  delete_word_forward,
4729
+ delete_to_start,
4730
+ delete_to_line_start,
4719
4731
  clear,
4720
4732
  move_caret: MirrorCaretMove,
4721
4733
  set_selection: MirrorSelection,
@@ -4731,6 +4743,8 @@ test "declaredTextInputUnion accepts the emitted mirror shape and rejects near-m
4731
4743
  delete_forward,
4732
4744
  delete_word_backward,
4733
4745
  delete_word_forward,
4746
+ delete_to_start,
4747
+ delete_to_line_start,
4734
4748
  clear,
4735
4749
  move_caret: struct { direction: WrongDirection, extend: bool },
4736
4750
  set_selection: MirrorSelection,
@@ -4984,6 +4998,8 @@ test "the interpreter binds on-input to a declared mirror union and translates e
4984
4998
  try testing.expectEqualStrings("abc", inserted.edit.insert_text);
4985
4999
  // Void verbs map by tag.
4986
5000
  try testing.expectEqual(MirrorTextInputEvent.delete_backward, tree.msgForTextEdit(field.id, .delete_backward).?.edit);
5001
+ try testing.expectEqual(MirrorTextInputEvent.delete_to_start, tree.msgForTextEdit(field.id, .delete_to_start).?.edit);
5002
+ try testing.expectEqual(MirrorTextInputEvent.delete_to_line_start, tree.msgForTextEdit(field.id, .delete_to_line_start).?.edit);
4987
5003
  // Caret moves translate the direction enum by member name.
4988
5004
  const moved = tree.msgForTextEdit(field.id, .{ .move_caret = .{ .direction = .previous_word, .extend = true } }).?;
4989
5005
  try testing.expectEqual(MirrorCaretDirection.previous_word, moved.edit.move_caret.direction);
@@ -349,6 +349,43 @@ test "keyboard events resolve activation and submit messages" {
349
349
  try testing.expectEqual(@as(?Msg, null), tree.msgForKeyboard(checkbox.id, letter));
350
350
  }
351
351
 
352
+ test "combobox Enter prefers submit while its other open keys still press" {
353
+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
354
+ defer arena_state.deinit();
355
+
356
+ var ui = InboxUi.init(arena_state.allocator());
357
+ const tree = try ui.finalize(ui.column(.{}, .{
358
+ ui.el(.combobox, .{
359
+ .text = "both handlers",
360
+ .on_press = .load_more,
361
+ .on_submit = .add,
362
+ }, .{}),
363
+ ui.el(.combobox, .{
364
+ .text = "press only",
365
+ .on_press = .load_more,
366
+ }, .{}),
367
+ ui.el(.combobox, .{
368
+ .text = "submit only",
369
+ .on_submit = .add,
370
+ }, .{}),
371
+ }));
372
+
373
+ const both = tree.root.children[0];
374
+ const press_only = tree.root.children[1];
375
+ const submit_only = tree.root.children[2];
376
+ const enter = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "enter" };
377
+ const space = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "space" };
378
+ const arrow_down = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowdown" };
379
+ const arrow_up = canvas.WidgetKeyboardEvent{ .phase = .key_down, .key = "arrowup" };
380
+
381
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(both.id, enter).?);
382
+ try testing.expectEqual(Msg.load_more, tree.msgForKeyboard(both.id, space).?);
383
+ try testing.expectEqual(Msg.load_more, tree.msgForKeyboard(both.id, arrow_down).?);
384
+ try testing.expectEqual(Msg.load_more, tree.msgForKeyboard(both.id, arrow_up).?);
385
+ try testing.expectEqual(Msg.load_more, tree.msgForKeyboard(press_only.id, enter).?);
386
+ try testing.expectEqual(Msg.add, tree.msgForKeyboard(submit_only.id, enter).?);
387
+ }
388
+
352
389
  test "tree keyboard navigation can select without dispatching pointer activation" {
353
390
  var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
354
391
  defer arena_state.deinit();
@@ -2403,6 +2403,19 @@ test "the accent override desaturates its dark-scheme focus ring" {
2403
2403
  try std.testing.expectEqualDeep(gray, canvas.accentFocusRing(gray, .dark));
2404
2404
  }
2405
2405
 
2406
+ test "accent overrides compose over either built-in pack without moving unrelated tokens" {
2407
+ const accent = Color.rgb8(0, 120, 111);
2408
+ for ([_]canvas.ThemePack{ .house, .geist }) |pack| {
2409
+ const base = DesignTokens.theme(.{ .pack = pack, .color_scheme = .dark });
2410
+ const branded = base.withOverrides(canvas.accentOverrides(accent, .dark));
2411
+ try std.testing.expectEqualDeep(accent, branded.colors.accent);
2412
+ try std.testing.expectEqualDeep(canvas.accentFocusRing(accent, .dark), branded.colors.focus_ring);
2413
+ try std.testing.expectEqualDeep(accent, branded.controls.slider.active_background);
2414
+ try std.testing.expectEqual(base.metrics.control_height, branded.metrics.control_height);
2415
+ try std.testing.expectEqualDeep(base.colors.background, branded.colors.background);
2416
+ }
2417
+ }
2418
+
2406
2419
  test "the dark accent focus ring holds the non-text contrast floor across hues" {
2407
2420
  // Rings draw OUTSIDE controls, so the tones that matter are the
2408
2421
  // dark containers controls commonly sit on, across BOTH shipped
@@ -30,6 +30,8 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
30
30
  .windows = self.automation_windows[0..1],
31
31
  .views = &.{},
32
32
  .widgets = &.{},
33
+ .commands = self.options.commands,
34
+ .menus = self.options.menus,
33
35
  .diagnostics = automationDiagnostics(self),
34
36
  .frame_profile = automationFrameProfile(self),
35
37
  .trays = automationTrays(self),
@@ -64,6 +66,8 @@ pub fn RuntimeAutomationSnapshot(comptime Runtime: type) type {
64
66
  .windows = self.automation_windows[0..count],
65
67
  .views = self.automation_views[0..view_count],
66
68
  .widgets = self.automation_widgets[0..widget_count],
69
+ .commands = self.options.commands,
70
+ .menus = self.options.menus,
67
71
  .diagnostics = automationDiagnostics(self),
68
72
  .frame_profile = automationFrameProfile(self),
69
73
  .trays = automationTrays(self),
@@ -2182,6 +2182,8 @@ test "runtime dispatches canvas widget commands from pointer and keyboard activa
2182
2182
  try std.testing.expectEqual(@as(u32, 6), app_state.command_count);
2183
2183
 
2184
2184
  harness.runtime.views[0].canvas_widget_focused_id = 6;
2185
+ // Command-string widgets have no typed on-submit channel, so their
2186
+ // combobox Enter behavior intentionally remains trigger activation.
2185
2187
  try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
2186
2188
  .window_id = 1,
2187
2189
  .label = "canvas",
@@ -1401,6 +1401,57 @@ test "single-line history replay restores exact retained bytes" {
1401
1401
  try std.testing.expect(harness.runtime.views[0].canvasWidgetTextHistoryAvailability(2).can_redo);
1402
1402
  }
1403
1403
 
1404
+ test "macOS Command Backspace treats model-provided newlines as single-line presentation bytes" {
1405
+ if (comptime builtin.os.tag != .macos) return error.SkipZigTest;
1406
+
1407
+ const TestApp = struct {
1408
+ fn app(self: *@This()) App {
1409
+ return .{ .context = self, .name = "gpu-widget-input-command-backspace-raw-newline", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1410
+ }
1411
+ };
1412
+
1413
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1414
+ defer harness.destroy(std.testing.allocator);
1415
+ harness.null_platform.gpu_surfaces = true;
1416
+ var app_state: TestApp = .{};
1417
+ const app = app_state.app();
1418
+ try harness.start(app);
1419
+ _ = try harness.runtime.createView(.{
1420
+ .window_id = 1,
1421
+ .label = "canvas",
1422
+ .kind = .gpu_surface,
1423
+ .frame = geometry.RectF.init(0, 0, 240, 100),
1424
+ });
1425
+
1426
+ var nodes: [2]canvas.WidgetLayoutNode = undefined;
1427
+ const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{canvas.Widget{
1428
+ .id = 2,
1429
+ .kind = .input,
1430
+ .frame = geometry.RectF.init(12, 16, 180, 32),
1431
+ .text = "one\ntwo",
1432
+ .text_selection = canvas.TextSelection.collapsed(7),
1433
+ }} }, geometry.RectF.init(0, 0, 240, 100), &nodes);
1434
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1435
+ harness.runtime.views[0].focused = true;
1436
+ harness.runtime.views[0].canvas_widget_focused_id = 2;
1437
+
1438
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1439
+ .window_id = 1,
1440
+ .label = "canvas",
1441
+ .kind = .key_down,
1442
+ .key = "backspace",
1443
+ .modifiers = .{ .command = true, .shift = true },
1444
+ } });
1445
+
1446
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1447
+ try std.testing.expectEqualStrings("", retained.nodes[1].widget.text);
1448
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(0), retained.nodes[1].widget.text_selection.?);
1449
+ try dispatchTextareaHistoryShortcut(harness, app, false);
1450
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1451
+ try std.testing.expectEqualStrings("one\ntwo", retained.nodes[1].widget.text);
1452
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(7), retained.nodes[1].widget.text_selection.?);
1453
+ }
1454
+
1404
1455
  test "textarea history replays newly completed CRLF atomically" {
1405
1456
  const TestApp = struct {
1406
1457
  fn app(self: *@This()) App {
@@ -1838,6 +1889,79 @@ test "canvas textareas undo and redo keyboard edits" {
1838
1889
  try std.testing.expectEqualStrings("external!", retained.nodes[1].widget.text);
1839
1890
  }
1840
1891
 
1892
+ test "macOS Command Backspace deletes to line start in every editable text kind and undoes as one step" {
1893
+ if (comptime builtin.os.tag != .macos) return error.SkipZigTest;
1894
+
1895
+ const TestApp = struct {
1896
+ fn app(self: *@This()) App {
1897
+ return .{ .context = self, .name = "gpu-widget-command-backspace", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
1898
+ }
1899
+ };
1900
+
1901
+ const harness = try TestHarness().create(std.testing.allocator, .{});
1902
+ defer harness.destroy(std.testing.allocator);
1903
+ harness.null_platform.gpu_surfaces = true;
1904
+ var app_state: TestApp = .{};
1905
+ const app = app_state.app();
1906
+ try harness.start(app);
1907
+ _ = try harness.runtime.createView(.{
1908
+ .window_id = 1,
1909
+ .label = "canvas",
1910
+ .kind = .gpu_surface,
1911
+ .frame = geometry.RectF.init(0, 0, 520, 280),
1912
+ });
1913
+
1914
+ const kinds = [_]canvas.WidgetKind{ .input, .text_field, .search_field, .combobox, .textarea };
1915
+ var children: [kinds.len]canvas.Widget = undefined;
1916
+ for (&children, kinds, 0..) |*child, kind, index| {
1917
+ child.* = .{
1918
+ .id = @intCast(index + 2),
1919
+ .kind = kind,
1920
+ .frame = geometry.RectF.init(12, @floatFromInt(12 + index * 46), 260, 36),
1921
+ .text = if (kind == .textarea) "first\nsecond line" else "second line",
1922
+ .text_selection = canvas.TextSelection.collapsed(if (kind == .textarea) 12 else 6),
1923
+ .semantics = .{ .label = "Editor" },
1924
+ };
1925
+ }
1926
+ var nodes: [kinds.len + 1]canvas.WidgetLayoutNode = undefined;
1927
+ const layout = try canvas.layoutWidgetTree(
1928
+ .{ .kind = .stack, .children = &children },
1929
+ geometry.RectF.init(0, 0, 520, 280),
1930
+ &nodes,
1931
+ );
1932
+ _ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
1933
+
1934
+ for (kinds, 0..) |kind, index| {
1935
+ const id: canvas.ObjectId = @intCast(index + 2);
1936
+ harness.runtime.views[0].focused = true;
1937
+ harness.runtime.views[0].canvas_widget_focused_id = id;
1938
+ try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
1939
+ .window_id = 1,
1940
+ .label = "canvas",
1941
+ .kind = .key_down,
1942
+ .key = "backspace",
1943
+ .modifiers = .{ .command = true },
1944
+ } });
1945
+
1946
+ var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1947
+ const edited = retained.findById(id).?.widget;
1948
+ try std.testing.expectEqualStrings(if (kind == .textarea) "first\n line" else " line", edited.text);
1949
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(if (kind == .textarea) 6 else 0), edited.text_selection.?);
1950
+
1951
+ try dispatchTextareaHistoryShortcut(harness, app, false);
1952
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1953
+ const undone = retained.findById(id).?.widget;
1954
+ try std.testing.expectEqualStrings(if (kind == .textarea) "first\nsecond line" else "second line", undone.text);
1955
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(if (kind == .textarea) 12 else 6), undone.text_selection.?);
1956
+
1957
+ try dispatchTextareaHistoryShortcut(harness, app, true);
1958
+ retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
1959
+ const redone = retained.findById(id).?.widget;
1960
+ try std.testing.expectEqualStrings(if (kind == .textarea) "first\n line" else " line", redone.text);
1961
+ try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(if (kind == .textarea) 6 else 0), redone.text_selection.?);
1962
+ }
1963
+ }
1964
+
1841
1965
  test "compound editor history reroutes every continuation after controlled rebuilds" {
1842
1966
  const TestApp = struct {
1843
1967
  replay_count: usize = 0,
@@ -253,6 +253,35 @@ test "runtime dispatches menu command events" {
253
253
  try std.testing.expectEqual(@as(platform.WindowId, 1), app_state.last_window_id);
254
254
  }
255
255
 
256
+ test "automation snapshot exposes configured app menus" {
257
+ const items = [_]platform.MenuItem{
258
+ .{ .label = "Refresh", .command = "app.refresh" },
259
+ .{ .label = "Disabled", .command = "app.disabled", .enabled = false },
260
+ .{ .separator = true },
261
+ };
262
+ const menus = [_]platform.Menu{
263
+ .{ .title = "View", .items = &items },
264
+ };
265
+ const harness = try TestHarness().create(std.testing.allocator, .{});
266
+ defer harness.destroy(std.testing.allocator);
267
+ harness.runtime.options.menus = &menus;
268
+ const snapshot = harness.runtime.automationSnapshot("Menus");
269
+ try std.testing.expectEqual(@as(usize, 1), snapshot.menus.len);
270
+ try std.testing.expectEqualStrings("View", snapshot.menus[0].title);
271
+ try std.testing.expectEqual(@as(usize, 3), snapshot.menus[0].items.len);
272
+ try std.testing.expectEqualStrings("app.refresh", snapshot.menus[0].items[0].command);
273
+ try std.testing.expect(!snapshot.menus[0].items[1].enabled);
274
+ try std.testing.expect(snapshot.menus[0].items[2].separator);
275
+
276
+ var buffer: [2048]u8 = undefined;
277
+ var writer = std.Io.Writer.fixed(&buffer);
278
+ try automation.snapshot.writeText(snapshot, &writer);
279
+ const text = writer.buffered();
280
+ try std.testing.expect(std.mem.indexOf(u8, text, "app-menu title=\"View\" items=3\n") != null);
281
+ try std.testing.expect(std.mem.indexOf(u8, text, " app-menu-item label=\"Refresh\" command=\"app.refresh\" enabled=true checked=false key=\"\"") != null);
282
+ try std.testing.expect(std.mem.indexOf(u8, text, " app-menu-item separator\n") != null);
283
+ }
284
+
256
285
  test "runtime dispatches tray item commands" {
257
286
  const TestApp = struct {
258
287
  command_count: u32 = 0,
@@ -133,8 +133,12 @@ pub const format_fingerprint: u64 = layout_fingerprint.hash(formatLayoutDescript
133
133
  /// out-of-window audio record as journal damage — an older recording
134
134
  /// could journal a wider value the old feed paths accepted, which
135
135
  /// would now be misreported as damage instead of refusing as a
136
- /// different generation.
137
- pub const format_semantic_epoch: u32 = 5;
136
+ /// different generation. Epoch 6: macOS Command+Backspace gained its
137
+ /// platform text-editor meaning (delete to field start in single-line
138
+ /// editors, or hard line start in textareas). The raw gpu-surface key record
139
+ /// is byte-identical, but replay now derives a text edit where older builds
140
+ /// derived none.
141
+ pub const format_semantic_epoch: u32 = 6;
138
142
 
139
143
  /// The canonical description `format_fingerprint` hashes: everything
140
144
  /// that defines the on-disk record layout. Reflection covers the record
@@ -1611,6 +1615,21 @@ test "event codec round-trips every payload variant" {
1611
1615
  try testing.expect(decoded.gpu_surface_input.modifiers.control);
1612
1616
  try testing.expectEqual(@as(f32, 0), decoded.gpu_surface_input.scale);
1613
1617
  }
1618
+ {
1619
+ // Command+Backspace journals as the raw platform key chord; replay
1620
+ // re-derives the semantic delete_to_start/delete_to_line_start edit
1621
+ // from the focused widget kind.
1622
+ const decoded = try roundTripEvent(.{ .gpu_surface_input = .{
1623
+ .label = "editor-canvas",
1624
+ .kind = .key_down,
1625
+ .key = "backspace",
1626
+ .modifiers = .{ .primary = true, .command = true },
1627
+ } });
1628
+ try testing.expectEqualStrings("backspace", decoded.gpu_surface_input.key);
1629
+ try testing.expect(decoded.gpu_surface_input.modifiers.primary);
1630
+ try testing.expect(decoded.gpu_surface_input.modifiers.command);
1631
+ try testing.expect(!decoded.gpu_surface_input.modifiers.control);
1632
+ }
1614
1633
  {
1615
1634
  // v5: pinch records carry the magnification delta and the
1616
1635
  // gesture kinds appended at codes 12-14.
@@ -44,7 +44,8 @@
44
44
  //! the committed model. One model-helper convention joins that wiring:
45
45
  //! an exported `themePack(model): "house" | "geist"` helper selects the
46
46
  //! stock pack live through `theme_fn`, without taking ownership of the
47
- //! system appearance axes. An exported
47
+ //! system appearance axes; `themeState(model)` subsumes it with scheme and
48
+ //! accent axes through `theme_state_fn`. An exported
48
49
  //! `statusItem(model): StatusItemState` helper similarly owns one complete
49
50
  //! menu-bar item through `status_item_fn`; `statusItems(model)` owns a keyed
50
51
  //! collection through `status_items_fn`. Both keep shell, presentation, and
@@ -80,6 +81,27 @@ const ts_core_host = @import("ts_core_host.zig");
80
81
 
81
82
  const ts_ui_app_log = std.log.scoped(.zero_ts_ui_app);
82
83
 
84
+ /// Quota for a comptime scan of an app-authored type. TS `Msg` unions may
85
+ /// legally carry 256 arms; include total identifier bytes because
86
+ /// `std.mem.eql`'s comptime scalar path scales with the compared names.
87
+ fn typeScanQuota(comptime T: type) u32 {
88
+ const fields = switch (@typeInfo(T)) {
89
+ .@"struct" => |info| info.fields,
90
+ .@"union" => |info| info.fields,
91
+ .@"enum" => |info| info.fields,
92
+ else => return 2_000,
93
+ };
94
+ var name_bytes: u64 = 0;
95
+ for (fields) |field| name_bytes += field.name.len;
96
+ const quota: u64 = 100_000 + @as(u64, fields.len) * 1_024 + name_bytes * 256;
97
+ return @intCast(@min(quota, std.math.maxInt(u32)));
98
+ }
99
+
100
+ fn scaledTypeScanQuota(comptime T: type, comptime scans: usize) u32 {
101
+ const quota = @as(u64, typeScanQuota(T)) * @max(scans, 1);
102
+ return @intCast(@min(quota, std.math.maxInt(u32)));
103
+ }
104
+
83
105
  pub fn TsUiApp(comptime core: type) type {
84
106
  return struct {
85
107
  /// The effect bridge — shared with any direct `TsCoreHost(core)`
@@ -92,6 +114,9 @@ pub fn TsUiApp(comptime core: type) type {
92
114
  pub const Options = App.Options;
93
115
  pub const Effects = App.Effects;
94
116
  pub const Ui = App.Ui;
117
+ /// Shared with generated launchers that perform their own Msg scans.
118
+ pub const msg_scan_quota = typeScanQuota(Msg);
119
+ pub const persist_route_scan_quota = scaledTypeScanQuota(Msg, 3);
95
120
 
96
121
  /// Internal keyed-channel namespace for persistence write failures
97
122
  /// ("TSPR"). It never shares an app-authored TS bridge index.
@@ -223,12 +248,14 @@ pub fn TsUiApp(comptime core: type) type {
223
248
  /// a typo or payload mismatch fails during `native build`, before a
224
249
  /// first boot can reach the dynamic dispatch path below.
225
250
  pub fn validatePersistRoutes(comptime routes: PersistRoutes) void {
251
+ @setEvalBranchQuota(persist_route_scan_quota);
226
252
  validatePersistRoute(routes.ok, void, "ok");
227
253
  validatePersistRoute(routes.none, void, "none");
228
254
  validatePersistRoute(routes.err, []const u8, "err");
229
255
  }
230
256
 
231
257
  fn validatePersistRoute(comptime route: []const u8, comptime Payload: type, comptime role: []const u8) void {
258
+ @setEvalBranchQuota(msg_scan_quota);
232
259
  inline for (@typeInfo(Msg).@"union".fields) |arm| {
233
260
  if (comptime std.mem.eql(u8, arm.name, route)) {
234
261
  if (arm.type != Payload) {
@@ -379,12 +406,22 @@ pub fn TsUiApp(comptime core: type) type {
379
406
  // external-core mirror. The app owns only the pack; UiApp's
380
407
  // stock-token path keeps following the OS appearance.
381
408
  if (comptime @hasDecl(Model, "themePack")) {
409
+ if (comptime @hasDecl(Model, "themeState")) {
410
+ @compileError("TsUiApp: export either themePack or themeState, not both");
411
+ }
382
412
  if (options.theme_fn != null) {
383
413
  @panic("TsUiApp wires theme_fn from the core's themePack helper - remove the wiring's theme_fn");
384
414
  }
385
415
  comptime validateThemePackHelper();
386
416
  stamped.theme_fn = themePackAdapter;
387
417
  }
418
+ if (comptime @hasDecl(Model, "themeState")) {
419
+ if (options.theme_state_fn != null or options.theme_fn != null) {
420
+ @panic("TsUiApp wires theme_state_fn from the core's themeState helper - remove the wiring's theme_state_fn/theme_fn");
421
+ }
422
+ comptime validateThemeStateHelper();
423
+ stamped.theme_state_fn = themeStateAdapter;
424
+ }
388
425
  // A statusItem helper is the TS app's model-derived shell
389
426
  // declaration. UiApp installs it on the first frame and
390
427
  // independently patches shell/presentation/menu after each
@@ -503,6 +540,82 @@ pub fn TsUiApp(comptime core: type) type {
503
540
  }
504
541
  }
505
542
 
543
+ fn themeStateAdapter(model: *const Model) App.ThemeState {
544
+ const params = @typeInfo(@TypeOf(Model.themeState)).@"fn".params;
545
+ const raw_state = if (comptime params.len == 1)
546
+ model.themeState()
547
+ else
548
+ model.themeState(core.rt.frameAllocator());
549
+ const state = if (comptime @typeInfo(@TypeOf(raw_state)) == .pointer) raw_state.* else raw_state;
550
+ const accent = if (state.accent) |value| parseThemeAccent(value) else null;
551
+ return .{
552
+ .pack = if (state.pack) |pack| canvas.ThemePack.fromName(@tagName(pack)).? else null,
553
+ .color_scheme = if (state.colorScheme) |scheme| themeColorScheme(scheme) else .system,
554
+ .accent = accent,
555
+ .invalid_accent = if (state.accent != null and accent == null) state.accent else null,
556
+ };
557
+ }
558
+
559
+ fn themeColorScheme(value: anytype) App.ThemeColorScheme {
560
+ const name = @tagName(value);
561
+ inline for (std.meta.fields(App.ThemeColorScheme)) |field| {
562
+ if (std.mem.eql(u8, name, field.name)) return @enumFromInt(field.value);
563
+ }
564
+ unreachable;
565
+ }
566
+
567
+ fn parseThemeAccent(value: []const u8) ?canvas.Color {
568
+ if (value.len != 7 or value[0] != '#') return null;
569
+ const r = themeHexByte(value[1], value[2]) orelse return null;
570
+ const g = themeHexByte(value[3], value[4]) orelse return null;
571
+ const b = themeHexByte(value[5], value[6]) orelse return null;
572
+ return canvas.Color.rgb8(r, g, b);
573
+ }
574
+
575
+ fn themeHexByte(hi: u8, lo: u8) ?u8 {
576
+ const h = themeHexNibble(hi) orelse return null;
577
+ const l = themeHexNibble(lo) orelse return null;
578
+ return h * 16 + l;
579
+ }
580
+
581
+ fn themeHexNibble(byte: u8) ?u8 {
582
+ return switch (byte) {
583
+ '0'...'9' => byte - '0',
584
+ 'a'...'f' => byte - 'a' + 10,
585
+ 'A'...'F' => byte - 'A' + 10,
586
+ else => null,
587
+ };
588
+ }
589
+
590
+ fn validateThemeStateHelper() void {
591
+ const teaching = "TsUiApp: themeState must be exported from core.ts as themeState(model: Model): ThemeState; import ThemeState from @native-sdk/core/events";
592
+ const helper_info = @typeInfo(@TypeOf(Model.themeState));
593
+ if (helper_info != .@"fn") @compileError(teaching);
594
+ const function = helper_info.@"fn";
595
+ if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type == null or function.params[0].type.? != *const Model) {
596
+ @compileError(teaching);
597
+ }
598
+ if (function.params.len == 2) {
599
+ if (function.params[1].type == null or function.params[1].type.? != std.mem.Allocator or
600
+ !@hasDecl(core, "rt") or !@hasDecl(core.rt, "frameAllocator"))
601
+ {
602
+ @compileError(teaching);
603
+ }
604
+ }
605
+ const RawState = function.return_type orelse @compileError(teaching);
606
+ const State = statusItemRecordType(RawState, teaching);
607
+ const info = @typeInfo(State).@"struct";
608
+ if (info.fields.len != 3 or !@hasField(State, "pack") or !@hasField(State, "colorScheme") or !@hasField(State, "accent")) {
609
+ @compileError(teaching);
610
+ }
611
+ if (!optionalEnumType(@FieldType(State, "pack"), &.{ "house", "geist" }) or
612
+ !optionalEnumType(@FieldType(State, "colorScheme"), &.{ "light", "dark", "system" }) or
613
+ @FieldType(State, "accent") != ?[]const u8)
614
+ {
615
+ @compileError(teaching);
616
+ }
617
+ }
618
+
506
619
  /// Convert the compiled core's canonical status-item records into
507
620
  /// the platform rows UiApp already knows how to validate, copy,
508
621
  /// hash, install, and patch. Interface records cross the core ABI
@@ -930,6 +1043,11 @@ pub fn TsUiApp(comptime core: type) type {
930
1043
  return info == .optional and statusItemNumericType(info.optional.child);
931
1044
  }
932
1045
 
1046
+ fn optionalEnumType(comptime T: type, comptime expected: []const []const u8) bool {
1047
+ const info = @typeInfo(T);
1048
+ return info == .optional and statusItemEnumType(info.optional.child, expected);
1049
+ }
1050
+
933
1051
  fn statusItemNumericType(comptime T: type) bool {
934
1052
  return @typeInfo(T) == .int or @typeInfo(T) == .float;
935
1053
  }
@@ -1029,6 +1147,7 @@ pub fn TsUiApp(comptime core: type) type {
1029
1147
  }
1030
1148
 
1031
1149
  fn persistOutcomeMsg(event: runtime_effects.EffectChannelEvent) Msg {
1150
+ @setEvalBranchQuota(msg_scan_quota);
1032
1151
  const reason: []const u8 = switch (event.kind) {
1033
1152
  .data => event.bytes,
1034
1153
  .rejected => "rejected",
@@ -1044,6 +1163,7 @@ pub fn TsUiApp(comptime core: type) type {
1044
1163
  }
1045
1164
 
1046
1165
  fn dispatchPersistVoid(fx: *Effects, route: []const u8) void {
1166
+ @setEvalBranchQuota(msg_scan_quota);
1047
1167
  inline for (@typeInfo(Msg).@"union".fields) |arm| {
1048
1168
  if (comptime arm.type == void) {
1049
1169
  if (std.mem.eql(u8, arm.name, route)) {
@@ -1056,6 +1176,7 @@ pub fn TsUiApp(comptime core: type) type {
1056
1176
  }
1057
1177
 
1058
1178
  fn dispatchPersistError(fx: *Effects, route: []const u8, reason: []const u8) void {
1179
+ @setEvalBranchQuota(msg_scan_quota);
1059
1180
  inline for (@typeInfo(Msg).@"union".fields) |arm| {
1060
1181
  if (comptime arm.type == []const u8) {
1061
1182
  if (std.mem.eql(u8, arm.name, route)) {
@@ -1098,6 +1219,7 @@ pub fn TsUiApp(comptime core: type) type {
1098
1219
  /// One env delivery: resolve the arm by name and dispatch the
1099
1220
  /// value through a full core cycle.
1100
1221
  fn dispatchOneEnvValue(fx: *Effects, msg: []const u8, value: []const u8) void {
1222
+ @setEvalBranchQuota(msg_scan_quota);
1101
1223
  inline for (@typeInfo(Msg).@"union".fields) |arm| {
1102
1224
  if (comptime arm.type == []const u8) {
1103
1225
  if (std.mem.eql(u8, arm.name, msg)) {
@@ -1117,6 +1239,7 @@ pub fn TsUiApp(comptime core: type) type {
1117
1239
  /// hand-assembled cores: every `envMsgs` entry must name a Msg
1118
1240
  /// arm carrying exactly one bytes payload.
1119
1241
  fn validateEnvMsgs() void {
1242
+ @setEvalBranchQuota(scaledTypeScanQuota(Msg, core.envMsgs.len));
1120
1243
  for (core.envMsgs) |entry| {
1121
1244
  var found = false;
1122
1245
  for (@typeInfo(Msg).@"union".fields) |arm| {
@@ -1333,6 +1456,7 @@ pub fn TsUiApp(comptime core: type) type {
1333
1456
  /// error the frontend's NS1033 re-derives for hand-written
1334
1457
  /// cores.
1335
1458
  fn channelArmIndex(comptime tag: []const u8, comptime channel: []const u8) usize {
1459
+ @setEvalBranchQuota(msg_scan_quota);
1336
1460
  for (@typeInfo(Msg).@"union".fields, 0..) |arm, index| {
1337
1461
  if (std.mem.eql(u8, arm.name, tag)) return index;
1338
1462
  }
@@ -1551,6 +1675,45 @@ const WindowsAdapterTestCore = struct {
1551
1675
  };
1552
1676
  };
1553
1677
 
1678
+ const ThemeStateAdapterTestCore = struct {
1679
+ const Pack = enum { house, geist };
1680
+ const Scheme = enum { light, dark, system };
1681
+ const State = struct {
1682
+ pack: ?Pack,
1683
+ colorScheme: ?Scheme,
1684
+ accent: ?[]const u8,
1685
+ };
1686
+
1687
+ pub const Msg = union(enum) { noop };
1688
+ pub const Model = struct {
1689
+ bad: bool = false,
1690
+
1691
+ pub fn themeState(self: *const Model) State {
1692
+ return .{
1693
+ .pack = .geist,
1694
+ .colorScheme = .dark,
1695
+ .accent = if (self.bad) "hot-pink" else "#Df2670",
1696
+ };
1697
+ }
1698
+ };
1699
+ };
1700
+
1701
+ test "TypeScript themeState adapter validates, parses hex, and preserves malformed accent teaching" {
1702
+ const Adapter = TsUiApp(ThemeStateAdapterTestCore);
1703
+ comptime Adapter.validateThemeStateHelper();
1704
+ var model = ThemeStateAdapterTestCore.Model{};
1705
+ var state = Adapter.themeStateAdapter(&model);
1706
+ try std.testing.expectEqual(canvas.ThemePack.geist, state.pack.?);
1707
+ try std.testing.expectEqual(Adapter.App.ThemeColorScheme.dark, state.color_scheme);
1708
+ try std.testing.expectEqual(canvas.Color.rgb8(0xdf, 0x26, 0x70), state.accent.?);
1709
+ try std.testing.expect(state.invalid_accent == null);
1710
+
1711
+ model.bad = true;
1712
+ state = Adapter.themeStateAdapter(&model);
1713
+ try std.testing.expect(state.accent == null);
1714
+ try std.testing.expectEqualStrings("hot-pink", state.invalid_accent.?);
1715
+ }
1716
+
1554
1717
  test "TypeScript windows adapter keeps the declared prefix on overflow and projects chromeless" {
1555
1718
  const Adapter = TsUiApp(WindowsAdapterTestCore);
1556
1719
  comptime Adapter.validateWindowsHelper();